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