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