1 /** @file
2   Provide Hob Library functions for build testing only.
3 
4 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2018, Linaro, Ltd. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7 
8 **/
9 
10 #include <Uefi.h>
11 #include <Pi/PiMultiPhase.h>
12 
13 #include <Library/DebugLib.h>
14 #include <Library/HobLib.h>
15 
16 /**
17   Returns the pointer to the HOB list.
18 
19   This function returns the pointer to first HOB in the list.
20   For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer
21   to the HOB list.  For the DXE phase, the HOB list pointer can be retrieved through
22   the EFI System Table by looking up theHOB list GUID in the System Configuration Table.
23   Since the System Configuration Table does not exist that the time the DXE Core is
24   launched, the DXE Core uses a global variable from the DXE Core Entry Point Library
25   to manage the pointer to the HOB list.
26 
27   If the pointer to the HOB list is NULL, then ASSERT().
28 
29   @return The pointer to the HOB list.
30 
31 **/
32 VOID *
33 EFIAPI
GetHobList(VOID)34 GetHobList (
35   VOID
36   )
37 {
38   ASSERT (FALSE);
39   return NULL;
40 }
41 
42 /**
43   Returns the next instance of a HOB type from the starting HOB.
44 
45   This function searches the first instance of a HOB type from the starting HOB pointer.
46   If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
47   In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
48   unconditionally: it returns HobStart back if HobStart itself meets the requirement;
49   caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
50 
51   If HobStart is NULL, then ASSERT().
52 
53   @param  Type          The HOB type to return.
54   @param  HobStart      The starting HOB pointer to search from.
55 
56   @return The next instance of a HOB type from the starting HOB.
57 
58 **/
59 VOID *
60 EFIAPI
GetNextHob(IN UINT16 Type,IN CONST VOID * HobStart)61 GetNextHob (
62   IN UINT16                 Type,
63   IN CONST VOID             *HobStart
64   )
65 {
66   ASSERT (FALSE);
67   return NULL;
68 }
69 
70 /**
71   Returns the first instance of a HOB type among the whole HOB list.
72 
73   This function searches the first instance of a HOB type among the whole HOB list.
74   If there does not exist such HOB type in the HOB list, it will return NULL.
75 
76   If the pointer to the HOB list is NULL, then ASSERT().
77 
78   @param  Type          The HOB type to return.
79 
80   @return The next instance of a HOB type from the starting HOB.
81 
82 **/
83 VOID *
84 EFIAPI
GetFirstHob(IN UINT16 Type)85 GetFirstHob (
86   IN UINT16                 Type
87   )
88 {
89   ASSERT (FALSE);
90   return NULL;
91 }
92 
93 /**
94   Returns the next instance of the matched GUID HOB from the starting HOB.
95 
96   This function searches the first instance of a HOB from the starting HOB pointer.
97   Such HOB should satisfy two conditions:
98   its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
99   If there does not exist such HOB from the starting HOB pointer, it will return NULL.
100   Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
101   to extract the data section and its size information, respectively.
102   In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
103   unconditionally: it returns HobStart back if HobStart itself meets the requirement;
104   caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
105 
106   If Guid is NULL, then ASSERT().
107   If HobStart is NULL, then ASSERT().
108 
109   @param  Guid          The GUID to match with in the HOB list.
110   @param  HobStart      A pointer to a Guid.
111 
112   @return The next instance of the matched GUID HOB from the starting HOB.
113 
114 **/
115 VOID *
116 EFIAPI
GetNextGuidHob(IN CONST EFI_GUID * Guid,IN CONST VOID * HobStart)117 GetNextGuidHob (
118   IN CONST EFI_GUID         *Guid,
119   IN CONST VOID             *HobStart
120   )
121 {
122   ASSERT (FALSE);
123   return NULL;
124 }
125 
126 /**
127   Returns the first instance of the matched GUID HOB among the whole HOB list.
128 
129   This function searches the first instance of a HOB among the whole HOB list.
130   Such HOB should satisfy two conditions:
131   its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
132   If there does not exist such HOB from the starting HOB pointer, it will return NULL.
133   Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
134   to extract the data section and its size information, respectively.
135 
136   If the pointer to the HOB list is NULL, then ASSERT().
137   If Guid is NULL, then ASSERT().
138 
139   @param  Guid          The GUID to match with in the HOB list.
140 
141   @return The first instance of the matched GUID HOB among the whole HOB list.
142 
143 **/
144 VOID *
145 EFIAPI
GetFirstGuidHob(IN CONST EFI_GUID * Guid)146 GetFirstGuidHob (
147   IN CONST EFI_GUID         *Guid
148   )
149 {
150   ASSERT (FALSE);
151   return NULL;
152 }
153 
154 /**
155   Get the system boot mode from the HOB list.
156 
157   This function returns the system boot mode information from the
158   PHIT HOB in HOB list.
159 
160   If the pointer to the HOB list is NULL, then ASSERT().
161 
162   @param  VOID.
163 
164   @return The Boot Mode.
165 
166 **/
167 EFI_BOOT_MODE
168 EFIAPI
GetBootModeHob(VOID)169 GetBootModeHob (
170   VOID
171   )
172 {
173   ASSERT (FALSE);
174   return MAX_UINT32;
175 }
176 
177 /**
178   Builds a HOB for a loaded PE32 module.
179 
180   This function builds a HOB for a loaded PE32 module.
181   It can only be invoked during PEI phase;
182   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
183 
184   If ModuleName is NULL, then ASSERT().
185   If there is no additional space for HOB creation, then ASSERT().
186 
187   @param  ModuleName              The GUID File Name of the module.
188   @param  MemoryAllocationModule  The 64 bit physical address of the module.
189   @param  ModuleLength            The length of the module in bytes.
190   @param  EntryPoint              The 64 bit physical address of the module entry point.
191 
192 **/
193 VOID
194 EFIAPI
BuildModuleHob(IN CONST EFI_GUID * ModuleName,IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,IN UINT64 ModuleLength,IN EFI_PHYSICAL_ADDRESS EntryPoint)195 BuildModuleHob (
196   IN CONST EFI_GUID         *ModuleName,
197   IN EFI_PHYSICAL_ADDRESS   MemoryAllocationModule,
198   IN UINT64                 ModuleLength,
199   IN EFI_PHYSICAL_ADDRESS   EntryPoint
200   )
201 {
202   ASSERT (FALSE);
203 }
204 
205 /**
206   Builds a HOB that describes a chunk of system memory with Owner GUID.
207 
208   This function builds a HOB that describes a chunk of system memory.
209   It can only be invoked during PEI phase;
210   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
211 
212   If there is no additional space for HOB creation, then ASSERT().
213 
214   @param  ResourceType        The type of resource described by this HOB.
215   @param  ResourceAttribute   The resource attributes of the memory described by this HOB.
216   @param  PhysicalStart       The 64 bit physical address of memory described by this HOB.
217   @param  NumberOfBytes       The length of the memory described by this HOB in bytes.
218   @param  OwnerGUID           GUID for the owner of this resource.
219 
220 **/
221 VOID
222 EFIAPI
BuildResourceDescriptorWithOwnerHob(IN EFI_RESOURCE_TYPE ResourceType,IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,IN EFI_PHYSICAL_ADDRESS PhysicalStart,IN UINT64 NumberOfBytes,IN EFI_GUID * OwnerGUID)223 BuildResourceDescriptorWithOwnerHob (
224   IN EFI_RESOURCE_TYPE            ResourceType,
225   IN EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttribute,
226   IN EFI_PHYSICAL_ADDRESS         PhysicalStart,
227   IN UINT64                       NumberOfBytes,
228   IN EFI_GUID                     *OwnerGUID
229   )
230 {
231   ASSERT (FALSE);
232 }
233 
234 /**
235   Builds a HOB that describes a chunk of system memory.
236 
237   This function builds a HOB that describes a chunk of system memory.
238   It can only be invoked during PEI phase;
239   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
240 
241   If there is no additional space for HOB creation, then ASSERT().
242 
243   @param  ResourceType        The type of resource described by this HOB.
244   @param  ResourceAttribute   The resource attributes of the memory described by this HOB.
245   @param  PhysicalStart       The 64 bit physical address of memory described by this HOB.
246   @param  NumberOfBytes       The length of the memory described by this HOB in bytes.
247 
248 **/
249 VOID
250 EFIAPI
BuildResourceDescriptorHob(IN EFI_RESOURCE_TYPE ResourceType,IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,IN EFI_PHYSICAL_ADDRESS PhysicalStart,IN UINT64 NumberOfBytes)251 BuildResourceDescriptorHob (
252   IN EFI_RESOURCE_TYPE            ResourceType,
253   IN EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttribute,
254   IN EFI_PHYSICAL_ADDRESS         PhysicalStart,
255   IN UINT64                       NumberOfBytes
256   )
257 {
258   ASSERT (FALSE);
259 }
260 
261 /**
262   Builds a customized HOB tagged with a GUID for identification and returns
263   the start address of GUID HOB data.
264 
265   This function builds a customized HOB tagged with a GUID for identification
266   and returns the start address of GUID HOB data so that caller can fill the customized data.
267   The HOB Header and Name field is already stripped.
268   It can only be invoked during PEI phase;
269   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
270 
271   If Guid is NULL, then ASSERT().
272   If there is no additional space for HOB creation, then ASSERT().
273   If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
274   HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
275 
276   @param  Guid          The GUID to tag the customized HOB.
277   @param  DataLength    The size of the data payload for the GUID HOB.
278 
279   @retval  NULL         The GUID HOB could not be allocated.
280   @retval  others       The start address of GUID HOB data.
281 
282 **/
283 VOID *
284 EFIAPI
BuildGuidHob(IN CONST EFI_GUID * Guid,IN UINTN DataLength)285 BuildGuidHob (
286   IN CONST EFI_GUID              *Guid,
287   IN UINTN                       DataLength
288   )
289 {
290   ASSERT (FALSE);
291   return NULL;
292 }
293 
294 /**
295   Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB
296   data field, and returns the start address of the GUID HOB data.
297 
298   This function builds a customized HOB tagged with a GUID for identification and copies the input
299   data to the HOB data field and returns the start address of the GUID HOB data.  It can only be
300   invoked during PEI phase; for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
301   The HOB Header and Name field is already stripped.
302   It can only be invoked during PEI phase;
303   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
304 
305   If Guid is NULL, then ASSERT().
306   If Data is NULL and DataLength > 0, then ASSERT().
307   If there is no additional space for HOB creation, then ASSERT().
308   If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
309   HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
310 
311   @param  Guid          The GUID to tag the customized HOB.
312   @param  Data          The data to be copied into the data field of the GUID HOB.
313   @param  DataLength    The size of the data payload for the GUID HOB.
314 
315   @retval  NULL         The GUID HOB could not be allocated.
316   @retval  others       The start address of GUID HOB data.
317 
318 **/
319 VOID *
320 EFIAPI
BuildGuidDataHob(IN CONST EFI_GUID * Guid,IN VOID * Data,IN UINTN DataLength)321 BuildGuidDataHob (
322   IN CONST EFI_GUID              *Guid,
323   IN VOID                        *Data,
324   IN UINTN                       DataLength
325   )
326 {
327   ASSERT (FALSE);
328   return NULL;
329 }
330 
331 /**
332   Builds a Firmware Volume HOB.
333 
334   This function builds a Firmware Volume HOB.
335   It can only be invoked during PEI phase;
336   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
337 
338   If there is no additional space for HOB creation, then ASSERT().
339   If the FvImage buffer is not at its required alignment, then ASSERT().
340 
341   @param  BaseAddress   The base address of the Firmware Volume.
342   @param  Length        The size of the Firmware Volume in bytes.
343 
344 **/
345 VOID
346 EFIAPI
BuildFvHob(IN EFI_PHYSICAL_ADDRESS BaseAddress,IN UINT64 Length)347 BuildFvHob (
348   IN EFI_PHYSICAL_ADDRESS        BaseAddress,
349   IN UINT64                      Length
350   )
351 {
352   ASSERT (FALSE);
353 }
354 
355 /**
356   Builds a EFI_HOB_TYPE_FV2 HOB.
357 
358   This function builds a EFI_HOB_TYPE_FV2 HOB.
359   It can only be invoked during PEI phase;
360   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
361 
362   If there is no additional space for HOB creation, then ASSERT().
363   If the FvImage buffer is not at its required alignment, then ASSERT().
364 
365   @param  BaseAddress   The base address of the Firmware Volume.
366   @param  Length        The size of the Firmware Volume in bytes.
367   @param  FvName        The name of the Firmware Volume.
368   @param  FileName      The name of the file.
369 
370 **/
371 VOID
372 EFIAPI
BuildFv2Hob(IN EFI_PHYSICAL_ADDRESS BaseAddress,IN UINT64 Length,IN CONST EFI_GUID * FvName,IN CONST EFI_GUID * FileName)373 BuildFv2Hob (
374   IN          EFI_PHYSICAL_ADDRESS        BaseAddress,
375   IN          UINT64                      Length,
376   IN CONST    EFI_GUID                    *FvName,
377   IN CONST    EFI_GUID                    *FileName
378   )
379 {
380   ASSERT (FALSE);
381 }
382 
383 /**
384   Builds a EFI_HOB_TYPE_FV3 HOB.
385 
386   This function builds a EFI_HOB_TYPE_FV3 HOB.
387   It can only be invoked during PEI phase;
388   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
389 
390   If there is no additional space for HOB creation, then ASSERT().
391   If the FvImage buffer is not at its required alignment, then ASSERT().
392 
393   @param BaseAddress            The base address of the Firmware Volume.
394   @param Length                 The size of the Firmware Volume in bytes.
395   @param AuthenticationStatus   The authentication status.
396   @param ExtractedFv            TRUE if the FV was extracted as a file within
397                                 another firmware volume. FALSE otherwise.
398   @param FvName                 The name of the Firmware Volume.
399                                 Valid only if IsExtractedFv is TRUE.
400   @param FileName               The name of the file.
401                                 Valid only if IsExtractedFv is TRUE.
402 
403 **/
404 VOID
405 EFIAPI
BuildFv3Hob(IN EFI_PHYSICAL_ADDRESS BaseAddress,IN UINT64 Length,IN UINT32 AuthenticationStatus,IN BOOLEAN ExtractedFv,IN CONST EFI_GUID * FvName,OPTIONAL IN CONST EFI_GUID * FileName OPTIONAL)406 BuildFv3Hob (
407   IN          EFI_PHYSICAL_ADDRESS        BaseAddress,
408   IN          UINT64                      Length,
409   IN          UINT32                      AuthenticationStatus,
410   IN          BOOLEAN                     ExtractedFv,
411   IN CONST    EFI_GUID                    *FvName, OPTIONAL
412   IN CONST    EFI_GUID                    *FileName OPTIONAL
413   )
414 {
415   ASSERT (FALSE);
416 }
417 
418 /**
419   Builds a Capsule Volume HOB.
420 
421   This function builds a Capsule Volume HOB.
422   It can only be invoked during PEI phase;
423   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
424 
425   If the platform does not support Capsule Volume HOBs, then ASSERT().
426   If there is no additional space for HOB creation, then ASSERT().
427 
428   @param  BaseAddress   The base address of the Capsule Volume.
429   @param  Length        The size of the Capsule Volume in bytes.
430 
431 **/
432 VOID
433 EFIAPI
BuildCvHob(IN EFI_PHYSICAL_ADDRESS BaseAddress,IN UINT64 Length)434 BuildCvHob (
435   IN EFI_PHYSICAL_ADDRESS        BaseAddress,
436   IN UINT64                      Length
437   )
438 {
439   ASSERT (FALSE);
440 }
441 
442 /**
443   Builds a HOB for the CPU.
444 
445   This function builds a HOB for the CPU.
446   It can only be invoked during PEI phase;
447   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
448 
449   If there is no additional space for HOB creation, then ASSERT().
450 
451   @param  SizeOfMemorySpace   The maximum physical memory addressability of the processor.
452   @param  SizeOfIoSpace       The maximum physical I/O addressability of the processor.
453 
454 **/
455 VOID
456 EFIAPI
BuildCpuHob(IN UINT8 SizeOfMemorySpace,IN UINT8 SizeOfIoSpace)457 BuildCpuHob (
458   IN UINT8                       SizeOfMemorySpace,
459   IN UINT8                       SizeOfIoSpace
460   )
461 {
462   ASSERT (FALSE);
463 }
464 
465 /**
466   Builds a HOB for the Stack.
467 
468   This function builds a HOB for the stack.
469   It can only be invoked during PEI phase;
470   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
471 
472   If there is no additional space for HOB creation, then ASSERT().
473 
474   @param  BaseAddress   The 64 bit physical address of the Stack.
475   @param  Length        The length of the stack in bytes.
476 
477 **/
478 VOID
479 EFIAPI
BuildStackHob(IN EFI_PHYSICAL_ADDRESS BaseAddress,IN UINT64 Length)480 BuildStackHob (
481   IN EFI_PHYSICAL_ADDRESS        BaseAddress,
482   IN UINT64                      Length
483   )
484 {
485   ASSERT (FALSE);
486 }
487 
488 /**
489   Builds a HOB for the BSP store.
490 
491   This function builds a HOB for BSP store.
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.
494 
495   If there is no additional space for HOB creation, then ASSERT().
496 
497   @param  BaseAddress   The 64 bit physical address of the BSP.
498   @param  Length        The length of the BSP store in bytes.
499   @param  MemoryType    The type of memory allocated by this HOB.
500 
501 **/
502 VOID
503 EFIAPI
BuildBspStoreHob(IN EFI_PHYSICAL_ADDRESS BaseAddress,IN UINT64 Length,IN EFI_MEMORY_TYPE MemoryType)504 BuildBspStoreHob (
505   IN EFI_PHYSICAL_ADDRESS        BaseAddress,
506   IN UINT64                      Length,
507   IN EFI_MEMORY_TYPE             MemoryType
508   )
509 {
510   ASSERT (FALSE);
511 }
512 
513 /**
514   Builds a HOB for the memory allocation.
515 
516   This function builds a HOB for the memory allocation.
517   It can only be invoked during PEI phase;
518   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
519 
520   If there is no additional space for HOB creation, then ASSERT().
521 
522   @param  BaseAddress   The 64 bit physical address of the memory.
523   @param  Length        The length of the memory allocation in bytes.
524   @param  MemoryType    The type of memory allocated by this HOB.
525 
526 **/
527 VOID
528 EFIAPI
BuildMemoryAllocationHob(IN EFI_PHYSICAL_ADDRESS BaseAddress,IN UINT64 Length,IN EFI_MEMORY_TYPE MemoryType)529 BuildMemoryAllocationHob (
530   IN EFI_PHYSICAL_ADDRESS        BaseAddress,
531   IN UINT64                      Length,
532   IN EFI_MEMORY_TYPE             MemoryType
533   )
534 {
535   ASSERT (FALSE);
536 }
537