kgd_pp_interface.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. OD_SCLK,
  99. OD_MCLK,
  100. };
  101. enum amd_pp_sensors {
  102. AMDGPU_PP_SENSOR_GFX_SCLK = 0,
  103. AMDGPU_PP_SENSOR_VDDNB,
  104. AMDGPU_PP_SENSOR_VDDGFX,
  105. AMDGPU_PP_SENSOR_UVD_VCLK,
  106. AMDGPU_PP_SENSOR_UVD_DCLK,
  107. AMDGPU_PP_SENSOR_VCE_ECCLK,
  108. AMDGPU_PP_SENSOR_GPU_LOAD,
  109. AMDGPU_PP_SENSOR_GFX_MCLK,
  110. AMDGPU_PP_SENSOR_GPU_TEMP,
  111. AMDGPU_PP_SENSOR_VCE_POWER,
  112. AMDGPU_PP_SENSOR_UVD_POWER,
  113. AMDGPU_PP_SENSOR_GPU_POWER,
  114. AMDGPU_PP_SENSOR_STABLE_PSTATE_SCLK,
  115. AMDGPU_PP_SENSOR_STABLE_PSTATE_MCLK,
  116. };
  117. enum amd_pp_task {
  118. AMD_PP_TASK_DISPLAY_CONFIG_CHANGE,
  119. AMD_PP_TASK_ENABLE_USER_STATE,
  120. AMD_PP_TASK_READJUST_POWER_STATE,
  121. AMD_PP_TASK_COMPLETE_INIT,
  122. AMD_PP_TASK_MAX
  123. };
  124. struct amd_pp_init {
  125. struct cgs_device *device;
  126. uint32_t chip_family;
  127. uint32_t chip_id;
  128. bool pm_en;
  129. uint32_t feature_mask;
  130. };
  131. enum PP_SMC_POWER_PROFILE {
  132. PP_SMC_POWER_PROFILE_FULLSCREEN3D = 0x0,
  133. PP_SMC_POWER_PROFILE_POWERSAVING = 0x1,
  134. PP_SMC_POWER_PROFILE_VIDEO = 0x2,
  135. PP_SMC_POWER_PROFILE_VR = 0x3,
  136. PP_SMC_POWER_PROFILE_COMPUTE = 0x4,
  137. PP_SMC_POWER_PROFILE_CUSTOM = 0x5,
  138. PP_SMC_POWER_PROFILE_AUTO = 0x6,
  139. };
  140. enum {
  141. PP_GROUP_UNKNOWN = 0,
  142. PP_GROUP_GFX = 1,
  143. PP_GROUP_SYS,
  144. PP_GROUP_MAX
  145. };
  146. enum PP_OD_DPM_TABLE_COMMAND {
  147. PP_OD_EDIT_SCLK_VDDC_TABLE,
  148. PP_OD_EDIT_MCLK_VDDC_TABLE,
  149. PP_OD_RESTORE_DEFAULT_TABLE,
  150. PP_OD_COMMIT_DPM_TABLE
  151. };
  152. struct pp_states_info {
  153. uint32_t nums;
  154. uint32_t states[16];
  155. };
  156. struct pp_gpu_power {
  157. uint32_t vddc_power;
  158. uint32_t vddci_power;
  159. uint32_t max_gpu_power;
  160. uint32_t average_gpu_power;
  161. };
  162. #define PP_GROUP_MASK 0xF0000000
  163. #define PP_GROUP_SHIFT 28
  164. #define PP_BLOCK_MASK 0x0FFFFF00
  165. #define PP_BLOCK_SHIFT 8
  166. #define PP_BLOCK_GFX_CG 0x01
  167. #define PP_BLOCK_GFX_MG 0x02
  168. #define PP_BLOCK_GFX_3D 0x04
  169. #define PP_BLOCK_GFX_RLC 0x08
  170. #define PP_BLOCK_GFX_CP 0x10
  171. #define PP_BLOCK_SYS_BIF 0x01
  172. #define PP_BLOCK_SYS_MC 0x02
  173. #define PP_BLOCK_SYS_ROM 0x04
  174. #define PP_BLOCK_SYS_DRM 0x08
  175. #define PP_BLOCK_SYS_HDP 0x10
  176. #define PP_BLOCK_SYS_SDMA 0x20
  177. #define PP_STATE_MASK 0x0000000F
  178. #define PP_STATE_SHIFT 0
  179. #define PP_STATE_SUPPORT_MASK 0x000000F0
  180. #define PP_STATE_SUPPORT_SHIFT 0
  181. #define PP_STATE_CG 0x01
  182. #define PP_STATE_LS 0x02
  183. #define PP_STATE_DS 0x04
  184. #define PP_STATE_SD 0x08
  185. #define PP_STATE_SUPPORT_CG 0x10
  186. #define PP_STATE_SUPPORT_LS 0x20
  187. #define PP_STATE_SUPPORT_DS 0x40
  188. #define PP_STATE_SUPPORT_SD 0x80
  189. #define PP_CG_MSG_ID(group, block, support, state) \
  190. ((group) << PP_GROUP_SHIFT | (block) << PP_BLOCK_SHIFT | \
  191. (support) << PP_STATE_SUPPORT_SHIFT | (state) << PP_STATE_SHIFT)
  192. struct seq_file;
  193. enum amd_pp_clock_type;
  194. struct amd_pp_simple_clock_info;
  195. struct amd_pp_display_configuration;
  196. struct amd_pp_clock_info;
  197. struct pp_display_clock_request;
  198. struct pp_wm_sets_with_clock_ranges_soc15;
  199. struct pp_clock_levels_with_voltage;
  200. struct pp_clock_levels_with_latency;
  201. struct amd_pp_clocks;
  202. struct amd_pm_funcs {
  203. /* export for dpm on ci and si */
  204. int (*pre_set_power_state)(void *handle);
  205. int (*set_power_state)(void *handle);
  206. void (*post_set_power_state)(void *handle);
  207. void (*display_configuration_changed)(void *handle);
  208. void (*print_power_state)(void *handle, void *ps);
  209. bool (*vblank_too_short)(void *handle);
  210. void (*enable_bapm)(void *handle, bool enable);
  211. int (*check_state_equal)(void *handle,
  212. void *cps,
  213. void *rps,
  214. bool *equal);
  215. /* export for sysfs */
  216. void (*set_fan_control_mode)(void *handle, u32 mode);
  217. u32 (*get_fan_control_mode)(void *handle);
  218. int (*set_fan_speed_percent)(void *handle, u32 speed);
  219. int (*get_fan_speed_percent)(void *handle, u32 *speed);
  220. int (*force_clock_level)(void *handle, enum pp_clock_type type, uint32_t mask);
  221. int (*print_clock_levels)(void *handle, enum pp_clock_type type, char *buf);
  222. int (*force_performance_level)(void *handle, enum amd_dpm_forced_level level);
  223. int (*get_sclk_od)(void *handle);
  224. int (*set_sclk_od)(void *handle, uint32_t value);
  225. int (*get_mclk_od)(void *handle);
  226. int (*set_mclk_od)(void *handle, uint32_t value);
  227. int (*read_sensor)(void *handle, int idx, void *value, int *size);
  228. enum amd_dpm_forced_level (*get_performance_level)(void *handle);
  229. enum amd_pm_state_type (*get_current_power_state)(void *handle);
  230. int (*get_fan_speed_rpm)(void *handle, uint32_t *rpm);
  231. int (*get_pp_num_states)(void *handle, struct pp_states_info *data);
  232. int (*get_pp_table)(void *handle, char **table);
  233. int (*set_pp_table)(void *handle, const char *buf, size_t size);
  234. void (*debugfs_print_current_performance_level)(void *handle, struct seq_file *m);
  235. int (*reset_power_profile_state)(void *handle,
  236. struct amd_pp_profile *request);
  237. int (*get_power_profile_state)(void *handle,
  238. struct amd_pp_profile *query);
  239. int (*set_power_profile_state)(void *handle,
  240. struct amd_pp_profile *request);
  241. int (*switch_power_profile)(void *handle,
  242. enum amd_pp_profile_type type);
  243. /* export to amdgpu */
  244. void (*powergate_uvd)(void *handle, bool gate);
  245. void (*powergate_vce)(void *handle, bool gate);
  246. struct amd_vce_state *(*get_vce_clock_state)(void *handle, u32 idx);
  247. int (*dispatch_tasks)(void *handle, enum amd_pp_task task_id,
  248. enum amd_pm_state_type *user_state);
  249. int (*load_firmware)(void *handle);
  250. int (*wait_for_fw_loading_complete)(void *handle);
  251. int (*set_clockgating_by_smu)(void *handle, uint32_t msg_id);
  252. int (*notify_smu_memory_info)(void *handle, uint32_t virtual_addr_low,
  253. uint32_t virtual_addr_hi,
  254. uint32_t mc_addr_low,
  255. uint32_t mc_addr_hi,
  256. uint32_t size);
  257. int (*set_power_limit)(void *handle, uint32_t n);
  258. int (*get_power_limit)(void *handle, uint32_t *limit, bool default_limit);
  259. /* export to DC */
  260. u32 (*get_sclk)(void *handle, bool low);
  261. u32 (*get_mclk)(void *handle, bool low);
  262. int (*display_configuration_change)(void *handle,
  263. const struct amd_pp_display_configuration *input);
  264. int (*get_display_power_level)(void *handle,
  265. struct amd_pp_simple_clock_info *output);
  266. int (*get_current_clocks)(void *handle,
  267. struct amd_pp_clock_info *clocks);
  268. int (*get_clock_by_type)(void *handle,
  269. enum amd_pp_clock_type type,
  270. struct amd_pp_clocks *clocks);
  271. int (*get_clock_by_type_with_latency)(void *handle,
  272. enum amd_pp_clock_type type,
  273. struct pp_clock_levels_with_latency *clocks);
  274. int (*get_clock_by_type_with_voltage)(void *handle,
  275. enum amd_pp_clock_type type,
  276. struct pp_clock_levels_with_voltage *clocks);
  277. int (*set_watermarks_for_clocks_ranges)(void *handle,
  278. struct pp_wm_sets_with_clock_ranges_soc15 *wm_with_clock_ranges);
  279. int (*display_clock_voltage_request)(void *handle,
  280. struct pp_display_clock_request *clock);
  281. int (*get_display_mode_validation_clocks)(void *handle,
  282. struct amd_pp_simple_clock_info *clocks);
  283. int (*get_power_profile_mode)(void *handle, char *buf);
  284. int (*set_power_profile_mode)(void *handle, long *input, uint32_t size);
  285. int (*odn_edit_dpm_table)(void *handle, uint32_t type, long *input, uint32_t size);
  286. int (*set_mmhub_powergating_by_smu)(void *handle);
  287. };
  288. #endif