xref: /openbmc/linux/include/acpi/cppc_acpi.h (revision 5f8b7d4b2e9604d03ae06f1a2dd5a1f34c33e533)
1b886d83cSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2337aadffSAshwin Chaugule /*
3337aadffSAshwin Chaugule  * CPPC (Collaborative Processor Performance Control) methods used
4337aadffSAshwin Chaugule  * by CPUfreq drivers.
5337aadffSAshwin Chaugule  *
6337aadffSAshwin Chaugule  * (C) Copyright 2014, 2015 Linaro Ltd.
7337aadffSAshwin Chaugule  * Author: Ashwin Chaugule <ashwin.chaugule@linaro.org>
8337aadffSAshwin Chaugule  */
9337aadffSAshwin Chaugule 
10337aadffSAshwin Chaugule #ifndef _CPPC_ACPI_H
11337aadffSAshwin Chaugule #define _CPPC_ACPI_H
12337aadffSAshwin Chaugule 
13337aadffSAshwin Chaugule #include <linux/acpi.h>
148a02d998SRafael J. Wysocki #include <linux/cpufreq.h>
15337aadffSAshwin Chaugule #include <linux/types.h>
16337aadffSAshwin Chaugule 
17866ae696SHoan Tran #include <acpi/pcc.h>
18337aadffSAshwin Chaugule #include <acpi/processor.h>
19337aadffSAshwin Chaugule 
204f4179fcSRafael J. Wysocki /* CPPCv2 and CPPCv3 support */
214773e77cSPrashanth Prakash #define CPPC_V2_REV	2
224773e77cSPrashanth Prakash #define CPPC_V3_REV	3
234773e77cSPrashanth Prakash #define CPPC_V2_NUM_ENT	21
244773e77cSPrashanth Prakash #define CPPC_V3_NUM_ENT	23
25337aadffSAshwin Chaugule 
26139aee73SPrakash, Prashanth #define PCC_CMD_COMPLETE_MASK	(1 << 0)
27139aee73SPrakash, Prashanth #define PCC_ERROR_MASK		(1 << 2)
28139aee73SPrakash, Prashanth 
294773e77cSPrashanth Prakash #define MAX_CPC_REG_ENT 21
30337aadffSAshwin Chaugule 
31337aadffSAshwin Chaugule /* CPPC specific PCC commands. */
32337aadffSAshwin Chaugule #define	CMD_READ 0
33337aadffSAshwin Chaugule #define	CMD_WRITE 1
34337aadffSAshwin Chaugule 
35337aadffSAshwin Chaugule /* Each register has the folowing format. */
36337aadffSAshwin Chaugule struct cpc_reg {
37337aadffSAshwin Chaugule 	u8 descriptor;
38337aadffSAshwin Chaugule 	u16 length;
39337aadffSAshwin Chaugule 	u8 space_id;
40337aadffSAshwin Chaugule 	u8 bit_width;
41337aadffSAshwin Chaugule 	u8 bit_offset;
42337aadffSAshwin Chaugule 	u8 access_width;
43d8f85cc0SIonela Voinescu 	u64 address;
44337aadffSAshwin Chaugule } __packed;
45337aadffSAshwin Chaugule 
46337aadffSAshwin Chaugule /*
47337aadffSAshwin Chaugule  * Each entry in the CPC table is either
48337aadffSAshwin Chaugule  * of type ACPI_TYPE_BUFFER or
49337aadffSAshwin Chaugule  * ACPI_TYPE_INTEGER.
50337aadffSAshwin Chaugule  */
51337aadffSAshwin Chaugule struct cpc_register_resource {
52337aadffSAshwin Chaugule 	acpi_object_type type;
535bbb86aaSAshwin Chaugule 	u64 __iomem *sys_mem_vaddr;
54337aadffSAshwin Chaugule 	union {
55337aadffSAshwin Chaugule 		struct cpc_reg reg;
56337aadffSAshwin Chaugule 		u64 int_value;
57337aadffSAshwin Chaugule 	} cpc_entry;
58337aadffSAshwin Chaugule };
59337aadffSAshwin Chaugule 
60337aadffSAshwin Chaugule /* Container to hold the CPC details for each CPU */
61337aadffSAshwin Chaugule struct cpc_desc {
62337aadffSAshwin Chaugule 	int num_entries;
63337aadffSAshwin Chaugule 	int version;
64337aadffSAshwin Chaugule 	int cpu_id;
6580b8286aSPrakash, Prashanth 	int write_cmd_status;
6680b8286aSPrakash, Prashanth 	int write_cmd_id;
678ad28208SClément Léger 	/* Lock used for RMW operations in cpc_write() */
68*0eb2b767SPierre Gondois 	raw_spinlock_t rmw_lock;
69337aadffSAshwin Chaugule 	struct cpc_register_resource cpc_regs[MAX_CPC_REG_ENT];
70337aadffSAshwin Chaugule 	struct acpi_psd_package domain_info;
71158c998eSAshwin Chaugule 	struct kobject kobj;
72337aadffSAshwin Chaugule };
73337aadffSAshwin Chaugule 
74337aadffSAshwin Chaugule /* These are indexes into the per-cpu cpc_regs[]. Order is important. */
75337aadffSAshwin Chaugule enum cppc_regs {
76337aadffSAshwin Chaugule 	HIGHEST_PERF,
77337aadffSAshwin Chaugule 	NOMINAL_PERF,
78337aadffSAshwin Chaugule 	LOW_NON_LINEAR_PERF,
79337aadffSAshwin Chaugule 	LOWEST_PERF,
80337aadffSAshwin Chaugule 	GUARANTEED_PERF,
81337aadffSAshwin Chaugule 	DESIRED_PERF,
82337aadffSAshwin Chaugule 	MIN_PERF,
83337aadffSAshwin Chaugule 	MAX_PERF,
84337aadffSAshwin Chaugule 	PERF_REDUC_TOLERANCE,
85337aadffSAshwin Chaugule 	TIME_WINDOW,
86337aadffSAshwin Chaugule 	CTR_WRAP_TIME,
87337aadffSAshwin Chaugule 	REFERENCE_CTR,
88337aadffSAshwin Chaugule 	DELIVERED_CTR,
89337aadffSAshwin Chaugule 	PERF_LIMITED,
90337aadffSAshwin Chaugule 	ENABLE,
91337aadffSAshwin Chaugule 	AUTO_SEL_ENABLE,
92337aadffSAshwin Chaugule 	AUTO_ACT_WINDOW,
93337aadffSAshwin Chaugule 	ENERGY_PERF,
94337aadffSAshwin Chaugule 	REFERENCE_PERF,
954773e77cSPrashanth Prakash 	LOWEST_FREQ,
964773e77cSPrashanth Prakash 	NOMINAL_FREQ,
97337aadffSAshwin Chaugule };
98337aadffSAshwin Chaugule 
99337aadffSAshwin Chaugule /*
100337aadffSAshwin Chaugule  * Categorization of registers as described
101337aadffSAshwin Chaugule  * in the ACPI v.5.1 spec.
102337aadffSAshwin Chaugule  * XXX: Only filling up ones which are used by governors
103337aadffSAshwin Chaugule  * today.
104337aadffSAshwin Chaugule  */
105337aadffSAshwin Chaugule struct cppc_perf_caps {
10629523f09SSrinivas Pandruvada 	u32 guaranteed_perf;
107337aadffSAshwin Chaugule 	u32 highest_perf;
108337aadffSAshwin Chaugule 	u32 nominal_perf;
109337aadffSAshwin Chaugule 	u32 lowest_perf;
110368520a6SPrakash, Prashanth 	u32 lowest_nonlinear_perf;
1114773e77cSPrashanth Prakash 	u32 lowest_freq;
1124773e77cSPrashanth Prakash 	u32 nominal_freq;
1137bc1fcd3SPerry Yuan 	u32 energy_perf;
114c984f5d5SWyes Karny 	bool auto_sel;
115337aadffSAshwin Chaugule };
116337aadffSAshwin Chaugule 
117337aadffSAshwin Chaugule struct cppc_perf_ctrls {
118337aadffSAshwin Chaugule 	u32 max_perf;
119337aadffSAshwin Chaugule 	u32 min_perf;
120337aadffSAshwin Chaugule 	u32 desired_perf;
1217bc1fcd3SPerry Yuan 	u32 energy_perf;
122337aadffSAshwin Chaugule };
123337aadffSAshwin Chaugule 
124337aadffSAshwin Chaugule struct cppc_perf_fb_ctrs {
125337aadffSAshwin Chaugule 	u64 reference;
126337aadffSAshwin Chaugule 	u64 delivered;
127158c998eSAshwin Chaugule 	u64 reference_perf;
1282c74d847SPrakash, Prashanth 	u64 wraparound_time;
129337aadffSAshwin Chaugule };
130337aadffSAshwin Chaugule 
131337aadffSAshwin Chaugule /* Per CPU container for runtime CPPC management. */
13241dd6403SSrinivas Pandruvada struct cppc_cpudata {
133a28b2bfcSIonela Voinescu 	struct list_head node;
134337aadffSAshwin Chaugule 	struct cppc_perf_caps perf_caps;
135337aadffSAshwin Chaugule 	struct cppc_perf_ctrls perf_ctrls;
136337aadffSAshwin Chaugule 	struct cppc_perf_fb_ctrs perf_fb_ctrs;
137337aadffSAshwin Chaugule 	unsigned int shared_type;
138337aadffSAshwin Chaugule 	cpumask_var_t shared_cpu_map;
139337aadffSAshwin Chaugule };
140337aadffSAshwin Chaugule 
1418a02d998SRafael J. Wysocki #ifdef CONFIG_ACPI_CPPC_LIB
1421757d05fSXiongfeng Wang extern int cppc_get_desired_perf(int cpunum, u64 *desired_perf);
1430654cf05SRafael J. Wysocki extern int cppc_get_nominal_perf(int cpunum, u64 *nominal_perf);
1440b983c08SMeng Li extern int cppc_get_highest_perf(int cpunum, u64 *highest_perf);
145337aadffSAshwin Chaugule extern int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs *perf_fb_ctrs);
146337aadffSAshwin Chaugule extern int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls);
147fb0b00afSJinzhou Su extern int cppc_set_enable(int cpu, bool enable);
148337aadffSAshwin Chaugule extern int cppc_get_perf_caps(int cpu, struct cppc_perf_caps *caps);
149ae2df912SJeremy Linton extern bool cppc_perf_ctrs_in_pcc(void);
15033e89c16SVincent Guittot extern unsigned int cppc_perf_to_khz(struct cppc_perf_caps *caps, unsigned int perf);
15133e89c16SVincent Guittot extern unsigned int cppc_khz_to_perf(struct cppc_perf_caps *caps, unsigned int freq);
152a28b2bfcSIonela Voinescu extern bool acpi_cpc_valid(void);
1533cc30dd0SPierre Gondois extern bool cppc_allow_fast_switch(void);
154a28b2bfcSIonela Voinescu extern int acpi_get_psd_map(unsigned int cpu, struct cppc_cpudata *cpu_data);
155be8b88d7SPrakash, Prashanth extern unsigned int cppc_get_transition_latency(int cpu);
156ad3bc25aSBorislav Petkov extern bool cpc_ffh_supported(void);
1578b356e53SMario Limonciello extern bool cpc_supported_by_cpu(void);
158ad3bc25aSBorislav Petkov extern int cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val);
159ad3bc25aSBorislav Petkov extern int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val);
1607bc1fcd3SPerry Yuan extern int cppc_get_epp_perf(int cpunum, u64 *epp_perf);
1617bc1fcd3SPerry Yuan extern int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable);
162c984f5d5SWyes Karny extern int cppc_get_auto_sel_caps(int cpunum, struct cppc_perf_caps *perf_caps);
163c984f5d5SWyes Karny extern int cppc_set_auto_sel(int cpu, bool enable);
1648a02d998SRafael J. Wysocki #else /* !CONFIG_ACPI_CPPC_LIB */
cppc_get_desired_perf(int cpunum,u64 * desired_perf)1658a02d998SRafael J. Wysocki static inline int cppc_get_desired_perf(int cpunum, u64 *desired_perf)
1668a02d998SRafael J. Wysocki {
1678a02d998SRafael J. Wysocki 	return -ENOTSUPP;
1688a02d998SRafael J. Wysocki }
cppc_get_nominal_perf(int cpunum,u64 * nominal_perf)1690654cf05SRafael J. Wysocki static inline int cppc_get_nominal_perf(int cpunum, u64 *nominal_perf)
1700654cf05SRafael J. Wysocki {
1710654cf05SRafael J. Wysocki 	return -ENOTSUPP;
1720654cf05SRafael J. Wysocki }
cppc_get_highest_perf(int cpunum,u64 * highest_perf)1730b983c08SMeng Li static inline int cppc_get_highest_perf(int cpunum, u64 *highest_perf)
1740b983c08SMeng Li {
1750b983c08SMeng Li 	return -ENOTSUPP;
1760b983c08SMeng Li }
cppc_get_perf_ctrs(int cpu,struct cppc_perf_fb_ctrs * perf_fb_ctrs)1778a02d998SRafael J. Wysocki static inline int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs *perf_fb_ctrs)
1788a02d998SRafael J. Wysocki {
1798a02d998SRafael J. Wysocki 	return -ENOTSUPP;
1808a02d998SRafael J. Wysocki }
cppc_set_perf(int cpu,struct cppc_perf_ctrls * perf_ctrls)1818a02d998SRafael J. Wysocki static inline int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)
1828a02d998SRafael J. Wysocki {
1838a02d998SRafael J. Wysocki 	return -ENOTSUPP;
1848a02d998SRafael J. Wysocki }
cppc_set_enable(int cpu,bool enable)185fb0b00afSJinzhou Su static inline int cppc_set_enable(int cpu, bool enable)
186fb0b00afSJinzhou Su {
187fb0b00afSJinzhou Su 	return -ENOTSUPP;
188fb0b00afSJinzhou Su }
cppc_get_perf_caps(int cpu,struct cppc_perf_caps * caps)1898a02d998SRafael J. Wysocki static inline int cppc_get_perf_caps(int cpu, struct cppc_perf_caps *caps)
1908a02d998SRafael J. Wysocki {
1918a02d998SRafael J. Wysocki 	return -ENOTSUPP;
1928a02d998SRafael J. Wysocki }
cppc_perf_ctrs_in_pcc(void)193ae2df912SJeremy Linton static inline bool cppc_perf_ctrs_in_pcc(void)
194ae2df912SJeremy Linton {
195ae2df912SJeremy Linton 	return false;
196ae2df912SJeremy Linton }
acpi_cpc_valid(void)1978a02d998SRafael J. Wysocki static inline bool acpi_cpc_valid(void)
1988a02d998SRafael J. Wysocki {
1998a02d998SRafael J. Wysocki 	return false;
2008a02d998SRafael J. Wysocki }
cppc_allow_fast_switch(void)2013cc30dd0SPierre Gondois static inline bool cppc_allow_fast_switch(void)
2023cc30dd0SPierre Gondois {
2033cc30dd0SPierre Gondois 	return false;
2043cc30dd0SPierre Gondois }
cppc_get_transition_latency(int cpu)2058a02d998SRafael J. Wysocki static inline unsigned int cppc_get_transition_latency(int cpu)
2068a02d998SRafael J. Wysocki {
2078a02d998SRafael J. Wysocki 	return CPUFREQ_ETERNAL;
2088a02d998SRafael J. Wysocki }
cpc_ffh_supported(void)2098a02d998SRafael J. Wysocki static inline bool cpc_ffh_supported(void)
2108a02d998SRafael J. Wysocki {
2118a02d998SRafael J. Wysocki 	return false;
2128a02d998SRafael J. Wysocki }
cpc_read_ffh(int cpunum,struct cpc_reg * reg,u64 * val)2138a02d998SRafael J. Wysocki static inline int cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val)
2148a02d998SRafael J. Wysocki {
2158a02d998SRafael J. Wysocki 	return -ENOTSUPP;
2168a02d998SRafael J. Wysocki }
cpc_write_ffh(int cpunum,struct cpc_reg * reg,u64 val)2178a02d998SRafael J. Wysocki static inline int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val)
2188a02d998SRafael J. Wysocki {
2198a02d998SRafael J. Wysocki 	return -ENOTSUPP;
2208a02d998SRafael J. Wysocki }
cppc_set_epp_perf(int cpu,struct cppc_perf_ctrls * perf_ctrls,bool enable)2217bc1fcd3SPerry Yuan static inline int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable)
2227bc1fcd3SPerry Yuan {
2237bc1fcd3SPerry Yuan 	return -ENOTSUPP;
2247bc1fcd3SPerry Yuan }
cppc_get_epp_perf(int cpunum,u64 * epp_perf)2257bc1fcd3SPerry Yuan static inline int cppc_get_epp_perf(int cpunum, u64 *epp_perf)
2267bc1fcd3SPerry Yuan {
2277bc1fcd3SPerry Yuan 	return -ENOTSUPP;
2287bc1fcd3SPerry Yuan }
cppc_set_auto_sel(int cpu,bool enable)229c984f5d5SWyes Karny static inline int cppc_set_auto_sel(int cpu, bool enable)
230c984f5d5SWyes Karny {
231c984f5d5SWyes Karny 	return -ENOTSUPP;
232c984f5d5SWyes Karny }
cppc_get_auto_sel_caps(int cpunum,struct cppc_perf_caps * perf_caps)233c984f5d5SWyes Karny static inline int cppc_get_auto_sel_caps(int cpunum, struct cppc_perf_caps *perf_caps)
234c984f5d5SWyes Karny {
235c984f5d5SWyes Karny 	return -ENOTSUPP;
236c984f5d5SWyes Karny }
2378a02d998SRafael J. Wysocki #endif /* !CONFIG_ACPI_CPPC_LIB */
238337aadffSAshwin Chaugule 
239337aadffSAshwin Chaugule #endif /* _CPPC_ACPI_H*/
240