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