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