]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Library/HobLib.h
Merge branch of PI tree to main trunk
[mirror_edk2.git] / MdePkg / Include / Library / HobLib.h
1 /** @file
2 Public include file for the HOB Library
3
4 Copyright (c) 2006 - 2007, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #ifndef __HOB_LIB_H__
16 #define __HOB_LIB_H__
17
18 /**
19 Returns the pointer to the HOB list.
20
21 This function returns the pointer to first HOB in the list.
22
23 @return The pointer to the HOB list.
24
25 **/
26 VOID *
27 EFIAPI
28 GetHobList (
29 VOID
30 )
31 ;
32
33 /**
34 Returns the next instance of a HOB type from the starting HOB.
35
36 This function searches the first instance of a HOB type from the starting HOB pointer.
37 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
38 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
39 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
40 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
41 If HobStart is NULL, then ASSERT().
42
43 @param Type The HOB type to return.
44 @param HobStart The starting HOB pointer to search from.
45
46 @return The next instance of a HOB type from the starting HOB.
47
48 **/
49 VOID *
50 EFIAPI
51 GetNextHob (
52 IN UINT16 Type,
53 IN CONST VOID *HobStart
54 )
55 ;
56
57 /**
58 Returns the first instance of a HOB type among the whole HOB list.
59
60 This function searches the first instance of a HOB type among the whole HOB list.
61 If there does not exist such HOB type in the HOB list, it will return NULL.
62
63 @param Type The HOB type to return.
64
65 @return The next instance of a HOB type from the starting HOB.
66
67 **/
68 VOID *
69 EFIAPI
70 GetFirstHob (
71 IN UINT16 Type
72 )
73 ;
74
75 /**
76 This function searches the first instance of a HOB from the starting HOB pointer.
77 Such HOB should satisfy two conditions:
78 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
79 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
80 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
81 to extract the data section and its size info respectively.
82 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
83 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
84 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
85 If Guid is NULL, then ASSERT().
86 If HobStart is NULL, then ASSERT().
87
88 @param Guid The GUID to match with in the HOB list.
89 @param HobStart A pointer to a Guid.
90
91 @return The next instance of the matched GUID HOB from the starting HOB.
92
93 **/
94 VOID *
95 EFIAPI
96 GetNextGuidHob (
97 IN CONST EFI_GUID *Guid,
98 IN CONST VOID *HobStart
99 )
100 ;
101
102 /**
103 This function searches the first instance of a HOB among the whole HOB list.
104 Such HOB should satisfy two conditions:
105 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
106 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
107 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
108 to extract the data section and its size info respectively.
109 If Guid is NULL, then ASSERT().
110
111 @param Guid The GUID to match with in the HOB list.
112
113 @return The first instance of the matched GUID HOB among the whole HOB list.
114
115 **/
116 VOID *
117 EFIAPI
118 GetFirstGuidHob (
119 IN CONST EFI_GUID *Guid
120 )
121 ;
122
123 /**
124 Get the Boot Mode from the HOB list.
125
126 This function returns the system boot mode information from the
127 PHIT HOB in HOB list.
128
129 @param VOID
130
131 @return The Boot Mode.
132
133 **/
134 EFI_BOOT_MODE
135 EFIAPI
136 GetBootModeHob (
137 VOID
138 )
139 ;
140
141 /**
142 Builds a HOB for a loaded PE32 module.
143
144 This function builds a HOB for a loaded PE32 module.
145 It can only be invoked during PEI phase;
146 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
147 If ModuleName is NULL, then ASSERT().
148 If there is no additional space for HOB creation, then ASSERT().
149
150 @param ModuleName The GUID File Name of the module.
151 @param MemoryAllocationModule The 64 bit physical address of the module.
152 @param ModuleLength The length of the module in bytes.
153 @param EntryPoint The 64 bit physical address of the module entry point.
154
155 **/
156 VOID
157 EFIAPI
158 BuildModuleHob (
159 IN CONST EFI_GUID *ModuleName,
160 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,
161 IN UINT64 ModuleLength,
162 IN EFI_PHYSICAL_ADDRESS EntryPoint
163 )
164 ;
165
166 /**
167 Builds a HOB that describes a chunk of system memory.
168
169 This function builds a HOB that describes a chunk of system memory.
170 It can only be invoked during PEI phase;
171 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
172 If there is no additional space for HOB creation, then ASSERT().
173
174 @param ResourceType The type of resource described by this HOB.
175 @param ResourceAttribute The resource attributes of the memory described by this HOB.
176 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
177 @param NumberOfBytes The length of the memory described by this HOB in bytes.
178
179 **/
180 VOID
181 EFIAPI
182 BuildResourceDescriptorHob (
183 IN EFI_RESOURCE_TYPE ResourceType,
184 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,
185 IN EFI_PHYSICAL_ADDRESS PhysicalStart,
186 IN UINT64 NumberOfBytes
187 )
188 ;
189
190 /**
191 Builds a GUID HOB with a certain data length.
192
193 This function builds a customized HOB tagged with a GUID for identification
194 and returns the start address of GUID HOB data so that caller can fill the customized data.
195 The HOB Header and Name field is already stripped.
196 It can only be invoked during PEI phase;
197 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
198 If Guid is NULL, then ASSERT().
199 If there is no additional space for HOB creation, then ASSERT().
200 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
201
202 @param Guid The GUID to tag the customized HOB.
203 @param DataLength The size of the data payload for the GUID HOB.
204
205 @return The start address of GUID HOB data.
206
207 **/
208 VOID *
209 EFIAPI
210 BuildGuidHob (
211 IN CONST EFI_GUID *Guid,
212 IN UINTN DataLength
213 )
214 ;
215
216 /**
217 Copies a data buffer to a newly-built HOB.
218
219 This function builds a customized HOB tagged with a GUID for identification,
220 copies the input data to the HOB data field and returns the start address of the GUID HOB data.
221 The HOB Header and Name field is already stripped.
222 It can only be invoked during PEI phase;
223 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
224 If Guid is NULL, then ASSERT().
225 If Data is NULL and DataLength > 0, then ASSERT().
226 If there is no additional space for HOB creation, then ASSERT().
227 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
228
229 @param Guid The GUID to tag the customized HOB.
230 @param Data The data to be copied into the data field of the GUID HOB.
231 @param DataLength The size of the data payload for the GUID HOB.
232
233 @return The start address of GUID HOB data.
234
235 **/
236 VOID *
237 EFIAPI
238 BuildGuidDataHob (
239 IN CONST EFI_GUID *Guid,
240 IN VOID *Data,
241 IN UINTN DataLength
242 )
243 ;
244
245 /**
246 Builds a Firmware Volume HOB.
247
248 This function builds a Firmware Volume HOB.
249 It can only be invoked during PEI phase;
250 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
251 If there is no additional space for HOB creation, then ASSERT().
252
253 @param BaseAddress The base address of the Firmware Volume.
254 @param Length The size of the Firmware Volume in bytes.
255
256 **/
257 VOID
258 EFIAPI
259 BuildFvHob (
260 IN EFI_PHYSICAL_ADDRESS BaseAddress,
261 IN UINT64 Length
262 )
263 ;
264
265 /**
266 Builds a EFI_HOB_TYPE_FV2 HOB.
267
268 This function builds a EFI_HOB_TYPE_FV2 HOB.
269 It can only be invoked during PEI phase;
270 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
271 If there is no additional space for HOB creation, then ASSERT().
272
273 @param BaseAddress The base address of the Firmware Volume.
274 @param Length The size of the Firmware Volume in bytes.
275 @param FvName The name of the Firmware Volume.
276 @param FileName The name of the file.
277
278 **/
279 VOID
280 EFIAPI
281 BuildFv2Hob (
282 IN EFI_PHYSICAL_ADDRESS BaseAddress,
283 IN UINT64 Length,
284 IN CONST EFI_GUID *FvName,
285 IN CONST EFI_GUID *FileName
286 )
287 ;
288
289 /**
290 Builds a Capsule Volume HOB.
291
292 This function builds a Capsule Volume HOB.
293 It can only be invoked during PEI phase;
294 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
295 If there is no additional space for HOB creation, then ASSERT().
296
297 @param BaseAddress The base address of the Capsule Volume.
298 @param Length The size of the Capsule Volume in bytes.
299
300 **/
301 VOID
302 EFIAPI
303 BuildCvHob (
304 IN EFI_PHYSICAL_ADDRESS BaseAddress,
305 IN UINT64 Length
306 )
307 ;
308
309 /**
310 Builds a HOB for the CPU.
311
312 This function builds a HOB for the CPU.
313 It can only be invoked during PEI phase;
314 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
315 If there is no additional space for HOB creation, then ASSERT().
316
317 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
318 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
319
320 **/
321 VOID
322 EFIAPI
323 BuildCpuHob (
324 IN UINT8 SizeOfMemorySpace,
325 IN UINT8 SizeOfIoSpace
326 )
327 ;
328
329 /**
330 Builds a HOB for the Stack.
331
332 This function builds a HOB for the stack.
333 It can only be invoked during PEI phase;
334 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
335 If there is no additional space for HOB creation, then ASSERT().
336
337 @param BaseAddress The 64 bit physical address of the Stack.
338 @param Length The length of the stack in bytes.
339
340 **/
341 VOID
342 EFIAPI
343 BuildStackHob (
344 IN EFI_PHYSICAL_ADDRESS BaseAddress,
345 IN UINT64 Length
346 )
347 ;
348
349 /**
350 Builds a HOB for the BSP store.
351
352 This function builds a HOB for BSP store.
353 It can only be invoked during PEI phase;
354 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
355 If there is no additional space for HOB creation, then ASSERT().
356
357 @param BaseAddress The 64 bit physical address of the BSP.
358 @param Length The length of the BSP store in bytes.
359 @param MemoryType Type of memory allocated by this HOB.
360
361 **/
362 VOID
363 EFIAPI
364 BuildBspStoreHob (
365 IN EFI_PHYSICAL_ADDRESS BaseAddress,
366 IN UINT64 Length,
367 IN EFI_MEMORY_TYPE MemoryType
368 )
369 ;
370
371 /**
372 Builds a HOB for the memory allocation.
373
374 This function builds a HOB for the memory allocation.
375 It can only be invoked during PEI phase;
376 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
377 If there is no additional space for HOB creation, then ASSERT().
378
379 @param BaseAddress The 64 bit physical address of the memory.
380 @param Length The length of the memory allocation in bytes.
381 @param MemoryType Type of memory allocated by this HOB.
382
383 **/
384 VOID
385 EFIAPI
386 BuildMemoryAllocationHob (
387 IN EFI_PHYSICAL_ADDRESS BaseAddress,
388 IN UINT64 Length,
389 IN EFI_MEMORY_TYPE MemoryType
390 )
391 ;
392
393 #define GET_HOB_TYPE(Hob) ((Hob).Header->HobType)
394 #define GET_HOB_LENGTH(Hob) ((Hob).Header->HobLength)
395 #define GET_NEXT_HOB(Hob) ((Hob).Raw + GET_HOB_LENGTH (Hob))
396 #define END_OF_HOB_LIST(Hob) (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_END_OF_HOB_LIST)
397
398 //
399 // Get the data and data size field of GUID
400 //
401 #define GET_GUID_HOB_DATA(GuidHob) ((VOID *) (((UINT8 *) &((GuidHob)->Name)) + sizeof (EFI_GUID)))
402 #define GET_GUID_HOB_DATA_SIZE(GuidHob) (((GuidHob)->Header).HobLength - sizeof (EFI_HOB_GUID_TYPE))
403
404 #endif