]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkPkg/Library/PeiHobLibFramework/HobLib.c
Add PeiHobLibFramework instance to provide a real implementation for BuildCvHob()
[mirror_edk2.git] / IntelFrameworkPkg / Library / PeiHobLibFramework / HobLib.c
CommitLineData
2f78ec7a 1/** @file\r
2 Instance of HOB Library using PEI Services.\r
3\r
4 HOB Library implementation that uses PEI Services to retrieve the HOB List.\r
5 This library instance uses EFI_HOB_TYPE_CV defined in Intel framework HOB specification v0.9\r
6 to implement HobLib BuildCvHob() API. \r
7\r
8Copyright (c) 2007 - 2009, Intel Corporation<BR>\r
9All rights reserved. This program and the accompanying materials\r
10are licensed and made available under the terms and conditions of the BSD License\r
11which accompanies this distribution. The full text of the license may be found at\r
12http://opensource.org/licenses/bsd-license.php\r
13\r
14THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
15WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
16\r
17**/\r
18\r
19#include <PiPei.h>\r
20#include <FrameworkPei.h>\r
21\r
22#include <Guid/MemoryAllocationHob.h>\r
23\r
24#include <Library/HobLib.h>\r
25#include <Library/DebugLib.h>\r
26#include <Library/PeiServicesLib.h>\r
27#include <Library/BaseMemoryLib.h>\r
28\r
29/**\r
30 Returns the pointer to the HOB list.\r
31\r
32 This function returns the pointer to first HOB in the list.\r
33 For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer \r
34 to the HOB list. For the DXE phase, the HOB list pointer can be retrieved through\r
35 the EFI System Table by looking up theHOB list GUID in the System Configuration Table.\r
36 Since the System Configuration Table does not exist that the time the DXE Core is \r
37 launched, the DXE Core uses a global variable from the DXE Core Entry Point Library \r
38 to manage the pointer to the HOB list.\r
39 \r
40 If the pointer to the HOB list is NULL, then ASSERT().\r
41 \r
42 @return The pointer to the HOB list.\r
43\r
44**/\r
45VOID *\r
46EFIAPI\r
47GetHobList (\r
48 VOID\r
49 )\r
50{\r
51 EFI_STATUS Status;\r
52 VOID *HobList;\r
53\r
54 Status = PeiServicesGetHobList (&HobList);\r
55 ASSERT_EFI_ERROR (Status);\r
56 ASSERT (HobList != NULL);\r
57\r
58 return HobList;\r
59}\r
60\r
61/**\r
62 Returns the next instance of a HOB type from the starting HOB.\r
63\r
64 This function searches the first instance of a HOB type from the starting HOB pointer. \r
65 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.\r
66 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r
67 unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r
68 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r
69 \r
70 If HobStart is NULL, then ASSERT().\r
71\r
72 @param Type The HOB type to return.\r
73 @param HobStart The starting HOB pointer to search from.\r
74\r
75 @return The next instance of a HOB type from the starting HOB.\r
76\r
77**/\r
78VOID *\r
79EFIAPI\r
80GetNextHob (\r
81 IN UINT16 Type,\r
82 IN CONST VOID *HobStart\r
83 )\r
84{\r
85 EFI_PEI_HOB_POINTERS Hob;\r
86\r
87 ASSERT (HobStart != NULL);\r
88 \r
89 Hob.Raw = (UINT8 *) HobStart;\r
90 //\r
91 // Parse the HOB list until end of list or matching type is found.\r
92 //\r
93 while (!END_OF_HOB_LIST (Hob)) {\r
94 if (Hob.Header->HobType == Type) {\r
95 return Hob.Raw;\r
96 }\r
97 Hob.Raw = GET_NEXT_HOB (Hob);\r
98 }\r
99 return NULL;\r
100}\r
101\r
102/**\r
103 Returns the first instance of a HOB type among the whole HOB list.\r
104\r
105 This function searches the first instance of a HOB type among the whole HOB list. \r
106 If there does not exist such HOB type in the HOB list, it will return NULL. \r
107 \r
108 If the pointer to the HOB list is NULL, then ASSERT().\r
109\r
110 @param Type The HOB type to return.\r
111\r
112 @return The next instance of a HOB type from the starting HOB.\r
113\r
114**/\r
115VOID *\r
116EFIAPI\r
117GetFirstHob (\r
118 IN UINT16 Type\r
119 )\r
120{\r
121 VOID *HobList;\r
122\r
123 HobList = GetHobList ();\r
124 return GetNextHob (Type, HobList);\r
125}\r
126\r
127/**\r
128 Returns the next instance of the matched GUID HOB from the starting HOB.\r
129 \r
130 This function searches the first instance of a HOB from the starting HOB pointer. \r
131 Such HOB should satisfy two conditions: \r
132 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid. \r
133 If there does not exist such HOB from the starting HOB pointer, it will return NULL. \r
134 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
135 to extract the data section and its size info respectively.\r
136 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r
137 unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r
138 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r
139 \r
140 If Guid is NULL, then ASSERT().\r
141 If HobStart is NULL, then ASSERT().\r
142\r
143 @param Guid The GUID to match with in the HOB list.\r
144 @param HobStart A pointer to a Guid.\r
145\r
146 @return The next instance of the matched GUID HOB from the starting HOB.\r
147\r
148**/\r
149VOID *\r
150EFIAPI\r
151GetNextGuidHob (\r
152 IN CONST EFI_GUID *Guid,\r
153 IN CONST VOID *HobStart\r
154 )\r
155{\r
156 EFI_PEI_HOB_POINTERS GuidHob;\r
157\r
158 GuidHob.Raw = (UINT8 *) HobStart;\r
159 while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {\r
160 if (CompareGuid (Guid, &GuidHob.Guid->Name)) {\r
161 break;\r
162 }\r
163 GuidHob.Raw = GET_NEXT_HOB (GuidHob);\r
164 }\r
165 return GuidHob.Raw;\r
166}\r
167\r
168/**\r
169 Returns the first instance of the matched GUID HOB among the whole HOB list.\r
170 \r
171 This function searches the first instance of a HOB among the whole HOB list. \r
172 Such HOB should satisfy two conditions:\r
173 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.\r
174 If there does not exist such HOB from the starting HOB pointer, it will return NULL.\r
175 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
176 to extract the data section and its size info respectively.\r
177 \r
178 If the pointer to the HOB list is NULL, then ASSERT().\r
179 If Guid is NULL, then ASSERT().\r
180\r
181 @param Guid The GUID to match with in the HOB list.\r
182\r
183 @return The first instance of the matched GUID HOB among the whole HOB list.\r
184\r
185**/\r
186VOID *\r
187EFIAPI\r
188GetFirstGuidHob (\r
189 IN CONST EFI_GUID *Guid\r
190 )\r
191{\r
192 VOID *HobList;\r
193\r
194 HobList = GetHobList ();\r
195 return GetNextGuidHob (Guid, HobList);\r
196}\r
197\r
198/**\r
199 Get the system boot mode from the HOB list.\r
200\r
201 This function returns the system boot mode information from the \r
202 PHIT HOB in HOB list.\r
203\r
204 If the pointer to the HOB list is NULL, then ASSERT().\r
205 \r
206 @param VOID\r
207\r
208 @return The Boot Mode.\r
209\r
210**/\r
211EFI_BOOT_MODE\r
212EFIAPI\r
213GetBootModeHob (\r
214 VOID\r
215 )\r
216{\r
217 EFI_STATUS Status;\r
218 EFI_BOOT_MODE BootMode;\r
219\r
220 Status = PeiServicesGetBootMode (&BootMode);\r
221 ASSERT_EFI_ERROR (Status);\r
222\r
223 return BootMode;\r
224}\r
225\r
226/**\r
227 Adds a new HOB to the HOB List.\r
228\r
229 This internal function enables PEIMs to create various types of HOBs.\r
230\r
231 @param Type Type of the new HOB.\r
232 @param Length Length of the new HOB to allocate.\r
233\r
234 @return The address of new HOB.\r
235\r
236**/\r
237VOID *\r
238EFIAPI\r
239InternalPeiCreateHob (\r
240 IN UINT16 Type,\r
241 IN UINT16 Length\r
242 )\r
243{\r
244 EFI_STATUS Status;\r
245 VOID *Hob;\r
246\r
247 Status = PeiServicesCreateHob (Type, Length, &Hob);\r
248 //\r
249 // Assume the process of HOB building is always successful.\r
250 //\r
251 ASSERT_EFI_ERROR (Status);\r
252 return Hob;\r
253}\r
254\r
255/**\r
256 Builds a HOB for a loaded PE32 module.\r
257\r
258 This function builds a HOB for a loaded PE32 module.\r
259 It can only be invoked during PEI phase;\r
260 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
261 \r
262 If ModuleName is NULL, then ASSERT().\r
263 If there is no additional space for HOB creation, then ASSERT().\r
264\r
265 @param ModuleName The GUID File Name of the module.\r
266 @param MemoryAllocationModule The 64 bit physical address of the module.\r
267 @param ModuleLength The length of the module in bytes.\r
268 @param EntryPoint The 64 bit physical address of the module entry point.\r
269\r
270**/\r
271VOID\r
272EFIAPI\r
273BuildModuleHob (\r
274 IN CONST EFI_GUID *ModuleName,\r
275 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,\r
276 IN UINT64 ModuleLength,\r
277 IN EFI_PHYSICAL_ADDRESS EntryPoint\r
278 )\r
279{\r
280 EFI_HOB_MEMORY_ALLOCATION_MODULE *Hob;\r
281\r
282 ASSERT (((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) &&\r
283 ((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0));\r
284\r
285 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE));\r
286\r
287 CopyGuid (&(Hob->MemoryAllocationHeader.Name), &gEfiHobMemoryAllocModuleGuid);\r
288 Hob->MemoryAllocationHeader.MemoryBaseAddress = MemoryAllocationModule;\r
289 Hob->MemoryAllocationHeader.MemoryLength = ModuleLength;\r
290 Hob->MemoryAllocationHeader.MemoryType = EfiBootServicesCode;\r
291\r
292 //\r
293 // Zero the reserved space to match HOB spec\r
294 //\r
295 ZeroMem (Hob->MemoryAllocationHeader.Reserved, sizeof (Hob->MemoryAllocationHeader.Reserved));\r
296 \r
297 CopyGuid (&Hob->ModuleName, ModuleName);\r
298 Hob->EntryPoint = EntryPoint;\r
299}\r
300\r
301/**\r
302 Builds a HOB that describes a chunk of system memory.\r
303\r
304 This function builds a HOB that describes a chunk of system memory.\r
305 It can only be invoked during PEI phase;\r
306 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
307 \r
308 If there is no additional space for HOB creation, then ASSERT().\r
309\r
310 @param ResourceType The type of resource described by this HOB.\r
311 @param ResourceAttribute The resource attributes of the memory described by this HOB.\r
312 @param PhysicalStart The 64 bit physical address of memory described by this HOB.\r
313 @param NumberOfBytes The length of the memory described by this HOB in bytes.\r
314\r
315**/\r
316VOID\r
317EFIAPI\r
318BuildResourceDescriptorHob (\r
319 IN EFI_RESOURCE_TYPE ResourceType,\r
320 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,\r
321 IN EFI_PHYSICAL_ADDRESS PhysicalStart,\r
322 IN UINT64 NumberOfBytes\r
323 )\r
324{\r
325 EFI_HOB_RESOURCE_DESCRIPTOR *Hob;\r
326\r
327 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));\r
328\r
329 Hob->ResourceType = ResourceType;\r
330 Hob->ResourceAttribute = ResourceAttribute;\r
331 Hob->PhysicalStart = PhysicalStart;\r
332 Hob->ResourceLength = NumberOfBytes;\r
333}\r
334\r
335/**\r
336 Builds a customized HOB tagged with a GUID for identification and returns \r
337 the start address of GUID HOB data.\r
338\r
339 This function builds a customized HOB tagged with a GUID for identification \r
340 and returns the start address of GUID HOB data so that caller can fill the customized data. \r
341 The HOB Header and Name field is already stripped.\r
342 It can only be invoked during PEI phase;\r
343 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
344 \r
345 If Guid is NULL, then ASSERT().\r
346 If there is no additional space for HOB creation, then ASSERT().\r
347 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
348\r
349 @param Guid The GUID to tag the customized HOB.\r
350 @param DataLength The size of the data payload for the GUID HOB.\r
351\r
352 @return The start address of GUID HOB data.\r
353\r
354**/\r
355VOID *\r
356EFIAPI\r
357BuildGuidHob (\r
358 IN CONST EFI_GUID *Guid,\r
359 IN UINTN DataLength\r
360 )\r
361{\r
362 EFI_HOB_GUID_TYPE *Hob;\r
363\r
364 //\r
365 // Make sure that data length is not too long.\r
366 //\r
367 ASSERT (DataLength <= (0xffff - sizeof (EFI_HOB_GUID_TYPE)));\r
368\r
369 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16) (sizeof (EFI_HOB_GUID_TYPE) + DataLength));\r
370 CopyGuid (&Hob->Name, Guid);\r
371 return Hob + 1;\r
372}\r
373\r
374/**\r
375 Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB \r
376 data field, and returns the start address of the GUID HOB data.\r
377\r
378 This function builds a customized HOB tagged with a GUID for identification and copies the input\r
379 data to the HOB data field and returns the start address of the GUID HOB data. It can only be \r
380 invoked during PEI phase; for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase. \r
381 The HOB Header and Name field is already stripped.\r
382 It can only be invoked during PEI phase;\r
383 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
384 \r
385 If Guid is NULL, then ASSERT().\r
386 If Data is NULL and DataLength > 0, then ASSERT().\r
387 If there is no additional space for HOB creation, then ASSERT().\r
388 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
389\r
390 @param Guid The GUID to tag the customized HOB.\r
391 @param Data The data to be copied into the data field of the GUID HOB.\r
392 @param DataLength The size of the data payload for the GUID HOB.\r
393\r
394 @return The start address of GUID HOB data.\r
395\r
396**/\r
397VOID *\r
398EFIAPI\r
399BuildGuidDataHob (\r
400 IN CONST EFI_GUID *Guid,\r
401 IN VOID *Data,\r
402 IN UINTN DataLength\r
403 )\r
404{\r
405 VOID *HobData;\r
406\r
407 ASSERT (Data != NULL || DataLength == 0);\r
408\r
409 HobData = BuildGuidHob (Guid, DataLength);\r
410\r
411 return CopyMem (HobData, Data, DataLength);\r
412}\r
413\r
414/**\r
415 Builds a Firmware Volume HOB.\r
416\r
417 This function builds a Firmware Volume HOB.\r
418 It can only be invoked during PEI phase;\r
419 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
420 \r
421 If there is no additional space for HOB creation, then ASSERT().\r
422\r
423 @param BaseAddress The base address of the Firmware Volume.\r
424 @param Length The size of the Firmware Volume in bytes.\r
425\r
426**/\r
427VOID\r
428EFIAPI\r
429BuildFvHob (\r
430 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
431 IN UINT64 Length\r
432 )\r
433{\r
434 EFI_HOB_FIRMWARE_VOLUME *Hob;\r
435\r
436 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV, sizeof (EFI_HOB_FIRMWARE_VOLUME));\r
437\r
438 Hob->BaseAddress = BaseAddress;\r
439 Hob->Length = Length;\r
440}\r
441\r
442/**\r
443 Builds a EFI_HOB_TYPE_FV2 HOB.\r
444\r
445 This function builds a EFI_HOB_TYPE_FV2 HOB.\r
446 It can only be invoked during PEI phase;\r
447 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
448 \r
449 If there is no additional space for HOB creation, then ASSERT().\r
450\r
451 @param BaseAddress The base address of the Firmware Volume.\r
452 @param Length The size of the Firmware Volume in bytes.\r
453 @param FvName The name of the Firmware Volume.\r
454 @param FileName The name of the file.\r
455 \r
456**/\r
457VOID\r
458EFIAPI\r
459BuildFv2Hob (\r
460 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
461 IN UINT64 Length,\r
462 IN CONST EFI_GUID *FvName,\r
463 IN CONST EFI_GUID *FileName\r
464 )\r
465{\r
466 EFI_HOB_FIRMWARE_VOLUME2 *Hob;\r
467\r
468 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV2, sizeof (EFI_HOB_FIRMWARE_VOLUME2));\r
469\r
470 Hob->BaseAddress = BaseAddress;\r
471 Hob->Length = Length;\r
472 CopyGuid (&Hob->FvName, FvName);\r
473 CopyGuid (&Hob->FileName, FileName);\r
474}\r
475\r
476/**\r
477 Builds a Capsule Volume HOB.\r
478\r
479 This function builds a Capsule Volume HOB.\r
480 It can only be invoked during PEI phase;\r
481 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
482 \r
483 If there is no additional space for HOB creation, then ASSERT().\r
484\r
485 @param BaseAddress The base address of the Capsule Volume.\r
486 @param Length The size of the Capsule Volume in bytes.\r
487\r
488**/\r
489VOID\r
490EFIAPI\r
491BuildCvHob (\r
492 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
493 IN UINT64 Length\r
494 )\r
495{\r
496 EFI_HOB_CAPSULE_VOLUME *Hob;\r
497\r
498 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CV, sizeof (EFI_HOB_CAPSULE_VOLUME));\r
499\r
500 Hob->BaseAddress = BaseAddress;\r
501 Hob->Length = Length;\r
502}\r
503\r
504/**\r
505 Builds a HOB for the CPU.\r
506\r
507 This function builds a HOB for the CPU.\r
508 It can only be invoked during PEI phase;\r
509 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
510 \r
511 If there is no additional space for HOB creation, then ASSERT().\r
512\r
513 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.\r
514 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.\r
515\r
516**/\r
517VOID\r
518EFIAPI\r
519BuildCpuHob (\r
520 IN UINT8 SizeOfMemorySpace,\r
521 IN UINT8 SizeOfIoSpace\r
522 )\r
523{\r
524 EFI_HOB_CPU *Hob;\r
525\r
526 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CPU, sizeof (EFI_HOB_CPU));\r
527\r
528 Hob->SizeOfMemorySpace = SizeOfMemorySpace;\r
529 Hob->SizeOfIoSpace = SizeOfIoSpace;\r
530\r
531 //\r
532 // Zero the reserved space to match HOB spec\r
533 //\r
534 ZeroMem (Hob->Reserved, sizeof (Hob->Reserved)); \r
535}\r
536\r
537/**\r
538 Builds a HOB for the Stack.\r
539\r
540 This function builds a HOB for the stack.\r
541 It can only be invoked during PEI phase;\r
542 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
543 \r
544 If there is no additional space for HOB creation, then ASSERT().\r
545\r
546 @param BaseAddress The 64 bit physical address of the Stack.\r
547 @param Length The length of the stack in bytes.\r
548\r
549**/\r
550VOID\r
551EFIAPI\r
552BuildStackHob (\r
553 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
554 IN UINT64 Length\r
555 )\r
556{\r
557 EFI_HOB_MEMORY_ALLOCATION_STACK *Hob;\r
558\r
559 ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
560 ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r
561\r
562 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK));\r
563\r
564 CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocStackGuid);\r
565 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
566 Hob->AllocDescriptor.MemoryLength = Length;\r
567 Hob->AllocDescriptor.MemoryType = EfiBootServicesData;\r
568\r
569 //\r
570 // Zero the reserved space to match HOB spec\r
571 //\r
572 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r
573}\r
574\r
575/**\r
576 Builds a HOB for the BSP store.\r
577\r
578 This function builds a HOB for BSP store.\r
579 It can only be invoked during PEI phase;\r
580 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
581 \r
582 If there is no additional space for HOB creation, then ASSERT().\r
583\r
584 @param BaseAddress The 64 bit physical address of the BSP.\r
585 @param Length The length of the BSP store in bytes.\r
586 @param MemoryType Type of memory allocated by this HOB.\r
587\r
588**/\r
589VOID\r
590EFIAPI\r
591BuildBspStoreHob (\r
592 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
593 IN UINT64 Length,\r
594 IN EFI_MEMORY_TYPE MemoryType\r
595 )\r
596{\r
597 EFI_HOB_MEMORY_ALLOCATION_BSP_STORE *Hob;\r
598\r
599 ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
600 ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r
601\r
602 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_BSP_STORE));\r
603\r
604 CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocBspStoreGuid);\r
605 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
606 Hob->AllocDescriptor.MemoryLength = Length;\r
607 Hob->AllocDescriptor.MemoryType = MemoryType;\r
608\r
609 //\r
610 // Zero the reserved space to match HOB spec\r
611 //\r
612 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r
613}\r
614\r
615/**\r
616 Builds a HOB for the memory allocation.\r
617\r
618 This function builds a HOB for the memory allocation.\r
619 It can only be invoked during PEI phase;\r
620 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
621 \r
622 If there is no additional space for HOB creation, then ASSERT().\r
623\r
624 @param BaseAddress The 64 bit physical address of the memory.\r
625 @param Length The length of the memory allocation in bytes.\r
626 @param MemoryType Type of memory allocated by this HOB.\r
627\r
628**/\r
629VOID\r
630EFIAPI\r
631BuildMemoryAllocationHob (\r
632 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
633 IN UINT64 Length,\r
634 IN EFI_MEMORY_TYPE MemoryType\r
635 )\r
636{\r
637 EFI_HOB_MEMORY_ALLOCATION *Hob;\r
638\r
639 ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
640 ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r
641 \r
642 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION));\r
643 \r
644 ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));\r
645 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
646 Hob->AllocDescriptor.MemoryLength = Length;\r
647 Hob->AllocDescriptor.MemoryType = MemoryType;\r
648 //\r
649 // Zero the reserved space to match HOB spec\r
650 //\r
651 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r
652}\r