]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFspPkg/Library/BaseFspPlatformLib/FspPlatformMemory.c
Add Dual-FSP support (MemoryInitUpd/SiliconInitUpd)
[mirror_edk2.git] / IntelFspPkg / Library / BaseFspPlatformLib / FspPlatformMemory.c
CommitLineData
c8ec22a2
JY
1/** @file\r
2\r
d5fb1edf 3 Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>\r
c8ec22a2
JY
4 This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php.\r
8\r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12**/\r
13\r
14#include <PiPei.h>\r
15#include <Library/BaseLib.h>\r
16#include <Library/BaseMemoryLib.h>\r
d5fb1edf 17#include <Library/MemoryAllocationLib.h>\r
c8ec22a2
JY
18#include <Library/DebugLib.h>\r
19#include <Library/PcdLib.h>\r
20#include <Library/HobLib.h>\r
21#include <Library/PeiServicesLib.h>\r
22#include <Library/FspCommonLib.h>\r
23#include <Guid/GuidHobFsp.h>\r
24#include <FspGlobalData.h>\r
25#include <FspApi.h>\r
26\r
27/**\r
28 Get system memory from HOB.\r
29\r
30 @param[in,out] LowMemoryLength less than 4G memory length\r
31 @param[in,out] HighMemoryLength greater than 4G memory length\r
32**/\r
33VOID\r
34EFIAPI\r
35FspGetSystemMemorySize (\r
36 IN OUT UINT64 *LowMemoryLength,\r
37 IN OUT UINT64 *HighMemoryLength\r
38 )\r
39{\r
40 EFI_PEI_HOB_POINTERS Hob;\r
41\r
42 *HighMemoryLength = 0;\r
43 *LowMemoryLength = SIZE_1MB;\r
44 //\r
45 // Get the HOB list for processing\r
46 //\r
47 Hob.Raw = GetHobList ();\r
48\r
49 //\r
50 // Collect memory ranges\r
51 //\r
52 while (!END_OF_HOB_LIST (Hob)) {\r
53 if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {\r
54 if (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) {\r
55 //\r
56 // Need memory above 1MB to be collected here\r
57 //\r
58 if (Hob.ResourceDescriptor->PhysicalStart >= BASE_1MB &&\r
59 Hob.ResourceDescriptor->PhysicalStart < (EFI_PHYSICAL_ADDRESS) BASE_4GB) {\r
60 *LowMemoryLength += (UINT64) (Hob.ResourceDescriptor->ResourceLength);\r
61 } else if (Hob.ResourceDescriptor->PhysicalStart >= (EFI_PHYSICAL_ADDRESS) BASE_4GB) {\r
62 *HighMemoryLength += (UINT64) (Hob.ResourceDescriptor->ResourceLength);\r
63 }\r
64 }\r
65 }\r
66 Hob.Raw = GET_NEXT_HOB (Hob);\r
67 }\r
68}\r
69\r
70/**\r
9da59186 71 Migrate BootLoader data before destroying CAR.\r
c8ec22a2
JY
72\r
73**/\r
74VOID\r
75EFIAPI\r
76FspMigrateTemporaryMemory (\r
77 VOID\r
78 )\r
79{\r
d5fb1edf
JY
80 FSP_INIT_RT_COMMON_BUFFER *FspInitRtBuffer;\r
81 UINT32 BootLoaderTempRamStart;\r
82 UINT32 BootLoaderTempRamEnd;\r
83 UINT32 BootLoaderTempRamSize;\r
84 UINT32 OffsetGap;\r
85 UINT32 FspParamPtr;\r
86 FSP_INIT_PARAMS *FspInitParams;\r
87 UINT32 *NewStackTop;\r
88 VOID *BootLoaderTempRamHob;\r
b2344187
JY
89 UINT32 UpdDataRgnPtr;\r
90 UINT32 MemoryInitUpdPtr;\r
91 UINT32 SiliconInitUpdPtr;\r
d5fb1edf
JY
92 VOID *PlatformDataPtr;\r
93 UINT8 ApiMode;\r
94 \r
95 ApiMode = GetFspApiCallingMode ();\r
c8ec22a2
JY
96\r
97 //\r
9da59186 98 // Get the temporary memory range used by the BootLoader\r
c8ec22a2
JY
99 //\r
100 BootLoaderTempRamStart = PcdGet32(PcdTemporaryRamBase);\r
101 BootLoaderTempRamSize = PcdGet32(PcdTemporaryRamSize) - PcdGet32(PcdFspTemporaryRamSize);\r
102 BootLoaderTempRamEnd = BootLoaderTempRamStart + BootLoaderTempRamSize;\r
103\r
104 //\r
105 // Build a Boot Loader Temporary Memory GUID HOB\r
106 //\r
d5fb1edf 107 if (ApiMode == 0) {\r
95c95ac0 108 BootLoaderTempRamHob = BuildGuidHob (&gFspBootLoaderTemporaryMemoryGuid, BootLoaderTempRamSize);\r
d5fb1edf 109 } else {\r
b2344187 110 BootLoaderTempRamHob = (VOID *)AllocatePages (EFI_SIZE_TO_PAGES (BootLoaderTempRamSize));\r
d5fb1edf 111 }\r
95c95ac0 112 ASSERT(BootLoaderTempRamHob != NULL);\r
d5fb1edf 113\r
c8ec22a2
JY
114 CopyMem (BootLoaderTempRamHob, (VOID *)BootLoaderTempRamStart, BootLoaderTempRamSize);\r
115 OffsetGap = (UINT32)BootLoaderTempRamHob - BootLoaderTempRamStart;\r
116\r
117 //\r
118 // Set a new stack frame for the continuation function\r
119 //\r
d5fb1edf
JY
120 if (ApiMode == 0) {\r
121 FspInitParams = (FSP_INIT_PARAMS *)GetFspApiParameter ();\r
122 FspInitRtBuffer = (FSP_INIT_RT_COMMON_BUFFER *)FspInitParams->RtBufferPtr;\r
123 NewStackTop = (UINT32 *)FspInitRtBuffer->StackTop - 1;\r
124 SetFspCoreStackPointer (NewStackTop);\r
125 }\r
c8ec22a2
JY
126\r
127 //\r
128 // Fix the FspInit Parameter Pointers to the new location.\r
129 //\r
130 FspParamPtr = GetFspApiParameter ();\r
131 if (FspParamPtr >= BootLoaderTempRamStart && FspParamPtr < BootLoaderTempRamEnd) {\r
132 SetFspApiParameter(FspParamPtr + OffsetGap);\r
133 }\r
134\r
135 FspInitParams = (FSP_INIT_PARAMS *)GetFspApiParameter ();\r
136 if ((UINT32)(FspInitParams->RtBufferPtr) >= BootLoaderTempRamStart &&\r
137 (UINT32)(FspInitParams->RtBufferPtr) < BootLoaderTempRamEnd) {\r
138 FspInitParams->RtBufferPtr = (VOID *)((UINT32)(FspInitParams->RtBufferPtr) + OffsetGap);\r
139 }\r
140\r
141 if ((UINT32)(FspInitParams->NvsBufferPtr) >= BootLoaderTempRamStart &&\r
142 (UINT32)(FspInitParams->NvsBufferPtr) < BootLoaderTempRamEnd) {\r
143 FspInitParams->NvsBufferPtr = (VOID *)((UINT32)(FspInitParams->NvsBufferPtr) + OffsetGap);\r
144 }\r
145\r
146 if ((UINT32)(((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr) >= BootLoaderTempRamStart &&\r
147 (UINT32)(((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr) < BootLoaderTempRamEnd) {\r
148 ((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr = \\r
149 (VOID *)((UINT32)(((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr) + OffsetGap);\r
150 }\r
151\r
152 //\r
153 // Update UPD pointer in FSP Global Data\r
154 //\r
b2344187
JY
155 if (ApiMode == 0) {\r
156 UpdDataRgnPtr = (UINT32)((UINT32 *)GetFspUpdDataPointer ());\r
157 if (UpdDataRgnPtr >= BootLoaderTempRamStart && UpdDataRgnPtr < BootLoaderTempRamEnd) {\r
158 MemoryInitUpdPtr = (UINT32)((UINT32 *)GetFspMemoryInitUpdDataPointer ());\r
159 SiliconInitUpdPtr = (UINT32)((UINT32 *)GetFspSiliconInitUpdDataPointer ());\r
160 SetFspUpdDataPointer ((VOID *)(UpdDataRgnPtr + OffsetGap));\r
161 SetFspMemoryInitUpdDataPointer ((VOID *)(MemoryInitUpdPtr + OffsetGap));\r
162 SetFspSiliconInitUpdDataPointer ((VOID *)(SiliconInitUpdPtr + OffsetGap));\r
163 }\r
164 } else {\r
165 MemoryInitUpdPtr = (UINT32)((UINT32 *)GetFspMemoryInitUpdDataPointer ());\r
166 if (MemoryInitUpdPtr >= BootLoaderTempRamStart && MemoryInitUpdPtr < BootLoaderTempRamEnd) {\r
167 SetFspMemoryInitUpdDataPointer ((VOID *)(MemoryInitUpdPtr + OffsetGap));\r
168 }\r
c8ec22a2
JY
169 }\r
170\r
171 //\r
172 // Update Platform data pointer in FSP Global Data\r
173 //\r
174 PlatformDataPtr = GetFspPlatformDataPointer ();\r
175 if (((UINT32)PlatformDataPtr >= BootLoaderTempRamStart) &&\r
176 ((UINT32)PlatformDataPtr < BootLoaderTempRamEnd)) {\r
177 SetFspPlatformDataPointer ((UINT8 *)PlatformDataPtr + OffsetGap);\r
178 }\r
c8ec22a2 179}\r