]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Library/DxeCoreHobLib/HobLib.c
MdePkg: fix mixed dos and linux EOL format issue
[mirror_edk2.git] / MdePkg / Library / DxeCoreHobLib / HobLib.c
... / ...
CommitLineData
1/** @file\r
2 HOB Library implementation for DxeCore driver.\r
3\r
4Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
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
8http://opensource.org/licenses/bsd-license.php.\r
9\r
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
12\r
13**/\r
14\r
15#include <PiDxe.h>\r
16\r
17#include <Library/HobLib.h>\r
18#include <Library/DebugLib.h>\r
19#include <Library/BaseMemoryLib.h>\r
20#include <Library/DxeCoreEntryPoint.h>\r
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
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
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
44 ASSERT (gHobList != NULL);\r
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
51 This function searches the first instance of a HOB type from the starting HOB pointer. \r
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
56 \r
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
75\r
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
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
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
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
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
121 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
122 to extract the data section and its size information, respectively.\r
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
126 \r
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
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
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
161 If such a HOB from the starting HOB pointer does not exist, it will return NULL.\r
162 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
163 to extract the data section and its size information, respectively.\r
164 \r
165 If the pointer to the HOB list is NULL, then ASSERT().\r
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
186 Get the system boot mode from the HOB list.\r
187\r
188 This function returns the system boot mode information from the \r
189 PHIT HOB in HOB list.\r
190\r
191 If the pointer to the HOB list is NULL, then ASSERT().\r
192 \r
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
210\r
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
216 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.\r
217 \r
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
224 @param EntryPoint The 64 bit physical address of the module entry point.\r
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 with Owner GUID.\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
247 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
248 \r
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 @param OwnerGUID GUID for the owner of this resource.\r
256\r
257**/\r
258VOID\r
259EFIAPI\r
260BuildResourceDescriptorWithOwnerHob (\r
261 IN EFI_RESOURCE_TYPE ResourceType,\r
262 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,\r
263 IN EFI_PHYSICAL_ADDRESS PhysicalStart,\r
264 IN UINT64 NumberOfBytes,\r
265 IN EFI_GUID *OwnerGUID\r
266 )\r
267{\r
268 //\r
269 // PEI HOB is read only for DXE phase\r
270 //\r
271 ASSERT (FALSE);\r
272}\r
273\r
274/**\r
275 Builds a HOB that describes a chunk of system memory.\r
276\r
277 This function builds a HOB that describes a chunk of system memory.\r
278 It can only be invoked during PEI phase;\r
279 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.\r
280 \r
281 If there is no additional space for HOB creation, then ASSERT().\r
282\r
283 @param ResourceType The type of resource described by this HOB.\r
284 @param ResourceAttribute The resource attributes of the memory described by this HOB.\r
285 @param PhysicalStart The 64 bit physical address of memory described by this HOB.\r
286 @param NumberOfBytes The length of the memory described by this HOB in bytes.\r
287\r
288**/\r
289VOID\r
290EFIAPI\r
291BuildResourceDescriptorHob (\r
292 IN EFI_RESOURCE_TYPE ResourceType,\r
293 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,\r
294 IN EFI_PHYSICAL_ADDRESS PhysicalStart,\r
295 IN UINT64 NumberOfBytes\r
296 )\r
297{\r
298 //\r
299 // PEI HOB is read only for DXE phase\r
300 //\r
301 ASSERT (FALSE);\r
302}\r
303\r
304/**\r
305 Builds a customized HOB tagged with a GUID for identification and returns \r
306 the start address of GUID HOB data.\r
307\r
308 This function builds a customized HOB tagged with a GUID for identification \r
309 and returns the start address of GUID HOB data so that caller can fill the customized data. \r
310 The HOB Header and Name field is already stripped.\r
311 It can only be invoked during PEI phase.\r
312 For DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.\r
313 \r
314 If Guid is NULL, then ASSERT().\r
315 If there is no additional space for HOB creation, then ASSERT().\r
316 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
317 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.\r
318\r
319 @param Guid The GUID to tag the customized HOB.\r
320 @param DataLength The size of the data payload for the GUID HOB.\r
321\r
322 @retval NULL The GUID HOB could not be allocated.\r
323 @retval others The start address of GUID HOB data.\r
324\r
325**/\r
326VOID *\r
327EFIAPI\r
328BuildGuidHob (\r
329 IN CONST EFI_GUID *Guid,\r
330 IN UINTN DataLength\r
331 )\r
332{\r
333 //\r
334 // PEI HOB is read only for DXE phase\r
335 //\r
336 ASSERT (FALSE);\r
337 return NULL;\r
338}\r
339\r
340/**\r
341 Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB \r
342 data field, and returns the start address of the GUID HOB data.\r
343\r
344 This function builds a customized HOB tagged with a GUID for identification and copies the input\r
345 data to the HOB data field and returns the start address of the GUID HOB data. It can only be \r
346 invoked during PEI phase; for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase. \r
347 The HOB Header and Name field is already stripped.\r
348 It can only be invoked during PEI phase.\r
349 For DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.\r
350 \r
351 If Guid is NULL, then ASSERT().\r
352 If Data is NULL and DataLength > 0, then ASSERT().\r
353 If there is no additional space for HOB creation, then ASSERT().\r
354 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
355 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.\r
356\r
357 @param Guid The GUID to tag the customized HOB.\r
358 @param Data The data to be copied into the data field of the GUID HOB.\r
359 @param DataLength The size of the data payload for the GUID HOB.\r
360\r
361 @retval NULL The GUID HOB could not be allocated.\r
362 @retval others The start address of GUID HOB data.\r
363\r
364**/\r
365VOID *\r
366EFIAPI\r
367BuildGuidDataHob (\r
368 IN CONST EFI_GUID *Guid,\r
369 IN VOID *Data,\r
370 IN UINTN DataLength\r
371 )\r
372{\r
373 //\r
374 // PEI HOB is read only for DXE phase\r
375 //\r
376 ASSERT (FALSE);\r
377 return NULL;\r
378}\r
379\r
380/**\r
381 Builds a Firmware Volume HOB.\r
382\r
383 This function builds a Firmware Volume HOB.\r
384 It can only be invoked during PEI phase;\r
385 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.\r
386 \r
387 If there is no additional space for HOB creation, then ASSERT().\r
388\r
389 @param BaseAddress The base address of the Firmware Volume.\r
390 @param Length The size of the Firmware Volume in bytes.\r
391\r
392**/\r
393VOID\r
394EFIAPI\r
395BuildFvHob (\r
396 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
397 IN UINT64 Length\r
398 )\r
399{\r
400 //\r
401 // PEI HOB is read only for DXE phase\r
402 //\r
403 ASSERT (FALSE);\r
404}\r
405\r
406/**\r
407 Builds a EFI_HOB_TYPE_FV2 HOB.\r
408\r
409 This function builds a EFI_HOB_TYPE_FV2 HOB.\r
410 It can only be invoked during PEI phase;\r
411 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.\r
412 \r
413 If there is no additional space for HOB creation, then ASSERT().\r
414\r
415 @param BaseAddress The base address of the Firmware Volume.\r
416 @param Length The size of the Firmware Volume in bytes.\r
417 @param FvName The name of the Firmware Volume.\r
418 @param FileName The name of the file.\r
419 \r
420**/\r
421VOID\r
422EFIAPI\r
423BuildFv2Hob (\r
424 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
425 IN UINT64 Length,\r
426 IN CONST EFI_GUID *FvName,\r
427 IN CONST EFI_GUID *FileName\r
428 )\r
429{\r
430 ASSERT (FALSE);\r
431}\r
432\r
433/**\r
434 Builds a Capsule Volume HOB.\r
435\r
436 This function builds a Capsule Volume HOB.\r
437 It can only be invoked during PEI phase;\r
438 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.\r
439 \r
440 If the platform does not support Capsule Volume HOBs, then ASSERT().\r
441 If there is no additional space for HOB creation, then ASSERT().\r
442\r
443 @param BaseAddress The base address of the Capsule Volume.\r
444 @param Length The size of the Capsule Volume in bytes.\r
445\r
446**/\r
447VOID\r
448EFIAPI\r
449BuildCvHob (\r
450 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
451 IN UINT64 Length\r
452 )\r
453{\r
454 //\r
455 // PEI HOB is read only for DXE phase\r
456 //\r
457 ASSERT (FALSE);\r
458}\r
459\r
460/**\r
461 Builds a HOB for the CPU.\r
462\r
463 This function builds a HOB for the CPU.\r
464 It can only be invoked during PEI phase;\r
465 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.\r
466 \r
467 If there is no additional space for HOB creation, then ASSERT().\r
468\r
469 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.\r
470 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.\r
471\r
472**/\r
473VOID\r
474EFIAPI\r
475BuildCpuHob (\r
476 IN UINT8 SizeOfMemorySpace,\r
477 IN UINT8 SizeOfIoSpace\r
478 )\r
479{\r
480 //\r
481 // PEI HOB is read only for DXE phase\r
482 //\r
483 ASSERT (FALSE);\r
484}\r
485\r
486/**\r
487 Builds a HOB for the Stack.\r
488\r
489 This function builds a HOB for the stack.\r
490 It can only be invoked during PEI phase;\r
491 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.\r
492 \r
493 If there is no additional space for HOB creation, then ASSERT().\r
494\r
495 @param BaseAddress The 64 bit physical address of the Stack.\r
496 @param Length The length of the stack in bytes.\r
497\r
498**/\r
499VOID\r
500EFIAPI\r
501BuildStackHob (\r
502 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
503 IN UINT64 Length\r
504 )\r
505{\r
506 //\r
507 // PEI HOB is read only for DXE phase\r
508 //\r
509 ASSERT (FALSE);\r
510}\r
511\r
512/**\r
513 Builds a HOB for the BSP store.\r
514\r
515 This function builds a HOB for BSP store.\r
516 It can only be invoked during PEI phase;\r
517 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.\r
518 \r
519 If there is no additional space for HOB creation, then ASSERT().\r
520\r
521 @param BaseAddress The 64 bit physical address of the BSP.\r
522 @param Length The length of the BSP store in bytes.\r
523 @param MemoryType Type of memory allocated by this HOB.\r
524\r
525**/\r
526VOID\r
527EFIAPI\r
528BuildBspStoreHob (\r
529 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
530 IN UINT64 Length,\r
531 IN EFI_MEMORY_TYPE MemoryType\r
532 )\r
533{\r
534 //\r
535 // PEI HOB is read only for DXE phase\r
536 //\r
537 ASSERT (FALSE);\r
538}\r
539\r
540/**\r
541 Builds a HOB for the memory allocation.\r
542\r
543 This function builds a HOB for the memory allocation.\r
544 It can only be invoked during PEI phase;\r
545 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.\r
546 \r
547 If there is no additional space for HOB creation, then ASSERT().\r
548\r
549 @param BaseAddress The 64 bit physical address of the memory.\r
550 @param Length The length of the memory allocation in bytes.\r
551 @param MemoryType Type of memory allocated by this HOB.\r
552\r
553**/\r
554VOID\r
555EFIAPI\r
556BuildMemoryAllocationHob (\r
557 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
558 IN UINT64 Length,\r
559 IN EFI_MEMORY_TYPE MemoryType\r
560 )\r
561{\r
562 //\r
563 // PEI HOB is read only for DXE phase\r
564 //\r
565 ASSERT (FALSE);\r
566}\r