]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Library/HobLib.h
Clean not in pub spec comments status codes returned for functions of EFI_TCG_PROTOCOL
[mirror_edk2.git] / MdePkg / Include / Library / HobLib.h
CommitLineData
fb3df220 1/** @file\r
50a64e5b 2 Provides services to create and parse HOBs. Only available for PEI\r
3 and DXE module types.\r
fb3df220 4\r
f9eb929d 5 The HOB Library supports the efficient creation and searching of HOBs\r
fbb393ab
LL
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
f9eb929d 9 independent and can be relocated easily to different memory memory locations.\r
10\r
192764db 11Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
9df063a0 12This program and the accompanying materials\r
50a64e5b 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
fb3df220 16\r
50a64e5b 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
fb3df220 19\r
fb3df220 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
fbb393ab 29 For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer\r
f9eb929d 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
fbb393ab
LL
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
f9eb929d 34 to manage the pointer to the HOB list.\r
fbb393ab 35\r
f9eb929d 36 If the pointer to the HOB list is NULL, then ASSERT().\r
fbb393ab 37\r
fb3df220 38 @return The pointer to the HOB list.\r
39\r
40**/\r
41VOID *\r
42EFIAPI\r
43GetHobList (\r
44 VOID\r
ed66e1bc 45 );\r
fb3df220 46\r
47/**\r
48 Returns the next instance of a HOB type from the starting HOB.\r
49\r
fbb393ab 50 This function searches the first instance of a HOB type from the starting HOB pointer.\r
fb3df220 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
fbb393ab 55\r
fb3df220 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
ed66e1bc 69 );\r
fb3df220 70\r
71/**\r
72 Returns the first instance of a HOB type among the whole HOB list.\r
73\r
fbb393ab
LL
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
f9eb929d 77 If the pointer to the HOB list is NULL, then ASSERT().\r
fb3df220 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
ed66e1bc 88 );\r
fb3df220 89\r
90/**\r
f9eb929d 91 Returns the next instance of the matched GUID HOB from the starting HOB.\r
fbb393ab
LL
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
fb3df220 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
fbb393ab 102\r
fb3df220 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
ed66e1bc 117 );\r
fb3df220 118\r
119/**\r
f9eb929d 120 Returns the first instance of the matched GUID HOB among the whole HOB list.\r
fbb393ab
LL
121\r
122 This function searches the first instance of a HOB among the whole HOB list.\r
fb3df220 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
fbb393ab 128\r
f9eb929d 129 If the pointer to the HOB list is NULL, then ASSERT().\r
fb3df220 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
ed66e1bc 141 );\r
fb3df220 142\r
143/**\r
f9eb929d 144 Get the system boot mode from the HOB list.\r
fb3df220 145\r
fbb393ab 146 This function returns the system boot mode information from the\r
fb3df220 147 PHIT HOB in HOB list.\r
148\r
f9eb929d 149 If the pointer to the HOB list is NULL, then ASSERT().\r
fbb393ab 150\r
fb3df220 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
ed66e1bc 160 );\r
fb3df220 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
fbb393ab 168\r
fb3df220 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
ed66e1bc 185 );\r
fb3df220 186\r
187/**\r
188 Builds a HOB that describes a chunk of system memory.\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
fbb393ab 193\r
fb3df220 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\r
201**/\r
202VOID\r
203EFIAPI\r
204BuildResourceDescriptorHob (\r
205 IN EFI_RESOURCE_TYPE ResourceType,\r
206 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,\r
207 IN EFI_PHYSICAL_ADDRESS PhysicalStart,\r
208 IN UINT64 NumberOfBytes\r
ed66e1bc 209 );\r
fb3df220 210\r
211/**\r
fbb393ab 212 Builds a customized HOB tagged with a GUID for identification and returns\r
f9eb929d 213 the start address of GUID HOB data.\r
fb3df220 214\r
fbb393ab
LL
215 This function builds a customized HOB tagged with a GUID for identification\r
216 and returns the start address of GUID HOB data so that caller can fill the customized data.\r
fb3df220 217 The HOB Header and Name field is already stripped.\r
218 It can only be invoked during PEI phase;\r
219 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
fbb393ab 220\r
fb3df220 221 If Guid is NULL, then ASSERT().\r
222 If there is no additional space for HOB creation, then ASSERT().\r
192764db
LG
223 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
224 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.\r
fb3df220 225\r
226 @param Guid The GUID to tag the customized HOB.\r
227 @param DataLength The size of the data payload for the GUID HOB.\r
228\r
ef2635c3
RN
229 @retval NULL The GUID HOB could not be allocated.\r
230 @retval others The start address of GUID HOB data.\r
fb3df220 231\r
232**/\r
233VOID *\r
234EFIAPI\r
235BuildGuidHob (\r
236 IN CONST EFI_GUID *Guid,\r
237 IN UINTN DataLength\r
ed66e1bc 238 );\r
fb3df220 239\r
240/**\r
fbb393ab 241 Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB\r
f9eb929d 242 data field, and returns the start address of the GUID HOB data.\r
fb3df220 243\r
f9eb929d 244 This function builds a customized HOB tagged with a GUID for identification and copies the input\r
fbb393ab
LL
245 data to the HOB data field and returns the start address of the GUID HOB data. It can only be\r
246 invoked during PEI phase; for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
fb3df220 247 The HOB Header and Name field is already stripped.\r
248 It can only be invoked during PEI phase;\r
249 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
fbb393ab 250\r
fb3df220 251 If Guid is NULL, then ASSERT().\r
252 If Data is NULL and DataLength > 0, then ASSERT().\r
253 If there is no additional space for HOB creation, then ASSERT().\r
192764db
LG
254 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
255 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.\r
fb3df220 256\r
257 @param Guid The GUID to tag the customized HOB.\r
258 @param Data The data to be copied into the data field of the GUID HOB.\r
259 @param DataLength The size of the data payload for the GUID HOB.\r
260\r
ef2635c3
RN
261 @retval NULL The GUID HOB could not be allocated.\r
262 @retval others The start address of GUID HOB data.\r
fb3df220 263\r
264**/\r
265VOID *\r
266EFIAPI\r
267BuildGuidDataHob (\r
268 IN CONST EFI_GUID *Guid,\r
269 IN VOID *Data,\r
270 IN UINTN DataLength\r
ed66e1bc 271 );\r
fb3df220 272\r
273/**\r
274 Builds a Firmware Volume HOB.\r
275\r
276 This function builds a Firmware Volume HOB.\r
277 It can only be invoked during PEI phase;\r
278 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
fbb393ab 279\r
fb3df220 280 If there is no additional space for HOB creation, then ASSERT().\r
281\r
282 @param BaseAddress The base address of the Firmware Volume.\r
283 @param Length The size of the Firmware Volume in bytes.\r
284\r
285**/\r
286VOID\r
287EFIAPI\r
288BuildFvHob (\r
289 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
290 IN UINT64 Length\r
ed66e1bc 291 );\r
fb3df220 292\r
b0d803fe 293/**\r
294 Builds a EFI_HOB_TYPE_FV2 HOB.\r
295\r
296 This function builds a EFI_HOB_TYPE_FV2 HOB.\r
297 It can only be invoked during PEI phase;\r
298 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
fbb393ab 299\r
b0d803fe 300 If there is no additional space for HOB creation, then ASSERT().\r
301\r
302 @param BaseAddress The base address of the Firmware Volume.\r
303 @param Length The size of the Firmware Volume in bytes.\r
f9eb929d 304 @param FvName The name of the Firmware Volume.\r
b0d803fe 305 @param FileName The name of the file.\r
fbb393ab 306\r
b0d803fe 307**/\r
308VOID\r
309EFIAPI\r
310BuildFv2Hob (\r
311 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
312 IN UINT64 Length,\r
313 IN CONST EFI_GUID *FvName,\r
314 IN CONST EFI_GUID *FileName\r
ed66e1bc 315 );\r
b0d803fe 316\r
fb3df220 317/**\r
318 Builds a Capsule Volume HOB.\r
319\r
320 This function builds a Capsule Volume HOB.\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
fbb393ab 323\r
c85cea80 324 If the platform does not support Capsule Volume HOBs, then ASSERT().\r
fb3df220 325 If there is no additional space for HOB creation, then ASSERT().\r
326\r
327 @param BaseAddress The base address of the Capsule Volume.\r
328 @param Length The size of the Capsule Volume in bytes.\r
329\r
330**/\r
331VOID\r
332EFIAPI\r
333BuildCvHob (\r
334 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
335 IN UINT64 Length\r
ed66e1bc 336 );\r
fb3df220 337\r
338/**\r
339 Builds a HOB for the CPU.\r
340\r
341 This function builds a HOB for the CPU.\r
342 It can only be invoked during PEI phase;\r
343 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
fbb393ab 344\r
fb3df220 345 If there is no additional space for HOB creation, then ASSERT().\r
346\r
347 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.\r
348 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.\r
349\r
350**/\r
351VOID\r
352EFIAPI\r
353BuildCpuHob (\r
354 IN UINT8 SizeOfMemorySpace,\r
355 IN UINT8 SizeOfIoSpace\r
ed66e1bc 356 );\r
fb3df220 357\r
358/**\r
359 Builds a HOB for the Stack.\r
360\r
361 This function builds a HOB for the stack.\r
362 It can only be invoked during PEI phase;\r
363 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
fbb393ab 364\r
fb3df220 365 If there is no additional space for HOB creation, then ASSERT().\r
366\r
367 @param BaseAddress The 64 bit physical address of the Stack.\r
368 @param Length The length of the stack in bytes.\r
369\r
370**/\r
371VOID\r
372EFIAPI\r
373BuildStackHob (\r
374 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
375 IN UINT64 Length\r
ed66e1bc 376 );\r
fb3df220 377\r
378/**\r
379 Builds a HOB for the BSP store.\r
380\r
381 This function builds a HOB for BSP store.\r
382 It can only be invoked during PEI phase;\r
383 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
fbb393ab 384\r
fb3df220 385 If there is no additional space for HOB creation, then ASSERT().\r
386\r
387 @param BaseAddress The 64 bit physical address of the BSP.\r
388 @param Length The length of the BSP store in bytes.\r
389 @param MemoryType Type of memory allocated by this HOB.\r
390\r
391**/\r
392VOID\r
393EFIAPI\r
394BuildBspStoreHob (\r
395 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
396 IN UINT64 Length,\r
397 IN EFI_MEMORY_TYPE MemoryType\r
ed66e1bc 398 );\r
fb3df220 399\r
400/**\r
401 Builds a HOB for the memory allocation.\r
402\r
403 This function builds a HOB for the memory allocation.\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
fbb393ab 406\r
fb3df220 407 If there is no additional space for HOB creation, then ASSERT().\r
408\r
409 @param BaseAddress The 64 bit physical address of the memory.\r
410 @param Length The length of the memory allocation in bytes.\r
411 @param MemoryType Type of memory allocated by this HOB.\r
412\r
413**/\r
414VOID\r
415EFIAPI\r
416BuildMemoryAllocationHob (\r
417 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
418 IN UINT64 Length,\r
419 IN EFI_MEMORY_TYPE MemoryType\r
ed66e1bc 420 );\r
fb3df220 421\r
f9eb929d 422/**\r
423 Returns the type of a HOB.\r
424\r
fbb393ab 425 This macro returns the HobType field from the HOB header for the\r
f754f721 426 HOB specified by HobStart.\r
f9eb929d 427\r
f754f721 428 @param HobStart A pointer to a HOB.\r
fbb393ab 429\r
2281e7a9 430 @return HobType.\r
fbb393ab 431\r
f9eb929d 432**/\r
cc4aa464 433#define GET_HOB_TYPE(HobStart) \\r
434 ((*(EFI_HOB_GENERIC_HEADER **)&(HobStart))->HobType)\r
55f298c3 435\r
f9eb929d 436/**\r
437 Returns the length, in bytes, of a HOB.\r
438\r
fbb393ab 439 This macro returns the HobLength field from the HOB header for the\r
f754f721 440 HOB specified by HobStart.\r
f9eb929d 441\r
f754f721 442 @param HobStart A pointer to a HOB.\r
f9eb929d 443\r
2281e7a9 444 @return HobLength.\r
f9eb929d 445\r
446**/\r
cc4aa464 447#define GET_HOB_LENGTH(HobStart) \\r
448 ((*(EFI_HOB_GENERIC_HEADER **)&(HobStart))->HobLength)\r
55f298c3 449\r
f9eb929d 450/**\r
451 Returns a pointer to the next HOB in the HOB list.\r
452\r
fbb393ab 453 This macro returns a pointer to HOB that follows the\r
f754f721 454 HOB specified by HobStart in the HOB List.\r
f9eb929d 455\r
f754f721 456 @param HobStart A pointer to a HOB.\r
f9eb929d 457\r
458 @return A pointer to the next HOB in the HOB list.\r
459\r
460**/\r
cc4aa464 461#define GET_NEXT_HOB(HobStart) \\r
462 (VOID *)(*(UINT8 **)&(HobStart) + GET_HOB_LENGTH (HobStart))\r
55f298c3 463\r
f9eb929d 464/**\r
465 Determines if a HOB is the last HOB in the HOB list.\r
fbb393ab
LL
466\r
467 This macro determine if the HOB specified by HobStart is the\r
468 last HOB in the HOB list. If HobStart is last HOB in the HOB list,\r
f9eb929d 469 then TRUE is returned. Otherwise, FALSE is returned.\r
470\r
f754f721 471 @param HobStart A pointer to a HOB.\r
f9eb929d 472\r
f754f721 473 @retval TRUE The HOB specified by HobStart is the last HOB in the HOB list.\r
474 @retval FALSE The HOB specified by HobStart is not the last HOB in the HOB list.\r
f9eb929d 475\r
476**/\r
f754f721 477#define END_OF_HOB_LIST(HobStart) (GET_HOB_TYPE (HobStart) == (UINT16)EFI_HOB_TYPE_END_OF_HOB_LIST)\r
146332ae 478\r
f9eb929d 479/**\r
480 Returns a pointer to data buffer from a HOB of type EFI_HOB_TYPE_GUID_EXTENSION.\r
481\r
f754f721 482 This macro returns a pointer to the data buffer in a HOB specified by HobStart.\r
fbb393ab 483 HobStart is assumed to be a HOB of type EFI_HOB_TYPE_GUID_EXTENSION.\r
f9eb929d 484\r
7ca066f9 485 @param GuidHob A pointer to a HOB.\r
f9eb929d 486\r
2281e7a9 487 @return A pointer to the data buffer in a HOB.\r
fbb393ab 488\r
f9eb929d 489**/\r
cc4aa464 490#define GET_GUID_HOB_DATA(HobStart) \\r
491 (VOID *)(*(UINT8 **)&(HobStart) + sizeof (EFI_HOB_GUID_TYPE))\r
55f298c3 492\r
f9eb929d 493/**\r
494 Returns the size of the data buffer from a HOB of type EFI_HOB_TYPE_GUID_EXTENSION.\r
495\r
f754f721 496 This macro returns the size, in bytes, of the data buffer in a HOB specified by HobStart.\r
497 HobStart is assumed to be a HOB of type EFI_HOB_TYPE_GUID_EXTENSION.\r
f9eb929d 498\r
7ca066f9 499 @param GuidHob A pointer to a HOB.\r
f9eb929d 500\r
2281e7a9 501 @return The size of the data buffer.\r
f9eb929d 502**/\r
cc4aa464 503#define GET_GUID_HOB_DATA_SIZE(HobStart) \\r
504 (UINT16)(GET_HOB_LENGTH (HobStart) - sizeof (EFI_HOB_GUID_TYPE))\r
146332ae 505\r
fb3df220 506#endif\r