blob: 63758761f2bb12f7931ef09888c54ffd8ccdcad8 [file] [log] [blame]
Stefan Reinauer800379f2010-03-01 08:34:19 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 * MA 02110-1301 USA
20 */
21
22#include <types.h>
23#include <arch/io.h>
Stefan Reinauer800379f2010-03-01 08:34:19 +000024#include <console/console.h>
25#include <cpu/x86/cache.h>
26#include <cpu/x86/smm.h>
27#include <device/pci_def.h>
28#include "i82801dx.h"
29
30#define DEBUG_SMI
31
Stefan Reinauer800379f2010-03-01 08:34:19 +000032/* I830M */
33#define SMRAM 0x90
34#define D_OPEN (1 << 6)
35#define D_CLS (1 << 5)
36#define D_LCK (1 << 4)
37#define G_SMRANE (1 << 3)
38#define C_BASE_SEG ((0 << 2) | (1 << 1) | (0 << 0))
39
stepan836ae292010-12-08 05:42:47 +000040#include "nvs.h"
Stefan Reinauer800379f2010-03-01 08:34:19 +000041
42/* While we read PMBASE dynamically in case it changed, let's
43 * initialize it with a sane value
44 */
45u16 pmbase = PMBASE_ADDR;
46u8 smm_initialized = 0;
47
48unsigned char *mbi = NULL;
49u32 mbi_len;
50u8 mbi_initialized = 0;
51
52/* GNVS needs to be updated by an 0xEA PM Trap (B2) after it has been located
53 * by coreboot.
54 */
55global_nvs_t *gnvs = (global_nvs_t *)0x0;
56void *tcg = (void *)0x0;
57void *smi1 = (void *)0x0;
58
59/**
60 * @brief read and clear PM1_STS
61 * @return PM1_STS register
62 */
63static u16 reset_pm1_status(void)
64{
65 u16 reg16;
66
67 reg16 = inw(pmbase + PM1_STS);
68 /* set status bits are cleared by writing 1 to them */
69 outw(reg16, pmbase + PM1_STS);
70
71 return reg16;
72}
73
74static void dump_pm1_status(u16 pm1_sts)
75{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000076 printk(BIOS_SPEW, "PM1_STS: ");
77 if (pm1_sts & (1 << 15)) printk(BIOS_SPEW, "WAK ");
78 if (pm1_sts & (1 << 14)) printk(BIOS_SPEW, "PCIEXPWAK ");
79 if (pm1_sts & (1 << 11)) printk(BIOS_SPEW, "PRBTNOR ");
80 if (pm1_sts & (1 << 10)) printk(BIOS_SPEW, "RTC ");
81 if (pm1_sts & (1 << 8)) printk(BIOS_SPEW, "PWRBTN ");
82 if (pm1_sts & (1 << 5)) printk(BIOS_SPEW, "GBL ");
83 if (pm1_sts & (1 << 4)) printk(BIOS_SPEW, "BM ");
84 if (pm1_sts & (1 << 0)) printk(BIOS_SPEW, "TMROF ");
85 printk(BIOS_SPEW, "\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +000086 int reg16 = inw(pmbase + PM1_EN);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000087 printk(BIOS_SPEW, "PM1_EN: %x\n", reg16);
Stefan Reinauer800379f2010-03-01 08:34:19 +000088}
89
90/**
91 * @brief read and clear SMI_STS
92 * @return SMI_STS register
93 */
94static u32 reset_smi_status(void)
95{
96 u32 reg32;
97
98 reg32 = inl(pmbase + SMI_STS);
99 /* set status bits are cleared by writing 1 to them */
100 outl(reg32, pmbase + SMI_STS);
101
102 return reg32;
103}
104
105static void dump_smi_status(u32 smi_sts)
106{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000107 printk(BIOS_DEBUG, "SMI_STS: ");
108 if (smi_sts & (1 << 26)) printk(BIOS_DEBUG, "SPI ");
109 if (smi_sts & (1 << 25)) printk(BIOS_DEBUG, "EL_SMI ");
110 if (smi_sts & (1 << 21)) printk(BIOS_DEBUG, "MONITOR ");
111 if (smi_sts & (1 << 20)) printk(BIOS_DEBUG, "PCI_EXP_SMI ");
112 if (smi_sts & (1 << 18)) printk(BIOS_DEBUG, "INTEL_USB2 ");
113 if (smi_sts & (1 << 17)) printk(BIOS_DEBUG, "LEGACY_USB2 ");
114 if (smi_sts & (1 << 16)) printk(BIOS_DEBUG, "SMBUS_SMI ");
115 if (smi_sts & (1 << 15)) printk(BIOS_DEBUG, "SERIRQ_SMI ");
116 if (smi_sts & (1 << 14)) printk(BIOS_DEBUG, "PERIODIC ");
117 if (smi_sts & (1 << 13)) printk(BIOS_DEBUG, "TCO ");
118 if (smi_sts & (1 << 12)) printk(BIOS_DEBUG, "DEVMON ");
119 if (smi_sts & (1 << 11)) printk(BIOS_DEBUG, "MCSMI ");
120 if (smi_sts & (1 << 10)) printk(BIOS_DEBUG, "GPI ");
121 if (smi_sts & (1 << 9)) printk(BIOS_DEBUG, "GPE0 ");
122 if (smi_sts & (1 << 8)) printk(BIOS_DEBUG, "PM1 ");
123 if (smi_sts & (1 << 6)) printk(BIOS_DEBUG, "SWSMI_TMR ");
124 if (smi_sts & (1 << 5)) printk(BIOS_DEBUG, "APM ");
125 if (smi_sts & (1 << 4)) printk(BIOS_DEBUG, "SLP_SMI ");
126 if (smi_sts & (1 << 3)) printk(BIOS_DEBUG, "LEGACY_USB ");
127 if (smi_sts & (1 << 2)) printk(BIOS_DEBUG, "BIOS ");
128 printk(BIOS_DEBUG, "\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000129}
130
131
132/**
133 * @brief read and clear GPE0_STS
134 * @return GPE0_STS register
135 */
136static u32 reset_gpe0_status(void)
137{
138 u32 reg32;
139
140 reg32 = inl(pmbase + GPE0_STS);
141 /* set status bits are cleared by writing 1 to them */
142 outl(reg32, pmbase + GPE0_STS);
143
144 return reg32;
145}
146
147static void dump_gpe0_status(u32 gpe0_sts)
148{
149 int i;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000150 printk(BIOS_DEBUG, "GPE0_STS: ");
Konstantin Aladyshev62f80832013-03-07 04:04:27 +0400151 for (i=31; i>= 16; i--) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000152 if (gpe0_sts & (1 << i)) printk(BIOS_DEBUG, "GPIO%d ", (i-16));
Stefan Reinauer800379f2010-03-01 08:34:19 +0000153 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000154 if (gpe0_sts & (1 << 14)) printk(BIOS_DEBUG, "USB4 ");
155 if (gpe0_sts & (1 << 13)) printk(BIOS_DEBUG, "PME_B0 ");
156 if (gpe0_sts & (1 << 12)) printk(BIOS_DEBUG, "USB3 ");
157 if (gpe0_sts & (1 << 11)) printk(BIOS_DEBUG, "PME ");
158 if (gpe0_sts & (1 << 10)) printk(BIOS_DEBUG, "EL_SCI/BATLOW ");
159 if (gpe0_sts & (1 << 9)) printk(BIOS_DEBUG, "PCI_EXP ");
160 if (gpe0_sts & (1 << 8)) printk(BIOS_DEBUG, "RI ");
161 if (gpe0_sts & (1 << 7)) printk(BIOS_DEBUG, "SMB_WAK ");
162 if (gpe0_sts & (1 << 6)) printk(BIOS_DEBUG, "TCO_SCI ");
163 if (gpe0_sts & (1 << 5)) printk(BIOS_DEBUG, "AC97 ");
164 if (gpe0_sts & (1 << 4)) printk(BIOS_DEBUG, "USB2 ");
165 if (gpe0_sts & (1 << 3)) printk(BIOS_DEBUG, "USB1 ");
166 if (gpe0_sts & (1 << 2)) printk(BIOS_DEBUG, "HOT_PLUG ");
167 if (gpe0_sts & (1 << 0)) printk(BIOS_DEBUG, "THRM ");
168 printk(BIOS_DEBUG, "\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000169}
170
171
172/**
173 * @brief read and clear TCOx_STS
174 * @return TCOx_STS registers
175 */
176static u32 reset_tco_status(void)
177{
178 u32 tcobase = pmbase + 0x60;
179 u32 reg32;
180
181 reg32 = inl(tcobase + 0x04);
182 /* set status bits are cleared by writing 1 to them */
183 outl(reg32 & ~(1<<18), tcobase + 0x04); // Don't clear BOOT_STS before SECOND_TO_STS
184 if (reg32 & (1 << 18))
185 outl(reg32 & (1<<18), tcobase + 0x04); // clear BOOT_STS
186
187 return reg32;
188}
189
190
191static void dump_tco_status(u32 tco_sts)
192{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000193 printk(BIOS_DEBUG, "TCO_STS: ");
194 if (tco_sts & (1 << 20)) printk(BIOS_DEBUG, "SMLINK_SLV ");
195 if (tco_sts & (1 << 18)) printk(BIOS_DEBUG, "BOOT ");
196 if (tco_sts & (1 << 17)) printk(BIOS_DEBUG, "SECOND_TO ");
197 if (tco_sts & (1 << 16)) printk(BIOS_DEBUG, "INTRD_DET ");
198 if (tco_sts & (1 << 12)) printk(BIOS_DEBUG, "DMISERR ");
199 if (tco_sts & (1 << 10)) printk(BIOS_DEBUG, "DMISMI ");
200 if (tco_sts & (1 << 9)) printk(BIOS_DEBUG, "DMISCI ");
201 if (tco_sts & (1 << 8)) printk(BIOS_DEBUG, "BIOSWR ");
202 if (tco_sts & (1 << 7)) printk(BIOS_DEBUG, "NEWCENTURY ");
203 if (tco_sts & (1 << 3)) printk(BIOS_DEBUG, "TIMEOUT ");
204 if (tco_sts & (1 << 2)) printk(BIOS_DEBUG, "TCO_INT ");
205 if (tco_sts & (1 << 1)) printk(BIOS_DEBUG, "SW_TCO ");
206 if (tco_sts & (1 << 0)) printk(BIOS_DEBUG, "NMI2SMI ");
207 printk(BIOS_DEBUG, "\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000208}
209
Stefan Reinauer800379f2010-03-01 08:34:19 +0000210int southbridge_io_trap_handler(int smif)
211{
212 switch (smif) {
213 case 0x32:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000214 printk(BIOS_DEBUG, "OS Init\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000215 /* gnvs->smif:
216 * On success, the IO Trap Handler returns 0
217 * On failure, the IO Trap Handler returns a value != 0
218 */
219 gnvs->smif = 0;
220 return 1; /* IO trap handled */
221 }
222
223 /* Not handled */
224 return 0;
225}
226
227/**
228 * @brief Set the EOS bit
229 */
230void southbridge_smi_set_eos(void)
231{
232 u8 reg8;
233
234 reg8 = inb(pmbase + SMI_EN);
235 reg8 |= EOS;
236 outb(reg8, pmbase + SMI_EN);
237}
238
239static void busmaster_disable_on_bus(int bus)
240{
241 int slot, func;
242 unsigned int val;
243 unsigned char hdr;
244
245 for (slot = 0; slot < 0x20; slot++) {
246 for (func = 0; func < 8; func++) {
247 u32 reg32;
248 device_t dev = PCI_DEV(bus, slot, func);
249
250 val = pci_read_config32(dev, PCI_VENDOR_ID);
251
252 if (val == 0xffffffff || val == 0x00000000 ||
253 val == 0x0000ffff || val == 0xffff0000)
254 continue;
255
256 /* Disable Bus Mastering for this one device */
257 reg32 = pci_read_config32(dev, PCI_COMMAND);
258 reg32 &= ~PCI_COMMAND_MASTER;
259 pci_write_config32(dev, PCI_COMMAND, reg32);
260
261 /* If this is a bridge, then follow it. */
262 hdr = pci_read_config8(dev, PCI_HEADER_TYPE);
263 hdr &= 0x7f;
264 if (hdr == PCI_HEADER_TYPE_BRIDGE ||
265 hdr == PCI_HEADER_TYPE_CARDBUS) {
266 unsigned int buses;
267 buses = pci_read_config32(dev, PCI_PRIMARY_BUS);
268 busmaster_disable_on_bus((buses >> 8) & 0xff);
269 }
270 }
271 }
272}
273
274
275static void southbridge_smi_sleep(unsigned int node, smm_state_save_area_t *state_save)
276{
277 u8 reg8;
278 u32 reg32;
279 u8 slp_typ;
280 /* FIXME: the power state on boot should be read from
281 * CMOS or even better from GNVS. Right now it's hard
282 * coded at compile time.
283 */
284 u8 s5pwr = CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL;
285
286 /* First, disable further SMIs */
287 reg8 = inb(pmbase + SMI_EN);
288 reg8 &= ~SLP_SMI_EN;
289 outb(reg8, pmbase + SMI_EN);
290
291 /* Figure out SLP_TYP */
292 reg32 = inl(pmbase + PM1_CNT);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000293 printk(BIOS_SPEW, "SMI#: SLP = 0x%08x\n", reg32);
Stefan Reinauer800379f2010-03-01 08:34:19 +0000294 slp_typ = (reg32 >> 10) & 7;
295
296 /* Next, do the deed.
297 */
298
299 switch (slp_typ) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000300 case 0: printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n"); break;
301 case 1: printk(BIOS_DEBUG, "SMI#: Entering S1 (Assert STPCLK#)\n"); break;
Stefan Reinauer800379f2010-03-01 08:34:19 +0000302 case 5:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000303 printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000304 /* Invalidate the cache before going to S3 */
305 wbinvd();
306 break;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000307 case 6: printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n"); break;
Stefan Reinauer800379f2010-03-01 08:34:19 +0000308 case 7:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000309 printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000310
311 outl(0, pmbase + GPE0_EN);
312
313 /* Should we keep the power state after a power loss?
314 * In case the setting is "ON" or "OFF" we don't have
315 * to do anything. But if it's "KEEP" we have to switch
316 * to "OFF" before entering S5.
317 */
318 if (s5pwr == MAINBOARD_POWER_KEEP) {
319 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3);
320 reg8 |= 1;
321 pci_write_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3, reg8);
322 }
323
324 /* also iterates over all bridges on bus 0 */
325 busmaster_disable_on_bus(0);
326 break;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000327 default: printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n"); break;
Stefan Reinauer800379f2010-03-01 08:34:19 +0000328 }
329
330 /* Write back to the SLP register to cause the originally intended
331 * event again. We need to set BIT13 (SLP_EN) though to make the
332 * sleep happen.
333 */
334 outl(reg32 | SLP_EN, pmbase + PM1_CNT);
335
336 /* In most sleep states, the code flow of this function ends at
337 * the line above. However, if we entered sleep state S1 and wake
338 * up again, we will continue to execute code in this function.
339 */
340 reg32 = inl(pmbase + PM1_CNT);
341 if (reg32 & SCI_EN) {
342 /* The OS is not an ACPI OS, so we set the state to S0 */
343 reg32 &= ~(SLP_EN | SLP_TYP);
344 outl(reg32, pmbase + PM1_CNT);
345 }
346}
347
348static void southbridge_smi_apmc(unsigned int node, smm_state_save_area_t *state_save)
349{
350 u32 pmctrl;
351 u8 reg8;
352
353 /* Emulate B2 register as the FADT / Linux expects it */
354
355 reg8 = inb(APM_CNT);
356 switch (reg8) {
Sven Schnellef4dc1a72011-06-05 11:33:41 +0200357 case APM_CNT_CST_CONTROL:
Stefan Reinauer800379f2010-03-01 08:34:19 +0000358 /* Calling this function seems to cause
359 * some kind of race condition in Linux
360 * and causes a kernel oops
361 */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000362 printk(BIOS_DEBUG, "C-state control\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000363 break;
Sven Schnellef4dc1a72011-06-05 11:33:41 +0200364 case APM_CNT_PST_CONTROL:
Stefan Reinauer800379f2010-03-01 08:34:19 +0000365 /* Calling this function seems to cause
366 * some kind of race condition in Linux
367 * and causes a kernel oops
368 */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000369 printk(BIOS_DEBUG, "P-state control\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000370 break;
Sven Schnellef4dc1a72011-06-05 11:33:41 +0200371 case APM_CNT_ACPI_DISABLE:
Stefan Reinauer800379f2010-03-01 08:34:19 +0000372 pmctrl = inl(pmbase + PM1_CNT);
373 pmctrl &= ~SCI_EN;
374 outl(pmctrl, pmbase + PM1_CNT);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000375 printk(BIOS_DEBUG, "SMI#: ACPI disabled.\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000376 break;
Sven Schnellef4dc1a72011-06-05 11:33:41 +0200377 case APM_CNT_ACPI_ENABLE:
Stefan Reinauer800379f2010-03-01 08:34:19 +0000378 pmctrl = inl(pmbase + PM1_CNT);
379 pmctrl |= SCI_EN;
380 outl(pmctrl, pmbase + PM1_CNT);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000381 printk(BIOS_DEBUG, "SMI#: ACPI enabled.\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000382 break;
Sven Schnellef4dc1a72011-06-05 11:33:41 +0200383 case APM_CNT_GNVS_UPDATE:
Stefan Reinauer800379f2010-03-01 08:34:19 +0000384 if (smm_initialized) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000385 printk(BIOS_DEBUG, "SMI#: SMM structures already initialized!\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000386 return;
387 }
388 gnvs = *(global_nvs_t **)0x500;
389 tcg = *(void **)0x504;
390 smi1 = *(void **)0x508;
391 smm_initialized = 1;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000392 printk(BIOS_DEBUG, "SMI#: Setting up structures to %p, %p, %p\n", gnvs, tcg, smi1);
Stefan Reinauer800379f2010-03-01 08:34:19 +0000393 break;
Sven Schnellef4dc1a72011-06-05 11:33:41 +0200394 case APM_CNT_MBI_UPDATE: // FIXME
Stefan Reinauer800379f2010-03-01 08:34:19 +0000395 if (mbi_initialized) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000396 printk(BIOS_DEBUG, "SMI#: mbi already registered!\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000397 return;
398 }
399 mbi = *(void **)0x500;
400 mbi_len = *(u32 *)0x504;
401 mbi_initialized = 1;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000402 printk(BIOS_DEBUG, "SMI#: Registered MBI at %p (%d bytes)\n", mbi, mbi_len);
Stefan Reinauer800379f2010-03-01 08:34:19 +0000403 break;
404
405 default:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000406 printk(BIOS_DEBUG, "SMI#: Unknown function APM_CNT=%02x\n", reg8);
Stefan Reinauer800379f2010-03-01 08:34:19 +0000407 }
408}
409
410static void southbridge_smi_pm1(unsigned int node, smm_state_save_area_t *state_save)
411{
412 u16 pm1_sts;
413
414 pm1_sts = reset_pm1_status();
415 dump_pm1_status(pm1_sts);
416
417 /* While OSPM is not active, poweroff immediately
418 * on a power button event.
419 */
420 if (pm1_sts & PWRBTN_STS) {
421 // power button pressed
422 u32 reg32;
423 reg32 = (7 << 10) | (1 << 13);
424 outl(reg32, pmbase + PM1_CNT);
425 }
426}
427
428static void southbridge_smi_gpe0(unsigned int node, smm_state_save_area_t *state_save)
429{
430 u32 gpe0_sts;
431
432 gpe0_sts = reset_gpe0_status();
433 dump_gpe0_status(gpe0_sts);
434}
435
Stefan Reinauer800379f2010-03-01 08:34:19 +0000436static void southbridge_smi_gpi(unsigned int node, smm_state_save_area_t *state_save)
437{
438 u16 reg16;
439 reg16 = inw(pmbase + ALT_GP_SMI_STS);
440 outl(reg16, pmbase + ALT_GP_SMI_STS);
441
442 reg16 &= inw(pmbase + ALT_GP_SMI_EN);
443
Kyƶsti MƤlkki48b3dbc2014-12-29 19:36:50 +0200444 mainboard_smi_gpi(reg16);
445
446 if (reg16)
447 printk(BIOS_DEBUG, "GPI (mask %04x)\n",reg16);
Stefan Reinauer800379f2010-03-01 08:34:19 +0000448}
449
450static void southbridge_smi_mc(unsigned int node, smm_state_save_area_t *state_save)
451{
452 u32 reg32;
453
454 reg32 = inl(pmbase + SMI_EN);
455
456 /* Are periodic SMIs enabled? */
457 if ((reg32 & MCSMI_EN) == 0)
458 return;
459
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000460 printk(BIOS_DEBUG, "Microcontroller SMI.\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000461}
462
463
464
465static void southbridge_smi_tco(unsigned int node, smm_state_save_area_t *state_save)
466{
467 u32 tco_sts;
468
469 tco_sts = reset_tco_status();
470
471 /* Any TCO event? */
472 if (!tco_sts)
473 return;
474
475 if (tco_sts & (1 << 8)) { // BIOSWR
476 u8 bios_cntl;
477
478 bios_cntl = pci_read_config16(PCI_DEV(0, 0x1f, 0), 0xdc);
479
480 if (bios_cntl & 1) {
481 /* BWE is RW, so the SMI was caused by a
482 * write to BWE, not by a write to the BIOS
483 */
484
485 /* This is the place where we notice someone
486 * is trying to tinker with the BIOS. We are
487 * trying to be nice and just ignore it. A more
488 * resolute answer would be to power down the
489 * box.
490 */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000491 printk(BIOS_DEBUG, "Switching back to RO\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000492 pci_write_config32(PCI_DEV(0, 0x1f, 0), 0xdc, (bios_cntl & ~1));
493 } /* No else for now? */
494 } else if (tco_sts & (1 << 3)) { /* TIMEOUT */
495 /* Handle TCO timeout */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000496 printk(BIOS_DEBUG, "TCO Timeout.\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000497 } else if (!tco_sts) {
498 dump_tco_status(tco_sts);
499 }
500}
501
502static void southbridge_smi_periodic(unsigned int node, smm_state_save_area_t *state_save)
503{
504 u32 reg32;
505
506 reg32 = inl(pmbase + SMI_EN);
507
508 /* Are periodic SMIs enabled? */
509 if ((reg32 & PERIODIC_EN) == 0)
510 return;
511
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000512 printk(BIOS_DEBUG, "Periodic SMI.\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000513}
514
515static void southbridge_smi_monitor(unsigned int node, smm_state_save_area_t *state_save)
516{
517#define IOTRAP(x) (trap_sts & (1 << x))
518#if 0
519 u32 trap_sts, trap_cycle;
520 u32 data, mask = 0;
521 int i;
522
523 trap_sts = RCBA32(0x1e00); // TRSR - Trap Status Register
524 RCBA32(0x1e00) = trap_sts; // Clear trap(s) in TRSR
525
526 trap_cycle = RCBA32(0x1e10);
527 for (i=16; i<20; i++) {
528 if (trap_cycle & (1 << i))
529 mask |= (0xff << ((i - 16) << 2));
530 }
531
532
533 /* IOTRAP(3) SMI function call */
534 if (IOTRAP(3)) {
535 if (gnvs && gnvs->smif)
536 io_trap_handler(gnvs->smif); // call function smif
537 return;
538 }
539
540 /* IOTRAP(2) currently unused
541 * IOTRAP(1) currently unused */
542
543 /* IOTRAP(0) SMIC */
544 if (IOTRAP(0)) {
545 if (!(trap_cycle & (1 << 24))) { // It's a write
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000546 printk(BIOS_DEBUG, "SMI1 command\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000547 data = RCBA32(0x1e18);
548 data &= mask;
549 // if (smi1)
550 // southbridge_smi_command(data);
551 // return;
552 }
553 // Fall through to debug
554 }
555
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000556 printk(BIOS_DEBUG, " trapped io address = 0x%x\n", trap_cycle & 0xfffc);
557 for (i=0; i < 4; i++) if(IOTRAP(i)) printk(BIOS_DEBUG, " TRAPĀ = %d\n", i);
558 printk(BIOS_DEBUG, " AHBE = %x\n", (trap_cycle >> 16) & 0xf);
559 printk(BIOS_DEBUG, " MASK = 0x%08x\n", mask);
560 printk(BIOS_DEBUG, " read/write: %s\n", (trap_cycle & (1 << 24)) ? "read" : "write");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000561
562 if (!(trap_cycle & (1 << 24))) {
563 /* Write Cycle */
564 data = RCBA32(0x1e18);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000565 printk(BIOS_DEBUG, " iotrap written data = 0x%08x\n", data);
Stefan Reinauer800379f2010-03-01 08:34:19 +0000566 }
567#endif
568#undef IOTRAP
569}
570
Stefan Reinauer348a1ba2010-03-17 01:51:11 +0000571typedef void (*smi_handler_t)(unsigned int node,
Stefan Reinauer800379f2010-03-01 08:34:19 +0000572 smm_state_save_area_t *state_save);
573
Stefan Reinauer348a1ba2010-03-17 01:51:11 +0000574smi_handler_t southbridge_smi[32] = {
Stefan Reinauer800379f2010-03-01 08:34:19 +0000575 NULL, // [0] reserved
576 NULL, // [1] reserved
577 NULL, // [2] BIOS_STS
578 NULL, // [3] LEGACY_USB_STS
579 southbridge_smi_sleep, // [4] SLP_SMI_STS
580 southbridge_smi_apmc, // [5] APM_STS
581 NULL, // [6] SWSMI_TMR_STS
582 NULL, // [7] reserved
583 southbridge_smi_pm1, // [8] PM1_STS
584 southbridge_smi_gpe0, // [9] GPE0_STS
585 southbridge_smi_gpi, // [10] GPI_STS
586 southbridge_smi_mc, // [11] MCSMI_STS
587 NULL, // [12] DEVMON_STS
588 southbridge_smi_tco, // [13] TCO_STS
589 southbridge_smi_periodic, // [14] PERIODIC_STS
590 NULL, // [15] SERIRQ_SMI_STS
591 NULL, // [16] SMBUS_SMI_STS
592 NULL, // [17] LEGACY_USB2_STS
593 NULL, // [18] INTEL_USB2_STS
594 NULL, // [19] reserved
595 NULL, // [20] PCI_EXP_SMI_STS
596 southbridge_smi_monitor, // [21] MONITOR_STS
597 NULL, // [22] reserved
598 NULL, // [23] reserved
599 NULL, // [24] reserved
600 NULL, // [25] EL_SMI_STS
601 NULL, // [26] SPI_STS
602 NULL, // [27] reserved
603 NULL, // [28] reserved
604 NULL, // [29] reserved
605 NULL, // [30] reserved
606 NULL // [31] reserved
607};
608
609/**
610 * @brief Interrupt handler for SMI#
Martin Roth182e551f2014-12-29 22:29:08 -0700611 * @param node
612 * @param state_save
Stefan Reinauer800379f2010-03-01 08:34:19 +0000613 */
Stefan Reinauer800379f2010-03-01 08:34:19 +0000614void southbridge_smi_handler(unsigned int node, smm_state_save_area_t *state_save)
615{
616 int i, dump = 0;
617 u32 smi_sts;
618
619 /* Update global variable pmbase */
620 pmbase = pci_read_config16(PCI_DEV(0, 0x1f, 0), 0x40) & 0xfffc;
621
622 /* We need to clear the SMI status registers, or we won't see what's
623 * happening in the following calls.
624 */
625 smi_sts = reset_smi_status();
626
627 /* Filter all non-enabled SMI events */
628 // FIXME Double check, this clears MONITOR
629 // smi_sts &= inl(pmbase + SMI_EN);
630
631 /* Call SMI sub handler for each of the status bits */
632 for (i = 0; i < 31; i++) {
633 if (smi_sts & (1 << i)) {
634 if (southbridge_smi[i])
635 southbridge_smi[i](node, state_save);
636 else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000637 printk(BIOS_DEBUG, "SMI_STS[%d] occured, but no "
Stefan Reinauer800379f2010-03-01 08:34:19 +0000638 "handler available.\n", i);
639 dump = 1;
640 }
641 }
642 }
643
644 if(dump) {
645 dump_smi_status(smi_sts);
646 }
647
648}