]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkPkg/Library/PeiHobLibFramework/HobLib.c
IntelFrameworkPkg PeiHobLib: Check FV alignment when building FV HOB
[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
368871a3 8Copyright (c) 2007 - 2016, 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
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
313 \r
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
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
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
540 \r
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
577 \r
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
585 \r
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
614/**\r
615 Builds a Capsule Volume HOB.\r
616\r
617 This function builds a Capsule Volume 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
a5a3a29c 621 If the platform does not support Capsule Volume HOBs, then ASSERT().\r
2f78ec7a 622 If there is no additional space for HOB creation, then ASSERT().\r
623\r
624 @param BaseAddress The base address of the Capsule Volume.\r
625 @param Length The size of the Capsule Volume in bytes.\r
626\r
627**/\r
628VOID\r
629EFIAPI\r
630BuildCvHob (\r
631 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
632 IN UINT64 Length\r
633 )\r
634{\r
635 EFI_HOB_CAPSULE_VOLUME *Hob;\r
636\r
8194a023 637 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CV, (UINT16) sizeof (EFI_HOB_CAPSULE_VOLUME));\r
2dfdd3eb
RN
638 if (Hob == NULL) {\r
639 return;\r
640 }\r
2f78ec7a 641\r
642 Hob->BaseAddress = BaseAddress;\r
643 Hob->Length = Length;\r
644}\r
645\r
646/**\r
647 Builds a HOB for the CPU.\r
648\r
649 This function builds a HOB for the CPU.\r
650 It can only be invoked during PEI phase;\r
651 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
652 \r
653 If there is no additional space for HOB creation, then ASSERT().\r
654\r
655 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.\r
656 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.\r
657\r
658**/\r
659VOID\r
660EFIAPI\r
661BuildCpuHob (\r
662 IN UINT8 SizeOfMemorySpace,\r
663 IN UINT8 SizeOfIoSpace\r
664 )\r
665{\r
666 EFI_HOB_CPU *Hob;\r
667\r
8194a023 668 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CPU, (UINT16) sizeof (EFI_HOB_CPU));\r
2dfdd3eb
RN
669 if (Hob == NULL) {\r
670 return;\r
671 }\r
2f78ec7a 672\r
673 Hob->SizeOfMemorySpace = SizeOfMemorySpace;\r
674 Hob->SizeOfIoSpace = SizeOfIoSpace;\r
675\r
676 //\r
677 // Zero the reserved space to match HOB spec\r
678 //\r
679 ZeroMem (Hob->Reserved, sizeof (Hob->Reserved)); \r
680}\r
681\r
682/**\r
683 Builds a HOB for the Stack.\r
684\r
685 This function builds a HOB for the stack.\r
686 It can only be invoked during PEI phase;\r
687 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
688 \r
689 If there is no additional space for HOB creation, then ASSERT().\r
690\r
691 @param BaseAddress The 64 bit physical address of the Stack.\r
692 @param Length The length of the stack in bytes.\r
693\r
694**/\r
695VOID\r
696EFIAPI\r
697BuildStackHob (\r
698 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
699 IN UINT64 Length\r
700 )\r
701{\r
702 EFI_HOB_MEMORY_ALLOCATION_STACK *Hob;\r
703\r
704 ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
705 ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r
706\r
8194a023 707 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK));\r
2dfdd3eb
RN
708 if (Hob == NULL) {\r
709 return;\r
710 }\r
2f78ec7a 711\r
712 CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocStackGuid);\r
713 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
714 Hob->AllocDescriptor.MemoryLength = Length;\r
715 Hob->AllocDescriptor.MemoryType = EfiBootServicesData;\r
716\r
717 //\r
718 // Zero the reserved space to match HOB spec\r
719 //\r
720 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r
721}\r
722\r
723/**\r
724 Builds a HOB for the BSP store.\r
725\r
726 This function builds a HOB for BSP store.\r
727 It can only be invoked during PEI phase;\r
728 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
729 \r
730 If there is no additional space for HOB creation, then ASSERT().\r
731\r
732 @param BaseAddress The 64 bit physical address of the BSP.\r
733 @param Length The length of the BSP store in bytes.\r
734 @param MemoryType Type of memory allocated by this HOB.\r
735\r
736**/\r
737VOID\r
738EFIAPI\r
739BuildBspStoreHob (\r
740 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
741 IN UINT64 Length,\r
742 IN EFI_MEMORY_TYPE MemoryType\r
743 )\r
744{\r
745 EFI_HOB_MEMORY_ALLOCATION_BSP_STORE *Hob;\r
746\r
747 ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
748 ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r
749\r
8194a023 750 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_BSP_STORE));\r
2dfdd3eb
RN
751 if (Hob == NULL) {\r
752 return;\r
753 }\r
2f78ec7a 754\r
755 CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocBspStoreGuid);\r
756 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
757 Hob->AllocDescriptor.MemoryLength = Length;\r
758 Hob->AllocDescriptor.MemoryType = MemoryType;\r
759\r
760 //\r
761 // Zero the reserved space to match HOB spec\r
762 //\r
763 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r
764}\r
765\r
766/**\r
767 Builds a HOB for the memory allocation.\r
768\r
769 This function builds a HOB for the memory allocation.\r
770 It can only be invoked during PEI phase;\r
771 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
772 \r
773 If there is no additional space for HOB creation, then ASSERT().\r
774\r
775 @param BaseAddress The 64 bit physical address of the memory.\r
776 @param Length The length of the memory allocation in bytes.\r
777 @param MemoryType Type of memory allocated by this HOB.\r
778\r
779**/\r
780VOID\r
781EFIAPI\r
782BuildMemoryAllocationHob (\r
783 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
784 IN UINT64 Length,\r
785 IN EFI_MEMORY_TYPE MemoryType\r
786 )\r
787{\r
788 EFI_HOB_MEMORY_ALLOCATION *Hob;\r
789\r
790 ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
791 ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r
792 \r
8194a023 793 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION));\r
2dfdd3eb
RN
794 if (Hob == NULL) {\r
795 return;\r
796 }\r
2f78ec7a 797 \r
798 ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));\r
799 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
800 Hob->AllocDescriptor.MemoryLength = Length;\r
801 Hob->AllocDescriptor.MemoryType = MemoryType;\r
802 //\r
803 // Zero the reserved space to match HOB spec\r
804 //\r
805 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r
806}\r