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