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