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