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