]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/SmramSaveInfoHandlerSmm/SmramSaveInfoHandlerSmm.c
Vlv2TbltDevicePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / Vlv2TbltDevicePkg / SmramSaveInfoHandlerSmm / SmramSaveInfoHandlerSmm.c
1 /** @file
2 A helper driver to save information to SMRAM after SMRR is enabled.
3
4 This driver is for ECP platforms.
5
6 Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
7
8 SPDX-License-Identifier: BSD-2-Clause-Patent
9
10
11
12 **/
13
14 #include <PiSmm.h>
15 #include <Library/DebugLib.h>
16 #include <Library/UefiDriverEntryPoint.h>
17 #include <Library/UefiRuntimeServicesTableLib.h>
18 #include <Library/SmmServicesTableLib.h>
19 #include <Library/BaseLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/IoLib.h>
22 #include <Protocol/SmmSwDispatch.h>
23 #include <Protocol/SmmReadyToLock.h>
24 #include <Protocol/SmmControl.h>
25 #include <Guid/Vlv2DeviceRefCodePkgTokenSpace.h>
26
27 #define SMM_FROM_SMBASE_DRIVER 0x55
28 #define SMM_FROM_CPU_DRIVER_SAVE_INFO 0x81
29
30 #define EFI_SMRAM_CPU_NVS_HEADER_GUID \
31 { \
32 0x429501d9, 0xe447, 0x40f4, 0x86, 0x7b, 0x75, 0xc9, 0x3a, 0x1d, 0xb5, 0x4e \
33 }
34
35 UINT8 mSmiDataRegister;
36 BOOLEAN mLocked = FALSE;
37 EFI_GUID mSmramCpuNvsHeaderGuid = EFI_SMRAM_CPU_NVS_HEADER_GUID;
38
39 /**
40 Dispatch function for a Software SMI handler.
41
42 @param DispatchHandle The handle of this dispatch function.
43 @param DispatchContext The pointer to the dispatch function's context.
44 The SwSmiInputValue field is filled in
45 by the software dispatch driver prior to
46 invoking this dispatch function.
47 The dispatch function will only be called
48 for input values for which it is registered.
49
50 @return None
51
52 **/
53 VOID
54 EFIAPI
55 SmramSaveInfoHandler (
56 IN EFI_HANDLE DispatchHandle,
57 IN EFI_SMM_SW_DISPATCH_CONTEXT *DispatchContext
58 )
59 {
60 ASSERT (DispatchContext != NULL);
61 ASSERT (DispatchContext->SwSmiInputValue == SMM_FROM_SMBASE_DRIVER);
62
63 if (!mLocked && IoRead8 (mSmiDataRegister) == SMM_FROM_CPU_DRIVER_SAVE_INFO) {
64 CopyMem (
65 (VOID *)(UINTN)(PcdGetEx64 (&gEfiVLVTokenSpaceGuid, PcdCpuLockBoxDataAddress)),
66 (VOID *)(UINTN)(PcdGetEx64 (&gEfiVLVTokenSpaceGuid, PcdCpuSmramCpuDataAddress)),
67 (UINTN)(PcdGetEx64 (&gEfiVLVTokenSpaceGuid, PcdCpuLockBoxSize))
68 );
69 }
70 }
71
72 /**
73 Smm Ready To Lock event notification handler.
74
75 It sets a flag indicating that SMRAM has been locked.
76
77 @param[in] Protocol Points to the protocol's unique identifier.
78 @param[in] Interface Points to the interface instance.
79 @param[in] Handle The handle on which the interface was installed.
80
81 @retval EFI_SUCCESS Notification handler runs successfully.
82 **/
83 EFI_STATUS
84 EFIAPI
85 SmmReadyToLockEventNotify (
86 IN CONST EFI_GUID *Protocol,
87 IN VOID *Interface,
88 IN EFI_HANDLE Handle
89 )
90 {
91 mLocked = TRUE;
92 return EFI_SUCCESS;
93 }
94
95 /**
96 Entry point function of this driver.
97
98 @param[in] ImageHandle The firmware allocated handle for the EFI image.
99 @param[in] SystemTable A pointer to the EFI System Table.
100
101 @retval EFI_SUCCESS The entry point is executed successfully.
102 @retval other Some error occurs when executing this entry point.
103 **/
104 EFI_STATUS
105 EFIAPI
106 SmramSaveInfoHandlerSmmMain (
107 IN EFI_HANDLE ImageHandle,
108 IN EFI_SYSTEM_TABLE *SystemTable
109 )
110 {
111 EFI_STATUS Status;
112 EFI_SMM_SW_DISPATCH_PROTOCOL *SmmSwDispatch;
113 EFI_SMM_SW_DISPATCH_CONTEXT SmmSwDispatchContext;
114 EFI_HANDLE DispatchHandle;
115 EFI_SMM_CONTROL_PROTOCOL *SmmControl;
116 EFI_SMM_CONTROL_REGISTER SmmControlRegister;
117 VOID *Registration;
118
119 //
120 // Get SMI data register
121 //
122 Status = SystemTable->BootServices->LocateProtocol (
123 &gEfiSmmControlProtocolGuid,
124 NULL,
125 (VOID **)&SmmControl
126 );
127 ASSERT_EFI_ERROR (Status);
128 Status = SmmControl->GetRegisterInfo (SmmControl, &SmmControlRegister);
129 ASSERT_EFI_ERROR (Status);
130 mSmiDataRegister = SmmControlRegister.SmiDataRegister;
131
132 //
133 // Register software SMI handler
134 //
135
136 Status = SystemTable->BootServices->LocateProtocol (
137 &gEfiSmmSwDispatchProtocolGuid,
138 NULL,
139 (VOID **)&SmmSwDispatch
140 );
141 ASSERT_EFI_ERROR (Status);
142
143 SmmSwDispatchContext.SwSmiInputValue = SMM_FROM_SMBASE_DRIVER;
144 Status = SmmSwDispatch->Register (
145 SmmSwDispatch,
146 &SmramSaveInfoHandler,
147 &SmmSwDispatchContext,
148 &DispatchHandle
149 );
150 ASSERT_EFI_ERROR (Status);
151
152 //
153 // Register SMM Ready To Lock Protocol notification
154 //
155 Status = gSmst->SmmRegisterProtocolNotify (
156 &gEfiSmmReadyToLockProtocolGuid,
157 SmmReadyToLockEventNotify,
158 &Registration
159 );
160 ASSERT_EFI_ERROR (Status);
161
162 return Status;
163 }
164