blob: 107cf80aeaaec02a2265c5dd14865f56e28e258b [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>
24#include <arch/romcc_io.h>
25#include <console/console.h>
26#include <cpu/x86/cache.h>
27#include <cpu/x86/smm.h>
28#include <device/pci_def.h>
29#include "i82801dx.h"
30
31#define DEBUG_SMI
32
33#define APM_CNT 0xb2
34#define CST_CONTROL 0x85
35#define PST_CONTROL 0x80
36#define ACPI_DISABLE 0x1e
37#define ACPI_ENABLE 0xe1
38#define GNVS_UPDATE 0xea
39#define MBI_UPDATE 0xeb
40#define APM_STS 0xb3
41
42/* I830M */
43#define SMRAM 0x90
44#define D_OPEN (1 << 6)
45#define D_CLS (1 << 5)
46#define D_LCK (1 << 4)
47#define G_SMRANE (1 << 3)
48#define C_BASE_SEG ((0 << 2) | (1 << 1) | (0 << 0))
49
50#include "i82801dx_nvs.h"
51
52/* While we read PMBASE dynamically in case it changed, let's
53 * initialize it with a sane value
54 */
55u16 pmbase = PMBASE_ADDR;
56u8 smm_initialized = 0;
57
58unsigned char *mbi = NULL;
59u32 mbi_len;
60u8 mbi_initialized = 0;
61
62/* GNVS needs to be updated by an 0xEA PM Trap (B2) after it has been located
63 * by coreboot.
64 */
65global_nvs_t *gnvs = (global_nvs_t *)0x0;
66void *tcg = (void *)0x0;
67void *smi1 = (void *)0x0;
68
69/**
70 * @brief read and clear PM1_STS
71 * @return PM1_STS register
72 */
73static u16 reset_pm1_status(void)
74{
75 u16 reg16;
76
77 reg16 = inw(pmbase + PM1_STS);
78 /* set status bits are cleared by writing 1 to them */
79 outw(reg16, pmbase + PM1_STS);
80
81 return reg16;
82}
83
84static void dump_pm1_status(u16 pm1_sts)
85{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000086 printk(BIOS_SPEW, "PM1_STS: ");
87 if (pm1_sts & (1 << 15)) printk(BIOS_SPEW, "WAK ");
88 if (pm1_sts & (1 << 14)) printk(BIOS_SPEW, "PCIEXPWAK ");
89 if (pm1_sts & (1 << 11)) printk(BIOS_SPEW, "PRBTNOR ");
90 if (pm1_sts & (1 << 10)) printk(BIOS_SPEW, "RTC ");
91 if (pm1_sts & (1 << 8)) printk(BIOS_SPEW, "PWRBTN ");
92 if (pm1_sts & (1 << 5)) printk(BIOS_SPEW, "GBL ");
93 if (pm1_sts & (1 << 4)) printk(BIOS_SPEW, "BM ");
94 if (pm1_sts & (1 << 0)) printk(BIOS_SPEW, "TMROF ");
95 printk(BIOS_SPEW, "\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +000096 int reg16 = inw(pmbase + PM1_EN);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000097 printk(BIOS_SPEW, "PM1_EN: %x\n", reg16);
Stefan Reinauer800379f2010-03-01 08:34:19 +000098}
99
100/**
101 * @brief read and clear SMI_STS
102 * @return SMI_STS register
103 */
104static u32 reset_smi_status(void)
105{
106 u32 reg32;
107
108 reg32 = inl(pmbase + SMI_STS);
109 /* set status bits are cleared by writing 1 to them */
110 outl(reg32, pmbase + SMI_STS);
111
112 return reg32;
113}
114
115static void dump_smi_status(u32 smi_sts)
116{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000117 printk(BIOS_DEBUG, "SMI_STS: ");
118 if (smi_sts & (1 << 26)) printk(BIOS_DEBUG, "SPI ");
119 if (smi_sts & (1 << 25)) printk(BIOS_DEBUG, "EL_SMI ");
120 if (smi_sts & (1 << 21)) printk(BIOS_DEBUG, "MONITOR ");
121 if (smi_sts & (1 << 20)) printk(BIOS_DEBUG, "PCI_EXP_SMI ");
122 if (smi_sts & (1 << 18)) printk(BIOS_DEBUG, "INTEL_USB2 ");
123 if (smi_sts & (1 << 17)) printk(BIOS_DEBUG, "LEGACY_USB2 ");
124 if (smi_sts & (1 << 16)) printk(BIOS_DEBUG, "SMBUS_SMI ");
125 if (smi_sts & (1 << 15)) printk(BIOS_DEBUG, "SERIRQ_SMI ");
126 if (smi_sts & (1 << 14)) printk(BIOS_DEBUG, "PERIODIC ");
127 if (smi_sts & (1 << 13)) printk(BIOS_DEBUG, "TCO ");
128 if (smi_sts & (1 << 12)) printk(BIOS_DEBUG, "DEVMON ");
129 if (smi_sts & (1 << 11)) printk(BIOS_DEBUG, "MCSMI ");
130 if (smi_sts & (1 << 10)) printk(BIOS_DEBUG, "GPI ");
131 if (smi_sts & (1 << 9)) printk(BIOS_DEBUG, "GPE0 ");
132 if (smi_sts & (1 << 8)) printk(BIOS_DEBUG, "PM1 ");
133 if (smi_sts & (1 << 6)) printk(BIOS_DEBUG, "SWSMI_TMR ");
134 if (smi_sts & (1 << 5)) printk(BIOS_DEBUG, "APM ");
135 if (smi_sts & (1 << 4)) printk(BIOS_DEBUG, "SLP_SMI ");
136 if (smi_sts & (1 << 3)) printk(BIOS_DEBUG, "LEGACY_USB ");
137 if (smi_sts & (1 << 2)) printk(BIOS_DEBUG, "BIOS ");
138 printk(BIOS_DEBUG, "\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000139}
140
141
142/**
143 * @brief read and clear GPE0_STS
144 * @return GPE0_STS register
145 */
146static u32 reset_gpe0_status(void)
147{
148 u32 reg32;
149
150 reg32 = inl(pmbase + GPE0_STS);
151 /* set status bits are cleared by writing 1 to them */
152 outl(reg32, pmbase + GPE0_STS);
153
154 return reg32;
155}
156
157static void dump_gpe0_status(u32 gpe0_sts)
158{
159 int i;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000160 printk(BIOS_DEBUG, "GPE0_STS: ");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000161 for (i=31; i<= 16; i--) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000162 if (gpe0_sts & (1 << i)) printk(BIOS_DEBUG, "GPIO%d ", (i-16));
Stefan Reinauer800379f2010-03-01 08:34:19 +0000163 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000164 if (gpe0_sts & (1 << 14)) printk(BIOS_DEBUG, "USB4 ");
165 if (gpe0_sts & (1 << 13)) printk(BIOS_DEBUG, "PME_B0 ");
166 if (gpe0_sts & (1 << 12)) printk(BIOS_DEBUG, "USB3 ");
167 if (gpe0_sts & (1 << 11)) printk(BIOS_DEBUG, "PME ");
168 if (gpe0_sts & (1 << 10)) printk(BIOS_DEBUG, "EL_SCI/BATLOW ");
169 if (gpe0_sts & (1 << 9)) printk(BIOS_DEBUG, "PCI_EXP ");
170 if (gpe0_sts & (1 << 8)) printk(BIOS_DEBUG, "RI ");
171 if (gpe0_sts & (1 << 7)) printk(BIOS_DEBUG, "SMB_WAK ");
172 if (gpe0_sts & (1 << 6)) printk(BIOS_DEBUG, "TCO_SCI ");
173 if (gpe0_sts & (1 << 5)) printk(BIOS_DEBUG, "AC97 ");
174 if (gpe0_sts & (1 << 4)) printk(BIOS_DEBUG, "USB2 ");
175 if (gpe0_sts & (1 << 3)) printk(BIOS_DEBUG, "USB1 ");
176 if (gpe0_sts & (1 << 2)) printk(BIOS_DEBUG, "HOT_PLUG ");
177 if (gpe0_sts & (1 << 0)) printk(BIOS_DEBUG, "THRM ");
178 printk(BIOS_DEBUG, "\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000179}
180
181
182/**
183 * @brief read and clear TCOx_STS
184 * @return TCOx_STS registers
185 */
186static u32 reset_tco_status(void)
187{
188 u32 tcobase = pmbase + 0x60;
189 u32 reg32;
190
191 reg32 = inl(tcobase + 0x04);
192 /* set status bits are cleared by writing 1 to them */
193 outl(reg32 & ~(1<<18), tcobase + 0x04); // Don't clear BOOT_STS before SECOND_TO_STS
194 if (reg32 & (1 << 18))
195 outl(reg32 & (1<<18), tcobase + 0x04); // clear BOOT_STS
196
197 return reg32;
198}
199
200
201static void dump_tco_status(u32 tco_sts)
202{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000203 printk(BIOS_DEBUG, "TCO_STS: ");
204 if (tco_sts & (1 << 20)) printk(BIOS_DEBUG, "SMLINK_SLV ");
205 if (tco_sts & (1 << 18)) printk(BIOS_DEBUG, "BOOT ");
206 if (tco_sts & (1 << 17)) printk(BIOS_DEBUG, "SECOND_TO ");
207 if (tco_sts & (1 << 16)) printk(BIOS_DEBUG, "INTRD_DET ");
208 if (tco_sts & (1 << 12)) printk(BIOS_DEBUG, "DMISERR ");
209 if (tco_sts & (1 << 10)) printk(BIOS_DEBUG, "DMISMI ");
210 if (tco_sts & (1 << 9)) printk(BIOS_DEBUG, "DMISCI ");
211 if (tco_sts & (1 << 8)) printk(BIOS_DEBUG, "BIOSWR ");
212 if (tco_sts & (1 << 7)) printk(BIOS_DEBUG, "NEWCENTURY ");
213 if (tco_sts & (1 << 3)) printk(BIOS_DEBUG, "TIMEOUT ");
214 if (tco_sts & (1 << 2)) printk(BIOS_DEBUG, "TCO_INT ");
215 if (tco_sts & (1 << 1)) printk(BIOS_DEBUG, "SW_TCO ");
216 if (tco_sts & (1 << 0)) printk(BIOS_DEBUG, "NMI2SMI ");
217 printk(BIOS_DEBUG, "\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000218}
219
220/* We are using PCIe accesses for now
221 * 1. the chipset can do it
222 * 2. we don't need to worry about how we leave 0xcf8/0xcfc behind
223 */
224// #include "../../../northbridge/intel/i945/pcie_config.c"
225
226int southbridge_io_trap_handler(int smif)
227{
228 switch (smif) {
229 case 0x32:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000230 printk(BIOS_DEBUG, "OS Init\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000231 /* gnvs->smif:
232 * On success, the IO Trap Handler returns 0
233 * On failure, the IO Trap Handler returns a value != 0
234 */
235 gnvs->smif = 0;
236 return 1; /* IO trap handled */
237 }
238
239 /* Not handled */
240 return 0;
241}
242
243/**
244 * @brief Set the EOS bit
245 */
246void southbridge_smi_set_eos(void)
247{
248 u8 reg8;
249
250 reg8 = inb(pmbase + SMI_EN);
251 reg8 |= EOS;
252 outb(reg8, pmbase + SMI_EN);
253}
254
255static void busmaster_disable_on_bus(int bus)
256{
257 int slot, func;
258 unsigned int val;
259 unsigned char hdr;
260
261 for (slot = 0; slot < 0x20; slot++) {
262 for (func = 0; func < 8; func++) {
263 u32 reg32;
264 device_t dev = PCI_DEV(bus, slot, func);
265
266 val = pci_read_config32(dev, PCI_VENDOR_ID);
267
268 if (val == 0xffffffff || val == 0x00000000 ||
269 val == 0x0000ffff || val == 0xffff0000)
270 continue;
271
272 /* Disable Bus Mastering for this one device */
273 reg32 = pci_read_config32(dev, PCI_COMMAND);
274 reg32 &= ~PCI_COMMAND_MASTER;
275 pci_write_config32(dev, PCI_COMMAND, reg32);
276
277 /* If this is a bridge, then follow it. */
278 hdr = pci_read_config8(dev, PCI_HEADER_TYPE);
279 hdr &= 0x7f;
280 if (hdr == PCI_HEADER_TYPE_BRIDGE ||
281 hdr == PCI_HEADER_TYPE_CARDBUS) {
282 unsigned int buses;
283 buses = pci_read_config32(dev, PCI_PRIMARY_BUS);
284 busmaster_disable_on_bus((buses >> 8) & 0xff);
285 }
286 }
287 }
288}
289
290
291static void southbridge_smi_sleep(unsigned int node, smm_state_save_area_t *state_save)
292{
293 u8 reg8;
294 u32 reg32;
295 u8 slp_typ;
296 /* FIXME: the power state on boot should be read from
297 * CMOS or even better from GNVS. Right now it's hard
298 * coded at compile time.
299 */
300 u8 s5pwr = CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL;
301
302 /* First, disable further SMIs */
303 reg8 = inb(pmbase + SMI_EN);
304 reg8 &= ~SLP_SMI_EN;
305 outb(reg8, pmbase + SMI_EN);
306
307 /* Figure out SLP_TYP */
308 reg32 = inl(pmbase + PM1_CNT);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000309 printk(BIOS_SPEW, "SMI#: SLP = 0x%08x\n", reg32);
Stefan Reinauer800379f2010-03-01 08:34:19 +0000310 slp_typ = (reg32 >> 10) & 7;
311
312 /* Next, do the deed.
313 */
314
315 switch (slp_typ) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000316 case 0: printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n"); break;
317 case 1: printk(BIOS_DEBUG, "SMI#: Entering S1 (Assert STPCLK#)\n"); break;
Stefan Reinauer800379f2010-03-01 08:34:19 +0000318 case 5:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000319 printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000320 /* Invalidate the cache before going to S3 */
321 wbinvd();
322 break;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000323 case 6: printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n"); break;
Stefan Reinauer800379f2010-03-01 08:34:19 +0000324 case 7:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000325 printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000326
327 outl(0, pmbase + GPE0_EN);
328
329 /* Should we keep the power state after a power loss?
330 * In case the setting is "ON" or "OFF" we don't have
331 * to do anything. But if it's "KEEP" we have to switch
332 * to "OFF" before entering S5.
333 */
334 if (s5pwr == MAINBOARD_POWER_KEEP) {
335 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3);
336 reg8 |= 1;
337 pci_write_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3, reg8);
338 }
339
340 /* also iterates over all bridges on bus 0 */
341 busmaster_disable_on_bus(0);
342 break;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000343 default: printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n"); break;
Stefan Reinauer800379f2010-03-01 08:34:19 +0000344 }
345
346 /* Write back to the SLP register to cause the originally intended
347 * event again. We need to set BIT13 (SLP_EN) though to make the
348 * sleep happen.
349 */
350 outl(reg32 | SLP_EN, pmbase + PM1_CNT);
351
352 /* In most sleep states, the code flow of this function ends at
353 * the line above. However, if we entered sleep state S1 and wake
354 * up again, we will continue to execute code in this function.
355 */
356 reg32 = inl(pmbase + PM1_CNT);
357 if (reg32 & SCI_EN) {
358 /* The OS is not an ACPI OS, so we set the state to S0 */
359 reg32 &= ~(SLP_EN | SLP_TYP);
360 outl(reg32, pmbase + PM1_CNT);
361 }
362}
363
364static void southbridge_smi_apmc(unsigned int node, smm_state_save_area_t *state_save)
365{
366 u32 pmctrl;
367 u8 reg8;
368
369 /* Emulate B2 register as the FADT / Linux expects it */
370
371 reg8 = inb(APM_CNT);
372 switch (reg8) {
373 case CST_CONTROL:
374 /* Calling this function seems to cause
375 * some kind of race condition in Linux
376 * and causes a kernel oops
377 */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000378 printk(BIOS_DEBUG, "C-state control\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000379 break;
380 case PST_CONTROL:
381 /* Calling this function seems to cause
382 * some kind of race condition in Linux
383 * and causes a kernel oops
384 */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000385 printk(BIOS_DEBUG, "P-state control\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000386 break;
387 case ACPI_DISABLE:
388 pmctrl = inl(pmbase + PM1_CNT);
389 pmctrl &= ~SCI_EN;
390 outl(pmctrl, pmbase + PM1_CNT);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000391 printk(BIOS_DEBUG, "SMI#: ACPI disabled.\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000392 break;
393 case ACPI_ENABLE:
394 pmctrl = inl(pmbase + PM1_CNT);
395 pmctrl |= SCI_EN;
396 outl(pmctrl, pmbase + PM1_CNT);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000397 printk(BIOS_DEBUG, "SMI#: ACPI enabled.\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000398 break;
399 case GNVS_UPDATE:
400 if (smm_initialized) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000401 printk(BIOS_DEBUG, "SMI#: SMM structures already initialized!\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000402 return;
403 }
404 gnvs = *(global_nvs_t **)0x500;
405 tcg = *(void **)0x504;
406 smi1 = *(void **)0x508;
407 smm_initialized = 1;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000408 printk(BIOS_DEBUG, "SMI#: Setting up structures to %p, %p, %p\n", gnvs, tcg, smi1);
Stefan Reinauer800379f2010-03-01 08:34:19 +0000409 break;
410 case MBI_UPDATE: // FIXME
411 if (mbi_initialized) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000412 printk(BIOS_DEBUG, "SMI#: mbi already registered!\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000413 return;
414 }
415 mbi = *(void **)0x500;
416 mbi_len = *(u32 *)0x504;
417 mbi_initialized = 1;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000418 printk(BIOS_DEBUG, "SMI#: Registered MBI at %p (%d bytes)\n", mbi, mbi_len);
Stefan Reinauer800379f2010-03-01 08:34:19 +0000419 break;
420
421 default:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000422 printk(BIOS_DEBUG, "SMI#: Unknown function APM_CNT=%02x\n", reg8);
Stefan Reinauer800379f2010-03-01 08:34:19 +0000423 }
424}
425
426static void southbridge_smi_pm1(unsigned int node, smm_state_save_area_t *state_save)
427{
428 u16 pm1_sts;
429
430 pm1_sts = reset_pm1_status();
431 dump_pm1_status(pm1_sts);
432
433 /* While OSPM is not active, poweroff immediately
434 * on a power button event.
435 */
436 if (pm1_sts & PWRBTN_STS) {
437 // power button pressed
438 u32 reg32;
439 reg32 = (7 << 10) | (1 << 13);
440 outl(reg32, pmbase + PM1_CNT);
441 }
442}
443
444static void southbridge_smi_gpe0(unsigned int node, smm_state_save_area_t *state_save)
445{
446 u32 gpe0_sts;
447
448 gpe0_sts = reset_gpe0_status();
449 dump_gpe0_status(gpe0_sts);
450}
451
452void __attribute__((weak)) mainboard_smi_gpi(u16 gpi_sts);
453
454static void southbridge_smi_gpi(unsigned int node, smm_state_save_area_t *state_save)
455{
456 u16 reg16;
457 reg16 = inw(pmbase + ALT_GP_SMI_STS);
458 outl(reg16, pmbase + ALT_GP_SMI_STS);
459
460 reg16 &= inw(pmbase + ALT_GP_SMI_EN);
461
462 if (mainboard_smi_gpi) {
463 mainboard_smi_gpi(reg16);
464 } else {
465 if (reg16)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000466 printk(BIOS_DEBUG, "GPI (mask %04x)\n",reg16);
Stefan Reinauer800379f2010-03-01 08:34:19 +0000467 }
468}
469
470static void southbridge_smi_mc(unsigned int node, smm_state_save_area_t *state_save)
471{
472 u32 reg32;
473
474 reg32 = inl(pmbase + SMI_EN);
475
476 /* Are periodic SMIs enabled? */
477 if ((reg32 & MCSMI_EN) == 0)
478 return;
479
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000480 printk(BIOS_DEBUG, "Microcontroller SMI.\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000481}
482
483
484
485static void southbridge_smi_tco(unsigned int node, smm_state_save_area_t *state_save)
486{
487 u32 tco_sts;
488
489 tco_sts = reset_tco_status();
490
491 /* Any TCO event? */
492 if (!tco_sts)
493 return;
494
495 if (tco_sts & (1 << 8)) { // BIOSWR
496 u8 bios_cntl;
497
498 bios_cntl = pci_read_config16(PCI_DEV(0, 0x1f, 0), 0xdc);
499
500 if (bios_cntl & 1) {
501 /* BWE is RW, so the SMI was caused by a
502 * write to BWE, not by a write to the BIOS
503 */
504
505 /* This is the place where we notice someone
506 * is trying to tinker with the BIOS. We are
507 * trying to be nice and just ignore it. A more
508 * resolute answer would be to power down the
509 * box.
510 */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000511 printk(BIOS_DEBUG, "Switching back to RO\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000512 pci_write_config32(PCI_DEV(0, 0x1f, 0), 0xdc, (bios_cntl & ~1));
513 } /* No else for now? */
514 } else if (tco_sts & (1 << 3)) { /* TIMEOUT */
515 /* Handle TCO timeout */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000516 printk(BIOS_DEBUG, "TCO Timeout.\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000517 } else if (!tco_sts) {
518 dump_tco_status(tco_sts);
519 }
520}
521
522static void southbridge_smi_periodic(unsigned int node, smm_state_save_area_t *state_save)
523{
524 u32 reg32;
525
526 reg32 = inl(pmbase + SMI_EN);
527
528 /* Are periodic SMIs enabled? */
529 if ((reg32 & PERIODIC_EN) == 0)
530 return;
531
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000532 printk(BIOS_DEBUG, "Periodic SMI.\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000533}
534
535static void southbridge_smi_monitor(unsigned int node, smm_state_save_area_t *state_save)
536{
537#define IOTRAP(x) (trap_sts & (1 << x))
538#if 0
539 u32 trap_sts, trap_cycle;
540 u32 data, mask = 0;
541 int i;
542
543 trap_sts = RCBA32(0x1e00); // TRSR - Trap Status Register
544 RCBA32(0x1e00) = trap_sts; // Clear trap(s) in TRSR
545
546 trap_cycle = RCBA32(0x1e10);
547 for (i=16; i<20; i++) {
548 if (trap_cycle & (1 << i))
549 mask |= (0xff << ((i - 16) << 2));
550 }
551
552
553 /* IOTRAP(3) SMI function call */
554 if (IOTRAP(3)) {
555 if (gnvs && gnvs->smif)
556 io_trap_handler(gnvs->smif); // call function smif
557 return;
558 }
559
560 /* IOTRAP(2) currently unused
561 * IOTRAP(1) currently unused */
562
563 /* IOTRAP(0) SMIC */
564 if (IOTRAP(0)) {
565 if (!(trap_cycle & (1 << 24))) { // It's a write
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000566 printk(BIOS_DEBUG, "SMI1 command\n");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000567 data = RCBA32(0x1e18);
568 data &= mask;
569 // if (smi1)
570 // southbridge_smi_command(data);
571 // return;
572 }
573 // Fall through to debug
574 }
575
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000576 printk(BIOS_DEBUG, " trapped io address = 0x%x\n", trap_cycle & 0xfffc);
577 for (i=0; i < 4; i++) if(IOTRAP(i)) printk(BIOS_DEBUG, " TRAPĀ = %d\n", i);
578 printk(BIOS_DEBUG, " AHBE = %x\n", (trap_cycle >> 16) & 0xf);
579 printk(BIOS_DEBUG, " MASK = 0x%08x\n", mask);
580 printk(BIOS_DEBUG, " read/write: %s\n", (trap_cycle & (1 << 24)) ? "read" : "write");
Stefan Reinauer800379f2010-03-01 08:34:19 +0000581
582 if (!(trap_cycle & (1 << 24))) {
583 /* Write Cycle */
584 data = RCBA32(0x1e18);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000585 printk(BIOS_DEBUG, " iotrap written data = 0x%08x\n", data);
Stefan Reinauer800379f2010-03-01 08:34:19 +0000586 }
587#endif
588#undef IOTRAP
589}
590
Stefan Reinauer348a1ba2010-03-17 01:51:11 +0000591typedef void (*smi_handler_t)(unsigned int node,
Stefan Reinauer800379f2010-03-01 08:34:19 +0000592 smm_state_save_area_t *state_save);
593
Stefan Reinauer348a1ba2010-03-17 01:51:11 +0000594smi_handler_t southbridge_smi[32] = {
Stefan Reinauer800379f2010-03-01 08:34:19 +0000595 NULL, // [0] reserved
596 NULL, // [1] reserved
597 NULL, // [2] BIOS_STS
598 NULL, // [3] LEGACY_USB_STS
599 southbridge_smi_sleep, // [4] SLP_SMI_STS
600 southbridge_smi_apmc, // [5] APM_STS
601 NULL, // [6] SWSMI_TMR_STS
602 NULL, // [7] reserved
603 southbridge_smi_pm1, // [8] PM1_STS
604 southbridge_smi_gpe0, // [9] GPE0_STS
605 southbridge_smi_gpi, // [10] GPI_STS
606 southbridge_smi_mc, // [11] MCSMI_STS
607 NULL, // [12] DEVMON_STS
608 southbridge_smi_tco, // [13] TCO_STS
609 southbridge_smi_periodic, // [14] PERIODIC_STS
610 NULL, // [15] SERIRQ_SMI_STS
611 NULL, // [16] SMBUS_SMI_STS
612 NULL, // [17] LEGACY_USB2_STS
613 NULL, // [18] INTEL_USB2_STS
614 NULL, // [19] reserved
615 NULL, // [20] PCI_EXP_SMI_STS
616 southbridge_smi_monitor, // [21] MONITOR_STS
617 NULL, // [22] reserved
618 NULL, // [23] reserved
619 NULL, // [24] reserved
620 NULL, // [25] EL_SMI_STS
621 NULL, // [26] SPI_STS
622 NULL, // [27] reserved
623 NULL, // [28] reserved
624 NULL, // [29] reserved
625 NULL, // [30] reserved
626 NULL // [31] reserved
627};
628
629/**
630 * @brief Interrupt handler for SMI#
631 *
632 * @param smm_revision revision of the smm state save map
633 */
634
635void southbridge_smi_handler(unsigned int node, smm_state_save_area_t *state_save)
636{
637 int i, dump = 0;
638 u32 smi_sts;
639
640 /* Update global variable pmbase */
641 pmbase = pci_read_config16(PCI_DEV(0, 0x1f, 0), 0x40) & 0xfffc;
642
643 /* We need to clear the SMI status registers, or we won't see what's
644 * happening in the following calls.
645 */
646 smi_sts = reset_smi_status();
647
648 /* Filter all non-enabled SMI events */
649 // FIXME Double check, this clears MONITOR
650 // smi_sts &= inl(pmbase + SMI_EN);
651
652 /* Call SMI sub handler for each of the status bits */
653 for (i = 0; i < 31; i++) {
654 if (smi_sts & (1 << i)) {
655 if (southbridge_smi[i])
656 southbridge_smi[i](node, state_save);
657 else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000658 printk(BIOS_DEBUG, "SMI_STS[%d] occured, but no "
Stefan Reinauer800379f2010-03-01 08:34:19 +0000659 "handler available.\n", i);
660 dump = 1;
661 }
662 }
663 }
664
665 if(dump) {
666 dump_smi_status(smi_sts);
667 }
668
669}