1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * CPPC (Collaborative Processor Performance Control) methods used
6 * (C) Copyright 2014, 2015 Linaro Ltd.
7 * Author: Ashwin Chaugule <ashwin.chaugule@linaro.org>
13 #include <linux/acpi.h>
14 #include <linux/cpufreq.h>
15 #include <linux/types.h>
18 #include <acpi/processor.h>
20 /* CPPCv2 and CPPCv3 support */
23 #define CPPC_V2_NUM_ENT 21
24 #define CPPC_V3_NUM_ENT 23
26 #define PCC_CMD_COMPLETE_MASK (1 << 0)
27 #define PCC_ERROR_MASK (1 << 2)
29 #define MAX_CPC_REG_ENT 21
31 /* CPPC specific PCC commands. */
35 /* Each register has the folowing format. */
47 * Each entry in the CPC table is either
48 * of type ACPI_TYPE_BUFFER or
51 struct cpc_register_resource
{
52 acpi_object_type type
;
53 u64 __iomem
*sys_mem_vaddr
;
60 /* Container to hold the CPC details for each CPU */
67 /* Lock used for RMW operations in cpc_write() */
68 raw_spinlock_t rmw_lock
;
69 struct cpc_register_resource cpc_regs
[MAX_CPC_REG_ENT
];
70 struct acpi_psd_package domain_info
;
74 /* These are indexes into the per-cpu cpc_regs[]. Order is important. */
100 * Categorization of registers as described
101 * in the ACPI v.5.1 spec.
102 * XXX: Only filling up ones which are used by governors
105 struct cppc_perf_caps
{
110 u32 lowest_nonlinear_perf
;
117 struct cppc_perf_ctrls
{
124 struct cppc_perf_fb_ctrs
{
131 /* Per CPU container for runtime CPPC management. */
132 struct cppc_cpudata
{
133 struct list_head node
;
134 struct cppc_perf_caps perf_caps
;
135 struct cppc_perf_ctrls perf_ctrls
;
136 struct cppc_perf_fb_ctrs perf_fb_ctrs
;
137 unsigned int shared_type
;
138 cpumask_var_t shared_cpu_map
;
141 #ifdef CONFIG_ACPI_CPPC_LIB
142 extern int cppc_get_desired_perf(int cpunum
, u64
*desired_perf
);
143 extern int cppc_get_nominal_perf(int cpunum
, u64
*nominal_perf
);
144 extern int cppc_get_highest_perf(int cpunum
, u64
*highest_perf
);
145 extern int cppc_get_perf_ctrs(int cpu
, struct cppc_perf_fb_ctrs
*perf_fb_ctrs
);
146 extern int cppc_set_perf(int cpu
, struct cppc_perf_ctrls
*perf_ctrls
);
147 extern int cppc_set_enable(int cpu
, bool enable
);
148 extern int cppc_get_perf_caps(int cpu
, struct cppc_perf_caps
*caps
);
149 extern bool cppc_perf_ctrs_in_pcc(void);
150 extern unsigned int cppc_perf_to_khz(struct cppc_perf_caps
*caps
, unsigned int perf
);
151 extern unsigned int cppc_khz_to_perf(struct cppc_perf_caps
*caps
, unsigned int freq
);
152 extern bool acpi_cpc_valid(void);
153 extern bool cppc_allow_fast_switch(void);
154 extern int acpi_get_psd_map(unsigned int cpu
, struct cppc_cpudata
*cpu_data
);
155 extern unsigned int cppc_get_transition_latency(int cpu
);
156 extern bool cpc_ffh_supported(void);
157 extern bool cpc_supported_by_cpu(void);
158 extern int cpc_read_ffh(int cpunum
, struct cpc_reg
*reg
, u64
*val
);
159 extern int cpc_write_ffh(int cpunum
, struct cpc_reg
*reg
, u64 val
);
160 extern int cppc_get_epp_perf(int cpunum
, u64
*epp_perf
);
161 extern int cppc_set_epp_perf(int cpu
, struct cppc_perf_ctrls
*perf_ctrls
, bool enable
);
162 extern int cppc_get_auto_sel_caps(int cpunum
, struct cppc_perf_caps
*perf_caps
);
163 extern int cppc_set_auto_sel(int cpu
, bool enable
);
164 extern int amd_get_highest_perf(unsigned int cpu
, u32
*highest_perf
);
165 extern int amd_get_boost_ratio_numerator(unsigned int cpu
, u64
*numerator
);
166 extern int amd_detect_prefcore(bool *detected
);
167 #else /* !CONFIG_ACPI_CPPC_LIB */
168 static inline int cppc_get_desired_perf(int cpunum
, u64
*desired_perf
)
172 static inline int cppc_get_nominal_perf(int cpunum
, u64
*nominal_perf
)
176 static inline int cppc_get_highest_perf(int cpunum
, u64
*highest_perf
)
180 static inline int cppc_get_perf_ctrs(int cpu
, struct cppc_perf_fb_ctrs
*perf_fb_ctrs
)
184 static inline int cppc_set_perf(int cpu
, struct cppc_perf_ctrls
*perf_ctrls
)
188 static inline int cppc_set_enable(int cpu
, bool enable
)
192 static inline int cppc_get_perf_caps(int cpu
, struct cppc_perf_caps
*caps
)
196 static inline bool cppc_perf_ctrs_in_pcc(void)
200 static inline bool acpi_cpc_valid(void)
204 static inline bool cppc_allow_fast_switch(void)
208 static inline unsigned int cppc_get_transition_latency(int cpu
)
210 return CPUFREQ_ETERNAL
;
212 static inline bool cpc_ffh_supported(void)
216 static inline int cpc_read_ffh(int cpunum
, struct cpc_reg
*reg
, u64
*val
)
220 static inline int cpc_write_ffh(int cpunum
, struct cpc_reg
*reg
, u64 val
)
224 static inline int cppc_set_epp_perf(int cpu
, struct cppc_perf_ctrls
*perf_ctrls
, bool enable
)
228 static inline int cppc_get_epp_perf(int cpunum
, u64
*epp_perf
)
232 static inline int cppc_set_auto_sel(int cpu
, bool enable
)
236 static inline int cppc_get_auto_sel_caps(int cpunum
, struct cppc_perf_caps
*perf_caps
)
240 static inline int amd_get_highest_perf(unsigned int cpu
, u32
*highest_perf
)
244 static inline int amd_get_boost_ratio_numerator(unsigned int cpu
, u64
*numerator
)
248 static inline int amd_detect_prefcore(bool *detected
)
252 #endif /* !CONFIG_ACPI_CPPC_LIB */
254 #endif /* _CPPC_ACPI_H*/