X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdePkg%2FInclude%2FLibrary%2FUefiLib.h;h=7a8af6036dda95ef9f2bcd1cc6294fb68485e364;hb=def220c4e59ce824525248bebc415475156271b7;hp=9eaf48cace7ed9403aeeefacea43c7e4dca9b4b1;hpb=fb3df220f89e6eecaf1862b9241d8a1214eeda1c;p=mirror_edk2.git diff --git a/MdePkg/Include/Library/UefiLib.h b/MdePkg/Include/Library/UefiLib.h index 9eaf48cace..7a8af6036d 100644 --- a/MdePkg/Include/Library/UefiLib.h +++ b/MdePkg/Include/Library/UefiLib.h @@ -1,5 +1,9 @@ /** @file - MDE UEFI library functions and macros + The UEFI Library provides functions and macros that simplify the development of + UEFI Drivers and UEFI Applications. These functions and macros help manage EFI + events, build simple locks utilizing EFI Task Priority Levels (TPLs), install + EFI Driver Model related protocols, manage Unicode string tables for UEFI Drivers, + and print messages on the console output and standard error devices. Copyright (c) 2006 - 2007, Intel Corporation All rights reserved. This program and the accompanying materials @@ -15,26 +19,33 @@ #ifndef __UEFI_LIB_H__ #define __UEFI_LIB_H__ -// -// Unicode String Table -// +#include +#include +#include +#include +#include +#include + +/// +/// Unicode String Table +/// typedef struct { CHAR8 *Language; CHAR16 *UnicodeString; } EFI_UNICODE_STRING_TABLE; -// -// EFI Lock Status -// +/// +/// EFI Lock Status +/// typedef enum { EfiLockUninitialized = 0, EfiLockReleased = 1, EfiLockAcquired = 2 } EFI_LOCK_STATE; -// -// EFI Lock -// +/// +/// EFI Lock +/// typedef struct { EFI_TPL Tpl; EFI_TPL OwnerTpl; @@ -137,9 +148,7 @@ EfiNamedEventSignal ( can then immediately be restored back to the current TPL level with a call to RestoreTPL(). - @param VOID - - @retvale EFI_TPL The current TPL. + @return The current TPL. **/ EFI_TPL @@ -173,14 +182,13 @@ EfiInitializeLock ( priority level. Since there is no preemption or multiprocessor support in EFI, acquiring the lock only consists of raising to the locks TPL. - @param Lock A pointer to the lock data structure to initialize. @param Priority The task priority level of the lock. @return The lock. **/ #define EFI_INITIALIZE_LOCK_VARIABLE(Priority) \ - {Priority, EFI_TPL_APPLICATION, EfiLockReleased } + {Priority, TPL_APPLICATION, EfiLockReleased } /** @@ -213,7 +221,7 @@ EfiInitializeLock ( priority level of the mutual exclusion lock. Then, it places the lock in the acquired state. - @param Priority The task priority level of the lock. + @param Lock A pointer to the lock to acquire. **/ VOID @@ -253,28 +261,28 @@ EfiReleaseLock ( IN EFI_LOCK *Lock ); -/** - Tests whether a controller handle is being managed by a specific driver. - +/** + Tests whether a controller handle is being managed by a specific driver. + This function tests whether the driver specified by DriverBindingHandle is currently managing the controller specified by ControllerHandle. This test is performed by evaluating if the the protocol specified by ProtocolGuid is present on ControllerHandle and is was opened by DriverBindingHandle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER. If ProtocolGuid is NULL, then ASSERT(). - - @param ControllerHandle A handle for a controller to test. - @param DriverBindingHandle Specifies the driver binding handle for the - driver. - @param ProtocolGuid Specifies the protocol that the driver specified - by DriverBindingHandle opens in its Start() - function. - - @retval EFI_SUCCESS ControllerHandle is managed by the driver - specifed by DriverBindingHandle. - @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driver - specifed by DriverBindingHandle. - + + @param ControllerHandle A handle for a controller to test. + @param DriverBindingHandle Specifies the driver binding handle for the + driver. + @param ProtocolGuid Specifies the protocol that the driver specified + by DriverBindingHandle opens in its Start() + function. + + @retval EFI_SUCCESS ControllerHandle is managed by the driver + specifed by DriverBindingHandle. + @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driver + specifed by DriverBindingHandle. + **/ EFI_STATUS EFIAPI @@ -284,24 +292,24 @@ EfiTestManagedDevice ( IN CONST EFI_GUID *ProtocolGuid ); -/** - Tests whether a child handle is a child device of the controller. - +/** + Tests whether a child handle is a child device of the controller. + This function tests whether ChildHandle is one of the children of ControllerHandle. This test is performed by checking to see if the protocol specified by ProtocolGuid is present on ControllerHandle and opened by ChildHandle with an attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER. If ProtocolGuid is NULL, then ASSERT(). - - @param ControllerHandle A handle for a (parent) controller to test. - @param ChildHandle A child handle to test. - @param ConsumsedGuid Supplies the protocol that the child controller - opens on its parent controller. - - @retval EFI_SUCCESS ChildHandle is a child of the ControllerHandle. - @retval EFI_UNSUPPORTED ChildHandle is not a child of the - ControllerHandle. - + + @param ControllerHandle A handle for a (parent) controller to test. + @param ChildHandle A child handle to test. + @param ProtocolGuid Supplies the protocol that the child controller + opens on its parent controller. + + @retval EFI_SUCCESS ChildHandle is a child of the ControllerHandle. + @retval EFI_UNSUPPORTED ChildHandle is not a child of the + ControllerHandle. + **/ EFI_STATUS EFIAPI @@ -349,6 +357,72 @@ LookupUnicodeString ( OUT CHAR16 **UnicodeString ); +/** + This function looks up a Unicode string in UnicodeStringTable. + If Language is a member of SupportedLanguages and a Unicode + string is found in UnicodeStringTable that matches the + language code specified by Language, then it is returned in + UnicodeString. + + @param Language A pointer to the ISO 639-2 or + RFC 3066 language code for the + Unicode string to look up and + return. + + @param SupportedLanguages A pointer to the set of ISO + 639-2 or RFC 3066 language + codes that the Unicode string + table supports. Language must + be a member of this set. + + @param UnicodeStringTable A pointer to the table of + Unicode strings. + + @param UnicodeString A pointer to the Unicode + string from UnicodeStringTable + that matches the language + specified by Language. + + @param Iso639Language Specify the language code + format supported. If true, + then the format follow ISO + 639-2. If false, then it + follows RFC3066. + + @retval EFI_SUCCESS The Unicode string that + matches the language specified + by Language was found in the + table of Unicoide strings + UnicodeStringTable, and it was + returned in UnicodeString. + + @retval EFI_INVALID_PARAMETER Language is NULL. + + @retval EFI_INVALID_PARAMETER UnicodeString is NULL. + + @retval EFI_UNSUPPORTED SupportedLanguages is NULL. + + @retval EFI_UNSUPPORTED UnicodeStringTable is NULL. + + @retval EFI_UNSUPPORTED The language specified by + Language is not a member + ofSupportedLanguages. + + @retval EFI_UNSUPPORTED The language specified by + Language is not supported by + UnicodeStringTable. + +**/ +EFI_STATUS +EFIAPI +LookupUnicodeString2 ( + IN CONST CHAR8 *Language, + IN CONST CHAR8 *SupportedLanguages, + IN CONST EFI_UNICODE_STRING_TABLE *UnicodeStringTable, + OUT CHAR16 **UnicodeString, + IN BOOLEAN Iso639Language + ); + /** This function adds a Unicode string to UnicodeStringTable. If Language is a member of SupportedLanguages then UnicodeString is added to @@ -390,6 +464,76 @@ AddUnicodeString ( IN CONST CHAR16 *UnicodeString ); +/** + + This function adds a Unicode string to UnicodeStringTable. + If Language is a member of SupportedLanguages then + UnicodeString is added to UnicodeStringTable. New buffers are + allocated for both Language and UnicodeString. The contents + of Language and UnicodeString are copied into these new + buffers. These buffers are automatically freed when + FreeUnicodeStringTable() is called. + + @param Language A pointer to the ISO 639-2 or + RFC 3066 language code for the + Unicode string to add. + + @param SupportedLanguages A pointer to the set of ISO + 639-2 or RFC 3066 language + codes that the Unicode string + table supports. Language must + be a member of this set. + + @param UnicodeStringTable A pointer to the table of + Unicode strings. + + @param UnicodeString A pointer to the Unicode + string to add. + + @param Iso639Language Specify the language code + format supported. If true, + then the format follow ISO + 639-2. If false, then it + follows RFC3066. + + @retval EFI_SUCCESS The Unicode string that + matches the language specified + by Language was found in the + table of Unicode strings + UnicodeStringTable, and it was + returned in UnicodeString. + + @retval EFI_INVALID_PARAMETER Language is NULL. + + @retval EFI_INVALID_PARAMETER UnicodeString is NULL. + + @retval EFI_INVALID_PARAMETER UnicodeString is an empty string. + + @retval EFI_UNSUPPORTED SupportedLanguages is NULL. + + @retval EFI_ALREADY_STARTED A Unicode string with language + Language is already present in + UnicodeStringTable. + + @retval EFI_OUT_OF_RESOURCES There is not enough memory to + add another Unicode string to + UnicodeStringTable. + + @retval EFI_UNSUPPORTED The language specified by + Language is not a member of + SupportedLanguages. + +**/ +EFI_STATUS +EFIAPI +AddUnicodeString2 ( + IN CONST CHAR8 *Language, + IN CONST CHAR8 *SupportedLanguages, + IN EFI_UNICODE_STRING_TABLE **UnicodeStringTable, + IN CONST CHAR16 *UnicodeString, + IN BOOLEAN Iso639Language + ); + /** This function frees the table of Unicode strings in UnicodeStringTable. If UnicodeStringTable is NULL, then EFI_SUCCESS is returned. @@ -472,14 +616,15 @@ EfiSignalEventLegacyBoot ( ); /** - Create a Legacy Boot Event. + Creates an EFI event in the Legacy Boot Event Group. Prior to UEFI 2.0 this + was done via a non blessed UEFI extensions and this library abstracts the + implementation mechanism of this event from the caller. - Tiano extended the CreateEvent Type enum to add a legacy boot event type. - This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was - added and now it's possible to not voilate the UEFI specification by - declaring a GUID for the legacy boot event class. This library supports - the EDK/EFI 1.10 form and EDK II/UEFI 2.0 form and allows common code to - work both ways. + This function abstracts the creation of the Legacy Boot Event. The Framework + moved from a proprietary to UEFI 2.0 based mechanism. This library abstracts + the caller from how this event is created to prevent to code form having to + change with the version of the specification supported. + If LegacyBootEvent is NULL, then ASSERT(). @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex). @@ -522,16 +667,17 @@ EfiCreateEventLegacyBootEx ( ); /** - Create a Read to Boot Event. + Create an EFI event in the Ready To Boot Event Group. Prior to UEFI 2.0 this + was done via a non-standard UEFI extension, and this library abstracts the + implementation mechanism of this event from the caller. - Tiano extended the CreateEvent Type enum to add a ready to boot event type. - This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was - added and now it's possible to not voilate the UEFI specification and use - the ready to boot event class defined in UEFI 2.0. This library supports - the EDK/EFI 1.10 form and EDKII/UEFI 2.0 form and allows common code to - work both ways. + This function abstracts the creation of the Ready to Boot Event. The Framework + moved from a proprietary to UEFI 2.0-based mechanism. This library abstracts + the caller from how this event is created to prevent the code form having to + change with the version of the specification supported. + If ReadyToBootEvent is NULL, then ASSERT(). - @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex). + @param ReadyToBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex). @retval EFI_SUCCESS Event was created. @retval Other Event was not created. @@ -556,7 +702,7 @@ EfiCreateEventReadyToBoot ( @param NotifyTpl The task priority level of the event. @param NotifyFunction The notification function to call when the event is signaled. @param NotifyContext The content to pass to NotifyFunction when the event is signaled. - @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex). + @param ReadyToBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex). @retval EFI_SUCCESS Event was created. @retval Other Event was not created. @@ -574,13 +720,17 @@ EfiCreateEventReadyToBootEx ( /** Initialize a Firmware Volume (FV) Media Device Path node. - Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum - so as we move to UEFI 2.0 support we must use a mechanism that conforms with - the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed - device path is defined for Tiano extensions of device path. If the code - is compiled to conform with the UEFI 2.0 specification use the new device path - else use the old form for backwards compatability. - + The Framework FwVol Device Path changed to conform to the UEFI 2.0 specification. + This library function abstracts initializing a device path node. + + Initialize the MEDIA_FW_VOL_FILEPATH_DEVICE_PATH data structure. This device + path changed in the DXE CIS version 0.92 in a non back ward compatible way to + not conflict with the UEFI 2.0 specification. This function abstracts the + differences from the caller. + + If FvDevicePathNode is NULL, then ASSERT(). + If NameGuid is NULL, then ASSERT(). + @param FvDevicePathNode Pointer to a FV device path node to initialize @param NameGuid FV file name to use in FvDevicePathNode @@ -595,14 +745,15 @@ EfiInitializeFwVolDevicepathNode ( /** Check to see if the Firmware Volume (FV) Media Device Path is valid - Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum - so as we move to UEFI 2.0 support we must use a mechanism that conforms with - the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed - device path is defined for Tiano extensions of device path. If the code - is compiled to conform with the UEFI 2.0 specification use the new device path - else use the old form for backwards compatability. The return value to this - function points to a location in FvDevicePathNode and it does not allocate - new memory for the GUID pointer that is returned. + The Framework FwVol Device Path changed to conform to the UEFI 2.0 specification. + This library function abstracts validating a device path node. + + Check the MEDIA_FW_VOL_FILEPATH_DEVICE_PATH data structure to see if it's valid. + If it is valid, then return the GUID file name from the device path node. Otherwise, + return NULL. This device path changed in the DXE CIS version 0.92 in a non back ward + compatible way to not conflict with the UEFI 2.0 specification. This function abstracts + the differences from the caller. + If FvDevicePathNode is NULL, then ASSERT(). @param FvDevicePathNode Pointer to FV device path to check. @@ -630,6 +781,8 @@ EfiGetNameGuidFromFwVolDevicePathNode ( @param ... VARARG list consumed to process Format. If Format is NULL, then ASSERT(). If Format is not aligned on a 16-bit boundary, then ASSERT(). + + @return Number of Unicode characters printed to ConOut. **/ UINTN @@ -653,6 +806,8 @@ Print ( @param ... VARARG list consumed to process Format. If Format is NULL, then ASSERT(). If Format is not aligned on a 16-bit boundary, then ASSERT(). + + @return Number of Unicode characters printed to StdErr. **/ UINTN @@ -676,6 +831,8 @@ ErrorPrint ( @param ... VARARG list consumed to process Format. If Format is NULL, then ASSERT(). If Format is not aligned on a 16-bit boundary, then ASSERT(). + + @return Number of ASCII characters printed to ConOut. **/ UINTN @@ -699,6 +856,8 @@ AsciiPrint ( @param ... VARARG list consumed to process Format. If Format is NULL, then ASSERT(). If Format is not aligned on a 16-bit boundary, then ASSERT(). + + @return Number of ASCII characters printed to ConErr. **/ UINTN @@ -708,4 +867,158 @@ AsciiErrorPrint ( ... ); +/** + Initializes a driver by installing the Driver Binding Protocol onto the driver's + DriverBindingHandle. This is typically the same as the driver's ImageHandle, but + it can be different if the driver produces multiple DriverBinding Protocols. + If the Driver Binding Protocol interface is NULL, then ASSERT (). + If the installation fails, then ASSERT (). + + @param ImageHandle The image handle of the driver. + @param SystemTable The EFI System Table that was passed to the driver's entry point. + @param DriverBinding A Driver Binding Protocol instance that this driver is producing. + @param DriverBindingHandle The handle that DriverBinding is to be installed onto. If this + parameter is NULL, then a new handle is created. + + @retval EFI_SUCCESS The protocol installation is completed successfully. + @retval Others Status from gBS->InstallMultipleProtocolInterfaces(). + +**/ +EFI_STATUS +EFIAPI +EfiLibInstallDriverBinding ( + IN CONST EFI_HANDLE ImageHandle, + IN CONST EFI_SYSTEM_TABLE *SystemTable, + IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, + IN EFI_HANDLE DriverBindingHandle + ); + + +/** + Initializes a driver by installing the Driver Binding Protocol together with the optional Component Name, + Driver Configure and Driver Diagnostic Protocols onto the driver's DriverBindingHandle. This is + typically the same as the driver's ImageHandle, but it can be different if the driver produces multiple + DriverBinding Protocols. + If the Driver Binding Protocol interface is NULL, then ASSERT (). + If the installation fails, then ASSERT (). + + @param ImageHandle The image handle of the driver. + @param SystemTable The EFI System Table that was passed to the driver's entry point. + @param DriverBinding A Driver Binding Protocol instance that this driver is producing. + @param DriverBindingHandle The handle that DriverBinding is to be installed onto. If this + parameter is NULL, then a new handle is created. + @param ComponentName A Component Name Protocol instance that this driver is producing. + @param DriverConfiguration A Driver Configuration Protocol instance that this driver is producing. + @param DriverDiagnostics A Driver Diagnostics Protocol instance that this driver is producing. + + @retval EFI_SUCCESS The protocol installation is completed successfully. + @retval Others Status from gBS->InstallMultipleProtocolInterfaces(). + +**/ +EFI_STATUS +EFIAPI +EfiLibInstallAllDriverProtocols ( + IN CONST EFI_HANDLE ImageHandle, + IN CONST EFI_SYSTEM_TABLE *SystemTable, + IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, + IN EFI_HANDLE DriverBindingHandle, + IN CONST EFI_COMPONENT_NAME_PROTOCOL *ComponentName, OPTIONAL + IN CONST EFI_DRIVER_CONFIGURATION_PROTOCOL *DriverConfiguration, OPTIONAL + IN CONST EFI_DRIVER_DIAGNOSTICS_PROTOCOL *DriverDiagnostics OPTIONAL + ); + + + +/** + Initializes a driver by installing the Driver Binding Protocol together with the optional Component Name, + Component Name 2 onto the driver's DriverBindingHandle. This is typically the same as the driver's + ImageHandle, but it can be different if the driver produces multiple DriverBinding Protocols. + If the Driver Binding Protocol interface is NULL, then ASSERT (). + If the installation fails, then ASSERT (). + + @param ImageHandle The image handle of the driver. + @param SystemTable The EFI System Table that was passed to the driver's entry point. + @param DriverBinding A Driver Binding Protocol instance that this driver is producing. + @param DriverBindingHandle The handle that DriverBinding is to be installed onto. If this + parameter is NULL, then a new handle is created. + @param ComponentName A Component Name Protocol instance that this driver is producing. + @param ComponentName2 A Component Name 2 Protocol instance that this driver is producing. + + @retval EFI_SUCCESS The protocol installation is completed successfully. + @retval Others Status from gBS->InstallMultipleProtocolInterfaces(). + +**/ +EFI_STATUS +EFIAPI +EfiLibInstallDriverBindingComponentName2 ( + IN CONST EFI_HANDLE ImageHandle, + IN CONST EFI_SYSTEM_TABLE *SystemTable, + IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, + IN EFI_HANDLE DriverBindingHandle, + IN CONST EFI_COMPONENT_NAME_PROTOCOL *ComponentName, OPTIONAL + IN CONST EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2 OPTIONAL + ); + + +/** + Intialize a driver by installing the Driver Binding Protocol together with the optional Component Name, + Component Name 2, Driver Configure, Driver Diagnostic and Driver Diagnostic 2 Protocols onto the driver's + DriverBindingHandle. This is typically the same as the driver's ImageHandle, but it can be different if + the driver produces multiple DriverBinding Protocols. + If the Drvier Binding Protocol interface is NULL, then ASSERT (). + If the installation fails, then ASSERT (). + + @param ImageHandle The image handle of the driver. + @param SystemTable The EFI System Table that was passed to the driver's entry point. + @param DriverBinding A Driver Binding Protocol instance that this driver is producing. + @param DriverBindingHandle The handle that DriverBinding is to be installe onto. If this + parameter is NULL, then a new handle is created. + @param ComponentName A Component Name Protocol instance that this driver is producing. + @param ComponentName2 A Component Name 2 Protocol instance that this driver is producing. + @param DriverConfiguration A Driver Configuration Protocol instance that this driver is producing. + @param DriverConfiguration2 A Driver Configuration Protocol 2 instance that this driver is producing. + @param DriverDiagnostics A Driver Diagnostics Protocol instance that this driver is producing. + @param DriverDiagnostics2 A Driver Diagnostics Protocol 2 instance that this driver is producing. + + @retval EFI_SUCCESS The protocol installation is completed successfully. + @retval Others Status from gBS->InstallMultipleProtocolInterfaces(). + +**/ +EFI_STATUS +EFIAPI +EfiLibInstallAllDriverProtocols2 ( + IN CONST EFI_HANDLE ImageHandle, + IN CONST EFI_SYSTEM_TABLE *SystemTable, + IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, + IN EFI_HANDLE DriverBindingHandle, + IN CONST EFI_COMPONENT_NAME_PROTOCOL *ComponentName, OPTIONAL + IN CONST EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2, OPTIONAL + IN CONST EFI_DRIVER_CONFIGURATION_PROTOCOL *DriverConfiguration, OPTIONAL + IN CONST EFI_DRIVER_CONFIGURATION_PROTOCOL *DriverConfiguration2, OPTIONAL + IN CONST EFI_DRIVER_DIAGNOSTICS_PROTOCOL *DriverDiagnostics, OPTIONAL + IN CONST EFI_DRIVER_DIAGNOSTICS2_PROTOCOL *DriverDiagnostics2 OPTIONAL + ); + +/** + Determine what is the current language setting. The space reserved for Lang + must be at least RFC_3066_ENTRY_SIZE bytes; + + If Lang is NULL, then ASSERT. + + @param Lang Pointer of system language. Lang will always be filled with + a valid RFC 3066 language string. If "PlatformLang" is not + set in the system, the default language specifed by PcdUefiVariableDefaultPlatformLang + is returned. + + @return EFI_SUCCESS If the EFI Variable with "PlatformLang" is set and return in Lang. + @return EFI_NOT_FOUND If the EFI Variable with "PlatformLang" is not set, but a valid default language is return in Lang. + +**/ +EFI_STATUS +EFIAPI +GetCurrentLanguage ( + OUT CHAR8 *Lang + ); + + #endif