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