blob: add53ed5a95fd9bcd7cb0cde50aa232d804eeae2 [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
Duncan Laurie467f31d2013-03-08 17:00:37 -08005 * Copyright 2013 Google Inc.
Aaron Durbin76c37002012-10-30 09:03:43 -05006 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; version 2 of
10 * the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
20 * MA 02110-1301 USA
21 */
22
Duncan Laurie2d9d39a2013-05-29 15:27:55 -070023#include <delay.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050024#include <types.h>
25#include <arch/hlt.h>
26#include <arch/io.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050027#include <console/console.h>
28#include <cpu/x86/cache.h>
29#include <device/pci_def.h>
30#include <cpu/x86/smm.h>
31#include <elog.h>
32#include <pc80/mc146818rtc.h>
33#include "pch.h"
34
35#include "nvs.h"
36
Aaron Durbin76c37002012-10-30 09:03:43 -050037
38static u8 smm_initialized = 0;
39
40/* GNVS needs to be updated by an 0xEA PM Trap (B2) after it has been located
41 * by coreboot.
42 */
Aaron Durbin29ffa542012-12-21 21:21:48 -060043static global_nvs_t *gnvs;
Aaron Durbin76c37002012-10-30 09:03:43 -050044global_nvs_t *smm_get_gnvs(void)
45{
46 return gnvs;
47}
48
Aaron Durbin76c37002012-10-30 09:03:43 -050049int southbridge_io_trap_handler(int smif)
50{
51 switch (smif) {
52 case 0x32:
53 printk(BIOS_DEBUG, "OS Init\n");
54 /* gnvs->smif:
55 * On success, the IO Trap Handler returns 0
56 * On failure, the IO Trap Handler returns a value != 0
57 */
58 gnvs->smif = 0;
59 return 1; /* IO trap handled */
60 }
61
62 /* Not handled */
63 return 0;
64}
65
66/**
67 * @brief Set the EOS bit
68 */
69void southbridge_smi_set_eos(void)
70{
Duncan Laurie467f31d2013-03-08 17:00:37 -080071 enable_smi(EOS);
Aaron Durbin76c37002012-10-30 09:03:43 -050072}
73
74static void busmaster_disable_on_bus(int bus)
75{
76 int slot, func;
77 unsigned int val;
78 unsigned char hdr;
79
80 for (slot = 0; slot < 0x20; slot++) {
81 for (func = 0; func < 8; func++) {
82 u32 reg32;
83 device_t dev = PCI_DEV(bus, slot, func);
84
85 val = pci_read_config32(dev, PCI_VENDOR_ID);
86
87 if (val == 0xffffffff || val == 0x00000000 ||
88 val == 0x0000ffff || val == 0xffff0000)
89 continue;
90
91 /* Disable Bus Mastering for this one device */
92 reg32 = pci_read_config32(dev, PCI_COMMAND);
93 reg32 &= ~PCI_COMMAND_MASTER;
94 pci_write_config32(dev, PCI_COMMAND, reg32);
95
96 /* If this is a bridge, then follow it. */
97 hdr = pci_read_config8(dev, PCI_HEADER_TYPE);
98 hdr &= 0x7f;
99 if (hdr == PCI_HEADER_TYPE_BRIDGE ||
100 hdr == PCI_HEADER_TYPE_CARDBUS) {
101 unsigned int buses;
102 buses = pci_read_config32(dev, PCI_PRIMARY_BUS);
103 busmaster_disable_on_bus((buses >> 8) & 0xff);
104 }
105 }
106 }
107}
108
Duncan Laurie2d9d39a2013-05-29 15:27:55 -0700109/* Handler for EHCI controller on entry to S3/S4/S5 */
110static void ehci_sleep_prepare(device_t dev, u8 slp_typ)
111{
112 u32 reg32;
113 u32 bar0_base;
114 u16 pwr_state;
115 u16 pci_cmd;
116
117 /* Check if the controller is disabled or not present */
118 bar0_base = pci_read_config32(dev, PCI_BASE_ADDRESS_0);
119 if (bar0_base == 0 || bar0_base == 0xffffffff)
120 return;
121 pci_cmd = pci_read_config32(dev, PCI_COMMAND);
122
123 switch (slp_typ) {
124 case SLP_TYP_S4:
125 case SLP_TYP_S5:
126 /* Check if controller is in D3 power state */
127 pwr_state = pci_read_config16(dev, EHCI_PWR_CNTL_STS);
128 if ((pwr_state & EHCI_PWR_STS_MASK) == EHCI_PWR_STS_SET_D3) {
129 /* Put in D0 */
130 pwr_state &= ~EHCI_PWR_STS_MASK;
131 pwr_state |= EHCI_PWR_STS_SET_D0;
132 pci_write_config16(dev, EHCI_PWR_CNTL_STS, pwr_state);
133
134 /* Make sure memory bar is set */
135 pci_write_config32(dev, PCI_BASE_ADDRESS_0, bar0_base);
136
137 /* Make sure memory space is enabled */
138 pci_write_config16(dev, PCI_COMMAND, pci_cmd |
139 PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
140 }
141
142 /*
143 * If Run/Stop (bit0) is clear in USB2.0_CMD:
144 * - Clear Async Schedule Enable (bit5) and
145 * - Clear Periodic Schedule Enable (bit4) and
146 * - Set Run/Stop (bit0)
147 */
148 reg32 = read32(bar0_base + 0x20);
149 if (reg32 & (1 << 0)) {
150 reg32 &= ~((1 << 5) | (1 << 4));
151 reg32 |= (1 << 0);
152 write32(bar0_base + 0x20, reg32);
153 }
154
155 /* Check for Port Enabled in PORTSC */
156 reg32 = read32(bar0_base + 0x64);
157 if (reg32 & (1 << 2)) {
158 /* Set suspend bit in PORTSC if not already set */
159 if (!(reg32 & (1 << 7))) {
160 reg32 |= (1 << 7);
161 write32(bar0_base + 0x64, reg32);
162 }
163
164 /* Delay 25ms !! */
165 udelay(25 * 1000);
166
167 /* Clear Run/Stop bit */
168 reg32 = read32(bar0_base + 0x20);
169 reg32 &= (1 << 0);
170 write32(bar0_base + 0x20, reg32);
171 }
172
173 pwr_state = pci_read_config16(dev, EHCI_PWR_CNTL_STS);
174 if ((pwr_state & EHCI_PWR_STS_MASK) == EHCI_PWR_STS_SET_D3) {
175 /* Restore pci command reg */
176 pci_write_config16(dev, PCI_COMMAND, pci_cmd);
177
178 /* Enable D3 */
179 pwr_state |= EHCI_PWR_STS_SET_D3;
180 pci_write_config16(dev, EHCI_PWR_CNTL_STS, pwr_state);
181 }
182 }
183}
184
185/* Handler for XHCI controller on entry to S3/S4/S5 */
186static void xhci_sleep_prepare(device_t dev, u8 slp_typ)
187{
188 u16 reg16;
189
190 switch (slp_typ) {
191 case SLP_TYP_S3:
192 case SLP_TYP_S4:
193 case SLP_TYP_S5:
194 /* Set D3Hot state and PME enable bit */
195 reg16 = pci_read_config16(dev, 0x74);
196 reg16 |= (1 << 8) | (1 << 1) | (1 << 0);
197 pci_write_config16(dev, 0x74, reg16);
198 }
199}
200
Aaron Durbin29ffa542012-12-21 21:21:48 -0600201static void southbridge_smi_sleep(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500202{
203 u8 reg8;
204 u32 reg32;
205 u8 slp_typ;
206 u8 s5pwr = CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL;
Duncan Laurie467f31d2013-03-08 17:00:37 -0800207 u16 pmbase = get_pmbase();
Aaron Durbin76c37002012-10-30 09:03:43 -0500208
209 // save and recover RTC port values
210 u8 tmp70, tmp72;
211 tmp70 = inb(0x70);
212 tmp72 = inb(0x72);
213 get_option(&s5pwr, "power_on_after_fail");
214 outb(tmp70, 0x70);
215 outb(tmp72, 0x72);
216
Aaron Durbin76c37002012-10-30 09:03:43 -0500217 /* First, disable further SMIs */
Duncan Laurie467f31d2013-03-08 17:00:37 -0800218 disable_smi(SLP_SMI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500219
220 /* Figure out SLP_TYP */
221 reg32 = inl(pmbase + PM1_CNT);
222 printk(BIOS_SPEW, "SMI#: SLP = 0x%08x\n", reg32);
223 slp_typ = (reg32 >> 10) & 7;
224
225 /* Do any mainboard sleep handling */
Aaron Durbin29ffa542012-12-21 21:21:48 -0600226 mainboard_smi_sleep(slp_typ-2);
Aaron Durbin76c37002012-10-30 09:03:43 -0500227
Duncan Laurie2d9d39a2013-05-29 15:27:55 -0700228 /* USB sleep preparations */
229 ehci_sleep_prepare(PCH_EHCI1_DEV, slp_typ);
230 ehci_sleep_prepare(PCH_EHCI2_DEV, slp_typ);
231 xhci_sleep_prepare(PCH_XHCI_DEV, slp_typ);
232
Aaron Durbin76c37002012-10-30 09:03:43 -0500233#if CONFIG_ELOG_GSMI
234 /* Log S3, S4, and S5 entry */
235 if (slp_typ >= 5)
236 elog_add_event_byte(ELOG_TYPE_ACPI_ENTER, slp_typ-2);
237#endif
238
239 /* Next, do the deed.
240 */
241
242 switch (slp_typ) {
Duncan Laurie467f31d2013-03-08 17:00:37 -0800243 case SLP_TYP_S0:
244 printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n");
245 break;
246 case SLP_TYP_S1:
247 printk(BIOS_DEBUG, "SMI#: Entering S1 (Assert STPCLK#)\n");
248 break;
249 case SLP_TYP_S3:
Aaron Durbin76c37002012-10-30 09:03:43 -0500250 printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n");
251
Aaron Durbin76c37002012-10-30 09:03:43 -0500252 /* Invalidate the cache before going to S3 */
253 wbinvd();
254 break;
Duncan Laurie467f31d2013-03-08 17:00:37 -0800255 case SLP_TYP_S4:
256 printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n");
257 break;
258 case SLP_TYP_S5:
Aaron Durbin76c37002012-10-30 09:03:43 -0500259 printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n");
260
Duncan Laurie467f31d2013-03-08 17:00:37 -0800261 /* Disable all GPE */
262 disable_all_gpe();
Aaron Durbin76c37002012-10-30 09:03:43 -0500263
264 /* Always set the flag in case CMOS was changed on runtime. For
265 * "KEEP", switch to "OFF" - KEEP is software emulated
266 */
Aaron Durbin89f79a02012-10-31 23:05:25 -0500267 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3);
Aaron Durbin76c37002012-10-30 09:03:43 -0500268 if (s5pwr == MAINBOARD_POWER_ON) {
269 reg8 &= ~1;
270 } else {
271 reg8 |= 1;
272 }
Aaron Durbin89f79a02012-10-31 23:05:25 -0500273 pci_write_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3, reg8);
Aaron Durbin76c37002012-10-30 09:03:43 -0500274
275 /* also iterates over all bridges on bus 0 */
276 busmaster_disable_on_bus(0);
277 break;
Duncan Laurie467f31d2013-03-08 17:00:37 -0800278 default:
279 printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n");
280 break;
Aaron Durbin76c37002012-10-30 09:03:43 -0500281 }
282
283 /* Write back to the SLP register to cause the originally intended
284 * event again. We need to set BIT13 (SLP_EN) though to make the
285 * sleep happen.
286 */
Duncan Laurie467f31d2013-03-08 17:00:37 -0800287 enable_pm1_control(SLP_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500288
289 /* Make sure to stop executing code here for S3/S4/S5 */
290 if (slp_typ > 1)
291 hlt();
292
293 /* In most sleep states, the code flow of this function ends at
294 * the line above. However, if we entered sleep state S1 and wake
295 * up again, we will continue to execute code in this function.
296 */
297 reg32 = inl(pmbase + PM1_CNT);
298 if (reg32 & SCI_EN) {
299 /* The OS is not an ACPI OS, so we set the state to S0 */
Duncan Laurie467f31d2013-03-08 17:00:37 -0800300 disable_pm1_control(SLP_EN | SLP_TYP);
Aaron Durbin76c37002012-10-30 09:03:43 -0500301 }
302}
303
304/*
305 * Look for Synchronous IO SMI and use save state from that
306 * core in case we are not running on the same core that
307 * initiated the IO transaction.
308 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500309static em64t101_smm_state_save_area_t *smi_apmc_find_state_save(u8 cmd)
310{
311 em64t101_smm_state_save_area_t *state;
Aaron Durbin76c37002012-10-30 09:03:43 -0500312 int node;
313
314 /* Check all nodes looking for the one that issued the IO */
315 for (node = 0; node < CONFIG_MAX_CPUS; node++) {
Aaron Durbin29ffa542012-12-21 21:21:48 -0600316 state = smm_get_save_state(node);
Aaron Durbin76c37002012-10-30 09:03:43 -0500317
318 /* Check for Synchronous IO (bit0==1) */
319 if (!(state->io_misc_info & (1 << 0)))
320 continue;
321
322 /* Make sure it was a write (bit4==0) */
323 if (state->io_misc_info & (1 << 4))
324 continue;
325
326 /* Check for APMC IO port */
327 if (((state->io_misc_info >> 16) & 0xff) != APM_CNT)
328 continue;
329
330 /* Check AX against the requested command */
331 if ((state->rax & 0xff) != cmd)
332 continue;
333
334 return state;
335 }
336
337 return NULL;
338}
339
340#if CONFIG_ELOG_GSMI
341static void southbridge_smi_gsmi(void)
342{
343 u32 *ret, *param;
344 u8 sub_command;
345 em64t101_smm_state_save_area_t *io_smi =
346 smi_apmc_find_state_save(ELOG_GSMI_APM_CNT);
347
348 if (!io_smi)
349 return;
350
351 /* Command and return value in EAX */
352 ret = (u32*)&io_smi->rax;
353 sub_command = (u8)(*ret >> 8);
354
355 /* Parameter buffer in EBX */
356 param = (u32*)&io_smi->rbx;
357
358 /* drivers/elog/gsmi.c */
359 *ret = gsmi_exec(sub_command, param);
360}
361#endif
362
Aaron Durbin29ffa542012-12-21 21:21:48 -0600363static void southbridge_smi_apmc(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500364{
Aaron Durbin76c37002012-10-30 09:03:43 -0500365 u8 reg8;
Aaron Durbin76c37002012-10-30 09:03:43 -0500366 em64t101_smm_state_save_area_t *state;
367
368 /* Emulate B2 register as the FADT / Linux expects it */
369
370 reg8 = inb(APM_CNT);
371 switch (reg8) {
372 case APM_CNT_CST_CONTROL:
373 /* Calling this function seems to cause
374 * some kind of race condition in Linux
375 * and causes a kernel oops
376 */
377 printk(BIOS_DEBUG, "C-state control\n");
378 break;
379 case APM_CNT_PST_CONTROL:
380 /* Calling this function seems to cause
381 * some kind of race condition in Linux
382 * and causes a kernel oops
383 */
384 printk(BIOS_DEBUG, "P-state control\n");
385 break;
386 case APM_CNT_ACPI_DISABLE:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800387 disable_pm1_control(SCI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500388 printk(BIOS_DEBUG, "SMI#: ACPI disabled.\n");
389 break;
390 case APM_CNT_ACPI_ENABLE:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800391 enable_pm1_control(SCI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500392 printk(BIOS_DEBUG, "SMI#: ACPI enabled.\n");
393 break;
394 case APM_CNT_GNVS_UPDATE:
395 if (smm_initialized) {
Duncan Laurie467f31d2013-03-08 17:00:37 -0800396 printk(BIOS_DEBUG,
397 "SMI#: SMM structures already initialized!\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500398 return;
399 }
400 state = smi_apmc_find_state_save(reg8);
401 if (state) {
402 /* EBX in the state save contains the GNVS pointer */
403 gnvs = (global_nvs_t *)((u32)state->rbx);
404 smm_initialized = 1;
405 printk(BIOS_DEBUG, "SMI#: Setting GNVS to %p\n", gnvs);
406 }
407 break;
408#if CONFIG_ELOG_GSMI
409 case ELOG_GSMI_APM_CNT:
410 southbridge_smi_gsmi();
411 break;
412#endif
413 }
414
Aaron Durbin29ffa542012-12-21 21:21:48 -0600415 mainboard_smi_apmc(reg8);
Aaron Durbin76c37002012-10-30 09:03:43 -0500416}
417
Aaron Durbin29ffa542012-12-21 21:21:48 -0600418static void southbridge_smi_pm1(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500419{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800420 u16 pm1_sts = clear_pm1_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500421
422 /* While OSPM is not active, poweroff immediately
423 * on a power button event.
424 */
425 if (pm1_sts & PWRBTN_STS) {
426 // power button pressed
Aaron Durbin76c37002012-10-30 09:03:43 -0500427#if CONFIG_ELOG_GSMI
428 elog_add_event(ELOG_TYPE_POWER_BUTTON);
429#endif
Duncan Laurie467f31d2013-03-08 17:00:37 -0800430 disable_pm1_control(-1UL);
431 enable_pm1_control(SLP_EN | (SLP_TYP_S5 << 10));
Aaron Durbin76c37002012-10-30 09:03:43 -0500432 }
433}
434
Aaron Durbin29ffa542012-12-21 21:21:48 -0600435static void southbridge_smi_gpe0(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500436{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800437 clear_gpe_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500438}
439
Aaron Durbin29ffa542012-12-21 21:21:48 -0600440static void southbridge_smi_gpi(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500441{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800442 mainboard_smi_gpi(clear_alt_smi_status());
Aaron Durbin76c37002012-10-30 09:03:43 -0500443
Duncan Laurie467f31d2013-03-08 17:00:37 -0800444 /* Clear again after mainboard handler */
445 clear_alt_smi_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500446}
447
Aaron Durbin29ffa542012-12-21 21:21:48 -0600448static void southbridge_smi_mc(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500449{
450 u32 reg32;
451
Duncan Laurie467f31d2013-03-08 17:00:37 -0800452 reg32 = inl(get_pmbase() + SMI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500453
Duncan Laurie467f31d2013-03-08 17:00:37 -0800454 /* Are microcontroller SMIs enabled? */
Aaron Durbin76c37002012-10-30 09:03:43 -0500455 if ((reg32 & MCSMI_EN) == 0)
456 return;
457
458 printk(BIOS_DEBUG, "Microcontroller SMI.\n");
459}
460
461
462
Aaron Durbin29ffa542012-12-21 21:21:48 -0600463static void southbridge_smi_tco(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500464{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800465 u32 tco_sts = clear_tco_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500466
467 /* Any TCO event? */
468 if (!tco_sts)
469 return;
470
471 if (tco_sts & (1 << 8)) { // BIOSWR
472 u8 bios_cntl;
473
Aaron Durbin89f79a02012-10-31 23:05:25 -0500474 bios_cntl = pci_read_config16(PCI_DEV(0, 0x1f, 0), 0xdc);
Aaron Durbin76c37002012-10-30 09:03:43 -0500475
476 if (bios_cntl & 1) {
477 /* BWE is RW, so the SMI was caused by a
478 * write to BWE, not by a write to the BIOS
479 */
480
481 /* This is the place where we notice someone
482 * is trying to tinker with the BIOS. We are
483 * trying to be nice and just ignore it. A more
484 * resolute answer would be to power down the
485 * box.
486 */
487 printk(BIOS_DEBUG, "Switching back to RO\n");
Duncan Laurie467f31d2013-03-08 17:00:37 -0800488 pci_write_config32(PCI_DEV(0, 0x1f, 0), 0xdc,
489 (bios_cntl & ~1));
Aaron Durbin76c37002012-10-30 09:03:43 -0500490 } /* No else for now? */
491 } else if (tco_sts & (1 << 3)) { /* TIMEOUT */
492 /* Handle TCO timeout */
493 printk(BIOS_DEBUG, "TCO Timeout.\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500494 }
495}
496
Aaron Durbin29ffa542012-12-21 21:21:48 -0600497static void southbridge_smi_periodic(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500498{
499 u32 reg32;
500
Duncan Laurie467f31d2013-03-08 17:00:37 -0800501 reg32 = inl(get_pmbase() + SMI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500502
503 /* Are periodic SMIs enabled? */
504 if ((reg32 & PERIODIC_EN) == 0)
505 return;
506
507 printk(BIOS_DEBUG, "Periodic SMI.\n");
508}
509
Aaron Durbin29ffa542012-12-21 21:21:48 -0600510static void southbridge_smi_monitor(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500511{
512#define IOTRAP(x) (trap_sts & (1 << x))
513 u32 trap_sts, trap_cycle;
514 u32 data, mask = 0;
515 int i;
516
517 trap_sts = RCBA32(0x1e00); // TRSR - Trap Status Register
518 RCBA32(0x1e00) = trap_sts; // Clear trap(s) in TRSR
519
520 trap_cycle = RCBA32(0x1e10);
521 for (i=16; i<20; i++) {
522 if (trap_cycle & (1 << i))
523 mask |= (0xff << ((i - 16) << 2));
524 }
525
526
527 /* IOTRAP(3) SMI function call */
528 if (IOTRAP(3)) {
529 if (gnvs && gnvs->smif)
530 io_trap_handler(gnvs->smif); // call function smif
531 return;
532 }
533
534 /* IOTRAP(2) currently unused
535 * IOTRAP(1) currently unused */
536
537 /* IOTRAP(0) SMIC */
538 if (IOTRAP(0)) {
539 if (!(trap_cycle & (1 << 24))) { // It's a write
540 printk(BIOS_DEBUG, "SMI1 command\n");
541 data = RCBA32(0x1e18);
542 data &= mask;
543 // if (smi1)
544 // southbridge_smi_command(data);
545 // return;
546 }
547 // Fall through to debug
548 }
549
Duncan Laurie467f31d2013-03-08 17:00:37 -0800550 printk(BIOS_DEBUG, " trapped io address = 0x%x\n",
551 trap_cycle & 0xfffc);
552 for (i=0; i < 4; i++)
553 if(IOTRAP(i)) printk(BIOS_DEBUG, " TRAP = %d\n", i);
Aaron Durbin76c37002012-10-30 09:03:43 -0500554 printk(BIOS_DEBUG, " AHBE = %x\n", (trap_cycle >> 16) & 0xf);
555 printk(BIOS_DEBUG, " MASK = 0x%08x\n", mask);
Duncan Laurie467f31d2013-03-08 17:00:37 -0800556 printk(BIOS_DEBUG, " read/write: %s\n",
557 (trap_cycle & (1 << 24)) ? "read" : "write");
Aaron Durbin76c37002012-10-30 09:03:43 -0500558
559 if (!(trap_cycle & (1 << 24))) {
560 /* Write Cycle */
561 data = RCBA32(0x1e18);
562 printk(BIOS_DEBUG, " iotrap written data = 0x%08x\n", data);
563 }
564#undef IOTRAP
565}
566
Aaron Durbin29ffa542012-12-21 21:21:48 -0600567typedef void (*smi_handler_t)(void);
Aaron Durbin76c37002012-10-30 09:03:43 -0500568
569static smi_handler_t southbridge_smi[32] = {
570 NULL, // [0] reserved
571 NULL, // [1] reserved
572 NULL, // [2] BIOS_STS
573 NULL, // [3] LEGACY_USB_STS
574 southbridge_smi_sleep, // [4] SLP_SMI_STS
575 southbridge_smi_apmc, // [5] APM_STS
576 NULL, // [6] SWSMI_TMR_STS
577 NULL, // [7] reserved
578 southbridge_smi_pm1, // [8] PM1_STS
579 southbridge_smi_gpe0, // [9] GPE0_STS
580 southbridge_smi_gpi, // [10] GPI_STS
581 southbridge_smi_mc, // [11] MCSMI_STS
582 NULL, // [12] DEVMON_STS
583 southbridge_smi_tco, // [13] TCO_STS
584 southbridge_smi_periodic, // [14] PERIODIC_STS
585 NULL, // [15] SERIRQ_SMI_STS
586 NULL, // [16] SMBUS_SMI_STS
587 NULL, // [17] LEGACY_USB2_STS
588 NULL, // [18] INTEL_USB2_STS
589 NULL, // [19] reserved
590 NULL, // [20] PCI_EXP_SMI_STS
591 southbridge_smi_monitor, // [21] MONITOR_STS
592 NULL, // [22] reserved
593 NULL, // [23] reserved
594 NULL, // [24] reserved
595 NULL, // [25] EL_SMI_STS
596 NULL, // [26] SPI_STS
597 NULL, // [27] reserved
598 NULL, // [28] reserved
599 NULL, // [29] reserved
600 NULL, // [30] reserved
601 NULL // [31] reserved
602};
603
604/**
605 * @brief Interrupt handler for SMI#
606 *
607 * @param smm_revision revision of the smm state save map
608 */
609
Aaron Durbin29ffa542012-12-21 21:21:48 -0600610void southbridge_smi_handler(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500611{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800612 int i;
Aaron Durbin76c37002012-10-30 09:03:43 -0500613 u32 smi_sts;
614
Aaron Durbin76c37002012-10-30 09:03:43 -0500615 /* We need to clear the SMI status registers, or we won't see what's
616 * happening in the following calls.
617 */
Duncan Laurie467f31d2013-03-08 17:00:37 -0800618 smi_sts = clear_smi_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500619
620 /* Call SMI sub handler for each of the status bits */
621 for (i = 0; i < 31; i++) {
622 if (smi_sts & (1 << i)) {
623 if (southbridge_smi[i]) {
Aaron Durbin29ffa542012-12-21 21:21:48 -0600624 southbridge_smi[i]();
Aaron Durbin76c37002012-10-30 09:03:43 -0500625 } else {
Duncan Laurie467f31d2013-03-08 17:00:37 -0800626 printk(BIOS_DEBUG,
627 "SMI_STS[%d] occured, but no "
628 "handler available.\n", i);
Aaron Durbin76c37002012-10-30 09:03:43 -0500629 }
630 }
631 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500632}