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