• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2  Instance of HOB Library using PEI Services.
3 
4  HOB Library implementation that uses PEI Services to retrieve the HOB List.
5  This library instance uses EFI_HOB_TYPE_CV defined in Intel framework HOB specification v0.9
6  to implement HobLib BuildCvHob() API.
7 
8 Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
9 This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution.  The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
13 
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 
17 **/
18 
19 #include <FrameworkPei.h>
20 
21 #include <Guid/MemoryAllocationHob.h>
22 
23 #include <Library/HobLib.h>
24 #include <Library/DebugLib.h>
25 #include <Library/PeiServicesLib.h>
26 #include <Library/BaseMemoryLib.h>
27 
28 /**
29   Returns the pointer to the HOB list.
30 
31   This function returns the pointer to first HOB in the list.
32   For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer
33   to the HOB list.  For the DXE phase, the HOB list pointer can be retrieved through
34   the EFI System Table by looking up theHOB list GUID in the System Configuration Table.
35   Since the System Configuration Table does not exist that the time the DXE Core is
36   launched, the DXE Core uses a global variable from the DXE Core Entry Point Library
37   to manage the pointer to the HOB list.
38 
39   If the pointer to the HOB list is NULL, then ASSERT().
40 
41   @return The pointer to the HOB list.
42 
43 **/
44 VOID *
45 EFIAPI
GetHobList(VOID)46 GetHobList (
47   VOID
48   )
49 {
50   EFI_STATUS            Status;
51   VOID                  *HobList;
52 
53   Status = PeiServicesGetHobList (&HobList);
54   ASSERT_EFI_ERROR (Status);
55   ASSERT (HobList != NULL);
56 
57   return HobList;
58 }
59 
60 /**
61   Returns the next instance of a HOB type from the starting HOB.
62 
63   This function searches the first instance of a HOB type from the starting HOB pointer.
64   If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
65   In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
66   unconditionally: it returns HobStart back if HobStart itself meets the requirement;
67   caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
68 
69   If HobStart is NULL, then ASSERT().
70 
71   @param  Type          The HOB type to return.
72   @param  HobStart      The starting HOB pointer to search from.
73 
74   @return The next instance of a HOB type from the starting HOB.
75 
76 **/
77 VOID *
78 EFIAPI
GetNextHob(IN UINT16 Type,IN CONST VOID * HobStart)79 GetNextHob (
80   IN UINT16                 Type,
81   IN CONST VOID             *HobStart
82   )
83 {
84   EFI_PEI_HOB_POINTERS  Hob;
85 
86   ASSERT (HobStart != NULL);
87 
88   Hob.Raw = (UINT8 *) HobStart;
89   //
90   // Parse the HOB list until end of list or matching type is found.
91   //
92   while (!END_OF_HOB_LIST (Hob)) {
93     if (Hob.Header->HobType == Type) {
94       return Hob.Raw;
95     }
96     Hob.Raw = GET_NEXT_HOB (Hob);
97   }
98   return NULL;
99 }
100 
101 /**
102   Returns the first instance of a HOB type among the whole HOB list.
103 
104   This function searches the first instance of a HOB type among the whole HOB list.
105   If there does not exist such HOB type in the HOB list, it will return NULL.
106 
107   If the pointer to the HOB list is NULL, then ASSERT().
108 
109   @param  Type          The HOB type to return.
110 
111   @return The next instance of a HOB type from the starting HOB.
112 
113 **/
114 VOID *
115 EFIAPI
GetFirstHob(IN UINT16 Type)116 GetFirstHob (
117   IN UINT16                 Type
118   )
119 {
120   VOID      *HobList;
121 
122   HobList = GetHobList ();
123   return GetNextHob (Type, HobList);
124 }
125 
126 /**
127   Returns the next instance of the matched GUID HOB from the starting HOB.
128 
129   This function searches the first instance of a HOB from the starting HOB pointer.
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 info respectively.
135   In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
136   unconditionally: it returns HobStart back if HobStart itself meets the requirement;
137   caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
138 
139   If Guid is NULL, then ASSERT().
140   If HobStart is NULL, then ASSERT().
141 
142   @param  Guid          The GUID to match with in the HOB list.
143   @param  HobStart      A pointer to a Guid.
144 
145   @return The next instance of the matched GUID HOB from the starting HOB.
146 
147 **/
148 VOID *
149 EFIAPI
GetNextGuidHob(IN CONST EFI_GUID * Guid,IN CONST VOID * HobStart)150 GetNextGuidHob (
151   IN CONST EFI_GUID         *Guid,
152   IN CONST VOID             *HobStart
153   )
154 {
155   EFI_PEI_HOB_POINTERS  GuidHob;
156 
157   GuidHob.Raw = (UINT8 *) HobStart;
158   while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {
159     if (CompareGuid (Guid, &GuidHob.Guid->Name)) {
160       break;
161     }
162     GuidHob.Raw = GET_NEXT_HOB (GuidHob);
163   }
164   return GuidHob.Raw;
165 }
166 
167 /**
168   Returns the first instance of the matched GUID HOB among the whole HOB list.
169 
170   This function searches the first instance of a HOB among the whole HOB list.
171   Such HOB should satisfy two conditions:
172   its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
173   If there does not exist such HOB from the starting HOB pointer, it will return NULL.
174   Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
175   to extract the data section and its size info respectively.
176 
177   If the pointer to the HOB list is NULL, then ASSERT().
178   If Guid is NULL, then ASSERT().
179 
180   @param  Guid          The GUID to match with in the HOB list.
181 
182   @return The first instance of the matched GUID HOB among the whole HOB list.
183 
184 **/
185 VOID *
186 EFIAPI
GetFirstGuidHob(IN CONST EFI_GUID * Guid)187 GetFirstGuidHob (
188   IN CONST EFI_GUID         *Guid
189   )
190 {
191   VOID      *HobList;
192 
193   HobList = GetHobList ();
194   return GetNextGuidHob (Guid, HobList);
195 }
196 
197 /**
198   Get the system boot mode from the HOB list.
199 
200   This function returns the system boot mode information from the
201   PHIT HOB in HOB list.
202 
203   If the pointer to the HOB list is NULL, then ASSERT().
204 
205   @param  VOID
206 
207   @return The Boot Mode.
208 
209 **/
210 EFI_BOOT_MODE
211 EFIAPI
GetBootModeHob(VOID)212 GetBootModeHob (
213   VOID
214   )
215 {
216   EFI_STATUS             Status;
217   EFI_BOOT_MODE          BootMode;
218 
219   Status = PeiServicesGetBootMode (&BootMode);
220   ASSERT_EFI_ERROR (Status);
221 
222   return BootMode;
223 }
224 
225 /**
226   Adds a new HOB to the HOB List.
227 
228   This internal function enables PEIMs to create various types of HOBs.
229 
230   @param  Type          Type of the new HOB.
231   @param  Length        Length of the new HOB to allocate.
232 
233   @retval  NULL         The HOB could not be allocated.
234   @retval  others       The address of new HOB.
235 
236 **/
237 VOID *
238 EFIAPI
InternalPeiCreateHob(IN UINT16 Type,IN UINT16 Length)239 InternalPeiCreateHob (
240   IN UINT16                      Type,
241   IN UINT16                      Length
242   )
243 {
244   EFI_STATUS        Status;
245   VOID              *Hob;
246 
247   Status = PeiServicesCreateHob (Type, Length, &Hob);
248   if (EFI_ERROR (Status)) {
249     Hob = NULL;
250   }
251   //
252   // Assume the process of HOB building is always successful.
253   //
254   ASSERT (Hob != NULL);
255   return Hob;
256 }
257 
258 /**
259   Builds a HOB for a loaded PE32 module.
260 
261   This function builds a HOB for a loaded PE32 module.
262   It can only be invoked during PEI phase;
263   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
264 
265   If ModuleName is NULL, then ASSERT().
266   If there is no additional space for HOB creation, then ASSERT().
267 
268   @param  ModuleName              The GUID File Name of the module.
269   @param  MemoryAllocationModule  The 64 bit physical address of the module.
270   @param  ModuleLength            The length of the module in bytes.
271   @param  EntryPoint              The 64 bit physical address of the module entry point.
272 
273 **/
274 VOID
275 EFIAPI
BuildModuleHob(IN CONST EFI_GUID * ModuleName,IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,IN UINT64 ModuleLength,IN EFI_PHYSICAL_ADDRESS EntryPoint)276 BuildModuleHob (
277   IN CONST EFI_GUID         *ModuleName,
278   IN EFI_PHYSICAL_ADDRESS   MemoryAllocationModule,
279   IN UINT64                 ModuleLength,
280   IN EFI_PHYSICAL_ADDRESS   EntryPoint
281   )
282 {
283   EFI_HOB_MEMORY_ALLOCATION_MODULE  *Hob;
284 
285   ASSERT (((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) &&
286           ((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0));
287 
288   Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE));
289   if (Hob == NULL) {
290     return;
291   }
292 
293   CopyGuid (&(Hob->MemoryAllocationHeader.Name), &gEfiHobMemoryAllocModuleGuid);
294   Hob->MemoryAllocationHeader.MemoryBaseAddress = MemoryAllocationModule;
295   Hob->MemoryAllocationHeader.MemoryLength      = ModuleLength;
296   Hob->MemoryAllocationHeader.MemoryType        = EfiBootServicesCode;
297 
298   //
299   // Zero the reserved space to match HOB spec
300   //
301   ZeroMem (Hob->MemoryAllocationHeader.Reserved, sizeof (Hob->MemoryAllocationHeader.Reserved));
302 
303   CopyGuid (&Hob->ModuleName, ModuleName);
304   Hob->EntryPoint = EntryPoint;
305 }
306 
307 /**
308   Builds a HOB that describes a chunk of system memory with Owner GUID.
309 
310   This function builds a HOB that describes a chunk of system memory.
311   It can only be invoked during PEI phase;
312   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
313 
314   If there is no additional space for HOB creation, then ASSERT().
315 
316   @param  ResourceType        The type of resource described by this HOB.
317   @param  ResourceAttribute   The resource attributes of the memory described by this HOB.
318   @param  PhysicalStart       The 64 bit physical address of memory described by this HOB.
319   @param  NumberOfBytes       The length of the memory described by this HOB in bytes.
320   @param  OwnerGUID           GUID for the owner of this resource.
321 
322 **/
323 VOID
324 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)325 BuildResourceDescriptorWithOwnerHob (
326   IN EFI_RESOURCE_TYPE            ResourceType,
327   IN EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttribute,
328   IN EFI_PHYSICAL_ADDRESS         PhysicalStart,
329   IN UINT64                       NumberOfBytes,
330   IN EFI_GUID                     *OwnerGUID
331   )
332 {
333   EFI_HOB_RESOURCE_DESCRIPTOR  *Hob;
334 
335   Hob = InternalPeiCreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, (UINT16) sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));
336   if (Hob == NULL) {
337     return;
338   }
339 
340   Hob->ResourceType      = ResourceType;
341   Hob->ResourceAttribute = ResourceAttribute;
342   Hob->PhysicalStart     = PhysicalStart;
343   Hob->ResourceLength    = NumberOfBytes;
344 
345   CopyGuid (&Hob->Owner, OwnerGUID);
346 }
347 
348 /**
349   Builds a HOB that describes a chunk of system memory.
350 
351   This function builds a HOB that describes a chunk of system memory.
352   It can only be invoked during PEI phase;
353   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
354 
355   If there is no additional space for HOB creation, then ASSERT().
356 
357   @param  ResourceType        The type of resource described by this HOB.
358   @param  ResourceAttribute   The resource attributes of the memory described by this HOB.
359   @param  PhysicalStart       The 64 bit physical address of memory described by this HOB.
360   @param  NumberOfBytes       The length of the memory described by this HOB in bytes.
361 
362 **/
363 VOID
364 EFIAPI
BuildResourceDescriptorHob(IN EFI_RESOURCE_TYPE ResourceType,IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,IN EFI_PHYSICAL_ADDRESS PhysicalStart,IN UINT64 NumberOfBytes)365 BuildResourceDescriptorHob (
366   IN EFI_RESOURCE_TYPE            ResourceType,
367   IN EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttribute,
368   IN EFI_PHYSICAL_ADDRESS         PhysicalStart,
369   IN UINT64                       NumberOfBytes
370   )
371 {
372   EFI_HOB_RESOURCE_DESCRIPTOR  *Hob;
373 
374   Hob = InternalPeiCreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, (UINT16) sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));
375   if (Hob == NULL) {
376     return;
377   }
378 
379   Hob->ResourceType      = ResourceType;
380   Hob->ResourceAttribute = ResourceAttribute;
381   Hob->PhysicalStart     = PhysicalStart;
382   Hob->ResourceLength    = NumberOfBytes;
383   ZeroMem (&(Hob->Owner), sizeof (EFI_GUID));
384 }
385 
386 /**
387   Builds a customized HOB tagged with a GUID for identification and returns
388   the start address of GUID HOB data.
389 
390   This function builds a customized HOB tagged with a GUID for identification
391   and returns the start address of GUID HOB data so that caller can fill the customized data.
392   The HOB Header and Name field is already stripped.
393   It can only be invoked during PEI phase;
394   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
395 
396   If Guid is NULL, then ASSERT().
397   If there is no additional space for HOB creation, then ASSERT().
398   If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
399 
400   @param  Guid          The GUID to tag the customized HOB.
401   @param  DataLength    The size of the data payload for the GUID HOB.
402 
403   @retval  NULL         The GUID HOB could not be allocated.
404   @retval  others       The start address of GUID HOB data.
405 
406 **/
407 VOID *
408 EFIAPI
BuildGuidHob(IN CONST EFI_GUID * Guid,IN UINTN DataLength)409 BuildGuidHob (
410   IN CONST EFI_GUID              *Guid,
411   IN UINTN                       DataLength
412   )
413 {
414   EFI_HOB_GUID_TYPE *Hob;
415 
416   //
417   // Make sure Guid is valid
418   //
419   ASSERT (Guid != NULL);
420 
421   //
422   // Make sure that data length is not too long.
423   //
424   ASSERT (DataLength <= (0xffff - sizeof (EFI_HOB_GUID_TYPE)));
425 
426   Hob = InternalPeiCreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16) (sizeof (EFI_HOB_GUID_TYPE) + DataLength));
427   if (Hob == NULL) {
428     return Hob;
429   }
430   CopyGuid (&Hob->Name, Guid);
431   return Hob + 1;
432 }
433 
434 /**
435   Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB
436   data field, and returns the start address of the GUID HOB data.
437 
438   This function builds a customized HOB tagged with a GUID for identification and copies the input
439   data to the HOB data field and returns the start address of the GUID HOB data.  It can only be
440   invoked during PEI phase; for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
441   The HOB Header and Name field is already stripped.
442   It can only be invoked during PEI phase;
443   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
444 
445   If Guid is NULL, then ASSERT().
446   If Data is NULL and DataLength > 0, then ASSERT().
447   If there is no additional space for HOB creation, then ASSERT().
448   If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
449 
450   @param  Guid          The GUID to tag the customized HOB.
451   @param  Data          The data to be copied into the data field of the GUID HOB.
452   @param  DataLength    The size of the data payload for the GUID HOB.
453 
454   @retval  NULL         The GUID HOB could not be allocated.
455   @retval  others       The start address of GUID HOB data.
456 
457 **/
458 VOID *
459 EFIAPI
BuildGuidDataHob(IN CONST EFI_GUID * Guid,IN VOID * Data,IN UINTN DataLength)460 BuildGuidDataHob (
461   IN CONST EFI_GUID              *Guid,
462   IN VOID                        *Data,
463   IN UINTN                       DataLength
464   )
465 {
466   VOID  *HobData;
467 
468   ASSERT (Data != NULL || DataLength == 0);
469 
470   HobData = BuildGuidHob (Guid, DataLength);
471   if (HobData == NULL) {
472     return HobData;
473   }
474 
475   return CopyMem (HobData, Data, DataLength);
476 }
477 
478 /**
479   Check FV alignment.
480 
481   @param  BaseAddress   The base address of the Firmware Volume.
482   @param  Length        The size of the Firmware Volume in bytes.
483 
484   @retval TRUE          FvImage buffer is at its required alignment.
485   @retval FALSE         FvImage buffer is not at its required alignment.
486 
487 **/
488 BOOLEAN
InternalCheckFvAlignment(IN EFI_PHYSICAL_ADDRESS BaseAddress,IN UINT64 Length)489 InternalCheckFvAlignment (
490   IN EFI_PHYSICAL_ADDRESS       BaseAddress,
491   IN UINT64                     Length
492   )
493 {
494   EFI_FIRMWARE_VOLUME_HEADER    *FwVolHeader;
495   UINT32                        FvAlignment;
496 
497   FvAlignment = 0;
498   FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress;
499 
500   //
501   // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume
502   // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from
503   // its initial linked location and maintain its alignment.
504   //
505   if ((FwVolHeader->Attributes & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {
506     //
507     // Get FvHeader alignment
508     //
509     FvAlignment = 1 << ((FwVolHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);
510     //
511     // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.
512     //
513     if (FvAlignment < 8) {
514       FvAlignment = 8;
515     }
516     if ((UINTN)BaseAddress % FvAlignment != 0) {
517       //
518       // FvImage buffer is not at its required alignment.
519       //
520       DEBUG ((
521         DEBUG_ERROR,
522         "Unaligned FvImage found at 0x%lx:0x%lx, the required alignment is 0x%x\n",
523         BaseAddress,
524         Length,
525         FvAlignment
526         ));
527       return FALSE;
528     }
529   }
530 
531   return TRUE;
532 }
533 
534 /**
535   Builds a Firmware Volume HOB.
536 
537   This function builds a Firmware Volume HOB.
538   It can only be invoked during PEI phase;
539   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
540 
541   If there is no additional space for HOB creation, then ASSERT().
542   If the FvImage buffer is not at its required alignment, then ASSERT().
543 
544   @param  BaseAddress   The base address of the Firmware Volume.
545   @param  Length        The size of the Firmware Volume in bytes.
546 
547 **/
548 VOID
549 EFIAPI
BuildFvHob(IN EFI_PHYSICAL_ADDRESS BaseAddress,IN UINT64 Length)550 BuildFvHob (
551   IN EFI_PHYSICAL_ADDRESS        BaseAddress,
552   IN UINT64                      Length
553   )
554 {
555   EFI_HOB_FIRMWARE_VOLUME  *Hob;
556 
557   if (!InternalCheckFvAlignment (BaseAddress, Length)) {
558     ASSERT (FALSE);
559     return;
560   }
561 
562   Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME));
563   if (Hob == NULL) {
564     return;
565   }
566 
567   Hob->BaseAddress = BaseAddress;
568   Hob->Length      = Length;
569 }
570 
571 /**
572   Builds a EFI_HOB_TYPE_FV2 HOB.
573 
574   This function builds a EFI_HOB_TYPE_FV2 HOB.
575   It can only be invoked during PEI phase;
576   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
577 
578   If there is no additional space for HOB creation, then ASSERT().
579   If the FvImage buffer is not at its required alignment, then ASSERT().
580 
581   @param  BaseAddress   The base address of the Firmware Volume.
582   @param  Length        The size of the Firmware Volume in bytes.
583   @param  FvName        The name of the Firmware Volume.
584   @param  FileName      The name of the file.
585 
586 **/
587 VOID
588 EFIAPI
BuildFv2Hob(IN EFI_PHYSICAL_ADDRESS BaseAddress,IN UINT64 Length,IN CONST EFI_GUID * FvName,IN CONST EFI_GUID * FileName)589 BuildFv2Hob (
590   IN          EFI_PHYSICAL_ADDRESS        BaseAddress,
591   IN          UINT64                      Length,
592   IN CONST    EFI_GUID                    *FvName,
593   IN CONST    EFI_GUID                    *FileName
594   )
595 {
596   EFI_HOB_FIRMWARE_VOLUME2  *Hob;
597 
598   if (!InternalCheckFvAlignment (BaseAddress, Length)) {
599     ASSERT (FALSE);
600     return;
601   }
602 
603   Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV2, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME2));
604   if (Hob == NULL) {
605     return;
606   }
607 
608   Hob->BaseAddress = BaseAddress;
609   Hob->Length      = Length;
610   CopyGuid (&Hob->FvName, FvName);
611   CopyGuid (&Hob->FileName, FileName);
612 }
613 
614 /**
615   Builds a Capsule Volume HOB.
616 
617   This function builds a Capsule Volume HOB.
618   It can only be invoked during PEI phase;
619   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
620 
621   If the platform does not support Capsule Volume HOBs, then ASSERT().
622   If there is no additional space for HOB creation, then ASSERT().
623 
624   @param  BaseAddress   The base address of the Capsule Volume.
625   @param  Length        The size of the Capsule Volume in bytes.
626 
627 **/
628 VOID
629 EFIAPI
BuildCvHob(IN EFI_PHYSICAL_ADDRESS BaseAddress,IN UINT64 Length)630 BuildCvHob (
631   IN EFI_PHYSICAL_ADDRESS        BaseAddress,
632   IN UINT64                      Length
633   )
634 {
635   EFI_HOB_CAPSULE_VOLUME     *Hob;
636 
637   Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CV, (UINT16) sizeof (EFI_HOB_CAPSULE_VOLUME));
638   if (Hob == NULL) {
639     return;
640   }
641 
642   Hob->BaseAddress = BaseAddress;
643   Hob->Length      = Length;
644 }
645 
646 /**
647   Builds a HOB for the CPU.
648 
649   This function builds a HOB for the CPU.
650   It can only be invoked during PEI phase;
651   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
652 
653   If there is no additional space for HOB creation, then ASSERT().
654 
655   @param  SizeOfMemorySpace   The maximum physical memory addressability of the processor.
656   @param  SizeOfIoSpace       The maximum physical I/O addressability of the processor.
657 
658 **/
659 VOID
660 EFIAPI
BuildCpuHob(IN UINT8 SizeOfMemorySpace,IN UINT8 SizeOfIoSpace)661 BuildCpuHob (
662   IN UINT8                       SizeOfMemorySpace,
663   IN UINT8                       SizeOfIoSpace
664   )
665 {
666   EFI_HOB_CPU  *Hob;
667 
668   Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CPU, (UINT16) sizeof (EFI_HOB_CPU));
669   if (Hob == NULL) {
670     return;
671   }
672 
673   Hob->SizeOfMemorySpace = SizeOfMemorySpace;
674   Hob->SizeOfIoSpace     = SizeOfIoSpace;
675 
676   //
677   // Zero the reserved space to match HOB spec
678   //
679   ZeroMem (Hob->Reserved, sizeof (Hob->Reserved));
680 }
681 
682 /**
683   Builds a HOB for the Stack.
684 
685   This function builds a HOB for the stack.
686   It can only be invoked during PEI phase;
687   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
688 
689   If there is no additional space for HOB creation, then ASSERT().
690 
691   @param  BaseAddress   The 64 bit physical address of the Stack.
692   @param  Length        The length of the stack in bytes.
693 
694 **/
695 VOID
696 EFIAPI
BuildStackHob(IN EFI_PHYSICAL_ADDRESS BaseAddress,IN UINT64 Length)697 BuildStackHob (
698   IN EFI_PHYSICAL_ADDRESS        BaseAddress,
699   IN UINT64                      Length
700   )
701 {
702   EFI_HOB_MEMORY_ALLOCATION_STACK  *Hob;
703 
704   ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&
705           ((Length & (EFI_PAGE_SIZE - 1)) == 0));
706 
707   Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK));
708   if (Hob == NULL) {
709     return;
710   }
711 
712   CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocStackGuid);
713   Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
714   Hob->AllocDescriptor.MemoryLength      = Length;
715   Hob->AllocDescriptor.MemoryType        = EfiBootServicesData;
716 
717   //
718   // Zero the reserved space to match HOB spec
719   //
720   ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));
721 }
722 
723 /**
724   Builds a HOB for the BSP store.
725 
726   This function builds a HOB for BSP store.
727   It can only be invoked during PEI phase;
728   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
729 
730   If there is no additional space for HOB creation, then ASSERT().
731 
732   @param  BaseAddress   The 64 bit physical address of the BSP.
733   @param  Length        The length of the BSP store in bytes.
734   @param  MemoryType    Type of memory allocated by this HOB.
735 
736 **/
737 VOID
738 EFIAPI
BuildBspStoreHob(IN EFI_PHYSICAL_ADDRESS BaseAddress,IN UINT64 Length,IN EFI_MEMORY_TYPE MemoryType)739 BuildBspStoreHob (
740   IN EFI_PHYSICAL_ADDRESS        BaseAddress,
741   IN UINT64                      Length,
742   IN EFI_MEMORY_TYPE             MemoryType
743   )
744 {
745   EFI_HOB_MEMORY_ALLOCATION_BSP_STORE  *Hob;
746 
747   ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&
748           ((Length & (EFI_PAGE_SIZE - 1)) == 0));
749 
750   Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_BSP_STORE));
751   if (Hob == NULL) {
752     return;
753   }
754 
755   CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocBspStoreGuid);
756   Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
757   Hob->AllocDescriptor.MemoryLength      = Length;
758   Hob->AllocDescriptor.MemoryType        = MemoryType;
759 
760   //
761   // Zero the reserved space to match HOB spec
762   //
763   ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));
764 }
765 
766 /**
767   Builds a HOB for the memory allocation.
768 
769   This function builds a HOB for the memory allocation.
770   It can only be invoked during PEI phase;
771   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
772 
773   If there is no additional space for HOB creation, then ASSERT().
774 
775   @param  BaseAddress   The 64 bit physical address of the memory.
776   @param  Length        The length of the memory allocation in bytes.
777   @param  MemoryType    Type of memory allocated by this HOB.
778 
779 **/
780 VOID
781 EFIAPI
BuildMemoryAllocationHob(IN EFI_PHYSICAL_ADDRESS BaseAddress,IN UINT64 Length,IN EFI_MEMORY_TYPE MemoryType)782 BuildMemoryAllocationHob (
783   IN EFI_PHYSICAL_ADDRESS        BaseAddress,
784   IN UINT64                      Length,
785   IN EFI_MEMORY_TYPE             MemoryType
786   )
787 {
788   EFI_HOB_MEMORY_ALLOCATION  *Hob;
789 
790   ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&
791           ((Length & (EFI_PAGE_SIZE - 1)) == 0));
792 
793   Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION));
794   if (Hob == NULL) {
795     return;
796   }
797 
798   ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));
799   Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
800   Hob->AllocDescriptor.MemoryLength      = Length;
801   Hob->AllocDescriptor.MemoryType        = MemoryType;
802   //
803   // Zero the reserved space to match HOB spec
804   //
805   ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));
806 }
807