]>
Commit | Line | Data |
---|---|---|
e386b444 | 1 | /** @file\r |
9095d37b LG |
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 | |
5ad97f35 | 6 | and print messages on the console output and standard error devices.\r |
e386b444 | 7 | \r |
40070a18 | 8 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r |
9344f092 | 9 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
e386b444 | 10 | \r |
e386b444 | 11 | **/\r |
12 | \r | |
1efcc4ae | 13 | \r |
f734a10a | 14 | #include "UefiLibInternal.h"\r |
e386b444 | 15 | \r |
5bd2d2cb | 16 | /**\r |
9095d37b | 17 | Empty constructor function that is required to resolve dependencies between\r |
5bd2d2cb | 18 | libraries.\r |
9095d37b | 19 | \r |
5bd2d2cb | 20 | ** DO NOT REMOVE **\r |
9095d37b | 21 | \r |
5bd2d2cb | 22 | @param ImageHandle The firmware allocated handle for the EFI image.\r |
23 | @param SystemTable A pointer to the EFI System Table.\r | |
9095d37b | 24 | \r |
5bd2d2cb | 25 | @retval EFI_SUCCESS The constructor executed correctly.\r |
26 | \r | |
27 | **/\r | |
28 | EFI_STATUS\r | |
29 | EFIAPI\r | |
30 | UefiLibConstructor (\r | |
31 | IN EFI_HANDLE ImageHandle,\r | |
32 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
33 | )\r | |
34 | {\r | |
35 | return EFI_SUCCESS;\r | |
36 | }\r | |
37 | \r | |
e386b444 | 38 | /**\r |
39 | Compare whether two names of languages are identical.\r | |
40 | \r | |
41 | @param Language1 Name of language 1.\r | |
42 | @param Language2 Name of language 2.\r | |
43 | \r | |
44 | @retval TRUE Language 1 and language 2 are the same.\r | |
45 | @retval FALSE Language 1 and language 2 are not the same.\r | |
46 | \r | |
47 | **/\r | |
e386b444 | 48 | BOOLEAN\r |
49 | CompareIso639LanguageCode (\r | |
50 | IN CONST CHAR8 *Language1,\r | |
51 | IN CONST CHAR8 *Language2\r | |
52 | )\r | |
53 | {\r | |
54 | UINT32 Name1;\r | |
55 | UINT32 Name2;\r | |
56 | \r | |
57 | Name1 = ReadUnaligned24 ((CONST UINT32 *) Language1);\r | |
58 | Name2 = ReadUnaligned24 ((CONST UINT32 *) Language2);\r | |
59 | \r | |
60 | return (BOOLEAN) (Name1 == Name2);\r | |
61 | }\r | |
62 | \r | |
63 | /**\r | |
1d37ab9f | 64 | Retrieves a pointer to the system configuration table from the EFI System Table\r |
65 | based on a specified GUID.\r | |
9095d37b | 66 | \r |
1d37ab9f | 67 | This function searches the list of configuration tables stored in the EFI System Table\r |
68 | for a table with a GUID that matches TableGuid. If a match is found, then a pointer to\r | |
69 | the configuration table is returned in Table., and EFI_SUCCESS is returned. If a matching GUID\r | |
70 | is not found, then EFI_NOT_FOUND is returned.\r | |
9edc73ad | 71 | If TableGuid is NULL, then ASSERT().\r |
72 | If Table is NULL, then ASSERT().\r | |
e386b444 | 73 | \r |
58380e9c | 74 | @param TableGuid The pointer to table's GUID type.\r |
2fc59a00 | 75 | @param Table The pointer to the table associated with TableGuid in the EFI System Table.\r |
e386b444 | 76 | \r |
77 | @retval EFI_SUCCESS A configuration table matching TableGuid was found.\r | |
78 | @retval EFI_NOT_FOUND A configuration table matching TableGuid could not be found.\r | |
79 | \r | |
80 | **/\r | |
81 | EFI_STATUS\r | |
82 | EFIAPI\r | |
83 | EfiGetSystemConfigurationTable (\r | |
84 | IN EFI_GUID *TableGuid,\r | |
85 | OUT VOID **Table\r | |
86 | )\r | |
87 | {\r | |
88 | EFI_SYSTEM_TABLE *SystemTable;\r | |
89 | UINTN Index;\r | |
90 | \r | |
91 | ASSERT (TableGuid != NULL);\r | |
92 | ASSERT (Table != NULL);\r | |
93 | \r | |
94 | SystemTable = gST;\r | |
95 | *Table = NULL;\r | |
96 | for (Index = 0; Index < SystemTable->NumberOfTableEntries; Index++) {\r | |
97 | if (CompareGuid (TableGuid, &(SystemTable->ConfigurationTable[Index].VendorGuid))) {\r | |
98 | *Table = SystemTable->ConfigurationTable[Index].VendorTable;\r | |
99 | return EFI_SUCCESS;\r | |
100 | }\r | |
101 | }\r | |
102 | \r | |
103 | return EFI_NOT_FOUND;\r | |
104 | }\r | |
105 | \r | |
106 | /**\r | |
1d37ab9f | 107 | Creates and returns a notification event and registers that event with all the protocol\r |
108 | instances specified by ProtocolGuid.\r | |
109 | \r | |
110 | This function causes the notification function to be executed for every protocol of type\r | |
f0a8eeb2 | 111 | ProtocolGuid instance that exists in the system when this function is invoked. If there are\r |
112 | no instances of ProtocolGuid in the handle database at the time this function is invoked,\r | |
113 | then the notification function is still executed one time. In addition, every time a protocol\r | |
114 | of type ProtocolGuid instance is installed or reinstalled, the notification function is also\r | |
9095d37b | 115 | executed. This function returns the notification event that was created.\r |
1d37ab9f | 116 | If ProtocolGuid is NULL, then ASSERT().\r |
117 | If NotifyTpl is not a legal TPL value, then ASSERT().\r | |
118 | If NotifyFunction is NULL, then ASSERT().\r | |
119 | If Registration is NULL, then ASSERT().\r | |
e386b444 | 120 | \r |
f0a8eeb2 | 121 | \r |
e386b444 | 122 | @param ProtocolGuid Supplies GUID of the protocol upon whose installation the event is fired.\r |
123 | @param NotifyTpl Supplies the task priority level of the event notifications.\r | |
124 | @param NotifyFunction Supplies the function to notify when the event is signaled.\r | |
125 | @param NotifyContext The context parameter to pass to NotifyFunction.\r | |
126 | @param Registration A pointer to a memory location to receive the registration value.\r | |
1d37ab9f | 127 | This value is passed to LocateHandle() to obtain new handles that\r |
9095d37b | 128 | have been added that support the ProtocolGuid-specified protocol.\r |
e386b444 | 129 | \r |
130 | @return The notification event that was created.\r | |
131 | \r | |
132 | **/\r | |
133 | EFI_EVENT\r | |
134 | EFIAPI\r | |
135 | EfiCreateProtocolNotifyEvent(\r | |
136 | IN EFI_GUID *ProtocolGuid,\r | |
137 | IN EFI_TPL NotifyTpl,\r | |
138 | IN EFI_EVENT_NOTIFY NotifyFunction,\r | |
139 | IN VOID *NotifyContext, OPTIONAL\r | |
140 | OUT VOID **Registration\r | |
141 | )\r | |
142 | {\r | |
143 | EFI_STATUS Status;\r | |
144 | EFI_EVENT Event;\r | |
145 | \r | |
1d37ab9f | 146 | ASSERT (ProtocolGuid != NULL);\r |
147 | ASSERT (NotifyFunction != NULL);\r | |
148 | ASSERT (Registration != NULL);\r | |
149 | \r | |
e386b444 | 150 | //\r |
151 | // Create the event\r | |
152 | //\r | |
153 | \r | |
154 | Status = gBS->CreateEvent (\r | |
155 | EVT_NOTIFY_SIGNAL,\r | |
156 | NotifyTpl,\r | |
157 | NotifyFunction,\r | |
158 | NotifyContext,\r | |
159 | &Event\r | |
160 | );\r | |
161 | ASSERT_EFI_ERROR (Status);\r | |
162 | \r | |
163 | //\r | |
6d28c497 | 164 | // Register for protocol notifications on this event\r |
e386b444 | 165 | //\r |
166 | \r | |
167 | Status = gBS->RegisterProtocolNotify (\r | |
168 | ProtocolGuid,\r | |
169 | Event,\r | |
170 | Registration\r | |
171 | );\r | |
172 | \r | |
173 | ASSERT_EFI_ERROR (Status);\r | |
174 | \r | |
175 | //\r | |
176 | // Kick the event so we will perform an initial pass of\r | |
177 | // current installed drivers\r | |
178 | //\r | |
179 | \r | |
180 | gBS->SignalEvent (Event);\r | |
181 | return Event;\r | |
182 | }\r | |
183 | \r | |
184 | /**\r | |
1d37ab9f | 185 | Creates a named event that can be signaled with EfiNamedEventSignal().\r |
186 | \r | |
e386b444 | 187 | This function creates an event using NotifyTpl, NoifyFunction, and NotifyContext.\r |
1d37ab9f | 188 | This event is signaled with EfiNamedEventSignal(). This provides the ability for one or more\r |
9095d37b | 189 | listeners on the same event named by the GUID specified by Name.\r |
9edc73ad | 190 | If Name is NULL, then ASSERT().\r |
191 | If NotifyTpl is not a legal TPL value, then ASSERT().\r | |
192 | If NotifyFunction is NULL, then ASSERT().\r | |
e386b444 | 193 | \r |
58380e9c | 194 | @param Name Supplies the GUID name of the event.\r |
e386b444 | 195 | @param NotifyTpl Supplies the task priority level of the event notifications.\r |
196 | @param NotifyFunction Supplies the function to notify when the event is signaled.\r | |
9095d37b | 197 | @param NotifyContext The context parameter to pass to NotifyFunction.\r |
e386b444 | 198 | @param Registration A pointer to a memory location to receive the registration value.\r |
199 | \r | |
200 | @retval EFI_SUCCESS A named event was created.\r | |
201 | @retval EFI_OUT_OF_RESOURCES There are not enough resource to create the named event.\r | |
202 | \r | |
203 | **/\r | |
204 | EFI_STATUS\r | |
205 | EFIAPI\r | |
206 | EfiNamedEventListen (\r | |
207 | IN CONST EFI_GUID *Name,\r | |
208 | IN EFI_TPL NotifyTpl,\r | |
209 | IN EFI_EVENT_NOTIFY NotifyFunction,\r | |
210 | IN CONST VOID *NotifyContext, OPTIONAL\r | |
211 | OUT VOID *Registration OPTIONAL\r | |
212 | )\r | |
213 | {\r | |
214 | EFI_STATUS Status;\r | |
215 | EFI_EVENT Event;\r | |
216 | VOID *RegistrationLocal;\r | |
217 | \r | |
9edc73ad | 218 | ASSERT (Name != NULL);\r |
219 | ASSERT (NotifyFunction != NULL);\r | |
220 | ASSERT (NotifyTpl <= TPL_HIGH_LEVEL);\r | |
9095d37b | 221 | \r |
e386b444 | 222 | //\r |
223 | // Create event\r | |
224 | //\r | |
225 | Status = gBS->CreateEvent (\r | |
226 | EVT_NOTIFY_SIGNAL,\r | |
227 | NotifyTpl,\r | |
228 | NotifyFunction,\r | |
229 | (VOID *) NotifyContext,\r | |
230 | &Event\r | |
231 | );\r | |
232 | ASSERT_EFI_ERROR (Status);\r | |
233 | \r | |
234 | //\r | |
235 | // The Registration is not optional to RegisterProtocolNotify().\r | |
236 | // To make it optional to EfiNamedEventListen(), may need to substitute with a local.\r | |
237 | //\r | |
238 | if (Registration != NULL) {\r | |
239 | RegistrationLocal = Registration;\r | |
240 | } else {\r | |
241 | RegistrationLocal = &RegistrationLocal;\r | |
242 | }\r | |
243 | \r | |
244 | //\r | |
245 | // Register for an installation of protocol interface\r | |
246 | //\r | |
247 | \r | |
248 | Status = gBS->RegisterProtocolNotify (\r | |
249 | (EFI_GUID *) Name,\r | |
250 | Event,\r | |
251 | RegistrationLocal\r | |
252 | );\r | |
253 | ASSERT_EFI_ERROR (Status);\r | |
254 | \r | |
9edc73ad | 255 | return Status;\r |
e386b444 | 256 | }\r |
257 | \r | |
258 | /**\r | |
1d37ab9f | 259 | Signals a named event created with EfiNamedEventListen().\r |
260 | \r | |
261 | This function signals the named event specified by Name. The named event must have been\r | |
262 | created with EfiNamedEventListen().\r | |
263 | If Name is NULL, then ASSERT().\r | |
e386b444 | 264 | \r |
58380e9c | 265 | @param Name Supplies the GUID name of the event.\r |
e386b444 | 266 | \r |
267 | @retval EFI_SUCCESS A named event was signaled.\r | |
268 | @retval EFI_OUT_OF_RESOURCES There are not enough resource to signal the named event.\r | |
269 | \r | |
270 | **/\r | |
271 | EFI_STATUS\r | |
272 | EFIAPI\r | |
273 | EfiNamedEventSignal (\r | |
274 | IN CONST EFI_GUID *Name\r | |
275 | )\r | |
276 | {\r | |
277 | EFI_STATUS Status;\r | |
278 | EFI_HANDLE Handle;\r | |
279 | \r | |
1d37ab9f | 280 | ASSERT(Name != NULL);\r |
281 | \r | |
e386b444 | 282 | Handle = NULL;\r |
283 | Status = gBS->InstallProtocolInterface (\r | |
284 | &Handle,\r | |
285 | (EFI_GUID *) Name,\r | |
286 | EFI_NATIVE_INTERFACE,\r | |
287 | NULL\r | |
288 | );\r | |
289 | ASSERT_EFI_ERROR (Status);\r | |
290 | \r | |
291 | Status = gBS->UninstallProtocolInterface (\r | |
292 | Handle,\r | |
293 | (EFI_GUID *) Name,\r | |
294 | NULL\r | |
295 | );\r | |
296 | ASSERT_EFI_ERROR (Status);\r | |
297 | \r | |
9edc73ad | 298 | return Status;\r |
e386b444 | 299 | }\r |
300 | \r | |
772fb7cb LE |
301 | /**\r |
302 | Signals an event group by placing a new event in the group temporarily and\r | |
303 | signaling it.\r | |
304 | \r | |
305 | @param[in] EventGroup Supplies the unique identifier of the event\r | |
306 | group to signal.\r | |
307 | \r | |
308 | @retval EFI_SUCCESS The event group was signaled successfully.\r | |
309 | @retval EFI_INVALID_PARAMETER EventGroup is NULL.\r | |
310 | @return Error codes that report problems about event\r | |
311 | creation or signaling.\r | |
312 | **/\r | |
313 | EFI_STATUS\r | |
314 | EFIAPI\r | |
315 | EfiEventGroupSignal (\r | |
316 | IN CONST EFI_GUID *EventGroup\r | |
317 | )\r | |
318 | {\r | |
319 | EFI_STATUS Status;\r | |
320 | EFI_EVENT Event;\r | |
321 | \r | |
322 | if (EventGroup == NULL) {\r | |
323 | return EFI_INVALID_PARAMETER;\r | |
324 | }\r | |
325 | \r | |
326 | Status = gBS->CreateEventEx (\r | |
327 | EVT_NOTIFY_SIGNAL,\r | |
328 | TPL_CALLBACK,\r | |
1b197063 | 329 | EfiEventEmptyFunction,\r |
772fb7cb LE |
330 | NULL,\r |
331 | EventGroup,\r | |
332 | &Event\r | |
333 | );\r | |
334 | if (EFI_ERROR (Status)) {\r | |
335 | return Status;\r | |
336 | }\r | |
337 | \r | |
338 | Status = gBS->SignalEvent (Event);\r | |
339 | gBS->CloseEvent (Event);\r | |
340 | \r | |
341 | return Status;\r | |
342 | }\r | |
343 | \r | |
1b197063 SZ |
344 | /**\r |
345 | An empty function that can be used as NotifyFunction parameter of\r | |
346 | CreateEvent() or CreateEventEx().\r | |
347 | \r | |
348 | @param Event Event whose notification function is being invoked.\r | |
349 | @param Context The pointer to the notification function's context,\r | |
350 | which is implementation-dependent.\r | |
351 | \r | |
352 | **/\r | |
353 | VOID\r | |
354 | EFIAPI\r | |
355 | EfiEventEmptyFunction (\r | |
356 | IN EFI_EVENT Event,\r | |
357 | IN VOID *Context\r | |
358 | )\r | |
359 | {\r | |
360 | }\r | |
361 | \r | |
9095d37b | 362 | /**\r |
e386b444 | 363 | Returns the current TPL.\r |
364 | \r | |
9095d37b LG |
365 | This function returns the current TPL. There is no EFI service to directly\r |
366 | retrieve the current TPL. Instead, the RaiseTPL() function is used to raise\r | |
367 | the TPL to TPL_HIGH_LEVEL. This will return the current TPL. The TPL level\r | |
368 | can then immediately be restored back to the current TPL level with a call\r | |
e386b444 | 369 | to RestoreTPL().\r |
370 | \r | |
cf8ae2f6 | 371 | @return The current TPL.\r |
e386b444 | 372 | \r |
373 | **/\r | |
374 | EFI_TPL\r | |
375 | EFIAPI\r | |
376 | EfiGetCurrentTpl (\r | |
377 | VOID\r | |
378 | )\r | |
379 | {\r | |
380 | EFI_TPL Tpl;\r | |
381 | \r | |
382 | Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r | |
383 | gBS->RestoreTPL (Tpl);\r | |
384 | \r | |
385 | return Tpl;\r | |
386 | }\r | |
387 | \r | |
388 | \r | |
389 | /**\r | |
1d37ab9f | 390 | Initializes a basic mutual exclusion lock.\r |
391 | \r | |
9095d37b LG |
392 | This function initializes a basic mutual exclusion lock to the released state\r |
393 | and returns the lock. Each lock provides mutual exclusion access at its task\r | |
e386b444 | 394 | priority level. Since there is no preemption or multiprocessor support in EFI,\r |
395 | acquiring the lock only consists of raising to the locks TPL.\r | |
9edc73ad | 396 | If Lock is NULL, then ASSERT().\r |
397 | If Priority is not a valid TPL value, then ASSERT().\r | |
e386b444 | 398 | \r |
399 | @param Lock A pointer to the lock data structure to initialize.\r | |
58380e9c | 400 | @param Priority EFI TPL is associated with the lock.\r |
e386b444 | 401 | \r |
402 | @return The lock.\r | |
403 | \r | |
404 | **/\r | |
405 | EFI_LOCK *\r | |
406 | EFIAPI\r | |
407 | EfiInitializeLock (\r | |
408 | IN OUT EFI_LOCK *Lock,\r | |
409 | IN EFI_TPL Priority\r | |
410 | )\r | |
411 | {\r | |
412 | ASSERT (Lock != NULL);\r | |
413 | ASSERT (Priority <= TPL_HIGH_LEVEL);\r | |
414 | \r | |
415 | Lock->Tpl = Priority;\r | |
416 | Lock->OwnerTpl = TPL_APPLICATION;\r | |
417 | Lock->Lock = EfiLockReleased ;\r | |
418 | return Lock;\r | |
419 | }\r | |
420 | \r | |
421 | /**\r | |
1d37ab9f | 422 | Acquires ownership of a lock.\r |
423 | \r | |
9095d37b LG |
424 | This function raises the system's current task priority level to the task\r |
425 | priority level of the mutual exclusion lock. Then, it places the lock in the\r | |
e386b444 | 426 | acquired state.\r |
9edc73ad | 427 | If Lock is NULL, then ASSERT().\r |
428 | If Lock is not initialized, then ASSERT().\r | |
429 | If Lock is already in the acquired state, then ASSERT().\r | |
e386b444 | 430 | \r |
1d37ab9f | 431 | @param Lock A pointer to the lock to acquire.\r |
e386b444 | 432 | \r |
433 | **/\r | |
434 | VOID\r | |
435 | EFIAPI\r | |
436 | EfiAcquireLock (\r | |
437 | IN EFI_LOCK *Lock\r | |
438 | )\r | |
439 | {\r | |
440 | ASSERT (Lock != NULL);\r | |
441 | ASSERT (Lock->Lock == EfiLockReleased);\r | |
442 | \r | |
443 | Lock->OwnerTpl = gBS->RaiseTPL (Lock->Tpl);\r | |
444 | Lock->Lock = EfiLockAcquired;\r | |
445 | }\r | |
446 | \r | |
447 | /**\r | |
cf8ae2f6 | 448 | Acquires ownership of a lock.\r |
1d37ab9f | 449 | \r |
cf8ae2f6 | 450 | This function raises the system's current task priority level to the task priority\r |
451 | level of the mutual exclusion lock. Then, it attempts to place the lock in the acquired state.\r | |
452 | If the lock is already in the acquired state, then EFI_ACCESS_DENIED is returned.\r | |
453 | Otherwise, EFI_SUCCESS is returned.\r | |
1d37ab9f | 454 | If Lock is NULL, then ASSERT().\r |
455 | If Lock is not initialized, then ASSERT().\r | |
e386b444 | 456 | \r |
457 | @param Lock A pointer to the lock to acquire.\r | |
458 | \r | |
459 | @retval EFI_SUCCESS The lock was acquired.\r | |
460 | @retval EFI_ACCESS_DENIED The lock could not be acquired because it is already owned.\r | |
461 | \r | |
462 | **/\r | |
463 | EFI_STATUS\r | |
464 | EFIAPI\r | |
465 | EfiAcquireLockOrFail (\r | |
466 | IN EFI_LOCK *Lock\r | |
467 | )\r | |
468 | {\r | |
469 | \r | |
470 | ASSERT (Lock != NULL);\r | |
471 | ASSERT (Lock->Lock != EfiLockUninitialized);\r | |
472 | \r | |
473 | if (Lock->Lock == EfiLockAcquired) {\r | |
474 | //\r | |
475 | // Lock is already owned, so bail out\r | |
476 | //\r | |
477 | return EFI_ACCESS_DENIED;\r | |
478 | }\r | |
479 | \r | |
480 | Lock->OwnerTpl = gBS->RaiseTPL (Lock->Tpl);\r | |
481 | \r | |
482 | Lock->Lock = EfiLockAcquired;\r | |
483 | \r | |
484 | return EFI_SUCCESS;\r | |
485 | }\r | |
486 | \r | |
487 | /**\r | |
1d37ab9f | 488 | Releases ownership of a lock.\r |
489 | \r | |
9095d37b LG |
490 | This function transitions a mutual exclusion lock from the acquired state to\r |
491 | the released state, and restores the system's task priority level to its\r | |
e386b444 | 492 | previous level.\r |
1d37ab9f | 493 | If Lock is NULL, then ASSERT().\r |
494 | If Lock is not initialized, then ASSERT().\r | |
495 | If Lock is already in the released state, then ASSERT().\r | |
e386b444 | 496 | \r |
497 | @param Lock A pointer to the lock to release.\r | |
498 | \r | |
499 | **/\r | |
500 | VOID\r | |
501 | EFIAPI\r | |
502 | EfiReleaseLock (\r | |
503 | IN EFI_LOCK *Lock\r | |
504 | )\r | |
505 | {\r | |
506 | EFI_TPL Tpl;\r | |
507 | \r | |
508 | ASSERT (Lock != NULL);\r | |
509 | ASSERT (Lock->Lock == EfiLockAcquired);\r | |
510 | \r | |
511 | Tpl = Lock->OwnerTpl;\r | |
512 | \r | |
513 | Lock->Lock = EfiLockReleased;\r | |
514 | \r | |
515 | gBS->RestoreTPL (Tpl);\r | |
516 | }\r | |
517 | \r | |
518 | /**\r | |
519 | Tests whether a controller handle is being managed by a specific driver.\r | |
520 | \r | |
521 | This function tests whether the driver specified by DriverBindingHandle is\r | |
522 | currently managing the controller specified by ControllerHandle. This test\r | |
523 | is performed by evaluating if the the protocol specified by ProtocolGuid is\r | |
524 | present on ControllerHandle and is was opened by DriverBindingHandle with an\r | |
9095d37b | 525 | attribute of EFI_OPEN_PROTOCOL_BY_DRIVER.\r |
e386b444 | 526 | If ProtocolGuid is NULL, then ASSERT().\r |
527 | \r | |
528 | @param ControllerHandle A handle for a controller to test.\r | |
529 | @param DriverBindingHandle Specifies the driver binding handle for the\r | |
530 | driver.\r | |
531 | @param ProtocolGuid Specifies the protocol that the driver specified\r | |
532 | by DriverBindingHandle opens in its Start()\r | |
533 | function.\r | |
534 | \r | |
535 | @retval EFI_SUCCESS ControllerHandle is managed by the driver\r | |
28d3e14f | 536 | specified by DriverBindingHandle.\r |
e386b444 | 537 | @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driver\r |
28d3e14f | 538 | specified by DriverBindingHandle.\r |
e386b444 | 539 | \r |
540 | **/\r | |
541 | EFI_STATUS\r | |
542 | EFIAPI\r | |
543 | EfiTestManagedDevice (\r | |
544 | IN CONST EFI_HANDLE ControllerHandle,\r | |
545 | IN CONST EFI_HANDLE DriverBindingHandle,\r | |
546 | IN CONST EFI_GUID *ProtocolGuid\r | |
547 | )\r | |
548 | {\r | |
549 | EFI_STATUS Status;\r | |
550 | VOID *ManagedInterface;\r | |
551 | \r | |
552 | ASSERT (ProtocolGuid != NULL);\r | |
553 | \r | |
554 | Status = gBS->OpenProtocol (\r | |
555 | ControllerHandle,\r | |
556 | (EFI_GUID *) ProtocolGuid,\r | |
557 | &ManagedInterface,\r | |
558 | DriverBindingHandle,\r | |
559 | ControllerHandle,\r | |
560 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
561 | );\r | |
562 | if (!EFI_ERROR (Status)) {\r | |
563 | gBS->CloseProtocol (\r | |
564 | ControllerHandle,\r | |
565 | (EFI_GUID *) ProtocolGuid,\r | |
566 | DriverBindingHandle,\r | |
567 | ControllerHandle\r | |
568 | );\r | |
569 | return EFI_UNSUPPORTED;\r | |
570 | }\r | |
571 | \r | |
572 | if (Status != EFI_ALREADY_STARTED) {\r | |
573 | return EFI_UNSUPPORTED;\r | |
574 | }\r | |
575 | \r | |
576 | return EFI_SUCCESS;\r | |
577 | }\r | |
578 | \r | |
579 | /**\r | |
580 | Tests whether a child handle is a child device of the controller.\r | |
581 | \r | |
582 | This function tests whether ChildHandle is one of the children of\r | |
583 | ControllerHandle. This test is performed by checking to see if the protocol\r | |
584 | specified by ProtocolGuid is present on ControllerHandle and opened by\r | |
585 | ChildHandle with an attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r | |
586 | If ProtocolGuid is NULL, then ASSERT().\r | |
587 | \r | |
9095d37b | 588 | @param ControllerHandle A handle for a (parent) controller to test.\r |
e386b444 | 589 | @param ChildHandle A child handle to test.\r |
42eedea9 | 590 | @param ProtocolGuid Supplies the protocol that the child controller\r |
9095d37b | 591 | opens on its parent controller.\r |
e386b444 | 592 | \r |
593 | @retval EFI_SUCCESS ChildHandle is a child of the ControllerHandle.\r | |
594 | @retval EFI_UNSUPPORTED ChildHandle is not a child of the\r | |
595 | ControllerHandle.\r | |
596 | \r | |
597 | **/\r | |
598 | EFI_STATUS\r | |
599 | EFIAPI\r | |
600 | EfiTestChildHandle (\r | |
601 | IN CONST EFI_HANDLE ControllerHandle,\r | |
602 | IN CONST EFI_HANDLE ChildHandle,\r | |
603 | IN CONST EFI_GUID *ProtocolGuid\r | |
604 | )\r | |
605 | {\r | |
606 | EFI_STATUS Status;\r | |
607 | EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r | |
608 | UINTN EntryCount;\r | |
609 | UINTN Index;\r | |
610 | \r | |
611 | ASSERT (ProtocolGuid != NULL);\r | |
612 | \r | |
613 | //\r | |
614 | // Retrieve the list of agents that are consuming the specific protocol\r | |
615 | // on ControllerHandle.\r | |
616 | //\r | |
617 | Status = gBS->OpenProtocolInformation (\r | |
618 | ControllerHandle,\r | |
619 | (EFI_GUID *) ProtocolGuid,\r | |
620 | &OpenInfoBuffer,\r | |
621 | &EntryCount\r | |
622 | );\r | |
623 | if (EFI_ERROR (Status)) {\r | |
624 | return EFI_UNSUPPORTED;\r | |
625 | }\r | |
626 | \r | |
627 | //\r | |
628 | // Inspect if ChildHandle is one of the agents.\r | |
629 | //\r | |
630 | Status = EFI_UNSUPPORTED;\r | |
631 | for (Index = 0; Index < EntryCount; Index++) {\r | |
632 | if ((OpenInfoBuffer[Index].ControllerHandle == ChildHandle) &&\r | |
633 | (OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r | |
634 | Status = EFI_SUCCESS;\r | |
635 | break;\r | |
636 | }\r | |
637 | }\r | |
638 | \r | |
639 | FreePool (OpenInfoBuffer);\r | |
640 | return Status;\r | |
641 | }\r | |
642 | \r | |
ea331a5c TZ |
643 | /**\r |
644 | * This function checks the supported languages list for a target language,\r | |
645 | * This only supports RFC 4646 Languages.\r | |
646 | *\r | |
647 | * @param SupportedLanguages The supported languages\r | |
648 | * @param TargetLanguage The target language\r | |
649 | *\r | |
650 | * @return Returns EFI_SUCCESS if the language is supported,\r | |
651 | * EFI_UNSUPPORTED otherwise\r | |
652 | */\r | |
653 | EFI_STATUS\r | |
654 | EFIAPI\r | |
655 | IsLanguageSupported (\r | |
656 | IN CONST CHAR8 *SupportedLanguages,\r | |
657 | IN CONST CHAR8 *TargetLanguage\r | |
658 | )\r | |
659 | {\r | |
660 | UINTN Index;\r | |
661 | while (*SupportedLanguages != 0) {\r | |
662 | for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++);\r | |
663 | if ((AsciiStrnCmp(SupportedLanguages, TargetLanguage, Index) == 0) && (TargetLanguage[Index] == 0)) {\r | |
664 | return EFI_SUCCESS;\r | |
665 | }\r | |
666 | SupportedLanguages += Index;\r | |
667 | for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++);\r | |
668 | }\r | |
669 | \r | |
670 | return EFI_UNSUPPORTED;\r | |
671 | }\r | |
672 | \r | |
e386b444 | 673 | /**\r |
dd51a993 | 674 | This function looks up a Unicode string in UnicodeStringTable.\r |
dd51a993 | 675 | \r |
cf8ae2f6 | 676 | If Language is a member of SupportedLanguages and a Unicode string is found in\r |
1d37ab9f | 677 | UnicodeStringTable that matches the language code specified by Language, then it\r |
678 | is returned in UnicodeString.\r | |
679 | \r | |
9095d37b | 680 | @param Language A pointer to the ISO 639-2 language code for the\r |
1d37ab9f | 681 | Unicode string to look up and return.\r |
9095d37b LG |
682 | @param SupportedLanguages A pointer to the set of ISO 639-2 language codes\r |
683 | that the Unicode string table supports. Language\r | |
1d37ab9f | 684 | must be a member of this set.\r |
685 | @param UnicodeStringTable A pointer to the table of Unicode strings.\r | |
686 | @param UnicodeString A pointer to the Unicode string from UnicodeStringTable\r | |
687 | that matches the language specified by Language.\r | |
688 | \r | |
9095d37b | 689 | @retval EFI_SUCCESS The Unicode string that matches the language\r |
1d37ab9f | 690 | specified by Language was found\r |
9095d37b | 691 | in the table of Unicode strings UnicodeStringTable,\r |
1d37ab9f | 692 | and it was returned in UnicodeString.\r |
693 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
694 | @retval EFI_INVALID_PARAMETER UnicodeString is NULL.\r | |
695 | @retval EFI_UNSUPPORTED SupportedLanguages is NULL.\r | |
696 | @retval EFI_UNSUPPORTED UnicodeStringTable is NULL.\r | |
9095d37b | 697 | @retval EFI_UNSUPPORTED The language specified by Language is not a\r |
1d37ab9f | 698 | member of SupportedLanguages.\r |
9095d37b | 699 | @retval EFI_UNSUPPORTED The language specified by Language is not\r |
1d37ab9f | 700 | supported by UnicodeStringTable.\r |
e386b444 | 701 | \r |
702 | **/\r | |
703 | EFI_STATUS\r | |
704 | EFIAPI\r | |
705 | LookupUnicodeString (\r | |
706 | IN CONST CHAR8 *Language,\r | |
707 | IN CONST CHAR8 *SupportedLanguages,\r | |
708 | IN CONST EFI_UNICODE_STRING_TABLE *UnicodeStringTable,\r | |
709 | OUT CHAR16 **UnicodeString\r | |
710 | )\r | |
711 | {\r | |
712 | //\r | |
713 | // Make sure the parameters are valid\r | |
714 | //\r | |
715 | if (Language == NULL || UnicodeString == NULL) {\r | |
716 | return EFI_INVALID_PARAMETER;\r | |
717 | }\r | |
718 | \r | |
719 | //\r | |
720 | // If there are no supported languages, or the Unicode String Table is empty, then the\r | |
721 | // Unicode String specified by Language is not supported by this Unicode String Table\r | |
722 | //\r | |
723 | if (SupportedLanguages == NULL || UnicodeStringTable == NULL) {\r | |
724 | return EFI_UNSUPPORTED;\r | |
725 | }\r | |
726 | \r | |
727 | //\r | |
728 | // Make sure Language is in the set of Supported Languages\r | |
729 | //\r | |
730 | while (*SupportedLanguages != 0) {\r | |
731 | if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r | |
732 | \r | |
733 | //\r | |
734 | // Search the Unicode String Table for the matching Language specifier\r | |
735 | //\r | |
736 | while (UnicodeStringTable->Language != NULL) {\r | |
737 | if (CompareIso639LanguageCode (Language, UnicodeStringTable->Language)) {\r | |
738 | \r | |
739 | //\r | |
740 | // A matching string was found, so return it\r | |
741 | //\r | |
742 | *UnicodeString = UnicodeStringTable->UnicodeString;\r | |
743 | return EFI_SUCCESS;\r | |
744 | }\r | |
745 | \r | |
746 | UnicodeStringTable++;\r | |
747 | }\r | |
748 | \r | |
749 | return EFI_UNSUPPORTED;\r | |
750 | }\r | |
751 | \r | |
752 | SupportedLanguages += 3;\r | |
753 | }\r | |
754 | \r | |
755 | return EFI_UNSUPPORTED;\r | |
756 | }\r | |
757 | \r | |
dd51a993 | 758 | \r |
759 | \r | |
e386b444 | 760 | /**\r |
dd51a993 | 761 | This function looks up a Unicode string in UnicodeStringTable.\r |
cf8ae2f6 | 762 | \r |
763 | If Language is a member of SupportedLanguages and a Unicode string is found in\r | |
764 | UnicodeStringTable that matches the language code specified by Language, then\r | |
765 | it is returned in UnicodeString.\r | |
766 | \r | |
767 | @param Language A pointer to an ASCII string containing the ISO 639-2 or the\r | |
768 | RFC 4646 language code for the Unicode string to look up and\r | |
769 | return. If Iso639Language is TRUE, then this ASCII string is\r | |
770 | not assumed to be Null-terminated, and only the first three\r | |
28d3e14f | 771 | characters are used. If Iso639Language is FALSE, then this ASCII\r |
9095d37b | 772 | string must be Null-terminated.\r |
cf8ae2f6 | 773 | @param SupportedLanguages A pointer to a Null-terminated ASCII string that contains a\r |
774 | set of ISO 639-2 or RFC 4646 language codes that the Unicode\r | |
775 | string table supports. Language must be a member of this set.\r | |
776 | If Iso639Language is TRUE, then this string contains one or more\r | |
777 | ISO 639-2 language codes with no separator characters. If Iso639Language\r | |
778 | is FALSE, then is string contains one or more RFC 4646 language\r | |
779 | codes separated by ';'.\r | |
780 | @param UnicodeStringTable A pointer to the table of Unicode strings. Type EFI_UNICODE_STRING_TABLE\r | |
781 | is defined in "Related Definitions".\r | |
782 | @param UnicodeString A pointer to the Null-terminated Unicode string from UnicodeStringTable\r | |
783 | that matches the language specified by Language.\r | |
784 | @param Iso639Language Specifies the supported language code format. If it is TRUE, then\r | |
785 | Language and SupportedLanguages follow ISO 639-2 language code format.\r | |
786 | Otherwise, they follow RFC 4646 language code format.\r | |
787 | \r | |
788 | \r | |
789 | @retval EFI_SUCCESS The Unicode string that matches the language specified by Language\r | |
790 | was found in the table of Unicode strings UnicodeStringTable, and\r | |
791 | it was returned in UnicodeString.\r | |
9095d37b LG |
792 | @retval EFI_INVALID_PARAMETER Language is NULL.\r |
793 | @retval EFI_INVALID_PARAMETER UnicodeString is NULL.\r | |
794 | @retval EFI_UNSUPPORTED SupportedLanguages is NULL.\r | |
795 | @retval EFI_UNSUPPORTED UnicodeStringTable is NULL.\r | |
796 | @retval EFI_UNSUPPORTED The language specified by Language is not a member of SupportedLanguages.\r | |
cf8ae2f6 | 797 | @retval EFI_UNSUPPORTED The language specified by Language is not supported by UnicodeStringTable.\r |
dd51a993 | 798 | \r |
799 | **/\r | |
800 | EFI_STATUS\r | |
801 | EFIAPI\r | |
802 | LookupUnicodeString2 (\r | |
803 | IN CONST CHAR8 *Language,\r | |
804 | IN CONST CHAR8 *SupportedLanguages,\r | |
805 | IN CONST EFI_UNICODE_STRING_TABLE *UnicodeStringTable,\r | |
806 | OUT CHAR16 **UnicodeString,\r | |
807 | IN BOOLEAN Iso639Language\r | |
808 | )\r | |
809 | {\r | |
810 | BOOLEAN Found;\r | |
811 | UINTN Index;\r | |
812 | CHAR8 *LanguageString;\r | |
813 | \r | |
814 | //\r | |
815 | // Make sure the parameters are valid\r | |
816 | //\r | |
817 | if (Language == NULL || UnicodeString == NULL) {\r | |
818 | return EFI_INVALID_PARAMETER;\r | |
819 | }\r | |
820 | \r | |
821 | //\r | |
822 | // If there are no supported languages, or the Unicode String Table is empty, then the\r | |
823 | // Unicode String specified by Language is not supported by this Unicode String Table\r | |
824 | //\r | |
825 | if (SupportedLanguages == NULL || UnicodeStringTable == NULL) {\r | |
826 | return EFI_UNSUPPORTED;\r | |
827 | }\r | |
828 | \r | |
829 | //\r | |
830 | // Make sure Language is in the set of Supported Languages\r | |
831 | //\r | |
832 | Found = FALSE;\r | |
ea331a5c TZ |
833 | if (Iso639Language) {\r |
834 | while (*SupportedLanguages != 0) {\r | |
dd51a993 | 835 | if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r |
836 | Found = TRUE;\r | |
837 | break;\r | |
838 | }\r | |
839 | SupportedLanguages += 3;\r | |
dd51a993 | 840 | }\r |
ea331a5c TZ |
841 | } else {\r |
842 | Found = !IsLanguageSupported(Language, SupportedLanguages);\r | |
dd51a993 | 843 | }\r |
844 | \r | |
ea331a5c | 845 | \r |
dd51a993 | 846 | //\r |
847 | // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED\r | |
848 | //\r | |
849 | if (!Found) {\r | |
850 | return EFI_UNSUPPORTED;\r | |
851 | }\r | |
852 | \r | |
853 | //\r | |
854 | // Search the Unicode String Table for the matching Language specifier\r | |
855 | //\r | |
856 | while (UnicodeStringTable->Language != NULL) {\r | |
857 | LanguageString = UnicodeStringTable->Language;\r | |
858 | while (0 != *LanguageString) {\r | |
859 | for (Index = 0 ;LanguageString[Index] != 0 && LanguageString[Index] != ';'; Index++);\r | |
860 | if (AsciiStrnCmp(LanguageString, Language, Index) == 0) {\r | |
861 | *UnicodeString = UnicodeStringTable->UnicodeString;\r | |
862 | return EFI_SUCCESS;\r | |
863 | }\r | |
864 | LanguageString += Index;\r | |
865 | for (Index = 0 ;LanguageString[Index] != 0 && LanguageString[Index] == ';'; Index++);\r | |
866 | }\r | |
867 | UnicodeStringTable++;\r | |
868 | }\r | |
869 | \r | |
870 | return EFI_UNSUPPORTED;\r | |
871 | }\r | |
872 | \r | |
873 | \r | |
874 | /**\r | |
e386b444 | 875 | This function adds a Unicode string to UnicodeStringTable.\r |
1d37ab9f | 876 | \r |
9095d37b LG |
877 | If Language is a member of SupportedLanguages then UnicodeString is added to\r |
878 | UnicodeStringTable. New buffers are allocated for both Language and\r | |
879 | UnicodeString. The contents of Language and UnicodeString are copied into\r | |
880 | these new buffers. These buffers are automatically freed when\r | |
e386b444 | 881 | FreeUnicodeStringTable() is called.\r |
882 | \r | |
9095d37b | 883 | @param Language A pointer to the ISO 639-2 language code for the Unicode\r |
e386b444 | 884 | string to add.\r |
1d37ab9f | 885 | @param SupportedLanguages A pointer to the set of ISO 639-2 language codes\r |
886 | that the Unicode string table supports.\r | |
887 | Language must be a member of this set.\r | |
888 | @param UnicodeStringTable A pointer to the table of Unicode strings.\r | |
889 | @param UnicodeString A pointer to the Unicode string to add.\r | |
890 | \r | |
9095d37b LG |
891 | @retval EFI_SUCCESS The Unicode string that matches the language\r |
892 | specified by Language was found in the table of\r | |
893 | Unicode strings UnicodeStringTable, and it was\r | |
e386b444 | 894 | returned in UnicodeString.\r |
895 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
896 | @retval EFI_INVALID_PARAMETER UnicodeString is NULL.\r | |
897 | @retval EFI_INVALID_PARAMETER UnicodeString is an empty string.\r | |
898 | @retval EFI_UNSUPPORTED SupportedLanguages is NULL.\r | |
9095d37b | 899 | @retval EFI_ALREADY_STARTED A Unicode string with language Language is\r |
1d37ab9f | 900 | already present in UnicodeStringTable.\r |
9095d37b | 901 | @retval EFI_OUT_OF_RESOURCES There is not enough memory to add another\r |
1d37ab9f | 902 | Unicode string to UnicodeStringTable.\r |
9095d37b | 903 | @retval EFI_UNSUPPORTED The language specified by Language is not a\r |
1d37ab9f | 904 | member of SupportedLanguages.\r |
e386b444 | 905 | \r |
906 | **/\r | |
907 | EFI_STATUS\r | |
908 | EFIAPI\r | |
909 | AddUnicodeString (\r | |
5b9626e8 MH |
910 | IN CONST CHAR8 *Language,\r |
911 | IN CONST CHAR8 *SupportedLanguages,\r | |
912 | IN OUT EFI_UNICODE_STRING_TABLE **UnicodeStringTable,\r | |
913 | IN CONST CHAR16 *UnicodeString\r | |
e386b444 | 914 | )\r |
915 | {\r | |
916 | UINTN NumberOfEntries;\r | |
917 | EFI_UNICODE_STRING_TABLE *OldUnicodeStringTable;\r | |
918 | EFI_UNICODE_STRING_TABLE *NewUnicodeStringTable;\r | |
919 | UINTN UnicodeStringLength;\r | |
920 | \r | |
921 | //\r | |
922 | // Make sure the parameter are valid\r | |
923 | //\r | |
924 | if (Language == NULL || UnicodeString == NULL || UnicodeStringTable == NULL) {\r | |
925 | return EFI_INVALID_PARAMETER;\r | |
926 | }\r | |
927 | \r | |
928 | //\r | |
929 | // If there are no supported languages, then a Unicode String can not be added\r | |
930 | //\r | |
931 | if (SupportedLanguages == NULL) {\r | |
932 | return EFI_UNSUPPORTED;\r | |
933 | }\r | |
934 | \r | |
935 | //\r | |
936 | // If the Unicode String is empty, then a Unicode String can not be added\r | |
937 | //\r | |
938 | if (UnicodeString[0] == 0) {\r | |
939 | return EFI_INVALID_PARAMETER;\r | |
940 | }\r | |
941 | \r | |
942 | //\r | |
943 | // Make sure Language is a member of SupportedLanguages\r | |
944 | //\r | |
945 | while (*SupportedLanguages != 0) {\r | |
946 | if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r | |
947 | \r | |
948 | //\r | |
949 | // Determine the size of the Unicode String Table by looking for a NULL Language entry\r | |
950 | //\r | |
951 | NumberOfEntries = 0;\r | |
952 | if (*UnicodeStringTable != NULL) {\r | |
953 | OldUnicodeStringTable = *UnicodeStringTable;\r | |
954 | while (OldUnicodeStringTable->Language != NULL) {\r | |
955 | if (CompareIso639LanguageCode (Language, OldUnicodeStringTable->Language)) {\r | |
956 | return EFI_ALREADY_STARTED;\r | |
957 | }\r | |
958 | \r | |
959 | OldUnicodeStringTable++;\r | |
960 | NumberOfEntries++;\r | |
961 | }\r | |
962 | }\r | |
963 | \r | |
964 | //\r | |
965 | // Allocate space for a new Unicode String Table. It must hold the current number of\r | |
966 | // entries, plus 1 entry for the new Unicode String, plus 1 entry for the end of table\r | |
967 | // marker\r | |
968 | //\r | |
969 | NewUnicodeStringTable = AllocatePool ((NumberOfEntries + 2) * sizeof (EFI_UNICODE_STRING_TABLE));\r | |
970 | if (NewUnicodeStringTable == NULL) {\r | |
971 | return EFI_OUT_OF_RESOURCES;\r | |
972 | }\r | |
973 | \r | |
974 | //\r | |
975 | // If the current Unicode String Table contains any entries, then copy them to the\r | |
976 | // newly allocated Unicode String Table.\r | |
977 | //\r | |
978 | if (*UnicodeStringTable != NULL) {\r | |
979 | CopyMem (\r | |
980 | NewUnicodeStringTable,\r | |
981 | *UnicodeStringTable,\r | |
982 | NumberOfEntries * sizeof (EFI_UNICODE_STRING_TABLE)\r | |
983 | );\r | |
984 | }\r | |
985 | \r | |
986 | //\r | |
987 | // Allocate space for a copy of the Language specifier\r | |
988 | //\r | |
989 | NewUnicodeStringTable[NumberOfEntries].Language = AllocateCopyPool (3, Language);\r | |
990 | if (NewUnicodeStringTable[NumberOfEntries].Language == NULL) {\r | |
6389e32b | 991 | FreePool (NewUnicodeStringTable);\r |
e386b444 | 992 | return EFI_OUT_OF_RESOURCES;\r |
993 | }\r | |
994 | \r | |
995 | //\r | |
996 | // Compute the length of the Unicode String\r | |
997 | //\r | |
998 | for (UnicodeStringLength = 0; UnicodeString[UnicodeStringLength] != 0; UnicodeStringLength++)\r | |
999 | ;\r | |
1000 | \r | |
1001 | //\r | |
1002 | // Allocate space for a copy of the Unicode String\r | |
1003 | //\r | |
1004 | NewUnicodeStringTable[NumberOfEntries].UnicodeString = AllocateCopyPool (\r | |
1005 | (UnicodeStringLength + 1) * sizeof (CHAR16),\r | |
1006 | UnicodeString\r | |
1007 | );\r | |
1008 | if (NewUnicodeStringTable[NumberOfEntries].UnicodeString == NULL) {\r | |
6389e32b LG |
1009 | FreePool (NewUnicodeStringTable[NumberOfEntries].Language);\r |
1010 | FreePool (NewUnicodeStringTable);\r | |
e386b444 | 1011 | return EFI_OUT_OF_RESOURCES;\r |
1012 | }\r | |
1013 | \r | |
1014 | //\r | |
1015 | // Mark the end of the Unicode String Table\r | |
1016 | //\r | |
1017 | NewUnicodeStringTable[NumberOfEntries + 1].Language = NULL;\r | |
1018 | NewUnicodeStringTable[NumberOfEntries + 1].UnicodeString = NULL;\r | |
1019 | \r | |
1020 | //\r | |
1021 | // Free the old Unicode String Table\r | |
1022 | //\r | |
1023 | if (*UnicodeStringTable != NULL) {\r | |
6389e32b | 1024 | FreePool (*UnicodeStringTable);\r |
e386b444 | 1025 | }\r |
1026 | \r | |
1027 | //\r | |
1028 | // Point UnicodeStringTable at the newly allocated Unicode String Table\r | |
1029 | //\r | |
1030 | *UnicodeStringTable = NewUnicodeStringTable;\r | |
1031 | \r | |
1032 | return EFI_SUCCESS;\r | |
1033 | }\r | |
1034 | \r | |
1035 | SupportedLanguages += 3;\r | |
1036 | }\r | |
1037 | \r | |
1038 | return EFI_UNSUPPORTED;\r | |
1039 | }\r | |
1040 | \r | |
dd51a993 | 1041 | \r |
1042 | /**\r | |
cf8ae2f6 | 1043 | This function adds the Null-terminated Unicode string specified by UnicodeString\r |
1044 | to UnicodeStringTable.\r | |
1045 | \r | |
1046 | If Language is a member of SupportedLanguages then UnicodeString is added to\r | |
1047 | UnicodeStringTable. New buffers are allocated for both Language and UnicodeString.\r | |
1048 | The contents of Language and UnicodeString are copied into these new buffers.\r | |
1049 | These buffers are automatically freed when EfiLibFreeUnicodeStringTable() is called.\r | |
1050 | \r | |
1051 | @param Language A pointer to an ASCII string containing the ISO 639-2 or\r | |
1052 | the RFC 4646 language code for the Unicode string to add.\r | |
1053 | If Iso639Language is TRUE, then this ASCII string is not\r | |
1054 | assumed to be Null-terminated, and only the first three\r | |
1055 | chacters are used. If Iso639Language is FALSE, then this\r | |
1056 | ASCII string must be Null-terminated.\r | |
1057 | @param SupportedLanguages A pointer to a Null-terminated ASCII string that contains\r | |
1058 | a set of ISO 639-2 or RFC 4646 language codes that the Unicode\r | |
1059 | string table supports. Language must be a member of this set.\r | |
1060 | If Iso639Language is TRUE, then this string contains one or more\r | |
1061 | ISO 639-2 language codes with no separator characters.\r | |
1062 | If Iso639Language is FALSE, then is string contains one or more\r | |
1063 | RFC 4646 language codes separated by ';'.\r | |
1064 | @param UnicodeStringTable A pointer to the table of Unicode strings. Type EFI_UNICODE_STRING_TABLE\r | |
1065 | is defined in "Related Definitions".\r | |
9095d37b | 1066 | @param UnicodeString A pointer to the Unicode string to add.\r |
cf8ae2f6 | 1067 | @param Iso639Language Specifies the supported language code format. If it is TRUE,\r |
1068 | then Language and SupportedLanguages follow ISO 639-2 language code format.\r | |
1069 | Otherwise, they follow RFC 4646 language code format.\r | |
1070 | \r | |
1071 | @retval EFI_SUCCESS The Unicode string that matches the language specified by\r | |
1072 | Language was found in the table of Unicode strings UnicodeStringTable,\r | |
9095d37b LG |
1073 | and it was returned in UnicodeString.\r |
1074 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
1075 | @retval EFI_INVALID_PARAMETER UnicodeString is NULL.\r | |
1076 | @retval EFI_INVALID_PARAMETER UnicodeString is an empty string.\r | |
1077 | @retval EFI_UNSUPPORTED SupportedLanguages is NULL.\r | |
cf8ae2f6 | 1078 | @retval EFI_ALREADY_STARTED A Unicode string with language Language is already present in\r |
9095d37b LG |
1079 | UnicodeStringTable.\r |
1080 | @retval EFI_OUT_OF_RESOURCES There is not enough memory to add another Unicode string UnicodeStringTable.\r | |
cf8ae2f6 | 1081 | @retval EFI_UNSUPPORTED The language specified by Language is not a member of SupportedLanguages.\r |
dd51a993 | 1082 | \r |
1083 | **/\r | |
1084 | EFI_STATUS\r | |
1085 | EFIAPI\r | |
1086 | AddUnicodeString2 (\r | |
5b9626e8 MH |
1087 | IN CONST CHAR8 *Language,\r |
1088 | IN CONST CHAR8 *SupportedLanguages,\r | |
1089 | IN OUT EFI_UNICODE_STRING_TABLE **UnicodeStringTable,\r | |
1090 | IN CONST CHAR16 *UnicodeString,\r | |
1091 | IN BOOLEAN Iso639Language\r | |
dd51a993 | 1092 | )\r |
1093 | {\r | |
1094 | UINTN NumberOfEntries;\r | |
1095 | EFI_UNICODE_STRING_TABLE *OldUnicodeStringTable;\r | |
1096 | EFI_UNICODE_STRING_TABLE *NewUnicodeStringTable;\r | |
1097 | UINTN UnicodeStringLength;\r | |
1098 | BOOLEAN Found;\r | |
1099 | UINTN Index;\r | |
1100 | CHAR8 *LanguageString;\r | |
1101 | \r | |
1102 | //\r | |
1103 | // Make sure the parameter are valid\r | |
1104 | //\r | |
1105 | if (Language == NULL || UnicodeString == NULL || UnicodeStringTable == NULL) {\r | |
1106 | return EFI_INVALID_PARAMETER;\r | |
1107 | }\r | |
1108 | \r | |
1109 | //\r | |
1110 | // If there are no supported languages, then a Unicode String can not be added\r | |
1111 | //\r | |
1112 | if (SupportedLanguages == NULL) {\r | |
1113 | return EFI_UNSUPPORTED;\r | |
1114 | }\r | |
1115 | \r | |
1116 | //\r | |
1117 | // If the Unicode String is empty, then a Unicode String can not be added\r | |
1118 | //\r | |
1119 | if (UnicodeString[0] == 0) {\r | |
1120 | return EFI_INVALID_PARAMETER;\r | |
1121 | }\r | |
1122 | \r | |
1123 | //\r | |
1124 | // Make sure Language is a member of SupportedLanguages\r | |
1125 | //\r | |
1126 | Found = FALSE;\r | |
ea331a5c TZ |
1127 | if (Iso639Language) {\r |
1128 | while (*SupportedLanguages != 0) {\r | |
dd51a993 | 1129 | if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r |
1130 | Found = TRUE;\r | |
1131 | break;\r | |
1132 | }\r | |
1133 | SupportedLanguages += 3;\r | |
dd51a993 | 1134 | }\r |
ea331a5c TZ |
1135 | } else {\r |
1136 | Found = !IsLanguageSupported(Language, SupportedLanguages);\r | |
dd51a993 | 1137 | }\r |
dd51a993 | 1138 | //\r |
1139 | // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED\r | |
1140 | //\r | |
1141 | if (!Found) {\r | |
1142 | return EFI_UNSUPPORTED;\r | |
1143 | }\r | |
1144 | \r | |
1145 | //\r | |
1146 | // Determine the size of the Unicode String Table by looking for a NULL Language entry\r | |
1147 | //\r | |
1148 | NumberOfEntries = 0;\r | |
1149 | if (*UnicodeStringTable != NULL) {\r | |
1150 | OldUnicodeStringTable = *UnicodeStringTable;\r | |
1151 | while (OldUnicodeStringTable->Language != NULL) {\r | |
1152 | LanguageString = OldUnicodeStringTable->Language;\r | |
1153 | \r | |
42eedea9 | 1154 | while (*LanguageString != 0) {\r |
dd51a993 | 1155 | for (Index = 0; LanguageString[Index] != 0 && LanguageString[Index] != ';'; Index++);\r |
1156 | \r | |
9095d37b | 1157 | if (AsciiStrnCmp (Language, LanguageString, Index) == 0) {\r |
dd51a993 | 1158 | return EFI_ALREADY_STARTED;\r |
1159 | }\r | |
1160 | LanguageString += Index;\r | |
1161 | for (; *LanguageString != 0 && *LanguageString == ';'; LanguageString++);\r | |
1162 | }\r | |
1163 | OldUnicodeStringTable++;\r | |
1164 | NumberOfEntries++;\r | |
1165 | }\r | |
1166 | }\r | |
1167 | \r | |
1168 | //\r | |
1169 | // Allocate space for a new Unicode String Table. It must hold the current number of\r | |
1170 | // entries, plus 1 entry for the new Unicode String, plus 1 entry for the end of table\r | |
1171 | // marker\r | |
1172 | //\r | |
1173 | NewUnicodeStringTable = AllocatePool ((NumberOfEntries + 2) * sizeof (EFI_UNICODE_STRING_TABLE));\r | |
1174 | if (NewUnicodeStringTable == NULL) {\r | |
1175 | return EFI_OUT_OF_RESOURCES;\r | |
1176 | }\r | |
1177 | \r | |
1178 | //\r | |
1179 | // If the current Unicode String Table contains any entries, then copy them to the\r | |
1180 | // newly allocated Unicode String Table.\r | |
1181 | //\r | |
1182 | if (*UnicodeStringTable != NULL) {\r | |
1183 | CopyMem (\r | |
1184 | NewUnicodeStringTable,\r | |
1185 | *UnicodeStringTable,\r | |
1186 | NumberOfEntries * sizeof (EFI_UNICODE_STRING_TABLE)\r | |
1187 | );\r | |
1188 | }\r | |
1189 | \r | |
1190 | //\r | |
1191 | // Allocate space for a copy of the Language specifier\r | |
1192 | //\r | |
1193 | NewUnicodeStringTable[NumberOfEntries].Language = AllocateCopyPool (AsciiStrSize(Language), Language);\r | |
1194 | if (NewUnicodeStringTable[NumberOfEntries].Language == NULL) {\r | |
6389e32b | 1195 | FreePool (NewUnicodeStringTable);\r |
dd51a993 | 1196 | return EFI_OUT_OF_RESOURCES;\r |
1197 | }\r | |
1198 | \r | |
1199 | //\r | |
1200 | // Compute the length of the Unicode String\r | |
1201 | //\r | |
1202 | for (UnicodeStringLength = 0; UnicodeString[UnicodeStringLength] != 0; UnicodeStringLength++);\r | |
1203 | \r | |
1204 | //\r | |
1205 | // Allocate space for a copy of the Unicode String\r | |
1206 | //\r | |
1207 | NewUnicodeStringTable[NumberOfEntries].UnicodeString = AllocateCopyPool (StrSize (UnicodeString), UnicodeString);\r | |
1208 | if (NewUnicodeStringTable[NumberOfEntries].UnicodeString == NULL) {\r | |
6389e32b LG |
1209 | FreePool (NewUnicodeStringTable[NumberOfEntries].Language);\r |
1210 | FreePool (NewUnicodeStringTable);\r | |
dd51a993 | 1211 | return EFI_OUT_OF_RESOURCES;\r |
1212 | }\r | |
1213 | \r | |
1214 | //\r | |
1215 | // Mark the end of the Unicode String Table\r | |
1216 | //\r | |
1217 | NewUnicodeStringTable[NumberOfEntries + 1].Language = NULL;\r | |
1218 | NewUnicodeStringTable[NumberOfEntries + 1].UnicodeString = NULL;\r | |
1219 | \r | |
1220 | //\r | |
1221 | // Free the old Unicode String Table\r | |
1222 | //\r | |
1223 | if (*UnicodeStringTable != NULL) {\r | |
6389e32b | 1224 | FreePool (*UnicodeStringTable);\r |
dd51a993 | 1225 | }\r |
1226 | \r | |
1227 | //\r | |
1228 | // Point UnicodeStringTable at the newly allocated Unicode String Table\r | |
1229 | //\r | |
1230 | *UnicodeStringTable = NewUnicodeStringTable;\r | |
1231 | \r | |
1232 | return EFI_SUCCESS;\r | |
1233 | }\r | |
1234 | \r | |
e386b444 | 1235 | /**\r |
1236 | This function frees the table of Unicode strings in UnicodeStringTable.\r | |
1d37ab9f | 1237 | \r |
e386b444 | 1238 | If UnicodeStringTable is NULL, then EFI_SUCCESS is returned.\r |
9095d37b | 1239 | Otherwise, each language code, and each Unicode string in the Unicode string\r |
e386b444 | 1240 | table are freed, and EFI_SUCCESS is returned.\r |
1241 | \r | |
1242 | @param UnicodeStringTable A pointer to the table of Unicode strings.\r | |
1243 | \r | |
1244 | @retval EFI_SUCCESS The Unicode string table was freed.\r | |
1245 | \r | |
1246 | **/\r | |
1247 | EFI_STATUS\r | |
1248 | EFIAPI\r | |
1249 | FreeUnicodeStringTable (\r | |
1250 | IN EFI_UNICODE_STRING_TABLE *UnicodeStringTable\r | |
1251 | )\r | |
1252 | {\r | |
1253 | UINTN Index;\r | |
1254 | \r | |
1255 | //\r | |
1256 | // If the Unicode String Table is NULL, then it is already freed\r | |
1257 | //\r | |
1258 | if (UnicodeStringTable == NULL) {\r | |
1259 | return EFI_SUCCESS;\r | |
1260 | }\r | |
1261 | \r | |
1262 | //\r | |
1263 | // Loop through the Unicode String Table until we reach the end of table marker\r | |
1264 | //\r | |
1265 | for (Index = 0; UnicodeStringTable[Index].Language != NULL; Index++) {\r | |
1266 | \r | |
1267 | //\r | |
1268 | // Free the Language string from the Unicode String Table\r | |
1269 | //\r | |
6389e32b | 1270 | FreePool (UnicodeStringTable[Index].Language);\r |
e386b444 | 1271 | \r |
1272 | //\r | |
1273 | // Free the Unicode String from the Unicode String Table\r | |
1274 | //\r | |
1275 | if (UnicodeStringTable[Index].UnicodeString != NULL) {\r | |
6389e32b | 1276 | FreePool (UnicodeStringTable[Index].UnicodeString);\r |
e386b444 | 1277 | }\r |
1278 | }\r | |
1279 | \r | |
1280 | //\r | |
1281 | // Free the Unicode String Table itself\r | |
1282 | //\r | |
6389e32b | 1283 | FreePool (UnicodeStringTable);\r |
e386b444 | 1284 | \r |
1285 | return EFI_SUCCESS;\r | |
1286 | }\r | |
6d28c497 | 1287 | \r |
bf4a3dbd ED |
1288 | #ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r |
1289 | \r | |
6d28c497 | 1290 | /**\r |
bf4a3dbd ED |
1291 | [ATTENTION] This function will be deprecated for security reason.\r |
1292 | \r | |
9095d37b LG |
1293 | Returns a pointer to an allocated buffer that contains the contents of a\r |
1294 | variable retrieved through the UEFI Runtime Service GetVariable(). The\r | |
28d3e14f | 1295 | returned buffer is allocated using AllocatePool(). The caller is responsible\r |
1296 | for freeing this buffer with FreePool().\r | |
6d28c497 | 1297 | \r |
28d3e14f | 1298 | If Name is NULL, then ASSERT().\r |
1299 | If Guid is NULL, then ASSERT().\r | |
6d28c497 | 1300 | \r |
2fc59a00 | 1301 | @param[in] Name The pointer to a Null-terminated Unicode string.\r |
1302 | @param[in] Guid The pointer to an EFI_GUID structure\r | |
6d28c497 | 1303 | \r |
28d3e14f | 1304 | @retval NULL The variable could not be retrieved.\r |
1305 | @retval NULL There are not enough resources available for the variable contents.\r | |
1306 | @retval Other A pointer to allocated buffer containing the variable contents.\r | |
6d28c497 | 1307 | \r |
1308 | **/\r | |
1309 | VOID *\r | |
1310 | EFIAPI\r | |
1311 | GetVariable (\r | |
35db1186 | 1312 | IN CONST CHAR16 *Name,\r |
1313 | IN CONST EFI_GUID *Guid\r | |
1314 | )\r | |
6d28c497 | 1315 | {\r |
1316 | EFI_STATUS Status;\r | |
1317 | UINTN Size;\r | |
1318 | VOID *Value;\r | |
1319 | \r | |
1320 | ASSERT (Name != NULL);\r | |
1321 | ASSERT (Guid != NULL);\r | |
1322 | \r | |
1323 | //\r | |
1324 | // Try to get the variable size.\r | |
1325 | //\r | |
1326 | Value = NULL;\r | |
1327 | Size = 0;\r | |
1328 | Status = gRT->GetVariable ((CHAR16 *) Name, (EFI_GUID *) Guid, NULL, &Size, Value);\r | |
1329 | if (Status != EFI_BUFFER_TOO_SMALL) {\r | |
1330 | return NULL;\r | |
1331 | }\r | |
1332 | \r | |
1333 | //\r | |
1334 | // Allocate buffer to get the variable.\r | |
1335 | //\r | |
1336 | Value = AllocatePool (Size);\r | |
1337 | if (Value == NULL) {\r | |
1338 | return NULL;\r | |
1339 | }\r | |
1340 | \r | |
1341 | //\r | |
1342 | // Get the variable data.\r | |
1343 | //\r | |
1344 | Status = gRT->GetVariable ((CHAR16 *) Name, (EFI_GUID *) Guid, NULL, &Size, Value);\r | |
1345 | if (EFI_ERROR (Status)) {\r | |
1346 | FreePool(Value);\r | |
1347 | return NULL;\r | |
1348 | }\r | |
1349 | \r | |
1350 | return Value;\r | |
1351 | }\r | |
1352 | \r | |
6d28c497 | 1353 | /**\r |
bf4a3dbd ED |
1354 | [ATTENTION] This function will be deprecated for security reason.\r |
1355 | \r | |
9095d37b LG |
1356 | Returns a pointer to an allocated buffer that contains the contents of a\r |
1357 | variable retrieved through the UEFI Runtime Service GetVariable(). This\r | |
6d28c497 | 1358 | function always uses the EFI_GLOBAL_VARIABLE GUID to retrieve variables.\r |
9095d37b | 1359 | The returned buffer is allocated using AllocatePool(). The caller is\r |
6d28c497 | 1360 | responsible for freeing this buffer with FreePool().\r |
1361 | \r | |
1362 | If Name is NULL, then ASSERT().\r | |
1363 | \r | |
2fc59a00 | 1364 | @param[in] Name The pointer to a Null-terminated Unicode string.\r |
6d28c497 | 1365 | \r |
1366 | @retval NULL The variable could not be retrieved.\r | |
1367 | @retval NULL There are not enough resources available for the variable contents.\r | |
1368 | @retval Other A pointer to allocated buffer containing the variable contents.\r | |
1369 | \r | |
1370 | **/\r | |
1371 | VOID *\r | |
1372 | EFIAPI\r | |
1373 | GetEfiGlobalVariable (\r | |
1374 | IN CONST CHAR16 *Name\r | |
1375 | )\r | |
1376 | {\r | |
1377 | return GetVariable (Name, &gEfiGlobalVariableGuid);\r | |
1378 | }\r | |
bf4a3dbd ED |
1379 | #endif\r |
1380 | \r | |
1381 | /**\r | |
9095d37b LG |
1382 | Returns the status whether get the variable success. The function retrieves\r |
1383 | variable through the UEFI Runtime Service GetVariable(). The\r | |
bf4a3dbd ED |
1384 | returned buffer is allocated using AllocatePool(). The caller is responsible\r |
1385 | for freeing this buffer with FreePool().\r | |
1386 | \r | |
1387 | If Name is NULL, then ASSERT().\r | |
1388 | If Guid is NULL, then ASSERT().\r | |
1389 | If Value is NULL, then ASSERT().\r | |
1390 | \r | |
1391 | @param[in] Name The pointer to a Null-terminated Unicode string.\r | |
1392 | @param[in] Guid The pointer to an EFI_GUID structure\r | |
1393 | @param[out] Value The buffer point saved the variable info.\r | |
1394 | @param[out] Size The buffer size of the variable.\r | |
1395 | \r | |
1396 | @return EFI_OUT_OF_RESOURCES Allocate buffer failed.\r | |
1397 | @return EFI_SUCCESS Find the specified variable.\r | |
1398 | @return Others Errors Return errors from call to gRT->GetVariable.\r | |
1399 | \r | |
1400 | **/\r | |
1401 | EFI_STATUS\r | |
1402 | EFIAPI\r | |
1403 | GetVariable2 (\r | |
1404 | IN CONST CHAR16 *Name,\r | |
1405 | IN CONST EFI_GUID *Guid,\r | |
1406 | OUT VOID **Value,\r | |
1407 | OUT UINTN *Size OPTIONAL\r | |
1408 | )\r | |
1409 | {\r | |
1410 | EFI_STATUS Status;\r | |
1411 | UINTN BufferSize;\r | |
1412 | \r | |
1413 | ASSERT (Name != NULL && Guid != NULL && Value != NULL);\r | |
1414 | \r | |
1415 | //\r | |
1416 | // Try to get the variable size.\r | |
1417 | //\r | |
1418 | BufferSize = 0;\r | |
1419 | *Value = NULL;\r | |
1420 | if (Size != NULL) {\r | |
1421 | *Size = 0;\r | |
1422 | }\r | |
9095d37b | 1423 | \r |
bf4a3dbd ED |
1424 | Status = gRT->GetVariable ((CHAR16 *) Name, (EFI_GUID *) Guid, NULL, &BufferSize, *Value);\r |
1425 | if (Status != EFI_BUFFER_TOO_SMALL) {\r | |
1426 | return Status;\r | |
1427 | }\r | |
1428 | \r | |
1429 | //\r | |
1430 | // Allocate buffer to get the variable.\r | |
1431 | //\r | |
1432 | *Value = AllocatePool (BufferSize);\r | |
1433 | ASSERT (*Value != NULL);\r | |
1434 | if (*Value == NULL) {\r | |
1435 | return EFI_OUT_OF_RESOURCES;\r | |
1436 | }\r | |
1437 | \r | |
1438 | //\r | |
1439 | // Get the variable data.\r | |
1440 | //\r | |
1441 | Status = gRT->GetVariable ((CHAR16 *) Name, (EFI_GUID *) Guid, NULL, &BufferSize, *Value);\r | |
1442 | if (EFI_ERROR (Status)) {\r | |
1443 | FreePool(*Value);\r | |
1444 | *Value = NULL;\r | |
1445 | }\r | |
1446 | \r | |
1447 | if (Size != NULL) {\r | |
1448 | *Size = BufferSize;\r | |
1449 | }\r | |
1450 | \r | |
37bf6787 BB |
1451 | return Status;\r |
1452 | }\r | |
1453 | \r | |
1454 | /** Return the attributes of the variable.\r | |
1455 | \r | |
1456 | Returns the status whether get the variable success. The function retrieves\r | |
1457 | variable through the UEFI Runtime Service GetVariable(). The\r | |
1458 | returned buffer is allocated using AllocatePool(). The caller is responsible\r | |
1459 | for freeing this buffer with FreePool(). The attributes are returned if\r | |
1460 | the caller provides a valid Attribute parameter.\r | |
1461 | \r | |
1462 | If Name is NULL, then ASSERT().\r | |
1463 | If Guid is NULL, then ASSERT().\r | |
1464 | If Value is NULL, then ASSERT().\r | |
1465 | \r | |
1466 | @param[in] Name The pointer to a Null-terminated Unicode string.\r | |
1467 | @param[in] Guid The pointer to an EFI_GUID structure\r | |
1468 | @param[out] Value The buffer point saved the variable info.\r | |
1469 | @param[out] Size The buffer size of the variable.\r | |
1470 | @param[out] Attr The pointer to the variable attributes as found in var store\r | |
1471 | \r | |
1472 | @retval EFI_OUT_OF_RESOURCES Allocate buffer failed.\r | |
1473 | @retval EFI_SUCCESS Find the specified variable.\r | |
1474 | @retval Others Errors Return errors from call to gRT->GetVariable.\r | |
1475 | \r | |
1476 | **/\r | |
1477 | EFI_STATUS\r | |
1478 | EFIAPI\r | |
1479 | GetVariable3(\r | |
1480 | IN CONST CHAR16 *Name,\r | |
1481 | IN CONST EFI_GUID *Guid,\r | |
1482 | OUT VOID **Value,\r | |
1483 | OUT UINTN *Size OPTIONAL,\r | |
1484 | OUT UINT32 *Attr OPTIONAL\r | |
1485 | )\r | |
1486 | {\r | |
1487 | EFI_STATUS Status;\r | |
1488 | UINTN BufferSize;\r | |
1489 | \r | |
1490 | ASSERT(Name != NULL && Guid != NULL && Value != NULL);\r | |
1491 | \r | |
1492 | //\r | |
1493 | // Try to get the variable size.\r | |
1494 | //\r | |
1495 | BufferSize = 0;\r | |
1496 | *Value = NULL;\r | |
1497 | if (Size != NULL) {\r | |
1498 | *Size = 0;\r | |
1499 | }\r | |
1500 | \r | |
1501 | if (Attr != NULL) {\r | |
1502 | *Attr = 0;\r | |
1503 | }\r | |
1504 | \r | |
1505 | Status = gRT->GetVariable((CHAR16 *)Name, (EFI_GUID *)Guid, Attr, &BufferSize, *Value);\r | |
1506 | if (Status != EFI_BUFFER_TOO_SMALL) {\r | |
1507 | return Status;\r | |
1508 | }\r | |
1509 | \r | |
1510 | //\r | |
1511 | // Allocate buffer to get the variable.\r | |
1512 | //\r | |
1513 | *Value = AllocatePool(BufferSize);\r | |
1514 | ASSERT(*Value != NULL);\r | |
1515 | if (*Value == NULL) {\r | |
1516 | return EFI_OUT_OF_RESOURCES;\r | |
1517 | }\r | |
1518 | \r | |
1519 | //\r | |
1520 | // Get the variable data.\r | |
1521 | //\r | |
1522 | Status = gRT->GetVariable((CHAR16 *)Name, (EFI_GUID *)Guid, Attr, &BufferSize, *Value);\r | |
1523 | if (EFI_ERROR(Status)) {\r | |
1524 | FreePool(*Value);\r | |
1525 | *Value = NULL;\r | |
1526 | }\r | |
1527 | \r | |
1528 | if (Size != NULL) {\r | |
1529 | *Size = BufferSize;\r | |
1530 | }\r | |
1531 | \r | |
bf4a3dbd ED |
1532 | return Status;\r |
1533 | }\r | |
6d28c497 | 1534 | \r |
bf4a3dbd | 1535 | /**\r |
9095d37b LG |
1536 | Returns a pointer to an allocated buffer that contains the contents of a\r |
1537 | variable retrieved through the UEFI Runtime Service GetVariable(). This\r | |
bf4a3dbd | 1538 | function always uses the EFI_GLOBAL_VARIABLE GUID to retrieve variables.\r |
9095d37b | 1539 | The returned buffer is allocated using AllocatePool(). The caller is\r |
bf4a3dbd ED |
1540 | responsible for freeing this buffer with FreePool().\r |
1541 | \r | |
1542 | If Name is NULL, then ASSERT().\r | |
1543 | If Value is NULL, then ASSERT().\r | |
1544 | \r | |
1545 | @param[in] Name The pointer to a Null-terminated Unicode string.\r | |
1546 | @param[out] Value The buffer point saved the variable info.\r | |
1547 | @param[out] Size The buffer size of the variable.\r | |
1548 | \r | |
1549 | @return EFI_OUT_OF_RESOURCES Allocate buffer failed.\r | |
1550 | @return EFI_SUCCESS Find the specified variable.\r | |
1551 | @return Others Errors Return errors from call to gRT->GetVariable.\r | |
1552 | \r | |
1553 | **/\r | |
1554 | EFI_STATUS\r | |
1555 | EFIAPI\r | |
1556 | GetEfiGlobalVariable2 (\r | |
1557 | IN CONST CHAR16 *Name,\r | |
1558 | OUT VOID **Value,\r | |
1559 | OUT UINTN *Size OPTIONAL\r | |
1560 | )\r | |
1561 | {\r | |
1562 | return GetVariable2 (Name, &gEfiGlobalVariableGuid, Value, Size);\r | |
1563 | }\r | |
6d28c497 | 1564 | \r |
1565 | /**\r | |
9095d37b LG |
1566 | Returns a pointer to an allocated buffer that contains the best matching language\r |
1567 | from a set of supported languages.\r | |
1568 | \r | |
1569 | This function supports both ISO 639-2 and RFC 4646 language codes, but language\r | |
1570 | code types may not be mixed in a single call to this function. The language\r | |
1571 | code returned is allocated using AllocatePool(). The caller is responsible for\r | |
6d28c497 | 1572 | freeing the allocated buffer using FreePool(). This function supports a variable\r |
9095d37b LG |
1573 | argument list that allows the caller to pass in a prioritized list of language\r |
1574 | codes to test against all the language codes in SupportedLanguages.\r | |
6d28c497 | 1575 | \r |
1576 | If SupportedLanguages is NULL, then ASSERT().\r | |
1577 | \r | |
1578 | @param[in] SupportedLanguages A pointer to a Null-terminated ASCII string that\r | |
9095d37b | 1579 | contains a set of language codes in the format\r |
6d28c497 | 1580 | specified by Iso639Language.\r |
3d7c6cfb LG |
1581 | @param[in] Iso639Language If not zero, then all language codes are assumed to be\r |
1582 | in ISO 639-2 format. If zero, then all language\r | |
6d28c497 | 1583 | codes are assumed to be in RFC 4646 language format\r |
9095d37b | 1584 | @param[in] ... A variable argument list that contains pointers to\r |
6d28c497 | 1585 | Null-terminated ASCII strings that contain one or more\r |
1586 | language codes in the format specified by Iso639Language.\r | |
1587 | The first language code from each of these language\r | |
1588 | code lists is used to determine if it is an exact or\r | |
9095d37b | 1589 | close match to any of the language codes in\r |
6d28c497 | 1590 | SupportedLanguages. Close matches only apply to RFC 4646\r |
1591 | language codes, and the matching algorithm from RFC 4647\r | |
9095d37b | 1592 | is used to determine if a close match is present. If\r |
6d28c497 | 1593 | an exact or close match is found, then the matching\r |
1594 | language code from SupportedLanguages is returned. If\r | |
1595 | no matches are found, then the next variable argument\r | |
9095d37b | 1596 | parameter is evaluated. The variable argument list\r |
6d28c497 | 1597 | is terminated by a NULL.\r |
1598 | \r | |
1599 | @retval NULL The best matching language could not be found in SupportedLanguages.\r | |
9095d37b | 1600 | @retval NULL There are not enough resources available to return the best matching\r |
6d28c497 | 1601 | language.\r |
9095d37b | 1602 | @retval Other A pointer to a Null-terminated ASCII string that is the best matching\r |
6d28c497 | 1603 | language in SupportedLanguages.\r |
1604 | \r | |
1605 | **/\r | |
1606 | CHAR8 *\r | |
1607 | EFIAPI\r | |
1608 | GetBestLanguage (\r | |
9095d37b | 1609 | IN CONST CHAR8 *SupportedLanguages,\r |
d2aafe1e | 1610 | IN UINTN Iso639Language,\r |
6d28c497 | 1611 | ...\r |
1612 | )\r | |
1613 | {\r | |
1614 | VA_LIST Args;\r | |
1615 | CHAR8 *Language;\r | |
1616 | UINTN CompareLength;\r | |
1617 | UINTN LanguageLength;\r | |
1618 | CONST CHAR8 *Supported;\r | |
1619 | CHAR8 *BestLanguage;\r | |
1620 | \r | |
1621 | ASSERT (SupportedLanguages != NULL);\r | |
1622 | \r | |
1623 | VA_START (Args, Iso639Language);\r | |
1624 | while ((Language = VA_ARG (Args, CHAR8 *)) != NULL) {\r | |
1625 | //\r | |
1626 | // Default to ISO 639-2 mode\r | |
1627 | //\r | |
1628 | CompareLength = 3;\r | |
1629 | LanguageLength = MIN (3, AsciiStrLen (Language));\r | |
1630 | \r | |
1631 | //\r | |
1632 | // If in RFC 4646 mode, then determine the length of the first RFC 4646 language code in Language\r | |
1633 | //\r | |
3d7c6cfb | 1634 | if (Iso639Language == 0) {\r |
6d28c497 | 1635 | for (LanguageLength = 0; Language[LanguageLength] != 0 && Language[LanguageLength] != ';'; LanguageLength++);\r |
1636 | }\r | |
1637 | \r | |
1638 | //\r | |
1639 | // Trim back the length of Language used until it is empty\r | |
1640 | //\r | |
1641 | while (LanguageLength > 0) {\r | |
1642 | //\r | |
1643 | // Loop through all language codes in SupportedLanguages\r | |
1644 | //\r | |
1645 | for (Supported = SupportedLanguages; *Supported != '\0'; Supported += CompareLength) {\r | |
1646 | //\r | |
1647 | // In RFC 4646 mode, then Loop through all language codes in SupportedLanguages\r | |
1648 | //\r | |
3d7c6cfb | 1649 | if (Iso639Language == 0) {\r |
6d28c497 | 1650 | //\r |
1651 | // Skip ';' characters in Supported\r | |
1652 | //\r | |
1653 | for (; *Supported != '\0' && *Supported == ';'; Supported++);\r | |
1654 | //\r | |
1655 | // Determine the length of the next language code in Supported\r | |
1656 | //\r | |
1657 | for (CompareLength = 0; Supported[CompareLength] != 0 && Supported[CompareLength] != ';'; CompareLength++);\r | |
1658 | //\r | |
1659 | // If Language is longer than the Supported, then skip to the next language\r | |
1660 | //\r | |
1661 | if (LanguageLength > CompareLength) {\r | |
1662 | continue;\r | |
1663 | }\r | |
1664 | }\r | |
1665 | //\r | |
1666 | // See if the first LanguageLength characters in Supported match Language\r | |
1667 | //\r | |
1668 | if (AsciiStrnCmp (Supported, Language, LanguageLength) == 0) {\r | |
1669 | VA_END (Args);\r | |
1670 | //\r | |
1671 | // Allocate, copy, and return the best matching language code from SupportedLanguages\r | |
1672 | //\r | |
1673 | BestLanguage = AllocateZeroPool (CompareLength + 1);\r | |
1674 | if (BestLanguage == NULL) {\r | |
1675 | return NULL;\r | |
1676 | }\r | |
1677 | return CopyMem (BestLanguage, Supported, CompareLength);\r | |
1678 | }\r | |
1679 | }\r | |
1680 | \r | |
3d7c6cfb | 1681 | if (Iso639Language != 0) {\r |
6d28c497 | 1682 | //\r |
1683 | // If ISO 639 mode, then each language can only be tested once\r | |
1684 | //\r | |
1685 | LanguageLength = 0;\r | |
1686 | } else {\r | |
1687 | //\r | |
9095d37b | 1688 | // If RFC 4646 mode, then trim Language from the right to the next '-' character\r |
6d28c497 | 1689 | //\r |
1690 | for (LanguageLength--; LanguageLength > 0 && Language[LanguageLength] != '-'; LanguageLength--);\r | |
1691 | }\r | |
1692 | }\r | |
1693 | }\r | |
1694 | VA_END (Args);\r | |
1695 | \r | |
1696 | //\r | |
9095d37b | 1697 | // No matches were found\r |
6d28c497 | 1698 | //\r |
1699 | return NULL;\r | |
1700 | }\r | |
40070a18 MK |
1701 | \r |
1702 | /**\r | |
1703 | Returns an array of protocol instance that matches the given protocol.\r | |
1704 | \r | |
1705 | @param[in] Protocol Provides the protocol to search for.\r | |
1706 | @param[out] NoProtocols The number of protocols returned in Buffer.\r | |
1707 | @param[out] Buffer A pointer to the buffer to return the requested\r | |
1708 | array of protocol instances that match Protocol.\r | |
1709 | The returned buffer is allocated using\r | |
1710 | EFI_BOOT_SERVICES.AllocatePool(). The caller is\r | |
1711 | responsible for freeing this buffer with\r | |
1712 | EFI_BOOT_SERVICES.FreePool().\r | |
1713 | \r | |
1714 | @retval EFI_SUCCESS The array of protocols was returned in Buffer,\r | |
1715 | and the number of protocols in Buffer was\r | |
1716 | returned in NoProtocols.\r | |
1717 | @retval EFI_NOT_FOUND No protocols found.\r | |
1718 | @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the\r | |
1719 | matching results.\r | |
1720 | @retval EFI_INVALID_PARAMETER Protocol is NULL.\r | |
1721 | @retval EFI_INVALID_PARAMETER NoProtocols is NULL.\r | |
1722 | @retval EFI_INVALID_PARAMETER Buffer is NULL.\r | |
1723 | \r | |
1724 | **/\r | |
1725 | EFI_STATUS\r | |
1726 | EFIAPI\r | |
1727 | EfiLocateProtocolBuffer (\r | |
1728 | IN EFI_GUID *Protocol,\r | |
1729 | OUT UINTN *NoProtocols,\r | |
1730 | OUT VOID ***Buffer\r | |
1731 | )\r | |
1732 | {\r | |
1733 | EFI_STATUS Status;\r | |
1734 | UINTN NoHandles;\r | |
1735 | EFI_HANDLE *HandleBuffer;\r | |
1736 | UINTN Index;\r | |
1737 | \r | |
1738 | //\r | |
1739 | // Check input parameters\r | |
1740 | //\r | |
1741 | if (Protocol == NULL || NoProtocols == NULL || Buffer == NULL) {\r | |
1742 | return EFI_INVALID_PARAMETER;\r | |
1743 | }\r | |
1744 | \r | |
1745 | //\r | |
1746 | // Initialze output parameters\r | |
1747 | //\r | |
1748 | *NoProtocols = 0;\r | |
1749 | *Buffer = NULL;\r | |
1750 | \r | |
1751 | //\r | |
1752 | // Retrieve the array of handles that support Protocol\r | |
1753 | //\r | |
1754 | Status = gBS->LocateHandleBuffer (\r | |
1755 | ByProtocol,\r | |
1756 | Protocol,\r | |
1757 | NULL,\r | |
1758 | &NoHandles,\r | |
1759 | &HandleBuffer\r | |
1760 | );\r | |
1761 | if (EFI_ERROR (Status)) {\r | |
1762 | return Status;\r | |
1763 | }\r | |
1764 | \r | |
1765 | //\r | |
1766 | // Allocate array of protocol instances\r | |
1767 | //\r | |
1768 | Status = gBS->AllocatePool (\r | |
1769 | EfiBootServicesData,\r | |
1770 | NoHandles * sizeof (VOID *),\r | |
1771 | (VOID **)Buffer\r | |
1772 | );\r | |
1773 | if (EFI_ERROR (Status)) {\r | |
fe507283 SZ |
1774 | //\r |
1775 | // Free the handle buffer\r | |
1776 | //\r | |
1777 | gBS->FreePool (HandleBuffer);\r | |
40070a18 MK |
1778 | return EFI_OUT_OF_RESOURCES;\r |
1779 | }\r | |
1780 | ZeroMem (*Buffer, NoHandles * sizeof (VOID *));\r | |
1781 | \r | |
1782 | //\r | |
1783 | // Lookup Protocol on each handle in HandleBuffer to fill in the array of\r | |
1784 | // protocol instances. Handle case where protocol instance was present when\r | |
1785 | // LocateHandleBuffer() was called, but is not present when HandleProtocol()\r | |
1786 | // is called.\r | |
1787 | //\r | |
1788 | for (Index = 0, *NoProtocols = 0; Index < NoHandles; Index++) {\r | |
1789 | Status = gBS->HandleProtocol (\r | |
1790 | HandleBuffer[Index],\r | |
1791 | Protocol,\r | |
1792 | &((*Buffer)[*NoProtocols])\r | |
1793 | );\r | |
1794 | if (!EFI_ERROR (Status)) {\r | |
1795 | (*NoProtocols)++;\r | |
1796 | }\r | |
1797 | }\r | |
1798 | \r | |
1799 | //\r | |
1800 | // Free the handle buffer\r | |
1801 | //\r | |
1802 | gBS->FreePool (HandleBuffer);\r | |
1803 | \r | |
1804 | //\r | |
1805 | // Make sure at least one protocol instance was found\r | |
1806 | //\r | |
1807 | if (*NoProtocols == 0) {\r | |
1808 | gBS->FreePool (*Buffer);\r | |
1809 | *Buffer = NULL;\r | |
1810 | return EFI_NOT_FOUND;\r | |
1811 | }\r | |
1812 | \r | |
1813 | return EFI_SUCCESS;\r | |
1814 | }\r | |
768b6111 LE |
1815 | \r |
1816 | /**\r | |
1817 | Open or create a file or directory, possibly creating the chain of\r | |
1818 | directories leading up to the directory.\r | |
1819 | \r | |
1820 | EfiOpenFileByDevicePath() first locates EFI_SIMPLE_FILE_SYSTEM_PROTOCOL on\r | |
1821 | FilePath, and opens the root directory of that filesystem with\r | |
1822 | EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume().\r | |
1823 | \r | |
1824 | On the remaining device path, the longest initial sequence of\r | |
1825 | FILEPATH_DEVICE_PATH nodes is node-wise traversed with\r | |
5dbc768f | 1826 | EFI_FILE_PROTOCOL.Open().\r |
768b6111 LE |
1827 | \r |
1828 | (As a consequence, if OpenMode includes EFI_FILE_MODE_CREATE, and Attributes\r | |
1829 | includes EFI_FILE_DIRECTORY, and each FILEPATH_DEVICE_PATH specifies a single\r | |
1830 | pathname component, then EfiOpenFileByDevicePath() ensures that the specified\r | |
1831 | series of subdirectories exist on return.)\r | |
1832 | \r | |
1833 | The EFI_FILE_PROTOCOL identified by the last FILEPATH_DEVICE_PATH node is\r | |
1834 | output to the caller; intermediate EFI_FILE_PROTOCOL instances are closed. If\r | |
1835 | there are no FILEPATH_DEVICE_PATH nodes past the node that identifies the\r | |
1836 | filesystem, then the EFI_FILE_PROTOCOL of the root directory of the\r | |
1837 | filesystem is output to the caller. If a device path node that is different\r | |
1838 | from FILEPATH_DEVICE_PATH is encountered relative to the filesystem, the\r | |
1839 | traversal is stopped with an error, and a NULL EFI_FILE_PROTOCOL is output.\r | |
1840 | \r | |
1841 | @param[in,out] FilePath On input, the device path to the file or directory\r | |
1842 | to open or create. The caller is responsible for\r | |
1843 | ensuring that the device path pointed-to by FilePath\r | |
1844 | is well-formed. On output, FilePath points one past\r | |
1845 | the last node in the original device path that has\r | |
1846 | been successfully processed. FilePath is set on\r | |
1847 | output even if EfiOpenFileByDevicePath() returns an\r | |
1848 | error.\r | |
1849 | \r | |
1850 | @param[out] File On error, File is set to NULL. On success, File is\r | |
1851 | set to the EFI_FILE_PROTOCOL of the root directory\r | |
1852 | of the filesystem, if there are no\r | |
1853 | FILEPATH_DEVICE_PATH nodes in FilePath; otherwise,\r | |
1854 | File is set to the EFI_FILE_PROTOCOL identified by\r | |
1855 | the last node in FilePath.\r | |
1856 | \r | |
1857 | @param[in] OpenMode The OpenMode parameter to pass to\r | |
5dbc768f | 1858 | EFI_FILE_PROTOCOL.Open().\r |
768b6111 LE |
1859 | \r |
1860 | @param[in] Attributes The Attributes parameter to pass to\r | |
5dbc768f | 1861 | EFI_FILE_PROTOCOL.Open().\r |
768b6111 LE |
1862 | \r |
1863 | @retval EFI_SUCCESS The file or directory has been opened or\r | |
1864 | created.\r | |
1865 | \r | |
1866 | @retval EFI_INVALID_PARAMETER FilePath is NULL; or File is NULL; or FilePath\r | |
1867 | contains a device path node, past the node\r | |
1868 | that identifies\r | |
1869 | EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, that is not a\r | |
1870 | FILEPATH_DEVICE_PATH node.\r | |
1871 | \r | |
1872 | @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r | |
1873 | \r | |
1874 | @return Error codes propagated from the\r | |
1875 | LocateDevicePath() and OpenProtocol() boot\r | |
1876 | services, and from the\r | |
1877 | EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume()\r | |
1878 | and EFI_FILE_PROTOCOL.Open() member functions.\r | |
1879 | **/\r | |
1880 | EFI_STATUS\r | |
1881 | EFIAPI\r | |
1882 | EfiOpenFileByDevicePath (\r | |
1883 | IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,\r | |
1884 | OUT EFI_FILE_PROTOCOL **File,\r | |
1885 | IN UINT64 OpenMode,\r | |
1886 | IN UINT64 Attributes\r | |
1887 | )\r | |
1888 | {\r | |
1889 | EFI_STATUS Status;\r | |
1890 | EFI_HANDLE FileSystemHandle;\r | |
1891 | EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem;\r | |
1892 | EFI_FILE_PROTOCOL *LastFile;\r | |
1893 | FILEPATH_DEVICE_PATH *FilePathNode;\r | |
1894 | CHAR16 *AlignedPathName;\r | |
1895 | CHAR16 *PathName;\r | |
1896 | EFI_FILE_PROTOCOL *NextFile;\r | |
1897 | \r | |
1898 | if (File == NULL) {\r | |
1899 | return EFI_INVALID_PARAMETER;\r | |
1900 | }\r | |
1901 | *File = NULL;\r | |
1902 | \r | |
1903 | if (FilePath == NULL) {\r | |
1904 | return EFI_INVALID_PARAMETER;\r | |
1905 | }\r | |
1906 | \r | |
1907 | //\r | |
1908 | // Look up the filesystem.\r | |
1909 | //\r | |
1910 | Status = gBS->LocateDevicePath (\r | |
1911 | &gEfiSimpleFileSystemProtocolGuid,\r | |
1912 | FilePath,\r | |
1913 | &FileSystemHandle\r | |
1914 | );\r | |
1915 | if (EFI_ERROR (Status)) {\r | |
1916 | return Status;\r | |
1917 | }\r | |
1918 | Status = gBS->OpenProtocol (\r | |
1919 | FileSystemHandle,\r | |
1920 | &gEfiSimpleFileSystemProtocolGuid,\r | |
1921 | (VOID **)&FileSystem,\r | |
1922 | gImageHandle,\r | |
1923 | NULL,\r | |
1924 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
1925 | );\r | |
1926 | if (EFI_ERROR (Status)) {\r | |
1927 | return Status;\r | |
1928 | }\r | |
1929 | \r | |
1930 | //\r | |
1931 | // Open the root directory of the filesystem. After this operation succeeds,\r | |
1932 | // we have to release LastFile on error.\r | |
1933 | //\r | |
1934 | Status = FileSystem->OpenVolume (FileSystem, &LastFile);\r | |
1935 | if (EFI_ERROR (Status)) {\r | |
1936 | return Status;\r | |
1937 | }\r | |
1938 | \r | |
1939 | //\r | |
1940 | // Traverse the device path nodes relative to the filesystem.\r | |
1941 | //\r | |
1942 | while (!IsDevicePathEnd (*FilePath)) {\r | |
1943 | if (DevicePathType (*FilePath) != MEDIA_DEVICE_PATH ||\r | |
1944 | DevicePathSubType (*FilePath) != MEDIA_FILEPATH_DP) {\r | |
1945 | Status = EFI_INVALID_PARAMETER;\r | |
1946 | goto CloseLastFile;\r | |
1947 | }\r | |
1948 | FilePathNode = (FILEPATH_DEVICE_PATH *)*FilePath;\r | |
1949 | \r | |
1950 | //\r | |
1951 | // FilePathNode->PathName may be unaligned, and the UEFI specification\r | |
1952 | // requires pointers that are passed to protocol member functions to be\r | |
1953 | // aligned. Create an aligned copy of the pathname if necessary.\r | |
1954 | //\r | |
1955 | if ((UINTN)FilePathNode->PathName % sizeof *FilePathNode->PathName == 0) {\r | |
1956 | AlignedPathName = NULL;\r | |
1957 | PathName = FilePathNode->PathName;\r | |
1958 | } else {\r | |
1959 | AlignedPathName = AllocateCopyPool (\r | |
1960 | (DevicePathNodeLength (FilePathNode) -\r | |
1961 | SIZE_OF_FILEPATH_DEVICE_PATH),\r | |
1962 | FilePathNode->PathName\r | |
1963 | );\r | |
1964 | if (AlignedPathName == NULL) {\r | |
1965 | Status = EFI_OUT_OF_RESOURCES;\r | |
1966 | goto CloseLastFile;\r | |
1967 | }\r | |
1968 | PathName = AlignedPathName;\r | |
1969 | }\r | |
1970 | \r | |
1971 | //\r | |
5dbc768f | 1972 | // Open or create the file corresponding to the next pathname fragment.\r |
768b6111 LE |
1973 | //\r |
1974 | Status = LastFile->Open (\r | |
1975 | LastFile,\r | |
1976 | &NextFile,\r | |
1977 | PathName,\r | |
5dbc768f LE |
1978 | OpenMode,\r |
1979 | Attributes\r | |
768b6111 LE |
1980 | );\r |
1981 | \r | |
768b6111 LE |
1982 | //\r |
1983 | // Release any AlignedPathName on both error and success paths; PathName is\r | |
1984 | // no longer needed.\r | |
1985 | //\r | |
1986 | if (AlignedPathName != NULL) {\r | |
1987 | FreePool (AlignedPathName);\r | |
1988 | }\r | |
1989 | if (EFI_ERROR (Status)) {\r | |
1990 | goto CloseLastFile;\r | |
1991 | }\r | |
1992 | \r | |
1993 | //\r | |
1994 | // Advance to the next device path node.\r | |
1995 | //\r | |
1996 | LastFile->Close (LastFile);\r | |
1997 | LastFile = NextFile;\r | |
1998 | *FilePath = NextDevicePathNode (FilePathNode);\r | |
1999 | }\r | |
2000 | \r | |
2001 | *File = LastFile;\r | |
2002 | return EFI_SUCCESS;\r | |
2003 | \r | |
2004 | CloseLastFile:\r | |
2005 | LastFile->Close (LastFile);\r | |
2006 | \r | |
2007 | //\r | |
2008 | // We are on the error path; we must have set an error Status for returning\r | |
2009 | // to the caller.\r | |
2010 | //\r | |
2011 | ASSERT (EFI_ERROR (Status));\r | |
2012 | return Status;\r | |
2013 | }\r |