2 MDE UEFI library functions and macros
4 Copyright (c) 2006 - 2007, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #ifndef __UEFI_LIB_H__
16 #define __UEFI_LIB_H__
19 // Unicode String Table
23 CHAR16
*UnicodeString
;
24 } EFI_UNICODE_STRING_TABLE
;
30 EfiLockUninitialized
= 0,
46 This function searches the list of configuration tables stored in the EFI System
47 Table for a table with a GUID that matches TableGuid. If a match is found,
48 then a pointer to the configuration table is returned in Table, and EFI_SUCCESS
49 is returned. If a matching GUID is not found, then EFI_NOT_FOUND is returned.
51 @param TableGuid Pointer to table's GUID type..
52 @param Table Pointer to the table associated with TableGuid in the EFI System Table.
54 @retval EFI_SUCCESS A configuration table matching TableGuid was found.
55 @retval EFI_NOT_FOUND A configuration table matching TableGuid could not be found.
60 EfiGetSystemConfigurationTable (
61 IN EFI_GUID
*TableGuid
,
66 This function causes the notification function to be executed for every protocol
67 of type ProtocolGuid instance that exists in the system when this function is
68 invoked. In addition, every time a protocol of type ProtocolGuid instance is
69 installed or reinstalled, the notification function is also executed.
71 @param ProtocolGuid Supplies GUID of the protocol upon whose installation the event is fired.
72 @param NotifyTpl Supplies the task priority level of the event notifications.
73 @param NotifyFunction Supplies the function to notify when the event is signaled.
74 @param NotifyContext The context parameter to pass to NotifyFunction.
75 @param Registration A pointer to a memory location to receive the registration value.
77 @return The notification event that was created.
82 EfiCreateProtocolNotifyEvent(
83 IN EFI_GUID
*ProtocolGuid
,
85 IN EFI_EVENT_NOTIFY NotifyFunction
,
86 IN VOID
*NotifyContext
, OPTIONAL
87 OUT VOID
**Registration
91 This function creates an event using NotifyTpl, NoifyFunction, and NotifyContext.
92 This event is signaled with EfiNamedEventSignal(). This provide the ability for
93 one or more listeners on the same event named by the GUID specified by Name.
95 @param Name Supplies GUID name of the event.
96 @param NotifyTpl Supplies the task priority level of the event notifications.
97 @param NotifyFunction Supplies the function to notify when the event is signaled.
98 @param NotifyContext The context parameter to pass to NotifyFunction.
99 @param Registration A pointer to a memory location to receive the registration value.
101 @retval EFI_SUCCESS A named event was created.
102 @retval EFI_OUT_OF_RESOURCES There are not enough resource to create the named event.
107 EfiNamedEventListen (
108 IN CONST EFI_GUID
*Name
,
109 IN EFI_TPL NotifyTpl
,
110 IN EFI_EVENT_NOTIFY NotifyFunction
,
111 IN CONST VOID
*NotifyContext
, OPTIONAL
112 OUT VOID
*Registration OPTIONAL
116 This function signals the named event specified by Name. The named event must
117 have been created with EfiNamedEventListen().
119 @param Name Supplies GUID name of the event.
121 @retval EFI_SUCCESS A named event was signaled.
122 @retval EFI_OUT_OF_RESOURCES There are not enough resource to signal the named event.
127 EfiNamedEventSignal (
128 IN CONST EFI_GUID
*Name
132 This function initializes a basic mutual exclusion lock to the released state
133 and returns the lock. Each lock provides mutual exclusion access at its task
134 priority level. Since there is no preemption or multiprocessor support in EFI,
135 acquiring the lock only consists of raising to the locks TPL.
137 @param Lock A pointer to the lock data structure to initialize.
138 @param Priority EFI TPL associated with the lock.
146 IN OUT EFI_LOCK
*Lock
,
151 This macro initializes the contents of a basic mutual exclusion lock to the
152 released state. Each lock provides mutual exclusion access at its task
153 priority level. Since there is no preemption or multiprocessor support in EFI,
154 acquiring the lock only consists of raising to the locks TPL.
156 @param Lock A pointer to the lock data structure to initialize.
157 @param Priority The task priority level of the lock.
162 #define EFI_INITIALIZE_LOCK_VARIABLE(Priority) \
163 {Priority, EFI_TPL_APPLICATION, EfiLockReleased }
168 Macro that calls DebugAssert() if an EFI_LOCK structure is not in the locked state.
170 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set,
171 then this macro evaluates the EFI_LOCK structure specified by Lock. If Lock
172 is not in the locked state, then DebugAssert() is called passing in the source
173 filename, source line number, and Lock.
175 If Lock is NULL, then ASSERT().
177 @param LockParameter A pointer to the lock to acquire.
180 #define ASSERT_LOCKED(LockParameter) \
182 if (DebugAssertEnabled ()) { \
183 ASSERT (LockParameter != NULL); \
184 if ((LockParameter)->Lock != EfiLockAcquired) { \
185 _ASSERT (LockParameter not locked); \
192 This function raises the system's current task priority level to the task
193 priority level of the mutual exclusion lock. Then, it places the lock in the
196 @param Priority The task priority level of the lock.
206 This function raises the system's current task priority level to the task
207 priority level of the mutual exclusion lock. Then, it attempts to place the
208 lock in the acquired state.
210 @param Lock A pointer to the lock to acquire.
212 @retval EFI_SUCCESS The lock was acquired.
213 @retval EFI_ACCESS_DENIED The lock could not be acquired because it is already owned.
218 EfiAcquireLockOrFail (
223 This function transitions a mutual exclusion lock from the acquired state to
224 the released state, and restores the system's task priority level to its
227 @param Lock A pointer to the lock to release.
237 Tests whether a controller is managed by a specific driver.
239 This function tests whether a specific driver manages ControllerHandle by
240 opening on DriverBindingHandle a protocol specified by ProtocolGuid with
241 attribute EFI_OPEN_PROTOCOL_BY_DRIVER. This library function is used to
242 implement the Component Name Protocol for EFI Drivers.
243 If ProtocolGuid is NULL, then ASSERT().
245 @param ControllerHandle A handle for a controller to test.
246 @param DriverBindingHandle Specifies the driver binding handle for the
248 @param ProtocolGuid Supplies GUID for the protocol opened by the
249 driver on the controller.
251 @retval EFI_SUCCESS ControllerHandle is managed by the specific
253 @retval EFI_UNSUPPORTED ControllerHandle is not managed by the specific
259 EfiTestManagedDevice (
260 IN CONST EFI_HANDLE ControllerHandle
,
261 IN CONST EFI_HANDLE DriverBindingHandle
,
262 IN CONST EFI_GUID
*ProtocolGuid
266 Tests whether a child handle is a children device of the controller.
268 This function tests whether ChildHandle is one of the children of
269 ControllerHandle which are consuming a protocol specified by ProtocolGuid
270 with the attribute bit EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER set. This
271 library function is used to implement the Component Name Protocol for EFI
273 If ProtocolGuid is NULL, then ASSERT().
275 @param ControllerHandle A handle for a (parent) controller to test.
276 @param ChildHandle A child handle to test.
277 @param ConsumsedGuid Supplies GUID for the protocol consumed by
278 children from controller.
280 @retval EFI_SUCCESS ChildHandle is a child of the ControllerHandle.
281 @retval EFI_UNSUPPORTED ChildHandle is not a child of the
288 IN CONST EFI_HANDLE ControllerHandle
,
289 IN CONST EFI_HANDLE ChildHandle
,
290 IN CONST EFI_GUID
*ProtocolGuid
294 This function looks up a Unicode string in UnicodeStringTable. If Language is
295 a member of SupportedLanguages and a Unicode string is found in UnicodeStringTable
296 that matches the language code specified by Language, then it is returned in
299 @param Language A pointer to the ISO 639-2 language code for the
300 Unicode string to look up and return.
301 @param SupportedLanguages A pointer to the set of ISO 639-2 language codes
302 that the Unicode string table supports. Language
303 must be a member of this set.
304 @param UnicodeStringTable A pointer to the table of Unicode strings.
305 @param UnicodeString A pointer to the Unicode string from UnicodeStringTable
306 that matches the language specified by Language.
308 @retval EFI_SUCCESS The Unicode string that matches the language
309 specified by Language was found
310 in the table of Unicoide strings UnicodeStringTable,
311 and it was returned in UnicodeString.
312 @retval EFI_INVALID_PARAMETER Language is NULL.
313 @retval EFI_INVALID_PARAMETER UnicodeString is NULL.
314 @retval EFI_UNSUPPORTED SupportedLanguages is NULL.
315 @retval EFI_UNSUPPORTED UnicodeStringTable is NULL.
316 @retval EFI_UNSUPPORTED The language specified by Language is not a
317 member of SupportedLanguages.
318 @retval EFI_UNSUPPORTED The language specified by Language is not
319 supported by UnicodeStringTable.
324 LookupUnicodeString (
325 IN CONST CHAR8
*Language
,
326 IN CONST CHAR8
*SupportedLanguages
,
327 IN CONST EFI_UNICODE_STRING_TABLE
*UnicodeStringTable
,
328 OUT CHAR16
**UnicodeString
332 This function adds a Unicode string to UnicodeStringTable.
333 If Language is a member of SupportedLanguages then UnicodeString is added to
334 UnicodeStringTable. New buffers are allocated for both Language and
335 UnicodeString. The contents of Language and UnicodeString are copied into
336 these new buffers. These buffers are automatically freed when
337 FreeUnicodeStringTable() is called.
339 @param Language A pointer to the ISO 639-2 language code for the Unicode
341 @param SupportedLanguages A pointer to the set of ISO 639-2 language codes
342 that the Unicode string table supports.
343 Language must be a member of this set.
344 @param UnicodeStringTable A pointer to the table of Unicode strings.
345 @param UnicodeString A pointer to the Unicode string to add.
347 @retval EFI_SUCCESS The Unicode string that matches the language
348 specified by Language was found in the table of
349 Unicode strings UnicodeStringTable, and it was
350 returned in UnicodeString.
351 @retval EFI_INVALID_PARAMETER Language is NULL.
352 @retval EFI_INVALID_PARAMETER UnicodeString is NULL.
353 @retval EFI_INVALID_PARAMETER UnicodeString is an empty string.
354 @retval EFI_UNSUPPORTED SupportedLanguages is NULL.
355 @retval EFI_ALREADY_STARTED A Unicode string with language Language is
356 already present in UnicodeStringTable.
357 @retval EFI_OUT_OF_RESOURCES There is not enough memory to add another
358 Unicode string to UnicodeStringTable.
359 @retval EFI_UNSUPPORTED The language specified by Language is not a
360 member of SupportedLanguages.
366 IN CONST CHAR8
*Language
,
367 IN CONST CHAR8
*SupportedLanguages
,
368 IN EFI_UNICODE_STRING_TABLE
**UnicodeStringTable
,
369 IN CONST CHAR16
*UnicodeString
373 This function frees the table of Unicode strings in UnicodeStringTable.
374 If UnicodeStringTable is NULL, then EFI_SUCCESS is returned.
375 Otherwise, each language code, and each Unicode string in the Unicode string
376 table are freed, and EFI_SUCCESS is returned.
378 @param UnicodeStringTable A pointer to the table of Unicode strings.
380 @retval EFI_SUCCESS The Unicode string table was freed.
385 FreeUnicodeStringTable (
386 IN EFI_UNICODE_STRING_TABLE
*UnicodeStringTable
390 This function computes and returns the width of the Unicode character
391 specified by UnicodeChar.
393 @param UnicodeChar A Unicode character.
395 @retval 0 The width if UnicodeChar could not be determined.
396 @retval 1 UnicodeChar is a narrow glyph.
397 @retval 2 UnicodeChar is a wide glyph.
403 IN CHAR16 UnicodeChar
407 This function computes and returns the display length of
408 the Null-terminated Unicode string specified by String.
409 If String is NULL, then 0 is returned.
410 If any of the widths of the Unicode characters in String
411 can not be determined, then 0 is returned.
413 @param String A pointer to a Null-terminated Unicode string.
415 @return The display length of the Null-terminated Unicode string specified by String.
420 UnicodeStringDisplayLength (
421 IN CONST CHAR16
*String
425 // Functions that abstract early Framework contamination of UEFI.
428 Signal a Ready to Boot Event.
430 Create a Ready to Boot Event. Signal it and close it. This causes other
431 events of the same event group to be signaled in other modules.
436 EfiSignalEventReadyToBoot (
441 Signal a Legacy Boot Event.
443 Create a legacy Boot Event. Signal it and close it. This causes other
444 events of the same event group to be signaled in other modules.
449 EfiSignalEventLegacyBoot (
454 Create a Legacy Boot Event.
456 Tiano extended the CreateEvent Type enum to add a legacy boot event type.
457 This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was
458 added and now it's possible to not voilate the UEFI specification by
459 declaring a GUID for the legacy boot event class. This library supports
460 the EDK/EFI 1.10 form and EDK II/UEFI 2.0 form and allows common code to
463 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
465 @retval EFI_SUCCESS Event was created.
466 @retval Other Event was not created.
471 EfiCreateEventLegacyBoot (
472 OUT EFI_EVENT
*LegacyBootEvent
476 Create an EFI event in the Legacy Boot Event Group and allows
477 the caller to specify a notification function.
479 This function abstracts the creation of the Legacy Boot Event.
480 The Framework moved from a proprietary to UEFI 2.0 based mechanism.
481 This library abstracts the caller from how this event is created to prevent
482 to code form having to change with the version of the specification supported.
483 If LegacyBootEvent is NULL, then ASSERT().
485 @param NotifyTpl The task priority level of the event.
486 @param NotifyFunction The notification function to call when the event is signaled.
487 @param NotifyContext The content to pass to NotifyFunction when the event is signaled.
488 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
490 @retval EFI_SUCCESS Event was created.
491 @retval Other Event was not created.
496 EfiCreateEventLegacyBootEx (
497 IN EFI_TPL NotifyTpl
,
498 IN EFI_EVENT_NOTIFY NotifyFunction
, OPTIONAL
499 IN VOID
*NotifyContext
, OPTIONAL
500 OUT EFI_EVENT
*LegacyBootEvent
504 Create a Read to Boot Event.
506 Tiano extended the CreateEvent Type enum to add a ready to boot event type.
507 This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was
508 added and now it's possible to not voilate the UEFI specification and use
509 the ready to boot event class defined in UEFI 2.0. This library supports
510 the EDK/EFI 1.10 form and EDKII/UEFI 2.0 form and allows common code to
513 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
515 @retval EFI_SUCCESS Event was created.
516 @retval Other Event was not created.
521 EfiCreateEventReadyToBoot (
522 OUT EFI_EVENT
*ReadyToBootEvent
526 Create an EFI event in the Ready To Boot Event Group and allows
527 the caller to specify a notification function.
529 This function abstracts the creation of the Ready to Boot Event.
530 The Framework moved from a proprietary to UEFI 2.0 based mechanism.
531 This library abstracts the caller from how this event is created to prevent
532 to code form having to change with the version of the specification supported.
533 If ReadyToBootEvent is NULL, then ASSERT().
535 @param NotifyTpl The task priority level of the event.
536 @param NotifyFunction The notification function to call when the event is signaled.
537 @param NotifyContext The content to pass to NotifyFunction when the event is signaled.
538 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
540 @retval EFI_SUCCESS Event was created.
541 @retval Other Event was not created.
546 EfiCreateEventReadyToBootEx (
547 IN EFI_TPL NotifyTpl
,
548 IN EFI_EVENT_NOTIFY NotifyFunction
, OPTIONAL
549 IN VOID
*NotifyContext
, OPTIONAL
550 OUT EFI_EVENT
*ReadyToBootEvent
554 Initialize a Firmware Volume (FV) Media Device Path node.
556 Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum
557 so as we move to UEFI 2.0 support we must use a mechanism that conforms with
558 the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed
559 device path is defined for Tiano extensions of device path. If the code
560 is compiled to conform with the UEFI 2.0 specification use the new device path
561 else use the old form for backwards compatability.
563 @param FvDevicePathNode Pointer to a FV device path node to initialize
564 @param NameGuid FV file name to use in FvDevicePathNode
569 EfiInitializeFwVolDevicepathNode (
570 IN OUT MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvDevicePathNode
,
571 IN CONST EFI_GUID
*NameGuid
575 Check to see if the Firmware Volume (FV) Media Device Path is valid
577 Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum
578 so as we move to UEFI 2.0 support we must use a mechanism that conforms with
579 the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed
580 device path is defined for Tiano extensions of device path. If the code
581 is compiled to conform with the UEFI 2.0 specification use the new device path
582 else use the old form for backwards compatability. The return value to this
583 function points to a location in FvDevicePathNode and it does not allocate
584 new memory for the GUID pointer that is returned.
586 @param FvDevicePathNode Pointer to FV device path to check.
588 @retval NULL FvDevicePathNode is not valid.
589 @retval Other FvDevicePathNode is valid and pointer to NameGuid was returned.
594 EfiGetNameGuidFromFwVolDevicePathNode (
595 IN CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvDevicePathNode