2 A helper driver to save information to SMRAM after SMRR is enabled.
4 This driver is for ECP platforms.
6 Copyright (c) 2010 - 2014, 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>
31 #define SMM_FROM_SMBASE_DRIVER 0x55
32 #define SMM_FROM_CPU_DRIVER_SAVE_INFO 0x81
34 #define EFI_SMRAM_CPU_NVS_HEADER_GUID \
36 0x429501d9, 0xe447, 0x40f4, 0x86, 0x7b, 0x75, 0xc9, 0x3a, 0x1d, 0xb5, 0x4e \
39 UINT8 mSmiDataRegister
;
40 BOOLEAN mLocked
= FALSE
;
41 EFI_GUID mSmramCpuNvsHeaderGuid
= EFI_SMRAM_CPU_NVS_HEADER_GUID
;
44 Dispatch function for a Software SMI handler.
46 @param DispatchHandle The handle of this dispatch function.
47 @param DispatchContext The pointer to the dispatch function's context.
48 The SwSmiInputValue field is filled in
49 by the software dispatch driver prior to
50 invoking this dispatch function.
51 The dispatch function will only be called
52 for input values for which it is registered.
59 SmramSaveInfoHandler (
60 IN EFI_HANDLE DispatchHandle
,
61 IN EFI_SMM_SW_DISPATCH_CONTEXT
*DispatchContext
68 ASSERT (DispatchContext
!= NULL
);
69 ASSERT (DispatchContext
->SwSmiInputValue
== SMM_FROM_SMBASE_DRIVER
);
71 if (!mLocked
&& IoRead8 (mSmiDataRegister
) == SMM_FROM_CPU_DRIVER_SAVE_INFO
) {
72 VarSize
= sizeof (VarData
);
73 Status
= gRT
->GetVariable (
75 &mSmramCpuNvsHeaderGuid
,
80 if (!EFI_ERROR (Status
) && VarSize
== sizeof (VarData
)) {
82 (VOID
*)(UINTN
)(VarData
[0]),
83 (VOID
*)(UINTN
)(VarData
[1]),
91 Smm Ready To Lock event notification handler.
93 It sets a flag indicating that SMRAM has been locked.
95 @param[in] Protocol Points to the protocol's unique identifier.
96 @param[in] Interface Points to the interface instance.
97 @param[in] Handle The handle on which the interface was installed.
99 @retval EFI_SUCCESS Notification handler runs successfully.
103 SmmReadyToLockEventNotify (
104 IN CONST EFI_GUID
*Protocol
,
114 Entry point function of this driver.
116 @param[in] ImageHandle The firmware allocated handle for the EFI image.
117 @param[in] SystemTable A pointer to the EFI System Table.
119 @retval EFI_SUCCESS The entry point is executed successfully.
120 @retval other Some error occurs when executing this entry point.
124 SmramSaveInfoHandlerSmmMain (
125 IN EFI_HANDLE ImageHandle
,
126 IN EFI_SYSTEM_TABLE
*SystemTable
130 EFI_SMM_SW_DISPATCH_PROTOCOL
*SmmSwDispatch
;
131 EFI_SMM_SW_DISPATCH_CONTEXT SmmSwDispatchContext
;
132 EFI_HANDLE DispatchHandle
;
133 EFI_SMM_CONTROL_PROTOCOL
*SmmControl
;
134 EFI_SMM_CONTROL_REGISTER SmmControlRegister
;
138 // Get SMI data register
140 Status
= SystemTable
->BootServices
->LocateProtocol (
141 &gEfiSmmControlProtocolGuid
,
145 ASSERT_EFI_ERROR (Status
);
146 Status
= SmmControl
->GetRegisterInfo (SmmControl
, &SmmControlRegister
);
147 ASSERT_EFI_ERROR (Status
);
148 mSmiDataRegister
= SmmControlRegister
.SmiDataRegister
;
151 // Register software SMI handler
154 Status
= SystemTable
->BootServices
->LocateProtocol (
155 &gEfiSmmSwDispatchProtocolGuid
,
157 (VOID
**)&SmmSwDispatch
159 ASSERT_EFI_ERROR (Status
);
161 SmmSwDispatchContext
.SwSmiInputValue
= SMM_FROM_SMBASE_DRIVER
;
162 Status
= SmmSwDispatch
->Register (
164 &SmramSaveInfoHandler
,
165 &SmmSwDispatchContext
,
168 ASSERT_EFI_ERROR (Status
);
171 // Register SMM Ready To Lock Protocol notification
173 Status
= gSmst
->SmmRegisterProtocolNotify (
174 &gEfiSmmReadyToLockProtocolGuid
,
175 SmmReadyToLockEventNotify
,
178 ASSERT_EFI_ERROR (Status
);