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