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