VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.c@ 105681

最後變更 在這個檔案從105681是 105670,由 vboxsync 提交於 8 月 前

Devices/EFI/FirmwareNew: Merge edk2-stable-202405 and make it build on aarch64, bugref:4643

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette