]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Library/DxeHobLib/HobLib.c
Update HobLib and Hob Service to avoid data over flow.
[mirror_edk2.git] / MdePkg / Library / DxeHobLib / HobLib.c
... / ...
CommitLineData
1/** @file\r
2 HOB Library implemenation for Dxe Phase.\r
3\r
4Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
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
9\r
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
12\r
13**/\r
14\r
15#include <PiDxe.h>\r
16\r
17#include <Guid/HobList.h>\r
18\r
19#include <Library/HobLib.h>\r
20#include <Library/UefiLib.h>\r
21#include <Library/DebugLib.h>\r
22#include <Library/BaseMemoryLib.h>\r
23\r
24VOID *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 successfully gets HobList.\r
36 @retval Other value The constructor can't get HobList.\r
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
48 Status = EfiGetSystemConfigurationTable (&gEfiHobListGuid, &mHobList);\r
49 ASSERT_EFI_ERROR (Status);\r
50 ASSERT (mHobList != NULL);\r
51\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 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
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 ASSERT (mHobList != NULL);\r
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
89 \r
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
127 \r
128 If the pointer to the HOB list is NULL, then ASSERT().\r
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
148 Returns the next instance of the matched GUID HOB from the starting HOB.\r
149 \r
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 information, 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
159 \r
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
189 Returns the first instance of the matched GUID HOB among the whole HOB list.\r
190 \r
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 information, respectively.\r
197 \r
198 If the pointer to the HOB list is NULL, then ASSERT().\r
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
219 Get the system boot mode from the HOB list.\r
220\r
221 This function returns the system boot mode information from the \r
222 PHIT HOB in HOB list.\r
223\r
224 If the pointer to the HOB list is NULL, then ASSERT().\r
225 \r
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
250 \r
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
257 @param EntryPoint The 64 bit physical address of the module entry point.\r
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
281 \r
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
306 Builds a customized HOB tagged with a GUID for identification and returns \r
307 the start address of GUID HOB data.\r
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
314 \r
315 If Guid is NULL, then ASSERT().\r
316 If there is no additional space for HOB creation, then ASSERT().\r
317 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
318 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.\r
319\r
320 @param Guid The GUID to tag the customized HOB.\r
321 @param DataLength The size of the data payload for the GUID HOB.\r
322\r
323 @retval NULL The GUID HOB could not be allocated.\r
324 @retval others The start address of GUID HOB data.\r
325\r
326**/\r
327VOID *\r
328EFIAPI\r
329BuildGuidHob (\r
330 IN CONST EFI_GUID *Guid,\r
331 IN UINTN DataLength\r
332 )\r
333{\r
334 //\r
335 // PEI HOB is read only for DXE phase\r
336 //\r
337 ASSERT (FALSE);\r
338 return NULL;\r
339}\r
340\r
341/**\r
342 Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB \r
343 data field, and returns the start address of the GUID HOB data.\r
344\r
345 This function builds a customized HOB tagged with a GUID for identification and copies the input\r
346 data to the HOB data field and returns the start address of the GUID HOB data. It can only be \r
347 invoked during PEI phase; for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase. \r
348 The HOB Header and Name field is already stripped.\r
349 It can only be invoked during PEI phase;\r
350 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
351 \r
352 If Guid is NULL, then ASSERT().\r
353 If Data is NULL and DataLength > 0, then ASSERT().\r
354 If there is no additional space for HOB creation, then ASSERT().\r
355 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
356 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.\r
357\r
358 @param Guid The GUID to tag the customized HOB.\r
359 @param Data The data to be copied into the data field of the GUID HOB.\r
360 @param DataLength The size of the data payload for the GUID HOB.\r
361\r
362 @retval NULL The GUID HOB could not be allocated.\r
363 @retval others The start address of GUID HOB data.\r
364\r
365**/\r
366VOID *\r
367EFIAPI\r
368BuildGuidDataHob (\r
369 IN CONST EFI_GUID *Guid,\r
370 IN VOID *Data,\r
371 IN UINTN DataLength\r
372 )\r
373{\r
374 //\r
375 // PEI HOB is read only for DXE phase\r
376 //\r
377 ASSERT (FALSE);\r
378 return NULL;\r
379}\r
380\r
381/**\r
382 Builds a Firmware Volume HOB.\r
383\r
384 This function builds a Firmware Volume HOB.\r
385 It can only be invoked during PEI phase;\r
386 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
387 \r
388 If there is no additional space for HOB creation, then ASSERT().\r
389\r
390 @param BaseAddress The base address of the Firmware Volume.\r
391 @param Length The size of the Firmware Volume in bytes.\r
392\r
393**/\r
394VOID\r
395EFIAPI\r
396BuildFvHob (\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 EFI_HOB_TYPE_FV2 HOB.\r
409\r
410 This function builds a EFI_HOB_TYPE_FV2 HOB.\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 \r
414 If there is no additional space for HOB creation, then ASSERT().\r
415\r
416 @param BaseAddress The base address of the Firmware Volume.\r
417 @param Length The size of the Firmware Volume in bytes.\r
418 @param FvName The name of the Firmware Volume.\r
419 @param FileName The name of the file.\r
420 \r
421**/\r
422VOID\r
423EFIAPI\r
424BuildFv2Hob (\r
425 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
426 IN UINT64 Length,\r
427 IN CONST EFI_GUID *FvName,\r
428 IN CONST EFI_GUID *FileName\r
429 )\r
430{\r
431 ASSERT (FALSE);\r
432}\r
433\r
434\r
435/**\r
436 Builds a Capsule Volume HOB.\r
437\r
438 This function builds a Capsule Volume HOB.\r
439 It can only be invoked during PEI phase;\r
440 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
441 \r
442 If the platform does not support Capsule Volume HOBs, then ASSERT().\r
443 If there is no additional space for HOB creation, then ASSERT().\r
444\r
445 @param BaseAddress The base address of the Capsule Volume.\r
446 @param Length The size of the Capsule Volume in bytes.\r
447\r
448**/\r
449VOID\r
450EFIAPI\r
451BuildCvHob (\r
452 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
453 IN UINT64 Length\r
454 )\r
455{\r
456 //\r
457 // PEI HOB is read only for DXE phase\r
458 //\r
459 ASSERT (FALSE);\r
460}\r
461\r
462/**\r
463 Builds a HOB for the CPU.\r
464\r
465 This function builds a HOB for the CPU.\r
466 It can only be invoked during PEI phase;\r
467 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
468 \r
469 If there is no additional space for HOB creation, then ASSERT().\r
470\r
471 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.\r
472 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.\r
473\r
474**/\r
475VOID\r
476EFIAPI\r
477BuildCpuHob (\r
478 IN UINT8 SizeOfMemorySpace,\r
479 IN UINT8 SizeOfIoSpace\r
480 )\r
481{\r
482 //\r
483 // PEI HOB is read only for DXE phase\r
484 //\r
485 ASSERT (FALSE);\r
486}\r
487\r
488/**\r
489 Builds a HOB for the Stack.\r
490\r
491 This function builds a HOB for the stack.\r
492 It can only be invoked during PEI phase;\r
493 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
494 \r
495 If there is no additional space for HOB creation, then ASSERT().\r
496\r
497 @param BaseAddress The 64 bit physical address of the Stack.\r
498 @param Length The length of the stack in bytes.\r
499\r
500**/\r
501VOID\r
502EFIAPI\r
503BuildStackHob (\r
504 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
505 IN UINT64 Length\r
506 )\r
507{\r
508 //\r
509 // PEI HOB is read only for DXE phase\r
510 //\r
511 ASSERT (FALSE);\r
512}\r
513\r
514/**\r
515 Builds a HOB for the BSP store.\r
516\r
517 This function builds a HOB for BSP store.\r
518 It can only be invoked during PEI phase;\r
519 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
520 \r
521 If there is no additional space for HOB creation, then ASSERT().\r
522\r
523 @param BaseAddress The 64 bit physical address of the BSP.\r
524 @param Length The length of the BSP store in bytes.\r
525 @param MemoryType Type of memory allocated by this HOB.\r
526\r
527**/\r
528VOID\r
529EFIAPI\r
530BuildBspStoreHob (\r
531 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
532 IN UINT64 Length,\r
533 IN EFI_MEMORY_TYPE MemoryType\r
534 )\r
535{\r
536 //\r
537 // PEI HOB is read only for DXE phase\r
538 //\r
539 ASSERT (FALSE);\r
540}\r
541\r
542/**\r
543 Builds a HOB for the memory allocation.\r
544\r
545 This function builds a HOB for the memory allocation.\r
546 It can only be invoked during PEI phase;\r
547 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
548 \r
549 If there is no additional space for HOB creation, then ASSERT().\r
550\r
551 @param BaseAddress The 64 bit physical address of the memory.\r
552 @param Length The length of the memory allocation in bytes.\r
553 @param MemoryType Type of memory allocated by this HOB.\r
554\r
555**/\r
556VOID\r
557EFIAPI\r
558BuildMemoryAllocationHob (\r
559 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
560 IN UINT64 Length,\r
561 IN EFI_MEMORY_TYPE MemoryType\r
562 )\r
563{\r
564 //\r
565 // PEI HOB is read only for DXE phase\r
566 //\r
567 ASSERT (FALSE);\r
568}\r