projects/linux·blob uaccess-cleanups · refs

318 lines · 8.3 KiB

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 <[email protected]>
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. */
53struct 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 */
68struct cpc_register_resource {
69 acpi_object_type type;
70 u64 __iomem *sys_mem_vaddr;
71 union {
72 struct {
73 struct cpc_reg reg;
74 bool use_rmw_lock;
75 };
76 u64 int_value;
77 } cpc_entry;
78};
79
80/* Container to hold the CPC details for each CPU */
81struct cpc_desc {
82 int num_entries;
83 int version;
84 int cpu_id;
85 int write_cmd_status;
86 int write_cmd_id;
87 /* Lock used for RMW operations in cpc_write() */
88 raw_spinlock_t rmw_lock;
89 struct cpc_register_resource cpc_regs[MAX_CPC_REG_ENT];
90 struct acpi_psd_package domain_info;
91 struct kobject kobj;
92};
93
94/* These are indexes into the per-cpu cpc_regs[]. Order is important. */
95enum cppc_regs {
96 HIGHEST_PERF,
97 NOMINAL_PERF,
98 LOW_NON_LINEAR_PERF,
99 LOWEST_PERF,
100 GUARANTEED_PERF,
101 DESIRED_PERF,
102 MIN_PERF,
103 MAX_PERF,
104 PERF_REDUC_TOLERANCE,
105 TIME_WINDOW,
106 CTR_WRAP_TIME,
107 REFERENCE_CTR,
108 DELIVERED_CTR,
109 PERF_LIMITED,
110 ENABLE,
111 AUTO_SEL_ENABLE,
112 AUTO_ACT_WINDOW,
113 ENERGY_PERF,
114 REFERENCE_PERF,
115 LOWEST_FREQ,
116 NOMINAL_FREQ,
117 OSPM_NOMINAL_PERF,
118 RESOURCE_PRIORITY,
119};
120
121/*
122 * Categorization of registers as described
123 * in the ACPI v.5.1 spec.
124 * XXX: Only filling up ones which are used by governors
125 * today.
126 */
127struct cppc_perf_caps {
128 u32 guaranteed_perf;
129 u32 highest_perf;
130 u32 nominal_perf;
131 u32 reference_perf;
132 u32 lowest_perf;
133 u32 lowest_nonlinear_perf;
134 u32 lowest_freq;
135 u32 nominal_freq;
136};
137
138struct cppc_perf_ctrls {
139 u32 max_perf;
140 u32 min_perf;
141 u32 desired_perf;
142 u32 energy_perf;
143 bool auto_sel;
144};
145
146struct cppc_perf_fb_ctrs {
147 u64 reference;
148 u64 delivered;
149 u64 wraparound_time;
150};
151
152/* Per CPU container for runtime CPPC management. */
153struct cppc_cpudata {
154 struct cppc_perf_caps perf_caps;
155 struct cppc_perf_ctrls perf_ctrls;
156 struct cppc_perf_fb_ctrs perf_fb_ctrs;
157 unsigned int shared_type;
158 cpumask_var_t shared_cpu_map;
159};
160
161#ifdef CONFIG_ACPI_CPPC_LIB
162extern int cppc_get_desired_perf(int cpunum, u64 *desired_perf);
163extern int cppc_get_nominal_perf(int cpunum, u64 *nominal_perf);
164extern int cppc_get_highest_perf(int cpunum, u64 *highest_perf);
165extern int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs *perf_fb_ctrs);
166extern int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls);
167extern int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls);
168extern int cppc_set_enable(int cpu, bool enable);
169extern int cppc_get_perf_caps(int cpu, struct cppc_perf_caps *caps);
170extern bool cppc_perf_ctrs_in_pcc_cpu(unsigned int cpu);
171extern bool cppc_perf_ctrs_in_pcc(void);
172extern u64 cppc_get_dmi_max_khz(void);
173extern unsigned int cppc_perf_to_khz(struct cppc_perf_caps *caps, unsigned int perf);
174extern unsigned int cppc_khz_to_perf(struct cppc_perf_caps *caps, unsigned int freq);
175extern bool acpi_cpc_valid(void);
176bool cppc_allow_fast_switch(const struct cpumask *cpus);
177extern int acpi_get_psd_map(unsigned int cpu, struct cppc_cpudata *cpu_data);
178extern int cppc_get_transition_latency(int cpu);
179extern bool cpc_ffh_supported(void);
180extern bool cpc_supported_by_cpu(void);
181extern int cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val);
182extern int cpc_read_ffh_fb_ctrs(int cpu, struct cpc_reg *reg1, u64 *val1,
183 struct cpc_reg *reg2, u64 *val2);
184extern int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val);
185extern int cppc_get_epp_perf(int cpunum, u64 *epp_perf);
186extern int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable);
187extern int cppc_set_epp(int cpu, u64 epp_val);
188extern int cppc_get_auto_act_window(int cpu, u64 *auto_act_window);
189extern int cppc_set_auto_act_window(int cpu, u64 auto_act_window);
190extern int cppc_get_auto_sel(int cpu, bool *enable);
191extern int cppc_set_auto_sel(int cpu, bool enable);
192extern int cppc_get_perf_limited(int cpu, u64 *perf_limited);
193extern int cppc_set_perf_limited(int cpu, u64 bits_to_clear);
194extern int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf);
195extern int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator);
196extern int amd_detect_prefcore(bool *detected);
197#else /* !CONFIG_ACPI_CPPC_LIB */
198static inline int cppc_get_desired_perf(int cpunum, u64 *desired_perf)
199{
200 return -EOPNOTSUPP;
201}
202static inline int cppc_get_nominal_perf(int cpunum, u64 *nominal_perf)
203{
204 return -EOPNOTSUPP;
205}
206static inline int cppc_get_highest_perf(int cpunum, u64 *highest_perf)
207{
208 return -EOPNOTSUPP;
209}
210static inline int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs *perf_fb_ctrs)
211{
212 return -EOPNOTSUPP;
213}
214static inline int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)
215{
216 return -EOPNOTSUPP;
217}
218static inline int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)
219{
220 return -EOPNOTSUPP;
221}
222static inline int cppc_set_enable(int cpu, bool enable)
223{
224 return -EOPNOTSUPP;
225}
226static inline int cppc_get_perf_caps(int cpu, struct cppc_perf_caps *caps)
227{
228 return -EOPNOTSUPP;
229}
230static inline bool cppc_perf_ctrs_in_pcc_cpu(unsigned int cpu)
231{
232 return false;
233}
234static inline bool cppc_perf_ctrs_in_pcc(void)
235{
236 return false;
237}
238static inline bool acpi_cpc_valid(void)
239{
240 return false;
241}
242
243static inline bool cppc_allow_fast_switch(const struct cpumask *cpus)
244{
245 return false;
246}
247static inline int cppc_get_transition_latency(int cpu)
248{
249 return -ENODATA;
250}
251static inline bool cpc_ffh_supported(void)
252{
253 return false;
254}
255static inline int cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val)
256{
257 return -EOPNOTSUPP;
258}
259static inline int cpc_read_ffh_fb_ctrs(int cpu, struct cpc_reg *reg1, u64 *val1,
260 struct cpc_reg *reg2, u64 *val2)
261{
262 return -EOPNOTSUPP;
263}
264static inline int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val)
265{
266 return -EOPNOTSUPP;
267}
268static inline int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable)
269{
270 return -EOPNOTSUPP;
271}
272static inline int cppc_get_epp_perf(int cpunum, u64 *epp_perf)
273{
274 return -EOPNOTSUPP;
275}
276static inline int cppc_set_epp(int cpu, u64 epp_val)
277{
278 return -EOPNOTSUPP;
279}
280static inline int cppc_get_auto_act_window(int cpu, u64 *auto_act_window)
281{
282 return -EOPNOTSUPP;
283}
284static inline int cppc_set_auto_act_window(int cpu, u64 auto_act_window)
285{
286 return -EOPNOTSUPP;
287}
288static inline int cppc_get_auto_sel(int cpu, bool *enable)
289{
290 return -EOPNOTSUPP;
291}
292static inline int cppc_set_auto_sel(int cpu, bool enable)
293{
294 return -EOPNOTSUPP;
295}
296static inline int cppc_get_perf_limited(int cpu, u64 *perf_limited)
297{
298 return -EOPNOTSUPP;
299}
300static inline int cppc_set_perf_limited(int cpu, u64 bits_to_clear)
301{
302 return -EOPNOTSUPP;
303}
304static inline int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf)
305{
306 return -ENODEV;
307}
308static inline int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator)
309{
310 return -EOPNOTSUPP;
311}
312static inline int amd_detect_prefcore(bool *detected)
313{
314 return -ENODEV;
315}
316#endif /* !CONFIG_ACPI_CPPC_LIB */
317
318#endif /* _CPPC_ACPI_H*/