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