1) Added BIT0, BIT1, …, BIT63 to the Base Defines
[mirror_edk2.git] / MdePkg / Library / DxeCoreHobLib / HobLib.c
CommitLineData
878ddf1f 1/** @file\r
2 HOB Library.\r
3\r
d958721a 4 Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
878ddf1f 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
13 Module Name: HobLib.c\r
14\r
15**/\r
16\r
58251024 17#include "HobLib.h"\r
5f10fa01 18\r
878ddf1f 19/**\r
20 Returns the pointer to the HOB list.\r
21\r
5f10fa01 22 This function returns the pointer to first HOB in the list.\r
23\r
878ddf1f 24 @return The pointer to the HOB list.\r
25\r
26**/\r
27VOID *\r
28EFIAPI\r
29GetHobList (\r
30 VOID\r
31 )\r
32{\r
33 return gHobList;\r
34}\r
35\r
36/**\r
5f10fa01 37 Returns the next instance of a HOB type from the starting HOB.\r
38\r
878ddf1f 39 This function searches the first instance of a HOB type from the starting HOB pointer. \r
5f10fa01 40 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.\r
41 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r
42 unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r
43 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r
44 If HobStart is NULL, then ASSERT().\r
878ddf1f 45\r
5f10fa01 46 @param Type The HOB type to return.\r
47 @param HobStart The starting HOB pointer to search from.\r
878ddf1f 48\r
49 @return The next instance of a HOB type from the starting HOB.\r
50\r
51**/\r
52VOID *\r
53EFIAPI\r
54GetNextHob (\r
55 IN UINT16 Type,\r
56 IN CONST VOID *HobStart\r
57 )\r
58{\r
59 EFI_PEI_HOB_POINTERS Hob;\r
60\r
61 ASSERT (HobStart != NULL);\r
62 \r
63 Hob.Raw = (UINT8 *) HobStart;\r
64 //\r
5f10fa01 65 // Parse the HOB list until end of list or matching type is found.\r
878ddf1f 66 //\r
67 while (!END_OF_HOB_LIST (Hob)) {\r
68 if (Hob.Header->HobType == Type) {\r
69 return Hob.Raw;\r
70 }\r
71 Hob.Raw = GET_NEXT_HOB (Hob);\r
72 }\r
73 return NULL;\r
74}\r
75\r
76/**\r
5f10fa01 77 Returns the first instance of a HOB type among the whole HOB list.\r
78\r
878ddf1f 79 This function searches the first instance of a HOB type among the whole HOB list. \r
80 If there does not exist such HOB type in the HOB list, it will return NULL. \r
81\r
5f10fa01 82 @param Type The HOB type to return.\r
878ddf1f 83\r
84 @return The next instance of a HOB type from the starting HOB.\r
85\r
86**/\r
87VOID *\r
88EFIAPI\r
89GetFirstHob (\r
90 IN UINT16 Type\r
91 )\r
92{\r
93 VOID *HobList;\r
94\r
95 HobList = GetHobList ();\r
96 return GetNextHob (Type, HobList);\r
97}\r
98\r
99/**\r
100 This function searches the first instance of a HOB from the starting HOB pointer. \r
101 Such HOB should satisfy two conditions: \r
102 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid. \r
103 If there does not exist such HOB from the starting HOB pointer, it will return NULL. \r
5f10fa01 104 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
105 to extract the data section and its size info respectively.\r
106 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r
107 unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r
108 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r
109 If Guid is NULL, then ASSERT().\r
110 If HobStart is NULL, then ASSERT().\r
878ddf1f 111\r
5f10fa01 112 @param Guid The GUID to match with in the HOB list.\r
113 @param HobStart A pointer to a Guid.\r
878ddf1f 114\r
115 @return The next instance of the matched GUID HOB from the starting HOB.\r
116\r
117**/\r
118VOID *\r
119EFIAPI\r
120GetNextGuidHob (\r
121 IN CONST EFI_GUID *Guid,\r
122 IN CONST VOID *HobStart\r
123 )\r
124{\r
125 EFI_PEI_HOB_POINTERS GuidHob;\r
126\r
127 GuidHob.Raw = (UINT8 *) HobStart;\r
128 while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {\r
129 if (CompareGuid (Guid, &GuidHob.Guid->Name)) {\r
130 break;\r
131 }\r
132 GuidHob.Raw = GET_NEXT_HOB (GuidHob);\r
133 }\r
134 return GuidHob.Raw;\r
135}\r
136\r
137/**\r
138 This function searches the first instance of a HOB among the whole HOB list. \r
139 Such HOB should satisfy two conditions:\r
140 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.\r
141 If there does not exist such HOB from the starting HOB pointer, it will return NULL.\r
5f10fa01 142 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
143 to extract the data section and its size info respectively.\r
144 If Guid is NULL, then ASSERT().\r
878ddf1f 145\r
5f10fa01 146 @param Guid The GUID to match with in the HOB list.\r
878ddf1f 147\r
148 @return The first instance of the matched GUID HOB among the whole HOB list.\r
149\r
150**/\r
151VOID *\r
152EFIAPI\r
153GetFirstGuidHob (\r
154 IN CONST EFI_GUID *Guid\r
155 )\r
156{\r
157 VOID *HobList;\r
158\r
159 HobList = GetHobList ();\r
160 return GetNextGuidHob (Guid, HobList);\r
161}\r
162\r
d958721a 163/**\r
164 Get the Boot Mode from the HOB list.\r
165\r
166 This function returns the system boot mode information from the \r
167 PHIT HOB in HOB list.\r
168\r
169 @param VOID\r
170\r
171 @return The Boot Mode.\r
172\r
173**/\r
174EFI_BOOT_MODE\r
175EFIAPI\r
176GetBootModeHob (\r
177 VOID\r
178 )\r
179{\r
180 EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;\r
181\r
182 HandOffHob = (EFI_HOB_HANDOFF_INFO_TABLE *) GetHobList ();\r
183\r
184 return HandOffHob->BootMode;\r
185}\r
878ddf1f 186/**\r
5f10fa01 187 Builds a HOB for a loaded PE32 module.\r
188\r
878ddf1f 189 This function builds a HOB for a loaded PE32 module.\r
5f10fa01 190 It can only be invoked during PEI phase;\r
191 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
192 If ModuleName is NULL, then ASSERT().\r
193 If there is no additional space for HOB creation, then ASSERT().\r
878ddf1f 194\r
5f10fa01 195 @param ModuleName The GUID File Name of the module.\r
196 @param MemoryAllocationModule The 64 bit physical address of the module.\r
197 @param ModuleLength The length of the module in bytes.\r
511710d6 198 @param EntryPoint The 64 bit physical address of the module's entry point.\r
878ddf1f 199\r
200**/\r
201VOID\r
202EFIAPI\r
203BuildModuleHob (\r
204 IN CONST EFI_GUID *ModuleName,\r
205 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,\r
206 IN UINT64 ModuleLength,\r
207 IN EFI_PHYSICAL_ADDRESS EntryPoint\r
208 )\r
209{\r
210 //\r
211 // PEI HOB is read only for DXE phase\r
212 //\r
213 ASSERT (FALSE);\r
214}\r
215\r
216/**\r
217 Builds a HOB that describes a chunk of system memory.\r
218\r
5f10fa01 219 This function builds a HOB that describes a chunk of system memory.\r
220 It can only be invoked during PEI phase;\r
221 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
222 If there is no additional space for HOB creation, then ASSERT().\r
223\r
224 @param ResourceType The type of resource described by this HOB.\r
225 @param ResourceAttribute The resource attributes of the memory described by this HOB.\r
226 @param PhysicalStart The 64 bit physical address of memory described by this HOB.\r
227 @param NumberOfBytes The length of the memory described by this HOB in bytes.\r
878ddf1f 228\r
229**/\r
230VOID\r
231EFIAPI\r
232BuildResourceDescriptorHob (\r
233 IN EFI_RESOURCE_TYPE ResourceType,\r
234 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,\r
235 IN EFI_PHYSICAL_ADDRESS PhysicalStart,\r
236 IN UINT64 NumberOfBytes\r
237 )\r
238{\r
239 //\r
240 // PEI HOB is read only for DXE phase\r
241 //\r
242 ASSERT (FALSE);\r
243}\r
244\r
245/**\r
5f10fa01 246 Builds a GUID HOB with a certain data length.\r
247\r
878ddf1f 248 This function builds a customized HOB tagged with a GUID for identification \r
249 and returns the start address of GUID HOB data so that caller can fill the customized data. \r
5f10fa01 250 The HOB Header and Name field is already stripped.\r
251 It can only be invoked during PEI phase;\r
252 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
253 If Guid is NULL, then ASSERT().\r
254 If there is no additional space for HOB creation, then ASSERT().\r
533f039e 255 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
878ddf1f 256\r
5f10fa01 257 @param Guid The GUID to tag the customized HOB.\r
258 @param DataLength The size of the data payload for the GUID HOB.\r
878ddf1f 259\r
260 @return The start address of GUID HOB data.\r
261\r
262**/\r
263VOID *\r
264EFIAPI\r
265BuildGuidHob (\r
266 IN CONST EFI_GUID *Guid,\r
267 IN UINTN DataLength\r
268 )\r
269{\r
270 //\r
271 // PEI HOB is read only for DXE phase\r
272 //\r
273 ASSERT (FALSE);\r
274 return NULL;\r
275}\r
276\r
277/**\r
5f10fa01 278 Copies a data buffer to a newly-built HOB.\r
279\r
280 This function builds a customized HOB tagged with a GUID for identification,\r
281 copies the input data to the HOB data field and returns the start address of the GUID HOB data.\r
282 The HOB Header and Name field is already stripped.\r
283 It can only be invoked during PEI phase;\r
284 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
285 If Guid is NULL, then ASSERT().\r
286 If Data is NULL and DataLength > 0, then ASSERT().\r
287 If there is no additional space for HOB creation, then ASSERT().\r
533f039e 288 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
5f10fa01 289\r
290 @param Guid The GUID to tag the customized HOB.\r
291 @param Data The data to be copied into the data field of the GUID HOB.\r
292 @param DataLength The size of the data payload for the GUID HOB.\r
878ddf1f 293\r
294 @return The start address of GUID HOB data.\r
295\r
296**/\r
297VOID *\r
298EFIAPI\r
299BuildGuidDataHob (\r
300 IN CONST EFI_GUID *Guid,\r
301 IN VOID *Data,\r
302 IN UINTN DataLength\r
303 )\r
304{\r
305 //\r
306 // PEI HOB is read only for DXE phase\r
307 //\r
308 ASSERT (FALSE);\r
309 return NULL;\r
310}\r
311\r
312/**\r
313 Builds a Firmware Volume HOB.\r
314\r
5f10fa01 315 This function builds a Firmware Volume HOB.\r
316 It can only be invoked during PEI phase;\r
317 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
318 If there is no additional space for HOB creation, then ASSERT().\r
319\r
320 @param BaseAddress The base address of the Firmware Volume.\r
321 @param Length The size of the Firmware Volume in bytes.\r
878ddf1f 322\r
323**/\r
324VOID\r
325EFIAPI\r
326BuildFvHob (\r
327 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
328 IN UINT64 Length\r
329 )\r
330{\r
331 //\r
332 // PEI HOB is read only for DXE phase\r
333 //\r
334 ASSERT (FALSE);\r
335}\r
336\r
337/**\r
338 Builds a Capsule Volume HOB.\r
339\r
5f10fa01 340 This function builds a Capsule Volume HOB.\r
341 It can only be invoked during PEI phase;\r
342 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
343 If there is no additional space for HOB creation, then ASSERT().\r
344\r
345 @param BaseAddress The base address of the Capsule Volume.\r
346 @param Length The size of the Capsule Volume in bytes.\r
878ddf1f 347\r
348**/\r
349VOID\r
350EFIAPI\r
351BuildCvHob (\r
352 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
353 IN UINT64 Length\r
354 )\r
355{\r
356 //\r
357 // PEI HOB is read only for DXE phase\r
358 //\r
359 ASSERT (FALSE);\r
360}\r
361\r
362/**\r
363 Builds a HOB for the CPU.\r
364\r
5f10fa01 365 This function builds a HOB for the CPU.\r
366 It can only be invoked during PEI phase;\r
367 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
368 If there is no additional space for HOB creation, then ASSERT().\r
369\r
370 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.\r
371 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.\r
878ddf1f 372\r
373**/\r
374VOID\r
375EFIAPI\r
376BuildCpuHob (\r
377 IN UINT8 SizeOfMemorySpace,\r
378 IN UINT8 SizeOfIoSpace\r
379 )\r
380{\r
381 //\r
382 // PEI HOB is read only for DXE phase\r
383 //\r
384 ASSERT (FALSE);\r
385}\r
386\r
387/**\r
388 Builds a HOB for the Stack.\r
389\r
5f10fa01 390 This function builds a HOB for the stack.\r
391 It can only be invoked during PEI phase;\r
392 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
393 If there is no additional space for HOB creation, then ASSERT().\r
394\r
395 @param BaseAddress The 64 bit physical address of the Stack.\r
396 @param Length The length of the stack in bytes.\r
878ddf1f 397\r
398**/\r
399VOID\r
400EFIAPI\r
401BuildStackHob (\r
402 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
403 IN UINT64 Length\r
404 )\r
405{\r
406 //\r
407 // PEI HOB is read only for DXE phase\r
408 //\r
409 ASSERT (FALSE);\r
410}\r
411\r
412/**\r
413 Builds a HOB for the BSP store.\r
414\r
5f10fa01 415 This function builds a HOB for BSP store.\r
416 It can only be invoked during PEI phase;\r
417 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
418 If there is no additional space for HOB creation, then ASSERT().\r
419\r
420 @param BaseAddress The 64 bit physical address of the BSP.\r
421 @param Length The length of the BSP store in bytes.\r
422 @param MemoryType Type of memory allocated by this HOB.\r
878ddf1f 423\r
424**/\r
425VOID\r
426EFIAPI\r
427BuildBspStoreHob (\r
428 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
429 IN UINT64 Length,\r
430 IN EFI_MEMORY_TYPE MemoryType\r
431 )\r
432{\r
433 //\r
434 // PEI HOB is read only for DXE phase\r
435 //\r
436 ASSERT (FALSE);\r
437}\r
438\r
439/**\r
440 Builds a HOB for the memory allocation.\r
441\r
5f10fa01 442 This function builds a HOB for the memory allocation.\r
443 It can only be invoked during PEI phase;\r
444 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
445 If there is no additional space for HOB creation, then ASSERT().\r
446\r
447 @param BaseAddress The 64 bit physical address of the memory.\r
448 @param Length The length of the memory allocation in bytes.\r
449 @param MemoryType Type of memory allocated by this HOB.\r
878ddf1f 450\r
451**/\r
452VOID\r
453EFIAPI\r
454BuildMemoryAllocationHob (\r
455 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
456 IN UINT64 Length,\r
457 IN EFI_MEMORY_TYPE MemoryType\r
458 )\r
459{\r
460 //\r
461 // PEI HOB is read only for DXE phase\r
462 //\r
463 ASSERT (FALSE);\r
464}\r