blob: 48dca2c8fd0a7b23254934ca737ecf1607429947 [file] [log] [blame]
Aaron Durbin76c37002012-10-30 09:03:43 -05001/*
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 <device/pci_def.h>
29#include <cpu/x86/smm.h>
30#include <elog.h>
31#include <pc80/mc146818rtc.h>
32#include "pch.h"
33
34#include "nvs.h"
35
Aaron Durbin76c37002012-10-30 09:03:43 -050036/* While we read PMBASE dynamically in case it changed, let's
37 * initialize it with a sane value
38 */
39static u16 pmbase = DEFAULT_PMBASE;
40u16 smm_get_pmbase(void)
41{
42 return pmbase;
43}
44
45static u8 smm_initialized = 0;
46
47/* GNVS needs to be updated by an 0xEA PM Trap (B2) after it has been located
48 * by coreboot.
49 */
Aaron Durbin29ffa542012-12-21 21:21:48 -060050static global_nvs_t *gnvs;
Aaron Durbin76c37002012-10-30 09:03:43 -050051global_nvs_t *smm_get_gnvs(void)
52{
53 return gnvs;
54}
55
Aaron Durbin76c37002012-10-30 09:03:43 -050056/**
57 * @brief read and clear PM1_STS
58 * @return PM1_STS register
59 */
60static u16 reset_pm1_status(void)
61{
62 u16 reg16;
63
64 reg16 = inw(pmbase + PM1_STS);
65 /* set status bits are cleared by writing 1 to them */
66 outw(reg16, pmbase + PM1_STS);
67
68 return reg16;
69}
70
71static void dump_pm1_status(u16 pm1_sts)
72{
73 printk(BIOS_SPEW, "PM1_STS: ");
74 if (pm1_sts & (1 << 15)) printk(BIOS_SPEW, "WAK ");
75 if (pm1_sts & (1 << 14)) printk(BIOS_SPEW, "PCIEXPWAK ");
76 if (pm1_sts & (1 << 11)) printk(BIOS_SPEW, "PRBTNOR ");
77 if (pm1_sts & (1 << 10)) printk(BIOS_SPEW, "RTC ");
78 if (pm1_sts & (1 << 8)) printk(BIOS_SPEW, "PWRBTN ");
79 if (pm1_sts & (1 << 5)) printk(BIOS_SPEW, "GBL ");
80 if (pm1_sts & (1 << 4)) printk(BIOS_SPEW, "BM ");
81 if (pm1_sts & (1 << 0)) printk(BIOS_SPEW, "TMROF ");
82 printk(BIOS_SPEW, "\n");
83 int reg16 = inw(pmbase + PM1_EN);
84 printk(BIOS_SPEW, "PM1_EN: %x\n", reg16);
85}
86
87/**
88 * @brief read and clear SMI_STS
89 * @return SMI_STS register
90 */
91static u32 reset_smi_status(void)
92{
93 u32 reg32;
94
95 reg32 = inl(pmbase + SMI_STS);
96 /* set status bits are cleared by writing 1 to them */
97 outl(reg32, pmbase + SMI_STS);
98
99 return reg32;
100}
101
102static void dump_smi_status(u32 smi_sts)
103{
104 printk(BIOS_DEBUG, "SMI_STS: ");
105 if (smi_sts & (1 << 26)) printk(BIOS_DEBUG, "SPI ");
106 if (smi_sts & (1 << 21)) printk(BIOS_DEBUG, "MONITOR ");
107 if (smi_sts & (1 << 20)) printk(BIOS_DEBUG, "PCI_EXP_SMI ");
108 if (smi_sts & (1 << 18)) printk(BIOS_DEBUG, "INTEL_USB2 ");
109 if (smi_sts & (1 << 17)) printk(BIOS_DEBUG, "LEGACY_USB2 ");
110 if (smi_sts & (1 << 16)) printk(BIOS_DEBUG, "SMBUS_SMI ");
111 if (smi_sts & (1 << 15)) printk(BIOS_DEBUG, "SERIRQ_SMI ");
112 if (smi_sts & (1 << 14)) printk(BIOS_DEBUG, "PERIODIC ");
113 if (smi_sts & (1 << 13)) printk(BIOS_DEBUG, "TCO ");
114 if (smi_sts & (1 << 12)) printk(BIOS_DEBUG, "DEVMON ");
115 if (smi_sts & (1 << 11)) printk(BIOS_DEBUG, "MCSMI ");
116 if (smi_sts & (1 << 10)) printk(BIOS_DEBUG, "GPI ");
117 if (smi_sts & (1 << 9)) printk(BIOS_DEBUG, "GPE0 ");
118 if (smi_sts & (1 << 8)) printk(BIOS_DEBUG, "PM1 ");
119 if (smi_sts & (1 << 6)) printk(BIOS_DEBUG, "SWSMI_TMR ");
120 if (smi_sts & (1 << 5)) printk(BIOS_DEBUG, "APM ");
121 if (smi_sts & (1 << 4)) printk(BIOS_DEBUG, "SLP_SMI ");
122 if (smi_sts & (1 << 3)) printk(BIOS_DEBUG, "LEGACY_USB ");
123 if (smi_sts & (1 << 2)) printk(BIOS_DEBUG, "BIOS ");
124 printk(BIOS_DEBUG, "\n");
125}
126
127
128/**
129 * @brief read and clear GPE0_STS
130 * @return GPE0_STS register
131 */
132static u32 reset_gpe0_status(void)
133{
134 u32 reg32;
135
136 reg32 = inl(pmbase + GPE0_STS);
137 /* set status bits are cleared by writing 1 to them */
138 outl(reg32, pmbase + GPE0_STS);
139
140 return reg32;
141}
142
143static void dump_gpe0_status(u32 gpe0_sts)
144{
145 int i;
146 printk(BIOS_DEBUG, "GPE0_STS: ");
147 for (i=31; i<= 16; i--) {
148 if (gpe0_sts & (1 << i)) printk(BIOS_DEBUG, "GPIO%d ", (i-16));
149 }
150 if (gpe0_sts & (1 << 14)) printk(BIOS_DEBUG, "USB4 ");
151 if (gpe0_sts & (1 << 13)) printk(BIOS_DEBUG, "PME_B0 ");
152 if (gpe0_sts & (1 << 12)) printk(BIOS_DEBUG, "USB3 ");
153 if (gpe0_sts & (1 << 11)) printk(BIOS_DEBUG, "PME ");
154 if (gpe0_sts & (1 << 10)) printk(BIOS_DEBUG, "BATLOW ");
155 if (gpe0_sts & (1 << 9)) printk(BIOS_DEBUG, "PCI_EXP ");
156 if (gpe0_sts & (1 << 8)) printk(BIOS_DEBUG, "RI ");
157 if (gpe0_sts & (1 << 7)) printk(BIOS_DEBUG, "SMB_WAK ");
158 if (gpe0_sts & (1 << 6)) printk(BIOS_DEBUG, "TCO_SCI ");
159 if (gpe0_sts & (1 << 5)) printk(BIOS_DEBUG, "AC97 ");
160 if (gpe0_sts & (1 << 4)) printk(BIOS_DEBUG, "USB2 ");
161 if (gpe0_sts & (1 << 3)) printk(BIOS_DEBUG, "USB1 ");
162 if (gpe0_sts & (1 << 2)) printk(BIOS_DEBUG, "SWGPE ");
163 if (gpe0_sts & (1 << 1)) printk(BIOS_DEBUG, "HOTPLUG ");
164 if (gpe0_sts & (1 << 0)) printk(BIOS_DEBUG, "THRM ");
165 printk(BIOS_DEBUG, "\n");
166}
167
168
169/**
170 * @brief read and clear TCOx_STS
171 * @return TCOx_STS registers
172 */
173static u32 reset_tco_status(void)
174{
175 u32 tcobase = pmbase + 0x60;
176 u32 reg32;
177
178 reg32 = inl(tcobase + 0x04);
179 /* set status bits are cleared by writing 1 to them */
180 outl(reg32 & ~(1<<18), tcobase + 0x04); // Don't clear BOOT_STS before SECOND_TO_STS
181 if (reg32 & (1 << 18))
182 outl(reg32 & (1<<18), tcobase + 0x04); // clear BOOT_STS
183
184 return reg32;
185}
186
187
188static void dump_tco_status(u32 tco_sts)
189{
190 printk(BIOS_DEBUG, "TCO_STS: ");
191 if (tco_sts & (1 << 20)) printk(BIOS_DEBUG, "SMLINK_SLV ");
192 if (tco_sts & (1 << 18)) printk(BIOS_DEBUG, "BOOT ");
193 if (tco_sts & (1 << 17)) printk(BIOS_DEBUG, "SECOND_TO ");
194 if (tco_sts & (1 << 16)) printk(BIOS_DEBUG, "INTRD_DET ");
195 if (tco_sts & (1 << 12)) printk(BIOS_DEBUG, "DMISERR ");
196 if (tco_sts & (1 << 10)) printk(BIOS_DEBUG, "DMISMI ");
197 if (tco_sts & (1 << 9)) printk(BIOS_DEBUG, "DMISCI ");
198 if (tco_sts & (1 << 8)) printk(BIOS_DEBUG, "BIOSWR ");
199 if (tco_sts & (1 << 7)) printk(BIOS_DEBUG, "NEWCENTURY ");
200 if (tco_sts & (1 << 3)) printk(BIOS_DEBUG, "TIMEOUT ");
201 if (tco_sts & (1 << 2)) printk(BIOS_DEBUG, "TCO_INT ");
202 if (tco_sts & (1 << 1)) printk(BIOS_DEBUG, "SW_TCO ");
203 if (tco_sts & (1 << 0)) printk(BIOS_DEBUG, "NMI2SMI ");
204 printk(BIOS_DEBUG, "\n");
205}
206
207int southbridge_io_trap_handler(int smif)
208{
209 switch (smif) {
210 case 0x32:
211 printk(BIOS_DEBUG, "OS Init\n");
212 /* gnvs->smif:
213 * On success, the IO Trap Handler returns 0
214 * On failure, the IO Trap Handler returns a value != 0
215 */
216 gnvs->smif = 0;
217 return 1; /* IO trap handled */
218 }
219
220 /* Not handled */
221 return 0;
222}
223
224/**
225 * @brief Set the EOS bit
226 */
227void southbridge_smi_set_eos(void)
228{
229 u8 reg8;
230
231 reg8 = inb(pmbase + SMI_EN);
232 reg8 |= EOS;
233 outb(reg8, pmbase + SMI_EN);
234}
235
236static void busmaster_disable_on_bus(int bus)
237{
238 int slot, func;
239 unsigned int val;
240 unsigned char hdr;
241
242 for (slot = 0; slot < 0x20; slot++) {
243 for (func = 0; func < 8; func++) {
244 u32 reg32;
245 device_t dev = PCI_DEV(bus, slot, func);
246
247 val = pci_read_config32(dev, PCI_VENDOR_ID);
248
249 if (val == 0xffffffff || val == 0x00000000 ||
250 val == 0x0000ffff || val == 0xffff0000)
251 continue;
252
253 /* Disable Bus Mastering for this one device */
254 reg32 = pci_read_config32(dev, PCI_COMMAND);
255 reg32 &= ~PCI_COMMAND_MASTER;
256 pci_write_config32(dev, PCI_COMMAND, reg32);
257
258 /* If this is a bridge, then follow it. */
259 hdr = pci_read_config8(dev, PCI_HEADER_TYPE);
260 hdr &= 0x7f;
261 if (hdr == PCI_HEADER_TYPE_BRIDGE ||
262 hdr == PCI_HEADER_TYPE_CARDBUS) {
263 unsigned int buses;
264 buses = pci_read_config32(dev, PCI_PRIMARY_BUS);
265 busmaster_disable_on_bus((buses >> 8) & 0xff);
266 }
267 }
268 }
269}
270
Aaron Durbin29ffa542012-12-21 21:21:48 -0600271static void southbridge_smi_sleep(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500272{
273 u8 reg8;
274 u32 reg32;
275 u8 slp_typ;
276 u8 s5pwr = CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL;
277
278 // save and recover RTC port values
279 u8 tmp70, tmp72;
280 tmp70 = inb(0x70);
281 tmp72 = inb(0x72);
282 get_option(&s5pwr, "power_on_after_fail");
283 outb(tmp70, 0x70);
284 outb(tmp72, 0x72);
285
Aaron Durbin76c37002012-10-30 09:03:43 -0500286 /* First, disable further SMIs */
287 reg8 = inb(pmbase + SMI_EN);
288 reg8 &= ~SLP_SMI_EN;
289 outb(reg8, pmbase + SMI_EN);
290
291 /* Figure out SLP_TYP */
292 reg32 = inl(pmbase + PM1_CNT);
293 printk(BIOS_SPEW, "SMI#: SLP = 0x%08x\n", reg32);
294 slp_typ = (reg32 >> 10) & 7;
295
296 /* Do any mainboard sleep handling */
Aaron Durbin29ffa542012-12-21 21:21:48 -0600297 mainboard_smi_sleep(slp_typ-2);
Aaron Durbin76c37002012-10-30 09:03:43 -0500298
299#if CONFIG_ELOG_GSMI
300 /* Log S3, S4, and S5 entry */
301 if (slp_typ >= 5)
302 elog_add_event_byte(ELOG_TYPE_ACPI_ENTER, slp_typ-2);
303#endif
304
305 /* Next, do the deed.
306 */
307
308 switch (slp_typ) {
309 case 0: printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n"); break;
310 case 1: printk(BIOS_DEBUG, "SMI#: Entering S1 (Assert STPCLK#)\n"); break;
311 case 5:
312 printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n");
313
Aaron Durbin76c37002012-10-30 09:03:43 -0500314 /* Invalidate the cache before going to S3 */
315 wbinvd();
316 break;
317 case 6: printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n"); break;
318 case 7:
319 printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n");
320
321 outl(0, pmbase + GPE0_EN);
322
323 /* Always set the flag in case CMOS was changed on runtime. For
324 * "KEEP", switch to "OFF" - KEEP is software emulated
325 */
Aaron Durbin89f79a02012-10-31 23:05:25 -0500326 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3);
Aaron Durbin76c37002012-10-30 09:03:43 -0500327 if (s5pwr == MAINBOARD_POWER_ON) {
328 reg8 &= ~1;
329 } else {
330 reg8 |= 1;
331 }
Aaron Durbin89f79a02012-10-31 23:05:25 -0500332 pci_write_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3, reg8);
Aaron Durbin76c37002012-10-30 09:03:43 -0500333
334 /* also iterates over all bridges on bus 0 */
335 busmaster_disable_on_bus(0);
336 break;
337 default: printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n"); break;
338 }
339
340 /* Write back to the SLP register to cause the originally intended
341 * event again. We need to set BIT13 (SLP_EN) though to make the
342 * sleep happen.
343 */
344 outl(reg32 | SLP_EN, pmbase + PM1_CNT);
345
346 /* Make sure to stop executing code here for S3/S4/S5 */
347 if (slp_typ > 1)
348 hlt();
349
350 /* In most sleep states, the code flow of this function ends at
351 * the line above. However, if we entered sleep state S1 and wake
352 * up again, we will continue to execute code in this function.
353 */
354 reg32 = inl(pmbase + PM1_CNT);
355 if (reg32 & SCI_EN) {
356 /* The OS is not an ACPI OS, so we set the state to S0 */
357 reg32 &= ~(SLP_EN | SLP_TYP);
358 outl(reg32, pmbase + PM1_CNT);
359 }
360}
361
362/*
363 * Look for Synchronous IO SMI and use save state from that
364 * core in case we are not running on the same core that
365 * initiated the IO transaction.
366 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500367static em64t101_smm_state_save_area_t *smi_apmc_find_state_save(u8 cmd)
368{
369 em64t101_smm_state_save_area_t *state;
Aaron Durbin76c37002012-10-30 09:03:43 -0500370 int node;
371
372 /* Check all nodes looking for the one that issued the IO */
373 for (node = 0; node < CONFIG_MAX_CPUS; node++) {
Aaron Durbin29ffa542012-12-21 21:21:48 -0600374 state = smm_get_save_state(node);
Aaron Durbin76c37002012-10-30 09:03:43 -0500375
376 /* Check for Synchronous IO (bit0==1) */
377 if (!(state->io_misc_info & (1 << 0)))
378 continue;
379
380 /* Make sure it was a write (bit4==0) */
381 if (state->io_misc_info & (1 << 4))
382 continue;
383
384 /* Check for APMC IO port */
385 if (((state->io_misc_info >> 16) & 0xff) != APM_CNT)
386 continue;
387
388 /* Check AX against the requested command */
389 if ((state->rax & 0xff) != cmd)
390 continue;
391
392 return state;
393 }
394
395 return NULL;
396}
397
398#if CONFIG_ELOG_GSMI
399static void southbridge_smi_gsmi(void)
400{
401 u32 *ret, *param;
402 u8 sub_command;
403 em64t101_smm_state_save_area_t *io_smi =
404 smi_apmc_find_state_save(ELOG_GSMI_APM_CNT);
405
406 if (!io_smi)
407 return;
408
409 /* Command and return value in EAX */
410 ret = (u32*)&io_smi->rax;
411 sub_command = (u8)(*ret >> 8);
412
413 /* Parameter buffer in EBX */
414 param = (u32*)&io_smi->rbx;
415
416 /* drivers/elog/gsmi.c */
417 *ret = gsmi_exec(sub_command, param);
418}
419#endif
420
Aaron Durbin29ffa542012-12-21 21:21:48 -0600421static void southbridge_smi_apmc(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500422{
423 u32 pmctrl;
424 u8 reg8;
Aaron Durbin76c37002012-10-30 09:03:43 -0500425 em64t101_smm_state_save_area_t *state;
426
427 /* Emulate B2 register as the FADT / Linux expects it */
428
429 reg8 = inb(APM_CNT);
430 switch (reg8) {
431 case APM_CNT_CST_CONTROL:
432 /* Calling this function seems to cause
433 * some kind of race condition in Linux
434 * and causes a kernel oops
435 */
436 printk(BIOS_DEBUG, "C-state control\n");
437 break;
438 case APM_CNT_PST_CONTROL:
439 /* Calling this function seems to cause
440 * some kind of race condition in Linux
441 * and causes a kernel oops
442 */
443 printk(BIOS_DEBUG, "P-state control\n");
444 break;
445 case APM_CNT_ACPI_DISABLE:
446 pmctrl = inl(pmbase + PM1_CNT);
447 pmctrl &= ~SCI_EN;
448 outl(pmctrl, pmbase + PM1_CNT);
449 printk(BIOS_DEBUG, "SMI#: ACPI disabled.\n");
450 break;
451 case APM_CNT_ACPI_ENABLE:
452 pmctrl = inl(pmbase + PM1_CNT);
453 pmctrl |= SCI_EN;
454 outl(pmctrl, pmbase + PM1_CNT);
455 printk(BIOS_DEBUG, "SMI#: ACPI enabled.\n");
456 break;
457 case APM_CNT_GNVS_UPDATE:
458 if (smm_initialized) {
459 printk(BIOS_DEBUG, "SMI#: SMM structures already initialized!\n");
460 return;
461 }
462 state = smi_apmc_find_state_save(reg8);
463 if (state) {
464 /* EBX in the state save contains the GNVS pointer */
465 gnvs = (global_nvs_t *)((u32)state->rbx);
466 smm_initialized = 1;
467 printk(BIOS_DEBUG, "SMI#: Setting GNVS to %p\n", gnvs);
468 }
469 break;
470#if CONFIG_ELOG_GSMI
471 case ELOG_GSMI_APM_CNT:
472 southbridge_smi_gsmi();
473 break;
474#endif
475 }
476
Aaron Durbin29ffa542012-12-21 21:21:48 -0600477 mainboard_smi_apmc(reg8);
Aaron Durbin76c37002012-10-30 09:03:43 -0500478}
479
Aaron Durbin29ffa542012-12-21 21:21:48 -0600480static void southbridge_smi_pm1(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500481{
482 u16 pm1_sts;
483
484 pm1_sts = reset_pm1_status();
485 dump_pm1_status(pm1_sts);
486
487 /* While OSPM is not active, poweroff immediately
488 * on a power button event.
489 */
490 if (pm1_sts & PWRBTN_STS) {
491 // power button pressed
492 u32 reg32;
493 reg32 = (7 << 10) | (1 << 13);
494#if CONFIG_ELOG_GSMI
495 elog_add_event(ELOG_TYPE_POWER_BUTTON);
496#endif
497 outl(reg32, pmbase + PM1_CNT);
498 }
499}
500
Aaron Durbin29ffa542012-12-21 21:21:48 -0600501static void southbridge_smi_gpe0(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500502{
503 u32 gpe0_sts;
504
505 gpe0_sts = reset_gpe0_status();
506 dump_gpe0_status(gpe0_sts);
507}
508
Aaron Durbin29ffa542012-12-21 21:21:48 -0600509static void southbridge_smi_gpi(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500510{
Aaron Durbin76c37002012-10-30 09:03:43 -0500511 u16 reg16;
512 reg16 = inw(pmbase + ALT_GP_SMI_STS);
513 outw(reg16, pmbase + ALT_GP_SMI_STS);
514
515 reg16 &= inw(pmbase + ALT_GP_SMI_EN);
516
Aaron Durbin29ffa542012-12-21 21:21:48 -0600517 mainboard_smi_gpi(reg16);
Aaron Durbin76c37002012-10-30 09:03:43 -0500518
519 outw(reg16, pmbase + ALT_GP_SMI_STS);
520}
521
Aaron Durbin29ffa542012-12-21 21:21:48 -0600522static void southbridge_smi_mc(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500523{
524 u32 reg32;
525
526 reg32 = inl(pmbase + SMI_EN);
527
528 /* Are periodic SMIs enabled? */
529 if ((reg32 & MCSMI_EN) == 0)
530 return;
531
532 printk(BIOS_DEBUG, "Microcontroller SMI.\n");
533}
534
535
536
Aaron Durbin29ffa542012-12-21 21:21:48 -0600537static void southbridge_smi_tco(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500538{
539 u32 tco_sts;
540
541 tco_sts = reset_tco_status();
542
543 /* Any TCO event? */
544 if (!tco_sts)
545 return;
546
547 if (tco_sts & (1 << 8)) { // BIOSWR
548 u8 bios_cntl;
549
Aaron Durbin89f79a02012-10-31 23:05:25 -0500550 bios_cntl = pci_read_config16(PCI_DEV(0, 0x1f, 0), 0xdc);
Aaron Durbin76c37002012-10-30 09:03:43 -0500551
552 if (bios_cntl & 1) {
553 /* BWE is RW, so the SMI was caused by a
554 * write to BWE, not by a write to the BIOS
555 */
556
557 /* This is the place where we notice someone
558 * is trying to tinker with the BIOS. We are
559 * trying to be nice and just ignore it. A more
560 * resolute answer would be to power down the
561 * box.
562 */
563 printk(BIOS_DEBUG, "Switching back to RO\n");
Aaron Durbin89f79a02012-10-31 23:05:25 -0500564 pci_write_config32(PCI_DEV(0, 0x1f, 0), 0xdc, (bios_cntl & ~1));
Aaron Durbin76c37002012-10-30 09:03:43 -0500565 } /* No else for now? */
566 } else if (tco_sts & (1 << 3)) { /* TIMEOUT */
567 /* Handle TCO timeout */
568 printk(BIOS_DEBUG, "TCO Timeout.\n");
569 } else if (!tco_sts) {
570 dump_tco_status(tco_sts);
571 }
572}
573
Aaron Durbin29ffa542012-12-21 21:21:48 -0600574static void southbridge_smi_periodic(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500575{
576 u32 reg32;
577
578 reg32 = inl(pmbase + SMI_EN);
579
580 /* Are periodic SMIs enabled? */
581 if ((reg32 & PERIODIC_EN) == 0)
582 return;
583
584 printk(BIOS_DEBUG, "Periodic SMI.\n");
585}
586
Aaron Durbin29ffa542012-12-21 21:21:48 -0600587static void southbridge_smi_monitor(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500588{
589#define IOTRAP(x) (trap_sts & (1 << x))
590 u32 trap_sts, trap_cycle;
591 u32 data, mask = 0;
592 int i;
593
594 trap_sts = RCBA32(0x1e00); // TRSR - Trap Status Register
595 RCBA32(0x1e00) = trap_sts; // Clear trap(s) in TRSR
596
597 trap_cycle = RCBA32(0x1e10);
598 for (i=16; i<20; i++) {
599 if (trap_cycle & (1 << i))
600 mask |= (0xff << ((i - 16) << 2));
601 }
602
603
604 /* IOTRAP(3) SMI function call */
605 if (IOTRAP(3)) {
606 if (gnvs && gnvs->smif)
607 io_trap_handler(gnvs->smif); // call function smif
608 return;
609 }
610
611 /* IOTRAP(2) currently unused
612 * IOTRAP(1) currently unused */
613
614 /* IOTRAP(0) SMIC */
615 if (IOTRAP(0)) {
616 if (!(trap_cycle & (1 << 24))) { // It's a write
617 printk(BIOS_DEBUG, "SMI1 command\n");
618 data = RCBA32(0x1e18);
619 data &= mask;
620 // if (smi1)
621 // southbridge_smi_command(data);
622 // return;
623 }
624 // Fall through to debug
625 }
626
627 printk(BIOS_DEBUG, " trapped io address = 0x%x\n", trap_cycle & 0xfffc);
628 for (i=0; i < 4; i++) if(IOTRAP(i)) printk(BIOS_DEBUG, " TRAPĀ = %d\n", i);
629 printk(BIOS_DEBUG, " AHBE = %x\n", (trap_cycle >> 16) & 0xf);
630 printk(BIOS_DEBUG, " MASK = 0x%08x\n", mask);
631 printk(BIOS_DEBUG, " read/write: %s\n", (trap_cycle & (1 << 24)) ? "read" : "write");
632
633 if (!(trap_cycle & (1 << 24))) {
634 /* Write Cycle */
635 data = RCBA32(0x1e18);
636 printk(BIOS_DEBUG, " iotrap written data = 0x%08x\n", data);
637 }
638#undef IOTRAP
639}
640
Aaron Durbin29ffa542012-12-21 21:21:48 -0600641typedef void (*smi_handler_t)(void);
Aaron Durbin76c37002012-10-30 09:03:43 -0500642
643static smi_handler_t southbridge_smi[32] = {
644 NULL, // [0] reserved
645 NULL, // [1] reserved
646 NULL, // [2] BIOS_STS
647 NULL, // [3] LEGACY_USB_STS
648 southbridge_smi_sleep, // [4] SLP_SMI_STS
649 southbridge_smi_apmc, // [5] APM_STS
650 NULL, // [6] SWSMI_TMR_STS
651 NULL, // [7] reserved
652 southbridge_smi_pm1, // [8] PM1_STS
653 southbridge_smi_gpe0, // [9] GPE0_STS
654 southbridge_smi_gpi, // [10] GPI_STS
655 southbridge_smi_mc, // [11] MCSMI_STS
656 NULL, // [12] DEVMON_STS
657 southbridge_smi_tco, // [13] TCO_STS
658 southbridge_smi_periodic, // [14] PERIODIC_STS
659 NULL, // [15] SERIRQ_SMI_STS
660 NULL, // [16] SMBUS_SMI_STS
661 NULL, // [17] LEGACY_USB2_STS
662 NULL, // [18] INTEL_USB2_STS
663 NULL, // [19] reserved
664 NULL, // [20] PCI_EXP_SMI_STS
665 southbridge_smi_monitor, // [21] MONITOR_STS
666 NULL, // [22] reserved
667 NULL, // [23] reserved
668 NULL, // [24] reserved
669 NULL, // [25] EL_SMI_STS
670 NULL, // [26] SPI_STS
671 NULL, // [27] reserved
672 NULL, // [28] reserved
673 NULL, // [29] reserved
674 NULL, // [30] reserved
675 NULL // [31] reserved
676};
677
678/**
679 * @brief Interrupt handler for SMI#
680 *
681 * @param smm_revision revision of the smm state save map
682 */
683
Aaron Durbin29ffa542012-12-21 21:21:48 -0600684void southbridge_smi_handler(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500685{
686 int i, dump = 0;
687 u32 smi_sts;
688
689 /* Update global variable pmbase */
Aaron Durbin89f79a02012-10-31 23:05:25 -0500690 pmbase = pci_read_config16(PCI_DEV(0, 0x1f, 0), 0x40) & 0xfffc;
Aaron Durbin76c37002012-10-30 09:03:43 -0500691
692 /* We need to clear the SMI status registers, or we won't see what's
693 * happening in the following calls.
694 */
695 smi_sts = reset_smi_status();
696
697 /* Call SMI sub handler for each of the status bits */
698 for (i = 0; i < 31; i++) {
699 if (smi_sts & (1 << i)) {
700 if (southbridge_smi[i]) {
Aaron Durbin29ffa542012-12-21 21:21:48 -0600701 southbridge_smi[i]();
Aaron Durbin76c37002012-10-30 09:03:43 -0500702 } else {
703 printk(BIOS_DEBUG, "SMI_STS[%d] occured, but no "
704 "handler available.\n", i);
705 dump = 1;
706 }
707 }
708 }
709
710 if(dump) {
711 dump_smi_status(smi_sts);
712 }
713
714}