Angel Pons | ba38f37 | 2020-04-05 15:46:45 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 2 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 3 | #include <arch/hlt.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 4 | #include <arch/io.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 5 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 6 | #include <device/pci_ops.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 7 | #include <console/console.h> |
| 8 | #include <cpu/x86/cache.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/em64t100_save_state.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 11 | #include <device/pci_def.h> |
| 12 | #include <elog.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 13 | #include <soc/nvs.h> |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 14 | #include <soc/pci_devs.h> |
| 15 | #include <soc/pm.h> |
| 16 | #include <spi-generic.h> |
| 17 | #include <stdint.h> |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 18 | #include <soc/gpio.h> |
Matt DeVillier | aa3b5e29 | 2018-12-25 22:10:48 -0600 | [diff] [blame] | 19 | #include <smmstore.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 20 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 21 | int southbridge_io_trap_handler(int smif) |
| 22 | { |
| 23 | switch (smif) { |
| 24 | case 0x32: |
| 25 | printk(BIOS_DEBUG, "OS Init\n"); |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 26 | /* |
| 27 | * gnvs->smif: |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 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 | void southbridge_smi_set_eos(void) |
| 40 | { |
| 41 | enable_smi(EOS); |
| 42 | } |
| 43 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 44 | static void busmaster_disable_on_bus(int bus) |
| 45 | { |
| 46 | int slot, func; |
| 47 | unsigned int val; |
| 48 | unsigned char hdr; |
| 49 | |
| 50 | for (slot = 0; slot < 0x20; slot++) { |
| 51 | for (func = 0; func < 8; func++) { |
Elyes HAOUAS | 066e61f | 2020-04-29 10:28:20 +0200 | [diff] [blame] | 52 | u16 reg16; |
Elyes HAOUAS | c8a649c | 2018-06-10 23:36:44 +0200 | [diff] [blame] | 53 | pci_devfn_t dev = PCI_DEV(bus, slot, func); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 54 | |
| 55 | val = pci_read_config32(dev, PCI_VENDOR_ID); |
| 56 | |
| 57 | if (val == 0xffffffff || val == 0x00000000 || |
| 58 | val == 0x0000ffff || val == 0xffff0000) |
| 59 | continue; |
| 60 | |
| 61 | /* Disable Bus Mastering for this one device */ |
Elyes HAOUAS | 066e61f | 2020-04-29 10:28:20 +0200 | [diff] [blame] | 62 | reg16 = pci_read_config16(dev, PCI_COMMAND); |
| 63 | reg16 &= ~PCI_COMMAND_MASTER; |
| 64 | pci_write_config16(dev, PCI_COMMAND, reg16); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 65 | |
| 66 | /* If this is a bridge, then follow it. */ |
| 67 | hdr = pci_read_config8(dev, PCI_HEADER_TYPE); |
| 68 | hdr &= 0x7f; |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 69 | if (hdr == PCI_HEADER_TYPE_BRIDGE || hdr == PCI_HEADER_TYPE_CARDBUS) { |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 70 | unsigned int buses; |
| 71 | buses = pci_read_config32(dev, PCI_PRIMARY_BUS); |
| 72 | busmaster_disable_on_bus((buses >> 8) & 0xff); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 78 | static void tristate_gpios(uint32_t val) |
| 79 | { |
| 80 | /* Tri-state eMMC */ |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 81 | write32((void *)COMMUNITY_GPSOUTHEAST_BASE + SDMMC1_CMD_MMIO_OFFSET, val); |
| 82 | write32((void *)COMMUNITY_GPSOUTHEAST_BASE + SDMMC1_D0_MMIO_OFFSET, val); |
| 83 | write32((void *)COMMUNITY_GPSOUTHEAST_BASE + SDMMC1_D1_MMIO_OFFSET, val); |
| 84 | write32((void *)COMMUNITY_GPSOUTHEAST_BASE + SDMMC1_D2_MMIO_OFFSET, val); |
| 85 | write32((void *)COMMUNITY_GPSOUTHEAST_BASE + SDMMC1_D3_MMIO_OFFSET, val); |
| 86 | write32((void *)COMMUNITY_GPSOUTHEAST_BASE + MMC1_D4_SD_WE_MMIO_OFFSET, val); |
| 87 | write32((void *)COMMUNITY_GPSOUTHEAST_BASE + MMC1_D5_MMIO_OFFSET, val); |
| 88 | write32((void *)COMMUNITY_GPSOUTHEAST_BASE + MMC1_D6_MMIO_OFFSET, val); |
| 89 | write32((void *)COMMUNITY_GPSOUTHEAST_BASE + MMC1_D7_MMIO_OFFSET, val); |
| 90 | write32((void *)COMMUNITY_GPSOUTHEAST_BASE + MMC1_RCLK_OFFSET, val); |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 91 | |
| 92 | /* Tri-state HDMI */ |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 93 | write32((void *)COMMUNITY_GPNORTH_BASE + HV_DDI2_DDC_SDA_MMIO_OFFSET, val); |
| 94 | write32((void *)COMMUNITY_GPNORTH_BASE + HV_DDI2_DDC_SCL_MMIO_OFFSET, val); |
Ravi Sarawadi | a5d9888 | 2015-08-11 14:06:15 -0700 | [diff] [blame] | 95 | |
| 96 | /* Tri-state CFIO 139 and 140 */ |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 97 | write32((void *)COMMUNITY_GPSOUTHWEST_BASE + CFIO_139_MMIO_OFFSET, val); |
| 98 | write32((void *)COMMUNITY_GPSOUTHWEST_BASE + CFIO_140_MMIO_OFFSET, val); |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 101 | static void southbridge_smi_sleep(void) |
| 102 | { |
| 103 | uint32_t reg32; |
| 104 | uint8_t slp_typ; |
| 105 | uint16_t pmbase = get_pmbase(); |
| 106 | |
| 107 | /* First, disable further SMIs */ |
| 108 | disable_smi(SLP_SMI_EN); |
| 109 | |
| 110 | /* Figure out SLP_TYP */ |
| 111 | reg32 = inl(pmbase + PM1_CNT); |
| 112 | printk(BIOS_SPEW, "SMI#: SLP = 0x%08x\n", reg32); |
Aaron Durbin | 1b6196d | 2016-07-13 23:20:26 -0500 | [diff] [blame] | 113 | slp_typ = acpi_sleep_from_pm1(reg32); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 114 | |
| 115 | /* Do any mainboard sleep handling */ |
Aaron Durbin | 1b6196d | 2016-07-13 23:20:26 -0500 | [diff] [blame] | 116 | mainboard_smi_sleep(slp_typ); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 117 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 118 | /* Log S3, S4, and S5 entry */ |
Aaron Durbin | 1b6196d | 2016-07-13 23:20:26 -0500 | [diff] [blame] | 119 | if (slp_typ >= ACPI_S3) |
Kyösti Mälkki | 9dd1a12 | 2019-11-06 11:04:27 +0200 | [diff] [blame] | 120 | elog_gsmi_add_event_byte(ELOG_TYPE_ACPI_ENTER, slp_typ); |
| 121 | |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 122 | /* Clear pending GPE events */ |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 123 | clear_gpe_status(); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 124 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 125 | /* Next, do the deed. */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 126 | switch (slp_typ) { |
Aaron Durbin | 1b6196d | 2016-07-13 23:20:26 -0500 | [diff] [blame] | 127 | case ACPI_S0: |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 128 | printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n"); |
| 129 | break; |
Aaron Durbin | 1b6196d | 2016-07-13 23:20:26 -0500 | [diff] [blame] | 130 | case ACPI_S1: |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 131 | printk(BIOS_DEBUG, "SMI#: Entering S1 (Assert STPCLK#)\n"); |
| 132 | break; |
Aaron Durbin | 1b6196d | 2016-07-13 23:20:26 -0500 | [diff] [blame] | 133 | case ACPI_S3: |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 134 | printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n"); |
| 135 | |
| 136 | /* Invalidate the cache before going to S3 */ |
| 137 | wbinvd(); |
| 138 | break; |
Aaron Durbin | 1b6196d | 2016-07-13 23:20:26 -0500 | [diff] [blame] | 139 | case ACPI_S4: |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 140 | printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n"); |
| 141 | break; |
Aaron Durbin | 1b6196d | 2016-07-13 23:20:26 -0500 | [diff] [blame] | 142 | case ACPI_S5: |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 143 | printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n"); |
| 144 | |
| 145 | /* Disable all GPE */ |
| 146 | disable_all_gpe(); |
| 147 | |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 148 | /* Also iterates over all bridges on bus 0 */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 149 | busmaster_disable_on_bus(0); |
| 150 | break; |
| 151 | default: |
| 152 | printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n"); |
| 153 | break; |
| 154 | } |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 155 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 156 | /* Clear pending wake status bit to avoid immediate wake */ |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 157 | write32((void *)(0xfed88000 + 0x0200), read32((void *)(0xfed88000 + 0x0200))); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 158 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 159 | /* Tri-state specific GPIOS to avoid leakage during S3/S5 */ |
Aaron Durbin | 1b6196d | 2016-07-13 23:20:26 -0500 | [diff] [blame] | 160 | if ((slp_typ == ACPI_S3) || (slp_typ == ACPI_S5)) |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 161 | tristate_gpios(PAD_CONTROL_REG0_TRISTATE); |
| 162 | |
| 163 | /* |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 164 | * Write back to the SLP register to cause the originally intended event again. |
| 165 | * We need to set BIT13 (SLP_EN) though to make the sleep happen. |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 166 | */ |
| 167 | enable_pm1_control(SLP_EN); |
| 168 | |
| 169 | /* Make sure to stop executing code here for S3/S4/S5 */ |
Aaron Durbin | 1b6196d | 2016-07-13 23:20:26 -0500 | [diff] [blame] | 170 | if (slp_typ >= ACPI_S3) |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 171 | hlt(); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 172 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 173 | /* |
| 174 | * In most sleep states, the code flow of this function ends at |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 175 | * the line above. However, if we entered sleep state S1 and wake |
| 176 | * up again, we will continue to execute code in this function. |
| 177 | */ |
| 178 | reg32 = inl(pmbase + PM1_CNT); |
| 179 | if (reg32 & SCI_EN) { |
| 180 | /* The OS is not an ACPI OS, so we set the state to S0 */ |
| 181 | disable_pm1_control(SLP_EN | SLP_TYP); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /* |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 186 | * Look for Synchronous IO SMI and use save state from that core in case |
| 187 | * we are not running on the same core that initiated the IO transaction. |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 188 | */ |
| 189 | static em64t100_smm_state_save_area_t *smi_apmc_find_state_save(uint8_t cmd) |
| 190 | { |
| 191 | em64t100_smm_state_save_area_t *state; |
| 192 | int node; |
| 193 | |
| 194 | /* Check all nodes looking for the one that issued the IO */ |
| 195 | for (node = 0; node < CONFIG_MAX_CPUS; node++) { |
| 196 | state = smm_get_save_state(node); |
| 197 | |
| 198 | /* Check for Synchronous IO (bit0==1) */ |
| 199 | if (!(state->io_misc_info & (1 << 0))) |
| 200 | continue; |
| 201 | |
| 202 | /* Make sure it was a write (bit4==0) */ |
| 203 | if (state->io_misc_info & (1 << 4)) |
| 204 | continue; |
| 205 | |
| 206 | /* Check for APMC IO port */ |
| 207 | if (((state->io_misc_info >> 16) & 0xff) != APM_CNT) |
| 208 | continue; |
| 209 | |
| 210 | /* Check AX against the requested command */ |
| 211 | if ((state->rax & 0xff) != cmd) |
| 212 | continue; |
| 213 | |
| 214 | return state; |
| 215 | } |
| 216 | |
| 217 | return NULL; |
| 218 | } |
| 219 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 220 | static void southbridge_smi_gsmi(void) |
| 221 | { |
| 222 | u32 *ret, *param; |
| 223 | uint8_t sub_command; |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 224 | em64t100_smm_state_save_area_t *io_smi = smi_apmc_find_state_save(APM_CNT_ELOG_GSMI); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 225 | |
| 226 | if (!io_smi) |
| 227 | return; |
| 228 | |
| 229 | /* Command and return value in EAX */ |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 230 | ret = (u32 *)&io_smi->rax; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 231 | sub_command = (uint8_t)(*ret >> 8); |
| 232 | |
| 233 | /* Parameter buffer in EBX */ |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 234 | param = (u32 *)&io_smi->rbx; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 235 | |
| 236 | /* drivers/elog/gsmi.c */ |
| 237 | *ret = gsmi_exec(sub_command, param); |
| 238 | } |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 239 | |
Matt DeVillier | aa3b5e29 | 2018-12-25 22:10:48 -0600 | [diff] [blame] | 240 | static void southbridge_smi_store(void) |
| 241 | { |
| 242 | u8 sub_command, ret; |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 243 | em64t100_smm_state_save_area_t *io_smi = smi_apmc_find_state_save(APM_CNT_SMMSTORE); |
Matt DeVillier | aa3b5e29 | 2018-12-25 22:10:48 -0600 | [diff] [blame] | 244 | uint32_t reg_ebx; |
| 245 | |
| 246 | if (!io_smi) |
| 247 | return; |
| 248 | /* Command and return value in EAX */ |
| 249 | sub_command = (io_smi->rax >> 8) & 0xff; |
| 250 | |
| 251 | /* Parameter buffer in EBX */ |
| 252 | reg_ebx = io_smi->rbx; |
| 253 | |
| 254 | /* drivers/smmstore/smi.c */ |
| 255 | ret = smmstore_exec(sub_command, (void *)reg_ebx); |
| 256 | io_smi->rax = ret; |
| 257 | } |
| 258 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 259 | static void southbridge_smi_apmc(void) |
| 260 | { |
| 261 | uint8_t reg8; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 262 | |
Kyösti Mälkki | 9a1620f | 2021-01-08 13:27:33 +0200 | [diff] [blame] | 263 | reg8 = apm_get_apmc(); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 264 | switch (reg8) { |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 265 | case APM_CNT_ACPI_DISABLE: |
| 266 | disable_pm1_control(SCI_EN); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 267 | break; |
| 268 | case APM_CNT_ACPI_ENABLE: |
| 269 | enable_pm1_control(SCI_EN); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 270 | break; |
Patrick Georgi | d61839c | 2018-12-03 16:10:33 +0100 | [diff] [blame] | 271 | case APM_CNT_ELOG_GSMI: |
Kyösti Mälkki | 9dd1a12 | 2019-11-06 11:04:27 +0200 | [diff] [blame] | 272 | if (CONFIG(ELOG_GSMI)) |
| 273 | southbridge_smi_gsmi(); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 274 | break; |
Matt DeVillier | aa3b5e29 | 2018-12-25 22:10:48 -0600 | [diff] [blame] | 275 | case APM_CNT_SMMSTORE: |
| 276 | if (CONFIG(SMMSTORE)) |
| 277 | southbridge_smi_store(); |
| 278 | break; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | mainboard_smi_apmc(reg8); |
| 282 | } |
| 283 | |
| 284 | static void southbridge_smi_pm1(void) |
| 285 | { |
| 286 | uint16_t pm1_sts = clear_pm1_status(); |
| 287 | |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 288 | /* While OSPM is not active, poweroff immediately on a power button event */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 289 | if (pm1_sts & PWRBTN_STS) { |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 290 | /* Power button pressed */ |
Kyösti Mälkki | 9dd1a12 | 2019-11-06 11:04:27 +0200 | [diff] [blame] | 291 | elog_gsmi_add_event(ELOG_TYPE_POWER_BUTTON); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 292 | disable_pm1_control(-1UL); |
| 293 | enable_pm1_control(SLP_EN | (SLP_TYP_S5 << SLP_TYP_SHIFT)); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | static void southbridge_smi_gpe0(void) |
| 298 | { |
| 299 | clear_gpe_status(); |
| 300 | } |
| 301 | |
| 302 | static void southbridge_smi_tco(void) |
| 303 | { |
| 304 | uint32_t tco_sts = clear_tco_status(); |
| 305 | |
| 306 | /* Any TCO event? */ |
| 307 | if (!tco_sts) |
| 308 | return; |
| 309 | |
| 310 | if (tco_sts & TCO_TIMEOUT) { /* TIMEOUT */ |
| 311 | /* Handle TCO timeout */ |
| 312 | printk(BIOS_DEBUG, "TCO Timeout.\n"); |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | static void southbridge_smi_periodic(void) |
| 317 | { |
| 318 | uint32_t reg32; |
| 319 | |
| 320 | reg32 = inl(get_pmbase() + SMI_EN); |
| 321 | |
| 322 | /* Are periodic SMIs enabled? */ |
| 323 | if ((reg32 & PERIODIC_EN) == 0) |
| 324 | return; |
| 325 | |
| 326 | printk(BIOS_DEBUG, "Periodic SMI.\n"); |
| 327 | } |
| 328 | |
| 329 | typedef void (*smi_handler_t)(void); |
| 330 | |
| 331 | static const smi_handler_t southbridge_smi[32] = { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 332 | NULL, /* [0] reserved */ |
| 333 | NULL, /* [1] reserved */ |
| 334 | NULL, /* [2] BIOS_STS */ |
| 335 | NULL, /* [3] LEGACY_USB_STS */ |
| 336 | southbridge_smi_sleep, /* [4] SLP_SMI_STS */ |
| 337 | southbridge_smi_apmc, /* [5] APM_STS */ |
| 338 | NULL, /* [6] SWSMI_TMR_STS */ |
| 339 | NULL, /* [7] reserved */ |
| 340 | southbridge_smi_pm1, /* [8] PM1_STS */ |
| 341 | southbridge_smi_gpe0, /* [9] GPE0_STS */ |
| 342 | NULL, /* [10] reserved */ |
| 343 | NULL, /* [11] reserved */ |
| 344 | NULL, /* [12] reserved */ |
| 345 | southbridge_smi_tco, /* [13] TCO_STS */ |
| 346 | southbridge_smi_periodic, /* [14] PERIODIC_STS */ |
| 347 | NULL, /* [15] SERIRQ_SMI_STS */ |
| 348 | NULL, /* [16] SMBUS_SMI_STS */ |
| 349 | NULL, /* [17] LEGACY_USB2_STS */ |
| 350 | NULL, /* [18] INTEL_USB2_STS */ |
| 351 | NULL, /* [19] reserved */ |
| 352 | NULL, /* [20] PCI_EXP_SMI_STS */ |
| 353 | NULL, /* [21] reserved */ |
| 354 | NULL, /* [22] reserved */ |
| 355 | NULL, /* [23] reserved */ |
| 356 | NULL, /* [24] reserved */ |
| 357 | NULL, /* [25] reserved */ |
| 358 | NULL, /* [26] SPI_STS */ |
| 359 | NULL, /* [27] reserved */ |
| 360 | NULL, /* [28] PUNIT */ |
| 361 | NULL, /* [29] GUNIT */ |
| 362 | NULL, /* [30] reserved */ |
| 363 | NULL /* [31] reserved */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 364 | }; |
| 365 | |
| 366 | void southbridge_smi_handler(void) |
| 367 | { |
| 368 | int i; |
| 369 | uint32_t smi_sts; |
| 370 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 371 | /* |
| 372 | * We need to clear the SMI status registers, or we won't see what's |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 373 | * happening in the following calls. |
| 374 | */ |
| 375 | smi_sts = clear_smi_status(); |
| 376 | |
| 377 | /* Call SMI sub handler for each of the status bits */ |
| 378 | for (i = 0; i < ARRAY_SIZE(southbridge_smi); i++) { |
| 379 | if (!(smi_sts & (1 << i))) |
| 380 | continue; |
| 381 | |
| 382 | if (southbridge_smi[i] != NULL) { |
| 383 | southbridge_smi[i](); |
| 384 | } else { |
| 385 | printk(BIOS_DEBUG, |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 386 | "SMI_STS[%d] occurred, but no handler available.\n", i); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 390 | /* |
| 391 | * The GPIO SMI events do not have a status bit in SMI_STS. Therefore, |
| 392 | * these events need to be cleared and checked unconditionally. |
| 393 | */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 394 | mainboard_smi_gpi(clear_alt_status()); |
| 395 | } |