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