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