Update IntelFspWrapperPkg according to FSP1.1.
[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 FspMemoryInitParams.HobListPtr = &FspHobList;
173
174 DEBUG ((DEBUG_INFO, "FspMemoryInitParams - 0x%x\n", &FspMemoryInitParams));
175 DEBUG ((DEBUG_INFO, " NvsBufferPtr - 0x%x\n", FspMemoryInitParams.NvsBufferPtr));
176 DEBUG ((DEBUG_INFO, " RtBufferPtr - 0x%x\n", FspMemoryInitParams.RtBufferPtr));
177 DEBUG ((DEBUG_INFO, " StackTop - 0x%x\n", FspRtBuffer.StackTop));
178 DEBUG ((DEBUG_INFO, " BootMode - 0x%x\n", FspRtBuffer.BootMode));
179 DEBUG ((DEBUG_INFO, " UpdDataRgnPtr - 0x%x\n", FspRtBuffer.UpdDataRgnPtr));
180 DEBUG ((DEBUG_INFO, " HobListPtr - 0x%x\n", FspMemoryInitParams.HobListPtr));
181
182 Status = CallFspMemoryInit (FspHeader, &FspMemoryInitParams);
183 DEBUG((DEBUG_INFO, "FspMemoryInit status: 0x%x\n", Status));
184 ASSERT_EFI_ERROR (Status);
185
186 DEBUG ((DEBUG_INFO, " HobListPtr (returned) - 0x%x\n", FspHobList));
187
188 FspHobProcessForMemoryResource (FspHobList);
189
190 //
191 // FspHobList is not complete at this moment.
192 // Save FspHobList pointer to hob, so that it can be got later
193 //
194 HobData = BuildGuidHob (
195 &gFspInitDonePpiGuid,
196 sizeof (VOID *)
197 );
198 ASSERT (HobData != NULL);
199 CopyMem (HobData, &FspHobList, sizeof (FspHobList));
200
201 return Status;
202 }
203
204 /**
205 TemporaryRamDone() disables the use of Temporary RAM. If present, this service is invoked
206 by the PEI Foundation after the EFI_PEI_PERMANANT_MEMORY_INSTALLED_PPI is installed.
207
208 @retval EFI_SUCCESS Use of Temporary RAM was disabled.
209 @retval EFI_INVALID_PARAMETER Temporary RAM could not be disabled.
210
211 **/
212 EFI_STATUS
213 EFIAPI
214 PeiTemporaryRamDone (
215 VOID
216 )
217 {
218 EFI_STATUS Status;
219 VOID *TempRamExitParam;
220 FSP_INFO_HEADER *FspHeader;
221
222 FspHeader = FspFindFspHeader (PcdGet32 (PcdFlashFvFspBase));
223 if (FspHeader == NULL) {
224 return EFI_DEVICE_ERROR;
225 }
226
227 DEBUG ((DEBUG_INFO, "PeiTemporaryRamDone enter\n"));
228
229 TempRamExitParam = GetTempRamExitParam ();
230 Status = CallTempRamExit (FspHeader, TempRamExitParam);
231 DEBUG((DEBUG_INFO, "TempRamExit status: 0x%x\n", Status));
232 ASSERT_EFI_ERROR (Status);
233
234 return EFI_SUCCESS;
235 }
236
237 /**
238 This function is called after PEI core discover memory and finish migration.
239
240 @param[in] PeiServices Pointer to PEI Services Table.
241 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
242 caused this function to execute.
243 @param[in] Ppi Pointer to the PPI data associated with this function.
244
245 @retval EFI_STATUS Always return EFI_SUCCESS
246 **/
247 EFI_STATUS
248 EFIAPI
249 PeiMemoryDiscoveredNotify (
250 IN EFI_PEI_SERVICES **PeiServices,
251 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
252 IN VOID *Ppi
253 )
254 {
255 EFI_STATUS Status;
256 VOID *FspSiliconInitParam;
257 FSP_INFO_HEADER *FspHeader;
258 VOID *FspHobList;
259 EFI_HOB_GUID_TYPE *GuidHob;
260
261 FspHeader = FspFindFspHeader (PcdGet32 (PcdFlashFvFspBase));
262 if (FspHeader == NULL) {
263 return EFI_DEVICE_ERROR;
264 }
265
266 DEBUG ((DEBUG_INFO, "PeiMemoryDiscoveredNotify enter\n"));
267
268 FspSiliconInitParam = GetFspSiliconInitParam ();
269 Status = CallFspSiliconInit (FspHeader, FspSiliconInitParam);
270 DEBUG((DEBUG_ERROR, "FspSiliconInit status: 0x%x\n", Status));
271 ASSERT_EFI_ERROR (Status);
272
273 //
274 // Now FspHobList complete, process it
275 //
276 GuidHob = GetFirstGuidHob (&gFspInitDonePpiGuid);
277 ASSERT (GuidHob != NULL);
278 FspHobList = *(VOID **)GET_GUID_HOB_DATA (GuidHob);
279 DEBUG ((DEBUG_INFO, "FspHobList - 0x%x\n", FspHobList));
280 FspHobProcessForOtherData (FspHobList);
281
282 //
283 // Install FspInitDonePpi so that any other driver can consume this info.
284 //
285 Status = PeiServicesInstallPpi (&mPeiFspInitDonePpiV2);
286 ASSERT_EFI_ERROR(Status);
287
288 return EFI_SUCCESS;
289 }
290
291 /**
292 Do FSP initialization based on FspApi version 2.
293
294 @param[in] FspHeader FSP header pointer.
295
296 @return FSP initialization status.
297 **/
298 EFI_STATUS
299 PeiFspInitV2 (
300 IN FSP_INFO_HEADER *FspHeader
301 )
302 {
303 EFI_STATUS Status;
304 EFI_BOOT_MODE BootMode;
305
306 Status = PeiFspMemoryInit (FspHeader);
307 ASSERT_EFI_ERROR (Status);
308
309 //
310 // Install TempramDonePpi to run TempRamExit
311 //
312 Status = PeiServicesInstallPpi (&mPeiTemporaryRamDoneDesc);
313 ASSERT_EFI_ERROR(Status);
314
315 //
316 // Register MemoryDiscovered Nofity to run FspSiliconInit
317 //
318 Status = PeiServicesNotifyPpi (&mPeiMemoryDiscoveredNotifyDesc);
319 ASSERT_EFI_ERROR (Status);
320
321 //
322 // Register EndOfPei Notify for S3 to run FspNotifyPhase
323 //
324 PeiServicesGetBootMode (&BootMode);
325 if (BootMode == BOOT_ON_S3_RESUME) {
326 Status = PeiServicesNotifyPpi (&mS3EndOfPeiNotifyDesc);
327 ASSERT_EFI_ERROR (Status);
328 }
329
330 return EFI_SUCCESS;
331 }