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