]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/Library/ArmVirtDxeHobLib/HobLib.c
ArmVirtPkg ArmVirtDxeHobLib: Implement BuildFv3Hob
[mirror_edk2.git] / ArmVirtPkg / Library / ArmVirtDxeHobLib / HobLib.c
CommitLineData
ad90df8a
AB
1/** @file\r
2 HOB Library implemenation for Dxe Phase with DebugLib dependency removed\r
3\r
234dbcef 4Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
ad90df8a
AB
5Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#define ASSERT(Expression) \\r
17 do { \\r
18 if (!(Expression)) { \\r
19 CpuDeadLoop (); \\r
20 } \\r
21 } while (FALSE)\r
22\r
23#include <PiDxe.h>\r
24\r
25#include <Guid/HobList.h>\r
26\r
27#include <Library/HobLib.h>\r
28#include <Library/UefiLib.h>\r
29#include <Library/BaseMemoryLib.h>\r
30\r
31VOID *mHobList = NULL;\r
32\r
33/**\r
34 The constructor function caches the pointer to HOB list.\r
35\r
36 The constructor function gets the start address of HOB list from system configuration table.\r
37\r
38 @param ImageHandle The firmware allocated handle for the EFI image.\r
39 @param SystemTable A pointer to the EFI System Table.\r
40\r
41 @retval EFI_SUCCESS The constructor successfully gets HobList.\r
42 @retval Other value The constructor can't get HobList.\r
43\r
44**/\r
45EFI_STATUS\r
46EFIAPI\r
47HobLibConstructor (\r
48 IN EFI_HANDLE ImageHandle,\r
49 IN EFI_SYSTEM_TABLE *SystemTable\r
50 )\r
51{\r
52 UINTN Index;\r
53\r
54 for (Index = 0; Index < SystemTable->NumberOfTableEntries; Index++) {\r
55 if (CompareGuid (&gEfiHobListGuid, &(SystemTable->ConfigurationTable[Index].VendorGuid))) {\r
56 mHobList = SystemTable->ConfigurationTable[Index].VendorTable;\r
57 return EFI_SUCCESS;\r
58 }\r
59 }\r
60\r
61 return EFI_NOT_FOUND;\r
62}\r
63\r
64/**\r
65 Returns the pointer to the HOB list.\r
66\r
67 This function returns the pointer to first HOB in the list.\r
68 For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer\r
69 to the HOB list. For the DXE phase, the HOB list pointer can be retrieved through\r
70 the EFI System Table by looking up theHOB list GUID in the System Configuration Table.\r
71 Since the System Configuration Table does not exist that the time the DXE Core is\r
72 launched, the DXE Core uses a global variable from the DXE Core Entry Point Library\r
73 to manage the pointer to the HOB list.\r
74\r
75 If the pointer to the HOB list is NULL, then ASSERT().\r
76\r
77 @return The pointer to the HOB list.\r
78\r
79**/\r
80VOID *\r
81EFIAPI\r
82GetHobList (\r
83 VOID\r
84 )\r
85{\r
86 ASSERT (mHobList != NULL);\r
87 return mHobList;\r
88}\r
89\r
90/**\r
91 Returns the next instance of a HOB type from the starting HOB.\r
92\r
93 This function searches the first instance of a HOB type from the starting HOB pointer.\r
94 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.\r
95 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r
96 unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r
97 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r
98\r
99 If HobStart is NULL, then ASSERT().\r
100\r
101 @param Type The HOB type to return.\r
102 @param HobStart The starting HOB pointer to search from.\r
103\r
104 @return The next instance of a HOB type from the starting HOB.\r
105\r
106**/\r
107VOID *\r
108EFIAPI\r
109GetNextHob (\r
110 IN UINT16 Type,\r
111 IN CONST VOID *HobStart\r
112 )\r
113{\r
114 EFI_PEI_HOB_POINTERS Hob;\r
115\r
116 ASSERT (HobStart != NULL);\r
117\r
118 Hob.Raw = (UINT8 *) HobStart;\r
119 //\r
120 // Parse the HOB list until end of list or matching type is found.\r
121 //\r
122 while (!END_OF_HOB_LIST (Hob)) {\r
123 if (Hob.Header->HobType == Type) {\r
124 return Hob.Raw;\r
125 }\r
126 Hob.Raw = GET_NEXT_HOB (Hob);\r
127 }\r
128 return NULL;\r
129}\r
130\r
131/**\r
132 Returns the first instance of a HOB type among the whole HOB list.\r
133\r
134 This function searches the first instance of a HOB type among the whole HOB list.\r
135 If there does not exist such HOB type in the HOB list, it will return NULL.\r
136\r
137 If the pointer to the HOB list is NULL, then ASSERT().\r
138\r
139 @param Type The HOB type to return.\r
140\r
141 @return The next instance of a HOB type from the starting HOB.\r
142\r
143**/\r
144VOID *\r
145EFIAPI\r
146GetFirstHob (\r
147 IN UINT16 Type\r
148 )\r
149{\r
150 VOID *HobList;\r
151\r
152 HobList = GetHobList ();\r
153 return GetNextHob (Type, HobList);\r
154}\r
155\r
156/**\r
157 Returns the next instance of the matched GUID HOB from the starting HOB.\r
158\r
159 This function searches the first instance of a HOB from the starting HOB pointer.\r
160 Such HOB should satisfy two conditions:\r
161 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.\r
162 If there does not exist such HOB from the starting HOB pointer, it will return NULL.\r
163 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
164 to extract the data section and its size information, respectively.\r
165 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r
166 unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r
167 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r
168\r
169 If Guid is NULL, then ASSERT().\r
170 If HobStart is NULL, then ASSERT().\r
171\r
172 @param Guid The GUID to match with in the HOB list.\r
173 @param HobStart A pointer to a Guid.\r
174\r
175 @return The next instance of the matched GUID HOB from the starting HOB.\r
176\r
177**/\r
178VOID *\r
179EFIAPI\r
180GetNextGuidHob (\r
181 IN CONST EFI_GUID *Guid,\r
182 IN CONST VOID *HobStart\r
183 )\r
184{\r
185 EFI_PEI_HOB_POINTERS GuidHob;\r
186\r
187 GuidHob.Raw = (UINT8 *) HobStart;\r
188 while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {\r
189 if (CompareGuid (Guid, &GuidHob.Guid->Name)) {\r
190 break;\r
191 }\r
192 GuidHob.Raw = GET_NEXT_HOB (GuidHob);\r
193 }\r
194 return GuidHob.Raw;\r
195}\r
196\r
197/**\r
198 Returns the first instance of the matched GUID HOB among the whole HOB list.\r
199\r
200 This function searches the first instance of a HOB among the whole HOB list.\r
201 Such HOB should satisfy two conditions:\r
202 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.\r
203 If there does not exist such HOB from the starting HOB pointer, it will return NULL.\r
204 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
205 to extract the data section and its size information, respectively.\r
206\r
207 If the pointer to the HOB list is NULL, then ASSERT().\r
208 If Guid is NULL, then ASSERT().\r
209\r
210 @param Guid The GUID to match with in the HOB list.\r
211\r
212 @return The first instance of the matched GUID HOB among the whole HOB list.\r
213\r
214**/\r
215VOID *\r
216EFIAPI\r
217GetFirstGuidHob (\r
218 IN CONST EFI_GUID *Guid\r
219 )\r
220{\r
221 VOID *HobList;\r
222\r
223 HobList = GetHobList ();\r
224 return GetNextGuidHob (Guid, HobList);\r
225}\r
226\r
227/**\r
228 Get the system boot mode from the HOB list.\r
229\r
230 This function returns the system boot mode information from the\r
231 PHIT HOB in HOB list.\r
232\r
233 If the pointer to the HOB list is NULL, then ASSERT().\r
234\r
235 @param VOID\r
236\r
237 @return The Boot Mode.\r
238\r
239**/\r
240EFI_BOOT_MODE\r
241EFIAPI\r
242GetBootModeHob (\r
243 VOID\r
244 )\r
245{\r
246 EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;\r
247\r
248 HandOffHob = (EFI_HOB_HANDOFF_INFO_TABLE *) GetHobList ();\r
249\r
250 return HandOffHob->BootMode;\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 //\r
279 // PEI HOB is read only for DXE phase\r
280 //\r
281 ASSERT (FALSE);\r
282}\r
283\r
284/**\r
285 Builds a HOB that describes a chunk of system memory.\r
286\r
287 This function builds a HOB that describes a chunk of system memory.\r
288 It can only be invoked during PEI phase;\r
289 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
290\r
291 If there is no additional space for HOB creation, then ASSERT().\r
292\r
293 @param ResourceType The type of resource described by this HOB.\r
294 @param ResourceAttribute The resource attributes of the memory described by this HOB.\r
295 @param PhysicalStart The 64 bit physical address of memory described by this HOB.\r
296 @param NumberOfBytes The length of the memory described by this HOB in bytes.\r
297\r
298**/\r
299VOID\r
300EFIAPI\r
301BuildResourceDescriptorHob (\r
302 IN EFI_RESOURCE_TYPE ResourceType,\r
303 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,\r
304 IN EFI_PHYSICAL_ADDRESS PhysicalStart,\r
305 IN UINT64 NumberOfBytes\r
306 )\r
307{\r
308 //\r
309 // PEI HOB is read only for DXE phase\r
310 //\r
311 ASSERT (FALSE);\r
312}\r
313\r
314/**\r
315 Builds a customized HOB tagged with a GUID for identification and returns\r
316 the start address of GUID HOB data.\r
317\r
318 This function builds a customized HOB tagged with a GUID for identification\r
319 and returns the start address of GUID HOB data so that caller can fill the customized data.\r
320 The HOB Header and Name field is already stripped.\r
321 It can only be invoked during PEI phase;\r
322 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
323\r
324 If Guid is NULL, then ASSERT().\r
325 If there is no additional space for HOB creation, then ASSERT().\r
326 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
327 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.\r
328\r
329 @param Guid The GUID to tag the customized HOB.\r
330 @param DataLength The size of the data payload for the GUID HOB.\r
331\r
332 @retval NULL The GUID HOB could not be allocated.\r
333 @retval others The start address of GUID HOB data.\r
334\r
335**/\r
336VOID *\r
337EFIAPI\r
338BuildGuidHob (\r
339 IN CONST EFI_GUID *Guid,\r
340 IN UINTN DataLength\r
341 )\r
342{\r
343 //\r
344 // PEI HOB is read only for DXE phase\r
345 //\r
346 ASSERT (FALSE);\r
347 return NULL;\r
348}\r
349\r
350/**\r
351 Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB\r
352 data field, and returns the start address of the GUID HOB data.\r
353\r
354 This function builds a customized HOB tagged with a GUID for identification and copies the input\r
355 data to the HOB data field and returns the start address of the GUID HOB data. It can only be\r
356 invoked during PEI phase; for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
357 The HOB Header and Name field is already stripped.\r
358 It can only be invoked during PEI phase;\r
359 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
360\r
361 If Guid is NULL, then ASSERT().\r
362 If Data is NULL and DataLength > 0, then ASSERT().\r
363 If there is no additional space for HOB creation, then ASSERT().\r
364 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
365 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.\r
366\r
367 @param Guid The GUID to tag the customized HOB.\r
368 @param Data The data to be copied into the data field of the GUID HOB.\r
369 @param DataLength The size of the data payload for the GUID HOB.\r
370\r
371 @retval NULL The GUID HOB could not be allocated.\r
372 @retval others The start address of GUID HOB data.\r
373\r
374**/\r
375VOID *\r
376EFIAPI\r
377BuildGuidDataHob (\r
378 IN CONST EFI_GUID *Guid,\r
379 IN VOID *Data,\r
380 IN UINTN DataLength\r
381 )\r
382{\r
383 //\r
384 // PEI HOB is read only for DXE phase\r
385 //\r
386 ASSERT (FALSE);\r
387 return NULL;\r
388}\r
389\r
390/**\r
391 Builds a Firmware Volume HOB.\r
392\r
393 This function builds a Firmware Volume HOB.\r
394 It can only be invoked during PEI phase;\r
395 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
396\r
397 If there is no additional space for HOB creation, then ASSERT().\r
a0426207 398 If the FvImage buffer is not at its required alignment, then ASSERT().\r
ad90df8a
AB
399\r
400 @param BaseAddress The base address of the Firmware Volume.\r
401 @param Length The size of the Firmware Volume in bytes.\r
402\r
403**/\r
404VOID\r
405EFIAPI\r
406BuildFvHob (\r
407 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
408 IN UINT64 Length\r
409 )\r
410{\r
411 //\r
412 // PEI HOB is read only for DXE phase\r
413 //\r
414 ASSERT (FALSE);\r
415}\r
416\r
417/**\r
418 Builds a EFI_HOB_TYPE_FV2 HOB.\r
419\r
420 This function builds a EFI_HOB_TYPE_FV2 HOB.\r
421 It can only be invoked during PEI phase;\r
422 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
423\r
424 If there is no additional space for HOB creation, then ASSERT().\r
a0426207 425 If the FvImage buffer is not at its required alignment, then ASSERT().\r
ad90df8a
AB
426\r
427 @param BaseAddress The base address of the Firmware Volume.\r
428 @param Length The size of the Firmware Volume in bytes.\r
429 @param FvName The name of the Firmware Volume.\r
430 @param FileName The name of the file.\r
431\r
432**/\r
433VOID\r
434EFIAPI\r
435BuildFv2Hob (\r
436 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
437 IN UINT64 Length,\r
438 IN CONST EFI_GUID *FvName,\r
439 IN CONST EFI_GUID *FileName\r
440 )\r
441{\r
442 ASSERT (FALSE);\r
443}\r
444\r
234dbcef
SZ
445/**\r
446 Builds a EFI_HOB_TYPE_FV3 HOB.\r
447\r
448 This function builds a EFI_HOB_TYPE_FV3 HOB.\r
449 It can only be invoked during PEI phase;\r
450 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
451\r
452 If there is no additional space for HOB creation, then ASSERT().\r
453 If the FvImage buffer is not at its required alignment, then ASSERT().\r
454\r
455 @param BaseAddress The base address of the Firmware Volume.\r
456 @param Length The size of the Firmware Volume in bytes.\r
457 @param AuthenticationStatus The authentication status.\r
458 @param ExtractedFv TRUE if the FV was extracted as a file within\r
459 another firmware volume. FALSE otherwise.\r
460 @param FvName The name of the Firmware Volume.\r
461 Valid only if IsExtractedFv is TRUE.\r
462 @param FileName The name of the file.\r
463 Valid only if IsExtractedFv is TRUE.\r
464\r
465**/\r
466VOID\r
467EFIAPI\r
468BuildFv3Hob (\r
469 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
470 IN UINT64 Length,\r
471 IN UINT32 AuthenticationStatus,\r
472 IN BOOLEAN ExtractedFv,\r
473 IN CONST EFI_GUID *FvName, OPTIONAL\r
474 IN CONST EFI_GUID *FileName OPTIONAL\r
475 )\r
476{\r
477 ASSERT (FALSE);\r
478}\r
ad90df8a
AB
479\r
480/**\r
481 Builds a Capsule Volume HOB.\r
482\r
483 This function builds a Capsule Volume HOB.\r
484 It can only be invoked during PEI phase;\r
485 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
486\r
487 If the platform does not support Capsule Volume HOBs, then ASSERT().\r
488 If there is no additional space for HOB creation, then ASSERT().\r
489\r
490 @param BaseAddress The base address of the Capsule Volume.\r
491 @param Length The size of the Capsule Volume in bytes.\r
492\r
493**/\r
494VOID\r
495EFIAPI\r
496BuildCvHob (\r
497 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
498 IN UINT64 Length\r
499 )\r
500{\r
501 //\r
502 // PEI HOB is read only for DXE phase\r
503 //\r
504 ASSERT (FALSE);\r
505}\r
506\r
507/**\r
508 Builds a HOB for the CPU.\r
509\r
510 This function builds a HOB for the CPU.\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\r
514 If there is no additional space for HOB creation, then ASSERT().\r
515\r
516 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.\r
517 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.\r
518\r
519**/\r
520VOID\r
521EFIAPI\r
522BuildCpuHob (\r
523 IN UINT8 SizeOfMemorySpace,\r
524 IN UINT8 SizeOfIoSpace\r
525 )\r
526{\r
527 //\r
528 // PEI HOB is read only for DXE phase\r
529 //\r
530 ASSERT (FALSE);\r
531}\r
532\r
533/**\r
534 Builds a HOB for the Stack.\r
535\r
536 This function builds a HOB for the stack.\r
537 It can only be invoked during PEI phase;\r
538 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
539\r
540 If there is no additional space for HOB creation, then ASSERT().\r
541\r
542 @param BaseAddress The 64 bit physical address of the Stack.\r
543 @param Length The length of the stack in bytes.\r
544\r
545**/\r
546VOID\r
547EFIAPI\r
548BuildStackHob (\r
549 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
550 IN UINT64 Length\r
551 )\r
552{\r
553 //\r
554 // PEI HOB is read only for DXE phase\r
555 //\r
556 ASSERT (FALSE);\r
557}\r
558\r
559/**\r
560 Builds a HOB for the BSP store.\r
561\r
562 This function builds a HOB for BSP store.\r
563 It can only be invoked during PEI phase;\r
564 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
565\r
566 If there is no additional space for HOB creation, then ASSERT().\r
567\r
568 @param BaseAddress The 64 bit physical address of the BSP.\r
569 @param Length The length of the BSP store in bytes.\r
570 @param MemoryType Type of memory allocated by this HOB.\r
571\r
572**/\r
573VOID\r
574EFIAPI\r
575BuildBspStoreHob (\r
576 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
577 IN UINT64 Length,\r
578 IN EFI_MEMORY_TYPE MemoryType\r
579 )\r
580{\r
581 //\r
582 // PEI HOB is read only for DXE phase\r
583 //\r
584 ASSERT (FALSE);\r
585}\r
586\r
587/**\r
588 Builds a HOB for the memory allocation.\r
589\r
590 This function builds a HOB for the memory allocation.\r
591 It can only be invoked during PEI phase;\r
592 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
593\r
594 If there is no additional space for HOB creation, then ASSERT().\r
595\r
596 @param BaseAddress The 64 bit physical address of the memory.\r
597 @param Length The length of the memory allocation in bytes.\r
598 @param MemoryType Type of memory allocated by this HOB.\r
599\r
600**/\r
601VOID\r
602EFIAPI\r
603BuildMemoryAllocationHob (\r
604 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
605 IN UINT64 Length,\r
606 IN EFI_MEMORY_TYPE MemoryType\r
607 )\r
608{\r
609 //\r
610 // PEI HOB is read only for DXE phase\r
611 //\r
612 ASSERT (FALSE);\r
613}\r