]> git.proxmox.com Git - mirror_edk2.git/blob - UefiPayloadPkg/Library/PayloadEntryHobLib/Hob.c
UefiPayloadPkg: Fix ECC reported issues
[mirror_edk2.git] / UefiPayloadPkg / Library / PayloadEntryHobLib / Hob.c
1 /** @file
2
3 Copyright (c) 2010, Apple Inc. All rights reserved.<BR>
4 Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include <PiPei.h>
11
12 #include <Library/BaseLib.h>
13 #include <Library/BaseMemoryLib.h>
14 #include <Library/DebugLib.h>
15 #include <Library/HobLib.h>
16 #include <Library/PcdLib.h>
17
18 VOID *mHobList;
19
20 /**
21 Returns the pointer to the HOB list.
22
23 This function returns the pointer to first HOB in the list.
24
25 @return The pointer to the HOB list.
26
27 **/
28 VOID *
29 EFIAPI
30 GetHobList (
31 VOID
32 )
33 {
34 ASSERT (mHobList != NULL);
35 return mHobList;
36 }
37
38
39 /**
40 Build a Handoff Information Table HOB
41
42 This function initialize a HOB region from EfiMemoryBegin to
43 EfiMemoryTop. And EfiFreeMemoryBottom and EfiFreeMemoryTop should
44 be inside the HOB region.
45
46 @param[in] EfiMemoryBottom Total memory start address
47 @param[in] EfiMemoryTop Total memory end address.
48 @param[in] EfiFreeMemoryBottom Free memory start address
49 @param[in] EfiFreeMemoryTop Free memory end address.
50
51 @return The pointer to the handoff HOB table.
52
53 **/
54 EFI_HOB_HANDOFF_INFO_TABLE*
55 EFIAPI
56 HobConstructor (
57 IN VOID *EfiMemoryBottom,
58 IN VOID *EfiMemoryTop,
59 IN VOID *EfiFreeMemoryBottom,
60 IN VOID *EfiFreeMemoryTop
61 )
62 {
63 EFI_HOB_HANDOFF_INFO_TABLE *Hob;
64 EFI_HOB_GENERIC_HEADER *HobEnd;
65
66 Hob = EfiFreeMemoryBottom;
67 HobEnd = (EFI_HOB_GENERIC_HEADER *)(Hob+1);
68
69 Hob->Header.HobType = EFI_HOB_TYPE_HANDOFF;
70 Hob->Header.HobLength = sizeof(EFI_HOB_HANDOFF_INFO_TABLE);
71 Hob->Header.Reserved = 0;
72
73 HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
74 HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER);
75 HobEnd->Reserved = 0;
76
77 Hob->Version = EFI_HOB_HANDOFF_TABLE_VERSION;
78 Hob->BootMode = BOOT_WITH_FULL_CONFIGURATION;
79
80 Hob->EfiMemoryTop = (EFI_PHYSICAL_ADDRESS) (UINTN) EfiMemoryTop;
81 Hob->EfiMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) EfiMemoryBottom;
82 Hob->EfiFreeMemoryTop = (EFI_PHYSICAL_ADDRESS) (UINTN) EfiFreeMemoryTop;
83 Hob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) (HobEnd+1);
84 Hob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
85
86 mHobList = Hob;
87 return Hob;
88 }
89
90 /**
91 Add a new HOB to the HOB List.
92
93 @param HobType Type of the new HOB.
94 @param HobLength Length of the new HOB to allocate.
95
96 @return NULL if there is no space to create a hob.
97 @return The address point to the new created hob.
98
99 **/
100 VOID *
101 EFIAPI
102 CreateHob (
103 IN UINT16 HobType,
104 IN UINT16 HobLength
105 )
106 {
107 EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
108 EFI_HOB_GENERIC_HEADER *HobEnd;
109 EFI_PHYSICAL_ADDRESS FreeMemory;
110 VOID *Hob;
111
112 HandOffHob = GetHobList ();
113
114 HobLength = (UINT16)((HobLength + 0x7) & (~0x7));
115
116 FreeMemory = HandOffHob->EfiFreeMemoryTop - HandOffHob->EfiFreeMemoryBottom;
117
118 if (FreeMemory < HobLength) {
119 return NULL;
120 }
121
122 Hob = (VOID*) (UINTN) HandOffHob->EfiEndOfHobList;
123 ((EFI_HOB_GENERIC_HEADER*) Hob)->HobType = HobType;
124 ((EFI_HOB_GENERIC_HEADER*) Hob)->HobLength = HobLength;
125 ((EFI_HOB_GENERIC_HEADER*) Hob)->Reserved = 0;
126
127 HobEnd = (EFI_HOB_GENERIC_HEADER*) ((UINTN)Hob + HobLength);
128 HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
129
130 HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
131 HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER);
132 HobEnd->Reserved = 0;
133 HobEnd++;
134 HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
135
136 return Hob;
137 }
138
139 /**
140 Builds a HOB that describes a chunk of system memory.
141
142 This function builds a HOB that describes a chunk of system memory.
143 If there is no additional space for HOB creation, then ASSERT().
144
145 @param ResourceType The type of resource described by this HOB.
146 @param ResourceAttribute The resource attributes of the memory described by this HOB.
147 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
148 @param NumberOfBytes The length of the memory described by this HOB in bytes.
149
150 **/
151 VOID
152 EFIAPI
153 BuildResourceDescriptorHob (
154 IN EFI_RESOURCE_TYPE ResourceType,
155 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,
156 IN EFI_PHYSICAL_ADDRESS PhysicalStart,
157 IN UINT64 NumberOfBytes
158 )
159 {
160 EFI_HOB_RESOURCE_DESCRIPTOR *Hob;
161
162 Hob = CreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));
163 ASSERT(Hob != NULL);
164
165 Hob->ResourceType = ResourceType;
166 Hob->ResourceAttribute = ResourceAttribute;
167 Hob->PhysicalStart = PhysicalStart;
168 Hob->ResourceLength = NumberOfBytes;
169 }
170
171 /**
172 Returns the next instance of a HOB type from the starting HOB.
173
174 This function searches the first instance of a HOB type from the starting HOB pointer.
175 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
176 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
177 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
178 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
179 If HobStart is NULL, then ASSERT().
180
181 @param Type The HOB type to return.
182 @param HobStart The starting HOB pointer to search from.
183
184 @return The next instance of a HOB type from the starting HOB.
185
186 **/
187 VOID *
188 EFIAPI
189 GetNextHob (
190 IN UINT16 Type,
191 IN CONST VOID *HobStart
192 )
193 {
194 EFI_PEI_HOB_POINTERS Hob;
195
196 ASSERT (HobStart != NULL);
197
198 Hob.Raw = (UINT8 *) HobStart;
199 //
200 // Parse the HOB list until end of list or matching type is found.
201 //
202 while (!END_OF_HOB_LIST (Hob)) {
203 if (Hob.Header->HobType == Type) {
204 return Hob.Raw;
205 }
206 Hob.Raw = GET_NEXT_HOB (Hob);
207 }
208 return NULL;
209 }
210
211
212
213 /**
214 Returns the first instance of a HOB type among the whole HOB list.
215
216 This function searches the first instance of a HOB type among the whole HOB list.
217 If there does not exist such HOB type in the HOB list, it will return NULL.
218
219 @param Type The HOB type to return.
220
221 @return The next instance of a HOB type from the starting HOB.
222
223 **/
224 VOID *
225 EFIAPI
226 GetFirstHob (
227 IN UINT16 Type
228 )
229 {
230 VOID *HobList;
231
232 HobList = GetHobList ();
233 return GetNextHob (Type, HobList);
234 }
235
236
237 /**
238 This function searches the first instance of a HOB from the starting HOB pointer.
239 Such HOB should satisfy two conditions:
240 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
241 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
242 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
243 to extract the data section and its size info respectively.
244 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
245 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
246 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
247 If Guid is NULL, then ASSERT().
248 If HobStart is NULL, then ASSERT().
249
250 @param Guid The GUID to match with in the HOB list.
251 @param HobStart A pointer to a Guid.
252
253 @return The next instance of the matched GUID HOB from the starting HOB.
254
255 **/
256 VOID *
257 EFIAPI
258 GetNextGuidHob (
259 IN CONST EFI_GUID *Guid,
260 IN CONST VOID *HobStart
261 )
262 {
263 EFI_PEI_HOB_POINTERS GuidHob;
264
265 GuidHob.Raw = (UINT8 *) HobStart;
266 while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {
267 if (CompareGuid (Guid, &GuidHob.Guid->Name)) {
268 break;
269 }
270 GuidHob.Raw = GET_NEXT_HOB (GuidHob);
271 }
272 return GuidHob.Raw;
273 }
274
275
276 /**
277 This function searches the first instance of a HOB among the whole HOB list.
278 Such HOB should satisfy two conditions:
279 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
280 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
281 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
282 to extract the data section and its size info respectively.
283 If Guid is NULL, then ASSERT().
284
285 @param Guid The GUID to match with in the HOB list.
286
287 @return The first instance of the matched GUID HOB among the whole HOB list.
288
289 **/
290 VOID *
291 EFIAPI
292 GetFirstGuidHob (
293 IN CONST EFI_GUID *Guid
294 )
295 {
296 VOID *HobList;
297
298 HobList = GetHobList ();
299 return GetNextGuidHob (Guid, HobList);
300 }
301
302
303
304
305 /**
306 Builds a HOB for a loaded PE32 module.
307
308 This function builds a HOB for a loaded PE32 module.
309 It can only be invoked during PEI phase;
310 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
311 If ModuleName is NULL, then ASSERT().
312 If there is no additional space for HOB creation, then ASSERT().
313
314 @param ModuleName The GUID File Name of the module.
315 @param MemoryAllocationModule The 64 bit physical address of the module.
316 @param ModuleLength The length of the module in bytes.
317 @param EntryPoint The 64 bit physical address of the module entry point.
318
319 **/
320 VOID
321 EFIAPI
322 BuildModuleHob (
323 IN CONST EFI_GUID *ModuleName,
324 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,
325 IN UINT64 ModuleLength,
326 IN EFI_PHYSICAL_ADDRESS EntryPoint
327 )
328 {
329 EFI_HOB_MEMORY_ALLOCATION_MODULE *Hob;
330
331 ASSERT (((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) &&
332 ((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0));
333
334 Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE));
335
336 CopyGuid (&(Hob->MemoryAllocationHeader.Name), &gEfiHobMemoryAllocModuleGuid);
337 Hob->MemoryAllocationHeader.MemoryBaseAddress = MemoryAllocationModule;
338 Hob->MemoryAllocationHeader.MemoryLength = ModuleLength;
339 Hob->MemoryAllocationHeader.MemoryType = EfiBootServicesCode;
340
341 //
342 // Zero the reserved space to match HOB spec
343 //
344 ZeroMem (Hob->MemoryAllocationHeader.Reserved, sizeof (Hob->MemoryAllocationHeader.Reserved));
345
346 CopyGuid (&Hob->ModuleName, ModuleName);
347 Hob->EntryPoint = EntryPoint;
348 }
349
350 /**
351 Builds a GUID HOB with a certain data length.
352
353 This function builds a customized HOB tagged with a GUID for identification
354 and returns the start address of GUID HOB data so that caller can fill the customized data.
355 The HOB Header and Name field is already stripped.
356 It can only be invoked during PEI phase;
357 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
358 If Guid is NULL, then ASSERT().
359 If there is no additional space for HOB creation, then ASSERT().
360 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
361
362 @param Guid The GUID to tag the customized HOB.
363 @param DataLength The size of the data payload for the GUID HOB.
364
365 @return The start address of GUID HOB data.
366
367 **/
368 VOID *
369 EFIAPI
370 BuildGuidHob (
371 IN CONST EFI_GUID *Guid,
372 IN UINTN DataLength
373 )
374 {
375 EFI_HOB_GUID_TYPE *Hob;
376
377 //
378 // Make sure that data length is not too long.
379 //
380 ASSERT (DataLength <= (0xffff - sizeof (EFI_HOB_GUID_TYPE)));
381
382 Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16) (sizeof (EFI_HOB_GUID_TYPE) + DataLength));
383 CopyGuid (&Hob->Name, Guid);
384 return Hob + 1;
385 }
386
387
388 /**
389 Copies a data buffer to a newly-built HOB.
390
391 This function builds a customized HOB tagged with a GUID for identification,
392 copies the input data to the HOB data field and returns the start address of the GUID HOB data.
393 The HOB Header and Name field is already stripped.
394 It can only be invoked during PEI phase;
395 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
396 If Guid is NULL, then ASSERT().
397 If Data is NULL and DataLength > 0, then ASSERT().
398 If there is no additional space for HOB creation, then ASSERT().
399 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
400
401 @param Guid The GUID to tag the customized HOB.
402 @param Data The data to be copied into the data field of the GUID HOB.
403 @param DataLength The size of the data payload for the GUID HOB.
404
405 @return The start address of GUID HOB data.
406
407 **/
408 VOID *
409 EFIAPI
410 BuildGuidDataHob (
411 IN CONST EFI_GUID *Guid,
412 IN VOID *Data,
413 IN UINTN DataLength
414 )
415 {
416 VOID *HobData;
417
418 ASSERT (Data != NULL || DataLength == 0);
419
420 HobData = BuildGuidHob (Guid, DataLength);
421
422 return CopyMem (HobData, Data, DataLength);
423 }
424
425
426 /**
427 Builds a Firmware Volume HOB.
428
429 This function builds a Firmware Volume HOB.
430 It can only be invoked during PEI phase;
431 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
432 If there is no additional space for HOB creation, then ASSERT().
433
434 @param BaseAddress The base address of the Firmware Volume.
435 @param Length The size of the Firmware Volume in bytes.
436
437 **/
438 VOID
439 EFIAPI
440 BuildFvHob (
441 IN EFI_PHYSICAL_ADDRESS BaseAddress,
442 IN UINT64 Length
443 )
444 {
445 EFI_HOB_FIRMWARE_VOLUME *Hob;
446
447 Hob = CreateHob (EFI_HOB_TYPE_FV, sizeof (EFI_HOB_FIRMWARE_VOLUME));
448
449 Hob->BaseAddress = BaseAddress;
450 Hob->Length = Length;
451 }
452
453
454 /**
455 Builds a EFI_HOB_TYPE_FV2 HOB.
456
457 This function builds a EFI_HOB_TYPE_FV2 HOB.
458 It can only be invoked during PEI phase;
459 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
460 If there is no additional space for HOB creation, then ASSERT().
461
462 @param BaseAddress The base address of the Firmware Volume.
463 @param Length The size of the Firmware Volume in bytes.
464 @param FvName The name of the Firmware Volume.
465 @param FileName The name of the file.
466
467 **/
468 VOID
469 EFIAPI
470 BuildFv2Hob (
471 IN EFI_PHYSICAL_ADDRESS BaseAddress,
472 IN UINT64 Length,
473 IN CONST EFI_GUID *FvName,
474 IN CONST EFI_GUID *FileName
475 )
476 {
477 EFI_HOB_FIRMWARE_VOLUME2 *Hob;
478
479 Hob = CreateHob (EFI_HOB_TYPE_FV2, sizeof (EFI_HOB_FIRMWARE_VOLUME2));
480
481 Hob->BaseAddress = BaseAddress;
482 Hob->Length = Length;
483 CopyGuid (&Hob->FvName, FvName);
484 CopyGuid (&Hob->FileName, FileName);
485 }
486
487 /**
488 Builds a EFI_HOB_TYPE_FV3 HOB.
489
490 This function builds a EFI_HOB_TYPE_FV3 HOB.
491 It can only be invoked during PEI phase;
492 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
493
494 If there is no additional space for HOB creation, then ASSERT().
495
496 @param BaseAddress The base address of the Firmware Volume.
497 @param Length The size of the Firmware Volume in bytes.
498 @param AuthenticationStatus The authentication status.
499 @param ExtractedFv TRUE if the FV was extracted as a file within
500 another firmware volume. FALSE otherwise.
501 @param FvName The name of the Firmware Volume.
502 Valid only if IsExtractedFv is TRUE.
503 @param FileName The name of the file.
504 Valid only if IsExtractedFv is TRUE.
505
506 **/
507 VOID
508 EFIAPI
509 BuildFv3Hob (
510 IN EFI_PHYSICAL_ADDRESS BaseAddress,
511 IN UINT64 Length,
512 IN UINT32 AuthenticationStatus,
513 IN BOOLEAN ExtractedFv,
514 IN CONST EFI_GUID *FvName, OPTIONAL
515 IN CONST EFI_GUID *FileName OPTIONAL
516 )
517 {
518 EFI_HOB_FIRMWARE_VOLUME3 *Hob;
519
520 Hob = CreateHob (EFI_HOB_TYPE_FV3, sizeof (EFI_HOB_FIRMWARE_VOLUME3));
521
522 Hob->BaseAddress = BaseAddress;
523 Hob->Length = Length;
524 Hob->AuthenticationStatus = AuthenticationStatus;
525 Hob->ExtractedFv = ExtractedFv;
526 if (ExtractedFv) {
527 CopyGuid (&Hob->FvName, FvName);
528 CopyGuid (&Hob->FileName, FileName);
529 }
530 }
531
532
533 /**
534 Builds a HOB for the CPU.
535
536 This function builds a HOB for the CPU.
537 It can only be invoked during PEI phase;
538 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
539 If there is no additional space for HOB creation, then ASSERT().
540
541 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
542 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
543
544 **/
545 VOID
546 EFIAPI
547 BuildCpuHob (
548 IN UINT8 SizeOfMemorySpace,
549 IN UINT8 SizeOfIoSpace
550 )
551 {
552 EFI_HOB_CPU *Hob;
553
554 Hob = CreateHob (EFI_HOB_TYPE_CPU, sizeof (EFI_HOB_CPU));
555
556 Hob->SizeOfMemorySpace = SizeOfMemorySpace;
557 Hob->SizeOfIoSpace = SizeOfIoSpace;
558
559 //
560 // Zero the reserved space to match HOB spec
561 //
562 ZeroMem (Hob->Reserved, sizeof (Hob->Reserved));
563 }
564
565
566 /**
567 Builds a HOB for the Stack.
568
569 This function builds a HOB for the stack.
570 It can only be invoked during PEI phase;
571 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
572 If there is no additional space for HOB creation, then ASSERT().
573
574 @param BaseAddress The 64 bit physical address of the Stack.
575 @param Length The length of the stack in bytes.
576
577 **/
578 VOID
579 EFIAPI
580 BuildStackHob (
581 IN EFI_PHYSICAL_ADDRESS BaseAddress,
582 IN UINT64 Length
583 )
584 {
585 EFI_HOB_MEMORY_ALLOCATION_STACK *Hob;
586
587 ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&
588 ((Length & (EFI_PAGE_SIZE - 1)) == 0));
589
590 Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK));
591
592 CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocStackGuid);
593 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
594 Hob->AllocDescriptor.MemoryLength = Length;
595 Hob->AllocDescriptor.MemoryType = EfiBootServicesData;
596
597 //
598 // Zero the reserved space to match HOB spec
599 //
600 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));
601 }
602
603
604 /**
605 Update the Stack Hob if the stack has been moved
606
607 @param BaseAddress The 64 bit physical address of the Stack.
608 @param Length The length of the stack in bytes.
609
610 **/
611 VOID
612 EFIAPI
613 UpdateStackHob (
614 IN EFI_PHYSICAL_ADDRESS BaseAddress,
615 IN UINT64 Length
616 )
617 {
618 EFI_PEI_HOB_POINTERS Hob;
619
620 Hob.Raw = GetHobList ();
621 while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) {
622 if (CompareGuid (&gEfiHobMemoryAllocStackGuid, &(Hob.MemoryAllocationStack->AllocDescriptor.Name))) {
623 //
624 // Build a new memory allocation HOB with old stack info with EfiConventionalMemory type
625 // to be reclaimed by DXE core.
626 //
627 BuildMemoryAllocationHob (
628 Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress,
629 Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength,
630 EfiConventionalMemory
631 );
632 //
633 // Update the BSP Stack Hob to reflect the new stack info.
634 //
635 Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress = BaseAddress;
636 Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength = Length;
637 break;
638 }
639 Hob.Raw = GET_NEXT_HOB (Hob);
640 }
641 }
642
643
644
645 /**
646 Builds a HOB for the memory allocation.
647
648 This function builds a HOB for the memory allocation.
649 It can only be invoked during PEI phase;
650 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
651 If there is no additional space for HOB creation, then ASSERT().
652
653 @param BaseAddress The 64 bit physical address of the memory.
654 @param Length The length of the memory allocation in bytes.
655 @param MemoryType Type of memory allocated by this HOB.
656
657 **/
658 VOID
659 EFIAPI
660 BuildMemoryAllocationHob (
661 IN EFI_PHYSICAL_ADDRESS BaseAddress,
662 IN UINT64 Length,
663 IN EFI_MEMORY_TYPE MemoryType
664 )
665 {
666 EFI_HOB_MEMORY_ALLOCATION *Hob;
667
668 ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&
669 ((Length & (EFI_PAGE_SIZE - 1)) == 0));
670
671 Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION));
672
673 ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));
674 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
675 Hob->AllocDescriptor.MemoryLength = Length;
676 Hob->AllocDescriptor.MemoryType = MemoryType;
677 //
678 // Zero the reserved space to match HOB spec
679 //
680 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));
681 }
682