cppc_acpi.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. #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. struct cpc_register_resource cpc_regs[MAX_CPC_REG_ENT];
  58. struct acpi_psd_package domain_info;
  59. struct kobject kobj;
  60. };
  61. /* These are indexes into the per-cpu cpc_regs[]. Order is important. */
  62. enum cppc_regs {
  63. HIGHEST_PERF,
  64. NOMINAL_PERF,
  65. LOW_NON_LINEAR_PERF,
  66. LOWEST_PERF,
  67. GUARANTEED_PERF,
  68. DESIRED_PERF,
  69. MIN_PERF,
  70. MAX_PERF,
  71. PERF_REDUC_TOLERANCE,
  72. TIME_WINDOW,
  73. CTR_WRAP_TIME,
  74. REFERENCE_CTR,
  75. DELIVERED_CTR,
  76. PERF_LIMITED,
  77. ENABLE,
  78. AUTO_SEL_ENABLE,
  79. AUTO_ACT_WINDOW,
  80. ENERGY_PERF,
  81. REFERENCE_PERF,
  82. LOWEST_FREQ,
  83. NOMINAL_FREQ,
  84. };
  85. /*
  86. * Categorization of registers as described
  87. * in the ACPI v.5.1 spec.
  88. * XXX: Only filling up ones which are used by governors
  89. * today.
  90. */
  91. struct cppc_perf_caps {
  92. u32 guaranteed_perf;
  93. u32 highest_perf;
  94. u32 nominal_perf;
  95. u32 lowest_perf;
  96. u32 lowest_nonlinear_perf;
  97. u32 lowest_freq;
  98. u32 nominal_freq;
  99. };
  100. struct cppc_perf_ctrls {
  101. u32 max_perf;
  102. u32 min_perf;
  103. u32 desired_perf;
  104. };
  105. struct cppc_perf_fb_ctrs {
  106. u64 reference;
  107. u64 delivered;
  108. u64 reference_perf;
  109. u64 wraparound_time;
  110. };
  111. /* Per CPU container for runtime CPPC management. */
  112. struct cppc_cpudata {
  113. struct list_head node;
  114. struct cppc_perf_caps perf_caps;
  115. struct cppc_perf_ctrls perf_ctrls;
  116. struct cppc_perf_fb_ctrs perf_fb_ctrs;
  117. unsigned int shared_type;
  118. cpumask_var_t shared_cpu_map;
  119. };
  120. #ifdef CONFIG_ACPI_CPPC_LIB
  121. extern int cppc_get_desired_perf(int cpunum, u64 *desired_perf);
  122. extern int cppc_get_nominal_perf(int cpunum, u64 *nominal_perf);
  123. extern int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs *perf_fb_ctrs);
  124. extern int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls);
  125. extern int cppc_set_enable(int cpu, bool enable);
  126. extern int cppc_get_perf_caps(int cpu, struct cppc_perf_caps *caps);
  127. extern bool cppc_perf_ctrs_in_pcc(void);
  128. extern bool acpi_cpc_valid(void);
  129. extern bool cppc_allow_fast_switch(void);
  130. extern int acpi_get_psd_map(unsigned int cpu, struct cppc_cpudata *cpu_data);
  131. extern unsigned int cppc_get_transition_latency(int cpu);
  132. extern bool cpc_ffh_supported(void);
  133. extern bool cpc_supported_by_cpu(void);
  134. extern int cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val);
  135. extern int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val);
  136. #else /* !CONFIG_ACPI_CPPC_LIB */
  137. static inline int cppc_get_desired_perf(int cpunum, u64 *desired_perf)
  138. {
  139. return -ENOTSUPP;
  140. }
  141. static inline int cppc_get_nominal_perf(int cpunum, u64 *nominal_perf)
  142. {
  143. return -ENOTSUPP;
  144. }
  145. static inline int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs *perf_fb_ctrs)
  146. {
  147. return -ENOTSUPP;
  148. }
  149. static inline int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)
  150. {
  151. return -ENOTSUPP;
  152. }
  153. static inline int cppc_set_enable(int cpu, bool enable)
  154. {
  155. return -ENOTSUPP;
  156. }
  157. static inline int cppc_get_perf_caps(int cpu, struct cppc_perf_caps *caps)
  158. {
  159. return -ENOTSUPP;
  160. }
  161. static inline bool cppc_perf_ctrs_in_pcc(void)
  162. {
  163. return false;
  164. }
  165. static inline bool acpi_cpc_valid(void)
  166. {
  167. return false;
  168. }
  169. static inline bool cppc_allow_fast_switch(void)
  170. {
  171. return false;
  172. }
  173. static inline unsigned int cppc_get_transition_latency(int cpu)
  174. {
  175. return CPUFREQ_ETERNAL;
  176. }
  177. static inline bool cpc_ffh_supported(void)
  178. {
  179. return false;
  180. }
  181. static inline int cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val)
  182. {
  183. return -ENOTSUPP;
  184. }
  185. static inline int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val)
  186. {
  187. return -ENOTSUPP;
  188. }
  189. #endif /* !CONFIG_ACPI_CPPC_LIB */
  190. #endif /* _CPPC_ACPI_H*/