]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/DxeHobLib/HobLib.c
Maintainers.txt: Remove EdkCompatibilityPkg information
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EdkIIGlueLib / Library / DxeHobLib / HobLib.c
CommitLineData
3eb9473e 1/*++\r
2\r
f99d3d23 3Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
2c7e5c2f 4This program and the accompanying materials \r
3eb9473e 5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12\r
13Module Name:\r
14\r
15 HobLib.c\r
16 \r
17Abstract: \r
18\r
19 HOB Library.\r
20\r
21--*/\r
22\r
23#include "EdkIIGlueDxe.h"\r
24\r
25\r
26STATIC VOID *mHobList = NULL;\r
27\r
28/**\r
29 The constructor function caches the pointer to HOB list.\r
30 \r
31 The constructor function gets the start address of HOB list from system configuration table.\r
32 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. \r
33\r
34 @param ImageHandle The firmware allocated handle for the EFI image.\r
35 @param SystemTable A pointer to the EFI System Table.\r
36 \r
37 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
38\r
39**/\r
40EFI_STATUS\r
41EFIAPI\r
42HobLibConstructor (\r
43 IN EFI_HANDLE ImageHandle,\r
44 IN EFI_SYSTEM_TABLE *SystemTable\r
45 )\r
46{\r
47 EFI_STATUS Status;\r
48\r
49 Status = EfiGetSystemConfigurationTable (&gEfiHobListGuid, &mHobList);\r
50 ASSERT_EFI_ERROR (Status);\r
51 ASSERT (mHobList != NULL);\r
52 return Status;\r
53}\r
54\r
55/**\r
56 Returns the pointer to the HOB list.\r
57\r
58 This function returns the pointer to first HOB in the list.\r
59\r
60 @return The pointer to the HOB list.\r
61\r
62**/\r
63VOID *\r
64EFIAPI\r
65GetHobList (\r
66 VOID\r
67 )\r
68{\r
69 return mHobList;\r
70}\r
71\r
72/**\r
73 Returns the next instance of a HOB type from the starting HOB.\r
74\r
75 This function searches the first instance of a HOB type from the starting HOB pointer. \r
76 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.\r
77 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r
78 unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r
79 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r
80 If HobStart is NULL, then ASSERT().\r
81\r
82 @param Type The HOB type to return.\r
83 @param HobStart The starting HOB pointer to search from.\r
84\r
85 @return The next instance of a HOB type from the starting HOB.\r
86\r
87**/\r
88VOID *\r
89EFIAPI\r
90GetNextHob (\r
91 IN UINT16 Type,\r
92 IN CONST VOID *HobStart\r
93 )\r
94{\r
95 EFI_PEI_HOB_POINTERS Hob;\r
96\r
97 ASSERT (HobStart != NULL);\r
98 \r
99 Hob.Raw = (UINT8 *) HobStart;\r
100 //\r
101 // Parse the HOB list until end of list or matching type is found.\r
102 //\r
103 while (!END_OF_HOB_LIST (Hob)) {\r
104 if (Hob.Header->HobType == Type) {\r
105 return Hob.Raw;\r
106 }\r
107 Hob.Raw = GET_NEXT_HOB (Hob);\r
108 }\r
109 return NULL;\r
110}\r
111\r
112/**\r
113 Returns the first instance of a HOB type among the whole HOB list.\r
114\r
115 This function searches the first instance of a HOB type among the whole HOB list. \r
116 If there does not exist such HOB type in the HOB list, it will return NULL. \r
117\r
118 @param Type The HOB type to return.\r
119\r
120 @return The next instance of a HOB type from the starting HOB.\r
121\r
122**/\r
123VOID *\r
124EFIAPI\r
125GetFirstHob (\r
126 IN UINT16 Type\r
127 )\r
128{\r
129 VOID *HobList;\r
130\r
131 HobList = GetHobList ();\r
132 return GetNextHob (Type, HobList);\r
133}\r
134\r
135/**\r
136 This function searches the first instance of a HOB from the starting HOB pointer. \r
137 Such HOB should satisfy two conditions: \r
138 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid. \r
139 If there does not exist such HOB from the starting HOB pointer, it will return NULL. \r
140 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
141 to extract the data section and its size info respectively.\r
142 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r
143 unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r
144 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r
145 If Guid is NULL, then ASSERT().\r
146 If HobStart is NULL, then ASSERT().\r
147\r
148 @param Guid The GUID to match with in the HOB list.\r
149 @param HobStart A pointer to a Guid.\r
150\r
151 @return The next instance of the matched GUID HOB from the starting HOB.\r
152\r
153**/\r
154VOID *\r
155EFIAPI\r
156GlueGetNextGuidHob (\r
157 IN CONST EFI_GUID *Guid,\r
158 IN CONST VOID *HobStart\r
159 )\r
160{\r
161 EFI_PEI_HOB_POINTERS GuidHob;\r
162\r
163 GuidHob.Raw = (UINT8 *) HobStart;\r
164 while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {\r
165 if (CompareGuid (Guid, &GuidHob.Guid->Name)) {\r
166 break;\r
167 }\r
168 GuidHob.Raw = GET_NEXT_HOB (GuidHob);\r
169 }\r
170 return GuidHob.Raw;\r
171}\r
172\r
173/**\r
174 This function searches the first instance of a HOB among the whole HOB list. \r
175 Such HOB should satisfy two conditions:\r
176 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.\r
177 If there does not exist such HOB from the starting HOB pointer, it will return NULL.\r
178 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
179 to extract the data section and its size info respectively.\r
180 If Guid is NULL, then ASSERT().\r
181\r
182 @param Guid The GUID to match with in the HOB list.\r
183\r
184 @return The first instance of the matched GUID HOB among the whole HOB list.\r
185\r
186**/\r
187VOID *\r
188EFIAPI\r
189GlueGetFirstGuidHob (\r
190 IN CONST EFI_GUID *Guid\r
191 )\r
192{\r
193 VOID *HobList;\r
194\r
195 HobList = GetHobList ();\r
196 return GetNextGuidHob (Guid, HobList);\r
197}\r
198\r
199/**\r
200 Get the Boot Mode from the HOB list.\r
201\r
202 This function returns the system boot mode information from the \r
203 PHIT HOB in HOB list.\r
204\r
205 @param VOID\r
206\r
207 @return The Boot Mode.\r
208\r
209**/\r
210EFI_BOOT_MODE\r
211EFIAPI\r
212GetBootModeHob (\r
213 VOID\r
214 )\r
215{\r
216 EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;\r
217\r
218 HandOffHob = (EFI_HOB_HANDOFF_INFO_TABLE *) GetHobList ();\r
219\r
220 return HandOffHob->BootMode;\r
221}\r
222\r
223/**\r
224 Builds a HOB for a loaded PE32 module.\r
225\r
226 This function builds a HOB for a loaded PE32 module.\r
227 It can only be invoked during PEI phase;\r
228 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
229 If ModuleName is NULL, then ASSERT().\r
230 If there is no additional space for HOB creation, then ASSERT().\r
231\r
232 @param ModuleName The GUID File Name of the module.\r
233 @param MemoryAllocationModule The 64 bit physical address of the module.\r
234 @param ModuleLength The length of the module in bytes.\r
235 @param EntryPoint The 64 bit physical address of the module's entry point.\r
236\r
237**/\r
238VOID\r
239EFIAPI\r
240GlueBuildModuleHob (\r
241 IN CONST EFI_GUID *ModuleName,\r
242 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,\r
243 IN UINT64 ModuleLength,\r
244 IN EFI_PHYSICAL_ADDRESS EntryPoint\r
245 )\r
246{\r
247 //\r
248 // PEI HOB is read only for DXE phase\r
249 //\r
250 ASSERT (FALSE);\r
251}\r
252\r
253/**\r
254 Builds a HOB that describes a chunk of system memory.\r
255\r
256 This function builds a HOB that describes a chunk of system memory.\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 If there is no additional space for HOB creation, then ASSERT().\r
260\r
261 @param ResourceType The type of resource described by this HOB.\r
262 @param ResourceAttribute The resource attributes of the memory described by this HOB.\r
263 @param PhysicalStart The 64 bit physical address of memory described by this HOB.\r
264 @param NumberOfBytes The length of the memory described by this HOB in bytes.\r
265\r
266**/\r
267VOID\r
268EFIAPI\r
269BuildResourceDescriptorHob (\r
270 IN EFI_RESOURCE_TYPE ResourceType,\r
271 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,\r
272 IN EFI_PHYSICAL_ADDRESS PhysicalStart,\r
273 IN UINT64 NumberOfBytes\r
274 )\r
275{\r
276 //\r
277 // PEI HOB is read only for DXE phase\r
278 //\r
279 ASSERT (FALSE);\r
280}\r
281\r
282/**\r
283 Builds a GUID HOB with a certain data length.\r
284\r
285 This function builds a customized HOB tagged with a GUID for identification \r
286 and returns the start address of GUID HOB data so that caller can fill the customized data. \r
287 The HOB Header and Name field is already stripped.\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 If Guid is NULL, then ASSERT().\r
291 If there is no additional space for HOB creation, then ASSERT().\r
292 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
293\r
294 @param Guid The GUID to tag the customized HOB.\r
295 @param DataLength The size of the data payload for the GUID HOB.\r
296\r
f99d3d23
RN
297 @retval NULL The GUID HOB could not be allocated.\r
298 @retval others The start address of GUID HOB data.\r
3eb9473e 299\r
300**/\r
301VOID *\r
302EFIAPI\r
303BuildGuidHob (\r
304 IN CONST EFI_GUID *Guid,\r
305 IN UINTN DataLength\r
306 )\r
307{\r
308 //\r
309 // PEI HOB is read only for DXE phase\r
310 //\r
311 ASSERT (FALSE);\r
312 return NULL;\r
313}\r
314\r
315/**\r
316 Copies a data buffer to a newly-built HOB.\r
317\r
318 This function builds a customized HOB tagged with a GUID for identification,\r
319 copies the input data to the HOB data field and returns the start address of the GUID HOB 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 If Guid is NULL, then ASSERT().\r
324 If Data is NULL and DataLength > 0, then ASSERT().\r
325 If there is no additional space for HOB creation, then ASSERT().\r
326 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
327\r
328 @param Guid The GUID to tag the customized HOB.\r
329 @param Data The data to be copied into the data field of the GUID HOB.\r
330 @param DataLength The size of the data payload for the GUID HOB.\r
331\r
f99d3d23
RN
332 @retval NULL The GUID HOB could not be allocated.\r
333 @retval others The start address of GUID HOB data.\r
3eb9473e 334\r
335**/\r
336VOID *\r
337EFIAPI\r
338BuildGuidDataHob (\r
339 IN CONST EFI_GUID *Guid,\r
340 IN VOID *Data,\r
341 IN UINTN DataLength\r
342 )\r
343{\r
344 //\r
345 // PEI HOB is read only for DXE phase\r
346 //\r
347 ASSERT (FALSE);\r
348 return NULL;\r
349}\r
350\r
351/**\r
352 Builds a Firmware Volume HOB.\r
353\r
354 This function builds a Firmware Volume HOB.\r
355 It can only be invoked during PEI phase;\r
356 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
357 If there is no additional space for HOB creation, then ASSERT().\r
358\r
359 @param BaseAddress The base address of the Firmware Volume.\r
360 @param Length The size of the Firmware Volume in bytes.\r
361\r
362**/\r
363VOID\r
364EFIAPI\r
365BuildFvHob (\r
366 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
367 IN UINT64 Length\r
368 )\r
369{\r
370 //\r
371 // PEI HOB is read only for DXE phase\r
372 //\r
373 ASSERT (FALSE);\r
374}\r
375\r
376/**\r
377 Builds a Capsule Volume HOB.\r
378\r
379 This function builds a Capsule Volume HOB.\r
380 It can only be invoked during PEI phase;\r
381 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
382 If there is no additional space for HOB creation, then ASSERT().\r
383\r
384 @param BaseAddress The base address of the Capsule Volume.\r
385 @param Length The size of the Capsule Volume in bytes.\r
386\r
387**/\r
388VOID\r
389EFIAPI\r
390BuildCvHob (\r
391 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
392 IN UINT64 Length\r
393 )\r
394{\r
395 //\r
396 // PEI HOB is read only for DXE phase\r
397 //\r
398 ASSERT (FALSE);\r
399}\r
400\r
401/**\r
402 Builds a HOB for the CPU.\r
403\r
404 This function builds a HOB for the CPU.\r
405 It can only be invoked during PEI phase;\r
406 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
407 If there is no additional space for HOB creation, then ASSERT().\r
408\r
409 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.\r
410 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.\r
411\r
412**/\r
413VOID\r
414EFIAPI\r
415BuildCpuHob (\r
416 IN UINT8 SizeOfMemorySpace,\r
417 IN UINT8 SizeOfIoSpace\r
418 )\r
419{\r
420 //\r
421 // PEI HOB is read only for DXE phase\r
422 //\r
423 ASSERT (FALSE);\r
424}\r
425\r
426/**\r
427 Builds a HOB for the Stack.\r
428\r
429 This function builds a HOB for the stack.\r
430 It can only be invoked during PEI phase;\r
431 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
432 If there is no additional space for HOB creation, then ASSERT().\r
433\r
434 @param BaseAddress The 64 bit physical address of the Stack.\r
435 @param Length The length of the stack in bytes.\r
436\r
437**/\r
438VOID\r
439EFIAPI\r
440BuildStackHob (\r
441 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
442 IN UINT64 Length\r
443 )\r
444{\r
445 //\r
446 // PEI HOB is read only for DXE phase\r
447 //\r
448 ASSERT (FALSE);\r
449}\r
450\r
451/**\r
452 Builds a HOB for the BSP store.\r
453\r
454 This function builds a HOB for BSP store.\r
455 It can only be invoked during PEI phase;\r
456 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
457 If there is no additional space for HOB creation, then ASSERT().\r
458\r
459 @param BaseAddress The 64 bit physical address of the BSP.\r
460 @param Length The length of the BSP store in bytes.\r
461 @param MemoryType Type of memory allocated by this HOB.\r
462\r
463**/\r
464VOID\r
465EFIAPI\r
466BuildBspStoreHob (\r
467 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
468 IN UINT64 Length,\r
469 IN EFI_MEMORY_TYPE MemoryType\r
470 )\r
471{\r
472 //\r
473 // PEI HOB is read only for DXE phase\r
474 //\r
475 ASSERT (FALSE);\r
476}\r
477\r
478/**\r
479 Builds a HOB for the memory allocation.\r
480\r
481 This function builds a HOB for the memory allocation.\r
482 It can only be invoked during PEI phase;\r
483 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
484 If there is no additional space for HOB creation, then ASSERT().\r
485\r
486 @param BaseAddress The 64 bit physical address of the memory.\r
487 @param Length The length of the memory allocation in bytes.\r
488 @param MemoryType Type of memory allocated by this HOB.\r
489\r
490**/\r
491VOID\r
492EFIAPI\r
493GlueBuildMemoryAllocationHob (\r
494 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
495 IN UINT64 Length,\r
496 IN EFI_MEMORY_TYPE MemoryType\r
497 )\r
498{\r
499 //\r
500 // PEI HOB is read only for DXE phase\r
501 //\r
502 ASSERT (FALSE);\r
503}\r