Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 2 | |
Alexandru Gagniuc | a633980 | 2016-04-05 12:40:24 -0700 | [diff] [blame] | 3 | #define __SIMPLE_DEVICE__ |
| 4 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 5 | #include <acpi/acpi.h> |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 6 | #include <arch/io.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 7 | #include <device/mmio.h> |
Aaron Durbin | 3118b62 | 2017-09-15 11:48:53 -0600 | [diff] [blame] | 8 | #include <cbmem.h> |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 9 | #include <console/console.h> |
Andrey Petrov | 3b63753 | 2016-11-30 17:39:16 -0800 | [diff] [blame] | 10 | #include <cpu/x86/msr.h> |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 11 | #include <device/device.h> |
| 12 | #include <device/pci.h> |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 13 | #include <device/pci_def.h> |
Barnali Sarkar | 66fe0c4 | 2017-05-23 18:17:14 +0530 | [diff] [blame] | 14 | #include <intelblocks/msr.h> |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 15 | #include <intelblocks/pmclib.h> |
Aaron Durbin | 3118b62 | 2017-09-15 11:48:53 -0600 | [diff] [blame] | 16 | #include <intelblocks/rtc.h> |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 17 | #include <intelblocks/tco.h> |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 18 | #include <soc/iomap.h> |
Andrey Petrov | 3b63753 | 2016-11-30 17:39:16 -0800 | [diff] [blame] | 19 | #include <soc/cpu.h> |
Alexandru Gagniuc | a633980 | 2016-04-05 12:40:24 -0700 | [diff] [blame] | 20 | #include <soc/pci_devs.h> |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 21 | #include <soc/pm.h> |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 22 | #include <soc/smbus.h> |
Philipp Deppenwiese | fea2429 | 2017-10-17 17:02:29 +0200 | [diff] [blame] | 23 | #include <security/vboot/vbnv.h> |
Elyes HAOUAS | add76f9 | 2019-03-21 09:55:49 +0100 | [diff] [blame] | 24 | |
Duncan Laurie | a673d1c | 2016-09-19 12:02:54 -0700 | [diff] [blame] | 25 | #include "chip.h" |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 26 | |
Alexandru Gagniuc | a633980 | 2016-04-05 12:40:24 -0700 | [diff] [blame] | 27 | static uintptr_t read_pmc_mmio_bar(void) |
| 28 | { |
Lijian Zhao | 9108680 | 2016-09-06 18:15:29 -0700 | [diff] [blame] | 29 | return PMC_BAR0; |
Alexandru Gagniuc | a633980 | 2016-04-05 12:40:24 -0700 | [diff] [blame] | 30 | } |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 31 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 32 | uintptr_t soc_read_pmc_base(void) |
Shaunak Saha | 9a0c9ac | 2016-06-27 23:00:15 -0700 | [diff] [blame] | 33 | { |
| 34 | return read_pmc_mmio_bar(); |
| 35 | } |
| 36 | |
Michael Niewöhner | b4d960b | 2019-11-02 12:14:06 +0100 | [diff] [blame] | 37 | uint32_t *soc_pmc_etr_addr(void) |
| 38 | { |
| 39 | return (uint32_t *)(soc_read_pmc_base() + ETR); |
| 40 | } |
| 41 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 42 | const char *const *soc_smi_sts_array(size_t *a) |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 43 | { |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 44 | static const char *const smi_sts_bits[] = { |
Subrata Banik | 4ab7ef9 | 2020-02-20 11:53:04 +0530 | [diff] [blame] | 45 | [BIOS_STS_BIT] = "BIOS", |
| 46 | [LEGACY_USB_STS_BIT] = "LEGACY USB", |
| 47 | [SMI_ON_SLP_EN_STS_BIT] = "SLP_SMI", |
| 48 | [APM_STS_BIT] = "APM", |
| 49 | [SWSMI_TMR_STS_BIT] = "SWSMI_TMR", |
| 50 | [PM1_STS_BIT] = "PM1", |
| 51 | [GPIO_STS_BIT] = "GPIO_SMI", |
| 52 | [GPIO_UNLOCK_SMI_STS_BIT] = "GPIO_UNLOCK_SSMI", |
| 53 | [MC_SMI_STS_BIT] = "MCSMI", |
| 54 | [TCO_STS_BIT] = "TCO", |
| 55 | [PERIODIC_STS_BIT] = "PERIODIC", |
| 56 | [SERIRQ_SMI_STS_BIT] = "SERIRQ", |
| 57 | [SMBUS_SMI_STS_BIT] = "SMBUS_SMI", |
| 58 | [XHCI_SMI_STS_BIT] = "XHCI", |
| 59 | [SCS_SMI_STS_BIT] = "HOST_SMBUS", |
| 60 | [SCS_SMI_STS_BIT] = "SCS", |
| 61 | [PCI_EXP_SMI_STS_BIT] = "PCI_EXP_SMI", |
| 62 | [SCC2_SMI_STS_BIT] = "SCC2", |
| 63 | [SPI_SSMI_STS_BIT] = "SPI_SSMI", |
| 64 | [SPI_SMI_STS_BIT] = "SPI", |
| 65 | [PMC_OCP_SMI_STS_BIT] = "OCP_CSE", |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 66 | }; |
| 67 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 68 | *a = ARRAY_SIZE(smi_sts_bits); |
| 69 | return smi_sts_bits; |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 72 | /* |
| 73 | * For APL/GLK this check for power button status if nothing else |
| 74 | * is indicating an SMI and SMIs aren't turned into SCIs. |
| 75 | * Apparently, there is no PM1 status bit in the SMI status |
| 76 | * register. That makes things difficult for |
| 77 | * determining if the power button caused an SMI. |
| 78 | */ |
| 79 | uint32_t soc_get_smi_status(uint32_t generic_sts) |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 80 | { |
Furquan Shaikh | 43810d9 | 2017-10-16 22:22:46 -0700 | [diff] [blame] | 81 | if (generic_sts == 0 && !(pmc_read_pm1_control() & SCI_EN)) { |
Barnali Sarkar | 9e55ff6 | 2017-06-05 20:01:14 +0530 | [diff] [blame] | 82 | uint16_t pm1_sts = inw(ACPI_BASE_ADDRESS + PM1_STS); |
Aaron Durbin | a554b71 | 2016-06-10 18:04:21 -0500 | [diff] [blame] | 83 | |
| 84 | /* Fake PM1 status bit if power button pressed. */ |
| 85 | if (pm1_sts & PWRBTN_STS) |
Subrata Banik | 4ab7ef9 | 2020-02-20 11:53:04 +0530 | [diff] [blame] | 86 | generic_sts |= (1 << PM1_STS_BIT); |
Aaron Durbin | a554b71 | 2016-06-10 18:04:21 -0500 | [diff] [blame] | 87 | } |
| 88 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 89 | return generic_sts; |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 90 | } |
| 91 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 92 | const char *const *soc_tco_sts_array(size_t *a) |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 93 | { |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 94 | static const char *const tco_sts_bits[] = { |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 95 | [3] = "TIMEOUT", |
| 96 | [17] = "SECOND_TO", |
| 97 | }; |
| 98 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 99 | *a = ARRAY_SIZE(tco_sts_bits); |
| 100 | return tco_sts_bits; |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 101 | } |
| 102 | |
Furquan Shaikh | c4e652f | 2017-10-11 14:44:29 -0700 | [diff] [blame] | 103 | const char *const *soc_std_gpe_sts_array(size_t *a) |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 104 | { |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 105 | static const char *const gpe_sts_bits[] = { |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 106 | [0] = "PCIE_SCI", |
| 107 | [2] = "SWGPE", |
| 108 | [3] = "PCIE_WAKE0", |
| 109 | [4] = "PUNIT", |
| 110 | [6] = "PCIE_WAKE1", |
| 111 | [7] = "PCIE_WAKE2", |
| 112 | [8] = "PCIE_WAKE3", |
| 113 | [9] = "PCI_EXP", |
| 114 | [10] = "BATLOW", |
| 115 | [11] = "CSE_PME", |
| 116 | [12] = "XDCI_PME", |
| 117 | [13] = "XHCI_PME", |
| 118 | [14] = "AVS_PME", |
| 119 | [15] = "GPIO_TIER1_SCI", |
| 120 | [16] = "SMB_WAK", |
| 121 | [17] = "SATA_PME", |
| 122 | }; |
| 123 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 124 | *a = ARRAY_SIZE(gpe_sts_bits); |
| 125 | return gpe_sts_bits; |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 126 | } |
| 127 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 128 | void soc_clear_pm_registers(uintptr_t pmc_bar) |
Duncan Laurie | 2e79009 | 2016-09-19 12:05:49 -0700 | [diff] [blame] | 129 | { |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 130 | uint32_t gen_pmcon1; |
| 131 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 132 | gen_pmcon1 = read32((void *)(pmc_bar + GEN_PMCON1)); |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 133 | /* Clear the status bits. The RPS field is cleared on a 0 write. */ |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 134 | write32((void *)(pmc_bar + GEN_PMCON1), gen_pmcon1 & ~RPS); |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 135 | } |
| 136 | |
Furquan Shaikh | c4e652f | 2017-10-11 14:44:29 -0700 | [diff] [blame] | 137 | void soc_get_gpi_gpe_configs(uint8_t *dw0, uint8_t *dw1, uint8_t *dw2) |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 138 | { |
Aaron Durbin | e4d7abc | 2017-04-16 22:05:36 -0500 | [diff] [blame] | 139 | DEVTREE_CONST struct soc_intel_apollolake_config *config; |
Duncan Laurie | a673d1c | 2016-09-19 12:02:54 -0700 | [diff] [blame] | 140 | |
Kyösti Mälkki | d5f645c | 2019-09-28 00:20:27 +0300 | [diff] [blame] | 141 | config = config_of_soc(); |
Duncan Laurie | a673d1c | 2016-09-19 12:02:54 -0700 | [diff] [blame] | 142 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 143 | /* Assign to out variable */ |
| 144 | *dw0 = config->gpe0_dw1; |
| 145 | *dw1 = config->gpe0_dw2; |
| 146 | *dw2 = config->gpe0_dw3; |
| 147 | } |
Duncan Laurie | a673d1c | 2016-09-19 12:02:54 -0700 | [diff] [blame] | 148 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 149 | void soc_fill_power_state(struct chipset_power_state *ps) |
| 150 | { |
| 151 | uintptr_t pmc_bar0 = read_pmc_mmio_bar(); |
Duncan Laurie | a673d1c | 2016-09-19 12:02:54 -0700 | [diff] [blame] | 152 | |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 153 | ps->tco1_sts = tco_read_reg(TCO1_STS); |
| 154 | ps->tco2_sts = tco_read_reg(TCO2_STS); |
| 155 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 156 | ps->prsts = read32((void *)(pmc_bar0 + PRSTS)); |
| 157 | ps->gen_pmcon1 = read32((void *)(pmc_bar0 + GEN_PMCON1)); |
| 158 | ps->gen_pmcon2 = read32((void *)(pmc_bar0 + GEN_PMCON2)); |
| 159 | ps->gen_pmcon3 = read32((void *)(pmc_bar0 + GEN_PMCON3)); |
Duncan Laurie | a673d1c | 2016-09-19 12:02:54 -0700 | [diff] [blame] | 160 | |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 161 | printk(BIOS_DEBUG, "prsts: %08x\n", |
| 162 | ps->prsts); |
| 163 | printk(BIOS_DEBUG, "tco_sts: %04x %04x\n", |
| 164 | ps->tco1_sts, ps->tco2_sts); |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 165 | printk(BIOS_DEBUG, |
| 166 | "gen_pmcon1: %08x gen_pmcon2: %08x gen_pmcon3: %08x\n", |
| 167 | ps->gen_pmcon1, ps->gen_pmcon2, ps->gen_pmcon3); |
Duncan Laurie | a673d1c | 2016-09-19 12:02:54 -0700 | [diff] [blame] | 168 | } |
Andrey Petrov | 3b63753 | 2016-11-30 17:39:16 -0800 | [diff] [blame] | 169 | |
Hannah Williams | cdecc0d | 2018-01-04 11:57:14 -0800 | [diff] [blame] | 170 | /* Return 0, 3, or 5 to indicate the previous sleep state. */ |
| 171 | int soc_prev_sleep_state(const struct chipset_power_state *ps, |
| 172 | int prev_sleep_state) |
| 173 | { |
| 174 | /* WAK_STS bit will not be set when waking from G3 state */ |
| 175 | |
| 176 | if (!(ps->pm1_sts & WAK_STS) && (ps->gen_pmcon1 & COLD_BOOT_STS)) |
| 177 | prev_sleep_state = ACPI_S5; |
| 178 | return prev_sleep_state; |
| 179 | } |
| 180 | |
Aaron Durbin | 3118b62 | 2017-09-15 11:48:53 -0600 | [diff] [blame] | 181 | static int rtc_failed(uint32_t gen_pmcon1) |
| 182 | { |
| 183 | return !!(gen_pmcon1 & RPS); |
| 184 | } |
| 185 | |
| 186 | int soc_get_rtc_failed(void) |
| 187 | { |
| 188 | const struct chipset_power_state *ps = cbmem_find(CBMEM_ID_POWER_STATE); |
| 189 | |
| 190 | if (!ps) { |
| 191 | printk(BIOS_ERR, "Could not find power state in cbmem, RTC init aborted\n"); |
| 192 | return 1; |
| 193 | } |
| 194 | |
| 195 | return rtc_failed(ps->gen_pmcon1); |
| 196 | } |
Aaron Durbin | 0990fbf | 2017-09-15 15:23:04 -0600 | [diff] [blame] | 197 | |
| 198 | int vbnv_cmos_failed(void) |
| 199 | { |
Furquan Shaikh | 9d07910 | 2018-02-02 15:11:29 -0800 | [diff] [blame] | 200 | uintptr_t pmc_bar = read_pmc_mmio_bar(); |
| 201 | uint32_t gen_pmcon1 = read32((void *)(pmc_bar + GEN_PMCON1)); |
| 202 | int rtc_failure = rtc_failed(gen_pmcon1); |
| 203 | |
| 204 | if (rtc_failure) { |
| 205 | printk(BIOS_INFO, "RTC failed!\n"); |
| 206 | |
| 207 | /* We do not want to write 1 to clear-1 bits. Set them to 0. */ |
| 208 | gen_pmcon1 &= ~GEN_PMCON1_CLR1_BITS; |
| 209 | |
| 210 | /* RPS is write 0 to clear. */ |
| 211 | gen_pmcon1 &= ~RPS; |
| 212 | |
| 213 | write32((void *)(pmc_bar + GEN_PMCON1), gen_pmcon1); |
| 214 | } |
| 215 | |
| 216 | return rtc_failure; |
Aaron Durbin | 0990fbf | 2017-09-15 15:23:04 -0600 | [diff] [blame] | 217 | } |
Eugene Myers | ebc8423 | 2020-01-21 16:46:16 -0500 | [diff] [blame] | 218 | |
| 219 | /* STM Support */ |
| 220 | uint16_t get_pmbase(void) |
| 221 | { |
| 222 | return (uint16_t) ACPI_BASE_ADDRESS; |
| 223 | } |