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