Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -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 "ci_dpm.h" |
| 29 | #include "atom.h" |
Alex Deucher | 94b4adc | 2013-07-15 17:34:33 -0400 | [diff] [blame] | 30 | #include <linux/seq_file.h> |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 31 | |
| 32 | #define MC_CG_ARB_FREQ_F0 0x0a |
| 33 | #define MC_CG_ARB_FREQ_F1 0x0b |
| 34 | #define MC_CG_ARB_FREQ_F2 0x0c |
| 35 | #define MC_CG_ARB_FREQ_F3 0x0d |
| 36 | |
| 37 | #define SMC_RAM_END 0x40000 |
| 38 | |
| 39 | #define VOLTAGE_SCALE 4 |
| 40 | #define VOLTAGE_VID_OFFSET_SCALE1 625 |
| 41 | #define VOLTAGE_VID_OFFSET_SCALE2 100 |
| 42 | |
Alex Deucher | 2d40038 | 2013-08-09 18:27:47 -0400 | [diff] [blame] | 43 | static const struct ci_pt_defaults defaults_hawaii_xt = |
| 44 | { |
| 45 | 1, 0xF, 0xFD, 0x19, 5, 0x14, 0, 0xB0000, |
| 46 | { 0x84, 0x0, 0x0, 0x7F, 0x0, 0x0, 0x5A, 0x60, 0x51, 0x8E, 0x79, 0x6B, 0x5F, 0x90, 0x79 }, |
| 47 | { 0x1EA, 0x1EA, 0x1EA, 0x224, 0x224, 0x224, 0x24F, 0x24F, 0x24F, 0x28E, 0x28E, 0x28E, 0x2BC, 0x2BC, 0x2BC } |
| 48 | }; |
| 49 | |
| 50 | static const struct ci_pt_defaults defaults_hawaii_pro = |
| 51 | { |
| 52 | 1, 0xF, 0xFD, 0x19, 5, 0x14, 0, 0x65062, |
| 53 | { 0x93, 0x0, 0x0, 0x97, 0x0, 0x0, 0x6B, 0x60, 0x51, 0x95, 0x79, 0x6B, 0x5F, 0x90, 0x79 }, |
| 54 | { 0x1EA, 0x1EA, 0x1EA, 0x224, 0x224, 0x224, 0x24F, 0x24F, 0x24F, 0x28E, 0x28E, 0x28E, 0x2BC, 0x2BC, 0x2BC } |
| 55 | }; |
| 56 | |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 57 | static const struct ci_pt_defaults defaults_bonaire_xt = |
| 58 | { |
| 59 | 1, 0xF, 0xFD, 0x19, 5, 45, 0, 0xB0000, |
| 60 | { 0x79, 0x253, 0x25D, 0xAE, 0x72, 0x80, 0x83, 0x86, 0x6F, 0xC8, 0xC9, 0xC9, 0x2F, 0x4D, 0x61 }, |
| 61 | { 0x17C, 0x172, 0x180, 0x1BC, 0x1B3, 0x1BD, 0x206, 0x200, 0x203, 0x25D, 0x25A, 0x255, 0x2C3, 0x2C5, 0x2B4 } |
| 62 | }; |
| 63 | |
| 64 | static const struct ci_pt_defaults defaults_bonaire_pro = |
| 65 | { |
| 66 | 1, 0xF, 0xFD, 0x19, 5, 45, 0, 0x65062, |
| 67 | { 0x8C, 0x23F, 0x244, 0xA6, 0x83, 0x85, 0x86, 0x86, 0x83, 0xDB, 0xDB, 0xDA, 0x67, 0x60, 0x5F }, |
| 68 | { 0x187, 0x193, 0x193, 0x1C7, 0x1D1, 0x1D1, 0x210, 0x219, 0x219, 0x266, 0x26C, 0x26C, 0x2C9, 0x2CB, 0x2CB } |
| 69 | }; |
| 70 | |
| 71 | static const struct ci_pt_defaults defaults_saturn_xt = |
| 72 | { |
| 73 | 1, 0xF, 0xFD, 0x19, 5, 55, 0, 0x70000, |
| 74 | { 0x8C, 0x247, 0x249, 0xA6, 0x80, 0x81, 0x8B, 0x89, 0x86, 0xC9, 0xCA, 0xC9, 0x4D, 0x4D, 0x4D }, |
| 75 | { 0x187, 0x187, 0x187, 0x1C7, 0x1C7, 0x1C7, 0x210, 0x210, 0x210, 0x266, 0x266, 0x266, 0x2C9, 0x2C9, 0x2C9 } |
| 76 | }; |
| 77 | |
| 78 | static const struct ci_pt_defaults defaults_saturn_pro = |
| 79 | { |
| 80 | 1, 0xF, 0xFD, 0x19, 5, 55, 0, 0x30000, |
| 81 | { 0x96, 0x21D, 0x23B, 0xA1, 0x85, 0x87, 0x83, 0x84, 0x81, 0xE6, 0xE6, 0xE6, 0x71, 0x6A, 0x6A }, |
| 82 | { 0x193, 0x19E, 0x19E, 0x1D2, 0x1DC, 0x1DC, 0x21A, 0x223, 0x223, 0x26E, 0x27E, 0x274, 0x2CF, 0x2D2, 0x2D2 } |
| 83 | }; |
| 84 | |
| 85 | static const struct ci_pt_config_reg didt_config_ci[] = |
| 86 | { |
| 87 | { 0x10, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 88 | { 0x10, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 89 | { 0x10, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 90 | { 0x10, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 91 | { 0x11, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 92 | { 0x11, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 93 | { 0x11, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 94 | { 0x11, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 95 | { 0x12, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 96 | { 0x12, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 97 | { 0x12, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 98 | { 0x12, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 99 | { 0x2, 0x00003fff, 0, 0x4, CISLANDS_CONFIGREG_DIDT_IND }, |
| 100 | { 0x2, 0x03ff0000, 16, 0x80, CISLANDS_CONFIGREG_DIDT_IND }, |
| 101 | { 0x2, 0x78000000, 27, 0x3, CISLANDS_CONFIGREG_DIDT_IND }, |
| 102 | { 0x1, 0x0000ffff, 0, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND }, |
| 103 | { 0x1, 0xffff0000, 16, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND }, |
| 104 | { 0x0, 0x00000001, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 105 | { 0x30, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 106 | { 0x30, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 107 | { 0x30, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 108 | { 0x30, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 109 | { 0x31, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 110 | { 0x31, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 111 | { 0x31, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 112 | { 0x31, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 113 | { 0x32, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 114 | { 0x32, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 115 | { 0x32, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 116 | { 0x32, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 117 | { 0x22, 0x00003fff, 0, 0x4, CISLANDS_CONFIGREG_DIDT_IND }, |
| 118 | { 0x22, 0x03ff0000, 16, 0x80, CISLANDS_CONFIGREG_DIDT_IND }, |
| 119 | { 0x22, 0x78000000, 27, 0x3, CISLANDS_CONFIGREG_DIDT_IND }, |
| 120 | { 0x21, 0x0000ffff, 0, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND }, |
| 121 | { 0x21, 0xffff0000, 16, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND }, |
| 122 | { 0x20, 0x00000001, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 123 | { 0x50, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 124 | { 0x50, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 125 | { 0x50, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 126 | { 0x50, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 127 | { 0x51, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 128 | { 0x51, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 129 | { 0x51, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 130 | { 0x51, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 131 | { 0x52, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 132 | { 0x52, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 133 | { 0x52, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 134 | { 0x52, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 135 | { 0x42, 0x00003fff, 0, 0x4, CISLANDS_CONFIGREG_DIDT_IND }, |
| 136 | { 0x42, 0x03ff0000, 16, 0x80, CISLANDS_CONFIGREG_DIDT_IND }, |
| 137 | { 0x42, 0x78000000, 27, 0x3, CISLANDS_CONFIGREG_DIDT_IND }, |
| 138 | { 0x41, 0x0000ffff, 0, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND }, |
| 139 | { 0x41, 0xffff0000, 16, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND }, |
| 140 | { 0x40, 0x00000001, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 141 | { 0x70, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 142 | { 0x70, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 143 | { 0x70, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 144 | { 0x70, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 145 | { 0x71, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 146 | { 0x71, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 147 | { 0x71, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 148 | { 0x71, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 149 | { 0x72, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 150 | { 0x72, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 151 | { 0x72, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 152 | { 0x72, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 153 | { 0x62, 0x00003fff, 0, 0x4, CISLANDS_CONFIGREG_DIDT_IND }, |
| 154 | { 0x62, 0x03ff0000, 16, 0x80, CISLANDS_CONFIGREG_DIDT_IND }, |
| 155 | { 0x62, 0x78000000, 27, 0x3, CISLANDS_CONFIGREG_DIDT_IND }, |
| 156 | { 0x61, 0x0000ffff, 0, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND }, |
| 157 | { 0x61, 0xffff0000, 16, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND }, |
| 158 | { 0x60, 0x00000001, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 159 | { 0xFFFFFFFF } |
| 160 | }; |
| 161 | |
| 162 | extern u8 rv770_get_memory_module_index(struct radeon_device *rdev); |
Alex Deucher | a52b5eb | 2013-09-21 14:16:01 -0400 | [diff] [blame] | 163 | extern void btc_get_max_clock_from_voltage_dependency_table(struct radeon_clock_voltage_dependency_table *table, |
| 164 | u32 *max_clock); |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 165 | extern int ni_copy_and_switch_arb_sets(struct radeon_device *rdev, |
| 166 | u32 arb_freq_src, u32 arb_freq_dest); |
| 167 | extern u8 si_get_ddr3_mclk_frequency_ratio(u32 memory_clock); |
| 168 | extern u8 si_get_mclk_frequency_ratio(u32 memory_clock, bool strobe_mode); |
| 169 | extern void si_trim_voltage_table_to_fit_state_table(struct radeon_device *rdev, |
| 170 | u32 max_voltage_steps, |
| 171 | struct atom_voltage_table *voltage_table); |
| 172 | extern void cik_enter_rlc_safe_mode(struct radeon_device *rdev); |
| 173 | extern void cik_exit_rlc_safe_mode(struct radeon_device *rdev); |
Alex Deucher | 6c7bcce | 2013-12-18 14:07:14 -0500 | [diff] [blame] | 174 | extern int ci_mc_load_microcode(struct radeon_device *rdev); |
Alex Deucher | a1d6f97 | 2013-09-06 12:33:04 -0400 | [diff] [blame] | 175 | extern void cik_update_cg(struct radeon_device *rdev, |
| 176 | u32 block, bool enable); |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 177 | |
| 178 | static int ci_get_std_voltage_value_sidd(struct radeon_device *rdev, |
| 179 | struct atom_voltage_table_entry *voltage_table, |
| 180 | u16 *std_voltage_hi_sidd, u16 *std_voltage_lo_sidd); |
| 181 | static int ci_set_power_limit(struct radeon_device *rdev, u32 n); |
| 182 | static int ci_set_overdrive_target_tdp(struct radeon_device *rdev, |
| 183 | u32 target_tdp); |
| 184 | static int ci_update_uvd_dpm(struct radeon_device *rdev, bool gate); |
| 185 | |
| 186 | static struct ci_power_info *ci_get_pi(struct radeon_device *rdev) |
| 187 | { |
| 188 | struct ci_power_info *pi = rdev->pm.dpm.priv; |
| 189 | |
| 190 | return pi; |
| 191 | } |
| 192 | |
| 193 | static struct ci_ps *ci_get_ps(struct radeon_ps *rps) |
| 194 | { |
| 195 | struct ci_ps *ps = rps->ps_priv; |
| 196 | |
| 197 | return ps; |
| 198 | } |
| 199 | |
| 200 | static void ci_initialize_powertune_defaults(struct radeon_device *rdev) |
| 201 | { |
| 202 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 203 | |
| 204 | switch (rdev->pdev->device) { |
Alex Deucher | 6abc6d5 | 2014-04-10 22:29:02 -0400 | [diff] [blame^] | 205 | case 0x6649: |
Alex Deucher | 2d40038 | 2013-08-09 18:27:47 -0400 | [diff] [blame] | 206 | case 0x6650: |
Alex Deucher | 6abc6d5 | 2014-04-10 22:29:02 -0400 | [diff] [blame^] | 207 | case 0x6651: |
Alex Deucher | 2d40038 | 2013-08-09 18:27:47 -0400 | [diff] [blame] | 208 | case 0x6658: |
| 209 | case 0x665C: |
Alex Deucher | 6abc6d5 | 2014-04-10 22:29:02 -0400 | [diff] [blame^] | 210 | case 0x665D: |
Alex Deucher | 2d40038 | 2013-08-09 18:27:47 -0400 | [diff] [blame] | 211 | default: |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 212 | pi->powertune_defaults = &defaults_bonaire_xt; |
| 213 | break; |
Alex Deucher | 2d40038 | 2013-08-09 18:27:47 -0400 | [diff] [blame] | 214 | case 0x6640: |
Alex Deucher | 2d40038 | 2013-08-09 18:27:47 -0400 | [diff] [blame] | 215 | case 0x6641: |
Alex Deucher | 6abc6d5 | 2014-04-10 22:29:02 -0400 | [diff] [blame^] | 216 | case 0x6646: |
| 217 | case 0x6647: |
| 218 | pi->powertune_defaults = &defaults_saturn_xt; |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 219 | break; |
Alex Deucher | 2d40038 | 2013-08-09 18:27:47 -0400 | [diff] [blame] | 220 | case 0x67B8: |
| 221 | case 0x67B0: |
Alex Deucher | 6abc6d5 | 2014-04-10 22:29:02 -0400 | [diff] [blame^] | 222 | pi->powertune_defaults = &defaults_hawaii_xt; |
| 223 | break; |
| 224 | case 0x67BA: |
| 225 | case 0x67B1: |
| 226 | pi->powertune_defaults = &defaults_hawaii_pro; |
| 227 | break; |
Alex Deucher | 2d40038 | 2013-08-09 18:27:47 -0400 | [diff] [blame] | 228 | case 0x67A0: |
| 229 | case 0x67A1: |
| 230 | case 0x67A2: |
| 231 | case 0x67A8: |
| 232 | case 0x67A9: |
| 233 | case 0x67AA: |
| 234 | case 0x67B9: |
| 235 | case 0x67BE: |
Alex Deucher | 6abc6d5 | 2014-04-10 22:29:02 -0400 | [diff] [blame^] | 236 | pi->powertune_defaults = &defaults_bonaire_xt; |
Alex Deucher | 2d40038 | 2013-08-09 18:27:47 -0400 | [diff] [blame] | 237 | break; |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | pi->dte_tj_offset = 0; |
| 241 | |
| 242 | pi->caps_power_containment = true; |
| 243 | pi->caps_cac = false; |
| 244 | pi->caps_sq_ramping = false; |
| 245 | pi->caps_db_ramping = false; |
| 246 | pi->caps_td_ramping = false; |
| 247 | pi->caps_tcp_ramping = false; |
| 248 | |
| 249 | if (pi->caps_power_containment) { |
| 250 | pi->caps_cac = true; |
| 251 | pi->enable_bapm_feature = true; |
| 252 | pi->enable_tdc_limit_feature = true; |
| 253 | pi->enable_pkg_pwr_tracking_feature = true; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | static u8 ci_convert_to_vid(u16 vddc) |
| 258 | { |
| 259 | return (6200 - (vddc * VOLTAGE_SCALE)) / 25; |
| 260 | } |
| 261 | |
| 262 | static int ci_populate_bapm_vddc_vid_sidd(struct radeon_device *rdev) |
| 263 | { |
| 264 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 265 | u8 *hi_vid = pi->smc_powertune_table.BapmVddCVidHiSidd; |
| 266 | u8 *lo_vid = pi->smc_powertune_table.BapmVddCVidLoSidd; |
| 267 | u8 *hi2_vid = pi->smc_powertune_table.BapmVddCVidHiSidd2; |
| 268 | u32 i; |
| 269 | |
| 270 | if (rdev->pm.dpm.dyn_state.cac_leakage_table.entries == NULL) |
| 271 | return -EINVAL; |
| 272 | if (rdev->pm.dpm.dyn_state.cac_leakage_table.count > 8) |
| 273 | return -EINVAL; |
| 274 | if (rdev->pm.dpm.dyn_state.cac_leakage_table.count != |
| 275 | rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.count) |
| 276 | return -EINVAL; |
| 277 | |
| 278 | for (i = 0; i < rdev->pm.dpm.dyn_state.cac_leakage_table.count; i++) { |
| 279 | if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_EVV) { |
| 280 | lo_vid[i] = ci_convert_to_vid(rdev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc1); |
| 281 | hi_vid[i] = ci_convert_to_vid(rdev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc2); |
| 282 | hi2_vid[i] = ci_convert_to_vid(rdev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc3); |
| 283 | } else { |
| 284 | lo_vid[i] = ci_convert_to_vid(rdev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc); |
| 285 | hi_vid[i] = ci_convert_to_vid((u16)rdev->pm.dpm.dyn_state.cac_leakage_table.entries[i].leakage); |
| 286 | } |
| 287 | } |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | static int ci_populate_vddc_vid(struct radeon_device *rdev) |
| 292 | { |
| 293 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 294 | u8 *vid = pi->smc_powertune_table.VddCVid; |
| 295 | u32 i; |
| 296 | |
| 297 | if (pi->vddc_voltage_table.count > 8) |
| 298 | return -EINVAL; |
| 299 | |
| 300 | for (i = 0; i < pi->vddc_voltage_table.count; i++) |
| 301 | vid[i] = ci_convert_to_vid(pi->vddc_voltage_table.entries[i].value); |
| 302 | |
| 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | static int ci_populate_svi_load_line(struct radeon_device *rdev) |
| 307 | { |
| 308 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 309 | const struct ci_pt_defaults *pt_defaults = pi->powertune_defaults; |
| 310 | |
| 311 | pi->smc_powertune_table.SviLoadLineEn = pt_defaults->svi_load_line_en; |
| 312 | pi->smc_powertune_table.SviLoadLineVddC = pt_defaults->svi_load_line_vddc; |
| 313 | pi->smc_powertune_table.SviLoadLineTrimVddC = 3; |
| 314 | pi->smc_powertune_table.SviLoadLineOffsetVddC = 0; |
| 315 | |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | static int ci_populate_tdc_limit(struct radeon_device *rdev) |
| 320 | { |
| 321 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 322 | const struct ci_pt_defaults *pt_defaults = pi->powertune_defaults; |
| 323 | u16 tdc_limit; |
| 324 | |
| 325 | tdc_limit = rdev->pm.dpm.dyn_state.cac_tdp_table->tdc * 256; |
| 326 | pi->smc_powertune_table.TDC_VDDC_PkgLimit = cpu_to_be16(tdc_limit); |
| 327 | pi->smc_powertune_table.TDC_VDDC_ThrottleReleaseLimitPerc = |
| 328 | pt_defaults->tdc_vddc_throttle_release_limit_perc; |
| 329 | pi->smc_powertune_table.TDC_MAWt = pt_defaults->tdc_mawt; |
| 330 | |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | static int ci_populate_dw8(struct radeon_device *rdev) |
| 335 | { |
| 336 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 337 | const struct ci_pt_defaults *pt_defaults = pi->powertune_defaults; |
| 338 | int ret; |
| 339 | |
| 340 | ret = ci_read_smc_sram_dword(rdev, |
| 341 | SMU7_FIRMWARE_HEADER_LOCATION + |
| 342 | offsetof(SMU7_Firmware_Header, PmFuseTable) + |
| 343 | offsetof(SMU7_Discrete_PmFuses, TdcWaterfallCtl), |
| 344 | (u32 *)&pi->smc_powertune_table.TdcWaterfallCtl, |
| 345 | pi->sram_end); |
| 346 | if (ret) |
| 347 | return -EINVAL; |
| 348 | else |
| 349 | pi->smc_powertune_table.TdcWaterfallCtl = pt_defaults->tdc_waterfall_ctl; |
| 350 | |
| 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | static int ci_min_max_v_gnbl_pm_lid_from_bapm_vddc(struct radeon_device *rdev) |
| 355 | { |
| 356 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 357 | u8 *hi_vid = pi->smc_powertune_table.BapmVddCVidHiSidd; |
| 358 | u8 *lo_vid = pi->smc_powertune_table.BapmVddCVidLoSidd; |
| 359 | int i, min, max; |
| 360 | |
| 361 | min = max = hi_vid[0]; |
| 362 | for (i = 0; i < 8; i++) { |
| 363 | if (0 != hi_vid[i]) { |
| 364 | if (min > hi_vid[i]) |
| 365 | min = hi_vid[i]; |
| 366 | if (max < hi_vid[i]) |
| 367 | max = hi_vid[i]; |
| 368 | } |
| 369 | |
| 370 | if (0 != lo_vid[i]) { |
| 371 | if (min > lo_vid[i]) |
| 372 | min = lo_vid[i]; |
| 373 | if (max < lo_vid[i]) |
| 374 | max = lo_vid[i]; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | if ((min == 0) || (max == 0)) |
| 379 | return -EINVAL; |
| 380 | pi->smc_powertune_table.GnbLPMLMaxVid = (u8)max; |
| 381 | pi->smc_powertune_table.GnbLPMLMinVid = (u8)min; |
| 382 | |
| 383 | return 0; |
| 384 | } |
| 385 | |
| 386 | static int ci_populate_bapm_vddc_base_leakage_sidd(struct radeon_device *rdev) |
| 387 | { |
| 388 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 389 | u16 hi_sidd = pi->smc_powertune_table.BapmVddCBaseLeakageHiSidd; |
| 390 | u16 lo_sidd = pi->smc_powertune_table.BapmVddCBaseLeakageLoSidd; |
| 391 | struct radeon_cac_tdp_table *cac_tdp_table = |
| 392 | rdev->pm.dpm.dyn_state.cac_tdp_table; |
| 393 | |
| 394 | hi_sidd = cac_tdp_table->high_cac_leakage / 100 * 256; |
| 395 | lo_sidd = cac_tdp_table->low_cac_leakage / 100 * 256; |
| 396 | |
| 397 | pi->smc_powertune_table.BapmVddCBaseLeakageHiSidd = cpu_to_be16(hi_sidd); |
| 398 | pi->smc_powertune_table.BapmVddCBaseLeakageLoSidd = cpu_to_be16(lo_sidd); |
| 399 | |
| 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | static int ci_populate_bapm_parameters_in_dpm_table(struct radeon_device *rdev) |
| 404 | { |
| 405 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 406 | const struct ci_pt_defaults *pt_defaults = pi->powertune_defaults; |
| 407 | SMU7_Discrete_DpmTable *dpm_table = &pi->smc_state_table; |
| 408 | struct radeon_cac_tdp_table *cac_tdp_table = |
| 409 | rdev->pm.dpm.dyn_state.cac_tdp_table; |
| 410 | struct radeon_ppm_table *ppm = rdev->pm.dpm.dyn_state.ppm_table; |
| 411 | int i, j, k; |
| 412 | const u16 *def1; |
| 413 | const u16 *def2; |
| 414 | |
| 415 | dpm_table->DefaultTdp = cac_tdp_table->tdp * 256; |
| 416 | dpm_table->TargetTdp = cac_tdp_table->configurable_tdp * 256; |
| 417 | |
| 418 | dpm_table->DTETjOffset = (u8)pi->dte_tj_offset; |
| 419 | dpm_table->GpuTjMax = |
| 420 | (u8)(pi->thermal_temp_setting.temperature_high / 1000); |
| 421 | dpm_table->GpuTjHyst = 8; |
| 422 | |
| 423 | dpm_table->DTEAmbientTempBase = pt_defaults->dte_ambient_temp_base; |
| 424 | |
| 425 | if (ppm) { |
| 426 | dpm_table->PPM_PkgPwrLimit = cpu_to_be16((u16)ppm->dgpu_tdp * 256 / 1000); |
| 427 | dpm_table->PPM_TemperatureLimit = cpu_to_be16((u16)ppm->tj_max * 256); |
| 428 | } else { |
| 429 | dpm_table->PPM_PkgPwrLimit = cpu_to_be16(0); |
| 430 | dpm_table->PPM_TemperatureLimit = cpu_to_be16(0); |
| 431 | } |
| 432 | |
| 433 | dpm_table->BAPM_TEMP_GRADIENT = cpu_to_be32(pt_defaults->bapm_temp_gradient); |
| 434 | def1 = pt_defaults->bapmti_r; |
| 435 | def2 = pt_defaults->bapmti_rc; |
| 436 | |
| 437 | for (i = 0; i < SMU7_DTE_ITERATIONS; i++) { |
| 438 | for (j = 0; j < SMU7_DTE_SOURCES; j++) { |
| 439 | for (k = 0; k < SMU7_DTE_SINKS; k++) { |
| 440 | dpm_table->BAPMTI_R[i][j][k] = cpu_to_be16(*def1); |
| 441 | dpm_table->BAPMTI_RC[i][j][k] = cpu_to_be16(*def2); |
| 442 | def1++; |
| 443 | def2++; |
| 444 | } |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | static int ci_populate_pm_base(struct radeon_device *rdev) |
| 452 | { |
| 453 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 454 | u32 pm_fuse_table_offset; |
| 455 | int ret; |
| 456 | |
| 457 | if (pi->caps_power_containment) { |
| 458 | ret = ci_read_smc_sram_dword(rdev, |
| 459 | SMU7_FIRMWARE_HEADER_LOCATION + |
| 460 | offsetof(SMU7_Firmware_Header, PmFuseTable), |
| 461 | &pm_fuse_table_offset, pi->sram_end); |
| 462 | if (ret) |
| 463 | return ret; |
| 464 | ret = ci_populate_bapm_vddc_vid_sidd(rdev); |
| 465 | if (ret) |
| 466 | return ret; |
| 467 | ret = ci_populate_vddc_vid(rdev); |
| 468 | if (ret) |
| 469 | return ret; |
| 470 | ret = ci_populate_svi_load_line(rdev); |
| 471 | if (ret) |
| 472 | return ret; |
| 473 | ret = ci_populate_tdc_limit(rdev); |
| 474 | if (ret) |
| 475 | return ret; |
| 476 | ret = ci_populate_dw8(rdev); |
| 477 | if (ret) |
| 478 | return ret; |
| 479 | ret = ci_min_max_v_gnbl_pm_lid_from_bapm_vddc(rdev); |
| 480 | if (ret) |
| 481 | return ret; |
| 482 | ret = ci_populate_bapm_vddc_base_leakage_sidd(rdev); |
| 483 | if (ret) |
| 484 | return ret; |
| 485 | ret = ci_copy_bytes_to_smc(rdev, pm_fuse_table_offset, |
| 486 | (u8 *)&pi->smc_powertune_table, |
| 487 | sizeof(SMU7_Discrete_PmFuses), pi->sram_end); |
| 488 | if (ret) |
| 489 | return ret; |
| 490 | } |
| 491 | |
| 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | static void ci_do_enable_didt(struct radeon_device *rdev, const bool enable) |
| 496 | { |
| 497 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 498 | u32 data; |
| 499 | |
| 500 | if (pi->caps_sq_ramping) { |
| 501 | data = RREG32_DIDT(DIDT_SQ_CTRL0); |
| 502 | if (enable) |
| 503 | data |= DIDT_CTRL_EN; |
| 504 | else |
| 505 | data &= ~DIDT_CTRL_EN; |
| 506 | WREG32_DIDT(DIDT_SQ_CTRL0, data); |
| 507 | } |
| 508 | |
| 509 | if (pi->caps_db_ramping) { |
| 510 | data = RREG32_DIDT(DIDT_DB_CTRL0); |
| 511 | if (enable) |
| 512 | data |= DIDT_CTRL_EN; |
| 513 | else |
| 514 | data &= ~DIDT_CTRL_EN; |
| 515 | WREG32_DIDT(DIDT_DB_CTRL0, data); |
| 516 | } |
| 517 | |
| 518 | if (pi->caps_td_ramping) { |
| 519 | data = RREG32_DIDT(DIDT_TD_CTRL0); |
| 520 | if (enable) |
| 521 | data |= DIDT_CTRL_EN; |
| 522 | else |
| 523 | data &= ~DIDT_CTRL_EN; |
| 524 | WREG32_DIDT(DIDT_TD_CTRL0, data); |
| 525 | } |
| 526 | |
| 527 | if (pi->caps_tcp_ramping) { |
| 528 | data = RREG32_DIDT(DIDT_TCP_CTRL0); |
| 529 | if (enable) |
| 530 | data |= DIDT_CTRL_EN; |
| 531 | else |
| 532 | data &= ~DIDT_CTRL_EN; |
| 533 | WREG32_DIDT(DIDT_TCP_CTRL0, data); |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | static int ci_program_pt_config_registers(struct radeon_device *rdev, |
| 538 | const struct ci_pt_config_reg *cac_config_regs) |
| 539 | { |
| 540 | const struct ci_pt_config_reg *config_regs = cac_config_regs; |
| 541 | u32 data; |
| 542 | u32 cache = 0; |
| 543 | |
| 544 | if (config_regs == NULL) |
| 545 | return -EINVAL; |
| 546 | |
| 547 | while (config_regs->offset != 0xFFFFFFFF) { |
| 548 | if (config_regs->type == CISLANDS_CONFIGREG_CACHE) { |
| 549 | cache |= ((config_regs->value << config_regs->shift) & config_regs->mask); |
| 550 | } else { |
| 551 | switch (config_regs->type) { |
| 552 | case CISLANDS_CONFIGREG_SMC_IND: |
| 553 | data = RREG32_SMC(config_regs->offset); |
| 554 | break; |
| 555 | case CISLANDS_CONFIGREG_DIDT_IND: |
| 556 | data = RREG32_DIDT(config_regs->offset); |
| 557 | break; |
| 558 | default: |
| 559 | data = RREG32(config_regs->offset << 2); |
| 560 | break; |
| 561 | } |
| 562 | |
| 563 | data &= ~config_regs->mask; |
| 564 | data |= ((config_regs->value << config_regs->shift) & config_regs->mask); |
| 565 | data |= cache; |
| 566 | |
| 567 | switch (config_regs->type) { |
| 568 | case CISLANDS_CONFIGREG_SMC_IND: |
| 569 | WREG32_SMC(config_regs->offset, data); |
| 570 | break; |
| 571 | case CISLANDS_CONFIGREG_DIDT_IND: |
| 572 | WREG32_DIDT(config_regs->offset, data); |
| 573 | break; |
| 574 | default: |
| 575 | WREG32(config_regs->offset << 2, data); |
| 576 | break; |
| 577 | } |
| 578 | cache = 0; |
| 579 | } |
| 580 | config_regs++; |
| 581 | } |
| 582 | return 0; |
| 583 | } |
| 584 | |
| 585 | static int ci_enable_didt(struct radeon_device *rdev, bool enable) |
| 586 | { |
| 587 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 588 | int ret; |
| 589 | |
| 590 | if (pi->caps_sq_ramping || pi->caps_db_ramping || |
| 591 | pi->caps_td_ramping || pi->caps_tcp_ramping) { |
| 592 | cik_enter_rlc_safe_mode(rdev); |
| 593 | |
| 594 | if (enable) { |
| 595 | ret = ci_program_pt_config_registers(rdev, didt_config_ci); |
| 596 | if (ret) { |
| 597 | cik_exit_rlc_safe_mode(rdev); |
| 598 | return ret; |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | ci_do_enable_didt(rdev, enable); |
| 603 | |
| 604 | cik_exit_rlc_safe_mode(rdev); |
| 605 | } |
| 606 | |
| 607 | return 0; |
| 608 | } |
| 609 | |
| 610 | static int ci_enable_power_containment(struct radeon_device *rdev, bool enable) |
| 611 | { |
| 612 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 613 | PPSMC_Result smc_result; |
| 614 | int ret = 0; |
| 615 | |
| 616 | if (enable) { |
| 617 | pi->power_containment_features = 0; |
| 618 | if (pi->caps_power_containment) { |
| 619 | if (pi->enable_bapm_feature) { |
| 620 | smc_result = ci_send_msg_to_smc(rdev, PPSMC_MSG_EnableDTE); |
| 621 | if (smc_result != PPSMC_Result_OK) |
| 622 | ret = -EINVAL; |
| 623 | else |
| 624 | pi->power_containment_features |= POWERCONTAINMENT_FEATURE_BAPM; |
| 625 | } |
| 626 | |
| 627 | if (pi->enable_tdc_limit_feature) { |
| 628 | smc_result = ci_send_msg_to_smc(rdev, PPSMC_MSG_TDCLimitEnable); |
| 629 | if (smc_result != PPSMC_Result_OK) |
| 630 | ret = -EINVAL; |
| 631 | else |
| 632 | pi->power_containment_features |= POWERCONTAINMENT_FEATURE_TDCLimit; |
| 633 | } |
| 634 | |
| 635 | if (pi->enable_pkg_pwr_tracking_feature) { |
| 636 | smc_result = ci_send_msg_to_smc(rdev, PPSMC_MSG_PkgPwrLimitEnable); |
| 637 | if (smc_result != PPSMC_Result_OK) { |
| 638 | ret = -EINVAL; |
| 639 | } else { |
| 640 | struct radeon_cac_tdp_table *cac_tdp_table = |
| 641 | rdev->pm.dpm.dyn_state.cac_tdp_table; |
| 642 | u32 default_pwr_limit = |
| 643 | (u32)(cac_tdp_table->maximum_power_delivery_limit * 256); |
| 644 | |
| 645 | pi->power_containment_features |= POWERCONTAINMENT_FEATURE_PkgPwrLimit; |
| 646 | |
| 647 | ci_set_power_limit(rdev, default_pwr_limit); |
| 648 | } |
| 649 | } |
| 650 | } |
| 651 | } else { |
| 652 | if (pi->caps_power_containment && pi->power_containment_features) { |
| 653 | if (pi->power_containment_features & POWERCONTAINMENT_FEATURE_TDCLimit) |
| 654 | ci_send_msg_to_smc(rdev, PPSMC_MSG_TDCLimitDisable); |
| 655 | |
| 656 | if (pi->power_containment_features & POWERCONTAINMENT_FEATURE_BAPM) |
| 657 | ci_send_msg_to_smc(rdev, PPSMC_MSG_DisableDTE); |
| 658 | |
| 659 | if (pi->power_containment_features & POWERCONTAINMENT_FEATURE_PkgPwrLimit) |
| 660 | ci_send_msg_to_smc(rdev, PPSMC_MSG_PkgPwrLimitDisable); |
| 661 | pi->power_containment_features = 0; |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | return ret; |
| 666 | } |
| 667 | |
| 668 | static int ci_enable_smc_cac(struct radeon_device *rdev, bool enable) |
| 669 | { |
| 670 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 671 | PPSMC_Result smc_result; |
| 672 | int ret = 0; |
| 673 | |
| 674 | if (pi->caps_cac) { |
| 675 | if (enable) { |
| 676 | smc_result = ci_send_msg_to_smc(rdev, PPSMC_MSG_EnableCac); |
| 677 | if (smc_result != PPSMC_Result_OK) { |
| 678 | ret = -EINVAL; |
| 679 | pi->cac_enabled = false; |
| 680 | } else { |
| 681 | pi->cac_enabled = true; |
| 682 | } |
| 683 | } else if (pi->cac_enabled) { |
| 684 | ci_send_msg_to_smc(rdev, PPSMC_MSG_DisableCac); |
| 685 | pi->cac_enabled = false; |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | return ret; |
| 690 | } |
| 691 | |
| 692 | static int ci_power_control_set_level(struct radeon_device *rdev) |
| 693 | { |
| 694 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 695 | struct radeon_cac_tdp_table *cac_tdp_table = |
| 696 | rdev->pm.dpm.dyn_state.cac_tdp_table; |
| 697 | s32 adjust_percent; |
| 698 | s32 target_tdp; |
| 699 | int ret = 0; |
| 700 | bool adjust_polarity = false; /* ??? */ |
| 701 | |
| 702 | if (pi->caps_power_containment && |
| 703 | (pi->power_containment_features & POWERCONTAINMENT_FEATURE_BAPM)) { |
| 704 | adjust_percent = adjust_polarity ? |
| 705 | rdev->pm.dpm.tdp_adjustment : (-1 * rdev->pm.dpm.tdp_adjustment); |
| 706 | target_tdp = ((100 + adjust_percent) * |
| 707 | (s32)cac_tdp_table->configurable_tdp) / 100; |
| 708 | target_tdp *= 256; |
| 709 | |
| 710 | ret = ci_set_overdrive_target_tdp(rdev, (u32)target_tdp); |
| 711 | } |
| 712 | |
| 713 | return ret; |
| 714 | } |
| 715 | |
Alex Deucher | 942bdf7 | 2013-08-09 10:05:24 -0400 | [diff] [blame] | 716 | void ci_dpm_powergate_uvd(struct radeon_device *rdev, bool gate) |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 717 | { |
Alex Deucher | 47acb1f | 2013-08-26 09:43:24 -0400 | [diff] [blame] | 718 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 719 | |
| 720 | if (pi->uvd_power_gated == gate) |
| 721 | return; |
| 722 | |
| 723 | pi->uvd_power_gated = gate; |
| 724 | |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 725 | ci_update_uvd_dpm(rdev, gate); |
| 726 | } |
| 727 | |
Alex Deucher | 5496131 | 2013-07-15 18:24:31 -0400 | [diff] [blame] | 728 | bool ci_dpm_vblank_too_short(struct radeon_device *rdev) |
| 729 | { |
| 730 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 731 | u32 vblank_time = r600_dpm_get_vblank_time(rdev); |
| 732 | u32 switch_limit = pi->mem_gddr5 ? 450 : 300; |
| 733 | |
| 734 | if (vblank_time < switch_limit) |
| 735 | return true; |
| 736 | else |
| 737 | return false; |
| 738 | |
| 739 | } |
| 740 | |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 741 | static void ci_apply_state_adjust_rules(struct radeon_device *rdev, |
| 742 | struct radeon_ps *rps) |
| 743 | { |
| 744 | struct ci_ps *ps = ci_get_ps(rps); |
| 745 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 746 | struct radeon_clock_and_voltage_limits *max_limits; |
| 747 | bool disable_mclk_switching; |
| 748 | u32 sclk, mclk; |
Alex Deucher | a52b5eb | 2013-09-21 14:16:01 -0400 | [diff] [blame] | 749 | u32 max_sclk_vddc, max_mclk_vddci, max_mclk_vddc; |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 750 | int i; |
| 751 | |
Alex Deucher | 8cd3668 | 2013-08-23 11:05:24 -0400 | [diff] [blame] | 752 | if (rps->vce_active) { |
| 753 | rps->evclk = rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].evclk; |
| 754 | rps->ecclk = rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].ecclk; |
| 755 | } else { |
| 756 | rps->evclk = 0; |
| 757 | rps->ecclk = 0; |
| 758 | } |
| 759 | |
Alex Deucher | 5496131 | 2013-07-15 18:24:31 -0400 | [diff] [blame] | 760 | if ((rdev->pm.dpm.new_active_crtc_count > 1) || |
| 761 | ci_dpm_vblank_too_short(rdev)) |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 762 | disable_mclk_switching = true; |
| 763 | else |
| 764 | disable_mclk_switching = false; |
| 765 | |
| 766 | if ((rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) == ATOM_PPLIB_CLASSIFICATION_UI_BATTERY) |
| 767 | pi->battery_state = true; |
| 768 | else |
| 769 | pi->battery_state = false; |
| 770 | |
| 771 | if (rdev->pm.dpm.ac_power) |
| 772 | max_limits = &rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac; |
| 773 | else |
| 774 | max_limits = &rdev->pm.dpm.dyn_state.max_clock_voltage_on_dc; |
| 775 | |
| 776 | if (rdev->pm.dpm.ac_power == false) { |
| 777 | for (i = 0; i < ps->performance_level_count; i++) { |
| 778 | if (ps->performance_levels[i].mclk > max_limits->mclk) |
| 779 | ps->performance_levels[i].mclk = max_limits->mclk; |
| 780 | if (ps->performance_levels[i].sclk > max_limits->sclk) |
| 781 | ps->performance_levels[i].sclk = max_limits->sclk; |
| 782 | } |
| 783 | } |
| 784 | |
Alex Deucher | a52b5eb | 2013-09-21 14:16:01 -0400 | [diff] [blame] | 785 | /* limit clocks to max supported clocks based on voltage dependency tables */ |
| 786 | btc_get_max_clock_from_voltage_dependency_table(&rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk, |
| 787 | &max_sclk_vddc); |
| 788 | btc_get_max_clock_from_voltage_dependency_table(&rdev->pm.dpm.dyn_state.vddci_dependency_on_mclk, |
| 789 | &max_mclk_vddci); |
| 790 | btc_get_max_clock_from_voltage_dependency_table(&rdev->pm.dpm.dyn_state.vddc_dependency_on_mclk, |
| 791 | &max_mclk_vddc); |
| 792 | |
| 793 | for (i = 0; i < ps->performance_level_count; i++) { |
| 794 | if (max_sclk_vddc) { |
| 795 | if (ps->performance_levels[i].sclk > max_sclk_vddc) |
| 796 | ps->performance_levels[i].sclk = max_sclk_vddc; |
| 797 | } |
| 798 | if (max_mclk_vddci) { |
| 799 | if (ps->performance_levels[i].mclk > max_mclk_vddci) |
| 800 | ps->performance_levels[i].mclk = max_mclk_vddci; |
| 801 | } |
| 802 | if (max_mclk_vddc) { |
| 803 | if (ps->performance_levels[i].mclk > max_mclk_vddc) |
| 804 | ps->performance_levels[i].mclk = max_mclk_vddc; |
| 805 | } |
| 806 | } |
| 807 | |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 808 | /* XXX validate the min clocks required for display */ |
| 809 | |
| 810 | if (disable_mclk_switching) { |
| 811 | mclk = ps->performance_levels[ps->performance_level_count - 1].mclk; |
| 812 | sclk = ps->performance_levels[0].sclk; |
| 813 | } else { |
| 814 | mclk = ps->performance_levels[0].mclk; |
| 815 | sclk = ps->performance_levels[0].sclk; |
| 816 | } |
| 817 | |
Alex Deucher | 8cd3668 | 2013-08-23 11:05:24 -0400 | [diff] [blame] | 818 | if (rps->vce_active) { |
| 819 | if (sclk < rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].sclk) |
| 820 | sclk = rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].sclk; |
| 821 | if (mclk < rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].mclk) |
| 822 | mclk = rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].mclk; |
| 823 | } |
| 824 | |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 825 | ps->performance_levels[0].sclk = sclk; |
| 826 | ps->performance_levels[0].mclk = mclk; |
| 827 | |
| 828 | if (ps->performance_levels[1].sclk < ps->performance_levels[0].sclk) |
| 829 | ps->performance_levels[1].sclk = ps->performance_levels[0].sclk; |
| 830 | |
| 831 | if (disable_mclk_switching) { |
| 832 | if (ps->performance_levels[0].mclk < ps->performance_levels[1].mclk) |
| 833 | ps->performance_levels[0].mclk = ps->performance_levels[1].mclk; |
| 834 | } else { |
| 835 | if (ps->performance_levels[1].mclk < ps->performance_levels[0].mclk) |
| 836 | ps->performance_levels[1].mclk = ps->performance_levels[0].mclk; |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | static int ci_set_thermal_temperature_range(struct radeon_device *rdev, |
| 841 | int min_temp, int max_temp) |
| 842 | { |
| 843 | int low_temp = 0 * 1000; |
| 844 | int high_temp = 255 * 1000; |
| 845 | u32 tmp; |
| 846 | |
| 847 | if (low_temp < min_temp) |
| 848 | low_temp = min_temp; |
| 849 | if (high_temp > max_temp) |
| 850 | high_temp = max_temp; |
| 851 | if (high_temp < low_temp) { |
| 852 | DRM_ERROR("invalid thermal range: %d - %d\n", low_temp, high_temp); |
| 853 | return -EINVAL; |
| 854 | } |
| 855 | |
| 856 | tmp = RREG32_SMC(CG_THERMAL_INT); |
| 857 | tmp &= ~(CI_DIG_THERM_INTH_MASK | CI_DIG_THERM_INTL_MASK); |
| 858 | tmp |= CI_DIG_THERM_INTH(high_temp / 1000) | |
| 859 | CI_DIG_THERM_INTL(low_temp / 1000); |
| 860 | WREG32_SMC(CG_THERMAL_INT, tmp); |
| 861 | |
| 862 | #if 0 |
| 863 | /* XXX: need to figure out how to handle this properly */ |
| 864 | tmp = RREG32_SMC(CG_THERMAL_CTRL); |
| 865 | tmp &= DIG_THERM_DPM_MASK; |
| 866 | tmp |= DIG_THERM_DPM(high_temp / 1000); |
| 867 | WREG32_SMC(CG_THERMAL_CTRL, tmp); |
| 868 | #endif |
| 869 | |
| 870 | return 0; |
| 871 | } |
| 872 | |
| 873 | #if 0 |
| 874 | static int ci_read_smc_soft_register(struct radeon_device *rdev, |
| 875 | u16 reg_offset, u32 *value) |
| 876 | { |
| 877 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 878 | |
| 879 | return ci_read_smc_sram_dword(rdev, |
| 880 | pi->soft_regs_start + reg_offset, |
| 881 | value, pi->sram_end); |
| 882 | } |
| 883 | #endif |
| 884 | |
| 885 | static int ci_write_smc_soft_register(struct radeon_device *rdev, |
| 886 | u16 reg_offset, u32 value) |
| 887 | { |
| 888 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 889 | |
| 890 | return ci_write_smc_sram_dword(rdev, |
| 891 | pi->soft_regs_start + reg_offset, |
| 892 | value, pi->sram_end); |
| 893 | } |
| 894 | |
| 895 | static void ci_init_fps_limits(struct radeon_device *rdev) |
| 896 | { |
| 897 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 898 | SMU7_Discrete_DpmTable *table = &pi->smc_state_table; |
| 899 | |
| 900 | if (pi->caps_fps) { |
| 901 | u16 tmp; |
| 902 | |
| 903 | tmp = 45; |
| 904 | table->FpsHighT = cpu_to_be16(tmp); |
| 905 | |
| 906 | tmp = 30; |
| 907 | table->FpsLowT = cpu_to_be16(tmp); |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | static int ci_update_sclk_t(struct radeon_device *rdev) |
| 912 | { |
| 913 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 914 | int ret = 0; |
| 915 | u32 low_sclk_interrupt_t = 0; |
| 916 | |
| 917 | if (pi->caps_sclk_throttle_low_notification) { |
| 918 | low_sclk_interrupt_t = cpu_to_be32(pi->low_sclk_interrupt_t); |
| 919 | |
| 920 | ret = ci_copy_bytes_to_smc(rdev, |
| 921 | pi->dpm_table_start + |
| 922 | offsetof(SMU7_Discrete_DpmTable, LowSclkInterruptT), |
| 923 | (u8 *)&low_sclk_interrupt_t, |
| 924 | sizeof(u32), pi->sram_end); |
| 925 | |
| 926 | } |
| 927 | |
| 928 | return ret; |
| 929 | } |
| 930 | |
| 931 | static void ci_get_leakage_voltages(struct radeon_device *rdev) |
| 932 | { |
| 933 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 934 | u16 leakage_id, virtual_voltage_id; |
| 935 | u16 vddc, vddci; |
| 936 | int i; |
| 937 | |
| 938 | pi->vddc_leakage.count = 0; |
| 939 | pi->vddci_leakage.count = 0; |
| 940 | |
| 941 | if (radeon_atom_get_leakage_id_from_vbios(rdev, &leakage_id) == 0) { |
| 942 | for (i = 0; i < CISLANDS_MAX_LEAKAGE_COUNT; i++) { |
| 943 | virtual_voltage_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i; |
| 944 | if (radeon_atom_get_leakage_vddc_based_on_leakage_params(rdev, &vddc, &vddci, |
| 945 | virtual_voltage_id, |
| 946 | leakage_id) == 0) { |
| 947 | if (vddc != 0 && vddc != virtual_voltage_id) { |
| 948 | pi->vddc_leakage.actual_voltage[pi->vddc_leakage.count] = vddc; |
| 949 | pi->vddc_leakage.leakage_id[pi->vddc_leakage.count] = virtual_voltage_id; |
| 950 | pi->vddc_leakage.count++; |
| 951 | } |
| 952 | if (vddci != 0 && vddci != virtual_voltage_id) { |
| 953 | pi->vddci_leakage.actual_voltage[pi->vddci_leakage.count] = vddci; |
| 954 | pi->vddci_leakage.leakage_id[pi->vddci_leakage.count] = virtual_voltage_id; |
| 955 | pi->vddci_leakage.count++; |
| 956 | } |
| 957 | } |
| 958 | } |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | static void ci_set_dpm_event_sources(struct radeon_device *rdev, u32 sources) |
| 963 | { |
| 964 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 965 | bool want_thermal_protection; |
| 966 | enum radeon_dpm_event_src dpm_event_src; |
| 967 | u32 tmp; |
| 968 | |
| 969 | switch (sources) { |
| 970 | case 0: |
| 971 | default: |
| 972 | want_thermal_protection = false; |
| 973 | break; |
| 974 | case (1 << RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL): |
| 975 | want_thermal_protection = true; |
| 976 | dpm_event_src = RADEON_DPM_EVENT_SRC_DIGITAL; |
| 977 | break; |
| 978 | case (1 << RADEON_DPM_AUTO_THROTTLE_SRC_EXTERNAL): |
| 979 | want_thermal_protection = true; |
| 980 | dpm_event_src = RADEON_DPM_EVENT_SRC_EXTERNAL; |
| 981 | break; |
| 982 | case ((1 << RADEON_DPM_AUTO_THROTTLE_SRC_EXTERNAL) | |
| 983 | (1 << RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL)): |
| 984 | want_thermal_protection = true; |
| 985 | dpm_event_src = RADEON_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL; |
| 986 | break; |
| 987 | } |
| 988 | |
| 989 | if (want_thermal_protection) { |
| 990 | #if 0 |
| 991 | /* XXX: need to figure out how to handle this properly */ |
| 992 | tmp = RREG32_SMC(CG_THERMAL_CTRL); |
| 993 | tmp &= DPM_EVENT_SRC_MASK; |
| 994 | tmp |= DPM_EVENT_SRC(dpm_event_src); |
| 995 | WREG32_SMC(CG_THERMAL_CTRL, tmp); |
| 996 | #endif |
| 997 | |
| 998 | tmp = RREG32_SMC(GENERAL_PWRMGT); |
| 999 | if (pi->thermal_protection) |
| 1000 | tmp &= ~THERMAL_PROTECTION_DIS; |
| 1001 | else |
| 1002 | tmp |= THERMAL_PROTECTION_DIS; |
| 1003 | WREG32_SMC(GENERAL_PWRMGT, tmp); |
| 1004 | } else { |
| 1005 | tmp = RREG32_SMC(GENERAL_PWRMGT); |
| 1006 | tmp |= THERMAL_PROTECTION_DIS; |
| 1007 | WREG32_SMC(GENERAL_PWRMGT, tmp); |
| 1008 | } |
| 1009 | } |
| 1010 | |
| 1011 | static void ci_enable_auto_throttle_source(struct radeon_device *rdev, |
| 1012 | enum radeon_dpm_auto_throttle_src source, |
| 1013 | bool enable) |
| 1014 | { |
| 1015 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1016 | |
| 1017 | if (enable) { |
| 1018 | if (!(pi->active_auto_throttle_sources & (1 << source))) { |
| 1019 | pi->active_auto_throttle_sources |= 1 << source; |
| 1020 | ci_set_dpm_event_sources(rdev, pi->active_auto_throttle_sources); |
| 1021 | } |
| 1022 | } else { |
| 1023 | if (pi->active_auto_throttle_sources & (1 << source)) { |
| 1024 | pi->active_auto_throttle_sources &= ~(1 << source); |
| 1025 | ci_set_dpm_event_sources(rdev, pi->active_auto_throttle_sources); |
| 1026 | } |
| 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | static void ci_enable_vr_hot_gpio_interrupt(struct radeon_device *rdev) |
| 1031 | { |
| 1032 | if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_REGULATOR_HOT) |
| 1033 | ci_send_msg_to_smc(rdev, PPSMC_MSG_EnableVRHotGPIOInterrupt); |
| 1034 | } |
| 1035 | |
| 1036 | static int ci_unfreeze_sclk_mclk_dpm(struct radeon_device *rdev) |
| 1037 | { |
| 1038 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1039 | PPSMC_Result smc_result; |
| 1040 | |
| 1041 | if (!pi->need_update_smu7_dpm_table) |
| 1042 | return 0; |
| 1043 | |
| 1044 | if ((!pi->sclk_dpm_key_disabled) && |
| 1045 | (pi->need_update_smu7_dpm_table & (DPMTABLE_OD_UPDATE_SCLK | DPMTABLE_UPDATE_SCLK))) { |
| 1046 | smc_result = ci_send_msg_to_smc(rdev, PPSMC_MSG_SCLKDPM_UnfreezeLevel); |
| 1047 | if (smc_result != PPSMC_Result_OK) |
| 1048 | return -EINVAL; |
| 1049 | } |
| 1050 | |
| 1051 | if ((!pi->mclk_dpm_key_disabled) && |
| 1052 | (pi->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) { |
| 1053 | smc_result = ci_send_msg_to_smc(rdev, PPSMC_MSG_MCLKDPM_UnfreezeLevel); |
| 1054 | if (smc_result != PPSMC_Result_OK) |
| 1055 | return -EINVAL; |
| 1056 | } |
| 1057 | |
| 1058 | pi->need_update_smu7_dpm_table = 0; |
| 1059 | return 0; |
| 1060 | } |
| 1061 | |
| 1062 | static int ci_enable_sclk_mclk_dpm(struct radeon_device *rdev, bool enable) |
| 1063 | { |
| 1064 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1065 | PPSMC_Result smc_result; |
| 1066 | |
| 1067 | if (enable) { |
| 1068 | if (!pi->sclk_dpm_key_disabled) { |
| 1069 | smc_result = ci_send_msg_to_smc(rdev, PPSMC_MSG_DPM_Enable); |
| 1070 | if (smc_result != PPSMC_Result_OK) |
| 1071 | return -EINVAL; |
| 1072 | } |
| 1073 | |
| 1074 | if (!pi->mclk_dpm_key_disabled) { |
| 1075 | smc_result = ci_send_msg_to_smc(rdev, PPSMC_MSG_MCLKDPM_Enable); |
| 1076 | if (smc_result != PPSMC_Result_OK) |
| 1077 | return -EINVAL; |
| 1078 | |
| 1079 | WREG32_P(MC_SEQ_CNTL_3, CAC_EN, ~CAC_EN); |
| 1080 | |
| 1081 | WREG32_SMC(LCAC_MC0_CNTL, 0x05); |
| 1082 | WREG32_SMC(LCAC_MC1_CNTL, 0x05); |
| 1083 | WREG32_SMC(LCAC_CPL_CNTL, 0x100005); |
| 1084 | |
| 1085 | udelay(10); |
| 1086 | |
| 1087 | WREG32_SMC(LCAC_MC0_CNTL, 0x400005); |
| 1088 | WREG32_SMC(LCAC_MC1_CNTL, 0x400005); |
| 1089 | WREG32_SMC(LCAC_CPL_CNTL, 0x500005); |
| 1090 | } |
| 1091 | } else { |
| 1092 | if (!pi->sclk_dpm_key_disabled) { |
| 1093 | smc_result = ci_send_msg_to_smc(rdev, PPSMC_MSG_DPM_Disable); |
| 1094 | if (smc_result != PPSMC_Result_OK) |
| 1095 | return -EINVAL; |
| 1096 | } |
| 1097 | |
| 1098 | if (!pi->mclk_dpm_key_disabled) { |
| 1099 | smc_result = ci_send_msg_to_smc(rdev, PPSMC_MSG_MCLKDPM_Disable); |
| 1100 | if (smc_result != PPSMC_Result_OK) |
| 1101 | return -EINVAL; |
| 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | return 0; |
| 1106 | } |
| 1107 | |
| 1108 | static int ci_start_dpm(struct radeon_device *rdev) |
| 1109 | { |
| 1110 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1111 | PPSMC_Result smc_result; |
| 1112 | int ret; |
| 1113 | u32 tmp; |
| 1114 | |
| 1115 | tmp = RREG32_SMC(GENERAL_PWRMGT); |
| 1116 | tmp |= GLOBAL_PWRMGT_EN; |
| 1117 | WREG32_SMC(GENERAL_PWRMGT, tmp); |
| 1118 | |
| 1119 | tmp = RREG32_SMC(SCLK_PWRMGT_CNTL); |
| 1120 | tmp |= DYNAMIC_PM_EN; |
| 1121 | WREG32_SMC(SCLK_PWRMGT_CNTL, tmp); |
| 1122 | |
| 1123 | ci_write_smc_soft_register(rdev, offsetof(SMU7_SoftRegisters, VoltageChangeTimeout), 0x1000); |
| 1124 | |
| 1125 | WREG32_P(BIF_LNCNT_RESET, 0, ~RESET_LNCNT_EN); |
| 1126 | |
| 1127 | smc_result = ci_send_msg_to_smc(rdev, PPSMC_MSG_Voltage_Cntl_Enable); |
| 1128 | if (smc_result != PPSMC_Result_OK) |
| 1129 | return -EINVAL; |
| 1130 | |
| 1131 | ret = ci_enable_sclk_mclk_dpm(rdev, true); |
| 1132 | if (ret) |
| 1133 | return ret; |
| 1134 | |
| 1135 | if (!pi->pcie_dpm_key_disabled) { |
| 1136 | smc_result = ci_send_msg_to_smc(rdev, PPSMC_MSG_PCIeDPM_Enable); |
| 1137 | if (smc_result != PPSMC_Result_OK) |
| 1138 | return -EINVAL; |
| 1139 | } |
| 1140 | |
| 1141 | return 0; |
| 1142 | } |
| 1143 | |
| 1144 | static int ci_freeze_sclk_mclk_dpm(struct radeon_device *rdev) |
| 1145 | { |
| 1146 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1147 | PPSMC_Result smc_result; |
| 1148 | |
| 1149 | if (!pi->need_update_smu7_dpm_table) |
| 1150 | return 0; |
| 1151 | |
| 1152 | if ((!pi->sclk_dpm_key_disabled) && |
| 1153 | (pi->need_update_smu7_dpm_table & (DPMTABLE_OD_UPDATE_SCLK | DPMTABLE_UPDATE_SCLK))) { |
| 1154 | smc_result = ci_send_msg_to_smc(rdev, PPSMC_MSG_SCLKDPM_FreezeLevel); |
| 1155 | if (smc_result != PPSMC_Result_OK) |
| 1156 | return -EINVAL; |
| 1157 | } |
| 1158 | |
| 1159 | if ((!pi->mclk_dpm_key_disabled) && |
| 1160 | (pi->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) { |
| 1161 | smc_result = ci_send_msg_to_smc(rdev, PPSMC_MSG_MCLKDPM_FreezeLevel); |
| 1162 | if (smc_result != PPSMC_Result_OK) |
| 1163 | return -EINVAL; |
| 1164 | } |
| 1165 | |
| 1166 | return 0; |
| 1167 | } |
| 1168 | |
| 1169 | static int ci_stop_dpm(struct radeon_device *rdev) |
| 1170 | { |
| 1171 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1172 | PPSMC_Result smc_result; |
| 1173 | int ret; |
| 1174 | u32 tmp; |
| 1175 | |
| 1176 | tmp = RREG32_SMC(GENERAL_PWRMGT); |
| 1177 | tmp &= ~GLOBAL_PWRMGT_EN; |
| 1178 | WREG32_SMC(GENERAL_PWRMGT, tmp); |
| 1179 | |
| 1180 | tmp = RREG32(SCLK_PWRMGT_CNTL); |
| 1181 | tmp &= ~DYNAMIC_PM_EN; |
| 1182 | WREG32_SMC(SCLK_PWRMGT_CNTL, tmp); |
| 1183 | |
| 1184 | if (!pi->pcie_dpm_key_disabled) { |
| 1185 | smc_result = ci_send_msg_to_smc(rdev, PPSMC_MSG_PCIeDPM_Disable); |
| 1186 | if (smc_result != PPSMC_Result_OK) |
| 1187 | return -EINVAL; |
| 1188 | } |
| 1189 | |
| 1190 | ret = ci_enable_sclk_mclk_dpm(rdev, false); |
| 1191 | if (ret) |
| 1192 | return ret; |
| 1193 | |
| 1194 | smc_result = ci_send_msg_to_smc(rdev, PPSMC_MSG_Voltage_Cntl_Disable); |
| 1195 | if (smc_result != PPSMC_Result_OK) |
| 1196 | return -EINVAL; |
| 1197 | |
| 1198 | return 0; |
| 1199 | } |
| 1200 | |
| 1201 | static void ci_enable_sclk_control(struct radeon_device *rdev, bool enable) |
| 1202 | { |
| 1203 | u32 tmp = RREG32_SMC(SCLK_PWRMGT_CNTL); |
| 1204 | |
| 1205 | if (enable) |
| 1206 | tmp &= ~SCLK_PWRMGT_OFF; |
| 1207 | else |
| 1208 | tmp |= SCLK_PWRMGT_OFF; |
| 1209 | WREG32_SMC(SCLK_PWRMGT_CNTL, tmp); |
| 1210 | } |
| 1211 | |
| 1212 | #if 0 |
| 1213 | static int ci_notify_hw_of_power_source(struct radeon_device *rdev, |
| 1214 | bool ac_power) |
| 1215 | { |
| 1216 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1217 | struct radeon_cac_tdp_table *cac_tdp_table = |
| 1218 | rdev->pm.dpm.dyn_state.cac_tdp_table; |
| 1219 | u32 power_limit; |
| 1220 | |
| 1221 | if (ac_power) |
| 1222 | power_limit = (u32)(cac_tdp_table->maximum_power_delivery_limit * 256); |
| 1223 | else |
| 1224 | power_limit = (u32)(cac_tdp_table->battery_power_limit * 256); |
| 1225 | |
| 1226 | ci_set_power_limit(rdev, power_limit); |
| 1227 | |
| 1228 | if (pi->caps_automatic_dc_transition) { |
| 1229 | if (ac_power) |
| 1230 | ci_send_msg_to_smc(rdev, PPSMC_MSG_RunningOnAC); |
| 1231 | else |
| 1232 | ci_send_msg_to_smc(rdev, PPSMC_MSG_Remove_DC_Clamp); |
| 1233 | } |
| 1234 | |
| 1235 | return 0; |
| 1236 | } |
| 1237 | #endif |
| 1238 | |
| 1239 | static PPSMC_Result ci_send_msg_to_smc_with_parameter(struct radeon_device *rdev, |
| 1240 | PPSMC_Msg msg, u32 parameter) |
| 1241 | { |
| 1242 | WREG32(SMC_MSG_ARG_0, parameter); |
| 1243 | return ci_send_msg_to_smc(rdev, msg); |
| 1244 | } |
| 1245 | |
| 1246 | static PPSMC_Result ci_send_msg_to_smc_return_parameter(struct radeon_device *rdev, |
| 1247 | PPSMC_Msg msg, u32 *parameter) |
| 1248 | { |
| 1249 | PPSMC_Result smc_result; |
| 1250 | |
| 1251 | smc_result = ci_send_msg_to_smc(rdev, msg); |
| 1252 | |
| 1253 | if ((smc_result == PPSMC_Result_OK) && parameter) |
| 1254 | *parameter = RREG32(SMC_MSG_ARG_0); |
| 1255 | |
| 1256 | return smc_result; |
| 1257 | } |
| 1258 | |
| 1259 | static int ci_dpm_force_state_sclk(struct radeon_device *rdev, u32 n) |
| 1260 | { |
| 1261 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1262 | |
| 1263 | if (!pi->sclk_dpm_key_disabled) { |
| 1264 | PPSMC_Result smc_result = |
| 1265 | ci_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_DPM_ForceState, n); |
| 1266 | if (smc_result != PPSMC_Result_OK) |
| 1267 | return -EINVAL; |
| 1268 | } |
| 1269 | |
| 1270 | return 0; |
| 1271 | } |
| 1272 | |
| 1273 | static int ci_dpm_force_state_mclk(struct radeon_device *rdev, u32 n) |
| 1274 | { |
| 1275 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1276 | |
| 1277 | if (!pi->mclk_dpm_key_disabled) { |
| 1278 | PPSMC_Result smc_result = |
| 1279 | ci_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_MCLKDPM_ForceState, n); |
| 1280 | if (smc_result != PPSMC_Result_OK) |
| 1281 | return -EINVAL; |
| 1282 | } |
| 1283 | |
| 1284 | return 0; |
| 1285 | } |
| 1286 | |
| 1287 | static int ci_dpm_force_state_pcie(struct radeon_device *rdev, u32 n) |
| 1288 | { |
| 1289 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1290 | |
| 1291 | if (!pi->pcie_dpm_key_disabled) { |
| 1292 | PPSMC_Result smc_result = |
| 1293 | ci_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_PCIeDPM_ForceLevel, n); |
| 1294 | if (smc_result != PPSMC_Result_OK) |
| 1295 | return -EINVAL; |
| 1296 | } |
| 1297 | |
| 1298 | return 0; |
| 1299 | } |
| 1300 | |
| 1301 | static int ci_set_power_limit(struct radeon_device *rdev, u32 n) |
| 1302 | { |
| 1303 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1304 | |
| 1305 | if (pi->power_containment_features & POWERCONTAINMENT_FEATURE_PkgPwrLimit) { |
| 1306 | PPSMC_Result smc_result = |
| 1307 | ci_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_PkgPwrSetLimit, n); |
| 1308 | if (smc_result != PPSMC_Result_OK) |
| 1309 | return -EINVAL; |
| 1310 | } |
| 1311 | |
| 1312 | return 0; |
| 1313 | } |
| 1314 | |
| 1315 | static int ci_set_overdrive_target_tdp(struct radeon_device *rdev, |
| 1316 | u32 target_tdp) |
| 1317 | { |
| 1318 | PPSMC_Result smc_result = |
| 1319 | ci_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_OverDriveSetTargetTdp, target_tdp); |
| 1320 | if (smc_result != PPSMC_Result_OK) |
| 1321 | return -EINVAL; |
| 1322 | return 0; |
| 1323 | } |
| 1324 | |
| 1325 | static int ci_set_boot_state(struct radeon_device *rdev) |
| 1326 | { |
| 1327 | return ci_enable_sclk_mclk_dpm(rdev, false); |
| 1328 | } |
| 1329 | |
| 1330 | static u32 ci_get_average_sclk_freq(struct radeon_device *rdev) |
| 1331 | { |
| 1332 | u32 sclk_freq; |
| 1333 | PPSMC_Result smc_result = |
| 1334 | ci_send_msg_to_smc_return_parameter(rdev, |
| 1335 | PPSMC_MSG_API_GetSclkFrequency, |
| 1336 | &sclk_freq); |
| 1337 | if (smc_result != PPSMC_Result_OK) |
| 1338 | sclk_freq = 0; |
| 1339 | |
| 1340 | return sclk_freq; |
| 1341 | } |
| 1342 | |
| 1343 | static u32 ci_get_average_mclk_freq(struct radeon_device *rdev) |
| 1344 | { |
| 1345 | u32 mclk_freq; |
| 1346 | PPSMC_Result smc_result = |
| 1347 | ci_send_msg_to_smc_return_parameter(rdev, |
| 1348 | PPSMC_MSG_API_GetMclkFrequency, |
| 1349 | &mclk_freq); |
| 1350 | if (smc_result != PPSMC_Result_OK) |
| 1351 | mclk_freq = 0; |
| 1352 | |
| 1353 | return mclk_freq; |
| 1354 | } |
| 1355 | |
| 1356 | static void ci_dpm_start_smc(struct radeon_device *rdev) |
| 1357 | { |
| 1358 | int i; |
| 1359 | |
| 1360 | ci_program_jump_on_start(rdev); |
| 1361 | ci_start_smc_clock(rdev); |
| 1362 | ci_start_smc(rdev); |
| 1363 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 1364 | if (RREG32_SMC(FIRMWARE_FLAGS) & INTERRUPTS_ENABLED) |
| 1365 | break; |
| 1366 | } |
| 1367 | } |
| 1368 | |
| 1369 | static void ci_dpm_stop_smc(struct radeon_device *rdev) |
| 1370 | { |
| 1371 | ci_reset_smc(rdev); |
| 1372 | ci_stop_smc_clock(rdev); |
| 1373 | } |
| 1374 | |
| 1375 | static int ci_process_firmware_header(struct radeon_device *rdev) |
| 1376 | { |
| 1377 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1378 | u32 tmp; |
| 1379 | int ret; |
| 1380 | |
| 1381 | ret = ci_read_smc_sram_dword(rdev, |
| 1382 | SMU7_FIRMWARE_HEADER_LOCATION + |
| 1383 | offsetof(SMU7_Firmware_Header, DpmTable), |
| 1384 | &tmp, pi->sram_end); |
| 1385 | if (ret) |
| 1386 | return ret; |
| 1387 | |
| 1388 | pi->dpm_table_start = tmp; |
| 1389 | |
| 1390 | ret = ci_read_smc_sram_dword(rdev, |
| 1391 | SMU7_FIRMWARE_HEADER_LOCATION + |
| 1392 | offsetof(SMU7_Firmware_Header, SoftRegisters), |
| 1393 | &tmp, pi->sram_end); |
| 1394 | if (ret) |
| 1395 | return ret; |
| 1396 | |
| 1397 | pi->soft_regs_start = tmp; |
| 1398 | |
| 1399 | ret = ci_read_smc_sram_dword(rdev, |
| 1400 | SMU7_FIRMWARE_HEADER_LOCATION + |
| 1401 | offsetof(SMU7_Firmware_Header, mcRegisterTable), |
| 1402 | &tmp, pi->sram_end); |
| 1403 | if (ret) |
| 1404 | return ret; |
| 1405 | |
| 1406 | pi->mc_reg_table_start = tmp; |
| 1407 | |
| 1408 | ret = ci_read_smc_sram_dword(rdev, |
| 1409 | SMU7_FIRMWARE_HEADER_LOCATION + |
| 1410 | offsetof(SMU7_Firmware_Header, FanTable), |
| 1411 | &tmp, pi->sram_end); |
| 1412 | if (ret) |
| 1413 | return ret; |
| 1414 | |
| 1415 | pi->fan_table_start = tmp; |
| 1416 | |
| 1417 | ret = ci_read_smc_sram_dword(rdev, |
| 1418 | SMU7_FIRMWARE_HEADER_LOCATION + |
| 1419 | offsetof(SMU7_Firmware_Header, mcArbDramTimingTable), |
| 1420 | &tmp, pi->sram_end); |
| 1421 | if (ret) |
| 1422 | return ret; |
| 1423 | |
| 1424 | pi->arb_table_start = tmp; |
| 1425 | |
| 1426 | return 0; |
| 1427 | } |
| 1428 | |
| 1429 | static void ci_read_clock_registers(struct radeon_device *rdev) |
| 1430 | { |
| 1431 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1432 | |
| 1433 | pi->clock_registers.cg_spll_func_cntl = |
| 1434 | RREG32_SMC(CG_SPLL_FUNC_CNTL); |
| 1435 | pi->clock_registers.cg_spll_func_cntl_2 = |
| 1436 | RREG32_SMC(CG_SPLL_FUNC_CNTL_2); |
| 1437 | pi->clock_registers.cg_spll_func_cntl_3 = |
| 1438 | RREG32_SMC(CG_SPLL_FUNC_CNTL_3); |
| 1439 | pi->clock_registers.cg_spll_func_cntl_4 = |
| 1440 | RREG32_SMC(CG_SPLL_FUNC_CNTL_4); |
| 1441 | pi->clock_registers.cg_spll_spread_spectrum = |
| 1442 | RREG32_SMC(CG_SPLL_SPREAD_SPECTRUM); |
| 1443 | pi->clock_registers.cg_spll_spread_spectrum_2 = |
| 1444 | RREG32_SMC(CG_SPLL_SPREAD_SPECTRUM_2); |
| 1445 | pi->clock_registers.dll_cntl = RREG32(DLL_CNTL); |
| 1446 | pi->clock_registers.mclk_pwrmgt_cntl = RREG32(MCLK_PWRMGT_CNTL); |
| 1447 | pi->clock_registers.mpll_ad_func_cntl = RREG32(MPLL_AD_FUNC_CNTL); |
| 1448 | pi->clock_registers.mpll_dq_func_cntl = RREG32(MPLL_DQ_FUNC_CNTL); |
| 1449 | pi->clock_registers.mpll_func_cntl = RREG32(MPLL_FUNC_CNTL); |
| 1450 | pi->clock_registers.mpll_func_cntl_1 = RREG32(MPLL_FUNC_CNTL_1); |
| 1451 | pi->clock_registers.mpll_func_cntl_2 = RREG32(MPLL_FUNC_CNTL_2); |
| 1452 | pi->clock_registers.mpll_ss1 = RREG32(MPLL_SS1); |
| 1453 | pi->clock_registers.mpll_ss2 = RREG32(MPLL_SS2); |
| 1454 | } |
| 1455 | |
| 1456 | static void ci_init_sclk_t(struct radeon_device *rdev) |
| 1457 | { |
| 1458 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1459 | |
| 1460 | pi->low_sclk_interrupt_t = 0; |
| 1461 | } |
| 1462 | |
| 1463 | static void ci_enable_thermal_protection(struct radeon_device *rdev, |
| 1464 | bool enable) |
| 1465 | { |
| 1466 | u32 tmp = RREG32_SMC(GENERAL_PWRMGT); |
| 1467 | |
| 1468 | if (enable) |
| 1469 | tmp &= ~THERMAL_PROTECTION_DIS; |
| 1470 | else |
| 1471 | tmp |= THERMAL_PROTECTION_DIS; |
| 1472 | WREG32_SMC(GENERAL_PWRMGT, tmp); |
| 1473 | } |
| 1474 | |
| 1475 | static void ci_enable_acpi_power_management(struct radeon_device *rdev) |
| 1476 | { |
| 1477 | u32 tmp = RREG32_SMC(GENERAL_PWRMGT); |
| 1478 | |
| 1479 | tmp |= STATIC_PM_EN; |
| 1480 | |
| 1481 | WREG32_SMC(GENERAL_PWRMGT, tmp); |
| 1482 | } |
| 1483 | |
| 1484 | #if 0 |
| 1485 | static int ci_enter_ulp_state(struct radeon_device *rdev) |
| 1486 | { |
| 1487 | |
| 1488 | WREG32(SMC_MESSAGE_0, PPSMC_MSG_SwitchToMinimumPower); |
| 1489 | |
| 1490 | udelay(25000); |
| 1491 | |
| 1492 | return 0; |
| 1493 | } |
| 1494 | |
| 1495 | static int ci_exit_ulp_state(struct radeon_device *rdev) |
| 1496 | { |
| 1497 | int i; |
| 1498 | |
| 1499 | WREG32(SMC_MESSAGE_0, PPSMC_MSG_ResumeFromMinimumPower); |
| 1500 | |
| 1501 | udelay(7000); |
| 1502 | |
| 1503 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 1504 | if (RREG32(SMC_RESP_0) == 1) |
| 1505 | break; |
| 1506 | udelay(1000); |
| 1507 | } |
| 1508 | |
| 1509 | return 0; |
| 1510 | } |
| 1511 | #endif |
| 1512 | |
| 1513 | static int ci_notify_smc_display_change(struct radeon_device *rdev, |
| 1514 | bool has_display) |
| 1515 | { |
| 1516 | PPSMC_Msg msg = has_display ? PPSMC_MSG_HasDisplay : PPSMC_MSG_NoDisplay; |
| 1517 | |
| 1518 | return (ci_send_msg_to_smc(rdev, msg) == PPSMC_Result_OK) ? 0 : -EINVAL; |
| 1519 | } |
| 1520 | |
| 1521 | static int ci_enable_ds_master_switch(struct radeon_device *rdev, |
| 1522 | bool enable) |
| 1523 | { |
| 1524 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1525 | |
| 1526 | if (enable) { |
| 1527 | if (pi->caps_sclk_ds) { |
| 1528 | if (ci_send_msg_to_smc(rdev, PPSMC_MSG_MASTER_DeepSleep_ON) != PPSMC_Result_OK) |
| 1529 | return -EINVAL; |
| 1530 | } else { |
| 1531 | if (ci_send_msg_to_smc(rdev, PPSMC_MSG_MASTER_DeepSleep_OFF) != PPSMC_Result_OK) |
| 1532 | return -EINVAL; |
| 1533 | } |
| 1534 | } else { |
| 1535 | if (pi->caps_sclk_ds) { |
| 1536 | if (ci_send_msg_to_smc(rdev, PPSMC_MSG_MASTER_DeepSleep_OFF) != PPSMC_Result_OK) |
| 1537 | return -EINVAL; |
| 1538 | } |
| 1539 | } |
| 1540 | |
| 1541 | return 0; |
| 1542 | } |
| 1543 | |
| 1544 | static void ci_program_display_gap(struct radeon_device *rdev) |
| 1545 | { |
| 1546 | u32 tmp = RREG32_SMC(CG_DISPLAY_GAP_CNTL); |
| 1547 | u32 pre_vbi_time_in_us; |
| 1548 | u32 frame_time_in_us; |
| 1549 | u32 ref_clock = rdev->clock.spll.reference_freq; |
| 1550 | u32 refresh_rate = r600_dpm_get_vrefresh(rdev); |
| 1551 | u32 vblank_time = r600_dpm_get_vblank_time(rdev); |
| 1552 | |
| 1553 | tmp &= ~DISP_GAP_MASK; |
| 1554 | if (rdev->pm.dpm.new_active_crtc_count > 0) |
| 1555 | tmp |= DISP_GAP(R600_PM_DISPLAY_GAP_VBLANK_OR_WM); |
| 1556 | else |
| 1557 | tmp |= DISP_GAP(R600_PM_DISPLAY_GAP_IGNORE); |
| 1558 | WREG32_SMC(CG_DISPLAY_GAP_CNTL, tmp); |
| 1559 | |
| 1560 | if (refresh_rate == 0) |
| 1561 | refresh_rate = 60; |
| 1562 | if (vblank_time == 0xffffffff) |
| 1563 | vblank_time = 500; |
| 1564 | frame_time_in_us = 1000000 / refresh_rate; |
| 1565 | pre_vbi_time_in_us = |
| 1566 | frame_time_in_us - 200 - vblank_time; |
| 1567 | tmp = pre_vbi_time_in_us * (ref_clock / 100); |
| 1568 | |
| 1569 | WREG32_SMC(CG_DISPLAY_GAP_CNTL2, tmp); |
| 1570 | ci_write_smc_soft_register(rdev, offsetof(SMU7_SoftRegisters, PreVBlankGap), 0x64); |
| 1571 | ci_write_smc_soft_register(rdev, offsetof(SMU7_SoftRegisters, VBlankTimeout), (frame_time_in_us - pre_vbi_time_in_us)); |
| 1572 | |
| 1573 | |
| 1574 | ci_notify_smc_display_change(rdev, (rdev->pm.dpm.new_active_crtc_count == 1)); |
| 1575 | |
| 1576 | } |
| 1577 | |
| 1578 | static void ci_enable_spread_spectrum(struct radeon_device *rdev, bool enable) |
| 1579 | { |
| 1580 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1581 | u32 tmp; |
| 1582 | |
| 1583 | if (enable) { |
| 1584 | if (pi->caps_sclk_ss_support) { |
| 1585 | tmp = RREG32_SMC(GENERAL_PWRMGT); |
| 1586 | tmp |= DYN_SPREAD_SPECTRUM_EN; |
| 1587 | WREG32_SMC(GENERAL_PWRMGT, tmp); |
| 1588 | } |
| 1589 | } else { |
| 1590 | tmp = RREG32_SMC(CG_SPLL_SPREAD_SPECTRUM); |
| 1591 | tmp &= ~SSEN; |
| 1592 | WREG32_SMC(CG_SPLL_SPREAD_SPECTRUM, tmp); |
| 1593 | |
| 1594 | tmp = RREG32_SMC(GENERAL_PWRMGT); |
| 1595 | tmp &= ~DYN_SPREAD_SPECTRUM_EN; |
| 1596 | WREG32_SMC(GENERAL_PWRMGT, tmp); |
| 1597 | } |
| 1598 | } |
| 1599 | |
| 1600 | static void ci_program_sstp(struct radeon_device *rdev) |
| 1601 | { |
| 1602 | WREG32_SMC(CG_SSP, (SSTU(R600_SSTU_DFLT) | SST(R600_SST_DFLT))); |
| 1603 | } |
| 1604 | |
| 1605 | static void ci_enable_display_gap(struct radeon_device *rdev) |
| 1606 | { |
| 1607 | u32 tmp = RREG32_SMC(CG_DISPLAY_GAP_CNTL); |
| 1608 | |
| 1609 | tmp &= ~(DISP_GAP_MASK | DISP_GAP_MCHG_MASK); |
| 1610 | tmp |= (DISP_GAP(R600_PM_DISPLAY_GAP_IGNORE) | |
| 1611 | DISP_GAP_MCHG(R600_PM_DISPLAY_GAP_VBLANK)); |
| 1612 | |
| 1613 | WREG32_SMC(CG_DISPLAY_GAP_CNTL, tmp); |
| 1614 | } |
| 1615 | |
| 1616 | static void ci_program_vc(struct radeon_device *rdev) |
| 1617 | { |
| 1618 | u32 tmp; |
| 1619 | |
| 1620 | tmp = RREG32_SMC(SCLK_PWRMGT_CNTL); |
| 1621 | tmp &= ~(RESET_SCLK_CNT | RESET_BUSY_CNT); |
| 1622 | WREG32_SMC(SCLK_PWRMGT_CNTL, tmp); |
| 1623 | |
| 1624 | WREG32_SMC(CG_FTV_0, CISLANDS_VRC_DFLT0); |
| 1625 | WREG32_SMC(CG_FTV_1, CISLANDS_VRC_DFLT1); |
| 1626 | WREG32_SMC(CG_FTV_2, CISLANDS_VRC_DFLT2); |
| 1627 | WREG32_SMC(CG_FTV_3, CISLANDS_VRC_DFLT3); |
| 1628 | WREG32_SMC(CG_FTV_4, CISLANDS_VRC_DFLT4); |
| 1629 | WREG32_SMC(CG_FTV_5, CISLANDS_VRC_DFLT5); |
| 1630 | WREG32_SMC(CG_FTV_6, CISLANDS_VRC_DFLT6); |
| 1631 | WREG32_SMC(CG_FTV_7, CISLANDS_VRC_DFLT7); |
| 1632 | } |
| 1633 | |
| 1634 | static void ci_clear_vc(struct radeon_device *rdev) |
| 1635 | { |
| 1636 | u32 tmp; |
| 1637 | |
| 1638 | tmp = RREG32_SMC(SCLK_PWRMGT_CNTL); |
| 1639 | tmp |= (RESET_SCLK_CNT | RESET_BUSY_CNT); |
| 1640 | WREG32_SMC(SCLK_PWRMGT_CNTL, tmp); |
| 1641 | |
| 1642 | WREG32_SMC(CG_FTV_0, 0); |
| 1643 | WREG32_SMC(CG_FTV_1, 0); |
| 1644 | WREG32_SMC(CG_FTV_2, 0); |
| 1645 | WREG32_SMC(CG_FTV_3, 0); |
| 1646 | WREG32_SMC(CG_FTV_4, 0); |
| 1647 | WREG32_SMC(CG_FTV_5, 0); |
| 1648 | WREG32_SMC(CG_FTV_6, 0); |
| 1649 | WREG32_SMC(CG_FTV_7, 0); |
| 1650 | } |
| 1651 | |
| 1652 | static int ci_upload_firmware(struct radeon_device *rdev) |
| 1653 | { |
| 1654 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1655 | int i, ret; |
| 1656 | |
| 1657 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 1658 | if (RREG32_SMC(RCU_UC_EVENTS) & BOOT_SEQ_DONE) |
| 1659 | break; |
| 1660 | } |
| 1661 | WREG32_SMC(SMC_SYSCON_MISC_CNTL, 1); |
| 1662 | |
| 1663 | ci_stop_smc_clock(rdev); |
| 1664 | ci_reset_smc(rdev); |
| 1665 | |
| 1666 | ret = ci_load_smc_ucode(rdev, pi->sram_end); |
| 1667 | |
| 1668 | return ret; |
| 1669 | |
| 1670 | } |
| 1671 | |
| 1672 | static int ci_get_svi2_voltage_table(struct radeon_device *rdev, |
| 1673 | struct radeon_clock_voltage_dependency_table *voltage_dependency_table, |
| 1674 | struct atom_voltage_table *voltage_table) |
| 1675 | { |
| 1676 | u32 i; |
| 1677 | |
| 1678 | if (voltage_dependency_table == NULL) |
| 1679 | return -EINVAL; |
| 1680 | |
| 1681 | voltage_table->mask_low = 0; |
| 1682 | voltage_table->phase_delay = 0; |
| 1683 | |
| 1684 | voltage_table->count = voltage_dependency_table->count; |
| 1685 | for (i = 0; i < voltage_table->count; i++) { |
| 1686 | voltage_table->entries[i].value = voltage_dependency_table->entries[i].v; |
| 1687 | voltage_table->entries[i].smio_low = 0; |
| 1688 | } |
| 1689 | |
| 1690 | return 0; |
| 1691 | } |
| 1692 | |
| 1693 | static int ci_construct_voltage_tables(struct radeon_device *rdev) |
| 1694 | { |
| 1695 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1696 | int ret; |
| 1697 | |
| 1698 | if (pi->voltage_control == CISLANDS_VOLTAGE_CONTROL_BY_GPIO) { |
| 1699 | ret = radeon_atom_get_voltage_table(rdev, VOLTAGE_TYPE_VDDC, |
| 1700 | VOLTAGE_OBJ_GPIO_LUT, |
| 1701 | &pi->vddc_voltage_table); |
| 1702 | if (ret) |
| 1703 | return ret; |
| 1704 | } else if (pi->voltage_control == CISLANDS_VOLTAGE_CONTROL_BY_SVID2) { |
| 1705 | ret = ci_get_svi2_voltage_table(rdev, |
| 1706 | &rdev->pm.dpm.dyn_state.vddc_dependency_on_mclk, |
| 1707 | &pi->vddc_voltage_table); |
| 1708 | if (ret) |
| 1709 | return ret; |
| 1710 | } |
| 1711 | |
| 1712 | if (pi->vddc_voltage_table.count > SMU7_MAX_LEVELS_VDDC) |
| 1713 | si_trim_voltage_table_to_fit_state_table(rdev, SMU7_MAX_LEVELS_VDDC, |
| 1714 | &pi->vddc_voltage_table); |
| 1715 | |
| 1716 | if (pi->vddci_control == CISLANDS_VOLTAGE_CONTROL_BY_GPIO) { |
| 1717 | ret = radeon_atom_get_voltage_table(rdev, VOLTAGE_TYPE_VDDCI, |
| 1718 | VOLTAGE_OBJ_GPIO_LUT, |
| 1719 | &pi->vddci_voltage_table); |
| 1720 | if (ret) |
| 1721 | return ret; |
| 1722 | } else if (pi->vddci_control == CISLANDS_VOLTAGE_CONTROL_BY_SVID2) { |
| 1723 | ret = ci_get_svi2_voltage_table(rdev, |
| 1724 | &rdev->pm.dpm.dyn_state.vddci_dependency_on_mclk, |
| 1725 | &pi->vddci_voltage_table); |
| 1726 | if (ret) |
| 1727 | return ret; |
| 1728 | } |
| 1729 | |
| 1730 | if (pi->vddci_voltage_table.count > SMU7_MAX_LEVELS_VDDCI) |
| 1731 | si_trim_voltage_table_to_fit_state_table(rdev, SMU7_MAX_LEVELS_VDDCI, |
| 1732 | &pi->vddci_voltage_table); |
| 1733 | |
| 1734 | if (pi->mvdd_control == CISLANDS_VOLTAGE_CONTROL_BY_GPIO) { |
| 1735 | ret = radeon_atom_get_voltage_table(rdev, VOLTAGE_TYPE_MVDDC, |
| 1736 | VOLTAGE_OBJ_GPIO_LUT, |
| 1737 | &pi->mvdd_voltage_table); |
| 1738 | if (ret) |
| 1739 | return ret; |
| 1740 | } else if (pi->mvdd_control == CISLANDS_VOLTAGE_CONTROL_BY_SVID2) { |
| 1741 | ret = ci_get_svi2_voltage_table(rdev, |
| 1742 | &rdev->pm.dpm.dyn_state.mvdd_dependency_on_mclk, |
| 1743 | &pi->mvdd_voltage_table); |
| 1744 | if (ret) |
| 1745 | return ret; |
| 1746 | } |
| 1747 | |
| 1748 | if (pi->mvdd_voltage_table.count > SMU7_MAX_LEVELS_MVDD) |
| 1749 | si_trim_voltage_table_to_fit_state_table(rdev, SMU7_MAX_LEVELS_MVDD, |
| 1750 | &pi->mvdd_voltage_table); |
| 1751 | |
| 1752 | return 0; |
| 1753 | } |
| 1754 | |
| 1755 | static void ci_populate_smc_voltage_table(struct radeon_device *rdev, |
| 1756 | struct atom_voltage_table_entry *voltage_table, |
| 1757 | SMU7_Discrete_VoltageLevel *smc_voltage_table) |
| 1758 | { |
| 1759 | int ret; |
| 1760 | |
| 1761 | ret = ci_get_std_voltage_value_sidd(rdev, voltage_table, |
| 1762 | &smc_voltage_table->StdVoltageHiSidd, |
| 1763 | &smc_voltage_table->StdVoltageLoSidd); |
| 1764 | |
| 1765 | if (ret) { |
| 1766 | smc_voltage_table->StdVoltageHiSidd = voltage_table->value * VOLTAGE_SCALE; |
| 1767 | smc_voltage_table->StdVoltageLoSidd = voltage_table->value * VOLTAGE_SCALE; |
| 1768 | } |
| 1769 | |
| 1770 | smc_voltage_table->Voltage = cpu_to_be16(voltage_table->value * VOLTAGE_SCALE); |
| 1771 | smc_voltage_table->StdVoltageHiSidd = |
| 1772 | cpu_to_be16(smc_voltage_table->StdVoltageHiSidd); |
| 1773 | smc_voltage_table->StdVoltageLoSidd = |
| 1774 | cpu_to_be16(smc_voltage_table->StdVoltageLoSidd); |
| 1775 | } |
| 1776 | |
| 1777 | static int ci_populate_smc_vddc_table(struct radeon_device *rdev, |
| 1778 | SMU7_Discrete_DpmTable *table) |
| 1779 | { |
| 1780 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1781 | unsigned int count; |
| 1782 | |
| 1783 | table->VddcLevelCount = pi->vddc_voltage_table.count; |
| 1784 | for (count = 0; count < table->VddcLevelCount; count++) { |
| 1785 | ci_populate_smc_voltage_table(rdev, |
| 1786 | &pi->vddc_voltage_table.entries[count], |
| 1787 | &table->VddcLevel[count]); |
| 1788 | |
| 1789 | if (pi->voltage_control == CISLANDS_VOLTAGE_CONTROL_BY_GPIO) |
| 1790 | table->VddcLevel[count].Smio |= |
| 1791 | pi->vddc_voltage_table.entries[count].smio_low; |
| 1792 | else |
| 1793 | table->VddcLevel[count].Smio = 0; |
| 1794 | } |
| 1795 | table->VddcLevelCount = cpu_to_be32(table->VddcLevelCount); |
| 1796 | |
| 1797 | return 0; |
| 1798 | } |
| 1799 | |
| 1800 | static int ci_populate_smc_vddci_table(struct radeon_device *rdev, |
| 1801 | SMU7_Discrete_DpmTable *table) |
| 1802 | { |
| 1803 | unsigned int count; |
| 1804 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1805 | |
| 1806 | table->VddciLevelCount = pi->vddci_voltage_table.count; |
| 1807 | for (count = 0; count < table->VddciLevelCount; count++) { |
| 1808 | ci_populate_smc_voltage_table(rdev, |
| 1809 | &pi->vddci_voltage_table.entries[count], |
| 1810 | &table->VddciLevel[count]); |
| 1811 | |
| 1812 | if (pi->vddci_control == CISLANDS_VOLTAGE_CONTROL_BY_GPIO) |
| 1813 | table->VddciLevel[count].Smio |= |
| 1814 | pi->vddci_voltage_table.entries[count].smio_low; |
| 1815 | else |
| 1816 | table->VddciLevel[count].Smio = 0; |
| 1817 | } |
| 1818 | table->VddciLevelCount = cpu_to_be32(table->VddciLevelCount); |
| 1819 | |
| 1820 | return 0; |
| 1821 | } |
| 1822 | |
| 1823 | static int ci_populate_smc_mvdd_table(struct radeon_device *rdev, |
| 1824 | SMU7_Discrete_DpmTable *table) |
| 1825 | { |
| 1826 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1827 | unsigned int count; |
| 1828 | |
| 1829 | table->MvddLevelCount = pi->mvdd_voltage_table.count; |
| 1830 | for (count = 0; count < table->MvddLevelCount; count++) { |
| 1831 | ci_populate_smc_voltage_table(rdev, |
| 1832 | &pi->mvdd_voltage_table.entries[count], |
| 1833 | &table->MvddLevel[count]); |
| 1834 | |
| 1835 | if (pi->mvdd_control == CISLANDS_VOLTAGE_CONTROL_BY_GPIO) |
| 1836 | table->MvddLevel[count].Smio |= |
| 1837 | pi->mvdd_voltage_table.entries[count].smio_low; |
| 1838 | else |
| 1839 | table->MvddLevel[count].Smio = 0; |
| 1840 | } |
| 1841 | table->MvddLevelCount = cpu_to_be32(table->MvddLevelCount); |
| 1842 | |
| 1843 | return 0; |
| 1844 | } |
| 1845 | |
| 1846 | static int ci_populate_smc_voltage_tables(struct radeon_device *rdev, |
| 1847 | SMU7_Discrete_DpmTable *table) |
| 1848 | { |
| 1849 | int ret; |
| 1850 | |
| 1851 | ret = ci_populate_smc_vddc_table(rdev, table); |
| 1852 | if (ret) |
| 1853 | return ret; |
| 1854 | |
| 1855 | ret = ci_populate_smc_vddci_table(rdev, table); |
| 1856 | if (ret) |
| 1857 | return ret; |
| 1858 | |
| 1859 | ret = ci_populate_smc_mvdd_table(rdev, table); |
| 1860 | if (ret) |
| 1861 | return ret; |
| 1862 | |
| 1863 | return 0; |
| 1864 | } |
| 1865 | |
| 1866 | static int ci_populate_mvdd_value(struct radeon_device *rdev, u32 mclk, |
| 1867 | SMU7_Discrete_VoltageLevel *voltage) |
| 1868 | { |
| 1869 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1870 | u32 i = 0; |
| 1871 | |
| 1872 | if (pi->mvdd_control != CISLANDS_VOLTAGE_CONTROL_NONE) { |
| 1873 | for (i = 0; i < rdev->pm.dpm.dyn_state.mvdd_dependency_on_mclk.count; i++) { |
| 1874 | if (mclk <= rdev->pm.dpm.dyn_state.mvdd_dependency_on_mclk.entries[i].clk) { |
| 1875 | voltage->Voltage = pi->mvdd_voltage_table.entries[i].value; |
| 1876 | break; |
| 1877 | } |
| 1878 | } |
| 1879 | |
| 1880 | if (i >= rdev->pm.dpm.dyn_state.mvdd_dependency_on_mclk.count) |
| 1881 | return -EINVAL; |
| 1882 | } |
| 1883 | |
| 1884 | return -EINVAL; |
| 1885 | } |
| 1886 | |
| 1887 | static int ci_get_std_voltage_value_sidd(struct radeon_device *rdev, |
| 1888 | struct atom_voltage_table_entry *voltage_table, |
| 1889 | u16 *std_voltage_hi_sidd, u16 *std_voltage_lo_sidd) |
| 1890 | { |
| 1891 | u16 v_index, idx; |
| 1892 | bool voltage_found = false; |
| 1893 | *std_voltage_hi_sidd = voltage_table->value * VOLTAGE_SCALE; |
| 1894 | *std_voltage_lo_sidd = voltage_table->value * VOLTAGE_SCALE; |
| 1895 | |
| 1896 | if (rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries == NULL) |
| 1897 | return -EINVAL; |
| 1898 | |
| 1899 | if (rdev->pm.dpm.dyn_state.cac_leakage_table.entries) { |
| 1900 | for (v_index = 0; (u32)v_index < rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.count; v_index++) { |
| 1901 | if (voltage_table->value == |
| 1902 | rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[v_index].v) { |
| 1903 | voltage_found = true; |
| 1904 | if ((u32)v_index < rdev->pm.dpm.dyn_state.cac_leakage_table.count) |
| 1905 | idx = v_index; |
| 1906 | else |
| 1907 | idx = rdev->pm.dpm.dyn_state.cac_leakage_table.count - 1; |
| 1908 | *std_voltage_lo_sidd = |
| 1909 | rdev->pm.dpm.dyn_state.cac_leakage_table.entries[idx].vddc * VOLTAGE_SCALE; |
| 1910 | *std_voltage_hi_sidd = |
| 1911 | rdev->pm.dpm.dyn_state.cac_leakage_table.entries[idx].leakage * VOLTAGE_SCALE; |
| 1912 | break; |
| 1913 | } |
| 1914 | } |
| 1915 | |
| 1916 | if (!voltage_found) { |
| 1917 | for (v_index = 0; (u32)v_index < rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.count; v_index++) { |
| 1918 | if (voltage_table->value <= |
| 1919 | rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[v_index].v) { |
| 1920 | voltage_found = true; |
| 1921 | if ((u32)v_index < rdev->pm.dpm.dyn_state.cac_leakage_table.count) |
| 1922 | idx = v_index; |
| 1923 | else |
| 1924 | idx = rdev->pm.dpm.dyn_state.cac_leakage_table.count - 1; |
| 1925 | *std_voltage_lo_sidd = |
| 1926 | rdev->pm.dpm.dyn_state.cac_leakage_table.entries[idx].vddc * VOLTAGE_SCALE; |
| 1927 | *std_voltage_hi_sidd = |
| 1928 | rdev->pm.dpm.dyn_state.cac_leakage_table.entries[idx].leakage * VOLTAGE_SCALE; |
| 1929 | break; |
| 1930 | } |
| 1931 | } |
| 1932 | } |
| 1933 | } |
| 1934 | |
| 1935 | return 0; |
| 1936 | } |
| 1937 | |
| 1938 | static void ci_populate_phase_value_based_on_sclk(struct radeon_device *rdev, |
| 1939 | const struct radeon_phase_shedding_limits_table *limits, |
| 1940 | u32 sclk, |
| 1941 | u32 *phase_shedding) |
| 1942 | { |
| 1943 | unsigned int i; |
| 1944 | |
| 1945 | *phase_shedding = 1; |
| 1946 | |
| 1947 | for (i = 0; i < limits->count; i++) { |
| 1948 | if (sclk < limits->entries[i].sclk) { |
| 1949 | *phase_shedding = i; |
| 1950 | break; |
| 1951 | } |
| 1952 | } |
| 1953 | } |
| 1954 | |
| 1955 | static void ci_populate_phase_value_based_on_mclk(struct radeon_device *rdev, |
| 1956 | const struct radeon_phase_shedding_limits_table *limits, |
| 1957 | u32 mclk, |
| 1958 | u32 *phase_shedding) |
| 1959 | { |
| 1960 | unsigned int i; |
| 1961 | |
| 1962 | *phase_shedding = 1; |
| 1963 | |
| 1964 | for (i = 0; i < limits->count; i++) { |
| 1965 | if (mclk < limits->entries[i].mclk) { |
| 1966 | *phase_shedding = i; |
| 1967 | break; |
| 1968 | } |
| 1969 | } |
| 1970 | } |
| 1971 | |
| 1972 | static int ci_init_arb_table_index(struct radeon_device *rdev) |
| 1973 | { |
| 1974 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 1975 | u32 tmp; |
| 1976 | int ret; |
| 1977 | |
| 1978 | ret = ci_read_smc_sram_dword(rdev, pi->arb_table_start, |
| 1979 | &tmp, pi->sram_end); |
| 1980 | if (ret) |
| 1981 | return ret; |
| 1982 | |
| 1983 | tmp &= 0x00FFFFFF; |
| 1984 | tmp |= MC_CG_ARB_FREQ_F1 << 24; |
| 1985 | |
| 1986 | return ci_write_smc_sram_dword(rdev, pi->arb_table_start, |
| 1987 | tmp, pi->sram_end); |
| 1988 | } |
| 1989 | |
| 1990 | static int ci_get_dependency_volt_by_clk(struct radeon_device *rdev, |
| 1991 | struct radeon_clock_voltage_dependency_table *allowed_clock_voltage_table, |
| 1992 | u32 clock, u32 *voltage) |
| 1993 | { |
| 1994 | u32 i = 0; |
| 1995 | |
| 1996 | if (allowed_clock_voltage_table->count == 0) |
| 1997 | return -EINVAL; |
| 1998 | |
| 1999 | for (i = 0; i < allowed_clock_voltage_table->count; i++) { |
| 2000 | if (allowed_clock_voltage_table->entries[i].clk >= clock) { |
| 2001 | *voltage = allowed_clock_voltage_table->entries[i].v; |
| 2002 | return 0; |
| 2003 | } |
| 2004 | } |
| 2005 | |
| 2006 | *voltage = allowed_clock_voltage_table->entries[i-1].v; |
| 2007 | |
| 2008 | return 0; |
| 2009 | } |
| 2010 | |
| 2011 | static u8 ci_get_sleep_divider_id_from_clock(struct radeon_device *rdev, |
| 2012 | u32 sclk, u32 min_sclk_in_sr) |
| 2013 | { |
| 2014 | u32 i; |
| 2015 | u32 tmp; |
| 2016 | u32 min = (min_sclk_in_sr > CISLAND_MINIMUM_ENGINE_CLOCK) ? |
| 2017 | min_sclk_in_sr : CISLAND_MINIMUM_ENGINE_CLOCK; |
| 2018 | |
| 2019 | if (sclk < min) |
| 2020 | return 0; |
| 2021 | |
| 2022 | for (i = CISLAND_MAX_DEEPSLEEP_DIVIDER_ID; ; i--) { |
| 2023 | tmp = sclk / (1 << i); |
| 2024 | if (tmp >= min || i == 0) |
| 2025 | break; |
| 2026 | } |
| 2027 | |
| 2028 | return (u8)i; |
| 2029 | } |
| 2030 | |
| 2031 | static int ci_initial_switch_from_arb_f0_to_f1(struct radeon_device *rdev) |
| 2032 | { |
| 2033 | return ni_copy_and_switch_arb_sets(rdev, MC_CG_ARB_FREQ_F0, MC_CG_ARB_FREQ_F1); |
| 2034 | } |
| 2035 | |
| 2036 | static int ci_reset_to_default(struct radeon_device *rdev) |
| 2037 | { |
| 2038 | return (ci_send_msg_to_smc(rdev, PPSMC_MSG_ResetToDefaults) == PPSMC_Result_OK) ? |
| 2039 | 0 : -EINVAL; |
| 2040 | } |
| 2041 | |
| 2042 | static int ci_force_switch_to_arb_f0(struct radeon_device *rdev) |
| 2043 | { |
| 2044 | u32 tmp; |
| 2045 | |
| 2046 | tmp = (RREG32_SMC(SMC_SCRATCH9) & 0x0000ff00) >> 8; |
| 2047 | |
| 2048 | if (tmp == MC_CG_ARB_FREQ_F0) |
| 2049 | return 0; |
| 2050 | |
| 2051 | return ni_copy_and_switch_arb_sets(rdev, tmp, MC_CG_ARB_FREQ_F0); |
| 2052 | } |
| 2053 | |
| 2054 | static int ci_populate_memory_timing_parameters(struct radeon_device *rdev, |
| 2055 | u32 sclk, |
| 2056 | u32 mclk, |
| 2057 | SMU7_Discrete_MCArbDramTimingTableEntry *arb_regs) |
| 2058 | { |
| 2059 | u32 dram_timing; |
| 2060 | u32 dram_timing2; |
| 2061 | u32 burst_time; |
| 2062 | |
| 2063 | radeon_atom_set_engine_dram_timings(rdev, sclk, mclk); |
| 2064 | |
| 2065 | dram_timing = RREG32(MC_ARB_DRAM_TIMING); |
| 2066 | dram_timing2 = RREG32(MC_ARB_DRAM_TIMING2); |
| 2067 | burst_time = RREG32(MC_ARB_BURST_TIME) & STATE0_MASK; |
| 2068 | |
| 2069 | arb_regs->McArbDramTiming = cpu_to_be32(dram_timing); |
| 2070 | arb_regs->McArbDramTiming2 = cpu_to_be32(dram_timing2); |
| 2071 | arb_regs->McArbBurstTime = (u8)burst_time; |
| 2072 | |
| 2073 | return 0; |
| 2074 | } |
| 2075 | |
| 2076 | static int ci_do_program_memory_timing_parameters(struct radeon_device *rdev) |
| 2077 | { |
| 2078 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 2079 | SMU7_Discrete_MCArbDramTimingTable arb_regs; |
| 2080 | u32 i, j; |
| 2081 | int ret = 0; |
| 2082 | |
| 2083 | memset(&arb_regs, 0, sizeof(SMU7_Discrete_MCArbDramTimingTable)); |
| 2084 | |
| 2085 | for (i = 0; i < pi->dpm_table.sclk_table.count; i++) { |
| 2086 | for (j = 0; j < pi->dpm_table.mclk_table.count; j++) { |
| 2087 | ret = ci_populate_memory_timing_parameters(rdev, |
| 2088 | pi->dpm_table.sclk_table.dpm_levels[i].value, |
| 2089 | pi->dpm_table.mclk_table.dpm_levels[j].value, |
| 2090 | &arb_regs.entries[i][j]); |
| 2091 | if (ret) |
| 2092 | break; |
| 2093 | } |
| 2094 | } |
| 2095 | |
| 2096 | if (ret == 0) |
| 2097 | ret = ci_copy_bytes_to_smc(rdev, |
| 2098 | pi->arb_table_start, |
| 2099 | (u8 *)&arb_regs, |
| 2100 | sizeof(SMU7_Discrete_MCArbDramTimingTable), |
| 2101 | pi->sram_end); |
| 2102 | |
| 2103 | return ret; |
| 2104 | } |
| 2105 | |
| 2106 | static int ci_program_memory_timing_parameters(struct radeon_device *rdev) |
| 2107 | { |
| 2108 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 2109 | |
| 2110 | if (pi->need_update_smu7_dpm_table == 0) |
| 2111 | return 0; |
| 2112 | |
| 2113 | return ci_do_program_memory_timing_parameters(rdev); |
| 2114 | } |
| 2115 | |
| 2116 | static void ci_populate_smc_initial_state(struct radeon_device *rdev, |
| 2117 | struct radeon_ps *radeon_boot_state) |
| 2118 | { |
| 2119 | struct ci_ps *boot_state = ci_get_ps(radeon_boot_state); |
| 2120 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 2121 | u32 level = 0; |
| 2122 | |
| 2123 | for (level = 0; level < rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.count; level++) { |
| 2124 | if (rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[level].clk >= |
| 2125 | boot_state->performance_levels[0].sclk) { |
| 2126 | pi->smc_state_table.GraphicsBootLevel = level; |
| 2127 | break; |
| 2128 | } |
| 2129 | } |
| 2130 | |
| 2131 | for (level = 0; level < rdev->pm.dpm.dyn_state.vddc_dependency_on_mclk.count; level++) { |
| 2132 | if (rdev->pm.dpm.dyn_state.vddc_dependency_on_mclk.entries[level].clk >= |
| 2133 | boot_state->performance_levels[0].mclk) { |
| 2134 | pi->smc_state_table.MemoryBootLevel = level; |
| 2135 | break; |
| 2136 | } |
| 2137 | } |
| 2138 | } |
| 2139 | |
| 2140 | static u32 ci_get_dpm_level_enable_mask_value(struct ci_single_dpm_table *dpm_table) |
| 2141 | { |
| 2142 | u32 i; |
| 2143 | u32 mask_value = 0; |
| 2144 | |
| 2145 | for (i = dpm_table->count; i > 0; i--) { |
| 2146 | mask_value = mask_value << 1; |
| 2147 | if (dpm_table->dpm_levels[i-1].enabled) |
| 2148 | mask_value |= 0x1; |
| 2149 | else |
| 2150 | mask_value &= 0xFFFFFFFE; |
| 2151 | } |
| 2152 | |
| 2153 | return mask_value; |
| 2154 | } |
| 2155 | |
| 2156 | static void ci_populate_smc_link_level(struct radeon_device *rdev, |
| 2157 | SMU7_Discrete_DpmTable *table) |
| 2158 | { |
| 2159 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 2160 | struct ci_dpm_table *dpm_table = &pi->dpm_table; |
| 2161 | u32 i; |
| 2162 | |
| 2163 | for (i = 0; i < dpm_table->pcie_speed_table.count; i++) { |
| 2164 | table->LinkLevel[i].PcieGenSpeed = |
| 2165 | (u8)dpm_table->pcie_speed_table.dpm_levels[i].value; |
| 2166 | table->LinkLevel[i].PcieLaneCount = |
| 2167 | r600_encode_pci_lane_width(dpm_table->pcie_speed_table.dpm_levels[i].param1); |
| 2168 | table->LinkLevel[i].EnabledForActivity = 1; |
| 2169 | table->LinkLevel[i].DownT = cpu_to_be32(5); |
| 2170 | table->LinkLevel[i].UpT = cpu_to_be32(30); |
| 2171 | } |
| 2172 | |
| 2173 | pi->smc_state_table.LinkLevelCount = (u8)dpm_table->pcie_speed_table.count; |
| 2174 | pi->dpm_level_enable_mask.pcie_dpm_enable_mask = |
| 2175 | ci_get_dpm_level_enable_mask_value(&dpm_table->pcie_speed_table); |
| 2176 | } |
| 2177 | |
| 2178 | static int ci_populate_smc_uvd_level(struct radeon_device *rdev, |
| 2179 | SMU7_Discrete_DpmTable *table) |
| 2180 | { |
| 2181 | u32 count; |
| 2182 | struct atom_clock_dividers dividers; |
| 2183 | int ret = -EINVAL; |
| 2184 | |
| 2185 | table->UvdLevelCount = |
| 2186 | rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.count; |
| 2187 | |
| 2188 | for (count = 0; count < table->UvdLevelCount; count++) { |
| 2189 | table->UvdLevel[count].VclkFrequency = |
| 2190 | rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[count].vclk; |
| 2191 | table->UvdLevel[count].DclkFrequency = |
| 2192 | rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[count].dclk; |
| 2193 | table->UvdLevel[count].MinVddc = |
| 2194 | rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[count].v * VOLTAGE_SCALE; |
| 2195 | table->UvdLevel[count].MinVddcPhases = 1; |
| 2196 | |
| 2197 | ret = radeon_atom_get_clock_dividers(rdev, |
| 2198 | COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK, |
| 2199 | table->UvdLevel[count].VclkFrequency, false, ÷rs); |
| 2200 | if (ret) |
| 2201 | return ret; |
| 2202 | |
| 2203 | table->UvdLevel[count].VclkDivider = (u8)dividers.post_divider; |
| 2204 | |
| 2205 | ret = radeon_atom_get_clock_dividers(rdev, |
| 2206 | COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK, |
| 2207 | table->UvdLevel[count].DclkFrequency, false, ÷rs); |
| 2208 | if (ret) |
| 2209 | return ret; |
| 2210 | |
| 2211 | table->UvdLevel[count].DclkDivider = (u8)dividers.post_divider; |
| 2212 | |
| 2213 | table->UvdLevel[count].VclkFrequency = cpu_to_be32(table->UvdLevel[count].VclkFrequency); |
| 2214 | table->UvdLevel[count].DclkFrequency = cpu_to_be32(table->UvdLevel[count].DclkFrequency); |
| 2215 | table->UvdLevel[count].MinVddc = cpu_to_be16(table->UvdLevel[count].MinVddc); |
| 2216 | } |
| 2217 | |
| 2218 | return ret; |
| 2219 | } |
| 2220 | |
| 2221 | static int ci_populate_smc_vce_level(struct radeon_device *rdev, |
| 2222 | SMU7_Discrete_DpmTable *table) |
| 2223 | { |
| 2224 | u32 count; |
| 2225 | struct atom_clock_dividers dividers; |
| 2226 | int ret = -EINVAL; |
| 2227 | |
| 2228 | table->VceLevelCount = |
| 2229 | rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.count; |
| 2230 | |
| 2231 | for (count = 0; count < table->VceLevelCount; count++) { |
| 2232 | table->VceLevel[count].Frequency = |
| 2233 | rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries[count].evclk; |
| 2234 | table->VceLevel[count].MinVoltage = |
| 2235 | (u16)rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries[count].v * VOLTAGE_SCALE; |
| 2236 | table->VceLevel[count].MinPhases = 1; |
| 2237 | |
| 2238 | ret = radeon_atom_get_clock_dividers(rdev, |
| 2239 | COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK, |
| 2240 | table->VceLevel[count].Frequency, false, ÷rs); |
| 2241 | if (ret) |
| 2242 | return ret; |
| 2243 | |
| 2244 | table->VceLevel[count].Divider = (u8)dividers.post_divider; |
| 2245 | |
| 2246 | table->VceLevel[count].Frequency = cpu_to_be32(table->VceLevel[count].Frequency); |
| 2247 | table->VceLevel[count].MinVoltage = cpu_to_be16(table->VceLevel[count].MinVoltage); |
| 2248 | } |
| 2249 | |
| 2250 | return ret; |
| 2251 | |
| 2252 | } |
| 2253 | |
| 2254 | static int ci_populate_smc_acp_level(struct radeon_device *rdev, |
| 2255 | SMU7_Discrete_DpmTable *table) |
| 2256 | { |
| 2257 | u32 count; |
| 2258 | struct atom_clock_dividers dividers; |
| 2259 | int ret = -EINVAL; |
| 2260 | |
| 2261 | table->AcpLevelCount = (u8) |
| 2262 | (rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.count); |
| 2263 | |
| 2264 | for (count = 0; count < table->AcpLevelCount; count++) { |
| 2265 | table->AcpLevel[count].Frequency = |
| 2266 | rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries[count].clk; |
| 2267 | table->AcpLevel[count].MinVoltage = |
| 2268 | rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries[count].v; |
| 2269 | table->AcpLevel[count].MinPhases = 1; |
| 2270 | |
| 2271 | ret = radeon_atom_get_clock_dividers(rdev, |
| 2272 | COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK, |
| 2273 | table->AcpLevel[count].Frequency, false, ÷rs); |
| 2274 | if (ret) |
| 2275 | return ret; |
| 2276 | |
| 2277 | table->AcpLevel[count].Divider = (u8)dividers.post_divider; |
| 2278 | |
| 2279 | table->AcpLevel[count].Frequency = cpu_to_be32(table->AcpLevel[count].Frequency); |
| 2280 | table->AcpLevel[count].MinVoltage = cpu_to_be16(table->AcpLevel[count].MinVoltage); |
| 2281 | } |
| 2282 | |
| 2283 | return ret; |
| 2284 | } |
| 2285 | |
| 2286 | static int ci_populate_smc_samu_level(struct radeon_device *rdev, |
| 2287 | SMU7_Discrete_DpmTable *table) |
| 2288 | { |
| 2289 | u32 count; |
| 2290 | struct atom_clock_dividers dividers; |
| 2291 | int ret = -EINVAL; |
| 2292 | |
| 2293 | table->SamuLevelCount = |
| 2294 | rdev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.count; |
| 2295 | |
| 2296 | for (count = 0; count < table->SamuLevelCount; count++) { |
| 2297 | table->SamuLevel[count].Frequency = |
| 2298 | rdev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries[count].clk; |
| 2299 | table->SamuLevel[count].MinVoltage = |
| 2300 | rdev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries[count].v * VOLTAGE_SCALE; |
| 2301 | table->SamuLevel[count].MinPhases = 1; |
| 2302 | |
| 2303 | ret = radeon_atom_get_clock_dividers(rdev, |
| 2304 | COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK, |
| 2305 | table->SamuLevel[count].Frequency, false, ÷rs); |
| 2306 | if (ret) |
| 2307 | return ret; |
| 2308 | |
| 2309 | table->SamuLevel[count].Divider = (u8)dividers.post_divider; |
| 2310 | |
| 2311 | table->SamuLevel[count].Frequency = cpu_to_be32(table->SamuLevel[count].Frequency); |
| 2312 | table->SamuLevel[count].MinVoltage = cpu_to_be16(table->SamuLevel[count].MinVoltage); |
| 2313 | } |
| 2314 | |
| 2315 | return ret; |
| 2316 | } |
| 2317 | |
| 2318 | static int ci_calculate_mclk_params(struct radeon_device *rdev, |
| 2319 | u32 memory_clock, |
| 2320 | SMU7_Discrete_MemoryLevel *mclk, |
| 2321 | bool strobe_mode, |
| 2322 | bool dll_state_on) |
| 2323 | { |
| 2324 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 2325 | u32 dll_cntl = pi->clock_registers.dll_cntl; |
| 2326 | u32 mclk_pwrmgt_cntl = pi->clock_registers.mclk_pwrmgt_cntl; |
| 2327 | u32 mpll_ad_func_cntl = pi->clock_registers.mpll_ad_func_cntl; |
| 2328 | u32 mpll_dq_func_cntl = pi->clock_registers.mpll_dq_func_cntl; |
| 2329 | u32 mpll_func_cntl = pi->clock_registers.mpll_func_cntl; |
| 2330 | u32 mpll_func_cntl_1 = pi->clock_registers.mpll_func_cntl_1; |
| 2331 | u32 mpll_func_cntl_2 = pi->clock_registers.mpll_func_cntl_2; |
| 2332 | u32 mpll_ss1 = pi->clock_registers.mpll_ss1; |
| 2333 | u32 mpll_ss2 = pi->clock_registers.mpll_ss2; |
| 2334 | struct atom_mpll_param mpll_param; |
| 2335 | int ret; |
| 2336 | |
| 2337 | ret = radeon_atom_get_memory_pll_dividers(rdev, memory_clock, strobe_mode, &mpll_param); |
| 2338 | if (ret) |
| 2339 | return ret; |
| 2340 | |
| 2341 | mpll_func_cntl &= ~BWCTRL_MASK; |
| 2342 | mpll_func_cntl |= BWCTRL(mpll_param.bwcntl); |
| 2343 | |
| 2344 | mpll_func_cntl_1 &= ~(CLKF_MASK | CLKFRAC_MASK | VCO_MODE_MASK); |
| 2345 | mpll_func_cntl_1 |= CLKF(mpll_param.clkf) | |
| 2346 | CLKFRAC(mpll_param.clkfrac) | VCO_MODE(mpll_param.vco_mode); |
| 2347 | |
| 2348 | mpll_ad_func_cntl &= ~YCLK_POST_DIV_MASK; |
| 2349 | mpll_ad_func_cntl |= YCLK_POST_DIV(mpll_param.post_div); |
| 2350 | |
| 2351 | if (pi->mem_gddr5) { |
| 2352 | mpll_dq_func_cntl &= ~(YCLK_SEL_MASK | YCLK_POST_DIV_MASK); |
| 2353 | mpll_dq_func_cntl |= YCLK_SEL(mpll_param.yclk_sel) | |
| 2354 | YCLK_POST_DIV(mpll_param.post_div); |
| 2355 | } |
| 2356 | |
| 2357 | if (pi->caps_mclk_ss_support) { |
| 2358 | struct radeon_atom_ss ss; |
| 2359 | u32 freq_nom; |
| 2360 | u32 tmp; |
| 2361 | u32 reference_clock = rdev->clock.mpll.reference_freq; |
| 2362 | |
| 2363 | if (pi->mem_gddr5) |
| 2364 | freq_nom = memory_clock * 4; |
| 2365 | else |
| 2366 | freq_nom = memory_clock * 2; |
| 2367 | |
| 2368 | tmp = (freq_nom / reference_clock); |
| 2369 | tmp = tmp * tmp; |
| 2370 | if (radeon_atombios_get_asic_ss_info(rdev, &ss, |
| 2371 | ASIC_INTERNAL_MEMORY_SS, freq_nom)) { |
| 2372 | u32 clks = reference_clock * 5 / ss.rate; |
| 2373 | u32 clkv = (u32)((((131 * ss.percentage * ss.rate) / 100) * tmp) / freq_nom); |
| 2374 | |
| 2375 | mpll_ss1 &= ~CLKV_MASK; |
| 2376 | mpll_ss1 |= CLKV(clkv); |
| 2377 | |
| 2378 | mpll_ss2 &= ~CLKS_MASK; |
| 2379 | mpll_ss2 |= CLKS(clks); |
| 2380 | } |
| 2381 | } |
| 2382 | |
| 2383 | mclk_pwrmgt_cntl &= ~DLL_SPEED_MASK; |
| 2384 | mclk_pwrmgt_cntl |= DLL_SPEED(mpll_param.dll_speed); |
| 2385 | |
| 2386 | if (dll_state_on) |
| 2387 | mclk_pwrmgt_cntl |= MRDCK0_PDNB | MRDCK1_PDNB; |
| 2388 | else |
| 2389 | mclk_pwrmgt_cntl &= ~(MRDCK0_PDNB | MRDCK1_PDNB); |
| 2390 | |
| 2391 | mclk->MclkFrequency = memory_clock; |
| 2392 | mclk->MpllFuncCntl = mpll_func_cntl; |
| 2393 | mclk->MpllFuncCntl_1 = mpll_func_cntl_1; |
| 2394 | mclk->MpllFuncCntl_2 = mpll_func_cntl_2; |
| 2395 | mclk->MpllAdFuncCntl = mpll_ad_func_cntl; |
| 2396 | mclk->MpllDqFuncCntl = mpll_dq_func_cntl; |
| 2397 | mclk->MclkPwrmgtCntl = mclk_pwrmgt_cntl; |
| 2398 | mclk->DllCntl = dll_cntl; |
| 2399 | mclk->MpllSs1 = mpll_ss1; |
| 2400 | mclk->MpllSs2 = mpll_ss2; |
| 2401 | |
| 2402 | return 0; |
| 2403 | } |
| 2404 | |
| 2405 | static int ci_populate_single_memory_level(struct radeon_device *rdev, |
| 2406 | u32 memory_clock, |
| 2407 | SMU7_Discrete_MemoryLevel *memory_level) |
| 2408 | { |
| 2409 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 2410 | int ret; |
| 2411 | bool dll_state_on; |
| 2412 | |
| 2413 | if (rdev->pm.dpm.dyn_state.vddc_dependency_on_mclk.entries) { |
| 2414 | ret = ci_get_dependency_volt_by_clk(rdev, |
| 2415 | &rdev->pm.dpm.dyn_state.vddc_dependency_on_mclk, |
| 2416 | memory_clock, &memory_level->MinVddc); |
| 2417 | if (ret) |
| 2418 | return ret; |
| 2419 | } |
| 2420 | |
| 2421 | if (rdev->pm.dpm.dyn_state.vddci_dependency_on_mclk.entries) { |
| 2422 | ret = ci_get_dependency_volt_by_clk(rdev, |
| 2423 | &rdev->pm.dpm.dyn_state.vddci_dependency_on_mclk, |
| 2424 | memory_clock, &memory_level->MinVddci); |
| 2425 | if (ret) |
| 2426 | return ret; |
| 2427 | } |
| 2428 | |
| 2429 | if (rdev->pm.dpm.dyn_state.mvdd_dependency_on_mclk.entries) { |
| 2430 | ret = ci_get_dependency_volt_by_clk(rdev, |
| 2431 | &rdev->pm.dpm.dyn_state.mvdd_dependency_on_mclk, |
| 2432 | memory_clock, &memory_level->MinMvdd); |
| 2433 | if (ret) |
| 2434 | return ret; |
| 2435 | } |
| 2436 | |
| 2437 | memory_level->MinVddcPhases = 1; |
| 2438 | |
| 2439 | if (pi->vddc_phase_shed_control) |
| 2440 | ci_populate_phase_value_based_on_mclk(rdev, |
| 2441 | &rdev->pm.dpm.dyn_state.phase_shedding_limits_table, |
| 2442 | memory_clock, |
| 2443 | &memory_level->MinVddcPhases); |
| 2444 | |
| 2445 | memory_level->EnabledForThrottle = 1; |
| 2446 | memory_level->EnabledForActivity = 1; |
| 2447 | memory_level->UpH = 0; |
| 2448 | memory_level->DownH = 100; |
| 2449 | memory_level->VoltageDownH = 0; |
| 2450 | memory_level->ActivityLevel = (u16)pi->mclk_activity_target; |
| 2451 | |
| 2452 | memory_level->StutterEnable = false; |
| 2453 | memory_level->StrobeEnable = false; |
| 2454 | memory_level->EdcReadEnable = false; |
| 2455 | memory_level->EdcWriteEnable = false; |
| 2456 | memory_level->RttEnable = false; |
| 2457 | |
| 2458 | memory_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW; |
| 2459 | |
| 2460 | if (pi->mclk_stutter_mode_threshold && |
| 2461 | (memory_clock <= pi->mclk_stutter_mode_threshold) && |
| 2462 | (pi->uvd_enabled == false) && |
| 2463 | (RREG32(DPG_PIPE_STUTTER_CONTROL) & STUTTER_ENABLE) && |
| 2464 | (rdev->pm.dpm.new_active_crtc_count <= 2)) |
| 2465 | memory_level->StutterEnable = true; |
| 2466 | |
| 2467 | if (pi->mclk_strobe_mode_threshold && |
| 2468 | (memory_clock <= pi->mclk_strobe_mode_threshold)) |
| 2469 | memory_level->StrobeEnable = 1; |
| 2470 | |
| 2471 | if (pi->mem_gddr5) { |
| 2472 | memory_level->StrobeRatio = |
| 2473 | si_get_mclk_frequency_ratio(memory_clock, memory_level->StrobeEnable); |
| 2474 | if (pi->mclk_edc_enable_threshold && |
| 2475 | (memory_clock > pi->mclk_edc_enable_threshold)) |
| 2476 | memory_level->EdcReadEnable = true; |
| 2477 | |
| 2478 | if (pi->mclk_edc_wr_enable_threshold && |
| 2479 | (memory_clock > pi->mclk_edc_wr_enable_threshold)) |
| 2480 | memory_level->EdcWriteEnable = true; |
| 2481 | |
| 2482 | if (memory_level->StrobeEnable) { |
| 2483 | if (si_get_mclk_frequency_ratio(memory_clock, true) >= |
| 2484 | ((RREG32(MC_SEQ_MISC7) >> 16) & 0xf)) |
| 2485 | dll_state_on = ((RREG32(MC_SEQ_MISC5) >> 1) & 0x1) ? true : false; |
| 2486 | else |
| 2487 | dll_state_on = ((RREG32(MC_SEQ_MISC6) >> 1) & 0x1) ? true : false; |
| 2488 | } else { |
| 2489 | dll_state_on = pi->dll_default_on; |
| 2490 | } |
| 2491 | } else { |
| 2492 | memory_level->StrobeRatio = si_get_ddr3_mclk_frequency_ratio(memory_clock); |
| 2493 | dll_state_on = ((RREG32(MC_SEQ_MISC5) >> 1) & 0x1) ? true : false; |
| 2494 | } |
| 2495 | |
| 2496 | ret = ci_calculate_mclk_params(rdev, memory_clock, memory_level, memory_level->StrobeEnable, dll_state_on); |
| 2497 | if (ret) |
| 2498 | return ret; |
| 2499 | |
| 2500 | memory_level->MinVddc = cpu_to_be32(memory_level->MinVddc * VOLTAGE_SCALE); |
| 2501 | memory_level->MinVddcPhases = cpu_to_be32(memory_level->MinVddcPhases); |
| 2502 | memory_level->MinVddci = cpu_to_be32(memory_level->MinVddci * VOLTAGE_SCALE); |
| 2503 | memory_level->MinMvdd = cpu_to_be32(memory_level->MinMvdd * VOLTAGE_SCALE); |
| 2504 | |
| 2505 | memory_level->MclkFrequency = cpu_to_be32(memory_level->MclkFrequency); |
| 2506 | memory_level->ActivityLevel = cpu_to_be16(memory_level->ActivityLevel); |
| 2507 | memory_level->MpllFuncCntl = cpu_to_be32(memory_level->MpllFuncCntl); |
| 2508 | memory_level->MpllFuncCntl_1 = cpu_to_be32(memory_level->MpllFuncCntl_1); |
| 2509 | memory_level->MpllFuncCntl_2 = cpu_to_be32(memory_level->MpllFuncCntl_2); |
| 2510 | memory_level->MpllAdFuncCntl = cpu_to_be32(memory_level->MpllAdFuncCntl); |
| 2511 | memory_level->MpllDqFuncCntl = cpu_to_be32(memory_level->MpllDqFuncCntl); |
| 2512 | memory_level->MclkPwrmgtCntl = cpu_to_be32(memory_level->MclkPwrmgtCntl); |
| 2513 | memory_level->DllCntl = cpu_to_be32(memory_level->DllCntl); |
| 2514 | memory_level->MpllSs1 = cpu_to_be32(memory_level->MpllSs1); |
| 2515 | memory_level->MpllSs2 = cpu_to_be32(memory_level->MpllSs2); |
| 2516 | |
| 2517 | return 0; |
| 2518 | } |
| 2519 | |
| 2520 | static int ci_populate_smc_acpi_level(struct radeon_device *rdev, |
| 2521 | SMU7_Discrete_DpmTable *table) |
| 2522 | { |
| 2523 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 2524 | struct atom_clock_dividers dividers; |
| 2525 | SMU7_Discrete_VoltageLevel voltage_level; |
| 2526 | u32 spll_func_cntl = pi->clock_registers.cg_spll_func_cntl; |
| 2527 | u32 spll_func_cntl_2 = pi->clock_registers.cg_spll_func_cntl_2; |
| 2528 | u32 dll_cntl = pi->clock_registers.dll_cntl; |
| 2529 | u32 mclk_pwrmgt_cntl = pi->clock_registers.mclk_pwrmgt_cntl; |
| 2530 | int ret; |
| 2531 | |
| 2532 | table->ACPILevel.Flags &= ~PPSMC_SWSTATE_FLAG_DC; |
| 2533 | |
| 2534 | if (pi->acpi_vddc) |
| 2535 | table->ACPILevel.MinVddc = cpu_to_be32(pi->acpi_vddc * VOLTAGE_SCALE); |
| 2536 | else |
| 2537 | table->ACPILevel.MinVddc = cpu_to_be32(pi->min_vddc_in_pp_table * VOLTAGE_SCALE); |
| 2538 | |
| 2539 | table->ACPILevel.MinVddcPhases = pi->vddc_phase_shed_control ? 0 : 1; |
| 2540 | |
| 2541 | table->ACPILevel.SclkFrequency = rdev->clock.spll.reference_freq; |
| 2542 | |
| 2543 | ret = radeon_atom_get_clock_dividers(rdev, |
| 2544 | COMPUTE_GPUCLK_INPUT_FLAG_SCLK, |
| 2545 | table->ACPILevel.SclkFrequency, false, ÷rs); |
| 2546 | if (ret) |
| 2547 | return ret; |
| 2548 | |
| 2549 | table->ACPILevel.SclkDid = (u8)dividers.post_divider; |
| 2550 | table->ACPILevel.DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW; |
| 2551 | table->ACPILevel.DeepSleepDivId = 0; |
| 2552 | |
| 2553 | spll_func_cntl &= ~SPLL_PWRON; |
| 2554 | spll_func_cntl |= SPLL_RESET; |
| 2555 | |
| 2556 | spll_func_cntl_2 &= ~SCLK_MUX_SEL_MASK; |
| 2557 | spll_func_cntl_2 |= SCLK_MUX_SEL(4); |
| 2558 | |
| 2559 | table->ACPILevel.CgSpllFuncCntl = spll_func_cntl; |
| 2560 | table->ACPILevel.CgSpllFuncCntl2 = spll_func_cntl_2; |
| 2561 | table->ACPILevel.CgSpllFuncCntl3 = pi->clock_registers.cg_spll_func_cntl_3; |
| 2562 | table->ACPILevel.CgSpllFuncCntl4 = pi->clock_registers.cg_spll_func_cntl_4; |
| 2563 | table->ACPILevel.SpllSpreadSpectrum = pi->clock_registers.cg_spll_spread_spectrum; |
| 2564 | table->ACPILevel.SpllSpreadSpectrum2 = pi->clock_registers.cg_spll_spread_spectrum_2; |
| 2565 | table->ACPILevel.CcPwrDynRm = 0; |
| 2566 | table->ACPILevel.CcPwrDynRm1 = 0; |
| 2567 | |
| 2568 | table->ACPILevel.Flags = cpu_to_be32(table->ACPILevel.Flags); |
| 2569 | table->ACPILevel.MinVddcPhases = cpu_to_be32(table->ACPILevel.MinVddcPhases); |
| 2570 | table->ACPILevel.SclkFrequency = cpu_to_be32(table->ACPILevel.SclkFrequency); |
| 2571 | table->ACPILevel.CgSpllFuncCntl = cpu_to_be32(table->ACPILevel.CgSpllFuncCntl); |
| 2572 | table->ACPILevel.CgSpllFuncCntl2 = cpu_to_be32(table->ACPILevel.CgSpllFuncCntl2); |
| 2573 | table->ACPILevel.CgSpllFuncCntl3 = cpu_to_be32(table->ACPILevel.CgSpllFuncCntl3); |
| 2574 | table->ACPILevel.CgSpllFuncCntl4 = cpu_to_be32(table->ACPILevel.CgSpllFuncCntl4); |
| 2575 | table->ACPILevel.SpllSpreadSpectrum = cpu_to_be32(table->ACPILevel.SpllSpreadSpectrum); |
| 2576 | table->ACPILevel.SpllSpreadSpectrum2 = cpu_to_be32(table->ACPILevel.SpllSpreadSpectrum2); |
| 2577 | table->ACPILevel.CcPwrDynRm = cpu_to_be32(table->ACPILevel.CcPwrDynRm); |
| 2578 | table->ACPILevel.CcPwrDynRm1 = cpu_to_be32(table->ACPILevel.CcPwrDynRm1); |
| 2579 | |
| 2580 | table->MemoryACPILevel.MinVddc = table->ACPILevel.MinVddc; |
| 2581 | table->MemoryACPILevel.MinVddcPhases = table->ACPILevel.MinVddcPhases; |
| 2582 | |
| 2583 | if (pi->vddci_control != CISLANDS_VOLTAGE_CONTROL_NONE) { |
| 2584 | if (pi->acpi_vddci) |
| 2585 | table->MemoryACPILevel.MinVddci = |
| 2586 | cpu_to_be32(pi->acpi_vddci * VOLTAGE_SCALE); |
| 2587 | else |
| 2588 | table->MemoryACPILevel.MinVddci = |
| 2589 | cpu_to_be32(pi->min_vddci_in_pp_table * VOLTAGE_SCALE); |
| 2590 | } |
| 2591 | |
| 2592 | if (ci_populate_mvdd_value(rdev, 0, &voltage_level)) |
| 2593 | table->MemoryACPILevel.MinMvdd = 0; |
| 2594 | else |
| 2595 | table->MemoryACPILevel.MinMvdd = |
| 2596 | cpu_to_be32(voltage_level.Voltage * VOLTAGE_SCALE); |
| 2597 | |
| 2598 | mclk_pwrmgt_cntl |= MRDCK0_RESET | MRDCK1_RESET; |
| 2599 | mclk_pwrmgt_cntl &= ~(MRDCK0_PDNB | MRDCK1_PDNB); |
| 2600 | |
| 2601 | dll_cntl &= ~(MRDCK0_BYPASS | MRDCK1_BYPASS); |
| 2602 | |
| 2603 | table->MemoryACPILevel.DllCntl = cpu_to_be32(dll_cntl); |
| 2604 | table->MemoryACPILevel.MclkPwrmgtCntl = cpu_to_be32(mclk_pwrmgt_cntl); |
| 2605 | table->MemoryACPILevel.MpllAdFuncCntl = |
| 2606 | cpu_to_be32(pi->clock_registers.mpll_ad_func_cntl); |
| 2607 | table->MemoryACPILevel.MpllDqFuncCntl = |
| 2608 | cpu_to_be32(pi->clock_registers.mpll_dq_func_cntl); |
| 2609 | table->MemoryACPILevel.MpllFuncCntl = |
| 2610 | cpu_to_be32(pi->clock_registers.mpll_func_cntl); |
| 2611 | table->MemoryACPILevel.MpllFuncCntl_1 = |
| 2612 | cpu_to_be32(pi->clock_registers.mpll_func_cntl_1); |
| 2613 | table->MemoryACPILevel.MpllFuncCntl_2 = |
| 2614 | cpu_to_be32(pi->clock_registers.mpll_func_cntl_2); |
| 2615 | table->MemoryACPILevel.MpllSs1 = cpu_to_be32(pi->clock_registers.mpll_ss1); |
| 2616 | table->MemoryACPILevel.MpllSs2 = cpu_to_be32(pi->clock_registers.mpll_ss2); |
| 2617 | |
| 2618 | table->MemoryACPILevel.EnabledForThrottle = 0; |
| 2619 | table->MemoryACPILevel.EnabledForActivity = 0; |
| 2620 | table->MemoryACPILevel.UpH = 0; |
| 2621 | table->MemoryACPILevel.DownH = 100; |
| 2622 | table->MemoryACPILevel.VoltageDownH = 0; |
| 2623 | table->MemoryACPILevel.ActivityLevel = |
| 2624 | cpu_to_be16((u16)pi->mclk_activity_target); |
| 2625 | |
| 2626 | table->MemoryACPILevel.StutterEnable = false; |
| 2627 | table->MemoryACPILevel.StrobeEnable = false; |
| 2628 | table->MemoryACPILevel.EdcReadEnable = false; |
| 2629 | table->MemoryACPILevel.EdcWriteEnable = false; |
| 2630 | table->MemoryACPILevel.RttEnable = false; |
| 2631 | |
| 2632 | return 0; |
| 2633 | } |
| 2634 | |
| 2635 | |
| 2636 | static int ci_enable_ulv(struct radeon_device *rdev, bool enable) |
| 2637 | { |
| 2638 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 2639 | struct ci_ulv_parm *ulv = &pi->ulv; |
| 2640 | |
| 2641 | if (ulv->supported) { |
| 2642 | if (enable) |
| 2643 | return (ci_send_msg_to_smc(rdev, PPSMC_MSG_EnableULV) == PPSMC_Result_OK) ? |
| 2644 | 0 : -EINVAL; |
| 2645 | else |
| 2646 | return (ci_send_msg_to_smc(rdev, PPSMC_MSG_DisableULV) == PPSMC_Result_OK) ? |
| 2647 | 0 : -EINVAL; |
| 2648 | } |
| 2649 | |
| 2650 | return 0; |
| 2651 | } |
| 2652 | |
| 2653 | static int ci_populate_ulv_level(struct radeon_device *rdev, |
| 2654 | SMU7_Discrete_Ulv *state) |
| 2655 | { |
| 2656 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 2657 | u16 ulv_voltage = rdev->pm.dpm.backbias_response_time; |
| 2658 | |
| 2659 | state->CcPwrDynRm = 0; |
| 2660 | state->CcPwrDynRm1 = 0; |
| 2661 | |
| 2662 | if (ulv_voltage == 0) { |
| 2663 | pi->ulv.supported = false; |
| 2664 | return 0; |
| 2665 | } |
| 2666 | |
| 2667 | if (pi->voltage_control != CISLANDS_VOLTAGE_CONTROL_BY_SVID2) { |
| 2668 | if (ulv_voltage > rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[0].v) |
| 2669 | state->VddcOffset = 0; |
| 2670 | else |
| 2671 | state->VddcOffset = |
| 2672 | rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[0].v - ulv_voltage; |
| 2673 | } else { |
| 2674 | if (ulv_voltage > rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[0].v) |
| 2675 | state->VddcOffsetVid = 0; |
| 2676 | else |
| 2677 | state->VddcOffsetVid = (u8) |
| 2678 | ((rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[0].v - ulv_voltage) * |
| 2679 | VOLTAGE_VID_OFFSET_SCALE2 / VOLTAGE_VID_OFFSET_SCALE1); |
| 2680 | } |
| 2681 | state->VddcPhase = pi->vddc_phase_shed_control ? 0 : 1; |
| 2682 | |
| 2683 | state->CcPwrDynRm = cpu_to_be32(state->CcPwrDynRm); |
| 2684 | state->CcPwrDynRm1 = cpu_to_be32(state->CcPwrDynRm1); |
| 2685 | state->VddcOffset = cpu_to_be16(state->VddcOffset); |
| 2686 | |
| 2687 | return 0; |
| 2688 | } |
| 2689 | |
| 2690 | static int ci_calculate_sclk_params(struct radeon_device *rdev, |
| 2691 | u32 engine_clock, |
| 2692 | SMU7_Discrete_GraphicsLevel *sclk) |
| 2693 | { |
| 2694 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 2695 | struct atom_clock_dividers dividers; |
| 2696 | u32 spll_func_cntl_3 = pi->clock_registers.cg_spll_func_cntl_3; |
| 2697 | u32 spll_func_cntl_4 = pi->clock_registers.cg_spll_func_cntl_4; |
| 2698 | u32 cg_spll_spread_spectrum = pi->clock_registers.cg_spll_spread_spectrum; |
| 2699 | u32 cg_spll_spread_spectrum_2 = pi->clock_registers.cg_spll_spread_spectrum_2; |
| 2700 | u32 reference_clock = rdev->clock.spll.reference_freq; |
| 2701 | u32 reference_divider; |
| 2702 | u32 fbdiv; |
| 2703 | int ret; |
| 2704 | |
| 2705 | ret = radeon_atom_get_clock_dividers(rdev, |
| 2706 | COMPUTE_GPUCLK_INPUT_FLAG_SCLK, |
| 2707 | engine_clock, false, ÷rs); |
| 2708 | if (ret) |
| 2709 | return ret; |
| 2710 | |
| 2711 | reference_divider = 1 + dividers.ref_div; |
| 2712 | fbdiv = dividers.fb_div & 0x3FFFFFF; |
| 2713 | |
| 2714 | spll_func_cntl_3 &= ~SPLL_FB_DIV_MASK; |
| 2715 | spll_func_cntl_3 |= SPLL_FB_DIV(fbdiv); |
| 2716 | spll_func_cntl_3 |= SPLL_DITHEN; |
| 2717 | |
| 2718 | if (pi->caps_sclk_ss_support) { |
| 2719 | struct radeon_atom_ss ss; |
| 2720 | u32 vco_freq = engine_clock * dividers.post_div; |
| 2721 | |
| 2722 | if (radeon_atombios_get_asic_ss_info(rdev, &ss, |
| 2723 | ASIC_INTERNAL_ENGINE_SS, vco_freq)) { |
| 2724 | u32 clk_s = reference_clock * 5 / (reference_divider * ss.rate); |
| 2725 | u32 clk_v = 4 * ss.percentage * fbdiv / (clk_s * 10000); |
| 2726 | |
| 2727 | cg_spll_spread_spectrum &= ~CLK_S_MASK; |
| 2728 | cg_spll_spread_spectrum |= CLK_S(clk_s); |
| 2729 | cg_spll_spread_spectrum |= SSEN; |
| 2730 | |
| 2731 | cg_spll_spread_spectrum_2 &= ~CLK_V_MASK; |
| 2732 | cg_spll_spread_spectrum_2 |= CLK_V(clk_v); |
| 2733 | } |
| 2734 | } |
| 2735 | |
| 2736 | sclk->SclkFrequency = engine_clock; |
| 2737 | sclk->CgSpllFuncCntl3 = spll_func_cntl_3; |
| 2738 | sclk->CgSpllFuncCntl4 = spll_func_cntl_4; |
| 2739 | sclk->SpllSpreadSpectrum = cg_spll_spread_spectrum; |
| 2740 | sclk->SpllSpreadSpectrum2 = cg_spll_spread_spectrum_2; |
| 2741 | sclk->SclkDid = (u8)dividers.post_divider; |
| 2742 | |
| 2743 | return 0; |
| 2744 | } |
| 2745 | |
| 2746 | static int ci_populate_single_graphic_level(struct radeon_device *rdev, |
| 2747 | u32 engine_clock, |
| 2748 | u16 sclk_activity_level_t, |
| 2749 | SMU7_Discrete_GraphicsLevel *graphic_level) |
| 2750 | { |
| 2751 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 2752 | int ret; |
| 2753 | |
| 2754 | ret = ci_calculate_sclk_params(rdev, engine_clock, graphic_level); |
| 2755 | if (ret) |
| 2756 | return ret; |
| 2757 | |
| 2758 | ret = ci_get_dependency_volt_by_clk(rdev, |
| 2759 | &rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk, |
| 2760 | engine_clock, &graphic_level->MinVddc); |
| 2761 | if (ret) |
| 2762 | return ret; |
| 2763 | |
| 2764 | graphic_level->SclkFrequency = engine_clock; |
| 2765 | |
| 2766 | graphic_level->Flags = 0; |
| 2767 | graphic_level->MinVddcPhases = 1; |
| 2768 | |
| 2769 | if (pi->vddc_phase_shed_control) |
| 2770 | ci_populate_phase_value_based_on_sclk(rdev, |
| 2771 | &rdev->pm.dpm.dyn_state.phase_shedding_limits_table, |
| 2772 | engine_clock, |
| 2773 | &graphic_level->MinVddcPhases); |
| 2774 | |
| 2775 | graphic_level->ActivityLevel = sclk_activity_level_t; |
| 2776 | |
| 2777 | graphic_level->CcPwrDynRm = 0; |
| 2778 | graphic_level->CcPwrDynRm1 = 0; |
| 2779 | graphic_level->EnabledForActivity = 1; |
| 2780 | graphic_level->EnabledForThrottle = 1; |
| 2781 | graphic_level->UpH = 0; |
| 2782 | graphic_level->DownH = 0; |
| 2783 | graphic_level->VoltageDownH = 0; |
| 2784 | graphic_level->PowerThrottle = 0; |
| 2785 | |
| 2786 | if (pi->caps_sclk_ds) |
| 2787 | graphic_level->DeepSleepDivId = ci_get_sleep_divider_id_from_clock(rdev, |
| 2788 | engine_clock, |
| 2789 | CISLAND_MINIMUM_ENGINE_CLOCK); |
| 2790 | |
| 2791 | graphic_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW; |
| 2792 | |
| 2793 | graphic_level->Flags = cpu_to_be32(graphic_level->Flags); |
| 2794 | graphic_level->MinVddc = cpu_to_be32(graphic_level->MinVddc * VOLTAGE_SCALE); |
| 2795 | graphic_level->MinVddcPhases = cpu_to_be32(graphic_level->MinVddcPhases); |
| 2796 | graphic_level->SclkFrequency = cpu_to_be32(graphic_level->SclkFrequency); |
| 2797 | graphic_level->ActivityLevel = cpu_to_be16(graphic_level->ActivityLevel); |
| 2798 | graphic_level->CgSpllFuncCntl3 = cpu_to_be32(graphic_level->CgSpllFuncCntl3); |
| 2799 | graphic_level->CgSpllFuncCntl4 = cpu_to_be32(graphic_level->CgSpllFuncCntl4); |
| 2800 | graphic_level->SpllSpreadSpectrum = cpu_to_be32(graphic_level->SpllSpreadSpectrum); |
| 2801 | graphic_level->SpllSpreadSpectrum2 = cpu_to_be32(graphic_level->SpllSpreadSpectrum2); |
| 2802 | graphic_level->CcPwrDynRm = cpu_to_be32(graphic_level->CcPwrDynRm); |
| 2803 | graphic_level->CcPwrDynRm1 = cpu_to_be32(graphic_level->CcPwrDynRm1); |
| 2804 | |
| 2805 | return 0; |
| 2806 | } |
| 2807 | |
| 2808 | static int ci_populate_all_graphic_levels(struct radeon_device *rdev) |
| 2809 | { |
| 2810 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 2811 | struct ci_dpm_table *dpm_table = &pi->dpm_table; |
| 2812 | u32 level_array_address = pi->dpm_table_start + |
| 2813 | offsetof(SMU7_Discrete_DpmTable, GraphicsLevel); |
| 2814 | u32 level_array_size = sizeof(SMU7_Discrete_GraphicsLevel) * |
| 2815 | SMU7_MAX_LEVELS_GRAPHICS; |
| 2816 | SMU7_Discrete_GraphicsLevel *levels = pi->smc_state_table.GraphicsLevel; |
| 2817 | u32 i, ret; |
| 2818 | |
| 2819 | memset(levels, 0, level_array_size); |
| 2820 | |
| 2821 | for (i = 0; i < dpm_table->sclk_table.count; i++) { |
| 2822 | ret = ci_populate_single_graphic_level(rdev, |
| 2823 | dpm_table->sclk_table.dpm_levels[i].value, |
| 2824 | (u16)pi->activity_target[i], |
| 2825 | &pi->smc_state_table.GraphicsLevel[i]); |
| 2826 | if (ret) |
| 2827 | return ret; |
| 2828 | if (i == (dpm_table->sclk_table.count - 1)) |
| 2829 | pi->smc_state_table.GraphicsLevel[i].DisplayWatermark = |
| 2830 | PPSMC_DISPLAY_WATERMARK_HIGH; |
| 2831 | } |
| 2832 | |
| 2833 | pi->smc_state_table.GraphicsDpmLevelCount = (u8)dpm_table->sclk_table.count; |
| 2834 | pi->dpm_level_enable_mask.sclk_dpm_enable_mask = |
| 2835 | ci_get_dpm_level_enable_mask_value(&dpm_table->sclk_table); |
| 2836 | |
| 2837 | ret = ci_copy_bytes_to_smc(rdev, level_array_address, |
| 2838 | (u8 *)levels, level_array_size, |
| 2839 | pi->sram_end); |
| 2840 | if (ret) |
| 2841 | return ret; |
| 2842 | |
| 2843 | return 0; |
| 2844 | } |
| 2845 | |
| 2846 | static int ci_populate_ulv_state(struct radeon_device *rdev, |
| 2847 | SMU7_Discrete_Ulv *ulv_level) |
| 2848 | { |
| 2849 | return ci_populate_ulv_level(rdev, ulv_level); |
| 2850 | } |
| 2851 | |
| 2852 | static int ci_populate_all_memory_levels(struct radeon_device *rdev) |
| 2853 | { |
| 2854 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 2855 | struct ci_dpm_table *dpm_table = &pi->dpm_table; |
| 2856 | u32 level_array_address = pi->dpm_table_start + |
| 2857 | offsetof(SMU7_Discrete_DpmTable, MemoryLevel); |
| 2858 | u32 level_array_size = sizeof(SMU7_Discrete_MemoryLevel) * |
| 2859 | SMU7_MAX_LEVELS_MEMORY; |
| 2860 | SMU7_Discrete_MemoryLevel *levels = pi->smc_state_table.MemoryLevel; |
| 2861 | u32 i, ret; |
| 2862 | |
| 2863 | memset(levels, 0, level_array_size); |
| 2864 | |
| 2865 | for (i = 0; i < dpm_table->mclk_table.count; i++) { |
| 2866 | if (dpm_table->mclk_table.dpm_levels[i].value == 0) |
| 2867 | return -EINVAL; |
| 2868 | ret = ci_populate_single_memory_level(rdev, |
| 2869 | dpm_table->mclk_table.dpm_levels[i].value, |
| 2870 | &pi->smc_state_table.MemoryLevel[i]); |
| 2871 | if (ret) |
| 2872 | return ret; |
| 2873 | } |
| 2874 | |
| 2875 | pi->smc_state_table.MemoryLevel[0].ActivityLevel = cpu_to_be16(0x1F); |
| 2876 | |
| 2877 | pi->smc_state_table.MemoryDpmLevelCount = (u8)dpm_table->mclk_table.count; |
| 2878 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask = |
| 2879 | ci_get_dpm_level_enable_mask_value(&dpm_table->mclk_table); |
| 2880 | |
| 2881 | pi->smc_state_table.MemoryLevel[dpm_table->mclk_table.count - 1].DisplayWatermark = |
| 2882 | PPSMC_DISPLAY_WATERMARK_HIGH; |
| 2883 | |
| 2884 | ret = ci_copy_bytes_to_smc(rdev, level_array_address, |
| 2885 | (u8 *)levels, level_array_size, |
| 2886 | pi->sram_end); |
| 2887 | if (ret) |
| 2888 | return ret; |
| 2889 | |
| 2890 | return 0; |
| 2891 | } |
| 2892 | |
| 2893 | static void ci_reset_single_dpm_table(struct radeon_device *rdev, |
| 2894 | struct ci_single_dpm_table* dpm_table, |
| 2895 | u32 count) |
| 2896 | { |
| 2897 | u32 i; |
| 2898 | |
| 2899 | dpm_table->count = count; |
| 2900 | for (i = 0; i < MAX_REGULAR_DPM_NUMBER; i++) |
| 2901 | dpm_table->dpm_levels[i].enabled = false; |
| 2902 | } |
| 2903 | |
| 2904 | static void ci_setup_pcie_table_entry(struct ci_single_dpm_table* dpm_table, |
| 2905 | u32 index, u32 pcie_gen, u32 pcie_lanes) |
| 2906 | { |
| 2907 | dpm_table->dpm_levels[index].value = pcie_gen; |
| 2908 | dpm_table->dpm_levels[index].param1 = pcie_lanes; |
| 2909 | dpm_table->dpm_levels[index].enabled = true; |
| 2910 | } |
| 2911 | |
| 2912 | static int ci_setup_default_pcie_tables(struct radeon_device *rdev) |
| 2913 | { |
| 2914 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 2915 | |
| 2916 | if (!pi->use_pcie_performance_levels && !pi->use_pcie_powersaving_levels) |
| 2917 | return -EINVAL; |
| 2918 | |
| 2919 | if (pi->use_pcie_performance_levels && !pi->use_pcie_powersaving_levels) { |
| 2920 | pi->pcie_gen_powersaving = pi->pcie_gen_performance; |
| 2921 | pi->pcie_lane_powersaving = pi->pcie_lane_performance; |
| 2922 | } else if (!pi->use_pcie_performance_levels && pi->use_pcie_powersaving_levels) { |
| 2923 | pi->pcie_gen_performance = pi->pcie_gen_powersaving; |
| 2924 | pi->pcie_lane_performance = pi->pcie_lane_powersaving; |
| 2925 | } |
| 2926 | |
| 2927 | ci_reset_single_dpm_table(rdev, |
| 2928 | &pi->dpm_table.pcie_speed_table, |
| 2929 | SMU7_MAX_LEVELS_LINK); |
| 2930 | |
| 2931 | ci_setup_pcie_table_entry(&pi->dpm_table.pcie_speed_table, 0, |
| 2932 | pi->pcie_gen_powersaving.min, |
| 2933 | pi->pcie_lane_powersaving.min); |
| 2934 | ci_setup_pcie_table_entry(&pi->dpm_table.pcie_speed_table, 1, |
| 2935 | pi->pcie_gen_performance.min, |
| 2936 | pi->pcie_lane_performance.min); |
| 2937 | ci_setup_pcie_table_entry(&pi->dpm_table.pcie_speed_table, 2, |
| 2938 | pi->pcie_gen_powersaving.min, |
| 2939 | pi->pcie_lane_powersaving.max); |
| 2940 | ci_setup_pcie_table_entry(&pi->dpm_table.pcie_speed_table, 3, |
| 2941 | pi->pcie_gen_performance.min, |
| 2942 | pi->pcie_lane_performance.max); |
| 2943 | ci_setup_pcie_table_entry(&pi->dpm_table.pcie_speed_table, 4, |
| 2944 | pi->pcie_gen_powersaving.max, |
| 2945 | pi->pcie_lane_powersaving.max); |
| 2946 | ci_setup_pcie_table_entry(&pi->dpm_table.pcie_speed_table, 5, |
| 2947 | pi->pcie_gen_performance.max, |
| 2948 | pi->pcie_lane_performance.max); |
| 2949 | |
| 2950 | pi->dpm_table.pcie_speed_table.count = 6; |
| 2951 | |
| 2952 | return 0; |
| 2953 | } |
| 2954 | |
| 2955 | static int ci_setup_default_dpm_tables(struct radeon_device *rdev) |
| 2956 | { |
| 2957 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 2958 | struct radeon_clock_voltage_dependency_table *allowed_sclk_vddc_table = |
| 2959 | &rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk; |
| 2960 | struct radeon_clock_voltage_dependency_table *allowed_mclk_table = |
| 2961 | &rdev->pm.dpm.dyn_state.vddc_dependency_on_mclk; |
| 2962 | struct radeon_cac_leakage_table *std_voltage_table = |
| 2963 | &rdev->pm.dpm.dyn_state.cac_leakage_table; |
| 2964 | u32 i; |
| 2965 | |
| 2966 | if (allowed_sclk_vddc_table == NULL) |
| 2967 | return -EINVAL; |
| 2968 | if (allowed_sclk_vddc_table->count < 1) |
| 2969 | return -EINVAL; |
| 2970 | if (allowed_mclk_table == NULL) |
| 2971 | return -EINVAL; |
| 2972 | if (allowed_mclk_table->count < 1) |
| 2973 | return -EINVAL; |
| 2974 | |
| 2975 | memset(&pi->dpm_table, 0, sizeof(struct ci_dpm_table)); |
| 2976 | |
| 2977 | ci_reset_single_dpm_table(rdev, |
| 2978 | &pi->dpm_table.sclk_table, |
| 2979 | SMU7_MAX_LEVELS_GRAPHICS); |
| 2980 | ci_reset_single_dpm_table(rdev, |
| 2981 | &pi->dpm_table.mclk_table, |
| 2982 | SMU7_MAX_LEVELS_MEMORY); |
| 2983 | ci_reset_single_dpm_table(rdev, |
| 2984 | &pi->dpm_table.vddc_table, |
| 2985 | SMU7_MAX_LEVELS_VDDC); |
| 2986 | ci_reset_single_dpm_table(rdev, |
| 2987 | &pi->dpm_table.vddci_table, |
| 2988 | SMU7_MAX_LEVELS_VDDCI); |
| 2989 | ci_reset_single_dpm_table(rdev, |
| 2990 | &pi->dpm_table.mvdd_table, |
| 2991 | SMU7_MAX_LEVELS_MVDD); |
| 2992 | |
| 2993 | pi->dpm_table.sclk_table.count = 0; |
| 2994 | for (i = 0; i < allowed_sclk_vddc_table->count; i++) { |
| 2995 | if ((i == 0) || |
| 2996 | (pi->dpm_table.sclk_table.dpm_levels[pi->dpm_table.sclk_table.count-1].value != |
| 2997 | allowed_sclk_vddc_table->entries[i].clk)) { |
| 2998 | pi->dpm_table.sclk_table.dpm_levels[pi->dpm_table.sclk_table.count].value = |
| 2999 | allowed_sclk_vddc_table->entries[i].clk; |
| 3000 | pi->dpm_table.sclk_table.dpm_levels[pi->dpm_table.sclk_table.count].enabled = true; |
| 3001 | pi->dpm_table.sclk_table.count++; |
| 3002 | } |
| 3003 | } |
| 3004 | |
| 3005 | pi->dpm_table.mclk_table.count = 0; |
| 3006 | for (i = 0; i < allowed_mclk_table->count; i++) { |
| 3007 | if ((i==0) || |
| 3008 | (pi->dpm_table.mclk_table.dpm_levels[pi->dpm_table.mclk_table.count-1].value != |
| 3009 | allowed_mclk_table->entries[i].clk)) { |
| 3010 | pi->dpm_table.mclk_table.dpm_levels[pi->dpm_table.mclk_table.count].value = |
| 3011 | allowed_mclk_table->entries[i].clk; |
| 3012 | pi->dpm_table.mclk_table.dpm_levels[pi->dpm_table.mclk_table.count].enabled = true; |
| 3013 | pi->dpm_table.mclk_table.count++; |
| 3014 | } |
| 3015 | } |
| 3016 | |
| 3017 | for (i = 0; i < allowed_sclk_vddc_table->count; i++) { |
| 3018 | pi->dpm_table.vddc_table.dpm_levels[i].value = |
| 3019 | allowed_sclk_vddc_table->entries[i].v; |
| 3020 | pi->dpm_table.vddc_table.dpm_levels[i].param1 = |
| 3021 | std_voltage_table->entries[i].leakage; |
| 3022 | pi->dpm_table.vddc_table.dpm_levels[i].enabled = true; |
| 3023 | } |
| 3024 | pi->dpm_table.vddc_table.count = allowed_sclk_vddc_table->count; |
| 3025 | |
| 3026 | allowed_mclk_table = &rdev->pm.dpm.dyn_state.vddci_dependency_on_mclk; |
| 3027 | if (allowed_mclk_table) { |
| 3028 | for (i = 0; i < allowed_mclk_table->count; i++) { |
| 3029 | pi->dpm_table.vddci_table.dpm_levels[i].value = |
| 3030 | allowed_mclk_table->entries[i].v; |
| 3031 | pi->dpm_table.vddci_table.dpm_levels[i].enabled = true; |
| 3032 | } |
| 3033 | pi->dpm_table.vddci_table.count = allowed_mclk_table->count; |
| 3034 | } |
| 3035 | |
| 3036 | allowed_mclk_table = &rdev->pm.dpm.dyn_state.mvdd_dependency_on_mclk; |
| 3037 | if (allowed_mclk_table) { |
| 3038 | for (i = 0; i < allowed_mclk_table->count; i++) { |
| 3039 | pi->dpm_table.mvdd_table.dpm_levels[i].value = |
| 3040 | allowed_mclk_table->entries[i].v; |
| 3041 | pi->dpm_table.mvdd_table.dpm_levels[i].enabled = true; |
| 3042 | } |
| 3043 | pi->dpm_table.mvdd_table.count = allowed_mclk_table->count; |
| 3044 | } |
| 3045 | |
| 3046 | ci_setup_default_pcie_tables(rdev); |
| 3047 | |
| 3048 | return 0; |
| 3049 | } |
| 3050 | |
| 3051 | static int ci_find_boot_level(struct ci_single_dpm_table *table, |
| 3052 | u32 value, u32 *boot_level) |
| 3053 | { |
| 3054 | u32 i; |
| 3055 | int ret = -EINVAL; |
| 3056 | |
| 3057 | for(i = 0; i < table->count; i++) { |
| 3058 | if (value == table->dpm_levels[i].value) { |
| 3059 | *boot_level = i; |
| 3060 | ret = 0; |
| 3061 | } |
| 3062 | } |
| 3063 | |
| 3064 | return ret; |
| 3065 | } |
| 3066 | |
| 3067 | static int ci_init_smc_table(struct radeon_device *rdev) |
| 3068 | { |
| 3069 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 3070 | struct ci_ulv_parm *ulv = &pi->ulv; |
| 3071 | struct radeon_ps *radeon_boot_state = rdev->pm.dpm.boot_ps; |
| 3072 | SMU7_Discrete_DpmTable *table = &pi->smc_state_table; |
| 3073 | int ret; |
| 3074 | |
| 3075 | ret = ci_setup_default_dpm_tables(rdev); |
| 3076 | if (ret) |
| 3077 | return ret; |
| 3078 | |
| 3079 | if (pi->voltage_control != CISLANDS_VOLTAGE_CONTROL_NONE) |
| 3080 | ci_populate_smc_voltage_tables(rdev, table); |
| 3081 | |
| 3082 | ci_init_fps_limits(rdev); |
| 3083 | |
| 3084 | if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_HARDWAREDC) |
| 3085 | table->SystemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC; |
| 3086 | |
| 3087 | if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_STEPVDDC) |
| 3088 | table->SystemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC; |
| 3089 | |
| 3090 | if (pi->mem_gddr5) |
| 3091 | table->SystemFlags |= PPSMC_SYSTEMFLAG_GDDR5; |
| 3092 | |
| 3093 | if (ulv->supported) { |
| 3094 | ret = ci_populate_ulv_state(rdev, &pi->smc_state_table.Ulv); |
| 3095 | if (ret) |
| 3096 | return ret; |
| 3097 | WREG32_SMC(CG_ULV_PARAMETER, ulv->cg_ulv_parameter); |
| 3098 | } |
| 3099 | |
| 3100 | ret = ci_populate_all_graphic_levels(rdev); |
| 3101 | if (ret) |
| 3102 | return ret; |
| 3103 | |
| 3104 | ret = ci_populate_all_memory_levels(rdev); |
| 3105 | if (ret) |
| 3106 | return ret; |
| 3107 | |
| 3108 | ci_populate_smc_link_level(rdev, table); |
| 3109 | |
| 3110 | ret = ci_populate_smc_acpi_level(rdev, table); |
| 3111 | if (ret) |
| 3112 | return ret; |
| 3113 | |
| 3114 | ret = ci_populate_smc_vce_level(rdev, table); |
| 3115 | if (ret) |
| 3116 | return ret; |
| 3117 | |
| 3118 | ret = ci_populate_smc_acp_level(rdev, table); |
| 3119 | if (ret) |
| 3120 | return ret; |
| 3121 | |
| 3122 | ret = ci_populate_smc_samu_level(rdev, table); |
| 3123 | if (ret) |
| 3124 | return ret; |
| 3125 | |
| 3126 | ret = ci_do_program_memory_timing_parameters(rdev); |
| 3127 | if (ret) |
| 3128 | return ret; |
| 3129 | |
| 3130 | ret = ci_populate_smc_uvd_level(rdev, table); |
| 3131 | if (ret) |
| 3132 | return ret; |
| 3133 | |
| 3134 | table->UvdBootLevel = 0; |
| 3135 | table->VceBootLevel = 0; |
| 3136 | table->AcpBootLevel = 0; |
| 3137 | table->SamuBootLevel = 0; |
| 3138 | table->GraphicsBootLevel = 0; |
| 3139 | table->MemoryBootLevel = 0; |
| 3140 | |
| 3141 | ret = ci_find_boot_level(&pi->dpm_table.sclk_table, |
| 3142 | pi->vbios_boot_state.sclk_bootup_value, |
| 3143 | (u32 *)&pi->smc_state_table.GraphicsBootLevel); |
| 3144 | |
| 3145 | ret = ci_find_boot_level(&pi->dpm_table.mclk_table, |
| 3146 | pi->vbios_boot_state.mclk_bootup_value, |
| 3147 | (u32 *)&pi->smc_state_table.MemoryBootLevel); |
| 3148 | |
| 3149 | table->BootVddc = pi->vbios_boot_state.vddc_bootup_value; |
| 3150 | table->BootVddci = pi->vbios_boot_state.vddci_bootup_value; |
| 3151 | table->BootMVdd = pi->vbios_boot_state.mvdd_bootup_value; |
| 3152 | |
| 3153 | ci_populate_smc_initial_state(rdev, radeon_boot_state); |
| 3154 | |
| 3155 | ret = ci_populate_bapm_parameters_in_dpm_table(rdev); |
| 3156 | if (ret) |
| 3157 | return ret; |
| 3158 | |
| 3159 | table->UVDInterval = 1; |
| 3160 | table->VCEInterval = 1; |
| 3161 | table->ACPInterval = 1; |
| 3162 | table->SAMUInterval = 1; |
| 3163 | table->GraphicsVoltageChangeEnable = 1; |
| 3164 | table->GraphicsThermThrottleEnable = 1; |
| 3165 | table->GraphicsInterval = 1; |
| 3166 | table->VoltageInterval = 1; |
| 3167 | table->ThermalInterval = 1; |
| 3168 | table->TemperatureLimitHigh = (u16)((pi->thermal_temp_setting.temperature_high * |
| 3169 | CISLANDS_Q88_FORMAT_CONVERSION_UNIT) / 1000); |
| 3170 | table->TemperatureLimitLow = (u16)((pi->thermal_temp_setting.temperature_low * |
| 3171 | CISLANDS_Q88_FORMAT_CONVERSION_UNIT) / 1000); |
| 3172 | table->MemoryVoltageChangeEnable = 1; |
| 3173 | table->MemoryInterval = 1; |
| 3174 | table->VoltageResponseTime = 0; |
| 3175 | table->VddcVddciDelta = 4000; |
| 3176 | table->PhaseResponseTime = 0; |
| 3177 | table->MemoryThermThrottleEnable = 1; |
| 3178 | table->PCIeBootLinkLevel = 0; |
| 3179 | table->PCIeGenInterval = 1; |
| 3180 | if (pi->voltage_control == CISLANDS_VOLTAGE_CONTROL_BY_SVID2) |
| 3181 | table->SVI2Enable = 1; |
| 3182 | else |
| 3183 | table->SVI2Enable = 0; |
| 3184 | |
| 3185 | table->ThermGpio = 17; |
| 3186 | table->SclkStepSize = 0x4000; |
| 3187 | |
| 3188 | table->SystemFlags = cpu_to_be32(table->SystemFlags); |
| 3189 | table->SmioMaskVddcVid = cpu_to_be32(table->SmioMaskVddcVid); |
| 3190 | table->SmioMaskVddcPhase = cpu_to_be32(table->SmioMaskVddcPhase); |
| 3191 | table->SmioMaskVddciVid = cpu_to_be32(table->SmioMaskVddciVid); |
| 3192 | table->SmioMaskMvddVid = cpu_to_be32(table->SmioMaskMvddVid); |
| 3193 | table->SclkStepSize = cpu_to_be32(table->SclkStepSize); |
| 3194 | table->TemperatureLimitHigh = cpu_to_be16(table->TemperatureLimitHigh); |
| 3195 | table->TemperatureLimitLow = cpu_to_be16(table->TemperatureLimitLow); |
| 3196 | table->VddcVddciDelta = cpu_to_be16(table->VddcVddciDelta); |
| 3197 | table->VoltageResponseTime = cpu_to_be16(table->VoltageResponseTime); |
| 3198 | table->PhaseResponseTime = cpu_to_be16(table->PhaseResponseTime); |
| 3199 | table->BootVddc = cpu_to_be16(table->BootVddc * VOLTAGE_SCALE); |
| 3200 | table->BootVddci = cpu_to_be16(table->BootVddci * VOLTAGE_SCALE); |
| 3201 | table->BootMVdd = cpu_to_be16(table->BootMVdd * VOLTAGE_SCALE); |
| 3202 | |
| 3203 | ret = ci_copy_bytes_to_smc(rdev, |
| 3204 | pi->dpm_table_start + |
| 3205 | offsetof(SMU7_Discrete_DpmTable, SystemFlags), |
| 3206 | (u8 *)&table->SystemFlags, |
| 3207 | sizeof(SMU7_Discrete_DpmTable) - 3 * sizeof(SMU7_PIDController), |
| 3208 | pi->sram_end); |
| 3209 | if (ret) |
| 3210 | return ret; |
| 3211 | |
| 3212 | return 0; |
| 3213 | } |
| 3214 | |
| 3215 | static void ci_trim_single_dpm_states(struct radeon_device *rdev, |
| 3216 | struct ci_single_dpm_table *dpm_table, |
| 3217 | u32 low_limit, u32 high_limit) |
| 3218 | { |
| 3219 | u32 i; |
| 3220 | |
| 3221 | for (i = 0; i < dpm_table->count; i++) { |
| 3222 | if ((dpm_table->dpm_levels[i].value < low_limit) || |
| 3223 | (dpm_table->dpm_levels[i].value > high_limit)) |
| 3224 | dpm_table->dpm_levels[i].enabled = false; |
| 3225 | else |
| 3226 | dpm_table->dpm_levels[i].enabled = true; |
| 3227 | } |
| 3228 | } |
| 3229 | |
| 3230 | static void ci_trim_pcie_dpm_states(struct radeon_device *rdev, |
| 3231 | u32 speed_low, u32 lanes_low, |
| 3232 | u32 speed_high, u32 lanes_high) |
| 3233 | { |
| 3234 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 3235 | struct ci_single_dpm_table *pcie_table = &pi->dpm_table.pcie_speed_table; |
| 3236 | u32 i, j; |
| 3237 | |
| 3238 | for (i = 0; i < pcie_table->count; i++) { |
| 3239 | if ((pcie_table->dpm_levels[i].value < speed_low) || |
| 3240 | (pcie_table->dpm_levels[i].param1 < lanes_low) || |
| 3241 | (pcie_table->dpm_levels[i].value > speed_high) || |
| 3242 | (pcie_table->dpm_levels[i].param1 > lanes_high)) |
| 3243 | pcie_table->dpm_levels[i].enabled = false; |
| 3244 | else |
| 3245 | pcie_table->dpm_levels[i].enabled = true; |
| 3246 | } |
| 3247 | |
| 3248 | for (i = 0; i < pcie_table->count; i++) { |
| 3249 | if (pcie_table->dpm_levels[i].enabled) { |
| 3250 | for (j = i + 1; j < pcie_table->count; j++) { |
| 3251 | if (pcie_table->dpm_levels[j].enabled) { |
| 3252 | if ((pcie_table->dpm_levels[i].value == pcie_table->dpm_levels[j].value) && |
| 3253 | (pcie_table->dpm_levels[i].param1 == pcie_table->dpm_levels[j].param1)) |
| 3254 | pcie_table->dpm_levels[j].enabled = false; |
| 3255 | } |
| 3256 | } |
| 3257 | } |
| 3258 | } |
| 3259 | } |
| 3260 | |
| 3261 | static int ci_trim_dpm_states(struct radeon_device *rdev, |
| 3262 | struct radeon_ps *radeon_state) |
| 3263 | { |
| 3264 | struct ci_ps *state = ci_get_ps(radeon_state); |
| 3265 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 3266 | u32 high_limit_count; |
| 3267 | |
| 3268 | if (state->performance_level_count < 1) |
| 3269 | return -EINVAL; |
| 3270 | |
| 3271 | if (state->performance_level_count == 1) |
| 3272 | high_limit_count = 0; |
| 3273 | else |
| 3274 | high_limit_count = 1; |
| 3275 | |
| 3276 | ci_trim_single_dpm_states(rdev, |
| 3277 | &pi->dpm_table.sclk_table, |
| 3278 | state->performance_levels[0].sclk, |
| 3279 | state->performance_levels[high_limit_count].sclk); |
| 3280 | |
| 3281 | ci_trim_single_dpm_states(rdev, |
| 3282 | &pi->dpm_table.mclk_table, |
| 3283 | state->performance_levels[0].mclk, |
| 3284 | state->performance_levels[high_limit_count].mclk); |
| 3285 | |
| 3286 | ci_trim_pcie_dpm_states(rdev, |
| 3287 | state->performance_levels[0].pcie_gen, |
| 3288 | state->performance_levels[0].pcie_lane, |
| 3289 | state->performance_levels[high_limit_count].pcie_gen, |
| 3290 | state->performance_levels[high_limit_count].pcie_lane); |
| 3291 | |
| 3292 | return 0; |
| 3293 | } |
| 3294 | |
| 3295 | static int ci_apply_disp_minimum_voltage_request(struct radeon_device *rdev) |
| 3296 | { |
| 3297 | struct radeon_clock_voltage_dependency_table *disp_voltage_table = |
| 3298 | &rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk; |
| 3299 | struct radeon_clock_voltage_dependency_table *vddc_table = |
| 3300 | &rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk; |
| 3301 | u32 requested_voltage = 0; |
| 3302 | u32 i; |
| 3303 | |
| 3304 | if (disp_voltage_table == NULL) |
| 3305 | return -EINVAL; |
| 3306 | if (!disp_voltage_table->count) |
| 3307 | return -EINVAL; |
| 3308 | |
| 3309 | for (i = 0; i < disp_voltage_table->count; i++) { |
| 3310 | if (rdev->clock.current_dispclk == disp_voltage_table->entries[i].clk) |
| 3311 | requested_voltage = disp_voltage_table->entries[i].v; |
| 3312 | } |
| 3313 | |
| 3314 | for (i = 0; i < vddc_table->count; i++) { |
| 3315 | if (requested_voltage <= vddc_table->entries[i].v) { |
| 3316 | requested_voltage = vddc_table->entries[i].v; |
| 3317 | return (ci_send_msg_to_smc_with_parameter(rdev, |
| 3318 | PPSMC_MSG_VddC_Request, |
| 3319 | requested_voltage * VOLTAGE_SCALE) == PPSMC_Result_OK) ? |
| 3320 | 0 : -EINVAL; |
| 3321 | } |
| 3322 | } |
| 3323 | |
| 3324 | return -EINVAL; |
| 3325 | } |
| 3326 | |
| 3327 | static int ci_upload_dpm_level_enable_mask(struct radeon_device *rdev) |
| 3328 | { |
| 3329 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 3330 | PPSMC_Result result; |
| 3331 | |
| 3332 | if (!pi->sclk_dpm_key_disabled) { |
| 3333 | if (pi->dpm_level_enable_mask.sclk_dpm_enable_mask) { |
| 3334 | result = ci_send_msg_to_smc_with_parameter(rdev, |
| 3335 | PPSMC_MSG_SCLKDPM_SetEnabledMask, |
| 3336 | pi->dpm_level_enable_mask.sclk_dpm_enable_mask); |
| 3337 | if (result != PPSMC_Result_OK) |
| 3338 | return -EINVAL; |
| 3339 | } |
| 3340 | } |
| 3341 | |
| 3342 | if (!pi->mclk_dpm_key_disabled) { |
| 3343 | if (pi->dpm_level_enable_mask.mclk_dpm_enable_mask) { |
| 3344 | result = ci_send_msg_to_smc_with_parameter(rdev, |
| 3345 | PPSMC_MSG_MCLKDPM_SetEnabledMask, |
| 3346 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask); |
| 3347 | if (result != PPSMC_Result_OK) |
| 3348 | return -EINVAL; |
| 3349 | } |
| 3350 | } |
| 3351 | |
| 3352 | if (!pi->pcie_dpm_key_disabled) { |
| 3353 | if (pi->dpm_level_enable_mask.pcie_dpm_enable_mask) { |
| 3354 | result = ci_send_msg_to_smc_with_parameter(rdev, |
| 3355 | PPSMC_MSG_PCIeDPM_SetEnabledMask, |
| 3356 | pi->dpm_level_enable_mask.pcie_dpm_enable_mask); |
| 3357 | if (result != PPSMC_Result_OK) |
| 3358 | return -EINVAL; |
| 3359 | } |
| 3360 | } |
| 3361 | |
| 3362 | ci_apply_disp_minimum_voltage_request(rdev); |
| 3363 | |
| 3364 | return 0; |
| 3365 | } |
| 3366 | |
| 3367 | static void ci_find_dpm_states_clocks_in_dpm_table(struct radeon_device *rdev, |
| 3368 | struct radeon_ps *radeon_state) |
| 3369 | { |
| 3370 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 3371 | struct ci_ps *state = ci_get_ps(radeon_state); |
| 3372 | struct ci_single_dpm_table *sclk_table = &pi->dpm_table.sclk_table; |
| 3373 | u32 sclk = state->performance_levels[state->performance_level_count-1].sclk; |
| 3374 | struct ci_single_dpm_table *mclk_table = &pi->dpm_table.mclk_table; |
| 3375 | u32 mclk = state->performance_levels[state->performance_level_count-1].mclk; |
| 3376 | u32 i; |
| 3377 | |
| 3378 | pi->need_update_smu7_dpm_table = 0; |
| 3379 | |
| 3380 | for (i = 0; i < sclk_table->count; i++) { |
| 3381 | if (sclk == sclk_table->dpm_levels[i].value) |
| 3382 | break; |
| 3383 | } |
| 3384 | |
| 3385 | if (i >= sclk_table->count) { |
| 3386 | pi->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK; |
| 3387 | } else { |
| 3388 | /* XXX check display min clock requirements */ |
| 3389 | if (0 != CISLAND_MINIMUM_ENGINE_CLOCK) |
| 3390 | pi->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_SCLK; |
| 3391 | } |
| 3392 | |
| 3393 | for (i = 0; i < mclk_table->count; i++) { |
| 3394 | if (mclk == mclk_table->dpm_levels[i].value) |
| 3395 | break; |
| 3396 | } |
| 3397 | |
| 3398 | if (i >= mclk_table->count) |
| 3399 | pi->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_MCLK; |
| 3400 | |
| 3401 | if (rdev->pm.dpm.current_active_crtc_count != |
| 3402 | rdev->pm.dpm.new_active_crtc_count) |
| 3403 | pi->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_MCLK; |
| 3404 | } |
| 3405 | |
| 3406 | static int ci_populate_and_upload_sclk_mclk_dpm_levels(struct radeon_device *rdev, |
| 3407 | struct radeon_ps *radeon_state) |
| 3408 | { |
| 3409 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 3410 | struct ci_ps *state = ci_get_ps(radeon_state); |
| 3411 | u32 sclk = state->performance_levels[state->performance_level_count-1].sclk; |
| 3412 | u32 mclk = state->performance_levels[state->performance_level_count-1].mclk; |
| 3413 | struct ci_dpm_table *dpm_table = &pi->dpm_table; |
| 3414 | int ret; |
| 3415 | |
| 3416 | if (!pi->need_update_smu7_dpm_table) |
| 3417 | return 0; |
| 3418 | |
| 3419 | if (pi->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_SCLK) |
| 3420 | dpm_table->sclk_table.dpm_levels[dpm_table->sclk_table.count-1].value = sclk; |
| 3421 | |
| 3422 | if (pi->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK) |
| 3423 | dpm_table->mclk_table.dpm_levels[dpm_table->mclk_table.count-1].value = mclk; |
| 3424 | |
| 3425 | if (pi->need_update_smu7_dpm_table & (DPMTABLE_OD_UPDATE_SCLK | DPMTABLE_UPDATE_SCLK)) { |
| 3426 | ret = ci_populate_all_graphic_levels(rdev); |
| 3427 | if (ret) |
| 3428 | return ret; |
| 3429 | } |
| 3430 | |
| 3431 | if (pi->need_update_smu7_dpm_table & (DPMTABLE_OD_UPDATE_MCLK | DPMTABLE_UPDATE_MCLK)) { |
| 3432 | ret = ci_populate_all_memory_levels(rdev); |
| 3433 | if (ret) |
| 3434 | return ret; |
| 3435 | } |
| 3436 | |
| 3437 | return 0; |
| 3438 | } |
| 3439 | |
| 3440 | static int ci_enable_uvd_dpm(struct radeon_device *rdev, bool enable) |
| 3441 | { |
| 3442 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 3443 | const struct radeon_clock_and_voltage_limits *max_limits; |
| 3444 | int i; |
| 3445 | |
| 3446 | if (rdev->pm.dpm.ac_power) |
| 3447 | max_limits = &rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac; |
| 3448 | else |
| 3449 | max_limits = &rdev->pm.dpm.dyn_state.max_clock_voltage_on_dc; |
| 3450 | |
| 3451 | if (enable) { |
| 3452 | pi->dpm_level_enable_mask.uvd_dpm_enable_mask = 0; |
| 3453 | |
| 3454 | for (i = rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.count - 1; i >= 0; i--) { |
| 3455 | if (rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[i].v <= max_limits->vddc) { |
| 3456 | pi->dpm_level_enable_mask.uvd_dpm_enable_mask |= 1 << i; |
| 3457 | |
| 3458 | if (!pi->caps_uvd_dpm) |
| 3459 | break; |
| 3460 | } |
| 3461 | } |
| 3462 | |
| 3463 | ci_send_msg_to_smc_with_parameter(rdev, |
| 3464 | PPSMC_MSG_UVDDPM_SetEnabledMask, |
| 3465 | pi->dpm_level_enable_mask.uvd_dpm_enable_mask); |
| 3466 | |
| 3467 | if (pi->last_mclk_dpm_enable_mask & 0x1) { |
| 3468 | pi->uvd_enabled = true; |
| 3469 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask &= 0xFFFFFFFE; |
| 3470 | ci_send_msg_to_smc_with_parameter(rdev, |
| 3471 | PPSMC_MSG_MCLKDPM_SetEnabledMask, |
| 3472 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask); |
| 3473 | } |
| 3474 | } else { |
| 3475 | if (pi->last_mclk_dpm_enable_mask & 0x1) { |
| 3476 | pi->uvd_enabled = false; |
| 3477 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask |= 1; |
| 3478 | ci_send_msg_to_smc_with_parameter(rdev, |
| 3479 | PPSMC_MSG_MCLKDPM_SetEnabledMask, |
| 3480 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask); |
| 3481 | } |
| 3482 | } |
| 3483 | |
| 3484 | return (ci_send_msg_to_smc(rdev, enable ? |
| 3485 | PPSMC_MSG_UVDDPM_Enable : PPSMC_MSG_UVDDPM_Disable) == PPSMC_Result_OK) ? |
| 3486 | 0 : -EINVAL; |
| 3487 | } |
| 3488 | |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 3489 | static int ci_enable_vce_dpm(struct radeon_device *rdev, bool enable) |
| 3490 | { |
| 3491 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 3492 | const struct radeon_clock_and_voltage_limits *max_limits; |
| 3493 | int i; |
| 3494 | |
| 3495 | if (rdev->pm.dpm.ac_power) |
| 3496 | max_limits = &rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac; |
| 3497 | else |
| 3498 | max_limits = &rdev->pm.dpm.dyn_state.max_clock_voltage_on_dc; |
| 3499 | |
| 3500 | if (enable) { |
| 3501 | pi->dpm_level_enable_mask.vce_dpm_enable_mask = 0; |
| 3502 | for (i = rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.count - 1; i >= 0; i--) { |
| 3503 | if (rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries[i].v <= max_limits->vddc) { |
| 3504 | pi->dpm_level_enable_mask.vce_dpm_enable_mask |= 1 << i; |
| 3505 | |
| 3506 | if (!pi->caps_vce_dpm) |
| 3507 | break; |
| 3508 | } |
| 3509 | } |
| 3510 | |
| 3511 | ci_send_msg_to_smc_with_parameter(rdev, |
| 3512 | PPSMC_MSG_VCEDPM_SetEnabledMask, |
| 3513 | pi->dpm_level_enable_mask.vce_dpm_enable_mask); |
| 3514 | } |
| 3515 | |
| 3516 | return (ci_send_msg_to_smc(rdev, enable ? |
| 3517 | PPSMC_MSG_VCEDPM_Enable : PPSMC_MSG_VCEDPM_Disable) == PPSMC_Result_OK) ? |
| 3518 | 0 : -EINVAL; |
| 3519 | } |
| 3520 | |
Alex Deucher | 8cd3668 | 2013-08-23 11:05:24 -0400 | [diff] [blame] | 3521 | #if 0 |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 3522 | static int ci_enable_samu_dpm(struct radeon_device *rdev, bool enable) |
| 3523 | { |
| 3524 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 3525 | const struct radeon_clock_and_voltage_limits *max_limits; |
| 3526 | int i; |
| 3527 | |
| 3528 | if (rdev->pm.dpm.ac_power) |
| 3529 | max_limits = &rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac; |
| 3530 | else |
| 3531 | max_limits = &rdev->pm.dpm.dyn_state.max_clock_voltage_on_dc; |
| 3532 | |
| 3533 | if (enable) { |
| 3534 | pi->dpm_level_enable_mask.samu_dpm_enable_mask = 0; |
| 3535 | for (i = rdev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.count - 1; i >= 0; i--) { |
| 3536 | if (rdev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries[i].v <= max_limits->vddc) { |
| 3537 | pi->dpm_level_enable_mask.samu_dpm_enable_mask |= 1 << i; |
| 3538 | |
| 3539 | if (!pi->caps_samu_dpm) |
| 3540 | break; |
| 3541 | } |
| 3542 | } |
| 3543 | |
| 3544 | ci_send_msg_to_smc_with_parameter(rdev, |
| 3545 | PPSMC_MSG_SAMUDPM_SetEnabledMask, |
| 3546 | pi->dpm_level_enable_mask.samu_dpm_enable_mask); |
| 3547 | } |
| 3548 | return (ci_send_msg_to_smc(rdev, enable ? |
| 3549 | PPSMC_MSG_SAMUDPM_Enable : PPSMC_MSG_SAMUDPM_Disable) == PPSMC_Result_OK) ? |
| 3550 | 0 : -EINVAL; |
| 3551 | } |
| 3552 | |
| 3553 | static int ci_enable_acp_dpm(struct radeon_device *rdev, bool enable) |
| 3554 | { |
| 3555 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 3556 | const struct radeon_clock_and_voltage_limits *max_limits; |
| 3557 | int i; |
| 3558 | |
| 3559 | if (rdev->pm.dpm.ac_power) |
| 3560 | max_limits = &rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac; |
| 3561 | else |
| 3562 | max_limits = &rdev->pm.dpm.dyn_state.max_clock_voltage_on_dc; |
| 3563 | |
| 3564 | if (enable) { |
| 3565 | pi->dpm_level_enable_mask.acp_dpm_enable_mask = 0; |
| 3566 | for (i = rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.count - 1; i >= 0; i--) { |
| 3567 | if (rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries[i].v <= max_limits->vddc) { |
| 3568 | pi->dpm_level_enable_mask.acp_dpm_enable_mask |= 1 << i; |
| 3569 | |
| 3570 | if (!pi->caps_acp_dpm) |
| 3571 | break; |
| 3572 | } |
| 3573 | } |
| 3574 | |
| 3575 | ci_send_msg_to_smc_with_parameter(rdev, |
| 3576 | PPSMC_MSG_ACPDPM_SetEnabledMask, |
| 3577 | pi->dpm_level_enable_mask.acp_dpm_enable_mask); |
| 3578 | } |
| 3579 | |
| 3580 | return (ci_send_msg_to_smc(rdev, enable ? |
| 3581 | PPSMC_MSG_ACPDPM_Enable : PPSMC_MSG_ACPDPM_Disable) == PPSMC_Result_OK) ? |
| 3582 | 0 : -EINVAL; |
| 3583 | } |
| 3584 | #endif |
| 3585 | |
| 3586 | static int ci_update_uvd_dpm(struct radeon_device *rdev, bool gate) |
| 3587 | { |
| 3588 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 3589 | u32 tmp; |
| 3590 | |
| 3591 | if (!gate) { |
| 3592 | if (pi->caps_uvd_dpm || |
| 3593 | (rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.count <= 0)) |
| 3594 | pi->smc_state_table.UvdBootLevel = 0; |
| 3595 | else |
| 3596 | pi->smc_state_table.UvdBootLevel = |
| 3597 | rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.count - 1; |
| 3598 | |
| 3599 | tmp = RREG32_SMC(DPM_TABLE_475); |
| 3600 | tmp &= ~UvdBootLevel_MASK; |
| 3601 | tmp |= UvdBootLevel(pi->smc_state_table.UvdBootLevel); |
| 3602 | WREG32_SMC(DPM_TABLE_475, tmp); |
| 3603 | } |
| 3604 | |
| 3605 | return ci_enable_uvd_dpm(rdev, !gate); |
| 3606 | } |
| 3607 | |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 3608 | static u8 ci_get_vce_boot_level(struct radeon_device *rdev) |
| 3609 | { |
| 3610 | u8 i; |
| 3611 | u32 min_evclk = 30000; /* ??? */ |
| 3612 | struct radeon_vce_clock_voltage_dependency_table *table = |
| 3613 | &rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table; |
| 3614 | |
| 3615 | for (i = 0; i < table->count; i++) { |
| 3616 | if (table->entries[i].evclk >= min_evclk) |
| 3617 | return i; |
| 3618 | } |
| 3619 | |
| 3620 | return table->count - 1; |
| 3621 | } |
| 3622 | |
| 3623 | static int ci_update_vce_dpm(struct radeon_device *rdev, |
| 3624 | struct radeon_ps *radeon_new_state, |
| 3625 | struct radeon_ps *radeon_current_state) |
| 3626 | { |
| 3627 | struct ci_power_info *pi = ci_get_pi(rdev); |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 3628 | int ret = 0; |
| 3629 | u32 tmp; |
| 3630 | |
Alex Deucher | 8cd3668 | 2013-08-23 11:05:24 -0400 | [diff] [blame] | 3631 | if (radeon_current_state->evclk != radeon_new_state->evclk) { |
| 3632 | if (radeon_new_state->evclk) { |
Alex Deucher | a1d6f97 | 2013-09-06 12:33:04 -0400 | [diff] [blame] | 3633 | /* turn the clocks on when encoding */ |
| 3634 | cik_update_cg(rdev, RADEON_CG_BLOCK_VCE, false); |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 3635 | |
Alex Deucher | a1d6f97 | 2013-09-06 12:33:04 -0400 | [diff] [blame] | 3636 | pi->smc_state_table.VceBootLevel = ci_get_vce_boot_level(rdev); |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 3637 | tmp = RREG32_SMC(DPM_TABLE_475); |
| 3638 | tmp &= ~VceBootLevel_MASK; |
| 3639 | tmp |= VceBootLevel(pi->smc_state_table.VceBootLevel); |
| 3640 | WREG32_SMC(DPM_TABLE_475, tmp); |
| 3641 | |
| 3642 | ret = ci_enable_vce_dpm(rdev, true); |
| 3643 | } else { |
Alex Deucher | a1d6f97 | 2013-09-06 12:33:04 -0400 | [diff] [blame] | 3644 | /* turn the clocks off when not encoding */ |
| 3645 | cik_update_cg(rdev, RADEON_CG_BLOCK_VCE, true); |
| 3646 | |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 3647 | ret = ci_enable_vce_dpm(rdev, false); |
| 3648 | } |
| 3649 | } |
| 3650 | return ret; |
| 3651 | } |
| 3652 | |
Alex Deucher | 8cd3668 | 2013-08-23 11:05:24 -0400 | [diff] [blame] | 3653 | #if 0 |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 3654 | static int ci_update_samu_dpm(struct radeon_device *rdev, bool gate) |
| 3655 | { |
| 3656 | return ci_enable_samu_dpm(rdev, gate); |
| 3657 | } |
| 3658 | |
| 3659 | static int ci_update_acp_dpm(struct radeon_device *rdev, bool gate) |
| 3660 | { |
| 3661 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 3662 | u32 tmp; |
| 3663 | |
| 3664 | if (!gate) { |
| 3665 | pi->smc_state_table.AcpBootLevel = 0; |
| 3666 | |
| 3667 | tmp = RREG32_SMC(DPM_TABLE_475); |
| 3668 | tmp &= ~AcpBootLevel_MASK; |
| 3669 | tmp |= AcpBootLevel(pi->smc_state_table.AcpBootLevel); |
| 3670 | WREG32_SMC(DPM_TABLE_475, tmp); |
| 3671 | } |
| 3672 | |
| 3673 | return ci_enable_acp_dpm(rdev, !gate); |
| 3674 | } |
| 3675 | #endif |
| 3676 | |
| 3677 | static int ci_generate_dpm_level_enable_mask(struct radeon_device *rdev, |
| 3678 | struct radeon_ps *radeon_state) |
| 3679 | { |
| 3680 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 3681 | int ret; |
| 3682 | |
| 3683 | ret = ci_trim_dpm_states(rdev, radeon_state); |
| 3684 | if (ret) |
| 3685 | return ret; |
| 3686 | |
| 3687 | pi->dpm_level_enable_mask.sclk_dpm_enable_mask = |
| 3688 | ci_get_dpm_level_enable_mask_value(&pi->dpm_table.sclk_table); |
| 3689 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask = |
| 3690 | ci_get_dpm_level_enable_mask_value(&pi->dpm_table.mclk_table); |
| 3691 | pi->last_mclk_dpm_enable_mask = |
| 3692 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask; |
| 3693 | if (pi->uvd_enabled) { |
| 3694 | if (pi->dpm_level_enable_mask.mclk_dpm_enable_mask & 1) |
| 3695 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask &= 0xFFFFFFFE; |
| 3696 | } |
| 3697 | pi->dpm_level_enable_mask.pcie_dpm_enable_mask = |
| 3698 | ci_get_dpm_level_enable_mask_value(&pi->dpm_table.pcie_speed_table); |
| 3699 | |
| 3700 | return 0; |
| 3701 | } |
| 3702 | |
Alex Deucher | 89536fd | 2013-07-15 18:14:24 -0400 | [diff] [blame] | 3703 | static u32 ci_get_lowest_enabled_level(struct radeon_device *rdev, |
| 3704 | u32 level_mask) |
| 3705 | { |
| 3706 | u32 level = 0; |
| 3707 | |
| 3708 | while ((level_mask & (1 << level)) == 0) |
| 3709 | level++; |
| 3710 | |
| 3711 | return level; |
| 3712 | } |
| 3713 | |
| 3714 | |
| 3715 | int ci_dpm_force_performance_level(struct radeon_device *rdev, |
| 3716 | enum radeon_dpm_forced_level level) |
| 3717 | { |
| 3718 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 3719 | PPSMC_Result smc_result; |
| 3720 | u32 tmp, levels, i; |
| 3721 | int ret; |
| 3722 | |
| 3723 | if (level == RADEON_DPM_FORCED_LEVEL_HIGH) { |
| 3724 | if ((!pi->sclk_dpm_key_disabled) && |
| 3725 | pi->dpm_level_enable_mask.sclk_dpm_enable_mask) { |
| 3726 | levels = 0; |
| 3727 | tmp = pi->dpm_level_enable_mask.sclk_dpm_enable_mask; |
| 3728 | while (tmp >>= 1) |
| 3729 | levels++; |
| 3730 | if (levels) { |
| 3731 | ret = ci_dpm_force_state_sclk(rdev, levels); |
| 3732 | if (ret) |
| 3733 | return ret; |
| 3734 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 3735 | tmp = (RREG32_SMC(TARGET_AND_CURRENT_PROFILE_INDEX) & |
| 3736 | CURR_SCLK_INDEX_MASK) >> CURR_SCLK_INDEX_SHIFT; |
| 3737 | if (tmp == levels) |
| 3738 | break; |
| 3739 | udelay(1); |
| 3740 | } |
| 3741 | } |
| 3742 | } |
| 3743 | if ((!pi->mclk_dpm_key_disabled) && |
| 3744 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask) { |
| 3745 | levels = 0; |
| 3746 | tmp = pi->dpm_level_enable_mask.mclk_dpm_enable_mask; |
| 3747 | while (tmp >>= 1) |
| 3748 | levels++; |
| 3749 | if (levels) { |
| 3750 | ret = ci_dpm_force_state_mclk(rdev, levels); |
| 3751 | if (ret) |
| 3752 | return ret; |
| 3753 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 3754 | tmp = (RREG32_SMC(TARGET_AND_CURRENT_PROFILE_INDEX) & |
| 3755 | CURR_MCLK_INDEX_MASK) >> CURR_MCLK_INDEX_SHIFT; |
| 3756 | if (tmp == levels) |
| 3757 | break; |
| 3758 | udelay(1); |
| 3759 | } |
| 3760 | } |
| 3761 | } |
| 3762 | if ((!pi->pcie_dpm_key_disabled) && |
| 3763 | pi->dpm_level_enable_mask.pcie_dpm_enable_mask) { |
| 3764 | levels = 0; |
| 3765 | tmp = pi->dpm_level_enable_mask.pcie_dpm_enable_mask; |
| 3766 | while (tmp >>= 1) |
| 3767 | levels++; |
| 3768 | if (levels) { |
| 3769 | ret = ci_dpm_force_state_pcie(rdev, level); |
| 3770 | if (ret) |
| 3771 | return ret; |
| 3772 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 3773 | tmp = (RREG32_SMC(TARGET_AND_CURRENT_PROFILE_INDEX_1) & |
| 3774 | CURR_PCIE_INDEX_MASK) >> CURR_PCIE_INDEX_SHIFT; |
| 3775 | if (tmp == levels) |
| 3776 | break; |
| 3777 | udelay(1); |
| 3778 | } |
| 3779 | } |
| 3780 | } |
| 3781 | } else if (level == RADEON_DPM_FORCED_LEVEL_LOW) { |
| 3782 | if ((!pi->sclk_dpm_key_disabled) && |
| 3783 | pi->dpm_level_enable_mask.sclk_dpm_enable_mask) { |
| 3784 | levels = ci_get_lowest_enabled_level(rdev, |
| 3785 | pi->dpm_level_enable_mask.sclk_dpm_enable_mask); |
| 3786 | ret = ci_dpm_force_state_sclk(rdev, levels); |
| 3787 | if (ret) |
| 3788 | return ret; |
| 3789 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 3790 | tmp = (RREG32_SMC(TARGET_AND_CURRENT_PROFILE_INDEX) & |
| 3791 | CURR_SCLK_INDEX_MASK) >> CURR_SCLK_INDEX_SHIFT; |
| 3792 | if (tmp == levels) |
| 3793 | break; |
| 3794 | udelay(1); |
| 3795 | } |
| 3796 | } |
| 3797 | if ((!pi->mclk_dpm_key_disabled) && |
| 3798 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask) { |
| 3799 | levels = ci_get_lowest_enabled_level(rdev, |
| 3800 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask); |
| 3801 | ret = ci_dpm_force_state_mclk(rdev, levels); |
| 3802 | if (ret) |
| 3803 | return ret; |
| 3804 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 3805 | tmp = (RREG32_SMC(TARGET_AND_CURRENT_PROFILE_INDEX) & |
| 3806 | CURR_MCLK_INDEX_MASK) >> CURR_MCLK_INDEX_SHIFT; |
| 3807 | if (tmp == levels) |
| 3808 | break; |
| 3809 | udelay(1); |
| 3810 | } |
| 3811 | } |
| 3812 | if ((!pi->pcie_dpm_key_disabled) && |
| 3813 | pi->dpm_level_enable_mask.pcie_dpm_enable_mask) { |
| 3814 | levels = ci_get_lowest_enabled_level(rdev, |
| 3815 | pi->dpm_level_enable_mask.pcie_dpm_enable_mask); |
| 3816 | ret = ci_dpm_force_state_pcie(rdev, levels); |
| 3817 | if (ret) |
| 3818 | return ret; |
| 3819 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 3820 | tmp = (RREG32_SMC(TARGET_AND_CURRENT_PROFILE_INDEX_1) & |
| 3821 | CURR_PCIE_INDEX_MASK) >> CURR_PCIE_INDEX_SHIFT; |
| 3822 | if (tmp == levels) |
| 3823 | break; |
| 3824 | udelay(1); |
| 3825 | } |
| 3826 | } |
| 3827 | } else if (level == RADEON_DPM_FORCED_LEVEL_AUTO) { |
| 3828 | if (!pi->sclk_dpm_key_disabled) { |
| 3829 | smc_result = ci_send_msg_to_smc(rdev, PPSMC_MSG_NoForcedLevel); |
| 3830 | if (smc_result != PPSMC_Result_OK) |
| 3831 | return -EINVAL; |
| 3832 | } |
| 3833 | if (!pi->mclk_dpm_key_disabled) { |
| 3834 | smc_result = ci_send_msg_to_smc(rdev, PPSMC_MSG_MCLKDPM_NoForcedLevel); |
| 3835 | if (smc_result != PPSMC_Result_OK) |
| 3836 | return -EINVAL; |
| 3837 | } |
| 3838 | if (!pi->pcie_dpm_key_disabled) { |
| 3839 | smc_result = ci_send_msg_to_smc(rdev, PPSMC_MSG_PCIeDPM_UnForceLevel); |
| 3840 | if (smc_result != PPSMC_Result_OK) |
| 3841 | return -EINVAL; |
| 3842 | } |
| 3843 | } |
| 3844 | |
| 3845 | rdev->pm.dpm.forced_level = level; |
| 3846 | |
| 3847 | return 0; |
| 3848 | } |
| 3849 | |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 3850 | static int ci_set_mc_special_registers(struct radeon_device *rdev, |
| 3851 | struct ci_mc_reg_table *table) |
| 3852 | { |
| 3853 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 3854 | u8 i, j, k; |
| 3855 | u32 temp_reg; |
| 3856 | |
| 3857 | for (i = 0, j = table->last; i < table->last; i++) { |
| 3858 | if (j >= SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE) |
| 3859 | return -EINVAL; |
| 3860 | switch(table->mc_reg_address[i].s1 << 2) { |
| 3861 | case MC_SEQ_MISC1: |
| 3862 | temp_reg = RREG32(MC_PMG_CMD_EMRS); |
| 3863 | table->mc_reg_address[j].s1 = MC_PMG_CMD_EMRS >> 2; |
| 3864 | table->mc_reg_address[j].s0 = MC_SEQ_PMG_CMD_EMRS_LP >> 2; |
| 3865 | for (k = 0; k < table->num_entries; k++) { |
| 3866 | table->mc_reg_table_entry[k].mc_data[j] = |
| 3867 | ((temp_reg & 0xffff0000)) | ((table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16); |
| 3868 | } |
| 3869 | j++; |
| 3870 | if (j >= SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE) |
| 3871 | return -EINVAL; |
| 3872 | |
| 3873 | temp_reg = RREG32(MC_PMG_CMD_MRS); |
| 3874 | table->mc_reg_address[j].s1 = MC_PMG_CMD_MRS >> 2; |
| 3875 | table->mc_reg_address[j].s0 = MC_SEQ_PMG_CMD_MRS_LP >> 2; |
| 3876 | for (k = 0; k < table->num_entries; k++) { |
| 3877 | table->mc_reg_table_entry[k].mc_data[j] = |
| 3878 | (temp_reg & 0xffff0000) | (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff); |
| 3879 | if (!pi->mem_gddr5) |
| 3880 | table->mc_reg_table_entry[k].mc_data[j] |= 0x100; |
| 3881 | } |
| 3882 | j++; |
| 3883 | if (j > SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE) |
| 3884 | return -EINVAL; |
| 3885 | |
| 3886 | if (!pi->mem_gddr5) { |
| 3887 | table->mc_reg_address[j].s1 = MC_PMG_AUTO_CMD >> 2; |
| 3888 | table->mc_reg_address[j].s0 = MC_PMG_AUTO_CMD >> 2; |
| 3889 | for (k = 0; k < table->num_entries; k++) { |
| 3890 | table->mc_reg_table_entry[k].mc_data[j] = |
| 3891 | (table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16; |
| 3892 | } |
| 3893 | j++; |
| 3894 | if (j > SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE) |
| 3895 | return -EINVAL; |
| 3896 | } |
| 3897 | break; |
| 3898 | case MC_SEQ_RESERVE_M: |
| 3899 | temp_reg = RREG32(MC_PMG_CMD_MRS1); |
| 3900 | table->mc_reg_address[j].s1 = MC_PMG_CMD_MRS1 >> 2; |
| 3901 | table->mc_reg_address[j].s0 = MC_SEQ_PMG_CMD_MRS1_LP >> 2; |
| 3902 | for (k = 0; k < table->num_entries; k++) { |
| 3903 | table->mc_reg_table_entry[k].mc_data[j] = |
| 3904 | (temp_reg & 0xffff0000) | (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff); |
| 3905 | } |
| 3906 | j++; |
| 3907 | if (j > SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE) |
| 3908 | return -EINVAL; |
| 3909 | break; |
| 3910 | default: |
| 3911 | break; |
| 3912 | } |
| 3913 | |
| 3914 | } |
| 3915 | |
| 3916 | table->last = j; |
| 3917 | |
| 3918 | return 0; |
| 3919 | } |
| 3920 | |
| 3921 | static bool ci_check_s0_mc_reg_index(u16 in_reg, u16 *out_reg) |
| 3922 | { |
| 3923 | bool result = true; |
| 3924 | |
| 3925 | switch(in_reg) { |
| 3926 | case MC_SEQ_RAS_TIMING >> 2: |
| 3927 | *out_reg = MC_SEQ_RAS_TIMING_LP >> 2; |
| 3928 | break; |
| 3929 | case MC_SEQ_DLL_STBY >> 2: |
| 3930 | *out_reg = MC_SEQ_DLL_STBY_LP >> 2; |
| 3931 | break; |
| 3932 | case MC_SEQ_G5PDX_CMD0 >> 2: |
| 3933 | *out_reg = MC_SEQ_G5PDX_CMD0_LP >> 2; |
| 3934 | break; |
| 3935 | case MC_SEQ_G5PDX_CMD1 >> 2: |
| 3936 | *out_reg = MC_SEQ_G5PDX_CMD1_LP >> 2; |
| 3937 | break; |
| 3938 | case MC_SEQ_G5PDX_CTRL >> 2: |
| 3939 | *out_reg = MC_SEQ_G5PDX_CTRL_LP >> 2; |
| 3940 | break; |
| 3941 | case MC_SEQ_CAS_TIMING >> 2: |
| 3942 | *out_reg = MC_SEQ_CAS_TIMING_LP >> 2; |
| 3943 | break; |
| 3944 | case MC_SEQ_MISC_TIMING >> 2: |
| 3945 | *out_reg = MC_SEQ_MISC_TIMING_LP >> 2; |
| 3946 | break; |
| 3947 | case MC_SEQ_MISC_TIMING2 >> 2: |
| 3948 | *out_reg = MC_SEQ_MISC_TIMING2_LP >> 2; |
| 3949 | break; |
| 3950 | case MC_SEQ_PMG_DVS_CMD >> 2: |
| 3951 | *out_reg = MC_SEQ_PMG_DVS_CMD_LP >> 2; |
| 3952 | break; |
| 3953 | case MC_SEQ_PMG_DVS_CTL >> 2: |
| 3954 | *out_reg = MC_SEQ_PMG_DVS_CTL_LP >> 2; |
| 3955 | break; |
| 3956 | case MC_SEQ_RD_CTL_D0 >> 2: |
| 3957 | *out_reg = MC_SEQ_RD_CTL_D0_LP >> 2; |
| 3958 | break; |
| 3959 | case MC_SEQ_RD_CTL_D1 >> 2: |
| 3960 | *out_reg = MC_SEQ_RD_CTL_D1_LP >> 2; |
| 3961 | break; |
| 3962 | case MC_SEQ_WR_CTL_D0 >> 2: |
| 3963 | *out_reg = MC_SEQ_WR_CTL_D0_LP >> 2; |
| 3964 | break; |
| 3965 | case MC_SEQ_WR_CTL_D1 >> 2: |
| 3966 | *out_reg = MC_SEQ_WR_CTL_D1_LP >> 2; |
| 3967 | break; |
| 3968 | case MC_PMG_CMD_EMRS >> 2: |
| 3969 | *out_reg = MC_SEQ_PMG_CMD_EMRS_LP >> 2; |
| 3970 | break; |
| 3971 | case MC_PMG_CMD_MRS >> 2: |
| 3972 | *out_reg = MC_SEQ_PMG_CMD_MRS_LP >> 2; |
| 3973 | break; |
| 3974 | case MC_PMG_CMD_MRS1 >> 2: |
| 3975 | *out_reg = MC_SEQ_PMG_CMD_MRS1_LP >> 2; |
| 3976 | break; |
| 3977 | case MC_SEQ_PMG_TIMING >> 2: |
| 3978 | *out_reg = MC_SEQ_PMG_TIMING_LP >> 2; |
| 3979 | break; |
| 3980 | case MC_PMG_CMD_MRS2 >> 2: |
| 3981 | *out_reg = MC_SEQ_PMG_CMD_MRS2_LP >> 2; |
| 3982 | break; |
| 3983 | case MC_SEQ_WR_CTL_2 >> 2: |
| 3984 | *out_reg = MC_SEQ_WR_CTL_2_LP >> 2; |
| 3985 | break; |
| 3986 | default: |
| 3987 | result = false; |
| 3988 | break; |
| 3989 | } |
| 3990 | |
| 3991 | return result; |
| 3992 | } |
| 3993 | |
| 3994 | static void ci_set_valid_flag(struct ci_mc_reg_table *table) |
| 3995 | { |
| 3996 | u8 i, j; |
| 3997 | |
| 3998 | for (i = 0; i < table->last; i++) { |
| 3999 | for (j = 1; j < table->num_entries; j++) { |
| 4000 | if (table->mc_reg_table_entry[j-1].mc_data[i] != |
| 4001 | table->mc_reg_table_entry[j].mc_data[i]) { |
| 4002 | table->valid_flag |= 1 << i; |
| 4003 | break; |
| 4004 | } |
| 4005 | } |
| 4006 | } |
| 4007 | } |
| 4008 | |
| 4009 | static void ci_set_s0_mc_reg_index(struct ci_mc_reg_table *table) |
| 4010 | { |
| 4011 | u32 i; |
| 4012 | u16 address; |
| 4013 | |
| 4014 | for (i = 0; i < table->last; i++) { |
| 4015 | table->mc_reg_address[i].s0 = |
| 4016 | ci_check_s0_mc_reg_index(table->mc_reg_address[i].s1, &address) ? |
| 4017 | address : table->mc_reg_address[i].s1; |
| 4018 | } |
| 4019 | } |
| 4020 | |
| 4021 | static int ci_copy_vbios_mc_reg_table(const struct atom_mc_reg_table *table, |
| 4022 | struct ci_mc_reg_table *ci_table) |
| 4023 | { |
| 4024 | u8 i, j; |
| 4025 | |
| 4026 | if (table->last > SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE) |
| 4027 | return -EINVAL; |
| 4028 | if (table->num_entries > MAX_AC_TIMING_ENTRIES) |
| 4029 | return -EINVAL; |
| 4030 | |
| 4031 | for (i = 0; i < table->last; i++) |
| 4032 | ci_table->mc_reg_address[i].s1 = table->mc_reg_address[i].s1; |
| 4033 | |
| 4034 | ci_table->last = table->last; |
| 4035 | |
| 4036 | for (i = 0; i < table->num_entries; i++) { |
| 4037 | ci_table->mc_reg_table_entry[i].mclk_max = |
| 4038 | table->mc_reg_table_entry[i].mclk_max; |
| 4039 | for (j = 0; j < table->last; j++) |
| 4040 | ci_table->mc_reg_table_entry[i].mc_data[j] = |
| 4041 | table->mc_reg_table_entry[i].mc_data[j]; |
| 4042 | } |
| 4043 | ci_table->num_entries = table->num_entries; |
| 4044 | |
| 4045 | return 0; |
| 4046 | } |
| 4047 | |
| 4048 | static int ci_initialize_mc_reg_table(struct radeon_device *rdev) |
| 4049 | { |
| 4050 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 4051 | struct atom_mc_reg_table *table; |
| 4052 | struct ci_mc_reg_table *ci_table = &pi->mc_reg_table; |
| 4053 | u8 module_index = rv770_get_memory_module_index(rdev); |
| 4054 | int ret; |
| 4055 | |
| 4056 | table = kzalloc(sizeof(struct atom_mc_reg_table), GFP_KERNEL); |
| 4057 | if (!table) |
| 4058 | return -ENOMEM; |
| 4059 | |
| 4060 | WREG32(MC_SEQ_RAS_TIMING_LP, RREG32(MC_SEQ_RAS_TIMING)); |
| 4061 | WREG32(MC_SEQ_CAS_TIMING_LP, RREG32(MC_SEQ_CAS_TIMING)); |
| 4062 | WREG32(MC_SEQ_DLL_STBY_LP, RREG32(MC_SEQ_DLL_STBY)); |
| 4063 | WREG32(MC_SEQ_G5PDX_CMD0_LP, RREG32(MC_SEQ_G5PDX_CMD0)); |
| 4064 | WREG32(MC_SEQ_G5PDX_CMD1_LP, RREG32(MC_SEQ_G5PDX_CMD1)); |
| 4065 | WREG32(MC_SEQ_G5PDX_CTRL_LP, RREG32(MC_SEQ_G5PDX_CTRL)); |
| 4066 | WREG32(MC_SEQ_PMG_DVS_CMD_LP, RREG32(MC_SEQ_PMG_DVS_CMD)); |
| 4067 | WREG32(MC_SEQ_PMG_DVS_CTL_LP, RREG32(MC_SEQ_PMG_DVS_CTL)); |
| 4068 | WREG32(MC_SEQ_MISC_TIMING_LP, RREG32(MC_SEQ_MISC_TIMING)); |
| 4069 | WREG32(MC_SEQ_MISC_TIMING2_LP, RREG32(MC_SEQ_MISC_TIMING2)); |
| 4070 | WREG32(MC_SEQ_PMG_CMD_EMRS_LP, RREG32(MC_PMG_CMD_EMRS)); |
| 4071 | WREG32(MC_SEQ_PMG_CMD_MRS_LP, RREG32(MC_PMG_CMD_MRS)); |
| 4072 | WREG32(MC_SEQ_PMG_CMD_MRS1_LP, RREG32(MC_PMG_CMD_MRS1)); |
| 4073 | WREG32(MC_SEQ_WR_CTL_D0_LP, RREG32(MC_SEQ_WR_CTL_D0)); |
| 4074 | WREG32(MC_SEQ_WR_CTL_D1_LP, RREG32(MC_SEQ_WR_CTL_D1)); |
| 4075 | WREG32(MC_SEQ_RD_CTL_D0_LP, RREG32(MC_SEQ_RD_CTL_D0)); |
| 4076 | WREG32(MC_SEQ_RD_CTL_D1_LP, RREG32(MC_SEQ_RD_CTL_D1)); |
| 4077 | WREG32(MC_SEQ_PMG_TIMING_LP, RREG32(MC_SEQ_PMG_TIMING)); |
| 4078 | WREG32(MC_SEQ_PMG_CMD_MRS2_LP, RREG32(MC_PMG_CMD_MRS2)); |
| 4079 | WREG32(MC_SEQ_WR_CTL_2_LP, RREG32(MC_SEQ_WR_CTL_2)); |
| 4080 | |
| 4081 | ret = radeon_atom_init_mc_reg_table(rdev, module_index, table); |
| 4082 | if (ret) |
| 4083 | goto init_mc_done; |
| 4084 | |
| 4085 | ret = ci_copy_vbios_mc_reg_table(table, ci_table); |
| 4086 | if (ret) |
| 4087 | goto init_mc_done; |
| 4088 | |
| 4089 | ci_set_s0_mc_reg_index(ci_table); |
| 4090 | |
| 4091 | ret = ci_set_mc_special_registers(rdev, ci_table); |
| 4092 | if (ret) |
| 4093 | goto init_mc_done; |
| 4094 | |
| 4095 | ci_set_valid_flag(ci_table); |
| 4096 | |
| 4097 | init_mc_done: |
| 4098 | kfree(table); |
| 4099 | |
| 4100 | return ret; |
| 4101 | } |
| 4102 | |
| 4103 | static int ci_populate_mc_reg_addresses(struct radeon_device *rdev, |
| 4104 | SMU7_Discrete_MCRegisters *mc_reg_table) |
| 4105 | { |
| 4106 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 4107 | u32 i, j; |
| 4108 | |
| 4109 | for (i = 0, j = 0; j < pi->mc_reg_table.last; j++) { |
| 4110 | if (pi->mc_reg_table.valid_flag & (1 << j)) { |
| 4111 | if (i >= SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE) |
| 4112 | return -EINVAL; |
| 4113 | mc_reg_table->address[i].s0 = cpu_to_be16(pi->mc_reg_table.mc_reg_address[j].s0); |
| 4114 | mc_reg_table->address[i].s1 = cpu_to_be16(pi->mc_reg_table.mc_reg_address[j].s1); |
| 4115 | i++; |
| 4116 | } |
| 4117 | } |
| 4118 | |
| 4119 | mc_reg_table->last = (u8)i; |
| 4120 | |
| 4121 | return 0; |
| 4122 | } |
| 4123 | |
| 4124 | static void ci_convert_mc_registers(const struct ci_mc_reg_entry *entry, |
| 4125 | SMU7_Discrete_MCRegisterSet *data, |
| 4126 | u32 num_entries, u32 valid_flag) |
| 4127 | { |
| 4128 | u32 i, j; |
| 4129 | |
| 4130 | for (i = 0, j = 0; j < num_entries; j++) { |
| 4131 | if (valid_flag & (1 << j)) { |
| 4132 | data->value[i] = cpu_to_be32(entry->mc_data[j]); |
| 4133 | i++; |
| 4134 | } |
| 4135 | } |
| 4136 | } |
| 4137 | |
| 4138 | static void ci_convert_mc_reg_table_entry_to_smc(struct radeon_device *rdev, |
| 4139 | const u32 memory_clock, |
| 4140 | SMU7_Discrete_MCRegisterSet *mc_reg_table_data) |
| 4141 | { |
| 4142 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 4143 | u32 i = 0; |
| 4144 | |
| 4145 | for(i = 0; i < pi->mc_reg_table.num_entries; i++) { |
| 4146 | if (memory_clock <= pi->mc_reg_table.mc_reg_table_entry[i].mclk_max) |
| 4147 | break; |
| 4148 | } |
| 4149 | |
| 4150 | if ((i == pi->mc_reg_table.num_entries) && (i > 0)) |
| 4151 | --i; |
| 4152 | |
| 4153 | ci_convert_mc_registers(&pi->mc_reg_table.mc_reg_table_entry[i], |
| 4154 | mc_reg_table_data, pi->mc_reg_table.last, |
| 4155 | pi->mc_reg_table.valid_flag); |
| 4156 | } |
| 4157 | |
| 4158 | static void ci_convert_mc_reg_table_to_smc(struct radeon_device *rdev, |
| 4159 | SMU7_Discrete_MCRegisters *mc_reg_table) |
| 4160 | { |
| 4161 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 4162 | u32 i; |
| 4163 | |
| 4164 | for (i = 0; i < pi->dpm_table.mclk_table.count; i++) |
| 4165 | ci_convert_mc_reg_table_entry_to_smc(rdev, |
| 4166 | pi->dpm_table.mclk_table.dpm_levels[i].value, |
| 4167 | &mc_reg_table->data[i]); |
| 4168 | } |
| 4169 | |
| 4170 | static int ci_populate_initial_mc_reg_table(struct radeon_device *rdev) |
| 4171 | { |
| 4172 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 4173 | int ret; |
| 4174 | |
| 4175 | memset(&pi->smc_mc_reg_table, 0, sizeof(SMU7_Discrete_MCRegisters)); |
| 4176 | |
| 4177 | ret = ci_populate_mc_reg_addresses(rdev, &pi->smc_mc_reg_table); |
| 4178 | if (ret) |
| 4179 | return ret; |
| 4180 | ci_convert_mc_reg_table_to_smc(rdev, &pi->smc_mc_reg_table); |
| 4181 | |
| 4182 | return ci_copy_bytes_to_smc(rdev, |
| 4183 | pi->mc_reg_table_start, |
| 4184 | (u8 *)&pi->smc_mc_reg_table, |
| 4185 | sizeof(SMU7_Discrete_MCRegisters), |
| 4186 | pi->sram_end); |
| 4187 | } |
| 4188 | |
| 4189 | static int ci_update_and_upload_mc_reg_table(struct radeon_device *rdev) |
| 4190 | { |
| 4191 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 4192 | |
| 4193 | if (!(pi->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) |
| 4194 | return 0; |
| 4195 | |
| 4196 | memset(&pi->smc_mc_reg_table, 0, sizeof(SMU7_Discrete_MCRegisters)); |
| 4197 | |
| 4198 | ci_convert_mc_reg_table_to_smc(rdev, &pi->smc_mc_reg_table); |
| 4199 | |
| 4200 | return ci_copy_bytes_to_smc(rdev, |
| 4201 | pi->mc_reg_table_start + |
| 4202 | offsetof(SMU7_Discrete_MCRegisters, data[0]), |
| 4203 | (u8 *)&pi->smc_mc_reg_table.data[0], |
| 4204 | sizeof(SMU7_Discrete_MCRegisterSet) * |
| 4205 | pi->dpm_table.mclk_table.count, |
| 4206 | pi->sram_end); |
| 4207 | } |
| 4208 | |
| 4209 | static void ci_enable_voltage_control(struct radeon_device *rdev) |
| 4210 | { |
| 4211 | u32 tmp = RREG32_SMC(GENERAL_PWRMGT); |
| 4212 | |
| 4213 | tmp |= VOLT_PWRMGT_EN; |
| 4214 | WREG32_SMC(GENERAL_PWRMGT, tmp); |
| 4215 | } |
| 4216 | |
| 4217 | static enum radeon_pcie_gen ci_get_maximum_link_speed(struct radeon_device *rdev, |
| 4218 | struct radeon_ps *radeon_state) |
| 4219 | { |
| 4220 | struct ci_ps *state = ci_get_ps(radeon_state); |
| 4221 | int i; |
| 4222 | u16 pcie_speed, max_speed = 0; |
| 4223 | |
| 4224 | for (i = 0; i < state->performance_level_count; i++) { |
| 4225 | pcie_speed = state->performance_levels[i].pcie_gen; |
| 4226 | if (max_speed < pcie_speed) |
| 4227 | max_speed = pcie_speed; |
| 4228 | } |
| 4229 | |
| 4230 | return max_speed; |
| 4231 | } |
| 4232 | |
| 4233 | static u16 ci_get_current_pcie_speed(struct radeon_device *rdev) |
| 4234 | { |
| 4235 | u32 speed_cntl = 0; |
| 4236 | |
| 4237 | speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL) & LC_CURRENT_DATA_RATE_MASK; |
| 4238 | speed_cntl >>= LC_CURRENT_DATA_RATE_SHIFT; |
| 4239 | |
| 4240 | return (u16)speed_cntl; |
| 4241 | } |
| 4242 | |
| 4243 | static int ci_get_current_pcie_lane_number(struct radeon_device *rdev) |
| 4244 | { |
| 4245 | u32 link_width = 0; |
| 4246 | |
| 4247 | link_width = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL) & LC_LINK_WIDTH_RD_MASK; |
| 4248 | link_width >>= LC_LINK_WIDTH_RD_SHIFT; |
| 4249 | |
| 4250 | switch (link_width) { |
| 4251 | case RADEON_PCIE_LC_LINK_WIDTH_X1: |
| 4252 | return 1; |
| 4253 | case RADEON_PCIE_LC_LINK_WIDTH_X2: |
| 4254 | return 2; |
| 4255 | case RADEON_PCIE_LC_LINK_WIDTH_X4: |
| 4256 | return 4; |
| 4257 | case RADEON_PCIE_LC_LINK_WIDTH_X8: |
| 4258 | return 8; |
| 4259 | case RADEON_PCIE_LC_LINK_WIDTH_X12: |
| 4260 | /* not actually supported */ |
| 4261 | return 12; |
| 4262 | case RADEON_PCIE_LC_LINK_WIDTH_X0: |
| 4263 | case RADEON_PCIE_LC_LINK_WIDTH_X16: |
| 4264 | default: |
| 4265 | return 16; |
| 4266 | } |
| 4267 | } |
| 4268 | |
| 4269 | static void ci_request_link_speed_change_before_state_change(struct radeon_device *rdev, |
| 4270 | struct radeon_ps *radeon_new_state, |
| 4271 | struct radeon_ps *radeon_current_state) |
| 4272 | { |
| 4273 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 4274 | enum radeon_pcie_gen target_link_speed = |
| 4275 | ci_get_maximum_link_speed(rdev, radeon_new_state); |
| 4276 | enum radeon_pcie_gen current_link_speed; |
| 4277 | |
| 4278 | if (pi->force_pcie_gen == RADEON_PCIE_GEN_INVALID) |
| 4279 | current_link_speed = ci_get_maximum_link_speed(rdev, radeon_current_state); |
| 4280 | else |
| 4281 | current_link_speed = pi->force_pcie_gen; |
| 4282 | |
| 4283 | pi->force_pcie_gen = RADEON_PCIE_GEN_INVALID; |
| 4284 | pi->pspp_notify_required = false; |
| 4285 | if (target_link_speed > current_link_speed) { |
| 4286 | switch (target_link_speed) { |
Stephen Rothwell | ab62e76 | 2013-09-02 19:01:23 +1000 | [diff] [blame] | 4287 | #ifdef CONFIG_ACPI |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 4288 | case RADEON_PCIE_GEN3: |
| 4289 | if (radeon_acpi_pcie_performance_request(rdev, PCIE_PERF_REQ_PECI_GEN3, false) == 0) |
| 4290 | break; |
| 4291 | pi->force_pcie_gen = RADEON_PCIE_GEN2; |
| 4292 | if (current_link_speed == RADEON_PCIE_GEN2) |
| 4293 | break; |
| 4294 | case RADEON_PCIE_GEN2: |
| 4295 | if (radeon_acpi_pcie_performance_request(rdev, PCIE_PERF_REQ_PECI_GEN2, false) == 0) |
| 4296 | break; |
Stephen Rothwell | ab62e76 | 2013-09-02 19:01:23 +1000 | [diff] [blame] | 4297 | #endif |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 4298 | default: |
| 4299 | pi->force_pcie_gen = ci_get_current_pcie_speed(rdev); |
| 4300 | break; |
| 4301 | } |
| 4302 | } else { |
| 4303 | if (target_link_speed < current_link_speed) |
| 4304 | pi->pspp_notify_required = true; |
| 4305 | } |
| 4306 | } |
| 4307 | |
| 4308 | static void ci_notify_link_speed_change_after_state_change(struct radeon_device *rdev, |
| 4309 | struct radeon_ps *radeon_new_state, |
| 4310 | struct radeon_ps *radeon_current_state) |
| 4311 | { |
| 4312 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 4313 | enum radeon_pcie_gen target_link_speed = |
| 4314 | ci_get_maximum_link_speed(rdev, radeon_new_state); |
| 4315 | u8 request; |
| 4316 | |
| 4317 | if (pi->pspp_notify_required) { |
| 4318 | if (target_link_speed == RADEON_PCIE_GEN3) |
| 4319 | request = PCIE_PERF_REQ_PECI_GEN3; |
| 4320 | else if (target_link_speed == RADEON_PCIE_GEN2) |
| 4321 | request = PCIE_PERF_REQ_PECI_GEN2; |
| 4322 | else |
| 4323 | request = PCIE_PERF_REQ_PECI_GEN1; |
| 4324 | |
| 4325 | if ((request == PCIE_PERF_REQ_PECI_GEN1) && |
| 4326 | (ci_get_current_pcie_speed(rdev) > 0)) |
| 4327 | return; |
| 4328 | |
Stephen Rothwell | ab62e76 | 2013-09-02 19:01:23 +1000 | [diff] [blame] | 4329 | #ifdef CONFIG_ACPI |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 4330 | radeon_acpi_pcie_performance_request(rdev, request, false); |
Stephen Rothwell | ab62e76 | 2013-09-02 19:01:23 +1000 | [diff] [blame] | 4331 | #endif |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 4332 | } |
| 4333 | } |
| 4334 | |
| 4335 | static int ci_set_private_data_variables_based_on_pptable(struct radeon_device *rdev) |
| 4336 | { |
| 4337 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 4338 | struct radeon_clock_voltage_dependency_table *allowed_sclk_vddc_table = |
| 4339 | &rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk; |
| 4340 | struct radeon_clock_voltage_dependency_table *allowed_mclk_vddc_table = |
| 4341 | &rdev->pm.dpm.dyn_state.vddc_dependency_on_mclk; |
| 4342 | struct radeon_clock_voltage_dependency_table *allowed_mclk_vddci_table = |
| 4343 | &rdev->pm.dpm.dyn_state.vddci_dependency_on_mclk; |
| 4344 | |
| 4345 | if (allowed_sclk_vddc_table == NULL) |
| 4346 | return -EINVAL; |
| 4347 | if (allowed_sclk_vddc_table->count < 1) |
| 4348 | return -EINVAL; |
| 4349 | if (allowed_mclk_vddc_table == NULL) |
| 4350 | return -EINVAL; |
| 4351 | if (allowed_mclk_vddc_table->count < 1) |
| 4352 | return -EINVAL; |
| 4353 | if (allowed_mclk_vddci_table == NULL) |
| 4354 | return -EINVAL; |
| 4355 | if (allowed_mclk_vddci_table->count < 1) |
| 4356 | return -EINVAL; |
| 4357 | |
| 4358 | pi->min_vddc_in_pp_table = allowed_sclk_vddc_table->entries[0].v; |
| 4359 | pi->max_vddc_in_pp_table = |
| 4360 | allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].v; |
| 4361 | |
| 4362 | pi->min_vddci_in_pp_table = allowed_mclk_vddci_table->entries[0].v; |
| 4363 | pi->max_vddci_in_pp_table = |
| 4364 | allowed_mclk_vddci_table->entries[allowed_mclk_vddci_table->count - 1].v; |
| 4365 | |
| 4366 | rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac.sclk = |
| 4367 | allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].clk; |
| 4368 | rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac.mclk = |
| 4369 | allowed_mclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].clk; |
| 4370 | rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac.vddc = |
| 4371 | allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].v; |
| 4372 | rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac.vddci = |
| 4373 | allowed_mclk_vddci_table->entries[allowed_mclk_vddci_table->count - 1].v; |
| 4374 | |
| 4375 | return 0; |
| 4376 | } |
| 4377 | |
| 4378 | static void ci_patch_with_vddc_leakage(struct radeon_device *rdev, u16 *vddc) |
| 4379 | { |
| 4380 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 4381 | struct ci_leakage_voltage *leakage_table = &pi->vddc_leakage; |
| 4382 | u32 leakage_index; |
| 4383 | |
| 4384 | for (leakage_index = 0; leakage_index < leakage_table->count; leakage_index++) { |
| 4385 | if (leakage_table->leakage_id[leakage_index] == *vddc) { |
| 4386 | *vddc = leakage_table->actual_voltage[leakage_index]; |
| 4387 | break; |
| 4388 | } |
| 4389 | } |
| 4390 | } |
| 4391 | |
| 4392 | static void ci_patch_with_vddci_leakage(struct radeon_device *rdev, u16 *vddci) |
| 4393 | { |
| 4394 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 4395 | struct ci_leakage_voltage *leakage_table = &pi->vddci_leakage; |
| 4396 | u32 leakage_index; |
| 4397 | |
| 4398 | for (leakage_index = 0; leakage_index < leakage_table->count; leakage_index++) { |
| 4399 | if (leakage_table->leakage_id[leakage_index] == *vddci) { |
| 4400 | *vddci = leakage_table->actual_voltage[leakage_index]; |
| 4401 | break; |
| 4402 | } |
| 4403 | } |
| 4404 | } |
| 4405 | |
| 4406 | static void ci_patch_clock_voltage_dependency_table_with_vddc_leakage(struct radeon_device *rdev, |
| 4407 | struct radeon_clock_voltage_dependency_table *table) |
| 4408 | { |
| 4409 | u32 i; |
| 4410 | |
| 4411 | if (table) { |
| 4412 | for (i = 0; i < table->count; i++) |
| 4413 | ci_patch_with_vddc_leakage(rdev, &table->entries[i].v); |
| 4414 | } |
| 4415 | } |
| 4416 | |
| 4417 | static void ci_patch_clock_voltage_dependency_table_with_vddci_leakage(struct radeon_device *rdev, |
| 4418 | struct radeon_clock_voltage_dependency_table *table) |
| 4419 | { |
| 4420 | u32 i; |
| 4421 | |
| 4422 | if (table) { |
| 4423 | for (i = 0; i < table->count; i++) |
| 4424 | ci_patch_with_vddci_leakage(rdev, &table->entries[i].v); |
| 4425 | } |
| 4426 | } |
| 4427 | |
| 4428 | static void ci_patch_vce_clock_voltage_dependency_table_with_vddc_leakage(struct radeon_device *rdev, |
| 4429 | struct radeon_vce_clock_voltage_dependency_table *table) |
| 4430 | { |
| 4431 | u32 i; |
| 4432 | |
| 4433 | if (table) { |
| 4434 | for (i = 0; i < table->count; i++) |
| 4435 | ci_patch_with_vddc_leakage(rdev, &table->entries[i].v); |
| 4436 | } |
| 4437 | } |
| 4438 | |
| 4439 | static void ci_patch_uvd_clock_voltage_dependency_table_with_vddc_leakage(struct radeon_device *rdev, |
| 4440 | struct radeon_uvd_clock_voltage_dependency_table *table) |
| 4441 | { |
| 4442 | u32 i; |
| 4443 | |
| 4444 | if (table) { |
| 4445 | for (i = 0; i < table->count; i++) |
| 4446 | ci_patch_with_vddc_leakage(rdev, &table->entries[i].v); |
| 4447 | } |
| 4448 | } |
| 4449 | |
| 4450 | static void ci_patch_vddc_phase_shed_limit_table_with_vddc_leakage(struct radeon_device *rdev, |
| 4451 | struct radeon_phase_shedding_limits_table *table) |
| 4452 | { |
| 4453 | u32 i; |
| 4454 | |
| 4455 | if (table) { |
| 4456 | for (i = 0; i < table->count; i++) |
| 4457 | ci_patch_with_vddc_leakage(rdev, &table->entries[i].voltage); |
| 4458 | } |
| 4459 | } |
| 4460 | |
| 4461 | static void ci_patch_clock_voltage_limits_with_vddc_leakage(struct radeon_device *rdev, |
| 4462 | struct radeon_clock_and_voltage_limits *table) |
| 4463 | { |
| 4464 | if (table) { |
| 4465 | ci_patch_with_vddc_leakage(rdev, (u16 *)&table->vddc); |
| 4466 | ci_patch_with_vddci_leakage(rdev, (u16 *)&table->vddci); |
| 4467 | } |
| 4468 | } |
| 4469 | |
| 4470 | static void ci_patch_cac_leakage_table_with_vddc_leakage(struct radeon_device *rdev, |
| 4471 | struct radeon_cac_leakage_table *table) |
| 4472 | { |
| 4473 | u32 i; |
| 4474 | |
| 4475 | if (table) { |
| 4476 | for (i = 0; i < table->count; i++) |
| 4477 | ci_patch_with_vddc_leakage(rdev, &table->entries[i].vddc); |
| 4478 | } |
| 4479 | } |
| 4480 | |
| 4481 | static void ci_patch_dependency_tables_with_leakage(struct radeon_device *rdev) |
| 4482 | { |
| 4483 | |
| 4484 | ci_patch_clock_voltage_dependency_table_with_vddc_leakage(rdev, |
| 4485 | &rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk); |
| 4486 | ci_patch_clock_voltage_dependency_table_with_vddc_leakage(rdev, |
| 4487 | &rdev->pm.dpm.dyn_state.vddc_dependency_on_mclk); |
| 4488 | ci_patch_clock_voltage_dependency_table_with_vddc_leakage(rdev, |
| 4489 | &rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk); |
| 4490 | ci_patch_clock_voltage_dependency_table_with_vddci_leakage(rdev, |
| 4491 | &rdev->pm.dpm.dyn_state.vddci_dependency_on_mclk); |
| 4492 | ci_patch_vce_clock_voltage_dependency_table_with_vddc_leakage(rdev, |
| 4493 | &rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table); |
| 4494 | ci_patch_uvd_clock_voltage_dependency_table_with_vddc_leakage(rdev, |
| 4495 | &rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table); |
| 4496 | ci_patch_clock_voltage_dependency_table_with_vddc_leakage(rdev, |
| 4497 | &rdev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table); |
| 4498 | ci_patch_clock_voltage_dependency_table_with_vddc_leakage(rdev, |
| 4499 | &rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table); |
| 4500 | ci_patch_vddc_phase_shed_limit_table_with_vddc_leakage(rdev, |
| 4501 | &rdev->pm.dpm.dyn_state.phase_shedding_limits_table); |
| 4502 | ci_patch_clock_voltage_limits_with_vddc_leakage(rdev, |
| 4503 | &rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac); |
| 4504 | ci_patch_clock_voltage_limits_with_vddc_leakage(rdev, |
| 4505 | &rdev->pm.dpm.dyn_state.max_clock_voltage_on_dc); |
| 4506 | ci_patch_cac_leakage_table_with_vddc_leakage(rdev, |
| 4507 | &rdev->pm.dpm.dyn_state.cac_leakage_table); |
| 4508 | |
| 4509 | } |
| 4510 | |
| 4511 | static void ci_get_memory_type(struct radeon_device *rdev) |
| 4512 | { |
| 4513 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 4514 | u32 tmp; |
| 4515 | |
| 4516 | tmp = RREG32(MC_SEQ_MISC0); |
| 4517 | |
| 4518 | if (((tmp & MC_SEQ_MISC0_GDDR5_MASK) >> MC_SEQ_MISC0_GDDR5_SHIFT) == |
| 4519 | MC_SEQ_MISC0_GDDR5_VALUE) |
| 4520 | pi->mem_gddr5 = true; |
| 4521 | else |
| 4522 | pi->mem_gddr5 = false; |
| 4523 | |
| 4524 | } |
| 4525 | |
Alex Deucher | 9a04dad3 | 2014-01-07 12:16:05 -0500 | [diff] [blame] | 4526 | static void ci_update_current_ps(struct radeon_device *rdev, |
| 4527 | struct radeon_ps *rps) |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 4528 | { |
| 4529 | struct ci_ps *new_ps = ci_get_ps(rps); |
| 4530 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 4531 | |
| 4532 | pi->current_rps = *rps; |
| 4533 | pi->current_ps = *new_ps; |
| 4534 | pi->current_rps.ps_priv = &pi->current_ps; |
| 4535 | } |
| 4536 | |
Alex Deucher | 9a04dad3 | 2014-01-07 12:16:05 -0500 | [diff] [blame] | 4537 | static void ci_update_requested_ps(struct radeon_device *rdev, |
| 4538 | struct radeon_ps *rps) |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 4539 | { |
| 4540 | struct ci_ps *new_ps = ci_get_ps(rps); |
| 4541 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 4542 | |
| 4543 | pi->requested_rps = *rps; |
| 4544 | pi->requested_ps = *new_ps; |
| 4545 | pi->requested_rps.ps_priv = &pi->requested_ps; |
| 4546 | } |
| 4547 | |
| 4548 | int ci_dpm_pre_set_power_state(struct radeon_device *rdev) |
| 4549 | { |
| 4550 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 4551 | struct radeon_ps requested_ps = *rdev->pm.dpm.requested_ps; |
| 4552 | struct radeon_ps *new_ps = &requested_ps; |
| 4553 | |
| 4554 | ci_update_requested_ps(rdev, new_ps); |
| 4555 | |
| 4556 | ci_apply_state_adjust_rules(rdev, &pi->requested_rps); |
| 4557 | |
| 4558 | return 0; |
| 4559 | } |
| 4560 | |
| 4561 | void ci_dpm_post_set_power_state(struct radeon_device *rdev) |
| 4562 | { |
| 4563 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 4564 | struct radeon_ps *new_ps = &pi->requested_rps; |
| 4565 | |
| 4566 | ci_update_current_ps(rdev, new_ps); |
| 4567 | } |
| 4568 | |
| 4569 | |
| 4570 | void ci_dpm_setup_asic(struct radeon_device *rdev) |
| 4571 | { |
Alex Deucher | 6c7bcce | 2013-12-18 14:07:14 -0500 | [diff] [blame] | 4572 | int r; |
| 4573 | |
| 4574 | r = ci_mc_load_microcode(rdev); |
| 4575 | if (r) |
| 4576 | DRM_ERROR("Failed to load MC firmware!\n"); |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 4577 | ci_read_clock_registers(rdev); |
| 4578 | ci_get_memory_type(rdev); |
| 4579 | ci_enable_acpi_power_management(rdev); |
| 4580 | ci_init_sclk_t(rdev); |
| 4581 | } |
| 4582 | |
| 4583 | int ci_dpm_enable(struct radeon_device *rdev) |
| 4584 | { |
| 4585 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 4586 | struct radeon_ps *boot_ps = rdev->pm.dpm.boot_ps; |
| 4587 | int ret; |
| 4588 | |
| 4589 | if (ci_is_smc_running(rdev)) |
| 4590 | return -EINVAL; |
| 4591 | if (pi->voltage_control != CISLANDS_VOLTAGE_CONTROL_NONE) { |
| 4592 | ci_enable_voltage_control(rdev); |
| 4593 | ret = ci_construct_voltage_tables(rdev); |
| 4594 | if (ret) { |
| 4595 | DRM_ERROR("ci_construct_voltage_tables failed\n"); |
| 4596 | return ret; |
| 4597 | } |
| 4598 | } |
| 4599 | if (pi->caps_dynamic_ac_timing) { |
| 4600 | ret = ci_initialize_mc_reg_table(rdev); |
| 4601 | if (ret) |
| 4602 | pi->caps_dynamic_ac_timing = false; |
| 4603 | } |
| 4604 | if (pi->dynamic_ss) |
| 4605 | ci_enable_spread_spectrum(rdev, true); |
| 4606 | if (pi->thermal_protection) |
| 4607 | ci_enable_thermal_protection(rdev, true); |
| 4608 | ci_program_sstp(rdev); |
| 4609 | ci_enable_display_gap(rdev); |
| 4610 | ci_program_vc(rdev); |
| 4611 | ret = ci_upload_firmware(rdev); |
| 4612 | if (ret) { |
| 4613 | DRM_ERROR("ci_upload_firmware failed\n"); |
| 4614 | return ret; |
| 4615 | } |
| 4616 | ret = ci_process_firmware_header(rdev); |
| 4617 | if (ret) { |
| 4618 | DRM_ERROR("ci_process_firmware_header failed\n"); |
| 4619 | return ret; |
| 4620 | } |
| 4621 | ret = ci_initial_switch_from_arb_f0_to_f1(rdev); |
| 4622 | if (ret) { |
| 4623 | DRM_ERROR("ci_initial_switch_from_arb_f0_to_f1 failed\n"); |
| 4624 | return ret; |
| 4625 | } |
| 4626 | ret = ci_init_smc_table(rdev); |
| 4627 | if (ret) { |
| 4628 | DRM_ERROR("ci_init_smc_table failed\n"); |
| 4629 | return ret; |
| 4630 | } |
| 4631 | ret = ci_init_arb_table_index(rdev); |
| 4632 | if (ret) { |
| 4633 | DRM_ERROR("ci_init_arb_table_index failed\n"); |
| 4634 | return ret; |
| 4635 | } |
| 4636 | if (pi->caps_dynamic_ac_timing) { |
| 4637 | ret = ci_populate_initial_mc_reg_table(rdev); |
| 4638 | if (ret) { |
| 4639 | DRM_ERROR("ci_populate_initial_mc_reg_table failed\n"); |
| 4640 | return ret; |
| 4641 | } |
| 4642 | } |
| 4643 | ret = ci_populate_pm_base(rdev); |
| 4644 | if (ret) { |
| 4645 | DRM_ERROR("ci_populate_pm_base failed\n"); |
| 4646 | return ret; |
| 4647 | } |
| 4648 | ci_dpm_start_smc(rdev); |
| 4649 | ci_enable_vr_hot_gpio_interrupt(rdev); |
| 4650 | ret = ci_notify_smc_display_change(rdev, false); |
| 4651 | if (ret) { |
| 4652 | DRM_ERROR("ci_notify_smc_display_change failed\n"); |
| 4653 | return ret; |
| 4654 | } |
| 4655 | ci_enable_sclk_control(rdev, true); |
| 4656 | ret = ci_enable_ulv(rdev, true); |
| 4657 | if (ret) { |
| 4658 | DRM_ERROR("ci_enable_ulv failed\n"); |
| 4659 | return ret; |
| 4660 | } |
| 4661 | ret = ci_enable_ds_master_switch(rdev, true); |
| 4662 | if (ret) { |
| 4663 | DRM_ERROR("ci_enable_ds_master_switch failed\n"); |
| 4664 | return ret; |
| 4665 | } |
| 4666 | ret = ci_start_dpm(rdev); |
| 4667 | if (ret) { |
| 4668 | DRM_ERROR("ci_start_dpm failed\n"); |
| 4669 | return ret; |
| 4670 | } |
| 4671 | ret = ci_enable_didt(rdev, true); |
| 4672 | if (ret) { |
| 4673 | DRM_ERROR("ci_enable_didt failed\n"); |
| 4674 | return ret; |
| 4675 | } |
| 4676 | ret = ci_enable_smc_cac(rdev, true); |
| 4677 | if (ret) { |
| 4678 | DRM_ERROR("ci_enable_smc_cac failed\n"); |
| 4679 | return ret; |
| 4680 | } |
| 4681 | ret = ci_enable_power_containment(rdev, true); |
| 4682 | if (ret) { |
| 4683 | DRM_ERROR("ci_enable_power_containment failed\n"); |
| 4684 | return ret; |
| 4685 | } |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 4686 | |
| 4687 | ci_enable_auto_throttle_source(rdev, RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL, true); |
| 4688 | |
| 4689 | ci_update_current_ps(rdev, boot_ps); |
| 4690 | |
| 4691 | return 0; |
| 4692 | } |
| 4693 | |
Alex Deucher | 9020842 | 2013-12-19 13:59:46 -0500 | [diff] [blame] | 4694 | int ci_dpm_late_enable(struct radeon_device *rdev) |
| 4695 | { |
| 4696 | int ret; |
| 4697 | |
| 4698 | if (rdev->irq.installed && |
| 4699 | r600_is_internal_thermal_sensor(rdev->pm.int_thermal_type)) { |
| 4700 | #if 0 |
| 4701 | PPSMC_Result result; |
| 4702 | #endif |
| 4703 | ret = ci_set_thermal_temperature_range(rdev, R600_TEMP_RANGE_MIN, R600_TEMP_RANGE_MAX); |
| 4704 | if (ret) { |
| 4705 | DRM_ERROR("ci_set_thermal_temperature_range failed\n"); |
| 4706 | return ret; |
| 4707 | } |
| 4708 | rdev->irq.dpm_thermal = true; |
| 4709 | radeon_irq_set(rdev); |
| 4710 | #if 0 |
| 4711 | result = ci_send_msg_to_smc(rdev, PPSMC_MSG_EnableThermalInterrupt); |
| 4712 | |
| 4713 | if (result != PPSMC_Result_OK) |
| 4714 | DRM_DEBUG_KMS("Could not enable thermal interrupts.\n"); |
| 4715 | #endif |
| 4716 | } |
| 4717 | |
| 4718 | ci_dpm_powergate_uvd(rdev, true); |
| 4719 | |
| 4720 | return 0; |
| 4721 | } |
| 4722 | |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 4723 | void ci_dpm_disable(struct radeon_device *rdev) |
| 4724 | { |
| 4725 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 4726 | struct radeon_ps *boot_ps = rdev->pm.dpm.boot_ps; |
| 4727 | |
Alex Deucher | 47acb1f | 2013-08-26 09:43:24 -0400 | [diff] [blame] | 4728 | ci_dpm_powergate_uvd(rdev, false); |
| 4729 | |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 4730 | if (!ci_is_smc_running(rdev)) |
| 4731 | return; |
| 4732 | |
| 4733 | if (pi->thermal_protection) |
| 4734 | ci_enable_thermal_protection(rdev, false); |
| 4735 | ci_enable_power_containment(rdev, false); |
| 4736 | ci_enable_smc_cac(rdev, false); |
| 4737 | ci_enable_didt(rdev, false); |
| 4738 | ci_enable_spread_spectrum(rdev, false); |
| 4739 | ci_enable_auto_throttle_source(rdev, RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL, false); |
| 4740 | ci_stop_dpm(rdev); |
| 4741 | ci_enable_ds_master_switch(rdev, true); |
| 4742 | ci_enable_ulv(rdev, false); |
| 4743 | ci_clear_vc(rdev); |
| 4744 | ci_reset_to_default(rdev); |
| 4745 | ci_dpm_stop_smc(rdev); |
| 4746 | ci_force_switch_to_arb_f0(rdev); |
| 4747 | |
| 4748 | ci_update_current_ps(rdev, boot_ps); |
| 4749 | } |
| 4750 | |
| 4751 | int ci_dpm_set_power_state(struct radeon_device *rdev) |
| 4752 | { |
| 4753 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 4754 | struct radeon_ps *new_ps = &pi->requested_rps; |
| 4755 | struct radeon_ps *old_ps = &pi->current_rps; |
| 4756 | int ret; |
| 4757 | |
| 4758 | ci_find_dpm_states_clocks_in_dpm_table(rdev, new_ps); |
| 4759 | if (pi->pcie_performance_request) |
| 4760 | ci_request_link_speed_change_before_state_change(rdev, new_ps, old_ps); |
| 4761 | ret = ci_freeze_sclk_mclk_dpm(rdev); |
| 4762 | if (ret) { |
| 4763 | DRM_ERROR("ci_freeze_sclk_mclk_dpm failed\n"); |
| 4764 | return ret; |
| 4765 | } |
| 4766 | ret = ci_populate_and_upload_sclk_mclk_dpm_levels(rdev, new_ps); |
| 4767 | if (ret) { |
| 4768 | DRM_ERROR("ci_populate_and_upload_sclk_mclk_dpm_levels failed\n"); |
| 4769 | return ret; |
| 4770 | } |
| 4771 | ret = ci_generate_dpm_level_enable_mask(rdev, new_ps); |
| 4772 | if (ret) { |
| 4773 | DRM_ERROR("ci_generate_dpm_level_enable_mask failed\n"); |
| 4774 | return ret; |
| 4775 | } |
Alex Deucher | 8cd3668 | 2013-08-23 11:05:24 -0400 | [diff] [blame] | 4776 | |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 4777 | ret = ci_update_vce_dpm(rdev, new_ps, old_ps); |
| 4778 | if (ret) { |
| 4779 | DRM_ERROR("ci_update_vce_dpm failed\n"); |
| 4780 | return ret; |
| 4781 | } |
Alex Deucher | 8cd3668 | 2013-08-23 11:05:24 -0400 | [diff] [blame] | 4782 | |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 4783 | ret = ci_update_sclk_t(rdev); |
| 4784 | if (ret) { |
| 4785 | DRM_ERROR("ci_update_sclk_t failed\n"); |
| 4786 | return ret; |
| 4787 | } |
| 4788 | if (pi->caps_dynamic_ac_timing) { |
| 4789 | ret = ci_update_and_upload_mc_reg_table(rdev); |
| 4790 | if (ret) { |
| 4791 | DRM_ERROR("ci_update_and_upload_mc_reg_table failed\n"); |
| 4792 | return ret; |
| 4793 | } |
| 4794 | } |
| 4795 | ret = ci_program_memory_timing_parameters(rdev); |
| 4796 | if (ret) { |
| 4797 | DRM_ERROR("ci_program_memory_timing_parameters failed\n"); |
| 4798 | return ret; |
| 4799 | } |
| 4800 | ret = ci_unfreeze_sclk_mclk_dpm(rdev); |
| 4801 | if (ret) { |
| 4802 | DRM_ERROR("ci_unfreeze_sclk_mclk_dpm failed\n"); |
| 4803 | return ret; |
| 4804 | } |
| 4805 | ret = ci_upload_dpm_level_enable_mask(rdev); |
| 4806 | if (ret) { |
| 4807 | DRM_ERROR("ci_upload_dpm_level_enable_mask failed\n"); |
| 4808 | return ret; |
| 4809 | } |
| 4810 | if (pi->pcie_performance_request) |
| 4811 | ci_notify_link_speed_change_after_state_change(rdev, new_ps, old_ps); |
| 4812 | |
| 4813 | return 0; |
| 4814 | } |
| 4815 | |
| 4816 | int ci_dpm_power_control_set_level(struct radeon_device *rdev) |
| 4817 | { |
| 4818 | return ci_power_control_set_level(rdev); |
| 4819 | } |
| 4820 | |
| 4821 | void ci_dpm_reset_asic(struct radeon_device *rdev) |
| 4822 | { |
| 4823 | ci_set_boot_state(rdev); |
| 4824 | } |
| 4825 | |
| 4826 | void ci_dpm_display_configuration_changed(struct radeon_device *rdev) |
| 4827 | { |
| 4828 | ci_program_display_gap(rdev); |
| 4829 | } |
| 4830 | |
| 4831 | union power_info { |
| 4832 | struct _ATOM_POWERPLAY_INFO info; |
| 4833 | struct _ATOM_POWERPLAY_INFO_V2 info_2; |
| 4834 | struct _ATOM_POWERPLAY_INFO_V3 info_3; |
| 4835 | struct _ATOM_PPLIB_POWERPLAYTABLE pplib; |
| 4836 | struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2; |
| 4837 | struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3; |
| 4838 | }; |
| 4839 | |
| 4840 | union pplib_clock_info { |
| 4841 | struct _ATOM_PPLIB_R600_CLOCK_INFO r600; |
| 4842 | struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780; |
| 4843 | struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen; |
| 4844 | struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo; |
| 4845 | struct _ATOM_PPLIB_SI_CLOCK_INFO si; |
| 4846 | struct _ATOM_PPLIB_CI_CLOCK_INFO ci; |
| 4847 | }; |
| 4848 | |
| 4849 | union pplib_power_state { |
| 4850 | struct _ATOM_PPLIB_STATE v1; |
| 4851 | struct _ATOM_PPLIB_STATE_V2 v2; |
| 4852 | }; |
| 4853 | |
| 4854 | static void ci_parse_pplib_non_clock_info(struct radeon_device *rdev, |
| 4855 | struct radeon_ps *rps, |
| 4856 | struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info, |
| 4857 | u8 table_rev) |
| 4858 | { |
| 4859 | rps->caps = le32_to_cpu(non_clock_info->ulCapsAndSettings); |
| 4860 | rps->class = le16_to_cpu(non_clock_info->usClassification); |
| 4861 | rps->class2 = le16_to_cpu(non_clock_info->usClassification2); |
| 4862 | |
| 4863 | if (ATOM_PPLIB_NONCLOCKINFO_VER1 < table_rev) { |
| 4864 | rps->vclk = le32_to_cpu(non_clock_info->ulVCLK); |
| 4865 | rps->dclk = le32_to_cpu(non_clock_info->ulDCLK); |
| 4866 | } else { |
| 4867 | rps->vclk = 0; |
| 4868 | rps->dclk = 0; |
| 4869 | } |
| 4870 | |
| 4871 | if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT) |
| 4872 | rdev->pm.dpm.boot_ps = rps; |
| 4873 | if (rps->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE) |
| 4874 | rdev->pm.dpm.uvd_ps = rps; |
| 4875 | } |
| 4876 | |
| 4877 | static void ci_parse_pplib_clock_info(struct radeon_device *rdev, |
| 4878 | struct radeon_ps *rps, int index, |
| 4879 | union pplib_clock_info *clock_info) |
| 4880 | { |
| 4881 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 4882 | struct ci_ps *ps = ci_get_ps(rps); |
| 4883 | struct ci_pl *pl = &ps->performance_levels[index]; |
| 4884 | |
| 4885 | ps->performance_level_count = index + 1; |
| 4886 | |
| 4887 | pl->sclk = le16_to_cpu(clock_info->ci.usEngineClockLow); |
| 4888 | pl->sclk |= clock_info->ci.ucEngineClockHigh << 16; |
| 4889 | pl->mclk = le16_to_cpu(clock_info->ci.usMemoryClockLow); |
| 4890 | pl->mclk |= clock_info->ci.ucMemoryClockHigh << 16; |
| 4891 | |
| 4892 | pl->pcie_gen = r600_get_pcie_gen_support(rdev, |
| 4893 | pi->sys_pcie_mask, |
| 4894 | pi->vbios_boot_state.pcie_gen_bootup_value, |
| 4895 | clock_info->ci.ucPCIEGen); |
| 4896 | pl->pcie_lane = r600_get_pcie_lane_support(rdev, |
| 4897 | pi->vbios_boot_state.pcie_lane_bootup_value, |
| 4898 | le16_to_cpu(clock_info->ci.usPCIELane)); |
| 4899 | |
| 4900 | if (rps->class & ATOM_PPLIB_CLASSIFICATION_ACPI) { |
| 4901 | pi->acpi_pcie_gen = pl->pcie_gen; |
| 4902 | } |
| 4903 | |
| 4904 | if (rps->class2 & ATOM_PPLIB_CLASSIFICATION2_ULV) { |
| 4905 | pi->ulv.supported = true; |
| 4906 | pi->ulv.pl = *pl; |
| 4907 | pi->ulv.cg_ulv_parameter = CISLANDS_CGULVPARAMETER_DFLT; |
| 4908 | } |
| 4909 | |
| 4910 | /* patch up boot state */ |
| 4911 | if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT) { |
| 4912 | pl->mclk = pi->vbios_boot_state.mclk_bootup_value; |
| 4913 | pl->sclk = pi->vbios_boot_state.sclk_bootup_value; |
| 4914 | pl->pcie_gen = pi->vbios_boot_state.pcie_gen_bootup_value; |
| 4915 | pl->pcie_lane = pi->vbios_boot_state.pcie_lane_bootup_value; |
| 4916 | } |
| 4917 | |
| 4918 | switch (rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) { |
| 4919 | case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY: |
| 4920 | pi->use_pcie_powersaving_levels = true; |
| 4921 | if (pi->pcie_gen_powersaving.max < pl->pcie_gen) |
| 4922 | pi->pcie_gen_powersaving.max = pl->pcie_gen; |
| 4923 | if (pi->pcie_gen_powersaving.min > pl->pcie_gen) |
| 4924 | pi->pcie_gen_powersaving.min = pl->pcie_gen; |
| 4925 | if (pi->pcie_lane_powersaving.max < pl->pcie_lane) |
| 4926 | pi->pcie_lane_powersaving.max = pl->pcie_lane; |
| 4927 | if (pi->pcie_lane_powersaving.min > pl->pcie_lane) |
| 4928 | pi->pcie_lane_powersaving.min = pl->pcie_lane; |
| 4929 | break; |
| 4930 | case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE: |
| 4931 | pi->use_pcie_performance_levels = true; |
| 4932 | if (pi->pcie_gen_performance.max < pl->pcie_gen) |
| 4933 | pi->pcie_gen_performance.max = pl->pcie_gen; |
| 4934 | if (pi->pcie_gen_performance.min > pl->pcie_gen) |
| 4935 | pi->pcie_gen_performance.min = pl->pcie_gen; |
| 4936 | if (pi->pcie_lane_performance.max < pl->pcie_lane) |
| 4937 | pi->pcie_lane_performance.max = pl->pcie_lane; |
| 4938 | if (pi->pcie_lane_performance.min > pl->pcie_lane) |
| 4939 | pi->pcie_lane_performance.min = pl->pcie_lane; |
| 4940 | break; |
| 4941 | default: |
| 4942 | break; |
| 4943 | } |
| 4944 | } |
| 4945 | |
| 4946 | static int ci_parse_power_table(struct radeon_device *rdev) |
| 4947 | { |
| 4948 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 4949 | struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info; |
| 4950 | union pplib_power_state *power_state; |
| 4951 | int i, j, k, non_clock_array_index, clock_array_index; |
| 4952 | union pplib_clock_info *clock_info; |
| 4953 | struct _StateArray *state_array; |
| 4954 | struct _ClockInfoArray *clock_info_array; |
| 4955 | struct _NonClockInfoArray *non_clock_info_array; |
| 4956 | union power_info *power_info; |
| 4957 | int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo); |
| 4958 | u16 data_offset; |
| 4959 | u8 frev, crev; |
| 4960 | u8 *power_state_offset; |
| 4961 | struct ci_ps *ps; |
| 4962 | |
| 4963 | if (!atom_parse_data_header(mode_info->atom_context, index, NULL, |
| 4964 | &frev, &crev, &data_offset)) |
| 4965 | return -EINVAL; |
| 4966 | power_info = (union power_info *)(mode_info->atom_context->bios + data_offset); |
| 4967 | |
| 4968 | state_array = (struct _StateArray *) |
| 4969 | (mode_info->atom_context->bios + data_offset + |
| 4970 | le16_to_cpu(power_info->pplib.usStateArrayOffset)); |
| 4971 | clock_info_array = (struct _ClockInfoArray *) |
| 4972 | (mode_info->atom_context->bios + data_offset + |
| 4973 | le16_to_cpu(power_info->pplib.usClockInfoArrayOffset)); |
| 4974 | non_clock_info_array = (struct _NonClockInfoArray *) |
| 4975 | (mode_info->atom_context->bios + data_offset + |
| 4976 | le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset)); |
| 4977 | |
| 4978 | rdev->pm.dpm.ps = kzalloc(sizeof(struct radeon_ps) * |
| 4979 | state_array->ucNumEntries, GFP_KERNEL); |
| 4980 | if (!rdev->pm.dpm.ps) |
| 4981 | return -ENOMEM; |
| 4982 | power_state_offset = (u8 *)state_array->states; |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 4983 | for (i = 0; i < state_array->ucNumEntries; i++) { |
Alex Deucher | b309ed9 | 2013-08-20 19:08:22 -0400 | [diff] [blame] | 4984 | u8 *idx; |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 4985 | power_state = (union pplib_power_state *)power_state_offset; |
| 4986 | non_clock_array_index = power_state->v2.nonClockInfoIndex; |
| 4987 | non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *) |
| 4988 | &non_clock_info_array->nonClockInfo[non_clock_array_index]; |
| 4989 | if (!rdev->pm.power_state[i].clock_info) |
| 4990 | return -EINVAL; |
| 4991 | ps = kzalloc(sizeof(struct ci_ps), GFP_KERNEL); |
| 4992 | if (ps == NULL) { |
| 4993 | kfree(rdev->pm.dpm.ps); |
| 4994 | return -ENOMEM; |
| 4995 | } |
| 4996 | rdev->pm.dpm.ps[i].ps_priv = ps; |
| 4997 | ci_parse_pplib_non_clock_info(rdev, &rdev->pm.dpm.ps[i], |
| 4998 | non_clock_info, |
| 4999 | non_clock_info_array->ucEntrySize); |
| 5000 | k = 0; |
Alex Deucher | b309ed9 | 2013-08-20 19:08:22 -0400 | [diff] [blame] | 5001 | idx = (u8 *)&power_state->v2.clockInfoIndex[0]; |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 5002 | for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) { |
Alex Deucher | b309ed9 | 2013-08-20 19:08:22 -0400 | [diff] [blame] | 5003 | clock_array_index = idx[j]; |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 5004 | if (clock_array_index >= clock_info_array->ucNumEntries) |
| 5005 | continue; |
| 5006 | if (k >= CISLANDS_MAX_HARDWARE_POWERLEVELS) |
| 5007 | break; |
| 5008 | clock_info = (union pplib_clock_info *) |
Alex Deucher | b309ed9 | 2013-08-20 19:08:22 -0400 | [diff] [blame] | 5009 | ((u8 *)&clock_info_array->clockInfo[0] + |
| 5010 | (clock_array_index * clock_info_array->ucEntrySize)); |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 5011 | ci_parse_pplib_clock_info(rdev, |
| 5012 | &rdev->pm.dpm.ps[i], k, |
| 5013 | clock_info); |
| 5014 | k++; |
| 5015 | } |
| 5016 | power_state_offset += 2 + power_state->v2.ucNumDPMLevels; |
| 5017 | } |
| 5018 | rdev->pm.dpm.num_ps = state_array->ucNumEntries; |
Alex Deucher | 8cd3668 | 2013-08-23 11:05:24 -0400 | [diff] [blame] | 5019 | |
| 5020 | /* fill in the vce power states */ |
| 5021 | for (i = 0; i < RADEON_MAX_VCE_LEVELS; i++) { |
| 5022 | u32 sclk, mclk; |
| 5023 | clock_array_index = rdev->pm.dpm.vce_states[i].clk_idx; |
| 5024 | clock_info = (union pplib_clock_info *) |
| 5025 | &clock_info_array->clockInfo[clock_array_index * clock_info_array->ucEntrySize]; |
| 5026 | sclk = le16_to_cpu(clock_info->ci.usEngineClockLow); |
| 5027 | sclk |= clock_info->ci.ucEngineClockHigh << 16; |
| 5028 | mclk = le16_to_cpu(clock_info->ci.usMemoryClockLow); |
| 5029 | mclk |= clock_info->ci.ucMemoryClockHigh << 16; |
| 5030 | rdev->pm.dpm.vce_states[i].sclk = sclk; |
| 5031 | rdev->pm.dpm.vce_states[i].mclk = mclk; |
| 5032 | } |
| 5033 | |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 5034 | return 0; |
| 5035 | } |
| 5036 | |
Alex Deucher | 9a04dad3 | 2014-01-07 12:16:05 -0500 | [diff] [blame] | 5037 | static int ci_get_vbios_boot_values(struct radeon_device *rdev, |
| 5038 | struct ci_vbios_boot_state *boot_state) |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 5039 | { |
| 5040 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 5041 | int index = GetIndexIntoMasterTable(DATA, FirmwareInfo); |
| 5042 | ATOM_FIRMWARE_INFO_V2_2 *firmware_info; |
| 5043 | u8 frev, crev; |
| 5044 | u16 data_offset; |
| 5045 | |
| 5046 | if (atom_parse_data_header(mode_info->atom_context, index, NULL, |
| 5047 | &frev, &crev, &data_offset)) { |
| 5048 | firmware_info = |
| 5049 | (ATOM_FIRMWARE_INFO_V2_2 *)(mode_info->atom_context->bios + |
| 5050 | data_offset); |
| 5051 | boot_state->mvdd_bootup_value = le16_to_cpu(firmware_info->usBootUpMVDDCVoltage); |
| 5052 | boot_state->vddc_bootup_value = le16_to_cpu(firmware_info->usBootUpVDDCVoltage); |
| 5053 | boot_state->vddci_bootup_value = le16_to_cpu(firmware_info->usBootUpVDDCIVoltage); |
| 5054 | boot_state->pcie_gen_bootup_value = ci_get_current_pcie_speed(rdev); |
| 5055 | boot_state->pcie_lane_bootup_value = ci_get_current_pcie_lane_number(rdev); |
| 5056 | boot_state->sclk_bootup_value = le32_to_cpu(firmware_info->ulDefaultEngineClock); |
| 5057 | boot_state->mclk_bootup_value = le32_to_cpu(firmware_info->ulDefaultMemoryClock); |
| 5058 | |
| 5059 | return 0; |
| 5060 | } |
| 5061 | return -EINVAL; |
| 5062 | } |
| 5063 | |
| 5064 | void ci_dpm_fini(struct radeon_device *rdev) |
| 5065 | { |
| 5066 | int i; |
| 5067 | |
| 5068 | for (i = 0; i < rdev->pm.dpm.num_ps; i++) { |
| 5069 | kfree(rdev->pm.dpm.ps[i].ps_priv); |
| 5070 | } |
| 5071 | kfree(rdev->pm.dpm.ps); |
| 5072 | kfree(rdev->pm.dpm.priv); |
| 5073 | kfree(rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries); |
| 5074 | r600_free_extended_power_table(rdev); |
| 5075 | } |
| 5076 | |
| 5077 | int ci_dpm_init(struct radeon_device *rdev) |
| 5078 | { |
| 5079 | int index = GetIndexIntoMasterTable(DATA, ASIC_InternalSS_Info); |
| 5080 | u16 data_offset, size; |
| 5081 | u8 frev, crev; |
| 5082 | struct ci_power_info *pi; |
| 5083 | int ret; |
| 5084 | u32 mask; |
| 5085 | |
| 5086 | pi = kzalloc(sizeof(struct ci_power_info), GFP_KERNEL); |
| 5087 | if (pi == NULL) |
| 5088 | return -ENOMEM; |
| 5089 | rdev->pm.dpm.priv = pi; |
| 5090 | |
| 5091 | ret = drm_pcie_get_speed_cap_mask(rdev->ddev, &mask); |
| 5092 | if (ret) |
| 5093 | pi->sys_pcie_mask = 0; |
| 5094 | else |
| 5095 | pi->sys_pcie_mask = mask; |
| 5096 | pi->force_pcie_gen = RADEON_PCIE_GEN_INVALID; |
| 5097 | |
| 5098 | pi->pcie_gen_performance.max = RADEON_PCIE_GEN1; |
| 5099 | pi->pcie_gen_performance.min = RADEON_PCIE_GEN3; |
| 5100 | pi->pcie_gen_powersaving.max = RADEON_PCIE_GEN1; |
| 5101 | pi->pcie_gen_powersaving.min = RADEON_PCIE_GEN3; |
| 5102 | |
| 5103 | pi->pcie_lane_performance.max = 0; |
| 5104 | pi->pcie_lane_performance.min = 16; |
| 5105 | pi->pcie_lane_powersaving.max = 0; |
| 5106 | pi->pcie_lane_powersaving.min = 16; |
| 5107 | |
| 5108 | ret = ci_get_vbios_boot_values(rdev, &pi->vbios_boot_state); |
| 5109 | if (ret) { |
| 5110 | ci_dpm_fini(rdev); |
| 5111 | return ret; |
| 5112 | } |
Alex Deucher | 82f79cc | 2013-08-21 10:02:32 -0400 | [diff] [blame] | 5113 | |
| 5114 | ret = r600_get_platform_caps(rdev); |
| 5115 | if (ret) { |
| 5116 | ci_dpm_fini(rdev); |
| 5117 | return ret; |
| 5118 | } |
Alex Deucher | 8cd3668 | 2013-08-23 11:05:24 -0400 | [diff] [blame] | 5119 | |
| 5120 | ret = r600_parse_extended_power_table(rdev); |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 5121 | if (ret) { |
| 5122 | ci_dpm_fini(rdev); |
| 5123 | return ret; |
| 5124 | } |
Alex Deucher | 8cd3668 | 2013-08-23 11:05:24 -0400 | [diff] [blame] | 5125 | |
| 5126 | ret = ci_parse_power_table(rdev); |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 5127 | if (ret) { |
| 5128 | ci_dpm_fini(rdev); |
| 5129 | return ret; |
| 5130 | } |
| 5131 | |
| 5132 | pi->dll_default_on = false; |
| 5133 | pi->sram_end = SMC_RAM_END; |
| 5134 | |
| 5135 | pi->activity_target[0] = CISLAND_TARGETACTIVITY_DFLT; |
| 5136 | pi->activity_target[1] = CISLAND_TARGETACTIVITY_DFLT; |
| 5137 | pi->activity_target[2] = CISLAND_TARGETACTIVITY_DFLT; |
| 5138 | pi->activity_target[3] = CISLAND_TARGETACTIVITY_DFLT; |
| 5139 | pi->activity_target[4] = CISLAND_TARGETACTIVITY_DFLT; |
| 5140 | pi->activity_target[5] = CISLAND_TARGETACTIVITY_DFLT; |
| 5141 | pi->activity_target[6] = CISLAND_TARGETACTIVITY_DFLT; |
| 5142 | pi->activity_target[7] = CISLAND_TARGETACTIVITY_DFLT; |
| 5143 | |
| 5144 | pi->mclk_activity_target = CISLAND_MCLK_TARGETACTIVITY_DFLT; |
| 5145 | |
| 5146 | pi->sclk_dpm_key_disabled = 0; |
| 5147 | pi->mclk_dpm_key_disabled = 0; |
| 5148 | pi->pcie_dpm_key_disabled = 0; |
| 5149 | |
Alex Deucher | 57700ad | 2014-04-10 22:29:03 -0400 | [diff] [blame] | 5150 | /* mclk dpm is unstable on some R7 260X cards */ |
| 5151 | if (rdev->pdev->device == 0x6658) |
| 5152 | pi->mclk_dpm_key_disabled = 1; |
| 5153 | |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 5154 | pi->caps_sclk_ds = true; |
| 5155 | |
| 5156 | pi->mclk_strobe_mode_threshold = 40000; |
| 5157 | pi->mclk_stutter_mode_threshold = 40000; |
| 5158 | pi->mclk_edc_enable_threshold = 40000; |
| 5159 | pi->mclk_edc_wr_enable_threshold = 40000; |
| 5160 | |
| 5161 | ci_initialize_powertune_defaults(rdev); |
| 5162 | |
| 5163 | pi->caps_fps = false; |
| 5164 | |
| 5165 | pi->caps_sclk_throttle_low_notification = false; |
| 5166 | |
Alex Deucher | 9597fe1 | 2013-08-23 11:06:12 -0400 | [diff] [blame] | 5167 | pi->caps_uvd_dpm = true; |
Alex Deucher | ee35b00 | 2013-08-23 11:09:21 -0400 | [diff] [blame] | 5168 | pi->caps_vce_dpm = true; |
Alex Deucher | 9597fe1 | 2013-08-23 11:06:12 -0400 | [diff] [blame] | 5169 | |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 5170 | ci_get_leakage_voltages(rdev); |
| 5171 | ci_patch_dependency_tables_with_leakage(rdev); |
| 5172 | ci_set_private_data_variables_based_on_pptable(rdev); |
| 5173 | |
| 5174 | rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries = |
| 5175 | kzalloc(4 * sizeof(struct radeon_clock_voltage_dependency_entry), GFP_KERNEL); |
| 5176 | if (!rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries) { |
| 5177 | ci_dpm_fini(rdev); |
| 5178 | return -ENOMEM; |
| 5179 | } |
| 5180 | rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.count = 4; |
| 5181 | rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[0].clk = 0; |
| 5182 | rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[0].v = 0; |
| 5183 | rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[1].clk = 36000; |
| 5184 | rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[1].v = 720; |
| 5185 | rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[2].clk = 54000; |
| 5186 | rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[2].v = 810; |
| 5187 | rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[3].clk = 72000; |
| 5188 | rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[3].v = 900; |
| 5189 | |
| 5190 | rdev->pm.dpm.dyn_state.mclk_sclk_ratio = 4; |
| 5191 | rdev->pm.dpm.dyn_state.sclk_mclk_delta = 15000; |
| 5192 | rdev->pm.dpm.dyn_state.vddc_vddci_delta = 200; |
| 5193 | |
| 5194 | rdev->pm.dpm.dyn_state.valid_sclk_values.count = 0; |
| 5195 | rdev->pm.dpm.dyn_state.valid_sclk_values.values = NULL; |
| 5196 | rdev->pm.dpm.dyn_state.valid_mclk_values.count = 0; |
| 5197 | rdev->pm.dpm.dyn_state.valid_mclk_values.values = NULL; |
| 5198 | |
Alex Deucher | 2d40038 | 2013-08-09 18:27:47 -0400 | [diff] [blame] | 5199 | if (rdev->family == CHIP_HAWAII) { |
| 5200 | pi->thermal_temp_setting.temperature_low = 94500; |
| 5201 | pi->thermal_temp_setting.temperature_high = 95000; |
| 5202 | pi->thermal_temp_setting.temperature_shutdown = 104000; |
| 5203 | } else { |
| 5204 | pi->thermal_temp_setting.temperature_low = 99500; |
| 5205 | pi->thermal_temp_setting.temperature_high = 100000; |
| 5206 | pi->thermal_temp_setting.temperature_shutdown = 104000; |
| 5207 | } |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 5208 | |
| 5209 | pi->uvd_enabled = false; |
| 5210 | |
| 5211 | pi->voltage_control = CISLANDS_VOLTAGE_CONTROL_NONE; |
| 5212 | pi->vddci_control = CISLANDS_VOLTAGE_CONTROL_NONE; |
| 5213 | pi->mvdd_control = CISLANDS_VOLTAGE_CONTROL_NONE; |
| 5214 | if (radeon_atom_is_voltage_gpio(rdev, VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_GPIO_LUT)) |
| 5215 | pi->voltage_control = CISLANDS_VOLTAGE_CONTROL_BY_GPIO; |
| 5216 | else if (radeon_atom_is_voltage_gpio(rdev, VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_SVID2)) |
| 5217 | pi->voltage_control = CISLANDS_VOLTAGE_CONTROL_BY_SVID2; |
| 5218 | |
| 5219 | if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_VDDCI_CONTROL) { |
| 5220 | if (radeon_atom_is_voltage_gpio(rdev, VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT)) |
| 5221 | pi->vddci_control = CISLANDS_VOLTAGE_CONTROL_BY_GPIO; |
| 5222 | else if (radeon_atom_is_voltage_gpio(rdev, VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_SVID2)) |
| 5223 | pi->vddci_control = CISLANDS_VOLTAGE_CONTROL_BY_SVID2; |
| 5224 | else |
| 5225 | rdev->pm.dpm.platform_caps &= ~ATOM_PP_PLATFORM_CAP_VDDCI_CONTROL; |
| 5226 | } |
| 5227 | |
| 5228 | if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_MVDDCONTROL) { |
| 5229 | if (radeon_atom_is_voltage_gpio(rdev, VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT)) |
| 5230 | pi->mvdd_control = CISLANDS_VOLTAGE_CONTROL_BY_GPIO; |
| 5231 | else if (radeon_atom_is_voltage_gpio(rdev, VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_SVID2)) |
| 5232 | pi->mvdd_control = CISLANDS_VOLTAGE_CONTROL_BY_SVID2; |
| 5233 | else |
| 5234 | rdev->pm.dpm.platform_caps &= ~ATOM_PP_PLATFORM_CAP_MVDDCONTROL; |
| 5235 | } |
| 5236 | |
| 5237 | pi->vddc_phase_shed_control = true; |
| 5238 | |
| 5239 | #if defined(CONFIG_ACPI) |
| 5240 | pi->pcie_performance_request = |
| 5241 | radeon_acpi_is_pcie_performance_request_supported(rdev); |
| 5242 | #else |
| 5243 | pi->pcie_performance_request = false; |
| 5244 | #endif |
| 5245 | |
| 5246 | if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size, |
| 5247 | &frev, &crev, &data_offset)) { |
| 5248 | pi->caps_sclk_ss_support = true; |
| 5249 | pi->caps_mclk_ss_support = true; |
| 5250 | pi->dynamic_ss = true; |
| 5251 | } else { |
| 5252 | pi->caps_sclk_ss_support = false; |
| 5253 | pi->caps_mclk_ss_support = false; |
| 5254 | pi->dynamic_ss = true; |
| 5255 | } |
| 5256 | |
| 5257 | if (rdev->pm.int_thermal_type != THERMAL_TYPE_NONE) |
| 5258 | pi->thermal_protection = true; |
| 5259 | else |
| 5260 | pi->thermal_protection = false; |
| 5261 | |
| 5262 | pi->caps_dynamic_ac_timing = true; |
| 5263 | |
Alex Deucher | 47acb1f | 2013-08-26 09:43:24 -0400 | [diff] [blame] | 5264 | pi->uvd_power_gated = false; |
| 5265 | |
Alex Deucher | 679fe80 | 2013-08-30 16:24:33 -0400 | [diff] [blame] | 5266 | /* make sure dc limits are valid */ |
| 5267 | if ((rdev->pm.dpm.dyn_state.max_clock_voltage_on_dc.sclk == 0) || |
| 5268 | (rdev->pm.dpm.dyn_state.max_clock_voltage_on_dc.mclk == 0)) |
| 5269 | rdev->pm.dpm.dyn_state.max_clock_voltage_on_dc = |
| 5270 | rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac; |
| 5271 | |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 5272 | return 0; |
| 5273 | } |
| 5274 | |
Alex Deucher | 94b4adc | 2013-07-15 17:34:33 -0400 | [diff] [blame] | 5275 | void ci_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev, |
| 5276 | struct seq_file *m) |
| 5277 | { |
| 5278 | u32 sclk = ci_get_average_sclk_freq(rdev); |
| 5279 | u32 mclk = ci_get_average_mclk_freq(rdev); |
| 5280 | |
| 5281 | seq_printf(m, "power level avg sclk: %u mclk: %u\n", |
| 5282 | sclk, mclk); |
| 5283 | } |
| 5284 | |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 5285 | void ci_dpm_print_power_state(struct radeon_device *rdev, |
| 5286 | struct radeon_ps *rps) |
| 5287 | { |
| 5288 | struct ci_ps *ps = ci_get_ps(rps); |
| 5289 | struct ci_pl *pl; |
| 5290 | int i; |
| 5291 | |
| 5292 | r600_dpm_print_class_info(rps->class, rps->class2); |
| 5293 | r600_dpm_print_cap_info(rps->caps); |
| 5294 | printk("\tuvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk); |
| 5295 | for (i = 0; i < ps->performance_level_count; i++) { |
| 5296 | pl = &ps->performance_levels[i]; |
| 5297 | printk("\t\tpower level %d sclk: %u mclk: %u pcie gen: %u pcie lanes: %u\n", |
| 5298 | i, pl->sclk, pl->mclk, pl->pcie_gen + 1, pl->pcie_lane); |
| 5299 | } |
| 5300 | r600_dpm_print_ps_status(rdev, rps); |
| 5301 | } |
| 5302 | |
| 5303 | u32 ci_dpm_get_sclk(struct radeon_device *rdev, bool low) |
| 5304 | { |
| 5305 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 5306 | struct ci_ps *requested_state = ci_get_ps(&pi->requested_rps); |
| 5307 | |
| 5308 | if (low) |
| 5309 | return requested_state->performance_levels[0].sclk; |
| 5310 | else |
| 5311 | return requested_state->performance_levels[requested_state->performance_level_count - 1].sclk; |
| 5312 | } |
| 5313 | |
| 5314 | u32 ci_dpm_get_mclk(struct radeon_device *rdev, bool low) |
| 5315 | { |
| 5316 | struct ci_power_info *pi = ci_get_pi(rdev); |
| 5317 | struct ci_ps *requested_state = ci_get_ps(&pi->requested_rps); |
| 5318 | |
| 5319 | if (low) |
| 5320 | return requested_state->performance_levels[0].mclk; |
| 5321 | else |
| 5322 | return requested_state->performance_levels[requested_state->performance_level_count - 1].mclk; |
| 5323 | } |