cppc_acpi.h 6.2 KB

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