Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 2 | |
| 3 | #include <types.h> |
| 4 | #include <arch/io.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 5 | #include <device/pci_ops.h> |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 6 | #include <console/console.h> |
| 7 | #include <cpu/x86/cache.h> |
| 8 | #include <cpu/x86/smm.h> |
| 9 | #include <device/pci_def.h> |
| 10 | #include "i82801dx.h" |
| 11 | |
| 12 | #define DEBUG_SMI |
| 13 | |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 14 | /* I830M */ |
| 15 | #define SMRAM 0x90 |
| 16 | #define D_OPEN (1 << 6) |
| 17 | #define D_CLS (1 << 5) |
| 18 | #define D_LCK (1 << 4) |
| 19 | #define G_SMRANE (1 << 3) |
| 20 | #define C_BASE_SEG ((0 << 2) | (1 << 1) | (0 << 0)) |
| 21 | |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 22 | /* While we read PMBASE dynamically in case it changed, let's |
| 23 | * initialize it with a sane value |
| 24 | */ |
| 25 | u16 pmbase = PMBASE_ADDR; |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 26 | |
| 27 | unsigned char *mbi = NULL; |
| 28 | u32 mbi_len; |
| 29 | u8 mbi_initialized = 0; |
| 30 | |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 31 | /** |
| 32 | * @brief read and clear PM1_STS |
| 33 | * @return PM1_STS register |
| 34 | */ |
| 35 | static u16 reset_pm1_status(void) |
| 36 | { |
| 37 | u16 reg16; |
| 38 | |
| 39 | reg16 = inw(pmbase + PM1_STS); |
| 40 | /* set status bits are cleared by writing 1 to them */ |
| 41 | outw(reg16, pmbase + PM1_STS); |
| 42 | |
| 43 | return reg16; |
| 44 | } |
| 45 | |
| 46 | static void dump_pm1_status(u16 pm1_sts) |
| 47 | { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 48 | printk(BIOS_SPEW, "PM1_STS: "); |
| 49 | if (pm1_sts & (1 << 15)) printk(BIOS_SPEW, "WAK "); |
| 50 | if (pm1_sts & (1 << 14)) printk(BIOS_SPEW, "PCIEXPWAK "); |
| 51 | if (pm1_sts & (1 << 11)) printk(BIOS_SPEW, "PRBTNOR "); |
| 52 | if (pm1_sts & (1 << 10)) printk(BIOS_SPEW, "RTC "); |
| 53 | if (pm1_sts & (1 << 8)) printk(BIOS_SPEW, "PWRBTN "); |
| 54 | if (pm1_sts & (1 << 5)) printk(BIOS_SPEW, "GBL "); |
| 55 | if (pm1_sts & (1 << 4)) printk(BIOS_SPEW, "BM "); |
| 56 | if (pm1_sts & (1 << 0)) printk(BIOS_SPEW, "TMROF "); |
| 57 | printk(BIOS_SPEW, "\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 58 | int reg16 = inw(pmbase + PM1_EN); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 59 | printk(BIOS_SPEW, "PM1_EN: %x\n", reg16); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @brief read and clear SMI_STS |
| 64 | * @return SMI_STS register |
| 65 | */ |
| 66 | static u32 reset_smi_status(void) |
| 67 | { |
| 68 | u32 reg32; |
| 69 | |
| 70 | reg32 = inl(pmbase + SMI_STS); |
| 71 | /* set status bits are cleared by writing 1 to them */ |
| 72 | outl(reg32, pmbase + SMI_STS); |
| 73 | |
| 74 | return reg32; |
| 75 | } |
| 76 | |
| 77 | static void dump_smi_status(u32 smi_sts) |
| 78 | { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 79 | printk(BIOS_DEBUG, "SMI_STS: "); |
| 80 | if (smi_sts & (1 << 26)) printk(BIOS_DEBUG, "SPI "); |
| 81 | if (smi_sts & (1 << 25)) printk(BIOS_DEBUG, "EL_SMI "); |
| 82 | if (smi_sts & (1 << 21)) printk(BIOS_DEBUG, "MONITOR "); |
| 83 | if (smi_sts & (1 << 20)) printk(BIOS_DEBUG, "PCI_EXP_SMI "); |
| 84 | if (smi_sts & (1 << 18)) printk(BIOS_DEBUG, "INTEL_USB2 "); |
| 85 | if (smi_sts & (1 << 17)) printk(BIOS_DEBUG, "LEGACY_USB2 "); |
| 86 | if (smi_sts & (1 << 16)) printk(BIOS_DEBUG, "SMBUS_SMI "); |
| 87 | if (smi_sts & (1 << 15)) printk(BIOS_DEBUG, "SERIRQ_SMI "); |
| 88 | if (smi_sts & (1 << 14)) printk(BIOS_DEBUG, "PERIODIC "); |
| 89 | if (smi_sts & (1 << 13)) printk(BIOS_DEBUG, "TCO "); |
| 90 | if (smi_sts & (1 << 12)) printk(BIOS_DEBUG, "DEVMON "); |
| 91 | if (smi_sts & (1 << 11)) printk(BIOS_DEBUG, "MCSMI "); |
| 92 | if (smi_sts & (1 << 10)) printk(BIOS_DEBUG, "GPI "); |
| 93 | if (smi_sts & (1 << 9)) printk(BIOS_DEBUG, "GPE0 "); |
| 94 | if (smi_sts & (1 << 8)) printk(BIOS_DEBUG, "PM1 "); |
| 95 | if (smi_sts & (1 << 6)) printk(BIOS_DEBUG, "SWSMI_TMR "); |
| 96 | if (smi_sts & (1 << 5)) printk(BIOS_DEBUG, "APM "); |
| 97 | if (smi_sts & (1 << 4)) printk(BIOS_DEBUG, "SLP_SMI "); |
| 98 | if (smi_sts & (1 << 3)) printk(BIOS_DEBUG, "LEGACY_USB "); |
| 99 | if (smi_sts & (1 << 2)) printk(BIOS_DEBUG, "BIOS "); |
| 100 | printk(BIOS_DEBUG, "\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | |
| 104 | /** |
| 105 | * @brief read and clear GPE0_STS |
| 106 | * @return GPE0_STS register |
| 107 | */ |
| 108 | static u32 reset_gpe0_status(void) |
| 109 | { |
| 110 | u32 reg32; |
| 111 | |
| 112 | reg32 = inl(pmbase + GPE0_STS); |
| 113 | /* set status bits are cleared by writing 1 to them */ |
| 114 | outl(reg32, pmbase + GPE0_STS); |
| 115 | |
| 116 | return reg32; |
| 117 | } |
| 118 | |
| 119 | static void dump_gpe0_status(u32 gpe0_sts) |
| 120 | { |
| 121 | int i; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 122 | printk(BIOS_DEBUG, "GPE0_STS: "); |
Konstantin Aladyshev | 62f8083 | 2013-03-07 04:04:27 +0400 | [diff] [blame] | 123 | for (i=31; i>= 16; i--) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 124 | if (gpe0_sts & (1 << i)) printk(BIOS_DEBUG, "GPIO%d ", (i-16)); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 125 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 126 | if (gpe0_sts & (1 << 14)) printk(BIOS_DEBUG, "USB4 "); |
| 127 | if (gpe0_sts & (1 << 13)) printk(BIOS_DEBUG, "PME_B0 "); |
| 128 | if (gpe0_sts & (1 << 12)) printk(BIOS_DEBUG, "USB3 "); |
| 129 | if (gpe0_sts & (1 << 11)) printk(BIOS_DEBUG, "PME "); |
| 130 | if (gpe0_sts & (1 << 10)) printk(BIOS_DEBUG, "EL_SCI/BATLOW "); |
| 131 | if (gpe0_sts & (1 << 9)) printk(BIOS_DEBUG, "PCI_EXP "); |
| 132 | if (gpe0_sts & (1 << 8)) printk(BIOS_DEBUG, "RI "); |
| 133 | if (gpe0_sts & (1 << 7)) printk(BIOS_DEBUG, "SMB_WAK "); |
| 134 | if (gpe0_sts & (1 << 6)) printk(BIOS_DEBUG, "TCO_SCI "); |
| 135 | if (gpe0_sts & (1 << 5)) printk(BIOS_DEBUG, "AC97 "); |
| 136 | if (gpe0_sts & (1 << 4)) printk(BIOS_DEBUG, "USB2 "); |
| 137 | if (gpe0_sts & (1 << 3)) printk(BIOS_DEBUG, "USB1 "); |
| 138 | if (gpe0_sts & (1 << 2)) printk(BIOS_DEBUG, "HOT_PLUG "); |
| 139 | if (gpe0_sts & (1 << 0)) printk(BIOS_DEBUG, "THRM "); |
| 140 | printk(BIOS_DEBUG, "\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | |
| 144 | /** |
| 145 | * @brief read and clear TCOx_STS |
| 146 | * @return TCOx_STS registers |
| 147 | */ |
| 148 | static u32 reset_tco_status(void) |
| 149 | { |
| 150 | u32 tcobase = pmbase + 0x60; |
| 151 | u32 reg32; |
| 152 | |
| 153 | reg32 = inl(tcobase + 0x04); |
| 154 | /* set status bits are cleared by writing 1 to them */ |
| 155 | outl(reg32 & ~(1<<18), tcobase + 0x04); // Don't clear BOOT_STS before SECOND_TO_STS |
| 156 | if (reg32 & (1 << 18)) |
| 157 | outl(reg32 & (1<<18), tcobase + 0x04); // clear BOOT_STS |
| 158 | |
| 159 | return reg32; |
| 160 | } |
| 161 | |
| 162 | |
| 163 | static void dump_tco_status(u32 tco_sts) |
| 164 | { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 165 | printk(BIOS_DEBUG, "TCO_STS: "); |
| 166 | if (tco_sts & (1 << 20)) printk(BIOS_DEBUG, "SMLINK_SLV "); |
| 167 | if (tco_sts & (1 << 18)) printk(BIOS_DEBUG, "BOOT "); |
| 168 | if (tco_sts & (1 << 17)) printk(BIOS_DEBUG, "SECOND_TO "); |
| 169 | if (tco_sts & (1 << 16)) printk(BIOS_DEBUG, "INTRD_DET "); |
| 170 | if (tco_sts & (1 << 12)) printk(BIOS_DEBUG, "DMISERR "); |
| 171 | if (tco_sts & (1 << 10)) printk(BIOS_DEBUG, "DMISMI "); |
| 172 | if (tco_sts & (1 << 9)) printk(BIOS_DEBUG, "DMISCI "); |
| 173 | if (tco_sts & (1 << 8)) printk(BIOS_DEBUG, "BIOSWR "); |
| 174 | if (tco_sts & (1 << 7)) printk(BIOS_DEBUG, "NEWCENTURY "); |
| 175 | if (tco_sts & (1 << 3)) printk(BIOS_DEBUG, "TIMEOUT "); |
| 176 | if (tco_sts & (1 << 2)) printk(BIOS_DEBUG, "TCO_INT "); |
| 177 | if (tco_sts & (1 << 1)) printk(BIOS_DEBUG, "SW_TCO "); |
| 178 | if (tco_sts & (1 << 0)) printk(BIOS_DEBUG, "NMI2SMI "); |
| 179 | printk(BIOS_DEBUG, "\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 182 | /** |
| 183 | * @brief Set the EOS bit |
| 184 | */ |
| 185 | void southbridge_smi_set_eos(void) |
| 186 | { |
| 187 | u8 reg8; |
| 188 | |
| 189 | reg8 = inb(pmbase + SMI_EN); |
| 190 | reg8 |= EOS; |
| 191 | outb(reg8, pmbase + SMI_EN); |
| 192 | } |
| 193 | |
| 194 | static void busmaster_disable_on_bus(int bus) |
| 195 | { |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 196 | int slot, func; |
| 197 | unsigned int val; |
| 198 | unsigned char hdr; |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 199 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 200 | for (slot = 0; slot < 0x20; slot++) { |
| 201 | for (func = 0; func < 8; func++) { |
Elyes HAOUAS | 2f2191a | 2020-04-28 19:59:30 +0200 | [diff] [blame] | 202 | u16 reg16; |
Antonello Dettori | f9aac2f | 2016-09-03 10:45:33 +0200 | [diff] [blame] | 203 | pci_devfn_t dev = PCI_DEV(bus, slot, func); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 204 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 205 | val = pci_read_config32(dev, PCI_VENDOR_ID); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 206 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 207 | if (val == 0xffffffff || val == 0x00000000 || |
| 208 | val == 0x0000ffff || val == 0xffff0000) |
| 209 | continue; |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 210 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 211 | /* Disable Bus Mastering for this one device */ |
Elyes HAOUAS | 2f2191a | 2020-04-28 19:59:30 +0200 | [diff] [blame] | 212 | reg16 = pci_read_config16(dev, PCI_COMMAND); |
| 213 | reg16 &= ~PCI_COMMAND_MASTER; |
| 214 | pci_write_config16(dev, PCI_COMMAND, reg16); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 215 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 216 | /* If this is a bridge, then follow it. */ |
| 217 | hdr = pci_read_config8(dev, PCI_HEADER_TYPE); |
| 218 | hdr &= 0x7f; |
| 219 | if (hdr == PCI_HEADER_TYPE_BRIDGE || |
| 220 | hdr == PCI_HEADER_TYPE_CARDBUS) { |
| 221 | unsigned int buses; |
| 222 | buses = pci_read_config32(dev, PCI_PRIMARY_BUS); |
| 223 | busmaster_disable_on_bus((buses >> 8) & 0xff); |
| 224 | } |
| 225 | } |
| 226 | } |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | |
Kyösti Mälkki | b987282 | 2019-08-10 15:47:29 +0300 | [diff] [blame] | 230 | static void southbridge_smi_sleep(void) |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 231 | { |
| 232 | u8 reg8; |
| 233 | u32 reg32; |
| 234 | u8 slp_typ; |
| 235 | /* FIXME: the power state on boot should be read from |
| 236 | * CMOS or even better from GNVS. Right now it's hard |
| 237 | * coded at compile time. |
| 238 | */ |
Nico Huber | 9faae2b | 2018-11-14 00:00:35 +0100 | [diff] [blame] | 239 | u8 s5pwr = CONFIG_MAINBOARD_POWER_FAILURE_STATE; |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 240 | |
| 241 | /* First, disable further SMIs */ |
| 242 | reg8 = inb(pmbase + SMI_EN); |
| 243 | reg8 &= ~SLP_SMI_EN; |
| 244 | outb(reg8, pmbase + SMI_EN); |
| 245 | |
| 246 | /* Figure out SLP_TYP */ |
| 247 | reg32 = inl(pmbase + PM1_CNT); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 248 | printk(BIOS_SPEW, "SMI#: SLP = 0x%08x\n", reg32); |
Aaron Durbin | 671909b | 2016-07-13 23:24:36 -0500 | [diff] [blame] | 249 | slp_typ = acpi_sleep_from_pm1(reg32); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 250 | |
| 251 | /* Next, do the deed. |
| 252 | */ |
| 253 | |
| 254 | switch (slp_typ) { |
Aaron Durbin | 671909b | 2016-07-13 23:24:36 -0500 | [diff] [blame] | 255 | case ACPI_S0: printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n"); break; |
| 256 | case ACPI_S1: printk(BIOS_DEBUG, "SMI#: Entering S1 (Assert STPCLK#)\n"); break; |
| 257 | case ACPI_S3: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 258 | printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 259 | /* Invalidate the cache before going to S3 */ |
| 260 | wbinvd(); |
| 261 | break; |
Aaron Durbin | 671909b | 2016-07-13 23:24:36 -0500 | [diff] [blame] | 262 | case ACPI_S4: printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n"); break; |
| 263 | case ACPI_S5: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 264 | printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 265 | |
| 266 | outl(0, pmbase + GPE0_EN); |
| 267 | |
| 268 | /* Should we keep the power state after a power loss? |
| 269 | * In case the setting is "ON" or "OFF" we don't have |
| 270 | * to do anything. But if it's "KEEP" we have to switch |
| 271 | * to "OFF" before entering S5. |
| 272 | */ |
| 273 | if (s5pwr == MAINBOARD_POWER_KEEP) { |
| 274 | reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3); |
| 275 | reg8 |= 1; |
| 276 | pci_write_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3, reg8); |
| 277 | } |
| 278 | |
| 279 | /* also iterates over all bridges on bus 0 */ |
| 280 | busmaster_disable_on_bus(0); |
| 281 | break; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 282 | default: printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n"); break; |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | /* Write back to the SLP register to cause the originally intended |
| 286 | * event again. We need to set BIT13 (SLP_EN) though to make the |
| 287 | * sleep happen. |
| 288 | */ |
| 289 | outl(reg32 | SLP_EN, pmbase + PM1_CNT); |
| 290 | |
| 291 | /* In most sleep states, the code flow of this function ends at |
| 292 | * the line above. However, if we entered sleep state S1 and wake |
| 293 | * up again, we will continue to execute code in this function. |
| 294 | */ |
| 295 | reg32 = inl(pmbase + PM1_CNT); |
| 296 | if (reg32 & SCI_EN) { |
| 297 | /* The OS is not an ACPI OS, so we set the state to S0 */ |
| 298 | reg32 &= ~(SLP_EN | SLP_TYP); |
| 299 | outl(reg32, pmbase + PM1_CNT); |
| 300 | } |
| 301 | } |
| 302 | |
Kyösti Mälkki | b987282 | 2019-08-10 15:47:29 +0300 | [diff] [blame] | 303 | static void southbridge_smi_apmc(void) |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 304 | { |
| 305 | u32 pmctrl; |
| 306 | u8 reg8; |
| 307 | |
| 308 | /* Emulate B2 register as the FADT / Linux expects it */ |
| 309 | |
| 310 | reg8 = inb(APM_CNT); |
| 311 | switch (reg8) { |
Sven Schnelle | f4dc1a7 | 2011-06-05 11:33:41 +0200 | [diff] [blame] | 312 | case APM_CNT_CST_CONTROL: |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 313 | /* Calling this function seems to cause |
| 314 | * some kind of race condition in Linux |
| 315 | * and causes a kernel oops |
| 316 | */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 317 | printk(BIOS_DEBUG, "C-state control\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 318 | break; |
Sven Schnelle | f4dc1a7 | 2011-06-05 11:33:41 +0200 | [diff] [blame] | 319 | case APM_CNT_PST_CONTROL: |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 320 | /* Calling this function seems to cause |
| 321 | * some kind of race condition in Linux |
| 322 | * and causes a kernel oops |
| 323 | */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 324 | printk(BIOS_DEBUG, "P-state control\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 325 | break; |
Sven Schnelle | f4dc1a7 | 2011-06-05 11:33:41 +0200 | [diff] [blame] | 326 | case APM_CNT_ACPI_DISABLE: |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 327 | pmctrl = inl(pmbase + PM1_CNT); |
| 328 | pmctrl &= ~SCI_EN; |
| 329 | outl(pmctrl, pmbase + PM1_CNT); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 330 | printk(BIOS_DEBUG, "SMI#: ACPI disabled.\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 331 | break; |
Sven Schnelle | f4dc1a7 | 2011-06-05 11:33:41 +0200 | [diff] [blame] | 332 | case APM_CNT_ACPI_ENABLE: |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 333 | pmctrl = inl(pmbase + PM1_CNT); |
| 334 | pmctrl |= SCI_EN; |
| 335 | outl(pmctrl, pmbase + PM1_CNT); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 336 | printk(BIOS_DEBUG, "SMI#: ACPI enabled.\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 337 | break; |
Sven Schnelle | f4dc1a7 | 2011-06-05 11:33:41 +0200 | [diff] [blame] | 338 | case APM_CNT_MBI_UPDATE: // FIXME |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 339 | if (mbi_initialized) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 340 | printk(BIOS_DEBUG, "SMI#: mbi already registered!\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 341 | return; |
| 342 | } |
| 343 | mbi = *(void **)0x500; |
| 344 | mbi_len = *(u32 *)0x504; |
| 345 | mbi_initialized = 1; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 346 | 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] | 347 | break; |
| 348 | |
| 349 | default: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 350 | printk(BIOS_DEBUG, "SMI#: Unknown function APM_CNT=%02x\n", reg8); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
Kyösti Mälkki | b987282 | 2019-08-10 15:47:29 +0300 | [diff] [blame] | 354 | static void southbridge_smi_pm1(void) |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 355 | { |
| 356 | u16 pm1_sts; |
| 357 | |
| 358 | pm1_sts = reset_pm1_status(); |
| 359 | dump_pm1_status(pm1_sts); |
| 360 | |
| 361 | /* While OSPM is not active, poweroff immediately |
| 362 | * on a power button event. |
| 363 | */ |
| 364 | if (pm1_sts & PWRBTN_STS) { |
| 365 | // power button pressed |
| 366 | u32 reg32; |
| 367 | reg32 = (7 << 10) | (1 << 13); |
| 368 | outl(reg32, pmbase + PM1_CNT); |
| 369 | } |
| 370 | } |
| 371 | |
Kyösti Mälkki | b987282 | 2019-08-10 15:47:29 +0300 | [diff] [blame] | 372 | static void southbridge_smi_gpe0(void) |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 373 | { |
| 374 | u32 gpe0_sts; |
| 375 | |
| 376 | gpe0_sts = reset_gpe0_status(); |
| 377 | dump_gpe0_status(gpe0_sts); |
| 378 | } |
| 379 | |
Kyösti Mälkki | b987282 | 2019-08-10 15:47:29 +0300 | [diff] [blame] | 380 | static void southbridge_smi_gpi(void) |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 381 | { |
| 382 | u16 reg16; |
| 383 | reg16 = inw(pmbase + ALT_GP_SMI_STS); |
| 384 | outl(reg16, pmbase + ALT_GP_SMI_STS); |
| 385 | |
| 386 | reg16 &= inw(pmbase + ALT_GP_SMI_EN); |
| 387 | |
Kyösti Mälkki | 48b3dbc | 2014-12-29 19:36:50 +0200 | [diff] [blame] | 388 | mainboard_smi_gpi(reg16); |
| 389 | |
| 390 | if (reg16) |
| 391 | printk(BIOS_DEBUG, "GPI (mask %04x)\n",reg16); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 392 | } |
| 393 | |
Kyösti Mälkki | b987282 | 2019-08-10 15:47:29 +0300 | [diff] [blame] | 394 | static void southbridge_smi_mc(void) |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 395 | { |
| 396 | u32 reg32; |
| 397 | |
| 398 | reg32 = inl(pmbase + SMI_EN); |
| 399 | |
| 400 | /* Are periodic SMIs enabled? */ |
| 401 | if ((reg32 & MCSMI_EN) == 0) |
| 402 | return; |
| 403 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 404 | printk(BIOS_DEBUG, "Microcontroller SMI.\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | |
| 408 | |
Kyösti Mälkki | b987282 | 2019-08-10 15:47:29 +0300 | [diff] [blame] | 409 | static void southbridge_smi_tco(void) |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 410 | { |
| 411 | u32 tco_sts; |
| 412 | |
| 413 | tco_sts = reset_tco_status(); |
| 414 | |
| 415 | /* Any TCO event? */ |
| 416 | if (!tco_sts) |
| 417 | return; |
| 418 | |
| 419 | if (tco_sts & (1 << 8)) { // BIOSWR |
| 420 | u8 bios_cntl; |
| 421 | |
| 422 | bios_cntl = pci_read_config16(PCI_DEV(0, 0x1f, 0), 0xdc); |
| 423 | |
| 424 | if (bios_cntl & 1) { |
| 425 | /* BWE is RW, so the SMI was caused by a |
| 426 | * write to BWE, not by a write to the BIOS |
| 427 | */ |
| 428 | |
| 429 | /* This is the place where we notice someone |
| 430 | * is trying to tinker with the BIOS. We are |
| 431 | * trying to be nice and just ignore it. A more |
| 432 | * resolute answer would be to power down the |
| 433 | * box. |
| 434 | */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 435 | printk(BIOS_DEBUG, "Switching back to RO\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 436 | pci_write_config32(PCI_DEV(0, 0x1f, 0), 0xdc, (bios_cntl & ~1)); |
| 437 | } /* No else for now? */ |
| 438 | } else if (tco_sts & (1 << 3)) { /* TIMEOUT */ |
| 439 | /* Handle TCO timeout */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 440 | printk(BIOS_DEBUG, "TCO Timeout.\n"); |
Jacob Garber | 7eb8eed | 2019-04-03 09:18:32 -0600 | [diff] [blame] | 441 | } else { |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 442 | dump_tco_status(tco_sts); |
| 443 | } |
| 444 | } |
| 445 | |
Kyösti Mälkki | b987282 | 2019-08-10 15:47:29 +0300 | [diff] [blame] | 446 | static void southbridge_smi_periodic(void) |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 447 | { |
| 448 | u32 reg32; |
| 449 | |
| 450 | reg32 = inl(pmbase + SMI_EN); |
| 451 | |
| 452 | /* Are periodic SMIs enabled? */ |
| 453 | if ((reg32 & PERIODIC_EN) == 0) |
| 454 | return; |
| 455 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 456 | printk(BIOS_DEBUG, "Periodic SMI.\n"); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 457 | } |
| 458 | |
Kyösti Mälkki | b987282 | 2019-08-10 15:47:29 +0300 | [diff] [blame] | 459 | typedef void (*smi_handler_t)(void); |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 460 | |
Stefan Reinauer | 348a1ba | 2010-03-17 01:51:11 +0000 | [diff] [blame] | 461 | smi_handler_t southbridge_smi[32] = { |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 462 | NULL, // [0] reserved |
| 463 | NULL, // [1] reserved |
| 464 | NULL, // [2] BIOS_STS |
| 465 | NULL, // [3] LEGACY_USB_STS |
| 466 | southbridge_smi_sleep, // [4] SLP_SMI_STS |
| 467 | southbridge_smi_apmc, // [5] APM_STS |
| 468 | NULL, // [6] SWSMI_TMR_STS |
| 469 | NULL, // [7] reserved |
| 470 | southbridge_smi_pm1, // [8] PM1_STS |
| 471 | southbridge_smi_gpe0, // [9] GPE0_STS |
| 472 | southbridge_smi_gpi, // [10] GPI_STS |
| 473 | southbridge_smi_mc, // [11] MCSMI_STS |
| 474 | NULL, // [12] DEVMON_STS |
| 475 | southbridge_smi_tco, // [13] TCO_STS |
| 476 | southbridge_smi_periodic, // [14] PERIODIC_STS |
| 477 | NULL, // [15] SERIRQ_SMI_STS |
| 478 | NULL, // [16] SMBUS_SMI_STS |
| 479 | NULL, // [17] LEGACY_USB2_STS |
| 480 | NULL, // [18] INTEL_USB2_STS |
| 481 | NULL, // [19] reserved |
| 482 | NULL, // [20] PCI_EXP_SMI_STS |
Kyösti Mälkki | f4617c0 | 2020-06-28 17:46:39 +0300 | [diff] [blame^] | 483 | NULL, // [21] MONITOR_STS |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 484 | NULL, // [22] reserved |
| 485 | NULL, // [23] reserved |
| 486 | NULL, // [24] reserved |
| 487 | NULL, // [25] EL_SMI_STS |
| 488 | NULL, // [26] SPI_STS |
| 489 | NULL, // [27] reserved |
| 490 | NULL, // [28] reserved |
| 491 | NULL, // [29] reserved |
| 492 | NULL, // [30] reserved |
| 493 | NULL // [31] reserved |
| 494 | }; |
| 495 | |
| 496 | /** |
| 497 | * @brief Interrupt handler for SMI# |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 498 | */ |
Kyösti Mälkki | 1ef039b | 2019-08-10 15:32:03 +0300 | [diff] [blame] | 499 | void southbridge_smi_handler(void) |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 500 | { |
| 501 | int i, dump = 0; |
| 502 | u32 smi_sts; |
| 503 | |
| 504 | /* Update global variable pmbase */ |
| 505 | pmbase = pci_read_config16(PCI_DEV(0, 0x1f, 0), 0x40) & 0xfffc; |
| 506 | |
| 507 | /* We need to clear the SMI status registers, or we won't see what's |
| 508 | * happening in the following calls. |
| 509 | */ |
| 510 | smi_sts = reset_smi_status(); |
| 511 | |
| 512 | /* Filter all non-enabled SMI events */ |
| 513 | // FIXME Double check, this clears MONITOR |
| 514 | // smi_sts &= inl(pmbase + SMI_EN); |
| 515 | |
| 516 | /* Call SMI sub handler for each of the status bits */ |
| 517 | for (i = 0; i < 31; i++) { |
| 518 | if (smi_sts & (1 << i)) { |
Kyösti Mälkki | b987282 | 2019-08-10 15:47:29 +0300 | [diff] [blame] | 519 | if (southbridge_smi[i]) { |
| 520 | southbridge_smi[i](); |
| 521 | } else { |
Martin Roth | 2ed0aa2 | 2016-01-05 20:58:58 -0700 | [diff] [blame] | 522 | printk(BIOS_DEBUG, "SMI_STS[%d] occurred, but no " |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 523 | "handler available.\n", i); |
| 524 | dump = 1; |
| 525 | } |
| 526 | } |
| 527 | } |
| 528 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 529 | if (dump) { |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 530 | dump_smi_status(smi_sts); |
| 531 | } |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 532 | } |