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