cppc_acpi.h 7.1 KB

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