]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFsp2Pkg/FspSecCore/SecFsp.c
IntelFsp2Pkg: Remove CarBase and CarSize from FSP_GLOBAL_DATA
[mirror_edk2.git] / IntelFsp2Pkg / FspSecCore / SecFsp.c
CommitLineData
cf1d4549
JY
1/** @file\r
2\r
3 Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>\r
4 This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php.\r
8\r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12**/\r
13\r
14#include "SecFsp.h"\r
15\r
16/**\r
17\r
18 Calculate the FSP IDT gate descriptor.\r
19\r
20 @param[in] IdtEntryTemplate IDT gate descriptor template.\r
21\r
22 @return FSP specific IDT gate descriptor.\r
23\r
24**/\r
25UINT64\r
26FspGetExceptionHandler(\r
27 IN UINT64 IdtEntryTemplate\r
28 )\r
29{\r
30 UINT32 Entry;\r
31 UINT64 ExceptionHandler;\r
32 IA32_IDT_GATE_DESCRIPTOR *IdtGateDescriptor;\r
33 FSP_INFO_HEADER *FspInfoHeader;\r
34\r
35 FspInfoHeader = (FSP_INFO_HEADER *)AsmGetFspInfoHeader();\r
36 ExceptionHandler = IdtEntryTemplate;\r
37 IdtGateDescriptor = (IA32_IDT_GATE_DESCRIPTOR *)&ExceptionHandler;\r
38 Entry = (IdtGateDescriptor->Bits.OffsetHigh << 16) | IdtGateDescriptor->Bits.OffsetLow;\r
39 Entry = FspInfoHeader->ImageBase + FspInfoHeader->ImageSize - (~Entry + 1);\r
40 IdtGateDescriptor->Bits.OffsetHigh = (UINT16)(Entry >> 16);\r
41 IdtGateDescriptor->Bits.OffsetLow = (UINT16)Entry;\r
42\r
43 return ExceptionHandler;\r
44}\r
45\r
46/**\r
47 This interface fills platform specific data.\r
48\r
49 @param[in,out] FspData Pointer to the FSP global data.\r
50\r
51**/\r
52VOID\r
53EFIAPI\r
54SecGetPlatformData (\r
55 IN OUT FSP_GLOBAL_DATA *FspData\r
56 )\r
57{\r
58 FSP_PLAT_DATA *FspPlatformData;\r
59 UINT32 TopOfCar;\r
60 UINT32 *StackPtr;\r
61 UINT32 DwordSize;\r
62\r
63 FspPlatformData = &FspData->PlatformData;\r
64\r
65 //\r
66 // The entries of platform information, together with the number of them,\r
67 // reside in the bottom of stack, left untouched by normal stack operation.\r
68 //\r
69\r
70 FspPlatformData->DataPtr = NULL;\r
71 FspPlatformData->MicrocodeRegionBase = 0;\r
72 FspPlatformData->MicrocodeRegionSize = 0;\r
73 FspPlatformData->CodeRegionBase = 0;\r
74 FspPlatformData->CodeRegionSize = 0;\r
75\r
76 //\r
77 // Pointer to the size field\r
78 //\r
40bc7509 79 TopOfCar = PcdGet32(PcdTemporaryRamBase) + PcdGet32(PcdTemporaryRamSize);\r
cf1d4549
JY
80 StackPtr = (UINT32 *)(TopOfCar - sizeof (UINT32));\r
81\r
82 if (*(StackPtr - 1) == FSP_MCUD_SIGNATURE) {\r
83 while (*StackPtr != 0) {\r
84 if (*(StackPtr - 1) == FSP_MCUD_SIGNATURE) {\r
85 //\r
86 // This following data was pushed onto stack after TempRamInit API\r
87 //\r
88 DwordSize = 4;\r
89 StackPtr = StackPtr - 1 - DwordSize;\r
90 CopyMem (&(FspPlatformData->MicrocodeRegionBase), StackPtr, (DwordSize << 2));\r
91 StackPtr--;\r
92 } else if (*(StackPtr - 1) == FSP_PER0_SIGNATURE) {\r
93 //\r
94 // This is the performance data for InitTempMemory API entry/exit\r
95 //\r
96 DwordSize = 4;\r
97 StackPtr = StackPtr - 1 - DwordSize;\r
98 CopyMem (FspData->PerfData, StackPtr, (DwordSize << 2));\r
99\r
100 ((UINT8 *)(&FspData->PerfData[0]))[7] = FSP_PERF_ID_API_TEMP_RAM_INIT_ENTRY;\r
101 ((UINT8 *)(&FspData->PerfData[1]))[7] = FSP_PERF_ID_API_TEMP_RAM_INIT_EXIT;\r
102\r
103 StackPtr--;\r
104 } else {\r
105 StackPtr -= (*StackPtr);\r
106 }\r
107 }\r
108 }\r
109}\r
110\r
111/**\r
112\r
113 Initialize the FSP global data region.\r
114 It needs to be done as soon as possible after the stack is setup.\r
115\r
116 @param[in,out] PeiFspData Pointer of the FSP global data.\r
117 @param[in] BootLoaderStack BootLoader stack.\r
118 @param[in] ApiIdx The index of the FSP API.\r
119\r
120**/\r
121VOID\r
122FspGlobalDataInit (\r
123 IN OUT FSP_GLOBAL_DATA *PeiFspData,\r
124 IN UINT32 BootLoaderStack,\r
125 IN UINT8 ApiIdx\r
126 )\r
127{\r
128 VOID *FspmUpdDataPtr;\r
129 CHAR8 ImageId[9];\r
130 UINTN Idx;\r
131\r
132 //\r
133 // Set FSP Global Data pointer\r
134 //\r
135 SetFspGlobalDataPointer (PeiFspData);\r
136 ZeroMem ((VOID *)PeiFspData, sizeof(FSP_GLOBAL_DATA));\r
137\r
138 PeiFspData->Signature = FSP_GLOBAL_DATA_SIGNATURE;\r
139 PeiFspData->Version = 0;\r
140 PeiFspData->CoreStack = BootLoaderStack;\r
141 PeiFspData->PerfIdx = 2;\r
142 PeiFspData->PerfSig = FSP_PERFORMANCE_DATA_SIGNATURE;\r
cf1d4549
JY
143\r
144 SetFspMeasurePoint (FSP_PERF_ID_API_FSP_MEMORY_INIT_ENTRY);\r
145\r
146 //\r
147 // Get FSP Header offset\r
148 // It may have multiple FVs, so look into the last one for FSP header\r
149 //\r
150 PeiFspData->FspInfoHeader = (FSP_INFO_HEADER *)AsmGetFspInfoHeader();\r
151 SecGetPlatformData (PeiFspData);\r
152\r
153 //\r
154 // Set API calling mode\r
155 //\r
156 SetFspApiCallingIndex (ApiIdx);\r
157 \r
158 //\r
159 // Set UPD pointer\r
160 //\r
161 FspmUpdDataPtr = (VOID *) GetFspApiParameter ();\r
162 if (FspmUpdDataPtr == NULL) {\r
163 FspmUpdDataPtr = (VOID *)(PeiFspData->FspInfoHeader->ImageBase + PeiFspData->FspInfoHeader->CfgRegionOffset);\r
164 }\r
165 SetFspUpdDataPointer (FspmUpdDataPtr);\r
166 SetFspMemoryInitUpdDataPointer (FspmUpdDataPtr);\r
167 SetFspSiliconInitUpdDataPointer (NULL);\r
168\r
169 //\r
170 // Initialize serial port\r
171 // It might have been done in ProcessLibraryConstructorList(), however,\r
172 // the FSP global data is not initialized at that time. So do it again\r
173 // for safe.\r
174 //\r
175 SerialPortInitialize ();\r
176\r
177 //\r
178 // Ensure the golbal data pointer is valid\r
179 //\r
180 ASSERT (GetFspGlobalDataPointer () == PeiFspData);\r
181\r
182 for (Idx = 0; Idx < 8; Idx++) {\r
183 ImageId[Idx] = PeiFspData->FspInfoHeader->ImageId[Idx];\r
184 }\r
185 ImageId[Idx] = 0;\r
186\r
187 DEBUG ((DEBUG_INFO | DEBUG_INIT, "\n============= FSP Spec v%d.%d Header Revision v%x (%a v%x.%x.%x.%x) =============\n", \\r
188 (PeiFspData->FspInfoHeader->SpecVersion >> 4) & 0xF, \\r
189 PeiFspData->FspInfoHeader->SpecVersion & 0xF, \\r
190 PeiFspData->FspInfoHeader->HeaderRevision, \\r
191 ImageId, \\r
192 (PeiFspData->FspInfoHeader->ImageRevision >> 24) & 0xFF, \\r
193 (PeiFspData->FspInfoHeader->ImageRevision >> 16) & 0xFF, \\r
194 (PeiFspData->FspInfoHeader->ImageRevision >> 8) & 0xFF, \\r
195 PeiFspData->FspInfoHeader->ImageRevision & 0xFF));\r
196}\r
197\r
198/**\r
199\r
200 Adjust the FSP data pointers after the stack is migrated to memory.\r
201\r
202 @param[in] OffsetGap The offset gap between the old stack and the new stack.\r
203\r
204**/\r
205VOID\r
206FspDataPointerFixUp (\r
207 IN UINT32 OffsetGap\r
208 )\r
209{\r
210 FSP_GLOBAL_DATA *NewFspData;\r
211\r
212 NewFspData = (FSP_GLOBAL_DATA *)((UINTN)GetFspGlobalDataPointer() + (UINTN)OffsetGap);\r
213 SetFspGlobalDataPointer (NewFspData);\r
214}\r