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()
52 //EfiInitializeDriverLib (ImageHandle, SystemTable);
54 DriverBinding
->ImageHandle
= ImageHandle
;
56 DriverBinding
->DriverBindingHandle
= DriverBindingHandle
;
58 return gBS
->InstallProtocolInterface (
59 &DriverBinding
->DriverBindingHandle
,
60 &gEfiDriverBindingProtocolGuid
,
69 R8_EfiLibInstallAllDriverProtocols (
70 IN EFI_HANDLE ImageHandle
,
71 IN EFI_SYSTEM_TABLE
* SystemTable
,
72 IN EFI_DRIVER_BINDING_PROTOCOL
* DriverBinding
,
73 IN EFI_HANDLE DriverBindingHandle
,
74 IN EFI_COMPONENT_NAME_PROTOCOL
* ComponentName
, OPTIONAL
75 IN EFI_DRIVER_CONFIGURATION_PROTOCOL
* DriverConfiguration
, OPTIONAL
76 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
* DriverDiagnostics OPTIONAL
82 Intialize a driver by installing the Driver Binding Protocol onto the
83 driver's DriverBindingHandle. This is typically the same as the driver's
84 ImageHandle, but it can be different if the driver produces multiple
85 DriverBinding Protocols. This function also initializes the EFI Driver
86 Library that initializes the global variables gST, gBS, gRT.
90 ImageHandle - The image handle of the driver
92 SystemTable - The EFI System Table that was passed to the driver's entry point
94 DriverBinding - A Driver Binding Protocol instance that this driver is producing
96 DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this
97 parameter is NULL, then a new handle is created.
99 ComponentName - A Component Name Protocol instance that this driver is producing
101 DriverConfiguration - A Driver Configuration Protocol instance that this driver is producing
103 DriverDiagnostics - A Driver Diagnostics Protocol instance that this driver is producing
107 EFI_SUCCESS if all the protocols were installed onto DriverBindingHandle
109 Otherwise, then return status from gBS->InstallProtocolInterface()
115 Status
= R8_EfiLibInstallDriverBinding (ImageHandle
, SystemTable
, DriverBinding
, DriverBindingHandle
);
116 if (EFI_ERROR (Status
)) {
120 if (ComponentName
!= NULL
) {
121 Status
= gBS
->InstallProtocolInterface (
122 &DriverBinding
->DriverBindingHandle
,
123 &gEfiComponentNameProtocolGuid
,
124 EFI_NATIVE_INTERFACE
,
127 if (EFI_ERROR (Status
)) {
132 if (DriverConfiguration
!= NULL
) {
133 Status
= gBS
->InstallProtocolInterface (
134 &DriverBinding
->DriverBindingHandle
,
135 &gEfiDriverConfigurationProtocolGuid
,
136 EFI_NATIVE_INTERFACE
,
139 if (EFI_ERROR (Status
)) {
144 if (DriverDiagnostics
!= NULL
) {
145 Status
= gBS
->InstallProtocolInterface (
146 &DriverBinding
->DriverBindingHandle
,
147 &gEfiDriverDiagnosticsProtocolGuid
,
148 EFI_NATIVE_INTERFACE
,
151 if (EFI_ERROR (Status
)) {
162 R8_EfiLibCompareLanguage (
170 Compare whether two names of languages are identical.
174 Language1 - Name of language 1
175 Language2 - Name of language 2
186 for (Index
= 0; Index
< 3; Index
++) {
187 if (Language1
[Index
] != Language2
[Index
]) {
200 IN OUT UINTN
*HexStringBufferLength
,
207 Converts binary buffer to Unicode string.
208 At a minimum, any blob of data could be represented as a hex string.
211 Str - Pointer to the string.
212 HexStringBufferLength - Length in bytes of buffer to hold the hex string. Includes tailing '\0' character.
213 If routine return with EFI_SUCCESS, containing length of hex string buffer.
214 If routine return with EFI_BUFFER_TOO_SMALL, containg length of hex string buffer desired.
215 Buf - Buffer to be converted from.
216 Len - Length in bytes of the buffer to be converted.
219 EFI_SUCCESS: Routine success.
220 EFI_BUFFER_TOO_SMALL: The hex string buffer is too small.
229 // Make sure string is either passed or allocate enough.
230 // It takes 2 Unicode characters (4 bytes) to represent 1 byte of the binary buffer.
231 // Plus the Unicode termination character.
234 if (StrLen
> ((*HexStringBufferLength
) - 1)) {
235 *HexStringBufferLength
= StrLen
+ 1;
236 return EFI_BUFFER_TOO_SMALL
;
239 *HexStringBufferLength
= StrLen
+ 1;
245 for (Idx
= 0; Idx
< Len
; Idx
++) {
248 Str
[StrLen
- 1 - Idx
* 2] = NibbleToHexChar (Byte
);
249 Str
[StrLen
- 2 - Idx
* 2] = NibbleToHexChar ((UINT8
)(Byte
>> 4));
266 Removes (trims) specified leading and trailing characters from a string.
270 str - Pointer to the null-terminated string to be trimmed. On return,
271 str will hold the trimmed string.
272 CharC - Character will be trimmed from str.
286 // Trim off the leading and trailing characters c
288 for (p1
= str
; *p1
&& *p1
== CharC
; p1
++) {
308 for (p1
= str
+ StrLen(str
) - 1; p1
>= str
&& *p1
== CharC
; p1
--) {
311 if (p1
!= str
+ StrLen(str
) - 1) {
319 R8_EfiValueToHexStr (
320 IN OUT CHAR16
*Buffer
,
329 VSPrint worker function that prints a Value as a hex number in Buffer
333 Buffer - Location to place ascii hex string of Value.
335 Value - Hex value to convert to a string in Buffer.
337 Flags - Flags to use in printing Hex string, see file header for details.
339 Width - Width of hex value.
343 Number of characters printed.
347 CHAR16 TempBuffer
[MAXIMUM_VALUE_CHARACTERS
];
354 TempStr
= TempBuffer
;
358 // Count starts at one since we will null terminate. Each iteration of the
359 // loop picks off one nibble. Oh yea TempStr ends up backwards
363 if (Width
> MAXIMUM_VALUE_CHARACTERS
- 1) {
364 Width
= MAXIMUM_VALUE_CHARACTERS
- 1;
369 // If Width == 0, it means no limit.
371 if ((Width
!= 0) && (Count
>= Width
)) {
375 Index
= ((UINTN
)Value
& 0xf);
376 *(TempStr
++) = mHexStr
[Index
];
377 Value
= RShiftU64 (Value
, 4);
379 } while (Value
!= 0);
381 if (Flags
& PREFIX_ZERO
) {
388 if (!(Flags
& LEFT_JUSTIFY
)) {
389 for (; Index
< Width
; Index
++) {
390 *(TempStr
++) = Prefix
;
395 // Reverse temp string into Buffer.
397 while (TempStr
!= TempBuffer
) {
398 *(BufferPtr
++) = *(--TempStr
);
414 OUT UINTN
*ConvertedStrLen OPTIONAL
419 Converts Unicode string to binary buffer.
420 The conversion may be partial.
421 The first character in the string that is not hex digit stops the conversion.
422 At a minimum, any blob of data could be represented as a hex string.
425 Buf - Pointer to buffer that receives the data.
426 Len - Length in bytes of the buffer to hold converted data.
427 If routine return with EFI_SUCCESS, containing length of converted data.
428 If routine return with EFI_BUFFER_TOO_SMALL, containg length of buffer desired.
429 Str - String to be converted from.
430 ConvertedStrLen - Length of the Hex String consumed.
433 EFI_SUCCESS: Routine Success.
434 EFI_BUFFER_TOO_SMALL: The buffer is too small to hold converted data.
446 // Find out how many hex characters the string has.
448 for (Idx
= 0, HexCnt
= 0; IsHexDigit (&Digit
, Str
[Idx
]); Idx
++, HexCnt
++);
455 // Two Unicode characters make up 1 buffer byte. Round up.
457 BufferLength
= (HexCnt
+ 1) / 2;
460 // Test if buffer is passed enough.
462 if (BufferLength
> (*Len
)) {
464 return EFI_BUFFER_TOO_SMALL
;
469 for (Idx
= 0; Idx
< HexCnt
; Idx
++) {
471 IsHexDigit (&Digit
, Str
[HexCnt
- 1 - Idx
]);
474 // For odd charaters, write the lower nibble for each buffer byte,
475 // and for even characters, the upper nibble.
477 if ((Idx
& 1) == 0) {
488 if (ConvertedStrLen
!= NULL
) {
489 *ConvertedStrLen
= HexCnt
;
505 Determines if a Unicode character is a hexadecimal digit.
506 The test is case insensitive.
509 Digit - Pointer to byte that receives the value of the hex character.
510 Char - Unicode character to test.
513 TRUE - If the character is a hexadecimal digit.
518 if ((Char
>= L
'0') && (Char
<= L
'9')) {
519 *Digit
= (UINT8
) (Char
- L
'0');
523 if ((Char
>= L
'A') && (Char
<= L
'F')) {
524 *Digit
= (UINT8
) (Char
- L
'A' + 0x0A);
528 if ((Char
>= L
'a') && (Char
<= L
'f')) {
529 *Digit
= (UINT8
) (Char
- L
'a' + 0x0A);
545 Converts the low nibble of a byte to hex unicode character.
548 Nibble - lower nibble of a byte.
551 Hex unicode character.
557 return (CHAR16
)(Nibble
+ L
'0');
560 return (CHAR16
)(Nibble
- 0xA + L
'A');
574 This function returns the first instance of a HOB type in a HOB list.
578 Type The HOB type to return.
579 HobStart The first HOB in the HOB list.
583 HobStart There were no HOBs found with the requested type.
584 else Returns the first HOB with the matching type.
590 // Return input if not found
592 if (HobStart
== NULL
) {
595 Hob
= GetNextHob (Type
, HobStart
);
613 Get size of hob list.
617 HobStart - Start pointer of hob list
625 EFI_PEI_HOB_POINTERS Hob
;
631 while (Hob
.Header
->HobType
!= EFI_HOB_TYPE_END_OF_HOB_LIST
) {
632 Size
+= Hob
.Header
->HobLength
;
633 Hob
.Raw
+= Hob
.Header
->HobLength
;
636 Size
+= Hob
.Header
->HobLength
;
655 HobStart - Start pointer of hob list
663 EFI_PEI_HOB_POINTERS Hob
;
666 return Hob
.HandoffInformationTable
->Version
;
674 OUT EFI_BOOT_MODE
*BootMode
680 Get current boot mode.
684 HobStart - Start pointer of hob list
686 BootMode - Current boot mode recorded in PHIT hob
690 EFI_NOT_FOUND - Invalid hob header
692 EFI_SUCCESS - Boot mode found
696 EFI_PEI_HOB_POINTERS Hob
;
699 if (Hob
.Header
->HobType
!= EFI_HOB_TYPE_HANDOFF
) {
700 return EFI_NOT_FOUND
;
703 *BootMode
= Hob
.HandoffInformationTable
->BootMode
;
713 OUT UINT8
*SizeOfMemorySpace
,
714 OUT UINT8
*SizeOfIoSpace
720 Get information recorded in CPU hob (Memory space size, Io space size)
724 HobStart - Start pointer of hob list
726 SizeOfMemorySpace - Size of memory size
728 SizeOfIoSpace - Size of IO size
732 EFI_NOT_FOUND - CPU hob not found
734 EFI_SUCCESS - CPU hob found and information got.
740 CpuHob
= GetHob (EFI_HOB_TYPE_CPU
, HobStart
);
741 if (CpuHob
== NULL
) {
742 return EFI_NOT_FOUND
;
745 *SizeOfMemorySpace
= CpuHob
->SizeOfMemorySpace
;
746 *SizeOfIoSpace
= CpuHob
->SizeOfIoSpace
;
753 R8_GetDxeCoreHobInfo (
755 OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
757 OUT VOID
**EntryPoint
,
758 OUT EFI_GUID
**FileName
764 Get memory allocation hob created for DXE core and extract its information
768 HobStart - Start pointer of the hob list
769 BaseAddress - Start address of memory allocated for DXE core
770 Length - Length of memory allocated for DXE core
771 EntryPoint - DXE core file name
776 EFI_NOT_FOUND - DxeCoreHob not found
777 EFI_SUCCESS - DxeCoreHob found and information got
781 EFI_PEI_HOB_POINTERS DxeCoreHob
;
783 DxeCoreHob
.Raw
= HobStart
;
784 DxeCoreHob
.Raw
= GetHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, DxeCoreHob
.Raw
);
785 while (DxeCoreHob
.Header
->HobType
== EFI_HOB_TYPE_MEMORY_ALLOCATION
&&
786 !EfiCompareGuid (&DxeCoreHob
.MemoryAllocationModule
->MemoryAllocationHeader
.Name
,
787 &gEfiHobMemeryAllocModuleGuid
)) {
789 DxeCoreHob
.Raw
= GET_NEXT_HOB (DxeCoreHob
);
790 DxeCoreHob
.Raw
= GetHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, DxeCoreHob
.Raw
);
794 if (DxeCoreHob
.Header
->HobType
!= EFI_HOB_TYPE_MEMORY_ALLOCATION
) {
795 return EFI_NOT_FOUND
;
798 *BaseAddress
= DxeCoreHob
.MemoryAllocationModule
->MemoryAllocationHeader
.MemoryBaseAddress
;
799 *Length
= DxeCoreHob
.MemoryAllocationModule
->MemoryAllocationHeader
.MemoryLength
;
800 *EntryPoint
= (VOID
*) (UINTN
) DxeCoreHob
.MemoryAllocationModule
->EntryPoint
;
801 *FileName
= &DxeCoreHob
.MemoryAllocationModule
->ModuleName
;
809 R8_GetNextFirmwareVolumeHob (
810 IN OUT VOID
**HobStart
,
811 OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
818 Get next firmware volume hob from HobStart
822 HobStart - Start pointer of hob list
824 BaseAddress - Start address of next firmware volume
826 Length - Length of next firmware volume
830 EFI_NOT_FOUND - Next firmware volume not found
832 EFI_SUCCESS - Next firmware volume found with address information
836 EFI_PEI_HOB_POINTERS FirmwareVolumeHob
;
838 FirmwareVolumeHob
.Raw
= GetNextHob (EFI_HOB_TYPE_FV
, *HobStart
);
839 if (FirmwareVolumeHob
.Raw
!= NULL
) {
840 return EFI_NOT_FOUND
;
843 *BaseAddress
= FirmwareVolumeHob
.FirmwareVolume
->BaseAddress
;
844 *Length
= FirmwareVolumeHob
.FirmwareVolume
->Length
;
846 *HobStart
= GET_NEXT_HOB (FirmwareVolumeHob
);
855 IN OUT VOID
**HobStart
,
858 OUT UINTN
*BufferSize OPTIONAL
863 Get the next guid hob.
866 HobStart A pointer to the start hob.
867 Guid A pointer to a guid.
868 Buffer A pointer to the buffer.
869 BufferSize Buffer size.
874 EFI_NOT_FOUND - Next Guid hob not found
876 EFI_SUCCESS - Next Guid hob found and data for this Guid got
878 EFI_INVALID_PARAMETER - invalid parameter
882 EFI_PEI_HOB_POINTERS GuidHob
;
884 if (Buffer
== NULL
) {
885 return EFI_INVALID_PARAMETER
;
888 GuidHob
.Raw
= GetNextGuidHob (Guid
, *HobStart
);
889 if (GuidHob
== NULL
) {
890 return EFI_NOT_FOUND
;
893 *Buffer
= GET_GUID_HOB_DATA (GuidHob
.Guid
);
894 if (BufferSize
!= NULL
) {
895 *BufferSize
= GET_GUID_HOB_DATA_SIZE (GuidHob
.Guid
);
898 *HobStart
= GET_NEXT_HOB (GuidHob
);
906 R8_GetPalEntryHobInfo (
908 OUT EFI_PHYSICAL_ADDRESS
*PalEntry
914 Get PAL entry from PalEntryHob
918 HobStart - Start pointer of hob list
920 PalEntry - Pointer to PAL entry
928 EFI_HOB_GUID_TYPE
*GuidHob
;
930 GuidHob
= GetNextGuidHob (&gPalEntryHob
, HobStart
);
932 if (GuidHob
== NULL
) {
933 return EFI_NOT_FOUND
;
936 *PalEntry
= *((EFI_PHYSICAL_ADDRESS
*) GET_GUID_HOB_DATA (GuidHob
));
943 R8_GetIoPortSpaceAddressHobInfo (
945 OUT EFI_PHYSICAL_ADDRESS
*IoPortSpaceAddress
951 Get IO port space address from IoBaseHob.
955 HobStart - Start pointer of hob list
957 IoPortSpaceAddress - IO port space address
965 EFI_HOB_GUID_TYPE
*GuidHob
;
967 GuidHob
= GetNextGuidHob (&gEfiIoBaseHobGuid
, HobStart
);
969 if (GuidHob
== NULL
) {
970 return EFI_NOT_FOUND
;
973 *IoPortSpaceAddress
= *((EFI_PHYSICAL_ADDRESS
*) GET_GUID_HOB_DATA (GuidHob
));