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