3 Copyright (c) 2014, 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>
24 // Cont Func Parameter 2 +0x3C
25 // Cont Func Parameter 1 +0x38
27 // API Parameter +0x34
28 // API return address +0x30
30 // push offset exit +0x2C
35 // sidt fword ptr [esp]
55 #define CONTEXT_STACK_OFFSET(x) (UINT32)&((CONTEXT_STACK *)(UINTN)0)->x
60 This function sets the FSP global data pointer.
62 @param[in] FspData Fsp global data pointer.
67 SetFspGlobalDataPointer (
68 IN FSP_GLOBAL_DATA
*FspData
71 ASSERT (FspData
!= NULL
);
72 *((volatile UINT32
*)(UINTN
)PcdGet32(PcdGlobalDataPointerAddress
)) = (UINT32
)(UINTN
)FspData
;
76 This function gets the FSP global data pointer.
81 GetFspGlobalDataPointer (
85 FSP_GLOBAL_DATA
*FspData
;
87 FspData
= *(FSP_GLOBAL_DATA
**)(UINTN
)PcdGet32(PcdGlobalDataPointerAddress
);
92 This function gets back the FSP API paramter passed by the bootlaoder.
94 @retval ApiParameter FSP API paramter passed by the bootlaoder.
102 FSP_GLOBAL_DATA
*FspData
;
104 FspData
= GetFspGlobalDataPointer ();
105 return *(UINT32
*)(UINTN
)(FspData
->CoreStack
+ CONTEXT_STACK_OFFSET(ApiParam
));
109 This function sets the FSP API paramter in the stack.
111 @param[in] Value New parameter value.
120 FSP_GLOBAL_DATA
*FspData
;
122 FspData
= GetFspGlobalDataPointer ();
123 *(UINT32
*)(UINTN
)(FspData
->CoreStack
+ CONTEXT_STACK_OFFSET(ApiParam
)) = Value
;
127 This function sets the FSP continuation function parameters in the stack.
129 @param[in] Value New parameter value to set.
130 @param[in] Index Parameter index.
134 SetFspContinuationFuncParameter (
139 FSP_GLOBAL_DATA
*FspData
;
141 FspData
= GetFspGlobalDataPointer ();
142 *(UINT32
*)(UINTN
)(FspData
->CoreStack
+ CONTEXT_STACK_OFFSET(ApiParam
) + (Index
+ 1) * sizeof(UINT32
)) = Value
;
147 This function changes the Bootloader return address in stack.
149 @param[in] ReturnAddress Address to return.
154 SetFspApiReturnAddress (
155 IN UINT32 ReturnAddress
158 FSP_GLOBAL_DATA
*FspData
;
160 FspData
= GetFspGlobalDataPointer ();
161 *(UINT32
*)(UINTN
)(FspData
->CoreStack
+ CONTEXT_STACK_OFFSET(ApiRet
)) = ReturnAddress
;
165 This function set the API status code returned to the bootloader.
167 @param[in] ReturnStatus Status code to return.
172 SetFspApiReturnStatus (
173 IN UINT32 ReturnStatus
176 FSP_GLOBAL_DATA
*FspData
;
178 FspData
= GetFspGlobalDataPointer ();
179 *(UINT32
*)(UINTN
)(FspData
->CoreStack
+ CONTEXT_STACK_OFFSET(Eax
)) = ReturnStatus
;
183 This function sets the context switching stack to a new stack frame.
185 @param[in] NewStackTop New core stack to be set.
190 SetFspCoreStackPointer (
194 FSP_GLOBAL_DATA
*FspData
;
197 UINT32 StackContextLen
;
199 FspData
= GetFspGlobalDataPointer ();
200 StackContextLen
= sizeof(CONTEXT_STACK
) / sizeof(UINT32
);
203 // Reserve space for the ContinuationFunc two parameters
205 OldStack
= (UINT32
*)FspData
->CoreStack
;
206 NewStack
= (UINT32
*)NewStackTop
- StackContextLen
- 2;
207 FspData
->CoreStack
= (UINT32
)NewStack
;
208 while (StackContextLen
-- != 0) {
209 *NewStack
++ = *OldStack
++;
214 This function sets the platform specific data pointer.
216 @param[in] PlatformData Fsp platform specific data pointer.
221 SetFspPlatformDataPointer (
222 IN VOID
*PlatformData
225 FSP_GLOBAL_DATA
*FspData
;
227 FspData
= GetFspGlobalDataPointer ();
228 FspData
->PlatformData
.DataPtr
= PlatformData
;
233 This function gets the platform specific data pointer.
235 @param[in] PlatformData Fsp platform specific data pointer.
240 GetFspPlatformDataPointer (
244 FSP_GLOBAL_DATA
*FspData
;
246 FspData
= GetFspGlobalDataPointer ();
247 return FspData
->PlatformData
.DataPtr
;
252 This function sets the UPD data pointer.
254 @param[in] UpdDataRgnPtr UPD data pointer.
258 SetFspUpdDataPointer (
259 IN VOID
*UpdDataRgnPtr
262 FSP_GLOBAL_DATA
*FspData
;
265 // Get the Fsp Global Data Pointer
267 FspData
= GetFspGlobalDataPointer ();
270 // Set the UPD pointer.
272 FspData
->UpdDataRgnPtr
= UpdDataRgnPtr
;
276 This function gets the UPD data pointer.
278 @return UpdDataRgnPtr UPD data pointer.
282 GetFspUpdDataPointer (
286 FSP_GLOBAL_DATA
*FspData
;
288 FspData
= GetFspGlobalDataPointer ();
289 return FspData
->UpdDataRgnPtr
;
293 Set FSP measurement point timestamp.
295 @param[in] Id Measurement point ID.
297 @return performance timestamp.
305 FSP_GLOBAL_DATA
*FspData
;
308 // Bit [55: 0] will be the timestamp
309 // Bit [63:56] will be the ID
311 FspData
= GetFspGlobalDataPointer ();
312 if (FspData
->PerfIdx
< sizeof(FspData
->PerfData
) / sizeof(FspData
->PerfData
[0])) {
313 FspData
->PerfData
[FspData
->PerfIdx
] = AsmReadTsc ();
314 ((UINT8
*)(&FspData
->PerfData
[FspData
->PerfIdx
]))[7] = Id
;
317 return FspData
->PerfData
[(FspData
->PerfIdx
)++];