xref: /linux/include/acpi/cppc_acpi.h (revision 6b3f7af57881f6d6250c6dcc4d910fe8e855a607)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * CPPC (Collaborative Processor Performance Control) methods used
4  * by CPUfreq drivers.
5  *
6  * (C) Copyright 2014, 2015 Linaro Ltd.
7  * Author: Ashwin Chaugule <ashwin.chaugule@linaro.org>
8  */
9 
10 #ifndef _CPPC_ACPI_H
11 #define _CPPC_ACPI_H
12 
13 #include <linux/acpi.h>
14 #include <linux/cpufreq.h>
15 #include <linux/types.h>
16 
17 #include <acpi/pcc.h>
18 #include <acpi/processor.h>
19 
20 /* CPPCv2, CPPCv3 and CPPCv4 support */
21 #define CPPC_V2_REV	2
22 #define CPPC_V3_REV	3
23 #define CPPC_V4_REV	4
24 #define CPPC_V2_NUM_ENT	21
25 #define CPPC_V3_NUM_ENT	23
26 #define CPPC_V4_NUM_ENT	25
27 
28 #define PCC_CMD_COMPLETE_MASK	(1 << 0)
29 #define PCC_ERROR_MASK		(1 << 2)
30 
31 #define MAX_CPC_REG_ENT 23
32 
33 /* CPPC specific PCC commands. */
34 #define	CMD_READ 0
35 #define	CMD_WRITE 1
36 
37 #define CPPC_AUTO_ACT_WINDOW_SIG_BIT_SIZE	(7)
38 #define CPPC_AUTO_ACT_WINDOW_EXP_BIT_SIZE	(3)
39 #define CPPC_AUTO_ACT_WINDOW_MAX_SIG	((1 << CPPC_AUTO_ACT_WINDOW_SIG_BIT_SIZE) - 1)
40 #define CPPC_AUTO_ACT_WINDOW_MAX_EXP	((1 << CPPC_AUTO_ACT_WINDOW_EXP_BIT_SIZE) - 1)
41 /* CPPC_AUTO_ACT_WINDOW_MAX_SIG is 127, so 128 and 129 will decay to 127 when writing */
42 #define CPPC_AUTO_ACT_WINDOW_SIG_CARRY_THRESH 129
43 
44 #define CPPC_EPP_PERFORMANCE_PREF		0x00
45 #define CPPC_EPP_ENERGY_EFFICIENCY_PREF		0xFF
46 
47 #define CPPC_PERF_LIMITED_DESIRED_EXCURSION	BIT(0)
48 #define CPPC_PERF_LIMITED_MINIMUM_EXCURSION	BIT(1)
49 #define CPPC_PERF_LIMITED_MASK		(CPPC_PERF_LIMITED_DESIRED_EXCURSION | \
50 					 CPPC_PERF_LIMITED_MINIMUM_EXCURSION)
51 
52 /* Each register has the folowing format. */
53 struct cpc_reg {
54 	u8 descriptor;
55 	u16 length;
56 	u8 space_id;
57 	u8 bit_width;
58 	u8 bit_offset;
59 	u8 access_width;
60 	u64 address;
61 } __packed;
62 
63 /*
64  * Each entry in the CPC table is either
65  * of type ACPI_TYPE_BUFFER or
66  * ACPI_TYPE_INTEGER.
67  */
68 struct cpc_register_resource {
69 	acpi_object_type type;
70 	u64 __iomem *sys_mem_vaddr;
71 	union {
72 		struct cpc_reg reg;
73 		u64 int_value;
74 	} cpc_entry;
75 };
76 
77 /* Container to hold the CPC details for each CPU */
78 struct cpc_desc {
79 	int num_entries;
80 	int version;
81 	int cpu_id;
82 	int write_cmd_status;
83 	int write_cmd_id;
84 	/* Lock used for RMW operations in cpc_write() */
85 	raw_spinlock_t rmw_lock;
86 	struct cpc_register_resource cpc_regs[MAX_CPC_REG_ENT];
87 	struct acpi_psd_package domain_info;
88 	struct kobject kobj;
89 };
90 
91 /* These are indexes into the per-cpu cpc_regs[]. Order is important. */
92 enum cppc_regs {
93 	HIGHEST_PERF,
94 	NOMINAL_PERF,
95 	LOW_NON_LINEAR_PERF,
96 	LOWEST_PERF,
97 	GUARANTEED_PERF,
98 	DESIRED_PERF,
99 	MIN_PERF,
100 	MAX_PERF,
101 	PERF_REDUC_TOLERANCE,
102 	TIME_WINDOW,
103 	CTR_WRAP_TIME,
104 	REFERENCE_CTR,
105 	DELIVERED_CTR,
106 	PERF_LIMITED,
107 	ENABLE,
108 	AUTO_SEL_ENABLE,
109 	AUTO_ACT_WINDOW,
110 	ENERGY_PERF,
111 	REFERENCE_PERF,
112 	LOWEST_FREQ,
113 	NOMINAL_FREQ,
114 	OSPM_NOMINAL_PERF,
115 	RESOURCE_PRIORITY,
116 };
117 
118 /*
119  * Categorization of registers as described
120  * in the ACPI v.5.1 spec.
121  * XXX: Only filling up ones which are used by governors
122  * today.
123  */
124 struct cppc_perf_caps {
125 	u32 guaranteed_perf;
126 	u32 highest_perf;
127 	u32 nominal_perf;
128 	u32 reference_perf;
129 	u32 lowest_perf;
130 	u32 lowest_nonlinear_perf;
131 	u32 lowest_freq;
132 	u32 nominal_freq;
133 };
134 
135 struct cppc_perf_ctrls {
136 	u32 max_perf;
137 	u32 min_perf;
138 	u32 desired_perf;
139 	u32 energy_perf;
140 	bool auto_sel;
141 };
142 
143 struct cppc_perf_fb_ctrs {
144 	u64 reference;
145 	u64 delivered;
146 	u64 wraparound_time;
147 };
148 
149 /* Per CPU container for runtime CPPC management. */
150 struct cppc_cpudata {
151 	struct cppc_perf_caps perf_caps;
152 	struct cppc_perf_ctrls perf_ctrls;
153 	struct cppc_perf_fb_ctrs perf_fb_ctrs;
154 	unsigned int shared_type;
155 	cpumask_var_t shared_cpu_map;
156 };
157 
158 #ifdef CONFIG_ACPI_CPPC_LIB
159 extern int cppc_get_desired_perf(int cpunum, u64 *desired_perf);
160 extern int cppc_get_nominal_perf(int cpunum, u64 *nominal_perf);
161 extern int cppc_get_highest_perf(int cpunum, u64 *highest_perf);
162 extern int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs *perf_fb_ctrs);
163 extern int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls);
164 extern int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls);
165 extern int cppc_set_enable(int cpu, bool enable);
166 extern int cppc_get_perf_caps(int cpu, struct cppc_perf_caps *caps);
167 extern bool cppc_perf_ctrs_in_pcc_cpu(unsigned int cpu);
168 extern bool cppc_perf_ctrs_in_pcc(void);
169 extern u64 cppc_get_dmi_max_khz(void);
170 extern unsigned int cppc_perf_to_khz(struct cppc_perf_caps *caps, unsigned int perf);
171 extern unsigned int cppc_khz_to_perf(struct cppc_perf_caps *caps, unsigned int freq);
172 extern bool acpi_cpc_valid(void);
173 extern bool cppc_allow_fast_switch(void);
174 extern int acpi_get_psd_map(unsigned int cpu, struct cppc_cpudata *cpu_data);
175 extern int cppc_get_transition_latency(int cpu);
176 extern bool cpc_ffh_supported(void);
177 extern bool cpc_supported_by_cpu(void);
178 extern int cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val);
179 extern int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val);
180 extern int cppc_get_epp_perf(int cpunum, u64 *epp_perf);
181 extern int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable);
182 extern int cppc_set_epp(int cpu, u64 epp_val);
183 extern int cppc_get_auto_act_window(int cpu, u64 *auto_act_window);
184 extern int cppc_set_auto_act_window(int cpu, u64 auto_act_window);
185 extern int cppc_get_auto_sel(int cpu, bool *enable);
186 extern int cppc_set_auto_sel(int cpu, bool enable);
187 extern int cppc_get_perf_limited(int cpu, u64 *perf_limited);
188 extern int cppc_set_perf_limited(int cpu, u64 bits_to_clear);
189 extern int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf);
190 extern int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator);
191 extern int amd_detect_prefcore(bool *detected);
192 #else /* !CONFIG_ACPI_CPPC_LIB */
193 static inline int cppc_get_desired_perf(int cpunum, u64 *desired_perf)
194 {
195 	return -EOPNOTSUPP;
196 }
197 static inline int cppc_get_nominal_perf(int cpunum, u64 *nominal_perf)
198 {
199 	return -EOPNOTSUPP;
200 }
201 static inline int cppc_get_highest_perf(int cpunum, u64 *highest_perf)
202 {
203 	return -EOPNOTSUPP;
204 }
205 static inline int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs *perf_fb_ctrs)
206 {
207 	return -EOPNOTSUPP;
208 }
209 static inline int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)
210 {
211 	return -EOPNOTSUPP;
212 }
213 static inline int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)
214 {
215 	return -EOPNOTSUPP;
216 }
217 static inline int cppc_set_enable(int cpu, bool enable)
218 {
219 	return -EOPNOTSUPP;
220 }
221 static inline int cppc_get_perf_caps(int cpu, struct cppc_perf_caps *caps)
222 {
223 	return -EOPNOTSUPP;
224 }
225 static inline bool cppc_perf_ctrs_in_pcc_cpu(unsigned int cpu)
226 {
227 	return false;
228 }
229 static inline bool cppc_perf_ctrs_in_pcc(void)
230 {
231 	return false;
232 }
233 static inline bool acpi_cpc_valid(void)
234 {
235 	return false;
236 }
237 static inline bool cppc_allow_fast_switch(void)
238 {
239 	return false;
240 }
241 static inline int cppc_get_transition_latency(int cpu)
242 {
243 	return -ENODATA;
244 }
245 static inline bool cpc_ffh_supported(void)
246 {
247 	return false;
248 }
249 static inline int cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val)
250 {
251 	return -EOPNOTSUPP;
252 }
253 static inline int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val)
254 {
255 	return -EOPNOTSUPP;
256 }
257 static inline int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable)
258 {
259 	return -EOPNOTSUPP;
260 }
261 static inline int cppc_get_epp_perf(int cpunum, u64 *epp_perf)
262 {
263 	return -EOPNOTSUPP;
264 }
265 static inline int cppc_set_epp(int cpu, u64 epp_val)
266 {
267 	return -EOPNOTSUPP;
268 }
269 static inline int cppc_get_auto_act_window(int cpu, u64 *auto_act_window)
270 {
271 	return -EOPNOTSUPP;
272 }
273 static inline int cppc_set_auto_act_window(int cpu, u64 auto_act_window)
274 {
275 	return -EOPNOTSUPP;
276 }
277 static inline int cppc_get_auto_sel(int cpu, bool *enable)
278 {
279 	return -EOPNOTSUPP;
280 }
281 static inline int cppc_set_auto_sel(int cpu, bool enable)
282 {
283 	return -EOPNOTSUPP;
284 }
285 static inline int cppc_get_perf_limited(int cpu, u64 *perf_limited)
286 {
287 	return -EOPNOTSUPP;
288 }
289 static inline int cppc_set_perf_limited(int cpu, u64 bits_to_clear)
290 {
291 	return -EOPNOTSUPP;
292 }
293 static inline int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf)
294 {
295 	return -ENODEV;
296 }
297 static inline int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator)
298 {
299 	return -EOPNOTSUPP;
300 }
301 static inline int amd_detect_prefcore(bool *detected)
302 {
303 	return -ENODEV;
304 }
305 #endif /* !CONFIG_ACPI_CPPC_LIB */
306 
307 #endif /* _CPPC_ACPI_H*/
308