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 <FspDataTable.h>
21 #include <Library/FspSwitchStackLib.h>
26 // API Parameter +0x34
27 // API return address +0x30
29 // push FspInfoHeader +0x2C
34 // sidt fword ptr [esp]
54 #define CONTEXT_STACK_OFFSET(x) (UINT32)&((CONTEXT_STACK *)(UINTN)0)->x
59 This function sets the FSP global data pointer.
61 @param[in] FspData Fsp global data pointer.
66 SetFspGlobalDataPointer (
67 IN FSP_GLOBAL_DATA
*FspData
70 ASSERT (FspData
!= NULL
);
71 *((volatile UINT32
*)(UINTN
)PcdGet32(PcdGlobalDataPointerAddress
)) = (UINT32
)(UINTN
)FspData
;
75 This function gets the FSP global data pointer.
80 GetFspGlobalDataPointer (
84 FSP_GLOBAL_DATA
*FspData
;
86 FspData
= *(FSP_GLOBAL_DATA
**)(UINTN
)PcdGet32(PcdGlobalDataPointerAddress
);
91 This function gets back the FSP API first parameter passed by the bootlaoder.
93 @retval ApiParameter FSP API first parameter passed by the bootlaoder.
101 FSP_GLOBAL_DATA
*FspData
;
103 FspData
= GetFspGlobalDataPointer ();
104 return *(UINT32
*)(UINTN
)(FspData
->CoreStack
+ CONTEXT_STACK_OFFSET(ApiParam
[0]));
108 This function gets back the FSP API second parameter passed by the bootlaoder.
110 @retval ApiParameter FSP API second parameter passed by the bootlaoder.
114 GetFspApiParameter2 (
118 FSP_GLOBAL_DATA
*FspData
;
120 FspData
= GetFspGlobalDataPointer ();
121 return *(UINT32
*)(UINTN
)(FspData
->CoreStack
+ CONTEXT_STACK_OFFSET(ApiParam
[1]));
125 This function sets the FSP API parameter in the stack.
127 @param[in] Value New parameter value.
136 FSP_GLOBAL_DATA
*FspData
;
138 FspData
= GetFspGlobalDataPointer ();
139 *(UINT32
*)(UINTN
)(FspData
->CoreStack
+ CONTEXT_STACK_OFFSET(ApiParam
)) = Value
;
143 This function set the API status code returned to the BootLoader.
145 @param[in] ReturnStatus Status code to return.
150 SetFspApiReturnStatus (
151 IN UINT32 ReturnStatus
154 FSP_GLOBAL_DATA
*FspData
;
156 FspData
= GetFspGlobalDataPointer ();
157 *(UINT32
*)(UINTN
)(FspData
->CoreStack
+ CONTEXT_STACK_OFFSET(Eax
)) = ReturnStatus
;
161 This function sets the context switching stack to a new stack frame.
163 @param[in] NewStackTop New core stack to be set.
168 SetFspCoreStackPointer (
172 FSP_GLOBAL_DATA
*FspData
;
175 UINT32 StackContextLen
;
177 FspData
= GetFspGlobalDataPointer ();
178 StackContextLen
= sizeof(CONTEXT_STACK
) / sizeof(UINT32
);
181 // Reserve space for the ContinuationFunc two parameters
183 OldStack
= (UINT32
*)FspData
->CoreStack
;
184 NewStack
= (UINT32
*)NewStackTop
- StackContextLen
- 2;
185 FspData
->CoreStack
= (UINT32
)NewStack
;
186 while (StackContextLen
-- != 0) {
187 *NewStack
++ = *OldStack
++;
192 This function sets the platform specific data pointer.
194 @param[in] PlatformData Fsp platform specific data pointer.
199 SetFspPlatformDataPointer (
200 IN VOID
*PlatformData
203 FSP_GLOBAL_DATA
*FspData
;
205 FspData
= GetFspGlobalDataPointer ();
206 FspData
->PlatformData
.DataPtr
= PlatformData
;
211 This function gets the platform specific data pointer.
213 @param[in] PlatformData Fsp platform specific data pointer.
218 GetFspPlatformDataPointer (
222 FSP_GLOBAL_DATA
*FspData
;
224 FspData
= GetFspGlobalDataPointer ();
225 return FspData
->PlatformData
.DataPtr
;
230 This function sets the UPD data pointer.
232 @param[in] UpdDataPtr UPD data pointer.
236 SetFspUpdDataPointer (
240 FSP_GLOBAL_DATA
*FspData
;
243 // Get the Fsp Global Data Pointer
245 FspData
= GetFspGlobalDataPointer ();
248 // Set the UPD pointer.
250 FspData
->UpdDataPtr
= UpdDataPtr
;
254 This function gets the UPD data pointer.
256 @return UpdDataPtr UPD data pointer.
260 GetFspUpdDataPointer (
264 FSP_GLOBAL_DATA
*FspData
;
266 FspData
= GetFspGlobalDataPointer ();
267 return FspData
->UpdDataPtr
;
272 This function sets the memory init UPD data pointer.
274 @param[in] MemoryInitUpdPtr memory init UPD data pointer.
278 SetFspMemoryInitUpdDataPointer (
279 IN VOID
*MemoryInitUpdPtr
282 FSP_GLOBAL_DATA
*FspData
;
285 // Get the Fsp Global Data Pointer
287 FspData
= GetFspGlobalDataPointer ();
290 // Set the memory init UPD pointer.
292 FspData
->MemoryInitUpdPtr
= MemoryInitUpdPtr
;
296 This function gets the memory init UPD data pointer.
298 @return memory init UPD data pointer.
302 GetFspMemoryInitUpdDataPointer (
306 FSP_GLOBAL_DATA
*FspData
;
308 FspData
= GetFspGlobalDataPointer ();
309 return FspData
->MemoryInitUpdPtr
;
314 This function sets the silicon init UPD data pointer.
316 @param[in] SiliconInitUpdPtr silicon init UPD data pointer.
320 SetFspSiliconInitUpdDataPointer (
321 IN VOID
*SiliconInitUpdPtr
324 FSP_GLOBAL_DATA
*FspData
;
327 // Get the Fsp Global Data Pointer
329 FspData
= GetFspGlobalDataPointer ();
332 // Set the silicon init UPD data pointer.
334 FspData
->SiliconInitUpdPtr
= SiliconInitUpdPtr
;
338 This function gets the silicon init UPD data pointer.
340 @return silicon init UPD data pointer.
344 GetFspSiliconInitUpdDataPointer (
348 FSP_GLOBAL_DATA
*FspData
;
350 FspData
= GetFspGlobalDataPointer ();
351 return FspData
->SiliconInitUpdPtr
;
356 Set FSP measurement point timestamp.
358 @param[in] Id Measurement point ID.
360 @return performance timestamp.
368 FSP_GLOBAL_DATA
*FspData
;
371 // Bit [55: 0] will be the timestamp
372 // Bit [63:56] will be the ID
374 FspData
= GetFspGlobalDataPointer ();
375 if (FspData
->PerfIdx
< sizeof(FspData
->PerfData
) / sizeof(FspData
->PerfData
[0])) {
376 FspData
->PerfData
[FspData
->PerfIdx
] = AsmReadTsc ();
377 ((UINT8
*)(&FspData
->PerfData
[FspData
->PerfIdx
]))[7] = Id
;
380 return FspData
->PerfData
[(FspData
->PerfIdx
)++];
384 This function gets the FSP info header pointer.
386 @retval FspInfoHeader FSP info header pointer
394 return GetFspGlobalDataPointer()->FspInfoHeader
;
398 This function sets the FSP info header pointer.
400 @param[in] FspInfoHeader FSP info header pointer
405 FSP_INFO_HEADER
*FspInfoHeader
408 GetFspGlobalDataPointer()->FspInfoHeader
= FspInfoHeader
;
412 This function gets the FSP info header pointer using the API stack context.
414 @retval FspInfoHeader FSP info header pointer using the API stack context
418 GetFspInfoHeaderFromApiContext (
422 FSP_GLOBAL_DATA
*FspData
;
424 FspData
= GetFspGlobalDataPointer ();
425 return (FSP_INFO_HEADER
*)(*(UINT32
*)(UINTN
)(FspData
->CoreStack
+ CONTEXT_STACK_OFFSET(FspInfoHeader
)));
429 This function gets the CfgRegion data pointer.
431 @return CfgRegion data pointer.
435 GetFspCfgRegionDataPointer (
439 FSP_INFO_HEADER
*FspInfoHeader
;
441 FspInfoHeader
= GetFspInfoHeader ();
442 return (VOID
*)(FspInfoHeader
->ImageBase
+ FspInfoHeader
->CfgRegionOffset
);
446 This function gets FSP API calling index.
448 @retval API calling index
452 GetFspApiCallingIndex (
456 return GetFspGlobalDataPointer()->ApiIdx
;
460 This function sets FSP API calling mode.
462 @param[in] Index API calling index
466 SetFspApiCallingIndex (
470 FSP_GLOBAL_DATA
*FspData
;
472 FspData
= GetFspGlobalDataPointer ();
473 FspData
->ApiIdx
= Index
;
477 This function gets FSP Phase StatusCode.
487 return GetFspGlobalDataPointer()->StatusCode
;
491 This function sets FSP Phase StatusCode.
493 @param[in] Mode Phase StatusCode
501 FSP_GLOBAL_DATA
*FspData
;
503 FspData
= GetFspGlobalDataPointer ();
504 FspData
->StatusCode
= StatusCode
;
508 This function updates the return status of the FSP API with requested reset type and returns to Boot Loader.
510 @param[in] FspResetType Reset type that needs to returned as API return status
515 FspApiReturnStatusReset (
516 IN UINT32 FspResetType
519 volatile BOOLEAN LoopUntilReset
;
521 LoopUntilReset
= TRUE
;
522 DEBUG ((DEBUG_INFO
, "FSP returning control to Bootloader with reset required return status %x\n",FspResetType
));
524 /// Below code is not an infinite loop.The control will go back to API calling function in BootLoader each time BootLoader
525 /// calls the FSP API without honoring the reset request by FSP
528 SetFspApiReturnStatus ((EFI_STATUS
)FspResetType
);
529 Pei2LoaderSwitchStack ();
530 DEBUG ((DEBUG_ERROR
, "!!!ERROR: FSP has requested BootLoader for reset. But BootLoader has not honored the reset\n"));
531 DEBUG ((DEBUG_ERROR
, "!!!ERROR: Please add support in BootLoader to honour the reset request from FSP\n"));
532 } while (LoopUntilReset
);