blob: 22845ec5181848dbb01518a75f54718bda9b8ba9 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbin76c37002012-10-30 09:03:43 -05002
3#include <types.h>
Aaron Durbin76c37002012-10-30 09:03:43 -05004#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02005#include <device/pci_ops.h>
Aaron Durbin76c37002012-10-30 09:03:43 -05006#include <console/console.h>
7#include <cpu/x86/cache.h>
8#include <device/pci_def.h>
9#include <cpu/x86/smm.h>
Kyösti Mälkkie31ec292019-08-10 17:27:01 +030010#include <cpu/intel/em64t101_save_state.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050011#include <elog.h>
Patrick Georgi546953c2014-11-29 10:38:17 +010012#include <halt.h>
Kyösti Mälkkicbf95712020-01-05 08:05:45 +020013#include <option.h>
Tristan Corrick63626b12018-11-30 22:53:50 +130014#include <southbridge/intel/common/finalize.h>
Tristan Corrick09fc6342018-11-30 22:53:01 +130015#include <northbridge/intel/haswell/haswell.h>
16#include <cpu/intel/haswell/haswell.h>
Kyösti Mälkki661ad462020-12-29 06:26:21 +020017#include <soc/nvs.h>
Matt DeVillier8187f112018-12-24 21:46:46 -060018#include <smmstore.h>
Tristan Corrick63626b12018-11-30 22:53:50 +130019#include "me.h"
Aaron Durbin76c37002012-10-30 09:03:43 -050020#include "pch.h"
Aaron Durbin76c37002012-10-30 09:03:43 -050021
Aaron Durbin76c37002012-10-30 09:03:43 -050022int southbridge_io_trap_handler(int smif)
23{
24 switch (smif) {
25 case 0x32:
26 printk(BIOS_DEBUG, "OS Init\n");
27 /* gnvs->smif:
28 * On success, the IO Trap Handler returns 0
29 * On failure, the IO Trap Handler returns a value != 0
30 */
31 gnvs->smif = 0;
32 return 1; /* IO trap handled */
33 }
34
35 /* Not handled */
36 return 0;
37}
38
39/**
40 * @brief Set the EOS bit
41 */
42void southbridge_smi_set_eos(void)
43{
Duncan Laurie467f31d2013-03-08 17:00:37 -080044 enable_smi(EOS);
Aaron Durbin76c37002012-10-30 09:03:43 -050045}
46
47static void busmaster_disable_on_bus(int bus)
48{
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020049 int slot, func;
50 unsigned int val;
51 unsigned char hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -050052
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020053 for (slot = 0; slot < 0x20; slot++) {
54 for (func = 0; func < 8; func++) {
Elyes HAOUAS68c851b2018-06-12 22:06:09 +020055 pci_devfn_t dev = PCI_DEV(bus, slot, func);
Aaron Durbin76c37002012-10-30 09:03:43 -050056
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020057 val = pci_read_config32(dev, PCI_VENDOR_ID);
Aaron Durbin76c37002012-10-30 09:03:43 -050058
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020059 if (val == 0xffffffff || val == 0x00000000 ||
60 val == 0x0000ffff || val == 0xffff0000)
61 continue;
Aaron Durbin76c37002012-10-30 09:03:43 -050062
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020063 /* Disable Bus Mastering for this one device */
Angel Ponsbf9bc502020-06-08 00:12:43 +020064 pci_and_config16(dev, PCI_COMMAND, ~PCI_COMMAND_MASTER);
Aaron Durbin76c37002012-10-30 09:03:43 -050065
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020066 /* If this is a bridge, then follow it. */
67 hdr = pci_read_config8(dev, PCI_HEADER_TYPE);
68 hdr &= 0x7f;
69 if (hdr == PCI_HEADER_TYPE_BRIDGE ||
70 hdr == PCI_HEADER_TYPE_CARDBUS) {
71 unsigned int buses;
72 buses = pci_read_config32(dev, PCI_PRIMARY_BUS);
73 busmaster_disable_on_bus((buses >> 8) & 0xff);
74 }
75 }
76 }
Aaron Durbin76c37002012-10-30 09:03:43 -050077}
78
Aaron Durbin29ffa542012-12-21 21:21:48 -060079static void southbridge_smi_sleep(void)
Aaron Durbin76c37002012-10-30 09:03:43 -050080{
81 u8 reg8;
82 u32 reg32;
83 u8 slp_typ;
Nico Huber9faae2b2018-11-14 00:00:35 +010084 u8 s5pwr = CONFIG_MAINBOARD_POWER_FAILURE_STATE;
Duncan Laurie467f31d2013-03-08 17:00:37 -080085 u16 pmbase = get_pmbase();
Aaron Durbin76c37002012-10-30 09:03:43 -050086
Angel Pons2aaf7c02020-09-24 18:03:18 +020087 /* save and recover RTC port values */
Aaron Durbin76c37002012-10-30 09:03:43 -050088 u8 tmp70, tmp72;
89 tmp70 = inb(0x70);
90 tmp72 = inb(0x72);
91 get_option(&s5pwr, "power_on_after_fail");
92 outb(tmp70, 0x70);
93 outb(tmp72, 0x72);
94
Aaron Durbin76c37002012-10-30 09:03:43 -050095 /* First, disable further SMIs */
Duncan Laurie467f31d2013-03-08 17:00:37 -080096 disable_smi(SLP_SMI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -050097
98 /* Figure out SLP_TYP */
99 reg32 = inl(pmbase + PM1_CNT);
100 printk(BIOS_SPEW, "SMI#: SLP = 0x%08x\n", reg32);
Aaron Durbinda5f5092016-07-13 23:23:16 -0500101 slp_typ = acpi_sleep_from_pm1(reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -0500102
103 /* Do any mainboard sleep handling */
Aaron Durbinda5f5092016-07-13 23:23:16 -0500104 mainboard_smi_sleep(slp_typ);
Aaron Durbin76c37002012-10-30 09:03:43 -0500105
Duncan Laurie2d9d39a2013-05-29 15:27:55 -0700106 /* USB sleep preparations */
Julius Wernercd49cce2019-03-05 16:53:33 -0800107#if !CONFIG(FINALIZE_USB_ROUTE_XHCI)
Duncan Laurie1f529082013-07-30 15:53:45 -0700108 usb_ehci_sleep_prepare(PCH_EHCI1_DEV, slp_typ);
109 usb_ehci_sleep_prepare(PCH_EHCI2_DEV, slp_typ);
Duncan Laurie911cedf2013-07-30 16:05:55 -0700110#endif
Duncan Laurie1f529082013-07-30 15:53:45 -0700111 usb_xhci_sleep_prepare(PCH_XHCI_DEV, slp_typ);
Duncan Laurie2d9d39a2013-05-29 15:27:55 -0700112
Aaron Durbin76c37002012-10-30 09:03:43 -0500113 /* Log S3, S4, and S5 entry */
Aaron Durbinda5f5092016-07-13 23:23:16 -0500114 if (slp_typ >= ACPI_S3)
Kyösti Mälkki9dd1a122019-11-06 11:04:27 +0200115 elog_gsmi_add_event_byte(ELOG_TYPE_ACPI_ENTER, slp_typ);
Aaron Durbin76c37002012-10-30 09:03:43 -0500116
117 /* Next, do the deed.
118 */
119
120 switch (slp_typ) {
Aaron Durbinda5f5092016-07-13 23:23:16 -0500121 case ACPI_S0:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800122 printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n");
123 break;
Aaron Durbinda5f5092016-07-13 23:23:16 -0500124 case ACPI_S1:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800125 printk(BIOS_DEBUG, "SMI#: Entering S1 (Assert STPCLK#)\n");
126 break;
Aaron Durbinda5f5092016-07-13 23:23:16 -0500127 case ACPI_S3:
Aaron Durbin76c37002012-10-30 09:03:43 -0500128 printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n");
129
Aaron Durbin76c37002012-10-30 09:03:43 -0500130 /* Invalidate the cache before going to S3 */
131 wbinvd();
132 break;
Aaron Durbinda5f5092016-07-13 23:23:16 -0500133 case ACPI_S4:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800134 printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n");
135 break;
Aaron Durbinda5f5092016-07-13 23:23:16 -0500136 case ACPI_S5:
Aaron Durbin76c37002012-10-30 09:03:43 -0500137 printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n");
138
Duncan Laurie467f31d2013-03-08 17:00:37 -0800139 /* Disable all GPE */
140 disable_all_gpe();
Aaron Durbin76c37002012-10-30 09:03:43 -0500141
142 /* Always set the flag in case CMOS was changed on runtime. For
143 * "KEEP", switch to "OFF" - KEEP is software emulated
144 */
Angel Pons90cdf702020-10-24 23:00:34 +0200145 reg8 = pci_read_config8(PCH_LPC_DEV, GEN_PMCON_3);
Angel Pons2aaf7c02020-09-24 18:03:18 +0200146 if (s5pwr == MAINBOARD_POWER_ON)
Aaron Durbin76c37002012-10-30 09:03:43 -0500147 reg8 &= ~1;
Angel Pons2aaf7c02020-09-24 18:03:18 +0200148 else
Aaron Durbin76c37002012-10-30 09:03:43 -0500149 reg8 |= 1;
Angel Pons90cdf702020-10-24 23:00:34 +0200150 pci_write_config8(PCH_LPC_DEV, GEN_PMCON_3, reg8);
Aaron Durbin76c37002012-10-30 09:03:43 -0500151
152 /* also iterates over all bridges on bus 0 */
153 busmaster_disable_on_bus(0);
154 break;
Duncan Laurie467f31d2013-03-08 17:00:37 -0800155 default:
156 printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n");
157 break;
Aaron Durbin76c37002012-10-30 09:03:43 -0500158 }
159
Angel Pons2aaf7c02020-09-24 18:03:18 +0200160 /*
161 * Write back to the SLP register to cause the originally intended
Aaron Durbin76c37002012-10-30 09:03:43 -0500162 * event again. We need to set BIT13 (SLP_EN) though to make the
163 * sleep happen.
164 */
Duncan Laurie467f31d2013-03-08 17:00:37 -0800165 enable_pm1_control(SLP_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500166
167 /* Make sure to stop executing code here for S3/S4/S5 */
Aaron Durbinda5f5092016-07-13 23:23:16 -0500168 if (slp_typ >= ACPI_S3)
Patrick Georgi546953c2014-11-29 10:38:17 +0100169 halt();
Aaron Durbin76c37002012-10-30 09:03:43 -0500170
Angel Pons2aaf7c02020-09-24 18:03:18 +0200171 /*
172 * In most sleep states, the code flow of this function ends at
Aaron Durbin76c37002012-10-30 09:03:43 -0500173 * the line above. However, if we entered sleep state S1 and wake
174 * up again, we will continue to execute code in this function.
175 */
176 reg32 = inl(pmbase + PM1_CNT);
177 if (reg32 & SCI_EN) {
178 /* The OS is not an ACPI OS, so we set the state to S0 */
Duncan Laurie467f31d2013-03-08 17:00:37 -0800179 disable_pm1_control(SLP_EN | SLP_TYP);
Aaron Durbin76c37002012-10-30 09:03:43 -0500180 }
181}
182
183/*
184 * Look for Synchronous IO SMI and use save state from that
185 * core in case we are not running on the same core that
186 * initiated the IO transaction.
187 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500188static em64t101_smm_state_save_area_t *smi_apmc_find_state_save(u8 cmd)
189{
190 em64t101_smm_state_save_area_t *state;
Aaron Durbin76c37002012-10-30 09:03:43 -0500191 int node;
192
193 /* Check all nodes looking for the one that issued the IO */
194 for (node = 0; node < CONFIG_MAX_CPUS; node++) {
Aaron Durbin29ffa542012-12-21 21:21:48 -0600195 state = smm_get_save_state(node);
Aaron Durbin76c37002012-10-30 09:03:43 -0500196
Elyes HAOUAS581fe582018-04-26 09:57:07 +0200197 /* Check for Synchronous IO (bit0 == 1) */
Aaron Durbin76c37002012-10-30 09:03:43 -0500198 if (!(state->io_misc_info & (1 << 0)))
199 continue;
200
Elyes HAOUAS581fe582018-04-26 09:57:07 +0200201 /* Make sure it was a write (bit4 == 0) */
Aaron Durbin76c37002012-10-30 09:03:43 -0500202 if (state->io_misc_info & (1 << 4))
203 continue;
204
205 /* Check for APMC IO port */
206 if (((state->io_misc_info >> 16) & 0xff) != APM_CNT)
207 continue;
208
209 /* Check AX against the requested command */
210 if ((state->rax & 0xff) != cmd)
211 continue;
212
213 return state;
214 }
215
216 return NULL;
217}
218
Aaron Durbin76c37002012-10-30 09:03:43 -0500219static void southbridge_smi_gsmi(void)
220{
221 u32 *ret, *param;
222 u8 sub_command;
223 em64t101_smm_state_save_area_t *io_smi =
Patrick Georgid61839c2018-12-03 16:10:33 +0100224 smi_apmc_find_state_save(APM_CNT_ELOG_GSMI);
Aaron Durbin76c37002012-10-30 09:03:43 -0500225
226 if (!io_smi)
227 return;
228
229 /* Command and return value in EAX */
Angel Pons2aaf7c02020-09-24 18:03:18 +0200230 ret = (u32 *)&io_smi->rax;
Aaron Durbin76c37002012-10-30 09:03:43 -0500231 sub_command = (u8)(*ret >> 8);
232
233 /* Parameter buffer in EBX */
Angel Pons2aaf7c02020-09-24 18:03:18 +0200234 param = (u32 *)&io_smi->rbx;
Aaron Durbin76c37002012-10-30 09:03:43 -0500235
236 /* drivers/elog/gsmi.c */
237 *ret = gsmi_exec(sub_command, param);
238}
Aaron Durbin76c37002012-10-30 09:03:43 -0500239
Matt DeVillier8187f112018-12-24 21:46:46 -0600240static void southbridge_smi_store(void)
241{
242 u8 sub_command, ret;
243 em64t101_smm_state_save_area_t *io_smi =
244 smi_apmc_find_state_save(APM_CNT_SMMSTORE);
245 uint32_t reg_ebx;
246
247 if (!io_smi)
248 return;
249 /* Command and return value in EAX */
250 sub_command = (io_smi->rax >> 8) & 0xff;
251
252 /* Parameter buffer in EBX */
253 reg_ebx = io_smi->rbx;
254
255 /* drivers/smmstore/smi.c */
256 ret = smmstore_exec(sub_command, (void *)reg_ebx);
257 io_smi->rax = ret;
258}
259
Aaron Durbin29ffa542012-12-21 21:21:48 -0600260static void southbridge_smi_apmc(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500261{
Aaron Durbin76c37002012-10-30 09:03:43 -0500262 u8 reg8;
Tristan Corrick09fc6342018-11-30 22:53:01 +1300263 static int chipset_finalized = 0;
Aaron Durbin76c37002012-10-30 09:03:43 -0500264
265 /* Emulate B2 register as the FADT / Linux expects it */
266
267 reg8 = inb(APM_CNT);
268 switch (reg8) {
Tristan Corrick09fc6342018-11-30 22:53:01 +1300269 case APM_CNT_FINALIZE:
270 if (chipset_finalized) {
271 printk(BIOS_DEBUG, "SMI#: Already finalized\n");
272 return;
273 }
274
Tristan Corrick63626b12018-11-30 22:53:50 +1300275 intel_me_finalize_smm();
Tristan Corrick09fc6342018-11-30 22:53:01 +1300276 intel_pch_finalize_smm();
277 intel_northbridge_haswell_finalize_smm();
278 intel_cpu_haswell_finalize_smm();
279
280 chipset_finalized = 1;
281 break;
Aaron Durbin76c37002012-10-30 09:03:43 -0500282 case APM_CNT_CST_CONTROL:
283 /* Calling this function seems to cause
284 * some kind of race condition in Linux
285 * and causes a kernel oops
286 */
287 printk(BIOS_DEBUG, "C-state control\n");
288 break;
289 case APM_CNT_PST_CONTROL:
290 /* Calling this function seems to cause
291 * some kind of race condition in Linux
292 * and causes a kernel oops
293 */
294 printk(BIOS_DEBUG, "P-state control\n");
295 break;
296 case APM_CNT_ACPI_DISABLE:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800297 disable_pm1_control(SCI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500298 printk(BIOS_DEBUG, "SMI#: ACPI disabled.\n");
299 break;
300 case APM_CNT_ACPI_ENABLE:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800301 enable_pm1_control(SCI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500302 printk(BIOS_DEBUG, "SMI#: ACPI enabled.\n");
303 break;
Kyösti Mälkkib486f292020-06-18 14:05:35 +0300304 case APM_CNT_ROUTE_ALL_XHCI:
Duncan Laurie911cedf2013-07-30 16:05:55 -0700305 usb_xhci_route_all();
Duncan Laurie911cedf2013-07-30 16:05:55 -0700306 break;
Patrick Georgid61839c2018-12-03 16:10:33 +0100307 case APM_CNT_ELOG_GSMI:
Kyösti Mälkki9dd1a122019-11-06 11:04:27 +0200308 if (CONFIG(ELOG_GSMI))
309 southbridge_smi_gsmi();
Aaron Durbin76c37002012-10-30 09:03:43 -0500310 break;
Matt DeVillier8187f112018-12-24 21:46:46 -0600311 case APM_CNT_SMMSTORE:
312 if (CONFIG(SMMSTORE))
313 southbridge_smi_store();
314 break;
Aaron Durbin76c37002012-10-30 09:03:43 -0500315 }
316
Aaron Durbin29ffa542012-12-21 21:21:48 -0600317 mainboard_smi_apmc(reg8);
Aaron Durbin76c37002012-10-30 09:03:43 -0500318}
319
Aaron Durbin29ffa542012-12-21 21:21:48 -0600320static void southbridge_smi_pm1(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500321{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800322 u16 pm1_sts = clear_pm1_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500323
324 /* While OSPM is not active, poweroff immediately
325 * on a power button event.
326 */
327 if (pm1_sts & PWRBTN_STS) {
Angel Pons2aaf7c02020-09-24 18:03:18 +0200328 /* power button pressed */
Kyösti Mälkki9dd1a122019-11-06 11:04:27 +0200329 elog_gsmi_add_event(ELOG_TYPE_POWER_BUTTON);
Angel Pons8963f7d2020-10-24 12:20:28 +0200330 disable_pm1_control(-1);
Duncan Laurie467f31d2013-03-08 17:00:37 -0800331 enable_pm1_control(SLP_EN | (SLP_TYP_S5 << 10));
Aaron Durbin76c37002012-10-30 09:03:43 -0500332 }
333}
334
Aaron Durbin29ffa542012-12-21 21:21:48 -0600335static void southbridge_smi_gpe0(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500336{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800337 clear_gpe_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500338}
339
Aaron Durbin29ffa542012-12-21 21:21:48 -0600340static void southbridge_smi_gpi(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500341{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800342 mainboard_smi_gpi(clear_alt_smi_status());
Aaron Durbin76c37002012-10-30 09:03:43 -0500343
Duncan Laurie467f31d2013-03-08 17:00:37 -0800344 /* Clear again after mainboard handler */
345 clear_alt_smi_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500346}
347
Aaron Durbin29ffa542012-12-21 21:21:48 -0600348static void southbridge_smi_mc(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500349{
Angel Pons2aaf7c02020-09-24 18:03:18 +0200350 u32 reg32 = inl(get_pmbase() + SMI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500351
Duncan Laurie467f31d2013-03-08 17:00:37 -0800352 /* Are microcontroller SMIs enabled? */
Aaron Durbin76c37002012-10-30 09:03:43 -0500353 if ((reg32 & MCSMI_EN) == 0)
354 return;
355
356 printk(BIOS_DEBUG, "Microcontroller SMI.\n");
357}
358
Aaron Durbin29ffa542012-12-21 21:21:48 -0600359static void southbridge_smi_tco(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500360{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800361 u32 tco_sts = clear_tco_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500362
363 /* Any TCO event? */
364 if (!tco_sts)
365 return;
366
Angel Pons2aaf7c02020-09-24 18:03:18 +0200367 // BIOSWR
368 if (tco_sts & (1 << 8)) {
Angel Pons90cdf702020-10-24 23:00:34 +0200369 u8 bios_cntl = pci_read_config16(PCH_LPC_DEV, BIOS_CNTL);
Aaron Durbin76c37002012-10-30 09:03:43 -0500370
371 if (bios_cntl & 1) {
Angel Pons2aaf7c02020-09-24 18:03:18 +0200372 /*
373 * BWE is RW, so the SMI was caused by a
Aaron Durbin76c37002012-10-30 09:03:43 -0500374 * write to BWE, not by a write to the BIOS
Angel Pons2aaf7c02020-09-24 18:03:18 +0200375 *
376 * This is the place where we notice someone
Aaron Durbin76c37002012-10-30 09:03:43 -0500377 * is trying to tinker with the BIOS. We are
378 * trying to be nice and just ignore it. A more
379 * resolute answer would be to power down the
380 * box.
381 */
382 printk(BIOS_DEBUG, "Switching back to RO\n");
Angel Pons90cdf702020-10-24 23:00:34 +0200383 pci_write_config32(PCH_LPC_DEV, BIOS_CNTL, (bios_cntl & ~1));
Aaron Durbin76c37002012-10-30 09:03:43 -0500384 } /* No else for now? */
385 } else if (tco_sts & (1 << 3)) { /* TIMEOUT */
386 /* Handle TCO timeout */
387 printk(BIOS_DEBUG, "TCO Timeout.\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500388 }
389}
390
Aaron Durbin29ffa542012-12-21 21:21:48 -0600391static void southbridge_smi_periodic(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500392{
Angel Pons2aaf7c02020-09-24 18:03:18 +0200393 u32 reg32 = inl(get_pmbase() + SMI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500394
395 /* Are periodic SMIs enabled? */
396 if ((reg32 & PERIODIC_EN) == 0)
397 return;
398
399 printk(BIOS_DEBUG, "Periodic SMI.\n");
400}
401
Aaron Durbin29ffa542012-12-21 21:21:48 -0600402static void southbridge_smi_monitor(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500403{
404#define IOTRAP(x) (trap_sts & (1 << x))
405 u32 trap_sts, trap_cycle;
Elyes HAOUAS2a66dd22020-08-07 15:22:12 +0200406 u32 mask = 0;
Aaron Durbin76c37002012-10-30 09:03:43 -0500407 int i;
408
409 trap_sts = RCBA32(0x1e00); // TRSR - Trap Status Register
410 RCBA32(0x1e00) = trap_sts; // Clear trap(s) in TRSR
411
412 trap_cycle = RCBA32(0x1e10);
Angel Pons2aaf7c02020-09-24 18:03:18 +0200413 for (i = 16; i < 20; i++) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500414 if (trap_cycle & (1 << i))
415 mask |= (0xff << ((i - 16) << 2));
416 }
417
Aaron Durbin76c37002012-10-30 09:03:43 -0500418 /* IOTRAP(3) SMI function call */
419 if (IOTRAP(3)) {
420 if (gnvs && gnvs->smif)
421 io_trap_handler(gnvs->smif); // call function smif
422 return;
423 }
424
425 /* IOTRAP(2) currently unused
426 * IOTRAP(1) currently unused */
427
428 /* IOTRAP(0) SMIC */
429 if (IOTRAP(0)) {
Angel Pons2aaf7c02020-09-24 18:03:18 +0200430 // It's a write
431 if (!(trap_cycle & (1 << 24))) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500432 printk(BIOS_DEBUG, "SMI1 command\n");
Elyes HAOUAS2a66dd22020-08-07 15:22:12 +0200433 (void)RCBA32(0x1e18);
434 // data = RCBA32(0x1e18);
435 // data &= mask;
Aaron Durbin76c37002012-10-30 09:03:43 -0500436 // if (smi1)
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200437 // southbridge_smi_command(data);
Aaron Durbin76c37002012-10-30 09:03:43 -0500438 // return;
439 }
440 // Fall through to debug
441 }
442
Duncan Laurie467f31d2013-03-08 17:00:37 -0800443 printk(BIOS_DEBUG, " trapped io address = 0x%x\n",
444 trap_cycle & 0xfffc);
Angel Pons2aaf7c02020-09-24 18:03:18 +0200445 for (i = 0; i < 4; i++)
446 if (IOTRAP(i))
447 printk(BIOS_DEBUG, " TRAP = %d\n", i);
Aaron Durbin76c37002012-10-30 09:03:43 -0500448 printk(BIOS_DEBUG, " AHBE = %x\n", (trap_cycle >> 16) & 0xf);
449 printk(BIOS_DEBUG, " MASK = 0x%08x\n", mask);
Duncan Laurie467f31d2013-03-08 17:00:37 -0800450 printk(BIOS_DEBUG, " read/write: %s\n",
451 (trap_cycle & (1 << 24)) ? "read" : "write");
Aaron Durbin76c37002012-10-30 09:03:43 -0500452
453 if (!(trap_cycle & (1 << 24))) {
454 /* Write Cycle */
Elyes HAOUAS2a66dd22020-08-07 15:22:12 +0200455 printk(BIOS_DEBUG, " iotrap written data = 0x%08x\n", RCBA32(0x1e18));
Aaron Durbin76c37002012-10-30 09:03:43 -0500456 }
457#undef IOTRAP
458}
459
Aaron Durbin29ffa542012-12-21 21:21:48 -0600460typedef void (*smi_handler_t)(void);
Aaron Durbin76c37002012-10-30 09:03:43 -0500461
462static smi_handler_t southbridge_smi[32] = {
463 NULL, // [0] reserved
464 NULL, // [1] reserved
465 NULL, // [2] BIOS_STS
466 NULL, // [3] LEGACY_USB_STS
467 southbridge_smi_sleep, // [4] SLP_SMI_STS
468 southbridge_smi_apmc, // [5] APM_STS
469 NULL, // [6] SWSMI_TMR_STS
470 NULL, // [7] reserved
471 southbridge_smi_pm1, // [8] PM1_STS
472 southbridge_smi_gpe0, // [9] GPE0_STS
473 southbridge_smi_gpi, // [10] GPI_STS
474 southbridge_smi_mc, // [11] MCSMI_STS
475 NULL, // [12] DEVMON_STS
476 southbridge_smi_tco, // [13] TCO_STS
477 southbridge_smi_periodic, // [14] PERIODIC_STS
478 NULL, // [15] SERIRQ_SMI_STS
479 NULL, // [16] SMBUS_SMI_STS
480 NULL, // [17] LEGACY_USB2_STS
481 NULL, // [18] INTEL_USB2_STS
482 NULL, // [19] reserved
483 NULL, // [20] PCI_EXP_SMI_STS
484 southbridge_smi_monitor, // [21] MONITOR_STS
485 NULL, // [22] reserved
486 NULL, // [23] reserved
487 NULL, // [24] reserved
488 NULL, // [25] EL_SMI_STS
489 NULL, // [26] SPI_STS
490 NULL, // [27] reserved
491 NULL, // [28] reserved
492 NULL, // [29] reserved
493 NULL, // [30] reserved
494 NULL // [31] reserved
495};
496
497/**
498 * @brief Interrupt handler for SMI#
Aaron Durbin76c37002012-10-30 09:03:43 -0500499 */
Aaron Durbin29ffa542012-12-21 21:21:48 -0600500void southbridge_smi_handler(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500501{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800502 int i;
Aaron Durbin76c37002012-10-30 09:03:43 -0500503 u32 smi_sts;
504
Aaron Durbin76c37002012-10-30 09:03:43 -0500505 /* We need to clear the SMI status registers, or we won't see what's
506 * happening in the following calls.
507 */
Duncan Laurie467f31d2013-03-08 17:00:37 -0800508 smi_sts = clear_smi_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500509
510 /* Call SMI sub handler for each of the status bits */
511 for (i = 0; i < 31; i++) {
512 if (smi_sts & (1 << i)) {
513 if (southbridge_smi[i]) {
Aaron Durbin29ffa542012-12-21 21:21:48 -0600514 southbridge_smi[i]();
Aaron Durbin76c37002012-10-30 09:03:43 -0500515 } else {
Duncan Laurie467f31d2013-03-08 17:00:37 -0800516 printk(BIOS_DEBUG,
Martin Roth2ed0aa22016-01-05 20:58:58 -0700517 "SMI_STS[%d] occurred, but no "
Duncan Laurie467f31d2013-03-08 17:00:37 -0800518 "handler available.\n", i);
Aaron Durbin76c37002012-10-30 09:03:43 -0500519 }
520 }
521 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500522}