3 Copyright (c) 2014 - 2015, 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 FspInfoHeader +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 parameter passed by the bootlaoder.
94 @retval ApiParameter FSP API parameter 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 parameter 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
;
294 This function sets the memory init UPD data pointer.
296 @param[in] MemoryInitUpdPtr memory init UPD data pointer.
300 SetFspMemoryInitUpdDataPointer (
301 IN VOID
*MemoryInitUpdPtr
304 FSP_GLOBAL_DATA
*FspData
;
307 // Get the Fsp Global Data Pointer
309 FspData
= GetFspGlobalDataPointer ();
312 // Set the memory init UPD pointer.
314 FspData
->MemoryInitUpdPtr
= MemoryInitUpdPtr
;
318 This function gets the memory init UPD data pointer.
320 @return memory init UPD data pointer.
324 GetFspMemoryInitUpdDataPointer (
328 FSP_GLOBAL_DATA
*FspData
;
330 FspData
= GetFspGlobalDataPointer ();
331 return FspData
->MemoryInitUpdPtr
;
336 This function sets the silicon init UPD data pointer.
338 @param[in] SiliconInitUpdPtr silicon init UPD data pointer.
342 SetFspSiliconInitUpdDataPointer (
343 IN VOID
*SiliconInitUpdPtr
346 FSP_GLOBAL_DATA
*FspData
;
349 // Get the Fsp Global Data Pointer
351 FspData
= GetFspGlobalDataPointer ();
354 // Set the silicon init UPD data pointer.
356 FspData
->SiliconInitUpdPtr
= SiliconInitUpdPtr
;
360 This function gets the silicon init UPD data pointer.
362 @return silicon init UPD data pointer.
366 GetFspSiliconInitUpdDataPointer (
370 FSP_GLOBAL_DATA
*FspData
;
372 FspData
= GetFspGlobalDataPointer ();
373 return FspData
->SiliconInitUpdPtr
;
378 Set FSP measurement point timestamp.
380 @param[in] Id Measurement point ID.
382 @return performance timestamp.
390 FSP_GLOBAL_DATA
*FspData
;
393 // Bit [55: 0] will be the timestamp
394 // Bit [63:56] will be the ID
396 FspData
= GetFspGlobalDataPointer ();
397 if (FspData
->PerfIdx
< sizeof(FspData
->PerfData
) / sizeof(FspData
->PerfData
[0])) {
398 FspData
->PerfData
[FspData
->PerfIdx
] = AsmReadTsc ();
399 ((UINT8
*)(&FspData
->PerfData
[FspData
->PerfIdx
]))[7] = Id
;
402 return FspData
->PerfData
[(FspData
->PerfIdx
)++];
406 This function gets the FSP info header pointer.
408 @retval FspInfoHeader FSP info header pointer
416 return GetFspGlobalDataPointer()->FspInfoHeader
;
420 This function gets the FSP info header pointer using the API stack context.
422 @retval FspInfoHeader FSP info header pointer using the API stack context
426 GetFspInfoHeaderFromApiContext (
430 FSP_GLOBAL_DATA
*FspData
;
432 FspData
= GetFspGlobalDataPointer ();
433 return (FSP_INFO_HEADER
*)(*(UINT32
*)(UINTN
)(FspData
->CoreStack
+ CONTEXT_STACK_OFFSET(FspInfoHeader
)));
437 This function gets the VPD data pointer.
439 @return VpdDataRgnPtr VPD data pointer.
443 GetFspVpdDataPointer (
447 FSP_INFO_HEADER
*FspInfoHeader
;
449 FspInfoHeader
= GetFspInfoHeader ();
450 return (VOID
*)(FspInfoHeader
->ImageBase
+ FspInfoHeader
->CfgRegionOffset
);
454 This function gets FSP API calling mode.
456 @retval API calling mode
460 GetFspApiCallingMode (
464 return GetFspGlobalDataPointer()->ApiMode
;
468 This function sets FSP API calling mode.
470 @param[in] Mode API calling mode
474 SetFspApiCallingMode (
478 FSP_GLOBAL_DATA
*FspData
;
480 FspData
= GetFspGlobalDataPointer ();
481 FspData
->ApiMode
= Mode
;