]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkPkg/Library/PeiHobLibFramework/HobLib.c
MdePkg/IntelFrameworkPkg HobLib: Update BuildResourceDescriptorWithOwnerHob()
[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 - 2014, 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 Builds a Firmware Volume HOB.
480
481 This function builds a Firmware Volume HOB.
482 It can only be invoked during PEI phase;
483 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
484
485 If there is no additional space for HOB creation, then ASSERT().
486
487 @param BaseAddress The base address of the Firmware Volume.
488 @param Length The size of the Firmware Volume in bytes.
489
490 **/
491 VOID
492 EFIAPI
493 BuildFvHob (
494 IN EFI_PHYSICAL_ADDRESS BaseAddress,
495 IN UINT64 Length
496 )
497 {
498 EFI_HOB_FIRMWARE_VOLUME *Hob;
499
500 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME));
501 if (Hob == NULL) {
502 return;
503 }
504
505 Hob->BaseAddress = BaseAddress;
506 Hob->Length = Length;
507 }
508
509 /**
510 Builds a EFI_HOB_TYPE_FV2 HOB.
511
512 This function builds a EFI_HOB_TYPE_FV2 HOB.
513 It can only be invoked during PEI phase;
514 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
515
516 If there is no additional space for HOB creation, then ASSERT().
517
518 @param BaseAddress The base address of the Firmware Volume.
519 @param Length The size of the Firmware Volume in bytes.
520 @param FvName The name of the Firmware Volume.
521 @param FileName The name of the file.
522
523 **/
524 VOID
525 EFIAPI
526 BuildFv2Hob (
527 IN EFI_PHYSICAL_ADDRESS BaseAddress,
528 IN UINT64 Length,
529 IN CONST EFI_GUID *FvName,
530 IN CONST EFI_GUID *FileName
531 )
532 {
533 EFI_HOB_FIRMWARE_VOLUME2 *Hob;
534
535 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV2, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME2));
536 if (Hob == NULL) {
537 return;
538 }
539
540 Hob->BaseAddress = BaseAddress;
541 Hob->Length = Length;
542 CopyGuid (&Hob->FvName, FvName);
543 CopyGuid (&Hob->FileName, FileName);
544 }
545
546 /**
547 Builds a Capsule Volume HOB.
548
549 This function builds a Capsule Volume HOB.
550 It can only be invoked during PEI phase;
551 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
552
553 If the platform does not support Capsule Volume HOBs, then ASSERT().
554 If there is no additional space for HOB creation, then ASSERT().
555
556 @param BaseAddress The base address of the Capsule Volume.
557 @param Length The size of the Capsule Volume in bytes.
558
559 **/
560 VOID
561 EFIAPI
562 BuildCvHob (
563 IN EFI_PHYSICAL_ADDRESS BaseAddress,
564 IN UINT64 Length
565 )
566 {
567 EFI_HOB_CAPSULE_VOLUME *Hob;
568
569 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CV, (UINT16) sizeof (EFI_HOB_CAPSULE_VOLUME));
570 if (Hob == NULL) {
571 return;
572 }
573
574 Hob->BaseAddress = BaseAddress;
575 Hob->Length = Length;
576 }
577
578 /**
579 Builds a HOB for the CPU.
580
581 This function builds a HOB for the CPU.
582 It can only be invoked during PEI phase;
583 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
584
585 If there is no additional space for HOB creation, then ASSERT().
586
587 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
588 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
589
590 **/
591 VOID
592 EFIAPI
593 BuildCpuHob (
594 IN UINT8 SizeOfMemorySpace,
595 IN UINT8 SizeOfIoSpace
596 )
597 {
598 EFI_HOB_CPU *Hob;
599
600 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CPU, (UINT16) sizeof (EFI_HOB_CPU));
601 if (Hob == NULL) {
602 return;
603 }
604
605 Hob->SizeOfMemorySpace = SizeOfMemorySpace;
606 Hob->SizeOfIoSpace = SizeOfIoSpace;
607
608 //
609 // Zero the reserved space to match HOB spec
610 //
611 ZeroMem (Hob->Reserved, sizeof (Hob->Reserved));
612 }
613
614 /**
615 Builds a HOB for the Stack.
616
617 This function builds a HOB for the stack.
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
623 @param BaseAddress The 64 bit physical address of the Stack.
624 @param Length The length of the stack in bytes.
625
626 **/
627 VOID
628 EFIAPI
629 BuildStackHob (
630 IN EFI_PHYSICAL_ADDRESS BaseAddress,
631 IN UINT64 Length
632 )
633 {
634 EFI_HOB_MEMORY_ALLOCATION_STACK *Hob;
635
636 ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&
637 ((Length & (EFI_PAGE_SIZE - 1)) == 0));
638
639 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK));
640 if (Hob == NULL) {
641 return;
642 }
643
644 CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocStackGuid);
645 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
646 Hob->AllocDescriptor.MemoryLength = Length;
647 Hob->AllocDescriptor.MemoryType = EfiBootServicesData;
648
649 //
650 // Zero the reserved space to match HOB spec
651 //
652 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));
653 }
654
655 /**
656 Builds a HOB for the BSP store.
657
658 This function builds a HOB for BSP store.
659 It can only be invoked during PEI phase;
660 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
661
662 If there is no additional space for HOB creation, then ASSERT().
663
664 @param BaseAddress The 64 bit physical address of the BSP.
665 @param Length The length of the BSP store in bytes.
666 @param MemoryType Type of memory allocated by this HOB.
667
668 **/
669 VOID
670 EFIAPI
671 BuildBspStoreHob (
672 IN EFI_PHYSICAL_ADDRESS BaseAddress,
673 IN UINT64 Length,
674 IN EFI_MEMORY_TYPE MemoryType
675 )
676 {
677 EFI_HOB_MEMORY_ALLOCATION_BSP_STORE *Hob;
678
679 ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&
680 ((Length & (EFI_PAGE_SIZE - 1)) == 0));
681
682 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_BSP_STORE));
683 if (Hob == NULL) {
684 return;
685 }
686
687 CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocBspStoreGuid);
688 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
689 Hob->AllocDescriptor.MemoryLength = Length;
690 Hob->AllocDescriptor.MemoryType = MemoryType;
691
692 //
693 // Zero the reserved space to match HOB spec
694 //
695 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));
696 }
697
698 /**
699 Builds a HOB for the memory allocation.
700
701 This function builds a HOB for the memory allocation.
702 It can only be invoked during PEI phase;
703 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
704
705 If there is no additional space for HOB creation, then ASSERT().
706
707 @param BaseAddress The 64 bit physical address of the memory.
708 @param Length The length of the memory allocation in bytes.
709 @param MemoryType Type of memory allocated by this HOB.
710
711 **/
712 VOID
713 EFIAPI
714 BuildMemoryAllocationHob (
715 IN EFI_PHYSICAL_ADDRESS BaseAddress,
716 IN UINT64 Length,
717 IN EFI_MEMORY_TYPE MemoryType
718 )
719 {
720 EFI_HOB_MEMORY_ALLOCATION *Hob;
721
722 ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&
723 ((Length & (EFI_PAGE_SIZE - 1)) == 0));
724
725 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION));
726 if (Hob == NULL) {
727 return;
728 }
729
730 ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));
731 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
732 Hob->AllocDescriptor.MemoryLength = Length;
733 Hob->AllocDescriptor.MemoryType = MemoryType;
734 //
735 // Zero the reserved space to match HOB spec
736 //
737 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));
738 }