| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#define __SIMPLE_DEVICE__ |
| 9 |
|
| 10 |
#include <acpi/acpi_pm.h> |
| 11 |
#include <console/console.h> |
| 12 |
#include <device/mmio.h> |
| 13 |
#include <device/device.h> |
| 14 |
#include <device/pci.h> |
| 15 |
#include <intelblocks/pmclib.h> |
| 16 |
#include <intelblocks/rtc.h> |
| 17 |
#include <intelblocks/tco.h> |
| 18 |
#include <intelpch/espi.h> |
| 19 |
#include <security/vboot/vbnv.h> |
| 20 |
#include <soc/gpe.h> |
| 21 |
#include <soc/gpio.h> |
| 22 |
#include <soc/iomap.h> |
| 23 |
#include <soc/pci_devs.h> |
| 24 |
#include <soc/pm.h> |
| 25 |
#include <soc/smbus.h> |
| 26 |
#include <soc/soc_chip.h> |
| 27 |
#include <static.h> |
| 28 |
#include <types.h> |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
const char *const *soc_smi_sts_array(size_t *a) |
| 34 |
{ |
| 35 |
static const char *const smi_sts_bits[] = { |
| 36 |
[BIOS_STS_BIT] = "BIOS", |
| 37 |
[LEGACY_USB_STS_BIT] = "LEGACY_USB", |
| 38 |
[SMI_ON_SLP_EN_STS_BIT] = "SLP_SMI", |
| 39 |
[APM_STS_BIT] = "APM", |
| 40 |
[SWSMI_TMR_STS_BIT] = "SWSMI_TMR", |
| 41 |
[PM1_STS_BIT] = "PM1", |
| 42 |
[GPE0_STS_BIT] = "GPE0", |
| 43 |
[GPIO_STS_BIT] = "GPI", |
| 44 |
[MCSMI_STS_BIT] = "MCSMI", |
| 45 |
[DEVMON_STS_BIT] = "DEVMON", |
| 46 |
[TCO_STS_BIT] = "TCO", |
| 47 |
[PERIODIC_STS_BIT] = "PERIODIC", |
| 48 |
[SERIRQ_SMI_STS_BIT] = "SERIRQ_SMI", |
| 49 |
[SMBUS_SMI_STS_BIT] = "SMBUS_SMI", |
| 50 |
[PCI_EXP_SMI_STS_BIT] = "PCI_EXP_SMI", |
| 51 |
[MONITOR_STS_BIT] = "MONITOR", |
| 52 |
[SPI_SMI_STS_BIT] = "SPI", |
| 53 |
[GPIO_UNLOCK_SMI_STS_BIT] = "GPIO_UNLOCK", |
| 54 |
[ESPI_SMI_STS_BIT] = "ESPI_SMI", |
| 55 |
}; |
| 56 |
|
| 57 |
*a = ARRAY_SIZE(smi_sts_bits); |
| 58 |
return smi_sts_bits; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
const char *const *soc_tco_sts_array(size_t *a) |
| 65 |
{ |
| 66 |
static const char *const tco_sts_bits[] = { |
| 67 |
[0] = "NMI2SMI", |
| 68 |
[1] = "SW_TCO", |
| 69 |
[2] = "TCO_INT", |
| 70 |
[3] = "TIMEOUT", |
| 71 |
[7] = "NEWCENTURY", |
| 72 |
[8] = "BIOSWR", |
| 73 |
[9] = "DMISCI", |
| 74 |
[10] = "DMISMI", |
| 75 |
[12] = "DMISERR", |
| 76 |
[13] = "SLVSEL", |
| 77 |
[16] = "INTRD_DET", |
| 78 |
[17] = "SECOND_TO", |
| 79 |
[18] = "BOOT", |
| 80 |
[20] = "SMLINK_SLV" |
| 81 |
}; |
| 82 |
|
| 83 |
*a = ARRAY_SIZE(tco_sts_bits); |
| 84 |
return tco_sts_bits; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
const char *const *soc_std_gpe_sts_array(size_t *a) |
| 91 |
{ |
| 92 |
static const char *const gpe_sts_bits[] = { |
| 93 |
[1] = "HOTPLUG", |
| 94 |
[2] = "SWGPE", |
| 95 |
[6] = "TCO_SCI", |
| 96 |
[7] = "SMB_WAK", |
| 97 |
[9] = "PCI_EXP", |
| 98 |
[10] = "BATLOW", |
| 99 |
[11] = "PME", |
| 100 |
[12] = "ME", |
| 101 |
[13] = "PME_B0", |
| 102 |
[14] = "eSPI", |
| 103 |
[15] = "GPIO Tier-2", |
| 104 |
[16] = "LAN_WAKE", |
| 105 |
[18] = "WADT" |
| 106 |
}; |
| 107 |
|
| 108 |
*a = ARRAY_SIZE(gpe_sts_bits); |
| 109 |
return gpe_sts_bits; |
| 110 |
} |
| 111 |
|
| 112 |
void pmc_set_disb(void) |
| 113 |
{ |
| 114 |
|
| 115 |
uint8_t disb_val; |
| 116 |
|
| 117 |
uint8_t *addr = (uint8_t *)(pmc_mmio_regs() + GEN_PMCON_A + 2); |
| 118 |
|
| 119 |
disb_val = read8(addr); |
| 120 |
disb_val |= (DISB >> 16); |
| 121 |
|
| 122 |
|
| 123 |
disb_val &= ~((MS4V | SUS_PWR_FLR) >> 16); |
| 124 |
write8(addr, disb_val); |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
uint8_t *pmc_mmio_regs(void) |
| 134 |
{ |
| 135 |
return (void *)(uintptr_t)PCH_PWRM_BASE_ADDRESS; |
| 136 |
} |
| 137 |
|
| 138 |
uintptr_t soc_read_pmc_base(void) |
| 139 |
{ |
| 140 |
return (uintptr_t)pmc_mmio_regs(); |
| 141 |
} |
| 142 |
|
| 143 |
uint32_t *soc_pmc_etr_addr(void) |
| 144 |
{ |
| 145 |
return (uint32_t *)(soc_read_pmc_base() + ETR); |
| 146 |
} |
| 147 |
|
| 148 |
static void pmc_gpe0_different_values(const struct soc_intel_pantherlake_config *config) |
| 149 |
{ |
| 150 |
bool all_zero = (config->pmc_gpe0_dw0 == 0) && |
| 151 |
(config->pmc_gpe0_dw1 == 0) && |
| 152 |
(config->pmc_gpe0_dw2 == 0); |
| 153 |
|
| 154 |
|
| 155 |
bool all_different = (config->pmc_gpe0_dw0 != config->pmc_gpe0_dw1) && |
| 156 |
(config->pmc_gpe0_dw0 != config->pmc_gpe0_dw2) && |
| 157 |
(config->pmc_gpe0_dw1 != config->pmc_gpe0_dw2); |
| 158 |
|
| 159 |
assert(all_different || all_zero); |
| 160 |
} |
| 161 |
|
| 162 |
void soc_get_gpi_gpe_configs(uint8_t *dw0, uint8_t *dw1, uint8_t *dw2) |
| 163 |
{ |
| 164 |
DEVTREE_CONST struct soc_intel_pantherlake_config *config; |
| 165 |
|
| 166 |
config = config_of_soc(); |
| 167 |
if (config == NULL) { |
| 168 |
printk(BIOS_ERR, "Configuration could not be retrieved.\n"); |
| 169 |
return; |
| 170 |
} |
| 171 |
|
| 172 |
pmc_gpe0_different_values(config); |
| 173 |
|
| 174 |
|
| 175 |
*dw0 = config->pmc_gpe0_dw0; |
| 176 |
*dw1 = config->pmc_gpe0_dw1; |
| 177 |
*dw2 = config->pmc_gpe0_dw2; |
| 178 |
} |
| 179 |
|
| 180 |
static int rtc_failed(uint32_t gen_pmcon_b) |
| 181 |
{ |
| 182 |
return !!(gen_pmcon_b & RTC_BATTERY_DEAD); |
| 183 |
} |
| 184 |
|
| 185 |
int soc_get_rtc_failed(void) |
| 186 |
{ |
| 187 |
const struct chipset_power_state *ps; |
| 188 |
|
| 189 |
if (acpi_fetch_pm_state(&ps, PS_CLAIMER_RTC) < 0) |
| 190 |
return 1; |
| 191 |
|
| 192 |
return rtc_failed(ps->gen_pmcon_b); |
| 193 |
} |
| 194 |
|
| 195 |
int vbnv_cmos_failed(void) |
| 196 |
{ |
| 197 |
return rtc_failed(read32(pmc_mmio_regs() + GEN_PMCON_B)); |
| 198 |
} |
| 199 |
|
| 200 |
static inline int deep_s3_enabled(void) |
| 201 |
{ |
| 202 |
uint32_t deep_s3_pol; |
| 203 |
|
| 204 |
deep_s3_pol = read32(pmc_mmio_regs() + S3_PWRGATE_POL); |
| 205 |
return !!(deep_s3_pol & (S3DC_GATE_SUS | S3AC_GATE_SUS)); |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
int soc_prev_sleep_state(const struct chipset_power_state *ps, int prev_sleep_state) |
| 210 |
{ |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
if (!(ps->pm1_sts & WAK_STS) && (ps->gen_pmcon_a & (PWR_FLR | SUS_PWR_FLR))) |
| 217 |
prev_sleep_state = ACPI_S5; |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
if (prev_sleep_state == ACPI_S3) { |
| 225 |
|
| 226 |
uint32_t mask = PWR_FLR; |
| 227 |
|
| 228 |
|
| 229 |
if (!deep_s3_enabled()) |
| 230 |
mask |= SUS_PWR_FLR; |
| 231 |
|
| 232 |
if (ps->gen_pmcon_a & mask) |
| 233 |
prev_sleep_state = ACPI_S5; |
| 234 |
} |
| 235 |
|
| 236 |
return prev_sleep_state; |
| 237 |
} |
| 238 |
|
| 239 |
void soc_fill_power_state(struct chipset_power_state *ps) |
| 240 |
{ |
| 241 |
uint8_t *pmc; |
| 242 |
|
| 243 |
ps->tco1_sts = tco_read_reg(TCO1_STS); |
| 244 |
ps->tco2_sts = tco_read_reg(TCO2_STS); |
| 245 |
|
| 246 |
printk(BIOS_DEBUG, "TCO_STS: %04x %04x\n", ps->tco1_sts, ps->tco2_sts); |
| 247 |
|
| 248 |
pmc = pmc_mmio_regs(); |
| 249 |
ps->gen_pmcon_a = read32(pmc + GEN_PMCON_A); |
| 250 |
ps->gen_pmcon_b = read32(pmc + GEN_PMCON_B); |
| 251 |
ps->gblrst_cause[0] = read32(pmc + GBLRST_CAUSE0); |
| 252 |
ps->gblrst_cause[1] = read32(pmc + GBLRST_CAUSE1); |
| 253 |
ps->hpr_cause0 = read32(pmc + HPR_CAUSE0); |
| 254 |
|
| 255 |
printk(BIOS_DEBUG, "GEN_PMCON: %08x %08x\n", |
| 256 |
ps->gen_pmcon_a, ps->gen_pmcon_b); |
| 257 |
|
| 258 |
printk(BIOS_DEBUG, "GBLRST_CAUSE: %08x %08x\n", |
| 259 |
ps->gblrst_cause[0], ps->gblrst_cause[1]); |
| 260 |
|
| 261 |
printk(BIOS_DEBUG, "HPR_CAUSE0: %08x\n", ps->hpr_cause0); |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
uint16_t get_pmbase(void) |
| 266 |
{ |
| 267 |
return (uint16_t)ACPI_BASE_ADDRESS; |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
void pmc_soc_set_afterg3_en(const bool on) |
| 275 |
{ |
| 276 |
uint8_t reg8; |
| 277 |
uint8_t *const pmcbase = pmc_mmio_regs(); |
| 278 |
|
| 279 |
reg8 = read8(pmcbase + GEN_PMCON_A); |
| 280 |
if (on) |
| 281 |
reg8 &= ~SLEEP_AFTER_POWER_FAIL; |
| 282 |
else |
| 283 |
reg8 |= SLEEP_AFTER_POWER_FAIL; |
| 284 |
write8(pmcbase + GEN_PMCON_A, reg8); |
| 285 |
} |