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