Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -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 <linux/firmware.h> |
| 25 | #include "drmP.h" |
| 26 | #include "amdgpu.h" |
| 27 | #include "amdgpu_pm.h" |
| 28 | #include "amdgpu_ucode.h" |
| 29 | #include "cikd.h" |
| 30 | #include "amdgpu_dpm.h" |
| 31 | #include "ci_dpm.h" |
| 32 | #include "gfx_v7_0.h" |
| 33 | #include "atom.h" |
Alex Deucher | 50171eb | 2016-02-04 10:44:04 -0500 | [diff] [blame] | 34 | #include "amd_pcie.h" |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 35 | #include <linux/seq_file.h> |
| 36 | |
| 37 | #include "smu/smu_7_0_1_d.h" |
| 38 | #include "smu/smu_7_0_1_sh_mask.h" |
| 39 | |
| 40 | #include "dce/dce_8_0_d.h" |
| 41 | #include "dce/dce_8_0_sh_mask.h" |
| 42 | |
| 43 | #include "bif/bif_4_1_d.h" |
| 44 | #include "bif/bif_4_1_sh_mask.h" |
| 45 | |
| 46 | #include "gca/gfx_7_2_d.h" |
| 47 | #include "gca/gfx_7_2_sh_mask.h" |
| 48 | |
| 49 | #include "gmc/gmc_7_1_d.h" |
| 50 | #include "gmc/gmc_7_1_sh_mask.h" |
| 51 | |
| 52 | MODULE_FIRMWARE("radeon/bonaire_smc.bin"); |
Alex Deucher | 2254c21 | 2015-12-10 00:49:32 -0500 | [diff] [blame] | 53 | MODULE_FIRMWARE("radeon/bonaire_k_smc.bin"); |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 54 | MODULE_FIRMWARE("radeon/hawaii_smc.bin"); |
Alex Deucher | 2254c21 | 2015-12-10 00:49:32 -0500 | [diff] [blame] | 55 | MODULE_FIRMWARE("radeon/hawaii_k_smc.bin"); |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 56 | |
| 57 | #define MC_CG_ARB_FREQ_F0 0x0a |
| 58 | #define MC_CG_ARB_FREQ_F1 0x0b |
| 59 | #define MC_CG_ARB_FREQ_F2 0x0c |
| 60 | #define MC_CG_ARB_FREQ_F3 0x0d |
| 61 | |
| 62 | #define SMC_RAM_END 0x40000 |
| 63 | |
| 64 | #define VOLTAGE_SCALE 4 |
| 65 | #define VOLTAGE_VID_OFFSET_SCALE1 625 |
| 66 | #define VOLTAGE_VID_OFFSET_SCALE2 100 |
| 67 | |
| 68 | static const struct ci_pt_defaults defaults_hawaii_xt = |
| 69 | { |
| 70 | 1, 0xF, 0xFD, 0x19, 5, 0x14, 0, 0xB0000, |
| 71 | { 0x2E, 0x00, 0x00, 0x88, 0x00, 0x00, 0x72, 0x60, 0x51, 0xA7, 0x79, 0x6B, 0x90, 0xBD, 0x79 }, |
| 72 | { 0x217, 0x217, 0x217, 0x242, 0x242, 0x242, 0x269, 0x269, 0x269, 0x2A1, 0x2A1, 0x2A1, 0x2C9, 0x2C9, 0x2C9 } |
| 73 | }; |
| 74 | |
| 75 | static const struct ci_pt_defaults defaults_hawaii_pro = |
| 76 | { |
| 77 | 1, 0xF, 0xFD, 0x19, 5, 0x14, 0, 0x65062, |
| 78 | { 0x2E, 0x00, 0x00, 0x88, 0x00, 0x00, 0x72, 0x60, 0x51, 0xA7, 0x79, 0x6B, 0x90, 0xBD, 0x79 }, |
| 79 | { 0x217, 0x217, 0x217, 0x242, 0x242, 0x242, 0x269, 0x269, 0x269, 0x2A1, 0x2A1, 0x2A1, 0x2C9, 0x2C9, 0x2C9 } |
| 80 | }; |
| 81 | |
| 82 | static const struct ci_pt_defaults defaults_bonaire_xt = |
| 83 | { |
| 84 | 1, 0xF, 0xFD, 0x19, 5, 45, 0, 0xB0000, |
| 85 | { 0x79, 0x253, 0x25D, 0xAE, 0x72, 0x80, 0x83, 0x86, 0x6F, 0xC8, 0xC9, 0xC9, 0x2F, 0x4D, 0x61 }, |
| 86 | { 0x17C, 0x172, 0x180, 0x1BC, 0x1B3, 0x1BD, 0x206, 0x200, 0x203, 0x25D, 0x25A, 0x255, 0x2C3, 0x2C5, 0x2B4 } |
| 87 | }; |
| 88 | |
Slava Grigorev | 5ef8292 | 2016-07-15 11:29:14 -0400 | [diff] [blame] | 89 | #if 0 |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 90 | static const struct ci_pt_defaults defaults_bonaire_pro = |
| 91 | { |
| 92 | 1, 0xF, 0xFD, 0x19, 5, 45, 0, 0x65062, |
| 93 | { 0x8C, 0x23F, 0x244, 0xA6, 0x83, 0x85, 0x86, 0x86, 0x83, 0xDB, 0xDB, 0xDA, 0x67, 0x60, 0x5F }, |
| 94 | { 0x187, 0x193, 0x193, 0x1C7, 0x1D1, 0x1D1, 0x210, 0x219, 0x219, 0x266, 0x26C, 0x26C, 0x2C9, 0x2CB, 0x2CB } |
| 95 | }; |
Slava Grigorev | 5ef8292 | 2016-07-15 11:29:14 -0400 | [diff] [blame] | 96 | #endif |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 97 | |
| 98 | static const struct ci_pt_defaults defaults_saturn_xt = |
| 99 | { |
| 100 | 1, 0xF, 0xFD, 0x19, 5, 55, 0, 0x70000, |
| 101 | { 0x8C, 0x247, 0x249, 0xA6, 0x80, 0x81, 0x8B, 0x89, 0x86, 0xC9, 0xCA, 0xC9, 0x4D, 0x4D, 0x4D }, |
| 102 | { 0x187, 0x187, 0x187, 0x1C7, 0x1C7, 0x1C7, 0x210, 0x210, 0x210, 0x266, 0x266, 0x266, 0x2C9, 0x2C9, 0x2C9 } |
| 103 | }; |
| 104 | |
Slava Grigorev | 529d8c5 | 2016-07-19 00:24:10 -0400 | [diff] [blame] | 105 | #if 0 |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 106 | static const struct ci_pt_defaults defaults_saturn_pro = |
| 107 | { |
| 108 | 1, 0xF, 0xFD, 0x19, 5, 55, 0, 0x30000, |
| 109 | { 0x96, 0x21D, 0x23B, 0xA1, 0x85, 0x87, 0x83, 0x84, 0x81, 0xE6, 0xE6, 0xE6, 0x71, 0x6A, 0x6A }, |
| 110 | { 0x193, 0x19E, 0x19E, 0x1D2, 0x1DC, 0x1DC, 0x21A, 0x223, 0x223, 0x26E, 0x27E, 0x274, 0x2CF, 0x2D2, 0x2D2 } |
| 111 | }; |
Slava Grigorev | 529d8c5 | 2016-07-19 00:24:10 -0400 | [diff] [blame] | 112 | #endif |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 113 | |
| 114 | static const struct ci_pt_config_reg didt_config_ci[] = |
| 115 | { |
| 116 | { 0x10, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 117 | { 0x10, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 118 | { 0x10, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 119 | { 0x10, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 120 | { 0x11, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 121 | { 0x11, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 122 | { 0x11, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 123 | { 0x11, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 124 | { 0x12, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 125 | { 0x12, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 126 | { 0x12, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 127 | { 0x12, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 128 | { 0x2, 0x00003fff, 0, 0x4, CISLANDS_CONFIGREG_DIDT_IND }, |
| 129 | { 0x2, 0x03ff0000, 16, 0x80, CISLANDS_CONFIGREG_DIDT_IND }, |
| 130 | { 0x2, 0x78000000, 27, 0x3, CISLANDS_CONFIGREG_DIDT_IND }, |
| 131 | { 0x1, 0x0000ffff, 0, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND }, |
| 132 | { 0x1, 0xffff0000, 16, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND }, |
| 133 | { 0x0, 0x00000001, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 134 | { 0x30, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 135 | { 0x30, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 136 | { 0x30, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 137 | { 0x30, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 138 | { 0x31, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 139 | { 0x31, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 140 | { 0x31, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 141 | { 0x31, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 142 | { 0x32, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 143 | { 0x32, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 144 | { 0x32, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 145 | { 0x32, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 146 | { 0x22, 0x00003fff, 0, 0x4, CISLANDS_CONFIGREG_DIDT_IND }, |
| 147 | { 0x22, 0x03ff0000, 16, 0x80, CISLANDS_CONFIGREG_DIDT_IND }, |
| 148 | { 0x22, 0x78000000, 27, 0x3, CISLANDS_CONFIGREG_DIDT_IND }, |
| 149 | { 0x21, 0x0000ffff, 0, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND }, |
| 150 | { 0x21, 0xffff0000, 16, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND }, |
| 151 | { 0x20, 0x00000001, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 152 | { 0x50, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 153 | { 0x50, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 154 | { 0x50, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 155 | { 0x50, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 156 | { 0x51, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 157 | { 0x51, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 158 | { 0x51, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 159 | { 0x51, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 160 | { 0x52, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 161 | { 0x52, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 162 | { 0x52, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 163 | { 0x52, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 164 | { 0x42, 0x00003fff, 0, 0x4, CISLANDS_CONFIGREG_DIDT_IND }, |
| 165 | { 0x42, 0x03ff0000, 16, 0x80, CISLANDS_CONFIGREG_DIDT_IND }, |
| 166 | { 0x42, 0x78000000, 27, 0x3, CISLANDS_CONFIGREG_DIDT_IND }, |
| 167 | { 0x41, 0x0000ffff, 0, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND }, |
| 168 | { 0x41, 0xffff0000, 16, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND }, |
| 169 | { 0x40, 0x00000001, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 170 | { 0x70, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 171 | { 0x70, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 172 | { 0x70, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 173 | { 0x70, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 174 | { 0x71, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 175 | { 0x71, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 176 | { 0x71, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 177 | { 0x71, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 178 | { 0x72, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 179 | { 0x72, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 180 | { 0x72, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 181 | { 0x72, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 182 | { 0x62, 0x00003fff, 0, 0x4, CISLANDS_CONFIGREG_DIDT_IND }, |
| 183 | { 0x62, 0x03ff0000, 16, 0x80, CISLANDS_CONFIGREG_DIDT_IND }, |
| 184 | { 0x62, 0x78000000, 27, 0x3, CISLANDS_CONFIGREG_DIDT_IND }, |
| 185 | { 0x61, 0x0000ffff, 0, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND }, |
| 186 | { 0x61, 0xffff0000, 16, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND }, |
| 187 | { 0x60, 0x00000001, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND }, |
| 188 | { 0xFFFFFFFF } |
| 189 | }; |
| 190 | |
| 191 | static u8 ci_get_memory_module_index(struct amdgpu_device *adev) |
| 192 | { |
| 193 | return (u8) ((RREG32(mmBIOS_SCRATCH_4) >> 16) & 0xff); |
| 194 | } |
| 195 | |
| 196 | #define MC_CG_ARB_FREQ_F0 0x0a |
| 197 | #define MC_CG_ARB_FREQ_F1 0x0b |
| 198 | #define MC_CG_ARB_FREQ_F2 0x0c |
| 199 | #define MC_CG_ARB_FREQ_F3 0x0d |
| 200 | |
| 201 | static int ci_copy_and_switch_arb_sets(struct amdgpu_device *adev, |
| 202 | u32 arb_freq_src, u32 arb_freq_dest) |
| 203 | { |
| 204 | u32 mc_arb_dram_timing; |
| 205 | u32 mc_arb_dram_timing2; |
| 206 | u32 burst_time; |
| 207 | u32 mc_cg_config; |
| 208 | |
| 209 | switch (arb_freq_src) { |
| 210 | case MC_CG_ARB_FREQ_F0: |
| 211 | mc_arb_dram_timing = RREG32(mmMC_ARB_DRAM_TIMING); |
| 212 | mc_arb_dram_timing2 = RREG32(mmMC_ARB_DRAM_TIMING2); |
| 213 | burst_time = (RREG32(mmMC_ARB_BURST_TIME) & MC_ARB_BURST_TIME__STATE0_MASK) >> |
| 214 | MC_ARB_BURST_TIME__STATE0__SHIFT; |
| 215 | break; |
| 216 | case MC_CG_ARB_FREQ_F1: |
| 217 | mc_arb_dram_timing = RREG32(mmMC_ARB_DRAM_TIMING_1); |
| 218 | mc_arb_dram_timing2 = RREG32(mmMC_ARB_DRAM_TIMING2_1); |
| 219 | burst_time = (RREG32(mmMC_ARB_BURST_TIME) & MC_ARB_BURST_TIME__STATE1_MASK) >> |
| 220 | MC_ARB_BURST_TIME__STATE1__SHIFT; |
| 221 | break; |
| 222 | default: |
| 223 | return -EINVAL; |
| 224 | } |
| 225 | |
| 226 | switch (arb_freq_dest) { |
| 227 | case MC_CG_ARB_FREQ_F0: |
| 228 | WREG32(mmMC_ARB_DRAM_TIMING, mc_arb_dram_timing); |
| 229 | WREG32(mmMC_ARB_DRAM_TIMING2, mc_arb_dram_timing2); |
| 230 | WREG32_P(mmMC_ARB_BURST_TIME, (burst_time << MC_ARB_BURST_TIME__STATE0__SHIFT), |
| 231 | ~MC_ARB_BURST_TIME__STATE0_MASK); |
| 232 | break; |
| 233 | case MC_CG_ARB_FREQ_F1: |
| 234 | WREG32(mmMC_ARB_DRAM_TIMING_1, mc_arb_dram_timing); |
| 235 | WREG32(mmMC_ARB_DRAM_TIMING2_1, mc_arb_dram_timing2); |
| 236 | WREG32_P(mmMC_ARB_BURST_TIME, (burst_time << MC_ARB_BURST_TIME__STATE1__SHIFT), |
| 237 | ~MC_ARB_BURST_TIME__STATE1_MASK); |
| 238 | break; |
| 239 | default: |
| 240 | return -EINVAL; |
| 241 | } |
| 242 | |
| 243 | mc_cg_config = RREG32(mmMC_CG_CONFIG) | 0x0000000F; |
| 244 | WREG32(mmMC_CG_CONFIG, mc_cg_config); |
| 245 | WREG32_P(mmMC_ARB_CG, (arb_freq_dest) << MC_ARB_CG__CG_ARB_REQ__SHIFT, |
| 246 | ~MC_ARB_CG__CG_ARB_REQ_MASK); |
| 247 | |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | static u8 ci_get_ddr3_mclk_frequency_ratio(u32 memory_clock) |
| 252 | { |
| 253 | u8 mc_para_index; |
| 254 | |
| 255 | if (memory_clock < 10000) |
| 256 | mc_para_index = 0; |
| 257 | else if (memory_clock >= 80000) |
| 258 | mc_para_index = 0x0f; |
| 259 | else |
| 260 | mc_para_index = (u8)((memory_clock - 10000) / 5000 + 1); |
| 261 | return mc_para_index; |
| 262 | } |
| 263 | |
| 264 | static u8 ci_get_mclk_frequency_ratio(u32 memory_clock, bool strobe_mode) |
| 265 | { |
| 266 | u8 mc_para_index; |
| 267 | |
| 268 | if (strobe_mode) { |
| 269 | if (memory_clock < 12500) |
| 270 | mc_para_index = 0x00; |
| 271 | else if (memory_clock > 47500) |
| 272 | mc_para_index = 0x0f; |
| 273 | else |
| 274 | mc_para_index = (u8)((memory_clock - 10000) / 2500); |
| 275 | } else { |
| 276 | if (memory_clock < 65000) |
| 277 | mc_para_index = 0x00; |
| 278 | else if (memory_clock > 135000) |
| 279 | mc_para_index = 0x0f; |
| 280 | else |
| 281 | mc_para_index = (u8)((memory_clock - 60000) / 5000); |
| 282 | } |
| 283 | return mc_para_index; |
| 284 | } |
| 285 | |
| 286 | static void ci_trim_voltage_table_to_fit_state_table(struct amdgpu_device *adev, |
| 287 | u32 max_voltage_steps, |
| 288 | struct atom_voltage_table *voltage_table) |
| 289 | { |
| 290 | unsigned int i, diff; |
| 291 | |
| 292 | if (voltage_table->count <= max_voltage_steps) |
| 293 | return; |
| 294 | |
| 295 | diff = voltage_table->count - max_voltage_steps; |
| 296 | |
| 297 | for (i = 0; i < max_voltage_steps; i++) |
| 298 | voltage_table->entries[i] = voltage_table->entries[i + diff]; |
| 299 | |
| 300 | voltage_table->count = max_voltage_steps; |
| 301 | } |
| 302 | |
| 303 | static int ci_get_std_voltage_value_sidd(struct amdgpu_device *adev, |
| 304 | struct atom_voltage_table_entry *voltage_table, |
| 305 | u16 *std_voltage_hi_sidd, u16 *std_voltage_lo_sidd); |
| 306 | static int ci_set_power_limit(struct amdgpu_device *adev, u32 n); |
| 307 | static int ci_set_overdrive_target_tdp(struct amdgpu_device *adev, |
| 308 | u32 target_tdp); |
| 309 | static int ci_update_uvd_dpm(struct amdgpu_device *adev, bool gate); |
| 310 | static void ci_dpm_set_dpm_funcs(struct amdgpu_device *adev); |
| 311 | static void ci_dpm_set_irq_funcs(struct amdgpu_device *adev); |
| 312 | |
| 313 | static PPSMC_Result amdgpu_ci_send_msg_to_smc_with_parameter(struct amdgpu_device *adev, |
| 314 | PPSMC_Msg msg, u32 parameter); |
| 315 | static void ci_thermal_start_smc_fan_control(struct amdgpu_device *adev); |
| 316 | static void ci_fan_ctrl_set_default_mode(struct amdgpu_device *adev); |
| 317 | |
| 318 | static struct ci_power_info *ci_get_pi(struct amdgpu_device *adev) |
| 319 | { |
| 320 | struct ci_power_info *pi = adev->pm.dpm.priv; |
| 321 | |
| 322 | return pi; |
| 323 | } |
| 324 | |
| 325 | static struct ci_ps *ci_get_ps(struct amdgpu_ps *rps) |
| 326 | { |
| 327 | struct ci_ps *ps = rps->ps_priv; |
| 328 | |
| 329 | return ps; |
| 330 | } |
| 331 | |
| 332 | static void ci_initialize_powertune_defaults(struct amdgpu_device *adev) |
| 333 | { |
| 334 | struct ci_power_info *pi = ci_get_pi(adev); |
| 335 | |
| 336 | switch (adev->pdev->device) { |
| 337 | case 0x6649: |
| 338 | case 0x6650: |
| 339 | case 0x6651: |
| 340 | case 0x6658: |
| 341 | case 0x665C: |
| 342 | case 0x665D: |
| 343 | default: |
| 344 | pi->powertune_defaults = &defaults_bonaire_xt; |
| 345 | break; |
| 346 | case 0x6640: |
| 347 | case 0x6641: |
| 348 | case 0x6646: |
| 349 | case 0x6647: |
| 350 | pi->powertune_defaults = &defaults_saturn_xt; |
| 351 | break; |
| 352 | case 0x67B8: |
| 353 | case 0x67B0: |
| 354 | pi->powertune_defaults = &defaults_hawaii_xt; |
| 355 | break; |
| 356 | case 0x67BA: |
| 357 | case 0x67B1: |
| 358 | pi->powertune_defaults = &defaults_hawaii_pro; |
| 359 | break; |
| 360 | case 0x67A0: |
| 361 | case 0x67A1: |
| 362 | case 0x67A2: |
| 363 | case 0x67A8: |
| 364 | case 0x67A9: |
| 365 | case 0x67AA: |
| 366 | case 0x67B9: |
| 367 | case 0x67BE: |
| 368 | pi->powertune_defaults = &defaults_bonaire_xt; |
| 369 | break; |
| 370 | } |
| 371 | |
| 372 | pi->dte_tj_offset = 0; |
| 373 | |
| 374 | pi->caps_power_containment = true; |
| 375 | pi->caps_cac = false; |
| 376 | pi->caps_sq_ramping = false; |
| 377 | pi->caps_db_ramping = false; |
| 378 | pi->caps_td_ramping = false; |
| 379 | pi->caps_tcp_ramping = false; |
| 380 | |
| 381 | if (pi->caps_power_containment) { |
| 382 | pi->caps_cac = true; |
| 383 | if (adev->asic_type == CHIP_HAWAII) |
| 384 | pi->enable_bapm_feature = false; |
| 385 | else |
| 386 | pi->enable_bapm_feature = true; |
| 387 | pi->enable_tdc_limit_feature = true; |
| 388 | pi->enable_pkg_pwr_tracking_feature = true; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | static u8 ci_convert_to_vid(u16 vddc) |
| 393 | { |
| 394 | return (6200 - (vddc * VOLTAGE_SCALE)) / 25; |
| 395 | } |
| 396 | |
| 397 | static int ci_populate_bapm_vddc_vid_sidd(struct amdgpu_device *adev) |
| 398 | { |
| 399 | struct ci_power_info *pi = ci_get_pi(adev); |
| 400 | u8 *hi_vid = pi->smc_powertune_table.BapmVddCVidHiSidd; |
| 401 | u8 *lo_vid = pi->smc_powertune_table.BapmVddCVidLoSidd; |
| 402 | u8 *hi2_vid = pi->smc_powertune_table.BapmVddCVidHiSidd2; |
| 403 | u32 i; |
| 404 | |
| 405 | if (adev->pm.dpm.dyn_state.cac_leakage_table.entries == NULL) |
| 406 | return -EINVAL; |
| 407 | if (adev->pm.dpm.dyn_state.cac_leakage_table.count > 8) |
| 408 | return -EINVAL; |
| 409 | if (adev->pm.dpm.dyn_state.cac_leakage_table.count != |
| 410 | adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.count) |
| 411 | return -EINVAL; |
| 412 | |
| 413 | for (i = 0; i < adev->pm.dpm.dyn_state.cac_leakage_table.count; i++) { |
| 414 | if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_EVV) { |
| 415 | lo_vid[i] = ci_convert_to_vid(adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc1); |
| 416 | hi_vid[i] = ci_convert_to_vid(adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc2); |
| 417 | hi2_vid[i] = ci_convert_to_vid(adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc3); |
| 418 | } else { |
| 419 | lo_vid[i] = ci_convert_to_vid(adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc); |
| 420 | hi_vid[i] = ci_convert_to_vid((u16)adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].leakage); |
| 421 | } |
| 422 | } |
| 423 | return 0; |
| 424 | } |
| 425 | |
| 426 | static int ci_populate_vddc_vid(struct amdgpu_device *adev) |
| 427 | { |
| 428 | struct ci_power_info *pi = ci_get_pi(adev); |
| 429 | u8 *vid = pi->smc_powertune_table.VddCVid; |
| 430 | u32 i; |
| 431 | |
| 432 | if (pi->vddc_voltage_table.count > 8) |
| 433 | return -EINVAL; |
| 434 | |
| 435 | for (i = 0; i < pi->vddc_voltage_table.count; i++) |
| 436 | vid[i] = ci_convert_to_vid(pi->vddc_voltage_table.entries[i].value); |
| 437 | |
| 438 | return 0; |
| 439 | } |
| 440 | |
| 441 | static int ci_populate_svi_load_line(struct amdgpu_device *adev) |
| 442 | { |
| 443 | struct ci_power_info *pi = ci_get_pi(adev); |
| 444 | const struct ci_pt_defaults *pt_defaults = pi->powertune_defaults; |
| 445 | |
| 446 | pi->smc_powertune_table.SviLoadLineEn = pt_defaults->svi_load_line_en; |
| 447 | pi->smc_powertune_table.SviLoadLineVddC = pt_defaults->svi_load_line_vddc; |
| 448 | pi->smc_powertune_table.SviLoadLineTrimVddC = 3; |
| 449 | pi->smc_powertune_table.SviLoadLineOffsetVddC = 0; |
| 450 | |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | static int ci_populate_tdc_limit(struct amdgpu_device *adev) |
| 455 | { |
| 456 | struct ci_power_info *pi = ci_get_pi(adev); |
| 457 | const struct ci_pt_defaults *pt_defaults = pi->powertune_defaults; |
| 458 | u16 tdc_limit; |
| 459 | |
| 460 | tdc_limit = adev->pm.dpm.dyn_state.cac_tdp_table->tdc * 256; |
| 461 | pi->smc_powertune_table.TDC_VDDC_PkgLimit = cpu_to_be16(tdc_limit); |
| 462 | pi->smc_powertune_table.TDC_VDDC_ThrottleReleaseLimitPerc = |
| 463 | pt_defaults->tdc_vddc_throttle_release_limit_perc; |
| 464 | pi->smc_powertune_table.TDC_MAWt = pt_defaults->tdc_mawt; |
| 465 | |
| 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | static int ci_populate_dw8(struct amdgpu_device *adev) |
| 470 | { |
| 471 | struct ci_power_info *pi = ci_get_pi(adev); |
| 472 | const struct ci_pt_defaults *pt_defaults = pi->powertune_defaults; |
| 473 | int ret; |
| 474 | |
| 475 | ret = amdgpu_ci_read_smc_sram_dword(adev, |
| 476 | SMU7_FIRMWARE_HEADER_LOCATION + |
| 477 | offsetof(SMU7_Firmware_Header, PmFuseTable) + |
| 478 | offsetof(SMU7_Discrete_PmFuses, TdcWaterfallCtl), |
| 479 | (u32 *)&pi->smc_powertune_table.TdcWaterfallCtl, |
| 480 | pi->sram_end); |
| 481 | if (ret) |
| 482 | return -EINVAL; |
| 483 | else |
| 484 | pi->smc_powertune_table.TdcWaterfallCtl = pt_defaults->tdc_waterfall_ctl; |
| 485 | |
| 486 | return 0; |
| 487 | } |
| 488 | |
| 489 | static int ci_populate_fuzzy_fan(struct amdgpu_device *adev) |
| 490 | { |
| 491 | struct ci_power_info *pi = ci_get_pi(adev); |
| 492 | |
| 493 | if ((adev->pm.dpm.fan.fan_output_sensitivity & (1 << 15)) || |
| 494 | (adev->pm.dpm.fan.fan_output_sensitivity == 0)) |
| 495 | adev->pm.dpm.fan.fan_output_sensitivity = |
| 496 | adev->pm.dpm.fan.default_fan_output_sensitivity; |
| 497 | |
| 498 | pi->smc_powertune_table.FuzzyFan_PwmSetDelta = |
| 499 | cpu_to_be16(adev->pm.dpm.fan.fan_output_sensitivity); |
| 500 | |
| 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | static int ci_min_max_v_gnbl_pm_lid_from_bapm_vddc(struct amdgpu_device *adev) |
| 505 | { |
| 506 | struct ci_power_info *pi = ci_get_pi(adev); |
| 507 | u8 *hi_vid = pi->smc_powertune_table.BapmVddCVidHiSidd; |
| 508 | u8 *lo_vid = pi->smc_powertune_table.BapmVddCVidLoSidd; |
| 509 | int i, min, max; |
| 510 | |
| 511 | min = max = hi_vid[0]; |
| 512 | for (i = 0; i < 8; i++) { |
| 513 | if (0 != hi_vid[i]) { |
| 514 | if (min > hi_vid[i]) |
| 515 | min = hi_vid[i]; |
| 516 | if (max < hi_vid[i]) |
| 517 | max = hi_vid[i]; |
| 518 | } |
| 519 | |
| 520 | if (0 != lo_vid[i]) { |
| 521 | if (min > lo_vid[i]) |
| 522 | min = lo_vid[i]; |
| 523 | if (max < lo_vid[i]) |
| 524 | max = lo_vid[i]; |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | if ((min == 0) || (max == 0)) |
| 529 | return -EINVAL; |
| 530 | pi->smc_powertune_table.GnbLPMLMaxVid = (u8)max; |
| 531 | pi->smc_powertune_table.GnbLPMLMinVid = (u8)min; |
| 532 | |
| 533 | return 0; |
| 534 | } |
| 535 | |
| 536 | static int ci_populate_bapm_vddc_base_leakage_sidd(struct amdgpu_device *adev) |
| 537 | { |
| 538 | struct ci_power_info *pi = ci_get_pi(adev); |
| 539 | u16 hi_sidd = pi->smc_powertune_table.BapmVddCBaseLeakageHiSidd; |
| 540 | u16 lo_sidd = pi->smc_powertune_table.BapmVddCBaseLeakageLoSidd; |
| 541 | struct amdgpu_cac_tdp_table *cac_tdp_table = |
| 542 | adev->pm.dpm.dyn_state.cac_tdp_table; |
| 543 | |
| 544 | hi_sidd = cac_tdp_table->high_cac_leakage / 100 * 256; |
| 545 | lo_sidd = cac_tdp_table->low_cac_leakage / 100 * 256; |
| 546 | |
| 547 | pi->smc_powertune_table.BapmVddCBaseLeakageHiSidd = cpu_to_be16(hi_sidd); |
| 548 | pi->smc_powertune_table.BapmVddCBaseLeakageLoSidd = cpu_to_be16(lo_sidd); |
| 549 | |
| 550 | return 0; |
| 551 | } |
| 552 | |
| 553 | static int ci_populate_bapm_parameters_in_dpm_table(struct amdgpu_device *adev) |
| 554 | { |
| 555 | struct ci_power_info *pi = ci_get_pi(adev); |
| 556 | const struct ci_pt_defaults *pt_defaults = pi->powertune_defaults; |
| 557 | SMU7_Discrete_DpmTable *dpm_table = &pi->smc_state_table; |
| 558 | struct amdgpu_cac_tdp_table *cac_tdp_table = |
| 559 | adev->pm.dpm.dyn_state.cac_tdp_table; |
| 560 | struct amdgpu_ppm_table *ppm = adev->pm.dpm.dyn_state.ppm_table; |
| 561 | int i, j, k; |
| 562 | const u16 *def1; |
| 563 | const u16 *def2; |
| 564 | |
| 565 | dpm_table->DefaultTdp = cac_tdp_table->tdp * 256; |
| 566 | dpm_table->TargetTdp = cac_tdp_table->configurable_tdp * 256; |
| 567 | |
| 568 | dpm_table->DTETjOffset = (u8)pi->dte_tj_offset; |
| 569 | dpm_table->GpuTjMax = |
| 570 | (u8)(pi->thermal_temp_setting.temperature_high / 1000); |
| 571 | dpm_table->GpuTjHyst = 8; |
| 572 | |
| 573 | dpm_table->DTEAmbientTempBase = pt_defaults->dte_ambient_temp_base; |
| 574 | |
| 575 | if (ppm) { |
| 576 | dpm_table->PPM_PkgPwrLimit = cpu_to_be16((u16)ppm->dgpu_tdp * 256 / 1000); |
| 577 | dpm_table->PPM_TemperatureLimit = cpu_to_be16((u16)ppm->tj_max * 256); |
| 578 | } else { |
| 579 | dpm_table->PPM_PkgPwrLimit = cpu_to_be16(0); |
| 580 | dpm_table->PPM_TemperatureLimit = cpu_to_be16(0); |
| 581 | } |
| 582 | |
| 583 | dpm_table->BAPM_TEMP_GRADIENT = cpu_to_be32(pt_defaults->bapm_temp_gradient); |
| 584 | def1 = pt_defaults->bapmti_r; |
| 585 | def2 = pt_defaults->bapmti_rc; |
| 586 | |
| 587 | for (i = 0; i < SMU7_DTE_ITERATIONS; i++) { |
| 588 | for (j = 0; j < SMU7_DTE_SOURCES; j++) { |
| 589 | for (k = 0; k < SMU7_DTE_SINKS; k++) { |
| 590 | dpm_table->BAPMTI_R[i][j][k] = cpu_to_be16(*def1); |
| 591 | dpm_table->BAPMTI_RC[i][j][k] = cpu_to_be16(*def2); |
| 592 | def1++; |
| 593 | def2++; |
| 594 | } |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | return 0; |
| 599 | } |
| 600 | |
| 601 | static int ci_populate_pm_base(struct amdgpu_device *adev) |
| 602 | { |
| 603 | struct ci_power_info *pi = ci_get_pi(adev); |
| 604 | u32 pm_fuse_table_offset; |
| 605 | int ret; |
| 606 | |
| 607 | if (pi->caps_power_containment) { |
| 608 | ret = amdgpu_ci_read_smc_sram_dword(adev, |
| 609 | SMU7_FIRMWARE_HEADER_LOCATION + |
| 610 | offsetof(SMU7_Firmware_Header, PmFuseTable), |
| 611 | &pm_fuse_table_offset, pi->sram_end); |
| 612 | if (ret) |
| 613 | return ret; |
| 614 | ret = ci_populate_bapm_vddc_vid_sidd(adev); |
| 615 | if (ret) |
| 616 | return ret; |
| 617 | ret = ci_populate_vddc_vid(adev); |
| 618 | if (ret) |
| 619 | return ret; |
| 620 | ret = ci_populate_svi_load_line(adev); |
| 621 | if (ret) |
| 622 | return ret; |
| 623 | ret = ci_populate_tdc_limit(adev); |
| 624 | if (ret) |
| 625 | return ret; |
| 626 | ret = ci_populate_dw8(adev); |
| 627 | if (ret) |
| 628 | return ret; |
| 629 | ret = ci_populate_fuzzy_fan(adev); |
| 630 | if (ret) |
| 631 | return ret; |
| 632 | ret = ci_min_max_v_gnbl_pm_lid_from_bapm_vddc(adev); |
| 633 | if (ret) |
| 634 | return ret; |
| 635 | ret = ci_populate_bapm_vddc_base_leakage_sidd(adev); |
| 636 | if (ret) |
| 637 | return ret; |
| 638 | ret = amdgpu_ci_copy_bytes_to_smc(adev, pm_fuse_table_offset, |
| 639 | (u8 *)&pi->smc_powertune_table, |
| 640 | sizeof(SMU7_Discrete_PmFuses), pi->sram_end); |
| 641 | if (ret) |
| 642 | return ret; |
| 643 | } |
| 644 | |
| 645 | return 0; |
| 646 | } |
| 647 | |
| 648 | static void ci_do_enable_didt(struct amdgpu_device *adev, const bool enable) |
| 649 | { |
| 650 | struct ci_power_info *pi = ci_get_pi(adev); |
| 651 | u32 data; |
| 652 | |
| 653 | if (pi->caps_sq_ramping) { |
| 654 | data = RREG32_DIDT(ixDIDT_SQ_CTRL0); |
| 655 | if (enable) |
| 656 | data |= DIDT_SQ_CTRL0__DIDT_CTRL_EN_MASK; |
| 657 | else |
| 658 | data &= ~DIDT_SQ_CTRL0__DIDT_CTRL_EN_MASK; |
| 659 | WREG32_DIDT(ixDIDT_SQ_CTRL0, data); |
| 660 | } |
| 661 | |
| 662 | if (pi->caps_db_ramping) { |
| 663 | data = RREG32_DIDT(ixDIDT_DB_CTRL0); |
| 664 | if (enable) |
| 665 | data |= DIDT_DB_CTRL0__DIDT_CTRL_EN_MASK; |
| 666 | else |
| 667 | data &= ~DIDT_DB_CTRL0__DIDT_CTRL_EN_MASK; |
| 668 | WREG32_DIDT(ixDIDT_DB_CTRL0, data); |
| 669 | } |
| 670 | |
| 671 | if (pi->caps_td_ramping) { |
| 672 | data = RREG32_DIDT(ixDIDT_TD_CTRL0); |
| 673 | if (enable) |
| 674 | data |= DIDT_TD_CTRL0__DIDT_CTRL_EN_MASK; |
| 675 | else |
| 676 | data &= ~DIDT_TD_CTRL0__DIDT_CTRL_EN_MASK; |
| 677 | WREG32_DIDT(ixDIDT_TD_CTRL0, data); |
| 678 | } |
| 679 | |
| 680 | if (pi->caps_tcp_ramping) { |
| 681 | data = RREG32_DIDT(ixDIDT_TCP_CTRL0); |
| 682 | if (enable) |
| 683 | data |= DIDT_TCP_CTRL0__DIDT_CTRL_EN_MASK; |
| 684 | else |
| 685 | data &= ~DIDT_TCP_CTRL0__DIDT_CTRL_EN_MASK; |
| 686 | WREG32_DIDT(ixDIDT_TCP_CTRL0, data); |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | static int ci_program_pt_config_registers(struct amdgpu_device *adev, |
| 691 | const struct ci_pt_config_reg *cac_config_regs) |
| 692 | { |
| 693 | const struct ci_pt_config_reg *config_regs = cac_config_regs; |
| 694 | u32 data; |
| 695 | u32 cache = 0; |
| 696 | |
| 697 | if (config_regs == NULL) |
| 698 | return -EINVAL; |
| 699 | |
| 700 | while (config_regs->offset != 0xFFFFFFFF) { |
| 701 | if (config_regs->type == CISLANDS_CONFIGREG_CACHE) { |
| 702 | cache |= ((config_regs->value << config_regs->shift) & config_regs->mask); |
| 703 | } else { |
| 704 | switch (config_regs->type) { |
| 705 | case CISLANDS_CONFIGREG_SMC_IND: |
| 706 | data = RREG32_SMC(config_regs->offset); |
| 707 | break; |
| 708 | case CISLANDS_CONFIGREG_DIDT_IND: |
| 709 | data = RREG32_DIDT(config_regs->offset); |
| 710 | break; |
| 711 | default: |
| 712 | data = RREG32(config_regs->offset); |
| 713 | break; |
| 714 | } |
| 715 | |
| 716 | data &= ~config_regs->mask; |
| 717 | data |= ((config_regs->value << config_regs->shift) & config_regs->mask); |
| 718 | data |= cache; |
| 719 | |
| 720 | switch (config_regs->type) { |
| 721 | case CISLANDS_CONFIGREG_SMC_IND: |
| 722 | WREG32_SMC(config_regs->offset, data); |
| 723 | break; |
| 724 | case CISLANDS_CONFIGREG_DIDT_IND: |
| 725 | WREG32_DIDT(config_regs->offset, data); |
| 726 | break; |
| 727 | default: |
| 728 | WREG32(config_regs->offset, data); |
| 729 | break; |
| 730 | } |
| 731 | cache = 0; |
| 732 | } |
| 733 | config_regs++; |
| 734 | } |
| 735 | return 0; |
| 736 | } |
| 737 | |
| 738 | static int ci_enable_didt(struct amdgpu_device *adev, bool enable) |
| 739 | { |
| 740 | struct ci_power_info *pi = ci_get_pi(adev); |
| 741 | int ret; |
| 742 | |
| 743 | if (pi->caps_sq_ramping || pi->caps_db_ramping || |
| 744 | pi->caps_td_ramping || pi->caps_tcp_ramping) { |
Alex Deucher | 06120a1 | 2016-06-21 12:16:30 -0400 | [diff] [blame] | 745 | adev->gfx.rlc.funcs->enter_safe_mode(adev); |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 746 | |
| 747 | if (enable) { |
| 748 | ret = ci_program_pt_config_registers(adev, didt_config_ci); |
| 749 | if (ret) { |
Alex Deucher | 06120a1 | 2016-06-21 12:16:30 -0400 | [diff] [blame] | 750 | adev->gfx.rlc.funcs->exit_safe_mode(adev); |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 751 | return ret; |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | ci_do_enable_didt(adev, enable); |
| 756 | |
Alex Deucher | 06120a1 | 2016-06-21 12:16:30 -0400 | [diff] [blame] | 757 | adev->gfx.rlc.funcs->exit_safe_mode(adev); |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | return 0; |
| 761 | } |
| 762 | |
| 763 | static int ci_enable_power_containment(struct amdgpu_device *adev, bool enable) |
| 764 | { |
| 765 | struct ci_power_info *pi = ci_get_pi(adev); |
| 766 | PPSMC_Result smc_result; |
| 767 | int ret = 0; |
| 768 | |
| 769 | if (enable) { |
| 770 | pi->power_containment_features = 0; |
| 771 | if (pi->caps_power_containment) { |
| 772 | if (pi->enable_bapm_feature) { |
| 773 | smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_EnableDTE); |
| 774 | if (smc_result != PPSMC_Result_OK) |
| 775 | ret = -EINVAL; |
| 776 | else |
| 777 | pi->power_containment_features |= POWERCONTAINMENT_FEATURE_BAPM; |
| 778 | } |
| 779 | |
| 780 | if (pi->enable_tdc_limit_feature) { |
| 781 | smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_TDCLimitEnable); |
| 782 | if (smc_result != PPSMC_Result_OK) |
| 783 | ret = -EINVAL; |
| 784 | else |
| 785 | pi->power_containment_features |= POWERCONTAINMENT_FEATURE_TDCLimit; |
| 786 | } |
| 787 | |
| 788 | if (pi->enable_pkg_pwr_tracking_feature) { |
| 789 | smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_PkgPwrLimitEnable); |
| 790 | if (smc_result != PPSMC_Result_OK) { |
| 791 | ret = -EINVAL; |
| 792 | } else { |
| 793 | struct amdgpu_cac_tdp_table *cac_tdp_table = |
| 794 | adev->pm.dpm.dyn_state.cac_tdp_table; |
| 795 | u32 default_pwr_limit = |
| 796 | (u32)(cac_tdp_table->maximum_power_delivery_limit * 256); |
| 797 | |
| 798 | pi->power_containment_features |= POWERCONTAINMENT_FEATURE_PkgPwrLimit; |
| 799 | |
| 800 | ci_set_power_limit(adev, default_pwr_limit); |
| 801 | } |
| 802 | } |
| 803 | } |
| 804 | } else { |
| 805 | if (pi->caps_power_containment && pi->power_containment_features) { |
| 806 | if (pi->power_containment_features & POWERCONTAINMENT_FEATURE_TDCLimit) |
| 807 | amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_TDCLimitDisable); |
| 808 | |
| 809 | if (pi->power_containment_features & POWERCONTAINMENT_FEATURE_BAPM) |
| 810 | amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_DisableDTE); |
| 811 | |
| 812 | if (pi->power_containment_features & POWERCONTAINMENT_FEATURE_PkgPwrLimit) |
| 813 | amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_PkgPwrLimitDisable); |
| 814 | pi->power_containment_features = 0; |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | return ret; |
| 819 | } |
| 820 | |
| 821 | static int ci_enable_smc_cac(struct amdgpu_device *adev, bool enable) |
| 822 | { |
| 823 | struct ci_power_info *pi = ci_get_pi(adev); |
| 824 | PPSMC_Result smc_result; |
| 825 | int ret = 0; |
| 826 | |
| 827 | if (pi->caps_cac) { |
| 828 | if (enable) { |
| 829 | smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_EnableCac); |
| 830 | if (smc_result != PPSMC_Result_OK) { |
| 831 | ret = -EINVAL; |
| 832 | pi->cac_enabled = false; |
| 833 | } else { |
| 834 | pi->cac_enabled = true; |
| 835 | } |
| 836 | } else if (pi->cac_enabled) { |
| 837 | amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_DisableCac); |
| 838 | pi->cac_enabled = false; |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | return ret; |
| 843 | } |
| 844 | |
| 845 | static int ci_enable_thermal_based_sclk_dpm(struct amdgpu_device *adev, |
| 846 | bool enable) |
| 847 | { |
| 848 | struct ci_power_info *pi = ci_get_pi(adev); |
| 849 | PPSMC_Result smc_result = PPSMC_Result_OK; |
| 850 | |
| 851 | if (pi->thermal_sclk_dpm_enabled) { |
| 852 | if (enable) |
| 853 | smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_ENABLE_THERMAL_DPM); |
| 854 | else |
| 855 | smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_DISABLE_THERMAL_DPM); |
| 856 | } |
| 857 | |
| 858 | if (smc_result == PPSMC_Result_OK) |
| 859 | return 0; |
| 860 | else |
| 861 | return -EINVAL; |
| 862 | } |
| 863 | |
| 864 | static int ci_power_control_set_level(struct amdgpu_device *adev) |
| 865 | { |
| 866 | struct ci_power_info *pi = ci_get_pi(adev); |
| 867 | struct amdgpu_cac_tdp_table *cac_tdp_table = |
| 868 | adev->pm.dpm.dyn_state.cac_tdp_table; |
| 869 | s32 adjust_percent; |
| 870 | s32 target_tdp; |
| 871 | int ret = 0; |
| 872 | bool adjust_polarity = false; /* ??? */ |
| 873 | |
| 874 | if (pi->caps_power_containment) { |
| 875 | adjust_percent = adjust_polarity ? |
| 876 | adev->pm.dpm.tdp_adjustment : (-1 * adev->pm.dpm.tdp_adjustment); |
| 877 | target_tdp = ((100 + adjust_percent) * |
| 878 | (s32)cac_tdp_table->configurable_tdp) / 100; |
| 879 | |
| 880 | ret = ci_set_overdrive_target_tdp(adev, (u32)target_tdp); |
| 881 | } |
| 882 | |
| 883 | return ret; |
| 884 | } |
| 885 | |
| 886 | static void ci_dpm_powergate_uvd(struct amdgpu_device *adev, bool gate) |
| 887 | { |
| 888 | struct ci_power_info *pi = ci_get_pi(adev); |
| 889 | |
| 890 | if (pi->uvd_power_gated == gate) |
| 891 | return; |
| 892 | |
| 893 | pi->uvd_power_gated = gate; |
| 894 | |
| 895 | ci_update_uvd_dpm(adev, gate); |
| 896 | } |
| 897 | |
| 898 | static bool ci_dpm_vblank_too_short(struct amdgpu_device *adev) |
| 899 | { |
| 900 | u32 vblank_time = amdgpu_dpm_get_vblank_time(adev); |
Ken Wang | 81c59f5 | 2015-06-03 21:02:01 +0800 | [diff] [blame] | 901 | u32 switch_limit = adev->mc.vram_type == AMDGPU_VRAM_TYPE_GDDR5 ? 450 : 300; |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 902 | |
Alex Deucher | 34bae9b | 2017-05-11 13:10:02 -0400 | [diff] [blame] | 903 | /* disable mclk switching if the refresh is >120Hz, even if the |
| 904 | * blanking period would allow it |
| 905 | */ |
| 906 | if (amdgpu_dpm_get_vrefresh(adev) > 120) |
| 907 | return true; |
| 908 | |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 909 | if (vblank_time < switch_limit) |
| 910 | return true; |
| 911 | else |
| 912 | return false; |
| 913 | |
| 914 | } |
| 915 | |
| 916 | static void ci_apply_state_adjust_rules(struct amdgpu_device *adev, |
| 917 | struct amdgpu_ps *rps) |
| 918 | { |
| 919 | struct ci_ps *ps = ci_get_ps(rps); |
| 920 | struct ci_power_info *pi = ci_get_pi(adev); |
| 921 | struct amdgpu_clock_and_voltage_limits *max_limits; |
| 922 | bool disable_mclk_switching; |
| 923 | u32 sclk, mclk; |
| 924 | int i; |
| 925 | |
| 926 | if (rps->vce_active) { |
| 927 | rps->evclk = adev->pm.dpm.vce_states[adev->pm.dpm.vce_level].evclk; |
| 928 | rps->ecclk = adev->pm.dpm.vce_states[adev->pm.dpm.vce_level].ecclk; |
| 929 | } else { |
| 930 | rps->evclk = 0; |
| 931 | rps->ecclk = 0; |
| 932 | } |
| 933 | |
| 934 | if ((adev->pm.dpm.new_active_crtc_count > 1) || |
| 935 | ci_dpm_vblank_too_short(adev)) |
| 936 | disable_mclk_switching = true; |
| 937 | else |
| 938 | disable_mclk_switching = false; |
| 939 | |
| 940 | if ((rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) == ATOM_PPLIB_CLASSIFICATION_UI_BATTERY) |
| 941 | pi->battery_state = true; |
| 942 | else |
| 943 | pi->battery_state = false; |
| 944 | |
| 945 | if (adev->pm.dpm.ac_power) |
| 946 | max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_ac; |
| 947 | else |
| 948 | max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_dc; |
| 949 | |
| 950 | if (adev->pm.dpm.ac_power == false) { |
| 951 | for (i = 0; i < ps->performance_level_count; i++) { |
| 952 | if (ps->performance_levels[i].mclk > max_limits->mclk) |
| 953 | ps->performance_levels[i].mclk = max_limits->mclk; |
| 954 | if (ps->performance_levels[i].sclk > max_limits->sclk) |
| 955 | ps->performance_levels[i].sclk = max_limits->sclk; |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | /* XXX validate the min clocks required for display */ |
| 960 | |
| 961 | if (disable_mclk_switching) { |
| 962 | mclk = ps->performance_levels[ps->performance_level_count - 1].mclk; |
| 963 | sclk = ps->performance_levels[0].sclk; |
| 964 | } else { |
| 965 | mclk = ps->performance_levels[0].mclk; |
| 966 | sclk = ps->performance_levels[0].sclk; |
| 967 | } |
| 968 | |
| 969 | if (rps->vce_active) { |
| 970 | if (sclk < adev->pm.dpm.vce_states[adev->pm.dpm.vce_level].sclk) |
| 971 | sclk = adev->pm.dpm.vce_states[adev->pm.dpm.vce_level].sclk; |
| 972 | if (mclk < adev->pm.dpm.vce_states[adev->pm.dpm.vce_level].mclk) |
| 973 | mclk = adev->pm.dpm.vce_states[adev->pm.dpm.vce_level].mclk; |
| 974 | } |
| 975 | |
| 976 | ps->performance_levels[0].sclk = sclk; |
| 977 | ps->performance_levels[0].mclk = mclk; |
| 978 | |
| 979 | if (ps->performance_levels[1].sclk < ps->performance_levels[0].sclk) |
| 980 | ps->performance_levels[1].sclk = ps->performance_levels[0].sclk; |
| 981 | |
| 982 | if (disable_mclk_switching) { |
| 983 | if (ps->performance_levels[0].mclk < ps->performance_levels[1].mclk) |
| 984 | ps->performance_levels[0].mclk = ps->performance_levels[1].mclk; |
| 985 | } else { |
| 986 | if (ps->performance_levels[1].mclk < ps->performance_levels[0].mclk) |
| 987 | ps->performance_levels[1].mclk = ps->performance_levels[0].mclk; |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | static int ci_thermal_set_temperature_range(struct amdgpu_device *adev, |
| 992 | int min_temp, int max_temp) |
| 993 | { |
| 994 | int low_temp = 0 * 1000; |
| 995 | int high_temp = 255 * 1000; |
| 996 | u32 tmp; |
| 997 | |
| 998 | if (low_temp < min_temp) |
| 999 | low_temp = min_temp; |
| 1000 | if (high_temp > max_temp) |
| 1001 | high_temp = max_temp; |
| 1002 | if (high_temp < low_temp) { |
| 1003 | DRM_ERROR("invalid thermal range: %d - %d\n", low_temp, high_temp); |
| 1004 | return -EINVAL; |
| 1005 | } |
| 1006 | |
| 1007 | tmp = RREG32_SMC(ixCG_THERMAL_INT); |
| 1008 | tmp &= ~(CG_THERMAL_INT__DIG_THERM_INTH_MASK | CG_THERMAL_INT__DIG_THERM_INTL_MASK); |
| 1009 | tmp |= ((high_temp / 1000) << CG_THERMAL_INT__DIG_THERM_INTH__SHIFT) | |
| 1010 | ((low_temp / 1000)) << CG_THERMAL_INT__DIG_THERM_INTL__SHIFT; |
| 1011 | WREG32_SMC(ixCG_THERMAL_INT, tmp); |
| 1012 | |
| 1013 | #if 0 |
| 1014 | /* XXX: need to figure out how to handle this properly */ |
| 1015 | tmp = RREG32_SMC(ixCG_THERMAL_CTRL); |
| 1016 | tmp &= DIG_THERM_DPM_MASK; |
| 1017 | tmp |= DIG_THERM_DPM(high_temp / 1000); |
| 1018 | WREG32_SMC(ixCG_THERMAL_CTRL, tmp); |
| 1019 | #endif |
| 1020 | |
| 1021 | adev->pm.dpm.thermal.min_temp = low_temp; |
| 1022 | adev->pm.dpm.thermal.max_temp = high_temp; |
| 1023 | return 0; |
| 1024 | } |
| 1025 | |
| 1026 | static int ci_thermal_enable_alert(struct amdgpu_device *adev, |
| 1027 | bool enable) |
| 1028 | { |
| 1029 | u32 thermal_int = RREG32_SMC(ixCG_THERMAL_INT); |
| 1030 | PPSMC_Result result; |
| 1031 | |
| 1032 | if (enable) { |
| 1033 | thermal_int &= ~(CG_THERMAL_INT_CTRL__THERM_INTH_MASK_MASK | |
| 1034 | CG_THERMAL_INT_CTRL__THERM_INTL_MASK_MASK); |
| 1035 | WREG32_SMC(ixCG_THERMAL_INT, thermal_int); |
| 1036 | result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_Thermal_Cntl_Enable); |
| 1037 | if (result != PPSMC_Result_OK) { |
| 1038 | DRM_DEBUG_KMS("Could not enable thermal interrupts.\n"); |
| 1039 | return -EINVAL; |
| 1040 | } |
| 1041 | } else { |
| 1042 | thermal_int |= CG_THERMAL_INT_CTRL__THERM_INTH_MASK_MASK | |
| 1043 | CG_THERMAL_INT_CTRL__THERM_INTL_MASK_MASK; |
| 1044 | WREG32_SMC(ixCG_THERMAL_INT, thermal_int); |
| 1045 | result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_Thermal_Cntl_Disable); |
| 1046 | if (result != PPSMC_Result_OK) { |
| 1047 | DRM_DEBUG_KMS("Could not disable thermal interrupts.\n"); |
| 1048 | return -EINVAL; |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | return 0; |
| 1053 | } |
| 1054 | |
| 1055 | static void ci_fan_ctrl_set_static_mode(struct amdgpu_device *adev, u32 mode) |
| 1056 | { |
| 1057 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1058 | u32 tmp; |
| 1059 | |
| 1060 | if (pi->fan_ctrl_is_in_default_mode) { |
| 1061 | tmp = (RREG32_SMC(ixCG_FDO_CTRL2) & CG_FDO_CTRL2__FDO_PWM_MODE_MASK) |
| 1062 | >> CG_FDO_CTRL2__FDO_PWM_MODE__SHIFT; |
| 1063 | pi->fan_ctrl_default_mode = tmp; |
| 1064 | tmp = (RREG32_SMC(ixCG_FDO_CTRL2) & CG_FDO_CTRL2__TMIN_MASK) |
| 1065 | >> CG_FDO_CTRL2__TMIN__SHIFT; |
| 1066 | pi->t_min = tmp; |
| 1067 | pi->fan_ctrl_is_in_default_mode = false; |
| 1068 | } |
| 1069 | |
| 1070 | tmp = RREG32_SMC(ixCG_FDO_CTRL2) & ~CG_FDO_CTRL2__TMIN_MASK; |
| 1071 | tmp |= 0 << CG_FDO_CTRL2__TMIN__SHIFT; |
| 1072 | WREG32_SMC(ixCG_FDO_CTRL2, tmp); |
| 1073 | |
| 1074 | tmp = RREG32_SMC(ixCG_FDO_CTRL2) & ~CG_FDO_CTRL2__FDO_PWM_MODE_MASK; |
| 1075 | tmp |= mode << CG_FDO_CTRL2__FDO_PWM_MODE__SHIFT; |
| 1076 | WREG32_SMC(ixCG_FDO_CTRL2, tmp); |
| 1077 | } |
| 1078 | |
| 1079 | static int ci_thermal_setup_fan_table(struct amdgpu_device *adev) |
| 1080 | { |
| 1081 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1082 | SMU7_Discrete_FanTable fan_table = { FDO_MODE_HARDWARE }; |
| 1083 | u32 duty100; |
| 1084 | u32 t_diff1, t_diff2, pwm_diff1, pwm_diff2; |
| 1085 | u16 fdo_min, slope1, slope2; |
| 1086 | u32 reference_clock, tmp; |
| 1087 | int ret; |
| 1088 | u64 tmp64; |
| 1089 | |
| 1090 | if (!pi->fan_table_start) { |
| 1091 | adev->pm.dpm.fan.ucode_fan_control = false; |
| 1092 | return 0; |
| 1093 | } |
| 1094 | |
| 1095 | duty100 = (RREG32_SMC(ixCG_FDO_CTRL1) & CG_FDO_CTRL1__FMAX_DUTY100_MASK) |
| 1096 | >> CG_FDO_CTRL1__FMAX_DUTY100__SHIFT; |
| 1097 | |
| 1098 | if (duty100 == 0) { |
| 1099 | adev->pm.dpm.fan.ucode_fan_control = false; |
| 1100 | return 0; |
| 1101 | } |
| 1102 | |
| 1103 | tmp64 = (u64)adev->pm.dpm.fan.pwm_min * duty100; |
| 1104 | do_div(tmp64, 10000); |
| 1105 | fdo_min = (u16)tmp64; |
| 1106 | |
| 1107 | t_diff1 = adev->pm.dpm.fan.t_med - adev->pm.dpm.fan.t_min; |
| 1108 | t_diff2 = adev->pm.dpm.fan.t_high - adev->pm.dpm.fan.t_med; |
| 1109 | |
| 1110 | pwm_diff1 = adev->pm.dpm.fan.pwm_med - adev->pm.dpm.fan.pwm_min; |
| 1111 | pwm_diff2 = adev->pm.dpm.fan.pwm_high - adev->pm.dpm.fan.pwm_med; |
| 1112 | |
| 1113 | slope1 = (u16)((50 + ((16 * duty100 * pwm_diff1) / t_diff1)) / 100); |
| 1114 | slope2 = (u16)((50 + ((16 * duty100 * pwm_diff2) / t_diff2)) / 100); |
| 1115 | |
| 1116 | fan_table.TempMin = cpu_to_be16((50 + adev->pm.dpm.fan.t_min) / 100); |
| 1117 | fan_table.TempMed = cpu_to_be16((50 + adev->pm.dpm.fan.t_med) / 100); |
| 1118 | fan_table.TempMax = cpu_to_be16((50 + adev->pm.dpm.fan.t_max) / 100); |
| 1119 | |
| 1120 | fan_table.Slope1 = cpu_to_be16(slope1); |
| 1121 | fan_table.Slope2 = cpu_to_be16(slope2); |
| 1122 | |
| 1123 | fan_table.FdoMin = cpu_to_be16(fdo_min); |
| 1124 | |
| 1125 | fan_table.HystDown = cpu_to_be16(adev->pm.dpm.fan.t_hyst); |
| 1126 | |
| 1127 | fan_table.HystUp = cpu_to_be16(1); |
| 1128 | |
| 1129 | fan_table.HystSlope = cpu_to_be16(1); |
| 1130 | |
| 1131 | fan_table.TempRespLim = cpu_to_be16(5); |
| 1132 | |
| 1133 | reference_clock = amdgpu_asic_get_xclk(adev); |
| 1134 | |
| 1135 | fan_table.RefreshPeriod = cpu_to_be32((adev->pm.dpm.fan.cycle_delay * |
| 1136 | reference_clock) / 1600); |
| 1137 | |
| 1138 | fan_table.FdoMax = cpu_to_be16((u16)duty100); |
| 1139 | |
| 1140 | tmp = (RREG32_SMC(ixCG_MULT_THERMAL_CTRL) & CG_MULT_THERMAL_CTRL__TEMP_SEL_MASK) |
| 1141 | >> CG_MULT_THERMAL_CTRL__TEMP_SEL__SHIFT; |
| 1142 | fan_table.TempSrc = (uint8_t)tmp; |
| 1143 | |
| 1144 | ret = amdgpu_ci_copy_bytes_to_smc(adev, |
| 1145 | pi->fan_table_start, |
| 1146 | (u8 *)(&fan_table), |
| 1147 | sizeof(fan_table), |
| 1148 | pi->sram_end); |
| 1149 | |
| 1150 | if (ret) { |
| 1151 | DRM_ERROR("Failed to load fan table to the SMC."); |
| 1152 | adev->pm.dpm.fan.ucode_fan_control = false; |
| 1153 | } |
| 1154 | |
| 1155 | return 0; |
| 1156 | } |
| 1157 | |
| 1158 | static int ci_fan_ctrl_start_smc_fan_control(struct amdgpu_device *adev) |
| 1159 | { |
| 1160 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1161 | PPSMC_Result ret; |
| 1162 | |
| 1163 | if (pi->caps_od_fuzzy_fan_control_support) { |
| 1164 | ret = amdgpu_ci_send_msg_to_smc_with_parameter(adev, |
| 1165 | PPSMC_StartFanControl, |
| 1166 | FAN_CONTROL_FUZZY); |
| 1167 | if (ret != PPSMC_Result_OK) |
| 1168 | return -EINVAL; |
| 1169 | ret = amdgpu_ci_send_msg_to_smc_with_parameter(adev, |
| 1170 | PPSMC_MSG_SetFanPwmMax, |
| 1171 | adev->pm.dpm.fan.default_max_fan_pwm); |
| 1172 | if (ret != PPSMC_Result_OK) |
| 1173 | return -EINVAL; |
| 1174 | } else { |
| 1175 | ret = amdgpu_ci_send_msg_to_smc_with_parameter(adev, |
| 1176 | PPSMC_StartFanControl, |
| 1177 | FAN_CONTROL_TABLE); |
| 1178 | if (ret != PPSMC_Result_OK) |
| 1179 | return -EINVAL; |
| 1180 | } |
| 1181 | |
| 1182 | pi->fan_is_controlled_by_smc = true; |
| 1183 | return 0; |
| 1184 | } |
| 1185 | |
| 1186 | |
| 1187 | static int ci_fan_ctrl_stop_smc_fan_control(struct amdgpu_device *adev) |
| 1188 | { |
| 1189 | PPSMC_Result ret; |
| 1190 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1191 | |
| 1192 | ret = amdgpu_ci_send_msg_to_smc(adev, PPSMC_StopFanControl); |
| 1193 | if (ret == PPSMC_Result_OK) { |
| 1194 | pi->fan_is_controlled_by_smc = false; |
| 1195 | return 0; |
| 1196 | } else { |
| 1197 | return -EINVAL; |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | static int ci_dpm_get_fan_speed_percent(struct amdgpu_device *adev, |
| 1202 | u32 *speed) |
| 1203 | { |
| 1204 | u32 duty, duty100; |
| 1205 | u64 tmp64; |
| 1206 | |
| 1207 | if (adev->pm.no_fan) |
| 1208 | return -ENOENT; |
| 1209 | |
| 1210 | duty100 = (RREG32_SMC(ixCG_FDO_CTRL1) & CG_FDO_CTRL1__FMAX_DUTY100_MASK) |
| 1211 | >> CG_FDO_CTRL1__FMAX_DUTY100__SHIFT; |
| 1212 | duty = (RREG32_SMC(ixCG_THERMAL_STATUS) & CG_THERMAL_STATUS__FDO_PWM_DUTY_MASK) |
| 1213 | >> CG_THERMAL_STATUS__FDO_PWM_DUTY__SHIFT; |
| 1214 | |
| 1215 | if (duty100 == 0) |
| 1216 | return -EINVAL; |
| 1217 | |
| 1218 | tmp64 = (u64)duty * 100; |
| 1219 | do_div(tmp64, duty100); |
| 1220 | *speed = (u32)tmp64; |
| 1221 | |
| 1222 | if (*speed > 100) |
| 1223 | *speed = 100; |
| 1224 | |
| 1225 | return 0; |
| 1226 | } |
| 1227 | |
| 1228 | static int ci_dpm_set_fan_speed_percent(struct amdgpu_device *adev, |
| 1229 | u32 speed) |
| 1230 | { |
| 1231 | u32 tmp; |
| 1232 | u32 duty, duty100; |
| 1233 | u64 tmp64; |
| 1234 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1235 | |
| 1236 | if (adev->pm.no_fan) |
| 1237 | return -ENOENT; |
| 1238 | |
| 1239 | if (pi->fan_is_controlled_by_smc) |
| 1240 | return -EINVAL; |
| 1241 | |
| 1242 | if (speed > 100) |
| 1243 | return -EINVAL; |
| 1244 | |
| 1245 | duty100 = (RREG32_SMC(ixCG_FDO_CTRL1) & CG_FDO_CTRL1__FMAX_DUTY100_MASK) |
| 1246 | >> CG_FDO_CTRL1__FMAX_DUTY100__SHIFT; |
| 1247 | |
| 1248 | if (duty100 == 0) |
| 1249 | return -EINVAL; |
| 1250 | |
| 1251 | tmp64 = (u64)speed * duty100; |
| 1252 | do_div(tmp64, 100); |
| 1253 | duty = (u32)tmp64; |
| 1254 | |
| 1255 | tmp = RREG32_SMC(ixCG_FDO_CTRL0) & ~CG_FDO_CTRL0__FDO_STATIC_DUTY_MASK; |
| 1256 | tmp |= duty << CG_FDO_CTRL0__FDO_STATIC_DUTY__SHIFT; |
| 1257 | WREG32_SMC(ixCG_FDO_CTRL0, tmp); |
| 1258 | |
| 1259 | return 0; |
| 1260 | } |
| 1261 | |
| 1262 | static void ci_dpm_set_fan_control_mode(struct amdgpu_device *adev, u32 mode) |
| 1263 | { |
| 1264 | if (mode) { |
| 1265 | /* stop auto-manage */ |
| 1266 | if (adev->pm.dpm.fan.ucode_fan_control) |
| 1267 | ci_fan_ctrl_stop_smc_fan_control(adev); |
| 1268 | ci_fan_ctrl_set_static_mode(adev, mode); |
| 1269 | } else { |
| 1270 | /* restart auto-manage */ |
| 1271 | if (adev->pm.dpm.fan.ucode_fan_control) |
| 1272 | ci_thermal_start_smc_fan_control(adev); |
| 1273 | else |
| 1274 | ci_fan_ctrl_set_default_mode(adev); |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | static u32 ci_dpm_get_fan_control_mode(struct amdgpu_device *adev) |
| 1279 | { |
| 1280 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1281 | u32 tmp; |
| 1282 | |
| 1283 | if (pi->fan_is_controlled_by_smc) |
| 1284 | return 0; |
| 1285 | |
| 1286 | tmp = RREG32_SMC(ixCG_FDO_CTRL2) & CG_FDO_CTRL2__FDO_PWM_MODE_MASK; |
| 1287 | return (tmp >> CG_FDO_CTRL2__FDO_PWM_MODE__SHIFT); |
| 1288 | } |
| 1289 | |
| 1290 | #if 0 |
| 1291 | static int ci_fan_ctrl_get_fan_speed_rpm(struct amdgpu_device *adev, |
| 1292 | u32 *speed) |
| 1293 | { |
| 1294 | u32 tach_period; |
| 1295 | u32 xclk = amdgpu_asic_get_xclk(adev); |
| 1296 | |
| 1297 | if (adev->pm.no_fan) |
| 1298 | return -ENOENT; |
| 1299 | |
| 1300 | if (adev->pm.fan_pulses_per_revolution == 0) |
| 1301 | return -ENOENT; |
| 1302 | |
| 1303 | tach_period = (RREG32_SMC(ixCG_TACH_STATUS) & CG_TACH_STATUS__TACH_PERIOD_MASK) |
| 1304 | >> CG_TACH_STATUS__TACH_PERIOD__SHIFT; |
| 1305 | if (tach_period == 0) |
| 1306 | return -ENOENT; |
| 1307 | |
| 1308 | *speed = 60 * xclk * 10000 / tach_period; |
| 1309 | |
| 1310 | return 0; |
| 1311 | } |
| 1312 | |
| 1313 | static int ci_fan_ctrl_set_fan_speed_rpm(struct amdgpu_device *adev, |
| 1314 | u32 speed) |
| 1315 | { |
| 1316 | u32 tach_period, tmp; |
| 1317 | u32 xclk = amdgpu_asic_get_xclk(adev); |
| 1318 | |
| 1319 | if (adev->pm.no_fan) |
| 1320 | return -ENOENT; |
| 1321 | |
| 1322 | if (adev->pm.fan_pulses_per_revolution == 0) |
| 1323 | return -ENOENT; |
| 1324 | |
| 1325 | if ((speed < adev->pm.fan_min_rpm) || |
| 1326 | (speed > adev->pm.fan_max_rpm)) |
| 1327 | return -EINVAL; |
| 1328 | |
| 1329 | if (adev->pm.dpm.fan.ucode_fan_control) |
| 1330 | ci_fan_ctrl_stop_smc_fan_control(adev); |
| 1331 | |
| 1332 | tach_period = 60 * xclk * 10000 / (8 * speed); |
| 1333 | tmp = RREG32_SMC(ixCG_TACH_CTRL) & ~CG_TACH_CTRL__TARGET_PERIOD_MASK; |
| 1334 | tmp |= tach_period << CG_TACH_CTRL__TARGET_PERIOD__SHIFT; |
| 1335 | WREG32_SMC(CG_TACH_CTRL, tmp); |
| 1336 | |
| 1337 | ci_fan_ctrl_set_static_mode(adev, FDO_PWM_MODE_STATIC_RPM); |
| 1338 | |
| 1339 | return 0; |
| 1340 | } |
| 1341 | #endif |
| 1342 | |
| 1343 | static void ci_fan_ctrl_set_default_mode(struct amdgpu_device *adev) |
| 1344 | { |
| 1345 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1346 | u32 tmp; |
| 1347 | |
| 1348 | if (!pi->fan_ctrl_is_in_default_mode) { |
| 1349 | tmp = RREG32_SMC(ixCG_FDO_CTRL2) & ~CG_FDO_CTRL2__FDO_PWM_MODE_MASK; |
| 1350 | tmp |= pi->fan_ctrl_default_mode << CG_FDO_CTRL2__FDO_PWM_MODE__SHIFT; |
| 1351 | WREG32_SMC(ixCG_FDO_CTRL2, tmp); |
| 1352 | |
| 1353 | tmp = RREG32_SMC(ixCG_FDO_CTRL2) & ~CG_FDO_CTRL2__TMIN_MASK; |
| 1354 | tmp |= pi->t_min << CG_FDO_CTRL2__TMIN__SHIFT; |
| 1355 | WREG32_SMC(ixCG_FDO_CTRL2, tmp); |
| 1356 | pi->fan_ctrl_is_in_default_mode = true; |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | static void ci_thermal_start_smc_fan_control(struct amdgpu_device *adev) |
| 1361 | { |
| 1362 | if (adev->pm.dpm.fan.ucode_fan_control) { |
| 1363 | ci_fan_ctrl_start_smc_fan_control(adev); |
| 1364 | ci_fan_ctrl_set_static_mode(adev, FDO_PWM_MODE_STATIC); |
| 1365 | } |
| 1366 | } |
| 1367 | |
| 1368 | static void ci_thermal_initialize(struct amdgpu_device *adev) |
| 1369 | { |
| 1370 | u32 tmp; |
| 1371 | |
| 1372 | if (adev->pm.fan_pulses_per_revolution) { |
| 1373 | tmp = RREG32_SMC(ixCG_TACH_CTRL) & ~CG_TACH_CTRL__EDGE_PER_REV_MASK; |
| 1374 | tmp |= (adev->pm.fan_pulses_per_revolution - 1) |
| 1375 | << CG_TACH_CTRL__EDGE_PER_REV__SHIFT; |
| 1376 | WREG32_SMC(ixCG_TACH_CTRL, tmp); |
| 1377 | } |
| 1378 | |
| 1379 | tmp = RREG32_SMC(ixCG_FDO_CTRL2) & ~CG_FDO_CTRL2__TACH_PWM_RESP_RATE_MASK; |
| 1380 | tmp |= 0x28 << CG_FDO_CTRL2__TACH_PWM_RESP_RATE__SHIFT; |
| 1381 | WREG32_SMC(ixCG_FDO_CTRL2, tmp); |
| 1382 | } |
| 1383 | |
| 1384 | static int ci_thermal_start_thermal_controller(struct amdgpu_device *adev) |
| 1385 | { |
| 1386 | int ret; |
| 1387 | |
| 1388 | ci_thermal_initialize(adev); |
| 1389 | ret = ci_thermal_set_temperature_range(adev, CISLANDS_TEMP_RANGE_MIN, CISLANDS_TEMP_RANGE_MAX); |
| 1390 | if (ret) |
| 1391 | return ret; |
| 1392 | ret = ci_thermal_enable_alert(adev, true); |
| 1393 | if (ret) |
| 1394 | return ret; |
| 1395 | if (adev->pm.dpm.fan.ucode_fan_control) { |
| 1396 | ret = ci_thermal_setup_fan_table(adev); |
| 1397 | if (ret) |
| 1398 | return ret; |
| 1399 | ci_thermal_start_smc_fan_control(adev); |
| 1400 | } |
| 1401 | |
| 1402 | return 0; |
| 1403 | } |
| 1404 | |
| 1405 | static void ci_thermal_stop_thermal_controller(struct amdgpu_device *adev) |
| 1406 | { |
| 1407 | if (!adev->pm.no_fan) |
| 1408 | ci_fan_ctrl_set_default_mode(adev); |
| 1409 | } |
| 1410 | |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 1411 | static int ci_read_smc_soft_register(struct amdgpu_device *adev, |
| 1412 | u16 reg_offset, u32 *value) |
| 1413 | { |
| 1414 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1415 | |
| 1416 | return amdgpu_ci_read_smc_sram_dword(adev, |
| 1417 | pi->soft_regs_start + reg_offset, |
| 1418 | value, pi->sram_end); |
| 1419 | } |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 1420 | |
| 1421 | static int ci_write_smc_soft_register(struct amdgpu_device *adev, |
| 1422 | u16 reg_offset, u32 value) |
| 1423 | { |
| 1424 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1425 | |
| 1426 | return amdgpu_ci_write_smc_sram_dword(adev, |
| 1427 | pi->soft_regs_start + reg_offset, |
| 1428 | value, pi->sram_end); |
| 1429 | } |
| 1430 | |
| 1431 | static void ci_init_fps_limits(struct amdgpu_device *adev) |
| 1432 | { |
| 1433 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1434 | SMU7_Discrete_DpmTable *table = &pi->smc_state_table; |
| 1435 | |
| 1436 | if (pi->caps_fps) { |
| 1437 | u16 tmp; |
| 1438 | |
| 1439 | tmp = 45; |
| 1440 | table->FpsHighT = cpu_to_be16(tmp); |
| 1441 | |
| 1442 | tmp = 30; |
| 1443 | table->FpsLowT = cpu_to_be16(tmp); |
| 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | static int ci_update_sclk_t(struct amdgpu_device *adev) |
| 1448 | { |
| 1449 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1450 | int ret = 0; |
| 1451 | u32 low_sclk_interrupt_t = 0; |
| 1452 | |
| 1453 | if (pi->caps_sclk_throttle_low_notification) { |
| 1454 | low_sclk_interrupt_t = cpu_to_be32(pi->low_sclk_interrupt_t); |
| 1455 | |
| 1456 | ret = amdgpu_ci_copy_bytes_to_smc(adev, |
| 1457 | pi->dpm_table_start + |
| 1458 | offsetof(SMU7_Discrete_DpmTable, LowSclkInterruptT), |
| 1459 | (u8 *)&low_sclk_interrupt_t, |
| 1460 | sizeof(u32), pi->sram_end); |
| 1461 | |
| 1462 | } |
| 1463 | |
| 1464 | return ret; |
| 1465 | } |
| 1466 | |
| 1467 | static void ci_get_leakage_voltages(struct amdgpu_device *adev) |
| 1468 | { |
| 1469 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1470 | u16 leakage_id, virtual_voltage_id; |
| 1471 | u16 vddc, vddci; |
| 1472 | int i; |
| 1473 | |
| 1474 | pi->vddc_leakage.count = 0; |
| 1475 | pi->vddci_leakage.count = 0; |
| 1476 | |
| 1477 | if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_EVV) { |
| 1478 | for (i = 0; i < CISLANDS_MAX_LEAKAGE_COUNT; i++) { |
| 1479 | virtual_voltage_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i; |
| 1480 | if (amdgpu_atombios_get_voltage_evv(adev, virtual_voltage_id, &vddc) != 0) |
| 1481 | continue; |
| 1482 | if (vddc != 0 && vddc != virtual_voltage_id) { |
| 1483 | pi->vddc_leakage.actual_voltage[pi->vddc_leakage.count] = vddc; |
| 1484 | pi->vddc_leakage.leakage_id[pi->vddc_leakage.count] = virtual_voltage_id; |
| 1485 | pi->vddc_leakage.count++; |
| 1486 | } |
| 1487 | } |
| 1488 | } else if (amdgpu_atombios_get_leakage_id_from_vbios(adev, &leakage_id) == 0) { |
| 1489 | for (i = 0; i < CISLANDS_MAX_LEAKAGE_COUNT; i++) { |
| 1490 | virtual_voltage_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i; |
| 1491 | if (amdgpu_atombios_get_leakage_vddc_based_on_leakage_params(adev, &vddc, &vddci, |
| 1492 | virtual_voltage_id, |
| 1493 | leakage_id) == 0) { |
| 1494 | if (vddc != 0 && vddc != virtual_voltage_id) { |
| 1495 | pi->vddc_leakage.actual_voltage[pi->vddc_leakage.count] = vddc; |
| 1496 | pi->vddc_leakage.leakage_id[pi->vddc_leakage.count] = virtual_voltage_id; |
| 1497 | pi->vddc_leakage.count++; |
| 1498 | } |
| 1499 | if (vddci != 0 && vddci != virtual_voltage_id) { |
| 1500 | pi->vddci_leakage.actual_voltage[pi->vddci_leakage.count] = vddci; |
| 1501 | pi->vddci_leakage.leakage_id[pi->vddci_leakage.count] = virtual_voltage_id; |
| 1502 | pi->vddci_leakage.count++; |
| 1503 | } |
| 1504 | } |
| 1505 | } |
| 1506 | } |
| 1507 | } |
| 1508 | |
| 1509 | static void ci_set_dpm_event_sources(struct amdgpu_device *adev, u32 sources) |
| 1510 | { |
| 1511 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1512 | bool want_thermal_protection; |
| 1513 | enum amdgpu_dpm_event_src dpm_event_src; |
| 1514 | u32 tmp; |
| 1515 | |
| 1516 | switch (sources) { |
| 1517 | case 0: |
| 1518 | default: |
| 1519 | want_thermal_protection = false; |
| 1520 | break; |
| 1521 | case (1 << AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL): |
| 1522 | want_thermal_protection = true; |
| 1523 | dpm_event_src = AMDGPU_DPM_EVENT_SRC_DIGITAL; |
| 1524 | break; |
| 1525 | case (1 << AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL): |
| 1526 | want_thermal_protection = true; |
| 1527 | dpm_event_src = AMDGPU_DPM_EVENT_SRC_EXTERNAL; |
| 1528 | break; |
| 1529 | case ((1 << AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL) | |
| 1530 | (1 << AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL)): |
| 1531 | want_thermal_protection = true; |
| 1532 | dpm_event_src = AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL; |
| 1533 | break; |
| 1534 | } |
| 1535 | |
| 1536 | if (want_thermal_protection) { |
| 1537 | #if 0 |
| 1538 | /* XXX: need to figure out how to handle this properly */ |
| 1539 | tmp = RREG32_SMC(ixCG_THERMAL_CTRL); |
| 1540 | tmp &= DPM_EVENT_SRC_MASK; |
| 1541 | tmp |= DPM_EVENT_SRC(dpm_event_src); |
| 1542 | WREG32_SMC(ixCG_THERMAL_CTRL, tmp); |
| 1543 | #endif |
| 1544 | |
| 1545 | tmp = RREG32_SMC(ixGENERAL_PWRMGT); |
| 1546 | if (pi->thermal_protection) |
| 1547 | tmp &= ~GENERAL_PWRMGT__THERMAL_PROTECTION_DIS_MASK; |
| 1548 | else |
| 1549 | tmp |= GENERAL_PWRMGT__THERMAL_PROTECTION_DIS_MASK; |
| 1550 | WREG32_SMC(ixGENERAL_PWRMGT, tmp); |
| 1551 | } else { |
| 1552 | tmp = RREG32_SMC(ixGENERAL_PWRMGT); |
| 1553 | tmp |= GENERAL_PWRMGT__THERMAL_PROTECTION_DIS_MASK; |
| 1554 | WREG32_SMC(ixGENERAL_PWRMGT, tmp); |
| 1555 | } |
| 1556 | } |
| 1557 | |
| 1558 | static void ci_enable_auto_throttle_source(struct amdgpu_device *adev, |
| 1559 | enum amdgpu_dpm_auto_throttle_src source, |
| 1560 | bool enable) |
| 1561 | { |
| 1562 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1563 | |
| 1564 | if (enable) { |
| 1565 | if (!(pi->active_auto_throttle_sources & (1 << source))) { |
| 1566 | pi->active_auto_throttle_sources |= 1 << source; |
| 1567 | ci_set_dpm_event_sources(adev, pi->active_auto_throttle_sources); |
| 1568 | } |
| 1569 | } else { |
| 1570 | if (pi->active_auto_throttle_sources & (1 << source)) { |
| 1571 | pi->active_auto_throttle_sources &= ~(1 << source); |
| 1572 | ci_set_dpm_event_sources(adev, pi->active_auto_throttle_sources); |
| 1573 | } |
| 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | static void ci_enable_vr_hot_gpio_interrupt(struct amdgpu_device *adev) |
| 1578 | { |
| 1579 | if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_REGULATOR_HOT) |
| 1580 | amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_EnableVRHotGPIOInterrupt); |
| 1581 | } |
| 1582 | |
| 1583 | static int ci_unfreeze_sclk_mclk_dpm(struct amdgpu_device *adev) |
| 1584 | { |
| 1585 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1586 | PPSMC_Result smc_result; |
| 1587 | |
| 1588 | if (!pi->need_update_smu7_dpm_table) |
| 1589 | return 0; |
| 1590 | |
| 1591 | if ((!pi->sclk_dpm_key_disabled) && |
| 1592 | (pi->need_update_smu7_dpm_table & (DPMTABLE_OD_UPDATE_SCLK | DPMTABLE_UPDATE_SCLK))) { |
| 1593 | smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_SCLKDPM_UnfreezeLevel); |
| 1594 | if (smc_result != PPSMC_Result_OK) |
| 1595 | return -EINVAL; |
| 1596 | } |
| 1597 | |
| 1598 | if ((!pi->mclk_dpm_key_disabled) && |
| 1599 | (pi->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) { |
| 1600 | smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_MCLKDPM_UnfreezeLevel); |
| 1601 | if (smc_result != PPSMC_Result_OK) |
| 1602 | return -EINVAL; |
| 1603 | } |
| 1604 | |
| 1605 | pi->need_update_smu7_dpm_table = 0; |
| 1606 | return 0; |
| 1607 | } |
| 1608 | |
| 1609 | static int ci_enable_sclk_mclk_dpm(struct amdgpu_device *adev, bool enable) |
| 1610 | { |
| 1611 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1612 | PPSMC_Result smc_result; |
| 1613 | |
| 1614 | if (enable) { |
| 1615 | if (!pi->sclk_dpm_key_disabled) { |
| 1616 | smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_DPM_Enable); |
| 1617 | if (smc_result != PPSMC_Result_OK) |
| 1618 | return -EINVAL; |
| 1619 | } |
| 1620 | |
| 1621 | if (!pi->mclk_dpm_key_disabled) { |
| 1622 | smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_MCLKDPM_Enable); |
| 1623 | if (smc_result != PPSMC_Result_OK) |
| 1624 | return -EINVAL; |
| 1625 | |
| 1626 | WREG32_P(mmMC_SEQ_CNTL_3, MC_SEQ_CNTL_3__CAC_EN_MASK, |
| 1627 | ~MC_SEQ_CNTL_3__CAC_EN_MASK); |
| 1628 | |
| 1629 | WREG32_SMC(ixLCAC_MC0_CNTL, 0x05); |
| 1630 | WREG32_SMC(ixLCAC_MC1_CNTL, 0x05); |
| 1631 | WREG32_SMC(ixLCAC_CPL_CNTL, 0x100005); |
| 1632 | |
| 1633 | udelay(10); |
| 1634 | |
| 1635 | WREG32_SMC(ixLCAC_MC0_CNTL, 0x400005); |
| 1636 | WREG32_SMC(ixLCAC_MC1_CNTL, 0x400005); |
| 1637 | WREG32_SMC(ixLCAC_CPL_CNTL, 0x500005); |
| 1638 | } |
| 1639 | } else { |
| 1640 | if (!pi->sclk_dpm_key_disabled) { |
| 1641 | smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_DPM_Disable); |
| 1642 | if (smc_result != PPSMC_Result_OK) |
| 1643 | return -EINVAL; |
| 1644 | } |
| 1645 | |
| 1646 | if (!pi->mclk_dpm_key_disabled) { |
| 1647 | smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_MCLKDPM_Disable); |
| 1648 | if (smc_result != PPSMC_Result_OK) |
| 1649 | return -EINVAL; |
| 1650 | } |
| 1651 | } |
| 1652 | |
| 1653 | return 0; |
| 1654 | } |
| 1655 | |
| 1656 | static int ci_start_dpm(struct amdgpu_device *adev) |
| 1657 | { |
| 1658 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1659 | PPSMC_Result smc_result; |
| 1660 | int ret; |
| 1661 | u32 tmp; |
| 1662 | |
| 1663 | tmp = RREG32_SMC(ixGENERAL_PWRMGT); |
| 1664 | tmp |= GENERAL_PWRMGT__GLOBAL_PWRMGT_EN_MASK; |
| 1665 | WREG32_SMC(ixGENERAL_PWRMGT, tmp); |
| 1666 | |
| 1667 | tmp = RREG32_SMC(ixSCLK_PWRMGT_CNTL); |
| 1668 | tmp |= SCLK_PWRMGT_CNTL__DYNAMIC_PM_EN_MASK; |
| 1669 | WREG32_SMC(ixSCLK_PWRMGT_CNTL, tmp); |
| 1670 | |
| 1671 | ci_write_smc_soft_register(adev, offsetof(SMU7_SoftRegisters, VoltageChangeTimeout), 0x1000); |
| 1672 | |
| 1673 | WREG32_P(mmBIF_LNCNT_RESET, 0, ~BIF_LNCNT_RESET__RESET_LNCNT_EN_MASK); |
| 1674 | |
| 1675 | smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_Voltage_Cntl_Enable); |
| 1676 | if (smc_result != PPSMC_Result_OK) |
| 1677 | return -EINVAL; |
| 1678 | |
| 1679 | ret = ci_enable_sclk_mclk_dpm(adev, true); |
| 1680 | if (ret) |
| 1681 | return ret; |
| 1682 | |
| 1683 | if (!pi->pcie_dpm_key_disabled) { |
| 1684 | smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_PCIeDPM_Enable); |
| 1685 | if (smc_result != PPSMC_Result_OK) |
| 1686 | return -EINVAL; |
| 1687 | } |
| 1688 | |
| 1689 | return 0; |
| 1690 | } |
| 1691 | |
| 1692 | static int ci_freeze_sclk_mclk_dpm(struct amdgpu_device *adev) |
| 1693 | { |
| 1694 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1695 | PPSMC_Result smc_result; |
| 1696 | |
| 1697 | if (!pi->need_update_smu7_dpm_table) |
| 1698 | return 0; |
| 1699 | |
| 1700 | if ((!pi->sclk_dpm_key_disabled) && |
| 1701 | (pi->need_update_smu7_dpm_table & (DPMTABLE_OD_UPDATE_SCLK | DPMTABLE_UPDATE_SCLK))) { |
| 1702 | smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_SCLKDPM_FreezeLevel); |
| 1703 | if (smc_result != PPSMC_Result_OK) |
| 1704 | return -EINVAL; |
| 1705 | } |
| 1706 | |
| 1707 | if ((!pi->mclk_dpm_key_disabled) && |
| 1708 | (pi->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) { |
| 1709 | smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_MCLKDPM_FreezeLevel); |
| 1710 | if (smc_result != PPSMC_Result_OK) |
| 1711 | return -EINVAL; |
| 1712 | } |
| 1713 | |
| 1714 | return 0; |
| 1715 | } |
| 1716 | |
| 1717 | static int ci_stop_dpm(struct amdgpu_device *adev) |
| 1718 | { |
| 1719 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1720 | PPSMC_Result smc_result; |
| 1721 | int ret; |
| 1722 | u32 tmp; |
| 1723 | |
| 1724 | tmp = RREG32_SMC(ixGENERAL_PWRMGT); |
| 1725 | tmp &= ~GENERAL_PWRMGT__GLOBAL_PWRMGT_EN_MASK; |
| 1726 | WREG32_SMC(ixGENERAL_PWRMGT, tmp); |
| 1727 | |
| 1728 | tmp = RREG32_SMC(ixSCLK_PWRMGT_CNTL); |
| 1729 | tmp &= ~SCLK_PWRMGT_CNTL__DYNAMIC_PM_EN_MASK; |
| 1730 | WREG32_SMC(ixSCLK_PWRMGT_CNTL, tmp); |
| 1731 | |
| 1732 | if (!pi->pcie_dpm_key_disabled) { |
| 1733 | smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_PCIeDPM_Disable); |
| 1734 | if (smc_result != PPSMC_Result_OK) |
| 1735 | return -EINVAL; |
| 1736 | } |
| 1737 | |
| 1738 | ret = ci_enable_sclk_mclk_dpm(adev, false); |
| 1739 | if (ret) |
| 1740 | return ret; |
| 1741 | |
| 1742 | smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_Voltage_Cntl_Disable); |
| 1743 | if (smc_result != PPSMC_Result_OK) |
| 1744 | return -EINVAL; |
| 1745 | |
| 1746 | return 0; |
| 1747 | } |
| 1748 | |
| 1749 | static void ci_enable_sclk_control(struct amdgpu_device *adev, bool enable) |
| 1750 | { |
| 1751 | u32 tmp = RREG32_SMC(ixSCLK_PWRMGT_CNTL); |
| 1752 | |
| 1753 | if (enable) |
| 1754 | tmp &= ~SCLK_PWRMGT_CNTL__SCLK_PWRMGT_OFF_MASK; |
| 1755 | else |
| 1756 | tmp |= SCLK_PWRMGT_CNTL__SCLK_PWRMGT_OFF_MASK; |
| 1757 | WREG32_SMC(ixSCLK_PWRMGT_CNTL, tmp); |
| 1758 | } |
| 1759 | |
| 1760 | #if 0 |
| 1761 | static int ci_notify_hw_of_power_source(struct amdgpu_device *adev, |
| 1762 | bool ac_power) |
| 1763 | { |
| 1764 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1765 | struct amdgpu_cac_tdp_table *cac_tdp_table = |
| 1766 | adev->pm.dpm.dyn_state.cac_tdp_table; |
| 1767 | u32 power_limit; |
| 1768 | |
| 1769 | if (ac_power) |
| 1770 | power_limit = (u32)(cac_tdp_table->maximum_power_delivery_limit * 256); |
| 1771 | else |
| 1772 | power_limit = (u32)(cac_tdp_table->battery_power_limit * 256); |
| 1773 | |
| 1774 | ci_set_power_limit(adev, power_limit); |
| 1775 | |
| 1776 | if (pi->caps_automatic_dc_transition) { |
| 1777 | if (ac_power) |
| 1778 | amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_RunningOnAC); |
| 1779 | else |
| 1780 | amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_Remove_DC_Clamp); |
| 1781 | } |
| 1782 | |
| 1783 | return 0; |
| 1784 | } |
| 1785 | #endif |
| 1786 | |
| 1787 | static PPSMC_Result amdgpu_ci_send_msg_to_smc_with_parameter(struct amdgpu_device *adev, |
| 1788 | PPSMC_Msg msg, u32 parameter) |
| 1789 | { |
| 1790 | WREG32(mmSMC_MSG_ARG_0, parameter); |
| 1791 | return amdgpu_ci_send_msg_to_smc(adev, msg); |
| 1792 | } |
| 1793 | |
| 1794 | static PPSMC_Result amdgpu_ci_send_msg_to_smc_return_parameter(struct amdgpu_device *adev, |
| 1795 | PPSMC_Msg msg, u32 *parameter) |
| 1796 | { |
| 1797 | PPSMC_Result smc_result; |
| 1798 | |
| 1799 | smc_result = amdgpu_ci_send_msg_to_smc(adev, msg); |
| 1800 | |
| 1801 | if ((smc_result == PPSMC_Result_OK) && parameter) |
| 1802 | *parameter = RREG32(mmSMC_MSG_ARG_0); |
| 1803 | |
| 1804 | return smc_result; |
| 1805 | } |
| 1806 | |
| 1807 | static int ci_dpm_force_state_sclk(struct amdgpu_device *adev, u32 n) |
| 1808 | { |
| 1809 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1810 | |
| 1811 | if (!pi->sclk_dpm_key_disabled) { |
| 1812 | PPSMC_Result smc_result = |
| 1813 | amdgpu_ci_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_SCLKDPM_SetEnabledMask, 1 << n); |
| 1814 | if (smc_result != PPSMC_Result_OK) |
| 1815 | return -EINVAL; |
| 1816 | } |
| 1817 | |
| 1818 | return 0; |
| 1819 | } |
| 1820 | |
| 1821 | static int ci_dpm_force_state_mclk(struct amdgpu_device *adev, u32 n) |
| 1822 | { |
| 1823 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1824 | |
| 1825 | if (!pi->mclk_dpm_key_disabled) { |
| 1826 | PPSMC_Result smc_result = |
| 1827 | amdgpu_ci_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_MCLKDPM_SetEnabledMask, 1 << n); |
| 1828 | if (smc_result != PPSMC_Result_OK) |
| 1829 | return -EINVAL; |
| 1830 | } |
| 1831 | |
| 1832 | return 0; |
| 1833 | } |
| 1834 | |
| 1835 | static int ci_dpm_force_state_pcie(struct amdgpu_device *adev, u32 n) |
| 1836 | { |
| 1837 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1838 | |
| 1839 | if (!pi->pcie_dpm_key_disabled) { |
| 1840 | PPSMC_Result smc_result = |
| 1841 | amdgpu_ci_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_PCIeDPM_ForceLevel, n); |
| 1842 | if (smc_result != PPSMC_Result_OK) |
| 1843 | return -EINVAL; |
| 1844 | } |
| 1845 | |
| 1846 | return 0; |
| 1847 | } |
| 1848 | |
| 1849 | static int ci_set_power_limit(struct amdgpu_device *adev, u32 n) |
| 1850 | { |
| 1851 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1852 | |
| 1853 | if (pi->power_containment_features & POWERCONTAINMENT_FEATURE_PkgPwrLimit) { |
| 1854 | PPSMC_Result smc_result = |
| 1855 | amdgpu_ci_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_PkgPwrSetLimit, n); |
| 1856 | if (smc_result != PPSMC_Result_OK) |
| 1857 | return -EINVAL; |
| 1858 | } |
| 1859 | |
| 1860 | return 0; |
| 1861 | } |
| 1862 | |
| 1863 | static int ci_set_overdrive_target_tdp(struct amdgpu_device *adev, |
| 1864 | u32 target_tdp) |
| 1865 | { |
| 1866 | PPSMC_Result smc_result = |
| 1867 | amdgpu_ci_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_OverDriveSetTargetTdp, target_tdp); |
| 1868 | if (smc_result != PPSMC_Result_OK) |
| 1869 | return -EINVAL; |
| 1870 | return 0; |
| 1871 | } |
| 1872 | |
| 1873 | #if 0 |
| 1874 | static int ci_set_boot_state(struct amdgpu_device *adev) |
| 1875 | { |
| 1876 | return ci_enable_sclk_mclk_dpm(adev, false); |
| 1877 | } |
| 1878 | #endif |
| 1879 | |
| 1880 | static u32 ci_get_average_sclk_freq(struct amdgpu_device *adev) |
| 1881 | { |
| 1882 | u32 sclk_freq; |
| 1883 | PPSMC_Result smc_result = |
| 1884 | amdgpu_ci_send_msg_to_smc_return_parameter(adev, |
| 1885 | PPSMC_MSG_API_GetSclkFrequency, |
| 1886 | &sclk_freq); |
| 1887 | if (smc_result != PPSMC_Result_OK) |
| 1888 | sclk_freq = 0; |
| 1889 | |
| 1890 | return sclk_freq; |
| 1891 | } |
| 1892 | |
| 1893 | static u32 ci_get_average_mclk_freq(struct amdgpu_device *adev) |
| 1894 | { |
| 1895 | u32 mclk_freq; |
| 1896 | PPSMC_Result smc_result = |
| 1897 | amdgpu_ci_send_msg_to_smc_return_parameter(adev, |
| 1898 | PPSMC_MSG_API_GetMclkFrequency, |
| 1899 | &mclk_freq); |
| 1900 | if (smc_result != PPSMC_Result_OK) |
| 1901 | mclk_freq = 0; |
| 1902 | |
| 1903 | return mclk_freq; |
| 1904 | } |
| 1905 | |
| 1906 | static void ci_dpm_start_smc(struct amdgpu_device *adev) |
| 1907 | { |
| 1908 | int i; |
| 1909 | |
| 1910 | amdgpu_ci_program_jump_on_start(adev); |
| 1911 | amdgpu_ci_start_smc_clock(adev); |
| 1912 | amdgpu_ci_start_smc(adev); |
| 1913 | for (i = 0; i < adev->usec_timeout; i++) { |
| 1914 | if (RREG32_SMC(ixFIRMWARE_FLAGS) & FIRMWARE_FLAGS__INTERRUPTS_ENABLED_MASK) |
| 1915 | break; |
| 1916 | } |
| 1917 | } |
| 1918 | |
| 1919 | static void ci_dpm_stop_smc(struct amdgpu_device *adev) |
| 1920 | { |
| 1921 | amdgpu_ci_reset_smc(adev); |
| 1922 | amdgpu_ci_stop_smc_clock(adev); |
| 1923 | } |
| 1924 | |
| 1925 | static int ci_process_firmware_header(struct amdgpu_device *adev) |
| 1926 | { |
| 1927 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1928 | u32 tmp; |
| 1929 | int ret; |
| 1930 | |
| 1931 | ret = amdgpu_ci_read_smc_sram_dword(adev, |
| 1932 | SMU7_FIRMWARE_HEADER_LOCATION + |
| 1933 | offsetof(SMU7_Firmware_Header, DpmTable), |
| 1934 | &tmp, pi->sram_end); |
| 1935 | if (ret) |
| 1936 | return ret; |
| 1937 | |
| 1938 | pi->dpm_table_start = tmp; |
| 1939 | |
| 1940 | ret = amdgpu_ci_read_smc_sram_dword(adev, |
| 1941 | SMU7_FIRMWARE_HEADER_LOCATION + |
| 1942 | offsetof(SMU7_Firmware_Header, SoftRegisters), |
| 1943 | &tmp, pi->sram_end); |
| 1944 | if (ret) |
| 1945 | return ret; |
| 1946 | |
| 1947 | pi->soft_regs_start = tmp; |
| 1948 | |
| 1949 | ret = amdgpu_ci_read_smc_sram_dword(adev, |
| 1950 | SMU7_FIRMWARE_HEADER_LOCATION + |
| 1951 | offsetof(SMU7_Firmware_Header, mcRegisterTable), |
| 1952 | &tmp, pi->sram_end); |
| 1953 | if (ret) |
| 1954 | return ret; |
| 1955 | |
| 1956 | pi->mc_reg_table_start = tmp; |
| 1957 | |
| 1958 | ret = amdgpu_ci_read_smc_sram_dword(adev, |
| 1959 | SMU7_FIRMWARE_HEADER_LOCATION + |
| 1960 | offsetof(SMU7_Firmware_Header, FanTable), |
| 1961 | &tmp, pi->sram_end); |
| 1962 | if (ret) |
| 1963 | return ret; |
| 1964 | |
| 1965 | pi->fan_table_start = tmp; |
| 1966 | |
| 1967 | ret = amdgpu_ci_read_smc_sram_dword(adev, |
| 1968 | SMU7_FIRMWARE_HEADER_LOCATION + |
| 1969 | offsetof(SMU7_Firmware_Header, mcArbDramTimingTable), |
| 1970 | &tmp, pi->sram_end); |
| 1971 | if (ret) |
| 1972 | return ret; |
| 1973 | |
| 1974 | pi->arb_table_start = tmp; |
| 1975 | |
| 1976 | return 0; |
| 1977 | } |
| 1978 | |
| 1979 | static void ci_read_clock_registers(struct amdgpu_device *adev) |
| 1980 | { |
| 1981 | struct ci_power_info *pi = ci_get_pi(adev); |
| 1982 | |
| 1983 | pi->clock_registers.cg_spll_func_cntl = |
| 1984 | RREG32_SMC(ixCG_SPLL_FUNC_CNTL); |
| 1985 | pi->clock_registers.cg_spll_func_cntl_2 = |
| 1986 | RREG32_SMC(ixCG_SPLL_FUNC_CNTL_2); |
| 1987 | pi->clock_registers.cg_spll_func_cntl_3 = |
| 1988 | RREG32_SMC(ixCG_SPLL_FUNC_CNTL_3); |
| 1989 | pi->clock_registers.cg_spll_func_cntl_4 = |
| 1990 | RREG32_SMC(ixCG_SPLL_FUNC_CNTL_4); |
| 1991 | pi->clock_registers.cg_spll_spread_spectrum = |
| 1992 | RREG32_SMC(ixCG_SPLL_SPREAD_SPECTRUM); |
| 1993 | pi->clock_registers.cg_spll_spread_spectrum_2 = |
| 1994 | RREG32_SMC(ixCG_SPLL_SPREAD_SPECTRUM_2); |
| 1995 | pi->clock_registers.dll_cntl = RREG32(mmDLL_CNTL); |
| 1996 | pi->clock_registers.mclk_pwrmgt_cntl = RREG32(mmMCLK_PWRMGT_CNTL); |
| 1997 | pi->clock_registers.mpll_ad_func_cntl = RREG32(mmMPLL_AD_FUNC_CNTL); |
| 1998 | pi->clock_registers.mpll_dq_func_cntl = RREG32(mmMPLL_DQ_FUNC_CNTL); |
| 1999 | pi->clock_registers.mpll_func_cntl = RREG32(mmMPLL_FUNC_CNTL); |
| 2000 | pi->clock_registers.mpll_func_cntl_1 = RREG32(mmMPLL_FUNC_CNTL_1); |
| 2001 | pi->clock_registers.mpll_func_cntl_2 = RREG32(mmMPLL_FUNC_CNTL_2); |
| 2002 | pi->clock_registers.mpll_ss1 = RREG32(mmMPLL_SS1); |
| 2003 | pi->clock_registers.mpll_ss2 = RREG32(mmMPLL_SS2); |
| 2004 | } |
| 2005 | |
| 2006 | static void ci_init_sclk_t(struct amdgpu_device *adev) |
| 2007 | { |
| 2008 | struct ci_power_info *pi = ci_get_pi(adev); |
| 2009 | |
| 2010 | pi->low_sclk_interrupt_t = 0; |
| 2011 | } |
| 2012 | |
| 2013 | static void ci_enable_thermal_protection(struct amdgpu_device *adev, |
| 2014 | bool enable) |
| 2015 | { |
| 2016 | u32 tmp = RREG32_SMC(ixGENERAL_PWRMGT); |
| 2017 | |
| 2018 | if (enable) |
| 2019 | tmp &= ~GENERAL_PWRMGT__THERMAL_PROTECTION_DIS_MASK; |
| 2020 | else |
| 2021 | tmp |= GENERAL_PWRMGT__THERMAL_PROTECTION_DIS_MASK; |
| 2022 | WREG32_SMC(ixGENERAL_PWRMGT, tmp); |
| 2023 | } |
| 2024 | |
| 2025 | static void ci_enable_acpi_power_management(struct amdgpu_device *adev) |
| 2026 | { |
| 2027 | u32 tmp = RREG32_SMC(ixGENERAL_PWRMGT); |
| 2028 | |
| 2029 | tmp |= GENERAL_PWRMGT__STATIC_PM_EN_MASK; |
| 2030 | |
| 2031 | WREG32_SMC(ixGENERAL_PWRMGT, tmp); |
| 2032 | } |
| 2033 | |
| 2034 | #if 0 |
| 2035 | static int ci_enter_ulp_state(struct amdgpu_device *adev) |
| 2036 | { |
| 2037 | |
| 2038 | WREG32(mmSMC_MESSAGE_0, PPSMC_MSG_SwitchToMinimumPower); |
| 2039 | |
| 2040 | udelay(25000); |
| 2041 | |
| 2042 | return 0; |
| 2043 | } |
| 2044 | |
| 2045 | static int ci_exit_ulp_state(struct amdgpu_device *adev) |
| 2046 | { |
| 2047 | int i; |
| 2048 | |
| 2049 | WREG32(mmSMC_MESSAGE_0, PPSMC_MSG_ResumeFromMinimumPower); |
| 2050 | |
| 2051 | udelay(7000); |
| 2052 | |
| 2053 | for (i = 0; i < adev->usec_timeout; i++) { |
| 2054 | if (RREG32(mmSMC_RESP_0) == 1) |
| 2055 | break; |
| 2056 | udelay(1000); |
| 2057 | } |
| 2058 | |
| 2059 | return 0; |
| 2060 | } |
| 2061 | #endif |
| 2062 | |
| 2063 | static int ci_notify_smc_display_change(struct amdgpu_device *adev, |
| 2064 | bool has_display) |
| 2065 | { |
| 2066 | PPSMC_Msg msg = has_display ? PPSMC_MSG_HasDisplay : PPSMC_MSG_NoDisplay; |
| 2067 | |
| 2068 | return (amdgpu_ci_send_msg_to_smc(adev, msg) == PPSMC_Result_OK) ? 0 : -EINVAL; |
| 2069 | } |
| 2070 | |
| 2071 | static int ci_enable_ds_master_switch(struct amdgpu_device *adev, |
| 2072 | bool enable) |
| 2073 | { |
| 2074 | struct ci_power_info *pi = ci_get_pi(adev); |
| 2075 | |
| 2076 | if (enable) { |
| 2077 | if (pi->caps_sclk_ds) { |
| 2078 | if (amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_MASTER_DeepSleep_ON) != PPSMC_Result_OK) |
| 2079 | return -EINVAL; |
| 2080 | } else { |
| 2081 | if (amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_MASTER_DeepSleep_OFF) != PPSMC_Result_OK) |
| 2082 | return -EINVAL; |
| 2083 | } |
| 2084 | } else { |
| 2085 | if (pi->caps_sclk_ds) { |
| 2086 | if (amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_MASTER_DeepSleep_OFF) != PPSMC_Result_OK) |
| 2087 | return -EINVAL; |
| 2088 | } |
| 2089 | } |
| 2090 | |
| 2091 | return 0; |
| 2092 | } |
| 2093 | |
| 2094 | static void ci_program_display_gap(struct amdgpu_device *adev) |
| 2095 | { |
| 2096 | u32 tmp = RREG32_SMC(ixCG_DISPLAY_GAP_CNTL); |
| 2097 | u32 pre_vbi_time_in_us; |
| 2098 | u32 frame_time_in_us; |
| 2099 | u32 ref_clock = adev->clock.spll.reference_freq; |
| 2100 | u32 refresh_rate = amdgpu_dpm_get_vrefresh(adev); |
| 2101 | u32 vblank_time = amdgpu_dpm_get_vblank_time(adev); |
| 2102 | |
| 2103 | tmp &= ~CG_DISPLAY_GAP_CNTL__DISP_GAP_MASK; |
| 2104 | if (adev->pm.dpm.new_active_crtc_count > 0) |
| 2105 | tmp |= (AMDGPU_PM_DISPLAY_GAP_VBLANK_OR_WM << CG_DISPLAY_GAP_CNTL__DISP_GAP__SHIFT); |
| 2106 | else |
| 2107 | tmp |= (AMDGPU_PM_DISPLAY_GAP_IGNORE << CG_DISPLAY_GAP_CNTL__DISP_GAP__SHIFT); |
| 2108 | WREG32_SMC(ixCG_DISPLAY_GAP_CNTL, tmp); |
| 2109 | |
| 2110 | if (refresh_rate == 0) |
| 2111 | refresh_rate = 60; |
| 2112 | if (vblank_time == 0xffffffff) |
| 2113 | vblank_time = 500; |
| 2114 | frame_time_in_us = 1000000 / refresh_rate; |
| 2115 | pre_vbi_time_in_us = |
| 2116 | frame_time_in_us - 200 - vblank_time; |
| 2117 | tmp = pre_vbi_time_in_us * (ref_clock / 100); |
| 2118 | |
| 2119 | WREG32_SMC(ixCG_DISPLAY_GAP_CNTL2, tmp); |
| 2120 | ci_write_smc_soft_register(adev, offsetof(SMU7_SoftRegisters, PreVBlankGap), 0x64); |
| 2121 | ci_write_smc_soft_register(adev, offsetof(SMU7_SoftRegisters, VBlankTimeout), (frame_time_in_us - pre_vbi_time_in_us)); |
| 2122 | |
| 2123 | |
| 2124 | ci_notify_smc_display_change(adev, (adev->pm.dpm.new_active_crtc_count == 1)); |
| 2125 | |
| 2126 | } |
| 2127 | |
| 2128 | static void ci_enable_spread_spectrum(struct amdgpu_device *adev, bool enable) |
| 2129 | { |
| 2130 | struct ci_power_info *pi = ci_get_pi(adev); |
| 2131 | u32 tmp; |
| 2132 | |
| 2133 | if (enable) { |
| 2134 | if (pi->caps_sclk_ss_support) { |
| 2135 | tmp = RREG32_SMC(ixGENERAL_PWRMGT); |
| 2136 | tmp |= GENERAL_PWRMGT__DYN_SPREAD_SPECTRUM_EN_MASK; |
| 2137 | WREG32_SMC(ixGENERAL_PWRMGT, tmp); |
| 2138 | } |
| 2139 | } else { |
| 2140 | tmp = RREG32_SMC(ixCG_SPLL_SPREAD_SPECTRUM); |
| 2141 | tmp &= ~CG_SPLL_SPREAD_SPECTRUM__SSEN_MASK; |
| 2142 | WREG32_SMC(ixCG_SPLL_SPREAD_SPECTRUM, tmp); |
| 2143 | |
| 2144 | tmp = RREG32_SMC(ixGENERAL_PWRMGT); |
| 2145 | tmp &= ~GENERAL_PWRMGT__DYN_SPREAD_SPECTRUM_EN_MASK; |
| 2146 | WREG32_SMC(ixGENERAL_PWRMGT, tmp); |
| 2147 | } |
| 2148 | } |
| 2149 | |
| 2150 | static void ci_program_sstp(struct amdgpu_device *adev) |
| 2151 | { |
| 2152 | WREG32_SMC(ixCG_STATIC_SCREEN_PARAMETER, |
| 2153 | ((CISLANDS_SSTU_DFLT << CG_STATIC_SCREEN_PARAMETER__STATIC_SCREEN_THRESHOLD_UNIT__SHIFT) | |
| 2154 | (CISLANDS_SST_DFLT << CG_STATIC_SCREEN_PARAMETER__STATIC_SCREEN_THRESHOLD__SHIFT))); |
| 2155 | } |
| 2156 | |
| 2157 | static void ci_enable_display_gap(struct amdgpu_device *adev) |
| 2158 | { |
| 2159 | u32 tmp = RREG32_SMC(ixCG_DISPLAY_GAP_CNTL); |
| 2160 | |
| 2161 | tmp &= ~(CG_DISPLAY_GAP_CNTL__DISP_GAP_MASK | |
| 2162 | CG_DISPLAY_GAP_CNTL__DISP_GAP_MCHG_MASK); |
| 2163 | tmp |= ((AMDGPU_PM_DISPLAY_GAP_IGNORE << CG_DISPLAY_GAP_CNTL__DISP_GAP__SHIFT) | |
| 2164 | (AMDGPU_PM_DISPLAY_GAP_VBLANK << CG_DISPLAY_GAP_CNTL__DISP_GAP_MCHG__SHIFT)); |
| 2165 | |
| 2166 | WREG32_SMC(ixCG_DISPLAY_GAP_CNTL, tmp); |
| 2167 | } |
| 2168 | |
| 2169 | static void ci_program_vc(struct amdgpu_device *adev) |
| 2170 | { |
| 2171 | u32 tmp; |
| 2172 | |
| 2173 | tmp = RREG32_SMC(ixSCLK_PWRMGT_CNTL); |
| 2174 | tmp &= ~(SCLK_PWRMGT_CNTL__RESET_SCLK_CNT_MASK | SCLK_PWRMGT_CNTL__RESET_BUSY_CNT_MASK); |
| 2175 | WREG32_SMC(ixSCLK_PWRMGT_CNTL, tmp); |
| 2176 | |
| 2177 | WREG32_SMC(ixCG_FREQ_TRAN_VOTING_0, CISLANDS_VRC_DFLT0); |
| 2178 | WREG32_SMC(ixCG_FREQ_TRAN_VOTING_1, CISLANDS_VRC_DFLT1); |
| 2179 | WREG32_SMC(ixCG_FREQ_TRAN_VOTING_2, CISLANDS_VRC_DFLT2); |
| 2180 | WREG32_SMC(ixCG_FREQ_TRAN_VOTING_3, CISLANDS_VRC_DFLT3); |
| 2181 | WREG32_SMC(ixCG_FREQ_TRAN_VOTING_4, CISLANDS_VRC_DFLT4); |
| 2182 | WREG32_SMC(ixCG_FREQ_TRAN_VOTING_5, CISLANDS_VRC_DFLT5); |
| 2183 | WREG32_SMC(ixCG_FREQ_TRAN_VOTING_6, CISLANDS_VRC_DFLT6); |
| 2184 | WREG32_SMC(ixCG_FREQ_TRAN_VOTING_7, CISLANDS_VRC_DFLT7); |
| 2185 | } |
| 2186 | |
| 2187 | static void ci_clear_vc(struct amdgpu_device *adev) |
| 2188 | { |
| 2189 | u32 tmp; |
| 2190 | |
| 2191 | tmp = RREG32_SMC(ixSCLK_PWRMGT_CNTL); |
| 2192 | tmp |= (SCLK_PWRMGT_CNTL__RESET_SCLK_CNT_MASK | SCLK_PWRMGT_CNTL__RESET_BUSY_CNT_MASK); |
| 2193 | WREG32_SMC(ixSCLK_PWRMGT_CNTL, tmp); |
| 2194 | |
| 2195 | WREG32_SMC(ixCG_FREQ_TRAN_VOTING_0, 0); |
| 2196 | WREG32_SMC(ixCG_FREQ_TRAN_VOTING_1, 0); |
| 2197 | WREG32_SMC(ixCG_FREQ_TRAN_VOTING_2, 0); |
| 2198 | WREG32_SMC(ixCG_FREQ_TRAN_VOTING_3, 0); |
| 2199 | WREG32_SMC(ixCG_FREQ_TRAN_VOTING_4, 0); |
| 2200 | WREG32_SMC(ixCG_FREQ_TRAN_VOTING_5, 0); |
| 2201 | WREG32_SMC(ixCG_FREQ_TRAN_VOTING_6, 0); |
| 2202 | WREG32_SMC(ixCG_FREQ_TRAN_VOTING_7, 0); |
| 2203 | } |
| 2204 | |
| 2205 | static int ci_upload_firmware(struct amdgpu_device *adev) |
| 2206 | { |
| 2207 | struct ci_power_info *pi = ci_get_pi(adev); |
| 2208 | int i, ret; |
| 2209 | |
| 2210 | for (i = 0; i < adev->usec_timeout; i++) { |
| 2211 | if (RREG32_SMC(ixRCU_UC_EVENTS) & RCU_UC_EVENTS__boot_seq_done_MASK) |
| 2212 | break; |
| 2213 | } |
| 2214 | WREG32_SMC(ixSMC_SYSCON_MISC_CNTL, 1); |
| 2215 | |
| 2216 | amdgpu_ci_stop_smc_clock(adev); |
| 2217 | amdgpu_ci_reset_smc(adev); |
| 2218 | |
| 2219 | ret = amdgpu_ci_load_smc_ucode(adev, pi->sram_end); |
| 2220 | |
| 2221 | return ret; |
| 2222 | |
| 2223 | } |
| 2224 | |
| 2225 | static int ci_get_svi2_voltage_table(struct amdgpu_device *adev, |
| 2226 | struct amdgpu_clock_voltage_dependency_table *voltage_dependency_table, |
| 2227 | struct atom_voltage_table *voltage_table) |
| 2228 | { |
| 2229 | u32 i; |
| 2230 | |
| 2231 | if (voltage_dependency_table == NULL) |
| 2232 | return -EINVAL; |
| 2233 | |
| 2234 | voltage_table->mask_low = 0; |
| 2235 | voltage_table->phase_delay = 0; |
| 2236 | |
| 2237 | voltage_table->count = voltage_dependency_table->count; |
| 2238 | for (i = 0; i < voltage_table->count; i++) { |
| 2239 | voltage_table->entries[i].value = voltage_dependency_table->entries[i].v; |
| 2240 | voltage_table->entries[i].smio_low = 0; |
| 2241 | } |
| 2242 | |
| 2243 | return 0; |
| 2244 | } |
| 2245 | |
| 2246 | static int ci_construct_voltage_tables(struct amdgpu_device *adev) |
| 2247 | { |
| 2248 | struct ci_power_info *pi = ci_get_pi(adev); |
| 2249 | int ret; |
| 2250 | |
| 2251 | if (pi->voltage_control == CISLANDS_VOLTAGE_CONTROL_BY_GPIO) { |
| 2252 | ret = amdgpu_atombios_get_voltage_table(adev, VOLTAGE_TYPE_VDDC, |
| 2253 | VOLTAGE_OBJ_GPIO_LUT, |
| 2254 | &pi->vddc_voltage_table); |
| 2255 | if (ret) |
| 2256 | return ret; |
| 2257 | } else if (pi->voltage_control == CISLANDS_VOLTAGE_CONTROL_BY_SVID2) { |
| 2258 | ret = ci_get_svi2_voltage_table(adev, |
| 2259 | &adev->pm.dpm.dyn_state.vddc_dependency_on_mclk, |
| 2260 | &pi->vddc_voltage_table); |
| 2261 | if (ret) |
| 2262 | return ret; |
| 2263 | } |
| 2264 | |
| 2265 | if (pi->vddc_voltage_table.count > SMU7_MAX_LEVELS_VDDC) |
| 2266 | ci_trim_voltage_table_to_fit_state_table(adev, SMU7_MAX_LEVELS_VDDC, |
| 2267 | &pi->vddc_voltage_table); |
| 2268 | |
| 2269 | if (pi->vddci_control == CISLANDS_VOLTAGE_CONTROL_BY_GPIO) { |
| 2270 | ret = amdgpu_atombios_get_voltage_table(adev, VOLTAGE_TYPE_VDDCI, |
| 2271 | VOLTAGE_OBJ_GPIO_LUT, |
| 2272 | &pi->vddci_voltage_table); |
| 2273 | if (ret) |
| 2274 | return ret; |
| 2275 | } else if (pi->vddci_control == CISLANDS_VOLTAGE_CONTROL_BY_SVID2) { |
| 2276 | ret = ci_get_svi2_voltage_table(adev, |
| 2277 | &adev->pm.dpm.dyn_state.vddci_dependency_on_mclk, |
| 2278 | &pi->vddci_voltage_table); |
| 2279 | if (ret) |
| 2280 | return ret; |
| 2281 | } |
| 2282 | |
| 2283 | if (pi->vddci_voltage_table.count > SMU7_MAX_LEVELS_VDDCI) |
| 2284 | ci_trim_voltage_table_to_fit_state_table(adev, SMU7_MAX_LEVELS_VDDCI, |
| 2285 | &pi->vddci_voltage_table); |
| 2286 | |
| 2287 | if (pi->mvdd_control == CISLANDS_VOLTAGE_CONTROL_BY_GPIO) { |
| 2288 | ret = amdgpu_atombios_get_voltage_table(adev, VOLTAGE_TYPE_MVDDC, |
| 2289 | VOLTAGE_OBJ_GPIO_LUT, |
| 2290 | &pi->mvdd_voltage_table); |
| 2291 | if (ret) |
| 2292 | return ret; |
| 2293 | } else if (pi->mvdd_control == CISLANDS_VOLTAGE_CONTROL_BY_SVID2) { |
| 2294 | ret = ci_get_svi2_voltage_table(adev, |
| 2295 | &adev->pm.dpm.dyn_state.mvdd_dependency_on_mclk, |
| 2296 | &pi->mvdd_voltage_table); |
| 2297 | if (ret) |
| 2298 | return ret; |
| 2299 | } |
| 2300 | |
| 2301 | if (pi->mvdd_voltage_table.count > SMU7_MAX_LEVELS_MVDD) |
| 2302 | ci_trim_voltage_table_to_fit_state_table(adev, SMU7_MAX_LEVELS_MVDD, |
| 2303 | &pi->mvdd_voltage_table); |
| 2304 | |
| 2305 | return 0; |
| 2306 | } |
| 2307 | |
| 2308 | static void ci_populate_smc_voltage_table(struct amdgpu_device *adev, |
| 2309 | struct atom_voltage_table_entry *voltage_table, |
| 2310 | SMU7_Discrete_VoltageLevel *smc_voltage_table) |
| 2311 | { |
| 2312 | int ret; |
| 2313 | |
| 2314 | ret = ci_get_std_voltage_value_sidd(adev, voltage_table, |
| 2315 | &smc_voltage_table->StdVoltageHiSidd, |
| 2316 | &smc_voltage_table->StdVoltageLoSidd); |
| 2317 | |
| 2318 | if (ret) { |
| 2319 | smc_voltage_table->StdVoltageHiSidd = voltage_table->value * VOLTAGE_SCALE; |
| 2320 | smc_voltage_table->StdVoltageLoSidd = voltage_table->value * VOLTAGE_SCALE; |
| 2321 | } |
| 2322 | |
| 2323 | smc_voltage_table->Voltage = cpu_to_be16(voltage_table->value * VOLTAGE_SCALE); |
| 2324 | smc_voltage_table->StdVoltageHiSidd = |
| 2325 | cpu_to_be16(smc_voltage_table->StdVoltageHiSidd); |
| 2326 | smc_voltage_table->StdVoltageLoSidd = |
| 2327 | cpu_to_be16(smc_voltage_table->StdVoltageLoSidd); |
| 2328 | } |
| 2329 | |
| 2330 | static int ci_populate_smc_vddc_table(struct amdgpu_device *adev, |
| 2331 | SMU7_Discrete_DpmTable *table) |
| 2332 | { |
| 2333 | struct ci_power_info *pi = ci_get_pi(adev); |
| 2334 | unsigned int count; |
| 2335 | |
| 2336 | table->VddcLevelCount = pi->vddc_voltage_table.count; |
| 2337 | for (count = 0; count < table->VddcLevelCount; count++) { |
| 2338 | ci_populate_smc_voltage_table(adev, |
| 2339 | &pi->vddc_voltage_table.entries[count], |
| 2340 | &table->VddcLevel[count]); |
| 2341 | |
| 2342 | if (pi->voltage_control == CISLANDS_VOLTAGE_CONTROL_BY_GPIO) |
| 2343 | table->VddcLevel[count].Smio |= |
| 2344 | pi->vddc_voltage_table.entries[count].smio_low; |
| 2345 | else |
| 2346 | table->VddcLevel[count].Smio = 0; |
| 2347 | } |
| 2348 | table->VddcLevelCount = cpu_to_be32(table->VddcLevelCount); |
| 2349 | |
| 2350 | return 0; |
| 2351 | } |
| 2352 | |
| 2353 | static int ci_populate_smc_vddci_table(struct amdgpu_device *adev, |
| 2354 | SMU7_Discrete_DpmTable *table) |
| 2355 | { |
| 2356 | unsigned int count; |
| 2357 | struct ci_power_info *pi = ci_get_pi(adev); |
| 2358 | |
| 2359 | table->VddciLevelCount = pi->vddci_voltage_table.count; |
| 2360 | for (count = 0; count < table->VddciLevelCount; count++) { |
| 2361 | ci_populate_smc_voltage_table(adev, |
| 2362 | &pi->vddci_voltage_table.entries[count], |
| 2363 | &table->VddciLevel[count]); |
| 2364 | |
| 2365 | if (pi->vddci_control == CISLANDS_VOLTAGE_CONTROL_BY_GPIO) |
| 2366 | table->VddciLevel[count].Smio |= |
| 2367 | pi->vddci_voltage_table.entries[count].smio_low; |
| 2368 | else |
| 2369 | table->VddciLevel[count].Smio = 0; |
| 2370 | } |
| 2371 | table->VddciLevelCount = cpu_to_be32(table->VddciLevelCount); |
| 2372 | |
| 2373 | return 0; |
| 2374 | } |
| 2375 | |
| 2376 | static int ci_populate_smc_mvdd_table(struct amdgpu_device *adev, |
| 2377 | SMU7_Discrete_DpmTable *table) |
| 2378 | { |
| 2379 | struct ci_power_info *pi = ci_get_pi(adev); |
| 2380 | unsigned int count; |
| 2381 | |
| 2382 | table->MvddLevelCount = pi->mvdd_voltage_table.count; |
| 2383 | for (count = 0; count < table->MvddLevelCount; count++) { |
| 2384 | ci_populate_smc_voltage_table(adev, |
| 2385 | &pi->mvdd_voltage_table.entries[count], |
| 2386 | &table->MvddLevel[count]); |
| 2387 | |
| 2388 | if (pi->mvdd_control == CISLANDS_VOLTAGE_CONTROL_BY_GPIO) |
| 2389 | table->MvddLevel[count].Smio |= |
| 2390 | pi->mvdd_voltage_table.entries[count].smio_low; |
| 2391 | else |
| 2392 | table->MvddLevel[count].Smio = 0; |
| 2393 | } |
| 2394 | table->MvddLevelCount = cpu_to_be32(table->MvddLevelCount); |
| 2395 | |
| 2396 | return 0; |
| 2397 | } |
| 2398 | |
| 2399 | static int ci_populate_smc_voltage_tables(struct amdgpu_device *adev, |
| 2400 | SMU7_Discrete_DpmTable *table) |
| 2401 | { |
| 2402 | int ret; |
| 2403 | |
| 2404 | ret = ci_populate_smc_vddc_table(adev, table); |
| 2405 | if (ret) |
| 2406 | return ret; |
| 2407 | |
| 2408 | ret = ci_populate_smc_vddci_table(adev, table); |
| 2409 | if (ret) |
| 2410 | return ret; |
| 2411 | |
| 2412 | ret = ci_populate_smc_mvdd_table(adev, table); |
| 2413 | if (ret) |
| 2414 | return ret; |
| 2415 | |
| 2416 | return 0; |
| 2417 | } |
| 2418 | |
| 2419 | static int ci_populate_mvdd_value(struct amdgpu_device *adev, u32 mclk, |
| 2420 | SMU7_Discrete_VoltageLevel *voltage) |
| 2421 | { |
| 2422 | struct ci_power_info *pi = ci_get_pi(adev); |
| 2423 | u32 i = 0; |
| 2424 | |
| 2425 | if (pi->mvdd_control != CISLANDS_VOLTAGE_CONTROL_NONE) { |
| 2426 | for (i = 0; i < adev->pm.dpm.dyn_state.mvdd_dependency_on_mclk.count; i++) { |
| 2427 | if (mclk <= adev->pm.dpm.dyn_state.mvdd_dependency_on_mclk.entries[i].clk) { |
| 2428 | voltage->Voltage = pi->mvdd_voltage_table.entries[i].value; |
| 2429 | break; |
| 2430 | } |
| 2431 | } |
| 2432 | |
| 2433 | if (i >= adev->pm.dpm.dyn_state.mvdd_dependency_on_mclk.count) |
| 2434 | return -EINVAL; |
| 2435 | } |
| 2436 | |
| 2437 | return -EINVAL; |
| 2438 | } |
| 2439 | |
| 2440 | static int ci_get_std_voltage_value_sidd(struct amdgpu_device *adev, |
| 2441 | struct atom_voltage_table_entry *voltage_table, |
| 2442 | u16 *std_voltage_hi_sidd, u16 *std_voltage_lo_sidd) |
| 2443 | { |
| 2444 | u16 v_index, idx; |
| 2445 | bool voltage_found = false; |
| 2446 | *std_voltage_hi_sidd = voltage_table->value * VOLTAGE_SCALE; |
| 2447 | *std_voltage_lo_sidd = voltage_table->value * VOLTAGE_SCALE; |
| 2448 | |
| 2449 | if (adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries == NULL) |
| 2450 | return -EINVAL; |
| 2451 | |
| 2452 | if (adev->pm.dpm.dyn_state.cac_leakage_table.entries) { |
| 2453 | for (v_index = 0; (u32)v_index < adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.count; v_index++) { |
| 2454 | if (voltage_table->value == |
| 2455 | adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[v_index].v) { |
| 2456 | voltage_found = true; |
| 2457 | if ((u32)v_index < adev->pm.dpm.dyn_state.cac_leakage_table.count) |
| 2458 | idx = v_index; |
| 2459 | else |
| 2460 | idx = adev->pm.dpm.dyn_state.cac_leakage_table.count - 1; |
| 2461 | *std_voltage_lo_sidd = |
| 2462 | adev->pm.dpm.dyn_state.cac_leakage_table.entries[idx].vddc * VOLTAGE_SCALE; |
| 2463 | *std_voltage_hi_sidd = |
| 2464 | adev->pm.dpm.dyn_state.cac_leakage_table.entries[idx].leakage * VOLTAGE_SCALE; |
| 2465 | break; |
| 2466 | } |
| 2467 | } |
| 2468 | |
| 2469 | if (!voltage_found) { |
| 2470 | for (v_index = 0; (u32)v_index < adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.count; v_index++) { |
| 2471 | if (voltage_table->value <= |
| 2472 | adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[v_index].v) { |
| 2473 | voltage_found = true; |
| 2474 | if ((u32)v_index < adev->pm.dpm.dyn_state.cac_leakage_table.count) |
| 2475 | idx = v_index; |
| 2476 | else |
| 2477 | idx = adev->pm.dpm.dyn_state.cac_leakage_table.count - 1; |
| 2478 | *std_voltage_lo_sidd = |
| 2479 | adev->pm.dpm.dyn_state.cac_leakage_table.entries[idx].vddc * VOLTAGE_SCALE; |
| 2480 | *std_voltage_hi_sidd = |
| 2481 | adev->pm.dpm.dyn_state.cac_leakage_table.entries[idx].leakage * VOLTAGE_SCALE; |
| 2482 | break; |
| 2483 | } |
| 2484 | } |
| 2485 | } |
| 2486 | } |
| 2487 | |
| 2488 | return 0; |
| 2489 | } |
| 2490 | |
| 2491 | static void ci_populate_phase_value_based_on_sclk(struct amdgpu_device *adev, |
| 2492 | const struct amdgpu_phase_shedding_limits_table *limits, |
| 2493 | u32 sclk, |
| 2494 | u32 *phase_shedding) |
| 2495 | { |
| 2496 | unsigned int i; |
| 2497 | |
| 2498 | *phase_shedding = 1; |
| 2499 | |
| 2500 | for (i = 0; i < limits->count; i++) { |
| 2501 | if (sclk < limits->entries[i].sclk) { |
| 2502 | *phase_shedding = i; |
| 2503 | break; |
| 2504 | } |
| 2505 | } |
| 2506 | } |
| 2507 | |
| 2508 | static void ci_populate_phase_value_based_on_mclk(struct amdgpu_device *adev, |
| 2509 | const struct amdgpu_phase_shedding_limits_table *limits, |
| 2510 | u32 mclk, |
| 2511 | u32 *phase_shedding) |
| 2512 | { |
| 2513 | unsigned int i; |
| 2514 | |
| 2515 | *phase_shedding = 1; |
| 2516 | |
| 2517 | for (i = 0; i < limits->count; i++) { |
| 2518 | if (mclk < limits->entries[i].mclk) { |
| 2519 | *phase_shedding = i; |
| 2520 | break; |
| 2521 | } |
| 2522 | } |
| 2523 | } |
| 2524 | |
| 2525 | static int ci_init_arb_table_index(struct amdgpu_device *adev) |
| 2526 | { |
| 2527 | struct ci_power_info *pi = ci_get_pi(adev); |
| 2528 | u32 tmp; |
| 2529 | int ret; |
| 2530 | |
| 2531 | ret = amdgpu_ci_read_smc_sram_dword(adev, pi->arb_table_start, |
| 2532 | &tmp, pi->sram_end); |
| 2533 | if (ret) |
| 2534 | return ret; |
| 2535 | |
| 2536 | tmp &= 0x00FFFFFF; |
| 2537 | tmp |= MC_CG_ARB_FREQ_F1 << 24; |
| 2538 | |
| 2539 | return amdgpu_ci_write_smc_sram_dword(adev, pi->arb_table_start, |
| 2540 | tmp, pi->sram_end); |
| 2541 | } |
| 2542 | |
| 2543 | static int ci_get_dependency_volt_by_clk(struct amdgpu_device *adev, |
| 2544 | struct amdgpu_clock_voltage_dependency_table *allowed_clock_voltage_table, |
| 2545 | u32 clock, u32 *voltage) |
| 2546 | { |
| 2547 | u32 i = 0; |
| 2548 | |
| 2549 | if (allowed_clock_voltage_table->count == 0) |
| 2550 | return -EINVAL; |
| 2551 | |
| 2552 | for (i = 0; i < allowed_clock_voltage_table->count; i++) { |
| 2553 | if (allowed_clock_voltage_table->entries[i].clk >= clock) { |
| 2554 | *voltage = allowed_clock_voltage_table->entries[i].v; |
| 2555 | return 0; |
| 2556 | } |
| 2557 | } |
| 2558 | |
| 2559 | *voltage = allowed_clock_voltage_table->entries[i-1].v; |
| 2560 | |
| 2561 | return 0; |
| 2562 | } |
| 2563 | |
Nils Wallménius | 438498a | 2016-05-05 09:07:48 +0200 | [diff] [blame] | 2564 | static u8 ci_get_sleep_divider_id_from_clock(u32 sclk, u32 min_sclk_in_sr) |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 2565 | { |
| 2566 | u32 i; |
| 2567 | u32 tmp; |
Nils Wallménius | 9887e42 | 2016-05-05 09:07:46 +0200 | [diff] [blame] | 2568 | u32 min = max(min_sclk_in_sr, (u32)CISLAND_MINIMUM_ENGINE_CLOCK); |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 2569 | |
| 2570 | if (sclk < min) |
| 2571 | return 0; |
| 2572 | |
| 2573 | for (i = CISLAND_MAX_DEEPSLEEP_DIVIDER_ID; ; i--) { |
Nils Wallménius | 354ef92 | 2016-05-05 09:07:47 +0200 | [diff] [blame] | 2574 | tmp = sclk >> i; |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 2575 | if (tmp >= min || i == 0) |
| 2576 | break; |
| 2577 | } |
| 2578 | |
| 2579 | return (u8)i; |
| 2580 | } |
| 2581 | |
| 2582 | static int ci_initial_switch_from_arb_f0_to_f1(struct amdgpu_device *adev) |
| 2583 | { |
| 2584 | return ci_copy_and_switch_arb_sets(adev, MC_CG_ARB_FREQ_F0, MC_CG_ARB_FREQ_F1); |
| 2585 | } |
| 2586 | |
| 2587 | static int ci_reset_to_default(struct amdgpu_device *adev) |
| 2588 | { |
| 2589 | return (amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_ResetToDefaults) == PPSMC_Result_OK) ? |
| 2590 | 0 : -EINVAL; |
| 2591 | } |
| 2592 | |
| 2593 | static int ci_force_switch_to_arb_f0(struct amdgpu_device *adev) |
| 2594 | { |
| 2595 | u32 tmp; |
| 2596 | |
| 2597 | tmp = (RREG32_SMC(ixSMC_SCRATCH9) & 0x0000ff00) >> 8; |
| 2598 | |
| 2599 | if (tmp == MC_CG_ARB_FREQ_F0) |
| 2600 | return 0; |
| 2601 | |
| 2602 | return ci_copy_and_switch_arb_sets(adev, tmp, MC_CG_ARB_FREQ_F0); |
| 2603 | } |
| 2604 | |
| 2605 | static void ci_register_patching_mc_arb(struct amdgpu_device *adev, |
| 2606 | const u32 engine_clock, |
| 2607 | const u32 memory_clock, |
| 2608 | u32 *dram_timimg2) |
| 2609 | { |
| 2610 | bool patch; |
| 2611 | u32 tmp, tmp2; |
| 2612 | |
| 2613 | tmp = RREG32(mmMC_SEQ_MISC0); |
| 2614 | patch = ((tmp & 0x0000f00) == 0x300) ? true : false; |
| 2615 | |
| 2616 | if (patch && |
| 2617 | ((adev->pdev->device == 0x67B0) || |
| 2618 | (adev->pdev->device == 0x67B1))) { |
| 2619 | if ((memory_clock > 100000) && (memory_clock <= 125000)) { |
| 2620 | tmp2 = (((0x31 * engine_clock) / 125000) - 1) & 0xff; |
| 2621 | *dram_timimg2 &= ~0x00ff0000; |
| 2622 | *dram_timimg2 |= tmp2 << 16; |
| 2623 | } else if ((memory_clock > 125000) && (memory_clock <= 137500)) { |
| 2624 | tmp2 = (((0x36 * engine_clock) / 137500) - 1) & 0xff; |
| 2625 | *dram_timimg2 &= ~0x00ff0000; |
| 2626 | *dram_timimg2 |= tmp2 << 16; |
| 2627 | } |
| 2628 | } |
| 2629 | } |
| 2630 | |
| 2631 | static int ci_populate_memory_timing_parameters(struct amdgpu_device *adev, |
| 2632 | u32 sclk, |
| 2633 | u32 mclk, |
| 2634 | SMU7_Discrete_MCArbDramTimingTableEntry *arb_regs) |
| 2635 | { |
| 2636 | u32 dram_timing; |
| 2637 | u32 dram_timing2; |
| 2638 | u32 burst_time; |
| 2639 | |
| 2640 | amdgpu_atombios_set_engine_dram_timings(adev, sclk, mclk); |
| 2641 | |
| 2642 | dram_timing = RREG32(mmMC_ARB_DRAM_TIMING); |
| 2643 | dram_timing2 = RREG32(mmMC_ARB_DRAM_TIMING2); |
| 2644 | burst_time = RREG32(mmMC_ARB_BURST_TIME) & MC_ARB_BURST_TIME__STATE0_MASK; |
| 2645 | |
| 2646 | ci_register_patching_mc_arb(adev, sclk, mclk, &dram_timing2); |
| 2647 | |
| 2648 | arb_regs->McArbDramTiming = cpu_to_be32(dram_timing); |
| 2649 | arb_regs->McArbDramTiming2 = cpu_to_be32(dram_timing2); |
| 2650 | arb_regs->McArbBurstTime = (u8)burst_time; |
| 2651 | |
| 2652 | return 0; |
| 2653 | } |
| 2654 | |
| 2655 | static int ci_do_program_memory_timing_parameters(struct amdgpu_device *adev) |
| 2656 | { |
| 2657 | struct ci_power_info *pi = ci_get_pi(adev); |
| 2658 | SMU7_Discrete_MCArbDramTimingTable arb_regs; |
| 2659 | u32 i, j; |
| 2660 | int ret = 0; |
| 2661 | |
| 2662 | memset(&arb_regs, 0, sizeof(SMU7_Discrete_MCArbDramTimingTable)); |
| 2663 | |
| 2664 | for (i = 0; i < pi->dpm_table.sclk_table.count; i++) { |
| 2665 | for (j = 0; j < pi->dpm_table.mclk_table.count; j++) { |
| 2666 | ret = ci_populate_memory_timing_parameters(adev, |
| 2667 | pi->dpm_table.sclk_table.dpm_levels[i].value, |
| 2668 | pi->dpm_table.mclk_table.dpm_levels[j].value, |
| 2669 | &arb_regs.entries[i][j]); |
| 2670 | if (ret) |
| 2671 | break; |
| 2672 | } |
| 2673 | } |
| 2674 | |
| 2675 | if (ret == 0) |
| 2676 | ret = amdgpu_ci_copy_bytes_to_smc(adev, |
| 2677 | pi->arb_table_start, |
| 2678 | (u8 *)&arb_regs, |
| 2679 | sizeof(SMU7_Discrete_MCArbDramTimingTable), |
| 2680 | pi->sram_end); |
| 2681 | |
| 2682 | return ret; |
| 2683 | } |
| 2684 | |
| 2685 | static int ci_program_memory_timing_parameters(struct amdgpu_device *adev) |
| 2686 | { |
| 2687 | struct ci_power_info *pi = ci_get_pi(adev); |
| 2688 | |
| 2689 | if (pi->need_update_smu7_dpm_table == 0) |
| 2690 | return 0; |
| 2691 | |
| 2692 | return ci_do_program_memory_timing_parameters(adev); |
| 2693 | } |
| 2694 | |
| 2695 | static void ci_populate_smc_initial_state(struct amdgpu_device *adev, |
| 2696 | struct amdgpu_ps *amdgpu_boot_state) |
| 2697 | { |
| 2698 | struct ci_ps *boot_state = ci_get_ps(amdgpu_boot_state); |
| 2699 | struct ci_power_info *pi = ci_get_pi(adev); |
| 2700 | u32 level = 0; |
| 2701 | |
| 2702 | for (level = 0; level < adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.count; level++) { |
| 2703 | if (adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[level].clk >= |
| 2704 | boot_state->performance_levels[0].sclk) { |
| 2705 | pi->smc_state_table.GraphicsBootLevel = level; |
| 2706 | break; |
| 2707 | } |
| 2708 | } |
| 2709 | |
| 2710 | for (level = 0; level < adev->pm.dpm.dyn_state.vddc_dependency_on_mclk.count; level++) { |
| 2711 | if (adev->pm.dpm.dyn_state.vddc_dependency_on_mclk.entries[level].clk >= |
| 2712 | boot_state->performance_levels[0].mclk) { |
| 2713 | pi->smc_state_table.MemoryBootLevel = level; |
| 2714 | break; |
| 2715 | } |
| 2716 | } |
| 2717 | } |
| 2718 | |
| 2719 | static u32 ci_get_dpm_level_enable_mask_value(struct ci_single_dpm_table *dpm_table) |
| 2720 | { |
| 2721 | u32 i; |
| 2722 | u32 mask_value = 0; |
| 2723 | |
| 2724 | for (i = dpm_table->count; i > 0; i--) { |
| 2725 | mask_value = mask_value << 1; |
| 2726 | if (dpm_table->dpm_levels[i-1].enabled) |
| 2727 | mask_value |= 0x1; |
| 2728 | else |
| 2729 | mask_value &= 0xFFFFFFFE; |
| 2730 | } |
| 2731 | |
| 2732 | return mask_value; |
| 2733 | } |
| 2734 | |
| 2735 | static void ci_populate_smc_link_level(struct amdgpu_device *adev, |
| 2736 | SMU7_Discrete_DpmTable *table) |
| 2737 | { |
| 2738 | struct ci_power_info *pi = ci_get_pi(adev); |
| 2739 | struct ci_dpm_table *dpm_table = &pi->dpm_table; |
| 2740 | u32 i; |
| 2741 | |
| 2742 | for (i = 0; i < dpm_table->pcie_speed_table.count; i++) { |
| 2743 | table->LinkLevel[i].PcieGenSpeed = |
| 2744 | (u8)dpm_table->pcie_speed_table.dpm_levels[i].value; |
| 2745 | table->LinkLevel[i].PcieLaneCount = |
| 2746 | amdgpu_encode_pci_lane_width(dpm_table->pcie_speed_table.dpm_levels[i].param1); |
| 2747 | table->LinkLevel[i].EnabledForActivity = 1; |
| 2748 | table->LinkLevel[i].DownT = cpu_to_be32(5); |
| 2749 | table->LinkLevel[i].UpT = cpu_to_be32(30); |
| 2750 | } |
| 2751 | |
| 2752 | pi->smc_state_table.LinkLevelCount = (u8)dpm_table->pcie_speed_table.count; |
| 2753 | pi->dpm_level_enable_mask.pcie_dpm_enable_mask = |
| 2754 | ci_get_dpm_level_enable_mask_value(&dpm_table->pcie_speed_table); |
| 2755 | } |
| 2756 | |
| 2757 | static int ci_populate_smc_uvd_level(struct amdgpu_device *adev, |
| 2758 | SMU7_Discrete_DpmTable *table) |
| 2759 | { |
| 2760 | u32 count; |
| 2761 | struct atom_clock_dividers dividers; |
| 2762 | int ret = -EINVAL; |
| 2763 | |
| 2764 | table->UvdLevelCount = |
| 2765 | adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.count; |
| 2766 | |
| 2767 | for (count = 0; count < table->UvdLevelCount; count++) { |
| 2768 | table->UvdLevel[count].VclkFrequency = |
| 2769 | adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[count].vclk; |
| 2770 | table->UvdLevel[count].DclkFrequency = |
| 2771 | adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[count].dclk; |
| 2772 | table->UvdLevel[count].MinVddc = |
| 2773 | adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[count].v * VOLTAGE_SCALE; |
| 2774 | table->UvdLevel[count].MinVddcPhases = 1; |
| 2775 | |
| 2776 | ret = amdgpu_atombios_get_clock_dividers(adev, |
| 2777 | COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK, |
| 2778 | table->UvdLevel[count].VclkFrequency, false, ÷rs); |
| 2779 | if (ret) |
| 2780 | return ret; |
| 2781 | |
| 2782 | table->UvdLevel[count].VclkDivider = (u8)dividers.post_divider; |
| 2783 | |
| 2784 | ret = amdgpu_atombios_get_clock_dividers(adev, |
| 2785 | COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK, |
| 2786 | table->UvdLevel[count].DclkFrequency, false, ÷rs); |
| 2787 | if (ret) |
| 2788 | return ret; |
| 2789 | |
| 2790 | table->UvdLevel[count].DclkDivider = (u8)dividers.post_divider; |
| 2791 | |
| 2792 | table->UvdLevel[count].VclkFrequency = cpu_to_be32(table->UvdLevel[count].VclkFrequency); |
| 2793 | table->UvdLevel[count].DclkFrequency = cpu_to_be32(table->UvdLevel[count].DclkFrequency); |
| 2794 | table->UvdLevel[count].MinVddc = cpu_to_be16(table->UvdLevel[count].MinVddc); |
| 2795 | } |
| 2796 | |
| 2797 | return ret; |
| 2798 | } |
| 2799 | |
| 2800 | static int ci_populate_smc_vce_level(struct amdgpu_device *adev, |
| 2801 | SMU7_Discrete_DpmTable *table) |
| 2802 | { |
| 2803 | u32 count; |
| 2804 | struct atom_clock_dividers dividers; |
| 2805 | int ret = -EINVAL; |
| 2806 | |
| 2807 | table->VceLevelCount = |
| 2808 | adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.count; |
| 2809 | |
| 2810 | for (count = 0; count < table->VceLevelCount; count++) { |
| 2811 | table->VceLevel[count].Frequency = |
| 2812 | adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries[count].evclk; |
| 2813 | table->VceLevel[count].MinVoltage = |
| 2814 | (u16)adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries[count].v * VOLTAGE_SCALE; |
| 2815 | table->VceLevel[count].MinPhases = 1; |
| 2816 | |
| 2817 | ret = amdgpu_atombios_get_clock_dividers(adev, |
| 2818 | COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK, |
| 2819 | table->VceLevel[count].Frequency, false, ÷rs); |
| 2820 | if (ret) |
| 2821 | return ret; |
| 2822 | |
| 2823 | table->VceLevel[count].Divider = (u8)dividers.post_divider; |
| 2824 | |
| 2825 | table->VceLevel[count].Frequency = cpu_to_be32(table->VceLevel[count].Frequency); |
| 2826 | table->VceLevel[count].MinVoltage = cpu_to_be16(table->VceLevel[count].MinVoltage); |
| 2827 | } |
| 2828 | |
| 2829 | return ret; |
| 2830 | |
| 2831 | } |
| 2832 | |
| 2833 | static int ci_populate_smc_acp_level(struct amdgpu_device *adev, |
| 2834 | SMU7_Discrete_DpmTable *table) |
| 2835 | { |
| 2836 | u32 count; |
| 2837 | struct atom_clock_dividers dividers; |
| 2838 | int ret = -EINVAL; |
| 2839 | |
| 2840 | table->AcpLevelCount = (u8) |
| 2841 | (adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.count); |
| 2842 | |
| 2843 | for (count = 0; count < table->AcpLevelCount; count++) { |
| 2844 | table->AcpLevel[count].Frequency = |
| 2845 | adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries[count].clk; |
| 2846 | table->AcpLevel[count].MinVoltage = |
| 2847 | adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries[count].v; |
| 2848 | table->AcpLevel[count].MinPhases = 1; |
| 2849 | |
| 2850 | ret = amdgpu_atombios_get_clock_dividers(adev, |
| 2851 | COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK, |
| 2852 | table->AcpLevel[count].Frequency, false, ÷rs); |
| 2853 | if (ret) |
| 2854 | return ret; |
| 2855 | |
| 2856 | table->AcpLevel[count].Divider = (u8)dividers.post_divider; |
| 2857 | |
| 2858 | table->AcpLevel[count].Frequency = cpu_to_be32(table->AcpLevel[count].Frequency); |
| 2859 | table->AcpLevel[count].MinVoltage = cpu_to_be16(table->AcpLevel[count].MinVoltage); |
| 2860 | } |
| 2861 | |
| 2862 | return ret; |
| 2863 | } |
| 2864 | |
| 2865 | static int ci_populate_smc_samu_level(struct amdgpu_device *adev, |
| 2866 | SMU7_Discrete_DpmTable *table) |
| 2867 | { |
| 2868 | u32 count; |
| 2869 | struct atom_clock_dividers dividers; |
| 2870 | int ret = -EINVAL; |
| 2871 | |
| 2872 | table->SamuLevelCount = |
| 2873 | adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.count; |
| 2874 | |
| 2875 | for (count = 0; count < table->SamuLevelCount; count++) { |
| 2876 | table->SamuLevel[count].Frequency = |
| 2877 | adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries[count].clk; |
| 2878 | table->SamuLevel[count].MinVoltage = |
| 2879 | adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries[count].v * VOLTAGE_SCALE; |
| 2880 | table->SamuLevel[count].MinPhases = 1; |
| 2881 | |
| 2882 | ret = amdgpu_atombios_get_clock_dividers(adev, |
| 2883 | COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK, |
| 2884 | table->SamuLevel[count].Frequency, false, ÷rs); |
| 2885 | if (ret) |
| 2886 | return ret; |
| 2887 | |
| 2888 | table->SamuLevel[count].Divider = (u8)dividers.post_divider; |
| 2889 | |
| 2890 | table->SamuLevel[count].Frequency = cpu_to_be32(table->SamuLevel[count].Frequency); |
| 2891 | table->SamuLevel[count].MinVoltage = cpu_to_be16(table->SamuLevel[count].MinVoltage); |
| 2892 | } |
| 2893 | |
| 2894 | return ret; |
| 2895 | } |
| 2896 | |
| 2897 | static int ci_calculate_mclk_params(struct amdgpu_device *adev, |
| 2898 | u32 memory_clock, |
| 2899 | SMU7_Discrete_MemoryLevel *mclk, |
| 2900 | bool strobe_mode, |
| 2901 | bool dll_state_on) |
| 2902 | { |
| 2903 | struct ci_power_info *pi = ci_get_pi(adev); |
| 2904 | u32 dll_cntl = pi->clock_registers.dll_cntl; |
| 2905 | u32 mclk_pwrmgt_cntl = pi->clock_registers.mclk_pwrmgt_cntl; |
| 2906 | u32 mpll_ad_func_cntl = pi->clock_registers.mpll_ad_func_cntl; |
| 2907 | u32 mpll_dq_func_cntl = pi->clock_registers.mpll_dq_func_cntl; |
| 2908 | u32 mpll_func_cntl = pi->clock_registers.mpll_func_cntl; |
| 2909 | u32 mpll_func_cntl_1 = pi->clock_registers.mpll_func_cntl_1; |
| 2910 | u32 mpll_func_cntl_2 = pi->clock_registers.mpll_func_cntl_2; |
| 2911 | u32 mpll_ss1 = pi->clock_registers.mpll_ss1; |
| 2912 | u32 mpll_ss2 = pi->clock_registers.mpll_ss2; |
| 2913 | struct atom_mpll_param mpll_param; |
| 2914 | int ret; |
| 2915 | |
| 2916 | ret = amdgpu_atombios_get_memory_pll_dividers(adev, memory_clock, strobe_mode, &mpll_param); |
| 2917 | if (ret) |
| 2918 | return ret; |
| 2919 | |
| 2920 | mpll_func_cntl &= ~MPLL_FUNC_CNTL__BWCTRL_MASK; |
| 2921 | mpll_func_cntl |= (mpll_param.bwcntl << MPLL_FUNC_CNTL__BWCTRL__SHIFT); |
| 2922 | |
| 2923 | mpll_func_cntl_1 &= ~(MPLL_FUNC_CNTL_1__CLKF_MASK | MPLL_FUNC_CNTL_1__CLKFRAC_MASK | |
| 2924 | MPLL_FUNC_CNTL_1__VCO_MODE_MASK); |
| 2925 | mpll_func_cntl_1 |= (mpll_param.clkf) << MPLL_FUNC_CNTL_1__CLKF__SHIFT | |
| 2926 | (mpll_param.clkfrac << MPLL_FUNC_CNTL_1__CLKFRAC__SHIFT) | |
| 2927 | (mpll_param.vco_mode << MPLL_FUNC_CNTL_1__VCO_MODE__SHIFT); |
| 2928 | |
| 2929 | mpll_ad_func_cntl &= ~MPLL_AD_FUNC_CNTL__YCLK_POST_DIV_MASK; |
| 2930 | mpll_ad_func_cntl |= (mpll_param.post_div << MPLL_AD_FUNC_CNTL__YCLK_POST_DIV__SHIFT); |
| 2931 | |
Ken Wang | 81c59f5 | 2015-06-03 21:02:01 +0800 | [diff] [blame] | 2932 | if (adev->mc.vram_type == AMDGPU_VRAM_TYPE_GDDR5) { |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 2933 | mpll_dq_func_cntl &= ~(MPLL_DQ_FUNC_CNTL__YCLK_SEL_MASK | |
| 2934 | MPLL_AD_FUNC_CNTL__YCLK_POST_DIV_MASK); |
| 2935 | mpll_dq_func_cntl |= (mpll_param.yclk_sel << MPLL_DQ_FUNC_CNTL__YCLK_SEL__SHIFT) | |
| 2936 | (mpll_param.post_div << MPLL_AD_FUNC_CNTL__YCLK_POST_DIV__SHIFT); |
| 2937 | } |
| 2938 | |
| 2939 | if (pi->caps_mclk_ss_support) { |
| 2940 | struct amdgpu_atom_ss ss; |
| 2941 | u32 freq_nom; |
| 2942 | u32 tmp; |
| 2943 | u32 reference_clock = adev->clock.mpll.reference_freq; |
| 2944 | |
| 2945 | if (mpll_param.qdr == 1) |
| 2946 | freq_nom = memory_clock * 4 * (1 << mpll_param.post_div); |
| 2947 | else |
| 2948 | freq_nom = memory_clock * 2 * (1 << mpll_param.post_div); |
| 2949 | |
| 2950 | tmp = (freq_nom / reference_clock); |
| 2951 | tmp = tmp * tmp; |
| 2952 | if (amdgpu_atombios_get_asic_ss_info(adev, &ss, |
| 2953 | ASIC_INTERNAL_MEMORY_SS, freq_nom)) { |
| 2954 | u32 clks = reference_clock * 5 / ss.rate; |
| 2955 | u32 clkv = (u32)((((131 * ss.percentage * ss.rate) / 100) * tmp) / freq_nom); |
| 2956 | |
| 2957 | mpll_ss1 &= ~MPLL_SS1__CLKV_MASK; |
| 2958 | mpll_ss1 |= (clkv << MPLL_SS1__CLKV__SHIFT); |
| 2959 | |
| 2960 | mpll_ss2 &= ~MPLL_SS2__CLKS_MASK; |
| 2961 | mpll_ss2 |= (clks << MPLL_SS2__CLKS__SHIFT); |
| 2962 | } |
| 2963 | } |
| 2964 | |
| 2965 | mclk_pwrmgt_cntl &= ~MCLK_PWRMGT_CNTL__DLL_SPEED_MASK; |
| 2966 | mclk_pwrmgt_cntl |= (mpll_param.dll_speed << MCLK_PWRMGT_CNTL__DLL_SPEED__SHIFT); |
| 2967 | |
| 2968 | if (dll_state_on) |
| 2969 | mclk_pwrmgt_cntl |= MCLK_PWRMGT_CNTL__MRDCK0_PDNB_MASK | |
| 2970 | MCLK_PWRMGT_CNTL__MRDCK1_PDNB_MASK; |
| 2971 | else |
| 2972 | mclk_pwrmgt_cntl &= ~(MCLK_PWRMGT_CNTL__MRDCK0_PDNB_MASK | |
| 2973 | MCLK_PWRMGT_CNTL__MRDCK1_PDNB_MASK); |
| 2974 | |
| 2975 | mclk->MclkFrequency = memory_clock; |
| 2976 | mclk->MpllFuncCntl = mpll_func_cntl; |
| 2977 | mclk->MpllFuncCntl_1 = mpll_func_cntl_1; |
| 2978 | mclk->MpllFuncCntl_2 = mpll_func_cntl_2; |
| 2979 | mclk->MpllAdFuncCntl = mpll_ad_func_cntl; |
| 2980 | mclk->MpllDqFuncCntl = mpll_dq_func_cntl; |
| 2981 | mclk->MclkPwrmgtCntl = mclk_pwrmgt_cntl; |
| 2982 | mclk->DllCntl = dll_cntl; |
| 2983 | mclk->MpllSs1 = mpll_ss1; |
| 2984 | mclk->MpllSs2 = mpll_ss2; |
| 2985 | |
| 2986 | return 0; |
| 2987 | } |
| 2988 | |
| 2989 | static int ci_populate_single_memory_level(struct amdgpu_device *adev, |
| 2990 | u32 memory_clock, |
| 2991 | SMU7_Discrete_MemoryLevel *memory_level) |
| 2992 | { |
| 2993 | struct ci_power_info *pi = ci_get_pi(adev); |
| 2994 | int ret; |
| 2995 | bool dll_state_on; |
| 2996 | |
| 2997 | if (adev->pm.dpm.dyn_state.vddc_dependency_on_mclk.entries) { |
| 2998 | ret = ci_get_dependency_volt_by_clk(adev, |
| 2999 | &adev->pm.dpm.dyn_state.vddc_dependency_on_mclk, |
| 3000 | memory_clock, &memory_level->MinVddc); |
| 3001 | if (ret) |
| 3002 | return ret; |
| 3003 | } |
| 3004 | |
| 3005 | if (adev->pm.dpm.dyn_state.vddci_dependency_on_mclk.entries) { |
| 3006 | ret = ci_get_dependency_volt_by_clk(adev, |
| 3007 | &adev->pm.dpm.dyn_state.vddci_dependency_on_mclk, |
| 3008 | memory_clock, &memory_level->MinVddci); |
| 3009 | if (ret) |
| 3010 | return ret; |
| 3011 | } |
| 3012 | |
| 3013 | if (adev->pm.dpm.dyn_state.mvdd_dependency_on_mclk.entries) { |
| 3014 | ret = ci_get_dependency_volt_by_clk(adev, |
| 3015 | &adev->pm.dpm.dyn_state.mvdd_dependency_on_mclk, |
| 3016 | memory_clock, &memory_level->MinMvdd); |
| 3017 | if (ret) |
| 3018 | return ret; |
| 3019 | } |
| 3020 | |
| 3021 | memory_level->MinVddcPhases = 1; |
| 3022 | |
| 3023 | if (pi->vddc_phase_shed_control) |
| 3024 | ci_populate_phase_value_based_on_mclk(adev, |
| 3025 | &adev->pm.dpm.dyn_state.phase_shedding_limits_table, |
| 3026 | memory_clock, |
| 3027 | &memory_level->MinVddcPhases); |
| 3028 | |
| 3029 | memory_level->EnabledForThrottle = 1; |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 3030 | memory_level->UpH = 0; |
| 3031 | memory_level->DownH = 100; |
| 3032 | memory_level->VoltageDownH = 0; |
| 3033 | memory_level->ActivityLevel = (u16)pi->mclk_activity_target; |
| 3034 | |
| 3035 | memory_level->StutterEnable = false; |
| 3036 | memory_level->StrobeEnable = false; |
| 3037 | memory_level->EdcReadEnable = false; |
| 3038 | memory_level->EdcWriteEnable = false; |
| 3039 | memory_level->RttEnable = false; |
| 3040 | |
| 3041 | memory_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW; |
| 3042 | |
| 3043 | if (pi->mclk_stutter_mode_threshold && |
| 3044 | (memory_clock <= pi->mclk_stutter_mode_threshold) && |
Edward O'Callaghan | 004e29c | 2016-07-12 10:17:53 +1000 | [diff] [blame] | 3045 | (!pi->uvd_enabled) && |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 3046 | (RREG32(mmDPG_PIPE_STUTTER_CONTROL) & DPG_PIPE_STUTTER_CONTROL__STUTTER_ENABLE_MASK) && |
| 3047 | (adev->pm.dpm.new_active_crtc_count <= 2)) |
| 3048 | memory_level->StutterEnable = true; |
| 3049 | |
| 3050 | if (pi->mclk_strobe_mode_threshold && |
| 3051 | (memory_clock <= pi->mclk_strobe_mode_threshold)) |
| 3052 | memory_level->StrobeEnable = 1; |
| 3053 | |
Ken Wang | 81c59f5 | 2015-06-03 21:02:01 +0800 | [diff] [blame] | 3054 | if (adev->mc.vram_type == AMDGPU_VRAM_TYPE_GDDR5) { |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 3055 | memory_level->StrobeRatio = |
| 3056 | ci_get_mclk_frequency_ratio(memory_clock, memory_level->StrobeEnable); |
| 3057 | if (pi->mclk_edc_enable_threshold && |
| 3058 | (memory_clock > pi->mclk_edc_enable_threshold)) |
| 3059 | memory_level->EdcReadEnable = true; |
| 3060 | |
| 3061 | if (pi->mclk_edc_wr_enable_threshold && |
| 3062 | (memory_clock > pi->mclk_edc_wr_enable_threshold)) |
| 3063 | memory_level->EdcWriteEnable = true; |
| 3064 | |
| 3065 | if (memory_level->StrobeEnable) { |
| 3066 | if (ci_get_mclk_frequency_ratio(memory_clock, true) >= |
| 3067 | ((RREG32(mmMC_SEQ_MISC7) >> 16) & 0xf)) |
| 3068 | dll_state_on = ((RREG32(mmMC_SEQ_MISC5) >> 1) & 0x1) ? true : false; |
| 3069 | else |
| 3070 | dll_state_on = ((RREG32(mmMC_SEQ_MISC6) >> 1) & 0x1) ? true : false; |
| 3071 | } else { |
| 3072 | dll_state_on = pi->dll_default_on; |
| 3073 | } |
| 3074 | } else { |
| 3075 | memory_level->StrobeRatio = ci_get_ddr3_mclk_frequency_ratio(memory_clock); |
| 3076 | dll_state_on = ((RREG32(mmMC_SEQ_MISC5) >> 1) & 0x1) ? true : false; |
| 3077 | } |
| 3078 | |
| 3079 | ret = ci_calculate_mclk_params(adev, memory_clock, memory_level, memory_level->StrobeEnable, dll_state_on); |
| 3080 | if (ret) |
| 3081 | return ret; |
| 3082 | |
| 3083 | memory_level->MinVddc = cpu_to_be32(memory_level->MinVddc * VOLTAGE_SCALE); |
| 3084 | memory_level->MinVddcPhases = cpu_to_be32(memory_level->MinVddcPhases); |
| 3085 | memory_level->MinVddci = cpu_to_be32(memory_level->MinVddci * VOLTAGE_SCALE); |
| 3086 | memory_level->MinMvdd = cpu_to_be32(memory_level->MinMvdd * VOLTAGE_SCALE); |
| 3087 | |
| 3088 | memory_level->MclkFrequency = cpu_to_be32(memory_level->MclkFrequency); |
| 3089 | memory_level->ActivityLevel = cpu_to_be16(memory_level->ActivityLevel); |
| 3090 | memory_level->MpllFuncCntl = cpu_to_be32(memory_level->MpllFuncCntl); |
| 3091 | memory_level->MpllFuncCntl_1 = cpu_to_be32(memory_level->MpllFuncCntl_1); |
| 3092 | memory_level->MpllFuncCntl_2 = cpu_to_be32(memory_level->MpllFuncCntl_2); |
| 3093 | memory_level->MpllAdFuncCntl = cpu_to_be32(memory_level->MpllAdFuncCntl); |
| 3094 | memory_level->MpllDqFuncCntl = cpu_to_be32(memory_level->MpllDqFuncCntl); |
| 3095 | memory_level->MclkPwrmgtCntl = cpu_to_be32(memory_level->MclkPwrmgtCntl); |
| 3096 | memory_level->DllCntl = cpu_to_be32(memory_level->DllCntl); |
| 3097 | memory_level->MpllSs1 = cpu_to_be32(memory_level->MpllSs1); |
| 3098 | memory_level->MpllSs2 = cpu_to_be32(memory_level->MpllSs2); |
| 3099 | |
| 3100 | return 0; |
| 3101 | } |
| 3102 | |
| 3103 | static int ci_populate_smc_acpi_level(struct amdgpu_device *adev, |
| 3104 | SMU7_Discrete_DpmTable *table) |
| 3105 | { |
| 3106 | struct ci_power_info *pi = ci_get_pi(adev); |
| 3107 | struct atom_clock_dividers dividers; |
| 3108 | SMU7_Discrete_VoltageLevel voltage_level; |
| 3109 | u32 spll_func_cntl = pi->clock_registers.cg_spll_func_cntl; |
| 3110 | u32 spll_func_cntl_2 = pi->clock_registers.cg_spll_func_cntl_2; |
| 3111 | u32 dll_cntl = pi->clock_registers.dll_cntl; |
| 3112 | u32 mclk_pwrmgt_cntl = pi->clock_registers.mclk_pwrmgt_cntl; |
| 3113 | int ret; |
| 3114 | |
| 3115 | table->ACPILevel.Flags &= ~PPSMC_SWSTATE_FLAG_DC; |
| 3116 | |
| 3117 | if (pi->acpi_vddc) |
| 3118 | table->ACPILevel.MinVddc = cpu_to_be32(pi->acpi_vddc * VOLTAGE_SCALE); |
| 3119 | else |
| 3120 | table->ACPILevel.MinVddc = cpu_to_be32(pi->min_vddc_in_pp_table * VOLTAGE_SCALE); |
| 3121 | |
| 3122 | table->ACPILevel.MinVddcPhases = pi->vddc_phase_shed_control ? 0 : 1; |
| 3123 | |
| 3124 | table->ACPILevel.SclkFrequency = adev->clock.spll.reference_freq; |
| 3125 | |
| 3126 | ret = amdgpu_atombios_get_clock_dividers(adev, |
| 3127 | COMPUTE_GPUCLK_INPUT_FLAG_SCLK, |
| 3128 | table->ACPILevel.SclkFrequency, false, ÷rs); |
| 3129 | if (ret) |
| 3130 | return ret; |
| 3131 | |
| 3132 | table->ACPILevel.SclkDid = (u8)dividers.post_divider; |
| 3133 | table->ACPILevel.DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW; |
| 3134 | table->ACPILevel.DeepSleepDivId = 0; |
| 3135 | |
| 3136 | spll_func_cntl &= ~CG_SPLL_FUNC_CNTL__SPLL_PWRON_MASK; |
| 3137 | spll_func_cntl |= CG_SPLL_FUNC_CNTL__SPLL_RESET_MASK; |
| 3138 | |
| 3139 | spll_func_cntl_2 &= ~CG_SPLL_FUNC_CNTL_2__SCLK_MUX_SEL_MASK; |
| 3140 | spll_func_cntl_2 |= (4 << CG_SPLL_FUNC_CNTL_2__SCLK_MUX_SEL__SHIFT); |
| 3141 | |
| 3142 | table->ACPILevel.CgSpllFuncCntl = spll_func_cntl; |
| 3143 | table->ACPILevel.CgSpllFuncCntl2 = spll_func_cntl_2; |
| 3144 | table->ACPILevel.CgSpllFuncCntl3 = pi->clock_registers.cg_spll_func_cntl_3; |
| 3145 | table->ACPILevel.CgSpllFuncCntl4 = pi->clock_registers.cg_spll_func_cntl_4; |
| 3146 | table->ACPILevel.SpllSpreadSpectrum = pi->clock_registers.cg_spll_spread_spectrum; |
| 3147 | table->ACPILevel.SpllSpreadSpectrum2 = pi->clock_registers.cg_spll_spread_spectrum_2; |
| 3148 | table->ACPILevel.CcPwrDynRm = 0; |
| 3149 | table->ACPILevel.CcPwrDynRm1 = 0; |
| 3150 | |
| 3151 | table->ACPILevel.Flags = cpu_to_be32(table->ACPILevel.Flags); |
| 3152 | table->ACPILevel.MinVddcPhases = cpu_to_be32(table->ACPILevel.MinVddcPhases); |
| 3153 | table->ACPILevel.SclkFrequency = cpu_to_be32(table->ACPILevel.SclkFrequency); |
| 3154 | table->ACPILevel.CgSpllFuncCntl = cpu_to_be32(table->ACPILevel.CgSpllFuncCntl); |
| 3155 | table->ACPILevel.CgSpllFuncCntl2 = cpu_to_be32(table->ACPILevel.CgSpllFuncCntl2); |
| 3156 | table->ACPILevel.CgSpllFuncCntl3 = cpu_to_be32(table->ACPILevel.CgSpllFuncCntl3); |
| 3157 | table->ACPILevel.CgSpllFuncCntl4 = cpu_to_be32(table->ACPILevel.CgSpllFuncCntl4); |
| 3158 | table->ACPILevel.SpllSpreadSpectrum = cpu_to_be32(table->ACPILevel.SpllSpreadSpectrum); |
| 3159 | table->ACPILevel.SpllSpreadSpectrum2 = cpu_to_be32(table->ACPILevel.SpllSpreadSpectrum2); |
| 3160 | table->ACPILevel.CcPwrDynRm = cpu_to_be32(table->ACPILevel.CcPwrDynRm); |
| 3161 | table->ACPILevel.CcPwrDynRm1 = cpu_to_be32(table->ACPILevel.CcPwrDynRm1); |
| 3162 | |
| 3163 | table->MemoryACPILevel.MinVddc = table->ACPILevel.MinVddc; |
| 3164 | table->MemoryACPILevel.MinVddcPhases = table->ACPILevel.MinVddcPhases; |
| 3165 | |
| 3166 | if (pi->vddci_control != CISLANDS_VOLTAGE_CONTROL_NONE) { |
| 3167 | if (pi->acpi_vddci) |
| 3168 | table->MemoryACPILevel.MinVddci = |
| 3169 | cpu_to_be32(pi->acpi_vddci * VOLTAGE_SCALE); |
| 3170 | else |
| 3171 | table->MemoryACPILevel.MinVddci = |
| 3172 | cpu_to_be32(pi->min_vddci_in_pp_table * VOLTAGE_SCALE); |
| 3173 | } |
| 3174 | |
| 3175 | if (ci_populate_mvdd_value(adev, 0, &voltage_level)) |
| 3176 | table->MemoryACPILevel.MinMvdd = 0; |
| 3177 | else |
| 3178 | table->MemoryACPILevel.MinMvdd = |
| 3179 | cpu_to_be32(voltage_level.Voltage * VOLTAGE_SCALE); |
| 3180 | |
| 3181 | mclk_pwrmgt_cntl |= MCLK_PWRMGT_CNTL__MRDCK0_RESET_MASK | |
| 3182 | MCLK_PWRMGT_CNTL__MRDCK1_RESET_MASK; |
| 3183 | mclk_pwrmgt_cntl &= ~(MCLK_PWRMGT_CNTL__MRDCK0_PDNB_MASK | |
| 3184 | MCLK_PWRMGT_CNTL__MRDCK1_PDNB_MASK); |
| 3185 | |
| 3186 | dll_cntl &= ~(DLL_CNTL__MRDCK0_BYPASS_MASK | DLL_CNTL__MRDCK1_BYPASS_MASK); |
| 3187 | |
| 3188 | table->MemoryACPILevel.DllCntl = cpu_to_be32(dll_cntl); |
| 3189 | table->MemoryACPILevel.MclkPwrmgtCntl = cpu_to_be32(mclk_pwrmgt_cntl); |
| 3190 | table->MemoryACPILevel.MpllAdFuncCntl = |
| 3191 | cpu_to_be32(pi->clock_registers.mpll_ad_func_cntl); |
| 3192 | table->MemoryACPILevel.MpllDqFuncCntl = |
| 3193 | cpu_to_be32(pi->clock_registers.mpll_dq_func_cntl); |
| 3194 | table->MemoryACPILevel.MpllFuncCntl = |
| 3195 | cpu_to_be32(pi->clock_registers.mpll_func_cntl); |
| 3196 | table->MemoryACPILevel.MpllFuncCntl_1 = |
| 3197 | cpu_to_be32(pi->clock_registers.mpll_func_cntl_1); |
| 3198 | table->MemoryACPILevel.MpllFuncCntl_2 = |
| 3199 | cpu_to_be32(pi->clock_registers.mpll_func_cntl_2); |
| 3200 | table->MemoryACPILevel.MpllSs1 = cpu_to_be32(pi->clock_registers.mpll_ss1); |
| 3201 | table->MemoryACPILevel.MpllSs2 = cpu_to_be32(pi->clock_registers.mpll_ss2); |
| 3202 | |
| 3203 | table->MemoryACPILevel.EnabledForThrottle = 0; |
| 3204 | table->MemoryACPILevel.EnabledForActivity = 0; |
| 3205 | table->MemoryACPILevel.UpH = 0; |
| 3206 | table->MemoryACPILevel.DownH = 100; |
| 3207 | table->MemoryACPILevel.VoltageDownH = 0; |
| 3208 | table->MemoryACPILevel.ActivityLevel = |
| 3209 | cpu_to_be16((u16)pi->mclk_activity_target); |
| 3210 | |
| 3211 | table->MemoryACPILevel.StutterEnable = false; |
| 3212 | table->MemoryACPILevel.StrobeEnable = false; |
| 3213 | table->MemoryACPILevel.EdcReadEnable = false; |
| 3214 | table->MemoryACPILevel.EdcWriteEnable = false; |
| 3215 | table->MemoryACPILevel.RttEnable = false; |
| 3216 | |
| 3217 | return 0; |
| 3218 | } |
| 3219 | |
| 3220 | |
| 3221 | static int ci_enable_ulv(struct amdgpu_device *adev, bool enable) |
| 3222 | { |
| 3223 | struct ci_power_info *pi = ci_get_pi(adev); |
| 3224 | struct ci_ulv_parm *ulv = &pi->ulv; |
| 3225 | |
| 3226 | if (ulv->supported) { |
| 3227 | if (enable) |
| 3228 | return (amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_EnableULV) == PPSMC_Result_OK) ? |
| 3229 | 0 : -EINVAL; |
| 3230 | else |
| 3231 | return (amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_DisableULV) == PPSMC_Result_OK) ? |
| 3232 | 0 : -EINVAL; |
| 3233 | } |
| 3234 | |
| 3235 | return 0; |
| 3236 | } |
| 3237 | |
| 3238 | static int ci_populate_ulv_level(struct amdgpu_device *adev, |
| 3239 | SMU7_Discrete_Ulv *state) |
| 3240 | { |
| 3241 | struct ci_power_info *pi = ci_get_pi(adev); |
| 3242 | u16 ulv_voltage = adev->pm.dpm.backbias_response_time; |
| 3243 | |
| 3244 | state->CcPwrDynRm = 0; |
| 3245 | state->CcPwrDynRm1 = 0; |
| 3246 | |
| 3247 | if (ulv_voltage == 0) { |
| 3248 | pi->ulv.supported = false; |
| 3249 | return 0; |
| 3250 | } |
| 3251 | |
| 3252 | if (pi->voltage_control != CISLANDS_VOLTAGE_CONTROL_BY_SVID2) { |
| 3253 | if (ulv_voltage > adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[0].v) |
| 3254 | state->VddcOffset = 0; |
| 3255 | else |
| 3256 | state->VddcOffset = |
| 3257 | adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[0].v - ulv_voltage; |
| 3258 | } else { |
| 3259 | if (ulv_voltage > adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[0].v) |
| 3260 | state->VddcOffsetVid = 0; |
| 3261 | else |
| 3262 | state->VddcOffsetVid = (u8) |
| 3263 | ((adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[0].v - ulv_voltage) * |
| 3264 | VOLTAGE_VID_OFFSET_SCALE2 / VOLTAGE_VID_OFFSET_SCALE1); |
| 3265 | } |
| 3266 | state->VddcPhase = pi->vddc_phase_shed_control ? 0 : 1; |
| 3267 | |
| 3268 | state->CcPwrDynRm = cpu_to_be32(state->CcPwrDynRm); |
| 3269 | state->CcPwrDynRm1 = cpu_to_be32(state->CcPwrDynRm1); |
| 3270 | state->VddcOffset = cpu_to_be16(state->VddcOffset); |
| 3271 | |
| 3272 | return 0; |
| 3273 | } |
| 3274 | |
| 3275 | static int ci_calculate_sclk_params(struct amdgpu_device *adev, |
| 3276 | u32 engine_clock, |
| 3277 | SMU7_Discrete_GraphicsLevel *sclk) |
| 3278 | { |
| 3279 | struct ci_power_info *pi = ci_get_pi(adev); |
| 3280 | struct atom_clock_dividers dividers; |
| 3281 | u32 spll_func_cntl_3 = pi->clock_registers.cg_spll_func_cntl_3; |
| 3282 | u32 spll_func_cntl_4 = pi->clock_registers.cg_spll_func_cntl_4; |
| 3283 | u32 cg_spll_spread_spectrum = pi->clock_registers.cg_spll_spread_spectrum; |
| 3284 | u32 cg_spll_spread_spectrum_2 = pi->clock_registers.cg_spll_spread_spectrum_2; |
| 3285 | u32 reference_clock = adev->clock.spll.reference_freq; |
| 3286 | u32 reference_divider; |
| 3287 | u32 fbdiv; |
| 3288 | int ret; |
| 3289 | |
| 3290 | ret = amdgpu_atombios_get_clock_dividers(adev, |
| 3291 | COMPUTE_GPUCLK_INPUT_FLAG_SCLK, |
| 3292 | engine_clock, false, ÷rs); |
| 3293 | if (ret) |
| 3294 | return ret; |
| 3295 | |
| 3296 | reference_divider = 1 + dividers.ref_div; |
| 3297 | fbdiv = dividers.fb_div & 0x3FFFFFF; |
| 3298 | |
| 3299 | spll_func_cntl_3 &= ~CG_SPLL_FUNC_CNTL_3__SPLL_FB_DIV_MASK; |
| 3300 | spll_func_cntl_3 |= (fbdiv << CG_SPLL_FUNC_CNTL_3__SPLL_FB_DIV__SHIFT); |
| 3301 | spll_func_cntl_3 |= CG_SPLL_FUNC_CNTL_3__SPLL_DITHEN_MASK; |
| 3302 | |
| 3303 | if (pi->caps_sclk_ss_support) { |
| 3304 | struct amdgpu_atom_ss ss; |
| 3305 | u32 vco_freq = engine_clock * dividers.post_div; |
| 3306 | |
| 3307 | if (amdgpu_atombios_get_asic_ss_info(adev, &ss, |
| 3308 | ASIC_INTERNAL_ENGINE_SS, vco_freq)) { |
| 3309 | u32 clk_s = reference_clock * 5 / (reference_divider * ss.rate); |
| 3310 | u32 clk_v = 4 * ss.percentage * fbdiv / (clk_s * 10000); |
| 3311 | |
| 3312 | cg_spll_spread_spectrum &= ~(CG_SPLL_SPREAD_SPECTRUM__CLKS_MASK | CG_SPLL_SPREAD_SPECTRUM__SSEN_MASK); |
| 3313 | cg_spll_spread_spectrum |= (clk_s << CG_SPLL_SPREAD_SPECTRUM__CLKS__SHIFT); |
| 3314 | cg_spll_spread_spectrum |= (1 << CG_SPLL_SPREAD_SPECTRUM__SSEN__SHIFT); |
| 3315 | |
| 3316 | cg_spll_spread_spectrum_2 &= ~CG_SPLL_SPREAD_SPECTRUM_2__CLKV_MASK; |
| 3317 | cg_spll_spread_spectrum_2 |= (clk_v << CG_SPLL_SPREAD_SPECTRUM_2__CLKV__SHIFT); |
| 3318 | } |
| 3319 | } |
| 3320 | |
| 3321 | sclk->SclkFrequency = engine_clock; |
| 3322 | sclk->CgSpllFuncCntl3 = spll_func_cntl_3; |
| 3323 | sclk->CgSpllFuncCntl4 = spll_func_cntl_4; |
| 3324 | sclk->SpllSpreadSpectrum = cg_spll_spread_spectrum; |
| 3325 | sclk->SpllSpreadSpectrum2 = cg_spll_spread_spectrum_2; |
| 3326 | sclk->SclkDid = (u8)dividers.post_divider; |
| 3327 | |
| 3328 | return 0; |
| 3329 | } |
| 3330 | |
| 3331 | static int ci_populate_single_graphic_level(struct amdgpu_device *adev, |
| 3332 | u32 engine_clock, |
| 3333 | u16 sclk_activity_level_t, |
| 3334 | SMU7_Discrete_GraphicsLevel *graphic_level) |
| 3335 | { |
| 3336 | struct ci_power_info *pi = ci_get_pi(adev); |
| 3337 | int ret; |
| 3338 | |
| 3339 | ret = ci_calculate_sclk_params(adev, engine_clock, graphic_level); |
| 3340 | if (ret) |
| 3341 | return ret; |
| 3342 | |
| 3343 | ret = ci_get_dependency_volt_by_clk(adev, |
| 3344 | &adev->pm.dpm.dyn_state.vddc_dependency_on_sclk, |
| 3345 | engine_clock, &graphic_level->MinVddc); |
| 3346 | if (ret) |
| 3347 | return ret; |
| 3348 | |
| 3349 | graphic_level->SclkFrequency = engine_clock; |
| 3350 | |
| 3351 | graphic_level->Flags = 0; |
| 3352 | graphic_level->MinVddcPhases = 1; |
| 3353 | |
| 3354 | if (pi->vddc_phase_shed_control) |
| 3355 | ci_populate_phase_value_based_on_sclk(adev, |
| 3356 | &adev->pm.dpm.dyn_state.phase_shedding_limits_table, |
| 3357 | engine_clock, |
| 3358 | &graphic_level->MinVddcPhases); |
| 3359 | |
| 3360 | graphic_level->ActivityLevel = sclk_activity_level_t; |
| 3361 | |
| 3362 | graphic_level->CcPwrDynRm = 0; |
| 3363 | graphic_level->CcPwrDynRm1 = 0; |
| 3364 | graphic_level->EnabledForThrottle = 1; |
| 3365 | graphic_level->UpH = 0; |
| 3366 | graphic_level->DownH = 0; |
| 3367 | graphic_level->VoltageDownH = 0; |
| 3368 | graphic_level->PowerThrottle = 0; |
| 3369 | |
| 3370 | if (pi->caps_sclk_ds) |
Nils Wallménius | 438498a | 2016-05-05 09:07:48 +0200 | [diff] [blame] | 3371 | graphic_level->DeepSleepDivId = ci_get_sleep_divider_id_from_clock(engine_clock, |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 3372 | CISLAND_MINIMUM_ENGINE_CLOCK); |
| 3373 | |
| 3374 | graphic_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW; |
| 3375 | |
| 3376 | graphic_level->Flags = cpu_to_be32(graphic_level->Flags); |
| 3377 | graphic_level->MinVddc = cpu_to_be32(graphic_level->MinVddc * VOLTAGE_SCALE); |
| 3378 | graphic_level->MinVddcPhases = cpu_to_be32(graphic_level->MinVddcPhases); |
| 3379 | graphic_level->SclkFrequency = cpu_to_be32(graphic_level->SclkFrequency); |
| 3380 | graphic_level->ActivityLevel = cpu_to_be16(graphic_level->ActivityLevel); |
| 3381 | graphic_level->CgSpllFuncCntl3 = cpu_to_be32(graphic_level->CgSpllFuncCntl3); |
| 3382 | graphic_level->CgSpllFuncCntl4 = cpu_to_be32(graphic_level->CgSpllFuncCntl4); |
| 3383 | graphic_level->SpllSpreadSpectrum = cpu_to_be32(graphic_level->SpllSpreadSpectrum); |
| 3384 | graphic_level->SpllSpreadSpectrum2 = cpu_to_be32(graphic_level->SpllSpreadSpectrum2); |
| 3385 | graphic_level->CcPwrDynRm = cpu_to_be32(graphic_level->CcPwrDynRm); |
| 3386 | graphic_level->CcPwrDynRm1 = cpu_to_be32(graphic_level->CcPwrDynRm1); |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 3387 | |
| 3388 | return 0; |
| 3389 | } |
| 3390 | |
| 3391 | static int ci_populate_all_graphic_levels(struct amdgpu_device *adev) |
| 3392 | { |
| 3393 | struct ci_power_info *pi = ci_get_pi(adev); |
| 3394 | struct ci_dpm_table *dpm_table = &pi->dpm_table; |
| 3395 | u32 level_array_address = pi->dpm_table_start + |
| 3396 | offsetof(SMU7_Discrete_DpmTable, GraphicsLevel); |
| 3397 | u32 level_array_size = sizeof(SMU7_Discrete_GraphicsLevel) * |
| 3398 | SMU7_MAX_LEVELS_GRAPHICS; |
| 3399 | SMU7_Discrete_GraphicsLevel *levels = pi->smc_state_table.GraphicsLevel; |
| 3400 | u32 i, ret; |
| 3401 | |
| 3402 | memset(levels, 0, level_array_size); |
| 3403 | |
| 3404 | for (i = 0; i < dpm_table->sclk_table.count; i++) { |
| 3405 | ret = ci_populate_single_graphic_level(adev, |
| 3406 | dpm_table->sclk_table.dpm_levels[i].value, |
| 3407 | (u16)pi->activity_target[i], |
| 3408 | &pi->smc_state_table.GraphicsLevel[i]); |
| 3409 | if (ret) |
| 3410 | return ret; |
| 3411 | if (i > 1) |
| 3412 | pi->smc_state_table.GraphicsLevel[i].DeepSleepDivId = 0; |
| 3413 | if (i == (dpm_table->sclk_table.count - 1)) |
| 3414 | pi->smc_state_table.GraphicsLevel[i].DisplayWatermark = |
| 3415 | PPSMC_DISPLAY_WATERMARK_HIGH; |
| 3416 | } |
Alex Deucher | 4223cc3d | 2016-03-03 12:27:46 -0500 | [diff] [blame] | 3417 | pi->smc_state_table.GraphicsLevel[0].EnabledForActivity = 1; |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 3418 | |
| 3419 | pi->smc_state_table.GraphicsDpmLevelCount = (u8)dpm_table->sclk_table.count; |
| 3420 | pi->dpm_level_enable_mask.sclk_dpm_enable_mask = |
| 3421 | ci_get_dpm_level_enable_mask_value(&dpm_table->sclk_table); |
| 3422 | |
| 3423 | ret = amdgpu_ci_copy_bytes_to_smc(adev, level_array_address, |
| 3424 | (u8 *)levels, level_array_size, |
| 3425 | pi->sram_end); |
| 3426 | if (ret) |
| 3427 | return ret; |
| 3428 | |
| 3429 | return 0; |
| 3430 | } |
| 3431 | |
| 3432 | static int ci_populate_ulv_state(struct amdgpu_device *adev, |
| 3433 | SMU7_Discrete_Ulv *ulv_level) |
| 3434 | { |
| 3435 | return ci_populate_ulv_level(adev, ulv_level); |
| 3436 | } |
| 3437 | |
| 3438 | static int ci_populate_all_memory_levels(struct amdgpu_device *adev) |
| 3439 | { |
| 3440 | struct ci_power_info *pi = ci_get_pi(adev); |
| 3441 | struct ci_dpm_table *dpm_table = &pi->dpm_table; |
| 3442 | u32 level_array_address = pi->dpm_table_start + |
| 3443 | offsetof(SMU7_Discrete_DpmTable, MemoryLevel); |
| 3444 | u32 level_array_size = sizeof(SMU7_Discrete_MemoryLevel) * |
| 3445 | SMU7_MAX_LEVELS_MEMORY; |
| 3446 | SMU7_Discrete_MemoryLevel *levels = pi->smc_state_table.MemoryLevel; |
| 3447 | u32 i, ret; |
| 3448 | |
| 3449 | memset(levels, 0, level_array_size); |
| 3450 | |
| 3451 | for (i = 0; i < dpm_table->mclk_table.count; i++) { |
| 3452 | if (dpm_table->mclk_table.dpm_levels[i].value == 0) |
| 3453 | return -EINVAL; |
| 3454 | ret = ci_populate_single_memory_level(adev, |
| 3455 | dpm_table->mclk_table.dpm_levels[i].value, |
| 3456 | &pi->smc_state_table.MemoryLevel[i]); |
| 3457 | if (ret) |
| 3458 | return ret; |
| 3459 | } |
| 3460 | |
Alex Deucher | 4223cc3d | 2016-03-03 12:27:46 -0500 | [diff] [blame] | 3461 | pi->smc_state_table.MemoryLevel[0].EnabledForActivity = 1; |
| 3462 | |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 3463 | if ((dpm_table->mclk_table.count >= 2) && |
| 3464 | ((adev->pdev->device == 0x67B0) || (adev->pdev->device == 0x67B1))) { |
| 3465 | pi->smc_state_table.MemoryLevel[1].MinVddc = |
| 3466 | pi->smc_state_table.MemoryLevel[0].MinVddc; |
| 3467 | pi->smc_state_table.MemoryLevel[1].MinVddcPhases = |
| 3468 | pi->smc_state_table.MemoryLevel[0].MinVddcPhases; |
| 3469 | } |
| 3470 | |
| 3471 | pi->smc_state_table.MemoryLevel[0].ActivityLevel = cpu_to_be16(0x1F); |
| 3472 | |
| 3473 | pi->smc_state_table.MemoryDpmLevelCount = (u8)dpm_table->mclk_table.count; |
| 3474 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask = |
| 3475 | ci_get_dpm_level_enable_mask_value(&dpm_table->mclk_table); |
| 3476 | |
| 3477 | pi->smc_state_table.MemoryLevel[dpm_table->mclk_table.count - 1].DisplayWatermark = |
| 3478 | PPSMC_DISPLAY_WATERMARK_HIGH; |
| 3479 | |
| 3480 | ret = amdgpu_ci_copy_bytes_to_smc(adev, level_array_address, |
| 3481 | (u8 *)levels, level_array_size, |
| 3482 | pi->sram_end); |
| 3483 | if (ret) |
| 3484 | return ret; |
| 3485 | |
| 3486 | return 0; |
| 3487 | } |
| 3488 | |
| 3489 | static void ci_reset_single_dpm_table(struct amdgpu_device *adev, |
| 3490 | struct ci_single_dpm_table* dpm_table, |
| 3491 | u32 count) |
| 3492 | { |
| 3493 | u32 i; |
| 3494 | |
| 3495 | dpm_table->count = count; |
| 3496 | for (i = 0; i < MAX_REGULAR_DPM_NUMBER; i++) |
| 3497 | dpm_table->dpm_levels[i].enabled = false; |
| 3498 | } |
| 3499 | |
| 3500 | static void ci_setup_pcie_table_entry(struct ci_single_dpm_table* dpm_table, |
| 3501 | u32 index, u32 pcie_gen, u32 pcie_lanes) |
| 3502 | { |
| 3503 | dpm_table->dpm_levels[index].value = pcie_gen; |
| 3504 | dpm_table->dpm_levels[index].param1 = pcie_lanes; |
| 3505 | dpm_table->dpm_levels[index].enabled = true; |
| 3506 | } |
| 3507 | |
| 3508 | static int ci_setup_default_pcie_tables(struct amdgpu_device *adev) |
| 3509 | { |
| 3510 | struct ci_power_info *pi = ci_get_pi(adev); |
| 3511 | |
| 3512 | if (!pi->use_pcie_performance_levels && !pi->use_pcie_powersaving_levels) |
| 3513 | return -EINVAL; |
| 3514 | |
| 3515 | if (pi->use_pcie_performance_levels && !pi->use_pcie_powersaving_levels) { |
| 3516 | pi->pcie_gen_powersaving = pi->pcie_gen_performance; |
| 3517 | pi->pcie_lane_powersaving = pi->pcie_lane_performance; |
| 3518 | } else if (!pi->use_pcie_performance_levels && pi->use_pcie_powersaving_levels) { |
| 3519 | pi->pcie_gen_performance = pi->pcie_gen_powersaving; |
| 3520 | pi->pcie_lane_performance = pi->pcie_lane_powersaving; |
| 3521 | } |
| 3522 | |
| 3523 | ci_reset_single_dpm_table(adev, |
| 3524 | &pi->dpm_table.pcie_speed_table, |
| 3525 | SMU7_MAX_LEVELS_LINK); |
| 3526 | |
| 3527 | if (adev->asic_type == CHIP_BONAIRE) |
| 3528 | ci_setup_pcie_table_entry(&pi->dpm_table.pcie_speed_table, 0, |
| 3529 | pi->pcie_gen_powersaving.min, |
| 3530 | pi->pcie_lane_powersaving.max); |
| 3531 | else |
| 3532 | ci_setup_pcie_table_entry(&pi->dpm_table.pcie_speed_table, 0, |
| 3533 | pi->pcie_gen_powersaving.min, |
| 3534 | pi->pcie_lane_powersaving.min); |
| 3535 | ci_setup_pcie_table_entry(&pi->dpm_table.pcie_speed_table, 1, |
| 3536 | pi->pcie_gen_performance.min, |
| 3537 | pi->pcie_lane_performance.min); |
| 3538 | ci_setup_pcie_table_entry(&pi->dpm_table.pcie_speed_table, 2, |
| 3539 | pi->pcie_gen_powersaving.min, |
| 3540 | pi->pcie_lane_powersaving.max); |
| 3541 | ci_setup_pcie_table_entry(&pi->dpm_table.pcie_speed_table, 3, |
| 3542 | pi->pcie_gen_performance.min, |
| 3543 | pi->pcie_lane_performance.max); |
| 3544 | ci_setup_pcie_table_entry(&pi->dpm_table.pcie_speed_table, 4, |
| 3545 | pi->pcie_gen_powersaving.max, |
| 3546 | pi->pcie_lane_powersaving.max); |
| 3547 | ci_setup_pcie_table_entry(&pi->dpm_table.pcie_speed_table, 5, |
| 3548 | pi->pcie_gen_performance.max, |
| 3549 | pi->pcie_lane_performance.max); |
| 3550 | |
| 3551 | pi->dpm_table.pcie_speed_table.count = 6; |
| 3552 | |
| 3553 | return 0; |
| 3554 | } |
| 3555 | |
| 3556 | static int ci_setup_default_dpm_tables(struct amdgpu_device *adev) |
| 3557 | { |
| 3558 | struct ci_power_info *pi = ci_get_pi(adev); |
| 3559 | struct amdgpu_clock_voltage_dependency_table *allowed_sclk_vddc_table = |
| 3560 | &adev->pm.dpm.dyn_state.vddc_dependency_on_sclk; |
| 3561 | struct amdgpu_clock_voltage_dependency_table *allowed_mclk_table = |
| 3562 | &adev->pm.dpm.dyn_state.vddc_dependency_on_mclk; |
| 3563 | struct amdgpu_cac_leakage_table *std_voltage_table = |
| 3564 | &adev->pm.dpm.dyn_state.cac_leakage_table; |
| 3565 | u32 i; |
| 3566 | |
| 3567 | if (allowed_sclk_vddc_table == NULL) |
| 3568 | return -EINVAL; |
| 3569 | if (allowed_sclk_vddc_table->count < 1) |
| 3570 | return -EINVAL; |
| 3571 | if (allowed_mclk_table == NULL) |
| 3572 | return -EINVAL; |
| 3573 | if (allowed_mclk_table->count < 1) |
| 3574 | return -EINVAL; |
| 3575 | |
| 3576 | memset(&pi->dpm_table, 0, sizeof(struct ci_dpm_table)); |
| 3577 | |
| 3578 | ci_reset_single_dpm_table(adev, |
| 3579 | &pi->dpm_table.sclk_table, |
| 3580 | SMU7_MAX_LEVELS_GRAPHICS); |
| 3581 | ci_reset_single_dpm_table(adev, |
| 3582 | &pi->dpm_table.mclk_table, |
| 3583 | SMU7_MAX_LEVELS_MEMORY); |
| 3584 | ci_reset_single_dpm_table(adev, |
| 3585 | &pi->dpm_table.vddc_table, |
| 3586 | SMU7_MAX_LEVELS_VDDC); |
| 3587 | ci_reset_single_dpm_table(adev, |
| 3588 | &pi->dpm_table.vddci_table, |
| 3589 | SMU7_MAX_LEVELS_VDDCI); |
| 3590 | ci_reset_single_dpm_table(adev, |
| 3591 | &pi->dpm_table.mvdd_table, |
| 3592 | SMU7_MAX_LEVELS_MVDD); |
| 3593 | |
| 3594 | pi->dpm_table.sclk_table.count = 0; |
| 3595 | for (i = 0; i < allowed_sclk_vddc_table->count; i++) { |
| 3596 | if ((i == 0) || |
| 3597 | (pi->dpm_table.sclk_table.dpm_levels[pi->dpm_table.sclk_table.count-1].value != |
| 3598 | allowed_sclk_vddc_table->entries[i].clk)) { |
| 3599 | pi->dpm_table.sclk_table.dpm_levels[pi->dpm_table.sclk_table.count].value = |
| 3600 | allowed_sclk_vddc_table->entries[i].clk; |
| 3601 | pi->dpm_table.sclk_table.dpm_levels[pi->dpm_table.sclk_table.count].enabled = |
| 3602 | (i == 0) ? true : false; |
| 3603 | pi->dpm_table.sclk_table.count++; |
| 3604 | } |
| 3605 | } |
| 3606 | |
| 3607 | pi->dpm_table.mclk_table.count = 0; |
| 3608 | for (i = 0; i < allowed_mclk_table->count; i++) { |
| 3609 | if ((i == 0) || |
| 3610 | (pi->dpm_table.mclk_table.dpm_levels[pi->dpm_table.mclk_table.count-1].value != |
| 3611 | allowed_mclk_table->entries[i].clk)) { |
| 3612 | pi->dpm_table.mclk_table.dpm_levels[pi->dpm_table.mclk_table.count].value = |
| 3613 | allowed_mclk_table->entries[i].clk; |
| 3614 | pi->dpm_table.mclk_table.dpm_levels[pi->dpm_table.mclk_table.count].enabled = |
| 3615 | (i == 0) ? true : false; |
| 3616 | pi->dpm_table.mclk_table.count++; |
| 3617 | } |
| 3618 | } |
| 3619 | |
| 3620 | for (i = 0; i < allowed_sclk_vddc_table->count; i++) { |
| 3621 | pi->dpm_table.vddc_table.dpm_levels[i].value = |
| 3622 | allowed_sclk_vddc_table->entries[i].v; |
| 3623 | pi->dpm_table.vddc_table.dpm_levels[i].param1 = |
| 3624 | std_voltage_table->entries[i].leakage; |
| 3625 | pi->dpm_table.vddc_table.dpm_levels[i].enabled = true; |
| 3626 | } |
| 3627 | pi->dpm_table.vddc_table.count = allowed_sclk_vddc_table->count; |
| 3628 | |
| 3629 | allowed_mclk_table = &adev->pm.dpm.dyn_state.vddci_dependency_on_mclk; |
| 3630 | if (allowed_mclk_table) { |
| 3631 | for (i = 0; i < allowed_mclk_table->count; i++) { |
| 3632 | pi->dpm_table.vddci_table.dpm_levels[i].value = |
| 3633 | allowed_mclk_table->entries[i].v; |
| 3634 | pi->dpm_table.vddci_table.dpm_levels[i].enabled = true; |
| 3635 | } |
| 3636 | pi->dpm_table.vddci_table.count = allowed_mclk_table->count; |
| 3637 | } |
| 3638 | |
| 3639 | allowed_mclk_table = &adev->pm.dpm.dyn_state.mvdd_dependency_on_mclk; |
| 3640 | if (allowed_mclk_table) { |
| 3641 | for (i = 0; i < allowed_mclk_table->count; i++) { |
| 3642 | pi->dpm_table.mvdd_table.dpm_levels[i].value = |
| 3643 | allowed_mclk_table->entries[i].v; |
| 3644 | pi->dpm_table.mvdd_table.dpm_levels[i].enabled = true; |
| 3645 | } |
| 3646 | pi->dpm_table.mvdd_table.count = allowed_mclk_table->count; |
| 3647 | } |
| 3648 | |
| 3649 | ci_setup_default_pcie_tables(adev); |
| 3650 | |
Eric Huang | 3cc2591 | 2016-05-19 15:54:35 -0400 | [diff] [blame] | 3651 | /* save a copy of the default DPM table */ |
| 3652 | memcpy(&(pi->golden_dpm_table), &(pi->dpm_table), |
| 3653 | sizeof(struct ci_dpm_table)); |
| 3654 | |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 3655 | return 0; |
| 3656 | } |
| 3657 | |
| 3658 | static int ci_find_boot_level(struct ci_single_dpm_table *table, |
| 3659 | u32 value, u32 *boot_level) |
| 3660 | { |
| 3661 | u32 i; |
| 3662 | int ret = -EINVAL; |
| 3663 | |
| 3664 | for(i = 0; i < table->count; i++) { |
| 3665 | if (value == table->dpm_levels[i].value) { |
| 3666 | *boot_level = i; |
| 3667 | ret = 0; |
| 3668 | } |
| 3669 | } |
| 3670 | |
| 3671 | return ret; |
| 3672 | } |
| 3673 | |
| 3674 | static int ci_init_smc_table(struct amdgpu_device *adev) |
| 3675 | { |
| 3676 | struct ci_power_info *pi = ci_get_pi(adev); |
| 3677 | struct ci_ulv_parm *ulv = &pi->ulv; |
| 3678 | struct amdgpu_ps *amdgpu_boot_state = adev->pm.dpm.boot_ps; |
| 3679 | SMU7_Discrete_DpmTable *table = &pi->smc_state_table; |
| 3680 | int ret; |
| 3681 | |
| 3682 | ret = ci_setup_default_dpm_tables(adev); |
| 3683 | if (ret) |
| 3684 | return ret; |
| 3685 | |
| 3686 | if (pi->voltage_control != CISLANDS_VOLTAGE_CONTROL_NONE) |
| 3687 | ci_populate_smc_voltage_tables(adev, table); |
| 3688 | |
| 3689 | ci_init_fps_limits(adev); |
| 3690 | |
| 3691 | if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_HARDWAREDC) |
| 3692 | table->SystemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC; |
| 3693 | |
| 3694 | if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_STEPVDDC) |
| 3695 | table->SystemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC; |
| 3696 | |
Ken Wang | 81c59f5 | 2015-06-03 21:02:01 +0800 | [diff] [blame] | 3697 | if (adev->mc.vram_type == AMDGPU_VRAM_TYPE_GDDR5) |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 3698 | table->SystemFlags |= PPSMC_SYSTEMFLAG_GDDR5; |
| 3699 | |
| 3700 | if (ulv->supported) { |
| 3701 | ret = ci_populate_ulv_state(adev, &pi->smc_state_table.Ulv); |
| 3702 | if (ret) |
| 3703 | return ret; |
| 3704 | WREG32_SMC(ixCG_ULV_PARAMETER, ulv->cg_ulv_parameter); |
| 3705 | } |
| 3706 | |
| 3707 | ret = ci_populate_all_graphic_levels(adev); |
| 3708 | if (ret) |
| 3709 | return ret; |
| 3710 | |
| 3711 | ret = ci_populate_all_memory_levels(adev); |
| 3712 | if (ret) |
| 3713 | return ret; |
| 3714 | |
| 3715 | ci_populate_smc_link_level(adev, table); |
| 3716 | |
| 3717 | ret = ci_populate_smc_acpi_level(adev, table); |
| 3718 | if (ret) |
| 3719 | return ret; |
| 3720 | |
| 3721 | ret = ci_populate_smc_vce_level(adev, table); |
| 3722 | if (ret) |
| 3723 | return ret; |
| 3724 | |
| 3725 | ret = ci_populate_smc_acp_level(adev, table); |
| 3726 | if (ret) |
| 3727 | return ret; |
| 3728 | |
| 3729 | ret = ci_populate_smc_samu_level(adev, table); |
| 3730 | if (ret) |
| 3731 | return ret; |
| 3732 | |
| 3733 | ret = ci_do_program_memory_timing_parameters(adev); |
| 3734 | if (ret) |
| 3735 | return ret; |
| 3736 | |
| 3737 | ret = ci_populate_smc_uvd_level(adev, table); |
| 3738 | if (ret) |
| 3739 | return ret; |
| 3740 | |
| 3741 | table->UvdBootLevel = 0; |
| 3742 | table->VceBootLevel = 0; |
| 3743 | table->AcpBootLevel = 0; |
| 3744 | table->SamuBootLevel = 0; |
| 3745 | table->GraphicsBootLevel = 0; |
| 3746 | table->MemoryBootLevel = 0; |
| 3747 | |
| 3748 | ret = ci_find_boot_level(&pi->dpm_table.sclk_table, |
| 3749 | pi->vbios_boot_state.sclk_bootup_value, |
| 3750 | (u32 *)&pi->smc_state_table.GraphicsBootLevel); |
| 3751 | |
| 3752 | ret = ci_find_boot_level(&pi->dpm_table.mclk_table, |
| 3753 | pi->vbios_boot_state.mclk_bootup_value, |
| 3754 | (u32 *)&pi->smc_state_table.MemoryBootLevel); |
| 3755 | |
| 3756 | table->BootVddc = pi->vbios_boot_state.vddc_bootup_value; |
| 3757 | table->BootVddci = pi->vbios_boot_state.vddci_bootup_value; |
| 3758 | table->BootMVdd = pi->vbios_boot_state.mvdd_bootup_value; |
| 3759 | |
| 3760 | ci_populate_smc_initial_state(adev, amdgpu_boot_state); |
| 3761 | |
| 3762 | ret = ci_populate_bapm_parameters_in_dpm_table(adev); |
| 3763 | if (ret) |
| 3764 | return ret; |
| 3765 | |
| 3766 | table->UVDInterval = 1; |
| 3767 | table->VCEInterval = 1; |
| 3768 | table->ACPInterval = 1; |
| 3769 | table->SAMUInterval = 1; |
| 3770 | table->GraphicsVoltageChangeEnable = 1; |
| 3771 | table->GraphicsThermThrottleEnable = 1; |
| 3772 | table->GraphicsInterval = 1; |
| 3773 | table->VoltageInterval = 1; |
| 3774 | table->ThermalInterval = 1; |
| 3775 | table->TemperatureLimitHigh = (u16)((pi->thermal_temp_setting.temperature_high * |
| 3776 | CISLANDS_Q88_FORMAT_CONVERSION_UNIT) / 1000); |
| 3777 | table->TemperatureLimitLow = (u16)((pi->thermal_temp_setting.temperature_low * |
| 3778 | CISLANDS_Q88_FORMAT_CONVERSION_UNIT) / 1000); |
| 3779 | table->MemoryVoltageChangeEnable = 1; |
| 3780 | table->MemoryInterval = 1; |
| 3781 | table->VoltageResponseTime = 0; |
| 3782 | table->VddcVddciDelta = 4000; |
| 3783 | table->PhaseResponseTime = 0; |
| 3784 | table->MemoryThermThrottleEnable = 1; |
| 3785 | table->PCIeBootLinkLevel = pi->dpm_table.pcie_speed_table.count - 1; |
| 3786 | table->PCIeGenInterval = 1; |
| 3787 | if (pi->voltage_control == CISLANDS_VOLTAGE_CONTROL_BY_SVID2) |
| 3788 | table->SVI2Enable = 1; |
| 3789 | else |
| 3790 | table->SVI2Enable = 0; |
| 3791 | |
| 3792 | table->ThermGpio = 17; |
| 3793 | table->SclkStepSize = 0x4000; |
| 3794 | |
| 3795 | table->SystemFlags = cpu_to_be32(table->SystemFlags); |
| 3796 | table->SmioMaskVddcVid = cpu_to_be32(table->SmioMaskVddcVid); |
| 3797 | table->SmioMaskVddcPhase = cpu_to_be32(table->SmioMaskVddcPhase); |
| 3798 | table->SmioMaskVddciVid = cpu_to_be32(table->SmioMaskVddciVid); |
| 3799 | table->SmioMaskMvddVid = cpu_to_be32(table->SmioMaskMvddVid); |
| 3800 | table->SclkStepSize = cpu_to_be32(table->SclkStepSize); |
| 3801 | table->TemperatureLimitHigh = cpu_to_be16(table->TemperatureLimitHigh); |
| 3802 | table->TemperatureLimitLow = cpu_to_be16(table->TemperatureLimitLow); |
| 3803 | table->VddcVddciDelta = cpu_to_be16(table->VddcVddciDelta); |
| 3804 | table->VoltageResponseTime = cpu_to_be16(table->VoltageResponseTime); |
| 3805 | table->PhaseResponseTime = cpu_to_be16(table->PhaseResponseTime); |
| 3806 | table->BootVddc = cpu_to_be16(table->BootVddc * VOLTAGE_SCALE); |
| 3807 | table->BootVddci = cpu_to_be16(table->BootVddci * VOLTAGE_SCALE); |
| 3808 | table->BootMVdd = cpu_to_be16(table->BootMVdd * VOLTAGE_SCALE); |
| 3809 | |
| 3810 | ret = amdgpu_ci_copy_bytes_to_smc(adev, |
| 3811 | pi->dpm_table_start + |
| 3812 | offsetof(SMU7_Discrete_DpmTable, SystemFlags), |
| 3813 | (u8 *)&table->SystemFlags, |
| 3814 | sizeof(SMU7_Discrete_DpmTable) - 3 * sizeof(SMU7_PIDController), |
| 3815 | pi->sram_end); |
| 3816 | if (ret) |
| 3817 | return ret; |
| 3818 | |
| 3819 | return 0; |
| 3820 | } |
| 3821 | |
| 3822 | static void ci_trim_single_dpm_states(struct amdgpu_device *adev, |
| 3823 | struct ci_single_dpm_table *dpm_table, |
| 3824 | u32 low_limit, u32 high_limit) |
| 3825 | { |
| 3826 | u32 i; |
| 3827 | |
| 3828 | for (i = 0; i < dpm_table->count; i++) { |
| 3829 | if ((dpm_table->dpm_levels[i].value < low_limit) || |
| 3830 | (dpm_table->dpm_levels[i].value > high_limit)) |
| 3831 | dpm_table->dpm_levels[i].enabled = false; |
| 3832 | else |
| 3833 | dpm_table->dpm_levels[i].enabled = true; |
| 3834 | } |
| 3835 | } |
| 3836 | |
| 3837 | static void ci_trim_pcie_dpm_states(struct amdgpu_device *adev, |
| 3838 | u32 speed_low, u32 lanes_low, |
| 3839 | u32 speed_high, u32 lanes_high) |
| 3840 | { |
| 3841 | struct ci_power_info *pi = ci_get_pi(adev); |
| 3842 | struct ci_single_dpm_table *pcie_table = &pi->dpm_table.pcie_speed_table; |
| 3843 | u32 i, j; |
| 3844 | |
| 3845 | for (i = 0; i < pcie_table->count; i++) { |
| 3846 | if ((pcie_table->dpm_levels[i].value < speed_low) || |
| 3847 | (pcie_table->dpm_levels[i].param1 < lanes_low) || |
| 3848 | (pcie_table->dpm_levels[i].value > speed_high) || |
| 3849 | (pcie_table->dpm_levels[i].param1 > lanes_high)) |
| 3850 | pcie_table->dpm_levels[i].enabled = false; |
| 3851 | else |
| 3852 | pcie_table->dpm_levels[i].enabled = true; |
| 3853 | } |
| 3854 | |
| 3855 | for (i = 0; i < pcie_table->count; i++) { |
| 3856 | if (pcie_table->dpm_levels[i].enabled) { |
| 3857 | for (j = i + 1; j < pcie_table->count; j++) { |
| 3858 | if (pcie_table->dpm_levels[j].enabled) { |
| 3859 | if ((pcie_table->dpm_levels[i].value == pcie_table->dpm_levels[j].value) && |
| 3860 | (pcie_table->dpm_levels[i].param1 == pcie_table->dpm_levels[j].param1)) |
| 3861 | pcie_table->dpm_levels[j].enabled = false; |
| 3862 | } |
| 3863 | } |
| 3864 | } |
| 3865 | } |
| 3866 | } |
| 3867 | |
| 3868 | static int ci_trim_dpm_states(struct amdgpu_device *adev, |
| 3869 | struct amdgpu_ps *amdgpu_state) |
| 3870 | { |
| 3871 | struct ci_ps *state = ci_get_ps(amdgpu_state); |
| 3872 | struct ci_power_info *pi = ci_get_pi(adev); |
| 3873 | u32 high_limit_count; |
| 3874 | |
| 3875 | if (state->performance_level_count < 1) |
| 3876 | return -EINVAL; |
| 3877 | |
| 3878 | if (state->performance_level_count == 1) |
| 3879 | high_limit_count = 0; |
| 3880 | else |
| 3881 | high_limit_count = 1; |
| 3882 | |
| 3883 | ci_trim_single_dpm_states(adev, |
| 3884 | &pi->dpm_table.sclk_table, |
| 3885 | state->performance_levels[0].sclk, |
| 3886 | state->performance_levels[high_limit_count].sclk); |
| 3887 | |
| 3888 | ci_trim_single_dpm_states(adev, |
| 3889 | &pi->dpm_table.mclk_table, |
| 3890 | state->performance_levels[0].mclk, |
| 3891 | state->performance_levels[high_limit_count].mclk); |
| 3892 | |
| 3893 | ci_trim_pcie_dpm_states(adev, |
| 3894 | state->performance_levels[0].pcie_gen, |
| 3895 | state->performance_levels[0].pcie_lane, |
| 3896 | state->performance_levels[high_limit_count].pcie_gen, |
| 3897 | state->performance_levels[high_limit_count].pcie_lane); |
| 3898 | |
| 3899 | return 0; |
| 3900 | } |
| 3901 | |
| 3902 | static int ci_apply_disp_minimum_voltage_request(struct amdgpu_device *adev) |
| 3903 | { |
| 3904 | struct amdgpu_clock_voltage_dependency_table *disp_voltage_table = |
| 3905 | &adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk; |
| 3906 | struct amdgpu_clock_voltage_dependency_table *vddc_table = |
| 3907 | &adev->pm.dpm.dyn_state.vddc_dependency_on_sclk; |
| 3908 | u32 requested_voltage = 0; |
| 3909 | u32 i; |
| 3910 | |
| 3911 | if (disp_voltage_table == NULL) |
| 3912 | return -EINVAL; |
| 3913 | if (!disp_voltage_table->count) |
| 3914 | return -EINVAL; |
| 3915 | |
| 3916 | for (i = 0; i < disp_voltage_table->count; i++) { |
| 3917 | if (adev->clock.current_dispclk == disp_voltage_table->entries[i].clk) |
| 3918 | requested_voltage = disp_voltage_table->entries[i].v; |
| 3919 | } |
| 3920 | |
| 3921 | for (i = 0; i < vddc_table->count; i++) { |
| 3922 | if (requested_voltage <= vddc_table->entries[i].v) { |
| 3923 | requested_voltage = vddc_table->entries[i].v; |
| 3924 | return (amdgpu_ci_send_msg_to_smc_with_parameter(adev, |
| 3925 | PPSMC_MSG_VddC_Request, |
| 3926 | requested_voltage * VOLTAGE_SCALE) == PPSMC_Result_OK) ? |
| 3927 | 0 : -EINVAL; |
| 3928 | } |
| 3929 | } |
| 3930 | |
| 3931 | return -EINVAL; |
| 3932 | } |
| 3933 | |
| 3934 | static int ci_upload_dpm_level_enable_mask(struct amdgpu_device *adev) |
| 3935 | { |
| 3936 | struct ci_power_info *pi = ci_get_pi(adev); |
| 3937 | PPSMC_Result result; |
| 3938 | |
| 3939 | ci_apply_disp_minimum_voltage_request(adev); |
| 3940 | |
| 3941 | if (!pi->sclk_dpm_key_disabled) { |
| 3942 | if (pi->dpm_level_enable_mask.sclk_dpm_enable_mask) { |
| 3943 | result = amdgpu_ci_send_msg_to_smc_with_parameter(adev, |
| 3944 | PPSMC_MSG_SCLKDPM_SetEnabledMask, |
| 3945 | pi->dpm_level_enable_mask.sclk_dpm_enable_mask); |
| 3946 | if (result != PPSMC_Result_OK) |
| 3947 | return -EINVAL; |
| 3948 | } |
| 3949 | } |
| 3950 | |
| 3951 | if (!pi->mclk_dpm_key_disabled) { |
| 3952 | if (pi->dpm_level_enable_mask.mclk_dpm_enable_mask) { |
| 3953 | result = amdgpu_ci_send_msg_to_smc_with_parameter(adev, |
| 3954 | PPSMC_MSG_MCLKDPM_SetEnabledMask, |
| 3955 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask); |
| 3956 | if (result != PPSMC_Result_OK) |
| 3957 | return -EINVAL; |
| 3958 | } |
| 3959 | } |
| 3960 | |
| 3961 | #if 0 |
| 3962 | if (!pi->pcie_dpm_key_disabled) { |
| 3963 | if (pi->dpm_level_enable_mask.pcie_dpm_enable_mask) { |
| 3964 | result = amdgpu_ci_send_msg_to_smc_with_parameter(adev, |
| 3965 | PPSMC_MSG_PCIeDPM_SetEnabledMask, |
| 3966 | pi->dpm_level_enable_mask.pcie_dpm_enable_mask); |
| 3967 | if (result != PPSMC_Result_OK) |
| 3968 | return -EINVAL; |
| 3969 | } |
| 3970 | } |
| 3971 | #endif |
| 3972 | |
| 3973 | return 0; |
| 3974 | } |
| 3975 | |
| 3976 | static void ci_find_dpm_states_clocks_in_dpm_table(struct amdgpu_device *adev, |
| 3977 | struct amdgpu_ps *amdgpu_state) |
| 3978 | { |
| 3979 | struct ci_power_info *pi = ci_get_pi(adev); |
| 3980 | struct ci_ps *state = ci_get_ps(amdgpu_state); |
| 3981 | struct ci_single_dpm_table *sclk_table = &pi->dpm_table.sclk_table; |
| 3982 | u32 sclk = state->performance_levels[state->performance_level_count-1].sclk; |
| 3983 | struct ci_single_dpm_table *mclk_table = &pi->dpm_table.mclk_table; |
| 3984 | u32 mclk = state->performance_levels[state->performance_level_count-1].mclk; |
| 3985 | u32 i; |
| 3986 | |
| 3987 | pi->need_update_smu7_dpm_table = 0; |
| 3988 | |
| 3989 | for (i = 0; i < sclk_table->count; i++) { |
| 3990 | if (sclk == sclk_table->dpm_levels[i].value) |
| 3991 | break; |
| 3992 | } |
| 3993 | |
| 3994 | if (i >= sclk_table->count) { |
| 3995 | pi->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK; |
| 3996 | } else { |
| 3997 | /* XXX check display min clock requirements */ |
| 3998 | if (CISLAND_MINIMUM_ENGINE_CLOCK != CISLAND_MINIMUM_ENGINE_CLOCK) |
| 3999 | pi->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_SCLK; |
| 4000 | } |
| 4001 | |
| 4002 | for (i = 0; i < mclk_table->count; i++) { |
| 4003 | if (mclk == mclk_table->dpm_levels[i].value) |
| 4004 | break; |
| 4005 | } |
| 4006 | |
| 4007 | if (i >= mclk_table->count) |
| 4008 | pi->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_MCLK; |
| 4009 | |
| 4010 | if (adev->pm.dpm.current_active_crtc_count != |
| 4011 | adev->pm.dpm.new_active_crtc_count) |
| 4012 | pi->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_MCLK; |
| 4013 | } |
| 4014 | |
| 4015 | static int ci_populate_and_upload_sclk_mclk_dpm_levels(struct amdgpu_device *adev, |
| 4016 | struct amdgpu_ps *amdgpu_state) |
| 4017 | { |
| 4018 | struct ci_power_info *pi = ci_get_pi(adev); |
| 4019 | struct ci_ps *state = ci_get_ps(amdgpu_state); |
| 4020 | u32 sclk = state->performance_levels[state->performance_level_count-1].sclk; |
| 4021 | u32 mclk = state->performance_levels[state->performance_level_count-1].mclk; |
| 4022 | struct ci_dpm_table *dpm_table = &pi->dpm_table; |
| 4023 | int ret; |
| 4024 | |
| 4025 | if (!pi->need_update_smu7_dpm_table) |
| 4026 | return 0; |
| 4027 | |
| 4028 | if (pi->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_SCLK) |
| 4029 | dpm_table->sclk_table.dpm_levels[dpm_table->sclk_table.count-1].value = sclk; |
| 4030 | |
| 4031 | if (pi->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK) |
| 4032 | dpm_table->mclk_table.dpm_levels[dpm_table->mclk_table.count-1].value = mclk; |
| 4033 | |
| 4034 | if (pi->need_update_smu7_dpm_table & (DPMTABLE_OD_UPDATE_SCLK | DPMTABLE_UPDATE_SCLK)) { |
| 4035 | ret = ci_populate_all_graphic_levels(adev); |
| 4036 | if (ret) |
| 4037 | return ret; |
| 4038 | } |
| 4039 | |
| 4040 | if (pi->need_update_smu7_dpm_table & (DPMTABLE_OD_UPDATE_MCLK | DPMTABLE_UPDATE_MCLK)) { |
| 4041 | ret = ci_populate_all_memory_levels(adev); |
| 4042 | if (ret) |
| 4043 | return ret; |
| 4044 | } |
| 4045 | |
| 4046 | return 0; |
| 4047 | } |
| 4048 | |
| 4049 | static int ci_enable_uvd_dpm(struct amdgpu_device *adev, bool enable) |
| 4050 | { |
| 4051 | struct ci_power_info *pi = ci_get_pi(adev); |
| 4052 | const struct amdgpu_clock_and_voltage_limits *max_limits; |
| 4053 | int i; |
| 4054 | |
| 4055 | if (adev->pm.dpm.ac_power) |
| 4056 | max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_ac; |
| 4057 | else |
| 4058 | max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_dc; |
| 4059 | |
| 4060 | if (enable) { |
| 4061 | pi->dpm_level_enable_mask.uvd_dpm_enable_mask = 0; |
| 4062 | |
| 4063 | for (i = adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.count - 1; i >= 0; i--) { |
| 4064 | if (adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[i].v <= max_limits->vddc) { |
| 4065 | pi->dpm_level_enable_mask.uvd_dpm_enable_mask |= 1 << i; |
| 4066 | |
| 4067 | if (!pi->caps_uvd_dpm) |
| 4068 | break; |
| 4069 | } |
| 4070 | } |
| 4071 | |
| 4072 | amdgpu_ci_send_msg_to_smc_with_parameter(adev, |
| 4073 | PPSMC_MSG_UVDDPM_SetEnabledMask, |
| 4074 | pi->dpm_level_enable_mask.uvd_dpm_enable_mask); |
| 4075 | |
| 4076 | if (pi->last_mclk_dpm_enable_mask & 0x1) { |
| 4077 | pi->uvd_enabled = true; |
| 4078 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask &= 0xFFFFFFFE; |
| 4079 | amdgpu_ci_send_msg_to_smc_with_parameter(adev, |
| 4080 | PPSMC_MSG_MCLKDPM_SetEnabledMask, |
| 4081 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask); |
| 4082 | } |
| 4083 | } else { |
Rex Zhu | 49a5d73 | 2016-10-21 16:55:02 +0800 | [diff] [blame] | 4084 | if (pi->uvd_enabled) { |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 4085 | pi->uvd_enabled = false; |
| 4086 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask |= 1; |
| 4087 | amdgpu_ci_send_msg_to_smc_with_parameter(adev, |
| 4088 | PPSMC_MSG_MCLKDPM_SetEnabledMask, |
| 4089 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask); |
| 4090 | } |
| 4091 | } |
| 4092 | |
| 4093 | return (amdgpu_ci_send_msg_to_smc(adev, enable ? |
| 4094 | PPSMC_MSG_UVDDPM_Enable : PPSMC_MSG_UVDDPM_Disable) == PPSMC_Result_OK) ? |
| 4095 | 0 : -EINVAL; |
| 4096 | } |
| 4097 | |
| 4098 | static int ci_enable_vce_dpm(struct amdgpu_device *adev, bool enable) |
| 4099 | { |
| 4100 | struct ci_power_info *pi = ci_get_pi(adev); |
| 4101 | const struct amdgpu_clock_and_voltage_limits *max_limits; |
| 4102 | int i; |
| 4103 | |
| 4104 | if (adev->pm.dpm.ac_power) |
| 4105 | max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_ac; |
| 4106 | else |
| 4107 | max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_dc; |
| 4108 | |
| 4109 | if (enable) { |
| 4110 | pi->dpm_level_enable_mask.vce_dpm_enable_mask = 0; |
| 4111 | for (i = adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.count - 1; i >= 0; i--) { |
| 4112 | if (adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries[i].v <= max_limits->vddc) { |
| 4113 | pi->dpm_level_enable_mask.vce_dpm_enable_mask |= 1 << i; |
| 4114 | |
| 4115 | if (!pi->caps_vce_dpm) |
| 4116 | break; |
| 4117 | } |
| 4118 | } |
| 4119 | |
| 4120 | amdgpu_ci_send_msg_to_smc_with_parameter(adev, |
| 4121 | PPSMC_MSG_VCEDPM_SetEnabledMask, |
| 4122 | pi->dpm_level_enable_mask.vce_dpm_enable_mask); |
| 4123 | } |
| 4124 | |
| 4125 | return (amdgpu_ci_send_msg_to_smc(adev, enable ? |
| 4126 | PPSMC_MSG_VCEDPM_Enable : PPSMC_MSG_VCEDPM_Disable) == PPSMC_Result_OK) ? |
| 4127 | 0 : -EINVAL; |
| 4128 | } |
| 4129 | |
| 4130 | #if 0 |
| 4131 | static int ci_enable_samu_dpm(struct amdgpu_device *adev, bool enable) |
| 4132 | { |
| 4133 | struct ci_power_info *pi = ci_get_pi(adev); |
| 4134 | const struct amdgpu_clock_and_voltage_limits *max_limits; |
| 4135 | int i; |
| 4136 | |
| 4137 | if (adev->pm.dpm.ac_power) |
| 4138 | max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_ac; |
| 4139 | else |
| 4140 | max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_dc; |
| 4141 | |
| 4142 | if (enable) { |
| 4143 | pi->dpm_level_enable_mask.samu_dpm_enable_mask = 0; |
| 4144 | for (i = adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.count - 1; i >= 0; i--) { |
| 4145 | if (adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries[i].v <= max_limits->vddc) { |
| 4146 | pi->dpm_level_enable_mask.samu_dpm_enable_mask |= 1 << i; |
| 4147 | |
| 4148 | if (!pi->caps_samu_dpm) |
| 4149 | break; |
| 4150 | } |
| 4151 | } |
| 4152 | |
| 4153 | amdgpu_ci_send_msg_to_smc_with_parameter(adev, |
| 4154 | PPSMC_MSG_SAMUDPM_SetEnabledMask, |
| 4155 | pi->dpm_level_enable_mask.samu_dpm_enable_mask); |
| 4156 | } |
| 4157 | return (amdgpu_ci_send_msg_to_smc(adev, enable ? |
| 4158 | PPSMC_MSG_SAMUDPM_Enable : PPSMC_MSG_SAMUDPM_Disable) == PPSMC_Result_OK) ? |
| 4159 | 0 : -EINVAL; |
| 4160 | } |
| 4161 | |
| 4162 | static int ci_enable_acp_dpm(struct amdgpu_device *adev, bool enable) |
| 4163 | { |
| 4164 | struct ci_power_info *pi = ci_get_pi(adev); |
| 4165 | const struct amdgpu_clock_and_voltage_limits *max_limits; |
| 4166 | int i; |
| 4167 | |
| 4168 | if (adev->pm.dpm.ac_power) |
| 4169 | max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_ac; |
| 4170 | else |
| 4171 | max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_dc; |
| 4172 | |
| 4173 | if (enable) { |
| 4174 | pi->dpm_level_enable_mask.acp_dpm_enable_mask = 0; |
| 4175 | for (i = adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.count - 1; i >= 0; i--) { |
| 4176 | if (adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries[i].v <= max_limits->vddc) { |
| 4177 | pi->dpm_level_enable_mask.acp_dpm_enable_mask |= 1 << i; |
| 4178 | |
| 4179 | if (!pi->caps_acp_dpm) |
| 4180 | break; |
| 4181 | } |
| 4182 | } |
| 4183 | |
| 4184 | amdgpu_ci_send_msg_to_smc_with_parameter(adev, |
| 4185 | PPSMC_MSG_ACPDPM_SetEnabledMask, |
| 4186 | pi->dpm_level_enable_mask.acp_dpm_enable_mask); |
| 4187 | } |
| 4188 | |
| 4189 | return (amdgpu_ci_send_msg_to_smc(adev, enable ? |
| 4190 | PPSMC_MSG_ACPDPM_Enable : PPSMC_MSG_ACPDPM_Disable) == PPSMC_Result_OK) ? |
| 4191 | 0 : -EINVAL; |
| 4192 | } |
| 4193 | #endif |
| 4194 | |
| 4195 | static int ci_update_uvd_dpm(struct amdgpu_device *adev, bool gate) |
| 4196 | { |
| 4197 | struct ci_power_info *pi = ci_get_pi(adev); |
| 4198 | u32 tmp; |
| 4199 | |
| 4200 | if (!gate) { |
| 4201 | if (pi->caps_uvd_dpm || |
| 4202 | (adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.count <= 0)) |
| 4203 | pi->smc_state_table.UvdBootLevel = 0; |
| 4204 | else |
| 4205 | pi->smc_state_table.UvdBootLevel = |
| 4206 | adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.count - 1; |
| 4207 | |
| 4208 | tmp = RREG32_SMC(ixDPM_TABLE_475); |
| 4209 | tmp &= ~DPM_TABLE_475__UvdBootLevel_MASK; |
| 4210 | tmp |= (pi->smc_state_table.UvdBootLevel << DPM_TABLE_475__UvdBootLevel__SHIFT); |
| 4211 | WREG32_SMC(ixDPM_TABLE_475, tmp); |
| 4212 | } |
| 4213 | |
| 4214 | return ci_enable_uvd_dpm(adev, !gate); |
| 4215 | } |
| 4216 | |
| 4217 | static u8 ci_get_vce_boot_level(struct amdgpu_device *adev) |
| 4218 | { |
| 4219 | u8 i; |
| 4220 | u32 min_evclk = 30000; /* ??? */ |
| 4221 | struct amdgpu_vce_clock_voltage_dependency_table *table = |
| 4222 | &adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table; |
| 4223 | |
| 4224 | for (i = 0; i < table->count; i++) { |
| 4225 | if (table->entries[i].evclk >= min_evclk) |
| 4226 | return i; |
| 4227 | } |
| 4228 | |
| 4229 | return table->count - 1; |
| 4230 | } |
| 4231 | |
| 4232 | static int ci_update_vce_dpm(struct amdgpu_device *adev, |
| 4233 | struct amdgpu_ps *amdgpu_new_state, |
| 4234 | struct amdgpu_ps *amdgpu_current_state) |
| 4235 | { |
| 4236 | struct ci_power_info *pi = ci_get_pi(adev); |
| 4237 | int ret = 0; |
| 4238 | u32 tmp; |
| 4239 | |
| 4240 | if (amdgpu_current_state->evclk != amdgpu_new_state->evclk) { |
| 4241 | if (amdgpu_new_state->evclk) { |
| 4242 | /* turn the clocks on when encoding */ |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 4243 | ret = amdgpu_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_VCE, |
| 4244 | AMD_CG_STATE_UNGATE); |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 4245 | if (ret) |
| 4246 | return ret; |
| 4247 | |
| 4248 | pi->smc_state_table.VceBootLevel = ci_get_vce_boot_level(adev); |
| 4249 | tmp = RREG32_SMC(ixDPM_TABLE_475); |
| 4250 | tmp &= ~DPM_TABLE_475__VceBootLevel_MASK; |
| 4251 | tmp |= (pi->smc_state_table.VceBootLevel << DPM_TABLE_475__VceBootLevel__SHIFT); |
| 4252 | WREG32_SMC(ixDPM_TABLE_475, tmp); |
| 4253 | |
| 4254 | ret = ci_enable_vce_dpm(adev, true); |
| 4255 | } else { |
| 4256 | /* turn the clocks off when not encoding */ |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 4257 | ret = amdgpu_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_VCE, |
| 4258 | AMD_CG_STATE_GATE); |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 4259 | if (ret) |
| 4260 | return ret; |
| 4261 | |
| 4262 | ret = ci_enable_vce_dpm(adev, false); |
| 4263 | } |
| 4264 | } |
| 4265 | return ret; |
| 4266 | } |
| 4267 | |
| 4268 | #if 0 |
| 4269 | static int ci_update_samu_dpm(struct amdgpu_device *adev, bool gate) |
| 4270 | { |
| 4271 | return ci_enable_samu_dpm(adev, gate); |
| 4272 | } |
| 4273 | |
| 4274 | static int ci_update_acp_dpm(struct amdgpu_device *adev, bool gate) |
| 4275 | { |
| 4276 | struct ci_power_info *pi = ci_get_pi(adev); |
| 4277 | u32 tmp; |
| 4278 | |
| 4279 | if (!gate) { |
| 4280 | pi->smc_state_table.AcpBootLevel = 0; |
| 4281 | |
| 4282 | tmp = RREG32_SMC(ixDPM_TABLE_475); |
| 4283 | tmp &= ~AcpBootLevel_MASK; |
| 4284 | tmp |= AcpBootLevel(pi->smc_state_table.AcpBootLevel); |
| 4285 | WREG32_SMC(ixDPM_TABLE_475, tmp); |
| 4286 | } |
| 4287 | |
| 4288 | return ci_enable_acp_dpm(adev, !gate); |
| 4289 | } |
| 4290 | #endif |
| 4291 | |
| 4292 | static int ci_generate_dpm_level_enable_mask(struct amdgpu_device *adev, |
| 4293 | struct amdgpu_ps *amdgpu_state) |
| 4294 | { |
| 4295 | struct ci_power_info *pi = ci_get_pi(adev); |
| 4296 | int ret; |
| 4297 | |
| 4298 | ret = ci_trim_dpm_states(adev, amdgpu_state); |
| 4299 | if (ret) |
| 4300 | return ret; |
| 4301 | |
| 4302 | pi->dpm_level_enable_mask.sclk_dpm_enable_mask = |
| 4303 | ci_get_dpm_level_enable_mask_value(&pi->dpm_table.sclk_table); |
| 4304 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask = |
| 4305 | ci_get_dpm_level_enable_mask_value(&pi->dpm_table.mclk_table); |
| 4306 | pi->last_mclk_dpm_enable_mask = |
| 4307 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask; |
| 4308 | if (pi->uvd_enabled) { |
| 4309 | if (pi->dpm_level_enable_mask.mclk_dpm_enable_mask & 1) |
| 4310 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask &= 0xFFFFFFFE; |
| 4311 | } |
| 4312 | pi->dpm_level_enable_mask.pcie_dpm_enable_mask = |
| 4313 | ci_get_dpm_level_enable_mask_value(&pi->dpm_table.pcie_speed_table); |
| 4314 | |
| 4315 | return 0; |
| 4316 | } |
| 4317 | |
| 4318 | static u32 ci_get_lowest_enabled_level(struct amdgpu_device *adev, |
| 4319 | u32 level_mask) |
| 4320 | { |
| 4321 | u32 level = 0; |
| 4322 | |
| 4323 | while ((level_mask & (1 << level)) == 0) |
| 4324 | level++; |
| 4325 | |
| 4326 | return level; |
| 4327 | } |
| 4328 | |
| 4329 | |
| 4330 | static int ci_dpm_force_performance_level(struct amdgpu_device *adev, |
| 4331 | enum amdgpu_dpm_forced_level level) |
| 4332 | { |
| 4333 | struct ci_power_info *pi = ci_get_pi(adev); |
| 4334 | u32 tmp, levels, i; |
| 4335 | int ret; |
| 4336 | |
| 4337 | if (level == AMDGPU_DPM_FORCED_LEVEL_HIGH) { |
| 4338 | if ((!pi->pcie_dpm_key_disabled) && |
| 4339 | pi->dpm_level_enable_mask.pcie_dpm_enable_mask) { |
| 4340 | levels = 0; |
| 4341 | tmp = pi->dpm_level_enable_mask.pcie_dpm_enable_mask; |
| 4342 | while (tmp >>= 1) |
| 4343 | levels++; |
| 4344 | if (levels) { |
| 4345 | ret = ci_dpm_force_state_pcie(adev, level); |
| 4346 | if (ret) |
| 4347 | return ret; |
| 4348 | for (i = 0; i < adev->usec_timeout; i++) { |
| 4349 | tmp = (RREG32_SMC(ixTARGET_AND_CURRENT_PROFILE_INDEX_1) & |
| 4350 | TARGET_AND_CURRENT_PROFILE_INDEX_1__CURR_PCIE_INDEX_MASK) >> |
| 4351 | TARGET_AND_CURRENT_PROFILE_INDEX_1__CURR_PCIE_INDEX__SHIFT; |
| 4352 | if (tmp == levels) |
| 4353 | break; |
| 4354 | udelay(1); |
| 4355 | } |
| 4356 | } |
| 4357 | } |
| 4358 | if ((!pi->sclk_dpm_key_disabled) && |
| 4359 | pi->dpm_level_enable_mask.sclk_dpm_enable_mask) { |
| 4360 | levels = 0; |
| 4361 | tmp = pi->dpm_level_enable_mask.sclk_dpm_enable_mask; |
| 4362 | while (tmp >>= 1) |
| 4363 | levels++; |
| 4364 | if (levels) { |
| 4365 | ret = ci_dpm_force_state_sclk(adev, levels); |
| 4366 | if (ret) |
| 4367 | return ret; |
| 4368 | for (i = 0; i < adev->usec_timeout; i++) { |
| 4369 | tmp = (RREG32_SMC(ixTARGET_AND_CURRENT_PROFILE_INDEX) & |
| 4370 | TARGET_AND_CURRENT_PROFILE_INDEX__CURR_SCLK_INDEX_MASK) >> |
| 4371 | TARGET_AND_CURRENT_PROFILE_INDEX__CURR_SCLK_INDEX__SHIFT; |
| 4372 | if (tmp == levels) |
| 4373 | break; |
| 4374 | udelay(1); |
| 4375 | } |
| 4376 | } |
| 4377 | } |
| 4378 | if ((!pi->mclk_dpm_key_disabled) && |
| 4379 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask) { |
| 4380 | levels = 0; |
| 4381 | tmp = pi->dpm_level_enable_mask.mclk_dpm_enable_mask; |
| 4382 | while (tmp >>= 1) |
| 4383 | levels++; |
| 4384 | if (levels) { |
| 4385 | ret = ci_dpm_force_state_mclk(adev, levels); |
| 4386 | if (ret) |
| 4387 | return ret; |
| 4388 | for (i = 0; i < adev->usec_timeout; i++) { |
| 4389 | tmp = (RREG32_SMC(ixTARGET_AND_CURRENT_PROFILE_INDEX) & |
| 4390 | TARGET_AND_CURRENT_PROFILE_INDEX__CURR_MCLK_INDEX_MASK) >> |
| 4391 | TARGET_AND_CURRENT_PROFILE_INDEX__CURR_MCLK_INDEX__SHIFT; |
| 4392 | if (tmp == levels) |
| 4393 | break; |
| 4394 | udelay(1); |
| 4395 | } |
| 4396 | } |
| 4397 | } |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 4398 | } else if (level == AMDGPU_DPM_FORCED_LEVEL_LOW) { |
| 4399 | if ((!pi->sclk_dpm_key_disabled) && |
| 4400 | pi->dpm_level_enable_mask.sclk_dpm_enable_mask) { |
| 4401 | levels = ci_get_lowest_enabled_level(adev, |
| 4402 | pi->dpm_level_enable_mask.sclk_dpm_enable_mask); |
| 4403 | ret = ci_dpm_force_state_sclk(adev, levels); |
| 4404 | if (ret) |
| 4405 | return ret; |
| 4406 | for (i = 0; i < adev->usec_timeout; i++) { |
| 4407 | tmp = (RREG32_SMC(ixTARGET_AND_CURRENT_PROFILE_INDEX) & |
| 4408 | TARGET_AND_CURRENT_PROFILE_INDEX__CURR_SCLK_INDEX_MASK) >> |
| 4409 | TARGET_AND_CURRENT_PROFILE_INDEX__CURR_SCLK_INDEX__SHIFT; |
| 4410 | if (tmp == levels) |
| 4411 | break; |
| 4412 | udelay(1); |
| 4413 | } |
| 4414 | } |
| 4415 | if ((!pi->mclk_dpm_key_disabled) && |
| 4416 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask) { |
| 4417 | levels = ci_get_lowest_enabled_level(adev, |
| 4418 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask); |
| 4419 | ret = ci_dpm_force_state_mclk(adev, levels); |
| 4420 | if (ret) |
| 4421 | return ret; |
| 4422 | for (i = 0; i < adev->usec_timeout; i++) { |
| 4423 | tmp = (RREG32_SMC(ixTARGET_AND_CURRENT_PROFILE_INDEX) & |
| 4424 | TARGET_AND_CURRENT_PROFILE_INDEX__CURR_MCLK_INDEX_MASK) >> |
| 4425 | TARGET_AND_CURRENT_PROFILE_INDEX__CURR_MCLK_INDEX__SHIFT; |
| 4426 | if (tmp == levels) |
| 4427 | break; |
| 4428 | udelay(1); |
| 4429 | } |
| 4430 | } |
| 4431 | if ((!pi->pcie_dpm_key_disabled) && |
| 4432 | pi->dpm_level_enable_mask.pcie_dpm_enable_mask) { |
| 4433 | levels = ci_get_lowest_enabled_level(adev, |
| 4434 | pi->dpm_level_enable_mask.pcie_dpm_enable_mask); |
| 4435 | ret = ci_dpm_force_state_pcie(adev, levels); |
| 4436 | if (ret) |
| 4437 | return ret; |
| 4438 | for (i = 0; i < adev->usec_timeout; i++) { |
| 4439 | tmp = (RREG32_SMC(ixTARGET_AND_CURRENT_PROFILE_INDEX_1) & |
| 4440 | TARGET_AND_CURRENT_PROFILE_INDEX_1__CURR_PCIE_INDEX_MASK) >> |
| 4441 | TARGET_AND_CURRENT_PROFILE_INDEX_1__CURR_PCIE_INDEX__SHIFT; |
| 4442 | if (tmp == levels) |
| 4443 | break; |
| 4444 | udelay(1); |
| 4445 | } |
| 4446 | } |
| 4447 | } else if (level == AMDGPU_DPM_FORCED_LEVEL_AUTO) { |
| 4448 | if (!pi->pcie_dpm_key_disabled) { |
| 4449 | PPSMC_Result smc_result; |
| 4450 | |
| 4451 | smc_result = amdgpu_ci_send_msg_to_smc(adev, |
| 4452 | PPSMC_MSG_PCIeDPM_UnForceLevel); |
| 4453 | if (smc_result != PPSMC_Result_OK) |
| 4454 | return -EINVAL; |
| 4455 | } |
| 4456 | ret = ci_upload_dpm_level_enable_mask(adev); |
| 4457 | if (ret) |
| 4458 | return ret; |
| 4459 | } |
| 4460 | |
| 4461 | adev->pm.dpm.forced_level = level; |
| 4462 | |
| 4463 | return 0; |
| 4464 | } |
| 4465 | |
| 4466 | static int ci_set_mc_special_registers(struct amdgpu_device *adev, |
| 4467 | struct ci_mc_reg_table *table) |
| 4468 | { |
| 4469 | u8 i, j, k; |
| 4470 | u32 temp_reg; |
| 4471 | |
| 4472 | for (i = 0, j = table->last; i < table->last; i++) { |
| 4473 | if (j >= SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE) |
| 4474 | return -EINVAL; |
| 4475 | switch(table->mc_reg_address[i].s1) { |
| 4476 | case mmMC_SEQ_MISC1: |
| 4477 | temp_reg = RREG32(mmMC_PMG_CMD_EMRS); |
| 4478 | table->mc_reg_address[j].s1 = mmMC_PMG_CMD_EMRS; |
| 4479 | table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_EMRS_LP; |
| 4480 | for (k = 0; k < table->num_entries; k++) { |
| 4481 | table->mc_reg_table_entry[k].mc_data[j] = |
| 4482 | ((temp_reg & 0xffff0000)) | ((table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16); |
| 4483 | } |
| 4484 | j++; |
| 4485 | if (j >= SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE) |
| 4486 | return -EINVAL; |
| 4487 | |
| 4488 | temp_reg = RREG32(mmMC_PMG_CMD_MRS); |
| 4489 | table->mc_reg_address[j].s1 = mmMC_PMG_CMD_MRS; |
| 4490 | table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_MRS_LP; |
| 4491 | for (k = 0; k < table->num_entries; k++) { |
| 4492 | table->mc_reg_table_entry[k].mc_data[j] = |
| 4493 | (temp_reg & 0xffff0000) | (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff); |
Ken Wang | 81c59f5 | 2015-06-03 21:02:01 +0800 | [diff] [blame] | 4494 | if (adev->mc.vram_type != AMDGPU_VRAM_TYPE_GDDR5) |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 4495 | table->mc_reg_table_entry[k].mc_data[j] |= 0x100; |
| 4496 | } |
| 4497 | j++; |
| 4498 | if (j > SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE) |
| 4499 | return -EINVAL; |
| 4500 | |
Ken Wang | 81c59f5 | 2015-06-03 21:02:01 +0800 | [diff] [blame] | 4501 | if (adev->mc.vram_type != AMDGPU_VRAM_TYPE_GDDR5) { |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 4502 | table->mc_reg_address[j].s1 = mmMC_PMG_AUTO_CMD; |
| 4503 | table->mc_reg_address[j].s0 = mmMC_PMG_AUTO_CMD; |
| 4504 | for (k = 0; k < table->num_entries; k++) { |
| 4505 | table->mc_reg_table_entry[k].mc_data[j] = |
| 4506 | (table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16; |
| 4507 | } |
| 4508 | j++; |
| 4509 | if (j > SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE) |
| 4510 | return -EINVAL; |
| 4511 | } |
| 4512 | break; |
| 4513 | case mmMC_SEQ_RESERVE_M: |
| 4514 | temp_reg = RREG32(mmMC_PMG_CMD_MRS1); |
| 4515 | table->mc_reg_address[j].s1 = mmMC_PMG_CMD_MRS1; |
| 4516 | table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_MRS1_LP; |
| 4517 | for (k = 0; k < table->num_entries; k++) { |
| 4518 | table->mc_reg_table_entry[k].mc_data[j] = |
| 4519 | (temp_reg & 0xffff0000) | (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff); |
| 4520 | } |
| 4521 | j++; |
| 4522 | if (j > SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE) |
| 4523 | return -EINVAL; |
| 4524 | break; |
| 4525 | default: |
| 4526 | break; |
| 4527 | } |
| 4528 | |
| 4529 | } |
| 4530 | |
| 4531 | table->last = j; |
| 4532 | |
| 4533 | return 0; |
| 4534 | } |
| 4535 | |
| 4536 | static bool ci_check_s0_mc_reg_index(u16 in_reg, u16 *out_reg) |
| 4537 | { |
| 4538 | bool result = true; |
| 4539 | |
| 4540 | switch(in_reg) { |
| 4541 | case mmMC_SEQ_RAS_TIMING: |
| 4542 | *out_reg = mmMC_SEQ_RAS_TIMING_LP; |
| 4543 | break; |
| 4544 | case mmMC_SEQ_DLL_STBY: |
| 4545 | *out_reg = mmMC_SEQ_DLL_STBY_LP; |
| 4546 | break; |
| 4547 | case mmMC_SEQ_G5PDX_CMD0: |
| 4548 | *out_reg = mmMC_SEQ_G5PDX_CMD0_LP; |
| 4549 | break; |
| 4550 | case mmMC_SEQ_G5PDX_CMD1: |
| 4551 | *out_reg = mmMC_SEQ_G5PDX_CMD1_LP; |
| 4552 | break; |
| 4553 | case mmMC_SEQ_G5PDX_CTRL: |
| 4554 | *out_reg = mmMC_SEQ_G5PDX_CTRL_LP; |
| 4555 | break; |
| 4556 | case mmMC_SEQ_CAS_TIMING: |
| 4557 | *out_reg = mmMC_SEQ_CAS_TIMING_LP; |
| 4558 | break; |
| 4559 | case mmMC_SEQ_MISC_TIMING: |
| 4560 | *out_reg = mmMC_SEQ_MISC_TIMING_LP; |
| 4561 | break; |
| 4562 | case mmMC_SEQ_MISC_TIMING2: |
| 4563 | *out_reg = mmMC_SEQ_MISC_TIMING2_LP; |
| 4564 | break; |
| 4565 | case mmMC_SEQ_PMG_DVS_CMD: |
| 4566 | *out_reg = mmMC_SEQ_PMG_DVS_CMD_LP; |
| 4567 | break; |
| 4568 | case mmMC_SEQ_PMG_DVS_CTL: |
| 4569 | *out_reg = mmMC_SEQ_PMG_DVS_CTL_LP; |
| 4570 | break; |
| 4571 | case mmMC_SEQ_RD_CTL_D0: |
| 4572 | *out_reg = mmMC_SEQ_RD_CTL_D0_LP; |
| 4573 | break; |
| 4574 | case mmMC_SEQ_RD_CTL_D1: |
| 4575 | *out_reg = mmMC_SEQ_RD_CTL_D1_LP; |
| 4576 | break; |
| 4577 | case mmMC_SEQ_WR_CTL_D0: |
| 4578 | *out_reg = mmMC_SEQ_WR_CTL_D0_LP; |
| 4579 | break; |
| 4580 | case mmMC_SEQ_WR_CTL_D1: |
| 4581 | *out_reg = mmMC_SEQ_WR_CTL_D1_LP; |
| 4582 | break; |
| 4583 | case mmMC_PMG_CMD_EMRS: |
| 4584 | *out_reg = mmMC_SEQ_PMG_CMD_EMRS_LP; |
| 4585 | break; |
| 4586 | case mmMC_PMG_CMD_MRS: |
| 4587 | *out_reg = mmMC_SEQ_PMG_CMD_MRS_LP; |
| 4588 | break; |
| 4589 | case mmMC_PMG_CMD_MRS1: |
| 4590 | *out_reg = mmMC_SEQ_PMG_CMD_MRS1_LP; |
| 4591 | break; |
| 4592 | case mmMC_SEQ_PMG_TIMING: |
| 4593 | *out_reg = mmMC_SEQ_PMG_TIMING_LP; |
| 4594 | break; |
| 4595 | case mmMC_PMG_CMD_MRS2: |
| 4596 | *out_reg = mmMC_SEQ_PMG_CMD_MRS2_LP; |
| 4597 | break; |
| 4598 | case mmMC_SEQ_WR_CTL_2: |
| 4599 | *out_reg = mmMC_SEQ_WR_CTL_2_LP; |
| 4600 | break; |
| 4601 | default: |
| 4602 | result = false; |
| 4603 | break; |
| 4604 | } |
| 4605 | |
| 4606 | return result; |
| 4607 | } |
| 4608 | |
| 4609 | static void ci_set_valid_flag(struct ci_mc_reg_table *table) |
| 4610 | { |
| 4611 | u8 i, j; |
| 4612 | |
| 4613 | for (i = 0; i < table->last; i++) { |
| 4614 | for (j = 1; j < table->num_entries; j++) { |
| 4615 | if (table->mc_reg_table_entry[j-1].mc_data[i] != |
| 4616 | table->mc_reg_table_entry[j].mc_data[i]) { |
| 4617 | table->valid_flag |= 1 << i; |
| 4618 | break; |
| 4619 | } |
| 4620 | } |
| 4621 | } |
| 4622 | } |
| 4623 | |
| 4624 | static void ci_set_s0_mc_reg_index(struct ci_mc_reg_table *table) |
| 4625 | { |
| 4626 | u32 i; |
| 4627 | u16 address; |
| 4628 | |
| 4629 | for (i = 0; i < table->last; i++) { |
| 4630 | table->mc_reg_address[i].s0 = |
| 4631 | ci_check_s0_mc_reg_index(table->mc_reg_address[i].s1, &address) ? |
| 4632 | address : table->mc_reg_address[i].s1; |
| 4633 | } |
| 4634 | } |
| 4635 | |
| 4636 | static int ci_copy_vbios_mc_reg_table(const struct atom_mc_reg_table *table, |
| 4637 | struct ci_mc_reg_table *ci_table) |
| 4638 | { |
| 4639 | u8 i, j; |
| 4640 | |
| 4641 | if (table->last > SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE) |
| 4642 | return -EINVAL; |
| 4643 | if (table->num_entries > MAX_AC_TIMING_ENTRIES) |
| 4644 | return -EINVAL; |
| 4645 | |
| 4646 | for (i = 0; i < table->last; i++) |
| 4647 | ci_table->mc_reg_address[i].s1 = table->mc_reg_address[i].s1; |
| 4648 | |
| 4649 | ci_table->last = table->last; |
| 4650 | |
| 4651 | for (i = 0; i < table->num_entries; i++) { |
| 4652 | ci_table->mc_reg_table_entry[i].mclk_max = |
| 4653 | table->mc_reg_table_entry[i].mclk_max; |
| 4654 | for (j = 0; j < table->last; j++) |
| 4655 | ci_table->mc_reg_table_entry[i].mc_data[j] = |
| 4656 | table->mc_reg_table_entry[i].mc_data[j]; |
| 4657 | } |
| 4658 | ci_table->num_entries = table->num_entries; |
| 4659 | |
| 4660 | return 0; |
| 4661 | } |
| 4662 | |
| 4663 | static int ci_register_patching_mc_seq(struct amdgpu_device *adev, |
| 4664 | struct ci_mc_reg_table *table) |
| 4665 | { |
| 4666 | u8 i, k; |
| 4667 | u32 tmp; |
| 4668 | bool patch; |
| 4669 | |
| 4670 | tmp = RREG32(mmMC_SEQ_MISC0); |
| 4671 | patch = ((tmp & 0x0000f00) == 0x300) ? true : false; |
| 4672 | |
| 4673 | if (patch && |
| 4674 | ((adev->pdev->device == 0x67B0) || |
| 4675 | (adev->pdev->device == 0x67B1))) { |
| 4676 | for (i = 0; i < table->last; i++) { |
| 4677 | if (table->last >= SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE) |
| 4678 | return -EINVAL; |
| 4679 | switch (table->mc_reg_address[i].s1) { |
| 4680 | case mmMC_SEQ_MISC1: |
| 4681 | for (k = 0; k < table->num_entries; k++) { |
| 4682 | if ((table->mc_reg_table_entry[k].mclk_max == 125000) || |
| 4683 | (table->mc_reg_table_entry[k].mclk_max == 137500)) |
| 4684 | table->mc_reg_table_entry[k].mc_data[i] = |
| 4685 | (table->mc_reg_table_entry[k].mc_data[i] & 0xFFFFFFF8) | |
| 4686 | 0x00000007; |
| 4687 | } |
| 4688 | break; |
| 4689 | case mmMC_SEQ_WR_CTL_D0: |
| 4690 | for (k = 0; k < table->num_entries; k++) { |
| 4691 | if ((table->mc_reg_table_entry[k].mclk_max == 125000) || |
| 4692 | (table->mc_reg_table_entry[k].mclk_max == 137500)) |
| 4693 | table->mc_reg_table_entry[k].mc_data[i] = |
| 4694 | (table->mc_reg_table_entry[k].mc_data[i] & 0xFFFF0F00) | |
| 4695 | 0x0000D0DD; |
| 4696 | } |
| 4697 | break; |
| 4698 | case mmMC_SEQ_WR_CTL_D1: |
| 4699 | for (k = 0; k < table->num_entries; k++) { |
| 4700 | if ((table->mc_reg_table_entry[k].mclk_max == 125000) || |
| 4701 | (table->mc_reg_table_entry[k].mclk_max == 137500)) |
| 4702 | table->mc_reg_table_entry[k].mc_data[i] = |
| 4703 | (table->mc_reg_table_entry[k].mc_data[i] & 0xFFFF0F00) | |
| 4704 | 0x0000D0DD; |
| 4705 | } |
| 4706 | break; |
| 4707 | case mmMC_SEQ_WR_CTL_2: |
| 4708 | for (k = 0; k < table->num_entries; k++) { |
| 4709 | if ((table->mc_reg_table_entry[k].mclk_max == 125000) || |
| 4710 | (table->mc_reg_table_entry[k].mclk_max == 137500)) |
| 4711 | table->mc_reg_table_entry[k].mc_data[i] = 0; |
| 4712 | } |
| 4713 | break; |
| 4714 | case mmMC_SEQ_CAS_TIMING: |
| 4715 | for (k = 0; k < table->num_entries; k++) { |
| 4716 | if (table->mc_reg_table_entry[k].mclk_max == 125000) |
| 4717 | table->mc_reg_table_entry[k].mc_data[i] = |
| 4718 | (table->mc_reg_table_entry[k].mc_data[i] & 0xFFE0FE0F) | |
| 4719 | 0x000C0140; |
| 4720 | else if (table->mc_reg_table_entry[k].mclk_max == 137500) |
| 4721 | table->mc_reg_table_entry[k].mc_data[i] = |
| 4722 | (table->mc_reg_table_entry[k].mc_data[i] & 0xFFE0FE0F) | |
| 4723 | 0x000C0150; |
| 4724 | } |
| 4725 | break; |
| 4726 | case mmMC_SEQ_MISC_TIMING: |
| 4727 | for (k = 0; k < table->num_entries; k++) { |
| 4728 | if (table->mc_reg_table_entry[k].mclk_max == 125000) |
| 4729 | table->mc_reg_table_entry[k].mc_data[i] = |
| 4730 | (table->mc_reg_table_entry[k].mc_data[i] & 0xFFFFFFE0) | |
| 4731 | 0x00000030; |
| 4732 | else if (table->mc_reg_table_entry[k].mclk_max == 137500) |
| 4733 | table->mc_reg_table_entry[k].mc_data[i] = |
| 4734 | (table->mc_reg_table_entry[k].mc_data[i] & 0xFFFFFFE0) | |
| 4735 | 0x00000035; |
| 4736 | } |
| 4737 | break; |
| 4738 | default: |
| 4739 | break; |
| 4740 | } |
| 4741 | } |
| 4742 | |
| 4743 | WREG32(mmMC_SEQ_IO_DEBUG_INDEX, 3); |
| 4744 | tmp = RREG32(mmMC_SEQ_IO_DEBUG_DATA); |
| 4745 | tmp = (tmp & 0xFFF8FFFF) | (1 << 16); |
| 4746 | WREG32(mmMC_SEQ_IO_DEBUG_INDEX, 3); |
| 4747 | WREG32(mmMC_SEQ_IO_DEBUG_DATA, tmp); |
| 4748 | } |
| 4749 | |
| 4750 | return 0; |
| 4751 | } |
| 4752 | |
| 4753 | static int ci_initialize_mc_reg_table(struct amdgpu_device *adev) |
| 4754 | { |
| 4755 | struct ci_power_info *pi = ci_get_pi(adev); |
| 4756 | struct atom_mc_reg_table *table; |
| 4757 | struct ci_mc_reg_table *ci_table = &pi->mc_reg_table; |
| 4758 | u8 module_index = ci_get_memory_module_index(adev); |
| 4759 | int ret; |
| 4760 | |
| 4761 | table = kzalloc(sizeof(struct atom_mc_reg_table), GFP_KERNEL); |
| 4762 | if (!table) |
| 4763 | return -ENOMEM; |
| 4764 | |
| 4765 | WREG32(mmMC_SEQ_RAS_TIMING_LP, RREG32(mmMC_SEQ_RAS_TIMING)); |
| 4766 | WREG32(mmMC_SEQ_CAS_TIMING_LP, RREG32(mmMC_SEQ_CAS_TIMING)); |
| 4767 | WREG32(mmMC_SEQ_DLL_STBY_LP, RREG32(mmMC_SEQ_DLL_STBY)); |
| 4768 | WREG32(mmMC_SEQ_G5PDX_CMD0_LP, RREG32(mmMC_SEQ_G5PDX_CMD0)); |
| 4769 | WREG32(mmMC_SEQ_G5PDX_CMD1_LP, RREG32(mmMC_SEQ_G5PDX_CMD1)); |
| 4770 | WREG32(mmMC_SEQ_G5PDX_CTRL_LP, RREG32(mmMC_SEQ_G5PDX_CTRL)); |
| 4771 | WREG32(mmMC_SEQ_PMG_DVS_CMD_LP, RREG32(mmMC_SEQ_PMG_DVS_CMD)); |
| 4772 | WREG32(mmMC_SEQ_PMG_DVS_CTL_LP, RREG32(mmMC_SEQ_PMG_DVS_CTL)); |
| 4773 | WREG32(mmMC_SEQ_MISC_TIMING_LP, RREG32(mmMC_SEQ_MISC_TIMING)); |
| 4774 | WREG32(mmMC_SEQ_MISC_TIMING2_LP, RREG32(mmMC_SEQ_MISC_TIMING2)); |
| 4775 | WREG32(mmMC_SEQ_PMG_CMD_EMRS_LP, RREG32(mmMC_PMG_CMD_EMRS)); |
| 4776 | WREG32(mmMC_SEQ_PMG_CMD_MRS_LP, RREG32(mmMC_PMG_CMD_MRS)); |
| 4777 | WREG32(mmMC_SEQ_PMG_CMD_MRS1_LP, RREG32(mmMC_PMG_CMD_MRS1)); |
| 4778 | WREG32(mmMC_SEQ_WR_CTL_D0_LP, RREG32(mmMC_SEQ_WR_CTL_D0)); |
| 4779 | WREG32(mmMC_SEQ_WR_CTL_D1_LP, RREG32(mmMC_SEQ_WR_CTL_D1)); |
| 4780 | WREG32(mmMC_SEQ_RD_CTL_D0_LP, RREG32(mmMC_SEQ_RD_CTL_D0)); |
| 4781 | WREG32(mmMC_SEQ_RD_CTL_D1_LP, RREG32(mmMC_SEQ_RD_CTL_D1)); |
| 4782 | WREG32(mmMC_SEQ_PMG_TIMING_LP, RREG32(mmMC_SEQ_PMG_TIMING)); |
| 4783 | WREG32(mmMC_SEQ_PMG_CMD_MRS2_LP, RREG32(mmMC_PMG_CMD_MRS2)); |
| 4784 | WREG32(mmMC_SEQ_WR_CTL_2_LP, RREG32(mmMC_SEQ_WR_CTL_2)); |
| 4785 | |
| 4786 | ret = amdgpu_atombios_init_mc_reg_table(adev, module_index, table); |
| 4787 | if (ret) |
| 4788 | goto init_mc_done; |
| 4789 | |
| 4790 | ret = ci_copy_vbios_mc_reg_table(table, ci_table); |
| 4791 | if (ret) |
| 4792 | goto init_mc_done; |
| 4793 | |
| 4794 | ci_set_s0_mc_reg_index(ci_table); |
| 4795 | |
| 4796 | ret = ci_register_patching_mc_seq(adev, ci_table); |
| 4797 | if (ret) |
| 4798 | goto init_mc_done; |
| 4799 | |
| 4800 | ret = ci_set_mc_special_registers(adev, ci_table); |
| 4801 | if (ret) |
| 4802 | goto init_mc_done; |
| 4803 | |
| 4804 | ci_set_valid_flag(ci_table); |
| 4805 | |
| 4806 | init_mc_done: |
| 4807 | kfree(table); |
| 4808 | |
| 4809 | return ret; |
| 4810 | } |
| 4811 | |
| 4812 | static int ci_populate_mc_reg_addresses(struct amdgpu_device *adev, |
| 4813 | SMU7_Discrete_MCRegisters *mc_reg_table) |
| 4814 | { |
| 4815 | struct ci_power_info *pi = ci_get_pi(adev); |
| 4816 | u32 i, j; |
| 4817 | |
| 4818 | for (i = 0, j = 0; j < pi->mc_reg_table.last; j++) { |
| 4819 | if (pi->mc_reg_table.valid_flag & (1 << j)) { |
| 4820 | if (i >= SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE) |
| 4821 | return -EINVAL; |
| 4822 | mc_reg_table->address[i].s0 = cpu_to_be16(pi->mc_reg_table.mc_reg_address[j].s0); |
| 4823 | mc_reg_table->address[i].s1 = cpu_to_be16(pi->mc_reg_table.mc_reg_address[j].s1); |
| 4824 | i++; |
| 4825 | } |
| 4826 | } |
| 4827 | |
| 4828 | mc_reg_table->last = (u8)i; |
| 4829 | |
| 4830 | return 0; |
| 4831 | } |
| 4832 | |
| 4833 | static void ci_convert_mc_registers(const struct ci_mc_reg_entry *entry, |
| 4834 | SMU7_Discrete_MCRegisterSet *data, |
| 4835 | u32 num_entries, u32 valid_flag) |
| 4836 | { |
| 4837 | u32 i, j; |
| 4838 | |
| 4839 | for (i = 0, j = 0; j < num_entries; j++) { |
| 4840 | if (valid_flag & (1 << j)) { |
| 4841 | data->value[i] = cpu_to_be32(entry->mc_data[j]); |
| 4842 | i++; |
| 4843 | } |
| 4844 | } |
| 4845 | } |
| 4846 | |
| 4847 | static void ci_convert_mc_reg_table_entry_to_smc(struct amdgpu_device *adev, |
| 4848 | const u32 memory_clock, |
| 4849 | SMU7_Discrete_MCRegisterSet *mc_reg_table_data) |
| 4850 | { |
| 4851 | struct ci_power_info *pi = ci_get_pi(adev); |
| 4852 | u32 i = 0; |
| 4853 | |
| 4854 | for(i = 0; i < pi->mc_reg_table.num_entries; i++) { |
| 4855 | if (memory_clock <= pi->mc_reg_table.mc_reg_table_entry[i].mclk_max) |
| 4856 | break; |
| 4857 | } |
| 4858 | |
| 4859 | if ((i == pi->mc_reg_table.num_entries) && (i > 0)) |
| 4860 | --i; |
| 4861 | |
| 4862 | ci_convert_mc_registers(&pi->mc_reg_table.mc_reg_table_entry[i], |
| 4863 | mc_reg_table_data, pi->mc_reg_table.last, |
| 4864 | pi->mc_reg_table.valid_flag); |
| 4865 | } |
| 4866 | |
| 4867 | static void ci_convert_mc_reg_table_to_smc(struct amdgpu_device *adev, |
| 4868 | SMU7_Discrete_MCRegisters *mc_reg_table) |
| 4869 | { |
| 4870 | struct ci_power_info *pi = ci_get_pi(adev); |
| 4871 | u32 i; |
| 4872 | |
| 4873 | for (i = 0; i < pi->dpm_table.mclk_table.count; i++) |
| 4874 | ci_convert_mc_reg_table_entry_to_smc(adev, |
| 4875 | pi->dpm_table.mclk_table.dpm_levels[i].value, |
| 4876 | &mc_reg_table->data[i]); |
| 4877 | } |
| 4878 | |
| 4879 | static int ci_populate_initial_mc_reg_table(struct amdgpu_device *adev) |
| 4880 | { |
| 4881 | struct ci_power_info *pi = ci_get_pi(adev); |
| 4882 | int ret; |
| 4883 | |
| 4884 | memset(&pi->smc_mc_reg_table, 0, sizeof(SMU7_Discrete_MCRegisters)); |
| 4885 | |
| 4886 | ret = ci_populate_mc_reg_addresses(adev, &pi->smc_mc_reg_table); |
| 4887 | if (ret) |
| 4888 | return ret; |
| 4889 | ci_convert_mc_reg_table_to_smc(adev, &pi->smc_mc_reg_table); |
| 4890 | |
| 4891 | return amdgpu_ci_copy_bytes_to_smc(adev, |
| 4892 | pi->mc_reg_table_start, |
| 4893 | (u8 *)&pi->smc_mc_reg_table, |
| 4894 | sizeof(SMU7_Discrete_MCRegisters), |
| 4895 | pi->sram_end); |
| 4896 | } |
| 4897 | |
| 4898 | static int ci_update_and_upload_mc_reg_table(struct amdgpu_device *adev) |
| 4899 | { |
| 4900 | struct ci_power_info *pi = ci_get_pi(adev); |
| 4901 | |
| 4902 | if (!(pi->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) |
| 4903 | return 0; |
| 4904 | |
| 4905 | memset(&pi->smc_mc_reg_table, 0, sizeof(SMU7_Discrete_MCRegisters)); |
| 4906 | |
| 4907 | ci_convert_mc_reg_table_to_smc(adev, &pi->smc_mc_reg_table); |
| 4908 | |
| 4909 | return amdgpu_ci_copy_bytes_to_smc(adev, |
| 4910 | pi->mc_reg_table_start + |
| 4911 | offsetof(SMU7_Discrete_MCRegisters, data[0]), |
| 4912 | (u8 *)&pi->smc_mc_reg_table.data[0], |
| 4913 | sizeof(SMU7_Discrete_MCRegisterSet) * |
| 4914 | pi->dpm_table.mclk_table.count, |
| 4915 | pi->sram_end); |
| 4916 | } |
| 4917 | |
| 4918 | static void ci_enable_voltage_control(struct amdgpu_device *adev) |
| 4919 | { |
| 4920 | u32 tmp = RREG32_SMC(ixGENERAL_PWRMGT); |
| 4921 | |
| 4922 | tmp |= GENERAL_PWRMGT__VOLT_PWRMGT_EN_MASK; |
| 4923 | WREG32_SMC(ixGENERAL_PWRMGT, tmp); |
| 4924 | } |
| 4925 | |
| 4926 | static enum amdgpu_pcie_gen ci_get_maximum_link_speed(struct amdgpu_device *adev, |
| 4927 | struct amdgpu_ps *amdgpu_state) |
| 4928 | { |
| 4929 | struct ci_ps *state = ci_get_ps(amdgpu_state); |
| 4930 | int i; |
| 4931 | u16 pcie_speed, max_speed = 0; |
| 4932 | |
| 4933 | for (i = 0; i < state->performance_level_count; i++) { |
| 4934 | pcie_speed = state->performance_levels[i].pcie_gen; |
| 4935 | if (max_speed < pcie_speed) |
| 4936 | max_speed = pcie_speed; |
| 4937 | } |
| 4938 | |
| 4939 | return max_speed; |
| 4940 | } |
| 4941 | |
| 4942 | static u16 ci_get_current_pcie_speed(struct amdgpu_device *adev) |
| 4943 | { |
| 4944 | u32 speed_cntl = 0; |
| 4945 | |
| 4946 | speed_cntl = RREG32_PCIE(ixPCIE_LC_SPEED_CNTL) & |
| 4947 | PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE_MASK; |
| 4948 | speed_cntl >>= PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE__SHIFT; |
| 4949 | |
| 4950 | return (u16)speed_cntl; |
| 4951 | } |
| 4952 | |
| 4953 | static int ci_get_current_pcie_lane_number(struct amdgpu_device *adev) |
| 4954 | { |
| 4955 | u32 link_width = 0; |
| 4956 | |
| 4957 | link_width = RREG32_PCIE(ixPCIE_LC_LINK_WIDTH_CNTL) & |
| 4958 | PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD_MASK; |
| 4959 | link_width >>= PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD__SHIFT; |
| 4960 | |
| 4961 | switch (link_width) { |
| 4962 | case 1: |
| 4963 | return 1; |
| 4964 | case 2: |
| 4965 | return 2; |
| 4966 | case 3: |
| 4967 | return 4; |
| 4968 | case 4: |
| 4969 | return 8; |
| 4970 | case 0: |
| 4971 | case 6: |
| 4972 | default: |
| 4973 | return 16; |
| 4974 | } |
| 4975 | } |
| 4976 | |
| 4977 | static void ci_request_link_speed_change_before_state_change(struct amdgpu_device *adev, |
| 4978 | struct amdgpu_ps *amdgpu_new_state, |
| 4979 | struct amdgpu_ps *amdgpu_current_state) |
| 4980 | { |
| 4981 | struct ci_power_info *pi = ci_get_pi(adev); |
| 4982 | enum amdgpu_pcie_gen target_link_speed = |
| 4983 | ci_get_maximum_link_speed(adev, amdgpu_new_state); |
| 4984 | enum amdgpu_pcie_gen current_link_speed; |
| 4985 | |
| 4986 | if (pi->force_pcie_gen == AMDGPU_PCIE_GEN_INVALID) |
| 4987 | current_link_speed = ci_get_maximum_link_speed(adev, amdgpu_current_state); |
| 4988 | else |
| 4989 | current_link_speed = pi->force_pcie_gen; |
| 4990 | |
| 4991 | pi->force_pcie_gen = AMDGPU_PCIE_GEN_INVALID; |
| 4992 | pi->pspp_notify_required = false; |
| 4993 | if (target_link_speed > current_link_speed) { |
| 4994 | switch (target_link_speed) { |
| 4995 | #ifdef CONFIG_ACPI |
| 4996 | case AMDGPU_PCIE_GEN3: |
| 4997 | if (amdgpu_acpi_pcie_performance_request(adev, PCIE_PERF_REQ_PECI_GEN3, false) == 0) |
| 4998 | break; |
| 4999 | pi->force_pcie_gen = AMDGPU_PCIE_GEN2; |
| 5000 | if (current_link_speed == AMDGPU_PCIE_GEN2) |
| 5001 | break; |
| 5002 | case AMDGPU_PCIE_GEN2: |
| 5003 | if (amdgpu_acpi_pcie_performance_request(adev, PCIE_PERF_REQ_PECI_GEN2, false) == 0) |
| 5004 | break; |
| 5005 | #endif |
| 5006 | default: |
| 5007 | pi->force_pcie_gen = ci_get_current_pcie_speed(adev); |
| 5008 | break; |
| 5009 | } |
| 5010 | } else { |
| 5011 | if (target_link_speed < current_link_speed) |
| 5012 | pi->pspp_notify_required = true; |
| 5013 | } |
| 5014 | } |
| 5015 | |
| 5016 | static void ci_notify_link_speed_change_after_state_change(struct amdgpu_device *adev, |
| 5017 | struct amdgpu_ps *amdgpu_new_state, |
| 5018 | struct amdgpu_ps *amdgpu_current_state) |
| 5019 | { |
| 5020 | struct ci_power_info *pi = ci_get_pi(adev); |
| 5021 | enum amdgpu_pcie_gen target_link_speed = |
| 5022 | ci_get_maximum_link_speed(adev, amdgpu_new_state); |
| 5023 | u8 request; |
| 5024 | |
| 5025 | if (pi->pspp_notify_required) { |
| 5026 | if (target_link_speed == AMDGPU_PCIE_GEN3) |
| 5027 | request = PCIE_PERF_REQ_PECI_GEN3; |
| 5028 | else if (target_link_speed == AMDGPU_PCIE_GEN2) |
| 5029 | request = PCIE_PERF_REQ_PECI_GEN2; |
| 5030 | else |
| 5031 | request = PCIE_PERF_REQ_PECI_GEN1; |
| 5032 | |
| 5033 | if ((request == PCIE_PERF_REQ_PECI_GEN1) && |
| 5034 | (ci_get_current_pcie_speed(adev) > 0)) |
| 5035 | return; |
| 5036 | |
| 5037 | #ifdef CONFIG_ACPI |
| 5038 | amdgpu_acpi_pcie_performance_request(adev, request, false); |
| 5039 | #endif |
| 5040 | } |
| 5041 | } |
| 5042 | |
| 5043 | static int ci_set_private_data_variables_based_on_pptable(struct amdgpu_device *adev) |
| 5044 | { |
| 5045 | struct ci_power_info *pi = ci_get_pi(adev); |
| 5046 | struct amdgpu_clock_voltage_dependency_table *allowed_sclk_vddc_table = |
| 5047 | &adev->pm.dpm.dyn_state.vddc_dependency_on_sclk; |
| 5048 | struct amdgpu_clock_voltage_dependency_table *allowed_mclk_vddc_table = |
| 5049 | &adev->pm.dpm.dyn_state.vddc_dependency_on_mclk; |
| 5050 | struct amdgpu_clock_voltage_dependency_table *allowed_mclk_vddci_table = |
| 5051 | &adev->pm.dpm.dyn_state.vddci_dependency_on_mclk; |
| 5052 | |
| 5053 | if (allowed_sclk_vddc_table == NULL) |
| 5054 | return -EINVAL; |
| 5055 | if (allowed_sclk_vddc_table->count < 1) |
| 5056 | return -EINVAL; |
| 5057 | if (allowed_mclk_vddc_table == NULL) |
| 5058 | return -EINVAL; |
| 5059 | if (allowed_mclk_vddc_table->count < 1) |
| 5060 | return -EINVAL; |
| 5061 | if (allowed_mclk_vddci_table == NULL) |
| 5062 | return -EINVAL; |
| 5063 | if (allowed_mclk_vddci_table->count < 1) |
| 5064 | return -EINVAL; |
| 5065 | |
| 5066 | pi->min_vddc_in_pp_table = allowed_sclk_vddc_table->entries[0].v; |
| 5067 | pi->max_vddc_in_pp_table = |
| 5068 | allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].v; |
| 5069 | |
| 5070 | pi->min_vddci_in_pp_table = allowed_mclk_vddci_table->entries[0].v; |
| 5071 | pi->max_vddci_in_pp_table = |
| 5072 | allowed_mclk_vddci_table->entries[allowed_mclk_vddci_table->count - 1].v; |
| 5073 | |
| 5074 | adev->pm.dpm.dyn_state.max_clock_voltage_on_ac.sclk = |
| 5075 | allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].clk; |
| 5076 | adev->pm.dpm.dyn_state.max_clock_voltage_on_ac.mclk = |
| 5077 | allowed_mclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].clk; |
| 5078 | adev->pm.dpm.dyn_state.max_clock_voltage_on_ac.vddc = |
| 5079 | allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].v; |
| 5080 | adev->pm.dpm.dyn_state.max_clock_voltage_on_ac.vddci = |
| 5081 | allowed_mclk_vddci_table->entries[allowed_mclk_vddci_table->count - 1].v; |
| 5082 | |
| 5083 | return 0; |
| 5084 | } |
| 5085 | |
| 5086 | static void ci_patch_with_vddc_leakage(struct amdgpu_device *adev, u16 *vddc) |
| 5087 | { |
| 5088 | struct ci_power_info *pi = ci_get_pi(adev); |
| 5089 | struct ci_leakage_voltage *leakage_table = &pi->vddc_leakage; |
| 5090 | u32 leakage_index; |
| 5091 | |
| 5092 | for (leakage_index = 0; leakage_index < leakage_table->count; leakage_index++) { |
| 5093 | if (leakage_table->leakage_id[leakage_index] == *vddc) { |
| 5094 | *vddc = leakage_table->actual_voltage[leakage_index]; |
| 5095 | break; |
| 5096 | } |
| 5097 | } |
| 5098 | } |
| 5099 | |
| 5100 | static void ci_patch_with_vddci_leakage(struct amdgpu_device *adev, u16 *vddci) |
| 5101 | { |
| 5102 | struct ci_power_info *pi = ci_get_pi(adev); |
| 5103 | struct ci_leakage_voltage *leakage_table = &pi->vddci_leakage; |
| 5104 | u32 leakage_index; |
| 5105 | |
| 5106 | for (leakage_index = 0; leakage_index < leakage_table->count; leakage_index++) { |
| 5107 | if (leakage_table->leakage_id[leakage_index] == *vddci) { |
| 5108 | *vddci = leakage_table->actual_voltage[leakage_index]; |
| 5109 | break; |
| 5110 | } |
| 5111 | } |
| 5112 | } |
| 5113 | |
| 5114 | static void ci_patch_clock_voltage_dependency_table_with_vddc_leakage(struct amdgpu_device *adev, |
| 5115 | struct amdgpu_clock_voltage_dependency_table *table) |
| 5116 | { |
| 5117 | u32 i; |
| 5118 | |
| 5119 | if (table) { |
| 5120 | for (i = 0; i < table->count; i++) |
| 5121 | ci_patch_with_vddc_leakage(adev, &table->entries[i].v); |
| 5122 | } |
| 5123 | } |
| 5124 | |
| 5125 | static void ci_patch_clock_voltage_dependency_table_with_vddci_leakage(struct amdgpu_device *adev, |
| 5126 | struct amdgpu_clock_voltage_dependency_table *table) |
| 5127 | { |
| 5128 | u32 i; |
| 5129 | |
| 5130 | if (table) { |
| 5131 | for (i = 0; i < table->count; i++) |
| 5132 | ci_patch_with_vddci_leakage(adev, &table->entries[i].v); |
| 5133 | } |
| 5134 | } |
| 5135 | |
| 5136 | static void ci_patch_vce_clock_voltage_dependency_table_with_vddc_leakage(struct amdgpu_device *adev, |
| 5137 | struct amdgpu_vce_clock_voltage_dependency_table *table) |
| 5138 | { |
| 5139 | u32 i; |
| 5140 | |
| 5141 | if (table) { |
| 5142 | for (i = 0; i < table->count; i++) |
| 5143 | ci_patch_with_vddc_leakage(adev, &table->entries[i].v); |
| 5144 | } |
| 5145 | } |
| 5146 | |
| 5147 | static void ci_patch_uvd_clock_voltage_dependency_table_with_vddc_leakage(struct amdgpu_device *adev, |
| 5148 | struct amdgpu_uvd_clock_voltage_dependency_table *table) |
| 5149 | { |
| 5150 | u32 i; |
| 5151 | |
| 5152 | if (table) { |
| 5153 | for (i = 0; i < table->count; i++) |
| 5154 | ci_patch_with_vddc_leakage(adev, &table->entries[i].v); |
| 5155 | } |
| 5156 | } |
| 5157 | |
| 5158 | static void ci_patch_vddc_phase_shed_limit_table_with_vddc_leakage(struct amdgpu_device *adev, |
| 5159 | struct amdgpu_phase_shedding_limits_table *table) |
| 5160 | { |
| 5161 | u32 i; |
| 5162 | |
| 5163 | if (table) { |
| 5164 | for (i = 0; i < table->count; i++) |
| 5165 | ci_patch_with_vddc_leakage(adev, &table->entries[i].voltage); |
| 5166 | } |
| 5167 | } |
| 5168 | |
| 5169 | static void ci_patch_clock_voltage_limits_with_vddc_leakage(struct amdgpu_device *adev, |
| 5170 | struct amdgpu_clock_and_voltage_limits *table) |
| 5171 | { |
| 5172 | if (table) { |
| 5173 | ci_patch_with_vddc_leakage(adev, (u16 *)&table->vddc); |
| 5174 | ci_patch_with_vddci_leakage(adev, (u16 *)&table->vddci); |
| 5175 | } |
| 5176 | } |
| 5177 | |
| 5178 | static void ci_patch_cac_leakage_table_with_vddc_leakage(struct amdgpu_device *adev, |
| 5179 | struct amdgpu_cac_leakage_table *table) |
| 5180 | { |
| 5181 | u32 i; |
| 5182 | |
| 5183 | if (table) { |
| 5184 | for (i = 0; i < table->count; i++) |
| 5185 | ci_patch_with_vddc_leakage(adev, &table->entries[i].vddc); |
| 5186 | } |
| 5187 | } |
| 5188 | |
| 5189 | static void ci_patch_dependency_tables_with_leakage(struct amdgpu_device *adev) |
| 5190 | { |
| 5191 | |
| 5192 | ci_patch_clock_voltage_dependency_table_with_vddc_leakage(adev, |
| 5193 | &adev->pm.dpm.dyn_state.vddc_dependency_on_sclk); |
| 5194 | ci_patch_clock_voltage_dependency_table_with_vddc_leakage(adev, |
| 5195 | &adev->pm.dpm.dyn_state.vddc_dependency_on_mclk); |
| 5196 | ci_patch_clock_voltage_dependency_table_with_vddc_leakage(adev, |
| 5197 | &adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk); |
| 5198 | ci_patch_clock_voltage_dependency_table_with_vddci_leakage(adev, |
| 5199 | &adev->pm.dpm.dyn_state.vddci_dependency_on_mclk); |
| 5200 | ci_patch_vce_clock_voltage_dependency_table_with_vddc_leakage(adev, |
| 5201 | &adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table); |
| 5202 | ci_patch_uvd_clock_voltage_dependency_table_with_vddc_leakage(adev, |
| 5203 | &adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table); |
| 5204 | ci_patch_clock_voltage_dependency_table_with_vddc_leakage(adev, |
| 5205 | &adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table); |
| 5206 | ci_patch_clock_voltage_dependency_table_with_vddc_leakage(adev, |
| 5207 | &adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table); |
| 5208 | ci_patch_vddc_phase_shed_limit_table_with_vddc_leakage(adev, |
| 5209 | &adev->pm.dpm.dyn_state.phase_shedding_limits_table); |
| 5210 | ci_patch_clock_voltage_limits_with_vddc_leakage(adev, |
| 5211 | &adev->pm.dpm.dyn_state.max_clock_voltage_on_ac); |
| 5212 | ci_patch_clock_voltage_limits_with_vddc_leakage(adev, |
| 5213 | &adev->pm.dpm.dyn_state.max_clock_voltage_on_dc); |
| 5214 | ci_patch_cac_leakage_table_with_vddc_leakage(adev, |
| 5215 | &adev->pm.dpm.dyn_state.cac_leakage_table); |
| 5216 | |
| 5217 | } |
| 5218 | |
| 5219 | static void ci_update_current_ps(struct amdgpu_device *adev, |
| 5220 | struct amdgpu_ps *rps) |
| 5221 | { |
| 5222 | struct ci_ps *new_ps = ci_get_ps(rps); |
| 5223 | struct ci_power_info *pi = ci_get_pi(adev); |
| 5224 | |
| 5225 | pi->current_rps = *rps; |
| 5226 | pi->current_ps = *new_ps; |
| 5227 | pi->current_rps.ps_priv = &pi->current_ps; |
| 5228 | } |
| 5229 | |
| 5230 | static void ci_update_requested_ps(struct amdgpu_device *adev, |
| 5231 | struct amdgpu_ps *rps) |
| 5232 | { |
| 5233 | struct ci_ps *new_ps = ci_get_ps(rps); |
| 5234 | struct ci_power_info *pi = ci_get_pi(adev); |
| 5235 | |
| 5236 | pi->requested_rps = *rps; |
| 5237 | pi->requested_ps = *new_ps; |
| 5238 | pi->requested_rps.ps_priv = &pi->requested_ps; |
| 5239 | } |
| 5240 | |
| 5241 | static int ci_dpm_pre_set_power_state(struct amdgpu_device *adev) |
| 5242 | { |
| 5243 | struct ci_power_info *pi = ci_get_pi(adev); |
| 5244 | struct amdgpu_ps requested_ps = *adev->pm.dpm.requested_ps; |
| 5245 | struct amdgpu_ps *new_ps = &requested_ps; |
| 5246 | |
| 5247 | ci_update_requested_ps(adev, new_ps); |
| 5248 | |
| 5249 | ci_apply_state_adjust_rules(adev, &pi->requested_rps); |
| 5250 | |
| 5251 | return 0; |
| 5252 | } |
| 5253 | |
| 5254 | static void ci_dpm_post_set_power_state(struct amdgpu_device *adev) |
| 5255 | { |
| 5256 | struct ci_power_info *pi = ci_get_pi(adev); |
| 5257 | struct amdgpu_ps *new_ps = &pi->requested_rps; |
| 5258 | |
| 5259 | ci_update_current_ps(adev, new_ps); |
| 5260 | } |
| 5261 | |
| 5262 | |
| 5263 | static void ci_dpm_setup_asic(struct amdgpu_device *adev) |
| 5264 | { |
| 5265 | ci_read_clock_registers(adev); |
| 5266 | ci_enable_acpi_power_management(adev); |
| 5267 | ci_init_sclk_t(adev); |
| 5268 | } |
| 5269 | |
| 5270 | static int ci_dpm_enable(struct amdgpu_device *adev) |
| 5271 | { |
| 5272 | struct ci_power_info *pi = ci_get_pi(adev); |
| 5273 | struct amdgpu_ps *boot_ps = adev->pm.dpm.boot_ps; |
| 5274 | int ret; |
| 5275 | |
| 5276 | if (amdgpu_ci_is_smc_running(adev)) |
| 5277 | return -EINVAL; |
| 5278 | if (pi->voltage_control != CISLANDS_VOLTAGE_CONTROL_NONE) { |
| 5279 | ci_enable_voltage_control(adev); |
| 5280 | ret = ci_construct_voltage_tables(adev); |
| 5281 | if (ret) { |
| 5282 | DRM_ERROR("ci_construct_voltage_tables failed\n"); |
| 5283 | return ret; |
| 5284 | } |
| 5285 | } |
| 5286 | if (pi->caps_dynamic_ac_timing) { |
| 5287 | ret = ci_initialize_mc_reg_table(adev); |
| 5288 | if (ret) |
| 5289 | pi->caps_dynamic_ac_timing = false; |
| 5290 | } |
| 5291 | if (pi->dynamic_ss) |
| 5292 | ci_enable_spread_spectrum(adev, true); |
| 5293 | if (pi->thermal_protection) |
| 5294 | ci_enable_thermal_protection(adev, true); |
| 5295 | ci_program_sstp(adev); |
| 5296 | ci_enable_display_gap(adev); |
| 5297 | ci_program_vc(adev); |
| 5298 | ret = ci_upload_firmware(adev); |
| 5299 | if (ret) { |
| 5300 | DRM_ERROR("ci_upload_firmware failed\n"); |
| 5301 | return ret; |
| 5302 | } |
| 5303 | ret = ci_process_firmware_header(adev); |
| 5304 | if (ret) { |
| 5305 | DRM_ERROR("ci_process_firmware_header failed\n"); |
| 5306 | return ret; |
| 5307 | } |
| 5308 | ret = ci_initial_switch_from_arb_f0_to_f1(adev); |
| 5309 | if (ret) { |
| 5310 | DRM_ERROR("ci_initial_switch_from_arb_f0_to_f1 failed\n"); |
| 5311 | return ret; |
| 5312 | } |
| 5313 | ret = ci_init_smc_table(adev); |
| 5314 | if (ret) { |
| 5315 | DRM_ERROR("ci_init_smc_table failed\n"); |
| 5316 | return ret; |
| 5317 | } |
| 5318 | ret = ci_init_arb_table_index(adev); |
| 5319 | if (ret) { |
| 5320 | DRM_ERROR("ci_init_arb_table_index failed\n"); |
| 5321 | return ret; |
| 5322 | } |
| 5323 | if (pi->caps_dynamic_ac_timing) { |
| 5324 | ret = ci_populate_initial_mc_reg_table(adev); |
| 5325 | if (ret) { |
| 5326 | DRM_ERROR("ci_populate_initial_mc_reg_table failed\n"); |
| 5327 | return ret; |
| 5328 | } |
| 5329 | } |
| 5330 | ret = ci_populate_pm_base(adev); |
| 5331 | if (ret) { |
| 5332 | DRM_ERROR("ci_populate_pm_base failed\n"); |
| 5333 | return ret; |
| 5334 | } |
| 5335 | ci_dpm_start_smc(adev); |
| 5336 | ci_enable_vr_hot_gpio_interrupt(adev); |
| 5337 | ret = ci_notify_smc_display_change(adev, false); |
| 5338 | if (ret) { |
| 5339 | DRM_ERROR("ci_notify_smc_display_change failed\n"); |
| 5340 | return ret; |
| 5341 | } |
| 5342 | ci_enable_sclk_control(adev, true); |
| 5343 | ret = ci_enable_ulv(adev, true); |
| 5344 | if (ret) { |
| 5345 | DRM_ERROR("ci_enable_ulv failed\n"); |
| 5346 | return ret; |
| 5347 | } |
| 5348 | ret = ci_enable_ds_master_switch(adev, true); |
| 5349 | if (ret) { |
| 5350 | DRM_ERROR("ci_enable_ds_master_switch failed\n"); |
| 5351 | return ret; |
| 5352 | } |
| 5353 | ret = ci_start_dpm(adev); |
| 5354 | if (ret) { |
| 5355 | DRM_ERROR("ci_start_dpm failed\n"); |
| 5356 | return ret; |
| 5357 | } |
| 5358 | ret = ci_enable_didt(adev, true); |
| 5359 | if (ret) { |
| 5360 | DRM_ERROR("ci_enable_didt failed\n"); |
| 5361 | return ret; |
| 5362 | } |
| 5363 | ret = ci_enable_smc_cac(adev, true); |
| 5364 | if (ret) { |
| 5365 | DRM_ERROR("ci_enable_smc_cac failed\n"); |
| 5366 | return ret; |
| 5367 | } |
| 5368 | ret = ci_enable_power_containment(adev, true); |
| 5369 | if (ret) { |
| 5370 | DRM_ERROR("ci_enable_power_containment failed\n"); |
| 5371 | return ret; |
| 5372 | } |
| 5373 | |
| 5374 | ret = ci_power_control_set_level(adev); |
| 5375 | if (ret) { |
| 5376 | DRM_ERROR("ci_power_control_set_level failed\n"); |
| 5377 | return ret; |
| 5378 | } |
| 5379 | |
| 5380 | ci_enable_auto_throttle_source(adev, AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL, true); |
| 5381 | |
| 5382 | ret = ci_enable_thermal_based_sclk_dpm(adev, true); |
| 5383 | if (ret) { |
| 5384 | DRM_ERROR("ci_enable_thermal_based_sclk_dpm failed\n"); |
| 5385 | return ret; |
| 5386 | } |
| 5387 | |
| 5388 | ci_thermal_start_thermal_controller(adev); |
| 5389 | |
| 5390 | ci_update_current_ps(adev, boot_ps); |
| 5391 | |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 5392 | return 0; |
| 5393 | } |
| 5394 | |
| 5395 | static void ci_dpm_disable(struct amdgpu_device *adev) |
| 5396 | { |
| 5397 | struct ci_power_info *pi = ci_get_pi(adev); |
| 5398 | struct amdgpu_ps *boot_ps = adev->pm.dpm.boot_ps; |
| 5399 | |
| 5400 | amdgpu_irq_put(adev, &adev->pm.dpm.thermal.irq, |
| 5401 | AMDGPU_THERMAL_IRQ_LOW_TO_HIGH); |
| 5402 | amdgpu_irq_put(adev, &adev->pm.dpm.thermal.irq, |
| 5403 | AMDGPU_THERMAL_IRQ_HIGH_TO_LOW); |
| 5404 | |
Rex Zhu | c08770e | 2016-08-24 19:39:06 +0800 | [diff] [blame] | 5405 | ci_dpm_powergate_uvd(adev, true); |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 5406 | |
| 5407 | if (!amdgpu_ci_is_smc_running(adev)) |
| 5408 | return; |
| 5409 | |
| 5410 | ci_thermal_stop_thermal_controller(adev); |
| 5411 | |
| 5412 | if (pi->thermal_protection) |
| 5413 | ci_enable_thermal_protection(adev, false); |
| 5414 | ci_enable_power_containment(adev, false); |
| 5415 | ci_enable_smc_cac(adev, false); |
| 5416 | ci_enable_didt(adev, false); |
| 5417 | ci_enable_spread_spectrum(adev, false); |
| 5418 | ci_enable_auto_throttle_source(adev, AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL, false); |
| 5419 | ci_stop_dpm(adev); |
| 5420 | ci_enable_ds_master_switch(adev, false); |
| 5421 | ci_enable_ulv(adev, false); |
| 5422 | ci_clear_vc(adev); |
| 5423 | ci_reset_to_default(adev); |
| 5424 | ci_dpm_stop_smc(adev); |
| 5425 | ci_force_switch_to_arb_f0(adev); |
| 5426 | ci_enable_thermal_based_sclk_dpm(adev, false); |
| 5427 | |
| 5428 | ci_update_current_ps(adev, boot_ps); |
| 5429 | } |
| 5430 | |
| 5431 | static int ci_dpm_set_power_state(struct amdgpu_device *adev) |
| 5432 | { |
| 5433 | struct ci_power_info *pi = ci_get_pi(adev); |
| 5434 | struct amdgpu_ps *new_ps = &pi->requested_rps; |
| 5435 | struct amdgpu_ps *old_ps = &pi->current_rps; |
| 5436 | int ret; |
| 5437 | |
| 5438 | ci_find_dpm_states_clocks_in_dpm_table(adev, new_ps); |
| 5439 | if (pi->pcie_performance_request) |
| 5440 | ci_request_link_speed_change_before_state_change(adev, new_ps, old_ps); |
| 5441 | ret = ci_freeze_sclk_mclk_dpm(adev); |
| 5442 | if (ret) { |
| 5443 | DRM_ERROR("ci_freeze_sclk_mclk_dpm failed\n"); |
| 5444 | return ret; |
| 5445 | } |
| 5446 | ret = ci_populate_and_upload_sclk_mclk_dpm_levels(adev, new_ps); |
| 5447 | if (ret) { |
| 5448 | DRM_ERROR("ci_populate_and_upload_sclk_mclk_dpm_levels failed\n"); |
| 5449 | return ret; |
| 5450 | } |
| 5451 | ret = ci_generate_dpm_level_enable_mask(adev, new_ps); |
| 5452 | if (ret) { |
| 5453 | DRM_ERROR("ci_generate_dpm_level_enable_mask failed\n"); |
| 5454 | return ret; |
| 5455 | } |
| 5456 | |
| 5457 | ret = ci_update_vce_dpm(adev, new_ps, old_ps); |
| 5458 | if (ret) { |
| 5459 | DRM_ERROR("ci_update_vce_dpm failed\n"); |
| 5460 | return ret; |
| 5461 | } |
| 5462 | |
| 5463 | ret = ci_update_sclk_t(adev); |
| 5464 | if (ret) { |
| 5465 | DRM_ERROR("ci_update_sclk_t failed\n"); |
| 5466 | return ret; |
| 5467 | } |
| 5468 | if (pi->caps_dynamic_ac_timing) { |
| 5469 | ret = ci_update_and_upload_mc_reg_table(adev); |
| 5470 | if (ret) { |
| 5471 | DRM_ERROR("ci_update_and_upload_mc_reg_table failed\n"); |
| 5472 | return ret; |
| 5473 | } |
| 5474 | } |
| 5475 | ret = ci_program_memory_timing_parameters(adev); |
| 5476 | if (ret) { |
| 5477 | DRM_ERROR("ci_program_memory_timing_parameters failed\n"); |
| 5478 | return ret; |
| 5479 | } |
| 5480 | ret = ci_unfreeze_sclk_mclk_dpm(adev); |
| 5481 | if (ret) { |
| 5482 | DRM_ERROR("ci_unfreeze_sclk_mclk_dpm failed\n"); |
| 5483 | return ret; |
| 5484 | } |
| 5485 | ret = ci_upload_dpm_level_enable_mask(adev); |
| 5486 | if (ret) { |
| 5487 | DRM_ERROR("ci_upload_dpm_level_enable_mask failed\n"); |
| 5488 | return ret; |
| 5489 | } |
| 5490 | if (pi->pcie_performance_request) |
| 5491 | ci_notify_link_speed_change_after_state_change(adev, new_ps, old_ps); |
| 5492 | |
| 5493 | return 0; |
| 5494 | } |
| 5495 | |
| 5496 | #if 0 |
| 5497 | static void ci_dpm_reset_asic(struct amdgpu_device *adev) |
| 5498 | { |
| 5499 | ci_set_boot_state(adev); |
| 5500 | } |
| 5501 | #endif |
| 5502 | |
| 5503 | static void ci_dpm_display_configuration_changed(struct amdgpu_device *adev) |
| 5504 | { |
| 5505 | ci_program_display_gap(adev); |
| 5506 | } |
| 5507 | |
| 5508 | union power_info { |
| 5509 | struct _ATOM_POWERPLAY_INFO info; |
| 5510 | struct _ATOM_POWERPLAY_INFO_V2 info_2; |
| 5511 | struct _ATOM_POWERPLAY_INFO_V3 info_3; |
| 5512 | struct _ATOM_PPLIB_POWERPLAYTABLE pplib; |
| 5513 | struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2; |
| 5514 | struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3; |
| 5515 | }; |
| 5516 | |
| 5517 | union pplib_clock_info { |
| 5518 | struct _ATOM_PPLIB_R600_CLOCK_INFO r600; |
| 5519 | struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780; |
| 5520 | struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen; |
| 5521 | struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo; |
| 5522 | struct _ATOM_PPLIB_SI_CLOCK_INFO si; |
| 5523 | struct _ATOM_PPLIB_CI_CLOCK_INFO ci; |
| 5524 | }; |
| 5525 | |
| 5526 | union pplib_power_state { |
| 5527 | struct _ATOM_PPLIB_STATE v1; |
| 5528 | struct _ATOM_PPLIB_STATE_V2 v2; |
| 5529 | }; |
| 5530 | |
| 5531 | static void ci_parse_pplib_non_clock_info(struct amdgpu_device *adev, |
| 5532 | struct amdgpu_ps *rps, |
| 5533 | struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info, |
| 5534 | u8 table_rev) |
| 5535 | { |
| 5536 | rps->caps = le32_to_cpu(non_clock_info->ulCapsAndSettings); |
| 5537 | rps->class = le16_to_cpu(non_clock_info->usClassification); |
| 5538 | rps->class2 = le16_to_cpu(non_clock_info->usClassification2); |
| 5539 | |
| 5540 | if (ATOM_PPLIB_NONCLOCKINFO_VER1 < table_rev) { |
| 5541 | rps->vclk = le32_to_cpu(non_clock_info->ulVCLK); |
| 5542 | rps->dclk = le32_to_cpu(non_clock_info->ulDCLK); |
| 5543 | } else { |
| 5544 | rps->vclk = 0; |
| 5545 | rps->dclk = 0; |
| 5546 | } |
| 5547 | |
| 5548 | if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT) |
| 5549 | adev->pm.dpm.boot_ps = rps; |
| 5550 | if (rps->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE) |
| 5551 | adev->pm.dpm.uvd_ps = rps; |
| 5552 | } |
| 5553 | |
| 5554 | static void ci_parse_pplib_clock_info(struct amdgpu_device *adev, |
| 5555 | struct amdgpu_ps *rps, int index, |
| 5556 | union pplib_clock_info *clock_info) |
| 5557 | { |
| 5558 | struct ci_power_info *pi = ci_get_pi(adev); |
| 5559 | struct ci_ps *ps = ci_get_ps(rps); |
| 5560 | struct ci_pl *pl = &ps->performance_levels[index]; |
| 5561 | |
| 5562 | ps->performance_level_count = index + 1; |
| 5563 | |
| 5564 | pl->sclk = le16_to_cpu(clock_info->ci.usEngineClockLow); |
| 5565 | pl->sclk |= clock_info->ci.ucEngineClockHigh << 16; |
| 5566 | pl->mclk = le16_to_cpu(clock_info->ci.usMemoryClockLow); |
| 5567 | pl->mclk |= clock_info->ci.ucMemoryClockHigh << 16; |
| 5568 | |
| 5569 | pl->pcie_gen = amdgpu_get_pcie_gen_support(adev, |
| 5570 | pi->sys_pcie_mask, |
| 5571 | pi->vbios_boot_state.pcie_gen_bootup_value, |
| 5572 | clock_info->ci.ucPCIEGen); |
| 5573 | pl->pcie_lane = amdgpu_get_pcie_lane_support(adev, |
| 5574 | pi->vbios_boot_state.pcie_lane_bootup_value, |
| 5575 | le16_to_cpu(clock_info->ci.usPCIELane)); |
| 5576 | |
| 5577 | if (rps->class & ATOM_PPLIB_CLASSIFICATION_ACPI) { |
| 5578 | pi->acpi_pcie_gen = pl->pcie_gen; |
| 5579 | } |
| 5580 | |
| 5581 | if (rps->class2 & ATOM_PPLIB_CLASSIFICATION2_ULV) { |
| 5582 | pi->ulv.supported = true; |
| 5583 | pi->ulv.pl = *pl; |
| 5584 | pi->ulv.cg_ulv_parameter = CISLANDS_CGULVPARAMETER_DFLT; |
| 5585 | } |
| 5586 | |
| 5587 | /* patch up boot state */ |
| 5588 | if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT) { |
| 5589 | pl->mclk = pi->vbios_boot_state.mclk_bootup_value; |
| 5590 | pl->sclk = pi->vbios_boot_state.sclk_bootup_value; |
| 5591 | pl->pcie_gen = pi->vbios_boot_state.pcie_gen_bootup_value; |
| 5592 | pl->pcie_lane = pi->vbios_boot_state.pcie_lane_bootup_value; |
| 5593 | } |
| 5594 | |
| 5595 | switch (rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) { |
| 5596 | case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY: |
| 5597 | pi->use_pcie_powersaving_levels = true; |
| 5598 | if (pi->pcie_gen_powersaving.max < pl->pcie_gen) |
| 5599 | pi->pcie_gen_powersaving.max = pl->pcie_gen; |
| 5600 | if (pi->pcie_gen_powersaving.min > pl->pcie_gen) |
| 5601 | pi->pcie_gen_powersaving.min = pl->pcie_gen; |
| 5602 | if (pi->pcie_lane_powersaving.max < pl->pcie_lane) |
| 5603 | pi->pcie_lane_powersaving.max = pl->pcie_lane; |
| 5604 | if (pi->pcie_lane_powersaving.min > pl->pcie_lane) |
| 5605 | pi->pcie_lane_powersaving.min = pl->pcie_lane; |
| 5606 | break; |
| 5607 | case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE: |
| 5608 | pi->use_pcie_performance_levels = true; |
| 5609 | if (pi->pcie_gen_performance.max < pl->pcie_gen) |
| 5610 | pi->pcie_gen_performance.max = pl->pcie_gen; |
| 5611 | if (pi->pcie_gen_performance.min > pl->pcie_gen) |
| 5612 | pi->pcie_gen_performance.min = pl->pcie_gen; |
| 5613 | if (pi->pcie_lane_performance.max < pl->pcie_lane) |
| 5614 | pi->pcie_lane_performance.max = pl->pcie_lane; |
| 5615 | if (pi->pcie_lane_performance.min > pl->pcie_lane) |
| 5616 | pi->pcie_lane_performance.min = pl->pcie_lane; |
| 5617 | break; |
| 5618 | default: |
| 5619 | break; |
| 5620 | } |
| 5621 | } |
| 5622 | |
| 5623 | static int ci_parse_power_table(struct amdgpu_device *adev) |
| 5624 | { |
| 5625 | struct amdgpu_mode_info *mode_info = &adev->mode_info; |
| 5626 | struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info; |
| 5627 | union pplib_power_state *power_state; |
| 5628 | int i, j, k, non_clock_array_index, clock_array_index; |
| 5629 | union pplib_clock_info *clock_info; |
| 5630 | struct _StateArray *state_array; |
| 5631 | struct _ClockInfoArray *clock_info_array; |
| 5632 | struct _NonClockInfoArray *non_clock_info_array; |
| 5633 | union power_info *power_info; |
| 5634 | int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo); |
| 5635 | u16 data_offset; |
| 5636 | u8 frev, crev; |
| 5637 | u8 *power_state_offset; |
| 5638 | struct ci_ps *ps; |
| 5639 | |
| 5640 | if (!amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL, |
| 5641 | &frev, &crev, &data_offset)) |
| 5642 | return -EINVAL; |
| 5643 | power_info = (union power_info *)(mode_info->atom_context->bios + data_offset); |
| 5644 | |
| 5645 | amdgpu_add_thermal_controller(adev); |
| 5646 | |
| 5647 | state_array = (struct _StateArray *) |
| 5648 | (mode_info->atom_context->bios + data_offset + |
| 5649 | le16_to_cpu(power_info->pplib.usStateArrayOffset)); |
| 5650 | clock_info_array = (struct _ClockInfoArray *) |
| 5651 | (mode_info->atom_context->bios + data_offset + |
| 5652 | le16_to_cpu(power_info->pplib.usClockInfoArrayOffset)); |
| 5653 | non_clock_info_array = (struct _NonClockInfoArray *) |
| 5654 | (mode_info->atom_context->bios + data_offset + |
| 5655 | le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset)); |
| 5656 | |
| 5657 | adev->pm.dpm.ps = kzalloc(sizeof(struct amdgpu_ps) * |
| 5658 | state_array->ucNumEntries, GFP_KERNEL); |
| 5659 | if (!adev->pm.dpm.ps) |
| 5660 | return -ENOMEM; |
| 5661 | power_state_offset = (u8 *)state_array->states; |
| 5662 | for (i = 0; i < state_array->ucNumEntries; i++) { |
| 5663 | u8 *idx; |
| 5664 | power_state = (union pplib_power_state *)power_state_offset; |
| 5665 | non_clock_array_index = power_state->v2.nonClockInfoIndex; |
| 5666 | non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *) |
| 5667 | &non_clock_info_array->nonClockInfo[non_clock_array_index]; |
| 5668 | ps = kzalloc(sizeof(struct ci_ps), GFP_KERNEL); |
| 5669 | if (ps == NULL) { |
| 5670 | kfree(adev->pm.dpm.ps); |
| 5671 | return -ENOMEM; |
| 5672 | } |
| 5673 | adev->pm.dpm.ps[i].ps_priv = ps; |
| 5674 | ci_parse_pplib_non_clock_info(adev, &adev->pm.dpm.ps[i], |
| 5675 | non_clock_info, |
| 5676 | non_clock_info_array->ucEntrySize); |
| 5677 | k = 0; |
| 5678 | idx = (u8 *)&power_state->v2.clockInfoIndex[0]; |
| 5679 | for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) { |
| 5680 | clock_array_index = idx[j]; |
| 5681 | if (clock_array_index >= clock_info_array->ucNumEntries) |
| 5682 | continue; |
| 5683 | if (k >= CISLANDS_MAX_HARDWARE_POWERLEVELS) |
| 5684 | break; |
| 5685 | clock_info = (union pplib_clock_info *) |
| 5686 | ((u8 *)&clock_info_array->clockInfo[0] + |
| 5687 | (clock_array_index * clock_info_array->ucEntrySize)); |
| 5688 | ci_parse_pplib_clock_info(adev, |
| 5689 | &adev->pm.dpm.ps[i], k, |
| 5690 | clock_info); |
| 5691 | k++; |
| 5692 | } |
| 5693 | power_state_offset += 2 + power_state->v2.ucNumDPMLevels; |
| 5694 | } |
| 5695 | adev->pm.dpm.num_ps = state_array->ucNumEntries; |
| 5696 | |
| 5697 | /* fill in the vce power states */ |
| 5698 | for (i = 0; i < AMDGPU_MAX_VCE_LEVELS; i++) { |
| 5699 | u32 sclk, mclk; |
| 5700 | clock_array_index = adev->pm.dpm.vce_states[i].clk_idx; |
| 5701 | clock_info = (union pplib_clock_info *) |
| 5702 | &clock_info_array->clockInfo[clock_array_index * clock_info_array->ucEntrySize]; |
| 5703 | sclk = le16_to_cpu(clock_info->ci.usEngineClockLow); |
| 5704 | sclk |= clock_info->ci.ucEngineClockHigh << 16; |
| 5705 | mclk = le16_to_cpu(clock_info->ci.usMemoryClockLow); |
| 5706 | mclk |= clock_info->ci.ucMemoryClockHigh << 16; |
| 5707 | adev->pm.dpm.vce_states[i].sclk = sclk; |
| 5708 | adev->pm.dpm.vce_states[i].mclk = mclk; |
| 5709 | } |
| 5710 | |
| 5711 | return 0; |
| 5712 | } |
| 5713 | |
| 5714 | static int ci_get_vbios_boot_values(struct amdgpu_device *adev, |
| 5715 | struct ci_vbios_boot_state *boot_state) |
| 5716 | { |
| 5717 | struct amdgpu_mode_info *mode_info = &adev->mode_info; |
| 5718 | int index = GetIndexIntoMasterTable(DATA, FirmwareInfo); |
| 5719 | ATOM_FIRMWARE_INFO_V2_2 *firmware_info; |
| 5720 | u8 frev, crev; |
| 5721 | u16 data_offset; |
| 5722 | |
| 5723 | if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL, |
| 5724 | &frev, &crev, &data_offset)) { |
| 5725 | firmware_info = |
| 5726 | (ATOM_FIRMWARE_INFO_V2_2 *)(mode_info->atom_context->bios + |
| 5727 | data_offset); |
| 5728 | boot_state->mvdd_bootup_value = le16_to_cpu(firmware_info->usBootUpMVDDCVoltage); |
| 5729 | boot_state->vddc_bootup_value = le16_to_cpu(firmware_info->usBootUpVDDCVoltage); |
| 5730 | boot_state->vddci_bootup_value = le16_to_cpu(firmware_info->usBootUpVDDCIVoltage); |
| 5731 | boot_state->pcie_gen_bootup_value = ci_get_current_pcie_speed(adev); |
| 5732 | boot_state->pcie_lane_bootup_value = ci_get_current_pcie_lane_number(adev); |
| 5733 | boot_state->sclk_bootup_value = le32_to_cpu(firmware_info->ulDefaultEngineClock); |
| 5734 | boot_state->mclk_bootup_value = le32_to_cpu(firmware_info->ulDefaultMemoryClock); |
| 5735 | |
| 5736 | return 0; |
| 5737 | } |
| 5738 | return -EINVAL; |
| 5739 | } |
| 5740 | |
| 5741 | static void ci_dpm_fini(struct amdgpu_device *adev) |
| 5742 | { |
| 5743 | int i; |
| 5744 | |
| 5745 | for (i = 0; i < adev->pm.dpm.num_ps; i++) { |
| 5746 | kfree(adev->pm.dpm.ps[i].ps_priv); |
| 5747 | } |
| 5748 | kfree(adev->pm.dpm.ps); |
| 5749 | kfree(adev->pm.dpm.priv); |
| 5750 | kfree(adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries); |
| 5751 | amdgpu_free_extended_power_table(adev); |
| 5752 | } |
| 5753 | |
| 5754 | /** |
| 5755 | * ci_dpm_init_microcode - load ucode images from disk |
| 5756 | * |
| 5757 | * @adev: amdgpu_device pointer |
| 5758 | * |
| 5759 | * Use the firmware interface to load the ucode images into |
| 5760 | * the driver (not loaded into hw). |
| 5761 | * Returns 0 on success, error on failure. |
| 5762 | */ |
| 5763 | static int ci_dpm_init_microcode(struct amdgpu_device *adev) |
| 5764 | { |
| 5765 | const char *chip_name; |
| 5766 | char fw_name[30]; |
| 5767 | int err; |
| 5768 | |
| 5769 | DRM_DEBUG("\n"); |
| 5770 | |
| 5771 | switch (adev->asic_type) { |
| 5772 | case CHIP_BONAIRE: |
Alex Deucher | 2254c21 | 2015-12-10 00:49:32 -0500 | [diff] [blame] | 5773 | if ((adev->pdev->revision == 0x80) || |
| 5774 | (adev->pdev->revision == 0x81) || |
| 5775 | (adev->pdev->device == 0x665f)) |
| 5776 | chip_name = "bonaire_k"; |
| 5777 | else |
| 5778 | chip_name = "bonaire"; |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 5779 | break; |
| 5780 | case CHIP_HAWAII: |
Alex Deucher | 2254c21 | 2015-12-10 00:49:32 -0500 | [diff] [blame] | 5781 | if (adev->pdev->revision == 0x80) |
| 5782 | chip_name = "hawaii_k"; |
| 5783 | else |
| 5784 | chip_name = "hawaii"; |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 5785 | break; |
| 5786 | case CHIP_KAVERI: |
| 5787 | case CHIP_KABINI: |
Alex Deucher | b9a8be9 | 2016-07-29 18:14:39 -0400 | [diff] [blame] | 5788 | case CHIP_MULLINS: |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 5789 | default: BUG(); |
| 5790 | } |
| 5791 | |
| 5792 | snprintf(fw_name, sizeof(fw_name), "radeon/%s_smc.bin", chip_name); |
| 5793 | err = request_firmware(&adev->pm.fw, fw_name, adev->dev); |
| 5794 | if (err) |
| 5795 | goto out; |
| 5796 | err = amdgpu_ucode_validate(adev->pm.fw); |
| 5797 | |
| 5798 | out: |
| 5799 | if (err) { |
| 5800 | printk(KERN_ERR |
| 5801 | "cik_smc: Failed to load firmware \"%s\"\n", |
| 5802 | fw_name); |
| 5803 | release_firmware(adev->pm.fw); |
| 5804 | adev->pm.fw = NULL; |
| 5805 | } |
| 5806 | return err; |
| 5807 | } |
| 5808 | |
| 5809 | static int ci_dpm_init(struct amdgpu_device *adev) |
| 5810 | { |
| 5811 | int index = GetIndexIntoMasterTable(DATA, ASIC_InternalSS_Info); |
| 5812 | SMU7_Discrete_DpmTable *dpm_table; |
| 5813 | struct amdgpu_gpio_rec gpio; |
| 5814 | u16 data_offset, size; |
| 5815 | u8 frev, crev; |
| 5816 | struct ci_power_info *pi; |
| 5817 | int ret; |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 5818 | |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 5819 | pi = kzalloc(sizeof(struct ci_power_info), GFP_KERNEL); |
| 5820 | if (pi == NULL) |
| 5821 | return -ENOMEM; |
| 5822 | adev->pm.dpm.priv = pi; |
| 5823 | |
Alex Deucher | 50171eb | 2016-02-04 10:44:04 -0500 | [diff] [blame] | 5824 | pi->sys_pcie_mask = |
| 5825 | (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_MASK) >> |
| 5826 | CAIL_PCIE_LINK_SPEED_SUPPORT_SHIFT; |
| 5827 | |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 5828 | pi->force_pcie_gen = AMDGPU_PCIE_GEN_INVALID; |
| 5829 | |
| 5830 | pi->pcie_gen_performance.max = AMDGPU_PCIE_GEN1; |
| 5831 | pi->pcie_gen_performance.min = AMDGPU_PCIE_GEN3; |
| 5832 | pi->pcie_gen_powersaving.max = AMDGPU_PCIE_GEN1; |
| 5833 | pi->pcie_gen_powersaving.min = AMDGPU_PCIE_GEN3; |
| 5834 | |
| 5835 | pi->pcie_lane_performance.max = 0; |
| 5836 | pi->pcie_lane_performance.min = 16; |
| 5837 | pi->pcie_lane_powersaving.max = 0; |
| 5838 | pi->pcie_lane_powersaving.min = 16; |
| 5839 | |
| 5840 | ret = ci_get_vbios_boot_values(adev, &pi->vbios_boot_state); |
| 5841 | if (ret) { |
| 5842 | ci_dpm_fini(adev); |
| 5843 | return ret; |
| 5844 | } |
| 5845 | |
| 5846 | ret = amdgpu_get_platform_caps(adev); |
| 5847 | if (ret) { |
| 5848 | ci_dpm_fini(adev); |
| 5849 | return ret; |
| 5850 | } |
| 5851 | |
| 5852 | ret = amdgpu_parse_extended_power_table(adev); |
| 5853 | if (ret) { |
| 5854 | ci_dpm_fini(adev); |
| 5855 | return ret; |
| 5856 | } |
| 5857 | |
| 5858 | ret = ci_parse_power_table(adev); |
| 5859 | if (ret) { |
| 5860 | ci_dpm_fini(adev); |
| 5861 | return ret; |
| 5862 | } |
| 5863 | |
| 5864 | pi->dll_default_on = false; |
| 5865 | pi->sram_end = SMC_RAM_END; |
| 5866 | |
| 5867 | pi->activity_target[0] = CISLAND_TARGETACTIVITY_DFLT; |
| 5868 | pi->activity_target[1] = CISLAND_TARGETACTIVITY_DFLT; |
| 5869 | pi->activity_target[2] = CISLAND_TARGETACTIVITY_DFLT; |
| 5870 | pi->activity_target[3] = CISLAND_TARGETACTIVITY_DFLT; |
| 5871 | pi->activity_target[4] = CISLAND_TARGETACTIVITY_DFLT; |
| 5872 | pi->activity_target[5] = CISLAND_TARGETACTIVITY_DFLT; |
| 5873 | pi->activity_target[6] = CISLAND_TARGETACTIVITY_DFLT; |
| 5874 | pi->activity_target[7] = CISLAND_TARGETACTIVITY_DFLT; |
| 5875 | |
| 5876 | pi->mclk_activity_target = CISLAND_MCLK_TARGETACTIVITY_DFLT; |
| 5877 | |
| 5878 | pi->sclk_dpm_key_disabled = 0; |
| 5879 | pi->mclk_dpm_key_disabled = 0; |
| 5880 | pi->pcie_dpm_key_disabled = 0; |
| 5881 | pi->thermal_sclk_dpm_enabled = 0; |
| 5882 | |
Rex Zhu | 66bc3f7 | 2016-07-28 17:36:35 +0800 | [diff] [blame] | 5883 | if (amdgpu_sclk_deep_sleep_en) |
| 5884 | pi->caps_sclk_ds = true; |
| 5885 | else |
| 5886 | pi->caps_sclk_ds = false; |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 5887 | |
| 5888 | pi->mclk_strobe_mode_threshold = 40000; |
| 5889 | pi->mclk_stutter_mode_threshold = 40000; |
| 5890 | pi->mclk_edc_enable_threshold = 40000; |
| 5891 | pi->mclk_edc_wr_enable_threshold = 40000; |
| 5892 | |
| 5893 | ci_initialize_powertune_defaults(adev); |
| 5894 | |
| 5895 | pi->caps_fps = false; |
| 5896 | |
| 5897 | pi->caps_sclk_throttle_low_notification = false; |
| 5898 | |
| 5899 | pi->caps_uvd_dpm = true; |
| 5900 | pi->caps_vce_dpm = true; |
| 5901 | |
| 5902 | ci_get_leakage_voltages(adev); |
| 5903 | ci_patch_dependency_tables_with_leakage(adev); |
| 5904 | ci_set_private_data_variables_based_on_pptable(adev); |
| 5905 | |
| 5906 | adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries = |
| 5907 | kzalloc(4 * sizeof(struct amdgpu_clock_voltage_dependency_entry), GFP_KERNEL); |
| 5908 | if (!adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries) { |
| 5909 | ci_dpm_fini(adev); |
| 5910 | return -ENOMEM; |
| 5911 | } |
| 5912 | adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.count = 4; |
| 5913 | adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[0].clk = 0; |
| 5914 | adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[0].v = 0; |
| 5915 | adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[1].clk = 36000; |
| 5916 | adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[1].v = 720; |
| 5917 | adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[2].clk = 54000; |
| 5918 | adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[2].v = 810; |
| 5919 | adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[3].clk = 72000; |
| 5920 | adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[3].v = 900; |
| 5921 | |
| 5922 | adev->pm.dpm.dyn_state.mclk_sclk_ratio = 4; |
| 5923 | adev->pm.dpm.dyn_state.sclk_mclk_delta = 15000; |
| 5924 | adev->pm.dpm.dyn_state.vddc_vddci_delta = 200; |
| 5925 | |
| 5926 | adev->pm.dpm.dyn_state.valid_sclk_values.count = 0; |
| 5927 | adev->pm.dpm.dyn_state.valid_sclk_values.values = NULL; |
| 5928 | adev->pm.dpm.dyn_state.valid_mclk_values.count = 0; |
| 5929 | adev->pm.dpm.dyn_state.valid_mclk_values.values = NULL; |
| 5930 | |
| 5931 | if (adev->asic_type == CHIP_HAWAII) { |
| 5932 | pi->thermal_temp_setting.temperature_low = 94500; |
| 5933 | pi->thermal_temp_setting.temperature_high = 95000; |
| 5934 | pi->thermal_temp_setting.temperature_shutdown = 104000; |
| 5935 | } else { |
| 5936 | pi->thermal_temp_setting.temperature_low = 99500; |
| 5937 | pi->thermal_temp_setting.temperature_high = 100000; |
| 5938 | pi->thermal_temp_setting.temperature_shutdown = 104000; |
| 5939 | } |
| 5940 | |
| 5941 | pi->uvd_enabled = false; |
| 5942 | |
| 5943 | dpm_table = &pi->smc_state_table; |
| 5944 | |
| 5945 | gpio = amdgpu_atombios_lookup_gpio(adev, VDDC_VRHOT_GPIO_PINID); |
| 5946 | if (gpio.valid) { |
| 5947 | dpm_table->VRHotGpio = gpio.shift; |
| 5948 | adev->pm.dpm.platform_caps |= ATOM_PP_PLATFORM_CAP_REGULATOR_HOT; |
| 5949 | } else { |
| 5950 | dpm_table->VRHotGpio = CISLANDS_UNUSED_GPIO_PIN; |
| 5951 | adev->pm.dpm.platform_caps &= ~ATOM_PP_PLATFORM_CAP_REGULATOR_HOT; |
| 5952 | } |
| 5953 | |
| 5954 | gpio = amdgpu_atombios_lookup_gpio(adev, PP_AC_DC_SWITCH_GPIO_PINID); |
| 5955 | if (gpio.valid) { |
| 5956 | dpm_table->AcDcGpio = gpio.shift; |
| 5957 | adev->pm.dpm.platform_caps |= ATOM_PP_PLATFORM_CAP_HARDWAREDC; |
| 5958 | } else { |
| 5959 | dpm_table->AcDcGpio = CISLANDS_UNUSED_GPIO_PIN; |
| 5960 | adev->pm.dpm.platform_caps &= ~ATOM_PP_PLATFORM_CAP_HARDWAREDC; |
| 5961 | } |
| 5962 | |
| 5963 | gpio = amdgpu_atombios_lookup_gpio(adev, VDDC_PCC_GPIO_PINID); |
| 5964 | if (gpio.valid) { |
| 5965 | u32 tmp = RREG32_SMC(ixCNB_PWRMGT_CNTL); |
| 5966 | |
| 5967 | switch (gpio.shift) { |
| 5968 | case 0: |
| 5969 | tmp &= ~CNB_PWRMGT_CNTL__GNB_SLOW_MODE_MASK; |
| 5970 | tmp |= 1 << CNB_PWRMGT_CNTL__GNB_SLOW_MODE__SHIFT; |
| 5971 | break; |
| 5972 | case 1: |
| 5973 | tmp &= ~CNB_PWRMGT_CNTL__GNB_SLOW_MODE_MASK; |
| 5974 | tmp |= 2 << CNB_PWRMGT_CNTL__GNB_SLOW_MODE__SHIFT; |
| 5975 | break; |
| 5976 | case 2: |
| 5977 | tmp |= CNB_PWRMGT_CNTL__GNB_SLOW_MASK; |
| 5978 | break; |
| 5979 | case 3: |
| 5980 | tmp |= CNB_PWRMGT_CNTL__FORCE_NB_PS1_MASK; |
| 5981 | break; |
| 5982 | case 4: |
| 5983 | tmp |= CNB_PWRMGT_CNTL__DPM_ENABLED_MASK; |
| 5984 | break; |
| 5985 | default: |
| 5986 | DRM_ERROR("Invalid PCC GPIO: %u!\n", gpio.shift); |
| 5987 | break; |
| 5988 | } |
| 5989 | WREG32_SMC(ixCNB_PWRMGT_CNTL, tmp); |
| 5990 | } |
| 5991 | |
| 5992 | pi->voltage_control = CISLANDS_VOLTAGE_CONTROL_NONE; |
| 5993 | pi->vddci_control = CISLANDS_VOLTAGE_CONTROL_NONE; |
| 5994 | pi->mvdd_control = CISLANDS_VOLTAGE_CONTROL_NONE; |
| 5995 | if (amdgpu_atombios_is_voltage_gpio(adev, VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_GPIO_LUT)) |
| 5996 | pi->voltage_control = CISLANDS_VOLTAGE_CONTROL_BY_GPIO; |
| 5997 | else if (amdgpu_atombios_is_voltage_gpio(adev, VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_SVID2)) |
| 5998 | pi->voltage_control = CISLANDS_VOLTAGE_CONTROL_BY_SVID2; |
| 5999 | |
| 6000 | if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_VDDCI_CONTROL) { |
| 6001 | if (amdgpu_atombios_is_voltage_gpio(adev, VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT)) |
| 6002 | pi->vddci_control = CISLANDS_VOLTAGE_CONTROL_BY_GPIO; |
| 6003 | else if (amdgpu_atombios_is_voltage_gpio(adev, VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_SVID2)) |
| 6004 | pi->vddci_control = CISLANDS_VOLTAGE_CONTROL_BY_SVID2; |
| 6005 | else |
| 6006 | adev->pm.dpm.platform_caps &= ~ATOM_PP_PLATFORM_CAP_VDDCI_CONTROL; |
| 6007 | } |
| 6008 | |
| 6009 | if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_MVDDCONTROL) { |
| 6010 | if (amdgpu_atombios_is_voltage_gpio(adev, VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT)) |
| 6011 | pi->mvdd_control = CISLANDS_VOLTAGE_CONTROL_BY_GPIO; |
| 6012 | else if (amdgpu_atombios_is_voltage_gpio(adev, VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_SVID2)) |
| 6013 | pi->mvdd_control = CISLANDS_VOLTAGE_CONTROL_BY_SVID2; |
| 6014 | else |
| 6015 | adev->pm.dpm.platform_caps &= ~ATOM_PP_PLATFORM_CAP_MVDDCONTROL; |
| 6016 | } |
| 6017 | |
| 6018 | pi->vddc_phase_shed_control = true; |
| 6019 | |
| 6020 | #if defined(CONFIG_ACPI) |
| 6021 | pi->pcie_performance_request = |
| 6022 | amdgpu_acpi_is_pcie_performance_request_supported(adev); |
| 6023 | #else |
| 6024 | pi->pcie_performance_request = false; |
| 6025 | #endif |
| 6026 | |
| 6027 | if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, &size, |
| 6028 | &frev, &crev, &data_offset)) { |
| 6029 | pi->caps_sclk_ss_support = true; |
| 6030 | pi->caps_mclk_ss_support = true; |
| 6031 | pi->dynamic_ss = true; |
| 6032 | } else { |
| 6033 | pi->caps_sclk_ss_support = false; |
| 6034 | pi->caps_mclk_ss_support = false; |
| 6035 | pi->dynamic_ss = true; |
| 6036 | } |
| 6037 | |
| 6038 | if (adev->pm.int_thermal_type != THERMAL_TYPE_NONE) |
| 6039 | pi->thermal_protection = true; |
| 6040 | else |
| 6041 | pi->thermal_protection = false; |
| 6042 | |
| 6043 | pi->caps_dynamic_ac_timing = true; |
| 6044 | |
Rex Zhu | c08770e | 2016-08-24 19:39:06 +0800 | [diff] [blame] | 6045 | pi->uvd_power_gated = true; |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6046 | |
| 6047 | /* make sure dc limits are valid */ |
| 6048 | if ((adev->pm.dpm.dyn_state.max_clock_voltage_on_dc.sclk == 0) || |
| 6049 | (adev->pm.dpm.dyn_state.max_clock_voltage_on_dc.mclk == 0)) |
| 6050 | adev->pm.dpm.dyn_state.max_clock_voltage_on_dc = |
| 6051 | adev->pm.dpm.dyn_state.max_clock_voltage_on_ac; |
| 6052 | |
| 6053 | pi->fan_ctrl_is_in_default_mode = true; |
| 6054 | |
| 6055 | return 0; |
| 6056 | } |
| 6057 | |
| 6058 | static void |
| 6059 | ci_dpm_debugfs_print_current_performance_level(struct amdgpu_device *adev, |
| 6060 | struct seq_file *m) |
| 6061 | { |
| 6062 | struct ci_power_info *pi = ci_get_pi(adev); |
| 6063 | struct amdgpu_ps *rps = &pi->current_rps; |
| 6064 | u32 sclk = ci_get_average_sclk_freq(adev); |
| 6065 | u32 mclk = ci_get_average_mclk_freq(adev); |
Rex Zhu | 9354573 | 2016-01-06 17:08:46 +0800 | [diff] [blame] | 6066 | u32 activity_percent = 50; |
| 6067 | int ret; |
| 6068 | |
| 6069 | ret = ci_read_smc_soft_register(adev, offsetof(SMU7_SoftRegisters, AverageGraphicsA), |
| 6070 | &activity_percent); |
| 6071 | |
| 6072 | if (ret == 0) { |
| 6073 | activity_percent += 0x80; |
| 6074 | activity_percent >>= 8; |
| 6075 | activity_percent = activity_percent > 100 ? 100 : activity_percent; |
| 6076 | } |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6077 | |
| 6078 | seq_printf(m, "uvd %sabled\n", pi->uvd_enabled ? "en" : "dis"); |
| 6079 | seq_printf(m, "vce %sabled\n", rps->vce_active ? "en" : "dis"); |
| 6080 | seq_printf(m, "power level avg sclk: %u mclk: %u\n", |
| 6081 | sclk, mclk); |
Rex Zhu | 9354573 | 2016-01-06 17:08:46 +0800 | [diff] [blame] | 6082 | seq_printf(m, "GPU load: %u %%\n", activity_percent); |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6083 | } |
| 6084 | |
| 6085 | static void ci_dpm_print_power_state(struct amdgpu_device *adev, |
| 6086 | struct amdgpu_ps *rps) |
| 6087 | { |
| 6088 | struct ci_ps *ps = ci_get_ps(rps); |
| 6089 | struct ci_pl *pl; |
| 6090 | int i; |
| 6091 | |
| 6092 | amdgpu_dpm_print_class_info(rps->class, rps->class2); |
| 6093 | amdgpu_dpm_print_cap_info(rps->caps); |
| 6094 | printk("\tuvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk); |
| 6095 | for (i = 0; i < ps->performance_level_count; i++) { |
| 6096 | pl = &ps->performance_levels[i]; |
| 6097 | printk("\t\tpower level %d sclk: %u mclk: %u pcie gen: %u pcie lanes: %u\n", |
| 6098 | i, pl->sclk, pl->mclk, pl->pcie_gen + 1, pl->pcie_lane); |
| 6099 | } |
| 6100 | amdgpu_dpm_print_ps_status(adev, rps); |
| 6101 | } |
| 6102 | |
| 6103 | static u32 ci_dpm_get_sclk(struct amdgpu_device *adev, bool low) |
| 6104 | { |
| 6105 | struct ci_power_info *pi = ci_get_pi(adev); |
| 6106 | struct ci_ps *requested_state = ci_get_ps(&pi->requested_rps); |
| 6107 | |
| 6108 | if (low) |
| 6109 | return requested_state->performance_levels[0].sclk; |
| 6110 | else |
| 6111 | return requested_state->performance_levels[requested_state->performance_level_count - 1].sclk; |
| 6112 | } |
| 6113 | |
| 6114 | static u32 ci_dpm_get_mclk(struct amdgpu_device *adev, bool low) |
| 6115 | { |
| 6116 | struct ci_power_info *pi = ci_get_pi(adev); |
| 6117 | struct ci_ps *requested_state = ci_get_ps(&pi->requested_rps); |
| 6118 | |
| 6119 | if (low) |
| 6120 | return requested_state->performance_levels[0].mclk; |
| 6121 | else |
| 6122 | return requested_state->performance_levels[requested_state->performance_level_count - 1].mclk; |
| 6123 | } |
| 6124 | |
| 6125 | /* get temperature in millidegrees */ |
| 6126 | static int ci_dpm_get_temp(struct amdgpu_device *adev) |
| 6127 | { |
| 6128 | u32 temp; |
| 6129 | int actual_temp = 0; |
| 6130 | |
| 6131 | temp = (RREG32_SMC(ixCG_MULT_THERMAL_STATUS) & CG_MULT_THERMAL_STATUS__CTF_TEMP_MASK) >> |
| 6132 | CG_MULT_THERMAL_STATUS__CTF_TEMP__SHIFT; |
| 6133 | |
| 6134 | if (temp & 0x200) |
| 6135 | actual_temp = 255; |
| 6136 | else |
| 6137 | actual_temp = temp & 0x1ff; |
| 6138 | |
| 6139 | actual_temp = actual_temp * 1000; |
| 6140 | |
| 6141 | return actual_temp; |
| 6142 | } |
| 6143 | |
| 6144 | static int ci_set_temperature_range(struct amdgpu_device *adev) |
| 6145 | { |
| 6146 | int ret; |
| 6147 | |
| 6148 | ret = ci_thermal_enable_alert(adev, false); |
| 6149 | if (ret) |
| 6150 | return ret; |
| 6151 | ret = ci_thermal_set_temperature_range(adev, CISLANDS_TEMP_RANGE_MIN, |
| 6152 | CISLANDS_TEMP_RANGE_MAX); |
| 6153 | if (ret) |
| 6154 | return ret; |
| 6155 | ret = ci_thermal_enable_alert(adev, true); |
| 6156 | if (ret) |
| 6157 | return ret; |
| 6158 | return ret; |
| 6159 | } |
| 6160 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6161 | static int ci_dpm_early_init(void *handle) |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6162 | { |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6163 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 6164 | |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6165 | ci_dpm_set_dpm_funcs(adev); |
| 6166 | ci_dpm_set_irq_funcs(adev); |
| 6167 | |
| 6168 | return 0; |
| 6169 | } |
| 6170 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6171 | static int ci_dpm_late_init(void *handle) |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6172 | { |
| 6173 | int ret; |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6174 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6175 | |
| 6176 | if (!amdgpu_dpm) |
| 6177 | return 0; |
| 6178 | |
Alex Deucher | fa022a9 | 2015-09-30 17:05:40 -0400 | [diff] [blame] | 6179 | /* init the sysfs and debugfs files late */ |
| 6180 | ret = amdgpu_pm_sysfs_init(adev); |
| 6181 | if (ret) |
| 6182 | return ret; |
| 6183 | |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6184 | ret = ci_set_temperature_range(adev); |
| 6185 | if (ret) |
| 6186 | return ret; |
| 6187 | |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6188 | return 0; |
| 6189 | } |
| 6190 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6191 | static int ci_dpm_sw_init(void *handle) |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6192 | { |
| 6193 | int ret; |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6194 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6195 | |
| 6196 | ret = amdgpu_irq_add_id(adev, 230, &adev->pm.dpm.thermal.irq); |
| 6197 | if (ret) |
| 6198 | return ret; |
| 6199 | |
| 6200 | ret = amdgpu_irq_add_id(adev, 231, &adev->pm.dpm.thermal.irq); |
| 6201 | if (ret) |
| 6202 | return ret; |
| 6203 | |
| 6204 | /* default to balanced state */ |
| 6205 | adev->pm.dpm.state = POWER_STATE_TYPE_BALANCED; |
| 6206 | adev->pm.dpm.user_state = POWER_STATE_TYPE_BALANCED; |
| 6207 | adev->pm.dpm.forced_level = AMDGPU_DPM_FORCED_LEVEL_AUTO; |
| 6208 | adev->pm.default_sclk = adev->clock.default_sclk; |
| 6209 | adev->pm.default_mclk = adev->clock.default_mclk; |
| 6210 | adev->pm.current_sclk = adev->clock.default_sclk; |
| 6211 | adev->pm.current_mclk = adev->clock.default_mclk; |
| 6212 | adev->pm.int_thermal_type = THERMAL_TYPE_NONE; |
| 6213 | |
| 6214 | if (amdgpu_dpm == 0) |
| 6215 | return 0; |
| 6216 | |
Christian König | faad24c | 2015-05-28 22:02:26 +0200 | [diff] [blame] | 6217 | ret = ci_dpm_init_microcode(adev); |
| 6218 | if (ret) |
| 6219 | return ret; |
| 6220 | |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6221 | INIT_WORK(&adev->pm.dpm.thermal.work, amdgpu_dpm_thermal_work_handler); |
| 6222 | mutex_lock(&adev->pm.mutex); |
| 6223 | ret = ci_dpm_init(adev); |
| 6224 | if (ret) |
| 6225 | goto dpm_failed; |
| 6226 | adev->pm.dpm.current_ps = adev->pm.dpm.requested_ps = adev->pm.dpm.boot_ps; |
| 6227 | if (amdgpu_dpm == 1) |
| 6228 | amdgpu_pm_print_power_states(adev); |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6229 | mutex_unlock(&adev->pm.mutex); |
| 6230 | DRM_INFO("amdgpu: dpm initialized\n"); |
| 6231 | |
| 6232 | return 0; |
| 6233 | |
| 6234 | dpm_failed: |
| 6235 | ci_dpm_fini(adev); |
| 6236 | mutex_unlock(&adev->pm.mutex); |
| 6237 | DRM_ERROR("amdgpu: dpm initialization failed\n"); |
| 6238 | return ret; |
| 6239 | } |
| 6240 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6241 | static int ci_dpm_sw_fini(void *handle) |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6242 | { |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6243 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 6244 | |
Alex Deucher | 4560738 | 2016-10-21 16:30:10 -0400 | [diff] [blame] | 6245 | flush_work(&adev->pm.dpm.thermal.work); |
| 6246 | |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6247 | mutex_lock(&adev->pm.mutex); |
| 6248 | amdgpu_pm_sysfs_fini(adev); |
| 6249 | ci_dpm_fini(adev); |
| 6250 | mutex_unlock(&adev->pm.mutex); |
| 6251 | |
Alex Deucher | 768c95e | 2016-06-01 11:09:01 -0400 | [diff] [blame] | 6252 | release_firmware(adev->pm.fw); |
| 6253 | adev->pm.fw = NULL; |
| 6254 | |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6255 | return 0; |
| 6256 | } |
| 6257 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6258 | static int ci_dpm_hw_init(void *handle) |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6259 | { |
| 6260 | int ret; |
| 6261 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6262 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 6263 | |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6264 | if (!amdgpu_dpm) |
| 6265 | return 0; |
| 6266 | |
| 6267 | mutex_lock(&adev->pm.mutex); |
| 6268 | ci_dpm_setup_asic(adev); |
| 6269 | ret = ci_dpm_enable(adev); |
| 6270 | if (ret) |
| 6271 | adev->pm.dpm_enabled = false; |
| 6272 | else |
| 6273 | adev->pm.dpm_enabled = true; |
| 6274 | mutex_unlock(&adev->pm.mutex); |
| 6275 | |
| 6276 | return ret; |
| 6277 | } |
| 6278 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6279 | static int ci_dpm_hw_fini(void *handle) |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6280 | { |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6281 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 6282 | |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6283 | if (adev->pm.dpm_enabled) { |
| 6284 | mutex_lock(&adev->pm.mutex); |
| 6285 | ci_dpm_disable(adev); |
| 6286 | mutex_unlock(&adev->pm.mutex); |
| 6287 | } |
| 6288 | |
| 6289 | return 0; |
| 6290 | } |
| 6291 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6292 | static int ci_dpm_suspend(void *handle) |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6293 | { |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6294 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 6295 | |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6296 | if (adev->pm.dpm_enabled) { |
| 6297 | mutex_lock(&adev->pm.mutex); |
| 6298 | /* disable dpm */ |
| 6299 | ci_dpm_disable(adev); |
| 6300 | /* reset the power state */ |
| 6301 | adev->pm.dpm.current_ps = adev->pm.dpm.requested_ps = adev->pm.dpm.boot_ps; |
| 6302 | mutex_unlock(&adev->pm.mutex); |
| 6303 | } |
| 6304 | return 0; |
| 6305 | } |
| 6306 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6307 | static int ci_dpm_resume(void *handle) |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6308 | { |
| 6309 | int ret; |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6310 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6311 | |
| 6312 | if (adev->pm.dpm_enabled) { |
| 6313 | /* asic init will reset to the boot state */ |
| 6314 | mutex_lock(&adev->pm.mutex); |
| 6315 | ci_dpm_setup_asic(adev); |
| 6316 | ret = ci_dpm_enable(adev); |
| 6317 | if (ret) |
| 6318 | adev->pm.dpm_enabled = false; |
| 6319 | else |
| 6320 | adev->pm.dpm_enabled = true; |
| 6321 | mutex_unlock(&adev->pm.mutex); |
| 6322 | if (adev->pm.dpm_enabled) |
| 6323 | amdgpu_pm_compute_clocks(adev); |
| 6324 | } |
| 6325 | return 0; |
| 6326 | } |
| 6327 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6328 | static bool ci_dpm_is_idle(void *handle) |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6329 | { |
| 6330 | /* XXX */ |
| 6331 | return true; |
| 6332 | } |
| 6333 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6334 | static int ci_dpm_wait_for_idle(void *handle) |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6335 | { |
| 6336 | /* XXX */ |
| 6337 | return 0; |
| 6338 | } |
| 6339 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6340 | static int ci_dpm_soft_reset(void *handle) |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6341 | { |
| 6342 | return 0; |
| 6343 | } |
| 6344 | |
| 6345 | static int ci_dpm_set_interrupt_state(struct amdgpu_device *adev, |
| 6346 | struct amdgpu_irq_src *source, |
| 6347 | unsigned type, |
| 6348 | enum amdgpu_interrupt_state state) |
| 6349 | { |
| 6350 | u32 cg_thermal_int; |
| 6351 | |
| 6352 | switch (type) { |
| 6353 | case AMDGPU_THERMAL_IRQ_LOW_TO_HIGH: |
| 6354 | switch (state) { |
| 6355 | case AMDGPU_IRQ_STATE_DISABLE: |
| 6356 | cg_thermal_int = RREG32_SMC(ixCG_THERMAL_INT); |
Rex Zhu | c305fd5 | 2015-10-13 13:57:52 +0800 | [diff] [blame] | 6357 | cg_thermal_int |= CG_THERMAL_INT_CTRL__THERM_INTH_MASK_MASK; |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6358 | WREG32_SMC(ixCG_THERMAL_INT, cg_thermal_int); |
| 6359 | break; |
| 6360 | case AMDGPU_IRQ_STATE_ENABLE: |
| 6361 | cg_thermal_int = RREG32_SMC(ixCG_THERMAL_INT); |
Rex Zhu | c305fd5 | 2015-10-13 13:57:52 +0800 | [diff] [blame] | 6362 | cg_thermal_int &= ~CG_THERMAL_INT_CTRL__THERM_INTH_MASK_MASK; |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6363 | WREG32_SMC(ixCG_THERMAL_INT, cg_thermal_int); |
| 6364 | break; |
| 6365 | default: |
| 6366 | break; |
| 6367 | } |
| 6368 | break; |
| 6369 | |
| 6370 | case AMDGPU_THERMAL_IRQ_HIGH_TO_LOW: |
| 6371 | switch (state) { |
| 6372 | case AMDGPU_IRQ_STATE_DISABLE: |
| 6373 | cg_thermal_int = RREG32_SMC(ixCG_THERMAL_INT); |
Rex Zhu | c305fd5 | 2015-10-13 13:57:52 +0800 | [diff] [blame] | 6374 | cg_thermal_int |= CG_THERMAL_INT_CTRL__THERM_INTL_MASK_MASK; |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6375 | WREG32_SMC(ixCG_THERMAL_INT, cg_thermal_int); |
| 6376 | break; |
| 6377 | case AMDGPU_IRQ_STATE_ENABLE: |
| 6378 | cg_thermal_int = RREG32_SMC(ixCG_THERMAL_INT); |
Rex Zhu | c305fd5 | 2015-10-13 13:57:52 +0800 | [diff] [blame] | 6379 | cg_thermal_int &= ~CG_THERMAL_INT_CTRL__THERM_INTL_MASK_MASK; |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6380 | WREG32_SMC(ixCG_THERMAL_INT, cg_thermal_int); |
| 6381 | break; |
| 6382 | default: |
| 6383 | break; |
| 6384 | } |
| 6385 | break; |
| 6386 | |
| 6387 | default: |
| 6388 | break; |
| 6389 | } |
| 6390 | return 0; |
| 6391 | } |
| 6392 | |
| 6393 | static int ci_dpm_process_interrupt(struct amdgpu_device *adev, |
Christian König | edf600d | 2016-05-03 15:54:54 +0200 | [diff] [blame] | 6394 | struct amdgpu_irq_src *source, |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6395 | struct amdgpu_iv_entry *entry) |
| 6396 | { |
| 6397 | bool queue_thermal = false; |
| 6398 | |
| 6399 | if (entry == NULL) |
| 6400 | return -EINVAL; |
| 6401 | |
| 6402 | switch (entry->src_id) { |
| 6403 | case 230: /* thermal low to high */ |
| 6404 | DRM_DEBUG("IH: thermal low to high\n"); |
| 6405 | adev->pm.dpm.thermal.high_to_low = false; |
| 6406 | queue_thermal = true; |
| 6407 | break; |
| 6408 | case 231: /* thermal high to low */ |
| 6409 | DRM_DEBUG("IH: thermal high to low\n"); |
| 6410 | adev->pm.dpm.thermal.high_to_low = true; |
| 6411 | queue_thermal = true; |
| 6412 | break; |
| 6413 | default: |
| 6414 | break; |
| 6415 | } |
| 6416 | |
| 6417 | if (queue_thermal) |
| 6418 | schedule_work(&adev->pm.dpm.thermal.work); |
| 6419 | |
| 6420 | return 0; |
| 6421 | } |
| 6422 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6423 | static int ci_dpm_set_clockgating_state(void *handle, |
| 6424 | enum amd_clockgating_state state) |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6425 | { |
| 6426 | return 0; |
| 6427 | } |
| 6428 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6429 | static int ci_dpm_set_powergating_state(void *handle, |
| 6430 | enum amd_powergating_state state) |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6431 | { |
| 6432 | return 0; |
| 6433 | } |
| 6434 | |
Eric Huang | 19fbc43 | 2016-05-19 15:50:09 -0400 | [diff] [blame] | 6435 | static int ci_dpm_print_clock_levels(struct amdgpu_device *adev, |
| 6436 | enum pp_clock_type type, char *buf) |
| 6437 | { |
| 6438 | struct ci_power_info *pi = ci_get_pi(adev); |
| 6439 | struct ci_single_dpm_table *sclk_table = &pi->dpm_table.sclk_table; |
| 6440 | struct ci_single_dpm_table *mclk_table = &pi->dpm_table.mclk_table; |
| 6441 | struct ci_single_dpm_table *pcie_table = &pi->dpm_table.pcie_speed_table; |
| 6442 | |
| 6443 | int i, now, size = 0; |
| 6444 | uint32_t clock, pcie_speed; |
| 6445 | |
| 6446 | switch (type) { |
| 6447 | case PP_SCLK: |
| 6448 | amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_API_GetSclkFrequency); |
| 6449 | clock = RREG32(mmSMC_MSG_ARG_0); |
| 6450 | |
| 6451 | for (i = 0; i < sclk_table->count; i++) { |
| 6452 | if (clock > sclk_table->dpm_levels[i].value) |
| 6453 | continue; |
| 6454 | break; |
| 6455 | } |
| 6456 | now = i; |
| 6457 | |
| 6458 | for (i = 0; i < sclk_table->count; i++) |
| 6459 | size += sprintf(buf + size, "%d: %uMhz %s\n", |
| 6460 | i, sclk_table->dpm_levels[i].value / 100, |
| 6461 | (i == now) ? "*" : ""); |
| 6462 | break; |
| 6463 | case PP_MCLK: |
| 6464 | amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_API_GetMclkFrequency); |
| 6465 | clock = RREG32(mmSMC_MSG_ARG_0); |
| 6466 | |
| 6467 | for (i = 0; i < mclk_table->count; i++) { |
| 6468 | if (clock > mclk_table->dpm_levels[i].value) |
| 6469 | continue; |
| 6470 | break; |
| 6471 | } |
| 6472 | now = i; |
| 6473 | |
| 6474 | for (i = 0; i < mclk_table->count; i++) |
| 6475 | size += sprintf(buf + size, "%d: %uMhz %s\n", |
| 6476 | i, mclk_table->dpm_levels[i].value / 100, |
| 6477 | (i == now) ? "*" : ""); |
| 6478 | break; |
| 6479 | case PP_PCIE: |
| 6480 | pcie_speed = ci_get_current_pcie_speed(adev); |
| 6481 | for (i = 0; i < pcie_table->count; i++) { |
| 6482 | if (pcie_speed != pcie_table->dpm_levels[i].value) |
| 6483 | continue; |
| 6484 | break; |
| 6485 | } |
| 6486 | now = i; |
| 6487 | |
| 6488 | for (i = 0; i < pcie_table->count; i++) |
| 6489 | size += sprintf(buf + size, "%d: %s %s\n", i, |
| 6490 | (pcie_table->dpm_levels[i].value == 0) ? "2.5GB, x1" : |
| 6491 | (pcie_table->dpm_levels[i].value == 1) ? "5.0GB, x16" : |
| 6492 | (pcie_table->dpm_levels[i].value == 2) ? "8.0GB, x16" : "", |
| 6493 | (i == now) ? "*" : ""); |
| 6494 | break; |
| 6495 | default: |
| 6496 | break; |
| 6497 | } |
| 6498 | |
| 6499 | return size; |
| 6500 | } |
| 6501 | |
| 6502 | static int ci_dpm_force_clock_level(struct amdgpu_device *adev, |
| 6503 | enum pp_clock_type type, uint32_t mask) |
| 6504 | { |
| 6505 | struct ci_power_info *pi = ci_get_pi(adev); |
| 6506 | |
| 6507 | if (adev->pm.dpm.forced_level |
| 6508 | != AMDGPU_DPM_FORCED_LEVEL_MANUAL) |
| 6509 | return -EINVAL; |
| 6510 | |
| 6511 | switch (type) { |
| 6512 | case PP_SCLK: |
| 6513 | if (!pi->sclk_dpm_key_disabled) |
| 6514 | amdgpu_ci_send_msg_to_smc_with_parameter(adev, |
| 6515 | PPSMC_MSG_SCLKDPM_SetEnabledMask, |
| 6516 | pi->dpm_level_enable_mask.sclk_dpm_enable_mask & mask); |
| 6517 | break; |
| 6518 | |
| 6519 | case PP_MCLK: |
| 6520 | if (!pi->mclk_dpm_key_disabled) |
| 6521 | amdgpu_ci_send_msg_to_smc_with_parameter(adev, |
| 6522 | PPSMC_MSG_MCLKDPM_SetEnabledMask, |
| 6523 | pi->dpm_level_enable_mask.mclk_dpm_enable_mask & mask); |
| 6524 | break; |
| 6525 | |
| 6526 | case PP_PCIE: |
| 6527 | { |
| 6528 | uint32_t tmp = mask & pi->dpm_level_enable_mask.pcie_dpm_enable_mask; |
| 6529 | uint32_t level = 0; |
| 6530 | |
| 6531 | while (tmp >>= 1) |
| 6532 | level++; |
| 6533 | |
| 6534 | if (!pi->pcie_dpm_key_disabled) |
| 6535 | amdgpu_ci_send_msg_to_smc_with_parameter(adev, |
| 6536 | PPSMC_MSG_PCIeDPM_ForceLevel, |
| 6537 | level); |
| 6538 | break; |
| 6539 | } |
| 6540 | default: |
| 6541 | break; |
| 6542 | } |
| 6543 | |
| 6544 | return 0; |
| 6545 | } |
| 6546 | |
Eric Huang | 3cc2591 | 2016-05-19 15:54:35 -0400 | [diff] [blame] | 6547 | static int ci_dpm_get_sclk_od(struct amdgpu_device *adev) |
| 6548 | { |
| 6549 | struct ci_power_info *pi = ci_get_pi(adev); |
| 6550 | struct ci_single_dpm_table *sclk_table = &(pi->dpm_table.sclk_table); |
| 6551 | struct ci_single_dpm_table *golden_sclk_table = |
| 6552 | &(pi->golden_dpm_table.sclk_table); |
| 6553 | int value; |
| 6554 | |
| 6555 | value = (sclk_table->dpm_levels[sclk_table->count - 1].value - |
| 6556 | golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value) * |
| 6557 | 100 / |
| 6558 | golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value; |
| 6559 | |
| 6560 | return value; |
| 6561 | } |
| 6562 | |
| 6563 | static int ci_dpm_set_sclk_od(struct amdgpu_device *adev, uint32_t value) |
| 6564 | { |
| 6565 | struct ci_power_info *pi = ci_get_pi(adev); |
| 6566 | struct ci_ps *ps = ci_get_ps(adev->pm.dpm.requested_ps); |
| 6567 | struct ci_single_dpm_table *golden_sclk_table = |
| 6568 | &(pi->golden_dpm_table.sclk_table); |
| 6569 | |
| 6570 | if (value > 20) |
| 6571 | value = 20; |
| 6572 | |
| 6573 | ps->performance_levels[ps->performance_level_count - 1].sclk = |
| 6574 | golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value * |
| 6575 | value / 100 + |
| 6576 | golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value; |
| 6577 | |
| 6578 | return 0; |
| 6579 | } |
| 6580 | |
Eric Huang | 40899d5 | 2016-05-24 15:43:53 -0400 | [diff] [blame] | 6581 | static int ci_dpm_get_mclk_od(struct amdgpu_device *adev) |
| 6582 | { |
| 6583 | struct ci_power_info *pi = ci_get_pi(adev); |
| 6584 | struct ci_single_dpm_table *mclk_table = &(pi->dpm_table.mclk_table); |
| 6585 | struct ci_single_dpm_table *golden_mclk_table = |
| 6586 | &(pi->golden_dpm_table.mclk_table); |
| 6587 | int value; |
| 6588 | |
| 6589 | value = (mclk_table->dpm_levels[mclk_table->count - 1].value - |
| 6590 | golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value) * |
| 6591 | 100 / |
| 6592 | golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value; |
| 6593 | |
| 6594 | return value; |
| 6595 | } |
| 6596 | |
| 6597 | static int ci_dpm_set_mclk_od(struct amdgpu_device *adev, uint32_t value) |
| 6598 | { |
| 6599 | struct ci_power_info *pi = ci_get_pi(adev); |
| 6600 | struct ci_ps *ps = ci_get_ps(adev->pm.dpm.requested_ps); |
| 6601 | struct ci_single_dpm_table *golden_mclk_table = |
| 6602 | &(pi->golden_dpm_table.mclk_table); |
| 6603 | |
| 6604 | if (value > 20) |
| 6605 | value = 20; |
| 6606 | |
| 6607 | ps->performance_levels[ps->performance_level_count - 1].mclk = |
| 6608 | golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value * |
| 6609 | value / 100 + |
| 6610 | golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value; |
| 6611 | |
| 6612 | return 0; |
| 6613 | } |
| 6614 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 6615 | const struct amd_ip_funcs ci_dpm_ip_funcs = { |
Tom St Denis | 88a907d | 2016-05-04 14:28:35 -0400 | [diff] [blame] | 6616 | .name = "ci_dpm", |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6617 | .early_init = ci_dpm_early_init, |
| 6618 | .late_init = ci_dpm_late_init, |
| 6619 | .sw_init = ci_dpm_sw_init, |
| 6620 | .sw_fini = ci_dpm_sw_fini, |
| 6621 | .hw_init = ci_dpm_hw_init, |
| 6622 | .hw_fini = ci_dpm_hw_fini, |
| 6623 | .suspend = ci_dpm_suspend, |
| 6624 | .resume = ci_dpm_resume, |
| 6625 | .is_idle = ci_dpm_is_idle, |
| 6626 | .wait_for_idle = ci_dpm_wait_for_idle, |
| 6627 | .soft_reset = ci_dpm_soft_reset, |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6628 | .set_clockgating_state = ci_dpm_set_clockgating_state, |
| 6629 | .set_powergating_state = ci_dpm_set_powergating_state, |
| 6630 | }; |
| 6631 | |
| 6632 | static const struct amdgpu_dpm_funcs ci_dpm_funcs = { |
| 6633 | .get_temperature = &ci_dpm_get_temp, |
| 6634 | .pre_set_power_state = &ci_dpm_pre_set_power_state, |
| 6635 | .set_power_state = &ci_dpm_set_power_state, |
| 6636 | .post_set_power_state = &ci_dpm_post_set_power_state, |
| 6637 | .display_configuration_changed = &ci_dpm_display_configuration_changed, |
| 6638 | .get_sclk = &ci_dpm_get_sclk, |
| 6639 | .get_mclk = &ci_dpm_get_mclk, |
| 6640 | .print_power_state = &ci_dpm_print_power_state, |
| 6641 | .debugfs_print_current_performance_level = &ci_dpm_debugfs_print_current_performance_level, |
| 6642 | .force_performance_level = &ci_dpm_force_performance_level, |
| 6643 | .vblank_too_short = &ci_dpm_vblank_too_short, |
| 6644 | .powergate_uvd = &ci_dpm_powergate_uvd, |
| 6645 | .set_fan_control_mode = &ci_dpm_set_fan_control_mode, |
| 6646 | .get_fan_control_mode = &ci_dpm_get_fan_control_mode, |
| 6647 | .set_fan_speed_percent = &ci_dpm_set_fan_speed_percent, |
| 6648 | .get_fan_speed_percent = &ci_dpm_get_fan_speed_percent, |
Eric Huang | 19fbc43 | 2016-05-19 15:50:09 -0400 | [diff] [blame] | 6649 | .print_clock_levels = ci_dpm_print_clock_levels, |
| 6650 | .force_clock_level = ci_dpm_force_clock_level, |
Eric Huang | 3cc2591 | 2016-05-19 15:54:35 -0400 | [diff] [blame] | 6651 | .get_sclk_od = ci_dpm_get_sclk_od, |
| 6652 | .set_sclk_od = ci_dpm_set_sclk_od, |
Eric Huang | 40899d5 | 2016-05-24 15:43:53 -0400 | [diff] [blame] | 6653 | .get_mclk_od = ci_dpm_get_mclk_od, |
| 6654 | .set_mclk_od = ci_dpm_set_mclk_od, |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 6655 | }; |
| 6656 | |
| 6657 | static void ci_dpm_set_dpm_funcs(struct amdgpu_device *adev) |
| 6658 | { |
| 6659 | if (adev->pm.funcs == NULL) |
| 6660 | adev->pm.funcs = &ci_dpm_funcs; |
| 6661 | } |
| 6662 | |
| 6663 | static const struct amdgpu_irq_src_funcs ci_dpm_irq_funcs = { |
| 6664 | .set = ci_dpm_set_interrupt_state, |
| 6665 | .process = ci_dpm_process_interrupt, |
| 6666 | }; |
| 6667 | |
| 6668 | static void ci_dpm_set_irq_funcs(struct amdgpu_device *adev) |
| 6669 | { |
| 6670 | adev->pm.dpm.thermal.irq.num_types = AMDGPU_THERMAL_IRQ_LAST; |
| 6671 | adev->pm.dpm.thermal.irq.funcs = &ci_dpm_irq_funcs; |
| 6672 | } |