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