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