TianoCore EDK2 master
Loading...
Searching...
No Matches
FspCommonLib.c
Go to the documentation of this file.
1
8#include <PiPei.h>
9#include <Library/BaseLib.h>
10#include <Library/DebugLib.h>
11#include <Library/PcdLib.h>
12#include <FspGlobalData.h>
13#include <FspEas.h>
15
16#pragma pack(1)
17
18typedef struct {
19 UINT16 IdtrLimit;
20 UINT32 IdtrBase;
21 UINT16 Reserved;
22 UINT32 Cr0;
23 UINT32 Cr3;
24 UINT32 Cr4;
25 UINT32 Efer; // lower 32-bit of EFER since only NXE bit (BIT11) need to be restored.
26 UINT32 Registers[8]; // General Purpose Registers: Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx and Eax
27 UINT16 Flags[2];
28 UINT32 FspInfoHeader;
29 UINT32 ApiRet;
30 UINT32 ApiParam[2];
32
33typedef struct {
34 UINT64 Idtr[2]; // IDTR Limit - bit0:bi15, IDTR Base - bit16:bit79
35 UINT64 Cr0;
36 UINT64 Cr3;
37 UINT64 Cr4;
38 UINT64 Efer;
39 UINT64 Registers[16]; // General Purpose Registers: RDI, RSI, RBP, RSP, RBX, RDX, RCX, RAX, and R15 to R8
40 UINT32 Flags[2];
41 UINT64 FspInfoHeader;
42 UINT64 ApiParam[2];
43 UINT64 Reserved; // The reserved QWORD is needed for stack alignment in X64.
44 UINT64 ApiRet; // 64bit stack format is different from the 32bit one due to x64 calling convention
46
47#define CONTEXT_STACK_OFFSET(x) (sizeof(UINTN) == sizeof (UINT32) ? (UINTN)&((CONTEXT_STACK *)(UINTN)0)->x : (UINTN)&((CONTEXT_STACK_64 *)(UINTN)0)->x)
48
49#pragma pack()
50
57VOID
58EFIAPI
60 IN FSP_GLOBAL_DATA *FspData
61 )
62{
63 ASSERT (FspData != NULL);
64 *((volatile UINT32 *)(UINTN)PcdGet32 (PcdGlobalDataPointerAddress)) = (UINT32)(UINTN)FspData;
65}
66
72EFIAPI
74 VOID
75 )
76{
77 UINT32 FspDataAddress;
78
79 FspDataAddress = *(UINT32 *)(UINTN)PcdGet32 (PcdGlobalDataPointerAddress);
80 return (FSP_GLOBAL_DATA *)(UINTN)FspDataAddress;
81}
82
89EFIAPI
91 VOID
92 )
93{
94 FSP_GLOBAL_DATA *FspData;
95
96 FspData = GetFspGlobalDataPointer ();
97 return *(UINTN *)(FspData->CoreStack + CONTEXT_STACK_OFFSET (ApiParam[0]));
98}
99
105VOID *
106EFIAPI
108 VOID
109 )
110{
111 FSP_GLOBAL_DATA *FspData;
112
113 FspData = GetFspGlobalDataPointer ();
114 return (VOID *)(FspData->CoreStack + CONTEXT_STACK_OFFSET (ApiParam[0]));
115}
116
122UINTN
123EFIAPI
125 VOID
126 )
127{
128 FSP_GLOBAL_DATA *FspData;
129
130 FspData = GetFspGlobalDataPointer ();
131 return *(UINTN *)(FspData->CoreStack + CONTEXT_STACK_OFFSET (ApiParam[1]));
132}
133
140VOID
141EFIAPI
143 IN UINT32 Value
144 )
145{
146 FSP_GLOBAL_DATA *FspData;
147
148 FspData = GetFspGlobalDataPointer ();
149 *(UINTN *)(FspData->CoreStack + CONTEXT_STACK_OFFSET (ApiParam)) = Value;
150}
151
158VOID
159EFIAPI
161 IN UINTN ReturnStatus
162 )
163{
164 FSP_GLOBAL_DATA *FspData;
165
166 FspData = GetFspGlobalDataPointer ();
167 *(UINTN *)(FspData->CoreStack + CONTEXT_STACK_OFFSET (Registers[7])) = ReturnStatus;
168}
169
176VOID
177EFIAPI
179 IN VOID *NewStackTop
180 )
181{
182 FSP_GLOBAL_DATA *FspData;
183 UINTN *OldStack;
184 UINTN *NewStack;
185 UINT32 StackContextLen;
186
187 FspData = GetFspGlobalDataPointer ();
188 StackContextLen = sizeof (CONTEXT_STACK) / sizeof (UINTN);
189
190 //
191 // Reserve space for the ContinuationFunc two parameters
192 //
193 OldStack = (UINTN *)FspData->CoreStack;
194 NewStack = (UINTN *)NewStackTop - StackContextLen - 2;
195 FspData->CoreStack = (UINTN)NewStack;
196 while (StackContextLen-- != 0) {
197 *NewStack++ = *OldStack++;
198 }
199}
200
207VOID
208EFIAPI
210 IN VOID *PlatformData
211 )
212{
213 FSP_GLOBAL_DATA *FspData;
214
215 FspData = GetFspGlobalDataPointer ();
216 FspData->PlatformData.DataPtr = PlatformData;
217}
218
225VOID *
226EFIAPI
228 VOID
229 )
230{
231 FSP_GLOBAL_DATA *FspData;
232
233 FspData = GetFspGlobalDataPointer ();
234 return FspData->PlatformData.DataPtr;
235}
236
242VOID
243EFIAPI
245 IN VOID *UpdDataPtr
246 )
247{
248 FSP_GLOBAL_DATA *FspData;
249
250 //
251 // Get the FSP Global Data Pointer
252 //
253 FspData = GetFspGlobalDataPointer ();
254
255 //
256 // Set the UPD pointer.
257 //
258 FspData->UpdDataPtr = UpdDataPtr;
259}
260
266VOID *
267EFIAPI
269 VOID
270 )
271{
272 FSP_GLOBAL_DATA *FspData;
273
274 FspData = GetFspGlobalDataPointer ();
275 return FspData->UpdDataPtr;
276}
277
283VOID
284EFIAPI
286 IN VOID *MemoryInitUpdPtr
287 )
288{
289 FSP_GLOBAL_DATA *FspData;
290
291 //
292 // Get the FSP Global Data Pointer
293 //
294 FspData = GetFspGlobalDataPointer ();
295
296 //
297 // Set the FspMemoryInit UPD pointer.
298 //
299 FspData->MemoryInitUpdPtr = MemoryInitUpdPtr;
300}
301
307VOID *
308EFIAPI
310 VOID
311 )
312{
313 FSP_GLOBAL_DATA *FspData;
314
315 FspData = GetFspGlobalDataPointer ();
316 return FspData->MemoryInitUpdPtr;
317}
318
324VOID
325EFIAPI
327 IN VOID *SiliconInitUpdPtr
328 )
329{
330 FSP_GLOBAL_DATA *FspData;
331
332 //
333 // Get the FSP Global Data Pointer
334 //
335 FspData = GetFspGlobalDataPointer ();
336
337 //
338 // Set the FspSiliconInit UPD data pointer.
339 //
340 FspData->SiliconInitUpdPtr = SiliconInitUpdPtr;
341}
342
348VOID *
349EFIAPI
351 VOID
352 )
353{
354 FSP_GLOBAL_DATA *FspData;
355
356 FspData = GetFspGlobalDataPointer ();
357 return FspData->SiliconInitUpdPtr;
358}
359
365VOID
366EFIAPI
368 IN VOID *SmmInitUpdPtr
369 )
370{
371 FSP_GLOBAL_DATA *FspData;
372
373 //
374 // Get the FSP Global Data Pointer
375 //
376 FspData = GetFspGlobalDataPointer ();
377
378 //
379 // Set the FspSmmInit UPD data pointer.
380 //
381 FspData->SmmInitUpdPtr = SmmInitUpdPtr;
382}
383
389VOID *
390EFIAPI
392 VOID
393 )
394{
395 FSP_GLOBAL_DATA *FspData;
396
397 FspData = GetFspGlobalDataPointer ();
398 return FspData->SmmInitUpdPtr;
399}
400
409UINT64
410EFIAPI
412 IN UINT8 Id
413 )
414{
415 FSP_GLOBAL_DATA *FspData;
416
417 //
418 // Bit [55: 0] will be the timestamp
419 // Bit [63:56] will be the ID
420 //
421 FspData = GetFspGlobalDataPointer ();
422 if (FspData->PerfIdx < sizeof (FspData->PerfData) / sizeof (FspData->PerfData[0])) {
423 FspData->PerfData[FspData->PerfIdx] = AsmReadTsc ();
424 ((UINT8 *)(&FspData->PerfData[FspData->PerfIdx]))[7] = Id;
425 return FspData->PerfData[(FspData->PerfIdx)++];
426 }
427
428 return 0;
429}
430
437EFIAPI
439 VOID
440 )
441{
442 return GetFspGlobalDataPointer ()->FspInfoHeader;
443}
444
450VOID
451EFIAPI
453 FSP_INFO_HEADER *FspInfoHeader
454 )
455{
456 GetFspGlobalDataPointer ()->FspInfoHeader = FspInfoHeader;
457}
458
465EFIAPI
467 VOID
468 )
469{
470 FSP_GLOBAL_DATA *FspData;
471
472 FspData = GetFspGlobalDataPointer ();
473 return (FSP_INFO_HEADER *)(*(UINTN *)(FspData->CoreStack + CONTEXT_STACK_OFFSET (FspInfoHeader)));
474}
475
481VOID *
482EFIAPI
484 VOID
485 )
486{
487 FSP_INFO_HEADER *FspInfoHeader;
488
489 FspInfoHeader = GetFspInfoHeader ();
490 return (VOID *)(UINTN)(FspInfoHeader->ImageBase + FspInfoHeader->CfgRegionOffset);
491}
492
498UINT8
499EFIAPI
501 VOID
502 )
503{
504 return GetFspGlobalDataPointer ()->ApiIdx;
505}
506
512VOID
513EFIAPI
515 UINT8 Index
516 )
517{
518 FSP_GLOBAL_DATA *FspData;
519
520 FspData = GetFspGlobalDataPointer ();
521 FspData->ApiIdx = Index;
522}
523
529UINT32
530EFIAPI
532 VOID
533 )
534{
536}
537
543VOID
544EFIAPI
546 UINT32 StatusCode
547 )
548{
549 FSP_GLOBAL_DATA *FspData;
550
551 FspData = GetFspGlobalDataPointer ();
552 FspData->StatusCode = StatusCode;
553}
UINT64 UINTN
UINT64 EFIAPI AsmReadTsc(VOID)
Definition: GccInline.c:555
VOID EFIAPI SetFspApiReturnStatus(IN UINTN ReturnStatus)
Definition: FspCommonLib.c:160
FSP_GLOBAL_DATA *EFIAPI GetFspGlobalDataPointer(VOID)
Definition: FspCommonLib.c:73
UINT8 EFIAPI GetFspApiCallingIndex(VOID)
Definition: FspCommonLib.c:500
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
FSP_INFO_HEADER *EFIAPI GetFspInfoHeaderFromApiContext(VOID)
Definition: FspCommonLib.c:466
VOID *EFIAPI GetFspCfgRegionDataPointer(VOID)
Definition: FspCommonLib.c:483
VOID *EFIAPI GetFspSiliconInitUpdDataPointer(VOID)
Definition: FspCommonLib.c:350
UINT64 EFIAPI SetFspMeasurePoint(IN UINT8 Id)
Definition: FspCommonLib.c:411
UINT32 EFIAPI GetPhaseStatusCode(VOID)
Definition: FspCommonLib.c:531
VOID EFIAPI SetPhaseStatusCode(UINT32 StatusCode)
Definition: FspCommonLib.c:545
VOID EFIAPI SetFspSmmInitUpdDataPointer(IN VOID *SmmInitUpdPtr)
Definition: FspCommonLib.c:367
VOID EFIAPI SetFspApiCallingIndex(UINT8 Index)
Definition: FspCommonLib.c:514
VOID *EFIAPI GetFspEntryStack(VOID)
Definition: FspCommonLib.c:107
FSP_INFO_HEADER *EFIAPI GetFspInfoHeader(VOID)
Definition: FspCommonLib.c:438
VOID *EFIAPI GetFspUpdDataPointer(VOID)
Definition: FspCommonLib.c:268
VOID EFIAPI SetFspApiParameter(IN UINT32 Value)
Definition: FspCommonLib.c:142
VOID EFIAPI SetFspInfoHeader(FSP_INFO_HEADER *FspInfoHeader)
Definition: FspCommonLib.c:452
VOID *EFIAPI GetFspMemoryInitUpdDataPointer(VOID)
Definition: FspCommonLib.c:309
VOID *EFIAPI GetFspSmmInitUpdDataPointer(VOID)
Definition: FspCommonLib.c:391
VOID EFIAPI SetFspSiliconInitUpdDataPointer(IN VOID *SiliconInitUpdPtr)
Definition: FspCommonLib.c:326
VOID EFIAPI SetFspCoreStackPointer(IN VOID *NewStackTop)
Definition: FspCommonLib.c:178
VOID EFIAPI SetFspPlatformDataPointer(IN VOID *PlatformData)
Definition: FspCommonLib.c:209
VOID *EFIAPI GetFspPlatformDataPointer(VOID)
Definition: FspCommonLib.c:227
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
FSP_PLAT_DATA PlatformData
Definition: FspGlobalData.h:74
UINT32 CfgRegionOffset