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