2 Sample to provide FSP hob process related function.
4 Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/PeiServicesLib.h>
12 #include <Library/PeiServicesTablePointerLib.h>
13 #include <Library/BaseLib.h>
14 #include <Library/DebugLib.h>
15 #include <Library/BaseMemoryLib.h>
16 #include <Library/HobLib.h>
17 #include <Library/PcdLib.h>
18 #include <Library/FspPlatformInfoLib.h>
20 #include <Guid/GuidHobFspEas.h>
21 #include <Guid/MemoryTypeInformation.h>
22 #include <Guid/PcdDataBaseHobGuid.h>
23 #include <Ppi/Capsule.h>
26 // Additional pages are used by DXE memory manager.
27 // It should be consistent between RetrieveRequiredMemorySize() and GetPeiMemSize()
29 #define PEI_ADDITIONAL_MEMORY_SIZE (16 * EFI_PAGE_SIZE)
32 Get the mem size in memory type infromation table.
34 @param[in] PeiServices PEI Services table.
36 @return the mem size in memory type infromation table.
39 GetMemorySizeInMemoryTypeInformation (
40 IN EFI_PEI_SERVICES
**PeiServices
43 EFI_PEI_HOB_POINTERS Hob
;
44 EFI_MEMORY_TYPE_INFORMATION
*MemoryData
;
49 (*PeiServices
)->GetHobList ((CONST EFI_PEI_SERVICES
**)PeiServices
, (VOID
**) &Hob
.Raw
);
50 while (!END_OF_HOB_LIST (Hob
)) {
51 if (Hob
.Header
->HobType
== EFI_HOB_TYPE_GUID_EXTENSION
&&
52 CompareGuid (&Hob
.Guid
->Name
, &gEfiMemoryTypeInformationGuid
)) {
53 MemoryData
= (EFI_MEMORY_TYPE_INFORMATION
*) (Hob
.Raw
+ sizeof (EFI_HOB_GENERIC_HEADER
) + sizeof (EFI_GUID
));
57 Hob
.Raw
= GET_NEXT_HOB (Hob
);
60 if (MemoryData
== NULL
) {
65 for (Index
= 0; MemoryData
[Index
].Type
!= EfiMaxMemoryType
; Index
++) {
67 // Accumulate default memory size requirements
69 TempPageNum
+= MemoryData
[Index
].NumberOfPages
;
72 return TempPageNum
* EFI_PAGE_SIZE
;
76 Get the mem size need to be reserved in PEI phase.
78 @param[in] PeiServices PEI Services table.
80 @return the mem size need to be reserved in PEI phase.
83 RetrieveRequiredMemorySize (
84 IN EFI_PEI_SERVICES
**PeiServices
89 Size
= GetMemorySizeInMemoryTypeInformation (PeiServices
);
90 return Size
+ PEI_ADDITIONAL_MEMORY_SIZE
;
94 Get the mem size need to be consumed and reserved in PEI phase.
96 @param[in] PeiServices PEI Services table.
97 @param[in] BootMode Current boot mode.
99 @return the mem size need to be consumed and reserved in PEI phase.
103 IN EFI_PEI_SERVICES
**PeiServices
,
110 if (BootMode
== BOOT_IN_RECOVERY_MODE
) {
111 return PcdGet32 (PcdPeiRecoveryMinMemSize
);
114 Size
= GetMemorySizeInMemoryTypeInformation (PeiServices
);
116 if (BootMode
== BOOT_ON_FLASH_UPDATE
) {
118 // Maybe more size when in CapsuleUpdate phase ?
120 MinSize
= PcdGet32 (PcdPeiMinMemSize
);
122 MinSize
= PcdGet32 (PcdPeiMinMemSize
);
125 return MinSize
+ Size
+ PEI_ADDITIONAL_MEMORY_SIZE
;
129 BIOS process FspBobList for Memory Resource Descriptor.
131 @param[in] FspHobList Pointer to the HOB data structure produced by FSP.
133 @return If platform process the FSP hob list successfully.
137 FspHobProcessForMemoryResource (
141 EFI_PEI_HOB_POINTERS Hob
;
142 UINT64 LowMemorySize
;
143 UINT64 FspMemorySize
;
144 EFI_PHYSICAL_ADDRESS FspMemoryBase
;
146 EFI_PHYSICAL_ADDRESS PeiMemBase
;
148 EFI_PHYSICAL_ADDRESS S3PeiMemBase
;
149 BOOLEAN FoundFspMemHob
;
151 EFI_BOOT_MODE BootMode
;
152 EFI_PEI_CAPSULE_PPI
*Capsule
;
154 UINTN CapsuleBufferLength
;
155 UINT64 RequiredMemSize
;
156 EFI_PEI_SERVICES
**PeiServices
;
158 PeiServices
= (EFI_PEI_SERVICES
**)GetPeiServicesTablePointer ();
160 PeiServicesGetBootMode (&BootMode
);
166 FoundFspMemHob
= FALSE
;
169 // Parse the hob list from fsp
170 // Report all the resource hob except the memory between 1M and 4G
172 Hob
.Raw
= (UINT8
*)(UINTN
)FspHobList
;
173 DEBUG((DEBUG_INFO
, "FspHobList - 0x%x\n", FspHobList
));
175 while ((Hob
.Raw
= GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
, Hob
.Raw
)) != NULL
) {
176 DEBUG((DEBUG_INFO
, "\nResourceType: 0x%x\n", Hob
.ResourceDescriptor
->ResourceType
));
177 if ((Hob
.ResourceDescriptor
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
) ||
178 (Hob
.ResourceDescriptor
->ResourceType
== EFI_RESOURCE_MEMORY_RESERVED
)) {
179 DEBUG((DEBUG_INFO
, "ResourceAttribute: 0x%x\n", Hob
.ResourceDescriptor
->ResourceAttribute
));
180 DEBUG((DEBUG_INFO
, "PhysicalStart: 0x%x\n", Hob
.ResourceDescriptor
->PhysicalStart
));
181 DEBUG((DEBUG_INFO
, "ResourceLength: 0x%x\n", Hob
.ResourceDescriptor
->ResourceLength
));
182 DEBUG((DEBUG_INFO
, "Owner: %g\n\n", &Hob
.ResourceDescriptor
->Owner
));
185 if ((Hob
.ResourceDescriptor
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
) // Found the low memory length below 4G
186 && (Hob
.ResourceDescriptor
->PhysicalStart
>= BASE_1MB
)
187 && (Hob
.ResourceDescriptor
->PhysicalStart
+ Hob
.ResourceDescriptor
->ResourceLength
<= BASE_4GB
)) {
188 LowMemorySize
+= Hob
.ResourceDescriptor
->ResourceLength
;
189 Hob
.Raw
= GET_NEXT_HOB (Hob
);
193 if ((Hob
.ResourceDescriptor
->ResourceType
== EFI_RESOURCE_MEMORY_RESERVED
) // Found the low memory length below 4G
194 && (Hob
.ResourceDescriptor
->PhysicalStart
>= BASE_1MB
)
195 && (Hob
.ResourceDescriptor
->PhysicalStart
+ Hob
.ResourceDescriptor
->ResourceLength
<= BASE_4GB
)
196 && (CompareGuid (&Hob
.ResourceDescriptor
->Owner
, &gFspReservedMemoryResourceHobGuid
))) {
197 FoundFspMemHob
= TRUE
;
198 FspMemoryBase
= Hob
.ResourceDescriptor
->PhysicalStart
;
199 FspMemorySize
= Hob
.ResourceDescriptor
->ResourceLength
;
200 DEBUG((DEBUG_INFO
, "Find fsp mem hob, base 0x%x, len 0x%x\n", FspMemoryBase
, FspMemorySize
));
204 // Report the resource hob
206 BuildResourceDescriptorHob (
207 Hob
.ResourceDescriptor
->ResourceType
,
208 Hob
.ResourceDescriptor
->ResourceAttribute
,
209 Hob
.ResourceDescriptor
->PhysicalStart
,
210 Hob
.ResourceDescriptor
->ResourceLength
213 Hob
.Raw
= GET_NEXT_HOB (Hob
);
216 if (!FoundFspMemHob
) {
217 DEBUG((DEBUG_INFO
, "Didn't find the fsp used memory information.\n"));
221 DEBUG((DEBUG_INFO
, "LowMemorySize: 0x%x.\n", LowMemorySize
));
222 DEBUG((DEBUG_INFO
, "FspMemoryBase: 0x%x.\n", FspMemoryBase
));
223 DEBUG((DEBUG_INFO
, "FspMemorySize: 0x%x.\n", FspMemorySize
));
225 if (BootMode
== BOOT_ON_S3_RESUME
) {
226 BuildResourceDescriptorHob (
227 EFI_RESOURCE_SYSTEM_MEMORY
,
229 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
230 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
231 // EFI_RESOURCE_ATTRIBUTE_TESTED |
232 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
233 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
234 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
235 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
243 Status
= GetS3MemoryInfo (&S3PeiMemSize
, &S3PeiMemBase
);
244 ASSERT_EFI_ERROR (Status
);
245 DEBUG((DEBUG_INFO
, "S3 memory %Xh - %Xh bytes\n", S3PeiMemBase
, S3PeiMemSize
));
248 // Make sure Stack and PeiMemory are not overlap
251 Status
= PeiServicesInstallPeiMemory (
255 ASSERT_EFI_ERROR (Status
);
257 PeiMemSize
= GetPeiMemSize (PeiServices
, BootMode
);
258 DEBUG((DEBUG_INFO
, "PEI memory size = %Xh bytes\n", PeiMemSize
));
264 CapsuleBuffer
= NULL
;
265 CapsuleBufferLength
= 0;
266 if (BootMode
== BOOT_ON_FLASH_UPDATE
) {
267 Status
= PeiServicesLocatePpi (
268 &gEfiPeiCapsulePpiGuid
,
273 ASSERT_EFI_ERROR (Status
);
275 if (Status
== EFI_SUCCESS
) {
277 // Make sure Stack and CapsuleBuffer are not overlap
279 CapsuleBuffer
= (VOID
*)(UINTN
)BASE_1MB
;
280 CapsuleBufferLength
= (UINTN
)(LowMemorySize
- PeiMemSize
);
282 // Call the Capsule PPI Coalesce function to coalesce the capsule data.
284 Status
= Capsule
->Coalesce (PeiServices
, &CapsuleBuffer
, &CapsuleBufferLength
);
288 RequiredMemSize
= RetrieveRequiredMemorySize (PeiServices
);
289 DEBUG((DEBUG_INFO
, "Required memory size = %Xh bytes\n", RequiredMemSize
));
292 // Report the main memory
294 BuildResourceDescriptorHob (
295 EFI_RESOURCE_SYSTEM_MEMORY
,
297 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
298 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
299 EFI_RESOURCE_ATTRIBUTE_TESTED
|
300 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
301 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
302 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
303 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
310 // Make sure Stack and CapsuleBuffer are not overlap
314 // Install efi memory
316 PeiMemBase
= BASE_1MB
+ LowMemorySize
- PeiMemSize
;
317 Status
= PeiServicesInstallPeiMemory (
319 PeiMemSize
- RequiredMemSize
321 ASSERT_EFI_ERROR (Status
);
323 if (Capsule
!= NULL
) {
324 Status
= Capsule
->CreateState (PeiServices
, CapsuleBuffer
, CapsuleBufferLength
);
334 @param[in] FspHobList Pointer to the HOB data structure produced by FSP.
342 EFI_PEI_HOB_POINTERS FspHob
;
344 FspHob
.Raw
= FspHobList
;
347 // Add all the HOBs from FSP binary to FSP wrapper
349 while (!END_OF_HOB_LIST (FspHob
)) {
350 if (FspHob
.Header
->HobType
== EFI_HOB_TYPE_GUID_EXTENSION
) {
352 // Skip FSP binary creates PcdDataBaseHobGuid
354 if (!CompareGuid(&FspHob
.Guid
->Name
, &gPcdDataBaseHobGuid
)) {
357 GET_GUID_HOB_DATA(FspHob
),
358 GET_GUID_HOB_DATA_SIZE(FspHob
)
362 FspHob
.Raw
= GET_NEXT_HOB (FspHob
);
367 BIOS process FspBobList for other data (not Memory Resource Descriptor).
369 @param[in] FspHobList Pointer to the HOB data structure produced by FSP.
371 @return If platform process the FSP hob list successfully.
375 FspHobProcessForOtherData (
379 ProcessFspHobList (FspHobList
);
385 BIOS process FspBobList.
387 @param[in] FspHobList Pointer to the HOB data structure produced by FSP.
389 @return If platform process the FSP hob list successfully.
399 Status
= FspHobProcessForMemoryResource (FspHobList
);
400 if (EFI_ERROR (Status
)) {
403 Status
= FspHobProcessForOtherData (FspHobList
);