]> git.proxmox.com Git - mirror_edk2.git/blame - Vlv2TbltDevicePkg/SmramSaveInfoHandlerSmm/SmramSaveInfoHandlerSmm.c
MdeModulePkg: use 64 KB granularity for runtime allocations on AArch64
[mirror_edk2.git] / Vlv2TbltDevicePkg / SmramSaveInfoHandlerSmm / SmramSaveInfoHandlerSmm.c
CommitLineData
3cbfba02
DW
1/** @file\r
2 A helper driver to save information to SMRAM after SMRR is enabled.\r
3\r
4 This driver is for ECP platforms.\r
5\r
6 Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
7 \r\r
8 This program and the accompanying materials are licensed and made available under\r\r
9 the terms and conditions of the BSD License that accompanies this distribution. \r\r
10 The full text of the license may be found at \r\r
11 http://opensource.org/licenses/bsd-license.php. \r\r
12 \r\r
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r\r
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r\r
15 \r\r
16\r
17**/\r
18\r
19#include <PiSmm.h>\r
20#include <Library/DebugLib.h>\r
21#include <Library/UefiDriverEntryPoint.h>\r
22#include <Library/UefiRuntimeServicesTableLib.h>\r
23#include <Library/SmmServicesTableLib.h>\r
24#include <Library/BaseLib.h>\r
25#include <Library/BaseMemoryLib.h>\r
26#include <Library/IoLib.h>\r
27#include <Protocol/SmmSwDispatch.h>\r
28#include <Protocol/SmmReadyToLock.h>\r
29#include <Protocol/SmmControl.h>\r
30\r
31#define SMM_FROM_SMBASE_DRIVER 0x55\r
32#define SMM_FROM_CPU_DRIVER_SAVE_INFO 0x81\r
33\r
34#define EFI_SMRAM_CPU_NVS_HEADER_GUID \\r
35 { \\r
36 0x429501d9, 0xe447, 0x40f4, 0x86, 0x7b, 0x75, 0xc9, 0x3a, 0x1d, 0xb5, 0x4e \\r
37 }\r
38\r
39UINT8 mSmiDataRegister;\r
40BOOLEAN mLocked = FALSE;\r
41EFI_GUID mSmramCpuNvsHeaderGuid = EFI_SMRAM_CPU_NVS_HEADER_GUID;\r
42\r
43/**\r
44 Dispatch function for a Software SMI handler.\r
45\r
46 @param DispatchHandle The handle of this dispatch function.\r
47 @param DispatchContext The pointer to the dispatch function's context.\r
48 The SwSmiInputValue field is filled in\r
49 by the software dispatch driver prior to\r
50 invoking this dispatch function.\r
51 The dispatch function will only be called\r
52 for input values for which it is registered.\r
53\r
54 @return None\r
55\r
56**/\r
57VOID\r
58EFIAPI\r
59SmramSaveInfoHandler (\r
60 IN EFI_HANDLE DispatchHandle,\r
61 IN EFI_SMM_SW_DISPATCH_CONTEXT *DispatchContext\r
62 )\r
63{\r
64 EFI_STATUS Status;\r
65 UINT64 VarData[3];\r
66 UINTN VarSize;\r
67\r
68 ASSERT (DispatchContext != NULL);\r
69 ASSERT (DispatchContext->SwSmiInputValue == SMM_FROM_SMBASE_DRIVER);\r
70\r
71 if (!mLocked && IoRead8 (mSmiDataRegister) == SMM_FROM_CPU_DRIVER_SAVE_INFO) {\r
72 VarSize = sizeof (VarData);\r
73 Status = gRT->GetVariable (\r
74 L"SmramCpuNvs",\r
75 &mSmramCpuNvsHeaderGuid,\r
76 NULL,\r
77 &VarSize,\r
78 VarData\r
79 );\r
80 if (!EFI_ERROR (Status) && VarSize == sizeof (VarData)) {\r
81 CopyMem (\r
82 (VOID *)(UINTN)(VarData[0]),\r
83 (VOID *)(UINTN)(VarData[1]),\r
84 (UINTN)(VarData[2])\r
85 );\r
86 }\r
87 }\r
88}\r
89\r
90/**\r
91 Smm Ready To Lock event notification handler.\r
92\r
93 It sets a flag indicating that SMRAM has been locked.\r
94\r
95 @param[in] Protocol Points to the protocol's unique identifier.\r
96 @param[in] Interface Points to the interface instance.\r
97 @param[in] Handle The handle on which the interface was installed.\r
98\r
99 @retval EFI_SUCCESS Notification handler runs successfully.\r
100 **/\r
101EFI_STATUS\r
102EFIAPI\r
103SmmReadyToLockEventNotify (\r
104 IN CONST EFI_GUID *Protocol,\r
105 IN VOID *Interface,\r
106 IN EFI_HANDLE Handle\r
107 )\r
108{\r
109 mLocked = TRUE;\r
110 return EFI_SUCCESS;\r
111}\r
112\r
113/**\r
114 Entry point function of this driver.\r
115\r
116 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
117 @param[in] SystemTable A pointer to the EFI System Table.\r
118\r
119 @retval EFI_SUCCESS The entry point is executed successfully.\r
120 @retval other Some error occurs when executing this entry point.\r
121**/\r
122EFI_STATUS\r
123EFIAPI\r
124SmramSaveInfoHandlerSmmMain (\r
125 IN EFI_HANDLE ImageHandle,\r
126 IN EFI_SYSTEM_TABLE *SystemTable\r
127 )\r
128{\r
129 EFI_STATUS Status;\r
130 EFI_SMM_SW_DISPATCH_PROTOCOL *SmmSwDispatch;\r
131 EFI_SMM_SW_DISPATCH_CONTEXT SmmSwDispatchContext;\r
132 EFI_HANDLE DispatchHandle;\r
133 EFI_SMM_CONTROL_PROTOCOL *SmmControl;\r
134 EFI_SMM_CONTROL_REGISTER SmmControlRegister;\r
135 VOID *Registration;\r
136\r
137 //\r
138 // Get SMI data register\r
139 //\r
140 Status = SystemTable->BootServices->LocateProtocol (\r
141 &gEfiSmmControlProtocolGuid,\r
142 NULL,\r
143 (VOID **)&SmmControl\r
144 );\r
145 ASSERT_EFI_ERROR (Status);\r
146 Status = SmmControl->GetRegisterInfo (SmmControl, &SmmControlRegister);\r
147 ASSERT_EFI_ERROR (Status);\r
148 mSmiDataRegister = SmmControlRegister.SmiDataRegister;\r
149\r
150 //\r
151 // Register software SMI handler\r
152 //\r
153\r
154 Status = SystemTable->BootServices->LocateProtocol (\r
155 &gEfiSmmSwDispatchProtocolGuid,\r
156 NULL,\r
157 (VOID **)&SmmSwDispatch\r
158 );\r
159 ASSERT_EFI_ERROR (Status);\r
160\r
161 SmmSwDispatchContext.SwSmiInputValue = SMM_FROM_SMBASE_DRIVER;\r
162 Status = SmmSwDispatch->Register (\r
163 SmmSwDispatch,\r
164 &SmramSaveInfoHandler,\r
165 &SmmSwDispatchContext,\r
166 &DispatchHandle\r
167 );\r
168 ASSERT_EFI_ERROR (Status);\r
169\r
170 //\r
171 // Register SMM Ready To Lock Protocol notification\r
172 //\r
173 Status = gSmst->SmmRegisterProtocolNotify (\r
174 &gEfiSmmReadyToLockProtocolGuid,\r
175 SmmReadyToLockEventNotify,\r
176 &Registration\r
177 );\r
178 ASSERT_EFI_ERROR (Status);\r
179\r
180 return Status;\r
181}\r
182\r