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