blob: 3d0d4593ddf7b7ee2d07c17ab8296370dda2e059 [file] [log] [blame]
Hannah Williams01bc8972016-02-04 20:13:34 -08001/*
2 * This file is part of the coreboot project.
3 *
Hannah Williams01bc8972016-02-04 20:13:34 -08004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
Alexandru Gagniuca6339802016-04-05 12:40:24 -070016#define __SIMPLE_DEVICE__
17
Duncan Laurie2e790092016-09-19 12:05:49 -070018#include <arch/acpi.h>
Hannah Williams01bc8972016-02-04 20:13:34 -080019#include <arch/io.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020020#include <device/mmio.h>
Aaron Durbin3118b622017-09-15 11:48:53 -060021#include <cbmem.h>
Hannah Williams01bc8972016-02-04 20:13:34 -080022#include <console/console.h>
Andrey Petrov3b637532016-11-30 17:39:16 -080023#include <cpu/x86/msr.h>
Shaunak Saha93cdc8b2017-04-18 15:42:09 -070024#include <device/device.h>
25#include <device/pci.h>
Hannah Williams01bc8972016-02-04 20:13:34 -080026#include <device/pci_def.h>
Barnali Sarkar66fe0c42017-05-23 18:17:14 +053027#include <intelblocks/msr.h>
Shaunak Saha93cdc8b2017-04-18 15:42:09 -070028#include <intelblocks/pmclib.h>
Aaron Durbin3118b622017-09-15 11:48:53 -060029#include <intelblocks/rtc.h>
Subrata Banik7bc4dc52018-05-17 18:40:32 +053030#include <intelblocks/tco.h>
Hannah Williams01bc8972016-02-04 20:13:34 -080031#include <soc/iomap.h>
Andrey Petrov3b637532016-11-30 17:39:16 -080032#include <soc/cpu.h>
Alexandru Gagniuca6339802016-04-05 12:40:24 -070033#include <soc/pci_devs.h>
Hannah Williams01bc8972016-02-04 20:13:34 -080034#include <soc/pm.h>
Subrata Banik7bc4dc52018-05-17 18:40:32 +053035#include <soc/smbus.h>
Philipp Deppenwiesefea24292017-10-17 17:02:29 +020036#include <security/vboot/vbnv.h>
Elyes HAOUASadd76f92019-03-21 09:55:49 +010037
Duncan Lauriea673d1c2016-09-19 12:02:54 -070038#include "chip.h"
Hannah Williams01bc8972016-02-04 20:13:34 -080039
Alexandru Gagniuca6339802016-04-05 12:40:24 -070040static uintptr_t read_pmc_mmio_bar(void)
41{
Lijian Zhao91086802016-09-06 18:15:29 -070042 return PMC_BAR0;
Alexandru Gagniuca6339802016-04-05 12:40:24 -070043}
Hannah Williams01bc8972016-02-04 20:13:34 -080044
Shaunak Saha93cdc8b2017-04-18 15:42:09 -070045uintptr_t soc_read_pmc_base(void)
Shaunak Saha9a0c9ac2016-06-27 23:00:15 -070046{
47 return read_pmc_mmio_bar();
48}
49
Michael Niewöhnerb4d960b2019-11-02 12:14:06 +010050uint32_t *soc_pmc_etr_addr(void)
51{
52 return (uint32_t *)(soc_read_pmc_base() + ETR);
53}
54
Shaunak Saha93cdc8b2017-04-18 15:42:09 -070055const char *const *soc_smi_sts_array(size_t *a)
Hannah Williams01bc8972016-02-04 20:13:34 -080056{
Shaunak Saha93cdc8b2017-04-18 15:42:09 -070057 static const char *const smi_sts_bits[] = {
Subrata Banik4ab7ef92020-02-20 11:53:04 +053058 [BIOS_STS_BIT] = "BIOS",
59 [LEGACY_USB_STS_BIT] = "LEGACY USB",
60 [SMI_ON_SLP_EN_STS_BIT] = "SLP_SMI",
61 [APM_STS_BIT] = "APM",
62 [SWSMI_TMR_STS_BIT] = "SWSMI_TMR",
63 [PM1_STS_BIT] = "PM1",
64 [GPIO_STS_BIT] = "GPIO_SMI",
65 [GPIO_UNLOCK_SMI_STS_BIT] = "GPIO_UNLOCK_SSMI",
66 [MC_SMI_STS_BIT] = "MCSMI",
67 [TCO_STS_BIT] = "TCO",
68 [PERIODIC_STS_BIT] = "PERIODIC",
69 [SERIRQ_SMI_STS_BIT] = "SERIRQ",
70 [SMBUS_SMI_STS_BIT] = "SMBUS_SMI",
71 [XHCI_SMI_STS_BIT] = "XHCI",
72 [SCS_SMI_STS_BIT] = "HOST_SMBUS",
73 [SCS_SMI_STS_BIT] = "SCS",
74 [PCI_EXP_SMI_STS_BIT] = "PCI_EXP_SMI",
75 [SCC2_SMI_STS_BIT] = "SCC2",
76 [SPI_SSMI_STS_BIT] = "SPI_SSMI",
77 [SPI_SMI_STS_BIT] = "SPI",
78 [PMC_OCP_SMI_STS_BIT] = "OCP_CSE",
Hannah Williams01bc8972016-02-04 20:13:34 -080079 };
80
Shaunak Saha93cdc8b2017-04-18 15:42:09 -070081 *a = ARRAY_SIZE(smi_sts_bits);
82 return smi_sts_bits;
Hannah Williams01bc8972016-02-04 20:13:34 -080083}
84
Shaunak Saha93cdc8b2017-04-18 15:42:09 -070085/*
86 * For APL/GLK this check for power button status if nothing else
87 * is indicating an SMI and SMIs aren't turned into SCIs.
88 * Apparently, there is no PM1 status bit in the SMI status
89 * register. That makes things difficult for
90 * determining if the power button caused an SMI.
91 */
92uint32_t soc_get_smi_status(uint32_t generic_sts)
Hannah Williams01bc8972016-02-04 20:13:34 -080093{
Furquan Shaikh43810d92017-10-16 22:22:46 -070094 if (generic_sts == 0 && !(pmc_read_pm1_control() & SCI_EN)) {
Barnali Sarkar9e55ff62017-06-05 20:01:14 +053095 uint16_t pm1_sts = inw(ACPI_BASE_ADDRESS + PM1_STS);
Aaron Durbina554b712016-06-10 18:04:21 -050096
97 /* Fake PM1 status bit if power button pressed. */
98 if (pm1_sts & PWRBTN_STS)
Subrata Banik4ab7ef92020-02-20 11:53:04 +053099 generic_sts |= (1 << PM1_STS_BIT);
Aaron Durbina554b712016-06-10 18:04:21 -0500100 }
101
Shaunak Saha93cdc8b2017-04-18 15:42:09 -0700102 return generic_sts;
Hannah Williams01bc8972016-02-04 20:13:34 -0800103}
104
Shaunak Saha93cdc8b2017-04-18 15:42:09 -0700105const char *const *soc_tco_sts_array(size_t *a)
Hannah Williams01bc8972016-02-04 20:13:34 -0800106{
Shaunak Saha93cdc8b2017-04-18 15:42:09 -0700107 static const char *const tco_sts_bits[] = {
Hannah Williams01bc8972016-02-04 20:13:34 -0800108 [3] = "TIMEOUT",
109 [17] = "SECOND_TO",
110 };
111
Shaunak Saha93cdc8b2017-04-18 15:42:09 -0700112 *a = ARRAY_SIZE(tco_sts_bits);
113 return tco_sts_bits;
Hannah Williams01bc8972016-02-04 20:13:34 -0800114}
115
Furquan Shaikhc4e652f2017-10-11 14:44:29 -0700116const char *const *soc_std_gpe_sts_array(size_t *a)
Hannah Williams01bc8972016-02-04 20:13:34 -0800117{
Shaunak Saha93cdc8b2017-04-18 15:42:09 -0700118 static const char *const gpe_sts_bits[] = {
Hannah Williams01bc8972016-02-04 20:13:34 -0800119 [0] = "PCIE_SCI",
120 [2] = "SWGPE",
121 [3] = "PCIE_WAKE0",
122 [4] = "PUNIT",
123 [6] = "PCIE_WAKE1",
124 [7] = "PCIE_WAKE2",
125 [8] = "PCIE_WAKE3",
126 [9] = "PCI_EXP",
127 [10] = "BATLOW",
128 [11] = "CSE_PME",
129 [12] = "XDCI_PME",
130 [13] = "XHCI_PME",
131 [14] = "AVS_PME",
132 [15] = "GPIO_TIER1_SCI",
133 [16] = "SMB_WAK",
134 [17] = "SATA_PME",
135 };
136
Shaunak Saha93cdc8b2017-04-18 15:42:09 -0700137 *a = ARRAY_SIZE(gpe_sts_bits);
138 return gpe_sts_bits;
Hannah Williams01bc8972016-02-04 20:13:34 -0800139}
140
Shaunak Saha93cdc8b2017-04-18 15:42:09 -0700141void soc_clear_pm_registers(uintptr_t pmc_bar)
Duncan Laurie2e790092016-09-19 12:05:49 -0700142{
Hannah Williams01bc8972016-02-04 20:13:34 -0800143 uint32_t gen_pmcon1;
144
Shaunak Saha93cdc8b2017-04-18 15:42:09 -0700145 gen_pmcon1 = read32((void *)(pmc_bar + GEN_PMCON1));
Hannah Williams01bc8972016-02-04 20:13:34 -0800146 /* Clear the status bits. The RPS field is cleared on a 0 write. */
Shaunak Saha93cdc8b2017-04-18 15:42:09 -0700147 write32((void *)(pmc_bar + GEN_PMCON1), gen_pmcon1 & ~RPS);
Hannah Williams01bc8972016-02-04 20:13:34 -0800148}
149
Furquan Shaikhc4e652f2017-10-11 14:44:29 -0700150void soc_get_gpi_gpe_configs(uint8_t *dw0, uint8_t *dw1, uint8_t *dw2)
Hannah Williams01bc8972016-02-04 20:13:34 -0800151{
Aaron Durbine4d7abc2017-04-16 22:05:36 -0500152 DEVTREE_CONST struct soc_intel_apollolake_config *config;
Duncan Lauriea673d1c2016-09-19 12:02:54 -0700153
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300154 config = config_of_soc();
Duncan Lauriea673d1c2016-09-19 12:02:54 -0700155
Shaunak Saha93cdc8b2017-04-18 15:42:09 -0700156 /* Assign to out variable */
157 *dw0 = config->gpe0_dw1;
158 *dw1 = config->gpe0_dw2;
159 *dw2 = config->gpe0_dw3;
160}
Duncan Lauriea673d1c2016-09-19 12:02:54 -0700161
Shaunak Saha93cdc8b2017-04-18 15:42:09 -0700162void soc_fill_power_state(struct chipset_power_state *ps)
163{
164 uintptr_t pmc_bar0 = read_pmc_mmio_bar();
Duncan Lauriea673d1c2016-09-19 12:02:54 -0700165
Subrata Banik7bc4dc52018-05-17 18:40:32 +0530166 ps->tco1_sts = tco_read_reg(TCO1_STS);
167 ps->tco2_sts = tco_read_reg(TCO2_STS);
168
Shaunak Saha93cdc8b2017-04-18 15:42:09 -0700169 ps->prsts = read32((void *)(pmc_bar0 + PRSTS));
170 ps->gen_pmcon1 = read32((void *)(pmc_bar0 + GEN_PMCON1));
171 ps->gen_pmcon2 = read32((void *)(pmc_bar0 + GEN_PMCON2));
172 ps->gen_pmcon3 = read32((void *)(pmc_bar0 + GEN_PMCON3));
Duncan Lauriea673d1c2016-09-19 12:02:54 -0700173
Subrata Banik7bc4dc52018-05-17 18:40:32 +0530174 printk(BIOS_DEBUG, "prsts: %08x\n",
175 ps->prsts);
176 printk(BIOS_DEBUG, "tco_sts: %04x %04x\n",
177 ps->tco1_sts, ps->tco2_sts);
Shaunak Saha93cdc8b2017-04-18 15:42:09 -0700178 printk(BIOS_DEBUG,
179 "gen_pmcon1: %08x gen_pmcon2: %08x gen_pmcon3: %08x\n",
180 ps->gen_pmcon1, ps->gen_pmcon2, ps->gen_pmcon3);
Duncan Lauriea673d1c2016-09-19 12:02:54 -0700181}
Andrey Petrov3b637532016-11-30 17:39:16 -0800182
Hannah Williamscdecc0d2018-01-04 11:57:14 -0800183/* Return 0, 3, or 5 to indicate the previous sleep state. */
184int soc_prev_sleep_state(const struct chipset_power_state *ps,
185 int prev_sleep_state)
186{
187 /* WAK_STS bit will not be set when waking from G3 state */
188
189 if (!(ps->pm1_sts & WAK_STS) && (ps->gen_pmcon1 & COLD_BOOT_STS))
190 prev_sleep_state = ACPI_S5;
191 return prev_sleep_state;
192}
193
Andrey Petrov3b637532016-11-30 17:39:16 -0800194void enable_pm_timer_emulation(void)
195{
196 /* ACPI PM timer emulation */
197 msr_t msr;
198 /*
199 * The derived frequency is calculated as follows:
200 * (CTC_FREQ * msr[63:32]) >> 32 = target frequency.
201 * Back solve the multiplier so the 3.579545MHz ACPI timer
202 * frequency is used.
203 */
204 msr.hi = (3579545ULL << 32) / CTC_FREQ;
Shaunak Saha93cdc8b2017-04-18 15:42:09 -0700205 /* Set PM1 timer IO port and enable */
Barnali Sarkar9e55ff62017-06-05 20:01:14 +0530206 msr.lo = EMULATE_PM_TMR_EN | (ACPI_BASE_ADDRESS + R_ACPI_PM1_TMR);
Elyes HAOUASf212cf32018-12-18 10:24:55 +0100207 wrmsr(MSR_EMULATE_PM_TIMER, msr);
Andrey Petrov3b637532016-11-30 17:39:16 -0800208}
Aaron Durbin3118b622017-09-15 11:48:53 -0600209
210static int rtc_failed(uint32_t gen_pmcon1)
211{
212 return !!(gen_pmcon1 & RPS);
213}
214
215int soc_get_rtc_failed(void)
216{
217 const struct chipset_power_state *ps = cbmem_find(CBMEM_ID_POWER_STATE);
218
219 if (!ps) {
220 printk(BIOS_ERR, "Could not find power state in cbmem, RTC init aborted\n");
221 return 1;
222 }
223
224 return rtc_failed(ps->gen_pmcon1);
225}
Aaron Durbin0990fbf2017-09-15 15:23:04 -0600226
227int vbnv_cmos_failed(void)
228{
Furquan Shaikh9d079102018-02-02 15:11:29 -0800229 uintptr_t pmc_bar = read_pmc_mmio_bar();
230 uint32_t gen_pmcon1 = read32((void *)(pmc_bar + GEN_PMCON1));
231 int rtc_failure = rtc_failed(gen_pmcon1);
232
233 if (rtc_failure) {
234 printk(BIOS_INFO, "RTC failed!\n");
235
236 /* We do not want to write 1 to clear-1 bits. Set them to 0. */
237 gen_pmcon1 &= ~GEN_PMCON1_CLR1_BITS;
238
239 /* RPS is write 0 to clear. */
240 gen_pmcon1 &= ~RPS;
241
242 write32((void *)(pmc_bar + GEN_PMCON1), gen_pmcon1);
243 }
244
245 return rtc_failure;
Aaron Durbin0990fbf2017-09-15 15:23:04 -0600246}
Eugene Myersebc84232020-01-21 16:46:16 -0500247
248/* STM Support */
249uint16_t get_pmbase(void)
250{
251 return (uint16_t) ACPI_BASE_ADDRESS;
252}