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 SPDX-License-Identifier: BSD-2-Clause-Patent
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>
27 #define SMM_FROM_SMBASE_DRIVER 0x55
28 #define SMM_FROM_CPU_DRIVER_SAVE_INFO 0x81
30 #define EFI_SMRAM_CPU_NVS_HEADER_GUID \
32 0x429501d9, 0xe447, 0x40f4, 0x86, 0x7b, 0x75, 0xc9, 0x3a, 0x1d, 0xb5, 0x4e \
35 UINT8 mSmiDataRegister
;
36 BOOLEAN mLocked
= FALSE
;
37 EFI_GUID mSmramCpuNvsHeaderGuid
= EFI_SMRAM_CPU_NVS_HEADER_GUID
;
40 Dispatch function for a Software SMI handler.
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.
55 SmramSaveInfoHandler (
56 IN EFI_HANDLE DispatchHandle
,
57 IN EFI_SMM_SW_DISPATCH_CONTEXT
*DispatchContext
60 ASSERT (DispatchContext
!= NULL
);
61 ASSERT (DispatchContext
->SwSmiInputValue
== SMM_FROM_SMBASE_DRIVER
);
63 if (!mLocked
&& IoRead8 (mSmiDataRegister
) == SMM_FROM_CPU_DRIVER_SAVE_INFO
) {
65 (VOID
*)(UINTN
)(PcdGetEx64 (&gEfiVLVTokenSpaceGuid
, PcdCpuLockBoxDataAddress
)),
66 (VOID
*)(UINTN
)(PcdGetEx64 (&gEfiVLVTokenSpaceGuid
, PcdCpuSmramCpuDataAddress
)),
67 (UINTN
)(PcdGetEx64 (&gEfiVLVTokenSpaceGuid
, PcdCpuLockBoxSize
))
73 Smm Ready To Lock event notification handler.
75 It sets a flag indicating that SMRAM has been locked.
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.
81 @retval EFI_SUCCESS Notification handler runs successfully.
85 SmmReadyToLockEventNotify (
86 IN CONST EFI_GUID
*Protocol
,
96 Entry point function of this driver.
98 @param[in] ImageHandle The firmware allocated handle for the EFI image.
99 @param[in] SystemTable A pointer to the EFI System Table.
101 @retval EFI_SUCCESS The entry point is executed successfully.
102 @retval other Some error occurs when executing this entry point.
106 SmramSaveInfoHandlerSmmMain (
107 IN EFI_HANDLE ImageHandle
,
108 IN EFI_SYSTEM_TABLE
*SystemTable
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
;
120 // Get SMI data register
122 Status
= SystemTable
->BootServices
->LocateProtocol (
123 &gEfiSmmControlProtocolGuid
,
127 ASSERT_EFI_ERROR (Status
);
128 Status
= SmmControl
->GetRegisterInfo (SmmControl
, &SmmControlRegister
);
129 ASSERT_EFI_ERROR (Status
);
130 mSmiDataRegister
= SmmControlRegister
.SmiDataRegister
;
133 // Register software SMI handler
136 Status
= SystemTable
->BootServices
->LocateProtocol (
137 &gEfiSmmSwDispatchProtocolGuid
,
139 (VOID
**)&SmmSwDispatch
141 ASSERT_EFI_ERROR (Status
);
143 SmmSwDispatchContext
.SwSmiInputValue
= SMM_FROM_SMBASE_DRIVER
;
144 Status
= SmmSwDispatch
->Register (
146 &SmramSaveInfoHandler
,
147 &SmmSwDispatchContext
,
150 ASSERT_EFI_ERROR (Status
);
153 // Register SMM Ready To Lock Protocol notification
155 Status
= gSmst
->SmmRegisterProtocolNotify (
156 &gEfiSmmReadyToLockProtocolGuid
,
157 SmmReadyToLockEventNotify
,
160 ASSERT_EFI_ERROR (Status
);