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