kgd_pp_interface.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*
  2. * Copyright 2017 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. */
  23. #ifndef __KGD_PP_INTERFACE_H__
  24. #define __KGD_PP_INTERFACE_H__
  25. extern const struct amd_ip_funcs pp_ip_funcs;
  26. extern const struct amd_pm_funcs pp_dpm_funcs;
  27. struct amd_vce_state {
  28. /* vce clocks */
  29. u32 evclk;
  30. u32 ecclk;
  31. /* gpu clocks */
  32. u32 sclk;
  33. u32 mclk;
  34. u8 clk_idx;
  35. u8 pstate;
  36. };
  37. enum amd_dpm_forced_level {
  38. AMD_DPM_FORCED_LEVEL_AUTO = 0x1,
  39. AMD_DPM_FORCED_LEVEL_MANUAL = 0x2,
  40. AMD_DPM_FORCED_LEVEL_LOW = 0x4,
  41. AMD_DPM_FORCED_LEVEL_HIGH = 0x8,
  42. AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD = 0x10,
  43. AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK = 0x20,
  44. AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK = 0x40,
  45. AMD_DPM_FORCED_LEVEL_PROFILE_PEAK = 0x80,
  46. AMD_DPM_FORCED_LEVEL_PROFILE_EXIT = 0x100,
  47. };
  48. enum amd_pm_state_type {
  49. /* not used for dpm */
  50. POWER_STATE_TYPE_DEFAULT,
  51. POWER_STATE_TYPE_POWERSAVE,
  52. /* user selectable states */
  53. POWER_STATE_TYPE_BATTERY,
  54. POWER_STATE_TYPE_BALANCED,
  55. POWER_STATE_TYPE_PERFORMANCE,
  56. /* internal states */
  57. POWER_STATE_TYPE_INTERNAL_UVD,
  58. POWER_STATE_TYPE_INTERNAL_UVD_SD,
  59. POWER_STATE_TYPE_INTERNAL_UVD_HD,
  60. POWER_STATE_TYPE_INTERNAL_UVD_HD2,
  61. POWER_STATE_TYPE_INTERNAL_UVD_MVC,
  62. POWER_STATE_TYPE_INTERNAL_BOOT,
  63. POWER_STATE_TYPE_INTERNAL_THERMAL,
  64. POWER_STATE_TYPE_INTERNAL_ACPI,
  65. POWER_STATE_TYPE_INTERNAL_ULV,
  66. POWER_STATE_TYPE_INTERNAL_3DPERF,
  67. };
  68. #define AMD_MAX_VCE_LEVELS 6
  69. enum amd_vce_level {
  70. AMD_VCE_LEVEL_AC_ALL = 0, /* AC, All cases */
  71. AMD_VCE_LEVEL_DC_EE = 1, /* DC, entropy encoding */
  72. AMD_VCE_LEVEL_DC_LL_LOW = 2, /* DC, low latency queue, res <= 720 */
  73. AMD_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
  74. AMD_VCE_LEVEL_DC_GP_LOW = 4, /* DC, general purpose queue, res <= 720 */
  75. AMD_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
  76. };
  77. enum amd_pp_profile_type {
  78. AMD_PP_GFX_PROFILE,
  79. AMD_PP_COMPUTE_PROFILE,
  80. };
  81. struct amd_pp_profile {
  82. enum amd_pp_profile_type type;
  83. uint32_t min_sclk;
  84. uint32_t min_mclk;
  85. uint16_t activity_threshold;
  86. uint8_t up_hyst;
  87. uint8_t down_hyst;
  88. };
  89. enum amd_fan_ctrl_mode {
  90. AMD_FAN_CTRL_NONE = 0,
  91. AMD_FAN_CTRL_MANUAL = 1,
  92. AMD_FAN_CTRL_AUTO = 2,
  93. };
  94. enum pp_clock_type {
  95. PP_SCLK,
  96. PP_MCLK,
  97. PP_PCIE,
  98. };
  99. enum amd_pp_sensors {
  100. AMDGPU_PP_SENSOR_GFX_SCLK = 0,
  101. AMDGPU_PP_SENSOR_VDDNB,
  102. AMDGPU_PP_SENSOR_VDDGFX,
  103. AMDGPU_PP_SENSOR_UVD_VCLK,
  104. AMDGPU_PP_SENSOR_UVD_DCLK,
  105. AMDGPU_PP_SENSOR_VCE_ECCLK,
  106. AMDGPU_PP_SENSOR_GPU_LOAD,
  107. AMDGPU_PP_SENSOR_GFX_MCLK,
  108. AMDGPU_PP_SENSOR_GPU_TEMP,
  109. AMDGPU_PP_SENSOR_VCE_POWER,
  110. AMDGPU_PP_SENSOR_UVD_POWER,
  111. AMDGPU_PP_SENSOR_GPU_POWER,
  112. };
  113. enum amd_pp_task {
  114. AMD_PP_TASK_DISPLAY_CONFIG_CHANGE,
  115. AMD_PP_TASK_ENABLE_USER_STATE,
  116. AMD_PP_TASK_READJUST_POWER_STATE,
  117. AMD_PP_TASK_COMPLETE_INIT,
  118. AMD_PP_TASK_MAX
  119. };
  120. struct amd_pp_init {
  121. struct cgs_device *device;
  122. uint32_t chip_family;
  123. uint32_t chip_id;
  124. bool pm_en;
  125. uint32_t feature_mask;
  126. };
  127. enum {
  128. PP_GROUP_UNKNOWN = 0,
  129. PP_GROUP_GFX = 1,
  130. PP_GROUP_SYS,
  131. PP_GROUP_MAX
  132. };
  133. struct pp_states_info {
  134. uint32_t nums;
  135. uint32_t states[16];
  136. };
  137. struct pp_gpu_power {
  138. uint32_t vddc_power;
  139. uint32_t vddci_power;
  140. uint32_t max_gpu_power;
  141. uint32_t average_gpu_power;
  142. };
  143. #define PP_GROUP_MASK 0xF0000000
  144. #define PP_GROUP_SHIFT 28
  145. #define PP_BLOCK_MASK 0x0FFFFF00
  146. #define PP_BLOCK_SHIFT 8
  147. #define PP_BLOCK_GFX_CG 0x01
  148. #define PP_BLOCK_GFX_MG 0x02
  149. #define PP_BLOCK_GFX_3D 0x04
  150. #define PP_BLOCK_GFX_RLC 0x08
  151. #define PP_BLOCK_GFX_CP 0x10
  152. #define PP_BLOCK_SYS_BIF 0x01
  153. #define PP_BLOCK_SYS_MC 0x02
  154. #define PP_BLOCK_SYS_ROM 0x04
  155. #define PP_BLOCK_SYS_DRM 0x08
  156. #define PP_BLOCK_SYS_HDP 0x10
  157. #define PP_BLOCK_SYS_SDMA 0x20
  158. #define PP_STATE_MASK 0x0000000F
  159. #define PP_STATE_SHIFT 0
  160. #define PP_STATE_SUPPORT_MASK 0x000000F0
  161. #define PP_STATE_SUPPORT_SHIFT 0
  162. #define PP_STATE_CG 0x01
  163. #define PP_STATE_LS 0x02
  164. #define PP_STATE_DS 0x04
  165. #define PP_STATE_SD 0x08
  166. #define PP_STATE_SUPPORT_CG 0x10
  167. #define PP_STATE_SUPPORT_LS 0x20
  168. #define PP_STATE_SUPPORT_DS 0x40
  169. #define PP_STATE_SUPPORT_SD 0x80
  170. #define PP_CG_MSG_ID(group, block, support, state) \
  171. ((group) << PP_GROUP_SHIFT | (block) << PP_BLOCK_SHIFT | \
  172. (support) << PP_STATE_SUPPORT_SHIFT | (state) << PP_STATE_SHIFT)
  173. struct seq_file;
  174. enum amd_pp_clock_type;
  175. struct amd_pp_simple_clock_info;
  176. struct amd_pp_display_configuration;
  177. struct amd_pp_clock_info;
  178. struct pp_display_clock_request;
  179. struct pp_wm_sets_with_clock_ranges_soc15;
  180. struct pp_clock_levels_with_voltage;
  181. struct pp_clock_levels_with_latency;
  182. struct amd_pp_clocks;
  183. struct amd_pm_funcs {
  184. /* export for dpm on ci and si */
  185. int (*pre_set_power_state)(void *handle);
  186. int (*set_power_state)(void *handle);
  187. void (*post_set_power_state)(void *handle);
  188. void (*display_configuration_changed)(void *handle);
  189. void (*print_power_state)(void *handle, void *ps);
  190. bool (*vblank_too_short)(void *handle);
  191. void (*enable_bapm)(void *handle, bool enable);
  192. int (*check_state_equal)(void *handle,
  193. void *cps,
  194. void *rps,
  195. bool *equal);
  196. /* export for sysfs */
  197. int (*get_temperature)(void *handle);
  198. void (*set_fan_control_mode)(void *handle, u32 mode);
  199. u32 (*get_fan_control_mode)(void *handle);
  200. int (*set_fan_speed_percent)(void *handle, u32 speed);
  201. int (*get_fan_speed_percent)(void *handle, u32 *speed);
  202. int (*force_clock_level)(void *handle, enum pp_clock_type type, uint32_t mask);
  203. int (*print_clock_levels)(void *handle, enum pp_clock_type type, char *buf);
  204. int (*force_performance_level)(void *handle, enum amd_dpm_forced_level level);
  205. int (*get_sclk_od)(void *handle);
  206. int (*set_sclk_od)(void *handle, uint32_t value);
  207. int (*get_mclk_od)(void *handle);
  208. int (*set_mclk_od)(void *handle, uint32_t value);
  209. int (*read_sensor)(void *handle, int idx, void *value, int *size);
  210. enum amd_dpm_forced_level (*get_performance_level)(void *handle);
  211. enum amd_pm_state_type (*get_current_power_state)(void *handle);
  212. int (*get_fan_speed_rpm)(void *handle, uint32_t *rpm);
  213. int (*get_pp_num_states)(void *handle, struct pp_states_info *data);
  214. int (*get_pp_table)(void *handle, char **table);
  215. int (*set_pp_table)(void *handle, const char *buf, size_t size);
  216. void (*debugfs_print_current_performance_level)(void *handle, struct seq_file *m);
  217. int (*reset_power_profile_state)(void *handle,
  218. struct amd_pp_profile *request);
  219. int (*get_power_profile_state)(void *handle,
  220. struct amd_pp_profile *query);
  221. int (*set_power_profile_state)(void *handle,
  222. struct amd_pp_profile *request);
  223. int (*switch_power_profile)(void *handle,
  224. enum amd_pp_profile_type type);
  225. /* export to amdgpu */
  226. void (*powergate_uvd)(void *handle, bool gate);
  227. void (*powergate_vce)(void *handle, bool gate);
  228. struct amd_vce_state *(*get_vce_clock_state)(void *handle, u32 idx);
  229. int (*dispatch_tasks)(void *handle, enum amd_pp_task task_id,
  230. void *input, void *output);
  231. int (*load_firmware)(void *handle);
  232. int (*wait_for_fw_loading_complete)(void *handle);
  233. int (*set_clockgating_by_smu)(void *handle, uint32_t msg_id);
  234. int (*notify_smu_memory_info)(void *handle, uint32_t virtual_addr_low,
  235. uint32_t virtual_addr_hi,
  236. uint32_t mc_addr_low,
  237. uint32_t mc_addr_hi,
  238. uint32_t size);
  239. /* export to DC */
  240. u32 (*get_sclk)(void *handle, bool low);
  241. u32 (*get_mclk)(void *handle, bool low);
  242. int (*display_configuration_change)(void *handle,
  243. const struct amd_pp_display_configuration *input);
  244. int (*get_display_power_level)(void *handle,
  245. struct amd_pp_simple_clock_info *output);
  246. int (*get_current_clocks)(void *handle,
  247. struct amd_pp_clock_info *clocks);
  248. int (*get_clock_by_type)(void *handle,
  249. enum amd_pp_clock_type type,
  250. struct amd_pp_clocks *clocks);
  251. int (*get_clock_by_type_with_latency)(void *handle,
  252. enum amd_pp_clock_type type,
  253. struct pp_clock_levels_with_latency *clocks);
  254. int (*get_clock_by_type_with_voltage)(void *handle,
  255. enum amd_pp_clock_type type,
  256. struct pp_clock_levels_with_voltage *clocks);
  257. int (*set_watermarks_for_clocks_ranges)(void *handle,
  258. struct pp_wm_sets_with_clock_ranges_soc15 *wm_with_clock_ranges);
  259. int (*display_clock_voltage_request)(void *handle,
  260. struct pp_display_clock_request *clock);
  261. int (*get_display_mode_validation_clocks)(void *handle,
  262. struct amd_pp_simple_clock_info *clocks);
  263. };
  264. #endif