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