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