2
HOB Library implemenation for Dxe Phase.
4
Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
5
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
#include <Guid/HobList.h>
19
#include <Library/HobLib.h>
20
#include <Library/UefiLib.h>
21
#include <Library/DebugLib.h>
22
#include <Library/BaseMemoryLib.h>
24
VOID *mHobList = NULL;
27
The constructor function caches the pointer to HOB list.
29
The constructor function gets the start address of HOB list from system configuration table.
30
It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
32
@param ImageHandle The firmware allocated handle for the EFI image.
33
@param SystemTable A pointer to the EFI System Table.
35
@retval EFI_SUCCESS The constructor successfully gets HobList.
36
@retval Other value The constructor can't get HobList.
42
IN EFI_HANDLE ImageHandle,
43
IN EFI_SYSTEM_TABLE *SystemTable
48
Status = EfiGetSystemConfigurationTable (&gEfiHobListGuid, &mHobList);
49
ASSERT_EFI_ERROR (Status);
50
ASSERT (mHobList != NULL);
56
Returns the pointer to the HOB list.
58
This function returns the pointer to first HOB in the list.
59
For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer
60
to the HOB list. For the DXE phase, the HOB list pointer can be retrieved through
61
the EFI System Table by looking up theHOB list GUID in the System Configuration Table.
62
Since the System Configuration Table does not exist that the time the DXE Core is
63
launched, the DXE Core uses a global variable from the DXE Core Entry Point Library
64
to manage the pointer to the HOB list.
66
If the pointer to the HOB list is NULL, then ASSERT().
68
@return The pointer to the HOB list.
77
ASSERT (mHobList != NULL);
82
Returns the next instance of a HOB type from the starting HOB.
84
This function searches the first instance of a HOB type from the starting HOB pointer.
85
If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
86
In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
87
unconditionally: it returns HobStart back if HobStart itself meets the requirement;
88
caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
90
If HobStart is NULL, then ASSERT().
92
@param Type The HOB type to return.
93
@param HobStart The starting HOB pointer to search from.
95
@return The next instance of a HOB type from the starting HOB.
102
IN CONST VOID *HobStart
105
EFI_PEI_HOB_POINTERS Hob;
107
ASSERT (HobStart != NULL);
109
Hob.Raw = (UINT8 *) HobStart;
111
// Parse the HOB list until end of list or matching type is found.
113
while (!END_OF_HOB_LIST (Hob)) {
114
if (Hob.Header->HobType == Type) {
117
Hob.Raw = GET_NEXT_HOB (Hob);
123
Returns the first instance of a HOB type among the whole HOB list.
125
This function searches the first instance of a HOB type among the whole HOB list.
126
If there does not exist such HOB type in the HOB list, it will return NULL.
128
If the pointer to the HOB list is NULL, then ASSERT().
130
@param Type The HOB type to return.
132
@return The next instance of a HOB type from the starting HOB.
143
HobList = GetHobList ();
144
return GetNextHob (Type, HobList);
148
Returns the next instance of the matched GUID HOB from the starting HOB.
150
This function searches the first instance of a HOB from the starting HOB pointer.
151
Such HOB should satisfy two conditions:
152
its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
153
If there does not exist such HOB from the starting HOB pointer, it will return NULL.
154
Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
155
to extract the data section and its size information, respectively.
156
In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
157
unconditionally: it returns HobStart back if HobStart itself meets the requirement;
158
caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
160
If Guid is NULL, then ASSERT().
161
If HobStart is NULL, then ASSERT().
163
@param Guid The GUID to match with in the HOB list.
164
@param HobStart A pointer to a Guid.
166
@return The next instance of the matched GUID HOB from the starting HOB.
172
IN CONST EFI_GUID *Guid,
173
IN CONST VOID *HobStart
176
EFI_PEI_HOB_POINTERS GuidHob;
178
GuidHob.Raw = (UINT8 *) HobStart;
179
while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {
180
if (CompareGuid (Guid, &GuidHob.Guid->Name)) {
183
GuidHob.Raw = GET_NEXT_HOB (GuidHob);
189
Returns the first instance of the matched GUID HOB among the whole HOB list.
191
This function searches the first instance of a HOB among the whole HOB list.
192
Such HOB should satisfy two conditions:
193
its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
194
If there does not exist such HOB from the starting HOB pointer, it will return NULL.
195
Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
196
to extract the data section and its size information, respectively.
198
If the pointer to the HOB list is NULL, then ASSERT().
199
If Guid is NULL, then ASSERT().
201
@param Guid The GUID to match with in the HOB list.
203
@return The first instance of the matched GUID HOB among the whole HOB list.
209
IN CONST EFI_GUID *Guid
214
HobList = GetHobList ();
215
return GetNextGuidHob (Guid, HobList);
219
Get the system boot mode from the HOB list.
221
This function returns the system boot mode information from the
222
PHIT HOB in HOB list.
224
If the pointer to the HOB list is NULL, then ASSERT().
228
@return The Boot Mode.
237
EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
239
HandOffHob = (EFI_HOB_HANDOFF_INFO_TABLE *) GetHobList ();
241
return HandOffHob->BootMode;
245
Builds a HOB for a loaded PE32 module.
247
This function builds a HOB for a loaded PE32 module.
248
It can only be invoked during PEI phase;
249
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
251
If ModuleName is NULL, then ASSERT().
252
If there is no additional space for HOB creation, then ASSERT().
254
@param ModuleName The GUID File Name of the module.
255
@param MemoryAllocationModule The 64 bit physical address of the module.
256
@param ModuleLength The length of the module in bytes.
257
@param EntryPoint The 64 bit physical address of the module entry point.
263
IN CONST EFI_GUID *ModuleName,
264
IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,
265
IN UINT64 ModuleLength,
266
IN EFI_PHYSICAL_ADDRESS EntryPoint
270
// PEI HOB is read only for DXE phase
276
Builds a HOB that describes a chunk of system memory.
278
This function builds a HOB that describes a chunk of system memory.
279
It can only be invoked during PEI phase;
280
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
282
If there is no additional space for HOB creation, then ASSERT().
284
@param ResourceType The type of resource described by this HOB.
285
@param ResourceAttribute The resource attributes of the memory described by this HOB.
286
@param PhysicalStart The 64 bit physical address of memory described by this HOB.
287
@param NumberOfBytes The length of the memory described by this HOB in bytes.
292
BuildResourceDescriptorHob (
293
IN EFI_RESOURCE_TYPE ResourceType,
294
IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,
295
IN EFI_PHYSICAL_ADDRESS PhysicalStart,
296
IN UINT64 NumberOfBytes
300
// PEI HOB is read only for DXE phase
306
Builds a customized HOB tagged with a GUID for identification and returns
307
the start address of GUID HOB data.
309
This function builds a customized HOB tagged with a GUID for identification
310
and returns the start address of GUID HOB data so that caller can fill the customized data.
311
The HOB Header and Name field is already stripped.
312
It can only be invoked during PEI phase;
313
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
315
If Guid is NULL, then ASSERT().
316
If there is no additional space for HOB creation, then ASSERT().
317
If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
318
HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
320
@param Guid The GUID to tag the customized HOB.
321
@param DataLength The size of the data payload for the GUID HOB.
323
@retval NULL The GUID HOB could not be allocated.
324
@retval others The start address of GUID HOB data.
330
IN CONST EFI_GUID *Guid,
335
// PEI HOB is read only for DXE phase
342
Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB
343
data field, and returns the start address of the GUID HOB data.
345
This function builds a customized HOB tagged with a GUID for identification and copies the input
346
data to the HOB data field and returns the start address of the GUID HOB data. It can only be
347
invoked during PEI phase; for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
348
The HOB Header and Name field is already stripped.
349
It can only be invoked during PEI phase;
350
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
352
If Guid is NULL, then ASSERT().
353
If Data is NULL and DataLength > 0, then ASSERT().
354
If there is no additional space for HOB creation, then ASSERT().
355
If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
356
HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
358
@param Guid The GUID to tag the customized HOB.
359
@param Data The data to be copied into the data field of the GUID HOB.
360
@param DataLength The size of the data payload for the GUID HOB.
362
@retval NULL The GUID HOB could not be allocated.
363
@retval others The start address of GUID HOB data.
369
IN CONST EFI_GUID *Guid,
375
// PEI HOB is read only for DXE phase
382
Builds a Firmware Volume HOB.
384
This function builds a Firmware Volume HOB.
385
It can only be invoked during PEI phase;
386
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
388
If there is no additional space for HOB creation, then ASSERT().
390
@param BaseAddress The base address of the Firmware Volume.
391
@param Length The size of the Firmware Volume in bytes.
397
IN EFI_PHYSICAL_ADDRESS BaseAddress,
402
// PEI HOB is read only for DXE phase
408
Builds a EFI_HOB_TYPE_FV2 HOB.
410
This function builds a EFI_HOB_TYPE_FV2 HOB.
411
It can only be invoked during PEI phase;
412
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
414
If there is no additional space for HOB creation, then ASSERT().
416
@param BaseAddress The base address of the Firmware Volume.
417
@param Length The size of the Firmware Volume in bytes.
418
@param FvName The name of the Firmware Volume.
419
@param FileName The name of the file.
425
IN EFI_PHYSICAL_ADDRESS BaseAddress,
427
IN CONST EFI_GUID *FvName,
428
IN CONST EFI_GUID *FileName
436
Builds a Capsule Volume HOB.
438
This function builds a Capsule Volume HOB.
439
It can only be invoked during PEI phase;
440
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
442
If the platform does not support Capsule Volume HOBs, then ASSERT().
443
If there is no additional space for HOB creation, then ASSERT().
445
@param BaseAddress The base address of the Capsule Volume.
446
@param Length The size of the Capsule Volume in bytes.
452
IN EFI_PHYSICAL_ADDRESS BaseAddress,
457
// PEI HOB is read only for DXE phase
463
Builds a HOB for the CPU.
465
This function builds a HOB for the CPU.
466
It can only be invoked during PEI phase;
467
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
469
If there is no additional space for HOB creation, then ASSERT().
471
@param SizeOfMemorySpace The maximum physical memory addressability of the processor.
472
@param SizeOfIoSpace The maximum physical I/O addressability of the processor.
478
IN UINT8 SizeOfMemorySpace,
479
IN UINT8 SizeOfIoSpace
483
// PEI HOB is read only for DXE phase
489
Builds a HOB for the Stack.
491
This function builds a HOB for the stack.
492
It can only be invoked during PEI phase;
493
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
495
If there is no additional space for HOB creation, then ASSERT().
497
@param BaseAddress The 64 bit physical address of the Stack.
498
@param Length The length of the stack in bytes.
504
IN EFI_PHYSICAL_ADDRESS BaseAddress,
509
// PEI HOB is read only for DXE phase
515
Builds a HOB for the BSP store.
517
This function builds a HOB for BSP store.
518
It can only be invoked during PEI phase;
519
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
521
If there is no additional space for HOB creation, then ASSERT().
523
@param BaseAddress The 64 bit physical address of the BSP.
524
@param Length The length of the BSP store in bytes.
525
@param MemoryType Type of memory allocated by this HOB.
531
IN EFI_PHYSICAL_ADDRESS BaseAddress,
533
IN EFI_MEMORY_TYPE MemoryType
537
// PEI HOB is read only for DXE phase
543
Builds a HOB for the memory allocation.
545
This function builds a HOB for the memory allocation.
546
It can only be invoked during PEI phase;
547
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
549
If there is no additional space for HOB creation, then ASSERT().
551
@param BaseAddress The 64 bit physical address of the memory.
552
@param Length The length of the memory allocation in bytes.
553
@param MemoryType Type of memory allocated by this HOB.
558
BuildMemoryAllocationHob (
559
IN EFI_PHYSICAL_ADDRESS BaseAddress,
561
IN EFI_MEMORY_TYPE MemoryType
565
// PEI HOB is read only for DXE phase