2 A helper driver to save information to SMRAM after SMRR is enabled.
4 This driver is for ECP platforms.
6 Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials are licensed and made available under
9 the terms and conditions of the BSD License that accompanies this distribution.
10 The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php.
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include <Library/DebugLib.h>
21 #include <Library/UefiDriverEntryPoint.h>
22 #include <Library/UefiRuntimeServicesTableLib.h>
23 #include <Library/SmmServicesTableLib.h>
24 #include <Library/BaseLib.h>
25 #include <Library/BaseMemoryLib.h>
26 #include <Library/IoLib.h>
27 #include <Protocol/SmmSwDispatch.h>
28 #include <Protocol/SmmReadyToLock.h>
29 #include <Protocol/SmmControl.h>
30 #include <Guid/Vlv2DeviceRefCodePkgTokenSpace.h>
32 #define SMM_FROM_SMBASE_DRIVER 0x55
33 #define SMM_FROM_CPU_DRIVER_SAVE_INFO 0x81
35 #define EFI_SMRAM_CPU_NVS_HEADER_GUID \
37 0x429501d9, 0xe447, 0x40f4, 0x86, 0x7b, 0x75, 0xc9, 0x3a, 0x1d, 0xb5, 0x4e \
40 UINT8 mSmiDataRegister
;
41 BOOLEAN mLocked
= FALSE
;
42 EFI_GUID mSmramCpuNvsHeaderGuid
= EFI_SMRAM_CPU_NVS_HEADER_GUID
;
45 Dispatch function for a Software SMI handler.
47 @param DispatchHandle The handle of this dispatch function.
48 @param DispatchContext The pointer to the dispatch function's context.
49 The SwSmiInputValue field is filled in
50 by the software dispatch driver prior to
51 invoking this dispatch function.
52 The dispatch function will only be called
53 for input values for which it is registered.
60 SmramSaveInfoHandler (
61 IN EFI_HANDLE DispatchHandle
,
62 IN EFI_SMM_SW_DISPATCH_CONTEXT
*DispatchContext
65 ASSERT (DispatchContext
!= NULL
);
66 ASSERT (DispatchContext
->SwSmiInputValue
== SMM_FROM_SMBASE_DRIVER
);
68 if (!mLocked
&& IoRead8 (mSmiDataRegister
) == SMM_FROM_CPU_DRIVER_SAVE_INFO
) {
70 (VOID
*)(UINTN
)(PcdGetEx64 (&gEfiVLVTokenSpaceGuid
, PcdCpuLockBoxDataAddress
)),
71 (VOID
*)(UINTN
)(PcdGetEx64 (&gEfiVLVTokenSpaceGuid
, PcdCpuSmramCpuDataAddress
)),
72 (UINTN
)(PcdGetEx64 (&gEfiVLVTokenSpaceGuid
, PcdCpuLockBoxSize
))
78 Smm Ready To Lock event notification handler.
80 It sets a flag indicating that SMRAM has been locked.
82 @param[in] Protocol Points to the protocol's unique identifier.
83 @param[in] Interface Points to the interface instance.
84 @param[in] Handle The handle on which the interface was installed.
86 @retval EFI_SUCCESS Notification handler runs successfully.
90 SmmReadyToLockEventNotify (
91 IN CONST EFI_GUID
*Protocol
,
101 Entry point function of this driver.
103 @param[in] ImageHandle The firmware allocated handle for the EFI image.
104 @param[in] SystemTable A pointer to the EFI System Table.
106 @retval EFI_SUCCESS The entry point is executed successfully.
107 @retval other Some error occurs when executing this entry point.
111 SmramSaveInfoHandlerSmmMain (
112 IN EFI_HANDLE ImageHandle
,
113 IN EFI_SYSTEM_TABLE
*SystemTable
117 EFI_SMM_SW_DISPATCH_PROTOCOL
*SmmSwDispatch
;
118 EFI_SMM_SW_DISPATCH_CONTEXT SmmSwDispatchContext
;
119 EFI_HANDLE DispatchHandle
;
120 EFI_SMM_CONTROL_PROTOCOL
*SmmControl
;
121 EFI_SMM_CONTROL_REGISTER SmmControlRegister
;
125 // Get SMI data register
127 Status
= SystemTable
->BootServices
->LocateProtocol (
128 &gEfiSmmControlProtocolGuid
,
132 ASSERT_EFI_ERROR (Status
);
133 Status
= SmmControl
->GetRegisterInfo (SmmControl
, &SmmControlRegister
);
134 ASSERT_EFI_ERROR (Status
);
135 mSmiDataRegister
= SmmControlRegister
.SmiDataRegister
;
138 // Register software SMI handler
141 Status
= SystemTable
->BootServices
->LocateProtocol (
142 &gEfiSmmSwDispatchProtocolGuid
,
144 (VOID
**)&SmmSwDispatch
146 ASSERT_EFI_ERROR (Status
);
148 SmmSwDispatchContext
.SwSmiInputValue
= SMM_FROM_SMBASE_DRIVER
;
149 Status
= SmmSwDispatch
->Register (
151 &SmramSaveInfoHandler
,
152 &SmmSwDispatchContext
,
155 ASSERT_EFI_ERROR (Status
);
158 // Register SMM Ready To Lock Protocol notification
160 Status
= gSmst
->SmmRegisterProtocolNotify (
161 &gEfiSmmReadyToLockProtocolGuid
,
162 SmmReadyToLockEventNotify
,
165 ASSERT_EFI_ERROR (Status
);