]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFspWrapperPkg/Library/SecPeiFspPlatformSecLibSample/SaveSecContext.c
DynamicTablesPkg: GTDT updates for ACPI 6.3
[mirror_edk2.git] / IntelFspWrapperPkg / Library / SecPeiFspPlatformSecLibSample / SaveSecContext.c
1 /** @file
2 Sample to provide SaveSecContext function.
3
4 Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9
10 #include <PiPei.h>
11 #include <Library/DebugLib.h>
12
13 #include <Ppi/TopOfTemporaryRam.h>
14 #include <Ppi/SecPlatformInformation.h>
15
16 /**
17 Save BIST value before call FspInit.
18
19 @param[in] Bist BIST value.
20 **/
21 VOID
22 AsmSaveBistValue (
23 IN UINT32 Bist
24 );
25
26 /**
27 Save Ticker value before call FspInit.
28
29 @param[in] Ticker Ticker value.
30 **/
31 VOID
32 AsmSaveTickerValue (
33 IN UINT64 Ticker
34 );
35
36 /**
37 Save SEC context before call FspInit.
38
39 @param[in] PeiServices Pointer to PEI Services Table.
40 **/
41 VOID
42 EFIAPI
43 SaveSecContext (
44 IN CONST EFI_PEI_SERVICES **PeiServices
45 )
46 {
47 UINT32 *Bist;
48 UINT64 *Ticker;
49 UINT32 Size;
50 UINT32 Count;
51 UINT32 TopOfTemporaryRam;
52 VOID *TopOfTemporaryRamPpi;
53 EFI_STATUS Status;
54
55 DEBUG ((DEBUG_INFO, "SaveSecContext - 0x%x\n", PeiServices));
56
57 Status = (*PeiServices)->LocatePpi (
58 PeiServices,
59 &gTopOfTemporaryRamPpiGuid,
60 0,
61 NULL,
62 (VOID **) &TopOfTemporaryRamPpi
63 );
64 if (EFI_ERROR (Status)) {
65 return ;
66 }
67
68 DEBUG ((DEBUG_INFO, "TopOfTemporaryRamPpi - 0x%x\n", TopOfTemporaryRamPpi));
69
70 //
71 // The entries of BIST information, together with the number of them,
72 // reside in the bottom of stack, left untouched by normal stack operation.
73 // This routine copies the BIST information to the buffer pointed by
74 // PlatformInformationRecord for output.
75 //
76 // |--------------| <- TopOfTemporaryRam
77 // |Number of BSPs|
78 // |--------------|
79 // | BIST |
80 // |--------------|
81 // | .... |
82 // |--------------|
83 // | TSC[63:32] |
84 // |--------------|
85 // | TSC[31:00] |
86 // |--------------|
87 //
88
89 TopOfTemporaryRam = (UINT32)(UINTN)TopOfTemporaryRamPpi - sizeof(UINT32);
90 TopOfTemporaryRam -= sizeof(UINT32) * 2;
91 DEBUG ((DEBUG_INFO, "TopOfTemporaryRam - 0x%x\n", TopOfTemporaryRam));
92 Count = *(UINT32 *)(UINTN)(TopOfTemporaryRam - sizeof(UINT32));
93 DEBUG ((DEBUG_INFO, "Count - 0x%x\n", Count));
94 Size = Count * sizeof (IA32_HANDOFF_STATUS);
95 DEBUG ((DEBUG_INFO, "Size - 0x%x\n", Size));
96
97 Bist = (UINT32 *)(UINTN)(TopOfTemporaryRam - sizeof(UINT32) - Size);
98 DEBUG ((DEBUG_INFO, "Bist - 0x%x\n", *Bist));
99 Ticker = (UINT64 *)(UINTN)(TopOfTemporaryRam - sizeof(UINT32) - Size - sizeof(UINT64));
100 DEBUG ((DEBUG_INFO, "Ticker - 0x%lx\n", *Ticker));
101
102 // Just need record BSP
103 AsmSaveBistValue (*Bist);
104 AsmSaveTickerValue (*Ticker);
105 }