Add support for Intel Panther Point PCH
[coreboot.git] / src / southbridge / intel / bd82x6x / 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/hlt.h>
24 #include <arch/io.h>
25 #include <arch/romcc_io.h>
26 #include <console/console.h>
27 #include <cpu/x86/cache.h>
28 #include <cpu/x86/smm.h>
29 #include <device/pci_def.h>
30 #include <cpu/x86/smm.h>
31 #include "pch.h"
32
33 #include "nvs.h"
34
35 /* While we read PMBASE dynamically in case it changed, let's
36  * initialize it with a sane value
37  */
38 u16 pmbase = DEFAULT_PMBASE;
39 u8 smm_initialized = 0;
40
41 /* GNVS needs to be updated by an 0xEA PM Trap (B2) after it has been located
42  * by coreboot.
43  */
44 global_nvs_t *gnvs = (global_nvs_t *)0x0;
45 void *tcg = (void *)0x0;
46 void *smi1 = (void *)0x0;
47
48 #if CONFIG_SMM_TSEG
49 static u32 tseg_base = 0;
50 static inline void tseg_fixup(void **ptr)
51 {
52         /* Adjust pointer with TSEG base */
53         if (*ptr)
54                 *ptr = (void *)(((u8*)*ptr) + tseg_base);
55 }
56 #else
57 #define tseg_fixup(x) do {} while(0)
58 #endif
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 << 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");
129 }
130
131
132 /**
133  * @brief read and clear GPE0_STS
134  * @return GPE0_STS register
135  */
136 static 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
147 static void dump_gpe0_status(u32 gpe0_sts)
148 {
149         int i;
150         printk(BIOS_DEBUG, "GPE0_STS: ");
151         for (i=31; i<= 16; i--) {
152                 if (gpe0_sts & (1 << i)) printk(BIOS_DEBUG, "GPIO%d ", (i-16));
153         }
154         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, "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, "SWGPE ");
167         if (gpe0_sts & (1 <<  1)) printk(BIOS_DEBUG, "HOTPLUG ");
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/sandybridge/sandybridge.h>
216 #include <northbridge/intel/sandybridge/pcie_config.c>
217
218 int southbridge_io_trap_handler(int smif)
219 {
220         switch (smif) {
221         case 0x32:
222                 printk(BIOS_DEBUG, "OS Init\n");
223                 /* gnvs->smif:
224                  *  On success, the IO Trap Handler returns 0
225                  *  On failure, the IO Trap Handler returns a value != 0
226                  */
227                 gnvs->smif = 0;
228                 return 1; /* IO trap handled */
229         }
230
231         /* Not handled */
232         return 0;
233 }
234
235 /**
236  * @brief Set the EOS bit
237  */
238 void southbridge_smi_set_eos(void)
239 {
240         u8 reg8;
241
242         reg8 = inb(pmbase + SMI_EN);
243         reg8 |= EOS;
244         outb(reg8, pmbase + SMI_EN);
245 }
246
247 static void busmaster_disable_on_bus(int bus)
248 {
249         int slot, func;
250         unsigned int val;
251         unsigned char hdr;
252
253         for (slot = 0; slot < 0x20; slot++) {
254                 for (func = 0; func < 8; func++) {
255                         u32 reg32;
256                         device_t dev = PCI_DEV(bus, slot, func);
257
258                         val = pci_read_config32(dev, PCI_VENDOR_ID);
259
260                         if (val == 0xffffffff || val == 0x00000000 ||
261                             val == 0x0000ffff || val == 0xffff0000)
262                                 continue;
263
264                         /* Disable Bus Mastering for this one device */
265                         reg32 = pci_read_config32(dev, PCI_COMMAND);
266                         reg32 &= ~PCI_COMMAND_MASTER;
267                         pci_write_config32(dev, PCI_COMMAND, reg32);
268
269                         /* If this is a bridge, then follow it. */
270                         hdr = pci_read_config8(dev, PCI_HEADER_TYPE);
271                         hdr &= 0x7f;
272                         if (hdr == PCI_HEADER_TYPE_BRIDGE ||
273                             hdr == PCI_HEADER_TYPE_CARDBUS) {
274                                 unsigned int buses;
275                                 buses = pci_read_config32(dev, PCI_PRIMARY_BUS);
276                                 busmaster_disable_on_bus((buses >> 8) & 0xff);
277                         }
278                 }
279         }
280 }
281
282 /*
283  * Drive GPIO 60 low to gate memory reset in S3.
284  *
285  * Intel reference designs all use GPIO 60 but it is
286  * not a requirement and boards could use a different pin.
287  */
288 static void southbridge_gate_memory_reset(void)
289 {
290         u32 reg32;
291         u16 gpiobase;
292
293         gpiobase = pcie_read_config16(PCI_DEV(0, 0x1f, 0), GPIOBASE) & 0xfffc;
294         if (!gpiobase)
295                 return;
296
297         /* Make sure it is set as GPIO */
298         reg32 = inl(gpiobase + GPIO_USE_SEL2);
299         if (!(reg32 & (1 << 28))) {
300                 reg32 |= (1 << 28);
301                 outl(reg32, gpiobase + GPIO_USE_SEL2);
302         }
303
304         /* Make sure it is set as output */
305         reg32 = inl(gpiobase + GP_IO_SEL2);
306         if (reg32 & (1 << 28)) {
307                 reg32 &= ~(1 << 28);
308                 outl(reg32, gpiobase + GP_IO_SEL2);
309         }
310
311         /* Drive the output low */
312         reg32 = inl(gpiobase + GP_LVL2);
313         reg32 &= ~(1 << 28);
314         outl(reg32, gpiobase + GP_LVL2);
315 }
316
317 static void southbridge_smi_sleep(unsigned int node, smm_state_save_area_t *state_save)
318 {
319         u8 reg8;
320         u32 reg32;
321         u8 slp_typ;
322         /* FIXME: the power state on boot should be read from
323          * CMOS or even better from GNVS. Right now it's hard
324          * coded at compile time.
325          */
326         u8 s5pwr = CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL;
327         void (*mainboard_sleep)(u8 slp_typ) = mainboard_smi_sleep;
328
329         /* First, disable further SMIs */
330         reg8 = inb(pmbase + SMI_EN);
331         reg8 &= ~SLP_SMI_EN;
332         outb(reg8, pmbase + SMI_EN);
333
334         /* Figure out SLP_TYP */
335         reg32 = inl(pmbase + PM1_CNT);
336         printk(BIOS_SPEW, "SMI#: SLP = 0x%08x\n", reg32);
337         slp_typ = (reg32 >> 10) & 7;
338
339         /* Do any mainboard sleep handling */
340         tseg_fixup((void **)&mainboard_sleep);
341         if (mainboard_sleep)
342                 mainboard_sleep(slp_typ);
343
344         /* Next, do the deed.
345          */
346
347         switch (slp_typ) {
348         case 0: printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n"); break;
349         case 1: printk(BIOS_DEBUG, "SMI#: Entering S1 (Assert STPCLK#)\n"); break;
350         case 5:
351                 printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n");
352
353                 /* Gate memory reset */
354                 southbridge_gate_memory_reset();
355
356                 /* Invalidate the cache before going to S3 */
357                 wbinvd();
358                 break;
359         case 6: printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n"); break;
360         case 7:
361                 printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n");
362
363                 outl(0, pmbase + GPE0_EN);
364
365                 /* Should we keep the power state after a power loss?
366                  * In case the setting is "ON" or "OFF" we don't have
367                  * to do anything. But if it's "KEEP" we have to switch
368                  * to "OFF" before entering S5.
369                  */
370                 if (s5pwr == MAINBOARD_POWER_KEEP) {
371                         reg8 = pcie_read_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3);
372                         reg8 |= 1;
373                         pcie_write_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3, reg8);
374                 }
375
376                 /* also iterates over all bridges on bus 0 */
377                 busmaster_disable_on_bus(0);
378                 break;
379         default: printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n"); break;
380         }
381
382         /* Write back to the SLP register to cause the originally intended
383          * event again. We need to set BIT13 (SLP_EN) though to make the
384          * sleep happen.
385          */
386         outl(reg32 | SLP_EN, pmbase + PM1_CNT);
387
388         /* Make sure to stop executing code here for S3/S4/S5 */
389         if (slp_typ > 1)
390                 hlt();
391
392         /* In most sleep states, the code flow of this function ends at
393          * the line above. However, if we entered sleep state S1 and wake
394          * up again, we will continue to execute code in this function.
395          */
396         reg32 = inl(pmbase + PM1_CNT);
397         if (reg32 & SCI_EN) {
398                 /* The OS is not an ACPI OS, so we set the state to S0 */
399                 reg32 &= ~(SLP_EN | SLP_TYP);
400                 outl(reg32, pmbase + PM1_CNT);
401         }
402 }
403
404 static void southbridge_smi_apmc(unsigned int node, smm_state_save_area_t *state_save)
405 {
406         u32 pmctrl;
407         u8 reg8;
408         void (*mainboard_apmc)(u8 apmc) = mainboard_smi_apmc;
409
410         /* Emulate B2 register as the FADT / Linux expects it */
411
412         reg8 = inb(APM_CNT);
413         switch (reg8) {
414         case APM_CNT_CST_CONTROL:
415                 /* Calling this function seems to cause
416                  * some kind of race condition in Linux
417                  * and causes a kernel oops
418                  */
419                 printk(BIOS_DEBUG, "C-state control\n");
420                 break;
421         case APM_CNT_PST_CONTROL:
422                 /* Calling this function seems to cause
423                  * some kind of race condition in Linux
424                  * and causes a kernel oops
425                  */
426                 printk(BIOS_DEBUG, "P-state control\n");
427                 break;
428         case APM_CNT_ACPI_DISABLE:
429                 pmctrl = inl(pmbase + PM1_CNT);
430                 pmctrl &= ~SCI_EN;
431                 outl(pmctrl, pmbase + PM1_CNT);
432                 printk(BIOS_DEBUG, "SMI#: ACPI disabled.\n");
433                 break;
434         case APM_CNT_ACPI_ENABLE:
435                 pmctrl = inl(pmbase + PM1_CNT);
436                 pmctrl |= SCI_EN;
437                 outl(pmctrl, pmbase + PM1_CNT);
438                 printk(BIOS_DEBUG, "SMI#: ACPI enabled.\n");
439                 break;
440         case APM_CNT_GNVS_UPDATE:
441                 if (smm_initialized) {
442                         printk(BIOS_DEBUG, "SMI#: SMM structures already initialized!\n");
443                         return;
444                 }
445                 gnvs = *(global_nvs_t **)0x500;
446                 tcg  = *(void **)0x504;
447                 smi1 = *(void **)0x508;
448                 smm_initialized = 1;
449                 printk(BIOS_DEBUG, "SMI#: Setting up structures to %p, %p, %p\n", gnvs, tcg, smi1);
450                 break;
451         }
452
453         tseg_fixup((void **)&mainboard_apmc);
454         if (mainboard_apmc)
455                 mainboard_apmc(reg8);
456 }
457
458 static void southbridge_smi_pm1(unsigned int node, smm_state_save_area_t *state_save)
459 {
460         u16 pm1_sts;
461
462         pm1_sts = reset_pm1_status();
463         dump_pm1_status(pm1_sts);
464
465         /* While OSPM is not active, poweroff immediately
466          * on a power button event.
467          */
468         if (pm1_sts & PWRBTN_STS) {
469                 // power button pressed
470                 u32 reg32;
471                 reg32 = (7 << 10) | (1 << 13);
472                 outl(reg32, pmbase + PM1_CNT);
473         }
474 }
475
476 static void southbridge_smi_gpe0(unsigned int node, smm_state_save_area_t *state_save)
477 {
478         u32 gpe0_sts;
479
480         gpe0_sts = reset_gpe0_status();
481         dump_gpe0_status(gpe0_sts);
482 }
483
484 static void southbridge_smi_gpi(unsigned int node, smm_state_save_area_t *state_save)
485 {
486         void (*mainboard_gpi)(u16 gpi_sts) = mainboard_smi_gpi;
487         u16 reg16;
488         reg16 = inw(pmbase + ALT_GP_SMI_STS);
489         outw(reg16, pmbase + ALT_GP_SMI_STS);
490
491         reg16 &= inw(pmbase + ALT_GP_SMI_EN);
492
493         tseg_fixup((void **)&mainboard_gpi);
494         if (mainboard_gpi) {
495                 mainboard_gpi(reg16);
496         } else {
497                 if (reg16)
498                         printk(BIOS_DEBUG, "GPI (mask %04x)\n",reg16);
499         }
500
501         outw(reg16, pmbase + ALT_GP_SMI_STS);
502 }
503
504 static void southbridge_smi_mc(unsigned int node, smm_state_save_area_t *state_save)
505 {
506         u32 reg32;
507
508         reg32 = inl(pmbase + SMI_EN);
509
510         /* Are periodic SMIs enabled? */
511         if ((reg32 & MCSMI_EN) == 0)
512                 return;
513
514         printk(BIOS_DEBUG, "Microcontroller SMI.\n");
515 }
516
517
518
519 static void southbridge_smi_tco(unsigned int node, smm_state_save_area_t *state_save)
520 {
521         u32 tco_sts;
522
523         tco_sts = reset_tco_status();
524
525         /* Any TCO event? */
526         if (!tco_sts)
527                 return;
528
529         if (tco_sts & (1 << 8)) { // BIOSWR
530                 u8 bios_cntl;
531
532                 bios_cntl = pcie_read_config16(PCI_DEV(0, 0x1f, 0), 0xdc);
533
534                 if (bios_cntl & 1) {
535                         /* BWE is RW, so the SMI was caused by a
536                          * write to BWE, not by a write to the BIOS
537                          */
538
539                         /* This is the place where we notice someone
540                          * is trying to tinker with the BIOS. We are
541                          * trying to be nice and just ignore it. A more
542                          * resolute answer would be to power down the
543                          * box.
544                          */
545                         printk(BIOS_DEBUG, "Switching back to RO\n");
546                         pcie_write_config32(PCI_DEV(0, 0x1f, 0), 0xdc, (bios_cntl & ~1));
547                 } /* No else for now? */
548         } else if (tco_sts & (1 << 3)) { /* TIMEOUT */
549                 /* Handle TCO timeout */
550                 printk(BIOS_DEBUG, "TCO Timeout.\n");
551         } else if (!tco_sts) {
552                 dump_tco_status(tco_sts);
553         }
554 }
555
556 static void southbridge_smi_periodic(unsigned int node, smm_state_save_area_t *state_save)
557 {
558         u32 reg32;
559
560         reg32 = inl(pmbase + SMI_EN);
561
562         /* Are periodic SMIs enabled? */
563         if ((reg32 & PERIODIC_EN) == 0)
564                 return;
565
566         printk(BIOS_DEBUG, "Periodic SMI.\n");
567 }
568
569 static void southbridge_smi_monitor(unsigned int node, smm_state_save_area_t *state_save)
570 {
571 #define IOTRAP(x) (trap_sts & (1 << x))
572         u32 trap_sts, trap_cycle;
573         u32 data, mask = 0;
574         int i;
575
576         trap_sts = RCBA32(0x1e00); // TRSR - Trap Status Register
577         RCBA32(0x1e00) = trap_sts; // Clear trap(s) in TRSR
578
579         trap_cycle = RCBA32(0x1e10);
580         for (i=16; i<20; i++) {
581                 if (trap_cycle & (1 << i))
582                         mask |= (0xff << ((i - 16) << 2));
583         }
584
585
586         /* IOTRAP(3) SMI function call */
587         if (IOTRAP(3)) {
588                 if (gnvs && gnvs->smif)
589                         io_trap_handler(gnvs->smif); // call function smif
590                 return;
591         }
592
593         /* IOTRAP(2) currently unused
594          * IOTRAP(1) currently unused */
595
596         /* IOTRAP(0) SMIC */
597         if (IOTRAP(0)) {
598                 if (!(trap_cycle & (1 << 24))) { // It's a write
599                         printk(BIOS_DEBUG, "SMI1 command\n");
600                         data = RCBA32(0x1e18);
601                         data &= mask;
602                         // if (smi1)
603                         //      southbridge_smi_command(data);
604                         // return;
605                 }
606                 // Fall through to debug
607         }
608
609         printk(BIOS_DEBUG, "  trapped io address = 0x%x\n", trap_cycle & 0xfffc);
610         for (i=0; i < 4; i++) if(IOTRAP(i)) printk(BIOS_DEBUG, "  TRAPĀ = %d\n", i);
611         printk(BIOS_DEBUG, "  AHBE = %x\n", (trap_cycle >> 16) & 0xf);
612         printk(BIOS_DEBUG, "  MASK = 0x%08x\n", mask);
613         printk(BIOS_DEBUG, "  read/write: %s\n", (trap_cycle & (1 << 24)) ? "read" : "write");
614
615         if (!(trap_cycle & (1 << 24))) {
616                 /* Write Cycle */
617                 data = RCBA32(0x1e18);
618                 printk(BIOS_DEBUG, "  iotrap written data = 0x%08x\n", data);
619         }
620 #undef IOTRAP
621 }
622
623 typedef void (*smi_handler_t)(unsigned int node,
624                 smm_state_save_area_t *state_save);
625
626 static smi_handler_t southbridge_smi[32] = {
627         NULL,                     //  [0] reserved
628         NULL,                     //  [1] reserved
629         NULL,                     //  [2] BIOS_STS
630         NULL,                     //  [3] LEGACY_USB_STS
631         southbridge_smi_sleep,    //  [4] SLP_SMI_STS
632         southbridge_smi_apmc,     //  [5] APM_STS
633         NULL,                     //  [6] SWSMI_TMR_STS
634         NULL,                     //  [7] reserved
635         southbridge_smi_pm1,      //  [8] PM1_STS
636         southbridge_smi_gpe0,     //  [9] GPE0_STS
637         southbridge_smi_gpi,      // [10] GPI_STS
638         southbridge_smi_mc,       // [11] MCSMI_STS
639         NULL,                     // [12] DEVMON_STS
640         southbridge_smi_tco,      // [13] TCO_STS
641         southbridge_smi_periodic, // [14] PERIODIC_STS
642         NULL,                     // [15] SERIRQ_SMI_STS
643         NULL,                     // [16] SMBUS_SMI_STS
644         NULL,                     // [17] LEGACY_USB2_STS
645         NULL,                     // [18] INTEL_USB2_STS
646         NULL,                     // [19] reserved
647         NULL,                     // [20] PCI_EXP_SMI_STS
648         southbridge_smi_monitor,  // [21] MONITOR_STS
649         NULL,                     // [22] reserved
650         NULL,                     // [23] reserved
651         NULL,                     // [24] reserved
652         NULL,                     // [25] EL_SMI_STS
653         NULL,                     // [26] SPI_STS
654         NULL,                     // [27] reserved
655         NULL,                     // [28] reserved
656         NULL,                     // [29] reserved
657         NULL,                     // [30] reserved
658         NULL                      // [31] reserved
659 };
660
661 /**
662  * @brief Interrupt handler for SMI#
663  *
664  * @param smm_revision revision of the smm state save map
665  */
666
667 void southbridge_smi_handler(unsigned int node, smm_state_save_area_t *state_save)
668 {
669         int i, dump = 0;
670         u32 smi_sts;
671
672         /* Update global variable pmbase */
673         pmbase = pcie_read_config16(PCI_DEV(0, 0x1f, 0), 0x40) & 0xfffc;
674
675 #if CONFIG_SMM_TSEG
676         /* Update global variable TSEG base */
677         tseg_base = pcie_read_config32(PCI_DEV(0, 0, 0), TSEG) & ~1;
678 #endif
679
680         /* We need to clear the SMI status registers, or we won't see what's
681          * happening in the following calls.
682          */
683         smi_sts = reset_smi_status();
684
685         /* Call SMI sub handler for each of the status bits */
686         for (i = 0; i < 31; i++) {
687                 if (smi_sts & (1 << i)) {
688                         if (southbridge_smi[i]) {
689 #if CONFIG_SMM_TSEG
690                                 smi_handler_t handler = (smi_handler_t)
691                                         ((u8*)southbridge_smi[i] + tseg_base);
692                                 if (handler)
693                                         handler(node, state_save);
694 #else
695                                 southbridge_smi[i](node, state_save);
696 #endif
697                         } else {
698                                 printk(BIOS_DEBUG, "SMI_STS[%d] occured, but no "
699                                                 "handler available.\n", i);
700                                 dump = 1;
701                         }
702                 }
703         }
704
705         if(dump) {
706                 dump_smi_status(smi_sts);
707         }
708
709 }