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