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