blob: b54d1d39c5431b333cea40c0a345dec255fbfc8f [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer800379f2010-03-01 08:34:19 +00002
3#include <types.h>
4#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02005#include <device/pci_ops.h>
Stefan Reinauer800379f2010-03-01 08:34:19 +00006#include <console/console.h>
7#include <cpu/x86/cache.h>
8#include <cpu/x86/smm.h>
9#include <device/pci_def.h>
10#include "i82801dx.h"
11
12#define DEBUG_SMI
13
Stefan Reinauer800379f2010-03-01 08:34:19 +000014/* I830M */
15#define SMRAM 0x90
16#define D_OPEN (1 << 6)
17#define D_CLS (1 << 5)
18#define D_LCK (1 << 4)
19#define G_SMRANE (1 << 3)
20#define C_BASE_SEG ((0 << 2) | (1 << 1) | (0 << 0))
21
Stefan Reinauer800379f2010-03-01 08:34:19 +000022/* While we read PMBASE dynamically in case it changed, let's
23 * initialize it with a sane value
24 */
25u16 pmbase = PMBASE_ADDR;
Stefan Reinauer800379f2010-03-01 08:34:19 +000026
27unsigned char *mbi = NULL;
28u32 mbi_len;
29u8 mbi_initialized = 0;
30
Stefan Reinauer800379f2010-03-01 08:34:19 +000031/**
32 * @brief read and clear PM1_STS
33 * @return PM1_STS register
34 */
35static u16 reset_pm1_status(void)
36{
37 u16 reg16;
38
39 reg16 = inw(pmbase + PM1_STS);
40 /* set status bits are cleared by writing 1 to them */
41 outw(reg16, pmbase + PM1_STS);
42
43 return reg16;
44}
45
46static void dump_pm1_status(u16 pm1_sts)
47{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000048 printk(BIOS_SPEW, "PM1_STS: ");
49 if (pm1_sts & (1 << 15)) printk(BIOS_SPEW, "WAK ");
50 if (pm1_sts & (1 << 14)) printk(BIOS_SPEW, "PCIEXPWAK ");
51 if (pm1_sts & (1 << 11)) printk(BIOS_SPEW, "PRBTNOR ");
52 if (pm1_sts & (1 << 10)) printk(BIOS_SPEW, "RTC ");
53 if (pm1_sts & (1 << 8)) printk(BIOS_SPEW, "PWRBTN ");
54 if (pm1_sts & (1 << 5)) printk(BIOS_SPEW, "GBL ");
55 if (pm1_sts & (1 << 4)) printk(BIOS_SPEW, "BM ");
56 if (pm1_sts & (1 << 0)) printk(BIOS_SPEW, "TMROF ");
57 printk(BIOS_SPEW, "\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +000058 int reg16 = inw(pmbase + PM1_EN);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000059 printk(BIOS_SPEW, "PM1_EN: %x\n", reg16);
Stefan Reinauer800379f2010-03-01 08:34:19 +000060}
61
62/**
63 * @brief read and clear SMI_STS
64 * @return SMI_STS register
65 */
66static u32 reset_smi_status(void)
67{
68 u32 reg32;
69
70 reg32 = inl(pmbase + SMI_STS);
71 /* set status bits are cleared by writing 1 to them */
72 outl(reg32, pmbase + SMI_STS);
73
74 return reg32;
75}
76
77static void dump_smi_status(u32 smi_sts)
78{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000079 printk(BIOS_DEBUG, "SMI_STS: ");
80 if (smi_sts & (1 << 26)) printk(BIOS_DEBUG, "SPI ");
81 if (smi_sts & (1 << 25)) printk(BIOS_DEBUG, "EL_SMI ");
82 if (smi_sts & (1 << 21)) printk(BIOS_DEBUG, "MONITOR ");
83 if (smi_sts & (1 << 20)) printk(BIOS_DEBUG, "PCI_EXP_SMI ");
84 if (smi_sts & (1 << 18)) printk(BIOS_DEBUG, "INTEL_USB2 ");
85 if (smi_sts & (1 << 17)) printk(BIOS_DEBUG, "LEGACY_USB2 ");
86 if (smi_sts & (1 << 16)) printk(BIOS_DEBUG, "SMBUS_SMI ");
87 if (smi_sts & (1 << 15)) printk(BIOS_DEBUG, "SERIRQ_SMI ");
88 if (smi_sts & (1 << 14)) printk(BIOS_DEBUG, "PERIODIC ");
89 if (smi_sts & (1 << 13)) printk(BIOS_DEBUG, "TCO ");
90 if (smi_sts & (1 << 12)) printk(BIOS_DEBUG, "DEVMON ");
91 if (smi_sts & (1 << 11)) printk(BIOS_DEBUG, "MCSMI ");
92 if (smi_sts & (1 << 10)) printk(BIOS_DEBUG, "GPI ");
93 if (smi_sts & (1 << 9)) printk(BIOS_DEBUG, "GPE0 ");
94 if (smi_sts & (1 << 8)) printk(BIOS_DEBUG, "PM1 ");
95 if (smi_sts & (1 << 6)) printk(BIOS_DEBUG, "SWSMI_TMR ");
96 if (smi_sts & (1 << 5)) printk(BIOS_DEBUG, "APM ");
97 if (smi_sts & (1 << 4)) printk(BIOS_DEBUG, "SLP_SMI ");
98 if (smi_sts & (1 << 3)) printk(BIOS_DEBUG, "LEGACY_USB ");
99 if (smi_sts & (1 << 2)) printk(BIOS_DEBUG, "BIOS ");
100 printk(BIOS_DEBUG, "\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000101}
102
103
104/**
105 * @brief read and clear GPE0_STS
106 * @return GPE0_STS register
107 */
108static u32 reset_gpe0_status(void)
109{
110 u32 reg32;
111
112 reg32 = inl(pmbase + GPE0_STS);
113 /* set status bits are cleared by writing 1 to them */
114 outl(reg32, pmbase + GPE0_STS);
115
116 return reg32;
117}
118
119static void dump_gpe0_status(u32 gpe0_sts)
120{
121 int i;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000122 printk(BIOS_DEBUG, "GPE0_STS: ");
Konstantin Aladyshev62f80832013-03-07 04:04:27 +0400123 for (i=31; i>= 16; i--) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000124 if (gpe0_sts & (1 << i)) printk(BIOS_DEBUG, "GPIO%d ", (i-16));
Stefan Reinauer800379f2010-03-01 08:34:19 +0000125 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000126 if (gpe0_sts & (1 << 14)) printk(BIOS_DEBUG, "USB4 ");
127 if (gpe0_sts & (1 << 13)) printk(BIOS_DEBUG, "PME_B0 ");
128 if (gpe0_sts & (1 << 12)) printk(BIOS_DEBUG, "USB3 ");
129 if (gpe0_sts & (1 << 11)) printk(BIOS_DEBUG, "PME ");
130 if (gpe0_sts & (1 << 10)) printk(BIOS_DEBUG, "EL_SCI/BATLOW ");
131 if (gpe0_sts & (1 << 9)) printk(BIOS_DEBUG, "PCI_EXP ");
132 if (gpe0_sts & (1 << 8)) printk(BIOS_DEBUG, "RI ");
133 if (gpe0_sts & (1 << 7)) printk(BIOS_DEBUG, "SMB_WAK ");
134 if (gpe0_sts & (1 << 6)) printk(BIOS_DEBUG, "TCO_SCI ");
135 if (gpe0_sts & (1 << 5)) printk(BIOS_DEBUG, "AC97 ");
136 if (gpe0_sts & (1 << 4)) printk(BIOS_DEBUG, "USB2 ");
137 if (gpe0_sts & (1 << 3)) printk(BIOS_DEBUG, "USB1 ");
138 if (gpe0_sts & (1 << 2)) printk(BIOS_DEBUG, "HOT_PLUG ");
139 if (gpe0_sts & (1 << 0)) printk(BIOS_DEBUG, "THRM ");
140 printk(BIOS_DEBUG, "\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000141}
142
143
144/**
145 * @brief read and clear TCOx_STS
146 * @return TCOx_STS registers
147 */
148static u32 reset_tco_status(void)
149{
150 u32 tcobase = pmbase + 0x60;
151 u32 reg32;
152
153 reg32 = inl(tcobase + 0x04);
154 /* set status bits are cleared by writing 1 to them */
155 outl(reg32 & ~(1<<18), tcobase + 0x04); // Don't clear BOOT_STS before SECOND_TO_STS
156 if (reg32 & (1 << 18))
157 outl(reg32 & (1<<18), tcobase + 0x04); // clear BOOT_STS
158
159 return reg32;
160}
161
162
163static void dump_tco_status(u32 tco_sts)
164{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000165 printk(BIOS_DEBUG, "TCO_STS: ");
166 if (tco_sts & (1 << 20)) printk(BIOS_DEBUG, "SMLINK_SLV ");
167 if (tco_sts & (1 << 18)) printk(BIOS_DEBUG, "BOOT ");
168 if (tco_sts & (1 << 17)) printk(BIOS_DEBUG, "SECOND_TO ");
169 if (tco_sts & (1 << 16)) printk(BIOS_DEBUG, "INTRD_DET ");
170 if (tco_sts & (1 << 12)) printk(BIOS_DEBUG, "DMISERR ");
171 if (tco_sts & (1 << 10)) printk(BIOS_DEBUG, "DMISMI ");
172 if (tco_sts & (1 << 9)) printk(BIOS_DEBUG, "DMISCI ");
173 if (tco_sts & (1 << 8)) printk(BIOS_DEBUG, "BIOSWR ");
174 if (tco_sts & (1 << 7)) printk(BIOS_DEBUG, "NEWCENTURY ");
175 if (tco_sts & (1 << 3)) printk(BIOS_DEBUG, "TIMEOUT ");
176 if (tco_sts & (1 << 2)) printk(BIOS_DEBUG, "TCO_INT ");
177 if (tco_sts & (1 << 1)) printk(BIOS_DEBUG, "SW_TCO ");
178 if (tco_sts & (1 << 0)) printk(BIOS_DEBUG, "NMI2SMI ");
179 printk(BIOS_DEBUG, "\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000180}
181
Stefan Reinauer800379f2010-03-01 08:34:19 +0000182/**
183 * @brief Set the EOS bit
184 */
185void southbridge_smi_set_eos(void)
186{
187 u8 reg8;
188
189 reg8 = inb(pmbase + SMI_EN);
190 reg8 |= EOS;
191 outb(reg8, pmbase + SMI_EN);
192}
193
194static void busmaster_disable_on_bus(int bus)
195{
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200196 int slot, func;
197 unsigned int val;
198 unsigned char hdr;
Stefan Reinauer800379f2010-03-01 08:34:19 +0000199
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200200 for (slot = 0; slot < 0x20; slot++) {
201 for (func = 0; func < 8; func++) {
Elyes HAOUAS2f2191a2020-04-28 19:59:30 +0200202 u16 reg16;
Antonello Dettorif9aac2f2016-09-03 10:45:33 +0200203 pci_devfn_t dev = PCI_DEV(bus, slot, func);
Stefan Reinauer800379f2010-03-01 08:34:19 +0000204
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200205 val = pci_read_config32(dev, PCI_VENDOR_ID);
Stefan Reinauer800379f2010-03-01 08:34:19 +0000206
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200207 if (val == 0xffffffff || val == 0x00000000 ||
208 val == 0x0000ffff || val == 0xffff0000)
209 continue;
Stefan Reinauer800379f2010-03-01 08:34:19 +0000210
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200211 /* Disable Bus Mastering for this one device */
Elyes HAOUAS2f2191a2020-04-28 19:59:30 +0200212 reg16 = pci_read_config16(dev, PCI_COMMAND);
213 reg16 &= ~PCI_COMMAND_MASTER;
214 pci_write_config16(dev, PCI_COMMAND, reg16);
Stefan Reinauer800379f2010-03-01 08:34:19 +0000215
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200216 /* If this is a bridge, then follow it. */
217 hdr = pci_read_config8(dev, PCI_HEADER_TYPE);
218 hdr &= 0x7f;
219 if (hdr == PCI_HEADER_TYPE_BRIDGE ||
220 hdr == PCI_HEADER_TYPE_CARDBUS) {
221 unsigned int buses;
222 buses = pci_read_config32(dev, PCI_PRIMARY_BUS);
223 busmaster_disable_on_bus((buses >> 8) & 0xff);
224 }
225 }
226 }
Stefan Reinauer800379f2010-03-01 08:34:19 +0000227}
228
229
Kyösti Mälkkib9872822019-08-10 15:47:29 +0300230static void southbridge_smi_sleep(void)
Stefan Reinauer800379f2010-03-01 08:34:19 +0000231{
232 u8 reg8;
233 u32 reg32;
234 u8 slp_typ;
235 /* FIXME: the power state on boot should be read from
236 * CMOS or even better from GNVS. Right now it's hard
237 * coded at compile time.
238 */
Nico Huber9faae2b2018-11-14 00:00:35 +0100239 u8 s5pwr = CONFIG_MAINBOARD_POWER_FAILURE_STATE;
Stefan Reinauer800379f2010-03-01 08:34:19 +0000240
241 /* First, disable further SMIs */
242 reg8 = inb(pmbase + SMI_EN);
243 reg8 &= ~SLP_SMI_EN;
244 outb(reg8, pmbase + SMI_EN);
245
246 /* Figure out SLP_TYP */
247 reg32 = inl(pmbase + PM1_CNT);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000248 printk(BIOS_SPEW, "SMI#: SLP = 0x%08x\n", reg32);
Aaron Durbin671909b2016-07-13 23:24:36 -0500249 slp_typ = acpi_sleep_from_pm1(reg32);
Stefan Reinauer800379f2010-03-01 08:34:19 +0000250
251 /* Next, do the deed.
252 */
253
254 switch (slp_typ) {
Aaron Durbin671909b2016-07-13 23:24:36 -0500255 case ACPI_S0: printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n"); break;
256 case ACPI_S1: printk(BIOS_DEBUG, "SMI#: Entering S1 (Assert STPCLK#)\n"); break;
257 case ACPI_S3:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000258 printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000259 /* Invalidate the cache before going to S3 */
260 wbinvd();
261 break;
Aaron Durbin671909b2016-07-13 23:24:36 -0500262 case ACPI_S4: printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n"); break;
263 case ACPI_S5:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000264 printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000265
266 outl(0, pmbase + GPE0_EN);
267
268 /* Should we keep the power state after a power loss?
269 * In case the setting is "ON" or "OFF" we don't have
270 * to do anything. But if it's "KEEP" we have to switch
271 * to "OFF" before entering S5.
272 */
273 if (s5pwr == MAINBOARD_POWER_KEEP) {
274 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3);
275 reg8 |= 1;
276 pci_write_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3, reg8);
277 }
278
279 /* also iterates over all bridges on bus 0 */
280 busmaster_disable_on_bus(0);
281 break;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000282 default: printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n"); break;
Stefan Reinauer800379f2010-03-01 08:34:19 +0000283 }
284
285 /* Write back to the SLP register to cause the originally intended
286 * event again. We need to set BIT13 (SLP_EN) though to make the
287 * sleep happen.
288 */
289 outl(reg32 | SLP_EN, pmbase + PM1_CNT);
290
291 /* In most sleep states, the code flow of this function ends at
292 * the line above. However, if we entered sleep state S1 and wake
293 * up again, we will continue to execute code in this function.
294 */
295 reg32 = inl(pmbase + PM1_CNT);
296 if (reg32 & SCI_EN) {
297 /* The OS is not an ACPI OS, so we set the state to S0 */
298 reg32 &= ~(SLP_EN | SLP_TYP);
299 outl(reg32, pmbase + PM1_CNT);
300 }
301}
302
Kyösti Mälkkib9872822019-08-10 15:47:29 +0300303static void southbridge_smi_apmc(void)
Stefan Reinauer800379f2010-03-01 08:34:19 +0000304{
305 u32 pmctrl;
306 u8 reg8;
307
308 /* Emulate B2 register as the FADT / Linux expects it */
309
310 reg8 = inb(APM_CNT);
311 switch (reg8) {
Sven Schnellef4dc1a72011-06-05 11:33:41 +0200312 case APM_CNT_CST_CONTROL:
Stefan Reinauer800379f2010-03-01 08:34:19 +0000313 /* Calling this function seems to cause
314 * some kind of race condition in Linux
315 * and causes a kernel oops
316 */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000317 printk(BIOS_DEBUG, "C-state control\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000318 break;
Sven Schnellef4dc1a72011-06-05 11:33:41 +0200319 case APM_CNT_PST_CONTROL:
Stefan Reinauer800379f2010-03-01 08:34:19 +0000320 /* Calling this function seems to cause
321 * some kind of race condition in Linux
322 * and causes a kernel oops
323 */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000324 printk(BIOS_DEBUG, "P-state control\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000325 break;
Sven Schnellef4dc1a72011-06-05 11:33:41 +0200326 case APM_CNT_ACPI_DISABLE:
Stefan Reinauer800379f2010-03-01 08:34:19 +0000327 pmctrl = inl(pmbase + PM1_CNT);
328 pmctrl &= ~SCI_EN;
329 outl(pmctrl, pmbase + PM1_CNT);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000330 printk(BIOS_DEBUG, "SMI#: ACPI disabled.\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000331 break;
Sven Schnellef4dc1a72011-06-05 11:33:41 +0200332 case APM_CNT_ACPI_ENABLE:
Stefan Reinauer800379f2010-03-01 08:34:19 +0000333 pmctrl = inl(pmbase + PM1_CNT);
334 pmctrl |= SCI_EN;
335 outl(pmctrl, pmbase + PM1_CNT);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000336 printk(BIOS_DEBUG, "SMI#: ACPI enabled.\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000337 break;
Sven Schnellef4dc1a72011-06-05 11:33:41 +0200338 case APM_CNT_MBI_UPDATE: // FIXME
Stefan Reinauer800379f2010-03-01 08:34:19 +0000339 if (mbi_initialized) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000340 printk(BIOS_DEBUG, "SMI#: mbi already registered!\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000341 return;
342 }
343 mbi = *(void **)0x500;
344 mbi_len = *(u32 *)0x504;
345 mbi_initialized = 1;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000346 printk(BIOS_DEBUG, "SMI#: Registered MBI at %p (%d bytes)\n", mbi, mbi_len);
Stefan Reinauer800379f2010-03-01 08:34:19 +0000347 break;
348
349 default:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000350 printk(BIOS_DEBUG, "SMI#: Unknown function APM_CNT=%02x\n", reg8);
Stefan Reinauer800379f2010-03-01 08:34:19 +0000351 }
352}
353
Kyösti Mälkkib9872822019-08-10 15:47:29 +0300354static void southbridge_smi_pm1(void)
Stefan Reinauer800379f2010-03-01 08:34:19 +0000355{
356 u16 pm1_sts;
357
358 pm1_sts = reset_pm1_status();
359 dump_pm1_status(pm1_sts);
360
361 /* While OSPM is not active, poweroff immediately
362 * on a power button event.
363 */
364 if (pm1_sts & PWRBTN_STS) {
365 // power button pressed
366 u32 reg32;
367 reg32 = (7 << 10) | (1 << 13);
368 outl(reg32, pmbase + PM1_CNT);
369 }
370}
371
Kyösti Mälkkib9872822019-08-10 15:47:29 +0300372static void southbridge_smi_gpe0(void)
Stefan Reinauer800379f2010-03-01 08:34:19 +0000373{
374 u32 gpe0_sts;
375
376 gpe0_sts = reset_gpe0_status();
377 dump_gpe0_status(gpe0_sts);
378}
379
Kyösti Mälkkib9872822019-08-10 15:47:29 +0300380static void southbridge_smi_gpi(void)
Stefan Reinauer800379f2010-03-01 08:34:19 +0000381{
382 u16 reg16;
383 reg16 = inw(pmbase + ALT_GP_SMI_STS);
384 outl(reg16, pmbase + ALT_GP_SMI_STS);
385
386 reg16 &= inw(pmbase + ALT_GP_SMI_EN);
387
Kyösti Mälkki48b3dbc2014-12-29 19:36:50 +0200388 mainboard_smi_gpi(reg16);
389
390 if (reg16)
391 printk(BIOS_DEBUG, "GPI (mask %04x)\n",reg16);
Stefan Reinauer800379f2010-03-01 08:34:19 +0000392}
393
Kyösti Mälkkib9872822019-08-10 15:47:29 +0300394static void southbridge_smi_mc(void)
Stefan Reinauer800379f2010-03-01 08:34:19 +0000395{
396 u32 reg32;
397
398 reg32 = inl(pmbase + SMI_EN);
399
400 /* Are periodic SMIs enabled? */
401 if ((reg32 & MCSMI_EN) == 0)
402 return;
403
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000404 printk(BIOS_DEBUG, "Microcontroller SMI.\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000405}
406
407
408
Kyösti Mälkkib9872822019-08-10 15:47:29 +0300409static void southbridge_smi_tco(void)
Stefan Reinauer800379f2010-03-01 08:34:19 +0000410{
411 u32 tco_sts;
412
413 tco_sts = reset_tco_status();
414
415 /* Any TCO event? */
416 if (!tco_sts)
417 return;
418
419 if (tco_sts & (1 << 8)) { // BIOSWR
420 u8 bios_cntl;
421
422 bios_cntl = pci_read_config16(PCI_DEV(0, 0x1f, 0), 0xdc);
423
424 if (bios_cntl & 1) {
425 /* BWE is RW, so the SMI was caused by a
426 * write to BWE, not by a write to the BIOS
427 */
428
429 /* This is the place where we notice someone
430 * is trying to tinker with the BIOS. We are
431 * trying to be nice and just ignore it. A more
432 * resolute answer would be to power down the
433 * box.
434 */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000435 printk(BIOS_DEBUG, "Switching back to RO\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000436 pci_write_config32(PCI_DEV(0, 0x1f, 0), 0xdc, (bios_cntl & ~1));
437 } /* No else for now? */
438 } else if (tco_sts & (1 << 3)) { /* TIMEOUT */
439 /* Handle TCO timeout */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000440 printk(BIOS_DEBUG, "TCO Timeout.\n");
Jacob Garber7eb8eed2019-04-03 09:18:32 -0600441 } else {
Stefan Reinauer800379f2010-03-01 08:34:19 +0000442 dump_tco_status(tco_sts);
443 }
444}
445
Kyösti Mälkkib9872822019-08-10 15:47:29 +0300446static void southbridge_smi_periodic(void)
Stefan Reinauer800379f2010-03-01 08:34:19 +0000447{
448 u32 reg32;
449
450 reg32 = inl(pmbase + SMI_EN);
451
452 /* Are periodic SMIs enabled? */
453 if ((reg32 & PERIODIC_EN) == 0)
454 return;
455
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000456 printk(BIOS_DEBUG, "Periodic SMI.\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000457}
458
Kyösti Mälkkib9872822019-08-10 15:47:29 +0300459typedef void (*smi_handler_t)(void);
Stefan Reinauer800379f2010-03-01 08:34:19 +0000460
Stefan Reinauer348a1ba2010-03-17 01:51:11 +0000461smi_handler_t southbridge_smi[32] = {
Stefan Reinauer800379f2010-03-01 08:34:19 +0000462 NULL, // [0] reserved
463 NULL, // [1] reserved
464 NULL, // [2] BIOS_STS
465 NULL, // [3] LEGACY_USB_STS
466 southbridge_smi_sleep, // [4] SLP_SMI_STS
467 southbridge_smi_apmc, // [5] APM_STS
468 NULL, // [6] SWSMI_TMR_STS
469 NULL, // [7] reserved
470 southbridge_smi_pm1, // [8] PM1_STS
471 southbridge_smi_gpe0, // [9] GPE0_STS
472 southbridge_smi_gpi, // [10] GPI_STS
473 southbridge_smi_mc, // [11] MCSMI_STS
474 NULL, // [12] DEVMON_STS
475 southbridge_smi_tco, // [13] TCO_STS
476 southbridge_smi_periodic, // [14] PERIODIC_STS
477 NULL, // [15] SERIRQ_SMI_STS
478 NULL, // [16] SMBUS_SMI_STS
479 NULL, // [17] LEGACY_USB2_STS
480 NULL, // [18] INTEL_USB2_STS
481 NULL, // [19] reserved
482 NULL, // [20] PCI_EXP_SMI_STS
Kyösti Mälkkif4617c02020-06-28 17:46:39 +0300483 NULL, // [21] MONITOR_STS
Stefan Reinauer800379f2010-03-01 08:34:19 +0000484 NULL, // [22] reserved
485 NULL, // [23] reserved
486 NULL, // [24] reserved
487 NULL, // [25] EL_SMI_STS
488 NULL, // [26] SPI_STS
489 NULL, // [27] reserved
490 NULL, // [28] reserved
491 NULL, // [29] reserved
492 NULL, // [30] reserved
493 NULL // [31] reserved
494};
495
496/**
497 * @brief Interrupt handler for SMI#
Stefan Reinauer800379f2010-03-01 08:34:19 +0000498 */
Kyösti Mälkki1ef039b2019-08-10 15:32:03 +0300499void southbridge_smi_handler(void)
Stefan Reinauer800379f2010-03-01 08:34:19 +0000500{
501 int i, dump = 0;
502 u32 smi_sts;
503
504 /* Update global variable pmbase */
505 pmbase = pci_read_config16(PCI_DEV(0, 0x1f, 0), 0x40) & 0xfffc;
506
507 /* We need to clear the SMI status registers, or we won't see what's
508 * happening in the following calls.
509 */
510 smi_sts = reset_smi_status();
511
512 /* Filter all non-enabled SMI events */
513 // FIXME Double check, this clears MONITOR
514 // smi_sts &= inl(pmbase + SMI_EN);
515
516 /* Call SMI sub handler for each of the status bits */
517 for (i = 0; i < 31; i++) {
518 if (smi_sts & (1 << i)) {
Kyösti Mälkkib9872822019-08-10 15:47:29 +0300519 if (southbridge_smi[i]) {
520 southbridge_smi[i]();
521 } else {
Martin Roth2ed0aa22016-01-05 20:58:58 -0700522 printk(BIOS_DEBUG, "SMI_STS[%d] occurred, but no "
Stefan Reinauer800379f2010-03-01 08:34:19 +0000523 "handler available.\n", i);
524 dump = 1;
525 }
526 }
527 }
528
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200529 if (dump) {
Stefan Reinauer800379f2010-03-01 08:34:19 +0000530 dump_smi_status(smi_sts);
531 }
Stefan Reinauer800379f2010-03-01 08:34:19 +0000532}