Debian Codegraph @

src/soc/intel/common/block/include/intelblocks/pmclib.h

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #ifndef SOC_INTEL_COMMON_BLOCK_PMCLIB_H
4 #define SOC_INTEL_COMMON_BLOCK_PMCLIB_H
5
6 #include <device/pci_type.h>
7 #include <types.h>
8
9 #define PCH_PMC_EPOC 0x18EC
10
11 /*
12 * GPE1 support is introduced in PTL. The existing standard GPE
13 * functions will cover GPE1 when SOC_INTEL_COMMON_BLOCK_ACPI_HAVE_GPE1 is
14 * selected. In addition, the following SOC GPE1 defines are required in common
15 * code but not present in older platform headers. Therefore, the dummy entries
16 * are added here for platforms without GPE1 support.
17 */
18 #if !CONFIG(SOC_INTEL_COMMON_BLOCK_ACPI_HAVE_GPE1)
19 #define GPE1_STS(x) (0x0 + ((x) * 4))
20 #define GPE1_EN(x) (0x0 + ((x) * 4))
21 #define GPE1_REG_MAX 0
22 #endif
23
24 /**
25 * enum pch_pmc_xtal - External crystal oscillator frequency.
26 * @XTAL_24_MHZ: 24 MHz external crystal.
27 * @XTAL_19_2_MHZ: 19.2 MHz external crystal.
28 * @XTAL_38_4_MHZ: 38.4 MHz external crystal.
29 * @XTAL_UNKNOWN_FREQ: Unsupported external crystal.
30 */
31 enum pch_pmc_xtal {
32 XTAL_24_MHZ,
33 XTAL_19_2_MHZ,
34 XTAL_38_4_MHZ,
35 XTAL_UNKNOWN_FREQ = 0xf,
36 };
37
38 /*
39 * pmc_get_xtal_freq() - Return &enum pch_pmc_xtal corresponding to
40 * frequency of external oscillator.
41 */
42 enum pch_pmc_xtal pmc_get_xtal_freq(void);
43
44 /*
45 * pmc_send_pci_enum_done() - send PMC IPC to inform both BIOS Reset
46 * and PCI enumeration is done.
47 */
48 void pmc_send_bios_reset_pci_enum_done(void);
49
50 /* Forward declare the power state struct here */
51 struct chipset_power_state;
52
53 /*
54 * This is implemented as weak function in common pmc lib.
55 * Clears all power management related registers as the boot
56 * flow is past the point of needing to maintain the values.
57 */
58 void soc_clear_pm_registers(uintptr_t pmc_bar);
59
60 /*
61 * This is implemented as weak function in common pmc lib and deals with any
62 * soc specific quarks. Returns SMI status bits.
63 */
64 uint32_t soc_get_smi_status(uint32_t generic_sts);
65
66 /*
67 * This function is specific to soc and is defined as weak in common
68 * pmclib file. SOC code can implement it for any special condition
69 * specific to the soc e.g. in SKL in handles deep S3 scenario.
70 * Return ACPI_SX values to indicate the previous sleep state.
71 */
72 int soc_prev_sleep_state(const struct chipset_power_state *ps,
73 int prev_sleep_state);
74
75 /* PM1 */
76 void pmc_update_pm1_enable(uint16_t events);
77 uint16_t pmc_read_pm1_enable(void);
78
79 uint32_t pmc_read_pm1_control(void);
80 void pmc_write_pm1_control(uint32_t pm1_cnt);
81
82 /*
83 * Function to print, clear, and return SMI status bits in SMI_STS
84 * register. This function internally calls pmc_reset_smi_status with
85 * extra functionality of printing the set smi_sts bits.
86 */
87 uint32_t pmc_clear_smi_status(void);
88
89 /*
90 * Function to return the 32 bit value of SMI control and enable register
91 * used to check which smi's are enabled.
92 */
93 uint32_t pmc_get_smi_en(void);
94
95 /* Enable SMI event in SMI control and enable register */
96 void pmc_enable_smi(uint32_t mask);
97
98 /* Disable SMI event */
99 void pmc_disable_smi(uint32_t mask);
100
101 /* Enable events in PM1 control register */
102 void pmc_enable_pm1_control(uint32_t mask);
103
104 /* Disable events in PM1 control register*/
105 void pmc_disable_pm1_control(uint32_t mask);
106
107 /* Set the PM1 register to events in PM1_STS_EN register */
108 void pmc_enable_pm1(uint16_t events);
109
110 /* Print, clear, and return PM1 status */
111 uint16_t pmc_clear_pm1_status(void);
112
113 /* TCO */
114
115 /* Print, clear, and return TCO status */
116 uint32_t pmc_clear_tco_status(void);
117
118 /*
119 * This function returns array of string which represents
120 * names for the TCO status bits. Size of the array is
121 * returned as an output parameter.
122 */
123 const char *const *soc_tco_sts_array(size_t *a);
124
125 /* GPE */
126
127 /*
128 * We have symmetrical pairs of GPE0_EN/STS registers for Standard(STD) and GPIO
129 * events. STD events are specific to SoC and one of the GPE0_EN/STS pairs
130 * handles the STD events. Other GPE0_EN/STS pairs are used for GPIO events
131 * based on the GPE0_DWx mappings.
132 *
133 * STS registers are symmetrical to event enable registers.
134 * In case of STD events, for GPE0_STS register if the corresponding _EN bit is
135 * set in GPE0_EN, then when the STS bit gets set, the PMC will generate a Wake
136 * Event. Once back in an S0 state (or if already in an S0 state when the event
137 * occurs), the PMC will also generate an SCI if the SCI_EN bit is set,
138 * or an SMI# if the SCI_EN bit is not set.
139 *
140 * GPIO GPE registers are symmetrical to STD GPE registers and reads/writes to
141 * those register will result in the transaction being forwarded to the
142 * corresponding GPIO community based on the GPIO_GPE_CFG.gpe0_dwX register
143 * configuration.
144 */
145 /* Enable a standard GPE. */
146 void pmc_enable_std_gpe(uint32_t mask);
147 /* Disable a standard GPE. */
148 void pmc_disable_std_gpe(uint32_t mask);
149 /* Disable all GPE's in STD and GPIO GPE registers. */
150 void pmc_disable_all_gpe(void);
151 /* Clear STD and GPIO GPE status registers. */
152 void pmc_clear_all_gpe_status(void);
153
154 /* Write PMC MMIO register value with the provided bitmask. */
155 void pmc_or_mmio32(uint32_t offset, uint32_t ormask);
156 /* Clear status bits in Power and Reset Status (PRSTS) register */
157 void pmc_clear_prsts(void);
158
159 /*
160 * Enable or disable global reset. If global reset is enabled, hard reset and
161 * soft reset will trigger global reset, where both host and TXE are reset.
162 * This is cleared on cold boot, hard reset, soft reset and Sx.
163 */
164 void pmc_global_reset_enable(bool enable);
165 /*
166 * Disable global reset and lock the CF9 global reset register in accordance to PCH ME BWG
167 * sections 4.4.1, 4.5.1 and 18.4 and the PCH datasheet(s) (Intel doc e.g. 332691-002EN,
168 * 332996-002EN). Deviate from the BGW we don't depend on the Intel ME state because Intel
169 * FPT (Flash Programming Tool) normally is not used with coreboot.
170 *
171 * Once the register is locked, it can't be changed. This lock is reset on cold boot, hard
172 * reset, soft reset and Sx.
173 */
174 void pmc_global_reset_disable_and_lock(void);
175
176 /* Returns the power state structure */
177 struct chipset_power_state *pmc_get_power_state(void);
178
179 /*
180 * Reads, fills(chipset_power_state) and prints ACPI specific PM registers. This
181 * function does not check the previous sleep state.
182 */
183 void pmc_fill_pm_reg_info(struct chipset_power_state *ps);
184
185 /*
186 * Reads and prints ACPI specific PM registers which are common across
187 * chipsets. Returns the previous sleep state which is one of ACPI_SX
188 * values. Additionally, it also disables all GPEs after GPE_EN
189 * registers are read.
190 */
191 int pmc_fill_power_state(struct chipset_power_state *ps);
192
193 /*
194 * Sets the gpe routing table by properly programming the GPE_CFG
195 * and the MISCCFG registers. This function calls soc specific
196 * soc_get_gpi_gpe_configs which reads the devicetree info
197 * and populates the dw variables and also returns the bit offset
198 * in GPIO_CFG register which is assigned to ACPI register.
199 */
200 void pmc_gpe_init(void);
201
202 /* Clear PMC GEN_PMCON_X register power failure status bits */
203 void pmc_clear_pmcon_pwr_failure_sts(void);
204
205 /* Clear PMC GEN_PMCON_A register status bits */
206 void pmc_clear_pmcon_sts(void);
207
208 /* Power Management Utility Functions. */
209
210 /* Returns PMC base address */
211 uintptr_t soc_read_pmc_base(void);
212
213 /* Returns pointer to the ETR register */
214 uint32_t *soc_pmc_etr_addr(void);
215
216 /*
217 * This function returns array of string which represents
218 * names for the SMI status register bits. Size of the array is
219 * returned as an output parameter.
220 */
221 const char *const *soc_smi_sts_array(size_t *a);
222
223 /*
224 * This function returns array of string which represents
225 * names for the STD GPE status register bits.
226 * Size of the array is returned as an output parameter.
227 */
228 const char *const *soc_std_gpe_sts_array(size_t *a);
229
230 /*
231 * This function gets the gpe0 dwX values from devicetree
232 * for pmc_gpe_init which will use those to set the GPE_CFG
233 * register.
234 */
235 void soc_get_gpi_gpe_configs(uint8_t *dw0, uint8_t *dw1, uint8_t *dw2);
236
237 /*
238 * Reads soc specific power management critical registers, fills
239 * chipset_power_state structure variable and prints.
240 */
241 void soc_fill_power_state(struct chipset_power_state *ps);
242
243 /*
244 * Which state do we want to goto after g3 (power restored)?
245 * 0 == S5 Soft Off
246 * 1 == S0 Full On
247 * 2 == Keep Previous State
248 * Keep in sync with `config MAINBOARD_POWER_FAILURE_STATE`.
249 */
250 enum {
251 MAINBOARD_POWER_STATE_OFF,
252 MAINBOARD_POWER_STATE_ON,
253 MAINBOARD_POWER_STATE_PREVIOUS,
254 };
255
256 /*
257 * Implemented by SoC code to set PMC register to know which state
258 * system should go into after power is reapplied.
259 */
260 void pmc_soc_set_afterg3_en(bool on);
261 /*
262 * Configure power state to go into when power is reapplied.
263 *
264 * To be called by SoC code once during boot and will be called by
265 * the "sleep" SMI handler when going into S5.
266 *
267 * `target_on` signifies that we are currently powering on, so that
268 * MAINBOARD_POWER_STATE_PREVIOUS can be handled accordingly.
269 */
270 void pmc_set_power_failure_state(bool target_on);
271
272 /*
273 * This function ensures that the duration programmed in the PchPmPwrCycDur will never be
274 * smaller than the SLP_Sx assertion widths.
275 * If the pm_pwr_cyc_dur is less than any of the SLP_Sx assertion widths then it returns the
276 * default value PCH_PM_PWR_CYC_DUR.
277 */
278 uint8_t get_pm_pwr_cyc_dur(uint8_t slp_s4_min_assert, uint8_t slp_s3_min_assert,
279 uint8_t slp_a_min_assert, uint8_t pm_pwr_cyc_dur);
280
281 /* API to set ACPI mode */
282 void pmc_set_acpi_mode(void);
283
284 /*
285 * This function reads and prints SoC QDF information using PMC interface
286 * if SOC_QDF_DYNAMIC_READ_PMC config is enabled.
287 */
288 void pmc_dump_soc_qdf_info(void);
289
290 /*
291 * Retrieve SoC QDF information.
292 *
293 * This function retrieves the SoC QDF information string, which can be used to
294 * populate various data structures, such as the SMBIOS Type 4 table for CPU
295 * identification.
296 *
297 * @return A pointer to the SoC QDF information string.
298 */
299 char *retrieve_soc_qdf_info_via_pmc_ipc(void);
300
301 #endif /* SOC_INTEL_COMMON_BLOCK_PMCLIB_H */