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