]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Library/PeiHobLib/HobLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / PeiHobLib / HobLib.c
... / ...
CommitLineData
1/** @file\r
2 Provide Hob Library functions for Pei phase.\r
3\r
4Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
5SPDX-License-Identifier: BSD-2-Clause-Patent\r
6\r
7**/\r
8\r
9#include <PiPei.h>\r
10\r
11#include <Guid/MemoryAllocationHob.h>\r
12\r
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
22 For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer\r
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
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
27 to manage the pointer to the HOB list.\r
28\r
29 If the pointer to the HOB list is NULL, then ASSERT().\r
30\r
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
40 EFI_STATUS Status;\r
41 VOID *HobList;\r
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
53 This function searches the first instance of a HOB type from the starting HOB pointer.\r
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
58\r
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
70 IN UINT16 Type,\r
71 IN CONST VOID *HobStart\r
72 )\r
73{\r
74 EFI_PEI_HOB_POINTERS Hob;\r
75\r
76 ASSERT (HobStart != NULL);\r
77\r
78 Hob.Raw = (UINT8 *)HobStart;\r
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
86\r
87 Hob.Raw = GET_NEXT_HOB (Hob);\r
88 }\r
89\r
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
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
99 If the pointer to the HOB list is NULL, then ASSERT().\r
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
109 IN UINT16 Type\r
110 )\r
111{\r
112 VOID *HobList;\r
113\r
114 HobList = GetHobList ();\r
115 return GetNextHob (Type, HobList);\r
116}\r
117\r
118/**\r
119 Returns the next instance of the matched GUID HOB from the starting HOB.\r
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
125 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
126 to extract the data section and its size information, respectively.\r
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
130\r
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
143 IN CONST EFI_GUID *Guid,\r
144 IN CONST VOID *HobStart\r
145 )\r
146{\r
147 EFI_PEI_HOB_POINTERS GuidHob;\r
148\r
149 GuidHob.Raw = (UINT8 *)HobStart;\r
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
154\r
155 GuidHob.Raw = GET_NEXT_HOB (GuidHob);\r
156 }\r
157\r
158 return GuidHob.Raw;\r
159}\r
160\r
161/**\r
162 Returns the first instance of the matched GUID HOB among the whole HOB list.\r
163\r
164 This function searches the first instance of a HOB among the whole HOB list.\r
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
169 to extract the data section and its size information, respectively.\r
170\r
171 If the pointer to the HOB list is NULL, then ASSERT().\r
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
182 IN CONST EFI_GUID *Guid\r
183 )\r
184{\r
185 VOID *HobList;\r
186\r
187 HobList = GetHobList ();\r
188 return GetNextGuidHob (Guid, HobList);\r
189}\r
190\r
191/**\r
192 Get the system boot mode from the HOB list.\r
193\r
194 This function returns the system boot mode information from the\r
195 PHIT HOB in HOB list.\r
196\r
197 If the pointer to the HOB list is NULL, then ASSERT().\r
198\r
199 @param VOID.\r
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
210 EFI_STATUS Status;\r
211 EFI_BOOT_MODE BootMode;\r
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
227 @retval NULL The HOB could not be allocated.\r
228 @retval others The address of new HOB.\r
229\r
230**/\r
231VOID *\r
232EFIAPI\r
233InternalPeiCreateHob (\r
234 IN UINT16 Type,\r
235 IN UINT16 Length\r
236 )\r
237{\r
238 EFI_STATUS Status;\r
239 VOID *Hob;\r
240\r
241 Status = PeiServicesCreateHob (Type, Length, &Hob);\r
242 if (EFI_ERROR (Status)) {\r
243 Hob = NULL;\r
244 }\r
245\r
246 //\r
247 // Assume the process of HOB building is always successful.\r
248 //\r
249 ASSERT (Hob != NULL);\r
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
259\r
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
266 @param EntryPoint The 64 bit physical address of the module entry point.\r
267\r
268**/\r
269VOID\r
270EFIAPI\r
271BuildModuleHob (\r
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
276 )\r
277{\r
278 EFI_HOB_MEMORY_ALLOCATION_MODULE *Hob;\r
279\r
280 ASSERT (\r
281 ((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) &&\r
282 ((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0)\r
283 );\r
284\r
285 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16)sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE));\r
286 if (Hob == NULL) {\r
287 return;\r
288 }\r
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
299\r
300 CopyGuid (&Hob->ModuleName, ModuleName);\r
301 Hob->EntryPoint = EntryPoint;\r
302}\r
303\r
304/**\r
305 Builds a HOB that describes a chunk of system memory with Owner GUID.\r
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
310\r
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
317 @param OwnerGUID GUID for the owner of this resource.\r
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
331\r
332 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, (UINT16)sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));\r
333 if (Hob == NULL) {\r
334 return;\r
335 }\r
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
343}\r
344\r
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
351\r
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
371 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, (UINT16)sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));\r
372 if (Hob == NULL) {\r
373 return;\r
374 }\r
375\r
376 Hob->ResourceType = ResourceType;\r
377 Hob->ResourceAttribute = ResourceAttribute;\r
378 Hob->PhysicalStart = PhysicalStart;\r
379 Hob->ResourceLength = NumberOfBytes;\r
380 ZeroMem (&(Hob->Owner), sizeof (EFI_GUID));\r
381}\r
382\r
383/**\r
384 Builds a customized HOB tagged with a GUID for identification and returns\r
385 the start address of GUID HOB data.\r
386\r
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
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
392\r
393 If Guid is NULL, then ASSERT().\r
394 If there is no additional space for HOB creation, then ASSERT().\r
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
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
401 @retval NULL The GUID HOB could not be allocated.\r
402 @retval others The start address of GUID HOB data.\r
403\r
404**/\r
405VOID *\r
406EFIAPI\r
407BuildGuidHob (\r
408 IN CONST EFI_GUID *Guid,\r
409 IN UINTN DataLength\r
410 )\r
411{\r
412 EFI_HOB_GUID_TYPE *Hob;\r
413\r
414 //\r
415 // Make sure Guid is valid\r
416 //\r
417 ASSERT (Guid != NULL);\r
418\r
419 //\r
420 // Make sure that data length is not too long.\r
421 //\r
422 ASSERT (DataLength <= (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)));\r
423\r
424 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16)(sizeof (EFI_HOB_GUID_TYPE) + DataLength));\r
425 if (Hob == NULL) {\r
426 return Hob;\r
427 }\r
428\r
429 CopyGuid (&Hob->Name, Guid);\r
430 return Hob + 1;\r
431}\r
432\r
433/**\r
434 Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB\r
435 data field, and returns the start address of the GUID HOB data.\r
436\r
437 This function builds a customized HOB tagged with a GUID for identification and copies the input\r
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
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
443\r
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
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
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
454 @retval NULL The GUID HOB could not be allocated.\r
455 @retval others The start address of GUID HOB data.\r
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
471 if (HobData == NULL) {\r
472 return HobData;\r
473 }\r
474\r
475 return CopyMem (HobData, Data, DataLength);\r
476}\r
477\r
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\r
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
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
541\r
542 If there is no additional space for HOB creation, then ASSERT().\r
543 If the FvImage buffer is not at its required alignment, then ASSERT().\r
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
552 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
553 IN UINT64 Length\r
554 )\r
555{\r
556 EFI_HOB_FIRMWARE_VOLUME *Hob;\r
557\r
558 if (!InternalCheckFvAlignment (BaseAddress, Length)) {\r
559 ASSERT (FALSE);\r
560 return;\r
561 }\r
562\r
563 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV, (UINT16)sizeof (EFI_HOB_FIRMWARE_VOLUME));\r
564 if (Hob == NULL) {\r
565 return;\r
566 }\r
567\r
568 Hob->BaseAddress = BaseAddress;\r
569 Hob->Length = Length;\r
570}\r
571\r
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
578\r
579 If there is no additional space for HOB creation, then ASSERT().\r
580 If the FvImage buffer is not at its required alignment, then ASSERT().\r
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
584 @param FvName The name of the Firmware Volume.\r
585 @param FileName The name of the file.\r
586\r
587**/\r
588VOID\r
589EFIAPI\r
590BuildFv2Hob (\r
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
595 )\r
596{\r
597 EFI_HOB_FIRMWARE_VOLUME2 *Hob;\r
598\r
599 if (!InternalCheckFvAlignment (BaseAddress, Length)) {\r
600 ASSERT (FALSE);\r
601 return;\r
602 }\r
603\r
604 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV2, (UINT16)sizeof (EFI_HOB_FIRMWARE_VOLUME2));\r
605 if (Hob == NULL) {\r
606 return;\r
607 }\r
608\r
609 Hob->BaseAddress = BaseAddress;\r
610 Hob->Length = Length;\r
611 CopyGuid (&Hob->FvName, FvName);\r
612 CopyGuid (&Hob->FileName, FileName);\r
613}\r
614\r
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
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
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
654 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV3, (UINT16)sizeof (EFI_HOB_FIRMWARE_VOLUME3));\r
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
669/**\r
670 Builds a Capsule Volume HOB.\r
671\r
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
675\r
676 If the platform does not support Capsule Volume HOBs, then ASSERT().\r
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
681\r
682**/\r
683VOID\r
684EFIAPI\r
685BuildCvHob (\r
686 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
687 IN UINT64 Length\r
688 )\r
689{\r
690 EFI_HOB_UEFI_CAPSULE *Hob;\r
691\r
692 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_UEFI_CAPSULE, (UINT16)sizeof (EFI_HOB_UEFI_CAPSULE));\r
693 if (Hob == NULL) {\r
694 return;\r
695 }\r
696\r
697 Hob->BaseAddress = BaseAddress;\r
698 Hob->Length = Length;\r
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
707\r
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
717 IN UINT8 SizeOfMemorySpace,\r
718 IN UINT8 SizeOfIoSpace\r
719 )\r
720{\r
721 EFI_HOB_CPU *Hob;\r
722\r
723 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CPU, (UINT16)sizeof (EFI_HOB_CPU));\r
724 if (Hob == NULL) {\r
725 return;\r
726 }\r
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
734 ZeroMem (Hob->Reserved, sizeof (Hob->Reserved));\r
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
743\r
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
753 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
754 IN UINT64 Length\r
755 )\r
756{\r
757 EFI_HOB_MEMORY_ALLOCATION_STACK *Hob;\r
758\r
759 ASSERT (\r
760 ((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
761 ((Length & (EFI_PAGE_SIZE - 1)) == 0)\r
762 );\r
763\r
764 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16)sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK));\r
765 if (Hob == NULL) {\r
766 return;\r
767 }\r
768\r
769 CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocStackGuid);\r
770 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
771 Hob->AllocDescriptor.MemoryLength = Length;\r
772 Hob->AllocDescriptor.MemoryType = EfiBootServicesData;\r
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
786\r
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
791 @param MemoryType The type of memory allocated by this HOB.\r
792\r
793**/\r
794VOID\r
795EFIAPI\r
796BuildBspStoreHob (\r
797 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
798 IN UINT64 Length,\r
799 IN EFI_MEMORY_TYPE MemoryType\r
800 )\r
801{\r
802 EFI_HOB_MEMORY_ALLOCATION_BSP_STORE *Hob;\r
803\r
804 ASSERT (\r
805 ((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
806 ((Length & (EFI_PAGE_SIZE - 1)) == 0)\r
807 );\r
808\r
809 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16)sizeof (EFI_HOB_MEMORY_ALLOCATION_BSP_STORE));\r
810 if (Hob == NULL) {\r
811 return;\r
812 }\r
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
831\r
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
836 @param MemoryType The type of memory allocated by this HOB.\r
837\r
838**/\r
839VOID\r
840EFIAPI\r
841BuildMemoryAllocationHob (\r
842 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
843 IN UINT64 Length,\r
844 IN EFI_MEMORY_TYPE MemoryType\r
845 )\r
846{\r
847 EFI_HOB_MEMORY_ALLOCATION *Hob;\r
848\r
849 ASSERT (\r
850 ((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
851 ((Length & (EFI_PAGE_SIZE - 1)) == 0)\r
852 );\r
853\r
854 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16)sizeof (EFI_HOB_MEMORY_ALLOCATION));\r
855 if (Hob == NULL) {\r
856 return;\r
857 }\r
858\r
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