]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkPkg/Library/PeiHobLibFramework/HobLib.c
MdeModulePkg/FaultTolerantWriteDxe: implement standalone MM version
[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
1c2f052d 6 to implement HobLib BuildCvHob() API.\r
2f78ec7a 7\r
1c2f052d 8Copyright (c) 2007 - 2018, 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
1c2f052d 32 For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer\r
2f78ec7a 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
1c2f052d
LG
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
2f78ec7a 37 to manage the pointer to the HOB list.\r
1c2f052d 38\r
2f78ec7a 39 If the pointer to the HOB list is NULL, then ASSERT().\r
1c2f052d 40\r
2f78ec7a 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
1c2f052d 63 This function searches the first instance of a HOB type from the starting HOB pointer.\r
2f78ec7a 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
1c2f052d 68\r
2f78ec7a 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
1c2f052d 87\r
2f78ec7a 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
1c2f052d
LG
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
2f78ec7a 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
1c2f052d
LG
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
2f78ec7a 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
1c2f052d 138\r
2f78ec7a 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
1c2f052d
LG
169\r
170 This function searches the first instance of a HOB among the whole HOB list.\r
2f78ec7a 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
1c2f052d 176\r
2f78ec7a 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
1c2f052d 200 This function returns the system boot mode information from the\r
2f78ec7a 201 PHIT HOB in HOB list.\r
202\r
203 If the pointer to the HOB list is NULL, then ASSERT().\r
1c2f052d 204\r
2f78ec7a 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
1c2f052d 264\r
2f78ec7a 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
1c2f052d 302\r
2f78ec7a 303 CopyGuid (&Hob->ModuleName, ModuleName);\r
304 Hob->EntryPoint = EntryPoint;\r
305}\r
306\r
b947f0cf 307/**\r
f1e2b728 308 Builds a HOB that describes a chunk of system memory with Owner GUID.\r
b947f0cf
HT
309\r
310 This function builds a HOB that describes a chunk of system memory.\r
311 It can only be invoked during PEI phase;\r
312 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
1c2f052d 313\r
b947f0cf
HT
314 If there is no additional space for HOB creation, then ASSERT().\r
315\r
316 @param ResourceType The type of resource described by this HOB.\r
317 @param ResourceAttribute The resource attributes of the memory described by this HOB.\r
318 @param PhysicalStart The 64 bit physical address of memory described by this HOB.\r
319 @param NumberOfBytes The length of the memory described by this HOB in bytes.\r
f1e2b728 320 @param OwnerGUID GUID for the owner of this resource.\r
b947f0cf
HT
321\r
322**/\r
323VOID\r
324EFIAPI\r
325BuildResourceDescriptorWithOwnerHob (\r
326 IN EFI_RESOURCE_TYPE ResourceType,\r
327 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,\r
328 IN EFI_PHYSICAL_ADDRESS PhysicalStart,\r
329 IN UINT64 NumberOfBytes,\r
330 IN EFI_GUID *OwnerGUID\r
331 )\r
332{\r
333 EFI_HOB_RESOURCE_DESCRIPTOR *Hob;\r
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
b947f0cf
HT
339\r
340 Hob->ResourceType = ResourceType;\r
341 Hob->ResourceAttribute = ResourceAttribute;\r
342 Hob->PhysicalStart = PhysicalStart;\r
343 Hob->ResourceLength = NumberOfBytes;\r
344\r
345 CopyGuid (&Hob->Owner, OwnerGUID);\r
f1e2b728
SZ
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
1c2f052d 354\r
2f78ec7a 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
1c2f052d 387 Builds a customized HOB tagged with a GUID for identification and returns\r
2f78ec7a 388 the start address of GUID HOB data.\r
389\r
1c2f052d
LG
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
2f78ec7a 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
1c2f052d 395\r
2f78ec7a 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
1c2f052d 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
1c2f052d 435 Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB\r
2f78ec7a 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
1c2f052d
LG
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
2f78ec7a 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
1c2f052d 444\r
2f78ec7a 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
368871a3
SZ
478/**\r
479 Check FV alignment.\r
480\r
481 @param BaseAddress The base address of the Firmware Volume.\r
482 @param Length The size of the Firmware Volume in bytes.\r
483\r
484 @retval TRUE FvImage buffer is at its required alignment.\r
485 @retval FALSE FvImage buffer is not at its required alignment.\r
486\r
487**/\r
488BOOLEAN\r
489InternalCheckFvAlignment (\r
490 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
491 IN UINT64 Length\r
492 )\r
493{\r
494 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
495 UINT32 FvAlignment;\r
496\r
497 FvAlignment = 0;\r
498 FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress;\r
499\r
500 //\r
501 // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume\r
502 // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from\r
503 // its initial linked location and maintain its alignment.\r
504 //\r
505 if ((FwVolHeader->Attributes & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {\r
506 //\r
507 // Get FvHeader alignment\r
508 //\r
509 FvAlignment = 1 << ((FwVolHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);\r
510 //\r
511 // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.\r
512 //\r
513 if (FvAlignment < 8) {\r
514 FvAlignment = 8;\r
515 }\r
516 if ((UINTN)BaseAddress % FvAlignment != 0) {\r
517 //\r
518 // FvImage buffer is not at its required alignment.\r
519 //\r
520 DEBUG ((\r
521 DEBUG_ERROR,\r
522 "Unaligned FvImage found at 0x%lx:0x%lx, the required alignment is 0x%x\n",\r
523 BaseAddress,\r
524 Length,\r
525 FvAlignment\r
526 ));\r
527 return FALSE;\r
528 }\r
529 }\r
530\r
531 return TRUE;\r
532}\r
533\r
2f78ec7a 534/**\r
535 Builds a Firmware Volume HOB.\r
536\r
537 This function builds a Firmware Volume HOB.\r
538 It can only be invoked during PEI phase;\r
539 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
1c2f052d 540\r
2f78ec7a 541 If there is no additional space for HOB creation, then ASSERT().\r
368871a3 542 If the FvImage buffer is not at its required alignment, then ASSERT().\r
2f78ec7a 543\r
544 @param BaseAddress The base address of the Firmware Volume.\r
545 @param Length The size of the Firmware Volume in bytes.\r
546\r
547**/\r
548VOID\r
549EFIAPI\r
550BuildFvHob (\r
551 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
552 IN UINT64 Length\r
553 )\r
554{\r
555 EFI_HOB_FIRMWARE_VOLUME *Hob;\r
556\r
368871a3
SZ
557 if (!InternalCheckFvAlignment (BaseAddress, Length)) {\r
558 ASSERT (FALSE);\r
559 return;\r
560 }\r
561\r
8194a023 562 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME));\r
2dfdd3eb
RN
563 if (Hob == NULL) {\r
564 return;\r
565 }\r
2f78ec7a 566\r
567 Hob->BaseAddress = BaseAddress;\r
568 Hob->Length = Length;\r
569}\r
570\r
571/**\r
572 Builds a EFI_HOB_TYPE_FV2 HOB.\r
573\r
574 This function builds a EFI_HOB_TYPE_FV2 HOB.\r
575 It can only be invoked during PEI phase;\r
576 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
1c2f052d 577\r
2f78ec7a 578 If there is no additional space for HOB creation, then ASSERT().\r
368871a3 579 If the FvImage buffer is not at its required alignment, then ASSERT().\r
2f78ec7a 580\r
581 @param BaseAddress The base address of the Firmware Volume.\r
582 @param Length The size of the Firmware Volume in bytes.\r
583 @param FvName The name of the Firmware Volume.\r
584 @param FileName The name of the file.\r
1c2f052d 585\r
2f78ec7a 586**/\r
587VOID\r
588EFIAPI\r
589BuildFv2Hob (\r
590 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
591 IN UINT64 Length,\r
592 IN CONST EFI_GUID *FvName,\r
593 IN CONST EFI_GUID *FileName\r
594 )\r
595{\r
596 EFI_HOB_FIRMWARE_VOLUME2 *Hob;\r
597\r
368871a3
SZ
598 if (!InternalCheckFvAlignment (BaseAddress, Length)) {\r
599 ASSERT (FALSE);\r
600 return;\r
601 }\r
602\r
8194a023 603 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV2, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME2));\r
2dfdd3eb
RN
604 if (Hob == NULL) {\r
605 return;\r
606 }\r
2f78ec7a 607\r
608 Hob->BaseAddress = BaseAddress;\r
609 Hob->Length = Length;\r
610 CopyGuid (&Hob->FvName, FvName);\r
611 CopyGuid (&Hob->FileName, FileName);\r
612}\r
613\r
e4623bd5
SZ
614/**\r
615 Builds a EFI_HOB_TYPE_FV3 HOB.\r
616\r
617 This function builds a EFI_HOB_TYPE_FV3 HOB.\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 If the FvImage buffer is not at its required alignment, then ASSERT().\r
623\r
624 @param BaseAddress The base address of the Firmware Volume.\r
625 @param Length The size of the Firmware Volume in bytes.\r
626 @param AuthenticationStatus The authentication status.\r
627 @param ExtractedFv TRUE if the FV was extracted as a file within\r
628 another firmware volume. FALSE otherwise.\r
629 @param FvName The name of the Firmware Volume.\r
630 Valid only if IsExtractedFv is TRUE.\r
631 @param FileName The name of the file.\r
632 Valid only if IsExtractedFv is TRUE.\r
633\r
634**/\r
635VOID\r
636EFIAPI\r
637BuildFv3Hob (\r
638 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
639 IN UINT64 Length,\r
640 IN UINT32 AuthenticationStatus,\r
641 IN BOOLEAN ExtractedFv,\r
642 IN CONST EFI_GUID *FvName, OPTIONAL\r
643 IN CONST EFI_GUID *FileName OPTIONAL\r
644 )\r
645{\r
646 EFI_HOB_FIRMWARE_VOLUME3 *Hob;\r
647\r
648 if (!InternalCheckFvAlignment (BaseAddress, Length)) {\r
649 ASSERT (FALSE);\r
650 return;\r
651 }\r
652\r
653 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV3, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME3));\r
654 if (Hob == NULL) {\r
655 return;\r
656 }\r
657\r
658 Hob->BaseAddress = BaseAddress;\r
659 Hob->Length = Length;\r
660 Hob->AuthenticationStatus = AuthenticationStatus;\r
661 Hob->ExtractedFv = ExtractedFv;\r
662 if (ExtractedFv) {\r
663 CopyGuid (&Hob->FvName, FvName);\r
664 CopyGuid (&Hob->FileName, FileName);\r
665 }\r
666}\r
667\r
2f78ec7a 668/**\r
669 Builds a Capsule Volume HOB.\r
670\r
671 This function builds a Capsule Volume HOB.\r
672 It can only be invoked during PEI phase;\r
673 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
1c2f052d 674\r
a5a3a29c 675 If the platform does not support Capsule Volume HOBs, then ASSERT().\r
2f78ec7a 676 If there is no additional space for HOB creation, then ASSERT().\r
677\r
678 @param BaseAddress The base address of the Capsule Volume.\r
679 @param Length The size of the Capsule Volume in bytes.\r
680\r
681**/\r
682VOID\r
683EFIAPI\r
684BuildCvHob (\r
685 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
686 IN UINT64 Length\r
687 )\r
688{\r
689 EFI_HOB_CAPSULE_VOLUME *Hob;\r
690\r
8194a023 691 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CV, (UINT16) sizeof (EFI_HOB_CAPSULE_VOLUME));\r
2dfdd3eb
RN
692 if (Hob == NULL) {\r
693 return;\r
694 }\r
2f78ec7a 695\r
696 Hob->BaseAddress = BaseAddress;\r
697 Hob->Length = Length;\r
698}\r
699\r
700/**\r
701 Builds a HOB for the CPU.\r
702\r
703 This function builds a HOB for the CPU.\r
704 It can only be invoked during PEI phase;\r
705 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
1c2f052d 706\r
2f78ec7a 707 If there is no additional space for HOB creation, then ASSERT().\r
708\r
709 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.\r
710 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.\r
711\r
712**/\r
713VOID\r
714EFIAPI\r
715BuildCpuHob (\r
716 IN UINT8 SizeOfMemorySpace,\r
717 IN UINT8 SizeOfIoSpace\r
718 )\r
719{\r
720 EFI_HOB_CPU *Hob;\r
721\r
8194a023 722 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CPU, (UINT16) sizeof (EFI_HOB_CPU));\r
2dfdd3eb
RN
723 if (Hob == NULL) {\r
724 return;\r
725 }\r
2f78ec7a 726\r
727 Hob->SizeOfMemorySpace = SizeOfMemorySpace;\r
728 Hob->SizeOfIoSpace = SizeOfIoSpace;\r
729\r
730 //\r
731 // Zero the reserved space to match HOB spec\r
732 //\r
1c2f052d 733 ZeroMem (Hob->Reserved, sizeof (Hob->Reserved));\r
2f78ec7a 734}\r
735\r
736/**\r
737 Builds a HOB for the Stack.\r
738\r
739 This function builds a HOB for the stack.\r
740 It can only be invoked during PEI phase;\r
741 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
1c2f052d 742\r
2f78ec7a 743 If there is no additional space for HOB creation, then ASSERT().\r
744\r
745 @param BaseAddress The 64 bit physical address of the Stack.\r
746 @param Length The length of the stack in bytes.\r
747\r
748**/\r
749VOID\r
750EFIAPI\r
751BuildStackHob (\r
752 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
753 IN UINT64 Length\r
754 )\r
755{\r
756 EFI_HOB_MEMORY_ALLOCATION_STACK *Hob;\r
757\r
758 ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
759 ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r
760\r
8194a023 761 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK));\r
2dfdd3eb
RN
762 if (Hob == NULL) {\r
763 return;\r
764 }\r
2f78ec7a 765\r
766 CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocStackGuid);\r
767 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
768 Hob->AllocDescriptor.MemoryLength = Length;\r
769 Hob->AllocDescriptor.MemoryType = EfiBootServicesData;\r
770\r
771 //\r
772 // Zero the reserved space to match HOB spec\r
773 //\r
774 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r
775}\r
776\r
777/**\r
778 Builds a HOB for the BSP store.\r
779\r
780 This function builds a HOB for BSP store.\r
781 It can only be invoked during PEI phase;\r
782 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
1c2f052d 783\r
2f78ec7a 784 If there is no additional space for HOB creation, then ASSERT().\r
785\r
786 @param BaseAddress The 64 bit physical address of the BSP.\r
787 @param Length The length of the BSP store in bytes.\r
788 @param MemoryType Type of memory allocated by this HOB.\r
789\r
790**/\r
791VOID\r
792EFIAPI\r
793BuildBspStoreHob (\r
794 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
795 IN UINT64 Length,\r
796 IN EFI_MEMORY_TYPE MemoryType\r
797 )\r
798{\r
799 EFI_HOB_MEMORY_ALLOCATION_BSP_STORE *Hob;\r
800\r
801 ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
802 ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r
803\r
8194a023 804 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_BSP_STORE));\r
2dfdd3eb
RN
805 if (Hob == NULL) {\r
806 return;\r
807 }\r
2f78ec7a 808\r
809 CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocBspStoreGuid);\r
810 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
811 Hob->AllocDescriptor.MemoryLength = Length;\r
812 Hob->AllocDescriptor.MemoryType = MemoryType;\r
813\r
814 //\r
815 // Zero the reserved space to match HOB spec\r
816 //\r
817 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r
818}\r
819\r
820/**\r
821 Builds a HOB for the memory allocation.\r
822\r
823 This function builds a HOB for the memory allocation.\r
824 It can only be invoked during PEI phase;\r
825 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
1c2f052d 826\r
2f78ec7a 827 If there is no additional space for HOB creation, then ASSERT().\r
828\r
829 @param BaseAddress The 64 bit physical address of the memory.\r
830 @param Length The length of the memory allocation in bytes.\r
831 @param MemoryType Type of memory allocated by this HOB.\r
832\r
833**/\r
834VOID\r
835EFIAPI\r
836BuildMemoryAllocationHob (\r
837 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
838 IN UINT64 Length,\r
839 IN EFI_MEMORY_TYPE MemoryType\r
840 )\r
841{\r
842 EFI_HOB_MEMORY_ALLOCATION *Hob;\r
843\r
844 ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
845 ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r
1c2f052d 846\r
8194a023 847 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION));\r
2dfdd3eb
RN
848 if (Hob == NULL) {\r
849 return;\r
850 }\r
1c2f052d 851\r
2f78ec7a 852 ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));\r
853 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
854 Hob->AllocDescriptor.MemoryLength = Length;\r
855 Hob->AllocDescriptor.MemoryType = MemoryType;\r
856 //\r
857 // Zero the reserved space to match HOB spec\r
858 //\r
859 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r
860}\r