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