TianoCore EDK2 master
Loading...
Searching...
No Matches
SecFsp.c
Go to the documentation of this file.
1
8#include "SecFsp.h"
9
19IA32_IDT_GATE_DESCRIPTOR
21 IN UINT64 IdtEntryTemplate
22 )
23{
24 UINT32 Entry;
25 IA32_IDT_GATE_DESCRIPTOR ExceptionHandler;
26 IA32_IDT_GATE_DESCRIPTOR *IdtGateDescriptor;
27 FSP_INFO_HEADER *FspInfoHeader;
28
29 ZeroMem ((VOID *)&ExceptionHandler, sizeof (IA32_IDT_GATE_DESCRIPTOR));
30 FspInfoHeader = (FSP_INFO_HEADER *)(UINTN)AsmGetFspInfoHeader ();
31 *(UINT64 *) &ExceptionHandler = IdtEntryTemplate;
32 IdtGateDescriptor = &ExceptionHandler;
33 Entry = (IdtGateDescriptor->Bits.OffsetHigh << 16) | IdtGateDescriptor->Bits.OffsetLow;
34 Entry = FspInfoHeader->ImageBase + FspInfoHeader->ImageSize - (~Entry + 1);
35 IdtGateDescriptor->Bits.OffsetHigh = (UINT16)(Entry >> 16);
36 IdtGateDescriptor->Bits.OffsetLow = (UINT16)Entry;
37
38 return ExceptionHandler;
39}
40
47VOID
48EFIAPI
50 IN OUT FSP_GLOBAL_DATA *FspData
51 )
52{
53 FSP_PLAT_DATA *FspPlatformData;
54 UINT32 TopOfCar;
55 UINT32 *StackPtr;
56 UINT32 DataSize;
57 UINT32 TemporaryRamSize;
58
59 FspPlatformData = &FspData->PlatformData;
60
61 //
62 // The entries of platform information, together with the number of them,
63 // reside in the bottom of stack, left untouched by normal stack operation.
64 //
65
66 FspPlatformData->DataPtr = NULL;
67 FspPlatformData->MicrocodeRegionBase = 0;
68 FspPlatformData->MicrocodeRegionSize = 0;
69 FspPlatformData->CodeRegionBase = 0;
70 FspPlatformData->CodeRegionSize = 0;
71 TemporaryRamSize = 0;
72
73 //
74 // Pointer to the size field
75 //
76 TopOfCar = PcdGet32 (PcdTemporaryRamBase) + PcdGet32 (PcdTemporaryRamSize);
77 StackPtr = (UINT32 *)(TopOfCar - sizeof (UINT32));
78 if ((*(StackPtr - 1) != FSP_MCUD_SIGNATURE) && (FspData->FspInfoHeader->ImageAttribute & BIT4)) {
79 ReadTemporaryRamSize (PcdGet32 (PcdTemporaryRamBase), &TemporaryRamSize);
80 if (TemporaryRamSize) {
81 TopOfCar = PcdGet32 (PcdTemporaryRamBase) + TemporaryRamSize;
82 StackPtr = (UINT32 *)(TopOfCar - sizeof (UINT32));
83 }
84 }
85
86 if (*(StackPtr - 1) == FSP_MCUD_SIGNATURE) {
87 while (*StackPtr != 0) {
88 if (*(StackPtr - 1) == FSP_MCUD_SIGNATURE) {
89 //
90 // This following data was pushed onto stack after TempRamInit API
91 //
92 DataSize = *(StackPtr);
93 DataSize = DataSize / sizeof (DataSize);
94 StackPtr -= DataSize;
95 CopyMem (&(FspPlatformData->MicrocodeRegionBase), StackPtr + 1, 4 * sizeof (UINTN));
96 } else if (*(StackPtr - 1) == FSP_PER0_SIGNATURE) {
97 //
98 // This is the performance data for InitTempMemory API entry/exit
99 //
100 DataSize = *(StackPtr);
101 DataSize = DataSize / sizeof (DataSize);
102 StackPtr -= DataSize;
103 CopyMem (FspData->PerfData, StackPtr + 1, 2 * sizeof (UINT64)); // Copy from the end of the PER0 data
104
105 ((UINT8 *)(&FspData->PerfData[0]))[7] = FSP_PERF_ID_API_TEMP_RAM_INIT_ENTRY;
106 ((UINT8 *)(&FspData->PerfData[1]))[7] = FSP_PERF_ID_API_TEMP_RAM_INIT_EXIT;
107 } else {
108 StackPtr -= (*StackPtr);
109 }
110 }
111 }
112}
113
124VOID
126 IN OUT FSP_GLOBAL_DATA *PeiFspData,
127 IN UINTN BootLoaderStack,
128 IN UINT8 ApiIdx
129 )
130{
131 VOID *FspmUpdDataPtr;
132 CHAR8 ImageId[9];
133 UINTN Idx;
134
135 //
136 // Set FSP Global Data pointer
137 //
138 SetFspGlobalDataPointer (PeiFspData);
139 ZeroMem ((VOID *)PeiFspData, sizeof (FSP_GLOBAL_DATA));
140
141 PeiFspData->Signature = FSP_GLOBAL_DATA_SIGNATURE;
142 PeiFspData->Version = FSP_GLOBAL_DATA_VERSION;
143 PeiFspData->CoreStack = BootLoaderStack;
144 PeiFspData->PerfIdx = 2;
145 PeiFspData->PerfSig = FSP_PERFORMANCE_DATA_SIGNATURE;
146 //
147 // Cache FspHobList pointer passed by bootloader via ApiParameter2
148 //
149 PeiFspData->FspHobListPtr = (VOID **)GetFspApiParameter2 ();
150
151 SetFspMeasurePoint (FSP_PERF_ID_API_FSP_MEMORY_INIT_ENTRY);
152
153 //
154 // Get FSP Header offset
155 // It may have multiple FVs, so look into the last one for FSP header
156 //
157 PeiFspData->FspInfoHeader = (FSP_INFO_HEADER *)(UINTN)AsmGetFspInfoHeader ();
158 SecGetPlatformData (PeiFspData);
159
160 //
161 // Set API calling mode
162 //
163 SetFspApiCallingIndex (ApiIdx);
164
165 //
166 // Set UPD pointer
167 //
168 FspmUpdDataPtr = (VOID *)GetFspApiParameter ();
169 if (FspmUpdDataPtr == NULL) {
170 FspmUpdDataPtr = (VOID *)(UINTN)(PeiFspData->FspInfoHeader->ImageBase + PeiFspData->FspInfoHeader->CfgRegionOffset);
171 }
172
173 SetFspUpdDataPointer (FspmUpdDataPtr);
174 SetFspMemoryInitUpdDataPointer (FspmUpdDataPtr);
176
177 //
178 // Initialize OnSeparateStack value.
179 //
180 if (PcdGet8 (PcdFspHeapSizePercentage) != 0) {
181 //
182 // FSP is running on its own stack and may need switching stack when calling bootloader functions.
183 //
184 GetFspGlobalDataPointer ()->OnSeparateStack = 1;
185 }
186
187 //
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
191 // for safe.
192 //
194
195 //
196 // Ensure the global data pointer is valid
197 //
198 ASSERT (GetFspGlobalDataPointer () == PeiFspData);
199
200 for (Idx = 0; Idx < 8; Idx++) {
201 ImageId[Idx] = PeiFspData->FspInfoHeader->ImageId[Idx];
202 }
203
204 ImageId[Idx] = 0;
205
206 DEBUG ((
207 DEBUG_INFO | DEBUG_INIT,
208 "\n============= FSP Spec v%d.%d Header Revision v%x (%a v%x.%x.%x.%x) =============\n", \
209 (PeiFspData->FspInfoHeader->SpecVersion >> 4) & 0xF, \
210 PeiFspData->FspInfoHeader->SpecVersion & 0xF, \
211 PeiFspData->FspInfoHeader->HeaderRevision, \
212 ImageId, \
213 (PeiFspData->FspInfoHeader->ImageRevision >> 24) & 0xFF, \
214 (PeiFspData->FspInfoHeader->ImageRevision >> 16) & 0xFF, \
215 (PeiFspData->FspInfoHeader->HeaderRevision >= 6) ? \
216 (((PeiFspData->FspInfoHeader->ImageRevision >> 8) & 0xFF) | (PeiFspData->FspInfoHeader->ExtendedImageRevision & 0xFF00)) : \
217 ((PeiFspData->FspInfoHeader->ImageRevision >> 8) & 0xFF), \
218 (PeiFspData->FspInfoHeader->HeaderRevision >= 6) ? \
219 ((PeiFspData->FspInfoHeader->ImageRevision & 0xFF) | ((PeiFspData->FspInfoHeader->ExtendedImageRevision & 0xFF) << 8)) : \
220 (PeiFspData->FspInfoHeader->ImageRevision & 0xFF)
221 ));
222}
223
231VOID
233 IN UINTN OffsetGap
234 )
235{
236 FSP_GLOBAL_DATA *NewFspData;
237
238 NewFspData = (FSP_GLOBAL_DATA *)((UINTN)GetFspGlobalDataPointer () + (UINTN)OffsetGap);
239 SetFspGlobalDataPointer (NewFspData);
240}
UINT64 UINTN
RETURN_STATUS EFIAPI SerialPortInitialize(VOID)
Definition: SerialPortLib.c:25
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
FSP_GLOBAL_DATA *EFIAPI GetFspGlobalDataPointer(VOID)
Definition: FspCommonLib.c:73
VOID EFIAPI SetFspMemoryInitUpdDataPointer(IN VOID *MemoryInitUpdPtr)
Definition: FspCommonLib.c:285
UINTN EFIAPI GetFspApiParameter2(VOID)
Definition: FspCommonLib.c:124
VOID EFIAPI SetFspUpdDataPointer(IN VOID *UpdDataPtr)
Definition: FspCommonLib.c:244
UINTN EFIAPI GetFspApiParameter(VOID)
Definition: FspCommonLib.c:90
VOID EFIAPI SetFspGlobalDataPointer(IN FSP_GLOBAL_DATA *FspData)
Definition: FspCommonLib.c:59
UINT64 EFIAPI SetFspMeasurePoint(IN UINT8 Id)
Definition: FspCommonLib.c:411
VOID EFIAPI SetFspApiCallingIndex(UINT8 Index)
Definition: FspCommonLib.c:514
VOID EFIAPI SetFspSiliconInitUpdDataPointer(IN VOID *SiliconInitUpdPtr)
Definition: FspCommonLib.c:326
VOID EFIAPI ReadTemporaryRamSize(IN UINT32 TemporaryRamBase, OUT UINT32 *TemporaryRamSize)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define PcdGet8(TokenName)
Definition: PcdLib.h:336
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
IA32_IDT_GATE_DESCRIPTOR FspGetExceptionHandler(IN UINT64 IdtEntryTemplate)
Definition: SecFsp.c:20
VOID FspDataPointerFixUp(IN UINTN OffsetGap)
Definition: SecFsp.c:232
VOID EFIAPI SecGetPlatformData(IN OUT FSP_GLOBAL_DATA *FspData)
Definition: SecFsp.c:49
VOID FspGlobalDataInit(IN OUT FSP_GLOBAL_DATA *PeiFspData, IN UINTN BootLoaderStack, IN UINT8 ApiIdx)
Definition: SecFsp.c:125
UINTN EFIAPI AsmGetFspInfoHeader(VOID)