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