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