1 | /** @file
|
---|
2 | Support FSP Wrapper MultiPhase process.
|
---|
3 |
|
---|
4 | Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
|
---|
5 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
6 |
|
---|
7 | **/
|
---|
8 |
|
---|
9 | #include <Library/BaseLib.h>
|
---|
10 | #include <Library/DebugLib.h>
|
---|
11 | #include <Library/PcdLib.h>
|
---|
12 | #include <Library/FspWrapperApiLib.h>
|
---|
13 | #include <Library/FspWrapperPlatformLib.h>
|
---|
14 | #include <FspEas.h>
|
---|
15 | #include <FspGlobalData.h>
|
---|
16 | #include <Ppi/ReadOnlyVariable2.h>
|
---|
17 | #include <Ppi/Variable.h>
|
---|
18 | #include <Library/PeiServicesLib.h>
|
---|
19 | #include <Library/FspWrapperPlatformMultiPhaseLib.h>
|
---|
20 |
|
---|
21 | /**
|
---|
22 | Execute 32-bit FSP API entry code.
|
---|
23 |
|
---|
24 | @param[in] Function The 32bit code entry to be executed.
|
---|
25 | @param[in] Param1 The first parameter to pass to 32bit code.
|
---|
26 | @param[in] Param2 The second parameter to pass to 32bit code.
|
---|
27 |
|
---|
28 | @return EFI_STATUS.
|
---|
29 | **/
|
---|
30 | EFI_STATUS
|
---|
31 | Execute32BitCode (
|
---|
32 | IN UINT64 Function,
|
---|
33 | IN UINT64 Param1,
|
---|
34 | IN UINT64 Param2
|
---|
35 | );
|
---|
36 |
|
---|
37 | /**
|
---|
38 | Execute 64-bit FSP API entry code.
|
---|
39 |
|
---|
40 | @param[in] Function The 64bit code entry to be executed.
|
---|
41 | @param[in] Param1 The first parameter to pass to 64bit code.
|
---|
42 | @param[in] Param2 The second parameter to pass to 64bit code.
|
---|
43 |
|
---|
44 | @return EFI_STATUS.
|
---|
45 | **/
|
---|
46 | EFI_STATUS
|
---|
47 | Execute64BitCode (
|
---|
48 | IN UINT64 Function,
|
---|
49 | IN UINT64 Param1,
|
---|
50 | IN UINT64 Param2
|
---|
51 | );
|
---|
52 |
|
---|
53 | /**
|
---|
54 | Call FspsMultiPhase API.
|
---|
55 |
|
---|
56 | @param[in] FspsMultiPhaseParams - Parameters for MultiPhase API.
|
---|
57 | @param[in] FspHobListPtr - Pointer to FSP HobList (valid after FSP-M completed)
|
---|
58 | @param[in] ComponentIndex - FSP Component which executing MultiPhase initialization.
|
---|
59 |
|
---|
60 | @return EFI_UNSUPPORTED - the requested FspsMultiPhase API is not supported.
|
---|
61 | @return EFI_DEVICE_ERROR - the FSP header was not found.
|
---|
62 | @return EFI status returned by FspsMultiPhase API.
|
---|
63 | **/
|
---|
64 | EFI_STATUS
|
---|
65 | EFIAPI
|
---|
66 | CallFspMultiPhaseEntry (
|
---|
67 | IN VOID *FspMultiPhaseParams,
|
---|
68 | IN OUT VOID **FspHobListPtr,
|
---|
69 | IN UINT8 ComponentIndex
|
---|
70 | )
|
---|
71 | {
|
---|
72 | FSP_INFO_HEADER *FspHeader;
|
---|
73 | //
|
---|
74 | // FSP_MULTI_PHASE_INIT and FSP_MULTI_PHASE_SI_INIT API functions having same prototype.
|
---|
75 | //
|
---|
76 | UINTN FspMultiPhaseApiEntry;
|
---|
77 | UINTN FspMultiPhaseApiOffset;
|
---|
78 | EFI_STATUS Status;
|
---|
79 | BOOLEAN InterruptState;
|
---|
80 | BOOLEAN IsVariableServiceRequest;
|
---|
81 | FSP_MULTI_PHASE_PARAMS *FspMultiPhaseParamsPtr;
|
---|
82 |
|
---|
83 | FspMultiPhaseApiOffset = 0;
|
---|
84 | FspMultiPhaseParamsPtr = (FSP_MULTI_PHASE_PARAMS *)FspMultiPhaseParams;
|
---|
85 | IsVariableServiceRequest = FALSE;
|
---|
86 | if ((FspMultiPhaseParamsPtr->MultiPhaseAction == EnumMultiPhaseGetVariableRequestInfo) ||
|
---|
87 | (FspMultiPhaseParamsPtr->MultiPhaseAction == EnumMultiPhaseCompleteVariableRequest))
|
---|
88 | {
|
---|
89 | IsVariableServiceRequest = TRUE;
|
---|
90 | }
|
---|
91 |
|
---|
92 | if (ComponentIndex == FspMultiPhaseMemInitApiIndex) {
|
---|
93 | FspHeader = (FSP_INFO_HEADER *)FspFindFspHeader (PcdGet32 (PcdFspmBaseAddress));
|
---|
94 | if (FspHeader == NULL) {
|
---|
95 | return EFI_DEVICE_ERROR;
|
---|
96 | } else if (FspHeader->SpecVersion < 0x24) {
|
---|
97 | return EFI_UNSUPPORTED;
|
---|
98 | }
|
---|
99 |
|
---|
100 | FspMultiPhaseApiOffset = FspHeader->FspMultiPhaseMemInitEntryOffset;
|
---|
101 | } else if (ComponentIndex == FspMultiPhaseSiInitApiIndex) {
|
---|
102 | FspHeader = (FSP_INFO_HEADER *)FspFindFspHeader (PcdGet32 (PcdFspsBaseAddress));
|
---|
103 | if (FspHeader == NULL) {
|
---|
104 | return EFI_DEVICE_ERROR;
|
---|
105 | } else if (FspHeader->SpecVersion < 0x22) {
|
---|
106 | return EFI_UNSUPPORTED;
|
---|
107 | } else if ((FspHeader->SpecVersion < 0x24) && (IsVariableServiceRequest == TRUE)) {
|
---|
108 | return EFI_UNSUPPORTED;
|
---|
109 | }
|
---|
110 |
|
---|
111 | FspMultiPhaseApiOffset = FspHeader->FspMultiPhaseSiInitEntryOffset;
|
---|
112 | }
|
---|
113 |
|
---|
114 | if (FspMultiPhaseApiOffset == 0) {
|
---|
115 | return EFI_UNSUPPORTED;
|
---|
116 | }
|
---|
117 |
|
---|
118 | FspMultiPhaseApiEntry = FspHeader->ImageBase + FspMultiPhaseApiOffset;
|
---|
119 | InterruptState = SaveAndDisableInterrupts ();
|
---|
120 | if ((FspHeader->ImageAttribute & BIT2) == 0) {
|
---|
121 | // BIT2: IMAGE_ATTRIBUTE_64BIT_MODE_SUPPORT
|
---|
122 | Status = Execute32BitCode ((UINTN)FspMultiPhaseApiEntry, (UINTN)FspMultiPhaseParams, (UINTN)NULL);
|
---|
123 | } else {
|
---|
124 | Status = Execute64BitCode ((UINTN)FspMultiPhaseApiEntry, (UINTN)FspMultiPhaseParams, (UINTN)NULL);
|
---|
125 | }
|
---|
126 |
|
---|
127 | SetInterruptState (InterruptState);
|
---|
128 |
|
---|
129 | DEBUG ((DEBUG_ERROR, "CallFspMultiPhaseEntry return Status %r \n", Status));
|
---|
130 |
|
---|
131 | return Status;
|
---|
132 | }
|
---|
133 |
|
---|
134 | /**
|
---|
135 | FSP Wrapper Variable Request Handler
|
---|
136 |
|
---|
137 | @param[in, out] FspHobListPtr - Pointer to FSP HobList (valid after FSP-M completed)
|
---|
138 | @param[in] ComponentIndex - FSP Component which executing MultiPhase initialization.
|
---|
139 |
|
---|
140 | @retval EFI_UNSUPPORTED FSP Wrapper cannot support the specific variable request,
|
---|
141 | or FSP does not support VariableService
|
---|
142 | @retval EFI_STATUS Return FSP returned status
|
---|
143 |
|
---|
144 | **/
|
---|
145 | EFI_STATUS
|
---|
146 | EFIAPI
|
---|
147 | FspWrapperVariableRequestHandler (
|
---|
148 | IN OUT VOID **FspHobListPtr,
|
---|
149 | IN UINT8 ComponentIndex
|
---|
150 | )
|
---|
151 | {
|
---|
152 | EFI_STATUS Status;
|
---|
153 | FSP_MULTI_PHASE_PARAMS FspMultiPhaseParams;
|
---|
154 | FSP_MULTI_PHASE_VARIABLE_REQUEST_INFO_PARAMS *FspVariableRequestParams;
|
---|
155 | EFI_PEI_READ_ONLY_VARIABLE2_PPI *ReadOnlyVariablePpi;
|
---|
156 | EDKII_PEI_VARIABLE_PPI *VariablePpi;
|
---|
157 | BOOLEAN WriteVariableSupport;
|
---|
158 | FSP_MULTI_PHASE_COMPLETE_VARIABLE_REQUEST_PARAMS CompleteVariableRequestParams;
|
---|
159 |
|
---|
160 | WriteVariableSupport = TRUE;
|
---|
161 | Status = PeiServicesLocatePpi (
|
---|
162 | &gEdkiiPeiVariablePpiGuid,
|
---|
163 | 0,
|
---|
164 | NULL,
|
---|
165 | (VOID **)&VariablePpi
|
---|
166 | );
|
---|
167 | if (EFI_ERROR (Status)) {
|
---|
168 | WriteVariableSupport = FALSE;
|
---|
169 | Status = PeiServicesLocatePpi (
|
---|
170 | &gEfiPeiReadOnlyVariable2PpiGuid,
|
---|
171 | 0,
|
---|
172 | NULL,
|
---|
173 | (VOID **)&ReadOnlyVariablePpi
|
---|
174 | );
|
---|
175 | ASSERT_EFI_ERROR (Status);
|
---|
176 | if (EFI_ERROR (Status)) {
|
---|
177 | return EFI_UNSUPPORTED;
|
---|
178 | }
|
---|
179 | }
|
---|
180 |
|
---|
181 | Status = FSP_STATUS_VARIABLE_REQUEST;
|
---|
182 | while (Status == FSP_STATUS_VARIABLE_REQUEST) {
|
---|
183 | //
|
---|
184 | // Get the variable request information from FSP.
|
---|
185 | //
|
---|
186 | FspMultiPhaseParams.MultiPhaseAction = EnumMultiPhaseGetVariableRequestInfo;
|
---|
187 | FspMultiPhaseParams.PhaseIndex = 0;
|
---|
188 | Status = CallFspMultiPhaseEntry (&FspMultiPhaseParams, FspHobListPtr, ComponentIndex);
|
---|
189 | ASSERT_EFI_ERROR (Status);
|
---|
190 | //
|
---|
191 | // FSP should output this pointer for variable request information.
|
---|
192 | //
|
---|
193 | FspVariableRequestParams = (FSP_MULTI_PHASE_VARIABLE_REQUEST_INFO_PARAMS *)FspMultiPhaseParams.MultiPhaseParamPtr;
|
---|
194 | switch (FspVariableRequestParams->VariableRequest) {
|
---|
195 | case EnumFspVariableRequestGetVariable:
|
---|
196 | if (WriteVariableSupport) {
|
---|
197 | Status = VariablePpi->GetVariable (
|
---|
198 | VariablePpi,
|
---|
199 | FspVariableRequestParams->VariableName,
|
---|
200 | FspVariableRequestParams->VariableGuid,
|
---|
201 | FspVariableRequestParams->Attributes,
|
---|
202 | (UINTN *)FspVariableRequestParams->DataSize,
|
---|
203 | FspVariableRequestParams->Data
|
---|
204 | );
|
---|
205 | } else {
|
---|
206 | Status = ReadOnlyVariablePpi->GetVariable (
|
---|
207 | ReadOnlyVariablePpi,
|
---|
208 | FspVariableRequestParams->VariableName,
|
---|
209 | FspVariableRequestParams->VariableGuid,
|
---|
210 | FspVariableRequestParams->Attributes,
|
---|
211 | (UINTN *)FspVariableRequestParams->DataSize,
|
---|
212 | FspVariableRequestParams->Data
|
---|
213 | );
|
---|
214 | }
|
---|
215 |
|
---|
216 | CompleteVariableRequestParams.VariableRequestStatus = Status;
|
---|
217 | FspMultiPhaseParams.MultiPhaseParamPtr = (VOID *)&CompleteVariableRequestParams;
|
---|
218 | FspMultiPhaseParams.MultiPhaseAction = EnumMultiPhaseCompleteVariableRequest;
|
---|
219 | Status = CallFspMultiPhaseEntry (&FspMultiPhaseParams, FspHobListPtr, ComponentIndex);
|
---|
220 | break;
|
---|
221 |
|
---|
222 | case EnumFspVariableRequestSetVariable:
|
---|
223 | if (WriteVariableSupport) {
|
---|
224 | Status = VariablePpi->SetVariable (
|
---|
225 | VariablePpi,
|
---|
226 | FspVariableRequestParams->VariableName,
|
---|
227 | FspVariableRequestParams->VariableGuid,
|
---|
228 | *FspVariableRequestParams->Attributes,
|
---|
229 | (UINTN)*FspVariableRequestParams->DataSize,
|
---|
230 | FspVariableRequestParams->Data
|
---|
231 | );
|
---|
232 | } else {
|
---|
233 | Status = EFI_UNSUPPORTED;
|
---|
234 | }
|
---|
235 |
|
---|
236 | CompleteVariableRequestParams.VariableRequestStatus = Status;
|
---|
237 | FspMultiPhaseParams.MultiPhaseParamPtr = (VOID *)&CompleteVariableRequestParams;
|
---|
238 | FspMultiPhaseParams.MultiPhaseAction = EnumMultiPhaseCompleteVariableRequest;
|
---|
239 | Status = CallFspMultiPhaseEntry (&FspMultiPhaseParams, FspHobListPtr, ComponentIndex);
|
---|
240 | break;
|
---|
241 |
|
---|
242 | case EnumFspVariableRequestGetNextVariableName:
|
---|
243 | if (WriteVariableSupport) {
|
---|
244 | Status = VariablePpi->GetNextVariableName (
|
---|
245 | VariablePpi,
|
---|
246 | (UINTN *)FspVariableRequestParams->VariableNameSize,
|
---|
247 | FspVariableRequestParams->VariableName,
|
---|
248 | FspVariableRequestParams->VariableGuid
|
---|
249 | );
|
---|
250 | } else {
|
---|
251 | Status = ReadOnlyVariablePpi->NextVariableName (
|
---|
252 | ReadOnlyVariablePpi,
|
---|
253 | (UINTN *)FspVariableRequestParams->VariableNameSize,
|
---|
254 | FspVariableRequestParams->VariableName,
|
---|
255 | FspVariableRequestParams->VariableGuid
|
---|
256 | );
|
---|
257 | }
|
---|
258 |
|
---|
259 | CompleteVariableRequestParams.VariableRequestStatus = Status;
|
---|
260 | FspMultiPhaseParams.MultiPhaseParamPtr = (VOID *)&CompleteVariableRequestParams;
|
---|
261 | FspMultiPhaseParams.MultiPhaseAction = EnumMultiPhaseCompleteVariableRequest;
|
---|
262 | Status = CallFspMultiPhaseEntry (&FspMultiPhaseParams, FspHobListPtr, ComponentIndex);
|
---|
263 | break;
|
---|
264 |
|
---|
265 | case EnumFspVariableRequestQueryVariableInfo:
|
---|
266 | if (WriteVariableSupport) {
|
---|
267 | Status = VariablePpi->QueryVariableInfo (
|
---|
268 | VariablePpi,
|
---|
269 | *FspVariableRequestParams->Attributes,
|
---|
270 | FspVariableRequestParams->MaximumVariableStorageSize,
|
---|
271 | FspVariableRequestParams->RemainingVariableStorageSize,
|
---|
272 | FspVariableRequestParams->MaximumVariableSize
|
---|
273 | );
|
---|
274 | } else {
|
---|
275 | Status = EFI_UNSUPPORTED;
|
---|
276 | }
|
---|
277 |
|
---|
278 | CompleteVariableRequestParams.VariableRequestStatus = Status;
|
---|
279 | FspMultiPhaseParams.MultiPhaseParamPtr = (VOID *)&CompleteVariableRequestParams;
|
---|
280 | FspMultiPhaseParams.MultiPhaseAction = EnumMultiPhaseCompleteVariableRequest;
|
---|
281 | Status = CallFspMultiPhaseEntry (&FspMultiPhaseParams, FspHobListPtr, ComponentIndex);
|
---|
282 | break;
|
---|
283 |
|
---|
284 | default:
|
---|
285 | DEBUG ((DEBUG_ERROR, "Unknown VariableRequest type!\n"));
|
---|
286 | Status = EFI_UNSUPPORTED;
|
---|
287 | break;
|
---|
288 | }
|
---|
289 | }
|
---|
290 |
|
---|
291 | //
|
---|
292 | // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
|
---|
293 | //
|
---|
294 | if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {
|
---|
295 | DEBUG ((DEBUG_INFO, "FspMultiPhaseApi-0x%x requested reset %r\n", ComponentIndex, Status));
|
---|
296 | CallFspWrapperResetSystem ((UINTN)Status);
|
---|
297 | }
|
---|
298 |
|
---|
299 | return Status;
|
---|
300 | }
|
---|
301 |
|
---|
302 | /**
|
---|
303 | FSP Wrapper MultiPhase Handler
|
---|
304 |
|
---|
305 | @param[in, out] FspHobListPtr - Pointer to FSP HobList (valid after FSP-M completed)
|
---|
306 | @param[in] ComponentIndex - FSP Component which executing MultiPhase initialization.
|
---|
307 |
|
---|
308 | @retval EFI_UNSUPPORTED Specific MultiPhase action was not supported.
|
---|
309 | @retval EFI_SUCCESS MultiPhase action were completed successfully.
|
---|
310 |
|
---|
311 | **/
|
---|
312 | EFI_STATUS
|
---|
313 | EFIAPI
|
---|
314 | FspWrapperMultiPhaseHandler (
|
---|
315 | IN OUT VOID **FspHobListPtr,
|
---|
316 | IN UINT8 ComponentIndex
|
---|
317 | )
|
---|
318 | {
|
---|
319 | EFI_STATUS Status;
|
---|
320 | FSP_MULTI_PHASE_PARAMS FspMultiPhaseParams;
|
---|
321 | FSP_MULTI_PHASE_GET_NUMBER_OF_PHASES_PARAMS FspMultiPhaseGetNumber;
|
---|
322 | UINT32 Index;
|
---|
323 | UINT32 NumOfPhases;
|
---|
324 |
|
---|
325 | //
|
---|
326 | // Query FSP for the number of phases supported.
|
---|
327 | //
|
---|
328 | FspMultiPhaseParams.MultiPhaseAction = EnumMultiPhaseGetNumberOfPhases;
|
---|
329 | FspMultiPhaseParams.PhaseIndex = 0;
|
---|
330 | FspMultiPhaseParams.MultiPhaseParamPtr = (VOID *)&FspMultiPhaseGetNumber;
|
---|
331 | Status = CallFspMultiPhaseEntry (&FspMultiPhaseParams, FspHobListPtr, ComponentIndex);
|
---|
332 | if (Status == EFI_UNSUPPORTED) {
|
---|
333 | //
|
---|
334 | // MultiPhase API was not supported
|
---|
335 | //
|
---|
336 | return Status;
|
---|
337 | } else {
|
---|
338 | ASSERT_EFI_ERROR (Status);
|
---|
339 | }
|
---|
340 |
|
---|
341 | NumOfPhases = FspMultiPhaseGetNumber.NumberOfPhases;
|
---|
342 |
|
---|
343 | for (Index = 1; Index <= NumOfPhases; Index++) {
|
---|
344 | DEBUG ((DEBUG_ERROR, "MultiPhase Index/NumOfPhases = %d of %d\n", Index, NumOfPhases));
|
---|
345 | //
|
---|
346 | // Platform actions can be added in below function for each component and phase before returning control back to FSP.
|
---|
347 | //
|
---|
348 | FspWrapperPlatformMultiPhaseHandler (FspHobListPtr, ComponentIndex, Index);
|
---|
349 |
|
---|
350 | FspMultiPhaseParams.MultiPhaseAction = EnumMultiPhaseExecutePhase;
|
---|
351 | FspMultiPhaseParams.PhaseIndex = Index;
|
---|
352 | FspMultiPhaseParams.MultiPhaseParamPtr = NULL;
|
---|
353 | Status = CallFspMultiPhaseEntry (&FspMultiPhaseParams, FspHobListPtr, ComponentIndex);
|
---|
354 |
|
---|
355 | if (Status == FSP_STATUS_VARIABLE_REQUEST) {
|
---|
356 | //
|
---|
357 | // call to Variable request handler
|
---|
358 | //
|
---|
359 | FspWrapperVariableRequestHandler (FspHobListPtr, ComponentIndex);
|
---|
360 | }
|
---|
361 |
|
---|
362 | //
|
---|
363 | // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
|
---|
364 | //
|
---|
365 | if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {
|
---|
366 | DEBUG ((DEBUG_INFO, "FspMultiPhaseApi-0x%x requested reset %r\n", ComponentIndex, Status));
|
---|
367 | CallFspWrapperResetSystem ((UINTN)Status);
|
---|
368 | }
|
---|
369 |
|
---|
370 | ASSERT_EFI_ERROR (Status);
|
---|
371 | }
|
---|
372 |
|
---|
373 | return EFI_SUCCESS;
|
---|
374 | }
|
---|