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