Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 5 | * Copyright 2013 Google Inc. |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 6 | * |
| 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 Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 23 | #include <delay.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 24 | #include <types.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 25 | #include <arch/io.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 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> |
Patrick Georgi | 546953c | 2014-11-29 10:38:17 +0100 | [diff] [blame^] | 31 | #include <halt.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 32 | #include <pc80/mc146818rtc.h> |
| 33 | #include "pch.h" |
| 34 | |
| 35 | #include "nvs.h" |
| 36 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 37 | |
| 38 | static 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 Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 43 | static global_nvs_t *gnvs; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 44 | global_nvs_t *smm_get_gnvs(void) |
| 45 | { |
| 46 | return gnvs; |
| 47 | } |
| 48 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 49 | int 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 | */ |
| 69 | void southbridge_smi_set_eos(void) |
| 70 | { |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 71 | enable_smi(EOS); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | static 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 Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 109 | |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 110 | static void southbridge_smi_sleep(void) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 111 | { |
| 112 | u8 reg8; |
| 113 | u32 reg32; |
| 114 | u8 slp_typ; |
| 115 | u8 s5pwr = CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL; |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 116 | u16 pmbase = get_pmbase(); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 117 | |
| 118 | // save and recover RTC port values |
| 119 | u8 tmp70, tmp72; |
| 120 | tmp70 = inb(0x70); |
| 121 | tmp72 = inb(0x72); |
| 122 | get_option(&s5pwr, "power_on_after_fail"); |
| 123 | outb(tmp70, 0x70); |
| 124 | outb(tmp72, 0x72); |
| 125 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 126 | /* First, disable further SMIs */ |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 127 | disable_smi(SLP_SMI_EN); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 128 | |
| 129 | /* Figure out SLP_TYP */ |
| 130 | reg32 = inl(pmbase + PM1_CNT); |
| 131 | printk(BIOS_SPEW, "SMI#: SLP = 0x%08x\n", reg32); |
| 132 | slp_typ = (reg32 >> 10) & 7; |
| 133 | |
| 134 | /* Do any mainboard sleep handling */ |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 135 | mainboard_smi_sleep(slp_typ-2); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 136 | |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 137 | /* USB sleep preparations */ |
Duncan Laurie | 911cedf | 2013-07-30 16:05:55 -0700 | [diff] [blame] | 138 | #if !CONFIG_FINALIZE_USB_ROUTE_XHCI |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 139 | usb_ehci_sleep_prepare(PCH_EHCI1_DEV, slp_typ); |
| 140 | usb_ehci_sleep_prepare(PCH_EHCI2_DEV, slp_typ); |
Duncan Laurie | 911cedf | 2013-07-30 16:05:55 -0700 | [diff] [blame] | 141 | #endif |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 142 | usb_xhci_sleep_prepare(PCH_XHCI_DEV, slp_typ); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 143 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 144 | #if CONFIG_ELOG_GSMI |
| 145 | /* Log S3, S4, and S5 entry */ |
| 146 | if (slp_typ >= 5) |
| 147 | elog_add_event_byte(ELOG_TYPE_ACPI_ENTER, slp_typ-2); |
| 148 | #endif |
| 149 | |
| 150 | /* Next, do the deed. |
| 151 | */ |
| 152 | |
| 153 | switch (slp_typ) { |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 154 | case SLP_TYP_S0: |
| 155 | printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n"); |
| 156 | break; |
| 157 | case SLP_TYP_S1: |
| 158 | printk(BIOS_DEBUG, "SMI#: Entering S1 (Assert STPCLK#)\n"); |
| 159 | break; |
| 160 | case SLP_TYP_S3: |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 161 | printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n"); |
| 162 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 163 | /* Invalidate the cache before going to S3 */ |
| 164 | wbinvd(); |
| 165 | break; |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 166 | case SLP_TYP_S4: |
| 167 | printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n"); |
| 168 | break; |
| 169 | case SLP_TYP_S5: |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 170 | printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n"); |
| 171 | |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 172 | /* Disable all GPE */ |
| 173 | disable_all_gpe(); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 174 | |
| 175 | /* Always set the flag in case CMOS was changed on runtime. For |
| 176 | * "KEEP", switch to "OFF" - KEEP is software emulated |
| 177 | */ |
Aaron Durbin | 89f79a0 | 2012-10-31 23:05:25 -0500 | [diff] [blame] | 178 | reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 179 | if (s5pwr == MAINBOARD_POWER_ON) { |
| 180 | reg8 &= ~1; |
| 181 | } else { |
| 182 | reg8 |= 1; |
| 183 | } |
Aaron Durbin | 89f79a0 | 2012-10-31 23:05:25 -0500 | [diff] [blame] | 184 | pci_write_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3, reg8); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 185 | |
| 186 | /* also iterates over all bridges on bus 0 */ |
| 187 | busmaster_disable_on_bus(0); |
| 188 | break; |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 189 | default: |
| 190 | printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n"); |
| 191 | break; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | /* Write back to the SLP register to cause the originally intended |
| 195 | * event again. We need to set BIT13 (SLP_EN) though to make the |
| 196 | * sleep happen. |
| 197 | */ |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 198 | enable_pm1_control(SLP_EN); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 199 | |
| 200 | /* Make sure to stop executing code here for S3/S4/S5 */ |
| 201 | if (slp_typ > 1) |
Patrick Georgi | 546953c | 2014-11-29 10:38:17 +0100 | [diff] [blame^] | 202 | halt(); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 203 | |
| 204 | /* In most sleep states, the code flow of this function ends at |
| 205 | * the line above. However, if we entered sleep state S1 and wake |
| 206 | * up again, we will continue to execute code in this function. |
| 207 | */ |
| 208 | reg32 = inl(pmbase + PM1_CNT); |
| 209 | if (reg32 & SCI_EN) { |
| 210 | /* The OS is not an ACPI OS, so we set the state to S0 */ |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 211 | disable_pm1_control(SLP_EN | SLP_TYP); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | |
| 215 | /* |
| 216 | * Look for Synchronous IO SMI and use save state from that |
| 217 | * core in case we are not running on the same core that |
| 218 | * initiated the IO transaction. |
| 219 | */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 220 | static em64t101_smm_state_save_area_t *smi_apmc_find_state_save(u8 cmd) |
| 221 | { |
| 222 | em64t101_smm_state_save_area_t *state; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 223 | int node; |
| 224 | |
| 225 | /* Check all nodes looking for the one that issued the IO */ |
| 226 | for (node = 0; node < CONFIG_MAX_CPUS; node++) { |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 227 | state = smm_get_save_state(node); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 228 | |
| 229 | /* Check for Synchronous IO (bit0==1) */ |
| 230 | if (!(state->io_misc_info & (1 << 0))) |
| 231 | continue; |
| 232 | |
| 233 | /* Make sure it was a write (bit4==0) */ |
| 234 | if (state->io_misc_info & (1 << 4)) |
| 235 | continue; |
| 236 | |
| 237 | /* Check for APMC IO port */ |
| 238 | if (((state->io_misc_info >> 16) & 0xff) != APM_CNT) |
| 239 | continue; |
| 240 | |
| 241 | /* Check AX against the requested command */ |
| 242 | if ((state->rax & 0xff) != cmd) |
| 243 | continue; |
| 244 | |
| 245 | return state; |
| 246 | } |
| 247 | |
| 248 | return NULL; |
| 249 | } |
| 250 | |
| 251 | #if CONFIG_ELOG_GSMI |
| 252 | static void southbridge_smi_gsmi(void) |
| 253 | { |
| 254 | u32 *ret, *param; |
| 255 | u8 sub_command; |
| 256 | em64t101_smm_state_save_area_t *io_smi = |
| 257 | smi_apmc_find_state_save(ELOG_GSMI_APM_CNT); |
| 258 | |
| 259 | if (!io_smi) |
| 260 | return; |
| 261 | |
| 262 | /* Command and return value in EAX */ |
| 263 | ret = (u32*)&io_smi->rax; |
| 264 | sub_command = (u8)(*ret >> 8); |
| 265 | |
| 266 | /* Parameter buffer in EBX */ |
| 267 | param = (u32*)&io_smi->rbx; |
| 268 | |
| 269 | /* drivers/elog/gsmi.c */ |
| 270 | *ret = gsmi_exec(sub_command, param); |
| 271 | } |
| 272 | #endif |
| 273 | |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 274 | static void southbridge_smi_apmc(void) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 275 | { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 276 | u8 reg8; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 277 | em64t101_smm_state_save_area_t *state; |
| 278 | |
| 279 | /* Emulate B2 register as the FADT / Linux expects it */ |
| 280 | |
| 281 | reg8 = inb(APM_CNT); |
| 282 | switch (reg8) { |
| 283 | case APM_CNT_CST_CONTROL: |
| 284 | /* Calling this function seems to cause |
| 285 | * some kind of race condition in Linux |
| 286 | * and causes a kernel oops |
| 287 | */ |
| 288 | printk(BIOS_DEBUG, "C-state control\n"); |
| 289 | break; |
| 290 | case APM_CNT_PST_CONTROL: |
| 291 | /* Calling this function seems to cause |
| 292 | * some kind of race condition in Linux |
| 293 | * and causes a kernel oops |
| 294 | */ |
| 295 | printk(BIOS_DEBUG, "P-state control\n"); |
| 296 | break; |
| 297 | case APM_CNT_ACPI_DISABLE: |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 298 | disable_pm1_control(SCI_EN); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 299 | printk(BIOS_DEBUG, "SMI#: ACPI disabled.\n"); |
| 300 | break; |
| 301 | case APM_CNT_ACPI_ENABLE: |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 302 | enable_pm1_control(SCI_EN); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 303 | printk(BIOS_DEBUG, "SMI#: ACPI enabled.\n"); |
| 304 | break; |
| 305 | case APM_CNT_GNVS_UPDATE: |
| 306 | if (smm_initialized) { |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 307 | printk(BIOS_DEBUG, |
| 308 | "SMI#: SMM structures already initialized!\n"); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 309 | return; |
| 310 | } |
| 311 | state = smi_apmc_find_state_save(reg8); |
| 312 | if (state) { |
| 313 | /* EBX in the state save contains the GNVS pointer */ |
| 314 | gnvs = (global_nvs_t *)((u32)state->rbx); |
| 315 | smm_initialized = 1; |
| 316 | printk(BIOS_DEBUG, "SMI#: Setting GNVS to %p\n", gnvs); |
| 317 | } |
| 318 | break; |
Duncan Laurie | 78145a5 | 2013-08-21 13:16:21 -0700 | [diff] [blame] | 319 | case 0xca: |
Duncan Laurie | 911cedf | 2013-07-30 16:05:55 -0700 | [diff] [blame] | 320 | usb_xhci_route_all(); |
Duncan Laurie | 911cedf | 2013-07-30 16:05:55 -0700 | [diff] [blame] | 321 | break; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 322 | #if CONFIG_ELOG_GSMI |
| 323 | case ELOG_GSMI_APM_CNT: |
| 324 | southbridge_smi_gsmi(); |
| 325 | break; |
| 326 | #endif |
| 327 | } |
| 328 | |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 329 | mainboard_smi_apmc(reg8); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 330 | } |
| 331 | |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 332 | static void southbridge_smi_pm1(void) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 333 | { |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 334 | u16 pm1_sts = clear_pm1_status(); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 335 | |
| 336 | /* While OSPM is not active, poweroff immediately |
| 337 | * on a power button event. |
| 338 | */ |
| 339 | if (pm1_sts & PWRBTN_STS) { |
| 340 | // power button pressed |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 341 | #if CONFIG_ELOG_GSMI |
| 342 | elog_add_event(ELOG_TYPE_POWER_BUTTON); |
| 343 | #endif |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 344 | disable_pm1_control(-1UL); |
| 345 | enable_pm1_control(SLP_EN | (SLP_TYP_S5 << 10)); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 349 | static void southbridge_smi_gpe0(void) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 350 | { |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 351 | clear_gpe_status(); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 352 | } |
| 353 | |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 354 | static void southbridge_smi_gpi(void) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 355 | { |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 356 | mainboard_smi_gpi(clear_alt_smi_status()); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 357 | |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 358 | /* Clear again after mainboard handler */ |
| 359 | clear_alt_smi_status(); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 360 | } |
| 361 | |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 362 | static void southbridge_smi_mc(void) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 363 | { |
| 364 | u32 reg32; |
| 365 | |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 366 | reg32 = inl(get_pmbase() + SMI_EN); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 367 | |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 368 | /* Are microcontroller SMIs enabled? */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 369 | if ((reg32 & MCSMI_EN) == 0) |
| 370 | return; |
| 371 | |
| 372 | printk(BIOS_DEBUG, "Microcontroller SMI.\n"); |
| 373 | } |
| 374 | |
| 375 | |
| 376 | |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 377 | static void southbridge_smi_tco(void) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 378 | { |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 379 | u32 tco_sts = clear_tco_status(); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 380 | |
| 381 | /* Any TCO event? */ |
| 382 | if (!tco_sts) |
| 383 | return; |
| 384 | |
| 385 | if (tco_sts & (1 << 8)) { // BIOSWR |
| 386 | u8 bios_cntl; |
| 387 | |
Aaron Durbin | 89f79a0 | 2012-10-31 23:05:25 -0500 | [diff] [blame] | 388 | bios_cntl = pci_read_config16(PCI_DEV(0, 0x1f, 0), 0xdc); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 389 | |
| 390 | if (bios_cntl & 1) { |
| 391 | /* BWE is RW, so the SMI was caused by a |
| 392 | * write to BWE, not by a write to the BIOS |
| 393 | */ |
| 394 | |
| 395 | /* This is the place where we notice someone |
| 396 | * is trying to tinker with the BIOS. We are |
| 397 | * trying to be nice and just ignore it. A more |
| 398 | * resolute answer would be to power down the |
| 399 | * box. |
| 400 | */ |
| 401 | printk(BIOS_DEBUG, "Switching back to RO\n"); |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 402 | pci_write_config32(PCI_DEV(0, 0x1f, 0), 0xdc, |
| 403 | (bios_cntl & ~1)); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 404 | } /* No else for now? */ |
| 405 | } else if (tco_sts & (1 << 3)) { /* TIMEOUT */ |
| 406 | /* Handle TCO timeout */ |
| 407 | printk(BIOS_DEBUG, "TCO Timeout.\n"); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 411 | static void southbridge_smi_periodic(void) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 412 | { |
| 413 | u32 reg32; |
| 414 | |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 415 | reg32 = inl(get_pmbase() + SMI_EN); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 416 | |
| 417 | /* Are periodic SMIs enabled? */ |
| 418 | if ((reg32 & PERIODIC_EN) == 0) |
| 419 | return; |
| 420 | |
| 421 | printk(BIOS_DEBUG, "Periodic SMI.\n"); |
| 422 | } |
| 423 | |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 424 | static void southbridge_smi_monitor(void) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 425 | { |
| 426 | #define IOTRAP(x) (trap_sts & (1 << x)) |
| 427 | u32 trap_sts, trap_cycle; |
| 428 | u32 data, mask = 0; |
| 429 | int i; |
| 430 | |
| 431 | trap_sts = RCBA32(0x1e00); // TRSR - Trap Status Register |
| 432 | RCBA32(0x1e00) = trap_sts; // Clear trap(s) in TRSR |
| 433 | |
| 434 | trap_cycle = RCBA32(0x1e10); |
| 435 | for (i=16; i<20; i++) { |
| 436 | if (trap_cycle & (1 << i)) |
| 437 | mask |= (0xff << ((i - 16) << 2)); |
| 438 | } |
| 439 | |
| 440 | |
| 441 | /* IOTRAP(3) SMI function call */ |
| 442 | if (IOTRAP(3)) { |
| 443 | if (gnvs && gnvs->smif) |
| 444 | io_trap_handler(gnvs->smif); // call function smif |
| 445 | return; |
| 446 | } |
| 447 | |
| 448 | /* IOTRAP(2) currently unused |
| 449 | * IOTRAP(1) currently unused */ |
| 450 | |
| 451 | /* IOTRAP(0) SMIC */ |
| 452 | if (IOTRAP(0)) { |
| 453 | if (!(trap_cycle & (1 << 24))) { // It's a write |
| 454 | printk(BIOS_DEBUG, "SMI1 command\n"); |
| 455 | data = RCBA32(0x1e18); |
| 456 | data &= mask; |
| 457 | // if (smi1) |
| 458 | // southbridge_smi_command(data); |
| 459 | // return; |
| 460 | } |
| 461 | // Fall through to debug |
| 462 | } |
| 463 | |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 464 | printk(BIOS_DEBUG, " trapped io address = 0x%x\n", |
| 465 | trap_cycle & 0xfffc); |
| 466 | for (i=0; i < 4; i++) |
| 467 | if(IOTRAP(i)) printk(BIOS_DEBUG, " TRAP = %d\n", i); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 468 | printk(BIOS_DEBUG, " AHBE = %x\n", (trap_cycle >> 16) & 0xf); |
| 469 | printk(BIOS_DEBUG, " MASK = 0x%08x\n", mask); |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 470 | printk(BIOS_DEBUG, " read/write: %s\n", |
| 471 | (trap_cycle & (1 << 24)) ? "read" : "write"); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 472 | |
| 473 | if (!(trap_cycle & (1 << 24))) { |
| 474 | /* Write Cycle */ |
| 475 | data = RCBA32(0x1e18); |
| 476 | printk(BIOS_DEBUG, " iotrap written data = 0x%08x\n", data); |
| 477 | } |
| 478 | #undef IOTRAP |
| 479 | } |
| 480 | |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 481 | typedef void (*smi_handler_t)(void); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 482 | |
| 483 | static smi_handler_t southbridge_smi[32] = { |
| 484 | NULL, // [0] reserved |
| 485 | NULL, // [1] reserved |
| 486 | NULL, // [2] BIOS_STS |
| 487 | NULL, // [3] LEGACY_USB_STS |
| 488 | southbridge_smi_sleep, // [4] SLP_SMI_STS |
| 489 | southbridge_smi_apmc, // [5] APM_STS |
| 490 | NULL, // [6] SWSMI_TMR_STS |
| 491 | NULL, // [7] reserved |
| 492 | southbridge_smi_pm1, // [8] PM1_STS |
| 493 | southbridge_smi_gpe0, // [9] GPE0_STS |
| 494 | southbridge_smi_gpi, // [10] GPI_STS |
| 495 | southbridge_smi_mc, // [11] MCSMI_STS |
| 496 | NULL, // [12] DEVMON_STS |
| 497 | southbridge_smi_tco, // [13] TCO_STS |
| 498 | southbridge_smi_periodic, // [14] PERIODIC_STS |
| 499 | NULL, // [15] SERIRQ_SMI_STS |
| 500 | NULL, // [16] SMBUS_SMI_STS |
| 501 | NULL, // [17] LEGACY_USB2_STS |
| 502 | NULL, // [18] INTEL_USB2_STS |
| 503 | NULL, // [19] reserved |
| 504 | NULL, // [20] PCI_EXP_SMI_STS |
| 505 | southbridge_smi_monitor, // [21] MONITOR_STS |
| 506 | NULL, // [22] reserved |
| 507 | NULL, // [23] reserved |
| 508 | NULL, // [24] reserved |
| 509 | NULL, // [25] EL_SMI_STS |
| 510 | NULL, // [26] SPI_STS |
| 511 | NULL, // [27] reserved |
| 512 | NULL, // [28] reserved |
| 513 | NULL, // [29] reserved |
| 514 | NULL, // [30] reserved |
| 515 | NULL // [31] reserved |
| 516 | }; |
| 517 | |
| 518 | /** |
| 519 | * @brief Interrupt handler for SMI# |
| 520 | * |
| 521 | * @param smm_revision revision of the smm state save map |
| 522 | */ |
| 523 | |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 524 | void southbridge_smi_handler(void) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 525 | { |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 526 | int i; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 527 | u32 smi_sts; |
| 528 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 529 | /* We need to clear the SMI status registers, or we won't see what's |
| 530 | * happening in the following calls. |
| 531 | */ |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 532 | smi_sts = clear_smi_status(); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 533 | |
| 534 | /* Call SMI sub handler for each of the status bits */ |
| 535 | for (i = 0; i < 31; i++) { |
| 536 | if (smi_sts & (1 << i)) { |
| 537 | if (southbridge_smi[i]) { |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 538 | southbridge_smi[i](); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 539 | } else { |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 540 | printk(BIOS_DEBUG, |
| 541 | "SMI_STS[%d] occured, but no " |
| 542 | "handler available.\n", i); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 543 | } |
| 544 | } |
| 545 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 546 | } |