]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/PeiHobLib/HobLib.c
MdePkg: Clean up source files
[mirror_edk2.git] / MdePkg / Library / PeiHobLib / HobLib.c
CommitLineData
66f0059f 1/** @file\r
6812ef9f 2 Provide Hob Library functions for Pei phase.\r
66f0059f 3\r
9095d37b 4Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
19388d29 5This program and the accompanying materials\r
3e5c3238 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
58380e9c 8http://opensource.org/licenses/bsd-license.php.\r
66f0059f 9\r
3e5c3238 10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
66f0059f 12\r
66f0059f 13**/\r
14\r
66f0059f 15#include <PiPei.h>\r
c892d846 16\r
66f0059f 17#include <Guid/MemoryAllocationHob.h>\r
c892d846 18\r
66f0059f 19#include <Library/HobLib.h>\r
20#include <Library/DebugLib.h>\r
21#include <Library/PeiServicesLib.h>\r
22#include <Library/BaseMemoryLib.h>\r
23\r
24/**\r
25 Returns the pointer to the HOB list.\r
26\r
27 This function returns the pointer to first HOB in the list.\r
9095d37b 28 For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer\r
3e5c3238 29 to the HOB list. For the DXE phase, the HOB list pointer can be retrieved through\r
30 the EFI System Table by looking up theHOB list GUID in the System Configuration Table.\r
9095d37b
LG
31 Since the System Configuration Table does not exist that the time the DXE Core is\r
32 launched, the DXE Core uses a global variable from the DXE Core Entry Point Library\r
3e5c3238 33 to manage the pointer to the HOB list.\r
9095d37b 34\r
3e5c3238 35 If the pointer to the HOB list is NULL, then ASSERT().\r
9095d37b 36\r
66f0059f 37 @return The pointer to the HOB list.\r
38\r
39**/\r
40VOID *\r
41EFIAPI\r
42GetHobList (\r
43 VOID\r
44 )\r
45{\r
46 EFI_STATUS Status;\r
47 VOID *HobList;\r
48\r
49 Status = PeiServicesGetHobList (&HobList);\r
50 ASSERT_EFI_ERROR (Status);\r
51 ASSERT (HobList != NULL);\r
52\r
53 return HobList;\r
54}\r
55\r
56/**\r
57 Returns the next instance of a HOB type from the starting HOB.\r
58\r
9095d37b 59 This function searches the first instance of a HOB type from the starting HOB pointer.\r
66f0059f 60 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.\r
61 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r
62 unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r
63 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r
9095d37b 64\r
66f0059f 65 If HobStart is NULL, then ASSERT().\r
66\r
67 @param Type The HOB type to return.\r
68 @param HobStart The starting HOB pointer to search from.\r
69\r
70 @return The next instance of a HOB type from the starting HOB.\r
71\r
72**/\r
73VOID *\r
74EFIAPI\r
75GetNextHob (\r
76 IN UINT16 Type,\r
77 IN CONST VOID *HobStart\r
78 )\r
79{\r
80 EFI_PEI_HOB_POINTERS Hob;\r
81\r
82 ASSERT (HobStart != NULL);\r
9095d37b 83\r
66f0059f 84 Hob.Raw = (UINT8 *) HobStart;\r
85 //\r
86 // Parse the HOB list until end of list or matching type is found.\r
87 //\r
88 while (!END_OF_HOB_LIST (Hob)) {\r
89 if (Hob.Header->HobType == Type) {\r
90 return Hob.Raw;\r
91 }\r
92 Hob.Raw = GET_NEXT_HOB (Hob);\r
93 }\r
94 return NULL;\r
95}\r
96\r
97/**\r
98 Returns the first instance of a HOB type among the whole HOB list.\r
99\r
9095d37b
LG
100 This function searches the first instance of a HOB type among the whole HOB list.\r
101 If there does not exist such HOB type in the HOB list, it will return NULL.\r
102\r
3e5c3238 103 If the pointer to the HOB list is NULL, then ASSERT().\r
66f0059f 104\r
105 @param Type The HOB type to return.\r
106\r
107 @return The next instance of a HOB type from the starting HOB.\r
108\r
109**/\r
110VOID *\r
111EFIAPI\r
112GetFirstHob (\r
113 IN UINT16 Type\r
114 )\r
115{\r
116 VOID *HobList;\r
117\r
118 HobList = GetHobList ();\r
119 return GetNextHob (Type, HobList);\r
120}\r
121\r
122/**\r
3e5c3238 123 Returns the next instance of the matched GUID HOB from the starting HOB.\r
9095d37b
LG
124\r
125 This function searches the first instance of a HOB from the starting HOB pointer.\r
126 Such HOB should satisfy two conditions:\r
127 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.\r
128 If there does not exist such HOB from the starting HOB pointer, it will return NULL.\r
66f0059f 129 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
58380e9c 130 to extract the data section and its size information, respectively.\r
66f0059f 131 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r
132 unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r
133 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r
9095d37b 134\r
66f0059f 135 If Guid is NULL, then ASSERT().\r
136 If HobStart is NULL, then ASSERT().\r
137\r
138 @param Guid The GUID to match with in the HOB list.\r
139 @param HobStart A pointer to a Guid.\r
140\r
141 @return The next instance of the matched GUID HOB from the starting HOB.\r
142\r
143**/\r
144VOID *\r
145EFIAPI\r
146GetNextGuidHob (\r
147 IN CONST EFI_GUID *Guid,\r
148 IN CONST VOID *HobStart\r
149 )\r
150{\r
151 EFI_PEI_HOB_POINTERS GuidHob;\r
152\r
153 GuidHob.Raw = (UINT8 *) HobStart;\r
154 while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {\r
155 if (CompareGuid (Guid, &GuidHob.Guid->Name)) {\r
156 break;\r
157 }\r
158 GuidHob.Raw = GET_NEXT_HOB (GuidHob);\r
159 }\r
160 return GuidHob.Raw;\r
161}\r
162\r
163/**\r
3e5c3238 164 Returns the first instance of the matched GUID HOB among the whole HOB list.\r
9095d37b
LG
165\r
166 This function searches the first instance of a HOB among the whole HOB list.\r
66f0059f 167 Such HOB should satisfy two conditions:\r
168 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.\r
169 If there does not exist such HOB from the starting HOB pointer, it will return NULL.\r
170 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
58380e9c 171 to extract the data section and its size information, respectively.\r
9095d37b 172\r
3e5c3238 173 If the pointer to the HOB list is NULL, then ASSERT().\r
66f0059f 174 If Guid is NULL, then ASSERT().\r
175\r
176 @param Guid The GUID to match with in the HOB list.\r
177\r
178 @return The first instance of the matched GUID HOB among the whole HOB list.\r
179\r
180**/\r
181VOID *\r
182EFIAPI\r
183GetFirstGuidHob (\r
184 IN CONST EFI_GUID *Guid\r
185 )\r
186{\r
187 VOID *HobList;\r
188\r
189 HobList = GetHobList ();\r
190 return GetNextGuidHob (Guid, HobList);\r
191}\r
192\r
193/**\r
3e5c3238 194 Get the system boot mode from the HOB list.\r
66f0059f 195\r
9095d37b 196 This function returns the system boot mode information from the\r
3e5c3238 197 PHIT HOB in HOB list.\r
66f0059f 198\r
3e5c3238 199 If the pointer to the HOB list is NULL, then ASSERT().\r
9095d37b 200\r
58380e9c 201 @param VOID.\r
66f0059f 202\r
203 @return The Boot Mode.\r
204\r
205**/\r
206EFI_BOOT_MODE\r
207EFIAPI\r
208GetBootModeHob (\r
209 VOID\r
210 )\r
211{\r
212 EFI_STATUS Status;\r
213 EFI_BOOT_MODE BootMode;\r
214\r
215 Status = PeiServicesGetBootMode (&BootMode);\r
216 ASSERT_EFI_ERROR (Status);\r
217\r
218 return BootMode;\r
219}\r
220\r
221/**\r
222 Adds a new HOB to the HOB List.\r
223\r
224 This internal function enables PEIMs to create various types of HOBs.\r
225\r
226 @param Type Type of the new HOB.\r
227 @param Length Length of the new HOB to allocate.\r
228\r
ef2635c3
RN
229 @retval NULL The HOB could not be allocated.\r
230 @retval others The address of new HOB.\r
66f0059f 231\r
232**/\r
66f0059f 233VOID *\r
42eedea9 234EFIAPI\r
66f0059f 235InternalPeiCreateHob (\r
236 IN UINT16 Type,\r
237 IN UINT16 Length\r
238 )\r
239{\r
240 EFI_STATUS Status;\r
241 VOID *Hob;\r
242\r
243 Status = PeiServicesCreateHob (Type, Length, &Hob);\r
ef2635c3
RN
244 if (EFI_ERROR (Status)) {\r
245 Hob = NULL;\r
246 }\r
66f0059f 247 //\r
248 // Assume the process of HOB building is always successful.\r
249 //\r
ef2635c3 250 ASSERT (Hob != NULL);\r
66f0059f 251 return Hob;\r
252}\r
253\r
254/**\r
255 Builds a HOB for a loaded PE32 module.\r
256\r
257 This function builds a HOB for a loaded PE32 module.\r
258 It can only be invoked during PEI phase;\r
259 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
9095d37b 260\r
66f0059f 261 If ModuleName is NULL, then ASSERT().\r
262 If there is no additional space for HOB creation, then ASSERT().\r
263\r
264 @param ModuleName The GUID File Name of the module.\r
265 @param MemoryAllocationModule The 64 bit physical address of the module.\r
266 @param ModuleLength The length of the module in bytes.\r
3e5c3238 267 @param EntryPoint The 64 bit physical address of the module entry point.\r
66f0059f 268\r
269**/\r
270VOID\r
271EFIAPI\r
272BuildModuleHob (\r
273 IN CONST EFI_GUID *ModuleName,\r
274 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,\r
275 IN UINT64 ModuleLength,\r
276 IN EFI_PHYSICAL_ADDRESS EntryPoint\r
277 )\r
278{\r
279 EFI_HOB_MEMORY_ALLOCATION_MODULE *Hob;\r
280\r
0a7d0741 281 ASSERT (((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) &&\r
282 ((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0));\r
283\r
f0b0ba31 284 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE));\r
ef2635c3
RN
285 if (Hob == NULL) {\r
286 return;\r
287 }\r
66f0059f 288\r
289 CopyGuid (&(Hob->MemoryAllocationHeader.Name), &gEfiHobMemoryAllocModuleGuid);\r
290 Hob->MemoryAllocationHeader.MemoryBaseAddress = MemoryAllocationModule;\r
291 Hob->MemoryAllocationHeader.MemoryLength = ModuleLength;\r
292 Hob->MemoryAllocationHeader.MemoryType = EfiBootServicesCode;\r
293\r
294 //\r
295 // Zero the reserved space to match HOB spec\r
296 //\r
297 ZeroMem (Hob->MemoryAllocationHeader.Reserved, sizeof (Hob->MemoryAllocationHeader.Reserved));\r
9095d37b 298\r
66f0059f 299 CopyGuid (&Hob->ModuleName, ModuleName);\r
300 Hob->EntryPoint = EntryPoint;\r
301}\r
302\r
e4b0415d 303/**\r
f1e2b728 304 Builds a HOB that describes a chunk of system memory with Owner GUID.\r
e4b0415d
HT
305\r
306 This function builds a HOB that describes a chunk of system memory.\r
307 It can only be invoked during PEI phase;\r
308 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
9095d37b 309\r
e4b0415d
HT
310 If there is no additional space for HOB creation, then ASSERT().\r
311\r
312 @param ResourceType The type of resource described by this HOB.\r
313 @param ResourceAttribute The resource attributes of the memory described by this HOB.\r
314 @param PhysicalStart The 64 bit physical address of memory described by this HOB.\r
315 @param NumberOfBytes The length of the memory described by this HOB in bytes.\r
f1e2b728 316 @param OwnerGUID GUID for the owner of this resource.\r
e4b0415d
HT
317\r
318**/\r
319VOID\r
320EFIAPI\r
321BuildResourceDescriptorWithOwnerHob (\r
322 IN EFI_RESOURCE_TYPE ResourceType,\r
323 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,\r
324 IN EFI_PHYSICAL_ADDRESS PhysicalStart,\r
325 IN UINT64 NumberOfBytes,\r
326 IN EFI_GUID *OwnerGUID\r
327 )\r
328{\r
329 EFI_HOB_RESOURCE_DESCRIPTOR *Hob;\r
a75cf433
SZ
330\r
331 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, (UINT16) sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));\r
332 if (Hob == NULL) {\r
333 return;\r
334 }\r
e4b0415d
HT
335\r
336 Hob->ResourceType = ResourceType;\r
337 Hob->ResourceAttribute = ResourceAttribute;\r
338 Hob->PhysicalStart = PhysicalStart;\r
339 Hob->ResourceLength = NumberOfBytes;\r
340\r
341 CopyGuid (&Hob->Owner, OwnerGUID);\r
f1e2b728
SZ
342}\r
343\r
66f0059f 344/**\r
345 Builds a HOB that describes a chunk of system memory.\r
346\r
347 This function builds a HOB that describes a chunk of system memory.\r
348 It can only be invoked during PEI phase;\r
349 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
9095d37b 350\r
66f0059f 351 If there is no additional space for HOB creation, then ASSERT().\r
352\r
353 @param ResourceType The type of resource described by this HOB.\r
354 @param ResourceAttribute The resource attributes of the memory described by this HOB.\r
355 @param PhysicalStart The 64 bit physical address of memory described by this HOB.\r
356 @param NumberOfBytes The length of the memory described by this HOB in bytes.\r
357\r
358**/\r
359VOID\r
360EFIAPI\r
361BuildResourceDescriptorHob (\r
362 IN EFI_RESOURCE_TYPE ResourceType,\r
363 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,\r
364 IN EFI_PHYSICAL_ADDRESS PhysicalStart,\r
365 IN UINT64 NumberOfBytes\r
366 )\r
367{\r
368 EFI_HOB_RESOURCE_DESCRIPTOR *Hob;\r
369\r
f0b0ba31 370 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, (UINT16) sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));\r
ef2635c3
RN
371 if (Hob == NULL) {\r
372 return;\r
373 }\r
66f0059f 374\r
375 Hob->ResourceType = ResourceType;\r
376 Hob->ResourceAttribute = ResourceAttribute;\r
377 Hob->PhysicalStart = PhysicalStart;\r
378 Hob->ResourceLength = NumberOfBytes;\r
0ca7b0b8 379 ZeroMem (&(Hob->Owner), sizeof (EFI_GUID));\r
66f0059f 380}\r
381\r
382/**\r
9095d37b 383 Builds a customized HOB tagged with a GUID for identification and returns\r
3e5c3238 384 the start address of GUID HOB data.\r
66f0059f 385\r
9095d37b
LG
386 This function builds a customized HOB tagged with a GUID for identification\r
387 and returns the start address of GUID HOB data so that caller can fill the customized data.\r
66f0059f 388 The HOB Header and Name field is already stripped.\r
389 It can only be invoked during PEI phase;\r
390 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
9095d37b 391\r
66f0059f 392 If Guid is NULL, then ASSERT().\r
393 If there is no additional space for HOB creation, then ASSERT().\r
192764db
LG
394 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
395 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.\r
66f0059f 396\r
397 @param Guid The GUID to tag the customized HOB.\r
398 @param DataLength The size of the data payload for the GUID HOB.\r
399\r
ef2635c3
RN
400 @retval NULL The GUID HOB could not be allocated.\r
401 @retval others The start address of GUID HOB data.\r
66f0059f 402\r
403**/\r
404VOID *\r
405EFIAPI\r
406BuildGuidHob (\r
407 IN CONST EFI_GUID *Guid,\r
408 IN UINTN DataLength\r
409 )\r
410{\r
411 EFI_HOB_GUID_TYPE *Hob;\r
412\r
ef2635c3
RN
413 //\r
414 // Make sure Guid is valid\r
415 //\r
416 ASSERT (Guid != NULL);\r
9095d37b 417\r
66f0059f 418 //\r
419 // Make sure that data length is not too long.\r
420 //\r
192764db 421 ASSERT (DataLength <= (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)));\r
66f0059f 422\r
423 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16) (sizeof (EFI_HOB_GUID_TYPE) + DataLength));\r
ef2635c3
RN
424 if (Hob == NULL) {\r
425 return Hob;\r
426 }\r
66f0059f 427 CopyGuid (&Hob->Name, Guid);\r
428 return Hob + 1;\r
429}\r
430\r
431/**\r
9095d37b 432 Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB\r
3e5c3238 433 data field, and returns the start address of the GUID HOB data.\r
66f0059f 434\r
3e5c3238 435 This function builds a customized HOB tagged with a GUID for identification and copies the input\r
9095d37b
LG
436 data to the HOB data field and returns the start address of the GUID HOB data. It can only be\r
437 invoked during PEI phase; for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
66f0059f 438 The HOB Header and Name field is already stripped.\r
439 It can only be invoked during PEI phase;\r
440 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
9095d37b 441\r
66f0059f 442 If Guid is NULL, then ASSERT().\r
443 If Data is NULL and DataLength > 0, then ASSERT().\r
444 If there is no additional space for HOB creation, then ASSERT().\r
192764db
LG
445 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
446 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.\r
66f0059f 447\r
448 @param Guid The GUID to tag the customized HOB.\r
449 @param Data The data to be copied into the data field of the GUID HOB.\r
450 @param DataLength The size of the data payload for the GUID HOB.\r
451\r
ef2635c3
RN
452 @retval NULL The GUID HOB could not be allocated.\r
453 @retval others The start address of GUID HOB data.\r
66f0059f 454\r
455**/\r
456VOID *\r
457EFIAPI\r
458BuildGuidDataHob (\r
459 IN CONST EFI_GUID *Guid,\r
460 IN VOID *Data,\r
461 IN UINTN DataLength\r
462 )\r
463{\r
464 VOID *HobData;\r
465\r
466 ASSERT (Data != NULL || DataLength == 0);\r
467\r
468 HobData = BuildGuidHob (Guid, DataLength);\r
ef2635c3
RN
469 if (HobData == NULL) {\r
470 return HobData;\r
471 }\r
66f0059f 472\r
473 return CopyMem (HobData, Data, DataLength);\r
474}\r
475\r
471d6210
SZ
476/**\r
477 Check FV alignment.\r
478\r
479 @param BaseAddress The base address of the Firmware Volume.\r
480 @param Length The size of the Firmware Volume in bytes.\r
481\r
482 @retval TRUE FvImage buffer is at its required alignment.\r
483 @retval FALSE FvImage buffer is not at its required alignment.\r
484\r
485**/\r
486BOOLEAN\r
487InternalCheckFvAlignment (\r
488 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
489 IN UINT64 Length\r
490 )\r
491{\r
492 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
493 UINT32 FvAlignment;\r
494\r
495 FvAlignment = 0;\r
496 FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress;\r
497\r
498 //\r
499 // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume\r
500 // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from\r
501 // its initial linked location and maintain its alignment.\r
502 //\r
503 if ((FwVolHeader->Attributes & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {\r
504 //\r
505 // Get FvHeader alignment\r
506 //\r
507 FvAlignment = 1 << ((FwVolHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);\r
508 //\r
509 // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.\r
510 //\r
511 if (FvAlignment < 8) {\r
512 FvAlignment = 8;\r
513 }\r
514 if ((UINTN)BaseAddress % FvAlignment != 0) {\r
515 //\r
516 // FvImage buffer is not at its required alignment.\r
517 //\r
518 DEBUG ((\r
519 DEBUG_ERROR,\r
520 "Unaligned FvImage found at 0x%lx:0x%lx, the required alignment is 0x%x\n",\r
521 BaseAddress,\r
522 Length,\r
523 FvAlignment\r
524 ));\r
525 return FALSE;\r
526 }\r
527 }\r
528\r
529 return TRUE;\r
530}\r
531\r
66f0059f 532/**\r
533 Builds a Firmware Volume HOB.\r
534\r
535 This function builds a Firmware Volume HOB.\r
536 It can only be invoked during PEI phase;\r
537 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
9095d37b 538\r
66f0059f 539 If there is no additional space for HOB creation, then ASSERT().\r
471d6210 540 If the FvImage buffer is not at its required alignment, then ASSERT().\r
66f0059f 541\r
542 @param BaseAddress The base address of the Firmware Volume.\r
543 @param Length The size of the Firmware Volume in bytes.\r
544\r
545**/\r
546VOID\r
547EFIAPI\r
548BuildFvHob (\r
549 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
550 IN UINT64 Length\r
551 )\r
552{\r
553 EFI_HOB_FIRMWARE_VOLUME *Hob;\r
554\r
471d6210
SZ
555 if (!InternalCheckFvAlignment (BaseAddress, Length)) {\r
556 ASSERT (FALSE);\r
557 return;\r
558 }\r
559\r
f0b0ba31 560 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME));\r
ef2635c3
RN
561 if (Hob == NULL) {\r
562 return;\r
563 }\r
66f0059f 564\r
565 Hob->BaseAddress = BaseAddress;\r
566 Hob->Length = Length;\r
567}\r
568\r
07ad9b81 569/**\r
570 Builds a EFI_HOB_TYPE_FV2 HOB.\r
571\r
572 This function builds a EFI_HOB_TYPE_FV2 HOB.\r
573 It can only be invoked during PEI phase;\r
574 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
9095d37b 575\r
07ad9b81 576 If there is no additional space for HOB creation, then ASSERT().\r
471d6210 577 If the FvImage buffer is not at its required alignment, then ASSERT().\r
07ad9b81 578\r
579 @param BaseAddress The base address of the Firmware Volume.\r
580 @param Length The size of the Firmware Volume in bytes.\r
3e5c3238 581 @param FvName The name of the Firmware Volume.\r
07ad9b81 582 @param FileName The name of the file.\r
9095d37b 583\r
07ad9b81 584**/\r
585VOID\r
586EFIAPI\r
587BuildFv2Hob (\r
588 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
589 IN UINT64 Length,\r
590 IN CONST EFI_GUID *FvName,\r
591 IN CONST EFI_GUID *FileName\r
592 )\r
593{\r
594 EFI_HOB_FIRMWARE_VOLUME2 *Hob;\r
595\r
471d6210
SZ
596 if (!InternalCheckFvAlignment (BaseAddress, Length)) {\r
597 ASSERT (FALSE);\r
598 return;\r
599 }\r
600\r
f0b0ba31 601 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV2, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME2));\r
ef2635c3
RN
602 if (Hob == NULL) {\r
603 return;\r
604 }\r
07ad9b81 605\r
606 Hob->BaseAddress = BaseAddress;\r
607 Hob->Length = Length;\r
3a364554 608 CopyGuid (&Hob->FvName, FvName);\r
609 CopyGuid (&Hob->FileName, FileName);\r
07ad9b81 610}\r
611\r
5450086c
SZ
612/**\r
613 Builds a EFI_HOB_TYPE_FV3 HOB.\r
614\r
615 This function builds a EFI_HOB_TYPE_FV3 HOB.\r
616 It can only be invoked during PEI phase;\r
617 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
618\r
619 If there is no additional space for HOB creation, then ASSERT().\r
620 If the FvImage buffer is not at its required alignment, then ASSERT().\r
621\r
622 @param BaseAddress The base address of the Firmware Volume.\r
623 @param Length The size of the Firmware Volume in bytes.\r
624 @param AuthenticationStatus The authentication status.\r
625 @param ExtractedFv TRUE if the FV was extracted as a file within\r
626 another firmware volume. FALSE otherwise.\r
627 @param FvName The name of the Firmware Volume.\r
628 Valid only if IsExtractedFv is TRUE.\r
629 @param FileName The name of the file.\r
630 Valid only if IsExtractedFv is TRUE.\r
631\r
632**/\r
633VOID\r
634EFIAPI\r
635BuildFv3Hob (\r
636 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
637 IN UINT64 Length,\r
638 IN UINT32 AuthenticationStatus,\r
639 IN BOOLEAN ExtractedFv,\r
640 IN CONST EFI_GUID *FvName, OPTIONAL\r
641 IN CONST EFI_GUID *FileName OPTIONAL\r
642 )\r
643{\r
644 EFI_HOB_FIRMWARE_VOLUME3 *Hob;\r
645\r
646 if (!InternalCheckFvAlignment (BaseAddress, Length)) {\r
647 ASSERT (FALSE);\r
648 return;\r
649 }\r
650\r
651 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV3, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME3));\r
652 if (Hob == NULL) {\r
653 return;\r
654 }\r
655\r
656 Hob->BaseAddress = BaseAddress;\r
657 Hob->Length = Length;\r
658 Hob->AuthenticationStatus = AuthenticationStatus;\r
659 Hob->ExtractedFv = ExtractedFv;\r
660 if (ExtractedFv) {\r
661 CopyGuid (&Hob->FvName, FvName);\r
662 CopyGuid (&Hob->FileName, FileName);\r
663 }\r
664}\r
665\r
66f0059f 666/**\r
667 Builds a Capsule Volume HOB.\r
668\r
faf46b40 669 This function builds a Capsule Volume HOB.\r
670 It can only be invoked during PEI phase;\r
671 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
9095d37b 672\r
c85cea80 673 If the platform does not support Capsule Volume HOBs, then ASSERT().\r
faf46b40 674 If there is no additional space for HOB creation, then ASSERT().\r
675\r
676 @param BaseAddress The base address of the Capsule Volume.\r
677 @param Length The size of the Capsule Volume in bytes.\r
66f0059f 678\r
679**/\r
680VOID\r
681EFIAPI\r
682BuildCvHob (\r
683 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
684 IN UINT64 Length\r
685 )\r
686{\r
61acaac8 687 EFI_HOB_UEFI_CAPSULE *Hob;\r
688\r
f0b0ba31 689 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_UEFI_CAPSULE, (UINT16) sizeof (EFI_HOB_UEFI_CAPSULE));\r
ef2635c3
RN
690 if (Hob == NULL) {\r
691 return;\r
692 }\r
61acaac8 693\r
694 Hob->BaseAddress = BaseAddress;\r
695 Hob->Length = Length;\r
66f0059f 696}\r
697\r
698/**\r
699 Builds a HOB for the CPU.\r
700\r
701 This function builds a HOB for the CPU.\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
9095d37b 704\r
66f0059f 705 If there is no additional space for HOB creation, then ASSERT().\r
706\r
707 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.\r
708 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.\r
709\r
710**/\r
711VOID\r
712EFIAPI\r
713BuildCpuHob (\r
714 IN UINT8 SizeOfMemorySpace,\r
715 IN UINT8 SizeOfIoSpace\r
716 )\r
717{\r
718 EFI_HOB_CPU *Hob;\r
719\r
f0b0ba31 720 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CPU, (UINT16) sizeof (EFI_HOB_CPU));\r
ef2635c3
RN
721 if (Hob == NULL) {\r
722 return;\r
723 }\r
66f0059f 724\r
725 Hob->SizeOfMemorySpace = SizeOfMemorySpace;\r
726 Hob->SizeOfIoSpace = SizeOfIoSpace;\r
727\r
728 //\r
729 // Zero the reserved space to match HOB spec\r
730 //\r
9095d37b 731 ZeroMem (Hob->Reserved, sizeof (Hob->Reserved));\r
66f0059f 732}\r
733\r
734/**\r
735 Builds a HOB for the Stack.\r
736\r
737 This function builds a HOB for the stack.\r
738 It can only be invoked during PEI phase;\r
739 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
9095d37b 740\r
66f0059f 741 If there is no additional space for HOB creation, then ASSERT().\r
742\r
743 @param BaseAddress The 64 bit physical address of the Stack.\r
744 @param Length The length of the stack in bytes.\r
745\r
746**/\r
747VOID\r
748EFIAPI\r
749BuildStackHob (\r
750 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
751 IN UINT64 Length\r
752 )\r
753{\r
754 EFI_HOB_MEMORY_ALLOCATION_STACK *Hob;\r
755\r
0a7d0741 756 ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
757 ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r
758\r
f0b0ba31 759 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK));\r
ef2635c3
RN
760 if (Hob == NULL) {\r
761 return;\r
762 }\r
66f0059f 763\r
764 CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocStackGuid);\r
765 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
766 Hob->AllocDescriptor.MemoryLength = Length;\r
dda0251d 767 Hob->AllocDescriptor.MemoryType = EfiBootServicesData;\r
66f0059f 768\r
769 //\r
770 // Zero the reserved space to match HOB spec\r
771 //\r
772 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r
773}\r
774\r
775/**\r
776 Builds a HOB for the BSP store.\r
777\r
778 This function builds a HOB for BSP store.\r
779 It can only be invoked during PEI phase;\r
780 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
9095d37b 781\r
66f0059f 782 If there is no additional space for HOB creation, then ASSERT().\r
783\r
784 @param BaseAddress The 64 bit physical address of the BSP.\r
785 @param Length The length of the BSP store in bytes.\r
58380e9c 786 @param MemoryType The type of memory allocated by this HOB.\r
66f0059f 787\r
788**/\r
789VOID\r
790EFIAPI\r
791BuildBspStoreHob (\r
792 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
793 IN UINT64 Length,\r
794 IN EFI_MEMORY_TYPE MemoryType\r
795 )\r
796{\r
797 EFI_HOB_MEMORY_ALLOCATION_BSP_STORE *Hob;\r
798\r
0a7d0741 799 ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
800 ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r
801\r
f0b0ba31 802 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_BSP_STORE));\r
ef2635c3
RN
803 if (Hob == NULL) {\r
804 return;\r
805 }\r
66f0059f 806\r
807 CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocBspStoreGuid);\r
808 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
809 Hob->AllocDescriptor.MemoryLength = Length;\r
810 Hob->AllocDescriptor.MemoryType = MemoryType;\r
811\r
812 //\r
813 // Zero the reserved space to match HOB spec\r
814 //\r
815 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r
816}\r
817\r
818/**\r
819 Builds a HOB for the memory allocation.\r
820\r
821 This function builds a HOB for the memory allocation.\r
822 It can only be invoked during PEI phase;\r
823 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
9095d37b 824\r
66f0059f 825 If there is no additional space for HOB creation, then ASSERT().\r
826\r
827 @param BaseAddress The 64 bit physical address of the memory.\r
828 @param Length The length of the memory allocation in bytes.\r
58380e9c 829 @param MemoryType The type of memory allocated by this HOB.\r
66f0059f 830\r
831**/\r
832VOID\r
833EFIAPI\r
834BuildMemoryAllocationHob (\r
835 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
836 IN UINT64 Length,\r
837 IN EFI_MEMORY_TYPE MemoryType\r
838 )\r
839{\r
840 EFI_HOB_MEMORY_ALLOCATION *Hob;\r
841\r
0a7d0741 842 ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
843 ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r
9095d37b 844\r
f0b0ba31 845 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION));\r
ef2635c3
RN
846 if (Hob == NULL) {\r
847 return;\r
848 }\r
9095d37b 849\r
66f0059f 850 ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));\r
851 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
852 Hob->AllocDescriptor.MemoryLength = Length;\r
853 Hob->AllocDescriptor.MemoryType = MemoryType;\r
854 //\r
855 // Zero the reserved space to match HOB spec\r
856 //\r
857 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r
858}\r