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