3 Copyright (c) 2004 - 2006, 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 Support for hob operation
23 #include "EfiDriverLib.h"
25 #include EFI_GUID_DEFINITION (IoBaseHob)
26 #include EFI_GUID_DEFINITION (MemoryAllocationHob)
37 This function returns the first instance of a HOB type in a HOB list.
41 Type The HOB type to return.
42 HobStart The first HOB in the HOB list.
46 HobStart There were no HOBs found with the requested type.
47 else Returns the first HOB with the matching type.
51 EFI_PEI_HOB_POINTERS Hob
;
55 // Return input if not found
57 if (HobStart
== NULL
) {
62 // Parse the HOB list, stop if end of list or matching type found.
64 while (!END_OF_HOB_LIST (Hob
)) {
66 if (Hob
.Header
->HobType
== Type
) {
70 Hob
.Raw
= GET_NEXT_HOB (Hob
);
74 // Return input if not found
76 if (END_OF_HOB_LIST (Hob
)) {
80 return (VOID
*) (Hob
.Raw
);
95 HobStart - Start pointer of hob list
103 EFI_PEI_HOB_POINTERS Hob
;
109 while (Hob
.Header
->HobType
!= EFI_HOB_TYPE_END_OF_HOB_LIST
) {
110 Size
+= Hob
.Header
->HobLength
;
111 Hob
.Raw
+= Hob
.Header
->HobLength
;
114 Size
+= Hob
.Header
->HobLength
;
131 HobStart - Start pointer of hob list
139 EFI_PEI_HOB_POINTERS Hob
;
142 return Hob
.HandoffInformationTable
->Version
;
148 OUT EFI_BOOT_MODE
*BootMode
154 Get current boot mode.
158 HobStart - Start pointer of hob list
160 BootMode - Current boot mode recorded in PHIT hob
164 EFI_NOT_FOUND - Invalid hob header
166 EFI_SUCCESS - Boot mode found
170 EFI_PEI_HOB_POINTERS Hob
;
173 if (Hob
.Header
->HobType
!= EFI_HOB_TYPE_HANDOFF
) {
174 return EFI_NOT_FOUND
;
177 *BootMode
= Hob
.HandoffInformationTable
->BootMode
;
184 OUT UINT8
*SizeOfMemorySpace
,
185 OUT UINT8
*SizeOfIoSpace
191 Get information recorded in CPU hob (Memory space size, Io space size)
195 HobStart - Start pointer of hob list
197 SizeOfMemorySpace - Size of memory size
199 SizeOfIoSpace - Size of IO size
203 EFI_NOT_FOUND - CPU hob not found
205 EFI_SUCCESS - CPU hob found and information got.
209 EFI_PEI_HOB_POINTERS CpuHob
;
211 CpuHob
.Raw
= HobStart
;
212 CpuHob
.Raw
= GetHob (EFI_HOB_TYPE_CPU
, CpuHob
.Raw
);
213 if (CpuHob
.Header
->HobType
!= EFI_HOB_TYPE_CPU
) {
214 return EFI_NOT_FOUND
;
217 *SizeOfMemorySpace
= CpuHob
.Cpu
->SizeOfMemorySpace
;
218 *SizeOfIoSpace
= CpuHob
.Cpu
->SizeOfIoSpace
;
225 OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
227 OUT VOID
**EntryPoint
,
228 OUT EFI_GUID
**FileName
234 Get memory allocation hob created for DXE core and extract its information
238 HobStart - Start pointer of the hob list
239 BaseAddress - Start address of memory allocated for DXE core
240 Length - Length of memory allocated for DXE core
241 EntryPoint - DXE core file name
246 EFI_NOT_FOUND - DxeCoreHob not found
247 EFI_SUCCESS - DxeCoreHob found and information got
251 EFI_PEI_HOB_POINTERS DxeCoreHob
;
254 DxeCoreHob
.Raw
= HobStart
;
255 DxeCoreHob
.Raw
= GetHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, DxeCoreHob
.Raw
);
256 while (DxeCoreHob
.Header
->HobType
== EFI_HOB_TYPE_MEMORY_ALLOCATION
&&
257 !EfiCompareGuid (&DxeCoreHob
.MemoryAllocationModule
->MemoryAllocationHeader
.Name
,
258 &gEfiHobMemeryAllocModuleGuid
)) {
260 DxeCoreHob
.Raw
= GET_NEXT_HOB (DxeCoreHob
);
261 DxeCoreHob
.Raw
= GetHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, DxeCoreHob
.Raw
);
265 if (DxeCoreHob
.Header
->HobType
!= EFI_HOB_TYPE_MEMORY_ALLOCATION
) {
266 return EFI_NOT_FOUND
;
269 *BaseAddress
= DxeCoreHob
.MemoryAllocationModule
->MemoryAllocationHeader
.MemoryBaseAddress
;
270 *Length
= DxeCoreHob
.MemoryAllocationModule
->MemoryAllocationHeader
.MemoryLength
;
271 *EntryPoint
= (VOID
*) (UINTN
) DxeCoreHob
.MemoryAllocationModule
->EntryPoint
;
272 *FileName
= &DxeCoreHob
.MemoryAllocationModule
->ModuleName
;
278 GetNextFirmwareVolumeHob (
279 IN OUT VOID
**HobStart
,
280 OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
287 Get next firmware volume hob from HobStart
291 HobStart - Start pointer of hob list
293 BaseAddress - Start address of next firmware volume
295 Length - Length of next firmware volume
299 EFI_NOT_FOUND - Next firmware volume not found
301 EFI_SUCCESS - Next firmware volume found with address information
305 EFI_PEI_HOB_POINTERS FirmwareVolumeHob
;
307 FirmwareVolumeHob
.Raw
= *HobStart
;
308 if (END_OF_HOB_LIST (FirmwareVolumeHob
)) {
309 return EFI_NOT_FOUND
;
312 FirmwareVolumeHob
.Raw
= GetHob (EFI_HOB_TYPE_FV
, *HobStart
);
313 if (FirmwareVolumeHob
.Header
->HobType
!= EFI_HOB_TYPE_FV
) {
314 return EFI_NOT_FOUND
;
317 *BaseAddress
= FirmwareVolumeHob
.FirmwareVolume
->BaseAddress
;
318 *Length
= FirmwareVolumeHob
.FirmwareVolume
->Length
;
320 *HobStart
= GET_NEXT_HOB (FirmwareVolumeHob
);
325 #if (PI_SPECIFICATION_VERSION >= 0x00010000)
327 GetNextFirmwareVolume2Hob (
328 IN OUT VOID
**HobStart
,
329 OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
331 OUT EFI_GUID
*FileName
337 Get next firmware volume2 hob from HobStart
341 HobStart - Start pointer of hob list
343 BaseAddress - Start address of next firmware volume
345 Length - Length of next firmware volume
349 EFI_NOT_FOUND - Next firmware volume not found
351 EFI_SUCCESS - Next firmware volume found with address information
355 EFI_PEI_HOB_POINTERS FirmwareVolumeHob
;
357 FirmwareVolumeHob
.Raw
= *HobStart
;
358 if (END_OF_HOB_LIST (FirmwareVolumeHob
)) {
359 return EFI_NOT_FOUND
;
362 FirmwareVolumeHob
.Raw
= GetHob (EFI_HOB_TYPE_FV2
, *HobStart
);
363 if (FirmwareVolumeHob
.Header
->HobType
!= EFI_HOB_TYPE_FV2
) {
364 return EFI_NOT_FOUND
;
367 *BaseAddress
= FirmwareVolumeHob
.FirmwareVolume2
->BaseAddress
;
368 *Length
= FirmwareVolumeHob
.FirmwareVolume2
->Length
;
369 EfiCommonLibCopyMem(FileName
,&FirmwareVolumeHob
.FirmwareVolume2
->FileName
,sizeof(EFI_GUID
));
371 *HobStart
= GET_NEXT_HOB (FirmwareVolumeHob
);
379 IN OUT VOID
**HobStart
,
382 OUT UINTN
*BufferSize OPTIONAL
387 Get the next guid hob.
390 HobStart A pointer to the start hob.
391 Guid A pointer to a guid.
392 Buffer A pointer to the buffer.
393 BufferSize Buffer size.
398 EFI_NOT_FOUND - Next Guid hob not found
400 EFI_SUCCESS - Next Guid hob found and data for this Guid got
402 EFI_INVALID_PARAMETER - invalid parameter
407 EFI_PEI_HOB_POINTERS GuidHob
;
409 if (Buffer
== NULL
) {
410 return EFI_INVALID_PARAMETER
;
413 for (Status
= EFI_NOT_FOUND
; EFI_ERROR (Status
);) {
415 GuidHob
.Raw
= *HobStart
;
416 if (END_OF_HOB_LIST (GuidHob
)) {
417 return EFI_NOT_FOUND
;
420 GuidHob
.Raw
= GetHob (EFI_HOB_TYPE_GUID_EXTENSION
, *HobStart
);
421 if (GuidHob
.Header
->HobType
== EFI_HOB_TYPE_GUID_EXTENSION
) {
422 if (EfiCompareGuid (Guid
, &GuidHob
.Guid
->Name
)) {
423 Status
= EFI_SUCCESS
;
424 *Buffer
= (VOID
*) ((UINT8
*) (&GuidHob
.Guid
->Name
) + sizeof (EFI_GUID
));
425 if (BufferSize
!= NULL
) {
426 *BufferSize
= GuidHob
.Header
->HobLength
- sizeof (EFI_HOB_GUID_TYPE
);
431 *HobStart
= GET_NEXT_HOB (GuidHob
);
438 #define PAL_ENTRY_HOB {0xe53cb8cc, 0xd62c, 0x4f74, 0xbd, 0xda, 0x31, 0xe5, 0x8d, 0xe5, 0x3e, 0x2}
439 EFI_GUID gPalEntryHob
= PAL_ENTRY_HOB
;
444 OUT EFI_PHYSICAL_ADDRESS
*PalEntry
450 Get PAL entry from PalEntryHob
454 HobStart - Start pointer of hob list
456 PalEntry - Pointer to PAL entry
469 HobStart2
= HobStart
;
470 Status
= GetNextGuidHob (
477 *PalEntry
= *((EFI_PHYSICAL_ADDRESS
*) Buffer
);
483 GetIoPortSpaceAddressHobInfo (
485 OUT EFI_PHYSICAL_ADDRESS
*IoPortSpaceAddress
491 Get IO port space address from IoBaseHob.
495 HobStart - Start pointer of hob list
497 IoPortSpaceAddress - IO port space address
511 HobStart2
= HobStart
;
512 Status
= GetNextGuidHob (
519 *IoPortSpaceAddress
= *((EFI_PHYSICAL_ADDRESS
*) Buffer
);