]> git.proxmox.com Git - mirror_edk2.git/blame - QuarkSocPkg/QuarkNorthCluster/Smm/Dxe/SmmControlDxe/SmmControlDriver.c
QuarkSocPkg: SmmControlDxe: remove set but unused variables
[mirror_edk2.git] / QuarkSocPkg / QuarkNorthCluster / Smm / Dxe / SmmControlDxe / SmmControlDriver.c
CommitLineData
9b6bbcdb
MK
1/** @file\r
2This module produces the SMM COntrol2 Protocol for QNC\r
3\r
4Copyright (c) 2013-2015 Intel Corporation.\r
5\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include <PiDxe.h>\r
17#include <Protocol/SmmControl2.h>\r
18#include <IndustryStandard/Pci.h>\r
19#include <Library/DebugLib.h>\r
20#include <Library/UefiBootServicesTableLib.h>\r
21#include <Library/UefiRuntimeServicesTableLib.h>\r
22#include <Library/PcdLib.h>\r
23#include <Library/IoLib.h>\r
24#include <Library/PciLib.h>\r
25#include <IntelQNCDxe.h>\r
26#include <Library/QNCAccessLib.h>\r
27#include <Uefi/UefiBaseType.h>\r
28\r
29#define EFI_INTERNAL_POINTER 0x00000004\r
30\r
31extern EFI_GUID gEfiEventVirtualAddressChangeGuid;\r
32\r
33/**\r
34 Generates an SMI using the parameters passed in.\r
35\r
36 @param This A pointer to an instance of\r
37 EFI_SMM_CONTROL2_PROTOCOL\r
38 @param ArgumentBuffer The argument buffer\r
39 @param ArgumentBufferSize The size of the argument buffer\r
40 @param Periodic TRUE to indicate a periodical SMI\r
41 @param ActivationInterval Interval of the periodical SMI\r
42\r
43 @retval EFI_INVALID_PARAMETER Periodic is TRUE or ArgumentBufferSize > 1\r
44 @return Return value from SmmTrigger().\r
45\r
46**/\r
47EFI_STATUS\r
48EFIAPI\r
49Activate (\r
50 IN CONST EFI_SMM_CONTROL2_PROTOCOL *This,\r
51 IN OUT UINT8 *CommandPort OPTIONAL,\r
52 IN OUT UINT8 *DataPort OPTIONAL,\r
53 IN BOOLEAN Periodic OPTIONAL,\r
54 IN EFI_SMM_PERIOD ActivationInterval OPTIONAL\r
55 );\r
56\r
57/**\r
58 Clears an SMI.\r
59\r
60 @param This Pointer to an instance of EFI_SMM_CONTROL2_PROTOCOL\r
61 @param Periodic TRUE to indicate a periodical SMI\r
62\r
63 @return Return value from SmmClear()\r
64\r
65**/\r
66EFI_STATUS\r
67EFIAPI\r
68Deactivate (\r
69 IN CONST EFI_SMM_CONTROL2_PROTOCOL *This,\r
70 IN BOOLEAN Periodic OPTIONAL\r
71 );\r
72\r
73///\r
74/// Handle for the SMM Control2 Protocol\r
75///\r
76EFI_HANDLE mSmmControl2Handle = NULL;\r
77\r
78///\r
79/// SMM COntrol2 Protocol instance\r
80///\r
81EFI_SMM_CONTROL2_PROTOCOL mSmmControl2 = {\r
82 Activate,\r
83 Deactivate,\r
84 0\r
85};\r
86\r
87VOID\r
88EFIAPI\r
89SmmControlVirtualddressChangeEvent (\r
90 IN EFI_EVENT Event,\r
91 IN VOID *Context\r
92 )\r
93/*++\r
94\r
95Routine Description:\r
96\r
97 Fixup internal data pointers so that the services can be called in virtual mode.\r
98\r
99Arguments:\r
100\r
101 Event The event registered.\r
102 Context Event context.\r
103\r
104Returns:\r
105\r
106 None.\r
107\r
108--*/\r
109{\r
110 gRT->ConvertPointer (EFI_INTERNAL_POINTER, (VOID *) &(mSmmControl2.Trigger));\r
111 gRT->ConvertPointer (EFI_INTERNAL_POINTER, (VOID *) &(mSmmControl2.Clear));\r
112}\r
113\r
114/**\r
115 Clear SMI related chipset status and re-enable SMI by setting the EOS bit.\r
116\r
117 @retval EFI_SUCCESS The requested operation has been carried out successfully\r
118 @retval EFI_DEVICE_ERROR The EOS bit could not be set.\r
119\r
120**/\r
121EFI_STATUS\r
122SmmClear (\r
123 VOID\r
124 )\r
125{\r
9b6bbcdb
MK
126 UINT16 GPE0BLK_Base;\r
127\r
128 //\r
a7705e19 129 // Get GPE0BLK_Base\r
9b6bbcdb 130 //\r
9b6bbcdb
MK
131 GPE0BLK_Base = PcdGet16 (PcdGpe0blkIoBaseAddress);\r
132\r
133 //\r
134 // Clear the Power Button Override Status Bit, it gates EOS from being set.\r
135 // In QuarkNcSocId - Bit is read only. Handled by external SMC, do nothing.\r
136 //\r
137\r
138 //\r
139 // Clear the APM SMI Status Bit\r
140 //\r
141 IoWrite32 ((GPE0BLK_Base + R_QNC_GPE0BLK_SMIS), B_QNC_GPE0BLK_SMIS_APM);\r
142\r
143 //\r
144 // Set the EOS Bit\r
145 //\r
146 IoOr32 ((GPE0BLK_Base + R_QNC_GPE0BLK_SMIS), B_QNC_GPE0BLK_SMIS_EOS);\r
147\r
148 return EFI_SUCCESS;\r
149}\r
150\r
151/**\r
152 Generates an SMI using the parameters passed in.\r
153\r
154 @param This A pointer to an instance of\r
155 EFI_SMM_CONTROL_PROTOCOL\r
156 @param ArgumentBuffer The argument buffer\r
157 @param ArgumentBufferSize The size of the argument buffer\r
158 @param Periodic TRUE to indicate a periodical SMI\r
159 @param ActivationInterval Interval of the periodical SMI\r
160\r
161 @retval EFI_INVALID_PARAMETER Periodic is TRUE or ArgumentBufferSize > 1\r
162 @retval EFI_SUCCESS SMI generated\r
163\r
164**/\r
165EFI_STATUS\r
166EFIAPI\r
167Activate (\r
168 IN CONST EFI_SMM_CONTROL2_PROTOCOL *This,\r
169 IN OUT UINT8 *CommandPort OPTIONAL,\r
170 IN OUT UINT8 *DataPort OPTIONAL,\r
171 IN BOOLEAN Periodic OPTIONAL,\r
172 IN EFI_SMM_PERIOD ActivationInterval OPTIONAL\r
173 )\r
174{\r
175 UINT16 GPE0BLK_Base;\r
176 UINT32 NewValue;\r
177\r
178 //\r
179 // Get GPE0BLK_Base\r
180 //\r
181 GPE0BLK_Base = PcdGet16 (PcdGpe0blkIoBaseAddress);\r
182\r
183 if (Periodic) {\r
184 return EFI_INVALID_PARAMETER;\r
185 }\r
186\r
187 //\r
188 // Clear any pending the APM SMI\r
189 //\r
190 if (EFI_ERROR (SmmClear())) {\r
191 return EFI_DEVICE_ERROR;\r
192 }\r
193\r
194 //\r
195 // Enable the APMC SMI\r
196 //\r
197 IoOr32 (GPE0BLK_Base + R_QNC_GPE0BLK_SMIE, B_QNC_GPE0BLK_SMIE_APM);\r
198\r
199 //\r
200 // Enable SMI globally\r
201 //\r
202 NewValue = QNCPortRead (QUARK_NC_HOST_BRIDGE_SB_PORT_ID, QNC_MSG_FSBIC_REG_HMISC);\r
203 NewValue |= SMI_EN;\r
204 QNCPortWrite (QUARK_NC_HOST_BRIDGE_SB_PORT_ID, QNC_MSG_FSBIC_REG_HMISC, NewValue);\r
205\r
206\r
207 //\r
208 // Set APMC_STS\r
209 //\r
210 if (DataPort == NULL) {\r
211 IoWrite8 (PcdGet16 (PcdSmmDataPort), 0xFF);\r
212 } else {\r
213 IoWrite8 (PcdGet16 (PcdSmmDataPort), *DataPort);\r
214 }\r
215\r
216 //\r
217 // Generate the APMC SMI\r
218 //\r
219 if (CommandPort == NULL) {\r
220 IoWrite8 (PcdGet16 (PcdSmmActivationPort), 0xFF);\r
221 } else {\r
222 IoWrite8 (PcdGet16 (PcdSmmActivationPort), *CommandPort);\r
223 }\r
224\r
225 return EFI_SUCCESS;\r
226}\r
227\r
228/**\r
229 Clears an SMI.\r
230\r
231 @param This Pointer to an instance of EFI_SMM_CONTROL_PROTOCOL\r
232 @param Periodic TRUE to indicate a periodical SMI\r
233\r
234 @return Return value from SmmClear()\r
235\r
236**/\r
237EFI_STATUS\r
238EFIAPI\r
239Deactivate (\r
240 IN CONST EFI_SMM_CONTROL2_PROTOCOL *This,\r
241 IN BOOLEAN Periodic\r
242 )\r
243{\r
244 if (Periodic) {\r
245 return EFI_INVALID_PARAMETER;\r
246 }\r
247\r
248 return SmmClear();\r
249}\r
250\r
251/**\r
252 This is the constructor for the SMM Control protocol.\r
253\r
254 This function installs EFI_SMM_CONTROL2_PROTOCOL.\r
255\r
256 @param ImageHandle Handle for the image of this driver\r
257 @param SystemTable Pointer to the EFI System Table\r
258\r
259 @retval EFI_UNSUPPORTED There's no Intel ICH on this platform\r
260 @return The status returned from InstallProtocolInterface().\r
261\r
262--*/\r
263EFI_STATUS\r
264SmmControl2Init (\r
265 IN EFI_HANDLE ImageHandle,\r
266 IN EFI_SYSTEM_TABLE *SystemTable\r
267 )\r
268{\r
269 EFI_STATUS Status;\r
270 EFI_EVENT Event;\r
271 UINT16 PM1BLK_Base;\r
272 UINT16 GPE0BLK_Base;\r
273 BOOLEAN SciEn;\r
274 UINT32 NewValue;\r
275\r
276 //\r
277 // Get PM1BLK_Base & GPE0BLK_Base\r
278 //\r
279 PM1BLK_Base = PcdGet16 (PcdPm1blkIoBaseAddress);\r
280 GPE0BLK_Base = PcdGet16 (PcdGpe0blkIoBaseAddress);\r
281\r
282 //\r
283 // Install our protocol interfaces on the device's handle\r
284 //\r
285 Status = gBS->InstallMultipleProtocolInterfaces (\r
286 &mSmmControl2Handle,\r
287 &gEfiSmmControl2ProtocolGuid, &mSmmControl2,\r
288 NULL\r
289 );\r
290 ASSERT_EFI_ERROR (Status);\r
291\r
292 //\r
293 // Determine whether an ACPI OS is present (via the SCI_EN bit)\r
294 //\r
295 SciEn = (BOOLEAN)((IoRead16 (PM1BLK_Base + R_QNC_PM1BLK_PM1C) & B_QNC_PM1BLK_PM1C_SCIEN) != 0);\r
296 if (!SciEn) {\r
297 //\r
298 // Clear any SMIs that double as SCIs (when SCI_EN==0)\r
299 //\r
300 IoWrite16 ((PM1BLK_Base + R_QNC_PM1BLK_PM1S), B_QNC_PM1BLK_PM1S_ALL);\r
301 IoWrite16 ((PM1BLK_Base + R_QNC_PM1BLK_PM1E), 0x00000000);\r
302 IoWrite32 ((PM1BLK_Base + R_QNC_PM1BLK_PM1C), 0x00000000);\r
303 IoWrite32 ((GPE0BLK_Base + R_QNC_GPE0BLK_GPE0S), B_QNC_GPE0BLK_GPE0S_ALL);\r
304 IoWrite32 ((GPE0BLK_Base + R_QNC_GPE0BLK_GPE0E), 0x00000000);\r
305 }\r
306\r
307 //\r
308 // Clear and disable all SMIs that are unaffected by SCI_EN\r
309 // Set EOS\r
310 //\r
311 IoWrite32 ((GPE0BLK_Base + R_QNC_GPE0BLK_SMIE), 0x00000000);\r
312 IoWrite32 ((GPE0BLK_Base + R_QNC_GPE0BLK_SMIS), (B_QNC_GPE0BLK_SMIS_EOS + B_QNC_GPE0BLK_SMIS_ALL));\r
313\r
314 //\r
315 // Enable SMI globally\r
316 //\r
317 NewValue = QNCPortRead (QUARK_NC_HOST_BRIDGE_SB_PORT_ID, QNC_MSG_FSBIC_REG_HMISC);\r
318 NewValue |= SMI_EN;\r
319 QNCPortWrite (QUARK_NC_HOST_BRIDGE_SB_PORT_ID, QNC_MSG_FSBIC_REG_HMISC, NewValue);\r
320\r
321 //\r
322 // Make sure to write this register last -- EOS re-enables SMIs for the QNC\r
323 //\r
324 IoAndThenOr32 (\r
325 GPE0BLK_Base + R_QNC_GPE0BLK_SMIE,\r
326 (UINT32)(~B_QNC_GPE0BLK_SMIE_ALL),\r
327 B_QNC_GPE0BLK_SMIE_APM\r
328 );\r
329\r
330 //\r
331 // Make sure EOS bit cleared\r
332 //\r
333 DEBUG_CODE_BEGIN ();\r
334 if (IoRead32 (GPE0BLK_Base + R_QNC_GPE0BLK_SMIS) & B_QNC_GPE0BLK_SMIS_EOS) {\r
335 DEBUG ((\r
336 EFI_D_ERROR,\r
337 "******************************************************************************\n"\r
338 "BIG ERROR: SmmControl constructor couldn't properly initialize the ACPI table.\n"\r
339 " SmmControl->Clear will probably hang. \n"\r
340 " NOTE: SCI_EN = %d \n"\r
341 "******************************************************************************\n",\r
342 SciEn\r
343 ));\r
344\r
345 //\r
346 // If we want the system to stop, then keep the ASSERT(FALSE).\r
347 // Otherwise, comment it out.\r
348 //\r
349 ASSERT (FALSE);\r
350 }\r
351 DEBUG_CODE_END ();\r
352\r
353 Status = gBS->CreateEventEx (\r
354 EVT_NOTIFY_SIGNAL,\r
355 TPL_NOTIFY,\r
356 SmmControlVirtualddressChangeEvent,\r
357 NULL,\r
358 &gEfiEventVirtualAddressChangeGuid,\r
359 &Event\r
360 );\r
361 ASSERT_EFI_ERROR (Status);\r
362\r
363 return Status;\r
364}\r