1 1.2 riastrad /* $NetBSD: ci_dpm.h,v 1.3 2021/12/18 23:45:42 riastradh Exp $ */ 2 1.2 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright 2013 Advanced Micro Devices, Inc. 5 1.1 riastrad * 6 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 7 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 8 1.1 riastrad * to deal in the Software without restriction, including without limitation 9 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 11 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 12 1.1 riastrad * 13 1.1 riastrad * The above copyright notice and this permission notice shall be included in 14 1.1 riastrad * all copies or substantial portions of the Software. 15 1.1 riastrad * 16 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 1.1 riastrad * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 1.1 riastrad * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 1.1 riastrad * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 1.1 riastrad * OTHER DEALINGS IN THE SOFTWARE. 23 1.1 riastrad * 24 1.1 riastrad */ 25 1.1 riastrad #ifndef __CI_DPM_H__ 26 1.1 riastrad #define __CI_DPM_H__ 27 1.1 riastrad 28 1.1 riastrad #include "ppsmc.h" 29 1.3 riastrad #include "radeon.h" 30 1.1 riastrad 31 1.1 riastrad #define SMU__NUM_SCLK_DPM_STATE 8 32 1.1 riastrad #define SMU__NUM_MCLK_DPM_LEVELS 6 33 1.1 riastrad #define SMU__NUM_LCLK_DPM_LEVELS 8 34 1.1 riastrad #define SMU__NUM_PCIE_DPM_LEVELS 8 35 1.1 riastrad #include "smu7_discrete.h" 36 1.1 riastrad 37 1.1 riastrad #define CISLANDS_MAX_HARDWARE_POWERLEVELS 2 38 1.1 riastrad 39 1.2 riastrad #define CISLANDS_UNUSED_GPIO_PIN 0x7F 40 1.2 riastrad 41 1.1 riastrad struct ci_pl { 42 1.1 riastrad u32 mclk; 43 1.1 riastrad u32 sclk; 44 1.1 riastrad enum radeon_pcie_gen pcie_gen; 45 1.1 riastrad u16 pcie_lane; 46 1.1 riastrad }; 47 1.1 riastrad 48 1.1 riastrad struct ci_ps { 49 1.1 riastrad u16 performance_level_count; 50 1.1 riastrad bool dc_compatible; 51 1.1 riastrad u32 sclk_t; 52 1.1 riastrad struct ci_pl performance_levels[CISLANDS_MAX_HARDWARE_POWERLEVELS]; 53 1.1 riastrad }; 54 1.1 riastrad 55 1.1 riastrad struct ci_dpm_level { 56 1.1 riastrad bool enabled; 57 1.1 riastrad u32 value; 58 1.1 riastrad u32 param1; 59 1.1 riastrad }; 60 1.1 riastrad 61 1.1 riastrad #define CISLAND_MAX_DEEPSLEEP_DIVIDER_ID 5 62 1.1 riastrad #define MAX_REGULAR_DPM_NUMBER 8 63 1.1 riastrad #define CISLAND_MINIMUM_ENGINE_CLOCK 800 64 1.1 riastrad 65 1.1 riastrad struct ci_single_dpm_table { 66 1.1 riastrad u32 count; 67 1.1 riastrad struct ci_dpm_level dpm_levels[MAX_REGULAR_DPM_NUMBER]; 68 1.1 riastrad }; 69 1.1 riastrad 70 1.1 riastrad struct ci_dpm_table { 71 1.1 riastrad struct ci_single_dpm_table sclk_table; 72 1.1 riastrad struct ci_single_dpm_table mclk_table; 73 1.1 riastrad struct ci_single_dpm_table pcie_speed_table; 74 1.1 riastrad struct ci_single_dpm_table vddc_table; 75 1.1 riastrad struct ci_single_dpm_table vddci_table; 76 1.1 riastrad struct ci_single_dpm_table mvdd_table; 77 1.1 riastrad }; 78 1.1 riastrad 79 1.1 riastrad struct ci_mc_reg_entry { 80 1.1 riastrad u32 mclk_max; 81 1.1 riastrad u32 mc_data[SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE]; 82 1.1 riastrad }; 83 1.1 riastrad 84 1.1 riastrad struct ci_mc_reg_table { 85 1.1 riastrad u8 last; 86 1.1 riastrad u8 num_entries; 87 1.1 riastrad u16 valid_flag; 88 1.1 riastrad struct ci_mc_reg_entry mc_reg_table_entry[MAX_AC_TIMING_ENTRIES]; 89 1.1 riastrad SMU7_Discrete_MCRegisterAddress mc_reg_address[SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE]; 90 1.1 riastrad }; 91 1.1 riastrad 92 1.1 riastrad struct ci_ulv_parm 93 1.1 riastrad { 94 1.1 riastrad bool supported; 95 1.1 riastrad u32 cg_ulv_parameter; 96 1.1 riastrad u32 volt_change_delay; 97 1.1 riastrad struct ci_pl pl; 98 1.1 riastrad }; 99 1.1 riastrad 100 1.1 riastrad #define CISLANDS_MAX_LEAKAGE_COUNT 8 101 1.1 riastrad 102 1.1 riastrad struct ci_leakage_voltage { 103 1.1 riastrad u16 count; 104 1.1 riastrad u16 leakage_id[CISLANDS_MAX_LEAKAGE_COUNT]; 105 1.1 riastrad u16 actual_voltage[CISLANDS_MAX_LEAKAGE_COUNT]; 106 1.1 riastrad }; 107 1.1 riastrad 108 1.1 riastrad struct ci_dpm_level_enable_mask { 109 1.1 riastrad u32 uvd_dpm_enable_mask; 110 1.1 riastrad u32 vce_dpm_enable_mask; 111 1.1 riastrad u32 acp_dpm_enable_mask; 112 1.1 riastrad u32 samu_dpm_enable_mask; 113 1.1 riastrad u32 sclk_dpm_enable_mask; 114 1.1 riastrad u32 mclk_dpm_enable_mask; 115 1.1 riastrad u32 pcie_dpm_enable_mask; 116 1.1 riastrad }; 117 1.1 riastrad 118 1.1 riastrad struct ci_vbios_boot_state 119 1.1 riastrad { 120 1.1 riastrad u16 mvdd_bootup_value; 121 1.1 riastrad u16 vddc_bootup_value; 122 1.1 riastrad u16 vddci_bootup_value; 123 1.1 riastrad u32 sclk_bootup_value; 124 1.1 riastrad u32 mclk_bootup_value; 125 1.1 riastrad u16 pcie_gen_bootup_value; 126 1.1 riastrad u16 pcie_lane_bootup_value; 127 1.1 riastrad }; 128 1.1 riastrad 129 1.1 riastrad struct ci_clock_registers { 130 1.1 riastrad u32 cg_spll_func_cntl; 131 1.1 riastrad u32 cg_spll_func_cntl_2; 132 1.1 riastrad u32 cg_spll_func_cntl_3; 133 1.1 riastrad u32 cg_spll_func_cntl_4; 134 1.1 riastrad u32 cg_spll_spread_spectrum; 135 1.1 riastrad u32 cg_spll_spread_spectrum_2; 136 1.1 riastrad u32 dll_cntl; 137 1.1 riastrad u32 mclk_pwrmgt_cntl; 138 1.1 riastrad u32 mpll_ad_func_cntl; 139 1.1 riastrad u32 mpll_dq_func_cntl; 140 1.1 riastrad u32 mpll_func_cntl; 141 1.1 riastrad u32 mpll_func_cntl_1; 142 1.1 riastrad u32 mpll_func_cntl_2; 143 1.1 riastrad u32 mpll_ss1; 144 1.1 riastrad u32 mpll_ss2; 145 1.1 riastrad }; 146 1.1 riastrad 147 1.1 riastrad struct ci_thermal_temperature_setting { 148 1.1 riastrad s32 temperature_low; 149 1.1 riastrad s32 temperature_high; 150 1.1 riastrad s32 temperature_shutdown; 151 1.1 riastrad }; 152 1.1 riastrad 153 1.1 riastrad struct ci_pcie_perf_range { 154 1.1 riastrad u16 max; 155 1.1 riastrad u16 min; 156 1.1 riastrad }; 157 1.1 riastrad 158 1.1 riastrad enum ci_pt_config_reg_type { 159 1.1 riastrad CISLANDS_CONFIGREG_MMR = 0, 160 1.1 riastrad CISLANDS_CONFIGREG_SMC_IND, 161 1.1 riastrad CISLANDS_CONFIGREG_DIDT_IND, 162 1.1 riastrad CISLANDS_CONFIGREG_CACHE, 163 1.1 riastrad CISLANDS_CONFIGREG_MAX 164 1.1 riastrad }; 165 1.1 riastrad 166 1.1 riastrad #define POWERCONTAINMENT_FEATURE_BAPM 0x00000001 167 1.1 riastrad #define POWERCONTAINMENT_FEATURE_TDCLimit 0x00000002 168 1.1 riastrad #define POWERCONTAINMENT_FEATURE_PkgPwrLimit 0x00000004 169 1.1 riastrad 170 1.1 riastrad struct ci_pt_config_reg { 171 1.1 riastrad u32 offset; 172 1.1 riastrad u32 mask; 173 1.1 riastrad u32 shift; 174 1.1 riastrad u32 value; 175 1.1 riastrad enum ci_pt_config_reg_type type; 176 1.1 riastrad }; 177 1.1 riastrad 178 1.1 riastrad struct ci_pt_defaults { 179 1.1 riastrad u8 svi_load_line_en; 180 1.1 riastrad u8 svi_load_line_vddc; 181 1.1 riastrad u8 tdc_vddc_throttle_release_limit_perc; 182 1.1 riastrad u8 tdc_mawt; 183 1.1 riastrad u8 tdc_waterfall_ctl; 184 1.1 riastrad u8 dte_ambient_temp_base; 185 1.1 riastrad u32 display_cac; 186 1.1 riastrad u32 bapm_temp_gradient; 187 1.1 riastrad u16 bapmti_r[SMU7_DTE_ITERATIONS * SMU7_DTE_SOURCES * SMU7_DTE_SINKS]; 188 1.1 riastrad u16 bapmti_rc[SMU7_DTE_ITERATIONS * SMU7_DTE_SOURCES * SMU7_DTE_SINKS]; 189 1.1 riastrad }; 190 1.1 riastrad 191 1.1 riastrad #define DPMTABLE_OD_UPDATE_SCLK 0x00000001 192 1.1 riastrad #define DPMTABLE_OD_UPDATE_MCLK 0x00000002 193 1.1 riastrad #define DPMTABLE_UPDATE_SCLK 0x00000004 194 1.1 riastrad #define DPMTABLE_UPDATE_MCLK 0x00000008 195 1.1 riastrad 196 1.1 riastrad struct ci_power_info { 197 1.1 riastrad struct ci_dpm_table dpm_table; 198 1.1 riastrad u32 voltage_control; 199 1.1 riastrad u32 mvdd_control; 200 1.1 riastrad u32 vddci_control; 201 1.1 riastrad u32 active_auto_throttle_sources; 202 1.1 riastrad struct ci_clock_registers clock_registers; 203 1.1 riastrad u16 acpi_vddc; 204 1.1 riastrad u16 acpi_vddci; 205 1.1 riastrad enum radeon_pcie_gen force_pcie_gen; 206 1.1 riastrad enum radeon_pcie_gen acpi_pcie_gen; 207 1.1 riastrad struct ci_leakage_voltage vddc_leakage; 208 1.1 riastrad struct ci_leakage_voltage vddci_leakage; 209 1.1 riastrad u16 max_vddc_in_pp_table; 210 1.1 riastrad u16 min_vddc_in_pp_table; 211 1.1 riastrad u16 max_vddci_in_pp_table; 212 1.1 riastrad u16 min_vddci_in_pp_table; 213 1.1 riastrad u32 mclk_strobe_mode_threshold; 214 1.1 riastrad u32 mclk_stutter_mode_threshold; 215 1.1 riastrad u32 mclk_edc_enable_threshold; 216 1.1 riastrad u32 mclk_edc_wr_enable_threshold; 217 1.1 riastrad struct ci_vbios_boot_state vbios_boot_state; 218 1.1 riastrad /* smc offsets */ 219 1.1 riastrad u32 sram_end; 220 1.1 riastrad u32 dpm_table_start; 221 1.1 riastrad u32 soft_regs_start; 222 1.1 riastrad u32 mc_reg_table_start; 223 1.1 riastrad u32 fan_table_start; 224 1.1 riastrad u32 arb_table_start; 225 1.1 riastrad /* smc tables */ 226 1.1 riastrad SMU7_Discrete_DpmTable smc_state_table; 227 1.1 riastrad SMU7_Discrete_MCRegisters smc_mc_reg_table; 228 1.1 riastrad SMU7_Discrete_PmFuses smc_powertune_table; 229 1.1 riastrad /* other stuff */ 230 1.1 riastrad struct ci_mc_reg_table mc_reg_table; 231 1.1 riastrad struct atom_voltage_table vddc_voltage_table; 232 1.1 riastrad struct atom_voltage_table vddci_voltage_table; 233 1.1 riastrad struct atom_voltage_table mvdd_voltage_table; 234 1.1 riastrad struct ci_ulv_parm ulv; 235 1.1 riastrad u32 power_containment_features; 236 1.1 riastrad const struct ci_pt_defaults *powertune_defaults; 237 1.1 riastrad u32 dte_tj_offset; 238 1.1 riastrad bool vddc_phase_shed_control; 239 1.1 riastrad struct ci_thermal_temperature_setting thermal_temp_setting; 240 1.1 riastrad struct ci_dpm_level_enable_mask dpm_level_enable_mask; 241 1.1 riastrad u32 need_update_smu7_dpm_table; 242 1.1 riastrad u32 sclk_dpm_key_disabled; 243 1.1 riastrad u32 mclk_dpm_key_disabled; 244 1.1 riastrad u32 pcie_dpm_key_disabled; 245 1.2 riastrad u32 thermal_sclk_dpm_enabled; 246 1.1 riastrad struct ci_pcie_perf_range pcie_gen_performance; 247 1.1 riastrad struct ci_pcie_perf_range pcie_lane_performance; 248 1.1 riastrad struct ci_pcie_perf_range pcie_gen_powersaving; 249 1.1 riastrad struct ci_pcie_perf_range pcie_lane_powersaving; 250 1.1 riastrad u32 activity_target[SMU7_MAX_LEVELS_GRAPHICS]; 251 1.1 riastrad u32 mclk_activity_target; 252 1.1 riastrad u32 low_sclk_interrupt_t; 253 1.1 riastrad u32 last_mclk_dpm_enable_mask; 254 1.1 riastrad u32 sys_pcie_mask; 255 1.1 riastrad /* caps */ 256 1.1 riastrad bool caps_power_containment; 257 1.1 riastrad bool caps_cac; 258 1.1 riastrad bool caps_sq_ramping; 259 1.1 riastrad bool caps_db_ramping; 260 1.1 riastrad bool caps_td_ramping; 261 1.1 riastrad bool caps_tcp_ramping; 262 1.1 riastrad bool caps_fps; 263 1.1 riastrad bool caps_sclk_ds; 264 1.1 riastrad bool caps_sclk_ss_support; 265 1.1 riastrad bool caps_mclk_ss_support; 266 1.1 riastrad bool caps_uvd_dpm; 267 1.1 riastrad bool caps_vce_dpm; 268 1.1 riastrad bool caps_samu_dpm; 269 1.1 riastrad bool caps_acp_dpm; 270 1.1 riastrad bool caps_automatic_dc_transition; 271 1.1 riastrad bool caps_sclk_throttle_low_notification; 272 1.1 riastrad bool caps_dynamic_ac_timing; 273 1.2 riastrad bool caps_od_fuzzy_fan_control_support; 274 1.1 riastrad /* flags */ 275 1.1 riastrad bool thermal_protection; 276 1.1 riastrad bool pcie_performance_request; 277 1.1 riastrad bool dynamic_ss; 278 1.1 riastrad bool dll_default_on; 279 1.1 riastrad bool cac_enabled; 280 1.1 riastrad bool uvd_enabled; 281 1.1 riastrad bool battery_state; 282 1.1 riastrad bool pspp_notify_required; 283 1.1 riastrad bool mem_gddr5; 284 1.1 riastrad bool enable_bapm_feature; 285 1.1 riastrad bool enable_tdc_limit_feature; 286 1.1 riastrad bool enable_pkg_pwr_tracking_feature; 287 1.1 riastrad bool use_pcie_performance_levels; 288 1.1 riastrad bool use_pcie_powersaving_levels; 289 1.1 riastrad bool uvd_power_gated; 290 1.1 riastrad /* driver states */ 291 1.1 riastrad struct radeon_ps current_rps; 292 1.1 riastrad struct ci_ps current_ps; 293 1.1 riastrad struct radeon_ps requested_rps; 294 1.1 riastrad struct ci_ps requested_ps; 295 1.2 riastrad /* fan control */ 296 1.2 riastrad bool fan_ctrl_is_in_default_mode; 297 1.2 riastrad bool fan_is_controlled_by_smc; 298 1.2 riastrad u32 t_min; 299 1.2 riastrad u32 fan_ctrl_default_mode; 300 1.1 riastrad }; 301 1.1 riastrad 302 1.1 riastrad #define CISLANDS_VOLTAGE_CONTROL_NONE 0x0 303 1.1 riastrad #define CISLANDS_VOLTAGE_CONTROL_BY_GPIO 0x1 304 1.1 riastrad #define CISLANDS_VOLTAGE_CONTROL_BY_SVID2 0x2 305 1.1 riastrad 306 1.1 riastrad #define CISLANDS_Q88_FORMAT_CONVERSION_UNIT 256 307 1.1 riastrad 308 1.1 riastrad #define CISLANDS_VRC_DFLT0 0x3FFFC000 309 1.1 riastrad #define CISLANDS_VRC_DFLT1 0x000400 310 1.1 riastrad #define CISLANDS_VRC_DFLT2 0xC00080 311 1.1 riastrad #define CISLANDS_VRC_DFLT3 0xC00200 312 1.1 riastrad #define CISLANDS_VRC_DFLT4 0xC01680 313 1.1 riastrad #define CISLANDS_VRC_DFLT5 0xC00033 314 1.1 riastrad #define CISLANDS_VRC_DFLT6 0xC00033 315 1.1 riastrad #define CISLANDS_VRC_DFLT7 0x3FFFC000 316 1.1 riastrad 317 1.1 riastrad #define CISLANDS_CGULVPARAMETER_DFLT 0x00040035 318 1.1 riastrad #define CISLAND_TARGETACTIVITY_DFLT 30 319 1.1 riastrad #define CISLAND_MCLK_TARGETACTIVITY_DFLT 10 320 1.1 riastrad 321 1.1 riastrad #define PCIE_PERF_REQ_REMOVE_REGISTRY 0 322 1.1 riastrad #define PCIE_PERF_REQ_FORCE_LOWPOWER 1 323 1.1 riastrad #define PCIE_PERF_REQ_PECI_GEN1 2 324 1.1 riastrad #define PCIE_PERF_REQ_PECI_GEN2 3 325 1.1 riastrad #define PCIE_PERF_REQ_PECI_GEN3 4 326 1.1 riastrad 327 1.1 riastrad int ci_copy_bytes_to_smc(struct radeon_device *rdev, 328 1.1 riastrad u32 smc_start_address, 329 1.1 riastrad const u8 *src, u32 byte_count, u32 limit); 330 1.1 riastrad void ci_start_smc(struct radeon_device *rdev); 331 1.1 riastrad void ci_reset_smc(struct radeon_device *rdev); 332 1.1 riastrad int ci_program_jump_on_start(struct radeon_device *rdev); 333 1.1 riastrad void ci_stop_smc_clock(struct radeon_device *rdev); 334 1.1 riastrad void ci_start_smc_clock(struct radeon_device *rdev); 335 1.1 riastrad bool ci_is_smc_running(struct radeon_device *rdev); 336 1.1 riastrad PPSMC_Result ci_wait_for_smc_inactive(struct radeon_device *rdev); 337 1.1 riastrad int ci_load_smc_ucode(struct radeon_device *rdev, u32 limit); 338 1.1 riastrad int ci_read_smc_sram_dword(struct radeon_device *rdev, 339 1.1 riastrad u32 smc_address, u32 *value, u32 limit); 340 1.1 riastrad int ci_write_smc_sram_dword(struct radeon_device *rdev, 341 1.1 riastrad u32 smc_address, u32 value, u32 limit); 342 1.1 riastrad 343 1.1 riastrad #endif 344