]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/SmramSaveInfoHandlerSmm/SmramSaveInfoHandlerSmm.c
MdeModulePkg/PciSioSerial: Fix bad EOL
[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 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.
12
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.
15
16
17 **/
18
19 #include <PiSmm.h>
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>
31
32 #define SMM_FROM_SMBASE_DRIVER 0x55
33 #define SMM_FROM_CPU_DRIVER_SAVE_INFO 0x81
34
35 #define EFI_SMRAM_CPU_NVS_HEADER_GUID \
36 { \
37 0x429501d9, 0xe447, 0x40f4, 0x86, 0x7b, 0x75, 0xc9, 0x3a, 0x1d, 0xb5, 0x4e \
38 }
39
40 UINT8 mSmiDataRegister;
41 BOOLEAN mLocked = FALSE;
42 EFI_GUID mSmramCpuNvsHeaderGuid = EFI_SMRAM_CPU_NVS_HEADER_GUID;
43
44 /**
45 Dispatch function for a Software SMI handler.
46
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.
54
55 @return None
56
57 **/
58 VOID
59 EFIAPI
60 SmramSaveInfoHandler (
61 IN EFI_HANDLE DispatchHandle,
62 IN EFI_SMM_SW_DISPATCH_CONTEXT *DispatchContext
63 )
64 {
65 ASSERT (DispatchContext != NULL);
66 ASSERT (DispatchContext->SwSmiInputValue == SMM_FROM_SMBASE_DRIVER);
67
68 if (!mLocked && IoRead8 (mSmiDataRegister) == SMM_FROM_CPU_DRIVER_SAVE_INFO) {
69 CopyMem (
70 (VOID *)(UINTN)(PcdGetEx64 (&gEfiVLVTokenSpaceGuid, PcdCpuLockBoxDataAddress)),
71 (VOID *)(UINTN)(PcdGetEx64 (&gEfiVLVTokenSpaceGuid, PcdCpuSmramCpuDataAddress)),
72 (UINTN)(PcdGetEx64 (&gEfiVLVTokenSpaceGuid, PcdCpuLockBoxSize))
73 );
74 }
75 }
76
77 /**
78 Smm Ready To Lock event notification handler.
79
80 It sets a flag indicating that SMRAM has been locked.
81
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.
85
86 @retval EFI_SUCCESS Notification handler runs successfully.
87 **/
88 EFI_STATUS
89 EFIAPI
90 SmmReadyToLockEventNotify (
91 IN CONST EFI_GUID *Protocol,
92 IN VOID *Interface,
93 IN EFI_HANDLE Handle
94 )
95 {
96 mLocked = TRUE;
97 return EFI_SUCCESS;
98 }
99
100 /**
101 Entry point function of this driver.
102
103 @param[in] ImageHandle The firmware allocated handle for the EFI image.
104 @param[in] SystemTable A pointer to the EFI System Table.
105
106 @retval EFI_SUCCESS The entry point is executed successfully.
107 @retval other Some error occurs when executing this entry point.
108 **/
109 EFI_STATUS
110 EFIAPI
111 SmramSaveInfoHandlerSmmMain (
112 IN EFI_HANDLE ImageHandle,
113 IN EFI_SYSTEM_TABLE *SystemTable
114 )
115 {
116 EFI_STATUS Status;
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;
122 VOID *Registration;
123
124 //
125 // Get SMI data register
126 //
127 Status = SystemTable->BootServices->LocateProtocol (
128 &gEfiSmmControlProtocolGuid,
129 NULL,
130 (VOID **)&SmmControl
131 );
132 ASSERT_EFI_ERROR (Status);
133 Status = SmmControl->GetRegisterInfo (SmmControl, &SmmControlRegister);
134 ASSERT_EFI_ERROR (Status);
135 mSmiDataRegister = SmmControlRegister.SmiDataRegister;
136
137 //
138 // Register software SMI handler
139 //
140
141 Status = SystemTable->BootServices->LocateProtocol (
142 &gEfiSmmSwDispatchProtocolGuid,
143 NULL,
144 (VOID **)&SmmSwDispatch
145 );
146 ASSERT_EFI_ERROR (Status);
147
148 SmmSwDispatchContext.SwSmiInputValue = SMM_FROM_SMBASE_DRIVER;
149 Status = SmmSwDispatch->Register (
150 SmmSwDispatch,
151 &SmramSaveInfoHandler,
152 &SmmSwDispatchContext,
153 &DispatchHandle
154 );
155 ASSERT_EFI_ERROR (Status);
156
157 //
158 // Register SMM Ready To Lock Protocol notification
159 //
160 Status = gSmst->SmmRegisterProtocolNotify (
161 &gEfiSmmReadyToLockProtocolGuid,
162 SmmReadyToLockEventNotify,
163 &Registration
164 );
165 ASSERT_EFI_ERROR (Status);
166
167 return Status;
168 }
169