ci_dpm.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /*
  2. * Copyright 2013 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 __CI_DPM_H__
  24. #define __CI_DPM_H__
  25. #include "amdgpu_atombios.h"
  26. #include "ppsmc.h"
  27. #define SMU__NUM_SCLK_DPM_STATE 8
  28. #define SMU__NUM_MCLK_DPM_LEVELS 6
  29. #define SMU__NUM_LCLK_DPM_LEVELS 8
  30. #define SMU__NUM_PCIE_DPM_LEVELS 8
  31. #include "smu7_discrete.h"
  32. #define CISLANDS_MAX_HARDWARE_POWERLEVELS 2
  33. #define CISLANDS_UNUSED_GPIO_PIN 0x7F
  34. struct ci_pl {
  35. u32 mclk;
  36. u32 sclk;
  37. enum amdgpu_pcie_gen pcie_gen;
  38. u16 pcie_lane;
  39. };
  40. struct ci_ps {
  41. u16 performance_level_count;
  42. bool dc_compatible;
  43. u32 sclk_t;
  44. struct ci_pl performance_levels[CISLANDS_MAX_HARDWARE_POWERLEVELS];
  45. };
  46. struct ci_dpm_level {
  47. bool enabled;
  48. u32 value;
  49. u32 param1;
  50. };
  51. #define CISLAND_MAX_DEEPSLEEP_DIVIDER_ID 5
  52. #define MAX_REGULAR_DPM_NUMBER 8
  53. #define CISLAND_MINIMUM_ENGINE_CLOCK 800
  54. struct ci_single_dpm_table {
  55. u32 count;
  56. struct ci_dpm_level dpm_levels[MAX_REGULAR_DPM_NUMBER];
  57. };
  58. struct ci_dpm_table {
  59. struct ci_single_dpm_table sclk_table;
  60. struct ci_single_dpm_table mclk_table;
  61. struct ci_single_dpm_table pcie_speed_table;
  62. struct ci_single_dpm_table vddc_table;
  63. struct ci_single_dpm_table vddci_table;
  64. struct ci_single_dpm_table mvdd_table;
  65. };
  66. struct ci_mc_reg_entry {
  67. u32 mclk_max;
  68. u32 mc_data[SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE];
  69. };
  70. struct ci_mc_reg_table {
  71. u8 last;
  72. u8 num_entries;
  73. u16 valid_flag;
  74. struct ci_mc_reg_entry mc_reg_table_entry[MAX_AC_TIMING_ENTRIES];
  75. SMU7_Discrete_MCRegisterAddress mc_reg_address[SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE];
  76. };
  77. struct ci_ulv_parm
  78. {
  79. bool supported;
  80. u32 cg_ulv_parameter;
  81. u32 volt_change_delay;
  82. struct ci_pl pl;
  83. };
  84. #define CISLANDS_MAX_LEAKAGE_COUNT 8
  85. struct ci_leakage_voltage {
  86. u16 count;
  87. u16 leakage_id[CISLANDS_MAX_LEAKAGE_COUNT];
  88. u16 actual_voltage[CISLANDS_MAX_LEAKAGE_COUNT];
  89. };
  90. struct ci_dpm_level_enable_mask {
  91. u32 uvd_dpm_enable_mask;
  92. u32 vce_dpm_enable_mask;
  93. u32 acp_dpm_enable_mask;
  94. u32 samu_dpm_enable_mask;
  95. u32 sclk_dpm_enable_mask;
  96. u32 mclk_dpm_enable_mask;
  97. u32 pcie_dpm_enable_mask;
  98. };
  99. struct ci_vbios_boot_state
  100. {
  101. u16 mvdd_bootup_value;
  102. u16 vddc_bootup_value;
  103. u16 vddci_bootup_value;
  104. u32 sclk_bootup_value;
  105. u32 mclk_bootup_value;
  106. u16 pcie_gen_bootup_value;
  107. u16 pcie_lane_bootup_value;
  108. };
  109. struct ci_clock_registers {
  110. u32 cg_spll_func_cntl;
  111. u32 cg_spll_func_cntl_2;
  112. u32 cg_spll_func_cntl_3;
  113. u32 cg_spll_func_cntl_4;
  114. u32 cg_spll_spread_spectrum;
  115. u32 cg_spll_spread_spectrum_2;
  116. u32 dll_cntl;
  117. u32 mclk_pwrmgt_cntl;
  118. u32 mpll_ad_func_cntl;
  119. u32 mpll_dq_func_cntl;
  120. u32 mpll_func_cntl;
  121. u32 mpll_func_cntl_1;
  122. u32 mpll_func_cntl_2;
  123. u32 mpll_ss1;
  124. u32 mpll_ss2;
  125. };
  126. struct ci_thermal_temperature_setting {
  127. s32 temperature_low;
  128. s32 temperature_high;
  129. s32 temperature_shutdown;
  130. };
  131. struct ci_pcie_perf_range {
  132. u16 max;
  133. u16 min;
  134. };
  135. enum ci_pt_config_reg_type {
  136. CISLANDS_CONFIGREG_MMR = 0,
  137. CISLANDS_CONFIGREG_SMC_IND,
  138. CISLANDS_CONFIGREG_DIDT_IND,
  139. CISLANDS_CONFIGREG_CACHE,
  140. CISLANDS_CONFIGREG_MAX
  141. };
  142. #define POWERCONTAINMENT_FEATURE_BAPM 0x00000001
  143. #define POWERCONTAINMENT_FEATURE_TDCLimit 0x00000002
  144. #define POWERCONTAINMENT_FEATURE_PkgPwrLimit 0x00000004
  145. struct ci_pt_config_reg {
  146. u32 offset;
  147. u32 mask;
  148. u32 shift;
  149. u32 value;
  150. enum ci_pt_config_reg_type type;
  151. };
  152. struct ci_pt_defaults {
  153. u8 svi_load_line_en;
  154. u8 svi_load_line_vddc;
  155. u8 tdc_vddc_throttle_release_limit_perc;
  156. u8 tdc_mawt;
  157. u8 tdc_waterfall_ctl;
  158. u8 dte_ambient_temp_base;
  159. u32 display_cac;
  160. u32 bapm_temp_gradient;
  161. u16 bapmti_r[SMU7_DTE_ITERATIONS * SMU7_DTE_SOURCES * SMU7_DTE_SINKS];
  162. u16 bapmti_rc[SMU7_DTE_ITERATIONS * SMU7_DTE_SOURCES * SMU7_DTE_SINKS];
  163. };
  164. #define DPMTABLE_OD_UPDATE_SCLK 0x00000001
  165. #define DPMTABLE_OD_UPDATE_MCLK 0x00000002
  166. #define DPMTABLE_UPDATE_SCLK 0x00000004
  167. #define DPMTABLE_UPDATE_MCLK 0x00000008
  168. struct ci_power_info {
  169. struct ci_dpm_table dpm_table;
  170. u32 voltage_control;
  171. u32 mvdd_control;
  172. u32 vddci_control;
  173. u32 active_auto_throttle_sources;
  174. struct ci_clock_registers clock_registers;
  175. u16 acpi_vddc;
  176. u16 acpi_vddci;
  177. enum amdgpu_pcie_gen force_pcie_gen;
  178. enum amdgpu_pcie_gen acpi_pcie_gen;
  179. struct ci_leakage_voltage vddc_leakage;
  180. struct ci_leakage_voltage vddci_leakage;
  181. u16 max_vddc_in_pp_table;
  182. u16 min_vddc_in_pp_table;
  183. u16 max_vddci_in_pp_table;
  184. u16 min_vddci_in_pp_table;
  185. u32 mclk_strobe_mode_threshold;
  186. u32 mclk_stutter_mode_threshold;
  187. u32 mclk_edc_enable_threshold;
  188. u32 mclk_edc_wr_enable_threshold;
  189. struct ci_vbios_boot_state vbios_boot_state;
  190. /* smc offsets */
  191. u32 sram_end;
  192. u32 dpm_table_start;
  193. u32 soft_regs_start;
  194. u32 mc_reg_table_start;
  195. u32 fan_table_start;
  196. u32 arb_table_start;
  197. /* smc tables */
  198. SMU7_Discrete_DpmTable smc_state_table;
  199. SMU7_Discrete_MCRegisters smc_mc_reg_table;
  200. SMU7_Discrete_PmFuses smc_powertune_table;
  201. /* other stuff */
  202. struct ci_mc_reg_table mc_reg_table;
  203. struct atom_voltage_table vddc_voltage_table;
  204. struct atom_voltage_table vddci_voltage_table;
  205. struct atom_voltage_table mvdd_voltage_table;
  206. struct ci_ulv_parm ulv;
  207. u32 power_containment_features;
  208. const struct ci_pt_defaults *powertune_defaults;
  209. u32 dte_tj_offset;
  210. bool vddc_phase_shed_control;
  211. struct ci_thermal_temperature_setting thermal_temp_setting;
  212. struct ci_dpm_level_enable_mask dpm_level_enable_mask;
  213. u32 need_update_smu7_dpm_table;
  214. u32 sclk_dpm_key_disabled;
  215. u32 mclk_dpm_key_disabled;
  216. u32 pcie_dpm_key_disabled;
  217. u32 thermal_sclk_dpm_enabled;
  218. struct ci_pcie_perf_range pcie_gen_performance;
  219. struct ci_pcie_perf_range pcie_lane_performance;
  220. struct ci_pcie_perf_range pcie_gen_powersaving;
  221. struct ci_pcie_perf_range pcie_lane_powersaving;
  222. u32 activity_target[SMU7_MAX_LEVELS_GRAPHICS];
  223. u32 mclk_activity_target;
  224. u32 low_sclk_interrupt_t;
  225. u32 last_mclk_dpm_enable_mask;
  226. u32 sys_pcie_mask;
  227. /* caps */
  228. bool caps_power_containment;
  229. bool caps_cac;
  230. bool caps_sq_ramping;
  231. bool caps_db_ramping;
  232. bool caps_td_ramping;
  233. bool caps_tcp_ramping;
  234. bool caps_fps;
  235. bool caps_sclk_ds;
  236. bool caps_sclk_ss_support;
  237. bool caps_mclk_ss_support;
  238. bool caps_uvd_dpm;
  239. bool caps_vce_dpm;
  240. bool caps_samu_dpm;
  241. bool caps_acp_dpm;
  242. bool caps_automatic_dc_transition;
  243. bool caps_sclk_throttle_low_notification;
  244. bool caps_dynamic_ac_timing;
  245. bool caps_od_fuzzy_fan_control_support;
  246. /* flags */
  247. bool thermal_protection;
  248. bool pcie_performance_request;
  249. bool dynamic_ss;
  250. bool dll_default_on;
  251. bool cac_enabled;
  252. bool uvd_enabled;
  253. bool battery_state;
  254. bool pspp_notify_required;
  255. bool enable_bapm_feature;
  256. bool enable_tdc_limit_feature;
  257. bool enable_pkg_pwr_tracking_feature;
  258. bool use_pcie_performance_levels;
  259. bool use_pcie_powersaving_levels;
  260. bool uvd_power_gated;
  261. /* driver states */
  262. struct amdgpu_ps current_rps;
  263. struct ci_ps current_ps;
  264. struct amdgpu_ps requested_rps;
  265. struct ci_ps requested_ps;
  266. /* fan control */
  267. bool fan_ctrl_is_in_default_mode;
  268. bool fan_is_controlled_by_smc;
  269. u32 t_min;
  270. u32 fan_ctrl_default_mode;
  271. };
  272. #define CISLANDS_VOLTAGE_CONTROL_NONE 0x0
  273. #define CISLANDS_VOLTAGE_CONTROL_BY_GPIO 0x1
  274. #define CISLANDS_VOLTAGE_CONTROL_BY_SVID2 0x2
  275. #define CISLANDS_Q88_FORMAT_CONVERSION_UNIT 256
  276. #define CISLANDS_VRC_DFLT0 0x3FFFC000
  277. #define CISLANDS_VRC_DFLT1 0x000400
  278. #define CISLANDS_VRC_DFLT2 0xC00080
  279. #define CISLANDS_VRC_DFLT3 0xC00200
  280. #define CISLANDS_VRC_DFLT4 0xC01680
  281. #define CISLANDS_VRC_DFLT5 0xC00033
  282. #define CISLANDS_VRC_DFLT6 0xC00033
  283. #define CISLANDS_VRC_DFLT7 0x3FFFC000
  284. #define CISLANDS_CGULVPARAMETER_DFLT 0x00040035
  285. #define CISLAND_TARGETACTIVITY_DFLT 30
  286. #define CISLAND_MCLK_TARGETACTIVITY_DFLT 10
  287. #define PCIE_PERF_REQ_REMOVE_REGISTRY 0
  288. #define PCIE_PERF_REQ_FORCE_LOWPOWER 1
  289. #define PCIE_PERF_REQ_PECI_GEN1 2
  290. #define PCIE_PERF_REQ_PECI_GEN2 3
  291. #define PCIE_PERF_REQ_PECI_GEN3 4
  292. #define CISLANDS_SSTU_DFLT 0
  293. #define CISLANDS_SST_DFLT 0x00C8
  294. /* XXX are these ok? */
  295. #define CISLANDS_TEMP_RANGE_MIN (90 * 1000)
  296. #define CISLANDS_TEMP_RANGE_MAX (120 * 1000)
  297. int amdgpu_ci_copy_bytes_to_smc(struct amdgpu_device *adev,
  298. u32 smc_start_address,
  299. const u8 *src, u32 byte_count, u32 limit);
  300. void amdgpu_ci_start_smc(struct amdgpu_device *adev);
  301. void amdgpu_ci_reset_smc(struct amdgpu_device *adev);
  302. int amdgpu_ci_program_jump_on_start(struct amdgpu_device *adev);
  303. void amdgpu_ci_stop_smc_clock(struct amdgpu_device *adev);
  304. void amdgpu_ci_start_smc_clock(struct amdgpu_device *adev);
  305. bool amdgpu_ci_is_smc_running(struct amdgpu_device *adev);
  306. PPSMC_Result amdgpu_ci_send_msg_to_smc(struct amdgpu_device *adev, PPSMC_Msg msg);
  307. PPSMC_Result amdgpu_ci_wait_for_smc_inactive(struct amdgpu_device *adev);
  308. int amdgpu_ci_load_smc_ucode(struct amdgpu_device *adev, u32 limit);
  309. int amdgpu_ci_read_smc_sram_dword(struct amdgpu_device *adev,
  310. u32 smc_address, u32 *value, u32 limit);
  311. int amdgpu_ci_write_smc_sram_dword(struct amdgpu_device *adev,
  312. u32 smc_address, u32 value, u32 limit);
  313. #endif