]>
Commit | Line | Data |
---|---|---|
2f78ec7a | 1 | /** @file\r |
2 | Instance of HOB Library using PEI Services.\r | |
3 | \r | |
4 | HOB Library implementation that uses PEI Services to retrieve the HOB List.\r | |
5 | This library instance uses EFI_HOB_TYPE_CV defined in Intel framework HOB specification v0.9\r | |
1c2f052d | 6 | to implement HobLib BuildCvHob() API.\r |
2f78ec7a | 7 | \r |
1c2f052d | 8 | Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r |
22a69a5e | 9 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
2f78ec7a | 10 | \r |
11 | **/\r | |
12 | \r | |
2f78ec7a | 13 | #include <FrameworkPei.h>\r |
14 | \r | |
15 | #include <Guid/MemoryAllocationHob.h>\r | |
16 | \r | |
17 | #include <Library/HobLib.h>\r | |
18 | #include <Library/DebugLib.h>\r | |
19 | #include <Library/PeiServicesLib.h>\r | |
20 | #include <Library/BaseMemoryLib.h>\r | |
21 | \r | |
22 | /**\r | |
23 | Returns the pointer to the HOB list.\r | |
24 | \r | |
25 | This function returns the pointer to first HOB in the list.\r | |
1c2f052d | 26 | For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer\r |
2f78ec7a | 27 | to the HOB list. For the DXE phase, the HOB list pointer can be retrieved through\r |
28 | the EFI System Table by looking up theHOB list GUID in the System Configuration Table.\r | |
1c2f052d LG |
29 | Since the System Configuration Table does not exist that the time the DXE Core is\r |
30 | launched, the DXE Core uses a global variable from the DXE Core Entry Point Library\r | |
2f78ec7a | 31 | to manage the pointer to the HOB list.\r |
1c2f052d | 32 | \r |
2f78ec7a | 33 | If the pointer to the HOB list is NULL, then ASSERT().\r |
1c2f052d | 34 | \r |
2f78ec7a | 35 | @return The pointer to the HOB list.\r |
36 | \r | |
37 | **/\r | |
38 | VOID *\r | |
39 | EFIAPI\r | |
40 | GetHobList (\r | |
41 | VOID\r | |
42 | )\r | |
43 | {\r | |
44 | EFI_STATUS Status;\r | |
45 | VOID *HobList;\r | |
46 | \r | |
47 | Status = PeiServicesGetHobList (&HobList);\r | |
48 | ASSERT_EFI_ERROR (Status);\r | |
49 | ASSERT (HobList != NULL);\r | |
50 | \r | |
51 | return HobList;\r | |
52 | }\r | |
53 | \r | |
54 | /**\r | |
55 | Returns the next instance of a HOB type from the starting HOB.\r | |
56 | \r | |
1c2f052d | 57 | This function searches the first instance of a HOB type from the starting HOB pointer.\r |
2f78ec7a | 58 | If there does not exist such HOB type from the starting HOB pointer, it will return NULL.\r |
59 | In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r | |
60 | unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r | |
61 | caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r | |
1c2f052d | 62 | \r |
2f78ec7a | 63 | If HobStart is NULL, then ASSERT().\r |
64 | \r | |
65 | @param Type The HOB type to return.\r | |
66 | @param HobStart The starting HOB pointer to search from.\r | |
67 | \r | |
68 | @return The next instance of a HOB type from the starting HOB.\r | |
69 | \r | |
70 | **/\r | |
71 | VOID *\r | |
72 | EFIAPI\r | |
73 | GetNextHob (\r | |
74 | IN UINT16 Type,\r | |
75 | IN CONST VOID *HobStart\r | |
76 | )\r | |
77 | {\r | |
78 | EFI_PEI_HOB_POINTERS Hob;\r | |
79 | \r | |
80 | ASSERT (HobStart != NULL);\r | |
1c2f052d | 81 | \r |
2f78ec7a | 82 | Hob.Raw = (UINT8 *) HobStart;\r |
83 | //\r | |
84 | // Parse the HOB list until end of list or matching type is found.\r | |
85 | //\r | |
86 | while (!END_OF_HOB_LIST (Hob)) {\r | |
87 | if (Hob.Header->HobType == Type) {\r | |
88 | return Hob.Raw;\r | |
89 | }\r | |
90 | Hob.Raw = GET_NEXT_HOB (Hob);\r | |
91 | }\r | |
92 | return NULL;\r | |
93 | }\r | |
94 | \r | |
95 | /**\r | |
96 | Returns the first instance of a HOB type among the whole HOB list.\r | |
97 | \r | |
1c2f052d LG |
98 | This function searches the first instance of a HOB type among the whole HOB list.\r |
99 | If there does not exist such HOB type in the HOB list, it will return NULL.\r | |
100 | \r | |
2f78ec7a | 101 | If the pointer to the HOB list is NULL, then ASSERT().\r |
102 | \r | |
103 | @param Type The HOB type to return.\r | |
104 | \r | |
105 | @return The next instance of a HOB type from the starting HOB.\r | |
106 | \r | |
107 | **/\r | |
108 | VOID *\r | |
109 | EFIAPI\r | |
110 | GetFirstHob (\r | |
111 | IN UINT16 Type\r | |
112 | )\r | |
113 | {\r | |
114 | VOID *HobList;\r | |
115 | \r | |
116 | HobList = GetHobList ();\r | |
117 | return GetNextHob (Type, HobList);\r | |
118 | }\r | |
119 | \r | |
120 | /**\r | |
121 | Returns the next instance of the matched GUID HOB from the starting HOB.\r | |
1c2f052d LG |
122 | \r |
123 | This function searches the first instance of a HOB from the starting HOB pointer.\r | |
124 | Such HOB should satisfy two conditions:\r | |
125 | its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.\r | |
126 | If there does not exist such HOB from the starting HOB pointer, it will return NULL.\r | |
2f78ec7a | 127 | Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r |
128 | to extract the data section and its size info respectively.\r | |
129 | In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r | |
130 | unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r | |
131 | caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r | |
1c2f052d | 132 | \r |
2f78ec7a | 133 | If Guid is NULL, then ASSERT().\r |
134 | If HobStart is NULL, then ASSERT().\r | |
135 | \r | |
136 | @param Guid The GUID to match with in the HOB list.\r | |
137 | @param HobStart A pointer to a Guid.\r | |
138 | \r | |
139 | @return The next instance of the matched GUID HOB from the starting HOB.\r | |
140 | \r | |
141 | **/\r | |
142 | VOID *\r | |
143 | EFIAPI\r | |
144 | GetNextGuidHob (\r | |
145 | IN CONST EFI_GUID *Guid,\r | |
146 | IN CONST VOID *HobStart\r | |
147 | )\r | |
148 | {\r | |
149 | EFI_PEI_HOB_POINTERS GuidHob;\r | |
150 | \r | |
151 | GuidHob.Raw = (UINT8 *) HobStart;\r | |
152 | while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {\r | |
153 | if (CompareGuid (Guid, &GuidHob.Guid->Name)) {\r | |
154 | break;\r | |
155 | }\r | |
156 | GuidHob.Raw = GET_NEXT_HOB (GuidHob);\r | |
157 | }\r | |
158 | return GuidHob.Raw;\r | |
159 | }\r | |
160 | \r | |
161 | /**\r | |
162 | Returns the first instance of the matched GUID HOB among the whole HOB list.\r | |
1c2f052d LG |
163 | \r |
164 | This function searches the first instance of a HOB among the whole HOB list.\r | |
2f78ec7a | 165 | Such HOB should satisfy two conditions:\r |
166 | its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.\r | |
167 | If there does not exist such HOB from the starting HOB pointer, it will return NULL.\r | |
168 | Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r | |
169 | to extract the data section and its size info respectively.\r | |
1c2f052d | 170 | \r |
2f78ec7a | 171 | If the pointer to the HOB list is NULL, then ASSERT().\r |
172 | If Guid is NULL, then ASSERT().\r | |
173 | \r | |
174 | @param Guid The GUID to match with in the HOB list.\r | |
175 | \r | |
176 | @return The first instance of the matched GUID HOB among the whole HOB list.\r | |
177 | \r | |
178 | **/\r | |
179 | VOID *\r | |
180 | EFIAPI\r | |
181 | GetFirstGuidHob (\r | |
182 | IN CONST EFI_GUID *Guid\r | |
183 | )\r | |
184 | {\r | |
185 | VOID *HobList;\r | |
186 | \r | |
187 | HobList = GetHobList ();\r | |
188 | return GetNextGuidHob (Guid, HobList);\r | |
189 | }\r | |
190 | \r | |
191 | /**\r | |
192 | Get the system boot mode from the HOB list.\r | |
193 | \r | |
1c2f052d | 194 | This function returns the system boot mode information from the\r |
2f78ec7a | 195 | PHIT HOB in HOB list.\r |
196 | \r | |
197 | If the pointer to the HOB list is NULL, then ASSERT().\r | |
1c2f052d | 198 | \r |
2f78ec7a | 199 | @param VOID\r |
200 | \r | |
201 | @return The Boot Mode.\r | |
202 | \r | |
203 | **/\r | |
204 | EFI_BOOT_MODE\r | |
205 | EFIAPI\r | |
206 | GetBootModeHob (\r | |
207 | VOID\r | |
208 | )\r | |
209 | {\r | |
210 | EFI_STATUS Status;\r | |
211 | EFI_BOOT_MODE BootMode;\r | |
212 | \r | |
213 | Status = PeiServicesGetBootMode (&BootMode);\r | |
214 | ASSERT_EFI_ERROR (Status);\r | |
215 | \r | |
216 | return BootMode;\r | |
217 | }\r | |
218 | \r | |
219 | /**\r | |
220 | Adds a new HOB to the HOB List.\r | |
221 | \r | |
222 | This internal function enables PEIMs to create various types of HOBs.\r | |
223 | \r | |
224 | @param Type Type of the new HOB.\r | |
225 | @param Length Length of the new HOB to allocate.\r | |
226 | \r | |
2dfdd3eb RN |
227 | @retval NULL The HOB could not be allocated.\r |
228 | @retval others The address of new HOB.\r | |
2f78ec7a | 229 | \r |
230 | **/\r | |
231 | VOID *\r | |
232 | EFIAPI\r | |
233 | InternalPeiCreateHob (\r | |
234 | IN UINT16 Type,\r | |
235 | IN UINT16 Length\r | |
236 | )\r | |
237 | {\r | |
238 | EFI_STATUS Status;\r | |
239 | VOID *Hob;\r | |
240 | \r | |
241 | Status = PeiServicesCreateHob (Type, Length, &Hob);\r | |
2dfdd3eb RN |
242 | if (EFI_ERROR (Status)) {\r |
243 | Hob = NULL;\r | |
244 | }\r | |
2f78ec7a | 245 | //\r |
246 | // Assume the process of HOB building is always successful.\r | |
247 | //\r | |
2dfdd3eb | 248 | ASSERT (Hob != NULL);\r |
2f78ec7a | 249 | return Hob;\r |
250 | }\r | |
251 | \r | |
252 | /**\r | |
253 | Builds a HOB for a loaded PE32 module.\r | |
254 | \r | |
255 | This function builds a HOB for a loaded PE32 module.\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 | |
1c2f052d | 258 | \r |
2f78ec7a | 259 | If ModuleName is NULL, then ASSERT().\r |
260 | If there is no additional space for HOB creation, then ASSERT().\r | |
261 | \r | |
262 | @param ModuleName The GUID File Name of the module.\r | |
263 | @param MemoryAllocationModule The 64 bit physical address of the module.\r | |
264 | @param ModuleLength The length of the module in bytes.\r | |
265 | @param EntryPoint The 64 bit physical address of the module entry point.\r | |
266 | \r | |
267 | **/\r | |
268 | VOID\r | |
269 | EFIAPI\r | |
270 | BuildModuleHob (\r | |
271 | IN CONST EFI_GUID *ModuleName,\r | |
272 | IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,\r | |
273 | IN UINT64 ModuleLength,\r | |
274 | IN EFI_PHYSICAL_ADDRESS EntryPoint\r | |
275 | )\r | |
276 | {\r | |
277 | EFI_HOB_MEMORY_ALLOCATION_MODULE *Hob;\r | |
278 | \r | |
279 | ASSERT (((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) &&\r | |
280 | ((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0));\r | |
281 | \r | |
8194a023 | 282 | Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE));\r |
2dfdd3eb RN |
283 | if (Hob == NULL) {\r |
284 | return;\r | |
285 | }\r | |
2f78ec7a | 286 | \r |
287 | CopyGuid (&(Hob->MemoryAllocationHeader.Name), &gEfiHobMemoryAllocModuleGuid);\r | |
288 | Hob->MemoryAllocationHeader.MemoryBaseAddress = MemoryAllocationModule;\r | |
289 | Hob->MemoryAllocationHeader.MemoryLength = ModuleLength;\r | |
290 | Hob->MemoryAllocationHeader.MemoryType = EfiBootServicesCode;\r | |
291 | \r | |
292 | //\r | |
293 | // Zero the reserved space to match HOB spec\r | |
294 | //\r | |
295 | ZeroMem (Hob->MemoryAllocationHeader.Reserved, sizeof (Hob->MemoryAllocationHeader.Reserved));\r | |
1c2f052d | 296 | \r |
2f78ec7a | 297 | CopyGuid (&Hob->ModuleName, ModuleName);\r |
298 | Hob->EntryPoint = EntryPoint;\r | |
299 | }\r | |
300 | \r | |
b947f0cf | 301 | /**\r |
f1e2b728 | 302 | Builds a HOB that describes a chunk of system memory with Owner GUID.\r |
b947f0cf HT |
303 | \r |
304 | This function builds a HOB that describes a chunk of system memory.\r | |
305 | It can only be invoked during PEI phase;\r | |
306 | for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r | |
1c2f052d | 307 | \r |
b947f0cf HT |
308 | If there is no additional space for HOB creation, then ASSERT().\r |
309 | \r | |
310 | @param ResourceType The type of resource described by this HOB.\r | |
311 | @param ResourceAttribute The resource attributes of the memory described by this HOB.\r | |
312 | @param PhysicalStart The 64 bit physical address of memory described by this HOB.\r | |
313 | @param NumberOfBytes The length of the memory described by this HOB in bytes.\r | |
f1e2b728 | 314 | @param OwnerGUID GUID for the owner of this resource.\r |
b947f0cf HT |
315 | \r |
316 | **/\r | |
317 | VOID\r | |
318 | EFIAPI\r | |
319 | BuildResourceDescriptorWithOwnerHob (\r | |
320 | IN EFI_RESOURCE_TYPE ResourceType,\r | |
321 | IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,\r | |
322 | IN EFI_PHYSICAL_ADDRESS PhysicalStart,\r | |
323 | IN UINT64 NumberOfBytes,\r | |
324 | IN EFI_GUID *OwnerGUID\r | |
325 | )\r | |
326 | {\r | |
327 | EFI_HOB_RESOURCE_DESCRIPTOR *Hob;\r | |
a75cf433 SZ |
328 | \r |
329 | Hob = InternalPeiCreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, (UINT16) sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));\r | |
330 | if (Hob == NULL) {\r | |
331 | return;\r | |
332 | }\r | |
b947f0cf HT |
333 | \r |
334 | Hob->ResourceType = ResourceType;\r | |
335 | Hob->ResourceAttribute = ResourceAttribute;\r | |
336 | Hob->PhysicalStart = PhysicalStart;\r | |
337 | Hob->ResourceLength = NumberOfBytes;\r | |
338 | \r | |
339 | CopyGuid (&Hob->Owner, OwnerGUID);\r | |
f1e2b728 SZ |
340 | }\r |
341 | \r | |
2f78ec7a | 342 | /**\r |
343 | Builds a HOB that describes a chunk of system memory.\r | |
344 | \r | |
345 | This function builds a HOB that describes a chunk of system memory.\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 | |
1c2f052d | 348 | \r |
2f78ec7a | 349 | If there is no additional space for HOB creation, then ASSERT().\r |
350 | \r | |
351 | @param ResourceType The type of resource described by this HOB.\r | |
352 | @param ResourceAttribute The resource attributes of the memory described by this HOB.\r | |
353 | @param PhysicalStart The 64 bit physical address of memory described by this HOB.\r | |
354 | @param NumberOfBytes The length of the memory described by this HOB in bytes.\r | |
355 | \r | |
356 | **/\r | |
357 | VOID\r | |
358 | EFIAPI\r | |
359 | BuildResourceDescriptorHob (\r | |
360 | IN EFI_RESOURCE_TYPE ResourceType,\r | |
361 | IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,\r | |
362 | IN EFI_PHYSICAL_ADDRESS PhysicalStart,\r | |
363 | IN UINT64 NumberOfBytes\r | |
364 | )\r | |
365 | {\r | |
366 | EFI_HOB_RESOURCE_DESCRIPTOR *Hob;\r | |
367 | \r | |
8194a023 | 368 | Hob = InternalPeiCreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, (UINT16) sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));\r |
2dfdd3eb RN |
369 | if (Hob == NULL) {\r |
370 | return;\r | |
371 | }\r | |
2f78ec7a | 372 | \r |
373 | Hob->ResourceType = ResourceType;\r | |
374 | Hob->ResourceAttribute = ResourceAttribute;\r | |
375 | Hob->PhysicalStart = PhysicalStart;\r | |
376 | Hob->ResourceLength = NumberOfBytes;\r | |
f1e2b728 | 377 | ZeroMem (&(Hob->Owner), sizeof (EFI_GUID));\r |
2f78ec7a | 378 | }\r |
379 | \r | |
380 | /**\r | |
1c2f052d | 381 | Builds a customized HOB tagged with a GUID for identification and returns\r |
2f78ec7a | 382 | the start address of GUID HOB data.\r |
383 | \r | |
1c2f052d LG |
384 | This function builds a customized HOB tagged with a GUID for identification\r |
385 | and returns the start address of GUID HOB data so that caller can fill the customized data.\r | |
2f78ec7a | 386 | The HOB Header and Name field is already stripped.\r |
387 | It can only be invoked during PEI phase;\r | |
388 | for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r | |
1c2f052d | 389 | \r |
2f78ec7a | 390 | If Guid is NULL, then ASSERT().\r |
391 | If there is no additional space for HOB creation, then ASSERT().\r | |
392 | If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r | |
393 | \r | |
394 | @param Guid The GUID to tag the customized HOB.\r | |
395 | @param DataLength The size of the data payload for the GUID HOB.\r | |
396 | \r | |
2dfdd3eb RN |
397 | @retval NULL The GUID HOB could not be allocated.\r |
398 | @retval others The start address of GUID HOB data.\r | |
2f78ec7a | 399 | \r |
400 | **/\r | |
401 | VOID *\r | |
402 | EFIAPI\r | |
403 | BuildGuidHob (\r | |
404 | IN CONST EFI_GUID *Guid,\r | |
405 | IN UINTN DataLength\r | |
406 | )\r | |
407 | {\r | |
408 | EFI_HOB_GUID_TYPE *Hob;\r | |
409 | \r | |
2dfdd3eb RN |
410 | //\r |
411 | // Make sure Guid is valid\r | |
412 | //\r | |
413 | ASSERT (Guid != NULL);\r | |
1c2f052d | 414 | \r |
2f78ec7a | 415 | //\r |
416 | // Make sure that data length is not too long.\r | |
417 | //\r | |
418 | ASSERT (DataLength <= (0xffff - sizeof (EFI_HOB_GUID_TYPE)));\r | |
419 | \r | |
420 | Hob = InternalPeiCreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16) (sizeof (EFI_HOB_GUID_TYPE) + DataLength));\r | |
2dfdd3eb RN |
421 | if (Hob == NULL) {\r |
422 | return Hob;\r | |
423 | }\r | |
2f78ec7a | 424 | CopyGuid (&Hob->Name, Guid);\r |
425 | return Hob + 1;\r | |
426 | }\r | |
427 | \r | |
428 | /**\r | |
1c2f052d | 429 | Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB\r |
2f78ec7a | 430 | data field, and returns the start address of the GUID HOB data.\r |
431 | \r | |
432 | This function builds a customized HOB tagged with a GUID for identification and copies the input\r | |
1c2f052d LG |
433 | data to the HOB data field and returns the start address of the GUID HOB data. It can only be\r |
434 | invoked during PEI phase; for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r | |
2f78ec7a | 435 | The HOB Header and Name field is already stripped.\r |
436 | It can only be invoked during PEI phase;\r | |
437 | for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r | |
1c2f052d | 438 | \r |
2f78ec7a | 439 | If Guid is NULL, then ASSERT().\r |
440 | If Data is NULL and DataLength > 0, then ASSERT().\r | |
441 | If there is no additional space for HOB creation, then ASSERT().\r | |
442 | If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r | |
443 | \r | |
444 | @param Guid The GUID to tag the customized HOB.\r | |
445 | @param Data The data to be copied into the data field of the GUID HOB.\r | |
446 | @param DataLength The size of the data payload for the GUID HOB.\r | |
447 | \r | |
2dfdd3eb RN |
448 | @retval NULL The GUID HOB could not be allocated.\r |
449 | @retval others The start address of GUID HOB data.\r | |
2f78ec7a | 450 | \r |
451 | **/\r | |
452 | VOID *\r | |
453 | EFIAPI\r | |
454 | BuildGuidDataHob (\r | |
455 | IN CONST EFI_GUID *Guid,\r | |
456 | IN VOID *Data,\r | |
457 | IN UINTN DataLength\r | |
458 | )\r | |
459 | {\r | |
460 | VOID *HobData;\r | |
461 | \r | |
462 | ASSERT (Data != NULL || DataLength == 0);\r | |
463 | \r | |
464 | HobData = BuildGuidHob (Guid, DataLength);\r | |
2dfdd3eb RN |
465 | if (HobData == NULL) {\r |
466 | return HobData;\r | |
467 | }\r | |
2f78ec7a | 468 | \r |
469 | return CopyMem (HobData, Data, DataLength);\r | |
470 | }\r | |
471 | \r | |
368871a3 SZ |
472 | /**\r |
473 | Check FV alignment.\r | |
474 | \r | |
475 | @param BaseAddress The base address of the Firmware Volume.\r | |
476 | @param Length The size of the Firmware Volume in bytes.\r | |
477 | \r | |
478 | @retval TRUE FvImage buffer is at its required alignment.\r | |
479 | @retval FALSE FvImage buffer is not at its required alignment.\r | |
480 | \r | |
481 | **/\r | |
482 | BOOLEAN\r | |
483 | InternalCheckFvAlignment (\r | |
484 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
485 | IN UINT64 Length\r | |
486 | )\r | |
487 | {\r | |
488 | EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r | |
489 | UINT32 FvAlignment;\r | |
490 | \r | |
491 | FvAlignment = 0;\r | |
492 | FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress;\r | |
493 | \r | |
494 | //\r | |
495 | // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume\r | |
496 | // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from\r | |
497 | // its initial linked location and maintain its alignment.\r | |
498 | //\r | |
499 | if ((FwVolHeader->Attributes & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {\r | |
500 | //\r | |
501 | // Get FvHeader alignment\r | |
502 | //\r | |
503 | FvAlignment = 1 << ((FwVolHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);\r | |
504 | //\r | |
505 | // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.\r | |
506 | //\r | |
507 | if (FvAlignment < 8) {\r | |
508 | FvAlignment = 8;\r | |
509 | }\r | |
510 | if ((UINTN)BaseAddress % FvAlignment != 0) {\r | |
511 | //\r | |
512 | // FvImage buffer is not at its required alignment.\r | |
513 | //\r | |
514 | DEBUG ((\r | |
515 | DEBUG_ERROR,\r | |
516 | "Unaligned FvImage found at 0x%lx:0x%lx, the required alignment is 0x%x\n",\r | |
517 | BaseAddress,\r | |
518 | Length,\r | |
519 | FvAlignment\r | |
520 | ));\r | |
521 | return FALSE;\r | |
522 | }\r | |
523 | }\r | |
524 | \r | |
525 | return TRUE;\r | |
526 | }\r | |
527 | \r | |
2f78ec7a | 528 | /**\r |
529 | Builds a Firmware Volume HOB.\r | |
530 | \r | |
531 | This function builds a Firmware Volume HOB.\r | |
532 | It can only be invoked during PEI phase;\r | |
533 | for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r | |
1c2f052d | 534 | \r |
2f78ec7a | 535 | If there is no additional space for HOB creation, then ASSERT().\r |
368871a3 | 536 | If the FvImage buffer is not at its required alignment, then ASSERT().\r |
2f78ec7a | 537 | \r |
538 | @param BaseAddress The base address of the Firmware Volume.\r | |
539 | @param Length The size of the Firmware Volume in bytes.\r | |
540 | \r | |
541 | **/\r | |
542 | VOID\r | |
543 | EFIAPI\r | |
544 | BuildFvHob (\r | |
545 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
546 | IN UINT64 Length\r | |
547 | )\r | |
548 | {\r | |
549 | EFI_HOB_FIRMWARE_VOLUME *Hob;\r | |
550 | \r | |
368871a3 SZ |
551 | if (!InternalCheckFvAlignment (BaseAddress, Length)) {\r |
552 | ASSERT (FALSE);\r | |
553 | return;\r | |
554 | }\r | |
555 | \r | |
8194a023 | 556 | Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME));\r |
2dfdd3eb RN |
557 | if (Hob == NULL) {\r |
558 | return;\r | |
559 | }\r | |
2f78ec7a | 560 | \r |
561 | Hob->BaseAddress = BaseAddress;\r | |
562 | Hob->Length = Length;\r | |
563 | }\r | |
564 | \r | |
565 | /**\r | |
566 | Builds a EFI_HOB_TYPE_FV2 HOB.\r | |
567 | \r | |
568 | This function builds a EFI_HOB_TYPE_FV2 HOB.\r | |
569 | It can only be invoked during PEI phase;\r | |
570 | for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r | |
1c2f052d | 571 | \r |
2f78ec7a | 572 | If there is no additional space for HOB creation, then ASSERT().\r |
368871a3 | 573 | If the FvImage buffer is not at its required alignment, then ASSERT().\r |
2f78ec7a | 574 | \r |
575 | @param BaseAddress The base address of the Firmware Volume.\r | |
576 | @param Length The size of the Firmware Volume in bytes.\r | |
577 | @param FvName The name of the Firmware Volume.\r | |
578 | @param FileName The name of the file.\r | |
1c2f052d | 579 | \r |
2f78ec7a | 580 | **/\r |
581 | VOID\r | |
582 | EFIAPI\r | |
583 | BuildFv2Hob (\r | |
584 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
585 | IN UINT64 Length,\r | |
586 | IN CONST EFI_GUID *FvName,\r | |
587 | IN CONST EFI_GUID *FileName\r | |
588 | )\r | |
589 | {\r | |
590 | EFI_HOB_FIRMWARE_VOLUME2 *Hob;\r | |
591 | \r | |
368871a3 SZ |
592 | if (!InternalCheckFvAlignment (BaseAddress, Length)) {\r |
593 | ASSERT (FALSE);\r | |
594 | return;\r | |
595 | }\r | |
596 | \r | |
8194a023 | 597 | Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV2, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME2));\r |
2dfdd3eb RN |
598 | if (Hob == NULL) {\r |
599 | return;\r | |
600 | }\r | |
2f78ec7a | 601 | \r |
602 | Hob->BaseAddress = BaseAddress;\r | |
603 | Hob->Length = Length;\r | |
604 | CopyGuid (&Hob->FvName, FvName);\r | |
605 | CopyGuid (&Hob->FileName, FileName);\r | |
606 | }\r | |
607 | \r | |
e4623bd5 SZ |
608 | /**\r |
609 | Builds a EFI_HOB_TYPE_FV3 HOB.\r | |
610 | \r | |
611 | This function builds a EFI_HOB_TYPE_FV3 HOB.\r | |
612 | It can only be invoked during PEI phase;\r | |
613 | for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r | |
614 | \r | |
615 | If there is no additional space for HOB creation, then ASSERT().\r | |
616 | If the FvImage buffer is not at its required alignment, then ASSERT().\r | |
617 | \r | |
618 | @param BaseAddress The base address of the Firmware Volume.\r | |
619 | @param Length The size of the Firmware Volume in bytes.\r | |
620 | @param AuthenticationStatus The authentication status.\r | |
621 | @param ExtractedFv TRUE if the FV was extracted as a file within\r | |
622 | another firmware volume. FALSE otherwise.\r | |
623 | @param FvName The name of the Firmware Volume.\r | |
624 | Valid only if IsExtractedFv is TRUE.\r | |
625 | @param FileName The name of the file.\r | |
626 | Valid only if IsExtractedFv is TRUE.\r | |
627 | \r | |
628 | **/\r | |
629 | VOID\r | |
630 | EFIAPI\r | |
631 | BuildFv3Hob (\r | |
632 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
633 | IN UINT64 Length,\r | |
634 | IN UINT32 AuthenticationStatus,\r | |
635 | IN BOOLEAN ExtractedFv,\r | |
636 | IN CONST EFI_GUID *FvName, OPTIONAL\r | |
637 | IN CONST EFI_GUID *FileName OPTIONAL\r | |
638 | )\r | |
639 | {\r | |
640 | EFI_HOB_FIRMWARE_VOLUME3 *Hob;\r | |
641 | \r | |
642 | if (!InternalCheckFvAlignment (BaseAddress, Length)) {\r | |
643 | ASSERT (FALSE);\r | |
644 | return;\r | |
645 | }\r | |
646 | \r | |
647 | Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV3, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME3));\r | |
648 | if (Hob == NULL) {\r | |
649 | return;\r | |
650 | }\r | |
651 | \r | |
652 | Hob->BaseAddress = BaseAddress;\r | |
653 | Hob->Length = Length;\r | |
654 | Hob->AuthenticationStatus = AuthenticationStatus;\r | |
655 | Hob->ExtractedFv = ExtractedFv;\r | |
656 | if (ExtractedFv) {\r | |
657 | CopyGuid (&Hob->FvName, FvName);\r | |
658 | CopyGuid (&Hob->FileName, FileName);\r | |
659 | }\r | |
660 | }\r | |
661 | \r | |
2f78ec7a | 662 | /**\r |
663 | Builds a Capsule Volume HOB.\r | |
664 | \r | |
665 | This function builds a Capsule Volume HOB.\r | |
666 | It can only be invoked during PEI phase;\r | |
667 | for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r | |
1c2f052d | 668 | \r |
a5a3a29c | 669 | If the platform does not support Capsule Volume HOBs, then ASSERT().\r |
2f78ec7a | 670 | If there is no additional space for HOB creation, then ASSERT().\r |
671 | \r | |
672 | @param BaseAddress The base address of the Capsule Volume.\r | |
673 | @param Length The size of the Capsule Volume in bytes.\r | |
674 | \r | |
675 | **/\r | |
676 | VOID\r | |
677 | EFIAPI\r | |
678 | BuildCvHob (\r | |
679 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
680 | IN UINT64 Length\r | |
681 | )\r | |
682 | {\r | |
683 | EFI_HOB_CAPSULE_VOLUME *Hob;\r | |
684 | \r | |
8194a023 | 685 | Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CV, (UINT16) sizeof (EFI_HOB_CAPSULE_VOLUME));\r |
2dfdd3eb RN |
686 | if (Hob == NULL) {\r |
687 | return;\r | |
688 | }\r | |
2f78ec7a | 689 | \r |
690 | Hob->BaseAddress = BaseAddress;\r | |
691 | Hob->Length = Length;\r | |
692 | }\r | |
693 | \r | |
694 | /**\r | |
695 | Builds a HOB for the CPU.\r | |
696 | \r | |
697 | This function builds a HOB for the CPU.\r | |
698 | It can only be invoked during PEI phase;\r | |
699 | for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r | |
1c2f052d | 700 | \r |
2f78ec7a | 701 | If there is no additional space for HOB creation, then ASSERT().\r |
702 | \r | |
703 | @param SizeOfMemorySpace The maximum physical memory addressability of the processor.\r | |
704 | @param SizeOfIoSpace The maximum physical I/O addressability of the processor.\r | |
705 | \r | |
706 | **/\r | |
707 | VOID\r | |
708 | EFIAPI\r | |
709 | BuildCpuHob (\r | |
710 | IN UINT8 SizeOfMemorySpace,\r | |
711 | IN UINT8 SizeOfIoSpace\r | |
712 | )\r | |
713 | {\r | |
714 | EFI_HOB_CPU *Hob;\r | |
715 | \r | |
8194a023 | 716 | Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CPU, (UINT16) sizeof (EFI_HOB_CPU));\r |
2dfdd3eb RN |
717 | if (Hob == NULL) {\r |
718 | return;\r | |
719 | }\r | |
2f78ec7a | 720 | \r |
721 | Hob->SizeOfMemorySpace = SizeOfMemorySpace;\r | |
722 | Hob->SizeOfIoSpace = SizeOfIoSpace;\r | |
723 | \r | |
724 | //\r | |
725 | // Zero the reserved space to match HOB spec\r | |
726 | //\r | |
1c2f052d | 727 | ZeroMem (Hob->Reserved, sizeof (Hob->Reserved));\r |
2f78ec7a | 728 | }\r |
729 | \r | |
730 | /**\r | |
731 | Builds a HOB for the Stack.\r | |
732 | \r | |
733 | This function builds a HOB for the stack.\r | |
734 | It can only be invoked during PEI phase;\r | |
735 | for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r | |
1c2f052d | 736 | \r |
2f78ec7a | 737 | If there is no additional space for HOB creation, then ASSERT().\r |
738 | \r | |
739 | @param BaseAddress The 64 bit physical address of the Stack.\r | |
740 | @param Length The length of the stack in bytes.\r | |
741 | \r | |
742 | **/\r | |
743 | VOID\r | |
744 | EFIAPI\r | |
745 | BuildStackHob (\r | |
746 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
747 | IN UINT64 Length\r | |
748 | )\r | |
749 | {\r | |
750 | EFI_HOB_MEMORY_ALLOCATION_STACK *Hob;\r | |
751 | \r | |
752 | ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r | |
753 | ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r | |
754 | \r | |
8194a023 | 755 | Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK));\r |
2dfdd3eb RN |
756 | if (Hob == NULL) {\r |
757 | return;\r | |
758 | }\r | |
2f78ec7a | 759 | \r |
760 | CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocStackGuid);\r | |
761 | Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r | |
762 | Hob->AllocDescriptor.MemoryLength = Length;\r | |
763 | Hob->AllocDescriptor.MemoryType = EfiBootServicesData;\r | |
764 | \r | |
765 | //\r | |
766 | // Zero the reserved space to match HOB spec\r | |
767 | //\r | |
768 | ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r | |
769 | }\r | |
770 | \r | |
771 | /**\r | |
772 | Builds a HOB for the BSP store.\r | |
773 | \r | |
774 | This function builds a HOB for BSP store.\r | |
775 | It can only be invoked during PEI phase;\r | |
776 | for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r | |
1c2f052d | 777 | \r |
2f78ec7a | 778 | If there is no additional space for HOB creation, then ASSERT().\r |
779 | \r | |
780 | @param BaseAddress The 64 bit physical address of the BSP.\r | |
781 | @param Length The length of the BSP store in bytes.\r | |
782 | @param MemoryType Type of memory allocated by this HOB.\r | |
783 | \r | |
784 | **/\r | |
785 | VOID\r | |
786 | EFIAPI\r | |
787 | BuildBspStoreHob (\r | |
788 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
789 | IN UINT64 Length,\r | |
790 | IN EFI_MEMORY_TYPE MemoryType\r | |
791 | )\r | |
792 | {\r | |
793 | EFI_HOB_MEMORY_ALLOCATION_BSP_STORE *Hob;\r | |
794 | \r | |
795 | ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r | |
796 | ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r | |
797 | \r | |
8194a023 | 798 | Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_BSP_STORE));\r |
2dfdd3eb RN |
799 | if (Hob == NULL) {\r |
800 | return;\r | |
801 | }\r | |
2f78ec7a | 802 | \r |
803 | CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocBspStoreGuid);\r | |
804 | Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r | |
805 | Hob->AllocDescriptor.MemoryLength = Length;\r | |
806 | Hob->AllocDescriptor.MemoryType = MemoryType;\r | |
807 | \r | |
808 | //\r | |
809 | // Zero the reserved space to match HOB spec\r | |
810 | //\r | |
811 | ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r | |
812 | }\r | |
813 | \r | |
814 | /**\r | |
815 | Builds a HOB for the memory allocation.\r | |
816 | \r | |
817 | This function builds a HOB for the memory allocation.\r | |
818 | It can only be invoked during PEI phase;\r | |
819 | for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r | |
1c2f052d | 820 | \r |
2f78ec7a | 821 | If there is no additional space for HOB creation, then ASSERT().\r |
822 | \r | |
823 | @param BaseAddress The 64 bit physical address of the memory.\r | |
824 | @param Length The length of the memory allocation in bytes.\r | |
825 | @param MemoryType Type of memory allocated by this HOB.\r | |
826 | \r | |
827 | **/\r | |
828 | VOID\r | |
829 | EFIAPI\r | |
830 | BuildMemoryAllocationHob (\r | |
831 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
832 | IN UINT64 Length,\r | |
833 | IN EFI_MEMORY_TYPE MemoryType\r | |
834 | )\r | |
835 | {\r | |
836 | EFI_HOB_MEMORY_ALLOCATION *Hob;\r | |
837 | \r | |
838 | ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r | |
839 | ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r | |
1c2f052d | 840 | \r |
8194a023 | 841 | Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION));\r |
2dfdd3eb RN |
842 | if (Hob == NULL) {\r |
843 | return;\r | |
844 | }\r | |
1c2f052d | 845 | \r |
2f78ec7a | 846 | ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));\r |
847 | Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r | |
848 | Hob->AllocDescriptor.MemoryLength = Length;\r | |
849 | Hob->AllocDescriptor.MemoryType = MemoryType;\r | |
850 | //\r | |
851 | // Zero the reserved space to match HOB spec\r | |
852 | //\r | |
853 | ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r | |
854 | }\r |