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