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