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.
16 UINT32 FspImageSizeOffset
= FSP_INFO_HEADER_OFF
+ OFFSET_IN_FSP_INFO_HEADER(ImageSize
);
20 Calculate the FSP IDT gate descriptor.
22 @param[in] IdtEntryTemplate IDT gate descriptor template.
24 @return FSP specific IDT gate descriptor.
28 FspGetExceptionHandler(
29 IN UINT64 IdtEntryTemplate
33 UINT64 ExceptionHandler
;
34 IA32_IDT_GATE_DESCRIPTOR
*IdtGateDescriptor
;
35 FSP_INFO_HEADER
*FspInfoHeader
;
37 FspInfoHeader
= (FSP_INFO_HEADER
*)(GetFspBaseAddress() + FSP_INFO_HEADER_OFF
);
38 ExceptionHandler
= IdtEntryTemplate
;
39 IdtGateDescriptor
= (IA32_IDT_GATE_DESCRIPTOR
*)&ExceptionHandler
;
40 Entry
= (IdtGateDescriptor
->Bits
.OffsetHigh
<< 16) | IdtGateDescriptor
->Bits
.OffsetLow
;
41 Entry
= FspInfoHeader
->ImageBase
+ FspInfoHeader
->ImageSize
- (~Entry
+ 1);
42 IdtGateDescriptor
->Bits
.OffsetHigh
= (UINT16
)(Entry
>> 16);
43 IdtGateDescriptor
->Bits
.OffsetLow
= (UINT16
)Entry
;
45 return ExceptionHandler
;
49 This function gets the FSP UPD region offset in flash.
51 @return the offset of the UPD region.
56 GetFspUpdRegionOffset (
60 FSP_GLOBAL_DATA
*FspData
;
63 FspData
= GetFspGlobalDataPointer ();
66 // It is required to put PcdUpdRegionOffset at offset 0x000C
68 // gPlatformFspPkgTokenSpaceGuid.PcdUpdRegionOffset | 0x000C | 0x12345678
70 Offset
= (UINT32
*)(FspData
->FspInfoHeader
->ImageBase
+ \
71 FspData
->FspInfoHeader
->CfgRegionOffset
+ 0x0C);
77 This interface fills platform specific data.
79 @param[in,out] FspData Pointer to the FSP global data.
85 IN OUT FSP_GLOBAL_DATA
*FspData
88 FSP_PLAT_DATA
*FspPlatformData
;
93 FspPlatformData
= &FspData
->PlatformData
;
96 // The entries of platform information, together with the number of them,
97 // reside in the bottom of stack, left untouched by normal stack operation.
99 TopOfCar
= PcdGet32 (PcdTemporaryRamBase
) + PcdGet32 (PcdTemporaryRamSize
);
101 FspPlatformData
->DataPtr
= NULL
;
102 FspPlatformData
->CodeRegionSize
= 0;
103 FspPlatformData
->CodeRegionBase
= 0;
104 FspPlatformData
->MicorcodeRegionBase
= 0;
105 FspPlatformData
->MicorcodeRegionSize
= 0;
108 // Pointer to the size field
110 StackPtr
= (UINT32
*)(TopOfCar
- sizeof(UINT32
));
112 while (*StackPtr
!= 0) {
113 if (*(StackPtr
- 1) == FSP_MCUD_SIGNATURE
) {
115 // This following data was pushed onto stack after TempRamInit API
118 StackPtr
= StackPtr
- 1 - DwordSize
;
119 CopyMem (&(FspPlatformData
->CodeRegionBase
), StackPtr
, (DwordSize
<< 2));
121 } else if (*(StackPtr
- 1) == FSP_PER0_SIGNATURE
) {
123 // This is the performance data for InitTempMemory API entry/exit
126 StackPtr
= StackPtr
- 1 - DwordSize
;
127 CopyMem (FspData
->PerfData
, StackPtr
, (DwordSize
<< 2));
128 ((UINT8
*)(&FspData
->PerfData
[0]))[7] = FSP_PERF_ID_API_TMPRAMINIT_ENTRY
;
129 ((UINT8
*)(&FspData
->PerfData
[1]))[7] = FSP_PERF_ID_API_TMPRAMINIT_EXIT
;
132 StackPtr
-= (*StackPtr
);
139 Initialize the FSP global data region.
140 It needs to be done as soon as possible after the stack is setup.
142 @param[in,out] PeiFspData Pointer of the FSP global data.
143 @param[in] BootFirmwareVolume Point to the address of BootFirmwareVolume in stack.
148 IN OUT FSP_GLOBAL_DATA
*PeiFspData
,
149 IN VOID
**BootFirmwareVolume
153 FSP_INIT_PARAMS
*FspInitParams
;
158 // Init PCIE_BAR with value and set global FSP data pointer.
159 // PciExpress Base should have been programmed by platform already.
161 SetFspGlobalDataPointer (PeiFspData
);
162 ZeroMem ((VOID
*)PeiFspData
, sizeof(FSP_GLOBAL_DATA
));
164 PeiFspData
->Signature
= FSP_GLOBAL_DATA_SIGNATURE
;
165 PeiFspData
->CoreStack
= *(UINTN
*)(BootFirmwareVolume
+ 2);
166 PeiFspData
->PerfIdx
= 2;
168 SetFspMeasurePoint (FSP_PERF_ID_API_FSPINIT_ENTRY
);
171 // Get FSP Header offset
172 // It may have multiple FVs, so look into the last one for FSP header
174 PeiFspData
->FspInfoHeader
= (FSP_INFO_HEADER
*)(GetFspBaseAddress() + FSP_INFO_HEADER_OFF
);
175 SecGetPlatformData (PeiFspData
);
178 // Initialize UPD pointer.
180 FspInitParams
= (FSP_INIT_PARAMS
*)GetFspApiParameter ();
181 UpdDataRgnPtr
= ((FSP_INIT_RT_COMMON_BUFFER
*)FspInitParams
->RtBufferPtr
)->UpdDataRgnPtr
;
182 if (UpdDataRgnPtr
== NULL
) {
183 UpdDataRgnPtr
= (VOID
*)(PeiFspData
->FspInfoHeader
->ImageBase
+ GetFspUpdRegionOffset());
185 SetFspUpdDataPointer (UpdDataRgnPtr
);
188 // Initialize serial port
189 // It might have been done in ProcessLibraryConstructorList(), however,
190 // the FSP global data is not initialized at that time. So do it again
193 SerialPortInitialize ();
196 // Ensure the golbal data pointer is valid
198 ASSERT (GetFspGlobalDataPointer () == PeiFspData
);
200 for (Idx
= 0; Idx
< 8; Idx
++) {
201 ImageId
[Idx
] = PeiFspData
->FspInfoHeader
->ImageId
[Idx
];
205 DEBUG ((DEBUG_INFO
| DEBUG_INIT
, "\n============= PEIM FSP (%a 0x%08X) =============\n", \
206 ImageId
, PeiFspData
->FspInfoHeader
->ImageRevision
));
212 Adjust the FSP data pointers after the stack is migrated to memory.
214 @param[in] OffsetGap The offset gap between the old stack and the new stack.
218 FspDataPointerFixUp (
222 FSP_GLOBAL_DATA
*NewFspData
;
224 NewFspData
= (FSP_GLOBAL_DATA
*)((UINTN
)GetFspGlobalDataPointer() + (UINTN
)OffsetGap
);
225 SetFspGlobalDataPointer (NewFspData
);
229 This function check the FSP API calling condition.
231 @param[in] ApiIdx Internal index of the FSP API.
241 FSP_GLOBAL_DATA
*FspData
;
243 Status
= EFI_SUCCESS
;
244 FspData
= GetFspGlobalDataPointer ();
249 if ((UINT32
)FspData
!= 0xFFFFFFFF) {
250 Status
= EFI_UNSUPPORTED
;
252 } else if (ApiIdx
== 2) {
256 if ((FspData
== NULL
) || ((UINT32
)FspData
== 0xFFFFFFFF)) {
257 Status
= EFI_UNSUPPORTED
;
259 if (FspData
->Signature
!= FSP_GLOBAL_DATA_SIGNATURE
) {
260 Status
= EFI_UNSUPPORTED
;
264 Status
= EFI_UNSUPPORTED
;