Alex Deucher | 41a524a | 2013-08-14 01:01:40 -0400 | [diff] [blame] | 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 | |
| 24 | #include "drmP.h" |
| 25 | #include "radeon.h" |
| 26 | #include "cikd.h" |
| 27 | #include "r600_dpm.h" |
| 28 | #include "kv_dpm.h" |
Alex Deucher | ae3e40e | 2013-07-18 16:39:53 -0400 | [diff] [blame^] | 29 | #include <linux/seq_file.h> |
Alex Deucher | 41a524a | 2013-08-14 01:01:40 -0400 | [diff] [blame] | 30 | |
| 31 | #define KV_MAX_DEEPSLEEP_DIVIDER_ID 5 |
| 32 | #define KV_MINIMUM_ENGINE_CLOCK 800 |
| 33 | #define SMC_RAM_END 0x40000 |
| 34 | |
| 35 | static void kv_init_graphics_levels(struct radeon_device *rdev); |
| 36 | static int kv_calculate_ds_divider(struct radeon_device *rdev); |
| 37 | static int kv_calculate_nbps_level_settings(struct radeon_device *rdev); |
| 38 | static int kv_calculate_dpm_settings(struct radeon_device *rdev); |
| 39 | static void kv_enable_new_levels(struct radeon_device *rdev); |
| 40 | static void kv_program_nbps_index_settings(struct radeon_device *rdev, |
| 41 | struct radeon_ps *new_rps); |
| 42 | static int kv_set_enabled_levels(struct radeon_device *rdev); |
| 43 | static int kv_force_dpm_lowest(struct radeon_device *rdev); |
| 44 | static void kv_apply_state_adjust_rules(struct radeon_device *rdev, |
| 45 | struct radeon_ps *new_rps, |
| 46 | struct radeon_ps *old_rps); |
| 47 | static int kv_set_thermal_temperature_range(struct radeon_device *rdev, |
| 48 | int min_temp, int max_temp); |
| 49 | static int kv_init_fps_limits(struct radeon_device *rdev); |
| 50 | |
| 51 | static void kv_dpm_powergate_uvd(struct radeon_device *rdev, bool gate); |
| 52 | static void kv_dpm_powergate_vce(struct radeon_device *rdev, bool gate); |
| 53 | static void kv_dpm_powergate_samu(struct radeon_device *rdev, bool gate); |
| 54 | static void kv_dpm_powergate_acp(struct radeon_device *rdev, bool gate); |
| 55 | |
| 56 | extern void cik_enter_rlc_safe_mode(struct radeon_device *rdev); |
| 57 | extern void cik_exit_rlc_safe_mode(struct radeon_device *rdev); |
| 58 | extern void cik_update_cg(struct radeon_device *rdev, |
| 59 | u32 block, bool enable); |
| 60 | |
| 61 | static const struct kv_lcac_config_values sx_local_cac_cfg_kv[] = |
| 62 | { |
| 63 | { 0, 4, 1 }, |
| 64 | { 1, 4, 1 }, |
| 65 | { 2, 5, 1 }, |
| 66 | { 3, 4, 2 }, |
| 67 | { 4, 1, 1 }, |
| 68 | { 5, 5, 2 }, |
| 69 | { 6, 6, 1 }, |
| 70 | { 7, 9, 2 }, |
| 71 | { 0xffffffff } |
| 72 | }; |
| 73 | |
| 74 | static const struct kv_lcac_config_values mc0_local_cac_cfg_kv[] = |
| 75 | { |
| 76 | { 0, 4, 1 }, |
| 77 | { 0xffffffff } |
| 78 | }; |
| 79 | |
| 80 | static const struct kv_lcac_config_values mc1_local_cac_cfg_kv[] = |
| 81 | { |
| 82 | { 0, 4, 1 }, |
| 83 | { 0xffffffff } |
| 84 | }; |
| 85 | |
| 86 | static const struct kv_lcac_config_values mc2_local_cac_cfg_kv[] = |
| 87 | { |
| 88 | { 0, 4, 1 }, |
| 89 | { 0xffffffff } |
| 90 | }; |
| 91 | |
| 92 | static const struct kv_lcac_config_values mc3_local_cac_cfg_kv[] = |
| 93 | { |
| 94 | { 0, 4, 1 }, |
| 95 | { 0xffffffff } |
| 96 | }; |
| 97 | |
| 98 | static const struct kv_lcac_config_values cpl_local_cac_cfg_kv[] = |
| 99 | { |
| 100 | { 0, 4, 1 }, |
| 101 | { 1, 4, 1 }, |
| 102 | { 2, 5, 1 }, |
| 103 | { 3, 4, 1 }, |
| 104 | { 4, 1, 1 }, |
| 105 | { 5, 5, 1 }, |
| 106 | { 6, 6, 1 }, |
| 107 | { 7, 9, 1 }, |
| 108 | { 8, 4, 1 }, |
| 109 | { 9, 2, 1 }, |
| 110 | { 10, 3, 1 }, |
| 111 | { 11, 6, 1 }, |
| 112 | { 12, 8, 2 }, |
| 113 | { 13, 1, 1 }, |
| 114 | { 14, 2, 1 }, |
| 115 | { 15, 3, 1 }, |
| 116 | { 16, 1, 1 }, |
| 117 | { 17, 4, 1 }, |
| 118 | { 18, 3, 1 }, |
| 119 | { 19, 1, 1 }, |
| 120 | { 20, 8, 1 }, |
| 121 | { 21, 5, 1 }, |
| 122 | { 22, 1, 1 }, |
| 123 | { 23, 1, 1 }, |
| 124 | { 24, 4, 1 }, |
| 125 | { 27, 6, 1 }, |
| 126 | { 28, 1, 1 }, |
| 127 | { 0xffffffff } |
| 128 | }; |
| 129 | |
| 130 | static const struct kv_lcac_config_reg sx0_cac_config_reg[] = |
| 131 | { |
| 132 | { 0xc0400d00, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 } |
| 133 | }; |
| 134 | |
| 135 | static const struct kv_lcac_config_reg mc0_cac_config_reg[] = |
| 136 | { |
| 137 | { 0xc0400d30, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 } |
| 138 | }; |
| 139 | |
| 140 | static const struct kv_lcac_config_reg mc1_cac_config_reg[] = |
| 141 | { |
| 142 | { 0xc0400d3c, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 } |
| 143 | }; |
| 144 | |
| 145 | static const struct kv_lcac_config_reg mc2_cac_config_reg[] = |
| 146 | { |
| 147 | { 0xc0400d48, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 } |
| 148 | }; |
| 149 | |
| 150 | static const struct kv_lcac_config_reg mc3_cac_config_reg[] = |
| 151 | { |
| 152 | { 0xc0400d54, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 } |
| 153 | }; |
| 154 | |
| 155 | static const struct kv_lcac_config_reg cpl_cac_config_reg[] = |
| 156 | { |
| 157 | { 0xc0400d80, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 } |
| 158 | }; |
| 159 | |
| 160 | static const struct kv_pt_config_reg didt_config_kv[] = |
| 161 | { |
| 162 | { 0x10, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 163 | { 0x10, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 164 | { 0x10, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 165 | { 0x10, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 166 | { 0x11, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 167 | { 0x11, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 168 | { 0x11, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 169 | { 0x11, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 170 | { 0x12, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 171 | { 0x12, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 172 | { 0x12, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 173 | { 0x12, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 174 | { 0x2, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND }, |
| 175 | { 0x2, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND }, |
| 176 | { 0x2, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND }, |
| 177 | { 0x1, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND }, |
| 178 | { 0x1, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND }, |
| 179 | { 0x0, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 180 | { 0x30, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 181 | { 0x30, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 182 | { 0x30, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 183 | { 0x30, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 184 | { 0x31, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 185 | { 0x31, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 186 | { 0x31, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 187 | { 0x31, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 188 | { 0x32, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 189 | { 0x32, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 190 | { 0x32, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 191 | { 0x32, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 192 | { 0x22, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND }, |
| 193 | { 0x22, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND }, |
| 194 | { 0x22, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND }, |
| 195 | { 0x21, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND }, |
| 196 | { 0x21, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND }, |
| 197 | { 0x20, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 198 | { 0x50, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 199 | { 0x50, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 200 | { 0x50, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 201 | { 0x50, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 202 | { 0x51, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 203 | { 0x51, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 204 | { 0x51, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 205 | { 0x51, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 206 | { 0x52, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 207 | { 0x52, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 208 | { 0x52, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 209 | { 0x52, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 210 | { 0x42, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND }, |
| 211 | { 0x42, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND }, |
| 212 | { 0x42, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND }, |
| 213 | { 0x41, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND }, |
| 214 | { 0x41, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND }, |
| 215 | { 0x40, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 216 | { 0x70, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 217 | { 0x70, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 218 | { 0x70, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 219 | { 0x70, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 220 | { 0x71, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 221 | { 0x71, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 222 | { 0x71, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 223 | { 0x71, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 224 | { 0x72, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 225 | { 0x72, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 226 | { 0x72, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 227 | { 0x72, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 228 | { 0x62, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND }, |
| 229 | { 0x62, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND }, |
| 230 | { 0x62, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND }, |
| 231 | { 0x61, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND }, |
| 232 | { 0x61, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND }, |
| 233 | { 0x60, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND }, |
| 234 | { 0xFFFFFFFF } |
| 235 | }; |
| 236 | |
| 237 | static struct kv_ps *kv_get_ps(struct radeon_ps *rps) |
| 238 | { |
| 239 | struct kv_ps *ps = rps->ps_priv; |
| 240 | |
| 241 | return ps; |
| 242 | } |
| 243 | |
| 244 | static struct kv_power_info *kv_get_pi(struct radeon_device *rdev) |
| 245 | { |
| 246 | struct kv_power_info *pi = rdev->pm.dpm.priv; |
| 247 | |
| 248 | return pi; |
| 249 | } |
| 250 | |
| 251 | #if 0 |
| 252 | static void kv_program_local_cac_table(struct radeon_device *rdev, |
| 253 | const struct kv_lcac_config_values *local_cac_table, |
| 254 | const struct kv_lcac_config_reg *local_cac_reg) |
| 255 | { |
| 256 | u32 i, count, data; |
| 257 | const struct kv_lcac_config_values *values = local_cac_table; |
| 258 | |
| 259 | while (values->block_id != 0xffffffff) { |
| 260 | count = values->signal_id; |
| 261 | for (i = 0; i < count; i++) { |
| 262 | data = ((values->block_id << local_cac_reg->block_shift) & |
| 263 | local_cac_reg->block_mask); |
| 264 | data |= ((i << local_cac_reg->signal_shift) & |
| 265 | local_cac_reg->signal_mask); |
| 266 | data |= ((values->t << local_cac_reg->t_shift) & |
| 267 | local_cac_reg->t_mask); |
| 268 | data |= ((1 << local_cac_reg->enable_shift) & |
| 269 | local_cac_reg->enable_mask); |
| 270 | WREG32_SMC(local_cac_reg->cntl, data); |
| 271 | } |
| 272 | values++; |
| 273 | } |
| 274 | } |
| 275 | #endif |
| 276 | |
| 277 | static int kv_program_pt_config_registers(struct radeon_device *rdev, |
| 278 | const struct kv_pt_config_reg *cac_config_regs) |
| 279 | { |
| 280 | const struct kv_pt_config_reg *config_regs = cac_config_regs; |
| 281 | u32 data; |
| 282 | u32 cache = 0; |
| 283 | |
| 284 | if (config_regs == NULL) |
| 285 | return -EINVAL; |
| 286 | |
| 287 | while (config_regs->offset != 0xFFFFFFFF) { |
| 288 | if (config_regs->type == KV_CONFIGREG_CACHE) { |
| 289 | cache |= ((config_regs->value << config_regs->shift) & config_regs->mask); |
| 290 | } else { |
| 291 | switch (config_regs->type) { |
| 292 | case KV_CONFIGREG_SMC_IND: |
| 293 | data = RREG32_SMC(config_regs->offset); |
| 294 | break; |
| 295 | case KV_CONFIGREG_DIDT_IND: |
| 296 | data = RREG32_DIDT(config_regs->offset); |
| 297 | break; |
| 298 | default: |
| 299 | data = RREG32(config_regs->offset << 2); |
| 300 | break; |
| 301 | } |
| 302 | |
| 303 | data &= ~config_regs->mask; |
| 304 | data |= ((config_regs->value << config_regs->shift) & config_regs->mask); |
| 305 | data |= cache; |
| 306 | cache = 0; |
| 307 | |
| 308 | switch (config_regs->type) { |
| 309 | case KV_CONFIGREG_SMC_IND: |
| 310 | WREG32_SMC(config_regs->offset, data); |
| 311 | break; |
| 312 | case KV_CONFIGREG_DIDT_IND: |
| 313 | WREG32_DIDT(config_regs->offset, data); |
| 314 | break; |
| 315 | default: |
| 316 | WREG32(config_regs->offset << 2, data); |
| 317 | break; |
| 318 | } |
| 319 | } |
| 320 | config_regs++; |
| 321 | } |
| 322 | |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | static void kv_do_enable_didt(struct radeon_device *rdev, bool enable) |
| 327 | { |
| 328 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 329 | u32 data; |
| 330 | |
| 331 | if (pi->caps_sq_ramping) { |
| 332 | data = RREG32_DIDT(DIDT_SQ_CTRL0); |
| 333 | if (enable) |
| 334 | data |= DIDT_CTRL_EN; |
| 335 | else |
| 336 | data &= ~DIDT_CTRL_EN; |
| 337 | WREG32_DIDT(DIDT_SQ_CTRL0, data); |
| 338 | } |
| 339 | |
| 340 | if (pi->caps_db_ramping) { |
| 341 | data = RREG32_DIDT(DIDT_DB_CTRL0); |
| 342 | if (enable) |
| 343 | data |= DIDT_CTRL_EN; |
| 344 | else |
| 345 | data &= ~DIDT_CTRL_EN; |
| 346 | WREG32_DIDT(DIDT_DB_CTRL0, data); |
| 347 | } |
| 348 | |
| 349 | if (pi->caps_td_ramping) { |
| 350 | data = RREG32_DIDT(DIDT_TD_CTRL0); |
| 351 | if (enable) |
| 352 | data |= DIDT_CTRL_EN; |
| 353 | else |
| 354 | data &= ~DIDT_CTRL_EN; |
| 355 | WREG32_DIDT(DIDT_TD_CTRL0, data); |
| 356 | } |
| 357 | |
| 358 | if (pi->caps_tcp_ramping) { |
| 359 | data = RREG32_DIDT(DIDT_TCP_CTRL0); |
| 360 | if (enable) |
| 361 | data |= DIDT_CTRL_EN; |
| 362 | else |
| 363 | data &= ~DIDT_CTRL_EN; |
| 364 | WREG32_DIDT(DIDT_TCP_CTRL0, data); |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | static int kv_enable_didt(struct radeon_device *rdev, bool enable) |
| 369 | { |
| 370 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 371 | int ret; |
| 372 | |
| 373 | if (pi->caps_sq_ramping || |
| 374 | pi->caps_db_ramping || |
| 375 | pi->caps_td_ramping || |
| 376 | pi->caps_tcp_ramping) { |
| 377 | cik_enter_rlc_safe_mode(rdev); |
| 378 | |
| 379 | if (enable) { |
| 380 | ret = kv_program_pt_config_registers(rdev, didt_config_kv); |
| 381 | if (ret) { |
| 382 | cik_exit_rlc_safe_mode(rdev); |
| 383 | return ret; |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | kv_do_enable_didt(rdev, enable); |
| 388 | |
| 389 | cik_exit_rlc_safe_mode(rdev); |
| 390 | } |
| 391 | |
| 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | #if 0 |
| 396 | static void kv_initialize_hardware_cac_manager(struct radeon_device *rdev) |
| 397 | { |
| 398 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 399 | |
| 400 | if (pi->caps_cac) { |
| 401 | WREG32_SMC(LCAC_SX0_OVR_SEL, 0); |
| 402 | WREG32_SMC(LCAC_SX0_OVR_VAL, 0); |
| 403 | kv_program_local_cac_table(rdev, sx_local_cac_cfg_kv, sx0_cac_config_reg); |
| 404 | |
| 405 | WREG32_SMC(LCAC_MC0_OVR_SEL, 0); |
| 406 | WREG32_SMC(LCAC_MC0_OVR_VAL, 0); |
| 407 | kv_program_local_cac_table(rdev, mc0_local_cac_cfg_kv, mc0_cac_config_reg); |
| 408 | |
| 409 | WREG32_SMC(LCAC_MC1_OVR_SEL, 0); |
| 410 | WREG32_SMC(LCAC_MC1_OVR_VAL, 0); |
| 411 | kv_program_local_cac_table(rdev, mc1_local_cac_cfg_kv, mc1_cac_config_reg); |
| 412 | |
| 413 | WREG32_SMC(LCAC_MC2_OVR_SEL, 0); |
| 414 | WREG32_SMC(LCAC_MC2_OVR_VAL, 0); |
| 415 | kv_program_local_cac_table(rdev, mc2_local_cac_cfg_kv, mc2_cac_config_reg); |
| 416 | |
| 417 | WREG32_SMC(LCAC_MC3_OVR_SEL, 0); |
| 418 | WREG32_SMC(LCAC_MC3_OVR_VAL, 0); |
| 419 | kv_program_local_cac_table(rdev, mc3_local_cac_cfg_kv, mc3_cac_config_reg); |
| 420 | |
| 421 | WREG32_SMC(LCAC_CPL_OVR_SEL, 0); |
| 422 | WREG32_SMC(LCAC_CPL_OVR_VAL, 0); |
| 423 | kv_program_local_cac_table(rdev, cpl_local_cac_cfg_kv, cpl_cac_config_reg); |
| 424 | } |
| 425 | } |
| 426 | #endif |
| 427 | |
| 428 | static int kv_enable_smc_cac(struct radeon_device *rdev, bool enable) |
| 429 | { |
| 430 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 431 | int ret = 0; |
| 432 | |
| 433 | if (pi->caps_cac) { |
| 434 | if (enable) { |
| 435 | ret = kv_notify_message_to_smu(rdev, PPSMC_MSG_EnableCac); |
| 436 | if (ret) |
| 437 | pi->cac_enabled = false; |
| 438 | else |
| 439 | pi->cac_enabled = true; |
| 440 | } else if (pi->cac_enabled) { |
| 441 | kv_notify_message_to_smu(rdev, PPSMC_MSG_DisableCac); |
| 442 | pi->cac_enabled = false; |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | return ret; |
| 447 | } |
| 448 | |
| 449 | static int kv_process_firmware_header(struct radeon_device *rdev) |
| 450 | { |
| 451 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 452 | u32 tmp; |
| 453 | int ret; |
| 454 | |
| 455 | ret = kv_read_smc_sram_dword(rdev, SMU7_FIRMWARE_HEADER_LOCATION + |
| 456 | offsetof(SMU7_Firmware_Header, DpmTable), |
| 457 | &tmp, pi->sram_end); |
| 458 | |
| 459 | if (ret == 0) |
| 460 | pi->dpm_table_start = tmp; |
| 461 | |
| 462 | ret = kv_read_smc_sram_dword(rdev, SMU7_FIRMWARE_HEADER_LOCATION + |
| 463 | offsetof(SMU7_Firmware_Header, SoftRegisters), |
| 464 | &tmp, pi->sram_end); |
| 465 | |
| 466 | if (ret == 0) |
| 467 | pi->soft_regs_start = tmp; |
| 468 | |
| 469 | return ret; |
| 470 | } |
| 471 | |
| 472 | static int kv_enable_dpm_voltage_scaling(struct radeon_device *rdev) |
| 473 | { |
| 474 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 475 | int ret; |
| 476 | |
| 477 | pi->graphics_voltage_change_enable = 1; |
| 478 | |
| 479 | ret = kv_copy_bytes_to_smc(rdev, |
| 480 | pi->dpm_table_start + |
| 481 | offsetof(SMU7_Fusion_DpmTable, GraphicsVoltageChangeEnable), |
| 482 | &pi->graphics_voltage_change_enable, |
| 483 | sizeof(u8), pi->sram_end); |
| 484 | |
| 485 | return ret; |
| 486 | } |
| 487 | |
| 488 | static int kv_set_dpm_interval(struct radeon_device *rdev) |
| 489 | { |
| 490 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 491 | int ret; |
| 492 | |
| 493 | pi->graphics_interval = 1; |
| 494 | |
| 495 | ret = kv_copy_bytes_to_smc(rdev, |
| 496 | pi->dpm_table_start + |
| 497 | offsetof(SMU7_Fusion_DpmTable, GraphicsInterval), |
| 498 | &pi->graphics_interval, |
| 499 | sizeof(u8), pi->sram_end); |
| 500 | |
| 501 | return ret; |
| 502 | } |
| 503 | |
| 504 | static int kv_set_dpm_boot_state(struct radeon_device *rdev) |
| 505 | { |
| 506 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 507 | int ret; |
| 508 | |
| 509 | ret = kv_copy_bytes_to_smc(rdev, |
| 510 | pi->dpm_table_start + |
| 511 | offsetof(SMU7_Fusion_DpmTable, GraphicsBootLevel), |
| 512 | &pi->graphics_boot_level, |
| 513 | sizeof(u8), pi->sram_end); |
| 514 | |
| 515 | return ret; |
| 516 | } |
| 517 | |
| 518 | static void kv_program_vc(struct radeon_device *rdev) |
| 519 | { |
| 520 | WREG32_SMC(CG_FTV_0, 0x3FFFC000); |
| 521 | } |
| 522 | |
| 523 | static void kv_clear_vc(struct radeon_device *rdev) |
| 524 | { |
| 525 | WREG32_SMC(CG_FTV_0, 0); |
| 526 | } |
| 527 | |
| 528 | static int kv_set_divider_value(struct radeon_device *rdev, |
| 529 | u32 index, u32 sclk) |
| 530 | { |
| 531 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 532 | struct atom_clock_dividers dividers; |
| 533 | int ret; |
| 534 | |
| 535 | ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM, |
| 536 | sclk, false, ÷rs); |
| 537 | if (ret) |
| 538 | return ret; |
| 539 | |
| 540 | pi->graphics_level[index].SclkDid = (u8)dividers.post_div; |
| 541 | pi->graphics_level[index].SclkFrequency = cpu_to_be32(sclk); |
| 542 | |
| 543 | return 0; |
| 544 | } |
| 545 | |
| 546 | static u16 kv_convert_8bit_index_to_voltage(struct radeon_device *rdev, |
| 547 | u16 voltage) |
| 548 | { |
| 549 | return 6200 - (voltage * 25); |
| 550 | } |
| 551 | |
| 552 | static u16 kv_convert_2bit_index_to_voltage(struct radeon_device *rdev, |
| 553 | u32 vid_2bit) |
| 554 | { |
| 555 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 556 | u32 vid_8bit = sumo_convert_vid2_to_vid7(rdev, |
| 557 | &pi->sys_info.vid_mapping_table, |
| 558 | vid_2bit); |
| 559 | |
| 560 | return kv_convert_8bit_index_to_voltage(rdev, (u16)vid_8bit); |
| 561 | } |
| 562 | |
| 563 | |
| 564 | static int kv_set_vid(struct radeon_device *rdev, u32 index, u32 vid) |
| 565 | { |
| 566 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 567 | |
| 568 | pi->graphics_level[index].VoltageDownH = (u8)pi->voltage_drop_t; |
| 569 | pi->graphics_level[index].MinVddNb = |
| 570 | cpu_to_be32(kv_convert_2bit_index_to_voltage(rdev, vid)); |
| 571 | |
| 572 | return 0; |
| 573 | } |
| 574 | |
| 575 | static int kv_set_at(struct radeon_device *rdev, u32 index, u32 at) |
| 576 | { |
| 577 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 578 | |
| 579 | pi->graphics_level[index].AT = cpu_to_be16((u16)at); |
| 580 | |
| 581 | return 0; |
| 582 | } |
| 583 | |
| 584 | static void kv_dpm_power_level_enable(struct radeon_device *rdev, |
| 585 | u32 index, bool enable) |
| 586 | { |
| 587 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 588 | |
| 589 | pi->graphics_level[index].EnabledForActivity = enable ? 1 : 0; |
| 590 | } |
| 591 | |
| 592 | static void kv_start_dpm(struct radeon_device *rdev) |
| 593 | { |
| 594 | u32 tmp = RREG32_SMC(GENERAL_PWRMGT); |
| 595 | |
| 596 | tmp |= GLOBAL_PWRMGT_EN; |
| 597 | WREG32_SMC(GENERAL_PWRMGT, tmp); |
| 598 | |
| 599 | kv_smc_dpm_enable(rdev, true); |
| 600 | } |
| 601 | |
| 602 | static void kv_stop_dpm(struct radeon_device *rdev) |
| 603 | { |
| 604 | kv_smc_dpm_enable(rdev, false); |
| 605 | } |
| 606 | |
| 607 | static void kv_start_am(struct radeon_device *rdev) |
| 608 | { |
| 609 | u32 sclk_pwrmgt_cntl = RREG32_SMC(SCLK_PWRMGT_CNTL); |
| 610 | |
| 611 | sclk_pwrmgt_cntl &= ~(RESET_SCLK_CNT | RESET_BUSY_CNT); |
| 612 | sclk_pwrmgt_cntl |= DYNAMIC_PM_EN; |
| 613 | |
| 614 | WREG32_SMC(SCLK_PWRMGT_CNTL, sclk_pwrmgt_cntl); |
| 615 | } |
| 616 | |
| 617 | static void kv_reset_am(struct radeon_device *rdev) |
| 618 | { |
| 619 | u32 sclk_pwrmgt_cntl = RREG32_SMC(SCLK_PWRMGT_CNTL); |
| 620 | |
| 621 | sclk_pwrmgt_cntl |= (RESET_SCLK_CNT | RESET_BUSY_CNT); |
| 622 | |
| 623 | WREG32_SMC(SCLK_PWRMGT_CNTL, sclk_pwrmgt_cntl); |
| 624 | } |
| 625 | |
| 626 | static int kv_freeze_sclk_dpm(struct radeon_device *rdev, bool freeze) |
| 627 | { |
| 628 | return kv_notify_message_to_smu(rdev, freeze ? |
| 629 | PPSMC_MSG_SCLKDPM_FreezeLevel : PPSMC_MSG_SCLKDPM_UnfreezeLevel); |
| 630 | } |
| 631 | |
| 632 | static int kv_force_lowest_valid(struct radeon_device *rdev) |
| 633 | { |
| 634 | return kv_force_dpm_lowest(rdev); |
| 635 | } |
| 636 | |
| 637 | static int kv_unforce_levels(struct radeon_device *rdev) |
| 638 | { |
| 639 | return kv_notify_message_to_smu(rdev, PPSMC_MSG_NoForcedLevel); |
| 640 | } |
| 641 | |
| 642 | static int kv_update_sclk_t(struct radeon_device *rdev) |
| 643 | { |
| 644 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 645 | u32 low_sclk_interrupt_t = 0; |
| 646 | int ret = 0; |
| 647 | |
| 648 | if (pi->caps_sclk_throttle_low_notification) { |
| 649 | low_sclk_interrupt_t = cpu_to_be32(pi->low_sclk_interrupt_t); |
| 650 | |
| 651 | ret = kv_copy_bytes_to_smc(rdev, |
| 652 | pi->dpm_table_start + |
| 653 | offsetof(SMU7_Fusion_DpmTable, LowSclkInterruptT), |
| 654 | (u8 *)&low_sclk_interrupt_t, |
| 655 | sizeof(u32), pi->sram_end); |
| 656 | } |
| 657 | return ret; |
| 658 | } |
| 659 | |
| 660 | static int kv_program_bootup_state(struct radeon_device *rdev) |
| 661 | { |
| 662 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 663 | u32 i; |
| 664 | struct radeon_clock_voltage_dependency_table *table = |
| 665 | &rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk; |
| 666 | |
| 667 | if (table && table->count) { |
| 668 | for (i = pi->graphics_dpm_level_count - 1; i >= 0; i--) { |
| 669 | if ((table->entries[i].clk == pi->boot_pl.sclk) || |
| 670 | (i == 0)) |
| 671 | break; |
| 672 | } |
| 673 | |
| 674 | pi->graphics_boot_level = (u8)i; |
| 675 | kv_dpm_power_level_enable(rdev, i, true); |
| 676 | } else { |
| 677 | struct sumo_sclk_voltage_mapping_table *table = |
| 678 | &pi->sys_info.sclk_voltage_mapping_table; |
| 679 | |
| 680 | if (table->num_max_dpm_entries == 0) |
| 681 | return -EINVAL; |
| 682 | |
| 683 | for (i = pi->graphics_dpm_level_count - 1; i >= 0; i--) { |
| 684 | if ((table->entries[i].sclk_frequency == pi->boot_pl.sclk) || |
| 685 | (i == 0)) |
| 686 | break; |
| 687 | } |
| 688 | |
| 689 | pi->graphics_boot_level = (u8)i; |
| 690 | kv_dpm_power_level_enable(rdev, i, true); |
| 691 | } |
| 692 | return 0; |
| 693 | } |
| 694 | |
| 695 | static int kv_enable_auto_thermal_throttling(struct radeon_device *rdev) |
| 696 | { |
| 697 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 698 | int ret; |
| 699 | |
| 700 | pi->graphics_therm_throttle_enable = 1; |
| 701 | |
| 702 | ret = kv_copy_bytes_to_smc(rdev, |
| 703 | pi->dpm_table_start + |
| 704 | offsetof(SMU7_Fusion_DpmTable, GraphicsThermThrottleEnable), |
| 705 | &pi->graphics_therm_throttle_enable, |
| 706 | sizeof(u8), pi->sram_end); |
| 707 | |
| 708 | return ret; |
| 709 | } |
| 710 | |
| 711 | static int kv_upload_dpm_settings(struct radeon_device *rdev) |
| 712 | { |
| 713 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 714 | int ret; |
| 715 | |
| 716 | ret = kv_copy_bytes_to_smc(rdev, |
| 717 | pi->dpm_table_start + |
| 718 | offsetof(SMU7_Fusion_DpmTable, GraphicsLevel), |
| 719 | (u8 *)&pi->graphics_level, |
| 720 | sizeof(SMU7_Fusion_GraphicsLevel) * SMU7_MAX_LEVELS_GRAPHICS, |
| 721 | pi->sram_end); |
| 722 | |
| 723 | if (ret) |
| 724 | return ret; |
| 725 | |
| 726 | ret = kv_copy_bytes_to_smc(rdev, |
| 727 | pi->dpm_table_start + |
| 728 | offsetof(SMU7_Fusion_DpmTable, GraphicsDpmLevelCount), |
| 729 | &pi->graphics_dpm_level_count, |
| 730 | sizeof(u8), pi->sram_end); |
| 731 | |
| 732 | return ret; |
| 733 | } |
| 734 | |
| 735 | static u32 kv_get_clock_difference(u32 a, u32 b) |
| 736 | { |
| 737 | return (a >= b) ? a - b : b - a; |
| 738 | } |
| 739 | |
| 740 | static u32 kv_get_clk_bypass(struct radeon_device *rdev, u32 clk) |
| 741 | { |
| 742 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 743 | u32 value; |
| 744 | |
| 745 | if (pi->caps_enable_dfs_bypass) { |
| 746 | if (kv_get_clock_difference(clk, 40000) < 200) |
| 747 | value = 3; |
| 748 | else if (kv_get_clock_difference(clk, 30000) < 200) |
| 749 | value = 2; |
| 750 | else if (kv_get_clock_difference(clk, 20000) < 200) |
| 751 | value = 7; |
| 752 | else if (kv_get_clock_difference(clk, 15000) < 200) |
| 753 | value = 6; |
| 754 | else if (kv_get_clock_difference(clk, 10000) < 200) |
| 755 | value = 8; |
| 756 | else |
| 757 | value = 0; |
| 758 | } else { |
| 759 | value = 0; |
| 760 | } |
| 761 | |
| 762 | return value; |
| 763 | } |
| 764 | |
| 765 | static int kv_populate_uvd_table(struct radeon_device *rdev) |
| 766 | { |
| 767 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 768 | struct radeon_uvd_clock_voltage_dependency_table *table = |
| 769 | &rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table; |
| 770 | struct atom_clock_dividers dividers; |
| 771 | int ret; |
| 772 | u32 i; |
| 773 | |
| 774 | if (table == NULL || table->count == 0) |
| 775 | return 0; |
| 776 | |
| 777 | pi->uvd_level_count = 0; |
| 778 | for (i = 0; i < table->count; i++) { |
| 779 | if (pi->high_voltage_t && |
| 780 | (pi->high_voltage_t < table->entries[i].v)) |
| 781 | break; |
| 782 | |
| 783 | pi->uvd_level[i].VclkFrequency = cpu_to_be32(table->entries[i].vclk); |
| 784 | pi->uvd_level[i].DclkFrequency = cpu_to_be32(table->entries[i].dclk); |
| 785 | pi->uvd_level[i].MinVddNb = cpu_to_be16(table->entries[i].v); |
| 786 | |
| 787 | pi->uvd_level[i].VClkBypassCntl = |
| 788 | (u8)kv_get_clk_bypass(rdev, table->entries[i].vclk); |
| 789 | pi->uvd_level[i].DClkBypassCntl = |
| 790 | (u8)kv_get_clk_bypass(rdev, table->entries[i].dclk); |
| 791 | |
| 792 | ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM, |
| 793 | table->entries[i].vclk, false, ÷rs); |
| 794 | if (ret) |
| 795 | return ret; |
| 796 | pi->uvd_level[i].VclkDivider = (u8)dividers.post_div; |
| 797 | |
| 798 | ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM, |
| 799 | table->entries[i].dclk, false, ÷rs); |
| 800 | if (ret) |
| 801 | return ret; |
| 802 | pi->uvd_level[i].DclkDivider = (u8)dividers.post_div; |
| 803 | |
| 804 | pi->uvd_level_count++; |
| 805 | } |
| 806 | |
| 807 | ret = kv_copy_bytes_to_smc(rdev, |
| 808 | pi->dpm_table_start + |
| 809 | offsetof(SMU7_Fusion_DpmTable, UvdLevelCount), |
| 810 | (u8 *)&pi->uvd_level_count, |
| 811 | sizeof(u8), pi->sram_end); |
| 812 | if (ret) |
| 813 | return ret; |
| 814 | |
| 815 | pi->uvd_interval = 1; |
| 816 | |
| 817 | ret = kv_copy_bytes_to_smc(rdev, |
| 818 | pi->dpm_table_start + |
| 819 | offsetof(SMU7_Fusion_DpmTable, UVDInterval), |
| 820 | &pi->uvd_interval, |
| 821 | sizeof(u8), pi->sram_end); |
| 822 | if (ret) |
| 823 | return ret; |
| 824 | |
| 825 | ret = kv_copy_bytes_to_smc(rdev, |
| 826 | pi->dpm_table_start + |
| 827 | offsetof(SMU7_Fusion_DpmTable, UvdLevel), |
| 828 | (u8 *)&pi->uvd_level, |
| 829 | sizeof(SMU7_Fusion_UvdLevel) * SMU7_MAX_LEVELS_UVD, |
| 830 | pi->sram_end); |
| 831 | |
| 832 | return ret; |
| 833 | |
| 834 | } |
| 835 | |
| 836 | static int kv_populate_vce_table(struct radeon_device *rdev) |
| 837 | { |
| 838 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 839 | int ret; |
| 840 | u32 i; |
| 841 | struct radeon_vce_clock_voltage_dependency_table *table = |
| 842 | &rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table; |
| 843 | struct atom_clock_dividers dividers; |
| 844 | |
| 845 | if (table == NULL || table->count == 0) |
| 846 | return 0; |
| 847 | |
| 848 | pi->vce_level_count = 0; |
| 849 | for (i = 0; i < table->count; i++) { |
| 850 | if (pi->high_voltage_t && |
| 851 | pi->high_voltage_t < table->entries[i].v) |
| 852 | break; |
| 853 | |
| 854 | pi->vce_level[i].Frequency = cpu_to_be32(table->entries[i].evclk); |
| 855 | pi->vce_level[i].MinVoltage = cpu_to_be16(table->entries[i].v); |
| 856 | |
| 857 | pi->vce_level[i].ClkBypassCntl = |
| 858 | (u8)kv_get_clk_bypass(rdev, table->entries[i].evclk); |
| 859 | |
| 860 | ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM, |
| 861 | table->entries[i].evclk, false, ÷rs); |
| 862 | if (ret) |
| 863 | return ret; |
| 864 | pi->vce_level[i].Divider = (u8)dividers.post_div; |
| 865 | |
| 866 | pi->vce_level_count++; |
| 867 | } |
| 868 | |
| 869 | ret = kv_copy_bytes_to_smc(rdev, |
| 870 | pi->dpm_table_start + |
| 871 | offsetof(SMU7_Fusion_DpmTable, VceLevelCount), |
| 872 | (u8 *)&pi->vce_level_count, |
| 873 | sizeof(u8), |
| 874 | pi->sram_end); |
| 875 | if (ret) |
| 876 | return ret; |
| 877 | |
| 878 | pi->vce_interval = 1; |
| 879 | |
| 880 | ret = kv_copy_bytes_to_smc(rdev, |
| 881 | pi->dpm_table_start + |
| 882 | offsetof(SMU7_Fusion_DpmTable, VCEInterval), |
| 883 | (u8 *)&pi->vce_interval, |
| 884 | sizeof(u8), |
| 885 | pi->sram_end); |
| 886 | if (ret) |
| 887 | return ret; |
| 888 | |
| 889 | ret = kv_copy_bytes_to_smc(rdev, |
| 890 | pi->dpm_table_start + |
| 891 | offsetof(SMU7_Fusion_DpmTable, VceLevel), |
| 892 | (u8 *)&pi->vce_level, |
| 893 | sizeof(SMU7_Fusion_ExtClkLevel) * SMU7_MAX_LEVELS_VCE, |
| 894 | pi->sram_end); |
| 895 | |
| 896 | return ret; |
| 897 | } |
| 898 | |
| 899 | static int kv_populate_samu_table(struct radeon_device *rdev) |
| 900 | { |
| 901 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 902 | struct radeon_clock_voltage_dependency_table *table = |
| 903 | &rdev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table; |
| 904 | struct atom_clock_dividers dividers; |
| 905 | int ret; |
| 906 | u32 i; |
| 907 | |
| 908 | if (table == NULL || table->count == 0) |
| 909 | return 0; |
| 910 | |
| 911 | pi->samu_level_count = 0; |
| 912 | for (i = 0; i < table->count; i++) { |
| 913 | if (pi->high_voltage_t && |
| 914 | pi->high_voltage_t < table->entries[i].v) |
| 915 | break; |
| 916 | |
| 917 | pi->samu_level[i].Frequency = cpu_to_be32(table->entries[i].clk); |
| 918 | pi->samu_level[i].MinVoltage = cpu_to_be16(table->entries[i].v); |
| 919 | |
| 920 | pi->samu_level[i].ClkBypassCntl = |
| 921 | (u8)kv_get_clk_bypass(rdev, table->entries[i].clk); |
| 922 | |
| 923 | ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM, |
| 924 | table->entries[i].clk, false, ÷rs); |
| 925 | if (ret) |
| 926 | return ret; |
| 927 | pi->samu_level[i].Divider = (u8)dividers.post_div; |
| 928 | |
| 929 | pi->samu_level_count++; |
| 930 | } |
| 931 | |
| 932 | ret = kv_copy_bytes_to_smc(rdev, |
| 933 | pi->dpm_table_start + |
| 934 | offsetof(SMU7_Fusion_DpmTable, SamuLevelCount), |
| 935 | (u8 *)&pi->samu_level_count, |
| 936 | sizeof(u8), |
| 937 | pi->sram_end); |
| 938 | if (ret) |
| 939 | return ret; |
| 940 | |
| 941 | pi->samu_interval = 1; |
| 942 | |
| 943 | ret = kv_copy_bytes_to_smc(rdev, |
| 944 | pi->dpm_table_start + |
| 945 | offsetof(SMU7_Fusion_DpmTable, SAMUInterval), |
| 946 | (u8 *)&pi->samu_interval, |
| 947 | sizeof(u8), |
| 948 | pi->sram_end); |
| 949 | if (ret) |
| 950 | return ret; |
| 951 | |
| 952 | ret = kv_copy_bytes_to_smc(rdev, |
| 953 | pi->dpm_table_start + |
| 954 | offsetof(SMU7_Fusion_DpmTable, SamuLevel), |
| 955 | (u8 *)&pi->samu_level, |
| 956 | sizeof(SMU7_Fusion_ExtClkLevel) * SMU7_MAX_LEVELS_SAMU, |
| 957 | pi->sram_end); |
| 958 | if (ret) |
| 959 | return ret; |
| 960 | |
| 961 | return ret; |
| 962 | } |
| 963 | |
| 964 | |
| 965 | static int kv_populate_acp_table(struct radeon_device *rdev) |
| 966 | { |
| 967 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 968 | struct radeon_clock_voltage_dependency_table *table = |
| 969 | &rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table; |
| 970 | struct atom_clock_dividers dividers; |
| 971 | int ret; |
| 972 | u32 i; |
| 973 | |
| 974 | if (table == NULL || table->count == 0) |
| 975 | return 0; |
| 976 | |
| 977 | pi->acp_level_count = 0; |
| 978 | for (i = 0; i < table->count; i++) { |
| 979 | pi->acp_level[i].Frequency = cpu_to_be32(table->entries[i].clk); |
| 980 | pi->acp_level[i].MinVoltage = cpu_to_be16(table->entries[i].v); |
| 981 | |
| 982 | ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM, |
| 983 | table->entries[i].clk, false, ÷rs); |
| 984 | if (ret) |
| 985 | return ret; |
| 986 | pi->acp_level[i].Divider = (u8)dividers.post_div; |
| 987 | |
| 988 | pi->acp_level_count++; |
| 989 | } |
| 990 | |
| 991 | ret = kv_copy_bytes_to_smc(rdev, |
| 992 | pi->dpm_table_start + |
| 993 | offsetof(SMU7_Fusion_DpmTable, AcpLevelCount), |
| 994 | (u8 *)&pi->acp_level_count, |
| 995 | sizeof(u8), |
| 996 | pi->sram_end); |
| 997 | if (ret) |
| 998 | return ret; |
| 999 | |
| 1000 | pi->acp_interval = 1; |
| 1001 | |
| 1002 | ret = kv_copy_bytes_to_smc(rdev, |
| 1003 | pi->dpm_table_start + |
| 1004 | offsetof(SMU7_Fusion_DpmTable, ACPInterval), |
| 1005 | (u8 *)&pi->acp_interval, |
| 1006 | sizeof(u8), |
| 1007 | pi->sram_end); |
| 1008 | if (ret) |
| 1009 | return ret; |
| 1010 | |
| 1011 | ret = kv_copy_bytes_to_smc(rdev, |
| 1012 | pi->dpm_table_start + |
| 1013 | offsetof(SMU7_Fusion_DpmTable, AcpLevel), |
| 1014 | (u8 *)&pi->acp_level, |
| 1015 | sizeof(SMU7_Fusion_ExtClkLevel) * SMU7_MAX_LEVELS_ACP, |
| 1016 | pi->sram_end); |
| 1017 | if (ret) |
| 1018 | return ret; |
| 1019 | |
| 1020 | return ret; |
| 1021 | } |
| 1022 | |
| 1023 | static void kv_calculate_dfs_bypass_settings(struct radeon_device *rdev) |
| 1024 | { |
| 1025 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1026 | u32 i; |
| 1027 | struct radeon_clock_voltage_dependency_table *table = |
| 1028 | &rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk; |
| 1029 | |
| 1030 | if (table && table->count) { |
| 1031 | for (i = 0; i < pi->graphics_dpm_level_count; i++) { |
| 1032 | if (pi->caps_enable_dfs_bypass) { |
| 1033 | if (kv_get_clock_difference(table->entries[i].clk, 40000) < 200) |
| 1034 | pi->graphics_level[i].ClkBypassCntl = 3; |
| 1035 | else if (kv_get_clock_difference(table->entries[i].clk, 30000) < 200) |
| 1036 | pi->graphics_level[i].ClkBypassCntl = 2; |
| 1037 | else if (kv_get_clock_difference(table->entries[i].clk, 26600) < 200) |
| 1038 | pi->graphics_level[i].ClkBypassCntl = 7; |
| 1039 | else if (kv_get_clock_difference(table->entries[i].clk , 20000) < 200) |
| 1040 | pi->graphics_level[i].ClkBypassCntl = 6; |
| 1041 | else if (kv_get_clock_difference(table->entries[i].clk , 10000) < 200) |
| 1042 | pi->graphics_level[i].ClkBypassCntl = 8; |
| 1043 | else |
| 1044 | pi->graphics_level[i].ClkBypassCntl = 0; |
| 1045 | } else { |
| 1046 | pi->graphics_level[i].ClkBypassCntl = 0; |
| 1047 | } |
| 1048 | } |
| 1049 | } else { |
| 1050 | struct sumo_sclk_voltage_mapping_table *table = |
| 1051 | &pi->sys_info.sclk_voltage_mapping_table; |
| 1052 | for (i = 0; i < pi->graphics_dpm_level_count; i++) { |
| 1053 | if (pi->caps_enable_dfs_bypass) { |
| 1054 | if (kv_get_clock_difference(table->entries[i].sclk_frequency, 40000) < 200) |
| 1055 | pi->graphics_level[i].ClkBypassCntl = 3; |
| 1056 | else if (kv_get_clock_difference(table->entries[i].sclk_frequency, 30000) < 200) |
| 1057 | pi->graphics_level[i].ClkBypassCntl = 2; |
| 1058 | else if (kv_get_clock_difference(table->entries[i].sclk_frequency, 26600) < 200) |
| 1059 | pi->graphics_level[i].ClkBypassCntl = 7; |
| 1060 | else if (kv_get_clock_difference(table->entries[i].sclk_frequency, 20000) < 200) |
| 1061 | pi->graphics_level[i].ClkBypassCntl = 6; |
| 1062 | else if (kv_get_clock_difference(table->entries[i].sclk_frequency, 10000) < 200) |
| 1063 | pi->graphics_level[i].ClkBypassCntl = 8; |
| 1064 | else |
| 1065 | pi->graphics_level[i].ClkBypassCntl = 0; |
| 1066 | } else { |
| 1067 | pi->graphics_level[i].ClkBypassCntl = 0; |
| 1068 | } |
| 1069 | } |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | static int kv_enable_ulv(struct radeon_device *rdev, bool enable) |
| 1074 | { |
| 1075 | return kv_notify_message_to_smu(rdev, enable ? |
| 1076 | PPSMC_MSG_EnableULV : PPSMC_MSG_DisableULV); |
| 1077 | } |
| 1078 | |
| 1079 | static void kv_update_current_ps(struct radeon_device *rdev, |
| 1080 | struct radeon_ps *rps) |
| 1081 | { |
| 1082 | struct kv_ps *new_ps = kv_get_ps(rps); |
| 1083 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1084 | |
| 1085 | pi->current_rps = *rps; |
| 1086 | pi->current_ps = *new_ps; |
| 1087 | pi->current_rps.ps_priv = &pi->current_ps; |
| 1088 | } |
| 1089 | |
| 1090 | static void kv_update_requested_ps(struct radeon_device *rdev, |
| 1091 | struct radeon_ps *rps) |
| 1092 | { |
| 1093 | struct kv_ps *new_ps = kv_get_ps(rps); |
| 1094 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1095 | |
| 1096 | pi->requested_rps = *rps; |
| 1097 | pi->requested_ps = *new_ps; |
| 1098 | pi->requested_rps.ps_priv = &pi->requested_ps; |
| 1099 | } |
| 1100 | |
| 1101 | int kv_dpm_enable(struct radeon_device *rdev) |
| 1102 | { |
| 1103 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1104 | int ret; |
| 1105 | |
| 1106 | ret = kv_process_firmware_header(rdev); |
| 1107 | if (ret) { |
| 1108 | DRM_ERROR("kv_process_firmware_header failed\n"); |
| 1109 | return ret; |
| 1110 | } |
| 1111 | kv_init_fps_limits(rdev); |
| 1112 | kv_init_graphics_levels(rdev); |
| 1113 | ret = kv_program_bootup_state(rdev); |
| 1114 | if (ret) { |
| 1115 | DRM_ERROR("kv_program_bootup_state failed\n"); |
| 1116 | return ret; |
| 1117 | } |
| 1118 | kv_calculate_dfs_bypass_settings(rdev); |
| 1119 | ret = kv_upload_dpm_settings(rdev); |
| 1120 | if (ret) { |
| 1121 | DRM_ERROR("kv_upload_dpm_settings failed\n"); |
| 1122 | return ret; |
| 1123 | } |
| 1124 | ret = kv_populate_uvd_table(rdev); |
| 1125 | if (ret) { |
| 1126 | DRM_ERROR("kv_populate_uvd_table failed\n"); |
| 1127 | return ret; |
| 1128 | } |
| 1129 | ret = kv_populate_vce_table(rdev); |
| 1130 | if (ret) { |
| 1131 | DRM_ERROR("kv_populate_vce_table failed\n"); |
| 1132 | return ret; |
| 1133 | } |
| 1134 | ret = kv_populate_samu_table(rdev); |
| 1135 | if (ret) { |
| 1136 | DRM_ERROR("kv_populate_samu_table failed\n"); |
| 1137 | return ret; |
| 1138 | } |
| 1139 | ret = kv_populate_acp_table(rdev); |
| 1140 | if (ret) { |
| 1141 | DRM_ERROR("kv_populate_acp_table failed\n"); |
| 1142 | return ret; |
| 1143 | } |
| 1144 | kv_program_vc(rdev); |
| 1145 | #if 0 |
| 1146 | kv_initialize_hardware_cac_manager(rdev); |
| 1147 | #endif |
| 1148 | kv_start_am(rdev); |
| 1149 | if (pi->enable_auto_thermal_throttling) { |
| 1150 | ret = kv_enable_auto_thermal_throttling(rdev); |
| 1151 | if (ret) { |
| 1152 | DRM_ERROR("kv_enable_auto_thermal_throttling failed\n"); |
| 1153 | return ret; |
| 1154 | } |
| 1155 | } |
| 1156 | ret = kv_enable_dpm_voltage_scaling(rdev); |
| 1157 | if (ret) { |
| 1158 | DRM_ERROR("kv_enable_dpm_voltage_scaling failed\n"); |
| 1159 | return ret; |
| 1160 | } |
| 1161 | ret = kv_set_dpm_interval(rdev); |
| 1162 | if (ret) { |
| 1163 | DRM_ERROR("kv_set_dpm_interval failed\n"); |
| 1164 | return ret; |
| 1165 | } |
| 1166 | ret = kv_set_dpm_boot_state(rdev); |
| 1167 | if (ret) { |
| 1168 | DRM_ERROR("kv_set_dpm_boot_state failed\n"); |
| 1169 | return ret; |
| 1170 | } |
| 1171 | ret = kv_enable_ulv(rdev, true); |
| 1172 | if (ret) { |
| 1173 | DRM_ERROR("kv_enable_ulv failed\n"); |
| 1174 | return ret; |
| 1175 | } |
| 1176 | kv_start_dpm(rdev); |
| 1177 | ret = kv_enable_didt(rdev, true); |
| 1178 | if (ret) { |
| 1179 | DRM_ERROR("kv_enable_didt failed\n"); |
| 1180 | return ret; |
| 1181 | } |
| 1182 | ret = kv_enable_smc_cac(rdev, true); |
| 1183 | if (ret) { |
| 1184 | DRM_ERROR("kv_enable_smc_cac failed\n"); |
| 1185 | return ret; |
| 1186 | } |
| 1187 | |
| 1188 | if (rdev->irq.installed && |
| 1189 | r600_is_internal_thermal_sensor(rdev->pm.int_thermal_type)) { |
| 1190 | ret = kv_set_thermal_temperature_range(rdev, R600_TEMP_RANGE_MIN, R600_TEMP_RANGE_MAX); |
| 1191 | if (ret) { |
| 1192 | DRM_ERROR("kv_set_thermal_temperature_range failed\n"); |
| 1193 | return ret; |
| 1194 | } |
| 1195 | rdev->irq.dpm_thermal = true; |
| 1196 | radeon_irq_set(rdev); |
| 1197 | } |
| 1198 | |
| 1199 | /* powerdown unused blocks for now */ |
| 1200 | kv_dpm_powergate_acp(rdev, true); |
| 1201 | kv_dpm_powergate_samu(rdev, true); |
| 1202 | kv_dpm_powergate_vce(rdev, true); |
| 1203 | |
| 1204 | kv_update_current_ps(rdev, rdev->pm.dpm.boot_ps); |
| 1205 | |
| 1206 | return ret; |
| 1207 | } |
| 1208 | |
| 1209 | void kv_dpm_disable(struct radeon_device *rdev) |
| 1210 | { |
| 1211 | kv_enable_smc_cac(rdev, false); |
| 1212 | kv_enable_didt(rdev, false); |
| 1213 | kv_clear_vc(rdev); |
| 1214 | kv_stop_dpm(rdev); |
| 1215 | kv_enable_ulv(rdev, false); |
| 1216 | kv_reset_am(rdev); |
| 1217 | |
| 1218 | kv_update_current_ps(rdev, rdev->pm.dpm.boot_ps); |
| 1219 | } |
| 1220 | |
| 1221 | #if 0 |
| 1222 | static int kv_write_smc_soft_register(struct radeon_device *rdev, |
| 1223 | u16 reg_offset, u32 value) |
| 1224 | { |
| 1225 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1226 | |
| 1227 | return kv_copy_bytes_to_smc(rdev, pi->soft_regs_start + reg_offset, |
| 1228 | (u8 *)&value, sizeof(u16), pi->sram_end); |
| 1229 | } |
| 1230 | |
| 1231 | static int kv_read_smc_soft_register(struct radeon_device *rdev, |
| 1232 | u16 reg_offset, u32 *value) |
| 1233 | { |
| 1234 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1235 | |
| 1236 | return kv_read_smc_sram_dword(rdev, pi->soft_regs_start + reg_offset, |
| 1237 | value, pi->sram_end); |
| 1238 | } |
| 1239 | #endif |
| 1240 | |
| 1241 | static void kv_init_sclk_t(struct radeon_device *rdev) |
| 1242 | { |
| 1243 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1244 | |
| 1245 | pi->low_sclk_interrupt_t = 0; |
| 1246 | } |
| 1247 | |
| 1248 | static int kv_init_fps_limits(struct radeon_device *rdev) |
| 1249 | { |
| 1250 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1251 | int ret = 0; |
| 1252 | |
| 1253 | if (pi->caps_fps) { |
| 1254 | u16 tmp; |
| 1255 | |
| 1256 | tmp = 45; |
| 1257 | pi->fps_high_t = cpu_to_be16(tmp); |
| 1258 | ret = kv_copy_bytes_to_smc(rdev, |
| 1259 | pi->dpm_table_start + |
| 1260 | offsetof(SMU7_Fusion_DpmTable, FpsHighT), |
| 1261 | (u8 *)&pi->fps_high_t, |
| 1262 | sizeof(u16), pi->sram_end); |
| 1263 | |
| 1264 | tmp = 30; |
| 1265 | pi->fps_low_t = cpu_to_be16(tmp); |
| 1266 | |
| 1267 | ret = kv_copy_bytes_to_smc(rdev, |
| 1268 | pi->dpm_table_start + |
| 1269 | offsetof(SMU7_Fusion_DpmTable, FpsLowT), |
| 1270 | (u8 *)&pi->fps_low_t, |
| 1271 | sizeof(u16), pi->sram_end); |
| 1272 | |
| 1273 | } |
| 1274 | return ret; |
| 1275 | } |
| 1276 | |
| 1277 | static void kv_init_powergate_state(struct radeon_device *rdev) |
| 1278 | { |
| 1279 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1280 | |
| 1281 | pi->uvd_power_gated = false; |
| 1282 | pi->vce_power_gated = false; |
| 1283 | pi->samu_power_gated = false; |
| 1284 | pi->acp_power_gated = false; |
| 1285 | |
| 1286 | } |
| 1287 | |
| 1288 | static int kv_enable_uvd_dpm(struct radeon_device *rdev, bool enable) |
| 1289 | { |
| 1290 | return kv_notify_message_to_smu(rdev, enable ? |
| 1291 | PPSMC_MSG_UVDDPM_Enable : PPSMC_MSG_UVDDPM_Disable); |
| 1292 | } |
| 1293 | |
| 1294 | #if 0 |
| 1295 | static int kv_enable_vce_dpm(struct radeon_device *rdev, bool enable) |
| 1296 | { |
| 1297 | return kv_notify_message_to_smu(rdev, enable ? |
| 1298 | PPSMC_MSG_VCEDPM_Enable : PPSMC_MSG_VCEDPM_Disable); |
| 1299 | } |
| 1300 | #endif |
| 1301 | |
| 1302 | static int kv_enable_samu_dpm(struct radeon_device *rdev, bool enable) |
| 1303 | { |
| 1304 | return kv_notify_message_to_smu(rdev, enable ? |
| 1305 | PPSMC_MSG_SAMUDPM_Enable : PPSMC_MSG_SAMUDPM_Disable); |
| 1306 | } |
| 1307 | |
| 1308 | static int kv_enable_acp_dpm(struct radeon_device *rdev, bool enable) |
| 1309 | { |
| 1310 | return kv_notify_message_to_smu(rdev, enable ? |
| 1311 | PPSMC_MSG_ACPDPM_Enable : PPSMC_MSG_ACPDPM_Disable); |
| 1312 | } |
| 1313 | |
| 1314 | static int kv_update_uvd_dpm(struct radeon_device *rdev, bool gate) |
| 1315 | { |
| 1316 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1317 | struct radeon_uvd_clock_voltage_dependency_table *table = |
| 1318 | &rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table; |
| 1319 | int ret; |
| 1320 | |
| 1321 | if (!gate) { |
| 1322 | if (!pi->caps_uvd_dpm || table->count || pi->caps_stable_p_state) |
| 1323 | pi->uvd_boot_level = table->count - 1; |
| 1324 | else |
| 1325 | pi->uvd_boot_level = 0; |
| 1326 | |
| 1327 | ret = kv_copy_bytes_to_smc(rdev, |
| 1328 | pi->dpm_table_start + |
| 1329 | offsetof(SMU7_Fusion_DpmTable, UvdBootLevel), |
| 1330 | (uint8_t *)&pi->uvd_boot_level, |
| 1331 | sizeof(u8), pi->sram_end); |
| 1332 | if (ret) |
| 1333 | return ret; |
| 1334 | |
| 1335 | if (!pi->caps_uvd_dpm || |
| 1336 | pi->caps_stable_p_state) |
| 1337 | kv_send_msg_to_smc_with_parameter(rdev, |
| 1338 | PPSMC_MSG_UVDDPM_SetEnabledMask, |
| 1339 | (1 << pi->uvd_boot_level)); |
| 1340 | } |
| 1341 | |
| 1342 | return kv_enable_uvd_dpm(rdev, !gate); |
| 1343 | } |
| 1344 | |
| 1345 | #if 0 |
| 1346 | static u8 kv_get_vce_boot_level(struct radeon_device *rdev) |
| 1347 | { |
| 1348 | u8 i; |
| 1349 | struct radeon_vce_clock_voltage_dependency_table *table = |
| 1350 | &rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table; |
| 1351 | |
| 1352 | for (i = 0; i < table->count; i++) { |
| 1353 | if (table->entries[i].evclk >= 0) /* XXX */ |
| 1354 | break; |
| 1355 | } |
| 1356 | |
| 1357 | return i; |
| 1358 | } |
| 1359 | |
| 1360 | static int kv_update_vce_dpm(struct radeon_device *rdev, |
| 1361 | struct radeon_ps *radeon_new_state, |
| 1362 | struct radeon_ps *radeon_current_state) |
| 1363 | { |
| 1364 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1365 | struct radeon_vce_clock_voltage_dependency_table *table = |
| 1366 | &rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table; |
| 1367 | int ret; |
| 1368 | |
| 1369 | if (radeon_new_state->evclk > 0 && radeon_current_state->evclk == 0) { |
| 1370 | if (pi->caps_stable_p_state) |
| 1371 | pi->vce_boot_level = table->count - 1; |
| 1372 | else |
| 1373 | pi->vce_boot_level = kv_get_vce_boot_level(rdev); |
| 1374 | |
| 1375 | ret = kv_copy_bytes_to_smc(rdev, |
| 1376 | pi->dpm_table_start + |
| 1377 | offsetof(SMU7_Fusion_DpmTable, VceBootLevel), |
| 1378 | (u8 *)&pi->vce_boot_level, |
| 1379 | sizeof(u8), |
| 1380 | pi->sram_end); |
| 1381 | if (ret) |
| 1382 | return ret; |
| 1383 | |
| 1384 | if (pi->caps_stable_p_state) |
| 1385 | kv_send_msg_to_smc_with_parameter(rdev, |
| 1386 | PPSMC_MSG_VCEDPM_SetEnabledMask, |
| 1387 | (1 << pi->vce_boot_level)); |
| 1388 | |
| 1389 | kv_enable_vce_dpm(rdev, true); |
| 1390 | } else if (radeon_new_state->evclk == 0 && radeon_current_state->evclk > 0) { |
| 1391 | kv_enable_vce_dpm(rdev, false); |
| 1392 | } |
| 1393 | |
| 1394 | return 0; |
| 1395 | } |
| 1396 | #endif |
| 1397 | |
| 1398 | static int kv_update_samu_dpm(struct radeon_device *rdev, bool gate) |
| 1399 | { |
| 1400 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1401 | struct radeon_clock_voltage_dependency_table *table = |
| 1402 | &rdev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table; |
| 1403 | int ret; |
| 1404 | |
| 1405 | if (!gate) { |
| 1406 | if (pi->caps_stable_p_state) |
| 1407 | pi->samu_boot_level = table->count - 1; |
| 1408 | else |
| 1409 | pi->samu_boot_level = 0; |
| 1410 | |
| 1411 | ret = kv_copy_bytes_to_smc(rdev, |
| 1412 | pi->dpm_table_start + |
| 1413 | offsetof(SMU7_Fusion_DpmTable, SamuBootLevel), |
| 1414 | (u8 *)&pi->samu_boot_level, |
| 1415 | sizeof(u8), |
| 1416 | pi->sram_end); |
| 1417 | if (ret) |
| 1418 | return ret; |
| 1419 | |
| 1420 | if (pi->caps_stable_p_state) |
| 1421 | kv_send_msg_to_smc_with_parameter(rdev, |
| 1422 | PPSMC_MSG_SAMUDPM_SetEnabledMask, |
| 1423 | (1 << pi->samu_boot_level)); |
| 1424 | } |
| 1425 | |
| 1426 | return kv_enable_samu_dpm(rdev, !gate); |
| 1427 | } |
| 1428 | |
| 1429 | static int kv_update_acp_dpm(struct radeon_device *rdev, bool gate) |
| 1430 | { |
| 1431 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1432 | struct radeon_clock_voltage_dependency_table *table = |
| 1433 | &rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table; |
| 1434 | int ret; |
| 1435 | |
| 1436 | if (!gate) { |
| 1437 | if (pi->caps_stable_p_state) |
| 1438 | pi->acp_boot_level = table->count - 1; |
| 1439 | else |
| 1440 | pi->acp_boot_level = 0; |
| 1441 | |
| 1442 | ret = kv_copy_bytes_to_smc(rdev, |
| 1443 | pi->dpm_table_start + |
| 1444 | offsetof(SMU7_Fusion_DpmTable, AcpBootLevel), |
| 1445 | (u8 *)&pi->acp_boot_level, |
| 1446 | sizeof(u8), |
| 1447 | pi->sram_end); |
| 1448 | if (ret) |
| 1449 | return ret; |
| 1450 | |
| 1451 | if (pi->caps_stable_p_state) |
| 1452 | kv_send_msg_to_smc_with_parameter(rdev, |
| 1453 | PPSMC_MSG_ACPDPM_SetEnabledMask, |
| 1454 | (1 << pi->acp_boot_level)); |
| 1455 | } |
| 1456 | |
| 1457 | return kv_enable_acp_dpm(rdev, !gate); |
| 1458 | } |
| 1459 | |
| 1460 | static void kv_dpm_powergate_uvd(struct radeon_device *rdev, bool gate) |
| 1461 | { |
| 1462 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1463 | |
| 1464 | if (pi->uvd_power_gated == gate) |
| 1465 | return; |
| 1466 | |
| 1467 | pi->uvd_power_gated = gate; |
| 1468 | |
| 1469 | if (gate) { |
| 1470 | kv_update_uvd_dpm(rdev, true); |
| 1471 | if (pi->caps_uvd_pg) |
| 1472 | kv_notify_message_to_smu(rdev, PPSMC_MSG_UVDPowerOFF); |
| 1473 | } else { |
| 1474 | if (pi->caps_uvd_pg) |
| 1475 | kv_notify_message_to_smu(rdev, PPSMC_MSG_UVDPowerON); |
| 1476 | kv_update_uvd_dpm(rdev, false); |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | static void kv_dpm_powergate_vce(struct radeon_device *rdev, bool gate) |
| 1481 | { |
| 1482 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1483 | |
| 1484 | if (pi->vce_power_gated == gate) |
| 1485 | return; |
| 1486 | |
| 1487 | pi->vce_power_gated = gate; |
| 1488 | |
| 1489 | if (gate) { |
| 1490 | if (pi->caps_vce_pg) |
| 1491 | kv_notify_message_to_smu(rdev, PPSMC_MSG_VCEPowerOFF); |
| 1492 | } else { |
| 1493 | if (pi->caps_vce_pg) |
| 1494 | kv_notify_message_to_smu(rdev, PPSMC_MSG_VCEPowerON); |
| 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | static void kv_dpm_powergate_samu(struct radeon_device *rdev, bool gate) |
| 1499 | { |
| 1500 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1501 | |
| 1502 | if (pi->samu_power_gated == gate) |
| 1503 | return; |
| 1504 | |
| 1505 | pi->samu_power_gated = gate; |
| 1506 | |
| 1507 | if (gate) { |
| 1508 | kv_update_samu_dpm(rdev, true); |
| 1509 | if (pi->caps_samu_pg) |
| 1510 | kv_notify_message_to_smu(rdev, PPSMC_MSG_SAMPowerOFF); |
| 1511 | } else { |
| 1512 | if (pi->caps_samu_pg) |
| 1513 | kv_notify_message_to_smu(rdev, PPSMC_MSG_SAMPowerON); |
| 1514 | kv_update_samu_dpm(rdev, false); |
| 1515 | } |
| 1516 | } |
| 1517 | |
| 1518 | static void kv_dpm_powergate_acp(struct radeon_device *rdev, bool gate) |
| 1519 | { |
| 1520 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1521 | |
| 1522 | if (pi->acp_power_gated == gate) |
| 1523 | return; |
| 1524 | |
| 1525 | if (rdev->family == CHIP_KABINI) |
| 1526 | return; |
| 1527 | |
| 1528 | pi->acp_power_gated = gate; |
| 1529 | |
| 1530 | if (gate) { |
| 1531 | kv_update_acp_dpm(rdev, true); |
| 1532 | if (pi->caps_acp_pg) |
| 1533 | kv_notify_message_to_smu(rdev, PPSMC_MSG_ACPPowerOFF); |
| 1534 | } else { |
| 1535 | if (pi->caps_acp_pg) |
| 1536 | kv_notify_message_to_smu(rdev, PPSMC_MSG_ACPPowerON); |
| 1537 | kv_update_acp_dpm(rdev, false); |
| 1538 | } |
| 1539 | } |
| 1540 | |
| 1541 | static void kv_set_valid_clock_range(struct radeon_device *rdev, |
| 1542 | struct radeon_ps *new_rps) |
| 1543 | { |
| 1544 | struct kv_ps *new_ps = kv_get_ps(new_rps); |
| 1545 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1546 | u32 i; |
| 1547 | struct radeon_clock_voltage_dependency_table *table = |
| 1548 | &rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk; |
| 1549 | |
| 1550 | if (table && table->count) { |
| 1551 | for (i = 0; i < pi->graphics_dpm_level_count; i++) { |
| 1552 | if ((table->entries[i].clk >= new_ps->levels[0].sclk) || |
| 1553 | (i == (pi->graphics_dpm_level_count - 1))) { |
| 1554 | pi->lowest_valid = i; |
| 1555 | break; |
| 1556 | } |
| 1557 | } |
| 1558 | |
| 1559 | for (i = pi->graphics_dpm_level_count - 1; i >= 0; i--) { |
| 1560 | if ((table->entries[i].clk <= new_ps->levels[new_ps->num_levels -1].sclk) || |
| 1561 | (i == 0)) { |
| 1562 | pi->highest_valid = i; |
| 1563 | break; |
| 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | if (pi->lowest_valid > pi->highest_valid) { |
| 1568 | if ((new_ps->levels[0].sclk - table->entries[pi->highest_valid].clk) > |
| 1569 | (table->entries[pi->lowest_valid].clk - new_ps->levels[new_ps->num_levels - 1].sclk)) |
| 1570 | pi->highest_valid = pi->lowest_valid; |
| 1571 | else |
| 1572 | pi->lowest_valid = pi->highest_valid; |
| 1573 | } |
| 1574 | } else { |
| 1575 | struct sumo_sclk_voltage_mapping_table *table = |
| 1576 | &pi->sys_info.sclk_voltage_mapping_table; |
| 1577 | |
| 1578 | for (i = 0; i < (int)pi->graphics_dpm_level_count; i++) { |
| 1579 | if (table->entries[i].sclk_frequency >= new_ps->levels[0].sclk || |
| 1580 | i == (int)(pi->graphics_dpm_level_count - 1)) { |
| 1581 | pi->lowest_valid = i; |
| 1582 | break; |
| 1583 | } |
| 1584 | } |
| 1585 | |
| 1586 | for (i = pi->graphics_dpm_level_count - 1; i >= 0; i--) { |
| 1587 | if (table->entries[i].sclk_frequency <= |
| 1588 | new_ps->levels[new_ps->num_levels - 1].sclk || |
| 1589 | i == 0) { |
| 1590 | pi->highest_valid = i; |
| 1591 | break; |
| 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | if (pi->lowest_valid > pi->highest_valid) { |
| 1596 | if ((new_ps->levels[0].sclk - |
| 1597 | table->entries[pi->highest_valid].sclk_frequency) > |
| 1598 | (table->entries[pi->lowest_valid].sclk_frequency - |
| 1599 | new_ps->levels[new_ps->num_levels -1].sclk)) |
| 1600 | pi->highest_valid = pi->lowest_valid; |
| 1601 | else |
| 1602 | pi->lowest_valid = pi->highest_valid; |
| 1603 | } |
| 1604 | } |
| 1605 | } |
| 1606 | |
| 1607 | static int kv_update_dfs_bypass_settings(struct radeon_device *rdev, |
| 1608 | struct radeon_ps *new_rps) |
| 1609 | { |
| 1610 | struct kv_ps *new_ps = kv_get_ps(new_rps); |
| 1611 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1612 | int ret = 0; |
| 1613 | u8 clk_bypass_cntl; |
| 1614 | |
| 1615 | if (pi->caps_enable_dfs_bypass) { |
| 1616 | clk_bypass_cntl = new_ps->need_dfs_bypass ? |
| 1617 | pi->graphics_level[pi->graphics_boot_level].ClkBypassCntl : 0; |
| 1618 | ret = kv_copy_bytes_to_smc(rdev, |
| 1619 | (pi->dpm_table_start + |
| 1620 | offsetof(SMU7_Fusion_DpmTable, GraphicsLevel) + |
| 1621 | (pi->graphics_boot_level * sizeof(SMU7_Fusion_GraphicsLevel)) + |
| 1622 | offsetof(SMU7_Fusion_GraphicsLevel, ClkBypassCntl)), |
| 1623 | &clk_bypass_cntl, |
| 1624 | sizeof(u8), pi->sram_end); |
| 1625 | } |
| 1626 | |
| 1627 | return ret; |
| 1628 | } |
| 1629 | |
| 1630 | static int kv_enable_nb_dpm(struct radeon_device *rdev) |
| 1631 | { |
| 1632 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1633 | int ret = 0; |
| 1634 | |
| 1635 | if (pi->enable_nb_dpm && !pi->nb_dpm_enabled) { |
| 1636 | ret = kv_notify_message_to_smu(rdev, PPSMC_MSG_NBDPM_Enable); |
| 1637 | if (ret == 0) |
| 1638 | pi->nb_dpm_enabled = true; |
| 1639 | } |
| 1640 | |
| 1641 | return ret; |
| 1642 | } |
| 1643 | |
| 1644 | int kv_dpm_pre_set_power_state(struct radeon_device *rdev) |
| 1645 | { |
| 1646 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1647 | struct radeon_ps requested_ps = *rdev->pm.dpm.requested_ps; |
| 1648 | struct radeon_ps *new_ps = &requested_ps; |
| 1649 | |
| 1650 | kv_update_requested_ps(rdev, new_ps); |
| 1651 | |
| 1652 | kv_apply_state_adjust_rules(rdev, |
| 1653 | &pi->requested_rps, |
| 1654 | &pi->current_rps); |
| 1655 | |
| 1656 | return 0; |
| 1657 | } |
| 1658 | |
| 1659 | int kv_dpm_set_power_state(struct radeon_device *rdev) |
| 1660 | { |
| 1661 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1662 | struct radeon_ps *new_ps = &pi->requested_rps; |
| 1663 | /*struct radeon_ps *old_ps = &pi->current_rps;*/ |
| 1664 | int ret; |
| 1665 | |
| 1666 | if (rdev->family == CHIP_KABINI) { |
| 1667 | if (pi->enable_dpm) { |
| 1668 | kv_set_valid_clock_range(rdev, new_ps); |
| 1669 | kv_update_dfs_bypass_settings(rdev, new_ps); |
| 1670 | ret = kv_calculate_ds_divider(rdev); |
| 1671 | if (ret) { |
| 1672 | DRM_ERROR("kv_calculate_ds_divider failed\n"); |
| 1673 | return ret; |
| 1674 | } |
| 1675 | kv_calculate_nbps_level_settings(rdev); |
| 1676 | kv_calculate_dpm_settings(rdev); |
| 1677 | kv_force_lowest_valid(rdev); |
| 1678 | kv_enable_new_levels(rdev); |
| 1679 | kv_upload_dpm_settings(rdev); |
| 1680 | kv_program_nbps_index_settings(rdev, new_ps); |
| 1681 | kv_unforce_levels(rdev); |
| 1682 | kv_set_enabled_levels(rdev); |
| 1683 | kv_force_lowest_valid(rdev); |
| 1684 | kv_unforce_levels(rdev); |
| 1685 | #if 0 |
| 1686 | ret = kv_update_vce_dpm(rdev, new_ps, old_ps); |
| 1687 | if (ret) { |
| 1688 | DRM_ERROR("kv_update_vce_dpm failed\n"); |
| 1689 | return ret; |
| 1690 | } |
| 1691 | #endif |
| 1692 | kv_update_uvd_dpm(rdev, false); |
| 1693 | kv_update_sclk_t(rdev); |
| 1694 | } |
| 1695 | } else { |
| 1696 | if (pi->enable_dpm) { |
| 1697 | kv_set_valid_clock_range(rdev, new_ps); |
| 1698 | kv_update_dfs_bypass_settings(rdev, new_ps); |
| 1699 | ret = kv_calculate_ds_divider(rdev); |
| 1700 | if (ret) { |
| 1701 | DRM_ERROR("kv_calculate_ds_divider failed\n"); |
| 1702 | return ret; |
| 1703 | } |
| 1704 | kv_calculate_nbps_level_settings(rdev); |
| 1705 | kv_calculate_dpm_settings(rdev); |
| 1706 | kv_freeze_sclk_dpm(rdev, true); |
| 1707 | kv_upload_dpm_settings(rdev); |
| 1708 | kv_program_nbps_index_settings(rdev, new_ps); |
| 1709 | kv_freeze_sclk_dpm(rdev, false); |
| 1710 | kv_set_enabled_levels(rdev); |
| 1711 | #if 0 |
| 1712 | ret = kv_update_vce_dpm(rdev, new_ps, old_ps); |
| 1713 | if (ret) { |
| 1714 | DRM_ERROR("kv_update_vce_dpm failed\n"); |
| 1715 | return ret; |
| 1716 | } |
| 1717 | #endif |
| 1718 | kv_update_uvd_dpm(rdev, false); |
| 1719 | kv_update_sclk_t(rdev); |
| 1720 | kv_enable_nb_dpm(rdev); |
| 1721 | } |
| 1722 | } |
| 1723 | return 0; |
| 1724 | } |
| 1725 | |
| 1726 | void kv_dpm_post_set_power_state(struct radeon_device *rdev) |
| 1727 | { |
| 1728 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1729 | struct radeon_ps *new_ps = &pi->requested_rps; |
| 1730 | |
| 1731 | kv_update_current_ps(rdev, new_ps); |
| 1732 | } |
| 1733 | |
| 1734 | void kv_dpm_setup_asic(struct radeon_device *rdev) |
| 1735 | { |
| 1736 | sumo_take_smu_control(rdev, true); |
| 1737 | kv_init_powergate_state(rdev); |
| 1738 | kv_init_sclk_t(rdev); |
| 1739 | } |
| 1740 | |
| 1741 | void kv_dpm_reset_asic(struct radeon_device *rdev) |
| 1742 | { |
| 1743 | kv_force_lowest_valid(rdev); |
| 1744 | kv_init_graphics_levels(rdev); |
| 1745 | kv_program_bootup_state(rdev); |
| 1746 | kv_upload_dpm_settings(rdev); |
| 1747 | kv_force_lowest_valid(rdev); |
| 1748 | kv_unforce_levels(rdev); |
| 1749 | } |
| 1750 | |
| 1751 | //XXX use sumo_dpm_display_configuration_changed |
| 1752 | |
| 1753 | static void kv_construct_max_power_limits_table(struct radeon_device *rdev, |
| 1754 | struct radeon_clock_and_voltage_limits *table) |
| 1755 | { |
| 1756 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1757 | |
| 1758 | if (pi->sys_info.sclk_voltage_mapping_table.num_max_dpm_entries > 0) { |
| 1759 | int idx = pi->sys_info.sclk_voltage_mapping_table.num_max_dpm_entries - 1; |
| 1760 | table->sclk = |
| 1761 | pi->sys_info.sclk_voltage_mapping_table.entries[idx].sclk_frequency; |
| 1762 | table->vddc = |
| 1763 | kv_convert_2bit_index_to_voltage(rdev, |
| 1764 | pi->sys_info.sclk_voltage_mapping_table.entries[idx].vid_2bit); |
| 1765 | } |
| 1766 | |
| 1767 | table->mclk = pi->sys_info.nbp_memory_clock[0]; |
| 1768 | } |
| 1769 | |
| 1770 | static void kv_patch_voltage_values(struct radeon_device *rdev) |
| 1771 | { |
| 1772 | int i; |
| 1773 | struct radeon_uvd_clock_voltage_dependency_table *table = |
| 1774 | &rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table; |
| 1775 | |
| 1776 | if (table->count) { |
| 1777 | for (i = 0; i < table->count; i++) |
| 1778 | table->entries[i].v = |
| 1779 | kv_convert_8bit_index_to_voltage(rdev, |
| 1780 | table->entries[i].v); |
| 1781 | } |
| 1782 | |
| 1783 | } |
| 1784 | |
| 1785 | static void kv_construct_boot_state(struct radeon_device *rdev) |
| 1786 | { |
| 1787 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1788 | |
| 1789 | pi->boot_pl.sclk = pi->sys_info.bootup_sclk; |
| 1790 | pi->boot_pl.vddc_index = pi->sys_info.bootup_nb_voltage_index; |
| 1791 | pi->boot_pl.ds_divider_index = 0; |
| 1792 | pi->boot_pl.ss_divider_index = 0; |
| 1793 | pi->boot_pl.allow_gnb_slow = 1; |
| 1794 | pi->boot_pl.force_nbp_state = 0; |
| 1795 | pi->boot_pl.display_wm = 0; |
| 1796 | pi->boot_pl.vce_wm = 0; |
| 1797 | } |
| 1798 | |
| 1799 | static int kv_force_dpm_lowest(struct radeon_device *rdev) |
| 1800 | { |
| 1801 | int ret; |
| 1802 | u32 enable_mask, i; |
| 1803 | |
| 1804 | ret = kv_dpm_get_enable_mask(rdev, &enable_mask); |
| 1805 | if (ret) |
| 1806 | return ret; |
| 1807 | |
| 1808 | for (i = 0; i < SMU7_MAX_LEVELS_GRAPHICS; i++) { |
| 1809 | if (enable_mask & (1 << i)) |
| 1810 | break; |
| 1811 | } |
| 1812 | |
| 1813 | return kv_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_DPM_ForceState, i); |
| 1814 | } |
| 1815 | |
| 1816 | static u8 kv_get_sleep_divider_id_from_clock(struct radeon_device *rdev, |
| 1817 | u32 sclk, u32 min_sclk_in_sr) |
| 1818 | { |
| 1819 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1820 | u32 i; |
| 1821 | u32 temp; |
| 1822 | u32 min = (min_sclk_in_sr > KV_MINIMUM_ENGINE_CLOCK) ? |
| 1823 | min_sclk_in_sr : KV_MINIMUM_ENGINE_CLOCK; |
| 1824 | |
| 1825 | if (sclk < min) |
| 1826 | return 0; |
| 1827 | |
| 1828 | if (!pi->caps_sclk_ds) |
| 1829 | return 0; |
| 1830 | |
| 1831 | for (i = KV_MAX_DEEPSLEEP_DIVIDER_ID; i <= 0; i--) { |
| 1832 | temp = sclk / sumo_get_sleep_divider_from_id(i); |
| 1833 | if ((temp >= min) || (i == 0)) |
| 1834 | break; |
| 1835 | } |
| 1836 | |
| 1837 | return (u8)i; |
| 1838 | } |
| 1839 | |
| 1840 | static int kv_get_high_voltage_limit(struct radeon_device *rdev, int *limit) |
| 1841 | { |
| 1842 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1843 | struct radeon_clock_voltage_dependency_table *table = |
| 1844 | &rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk; |
| 1845 | int i; |
| 1846 | |
| 1847 | if (table && table->count) { |
| 1848 | for (i = table->count - 1; i >= 0; i--) { |
| 1849 | if (pi->high_voltage_t && |
| 1850 | (kv_convert_8bit_index_to_voltage(rdev, table->entries[i].v) <= |
| 1851 | pi->high_voltage_t)) { |
| 1852 | *limit = i; |
| 1853 | return 0; |
| 1854 | } |
| 1855 | } |
| 1856 | } else { |
| 1857 | struct sumo_sclk_voltage_mapping_table *table = |
| 1858 | &pi->sys_info.sclk_voltage_mapping_table; |
| 1859 | |
| 1860 | for (i = table->num_max_dpm_entries - 1; i >= 0; i--) { |
| 1861 | if (pi->high_voltage_t && |
| 1862 | (kv_convert_2bit_index_to_voltage(rdev, table->entries[i].vid_2bit) <= |
| 1863 | pi->high_voltage_t)) { |
| 1864 | *limit = i; |
| 1865 | return 0; |
| 1866 | } |
| 1867 | } |
| 1868 | } |
| 1869 | |
| 1870 | *limit = 0; |
| 1871 | return 0; |
| 1872 | } |
| 1873 | |
| 1874 | static void kv_apply_state_adjust_rules(struct radeon_device *rdev, |
| 1875 | struct radeon_ps *new_rps, |
| 1876 | struct radeon_ps *old_rps) |
| 1877 | { |
| 1878 | struct kv_ps *ps = kv_get_ps(new_rps); |
| 1879 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1880 | u32 min_sclk = 10000; /* ??? */ |
| 1881 | u32 sclk, mclk = 0; |
| 1882 | int i, limit; |
| 1883 | bool force_high; |
| 1884 | struct radeon_clock_voltage_dependency_table *table = |
| 1885 | &rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk; |
| 1886 | u32 stable_p_state_sclk = 0; |
| 1887 | struct radeon_clock_and_voltage_limits *max_limits = |
| 1888 | &rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac; |
| 1889 | |
| 1890 | mclk = max_limits->mclk; |
| 1891 | sclk = min_sclk; |
| 1892 | |
| 1893 | if (pi->caps_stable_p_state) { |
| 1894 | stable_p_state_sclk = (max_limits->sclk * 75) / 100; |
| 1895 | |
| 1896 | for (i = table->count - 1; i >= 0; i++) { |
| 1897 | if (stable_p_state_sclk >= table->entries[i].clk) { |
| 1898 | stable_p_state_sclk = table->entries[i].clk; |
| 1899 | break; |
| 1900 | } |
| 1901 | } |
| 1902 | |
| 1903 | if (i > 0) |
| 1904 | stable_p_state_sclk = table->entries[0].clk; |
| 1905 | |
| 1906 | sclk = stable_p_state_sclk; |
| 1907 | } |
| 1908 | |
| 1909 | ps->need_dfs_bypass = true; |
| 1910 | |
| 1911 | for (i = 0; i < ps->num_levels; i++) { |
| 1912 | if (ps->levels[i].sclk < sclk) |
| 1913 | ps->levels[i].sclk = sclk; |
| 1914 | } |
| 1915 | |
| 1916 | if (table && table->count) { |
| 1917 | for (i = 0; i < ps->num_levels; i++) { |
| 1918 | if (pi->high_voltage_t && |
| 1919 | (pi->high_voltage_t < |
| 1920 | kv_convert_8bit_index_to_voltage(rdev, ps->levels[i].vddc_index))) { |
| 1921 | kv_get_high_voltage_limit(rdev, &limit); |
| 1922 | ps->levels[i].sclk = table->entries[limit].clk; |
| 1923 | } |
| 1924 | } |
| 1925 | } else { |
| 1926 | struct sumo_sclk_voltage_mapping_table *table = |
| 1927 | &pi->sys_info.sclk_voltage_mapping_table; |
| 1928 | |
| 1929 | for (i = 0; i < ps->num_levels; i++) { |
| 1930 | if (pi->high_voltage_t && |
| 1931 | (pi->high_voltage_t < |
| 1932 | kv_convert_8bit_index_to_voltage(rdev, ps->levels[i].vddc_index))) { |
| 1933 | kv_get_high_voltage_limit(rdev, &limit); |
| 1934 | ps->levels[i].sclk = table->entries[limit].sclk_frequency; |
| 1935 | } |
| 1936 | } |
| 1937 | } |
| 1938 | |
| 1939 | if (pi->caps_stable_p_state) { |
| 1940 | for (i = 0; i < ps->num_levels; i++) { |
| 1941 | ps->levels[i].sclk = stable_p_state_sclk; |
| 1942 | } |
| 1943 | } |
| 1944 | |
| 1945 | pi->video_start = new_rps->dclk || new_rps->vclk; |
| 1946 | |
| 1947 | if ((new_rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) == |
| 1948 | ATOM_PPLIB_CLASSIFICATION_UI_BATTERY) |
| 1949 | pi->battery_state = true; |
| 1950 | else |
| 1951 | pi->battery_state = false; |
| 1952 | |
| 1953 | if (rdev->family == CHIP_KABINI) { |
| 1954 | ps->dpm0_pg_nb_ps_lo = 0x1; |
| 1955 | ps->dpm0_pg_nb_ps_hi = 0x0; |
| 1956 | ps->dpmx_nb_ps_lo = 0x1; |
| 1957 | ps->dpmx_nb_ps_hi = 0x0; |
| 1958 | } else { |
| 1959 | ps->dpm0_pg_nb_ps_lo = 0x1; |
| 1960 | ps->dpm0_pg_nb_ps_hi = 0x0; |
| 1961 | ps->dpmx_nb_ps_lo = 0x2; |
| 1962 | ps->dpmx_nb_ps_hi = 0x1; |
| 1963 | |
| 1964 | if (pi->sys_info.nb_dpm_enable && pi->battery_state) { |
| 1965 | force_high = (mclk >= pi->sys_info.nbp_memory_clock[3]) || |
| 1966 | pi->video_start || (rdev->pm.dpm.new_active_crtc_count >= 3) || |
| 1967 | pi->disable_nb_ps3_in_battery; |
| 1968 | ps->dpm0_pg_nb_ps_lo = force_high ? 0x2 : 0x3; |
| 1969 | ps->dpm0_pg_nb_ps_hi = 0x2; |
| 1970 | ps->dpmx_nb_ps_lo = force_high ? 0x2 : 0x3; |
| 1971 | ps->dpmx_nb_ps_hi = 0x2; |
| 1972 | } |
| 1973 | } |
| 1974 | } |
| 1975 | |
| 1976 | static void kv_dpm_power_level_enabled_for_throttle(struct radeon_device *rdev, |
| 1977 | u32 index, bool enable) |
| 1978 | { |
| 1979 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1980 | |
| 1981 | pi->graphics_level[index].EnabledForThrottle = enable ? 1 : 0; |
| 1982 | } |
| 1983 | |
| 1984 | static int kv_calculate_ds_divider(struct radeon_device *rdev) |
| 1985 | { |
| 1986 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 1987 | u32 sclk_in_sr = 10000; /* ??? */ |
| 1988 | u32 i; |
| 1989 | |
| 1990 | if (pi->lowest_valid > pi->highest_valid) |
| 1991 | return -EINVAL; |
| 1992 | |
| 1993 | for (i = pi->lowest_valid; i <= pi->highest_valid; i++) { |
| 1994 | pi->graphics_level[i].DeepSleepDivId = |
| 1995 | kv_get_sleep_divider_id_from_clock(rdev, |
| 1996 | be32_to_cpu(pi->graphics_level[i].SclkFrequency), |
| 1997 | sclk_in_sr); |
| 1998 | } |
| 1999 | return 0; |
| 2000 | } |
| 2001 | |
| 2002 | static int kv_calculate_nbps_level_settings(struct radeon_device *rdev) |
| 2003 | { |
| 2004 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 2005 | u32 i; |
| 2006 | bool force_high; |
| 2007 | struct radeon_clock_and_voltage_limits *max_limits = |
| 2008 | &rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac; |
| 2009 | u32 mclk = max_limits->mclk; |
| 2010 | |
| 2011 | if (pi->lowest_valid > pi->highest_valid) |
| 2012 | return -EINVAL; |
| 2013 | |
| 2014 | if (rdev->family == CHIP_KABINI) { |
| 2015 | for (i = pi->lowest_valid; i <= pi->highest_valid; i++) { |
| 2016 | pi->graphics_level[i].GnbSlow = 1; |
| 2017 | pi->graphics_level[i].ForceNbPs1 = 0; |
| 2018 | pi->graphics_level[i].UpH = 0; |
| 2019 | } |
| 2020 | |
| 2021 | if (!pi->sys_info.nb_dpm_enable) |
| 2022 | return 0; |
| 2023 | |
| 2024 | force_high = ((mclk >= pi->sys_info.nbp_memory_clock[3]) || |
| 2025 | (rdev->pm.dpm.new_active_crtc_count >= 3) || pi->video_start); |
| 2026 | |
| 2027 | if (force_high) { |
| 2028 | for (i = pi->lowest_valid; i <= pi->highest_valid; i++) |
| 2029 | pi->graphics_level[i].GnbSlow = 0; |
| 2030 | } else { |
| 2031 | if (pi->battery_state) |
| 2032 | pi->graphics_level[0].ForceNbPs1 = 1; |
| 2033 | |
| 2034 | pi->graphics_level[1].GnbSlow = 0; |
| 2035 | pi->graphics_level[2].GnbSlow = 0; |
| 2036 | pi->graphics_level[3].GnbSlow = 0; |
| 2037 | pi->graphics_level[4].GnbSlow = 0; |
| 2038 | } |
| 2039 | } else { |
| 2040 | for (i = pi->lowest_valid; i <= pi->highest_valid; i++) { |
| 2041 | pi->graphics_level[i].GnbSlow = 1; |
| 2042 | pi->graphics_level[i].ForceNbPs1 = 0; |
| 2043 | pi->graphics_level[i].UpH = 0; |
| 2044 | } |
| 2045 | |
| 2046 | if (pi->sys_info.nb_dpm_enable && pi->battery_state) { |
| 2047 | pi->graphics_level[pi->lowest_valid].UpH = 0x28; |
| 2048 | pi->graphics_level[pi->lowest_valid].GnbSlow = 0; |
| 2049 | if (pi->lowest_valid != pi->highest_valid) |
| 2050 | pi->graphics_level[pi->lowest_valid].ForceNbPs1 = 1; |
| 2051 | } |
| 2052 | } |
| 2053 | return 0; |
| 2054 | } |
| 2055 | |
| 2056 | static int kv_calculate_dpm_settings(struct radeon_device *rdev) |
| 2057 | { |
| 2058 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 2059 | u32 i; |
| 2060 | |
| 2061 | if (pi->lowest_valid > pi->highest_valid) |
| 2062 | return -EINVAL; |
| 2063 | |
| 2064 | for (i = pi->lowest_valid; i <= pi->highest_valid; i++) |
| 2065 | pi->graphics_level[i].DisplayWatermark = (i == pi->highest_valid) ? 1 : 0; |
| 2066 | |
| 2067 | return 0; |
| 2068 | } |
| 2069 | |
| 2070 | static void kv_init_graphics_levels(struct radeon_device *rdev) |
| 2071 | { |
| 2072 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 2073 | u32 i; |
| 2074 | struct radeon_clock_voltage_dependency_table *table = |
| 2075 | &rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk; |
| 2076 | |
| 2077 | if (table && table->count) { |
| 2078 | u32 vid_2bit; |
| 2079 | |
| 2080 | pi->graphics_dpm_level_count = 0; |
| 2081 | for (i = 0; i < table->count; i++) { |
| 2082 | if (pi->high_voltage_t && |
| 2083 | (pi->high_voltage_t < |
| 2084 | kv_convert_8bit_index_to_voltage(rdev, table->entries[i].v))) |
| 2085 | break; |
| 2086 | |
| 2087 | kv_set_divider_value(rdev, i, table->entries[i].clk); |
| 2088 | vid_2bit = sumo_convert_vid7_to_vid2(rdev, |
| 2089 | &pi->sys_info.vid_mapping_table, |
| 2090 | table->entries[i].v); |
| 2091 | kv_set_vid(rdev, i, vid_2bit); |
| 2092 | kv_set_at(rdev, i, pi->at[i]); |
| 2093 | kv_dpm_power_level_enabled_for_throttle(rdev, i, true); |
| 2094 | pi->graphics_dpm_level_count++; |
| 2095 | } |
| 2096 | } else { |
| 2097 | struct sumo_sclk_voltage_mapping_table *table = |
| 2098 | &pi->sys_info.sclk_voltage_mapping_table; |
| 2099 | |
| 2100 | pi->graphics_dpm_level_count = 0; |
| 2101 | for (i = 0; i < table->num_max_dpm_entries; i++) { |
| 2102 | if (pi->high_voltage_t && |
| 2103 | pi->high_voltage_t < |
| 2104 | kv_convert_2bit_index_to_voltage(rdev, table->entries[i].vid_2bit)) |
| 2105 | break; |
| 2106 | |
| 2107 | kv_set_divider_value(rdev, i, table->entries[i].sclk_frequency); |
| 2108 | kv_set_vid(rdev, i, table->entries[i].vid_2bit); |
| 2109 | kv_set_at(rdev, i, pi->at[i]); |
| 2110 | kv_dpm_power_level_enabled_for_throttle(rdev, i, true); |
| 2111 | pi->graphics_dpm_level_count++; |
| 2112 | } |
| 2113 | } |
| 2114 | |
| 2115 | for (i = 0; i < SMU7_MAX_LEVELS_GRAPHICS; i++) |
| 2116 | kv_dpm_power_level_enable(rdev, i, false); |
| 2117 | } |
| 2118 | |
| 2119 | static void kv_enable_new_levels(struct radeon_device *rdev) |
| 2120 | { |
| 2121 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 2122 | u32 i; |
| 2123 | |
| 2124 | for (i = 0; i < SMU7_MAX_LEVELS_GRAPHICS; i++) { |
| 2125 | if (i >= pi->lowest_valid && i <= pi->highest_valid) |
| 2126 | kv_dpm_power_level_enable(rdev, i, true); |
| 2127 | } |
| 2128 | } |
| 2129 | |
| 2130 | static int kv_set_enabled_levels(struct radeon_device *rdev) |
| 2131 | { |
| 2132 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 2133 | u32 i, new_mask = 0; |
| 2134 | |
| 2135 | for (i = pi->lowest_valid; i <= pi->highest_valid; i++) |
| 2136 | new_mask |= (1 << i); |
| 2137 | |
| 2138 | return kv_send_msg_to_smc_with_parameter(rdev, |
| 2139 | PPSMC_MSG_SCLKDPM_SetEnabledMask, |
| 2140 | new_mask); |
| 2141 | } |
| 2142 | |
| 2143 | static void kv_program_nbps_index_settings(struct radeon_device *rdev, |
| 2144 | struct radeon_ps *new_rps) |
| 2145 | { |
| 2146 | struct kv_ps *new_ps = kv_get_ps(new_rps); |
| 2147 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 2148 | u32 nbdpmconfig1; |
| 2149 | |
| 2150 | if (rdev->family == CHIP_KABINI) |
| 2151 | return; |
| 2152 | |
| 2153 | if (pi->sys_info.nb_dpm_enable) { |
| 2154 | nbdpmconfig1 = RREG32_SMC(NB_DPM_CONFIG_1); |
| 2155 | nbdpmconfig1 &= ~(Dpm0PgNbPsLo_MASK | Dpm0PgNbPsHi_MASK | |
| 2156 | DpmXNbPsLo_MASK | DpmXNbPsHi_MASK); |
| 2157 | nbdpmconfig1 |= (Dpm0PgNbPsLo(new_ps->dpm0_pg_nb_ps_lo) | |
| 2158 | Dpm0PgNbPsHi(new_ps->dpm0_pg_nb_ps_hi) | |
| 2159 | DpmXNbPsLo(new_ps->dpmx_nb_ps_lo) | |
| 2160 | DpmXNbPsHi(new_ps->dpmx_nb_ps_hi)); |
| 2161 | WREG32_SMC(NB_DPM_CONFIG_1, nbdpmconfig1); |
| 2162 | } |
| 2163 | } |
| 2164 | |
| 2165 | static int kv_set_thermal_temperature_range(struct radeon_device *rdev, |
| 2166 | int min_temp, int max_temp) |
| 2167 | { |
| 2168 | int low_temp = 0 * 1000; |
| 2169 | int high_temp = 255 * 1000; |
| 2170 | u32 tmp; |
| 2171 | |
| 2172 | if (low_temp < min_temp) |
| 2173 | low_temp = min_temp; |
| 2174 | if (high_temp > max_temp) |
| 2175 | high_temp = max_temp; |
| 2176 | if (high_temp < low_temp) { |
| 2177 | DRM_ERROR("invalid thermal range: %d - %d\n", low_temp, high_temp); |
| 2178 | return -EINVAL; |
| 2179 | } |
| 2180 | |
| 2181 | tmp = RREG32_SMC(CG_THERMAL_INT_CTRL); |
| 2182 | tmp &= ~(DIG_THERM_INTH_MASK | DIG_THERM_INTL_MASK); |
| 2183 | tmp |= (DIG_THERM_INTH(49 + (high_temp / 1000)) | |
| 2184 | DIG_THERM_INTL(49 + (low_temp / 1000))); |
| 2185 | WREG32_SMC(CG_THERMAL_INT_CTRL, tmp); |
| 2186 | |
| 2187 | rdev->pm.dpm.thermal.min_temp = low_temp; |
| 2188 | rdev->pm.dpm.thermal.max_temp = high_temp; |
| 2189 | |
| 2190 | return 0; |
| 2191 | } |
| 2192 | |
| 2193 | union igp_info { |
| 2194 | struct _ATOM_INTEGRATED_SYSTEM_INFO info; |
| 2195 | struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2; |
| 2196 | struct _ATOM_INTEGRATED_SYSTEM_INFO_V5 info_5; |
| 2197 | struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 info_6; |
| 2198 | struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_7 info_7; |
| 2199 | struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_8 info_8; |
| 2200 | }; |
| 2201 | |
| 2202 | static int kv_parse_sys_info_table(struct radeon_device *rdev) |
| 2203 | { |
| 2204 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 2205 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 2206 | int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo); |
| 2207 | union igp_info *igp_info; |
| 2208 | u8 frev, crev; |
| 2209 | u16 data_offset; |
| 2210 | int i; |
| 2211 | |
| 2212 | if (atom_parse_data_header(mode_info->atom_context, index, NULL, |
| 2213 | &frev, &crev, &data_offset)) { |
| 2214 | igp_info = (union igp_info *)(mode_info->atom_context->bios + |
| 2215 | data_offset); |
| 2216 | |
| 2217 | if (crev != 8) { |
| 2218 | DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev); |
| 2219 | return -EINVAL; |
| 2220 | } |
| 2221 | pi->sys_info.bootup_sclk = le32_to_cpu(igp_info->info_8.ulBootUpEngineClock); |
| 2222 | pi->sys_info.bootup_uma_clk = le32_to_cpu(igp_info->info_8.ulBootUpUMAClock); |
| 2223 | pi->sys_info.bootup_nb_voltage_index = |
| 2224 | le16_to_cpu(igp_info->info_8.usBootUpNBVoltage); |
| 2225 | if (igp_info->info_8.ucHtcTmpLmt == 0) |
| 2226 | pi->sys_info.htc_tmp_lmt = 203; |
| 2227 | else |
| 2228 | pi->sys_info.htc_tmp_lmt = igp_info->info_8.ucHtcTmpLmt; |
| 2229 | if (igp_info->info_8.ucHtcHystLmt == 0) |
| 2230 | pi->sys_info.htc_hyst_lmt = 5; |
| 2231 | else |
| 2232 | pi->sys_info.htc_hyst_lmt = igp_info->info_8.ucHtcHystLmt; |
| 2233 | if (pi->sys_info.htc_tmp_lmt <= pi->sys_info.htc_hyst_lmt) { |
| 2234 | DRM_ERROR("The htcTmpLmt should be larger than htcHystLmt.\n"); |
| 2235 | } |
| 2236 | |
| 2237 | if (le32_to_cpu(igp_info->info_8.ulSystemConfig) & (1 << 3)) |
| 2238 | pi->sys_info.nb_dpm_enable = true; |
| 2239 | else |
| 2240 | pi->sys_info.nb_dpm_enable = false; |
| 2241 | |
| 2242 | for (i = 0; i < KV_NUM_NBPSTATES; i++) { |
| 2243 | pi->sys_info.nbp_memory_clock[i] = |
| 2244 | le32_to_cpu(igp_info->info_8.ulNbpStateMemclkFreq[i]); |
| 2245 | pi->sys_info.nbp_n_clock[i] = |
| 2246 | le32_to_cpu(igp_info->info_8.ulNbpStateNClkFreq[i]); |
| 2247 | } |
| 2248 | if (le32_to_cpu(igp_info->info_8.ulGPUCapInfo) & |
| 2249 | SYS_INFO_GPUCAPS__ENABEL_DFS_BYPASS) |
| 2250 | pi->caps_enable_dfs_bypass = true; |
| 2251 | |
| 2252 | sumo_construct_sclk_voltage_mapping_table(rdev, |
| 2253 | &pi->sys_info.sclk_voltage_mapping_table, |
| 2254 | igp_info->info_8.sAvail_SCLK); |
| 2255 | |
| 2256 | sumo_construct_vid_mapping_table(rdev, |
| 2257 | &pi->sys_info.vid_mapping_table, |
| 2258 | igp_info->info_8.sAvail_SCLK); |
| 2259 | |
| 2260 | kv_construct_max_power_limits_table(rdev, |
| 2261 | &rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac); |
| 2262 | } |
| 2263 | return 0; |
| 2264 | } |
| 2265 | |
| 2266 | union power_info { |
| 2267 | struct _ATOM_POWERPLAY_INFO info; |
| 2268 | struct _ATOM_POWERPLAY_INFO_V2 info_2; |
| 2269 | struct _ATOM_POWERPLAY_INFO_V3 info_3; |
| 2270 | struct _ATOM_PPLIB_POWERPLAYTABLE pplib; |
| 2271 | struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2; |
| 2272 | struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3; |
| 2273 | }; |
| 2274 | |
| 2275 | union pplib_clock_info { |
| 2276 | struct _ATOM_PPLIB_R600_CLOCK_INFO r600; |
| 2277 | struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780; |
| 2278 | struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen; |
| 2279 | struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo; |
| 2280 | }; |
| 2281 | |
| 2282 | union pplib_power_state { |
| 2283 | struct _ATOM_PPLIB_STATE v1; |
| 2284 | struct _ATOM_PPLIB_STATE_V2 v2; |
| 2285 | }; |
| 2286 | |
| 2287 | static void kv_patch_boot_state(struct radeon_device *rdev, |
| 2288 | struct kv_ps *ps) |
| 2289 | { |
| 2290 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 2291 | |
| 2292 | ps->num_levels = 1; |
| 2293 | ps->levels[0] = pi->boot_pl; |
| 2294 | } |
| 2295 | |
| 2296 | static void kv_parse_pplib_non_clock_info(struct radeon_device *rdev, |
| 2297 | struct radeon_ps *rps, |
| 2298 | struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info, |
| 2299 | u8 table_rev) |
| 2300 | { |
| 2301 | struct kv_ps *ps = kv_get_ps(rps); |
| 2302 | |
| 2303 | rps->caps = le32_to_cpu(non_clock_info->ulCapsAndSettings); |
| 2304 | rps->class = le16_to_cpu(non_clock_info->usClassification); |
| 2305 | rps->class2 = le16_to_cpu(non_clock_info->usClassification2); |
| 2306 | |
| 2307 | if (ATOM_PPLIB_NONCLOCKINFO_VER1 < table_rev) { |
| 2308 | rps->vclk = le32_to_cpu(non_clock_info->ulVCLK); |
| 2309 | rps->dclk = le32_to_cpu(non_clock_info->ulDCLK); |
| 2310 | } else { |
| 2311 | rps->vclk = 0; |
| 2312 | rps->dclk = 0; |
| 2313 | } |
| 2314 | |
| 2315 | if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT) { |
| 2316 | rdev->pm.dpm.boot_ps = rps; |
| 2317 | kv_patch_boot_state(rdev, ps); |
| 2318 | } |
| 2319 | if (rps->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE) |
| 2320 | rdev->pm.dpm.uvd_ps = rps; |
| 2321 | } |
| 2322 | |
| 2323 | static void kv_parse_pplib_clock_info(struct radeon_device *rdev, |
| 2324 | struct radeon_ps *rps, int index, |
| 2325 | union pplib_clock_info *clock_info) |
| 2326 | { |
| 2327 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 2328 | struct kv_ps *ps = kv_get_ps(rps); |
| 2329 | struct kv_pl *pl = &ps->levels[index]; |
| 2330 | u32 sclk; |
| 2331 | |
| 2332 | sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow); |
| 2333 | sclk |= clock_info->sumo.ucEngineClockHigh << 16; |
| 2334 | pl->sclk = sclk; |
| 2335 | pl->vddc_index = clock_info->sumo.vddcIndex; |
| 2336 | |
| 2337 | ps->num_levels = index + 1; |
| 2338 | |
| 2339 | if (pi->caps_sclk_ds) { |
| 2340 | pl->ds_divider_index = 5; |
| 2341 | pl->ss_divider_index = 5; |
| 2342 | } |
| 2343 | } |
| 2344 | |
| 2345 | static int kv_parse_power_table(struct radeon_device *rdev) |
| 2346 | { |
| 2347 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 2348 | struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info; |
| 2349 | union pplib_power_state *power_state; |
| 2350 | int i, j, k, non_clock_array_index, clock_array_index; |
| 2351 | union pplib_clock_info *clock_info; |
| 2352 | struct _StateArray *state_array; |
| 2353 | struct _ClockInfoArray *clock_info_array; |
| 2354 | struct _NonClockInfoArray *non_clock_info_array; |
| 2355 | union power_info *power_info; |
| 2356 | int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo); |
| 2357 | u16 data_offset; |
| 2358 | u8 frev, crev; |
| 2359 | u8 *power_state_offset; |
| 2360 | struct kv_ps *ps; |
| 2361 | |
| 2362 | if (!atom_parse_data_header(mode_info->atom_context, index, NULL, |
| 2363 | &frev, &crev, &data_offset)) |
| 2364 | return -EINVAL; |
| 2365 | power_info = (union power_info *)(mode_info->atom_context->bios + data_offset); |
| 2366 | |
| 2367 | state_array = (struct _StateArray *) |
| 2368 | (mode_info->atom_context->bios + data_offset + |
| 2369 | le16_to_cpu(power_info->pplib.usStateArrayOffset)); |
| 2370 | clock_info_array = (struct _ClockInfoArray *) |
| 2371 | (mode_info->atom_context->bios + data_offset + |
| 2372 | le16_to_cpu(power_info->pplib.usClockInfoArrayOffset)); |
| 2373 | non_clock_info_array = (struct _NonClockInfoArray *) |
| 2374 | (mode_info->atom_context->bios + data_offset + |
| 2375 | le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset)); |
| 2376 | |
| 2377 | rdev->pm.dpm.ps = kzalloc(sizeof(struct radeon_ps) * |
| 2378 | state_array->ucNumEntries, GFP_KERNEL); |
| 2379 | if (!rdev->pm.dpm.ps) |
| 2380 | return -ENOMEM; |
| 2381 | power_state_offset = (u8 *)state_array->states; |
| 2382 | rdev->pm.dpm.platform_caps = le32_to_cpu(power_info->pplib.ulPlatformCaps); |
| 2383 | rdev->pm.dpm.backbias_response_time = le16_to_cpu(power_info->pplib.usBackbiasTime); |
| 2384 | rdev->pm.dpm.voltage_response_time = le16_to_cpu(power_info->pplib.usVoltageTime); |
| 2385 | for (i = 0; i < state_array->ucNumEntries; i++) { |
| 2386 | power_state = (union pplib_power_state *)power_state_offset; |
| 2387 | non_clock_array_index = power_state->v2.nonClockInfoIndex; |
| 2388 | non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *) |
| 2389 | &non_clock_info_array->nonClockInfo[non_clock_array_index]; |
| 2390 | if (!rdev->pm.power_state[i].clock_info) |
| 2391 | return -EINVAL; |
| 2392 | ps = kzalloc(sizeof(struct kv_ps), GFP_KERNEL); |
| 2393 | if (ps == NULL) { |
| 2394 | kfree(rdev->pm.dpm.ps); |
| 2395 | return -ENOMEM; |
| 2396 | } |
| 2397 | rdev->pm.dpm.ps[i].ps_priv = ps; |
| 2398 | k = 0; |
| 2399 | for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) { |
| 2400 | clock_array_index = power_state->v2.clockInfoIndex[j]; |
| 2401 | if (clock_array_index >= clock_info_array->ucNumEntries) |
| 2402 | continue; |
| 2403 | if (k >= SUMO_MAX_HARDWARE_POWERLEVELS) |
| 2404 | break; |
| 2405 | clock_info = (union pplib_clock_info *) |
| 2406 | &clock_info_array->clockInfo[clock_array_index * clock_info_array->ucEntrySize]; |
| 2407 | kv_parse_pplib_clock_info(rdev, |
| 2408 | &rdev->pm.dpm.ps[i], k, |
| 2409 | clock_info); |
| 2410 | k++; |
| 2411 | } |
| 2412 | kv_parse_pplib_non_clock_info(rdev, &rdev->pm.dpm.ps[i], |
| 2413 | non_clock_info, |
| 2414 | non_clock_info_array->ucEntrySize); |
| 2415 | power_state_offset += 2 + power_state->v2.ucNumDPMLevels; |
| 2416 | } |
| 2417 | rdev->pm.dpm.num_ps = state_array->ucNumEntries; |
| 2418 | return 0; |
| 2419 | } |
| 2420 | |
| 2421 | int kv_dpm_init(struct radeon_device *rdev) |
| 2422 | { |
| 2423 | struct kv_power_info *pi; |
| 2424 | int ret, i; |
| 2425 | |
| 2426 | pi = kzalloc(sizeof(struct kv_power_info), GFP_KERNEL); |
| 2427 | if (pi == NULL) |
| 2428 | return -ENOMEM; |
| 2429 | rdev->pm.dpm.priv = pi; |
| 2430 | |
| 2431 | ret = r600_parse_extended_power_table(rdev); |
| 2432 | if (ret) |
| 2433 | return ret; |
| 2434 | |
| 2435 | for (i = 0; i < SUMO_MAX_HARDWARE_POWERLEVELS; i++) |
| 2436 | pi->at[i] = TRINITY_AT_DFLT; |
| 2437 | |
| 2438 | pi->sram_end = SMC_RAM_END; |
| 2439 | |
| 2440 | if (rdev->family == CHIP_KABINI) |
| 2441 | pi->high_voltage_t = 4001; |
| 2442 | |
| 2443 | pi->enable_nb_dpm = true; |
| 2444 | |
| 2445 | pi->caps_power_containment = true; |
| 2446 | pi->caps_cac = true; |
| 2447 | pi->enable_didt = false; |
| 2448 | if (pi->enable_didt) { |
| 2449 | pi->caps_sq_ramping = true; |
| 2450 | pi->caps_db_ramping = true; |
| 2451 | pi->caps_td_ramping = true; |
| 2452 | pi->caps_tcp_ramping = true; |
| 2453 | } |
| 2454 | |
| 2455 | pi->caps_sclk_ds = true; |
| 2456 | pi->enable_auto_thermal_throttling = true; |
| 2457 | pi->disable_nb_ps3_in_battery = false; |
| 2458 | pi->bapm_enable = true; |
| 2459 | pi->voltage_drop_t = 0; |
| 2460 | pi->caps_sclk_throttle_low_notification = false; |
| 2461 | pi->caps_fps = false; /* true? */ |
| 2462 | pi->caps_uvd_pg = false; /* XXX */ |
| 2463 | pi->caps_uvd_dpm = true; |
| 2464 | pi->caps_vce_pg = false; |
| 2465 | pi->caps_samu_pg = false; |
| 2466 | pi->caps_acp_pg = false; |
| 2467 | pi->caps_stable_p_state = false; |
| 2468 | |
| 2469 | ret = kv_parse_sys_info_table(rdev); |
| 2470 | if (ret) |
| 2471 | return ret; |
| 2472 | |
| 2473 | kv_patch_voltage_values(rdev); |
| 2474 | kv_construct_boot_state(rdev); |
| 2475 | |
| 2476 | ret = kv_parse_power_table(rdev); |
| 2477 | if (ret) |
| 2478 | return ret; |
| 2479 | |
| 2480 | pi->enable_dpm = true; |
| 2481 | |
| 2482 | return 0; |
| 2483 | } |
| 2484 | |
Alex Deucher | ae3e40e | 2013-07-18 16:39:53 -0400 | [diff] [blame^] | 2485 | void kv_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev, |
| 2486 | struct seq_file *m) |
| 2487 | { |
| 2488 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 2489 | u32 current_index = |
| 2490 | (RREG32_SMC(TARGET_AND_CURRENT_PROFILE_INDEX) & CURR_SCLK_INDEX_MASK) >> |
| 2491 | CURR_SCLK_INDEX_SHIFT; |
| 2492 | u32 sclk, tmp; |
| 2493 | u16 vddc; |
| 2494 | |
| 2495 | if (current_index >= SMU__NUM_SCLK_DPM_STATE) { |
| 2496 | seq_printf(m, "invalid dpm profile %d\n", current_index); |
| 2497 | } else { |
| 2498 | sclk = be32_to_cpu(pi->graphics_level[current_index].SclkFrequency); |
| 2499 | tmp = (RREG32_SMC(SMU_VOLTAGE_STATUS) & SMU_VOLTAGE_CURRENT_LEVEL_MASK) >> |
| 2500 | SMU_VOLTAGE_CURRENT_LEVEL_SHIFT; |
| 2501 | vddc = kv_convert_8bit_index_to_voltage(rdev, (u16)tmp); |
| 2502 | seq_printf(m, "power level %d sclk: %u vddc: %u\n", |
| 2503 | current_index, sclk, vddc); |
| 2504 | } |
| 2505 | } |
| 2506 | |
Alex Deucher | 41a524a | 2013-08-14 01:01:40 -0400 | [diff] [blame] | 2507 | void kv_dpm_print_power_state(struct radeon_device *rdev, |
| 2508 | struct radeon_ps *rps) |
| 2509 | { |
| 2510 | int i; |
| 2511 | struct kv_ps *ps = kv_get_ps(rps); |
| 2512 | |
| 2513 | r600_dpm_print_class_info(rps->class, rps->class2); |
| 2514 | r600_dpm_print_cap_info(rps->caps); |
| 2515 | printk("\tuvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk); |
| 2516 | for (i = 0; i < ps->num_levels; i++) { |
| 2517 | struct kv_pl *pl = &ps->levels[i]; |
| 2518 | printk("\t\tpower level %d sclk: %u vddc: %u\n", |
| 2519 | i, pl->sclk, |
| 2520 | kv_convert_8bit_index_to_voltage(rdev, pl->vddc_index)); |
| 2521 | } |
| 2522 | r600_dpm_print_ps_status(rdev, rps); |
| 2523 | } |
| 2524 | |
| 2525 | void kv_dpm_fini(struct radeon_device *rdev) |
| 2526 | { |
| 2527 | int i; |
| 2528 | |
| 2529 | for (i = 0; i < rdev->pm.dpm.num_ps; i++) { |
| 2530 | kfree(rdev->pm.dpm.ps[i].ps_priv); |
| 2531 | } |
| 2532 | kfree(rdev->pm.dpm.ps); |
| 2533 | kfree(rdev->pm.dpm.priv); |
| 2534 | r600_free_extended_power_table(rdev); |
| 2535 | } |
| 2536 | |
| 2537 | void kv_dpm_display_configuration_changed(struct radeon_device *rdev) |
| 2538 | { |
| 2539 | |
| 2540 | } |
| 2541 | |
| 2542 | u32 kv_dpm_get_sclk(struct radeon_device *rdev, bool low) |
| 2543 | { |
| 2544 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 2545 | struct kv_ps *requested_state = kv_get_ps(&pi->requested_rps); |
| 2546 | |
| 2547 | if (low) |
| 2548 | return requested_state->levels[0].sclk; |
| 2549 | else |
| 2550 | return requested_state->levels[requested_state->num_levels - 1].sclk; |
| 2551 | } |
| 2552 | |
| 2553 | u32 kv_dpm_get_mclk(struct radeon_device *rdev, bool low) |
| 2554 | { |
| 2555 | struct kv_power_info *pi = kv_get_pi(rdev); |
| 2556 | |
| 2557 | return pi->sys_info.bootup_uma_clk; |
| 2558 | } |
| 2559 | |