3 Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php.
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include <Library/BaseLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/PcdLib.h>
18 #include <FspGlobalData.h>
20 #include <Library/FspSwitchStackLib.h>
25 // API Parameter +0x34
26 // API return address +0x30
28 // push FspInfoHeader +0x2C
33 // sidt fword ptr [esp]
53 #define CONTEXT_STACK_OFFSET(x) (UINT32)&((CONTEXT_STACK *)(UINTN)0)->x
58 This function sets the FSP global data pointer.
60 @param[in] FspData FSP global data pointer.
65 SetFspGlobalDataPointer (
66 IN FSP_GLOBAL_DATA
*FspData
69 ASSERT (FspData
!= NULL
);
70 *((volatile UINT32
*)(UINTN
)PcdGet32(PcdGlobalDataPointerAddress
)) = (UINT32
)(UINTN
)FspData
;
74 This function gets the FSP global data pointer.
79 GetFspGlobalDataPointer (
83 FSP_GLOBAL_DATA
*FspData
;
85 FspData
= *(FSP_GLOBAL_DATA
**)(UINTN
)PcdGet32(PcdGlobalDataPointerAddress
);
90 This function gets back the FSP API first parameter passed by the bootlaoder.
92 @retval ApiParameter FSP API first parameter passed by the bootlaoder.
100 FSP_GLOBAL_DATA
*FspData
;
102 FspData
= GetFspGlobalDataPointer ();
103 return *(UINT32
*)(UINTN
)(FspData
->CoreStack
+ CONTEXT_STACK_OFFSET(ApiParam
[0]));
107 This function gets back the FSP API second parameter passed by the bootlaoder.
109 @retval ApiParameter FSP API second parameter passed by the bootlaoder.
113 GetFspApiParameter2 (
117 FSP_GLOBAL_DATA
*FspData
;
119 FspData
= GetFspGlobalDataPointer ();
120 return *(UINT32
*)(UINTN
)(FspData
->CoreStack
+ CONTEXT_STACK_OFFSET(ApiParam
[1]));
124 This function sets the FSP API parameter in the stack.
126 @param[in] Value New parameter value.
135 FSP_GLOBAL_DATA
*FspData
;
137 FspData
= GetFspGlobalDataPointer ();
138 *(UINT32
*)(UINTN
)(FspData
->CoreStack
+ CONTEXT_STACK_OFFSET(ApiParam
)) = Value
;
142 This function set the API status code returned to the BootLoader.
144 @param[in] ReturnStatus Status code to return.
149 SetFspApiReturnStatus (
150 IN UINT32 ReturnStatus
153 FSP_GLOBAL_DATA
*FspData
;
155 FspData
= GetFspGlobalDataPointer ();
156 *(UINT32
*)(UINTN
)(FspData
->CoreStack
+ CONTEXT_STACK_OFFSET(Eax
)) = ReturnStatus
;
160 This function sets the context switching stack to a new stack frame.
162 @param[in] NewStackTop New core stack to be set.
167 SetFspCoreStackPointer (
171 FSP_GLOBAL_DATA
*FspData
;
174 UINT32 StackContextLen
;
176 FspData
= GetFspGlobalDataPointer ();
177 StackContextLen
= sizeof(CONTEXT_STACK
) / sizeof(UINT32
);
180 // Reserve space for the ContinuationFunc two parameters
182 OldStack
= (UINT32
*)FspData
->CoreStack
;
183 NewStack
= (UINT32
*)NewStackTop
- StackContextLen
- 2;
184 FspData
->CoreStack
= (UINT32
)NewStack
;
185 while (StackContextLen
-- != 0) {
186 *NewStack
++ = *OldStack
++;
191 This function sets the platform specific data pointer.
193 @param[in] PlatformData FSP platform specific data pointer.
198 SetFspPlatformDataPointer (
199 IN VOID
*PlatformData
202 FSP_GLOBAL_DATA
*FspData
;
204 FspData
= GetFspGlobalDataPointer ();
205 FspData
->PlatformData
.DataPtr
= PlatformData
;
210 This function gets the platform specific data pointer.
212 @param[in] PlatformData FSP platform specific data pointer.
217 GetFspPlatformDataPointer (
221 FSP_GLOBAL_DATA
*FspData
;
223 FspData
= GetFspGlobalDataPointer ();
224 return FspData
->PlatformData
.DataPtr
;
229 This function sets the UPD data pointer.
231 @param[in] UpdDataPtr UPD data pointer.
235 SetFspUpdDataPointer (
239 FSP_GLOBAL_DATA
*FspData
;
242 // Get the FSP Global Data Pointer
244 FspData
= GetFspGlobalDataPointer ();
247 // Set the UPD pointer.
249 FspData
->UpdDataPtr
= UpdDataPtr
;
253 This function gets the UPD data pointer.
255 @return UpdDataPtr UPD data pointer.
259 GetFspUpdDataPointer (
263 FSP_GLOBAL_DATA
*FspData
;
265 FspData
= GetFspGlobalDataPointer ();
266 return FspData
->UpdDataPtr
;
271 This function sets the FspMemoryInit UPD data pointer.
273 @param[in] MemoryInitUpdPtr FspMemoryInit UPD data pointer.
277 SetFspMemoryInitUpdDataPointer (
278 IN VOID
*MemoryInitUpdPtr
281 FSP_GLOBAL_DATA
*FspData
;
284 // Get the FSP Global Data Pointer
286 FspData
= GetFspGlobalDataPointer ();
289 // Set the FspMemoryInit UPD pointer.
291 FspData
->MemoryInitUpdPtr
= MemoryInitUpdPtr
;
295 This function gets the FspMemoryInit UPD data pointer.
297 @return FspMemoryInit UPD data pointer.
301 GetFspMemoryInitUpdDataPointer (
305 FSP_GLOBAL_DATA
*FspData
;
307 FspData
= GetFspGlobalDataPointer ();
308 return FspData
->MemoryInitUpdPtr
;
313 This function sets the FspSiliconInit UPD data pointer.
315 @param[in] SiliconInitUpdPtr FspSiliconInit UPD data pointer.
319 SetFspSiliconInitUpdDataPointer (
320 IN VOID
*SiliconInitUpdPtr
323 FSP_GLOBAL_DATA
*FspData
;
326 // Get the FSP Global Data Pointer
328 FspData
= GetFspGlobalDataPointer ();
331 // Set the FspSiliconInit UPD data pointer.
333 FspData
->SiliconInitUpdPtr
= SiliconInitUpdPtr
;
337 This function gets the FspSiliconInit UPD data pointer.
339 @return FspSiliconInit UPD data pointer.
343 GetFspSiliconInitUpdDataPointer (
347 FSP_GLOBAL_DATA
*FspData
;
349 FspData
= GetFspGlobalDataPointer ();
350 return FspData
->SiliconInitUpdPtr
;
355 Set FSP measurement point timestamp.
357 @param[in] Id Measurement point ID.
359 @return performance timestamp.
367 FSP_GLOBAL_DATA
*FspData
;
370 // Bit [55: 0] will be the timestamp
371 // Bit [63:56] will be the ID
373 FspData
= GetFspGlobalDataPointer ();
374 if (FspData
->PerfIdx
< sizeof(FspData
->PerfData
) / sizeof(FspData
->PerfData
[0])) {
375 FspData
->PerfData
[FspData
->PerfIdx
] = AsmReadTsc ();
376 ((UINT8
*)(&FspData
->PerfData
[FspData
->PerfIdx
]))[7] = Id
;
379 return FspData
->PerfData
[(FspData
->PerfIdx
)++];
383 This function gets the FSP info header pointer.
385 @retval FspInfoHeader FSP info header pointer
393 return GetFspGlobalDataPointer()->FspInfoHeader
;
397 This function sets the FSP info header pointer.
399 @param[in] FspInfoHeader FSP info header pointer
404 FSP_INFO_HEADER
*FspInfoHeader
407 GetFspGlobalDataPointer()->FspInfoHeader
= FspInfoHeader
;
411 This function gets the FSP info header pointer using the API stack context.
413 @retval FspInfoHeader FSP info header pointer using the API stack context
417 GetFspInfoHeaderFromApiContext (
421 FSP_GLOBAL_DATA
*FspData
;
423 FspData
= GetFspGlobalDataPointer ();
424 return (FSP_INFO_HEADER
*)(*(UINT32
*)(UINTN
)(FspData
->CoreStack
+ CONTEXT_STACK_OFFSET(FspInfoHeader
)));
428 This function gets the CfgRegion data pointer.
430 @return CfgRegion data pointer.
434 GetFspCfgRegionDataPointer (
438 FSP_INFO_HEADER
*FspInfoHeader
;
440 FspInfoHeader
= GetFspInfoHeader ();
441 return (VOID
*)(FspInfoHeader
->ImageBase
+ FspInfoHeader
->CfgRegionOffset
);
445 This function gets FSP API calling index.
447 @retval API calling index
451 GetFspApiCallingIndex (
455 return GetFspGlobalDataPointer()->ApiIdx
;
459 This function sets FSP API calling mode.
461 @param[in] Index API calling index
465 SetFspApiCallingIndex (
469 FSP_GLOBAL_DATA
*FspData
;
471 FspData
= GetFspGlobalDataPointer ();
472 FspData
->ApiIdx
= Index
;
476 This function gets FSP Phase StatusCode.
486 return GetFspGlobalDataPointer()->StatusCode
;
490 This function sets FSP Phase StatusCode.
492 @param[in] Mode Phase StatusCode
500 FSP_GLOBAL_DATA
*FspData
;
502 FspData
= GetFspGlobalDataPointer ();
503 FspData
->StatusCode
= StatusCode
;
507 This function updates the return status of the FSP API with requested reset type and returns to Boot Loader.
509 @param[in] FspResetType Reset type that needs to returned as API return status
514 FspApiReturnStatusReset (
515 IN UINT32 FspResetType
518 volatile BOOLEAN LoopUntilReset
;
520 LoopUntilReset
= TRUE
;
521 DEBUG ((DEBUG_INFO
, "FSP returning control to Bootloader with reset required return status %x\n",FspResetType
));
523 /// Below code is not an infinite loop.The control will go back to API calling function in BootLoader each time BootLoader
524 /// calls the FSP API without honoring the reset request by FSP
527 SetFspApiReturnStatus ((EFI_STATUS
)FspResetType
);
528 Pei2LoaderSwitchStack ();
529 DEBUG ((DEBUG_ERROR
, "!!!ERROR: FSP has requested BootLoader for reset. But BootLoader has not honored the reset\n"));
530 DEBUG ((DEBUG_ERROR
, "!!!ERROR: Please add support in BootLoader to honor the reset request from FSP\n"));
531 } while (LoopUntilReset
);