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