]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/PeiHobLib/HobLib.c
Fix a bug introuduced by r16104, not all NIC device implement both memory and IO...
[mirror_edk2.git] / MdePkg / Library / PeiHobLib / HobLib.c
CommitLineData
66f0059f 1/** @file\r
6812ef9f 2 Provide Hob Library functions for Pei phase.\r
66f0059f 3\r
0ca7b0b8 4Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
19388d29 5This program and the accompanying materials\r
3e5c3238 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
58380e9c 8http://opensource.org/licenses/bsd-license.php.\r
66f0059f 9\r
3e5c3238 10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
66f0059f 12\r
66f0059f 13**/\r
14\r
66f0059f 15#include <PiPei.h>\r
c892d846 16\r
66f0059f 17#include <Guid/MemoryAllocationHob.h>\r
c892d846 18\r
66f0059f 19#include <Library/HobLib.h>\r
20#include <Library/DebugLib.h>\r
21#include <Library/PeiServicesLib.h>\r
22#include <Library/BaseMemoryLib.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
3e5c3238 28 For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer \r
29 to the HOB list. For the DXE phase, the HOB list pointer can be retrieved through\r
30 the EFI System Table by looking up theHOB list GUID in the System Configuration Table.\r
31 Since the System Configuration Table does not exist that the time the DXE Core is \r
32 launched, the DXE Core uses a global variable from the DXE Core Entry Point Library \r
33 to manage the pointer to the HOB list.\r
34 \r
35 If the pointer to the HOB list is NULL, then ASSERT().\r
36 \r
66f0059f 37 @return The pointer to the HOB list.\r
38\r
39**/\r
40VOID *\r
41EFIAPI\r
42GetHobList (\r
43 VOID\r
44 )\r
45{\r
46 EFI_STATUS Status;\r
47 VOID *HobList;\r
48\r
49 Status = PeiServicesGetHobList (&HobList);\r
50 ASSERT_EFI_ERROR (Status);\r
51 ASSERT (HobList != NULL);\r
52\r
53 return HobList;\r
54}\r
55\r
56/**\r
57 Returns the next instance of a HOB type from the starting HOB.\r
58\r
59 This function searches the first instance of a HOB type from the starting HOB pointer. \r
60 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.\r
61 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r
62 unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r
63 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r
3e5c3238 64 \r
66f0059f 65 If HobStart is NULL, then ASSERT().\r
66\r
67 @param Type The HOB type to return.\r
68 @param HobStart The starting HOB pointer to search from.\r
69\r
70 @return The next instance of a HOB type from the starting HOB.\r
71\r
72**/\r
73VOID *\r
74EFIAPI\r
75GetNextHob (\r
76 IN UINT16 Type,\r
77 IN CONST VOID *HobStart\r
78 )\r
79{\r
80 EFI_PEI_HOB_POINTERS Hob;\r
81\r
82 ASSERT (HobStart != NULL);\r
83 \r
84 Hob.Raw = (UINT8 *) HobStart;\r
85 //\r
86 // Parse the HOB list until end of list or matching type is found.\r
87 //\r
88 while (!END_OF_HOB_LIST (Hob)) {\r
89 if (Hob.Header->HobType == Type) {\r
90 return Hob.Raw;\r
91 }\r
92 Hob.Raw = GET_NEXT_HOB (Hob);\r
93 }\r
94 return NULL;\r
95}\r
96\r
97/**\r
98 Returns the first instance of a HOB type among the whole HOB list.\r
99\r
100 This function searches the first instance of a HOB type among the whole HOB list. \r
101 If there does not exist such HOB type in the HOB list, it will return NULL. \r
3e5c3238 102 \r
103 If the pointer to the HOB list is NULL, then ASSERT().\r
66f0059f 104\r
105 @param Type The HOB type to return.\r
106\r
107 @return The next instance of a HOB type from the starting HOB.\r
108\r
109**/\r
110VOID *\r
111EFIAPI\r
112GetFirstHob (\r
113 IN UINT16 Type\r
114 )\r
115{\r
116 VOID *HobList;\r
117\r
118 HobList = GetHobList ();\r
119 return GetNextHob (Type, HobList);\r
120}\r
121\r
122/**\r
3e5c3238 123 Returns the next instance of the matched GUID HOB from the starting HOB.\r
124 \r
66f0059f 125 This function searches the first instance of a HOB from the starting HOB pointer. \r
126 Such HOB should satisfy two conditions: \r
127 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid. \r
128 If there does not exist such HOB from the starting HOB pointer, it will return NULL. \r
129 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
58380e9c 130 to extract the data section and its size information, respectively.\r
66f0059f 131 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r
132 unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r
133 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r
3e5c3238 134 \r
66f0059f 135 If Guid is NULL, then ASSERT().\r
136 If HobStart is NULL, then ASSERT().\r
137\r
138 @param Guid The GUID to match with in the HOB list.\r
139 @param HobStart A pointer to a Guid.\r
140\r
141 @return The next instance of the matched GUID HOB from the starting HOB.\r
142\r
143**/\r
144VOID *\r
145EFIAPI\r
146GetNextGuidHob (\r
147 IN CONST EFI_GUID *Guid,\r
148 IN CONST VOID *HobStart\r
149 )\r
150{\r
151 EFI_PEI_HOB_POINTERS GuidHob;\r
152\r
153 GuidHob.Raw = (UINT8 *) HobStart;\r
154 while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {\r
155 if (CompareGuid (Guid, &GuidHob.Guid->Name)) {\r
156 break;\r
157 }\r
158 GuidHob.Raw = GET_NEXT_HOB (GuidHob);\r
159 }\r
160 return GuidHob.Raw;\r
161}\r
162\r
163/**\r
3e5c3238 164 Returns the first instance of the matched GUID HOB among the whole HOB list.\r
165 \r
66f0059f 166 This function searches the first instance of a HOB among the whole HOB list. \r
167 Such HOB should satisfy two conditions:\r
168 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.\r
169 If there does not exist such HOB from the starting HOB pointer, it will return NULL.\r
170 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
58380e9c 171 to extract the data section and its size information, respectively.\r
3e5c3238 172 \r
173 If the pointer to the HOB list is NULL, then ASSERT().\r
66f0059f 174 If Guid is NULL, then ASSERT().\r
175\r
176 @param Guid The GUID to match with in the HOB list.\r
177\r
178 @return The first instance of the matched GUID HOB among the whole HOB list.\r
179\r
180**/\r
181VOID *\r
182EFIAPI\r
183GetFirstGuidHob (\r
184 IN CONST EFI_GUID *Guid\r
185 )\r
186{\r
187 VOID *HobList;\r
188\r
189 HobList = GetHobList ();\r
190 return GetNextGuidHob (Guid, HobList);\r
191}\r
192\r
193/**\r
3e5c3238 194 Get the system boot mode from the HOB list.\r
66f0059f 195\r
3e5c3238 196 This function returns the system boot mode information from the \r
197 PHIT HOB in HOB list.\r
66f0059f 198\r
3e5c3238 199 If the pointer to the HOB list is NULL, then ASSERT().\r
200 \r
58380e9c 201 @param VOID.\r
66f0059f 202\r
203 @return The Boot Mode.\r
204\r
205**/\r
206EFI_BOOT_MODE\r
207EFIAPI\r
208GetBootModeHob (\r
209 VOID\r
210 )\r
211{\r
212 EFI_STATUS Status;\r
213 EFI_BOOT_MODE BootMode;\r
214\r
215 Status = PeiServicesGetBootMode (&BootMode);\r
216 ASSERT_EFI_ERROR (Status);\r
217\r
218 return BootMode;\r
219}\r
220\r
221/**\r
222 Adds a new HOB to the HOB List.\r
223\r
224 This internal function enables PEIMs to create various types of HOBs.\r
225\r
226 @param Type Type of the new HOB.\r
227 @param Length Length of the new HOB to allocate.\r
228\r
ef2635c3
RN
229 @retval NULL The HOB could not be allocated.\r
230 @retval others The address of new HOB.\r
66f0059f 231\r
232**/\r
66f0059f 233VOID *\r
42eedea9 234EFIAPI\r
66f0059f 235InternalPeiCreateHob (\r
236 IN UINT16 Type,\r
237 IN UINT16 Length\r
238 )\r
239{\r
240 EFI_STATUS Status;\r
241 VOID *Hob;\r
242\r
243 Status = PeiServicesCreateHob (Type, Length, &Hob);\r
ef2635c3
RN
244 if (EFI_ERROR (Status)) {\r
245 Hob = NULL;\r
246 }\r
66f0059f 247 //\r
248 // Assume the process of HOB building is always successful.\r
249 //\r
ef2635c3 250 ASSERT (Hob != NULL);\r
66f0059f 251 return Hob;\r
252}\r
253\r
254/**\r
255 Builds a HOB for a loaded PE32 module.\r
256\r
257 This function builds a HOB for a loaded PE32 module.\r
258 It can only be invoked during PEI phase;\r
259 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
3e5c3238 260 \r
66f0059f 261 If ModuleName is NULL, then ASSERT().\r
262 If there is no additional space for HOB creation, then ASSERT().\r
263\r
264 @param ModuleName The GUID File Name of the module.\r
265 @param MemoryAllocationModule The 64 bit physical address of the module.\r
266 @param ModuleLength The length of the module in bytes.\r
3e5c3238 267 @param EntryPoint The 64 bit physical address of the module entry point.\r
66f0059f 268\r
269**/\r
270VOID\r
271EFIAPI\r
272BuildModuleHob (\r
273 IN CONST EFI_GUID *ModuleName,\r
274 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,\r
275 IN UINT64 ModuleLength,\r
276 IN EFI_PHYSICAL_ADDRESS EntryPoint\r
277 )\r
278{\r
279 EFI_HOB_MEMORY_ALLOCATION_MODULE *Hob;\r
280\r
0a7d0741 281 ASSERT (((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) &&\r
282 ((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0));\r
283\r
f0b0ba31 284 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE));\r
ef2635c3
RN
285 if (Hob == NULL) {\r
286 return;\r
287 }\r
66f0059f 288\r
289 CopyGuid (&(Hob->MemoryAllocationHeader.Name), &gEfiHobMemoryAllocModuleGuid);\r
290 Hob->MemoryAllocationHeader.MemoryBaseAddress = MemoryAllocationModule;\r
291 Hob->MemoryAllocationHeader.MemoryLength = ModuleLength;\r
292 Hob->MemoryAllocationHeader.MemoryType = EfiBootServicesCode;\r
293\r
294 //\r
295 // Zero the reserved space to match HOB spec\r
296 //\r
297 ZeroMem (Hob->MemoryAllocationHeader.Reserved, sizeof (Hob->MemoryAllocationHeader.Reserved));\r
298 \r
299 CopyGuid (&Hob->ModuleName, ModuleName);\r
300 Hob->EntryPoint = EntryPoint;\r
301}\r
302\r
f1e2b728
SZ
303/**
304 Builds a HOB that describes a chunk of system memory with Owner GUID.\r
305
306 This function builds a HOB that describes a chunk of system memory.
307 It can only be invoked during PEI phase;
308 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
309
310 If there is no additional space for HOB creation, then ASSERT().
311
312 @param ResourceType The type of resource described by this HOB.
313 @param ResourceAttribute The resource attributes of the memory described by this HOB.
314 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
315 @param NumberOfBytes The length of the memory described by this HOB in bytes.
316 @param OwnerGUID GUID for the owner of this resource.\r
317
318**/
319VOID
320EFIAPI
321BuildResourceDescriptorWithOwnerHob (
322 IN EFI_RESOURCE_TYPE ResourceType,
323 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,
324 IN EFI_PHYSICAL_ADDRESS PhysicalStart,
325 IN UINT64 NumberOfBytes,
326 IN EFI_GUID *OwnerGUID
327 )
328{
329 EFI_HOB_RESOURCE_DESCRIPTOR *Hob;
330 EFI_STATUS Status;
331
332 Status = PeiServicesCreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, sizeof (EFI_HOB_RESOURCE_DESCRIPTOR), (void **)&Hob);
333 ASSERT_EFI_ERROR (Status);
334
335 Hob->ResourceType = ResourceType;
336 Hob->ResourceAttribute = ResourceAttribute;
337 Hob->PhysicalStart = PhysicalStart;
338 Hob->ResourceLength = NumberOfBytes;
339
340 CopyGuid (&Hob->Owner, OwnerGUID);
341}\r
342\r
66f0059f 343/**\r
344 Builds a HOB that describes a chunk of system memory.\r
345\r
346 This function builds a HOB that describes a chunk of system memory.\r
347 It can only be invoked during PEI phase;\r
348 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
3e5c3238 349 \r
66f0059f 350 If there is no additional space for HOB creation, then ASSERT().\r
351\r
352 @param ResourceType The type of resource described by this HOB.\r
353 @param ResourceAttribute The resource attributes of the memory described by this HOB.\r
354 @param PhysicalStart The 64 bit physical address of memory described by this HOB.\r
355 @param NumberOfBytes The length of the memory described by this HOB in bytes.\r
356\r
357**/\r
358VOID\r
359EFIAPI\r
360BuildResourceDescriptorHob (\r
361 IN EFI_RESOURCE_TYPE ResourceType,\r
362 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,\r
363 IN EFI_PHYSICAL_ADDRESS PhysicalStart,\r
364 IN UINT64 NumberOfBytes\r
365 )\r
366{\r
367 EFI_HOB_RESOURCE_DESCRIPTOR *Hob;\r
368\r
f0b0ba31 369 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, (UINT16) sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));\r
ef2635c3
RN
370 if (Hob == NULL) {\r
371 return;\r
372 }\r
66f0059f 373\r
374 Hob->ResourceType = ResourceType;\r
375 Hob->ResourceAttribute = ResourceAttribute;\r
376 Hob->PhysicalStart = PhysicalStart;\r
377 Hob->ResourceLength = NumberOfBytes;\r
0ca7b0b8 378 ZeroMem (&(Hob->Owner), sizeof (EFI_GUID));\r
66f0059f 379}\r
380\r
381/**\r
3e5c3238 382 Builds a customized HOB tagged with a GUID for identification and returns \r
383 the start address of GUID HOB data.\r
66f0059f 384\r
385 This function builds a customized HOB tagged with a GUID for identification \r
386 and returns the start address of GUID HOB data so that caller can fill the customized data. \r
387 The HOB Header and Name field is already stripped.\r
388 It can only be invoked during PEI phase;\r
389 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
3e5c3238 390 \r
66f0059f 391 If Guid is NULL, then ASSERT().\r
392 If there is no additional space for HOB creation, then ASSERT().\r
192764db
LG
393 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
394 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.\r
66f0059f 395\r
396 @param Guid The GUID to tag the customized HOB.\r
397 @param DataLength The size of the data payload for the GUID HOB.\r
398\r
ef2635c3
RN
399 @retval NULL The GUID HOB could not be allocated.\r
400 @retval others The start address of GUID HOB data.\r
66f0059f 401\r
402**/\r
403VOID *\r
404EFIAPI\r
405BuildGuidHob (\r
406 IN CONST EFI_GUID *Guid,\r
407 IN UINTN DataLength\r
408 )\r
409{\r
410 EFI_HOB_GUID_TYPE *Hob;\r
411\r
ef2635c3
RN
412 //\r
413 // Make sure Guid is valid\r
414 //\r
415 ASSERT (Guid != NULL);\r
416 \r
66f0059f 417 //\r
418 // Make sure that data length is not too long.\r
419 //\r
192764db 420 ASSERT (DataLength <= (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)));\r
66f0059f 421\r
422 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16) (sizeof (EFI_HOB_GUID_TYPE) + DataLength));\r
ef2635c3
RN
423 if (Hob == NULL) {\r
424 return Hob;\r
425 }\r
66f0059f 426 CopyGuid (&Hob->Name, Guid);\r
427 return Hob + 1;\r
428}\r
429\r
430/**\r
3e5c3238 431 Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB \r
432 data field, and returns the start address of the GUID HOB data.\r
66f0059f 433\r
3e5c3238 434 This function builds a customized HOB tagged with a GUID for identification and copies the input\r
435 data to the HOB data field and returns the start address of the GUID HOB data. It can only be \r
436 invoked during PEI phase; for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase. \r
66f0059f 437 The HOB Header and Name field is already stripped.\r
438 It can only be invoked during PEI phase;\r
439 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
3e5c3238 440 \r
66f0059f 441 If Guid is NULL, then ASSERT().\r
442 If Data is NULL and DataLength > 0, then ASSERT().\r
443 If there is no additional space for HOB creation, then ASSERT().\r
192764db
LG
444 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
445 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.\r
66f0059f 446\r
447 @param Guid The GUID to tag the customized HOB.\r
448 @param Data The data to be copied into the data field of the GUID HOB.\r
449 @param DataLength The size of the data payload for the GUID HOB.\r
450\r
ef2635c3
RN
451 @retval NULL The GUID HOB could not be allocated.\r
452 @retval others The start address of GUID HOB data.\r
66f0059f 453\r
454**/\r
455VOID *\r
456EFIAPI\r
457BuildGuidDataHob (\r
458 IN CONST EFI_GUID *Guid,\r
459 IN VOID *Data,\r
460 IN UINTN DataLength\r
461 )\r
462{\r
463 VOID *HobData;\r
464\r
465 ASSERT (Data != NULL || DataLength == 0);\r
466\r
467 HobData = BuildGuidHob (Guid, DataLength);\r
ef2635c3
RN
468 if (HobData == NULL) {\r
469 return HobData;\r
470 }\r
66f0059f 471\r
472 return CopyMem (HobData, Data, DataLength);\r
473}\r
474\r
475/**\r
476 Builds a Firmware Volume HOB.\r
477\r
478 This function builds a Firmware Volume HOB.\r
479 It can only be invoked during PEI phase;\r
480 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
3e5c3238 481 \r
66f0059f 482 If there is no additional space for HOB creation, then ASSERT().\r
483\r
484 @param BaseAddress The base address of the Firmware Volume.\r
485 @param Length The size of the Firmware Volume in bytes.\r
486\r
487**/\r
488VOID\r
489EFIAPI\r
490BuildFvHob (\r
491 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
492 IN UINT64 Length\r
493 )\r
494{\r
495 EFI_HOB_FIRMWARE_VOLUME *Hob;\r
496\r
f0b0ba31 497 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME));\r
ef2635c3
RN
498 if (Hob == NULL) {\r
499 return;\r
500 }\r
66f0059f 501\r
502 Hob->BaseAddress = BaseAddress;\r
503 Hob->Length = Length;\r
504}\r
505\r
07ad9b81 506/**\r
507 Builds a EFI_HOB_TYPE_FV2 HOB.\r
508\r
509 This function builds a EFI_HOB_TYPE_FV2 HOB.\r
510 It can only be invoked during PEI phase;\r
511 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
3e5c3238 512 \r
07ad9b81 513 If there is no additional space for HOB creation, then ASSERT().\r
514\r
515 @param BaseAddress The base address of the Firmware Volume.\r
516 @param Length The size of the Firmware Volume in bytes.\r
3e5c3238 517 @param FvName The name of the Firmware Volume.\r
07ad9b81 518 @param FileName The name of the file.\r
519 \r
520**/\r
521VOID\r
522EFIAPI\r
523BuildFv2Hob (\r
524 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
525 IN UINT64 Length,\r
526 IN CONST EFI_GUID *FvName,\r
527 IN CONST EFI_GUID *FileName\r
528 )\r
529{\r
530 EFI_HOB_FIRMWARE_VOLUME2 *Hob;\r
531\r
f0b0ba31 532 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV2, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME2));\r
ef2635c3
RN
533 if (Hob == NULL) {\r
534 return;\r
535 }\r
07ad9b81 536\r
537 Hob->BaseAddress = BaseAddress;\r
538 Hob->Length = Length;\r
3a364554 539 CopyGuid (&Hob->FvName, FvName);\r
540 CopyGuid (&Hob->FileName, FileName);\r
07ad9b81 541}\r
542\r
66f0059f 543/**\r
544 Builds a Capsule Volume HOB.\r
545\r
faf46b40 546 This function builds a Capsule Volume HOB.\r
547 It can only be invoked during PEI phase;\r
548 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
3e5c3238 549 \r
c85cea80 550 If the platform does not support Capsule Volume HOBs, then ASSERT().\r
faf46b40 551 If there is no additional space for HOB creation, then ASSERT().\r
552\r
553 @param BaseAddress The base address of the Capsule Volume.\r
554 @param Length The size of the Capsule Volume in bytes.\r
66f0059f 555\r
556**/\r
557VOID\r
558EFIAPI\r
559BuildCvHob (\r
560 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
561 IN UINT64 Length\r
562 )\r
563{\r
61acaac8 564 EFI_HOB_UEFI_CAPSULE *Hob;\r
565\r
f0b0ba31 566 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_UEFI_CAPSULE, (UINT16) sizeof (EFI_HOB_UEFI_CAPSULE));\r
ef2635c3
RN
567 if (Hob == NULL) {\r
568 return;\r
569 }\r
61acaac8 570\r
571 Hob->BaseAddress = BaseAddress;\r
572 Hob->Length = Length;\r
66f0059f 573}\r
574\r
575/**\r
576 Builds a HOB for the CPU.\r
577\r
578 This function builds a HOB for the CPU.\r
579 It can only be invoked during PEI phase;\r
580 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
3e5c3238 581 \r
66f0059f 582 If there is no additional space for HOB creation, then ASSERT().\r
583\r
584 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.\r
585 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.\r
586\r
587**/\r
588VOID\r
589EFIAPI\r
590BuildCpuHob (\r
591 IN UINT8 SizeOfMemorySpace,\r
592 IN UINT8 SizeOfIoSpace\r
593 )\r
594{\r
595 EFI_HOB_CPU *Hob;\r
596\r
f0b0ba31 597 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CPU, (UINT16) sizeof (EFI_HOB_CPU));\r
ef2635c3
RN
598 if (Hob == NULL) {\r
599 return;\r
600 }\r
66f0059f 601\r
602 Hob->SizeOfMemorySpace = SizeOfMemorySpace;\r
603 Hob->SizeOfIoSpace = SizeOfIoSpace;\r
604\r
605 //\r
606 // Zero the reserved space to match HOB spec\r
607 //\r
608 ZeroMem (Hob->Reserved, sizeof (Hob->Reserved)); \r
609}\r
610\r
611/**\r
612 Builds a HOB for the Stack.\r
613\r
614 This function builds a HOB for the stack.\r
615 It can only be invoked during PEI phase;\r
616 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
3e5c3238 617 \r
66f0059f 618 If there is no additional space for HOB creation, then ASSERT().\r
619\r
620 @param BaseAddress The 64 bit physical address of the Stack.\r
621 @param Length The length of the stack in bytes.\r
622\r
623**/\r
624VOID\r
625EFIAPI\r
626BuildStackHob (\r
627 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
628 IN UINT64 Length\r
629 )\r
630{\r
631 EFI_HOB_MEMORY_ALLOCATION_STACK *Hob;\r
632\r
0a7d0741 633 ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
634 ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r
635\r
f0b0ba31 636 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK));\r
ef2635c3
RN
637 if (Hob == NULL) {\r
638 return;\r
639 }\r
66f0059f 640\r
641 CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocStackGuid);\r
642 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
643 Hob->AllocDescriptor.MemoryLength = Length;\r
dda0251d 644 Hob->AllocDescriptor.MemoryType = EfiBootServicesData;\r
66f0059f 645\r
646 //\r
647 // Zero the reserved space to match HOB spec\r
648 //\r
649 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r
650}\r
651\r
652/**\r
653 Builds a HOB for the BSP store.\r
654\r
655 This function builds a HOB for BSP store.\r
656 It can only be invoked during PEI phase;\r
657 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
3e5c3238 658 \r
66f0059f 659 If there is no additional space for HOB creation, then ASSERT().\r
660\r
661 @param BaseAddress The 64 bit physical address of the BSP.\r
662 @param Length The length of the BSP store in bytes.\r
58380e9c 663 @param MemoryType The type of memory allocated by this HOB.\r
66f0059f 664\r
665**/\r
666VOID\r
667EFIAPI\r
668BuildBspStoreHob (\r
669 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
670 IN UINT64 Length,\r
671 IN EFI_MEMORY_TYPE MemoryType\r
672 )\r
673{\r
674 EFI_HOB_MEMORY_ALLOCATION_BSP_STORE *Hob;\r
675\r
0a7d0741 676 ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
677 ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r
678\r
f0b0ba31 679 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_BSP_STORE));\r
ef2635c3
RN
680 if (Hob == NULL) {\r
681 return;\r
682 }\r
66f0059f 683\r
684 CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocBspStoreGuid);\r
685 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
686 Hob->AllocDescriptor.MemoryLength = Length;\r
687 Hob->AllocDescriptor.MemoryType = MemoryType;\r
688\r
689 //\r
690 // Zero the reserved space to match HOB spec\r
691 //\r
692 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r
693}\r
694\r
695/**\r
696 Builds a HOB for the memory allocation.\r
697\r
698 This function builds a HOB for the memory allocation.\r
699 It can only be invoked during PEI phase;\r
700 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
3e5c3238 701 \r
66f0059f 702 If there is no additional space for HOB creation, then ASSERT().\r
703\r
704 @param BaseAddress The 64 bit physical address of the memory.\r
705 @param Length The length of the memory allocation in bytes.\r
58380e9c 706 @param MemoryType The type of memory allocated by this HOB.\r
66f0059f 707\r
708**/\r
709VOID\r
710EFIAPI\r
711BuildMemoryAllocationHob (\r
712 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
713 IN UINT64 Length,\r
714 IN EFI_MEMORY_TYPE MemoryType\r
715 )\r
716{\r
717 EFI_HOB_MEMORY_ALLOCATION *Hob;\r
718\r
0a7d0741 719 ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
720 ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r
721 \r
f0b0ba31 722 Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION));\r
ef2635c3
RN
723 if (Hob == NULL) {\r
724 return;\r
725 }\r
0a7d0741 726 \r
66f0059f 727 ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));\r
728 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
729 Hob->AllocDescriptor.MemoryLength = Length;\r
730 Hob->AllocDescriptor.MemoryType = MemoryType;\r
731 //\r
732 // Zero the reserved space to match HOB spec\r
733 //\r
734 ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r
735}\r