]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFsp2WrapperPkg/FspsWrapperPeim/FspsWrapperPeim.c
IntelFsp2WrapperPkg: Remove unused header files from Fspm and Fsps WrapperPeim
[mirror_edk2.git] / IntelFsp2WrapperPkg / FspsWrapperPeim / FspsWrapperPeim.c
1 /** @file
2 This 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) 2014 - 2016, 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 #include <PiPei.h>
18
19 #include <Library/PeimEntryPoint.h>
20 #include <Library/PeiServicesLib.h>
21 #include <Library/PeiServicesTablePointerLib.h>
22 #include <Library/BaseLib.h>
23 #include <Library/DebugLib.h>
24 #include <Library/BaseMemoryLib.h>
25 #include <Library/HobLib.h>
26 #include <Library/PcdLib.h>
27 #include <Library/MemoryAllocationLib.h>
28 #include <Library/FspWrapperPlatformLib.h>
29 #include <Library/FspWrapperHobProcessLib.h>
30 #include <Library/TimerLib.h>
31 #include <Library/PerformanceLib.h>
32 #include <Library/FspWrapperApiLib.h>
33
34 #include <Ppi/FspSiliconInitDone.h>
35 #include <Ppi/EndOfPeiPhase.h>
36 #include <Ppi/MemoryDiscovered.h>
37 #include <Ppi/TemporaryRamDone.h>
38 #include <Ppi/SecPlatformInformation.h>
39 #include <Library/FspWrapperApiTestLib.h>
40 #include <FspEas.h>
41
42 extern EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc;
43 extern EFI_GUID gFspHobGuid;
44
45 /**
46 This function handles S3 resume task at the end of PEI
47
48 @param[in] PeiServices Pointer to PEI Services Table.
49 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
50 caused this function to execute.
51 @param[in] Ppi Pointer to the PPI data associated with this function.
52
53 @retval EFI_STATUS Always return EFI_SUCCESS
54 **/
55 EFI_STATUS
56 EFIAPI
57 S3EndOfPeiNotify(
58 IN EFI_PEI_SERVICES **PeiServices,
59 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
60 IN VOID *Ppi
61 );
62
63 EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc = {
64 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
65 &gEfiEndOfPeiSignalPpiGuid,
66 S3EndOfPeiNotify
67 };
68
69 /**
70 This function handles S3 resume task at the end of PEI
71
72 @param[in] PeiServices Pointer to PEI Services Table.
73 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
74 caused this function to execute.
75 @param[in] Ppi Pointer to the PPI data associated with this function.
76
77 @retval EFI_STATUS Always return EFI_SUCCESS
78 **/
79 EFI_STATUS
80 EFIAPI
81 S3EndOfPeiNotify(
82 IN EFI_PEI_SERVICES **PeiServices,
83 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
84 IN VOID *Ppi
85 )
86 {
87 NOTIFY_PHASE_PARAMS NotifyPhaseParams;
88 EFI_STATUS Status;
89
90 DEBUG((DEBUG_INFO, "S3EndOfPeiNotify enter\n"));
91
92 NotifyPhaseParams.Phase = EnumInitPhaseAfterPciEnumeration;
93 Status = CallFspNotifyPhase (&NotifyPhaseParams);
94 DEBUG((DEBUG_INFO, "FSP S3NotifyPhase AfterPciEnumeration status: 0x%x\n", Status));
95
96 //
97 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
98 //
99 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {
100 DEBUG((DEBUG_INFO, "FSP S3NotifyPhase AfterPciEnumeration requested reset 0x%x\n", Status));
101 CallFspWrapperResetSystem ((UINT32)Status);
102 }
103
104 NotifyPhaseParams.Phase = EnumInitPhaseReadyToBoot;
105 Status = CallFspNotifyPhase (&NotifyPhaseParams);
106 DEBUG((DEBUG_INFO, "FSP S3NotifyPhase ReadyToBoot status: 0x%x\n", Status));
107
108 //
109 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
110 //
111 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {
112 DEBUG((DEBUG_INFO, "FSP S3NotifyPhase ReadyToBoot requested reset 0x%x\n", Status));
113 CallFspWrapperResetSystem ((UINT32)Status);
114 }
115
116 NotifyPhaseParams.Phase = EnumInitPhaseEndOfFirmware;
117 Status = CallFspNotifyPhase (&NotifyPhaseParams);
118 DEBUG((DEBUG_INFO, "FSP S3NotifyPhase EndOfFirmware status: 0x%x\n", Status));
119
120 //
121 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
122 //
123 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {
124 DEBUG((DEBUG_INFO, "FSP S3NotifyPhase EndOfFirmware requested reset 0x%x\n", Status));
125 CallFspWrapperResetSystem ((UINT32)Status);
126 }
127
128 return EFI_SUCCESS;
129 }
130
131 /**
132 Return Hob list produced by FSP.
133
134 @param[in] PeiServices The pointer to the PEI Services Table.
135 @param[in] This The pointer to this instance of this PPI.
136 @param[out] FspHobList The pointer to Hob list produced by FSP.
137
138 @return EFI_SUCCESS FReturn Hob list produced by FSP successfully.
139 **/
140 EFI_STATUS
141 EFIAPI
142 FspSiliconInitDoneGetFspHobList (
143 IN CONST EFI_PEI_SERVICES **PeiServices,
144 IN FSP_SILICON_INIT_DONE_PPI *This,
145 OUT VOID **FspHobList
146 );
147
148 FSP_SILICON_INIT_DONE_PPI mFspSiliconInitDonePpi = {
149 FspSiliconInitDoneGetFspHobList
150 };
151
152 EFI_PEI_PPI_DESCRIPTOR mPeiFspSiliconInitDonePpi = {
153 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
154 &gFspSiliconInitDonePpiGuid,
155 &mFspSiliconInitDonePpi
156 };
157
158 /**
159 Return Hob list produced by FSP.
160
161 @param[in] PeiServices The pointer to the PEI Services Table.
162 @param[in] This The pointer to this instance of this PPI.
163 @param[out] FspHobList The pointer to Hob list produced by FSP.
164
165 @return EFI_SUCCESS FReturn Hob list produced by FSP successfully.
166 **/
167 EFI_STATUS
168 EFIAPI
169 FspSiliconInitDoneGetFspHobList (
170 IN CONST EFI_PEI_SERVICES **PeiServices,
171 IN FSP_SILICON_INIT_DONE_PPI *This,
172 OUT VOID **FspHobList
173 )
174 {
175 EFI_HOB_GUID_TYPE *GuidHob;
176
177 GuidHob = GetFirstGuidHob (&gFspHobGuid);
178 if (GuidHob != NULL) {
179 *FspHobList = *(VOID **)GET_GUID_HOB_DATA(GuidHob);
180 return EFI_SUCCESS;
181 } else {
182 return EFI_NOT_FOUND;
183 }
184 }
185
186 /**
187 This function is called after PEI core discover memory and finish migration.
188
189 @param[in] PeiServices Pointer to PEI Services Table.
190 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
191 caused this function to execute.
192 @param[in] Ppi Pointer to the PPI data associated with this function.
193
194 @retval EFI_STATUS Always return EFI_SUCCESS
195 **/
196 EFI_STATUS
197 EFIAPI
198 PeiMemoryDiscoveredNotify (
199 IN EFI_PEI_SERVICES **PeiServices,
200 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
201 IN VOID *Ppi
202 );
203
204 EFI_PEI_NOTIFY_DESCRIPTOR mPeiMemoryDiscoveredNotifyDesc = {
205 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
206 &gEfiPeiMemoryDiscoveredPpiGuid,
207 PeiMemoryDiscoveredNotify
208 };
209
210 /**
211 This function is called after PEI core discover memory and finish migration.
212
213 @param[in] PeiServices Pointer to PEI Services Table.
214 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
215 caused this function to execute.
216 @param[in] Ppi Pointer to the PPI data associated with this function.
217
218 @retval EFI_STATUS Always return EFI_SUCCESS
219 **/
220 EFI_STATUS
221 EFIAPI
222 PeiMemoryDiscoveredNotify (
223 IN EFI_PEI_SERVICES **PeiServices,
224 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
225 IN VOID *Ppi
226 )
227 {
228 FSP_INFO_HEADER *FspsHeaderPtr;
229 UINT64 TimeStampCounterStart;
230 EFI_STATUS Status;
231 VOID *FspHobListPtr;
232 EFI_HOB_GUID_TYPE *GuidHob;
233 FSPS_UPD_COMMON *FspsUpdDataPtr;
234 UINTN *SourceData;
235
236
237 DEBUG ((DEBUG_INFO, "PeiMemoryDiscoveredNotify enter\n"));
238
239 //
240 // Copy default FSP-S UPD data from Flash
241 //
242 FspsHeaderPtr = (FSP_INFO_HEADER *)FspFindFspHeader (PcdGet32 (PcdFspsBaseAddress));
243 DEBUG ((DEBUG_INFO, "FspsHeaderPtr - 0x%x\n", FspsHeaderPtr));
244 if (FspsHeaderPtr == NULL) {
245 return EFI_DEVICE_ERROR;
246 }
247
248 FspsUpdDataPtr = (FSPS_UPD_COMMON *)AllocateZeroPool ((UINTN)FspsHeaderPtr->CfgRegionSize);
249 ASSERT (FspsUpdDataPtr != NULL);
250 SourceData = (UINTN *)((UINTN)FspsHeaderPtr->ImageBase + (UINTN)FspsHeaderPtr->CfgRegionOffset);
251 CopyMem (FspsUpdDataPtr, SourceData, (UINTN)FspsHeaderPtr->CfgRegionSize);
252
253 UpdateFspsUpdData ((VOID *)FspsUpdDataPtr);
254
255 TimeStampCounterStart = AsmReadTsc ();
256 PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, 0x9000);
257 Status = CallFspSiliconInit ((VOID *)FspsUpdDataPtr);
258 PERF_END_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, 0x907F);
259 DEBUG ((DEBUG_INFO, "Total time spent executing FspSiliconInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart), 1000000)));
260
261 //
262 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
263 //
264 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {
265 DEBUG((DEBUG_INFO, "FspSiliconInitApi requested reset 0x%x\n", Status));
266 CallFspWrapperResetSystem ((UINT32)Status);
267 }
268
269 if (EFI_ERROR(Status)) {
270 DEBUG ((DEBUG_ERROR, "ERROR - Failed to execute FspSiliconInitApi(), Status = %r\n", Status));
271 }
272 DEBUG((DEBUG_INFO, "FspSiliconInit status: 0x%x\n", Status));
273 ASSERT_EFI_ERROR (Status);
274
275 Status = TestFspSiliconInitApiOutput ((VOID *)NULL);
276 if (RETURN_ERROR (Status)) {
277 DEBUG ((DEBUG_ERROR, "ERROR - TestFspSiliconInitApiOutput () fail, Status = %r\n", Status));
278 }
279
280 //
281 // Now FspHobList complete, process it
282 //
283 GuidHob = GetFirstGuidHob (&gFspHobGuid);
284 ASSERT (GuidHob != NULL);
285 FspHobListPtr = *(VOID **)GET_GUID_HOB_DATA (GuidHob);
286 DEBUG ((DEBUG_INFO, "FspHobListPtr - 0x%x\n", FspHobListPtr));
287 PostFspsHobProcess (FspHobListPtr);
288
289 //
290 // Install FspSiliconInitDonePpi so that any other driver can consume this info.
291 //
292 Status = PeiServicesInstallPpi (&mPeiFspSiliconInitDonePpi);
293 ASSERT_EFI_ERROR(Status);
294
295 return Status;
296 }
297
298 /**
299 Do FSP initialization.
300
301 @return FSP initialization status.
302 **/
303 EFI_STATUS
304 FspsWrapperInit (
305 VOID
306 )
307 {
308 EFI_STATUS Status;
309 EFI_BOOT_MODE BootMode;
310
311 //
312 // Register MemoryDiscovered Nofity to run FspSiliconInit
313 //
314 Status = PeiServicesNotifyPpi (&mPeiMemoryDiscoveredNotifyDesc);
315 ASSERT_EFI_ERROR (Status);
316
317 //
318 // Register EndOfPei Notify for S3 to run FSP NotifyPhase
319 //
320 PeiServicesGetBootMode (&BootMode);
321 if (BootMode == BOOT_ON_S3_RESUME) {
322 Status = PeiServicesNotifyPpi (&mS3EndOfPeiNotifyDesc);
323 ASSERT_EFI_ERROR (Status);
324 }
325
326 return EFI_SUCCESS;
327 }
328
329 /**
330 This is the entrypoint of PEIM
331
332 @param[in] FileHandle Handle of the file being invoked.
333 @param[in] PeiServices Describes the list of possible PEI Services.
334
335 @retval EFI_SUCCESS if it completed successfully.
336 **/
337 EFI_STATUS
338 EFIAPI
339 FspsWrapperPeimEntryPoint (
340 IN EFI_PEI_FILE_HANDLE FileHandle,
341 IN CONST EFI_PEI_SERVICES **PeiServices
342 )
343 {
344
345 DEBUG ((DEBUG_INFO, "FspsWrapperPeimEntryPoint\n"));
346
347 FspsWrapperInit ();
348
349 return EFI_SUCCESS;
350 }