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