Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 5 | * Copyright (C) 2014 Google Inc. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of 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. |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <delay.h> |
| 18 | #include <types.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 19 | #include <arch/io.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 20 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 21 | #include <device/pci_ops.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 22 | #include <console/console.h> |
| 23 | #include <cpu/x86/cache.h> |
| 24 | #include <device/pci_def.h> |
| 25 | #include <cpu/x86/smm.h> |
| 26 | #include <spi-generic.h> |
| 27 | #include <elog.h> |
Patrick Georgi | 546953c | 2014-11-29 10:38:17 +0100 | [diff] [blame] | 28 | #include <halt.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 29 | #include <pc80/mc146818rtc.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 30 | #include <soc/lpc.h> |
| 31 | #include <soc/nvs.h> |
| 32 | #include <soc/pci_devs.h> |
| 33 | #include <soc/pm.h> |
| 34 | #include <soc/rcba.h> |
| 35 | #include <soc/smm.h> |
| 36 | #include <soc/xhci.h> |
Duncan Laurie | f3e0a13 | 2015-01-14 17:33:00 -0800 | [diff] [blame] | 37 | #include <drivers/intel/gma/i915_reg.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 38 | |
| 39 | static u8 smm_initialized = 0; |
| 40 | |
| 41 | /* |
| 42 | * GNVS needs to be updated by an 0xEA PM Trap (B2) after it has been located |
| 43 | * by coreboot. |
| 44 | */ |
| 45 | static global_nvs_t *gnvs; |
| 46 | global_nvs_t *smm_get_gnvs(void) |
| 47 | { |
| 48 | return gnvs; |
| 49 | } |
| 50 | |
| 51 | int southbridge_io_trap_handler(int smif) |
| 52 | { |
| 53 | switch (smif) { |
| 54 | case 0x32: |
| 55 | printk(BIOS_DEBUG, "OS Init\n"); |
| 56 | /* gnvs->smif: |
| 57 | * On success, the IO Trap Handler returns 0 |
| 58 | * On failure, the IO Trap Handler returns a value != 0 |
| 59 | */ |
| 60 | gnvs->smif = 0; |
| 61 | return 1; /* IO trap handled */ |
| 62 | } |
| 63 | |
| 64 | /* Not handled */ |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @brief Set the EOS bit |
| 70 | */ |
| 71 | void southbridge_smi_set_eos(void) |
| 72 | { |
| 73 | enable_smi(EOS); |
| 74 | } |
| 75 | |
| 76 | static void busmaster_disable_on_bus(int bus) |
| 77 | { |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 78 | int slot, func; |
| 79 | unsigned int val; |
| 80 | unsigned char hdr; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 81 | |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 82 | for (slot = 0; slot < 0x20; slot++) { |
| 83 | for (func = 0; func < 8; func++) { |
| 84 | u32 reg32; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 85 | |
Kyösti Mälkki | e16c9df | 2018-12-29 08:04:16 +0200 | [diff] [blame] | 86 | pci_devfn_t dev = PCI_DEV(bus, slot, func); |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 87 | val = pci_read_config32(dev, PCI_VENDOR_ID); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 88 | |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 89 | if (val == 0xffffffff || val == 0x00000000 || |
| 90 | val == 0x0000ffff || val == 0xffff0000) |
| 91 | continue; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 92 | |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 93 | /* Disable Bus Mastering for this one device */ |
| 94 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 95 | reg32 &= ~PCI_COMMAND_MASTER; |
| 96 | pci_write_config32(dev, PCI_COMMAND, reg32); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 97 | |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 98 | /* If this is a bridge, then follow it. */ |
| 99 | hdr = pci_read_config8(dev, PCI_HEADER_TYPE); |
| 100 | hdr &= 0x7f; |
| 101 | if (hdr == PCI_HEADER_TYPE_BRIDGE || |
| 102 | hdr == PCI_HEADER_TYPE_CARDBUS) { |
| 103 | unsigned int buses; |
| 104 | buses = pci_read_config32(dev, PCI_PRIMARY_BUS); |
| 105 | busmaster_disable_on_bus((buses >> 8) & 0xff); |
| 106 | } |
| 107 | } |
| 108 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Duncan Laurie | f3e0a13 | 2015-01-14 17:33:00 -0800 | [diff] [blame] | 111 | /* |
| 112 | * Turn off the backlight if it is on, and wait for the specified |
| 113 | * backlight off delay. This will allow panel power timings to meet |
| 114 | * spec and prevent brief garbage on the screen when turned off |
| 115 | * during firmware with power button triggered SMI. |
| 116 | */ |
| 117 | static void backlight_off(void) |
| 118 | { |
| 119 | void *reg_base; |
| 120 | uint32_t pp_ctrl; |
| 121 | uint32_t bl_off_delay; |
| 122 | |
Lee Leahy | 6ef5192 | 2017-03-17 10:56:08 -0700 | [diff] [blame] | 123 | reg_base = (void *)((uintptr_t)pci_read_config32(SA_DEV_IGD, |
| 124 | PCI_BASE_ADDRESS_0) & ~0xf); |
Duncan Laurie | f3e0a13 | 2015-01-14 17:33:00 -0800 | [diff] [blame] | 125 | |
| 126 | /* Check if backlight is enabled */ |
| 127 | pp_ctrl = read32(reg_base + PCH_PP_CONTROL); |
| 128 | if (!(pp_ctrl & EDP_BLC_ENABLE)) |
| 129 | return; |
| 130 | |
| 131 | /* Enable writes to this register */ |
| 132 | pp_ctrl &= ~PANEL_UNLOCK_MASK; |
| 133 | pp_ctrl |= PANEL_UNLOCK_REGS; |
| 134 | |
| 135 | /* Turn off backlight */ |
| 136 | pp_ctrl &= ~EDP_BLC_ENABLE; |
| 137 | |
| 138 | write32(reg_base + PCH_PP_CONTROL, pp_ctrl); |
| 139 | read32(reg_base + PCH_PP_CONTROL); |
| 140 | |
| 141 | /* Read backlight off delay in 100us units */ |
| 142 | bl_off_delay = read32(reg_base + PCH_PP_OFF_DELAYS); |
| 143 | bl_off_delay &= PANEL_LIGHT_OFF_DELAY_MASK; |
| 144 | bl_off_delay *= 100; |
| 145 | |
| 146 | /* Wait for backlight to turn off */ |
| 147 | udelay(bl_off_delay); |
| 148 | |
| 149 | printk(BIOS_INFO, "Backlight turned off\n"); |
| 150 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 151 | |
| 152 | static void southbridge_smi_sleep(void) |
| 153 | { |
| 154 | u8 reg8; |
| 155 | u32 reg32; |
| 156 | u8 slp_typ; |
Nico Huber | 9faae2b | 2018-11-14 00:00:35 +0100 | [diff] [blame] | 157 | u8 s5pwr = CONFIG_MAINBOARD_POWER_FAILURE_STATE; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 158 | |
| 159 | /* save and recover RTC port values */ |
| 160 | u8 tmp70, tmp72; |
| 161 | tmp70 = inb(0x70); |
| 162 | tmp72 = inb(0x72); |
| 163 | get_option(&s5pwr, "power_on_after_fail"); |
| 164 | outb(tmp70, 0x70); |
| 165 | outb(tmp72, 0x72); |
| 166 | |
| 167 | /* First, disable further SMIs */ |
| 168 | disable_smi(SLP_SMI_EN); |
| 169 | |
| 170 | /* Figure out SLP_TYP */ |
| 171 | reg32 = inl(ACPI_BASE_ADDRESS + PM1_CNT); |
| 172 | printk(BIOS_SPEW, "SMI#: SLP = 0x%08x\n", reg32); |
Aaron Durbin | 9e6d143 | 2016-07-13 23:21:41 -0500 | [diff] [blame] | 173 | slp_typ = acpi_sleep_from_pm1(reg32); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 174 | |
| 175 | /* Do any mainboard sleep handling */ |
Aaron Durbin | 9e6d143 | 2016-07-13 23:21:41 -0500 | [diff] [blame] | 176 | mainboard_smi_sleep(slp_typ); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 177 | |
| 178 | /* USB sleep preparations */ |
| 179 | usb_xhci_sleep_prepare(PCH_DEV_XHCI, slp_typ); |
| 180 | |
Martin Roth | e6ff159 | 2017-06-24 21:34:29 -0600 | [diff] [blame] | 181 | #if IS_ENABLED(CONFIG_ELOG_GSMI) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 182 | /* Log S3, S4, and S5 entry */ |
Aaron Durbin | 9e6d143 | 2016-07-13 23:21:41 -0500 | [diff] [blame] | 183 | if (slp_typ >= ACPI_S3) |
| 184 | elog_add_event_byte(ELOG_TYPE_ACPI_ENTER, slp_typ); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 185 | #endif |
| 186 | |
Duncan Laurie | d775dda | 2014-10-25 01:49:32 -0700 | [diff] [blame] | 187 | /* Clear pending GPE events */ |
| 188 | clear_gpe_status(); |
| 189 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 190 | /* Next, do the deed. |
| 191 | */ |
| 192 | |
| 193 | switch (slp_typ) { |
Aaron Durbin | 9e6d143 | 2016-07-13 23:21:41 -0500 | [diff] [blame] | 194 | case ACPI_S0: |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 195 | printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n"); |
| 196 | break; |
Aaron Durbin | 9e6d143 | 2016-07-13 23:21:41 -0500 | [diff] [blame] | 197 | case ACPI_S1: |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 198 | printk(BIOS_DEBUG, "SMI#: Entering S1 (Assert STPCLK#)\n"); |
| 199 | break; |
Aaron Durbin | 9e6d143 | 2016-07-13 23:21:41 -0500 | [diff] [blame] | 200 | case ACPI_S3: |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 201 | printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n"); |
| 202 | |
| 203 | /* Invalidate the cache before going to S3 */ |
| 204 | wbinvd(); |
| 205 | break; |
Aaron Durbin | 9e6d143 | 2016-07-13 23:21:41 -0500 | [diff] [blame] | 206 | case ACPI_S4: |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 207 | printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n"); |
| 208 | break; |
Aaron Durbin | 9e6d143 | 2016-07-13 23:21:41 -0500 | [diff] [blame] | 209 | case ACPI_S5: |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 210 | printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n"); |
| 211 | |
Duncan Laurie | f3e0a13 | 2015-01-14 17:33:00 -0800 | [diff] [blame] | 212 | /* Turn off backlight if needed */ |
| 213 | backlight_off(); |
| 214 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 215 | /* Disable all GPE */ |
| 216 | disable_all_gpe(); |
| 217 | |
| 218 | /* Always set the flag in case CMOS was changed on runtime. For |
| 219 | * "KEEP", switch to "OFF" - KEEP is software emulated |
| 220 | */ |
| 221 | reg8 = pci_read_config8(PCH_DEV_LPC, GEN_PMCON_3); |
| 222 | if (s5pwr == MAINBOARD_POWER_ON) |
| 223 | reg8 &= ~1; |
| 224 | else |
| 225 | reg8 |= 1; |
| 226 | pci_write_config8(PCH_DEV_LPC, GEN_PMCON_3, reg8); |
| 227 | |
| 228 | /* also iterates over all bridges on bus 0 */ |
| 229 | busmaster_disable_on_bus(0); |
| 230 | break; |
| 231 | default: |
| 232 | printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n"); |
| 233 | break; |
| 234 | } |
| 235 | |
| 236 | /* |
| 237 | * Write back to the SLP register to cause the originally intended |
| 238 | * event again. We need to set BIT13 (SLP_EN) though to make the |
| 239 | * sleep happen. |
| 240 | */ |
| 241 | enable_pm1_control(SLP_EN); |
| 242 | |
| 243 | /* Make sure to stop executing code here for S3/S4/S5 */ |
Aaron Durbin | 9e6d143 | 2016-07-13 23:21:41 -0500 | [diff] [blame] | 244 | if (slp_typ >= ACPI_S3) |
Patrick Georgi | 546953c | 2014-11-29 10:38:17 +0100 | [diff] [blame] | 245 | halt(); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 246 | |
| 247 | /* |
| 248 | * In most sleep states, the code flow of this function ends at |
| 249 | * the line above. However, if we entered sleep state S1 and wake |
| 250 | * up again, we will continue to execute code in this function. |
| 251 | */ |
| 252 | reg32 = inl(ACPI_BASE_ADDRESS + PM1_CNT); |
| 253 | if (reg32 & SCI_EN) { |
| 254 | /* The OS is not an ACPI OS, so we set the state to S0 */ |
| 255 | disable_pm1_control(SLP_EN | SLP_TYP); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | /* |
| 260 | * Look for Synchronous IO SMI and use save state from that |
| 261 | * core in case we are not running on the same core that |
| 262 | * initiated the IO transaction. |
| 263 | */ |
| 264 | static em64t101_smm_state_save_area_t *smi_apmc_find_state_save(u8 cmd) |
| 265 | { |
| 266 | em64t101_smm_state_save_area_t *state; |
| 267 | int node; |
| 268 | |
| 269 | /* Check all nodes looking for the one that issued the IO */ |
| 270 | for (node = 0; node < CONFIG_MAX_CPUS; node++) { |
| 271 | state = smm_get_save_state(node); |
| 272 | |
| 273 | /* Check for Synchronous IO (bit0==1) */ |
| 274 | if (!(state->io_misc_info & (1 << 0))) |
| 275 | continue; |
| 276 | |
| 277 | /* Make sure it was a write (bit4==0) */ |
| 278 | if (state->io_misc_info & (1 << 4)) |
| 279 | continue; |
| 280 | |
| 281 | /* Check for APMC IO port */ |
| 282 | if (((state->io_misc_info >> 16) & 0xff) != APM_CNT) |
| 283 | continue; |
| 284 | |
| 285 | /* Check AX against the requested command */ |
| 286 | if ((state->rax & 0xff) != cmd) |
| 287 | continue; |
| 288 | |
| 289 | return state; |
| 290 | } |
| 291 | |
| 292 | return NULL; |
| 293 | } |
| 294 | |
Martin Roth | e6ff159 | 2017-06-24 21:34:29 -0600 | [diff] [blame] | 295 | #if IS_ENABLED(CONFIG_ELOG_GSMI) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 296 | static void southbridge_smi_gsmi(void) |
| 297 | { |
| 298 | u32 *ret, *param; |
| 299 | u8 sub_command; |
| 300 | em64t101_smm_state_save_area_t *io_smi = |
Patrick Georgi | d61839c | 2018-12-03 16:10:33 +0100 | [diff] [blame] | 301 | smi_apmc_find_state_save(APM_CNT_ELOG_GSMI); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 302 | |
| 303 | if (!io_smi) |
| 304 | return; |
| 305 | |
| 306 | /* Command and return value in EAX */ |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 307 | ret = (u32 *)&io_smi->rax; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 308 | sub_command = (u8)(*ret >> 8); |
| 309 | |
| 310 | /* Parameter buffer in EBX */ |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 311 | param = (u32 *)&io_smi->rbx; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 312 | |
| 313 | /* drivers/elog/gsmi.c */ |
| 314 | *ret = gsmi_exec(sub_command, param); |
| 315 | } |
| 316 | #endif |
| 317 | |
| 318 | static void finalize(void) |
| 319 | { |
| 320 | static int finalize_done; |
| 321 | |
| 322 | if (finalize_done) { |
| 323 | printk(BIOS_DEBUG, "SMM already finalized.\n"); |
| 324 | return; |
| 325 | } |
| 326 | finalize_done = 1; |
| 327 | |
Martin Roth | e6ff159 | 2017-06-24 21:34:29 -0600 | [diff] [blame] | 328 | #if IS_ENABLED(CONFIG_SPI_FLASH_SMM) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 329 | /* Re-init SPI driver to handle locked BAR */ |
| 330 | spi_init(); |
| 331 | #endif |
| 332 | } |
| 333 | |
| 334 | static void southbridge_smi_apmc(void) |
| 335 | { |
| 336 | u8 reg8; |
| 337 | em64t101_smm_state_save_area_t *state; |
| 338 | |
| 339 | /* Emulate B2 register as the FADT / Linux expects it */ |
| 340 | |
| 341 | reg8 = inb(APM_CNT); |
| 342 | switch (reg8) { |
| 343 | case APM_CNT_CST_CONTROL: |
| 344 | printk(BIOS_DEBUG, "C-state control\n"); |
| 345 | break; |
| 346 | case APM_CNT_PST_CONTROL: |
| 347 | printk(BIOS_DEBUG, "P-state control\n"); |
| 348 | break; |
| 349 | case APM_CNT_ACPI_DISABLE: |
| 350 | disable_pm1_control(SCI_EN); |
| 351 | printk(BIOS_DEBUG, "SMI#: ACPI disabled.\n"); |
| 352 | break; |
| 353 | case APM_CNT_ACPI_ENABLE: |
| 354 | enable_pm1_control(SCI_EN); |
| 355 | printk(BIOS_DEBUG, "SMI#: ACPI enabled.\n"); |
| 356 | break; |
| 357 | case APM_CNT_FINALIZE: |
| 358 | finalize(); |
| 359 | break; |
| 360 | case APM_CNT_GNVS_UPDATE: |
| 361 | if (smm_initialized) { |
| 362 | printk(BIOS_DEBUG, |
| 363 | "SMI#: SMM structures already initialized!\n"); |
| 364 | return; |
| 365 | } |
| 366 | state = smi_apmc_find_state_save(reg8); |
| 367 | if (state) { |
| 368 | /* EBX in the state save contains the GNVS pointer */ |
| 369 | gnvs = (global_nvs_t *)((u32)state->rbx); |
| 370 | smm_initialized = 1; |
| 371 | printk(BIOS_DEBUG, "SMI#: Setting GNVS to %p\n", gnvs); |
| 372 | } |
| 373 | break; |
Martin Roth | e6ff159 | 2017-06-24 21:34:29 -0600 | [diff] [blame] | 374 | #if IS_ENABLED(CONFIG_ELOG_GSMI) |
Patrick Georgi | d61839c | 2018-12-03 16:10:33 +0100 | [diff] [blame] | 375 | case APM_CNT_ELOG_GSMI: |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 376 | southbridge_smi_gsmi(); |
| 377 | break; |
| 378 | #endif |
| 379 | } |
| 380 | |
| 381 | mainboard_smi_apmc(reg8); |
| 382 | } |
| 383 | |
| 384 | static void southbridge_smi_pm1(void) |
| 385 | { |
| 386 | u16 pm1_sts = clear_pm1_status(); |
| 387 | |
| 388 | /* While OSPM is not active, poweroff immediately |
| 389 | * on a power button event. |
| 390 | */ |
| 391 | if (pm1_sts & PWRBTN_STS) { |
| 392 | /* power button pressed */ |
Martin Roth | e6ff159 | 2017-06-24 21:34:29 -0600 | [diff] [blame] | 393 | #if IS_ENABLED(CONFIG_ELOG_GSMI) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 394 | elog_add_event(ELOG_TYPE_POWER_BUTTON); |
| 395 | #endif |
| 396 | disable_pm1_control(-1UL); |
| 397 | enable_pm1_control(SLP_EN | (SLP_TYP_S5 << 10)); |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | static void southbridge_smi_gpe0(void) |
| 402 | { |
| 403 | clear_gpe_status(); |
| 404 | } |
| 405 | |
| 406 | static void southbridge_smi_gpi(void) |
| 407 | { |
| 408 | mainboard_smi_gpi(clear_alt_smi_status()); |
| 409 | |
| 410 | /* Clear again after mainboard handler */ |
| 411 | clear_alt_smi_status(); |
| 412 | } |
| 413 | |
| 414 | static void southbridge_smi_mc(void) |
| 415 | { |
| 416 | u32 reg32 = inl(ACPI_BASE_ADDRESS + SMI_EN); |
| 417 | |
| 418 | /* Are microcontroller SMIs enabled? */ |
| 419 | if ((reg32 & MCSMI_EN) == 0) |
| 420 | return; |
| 421 | |
| 422 | printk(BIOS_DEBUG, "Microcontroller SMI.\n"); |
| 423 | } |
| 424 | |
| 425 | static void southbridge_smi_tco(void) |
| 426 | { |
| 427 | u32 tco_sts = clear_tco_status(); |
| 428 | |
| 429 | /* Any TCO event? */ |
| 430 | if (!tco_sts) |
| 431 | return; |
| 432 | |
Lee Leahy | 8a9c7dc | 2017-03-17 10:43:25 -0700 | [diff] [blame] | 433 | // BIOSWR |
| 434 | if (tco_sts & (1 << 8)) { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 435 | u8 bios_cntl = pci_read_config16(PCH_DEV_LPC, BIOS_CNTL); |
| 436 | |
| 437 | if (bios_cntl & 1) { |
| 438 | /* |
| 439 | * BWE is RW, so the SMI was caused by a |
| 440 | * write to BWE, not by a write to the BIOS |
| 441 | * |
| 442 | * This is the place where we notice someone |
| 443 | * is trying to tinker with the BIOS. We are |
| 444 | * trying to be nice and just ignore it. A more |
| 445 | * resolute answer would be to power down the |
| 446 | * box. |
| 447 | */ |
| 448 | printk(BIOS_DEBUG, "Switching back to RO\n"); |
| 449 | pci_write_config32(PCH_DEV_LPC, BIOS_CNTL, |
| 450 | (bios_cntl & ~1)); |
| 451 | } /* No else for now? */ |
| 452 | } else if (tco_sts & (1 << 3)) { /* TIMEOUT */ |
| 453 | /* Handle TCO timeout */ |
| 454 | printk(BIOS_DEBUG, "TCO Timeout.\n"); |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | static void southbridge_smi_periodic(void) |
| 459 | { |
| 460 | u32 reg32 = inl(ACPI_BASE_ADDRESS + SMI_EN); |
| 461 | |
| 462 | /* Are periodic SMIs enabled? */ |
| 463 | if ((reg32 & PERIODIC_EN) == 0) |
| 464 | return; |
| 465 | |
| 466 | printk(BIOS_DEBUG, "Periodic SMI.\n"); |
| 467 | } |
| 468 | |
| 469 | static void southbridge_smi_monitor(void) |
| 470 | { |
| 471 | #define IOTRAP(x) (trap_sts & (1 << x)) |
| 472 | u32 trap_sts, trap_cycle; |
| 473 | u32 data, mask = 0; |
| 474 | int i; |
| 475 | |
| 476 | trap_sts = RCBA32(0x1e00); // TRSR - Trap Status Register |
| 477 | RCBA32(0x1e00) = trap_sts; // Clear trap(s) in TRSR |
| 478 | |
| 479 | trap_cycle = RCBA32(0x1e10); |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 480 | for (i = 16; i < 20; i++) { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 481 | if (trap_cycle & (1 << i)) |
| 482 | mask |= (0xff << ((i - 16) << 2)); |
| 483 | } |
| 484 | |
| 485 | |
| 486 | /* IOTRAP(3) SMI function call */ |
| 487 | if (IOTRAP(3)) { |
| 488 | if (gnvs && gnvs->smif) |
| 489 | io_trap_handler(gnvs->smif); // call function smif |
| 490 | return; |
| 491 | } |
| 492 | |
| 493 | /* IOTRAP(2) currently unused |
| 494 | * IOTRAP(1) currently unused */ |
| 495 | |
| 496 | /* IOTRAP(0) SMIC */ |
| 497 | if (IOTRAP(0)) { |
Lee Leahy | 8a9c7dc | 2017-03-17 10:43:25 -0700 | [diff] [blame] | 498 | // It's a write |
| 499 | if (!(trap_cycle & (1 << 24))) { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 500 | printk(BIOS_DEBUG, "SMI1 command\n"); |
| 501 | data = RCBA32(0x1e18); |
| 502 | data &= mask; |
| 503 | // if (smi1) |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 504 | // southbridge_smi_command(data); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 505 | // return; |
| 506 | } |
| 507 | // Fall through to debug |
| 508 | } |
| 509 | |
| 510 | printk(BIOS_DEBUG, " trapped io address = 0x%x\n", |
| 511 | trap_cycle & 0xfffc); |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 512 | for (i = 0; i < 4; i++) |
Lee Leahy | 8a9c7dc | 2017-03-17 10:43:25 -0700 | [diff] [blame] | 513 | if (IOTRAP(i)) |
| 514 | printk(BIOS_DEBUG, " TRAP = %d\n", i); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 515 | printk(BIOS_DEBUG, " AHBE = %x\n", (trap_cycle >> 16) & 0xf); |
| 516 | printk(BIOS_DEBUG, " MASK = 0x%08x\n", mask); |
| 517 | printk(BIOS_DEBUG, " read/write: %s\n", |
| 518 | (trap_cycle & (1 << 24)) ? "read" : "write"); |
| 519 | |
| 520 | if (!(trap_cycle & (1 << 24))) { |
| 521 | /* Write Cycle */ |
| 522 | data = RCBA32(0x1e18); |
| 523 | printk(BIOS_DEBUG, " iotrap written data = 0x%08x\n", data); |
| 524 | } |
| 525 | #undef IOTRAP |
| 526 | } |
| 527 | |
| 528 | typedef void (*smi_handler_t)(void); |
| 529 | |
| 530 | static smi_handler_t southbridge_smi[32] = { |
| 531 | NULL, // [0] reserved |
| 532 | NULL, // [1] reserved |
| 533 | NULL, // [2] BIOS_STS |
| 534 | NULL, // [3] LEGACY_USB_STS |
| 535 | southbridge_smi_sleep, // [4] SLP_SMI_STS |
| 536 | southbridge_smi_apmc, // [5] APM_STS |
| 537 | NULL, // [6] SWSMI_TMR_STS |
| 538 | NULL, // [7] reserved |
| 539 | southbridge_smi_pm1, // [8] PM1_STS |
| 540 | southbridge_smi_gpe0, // [9] GPE0_STS |
| 541 | southbridge_smi_gpi, // [10] GPI_STS |
| 542 | southbridge_smi_mc, // [11] MCSMI_STS |
| 543 | NULL, // [12] DEVMON_STS |
| 544 | southbridge_smi_tco, // [13] TCO_STS |
| 545 | southbridge_smi_periodic, // [14] PERIODIC_STS |
| 546 | NULL, // [15] SERIRQ_SMI_STS |
| 547 | NULL, // [16] SMBUS_SMI_STS |
| 548 | NULL, // [17] LEGACY_USB2_STS |
| 549 | NULL, // [18] INTEL_USB2_STS |
| 550 | NULL, // [19] reserved |
| 551 | NULL, // [20] PCI_EXP_SMI_STS |
| 552 | southbridge_smi_monitor, // [21] MONITOR_STS |
| 553 | NULL, // [22] reserved |
| 554 | NULL, // [23] reserved |
| 555 | NULL, // [24] reserved |
| 556 | NULL, // [25] EL_SMI_STS |
| 557 | NULL, // [26] SPI_STS |
| 558 | NULL, // [27] reserved |
| 559 | NULL, // [28] reserved |
| 560 | NULL, // [29] reserved |
| 561 | NULL, // [30] reserved |
| 562 | NULL // [31] reserved |
| 563 | }; |
| 564 | |
| 565 | /** |
| 566 | * @brief Interrupt handler for SMI# |
| 567 | * |
| 568 | * @param smm_revision revision of the smm state save map |
| 569 | */ |
| 570 | |
| 571 | void southbridge_smi_handler(void) |
| 572 | { |
| 573 | int i; |
| 574 | u32 smi_sts; |
| 575 | |
| 576 | /* We need to clear the SMI status registers, or we won't see what's |
| 577 | * happening in the following calls. |
| 578 | */ |
| 579 | smi_sts = clear_smi_status(); |
| 580 | |
| 581 | /* Call SMI sub handler for each of the status bits */ |
| 582 | for (i = 0; i < 31; i++) { |
| 583 | if (smi_sts & (1 << i)) { |
| 584 | if (southbridge_smi[i]) { |
| 585 | southbridge_smi[i](); |
| 586 | } else { |
| 587 | printk(BIOS_DEBUG, |
Martin Roth | de7ed6f | 2014-12-07 14:58:18 -0700 | [diff] [blame] | 588 | "SMI_STS[%d] occurred, but no " |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 589 | "handler available.\n", i); |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | } |