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