2 * Copyright 2013 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
24 #include <linux/firmware.h>
27 #include "amdgpu_pm.h"
28 #include "amdgpu_ucode.h"
30 #include "amdgpu_dpm.h"
34 #include <linux/seq_file.h>
36 #include "smu/smu_7_0_1_d.h"
37 #include "smu/smu_7_0_1_sh_mask.h"
39 #include "dce/dce_8_0_d.h"
40 #include "dce/dce_8_0_sh_mask.h"
42 #include "bif/bif_4_1_d.h"
43 #include "bif/bif_4_1_sh_mask.h"
45 #include "gca/gfx_7_2_d.h"
46 #include "gca/gfx_7_2_sh_mask.h"
48 #include "gmc/gmc_7_1_d.h"
49 #include "gmc/gmc_7_1_sh_mask.h"
51 MODULE_FIRMWARE("radeon/bonaire_smc.bin");
52 MODULE_FIRMWARE("radeon/hawaii_smc.bin");
54 #define MC_CG_ARB_FREQ_F0 0x0a
55 #define MC_CG_ARB_FREQ_F1 0x0b
56 #define MC_CG_ARB_FREQ_F2 0x0c
57 #define MC_CG_ARB_FREQ_F3 0x0d
59 #define SMC_RAM_END 0x40000
61 #define VOLTAGE_SCALE 4
62 #define VOLTAGE_VID_OFFSET_SCALE1 625
63 #define VOLTAGE_VID_OFFSET_SCALE2 100
65 static const struct ci_pt_defaults defaults_hawaii_xt =
67 1, 0xF, 0xFD, 0x19, 5, 0x14, 0, 0xB0000,
68 { 0x2E, 0x00, 0x00, 0x88, 0x00, 0x00, 0x72, 0x60, 0x51, 0xA7, 0x79, 0x6B, 0x90, 0xBD, 0x79 },
69 { 0x217, 0x217, 0x217, 0x242, 0x242, 0x242, 0x269, 0x269, 0x269, 0x2A1, 0x2A1, 0x2A1, 0x2C9, 0x2C9, 0x2C9 }
72 static const struct ci_pt_defaults defaults_hawaii_pro =
74 1, 0xF, 0xFD, 0x19, 5, 0x14, 0, 0x65062,
75 { 0x2E, 0x00, 0x00, 0x88, 0x00, 0x00, 0x72, 0x60, 0x51, 0xA7, 0x79, 0x6B, 0x90, 0xBD, 0x79 },
76 { 0x217, 0x217, 0x217, 0x242, 0x242, 0x242, 0x269, 0x269, 0x269, 0x2A1, 0x2A1, 0x2A1, 0x2C9, 0x2C9, 0x2C9 }
79 static const struct ci_pt_defaults defaults_bonaire_xt =
81 1, 0xF, 0xFD, 0x19, 5, 45, 0, 0xB0000,
82 { 0x79, 0x253, 0x25D, 0xAE, 0x72, 0x80, 0x83, 0x86, 0x6F, 0xC8, 0xC9, 0xC9, 0x2F, 0x4D, 0x61 },
83 { 0x17C, 0x172, 0x180, 0x1BC, 0x1B3, 0x1BD, 0x206, 0x200, 0x203, 0x25D, 0x25A, 0x255, 0x2C3, 0x2C5, 0x2B4 }
86 static const struct ci_pt_defaults defaults_bonaire_pro =
88 1, 0xF, 0xFD, 0x19, 5, 45, 0, 0x65062,
89 { 0x8C, 0x23F, 0x244, 0xA6, 0x83, 0x85, 0x86, 0x86, 0x83, 0xDB, 0xDB, 0xDA, 0x67, 0x60, 0x5F },
90 { 0x187, 0x193, 0x193, 0x1C7, 0x1D1, 0x1D1, 0x210, 0x219, 0x219, 0x266, 0x26C, 0x26C, 0x2C9, 0x2CB, 0x2CB }
93 static const struct ci_pt_defaults defaults_saturn_xt =
95 1, 0xF, 0xFD, 0x19, 5, 55, 0, 0x70000,
96 { 0x8C, 0x247, 0x249, 0xA6, 0x80, 0x81, 0x8B, 0x89, 0x86, 0xC9, 0xCA, 0xC9, 0x4D, 0x4D, 0x4D },
97 { 0x187, 0x187, 0x187, 0x1C7, 0x1C7, 0x1C7, 0x210, 0x210, 0x210, 0x266, 0x266, 0x266, 0x2C9, 0x2C9, 0x2C9 }
100 static const struct ci_pt_defaults defaults_saturn_pro =
102 1, 0xF, 0xFD, 0x19, 5, 55, 0, 0x30000,
103 { 0x96, 0x21D, 0x23B, 0xA1, 0x85, 0x87, 0x83, 0x84, 0x81, 0xE6, 0xE6, 0xE6, 0x71, 0x6A, 0x6A },
104 { 0x193, 0x19E, 0x19E, 0x1D2, 0x1DC, 0x1DC, 0x21A, 0x223, 0x223, 0x26E, 0x27E, 0x274, 0x2CF, 0x2D2, 0x2D2 }
107 static const struct ci_pt_config_reg didt_config_ci[] =
109 { 0x10, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
110 { 0x10, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
111 { 0x10, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
112 { 0x10, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
113 { 0x11, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
114 { 0x11, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
115 { 0x11, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
116 { 0x11, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
117 { 0x12, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
118 { 0x12, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
119 { 0x12, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
120 { 0x12, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
121 { 0x2, 0x00003fff, 0, 0x4, CISLANDS_CONFIGREG_DIDT_IND },
122 { 0x2, 0x03ff0000, 16, 0x80, CISLANDS_CONFIGREG_DIDT_IND },
123 { 0x2, 0x78000000, 27, 0x3, CISLANDS_CONFIGREG_DIDT_IND },
124 { 0x1, 0x0000ffff, 0, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND },
125 { 0x1, 0xffff0000, 16, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND },
126 { 0x0, 0x00000001, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
127 { 0x30, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
128 { 0x30, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
129 { 0x30, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
130 { 0x30, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
131 { 0x31, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
132 { 0x31, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
133 { 0x31, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
134 { 0x31, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
135 { 0x32, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
136 { 0x32, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
137 { 0x32, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
138 { 0x32, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
139 { 0x22, 0x00003fff, 0, 0x4, CISLANDS_CONFIGREG_DIDT_IND },
140 { 0x22, 0x03ff0000, 16, 0x80, CISLANDS_CONFIGREG_DIDT_IND },
141 { 0x22, 0x78000000, 27, 0x3, CISLANDS_CONFIGREG_DIDT_IND },
142 { 0x21, 0x0000ffff, 0, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND },
143 { 0x21, 0xffff0000, 16, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND },
144 { 0x20, 0x00000001, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
145 { 0x50, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
146 { 0x50, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
147 { 0x50, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
148 { 0x50, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
149 { 0x51, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
150 { 0x51, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
151 { 0x51, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
152 { 0x51, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
153 { 0x52, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
154 { 0x52, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
155 { 0x52, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
156 { 0x52, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
157 { 0x42, 0x00003fff, 0, 0x4, CISLANDS_CONFIGREG_DIDT_IND },
158 { 0x42, 0x03ff0000, 16, 0x80, CISLANDS_CONFIGREG_DIDT_IND },
159 { 0x42, 0x78000000, 27, 0x3, CISLANDS_CONFIGREG_DIDT_IND },
160 { 0x41, 0x0000ffff, 0, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND },
161 { 0x41, 0xffff0000, 16, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND },
162 { 0x40, 0x00000001, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
163 { 0x70, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
164 { 0x70, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
165 { 0x70, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
166 { 0x70, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
167 { 0x71, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
168 { 0x71, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
169 { 0x71, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
170 { 0x71, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
171 { 0x72, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
172 { 0x72, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
173 { 0x72, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
174 { 0x72, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
175 { 0x62, 0x00003fff, 0, 0x4, CISLANDS_CONFIGREG_DIDT_IND },
176 { 0x62, 0x03ff0000, 16, 0x80, CISLANDS_CONFIGREG_DIDT_IND },
177 { 0x62, 0x78000000, 27, 0x3, CISLANDS_CONFIGREG_DIDT_IND },
178 { 0x61, 0x0000ffff, 0, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND },
179 { 0x61, 0xffff0000, 16, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND },
180 { 0x60, 0x00000001, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND },
184 static u8 ci_get_memory_module_index(struct amdgpu_device *adev)
186 return (u8) ((RREG32(mmBIOS_SCRATCH_4) >> 16) & 0xff);
189 #define MC_CG_ARB_FREQ_F0 0x0a
190 #define MC_CG_ARB_FREQ_F1 0x0b
191 #define MC_CG_ARB_FREQ_F2 0x0c
192 #define MC_CG_ARB_FREQ_F3 0x0d
194 static int ci_copy_and_switch_arb_sets(struct amdgpu_device *adev,
195 u32 arb_freq_src, u32 arb_freq_dest)
197 u32 mc_arb_dram_timing;
198 u32 mc_arb_dram_timing2;
202 switch (arb_freq_src) {
203 case MC_CG_ARB_FREQ_F0:
204 mc_arb_dram_timing = RREG32(mmMC_ARB_DRAM_TIMING);
205 mc_arb_dram_timing2 = RREG32(mmMC_ARB_DRAM_TIMING2);
206 burst_time = (RREG32(mmMC_ARB_BURST_TIME) & MC_ARB_BURST_TIME__STATE0_MASK) >>
207 MC_ARB_BURST_TIME__STATE0__SHIFT;
209 case MC_CG_ARB_FREQ_F1:
210 mc_arb_dram_timing = RREG32(mmMC_ARB_DRAM_TIMING_1);
211 mc_arb_dram_timing2 = RREG32(mmMC_ARB_DRAM_TIMING2_1);
212 burst_time = (RREG32(mmMC_ARB_BURST_TIME) & MC_ARB_BURST_TIME__STATE1_MASK) >>
213 MC_ARB_BURST_TIME__STATE1__SHIFT;
219 switch (arb_freq_dest) {
220 case MC_CG_ARB_FREQ_F0:
221 WREG32(mmMC_ARB_DRAM_TIMING, mc_arb_dram_timing);
222 WREG32(mmMC_ARB_DRAM_TIMING2, mc_arb_dram_timing2);
223 WREG32_P(mmMC_ARB_BURST_TIME, (burst_time << MC_ARB_BURST_TIME__STATE0__SHIFT),
224 ~MC_ARB_BURST_TIME__STATE0_MASK);
226 case MC_CG_ARB_FREQ_F1:
227 WREG32(mmMC_ARB_DRAM_TIMING_1, mc_arb_dram_timing);
228 WREG32(mmMC_ARB_DRAM_TIMING2_1, mc_arb_dram_timing2);
229 WREG32_P(mmMC_ARB_BURST_TIME, (burst_time << MC_ARB_BURST_TIME__STATE1__SHIFT),
230 ~MC_ARB_BURST_TIME__STATE1_MASK);
236 mc_cg_config = RREG32(mmMC_CG_CONFIG) | 0x0000000F;
237 WREG32(mmMC_CG_CONFIG, mc_cg_config);
238 WREG32_P(mmMC_ARB_CG, (arb_freq_dest) << MC_ARB_CG__CG_ARB_REQ__SHIFT,
239 ~MC_ARB_CG__CG_ARB_REQ_MASK);
244 static u8 ci_get_ddr3_mclk_frequency_ratio(u32 memory_clock)
248 if (memory_clock < 10000)
250 else if (memory_clock >= 80000)
251 mc_para_index = 0x0f;
253 mc_para_index = (u8)((memory_clock - 10000) / 5000 + 1);
254 return mc_para_index;
257 static u8 ci_get_mclk_frequency_ratio(u32 memory_clock, bool strobe_mode)
262 if (memory_clock < 12500)
263 mc_para_index = 0x00;
264 else if (memory_clock > 47500)
265 mc_para_index = 0x0f;
267 mc_para_index = (u8)((memory_clock - 10000) / 2500);
269 if (memory_clock < 65000)
270 mc_para_index = 0x00;
271 else if (memory_clock > 135000)
272 mc_para_index = 0x0f;
274 mc_para_index = (u8)((memory_clock - 60000) / 5000);
276 return mc_para_index;
279 static void ci_trim_voltage_table_to_fit_state_table(struct amdgpu_device *adev,
280 u32 max_voltage_steps,
281 struct atom_voltage_table *voltage_table)
283 unsigned int i, diff;
285 if (voltage_table->count <= max_voltage_steps)
288 diff = voltage_table->count - max_voltage_steps;
290 for (i = 0; i < max_voltage_steps; i++)
291 voltage_table->entries[i] = voltage_table->entries[i + diff];
293 voltage_table->count = max_voltage_steps;
296 static int ci_get_std_voltage_value_sidd(struct amdgpu_device *adev,
297 struct atom_voltage_table_entry *voltage_table,
298 u16 *std_voltage_hi_sidd, u16 *std_voltage_lo_sidd);
299 static int ci_set_power_limit(struct amdgpu_device *adev, u32 n);
300 static int ci_set_overdrive_target_tdp(struct amdgpu_device *adev,
302 static int ci_update_uvd_dpm(struct amdgpu_device *adev, bool gate);
303 static void ci_dpm_set_dpm_funcs(struct amdgpu_device *adev);
304 static void ci_dpm_set_irq_funcs(struct amdgpu_device *adev);
306 static PPSMC_Result amdgpu_ci_send_msg_to_smc_with_parameter(struct amdgpu_device *adev,
307 PPSMC_Msg msg, u32 parameter);
308 static void ci_thermal_start_smc_fan_control(struct amdgpu_device *adev);
309 static void ci_fan_ctrl_set_default_mode(struct amdgpu_device *adev);
311 static struct ci_power_info *ci_get_pi(struct amdgpu_device *adev)
313 struct ci_power_info *pi = adev->pm.dpm.priv;
318 static struct ci_ps *ci_get_ps(struct amdgpu_ps *rps)
320 struct ci_ps *ps = rps->ps_priv;
325 static void ci_initialize_powertune_defaults(struct amdgpu_device *adev)
327 struct ci_power_info *pi = ci_get_pi(adev);
329 switch (adev->pdev->device) {
337 pi->powertune_defaults = &defaults_bonaire_xt;
343 pi->powertune_defaults = &defaults_saturn_xt;
347 pi->powertune_defaults = &defaults_hawaii_xt;
351 pi->powertune_defaults = &defaults_hawaii_pro;
361 pi->powertune_defaults = &defaults_bonaire_xt;
365 pi->dte_tj_offset = 0;
367 pi->caps_power_containment = true;
368 pi->caps_cac = false;
369 pi->caps_sq_ramping = false;
370 pi->caps_db_ramping = false;
371 pi->caps_td_ramping = false;
372 pi->caps_tcp_ramping = false;
374 if (pi->caps_power_containment) {
376 if (adev->asic_type == CHIP_HAWAII)
377 pi->enable_bapm_feature = false;
379 pi->enable_bapm_feature = true;
380 pi->enable_tdc_limit_feature = true;
381 pi->enable_pkg_pwr_tracking_feature = true;
385 static u8 ci_convert_to_vid(u16 vddc)
387 return (6200 - (vddc * VOLTAGE_SCALE)) / 25;
390 static int ci_populate_bapm_vddc_vid_sidd(struct amdgpu_device *adev)
392 struct ci_power_info *pi = ci_get_pi(adev);
393 u8 *hi_vid = pi->smc_powertune_table.BapmVddCVidHiSidd;
394 u8 *lo_vid = pi->smc_powertune_table.BapmVddCVidLoSidd;
395 u8 *hi2_vid = pi->smc_powertune_table.BapmVddCVidHiSidd2;
398 if (adev->pm.dpm.dyn_state.cac_leakage_table.entries == NULL)
400 if (adev->pm.dpm.dyn_state.cac_leakage_table.count > 8)
402 if (adev->pm.dpm.dyn_state.cac_leakage_table.count !=
403 adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.count)
406 for (i = 0; i < adev->pm.dpm.dyn_state.cac_leakage_table.count; i++) {
407 if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_EVV) {
408 lo_vid[i] = ci_convert_to_vid(adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc1);
409 hi_vid[i] = ci_convert_to_vid(adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc2);
410 hi2_vid[i] = ci_convert_to_vid(adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc3);
412 lo_vid[i] = ci_convert_to_vid(adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc);
413 hi_vid[i] = ci_convert_to_vid((u16)adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].leakage);
419 static int ci_populate_vddc_vid(struct amdgpu_device *adev)
421 struct ci_power_info *pi = ci_get_pi(adev);
422 u8 *vid = pi->smc_powertune_table.VddCVid;
425 if (pi->vddc_voltage_table.count > 8)
428 for (i = 0; i < pi->vddc_voltage_table.count; i++)
429 vid[i] = ci_convert_to_vid(pi->vddc_voltage_table.entries[i].value);
434 static int ci_populate_svi_load_line(struct amdgpu_device *adev)
436 struct ci_power_info *pi = ci_get_pi(adev);
437 const struct ci_pt_defaults *pt_defaults = pi->powertune_defaults;
439 pi->smc_powertune_table.SviLoadLineEn = pt_defaults->svi_load_line_en;
440 pi->smc_powertune_table.SviLoadLineVddC = pt_defaults->svi_load_line_vddc;
441 pi->smc_powertune_table.SviLoadLineTrimVddC = 3;
442 pi->smc_powertune_table.SviLoadLineOffsetVddC = 0;
447 static int ci_populate_tdc_limit(struct amdgpu_device *adev)
449 struct ci_power_info *pi = ci_get_pi(adev);
450 const struct ci_pt_defaults *pt_defaults = pi->powertune_defaults;
453 tdc_limit = adev->pm.dpm.dyn_state.cac_tdp_table->tdc * 256;
454 pi->smc_powertune_table.TDC_VDDC_PkgLimit = cpu_to_be16(tdc_limit);
455 pi->smc_powertune_table.TDC_VDDC_ThrottleReleaseLimitPerc =
456 pt_defaults->tdc_vddc_throttle_release_limit_perc;
457 pi->smc_powertune_table.TDC_MAWt = pt_defaults->tdc_mawt;
462 static int ci_populate_dw8(struct amdgpu_device *adev)
464 struct ci_power_info *pi = ci_get_pi(adev);
465 const struct ci_pt_defaults *pt_defaults = pi->powertune_defaults;
468 ret = amdgpu_ci_read_smc_sram_dword(adev,
469 SMU7_FIRMWARE_HEADER_LOCATION +
470 offsetof(SMU7_Firmware_Header, PmFuseTable) +
471 offsetof(SMU7_Discrete_PmFuses, TdcWaterfallCtl),
472 (u32 *)&pi->smc_powertune_table.TdcWaterfallCtl,
477 pi->smc_powertune_table.TdcWaterfallCtl = pt_defaults->tdc_waterfall_ctl;
482 static int ci_populate_fuzzy_fan(struct amdgpu_device *adev)
484 struct ci_power_info *pi = ci_get_pi(adev);
486 if ((adev->pm.dpm.fan.fan_output_sensitivity & (1 << 15)) ||
487 (adev->pm.dpm.fan.fan_output_sensitivity == 0))
488 adev->pm.dpm.fan.fan_output_sensitivity =
489 adev->pm.dpm.fan.default_fan_output_sensitivity;
491 pi->smc_powertune_table.FuzzyFan_PwmSetDelta =
492 cpu_to_be16(adev->pm.dpm.fan.fan_output_sensitivity);
497 static int ci_min_max_v_gnbl_pm_lid_from_bapm_vddc(struct amdgpu_device *adev)
499 struct ci_power_info *pi = ci_get_pi(adev);
500 u8 *hi_vid = pi->smc_powertune_table.BapmVddCVidHiSidd;
501 u8 *lo_vid = pi->smc_powertune_table.BapmVddCVidLoSidd;
504 min = max = hi_vid[0];
505 for (i = 0; i < 8; i++) {
506 if (0 != hi_vid[i]) {
513 if (0 != lo_vid[i]) {
521 if ((min == 0) || (max == 0))
523 pi->smc_powertune_table.GnbLPMLMaxVid = (u8)max;
524 pi->smc_powertune_table.GnbLPMLMinVid = (u8)min;
529 static int ci_populate_bapm_vddc_base_leakage_sidd(struct amdgpu_device *adev)
531 struct ci_power_info *pi = ci_get_pi(adev);
532 u16 hi_sidd = pi->smc_powertune_table.BapmVddCBaseLeakageHiSidd;
533 u16 lo_sidd = pi->smc_powertune_table.BapmVddCBaseLeakageLoSidd;
534 struct amdgpu_cac_tdp_table *cac_tdp_table =
535 adev->pm.dpm.dyn_state.cac_tdp_table;
537 hi_sidd = cac_tdp_table->high_cac_leakage / 100 * 256;
538 lo_sidd = cac_tdp_table->low_cac_leakage / 100 * 256;
540 pi->smc_powertune_table.BapmVddCBaseLeakageHiSidd = cpu_to_be16(hi_sidd);
541 pi->smc_powertune_table.BapmVddCBaseLeakageLoSidd = cpu_to_be16(lo_sidd);
546 static int ci_populate_bapm_parameters_in_dpm_table(struct amdgpu_device *adev)
548 struct ci_power_info *pi = ci_get_pi(adev);
549 const struct ci_pt_defaults *pt_defaults = pi->powertune_defaults;
550 SMU7_Discrete_DpmTable *dpm_table = &pi->smc_state_table;
551 struct amdgpu_cac_tdp_table *cac_tdp_table =
552 adev->pm.dpm.dyn_state.cac_tdp_table;
553 struct amdgpu_ppm_table *ppm = adev->pm.dpm.dyn_state.ppm_table;
558 dpm_table->DefaultTdp = cac_tdp_table->tdp * 256;
559 dpm_table->TargetTdp = cac_tdp_table->configurable_tdp * 256;
561 dpm_table->DTETjOffset = (u8)pi->dte_tj_offset;
562 dpm_table->GpuTjMax =
563 (u8)(pi->thermal_temp_setting.temperature_high / 1000);
564 dpm_table->GpuTjHyst = 8;
566 dpm_table->DTEAmbientTempBase = pt_defaults->dte_ambient_temp_base;
569 dpm_table->PPM_PkgPwrLimit = cpu_to_be16((u16)ppm->dgpu_tdp * 256 / 1000);
570 dpm_table->PPM_TemperatureLimit = cpu_to_be16((u16)ppm->tj_max * 256);
572 dpm_table->PPM_PkgPwrLimit = cpu_to_be16(0);
573 dpm_table->PPM_TemperatureLimit = cpu_to_be16(0);
576 dpm_table->BAPM_TEMP_GRADIENT = cpu_to_be32(pt_defaults->bapm_temp_gradient);
577 def1 = pt_defaults->bapmti_r;
578 def2 = pt_defaults->bapmti_rc;
580 for (i = 0; i < SMU7_DTE_ITERATIONS; i++) {
581 for (j = 0; j < SMU7_DTE_SOURCES; j++) {
582 for (k = 0; k < SMU7_DTE_SINKS; k++) {
583 dpm_table->BAPMTI_R[i][j][k] = cpu_to_be16(*def1);
584 dpm_table->BAPMTI_RC[i][j][k] = cpu_to_be16(*def2);
594 static int ci_populate_pm_base(struct amdgpu_device *adev)
596 struct ci_power_info *pi = ci_get_pi(adev);
597 u32 pm_fuse_table_offset;
600 if (pi->caps_power_containment) {
601 ret = amdgpu_ci_read_smc_sram_dword(adev,
602 SMU7_FIRMWARE_HEADER_LOCATION +
603 offsetof(SMU7_Firmware_Header, PmFuseTable),
604 &pm_fuse_table_offset, pi->sram_end);
607 ret = ci_populate_bapm_vddc_vid_sidd(adev);
610 ret = ci_populate_vddc_vid(adev);
613 ret = ci_populate_svi_load_line(adev);
616 ret = ci_populate_tdc_limit(adev);
619 ret = ci_populate_dw8(adev);
622 ret = ci_populate_fuzzy_fan(adev);
625 ret = ci_min_max_v_gnbl_pm_lid_from_bapm_vddc(adev);
628 ret = ci_populate_bapm_vddc_base_leakage_sidd(adev);
631 ret = amdgpu_ci_copy_bytes_to_smc(adev, pm_fuse_table_offset,
632 (u8 *)&pi->smc_powertune_table,
633 sizeof(SMU7_Discrete_PmFuses), pi->sram_end);
641 static void ci_do_enable_didt(struct amdgpu_device *adev, const bool enable)
643 struct ci_power_info *pi = ci_get_pi(adev);
646 if (pi->caps_sq_ramping) {
647 data = RREG32_DIDT(ixDIDT_SQ_CTRL0);
649 data |= DIDT_SQ_CTRL0__DIDT_CTRL_EN_MASK;
651 data &= ~DIDT_SQ_CTRL0__DIDT_CTRL_EN_MASK;
652 WREG32_DIDT(ixDIDT_SQ_CTRL0, data);
655 if (pi->caps_db_ramping) {
656 data = RREG32_DIDT(ixDIDT_DB_CTRL0);
658 data |= DIDT_DB_CTRL0__DIDT_CTRL_EN_MASK;
660 data &= ~DIDT_DB_CTRL0__DIDT_CTRL_EN_MASK;
661 WREG32_DIDT(ixDIDT_DB_CTRL0, data);
664 if (pi->caps_td_ramping) {
665 data = RREG32_DIDT(ixDIDT_TD_CTRL0);
667 data |= DIDT_TD_CTRL0__DIDT_CTRL_EN_MASK;
669 data &= ~DIDT_TD_CTRL0__DIDT_CTRL_EN_MASK;
670 WREG32_DIDT(ixDIDT_TD_CTRL0, data);
673 if (pi->caps_tcp_ramping) {
674 data = RREG32_DIDT(ixDIDT_TCP_CTRL0);
676 data |= DIDT_TCP_CTRL0__DIDT_CTRL_EN_MASK;
678 data &= ~DIDT_TCP_CTRL0__DIDT_CTRL_EN_MASK;
679 WREG32_DIDT(ixDIDT_TCP_CTRL0, data);
683 static int ci_program_pt_config_registers(struct amdgpu_device *adev,
684 const struct ci_pt_config_reg *cac_config_regs)
686 const struct ci_pt_config_reg *config_regs = cac_config_regs;
690 if (config_regs == NULL)
693 while (config_regs->offset != 0xFFFFFFFF) {
694 if (config_regs->type == CISLANDS_CONFIGREG_CACHE) {
695 cache |= ((config_regs->value << config_regs->shift) & config_regs->mask);
697 switch (config_regs->type) {
698 case CISLANDS_CONFIGREG_SMC_IND:
699 data = RREG32_SMC(config_regs->offset);
701 case CISLANDS_CONFIGREG_DIDT_IND:
702 data = RREG32_DIDT(config_regs->offset);
705 data = RREG32(config_regs->offset);
709 data &= ~config_regs->mask;
710 data |= ((config_regs->value << config_regs->shift) & config_regs->mask);
713 switch (config_regs->type) {
714 case CISLANDS_CONFIGREG_SMC_IND:
715 WREG32_SMC(config_regs->offset, data);
717 case CISLANDS_CONFIGREG_DIDT_IND:
718 WREG32_DIDT(config_regs->offset, data);
721 WREG32(config_regs->offset, data);
731 static int ci_enable_didt(struct amdgpu_device *adev, bool enable)
733 struct ci_power_info *pi = ci_get_pi(adev);
736 if (pi->caps_sq_ramping || pi->caps_db_ramping ||
737 pi->caps_td_ramping || pi->caps_tcp_ramping) {
738 gfx_v7_0_enter_rlc_safe_mode(adev);
741 ret = ci_program_pt_config_registers(adev, didt_config_ci);
743 gfx_v7_0_exit_rlc_safe_mode(adev);
748 ci_do_enable_didt(adev, enable);
750 gfx_v7_0_exit_rlc_safe_mode(adev);
756 static int ci_enable_power_containment(struct amdgpu_device *adev, bool enable)
758 struct ci_power_info *pi = ci_get_pi(adev);
759 PPSMC_Result smc_result;
763 pi->power_containment_features = 0;
764 if (pi->caps_power_containment) {
765 if (pi->enable_bapm_feature) {
766 smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_EnableDTE);
767 if (smc_result != PPSMC_Result_OK)
770 pi->power_containment_features |= POWERCONTAINMENT_FEATURE_BAPM;
773 if (pi->enable_tdc_limit_feature) {
774 smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_TDCLimitEnable);
775 if (smc_result != PPSMC_Result_OK)
778 pi->power_containment_features |= POWERCONTAINMENT_FEATURE_TDCLimit;
781 if (pi->enable_pkg_pwr_tracking_feature) {
782 smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_PkgPwrLimitEnable);
783 if (smc_result != PPSMC_Result_OK) {
786 struct amdgpu_cac_tdp_table *cac_tdp_table =
787 adev->pm.dpm.dyn_state.cac_tdp_table;
788 u32 default_pwr_limit =
789 (u32)(cac_tdp_table->maximum_power_delivery_limit * 256);
791 pi->power_containment_features |= POWERCONTAINMENT_FEATURE_PkgPwrLimit;
793 ci_set_power_limit(adev, default_pwr_limit);
798 if (pi->caps_power_containment && pi->power_containment_features) {
799 if (pi->power_containment_features & POWERCONTAINMENT_FEATURE_TDCLimit)
800 amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_TDCLimitDisable);
802 if (pi->power_containment_features & POWERCONTAINMENT_FEATURE_BAPM)
803 amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_DisableDTE);
805 if (pi->power_containment_features & POWERCONTAINMENT_FEATURE_PkgPwrLimit)
806 amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_PkgPwrLimitDisable);
807 pi->power_containment_features = 0;
814 static int ci_enable_smc_cac(struct amdgpu_device *adev, bool enable)
816 struct ci_power_info *pi = ci_get_pi(adev);
817 PPSMC_Result smc_result;
822 smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_EnableCac);
823 if (smc_result != PPSMC_Result_OK) {
825 pi->cac_enabled = false;
827 pi->cac_enabled = true;
829 } else if (pi->cac_enabled) {
830 amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_DisableCac);
831 pi->cac_enabled = false;
838 static int ci_enable_thermal_based_sclk_dpm(struct amdgpu_device *adev,
841 struct ci_power_info *pi = ci_get_pi(adev);
842 PPSMC_Result smc_result = PPSMC_Result_OK;
844 if (pi->thermal_sclk_dpm_enabled) {
846 smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_ENABLE_THERMAL_DPM);
848 smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_DISABLE_THERMAL_DPM);
851 if (smc_result == PPSMC_Result_OK)
857 static int ci_power_control_set_level(struct amdgpu_device *adev)
859 struct ci_power_info *pi = ci_get_pi(adev);
860 struct amdgpu_cac_tdp_table *cac_tdp_table =
861 adev->pm.dpm.dyn_state.cac_tdp_table;
865 bool adjust_polarity = false; /* ??? */
867 if (pi->caps_power_containment) {
868 adjust_percent = adjust_polarity ?
869 adev->pm.dpm.tdp_adjustment : (-1 * adev->pm.dpm.tdp_adjustment);
870 target_tdp = ((100 + adjust_percent) *
871 (s32)cac_tdp_table->configurable_tdp) / 100;
873 ret = ci_set_overdrive_target_tdp(adev, (u32)target_tdp);
879 static void ci_dpm_powergate_uvd(struct amdgpu_device *adev, bool gate)
881 struct ci_power_info *pi = ci_get_pi(adev);
883 if (pi->uvd_power_gated == gate)
886 pi->uvd_power_gated = gate;
888 ci_update_uvd_dpm(adev, gate);
891 static bool ci_dpm_vblank_too_short(struct amdgpu_device *adev)
893 u32 vblank_time = amdgpu_dpm_get_vblank_time(adev);
894 u32 switch_limit = adev->mc.vram_type == AMDGPU_VRAM_TYPE_GDDR5 ? 450 : 300;
896 if (vblank_time < switch_limit)
903 static void ci_apply_state_adjust_rules(struct amdgpu_device *adev,
904 struct amdgpu_ps *rps)
906 struct ci_ps *ps = ci_get_ps(rps);
907 struct ci_power_info *pi = ci_get_pi(adev);
908 struct amdgpu_clock_and_voltage_limits *max_limits;
909 bool disable_mclk_switching;
913 if (rps->vce_active) {
914 rps->evclk = adev->pm.dpm.vce_states[adev->pm.dpm.vce_level].evclk;
915 rps->ecclk = adev->pm.dpm.vce_states[adev->pm.dpm.vce_level].ecclk;
921 if ((adev->pm.dpm.new_active_crtc_count > 1) ||
922 ci_dpm_vblank_too_short(adev))
923 disable_mclk_switching = true;
925 disable_mclk_switching = false;
927 if ((rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) == ATOM_PPLIB_CLASSIFICATION_UI_BATTERY)
928 pi->battery_state = true;
930 pi->battery_state = false;
932 if (adev->pm.dpm.ac_power)
933 max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_ac;
935 max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_dc;
937 if (adev->pm.dpm.ac_power == false) {
938 for (i = 0; i < ps->performance_level_count; i++) {
939 if (ps->performance_levels[i].mclk > max_limits->mclk)
940 ps->performance_levels[i].mclk = max_limits->mclk;
941 if (ps->performance_levels[i].sclk > max_limits->sclk)
942 ps->performance_levels[i].sclk = max_limits->sclk;
946 /* XXX validate the min clocks required for display */
948 if (disable_mclk_switching) {
949 mclk = ps->performance_levels[ps->performance_level_count - 1].mclk;
950 sclk = ps->performance_levels[0].sclk;
952 mclk = ps->performance_levels[0].mclk;
953 sclk = ps->performance_levels[0].sclk;
956 if (rps->vce_active) {
957 if (sclk < adev->pm.dpm.vce_states[adev->pm.dpm.vce_level].sclk)
958 sclk = adev->pm.dpm.vce_states[adev->pm.dpm.vce_level].sclk;
959 if (mclk < adev->pm.dpm.vce_states[adev->pm.dpm.vce_level].mclk)
960 mclk = adev->pm.dpm.vce_states[adev->pm.dpm.vce_level].mclk;
963 ps->performance_levels[0].sclk = sclk;
964 ps->performance_levels[0].mclk = mclk;
966 if (ps->performance_levels[1].sclk < ps->performance_levels[0].sclk)
967 ps->performance_levels[1].sclk = ps->performance_levels[0].sclk;
969 if (disable_mclk_switching) {
970 if (ps->performance_levels[0].mclk < ps->performance_levels[1].mclk)
971 ps->performance_levels[0].mclk = ps->performance_levels[1].mclk;
973 if (ps->performance_levels[1].mclk < ps->performance_levels[0].mclk)
974 ps->performance_levels[1].mclk = ps->performance_levels[0].mclk;
978 static int ci_thermal_set_temperature_range(struct amdgpu_device *adev,
979 int min_temp, int max_temp)
981 int low_temp = 0 * 1000;
982 int high_temp = 255 * 1000;
985 if (low_temp < min_temp)
987 if (high_temp > max_temp)
988 high_temp = max_temp;
989 if (high_temp < low_temp) {
990 DRM_ERROR("invalid thermal range: %d - %d\n", low_temp, high_temp);
994 tmp = RREG32_SMC(ixCG_THERMAL_INT);
995 tmp &= ~(CG_THERMAL_INT__DIG_THERM_INTH_MASK | CG_THERMAL_INT__DIG_THERM_INTL_MASK);
996 tmp |= ((high_temp / 1000) << CG_THERMAL_INT__DIG_THERM_INTH__SHIFT) |
997 ((low_temp / 1000)) << CG_THERMAL_INT__DIG_THERM_INTL__SHIFT;
998 WREG32_SMC(ixCG_THERMAL_INT, tmp);
1001 /* XXX: need to figure out how to handle this properly */
1002 tmp = RREG32_SMC(ixCG_THERMAL_CTRL);
1003 tmp &= DIG_THERM_DPM_MASK;
1004 tmp |= DIG_THERM_DPM(high_temp / 1000);
1005 WREG32_SMC(ixCG_THERMAL_CTRL, tmp);
1008 adev->pm.dpm.thermal.min_temp = low_temp;
1009 adev->pm.dpm.thermal.max_temp = high_temp;
1013 static int ci_thermal_enable_alert(struct amdgpu_device *adev,
1016 u32 thermal_int = RREG32_SMC(ixCG_THERMAL_INT);
1017 PPSMC_Result result;
1020 thermal_int &= ~(CG_THERMAL_INT_CTRL__THERM_INTH_MASK_MASK |
1021 CG_THERMAL_INT_CTRL__THERM_INTL_MASK_MASK);
1022 WREG32_SMC(ixCG_THERMAL_INT, thermal_int);
1023 result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_Thermal_Cntl_Enable);
1024 if (result != PPSMC_Result_OK) {
1025 DRM_DEBUG_KMS("Could not enable thermal interrupts.\n");
1029 thermal_int |= CG_THERMAL_INT_CTRL__THERM_INTH_MASK_MASK |
1030 CG_THERMAL_INT_CTRL__THERM_INTL_MASK_MASK;
1031 WREG32_SMC(ixCG_THERMAL_INT, thermal_int);
1032 result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_Thermal_Cntl_Disable);
1033 if (result != PPSMC_Result_OK) {
1034 DRM_DEBUG_KMS("Could not disable thermal interrupts.\n");
1042 static void ci_fan_ctrl_set_static_mode(struct amdgpu_device *adev, u32 mode)
1044 struct ci_power_info *pi = ci_get_pi(adev);
1047 if (pi->fan_ctrl_is_in_default_mode) {
1048 tmp = (RREG32_SMC(ixCG_FDO_CTRL2) & CG_FDO_CTRL2__FDO_PWM_MODE_MASK)
1049 >> CG_FDO_CTRL2__FDO_PWM_MODE__SHIFT;
1050 pi->fan_ctrl_default_mode = tmp;
1051 tmp = (RREG32_SMC(ixCG_FDO_CTRL2) & CG_FDO_CTRL2__TMIN_MASK)
1052 >> CG_FDO_CTRL2__TMIN__SHIFT;
1054 pi->fan_ctrl_is_in_default_mode = false;
1057 tmp = RREG32_SMC(ixCG_FDO_CTRL2) & ~CG_FDO_CTRL2__TMIN_MASK;
1058 tmp |= 0 << CG_FDO_CTRL2__TMIN__SHIFT;
1059 WREG32_SMC(ixCG_FDO_CTRL2, tmp);
1061 tmp = RREG32_SMC(ixCG_FDO_CTRL2) & ~CG_FDO_CTRL2__FDO_PWM_MODE_MASK;
1062 tmp |= mode << CG_FDO_CTRL2__FDO_PWM_MODE__SHIFT;
1063 WREG32_SMC(ixCG_FDO_CTRL2, tmp);
1066 static int ci_thermal_setup_fan_table(struct amdgpu_device *adev)
1068 struct ci_power_info *pi = ci_get_pi(adev);
1069 SMU7_Discrete_FanTable fan_table = { FDO_MODE_HARDWARE };
1071 u32 t_diff1, t_diff2, pwm_diff1, pwm_diff2;
1072 u16 fdo_min, slope1, slope2;
1073 u32 reference_clock, tmp;
1077 if (!pi->fan_table_start) {
1078 adev->pm.dpm.fan.ucode_fan_control = false;
1082 duty100 = (RREG32_SMC(ixCG_FDO_CTRL1) & CG_FDO_CTRL1__FMAX_DUTY100_MASK)
1083 >> CG_FDO_CTRL1__FMAX_DUTY100__SHIFT;
1086 adev->pm.dpm.fan.ucode_fan_control = false;
1090 tmp64 = (u64)adev->pm.dpm.fan.pwm_min * duty100;
1091 do_div(tmp64, 10000);
1092 fdo_min = (u16)tmp64;
1094 t_diff1 = adev->pm.dpm.fan.t_med - adev->pm.dpm.fan.t_min;
1095 t_diff2 = adev->pm.dpm.fan.t_high - adev->pm.dpm.fan.t_med;
1097 pwm_diff1 = adev->pm.dpm.fan.pwm_med - adev->pm.dpm.fan.pwm_min;
1098 pwm_diff2 = adev->pm.dpm.fan.pwm_high - adev->pm.dpm.fan.pwm_med;
1100 slope1 = (u16)((50 + ((16 * duty100 * pwm_diff1) / t_diff1)) / 100);
1101 slope2 = (u16)((50 + ((16 * duty100 * pwm_diff2) / t_diff2)) / 100);
1103 fan_table.TempMin = cpu_to_be16((50 + adev->pm.dpm.fan.t_min) / 100);
1104 fan_table.TempMed = cpu_to_be16((50 + adev->pm.dpm.fan.t_med) / 100);
1105 fan_table.TempMax = cpu_to_be16((50 + adev->pm.dpm.fan.t_max) / 100);
1107 fan_table.Slope1 = cpu_to_be16(slope1);
1108 fan_table.Slope2 = cpu_to_be16(slope2);
1110 fan_table.FdoMin = cpu_to_be16(fdo_min);
1112 fan_table.HystDown = cpu_to_be16(adev->pm.dpm.fan.t_hyst);
1114 fan_table.HystUp = cpu_to_be16(1);
1116 fan_table.HystSlope = cpu_to_be16(1);
1118 fan_table.TempRespLim = cpu_to_be16(5);
1120 reference_clock = amdgpu_asic_get_xclk(adev);
1122 fan_table.RefreshPeriod = cpu_to_be32((adev->pm.dpm.fan.cycle_delay *
1123 reference_clock) / 1600);
1125 fan_table.FdoMax = cpu_to_be16((u16)duty100);
1127 tmp = (RREG32_SMC(ixCG_MULT_THERMAL_CTRL) & CG_MULT_THERMAL_CTRL__TEMP_SEL_MASK)
1128 >> CG_MULT_THERMAL_CTRL__TEMP_SEL__SHIFT;
1129 fan_table.TempSrc = (uint8_t)tmp;
1131 ret = amdgpu_ci_copy_bytes_to_smc(adev,
1132 pi->fan_table_start,
1138 DRM_ERROR("Failed to load fan table to the SMC.");
1139 adev->pm.dpm.fan.ucode_fan_control = false;
1145 static int ci_fan_ctrl_start_smc_fan_control(struct amdgpu_device *adev)
1147 struct ci_power_info *pi = ci_get_pi(adev);
1150 if (pi->caps_od_fuzzy_fan_control_support) {
1151 ret = amdgpu_ci_send_msg_to_smc_with_parameter(adev,
1152 PPSMC_StartFanControl,
1154 if (ret != PPSMC_Result_OK)
1156 ret = amdgpu_ci_send_msg_to_smc_with_parameter(adev,
1157 PPSMC_MSG_SetFanPwmMax,
1158 adev->pm.dpm.fan.default_max_fan_pwm);
1159 if (ret != PPSMC_Result_OK)
1162 ret = amdgpu_ci_send_msg_to_smc_with_parameter(adev,
1163 PPSMC_StartFanControl,
1165 if (ret != PPSMC_Result_OK)
1169 pi->fan_is_controlled_by_smc = true;
1174 static int ci_fan_ctrl_stop_smc_fan_control(struct amdgpu_device *adev)
1177 struct ci_power_info *pi = ci_get_pi(adev);
1179 ret = amdgpu_ci_send_msg_to_smc(adev, PPSMC_StopFanControl);
1180 if (ret == PPSMC_Result_OK) {
1181 pi->fan_is_controlled_by_smc = false;
1188 static int ci_dpm_get_fan_speed_percent(struct amdgpu_device *adev,
1194 if (adev->pm.no_fan)
1197 duty100 = (RREG32_SMC(ixCG_FDO_CTRL1) & CG_FDO_CTRL1__FMAX_DUTY100_MASK)
1198 >> CG_FDO_CTRL1__FMAX_DUTY100__SHIFT;
1199 duty = (RREG32_SMC(ixCG_THERMAL_STATUS) & CG_THERMAL_STATUS__FDO_PWM_DUTY_MASK)
1200 >> CG_THERMAL_STATUS__FDO_PWM_DUTY__SHIFT;
1205 tmp64 = (u64)duty * 100;
1206 do_div(tmp64, duty100);
1207 *speed = (u32)tmp64;
1215 static int ci_dpm_set_fan_speed_percent(struct amdgpu_device *adev,
1221 struct ci_power_info *pi = ci_get_pi(adev);
1223 if (adev->pm.no_fan)
1226 if (pi->fan_is_controlled_by_smc)
1232 duty100 = (RREG32_SMC(ixCG_FDO_CTRL1) & CG_FDO_CTRL1__FMAX_DUTY100_MASK)
1233 >> CG_FDO_CTRL1__FMAX_DUTY100__SHIFT;
1238 tmp64 = (u64)speed * duty100;
1242 tmp = RREG32_SMC(ixCG_FDO_CTRL0) & ~CG_FDO_CTRL0__FDO_STATIC_DUTY_MASK;
1243 tmp |= duty << CG_FDO_CTRL0__FDO_STATIC_DUTY__SHIFT;
1244 WREG32_SMC(ixCG_FDO_CTRL0, tmp);
1249 static void ci_dpm_set_fan_control_mode(struct amdgpu_device *adev, u32 mode)
1252 /* stop auto-manage */
1253 if (adev->pm.dpm.fan.ucode_fan_control)
1254 ci_fan_ctrl_stop_smc_fan_control(adev);
1255 ci_fan_ctrl_set_static_mode(adev, mode);
1257 /* restart auto-manage */
1258 if (adev->pm.dpm.fan.ucode_fan_control)
1259 ci_thermal_start_smc_fan_control(adev);
1261 ci_fan_ctrl_set_default_mode(adev);
1265 static u32 ci_dpm_get_fan_control_mode(struct amdgpu_device *adev)
1267 struct ci_power_info *pi = ci_get_pi(adev);
1270 if (pi->fan_is_controlled_by_smc)
1273 tmp = RREG32_SMC(ixCG_FDO_CTRL2) & CG_FDO_CTRL2__FDO_PWM_MODE_MASK;
1274 return (tmp >> CG_FDO_CTRL2__FDO_PWM_MODE__SHIFT);
1278 static int ci_fan_ctrl_get_fan_speed_rpm(struct amdgpu_device *adev,
1282 u32 xclk = amdgpu_asic_get_xclk(adev);
1284 if (adev->pm.no_fan)
1287 if (adev->pm.fan_pulses_per_revolution == 0)
1290 tach_period = (RREG32_SMC(ixCG_TACH_STATUS) & CG_TACH_STATUS__TACH_PERIOD_MASK)
1291 >> CG_TACH_STATUS__TACH_PERIOD__SHIFT;
1292 if (tach_period == 0)
1295 *speed = 60 * xclk * 10000 / tach_period;
1300 static int ci_fan_ctrl_set_fan_speed_rpm(struct amdgpu_device *adev,
1303 u32 tach_period, tmp;
1304 u32 xclk = amdgpu_asic_get_xclk(adev);
1306 if (adev->pm.no_fan)
1309 if (adev->pm.fan_pulses_per_revolution == 0)
1312 if ((speed < adev->pm.fan_min_rpm) ||
1313 (speed > adev->pm.fan_max_rpm))
1316 if (adev->pm.dpm.fan.ucode_fan_control)
1317 ci_fan_ctrl_stop_smc_fan_control(adev);
1319 tach_period = 60 * xclk * 10000 / (8 * speed);
1320 tmp = RREG32_SMC(ixCG_TACH_CTRL) & ~CG_TACH_CTRL__TARGET_PERIOD_MASK;
1321 tmp |= tach_period << CG_TACH_CTRL__TARGET_PERIOD__SHIFT;
1322 WREG32_SMC(CG_TACH_CTRL, tmp);
1324 ci_fan_ctrl_set_static_mode(adev, FDO_PWM_MODE_STATIC_RPM);
1330 static void ci_fan_ctrl_set_default_mode(struct amdgpu_device *adev)
1332 struct ci_power_info *pi = ci_get_pi(adev);
1335 if (!pi->fan_ctrl_is_in_default_mode) {
1336 tmp = RREG32_SMC(ixCG_FDO_CTRL2) & ~CG_FDO_CTRL2__FDO_PWM_MODE_MASK;
1337 tmp |= pi->fan_ctrl_default_mode << CG_FDO_CTRL2__FDO_PWM_MODE__SHIFT;
1338 WREG32_SMC(ixCG_FDO_CTRL2, tmp);
1340 tmp = RREG32_SMC(ixCG_FDO_CTRL2) & ~CG_FDO_CTRL2__TMIN_MASK;
1341 tmp |= pi->t_min << CG_FDO_CTRL2__TMIN__SHIFT;
1342 WREG32_SMC(ixCG_FDO_CTRL2, tmp);
1343 pi->fan_ctrl_is_in_default_mode = true;
1347 static void ci_thermal_start_smc_fan_control(struct amdgpu_device *adev)
1349 if (adev->pm.dpm.fan.ucode_fan_control) {
1350 ci_fan_ctrl_start_smc_fan_control(adev);
1351 ci_fan_ctrl_set_static_mode(adev, FDO_PWM_MODE_STATIC);
1355 static void ci_thermal_initialize(struct amdgpu_device *adev)
1359 if (adev->pm.fan_pulses_per_revolution) {
1360 tmp = RREG32_SMC(ixCG_TACH_CTRL) & ~CG_TACH_CTRL__EDGE_PER_REV_MASK;
1361 tmp |= (adev->pm.fan_pulses_per_revolution - 1)
1362 << CG_TACH_CTRL__EDGE_PER_REV__SHIFT;
1363 WREG32_SMC(ixCG_TACH_CTRL, tmp);
1366 tmp = RREG32_SMC(ixCG_FDO_CTRL2) & ~CG_FDO_CTRL2__TACH_PWM_RESP_RATE_MASK;
1367 tmp |= 0x28 << CG_FDO_CTRL2__TACH_PWM_RESP_RATE__SHIFT;
1368 WREG32_SMC(ixCG_FDO_CTRL2, tmp);
1371 static int ci_thermal_start_thermal_controller(struct amdgpu_device *adev)
1375 ci_thermal_initialize(adev);
1376 ret = ci_thermal_set_temperature_range(adev, CISLANDS_TEMP_RANGE_MIN, CISLANDS_TEMP_RANGE_MAX);
1379 ret = ci_thermal_enable_alert(adev, true);
1382 if (adev->pm.dpm.fan.ucode_fan_control) {
1383 ret = ci_thermal_setup_fan_table(adev);
1386 ci_thermal_start_smc_fan_control(adev);
1392 static void ci_thermal_stop_thermal_controller(struct amdgpu_device *adev)
1394 if (!adev->pm.no_fan)
1395 ci_fan_ctrl_set_default_mode(adev);
1398 static int ci_read_smc_soft_register(struct amdgpu_device *adev,
1399 u16 reg_offset, u32 *value)
1401 struct ci_power_info *pi = ci_get_pi(adev);
1403 return amdgpu_ci_read_smc_sram_dword(adev,
1404 pi->soft_regs_start + reg_offset,
1405 value, pi->sram_end);
1408 static int ci_write_smc_soft_register(struct amdgpu_device *adev,
1409 u16 reg_offset, u32 value)
1411 struct ci_power_info *pi = ci_get_pi(adev);
1413 return amdgpu_ci_write_smc_sram_dword(adev,
1414 pi->soft_regs_start + reg_offset,
1415 value, pi->sram_end);
1418 static void ci_init_fps_limits(struct amdgpu_device *adev)
1420 struct ci_power_info *pi = ci_get_pi(adev);
1421 SMU7_Discrete_DpmTable *table = &pi->smc_state_table;
1427 table->FpsHighT = cpu_to_be16(tmp);
1430 table->FpsLowT = cpu_to_be16(tmp);
1434 static int ci_update_sclk_t(struct amdgpu_device *adev)
1436 struct ci_power_info *pi = ci_get_pi(adev);
1438 u32 low_sclk_interrupt_t = 0;
1440 if (pi->caps_sclk_throttle_low_notification) {
1441 low_sclk_interrupt_t = cpu_to_be32(pi->low_sclk_interrupt_t);
1443 ret = amdgpu_ci_copy_bytes_to_smc(adev,
1444 pi->dpm_table_start +
1445 offsetof(SMU7_Discrete_DpmTable, LowSclkInterruptT),
1446 (u8 *)&low_sclk_interrupt_t,
1447 sizeof(u32), pi->sram_end);
1454 static void ci_get_leakage_voltages(struct amdgpu_device *adev)
1456 struct ci_power_info *pi = ci_get_pi(adev);
1457 u16 leakage_id, virtual_voltage_id;
1461 pi->vddc_leakage.count = 0;
1462 pi->vddci_leakage.count = 0;
1464 if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_EVV) {
1465 for (i = 0; i < CISLANDS_MAX_LEAKAGE_COUNT; i++) {
1466 virtual_voltage_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i;
1467 if (amdgpu_atombios_get_voltage_evv(adev, virtual_voltage_id, &vddc) != 0)
1469 if (vddc != 0 && vddc != virtual_voltage_id) {
1470 pi->vddc_leakage.actual_voltage[pi->vddc_leakage.count] = vddc;
1471 pi->vddc_leakage.leakage_id[pi->vddc_leakage.count] = virtual_voltage_id;
1472 pi->vddc_leakage.count++;
1475 } else if (amdgpu_atombios_get_leakage_id_from_vbios(adev, &leakage_id) == 0) {
1476 for (i = 0; i < CISLANDS_MAX_LEAKAGE_COUNT; i++) {
1477 virtual_voltage_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i;
1478 if (amdgpu_atombios_get_leakage_vddc_based_on_leakage_params(adev, &vddc, &vddci,
1481 if (vddc != 0 && vddc != virtual_voltage_id) {
1482 pi->vddc_leakage.actual_voltage[pi->vddc_leakage.count] = vddc;
1483 pi->vddc_leakage.leakage_id[pi->vddc_leakage.count] = virtual_voltage_id;
1484 pi->vddc_leakage.count++;
1486 if (vddci != 0 && vddci != virtual_voltage_id) {
1487 pi->vddci_leakage.actual_voltage[pi->vddci_leakage.count] = vddci;
1488 pi->vddci_leakage.leakage_id[pi->vddci_leakage.count] = virtual_voltage_id;
1489 pi->vddci_leakage.count++;
1496 static void ci_set_dpm_event_sources(struct amdgpu_device *adev, u32 sources)
1498 struct ci_power_info *pi = ci_get_pi(adev);
1499 bool want_thermal_protection;
1500 enum amdgpu_dpm_event_src dpm_event_src;
1506 want_thermal_protection = false;
1508 case (1 << AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL):
1509 want_thermal_protection = true;
1510 dpm_event_src = AMDGPU_DPM_EVENT_SRC_DIGITAL;
1512 case (1 << AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL):
1513 want_thermal_protection = true;
1514 dpm_event_src = AMDGPU_DPM_EVENT_SRC_EXTERNAL;
1516 case ((1 << AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL) |
1517 (1 << AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL)):
1518 want_thermal_protection = true;
1519 dpm_event_src = AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL;
1523 if (want_thermal_protection) {
1525 /* XXX: need to figure out how to handle this properly */
1526 tmp = RREG32_SMC(ixCG_THERMAL_CTRL);
1527 tmp &= DPM_EVENT_SRC_MASK;
1528 tmp |= DPM_EVENT_SRC(dpm_event_src);
1529 WREG32_SMC(ixCG_THERMAL_CTRL, tmp);
1532 tmp = RREG32_SMC(ixGENERAL_PWRMGT);
1533 if (pi->thermal_protection)
1534 tmp &= ~GENERAL_PWRMGT__THERMAL_PROTECTION_DIS_MASK;
1536 tmp |= GENERAL_PWRMGT__THERMAL_PROTECTION_DIS_MASK;
1537 WREG32_SMC(ixGENERAL_PWRMGT, tmp);
1539 tmp = RREG32_SMC(ixGENERAL_PWRMGT);
1540 tmp |= GENERAL_PWRMGT__THERMAL_PROTECTION_DIS_MASK;
1541 WREG32_SMC(ixGENERAL_PWRMGT, tmp);
1545 static void ci_enable_auto_throttle_source(struct amdgpu_device *adev,
1546 enum amdgpu_dpm_auto_throttle_src source,
1549 struct ci_power_info *pi = ci_get_pi(adev);
1552 if (!(pi->active_auto_throttle_sources & (1 << source))) {
1553 pi->active_auto_throttle_sources |= 1 << source;
1554 ci_set_dpm_event_sources(adev, pi->active_auto_throttle_sources);
1557 if (pi->active_auto_throttle_sources & (1 << source)) {
1558 pi->active_auto_throttle_sources &= ~(1 << source);
1559 ci_set_dpm_event_sources(adev, pi->active_auto_throttle_sources);
1564 static void ci_enable_vr_hot_gpio_interrupt(struct amdgpu_device *adev)
1566 if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_REGULATOR_HOT)
1567 amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_EnableVRHotGPIOInterrupt);
1570 static int ci_unfreeze_sclk_mclk_dpm(struct amdgpu_device *adev)
1572 struct ci_power_info *pi = ci_get_pi(adev);
1573 PPSMC_Result smc_result;
1575 if (!pi->need_update_smu7_dpm_table)
1578 if ((!pi->sclk_dpm_key_disabled) &&
1579 (pi->need_update_smu7_dpm_table & (DPMTABLE_OD_UPDATE_SCLK | DPMTABLE_UPDATE_SCLK))) {
1580 smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_SCLKDPM_UnfreezeLevel);
1581 if (smc_result != PPSMC_Result_OK)
1585 if ((!pi->mclk_dpm_key_disabled) &&
1586 (pi->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) {
1587 smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_MCLKDPM_UnfreezeLevel);
1588 if (smc_result != PPSMC_Result_OK)
1592 pi->need_update_smu7_dpm_table = 0;
1596 static int ci_enable_sclk_mclk_dpm(struct amdgpu_device *adev, bool enable)
1598 struct ci_power_info *pi = ci_get_pi(adev);
1599 PPSMC_Result smc_result;
1602 if (!pi->sclk_dpm_key_disabled) {
1603 smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_DPM_Enable);
1604 if (smc_result != PPSMC_Result_OK)
1608 if (!pi->mclk_dpm_key_disabled) {
1609 smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_MCLKDPM_Enable);
1610 if (smc_result != PPSMC_Result_OK)
1613 WREG32_P(mmMC_SEQ_CNTL_3, MC_SEQ_CNTL_3__CAC_EN_MASK,
1614 ~MC_SEQ_CNTL_3__CAC_EN_MASK);
1616 WREG32_SMC(ixLCAC_MC0_CNTL, 0x05);
1617 WREG32_SMC(ixLCAC_MC1_CNTL, 0x05);
1618 WREG32_SMC(ixLCAC_CPL_CNTL, 0x100005);
1622 WREG32_SMC(ixLCAC_MC0_CNTL, 0x400005);
1623 WREG32_SMC(ixLCAC_MC1_CNTL, 0x400005);
1624 WREG32_SMC(ixLCAC_CPL_CNTL, 0x500005);
1627 if (!pi->sclk_dpm_key_disabled) {
1628 smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_DPM_Disable);
1629 if (smc_result != PPSMC_Result_OK)
1633 if (!pi->mclk_dpm_key_disabled) {
1634 smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_MCLKDPM_Disable);
1635 if (smc_result != PPSMC_Result_OK)
1643 static int ci_start_dpm(struct amdgpu_device *adev)
1645 struct ci_power_info *pi = ci_get_pi(adev);
1646 PPSMC_Result smc_result;
1650 tmp = RREG32_SMC(ixGENERAL_PWRMGT);
1651 tmp |= GENERAL_PWRMGT__GLOBAL_PWRMGT_EN_MASK;
1652 WREG32_SMC(ixGENERAL_PWRMGT, tmp);
1654 tmp = RREG32_SMC(ixSCLK_PWRMGT_CNTL);
1655 tmp |= SCLK_PWRMGT_CNTL__DYNAMIC_PM_EN_MASK;
1656 WREG32_SMC(ixSCLK_PWRMGT_CNTL, tmp);
1658 ci_write_smc_soft_register(adev, offsetof(SMU7_SoftRegisters, VoltageChangeTimeout), 0x1000);
1660 WREG32_P(mmBIF_LNCNT_RESET, 0, ~BIF_LNCNT_RESET__RESET_LNCNT_EN_MASK);
1662 smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_Voltage_Cntl_Enable);
1663 if (smc_result != PPSMC_Result_OK)
1666 ret = ci_enable_sclk_mclk_dpm(adev, true);
1670 if (!pi->pcie_dpm_key_disabled) {
1671 smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_PCIeDPM_Enable);
1672 if (smc_result != PPSMC_Result_OK)
1679 static int ci_freeze_sclk_mclk_dpm(struct amdgpu_device *adev)
1681 struct ci_power_info *pi = ci_get_pi(adev);
1682 PPSMC_Result smc_result;
1684 if (!pi->need_update_smu7_dpm_table)
1687 if ((!pi->sclk_dpm_key_disabled) &&
1688 (pi->need_update_smu7_dpm_table & (DPMTABLE_OD_UPDATE_SCLK | DPMTABLE_UPDATE_SCLK))) {
1689 smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_SCLKDPM_FreezeLevel);
1690 if (smc_result != PPSMC_Result_OK)
1694 if ((!pi->mclk_dpm_key_disabled) &&
1695 (pi->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) {
1696 smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_MCLKDPM_FreezeLevel);
1697 if (smc_result != PPSMC_Result_OK)
1704 static int ci_stop_dpm(struct amdgpu_device *adev)
1706 struct ci_power_info *pi = ci_get_pi(adev);
1707 PPSMC_Result smc_result;
1711 tmp = RREG32_SMC(ixGENERAL_PWRMGT);
1712 tmp &= ~GENERAL_PWRMGT__GLOBAL_PWRMGT_EN_MASK;
1713 WREG32_SMC(ixGENERAL_PWRMGT, tmp);
1715 tmp = RREG32_SMC(ixSCLK_PWRMGT_CNTL);
1716 tmp &= ~SCLK_PWRMGT_CNTL__DYNAMIC_PM_EN_MASK;
1717 WREG32_SMC(ixSCLK_PWRMGT_CNTL, tmp);
1719 if (!pi->pcie_dpm_key_disabled) {
1720 smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_PCIeDPM_Disable);
1721 if (smc_result != PPSMC_Result_OK)
1725 ret = ci_enable_sclk_mclk_dpm(adev, false);
1729 smc_result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_Voltage_Cntl_Disable);
1730 if (smc_result != PPSMC_Result_OK)
1736 static void ci_enable_sclk_control(struct amdgpu_device *adev, bool enable)
1738 u32 tmp = RREG32_SMC(ixSCLK_PWRMGT_CNTL);
1741 tmp &= ~SCLK_PWRMGT_CNTL__SCLK_PWRMGT_OFF_MASK;
1743 tmp |= SCLK_PWRMGT_CNTL__SCLK_PWRMGT_OFF_MASK;
1744 WREG32_SMC(ixSCLK_PWRMGT_CNTL, tmp);
1748 static int ci_notify_hw_of_power_source(struct amdgpu_device *adev,
1751 struct ci_power_info *pi = ci_get_pi(adev);
1752 struct amdgpu_cac_tdp_table *cac_tdp_table =
1753 adev->pm.dpm.dyn_state.cac_tdp_table;
1757 power_limit = (u32)(cac_tdp_table->maximum_power_delivery_limit * 256);
1759 power_limit = (u32)(cac_tdp_table->battery_power_limit * 256);
1761 ci_set_power_limit(adev, power_limit);
1763 if (pi->caps_automatic_dc_transition) {
1765 amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_RunningOnAC);
1767 amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_Remove_DC_Clamp);
1774 static PPSMC_Result amdgpu_ci_send_msg_to_smc_with_parameter(struct amdgpu_device *adev,
1775 PPSMC_Msg msg, u32 parameter)
1777 WREG32(mmSMC_MSG_ARG_0, parameter);
1778 return amdgpu_ci_send_msg_to_smc(adev, msg);
1781 static PPSMC_Result amdgpu_ci_send_msg_to_smc_return_parameter(struct amdgpu_device *adev,
1782 PPSMC_Msg msg, u32 *parameter)
1784 PPSMC_Result smc_result;
1786 smc_result = amdgpu_ci_send_msg_to_smc(adev, msg);
1788 if ((smc_result == PPSMC_Result_OK) && parameter)
1789 *parameter = RREG32(mmSMC_MSG_ARG_0);
1794 static int ci_dpm_force_state_sclk(struct amdgpu_device *adev, u32 n)
1796 struct ci_power_info *pi = ci_get_pi(adev);
1798 if (!pi->sclk_dpm_key_disabled) {
1799 PPSMC_Result smc_result =
1800 amdgpu_ci_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_SCLKDPM_SetEnabledMask, 1 << n);
1801 if (smc_result != PPSMC_Result_OK)
1808 static int ci_dpm_force_state_mclk(struct amdgpu_device *adev, u32 n)
1810 struct ci_power_info *pi = ci_get_pi(adev);
1812 if (!pi->mclk_dpm_key_disabled) {
1813 PPSMC_Result smc_result =
1814 amdgpu_ci_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_MCLKDPM_SetEnabledMask, 1 << n);
1815 if (smc_result != PPSMC_Result_OK)
1822 static int ci_dpm_force_state_pcie(struct amdgpu_device *adev, u32 n)
1824 struct ci_power_info *pi = ci_get_pi(adev);
1826 if (!pi->pcie_dpm_key_disabled) {
1827 PPSMC_Result smc_result =
1828 amdgpu_ci_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_PCIeDPM_ForceLevel, n);
1829 if (smc_result != PPSMC_Result_OK)
1836 static int ci_set_power_limit(struct amdgpu_device *adev, u32 n)
1838 struct ci_power_info *pi = ci_get_pi(adev);
1840 if (pi->power_containment_features & POWERCONTAINMENT_FEATURE_PkgPwrLimit) {
1841 PPSMC_Result smc_result =
1842 amdgpu_ci_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_PkgPwrSetLimit, n);
1843 if (smc_result != PPSMC_Result_OK)
1850 static int ci_set_overdrive_target_tdp(struct amdgpu_device *adev,
1853 PPSMC_Result smc_result =
1854 amdgpu_ci_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_OverDriveSetTargetTdp, target_tdp);
1855 if (smc_result != PPSMC_Result_OK)
1861 static int ci_set_boot_state(struct amdgpu_device *adev)
1863 return ci_enable_sclk_mclk_dpm(adev, false);
1867 static u32 ci_get_average_sclk_freq(struct amdgpu_device *adev)
1870 PPSMC_Result smc_result =
1871 amdgpu_ci_send_msg_to_smc_return_parameter(adev,
1872 PPSMC_MSG_API_GetSclkFrequency,
1874 if (smc_result != PPSMC_Result_OK)
1880 static u32 ci_get_average_mclk_freq(struct amdgpu_device *adev)
1883 PPSMC_Result smc_result =
1884 amdgpu_ci_send_msg_to_smc_return_parameter(adev,
1885 PPSMC_MSG_API_GetMclkFrequency,
1887 if (smc_result != PPSMC_Result_OK)
1893 static void ci_dpm_start_smc(struct amdgpu_device *adev)
1897 amdgpu_ci_program_jump_on_start(adev);
1898 amdgpu_ci_start_smc_clock(adev);
1899 amdgpu_ci_start_smc(adev);
1900 for (i = 0; i < adev->usec_timeout; i++) {
1901 if (RREG32_SMC(ixFIRMWARE_FLAGS) & FIRMWARE_FLAGS__INTERRUPTS_ENABLED_MASK)
1906 static void ci_dpm_stop_smc(struct amdgpu_device *adev)
1908 amdgpu_ci_reset_smc(adev);
1909 amdgpu_ci_stop_smc_clock(adev);
1912 static int ci_process_firmware_header(struct amdgpu_device *adev)
1914 struct ci_power_info *pi = ci_get_pi(adev);
1918 ret = amdgpu_ci_read_smc_sram_dword(adev,
1919 SMU7_FIRMWARE_HEADER_LOCATION +
1920 offsetof(SMU7_Firmware_Header, DpmTable),
1921 &tmp, pi->sram_end);
1925 pi->dpm_table_start = tmp;
1927 ret = amdgpu_ci_read_smc_sram_dword(adev,
1928 SMU7_FIRMWARE_HEADER_LOCATION +
1929 offsetof(SMU7_Firmware_Header, SoftRegisters),
1930 &tmp, pi->sram_end);
1934 pi->soft_regs_start = tmp;
1936 ret = amdgpu_ci_read_smc_sram_dword(adev,
1937 SMU7_FIRMWARE_HEADER_LOCATION +
1938 offsetof(SMU7_Firmware_Header, mcRegisterTable),
1939 &tmp, pi->sram_end);
1943 pi->mc_reg_table_start = tmp;
1945 ret = amdgpu_ci_read_smc_sram_dword(adev,
1946 SMU7_FIRMWARE_HEADER_LOCATION +
1947 offsetof(SMU7_Firmware_Header, FanTable),
1948 &tmp, pi->sram_end);
1952 pi->fan_table_start = tmp;
1954 ret = amdgpu_ci_read_smc_sram_dword(adev,
1955 SMU7_FIRMWARE_HEADER_LOCATION +
1956 offsetof(SMU7_Firmware_Header, mcArbDramTimingTable),
1957 &tmp, pi->sram_end);
1961 pi->arb_table_start = tmp;
1966 static void ci_read_clock_registers(struct amdgpu_device *adev)
1968 struct ci_power_info *pi = ci_get_pi(adev);
1970 pi->clock_registers.cg_spll_func_cntl =
1971 RREG32_SMC(ixCG_SPLL_FUNC_CNTL);
1972 pi->clock_registers.cg_spll_func_cntl_2 =
1973 RREG32_SMC(ixCG_SPLL_FUNC_CNTL_2);
1974 pi->clock_registers.cg_spll_func_cntl_3 =
1975 RREG32_SMC(ixCG_SPLL_FUNC_CNTL_3);
1976 pi->clock_registers.cg_spll_func_cntl_4 =
1977 RREG32_SMC(ixCG_SPLL_FUNC_CNTL_4);
1978 pi->clock_registers.cg_spll_spread_spectrum =
1979 RREG32_SMC(ixCG_SPLL_SPREAD_SPECTRUM);
1980 pi->clock_registers.cg_spll_spread_spectrum_2 =
1981 RREG32_SMC(ixCG_SPLL_SPREAD_SPECTRUM_2);
1982 pi->clock_registers.dll_cntl = RREG32(mmDLL_CNTL);
1983 pi->clock_registers.mclk_pwrmgt_cntl = RREG32(mmMCLK_PWRMGT_CNTL);
1984 pi->clock_registers.mpll_ad_func_cntl = RREG32(mmMPLL_AD_FUNC_CNTL);
1985 pi->clock_registers.mpll_dq_func_cntl = RREG32(mmMPLL_DQ_FUNC_CNTL);
1986 pi->clock_registers.mpll_func_cntl = RREG32(mmMPLL_FUNC_CNTL);
1987 pi->clock_registers.mpll_func_cntl_1 = RREG32(mmMPLL_FUNC_CNTL_1);
1988 pi->clock_registers.mpll_func_cntl_2 = RREG32(mmMPLL_FUNC_CNTL_2);
1989 pi->clock_registers.mpll_ss1 = RREG32(mmMPLL_SS1);
1990 pi->clock_registers.mpll_ss2 = RREG32(mmMPLL_SS2);
1993 static void ci_init_sclk_t(struct amdgpu_device *adev)
1995 struct ci_power_info *pi = ci_get_pi(adev);
1997 pi->low_sclk_interrupt_t = 0;
2000 static void ci_enable_thermal_protection(struct amdgpu_device *adev,
2003 u32 tmp = RREG32_SMC(ixGENERAL_PWRMGT);
2006 tmp &= ~GENERAL_PWRMGT__THERMAL_PROTECTION_DIS_MASK;
2008 tmp |= GENERAL_PWRMGT__THERMAL_PROTECTION_DIS_MASK;
2009 WREG32_SMC(ixGENERAL_PWRMGT, tmp);
2012 static void ci_enable_acpi_power_management(struct amdgpu_device *adev)
2014 u32 tmp = RREG32_SMC(ixGENERAL_PWRMGT);
2016 tmp |= GENERAL_PWRMGT__STATIC_PM_EN_MASK;
2018 WREG32_SMC(ixGENERAL_PWRMGT, tmp);
2022 static int ci_enter_ulp_state(struct amdgpu_device *adev)
2025 WREG32(mmSMC_MESSAGE_0, PPSMC_MSG_SwitchToMinimumPower);
2032 static int ci_exit_ulp_state(struct amdgpu_device *adev)
2036 WREG32(mmSMC_MESSAGE_0, PPSMC_MSG_ResumeFromMinimumPower);
2040 for (i = 0; i < adev->usec_timeout; i++) {
2041 if (RREG32(mmSMC_RESP_0) == 1)
2050 static int ci_notify_smc_display_change(struct amdgpu_device *adev,
2053 PPSMC_Msg msg = has_display ? PPSMC_MSG_HasDisplay : PPSMC_MSG_NoDisplay;
2055 return (amdgpu_ci_send_msg_to_smc(adev, msg) == PPSMC_Result_OK) ? 0 : -EINVAL;
2058 static int ci_enable_ds_master_switch(struct amdgpu_device *adev,
2061 struct ci_power_info *pi = ci_get_pi(adev);
2064 if (pi->caps_sclk_ds) {
2065 if (amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_MASTER_DeepSleep_ON) != PPSMC_Result_OK)
2068 if (amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_MASTER_DeepSleep_OFF) != PPSMC_Result_OK)
2072 if (pi->caps_sclk_ds) {
2073 if (amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_MASTER_DeepSleep_OFF) != PPSMC_Result_OK)
2081 static void ci_program_display_gap(struct amdgpu_device *adev)
2083 u32 tmp = RREG32_SMC(ixCG_DISPLAY_GAP_CNTL);
2084 u32 pre_vbi_time_in_us;
2085 u32 frame_time_in_us;
2086 u32 ref_clock = adev->clock.spll.reference_freq;
2087 u32 refresh_rate = amdgpu_dpm_get_vrefresh(adev);
2088 u32 vblank_time = amdgpu_dpm_get_vblank_time(adev);
2090 tmp &= ~CG_DISPLAY_GAP_CNTL__DISP_GAP_MASK;
2091 if (adev->pm.dpm.new_active_crtc_count > 0)
2092 tmp |= (AMDGPU_PM_DISPLAY_GAP_VBLANK_OR_WM << CG_DISPLAY_GAP_CNTL__DISP_GAP__SHIFT);
2094 tmp |= (AMDGPU_PM_DISPLAY_GAP_IGNORE << CG_DISPLAY_GAP_CNTL__DISP_GAP__SHIFT);
2095 WREG32_SMC(ixCG_DISPLAY_GAP_CNTL, tmp);
2097 if (refresh_rate == 0)
2099 if (vblank_time == 0xffffffff)
2101 frame_time_in_us = 1000000 / refresh_rate;
2102 pre_vbi_time_in_us =
2103 frame_time_in_us - 200 - vblank_time;
2104 tmp = pre_vbi_time_in_us * (ref_clock / 100);
2106 WREG32_SMC(ixCG_DISPLAY_GAP_CNTL2, tmp);
2107 ci_write_smc_soft_register(adev, offsetof(SMU7_SoftRegisters, PreVBlankGap), 0x64);
2108 ci_write_smc_soft_register(adev, offsetof(SMU7_SoftRegisters, VBlankTimeout), (frame_time_in_us - pre_vbi_time_in_us));
2111 ci_notify_smc_display_change(adev, (adev->pm.dpm.new_active_crtc_count == 1));
2115 static void ci_enable_spread_spectrum(struct amdgpu_device *adev, bool enable)
2117 struct ci_power_info *pi = ci_get_pi(adev);
2121 if (pi->caps_sclk_ss_support) {
2122 tmp = RREG32_SMC(ixGENERAL_PWRMGT);
2123 tmp |= GENERAL_PWRMGT__DYN_SPREAD_SPECTRUM_EN_MASK;
2124 WREG32_SMC(ixGENERAL_PWRMGT, tmp);
2127 tmp = RREG32_SMC(ixCG_SPLL_SPREAD_SPECTRUM);
2128 tmp &= ~CG_SPLL_SPREAD_SPECTRUM__SSEN_MASK;
2129 WREG32_SMC(ixCG_SPLL_SPREAD_SPECTRUM, tmp);
2131 tmp = RREG32_SMC(ixGENERAL_PWRMGT);
2132 tmp &= ~GENERAL_PWRMGT__DYN_SPREAD_SPECTRUM_EN_MASK;
2133 WREG32_SMC(ixGENERAL_PWRMGT, tmp);
2137 static void ci_program_sstp(struct amdgpu_device *adev)
2139 WREG32_SMC(ixCG_STATIC_SCREEN_PARAMETER,
2140 ((CISLANDS_SSTU_DFLT << CG_STATIC_SCREEN_PARAMETER__STATIC_SCREEN_THRESHOLD_UNIT__SHIFT) |
2141 (CISLANDS_SST_DFLT << CG_STATIC_SCREEN_PARAMETER__STATIC_SCREEN_THRESHOLD__SHIFT)));
2144 static void ci_enable_display_gap(struct amdgpu_device *adev)
2146 u32 tmp = RREG32_SMC(ixCG_DISPLAY_GAP_CNTL);
2148 tmp &= ~(CG_DISPLAY_GAP_CNTL__DISP_GAP_MASK |
2149 CG_DISPLAY_GAP_CNTL__DISP_GAP_MCHG_MASK);
2150 tmp |= ((AMDGPU_PM_DISPLAY_GAP_IGNORE << CG_DISPLAY_GAP_CNTL__DISP_GAP__SHIFT) |
2151 (AMDGPU_PM_DISPLAY_GAP_VBLANK << CG_DISPLAY_GAP_CNTL__DISP_GAP_MCHG__SHIFT));
2153 WREG32_SMC(ixCG_DISPLAY_GAP_CNTL, tmp);
2156 static void ci_program_vc(struct amdgpu_device *adev)
2160 tmp = RREG32_SMC(ixSCLK_PWRMGT_CNTL);
2161 tmp &= ~(SCLK_PWRMGT_CNTL__RESET_SCLK_CNT_MASK | SCLK_PWRMGT_CNTL__RESET_BUSY_CNT_MASK);
2162 WREG32_SMC(ixSCLK_PWRMGT_CNTL, tmp);
2164 WREG32_SMC(ixCG_FREQ_TRAN_VOTING_0, CISLANDS_VRC_DFLT0);
2165 WREG32_SMC(ixCG_FREQ_TRAN_VOTING_1, CISLANDS_VRC_DFLT1);
2166 WREG32_SMC(ixCG_FREQ_TRAN_VOTING_2, CISLANDS_VRC_DFLT2);
2167 WREG32_SMC(ixCG_FREQ_TRAN_VOTING_3, CISLANDS_VRC_DFLT3);
2168 WREG32_SMC(ixCG_FREQ_TRAN_VOTING_4, CISLANDS_VRC_DFLT4);
2169 WREG32_SMC(ixCG_FREQ_TRAN_VOTING_5, CISLANDS_VRC_DFLT5);
2170 WREG32_SMC(ixCG_FREQ_TRAN_VOTING_6, CISLANDS_VRC_DFLT6);
2171 WREG32_SMC(ixCG_FREQ_TRAN_VOTING_7, CISLANDS_VRC_DFLT7);
2174 static void ci_clear_vc(struct amdgpu_device *adev)
2178 tmp = RREG32_SMC(ixSCLK_PWRMGT_CNTL);
2179 tmp |= (SCLK_PWRMGT_CNTL__RESET_SCLK_CNT_MASK | SCLK_PWRMGT_CNTL__RESET_BUSY_CNT_MASK);
2180 WREG32_SMC(ixSCLK_PWRMGT_CNTL, tmp);
2182 WREG32_SMC(ixCG_FREQ_TRAN_VOTING_0, 0);
2183 WREG32_SMC(ixCG_FREQ_TRAN_VOTING_1, 0);
2184 WREG32_SMC(ixCG_FREQ_TRAN_VOTING_2, 0);
2185 WREG32_SMC(ixCG_FREQ_TRAN_VOTING_3, 0);
2186 WREG32_SMC(ixCG_FREQ_TRAN_VOTING_4, 0);
2187 WREG32_SMC(ixCG_FREQ_TRAN_VOTING_5, 0);
2188 WREG32_SMC(ixCG_FREQ_TRAN_VOTING_6, 0);
2189 WREG32_SMC(ixCG_FREQ_TRAN_VOTING_7, 0);
2192 static int ci_upload_firmware(struct amdgpu_device *adev)
2194 struct ci_power_info *pi = ci_get_pi(adev);
2197 for (i = 0; i < adev->usec_timeout; i++) {
2198 if (RREG32_SMC(ixRCU_UC_EVENTS) & RCU_UC_EVENTS__boot_seq_done_MASK)
2201 WREG32_SMC(ixSMC_SYSCON_MISC_CNTL, 1);
2203 amdgpu_ci_stop_smc_clock(adev);
2204 amdgpu_ci_reset_smc(adev);
2206 ret = amdgpu_ci_load_smc_ucode(adev, pi->sram_end);
2212 static int ci_get_svi2_voltage_table(struct amdgpu_device *adev,
2213 struct amdgpu_clock_voltage_dependency_table *voltage_dependency_table,
2214 struct atom_voltage_table *voltage_table)
2218 if (voltage_dependency_table == NULL)
2221 voltage_table->mask_low = 0;
2222 voltage_table->phase_delay = 0;
2224 voltage_table->count = voltage_dependency_table->count;
2225 for (i = 0; i < voltage_table->count; i++) {
2226 voltage_table->entries[i].value = voltage_dependency_table->entries[i].v;
2227 voltage_table->entries[i].smio_low = 0;
2233 static int ci_construct_voltage_tables(struct amdgpu_device *adev)
2235 struct ci_power_info *pi = ci_get_pi(adev);
2238 if (pi->voltage_control == CISLANDS_VOLTAGE_CONTROL_BY_GPIO) {
2239 ret = amdgpu_atombios_get_voltage_table(adev, VOLTAGE_TYPE_VDDC,
2240 VOLTAGE_OBJ_GPIO_LUT,
2241 &pi->vddc_voltage_table);
2244 } else if (pi->voltage_control == CISLANDS_VOLTAGE_CONTROL_BY_SVID2) {
2245 ret = ci_get_svi2_voltage_table(adev,
2246 &adev->pm.dpm.dyn_state.vddc_dependency_on_mclk,
2247 &pi->vddc_voltage_table);
2252 if (pi->vddc_voltage_table.count > SMU7_MAX_LEVELS_VDDC)
2253 ci_trim_voltage_table_to_fit_state_table(adev, SMU7_MAX_LEVELS_VDDC,
2254 &pi->vddc_voltage_table);
2256 if (pi->vddci_control == CISLANDS_VOLTAGE_CONTROL_BY_GPIO) {
2257 ret = amdgpu_atombios_get_voltage_table(adev, VOLTAGE_TYPE_VDDCI,
2258 VOLTAGE_OBJ_GPIO_LUT,
2259 &pi->vddci_voltage_table);
2262 } else if (pi->vddci_control == CISLANDS_VOLTAGE_CONTROL_BY_SVID2) {
2263 ret = ci_get_svi2_voltage_table(adev,
2264 &adev->pm.dpm.dyn_state.vddci_dependency_on_mclk,
2265 &pi->vddci_voltage_table);
2270 if (pi->vddci_voltage_table.count > SMU7_MAX_LEVELS_VDDCI)
2271 ci_trim_voltage_table_to_fit_state_table(adev, SMU7_MAX_LEVELS_VDDCI,
2272 &pi->vddci_voltage_table);
2274 if (pi->mvdd_control == CISLANDS_VOLTAGE_CONTROL_BY_GPIO) {
2275 ret = amdgpu_atombios_get_voltage_table(adev, VOLTAGE_TYPE_MVDDC,
2276 VOLTAGE_OBJ_GPIO_LUT,
2277 &pi->mvdd_voltage_table);
2280 } else if (pi->mvdd_control == CISLANDS_VOLTAGE_CONTROL_BY_SVID2) {
2281 ret = ci_get_svi2_voltage_table(adev,
2282 &adev->pm.dpm.dyn_state.mvdd_dependency_on_mclk,
2283 &pi->mvdd_voltage_table);
2288 if (pi->mvdd_voltage_table.count > SMU7_MAX_LEVELS_MVDD)
2289 ci_trim_voltage_table_to_fit_state_table(adev, SMU7_MAX_LEVELS_MVDD,
2290 &pi->mvdd_voltage_table);
2295 static void ci_populate_smc_voltage_table(struct amdgpu_device *adev,
2296 struct atom_voltage_table_entry *voltage_table,
2297 SMU7_Discrete_VoltageLevel *smc_voltage_table)
2301 ret = ci_get_std_voltage_value_sidd(adev, voltage_table,
2302 &smc_voltage_table->StdVoltageHiSidd,
2303 &smc_voltage_table->StdVoltageLoSidd);
2306 smc_voltage_table->StdVoltageHiSidd = voltage_table->value * VOLTAGE_SCALE;
2307 smc_voltage_table->StdVoltageLoSidd = voltage_table->value * VOLTAGE_SCALE;
2310 smc_voltage_table->Voltage = cpu_to_be16(voltage_table->value * VOLTAGE_SCALE);
2311 smc_voltage_table->StdVoltageHiSidd =
2312 cpu_to_be16(smc_voltage_table->StdVoltageHiSidd);
2313 smc_voltage_table->StdVoltageLoSidd =
2314 cpu_to_be16(smc_voltage_table->StdVoltageLoSidd);
2317 static int ci_populate_smc_vddc_table(struct amdgpu_device *adev,
2318 SMU7_Discrete_DpmTable *table)
2320 struct ci_power_info *pi = ci_get_pi(adev);
2323 table->VddcLevelCount = pi->vddc_voltage_table.count;
2324 for (count = 0; count < table->VddcLevelCount; count++) {
2325 ci_populate_smc_voltage_table(adev,
2326 &pi->vddc_voltage_table.entries[count],
2327 &table->VddcLevel[count]);
2329 if (pi->voltage_control == CISLANDS_VOLTAGE_CONTROL_BY_GPIO)
2330 table->VddcLevel[count].Smio |=
2331 pi->vddc_voltage_table.entries[count].smio_low;
2333 table->VddcLevel[count].Smio = 0;
2335 table->VddcLevelCount = cpu_to_be32(table->VddcLevelCount);
2340 static int ci_populate_smc_vddci_table(struct amdgpu_device *adev,
2341 SMU7_Discrete_DpmTable *table)
2344 struct ci_power_info *pi = ci_get_pi(adev);
2346 table->VddciLevelCount = pi->vddci_voltage_table.count;
2347 for (count = 0; count < table->VddciLevelCount; count++) {
2348 ci_populate_smc_voltage_table(adev,
2349 &pi->vddci_voltage_table.entries[count],
2350 &table->VddciLevel[count]);
2352 if (pi->vddci_control == CISLANDS_VOLTAGE_CONTROL_BY_GPIO)
2353 table->VddciLevel[count].Smio |=
2354 pi->vddci_voltage_table.entries[count].smio_low;
2356 table->VddciLevel[count].Smio = 0;
2358 table->VddciLevelCount = cpu_to_be32(table->VddciLevelCount);
2363 static int ci_populate_smc_mvdd_table(struct amdgpu_device *adev,
2364 SMU7_Discrete_DpmTable *table)
2366 struct ci_power_info *pi = ci_get_pi(adev);
2369 table->MvddLevelCount = pi->mvdd_voltage_table.count;
2370 for (count = 0; count < table->MvddLevelCount; count++) {
2371 ci_populate_smc_voltage_table(adev,
2372 &pi->mvdd_voltage_table.entries[count],
2373 &table->MvddLevel[count]);
2375 if (pi->mvdd_control == CISLANDS_VOLTAGE_CONTROL_BY_GPIO)
2376 table->MvddLevel[count].Smio |=
2377 pi->mvdd_voltage_table.entries[count].smio_low;
2379 table->MvddLevel[count].Smio = 0;
2381 table->MvddLevelCount = cpu_to_be32(table->MvddLevelCount);
2386 static int ci_populate_smc_voltage_tables(struct amdgpu_device *adev,
2387 SMU7_Discrete_DpmTable *table)
2391 ret = ci_populate_smc_vddc_table(adev, table);
2395 ret = ci_populate_smc_vddci_table(adev, table);
2399 ret = ci_populate_smc_mvdd_table(adev, table);
2406 static int ci_populate_mvdd_value(struct amdgpu_device *adev, u32 mclk,
2407 SMU7_Discrete_VoltageLevel *voltage)
2409 struct ci_power_info *pi = ci_get_pi(adev);
2412 if (pi->mvdd_control != CISLANDS_VOLTAGE_CONTROL_NONE) {
2413 for (i = 0; i < adev->pm.dpm.dyn_state.mvdd_dependency_on_mclk.count; i++) {
2414 if (mclk <= adev->pm.dpm.dyn_state.mvdd_dependency_on_mclk.entries[i].clk) {
2415 voltage->Voltage = pi->mvdd_voltage_table.entries[i].value;
2420 if (i >= adev->pm.dpm.dyn_state.mvdd_dependency_on_mclk.count)
2427 static int ci_get_std_voltage_value_sidd(struct amdgpu_device *adev,
2428 struct atom_voltage_table_entry *voltage_table,
2429 u16 *std_voltage_hi_sidd, u16 *std_voltage_lo_sidd)
2432 bool voltage_found = false;
2433 *std_voltage_hi_sidd = voltage_table->value * VOLTAGE_SCALE;
2434 *std_voltage_lo_sidd = voltage_table->value * VOLTAGE_SCALE;
2436 if (adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries == NULL)
2439 if (adev->pm.dpm.dyn_state.cac_leakage_table.entries) {
2440 for (v_index = 0; (u32)v_index < adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.count; v_index++) {
2441 if (voltage_table->value ==
2442 adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[v_index].v) {
2443 voltage_found = true;
2444 if ((u32)v_index < adev->pm.dpm.dyn_state.cac_leakage_table.count)
2447 idx = adev->pm.dpm.dyn_state.cac_leakage_table.count - 1;
2448 *std_voltage_lo_sidd =
2449 adev->pm.dpm.dyn_state.cac_leakage_table.entries[idx].vddc * VOLTAGE_SCALE;
2450 *std_voltage_hi_sidd =
2451 adev->pm.dpm.dyn_state.cac_leakage_table.entries[idx].leakage * VOLTAGE_SCALE;
2456 if (!voltage_found) {
2457 for (v_index = 0; (u32)v_index < adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.count; v_index++) {
2458 if (voltage_table->value <=
2459 adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[v_index].v) {
2460 voltage_found = true;
2461 if ((u32)v_index < adev->pm.dpm.dyn_state.cac_leakage_table.count)
2464 idx = adev->pm.dpm.dyn_state.cac_leakage_table.count - 1;
2465 *std_voltage_lo_sidd =
2466 adev->pm.dpm.dyn_state.cac_leakage_table.entries[idx].vddc * VOLTAGE_SCALE;
2467 *std_voltage_hi_sidd =
2468 adev->pm.dpm.dyn_state.cac_leakage_table.entries[idx].leakage * VOLTAGE_SCALE;
2478 static void ci_populate_phase_value_based_on_sclk(struct amdgpu_device *adev,
2479 const struct amdgpu_phase_shedding_limits_table *limits,
2481 u32 *phase_shedding)
2485 *phase_shedding = 1;
2487 for (i = 0; i < limits->count; i++) {
2488 if (sclk < limits->entries[i].sclk) {
2489 *phase_shedding = i;
2495 static void ci_populate_phase_value_based_on_mclk(struct amdgpu_device *adev,
2496 const struct amdgpu_phase_shedding_limits_table *limits,
2498 u32 *phase_shedding)
2502 *phase_shedding = 1;
2504 for (i = 0; i < limits->count; i++) {
2505 if (mclk < limits->entries[i].mclk) {
2506 *phase_shedding = i;
2512 static int ci_init_arb_table_index(struct amdgpu_device *adev)
2514 struct ci_power_info *pi = ci_get_pi(adev);
2518 ret = amdgpu_ci_read_smc_sram_dword(adev, pi->arb_table_start,
2519 &tmp, pi->sram_end);
2524 tmp |= MC_CG_ARB_FREQ_F1 << 24;
2526 return amdgpu_ci_write_smc_sram_dword(adev, pi->arb_table_start,
2530 static int ci_get_dependency_volt_by_clk(struct amdgpu_device *adev,
2531 struct amdgpu_clock_voltage_dependency_table *allowed_clock_voltage_table,
2532 u32 clock, u32 *voltage)
2536 if (allowed_clock_voltage_table->count == 0)
2539 for (i = 0; i < allowed_clock_voltage_table->count; i++) {
2540 if (allowed_clock_voltage_table->entries[i].clk >= clock) {
2541 *voltage = allowed_clock_voltage_table->entries[i].v;
2546 *voltage = allowed_clock_voltage_table->entries[i-1].v;
2551 static u8 ci_get_sleep_divider_id_from_clock(struct amdgpu_device *adev,
2552 u32 sclk, u32 min_sclk_in_sr)
2556 u32 min = (min_sclk_in_sr > CISLAND_MINIMUM_ENGINE_CLOCK) ?
2557 min_sclk_in_sr : CISLAND_MINIMUM_ENGINE_CLOCK;
2562 for (i = CISLAND_MAX_DEEPSLEEP_DIVIDER_ID; ; i--) {
2563 tmp = sclk / (1 << i);
2564 if (tmp >= min || i == 0)
2571 static int ci_initial_switch_from_arb_f0_to_f1(struct amdgpu_device *adev)
2573 return ci_copy_and_switch_arb_sets(adev, MC_CG_ARB_FREQ_F0, MC_CG_ARB_FREQ_F1);
2576 static int ci_reset_to_default(struct amdgpu_device *adev)
2578 return (amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_ResetToDefaults) == PPSMC_Result_OK) ?
2582 static int ci_force_switch_to_arb_f0(struct amdgpu_device *adev)
2586 tmp = (RREG32_SMC(ixSMC_SCRATCH9) & 0x0000ff00) >> 8;
2588 if (tmp == MC_CG_ARB_FREQ_F0)
2591 return ci_copy_and_switch_arb_sets(adev, tmp, MC_CG_ARB_FREQ_F0);
2594 static void ci_register_patching_mc_arb(struct amdgpu_device *adev,
2595 const u32 engine_clock,
2596 const u32 memory_clock,
2602 tmp = RREG32(mmMC_SEQ_MISC0);
2603 patch = ((tmp & 0x0000f00) == 0x300) ? true : false;
2606 ((adev->pdev->device == 0x67B0) ||
2607 (adev->pdev->device == 0x67B1))) {
2608 if ((memory_clock > 100000) && (memory_clock <= 125000)) {
2609 tmp2 = (((0x31 * engine_clock) / 125000) - 1) & 0xff;
2610 *dram_timimg2 &= ~0x00ff0000;
2611 *dram_timimg2 |= tmp2 << 16;
2612 } else if ((memory_clock > 125000) && (memory_clock <= 137500)) {
2613 tmp2 = (((0x36 * engine_clock) / 137500) - 1) & 0xff;
2614 *dram_timimg2 &= ~0x00ff0000;
2615 *dram_timimg2 |= tmp2 << 16;
2620 static int ci_populate_memory_timing_parameters(struct amdgpu_device *adev,
2623 SMU7_Discrete_MCArbDramTimingTableEntry *arb_regs)
2629 amdgpu_atombios_set_engine_dram_timings(adev, sclk, mclk);
2631 dram_timing = RREG32(mmMC_ARB_DRAM_TIMING);
2632 dram_timing2 = RREG32(mmMC_ARB_DRAM_TIMING2);
2633 burst_time = RREG32(mmMC_ARB_BURST_TIME) & MC_ARB_BURST_TIME__STATE0_MASK;
2635 ci_register_patching_mc_arb(adev, sclk, mclk, &dram_timing2);
2637 arb_regs->McArbDramTiming = cpu_to_be32(dram_timing);
2638 arb_regs->McArbDramTiming2 = cpu_to_be32(dram_timing2);
2639 arb_regs->McArbBurstTime = (u8)burst_time;
2644 static int ci_do_program_memory_timing_parameters(struct amdgpu_device *adev)
2646 struct ci_power_info *pi = ci_get_pi(adev);
2647 SMU7_Discrete_MCArbDramTimingTable arb_regs;
2651 memset(&arb_regs, 0, sizeof(SMU7_Discrete_MCArbDramTimingTable));
2653 for (i = 0; i < pi->dpm_table.sclk_table.count; i++) {
2654 for (j = 0; j < pi->dpm_table.mclk_table.count; j++) {
2655 ret = ci_populate_memory_timing_parameters(adev,
2656 pi->dpm_table.sclk_table.dpm_levels[i].value,
2657 pi->dpm_table.mclk_table.dpm_levels[j].value,
2658 &arb_regs.entries[i][j]);
2665 ret = amdgpu_ci_copy_bytes_to_smc(adev,
2666 pi->arb_table_start,
2668 sizeof(SMU7_Discrete_MCArbDramTimingTable),
2674 static int ci_program_memory_timing_parameters(struct amdgpu_device *adev)
2676 struct ci_power_info *pi = ci_get_pi(adev);
2678 if (pi->need_update_smu7_dpm_table == 0)
2681 return ci_do_program_memory_timing_parameters(adev);
2684 static void ci_populate_smc_initial_state(struct amdgpu_device *adev,
2685 struct amdgpu_ps *amdgpu_boot_state)
2687 struct ci_ps *boot_state = ci_get_ps(amdgpu_boot_state);
2688 struct ci_power_info *pi = ci_get_pi(adev);
2691 for (level = 0; level < adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.count; level++) {
2692 if (adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[level].clk >=
2693 boot_state->performance_levels[0].sclk) {
2694 pi->smc_state_table.GraphicsBootLevel = level;
2699 for (level = 0; level < adev->pm.dpm.dyn_state.vddc_dependency_on_mclk.count; level++) {
2700 if (adev->pm.dpm.dyn_state.vddc_dependency_on_mclk.entries[level].clk >=
2701 boot_state->performance_levels[0].mclk) {
2702 pi->smc_state_table.MemoryBootLevel = level;
2708 static u32 ci_get_dpm_level_enable_mask_value(struct ci_single_dpm_table *dpm_table)
2713 for (i = dpm_table->count; i > 0; i--) {
2714 mask_value = mask_value << 1;
2715 if (dpm_table->dpm_levels[i-1].enabled)
2718 mask_value &= 0xFFFFFFFE;
2724 static void ci_populate_smc_link_level(struct amdgpu_device *adev,
2725 SMU7_Discrete_DpmTable *table)
2727 struct ci_power_info *pi = ci_get_pi(adev);
2728 struct ci_dpm_table *dpm_table = &pi->dpm_table;
2731 for (i = 0; i < dpm_table->pcie_speed_table.count; i++) {
2732 table->LinkLevel[i].PcieGenSpeed =
2733 (u8)dpm_table->pcie_speed_table.dpm_levels[i].value;
2734 table->LinkLevel[i].PcieLaneCount =
2735 amdgpu_encode_pci_lane_width(dpm_table->pcie_speed_table.dpm_levels[i].param1);
2736 table->LinkLevel[i].EnabledForActivity = 1;
2737 table->LinkLevel[i].DownT = cpu_to_be32(5);
2738 table->LinkLevel[i].UpT = cpu_to_be32(30);
2741 pi->smc_state_table.LinkLevelCount = (u8)dpm_table->pcie_speed_table.count;
2742 pi->dpm_level_enable_mask.pcie_dpm_enable_mask =
2743 ci_get_dpm_level_enable_mask_value(&dpm_table->pcie_speed_table);
2746 static int ci_populate_smc_uvd_level(struct amdgpu_device *adev,
2747 SMU7_Discrete_DpmTable *table)
2750 struct atom_clock_dividers dividers;
2753 table->UvdLevelCount =
2754 adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.count;
2756 for (count = 0; count < table->UvdLevelCount; count++) {
2757 table->UvdLevel[count].VclkFrequency =
2758 adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[count].vclk;
2759 table->UvdLevel[count].DclkFrequency =
2760 adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[count].dclk;
2761 table->UvdLevel[count].MinVddc =
2762 adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[count].v * VOLTAGE_SCALE;
2763 table->UvdLevel[count].MinVddcPhases = 1;
2765 ret = amdgpu_atombios_get_clock_dividers(adev,
2766 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
2767 table->UvdLevel[count].VclkFrequency, false, ÷rs);
2771 table->UvdLevel[count].VclkDivider = (u8)dividers.post_divider;
2773 ret = amdgpu_atombios_get_clock_dividers(adev,
2774 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
2775 table->UvdLevel[count].DclkFrequency, false, ÷rs);
2779 table->UvdLevel[count].DclkDivider = (u8)dividers.post_divider;
2781 table->UvdLevel[count].VclkFrequency = cpu_to_be32(table->UvdLevel[count].VclkFrequency);
2782 table->UvdLevel[count].DclkFrequency = cpu_to_be32(table->UvdLevel[count].DclkFrequency);
2783 table->UvdLevel[count].MinVddc = cpu_to_be16(table->UvdLevel[count].MinVddc);
2789 static int ci_populate_smc_vce_level(struct amdgpu_device *adev,
2790 SMU7_Discrete_DpmTable *table)
2793 struct atom_clock_dividers dividers;
2796 table->VceLevelCount =
2797 adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.count;
2799 for (count = 0; count < table->VceLevelCount; count++) {
2800 table->VceLevel[count].Frequency =
2801 adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries[count].evclk;
2802 table->VceLevel[count].MinVoltage =
2803 (u16)adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries[count].v * VOLTAGE_SCALE;
2804 table->VceLevel[count].MinPhases = 1;
2806 ret = amdgpu_atombios_get_clock_dividers(adev,
2807 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
2808 table->VceLevel[count].Frequency, false, ÷rs);
2812 table->VceLevel[count].Divider = (u8)dividers.post_divider;
2814 table->VceLevel[count].Frequency = cpu_to_be32(table->VceLevel[count].Frequency);
2815 table->VceLevel[count].MinVoltage = cpu_to_be16(table->VceLevel[count].MinVoltage);
2822 static int ci_populate_smc_acp_level(struct amdgpu_device *adev,
2823 SMU7_Discrete_DpmTable *table)
2826 struct atom_clock_dividers dividers;
2829 table->AcpLevelCount = (u8)
2830 (adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.count);
2832 for (count = 0; count < table->AcpLevelCount; count++) {
2833 table->AcpLevel[count].Frequency =
2834 adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries[count].clk;
2835 table->AcpLevel[count].MinVoltage =
2836 adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries[count].v;
2837 table->AcpLevel[count].MinPhases = 1;
2839 ret = amdgpu_atombios_get_clock_dividers(adev,
2840 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
2841 table->AcpLevel[count].Frequency, false, ÷rs);
2845 table->AcpLevel[count].Divider = (u8)dividers.post_divider;
2847 table->AcpLevel[count].Frequency = cpu_to_be32(table->AcpLevel[count].Frequency);
2848 table->AcpLevel[count].MinVoltage = cpu_to_be16(table->AcpLevel[count].MinVoltage);
2854 static int ci_populate_smc_samu_level(struct amdgpu_device *adev,
2855 SMU7_Discrete_DpmTable *table)
2858 struct atom_clock_dividers dividers;
2861 table->SamuLevelCount =
2862 adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.count;
2864 for (count = 0; count < table->SamuLevelCount; count++) {
2865 table->SamuLevel[count].Frequency =
2866 adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries[count].clk;
2867 table->SamuLevel[count].MinVoltage =
2868 adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries[count].v * VOLTAGE_SCALE;
2869 table->SamuLevel[count].MinPhases = 1;
2871 ret = amdgpu_atombios_get_clock_dividers(adev,
2872 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
2873 table->SamuLevel[count].Frequency, false, ÷rs);
2877 table->SamuLevel[count].Divider = (u8)dividers.post_divider;
2879 table->SamuLevel[count].Frequency = cpu_to_be32(table->SamuLevel[count].Frequency);
2880 table->SamuLevel[count].MinVoltage = cpu_to_be16(table->SamuLevel[count].MinVoltage);
2886 static int ci_calculate_mclk_params(struct amdgpu_device *adev,
2888 SMU7_Discrete_MemoryLevel *mclk,
2892 struct ci_power_info *pi = ci_get_pi(adev);
2893 u32 dll_cntl = pi->clock_registers.dll_cntl;
2894 u32 mclk_pwrmgt_cntl = pi->clock_registers.mclk_pwrmgt_cntl;
2895 u32 mpll_ad_func_cntl = pi->clock_registers.mpll_ad_func_cntl;
2896 u32 mpll_dq_func_cntl = pi->clock_registers.mpll_dq_func_cntl;
2897 u32 mpll_func_cntl = pi->clock_registers.mpll_func_cntl;
2898 u32 mpll_func_cntl_1 = pi->clock_registers.mpll_func_cntl_1;
2899 u32 mpll_func_cntl_2 = pi->clock_registers.mpll_func_cntl_2;
2900 u32 mpll_ss1 = pi->clock_registers.mpll_ss1;
2901 u32 mpll_ss2 = pi->clock_registers.mpll_ss2;
2902 struct atom_mpll_param mpll_param;
2905 ret = amdgpu_atombios_get_memory_pll_dividers(adev, memory_clock, strobe_mode, &mpll_param);
2909 mpll_func_cntl &= ~MPLL_FUNC_CNTL__BWCTRL_MASK;
2910 mpll_func_cntl |= (mpll_param.bwcntl << MPLL_FUNC_CNTL__BWCTRL__SHIFT);
2912 mpll_func_cntl_1 &= ~(MPLL_FUNC_CNTL_1__CLKF_MASK | MPLL_FUNC_CNTL_1__CLKFRAC_MASK |
2913 MPLL_FUNC_CNTL_1__VCO_MODE_MASK);
2914 mpll_func_cntl_1 |= (mpll_param.clkf) << MPLL_FUNC_CNTL_1__CLKF__SHIFT |
2915 (mpll_param.clkfrac << MPLL_FUNC_CNTL_1__CLKFRAC__SHIFT) |
2916 (mpll_param.vco_mode << MPLL_FUNC_CNTL_1__VCO_MODE__SHIFT);
2918 mpll_ad_func_cntl &= ~MPLL_AD_FUNC_CNTL__YCLK_POST_DIV_MASK;
2919 mpll_ad_func_cntl |= (mpll_param.post_div << MPLL_AD_FUNC_CNTL__YCLK_POST_DIV__SHIFT);
2921 if (adev->mc.vram_type == AMDGPU_VRAM_TYPE_GDDR5) {
2922 mpll_dq_func_cntl &= ~(MPLL_DQ_FUNC_CNTL__YCLK_SEL_MASK |
2923 MPLL_AD_FUNC_CNTL__YCLK_POST_DIV_MASK);
2924 mpll_dq_func_cntl |= (mpll_param.yclk_sel << MPLL_DQ_FUNC_CNTL__YCLK_SEL__SHIFT) |
2925 (mpll_param.post_div << MPLL_AD_FUNC_CNTL__YCLK_POST_DIV__SHIFT);
2928 if (pi->caps_mclk_ss_support) {
2929 struct amdgpu_atom_ss ss;
2932 u32 reference_clock = adev->clock.mpll.reference_freq;
2934 if (mpll_param.qdr == 1)
2935 freq_nom = memory_clock * 4 * (1 << mpll_param.post_div);
2937 freq_nom = memory_clock * 2 * (1 << mpll_param.post_div);
2939 tmp = (freq_nom / reference_clock);
2941 if (amdgpu_atombios_get_asic_ss_info(adev, &ss,
2942 ASIC_INTERNAL_MEMORY_SS, freq_nom)) {
2943 u32 clks = reference_clock * 5 / ss.rate;
2944 u32 clkv = (u32)((((131 * ss.percentage * ss.rate) / 100) * tmp) / freq_nom);
2946 mpll_ss1 &= ~MPLL_SS1__CLKV_MASK;
2947 mpll_ss1 |= (clkv << MPLL_SS1__CLKV__SHIFT);
2949 mpll_ss2 &= ~MPLL_SS2__CLKS_MASK;
2950 mpll_ss2 |= (clks << MPLL_SS2__CLKS__SHIFT);
2954 mclk_pwrmgt_cntl &= ~MCLK_PWRMGT_CNTL__DLL_SPEED_MASK;
2955 mclk_pwrmgt_cntl |= (mpll_param.dll_speed << MCLK_PWRMGT_CNTL__DLL_SPEED__SHIFT);
2958 mclk_pwrmgt_cntl |= MCLK_PWRMGT_CNTL__MRDCK0_PDNB_MASK |
2959 MCLK_PWRMGT_CNTL__MRDCK1_PDNB_MASK;
2961 mclk_pwrmgt_cntl &= ~(MCLK_PWRMGT_CNTL__MRDCK0_PDNB_MASK |
2962 MCLK_PWRMGT_CNTL__MRDCK1_PDNB_MASK);
2964 mclk->MclkFrequency = memory_clock;
2965 mclk->MpllFuncCntl = mpll_func_cntl;
2966 mclk->MpllFuncCntl_1 = mpll_func_cntl_1;
2967 mclk->MpllFuncCntl_2 = mpll_func_cntl_2;
2968 mclk->MpllAdFuncCntl = mpll_ad_func_cntl;
2969 mclk->MpllDqFuncCntl = mpll_dq_func_cntl;
2970 mclk->MclkPwrmgtCntl = mclk_pwrmgt_cntl;
2971 mclk->DllCntl = dll_cntl;
2972 mclk->MpllSs1 = mpll_ss1;
2973 mclk->MpllSs2 = mpll_ss2;
2978 static int ci_populate_single_memory_level(struct amdgpu_device *adev,
2980 SMU7_Discrete_MemoryLevel *memory_level)
2982 struct ci_power_info *pi = ci_get_pi(adev);
2986 if (adev->pm.dpm.dyn_state.vddc_dependency_on_mclk.entries) {
2987 ret = ci_get_dependency_volt_by_clk(adev,
2988 &adev->pm.dpm.dyn_state.vddc_dependency_on_mclk,
2989 memory_clock, &memory_level->MinVddc);
2994 if (adev->pm.dpm.dyn_state.vddci_dependency_on_mclk.entries) {
2995 ret = ci_get_dependency_volt_by_clk(adev,
2996 &adev->pm.dpm.dyn_state.vddci_dependency_on_mclk,
2997 memory_clock, &memory_level->MinVddci);
3002 if (adev->pm.dpm.dyn_state.mvdd_dependency_on_mclk.entries) {
3003 ret = ci_get_dependency_volt_by_clk(adev,
3004 &adev->pm.dpm.dyn_state.mvdd_dependency_on_mclk,
3005 memory_clock, &memory_level->MinMvdd);
3010 memory_level->MinVddcPhases = 1;
3012 if (pi->vddc_phase_shed_control)
3013 ci_populate_phase_value_based_on_mclk(adev,
3014 &adev->pm.dpm.dyn_state.phase_shedding_limits_table,
3016 &memory_level->MinVddcPhases);
3018 memory_level->EnabledForThrottle = 1;
3019 memory_level->EnabledForActivity = 1;
3020 memory_level->UpH = 0;
3021 memory_level->DownH = 100;
3022 memory_level->VoltageDownH = 0;
3023 memory_level->ActivityLevel = (u16)pi->mclk_activity_target;
3025 memory_level->StutterEnable = false;
3026 memory_level->StrobeEnable = false;
3027 memory_level->EdcReadEnable = false;
3028 memory_level->EdcWriteEnable = false;
3029 memory_level->RttEnable = false;
3031 memory_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
3033 if (pi->mclk_stutter_mode_threshold &&
3034 (memory_clock <= pi->mclk_stutter_mode_threshold) &&
3035 (pi->uvd_enabled == false) &&
3036 (RREG32(mmDPG_PIPE_STUTTER_CONTROL) & DPG_PIPE_STUTTER_CONTROL__STUTTER_ENABLE_MASK) &&
3037 (adev->pm.dpm.new_active_crtc_count <= 2))
3038 memory_level->StutterEnable = true;
3040 if (pi->mclk_strobe_mode_threshold &&
3041 (memory_clock <= pi->mclk_strobe_mode_threshold))
3042 memory_level->StrobeEnable = 1;
3044 if (adev->mc.vram_type == AMDGPU_VRAM_TYPE_GDDR5) {
3045 memory_level->StrobeRatio =
3046 ci_get_mclk_frequency_ratio(memory_clock, memory_level->StrobeEnable);
3047 if (pi->mclk_edc_enable_threshold &&
3048 (memory_clock > pi->mclk_edc_enable_threshold))
3049 memory_level->EdcReadEnable = true;
3051 if (pi->mclk_edc_wr_enable_threshold &&
3052 (memory_clock > pi->mclk_edc_wr_enable_threshold))
3053 memory_level->EdcWriteEnable = true;
3055 if (memory_level->StrobeEnable) {
3056 if (ci_get_mclk_frequency_ratio(memory_clock, true) >=
3057 ((RREG32(mmMC_SEQ_MISC7) >> 16) & 0xf))
3058 dll_state_on = ((RREG32(mmMC_SEQ_MISC5) >> 1) & 0x1) ? true : false;
3060 dll_state_on = ((RREG32(mmMC_SEQ_MISC6) >> 1) & 0x1) ? true : false;
3062 dll_state_on = pi->dll_default_on;
3065 memory_level->StrobeRatio = ci_get_ddr3_mclk_frequency_ratio(memory_clock);
3066 dll_state_on = ((RREG32(mmMC_SEQ_MISC5) >> 1) & 0x1) ? true : false;
3069 ret = ci_calculate_mclk_params(adev, memory_clock, memory_level, memory_level->StrobeEnable, dll_state_on);
3073 memory_level->MinVddc = cpu_to_be32(memory_level->MinVddc * VOLTAGE_SCALE);
3074 memory_level->MinVddcPhases = cpu_to_be32(memory_level->MinVddcPhases);
3075 memory_level->MinVddci = cpu_to_be32(memory_level->MinVddci * VOLTAGE_SCALE);
3076 memory_level->MinMvdd = cpu_to_be32(memory_level->MinMvdd * VOLTAGE_SCALE);
3078 memory_level->MclkFrequency = cpu_to_be32(memory_level->MclkFrequency);
3079 memory_level->ActivityLevel = cpu_to_be16(memory_level->ActivityLevel);
3080 memory_level->MpllFuncCntl = cpu_to_be32(memory_level->MpllFuncCntl);
3081 memory_level->MpllFuncCntl_1 = cpu_to_be32(memory_level->MpllFuncCntl_1);
3082 memory_level->MpllFuncCntl_2 = cpu_to_be32(memory_level->MpllFuncCntl_2);
3083 memory_level->MpllAdFuncCntl = cpu_to_be32(memory_level->MpllAdFuncCntl);
3084 memory_level->MpllDqFuncCntl = cpu_to_be32(memory_level->MpllDqFuncCntl);
3085 memory_level->MclkPwrmgtCntl = cpu_to_be32(memory_level->MclkPwrmgtCntl);
3086 memory_level->DllCntl = cpu_to_be32(memory_level->DllCntl);
3087 memory_level->MpllSs1 = cpu_to_be32(memory_level->MpllSs1);
3088 memory_level->MpllSs2 = cpu_to_be32(memory_level->MpllSs2);
3093 static int ci_populate_smc_acpi_level(struct amdgpu_device *adev,
3094 SMU7_Discrete_DpmTable *table)
3096 struct ci_power_info *pi = ci_get_pi(adev);
3097 struct atom_clock_dividers dividers;
3098 SMU7_Discrete_VoltageLevel voltage_level;
3099 u32 spll_func_cntl = pi->clock_registers.cg_spll_func_cntl;
3100 u32 spll_func_cntl_2 = pi->clock_registers.cg_spll_func_cntl_2;
3101 u32 dll_cntl = pi->clock_registers.dll_cntl;
3102 u32 mclk_pwrmgt_cntl = pi->clock_registers.mclk_pwrmgt_cntl;
3105 table->ACPILevel.Flags &= ~PPSMC_SWSTATE_FLAG_DC;
3108 table->ACPILevel.MinVddc = cpu_to_be32(pi->acpi_vddc * VOLTAGE_SCALE);
3110 table->ACPILevel.MinVddc = cpu_to_be32(pi->min_vddc_in_pp_table * VOLTAGE_SCALE);
3112 table->ACPILevel.MinVddcPhases = pi->vddc_phase_shed_control ? 0 : 1;
3114 table->ACPILevel.SclkFrequency = adev->clock.spll.reference_freq;
3116 ret = amdgpu_atombios_get_clock_dividers(adev,
3117 COMPUTE_GPUCLK_INPUT_FLAG_SCLK,
3118 table->ACPILevel.SclkFrequency, false, ÷rs);
3122 table->ACPILevel.SclkDid = (u8)dividers.post_divider;
3123 table->ACPILevel.DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
3124 table->ACPILevel.DeepSleepDivId = 0;
3126 spll_func_cntl &= ~CG_SPLL_FUNC_CNTL__SPLL_PWRON_MASK;
3127 spll_func_cntl |= CG_SPLL_FUNC_CNTL__SPLL_RESET_MASK;
3129 spll_func_cntl_2 &= ~CG_SPLL_FUNC_CNTL_2__SCLK_MUX_SEL_MASK;
3130 spll_func_cntl_2 |= (4 << CG_SPLL_FUNC_CNTL_2__SCLK_MUX_SEL__SHIFT);
3132 table->ACPILevel.CgSpllFuncCntl = spll_func_cntl;
3133 table->ACPILevel.CgSpllFuncCntl2 = spll_func_cntl_2;
3134 table->ACPILevel.CgSpllFuncCntl3 = pi->clock_registers.cg_spll_func_cntl_3;
3135 table->ACPILevel.CgSpllFuncCntl4 = pi->clock_registers.cg_spll_func_cntl_4;
3136 table->ACPILevel.SpllSpreadSpectrum = pi->clock_registers.cg_spll_spread_spectrum;
3137 table->ACPILevel.SpllSpreadSpectrum2 = pi->clock_registers.cg_spll_spread_spectrum_2;
3138 table->ACPILevel.CcPwrDynRm = 0;
3139 table->ACPILevel.CcPwrDynRm1 = 0;
3141 table->ACPILevel.Flags = cpu_to_be32(table->ACPILevel.Flags);
3142 table->ACPILevel.MinVddcPhases = cpu_to_be32(table->ACPILevel.MinVddcPhases);
3143 table->ACPILevel.SclkFrequency = cpu_to_be32(table->ACPILevel.SclkFrequency);
3144 table->ACPILevel.CgSpllFuncCntl = cpu_to_be32(table->ACPILevel.CgSpllFuncCntl);
3145 table->ACPILevel.CgSpllFuncCntl2 = cpu_to_be32(table->ACPILevel.CgSpllFuncCntl2);
3146 table->ACPILevel.CgSpllFuncCntl3 = cpu_to_be32(table->ACPILevel.CgSpllFuncCntl3);
3147 table->ACPILevel.CgSpllFuncCntl4 = cpu_to_be32(table->ACPILevel.CgSpllFuncCntl4);
3148 table->ACPILevel.SpllSpreadSpectrum = cpu_to_be32(table->ACPILevel.SpllSpreadSpectrum);
3149 table->ACPILevel.SpllSpreadSpectrum2 = cpu_to_be32(table->ACPILevel.SpllSpreadSpectrum2);
3150 table->ACPILevel.CcPwrDynRm = cpu_to_be32(table->ACPILevel.CcPwrDynRm);
3151 table->ACPILevel.CcPwrDynRm1 = cpu_to_be32(table->ACPILevel.CcPwrDynRm1);
3153 table->MemoryACPILevel.MinVddc = table->ACPILevel.MinVddc;
3154 table->MemoryACPILevel.MinVddcPhases = table->ACPILevel.MinVddcPhases;
3156 if (pi->vddci_control != CISLANDS_VOLTAGE_CONTROL_NONE) {
3158 table->MemoryACPILevel.MinVddci =
3159 cpu_to_be32(pi->acpi_vddci * VOLTAGE_SCALE);
3161 table->MemoryACPILevel.MinVddci =
3162 cpu_to_be32(pi->min_vddci_in_pp_table * VOLTAGE_SCALE);
3165 if (ci_populate_mvdd_value(adev, 0, &voltage_level))
3166 table->MemoryACPILevel.MinMvdd = 0;
3168 table->MemoryACPILevel.MinMvdd =
3169 cpu_to_be32(voltage_level.Voltage * VOLTAGE_SCALE);
3171 mclk_pwrmgt_cntl |= MCLK_PWRMGT_CNTL__MRDCK0_RESET_MASK |
3172 MCLK_PWRMGT_CNTL__MRDCK1_RESET_MASK;
3173 mclk_pwrmgt_cntl &= ~(MCLK_PWRMGT_CNTL__MRDCK0_PDNB_MASK |
3174 MCLK_PWRMGT_CNTL__MRDCK1_PDNB_MASK);
3176 dll_cntl &= ~(DLL_CNTL__MRDCK0_BYPASS_MASK | DLL_CNTL__MRDCK1_BYPASS_MASK);
3178 table->MemoryACPILevel.DllCntl = cpu_to_be32(dll_cntl);
3179 table->MemoryACPILevel.MclkPwrmgtCntl = cpu_to_be32(mclk_pwrmgt_cntl);
3180 table->MemoryACPILevel.MpllAdFuncCntl =
3181 cpu_to_be32(pi->clock_registers.mpll_ad_func_cntl);
3182 table->MemoryACPILevel.MpllDqFuncCntl =
3183 cpu_to_be32(pi->clock_registers.mpll_dq_func_cntl);
3184 table->MemoryACPILevel.MpllFuncCntl =
3185 cpu_to_be32(pi->clock_registers.mpll_func_cntl);
3186 table->MemoryACPILevel.MpllFuncCntl_1 =
3187 cpu_to_be32(pi->clock_registers.mpll_func_cntl_1);
3188 table->MemoryACPILevel.MpllFuncCntl_2 =
3189 cpu_to_be32(pi->clock_registers.mpll_func_cntl_2);
3190 table->MemoryACPILevel.MpllSs1 = cpu_to_be32(pi->clock_registers.mpll_ss1);
3191 table->MemoryACPILevel.MpllSs2 = cpu_to_be32(pi->clock_registers.mpll_ss2);
3193 table->MemoryACPILevel.EnabledForThrottle = 0;
3194 table->MemoryACPILevel.EnabledForActivity = 0;
3195 table->MemoryACPILevel.UpH = 0;
3196 table->MemoryACPILevel.DownH = 100;
3197 table->MemoryACPILevel.VoltageDownH = 0;
3198 table->MemoryACPILevel.ActivityLevel =
3199 cpu_to_be16((u16)pi->mclk_activity_target);
3201 table->MemoryACPILevel.StutterEnable = false;
3202 table->MemoryACPILevel.StrobeEnable = false;
3203 table->MemoryACPILevel.EdcReadEnable = false;
3204 table->MemoryACPILevel.EdcWriteEnable = false;
3205 table->MemoryACPILevel.RttEnable = false;
3211 static int ci_enable_ulv(struct amdgpu_device *adev, bool enable)
3213 struct ci_power_info *pi = ci_get_pi(adev);
3214 struct ci_ulv_parm *ulv = &pi->ulv;
3216 if (ulv->supported) {
3218 return (amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_EnableULV) == PPSMC_Result_OK) ?
3221 return (amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_DisableULV) == PPSMC_Result_OK) ?
3228 static int ci_populate_ulv_level(struct amdgpu_device *adev,
3229 SMU7_Discrete_Ulv *state)
3231 struct ci_power_info *pi = ci_get_pi(adev);
3232 u16 ulv_voltage = adev->pm.dpm.backbias_response_time;
3234 state->CcPwrDynRm = 0;
3235 state->CcPwrDynRm1 = 0;
3237 if (ulv_voltage == 0) {
3238 pi->ulv.supported = false;
3242 if (pi->voltage_control != CISLANDS_VOLTAGE_CONTROL_BY_SVID2) {
3243 if (ulv_voltage > adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[0].v)
3244 state->VddcOffset = 0;
3247 adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[0].v - ulv_voltage;
3249 if (ulv_voltage > adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[0].v)
3250 state->VddcOffsetVid = 0;
3252 state->VddcOffsetVid = (u8)
3253 ((adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[0].v - ulv_voltage) *
3254 VOLTAGE_VID_OFFSET_SCALE2 / VOLTAGE_VID_OFFSET_SCALE1);
3256 state->VddcPhase = pi->vddc_phase_shed_control ? 0 : 1;
3258 state->CcPwrDynRm = cpu_to_be32(state->CcPwrDynRm);
3259 state->CcPwrDynRm1 = cpu_to_be32(state->CcPwrDynRm1);
3260 state->VddcOffset = cpu_to_be16(state->VddcOffset);
3265 static int ci_calculate_sclk_params(struct amdgpu_device *adev,
3267 SMU7_Discrete_GraphicsLevel *sclk)
3269 struct ci_power_info *pi = ci_get_pi(adev);
3270 struct atom_clock_dividers dividers;
3271 u32 spll_func_cntl_3 = pi->clock_registers.cg_spll_func_cntl_3;
3272 u32 spll_func_cntl_4 = pi->clock_registers.cg_spll_func_cntl_4;
3273 u32 cg_spll_spread_spectrum = pi->clock_registers.cg_spll_spread_spectrum;
3274 u32 cg_spll_spread_spectrum_2 = pi->clock_registers.cg_spll_spread_spectrum_2;
3275 u32 reference_clock = adev->clock.spll.reference_freq;
3276 u32 reference_divider;
3280 ret = amdgpu_atombios_get_clock_dividers(adev,
3281 COMPUTE_GPUCLK_INPUT_FLAG_SCLK,
3282 engine_clock, false, ÷rs);
3286 reference_divider = 1 + dividers.ref_div;
3287 fbdiv = dividers.fb_div & 0x3FFFFFF;
3289 spll_func_cntl_3 &= ~CG_SPLL_FUNC_CNTL_3__SPLL_FB_DIV_MASK;
3290 spll_func_cntl_3 |= (fbdiv << CG_SPLL_FUNC_CNTL_3__SPLL_FB_DIV__SHIFT);
3291 spll_func_cntl_3 |= CG_SPLL_FUNC_CNTL_3__SPLL_DITHEN_MASK;
3293 if (pi->caps_sclk_ss_support) {
3294 struct amdgpu_atom_ss ss;
3295 u32 vco_freq = engine_clock * dividers.post_div;
3297 if (amdgpu_atombios_get_asic_ss_info(adev, &ss,
3298 ASIC_INTERNAL_ENGINE_SS, vco_freq)) {
3299 u32 clk_s = reference_clock * 5 / (reference_divider * ss.rate);
3300 u32 clk_v = 4 * ss.percentage * fbdiv / (clk_s * 10000);
3302 cg_spll_spread_spectrum &= ~(CG_SPLL_SPREAD_SPECTRUM__CLKS_MASK | CG_SPLL_SPREAD_SPECTRUM__SSEN_MASK);
3303 cg_spll_spread_spectrum |= (clk_s << CG_SPLL_SPREAD_SPECTRUM__CLKS__SHIFT);
3304 cg_spll_spread_spectrum |= (1 << CG_SPLL_SPREAD_SPECTRUM__SSEN__SHIFT);
3306 cg_spll_spread_spectrum_2 &= ~CG_SPLL_SPREAD_SPECTRUM_2__CLKV_MASK;
3307 cg_spll_spread_spectrum_2 |= (clk_v << CG_SPLL_SPREAD_SPECTRUM_2__CLKV__SHIFT);
3311 sclk->SclkFrequency = engine_clock;
3312 sclk->CgSpllFuncCntl3 = spll_func_cntl_3;
3313 sclk->CgSpllFuncCntl4 = spll_func_cntl_4;
3314 sclk->SpllSpreadSpectrum = cg_spll_spread_spectrum;
3315 sclk->SpllSpreadSpectrum2 = cg_spll_spread_spectrum_2;
3316 sclk->SclkDid = (u8)dividers.post_divider;
3321 static int ci_populate_single_graphic_level(struct amdgpu_device *adev,
3323 u16 sclk_activity_level_t,
3324 SMU7_Discrete_GraphicsLevel *graphic_level)
3326 struct ci_power_info *pi = ci_get_pi(adev);
3329 ret = ci_calculate_sclk_params(adev, engine_clock, graphic_level);
3333 ret = ci_get_dependency_volt_by_clk(adev,
3334 &adev->pm.dpm.dyn_state.vddc_dependency_on_sclk,
3335 engine_clock, &graphic_level->MinVddc);
3339 graphic_level->SclkFrequency = engine_clock;
3341 graphic_level->Flags = 0;
3342 graphic_level->MinVddcPhases = 1;
3344 if (pi->vddc_phase_shed_control)
3345 ci_populate_phase_value_based_on_sclk(adev,
3346 &adev->pm.dpm.dyn_state.phase_shedding_limits_table,
3348 &graphic_level->MinVddcPhases);
3350 graphic_level->ActivityLevel = sclk_activity_level_t;
3352 graphic_level->CcPwrDynRm = 0;
3353 graphic_level->CcPwrDynRm1 = 0;
3354 graphic_level->EnabledForThrottle = 1;
3355 graphic_level->UpH = 0;
3356 graphic_level->DownH = 0;
3357 graphic_level->VoltageDownH = 0;
3358 graphic_level->PowerThrottle = 0;
3360 if (pi->caps_sclk_ds)
3361 graphic_level->DeepSleepDivId = ci_get_sleep_divider_id_from_clock(adev,
3363 CISLAND_MINIMUM_ENGINE_CLOCK);
3365 graphic_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
3367 graphic_level->Flags = cpu_to_be32(graphic_level->Flags);
3368 graphic_level->MinVddc = cpu_to_be32(graphic_level->MinVddc * VOLTAGE_SCALE);
3369 graphic_level->MinVddcPhases = cpu_to_be32(graphic_level->MinVddcPhases);
3370 graphic_level->SclkFrequency = cpu_to_be32(graphic_level->SclkFrequency);
3371 graphic_level->ActivityLevel = cpu_to_be16(graphic_level->ActivityLevel);
3372 graphic_level->CgSpllFuncCntl3 = cpu_to_be32(graphic_level->CgSpllFuncCntl3);
3373 graphic_level->CgSpllFuncCntl4 = cpu_to_be32(graphic_level->CgSpllFuncCntl4);
3374 graphic_level->SpllSpreadSpectrum = cpu_to_be32(graphic_level->SpllSpreadSpectrum);
3375 graphic_level->SpllSpreadSpectrum2 = cpu_to_be32(graphic_level->SpllSpreadSpectrum2);
3376 graphic_level->CcPwrDynRm = cpu_to_be32(graphic_level->CcPwrDynRm);
3377 graphic_level->CcPwrDynRm1 = cpu_to_be32(graphic_level->CcPwrDynRm1);
3378 graphic_level->EnabledForActivity = 1;
3383 static int ci_populate_all_graphic_levels(struct amdgpu_device *adev)
3385 struct ci_power_info *pi = ci_get_pi(adev);
3386 struct ci_dpm_table *dpm_table = &pi->dpm_table;
3387 u32 level_array_address = pi->dpm_table_start +
3388 offsetof(SMU7_Discrete_DpmTable, GraphicsLevel);
3389 u32 level_array_size = sizeof(SMU7_Discrete_GraphicsLevel) *
3390 SMU7_MAX_LEVELS_GRAPHICS;
3391 SMU7_Discrete_GraphicsLevel *levels = pi->smc_state_table.GraphicsLevel;
3394 memset(levels, 0, level_array_size);
3396 for (i = 0; i < dpm_table->sclk_table.count; i++) {
3397 ret = ci_populate_single_graphic_level(adev,
3398 dpm_table->sclk_table.dpm_levels[i].value,
3399 (u16)pi->activity_target[i],
3400 &pi->smc_state_table.GraphicsLevel[i]);
3404 pi->smc_state_table.GraphicsLevel[i].DeepSleepDivId = 0;
3405 if (i == (dpm_table->sclk_table.count - 1))
3406 pi->smc_state_table.GraphicsLevel[i].DisplayWatermark =
3407 PPSMC_DISPLAY_WATERMARK_HIGH;
3410 pi->smc_state_table.GraphicsDpmLevelCount = (u8)dpm_table->sclk_table.count;
3411 pi->dpm_level_enable_mask.sclk_dpm_enable_mask =
3412 ci_get_dpm_level_enable_mask_value(&dpm_table->sclk_table);
3414 ret = amdgpu_ci_copy_bytes_to_smc(adev, level_array_address,
3415 (u8 *)levels, level_array_size,
3423 static int ci_populate_ulv_state(struct amdgpu_device *adev,
3424 SMU7_Discrete_Ulv *ulv_level)
3426 return ci_populate_ulv_level(adev, ulv_level);
3429 static int ci_populate_all_memory_levels(struct amdgpu_device *adev)
3431 struct ci_power_info *pi = ci_get_pi(adev);
3432 struct ci_dpm_table *dpm_table = &pi->dpm_table;
3433 u32 level_array_address = pi->dpm_table_start +
3434 offsetof(SMU7_Discrete_DpmTable, MemoryLevel);
3435 u32 level_array_size = sizeof(SMU7_Discrete_MemoryLevel) *
3436 SMU7_MAX_LEVELS_MEMORY;
3437 SMU7_Discrete_MemoryLevel *levels = pi->smc_state_table.MemoryLevel;
3440 memset(levels, 0, level_array_size);
3442 for (i = 0; i < dpm_table->mclk_table.count; i++) {
3443 if (dpm_table->mclk_table.dpm_levels[i].value == 0)
3445 ret = ci_populate_single_memory_level(adev,
3446 dpm_table->mclk_table.dpm_levels[i].value,
3447 &pi->smc_state_table.MemoryLevel[i]);
3452 if ((dpm_table->mclk_table.count >= 2) &&
3453 ((adev->pdev->device == 0x67B0) || (adev->pdev->device == 0x67B1))) {
3454 pi->smc_state_table.MemoryLevel[1].MinVddc =
3455 pi->smc_state_table.MemoryLevel[0].MinVddc;
3456 pi->smc_state_table.MemoryLevel[1].MinVddcPhases =
3457 pi->smc_state_table.MemoryLevel[0].MinVddcPhases;
3460 pi->smc_state_table.MemoryLevel[0].ActivityLevel = cpu_to_be16(0x1F);
3462 pi->smc_state_table.MemoryDpmLevelCount = (u8)dpm_table->mclk_table.count;
3463 pi->dpm_level_enable_mask.mclk_dpm_enable_mask =
3464 ci_get_dpm_level_enable_mask_value(&dpm_table->mclk_table);
3466 pi->smc_state_table.MemoryLevel[dpm_table->mclk_table.count - 1].DisplayWatermark =
3467 PPSMC_DISPLAY_WATERMARK_HIGH;
3469 ret = amdgpu_ci_copy_bytes_to_smc(adev, level_array_address,
3470 (u8 *)levels, level_array_size,
3478 static void ci_reset_single_dpm_table(struct amdgpu_device *adev,
3479 struct ci_single_dpm_table* dpm_table,
3484 dpm_table->count = count;
3485 for (i = 0; i < MAX_REGULAR_DPM_NUMBER; i++)
3486 dpm_table->dpm_levels[i].enabled = false;
3489 static void ci_setup_pcie_table_entry(struct ci_single_dpm_table* dpm_table,
3490 u32 index, u32 pcie_gen, u32 pcie_lanes)
3492 dpm_table->dpm_levels[index].value = pcie_gen;
3493 dpm_table->dpm_levels[index].param1 = pcie_lanes;
3494 dpm_table->dpm_levels[index].enabled = true;
3497 static int ci_setup_default_pcie_tables(struct amdgpu_device *adev)
3499 struct ci_power_info *pi = ci_get_pi(adev);
3501 if (!pi->use_pcie_performance_levels && !pi->use_pcie_powersaving_levels)
3504 if (pi->use_pcie_performance_levels && !pi->use_pcie_powersaving_levels) {
3505 pi->pcie_gen_powersaving = pi->pcie_gen_performance;
3506 pi->pcie_lane_powersaving = pi->pcie_lane_performance;
3507 } else if (!pi->use_pcie_performance_levels && pi->use_pcie_powersaving_levels) {
3508 pi->pcie_gen_performance = pi->pcie_gen_powersaving;
3509 pi->pcie_lane_performance = pi->pcie_lane_powersaving;
3512 ci_reset_single_dpm_table(adev,
3513 &pi->dpm_table.pcie_speed_table,
3514 SMU7_MAX_LEVELS_LINK);
3516 if (adev->asic_type == CHIP_BONAIRE)
3517 ci_setup_pcie_table_entry(&pi->dpm_table.pcie_speed_table, 0,
3518 pi->pcie_gen_powersaving.min,
3519 pi->pcie_lane_powersaving.max);
3521 ci_setup_pcie_table_entry(&pi->dpm_table.pcie_speed_table, 0,
3522 pi->pcie_gen_powersaving.min,
3523 pi->pcie_lane_powersaving.min);
3524 ci_setup_pcie_table_entry(&pi->dpm_table.pcie_speed_table, 1,
3525 pi->pcie_gen_performance.min,
3526 pi->pcie_lane_performance.min);
3527 ci_setup_pcie_table_entry(&pi->dpm_table.pcie_speed_table, 2,
3528 pi->pcie_gen_powersaving.min,
3529 pi->pcie_lane_powersaving.max);
3530 ci_setup_pcie_table_entry(&pi->dpm_table.pcie_speed_table, 3,
3531 pi->pcie_gen_performance.min,
3532 pi->pcie_lane_performance.max);
3533 ci_setup_pcie_table_entry(&pi->dpm_table.pcie_speed_table, 4,
3534 pi->pcie_gen_powersaving.max,
3535 pi->pcie_lane_powersaving.max);
3536 ci_setup_pcie_table_entry(&pi->dpm_table.pcie_speed_table, 5,
3537 pi->pcie_gen_performance.max,
3538 pi->pcie_lane_performance.max);
3540 pi->dpm_table.pcie_speed_table.count = 6;
3545 static int ci_setup_default_dpm_tables(struct amdgpu_device *adev)
3547 struct ci_power_info *pi = ci_get_pi(adev);
3548 struct amdgpu_clock_voltage_dependency_table *allowed_sclk_vddc_table =
3549 &adev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
3550 struct amdgpu_clock_voltage_dependency_table *allowed_mclk_table =
3551 &adev->pm.dpm.dyn_state.vddc_dependency_on_mclk;
3552 struct amdgpu_cac_leakage_table *std_voltage_table =
3553 &adev->pm.dpm.dyn_state.cac_leakage_table;
3556 if (allowed_sclk_vddc_table == NULL)
3558 if (allowed_sclk_vddc_table->count < 1)
3560 if (allowed_mclk_table == NULL)
3562 if (allowed_mclk_table->count < 1)
3565 memset(&pi->dpm_table, 0, sizeof(struct ci_dpm_table));
3567 ci_reset_single_dpm_table(adev,
3568 &pi->dpm_table.sclk_table,
3569 SMU7_MAX_LEVELS_GRAPHICS);
3570 ci_reset_single_dpm_table(adev,
3571 &pi->dpm_table.mclk_table,
3572 SMU7_MAX_LEVELS_MEMORY);
3573 ci_reset_single_dpm_table(adev,
3574 &pi->dpm_table.vddc_table,
3575 SMU7_MAX_LEVELS_VDDC);
3576 ci_reset_single_dpm_table(adev,
3577 &pi->dpm_table.vddci_table,
3578 SMU7_MAX_LEVELS_VDDCI);
3579 ci_reset_single_dpm_table(adev,
3580 &pi->dpm_table.mvdd_table,
3581 SMU7_MAX_LEVELS_MVDD);
3583 pi->dpm_table.sclk_table.count = 0;
3584 for (i = 0; i < allowed_sclk_vddc_table->count; i++) {
3586 (pi->dpm_table.sclk_table.dpm_levels[pi->dpm_table.sclk_table.count-1].value !=
3587 allowed_sclk_vddc_table->entries[i].clk)) {
3588 pi->dpm_table.sclk_table.dpm_levels[pi->dpm_table.sclk_table.count].value =
3589 allowed_sclk_vddc_table->entries[i].clk;
3590 pi->dpm_table.sclk_table.dpm_levels[pi->dpm_table.sclk_table.count].enabled =
3591 (i == 0) ? true : false;
3592 pi->dpm_table.sclk_table.count++;
3596 pi->dpm_table.mclk_table.count = 0;
3597 for (i = 0; i < allowed_mclk_table->count; i++) {
3599 (pi->dpm_table.mclk_table.dpm_levels[pi->dpm_table.mclk_table.count-1].value !=
3600 allowed_mclk_table->entries[i].clk)) {
3601 pi->dpm_table.mclk_table.dpm_levels[pi->dpm_table.mclk_table.count].value =
3602 allowed_mclk_table->entries[i].clk;
3603 pi->dpm_table.mclk_table.dpm_levels[pi->dpm_table.mclk_table.count].enabled =
3604 (i == 0) ? true : false;
3605 pi->dpm_table.mclk_table.count++;
3609 for (i = 0; i < allowed_sclk_vddc_table->count; i++) {
3610 pi->dpm_table.vddc_table.dpm_levels[i].value =
3611 allowed_sclk_vddc_table->entries[i].v;
3612 pi->dpm_table.vddc_table.dpm_levels[i].param1 =
3613 std_voltage_table->entries[i].leakage;
3614 pi->dpm_table.vddc_table.dpm_levels[i].enabled = true;
3616 pi->dpm_table.vddc_table.count = allowed_sclk_vddc_table->count;
3618 allowed_mclk_table = &adev->pm.dpm.dyn_state.vddci_dependency_on_mclk;
3619 if (allowed_mclk_table) {
3620 for (i = 0; i < allowed_mclk_table->count; i++) {
3621 pi->dpm_table.vddci_table.dpm_levels[i].value =
3622 allowed_mclk_table->entries[i].v;
3623 pi->dpm_table.vddci_table.dpm_levels[i].enabled = true;
3625 pi->dpm_table.vddci_table.count = allowed_mclk_table->count;
3628 allowed_mclk_table = &adev->pm.dpm.dyn_state.mvdd_dependency_on_mclk;
3629 if (allowed_mclk_table) {
3630 for (i = 0; i < allowed_mclk_table->count; i++) {
3631 pi->dpm_table.mvdd_table.dpm_levels[i].value =
3632 allowed_mclk_table->entries[i].v;
3633 pi->dpm_table.mvdd_table.dpm_levels[i].enabled = true;
3635 pi->dpm_table.mvdd_table.count = allowed_mclk_table->count;
3638 ci_setup_default_pcie_tables(adev);
3643 static int ci_find_boot_level(struct ci_single_dpm_table *table,
3644 u32 value, u32 *boot_level)
3649 for(i = 0; i < table->count; i++) {
3650 if (value == table->dpm_levels[i].value) {
3659 static int ci_init_smc_table(struct amdgpu_device *adev)
3661 struct ci_power_info *pi = ci_get_pi(adev);
3662 struct ci_ulv_parm *ulv = &pi->ulv;
3663 struct amdgpu_ps *amdgpu_boot_state = adev->pm.dpm.boot_ps;
3664 SMU7_Discrete_DpmTable *table = &pi->smc_state_table;
3667 ret = ci_setup_default_dpm_tables(adev);
3671 if (pi->voltage_control != CISLANDS_VOLTAGE_CONTROL_NONE)
3672 ci_populate_smc_voltage_tables(adev, table);
3674 ci_init_fps_limits(adev);
3676 if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_HARDWAREDC)
3677 table->SystemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC;
3679 if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_STEPVDDC)
3680 table->SystemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC;
3682 if (adev->mc.vram_type == AMDGPU_VRAM_TYPE_GDDR5)
3683 table->SystemFlags |= PPSMC_SYSTEMFLAG_GDDR5;
3685 if (ulv->supported) {
3686 ret = ci_populate_ulv_state(adev, &pi->smc_state_table.Ulv);
3689 WREG32_SMC(ixCG_ULV_PARAMETER, ulv->cg_ulv_parameter);
3692 ret = ci_populate_all_graphic_levels(adev);
3696 ret = ci_populate_all_memory_levels(adev);
3700 ci_populate_smc_link_level(adev, table);
3702 ret = ci_populate_smc_acpi_level(adev, table);
3706 ret = ci_populate_smc_vce_level(adev, table);
3710 ret = ci_populate_smc_acp_level(adev, table);
3714 ret = ci_populate_smc_samu_level(adev, table);
3718 ret = ci_do_program_memory_timing_parameters(adev);
3722 ret = ci_populate_smc_uvd_level(adev, table);
3726 table->UvdBootLevel = 0;
3727 table->VceBootLevel = 0;
3728 table->AcpBootLevel = 0;
3729 table->SamuBootLevel = 0;
3730 table->GraphicsBootLevel = 0;
3731 table->MemoryBootLevel = 0;
3733 ret = ci_find_boot_level(&pi->dpm_table.sclk_table,
3734 pi->vbios_boot_state.sclk_bootup_value,
3735 (u32 *)&pi->smc_state_table.GraphicsBootLevel);
3737 ret = ci_find_boot_level(&pi->dpm_table.mclk_table,
3738 pi->vbios_boot_state.mclk_bootup_value,
3739 (u32 *)&pi->smc_state_table.MemoryBootLevel);
3741 table->BootVddc = pi->vbios_boot_state.vddc_bootup_value;
3742 table->BootVddci = pi->vbios_boot_state.vddci_bootup_value;
3743 table->BootMVdd = pi->vbios_boot_state.mvdd_bootup_value;
3745 ci_populate_smc_initial_state(adev, amdgpu_boot_state);
3747 ret = ci_populate_bapm_parameters_in_dpm_table(adev);
3751 table->UVDInterval = 1;
3752 table->VCEInterval = 1;
3753 table->ACPInterval = 1;
3754 table->SAMUInterval = 1;
3755 table->GraphicsVoltageChangeEnable = 1;
3756 table->GraphicsThermThrottleEnable = 1;
3757 table->GraphicsInterval = 1;
3758 table->VoltageInterval = 1;
3759 table->ThermalInterval = 1;
3760 table->TemperatureLimitHigh = (u16)((pi->thermal_temp_setting.temperature_high *
3761 CISLANDS_Q88_FORMAT_CONVERSION_UNIT) / 1000);
3762 table->TemperatureLimitLow = (u16)((pi->thermal_temp_setting.temperature_low *
3763 CISLANDS_Q88_FORMAT_CONVERSION_UNIT) / 1000);
3764 table->MemoryVoltageChangeEnable = 1;
3765 table->MemoryInterval = 1;
3766 table->VoltageResponseTime = 0;
3767 table->VddcVddciDelta = 4000;
3768 table->PhaseResponseTime = 0;
3769 table->MemoryThermThrottleEnable = 1;
3770 table->PCIeBootLinkLevel = pi->dpm_table.pcie_speed_table.count - 1;
3771 table->PCIeGenInterval = 1;
3772 if (pi->voltage_control == CISLANDS_VOLTAGE_CONTROL_BY_SVID2)
3773 table->SVI2Enable = 1;
3775 table->SVI2Enable = 0;
3777 table->ThermGpio = 17;
3778 table->SclkStepSize = 0x4000;
3780 table->SystemFlags = cpu_to_be32(table->SystemFlags);
3781 table->SmioMaskVddcVid = cpu_to_be32(table->SmioMaskVddcVid);
3782 table->SmioMaskVddcPhase = cpu_to_be32(table->SmioMaskVddcPhase);
3783 table->SmioMaskVddciVid = cpu_to_be32(table->SmioMaskVddciVid);
3784 table->SmioMaskMvddVid = cpu_to_be32(table->SmioMaskMvddVid);
3785 table->SclkStepSize = cpu_to_be32(table->SclkStepSize);
3786 table->TemperatureLimitHigh = cpu_to_be16(table->TemperatureLimitHigh);
3787 table->TemperatureLimitLow = cpu_to_be16(table->TemperatureLimitLow);
3788 table->VddcVddciDelta = cpu_to_be16(table->VddcVddciDelta);
3789 table->VoltageResponseTime = cpu_to_be16(table->VoltageResponseTime);
3790 table->PhaseResponseTime = cpu_to_be16(table->PhaseResponseTime);
3791 table->BootVddc = cpu_to_be16(table->BootVddc * VOLTAGE_SCALE);
3792 table->BootVddci = cpu_to_be16(table->BootVddci * VOLTAGE_SCALE);
3793 table->BootMVdd = cpu_to_be16(table->BootMVdd * VOLTAGE_SCALE);
3795 ret = amdgpu_ci_copy_bytes_to_smc(adev,
3796 pi->dpm_table_start +
3797 offsetof(SMU7_Discrete_DpmTable, SystemFlags),
3798 (u8 *)&table->SystemFlags,
3799 sizeof(SMU7_Discrete_DpmTable) - 3 * sizeof(SMU7_PIDController),
3807 static void ci_trim_single_dpm_states(struct amdgpu_device *adev,
3808 struct ci_single_dpm_table *dpm_table,
3809 u32 low_limit, u32 high_limit)
3813 for (i = 0; i < dpm_table->count; i++) {
3814 if ((dpm_table->dpm_levels[i].value < low_limit) ||
3815 (dpm_table->dpm_levels[i].value > high_limit))
3816 dpm_table->dpm_levels[i].enabled = false;
3818 dpm_table->dpm_levels[i].enabled = true;
3822 static void ci_trim_pcie_dpm_states(struct amdgpu_device *adev,
3823 u32 speed_low, u32 lanes_low,
3824 u32 speed_high, u32 lanes_high)
3826 struct ci_power_info *pi = ci_get_pi(adev);
3827 struct ci_single_dpm_table *pcie_table = &pi->dpm_table.pcie_speed_table;
3830 for (i = 0; i < pcie_table->count; i++) {
3831 if ((pcie_table->dpm_levels[i].value < speed_low) ||
3832 (pcie_table->dpm_levels[i].param1 < lanes_low) ||
3833 (pcie_table->dpm_levels[i].value > speed_high) ||
3834 (pcie_table->dpm_levels[i].param1 > lanes_high))
3835 pcie_table->dpm_levels[i].enabled = false;
3837 pcie_table->dpm_levels[i].enabled = true;
3840 for (i = 0; i < pcie_table->count; i++) {
3841 if (pcie_table->dpm_levels[i].enabled) {
3842 for (j = i + 1; j < pcie_table->count; j++) {
3843 if (pcie_table->dpm_levels[j].enabled) {
3844 if ((pcie_table->dpm_levels[i].value == pcie_table->dpm_levels[j].value) &&
3845 (pcie_table->dpm_levels[i].param1 == pcie_table->dpm_levels[j].param1))
3846 pcie_table->dpm_levels[j].enabled = false;
3853 static int ci_trim_dpm_states(struct amdgpu_device *adev,
3854 struct amdgpu_ps *amdgpu_state)
3856 struct ci_ps *state = ci_get_ps(amdgpu_state);
3857 struct ci_power_info *pi = ci_get_pi(adev);
3858 u32 high_limit_count;
3860 if (state->performance_level_count < 1)
3863 if (state->performance_level_count == 1)
3864 high_limit_count = 0;
3866 high_limit_count = 1;
3868 ci_trim_single_dpm_states(adev,
3869 &pi->dpm_table.sclk_table,
3870 state->performance_levels[0].sclk,
3871 state->performance_levels[high_limit_count].sclk);
3873 ci_trim_single_dpm_states(adev,
3874 &pi->dpm_table.mclk_table,
3875 state->performance_levels[0].mclk,
3876 state->performance_levels[high_limit_count].mclk);
3878 ci_trim_pcie_dpm_states(adev,
3879 state->performance_levels[0].pcie_gen,
3880 state->performance_levels[0].pcie_lane,
3881 state->performance_levels[high_limit_count].pcie_gen,
3882 state->performance_levels[high_limit_count].pcie_lane);
3887 static int ci_apply_disp_minimum_voltage_request(struct amdgpu_device *adev)
3889 struct amdgpu_clock_voltage_dependency_table *disp_voltage_table =
3890 &adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk;
3891 struct amdgpu_clock_voltage_dependency_table *vddc_table =
3892 &adev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
3893 u32 requested_voltage = 0;
3896 if (disp_voltage_table == NULL)
3898 if (!disp_voltage_table->count)
3901 for (i = 0; i < disp_voltage_table->count; i++) {
3902 if (adev->clock.current_dispclk == disp_voltage_table->entries[i].clk)
3903 requested_voltage = disp_voltage_table->entries[i].v;
3906 for (i = 0; i < vddc_table->count; i++) {
3907 if (requested_voltage <= vddc_table->entries[i].v) {
3908 requested_voltage = vddc_table->entries[i].v;
3909 return (amdgpu_ci_send_msg_to_smc_with_parameter(adev,
3910 PPSMC_MSG_VddC_Request,
3911 requested_voltage * VOLTAGE_SCALE) == PPSMC_Result_OK) ?
3919 static int ci_upload_dpm_level_enable_mask(struct amdgpu_device *adev)
3921 struct ci_power_info *pi = ci_get_pi(adev);
3922 PPSMC_Result result;
3924 ci_apply_disp_minimum_voltage_request(adev);
3926 if (!pi->sclk_dpm_key_disabled) {
3927 if (pi->dpm_level_enable_mask.sclk_dpm_enable_mask) {
3928 result = amdgpu_ci_send_msg_to_smc_with_parameter(adev,
3929 PPSMC_MSG_SCLKDPM_SetEnabledMask,
3930 pi->dpm_level_enable_mask.sclk_dpm_enable_mask);
3931 if (result != PPSMC_Result_OK)
3936 if (!pi->mclk_dpm_key_disabled) {
3937 if (pi->dpm_level_enable_mask.mclk_dpm_enable_mask) {
3938 result = amdgpu_ci_send_msg_to_smc_with_parameter(adev,
3939 PPSMC_MSG_MCLKDPM_SetEnabledMask,
3940 pi->dpm_level_enable_mask.mclk_dpm_enable_mask);
3941 if (result != PPSMC_Result_OK)
3947 if (!pi->pcie_dpm_key_disabled) {
3948 if (pi->dpm_level_enable_mask.pcie_dpm_enable_mask) {
3949 result = amdgpu_ci_send_msg_to_smc_with_parameter(adev,
3950 PPSMC_MSG_PCIeDPM_SetEnabledMask,
3951 pi->dpm_level_enable_mask.pcie_dpm_enable_mask);
3952 if (result != PPSMC_Result_OK)
3961 static void ci_find_dpm_states_clocks_in_dpm_table(struct amdgpu_device *adev,
3962 struct amdgpu_ps *amdgpu_state)
3964 struct ci_power_info *pi = ci_get_pi(adev);
3965 struct ci_ps *state = ci_get_ps(amdgpu_state);
3966 struct ci_single_dpm_table *sclk_table = &pi->dpm_table.sclk_table;
3967 u32 sclk = state->performance_levels[state->performance_level_count-1].sclk;
3968 struct ci_single_dpm_table *mclk_table = &pi->dpm_table.mclk_table;
3969 u32 mclk = state->performance_levels[state->performance_level_count-1].mclk;
3972 pi->need_update_smu7_dpm_table = 0;
3974 for (i = 0; i < sclk_table->count; i++) {
3975 if (sclk == sclk_table->dpm_levels[i].value)
3979 if (i >= sclk_table->count) {
3980 pi->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK;
3982 /* XXX check display min clock requirements */
3983 if (CISLAND_MINIMUM_ENGINE_CLOCK != CISLAND_MINIMUM_ENGINE_CLOCK)
3984 pi->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_SCLK;
3987 for (i = 0; i < mclk_table->count; i++) {
3988 if (mclk == mclk_table->dpm_levels[i].value)
3992 if (i >= mclk_table->count)
3993 pi->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_MCLK;
3995 if (adev->pm.dpm.current_active_crtc_count !=
3996 adev->pm.dpm.new_active_crtc_count)
3997 pi->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_MCLK;
4000 static int ci_populate_and_upload_sclk_mclk_dpm_levels(struct amdgpu_device *adev,
4001 struct amdgpu_ps *amdgpu_state)
4003 struct ci_power_info *pi = ci_get_pi(adev);
4004 struct ci_ps *state = ci_get_ps(amdgpu_state);
4005 u32 sclk = state->performance_levels[state->performance_level_count-1].sclk;
4006 u32 mclk = state->performance_levels[state->performance_level_count-1].mclk;
4007 struct ci_dpm_table *dpm_table = &pi->dpm_table;
4010 if (!pi->need_update_smu7_dpm_table)
4013 if (pi->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_SCLK)
4014 dpm_table->sclk_table.dpm_levels[dpm_table->sclk_table.count-1].value = sclk;
4016 if (pi->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)
4017 dpm_table->mclk_table.dpm_levels[dpm_table->mclk_table.count-1].value = mclk;
4019 if (pi->need_update_smu7_dpm_table & (DPMTABLE_OD_UPDATE_SCLK | DPMTABLE_UPDATE_SCLK)) {
4020 ret = ci_populate_all_graphic_levels(adev);
4025 if (pi->need_update_smu7_dpm_table & (DPMTABLE_OD_UPDATE_MCLK | DPMTABLE_UPDATE_MCLK)) {
4026 ret = ci_populate_all_memory_levels(adev);
4034 static int ci_enable_uvd_dpm(struct amdgpu_device *adev, bool enable)
4036 struct ci_power_info *pi = ci_get_pi(adev);
4037 const struct amdgpu_clock_and_voltage_limits *max_limits;
4040 if (adev->pm.dpm.ac_power)
4041 max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_ac;
4043 max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_dc;
4046 pi->dpm_level_enable_mask.uvd_dpm_enable_mask = 0;
4048 for (i = adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.count - 1; i >= 0; i--) {
4049 if (adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[i].v <= max_limits->vddc) {
4050 pi->dpm_level_enable_mask.uvd_dpm_enable_mask |= 1 << i;
4052 if (!pi->caps_uvd_dpm)
4057 amdgpu_ci_send_msg_to_smc_with_parameter(adev,
4058 PPSMC_MSG_UVDDPM_SetEnabledMask,
4059 pi->dpm_level_enable_mask.uvd_dpm_enable_mask);
4061 if (pi->last_mclk_dpm_enable_mask & 0x1) {
4062 pi->uvd_enabled = true;
4063 pi->dpm_level_enable_mask.mclk_dpm_enable_mask &= 0xFFFFFFFE;
4064 amdgpu_ci_send_msg_to_smc_with_parameter(adev,
4065 PPSMC_MSG_MCLKDPM_SetEnabledMask,
4066 pi->dpm_level_enable_mask.mclk_dpm_enable_mask);
4069 if (pi->last_mclk_dpm_enable_mask & 0x1) {
4070 pi->uvd_enabled = false;
4071 pi->dpm_level_enable_mask.mclk_dpm_enable_mask |= 1;
4072 amdgpu_ci_send_msg_to_smc_with_parameter(adev,
4073 PPSMC_MSG_MCLKDPM_SetEnabledMask,
4074 pi->dpm_level_enable_mask.mclk_dpm_enable_mask);
4078 return (amdgpu_ci_send_msg_to_smc(adev, enable ?
4079 PPSMC_MSG_UVDDPM_Enable : PPSMC_MSG_UVDDPM_Disable) == PPSMC_Result_OK) ?
4083 static int ci_enable_vce_dpm(struct amdgpu_device *adev, bool enable)
4085 struct ci_power_info *pi = ci_get_pi(adev);
4086 const struct amdgpu_clock_and_voltage_limits *max_limits;
4089 if (adev->pm.dpm.ac_power)
4090 max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_ac;
4092 max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_dc;
4095 pi->dpm_level_enable_mask.vce_dpm_enable_mask = 0;
4096 for (i = adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.count - 1; i >= 0; i--) {
4097 if (adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries[i].v <= max_limits->vddc) {
4098 pi->dpm_level_enable_mask.vce_dpm_enable_mask |= 1 << i;
4100 if (!pi->caps_vce_dpm)
4105 amdgpu_ci_send_msg_to_smc_with_parameter(adev,
4106 PPSMC_MSG_VCEDPM_SetEnabledMask,
4107 pi->dpm_level_enable_mask.vce_dpm_enable_mask);
4110 return (amdgpu_ci_send_msg_to_smc(adev, enable ?
4111 PPSMC_MSG_VCEDPM_Enable : PPSMC_MSG_VCEDPM_Disable) == PPSMC_Result_OK) ?
4116 static int ci_enable_samu_dpm(struct amdgpu_device *adev, bool enable)
4118 struct ci_power_info *pi = ci_get_pi(adev);
4119 const struct amdgpu_clock_and_voltage_limits *max_limits;
4122 if (adev->pm.dpm.ac_power)
4123 max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_ac;
4125 max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_dc;
4128 pi->dpm_level_enable_mask.samu_dpm_enable_mask = 0;
4129 for (i = adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.count - 1; i >= 0; i--) {
4130 if (adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries[i].v <= max_limits->vddc) {
4131 pi->dpm_level_enable_mask.samu_dpm_enable_mask |= 1 << i;
4133 if (!pi->caps_samu_dpm)
4138 amdgpu_ci_send_msg_to_smc_with_parameter(adev,
4139 PPSMC_MSG_SAMUDPM_SetEnabledMask,
4140 pi->dpm_level_enable_mask.samu_dpm_enable_mask);
4142 return (amdgpu_ci_send_msg_to_smc(adev, enable ?
4143 PPSMC_MSG_SAMUDPM_Enable : PPSMC_MSG_SAMUDPM_Disable) == PPSMC_Result_OK) ?
4147 static int ci_enable_acp_dpm(struct amdgpu_device *adev, bool enable)
4149 struct ci_power_info *pi = ci_get_pi(adev);
4150 const struct amdgpu_clock_and_voltage_limits *max_limits;
4153 if (adev->pm.dpm.ac_power)
4154 max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_ac;
4156 max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_dc;
4159 pi->dpm_level_enable_mask.acp_dpm_enable_mask = 0;
4160 for (i = adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.count - 1; i >= 0; i--) {
4161 if (adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries[i].v <= max_limits->vddc) {
4162 pi->dpm_level_enable_mask.acp_dpm_enable_mask |= 1 << i;
4164 if (!pi->caps_acp_dpm)
4169 amdgpu_ci_send_msg_to_smc_with_parameter(adev,
4170 PPSMC_MSG_ACPDPM_SetEnabledMask,
4171 pi->dpm_level_enable_mask.acp_dpm_enable_mask);
4174 return (amdgpu_ci_send_msg_to_smc(adev, enable ?
4175 PPSMC_MSG_ACPDPM_Enable : PPSMC_MSG_ACPDPM_Disable) == PPSMC_Result_OK) ?
4180 static int ci_update_uvd_dpm(struct amdgpu_device *adev, bool gate)
4182 struct ci_power_info *pi = ci_get_pi(adev);
4186 if (pi->caps_uvd_dpm ||
4187 (adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.count <= 0))
4188 pi->smc_state_table.UvdBootLevel = 0;
4190 pi->smc_state_table.UvdBootLevel =
4191 adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.count - 1;
4193 tmp = RREG32_SMC(ixDPM_TABLE_475);
4194 tmp &= ~DPM_TABLE_475__UvdBootLevel_MASK;
4195 tmp |= (pi->smc_state_table.UvdBootLevel << DPM_TABLE_475__UvdBootLevel__SHIFT);
4196 WREG32_SMC(ixDPM_TABLE_475, tmp);
4199 return ci_enable_uvd_dpm(adev, !gate);
4202 static u8 ci_get_vce_boot_level(struct amdgpu_device *adev)
4205 u32 min_evclk = 30000; /* ??? */
4206 struct amdgpu_vce_clock_voltage_dependency_table *table =
4207 &adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table;
4209 for (i = 0; i < table->count; i++) {
4210 if (table->entries[i].evclk >= min_evclk)
4214 return table->count - 1;
4217 static int ci_update_vce_dpm(struct amdgpu_device *adev,
4218 struct amdgpu_ps *amdgpu_new_state,
4219 struct amdgpu_ps *amdgpu_current_state)
4221 struct ci_power_info *pi = ci_get_pi(adev);
4225 if (amdgpu_current_state->evclk != amdgpu_new_state->evclk) {
4226 if (amdgpu_new_state->evclk) {
4227 /* turn the clocks on when encoding */
4228 ret = amdgpu_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_VCE,
4229 AMD_CG_STATE_UNGATE);
4233 pi->smc_state_table.VceBootLevel = ci_get_vce_boot_level(adev);
4234 tmp = RREG32_SMC(ixDPM_TABLE_475);
4235 tmp &= ~DPM_TABLE_475__VceBootLevel_MASK;
4236 tmp |= (pi->smc_state_table.VceBootLevel << DPM_TABLE_475__VceBootLevel__SHIFT);
4237 WREG32_SMC(ixDPM_TABLE_475, tmp);
4239 ret = ci_enable_vce_dpm(adev, true);
4241 /* turn the clocks off when not encoding */
4242 ret = amdgpu_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_VCE,
4247 ret = ci_enable_vce_dpm(adev, false);
4254 static int ci_update_samu_dpm(struct amdgpu_device *adev, bool gate)
4256 return ci_enable_samu_dpm(adev, gate);
4259 static int ci_update_acp_dpm(struct amdgpu_device *adev, bool gate)
4261 struct ci_power_info *pi = ci_get_pi(adev);
4265 pi->smc_state_table.AcpBootLevel = 0;
4267 tmp = RREG32_SMC(ixDPM_TABLE_475);
4268 tmp &= ~AcpBootLevel_MASK;
4269 tmp |= AcpBootLevel(pi->smc_state_table.AcpBootLevel);
4270 WREG32_SMC(ixDPM_TABLE_475, tmp);
4273 return ci_enable_acp_dpm(adev, !gate);
4277 static int ci_generate_dpm_level_enable_mask(struct amdgpu_device *adev,
4278 struct amdgpu_ps *amdgpu_state)
4280 struct ci_power_info *pi = ci_get_pi(adev);
4283 ret = ci_trim_dpm_states(adev, amdgpu_state);
4287 pi->dpm_level_enable_mask.sclk_dpm_enable_mask =
4288 ci_get_dpm_level_enable_mask_value(&pi->dpm_table.sclk_table);
4289 pi->dpm_level_enable_mask.mclk_dpm_enable_mask =
4290 ci_get_dpm_level_enable_mask_value(&pi->dpm_table.mclk_table);
4291 pi->last_mclk_dpm_enable_mask =
4292 pi->dpm_level_enable_mask.mclk_dpm_enable_mask;
4293 if (pi->uvd_enabled) {
4294 if (pi->dpm_level_enable_mask.mclk_dpm_enable_mask & 1)
4295 pi->dpm_level_enable_mask.mclk_dpm_enable_mask &= 0xFFFFFFFE;
4297 pi->dpm_level_enable_mask.pcie_dpm_enable_mask =
4298 ci_get_dpm_level_enable_mask_value(&pi->dpm_table.pcie_speed_table);
4303 static u32 ci_get_lowest_enabled_level(struct amdgpu_device *adev,
4308 while ((level_mask & (1 << level)) == 0)
4315 static int ci_dpm_force_performance_level(struct amdgpu_device *adev,
4316 enum amdgpu_dpm_forced_level level)
4318 struct ci_power_info *pi = ci_get_pi(adev);
4322 if (level == AMDGPU_DPM_FORCED_LEVEL_HIGH) {
4323 if ((!pi->pcie_dpm_key_disabled) &&
4324 pi->dpm_level_enable_mask.pcie_dpm_enable_mask) {
4326 tmp = pi->dpm_level_enable_mask.pcie_dpm_enable_mask;
4330 ret = ci_dpm_force_state_pcie(adev, level);
4333 for (i = 0; i < adev->usec_timeout; i++) {
4334 tmp = (RREG32_SMC(ixTARGET_AND_CURRENT_PROFILE_INDEX_1) &
4335 TARGET_AND_CURRENT_PROFILE_INDEX_1__CURR_PCIE_INDEX_MASK) >>
4336 TARGET_AND_CURRENT_PROFILE_INDEX_1__CURR_PCIE_INDEX__SHIFT;
4343 if ((!pi->sclk_dpm_key_disabled) &&
4344 pi->dpm_level_enable_mask.sclk_dpm_enable_mask) {
4346 tmp = pi->dpm_level_enable_mask.sclk_dpm_enable_mask;
4350 ret = ci_dpm_force_state_sclk(adev, levels);
4353 for (i = 0; i < adev->usec_timeout; i++) {
4354 tmp = (RREG32_SMC(ixTARGET_AND_CURRENT_PROFILE_INDEX) &
4355 TARGET_AND_CURRENT_PROFILE_INDEX__CURR_SCLK_INDEX_MASK) >>
4356 TARGET_AND_CURRENT_PROFILE_INDEX__CURR_SCLK_INDEX__SHIFT;
4363 if ((!pi->mclk_dpm_key_disabled) &&
4364 pi->dpm_level_enable_mask.mclk_dpm_enable_mask) {
4366 tmp = pi->dpm_level_enable_mask.mclk_dpm_enable_mask;
4370 ret = ci_dpm_force_state_mclk(adev, levels);
4373 for (i = 0; i < adev->usec_timeout; i++) {
4374 tmp = (RREG32_SMC(ixTARGET_AND_CURRENT_PROFILE_INDEX) &
4375 TARGET_AND_CURRENT_PROFILE_INDEX__CURR_MCLK_INDEX_MASK) >>
4376 TARGET_AND_CURRENT_PROFILE_INDEX__CURR_MCLK_INDEX__SHIFT;
4383 if ((!pi->pcie_dpm_key_disabled) &&
4384 pi->dpm_level_enable_mask.pcie_dpm_enable_mask) {
4386 tmp = pi->dpm_level_enable_mask.pcie_dpm_enable_mask;
4390 ret = ci_dpm_force_state_pcie(adev, level);
4393 for (i = 0; i < adev->usec_timeout; i++) {
4394 tmp = (RREG32_SMC(ixTARGET_AND_CURRENT_PROFILE_INDEX_1) &
4395 TARGET_AND_CURRENT_PROFILE_INDEX_1__CURR_PCIE_INDEX_MASK) >>
4396 TARGET_AND_CURRENT_PROFILE_INDEX_1__CURR_PCIE_INDEX__SHIFT;
4403 } else if (level == AMDGPU_DPM_FORCED_LEVEL_LOW) {
4404 if ((!pi->sclk_dpm_key_disabled) &&
4405 pi->dpm_level_enable_mask.sclk_dpm_enable_mask) {
4406 levels = ci_get_lowest_enabled_level(adev,
4407 pi->dpm_level_enable_mask.sclk_dpm_enable_mask);
4408 ret = ci_dpm_force_state_sclk(adev, levels);
4411 for (i = 0; i < adev->usec_timeout; i++) {
4412 tmp = (RREG32_SMC(ixTARGET_AND_CURRENT_PROFILE_INDEX) &
4413 TARGET_AND_CURRENT_PROFILE_INDEX__CURR_SCLK_INDEX_MASK) >>
4414 TARGET_AND_CURRENT_PROFILE_INDEX__CURR_SCLK_INDEX__SHIFT;
4420 if ((!pi->mclk_dpm_key_disabled) &&
4421 pi->dpm_level_enable_mask.mclk_dpm_enable_mask) {
4422 levels = ci_get_lowest_enabled_level(adev,
4423 pi->dpm_level_enable_mask.mclk_dpm_enable_mask);
4424 ret = ci_dpm_force_state_mclk(adev, levels);
4427 for (i = 0; i < adev->usec_timeout; i++) {
4428 tmp = (RREG32_SMC(ixTARGET_AND_CURRENT_PROFILE_INDEX) &
4429 TARGET_AND_CURRENT_PROFILE_INDEX__CURR_MCLK_INDEX_MASK) >>
4430 TARGET_AND_CURRENT_PROFILE_INDEX__CURR_MCLK_INDEX__SHIFT;
4436 if ((!pi->pcie_dpm_key_disabled) &&
4437 pi->dpm_level_enable_mask.pcie_dpm_enable_mask) {
4438 levels = ci_get_lowest_enabled_level(adev,
4439 pi->dpm_level_enable_mask.pcie_dpm_enable_mask);
4440 ret = ci_dpm_force_state_pcie(adev, levels);
4443 for (i = 0; i < adev->usec_timeout; i++) {
4444 tmp = (RREG32_SMC(ixTARGET_AND_CURRENT_PROFILE_INDEX_1) &
4445 TARGET_AND_CURRENT_PROFILE_INDEX_1__CURR_PCIE_INDEX_MASK) >>
4446 TARGET_AND_CURRENT_PROFILE_INDEX_1__CURR_PCIE_INDEX__SHIFT;
4452 } else if (level == AMDGPU_DPM_FORCED_LEVEL_AUTO) {
4453 if (!pi->pcie_dpm_key_disabled) {
4454 PPSMC_Result smc_result;
4456 smc_result = amdgpu_ci_send_msg_to_smc(adev,
4457 PPSMC_MSG_PCIeDPM_UnForceLevel);
4458 if (smc_result != PPSMC_Result_OK)
4461 ret = ci_upload_dpm_level_enable_mask(adev);
4466 adev->pm.dpm.forced_level = level;
4471 static int ci_set_mc_special_registers(struct amdgpu_device *adev,
4472 struct ci_mc_reg_table *table)
4477 for (i = 0, j = table->last; i < table->last; i++) {
4478 if (j >= SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE)
4480 switch(table->mc_reg_address[i].s1) {
4481 case mmMC_SEQ_MISC1:
4482 temp_reg = RREG32(mmMC_PMG_CMD_EMRS);
4483 table->mc_reg_address[j].s1 = mmMC_PMG_CMD_EMRS;
4484 table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_EMRS_LP;
4485 for (k = 0; k < table->num_entries; k++) {
4486 table->mc_reg_table_entry[k].mc_data[j] =
4487 ((temp_reg & 0xffff0000)) | ((table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16);
4490 if (j >= SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE)
4493 temp_reg = RREG32(mmMC_PMG_CMD_MRS);
4494 table->mc_reg_address[j].s1 = mmMC_PMG_CMD_MRS;
4495 table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_MRS_LP;
4496 for (k = 0; k < table->num_entries; k++) {
4497 table->mc_reg_table_entry[k].mc_data[j] =
4498 (temp_reg & 0xffff0000) | (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff);
4499 if (adev->mc.vram_type != AMDGPU_VRAM_TYPE_GDDR5)
4500 table->mc_reg_table_entry[k].mc_data[j] |= 0x100;
4503 if (j > SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE)
4506 if (adev->mc.vram_type != AMDGPU_VRAM_TYPE_GDDR5) {
4507 table->mc_reg_address[j].s1 = mmMC_PMG_AUTO_CMD;
4508 table->mc_reg_address[j].s0 = mmMC_PMG_AUTO_CMD;
4509 for (k = 0; k < table->num_entries; k++) {
4510 table->mc_reg_table_entry[k].mc_data[j] =
4511 (table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16;
4514 if (j > SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE)
4518 case mmMC_SEQ_RESERVE_M:
4519 temp_reg = RREG32(mmMC_PMG_CMD_MRS1);
4520 table->mc_reg_address[j].s1 = mmMC_PMG_CMD_MRS1;
4521 table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_MRS1_LP;
4522 for (k = 0; k < table->num_entries; k++) {
4523 table->mc_reg_table_entry[k].mc_data[j] =
4524 (temp_reg & 0xffff0000) | (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff);
4527 if (j > SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE)
4541 static bool ci_check_s0_mc_reg_index(u16 in_reg, u16 *out_reg)
4546 case mmMC_SEQ_RAS_TIMING:
4547 *out_reg = mmMC_SEQ_RAS_TIMING_LP;
4549 case mmMC_SEQ_DLL_STBY:
4550 *out_reg = mmMC_SEQ_DLL_STBY_LP;
4552 case mmMC_SEQ_G5PDX_CMD0:
4553 *out_reg = mmMC_SEQ_G5PDX_CMD0_LP;
4555 case mmMC_SEQ_G5PDX_CMD1:
4556 *out_reg = mmMC_SEQ_G5PDX_CMD1_LP;
4558 case mmMC_SEQ_G5PDX_CTRL:
4559 *out_reg = mmMC_SEQ_G5PDX_CTRL_LP;
4561 case mmMC_SEQ_CAS_TIMING:
4562 *out_reg = mmMC_SEQ_CAS_TIMING_LP;
4564 case mmMC_SEQ_MISC_TIMING:
4565 *out_reg = mmMC_SEQ_MISC_TIMING_LP;
4567 case mmMC_SEQ_MISC_TIMING2:
4568 *out_reg = mmMC_SEQ_MISC_TIMING2_LP;
4570 case mmMC_SEQ_PMG_DVS_CMD:
4571 *out_reg = mmMC_SEQ_PMG_DVS_CMD_LP;
4573 case mmMC_SEQ_PMG_DVS_CTL:
4574 *out_reg = mmMC_SEQ_PMG_DVS_CTL_LP;
4576 case mmMC_SEQ_RD_CTL_D0:
4577 *out_reg = mmMC_SEQ_RD_CTL_D0_LP;
4579 case mmMC_SEQ_RD_CTL_D1:
4580 *out_reg = mmMC_SEQ_RD_CTL_D1_LP;
4582 case mmMC_SEQ_WR_CTL_D0:
4583 *out_reg = mmMC_SEQ_WR_CTL_D0_LP;
4585 case mmMC_SEQ_WR_CTL_D1:
4586 *out_reg = mmMC_SEQ_WR_CTL_D1_LP;
4588 case mmMC_PMG_CMD_EMRS:
4589 *out_reg = mmMC_SEQ_PMG_CMD_EMRS_LP;
4591 case mmMC_PMG_CMD_MRS:
4592 *out_reg = mmMC_SEQ_PMG_CMD_MRS_LP;
4594 case mmMC_PMG_CMD_MRS1:
4595 *out_reg = mmMC_SEQ_PMG_CMD_MRS1_LP;
4597 case mmMC_SEQ_PMG_TIMING:
4598 *out_reg = mmMC_SEQ_PMG_TIMING_LP;
4600 case mmMC_PMG_CMD_MRS2:
4601 *out_reg = mmMC_SEQ_PMG_CMD_MRS2_LP;
4603 case mmMC_SEQ_WR_CTL_2:
4604 *out_reg = mmMC_SEQ_WR_CTL_2_LP;
4614 static void ci_set_valid_flag(struct ci_mc_reg_table *table)
4618 for (i = 0; i < table->last; i++) {
4619 for (j = 1; j < table->num_entries; j++) {
4620 if (table->mc_reg_table_entry[j-1].mc_data[i] !=
4621 table->mc_reg_table_entry[j].mc_data[i]) {
4622 table->valid_flag |= 1 << i;
4629 static void ci_set_s0_mc_reg_index(struct ci_mc_reg_table *table)
4634 for (i = 0; i < table->last; i++) {
4635 table->mc_reg_address[i].s0 =
4636 ci_check_s0_mc_reg_index(table->mc_reg_address[i].s1, &address) ?
4637 address : table->mc_reg_address[i].s1;
4641 static int ci_copy_vbios_mc_reg_table(const struct atom_mc_reg_table *table,
4642 struct ci_mc_reg_table *ci_table)
4646 if (table->last > SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE)
4648 if (table->num_entries > MAX_AC_TIMING_ENTRIES)
4651 for (i = 0; i < table->last; i++)
4652 ci_table->mc_reg_address[i].s1 = table->mc_reg_address[i].s1;
4654 ci_table->last = table->last;
4656 for (i = 0; i < table->num_entries; i++) {
4657 ci_table->mc_reg_table_entry[i].mclk_max =
4658 table->mc_reg_table_entry[i].mclk_max;
4659 for (j = 0; j < table->last; j++)
4660 ci_table->mc_reg_table_entry[i].mc_data[j] =
4661 table->mc_reg_table_entry[i].mc_data[j];
4663 ci_table->num_entries = table->num_entries;
4668 static int ci_register_patching_mc_seq(struct amdgpu_device *adev,
4669 struct ci_mc_reg_table *table)
4675 tmp = RREG32(mmMC_SEQ_MISC0);
4676 patch = ((tmp & 0x0000f00) == 0x300) ? true : false;
4679 ((adev->pdev->device == 0x67B0) ||
4680 (adev->pdev->device == 0x67B1))) {
4681 for (i = 0; i < table->last; i++) {
4682 if (table->last >= SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE)
4684 switch (table->mc_reg_address[i].s1) {
4685 case mmMC_SEQ_MISC1:
4686 for (k = 0; k < table->num_entries; k++) {
4687 if ((table->mc_reg_table_entry[k].mclk_max == 125000) ||
4688 (table->mc_reg_table_entry[k].mclk_max == 137500))
4689 table->mc_reg_table_entry[k].mc_data[i] =
4690 (table->mc_reg_table_entry[k].mc_data[i] & 0xFFFFFFF8) |
4694 case mmMC_SEQ_WR_CTL_D0:
4695 for (k = 0; k < table->num_entries; k++) {
4696 if ((table->mc_reg_table_entry[k].mclk_max == 125000) ||
4697 (table->mc_reg_table_entry[k].mclk_max == 137500))
4698 table->mc_reg_table_entry[k].mc_data[i] =
4699 (table->mc_reg_table_entry[k].mc_data[i] & 0xFFFF0F00) |
4703 case mmMC_SEQ_WR_CTL_D1:
4704 for (k = 0; k < table->num_entries; k++) {
4705 if ((table->mc_reg_table_entry[k].mclk_max == 125000) ||
4706 (table->mc_reg_table_entry[k].mclk_max == 137500))
4707 table->mc_reg_table_entry[k].mc_data[i] =
4708 (table->mc_reg_table_entry[k].mc_data[i] & 0xFFFF0F00) |
4712 case mmMC_SEQ_WR_CTL_2:
4713 for (k = 0; k < table->num_entries; k++) {
4714 if ((table->mc_reg_table_entry[k].mclk_max == 125000) ||
4715 (table->mc_reg_table_entry[k].mclk_max == 137500))
4716 table->mc_reg_table_entry[k].mc_data[i] = 0;
4719 case mmMC_SEQ_CAS_TIMING:
4720 for (k = 0; k < table->num_entries; k++) {
4721 if (table->mc_reg_table_entry[k].mclk_max == 125000)
4722 table->mc_reg_table_entry[k].mc_data[i] =
4723 (table->mc_reg_table_entry[k].mc_data[i] & 0xFFE0FE0F) |
4725 else if (table->mc_reg_table_entry[k].mclk_max == 137500)
4726 table->mc_reg_table_entry[k].mc_data[i] =
4727 (table->mc_reg_table_entry[k].mc_data[i] & 0xFFE0FE0F) |
4731 case mmMC_SEQ_MISC_TIMING:
4732 for (k = 0; k < table->num_entries; k++) {
4733 if (table->mc_reg_table_entry[k].mclk_max == 125000)
4734 table->mc_reg_table_entry[k].mc_data[i] =
4735 (table->mc_reg_table_entry[k].mc_data[i] & 0xFFFFFFE0) |
4737 else if (table->mc_reg_table_entry[k].mclk_max == 137500)
4738 table->mc_reg_table_entry[k].mc_data[i] =
4739 (table->mc_reg_table_entry[k].mc_data[i] & 0xFFFFFFE0) |
4748 WREG32(mmMC_SEQ_IO_DEBUG_INDEX, 3);
4749 tmp = RREG32(mmMC_SEQ_IO_DEBUG_DATA);
4750 tmp = (tmp & 0xFFF8FFFF) | (1 << 16);
4751 WREG32(mmMC_SEQ_IO_DEBUG_INDEX, 3);
4752 WREG32(mmMC_SEQ_IO_DEBUG_DATA, tmp);
4758 static int ci_initialize_mc_reg_table(struct amdgpu_device *adev)
4760 struct ci_power_info *pi = ci_get_pi(adev);
4761 struct atom_mc_reg_table *table;
4762 struct ci_mc_reg_table *ci_table = &pi->mc_reg_table;
4763 u8 module_index = ci_get_memory_module_index(adev);
4766 table = kzalloc(sizeof(struct atom_mc_reg_table), GFP_KERNEL);
4770 WREG32(mmMC_SEQ_RAS_TIMING_LP, RREG32(mmMC_SEQ_RAS_TIMING));
4771 WREG32(mmMC_SEQ_CAS_TIMING_LP, RREG32(mmMC_SEQ_CAS_TIMING));
4772 WREG32(mmMC_SEQ_DLL_STBY_LP, RREG32(mmMC_SEQ_DLL_STBY));
4773 WREG32(mmMC_SEQ_G5PDX_CMD0_LP, RREG32(mmMC_SEQ_G5PDX_CMD0));
4774 WREG32(mmMC_SEQ_G5PDX_CMD1_LP, RREG32(mmMC_SEQ_G5PDX_CMD1));
4775 WREG32(mmMC_SEQ_G5PDX_CTRL_LP, RREG32(mmMC_SEQ_G5PDX_CTRL));
4776 WREG32(mmMC_SEQ_PMG_DVS_CMD_LP, RREG32(mmMC_SEQ_PMG_DVS_CMD));
4777 WREG32(mmMC_SEQ_PMG_DVS_CTL_LP, RREG32(mmMC_SEQ_PMG_DVS_CTL));
4778 WREG32(mmMC_SEQ_MISC_TIMING_LP, RREG32(mmMC_SEQ_MISC_TIMING));
4779 WREG32(mmMC_SEQ_MISC_TIMING2_LP, RREG32(mmMC_SEQ_MISC_TIMING2));
4780 WREG32(mmMC_SEQ_PMG_CMD_EMRS_LP, RREG32(mmMC_PMG_CMD_EMRS));
4781 WREG32(mmMC_SEQ_PMG_CMD_MRS_LP, RREG32(mmMC_PMG_CMD_MRS));
4782 WREG32(mmMC_SEQ_PMG_CMD_MRS1_LP, RREG32(mmMC_PMG_CMD_MRS1));
4783 WREG32(mmMC_SEQ_WR_CTL_D0_LP, RREG32(mmMC_SEQ_WR_CTL_D0));
4784 WREG32(mmMC_SEQ_WR_CTL_D1_LP, RREG32(mmMC_SEQ_WR_CTL_D1));
4785 WREG32(mmMC_SEQ_RD_CTL_D0_LP, RREG32(mmMC_SEQ_RD_CTL_D0));
4786 WREG32(mmMC_SEQ_RD_CTL_D1_LP, RREG32(mmMC_SEQ_RD_CTL_D1));
4787 WREG32(mmMC_SEQ_PMG_TIMING_LP, RREG32(mmMC_SEQ_PMG_TIMING));
4788 WREG32(mmMC_SEQ_PMG_CMD_MRS2_LP, RREG32(mmMC_PMG_CMD_MRS2));
4789 WREG32(mmMC_SEQ_WR_CTL_2_LP, RREG32(mmMC_SEQ_WR_CTL_2));
4791 ret = amdgpu_atombios_init_mc_reg_table(adev, module_index, table);
4795 ret = ci_copy_vbios_mc_reg_table(table, ci_table);
4799 ci_set_s0_mc_reg_index(ci_table);
4801 ret = ci_register_patching_mc_seq(adev, ci_table);
4805 ret = ci_set_mc_special_registers(adev, ci_table);
4809 ci_set_valid_flag(ci_table);
4817 static int ci_populate_mc_reg_addresses(struct amdgpu_device *adev,
4818 SMU7_Discrete_MCRegisters *mc_reg_table)
4820 struct ci_power_info *pi = ci_get_pi(adev);
4823 for (i = 0, j = 0; j < pi->mc_reg_table.last; j++) {
4824 if (pi->mc_reg_table.valid_flag & (1 << j)) {
4825 if (i >= SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE)
4827 mc_reg_table->address[i].s0 = cpu_to_be16(pi->mc_reg_table.mc_reg_address[j].s0);
4828 mc_reg_table->address[i].s1 = cpu_to_be16(pi->mc_reg_table.mc_reg_address[j].s1);
4833 mc_reg_table->last = (u8)i;
4838 static void ci_convert_mc_registers(const struct ci_mc_reg_entry *entry,
4839 SMU7_Discrete_MCRegisterSet *data,
4840 u32 num_entries, u32 valid_flag)
4844 for (i = 0, j = 0; j < num_entries; j++) {
4845 if (valid_flag & (1 << j)) {
4846 data->value[i] = cpu_to_be32(entry->mc_data[j]);
4852 static void ci_convert_mc_reg_table_entry_to_smc(struct amdgpu_device *adev,
4853 const u32 memory_clock,
4854 SMU7_Discrete_MCRegisterSet *mc_reg_table_data)
4856 struct ci_power_info *pi = ci_get_pi(adev);
4859 for(i = 0; i < pi->mc_reg_table.num_entries; i++) {
4860 if (memory_clock <= pi->mc_reg_table.mc_reg_table_entry[i].mclk_max)
4864 if ((i == pi->mc_reg_table.num_entries) && (i > 0))
4867 ci_convert_mc_registers(&pi->mc_reg_table.mc_reg_table_entry[i],
4868 mc_reg_table_data, pi->mc_reg_table.last,
4869 pi->mc_reg_table.valid_flag);
4872 static void ci_convert_mc_reg_table_to_smc(struct amdgpu_device *adev,
4873 SMU7_Discrete_MCRegisters *mc_reg_table)
4875 struct ci_power_info *pi = ci_get_pi(adev);
4878 for (i = 0; i < pi->dpm_table.mclk_table.count; i++)
4879 ci_convert_mc_reg_table_entry_to_smc(adev,
4880 pi->dpm_table.mclk_table.dpm_levels[i].value,
4881 &mc_reg_table->data[i]);
4884 static int ci_populate_initial_mc_reg_table(struct amdgpu_device *adev)
4886 struct ci_power_info *pi = ci_get_pi(adev);
4889 memset(&pi->smc_mc_reg_table, 0, sizeof(SMU7_Discrete_MCRegisters));
4891 ret = ci_populate_mc_reg_addresses(adev, &pi->smc_mc_reg_table);
4894 ci_convert_mc_reg_table_to_smc(adev, &pi->smc_mc_reg_table);
4896 return amdgpu_ci_copy_bytes_to_smc(adev,
4897 pi->mc_reg_table_start,
4898 (u8 *)&pi->smc_mc_reg_table,
4899 sizeof(SMU7_Discrete_MCRegisters),
4903 static int ci_update_and_upload_mc_reg_table(struct amdgpu_device *adev)
4905 struct ci_power_info *pi = ci_get_pi(adev);
4907 if (!(pi->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK))
4910 memset(&pi->smc_mc_reg_table, 0, sizeof(SMU7_Discrete_MCRegisters));
4912 ci_convert_mc_reg_table_to_smc(adev, &pi->smc_mc_reg_table);
4914 return amdgpu_ci_copy_bytes_to_smc(adev,
4915 pi->mc_reg_table_start +
4916 offsetof(SMU7_Discrete_MCRegisters, data[0]),
4917 (u8 *)&pi->smc_mc_reg_table.data[0],
4918 sizeof(SMU7_Discrete_MCRegisterSet) *
4919 pi->dpm_table.mclk_table.count,
4923 static void ci_enable_voltage_control(struct amdgpu_device *adev)
4925 u32 tmp = RREG32_SMC(ixGENERAL_PWRMGT);
4927 tmp |= GENERAL_PWRMGT__VOLT_PWRMGT_EN_MASK;
4928 WREG32_SMC(ixGENERAL_PWRMGT, tmp);
4931 static enum amdgpu_pcie_gen ci_get_maximum_link_speed(struct amdgpu_device *adev,
4932 struct amdgpu_ps *amdgpu_state)
4934 struct ci_ps *state = ci_get_ps(amdgpu_state);
4936 u16 pcie_speed, max_speed = 0;
4938 for (i = 0; i < state->performance_level_count; i++) {
4939 pcie_speed = state->performance_levels[i].pcie_gen;
4940 if (max_speed < pcie_speed)
4941 max_speed = pcie_speed;
4947 static u16 ci_get_current_pcie_speed(struct amdgpu_device *adev)
4951 speed_cntl = RREG32_PCIE(ixPCIE_LC_SPEED_CNTL) &
4952 PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE_MASK;
4953 speed_cntl >>= PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE__SHIFT;
4955 return (u16)speed_cntl;
4958 static int ci_get_current_pcie_lane_number(struct amdgpu_device *adev)
4962 link_width = RREG32_PCIE(ixPCIE_LC_LINK_WIDTH_CNTL) &
4963 PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD_MASK;
4964 link_width >>= PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD__SHIFT;
4966 switch (link_width) {
4982 static void ci_request_link_speed_change_before_state_change(struct amdgpu_device *adev,
4983 struct amdgpu_ps *amdgpu_new_state,
4984 struct amdgpu_ps *amdgpu_current_state)
4986 struct ci_power_info *pi = ci_get_pi(adev);
4987 enum amdgpu_pcie_gen target_link_speed =
4988 ci_get_maximum_link_speed(adev, amdgpu_new_state);
4989 enum amdgpu_pcie_gen current_link_speed;
4991 if (pi->force_pcie_gen == AMDGPU_PCIE_GEN_INVALID)
4992 current_link_speed = ci_get_maximum_link_speed(adev, amdgpu_current_state);
4994 current_link_speed = pi->force_pcie_gen;
4996 pi->force_pcie_gen = AMDGPU_PCIE_GEN_INVALID;
4997 pi->pspp_notify_required = false;
4998 if (target_link_speed > current_link_speed) {
4999 switch (target_link_speed) {
5001 case AMDGPU_PCIE_GEN3:
5002 if (amdgpu_acpi_pcie_performance_request(adev, PCIE_PERF_REQ_PECI_GEN3, false) == 0)
5004 pi->force_pcie_gen = AMDGPU_PCIE_GEN2;
5005 if (current_link_speed == AMDGPU_PCIE_GEN2)
5007 case AMDGPU_PCIE_GEN2:
5008 if (amdgpu_acpi_pcie_performance_request(adev, PCIE_PERF_REQ_PECI_GEN2, false) == 0)
5012 pi->force_pcie_gen = ci_get_current_pcie_speed(adev);
5016 if (target_link_speed < current_link_speed)
5017 pi->pspp_notify_required = true;
5021 static void ci_notify_link_speed_change_after_state_change(struct amdgpu_device *adev,
5022 struct amdgpu_ps *amdgpu_new_state,
5023 struct amdgpu_ps *amdgpu_current_state)
5025 struct ci_power_info *pi = ci_get_pi(adev);
5026 enum amdgpu_pcie_gen target_link_speed =
5027 ci_get_maximum_link_speed(adev, amdgpu_new_state);
5030 if (pi->pspp_notify_required) {
5031 if (target_link_speed == AMDGPU_PCIE_GEN3)
5032 request = PCIE_PERF_REQ_PECI_GEN3;
5033 else if (target_link_speed == AMDGPU_PCIE_GEN2)
5034 request = PCIE_PERF_REQ_PECI_GEN2;
5036 request = PCIE_PERF_REQ_PECI_GEN1;
5038 if ((request == PCIE_PERF_REQ_PECI_GEN1) &&
5039 (ci_get_current_pcie_speed(adev) > 0))
5043 amdgpu_acpi_pcie_performance_request(adev, request, false);
5048 static int ci_set_private_data_variables_based_on_pptable(struct amdgpu_device *adev)
5050 struct ci_power_info *pi = ci_get_pi(adev);
5051 struct amdgpu_clock_voltage_dependency_table *allowed_sclk_vddc_table =
5052 &adev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
5053 struct amdgpu_clock_voltage_dependency_table *allowed_mclk_vddc_table =
5054 &adev->pm.dpm.dyn_state.vddc_dependency_on_mclk;
5055 struct amdgpu_clock_voltage_dependency_table *allowed_mclk_vddci_table =
5056 &adev->pm.dpm.dyn_state.vddci_dependency_on_mclk;
5058 if (allowed_sclk_vddc_table == NULL)
5060 if (allowed_sclk_vddc_table->count < 1)
5062 if (allowed_mclk_vddc_table == NULL)
5064 if (allowed_mclk_vddc_table->count < 1)
5066 if (allowed_mclk_vddci_table == NULL)
5068 if (allowed_mclk_vddci_table->count < 1)
5071 pi->min_vddc_in_pp_table = allowed_sclk_vddc_table->entries[0].v;
5072 pi->max_vddc_in_pp_table =
5073 allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].v;
5075 pi->min_vddci_in_pp_table = allowed_mclk_vddci_table->entries[0].v;
5076 pi->max_vddci_in_pp_table =
5077 allowed_mclk_vddci_table->entries[allowed_mclk_vddci_table->count - 1].v;
5079 adev->pm.dpm.dyn_state.max_clock_voltage_on_ac.sclk =
5080 allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].clk;
5081 adev->pm.dpm.dyn_state.max_clock_voltage_on_ac.mclk =
5082 allowed_mclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].clk;
5083 adev->pm.dpm.dyn_state.max_clock_voltage_on_ac.vddc =
5084 allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].v;
5085 adev->pm.dpm.dyn_state.max_clock_voltage_on_ac.vddci =
5086 allowed_mclk_vddci_table->entries[allowed_mclk_vddci_table->count - 1].v;
5091 static void ci_patch_with_vddc_leakage(struct amdgpu_device *adev, u16 *vddc)
5093 struct ci_power_info *pi = ci_get_pi(adev);
5094 struct ci_leakage_voltage *leakage_table = &pi->vddc_leakage;
5097 for (leakage_index = 0; leakage_index < leakage_table->count; leakage_index++) {
5098 if (leakage_table->leakage_id[leakage_index] == *vddc) {
5099 *vddc = leakage_table->actual_voltage[leakage_index];
5105 static void ci_patch_with_vddci_leakage(struct amdgpu_device *adev, u16 *vddci)
5107 struct ci_power_info *pi = ci_get_pi(adev);
5108 struct ci_leakage_voltage *leakage_table = &pi->vddci_leakage;
5111 for (leakage_index = 0; leakage_index < leakage_table->count; leakage_index++) {
5112 if (leakage_table->leakage_id[leakage_index] == *vddci) {
5113 *vddci = leakage_table->actual_voltage[leakage_index];
5119 static void ci_patch_clock_voltage_dependency_table_with_vddc_leakage(struct amdgpu_device *adev,
5120 struct amdgpu_clock_voltage_dependency_table *table)
5125 for (i = 0; i < table->count; i++)
5126 ci_patch_with_vddc_leakage(adev, &table->entries[i].v);
5130 static void ci_patch_clock_voltage_dependency_table_with_vddci_leakage(struct amdgpu_device *adev,
5131 struct amdgpu_clock_voltage_dependency_table *table)
5136 for (i = 0; i < table->count; i++)
5137 ci_patch_with_vddci_leakage(adev, &table->entries[i].v);
5141 static void ci_patch_vce_clock_voltage_dependency_table_with_vddc_leakage(struct amdgpu_device *adev,
5142 struct amdgpu_vce_clock_voltage_dependency_table *table)
5147 for (i = 0; i < table->count; i++)
5148 ci_patch_with_vddc_leakage(adev, &table->entries[i].v);
5152 static void ci_patch_uvd_clock_voltage_dependency_table_with_vddc_leakage(struct amdgpu_device *adev,
5153 struct amdgpu_uvd_clock_voltage_dependency_table *table)
5158 for (i = 0; i < table->count; i++)
5159 ci_patch_with_vddc_leakage(adev, &table->entries[i].v);
5163 static void ci_patch_vddc_phase_shed_limit_table_with_vddc_leakage(struct amdgpu_device *adev,
5164 struct amdgpu_phase_shedding_limits_table *table)
5169 for (i = 0; i < table->count; i++)
5170 ci_patch_with_vddc_leakage(adev, &table->entries[i].voltage);
5174 static void ci_patch_clock_voltage_limits_with_vddc_leakage(struct amdgpu_device *adev,
5175 struct amdgpu_clock_and_voltage_limits *table)
5178 ci_patch_with_vddc_leakage(adev, (u16 *)&table->vddc);
5179 ci_patch_with_vddci_leakage(adev, (u16 *)&table->vddci);
5183 static void ci_patch_cac_leakage_table_with_vddc_leakage(struct amdgpu_device *adev,
5184 struct amdgpu_cac_leakage_table *table)
5189 for (i = 0; i < table->count; i++)
5190 ci_patch_with_vddc_leakage(adev, &table->entries[i].vddc);
5194 static void ci_patch_dependency_tables_with_leakage(struct amdgpu_device *adev)
5197 ci_patch_clock_voltage_dependency_table_with_vddc_leakage(adev,
5198 &adev->pm.dpm.dyn_state.vddc_dependency_on_sclk);
5199 ci_patch_clock_voltage_dependency_table_with_vddc_leakage(adev,
5200 &adev->pm.dpm.dyn_state.vddc_dependency_on_mclk);
5201 ci_patch_clock_voltage_dependency_table_with_vddc_leakage(adev,
5202 &adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk);
5203 ci_patch_clock_voltage_dependency_table_with_vddci_leakage(adev,
5204 &adev->pm.dpm.dyn_state.vddci_dependency_on_mclk);
5205 ci_patch_vce_clock_voltage_dependency_table_with_vddc_leakage(adev,
5206 &adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table);
5207 ci_patch_uvd_clock_voltage_dependency_table_with_vddc_leakage(adev,
5208 &adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table);
5209 ci_patch_clock_voltage_dependency_table_with_vddc_leakage(adev,
5210 &adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table);
5211 ci_patch_clock_voltage_dependency_table_with_vddc_leakage(adev,
5212 &adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table);
5213 ci_patch_vddc_phase_shed_limit_table_with_vddc_leakage(adev,
5214 &adev->pm.dpm.dyn_state.phase_shedding_limits_table);
5215 ci_patch_clock_voltage_limits_with_vddc_leakage(adev,
5216 &adev->pm.dpm.dyn_state.max_clock_voltage_on_ac);
5217 ci_patch_clock_voltage_limits_with_vddc_leakage(adev,
5218 &adev->pm.dpm.dyn_state.max_clock_voltage_on_dc);
5219 ci_patch_cac_leakage_table_with_vddc_leakage(adev,
5220 &adev->pm.dpm.dyn_state.cac_leakage_table);
5224 static void ci_update_current_ps(struct amdgpu_device *adev,
5225 struct amdgpu_ps *rps)
5227 struct ci_ps *new_ps = ci_get_ps(rps);
5228 struct ci_power_info *pi = ci_get_pi(adev);
5230 pi->current_rps = *rps;
5231 pi->current_ps = *new_ps;
5232 pi->current_rps.ps_priv = &pi->current_ps;
5235 static void ci_update_requested_ps(struct amdgpu_device *adev,
5236 struct amdgpu_ps *rps)
5238 struct ci_ps *new_ps = ci_get_ps(rps);
5239 struct ci_power_info *pi = ci_get_pi(adev);
5241 pi->requested_rps = *rps;
5242 pi->requested_ps = *new_ps;
5243 pi->requested_rps.ps_priv = &pi->requested_ps;
5246 static int ci_dpm_pre_set_power_state(struct amdgpu_device *adev)
5248 struct ci_power_info *pi = ci_get_pi(adev);
5249 struct amdgpu_ps requested_ps = *adev->pm.dpm.requested_ps;
5250 struct amdgpu_ps *new_ps = &requested_ps;
5252 ci_update_requested_ps(adev, new_ps);
5254 ci_apply_state_adjust_rules(adev, &pi->requested_rps);
5259 static void ci_dpm_post_set_power_state(struct amdgpu_device *adev)
5261 struct ci_power_info *pi = ci_get_pi(adev);
5262 struct amdgpu_ps *new_ps = &pi->requested_rps;
5264 ci_update_current_ps(adev, new_ps);
5268 static void ci_dpm_setup_asic(struct amdgpu_device *adev)
5270 ci_read_clock_registers(adev);
5271 ci_enable_acpi_power_management(adev);
5272 ci_init_sclk_t(adev);
5275 static int ci_dpm_enable(struct amdgpu_device *adev)
5277 struct ci_power_info *pi = ci_get_pi(adev);
5278 struct amdgpu_ps *boot_ps = adev->pm.dpm.boot_ps;
5281 if (amdgpu_ci_is_smc_running(adev))
5283 if (pi->voltage_control != CISLANDS_VOLTAGE_CONTROL_NONE) {
5284 ci_enable_voltage_control(adev);
5285 ret = ci_construct_voltage_tables(adev);
5287 DRM_ERROR("ci_construct_voltage_tables failed\n");
5291 if (pi->caps_dynamic_ac_timing) {
5292 ret = ci_initialize_mc_reg_table(adev);
5294 pi->caps_dynamic_ac_timing = false;
5297 ci_enable_spread_spectrum(adev, true);
5298 if (pi->thermal_protection)
5299 ci_enable_thermal_protection(adev, true);
5300 ci_program_sstp(adev);
5301 ci_enable_display_gap(adev);
5302 ci_program_vc(adev);
5303 ret = ci_upload_firmware(adev);
5305 DRM_ERROR("ci_upload_firmware failed\n");
5308 ret = ci_process_firmware_header(adev);
5310 DRM_ERROR("ci_process_firmware_header failed\n");
5313 ret = ci_initial_switch_from_arb_f0_to_f1(adev);
5315 DRM_ERROR("ci_initial_switch_from_arb_f0_to_f1 failed\n");
5318 ret = ci_init_smc_table(adev);
5320 DRM_ERROR("ci_init_smc_table failed\n");
5323 ret = ci_init_arb_table_index(adev);
5325 DRM_ERROR("ci_init_arb_table_index failed\n");
5328 if (pi->caps_dynamic_ac_timing) {
5329 ret = ci_populate_initial_mc_reg_table(adev);
5331 DRM_ERROR("ci_populate_initial_mc_reg_table failed\n");
5335 ret = ci_populate_pm_base(adev);
5337 DRM_ERROR("ci_populate_pm_base failed\n");
5340 ci_dpm_start_smc(adev);
5341 ci_enable_vr_hot_gpio_interrupt(adev);
5342 ret = ci_notify_smc_display_change(adev, false);
5344 DRM_ERROR("ci_notify_smc_display_change failed\n");
5347 ci_enable_sclk_control(adev, true);
5348 ret = ci_enable_ulv(adev, true);
5350 DRM_ERROR("ci_enable_ulv failed\n");
5353 ret = ci_enable_ds_master_switch(adev, true);
5355 DRM_ERROR("ci_enable_ds_master_switch failed\n");
5358 ret = ci_start_dpm(adev);
5360 DRM_ERROR("ci_start_dpm failed\n");
5363 ret = ci_enable_didt(adev, true);
5365 DRM_ERROR("ci_enable_didt failed\n");
5368 ret = ci_enable_smc_cac(adev, true);
5370 DRM_ERROR("ci_enable_smc_cac failed\n");
5373 ret = ci_enable_power_containment(adev, true);
5375 DRM_ERROR("ci_enable_power_containment failed\n");
5379 ret = ci_power_control_set_level(adev);
5381 DRM_ERROR("ci_power_control_set_level failed\n");
5385 ci_enable_auto_throttle_source(adev, AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL, true);
5387 ret = ci_enable_thermal_based_sclk_dpm(adev, true);
5389 DRM_ERROR("ci_enable_thermal_based_sclk_dpm failed\n");
5393 ci_thermal_start_thermal_controller(adev);
5395 ci_update_current_ps(adev, boot_ps);
5397 if (adev->irq.installed &&
5398 amdgpu_is_internal_thermal_sensor(adev->pm.int_thermal_type)) {
5400 PPSMC_Result result;
5402 ret = ci_thermal_set_temperature_range(adev, CISLANDS_TEMP_RANGE_MIN,
5403 CISLANDS_TEMP_RANGE_MAX);
5405 DRM_ERROR("ci_thermal_set_temperature_range failed\n");
5408 amdgpu_irq_get(adev, &adev->pm.dpm.thermal.irq,
5409 AMDGPU_THERMAL_IRQ_LOW_TO_HIGH);
5410 amdgpu_irq_get(adev, &adev->pm.dpm.thermal.irq,
5411 AMDGPU_THERMAL_IRQ_HIGH_TO_LOW);
5414 result = amdgpu_ci_send_msg_to_smc(adev, PPSMC_MSG_EnableThermalInterrupt);
5416 if (result != PPSMC_Result_OK)
5417 DRM_DEBUG_KMS("Could not enable thermal interrupts.\n");
5424 static void ci_dpm_disable(struct amdgpu_device *adev)
5426 struct ci_power_info *pi = ci_get_pi(adev);
5427 struct amdgpu_ps *boot_ps = adev->pm.dpm.boot_ps;
5429 amdgpu_irq_put(adev, &adev->pm.dpm.thermal.irq,
5430 AMDGPU_THERMAL_IRQ_LOW_TO_HIGH);
5431 amdgpu_irq_put(adev, &adev->pm.dpm.thermal.irq,
5432 AMDGPU_THERMAL_IRQ_HIGH_TO_LOW);
5434 ci_dpm_powergate_uvd(adev, false);
5436 if (!amdgpu_ci_is_smc_running(adev))
5439 ci_thermal_stop_thermal_controller(adev);
5441 if (pi->thermal_protection)
5442 ci_enable_thermal_protection(adev, false);
5443 ci_enable_power_containment(adev, false);
5444 ci_enable_smc_cac(adev, false);
5445 ci_enable_didt(adev, false);
5446 ci_enable_spread_spectrum(adev, false);
5447 ci_enable_auto_throttle_source(adev, AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL, false);
5449 ci_enable_ds_master_switch(adev, false);
5450 ci_enable_ulv(adev, false);
5452 ci_reset_to_default(adev);
5453 ci_dpm_stop_smc(adev);
5454 ci_force_switch_to_arb_f0(adev);
5455 ci_enable_thermal_based_sclk_dpm(adev, false);
5457 ci_update_current_ps(adev, boot_ps);
5460 static int ci_dpm_set_power_state(struct amdgpu_device *adev)
5462 struct ci_power_info *pi = ci_get_pi(adev);
5463 struct amdgpu_ps *new_ps = &pi->requested_rps;
5464 struct amdgpu_ps *old_ps = &pi->current_rps;
5467 ci_find_dpm_states_clocks_in_dpm_table(adev, new_ps);
5468 if (pi->pcie_performance_request)
5469 ci_request_link_speed_change_before_state_change(adev, new_ps, old_ps);
5470 ret = ci_freeze_sclk_mclk_dpm(adev);
5472 DRM_ERROR("ci_freeze_sclk_mclk_dpm failed\n");
5475 ret = ci_populate_and_upload_sclk_mclk_dpm_levels(adev, new_ps);
5477 DRM_ERROR("ci_populate_and_upload_sclk_mclk_dpm_levels failed\n");
5480 ret = ci_generate_dpm_level_enable_mask(adev, new_ps);
5482 DRM_ERROR("ci_generate_dpm_level_enable_mask failed\n");
5486 ret = ci_update_vce_dpm(adev, new_ps, old_ps);
5488 DRM_ERROR("ci_update_vce_dpm failed\n");
5492 ret = ci_update_sclk_t(adev);
5494 DRM_ERROR("ci_update_sclk_t failed\n");
5497 if (pi->caps_dynamic_ac_timing) {
5498 ret = ci_update_and_upload_mc_reg_table(adev);
5500 DRM_ERROR("ci_update_and_upload_mc_reg_table failed\n");
5504 ret = ci_program_memory_timing_parameters(adev);
5506 DRM_ERROR("ci_program_memory_timing_parameters failed\n");
5509 ret = ci_unfreeze_sclk_mclk_dpm(adev);
5511 DRM_ERROR("ci_unfreeze_sclk_mclk_dpm failed\n");
5514 ret = ci_upload_dpm_level_enable_mask(adev);
5516 DRM_ERROR("ci_upload_dpm_level_enable_mask failed\n");
5519 if (pi->pcie_performance_request)
5520 ci_notify_link_speed_change_after_state_change(adev, new_ps, old_ps);
5526 static void ci_dpm_reset_asic(struct amdgpu_device *adev)
5528 ci_set_boot_state(adev);
5532 static void ci_dpm_display_configuration_changed(struct amdgpu_device *adev)
5534 ci_program_display_gap(adev);
5538 struct _ATOM_POWERPLAY_INFO info;
5539 struct _ATOM_POWERPLAY_INFO_V2 info_2;
5540 struct _ATOM_POWERPLAY_INFO_V3 info_3;
5541 struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
5542 struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
5543 struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
5546 union pplib_clock_info {
5547 struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
5548 struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
5549 struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
5550 struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
5551 struct _ATOM_PPLIB_SI_CLOCK_INFO si;
5552 struct _ATOM_PPLIB_CI_CLOCK_INFO ci;
5555 union pplib_power_state {
5556 struct _ATOM_PPLIB_STATE v1;
5557 struct _ATOM_PPLIB_STATE_V2 v2;
5560 static void ci_parse_pplib_non_clock_info(struct amdgpu_device *adev,
5561 struct amdgpu_ps *rps,
5562 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info,
5565 rps->caps = le32_to_cpu(non_clock_info->ulCapsAndSettings);
5566 rps->class = le16_to_cpu(non_clock_info->usClassification);
5567 rps->class2 = le16_to_cpu(non_clock_info->usClassification2);
5569 if (ATOM_PPLIB_NONCLOCKINFO_VER1 < table_rev) {
5570 rps->vclk = le32_to_cpu(non_clock_info->ulVCLK);
5571 rps->dclk = le32_to_cpu(non_clock_info->ulDCLK);
5577 if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT)
5578 adev->pm.dpm.boot_ps = rps;
5579 if (rps->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE)
5580 adev->pm.dpm.uvd_ps = rps;
5583 static void ci_parse_pplib_clock_info(struct amdgpu_device *adev,
5584 struct amdgpu_ps *rps, int index,
5585 union pplib_clock_info *clock_info)
5587 struct ci_power_info *pi = ci_get_pi(adev);
5588 struct ci_ps *ps = ci_get_ps(rps);
5589 struct ci_pl *pl = &ps->performance_levels[index];
5591 ps->performance_level_count = index + 1;
5593 pl->sclk = le16_to_cpu(clock_info->ci.usEngineClockLow);
5594 pl->sclk |= clock_info->ci.ucEngineClockHigh << 16;
5595 pl->mclk = le16_to_cpu(clock_info->ci.usMemoryClockLow);
5596 pl->mclk |= clock_info->ci.ucMemoryClockHigh << 16;
5598 pl->pcie_gen = amdgpu_get_pcie_gen_support(adev,
5600 pi->vbios_boot_state.pcie_gen_bootup_value,
5601 clock_info->ci.ucPCIEGen);
5602 pl->pcie_lane = amdgpu_get_pcie_lane_support(adev,
5603 pi->vbios_boot_state.pcie_lane_bootup_value,
5604 le16_to_cpu(clock_info->ci.usPCIELane));
5606 if (rps->class & ATOM_PPLIB_CLASSIFICATION_ACPI) {
5607 pi->acpi_pcie_gen = pl->pcie_gen;
5610 if (rps->class2 & ATOM_PPLIB_CLASSIFICATION2_ULV) {
5611 pi->ulv.supported = true;
5613 pi->ulv.cg_ulv_parameter = CISLANDS_CGULVPARAMETER_DFLT;
5616 /* patch up boot state */
5617 if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT) {
5618 pl->mclk = pi->vbios_boot_state.mclk_bootup_value;
5619 pl->sclk = pi->vbios_boot_state.sclk_bootup_value;
5620 pl->pcie_gen = pi->vbios_boot_state.pcie_gen_bootup_value;
5621 pl->pcie_lane = pi->vbios_boot_state.pcie_lane_bootup_value;
5624 switch (rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
5625 case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
5626 pi->use_pcie_powersaving_levels = true;
5627 if (pi->pcie_gen_powersaving.max < pl->pcie_gen)
5628 pi->pcie_gen_powersaving.max = pl->pcie_gen;
5629 if (pi->pcie_gen_powersaving.min > pl->pcie_gen)
5630 pi->pcie_gen_powersaving.min = pl->pcie_gen;
5631 if (pi->pcie_lane_powersaving.max < pl->pcie_lane)
5632 pi->pcie_lane_powersaving.max = pl->pcie_lane;
5633 if (pi->pcie_lane_powersaving.min > pl->pcie_lane)
5634 pi->pcie_lane_powersaving.min = pl->pcie_lane;
5636 case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
5637 pi->use_pcie_performance_levels = true;
5638 if (pi->pcie_gen_performance.max < pl->pcie_gen)
5639 pi->pcie_gen_performance.max = pl->pcie_gen;
5640 if (pi->pcie_gen_performance.min > pl->pcie_gen)
5641 pi->pcie_gen_performance.min = pl->pcie_gen;
5642 if (pi->pcie_lane_performance.max < pl->pcie_lane)
5643 pi->pcie_lane_performance.max = pl->pcie_lane;
5644 if (pi->pcie_lane_performance.min > pl->pcie_lane)
5645 pi->pcie_lane_performance.min = pl->pcie_lane;
5652 static int ci_parse_power_table(struct amdgpu_device *adev)
5654 struct amdgpu_mode_info *mode_info = &adev->mode_info;
5655 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
5656 union pplib_power_state *power_state;
5657 int i, j, k, non_clock_array_index, clock_array_index;
5658 union pplib_clock_info *clock_info;
5659 struct _StateArray *state_array;
5660 struct _ClockInfoArray *clock_info_array;
5661 struct _NonClockInfoArray *non_clock_info_array;
5662 union power_info *power_info;
5663 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
5666 u8 *power_state_offset;
5669 if (!amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
5670 &frev, &crev, &data_offset))
5672 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
5674 amdgpu_add_thermal_controller(adev);
5676 state_array = (struct _StateArray *)
5677 (mode_info->atom_context->bios + data_offset +
5678 le16_to_cpu(power_info->pplib.usStateArrayOffset));
5679 clock_info_array = (struct _ClockInfoArray *)
5680 (mode_info->atom_context->bios + data_offset +
5681 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset));
5682 non_clock_info_array = (struct _NonClockInfoArray *)
5683 (mode_info->atom_context->bios + data_offset +
5684 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset));
5686 adev->pm.dpm.ps = kzalloc(sizeof(struct amdgpu_ps) *
5687 state_array->ucNumEntries, GFP_KERNEL);
5688 if (!adev->pm.dpm.ps)
5690 power_state_offset = (u8 *)state_array->states;
5691 for (i = 0; i < state_array->ucNumEntries; i++) {
5693 power_state = (union pplib_power_state *)power_state_offset;
5694 non_clock_array_index = power_state->v2.nonClockInfoIndex;
5695 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
5696 &non_clock_info_array->nonClockInfo[non_clock_array_index];
5697 ps = kzalloc(sizeof(struct ci_ps), GFP_KERNEL);
5699 kfree(adev->pm.dpm.ps);
5702 adev->pm.dpm.ps[i].ps_priv = ps;
5703 ci_parse_pplib_non_clock_info(adev, &adev->pm.dpm.ps[i],
5705 non_clock_info_array->ucEntrySize);
5707 idx = (u8 *)&power_state->v2.clockInfoIndex[0];
5708 for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
5709 clock_array_index = idx[j];
5710 if (clock_array_index >= clock_info_array->ucNumEntries)
5712 if (k >= CISLANDS_MAX_HARDWARE_POWERLEVELS)
5714 clock_info = (union pplib_clock_info *)
5715 ((u8 *)&clock_info_array->clockInfo[0] +
5716 (clock_array_index * clock_info_array->ucEntrySize));
5717 ci_parse_pplib_clock_info(adev,
5718 &adev->pm.dpm.ps[i], k,
5722 power_state_offset += 2 + power_state->v2.ucNumDPMLevels;
5724 adev->pm.dpm.num_ps = state_array->ucNumEntries;
5726 /* fill in the vce power states */
5727 for (i = 0; i < AMDGPU_MAX_VCE_LEVELS; i++) {
5729 clock_array_index = adev->pm.dpm.vce_states[i].clk_idx;
5730 clock_info = (union pplib_clock_info *)
5731 &clock_info_array->clockInfo[clock_array_index * clock_info_array->ucEntrySize];
5732 sclk = le16_to_cpu(clock_info->ci.usEngineClockLow);
5733 sclk |= clock_info->ci.ucEngineClockHigh << 16;
5734 mclk = le16_to_cpu(clock_info->ci.usMemoryClockLow);
5735 mclk |= clock_info->ci.ucMemoryClockHigh << 16;
5736 adev->pm.dpm.vce_states[i].sclk = sclk;
5737 adev->pm.dpm.vce_states[i].mclk = mclk;
5743 static int ci_get_vbios_boot_values(struct amdgpu_device *adev,
5744 struct ci_vbios_boot_state *boot_state)
5746 struct amdgpu_mode_info *mode_info = &adev->mode_info;
5747 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
5748 ATOM_FIRMWARE_INFO_V2_2 *firmware_info;
5752 if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
5753 &frev, &crev, &data_offset)) {
5755 (ATOM_FIRMWARE_INFO_V2_2 *)(mode_info->atom_context->bios +
5757 boot_state->mvdd_bootup_value = le16_to_cpu(firmware_info->usBootUpMVDDCVoltage);
5758 boot_state->vddc_bootup_value = le16_to_cpu(firmware_info->usBootUpVDDCVoltage);
5759 boot_state->vddci_bootup_value = le16_to_cpu(firmware_info->usBootUpVDDCIVoltage);
5760 boot_state->pcie_gen_bootup_value = ci_get_current_pcie_speed(adev);
5761 boot_state->pcie_lane_bootup_value = ci_get_current_pcie_lane_number(adev);
5762 boot_state->sclk_bootup_value = le32_to_cpu(firmware_info->ulDefaultEngineClock);
5763 boot_state->mclk_bootup_value = le32_to_cpu(firmware_info->ulDefaultMemoryClock);
5770 static void ci_dpm_fini(struct amdgpu_device *adev)
5774 for (i = 0; i < adev->pm.dpm.num_ps; i++) {
5775 kfree(adev->pm.dpm.ps[i].ps_priv);
5777 kfree(adev->pm.dpm.ps);
5778 kfree(adev->pm.dpm.priv);
5779 kfree(adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries);
5780 amdgpu_free_extended_power_table(adev);
5784 * ci_dpm_init_microcode - load ucode images from disk
5786 * @adev: amdgpu_device pointer
5788 * Use the firmware interface to load the ucode images into
5789 * the driver (not loaded into hw).
5790 * Returns 0 on success, error on failure.
5792 static int ci_dpm_init_microcode(struct amdgpu_device *adev)
5794 const char *chip_name;
5800 switch (adev->asic_type) {
5802 chip_name = "bonaire";
5805 chip_name = "hawaii";
5812 snprintf(fw_name, sizeof(fw_name), "radeon/%s_smc.bin", chip_name);
5813 err = request_firmware(&adev->pm.fw, fw_name, adev->dev);
5816 err = amdgpu_ucode_validate(adev->pm.fw);
5821 "cik_smc: Failed to load firmware \"%s\"\n",
5823 release_firmware(adev->pm.fw);
5829 static int ci_dpm_init(struct amdgpu_device *adev)
5831 int index = GetIndexIntoMasterTable(DATA, ASIC_InternalSS_Info);
5832 SMU7_Discrete_DpmTable *dpm_table;
5833 struct amdgpu_gpio_rec gpio;
5834 u16 data_offset, size;
5836 struct ci_power_info *pi;
5840 pi = kzalloc(sizeof(struct ci_power_info), GFP_KERNEL);
5843 adev->pm.dpm.priv = pi;
5845 ret = drm_pcie_get_speed_cap_mask(adev->ddev, &mask);
5847 pi->sys_pcie_mask = 0;
5849 pi->sys_pcie_mask = mask;
5850 pi->force_pcie_gen = AMDGPU_PCIE_GEN_INVALID;
5852 pi->pcie_gen_performance.max = AMDGPU_PCIE_GEN1;
5853 pi->pcie_gen_performance.min = AMDGPU_PCIE_GEN3;
5854 pi->pcie_gen_powersaving.max = AMDGPU_PCIE_GEN1;
5855 pi->pcie_gen_powersaving.min = AMDGPU_PCIE_GEN3;
5857 pi->pcie_lane_performance.max = 0;
5858 pi->pcie_lane_performance.min = 16;
5859 pi->pcie_lane_powersaving.max = 0;
5860 pi->pcie_lane_powersaving.min = 16;
5862 ret = ci_get_vbios_boot_values(adev, &pi->vbios_boot_state);
5868 ret = amdgpu_get_platform_caps(adev);
5874 ret = amdgpu_parse_extended_power_table(adev);
5880 ret = ci_parse_power_table(adev);
5886 pi->dll_default_on = false;
5887 pi->sram_end = SMC_RAM_END;
5889 pi->activity_target[0] = CISLAND_TARGETACTIVITY_DFLT;
5890 pi->activity_target[1] = CISLAND_TARGETACTIVITY_DFLT;
5891 pi->activity_target[2] = CISLAND_TARGETACTIVITY_DFLT;
5892 pi->activity_target[3] = CISLAND_TARGETACTIVITY_DFLT;
5893 pi->activity_target[4] = CISLAND_TARGETACTIVITY_DFLT;
5894 pi->activity_target[5] = CISLAND_TARGETACTIVITY_DFLT;
5895 pi->activity_target[6] = CISLAND_TARGETACTIVITY_DFLT;
5896 pi->activity_target[7] = CISLAND_TARGETACTIVITY_DFLT;
5898 pi->mclk_activity_target = CISLAND_MCLK_TARGETACTIVITY_DFLT;
5900 pi->sclk_dpm_key_disabled = 0;
5901 pi->mclk_dpm_key_disabled = 0;
5902 pi->pcie_dpm_key_disabled = 0;
5903 pi->thermal_sclk_dpm_enabled = 0;
5905 pi->caps_sclk_ds = true;
5907 pi->mclk_strobe_mode_threshold = 40000;
5908 pi->mclk_stutter_mode_threshold = 40000;
5909 pi->mclk_edc_enable_threshold = 40000;
5910 pi->mclk_edc_wr_enable_threshold = 40000;
5912 ci_initialize_powertune_defaults(adev);
5914 pi->caps_fps = false;
5916 pi->caps_sclk_throttle_low_notification = false;
5918 pi->caps_uvd_dpm = true;
5919 pi->caps_vce_dpm = true;
5921 ci_get_leakage_voltages(adev);
5922 ci_patch_dependency_tables_with_leakage(adev);
5923 ci_set_private_data_variables_based_on_pptable(adev);
5925 adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries =
5926 kzalloc(4 * sizeof(struct amdgpu_clock_voltage_dependency_entry), GFP_KERNEL);
5927 if (!adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries) {
5931 adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.count = 4;
5932 adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[0].clk = 0;
5933 adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[0].v = 0;
5934 adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[1].clk = 36000;
5935 adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[1].v = 720;
5936 adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[2].clk = 54000;
5937 adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[2].v = 810;
5938 adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[3].clk = 72000;
5939 adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[3].v = 900;
5941 adev->pm.dpm.dyn_state.mclk_sclk_ratio = 4;
5942 adev->pm.dpm.dyn_state.sclk_mclk_delta = 15000;
5943 adev->pm.dpm.dyn_state.vddc_vddci_delta = 200;
5945 adev->pm.dpm.dyn_state.valid_sclk_values.count = 0;
5946 adev->pm.dpm.dyn_state.valid_sclk_values.values = NULL;
5947 adev->pm.dpm.dyn_state.valid_mclk_values.count = 0;
5948 adev->pm.dpm.dyn_state.valid_mclk_values.values = NULL;
5950 if (adev->asic_type == CHIP_HAWAII) {
5951 pi->thermal_temp_setting.temperature_low = 94500;
5952 pi->thermal_temp_setting.temperature_high = 95000;
5953 pi->thermal_temp_setting.temperature_shutdown = 104000;
5955 pi->thermal_temp_setting.temperature_low = 99500;
5956 pi->thermal_temp_setting.temperature_high = 100000;
5957 pi->thermal_temp_setting.temperature_shutdown = 104000;
5960 pi->uvd_enabled = false;
5962 dpm_table = &pi->smc_state_table;
5964 gpio = amdgpu_atombios_lookup_gpio(adev, VDDC_VRHOT_GPIO_PINID);
5966 dpm_table->VRHotGpio = gpio.shift;
5967 adev->pm.dpm.platform_caps |= ATOM_PP_PLATFORM_CAP_REGULATOR_HOT;
5969 dpm_table->VRHotGpio = CISLANDS_UNUSED_GPIO_PIN;
5970 adev->pm.dpm.platform_caps &= ~ATOM_PP_PLATFORM_CAP_REGULATOR_HOT;
5973 gpio = amdgpu_atombios_lookup_gpio(adev, PP_AC_DC_SWITCH_GPIO_PINID);
5975 dpm_table->AcDcGpio = gpio.shift;
5976 adev->pm.dpm.platform_caps |= ATOM_PP_PLATFORM_CAP_HARDWAREDC;
5978 dpm_table->AcDcGpio = CISLANDS_UNUSED_GPIO_PIN;
5979 adev->pm.dpm.platform_caps &= ~ATOM_PP_PLATFORM_CAP_HARDWAREDC;
5982 gpio = amdgpu_atombios_lookup_gpio(adev, VDDC_PCC_GPIO_PINID);
5984 u32 tmp = RREG32_SMC(ixCNB_PWRMGT_CNTL);
5986 switch (gpio.shift) {
5988 tmp &= ~CNB_PWRMGT_CNTL__GNB_SLOW_MODE_MASK;
5989 tmp |= 1 << CNB_PWRMGT_CNTL__GNB_SLOW_MODE__SHIFT;
5992 tmp &= ~CNB_PWRMGT_CNTL__GNB_SLOW_MODE_MASK;
5993 tmp |= 2 << CNB_PWRMGT_CNTL__GNB_SLOW_MODE__SHIFT;
5996 tmp |= CNB_PWRMGT_CNTL__GNB_SLOW_MASK;
5999 tmp |= CNB_PWRMGT_CNTL__FORCE_NB_PS1_MASK;
6002 tmp |= CNB_PWRMGT_CNTL__DPM_ENABLED_MASK;
6005 DRM_ERROR("Invalid PCC GPIO: %u!\n", gpio.shift);
6008 WREG32_SMC(ixCNB_PWRMGT_CNTL, tmp);
6011 pi->voltage_control = CISLANDS_VOLTAGE_CONTROL_NONE;
6012 pi->vddci_control = CISLANDS_VOLTAGE_CONTROL_NONE;
6013 pi->mvdd_control = CISLANDS_VOLTAGE_CONTROL_NONE;
6014 if (amdgpu_atombios_is_voltage_gpio(adev, VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_GPIO_LUT))
6015 pi->voltage_control = CISLANDS_VOLTAGE_CONTROL_BY_GPIO;
6016 else if (amdgpu_atombios_is_voltage_gpio(adev, VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_SVID2))
6017 pi->voltage_control = CISLANDS_VOLTAGE_CONTROL_BY_SVID2;
6019 if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_VDDCI_CONTROL) {
6020 if (amdgpu_atombios_is_voltage_gpio(adev, VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT))
6021 pi->vddci_control = CISLANDS_VOLTAGE_CONTROL_BY_GPIO;
6022 else if (amdgpu_atombios_is_voltage_gpio(adev, VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_SVID2))
6023 pi->vddci_control = CISLANDS_VOLTAGE_CONTROL_BY_SVID2;
6025 adev->pm.dpm.platform_caps &= ~ATOM_PP_PLATFORM_CAP_VDDCI_CONTROL;
6028 if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_MVDDCONTROL) {
6029 if (amdgpu_atombios_is_voltage_gpio(adev, VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT))
6030 pi->mvdd_control = CISLANDS_VOLTAGE_CONTROL_BY_GPIO;
6031 else if (amdgpu_atombios_is_voltage_gpio(adev, VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_SVID2))
6032 pi->mvdd_control = CISLANDS_VOLTAGE_CONTROL_BY_SVID2;
6034 adev->pm.dpm.platform_caps &= ~ATOM_PP_PLATFORM_CAP_MVDDCONTROL;
6037 pi->vddc_phase_shed_control = true;
6039 #if defined(CONFIG_ACPI)
6040 pi->pcie_performance_request =
6041 amdgpu_acpi_is_pcie_performance_request_supported(adev);
6043 pi->pcie_performance_request = false;
6046 if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, &size,
6047 &frev, &crev, &data_offset)) {
6048 pi->caps_sclk_ss_support = true;
6049 pi->caps_mclk_ss_support = true;
6050 pi->dynamic_ss = true;
6052 pi->caps_sclk_ss_support = false;
6053 pi->caps_mclk_ss_support = false;
6054 pi->dynamic_ss = true;
6057 if (adev->pm.int_thermal_type != THERMAL_TYPE_NONE)
6058 pi->thermal_protection = true;
6060 pi->thermal_protection = false;
6062 pi->caps_dynamic_ac_timing = true;
6064 pi->uvd_power_gated = false;
6066 /* make sure dc limits are valid */
6067 if ((adev->pm.dpm.dyn_state.max_clock_voltage_on_dc.sclk == 0) ||
6068 (adev->pm.dpm.dyn_state.max_clock_voltage_on_dc.mclk == 0))
6069 adev->pm.dpm.dyn_state.max_clock_voltage_on_dc =
6070 adev->pm.dpm.dyn_state.max_clock_voltage_on_ac;
6072 pi->fan_ctrl_is_in_default_mode = true;
6078 ci_dpm_debugfs_print_current_performance_level(struct amdgpu_device *adev,
6081 struct ci_power_info *pi = ci_get_pi(adev);
6082 struct amdgpu_ps *rps = &pi->current_rps;
6083 u32 sclk = ci_get_average_sclk_freq(adev);
6084 u32 mclk = ci_get_average_mclk_freq(adev);
6085 u32 activity_percent = 50;
6088 ret = ci_read_smc_soft_register(adev, offsetof(SMU7_SoftRegisters, AverageGraphicsA),
6092 activity_percent += 0x80;
6093 activity_percent >>= 8;
6094 activity_percent = activity_percent > 100 ? 100 : activity_percent;
6097 seq_printf(m, "uvd %sabled\n", pi->uvd_enabled ? "en" : "dis");
6098 seq_printf(m, "vce %sabled\n", rps->vce_active ? "en" : "dis");
6099 seq_printf(m, "power level avg sclk: %u mclk: %u\n",
6101 seq_printf(m, "GPU load: %u %%\n", activity_percent);
6104 static void ci_dpm_print_power_state(struct amdgpu_device *adev,
6105 struct amdgpu_ps *rps)
6107 struct ci_ps *ps = ci_get_ps(rps);
6111 amdgpu_dpm_print_class_info(rps->class, rps->class2);
6112 amdgpu_dpm_print_cap_info(rps->caps);
6113 printk("\tuvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
6114 for (i = 0; i < ps->performance_level_count; i++) {
6115 pl = &ps->performance_levels[i];
6116 printk("\t\tpower level %d sclk: %u mclk: %u pcie gen: %u pcie lanes: %u\n",
6117 i, pl->sclk, pl->mclk, pl->pcie_gen + 1, pl->pcie_lane);
6119 amdgpu_dpm_print_ps_status(adev, rps);
6122 static u32 ci_dpm_get_sclk(struct amdgpu_device *adev, bool low)
6124 struct ci_power_info *pi = ci_get_pi(adev);
6125 struct ci_ps *requested_state = ci_get_ps(&pi->requested_rps);
6128 return requested_state->performance_levels[0].sclk;
6130 return requested_state->performance_levels[requested_state->performance_level_count - 1].sclk;
6133 static u32 ci_dpm_get_mclk(struct amdgpu_device *adev, bool low)
6135 struct ci_power_info *pi = ci_get_pi(adev);
6136 struct ci_ps *requested_state = ci_get_ps(&pi->requested_rps);
6139 return requested_state->performance_levels[0].mclk;
6141 return requested_state->performance_levels[requested_state->performance_level_count - 1].mclk;
6144 /* get temperature in millidegrees */
6145 static int ci_dpm_get_temp(struct amdgpu_device *adev)
6148 int actual_temp = 0;
6150 temp = (RREG32_SMC(ixCG_MULT_THERMAL_STATUS) & CG_MULT_THERMAL_STATUS__CTF_TEMP_MASK) >>
6151 CG_MULT_THERMAL_STATUS__CTF_TEMP__SHIFT;
6156 actual_temp = temp & 0x1ff;
6158 actual_temp = actual_temp * 1000;
6163 static int ci_set_temperature_range(struct amdgpu_device *adev)
6167 ret = ci_thermal_enable_alert(adev, false);
6170 ret = ci_thermal_set_temperature_range(adev, CISLANDS_TEMP_RANGE_MIN,
6171 CISLANDS_TEMP_RANGE_MAX);
6174 ret = ci_thermal_enable_alert(adev, true);
6180 static int ci_dpm_early_init(void *handle)
6182 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
6184 ci_dpm_set_dpm_funcs(adev);
6185 ci_dpm_set_irq_funcs(adev);
6190 static int ci_dpm_late_init(void *handle)
6193 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
6198 /* init the sysfs and debugfs files late */
6199 ret = amdgpu_pm_sysfs_init(adev);
6203 ret = ci_set_temperature_range(adev);
6207 ci_dpm_powergate_uvd(adev, true);
6212 static int ci_dpm_sw_init(void *handle)
6215 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
6217 ret = amdgpu_irq_add_id(adev, 230, &adev->pm.dpm.thermal.irq);
6221 ret = amdgpu_irq_add_id(adev, 231, &adev->pm.dpm.thermal.irq);
6225 /* default to balanced state */
6226 adev->pm.dpm.state = POWER_STATE_TYPE_BALANCED;
6227 adev->pm.dpm.user_state = POWER_STATE_TYPE_BALANCED;
6228 adev->pm.dpm.forced_level = AMDGPU_DPM_FORCED_LEVEL_AUTO;
6229 adev->pm.default_sclk = adev->clock.default_sclk;
6230 adev->pm.default_mclk = adev->clock.default_mclk;
6231 adev->pm.current_sclk = adev->clock.default_sclk;
6232 adev->pm.current_mclk = adev->clock.default_mclk;
6233 adev->pm.int_thermal_type = THERMAL_TYPE_NONE;
6235 if (amdgpu_dpm == 0)
6238 ret = ci_dpm_init_microcode(adev);
6242 INIT_WORK(&adev->pm.dpm.thermal.work, amdgpu_dpm_thermal_work_handler);
6243 mutex_lock(&adev->pm.mutex);
6244 ret = ci_dpm_init(adev);
6247 adev->pm.dpm.current_ps = adev->pm.dpm.requested_ps = adev->pm.dpm.boot_ps;
6248 if (amdgpu_dpm == 1)
6249 amdgpu_pm_print_power_states(adev);
6250 mutex_unlock(&adev->pm.mutex);
6251 DRM_INFO("amdgpu: dpm initialized\n");
6257 mutex_unlock(&adev->pm.mutex);
6258 DRM_ERROR("amdgpu: dpm initialization failed\n");
6262 static int ci_dpm_sw_fini(void *handle)
6264 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
6266 mutex_lock(&adev->pm.mutex);
6267 amdgpu_pm_sysfs_fini(adev);
6269 mutex_unlock(&adev->pm.mutex);
6274 static int ci_dpm_hw_init(void *handle)
6278 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
6283 mutex_lock(&adev->pm.mutex);
6284 ci_dpm_setup_asic(adev);
6285 ret = ci_dpm_enable(adev);
6287 adev->pm.dpm_enabled = false;
6289 adev->pm.dpm_enabled = true;
6290 mutex_unlock(&adev->pm.mutex);
6295 static int ci_dpm_hw_fini(void *handle)
6297 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
6299 if (adev->pm.dpm_enabled) {
6300 mutex_lock(&adev->pm.mutex);
6301 ci_dpm_disable(adev);
6302 mutex_unlock(&adev->pm.mutex);
6308 static int ci_dpm_suspend(void *handle)
6310 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
6312 if (adev->pm.dpm_enabled) {
6313 mutex_lock(&adev->pm.mutex);
6315 ci_dpm_disable(adev);
6316 /* reset the power state */
6317 adev->pm.dpm.current_ps = adev->pm.dpm.requested_ps = adev->pm.dpm.boot_ps;
6318 mutex_unlock(&adev->pm.mutex);
6323 static int ci_dpm_resume(void *handle)
6326 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
6328 if (adev->pm.dpm_enabled) {
6329 /* asic init will reset to the boot state */
6330 mutex_lock(&adev->pm.mutex);
6331 ci_dpm_setup_asic(adev);
6332 ret = ci_dpm_enable(adev);
6334 adev->pm.dpm_enabled = false;
6336 adev->pm.dpm_enabled = true;
6337 mutex_unlock(&adev->pm.mutex);
6338 if (adev->pm.dpm_enabled)
6339 amdgpu_pm_compute_clocks(adev);
6344 static bool ci_dpm_is_idle(void *handle)
6350 static int ci_dpm_wait_for_idle(void *handle)
6356 static void ci_dpm_print_status(void *handle)
6358 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
6360 dev_info(adev->dev, "CIK DPM registers\n");
6361 dev_info(adev->dev, " BIOS_SCRATCH_4=0x%08X\n",
6362 RREG32(mmBIOS_SCRATCH_4));
6363 dev_info(adev->dev, " MC_ARB_DRAM_TIMING=0x%08X\n",
6364 RREG32(mmMC_ARB_DRAM_TIMING));
6365 dev_info(adev->dev, " MC_ARB_DRAM_TIMING2=0x%08X\n",
6366 RREG32(mmMC_ARB_DRAM_TIMING2));
6367 dev_info(adev->dev, " MC_ARB_BURST_TIME=0x%08X\n",
6368 RREG32(mmMC_ARB_BURST_TIME));
6369 dev_info(adev->dev, " MC_ARB_DRAM_TIMING_1=0x%08X\n",
6370 RREG32(mmMC_ARB_DRAM_TIMING_1));
6371 dev_info(adev->dev, " MC_ARB_DRAM_TIMING2_1=0x%08X\n",
6372 RREG32(mmMC_ARB_DRAM_TIMING2_1));
6373 dev_info(adev->dev, " MC_CG_CONFIG=0x%08X\n",
6374 RREG32(mmMC_CG_CONFIG));
6375 dev_info(adev->dev, " MC_ARB_CG=0x%08X\n",
6376 RREG32(mmMC_ARB_CG));
6377 dev_info(adev->dev, " DIDT_SQ_CTRL0=0x%08X\n",
6378 RREG32_DIDT(ixDIDT_SQ_CTRL0));
6379 dev_info(adev->dev, " DIDT_DB_CTRL0=0x%08X\n",
6380 RREG32_DIDT(ixDIDT_DB_CTRL0));
6381 dev_info(adev->dev, " DIDT_TD_CTRL0=0x%08X\n",
6382 RREG32_DIDT(ixDIDT_TD_CTRL0));
6383 dev_info(adev->dev, " DIDT_TCP_CTRL0=0x%08X\n",
6384 RREG32_DIDT(ixDIDT_TCP_CTRL0));
6385 dev_info(adev->dev, " CG_THERMAL_INT=0x%08X\n",
6386 RREG32_SMC(ixCG_THERMAL_INT));
6387 dev_info(adev->dev, " CG_THERMAL_CTRL=0x%08X\n",
6388 RREG32_SMC(ixCG_THERMAL_CTRL));
6389 dev_info(adev->dev, " GENERAL_PWRMGT=0x%08X\n",
6390 RREG32_SMC(ixGENERAL_PWRMGT));
6391 dev_info(adev->dev, " MC_SEQ_CNTL_3=0x%08X\n",
6392 RREG32(mmMC_SEQ_CNTL_3));
6393 dev_info(adev->dev, " LCAC_MC0_CNTL=0x%08X\n",
6394 RREG32_SMC(ixLCAC_MC0_CNTL));
6395 dev_info(adev->dev, " LCAC_MC1_CNTL=0x%08X\n",
6396 RREG32_SMC(ixLCAC_MC1_CNTL));
6397 dev_info(adev->dev, " LCAC_CPL_CNTL=0x%08X\n",
6398 RREG32_SMC(ixLCAC_CPL_CNTL));
6399 dev_info(adev->dev, " SCLK_PWRMGT_CNTL=0x%08X\n",
6400 RREG32_SMC(ixSCLK_PWRMGT_CNTL));
6401 dev_info(adev->dev, " BIF_LNCNT_RESET=0x%08X\n",
6402 RREG32(mmBIF_LNCNT_RESET));
6403 dev_info(adev->dev, " FIRMWARE_FLAGS=0x%08X\n",
6404 RREG32_SMC(ixFIRMWARE_FLAGS));
6405 dev_info(adev->dev, " CG_SPLL_FUNC_CNTL=0x%08X\n",
6406 RREG32_SMC(ixCG_SPLL_FUNC_CNTL));
6407 dev_info(adev->dev, " CG_SPLL_FUNC_CNTL_2=0x%08X\n",
6408 RREG32_SMC(ixCG_SPLL_FUNC_CNTL_2));
6409 dev_info(adev->dev, " CG_SPLL_FUNC_CNTL_3=0x%08X\n",
6410 RREG32_SMC(ixCG_SPLL_FUNC_CNTL_3));
6411 dev_info(adev->dev, " CG_SPLL_FUNC_CNTL_4=0x%08X\n",
6412 RREG32_SMC(ixCG_SPLL_FUNC_CNTL_4));
6413 dev_info(adev->dev, " CG_SPLL_SPREAD_SPECTRUM=0x%08X\n",
6414 RREG32_SMC(ixCG_SPLL_SPREAD_SPECTRUM));
6415 dev_info(adev->dev, " CG_SPLL_SPREAD_SPECTRUM_2=0x%08X\n",
6416 RREG32_SMC(ixCG_SPLL_SPREAD_SPECTRUM_2));
6417 dev_info(adev->dev, " DLL_CNTL=0x%08X\n",
6418 RREG32(mmDLL_CNTL));
6419 dev_info(adev->dev, " MCLK_PWRMGT_CNTL=0x%08X\n",
6420 RREG32(mmMCLK_PWRMGT_CNTL));
6421 dev_info(adev->dev, " MPLL_AD_FUNC_CNTL=0x%08X\n",
6422 RREG32(mmMPLL_AD_FUNC_CNTL));
6423 dev_info(adev->dev, " MPLL_DQ_FUNC_CNTL=0x%08X\n",
6424 RREG32(mmMPLL_DQ_FUNC_CNTL));
6425 dev_info(adev->dev, " MPLL_FUNC_CNTL=0x%08X\n",
6426 RREG32(mmMPLL_FUNC_CNTL));
6427 dev_info(adev->dev, " MPLL_FUNC_CNTL_1=0x%08X\n",
6428 RREG32(mmMPLL_FUNC_CNTL_1));
6429 dev_info(adev->dev, " MPLL_FUNC_CNTL_2=0x%08X\n",
6430 RREG32(mmMPLL_FUNC_CNTL_2));
6431 dev_info(adev->dev, " MPLL_SS1=0x%08X\n",
6432 RREG32(mmMPLL_SS1));
6433 dev_info(adev->dev, " MPLL_SS2=0x%08X\n",
6434 RREG32(mmMPLL_SS2));
6435 dev_info(adev->dev, " CG_DISPLAY_GAP_CNTL=0x%08X\n",
6436 RREG32_SMC(ixCG_DISPLAY_GAP_CNTL));
6437 dev_info(adev->dev, " CG_DISPLAY_GAP_CNTL2=0x%08X\n",
6438 RREG32_SMC(ixCG_DISPLAY_GAP_CNTL2));
6439 dev_info(adev->dev, " CG_STATIC_SCREEN_PARAMETER=0x%08X\n",
6440 RREG32_SMC(ixCG_STATIC_SCREEN_PARAMETER));
6441 dev_info(adev->dev, " CG_FREQ_TRAN_VOTING_0=0x%08X\n",
6442 RREG32_SMC(ixCG_FREQ_TRAN_VOTING_0));
6443 dev_info(adev->dev, " CG_FREQ_TRAN_VOTING_1=0x%08X\n",
6444 RREG32_SMC(ixCG_FREQ_TRAN_VOTING_1));
6445 dev_info(adev->dev, " CG_FREQ_TRAN_VOTING_2=0x%08X\n",
6446 RREG32_SMC(ixCG_FREQ_TRAN_VOTING_2));
6447 dev_info(adev->dev, " CG_FREQ_TRAN_VOTING_3=0x%08X\n",
6448 RREG32_SMC(ixCG_FREQ_TRAN_VOTING_3));
6449 dev_info(adev->dev, " CG_FREQ_TRAN_VOTING_4=0x%08X\n",
6450 RREG32_SMC(ixCG_FREQ_TRAN_VOTING_4));
6451 dev_info(adev->dev, " CG_FREQ_TRAN_VOTING_5=0x%08X\n",
6452 RREG32_SMC(ixCG_FREQ_TRAN_VOTING_5));
6453 dev_info(adev->dev, " CG_FREQ_TRAN_VOTING_6=0x%08X\n",
6454 RREG32_SMC(ixCG_FREQ_TRAN_VOTING_6));
6455 dev_info(adev->dev, " CG_FREQ_TRAN_VOTING_7=0x%08X\n",
6456 RREG32_SMC(ixCG_FREQ_TRAN_VOTING_7));
6457 dev_info(adev->dev, " RCU_UC_EVENTS=0x%08X\n",
6458 RREG32_SMC(ixRCU_UC_EVENTS));
6459 dev_info(adev->dev, " DPM_TABLE_475=0x%08X\n",
6460 RREG32_SMC(ixDPM_TABLE_475));
6461 dev_info(adev->dev, " MC_SEQ_RAS_TIMING_LP=0x%08X\n",
6462 RREG32(mmMC_SEQ_RAS_TIMING_LP));
6463 dev_info(adev->dev, " MC_SEQ_RAS_TIMING=0x%08X\n",
6464 RREG32(mmMC_SEQ_RAS_TIMING));
6465 dev_info(adev->dev, " MC_SEQ_CAS_TIMING_LP=0x%08X\n",
6466 RREG32(mmMC_SEQ_CAS_TIMING_LP));
6467 dev_info(adev->dev, " MC_SEQ_CAS_TIMING=0x%08X\n",
6468 RREG32(mmMC_SEQ_CAS_TIMING));
6469 dev_info(adev->dev, " MC_SEQ_DLL_STBY_LP=0x%08X\n",
6470 RREG32(mmMC_SEQ_DLL_STBY_LP));
6471 dev_info(adev->dev, " MC_SEQ_DLL_STBY=0x%08X\n",
6472 RREG32(mmMC_SEQ_DLL_STBY));
6473 dev_info(adev->dev, " MC_SEQ_G5PDX_CMD0_LP=0x%08X\n",
6474 RREG32(mmMC_SEQ_G5PDX_CMD0_LP));
6475 dev_info(adev->dev, " MC_SEQ_G5PDX_CMD0=0x%08X\n",
6476 RREG32(mmMC_SEQ_G5PDX_CMD0));
6477 dev_info(adev->dev, " MC_SEQ_G5PDX_CMD1_LP=0x%08X\n",
6478 RREG32(mmMC_SEQ_G5PDX_CMD1_LP));
6479 dev_info(adev->dev, " MC_SEQ_G5PDX_CMD1=0x%08X\n",
6480 RREG32(mmMC_SEQ_G5PDX_CMD1));
6481 dev_info(adev->dev, " MC_SEQ_G5PDX_CTRL_LP=0x%08X\n",
6482 RREG32(mmMC_SEQ_G5PDX_CTRL_LP));
6483 dev_info(adev->dev, " MC_SEQ_G5PDX_CTRL=0x%08X\n",
6484 RREG32(mmMC_SEQ_G5PDX_CTRL));
6485 dev_info(adev->dev, " MC_SEQ_PMG_DVS_CMD_LP=0x%08X\n",
6486 RREG32(mmMC_SEQ_PMG_DVS_CMD_LP));
6487 dev_info(adev->dev, " MC_SEQ_PMG_DVS_CMD=0x%08X\n",
6488 RREG32(mmMC_SEQ_PMG_DVS_CMD));
6489 dev_info(adev->dev, " MC_SEQ_PMG_DVS_CTL_LP=0x%08X\n",
6490 RREG32(mmMC_SEQ_PMG_DVS_CTL_LP));
6491 dev_info(adev->dev, " MC_SEQ_PMG_DVS_CTL=0x%08X\n",
6492 RREG32(mmMC_SEQ_PMG_DVS_CTL));
6493 dev_info(adev->dev, " MC_SEQ_MISC_TIMING_LP=0x%08X\n",
6494 RREG32(mmMC_SEQ_MISC_TIMING_LP));
6495 dev_info(adev->dev, " MC_SEQ_MISC_TIMING=0x%08X\n",
6496 RREG32(mmMC_SEQ_MISC_TIMING));
6497 dev_info(adev->dev, " MC_SEQ_MISC_TIMING2_LP=0x%08X\n",
6498 RREG32(mmMC_SEQ_MISC_TIMING2_LP));
6499 dev_info(adev->dev, " MC_SEQ_MISC_TIMING2=0x%08X\n",
6500 RREG32(mmMC_SEQ_MISC_TIMING2));
6501 dev_info(adev->dev, " MC_SEQ_PMG_CMD_EMRS_LP=0x%08X\n",
6502 RREG32(mmMC_SEQ_PMG_CMD_EMRS_LP));
6503 dev_info(adev->dev, " MC_PMG_CMD_EMRS=0x%08X\n",
6504 RREG32(mmMC_PMG_CMD_EMRS));
6505 dev_info(adev->dev, " MC_SEQ_PMG_CMD_MRS_LP=0x%08X\n",
6506 RREG32(mmMC_SEQ_PMG_CMD_MRS_LP));
6507 dev_info(adev->dev, " MC_PMG_CMD_MRS=0x%08X\n",
6508 RREG32(mmMC_PMG_CMD_MRS));
6509 dev_info(adev->dev, " MC_SEQ_PMG_CMD_MRS1_LP=0x%08X\n",
6510 RREG32(mmMC_SEQ_PMG_CMD_MRS1_LP));
6511 dev_info(adev->dev, " MC_PMG_CMD_MRS1=0x%08X\n",
6512 RREG32(mmMC_PMG_CMD_MRS1));
6513 dev_info(adev->dev, " MC_SEQ_WR_CTL_D0_LP=0x%08X\n",
6514 RREG32(mmMC_SEQ_WR_CTL_D0_LP));
6515 dev_info(adev->dev, " MC_SEQ_WR_CTL_D0=0x%08X\n",
6516 RREG32(mmMC_SEQ_WR_CTL_D0));
6517 dev_info(adev->dev, " MC_SEQ_WR_CTL_D1_LP=0x%08X\n",
6518 RREG32(mmMC_SEQ_WR_CTL_D1_LP));
6519 dev_info(adev->dev, " MC_SEQ_WR_CTL_D1=0x%08X\n",
6520 RREG32(mmMC_SEQ_WR_CTL_D1));
6521 dev_info(adev->dev, " MC_SEQ_RD_CTL_D0_LP=0x%08X\n",
6522 RREG32(mmMC_SEQ_RD_CTL_D0_LP));
6523 dev_info(adev->dev, " MC_SEQ_RD_CTL_D0=0x%08X\n",
6524 RREG32(mmMC_SEQ_RD_CTL_D0));
6525 dev_info(adev->dev, " MC_SEQ_RD_CTL_D1_LP=0x%08X\n",
6526 RREG32(mmMC_SEQ_RD_CTL_D1_LP));
6527 dev_info(adev->dev, " MC_SEQ_RD_CTL_D1=0x%08X\n",
6528 RREG32(mmMC_SEQ_RD_CTL_D1));
6529 dev_info(adev->dev, " MC_SEQ_PMG_TIMING_LP=0x%08X\n",
6530 RREG32(mmMC_SEQ_PMG_TIMING_LP));
6531 dev_info(adev->dev, " MC_SEQ_PMG_TIMING=0x%08X\n",
6532 RREG32(mmMC_SEQ_PMG_TIMING));
6533 dev_info(adev->dev, " MC_SEQ_PMG_CMD_MRS2_LP=0x%08X\n",
6534 RREG32(mmMC_SEQ_PMG_CMD_MRS2_LP));
6535 dev_info(adev->dev, " MC_PMG_CMD_MRS2=0x%08X\n",
6536 RREG32(mmMC_PMG_CMD_MRS2));
6537 dev_info(adev->dev, " MC_SEQ_WR_CTL_2_LP=0x%08X\n",
6538 RREG32(mmMC_SEQ_WR_CTL_2_LP));
6539 dev_info(adev->dev, " MC_SEQ_WR_CTL_2=0x%08X\n",
6540 RREG32(mmMC_SEQ_WR_CTL_2));
6541 dev_info(adev->dev, " PCIE_LC_SPEED_CNTL=0x%08X\n",
6542 RREG32_PCIE(ixPCIE_LC_SPEED_CNTL));
6543 dev_info(adev->dev, " PCIE_LC_LINK_WIDTH_CNTL=0x%08X\n",
6544 RREG32_PCIE(ixPCIE_LC_LINK_WIDTH_CNTL));
6545 dev_info(adev->dev, " SMC_IND_INDEX_0=0x%08X\n",
6546 RREG32(mmSMC_IND_INDEX_0));
6547 dev_info(adev->dev, " SMC_IND_DATA_0=0x%08X\n",
6548 RREG32(mmSMC_IND_DATA_0));
6549 dev_info(adev->dev, " SMC_IND_ACCESS_CNTL=0x%08X\n",
6550 RREG32(mmSMC_IND_ACCESS_CNTL));
6551 dev_info(adev->dev, " SMC_RESP_0=0x%08X\n",
6552 RREG32(mmSMC_RESP_0));
6553 dev_info(adev->dev, " SMC_MESSAGE_0=0x%08X\n",
6554 RREG32(mmSMC_MESSAGE_0));
6555 dev_info(adev->dev, " SMC_SYSCON_RESET_CNTL=0x%08X\n",
6556 RREG32_SMC(ixSMC_SYSCON_RESET_CNTL));
6557 dev_info(adev->dev, " SMC_SYSCON_CLOCK_CNTL_0=0x%08X\n",
6558 RREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0));
6559 dev_info(adev->dev, " SMC_SYSCON_MISC_CNTL=0x%08X\n",
6560 RREG32_SMC(ixSMC_SYSCON_MISC_CNTL));
6561 dev_info(adev->dev, " SMC_PC_C=0x%08X\n",
6562 RREG32_SMC(ixSMC_PC_C));
6565 static int ci_dpm_soft_reset(void *handle)
6570 static int ci_dpm_set_interrupt_state(struct amdgpu_device *adev,
6571 struct amdgpu_irq_src *source,
6573 enum amdgpu_interrupt_state state)
6578 case AMDGPU_THERMAL_IRQ_LOW_TO_HIGH:
6580 case AMDGPU_IRQ_STATE_DISABLE:
6581 cg_thermal_int = RREG32_SMC(ixCG_THERMAL_INT);
6582 cg_thermal_int |= CG_THERMAL_INT_CTRL__THERM_INTH_MASK_MASK;
6583 WREG32_SMC(ixCG_THERMAL_INT, cg_thermal_int);
6585 case AMDGPU_IRQ_STATE_ENABLE:
6586 cg_thermal_int = RREG32_SMC(ixCG_THERMAL_INT);
6587 cg_thermal_int &= ~CG_THERMAL_INT_CTRL__THERM_INTH_MASK_MASK;
6588 WREG32_SMC(ixCG_THERMAL_INT, cg_thermal_int);
6595 case AMDGPU_THERMAL_IRQ_HIGH_TO_LOW:
6597 case AMDGPU_IRQ_STATE_DISABLE:
6598 cg_thermal_int = RREG32_SMC(ixCG_THERMAL_INT);
6599 cg_thermal_int |= CG_THERMAL_INT_CTRL__THERM_INTL_MASK_MASK;
6600 WREG32_SMC(ixCG_THERMAL_INT, cg_thermal_int);
6602 case AMDGPU_IRQ_STATE_ENABLE:
6603 cg_thermal_int = RREG32_SMC(ixCG_THERMAL_INT);
6604 cg_thermal_int &= ~CG_THERMAL_INT_CTRL__THERM_INTL_MASK_MASK;
6605 WREG32_SMC(ixCG_THERMAL_INT, cg_thermal_int);
6618 static int ci_dpm_process_interrupt(struct amdgpu_device *adev,
6619 struct amdgpu_irq_src *source,
6620 struct amdgpu_iv_entry *entry)
6622 bool queue_thermal = false;
6627 switch (entry->src_id) {
6628 case 230: /* thermal low to high */
6629 DRM_DEBUG("IH: thermal low to high\n");
6630 adev->pm.dpm.thermal.high_to_low = false;
6631 queue_thermal = true;
6633 case 231: /* thermal high to low */
6634 DRM_DEBUG("IH: thermal high to low\n");
6635 adev->pm.dpm.thermal.high_to_low = true;
6636 queue_thermal = true;
6643 schedule_work(&adev->pm.dpm.thermal.work);
6648 static int ci_dpm_set_clockgating_state(void *handle,
6649 enum amd_clockgating_state state)
6654 static int ci_dpm_set_powergating_state(void *handle,
6655 enum amd_powergating_state state)
6660 const struct amd_ip_funcs ci_dpm_ip_funcs = {
6661 .early_init = ci_dpm_early_init,
6662 .late_init = ci_dpm_late_init,
6663 .sw_init = ci_dpm_sw_init,
6664 .sw_fini = ci_dpm_sw_fini,
6665 .hw_init = ci_dpm_hw_init,
6666 .hw_fini = ci_dpm_hw_fini,
6667 .suspend = ci_dpm_suspend,
6668 .resume = ci_dpm_resume,
6669 .is_idle = ci_dpm_is_idle,
6670 .wait_for_idle = ci_dpm_wait_for_idle,
6671 .soft_reset = ci_dpm_soft_reset,
6672 .print_status = ci_dpm_print_status,
6673 .set_clockgating_state = ci_dpm_set_clockgating_state,
6674 .set_powergating_state = ci_dpm_set_powergating_state,
6677 static const struct amdgpu_dpm_funcs ci_dpm_funcs = {
6678 .get_temperature = &ci_dpm_get_temp,
6679 .pre_set_power_state = &ci_dpm_pre_set_power_state,
6680 .set_power_state = &ci_dpm_set_power_state,
6681 .post_set_power_state = &ci_dpm_post_set_power_state,
6682 .display_configuration_changed = &ci_dpm_display_configuration_changed,
6683 .get_sclk = &ci_dpm_get_sclk,
6684 .get_mclk = &ci_dpm_get_mclk,
6685 .print_power_state = &ci_dpm_print_power_state,
6686 .debugfs_print_current_performance_level = &ci_dpm_debugfs_print_current_performance_level,
6687 .force_performance_level = &ci_dpm_force_performance_level,
6688 .vblank_too_short = &ci_dpm_vblank_too_short,
6689 .powergate_uvd = &ci_dpm_powergate_uvd,
6690 .set_fan_control_mode = &ci_dpm_set_fan_control_mode,
6691 .get_fan_control_mode = &ci_dpm_get_fan_control_mode,
6692 .set_fan_speed_percent = &ci_dpm_set_fan_speed_percent,
6693 .get_fan_speed_percent = &ci_dpm_get_fan_speed_percent,
6696 static void ci_dpm_set_dpm_funcs(struct amdgpu_device *adev)
6698 if (adev->pm.funcs == NULL)
6699 adev->pm.funcs = &ci_dpm_funcs;
6702 static const struct amdgpu_irq_src_funcs ci_dpm_irq_funcs = {
6703 .set = ci_dpm_set_interrupt_state,
6704 .process = ci_dpm_process_interrupt,
6707 static void ci_dpm_set_irq_funcs(struct amdgpu_device *adev)
6709 adev->pm.dpm.thermal.irq.num_types = AMDGPU_THERMAL_IRQ_LAST;
6710 adev->pm.dpm.thermal.irq.funcs = &ci_dpm_irq_funcs;