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