]>
Commit | Line | Data |
---|---|---|
e386b444 | 1 | /** @file\r |
5ad97f35 | 2 | The UEFI Library provides functions and macros that simplify the development of \r |
3 | UEFI Drivers and UEFI Applications. These functions and macros help manage EFI \r | |
4 | events, build simple locks utilizing EFI Task Priority Levels (TPLs), install \r | |
5 | EFI Driver Model related protocols, manage Unicode string tables for UEFI Drivers, \r | |
6 | and print messages on the console output and standard error devices.\r | |
e386b444 | 7 | \r |
bf4a3dbd | 8 | Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r |
19388d29 | 9 | This program and the accompanying materials\r |
e386b444 | 10 | are licensed and made available under the terms and conditions of the BSD License\r |
11 | which accompanies this distribution. The full text of the license may be found at\r | |
2fc59a00 | 12 | http://opensource.org/licenses/bsd-license.php.\r |
e386b444 | 13 | \r |
14 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
15 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
16 | \r | |
e386b444 | 17 | **/\r |
18 | \r | |
1efcc4ae | 19 | \r |
f734a10a | 20 | #include "UefiLibInternal.h"\r |
e386b444 | 21 | \r |
5bd2d2cb | 22 | /**\r |
23 | Empty constructor function that is required to resolve dependencies between \r | |
24 | libraries.\r | |
25 | \r | |
26 | ** DO NOT REMOVE **\r | |
27 | \r | |
28 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
29 | @param SystemTable A pointer to the EFI System Table.\r | |
30 | \r | |
31 | @retval EFI_SUCCESS The constructor executed correctly.\r | |
32 | \r | |
33 | **/\r | |
34 | EFI_STATUS\r | |
35 | EFIAPI\r | |
36 | UefiLibConstructor (\r | |
37 | IN EFI_HANDLE ImageHandle,\r | |
38 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
39 | )\r | |
40 | {\r | |
41 | return EFI_SUCCESS;\r | |
42 | }\r | |
43 | \r | |
e386b444 | 44 | /**\r |
45 | Compare whether two names of languages are identical.\r | |
46 | \r | |
47 | @param Language1 Name of language 1.\r | |
48 | @param Language2 Name of language 2.\r | |
49 | \r | |
50 | @retval TRUE Language 1 and language 2 are the same.\r | |
51 | @retval FALSE Language 1 and language 2 are not the same.\r | |
52 | \r | |
53 | **/\r | |
e386b444 | 54 | BOOLEAN\r |
55 | CompareIso639LanguageCode (\r | |
56 | IN CONST CHAR8 *Language1,\r | |
57 | IN CONST CHAR8 *Language2\r | |
58 | )\r | |
59 | {\r | |
60 | UINT32 Name1;\r | |
61 | UINT32 Name2;\r | |
62 | \r | |
63 | Name1 = ReadUnaligned24 ((CONST UINT32 *) Language1);\r | |
64 | Name2 = ReadUnaligned24 ((CONST UINT32 *) Language2);\r | |
65 | \r | |
66 | return (BOOLEAN) (Name1 == Name2);\r | |
67 | }\r | |
68 | \r | |
69 | /**\r | |
1d37ab9f | 70 | Retrieves a pointer to the system configuration table from the EFI System Table\r |
71 | based on a specified GUID.\r | |
72 | \r | |
73 | This function searches the list of configuration tables stored in the EFI System Table\r | |
74 | for a table with a GUID that matches TableGuid. If a match is found, then a pointer to\r | |
75 | the configuration table is returned in Table., and EFI_SUCCESS is returned. If a matching GUID\r | |
76 | is not found, then EFI_NOT_FOUND is returned.\r | |
9edc73ad | 77 | If TableGuid is NULL, then ASSERT().\r |
78 | If Table is NULL, then ASSERT().\r | |
e386b444 | 79 | \r |
58380e9c | 80 | @param TableGuid The pointer to table's GUID type.\r |
2fc59a00 | 81 | @param Table The pointer to the table associated with TableGuid in the EFI System Table.\r |
e386b444 | 82 | \r |
83 | @retval EFI_SUCCESS A configuration table matching TableGuid was found.\r | |
84 | @retval EFI_NOT_FOUND A configuration table matching TableGuid could not be found.\r | |
85 | \r | |
86 | **/\r | |
87 | EFI_STATUS\r | |
88 | EFIAPI\r | |
89 | EfiGetSystemConfigurationTable (\r | |
90 | IN EFI_GUID *TableGuid,\r | |
91 | OUT VOID **Table\r | |
92 | )\r | |
93 | {\r | |
94 | EFI_SYSTEM_TABLE *SystemTable;\r | |
95 | UINTN Index;\r | |
96 | \r | |
97 | ASSERT (TableGuid != NULL);\r | |
98 | ASSERT (Table != NULL);\r | |
99 | \r | |
100 | SystemTable = gST;\r | |
101 | *Table = NULL;\r | |
102 | for (Index = 0; Index < SystemTable->NumberOfTableEntries; Index++) {\r | |
103 | if (CompareGuid (TableGuid, &(SystemTable->ConfigurationTable[Index].VendorGuid))) {\r | |
104 | *Table = SystemTable->ConfigurationTable[Index].VendorTable;\r | |
105 | return EFI_SUCCESS;\r | |
106 | }\r | |
107 | }\r | |
108 | \r | |
109 | return EFI_NOT_FOUND;\r | |
110 | }\r | |
111 | \r | |
112 | /**\r | |
1d37ab9f | 113 | Creates and returns a notification event and registers that event with all the protocol\r |
114 | instances specified by ProtocolGuid.\r | |
115 | \r | |
116 | This function causes the notification function to be executed for every protocol of type\r | |
f0a8eeb2 | 117 | ProtocolGuid instance that exists in the system when this function is invoked. If there are\r |
118 | no instances of ProtocolGuid in the handle database at the time this function is invoked,\r | |
119 | then the notification function is still executed one time. In addition, every time a protocol\r | |
120 | of type ProtocolGuid instance is installed or reinstalled, the notification function is also\r | |
121 | executed. This function returns the notification event that was created. \r | |
1d37ab9f | 122 | If ProtocolGuid is NULL, then ASSERT().\r |
123 | If NotifyTpl is not a legal TPL value, then ASSERT().\r | |
124 | If NotifyFunction is NULL, then ASSERT().\r | |
125 | If Registration is NULL, then ASSERT().\r | |
e386b444 | 126 | \r |
f0a8eeb2 | 127 | \r |
e386b444 | 128 | @param ProtocolGuid Supplies GUID of the protocol upon whose installation the event is fired.\r |
129 | @param NotifyTpl Supplies the task priority level of the event notifications.\r | |
130 | @param NotifyFunction Supplies the function to notify when the event is signaled.\r | |
131 | @param NotifyContext The context parameter to pass to NotifyFunction.\r | |
132 | @param Registration A pointer to a memory location to receive the registration value.\r | |
1d37ab9f | 133 | This value is passed to LocateHandle() to obtain new handles that\r |
134 | have been added that support the ProtocolGuid-specified protocol. \r | |
e386b444 | 135 | \r |
136 | @return The notification event that was created.\r | |
137 | \r | |
138 | **/\r | |
139 | EFI_EVENT\r | |
140 | EFIAPI\r | |
141 | EfiCreateProtocolNotifyEvent(\r | |
142 | IN EFI_GUID *ProtocolGuid,\r | |
143 | IN EFI_TPL NotifyTpl,\r | |
144 | IN EFI_EVENT_NOTIFY NotifyFunction,\r | |
145 | IN VOID *NotifyContext, OPTIONAL\r | |
146 | OUT VOID **Registration\r | |
147 | )\r | |
148 | {\r | |
149 | EFI_STATUS Status;\r | |
150 | EFI_EVENT Event;\r | |
151 | \r | |
1d37ab9f | 152 | ASSERT (ProtocolGuid != NULL);\r |
153 | ASSERT (NotifyFunction != NULL);\r | |
154 | ASSERT (Registration != NULL);\r | |
155 | \r | |
e386b444 | 156 | //\r |
157 | // Create the event\r | |
158 | //\r | |
159 | \r | |
160 | Status = gBS->CreateEvent (\r | |
161 | EVT_NOTIFY_SIGNAL,\r | |
162 | NotifyTpl,\r | |
163 | NotifyFunction,\r | |
164 | NotifyContext,\r | |
165 | &Event\r | |
166 | );\r | |
167 | ASSERT_EFI_ERROR (Status);\r | |
168 | \r | |
169 | //\r | |
6d28c497 | 170 | // Register for protocol notifications on this event\r |
e386b444 | 171 | //\r |
172 | \r | |
173 | Status = gBS->RegisterProtocolNotify (\r | |
174 | ProtocolGuid,\r | |
175 | Event,\r | |
176 | Registration\r | |
177 | );\r | |
178 | \r | |
179 | ASSERT_EFI_ERROR (Status);\r | |
180 | \r | |
181 | //\r | |
182 | // Kick the event so we will perform an initial pass of\r | |
183 | // current installed drivers\r | |
184 | //\r | |
185 | \r | |
186 | gBS->SignalEvent (Event);\r | |
187 | return Event;\r | |
188 | }\r | |
189 | \r | |
190 | /**\r | |
1d37ab9f | 191 | Creates a named event that can be signaled with EfiNamedEventSignal().\r |
192 | \r | |
e386b444 | 193 | This function creates an event using NotifyTpl, NoifyFunction, and NotifyContext.\r |
1d37ab9f | 194 | This event is signaled with EfiNamedEventSignal(). This provides the ability for one or more\r |
195 | listeners on the same event named by the GUID specified by Name. \r | |
9edc73ad | 196 | If Name is NULL, then ASSERT().\r |
197 | If NotifyTpl is not a legal TPL value, then ASSERT().\r | |
198 | If NotifyFunction is NULL, then ASSERT().\r | |
e386b444 | 199 | \r |
58380e9c | 200 | @param Name Supplies the GUID name of the event.\r |
e386b444 | 201 | @param NotifyTpl Supplies the task priority level of the event notifications.\r |
202 | @param NotifyFunction Supplies the function to notify when the event is signaled.\r | |
1d37ab9f | 203 | @param NotifyContext The context parameter to pass to NotifyFunction. \r |
e386b444 | 204 | @param Registration A pointer to a memory location to receive the registration value.\r |
205 | \r | |
206 | @retval EFI_SUCCESS A named event was created.\r | |
207 | @retval EFI_OUT_OF_RESOURCES There are not enough resource to create the named event.\r | |
208 | \r | |
209 | **/\r | |
210 | EFI_STATUS\r | |
211 | EFIAPI\r | |
212 | EfiNamedEventListen (\r | |
213 | IN CONST EFI_GUID *Name,\r | |
214 | IN EFI_TPL NotifyTpl,\r | |
215 | IN EFI_EVENT_NOTIFY NotifyFunction,\r | |
216 | IN CONST VOID *NotifyContext, OPTIONAL\r | |
217 | OUT VOID *Registration OPTIONAL\r | |
218 | )\r | |
219 | {\r | |
220 | EFI_STATUS Status;\r | |
221 | EFI_EVENT Event;\r | |
222 | VOID *RegistrationLocal;\r | |
223 | \r | |
9edc73ad | 224 | ASSERT (Name != NULL);\r |
225 | ASSERT (NotifyFunction != NULL);\r | |
226 | ASSERT (NotifyTpl <= TPL_HIGH_LEVEL);\r | |
227 | \r | |
e386b444 | 228 | //\r |
229 | // Create event\r | |
230 | //\r | |
231 | Status = gBS->CreateEvent (\r | |
232 | EVT_NOTIFY_SIGNAL,\r | |
233 | NotifyTpl,\r | |
234 | NotifyFunction,\r | |
235 | (VOID *) NotifyContext,\r | |
236 | &Event\r | |
237 | );\r | |
238 | ASSERT_EFI_ERROR (Status);\r | |
239 | \r | |
240 | //\r | |
241 | // The Registration is not optional to RegisterProtocolNotify().\r | |
242 | // To make it optional to EfiNamedEventListen(), may need to substitute with a local.\r | |
243 | //\r | |
244 | if (Registration != NULL) {\r | |
245 | RegistrationLocal = Registration;\r | |
246 | } else {\r | |
247 | RegistrationLocal = &RegistrationLocal;\r | |
248 | }\r | |
249 | \r | |
250 | //\r | |
251 | // Register for an installation of protocol interface\r | |
252 | //\r | |
253 | \r | |
254 | Status = gBS->RegisterProtocolNotify (\r | |
255 | (EFI_GUID *) Name,\r | |
256 | Event,\r | |
257 | RegistrationLocal\r | |
258 | );\r | |
259 | ASSERT_EFI_ERROR (Status);\r | |
260 | \r | |
9edc73ad | 261 | return Status;\r |
e386b444 | 262 | }\r |
263 | \r | |
264 | /**\r | |
1d37ab9f | 265 | Signals a named event created with EfiNamedEventListen().\r |
266 | \r | |
267 | This function signals the named event specified by Name. The named event must have been\r | |
268 | created with EfiNamedEventListen().\r | |
269 | If Name is NULL, then ASSERT().\r | |
e386b444 | 270 | \r |
58380e9c | 271 | @param Name Supplies the GUID name of the event.\r |
e386b444 | 272 | \r |
273 | @retval EFI_SUCCESS A named event was signaled.\r | |
274 | @retval EFI_OUT_OF_RESOURCES There are not enough resource to signal the named event.\r | |
275 | \r | |
276 | **/\r | |
277 | EFI_STATUS\r | |
278 | EFIAPI\r | |
279 | EfiNamedEventSignal (\r | |
280 | IN CONST EFI_GUID *Name\r | |
281 | )\r | |
282 | {\r | |
283 | EFI_STATUS Status;\r | |
284 | EFI_HANDLE Handle;\r | |
285 | \r | |
1d37ab9f | 286 | ASSERT(Name != NULL);\r |
287 | \r | |
e386b444 | 288 | Handle = NULL;\r |
289 | Status = gBS->InstallProtocolInterface (\r | |
290 | &Handle,\r | |
291 | (EFI_GUID *) Name,\r | |
292 | EFI_NATIVE_INTERFACE,\r | |
293 | NULL\r | |
294 | );\r | |
295 | ASSERT_EFI_ERROR (Status);\r | |
296 | \r | |
297 | Status = gBS->UninstallProtocolInterface (\r | |
298 | Handle,\r | |
299 | (EFI_GUID *) Name,\r | |
300 | NULL\r | |
301 | );\r | |
302 | ASSERT_EFI_ERROR (Status);\r | |
303 | \r | |
9edc73ad | 304 | return Status;\r |
e386b444 | 305 | }\r |
306 | \r | |
772fb7cb LE |
307 | /**\r |
308 | Signals an event group by placing a new event in the group temporarily and\r | |
309 | signaling it.\r | |
310 | \r | |
311 | @param[in] EventGroup Supplies the unique identifier of the event\r | |
312 | group to signal.\r | |
313 | \r | |
314 | @retval EFI_SUCCESS The event group was signaled successfully.\r | |
315 | @retval EFI_INVALID_PARAMETER EventGroup is NULL.\r | |
316 | @return Error codes that report problems about event\r | |
317 | creation or signaling.\r | |
318 | **/\r | |
319 | EFI_STATUS\r | |
320 | EFIAPI\r | |
321 | EfiEventGroupSignal (\r | |
322 | IN CONST EFI_GUID *EventGroup\r | |
323 | )\r | |
324 | {\r | |
325 | EFI_STATUS Status;\r | |
326 | EFI_EVENT Event;\r | |
327 | \r | |
328 | if (EventGroup == NULL) {\r | |
329 | return EFI_INVALID_PARAMETER;\r | |
330 | }\r | |
331 | \r | |
332 | Status = gBS->CreateEventEx (\r | |
333 | EVT_NOTIFY_SIGNAL,\r | |
334 | TPL_CALLBACK,\r | |
335 | InternalEmptyFunction,\r | |
336 | NULL,\r | |
337 | EventGroup,\r | |
338 | &Event\r | |
339 | );\r | |
340 | if (EFI_ERROR (Status)) {\r | |
341 | return Status;\r | |
342 | }\r | |
343 | \r | |
344 | Status = gBS->SignalEvent (Event);\r | |
345 | gBS->CloseEvent (Event);\r | |
346 | \r | |
347 | return Status;\r | |
348 | }\r | |
349 | \r | |
cf8ae2f6 | 350 | /** \r |
e386b444 | 351 | Returns the current TPL.\r |
352 | \r | |
cf8ae2f6 | 353 | This function returns the current TPL. There is no EFI service to directly \r |
354 | retrieve the current TPL. Instead, the RaiseTPL() function is used to raise \r | |
355 | the TPL to TPL_HIGH_LEVEL. This will return the current TPL. The TPL level \r | |
356 | can then immediately be restored back to the current TPL level with a call \r | |
e386b444 | 357 | to RestoreTPL().\r |
358 | \r | |
cf8ae2f6 | 359 | @return The current TPL.\r |
e386b444 | 360 | \r |
361 | **/\r | |
362 | EFI_TPL\r | |
363 | EFIAPI\r | |
364 | EfiGetCurrentTpl (\r | |
365 | VOID\r | |
366 | )\r | |
367 | {\r | |
368 | EFI_TPL Tpl;\r | |
369 | \r | |
370 | Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r | |
371 | gBS->RestoreTPL (Tpl);\r | |
372 | \r | |
373 | return Tpl;\r | |
374 | }\r | |
375 | \r | |
376 | \r | |
377 | /**\r | |
1d37ab9f | 378 | Initializes a basic mutual exclusion lock.\r |
379 | \r | |
380 | This function initializes a basic mutual exclusion lock to the released state \r | |
381 | and returns the lock. Each lock provides mutual exclusion access at its task \r | |
e386b444 | 382 | priority level. Since there is no preemption or multiprocessor support in EFI,\r |
383 | acquiring the lock only consists of raising to the locks TPL.\r | |
9edc73ad | 384 | If Lock is NULL, then ASSERT().\r |
385 | If Priority is not a valid TPL value, then ASSERT().\r | |
e386b444 | 386 | \r |
387 | @param Lock A pointer to the lock data structure to initialize.\r | |
58380e9c | 388 | @param Priority EFI TPL is associated with the lock.\r |
e386b444 | 389 | \r |
390 | @return The lock.\r | |
391 | \r | |
392 | **/\r | |
393 | EFI_LOCK *\r | |
394 | EFIAPI\r | |
395 | EfiInitializeLock (\r | |
396 | IN OUT EFI_LOCK *Lock,\r | |
397 | IN EFI_TPL Priority\r | |
398 | )\r | |
399 | {\r | |
400 | ASSERT (Lock != NULL);\r | |
401 | ASSERT (Priority <= TPL_HIGH_LEVEL);\r | |
402 | \r | |
403 | Lock->Tpl = Priority;\r | |
404 | Lock->OwnerTpl = TPL_APPLICATION;\r | |
405 | Lock->Lock = EfiLockReleased ;\r | |
406 | return Lock;\r | |
407 | }\r | |
408 | \r | |
409 | /**\r | |
1d37ab9f | 410 | Acquires ownership of a lock.\r |
411 | \r | |
412 | This function raises the system's current task priority level to the task \r | |
413 | priority level of the mutual exclusion lock. Then, it places the lock in the \r | |
e386b444 | 414 | acquired state.\r |
9edc73ad | 415 | If Lock is NULL, then ASSERT().\r |
416 | If Lock is not initialized, then ASSERT().\r | |
417 | If Lock is already in the acquired state, then ASSERT().\r | |
e386b444 | 418 | \r |
1d37ab9f | 419 | @param Lock A pointer to the lock to acquire.\r |
e386b444 | 420 | \r |
421 | **/\r | |
422 | VOID\r | |
423 | EFIAPI\r | |
424 | EfiAcquireLock (\r | |
425 | IN EFI_LOCK *Lock\r | |
426 | )\r | |
427 | {\r | |
428 | ASSERT (Lock != NULL);\r | |
429 | ASSERT (Lock->Lock == EfiLockReleased);\r | |
430 | \r | |
431 | Lock->OwnerTpl = gBS->RaiseTPL (Lock->Tpl);\r | |
432 | Lock->Lock = EfiLockAcquired;\r | |
433 | }\r | |
434 | \r | |
435 | /**\r | |
cf8ae2f6 | 436 | Acquires ownership of a lock.\r |
1d37ab9f | 437 | \r |
cf8ae2f6 | 438 | This function raises the system's current task priority level to the task priority\r |
439 | level of the mutual exclusion lock. Then, it attempts to place the lock in the acquired state.\r | |
440 | If the lock is already in the acquired state, then EFI_ACCESS_DENIED is returned.\r | |
441 | Otherwise, EFI_SUCCESS is returned.\r | |
1d37ab9f | 442 | If Lock is NULL, then ASSERT().\r |
443 | If Lock is not initialized, then ASSERT().\r | |
e386b444 | 444 | \r |
445 | @param Lock A pointer to the lock to acquire.\r | |
446 | \r | |
447 | @retval EFI_SUCCESS The lock was acquired.\r | |
448 | @retval EFI_ACCESS_DENIED The lock could not be acquired because it is already owned.\r | |
449 | \r | |
450 | **/\r | |
451 | EFI_STATUS\r | |
452 | EFIAPI\r | |
453 | EfiAcquireLockOrFail (\r | |
454 | IN EFI_LOCK *Lock\r | |
455 | )\r | |
456 | {\r | |
457 | \r | |
458 | ASSERT (Lock != NULL);\r | |
459 | ASSERT (Lock->Lock != EfiLockUninitialized);\r | |
460 | \r | |
461 | if (Lock->Lock == EfiLockAcquired) {\r | |
462 | //\r | |
463 | // Lock is already owned, so bail out\r | |
464 | //\r | |
465 | return EFI_ACCESS_DENIED;\r | |
466 | }\r | |
467 | \r | |
468 | Lock->OwnerTpl = gBS->RaiseTPL (Lock->Tpl);\r | |
469 | \r | |
470 | Lock->Lock = EfiLockAcquired;\r | |
471 | \r | |
472 | return EFI_SUCCESS;\r | |
473 | }\r | |
474 | \r | |
475 | /**\r | |
1d37ab9f | 476 | Releases ownership of a lock.\r |
477 | \r | |
478 | This function transitions a mutual exclusion lock from the acquired state to \r | |
479 | the released state, and restores the system's task priority level to its \r | |
e386b444 | 480 | previous level.\r |
1d37ab9f | 481 | If Lock is NULL, then ASSERT().\r |
482 | If Lock is not initialized, then ASSERT().\r | |
483 | If Lock is already in the released state, then ASSERT().\r | |
e386b444 | 484 | \r |
485 | @param Lock A pointer to the lock to release.\r | |
486 | \r | |
487 | **/\r | |
488 | VOID\r | |
489 | EFIAPI\r | |
490 | EfiReleaseLock (\r | |
491 | IN EFI_LOCK *Lock\r | |
492 | )\r | |
493 | {\r | |
494 | EFI_TPL Tpl;\r | |
495 | \r | |
496 | ASSERT (Lock != NULL);\r | |
497 | ASSERT (Lock->Lock == EfiLockAcquired);\r | |
498 | \r | |
499 | Tpl = Lock->OwnerTpl;\r | |
500 | \r | |
501 | Lock->Lock = EfiLockReleased;\r | |
502 | \r | |
503 | gBS->RestoreTPL (Tpl);\r | |
504 | }\r | |
505 | \r | |
506 | /**\r | |
507 | Tests whether a controller handle is being managed by a specific driver.\r | |
508 | \r | |
509 | This function tests whether the driver specified by DriverBindingHandle is\r | |
510 | currently managing the controller specified by ControllerHandle. This test\r | |
511 | is performed by evaluating if the the protocol specified by ProtocolGuid is\r | |
512 | present on ControllerHandle and is was opened by DriverBindingHandle with an\r | |
cf8ae2f6 | 513 | attribute of EFI_OPEN_PROTOCOL_BY_DRIVER. \r |
e386b444 | 514 | If ProtocolGuid is NULL, then ASSERT().\r |
515 | \r | |
516 | @param ControllerHandle A handle for a controller to test.\r | |
517 | @param DriverBindingHandle Specifies the driver binding handle for the\r | |
518 | driver.\r | |
519 | @param ProtocolGuid Specifies the protocol that the driver specified\r | |
520 | by DriverBindingHandle opens in its Start()\r | |
521 | function.\r | |
522 | \r | |
523 | @retval EFI_SUCCESS ControllerHandle is managed by the driver\r | |
28d3e14f | 524 | specified by DriverBindingHandle.\r |
e386b444 | 525 | @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driver\r |
28d3e14f | 526 | specified by DriverBindingHandle.\r |
e386b444 | 527 | \r |
528 | **/\r | |
529 | EFI_STATUS\r | |
530 | EFIAPI\r | |
531 | EfiTestManagedDevice (\r | |
532 | IN CONST EFI_HANDLE ControllerHandle,\r | |
533 | IN CONST EFI_HANDLE DriverBindingHandle,\r | |
534 | IN CONST EFI_GUID *ProtocolGuid\r | |
535 | )\r | |
536 | {\r | |
537 | EFI_STATUS Status;\r | |
538 | VOID *ManagedInterface;\r | |
539 | \r | |
540 | ASSERT (ProtocolGuid != NULL);\r | |
541 | \r | |
542 | Status = gBS->OpenProtocol (\r | |
543 | ControllerHandle,\r | |
544 | (EFI_GUID *) ProtocolGuid,\r | |
545 | &ManagedInterface,\r | |
546 | DriverBindingHandle,\r | |
547 | ControllerHandle,\r | |
548 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
549 | );\r | |
550 | if (!EFI_ERROR (Status)) {\r | |
551 | gBS->CloseProtocol (\r | |
552 | ControllerHandle,\r | |
553 | (EFI_GUID *) ProtocolGuid,\r | |
554 | DriverBindingHandle,\r | |
555 | ControllerHandle\r | |
556 | );\r | |
557 | return EFI_UNSUPPORTED;\r | |
558 | }\r | |
559 | \r | |
560 | if (Status != EFI_ALREADY_STARTED) {\r | |
561 | return EFI_UNSUPPORTED;\r | |
562 | }\r | |
563 | \r | |
564 | return EFI_SUCCESS;\r | |
565 | }\r | |
566 | \r | |
567 | /**\r | |
568 | Tests whether a child handle is a child device of the controller.\r | |
569 | \r | |
570 | This function tests whether ChildHandle is one of the children of\r | |
571 | ControllerHandle. This test is performed by checking to see if the protocol\r | |
572 | specified by ProtocolGuid is present on ControllerHandle and opened by\r | |
573 | ChildHandle with an attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r | |
574 | If ProtocolGuid is NULL, then ASSERT().\r | |
575 | \r | |
cf8ae2f6 | 576 | @param ControllerHandle A handle for a (parent) controller to test. \r |
e386b444 | 577 | @param ChildHandle A child handle to test.\r |
42eedea9 | 578 | @param ProtocolGuid Supplies the protocol that the child controller\r |
cf8ae2f6 | 579 | opens on its parent controller. \r |
e386b444 | 580 | \r |
581 | @retval EFI_SUCCESS ChildHandle is a child of the ControllerHandle.\r | |
582 | @retval EFI_UNSUPPORTED ChildHandle is not a child of the\r | |
583 | ControllerHandle.\r | |
584 | \r | |
585 | **/\r | |
586 | EFI_STATUS\r | |
587 | EFIAPI\r | |
588 | EfiTestChildHandle (\r | |
589 | IN CONST EFI_HANDLE ControllerHandle,\r | |
590 | IN CONST EFI_HANDLE ChildHandle,\r | |
591 | IN CONST EFI_GUID *ProtocolGuid\r | |
592 | )\r | |
593 | {\r | |
594 | EFI_STATUS Status;\r | |
595 | EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r | |
596 | UINTN EntryCount;\r | |
597 | UINTN Index;\r | |
598 | \r | |
599 | ASSERT (ProtocolGuid != NULL);\r | |
600 | \r | |
601 | //\r | |
602 | // Retrieve the list of agents that are consuming the specific protocol\r | |
603 | // on ControllerHandle.\r | |
604 | //\r | |
605 | Status = gBS->OpenProtocolInformation (\r | |
606 | ControllerHandle,\r | |
607 | (EFI_GUID *) ProtocolGuid,\r | |
608 | &OpenInfoBuffer,\r | |
609 | &EntryCount\r | |
610 | );\r | |
611 | if (EFI_ERROR (Status)) {\r | |
612 | return EFI_UNSUPPORTED;\r | |
613 | }\r | |
614 | \r | |
615 | //\r | |
616 | // Inspect if ChildHandle is one of the agents.\r | |
617 | //\r | |
618 | Status = EFI_UNSUPPORTED;\r | |
619 | for (Index = 0; Index < EntryCount; Index++) {\r | |
620 | if ((OpenInfoBuffer[Index].ControllerHandle == ChildHandle) &&\r | |
621 | (OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r | |
622 | Status = EFI_SUCCESS;\r | |
623 | break;\r | |
624 | }\r | |
625 | }\r | |
626 | \r | |
627 | FreePool (OpenInfoBuffer);\r | |
628 | return Status;\r | |
629 | }\r | |
630 | \r | |
631 | /**\r | |
dd51a993 | 632 | This function looks up a Unicode string in UnicodeStringTable.\r |
dd51a993 | 633 | \r |
cf8ae2f6 | 634 | If Language is a member of SupportedLanguages and a Unicode string is found in\r |
1d37ab9f | 635 | UnicodeStringTable that matches the language code specified by Language, then it\r |
636 | is returned in UnicodeString.\r | |
637 | \r | |
638 | @param Language A pointer to the ISO 639-2 language code for the \r | |
639 | Unicode string to look up and return.\r | |
640 | @param SupportedLanguages A pointer to the set of ISO 639-2 language codes \r | |
641 | that the Unicode string table supports. Language \r | |
642 | must be a member of this set.\r | |
643 | @param UnicodeStringTable A pointer to the table of Unicode strings.\r | |
644 | @param UnicodeString A pointer to the Unicode string from UnicodeStringTable\r | |
645 | that matches the language specified by Language.\r | |
646 | \r | |
647 | @retval EFI_SUCCESS The Unicode string that matches the language \r | |
648 | specified by Language was found\r | |
28d3e14f | 649 | in the table of Unicode strings UnicodeStringTable, \r |
1d37ab9f | 650 | and it was returned in UnicodeString.\r |
651 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
652 | @retval EFI_INVALID_PARAMETER UnicodeString is NULL.\r | |
653 | @retval EFI_UNSUPPORTED SupportedLanguages is NULL.\r | |
654 | @retval EFI_UNSUPPORTED UnicodeStringTable is NULL.\r | |
655 | @retval EFI_UNSUPPORTED The language specified by Language is not a \r | |
656 | member of SupportedLanguages.\r | |
657 | @retval EFI_UNSUPPORTED The language specified by Language is not \r | |
658 | supported by UnicodeStringTable.\r | |
e386b444 | 659 | \r |
660 | **/\r | |
661 | EFI_STATUS\r | |
662 | EFIAPI\r | |
663 | LookupUnicodeString (\r | |
664 | IN CONST CHAR8 *Language,\r | |
665 | IN CONST CHAR8 *SupportedLanguages,\r | |
666 | IN CONST EFI_UNICODE_STRING_TABLE *UnicodeStringTable,\r | |
667 | OUT CHAR16 **UnicodeString\r | |
668 | )\r | |
669 | {\r | |
670 | //\r | |
671 | // Make sure the parameters are valid\r | |
672 | //\r | |
673 | if (Language == NULL || UnicodeString == NULL) {\r | |
674 | return EFI_INVALID_PARAMETER;\r | |
675 | }\r | |
676 | \r | |
677 | //\r | |
678 | // If there are no supported languages, or the Unicode String Table is empty, then the\r | |
679 | // Unicode String specified by Language is not supported by this Unicode String Table\r | |
680 | //\r | |
681 | if (SupportedLanguages == NULL || UnicodeStringTable == NULL) {\r | |
682 | return EFI_UNSUPPORTED;\r | |
683 | }\r | |
684 | \r | |
685 | //\r | |
686 | // Make sure Language is in the set of Supported Languages\r | |
687 | //\r | |
688 | while (*SupportedLanguages != 0) {\r | |
689 | if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r | |
690 | \r | |
691 | //\r | |
692 | // Search the Unicode String Table for the matching Language specifier\r | |
693 | //\r | |
694 | while (UnicodeStringTable->Language != NULL) {\r | |
695 | if (CompareIso639LanguageCode (Language, UnicodeStringTable->Language)) {\r | |
696 | \r | |
697 | //\r | |
698 | // A matching string was found, so return it\r | |
699 | //\r | |
700 | *UnicodeString = UnicodeStringTable->UnicodeString;\r | |
701 | return EFI_SUCCESS;\r | |
702 | }\r | |
703 | \r | |
704 | UnicodeStringTable++;\r | |
705 | }\r | |
706 | \r | |
707 | return EFI_UNSUPPORTED;\r | |
708 | }\r | |
709 | \r | |
710 | SupportedLanguages += 3;\r | |
711 | }\r | |
712 | \r | |
713 | return EFI_UNSUPPORTED;\r | |
714 | }\r | |
715 | \r | |
dd51a993 | 716 | \r |
717 | \r | |
e386b444 | 718 | /**\r |
dd51a993 | 719 | This function looks up a Unicode string in UnicodeStringTable.\r |
cf8ae2f6 | 720 | \r |
721 | If Language is a member of SupportedLanguages and a Unicode string is found in\r | |
722 | UnicodeStringTable that matches the language code specified by Language, then\r | |
723 | it is returned in UnicodeString.\r | |
724 | \r | |
725 | @param Language A pointer to an ASCII string containing the ISO 639-2 or the\r | |
726 | RFC 4646 language code for the Unicode string to look up and\r | |
727 | return. If Iso639Language is TRUE, then this ASCII string is\r | |
728 | not assumed to be Null-terminated, and only the first three\r | |
28d3e14f | 729 | characters are used. If Iso639Language is FALSE, then this ASCII\r |
cf8ae2f6 | 730 | string must be Null-terminated. \r |
731 | @param SupportedLanguages A pointer to a Null-terminated ASCII string that contains a\r | |
732 | set of ISO 639-2 or RFC 4646 language codes that the Unicode\r | |
733 | string table supports. Language must be a member of this set.\r | |
734 | If Iso639Language is TRUE, then this string contains one or more\r | |
735 | ISO 639-2 language codes with no separator characters. If Iso639Language\r | |
736 | is FALSE, then is string contains one or more RFC 4646 language\r | |
737 | codes separated by ';'.\r | |
738 | @param UnicodeStringTable A pointer to the table of Unicode strings. Type EFI_UNICODE_STRING_TABLE\r | |
739 | is defined in "Related Definitions".\r | |
740 | @param UnicodeString A pointer to the Null-terminated Unicode string from UnicodeStringTable\r | |
741 | that matches the language specified by Language.\r | |
742 | @param Iso639Language Specifies the supported language code format. If it is TRUE, then\r | |
743 | Language and SupportedLanguages follow ISO 639-2 language code format.\r | |
744 | Otherwise, they follow RFC 4646 language code format.\r | |
745 | \r | |
746 | \r | |
747 | @retval EFI_SUCCESS The Unicode string that matches the language specified by Language\r | |
748 | was found in the table of Unicode strings UnicodeStringTable, and\r | |
749 | it was returned in UnicodeString.\r | |
1d37ab9f | 750 | @retval EFI_INVALID_PARAMETER Language is NULL. \r |
751 | @retval EFI_INVALID_PARAMETER UnicodeString is NULL. \r | |
752 | @retval EFI_UNSUPPORTED SupportedLanguages is NULL. \r | |
cf8ae2f6 | 753 | @retval EFI_UNSUPPORTED UnicodeStringTable is NULL. \r |
754 | @retval EFI_UNSUPPORTED The language specified by Language is not a member of SupportedLanguages. \r | |
755 | @retval EFI_UNSUPPORTED The language specified by Language is not supported by UnicodeStringTable.\r | |
dd51a993 | 756 | \r |
757 | **/\r | |
758 | EFI_STATUS\r | |
759 | EFIAPI\r | |
760 | LookupUnicodeString2 (\r | |
761 | IN CONST CHAR8 *Language,\r | |
762 | IN CONST CHAR8 *SupportedLanguages,\r | |
763 | IN CONST EFI_UNICODE_STRING_TABLE *UnicodeStringTable,\r | |
764 | OUT CHAR16 **UnicodeString,\r | |
765 | IN BOOLEAN Iso639Language\r | |
766 | )\r | |
767 | {\r | |
768 | BOOLEAN Found;\r | |
769 | UINTN Index;\r | |
770 | CHAR8 *LanguageString;\r | |
771 | \r | |
772 | //\r | |
773 | // Make sure the parameters are valid\r | |
774 | //\r | |
775 | if (Language == NULL || UnicodeString == NULL) {\r | |
776 | return EFI_INVALID_PARAMETER;\r | |
777 | }\r | |
778 | \r | |
779 | //\r | |
780 | // If there are no supported languages, or the Unicode String Table is empty, then the\r | |
781 | // Unicode String specified by Language is not supported by this Unicode String Table\r | |
782 | //\r | |
783 | if (SupportedLanguages == NULL || UnicodeStringTable == NULL) {\r | |
784 | return EFI_UNSUPPORTED;\r | |
785 | }\r | |
786 | \r | |
787 | //\r | |
788 | // Make sure Language is in the set of Supported Languages\r | |
789 | //\r | |
790 | Found = FALSE;\r | |
791 | while (*SupportedLanguages != 0) {\r | |
792 | if (Iso639Language) {\r | |
793 | if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r | |
794 | Found = TRUE;\r | |
795 | break;\r | |
796 | }\r | |
797 | SupportedLanguages += 3;\r | |
798 | } else {\r | |
799 | for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++);\r | |
634aa59d | 800 | if ((AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) && (Language[Index] == 0)) {\r |
dd51a993 | 801 | Found = TRUE;\r |
802 | break;\r | |
803 | }\r | |
804 | SupportedLanguages += Index;\r | |
805 | for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++);\r | |
806 | }\r | |
807 | }\r | |
808 | \r | |
809 | //\r | |
810 | // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED\r | |
811 | //\r | |
812 | if (!Found) {\r | |
813 | return EFI_UNSUPPORTED;\r | |
814 | }\r | |
815 | \r | |
816 | //\r | |
817 | // Search the Unicode String Table for the matching Language specifier\r | |
818 | //\r | |
819 | while (UnicodeStringTable->Language != NULL) {\r | |
820 | LanguageString = UnicodeStringTable->Language;\r | |
821 | while (0 != *LanguageString) {\r | |
822 | for (Index = 0 ;LanguageString[Index] != 0 && LanguageString[Index] != ';'; Index++);\r | |
823 | if (AsciiStrnCmp(LanguageString, Language, Index) == 0) {\r | |
824 | *UnicodeString = UnicodeStringTable->UnicodeString;\r | |
825 | return EFI_SUCCESS;\r | |
826 | }\r | |
827 | LanguageString += Index;\r | |
828 | for (Index = 0 ;LanguageString[Index] != 0 && LanguageString[Index] == ';'; Index++);\r | |
829 | }\r | |
830 | UnicodeStringTable++;\r | |
831 | }\r | |
832 | \r | |
833 | return EFI_UNSUPPORTED;\r | |
834 | }\r | |
835 | \r | |
836 | \r | |
837 | /**\r | |
e386b444 | 838 | This function adds a Unicode string to UnicodeStringTable.\r |
1d37ab9f | 839 | \r |
840 | If Language is a member of SupportedLanguages then UnicodeString is added to \r | |
841 | UnicodeStringTable. New buffers are allocated for both Language and \r | |
842 | UnicodeString. The contents of Language and UnicodeString are copied into \r | |
843 | these new buffers. These buffers are automatically freed when \r | |
e386b444 | 844 | FreeUnicodeStringTable() is called.\r |
845 | \r | |
1d37ab9f | 846 | @param Language A pointer to the ISO 639-2 language code for the Unicode \r |
e386b444 | 847 | string to add.\r |
1d37ab9f | 848 | @param SupportedLanguages A pointer to the set of ISO 639-2 language codes\r |
849 | that the Unicode string table supports.\r | |
850 | Language must be a member of this set.\r | |
851 | @param UnicodeStringTable A pointer to the table of Unicode strings.\r | |
852 | @param UnicodeString A pointer to the Unicode string to add.\r | |
853 | \r | |
854 | @retval EFI_SUCCESS The Unicode string that matches the language \r | |
855 | specified by Language was found in the table of \r | |
856 | Unicode strings UnicodeStringTable, and it was \r | |
e386b444 | 857 | returned in UnicodeString.\r |
858 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
859 | @retval EFI_INVALID_PARAMETER UnicodeString is NULL.\r | |
860 | @retval EFI_INVALID_PARAMETER UnicodeString is an empty string.\r | |
861 | @retval EFI_UNSUPPORTED SupportedLanguages is NULL.\r | |
1d37ab9f | 862 | @retval EFI_ALREADY_STARTED A Unicode string with language Language is \r |
863 | already present in UnicodeStringTable.\r | |
864 | @retval EFI_OUT_OF_RESOURCES There is not enough memory to add another \r | |
865 | Unicode string to UnicodeStringTable.\r | |
866 | @retval EFI_UNSUPPORTED The language specified by Language is not a \r | |
867 | member of SupportedLanguages.\r | |
e386b444 | 868 | \r |
869 | **/\r | |
870 | EFI_STATUS\r | |
871 | EFIAPI\r | |
872 | AddUnicodeString (\r | |
873 | IN CONST CHAR8 *Language,\r | |
874 | IN CONST CHAR8 *SupportedLanguages,\r | |
875 | IN EFI_UNICODE_STRING_TABLE **UnicodeStringTable,\r | |
876 | IN CONST CHAR16 *UnicodeString\r | |
877 | )\r | |
878 | {\r | |
879 | UINTN NumberOfEntries;\r | |
880 | EFI_UNICODE_STRING_TABLE *OldUnicodeStringTable;\r | |
881 | EFI_UNICODE_STRING_TABLE *NewUnicodeStringTable;\r | |
882 | UINTN UnicodeStringLength;\r | |
883 | \r | |
884 | //\r | |
885 | // Make sure the parameter are valid\r | |
886 | //\r | |
887 | if (Language == NULL || UnicodeString == NULL || UnicodeStringTable == NULL) {\r | |
888 | return EFI_INVALID_PARAMETER;\r | |
889 | }\r | |
890 | \r | |
891 | //\r | |
892 | // If there are no supported languages, then a Unicode String can not be added\r | |
893 | //\r | |
894 | if (SupportedLanguages == NULL) {\r | |
895 | return EFI_UNSUPPORTED;\r | |
896 | }\r | |
897 | \r | |
898 | //\r | |
899 | // If the Unicode String is empty, then a Unicode String can not be added\r | |
900 | //\r | |
901 | if (UnicodeString[0] == 0) {\r | |
902 | return EFI_INVALID_PARAMETER;\r | |
903 | }\r | |
904 | \r | |
905 | //\r | |
906 | // Make sure Language is a member of SupportedLanguages\r | |
907 | //\r | |
908 | while (*SupportedLanguages != 0) {\r | |
909 | if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r | |
910 | \r | |
911 | //\r | |
912 | // Determine the size of the Unicode String Table by looking for a NULL Language entry\r | |
913 | //\r | |
914 | NumberOfEntries = 0;\r | |
915 | if (*UnicodeStringTable != NULL) {\r | |
916 | OldUnicodeStringTable = *UnicodeStringTable;\r | |
917 | while (OldUnicodeStringTable->Language != NULL) {\r | |
918 | if (CompareIso639LanguageCode (Language, OldUnicodeStringTable->Language)) {\r | |
919 | return EFI_ALREADY_STARTED;\r | |
920 | }\r | |
921 | \r | |
922 | OldUnicodeStringTable++;\r | |
923 | NumberOfEntries++;\r | |
924 | }\r | |
925 | }\r | |
926 | \r | |
927 | //\r | |
928 | // Allocate space for a new Unicode String Table. It must hold the current number of\r | |
929 | // entries, plus 1 entry for the new Unicode String, plus 1 entry for the end of table\r | |
930 | // marker\r | |
931 | //\r | |
932 | NewUnicodeStringTable = AllocatePool ((NumberOfEntries + 2) * sizeof (EFI_UNICODE_STRING_TABLE));\r | |
933 | if (NewUnicodeStringTable == NULL) {\r | |
934 | return EFI_OUT_OF_RESOURCES;\r | |
935 | }\r | |
936 | \r | |
937 | //\r | |
938 | // If the current Unicode String Table contains any entries, then copy them to the\r | |
939 | // newly allocated Unicode String Table.\r | |
940 | //\r | |
941 | if (*UnicodeStringTable != NULL) {\r | |
942 | CopyMem (\r | |
943 | NewUnicodeStringTable,\r | |
944 | *UnicodeStringTable,\r | |
945 | NumberOfEntries * sizeof (EFI_UNICODE_STRING_TABLE)\r | |
946 | );\r | |
947 | }\r | |
948 | \r | |
949 | //\r | |
950 | // Allocate space for a copy of the Language specifier\r | |
951 | //\r | |
952 | NewUnicodeStringTable[NumberOfEntries].Language = AllocateCopyPool (3, Language);\r | |
953 | if (NewUnicodeStringTable[NumberOfEntries].Language == NULL) {\r | |
6389e32b | 954 | FreePool (NewUnicodeStringTable);\r |
e386b444 | 955 | return EFI_OUT_OF_RESOURCES;\r |
956 | }\r | |
957 | \r | |
958 | //\r | |
959 | // Compute the length of the Unicode String\r | |
960 | //\r | |
961 | for (UnicodeStringLength = 0; UnicodeString[UnicodeStringLength] != 0; UnicodeStringLength++)\r | |
962 | ;\r | |
963 | \r | |
964 | //\r | |
965 | // Allocate space for a copy of the Unicode String\r | |
966 | //\r | |
967 | NewUnicodeStringTable[NumberOfEntries].UnicodeString = AllocateCopyPool (\r | |
968 | (UnicodeStringLength + 1) * sizeof (CHAR16),\r | |
969 | UnicodeString\r | |
970 | );\r | |
971 | if (NewUnicodeStringTable[NumberOfEntries].UnicodeString == NULL) {\r | |
6389e32b LG |
972 | FreePool (NewUnicodeStringTable[NumberOfEntries].Language);\r |
973 | FreePool (NewUnicodeStringTable);\r | |
e386b444 | 974 | return EFI_OUT_OF_RESOURCES;\r |
975 | }\r | |
976 | \r | |
977 | //\r | |
978 | // Mark the end of the Unicode String Table\r | |
979 | //\r | |
980 | NewUnicodeStringTable[NumberOfEntries + 1].Language = NULL;\r | |
981 | NewUnicodeStringTable[NumberOfEntries + 1].UnicodeString = NULL;\r | |
982 | \r | |
983 | //\r | |
984 | // Free the old Unicode String Table\r | |
985 | //\r | |
986 | if (*UnicodeStringTable != NULL) {\r | |
6389e32b | 987 | FreePool (*UnicodeStringTable);\r |
e386b444 | 988 | }\r |
989 | \r | |
990 | //\r | |
991 | // Point UnicodeStringTable at the newly allocated Unicode String Table\r | |
992 | //\r | |
993 | *UnicodeStringTable = NewUnicodeStringTable;\r | |
994 | \r | |
995 | return EFI_SUCCESS;\r | |
996 | }\r | |
997 | \r | |
998 | SupportedLanguages += 3;\r | |
999 | }\r | |
1000 | \r | |
1001 | return EFI_UNSUPPORTED;\r | |
1002 | }\r | |
1003 | \r | |
dd51a993 | 1004 | \r |
1005 | /**\r | |
cf8ae2f6 | 1006 | This function adds the Null-terminated Unicode string specified by UnicodeString\r |
1007 | to UnicodeStringTable.\r | |
1008 | \r | |
1009 | If Language is a member of SupportedLanguages then UnicodeString is added to\r | |
1010 | UnicodeStringTable. New buffers are allocated for both Language and UnicodeString.\r | |
1011 | The contents of Language and UnicodeString are copied into these new buffers.\r | |
1012 | These buffers are automatically freed when EfiLibFreeUnicodeStringTable() is called.\r | |
1013 | \r | |
1014 | @param Language A pointer to an ASCII string containing the ISO 639-2 or\r | |
1015 | the RFC 4646 language code for the Unicode string to add.\r | |
1016 | If Iso639Language is TRUE, then this ASCII string is not\r | |
1017 | assumed to be Null-terminated, and only the first three\r | |
1018 | chacters are used. If Iso639Language is FALSE, then this\r | |
1019 | ASCII string must be Null-terminated.\r | |
1020 | @param SupportedLanguages A pointer to a Null-terminated ASCII string that contains\r | |
1021 | a set of ISO 639-2 or RFC 4646 language codes that the Unicode\r | |
1022 | string table supports. Language must be a member of this set.\r | |
1023 | If Iso639Language is TRUE, then this string contains one or more\r | |
1024 | ISO 639-2 language codes with no separator characters.\r | |
1025 | If Iso639Language is FALSE, then is string contains one or more\r | |
1026 | RFC 4646 language codes separated by ';'.\r | |
1027 | @param UnicodeStringTable A pointer to the table of Unicode strings. Type EFI_UNICODE_STRING_TABLE\r | |
1028 | is defined in "Related Definitions".\r | |
1029 | @param UnicodeString A pointer to the Unicode string to add. \r | |
1030 | @param Iso639Language Specifies the supported language code format. If it is TRUE,\r | |
1031 | then Language and SupportedLanguages follow ISO 639-2 language code format.\r | |
1032 | Otherwise, they follow RFC 4646 language code format.\r | |
1033 | \r | |
1034 | @retval EFI_SUCCESS The Unicode string that matches the language specified by\r | |
1035 | Language was found in the table of Unicode strings UnicodeStringTable,\r | |
1036 | and it was returned in UnicodeString. \r | |
1037 | @retval EFI_INVALID_PARAMETER Language is NULL. \r | |
1038 | @retval EFI_INVALID_PARAMETER UnicodeString is NULL. \r | |
1039 | @retval EFI_INVALID_PARAMETER UnicodeString is an empty string. \r | |
1040 | @retval EFI_UNSUPPORTED SupportedLanguages is NULL. \r | |
1041 | @retval EFI_ALREADY_STARTED A Unicode string with language Language is already present in\r | |
1042 | UnicodeStringTable. \r | |
1043 | @retval EFI_OUT_OF_RESOURCES There is not enough memory to add another Unicode string UnicodeStringTable. \r | |
1044 | @retval EFI_UNSUPPORTED The language specified by Language is not a member of SupportedLanguages.\r | |
dd51a993 | 1045 | \r |
1046 | **/\r | |
1047 | EFI_STATUS\r | |
1048 | EFIAPI\r | |
1049 | AddUnicodeString2 (\r | |
1050 | IN CONST CHAR8 *Language,\r | |
1051 | IN CONST CHAR8 *SupportedLanguages,\r | |
1052 | IN EFI_UNICODE_STRING_TABLE **UnicodeStringTable,\r | |
1053 | IN CONST CHAR16 *UnicodeString,\r | |
1054 | IN BOOLEAN Iso639Language\r | |
1055 | )\r | |
1056 | {\r | |
1057 | UINTN NumberOfEntries;\r | |
1058 | EFI_UNICODE_STRING_TABLE *OldUnicodeStringTable;\r | |
1059 | EFI_UNICODE_STRING_TABLE *NewUnicodeStringTable;\r | |
1060 | UINTN UnicodeStringLength;\r | |
1061 | BOOLEAN Found;\r | |
1062 | UINTN Index;\r | |
1063 | CHAR8 *LanguageString;\r | |
1064 | \r | |
1065 | //\r | |
1066 | // Make sure the parameter are valid\r | |
1067 | //\r | |
1068 | if (Language == NULL || UnicodeString == NULL || UnicodeStringTable == NULL) {\r | |
1069 | return EFI_INVALID_PARAMETER;\r | |
1070 | }\r | |
1071 | \r | |
1072 | //\r | |
1073 | // If there are no supported languages, then a Unicode String can not be added\r | |
1074 | //\r | |
1075 | if (SupportedLanguages == NULL) {\r | |
1076 | return EFI_UNSUPPORTED;\r | |
1077 | }\r | |
1078 | \r | |
1079 | //\r | |
1080 | // If the Unicode String is empty, then a Unicode String can not be added\r | |
1081 | //\r | |
1082 | if (UnicodeString[0] == 0) {\r | |
1083 | return EFI_INVALID_PARAMETER;\r | |
1084 | }\r | |
1085 | \r | |
1086 | //\r | |
1087 | // Make sure Language is a member of SupportedLanguages\r | |
1088 | //\r | |
1089 | Found = FALSE;\r | |
1090 | while (*SupportedLanguages != 0) {\r | |
1091 | if (Iso639Language) {\r | |
1092 | if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r | |
1093 | Found = TRUE;\r | |
1094 | break;\r | |
1095 | }\r | |
1096 | SupportedLanguages += 3;\r | |
1097 | } else {\r | |
1098 | for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++);\r | |
1099 | if (AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) {\r | |
1100 | Found = TRUE;\r | |
1101 | break;\r | |
1102 | }\r | |
1103 | SupportedLanguages += Index;\r | |
1104 | for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++);\r | |
1105 | }\r | |
1106 | }\r | |
1107 | \r | |
1108 | //\r | |
1109 | // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED\r | |
1110 | //\r | |
1111 | if (!Found) {\r | |
1112 | return EFI_UNSUPPORTED;\r | |
1113 | }\r | |
1114 | \r | |
1115 | //\r | |
1116 | // Determine the size of the Unicode String Table by looking for a NULL Language entry\r | |
1117 | //\r | |
1118 | NumberOfEntries = 0;\r | |
1119 | if (*UnicodeStringTable != NULL) {\r | |
1120 | OldUnicodeStringTable = *UnicodeStringTable;\r | |
1121 | while (OldUnicodeStringTable->Language != NULL) {\r | |
1122 | LanguageString = OldUnicodeStringTable->Language;\r | |
1123 | \r | |
42eedea9 | 1124 | while (*LanguageString != 0) {\r |
dd51a993 | 1125 | for (Index = 0; LanguageString[Index] != 0 && LanguageString[Index] != ';'; Index++);\r |
1126 | \r | |
1127 | if (AsciiStrnCmp (Language, LanguageString, Index) == 0) { \r | |
1128 | return EFI_ALREADY_STARTED;\r | |
1129 | }\r | |
1130 | LanguageString += Index;\r | |
1131 | for (; *LanguageString != 0 && *LanguageString == ';'; LanguageString++);\r | |
1132 | }\r | |
1133 | OldUnicodeStringTable++;\r | |
1134 | NumberOfEntries++;\r | |
1135 | }\r | |
1136 | }\r | |
1137 | \r | |
1138 | //\r | |
1139 | // Allocate space for a new Unicode String Table. It must hold the current number of\r | |
1140 | // entries, plus 1 entry for the new Unicode String, plus 1 entry for the end of table\r | |
1141 | // marker\r | |
1142 | //\r | |
1143 | NewUnicodeStringTable = AllocatePool ((NumberOfEntries + 2) * sizeof (EFI_UNICODE_STRING_TABLE));\r | |
1144 | if (NewUnicodeStringTable == NULL) {\r | |
1145 | return EFI_OUT_OF_RESOURCES;\r | |
1146 | }\r | |
1147 | \r | |
1148 | //\r | |
1149 | // If the current Unicode String Table contains any entries, then copy them to the\r | |
1150 | // newly allocated Unicode String Table.\r | |
1151 | //\r | |
1152 | if (*UnicodeStringTable != NULL) {\r | |
1153 | CopyMem (\r | |
1154 | NewUnicodeStringTable,\r | |
1155 | *UnicodeStringTable,\r | |
1156 | NumberOfEntries * sizeof (EFI_UNICODE_STRING_TABLE)\r | |
1157 | );\r | |
1158 | }\r | |
1159 | \r | |
1160 | //\r | |
1161 | // Allocate space for a copy of the Language specifier\r | |
1162 | //\r | |
1163 | NewUnicodeStringTable[NumberOfEntries].Language = AllocateCopyPool (AsciiStrSize(Language), Language);\r | |
1164 | if (NewUnicodeStringTable[NumberOfEntries].Language == NULL) {\r | |
6389e32b | 1165 | FreePool (NewUnicodeStringTable);\r |
dd51a993 | 1166 | return EFI_OUT_OF_RESOURCES;\r |
1167 | }\r | |
1168 | \r | |
1169 | //\r | |
1170 | // Compute the length of the Unicode String\r | |
1171 | //\r | |
1172 | for (UnicodeStringLength = 0; UnicodeString[UnicodeStringLength] != 0; UnicodeStringLength++);\r | |
1173 | \r | |
1174 | //\r | |
1175 | // Allocate space for a copy of the Unicode String\r | |
1176 | //\r | |
1177 | NewUnicodeStringTable[NumberOfEntries].UnicodeString = AllocateCopyPool (StrSize (UnicodeString), UnicodeString);\r | |
1178 | if (NewUnicodeStringTable[NumberOfEntries].UnicodeString == NULL) {\r | |
6389e32b LG |
1179 | FreePool (NewUnicodeStringTable[NumberOfEntries].Language);\r |
1180 | FreePool (NewUnicodeStringTable);\r | |
dd51a993 | 1181 | return EFI_OUT_OF_RESOURCES;\r |
1182 | }\r | |
1183 | \r | |
1184 | //\r | |
1185 | // Mark the end of the Unicode String Table\r | |
1186 | //\r | |
1187 | NewUnicodeStringTable[NumberOfEntries + 1].Language = NULL;\r | |
1188 | NewUnicodeStringTable[NumberOfEntries + 1].UnicodeString = NULL;\r | |
1189 | \r | |
1190 | //\r | |
1191 | // Free the old Unicode String Table\r | |
1192 | //\r | |
1193 | if (*UnicodeStringTable != NULL) {\r | |
6389e32b | 1194 | FreePool (*UnicodeStringTable);\r |
dd51a993 | 1195 | }\r |
1196 | \r | |
1197 | //\r | |
1198 | // Point UnicodeStringTable at the newly allocated Unicode String Table\r | |
1199 | //\r | |
1200 | *UnicodeStringTable = NewUnicodeStringTable;\r | |
1201 | \r | |
1202 | return EFI_SUCCESS;\r | |
1203 | }\r | |
1204 | \r | |
e386b444 | 1205 | /**\r |
1206 | This function frees the table of Unicode strings in UnicodeStringTable.\r | |
1d37ab9f | 1207 | \r |
e386b444 | 1208 | If UnicodeStringTable is NULL, then EFI_SUCCESS is returned.\r |
dd51a993 | 1209 | Otherwise, each language code, and each Unicode string in the Unicode string \r |
e386b444 | 1210 | table are freed, and EFI_SUCCESS is returned.\r |
1211 | \r | |
1212 | @param UnicodeStringTable A pointer to the table of Unicode strings.\r | |
1213 | \r | |
1214 | @retval EFI_SUCCESS The Unicode string table was freed.\r | |
1215 | \r | |
1216 | **/\r | |
1217 | EFI_STATUS\r | |
1218 | EFIAPI\r | |
1219 | FreeUnicodeStringTable (\r | |
1220 | IN EFI_UNICODE_STRING_TABLE *UnicodeStringTable\r | |
1221 | )\r | |
1222 | {\r | |
1223 | UINTN Index;\r | |
1224 | \r | |
1225 | //\r | |
1226 | // If the Unicode String Table is NULL, then it is already freed\r | |
1227 | //\r | |
1228 | if (UnicodeStringTable == NULL) {\r | |
1229 | return EFI_SUCCESS;\r | |
1230 | }\r | |
1231 | \r | |
1232 | //\r | |
1233 | // Loop through the Unicode String Table until we reach the end of table marker\r | |
1234 | //\r | |
1235 | for (Index = 0; UnicodeStringTable[Index].Language != NULL; Index++) {\r | |
1236 | \r | |
1237 | //\r | |
1238 | // Free the Language string from the Unicode String Table\r | |
1239 | //\r | |
6389e32b | 1240 | FreePool (UnicodeStringTable[Index].Language);\r |
e386b444 | 1241 | \r |
1242 | //\r | |
1243 | // Free the Unicode String from the Unicode String Table\r | |
1244 | //\r | |
1245 | if (UnicodeStringTable[Index].UnicodeString != NULL) {\r | |
6389e32b | 1246 | FreePool (UnicodeStringTable[Index].UnicodeString);\r |
e386b444 | 1247 | }\r |
1248 | }\r | |
1249 | \r | |
1250 | //\r | |
1251 | // Free the Unicode String Table itself\r | |
1252 | //\r | |
6389e32b | 1253 | FreePool (UnicodeStringTable);\r |
e386b444 | 1254 | \r |
1255 | return EFI_SUCCESS;\r | |
1256 | }\r | |
6d28c497 | 1257 | \r |
bf4a3dbd ED |
1258 | #ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r |
1259 | \r | |
6d28c497 | 1260 | /**\r |
bf4a3dbd ED |
1261 | [ATTENTION] This function will be deprecated for security reason.\r |
1262 | \r | |
28d3e14f | 1263 | Returns a pointer to an allocated buffer that contains the contents of a \r |
1264 | variable retrieved through the UEFI Runtime Service GetVariable(). The \r | |
1265 | returned buffer is allocated using AllocatePool(). The caller is responsible\r | |
1266 | for freeing this buffer with FreePool().\r | |
6d28c497 | 1267 | \r |
28d3e14f | 1268 | If Name is NULL, then ASSERT().\r |
1269 | If Guid is NULL, then ASSERT().\r | |
6d28c497 | 1270 | \r |
2fc59a00 | 1271 | @param[in] Name The pointer to a Null-terminated Unicode string.\r |
1272 | @param[in] Guid The pointer to an EFI_GUID structure\r | |
6d28c497 | 1273 | \r |
28d3e14f | 1274 | @retval NULL The variable could not be retrieved.\r |
1275 | @retval NULL There are not enough resources available for the variable contents.\r | |
1276 | @retval Other A pointer to allocated buffer containing the variable contents.\r | |
6d28c497 | 1277 | \r |
1278 | **/\r | |
1279 | VOID *\r | |
1280 | EFIAPI\r | |
1281 | GetVariable (\r | |
35db1186 | 1282 | IN CONST CHAR16 *Name,\r |
1283 | IN CONST EFI_GUID *Guid\r | |
1284 | )\r | |
6d28c497 | 1285 | {\r |
1286 | EFI_STATUS Status;\r | |
1287 | UINTN Size;\r | |
1288 | VOID *Value;\r | |
1289 | \r | |
1290 | ASSERT (Name != NULL);\r | |
1291 | ASSERT (Guid != NULL);\r | |
1292 | \r | |
1293 | //\r | |
1294 | // Try to get the variable size.\r | |
1295 | //\r | |
1296 | Value = NULL;\r | |
1297 | Size = 0;\r | |
1298 | Status = gRT->GetVariable ((CHAR16 *) Name, (EFI_GUID *) Guid, NULL, &Size, Value);\r | |
1299 | if (Status != EFI_BUFFER_TOO_SMALL) {\r | |
1300 | return NULL;\r | |
1301 | }\r | |
1302 | \r | |
1303 | //\r | |
1304 | // Allocate buffer to get the variable.\r | |
1305 | //\r | |
1306 | Value = AllocatePool (Size);\r | |
1307 | if (Value == NULL) {\r | |
1308 | return NULL;\r | |
1309 | }\r | |
1310 | \r | |
1311 | //\r | |
1312 | // Get the variable data.\r | |
1313 | //\r | |
1314 | Status = gRT->GetVariable ((CHAR16 *) Name, (EFI_GUID *) Guid, NULL, &Size, Value);\r | |
1315 | if (EFI_ERROR (Status)) {\r | |
1316 | FreePool(Value);\r | |
1317 | return NULL;\r | |
1318 | }\r | |
1319 | \r | |
1320 | return Value;\r | |
1321 | }\r | |
1322 | \r | |
6d28c497 | 1323 | /**\r |
bf4a3dbd ED |
1324 | [ATTENTION] This function will be deprecated for security reason.\r |
1325 | \r | |
6d28c497 | 1326 | Returns a pointer to an allocated buffer that contains the contents of a \r |
1327 | variable retrieved through the UEFI Runtime Service GetVariable(). This \r | |
1328 | function always uses the EFI_GLOBAL_VARIABLE GUID to retrieve variables.\r | |
1329 | The returned buffer is allocated using AllocatePool(). The caller is \r | |
1330 | responsible for freeing this buffer with FreePool().\r | |
1331 | \r | |
1332 | If Name is NULL, then ASSERT().\r | |
1333 | \r | |
2fc59a00 | 1334 | @param[in] Name The pointer to a Null-terminated Unicode string.\r |
6d28c497 | 1335 | \r |
1336 | @retval NULL The variable could not be retrieved.\r | |
1337 | @retval NULL There are not enough resources available for the variable contents.\r | |
1338 | @retval Other A pointer to allocated buffer containing the variable contents.\r | |
1339 | \r | |
1340 | **/\r | |
1341 | VOID *\r | |
1342 | EFIAPI\r | |
1343 | GetEfiGlobalVariable (\r | |
1344 | IN CONST CHAR16 *Name\r | |
1345 | )\r | |
1346 | {\r | |
1347 | return GetVariable (Name, &gEfiGlobalVariableGuid);\r | |
1348 | }\r | |
bf4a3dbd ED |
1349 | #endif\r |
1350 | \r | |
1351 | /**\r | |
1352 | Returns the status whether get the variable success. The function retrieves \r | |
1353 | variable through the UEFI Runtime Service GetVariable(). The \r | |
1354 | returned buffer is allocated using AllocatePool(). The caller is responsible\r | |
1355 | for freeing this buffer with FreePool().\r | |
1356 | \r | |
1357 | If Name is NULL, then ASSERT().\r | |
1358 | If Guid is NULL, then ASSERT().\r | |
1359 | If Value is NULL, then ASSERT().\r | |
1360 | \r | |
1361 | @param[in] Name The pointer to a Null-terminated Unicode string.\r | |
1362 | @param[in] Guid The pointer to an EFI_GUID structure\r | |
1363 | @param[out] Value The buffer point saved the variable info.\r | |
1364 | @param[out] Size The buffer size of the variable.\r | |
1365 | \r | |
1366 | @return EFI_OUT_OF_RESOURCES Allocate buffer failed.\r | |
1367 | @return EFI_SUCCESS Find the specified variable.\r | |
1368 | @return Others Errors Return errors from call to gRT->GetVariable.\r | |
1369 | \r | |
1370 | **/\r | |
1371 | EFI_STATUS\r | |
1372 | EFIAPI\r | |
1373 | GetVariable2 (\r | |
1374 | IN CONST CHAR16 *Name,\r | |
1375 | IN CONST EFI_GUID *Guid,\r | |
1376 | OUT VOID **Value,\r | |
1377 | OUT UINTN *Size OPTIONAL\r | |
1378 | )\r | |
1379 | {\r | |
1380 | EFI_STATUS Status;\r | |
1381 | UINTN BufferSize;\r | |
1382 | \r | |
1383 | ASSERT (Name != NULL && Guid != NULL && Value != NULL);\r | |
1384 | \r | |
1385 | //\r | |
1386 | // Try to get the variable size.\r | |
1387 | //\r | |
1388 | BufferSize = 0;\r | |
1389 | *Value = NULL;\r | |
1390 | if (Size != NULL) {\r | |
1391 | *Size = 0;\r | |
1392 | }\r | |
1393 | \r | |
1394 | Status = gRT->GetVariable ((CHAR16 *) Name, (EFI_GUID *) Guid, NULL, &BufferSize, *Value);\r | |
1395 | if (Status != EFI_BUFFER_TOO_SMALL) {\r | |
1396 | return Status;\r | |
1397 | }\r | |
1398 | \r | |
1399 | //\r | |
1400 | // Allocate buffer to get the variable.\r | |
1401 | //\r | |
1402 | *Value = AllocatePool (BufferSize);\r | |
1403 | ASSERT (*Value != NULL);\r | |
1404 | if (*Value == NULL) {\r | |
1405 | return EFI_OUT_OF_RESOURCES;\r | |
1406 | }\r | |
1407 | \r | |
1408 | //\r | |
1409 | // Get the variable data.\r | |
1410 | //\r | |
1411 | Status = gRT->GetVariable ((CHAR16 *) Name, (EFI_GUID *) Guid, NULL, &BufferSize, *Value);\r | |
1412 | if (EFI_ERROR (Status)) {\r | |
1413 | FreePool(*Value);\r | |
1414 | *Value = NULL;\r | |
1415 | }\r | |
1416 | \r | |
1417 | if (Size != NULL) {\r | |
1418 | *Size = BufferSize;\r | |
1419 | }\r | |
1420 | \r | |
1421 | return Status;\r | |
1422 | }\r | |
6d28c497 | 1423 | \r |
bf4a3dbd ED |
1424 | /**\r |
1425 | Returns a pointer to an allocated buffer that contains the contents of a \r | |
1426 | variable retrieved through the UEFI Runtime Service GetVariable(). This \r | |
1427 | function always uses the EFI_GLOBAL_VARIABLE GUID to retrieve variables.\r | |
1428 | The returned buffer is allocated using AllocatePool(). The caller is \r | |
1429 | responsible for freeing this buffer with FreePool().\r | |
1430 | \r | |
1431 | If Name is NULL, then ASSERT().\r | |
1432 | If Value is NULL, then ASSERT().\r | |
1433 | \r | |
1434 | @param[in] Name The pointer to a Null-terminated Unicode string.\r | |
1435 | @param[out] Value The buffer point saved the variable info.\r | |
1436 | @param[out] Size The buffer size of the variable.\r | |
1437 | \r | |
1438 | @return EFI_OUT_OF_RESOURCES Allocate buffer failed.\r | |
1439 | @return EFI_SUCCESS Find the specified variable.\r | |
1440 | @return Others Errors Return errors from call to gRT->GetVariable.\r | |
1441 | \r | |
1442 | **/\r | |
1443 | EFI_STATUS\r | |
1444 | EFIAPI\r | |
1445 | GetEfiGlobalVariable2 (\r | |
1446 | IN CONST CHAR16 *Name,\r | |
1447 | OUT VOID **Value,\r | |
1448 | OUT UINTN *Size OPTIONAL\r | |
1449 | )\r | |
1450 | {\r | |
1451 | return GetVariable2 (Name, &gEfiGlobalVariableGuid, Value, Size);\r | |
1452 | }\r | |
6d28c497 | 1453 | \r |
1454 | /**\r | |
1455 | Returns a pointer to an allocated buffer that contains the best matching language \r | |
1456 | from a set of supported languages. \r | |
1457 | \r | |
1458 | This function supports both ISO 639-2 and RFC 4646 language codes, but language \r | |
1459 | code types may not be mixed in a single call to this function. The language \r | |
1460 | code returned is allocated using AllocatePool(). The caller is responsible for \r | |
1461 | freeing the allocated buffer using FreePool(). This function supports a variable\r | |
1462 | argument list that allows the caller to pass in a prioritized list of language \r | |
1463 | codes to test against all the language codes in SupportedLanguages. \r | |
1464 | \r | |
1465 | If SupportedLanguages is NULL, then ASSERT().\r | |
1466 | \r | |
1467 | @param[in] SupportedLanguages A pointer to a Null-terminated ASCII string that\r | |
1468 | contains a set of language codes in the format \r | |
1469 | specified by Iso639Language.\r | |
1470 | @param[in] Iso639Language If TRUE, then all language codes are assumed to be\r | |
1471 | in ISO 639-2 format. If FALSE, then all language\r | |
1472 | codes are assumed to be in RFC 4646 language format\r | |
1473 | @param[in] ... A variable argument list that contains pointers to \r | |
1474 | Null-terminated ASCII strings that contain one or more\r | |
1475 | language codes in the format specified by Iso639Language.\r | |
1476 | The first language code from each of these language\r | |
1477 | code lists is used to determine if it is an exact or\r | |
1478 | close match to any of the language codes in \r | |
1479 | SupportedLanguages. Close matches only apply to RFC 4646\r | |
1480 | language codes, and the matching algorithm from RFC 4647\r | |
1481 | is used to determine if a close match is present. If \r | |
1482 | an exact or close match is found, then the matching\r | |
1483 | language code from SupportedLanguages is returned. If\r | |
1484 | no matches are found, then the next variable argument\r | |
1485 | parameter is evaluated. The variable argument list \r | |
1486 | is terminated by a NULL.\r | |
1487 | \r | |
1488 | @retval NULL The best matching language could not be found in SupportedLanguages.\r | |
1489 | @retval NULL There are not enough resources available to return the best matching \r | |
1490 | language.\r | |
1491 | @retval Other A pointer to a Null-terminated ASCII string that is the best matching \r | |
1492 | language in SupportedLanguages.\r | |
1493 | \r | |
1494 | **/\r | |
1495 | CHAR8 *\r | |
1496 | EFIAPI\r | |
1497 | GetBestLanguage (\r | |
1498 | IN CONST CHAR8 *SupportedLanguages, \r | |
1499 | IN BOOLEAN Iso639Language,\r | |
1500 | ...\r | |
1501 | )\r | |
1502 | {\r | |
1503 | VA_LIST Args;\r | |
1504 | CHAR8 *Language;\r | |
1505 | UINTN CompareLength;\r | |
1506 | UINTN LanguageLength;\r | |
1507 | CONST CHAR8 *Supported;\r | |
1508 | CHAR8 *BestLanguage;\r | |
1509 | \r | |
1510 | ASSERT (SupportedLanguages != NULL);\r | |
1511 | \r | |
1512 | VA_START (Args, Iso639Language);\r | |
1513 | while ((Language = VA_ARG (Args, CHAR8 *)) != NULL) {\r | |
1514 | //\r | |
1515 | // Default to ISO 639-2 mode\r | |
1516 | //\r | |
1517 | CompareLength = 3;\r | |
1518 | LanguageLength = MIN (3, AsciiStrLen (Language));\r | |
1519 | \r | |
1520 | //\r | |
1521 | // If in RFC 4646 mode, then determine the length of the first RFC 4646 language code in Language\r | |
1522 | //\r | |
1523 | if (!Iso639Language) {\r | |
1524 | for (LanguageLength = 0; Language[LanguageLength] != 0 && Language[LanguageLength] != ';'; LanguageLength++);\r | |
1525 | }\r | |
1526 | \r | |
1527 | //\r | |
1528 | // Trim back the length of Language used until it is empty\r | |
1529 | //\r | |
1530 | while (LanguageLength > 0) {\r | |
1531 | //\r | |
1532 | // Loop through all language codes in SupportedLanguages\r | |
1533 | //\r | |
1534 | for (Supported = SupportedLanguages; *Supported != '\0'; Supported += CompareLength) {\r | |
1535 | //\r | |
1536 | // In RFC 4646 mode, then Loop through all language codes in SupportedLanguages\r | |
1537 | //\r | |
1538 | if (!Iso639Language) {\r | |
1539 | //\r | |
1540 | // Skip ';' characters in Supported\r | |
1541 | //\r | |
1542 | for (; *Supported != '\0' && *Supported == ';'; Supported++);\r | |
1543 | //\r | |
1544 | // Determine the length of the next language code in Supported\r | |
1545 | //\r | |
1546 | for (CompareLength = 0; Supported[CompareLength] != 0 && Supported[CompareLength] != ';'; CompareLength++);\r | |
1547 | //\r | |
1548 | // If Language is longer than the Supported, then skip to the next language\r | |
1549 | //\r | |
1550 | if (LanguageLength > CompareLength) {\r | |
1551 | continue;\r | |
1552 | }\r | |
1553 | }\r | |
1554 | //\r | |
1555 | // See if the first LanguageLength characters in Supported match Language\r | |
1556 | //\r | |
1557 | if (AsciiStrnCmp (Supported, Language, LanguageLength) == 0) {\r | |
1558 | VA_END (Args);\r | |
1559 | //\r | |
1560 | // Allocate, copy, and return the best matching language code from SupportedLanguages\r | |
1561 | //\r | |
1562 | BestLanguage = AllocateZeroPool (CompareLength + 1);\r | |
1563 | if (BestLanguage == NULL) {\r | |
1564 | return NULL;\r | |
1565 | }\r | |
1566 | return CopyMem (BestLanguage, Supported, CompareLength);\r | |
1567 | }\r | |
1568 | }\r | |
1569 | \r | |
1570 | if (Iso639Language) {\r | |
1571 | //\r | |
1572 | // If ISO 639 mode, then each language can only be tested once\r | |
1573 | //\r | |
1574 | LanguageLength = 0;\r | |
1575 | } else {\r | |
1576 | //\r | |
1577 | // If RFC 4646 mode, then trim Language from the right to the next '-' character \r | |
1578 | //\r | |
1579 | for (LanguageLength--; LanguageLength > 0 && Language[LanguageLength] != '-'; LanguageLength--);\r | |
1580 | }\r | |
1581 | }\r | |
1582 | }\r | |
1583 | VA_END (Args);\r | |
1584 | \r | |
1585 | //\r | |
1586 | // No matches were found \r | |
1587 | //\r | |
1588 | return NULL;\r | |
1589 | }\r | |
1590 | \r | |
ca8f50e8 LE |
1591 | /**\r |
1592 | An empty function to pass error checking of CreateEventEx ().\r | |
1593 | \r | |
1594 | This empty function ensures that EVT_NOTIFY_SIGNAL_ALL is error\r | |
1595 | checked correctly since it is now mapped into CreateEventEx() in UEFI 2.0.\r | |
1596 | \r | |
1597 | @param Event Event whose notification function is being invoked.\r | |
1598 | @param Context The pointer to the notification function's context,\r | |
1599 | which is implementation-dependent.\r | |
1600 | \r | |
1601 | **/\r | |
1602 | VOID\r | |
1603 | EFIAPI\r | |
1604 | InternalEmptyFunction (\r | |
1605 | IN EFI_EVENT Event,\r | |
1606 | IN VOID *Context\r | |
1607 | )\r | |
1608 | {\r | |
1609 | }\r |