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