Debian Codegraph @

src/soc/intel/xeon_sp/ebg/soc_pmutil.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 /*
4 * Helper functions for dealing with power management registers
5 * and the differences between PCH variants.
6 */
7
8 #define __SIMPLE_DEVICE__
9
10 #include <console/console.h>
11 #include <device/pci.h>
12 #include <intelblocks/pmclib.h>
13 #include <intelblocks/rtc.h>
14 #include <soc/pm.h>
15 #include <soc/pmc.h>
16
17 uint8_t *pmc_mmio_regs(void)
18 {
19 /* PMC PWRMBASE can be hidden after FSP-S so can't be accessed using PCI CSR,
20 * hence use hard-coded address */
21 return (void *)(uintptr_t)PCH_PWRM_BASE_ADDRESS;
22 }
23
24 uintptr_t soc_read_pmc_base(void)
25 {
26 return (uintptr_t)(pmc_mmio_regs());
27 }
28
29 uint32_t *soc_pmc_etr_addr(void)
30 {
31 /*
32 * The pointer returned must not be cached, because the address depends on the
33 * MMCONF base address and the assigned PCI bus number, which both may change
34 * during the boot process!
35 */
36 return (uint32_t *)(soc_read_pmc_base() + ETR);
37 }
38
39 int soc_get_rtc_failed(void)
40 {
41 uint32_t pmcon_b = read32(pmc_mmio_regs() + GEN_PMCON_B);
42 int rtc_fail = !!(pmcon_b & RTC_BATTERY_DEAD);
43
44 if (rtc_fail)
45 printk(BIOS_ERR, "%s: RTC battery dead or removed\n", __func__);
46
47 return rtc_fail;
48 }
49
50 void soc_fill_power_state(struct chipset_power_state *ps)
51 {
52 uint8_t *pmc;
53
54 pmc = pmc_mmio_regs();
55
56 ps->gen_pmcon_a = read32(pmc + GEN_PMCON_A);
57 ps->gen_pmcon_b = read32(pmc + GEN_PMCON_B);
58 ps->gblrst_cause[0] = read32(pmc + GBLRST_CAUSE0);
59 ps->gblrst_cause[1] = read32(pmc + GBLRST_CAUSE1);
60
61 printk(BIOS_DEBUG, "GEN_PMCON: %08x %08x\n", ps->gen_pmcon_a, ps->gen_pmcon_b);
62
63 printk(BIOS_DEBUG, "GBLRST_CAUSE: %08x %08x\n", ps->gblrst_cause[0],
64 ps->gblrst_cause[1]);
65 }
66
67 /*
68 * Set which power state system will be after reapplying
69 * the power (from G3 State)
70 */
71 void pmc_soc_set_afterg3_en(const bool on)
72 {
73 uint8_t reg8;
74 uint8_t *const pmcbase = pmc_mmio_regs();
75
76 reg8 = read8(pmcbase + GEN_PMCON_A);
77 if (on)
78 reg8 &= ~SLEEP_AFTER_POWER_FAIL;
79 else
80 reg8 |= SLEEP_AFTER_POWER_FAIL;
81 write8(pmcbase + GEN_PMCON_A, reg8);
82 }
83
84 void pmc_lock_smi(void)
85 {
86 printk(BIOS_DEBUG, "Locking SMM enable.\n");
87 pmc_or_mmio32(GEN_PMCON_B, SMI_LOCK);
88 }
89
90 void pmc_lockdown_config(void)
91 {
92 /* PMSYNC */
93 pmc_or_mmio32(PMSYNC_MISC_CFG, PMSYNC_LOCK);
94
95 /* Make sure payload/OS can't trigger global reset */
96 pmc_global_reset_disable_and_lock();
97
98 /* Lock PMC stretch policy */
99 pmc_or_mmio32(GEN_PMCON_B, SLP_STR_POL_LOCK);
100 pmc_or_mmio32(ST_PG_FDIS1, ST_FDIS_LK);
101 pmc_or_mmio32(PM_CFG, PMC_LOCK);
102 }