Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013 Google Inc. |
| 5 | * Copyright (C) 2015-2016 Intel Corp. |
| 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, or (at your option) |
| 10 | * any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | */ |
| 17 | |
Alexandru Gagniuc | a633980 | 2016-04-05 12:40:24 -0700 | [diff] [blame] | 18 | #define __SIMPLE_DEVICE__ |
| 19 | |
Duncan Laurie | 2e79009 | 2016-09-19 12:05:49 -0700 | [diff] [blame] | 20 | #include <arch/acpi.h> |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 21 | #include <arch/io.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 22 | #include <device/mmio.h> |
Aaron Durbin | 3118b62 | 2017-09-15 11:48:53 -0600 | [diff] [blame] | 23 | #include <cbmem.h> |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 24 | #include <console/console.h> |
Andrey Petrov | 3b63753 | 2016-11-30 17:39:16 -0800 | [diff] [blame] | 25 | #include <cpu/x86/msr.h> |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 26 | #include <device/device.h> |
| 27 | #include <device/pci.h> |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 28 | #include <device/pci_def.h> |
Barnali Sarkar | 66fe0c4 | 2017-05-23 18:17:14 +0530 | [diff] [blame] | 29 | #include <intelblocks/msr.h> |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 30 | #include <intelblocks/pmclib.h> |
Aaron Durbin | 3118b62 | 2017-09-15 11:48:53 -0600 | [diff] [blame] | 31 | #include <intelblocks/rtc.h> |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 32 | #include <intelblocks/tco.h> |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 33 | #include <soc/iomap.h> |
Andrey Petrov | 3b63753 | 2016-11-30 17:39:16 -0800 | [diff] [blame] | 34 | #include <soc/cpu.h> |
Alexandru Gagniuc | a633980 | 2016-04-05 12:40:24 -0700 | [diff] [blame] | 35 | #include <soc/pci_devs.h> |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 36 | #include <soc/pm.h> |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 37 | #include <soc/smbus.h> |
Philipp Deppenwiese | fea2429 | 2017-10-17 17:02:29 +0200 | [diff] [blame] | 38 | #include <security/vboot/vbnv.h> |
Elyes HAOUAS | add76f9 | 2019-03-21 09:55:49 +0100 | [diff] [blame] | 39 | |
Duncan Laurie | a673d1c | 2016-09-19 12:02:54 -0700 | [diff] [blame] | 40 | #include "chip.h" |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 41 | |
Alexandru Gagniuc | a633980 | 2016-04-05 12:40:24 -0700 | [diff] [blame] | 42 | static uintptr_t read_pmc_mmio_bar(void) |
| 43 | { |
Lijian Zhao | 9108680 | 2016-09-06 18:15:29 -0700 | [diff] [blame] | 44 | return PMC_BAR0; |
Alexandru Gagniuc | a633980 | 2016-04-05 12:40:24 -0700 | [diff] [blame] | 45 | } |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 46 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 47 | uintptr_t soc_read_pmc_base(void) |
Shaunak Saha | 9a0c9ac | 2016-06-27 23:00:15 -0700 | [diff] [blame] | 48 | { |
| 49 | return read_pmc_mmio_bar(); |
| 50 | } |
| 51 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 52 | const char *const *soc_smi_sts_array(size_t *a) |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 53 | { |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 54 | static const char *const smi_sts_bits[] = { |
Aaron Durbin | 7929dd0 | 2016-06-10 18:01:45 -0500 | [diff] [blame] | 55 | [BIOS_SMI_STS] = "BIOS", |
| 56 | [LEGACY_USB_SMI_STS] = "LEGACY USB", |
| 57 | [SLP_SMI_STS] = "SLP_SMI", |
| 58 | [APM_SMI_STS] = "APM", |
| 59 | [SWSMI_TMR_SMI_STS] = "SWSMI_TMR", |
Aaron Durbin | a554b71 | 2016-06-10 18:04:21 -0500 | [diff] [blame] | 60 | [FAKE_PM1_SMI_STS] = "PM1", |
Lee Leahy | 320b7ca | 2017-03-09 09:42:48 -0800 | [diff] [blame] | 61 | [GPIO_SMI_STS] = "GPIO_SMI", |
| 62 | [GPIO_UNLOCK_SMI_STS] = "GPIO_UNLOCK_SSMI", |
Aaron Durbin | 7929dd0 | 2016-06-10 18:01:45 -0500 | [diff] [blame] | 63 | [MC_SMI_STS] = "MCSMI", |
| 64 | [TCO_SMI_STS] = "TCO", |
| 65 | [PERIODIC_SMI_STS] = "PERIODIC", |
| 66 | [SERIRQ_SMI_STS] = "SERIRQ", |
| 67 | [SMBUS_SMI_STS] = "SMBUS_SMI", |
| 68 | [XHCI_SMI_STS] = "XHCI", |
| 69 | [HSMBUS_SMI_STS] = "HOST_SMBUS", |
| 70 | [SCS_SMI_STS] = "SCS", |
| 71 | [PCIE_SMI_STS] = "PCI_EXP_SMI", |
| 72 | [SCC2_SMI_STS] = "SCC2", |
| 73 | [SPI_SSMI_STS] = "SPI_SSMI", |
| 74 | [SPI_SMI_STS] = "SPI", |
| 75 | [PMC_OCP_SMI_STS] = "OCP_CSE", |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 76 | }; |
| 77 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 78 | *a = ARRAY_SIZE(smi_sts_bits); |
| 79 | return smi_sts_bits; |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 80 | } |
| 81 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 82 | /* |
| 83 | * For APL/GLK this check for power button status if nothing else |
| 84 | * is indicating an SMI and SMIs aren't turned into SCIs. |
| 85 | * Apparently, there is no PM1 status bit in the SMI status |
| 86 | * register. That makes things difficult for |
| 87 | * determining if the power button caused an SMI. |
| 88 | */ |
| 89 | uint32_t soc_get_smi_status(uint32_t generic_sts) |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 90 | { |
Furquan Shaikh | 43810d9 | 2017-10-16 22:22:46 -0700 | [diff] [blame] | 91 | if (generic_sts == 0 && !(pmc_read_pm1_control() & SCI_EN)) { |
Barnali Sarkar | 9e55ff6 | 2017-06-05 20:01:14 +0530 | [diff] [blame] | 92 | uint16_t pm1_sts = inw(ACPI_BASE_ADDRESS + PM1_STS); |
Aaron Durbin | a554b71 | 2016-06-10 18:04:21 -0500 | [diff] [blame] | 93 | |
| 94 | /* Fake PM1 status bit if power button pressed. */ |
| 95 | if (pm1_sts & PWRBTN_STS) |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 96 | generic_sts |= (1 << FAKE_PM1_SMI_STS); |
Aaron Durbin | a554b71 | 2016-06-10 18:04:21 -0500 | [diff] [blame] | 97 | } |
| 98 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 99 | return generic_sts; |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 100 | } |
| 101 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 102 | const char *const *soc_tco_sts_array(size_t *a) |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 103 | { |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 104 | static const char *const tco_sts_bits[] = { |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 105 | [3] = "TIMEOUT", |
| 106 | [17] = "SECOND_TO", |
| 107 | }; |
| 108 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 109 | *a = ARRAY_SIZE(tco_sts_bits); |
| 110 | return tco_sts_bits; |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 111 | } |
| 112 | |
Furquan Shaikh | c4e652f | 2017-10-11 14:44:29 -0700 | [diff] [blame] | 113 | const char *const *soc_std_gpe_sts_array(size_t *a) |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 114 | { |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 115 | static const char *const gpe_sts_bits[] = { |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 116 | [0] = "PCIE_SCI", |
| 117 | [2] = "SWGPE", |
| 118 | [3] = "PCIE_WAKE0", |
| 119 | [4] = "PUNIT", |
| 120 | [6] = "PCIE_WAKE1", |
| 121 | [7] = "PCIE_WAKE2", |
| 122 | [8] = "PCIE_WAKE3", |
| 123 | [9] = "PCI_EXP", |
| 124 | [10] = "BATLOW", |
| 125 | [11] = "CSE_PME", |
| 126 | [12] = "XDCI_PME", |
| 127 | [13] = "XHCI_PME", |
| 128 | [14] = "AVS_PME", |
| 129 | [15] = "GPIO_TIER1_SCI", |
| 130 | [16] = "SMB_WAK", |
| 131 | [17] = "SATA_PME", |
| 132 | }; |
| 133 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 134 | *a = ARRAY_SIZE(gpe_sts_bits); |
| 135 | return gpe_sts_bits; |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 136 | } |
| 137 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 138 | void soc_clear_pm_registers(uintptr_t pmc_bar) |
Duncan Laurie | 2e79009 | 2016-09-19 12:05:49 -0700 | [diff] [blame] | 139 | { |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 140 | uint32_t gen_pmcon1; |
| 141 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 142 | gen_pmcon1 = read32((void *)(pmc_bar + GEN_PMCON1)); |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 143 | /* 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] | 144 | write32((void *)(pmc_bar + GEN_PMCON1), gen_pmcon1 & ~RPS); |
Hannah Williams | 01bc897 | 2016-02-04 20:13:34 -0800 | [diff] [blame] | 145 | } |
| 146 | |
Furquan Shaikh | c4e652f | 2017-10-11 14:44:29 -0700 | [diff] [blame] | 147 | 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] | 148 | { |
Aaron Durbin | e4d7abc | 2017-04-16 22:05:36 -0500 | [diff] [blame] | 149 | DEVTREE_CONST struct soc_intel_apollolake_config *config; |
Duncan Laurie | a673d1c | 2016-09-19 12:02:54 -0700 | [diff] [blame] | 150 | |
Kyösti Mälkki | d5f645c | 2019-09-28 00:20:27 +0300 | [diff] [blame] | 151 | config = config_of_soc(); |
Duncan Laurie | a673d1c | 2016-09-19 12:02:54 -0700 | [diff] [blame] | 152 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 153 | /* Assign to out variable */ |
| 154 | *dw0 = config->gpe0_dw1; |
| 155 | *dw1 = config->gpe0_dw2; |
| 156 | *dw2 = config->gpe0_dw3; |
| 157 | } |
Duncan Laurie | a673d1c | 2016-09-19 12:02:54 -0700 | [diff] [blame] | 158 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 159 | void soc_fill_power_state(struct chipset_power_state *ps) |
| 160 | { |
| 161 | uintptr_t pmc_bar0 = read_pmc_mmio_bar(); |
Duncan Laurie | a673d1c | 2016-09-19 12:02:54 -0700 | [diff] [blame] | 162 | |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 163 | ps->tco1_sts = tco_read_reg(TCO1_STS); |
| 164 | ps->tco2_sts = tco_read_reg(TCO2_STS); |
| 165 | |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 166 | ps->prsts = read32((void *)(pmc_bar0 + PRSTS)); |
| 167 | ps->gen_pmcon1 = read32((void *)(pmc_bar0 + GEN_PMCON1)); |
| 168 | ps->gen_pmcon2 = read32((void *)(pmc_bar0 + GEN_PMCON2)); |
| 169 | ps->gen_pmcon3 = read32((void *)(pmc_bar0 + GEN_PMCON3)); |
Duncan Laurie | a673d1c | 2016-09-19 12:02:54 -0700 | [diff] [blame] | 170 | |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 171 | printk(BIOS_DEBUG, "prsts: %08x\n", |
| 172 | ps->prsts); |
| 173 | printk(BIOS_DEBUG, "tco_sts: %04x %04x\n", |
| 174 | ps->tco1_sts, ps->tco2_sts); |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 175 | printk(BIOS_DEBUG, |
| 176 | "gen_pmcon1: %08x gen_pmcon2: %08x gen_pmcon3: %08x\n", |
| 177 | ps->gen_pmcon1, ps->gen_pmcon2, ps->gen_pmcon3); |
Duncan Laurie | a673d1c | 2016-09-19 12:02:54 -0700 | [diff] [blame] | 178 | } |
Andrey Petrov | 3b63753 | 2016-11-30 17:39:16 -0800 | [diff] [blame] | 179 | |
Hannah Williams | cdecc0d | 2018-01-04 11:57:14 -0800 | [diff] [blame] | 180 | /* Return 0, 3, or 5 to indicate the previous sleep state. */ |
| 181 | int soc_prev_sleep_state(const struct chipset_power_state *ps, |
| 182 | int prev_sleep_state) |
| 183 | { |
| 184 | /* WAK_STS bit will not be set when waking from G3 state */ |
| 185 | |
| 186 | if (!(ps->pm1_sts & WAK_STS) && (ps->gen_pmcon1 & COLD_BOOT_STS)) |
| 187 | prev_sleep_state = ACPI_S5; |
| 188 | return prev_sleep_state; |
| 189 | } |
| 190 | |
Andrey Petrov | 3b63753 | 2016-11-30 17:39:16 -0800 | [diff] [blame] | 191 | void enable_pm_timer_emulation(void) |
| 192 | { |
| 193 | /* ACPI PM timer emulation */ |
| 194 | msr_t msr; |
| 195 | /* |
| 196 | * The derived frequency is calculated as follows: |
| 197 | * (CTC_FREQ * msr[63:32]) >> 32 = target frequency. |
| 198 | * Back solve the multiplier so the 3.579545MHz ACPI timer |
| 199 | * frequency is used. |
| 200 | */ |
| 201 | msr.hi = (3579545ULL << 32) / CTC_FREQ; |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 202 | /* Set PM1 timer IO port and enable */ |
Barnali Sarkar | 9e55ff6 | 2017-06-05 20:01:14 +0530 | [diff] [blame] | 203 | msr.lo = EMULATE_PM_TMR_EN | (ACPI_BASE_ADDRESS + R_ACPI_PM1_TMR); |
Elyes HAOUAS | f212cf3 | 2018-12-18 10:24:55 +0100 | [diff] [blame] | 204 | wrmsr(MSR_EMULATE_PM_TIMER, msr); |
Andrey Petrov | 3b63753 | 2016-11-30 17:39:16 -0800 | [diff] [blame] | 205 | } |
Aaron Durbin | 3118b62 | 2017-09-15 11:48:53 -0600 | [diff] [blame] | 206 | |
| 207 | static int rtc_failed(uint32_t gen_pmcon1) |
| 208 | { |
| 209 | return !!(gen_pmcon1 & RPS); |
| 210 | } |
| 211 | |
| 212 | int soc_get_rtc_failed(void) |
| 213 | { |
| 214 | const struct chipset_power_state *ps = cbmem_find(CBMEM_ID_POWER_STATE); |
| 215 | |
| 216 | if (!ps) { |
| 217 | printk(BIOS_ERR, "Could not find power state in cbmem, RTC init aborted\n"); |
| 218 | return 1; |
| 219 | } |
| 220 | |
| 221 | return rtc_failed(ps->gen_pmcon1); |
| 222 | } |
Aaron Durbin | 0990fbf | 2017-09-15 15:23:04 -0600 | [diff] [blame] | 223 | |
| 224 | int vbnv_cmos_failed(void) |
| 225 | { |
Furquan Shaikh | 9d07910 | 2018-02-02 15:11:29 -0800 | [diff] [blame] | 226 | uintptr_t pmc_bar = read_pmc_mmio_bar(); |
| 227 | uint32_t gen_pmcon1 = read32((void *)(pmc_bar + GEN_PMCON1)); |
| 228 | int rtc_failure = rtc_failed(gen_pmcon1); |
| 229 | |
| 230 | if (rtc_failure) { |
| 231 | printk(BIOS_INFO, "RTC failed!\n"); |
| 232 | |
| 233 | /* We do not want to write 1 to clear-1 bits. Set them to 0. */ |
| 234 | gen_pmcon1 &= ~GEN_PMCON1_CLR1_BITS; |
| 235 | |
| 236 | /* RPS is write 0 to clear. */ |
| 237 | gen_pmcon1 &= ~RPS; |
| 238 | |
| 239 | write32((void *)(pmc_bar + GEN_PMCON1), gen_pmcon1); |
| 240 | } |
| 241 | |
| 242 | return rtc_failure; |
Aaron Durbin | 0990fbf | 2017-09-15 15:23:04 -0600 | [diff] [blame] | 243 | } |