3 Copyright (c) 2004 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Light weight lib to support EFI drivers.
22 #ifndef _EFI_DRIVER_LIB_H_
23 #define _EFI_DRIVER_LIB_H_
25 #include "EfiStatusCode.h"
26 #include "EfiCommonLib.h"
28 #include "LinkedList.h"
30 #include "EfiImageFormat.h"
32 #include EFI_GUID_DEFINITION (DxeServices)
33 #include EFI_GUID_DEFINITION (EventGroup)
34 #include EFI_GUID_DEFINITION (EventLegacyBios)
35 #include EFI_GUID_DEFINITION (FrameworkDevicePath)
36 #include EFI_PROTOCOL_DEFINITION (FirmwareVolume)
37 #include EFI_PROTOCOL_DEFINITION (FirmwareVolume2)
38 #include EFI_PROTOCOL_DEFINITION (DataHub)
39 #include EFI_PROTOCOL_DEFINITION (DriverBinding)
40 #include EFI_PROTOCOL_DEFINITION (ComponentName)
41 #include EFI_PROTOCOL_DEFINITION (ComponentName2)
42 #include EFI_PROTOCOL_DEFINITION (DriverConfiguration)
43 #include EFI_PROTOCOL_DEFINITION (DriverDiagnostics)
45 #include EFI_PROTOCOL_DEFINITION (DebugMask)
49 CHAR16
*UnicodeString
;
50 } EFI_UNICODE_STRING_TABLE
;
51 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
52 #define LANGUAGE_RFC_3066
53 #define LANGUAGE_CODE_ENGLISH "en-US"
55 #define LANGUAGE_ISO_639_2
56 #define LANGUAGE_CODE_ENGLISH "eng"
60 // Macros for EFI Driver Library Functions that are really EFI Boot Services
62 #define EfiCopyMem(_Destination, _Source, _Length) gBS->CopyMem ((_Destination), (_Source), (_Length))
63 #define EfiSetMem(_Destination, _Length, _Value) gBS->SetMem ((_Destination), (_Length), (_Value))
64 #define EfiZeroMem(_Destination, _Length) gBS->SetMem ((_Destination), (_Length), 0)
67 // Driver Lib Globals.
69 extern EFI_BOOT_SERVICES
*gBS
;
70 extern EFI_DXE_SERVICES
*gDS
;
71 extern EFI_RUNTIME_SERVICES
*gRT
;
72 extern EFI_SYSTEM_TABLE
*gST
;
73 extern UINTN gErrorLevel
;
74 extern EFI_GUID gEfiCallerIdGuid
;
75 extern EFI_DEBUG_MASK_PROTOCOL
*gDebugMaskInterface
;
78 EfiInitializeDriverLib (
79 IN EFI_HANDLE ImageHandle
,
80 IN EFI_SYSTEM_TABLE
*SystemTable
86 Intialize Driver Lib if it has not yet been initialized.
90 ImageHandle - The firmware allocated handle for the EFI image.
92 SystemTable - A pointer to the EFI System Table.
97 EFI_STATUS always returns EFI_SUCCESS
103 DxeInitializeDriverLib (
104 IN EFI_HANDLE ImageHandle
,
105 IN EFI_SYSTEM_TABLE
*SystemTable
111 Intialize Driver Lib if it has not yet been initialized.
115 ImageHandle - The firmware allocated handle for the EFI image.
117 SystemTable - A pointer to the EFI System Table.
121 EFI_STATUS always returns EFI_SUCCESS
127 EfiLibInstallDriverBinding (
128 IN EFI_HANDLE ImageHandle
,
129 IN EFI_SYSTEM_TABLE
*SystemTable
,
130 IN EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
,
131 IN EFI_HANDLE DriverBindingHandle
137 Intialize a driver by installing the Driver Binding Protocol onto the
138 driver's DriverBindingHandle. This is typically the same as the driver's
139 ImageHandle, but it can be different if the driver produces multiple
140 DriverBinding Protocols. This function also initializes the EFI Driver
141 Library that initializes the global variables gST, gBS, gRT.
145 ImageHandle - The image handle of the driver
147 SystemTable - The EFI System Table that was passed to the driver's entry point
149 DriverBinding - A Driver Binding Protocol instance that this driver is producing
151 DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this
152 parameter is NULL, then a new handle is created.
156 EFI_SUCCESS is DriverBinding is installed onto DriverBindingHandle
158 Otherwise, then return status from gBS->InstallProtocolInterface()
164 EfiLibInstallAllDriverProtocols (
165 IN EFI_HANDLE ImageHandle
,
166 IN EFI_SYSTEM_TABLE
*SystemTable
,
167 IN EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
,
168 IN EFI_HANDLE DriverBindingHandle
,
169 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
170 IN EFI_COMPONENT_NAME2_PROTOCOL
*ComponentName
,
172 IN EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
,
174 IN EFI_DRIVER_CONFIGURATION_PROTOCOL
*DriverConfiguration
,
175 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*DriverDiagnostics
181 Intialize a driver by installing the Driver Binding Protocol onto the
182 driver's DriverBindingHandle. This is typically the same as the driver's
183 ImageHandle, but it can be different if the driver produces multiple
184 DriverBinding Protocols. This function also initializes the EFI Driver
185 Library that initializes the global variables gST, gBS, gRT.
189 ImageHandle - The image handle of the driver
191 SystemTable - The EFI System Table that was passed to the driver's entry point
193 DriverBinding - A Driver Binding Protocol instance that this driver is producing
195 DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this
196 parameter is NULL, then a new handle is created.
198 ComponentName - A Component Name Protocol instance that this driver is producing
200 DriverConfiguration - A Driver Configuration Protocol instance that this driver is producing
202 DriverDiagnostics - A Driver Diagnostics Protocol instance that this driver is producing
206 EFI_SUCCESS if all the protocols were installed onto DriverBindingHandle
208 Otherwise, then return status from gBS->InstallProtocolInterface()
214 EfiLibGetSystemConfigurationTable (
215 IN EFI_GUID
*TableGuid
,
222 Return the EFI 1.0 System Tabl entry with TableGuid
226 TableGuid - Name of entry to return in the system table
227 Table - Pointer in EFI system table associated with TableGuid
231 EFI_SUCCESS - Table returned;
232 EFI_NOT_FOUND - TableGuid not in EFI system table
238 EfiLibCompareLanguage (
246 Compare two languages to say whether they are identical.
250 Language1 - first language
251 Language2 - second language
256 FALSE - not identical
265 EfiIsDevicePathMultiInstance (
266 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
271 Return TRUE is this is a multi instance device path.
274 DevicePath - A pointer to a device path data structure.
278 TRUE - If DevicePath is multi instance.
279 FALSE - If DevicePath is not multi instance.
284 EFI_DEVICE_PATH_PROTOCOL
*
285 EfiDevicePathInstance (
286 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DevicePath
,
292 Function retrieves the next device path instance from a device path data structure.
295 DevicePath - A pointer to a device path data structure.
297 Size - A pointer to the size of a device path instance in bytes.
301 This function returns a pointer to the current device path instance.
302 In addition, it returns the size in bytes of the current device path instance in Size,
303 and a pointer to the next device path instance in DevicePath.
304 If there are no more device path instances in DevicePath, then DevicePath will be set to NULL.
311 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
317 Calculate the size of a whole device path.
321 DevPath - The pointer to the device path data.
325 Size of device path data structure..
330 EFI_DEVICE_PATH_PROTOCOL
*
331 EfiAppendDevicePath (
332 IN EFI_DEVICE_PATH_PROTOCOL
*Src1
,
333 IN EFI_DEVICE_PATH_PROTOCOL
*Src2
338 Function is used to append a Src1 and Src2 together.
341 Src1 - A pointer to a device path data structure.
343 Src2 - A pointer to a device path data structure.
347 A pointer to the new device path is returned.
348 NULL is returned if space for the new device path could not be allocated from pool.
349 It is up to the caller to free the memory used by Src1 and Src2 if they are no longer needed.
354 EFI_DEVICE_PATH_PROTOCOL
*
355 EfiDevicePathFromHandle (
362 Locate device path protocol interface on a device handle.
366 Handle - The device handle
370 Device path protocol interface located.
375 EFI_DEVICE_PATH_PROTOCOL
*
376 EfiDuplicateDevicePath (
377 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
382 Duplicate a new device path data structure from the old one.
385 DevPath - A pointer to a device path data structure.
388 A pointer to the new allocated device path data.
389 Caller must free the memory used by DevicePath if it is no longer needed.
394 EFI_DEVICE_PATH_PROTOCOL
*
395 EfiAppendDevicePathNode (
396 IN EFI_DEVICE_PATH_PROTOCOL
*Src1
,
397 IN EFI_DEVICE_PATH_PROTOCOL
*Src2
402 Function is used to append a device path node to the end of another device path.
405 Src1 - A pointer to a device path data structure.
407 Src2 - A pointer to a device path data structure.
410 This function returns a pointer to the new device path.
411 If there is not enough temporary pool memory available to complete this function,
412 then NULL is returned.
418 EFI_DEVICE_PATH_PROTOCOL
*
420 IN EFI_HANDLE Device OPTIONAL
,
426 Create a device path that appends a MEDIA_DEVICE_PATH with
427 FileNameGuid to the device path of DeviceHandle.
430 Device - Optional Device Handle to use as Root of the Device Path
435 EFI_DEVICE_PATH_PROTOCOL that was allocated from dynamic memory
441 EFI_DEVICE_PATH_PROTOCOL
*
442 EfiAppendDevicePathInstance (
443 IN EFI_DEVICE_PATH_PROTOCOL
*Src
,
444 IN EFI_DEVICE_PATH_PROTOCOL
*Instance
450 Append a device path instance to another.
454 Src - The device path instance to be appended with.
455 Instance - The device path instance appending the other.
459 The contaction of these two.
475 IN OUT EFI_LOCK
*Lock
,
482 Initialize a basic mutual exclusion lock. Each lock
483 provides mutual exclusion access at it's task priority
484 level. Since there is no-premption (at any TPL) or
485 multiprocessor support, acquiring the lock only consists
486 of raising to the locks TPL.
488 Note on a check build ASSERT()s are used to ensure proper
493 Lock - The EFI_LOCK structure to initialize
495 Priority - The task priority level of the lock
500 An initialized Efi Lock structure.
506 // Macro to initialize the state of a lock when a lock variable is declared
508 #define EFI_INITIALIZE_LOCK_VARIABLE(Tpl) {Tpl,0,0}
518 Raising to the task priority level of the mutual exclusion
519 lock, and then acquires ownership of the lock.
523 Lock - The lock to acquire
533 EfiAcquireLockOrFail (
540 Initialize a basic mutual exclusion lock. Each lock
541 provides mutual exclusion access at it's task priority
542 level. Since there is no-premption (at any TPL) or
543 multiprocessor support, acquiring the lock only consists
544 of raising to the locks TPL.
548 Lock - The EFI_LOCK structure to initialize
552 EFI_SUCCESS - Lock Owned.
553 EFI_ACCESS_DENIED - Reentrant Lock Acquisition, Lock not Owned.
566 Releases ownership of the mutual exclusion lock, and
567 restores the previous task priority level.
571 Lock - The lock to release
582 IN UINTN AllocationSize
588 Allocate EfiBootServicesData pool of size AllocationSize
592 AllocationSize - Pool size
596 Pointer to the pool allocated
602 EfiLibAllocateRuntimePool (
603 IN UINTN AllocationSize
609 Allocate EfiRuntimeServicesData pool of size AllocationSize
613 AllocationSize - Pool size
617 Pointer to the pool allocated
623 EfiLibAllocateZeroPool (
624 IN UINTN AllocationSize
630 Allocate EfiBootServicesData pool of size AllocationSize and set memory to zero.
634 AllocationSize - Pool size
638 Pointer to the pool allocated
644 EfiLibAllocateRuntimeZeroPool (
645 IN UINTN AllocationSize
651 Allocate EfiRuntimeServicesData pool of size AllocationSize and set memory to zero.
655 AllocationSize - Pool size
659 Pointer to the pool allocated
665 EfiLibAllocateCopyPool (
666 IN UINTN AllocationSize
,
673 Allocate BootServicesData pool and use a buffer provided by
678 AllocationSize - The size to allocate
680 Buffer - Buffer that will be filled into the buffer allocated
684 Pointer of the buffer allocated.
690 EfiLibAllocateRuntimeCopyPool (
691 IN UINTN AllocationSize
,
698 Allocate RuntimeServicesData pool and use a buffer provided by
703 AllocationSize - The size to allocate
705 Buffer - Buffer that will be filled into the buffer allocated
709 Pointer of the buffer allocated.
718 EfiLibCreateProtocolNotifyEvent (
719 IN EFI_GUID
*ProtocolGuid
,
720 IN EFI_TPL NotifyTpl
,
721 IN EFI_EVENT_NOTIFY NotifyFunction
,
722 IN VOID
*NotifyContext
,
723 OUT VOID
**Registration
729 Create a protocol notification event and return it.
733 ProtocolGuid - Protocol to register notification event on.
735 NotifyTpl - Maximum TPL to single the NotifyFunction.
737 NotifyFunction - EFI notification routine.
739 NotifyContext - Context passed into Event when it is created.
741 Registration - Registration key returned from RegisterProtocolNotify().
745 The EFI_EVENT that has been registered to be signaled when a ProtocolGuid
746 is added to the system.
752 EfiLibNamedEventSignal (
758 Signals a named event. All registered listeners will run.
759 The listeners should register using EfiLibNamedEventListen() function.
761 NOTE: For now, the named listening/signalling is implemented
762 on a protocol interface being installed and uninstalled.
763 In the future, this maybe implemented based on a dedicated mechanism.
766 Name - Name to perform the signaling on. The name is a GUID.
769 EFI_SUCCESS if successfull.
775 EfiLibNamedEventListen (
777 IN EFI_TPL NotifyTpl
,
778 IN EFI_EVENT_NOTIFY NotifyFunction
,
779 IN VOID
*NotifyContext
784 Listenes to signals on the name.
785 EfiLibNamedEventSignal() signals the event.
787 NOTE: For now, the named listening/signalling is implemented
788 on a protocol interface being installed and uninstalled.
789 In the future, this maybe implemented based on a dedicated mechanism.
792 Name - Name to register the listener on.
793 NotifyTpl - Maximum TPL to singnal the NotifyFunction.
794 NotifyFunction - The listener routine.
795 NotifyContext - Context passed into the listener routine.
798 EFI_SUCCESS if successful.
807 EfiLibLocateHandleProtocolByProtocols (
808 IN OUT EFI_HANDLE
* Handle
, OPTIONAL
809 OUT VOID
**Interface
, OPTIONAL
815 Function locates Protocol and/or Handle on which all Protocols specified
816 as a variable list are installed.
817 It supports continued search. The caller must assure that no handles are added
818 or removed while performing continued search, by e.g., rising the TPL and not
819 calling any handle routines. Otherwise the behavior is undefined.
823 Handle - The address of handle to receive the handle on which protocols
824 indicated by the variable list are installed.
825 If points to NULL, all handles are searched. If pointing to a
826 handle returned from previous call, searches starting from next handle.
827 If NULL, the parameter is ignored.
829 Interface - The address of a pointer to a protocol interface that will receive
830 the interface indicated by first variable argument.
831 If NULL, the parameter is ignored.
833 ... - A variable argument list containing protocol GUIDs. Must end with NULL.
837 EFI_SUCCESS - All the protocols where found on same handle.
838 EFI_NOT_FOUND - A Handle with all the protocols installed was not found.
839 Other values as may be returned from LocateHandleBuffer() or HandleProtocol().
855 Locate Debug Assert Protocol and set as mDebugAssert
869 // Unicode String Support
872 EfiLibLookupUnicodeString (
874 CHAR8
*SupportedLanguages
,
875 EFI_UNICODE_STRING_TABLE
*UnicodeStringTable
,
876 CHAR16
**UnicodeString
882 Translate a unicode string to a specified language if supported.
886 Language - The name of language to translate to
887 SupportedLanguages - Supported languages set
888 UnicodeStringTable - Pointer of one item in translation dictionary
889 UnicodeString - The translated string
893 EFI_INVALID_PARAMETER - Invalid parameter
894 EFI_UNSUPPORTED - System not supported this language or this string translation
895 EFI_SUCCESS - String successfully translated
901 EfiLibAddUnicodeString (
903 CHAR8
*SupportedLanguages
,
904 EFI_UNICODE_STRING_TABLE
**UnicodeStringTable
,
905 CHAR16
*UnicodeString
911 Add an translation to the dictionary if this language if supported.
915 Language - The name of language to translate to
916 SupportedLanguages - Supported languages set
917 UnicodeStringTable - Translation dictionary
918 UnicodeString - The corresponding string for the language to be translated to
922 EFI_INVALID_PARAMETER - Invalid parameter
923 EFI_UNSUPPORTED - System not supported this language
924 EFI_ALREADY_STARTED - Already has a translation item of this language
925 EFI_OUT_OF_RESOURCES - No enough buffer to be allocated
926 EFI_SUCCESS - String successfully translated
932 EfiLibFreeUnicodeStringTable (
933 EFI_UNICODE_STRING_TABLE
*UnicodeStringTable
943 UnicodeStringTable - The string table to be freed.
947 EFI_SUCCESS - The table successfully freed.
953 EfiLibReportStatusCode (
954 IN EFI_STATUS_CODE_TYPE Type
,
955 IN EFI_STATUS_CODE_VALUE Value
,
957 IN EFI_GUID
*CallerId OPTIONAL
,
958 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
970 Instance - Instance number
971 CallerId - Caller name
972 DevicePath - Device path that to be reported
978 EFI_OUT_OF_RESOURCES - No enough buffer could be allocated
984 ReportStatusCodeWithDevicePath (
985 IN EFI_STATUS_CODE_TYPE Type
,
986 IN EFI_STATUS_CODE_VALUE Value
,
988 IN EFI_GUID
* CallerId OPTIONAL
,
989 IN EFI_DEVICE_PATH_PROTOCOL
* DevicePath
995 Report device path through status code.
1001 Instance - Instance number
1002 CallerId - Caller name
1003 DevicePath - Device path that to be reported
1009 EFI_OUT_OF_RESOURCES - No enough buffer could be allocated
1016 EfiCreateEventLegacyBoot (
1017 IN EFI_TPL NotifyTpl
,
1018 IN EFI_EVENT_NOTIFY NotifyFunction
,
1019 IN VOID
*NotifyContext
,
1020 OUT EFI_EVENT
*LegacyBootEvent
1024 Routine Description:
1025 Create a Legacy Boot Event.
1026 Tiano extended the CreateEvent Type enum to add a legacy boot event type.
1027 This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was
1028 added and now it's possible to not voilate the UEFI specification by
1029 declaring a GUID for the legacy boot event class. This library supports
1030 the R8.5/EFI 1.10 form and R8.6/UEFI 2.0 form and allows common code to
1034 LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex)
1037 EFI_SUCCESS Event was created.
1038 Other Event was not created.
1045 EfiCreateEventReadyToBoot (
1046 IN EFI_TPL NotifyTpl
,
1047 IN EFI_EVENT_NOTIFY NotifyFunction
,
1048 IN VOID
*NotifyContext
,
1049 OUT EFI_EVENT
*ReadyToBootEvent
1053 Routine Description:
1054 Create a Read to Boot Event.
1056 Tiano extended the CreateEvent Type enum to add a ready to boot event type.
1057 This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was
1058 added and now it's possible to not voilate the UEFI specification and use
1059 the ready to boot event class defined in UEFI 2.0. This library supports
1060 the R8.5/EFI 1.10 form and R8.6/UEFI 2.0 form and allows common code to
1064 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex)
1067 EFI_SUCCESS - Event was created.
1068 Other - Event was not created.
1075 EfiInitializeFwVolDevicepathNode (
1076 IN MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvDevicePathNode
,
1077 IN EFI_GUID
*NameGuid
1080 Routine Description:
1081 Initialize a Firmware Volume (FV) Media Device Path node.
1083 Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum
1084 so as we move to UEFI 2.0 support we must use a mechanism that conforms with
1085 the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed
1086 device path is defined for PIWG extensions of device path. If the code
1087 is compiled to conform with the UEFI 2.0 specification use the new device path
1088 else use the old form for backwards compatability.
1091 FvDevicePathNode - Pointer to a FV device path node to initialize
1092 NameGuid - FV file name to use in FvDevicePathNode
1099 EfiGetNameGuidFromFwVolDevicePathNode (
1100 IN MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvDevicePathNode
1103 Routine Description:
1104 Check to see if the Firmware Volume (FV) Media Device Path is valid.
1106 Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum
1107 so as we move to UEFI 2.0 support we must use a mechanism that conforms with
1108 the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed
1109 device path is defined for PIWG extensions of device path. If the code
1110 is compiled to conform with the UEFI 2.0 specification use the new device path
1111 else use the old form for backwards compatability. The return value to this
1112 function points to a location in FvDevicePathNode and it does not allocate
1113 new memory for the GUID pointer that is returned.
1116 FvDevicePathNode - Pointer to FV device path to check
1119 NULL - FvDevicePathNode is not valid.
1120 Other - FvDevicePathNode is valid and pointer to NameGuid was returned.
1126 EfiLibSafeFreePool (
1131 Routine Description:
1137 Buffer - The allocated pool entry to free
1141 Pointer of the buffer allocated.
1147 EfiLibTestManagedDevice (
1148 IN EFI_HANDLE ControllerHandle
,
1149 IN EFI_HANDLE DriverBindingHandle
,
1150 IN EFI_GUID
*ManagedProtocolGuid
1154 Routine Description:
1156 Test to see if the controller is managed by a specific driver.
1160 ControllerHandle - Handle for controller to test
1162 DriverBindingHandle - Driver binding handle for controller
1164 ManagedProtocolGuid - The protocol guid the driver opens on controller
1168 EFI_SUCCESS - The controller is managed by the driver
1170 EFI_UNSUPPORTED - The controller is not managed by the driver
1176 EfiLibTestChildHandle (
1177 IN EFI_HANDLE ControllerHandle
,
1178 IN EFI_HANDLE ChildHandle
,
1179 IN EFI_GUID
*ConsumedGuid
1183 Routine Description:
1185 Test to see if the child handle is the child of the controller
1189 ControllerHandle - Handle for controller (parent)
1191 ChildHandle - Child handle to test
1193 ConsumsedGuid - Protocol guid consumed by child from controller
1197 EFI_SUCCESS - The child handle is the child of the controller
1199 EFI_UNSUPPORTED - The child handle is not the child of the controller