HobLib.c revision 3eb9473ea9a949badfe06ae61d2d3fcfa53651c7
1/*++
2
3Copyright (c) 2004 - 2006, Intel Corporation
4All rights reserved. This program and the accompanying materials
5are licensed and made available under the terms and conditions of the BSD License
6which accompanies this distribution.  The full text of the license may be found at
7http://opensource.org/licenses/bsd-license.php
8
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12
13Module Name:
14
15  HobLib.c
16
17Abstract:
18
19  HOB Library.
20
21--*/
22
23#include "EdkIIGlueDxe.h"
24
25
26STATIC VOID  *mHobList = NULL;
27
28/**
29  The constructor function caches the pointer to HOB list.
30
31  The constructor function gets the start address of HOB list from system configuration table.
32  It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
33
34  @param  ImageHandle   The firmware allocated handle for the EFI image.
35  @param  SystemTable   A pointer to the EFI System Table.
36
37  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.
38
39**/
40EFI_STATUS
41EFIAPI
42HobLibConstructor (
43  IN EFI_HANDLE        ImageHandle,
44  IN EFI_SYSTEM_TABLE  *SystemTable
45  )
46{
47  EFI_STATUS  Status;
48
49  Status = EfiGetSystemConfigurationTable (&gEfiHobListGuid, &mHobList);
50  ASSERT_EFI_ERROR (Status);
51  ASSERT (mHobList != NULL);
52  return Status;
53}
54
55/**
56  Returns the pointer to the HOB list.
57
58  This function returns the pointer to first HOB in the list.
59
60  @return The pointer to the HOB list.
61
62**/
63VOID *
64EFIAPI
65GetHobList (
66  VOID
67  )
68{
69  return mHobList;
70}
71
72/**
73  Returns the next instance of a HOB type from the starting HOB.
74
75  This function searches the first instance of a HOB type from the starting HOB pointer.
76  If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
77  In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
78  unconditionally: it returns HobStart back if HobStart itself meets the requirement;
79  caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
80  If HobStart is NULL, then ASSERT().
81
82  @param  Type          The HOB type to return.
83  @param  HobStart      The starting HOB pointer to search from.
84
85  @return The next instance of a HOB type from the starting HOB.
86
87**/
88VOID *
89EFIAPI
90GetNextHob (
91  IN UINT16                 Type,
92  IN CONST VOID             *HobStart
93  )
94{
95  EFI_PEI_HOB_POINTERS  Hob;
96
97  ASSERT (HobStart != NULL);
98
99  Hob.Raw = (UINT8 *) HobStart;
100  //
101  // Parse the HOB list until end of list or matching type is found.
102  //
103  while (!END_OF_HOB_LIST (Hob)) {
104    if (Hob.Header->HobType == Type) {
105      return Hob.Raw;
106    }
107    Hob.Raw = GET_NEXT_HOB (Hob);
108  }
109  return NULL;
110}
111
112/**
113  Returns the first instance of a HOB type among the whole HOB list.
114
115  This function searches the first instance of a HOB type among the whole HOB list.
116  If there does not exist such HOB type in the HOB list, it will return NULL.
117
118  @param  Type          The HOB type to return.
119
120  @return The next instance of a HOB type from the starting HOB.
121
122**/
123VOID *
124EFIAPI
125GetFirstHob (
126  IN UINT16                 Type
127  )
128{
129  VOID      *HobList;
130
131  HobList = GetHobList ();
132  return GetNextHob (Type, HobList);
133}
134
135/**
136  This function searches the first instance of a HOB from the starting HOB pointer.
137  Such HOB should satisfy two conditions:
138  its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
139  If there does not exist such HOB from the starting HOB pointer, it will return NULL.
140  Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
141  to extract the data section and its size info respectively.
142  In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
143  unconditionally: it returns HobStart back if HobStart itself meets the requirement;
144  caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
145  If Guid is NULL, then ASSERT().
146  If HobStart is NULL, then ASSERT().
147
148  @param  Guid          The GUID to match with in the HOB list.
149  @param  HobStart      A pointer to a Guid.
150
151  @return The next instance of the matched GUID HOB from the starting HOB.
152
153**/
154VOID *
155EFIAPI
156GlueGetNextGuidHob (
157  IN CONST EFI_GUID         *Guid,
158  IN CONST VOID             *HobStart
159  )
160{
161  EFI_PEI_HOB_POINTERS  GuidHob;
162
163  GuidHob.Raw = (UINT8 *) HobStart;
164  while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {
165    if (CompareGuid (Guid, &GuidHob.Guid->Name)) {
166      break;
167    }
168    GuidHob.Raw = GET_NEXT_HOB (GuidHob);
169  }
170  return GuidHob.Raw;
171}
172
173/**
174  This function searches the first instance of a HOB among the whole HOB list.
175  Such HOB should satisfy two conditions:
176  its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
177  If there does not exist such HOB from the starting HOB pointer, it will return NULL.
178  Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
179  to extract the data section and its size info respectively.
180  If Guid is NULL, then ASSERT().
181
182  @param  Guid          The GUID to match with in the HOB list.
183
184  @return The first instance of the matched GUID HOB among the whole HOB list.
185
186**/
187VOID *
188EFIAPI
189GlueGetFirstGuidHob (
190  IN CONST EFI_GUID         *Guid
191  )
192{
193  VOID      *HobList;
194
195  HobList = GetHobList ();
196  return GetNextGuidHob (Guid, HobList);
197}
198
199/**
200  Get the Boot Mode from the HOB list.
201
202  This function returns the system boot mode information from the
203  PHIT HOB in HOB list.
204
205  @param  VOID
206
207  @return The Boot Mode.
208
209**/
210EFI_BOOT_MODE
211EFIAPI
212GetBootModeHob (
213  VOID
214  )
215{
216  EFI_HOB_HANDOFF_INFO_TABLE    *HandOffHob;
217
218  HandOffHob = (EFI_HOB_HANDOFF_INFO_TABLE *) GetHobList ();
219
220  return  HandOffHob->BootMode;
221}
222
223/**
224  Builds a HOB for a loaded PE32 module.
225
226  This function builds a HOB for a loaded PE32 module.
227  It can only be invoked during PEI phase;
228  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
229  If ModuleName is NULL, then ASSERT().
230  If there is no additional space for HOB creation, then ASSERT().
231
232  @param  ModuleName              The GUID File Name of the module.
233  @param  MemoryAllocationModule  The 64 bit physical address of the module.
234  @param  ModuleLength            The length of the module in bytes.
235  @param  EntryPoint              The 64 bit physical address of the module's entry point.
236
237**/
238VOID
239EFIAPI
240GlueBuildModuleHob (
241  IN CONST EFI_GUID         *ModuleName,
242  IN EFI_PHYSICAL_ADDRESS   MemoryAllocationModule,
243  IN UINT64                 ModuleLength,
244  IN EFI_PHYSICAL_ADDRESS   EntryPoint
245  )
246{
247  //
248  // PEI HOB is read only for DXE phase
249  //
250  ASSERT (FALSE);
251}
252
253/**
254  Builds a HOB that describes a chunk of system memory.
255
256  This function builds a HOB that describes a chunk of system memory.
257  It can only be invoked during PEI phase;
258  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
259  If there is no additional space for HOB creation, then ASSERT().
260
261  @param  ResourceType        The type of resource described by this HOB.
262  @param  ResourceAttribute   The resource attributes of the memory described by this HOB.
263  @param  PhysicalStart       The 64 bit physical address of memory described by this HOB.
264  @param  NumberOfBytes       The length of the memory described by this HOB in bytes.
265
266**/
267VOID
268EFIAPI
269BuildResourceDescriptorHob (
270  IN EFI_RESOURCE_TYPE            ResourceType,
271  IN EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttribute,
272  IN EFI_PHYSICAL_ADDRESS         PhysicalStart,
273  IN UINT64                       NumberOfBytes
274  )
275{
276  //
277  // PEI HOB is read only for DXE phase
278  //
279  ASSERT (FALSE);
280}
281
282/**
283  Builds a GUID HOB with a certain data length.
284
285  This function builds a customized HOB tagged with a GUID for identification
286  and returns the start address of GUID HOB data so that caller can fill the customized data.
287  The HOB Header and Name field is already stripped.
288  It can only be invoked during PEI phase;
289  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
290  If Guid is NULL, then ASSERT().
291  If there is no additional space for HOB creation, then ASSERT().
292  If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
293
294  @param  Guid          The GUID to tag the customized HOB.
295  @param  DataLength    The size of the data payload for the GUID HOB.
296
297  @return The start address of GUID HOB data.
298
299**/
300VOID *
301EFIAPI
302BuildGuidHob (
303  IN CONST EFI_GUID              *Guid,
304  IN UINTN                       DataLength
305  )
306{
307  //
308  // PEI HOB is read only for DXE phase
309  //
310  ASSERT (FALSE);
311  return NULL;
312}
313
314/**
315  Copies a data buffer to a newly-built HOB.
316
317  This function builds a customized HOB tagged with a GUID for identification,
318  copies the input data to the HOB data field and returns the start address of the GUID HOB data.
319  The HOB Header and Name field is already stripped.
320  It can only be invoked during PEI phase;
321  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
322  If Guid is NULL, then ASSERT().
323  If Data is NULL and DataLength > 0, then ASSERT().
324  If there is no additional space for HOB creation, then ASSERT().
325  If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
326
327  @param  Guid          The GUID to tag the customized HOB.
328  @param  Data          The data to be copied into the data field of the GUID HOB.
329  @param  DataLength    The size of the data payload for the GUID HOB.
330
331  @return The start address of GUID HOB data.
332
333**/
334VOID *
335EFIAPI
336BuildGuidDataHob (
337  IN CONST EFI_GUID              *Guid,
338  IN VOID                        *Data,
339  IN UINTN                       DataLength
340  )
341{
342  //
343  // PEI HOB is read only for DXE phase
344  //
345  ASSERT (FALSE);
346  return NULL;
347}
348
349/**
350  Builds a Firmware Volume HOB.
351
352  This function builds a Firmware Volume HOB.
353  It can only be invoked during PEI phase;
354  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
355  If there is no additional space for HOB creation, then ASSERT().
356
357  @param  BaseAddress   The base address of the Firmware Volume.
358  @param  Length        The size of the Firmware Volume in bytes.
359
360**/
361VOID
362EFIAPI
363BuildFvHob (
364  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
365  IN UINT64                      Length
366  )
367{
368  //
369  // PEI HOB is read only for DXE phase
370  //
371  ASSERT (FALSE);
372}
373
374/**
375  Builds a Capsule Volume HOB.
376
377  This function builds a Capsule Volume HOB.
378  It can only be invoked during PEI phase;
379  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
380  If there is no additional space for HOB creation, then ASSERT().
381
382  @param  BaseAddress   The base address of the Capsule Volume.
383  @param  Length        The size of the Capsule Volume in bytes.
384
385**/
386VOID
387EFIAPI
388BuildCvHob (
389  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
390  IN UINT64                      Length
391  )
392{
393  //
394  // PEI HOB is read only for DXE phase
395  //
396  ASSERT (FALSE);
397}
398
399/**
400  Builds a HOB for the CPU.
401
402  This function builds a HOB for the CPU.
403  It can only be invoked during PEI phase;
404  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
405  If there is no additional space for HOB creation, then ASSERT().
406
407  @param  SizeOfMemorySpace   The maximum physical memory addressability of the processor.
408  @param  SizeOfIoSpace       The maximum physical I/O addressability of the processor.
409
410**/
411VOID
412EFIAPI
413BuildCpuHob (
414  IN UINT8                       SizeOfMemorySpace,
415  IN UINT8                       SizeOfIoSpace
416  )
417{
418  //
419  // PEI HOB is read only for DXE phase
420  //
421  ASSERT (FALSE);
422}
423
424/**
425  Builds a HOB for the Stack.
426
427  This function builds a HOB for the stack.
428  It can only be invoked during PEI phase;
429  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
430  If there is no additional space for HOB creation, then ASSERT().
431
432  @param  BaseAddress   The 64 bit physical address of the Stack.
433  @param  Length        The length of the stack in bytes.
434
435**/
436VOID
437EFIAPI
438BuildStackHob (
439  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
440  IN UINT64                      Length
441  )
442{
443  //
444  // PEI HOB is read only for DXE phase
445  //
446  ASSERT (FALSE);
447}
448
449/**
450  Builds a HOB for the BSP store.
451
452  This function builds a HOB for BSP store.
453  It can only be invoked during PEI phase;
454  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
455  If there is no additional space for HOB creation, then ASSERT().
456
457  @param  BaseAddress   The 64 bit physical address of the BSP.
458  @param  Length        The length of the BSP store in bytes.
459  @param  MemoryType    Type of memory allocated by this HOB.
460
461**/
462VOID
463EFIAPI
464BuildBspStoreHob (
465  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
466  IN UINT64                      Length,
467  IN EFI_MEMORY_TYPE             MemoryType
468  )
469{
470  //
471  // PEI HOB is read only for DXE phase
472  //
473  ASSERT (FALSE);
474}
475
476/**
477  Builds a HOB for the memory allocation.
478
479  This function builds a HOB for the memory allocation.
480  It can only be invoked during PEI phase;
481  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
482  If there is no additional space for HOB creation, then ASSERT().
483
484  @param  BaseAddress   The 64 bit physical address of the memory.
485  @param  Length        The length of the memory allocation in bytes.
486  @param  MemoryType    Type of memory allocated by this HOB.
487
488**/
489VOID
490EFIAPI
491GlueBuildMemoryAllocationHob (
492  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
493  IN UINT64                      Length,
494  IN EFI_MEMORY_TYPE             MemoryType
495  )
496{
497  //
498  // PEI HOB is read only for DXE phase
499  //
500  ASSERT (FALSE);
501}
502