]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Library/HobLib.h
Updated headers to follow coding standard
[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 Capsule Volume HOB.
267
268 This function builds a Capsule Volume 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 Capsule Volume.
274 @param Length The size of the Capsule Volume in bytes.
275
276 **/
277 VOID
278 EFIAPI
279 BuildCvHob (
280 IN EFI_PHYSICAL_ADDRESS BaseAddress,
281 IN UINT64 Length
282 )
283 ;
284
285 /**
286 Builds a HOB for the CPU.
287
288 This function builds a HOB for the CPU.
289 It can only be invoked during PEI phase;
290 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
291 If there is no additional space for HOB creation, then ASSERT().
292
293 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
294 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
295
296 **/
297 VOID
298 EFIAPI
299 BuildCpuHob (
300 IN UINT8 SizeOfMemorySpace,
301 IN UINT8 SizeOfIoSpace
302 )
303 ;
304
305 /**
306 Builds a HOB for the Stack.
307
308 This function builds a HOB for the stack.
309 It can only be invoked during PEI phase;
310 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
311 If there is no additional space for HOB creation, then ASSERT().
312
313 @param BaseAddress The 64 bit physical address of the Stack.
314 @param Length The length of the stack in bytes.
315
316 **/
317 VOID
318 EFIAPI
319 BuildStackHob (
320 IN EFI_PHYSICAL_ADDRESS BaseAddress,
321 IN UINT64 Length
322 )
323 ;
324
325 /**
326 Builds a HOB for the BSP store.
327
328 This function builds a HOB for BSP store.
329 It can only be invoked during PEI phase;
330 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
331 If there is no additional space for HOB creation, then ASSERT().
332
333 @param BaseAddress The 64 bit physical address of the BSP.
334 @param Length The length of the BSP store in bytes.
335 @param MemoryType Type of memory allocated by this HOB.
336
337 **/
338 VOID
339 EFIAPI
340 BuildBspStoreHob (
341 IN EFI_PHYSICAL_ADDRESS BaseAddress,
342 IN UINT64 Length,
343 IN EFI_MEMORY_TYPE MemoryType
344 )
345 ;
346
347 /**
348 Builds a HOB for the memory allocation.
349
350 This function builds a HOB for the memory allocation.
351 It can only be invoked during PEI phase;
352 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
353 If there is no additional space for HOB creation, then ASSERT().
354
355 @param BaseAddress The 64 bit physical address of the memory.
356 @param Length The length of the memory allocation in bytes.
357 @param MemoryType Type of memory allocated by this HOB.
358
359 **/
360 VOID
361 EFIAPI
362 BuildMemoryAllocationHob (
363 IN EFI_PHYSICAL_ADDRESS BaseAddress,
364 IN UINT64 Length,
365 IN EFI_MEMORY_TYPE MemoryType
366 )
367 ;
368
369 #define GET_HOB_TYPE(Hob) ((Hob).Header->HobType)
370 #define GET_HOB_LENGTH(Hob) ((Hob).Header->HobLength)
371 #define GET_NEXT_HOB(Hob) ((Hob).Raw + GET_HOB_LENGTH (Hob))
372 #define END_OF_HOB_LIST(Hob) (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_END_OF_HOB_LIST)
373
374 //
375 // Get the data and data size field of GUID
376 //
377 #define GET_GUID_HOB_DATA(GuidHob) ((VOID *) (((UINT8 *) &((GuidHob)->Name)) + sizeof (EFI_GUID)))
378 #define GET_GUID_HOB_DATA_SIZE(GuidHob) (((GuidHob)->Header).HobLength - sizeof (EFI_HOB_GUID_TYPE))
379
380 #endif