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