Fsp1.1 update.
[mirror_edk2.git] / IntelFspWrapperPkg / FspInitPei / FspInitPeiV2.c
CommitLineData
d8043ce9
JY
1/** @file\r
2 In FSP API V2 mode, it will be invoked only once. It will call FspMemoryInit API,\r
3 register TemporaryRamDonePpi to call TempRamExit API, and register MemoryDiscoveredPpi\r
4 notify to call FspSiliconInit API.\r
5\r
6 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
7 This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php.\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17\r
18#include "FspInitPei.h"\r
19\r
20/**\r
21 Return Hob list produced by FSP.\r
22\r
23 @param[in] PeiServices The pointer to the PEI Services Table.\r
24 @param[in] This The pointer to this instance of this PPI.\r
25 @param[out] FspHobList The pointer to Hob list produced by FSP.\r
26\r
27 @return EFI_SUCCESS FReturn Hob list produced by FSP successfully.\r
28**/\r
29EFI_STATUS\r
30EFIAPI\r
31FspInitDoneGetFspHobListV2 (\r
32 IN CONST EFI_PEI_SERVICES **PeiServices,\r
33 IN FSP_INIT_DONE_PPI *This,\r
34 OUT VOID **FspHobList\r
35 );\r
36\r
37FSP_INIT_DONE_PPI mFspInitDonePpiV2 = {\r
38 FspInitDoneGetFspHobListV2\r
39};\r
40\r
41EFI_PEI_PPI_DESCRIPTOR mPeiFspInitDonePpiV2 = {\r
42 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,\r
43 &gFspInitDonePpiGuid,\r
44 &mFspInitDonePpiV2\r
45};\r
46\r
47/**\r
48 This function is called after PEI core discover memory and finish migration.\r
49\r
50 @param[in] PeiServices Pointer to PEI Services Table.\r
51 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that\r
52 caused this function to execute.\r
53 @param[in] Ppi Pointer to the PPI data associated with this function.\r
54\r
55 @retval EFI_STATUS Always return EFI_SUCCESS\r
56**/\r
57EFI_STATUS\r
58EFIAPI\r
59PeiMemoryDiscoveredNotify (\r
60 IN EFI_PEI_SERVICES **PeiServices,\r
61 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
62 IN VOID *Ppi\r
63 );\r
64\r
65EFI_PEI_NOTIFY_DESCRIPTOR mPeiMemoryDiscoveredNotifyDesc = {\r
66 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
67 &gEfiPeiMemoryDiscoveredPpiGuid,\r
68 PeiMemoryDiscoveredNotify\r
69};\r
70\r
71/**\r
72 TemporaryRamDone() disables the use of Temporary RAM. If present, this service is invoked\r
73 by the PEI Foundation after the EFI_PEI_PERMANANT_MEMORY_INSTALLED_PPI is installed.\r
74\r
75 @retval EFI_SUCCESS Use of Temporary RAM was disabled.\r
76 @retval EFI_INVALID_PARAMETER Temporary RAM could not be disabled.\r
77\r
78**/\r
79EFI_STATUS\r
80EFIAPI\r
81PeiTemporaryRamDone (\r
82 VOID\r
83 );\r
84\r
85EFI_PEI_TEMPORARY_RAM_DONE_PPI mPeiTemporaryRamDonePpi = {\r
86 PeiTemporaryRamDone\r
87};\r
88\r
89EFI_PEI_PPI_DESCRIPTOR mPeiTemporaryRamDoneDesc = {\r
90 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
91 &gEfiTemporaryRamDonePpiGuid,\r
92 &mPeiTemporaryRamDonePpi\r
93};\r
94\r
95/**\r
96 Return Hob list produced by FSP.\r
97\r
98 @param[in] PeiServices The pointer to the PEI Services Table.\r
99 @param[in] This The pointer to this instance of this PPI.\r
100 @param[out] FspHobList The pointer to Hob list produced by FSP.\r
101\r
102 @return EFI_SUCCESS FReturn Hob list produced by FSP successfully.\r
103**/\r
104EFI_STATUS\r
105EFIAPI\r
106FspInitDoneGetFspHobListV2 (\r
107 IN CONST EFI_PEI_SERVICES **PeiServices,\r
108 IN FSP_INIT_DONE_PPI *This,\r
109 OUT VOID **FspHobList\r
110 )\r
111{\r
112 EFI_HOB_GUID_TYPE *GuidHob;\r
113\r
114 GuidHob = GetFirstGuidHob (&gFspInitDonePpiGuid);\r
115 if (GuidHob != NULL) {\r
116 *FspHobList = *(VOID **)GET_GUID_HOB_DATA (GuidHob);\r
117 return EFI_SUCCESS;\r
118 } else {\r
119 return EFI_NOT_FOUND;\r
120 }\r
121}\r
122\r
123/**\r
124 Call FspMemoryInit API.\r
125\r
126 @param[in] FspHeader FSP header pointer.\r
127\r
128 @return Status returned by FspMemoryInit API.\r
129**/\r
130EFI_STATUS\r
131PeiFspMemoryInit (\r
132 IN FSP_INFO_HEADER *FspHeader\r
133 )\r
134{\r
135 FSP_MEMORY_INIT_PARAMS FspMemoryInitParams;\r
136 FSP_INIT_RT_COMMON_BUFFER FspRtBuffer;\r
137 UINT8 FspUpdRgn[FixedPcdGet32 (PcdMaxUpdRegionSize)];\r
138 UINT32 UpdRegionSize;\r
139 EFI_BOOT_MODE BootMode;\r
140 UINT64 StackSize;\r
141 EFI_PHYSICAL_ADDRESS StackBase;\r
142 EFI_STATUS Status;\r
143 VOID *FspHobList;\r
144 VOID *HobData;\r
145\r
146 DEBUG ((DEBUG_INFO, "PeiFspMemoryInit enter\n"));\r
147\r
148 PeiServicesGetBootMode (&BootMode);\r
149 DEBUG ((DEBUG_INFO, "BootMode - 0x%x\n", BootMode));\r
150\r
151 GetStackInfo (BootMode, FALSE, &StackBase, &StackSize);\r
152 DEBUG ((DEBUG_INFO, "StackBase - 0x%x\n", StackBase));\r
153 DEBUG ((DEBUG_INFO, "StackSize - 0x%x\n", StackSize));\r
154\r
155 ZeroMem (&FspRtBuffer, sizeof(FspRtBuffer));\r
156 FspRtBuffer.StackTop = (UINT32 *)(UINTN)(StackBase + StackSize);\r
157\r
158 FspRtBuffer.BootMode = BootMode;\r
159\r
160 /* Platform override any UPD configs */\r
161 UpdRegionSize = GetUpdRegionSize();\r
162 DEBUG ((DEBUG_INFO, "UpdRegionSize - 0x%x\n", UpdRegionSize));\r
163 DEBUG ((DEBUG_INFO, "sizeof(FspUpdRgn) - 0x%x\n", sizeof(FspUpdRgn)));\r
164 ASSERT(sizeof(FspUpdRgn) >= UpdRegionSize);\r
165 ZeroMem (FspUpdRgn, UpdRegionSize);\r
166 FspRtBuffer.UpdDataRgnPtr = UpdateFspUpdConfigs (FspUpdRgn);\r
167\r
168 ZeroMem (&FspMemoryInitParams, sizeof(FspMemoryInitParams));\r
169 FspMemoryInitParams.NvsBufferPtr = GetNvsBuffer ();\r
170 DEBUG ((DEBUG_INFO, "NvsBufferPtr - 0x%x\n", FspMemoryInitParams.NvsBufferPtr));\r
171 FspMemoryInitParams.RtBufferPtr = (VOID *)&FspRtBuffer;\r
95c95ac0 172 FspHobList = NULL;\r
d8043ce9
JY
173 FspMemoryInitParams.HobListPtr = &FspHobList;\r
174\r
175 DEBUG ((DEBUG_INFO, "FspMemoryInitParams - 0x%x\n", &FspMemoryInitParams));\r
176 DEBUG ((DEBUG_INFO, " NvsBufferPtr - 0x%x\n", FspMemoryInitParams.NvsBufferPtr));\r
177 DEBUG ((DEBUG_INFO, " RtBufferPtr - 0x%x\n", FspMemoryInitParams.RtBufferPtr));\r
178 DEBUG ((DEBUG_INFO, " StackTop - 0x%x\n", FspRtBuffer.StackTop));\r
179 DEBUG ((DEBUG_INFO, " BootMode - 0x%x\n", FspRtBuffer.BootMode));\r
180 DEBUG ((DEBUG_INFO, " UpdDataRgnPtr - 0x%x\n", FspRtBuffer.UpdDataRgnPtr));\r
181 DEBUG ((DEBUG_INFO, " HobListPtr - 0x%x\n", FspMemoryInitParams.HobListPtr));\r
182\r
183 Status = CallFspMemoryInit (FspHeader, &FspMemoryInitParams);\r
184 DEBUG((DEBUG_INFO, "FspMemoryInit status: 0x%x\n", Status));\r
185 ASSERT_EFI_ERROR (Status);\r
186\r
187 DEBUG ((DEBUG_INFO, " HobListPtr (returned) - 0x%x\n", FspHobList));\r
95c95ac0 188 ASSERT (FspHobList != NULL);\r
d8043ce9
JY
189\r
190 FspHobProcessForMemoryResource (FspHobList);\r
191\r
192 //\r
193 // FspHobList is not complete at this moment.\r
194 // Save FspHobList pointer to hob, so that it can be got later\r
195 //\r
196 HobData = BuildGuidHob (\r
197 &gFspInitDonePpiGuid,\r
198 sizeof (VOID *)\r
199 );\r
200 ASSERT (HobData != NULL);\r
201 CopyMem (HobData, &FspHobList, sizeof (FspHobList));\r
202\r
203 return Status;\r
204}\r
205\r
206/**\r
207 TemporaryRamDone() disables the use of Temporary RAM. If present, this service is invoked\r
208 by the PEI Foundation after the EFI_PEI_PERMANANT_MEMORY_INSTALLED_PPI is installed.\r
209\r
210 @retval EFI_SUCCESS Use of Temporary RAM was disabled.\r
211 @retval EFI_INVALID_PARAMETER Temporary RAM could not be disabled.\r
212\r
213**/\r
214EFI_STATUS\r
215EFIAPI\r
216PeiTemporaryRamDone (\r
217 VOID\r
218 )\r
219{\r
220 EFI_STATUS Status;\r
221 VOID *TempRamExitParam;\r
222 FSP_INFO_HEADER *FspHeader;\r
223\r
224 FspHeader = FspFindFspHeader (PcdGet32 (PcdFlashFvFspBase));\r
225 if (FspHeader == NULL) {\r
226 return EFI_DEVICE_ERROR;\r
227 }\r
228 \r
229 DEBUG ((DEBUG_INFO, "PeiTemporaryRamDone enter\n"));\r
230 \r
231 TempRamExitParam = GetTempRamExitParam ();\r
232 Status = CallTempRamExit (FspHeader, TempRamExitParam);\r
233 DEBUG((DEBUG_INFO, "TempRamExit status: 0x%x\n", Status));\r
234 ASSERT_EFI_ERROR (Status);\r
235\r
236 return EFI_SUCCESS;\r
237}\r
238\r
239/**\r
240 This function is called after PEI core discover memory and finish migration.\r
241\r
242 @param[in] PeiServices Pointer to PEI Services Table.\r
243 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that\r
244 caused this function to execute.\r
245 @param[in] Ppi Pointer to the PPI data associated with this function.\r
246\r
247 @retval EFI_STATUS Always return EFI_SUCCESS\r
248**/\r
249EFI_STATUS\r
250EFIAPI\r
251PeiMemoryDiscoveredNotify (\r
252 IN EFI_PEI_SERVICES **PeiServices,\r
253 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
254 IN VOID *Ppi\r
255 )\r
256{\r
257 EFI_STATUS Status;\r
258 VOID *FspSiliconInitParam;\r
259 FSP_INFO_HEADER *FspHeader;\r
260 VOID *FspHobList;\r
261 EFI_HOB_GUID_TYPE *GuidHob;\r
262\r
263 FspHeader = FspFindFspHeader (PcdGet32 (PcdFlashFvFspBase));\r
264 if (FspHeader == NULL) {\r
265 return EFI_DEVICE_ERROR;\r
266 }\r
267 \r
268 DEBUG ((DEBUG_INFO, "PeiMemoryDiscoveredNotify enter\n"));\r
269 \r
270 FspSiliconInitParam = GetFspSiliconInitParam ();\r
271 Status = CallFspSiliconInit (FspHeader, FspSiliconInitParam);\r
272 DEBUG((DEBUG_ERROR, "FspSiliconInit status: 0x%x\n", Status));\r
273 ASSERT_EFI_ERROR (Status);\r
274 \r
275 //\r
276 // Now FspHobList complete, process it\r
277 //\r
278 GuidHob = GetFirstGuidHob (&gFspInitDonePpiGuid);\r
279 ASSERT (GuidHob != NULL);\r
280 FspHobList = *(VOID **)GET_GUID_HOB_DATA (GuidHob);\r
281 DEBUG ((DEBUG_INFO, "FspHobList - 0x%x\n", FspHobList));\r
282 FspHobProcessForOtherData (FspHobList);\r
283\r
284 //\r
285 // Install FspInitDonePpi so that any other driver can consume this info.\r
286 //\r
287 Status = PeiServicesInstallPpi (&mPeiFspInitDonePpiV2);\r
288 ASSERT_EFI_ERROR(Status);\r
289\r
290 return EFI_SUCCESS;\r
291}\r
292\r
293/**\r
294 Do FSP initialization based on FspApi version 2.\r
295\r
296 @param[in] FspHeader FSP header pointer.\r
297\r
298 @return FSP initialization status.\r
299**/\r
300EFI_STATUS\r
301PeiFspInitV2 (\r
302 IN FSP_INFO_HEADER *FspHeader\r
303 )\r
304{\r
305 EFI_STATUS Status;\r
306 EFI_BOOT_MODE BootMode;\r
307\r
308 Status = PeiFspMemoryInit (FspHeader);\r
309 ASSERT_EFI_ERROR (Status);\r
310\r
311 //\r
312 // Install TempramDonePpi to run TempRamExit\r
313 //\r
314 Status = PeiServicesInstallPpi (&mPeiTemporaryRamDoneDesc);\r
315 ASSERT_EFI_ERROR(Status);\r
316\r
317 //\r
318 // Register MemoryDiscovered Nofity to run FspSiliconInit\r
319 //\r
320 Status = PeiServicesNotifyPpi (&mPeiMemoryDiscoveredNotifyDesc);\r
321 ASSERT_EFI_ERROR (Status);\r
322 \r
323 //\r
324 // Register EndOfPei Notify for S3 to run FspNotifyPhase\r
325 //\r
326 PeiServicesGetBootMode (&BootMode);\r
327 if (BootMode == BOOT_ON_S3_RESUME) {\r
328 Status = PeiServicesNotifyPpi (&mS3EndOfPeiNotifyDesc);\r
329 ASSERT_EFI_ERROR (Status);\r
330 }\r
331\r
332 return EFI_SUCCESS;\r
333}