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