]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Mde UEFI library functions.\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2007, Intel Corporation<BR>\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | //\r | |
16 | // Include common header file for this module.\r | |
17 | //\r | |
18 | #include "UefiLibInternal.h"\r | |
19 | \r | |
20 | /**\r | |
21 | Compare whether two names of languages are identical.\r | |
22 | \r | |
23 | @param Language1 Name of language 1.\r | |
24 | @param Language2 Name of language 2.\r | |
25 | \r | |
26 | @retval TRUE Language 1 and language 2 are the same.\r | |
27 | @retval FALSE Language 1 and language 2 are not the same.\r | |
28 | \r | |
29 | **/\r | |
30 | BOOLEAN\r | |
31 | CompareIso639LanguageCode (\r | |
32 | IN CONST CHAR8 *Language1,\r | |
33 | IN CONST CHAR8 *Language2\r | |
34 | )\r | |
35 | {\r | |
36 | UINT32 Name1;\r | |
37 | UINT32 Name2;\r | |
38 | \r | |
39 | Name1 = ReadUnaligned24 ((CONST UINT32 *) Language1);\r | |
40 | Name2 = ReadUnaligned24 ((CONST UINT32 *) Language2);\r | |
41 | \r | |
42 | return (BOOLEAN) (Name1 == Name2);\r | |
43 | }\r | |
44 | \r | |
45 | /**\r | |
46 | This function searches the list of configuration tables stored in the EFI System\r | |
47 | Table for a table with a GUID that matches TableGuid. If a match is found,\r | |
48 | then a pointer to the configuration table is returned in Table, and EFI_SUCCESS\r | |
49 | is returned. If a matching GUID is not found, then EFI_NOT_FOUND is returned.\r | |
50 | If TableGuid is NULL, then ASSERT().\r | |
51 | If Table is NULL, then ASSERT().\r | |
52 | \r | |
53 | @param TableGuid Pointer to table's GUID type..\r | |
54 | @param Table Pointer to the table associated with TableGuid in the EFI System Table.\r | |
55 | \r | |
56 | @retval EFI_SUCCESS A configuration table matching TableGuid was found.\r | |
57 | @retval EFI_NOT_FOUND A configuration table matching TableGuid could not be found.\r | |
58 | \r | |
59 | **/\r | |
60 | EFI_STATUS\r | |
61 | EFIAPI\r | |
62 | EfiGetSystemConfigurationTable (\r | |
63 | IN EFI_GUID *TableGuid,\r | |
64 | OUT VOID **Table\r | |
65 | )\r | |
66 | {\r | |
67 | EFI_SYSTEM_TABLE *SystemTable;\r | |
68 | UINTN Index;\r | |
69 | \r | |
70 | ASSERT (TableGuid != NULL);\r | |
71 | ASSERT (Table != NULL);\r | |
72 | \r | |
73 | SystemTable = gST;\r | |
74 | *Table = NULL;\r | |
75 | for (Index = 0; Index < SystemTable->NumberOfTableEntries; Index++) {\r | |
76 | if (CompareGuid (TableGuid, &(SystemTable->ConfigurationTable[Index].VendorGuid))) {\r | |
77 | *Table = SystemTable->ConfigurationTable[Index].VendorTable;\r | |
78 | return EFI_SUCCESS;\r | |
79 | }\r | |
80 | }\r | |
81 | \r | |
82 | return EFI_NOT_FOUND;\r | |
83 | }\r | |
84 | \r | |
85 | /**\r | |
86 | This function causes the notification function to be executed for every protocol\r | |
87 | of type ProtocolGuid instance that exists in the system when this function is\r | |
88 | invoked. In addition, every time a protocol of type ProtocolGuid instance is\r | |
89 | installed or reinstalled, the notification function is also executed.\r | |
90 | \r | |
91 | @param ProtocolGuid Supplies GUID of the protocol upon whose installation the event is fired.\r | |
92 | @param NotifyTpl Supplies the task priority level of the event notifications.\r | |
93 | @param NotifyFunction Supplies the function to notify when the event is signaled.\r | |
94 | @param NotifyContext The context parameter to pass to NotifyFunction.\r | |
95 | @param Registration A pointer to a memory location to receive the registration value.\r | |
96 | \r | |
97 | @return The notification event that was created.\r | |
98 | \r | |
99 | **/\r | |
100 | EFI_EVENT\r | |
101 | EFIAPI\r | |
102 | EfiCreateProtocolNotifyEvent(\r | |
103 | IN EFI_GUID *ProtocolGuid,\r | |
104 | IN EFI_TPL NotifyTpl,\r | |
105 | IN EFI_EVENT_NOTIFY NotifyFunction,\r | |
106 | IN VOID *NotifyContext, OPTIONAL\r | |
107 | OUT VOID **Registration\r | |
108 | )\r | |
109 | {\r | |
110 | EFI_STATUS Status;\r | |
111 | EFI_EVENT Event;\r | |
112 | \r | |
113 | //\r | |
114 | // Create the event\r | |
115 | //\r | |
116 | \r | |
117 | Status = gBS->CreateEvent (\r | |
118 | EVT_NOTIFY_SIGNAL,\r | |
119 | NotifyTpl,\r | |
120 | NotifyFunction,\r | |
121 | NotifyContext,\r | |
122 | &Event\r | |
123 | );\r | |
124 | ASSERT_EFI_ERROR (Status);\r | |
125 | \r | |
126 | //\r | |
127 | // Register for protocol notifactions on this event\r | |
128 | //\r | |
129 | \r | |
130 | Status = gBS->RegisterProtocolNotify (\r | |
131 | ProtocolGuid,\r | |
132 | Event,\r | |
133 | Registration\r | |
134 | );\r | |
135 | \r | |
136 | ASSERT_EFI_ERROR (Status);\r | |
137 | \r | |
138 | //\r | |
139 | // Kick the event so we will perform an initial pass of\r | |
140 | // current installed drivers\r | |
141 | //\r | |
142 | \r | |
143 | gBS->SignalEvent (Event);\r | |
144 | return Event;\r | |
145 | }\r | |
146 | \r | |
147 | /**\r | |
148 | This function creates an event using NotifyTpl, NoifyFunction, and NotifyContext.\r | |
149 | This event is signaled with EfiNamedEventSignal(). This provide the ability for\r | |
150 | one or more listeners on the same event named by the GUID specified by Name.\r | |
151 | If Name is NULL, then ASSERT().\r | |
152 | If NotifyTpl is not a legal TPL value, then ASSERT().\r | |
153 | If NotifyFunction is NULL, then ASSERT().\r | |
154 | \r | |
155 | @param Name Supplies GUID name of the event.\r | |
156 | @param NotifyTpl Supplies the task priority level of the event notifications.\r | |
157 | @param NotifyFunction Supplies the function to notify when the event is signaled.\r | |
158 | @param NotifyContext The context parameter to pass to NotifyFunction.\r | |
159 | @param Registration A pointer to a memory location to receive the registration value.\r | |
160 | \r | |
161 | @retval EFI_SUCCESS A named event was created.\r | |
162 | @retval EFI_OUT_OF_RESOURCES There are not enough resource to create the named event.\r | |
163 | \r | |
164 | **/\r | |
165 | EFI_STATUS\r | |
166 | EFIAPI\r | |
167 | EfiNamedEventListen (\r | |
168 | IN CONST EFI_GUID *Name,\r | |
169 | IN EFI_TPL NotifyTpl,\r | |
170 | IN EFI_EVENT_NOTIFY NotifyFunction,\r | |
171 | IN CONST VOID *NotifyContext, OPTIONAL\r | |
172 | OUT VOID *Registration OPTIONAL\r | |
173 | )\r | |
174 | {\r | |
175 | EFI_STATUS Status;\r | |
176 | EFI_EVENT Event;\r | |
177 | VOID *RegistrationLocal;\r | |
178 | \r | |
179 | ASSERT (Name != NULL);\r | |
180 | ASSERT (NotifyFunction != NULL);\r | |
181 | ASSERT (NotifyTpl <= TPL_HIGH_LEVEL);\r | |
182 | \r | |
183 | //\r | |
184 | // Create event\r | |
185 | //\r | |
186 | Status = gBS->CreateEvent (\r | |
187 | EVT_NOTIFY_SIGNAL,\r | |
188 | NotifyTpl,\r | |
189 | NotifyFunction,\r | |
190 | (VOID *) NotifyContext,\r | |
191 | &Event\r | |
192 | );\r | |
193 | ASSERT_EFI_ERROR (Status);\r | |
194 | \r | |
195 | //\r | |
196 | // The Registration is not optional to RegisterProtocolNotify().\r | |
197 | // To make it optional to EfiNamedEventListen(), may need to substitute with a local.\r | |
198 | //\r | |
199 | if (Registration != NULL) {\r | |
200 | RegistrationLocal = Registration;\r | |
201 | } else {\r | |
202 | RegistrationLocal = &RegistrationLocal;\r | |
203 | }\r | |
204 | \r | |
205 | //\r | |
206 | // Register for an installation of protocol interface\r | |
207 | //\r | |
208 | \r | |
209 | Status = gBS->RegisterProtocolNotify (\r | |
210 | (EFI_GUID *) Name,\r | |
211 | Event,\r | |
212 | RegistrationLocal\r | |
213 | );\r | |
214 | ASSERT_EFI_ERROR (Status);\r | |
215 | \r | |
216 | return Status;\r | |
217 | }\r | |
218 | \r | |
219 | /**\r | |
220 | This function signals the named event specified by Name. The named event must\r | |
221 | have been created with EfiNamedEventListen().\r | |
222 | \r | |
223 | @param Name Supplies GUID name of the event.\r | |
224 | \r | |
225 | @retval EFI_SUCCESS A named event was signaled.\r | |
226 | @retval EFI_OUT_OF_RESOURCES There are not enough resource to signal the named event.\r | |
227 | \r | |
228 | **/\r | |
229 | EFI_STATUS\r | |
230 | EFIAPI\r | |
231 | EfiNamedEventSignal (\r | |
232 | IN CONST EFI_GUID *Name\r | |
233 | )\r | |
234 | {\r | |
235 | EFI_STATUS Status;\r | |
236 | EFI_HANDLE Handle;\r | |
237 | \r | |
238 | Handle = NULL;\r | |
239 | Status = gBS->InstallProtocolInterface (\r | |
240 | &Handle,\r | |
241 | (EFI_GUID *) Name,\r | |
242 | EFI_NATIVE_INTERFACE,\r | |
243 | NULL\r | |
244 | );\r | |
245 | ASSERT_EFI_ERROR (Status);\r | |
246 | \r | |
247 | Status = gBS->UninstallProtocolInterface (\r | |
248 | Handle,\r | |
249 | (EFI_GUID *) Name,\r | |
250 | NULL\r | |
251 | );\r | |
252 | ASSERT_EFI_ERROR (Status);\r | |
253 | \r | |
254 | return Status;\r | |
255 | }\r | |
256 | \r | |
257 | /**\r | |
258 | Returns the current TPL.\r | |
259 | \r | |
260 | This function returns the current TPL. There is no EFI service to directly\r | |
261 | retrieve the current TPL. Instead, the RaiseTPL() function is used to raise\r | |
262 | the TPL to TPL_HIGH_LEVEL. This will return the current TPL. The TPL level\r | |
263 | can then immediately be restored back to the current TPL level with a call\r | |
264 | to RestoreTPL().\r | |
265 | \r | |
266 | @param VOID\r | |
267 | \r | |
268 | @retval EFI_TPL The current TPL.\r | |
269 | \r | |
270 | **/\r | |
271 | EFI_TPL\r | |
272 | EFIAPI\r | |
273 | EfiGetCurrentTpl (\r | |
274 | VOID\r | |
275 | )\r | |
276 | {\r | |
277 | EFI_TPL Tpl;\r | |
278 | \r | |
279 | Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r | |
280 | gBS->RestoreTPL (Tpl);\r | |
281 | \r | |
282 | return Tpl;\r | |
283 | }\r | |
284 | \r | |
285 | \r | |
286 | /**\r | |
287 | This function initializes a basic mutual exclusion lock to the released state\r | |
288 | and returns the lock. Each lock provides mutual exclusion access at its task\r | |
289 | priority level. Since there is no preemption or multiprocessor support in EFI,\r | |
290 | acquiring the lock only consists of raising to the locks TPL.\r | |
291 | If Lock is NULL, then ASSERT().\r | |
292 | If Priority is not a valid TPL value, then ASSERT().\r | |
293 | \r | |
294 | @param Lock A pointer to the lock data structure to initialize.\r | |
295 | @param Priority EFI TPL associated with the lock.\r | |
296 | \r | |
297 | @return The lock.\r | |
298 | \r | |
299 | **/\r | |
300 | EFI_LOCK *\r | |
301 | EFIAPI\r | |
302 | EfiInitializeLock (\r | |
303 | IN OUT EFI_LOCK *Lock,\r | |
304 | IN EFI_TPL Priority\r | |
305 | )\r | |
306 | {\r | |
307 | ASSERT (Lock != NULL);\r | |
308 | ASSERT (Priority <= TPL_HIGH_LEVEL);\r | |
309 | \r | |
310 | Lock->Tpl = Priority;\r | |
311 | Lock->OwnerTpl = TPL_APPLICATION;\r | |
312 | Lock->Lock = EfiLockReleased ;\r | |
313 | return Lock;\r | |
314 | }\r | |
315 | \r | |
316 | /**\r | |
317 | This function raises the system's current task priority level to the task\r | |
318 | priority level of the mutual exclusion lock. Then, it places the lock in the\r | |
319 | acquired state.\r | |
320 | If Lock is NULL, then ASSERT().\r | |
321 | If Lock is not initialized, then ASSERT().\r | |
322 | If Lock is already in the acquired state, then ASSERT().\r | |
323 | \r | |
324 | @param Lock The task lock with priority level.\r | |
325 | \r | |
326 | **/\r | |
327 | VOID\r | |
328 | EFIAPI\r | |
329 | EfiAcquireLock (\r | |
330 | IN EFI_LOCK *Lock\r | |
331 | )\r | |
332 | {\r | |
333 | ASSERT (Lock != NULL);\r | |
334 | ASSERT (Lock->Lock == EfiLockReleased);\r | |
335 | \r | |
336 | Lock->OwnerTpl = gBS->RaiseTPL (Lock->Tpl);\r | |
337 | Lock->Lock = EfiLockAcquired;\r | |
338 | }\r | |
339 | \r | |
340 | /**\r | |
341 | This function raises the system's current task priority level to the task\r | |
342 | priority level of the mutual exclusion lock. Then, it attempts to place the\r | |
343 | lock in the acquired state.\r | |
344 | \r | |
345 | @param Lock A pointer to the lock to acquire.\r | |
346 | \r | |
347 | @retval EFI_SUCCESS The lock was acquired.\r | |
348 | @retval EFI_ACCESS_DENIED The lock could not be acquired because it is already owned.\r | |
349 | \r | |
350 | **/\r | |
351 | EFI_STATUS\r | |
352 | EFIAPI\r | |
353 | EfiAcquireLockOrFail (\r | |
354 | IN EFI_LOCK *Lock\r | |
355 | )\r | |
356 | {\r | |
357 | \r | |
358 | ASSERT (Lock != NULL);\r | |
359 | ASSERT (Lock->Lock != EfiLockUninitialized);\r | |
360 | \r | |
361 | if (Lock->Lock == EfiLockAcquired) {\r | |
362 | //\r | |
363 | // Lock is already owned, so bail out\r | |
364 | //\r | |
365 | return EFI_ACCESS_DENIED;\r | |
366 | }\r | |
367 | \r | |
368 | Lock->OwnerTpl = gBS->RaiseTPL (Lock->Tpl);\r | |
369 | \r | |
370 | Lock->Lock = EfiLockAcquired;\r | |
371 | \r | |
372 | return EFI_SUCCESS;\r | |
373 | }\r | |
374 | \r | |
375 | /**\r | |
376 | This function transitions a mutual exclusion lock from the acquired state to\r | |
377 | the released state, and restores the system's task priority level to its\r | |
378 | previous level.\r | |
379 | \r | |
380 | @param Lock A pointer to the lock to release.\r | |
381 | \r | |
382 | **/\r | |
383 | VOID\r | |
384 | EFIAPI\r | |
385 | EfiReleaseLock (\r | |
386 | IN EFI_LOCK *Lock\r | |
387 | )\r | |
388 | {\r | |
389 | EFI_TPL Tpl;\r | |
390 | \r | |
391 | ASSERT (Lock != NULL);\r | |
392 | ASSERT (Lock->Lock == EfiLockAcquired);\r | |
393 | \r | |
394 | Tpl = Lock->OwnerTpl;\r | |
395 | \r | |
396 | Lock->Lock = EfiLockReleased;\r | |
397 | \r | |
398 | gBS->RestoreTPL (Tpl);\r | |
399 | }\r | |
400 | \r | |
401 | /**\r | |
402 | Tests whether a controller handle is being managed by a specific driver.\r | |
403 | \r | |
404 | This function tests whether the driver specified by DriverBindingHandle is\r | |
405 | currently managing the controller specified by ControllerHandle. This test\r | |
406 | is performed by evaluating if the the protocol specified by ProtocolGuid is\r | |
407 | present on ControllerHandle and is was opened by DriverBindingHandle with an\r | |
408 | attribute of EFI_OPEN_PROTOCOL_BY_DRIVER.\r | |
409 | If ProtocolGuid is NULL, then ASSERT().\r | |
410 | \r | |
411 | @param ControllerHandle A handle for a controller to test.\r | |
412 | @param DriverBindingHandle Specifies the driver binding handle for the\r | |
413 | driver.\r | |
414 | @param ProtocolGuid Specifies the protocol that the driver specified\r | |
415 | by DriverBindingHandle opens in its Start()\r | |
416 | function.\r | |
417 | \r | |
418 | @retval EFI_SUCCESS ControllerHandle is managed by the driver\r | |
419 | specifed by DriverBindingHandle.\r | |
420 | @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driver\r | |
421 | specifed by DriverBindingHandle.\r | |
422 | \r | |
423 | **/\r | |
424 | EFI_STATUS\r | |
425 | EFIAPI\r | |
426 | EfiTestManagedDevice (\r | |
427 | IN CONST EFI_HANDLE ControllerHandle,\r | |
428 | IN CONST EFI_HANDLE DriverBindingHandle,\r | |
429 | IN CONST EFI_GUID *ProtocolGuid\r | |
430 | )\r | |
431 | {\r | |
432 | EFI_STATUS Status;\r | |
433 | VOID *ManagedInterface;\r | |
434 | \r | |
435 | ASSERT (ProtocolGuid != NULL);\r | |
436 | \r | |
437 | Status = gBS->OpenProtocol (\r | |
438 | ControllerHandle,\r | |
439 | (EFI_GUID *) ProtocolGuid,\r | |
440 | &ManagedInterface,\r | |
441 | DriverBindingHandle,\r | |
442 | ControllerHandle,\r | |
443 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
444 | );\r | |
445 | if (!EFI_ERROR (Status)) {\r | |
446 | gBS->CloseProtocol (\r | |
447 | ControllerHandle,\r | |
448 | (EFI_GUID *) ProtocolGuid,\r | |
449 | DriverBindingHandle,\r | |
450 | ControllerHandle\r | |
451 | );\r | |
452 | return EFI_UNSUPPORTED;\r | |
453 | }\r | |
454 | \r | |
455 | if (Status != EFI_ALREADY_STARTED) {\r | |
456 | return EFI_UNSUPPORTED;\r | |
457 | }\r | |
458 | \r | |
459 | return EFI_SUCCESS;\r | |
460 | }\r | |
461 | \r | |
462 | /**\r | |
463 | Tests whether a child handle is a child device of the controller.\r | |
464 | \r | |
465 | This function tests whether ChildHandle is one of the children of\r | |
466 | ControllerHandle. This test is performed by checking to see if the protocol\r | |
467 | specified by ProtocolGuid is present on ControllerHandle and opened by\r | |
468 | ChildHandle with an attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r | |
469 | If ProtocolGuid is NULL, then ASSERT().\r | |
470 | \r | |
471 | @param ControllerHandle A handle for a (parent) controller to test.\r | |
472 | @param ChildHandle A child handle to test.\r | |
473 | @param ProtocolGuid Supplies the protocol that the child controller\r | |
474 | opens on its parent controller.\r | |
475 | \r | |
476 | @retval EFI_SUCCESS ChildHandle is a child of the ControllerHandle.\r | |
477 | @retval EFI_UNSUPPORTED ChildHandle is not a child of the\r | |
478 | ControllerHandle.\r | |
479 | \r | |
480 | **/\r | |
481 | EFI_STATUS\r | |
482 | EFIAPI\r | |
483 | EfiTestChildHandle (\r | |
484 | IN CONST EFI_HANDLE ControllerHandle,\r | |
485 | IN CONST EFI_HANDLE ChildHandle,\r | |
486 | IN CONST EFI_GUID *ProtocolGuid\r | |
487 | )\r | |
488 | {\r | |
489 | EFI_STATUS Status;\r | |
490 | EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r | |
491 | UINTN EntryCount;\r | |
492 | UINTN Index;\r | |
493 | \r | |
494 | ASSERT (ProtocolGuid != NULL);\r | |
495 | \r | |
496 | //\r | |
497 | // Retrieve the list of agents that are consuming the specific protocol\r | |
498 | // on ControllerHandle.\r | |
499 | //\r | |
500 | Status = gBS->OpenProtocolInformation (\r | |
501 | ControllerHandle,\r | |
502 | (EFI_GUID *) ProtocolGuid,\r | |
503 | &OpenInfoBuffer,\r | |
504 | &EntryCount\r | |
505 | );\r | |
506 | if (EFI_ERROR (Status)) {\r | |
507 | return EFI_UNSUPPORTED;\r | |
508 | }\r | |
509 | \r | |
510 | //\r | |
511 | // Inspect if ChildHandle is one of the agents.\r | |
512 | //\r | |
513 | Status = EFI_UNSUPPORTED;\r | |
514 | for (Index = 0; Index < EntryCount; Index++) {\r | |
515 | if ((OpenInfoBuffer[Index].ControllerHandle == ChildHandle) &&\r | |
516 | (OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r | |
517 | Status = EFI_SUCCESS;\r | |
518 | break;\r | |
519 | }\r | |
520 | }\r | |
521 | \r | |
522 | FreePool (OpenInfoBuffer);\r | |
523 | return Status;\r | |
524 | }\r | |
525 | \r | |
526 | /**\r | |
527 | This function looks up a Unicode string in UnicodeStringTable.\r | |
528 | If Language is a member of SupportedLanguages and a Unicode\r | |
529 | string is found in UnicodeStringTable that matches the\r | |
530 | language code specified by Language, then it is returned in\r | |
531 | UnicodeString.\r | |
532 | \r | |
533 | @param Language A pointer to the ISO 639-2\r | |
534 | language code for the Unicode\r | |
535 | string to look up and return.\r | |
536 | \r | |
537 | @param SupportedLanguages A pointer to the set of ISO\r | |
538 | 639-2language\r | |
539 | codes that the Unicode string\r | |
540 | table supports. Language must\r | |
541 | be a member of this set.\r | |
542 | \r | |
543 | @param UnicodeStringTable A pointer to the table of\r | |
544 | Unicode strings.\r | |
545 | \r | |
546 | @param UnicodeString A pointer to the Unicode\r | |
547 | string from UnicodeStringTable\r | |
548 | that matches the language\r | |
549 | specified by Language.\r | |
550 | \r | |
551 | @retval EFI_SUCCESS The Unicode string that\r | |
552 | matches the language specified\r | |
553 | by Language was found in the\r | |
554 | table of Unicoide strings\r | |
555 | UnicodeStringTable, and it was\r | |
556 | returned in UnicodeString.\r | |
557 | \r | |
558 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
559 | \r | |
560 | @retval EFI_INVALID_PARAMETER UnicodeString is NULL.\r | |
561 | @retval EFI_UNSUPPORTED SupportedLanguages is NULL.\r | |
562 | \r | |
563 | @retval EFI_UNSUPPORTED UnicodeStringTable is NULL.\r | |
564 | \r | |
565 | @retval EFI_UNSUPPORTED The language specified by\r | |
566 | Language is not a member\r | |
567 | ofSupportedLanguages.\r | |
568 | \r | |
569 | @retval EFI_UNSUPPORTED The language specified by\r | |
570 | Language is not supported by\r | |
571 | UnicodeStringTable.\r | |
572 | \r | |
573 | **/\r | |
574 | EFI_STATUS\r | |
575 | EFIAPI\r | |
576 | LookupUnicodeString (\r | |
577 | IN CONST CHAR8 *Language,\r | |
578 | IN CONST CHAR8 *SupportedLanguages,\r | |
579 | IN CONST EFI_UNICODE_STRING_TABLE *UnicodeStringTable,\r | |
580 | OUT CHAR16 **UnicodeString\r | |
581 | )\r | |
582 | {\r | |
583 | //\r | |
584 | // Make sure the parameters are valid\r | |
585 | //\r | |
586 | if (Language == NULL || UnicodeString == NULL) {\r | |
587 | return EFI_INVALID_PARAMETER;\r | |
588 | }\r | |
589 | \r | |
590 | //\r | |
591 | // If there are no supported languages, or the Unicode String Table is empty, then the\r | |
592 | // Unicode String specified by Language is not supported by this Unicode String Table\r | |
593 | //\r | |
594 | if (SupportedLanguages == NULL || UnicodeStringTable == NULL) {\r | |
595 | return EFI_UNSUPPORTED;\r | |
596 | }\r | |
597 | \r | |
598 | //\r | |
599 | // Make sure Language is in the set of Supported Languages\r | |
600 | //\r | |
601 | while (*SupportedLanguages != 0) {\r | |
602 | if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r | |
603 | \r | |
604 | //\r | |
605 | // Search the Unicode String Table for the matching Language specifier\r | |
606 | //\r | |
607 | while (UnicodeStringTable->Language != NULL) {\r | |
608 | if (CompareIso639LanguageCode (Language, UnicodeStringTable->Language)) {\r | |
609 | \r | |
610 | //\r | |
611 | // A matching string was found, so return it\r | |
612 | //\r | |
613 | *UnicodeString = UnicodeStringTable->UnicodeString;\r | |
614 | return EFI_SUCCESS;\r | |
615 | }\r | |
616 | \r | |
617 | UnicodeStringTable++;\r | |
618 | }\r | |
619 | \r | |
620 | return EFI_UNSUPPORTED;\r | |
621 | }\r | |
622 | \r | |
623 | SupportedLanguages += 3;\r | |
624 | }\r | |
625 | \r | |
626 | return EFI_UNSUPPORTED;\r | |
627 | }\r | |
628 | \r | |
629 | \r | |
630 | \r | |
631 | /**\r | |
632 | This function looks up a Unicode string in UnicodeStringTable.\r | |
633 | If Language is a member of SupportedLanguages and a Unicode\r | |
634 | string is found in UnicodeStringTable that matches the\r | |
635 | language code specified by Language, then it is returned in\r | |
636 | UnicodeString.\r | |
637 | \r | |
638 | @param Language A pointer to the ISO 639-2 or\r | |
639 | RFC 3066 language code for the\r | |
640 | Unicode string to look up and\r | |
641 | return.\r | |
642 | \r | |
643 | @param SupportedLanguages A pointer to the set of ISO\r | |
644 | 639-2 or RFC 3066 language\r | |
645 | codes that the Unicode string\r | |
646 | table supports. Language must\r | |
647 | be a member of this set.\r | |
648 | \r | |
649 | @param UnicodeStringTable A pointer to the table of\r | |
650 | Unicode strings.\r | |
651 | \r | |
652 | @param UnicodeString A pointer to the Unicode\r | |
653 | string from UnicodeStringTable\r | |
654 | that matches the language\r | |
655 | specified by Language.\r | |
656 | \r | |
657 | @param Iso639Language Specify the language code\r | |
658 | format supported. If true,\r | |
659 | then the format follow ISO\r | |
660 | 639-2. If false, then it\r | |
661 | follows RFC3066.\r | |
662 | \r | |
663 | @retval EFI_SUCCESS The Unicode string that\r | |
664 | matches the language specified\r | |
665 | by Language was found in the\r | |
666 | table of Unicoide strings\r | |
667 | UnicodeStringTable, and it was\r | |
668 | returned in UnicodeString.\r | |
669 | \r | |
670 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
671 | \r | |
672 | @retval EFI_INVALID_PARAMETER UnicodeString is NULL.\r | |
673 | \r | |
674 | @retval EFI_UNSUPPORTED SupportedLanguages is NULL.\r | |
675 | \r | |
676 | @retval EFI_UNSUPPORTED UnicodeStringTable is NULL.\r | |
677 | \r | |
678 | @retval EFI_UNSUPPORTED The language specified by\r | |
679 | Language is not a member\r | |
680 | ofSupportedLanguages.\r | |
681 | \r | |
682 | @retval EFI_UNSUPPORTED The language specified by\r | |
683 | Language is not supported by\r | |
684 | UnicodeStringTable.\r | |
685 | \r | |
686 | **/\r | |
687 | EFI_STATUS\r | |
688 | \r | |
689 | EFIAPI\r | |
690 | LookupUnicodeString2 (\r | |
691 | IN CONST CHAR8 *Language,\r | |
692 | IN CONST CHAR8 *SupportedLanguages,\r | |
693 | IN CONST EFI_UNICODE_STRING_TABLE *UnicodeStringTable,\r | |
694 | OUT CHAR16 **UnicodeString,\r | |
695 | IN BOOLEAN Iso639Language\r | |
696 | )\r | |
697 | {\r | |
698 | BOOLEAN Found;\r | |
699 | UINTN Index;\r | |
700 | CHAR8 *LanguageString;\r | |
701 | \r | |
702 | //\r | |
703 | // Make sure the parameters are valid\r | |
704 | //\r | |
705 | if (Language == NULL || UnicodeString == NULL) {\r | |
706 | return EFI_INVALID_PARAMETER;\r | |
707 | }\r | |
708 | \r | |
709 | //\r | |
710 | // If there are no supported languages, or the Unicode String Table is empty, then the\r | |
711 | // Unicode String specified by Language is not supported by this Unicode String Table\r | |
712 | //\r | |
713 | if (SupportedLanguages == NULL || UnicodeStringTable == NULL) {\r | |
714 | return EFI_UNSUPPORTED;\r | |
715 | }\r | |
716 | \r | |
717 | //\r | |
718 | // Make sure Language is in the set of Supported Languages\r | |
719 | //\r | |
720 | Found = FALSE;\r | |
721 | while (*SupportedLanguages != 0) {\r | |
722 | if (Iso639Language) {\r | |
723 | if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r | |
724 | Found = TRUE;\r | |
725 | break;\r | |
726 | }\r | |
727 | SupportedLanguages += 3;\r | |
728 | } else {\r | |
729 | for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++);\r | |
730 | if ((AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) && (Language[Index] == 0)) {\r | |
731 | Found = TRUE;\r | |
732 | break;\r | |
733 | }\r | |
734 | SupportedLanguages += Index;\r | |
735 | for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++);\r | |
736 | }\r | |
737 | }\r | |
738 | \r | |
739 | //\r | |
740 | // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED\r | |
741 | //\r | |
742 | if (!Found) {\r | |
743 | return EFI_UNSUPPORTED;\r | |
744 | }\r | |
745 | \r | |
746 | //\r | |
747 | // Search the Unicode String Table for the matching Language specifier\r | |
748 | //\r | |
749 | while (UnicodeStringTable->Language != NULL) {\r | |
750 | LanguageString = UnicodeStringTable->Language;\r | |
751 | while (0 != *LanguageString) {\r | |
752 | for (Index = 0 ;LanguageString[Index] != 0 && LanguageString[Index] != ';'; Index++);\r | |
753 | if (AsciiStrnCmp(LanguageString, Language, Index) == 0) {\r | |
754 | *UnicodeString = UnicodeStringTable->UnicodeString;\r | |
755 | return EFI_SUCCESS;\r | |
756 | }\r | |
757 | LanguageString += Index;\r | |
758 | for (Index = 0 ;LanguageString[Index] != 0 && LanguageString[Index] == ';'; Index++);\r | |
759 | }\r | |
760 | UnicodeStringTable++;\r | |
761 | }\r | |
762 | \r | |
763 | return EFI_UNSUPPORTED;\r | |
764 | }\r | |
765 | \r | |
766 | \r | |
767 | /**\r | |
768 | \r | |
769 | This function adds a Unicode string to UnicodeStringTable.\r | |
770 | If Language is a member of SupportedLanguages then\r | |
771 | UnicodeString is added to UnicodeStringTable. New buffers are\r | |
772 | allocated for both Language and UnicodeString. The contents\r | |
773 | of Language and UnicodeString are copied into these new\r | |
774 | buffers. These buffers are automatically freed when\r | |
775 | FreeUnicodeStringTable() is called.\r | |
776 | \r | |
777 | @param Language A pointer to the ISO 639-2\r | |
778 | language code for the Unicode\r | |
779 | string to add.\r | |
780 | \r | |
781 | @param SupportedLanguages A pointer to the set of ISO\r | |
782 | 639-2 language codes that the\r | |
783 | Unicode string table supports.\r | |
784 | Language must be a member of\r | |
785 | this set.\r | |
786 | \r | |
787 | @param UnicodeStringTable A pointer to the table of\r | |
788 | Unicode strings.\r | |
789 | \r | |
790 | @param UnicodeString A pointer to the Unicode\r | |
791 | string to add.\r | |
792 | \r | |
793 | @retval EFI_SUCCESS The Unicode string that\r | |
794 | matches the language specified\r | |
795 | by Language was found in the\r | |
796 | table of Unicode strings\r | |
797 | UnicodeStringTable, and it was\r | |
798 | returned in UnicodeString.\r | |
799 | \r | |
800 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
801 | \r | |
802 | @retval EFI_INVALID_PARAMETER UnicodeString is NULL.\r | |
803 | \r | |
804 | @retval EFI_INVALID_PARAMETER UnicodeString is an empty string.\r | |
805 | \r | |
806 | @retval EFI_UNSUPPORTED SupportedLanguages is NULL.\r | |
807 | \r | |
808 | @retval EFI_ALREADY_STARTED A Unicode string with language\r | |
809 | Language is already present in\r | |
810 | UnicodeStringTable.\r | |
811 | \r | |
812 | @retval EFI_OUT_OF_RESOURCES There is not enough memory to\r | |
813 | add another Unicode string to\r | |
814 | UnicodeStringTable.\r | |
815 | \r | |
816 | @retval EFI_UNSUPPORTED The language specified by\r | |
817 | Language is not a member of\r | |
818 | SupportedLanguages.\r | |
819 | \r | |
820 | **/\r | |
821 | EFI_STATUS\r | |
822 | EFIAPI\r | |
823 | AddUnicodeString (\r | |
824 | IN CONST CHAR8 *Language,\r | |
825 | IN CONST CHAR8 *SupportedLanguages,\r | |
826 | IN EFI_UNICODE_STRING_TABLE **UnicodeStringTable,\r | |
827 | IN CONST CHAR16 *UnicodeString\r | |
828 | )\r | |
829 | {\r | |
830 | UINTN NumberOfEntries;\r | |
831 | EFI_UNICODE_STRING_TABLE *OldUnicodeStringTable;\r | |
832 | EFI_UNICODE_STRING_TABLE *NewUnicodeStringTable;\r | |
833 | UINTN UnicodeStringLength;\r | |
834 | \r | |
835 | //\r | |
836 | // Make sure the parameter are valid\r | |
837 | //\r | |
838 | if (Language == NULL || UnicodeString == NULL || UnicodeStringTable == NULL) {\r | |
839 | return EFI_INVALID_PARAMETER;\r | |
840 | }\r | |
841 | \r | |
842 | //\r | |
843 | // If there are no supported languages, then a Unicode String can not be added\r | |
844 | //\r | |
845 | if (SupportedLanguages == NULL) {\r | |
846 | return EFI_UNSUPPORTED;\r | |
847 | }\r | |
848 | \r | |
849 | //\r | |
850 | // If the Unicode String is empty, then a Unicode String can not be added\r | |
851 | //\r | |
852 | if (UnicodeString[0] == 0) {\r | |
853 | return EFI_INVALID_PARAMETER;\r | |
854 | }\r | |
855 | \r | |
856 | //\r | |
857 | // Make sure Language is a member of SupportedLanguages\r | |
858 | //\r | |
859 | while (*SupportedLanguages != 0) {\r | |
860 | if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r | |
861 | \r | |
862 | //\r | |
863 | // Determine the size of the Unicode String Table by looking for a NULL Language entry\r | |
864 | //\r | |
865 | NumberOfEntries = 0;\r | |
866 | if (*UnicodeStringTable != NULL) {\r | |
867 | OldUnicodeStringTable = *UnicodeStringTable;\r | |
868 | while (OldUnicodeStringTable->Language != NULL) {\r | |
869 | if (CompareIso639LanguageCode (Language, OldUnicodeStringTable->Language)) {\r | |
870 | return EFI_ALREADY_STARTED;\r | |
871 | }\r | |
872 | \r | |
873 | OldUnicodeStringTable++;\r | |
874 | NumberOfEntries++;\r | |
875 | }\r | |
876 | }\r | |
877 | \r | |
878 | //\r | |
879 | // Allocate space for a new Unicode String Table. It must hold the current number of\r | |
880 | // entries, plus 1 entry for the new Unicode String, plus 1 entry for the end of table\r | |
881 | // marker\r | |
882 | //\r | |
883 | NewUnicodeStringTable = AllocatePool ((NumberOfEntries + 2) * sizeof (EFI_UNICODE_STRING_TABLE));\r | |
884 | if (NewUnicodeStringTable == NULL) {\r | |
885 | return EFI_OUT_OF_RESOURCES;\r | |
886 | }\r | |
887 | \r | |
888 | //\r | |
889 | // If the current Unicode String Table contains any entries, then copy them to the\r | |
890 | // newly allocated Unicode String Table.\r | |
891 | //\r | |
892 | if (*UnicodeStringTable != NULL) {\r | |
893 | CopyMem (\r | |
894 | NewUnicodeStringTable,\r | |
895 | *UnicodeStringTable,\r | |
896 | NumberOfEntries * sizeof (EFI_UNICODE_STRING_TABLE)\r | |
897 | );\r | |
898 | }\r | |
899 | \r | |
900 | //\r | |
901 | // Allocate space for a copy of the Language specifier\r | |
902 | //\r | |
903 | NewUnicodeStringTable[NumberOfEntries].Language = AllocateCopyPool (3, Language);\r | |
904 | if (NewUnicodeStringTable[NumberOfEntries].Language == NULL) {\r | |
905 | gBS->FreePool (NewUnicodeStringTable);\r | |
906 | return EFI_OUT_OF_RESOURCES;\r | |
907 | }\r | |
908 | \r | |
909 | //\r | |
910 | // Compute the length of the Unicode String\r | |
911 | //\r | |
912 | for (UnicodeStringLength = 0; UnicodeString[UnicodeStringLength] != 0; UnicodeStringLength++)\r | |
913 | ;\r | |
914 | \r | |
915 | //\r | |
916 | // Allocate space for a copy of the Unicode String\r | |
917 | //\r | |
918 | NewUnicodeStringTable[NumberOfEntries].UnicodeString = AllocateCopyPool (\r | |
919 | (UnicodeStringLength + 1) * sizeof (CHAR16),\r | |
920 | UnicodeString\r | |
921 | );\r | |
922 | if (NewUnicodeStringTable[NumberOfEntries].UnicodeString == NULL) {\r | |
923 | gBS->FreePool (NewUnicodeStringTable[NumberOfEntries].Language);\r | |
924 | gBS->FreePool (NewUnicodeStringTable);\r | |
925 | return EFI_OUT_OF_RESOURCES;\r | |
926 | }\r | |
927 | \r | |
928 | //\r | |
929 | // Mark the end of the Unicode String Table\r | |
930 | //\r | |
931 | NewUnicodeStringTable[NumberOfEntries + 1].Language = NULL;\r | |
932 | NewUnicodeStringTable[NumberOfEntries + 1].UnicodeString = NULL;\r | |
933 | \r | |
934 | //\r | |
935 | // Free the old Unicode String Table\r | |
936 | //\r | |
937 | if (*UnicodeStringTable != NULL) {\r | |
938 | gBS->FreePool (*UnicodeStringTable);\r | |
939 | }\r | |
940 | \r | |
941 | //\r | |
942 | // Point UnicodeStringTable at the newly allocated Unicode String Table\r | |
943 | //\r | |
944 | *UnicodeStringTable = NewUnicodeStringTable;\r | |
945 | \r | |
946 | return EFI_SUCCESS;\r | |
947 | }\r | |
948 | \r | |
949 | SupportedLanguages += 3;\r | |
950 | }\r | |
951 | \r | |
952 | return EFI_UNSUPPORTED;\r | |
953 | }\r | |
954 | \r | |
955 | \r | |
956 | /**\r | |
957 | \r | |
958 | This function adds a Unicode string to UnicodeStringTable.\r | |
959 | If Language is a member of SupportedLanguages then\r | |
960 | UnicodeString is added to UnicodeStringTable. New buffers are\r | |
961 | allocated for both Language and UnicodeString. The contents\r | |
962 | of Language and UnicodeString are copied into these new\r | |
963 | buffers. These buffers are automatically freed when\r | |
964 | FreeUnicodeStringTable() is called.\r | |
965 | \r | |
966 | @param Language A pointer to the ISO 639-2 or\r | |
967 | RFC 3066 language code for the\r | |
968 | Unicode string to add.\r | |
969 | \r | |
970 | @param SupportedLanguages A pointer to the set of ISO\r | |
971 | 639-2 or RFC 3.66 language\r | |
972 | codes that the Unicode string\r | |
973 | table supports. Language must\r | |
974 | be a member of this set.\r | |
975 | \r | |
976 | @param UnicodeStringTable A pointer to the table of\r | |
977 | Unicode strings.\r | |
978 | \r | |
979 | @param UnicodeString A pointer to the Unicode\r | |
980 | string to add.\r | |
981 | \r | |
982 | @param Iso639Language Specify the language code\r | |
983 | format supported. If true,\r | |
984 | then the format follow ISO\r | |
985 | 639-2. If false, then it\r | |
986 | follows RFC3066.\r | |
987 | \r | |
988 | @retval EFI_SUCCESS The Unicode string that\r | |
989 | matches the language specified\r | |
990 | by Language was found in the\r | |
991 | table of Unicode strings\r | |
992 | UnicodeStringTable, and it was\r | |
993 | returned in UnicodeString.\r | |
994 | \r | |
995 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
996 | \r | |
997 | @retval EFI_INVALID_PARAMETER UnicodeString is NULL.\r | |
998 | \r | |
999 | @retval EFI_INVALID_PARAMETER UnicodeString is an empty string.\r | |
1000 | \r | |
1001 | @retval EFI_UNSUPPORTED SupportedLanguages is NULL.\r | |
1002 | \r | |
1003 | @retval EFI_ALREADY_STARTED A Unicode string with language\r | |
1004 | Language is already present in\r | |
1005 | UnicodeStringTable.\r | |
1006 | \r | |
1007 | @retval EFI_OUT_OF_RESOURCES There is not enough memory to\r | |
1008 | add another Unicode string to\r | |
1009 | UnicodeStringTable.\r | |
1010 | \r | |
1011 | @retval EFI_UNSUPPORTED The language specified by\r | |
1012 | Language is not a member of\r | |
1013 | SupportedLanguages.\r | |
1014 | \r | |
1015 | **/\r | |
1016 | EFI_STATUS\r | |
1017 | EFIAPI\r | |
1018 | AddUnicodeString2 (\r | |
1019 | IN CONST CHAR8 *Language,\r | |
1020 | IN CONST CHAR8 *SupportedLanguages,\r | |
1021 | IN EFI_UNICODE_STRING_TABLE **UnicodeStringTable,\r | |
1022 | IN CONST CHAR16 *UnicodeString,\r | |
1023 | IN BOOLEAN Iso639Language\r | |
1024 | )\r | |
1025 | {\r | |
1026 | UINTN NumberOfEntries;\r | |
1027 | EFI_UNICODE_STRING_TABLE *OldUnicodeStringTable;\r | |
1028 | EFI_UNICODE_STRING_TABLE *NewUnicodeStringTable;\r | |
1029 | UINTN UnicodeStringLength;\r | |
1030 | BOOLEAN Found;\r | |
1031 | UINTN Index;\r | |
1032 | CHAR8 *LanguageString;\r | |
1033 | \r | |
1034 | //\r | |
1035 | // Make sure the parameter are valid\r | |
1036 | //\r | |
1037 | if (Language == NULL || UnicodeString == NULL || UnicodeStringTable == NULL) {\r | |
1038 | return EFI_INVALID_PARAMETER;\r | |
1039 | }\r | |
1040 | \r | |
1041 | //\r | |
1042 | // If there are no supported languages, then a Unicode String can not be added\r | |
1043 | //\r | |
1044 | if (SupportedLanguages == NULL) {\r | |
1045 | return EFI_UNSUPPORTED;\r | |
1046 | }\r | |
1047 | \r | |
1048 | //\r | |
1049 | // If the Unicode String is empty, then a Unicode String can not be added\r | |
1050 | //\r | |
1051 | if (UnicodeString[0] == 0) {\r | |
1052 | return EFI_INVALID_PARAMETER;\r | |
1053 | }\r | |
1054 | \r | |
1055 | //\r | |
1056 | // Make sure Language is a member of SupportedLanguages\r | |
1057 | //\r | |
1058 | Found = FALSE;\r | |
1059 | while (*SupportedLanguages != 0) {\r | |
1060 | if (Iso639Language) {\r | |
1061 | if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r | |
1062 | Found = TRUE;\r | |
1063 | break;\r | |
1064 | }\r | |
1065 | SupportedLanguages += 3;\r | |
1066 | } else {\r | |
1067 | for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++);\r | |
1068 | if (AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) {\r | |
1069 | Found = TRUE;\r | |
1070 | break;\r | |
1071 | }\r | |
1072 | SupportedLanguages += Index;\r | |
1073 | for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++);\r | |
1074 | }\r | |
1075 | }\r | |
1076 | \r | |
1077 | //\r | |
1078 | // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED\r | |
1079 | //\r | |
1080 | if (!Found) {\r | |
1081 | return EFI_UNSUPPORTED;\r | |
1082 | }\r | |
1083 | \r | |
1084 | //\r | |
1085 | // Determine the size of the Unicode String Table by looking for a NULL Language entry\r | |
1086 | //\r | |
1087 | NumberOfEntries = 0;\r | |
1088 | if (*UnicodeStringTable != NULL) {\r | |
1089 | OldUnicodeStringTable = *UnicodeStringTable;\r | |
1090 | while (OldUnicodeStringTable->Language != NULL) {\r | |
1091 | LanguageString = OldUnicodeStringTable->Language;\r | |
1092 | \r | |
1093 | while (*LanguageString != 0) {\r | |
1094 | for (Index = 0; LanguageString[Index] != 0 && LanguageString[Index] != ';'; Index++);\r | |
1095 | \r | |
1096 | if (AsciiStrnCmp (Language, LanguageString, Index) == 0) { \r | |
1097 | return EFI_ALREADY_STARTED;\r | |
1098 | }\r | |
1099 | LanguageString += Index;\r | |
1100 | for (; *LanguageString != 0 && *LanguageString == ';'; LanguageString++);\r | |
1101 | }\r | |
1102 | OldUnicodeStringTable++;\r | |
1103 | NumberOfEntries++;\r | |
1104 | }\r | |
1105 | }\r | |
1106 | \r | |
1107 | //\r | |
1108 | // Allocate space for a new Unicode String Table. It must hold the current number of\r | |
1109 | // entries, plus 1 entry for the new Unicode String, plus 1 entry for the end of table\r | |
1110 | // marker\r | |
1111 | //\r | |
1112 | NewUnicodeStringTable = AllocatePool ((NumberOfEntries + 2) * sizeof (EFI_UNICODE_STRING_TABLE));\r | |
1113 | if (NewUnicodeStringTable == NULL) {\r | |
1114 | return EFI_OUT_OF_RESOURCES;\r | |
1115 | }\r | |
1116 | \r | |
1117 | //\r | |
1118 | // If the current Unicode String Table contains any entries, then copy them to the\r | |
1119 | // newly allocated Unicode String Table.\r | |
1120 | //\r | |
1121 | if (*UnicodeStringTable != NULL) {\r | |
1122 | CopyMem (\r | |
1123 | NewUnicodeStringTable,\r | |
1124 | *UnicodeStringTable,\r | |
1125 | NumberOfEntries * sizeof (EFI_UNICODE_STRING_TABLE)\r | |
1126 | );\r | |
1127 | }\r | |
1128 | \r | |
1129 | //\r | |
1130 | // Allocate space for a copy of the Language specifier\r | |
1131 | //\r | |
1132 | NewUnicodeStringTable[NumberOfEntries].Language = AllocateCopyPool (AsciiStrSize(Language), Language);\r | |
1133 | if (NewUnicodeStringTable[NumberOfEntries].Language == NULL) {\r | |
1134 | gBS->FreePool (NewUnicodeStringTable);\r | |
1135 | return EFI_OUT_OF_RESOURCES;\r | |
1136 | }\r | |
1137 | \r | |
1138 | //\r | |
1139 | // Compute the length of the Unicode String\r | |
1140 | //\r | |
1141 | for (UnicodeStringLength = 0; UnicodeString[UnicodeStringLength] != 0; UnicodeStringLength++);\r | |
1142 | \r | |
1143 | //\r | |
1144 | // Allocate space for a copy of the Unicode String\r | |
1145 | //\r | |
1146 | NewUnicodeStringTable[NumberOfEntries].UnicodeString = AllocateCopyPool (StrSize (UnicodeString), UnicodeString);\r | |
1147 | if (NewUnicodeStringTable[NumberOfEntries].UnicodeString == NULL) {\r | |
1148 | gBS->FreePool (NewUnicodeStringTable[NumberOfEntries].Language);\r | |
1149 | gBS->FreePool (NewUnicodeStringTable);\r | |
1150 | return EFI_OUT_OF_RESOURCES;\r | |
1151 | }\r | |
1152 | \r | |
1153 | //\r | |
1154 | // Mark the end of the Unicode String Table\r | |
1155 | //\r | |
1156 | NewUnicodeStringTable[NumberOfEntries + 1].Language = NULL;\r | |
1157 | NewUnicodeStringTable[NumberOfEntries + 1].UnicodeString = NULL;\r | |
1158 | \r | |
1159 | //\r | |
1160 | // Free the old Unicode String Table\r | |
1161 | //\r | |
1162 | if (*UnicodeStringTable != NULL) {\r | |
1163 | gBS->FreePool (*UnicodeStringTable);\r | |
1164 | }\r | |
1165 | \r | |
1166 | //\r | |
1167 | // Point UnicodeStringTable at the newly allocated Unicode String Table\r | |
1168 | //\r | |
1169 | *UnicodeStringTable = NewUnicodeStringTable;\r | |
1170 | \r | |
1171 | return EFI_SUCCESS;\r | |
1172 | }\r | |
1173 | \r | |
1174 | /**\r | |
1175 | This function frees the table of Unicode strings in UnicodeStringTable.\r | |
1176 | If UnicodeStringTable is NULL, then EFI_SUCCESS is returned.\r | |
1177 | Otherwise, each language code, and each Unicode string in the Unicode string \r | |
1178 | table are freed, and EFI_SUCCESS is returned.\r | |
1179 | \r | |
1180 | @param UnicodeStringTable A pointer to the table of Unicode strings.\r | |
1181 | \r | |
1182 | @retval EFI_SUCCESS The Unicode string table was freed.\r | |
1183 | \r | |
1184 | **/\r | |
1185 | EFI_STATUS\r | |
1186 | EFIAPI\r | |
1187 | FreeUnicodeStringTable (\r | |
1188 | IN EFI_UNICODE_STRING_TABLE *UnicodeStringTable\r | |
1189 | )\r | |
1190 | {\r | |
1191 | UINTN Index;\r | |
1192 | \r | |
1193 | //\r | |
1194 | // If the Unicode String Table is NULL, then it is already freed\r | |
1195 | //\r | |
1196 | if (UnicodeStringTable == NULL) {\r | |
1197 | return EFI_SUCCESS;\r | |
1198 | }\r | |
1199 | \r | |
1200 | //\r | |
1201 | // Loop through the Unicode String Table until we reach the end of table marker\r | |
1202 | //\r | |
1203 | for (Index = 0; UnicodeStringTable[Index].Language != NULL; Index++) {\r | |
1204 | \r | |
1205 | //\r | |
1206 | // Free the Language string from the Unicode String Table\r | |
1207 | //\r | |
1208 | gBS->FreePool (UnicodeStringTable[Index].Language);\r | |
1209 | \r | |
1210 | //\r | |
1211 | // Free the Unicode String from the Unicode String Table\r | |
1212 | //\r | |
1213 | if (UnicodeStringTable[Index].UnicodeString != NULL) {\r | |
1214 | gBS->FreePool (UnicodeStringTable[Index].UnicodeString);\r | |
1215 | }\r | |
1216 | }\r | |
1217 | \r | |
1218 | //\r | |
1219 | // Free the Unicode String Table itself\r | |
1220 | //\r | |
1221 | gBS->FreePool (UnicodeStringTable);\r | |
1222 | \r | |
1223 | return EFI_SUCCESS;\r | |
1224 | }\r | |
1225 | \r | |
1226 | \r |