Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 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. |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <types.h> |
| 18 | #include <arch/io.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame^] | 19 | #include <device/pci_ops.h> |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 20 | #include <console/console.h> |
| 21 | #include <cpu/x86/cache.h> |
| 22 | #include <cpu/x86/smm.h> |
| 23 | #include <device/pci_def.h> |
| 24 | #include "i82801dx.h" |
| 25 | |
| 26 | #define DEBUG_SMI |
| 27 | |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 28 | /* I830M */ |
| 29 | #define SMRAM 0x90 |
| 30 | #define D_OPEN (1 << 6) |
| 31 | #define D_CLS (1 << 5) |
| 32 | #define D_LCK (1 << 4) |
| 33 | #define G_SMRANE (1 << 3) |
| 34 | #define C_BASE_SEG ((0 << 2) | (1 << 1) | (0 << 0)) |
| 35 | |
stepan | 836ae29 | 2010-12-08 05:42:47 +0000 | [diff] [blame] | 36 | #include "nvs.h" |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 37 | |
| 38 | /* While we read PMBASE dynamically in case it changed, let's |
| 39 | * initialize it with a sane value |
| 40 | */ |
| 41 | u16 pmbase = PMBASE_ADDR; |
| 42 | u8 smm_initialized = 0; |
| 43 | |
| 44 | unsigned char *mbi = NULL; |
| 45 | u32 mbi_len; |
| 46 | u8 mbi_initialized = 0; |
| 47 | |
| 48 | /* GNVS needs to be updated by an 0xEA PM Trap (B2) after it has been located |
| 49 | * by coreboot. |
| 50 | */ |
| 51 | global_nvs_t *gnvs = (global_nvs_t *)0x0; |
| 52 | void *tcg = (void *)0x0; |
| 53 | void *smi1 = (void *)0x0; |
| 54 | |
| 55 | /** |
| 56 | * @brief read and clear PM1_STS |
| 57 | * @return PM1_STS register |
| 58 | */ |
| 59 | static u16 reset_pm1_status(void) |
| 60 | { |
| 61 | u16 reg16; |
| 62 | |
| 63 | reg16 = inw(pmbase + PM1_STS); |
| 64 | /* set status bits are cleared by writing 1 to them */ |
| 65 | outw(reg16, pmbase + PM1_STS); |
| 66 | |
| 67 | return reg16; |
| 68 | } |
| 69 | |
| 70 | static void dump_pm1_status(u16 pm1_sts) |
| 71 | { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 72 | printk(BIOS_SPEW, "PM1_STS: "); |
| 73 | if (pm1_sts & (1 << 15)) printk(BIOS_SPEW, "WAK "); |
| 74 | if (pm1_sts & (1 << 14)) printk(BIOS_SPEW, "PCIEXPWAK "); |
| 75 | if (pm1_sts & (1 << 11)) printk(BIOS_SPEW, "PRBTNOR "); |
| 76 | if (pm1_sts & (1 << 10)) printk(BIOS_SPEW, "RTC "); |
| 77 | if (pm1_sts & (1 << 8)) printk(BIOS_SPEW, "PWRBTN "); |
| 78 | if (pm1_sts & (1 << 5)) printk(BIOS_SPEW, "GBL "); |
| 79 | if (pm1_sts & (1 << 4)) printk(BIOS_SPEW, "BM "); |
| 80 | if (pm1_sts & (1 << 0)) printk(BIOS_SPEW, "TMROF "); |
| 81 | printk(BIOS_SPEW, "\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 82 | int reg16 = inw(pmbase + PM1_EN); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 83 | printk(BIOS_SPEW, "PM1_EN: %x\n", reg16); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | /** |
| 87 | * @brief read and clear SMI_STS |
| 88 | * @return SMI_STS register |
| 89 | */ |
| 90 | static u32 reset_smi_status(void) |
| 91 | { |
| 92 | u32 reg32; |
| 93 | |
| 94 | reg32 = inl(pmbase + SMI_STS); |
| 95 | /* set status bits are cleared by writing 1 to them */ |
| 96 | outl(reg32, pmbase + SMI_STS); |
| 97 | |
| 98 | return reg32; |
| 99 | } |
| 100 | |
| 101 | static void dump_smi_status(u32 smi_sts) |
| 102 | { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 103 | printk(BIOS_DEBUG, "SMI_STS: "); |
| 104 | if (smi_sts & (1 << 26)) printk(BIOS_DEBUG, "SPI "); |
| 105 | if (smi_sts & (1 << 25)) printk(BIOS_DEBUG, "EL_SMI "); |
| 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"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | |
| 128 | /** |
| 129 | * @brief read and clear GPE0_STS |
| 130 | * @return GPE0_STS register |
| 131 | */ |
| 132 | static 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 | |
| 143 | static void dump_gpe0_status(u32 gpe0_sts) |
| 144 | { |
| 145 | int i; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 146 | printk(BIOS_DEBUG, "GPE0_STS: "); |
Konstantin Aladyshev | 62f8083 | 2013-03-07 04:04:27 +0400 | [diff] [blame] | 147 | for (i=31; i>= 16; i--) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 148 | if (gpe0_sts & (1 << i)) printk(BIOS_DEBUG, "GPIO%d ", (i-16)); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 149 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 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, "EL_SCI/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, "HOT_PLUG "); |
| 163 | if (gpe0_sts & (1 << 0)) printk(BIOS_DEBUG, "THRM "); |
| 164 | printk(BIOS_DEBUG, "\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | |
| 168 | /** |
| 169 | * @brief read and clear TCOx_STS |
| 170 | * @return TCOx_STS registers |
| 171 | */ |
| 172 | static u32 reset_tco_status(void) |
| 173 | { |
| 174 | u32 tcobase = pmbase + 0x60; |
| 175 | u32 reg32; |
| 176 | |
| 177 | reg32 = inl(tcobase + 0x04); |
| 178 | /* set status bits are cleared by writing 1 to them */ |
| 179 | outl(reg32 & ~(1<<18), tcobase + 0x04); // Don't clear BOOT_STS before SECOND_TO_STS |
| 180 | if (reg32 & (1 << 18)) |
| 181 | outl(reg32 & (1<<18), tcobase + 0x04); // clear BOOT_STS |
| 182 | |
| 183 | return reg32; |
| 184 | } |
| 185 | |
| 186 | |
| 187 | static void dump_tco_status(u32 tco_sts) |
| 188 | { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 189 | printk(BIOS_DEBUG, "TCO_STS: "); |
| 190 | if (tco_sts & (1 << 20)) printk(BIOS_DEBUG, "SMLINK_SLV "); |
| 191 | if (tco_sts & (1 << 18)) printk(BIOS_DEBUG, "BOOT "); |
| 192 | if (tco_sts & (1 << 17)) printk(BIOS_DEBUG, "SECOND_TO "); |
| 193 | if (tco_sts & (1 << 16)) printk(BIOS_DEBUG, "INTRD_DET "); |
| 194 | if (tco_sts & (1 << 12)) printk(BIOS_DEBUG, "DMISERR "); |
| 195 | if (tco_sts & (1 << 10)) printk(BIOS_DEBUG, "DMISMI "); |
| 196 | if (tco_sts & (1 << 9)) printk(BIOS_DEBUG, "DMISCI "); |
| 197 | if (tco_sts & (1 << 8)) printk(BIOS_DEBUG, "BIOSWR "); |
| 198 | if (tco_sts & (1 << 7)) printk(BIOS_DEBUG, "NEWCENTURY "); |
| 199 | if (tco_sts & (1 << 3)) printk(BIOS_DEBUG, "TIMEOUT "); |
| 200 | if (tco_sts & (1 << 2)) printk(BIOS_DEBUG, "TCO_INT "); |
| 201 | if (tco_sts & (1 << 1)) printk(BIOS_DEBUG, "SW_TCO "); |
| 202 | if (tco_sts & (1 << 0)) printk(BIOS_DEBUG, "NMI2SMI "); |
| 203 | printk(BIOS_DEBUG, "\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 206 | int southbridge_io_trap_handler(int smif) |
| 207 | { |
| 208 | switch (smif) { |
| 209 | case 0x32: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 210 | printk(BIOS_DEBUG, "OS Init\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 211 | /* gnvs->smif: |
| 212 | * On success, the IO Trap Handler returns 0 |
| 213 | * On failure, the IO Trap Handler returns a value != 0 |
| 214 | */ |
| 215 | gnvs->smif = 0; |
| 216 | return 1; /* IO trap handled */ |
| 217 | } |
| 218 | |
| 219 | /* Not handled */ |
| 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * @brief Set the EOS bit |
| 225 | */ |
| 226 | void southbridge_smi_set_eos(void) |
| 227 | { |
| 228 | u8 reg8; |
| 229 | |
| 230 | reg8 = inb(pmbase + SMI_EN); |
| 231 | reg8 |= EOS; |
| 232 | outb(reg8, pmbase + SMI_EN); |
| 233 | } |
| 234 | |
| 235 | static void busmaster_disable_on_bus(int bus) |
| 236 | { |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 237 | int slot, func; |
| 238 | unsigned int val; |
| 239 | unsigned char hdr; |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 240 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 241 | for (slot = 0; slot < 0x20; slot++) { |
| 242 | for (func = 0; func < 8; func++) { |
| 243 | u32 reg32; |
Antonello Dettori | f9aac2f | 2016-09-03 10:45:33 +0200 | [diff] [blame] | 244 | pci_devfn_t dev = PCI_DEV(bus, slot, func); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 245 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 246 | val = pci_read_config32(dev, PCI_VENDOR_ID); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 247 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 248 | if (val == 0xffffffff || val == 0x00000000 || |
| 249 | val == 0x0000ffff || val == 0xffff0000) |
| 250 | continue; |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 251 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 252 | /* Disable Bus Mastering for this one device */ |
| 253 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 254 | reg32 &= ~PCI_COMMAND_MASTER; |
| 255 | pci_write_config32(dev, PCI_COMMAND, reg32); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 256 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 257 | /* If this is a bridge, then follow it. */ |
| 258 | hdr = pci_read_config8(dev, PCI_HEADER_TYPE); |
| 259 | hdr &= 0x7f; |
| 260 | if (hdr == PCI_HEADER_TYPE_BRIDGE || |
| 261 | hdr == PCI_HEADER_TYPE_CARDBUS) { |
| 262 | unsigned int buses; |
| 263 | buses = pci_read_config32(dev, PCI_PRIMARY_BUS); |
| 264 | busmaster_disable_on_bus((buses >> 8) & 0xff); |
| 265 | } |
| 266 | } |
| 267 | } |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | |
| 271 | static void southbridge_smi_sleep(unsigned int node, smm_state_save_area_t *state_save) |
| 272 | { |
| 273 | u8 reg8; |
| 274 | u32 reg32; |
| 275 | u8 slp_typ; |
| 276 | /* FIXME: the power state on boot should be read from |
| 277 | * CMOS or even better from GNVS. Right now it's hard |
| 278 | * coded at compile time. |
| 279 | */ |
Nico Huber | 9faae2b | 2018-11-14 00:00:35 +0100 | [diff] [blame] | 280 | u8 s5pwr = CONFIG_MAINBOARD_POWER_FAILURE_STATE; |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 281 | |
| 282 | /* First, disable further SMIs */ |
| 283 | reg8 = inb(pmbase + SMI_EN); |
| 284 | reg8 &= ~SLP_SMI_EN; |
| 285 | outb(reg8, pmbase + SMI_EN); |
| 286 | |
| 287 | /* Figure out SLP_TYP */ |
| 288 | reg32 = inl(pmbase + PM1_CNT); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 289 | printk(BIOS_SPEW, "SMI#: SLP = 0x%08x\n", reg32); |
Aaron Durbin | 671909b | 2016-07-13 23:24:36 -0500 | [diff] [blame] | 290 | slp_typ = acpi_sleep_from_pm1(reg32); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 291 | |
| 292 | /* Next, do the deed. |
| 293 | */ |
| 294 | |
| 295 | switch (slp_typ) { |
Aaron Durbin | 671909b | 2016-07-13 23:24:36 -0500 | [diff] [blame] | 296 | case ACPI_S0: printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n"); break; |
| 297 | case ACPI_S1: printk(BIOS_DEBUG, "SMI#: Entering S1 (Assert STPCLK#)\n"); break; |
| 298 | case ACPI_S3: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 299 | printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 300 | /* Invalidate the cache before going to S3 */ |
| 301 | wbinvd(); |
| 302 | break; |
Aaron Durbin | 671909b | 2016-07-13 23:24:36 -0500 | [diff] [blame] | 303 | case ACPI_S4: printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n"); break; |
| 304 | case ACPI_S5: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 305 | printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 306 | |
| 307 | outl(0, pmbase + GPE0_EN); |
| 308 | |
| 309 | /* Should we keep the power state after a power loss? |
| 310 | * In case the setting is "ON" or "OFF" we don't have |
| 311 | * to do anything. But if it's "KEEP" we have to switch |
| 312 | * to "OFF" before entering S5. |
| 313 | */ |
| 314 | if (s5pwr == MAINBOARD_POWER_KEEP) { |
| 315 | reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3); |
| 316 | reg8 |= 1; |
| 317 | pci_write_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3, reg8); |
| 318 | } |
| 319 | |
| 320 | /* also iterates over all bridges on bus 0 */ |
| 321 | busmaster_disable_on_bus(0); |
| 322 | break; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 323 | default: printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n"); break; |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | /* Write back to the SLP register to cause the originally intended |
| 327 | * event again. We need to set BIT13 (SLP_EN) though to make the |
| 328 | * sleep happen. |
| 329 | */ |
| 330 | outl(reg32 | SLP_EN, pmbase + PM1_CNT); |
| 331 | |
| 332 | /* In most sleep states, the code flow of this function ends at |
| 333 | * the line above. However, if we entered sleep state S1 and wake |
| 334 | * up again, we will continue to execute code in this function. |
| 335 | */ |
| 336 | reg32 = inl(pmbase + PM1_CNT); |
| 337 | if (reg32 & SCI_EN) { |
| 338 | /* The OS is not an ACPI OS, so we set the state to S0 */ |
| 339 | reg32 &= ~(SLP_EN | SLP_TYP); |
| 340 | outl(reg32, pmbase + PM1_CNT); |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | static void southbridge_smi_apmc(unsigned int node, smm_state_save_area_t *state_save) |
| 345 | { |
| 346 | u32 pmctrl; |
| 347 | u8 reg8; |
| 348 | |
| 349 | /* Emulate B2 register as the FADT / Linux expects it */ |
| 350 | |
| 351 | reg8 = inb(APM_CNT); |
| 352 | switch (reg8) { |
Sven Schnelle | f4dc1a7 | 2011-06-05 11:33:41 +0200 | [diff] [blame] | 353 | case APM_CNT_CST_CONTROL: |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 354 | /* Calling this function seems to cause |
| 355 | * some kind of race condition in Linux |
| 356 | * and causes a kernel oops |
| 357 | */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 358 | printk(BIOS_DEBUG, "C-state control\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 359 | break; |
Sven Schnelle | f4dc1a7 | 2011-06-05 11:33:41 +0200 | [diff] [blame] | 360 | case APM_CNT_PST_CONTROL: |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 361 | /* Calling this function seems to cause |
| 362 | * some kind of race condition in Linux |
| 363 | * and causes a kernel oops |
| 364 | */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 365 | printk(BIOS_DEBUG, "P-state control\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 366 | break; |
Sven Schnelle | f4dc1a7 | 2011-06-05 11:33:41 +0200 | [diff] [blame] | 367 | case APM_CNT_ACPI_DISABLE: |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 368 | pmctrl = inl(pmbase + PM1_CNT); |
| 369 | pmctrl &= ~SCI_EN; |
| 370 | outl(pmctrl, pmbase + PM1_CNT); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 371 | printk(BIOS_DEBUG, "SMI#: ACPI disabled.\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 372 | break; |
Sven Schnelle | f4dc1a7 | 2011-06-05 11:33:41 +0200 | [diff] [blame] | 373 | case APM_CNT_ACPI_ENABLE: |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 374 | pmctrl = inl(pmbase + PM1_CNT); |
| 375 | pmctrl |= SCI_EN; |
| 376 | outl(pmctrl, pmbase + PM1_CNT); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 377 | printk(BIOS_DEBUG, "SMI#: ACPI enabled.\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 378 | break; |
Sven Schnelle | f4dc1a7 | 2011-06-05 11:33:41 +0200 | [diff] [blame] | 379 | case APM_CNT_GNVS_UPDATE: |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 380 | if (smm_initialized) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 381 | printk(BIOS_DEBUG, "SMI#: SMM structures already initialized!\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 382 | return; |
| 383 | } |
| 384 | gnvs = *(global_nvs_t **)0x500; |
| 385 | tcg = *(void **)0x504; |
| 386 | smi1 = *(void **)0x508; |
| 387 | smm_initialized = 1; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 388 | printk(BIOS_DEBUG, "SMI#: Setting up structures to %p, %p, %p\n", gnvs, tcg, smi1); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 389 | break; |
Sven Schnelle | f4dc1a7 | 2011-06-05 11:33:41 +0200 | [diff] [blame] | 390 | case APM_CNT_MBI_UPDATE: // FIXME |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 391 | if (mbi_initialized) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 392 | printk(BIOS_DEBUG, "SMI#: mbi already registered!\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 393 | return; |
| 394 | } |
| 395 | mbi = *(void **)0x500; |
| 396 | mbi_len = *(u32 *)0x504; |
| 397 | mbi_initialized = 1; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 398 | printk(BIOS_DEBUG, "SMI#: Registered MBI at %p (%d bytes)\n", mbi, mbi_len); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 399 | break; |
| 400 | |
| 401 | default: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 402 | printk(BIOS_DEBUG, "SMI#: Unknown function APM_CNT=%02x\n", reg8); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | |
| 406 | static void southbridge_smi_pm1(unsigned int node, smm_state_save_area_t *state_save) |
| 407 | { |
| 408 | u16 pm1_sts; |
| 409 | |
| 410 | pm1_sts = reset_pm1_status(); |
| 411 | dump_pm1_status(pm1_sts); |
| 412 | |
| 413 | /* While OSPM is not active, poweroff immediately |
| 414 | * on a power button event. |
| 415 | */ |
| 416 | if (pm1_sts & PWRBTN_STS) { |
| 417 | // power button pressed |
| 418 | u32 reg32; |
| 419 | reg32 = (7 << 10) | (1 << 13); |
| 420 | outl(reg32, pmbase + PM1_CNT); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | static void southbridge_smi_gpe0(unsigned int node, smm_state_save_area_t *state_save) |
| 425 | { |
| 426 | u32 gpe0_sts; |
| 427 | |
| 428 | gpe0_sts = reset_gpe0_status(); |
| 429 | dump_gpe0_status(gpe0_sts); |
| 430 | } |
| 431 | |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 432 | static void southbridge_smi_gpi(unsigned int node, smm_state_save_area_t *state_save) |
| 433 | { |
| 434 | u16 reg16; |
| 435 | reg16 = inw(pmbase + ALT_GP_SMI_STS); |
| 436 | outl(reg16, pmbase + ALT_GP_SMI_STS); |
| 437 | |
| 438 | reg16 &= inw(pmbase + ALT_GP_SMI_EN); |
| 439 | |
Kyösti Mälkki | 48b3dbc | 2014-12-29 19:36:50 +0200 | [diff] [blame] | 440 | mainboard_smi_gpi(reg16); |
| 441 | |
| 442 | if (reg16) |
| 443 | printk(BIOS_DEBUG, "GPI (mask %04x)\n",reg16); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | static void southbridge_smi_mc(unsigned int node, smm_state_save_area_t *state_save) |
| 447 | { |
| 448 | u32 reg32; |
| 449 | |
| 450 | reg32 = inl(pmbase + SMI_EN); |
| 451 | |
| 452 | /* Are periodic SMIs enabled? */ |
| 453 | if ((reg32 & MCSMI_EN) == 0) |
| 454 | return; |
| 455 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 456 | printk(BIOS_DEBUG, "Microcontroller SMI.\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | |
| 460 | |
| 461 | static void southbridge_smi_tco(unsigned int node, smm_state_save_area_t *state_save) |
| 462 | { |
| 463 | u32 tco_sts; |
| 464 | |
| 465 | tco_sts = reset_tco_status(); |
| 466 | |
| 467 | /* Any TCO event? */ |
| 468 | if (!tco_sts) |
| 469 | return; |
| 470 | |
| 471 | if (tco_sts & (1 << 8)) { // BIOSWR |
| 472 | u8 bios_cntl; |
| 473 | |
| 474 | bios_cntl = pci_read_config16(PCI_DEV(0, 0x1f, 0), 0xdc); |
| 475 | |
| 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 | */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 487 | printk(BIOS_DEBUG, "Switching back to RO\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 488 | pci_write_config32(PCI_DEV(0, 0x1f, 0), 0xdc, (bios_cntl & ~1)); |
| 489 | } /* No else for now? */ |
| 490 | } else if (tco_sts & (1 << 3)) { /* TIMEOUT */ |
| 491 | /* Handle TCO timeout */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 492 | printk(BIOS_DEBUG, "TCO Timeout.\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 493 | } else if (!tco_sts) { |
| 494 | dump_tco_status(tco_sts); |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | static void southbridge_smi_periodic(unsigned int node, smm_state_save_area_t *state_save) |
| 499 | { |
| 500 | u32 reg32; |
| 501 | |
| 502 | reg32 = inl(pmbase + SMI_EN); |
| 503 | |
| 504 | /* Are periodic SMIs enabled? */ |
| 505 | if ((reg32 & PERIODIC_EN) == 0) |
| 506 | return; |
| 507 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 508 | printk(BIOS_DEBUG, "Periodic SMI.\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | static void southbridge_smi_monitor(unsigned int node, smm_state_save_area_t *state_save) |
| 512 | { |
| 513 | #define IOTRAP(x) (trap_sts & (1 << x)) |
| 514 | #if 0 |
| 515 | u32 trap_sts, trap_cycle; |
| 516 | u32 data, mask = 0; |
| 517 | int i; |
| 518 | |
| 519 | trap_sts = RCBA32(0x1e00); // TRSR - Trap Status Register |
| 520 | RCBA32(0x1e00) = trap_sts; // Clear trap(s) in TRSR |
| 521 | |
| 522 | trap_cycle = RCBA32(0x1e10); |
| 523 | for (i=16; i<20; i++) { |
| 524 | if (trap_cycle & (1 << i)) |
| 525 | mask |= (0xff << ((i - 16) << 2)); |
| 526 | } |
| 527 | |
| 528 | |
| 529 | /* IOTRAP(3) SMI function call */ |
| 530 | if (IOTRAP(3)) { |
| 531 | if (gnvs && gnvs->smif) |
| 532 | io_trap_handler(gnvs->smif); // call function smif |
| 533 | return; |
| 534 | } |
| 535 | |
| 536 | /* IOTRAP(2) currently unused |
| 537 | * IOTRAP(1) currently unused */ |
| 538 | |
| 539 | /* IOTRAP(0) SMIC */ |
| 540 | if (IOTRAP(0)) { |
| 541 | if (!(trap_cycle & (1 << 24))) { // It's a write |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 542 | printk(BIOS_DEBUG, "SMI1 command\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 543 | data = RCBA32(0x1e18); |
| 544 | data &= mask; |
| 545 | // if (smi1) |
Elyes HAOUAS | b0f1988 | 2018-06-09 11:59:00 +0200 | [diff] [blame] | 546 | // southbridge_smi_command(data); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 547 | // return; |
| 548 | } |
| 549 | // Fall through to debug |
| 550 | } |
| 551 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 552 | printk(BIOS_DEBUG, " trapped io address = 0x%x\n", trap_cycle & 0xfffc); |
Elyes HAOUAS | 70d79a4 | 2016-08-21 18:36:06 +0200 | [diff] [blame] | 553 | for (i=0; i < 4; i++) if (IOTRAP(i)) printk(BIOS_DEBUG, " TRAP = %d\n", i); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 554 | printk(BIOS_DEBUG, " AHBE = %x\n", (trap_cycle >> 16) & 0xf); |
| 555 | printk(BIOS_DEBUG, " MASK = 0x%08x\n", mask); |
| 556 | printk(BIOS_DEBUG, " read/write: %s\n", (trap_cycle & (1 << 24)) ? "read" : "write"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 557 | |
| 558 | if (!(trap_cycle & (1 << 24))) { |
| 559 | /* Write Cycle */ |
| 560 | data = RCBA32(0x1e18); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 561 | printk(BIOS_DEBUG, " iotrap written data = 0x%08x\n", data); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 562 | } |
| 563 | #endif |
| 564 | #undef IOTRAP |
| 565 | } |
| 566 | |
Stefan Reinauer | 348a1ba | 2010-03-17 01:51:11 +0000 | [diff] [blame] | 567 | typedef void (*smi_handler_t)(unsigned int node, |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 568 | smm_state_save_area_t *state_save); |
| 569 | |
Stefan Reinauer | 348a1ba | 2010-03-17 01:51:11 +0000 | [diff] [blame] | 570 | smi_handler_t southbridge_smi[32] = { |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 571 | NULL, // [0] reserved |
| 572 | NULL, // [1] reserved |
| 573 | NULL, // [2] BIOS_STS |
| 574 | NULL, // [3] LEGACY_USB_STS |
| 575 | southbridge_smi_sleep, // [4] SLP_SMI_STS |
| 576 | southbridge_smi_apmc, // [5] APM_STS |
| 577 | NULL, // [6] SWSMI_TMR_STS |
| 578 | NULL, // [7] reserved |
| 579 | southbridge_smi_pm1, // [8] PM1_STS |
| 580 | southbridge_smi_gpe0, // [9] GPE0_STS |
| 581 | southbridge_smi_gpi, // [10] GPI_STS |
| 582 | southbridge_smi_mc, // [11] MCSMI_STS |
| 583 | NULL, // [12] DEVMON_STS |
| 584 | southbridge_smi_tco, // [13] TCO_STS |
| 585 | southbridge_smi_periodic, // [14] PERIODIC_STS |
| 586 | NULL, // [15] SERIRQ_SMI_STS |
| 587 | NULL, // [16] SMBUS_SMI_STS |
| 588 | NULL, // [17] LEGACY_USB2_STS |
| 589 | NULL, // [18] INTEL_USB2_STS |
| 590 | NULL, // [19] reserved |
| 591 | NULL, // [20] PCI_EXP_SMI_STS |
| 592 | southbridge_smi_monitor, // [21] MONITOR_STS |
| 593 | NULL, // [22] reserved |
| 594 | NULL, // [23] reserved |
| 595 | NULL, // [24] reserved |
| 596 | NULL, // [25] EL_SMI_STS |
| 597 | NULL, // [26] SPI_STS |
| 598 | NULL, // [27] reserved |
| 599 | NULL, // [28] reserved |
| 600 | NULL, // [29] reserved |
| 601 | NULL, // [30] reserved |
| 602 | NULL // [31] reserved |
| 603 | }; |
| 604 | |
| 605 | /** |
| 606 | * @brief Interrupt handler for SMI# |
Martin Roth | 182e551f | 2014-12-29 22:29:08 -0700 | [diff] [blame] | 607 | * @param node |
| 608 | * @param state_save |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 609 | */ |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 610 | void southbridge_smi_handler(unsigned int node, smm_state_save_area_t *state_save) |
| 611 | { |
| 612 | int i, dump = 0; |
| 613 | u32 smi_sts; |
| 614 | |
| 615 | /* Update global variable pmbase */ |
| 616 | pmbase = pci_read_config16(PCI_DEV(0, 0x1f, 0), 0x40) & 0xfffc; |
| 617 | |
| 618 | /* We need to clear the SMI status registers, or we won't see what's |
| 619 | * happening in the following calls. |
| 620 | */ |
| 621 | smi_sts = reset_smi_status(); |
| 622 | |
| 623 | /* Filter all non-enabled SMI events */ |
| 624 | // FIXME Double check, this clears MONITOR |
| 625 | // smi_sts &= inl(pmbase + SMI_EN); |
| 626 | |
| 627 | /* Call SMI sub handler for each of the status bits */ |
| 628 | for (i = 0; i < 31; i++) { |
| 629 | if (smi_sts & (1 << i)) { |
| 630 | if (southbridge_smi[i]) |
| 631 | southbridge_smi[i](node, state_save); |
| 632 | else { |
Martin Roth | 2ed0aa2 | 2016-01-05 20:58:58 -0700 | [diff] [blame] | 633 | printk(BIOS_DEBUG, "SMI_STS[%d] occurred, but no " |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 634 | "handler available.\n", i); |
| 635 | dump = 1; |
| 636 | } |
| 637 | } |
| 638 | } |
| 639 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 640 | if (dump) { |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 641 | dump_smi_status(smi_sts); |
| 642 | } |
| 643 | |
| 644 | } |