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