4 Copyright (c) 2006, 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.
17 R8_EfiLibInstallDriverBinding (
18 IN EFI_HANDLE ImageHandle
,
19 IN EFI_SYSTEM_TABLE
*SystemTable
,
20 IN EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
,
21 IN EFI_HANDLE DriverBindingHandle
27 Intialize a driver by installing the Driver Binding Protocol onto the
28 driver's DriverBindingHandle. This is typically the same as the driver's
29 ImageHandle, but it can be different if the driver produces multiple
30 DriverBinding Protocols. This function also initializes the EFI Driver
31 Library that initializes the global variables gST, gBS, gRT.
35 ImageHandle - The image handle of the driver
37 SystemTable - The EFI System Table that was passed to the driver's entry point
39 DriverBinding - A Driver Binding Protocol instance that this driver is producing
41 DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this
42 parameter is NULL, then a new handle is created.
46 EFI_SUCCESS is DriverBinding is installed onto DriverBindingHandle
48 Otherwise, then return status from gBS->InstallProtocolInterface()
54 // This obsolete Edk library interface installs driver binding protocol.
55 // If the entry point of that module only invoke this function, it can
56 // use UefiDriverModuleLib in MdePkg and expose "DriverBinding" protocol interface
57 // at the <Externs> tag, build tool will auto generate code to handle it.
61 // <DriverBinding>gFatDriverBinding</DriverBinding>
65 DriverBinding
->ImageHandle
= ImageHandle
;
67 DriverBinding
->DriverBindingHandle
= DriverBindingHandle
;
69 return gBS
->InstallProtocolInterface (
70 &DriverBinding
->DriverBindingHandle
,
71 &gEfiDriverBindingProtocolGuid
,
80 R8_EfiLibInstallAllDriverProtocols (
81 IN EFI_HANDLE ImageHandle
,
82 IN EFI_SYSTEM_TABLE
* SystemTable
,
83 IN EFI_DRIVER_BINDING_PROTOCOL
* DriverBinding
,
84 IN EFI_HANDLE DriverBindingHandle
,
85 IN EFI_COMPONENT_NAME_PROTOCOL
* ComponentName
, OPTIONAL
86 IN EFI_DRIVER_CONFIGURATION_PROTOCOL
* DriverConfiguration
, OPTIONAL
87 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
* DriverDiagnostics OPTIONAL
93 Intialize a driver by installing the Driver Binding Protocol onto the
94 driver's DriverBindingHandle. This is typically the same as the driver's
95 ImageHandle, but it can be different if the driver produces multiple
96 DriverBinding Protocols. This function also initializes the EFI Driver
97 Library that initializes the global variables gST, gBS, gRT.
101 ImageHandle - The image handle of the driver
103 SystemTable - The EFI System Table that was passed to the driver's entry point
105 DriverBinding - A Driver Binding Protocol instance that this driver is producing
107 DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this
108 parameter is NULL, then a new handle is created.
110 ComponentName - A Component Name Protocol instance that this driver is producing
112 DriverConfiguration - A Driver Configuration Protocol instance that this driver is producing
114 DriverDiagnostics - A Driver Diagnostics Protocol instance that this driver is producing
118 EFI_SUCCESS if all the protocols were installed onto DriverBindingHandle
120 Otherwise, then return status from gBS->InstallProtocolInterface()
126 // This obsolete Edk library interface installs driver binding protocol
127 // with optional component name, driver configuration & driver diagnotics protocols.
128 // If the entry point of that module only invoke this function, it can
129 // use UefiDriverModuleLib in MdePkg and expose "DriverBinding", "ComponentName",
130 // "DriverConfiguration" and "DriverDiagnostics" protocol interfaces.
131 // at the <Externs> tag, build tool will auto generate code to handle it.
135 // <DriverBinding>gFatDriverBinding</DriverBinding>
138 // <ComponentName>gFatComponentName</ComponentName>
144 Status
= R8_EfiLibInstallDriverBinding (ImageHandle
, SystemTable
, DriverBinding
, DriverBindingHandle
);
145 if (EFI_ERROR (Status
)) {
149 if (ComponentName
!= NULL
) {
150 Status
= gBS
->InstallProtocolInterface (
151 &DriverBinding
->DriverBindingHandle
,
152 &gEfiComponentNameProtocolGuid
,
153 EFI_NATIVE_INTERFACE
,
156 if (EFI_ERROR (Status
)) {
161 if (DriverConfiguration
!= NULL
) {
162 Status
= gBS
->InstallProtocolInterface (
163 &DriverBinding
->DriverBindingHandle
,
164 &gEfiDriverConfigurationProtocolGuid
,
165 EFI_NATIVE_INTERFACE
,
168 if (EFI_ERROR (Status
)) {
173 if (DriverDiagnostics
!= NULL
) {
174 Status
= gBS
->InstallProtocolInterface (
175 &DriverBinding
->DriverBindingHandle
,
176 &gEfiDriverDiagnosticsProtocolGuid
,
177 EFI_NATIVE_INTERFACE
,
180 if (EFI_ERROR (Status
)) {
191 R8_EfiLibCompareLanguage (
199 Compare whether two names of languages are identical.
203 Language1 - Name of language 1
204 Language2 - Name of language 2
215 // This library interface is simply obsolete.
216 // Include the source code to user code.
220 for (Index
= 0; Index
< 3; Index
++) {
221 if (Language1
[Index
] != Language2
[Index
]) {
234 IN OUT UINTN
*HexStringBufferLength
,
241 Converts binary buffer to Unicode string.
242 At a minimum, any blob of data could be represented as a hex string.
245 Str - Pointer to the string.
246 HexStringBufferLength - Length in bytes of buffer to hold the hex string. Includes tailing '\0' character.
247 If routine return with EFI_SUCCESS, containing length of hex string buffer.
248 If routine return with EFI_BUFFER_TOO_SMALL, containg length of hex string buffer desired.
249 Buf - Buffer to be converted from.
250 Len - Length in bytes of the buffer to be converted.
253 EFI_SUCCESS: Routine success.
254 EFI_BUFFER_TOO_SMALL: The hex string buffer is too small.
260 // This library interface is simply obsolete.
261 // Include the source code to user code.
268 // Make sure string is either passed or allocate enough.
269 // It takes 2 Unicode characters (4 bytes) to represent 1 byte of the binary buffer.
270 // Plus the Unicode termination character.
273 if (StrLen
> ((*HexStringBufferLength
) - 1)) {
274 *HexStringBufferLength
= StrLen
+ 1;
275 return EFI_BUFFER_TOO_SMALL
;
278 *HexStringBufferLength
= StrLen
+ 1;
284 for (Idx
= 0; Idx
< Len
; Idx
++) {
287 Str
[StrLen
- 1 - Idx
* 2] = NibbleToHexChar (Byte
);
288 Str
[StrLen
- 2 - Idx
* 2] = NibbleToHexChar ((UINT8
)(Byte
>> 4));
305 Removes (trims) specified leading and trailing characters from a string.
309 str - Pointer to the null-terminated string to be trimmed. On return,
310 str will hold the trimmed string.
311 CharC - Character will be trimmed from str.
319 // This library interface is simply obsolete.
320 // Include the source code to user code.
330 // Trim off the leading and trailing characters c
332 for (p1
= str
; *p1
&& *p1
== CharC
; p1
++) {
352 for (p1
= str
+ StrLen(str
) - 1; p1
>= str
&& *p1
== CharC
; p1
--) {
355 if (p1
!= str
+ StrLen(str
) - 1) {
363 R8_EfiValueToHexStr (
364 IN OUT CHAR16
*Buffer
,
373 VSPrint worker function that prints a Value as a hex number in Buffer
377 Buffer - Location to place ascii hex string of Value.
379 Value - Hex value to convert to a string in Buffer.
381 Flags - Flags to use in printing Hex string, see file header for details.
383 Width - Width of hex value.
387 Number of characters printed.
393 // Edk II BasePrintLib function UnicodeValueToString does not support
394 // to convert Value to Hex String.
395 // Include the source code to user code or use the full PrintLib funtion
396 // UnicodeVSPrintAsciiFormat (Buffer, MAXIMUM_VALUE_CHARACTERS, "%x", Value) instead.
399 CHAR16 TempBuffer
[MAXIMUM_VALUE_CHARACTERS
];
406 TempStr
= TempBuffer
;
410 // Count starts at one since we will null terminate. Each iteration of the
411 // loop picks off one nibble. Oh yea TempStr ends up backwards
415 if (Width
> MAXIMUM_VALUE_CHARACTERS
- 1) {
416 Width
= MAXIMUM_VALUE_CHARACTERS
- 1;
421 // If Width == 0, it means no limit.
423 if ((Width
!= 0) && (Count
>= Width
)) {
427 Index
= ((UINTN
)Value
& 0xf);
428 *(TempStr
++) = mHexStr
[Index
];
429 Value
= RShiftU64 (Value
, 4);
431 } while (Value
!= 0);
433 if (Flags
& PREFIX_ZERO
) {
440 if (!(Flags
& LEFT_JUSTIFY
)) {
441 for (; Index
< Width
; Index
++) {
442 *(TempStr
++) = Prefix
;
447 // Reverse temp string into Buffer.
449 while (TempStr
!= TempBuffer
) {
450 *(BufferPtr
++) = *(--TempStr
);
466 OUT UINTN
*ConvertedStrLen OPTIONAL
471 Converts Unicode string to binary buffer.
472 The conversion may be partial.
473 The first character in the string that is not hex digit stops the conversion.
474 At a minimum, any blob of data could be represented as a hex string.
477 Buf - Pointer to buffer that receives the data.
478 Len - Length in bytes of the buffer to hold converted data.
479 If routine return with EFI_SUCCESS, containing length of converted data.
480 If routine return with EFI_BUFFER_TOO_SMALL, containg length of buffer desired.
481 Str - String to be converted from.
482 ConvertedStrLen - Length of the Hex String consumed.
485 EFI_SUCCESS: Routine Success.
486 EFI_BUFFER_TOO_SMALL: The buffer is too small to hold converted data.
493 // This library interface is simply obsolete.
494 // Include the source code to user code.
504 // Find out how many hex characters the string has.
506 for (Idx
= 0, HexCnt
= 0; IsHexDigit (&Digit
, Str
[Idx
]); Idx
++, HexCnt
++);
513 // Two Unicode characters make up 1 buffer byte. Round up.
515 BufferLength
= (HexCnt
+ 1) / 2;
518 // Test if buffer is passed enough.
520 if (BufferLength
> (*Len
)) {
522 return EFI_BUFFER_TOO_SMALL
;
527 for (Idx
= 0; Idx
< HexCnt
; Idx
++) {
529 IsHexDigit (&Digit
, Str
[HexCnt
- 1 - Idx
]);
532 // For odd charaters, write the lower nibble for each buffer byte,
533 // and for even characters, the upper nibble.
535 if ((Idx
& 1) == 0) {
546 if (ConvertedStrLen
!= NULL
) {
547 *ConvertedStrLen
= HexCnt
;
563 Determines if a Unicode character is a hexadecimal digit.
564 The test is case insensitive.
567 Digit - Pointer to byte that receives the value of the hex character.
568 Char - Unicode character to test.
571 TRUE - If the character is a hexadecimal digit.
578 // This library interface is simply obsolete.
579 // Include the source code to user code.
582 if ((Char
>= L
'0') && (Char
<= L
'9')) {
583 *Digit
= (UINT8
) (Char
- L
'0');
587 if ((Char
>= L
'A') && (Char
<= L
'F')) {
588 *Digit
= (UINT8
) (Char
- L
'A' + 0x0A);
592 if ((Char
>= L
'a') && (Char
<= L
'f')) {
593 *Digit
= (UINT8
) (Char
- L
'a' + 0x0A);
609 Converts the low nibble of a byte to hex unicode character.
612 Nibble - lower nibble of a byte.
615 Hex unicode character.
621 // This library interface is simply obsolete.
622 // Include the source code to user code.
627 return (CHAR16
)(Nibble
+ L
'0');
630 return (CHAR16
)(Nibble
- 0xA + L
'A');
644 This function returns the first instance of a HOB type in a HOB list.
648 Type The HOB type to return.
649 HobStart The first HOB in the HOB list.
653 HobStart There were no HOBs found with the requested type.
654 else Returns the first HOB with the matching type.
660 // Edk II HobLib GetNextHob () is an equivelent function with the following exceptions:
661 // 1. GetNextHob () does not allow NULL value as the argument of HobStart by ASSERT ()
662 // 2. GetNextHob () will return NULL instead of returning HobStart when such kind of
663 // HOB can be retrieved, so caller does not need to re-check the return HOB type any longer.
668 // Return input if not found
670 if (HobStart
== NULL
) {
673 Hob
= GetNextHob (Type
, HobStart
);
691 Get size of hob list.
695 HobStart - Start pointer of hob list
705 // This library interface is simply obsolete.
706 // Include the source code to user code.
708 EFI_PEI_HOB_POINTERS Hob
;
714 while (Hob
.Header
->HobType
!= EFI_HOB_TYPE_END_OF_HOB_LIST
) {
715 Size
+= Hob
.Header
->HobLength
;
716 Hob
.Raw
+= Hob
.Header
->HobLength
;
719 Size
+= Hob
.Header
->HobLength
;
738 HobStart - Start pointer of hob list
748 // This library interface is simply obsolete.
749 // Include the source code to user code.
752 EFI_PEI_HOB_POINTERS Hob
;
755 return Hob
.HandoffInformationTable
->Version
;
763 OUT EFI_BOOT_MODE
*BootMode
769 Get current boot mode.
773 HobStart - Start pointer of hob list
775 BootMode - Current boot mode recorded in PHIT hob
779 EFI_NOT_FOUND - Invalid hob header
781 EFI_SUCCESS - Boot mode found
787 // This library interface is simply obsolete.
788 // Include the source code to user code.
789 // In fact, since EFI_HANDOFF_HOB must be the first Hob,
790 // the following code can retrieve boot mode.
792 // EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
794 // HandOffHob = GetHobList ();
795 // ASSERT (HandOffHob->Header.HobType = EFI_HOB_TYPE_HANDOFF);
797 // BootMode = HandOffHob->BootMode;
799 EFI_PEI_HOB_POINTERS Hob
;
802 if (Hob
.Header
->HobType
!= EFI_HOB_TYPE_HANDOFF
) {
803 return EFI_NOT_FOUND
;
806 *BootMode
= Hob
.HandoffInformationTable
->BootMode
;
816 OUT UINT8
*SizeOfMemorySpace
,
817 OUT UINT8
*SizeOfIoSpace
823 Get information recorded in CPU hob (Memory space size, Io space size)
827 HobStart - Start pointer of hob list
829 SizeOfMemorySpace - Size of memory size
831 SizeOfIoSpace - Size of IO size
835 EFI_NOT_FOUND - CPU hob not found
837 EFI_SUCCESS - CPU hob found and information got.
843 // This library interface is simply obsolete.
844 // Include the source code to user code.
845 // If Cpu HOB info is indispensable, user is able to ASSERT ()
846 // first to save error handling code
849 // EFI_HOB_CPU *CpuHob;
851 // CpuHob = GetHob (EFI_HOB_TYPE_CPU, HobStart);
852 // ASSERT (CpuHob != NULL);
858 CpuHob
= GetHob (EFI_HOB_TYPE_CPU
, HobStart
);
859 if (CpuHob
== NULL
) {
860 return EFI_NOT_FOUND
;
863 *SizeOfMemorySpace
= CpuHob
->SizeOfMemorySpace
;
864 *SizeOfIoSpace
= CpuHob
->SizeOfIoSpace
;
871 R8_GetDxeCoreHobInfo (
873 OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
875 OUT VOID
**EntryPoint
,
876 OUT EFI_GUID
**FileName
882 Get memory allocation hob created for DXE core and extract its information
886 HobStart - Start pointer of the hob list
887 BaseAddress - Start address of memory allocated for DXE core
888 Length - Length of memory allocated for DXE core
889 EntryPoint - DXE core file name
894 EFI_NOT_FOUND - DxeCoreHob not found
895 EFI_SUCCESS - DxeCoreHob found and information got
901 // This library interface is simply obsolete.
902 // Include the source code to user code.
904 EFI_PEI_HOB_POINTERS DxeCoreHob
;
906 for (DxeCoreHob
.Raw
= HobStart
;
907 (DxeCoreHob
.Raw
= GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, DxeCoreHob
.Raw
)) != NULL
;
908 DxeCoreHob
.Raw
= GET_NEXT_HOB (DxeCoreHob
)) {
909 if (CompareGuid (&DxeCoreHob
.MemoryAllocationModule
->MemoryAllocationHeader
.Name
,
910 &gEfiHobMemeryAllocModuleGuid
)) {
911 *BaseAddress
= DxeCoreHob
.MemoryAllocationModule
->MemoryAllocationHeader
.MemoryBaseAddress
;
912 *Length
= DxeCoreHob
.MemoryAllocationModule
->MemoryAllocationHeader
.MemoryLength
;
913 *EntryPoint
= (VOID
*) (UINTN
) DxeCoreHob
.MemoryAllocationModule
->EntryPoint
;
914 *FileName
= &DxeCoreHob
.MemoryAllocationModule
->ModuleName
;
919 return EFI_NOT_FOUND
;
925 R8_GetNextFirmwareVolumeHob (
926 IN OUT VOID
**HobStart
,
927 OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
934 Get next firmware volume hob from HobStart
938 HobStart - Start pointer of hob list
940 BaseAddress - Start address of next firmware volume
942 Length - Length of next firmware volume
946 EFI_NOT_FOUND - Next firmware volume not found
948 EFI_SUCCESS - Next firmware volume found with address information
954 // This library interface is simply obsolete.
955 // Include the source code to user code.
956 // Pay attention that caller is REQUIRED to update HobStart with:
957 // *HobStart = GET_NEXT_HOB (FirmwareVolumeHob)
959 // If FV HOB info is indispensable, user is able to ASSERT ()
960 // first to save error handling code
963 // EFI_HOB_FIRMWARE_VOLUME *FirmwareVolumeHob;
965 // FirmwareVolumeHob = GetHob (EFI_HOB_TYPE_FV, HobStart);
966 // ASSERT (FirmwareVolumeHob != NULL);
971 EFI_PEI_HOB_POINTERS FirmwareVolumeHob
;
973 FirmwareVolumeHob
.Raw
= GetNextHob (EFI_HOB_TYPE_FV
, *HobStart
);
974 if (FirmwareVolumeHob
.Raw
!= NULL
) {
975 return EFI_NOT_FOUND
;
978 *BaseAddress
= FirmwareVolumeHob
.FirmwareVolume
->BaseAddress
;
979 *Length
= FirmwareVolumeHob
.FirmwareVolume
->Length
;
981 *HobStart
= GET_NEXT_HOB (FirmwareVolumeHob
);
990 IN OUT VOID
**HobStart
,
993 OUT UINTN
*BufferSize OPTIONAL
998 Get the next guid hob.
1001 HobStart A pointer to the start hob.
1002 Guid A pointer to a guid.
1003 Buffer A pointer to the buffer.
1004 BufferSize Buffer size.
1009 EFI_NOT_FOUND - Next Guid hob not found
1011 EFI_SUCCESS - Next Guid hob found and data for this Guid got
1013 EFI_INVALID_PARAMETER - invalid parameter
1019 // This library interface is changed substantially with R9 counerpart GetNextGuidHob ().
1020 // 1. R9 GetNextGuidHob has two parameters and returns the matched GUID HOB from the StartHob.
1021 // 2. R9 GetNextGuidHob does not strip the HOB header, so caller is required to apply
1022 // GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE () to extract the data section and its
1023 // size info respectively.
1024 // 3. this function does not skip the starting HOB pointer unconditionally:
1025 // it returns HobStart back if HobStart itself meets the requirement;
1026 // caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
1028 EFI_PEI_HOB_POINTERS GuidHob
;
1030 if (Buffer
== NULL
) {
1031 return EFI_INVALID_PARAMETER
;
1034 GuidHob
.Raw
= GetNextGuidHob (Guid
, *HobStart
);
1035 if (GuidHob
== NULL
) {
1036 return EFI_NOT_FOUND
;
1039 *Buffer
= GET_GUID_HOB_DATA (GuidHob
.Guid
);
1040 if (BufferSize
!= NULL
) {
1041 *BufferSize
= GET_GUID_HOB_DATA_SIZE (GuidHob
.Guid
);
1044 *HobStart
= GET_NEXT_HOB (GuidHob
);
1052 R8_GetPalEntryHobInfo (
1054 OUT EFI_PHYSICAL_ADDRESS
*PalEntry
1058 Routine Description:
1060 Get PAL entry from PalEntryHob
1064 HobStart - Start pointer of hob list
1066 PalEntry - Pointer to PAL entry
1074 EFI_HOB_GUID_TYPE
*GuidHob
;
1076 GuidHob
= GetNextGuidHob (&gPalEntryHob
, HobStart
);
1078 if (GuidHob
== NULL
) {
1079 return EFI_NOT_FOUND
;
1082 *PalEntry
= *((EFI_PHYSICAL_ADDRESS
*) GET_GUID_HOB_DATA (GuidHob
));
1089 R8_GetIoPortSpaceAddressHobInfo (
1091 OUT EFI_PHYSICAL_ADDRESS
*IoPortSpaceAddress
1095 Routine Description:
1097 Get IO port space address from IoBaseHob.
1101 HobStart - Start pointer of hob list
1103 IoPortSpaceAddress - IO port space address
1113 // This library interface is simply obsolete.
1114 // Include the source code to user code.
1116 EFI_HOB_GUID_TYPE
*GuidHob
;
1118 GuidHob
= GetNextGuidHob (&gEfiIoBaseHobGuid
, HobStart
);
1120 if (GuidHob
== NULL
) {
1121 return EFI_NOT_FOUND
;
1124 *IoPortSpaceAddress
= *((EFI_PHYSICAL_ADDRESS
*) GET_GUID_HOB_DATA (GuidHob
));