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