Angel Pons | 3bd1e3d | 2020-04-05 15:47:17 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 3 | |
| 4 | /* |
| 5 | * Helper functions for dealing with power management registers |
| 6 | * and the differences between PCH variants. |
| 7 | */ |
| 8 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame^] | 9 | #include <acpi/acpi.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 10 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 11 | #include <device/pci_ops.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 12 | #include <device/device.h> |
| 13 | #include <device/pci.h> |
| 14 | #include <device/pci_def.h> |
| 15 | #include <console/console.h> |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 16 | #include <intelblocks/pmclib.h> |
Ravi Sarawadi | 1483d1f | 2017-09-28 17:06:01 -0700 | [diff] [blame] | 17 | #include <intelblocks/lpc_lib.h> |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 18 | #include <intelblocks/tco.h> |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 19 | #include <soc/gpe.h> |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 20 | #include <soc/gpio.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 21 | #include <soc/iomap.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 22 | #include <soc/pci_devs.h> |
| 23 | #include <soc/pm.h> |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 24 | #include <soc/pmc.h> |
| 25 | #include <soc/smbus.h> |
Philipp Deppenwiese | fea2429 | 2017-10-17 17:02:29 +0200 | [diff] [blame] | 26 | #include <security/vboot/vbnv.h> |
Elyes HAOUAS | add76f9 | 2019-03-21 09:55:49 +0100 | [diff] [blame] | 27 | |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 28 | #include "chip.h" |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 29 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 30 | /* |
| 31 | * SMI |
| 32 | */ |
| 33 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 34 | const char *const *soc_smi_sts_array(size_t *smi_arr) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 35 | { |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 36 | static const char *const smi_sts_bits[] = { |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 37 | [2] = "BIOS", |
| 38 | [3] = "LEGACY_USB", |
| 39 | [4] = "SLP_SMI", |
| 40 | [5] = "APM", |
| 41 | [6] = "SWSMI_TMR", |
| 42 | [8] = "PM1", |
| 43 | [9] = "GPE0", |
| 44 | [10] = "GPI", |
| 45 | [11] = "MCSMI", |
| 46 | [12] = "DEVMON", |
| 47 | [13] = "TCO", |
| 48 | [14] = "PERIODIC", |
| 49 | [15] = "SERIRQ_SMI", |
| 50 | [16] = "SMBUS_SMI", |
| 51 | [17] = "LEGACY_USB2", |
| 52 | [18] = "INTEL_USB2", |
| 53 | [20] = "PCI_EXP_SMI", |
| 54 | [21] = "MONITOR", |
| 55 | [26] = "SPI", |
Duncan Laurie | 8d01902 | 2016-10-25 19:58:27 -0700 | [diff] [blame] | 56 | [27] = "GPIO_UNLOCK", |
| 57 | [28] = "ESPI_SMI", |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 60 | *smi_arr = ARRAY_SIZE(smi_sts_bits); |
| 61 | return smi_sts_bits; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 64 | /* |
| 65 | * TCO |
| 66 | */ |
| 67 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 68 | const char *const *soc_tco_sts_array(size_t *tco_arr) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 69 | { |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 70 | static const char *const tco_sts_bits[] = { |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 71 | [0] = "NMI2SMI", |
| 72 | [1] = "SW_TCO", |
| 73 | [2] = "TCO_INT", |
| 74 | [3] = "TIMEOUT", |
| 75 | [7] = "NEWCENTURY", |
| 76 | [8] = "BIOSWR", |
| 77 | [9] = "DMISCI", |
| 78 | [10] = "DMISMI", |
| 79 | [12] = "DMISERR", |
| 80 | [13] = "SLVSEL", |
| 81 | [16] = "INTRD_DET", |
| 82 | [17] = "SECOND_TO", |
| 83 | [18] = "BOOT", |
| 84 | [20] = "SMLINK_SLV" |
| 85 | }; |
| 86 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 87 | *tco_arr = ARRAY_SIZE(tco_sts_bits); |
| 88 | return tco_sts_bits; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 91 | /* |
| 92 | * GPE0 |
| 93 | */ |
| 94 | |
Furquan Shaikh | c4e652f | 2017-10-11 14:44:29 -0700 | [diff] [blame] | 95 | const char *const *soc_std_gpe_sts_array(size_t *gpe_arr) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 96 | { |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 97 | static const char *const gpe_sts_bits[] = { |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 98 | [1] = "HOTPLUG", |
| 99 | [2] = "SWGPE", |
| 100 | [6] = "TCO_SCI", |
| 101 | [7] = "SMB_WAK", |
| 102 | [9] = "PCI_EXP", |
| 103 | [10] = "BATLOW", |
| 104 | [11] = "PME", |
| 105 | [12] = "ME", |
| 106 | [13] = "PME_B0", |
Aaron Durbin | 7f78849 | 2015-07-24 17:10:31 -0500 | [diff] [blame] | 107 | [14] = "eSPI", |
| 108 | [15] = "GPIO Tier-2", |
| 109 | [16] = "LAN_WAKE", |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 110 | [18] = "WADT" |
| 111 | }; |
| 112 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 113 | *gpe_arr = ARRAY_SIZE(gpe_sts_bits); |
| 114 | return gpe_sts_bits; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | int acpi_sci_irq(void) |
| 118 | { |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 119 | int scis = pci_read_config32(PCH_DEV_PMC, ACTL) & SCI_IRQ_SEL; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 120 | int sci_irq = 9; |
| 121 | |
| 122 | /* Determine how SCI is routed. */ |
| 123 | switch (scis) { |
| 124 | case SCIS_IRQ9: |
| 125 | case SCIS_IRQ10: |
| 126 | case SCIS_IRQ11: |
| 127 | sci_irq = scis - SCIS_IRQ9 + 9; |
| 128 | break; |
| 129 | case SCIS_IRQ20: |
| 130 | case SCIS_IRQ21: |
| 131 | case SCIS_IRQ22: |
| 132 | case SCIS_IRQ23: |
| 133 | sci_irq = scis - SCIS_IRQ20 + 20; |
| 134 | break; |
| 135 | default: |
| 136 | printk(BIOS_DEBUG, "Invalid SCI route! Defaulting to IRQ9.\n"); |
| 137 | sci_irq = 9; |
| 138 | break; |
| 139 | } |
| 140 | |
| 141 | printk(BIOS_DEBUG, "SCI is IRQ%d\n", sci_irq); |
| 142 | return sci_irq; |
| 143 | } |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 144 | |
| 145 | uint8_t *pmc_mmio_regs(void) |
| 146 | { |
| 147 | uint32_t reg32; |
| 148 | |
| 149 | reg32 = pci_read_config32(PCH_DEV_PMC, PWRMBASE); |
| 150 | |
| 151 | /* 4KiB alignment. */ |
| 152 | reg32 &= ~0xfff; |
| 153 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 154 | return (void *)(uintptr_t) reg32; |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 157 | uintptr_t soc_read_pmc_base(void) |
| 158 | { |
| 159 | return (uintptr_t) (pmc_mmio_regs()); |
| 160 | } |
| 161 | |
Michael Niewöhner | 35e76dd | 2019-11-02 12:14:06 +0100 | [diff] [blame] | 162 | uint32_t *soc_pmc_etr_addr(void) |
| 163 | { |
| 164 | /* |
| 165 | * The pointer returned must not be cached, because the address depends on the |
| 166 | * MMCONF base address and the assigned PCI bus number, which both may change |
| 167 | * during the boot process! |
| 168 | */ |
| 169 | return pci_mmio_config32_addr(PCH_DEVFN_PMC << 12, ETR); |
| 170 | } |
| 171 | |
Furquan Shaikh | c4e652f | 2017-10-11 14:44:29 -0700 | [diff] [blame] | 172 | void soc_get_gpi_gpe_configs(uint8_t *dw0, uint8_t *dw1, uint8_t *dw2) |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 173 | { |
Aaron Durbin | e4d7abc | 2017-04-16 22:05:36 -0500 | [diff] [blame] | 174 | DEVTREE_CONST struct soc_intel_skylake_config *config; |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 175 | |
Kyösti Mälkki | d5f645c | 2019-09-28 00:20:27 +0300 | [diff] [blame] | 176 | config = config_of_soc(); |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 177 | |
Shaunak Saha | d347680 | 2017-07-08 01:08:40 -0700 | [diff] [blame] | 178 | /* Assign to out variable */ |
| 179 | *dw0 = config->gpe0_dw0; |
| 180 | *dw1 = config->gpe0_dw1; |
| 181 | *dw2 = config->gpe0_dw2; |
Duncan Laurie | f0ba225 | 2016-10-25 20:03:56 -0700 | [diff] [blame] | 182 | } |
Aaron Durbin | d1fc8c1 | 2017-09-15 12:37:05 -0600 | [diff] [blame] | 183 | |
| 184 | int rtc_failure(void) |
| 185 | { |
| 186 | u8 reg8; |
| 187 | int rtc_failed; |
| 188 | /* PMC Controller Device 0x1F, Func 02 */ |
Elyes HAOUAS | 68c851b | 2018-06-12 22:06:09 +0200 | [diff] [blame] | 189 | #if defined(__SIMPLE_DEVICE__) |
| 190 | pci_devfn_t dev = PCH_DEV_PMC; |
| 191 | #else |
| 192 | struct device *dev = PCH_DEV_PMC; |
| 193 | #endif |
Aaron Durbin | d1fc8c1 | 2017-09-15 12:37:05 -0600 | [diff] [blame] | 194 | reg8 = pci_read_config8(dev, GEN_PMCON_B); |
| 195 | rtc_failed = reg8 & RTC_BATTERY_DEAD; |
| 196 | if (rtc_failed) { |
| 197 | reg8 &= ~RTC_BATTERY_DEAD; |
| 198 | pci_write_config8(dev, GEN_PMCON_B, reg8); |
| 199 | printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed); |
| 200 | } |
| 201 | |
| 202 | return !!rtc_failed; |
| 203 | } |
Aaron Durbin | 0990fbf | 2017-09-15 15:23:04 -0600 | [diff] [blame] | 204 | |
| 205 | int vbnv_cmos_failed(void) |
| 206 | { |
| 207 | return rtc_failure(); |
| 208 | } |
Furquan Shaikh | 3efeeb2 | 2017-10-14 19:24:43 -0700 | [diff] [blame] | 209 | |
| 210 | /* Return 0, 3, or 5 to indicate the previous sleep state. */ |
| 211 | int soc_prev_sleep_state(const struct chipset_power_state *ps, |
| 212 | int prev_sleep_state) |
| 213 | { |
| 214 | /* |
| 215 | * Check for any power failure to determine if this a wake from |
| 216 | * S5 because the PCH does not set the WAK_STS bit when waking |
| 217 | * from a true G3 state. |
| 218 | */ |
| 219 | if (!(ps->pm1_sts & WAK_STS) && |
| 220 | (ps->gen_pmcon_b & (PWR_FLR | SUS_PWR_FLR))) |
| 221 | prev_sleep_state = ACPI_S5; |
| 222 | |
| 223 | /* |
| 224 | * If waking from S3 determine if deep S3 is enabled. If not, |
| 225 | * need to check both deep sleep well and normal suspend well. |
| 226 | * Otherwise just check deep sleep well. |
| 227 | */ |
| 228 | if (prev_sleep_state == ACPI_S3) { |
| 229 | /* PWR_FLR represents deep sleep power well loss. */ |
| 230 | uint32_t mask = PWR_FLR; |
| 231 | |
| 232 | /* If deep s3 isn't enabled check the suspend well too. */ |
| 233 | if (!deep_s3_enabled()) |
| 234 | mask |= SUS_PWR_FLR; |
| 235 | |
| 236 | if (ps->gen_pmcon_b & mask) |
| 237 | prev_sleep_state = ACPI_S5; |
| 238 | } |
| 239 | return prev_sleep_state; |
| 240 | } |
| 241 | |
| 242 | void soc_fill_power_state(struct chipset_power_state *ps) |
| 243 | { |
Furquan Shaikh | 3efeeb2 | 2017-10-14 19:24:43 -0700 | [diff] [blame] | 244 | uint8_t *pmc; |
| 245 | |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 246 | ps->tco1_sts = tco_read_reg(TCO1_STS); |
| 247 | ps->tco2_sts = tco_read_reg(TCO2_STS); |
Furquan Shaikh | 3efeeb2 | 2017-10-14 19:24:43 -0700 | [diff] [blame] | 248 | |
| 249 | printk(BIOS_DEBUG, "TCO_STS: %04x %04x\n", |
| 250 | ps->tco1_sts, ps->tco2_sts); |
| 251 | |
| 252 | ps->gen_pmcon_a = pci_read_config32(PCH_DEV_PMC, GEN_PMCON_A); |
| 253 | ps->gen_pmcon_b = pci_read_config32(PCH_DEV_PMC, GEN_PMCON_B); |
| 254 | |
| 255 | pmc = pmc_mmio_regs(); |
| 256 | ps->gblrst_cause[0] = read32(pmc + GBLRST_CAUSE0); |
| 257 | ps->gblrst_cause[1] = read32(pmc + GBLRST_CAUSE1); |
| 258 | |
| 259 | printk(BIOS_DEBUG, "GEN_PMCON: %08x %08x\n", |
| 260 | ps->gen_pmcon_a, ps->gen_pmcon_b); |
| 261 | |
| 262 | printk(BIOS_DEBUG, "GBLRST_CAUSE: %08x %08x\n", |
| 263 | ps->gblrst_cause[0], ps->gblrst_cause[1]); |
| 264 | } |
Eugene Myers | ebc8423 | 2020-01-21 16:46:16 -0500 | [diff] [blame] | 265 | |
| 266 | /* STM Support */ |
| 267 | uint16_t get_pmbase(void) |
| 268 | { |
| 269 | return ACPI_BASE_ADDRESS; |
| 270 | } |