]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiHobLib/HobLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / PeiHobLib / HobLib.c
1 /** @file
2 Provide Hob Library functions for Pei phase.
3
4 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <PiPei.h>
10
11 #include <Guid/MemoryAllocationHob.h>
12
13 #include <Library/HobLib.h>
14 #include <Library/DebugLib.h>
15 #include <Library/PeiServicesLib.h>
16 #include <Library/BaseMemoryLib.h>
17
18 /**
19 Returns the pointer to the HOB list.
20
21 This function returns the pointer to first HOB in the list.
22 For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer
23 to the HOB list. For the DXE phase, the HOB list pointer can be retrieved through
24 the EFI System Table by looking up theHOB list GUID in the System Configuration Table.
25 Since the System Configuration Table does not exist that the time the DXE Core is
26 launched, the DXE Core uses a global variable from the DXE Core Entry Point Library
27 to manage the pointer to the HOB list.
28
29 If the pointer to the HOB list is NULL, then ASSERT().
30
31 @return The pointer to the HOB list.
32
33 **/
34 VOID *
35 EFIAPI
36 GetHobList (
37 VOID
38 )
39 {
40 EFI_STATUS Status;
41 VOID *HobList;
42
43 Status = PeiServicesGetHobList (&HobList);
44 ASSERT_EFI_ERROR (Status);
45 ASSERT (HobList != NULL);
46
47 return HobList;
48 }
49
50 /**
51 Returns the next instance of a HOB type from the starting HOB.
52
53 This function searches the first instance of a HOB type from the starting HOB pointer.
54 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
55 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
56 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
57 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
58
59 If HobStart is NULL, then ASSERT().
60
61 @param Type The HOB type to return.
62 @param HobStart The starting HOB pointer to search from.
63
64 @return The next instance of a HOB type from the starting HOB.
65
66 **/
67 VOID *
68 EFIAPI
69 GetNextHob (
70 IN UINT16 Type,
71 IN CONST VOID *HobStart
72 )
73 {
74 EFI_PEI_HOB_POINTERS Hob;
75
76 ASSERT (HobStart != NULL);
77
78 Hob.Raw = (UINT8 *)HobStart;
79 //
80 // Parse the HOB list until end of list or matching type is found.
81 //
82 while (!END_OF_HOB_LIST (Hob)) {
83 if (Hob.Header->HobType == Type) {
84 return Hob.Raw;
85 }
86
87 Hob.Raw = GET_NEXT_HOB (Hob);
88 }
89
90 return NULL;
91 }
92
93 /**
94 Returns the first instance of a HOB type among the whole HOB list.
95
96 This function searches the first instance of a HOB type among the whole HOB list.
97 If there does not exist such HOB type in the HOB list, it will return NULL.
98
99 If the pointer to the HOB list is NULL, then ASSERT().
100
101 @param Type The HOB type to return.
102
103 @return The next instance of a HOB type from the starting HOB.
104
105 **/
106 VOID *
107 EFIAPI
108 GetFirstHob (
109 IN UINT16 Type
110 )
111 {
112 VOID *HobList;
113
114 HobList = GetHobList ();
115 return GetNextHob (Type, HobList);
116 }
117
118 /**
119 Returns the next instance of the matched GUID HOB from the starting HOB.
120
121 This function searches the first instance of a HOB from the starting HOB pointer.
122 Such HOB should satisfy two conditions:
123 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
124 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
125 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
126 to extract the data section and its size information, respectively.
127 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
128 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
129 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
130
131 If Guid is NULL, then ASSERT().
132 If HobStart is NULL, then ASSERT().
133
134 @param Guid The GUID to match with in the HOB list.
135 @param HobStart A pointer to a Guid.
136
137 @return The next instance of the matched GUID HOB from the starting HOB.
138
139 **/
140 VOID *
141 EFIAPI
142 GetNextGuidHob (
143 IN CONST EFI_GUID *Guid,
144 IN CONST VOID *HobStart
145 )
146 {
147 EFI_PEI_HOB_POINTERS GuidHob;
148
149 GuidHob.Raw = (UINT8 *)HobStart;
150 while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {
151 if (CompareGuid (Guid, &GuidHob.Guid->Name)) {
152 break;
153 }
154
155 GuidHob.Raw = GET_NEXT_HOB (GuidHob);
156 }
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 information, 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 //
247 // Assume the process of HOB building is always successful.
248 //
249 ASSERT (Hob != NULL);
250 return Hob;
251 }
252
253 /**
254 Builds a HOB for a loaded PE32 module.
255
256 This function builds a HOB for a loaded PE32 module.
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
260 If ModuleName is NULL, then ASSERT().
261 If there is no additional space for HOB creation, then ASSERT().
262
263 @param ModuleName The GUID File Name of the module.
264 @param MemoryAllocationModule The 64 bit physical address of the module.
265 @param ModuleLength The length of the module in bytes.
266 @param EntryPoint The 64 bit physical address of the module entry point.
267
268 **/
269 VOID
270 EFIAPI
271 BuildModuleHob (
272 IN CONST EFI_GUID *ModuleName,
273 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,
274 IN UINT64 ModuleLength,
275 IN EFI_PHYSICAL_ADDRESS EntryPoint
276 )
277 {
278 EFI_HOB_MEMORY_ALLOCATION_MODULE *Hob;
279
280 ASSERT (
281 ((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) &&
282 ((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0)
283 );
284
285 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16)sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE));
286 if (Hob == NULL) {
287 return;
288 }
289
290 CopyGuid (&(Hob->MemoryAllocationHeader.Name), &gEfiHobMemoryAllocModuleGuid);
291 Hob->MemoryAllocationHeader.MemoryBaseAddress = MemoryAllocationModule;
292 Hob->MemoryAllocationHeader.MemoryLength = ModuleLength;
293 Hob->MemoryAllocationHeader.MemoryType = EfiBootServicesCode;
294
295 //
296 // Zero the reserved space to match HOB spec
297 //
298 ZeroMem (Hob->MemoryAllocationHeader.Reserved, sizeof (Hob->MemoryAllocationHeader.Reserved));
299
300 CopyGuid (&Hob->ModuleName, ModuleName);
301 Hob->EntryPoint = EntryPoint;
302 }
303
304 /**
305 Builds a HOB that describes a chunk of system memory with Owner GUID.
306
307 This function builds a HOB that describes a chunk of system memory.
308 It can only be invoked during PEI phase;
309 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
310
311 If there is no additional space for HOB creation, then ASSERT().
312
313 @param ResourceType The type of resource described by this HOB.
314 @param ResourceAttribute The resource attributes of the memory described by this HOB.
315 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
316 @param NumberOfBytes The length of the memory described by this HOB in bytes.
317 @param OwnerGUID GUID for the owner of this resource.
318
319 **/
320 VOID
321 EFIAPI
322 BuildResourceDescriptorWithOwnerHob (
323 IN EFI_RESOURCE_TYPE ResourceType,
324 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,
325 IN EFI_PHYSICAL_ADDRESS PhysicalStart,
326 IN UINT64 NumberOfBytes,
327 IN EFI_GUID *OwnerGUID
328 )
329 {
330 EFI_HOB_RESOURCE_DESCRIPTOR *Hob;
331
332 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, (UINT16)sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));
333 if (Hob == NULL) {
334 return;
335 }
336
337 Hob->ResourceType = ResourceType;
338 Hob->ResourceAttribute = ResourceAttribute;
339 Hob->PhysicalStart = PhysicalStart;
340 Hob->ResourceLength = NumberOfBytes;
341
342 CopyGuid (&Hob->Owner, OwnerGUID);
343 }
344
345 /**
346 Builds a HOB that describes a chunk of system memory.
347
348 This function builds a HOB that describes a chunk of system memory.
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.
351
352 If there is no additional space for HOB creation, then ASSERT().
353
354 @param ResourceType The type of resource described by this HOB.
355 @param ResourceAttribute The resource attributes of the memory described by this HOB.
356 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
357 @param NumberOfBytes The length of the memory described by this HOB in bytes.
358
359 **/
360 VOID
361 EFIAPI
362 BuildResourceDescriptorHob (
363 IN EFI_RESOURCE_TYPE ResourceType,
364 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,
365 IN EFI_PHYSICAL_ADDRESS PhysicalStart,
366 IN UINT64 NumberOfBytes
367 )
368 {
369 EFI_HOB_RESOURCE_DESCRIPTOR *Hob;
370
371 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, (UINT16)sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));
372 if (Hob == NULL) {
373 return;
374 }
375
376 Hob->ResourceType = ResourceType;
377 Hob->ResourceAttribute = ResourceAttribute;
378 Hob->PhysicalStart = PhysicalStart;
379 Hob->ResourceLength = NumberOfBytes;
380 ZeroMem (&(Hob->Owner), sizeof (EFI_GUID));
381 }
382
383 /**
384 Builds a customized HOB tagged with a GUID for identification and returns
385 the start address of GUID HOB data.
386
387 This function builds a customized HOB tagged with a GUID for identification
388 and returns the start address of GUID HOB data so that caller can fill the customized data.
389 The HOB Header and Name field is already stripped.
390 It can only be invoked during PEI phase;
391 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
392
393 If Guid is NULL, then ASSERT().
394 If there is no additional space for HOB creation, then ASSERT().
395 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
396 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
397
398 @param Guid The GUID to tag the customized HOB.
399 @param DataLength The size of the data payload for the GUID HOB.
400
401 @retval NULL The GUID HOB could not be allocated.
402 @retval others The start address of GUID HOB data.
403
404 **/
405 VOID *
406 EFIAPI
407 BuildGuidHob (
408 IN CONST EFI_GUID *Guid,
409 IN UINTN DataLength
410 )
411 {
412 EFI_HOB_GUID_TYPE *Hob;
413
414 //
415 // Make sure Guid is valid
416 //
417 ASSERT (Guid != NULL);
418
419 //
420 // Make sure that data length is not too long.
421 //
422 ASSERT (DataLength <= (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)));
423
424 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16)(sizeof (EFI_HOB_GUID_TYPE) + DataLength));
425 if (Hob == NULL) {
426 return Hob;
427 }
428
429 CopyGuid (&Hob->Name, Guid);
430 return Hob + 1;
431 }
432
433 /**
434 Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB
435 data field, and returns the start address of the GUID HOB data.
436
437 This function builds a customized HOB tagged with a GUID for identification and copies the input
438 data to the HOB data field and returns the start address of the GUID HOB data. It can only be
439 invoked during PEI phase; for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
440 The HOB Header and Name field is already stripped.
441 It can only be invoked during PEI phase;
442 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
443
444 If Guid is NULL, then ASSERT().
445 If Data is NULL and DataLength > 0, then ASSERT().
446 If there is no additional space for HOB creation, then ASSERT().
447 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
448 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
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
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
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
517 if ((UINTN)BaseAddress % FvAlignment != 0) {
518 //
519 // FvImage buffer is not at its required alignment.
520 //
521 DEBUG ((
522 DEBUG_ERROR,
523 "Unaligned FvImage found at 0x%lx:0x%lx, the required alignment is 0x%x\n",
524 BaseAddress,
525 Length,
526 FvAlignment
527 ));
528 return FALSE;
529 }
530 }
531
532 return TRUE;
533 }
534
535 /**
536 Builds a Firmware Volume HOB.
537
538 This function builds a Firmware Volume HOB.
539 It can only be invoked during PEI phase;
540 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
541
542 If there is no additional space for HOB creation, then ASSERT().
543 If the FvImage buffer is not at its required alignment, then ASSERT().
544
545 @param BaseAddress The base address of the Firmware Volume.
546 @param Length The size of the Firmware Volume in bytes.
547
548 **/
549 VOID
550 EFIAPI
551 BuildFvHob (
552 IN EFI_PHYSICAL_ADDRESS BaseAddress,
553 IN UINT64 Length
554 )
555 {
556 EFI_HOB_FIRMWARE_VOLUME *Hob;
557
558 if (!InternalCheckFvAlignment (BaseAddress, Length)) {
559 ASSERT (FALSE);
560 return;
561 }
562
563 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV, (UINT16)sizeof (EFI_HOB_FIRMWARE_VOLUME));
564 if (Hob == NULL) {
565 return;
566 }
567
568 Hob->BaseAddress = BaseAddress;
569 Hob->Length = Length;
570 }
571
572 /**
573 Builds a EFI_HOB_TYPE_FV2 HOB.
574
575 This function builds a EFI_HOB_TYPE_FV2 HOB.
576 It can only be invoked during PEI phase;
577 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
578
579 If there is no additional space for HOB creation, then ASSERT().
580 If the FvImage buffer is not at its required alignment, then ASSERT().
581
582 @param BaseAddress The base address of the Firmware Volume.
583 @param Length The size of the Firmware Volume in bytes.
584 @param FvName The name of the Firmware Volume.
585 @param FileName The name of the file.
586
587 **/
588 VOID
589 EFIAPI
590 BuildFv2Hob (
591 IN EFI_PHYSICAL_ADDRESS BaseAddress,
592 IN UINT64 Length,
593 IN CONST EFI_GUID *FvName,
594 IN CONST EFI_GUID *FileName
595 )
596 {
597 EFI_HOB_FIRMWARE_VOLUME2 *Hob;
598
599 if (!InternalCheckFvAlignment (BaseAddress, Length)) {
600 ASSERT (FALSE);
601 return;
602 }
603
604 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV2, (UINT16)sizeof (EFI_HOB_FIRMWARE_VOLUME2));
605 if (Hob == NULL) {
606 return;
607 }
608
609 Hob->BaseAddress = BaseAddress;
610 Hob->Length = Length;
611 CopyGuid (&Hob->FvName, FvName);
612 CopyGuid (&Hob->FileName, FileName);
613 }
614
615 /**
616 Builds a EFI_HOB_TYPE_FV3 HOB.
617
618 This function builds a EFI_HOB_TYPE_FV3 HOB.
619 It can only be invoked during PEI phase;
620 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
621
622 If there is no additional space for HOB creation, then ASSERT().
623 If the FvImage buffer is not at its required alignment, then ASSERT().
624
625 @param BaseAddress The base address of the Firmware Volume.
626 @param Length The size of the Firmware Volume in bytes.
627 @param AuthenticationStatus The authentication status.
628 @param ExtractedFv TRUE if the FV was extracted as a file within
629 another firmware volume. FALSE otherwise.
630 @param FvName The name of the Firmware Volume.
631 Valid only if IsExtractedFv is TRUE.
632 @param FileName The name of the file.
633 Valid only if IsExtractedFv is TRUE.
634
635 **/
636 VOID
637 EFIAPI
638 BuildFv3Hob (
639 IN EFI_PHYSICAL_ADDRESS BaseAddress,
640 IN UINT64 Length,
641 IN UINT32 AuthenticationStatus,
642 IN BOOLEAN ExtractedFv,
643 IN CONST EFI_GUID *FvName OPTIONAL,
644 IN CONST EFI_GUID *FileName OPTIONAL
645 )
646 {
647 EFI_HOB_FIRMWARE_VOLUME3 *Hob;
648
649 if (!InternalCheckFvAlignment (BaseAddress, Length)) {
650 ASSERT (FALSE);
651 return;
652 }
653
654 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV3, (UINT16)sizeof (EFI_HOB_FIRMWARE_VOLUME3));
655 if (Hob == NULL) {
656 return;
657 }
658
659 Hob->BaseAddress = BaseAddress;
660 Hob->Length = Length;
661 Hob->AuthenticationStatus = AuthenticationStatus;
662 Hob->ExtractedFv = ExtractedFv;
663 if (ExtractedFv) {
664 CopyGuid (&Hob->FvName, FvName);
665 CopyGuid (&Hob->FileName, FileName);
666 }
667 }
668
669 /**
670 Builds a Capsule Volume HOB.
671
672 This function builds a Capsule Volume HOB.
673 It can only be invoked during PEI phase;
674 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
675
676 If the platform does not support Capsule Volume HOBs, then ASSERT().
677 If there is no additional space for HOB creation, then ASSERT().
678
679 @param BaseAddress The base address of the Capsule Volume.
680 @param Length The size of the Capsule Volume in bytes.
681
682 **/
683 VOID
684 EFIAPI
685 BuildCvHob (
686 IN EFI_PHYSICAL_ADDRESS BaseAddress,
687 IN UINT64 Length
688 )
689 {
690 EFI_HOB_UEFI_CAPSULE *Hob;
691
692 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_UEFI_CAPSULE, (UINT16)sizeof (EFI_HOB_UEFI_CAPSULE));
693 if (Hob == NULL) {
694 return;
695 }
696
697 Hob->BaseAddress = BaseAddress;
698 Hob->Length = Length;
699 }
700
701 /**
702 Builds a HOB for the CPU.
703
704 This function builds a HOB for the CPU.
705 It can only be invoked during PEI phase;
706 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
707
708 If there is no additional space for HOB creation, then ASSERT().
709
710 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
711 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
712
713 **/
714 VOID
715 EFIAPI
716 BuildCpuHob (
717 IN UINT8 SizeOfMemorySpace,
718 IN UINT8 SizeOfIoSpace
719 )
720 {
721 EFI_HOB_CPU *Hob;
722
723 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CPU, (UINT16)sizeof (EFI_HOB_CPU));
724 if (Hob == NULL) {
725 return;
726 }
727
728 Hob->SizeOfMemorySpace = SizeOfMemorySpace;
729 Hob->SizeOfIoSpace = SizeOfIoSpace;
730
731 //
732 // Zero the reserved space to match HOB spec
733 //
734 ZeroMem (Hob->Reserved, sizeof (Hob->Reserved));
735 }
736
737 /**
738 Builds a HOB for the Stack.
739
740 This function builds a HOB for the stack.
741 It can only be invoked during PEI phase;
742 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
743
744 If there is no additional space for HOB creation, then ASSERT().
745
746 @param BaseAddress The 64 bit physical address of the Stack.
747 @param Length The length of the stack in bytes.
748
749 **/
750 VOID
751 EFIAPI
752 BuildStackHob (
753 IN EFI_PHYSICAL_ADDRESS BaseAddress,
754 IN UINT64 Length
755 )
756 {
757 EFI_HOB_MEMORY_ALLOCATION_STACK *Hob;
758
759 ASSERT (
760 ((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&
761 ((Length & (EFI_PAGE_SIZE - 1)) == 0)
762 );
763
764 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16)sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK));
765 if (Hob == NULL) {
766 return;
767 }
768
769 CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocStackGuid);
770 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
771 Hob->AllocDescriptor.MemoryLength = Length;
772 Hob->AllocDescriptor.MemoryType = EfiBootServicesData;
773
774 //
775 // Zero the reserved space to match HOB spec
776 //
777 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));
778 }
779
780 /**
781 Builds a HOB for the BSP store.
782
783 This function builds a HOB for BSP store.
784 It can only be invoked during PEI phase;
785 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
786
787 If there is no additional space for HOB creation, then ASSERT().
788
789 @param BaseAddress The 64 bit physical address of the BSP.
790 @param Length The length of the BSP store in bytes.
791 @param MemoryType The type of memory allocated by this HOB.
792
793 **/
794 VOID
795 EFIAPI
796 BuildBspStoreHob (
797 IN EFI_PHYSICAL_ADDRESS BaseAddress,
798 IN UINT64 Length,
799 IN EFI_MEMORY_TYPE MemoryType
800 )
801 {
802 EFI_HOB_MEMORY_ALLOCATION_BSP_STORE *Hob;
803
804 ASSERT (
805 ((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&
806 ((Length & (EFI_PAGE_SIZE - 1)) == 0)
807 );
808
809 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16)sizeof (EFI_HOB_MEMORY_ALLOCATION_BSP_STORE));
810 if (Hob == NULL) {
811 return;
812 }
813
814 CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocBspStoreGuid);
815 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
816 Hob->AllocDescriptor.MemoryLength = Length;
817 Hob->AllocDescriptor.MemoryType = MemoryType;
818
819 //
820 // Zero the reserved space to match HOB spec
821 //
822 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));
823 }
824
825 /**
826 Builds a HOB for the memory allocation.
827
828 This function builds a HOB for the memory allocation.
829 It can only be invoked during PEI phase;
830 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
831
832 If there is no additional space for HOB creation, then ASSERT().
833
834 @param BaseAddress The 64 bit physical address of the memory.
835 @param Length The length of the memory allocation in bytes.
836 @param MemoryType The type of memory allocated by this HOB.
837
838 **/
839 VOID
840 EFIAPI
841 BuildMemoryAllocationHob (
842 IN EFI_PHYSICAL_ADDRESS BaseAddress,
843 IN UINT64 Length,
844 IN EFI_MEMORY_TYPE MemoryType
845 )
846 {
847 EFI_HOB_MEMORY_ALLOCATION *Hob;
848
849 ASSERT (
850 ((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&
851 ((Length & (EFI_PAGE_SIZE - 1)) == 0)
852 );
853
854 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16)sizeof (EFI_HOB_MEMORY_ALLOCATION));
855 if (Hob == NULL) {
856 return;
857 }
858
859 ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));
860 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
861 Hob->AllocDescriptor.MemoryLength = Length;
862 Hob->AllocDescriptor.MemoryType = MemoryType;
863 //
864 // Zero the reserved space to match HOB spec
865 //
866 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));
867 }