2 * This file is part of the coreboot project.
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.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 * Helper functions for dealing with power management registers
17 * and the differences between PCH variants.
20 #include <arch/acpi.h>
21 #include <device/mmio.h>
22 #include <device/pci_ops.h>
23 #include <device/device.h>
24 #include <device/pci.h>
25 #include <device/pci_def.h>
26 #include <console/console.h>
27 #include <intelblocks/pmclib.h>
28 #include <intelblocks/lpc_lib.h>
29 #include <intelblocks/tco.h>
32 #include <soc/iomap.h>
33 #include <soc/pci_devs.h>
36 #include <soc/smbus.h>
37 #include <security/vboot/vbnv.h>
45 const char *const *soc_smi_sts_array(size_t *smi_arr
)
47 static const char *const smi_sts_bits
[] = {
71 *smi_arr
= ARRAY_SIZE(smi_sts_bits
);
79 const char *const *soc_tco_sts_array(size_t *tco_arr
)
81 static const char *const tco_sts_bits
[] = {
98 *tco_arr
= ARRAY_SIZE(tco_sts_bits
);
106 const char *const *soc_std_gpe_sts_array(size_t *gpe_arr
)
108 static const char *const gpe_sts_bits
[] = {
119 [15] = "GPIO Tier-2",
124 *gpe_arr
= ARRAY_SIZE(gpe_sts_bits
);
128 int acpi_sci_irq(void)
130 int scis
= pci_read_config32(PCH_DEV_PMC
, ACTL
) & SCI_IRQ_SEL
;
133 /* Determine how SCI is routed. */
138 sci_irq
= scis
- SCIS_IRQ9
+ 9;
144 sci_irq
= scis
- SCIS_IRQ20
+ 20;
147 printk(BIOS_DEBUG
, "Invalid SCI route! Defaulting to IRQ9.\n");
152 printk(BIOS_DEBUG
, "SCI is IRQ%d\n", sci_irq
);
156 uint8_t *pmc_mmio_regs(void)
160 reg32
= pci_read_config32(PCH_DEV_PMC
, PWRMBASE
);
162 /* 4KiB alignment. */
165 return (void *)(uintptr_t) reg32
;
168 uintptr_t soc_read_pmc_base(void)
170 return (uintptr_t) (pmc_mmio_regs());
173 uint32_t *soc_pmc_etr_addr(void)
176 * The pointer returned must not be cached, because the address depends on the
177 * MMCONF base address and the assigned PCI bus number, which both may change
178 * during the boot process!
180 return pci_mmio_config32_addr(PCH_DEVFN_PMC
<< 12, ETR
);
183 void soc_get_gpi_gpe_configs(uint8_t *dw0
, uint8_t *dw1
, uint8_t *dw2
)
185 DEVTREE_CONST
struct soc_intel_skylake_config
*config
;
187 config
= config_of_soc();
189 /* Assign to out variable */
190 *dw0
= config
->gpe0_dw0
;
191 *dw1
= config
->gpe0_dw1
;
192 *dw2
= config
->gpe0_dw2
;
195 int rtc_failure(void)
199 /* PMC Controller Device 0x1F, Func 02 */
200 #if defined(__SIMPLE_DEVICE__)
201 pci_devfn_t dev
= PCH_DEV_PMC
;
203 struct device
*dev
= PCH_DEV_PMC
;
205 reg8
= pci_read_config8(dev
, GEN_PMCON_B
);
206 rtc_failed
= reg8
& RTC_BATTERY_DEAD
;
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
);
216 int vbnv_cmos_failed(void)
218 return rtc_failure();
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
)
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.
230 if (!(ps
->pm1_sts
& WAK_STS
) &&
231 (ps
->gen_pmcon_b
& (PWR_FLR
| SUS_PWR_FLR
)))
232 prev_sleep_state
= ACPI_S5
;
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.
239 if (prev_sleep_state
== ACPI_S3
) {
240 /* PWR_FLR represents deep sleep power well loss. */
241 uint32_t mask
= PWR_FLR
;
243 /* If deep s3 isn't enabled check the suspend well too. */
244 if (!deep_s3_enabled())
247 if (ps
->gen_pmcon_b
& mask
)
248 prev_sleep_state
= ACPI_S5
;
250 return prev_sleep_state
;
253 void soc_fill_power_state(struct chipset_power_state
*ps
)
257 ps
->tco1_sts
= tco_read_reg(TCO1_STS
);
258 ps
->tco2_sts
= tco_read_reg(TCO2_STS
);
260 printk(BIOS_DEBUG
, "TCO_STS: %04x %04x\n",
261 ps
->tco1_sts
, ps
->tco2_sts
);
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
);
266 pmc
= pmc_mmio_regs();
267 ps
->gblrst_cause
[0] = read32(pmc
+ GBLRST_CAUSE0
);
268 ps
->gblrst_cause
[1] = read32(pmc
+ GBLRST_CAUSE1
);
270 printk(BIOS_DEBUG
, "GEN_PMCON: %08x %08x\n",
271 ps
->gen_pmcon_a
, ps
->gen_pmcon_b
);
273 printk(BIOS_DEBUG
, "GBLRST_CAUSE: %08x %08x\n",
274 ps
->gblrst_cause
[0], ps
->gblrst_cause
[1]);
278 uint16_t get_pmbase(void)
280 return ACPI_BASE_ADDRESS
;