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