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 "radeon_asic.h"
28 #include "radeon_ucode.h"
34 #include <linux/seq_file.h>
36 #define MC_CG_ARB_FREQ_F0 0x0a
37 #define MC_CG_ARB_FREQ_F1 0x0b
38 #define MC_CG_ARB_FREQ_F2 0x0c
39 #define MC_CG_ARB_FREQ_F3 0x0d
41 #define SMC_RAM_END 0x40000
43 #define VOLTAGE_SCALE 4
44 #define VOLTAGE_VID_OFFSET_SCALE1 625
45 #define VOLTAGE_VID_OFFSET_SCALE2 100
47 static const struct ci_pt_defaults defaults_hawaii_xt
=
49 1, 0xF, 0xFD, 0x19, 5, 0x14, 0, 0xB0000,
50 { 0x84, 0x0, 0x0, 0x7F, 0x0, 0x0, 0x5A, 0x60, 0x51, 0x8E, 0x79, 0x6B, 0x5F, 0x90, 0x79 },
51 { 0x1EA, 0x1EA, 0x1EA, 0x224, 0x224, 0x224, 0x24F, 0x24F, 0x24F, 0x28E, 0x28E, 0x28E, 0x2BC, 0x2BC, 0x2BC }
54 static const struct ci_pt_defaults defaults_hawaii_pro
=
56 1, 0xF, 0xFD, 0x19, 5, 0x14, 0, 0x65062,
57 { 0x93, 0x0, 0x0, 0x97, 0x0, 0x0, 0x6B, 0x60, 0x51, 0x95, 0x79, 0x6B, 0x5F, 0x90, 0x79 },
58 { 0x1EA, 0x1EA, 0x1EA, 0x224, 0x224, 0x224, 0x24F, 0x24F, 0x24F, 0x28E, 0x28E, 0x28E, 0x2BC, 0x2BC, 0x2BC }
61 static const struct ci_pt_defaults defaults_bonaire_xt
=
63 1, 0xF, 0xFD, 0x19, 5, 45, 0, 0xB0000,
64 { 0x79, 0x253, 0x25D, 0xAE, 0x72, 0x80, 0x83, 0x86, 0x6F, 0xC8, 0xC9, 0xC9, 0x2F, 0x4D, 0x61 },
65 { 0x17C, 0x172, 0x180, 0x1BC, 0x1B3, 0x1BD, 0x206, 0x200, 0x203, 0x25D, 0x25A, 0x255, 0x2C3, 0x2C5, 0x2B4 }
68 static const struct ci_pt_defaults defaults_bonaire_pro
=
70 1, 0xF, 0xFD, 0x19, 5, 45, 0, 0x65062,
71 { 0x8C, 0x23F, 0x244, 0xA6, 0x83, 0x85, 0x86, 0x86, 0x83, 0xDB, 0xDB, 0xDA, 0x67, 0x60, 0x5F },
72 { 0x187, 0x193, 0x193, 0x1C7, 0x1D1, 0x1D1, 0x210, 0x219, 0x219, 0x266, 0x26C, 0x26C, 0x2C9, 0x2CB, 0x2CB }
75 static const struct ci_pt_defaults defaults_saturn_xt
=
77 1, 0xF, 0xFD, 0x19, 5, 55, 0, 0x70000,
78 { 0x8C, 0x247, 0x249, 0xA6, 0x80, 0x81, 0x8B, 0x89, 0x86, 0xC9, 0xCA, 0xC9, 0x4D, 0x4D, 0x4D },
79 { 0x187, 0x187, 0x187, 0x1C7, 0x1C7, 0x1C7, 0x210, 0x210, 0x210, 0x266, 0x266, 0x266, 0x2C9, 0x2C9, 0x2C9 }
82 static const struct ci_pt_defaults defaults_saturn_pro
=
84 1, 0xF, 0xFD, 0x19, 5, 55, 0, 0x30000,
85 { 0x96, 0x21D, 0x23B, 0xA1, 0x85, 0x87, 0x83, 0x84, 0x81, 0xE6, 0xE6, 0xE6, 0x71, 0x6A, 0x6A },
86 { 0x193, 0x19E, 0x19E, 0x1D2, 0x1DC, 0x1DC, 0x21A, 0x223, 0x223, 0x26E, 0x27E, 0x274, 0x2CF, 0x2D2, 0x2D2 }
89 static const struct ci_pt_config_reg didt_config_ci
[] =
91 { 0x10, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
92 { 0x10, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
93 { 0x10, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
94 { 0x10, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
95 { 0x11, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
96 { 0x11, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
97 { 0x11, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
98 { 0x11, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
99 { 0x12, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
100 { 0x12, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
101 { 0x12, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
102 { 0x12, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
103 { 0x2, 0x00003fff, 0, 0x4, CISLANDS_CONFIGREG_DIDT_IND
},
104 { 0x2, 0x03ff0000, 16, 0x80, CISLANDS_CONFIGREG_DIDT_IND
},
105 { 0x2, 0x78000000, 27, 0x3, CISLANDS_CONFIGREG_DIDT_IND
},
106 { 0x1, 0x0000ffff, 0, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND
},
107 { 0x1, 0xffff0000, 16, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND
},
108 { 0x0, 0x00000001, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
109 { 0x30, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
110 { 0x30, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
111 { 0x30, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
112 { 0x30, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
113 { 0x31, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
114 { 0x31, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
115 { 0x31, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
116 { 0x31, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
117 { 0x32, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
118 { 0x32, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
119 { 0x32, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
120 { 0x32, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
121 { 0x22, 0x00003fff, 0, 0x4, CISLANDS_CONFIGREG_DIDT_IND
},
122 { 0x22, 0x03ff0000, 16, 0x80, CISLANDS_CONFIGREG_DIDT_IND
},
123 { 0x22, 0x78000000, 27, 0x3, CISLANDS_CONFIGREG_DIDT_IND
},
124 { 0x21, 0x0000ffff, 0, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND
},
125 { 0x21, 0xffff0000, 16, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND
},
126 { 0x20, 0x00000001, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
127 { 0x50, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
128 { 0x50, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
129 { 0x50, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
130 { 0x50, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
131 { 0x51, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
132 { 0x51, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
133 { 0x51, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
134 { 0x51, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
135 { 0x52, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
136 { 0x52, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
137 { 0x52, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
138 { 0x52, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
139 { 0x42, 0x00003fff, 0, 0x4, CISLANDS_CONFIGREG_DIDT_IND
},
140 { 0x42, 0x03ff0000, 16, 0x80, CISLANDS_CONFIGREG_DIDT_IND
},
141 { 0x42, 0x78000000, 27, 0x3, CISLANDS_CONFIGREG_DIDT_IND
},
142 { 0x41, 0x0000ffff, 0, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND
},
143 { 0x41, 0xffff0000, 16, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND
},
144 { 0x40, 0x00000001, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
145 { 0x70, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
146 { 0x70, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
147 { 0x70, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
148 { 0x70, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
149 { 0x71, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
150 { 0x71, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
151 { 0x71, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
152 { 0x71, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
153 { 0x72, 0x000000ff, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
154 { 0x72, 0x0000ff00, 8, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
155 { 0x72, 0x00ff0000, 16, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
156 { 0x72, 0xff000000, 24, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
157 { 0x62, 0x00003fff, 0, 0x4, CISLANDS_CONFIGREG_DIDT_IND
},
158 { 0x62, 0x03ff0000, 16, 0x80, CISLANDS_CONFIGREG_DIDT_IND
},
159 { 0x62, 0x78000000, 27, 0x3, CISLANDS_CONFIGREG_DIDT_IND
},
160 { 0x61, 0x0000ffff, 0, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND
},
161 { 0x61, 0xffff0000, 16, 0x3FFF, CISLANDS_CONFIGREG_DIDT_IND
},
162 { 0x60, 0x00000001, 0, 0x0, CISLANDS_CONFIGREG_DIDT_IND
},
166 static int ci_get_std_voltage_value_sidd(struct radeon_device
*rdev
,
167 struct atom_voltage_table_entry
*voltage_table
,
168 u16
*std_voltage_hi_sidd
, u16
*std_voltage_lo_sidd
);
169 static int ci_set_power_limit(struct radeon_device
*rdev
, u32 n
);
170 static int ci_set_overdrive_target_tdp(struct radeon_device
*rdev
,
172 static int ci_update_uvd_dpm(struct radeon_device
*rdev
, bool gate
);
174 static struct ci_power_info
*ci_get_pi(struct radeon_device
*rdev
)
176 struct ci_power_info
*pi
= rdev
->pm
.dpm
.priv
;
181 static struct ci_ps
*ci_get_ps(struct radeon_ps
*rps
)
183 struct ci_ps
*ps
= rps
->ps_priv
;
188 static void ci_initialize_powertune_defaults(struct radeon_device
*rdev
)
190 struct ci_power_info
*pi
= ci_get_pi(rdev
);
192 switch (rdev
->pdev
->device
) {
200 pi
->powertune_defaults
= &defaults_bonaire_xt
;
206 pi
->powertune_defaults
= &defaults_saturn_xt
;
210 pi
->powertune_defaults
= &defaults_hawaii_xt
;
214 pi
->powertune_defaults
= &defaults_hawaii_pro
;
224 pi
->powertune_defaults
= &defaults_bonaire_xt
;
228 pi
->dte_tj_offset
= 0;
230 pi
->caps_power_containment
= true;
231 pi
->caps_cac
= false;
232 pi
->caps_sq_ramping
= false;
233 pi
->caps_db_ramping
= false;
234 pi
->caps_td_ramping
= false;
235 pi
->caps_tcp_ramping
= false;
237 if (pi
->caps_power_containment
) {
239 pi
->enable_bapm_feature
= true;
240 pi
->enable_tdc_limit_feature
= true;
241 pi
->enable_pkg_pwr_tracking_feature
= true;
245 static u8
ci_convert_to_vid(u16 vddc
)
247 return (6200 - (vddc
* VOLTAGE_SCALE
)) / 25;
250 static int ci_populate_bapm_vddc_vid_sidd(struct radeon_device
*rdev
)
252 struct ci_power_info
*pi
= ci_get_pi(rdev
);
253 u8
*hi_vid
= pi
->smc_powertune_table
.BapmVddCVidHiSidd
;
254 u8
*lo_vid
= pi
->smc_powertune_table
.BapmVddCVidLoSidd
;
255 u8
*hi2_vid
= pi
->smc_powertune_table
.BapmVddCVidHiSidd2
;
258 if (rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.entries
== NULL
)
260 if (rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.count
> 8)
262 if (rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.count
!=
263 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
.count
)
266 for (i
= 0; i
< rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.count
; i
++) {
267 if (rdev
->pm
.dpm
.platform_caps
& ATOM_PP_PLATFORM_CAP_EVV
) {
268 lo_vid
[i
] = ci_convert_to_vid(rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.entries
[i
].vddc1
);
269 hi_vid
[i
] = ci_convert_to_vid(rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.entries
[i
].vddc2
);
270 hi2_vid
[i
] = ci_convert_to_vid(rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.entries
[i
].vddc3
);
272 lo_vid
[i
] = ci_convert_to_vid(rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.entries
[i
].vddc
);
273 hi_vid
[i
] = ci_convert_to_vid((u16
)rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.entries
[i
].leakage
);
279 static int ci_populate_vddc_vid(struct radeon_device
*rdev
)
281 struct ci_power_info
*pi
= ci_get_pi(rdev
);
282 u8
*vid
= pi
->smc_powertune_table
.VddCVid
;
285 if (pi
->vddc_voltage_table
.count
> 8)
288 for (i
= 0; i
< pi
->vddc_voltage_table
.count
; i
++)
289 vid
[i
] = ci_convert_to_vid(pi
->vddc_voltage_table
.entries
[i
].value
);
294 static int ci_populate_svi_load_line(struct radeon_device
*rdev
)
296 struct ci_power_info
*pi
= ci_get_pi(rdev
);
297 const struct ci_pt_defaults
*pt_defaults
= pi
->powertune_defaults
;
299 pi
->smc_powertune_table
.SviLoadLineEn
= pt_defaults
->svi_load_line_en
;
300 pi
->smc_powertune_table
.SviLoadLineVddC
= pt_defaults
->svi_load_line_vddc
;
301 pi
->smc_powertune_table
.SviLoadLineTrimVddC
= 3;
302 pi
->smc_powertune_table
.SviLoadLineOffsetVddC
= 0;
307 static int ci_populate_tdc_limit(struct radeon_device
*rdev
)
309 struct ci_power_info
*pi
= ci_get_pi(rdev
);
310 const struct ci_pt_defaults
*pt_defaults
= pi
->powertune_defaults
;
313 tdc_limit
= rdev
->pm
.dpm
.dyn_state
.cac_tdp_table
->tdc
* 256;
314 pi
->smc_powertune_table
.TDC_VDDC_PkgLimit
= cpu_to_be16(tdc_limit
);
315 pi
->smc_powertune_table
.TDC_VDDC_ThrottleReleaseLimitPerc
=
316 pt_defaults
->tdc_vddc_throttle_release_limit_perc
;
317 pi
->smc_powertune_table
.TDC_MAWt
= pt_defaults
->tdc_mawt
;
322 static int ci_populate_dw8(struct radeon_device
*rdev
)
324 struct ci_power_info
*pi
= ci_get_pi(rdev
);
325 const struct ci_pt_defaults
*pt_defaults
= pi
->powertune_defaults
;
328 ret
= ci_read_smc_sram_dword(rdev
,
329 SMU7_FIRMWARE_HEADER_LOCATION
+
330 offsetof(SMU7_Firmware_Header
, PmFuseTable
) +
331 offsetof(SMU7_Discrete_PmFuses
, TdcWaterfallCtl
),
332 (u32
*)&pi
->smc_powertune_table
.TdcWaterfallCtl
,
337 pi
->smc_powertune_table
.TdcWaterfallCtl
= pt_defaults
->tdc_waterfall_ctl
;
342 static int ci_min_max_v_gnbl_pm_lid_from_bapm_vddc(struct radeon_device
*rdev
)
344 struct ci_power_info
*pi
= ci_get_pi(rdev
);
345 u8
*hi_vid
= pi
->smc_powertune_table
.BapmVddCVidHiSidd
;
346 u8
*lo_vid
= pi
->smc_powertune_table
.BapmVddCVidLoSidd
;
349 min
= max
= hi_vid
[0];
350 for (i
= 0; i
< 8; i
++) {
351 if (0 != hi_vid
[i
]) {
358 if (0 != lo_vid
[i
]) {
366 if ((min
== 0) || (max
== 0))
368 pi
->smc_powertune_table
.GnbLPMLMaxVid
= (u8
)max
;
369 pi
->smc_powertune_table
.GnbLPMLMinVid
= (u8
)min
;
374 static int ci_populate_bapm_vddc_base_leakage_sidd(struct radeon_device
*rdev
)
376 struct ci_power_info
*pi
= ci_get_pi(rdev
);
377 u16 hi_sidd
= pi
->smc_powertune_table
.BapmVddCBaseLeakageHiSidd
;
378 u16 lo_sidd
= pi
->smc_powertune_table
.BapmVddCBaseLeakageLoSidd
;
379 struct radeon_cac_tdp_table
*cac_tdp_table
=
380 rdev
->pm
.dpm
.dyn_state
.cac_tdp_table
;
382 hi_sidd
= cac_tdp_table
->high_cac_leakage
/ 100 * 256;
383 lo_sidd
= cac_tdp_table
->low_cac_leakage
/ 100 * 256;
385 pi
->smc_powertune_table
.BapmVddCBaseLeakageHiSidd
= cpu_to_be16(hi_sidd
);
386 pi
->smc_powertune_table
.BapmVddCBaseLeakageLoSidd
= cpu_to_be16(lo_sidd
);
391 static int ci_populate_bapm_parameters_in_dpm_table(struct radeon_device
*rdev
)
393 struct ci_power_info
*pi
= ci_get_pi(rdev
);
394 const struct ci_pt_defaults
*pt_defaults
= pi
->powertune_defaults
;
395 SMU7_Discrete_DpmTable
*dpm_table
= &pi
->smc_state_table
;
396 struct radeon_cac_tdp_table
*cac_tdp_table
=
397 rdev
->pm
.dpm
.dyn_state
.cac_tdp_table
;
398 struct radeon_ppm_table
*ppm
= rdev
->pm
.dpm
.dyn_state
.ppm_table
;
403 dpm_table
->DefaultTdp
= cac_tdp_table
->tdp
* 256;
404 dpm_table
->TargetTdp
= cac_tdp_table
->configurable_tdp
* 256;
406 dpm_table
->DTETjOffset
= (u8
)pi
->dte_tj_offset
;
407 dpm_table
->GpuTjMax
=
408 (u8
)(pi
->thermal_temp_setting
.temperature_high
/ 1000);
409 dpm_table
->GpuTjHyst
= 8;
411 dpm_table
->DTEAmbientTempBase
= pt_defaults
->dte_ambient_temp_base
;
414 dpm_table
->PPM_PkgPwrLimit
= cpu_to_be16((u16
)ppm
->dgpu_tdp
* 256 / 1000);
415 dpm_table
->PPM_TemperatureLimit
= cpu_to_be16((u16
)ppm
->tj_max
* 256);
417 dpm_table
->PPM_PkgPwrLimit
= cpu_to_be16(0);
418 dpm_table
->PPM_TemperatureLimit
= cpu_to_be16(0);
421 dpm_table
->BAPM_TEMP_GRADIENT
= cpu_to_be32(pt_defaults
->bapm_temp_gradient
);
422 def1
= pt_defaults
->bapmti_r
;
423 def2
= pt_defaults
->bapmti_rc
;
425 for (i
= 0; i
< SMU7_DTE_ITERATIONS
; i
++) {
426 for (j
= 0; j
< SMU7_DTE_SOURCES
; j
++) {
427 for (k
= 0; k
< SMU7_DTE_SINKS
; k
++) {
428 dpm_table
->BAPMTI_R
[i
][j
][k
] = cpu_to_be16(*def1
);
429 dpm_table
->BAPMTI_RC
[i
][j
][k
] = cpu_to_be16(*def2
);
439 static int ci_populate_pm_base(struct radeon_device
*rdev
)
441 struct ci_power_info
*pi
= ci_get_pi(rdev
);
442 u32 pm_fuse_table_offset
;
445 if (pi
->caps_power_containment
) {
446 ret
= ci_read_smc_sram_dword(rdev
,
447 SMU7_FIRMWARE_HEADER_LOCATION
+
448 offsetof(SMU7_Firmware_Header
, PmFuseTable
),
449 &pm_fuse_table_offset
, pi
->sram_end
);
452 ret
= ci_populate_bapm_vddc_vid_sidd(rdev
);
455 ret
= ci_populate_vddc_vid(rdev
);
458 ret
= ci_populate_svi_load_line(rdev
);
461 ret
= ci_populate_tdc_limit(rdev
);
464 ret
= ci_populate_dw8(rdev
);
467 ret
= ci_min_max_v_gnbl_pm_lid_from_bapm_vddc(rdev
);
470 ret
= ci_populate_bapm_vddc_base_leakage_sidd(rdev
);
473 ret
= ci_copy_bytes_to_smc(rdev
, pm_fuse_table_offset
,
474 (u8
*)&pi
->smc_powertune_table
,
475 sizeof(SMU7_Discrete_PmFuses
), pi
->sram_end
);
483 static void ci_do_enable_didt(struct radeon_device
*rdev
, const bool enable
)
485 struct ci_power_info
*pi
= ci_get_pi(rdev
);
488 if (pi
->caps_sq_ramping
) {
489 data
= RREG32_DIDT(DIDT_SQ_CTRL0
);
491 data
|= DIDT_CTRL_EN
;
493 data
&= ~DIDT_CTRL_EN
;
494 WREG32_DIDT(DIDT_SQ_CTRL0
, data
);
497 if (pi
->caps_db_ramping
) {
498 data
= RREG32_DIDT(DIDT_DB_CTRL0
);
500 data
|= DIDT_CTRL_EN
;
502 data
&= ~DIDT_CTRL_EN
;
503 WREG32_DIDT(DIDT_DB_CTRL0
, data
);
506 if (pi
->caps_td_ramping
) {
507 data
= RREG32_DIDT(DIDT_TD_CTRL0
);
509 data
|= DIDT_CTRL_EN
;
511 data
&= ~DIDT_CTRL_EN
;
512 WREG32_DIDT(DIDT_TD_CTRL0
, data
);
515 if (pi
->caps_tcp_ramping
) {
516 data
= RREG32_DIDT(DIDT_TCP_CTRL0
);
518 data
|= DIDT_CTRL_EN
;
520 data
&= ~DIDT_CTRL_EN
;
521 WREG32_DIDT(DIDT_TCP_CTRL0
, data
);
525 static int ci_program_pt_config_registers(struct radeon_device
*rdev
,
526 const struct ci_pt_config_reg
*cac_config_regs
)
528 const struct ci_pt_config_reg
*config_regs
= cac_config_regs
;
532 if (config_regs
== NULL
)
535 while (config_regs
->offset
!= 0xFFFFFFFF) {
536 if (config_regs
->type
== CISLANDS_CONFIGREG_CACHE
) {
537 cache
|= ((config_regs
->value
<< config_regs
->shift
) & config_regs
->mask
);
539 switch (config_regs
->type
) {
540 case CISLANDS_CONFIGREG_SMC_IND
:
541 data
= RREG32_SMC(config_regs
->offset
);
543 case CISLANDS_CONFIGREG_DIDT_IND
:
544 data
= RREG32_DIDT(config_regs
->offset
);
547 data
= RREG32(config_regs
->offset
<< 2);
551 data
&= ~config_regs
->mask
;
552 data
|= ((config_regs
->value
<< config_regs
->shift
) & config_regs
->mask
);
555 switch (config_regs
->type
) {
556 case CISLANDS_CONFIGREG_SMC_IND
:
557 WREG32_SMC(config_regs
->offset
, data
);
559 case CISLANDS_CONFIGREG_DIDT_IND
:
560 WREG32_DIDT(config_regs
->offset
, data
);
563 WREG32(config_regs
->offset
<< 2, data
);
573 static int ci_enable_didt(struct radeon_device
*rdev
, bool enable
)
575 struct ci_power_info
*pi
= ci_get_pi(rdev
);
578 if (pi
->caps_sq_ramping
|| pi
->caps_db_ramping
||
579 pi
->caps_td_ramping
|| pi
->caps_tcp_ramping
) {
580 cik_enter_rlc_safe_mode(rdev
);
583 ret
= ci_program_pt_config_registers(rdev
, didt_config_ci
);
585 cik_exit_rlc_safe_mode(rdev
);
590 ci_do_enable_didt(rdev
, enable
);
592 cik_exit_rlc_safe_mode(rdev
);
598 static int ci_enable_power_containment(struct radeon_device
*rdev
, bool enable
)
600 struct ci_power_info
*pi
= ci_get_pi(rdev
);
601 PPSMC_Result smc_result
;
605 pi
->power_containment_features
= 0;
606 if (pi
->caps_power_containment
) {
607 if (pi
->enable_bapm_feature
) {
608 smc_result
= ci_send_msg_to_smc(rdev
, PPSMC_MSG_EnableDTE
);
609 if (smc_result
!= PPSMC_Result_OK
)
612 pi
->power_containment_features
|= POWERCONTAINMENT_FEATURE_BAPM
;
615 if (pi
->enable_tdc_limit_feature
) {
616 smc_result
= ci_send_msg_to_smc(rdev
, PPSMC_MSG_TDCLimitEnable
);
617 if (smc_result
!= PPSMC_Result_OK
)
620 pi
->power_containment_features
|= POWERCONTAINMENT_FEATURE_TDCLimit
;
623 if (pi
->enable_pkg_pwr_tracking_feature
) {
624 smc_result
= ci_send_msg_to_smc(rdev
, PPSMC_MSG_PkgPwrLimitEnable
);
625 if (smc_result
!= PPSMC_Result_OK
) {
628 struct radeon_cac_tdp_table
*cac_tdp_table
=
629 rdev
->pm
.dpm
.dyn_state
.cac_tdp_table
;
630 u32 default_pwr_limit
=
631 (u32
)(cac_tdp_table
->maximum_power_delivery_limit
* 256);
633 pi
->power_containment_features
|= POWERCONTAINMENT_FEATURE_PkgPwrLimit
;
635 ci_set_power_limit(rdev
, default_pwr_limit
);
640 if (pi
->caps_power_containment
&& pi
->power_containment_features
) {
641 if (pi
->power_containment_features
& POWERCONTAINMENT_FEATURE_TDCLimit
)
642 ci_send_msg_to_smc(rdev
, PPSMC_MSG_TDCLimitDisable
);
644 if (pi
->power_containment_features
& POWERCONTAINMENT_FEATURE_BAPM
)
645 ci_send_msg_to_smc(rdev
, PPSMC_MSG_DisableDTE
);
647 if (pi
->power_containment_features
& POWERCONTAINMENT_FEATURE_PkgPwrLimit
)
648 ci_send_msg_to_smc(rdev
, PPSMC_MSG_PkgPwrLimitDisable
);
649 pi
->power_containment_features
= 0;
656 static int ci_enable_smc_cac(struct radeon_device
*rdev
, bool enable
)
658 struct ci_power_info
*pi
= ci_get_pi(rdev
);
659 PPSMC_Result smc_result
;
664 smc_result
= ci_send_msg_to_smc(rdev
, PPSMC_MSG_EnableCac
);
665 if (smc_result
!= PPSMC_Result_OK
) {
667 pi
->cac_enabled
= false;
669 pi
->cac_enabled
= true;
671 } else if (pi
->cac_enabled
) {
672 ci_send_msg_to_smc(rdev
, PPSMC_MSG_DisableCac
);
673 pi
->cac_enabled
= false;
680 static int ci_power_control_set_level(struct radeon_device
*rdev
)
682 struct ci_power_info
*pi
= ci_get_pi(rdev
);
683 struct radeon_cac_tdp_table
*cac_tdp_table
=
684 rdev
->pm
.dpm
.dyn_state
.cac_tdp_table
;
688 bool adjust_polarity
= false; /* ??? */
690 if (pi
->caps_power_containment
&&
691 (pi
->power_containment_features
& POWERCONTAINMENT_FEATURE_BAPM
)) {
692 adjust_percent
= adjust_polarity
?
693 rdev
->pm
.dpm
.tdp_adjustment
: (-1 * rdev
->pm
.dpm
.tdp_adjustment
);
694 target_tdp
= ((100 + adjust_percent
) *
695 (s32
)cac_tdp_table
->configurable_tdp
) / 100;
698 ret
= ci_set_overdrive_target_tdp(rdev
, (u32
)target_tdp
);
704 void ci_dpm_powergate_uvd(struct radeon_device
*rdev
, bool gate
)
706 struct ci_power_info
*pi
= ci_get_pi(rdev
);
708 if (pi
->uvd_power_gated
== gate
)
711 pi
->uvd_power_gated
= gate
;
713 ci_update_uvd_dpm(rdev
, gate
);
716 bool ci_dpm_vblank_too_short(struct radeon_device
*rdev
)
718 struct ci_power_info
*pi
= ci_get_pi(rdev
);
719 u32 vblank_time
= r600_dpm_get_vblank_time(rdev
);
720 u32 switch_limit
= pi
->mem_gddr5
? 450 : 300;
722 if (vblank_time
< switch_limit
)
729 static void ci_apply_state_adjust_rules(struct radeon_device
*rdev
,
730 struct radeon_ps
*rps
)
732 struct ci_ps
*ps
= ci_get_ps(rps
);
733 struct ci_power_info
*pi
= ci_get_pi(rdev
);
734 struct radeon_clock_and_voltage_limits
*max_limits
;
735 bool disable_mclk_switching
;
739 if (rps
->vce_active
) {
740 rps
->evclk
= rdev
->pm
.dpm
.vce_states
[rdev
->pm
.dpm
.vce_level
].evclk
;
741 rps
->ecclk
= rdev
->pm
.dpm
.vce_states
[rdev
->pm
.dpm
.vce_level
].ecclk
;
747 if ((rdev
->pm
.dpm
.new_active_crtc_count
> 1) ||
748 ci_dpm_vblank_too_short(rdev
))
749 disable_mclk_switching
= true;
751 disable_mclk_switching
= false;
753 if ((rps
->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK
) == ATOM_PPLIB_CLASSIFICATION_UI_BATTERY
)
754 pi
->battery_state
= true;
756 pi
->battery_state
= false;
758 if (rdev
->pm
.dpm
.ac_power
)
759 max_limits
= &rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
;
761 max_limits
= &rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_dc
;
763 if (rdev
->pm
.dpm
.ac_power
== false) {
764 for (i
= 0; i
< ps
->performance_level_count
; i
++) {
765 if (ps
->performance_levels
[i
].mclk
> max_limits
->mclk
)
766 ps
->performance_levels
[i
].mclk
= max_limits
->mclk
;
767 if (ps
->performance_levels
[i
].sclk
> max_limits
->sclk
)
768 ps
->performance_levels
[i
].sclk
= max_limits
->sclk
;
772 /* XXX validate the min clocks required for display */
774 if (disable_mclk_switching
) {
775 mclk
= ps
->performance_levels
[ps
->performance_level_count
- 1].mclk
;
776 sclk
= ps
->performance_levels
[0].sclk
;
778 mclk
= ps
->performance_levels
[0].mclk
;
779 sclk
= ps
->performance_levels
[0].sclk
;
782 if (rps
->vce_active
) {
783 if (sclk
< rdev
->pm
.dpm
.vce_states
[rdev
->pm
.dpm
.vce_level
].sclk
)
784 sclk
= rdev
->pm
.dpm
.vce_states
[rdev
->pm
.dpm
.vce_level
].sclk
;
785 if (mclk
< rdev
->pm
.dpm
.vce_states
[rdev
->pm
.dpm
.vce_level
].mclk
)
786 mclk
= rdev
->pm
.dpm
.vce_states
[rdev
->pm
.dpm
.vce_level
].mclk
;
789 ps
->performance_levels
[0].sclk
= sclk
;
790 ps
->performance_levels
[0].mclk
= mclk
;
792 if (ps
->performance_levels
[1].sclk
< ps
->performance_levels
[0].sclk
)
793 ps
->performance_levels
[1].sclk
= ps
->performance_levels
[0].sclk
;
795 if (disable_mclk_switching
) {
796 if (ps
->performance_levels
[0].mclk
< ps
->performance_levels
[1].mclk
)
797 ps
->performance_levels
[0].mclk
= ps
->performance_levels
[1].mclk
;
799 if (ps
->performance_levels
[1].mclk
< ps
->performance_levels
[0].mclk
)
800 ps
->performance_levels
[1].mclk
= ps
->performance_levels
[0].mclk
;
804 static int ci_set_thermal_temperature_range(struct radeon_device
*rdev
,
805 int min_temp
, int max_temp
)
807 int low_temp
= 0 * 1000;
808 int high_temp
= 255 * 1000;
811 if (low_temp
< min_temp
)
813 if (high_temp
> max_temp
)
814 high_temp
= max_temp
;
815 if (high_temp
< low_temp
) {
816 DRM_ERROR("invalid thermal range: %d - %d\n", low_temp
, high_temp
);
820 tmp
= RREG32_SMC(CG_THERMAL_INT
);
821 tmp
&= ~(CI_DIG_THERM_INTH_MASK
| CI_DIG_THERM_INTL_MASK
);
822 tmp
|= CI_DIG_THERM_INTH(high_temp
/ 1000) |
823 CI_DIG_THERM_INTL(low_temp
/ 1000);
824 WREG32_SMC(CG_THERMAL_INT
, tmp
);
827 /* XXX: need to figure out how to handle this properly */
828 tmp
= RREG32_SMC(CG_THERMAL_CTRL
);
829 tmp
&= DIG_THERM_DPM_MASK
;
830 tmp
|= DIG_THERM_DPM(high_temp
/ 1000);
831 WREG32_SMC(CG_THERMAL_CTRL
, tmp
);
834 rdev
->pm
.dpm
.thermal
.min_temp
= low_temp
;
835 rdev
->pm
.dpm
.thermal
.max_temp
= high_temp
;
841 static int ci_read_smc_soft_register(struct radeon_device
*rdev
,
842 u16 reg_offset
, u32
*value
)
844 struct ci_power_info
*pi
= ci_get_pi(rdev
);
846 return ci_read_smc_sram_dword(rdev
,
847 pi
->soft_regs_start
+ reg_offset
,
848 value
, pi
->sram_end
);
852 static int ci_write_smc_soft_register(struct radeon_device
*rdev
,
853 u16 reg_offset
, u32 value
)
855 struct ci_power_info
*pi
= ci_get_pi(rdev
);
857 return ci_write_smc_sram_dword(rdev
,
858 pi
->soft_regs_start
+ reg_offset
,
859 value
, pi
->sram_end
);
862 static void ci_init_fps_limits(struct radeon_device
*rdev
)
864 struct ci_power_info
*pi
= ci_get_pi(rdev
);
865 SMU7_Discrete_DpmTable
*table
= &pi
->smc_state_table
;
871 table
->FpsHighT
= cpu_to_be16(tmp
);
874 table
->FpsLowT
= cpu_to_be16(tmp
);
878 static int ci_update_sclk_t(struct radeon_device
*rdev
)
880 struct ci_power_info
*pi
= ci_get_pi(rdev
);
882 u32 low_sclk_interrupt_t
= 0;
884 if (pi
->caps_sclk_throttle_low_notification
) {
885 low_sclk_interrupt_t
= cpu_to_be32(pi
->low_sclk_interrupt_t
);
887 ret
= ci_copy_bytes_to_smc(rdev
,
888 pi
->dpm_table_start
+
889 offsetof(SMU7_Discrete_DpmTable
, LowSclkInterruptT
),
890 (u8
*)&low_sclk_interrupt_t
,
891 sizeof(u32
), pi
->sram_end
);
898 static void ci_get_leakage_voltages(struct radeon_device
*rdev
)
900 struct ci_power_info
*pi
= ci_get_pi(rdev
);
901 u16 leakage_id
, virtual_voltage_id
;
905 pi
->vddc_leakage
.count
= 0;
906 pi
->vddci_leakage
.count
= 0;
908 if (rdev
->pm
.dpm
.platform_caps
& ATOM_PP_PLATFORM_CAP_EVV
) {
909 for (i
= 0; i
< CISLANDS_MAX_LEAKAGE_COUNT
; i
++) {
910 virtual_voltage_id
= ATOM_VIRTUAL_VOLTAGE_ID0
+ i
;
911 if (radeon_atom_get_voltage_evv(rdev
, virtual_voltage_id
, &vddc
) != 0)
913 if (vddc
!= 0 && vddc
!= virtual_voltage_id
) {
914 pi
->vddc_leakage
.actual_voltage
[pi
->vddc_leakage
.count
] = vddc
;
915 pi
->vddc_leakage
.leakage_id
[pi
->vddc_leakage
.count
] = virtual_voltage_id
;
916 pi
->vddc_leakage
.count
++;
919 } else if (radeon_atom_get_leakage_id_from_vbios(rdev
, &leakage_id
) == 0) {
920 for (i
= 0; i
< CISLANDS_MAX_LEAKAGE_COUNT
; i
++) {
921 virtual_voltage_id
= ATOM_VIRTUAL_VOLTAGE_ID0
+ i
;
922 if (radeon_atom_get_leakage_vddc_based_on_leakage_params(rdev
, &vddc
, &vddci
,
925 if (vddc
!= 0 && vddc
!= virtual_voltage_id
) {
926 pi
->vddc_leakage
.actual_voltage
[pi
->vddc_leakage
.count
] = vddc
;
927 pi
->vddc_leakage
.leakage_id
[pi
->vddc_leakage
.count
] = virtual_voltage_id
;
928 pi
->vddc_leakage
.count
++;
930 if (vddci
!= 0 && vddci
!= virtual_voltage_id
) {
931 pi
->vddci_leakage
.actual_voltage
[pi
->vddci_leakage
.count
] = vddci
;
932 pi
->vddci_leakage
.leakage_id
[pi
->vddci_leakage
.count
] = virtual_voltage_id
;
933 pi
->vddci_leakage
.count
++;
940 static void ci_set_dpm_event_sources(struct radeon_device
*rdev
, u32 sources
)
942 struct ci_power_info
*pi
= ci_get_pi(rdev
);
943 bool want_thermal_protection
;
944 enum radeon_dpm_event_src dpm_event_src
;
950 want_thermal_protection
= false;
952 case (1 << RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL
):
953 want_thermal_protection
= true;
954 dpm_event_src
= RADEON_DPM_EVENT_SRC_DIGITAL
;
956 case (1 << RADEON_DPM_AUTO_THROTTLE_SRC_EXTERNAL
):
957 want_thermal_protection
= true;
958 dpm_event_src
= RADEON_DPM_EVENT_SRC_EXTERNAL
;
960 case ((1 << RADEON_DPM_AUTO_THROTTLE_SRC_EXTERNAL
) |
961 (1 << RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL
)):
962 want_thermal_protection
= true;
963 dpm_event_src
= RADEON_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL
;
967 if (want_thermal_protection
) {
969 /* XXX: need to figure out how to handle this properly */
970 tmp
= RREG32_SMC(CG_THERMAL_CTRL
);
971 tmp
&= DPM_EVENT_SRC_MASK
;
972 tmp
|= DPM_EVENT_SRC(dpm_event_src
);
973 WREG32_SMC(CG_THERMAL_CTRL
, tmp
);
976 tmp
= RREG32_SMC(GENERAL_PWRMGT
);
977 if (pi
->thermal_protection
)
978 tmp
&= ~THERMAL_PROTECTION_DIS
;
980 tmp
|= THERMAL_PROTECTION_DIS
;
981 WREG32_SMC(GENERAL_PWRMGT
, tmp
);
983 tmp
= RREG32_SMC(GENERAL_PWRMGT
);
984 tmp
|= THERMAL_PROTECTION_DIS
;
985 WREG32_SMC(GENERAL_PWRMGT
, tmp
);
989 static void ci_enable_auto_throttle_source(struct radeon_device
*rdev
,
990 enum radeon_dpm_auto_throttle_src source
,
993 struct ci_power_info
*pi
= ci_get_pi(rdev
);
996 if (!(pi
->active_auto_throttle_sources
& (1 << source
))) {
997 pi
->active_auto_throttle_sources
|= 1 << source
;
998 ci_set_dpm_event_sources(rdev
, pi
->active_auto_throttle_sources
);
1001 if (pi
->active_auto_throttle_sources
& (1 << source
)) {
1002 pi
->active_auto_throttle_sources
&= ~(1 << source
);
1003 ci_set_dpm_event_sources(rdev
, pi
->active_auto_throttle_sources
);
1008 static void ci_enable_vr_hot_gpio_interrupt(struct radeon_device
*rdev
)
1010 if (rdev
->pm
.dpm
.platform_caps
& ATOM_PP_PLATFORM_CAP_REGULATOR_HOT
)
1011 ci_send_msg_to_smc(rdev
, PPSMC_MSG_EnableVRHotGPIOInterrupt
);
1014 static int ci_unfreeze_sclk_mclk_dpm(struct radeon_device
*rdev
)
1016 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1017 PPSMC_Result smc_result
;
1019 if (!pi
->need_update_smu7_dpm_table
)
1022 if ((!pi
->sclk_dpm_key_disabled
) &&
1023 (pi
->need_update_smu7_dpm_table
& (DPMTABLE_OD_UPDATE_SCLK
| DPMTABLE_UPDATE_SCLK
))) {
1024 smc_result
= ci_send_msg_to_smc(rdev
, PPSMC_MSG_SCLKDPM_UnfreezeLevel
);
1025 if (smc_result
!= PPSMC_Result_OK
)
1029 if ((!pi
->mclk_dpm_key_disabled
) &&
1030 (pi
->need_update_smu7_dpm_table
& DPMTABLE_OD_UPDATE_MCLK
)) {
1031 smc_result
= ci_send_msg_to_smc(rdev
, PPSMC_MSG_MCLKDPM_UnfreezeLevel
);
1032 if (smc_result
!= PPSMC_Result_OK
)
1036 pi
->need_update_smu7_dpm_table
= 0;
1040 static int ci_enable_sclk_mclk_dpm(struct radeon_device
*rdev
, bool enable
)
1042 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1043 PPSMC_Result smc_result
;
1046 if (!pi
->sclk_dpm_key_disabled
) {
1047 smc_result
= ci_send_msg_to_smc(rdev
, PPSMC_MSG_DPM_Enable
);
1048 if (smc_result
!= PPSMC_Result_OK
)
1052 if (!pi
->mclk_dpm_key_disabled
) {
1053 smc_result
= ci_send_msg_to_smc(rdev
, PPSMC_MSG_MCLKDPM_Enable
);
1054 if (smc_result
!= PPSMC_Result_OK
)
1057 WREG32_P(MC_SEQ_CNTL_3
, CAC_EN
, ~CAC_EN
);
1059 WREG32_SMC(LCAC_MC0_CNTL
, 0x05);
1060 WREG32_SMC(LCAC_MC1_CNTL
, 0x05);
1061 WREG32_SMC(LCAC_CPL_CNTL
, 0x100005);
1065 WREG32_SMC(LCAC_MC0_CNTL
, 0x400005);
1066 WREG32_SMC(LCAC_MC1_CNTL
, 0x400005);
1067 WREG32_SMC(LCAC_CPL_CNTL
, 0x500005);
1070 if (!pi
->sclk_dpm_key_disabled
) {
1071 smc_result
= ci_send_msg_to_smc(rdev
, PPSMC_MSG_DPM_Disable
);
1072 if (smc_result
!= PPSMC_Result_OK
)
1076 if (!pi
->mclk_dpm_key_disabled
) {
1077 smc_result
= ci_send_msg_to_smc(rdev
, PPSMC_MSG_MCLKDPM_Disable
);
1078 if (smc_result
!= PPSMC_Result_OK
)
1086 static int ci_start_dpm(struct radeon_device
*rdev
)
1088 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1089 PPSMC_Result smc_result
;
1093 tmp
= RREG32_SMC(GENERAL_PWRMGT
);
1094 tmp
|= GLOBAL_PWRMGT_EN
;
1095 WREG32_SMC(GENERAL_PWRMGT
, tmp
);
1097 tmp
= RREG32_SMC(SCLK_PWRMGT_CNTL
);
1098 tmp
|= DYNAMIC_PM_EN
;
1099 WREG32_SMC(SCLK_PWRMGT_CNTL
, tmp
);
1101 ci_write_smc_soft_register(rdev
, offsetof(SMU7_SoftRegisters
, VoltageChangeTimeout
), 0x1000);
1103 WREG32_P(BIF_LNCNT_RESET
, 0, ~RESET_LNCNT_EN
);
1105 smc_result
= ci_send_msg_to_smc(rdev
, PPSMC_MSG_Voltage_Cntl_Enable
);
1106 if (smc_result
!= PPSMC_Result_OK
)
1109 ret
= ci_enable_sclk_mclk_dpm(rdev
, true);
1113 if (!pi
->pcie_dpm_key_disabled
) {
1114 smc_result
= ci_send_msg_to_smc(rdev
, PPSMC_MSG_PCIeDPM_Enable
);
1115 if (smc_result
!= PPSMC_Result_OK
)
1122 static int ci_freeze_sclk_mclk_dpm(struct radeon_device
*rdev
)
1124 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1125 PPSMC_Result smc_result
;
1127 if (!pi
->need_update_smu7_dpm_table
)
1130 if ((!pi
->sclk_dpm_key_disabled
) &&
1131 (pi
->need_update_smu7_dpm_table
& (DPMTABLE_OD_UPDATE_SCLK
| DPMTABLE_UPDATE_SCLK
))) {
1132 smc_result
= ci_send_msg_to_smc(rdev
, PPSMC_MSG_SCLKDPM_FreezeLevel
);
1133 if (smc_result
!= PPSMC_Result_OK
)
1137 if ((!pi
->mclk_dpm_key_disabled
) &&
1138 (pi
->need_update_smu7_dpm_table
& DPMTABLE_OD_UPDATE_MCLK
)) {
1139 smc_result
= ci_send_msg_to_smc(rdev
, PPSMC_MSG_MCLKDPM_FreezeLevel
);
1140 if (smc_result
!= PPSMC_Result_OK
)
1147 static int ci_stop_dpm(struct radeon_device
*rdev
)
1149 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1150 PPSMC_Result smc_result
;
1154 tmp
= RREG32_SMC(GENERAL_PWRMGT
);
1155 tmp
&= ~GLOBAL_PWRMGT_EN
;
1156 WREG32_SMC(GENERAL_PWRMGT
, tmp
);
1158 tmp
= RREG32_SMC(SCLK_PWRMGT_CNTL
);
1159 tmp
&= ~DYNAMIC_PM_EN
;
1160 WREG32_SMC(SCLK_PWRMGT_CNTL
, tmp
);
1162 if (!pi
->pcie_dpm_key_disabled
) {
1163 smc_result
= ci_send_msg_to_smc(rdev
, PPSMC_MSG_PCIeDPM_Disable
);
1164 if (smc_result
!= PPSMC_Result_OK
)
1168 ret
= ci_enable_sclk_mclk_dpm(rdev
, false);
1172 smc_result
= ci_send_msg_to_smc(rdev
, PPSMC_MSG_Voltage_Cntl_Disable
);
1173 if (smc_result
!= PPSMC_Result_OK
)
1179 static void ci_enable_sclk_control(struct radeon_device
*rdev
, bool enable
)
1181 u32 tmp
= RREG32_SMC(SCLK_PWRMGT_CNTL
);
1184 tmp
&= ~SCLK_PWRMGT_OFF
;
1186 tmp
|= SCLK_PWRMGT_OFF
;
1187 WREG32_SMC(SCLK_PWRMGT_CNTL
, tmp
);
1191 static int ci_notify_hw_of_power_source(struct radeon_device
*rdev
,
1194 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1195 struct radeon_cac_tdp_table
*cac_tdp_table
=
1196 rdev
->pm
.dpm
.dyn_state
.cac_tdp_table
;
1200 power_limit
= (u32
)(cac_tdp_table
->maximum_power_delivery_limit
* 256);
1202 power_limit
= (u32
)(cac_tdp_table
->battery_power_limit
* 256);
1204 ci_set_power_limit(rdev
, power_limit
);
1206 if (pi
->caps_automatic_dc_transition
) {
1208 ci_send_msg_to_smc(rdev
, PPSMC_MSG_RunningOnAC
);
1210 ci_send_msg_to_smc(rdev
, PPSMC_MSG_Remove_DC_Clamp
);
1217 static PPSMC_Result
ci_send_msg_to_smc_with_parameter(struct radeon_device
*rdev
,
1218 PPSMC_Msg msg
, u32 parameter
)
1220 WREG32(SMC_MSG_ARG_0
, parameter
);
1221 return ci_send_msg_to_smc(rdev
, msg
);
1224 static PPSMC_Result
ci_send_msg_to_smc_return_parameter(struct radeon_device
*rdev
,
1225 PPSMC_Msg msg
, u32
*parameter
)
1227 PPSMC_Result smc_result
;
1229 smc_result
= ci_send_msg_to_smc(rdev
, msg
);
1231 if ((smc_result
== PPSMC_Result_OK
) && parameter
)
1232 *parameter
= RREG32(SMC_MSG_ARG_0
);
1237 static int ci_dpm_force_state_sclk(struct radeon_device
*rdev
, u32 n
)
1239 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1241 if (!pi
->sclk_dpm_key_disabled
) {
1242 PPSMC_Result smc_result
=
1243 ci_send_msg_to_smc_with_parameter(rdev
, PPSMC_MSG_DPM_ForceState
, n
);
1244 if (smc_result
!= PPSMC_Result_OK
)
1251 static int ci_dpm_force_state_mclk(struct radeon_device
*rdev
, u32 n
)
1253 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1255 if (!pi
->mclk_dpm_key_disabled
) {
1256 PPSMC_Result smc_result
=
1257 ci_send_msg_to_smc_with_parameter(rdev
, PPSMC_MSG_MCLKDPM_ForceState
, n
);
1258 if (smc_result
!= PPSMC_Result_OK
)
1265 static int ci_dpm_force_state_pcie(struct radeon_device
*rdev
, u32 n
)
1267 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1269 if (!pi
->pcie_dpm_key_disabled
) {
1270 PPSMC_Result smc_result
=
1271 ci_send_msg_to_smc_with_parameter(rdev
, PPSMC_MSG_PCIeDPM_ForceLevel
, n
);
1272 if (smc_result
!= PPSMC_Result_OK
)
1279 static int ci_set_power_limit(struct radeon_device
*rdev
, u32 n
)
1281 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1283 if (pi
->power_containment_features
& POWERCONTAINMENT_FEATURE_PkgPwrLimit
) {
1284 PPSMC_Result smc_result
=
1285 ci_send_msg_to_smc_with_parameter(rdev
, PPSMC_MSG_PkgPwrSetLimit
, n
);
1286 if (smc_result
!= PPSMC_Result_OK
)
1293 static int ci_set_overdrive_target_tdp(struct radeon_device
*rdev
,
1296 PPSMC_Result smc_result
=
1297 ci_send_msg_to_smc_with_parameter(rdev
, PPSMC_MSG_OverDriveSetTargetTdp
, target_tdp
);
1298 if (smc_result
!= PPSMC_Result_OK
)
1304 static int ci_set_boot_state(struct radeon_device
*rdev
)
1306 return ci_enable_sclk_mclk_dpm(rdev
, false);
1310 static u32
ci_get_average_sclk_freq(struct radeon_device
*rdev
)
1313 PPSMC_Result smc_result
=
1314 ci_send_msg_to_smc_return_parameter(rdev
,
1315 PPSMC_MSG_API_GetSclkFrequency
,
1317 if (smc_result
!= PPSMC_Result_OK
)
1323 static u32
ci_get_average_mclk_freq(struct radeon_device
*rdev
)
1326 PPSMC_Result smc_result
=
1327 ci_send_msg_to_smc_return_parameter(rdev
,
1328 PPSMC_MSG_API_GetMclkFrequency
,
1330 if (smc_result
!= PPSMC_Result_OK
)
1336 static void ci_dpm_start_smc(struct radeon_device
*rdev
)
1340 ci_program_jump_on_start(rdev
);
1341 ci_start_smc_clock(rdev
);
1343 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
1344 if (RREG32_SMC(FIRMWARE_FLAGS
) & INTERRUPTS_ENABLED
)
1349 static void ci_dpm_stop_smc(struct radeon_device
*rdev
)
1352 ci_stop_smc_clock(rdev
);
1355 static int ci_process_firmware_header(struct radeon_device
*rdev
)
1357 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1361 ret
= ci_read_smc_sram_dword(rdev
,
1362 SMU7_FIRMWARE_HEADER_LOCATION
+
1363 offsetof(SMU7_Firmware_Header
, DpmTable
),
1364 &tmp
, pi
->sram_end
);
1368 pi
->dpm_table_start
= tmp
;
1370 ret
= ci_read_smc_sram_dword(rdev
,
1371 SMU7_FIRMWARE_HEADER_LOCATION
+
1372 offsetof(SMU7_Firmware_Header
, SoftRegisters
),
1373 &tmp
, pi
->sram_end
);
1377 pi
->soft_regs_start
= tmp
;
1379 ret
= ci_read_smc_sram_dword(rdev
,
1380 SMU7_FIRMWARE_HEADER_LOCATION
+
1381 offsetof(SMU7_Firmware_Header
, mcRegisterTable
),
1382 &tmp
, pi
->sram_end
);
1386 pi
->mc_reg_table_start
= tmp
;
1388 ret
= ci_read_smc_sram_dword(rdev
,
1389 SMU7_FIRMWARE_HEADER_LOCATION
+
1390 offsetof(SMU7_Firmware_Header
, FanTable
),
1391 &tmp
, pi
->sram_end
);
1395 pi
->fan_table_start
= tmp
;
1397 ret
= ci_read_smc_sram_dword(rdev
,
1398 SMU7_FIRMWARE_HEADER_LOCATION
+
1399 offsetof(SMU7_Firmware_Header
, mcArbDramTimingTable
),
1400 &tmp
, pi
->sram_end
);
1404 pi
->arb_table_start
= tmp
;
1409 static void ci_read_clock_registers(struct radeon_device
*rdev
)
1411 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1413 pi
->clock_registers
.cg_spll_func_cntl
=
1414 RREG32_SMC(CG_SPLL_FUNC_CNTL
);
1415 pi
->clock_registers
.cg_spll_func_cntl_2
=
1416 RREG32_SMC(CG_SPLL_FUNC_CNTL_2
);
1417 pi
->clock_registers
.cg_spll_func_cntl_3
=
1418 RREG32_SMC(CG_SPLL_FUNC_CNTL_3
);
1419 pi
->clock_registers
.cg_spll_func_cntl_4
=
1420 RREG32_SMC(CG_SPLL_FUNC_CNTL_4
);
1421 pi
->clock_registers
.cg_spll_spread_spectrum
=
1422 RREG32_SMC(CG_SPLL_SPREAD_SPECTRUM
);
1423 pi
->clock_registers
.cg_spll_spread_spectrum_2
=
1424 RREG32_SMC(CG_SPLL_SPREAD_SPECTRUM_2
);
1425 pi
->clock_registers
.dll_cntl
= RREG32(DLL_CNTL
);
1426 pi
->clock_registers
.mclk_pwrmgt_cntl
= RREG32(MCLK_PWRMGT_CNTL
);
1427 pi
->clock_registers
.mpll_ad_func_cntl
= RREG32(MPLL_AD_FUNC_CNTL
);
1428 pi
->clock_registers
.mpll_dq_func_cntl
= RREG32(MPLL_DQ_FUNC_CNTL
);
1429 pi
->clock_registers
.mpll_func_cntl
= RREG32(MPLL_FUNC_CNTL
);
1430 pi
->clock_registers
.mpll_func_cntl_1
= RREG32(MPLL_FUNC_CNTL_1
);
1431 pi
->clock_registers
.mpll_func_cntl_2
= RREG32(MPLL_FUNC_CNTL_2
);
1432 pi
->clock_registers
.mpll_ss1
= RREG32(MPLL_SS1
);
1433 pi
->clock_registers
.mpll_ss2
= RREG32(MPLL_SS2
);
1436 static void ci_init_sclk_t(struct radeon_device
*rdev
)
1438 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1440 pi
->low_sclk_interrupt_t
= 0;
1443 static void ci_enable_thermal_protection(struct radeon_device
*rdev
,
1446 u32 tmp
= RREG32_SMC(GENERAL_PWRMGT
);
1449 tmp
&= ~THERMAL_PROTECTION_DIS
;
1451 tmp
|= THERMAL_PROTECTION_DIS
;
1452 WREG32_SMC(GENERAL_PWRMGT
, tmp
);
1455 static void ci_enable_acpi_power_management(struct radeon_device
*rdev
)
1457 u32 tmp
= RREG32_SMC(GENERAL_PWRMGT
);
1459 tmp
|= STATIC_PM_EN
;
1461 WREG32_SMC(GENERAL_PWRMGT
, tmp
);
1465 static int ci_enter_ulp_state(struct radeon_device
*rdev
)
1468 WREG32(SMC_MESSAGE_0
, PPSMC_MSG_SwitchToMinimumPower
);
1475 static int ci_exit_ulp_state(struct radeon_device
*rdev
)
1479 WREG32(SMC_MESSAGE_0
, PPSMC_MSG_ResumeFromMinimumPower
);
1483 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
1484 if (RREG32(SMC_RESP_0
) == 1)
1493 static int ci_notify_smc_display_change(struct radeon_device
*rdev
,
1496 PPSMC_Msg msg
= has_display
? PPSMC_MSG_HasDisplay
: PPSMC_MSG_NoDisplay
;
1498 return (ci_send_msg_to_smc(rdev
, msg
) == PPSMC_Result_OK
) ? 0 : -EINVAL
;
1501 static int ci_enable_ds_master_switch(struct radeon_device
*rdev
,
1504 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1507 if (pi
->caps_sclk_ds
) {
1508 if (ci_send_msg_to_smc(rdev
, PPSMC_MSG_MASTER_DeepSleep_ON
) != PPSMC_Result_OK
)
1511 if (ci_send_msg_to_smc(rdev
, PPSMC_MSG_MASTER_DeepSleep_OFF
) != PPSMC_Result_OK
)
1515 if (pi
->caps_sclk_ds
) {
1516 if (ci_send_msg_to_smc(rdev
, PPSMC_MSG_MASTER_DeepSleep_OFF
) != PPSMC_Result_OK
)
1524 static void ci_program_display_gap(struct radeon_device
*rdev
)
1526 u32 tmp
= RREG32_SMC(CG_DISPLAY_GAP_CNTL
);
1527 u32 pre_vbi_time_in_us
;
1528 u32 frame_time_in_us
;
1529 u32 ref_clock
= rdev
->clock
.spll
.reference_freq
;
1530 u32 refresh_rate
= r600_dpm_get_vrefresh(rdev
);
1531 u32 vblank_time
= r600_dpm_get_vblank_time(rdev
);
1533 tmp
&= ~DISP_GAP_MASK
;
1534 if (rdev
->pm
.dpm
.new_active_crtc_count
> 0)
1535 tmp
|= DISP_GAP(R600_PM_DISPLAY_GAP_VBLANK_OR_WM
);
1537 tmp
|= DISP_GAP(R600_PM_DISPLAY_GAP_IGNORE
);
1538 WREG32_SMC(CG_DISPLAY_GAP_CNTL
, tmp
);
1540 if (refresh_rate
== 0)
1542 if (vblank_time
== 0xffffffff)
1544 frame_time_in_us
= 1000000 / refresh_rate
;
1545 pre_vbi_time_in_us
=
1546 frame_time_in_us
- 200 - vblank_time
;
1547 tmp
= pre_vbi_time_in_us
* (ref_clock
/ 100);
1549 WREG32_SMC(CG_DISPLAY_GAP_CNTL2
, tmp
);
1550 ci_write_smc_soft_register(rdev
, offsetof(SMU7_SoftRegisters
, PreVBlankGap
), 0x64);
1551 ci_write_smc_soft_register(rdev
, offsetof(SMU7_SoftRegisters
, VBlankTimeout
), (frame_time_in_us
- pre_vbi_time_in_us
));
1554 ci_notify_smc_display_change(rdev
, (rdev
->pm
.dpm
.new_active_crtc_count
== 1));
1558 static void ci_enable_spread_spectrum(struct radeon_device
*rdev
, bool enable
)
1560 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1564 if (pi
->caps_sclk_ss_support
) {
1565 tmp
= RREG32_SMC(GENERAL_PWRMGT
);
1566 tmp
|= DYN_SPREAD_SPECTRUM_EN
;
1567 WREG32_SMC(GENERAL_PWRMGT
, tmp
);
1570 tmp
= RREG32_SMC(CG_SPLL_SPREAD_SPECTRUM
);
1572 WREG32_SMC(CG_SPLL_SPREAD_SPECTRUM
, tmp
);
1574 tmp
= RREG32_SMC(GENERAL_PWRMGT
);
1575 tmp
&= ~DYN_SPREAD_SPECTRUM_EN
;
1576 WREG32_SMC(GENERAL_PWRMGT
, tmp
);
1580 static void ci_program_sstp(struct radeon_device
*rdev
)
1582 WREG32_SMC(CG_SSP
, (SSTU(R600_SSTU_DFLT
) | SST(R600_SST_DFLT
)));
1585 static void ci_enable_display_gap(struct radeon_device
*rdev
)
1587 u32 tmp
= RREG32_SMC(CG_DISPLAY_GAP_CNTL
);
1589 tmp
&= ~(DISP_GAP_MASK
| DISP_GAP_MCHG_MASK
);
1590 tmp
|= (DISP_GAP(R600_PM_DISPLAY_GAP_IGNORE
) |
1591 DISP_GAP_MCHG(R600_PM_DISPLAY_GAP_VBLANK
));
1593 WREG32_SMC(CG_DISPLAY_GAP_CNTL
, tmp
);
1596 static void ci_program_vc(struct radeon_device
*rdev
)
1600 tmp
= RREG32_SMC(SCLK_PWRMGT_CNTL
);
1601 tmp
&= ~(RESET_SCLK_CNT
| RESET_BUSY_CNT
);
1602 WREG32_SMC(SCLK_PWRMGT_CNTL
, tmp
);
1604 WREG32_SMC(CG_FTV_0
, CISLANDS_VRC_DFLT0
);
1605 WREG32_SMC(CG_FTV_1
, CISLANDS_VRC_DFLT1
);
1606 WREG32_SMC(CG_FTV_2
, CISLANDS_VRC_DFLT2
);
1607 WREG32_SMC(CG_FTV_3
, CISLANDS_VRC_DFLT3
);
1608 WREG32_SMC(CG_FTV_4
, CISLANDS_VRC_DFLT4
);
1609 WREG32_SMC(CG_FTV_5
, CISLANDS_VRC_DFLT5
);
1610 WREG32_SMC(CG_FTV_6
, CISLANDS_VRC_DFLT6
);
1611 WREG32_SMC(CG_FTV_7
, CISLANDS_VRC_DFLT7
);
1614 static void ci_clear_vc(struct radeon_device
*rdev
)
1618 tmp
= RREG32_SMC(SCLK_PWRMGT_CNTL
);
1619 tmp
|= (RESET_SCLK_CNT
| RESET_BUSY_CNT
);
1620 WREG32_SMC(SCLK_PWRMGT_CNTL
, tmp
);
1622 WREG32_SMC(CG_FTV_0
, 0);
1623 WREG32_SMC(CG_FTV_1
, 0);
1624 WREG32_SMC(CG_FTV_2
, 0);
1625 WREG32_SMC(CG_FTV_3
, 0);
1626 WREG32_SMC(CG_FTV_4
, 0);
1627 WREG32_SMC(CG_FTV_5
, 0);
1628 WREG32_SMC(CG_FTV_6
, 0);
1629 WREG32_SMC(CG_FTV_7
, 0);
1632 static int ci_upload_firmware(struct radeon_device
*rdev
)
1634 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1637 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
1638 if (RREG32_SMC(RCU_UC_EVENTS
) & BOOT_SEQ_DONE
)
1641 WREG32_SMC(SMC_SYSCON_MISC_CNTL
, 1);
1643 ci_stop_smc_clock(rdev
);
1646 ret
= ci_load_smc_ucode(rdev
, pi
->sram_end
);
1652 static int ci_get_svi2_voltage_table(struct radeon_device
*rdev
,
1653 struct radeon_clock_voltage_dependency_table
*voltage_dependency_table
,
1654 struct atom_voltage_table
*voltage_table
)
1658 if (voltage_dependency_table
== NULL
)
1661 voltage_table
->mask_low
= 0;
1662 voltage_table
->phase_delay
= 0;
1664 voltage_table
->count
= voltage_dependency_table
->count
;
1665 for (i
= 0; i
< voltage_table
->count
; i
++) {
1666 voltage_table
->entries
[i
].value
= voltage_dependency_table
->entries
[i
].v
;
1667 voltage_table
->entries
[i
].smio_low
= 0;
1673 static int ci_construct_voltage_tables(struct radeon_device
*rdev
)
1675 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1678 if (pi
->voltage_control
== CISLANDS_VOLTAGE_CONTROL_BY_GPIO
) {
1679 ret
= radeon_atom_get_voltage_table(rdev
, VOLTAGE_TYPE_VDDC
,
1680 VOLTAGE_OBJ_GPIO_LUT
,
1681 &pi
->vddc_voltage_table
);
1684 } else if (pi
->voltage_control
== CISLANDS_VOLTAGE_CONTROL_BY_SVID2
) {
1685 ret
= ci_get_svi2_voltage_table(rdev
,
1686 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_mclk
,
1687 &pi
->vddc_voltage_table
);
1692 if (pi
->vddc_voltage_table
.count
> SMU7_MAX_LEVELS_VDDC
)
1693 si_trim_voltage_table_to_fit_state_table(rdev
, SMU7_MAX_LEVELS_VDDC
,
1694 &pi
->vddc_voltage_table
);
1696 if (pi
->vddci_control
== CISLANDS_VOLTAGE_CONTROL_BY_GPIO
) {
1697 ret
= radeon_atom_get_voltage_table(rdev
, VOLTAGE_TYPE_VDDCI
,
1698 VOLTAGE_OBJ_GPIO_LUT
,
1699 &pi
->vddci_voltage_table
);
1702 } else if (pi
->vddci_control
== CISLANDS_VOLTAGE_CONTROL_BY_SVID2
) {
1703 ret
= ci_get_svi2_voltage_table(rdev
,
1704 &rdev
->pm
.dpm
.dyn_state
.vddci_dependency_on_mclk
,
1705 &pi
->vddci_voltage_table
);
1710 if (pi
->vddci_voltage_table
.count
> SMU7_MAX_LEVELS_VDDCI
)
1711 si_trim_voltage_table_to_fit_state_table(rdev
, SMU7_MAX_LEVELS_VDDCI
,
1712 &pi
->vddci_voltage_table
);
1714 if (pi
->mvdd_control
== CISLANDS_VOLTAGE_CONTROL_BY_GPIO
) {
1715 ret
= radeon_atom_get_voltage_table(rdev
, VOLTAGE_TYPE_MVDDC
,
1716 VOLTAGE_OBJ_GPIO_LUT
,
1717 &pi
->mvdd_voltage_table
);
1720 } else if (pi
->mvdd_control
== CISLANDS_VOLTAGE_CONTROL_BY_SVID2
) {
1721 ret
= ci_get_svi2_voltage_table(rdev
,
1722 &rdev
->pm
.dpm
.dyn_state
.mvdd_dependency_on_mclk
,
1723 &pi
->mvdd_voltage_table
);
1728 if (pi
->mvdd_voltage_table
.count
> SMU7_MAX_LEVELS_MVDD
)
1729 si_trim_voltage_table_to_fit_state_table(rdev
, SMU7_MAX_LEVELS_MVDD
,
1730 &pi
->mvdd_voltage_table
);
1735 static void ci_populate_smc_voltage_table(struct radeon_device
*rdev
,
1736 struct atom_voltage_table_entry
*voltage_table
,
1737 SMU7_Discrete_VoltageLevel
*smc_voltage_table
)
1741 ret
= ci_get_std_voltage_value_sidd(rdev
, voltage_table
,
1742 &smc_voltage_table
->StdVoltageHiSidd
,
1743 &smc_voltage_table
->StdVoltageLoSidd
);
1746 smc_voltage_table
->StdVoltageHiSidd
= voltage_table
->value
* VOLTAGE_SCALE
;
1747 smc_voltage_table
->StdVoltageLoSidd
= voltage_table
->value
* VOLTAGE_SCALE
;
1750 smc_voltage_table
->Voltage
= cpu_to_be16(voltage_table
->value
* VOLTAGE_SCALE
);
1751 smc_voltage_table
->StdVoltageHiSidd
=
1752 cpu_to_be16(smc_voltage_table
->StdVoltageHiSidd
);
1753 smc_voltage_table
->StdVoltageLoSidd
=
1754 cpu_to_be16(smc_voltage_table
->StdVoltageLoSidd
);
1757 static int ci_populate_smc_vddc_table(struct radeon_device
*rdev
,
1758 SMU7_Discrete_DpmTable
*table
)
1760 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1763 table
->VddcLevelCount
= pi
->vddc_voltage_table
.count
;
1764 for (count
= 0; count
< table
->VddcLevelCount
; count
++) {
1765 ci_populate_smc_voltage_table(rdev
,
1766 &pi
->vddc_voltage_table
.entries
[count
],
1767 &table
->VddcLevel
[count
]);
1769 if (pi
->voltage_control
== CISLANDS_VOLTAGE_CONTROL_BY_GPIO
)
1770 table
->VddcLevel
[count
].Smio
|=
1771 pi
->vddc_voltage_table
.entries
[count
].smio_low
;
1773 table
->VddcLevel
[count
].Smio
= 0;
1775 table
->VddcLevelCount
= cpu_to_be32(table
->VddcLevelCount
);
1780 static int ci_populate_smc_vddci_table(struct radeon_device
*rdev
,
1781 SMU7_Discrete_DpmTable
*table
)
1784 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1786 table
->VddciLevelCount
= pi
->vddci_voltage_table
.count
;
1787 for (count
= 0; count
< table
->VddciLevelCount
; count
++) {
1788 ci_populate_smc_voltage_table(rdev
,
1789 &pi
->vddci_voltage_table
.entries
[count
],
1790 &table
->VddciLevel
[count
]);
1792 if (pi
->vddci_control
== CISLANDS_VOLTAGE_CONTROL_BY_GPIO
)
1793 table
->VddciLevel
[count
].Smio
|=
1794 pi
->vddci_voltage_table
.entries
[count
].smio_low
;
1796 table
->VddciLevel
[count
].Smio
= 0;
1798 table
->VddciLevelCount
= cpu_to_be32(table
->VddciLevelCount
);
1803 static int ci_populate_smc_mvdd_table(struct radeon_device
*rdev
,
1804 SMU7_Discrete_DpmTable
*table
)
1806 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1809 table
->MvddLevelCount
= pi
->mvdd_voltage_table
.count
;
1810 for (count
= 0; count
< table
->MvddLevelCount
; count
++) {
1811 ci_populate_smc_voltage_table(rdev
,
1812 &pi
->mvdd_voltage_table
.entries
[count
],
1813 &table
->MvddLevel
[count
]);
1815 if (pi
->mvdd_control
== CISLANDS_VOLTAGE_CONTROL_BY_GPIO
)
1816 table
->MvddLevel
[count
].Smio
|=
1817 pi
->mvdd_voltage_table
.entries
[count
].smio_low
;
1819 table
->MvddLevel
[count
].Smio
= 0;
1821 table
->MvddLevelCount
= cpu_to_be32(table
->MvddLevelCount
);
1826 static int ci_populate_smc_voltage_tables(struct radeon_device
*rdev
,
1827 SMU7_Discrete_DpmTable
*table
)
1831 ret
= ci_populate_smc_vddc_table(rdev
, table
);
1835 ret
= ci_populate_smc_vddci_table(rdev
, table
);
1839 ret
= ci_populate_smc_mvdd_table(rdev
, table
);
1846 static int ci_populate_mvdd_value(struct radeon_device
*rdev
, u32 mclk
,
1847 SMU7_Discrete_VoltageLevel
*voltage
)
1849 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1852 if (pi
->mvdd_control
!= CISLANDS_VOLTAGE_CONTROL_NONE
) {
1853 for (i
= 0; i
< rdev
->pm
.dpm
.dyn_state
.mvdd_dependency_on_mclk
.count
; i
++) {
1854 if (mclk
<= rdev
->pm
.dpm
.dyn_state
.mvdd_dependency_on_mclk
.entries
[i
].clk
) {
1855 voltage
->Voltage
= pi
->mvdd_voltage_table
.entries
[i
].value
;
1860 if (i
>= rdev
->pm
.dpm
.dyn_state
.mvdd_dependency_on_mclk
.count
)
1867 static int ci_get_std_voltage_value_sidd(struct radeon_device
*rdev
,
1868 struct atom_voltage_table_entry
*voltage_table
,
1869 u16
*std_voltage_hi_sidd
, u16
*std_voltage_lo_sidd
)
1872 bool voltage_found
= false;
1873 *std_voltage_hi_sidd
= voltage_table
->value
* VOLTAGE_SCALE
;
1874 *std_voltage_lo_sidd
= voltage_table
->value
* VOLTAGE_SCALE
;
1876 if (rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
.entries
== NULL
)
1879 if (rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.entries
) {
1880 for (v_index
= 0; (u32
)v_index
< rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
.count
; v_index
++) {
1881 if (voltage_table
->value
==
1882 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
.entries
[v_index
].v
) {
1883 voltage_found
= true;
1884 if ((u32
)v_index
< rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.count
)
1887 idx
= rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.count
- 1;
1888 *std_voltage_lo_sidd
=
1889 rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.entries
[idx
].vddc
* VOLTAGE_SCALE
;
1890 *std_voltage_hi_sidd
=
1891 rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.entries
[idx
].leakage
* VOLTAGE_SCALE
;
1896 if (!voltage_found
) {
1897 for (v_index
= 0; (u32
)v_index
< rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
.count
; v_index
++) {
1898 if (voltage_table
->value
<=
1899 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
.entries
[v_index
].v
) {
1900 voltage_found
= true;
1901 if ((u32
)v_index
< rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.count
)
1904 idx
= rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.count
- 1;
1905 *std_voltage_lo_sidd
=
1906 rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.entries
[idx
].vddc
* VOLTAGE_SCALE
;
1907 *std_voltage_hi_sidd
=
1908 rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.entries
[idx
].leakage
* VOLTAGE_SCALE
;
1918 static void ci_populate_phase_value_based_on_sclk(struct radeon_device
*rdev
,
1919 const struct radeon_phase_shedding_limits_table
*limits
,
1921 u32
*phase_shedding
)
1925 *phase_shedding
= 1;
1927 for (i
= 0; i
< limits
->count
; i
++) {
1928 if (sclk
< limits
->entries
[i
].sclk
) {
1929 *phase_shedding
= i
;
1935 static void ci_populate_phase_value_based_on_mclk(struct radeon_device
*rdev
,
1936 const struct radeon_phase_shedding_limits_table
*limits
,
1938 u32
*phase_shedding
)
1942 *phase_shedding
= 1;
1944 for (i
= 0; i
< limits
->count
; i
++) {
1945 if (mclk
< limits
->entries
[i
].mclk
) {
1946 *phase_shedding
= i
;
1952 static int ci_init_arb_table_index(struct radeon_device
*rdev
)
1954 struct ci_power_info
*pi
= ci_get_pi(rdev
);
1958 ret
= ci_read_smc_sram_dword(rdev
, pi
->arb_table_start
,
1959 &tmp
, pi
->sram_end
);
1964 tmp
|= MC_CG_ARB_FREQ_F1
<< 24;
1966 return ci_write_smc_sram_dword(rdev
, pi
->arb_table_start
,
1970 static int ci_get_dependency_volt_by_clk(struct radeon_device
*rdev
,
1971 struct radeon_clock_voltage_dependency_table
*allowed_clock_voltage_table
,
1972 u32 clock
, u32
*voltage
)
1976 if (allowed_clock_voltage_table
->count
== 0)
1979 for (i
= 0; i
< allowed_clock_voltage_table
->count
; i
++) {
1980 if (allowed_clock_voltage_table
->entries
[i
].clk
>= clock
) {
1981 *voltage
= allowed_clock_voltage_table
->entries
[i
].v
;
1986 *voltage
= allowed_clock_voltage_table
->entries
[i
-1].v
;
1991 static u8
ci_get_sleep_divider_id_from_clock(struct radeon_device
*rdev
,
1992 u32 sclk
, u32 min_sclk_in_sr
)
1996 u32 min
= (min_sclk_in_sr
> CISLAND_MINIMUM_ENGINE_CLOCK
) ?
1997 min_sclk_in_sr
: CISLAND_MINIMUM_ENGINE_CLOCK
;
2002 for (i
= CISLAND_MAX_DEEPSLEEP_DIVIDER_ID
; ; i
--) {
2003 tmp
= sclk
/ (1 << i
);
2004 if (tmp
>= min
|| i
== 0)
2011 static int ci_initial_switch_from_arb_f0_to_f1(struct radeon_device
*rdev
)
2013 return ni_copy_and_switch_arb_sets(rdev
, MC_CG_ARB_FREQ_F0
, MC_CG_ARB_FREQ_F1
);
2016 static int ci_reset_to_default(struct radeon_device
*rdev
)
2018 return (ci_send_msg_to_smc(rdev
, PPSMC_MSG_ResetToDefaults
) == PPSMC_Result_OK
) ?
2022 static int ci_force_switch_to_arb_f0(struct radeon_device
*rdev
)
2026 tmp
= (RREG32_SMC(SMC_SCRATCH9
) & 0x0000ff00) >> 8;
2028 if (tmp
== MC_CG_ARB_FREQ_F0
)
2031 return ni_copy_and_switch_arb_sets(rdev
, tmp
, MC_CG_ARB_FREQ_F0
);
2034 static int ci_populate_memory_timing_parameters(struct radeon_device
*rdev
,
2037 SMU7_Discrete_MCArbDramTimingTableEntry
*arb_regs
)
2043 radeon_atom_set_engine_dram_timings(rdev
, sclk
, mclk
);
2045 dram_timing
= RREG32(MC_ARB_DRAM_TIMING
);
2046 dram_timing2
= RREG32(MC_ARB_DRAM_TIMING2
);
2047 burst_time
= RREG32(MC_ARB_BURST_TIME
) & STATE0_MASK
;
2049 arb_regs
->McArbDramTiming
= cpu_to_be32(dram_timing
);
2050 arb_regs
->McArbDramTiming2
= cpu_to_be32(dram_timing2
);
2051 arb_regs
->McArbBurstTime
= (u8
)burst_time
;
2056 static int ci_do_program_memory_timing_parameters(struct radeon_device
*rdev
)
2058 struct ci_power_info
*pi
= ci_get_pi(rdev
);
2059 SMU7_Discrete_MCArbDramTimingTable arb_regs
;
2063 memset(&arb_regs
, 0, sizeof(SMU7_Discrete_MCArbDramTimingTable
));
2065 for (i
= 0; i
< pi
->dpm_table
.sclk_table
.count
; i
++) {
2066 for (j
= 0; j
< pi
->dpm_table
.mclk_table
.count
; j
++) {
2067 ret
= ci_populate_memory_timing_parameters(rdev
,
2068 pi
->dpm_table
.sclk_table
.dpm_levels
[i
].value
,
2069 pi
->dpm_table
.mclk_table
.dpm_levels
[j
].value
,
2070 &arb_regs
.entries
[i
][j
]);
2077 ret
= ci_copy_bytes_to_smc(rdev
,
2078 pi
->arb_table_start
,
2080 sizeof(SMU7_Discrete_MCArbDramTimingTable
),
2086 static int ci_program_memory_timing_parameters(struct radeon_device
*rdev
)
2088 struct ci_power_info
*pi
= ci_get_pi(rdev
);
2090 if (pi
->need_update_smu7_dpm_table
== 0)
2093 return ci_do_program_memory_timing_parameters(rdev
);
2096 static void ci_populate_smc_initial_state(struct radeon_device
*rdev
,
2097 struct radeon_ps
*radeon_boot_state
)
2099 struct ci_ps
*boot_state
= ci_get_ps(radeon_boot_state
);
2100 struct ci_power_info
*pi
= ci_get_pi(rdev
);
2103 for (level
= 0; level
< rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
.count
; level
++) {
2104 if (rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
.entries
[level
].clk
>=
2105 boot_state
->performance_levels
[0].sclk
) {
2106 pi
->smc_state_table
.GraphicsBootLevel
= level
;
2111 for (level
= 0; level
< rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_mclk
.count
; level
++) {
2112 if (rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_mclk
.entries
[level
].clk
>=
2113 boot_state
->performance_levels
[0].mclk
) {
2114 pi
->smc_state_table
.MemoryBootLevel
= level
;
2120 static u32
ci_get_dpm_level_enable_mask_value(struct ci_single_dpm_table
*dpm_table
)
2125 for (i
= dpm_table
->count
; i
> 0; i
--) {
2126 mask_value
= mask_value
<< 1;
2127 if (dpm_table
->dpm_levels
[i
-1].enabled
)
2130 mask_value
&= 0xFFFFFFFE;
2136 static void ci_populate_smc_link_level(struct radeon_device
*rdev
,
2137 SMU7_Discrete_DpmTable
*table
)
2139 struct ci_power_info
*pi
= ci_get_pi(rdev
);
2140 struct ci_dpm_table
*dpm_table
= &pi
->dpm_table
;
2143 for (i
= 0; i
< dpm_table
->pcie_speed_table
.count
; i
++) {
2144 table
->LinkLevel
[i
].PcieGenSpeed
=
2145 (u8
)dpm_table
->pcie_speed_table
.dpm_levels
[i
].value
;
2146 table
->LinkLevel
[i
].PcieLaneCount
=
2147 r600_encode_pci_lane_width(dpm_table
->pcie_speed_table
.dpm_levels
[i
].param1
);
2148 table
->LinkLevel
[i
].EnabledForActivity
= 1;
2149 table
->LinkLevel
[i
].DownT
= cpu_to_be32(5);
2150 table
->LinkLevel
[i
].UpT
= cpu_to_be32(30);
2153 pi
->smc_state_table
.LinkLevelCount
= (u8
)dpm_table
->pcie_speed_table
.count
;
2154 pi
->dpm_level_enable_mask
.pcie_dpm_enable_mask
=
2155 ci_get_dpm_level_enable_mask_value(&dpm_table
->pcie_speed_table
);
2158 static int ci_populate_smc_uvd_level(struct radeon_device
*rdev
,
2159 SMU7_Discrete_DpmTable
*table
)
2162 struct atom_clock_dividers dividers
;
2165 table
->UvdLevelCount
=
2166 rdev
->pm
.dpm
.dyn_state
.uvd_clock_voltage_dependency_table
.count
;
2168 for (count
= 0; count
< table
->UvdLevelCount
; count
++) {
2169 table
->UvdLevel
[count
].VclkFrequency
=
2170 rdev
->pm
.dpm
.dyn_state
.uvd_clock_voltage_dependency_table
.entries
[count
].vclk
;
2171 table
->UvdLevel
[count
].DclkFrequency
=
2172 rdev
->pm
.dpm
.dyn_state
.uvd_clock_voltage_dependency_table
.entries
[count
].dclk
;
2173 table
->UvdLevel
[count
].MinVddc
=
2174 rdev
->pm
.dpm
.dyn_state
.uvd_clock_voltage_dependency_table
.entries
[count
].v
* VOLTAGE_SCALE
;
2175 table
->UvdLevel
[count
].MinVddcPhases
= 1;
2177 ret
= radeon_atom_get_clock_dividers(rdev
,
2178 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK
,
2179 table
->UvdLevel
[count
].VclkFrequency
, false, ÷rs
);
2183 table
->UvdLevel
[count
].VclkDivider
= (u8
)dividers
.post_divider
;
2185 ret
= radeon_atom_get_clock_dividers(rdev
,
2186 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK
,
2187 table
->UvdLevel
[count
].DclkFrequency
, false, ÷rs
);
2191 table
->UvdLevel
[count
].DclkDivider
= (u8
)dividers
.post_divider
;
2193 table
->UvdLevel
[count
].VclkFrequency
= cpu_to_be32(table
->UvdLevel
[count
].VclkFrequency
);
2194 table
->UvdLevel
[count
].DclkFrequency
= cpu_to_be32(table
->UvdLevel
[count
].DclkFrequency
);
2195 table
->UvdLevel
[count
].MinVddc
= cpu_to_be16(table
->UvdLevel
[count
].MinVddc
);
2201 static int ci_populate_smc_vce_level(struct radeon_device
*rdev
,
2202 SMU7_Discrete_DpmTable
*table
)
2205 struct atom_clock_dividers dividers
;
2208 table
->VceLevelCount
=
2209 rdev
->pm
.dpm
.dyn_state
.vce_clock_voltage_dependency_table
.count
;
2211 for (count
= 0; count
< table
->VceLevelCount
; count
++) {
2212 table
->VceLevel
[count
].Frequency
=
2213 rdev
->pm
.dpm
.dyn_state
.vce_clock_voltage_dependency_table
.entries
[count
].evclk
;
2214 table
->VceLevel
[count
].MinVoltage
=
2215 (u16
)rdev
->pm
.dpm
.dyn_state
.vce_clock_voltage_dependency_table
.entries
[count
].v
* VOLTAGE_SCALE
;
2216 table
->VceLevel
[count
].MinPhases
= 1;
2218 ret
= radeon_atom_get_clock_dividers(rdev
,
2219 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK
,
2220 table
->VceLevel
[count
].Frequency
, false, ÷rs
);
2224 table
->VceLevel
[count
].Divider
= (u8
)dividers
.post_divider
;
2226 table
->VceLevel
[count
].Frequency
= cpu_to_be32(table
->VceLevel
[count
].Frequency
);
2227 table
->VceLevel
[count
].MinVoltage
= cpu_to_be16(table
->VceLevel
[count
].MinVoltage
);
2234 static int ci_populate_smc_acp_level(struct radeon_device
*rdev
,
2235 SMU7_Discrete_DpmTable
*table
)
2238 struct atom_clock_dividers dividers
;
2241 table
->AcpLevelCount
= (u8
)
2242 (rdev
->pm
.dpm
.dyn_state
.acp_clock_voltage_dependency_table
.count
);
2244 for (count
= 0; count
< table
->AcpLevelCount
; count
++) {
2245 table
->AcpLevel
[count
].Frequency
=
2246 rdev
->pm
.dpm
.dyn_state
.acp_clock_voltage_dependency_table
.entries
[count
].clk
;
2247 table
->AcpLevel
[count
].MinVoltage
=
2248 rdev
->pm
.dpm
.dyn_state
.acp_clock_voltage_dependency_table
.entries
[count
].v
;
2249 table
->AcpLevel
[count
].MinPhases
= 1;
2251 ret
= radeon_atom_get_clock_dividers(rdev
,
2252 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK
,
2253 table
->AcpLevel
[count
].Frequency
, false, ÷rs
);
2257 table
->AcpLevel
[count
].Divider
= (u8
)dividers
.post_divider
;
2259 table
->AcpLevel
[count
].Frequency
= cpu_to_be32(table
->AcpLevel
[count
].Frequency
);
2260 table
->AcpLevel
[count
].MinVoltage
= cpu_to_be16(table
->AcpLevel
[count
].MinVoltage
);
2266 static int ci_populate_smc_samu_level(struct radeon_device
*rdev
,
2267 SMU7_Discrete_DpmTable
*table
)
2270 struct atom_clock_dividers dividers
;
2273 table
->SamuLevelCount
=
2274 rdev
->pm
.dpm
.dyn_state
.samu_clock_voltage_dependency_table
.count
;
2276 for (count
= 0; count
< table
->SamuLevelCount
; count
++) {
2277 table
->SamuLevel
[count
].Frequency
=
2278 rdev
->pm
.dpm
.dyn_state
.samu_clock_voltage_dependency_table
.entries
[count
].clk
;
2279 table
->SamuLevel
[count
].MinVoltage
=
2280 rdev
->pm
.dpm
.dyn_state
.samu_clock_voltage_dependency_table
.entries
[count
].v
* VOLTAGE_SCALE
;
2281 table
->SamuLevel
[count
].MinPhases
= 1;
2283 ret
= radeon_atom_get_clock_dividers(rdev
,
2284 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK
,
2285 table
->SamuLevel
[count
].Frequency
, false, ÷rs
);
2289 table
->SamuLevel
[count
].Divider
= (u8
)dividers
.post_divider
;
2291 table
->SamuLevel
[count
].Frequency
= cpu_to_be32(table
->SamuLevel
[count
].Frequency
);
2292 table
->SamuLevel
[count
].MinVoltage
= cpu_to_be16(table
->SamuLevel
[count
].MinVoltage
);
2298 static int ci_calculate_mclk_params(struct radeon_device
*rdev
,
2300 SMU7_Discrete_MemoryLevel
*mclk
,
2304 struct ci_power_info
*pi
= ci_get_pi(rdev
);
2305 u32 dll_cntl
= pi
->clock_registers
.dll_cntl
;
2306 u32 mclk_pwrmgt_cntl
= pi
->clock_registers
.mclk_pwrmgt_cntl
;
2307 u32 mpll_ad_func_cntl
= pi
->clock_registers
.mpll_ad_func_cntl
;
2308 u32 mpll_dq_func_cntl
= pi
->clock_registers
.mpll_dq_func_cntl
;
2309 u32 mpll_func_cntl
= pi
->clock_registers
.mpll_func_cntl
;
2310 u32 mpll_func_cntl_1
= pi
->clock_registers
.mpll_func_cntl_1
;
2311 u32 mpll_func_cntl_2
= pi
->clock_registers
.mpll_func_cntl_2
;
2312 u32 mpll_ss1
= pi
->clock_registers
.mpll_ss1
;
2313 u32 mpll_ss2
= pi
->clock_registers
.mpll_ss2
;
2314 struct atom_mpll_param mpll_param
;
2317 ret
= radeon_atom_get_memory_pll_dividers(rdev
, memory_clock
, strobe_mode
, &mpll_param
);
2321 mpll_func_cntl
&= ~BWCTRL_MASK
;
2322 mpll_func_cntl
|= BWCTRL(mpll_param
.bwcntl
);
2324 mpll_func_cntl_1
&= ~(CLKF_MASK
| CLKFRAC_MASK
| VCO_MODE_MASK
);
2325 mpll_func_cntl_1
|= CLKF(mpll_param
.clkf
) |
2326 CLKFRAC(mpll_param
.clkfrac
) | VCO_MODE(mpll_param
.vco_mode
);
2328 mpll_ad_func_cntl
&= ~YCLK_POST_DIV_MASK
;
2329 mpll_ad_func_cntl
|= YCLK_POST_DIV(mpll_param
.post_div
);
2331 if (pi
->mem_gddr5
) {
2332 mpll_dq_func_cntl
&= ~(YCLK_SEL_MASK
| YCLK_POST_DIV_MASK
);
2333 mpll_dq_func_cntl
|= YCLK_SEL(mpll_param
.yclk_sel
) |
2334 YCLK_POST_DIV(mpll_param
.post_div
);
2337 if (pi
->caps_mclk_ss_support
) {
2338 struct radeon_atom_ss ss
;
2341 u32 reference_clock
= rdev
->clock
.mpll
.reference_freq
;
2344 freq_nom
= memory_clock
* 4;
2346 freq_nom
= memory_clock
* 2;
2348 tmp
= (freq_nom
/ reference_clock
);
2350 if (radeon_atombios_get_asic_ss_info(rdev
, &ss
,
2351 ASIC_INTERNAL_MEMORY_SS
, freq_nom
)) {
2352 u32 clks
= reference_clock
* 5 / ss
.rate
;
2353 u32 clkv
= (u32
)((((131 * ss
.percentage
* ss
.rate
) / 100) * tmp
) / freq_nom
);
2355 mpll_ss1
&= ~CLKV_MASK
;
2356 mpll_ss1
|= CLKV(clkv
);
2358 mpll_ss2
&= ~CLKS_MASK
;
2359 mpll_ss2
|= CLKS(clks
);
2363 mclk_pwrmgt_cntl
&= ~DLL_SPEED_MASK
;
2364 mclk_pwrmgt_cntl
|= DLL_SPEED(mpll_param
.dll_speed
);
2367 mclk_pwrmgt_cntl
|= MRDCK0_PDNB
| MRDCK1_PDNB
;
2369 mclk_pwrmgt_cntl
&= ~(MRDCK0_PDNB
| MRDCK1_PDNB
);
2371 mclk
->MclkFrequency
= memory_clock
;
2372 mclk
->MpllFuncCntl
= mpll_func_cntl
;
2373 mclk
->MpllFuncCntl_1
= mpll_func_cntl_1
;
2374 mclk
->MpllFuncCntl_2
= mpll_func_cntl_2
;
2375 mclk
->MpllAdFuncCntl
= mpll_ad_func_cntl
;
2376 mclk
->MpllDqFuncCntl
= mpll_dq_func_cntl
;
2377 mclk
->MclkPwrmgtCntl
= mclk_pwrmgt_cntl
;
2378 mclk
->DllCntl
= dll_cntl
;
2379 mclk
->MpllSs1
= mpll_ss1
;
2380 mclk
->MpllSs2
= mpll_ss2
;
2385 static int ci_populate_single_memory_level(struct radeon_device
*rdev
,
2387 SMU7_Discrete_MemoryLevel
*memory_level
)
2389 struct ci_power_info
*pi
= ci_get_pi(rdev
);
2393 if (rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_mclk
.entries
) {
2394 ret
= ci_get_dependency_volt_by_clk(rdev
,
2395 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_mclk
,
2396 memory_clock
, &memory_level
->MinVddc
);
2401 if (rdev
->pm
.dpm
.dyn_state
.vddci_dependency_on_mclk
.entries
) {
2402 ret
= ci_get_dependency_volt_by_clk(rdev
,
2403 &rdev
->pm
.dpm
.dyn_state
.vddci_dependency_on_mclk
,
2404 memory_clock
, &memory_level
->MinVddci
);
2409 if (rdev
->pm
.dpm
.dyn_state
.mvdd_dependency_on_mclk
.entries
) {
2410 ret
= ci_get_dependency_volt_by_clk(rdev
,
2411 &rdev
->pm
.dpm
.dyn_state
.mvdd_dependency_on_mclk
,
2412 memory_clock
, &memory_level
->MinMvdd
);
2417 memory_level
->MinVddcPhases
= 1;
2419 if (pi
->vddc_phase_shed_control
)
2420 ci_populate_phase_value_based_on_mclk(rdev
,
2421 &rdev
->pm
.dpm
.dyn_state
.phase_shedding_limits_table
,
2423 &memory_level
->MinVddcPhases
);
2425 memory_level
->EnabledForThrottle
= 1;
2426 memory_level
->EnabledForActivity
= 1;
2427 memory_level
->UpH
= 0;
2428 memory_level
->DownH
= 100;
2429 memory_level
->VoltageDownH
= 0;
2430 memory_level
->ActivityLevel
= (u16
)pi
->mclk_activity_target
;
2432 memory_level
->StutterEnable
= false;
2433 memory_level
->StrobeEnable
= false;
2434 memory_level
->EdcReadEnable
= false;
2435 memory_level
->EdcWriteEnable
= false;
2436 memory_level
->RttEnable
= false;
2438 memory_level
->DisplayWatermark
= PPSMC_DISPLAY_WATERMARK_LOW
;
2440 if (pi
->mclk_stutter_mode_threshold
&&
2441 (memory_clock
<= pi
->mclk_stutter_mode_threshold
) &&
2442 (pi
->uvd_enabled
== false) &&
2443 (RREG32(DPG_PIPE_STUTTER_CONTROL
) & STUTTER_ENABLE
) &&
2444 (rdev
->pm
.dpm
.new_active_crtc_count
<= 2))
2445 memory_level
->StutterEnable
= true;
2447 if (pi
->mclk_strobe_mode_threshold
&&
2448 (memory_clock
<= pi
->mclk_strobe_mode_threshold
))
2449 memory_level
->StrobeEnable
= 1;
2451 if (pi
->mem_gddr5
) {
2452 memory_level
->StrobeRatio
=
2453 si_get_mclk_frequency_ratio(memory_clock
, memory_level
->StrobeEnable
);
2454 if (pi
->mclk_edc_enable_threshold
&&
2455 (memory_clock
> pi
->mclk_edc_enable_threshold
))
2456 memory_level
->EdcReadEnable
= true;
2458 if (pi
->mclk_edc_wr_enable_threshold
&&
2459 (memory_clock
> pi
->mclk_edc_wr_enable_threshold
))
2460 memory_level
->EdcWriteEnable
= true;
2462 if (memory_level
->StrobeEnable
) {
2463 if (si_get_mclk_frequency_ratio(memory_clock
, true) >=
2464 ((RREG32(MC_SEQ_MISC7
) >> 16) & 0xf))
2465 dll_state_on
= ((RREG32(MC_SEQ_MISC5
) >> 1) & 0x1) ? true : false;
2467 dll_state_on
= ((RREG32(MC_SEQ_MISC6
) >> 1) & 0x1) ? true : false;
2469 dll_state_on
= pi
->dll_default_on
;
2472 memory_level
->StrobeRatio
= si_get_ddr3_mclk_frequency_ratio(memory_clock
);
2473 dll_state_on
= ((RREG32(MC_SEQ_MISC5
) >> 1) & 0x1) ? true : false;
2476 ret
= ci_calculate_mclk_params(rdev
, memory_clock
, memory_level
, memory_level
->StrobeEnable
, dll_state_on
);
2480 memory_level
->MinVddc
= cpu_to_be32(memory_level
->MinVddc
* VOLTAGE_SCALE
);
2481 memory_level
->MinVddcPhases
= cpu_to_be32(memory_level
->MinVddcPhases
);
2482 memory_level
->MinVddci
= cpu_to_be32(memory_level
->MinVddci
* VOLTAGE_SCALE
);
2483 memory_level
->MinMvdd
= cpu_to_be32(memory_level
->MinMvdd
* VOLTAGE_SCALE
);
2485 memory_level
->MclkFrequency
= cpu_to_be32(memory_level
->MclkFrequency
);
2486 memory_level
->ActivityLevel
= cpu_to_be16(memory_level
->ActivityLevel
);
2487 memory_level
->MpllFuncCntl
= cpu_to_be32(memory_level
->MpllFuncCntl
);
2488 memory_level
->MpllFuncCntl_1
= cpu_to_be32(memory_level
->MpllFuncCntl_1
);
2489 memory_level
->MpllFuncCntl_2
= cpu_to_be32(memory_level
->MpllFuncCntl_2
);
2490 memory_level
->MpllAdFuncCntl
= cpu_to_be32(memory_level
->MpllAdFuncCntl
);
2491 memory_level
->MpllDqFuncCntl
= cpu_to_be32(memory_level
->MpllDqFuncCntl
);
2492 memory_level
->MclkPwrmgtCntl
= cpu_to_be32(memory_level
->MclkPwrmgtCntl
);
2493 memory_level
->DllCntl
= cpu_to_be32(memory_level
->DllCntl
);
2494 memory_level
->MpllSs1
= cpu_to_be32(memory_level
->MpllSs1
);
2495 memory_level
->MpllSs2
= cpu_to_be32(memory_level
->MpllSs2
);
2500 static int ci_populate_smc_acpi_level(struct radeon_device
*rdev
,
2501 SMU7_Discrete_DpmTable
*table
)
2503 struct ci_power_info
*pi
= ci_get_pi(rdev
);
2504 struct atom_clock_dividers dividers
;
2505 SMU7_Discrete_VoltageLevel voltage_level
;
2506 u32 spll_func_cntl
= pi
->clock_registers
.cg_spll_func_cntl
;
2507 u32 spll_func_cntl_2
= pi
->clock_registers
.cg_spll_func_cntl_2
;
2508 u32 dll_cntl
= pi
->clock_registers
.dll_cntl
;
2509 u32 mclk_pwrmgt_cntl
= pi
->clock_registers
.mclk_pwrmgt_cntl
;
2512 table
->ACPILevel
.Flags
&= ~PPSMC_SWSTATE_FLAG_DC
;
2515 table
->ACPILevel
.MinVddc
= cpu_to_be32(pi
->acpi_vddc
* VOLTAGE_SCALE
);
2517 table
->ACPILevel
.MinVddc
= cpu_to_be32(pi
->min_vddc_in_pp_table
* VOLTAGE_SCALE
);
2519 table
->ACPILevel
.MinVddcPhases
= pi
->vddc_phase_shed_control
? 0 : 1;
2521 table
->ACPILevel
.SclkFrequency
= rdev
->clock
.spll
.reference_freq
;
2523 ret
= radeon_atom_get_clock_dividers(rdev
,
2524 COMPUTE_GPUCLK_INPUT_FLAG_SCLK
,
2525 table
->ACPILevel
.SclkFrequency
, false, ÷rs
);
2529 table
->ACPILevel
.SclkDid
= (u8
)dividers
.post_divider
;
2530 table
->ACPILevel
.DisplayWatermark
= PPSMC_DISPLAY_WATERMARK_LOW
;
2531 table
->ACPILevel
.DeepSleepDivId
= 0;
2533 spll_func_cntl
&= ~SPLL_PWRON
;
2534 spll_func_cntl
|= SPLL_RESET
;
2536 spll_func_cntl_2
&= ~SCLK_MUX_SEL_MASK
;
2537 spll_func_cntl_2
|= SCLK_MUX_SEL(4);
2539 table
->ACPILevel
.CgSpllFuncCntl
= spll_func_cntl
;
2540 table
->ACPILevel
.CgSpllFuncCntl2
= spll_func_cntl_2
;
2541 table
->ACPILevel
.CgSpllFuncCntl3
= pi
->clock_registers
.cg_spll_func_cntl_3
;
2542 table
->ACPILevel
.CgSpllFuncCntl4
= pi
->clock_registers
.cg_spll_func_cntl_4
;
2543 table
->ACPILevel
.SpllSpreadSpectrum
= pi
->clock_registers
.cg_spll_spread_spectrum
;
2544 table
->ACPILevel
.SpllSpreadSpectrum2
= pi
->clock_registers
.cg_spll_spread_spectrum_2
;
2545 table
->ACPILevel
.CcPwrDynRm
= 0;
2546 table
->ACPILevel
.CcPwrDynRm1
= 0;
2548 table
->ACPILevel
.Flags
= cpu_to_be32(table
->ACPILevel
.Flags
);
2549 table
->ACPILevel
.MinVddcPhases
= cpu_to_be32(table
->ACPILevel
.MinVddcPhases
);
2550 table
->ACPILevel
.SclkFrequency
= cpu_to_be32(table
->ACPILevel
.SclkFrequency
);
2551 table
->ACPILevel
.CgSpllFuncCntl
= cpu_to_be32(table
->ACPILevel
.CgSpllFuncCntl
);
2552 table
->ACPILevel
.CgSpllFuncCntl2
= cpu_to_be32(table
->ACPILevel
.CgSpllFuncCntl2
);
2553 table
->ACPILevel
.CgSpllFuncCntl3
= cpu_to_be32(table
->ACPILevel
.CgSpllFuncCntl3
);
2554 table
->ACPILevel
.CgSpllFuncCntl4
= cpu_to_be32(table
->ACPILevel
.CgSpllFuncCntl4
);
2555 table
->ACPILevel
.SpllSpreadSpectrum
= cpu_to_be32(table
->ACPILevel
.SpllSpreadSpectrum
);
2556 table
->ACPILevel
.SpllSpreadSpectrum2
= cpu_to_be32(table
->ACPILevel
.SpllSpreadSpectrum2
);
2557 table
->ACPILevel
.CcPwrDynRm
= cpu_to_be32(table
->ACPILevel
.CcPwrDynRm
);
2558 table
->ACPILevel
.CcPwrDynRm1
= cpu_to_be32(table
->ACPILevel
.CcPwrDynRm1
);
2560 table
->MemoryACPILevel
.MinVddc
= table
->ACPILevel
.MinVddc
;
2561 table
->MemoryACPILevel
.MinVddcPhases
= table
->ACPILevel
.MinVddcPhases
;
2563 if (pi
->vddci_control
!= CISLANDS_VOLTAGE_CONTROL_NONE
) {
2565 table
->MemoryACPILevel
.MinVddci
=
2566 cpu_to_be32(pi
->acpi_vddci
* VOLTAGE_SCALE
);
2568 table
->MemoryACPILevel
.MinVddci
=
2569 cpu_to_be32(pi
->min_vddci_in_pp_table
* VOLTAGE_SCALE
);
2572 if (ci_populate_mvdd_value(rdev
, 0, &voltage_level
))
2573 table
->MemoryACPILevel
.MinMvdd
= 0;
2575 table
->MemoryACPILevel
.MinMvdd
=
2576 cpu_to_be32(voltage_level
.Voltage
* VOLTAGE_SCALE
);
2578 mclk_pwrmgt_cntl
|= MRDCK0_RESET
| MRDCK1_RESET
;
2579 mclk_pwrmgt_cntl
&= ~(MRDCK0_PDNB
| MRDCK1_PDNB
);
2581 dll_cntl
&= ~(MRDCK0_BYPASS
| MRDCK1_BYPASS
);
2583 table
->MemoryACPILevel
.DllCntl
= cpu_to_be32(dll_cntl
);
2584 table
->MemoryACPILevel
.MclkPwrmgtCntl
= cpu_to_be32(mclk_pwrmgt_cntl
);
2585 table
->MemoryACPILevel
.MpllAdFuncCntl
=
2586 cpu_to_be32(pi
->clock_registers
.mpll_ad_func_cntl
);
2587 table
->MemoryACPILevel
.MpllDqFuncCntl
=
2588 cpu_to_be32(pi
->clock_registers
.mpll_dq_func_cntl
);
2589 table
->MemoryACPILevel
.MpllFuncCntl
=
2590 cpu_to_be32(pi
->clock_registers
.mpll_func_cntl
);
2591 table
->MemoryACPILevel
.MpllFuncCntl_1
=
2592 cpu_to_be32(pi
->clock_registers
.mpll_func_cntl_1
);
2593 table
->MemoryACPILevel
.MpllFuncCntl_2
=
2594 cpu_to_be32(pi
->clock_registers
.mpll_func_cntl_2
);
2595 table
->MemoryACPILevel
.MpllSs1
= cpu_to_be32(pi
->clock_registers
.mpll_ss1
);
2596 table
->MemoryACPILevel
.MpllSs2
= cpu_to_be32(pi
->clock_registers
.mpll_ss2
);
2598 table
->MemoryACPILevel
.EnabledForThrottle
= 0;
2599 table
->MemoryACPILevel
.EnabledForActivity
= 0;
2600 table
->MemoryACPILevel
.UpH
= 0;
2601 table
->MemoryACPILevel
.DownH
= 100;
2602 table
->MemoryACPILevel
.VoltageDownH
= 0;
2603 table
->MemoryACPILevel
.ActivityLevel
=
2604 cpu_to_be16((u16
)pi
->mclk_activity_target
);
2606 table
->MemoryACPILevel
.StutterEnable
= false;
2607 table
->MemoryACPILevel
.StrobeEnable
= false;
2608 table
->MemoryACPILevel
.EdcReadEnable
= false;
2609 table
->MemoryACPILevel
.EdcWriteEnable
= false;
2610 table
->MemoryACPILevel
.RttEnable
= false;
2616 static int ci_enable_ulv(struct radeon_device
*rdev
, bool enable
)
2618 struct ci_power_info
*pi
= ci_get_pi(rdev
);
2619 struct ci_ulv_parm
*ulv
= &pi
->ulv
;
2621 if (ulv
->supported
) {
2623 return (ci_send_msg_to_smc(rdev
, PPSMC_MSG_EnableULV
) == PPSMC_Result_OK
) ?
2626 return (ci_send_msg_to_smc(rdev
, PPSMC_MSG_DisableULV
) == PPSMC_Result_OK
) ?
2633 static int ci_populate_ulv_level(struct radeon_device
*rdev
,
2634 SMU7_Discrete_Ulv
*state
)
2636 struct ci_power_info
*pi
= ci_get_pi(rdev
);
2637 u16 ulv_voltage
= rdev
->pm
.dpm
.backbias_response_time
;
2639 state
->CcPwrDynRm
= 0;
2640 state
->CcPwrDynRm1
= 0;
2642 if (ulv_voltage
== 0) {
2643 pi
->ulv
.supported
= false;
2647 if (pi
->voltage_control
!= CISLANDS_VOLTAGE_CONTROL_BY_SVID2
) {
2648 if (ulv_voltage
> rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
.entries
[0].v
)
2649 state
->VddcOffset
= 0;
2652 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
.entries
[0].v
- ulv_voltage
;
2654 if (ulv_voltage
> rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
.entries
[0].v
)
2655 state
->VddcOffsetVid
= 0;
2657 state
->VddcOffsetVid
= (u8
)
2658 ((rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
.entries
[0].v
- ulv_voltage
) *
2659 VOLTAGE_VID_OFFSET_SCALE2
/ VOLTAGE_VID_OFFSET_SCALE1
);
2661 state
->VddcPhase
= pi
->vddc_phase_shed_control
? 0 : 1;
2663 state
->CcPwrDynRm
= cpu_to_be32(state
->CcPwrDynRm
);
2664 state
->CcPwrDynRm1
= cpu_to_be32(state
->CcPwrDynRm1
);
2665 state
->VddcOffset
= cpu_to_be16(state
->VddcOffset
);
2670 static int ci_calculate_sclk_params(struct radeon_device
*rdev
,
2672 SMU7_Discrete_GraphicsLevel
*sclk
)
2674 struct ci_power_info
*pi
= ci_get_pi(rdev
);
2675 struct atom_clock_dividers dividers
;
2676 u32 spll_func_cntl_3
= pi
->clock_registers
.cg_spll_func_cntl_3
;
2677 u32 spll_func_cntl_4
= pi
->clock_registers
.cg_spll_func_cntl_4
;
2678 u32 cg_spll_spread_spectrum
= pi
->clock_registers
.cg_spll_spread_spectrum
;
2679 u32 cg_spll_spread_spectrum_2
= pi
->clock_registers
.cg_spll_spread_spectrum_2
;
2680 u32 reference_clock
= rdev
->clock
.spll
.reference_freq
;
2681 u32 reference_divider
;
2685 ret
= radeon_atom_get_clock_dividers(rdev
,
2686 COMPUTE_GPUCLK_INPUT_FLAG_SCLK
,
2687 engine_clock
, false, ÷rs
);
2691 reference_divider
= 1 + dividers
.ref_div
;
2692 fbdiv
= dividers
.fb_div
& 0x3FFFFFF;
2694 spll_func_cntl_3
&= ~SPLL_FB_DIV_MASK
;
2695 spll_func_cntl_3
|= SPLL_FB_DIV(fbdiv
);
2696 spll_func_cntl_3
|= SPLL_DITHEN
;
2698 if (pi
->caps_sclk_ss_support
) {
2699 struct radeon_atom_ss ss
;
2700 u32 vco_freq
= engine_clock
* dividers
.post_div
;
2702 if (radeon_atombios_get_asic_ss_info(rdev
, &ss
,
2703 ASIC_INTERNAL_ENGINE_SS
, vco_freq
)) {
2704 u32 clk_s
= reference_clock
* 5 / (reference_divider
* ss
.rate
);
2705 u32 clk_v
= 4 * ss
.percentage
* fbdiv
/ (clk_s
* 10000);
2707 cg_spll_spread_spectrum
&= ~CLK_S_MASK
;
2708 cg_spll_spread_spectrum
|= CLK_S(clk_s
);
2709 cg_spll_spread_spectrum
|= SSEN
;
2711 cg_spll_spread_spectrum_2
&= ~CLK_V_MASK
;
2712 cg_spll_spread_spectrum_2
|= CLK_V(clk_v
);
2716 sclk
->SclkFrequency
= engine_clock
;
2717 sclk
->CgSpllFuncCntl3
= spll_func_cntl_3
;
2718 sclk
->CgSpllFuncCntl4
= spll_func_cntl_4
;
2719 sclk
->SpllSpreadSpectrum
= cg_spll_spread_spectrum
;
2720 sclk
->SpllSpreadSpectrum2
= cg_spll_spread_spectrum_2
;
2721 sclk
->SclkDid
= (u8
)dividers
.post_divider
;
2726 static int ci_populate_single_graphic_level(struct radeon_device
*rdev
,
2728 u16 sclk_activity_level_t
,
2729 SMU7_Discrete_GraphicsLevel
*graphic_level
)
2731 struct ci_power_info
*pi
= ci_get_pi(rdev
);
2734 ret
= ci_calculate_sclk_params(rdev
, engine_clock
, graphic_level
);
2738 ret
= ci_get_dependency_volt_by_clk(rdev
,
2739 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
,
2740 engine_clock
, &graphic_level
->MinVddc
);
2744 graphic_level
->SclkFrequency
= engine_clock
;
2746 graphic_level
->Flags
= 0;
2747 graphic_level
->MinVddcPhases
= 1;
2749 if (pi
->vddc_phase_shed_control
)
2750 ci_populate_phase_value_based_on_sclk(rdev
,
2751 &rdev
->pm
.dpm
.dyn_state
.phase_shedding_limits_table
,
2753 &graphic_level
->MinVddcPhases
);
2755 graphic_level
->ActivityLevel
= sclk_activity_level_t
;
2757 graphic_level
->CcPwrDynRm
= 0;
2758 graphic_level
->CcPwrDynRm1
= 0;
2759 graphic_level
->EnabledForActivity
= 1;
2760 graphic_level
->EnabledForThrottle
= 1;
2761 graphic_level
->UpH
= 0;
2762 graphic_level
->DownH
= 0;
2763 graphic_level
->VoltageDownH
= 0;
2764 graphic_level
->PowerThrottle
= 0;
2766 if (pi
->caps_sclk_ds
)
2767 graphic_level
->DeepSleepDivId
= ci_get_sleep_divider_id_from_clock(rdev
,
2769 CISLAND_MINIMUM_ENGINE_CLOCK
);
2771 graphic_level
->DisplayWatermark
= PPSMC_DISPLAY_WATERMARK_LOW
;
2773 graphic_level
->Flags
= cpu_to_be32(graphic_level
->Flags
);
2774 graphic_level
->MinVddc
= cpu_to_be32(graphic_level
->MinVddc
* VOLTAGE_SCALE
);
2775 graphic_level
->MinVddcPhases
= cpu_to_be32(graphic_level
->MinVddcPhases
);
2776 graphic_level
->SclkFrequency
= cpu_to_be32(graphic_level
->SclkFrequency
);
2777 graphic_level
->ActivityLevel
= cpu_to_be16(graphic_level
->ActivityLevel
);
2778 graphic_level
->CgSpllFuncCntl3
= cpu_to_be32(graphic_level
->CgSpllFuncCntl3
);
2779 graphic_level
->CgSpllFuncCntl4
= cpu_to_be32(graphic_level
->CgSpllFuncCntl4
);
2780 graphic_level
->SpllSpreadSpectrum
= cpu_to_be32(graphic_level
->SpllSpreadSpectrum
);
2781 graphic_level
->SpllSpreadSpectrum2
= cpu_to_be32(graphic_level
->SpllSpreadSpectrum2
);
2782 graphic_level
->CcPwrDynRm
= cpu_to_be32(graphic_level
->CcPwrDynRm
);
2783 graphic_level
->CcPwrDynRm1
= cpu_to_be32(graphic_level
->CcPwrDynRm1
);
2788 static int ci_populate_all_graphic_levels(struct radeon_device
*rdev
)
2790 struct ci_power_info
*pi
= ci_get_pi(rdev
);
2791 struct ci_dpm_table
*dpm_table
= &pi
->dpm_table
;
2792 u32 level_array_address
= pi
->dpm_table_start
+
2793 offsetof(SMU7_Discrete_DpmTable
, GraphicsLevel
);
2794 u32 level_array_size
= sizeof(SMU7_Discrete_GraphicsLevel
) *
2795 SMU7_MAX_LEVELS_GRAPHICS
;
2796 SMU7_Discrete_GraphicsLevel
*levels
= pi
->smc_state_table
.GraphicsLevel
;
2799 memset(levels
, 0, level_array_size
);
2801 for (i
= 0; i
< dpm_table
->sclk_table
.count
; i
++) {
2802 ret
= ci_populate_single_graphic_level(rdev
,
2803 dpm_table
->sclk_table
.dpm_levels
[i
].value
,
2804 (u16
)pi
->activity_target
[i
],
2805 &pi
->smc_state_table
.GraphicsLevel
[i
]);
2808 if (i
== (dpm_table
->sclk_table
.count
- 1))
2809 pi
->smc_state_table
.GraphicsLevel
[i
].DisplayWatermark
=
2810 PPSMC_DISPLAY_WATERMARK_HIGH
;
2813 pi
->smc_state_table
.GraphicsDpmLevelCount
= (u8
)dpm_table
->sclk_table
.count
;
2814 pi
->dpm_level_enable_mask
.sclk_dpm_enable_mask
=
2815 ci_get_dpm_level_enable_mask_value(&dpm_table
->sclk_table
);
2817 ret
= ci_copy_bytes_to_smc(rdev
, level_array_address
,
2818 (u8
*)levels
, level_array_size
,
2826 static int ci_populate_ulv_state(struct radeon_device
*rdev
,
2827 SMU7_Discrete_Ulv
*ulv_level
)
2829 return ci_populate_ulv_level(rdev
, ulv_level
);
2832 static int ci_populate_all_memory_levels(struct radeon_device
*rdev
)
2834 struct ci_power_info
*pi
= ci_get_pi(rdev
);
2835 struct ci_dpm_table
*dpm_table
= &pi
->dpm_table
;
2836 u32 level_array_address
= pi
->dpm_table_start
+
2837 offsetof(SMU7_Discrete_DpmTable
, MemoryLevel
);
2838 u32 level_array_size
= sizeof(SMU7_Discrete_MemoryLevel
) *
2839 SMU7_MAX_LEVELS_MEMORY
;
2840 SMU7_Discrete_MemoryLevel
*levels
= pi
->smc_state_table
.MemoryLevel
;
2843 memset(levels
, 0, level_array_size
);
2845 for (i
= 0; i
< dpm_table
->mclk_table
.count
; i
++) {
2846 if (dpm_table
->mclk_table
.dpm_levels
[i
].value
== 0)
2848 ret
= ci_populate_single_memory_level(rdev
,
2849 dpm_table
->mclk_table
.dpm_levels
[i
].value
,
2850 &pi
->smc_state_table
.MemoryLevel
[i
]);
2855 pi
->smc_state_table
.MemoryLevel
[0].ActivityLevel
= cpu_to_be16(0x1F);
2857 pi
->smc_state_table
.MemoryDpmLevelCount
= (u8
)dpm_table
->mclk_table
.count
;
2858 pi
->dpm_level_enable_mask
.mclk_dpm_enable_mask
=
2859 ci_get_dpm_level_enable_mask_value(&dpm_table
->mclk_table
);
2861 pi
->smc_state_table
.MemoryLevel
[dpm_table
->mclk_table
.count
- 1].DisplayWatermark
=
2862 PPSMC_DISPLAY_WATERMARK_HIGH
;
2864 ret
= ci_copy_bytes_to_smc(rdev
, level_array_address
,
2865 (u8
*)levels
, level_array_size
,
2873 static void ci_reset_single_dpm_table(struct radeon_device
*rdev
,
2874 struct ci_single_dpm_table
* dpm_table
,
2879 dpm_table
->count
= count
;
2880 for (i
= 0; i
< MAX_REGULAR_DPM_NUMBER
; i
++)
2881 dpm_table
->dpm_levels
[i
].enabled
= false;
2884 static void ci_setup_pcie_table_entry(struct ci_single_dpm_table
* dpm_table
,
2885 u32 index
, u32 pcie_gen
, u32 pcie_lanes
)
2887 dpm_table
->dpm_levels
[index
].value
= pcie_gen
;
2888 dpm_table
->dpm_levels
[index
].param1
= pcie_lanes
;
2889 dpm_table
->dpm_levels
[index
].enabled
= true;
2892 static int ci_setup_default_pcie_tables(struct radeon_device
*rdev
)
2894 struct ci_power_info
*pi
= ci_get_pi(rdev
);
2896 if (!pi
->use_pcie_performance_levels
&& !pi
->use_pcie_powersaving_levels
)
2899 if (pi
->use_pcie_performance_levels
&& !pi
->use_pcie_powersaving_levels
) {
2900 pi
->pcie_gen_powersaving
= pi
->pcie_gen_performance
;
2901 pi
->pcie_lane_powersaving
= pi
->pcie_lane_performance
;
2902 } else if (!pi
->use_pcie_performance_levels
&& pi
->use_pcie_powersaving_levels
) {
2903 pi
->pcie_gen_performance
= pi
->pcie_gen_powersaving
;
2904 pi
->pcie_lane_performance
= pi
->pcie_lane_powersaving
;
2907 ci_reset_single_dpm_table(rdev
,
2908 &pi
->dpm_table
.pcie_speed_table
,
2909 SMU7_MAX_LEVELS_LINK
);
2911 ci_setup_pcie_table_entry(&pi
->dpm_table
.pcie_speed_table
, 0,
2912 pi
->pcie_gen_powersaving
.min
,
2913 pi
->pcie_lane_powersaving
.min
);
2914 ci_setup_pcie_table_entry(&pi
->dpm_table
.pcie_speed_table
, 1,
2915 pi
->pcie_gen_performance
.min
,
2916 pi
->pcie_lane_performance
.min
);
2917 ci_setup_pcie_table_entry(&pi
->dpm_table
.pcie_speed_table
, 2,
2918 pi
->pcie_gen_powersaving
.min
,
2919 pi
->pcie_lane_powersaving
.max
);
2920 ci_setup_pcie_table_entry(&pi
->dpm_table
.pcie_speed_table
, 3,
2921 pi
->pcie_gen_performance
.min
,
2922 pi
->pcie_lane_performance
.max
);
2923 ci_setup_pcie_table_entry(&pi
->dpm_table
.pcie_speed_table
, 4,
2924 pi
->pcie_gen_powersaving
.max
,
2925 pi
->pcie_lane_powersaving
.max
);
2926 ci_setup_pcie_table_entry(&pi
->dpm_table
.pcie_speed_table
, 5,
2927 pi
->pcie_gen_performance
.max
,
2928 pi
->pcie_lane_performance
.max
);
2930 pi
->dpm_table
.pcie_speed_table
.count
= 6;
2935 static int ci_setup_default_dpm_tables(struct radeon_device
*rdev
)
2937 struct ci_power_info
*pi
= ci_get_pi(rdev
);
2938 struct radeon_clock_voltage_dependency_table
*allowed_sclk_vddc_table
=
2939 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
;
2940 struct radeon_clock_voltage_dependency_table
*allowed_mclk_table
=
2941 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_mclk
;
2942 struct radeon_cac_leakage_table
*std_voltage_table
=
2943 &rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
;
2946 if (allowed_sclk_vddc_table
== NULL
)
2948 if (allowed_sclk_vddc_table
->count
< 1)
2950 if (allowed_mclk_table
== NULL
)
2952 if (allowed_mclk_table
->count
< 1)
2955 memset(&pi
->dpm_table
, 0, sizeof(struct ci_dpm_table
));
2957 ci_reset_single_dpm_table(rdev
,
2958 &pi
->dpm_table
.sclk_table
,
2959 SMU7_MAX_LEVELS_GRAPHICS
);
2960 ci_reset_single_dpm_table(rdev
,
2961 &pi
->dpm_table
.mclk_table
,
2962 SMU7_MAX_LEVELS_MEMORY
);
2963 ci_reset_single_dpm_table(rdev
,
2964 &pi
->dpm_table
.vddc_table
,
2965 SMU7_MAX_LEVELS_VDDC
);
2966 ci_reset_single_dpm_table(rdev
,
2967 &pi
->dpm_table
.vddci_table
,
2968 SMU7_MAX_LEVELS_VDDCI
);
2969 ci_reset_single_dpm_table(rdev
,
2970 &pi
->dpm_table
.mvdd_table
,
2971 SMU7_MAX_LEVELS_MVDD
);
2973 pi
->dpm_table
.sclk_table
.count
= 0;
2974 for (i
= 0; i
< allowed_sclk_vddc_table
->count
; i
++) {
2976 (pi
->dpm_table
.sclk_table
.dpm_levels
[pi
->dpm_table
.sclk_table
.count
-1].value
!=
2977 allowed_sclk_vddc_table
->entries
[i
].clk
)) {
2978 pi
->dpm_table
.sclk_table
.dpm_levels
[pi
->dpm_table
.sclk_table
.count
].value
=
2979 allowed_sclk_vddc_table
->entries
[i
].clk
;
2980 pi
->dpm_table
.sclk_table
.dpm_levels
[pi
->dpm_table
.sclk_table
.count
].enabled
= true;
2981 pi
->dpm_table
.sclk_table
.count
++;
2985 pi
->dpm_table
.mclk_table
.count
= 0;
2986 for (i
= 0; i
< allowed_mclk_table
->count
; i
++) {
2988 (pi
->dpm_table
.mclk_table
.dpm_levels
[pi
->dpm_table
.mclk_table
.count
-1].value
!=
2989 allowed_mclk_table
->entries
[i
].clk
)) {
2990 pi
->dpm_table
.mclk_table
.dpm_levels
[pi
->dpm_table
.mclk_table
.count
].value
=
2991 allowed_mclk_table
->entries
[i
].clk
;
2992 pi
->dpm_table
.mclk_table
.dpm_levels
[pi
->dpm_table
.mclk_table
.count
].enabled
= true;
2993 pi
->dpm_table
.mclk_table
.count
++;
2997 for (i
= 0; i
< allowed_sclk_vddc_table
->count
; i
++) {
2998 pi
->dpm_table
.vddc_table
.dpm_levels
[i
].value
=
2999 allowed_sclk_vddc_table
->entries
[i
].v
;
3000 pi
->dpm_table
.vddc_table
.dpm_levels
[i
].param1
=
3001 std_voltage_table
->entries
[i
].leakage
;
3002 pi
->dpm_table
.vddc_table
.dpm_levels
[i
].enabled
= true;
3004 pi
->dpm_table
.vddc_table
.count
= allowed_sclk_vddc_table
->count
;
3006 allowed_mclk_table
= &rdev
->pm
.dpm
.dyn_state
.vddci_dependency_on_mclk
;
3007 if (allowed_mclk_table
) {
3008 for (i
= 0; i
< allowed_mclk_table
->count
; i
++) {
3009 pi
->dpm_table
.vddci_table
.dpm_levels
[i
].value
=
3010 allowed_mclk_table
->entries
[i
].v
;
3011 pi
->dpm_table
.vddci_table
.dpm_levels
[i
].enabled
= true;
3013 pi
->dpm_table
.vddci_table
.count
= allowed_mclk_table
->count
;
3016 allowed_mclk_table
= &rdev
->pm
.dpm
.dyn_state
.mvdd_dependency_on_mclk
;
3017 if (allowed_mclk_table
) {
3018 for (i
= 0; i
< allowed_mclk_table
->count
; i
++) {
3019 pi
->dpm_table
.mvdd_table
.dpm_levels
[i
].value
=
3020 allowed_mclk_table
->entries
[i
].v
;
3021 pi
->dpm_table
.mvdd_table
.dpm_levels
[i
].enabled
= true;
3023 pi
->dpm_table
.mvdd_table
.count
= allowed_mclk_table
->count
;
3026 ci_setup_default_pcie_tables(rdev
);
3031 static int ci_find_boot_level(struct ci_single_dpm_table
*table
,
3032 u32 value
, u32
*boot_level
)
3037 for(i
= 0; i
< table
->count
; i
++) {
3038 if (value
== table
->dpm_levels
[i
].value
) {
3047 static int ci_init_smc_table(struct radeon_device
*rdev
)
3049 struct ci_power_info
*pi
= ci_get_pi(rdev
);
3050 struct ci_ulv_parm
*ulv
= &pi
->ulv
;
3051 struct radeon_ps
*radeon_boot_state
= rdev
->pm
.dpm
.boot_ps
;
3052 SMU7_Discrete_DpmTable
*table
= &pi
->smc_state_table
;
3055 ret
= ci_setup_default_dpm_tables(rdev
);
3059 if (pi
->voltage_control
!= CISLANDS_VOLTAGE_CONTROL_NONE
)
3060 ci_populate_smc_voltage_tables(rdev
, table
);
3062 ci_init_fps_limits(rdev
);
3064 if (rdev
->pm
.dpm
.platform_caps
& ATOM_PP_PLATFORM_CAP_HARDWAREDC
)
3065 table
->SystemFlags
|= PPSMC_SYSTEMFLAG_GPIO_DC
;
3067 if (rdev
->pm
.dpm
.platform_caps
& ATOM_PP_PLATFORM_CAP_STEPVDDC
)
3068 table
->SystemFlags
|= PPSMC_SYSTEMFLAG_STEPVDDC
;
3071 table
->SystemFlags
|= PPSMC_SYSTEMFLAG_GDDR5
;
3073 if (ulv
->supported
) {
3074 ret
= ci_populate_ulv_state(rdev
, &pi
->smc_state_table
.Ulv
);
3077 WREG32_SMC(CG_ULV_PARAMETER
, ulv
->cg_ulv_parameter
);
3080 ret
= ci_populate_all_graphic_levels(rdev
);
3084 ret
= ci_populate_all_memory_levels(rdev
);
3088 ci_populate_smc_link_level(rdev
, table
);
3090 ret
= ci_populate_smc_acpi_level(rdev
, table
);
3094 ret
= ci_populate_smc_vce_level(rdev
, table
);
3098 ret
= ci_populate_smc_acp_level(rdev
, table
);
3102 ret
= ci_populate_smc_samu_level(rdev
, table
);
3106 ret
= ci_do_program_memory_timing_parameters(rdev
);
3110 ret
= ci_populate_smc_uvd_level(rdev
, table
);
3114 table
->UvdBootLevel
= 0;
3115 table
->VceBootLevel
= 0;
3116 table
->AcpBootLevel
= 0;
3117 table
->SamuBootLevel
= 0;
3118 table
->GraphicsBootLevel
= 0;
3119 table
->MemoryBootLevel
= 0;
3121 ret
= ci_find_boot_level(&pi
->dpm_table
.sclk_table
,
3122 pi
->vbios_boot_state
.sclk_bootup_value
,
3123 (u32
*)&pi
->smc_state_table
.GraphicsBootLevel
);
3125 ret
= ci_find_boot_level(&pi
->dpm_table
.mclk_table
,
3126 pi
->vbios_boot_state
.mclk_bootup_value
,
3127 (u32
*)&pi
->smc_state_table
.MemoryBootLevel
);
3129 table
->BootVddc
= pi
->vbios_boot_state
.vddc_bootup_value
;
3130 table
->BootVddci
= pi
->vbios_boot_state
.vddci_bootup_value
;
3131 table
->BootMVdd
= pi
->vbios_boot_state
.mvdd_bootup_value
;
3133 ci_populate_smc_initial_state(rdev
, radeon_boot_state
);
3135 ret
= ci_populate_bapm_parameters_in_dpm_table(rdev
);
3139 table
->UVDInterval
= 1;
3140 table
->VCEInterval
= 1;
3141 table
->ACPInterval
= 1;
3142 table
->SAMUInterval
= 1;
3143 table
->GraphicsVoltageChangeEnable
= 1;
3144 table
->GraphicsThermThrottleEnable
= 1;
3145 table
->GraphicsInterval
= 1;
3146 table
->VoltageInterval
= 1;
3147 table
->ThermalInterval
= 1;
3148 table
->TemperatureLimitHigh
= (u16
)((pi
->thermal_temp_setting
.temperature_high
*
3149 CISLANDS_Q88_FORMAT_CONVERSION_UNIT
) / 1000);
3150 table
->TemperatureLimitLow
= (u16
)((pi
->thermal_temp_setting
.temperature_low
*
3151 CISLANDS_Q88_FORMAT_CONVERSION_UNIT
) / 1000);
3152 table
->MemoryVoltageChangeEnable
= 1;
3153 table
->MemoryInterval
= 1;
3154 table
->VoltageResponseTime
= 0;
3155 table
->VddcVddciDelta
= 4000;
3156 table
->PhaseResponseTime
= 0;
3157 table
->MemoryThermThrottleEnable
= 1;
3158 table
->PCIeBootLinkLevel
= 0;
3159 table
->PCIeGenInterval
= 1;
3160 if (pi
->voltage_control
== CISLANDS_VOLTAGE_CONTROL_BY_SVID2
)
3161 table
->SVI2Enable
= 1;
3163 table
->SVI2Enable
= 0;
3165 table
->ThermGpio
= 17;
3166 table
->SclkStepSize
= 0x4000;
3168 table
->SystemFlags
= cpu_to_be32(table
->SystemFlags
);
3169 table
->SmioMaskVddcVid
= cpu_to_be32(table
->SmioMaskVddcVid
);
3170 table
->SmioMaskVddcPhase
= cpu_to_be32(table
->SmioMaskVddcPhase
);
3171 table
->SmioMaskVddciVid
= cpu_to_be32(table
->SmioMaskVddciVid
);
3172 table
->SmioMaskMvddVid
= cpu_to_be32(table
->SmioMaskMvddVid
);
3173 table
->SclkStepSize
= cpu_to_be32(table
->SclkStepSize
);
3174 table
->TemperatureLimitHigh
= cpu_to_be16(table
->TemperatureLimitHigh
);
3175 table
->TemperatureLimitLow
= cpu_to_be16(table
->TemperatureLimitLow
);
3176 table
->VddcVddciDelta
= cpu_to_be16(table
->VddcVddciDelta
);
3177 table
->VoltageResponseTime
= cpu_to_be16(table
->VoltageResponseTime
);
3178 table
->PhaseResponseTime
= cpu_to_be16(table
->PhaseResponseTime
);
3179 table
->BootVddc
= cpu_to_be16(table
->BootVddc
* VOLTAGE_SCALE
);
3180 table
->BootVddci
= cpu_to_be16(table
->BootVddci
* VOLTAGE_SCALE
);
3181 table
->BootMVdd
= cpu_to_be16(table
->BootMVdd
* VOLTAGE_SCALE
);
3183 ret
= ci_copy_bytes_to_smc(rdev
,
3184 pi
->dpm_table_start
+
3185 offsetof(SMU7_Discrete_DpmTable
, SystemFlags
),
3186 (u8
*)&table
->SystemFlags
,
3187 sizeof(SMU7_Discrete_DpmTable
) - 3 * sizeof(SMU7_PIDController
),
3195 static void ci_trim_single_dpm_states(struct radeon_device
*rdev
,
3196 struct ci_single_dpm_table
*dpm_table
,
3197 u32 low_limit
, u32 high_limit
)
3201 for (i
= 0; i
< dpm_table
->count
; i
++) {
3202 if ((dpm_table
->dpm_levels
[i
].value
< low_limit
) ||
3203 (dpm_table
->dpm_levels
[i
].value
> high_limit
))
3204 dpm_table
->dpm_levels
[i
].enabled
= false;
3206 dpm_table
->dpm_levels
[i
].enabled
= true;
3210 static void ci_trim_pcie_dpm_states(struct radeon_device
*rdev
,
3211 u32 speed_low
, u32 lanes_low
,
3212 u32 speed_high
, u32 lanes_high
)
3214 struct ci_power_info
*pi
= ci_get_pi(rdev
);
3215 struct ci_single_dpm_table
*pcie_table
= &pi
->dpm_table
.pcie_speed_table
;
3218 for (i
= 0; i
< pcie_table
->count
; i
++) {
3219 if ((pcie_table
->dpm_levels
[i
].value
< speed_low
) ||
3220 (pcie_table
->dpm_levels
[i
].param1
< lanes_low
) ||
3221 (pcie_table
->dpm_levels
[i
].value
> speed_high
) ||
3222 (pcie_table
->dpm_levels
[i
].param1
> lanes_high
))
3223 pcie_table
->dpm_levels
[i
].enabled
= false;
3225 pcie_table
->dpm_levels
[i
].enabled
= true;
3228 for (i
= 0; i
< pcie_table
->count
; i
++) {
3229 if (pcie_table
->dpm_levels
[i
].enabled
) {
3230 for (j
= i
+ 1; j
< pcie_table
->count
; j
++) {
3231 if (pcie_table
->dpm_levels
[j
].enabled
) {
3232 if ((pcie_table
->dpm_levels
[i
].value
== pcie_table
->dpm_levels
[j
].value
) &&
3233 (pcie_table
->dpm_levels
[i
].param1
== pcie_table
->dpm_levels
[j
].param1
))
3234 pcie_table
->dpm_levels
[j
].enabled
= false;
3241 static int ci_trim_dpm_states(struct radeon_device
*rdev
,
3242 struct radeon_ps
*radeon_state
)
3244 struct ci_ps
*state
= ci_get_ps(radeon_state
);
3245 struct ci_power_info
*pi
= ci_get_pi(rdev
);
3246 u32 high_limit_count
;
3248 if (state
->performance_level_count
< 1)
3251 if (state
->performance_level_count
== 1)
3252 high_limit_count
= 0;
3254 high_limit_count
= 1;
3256 ci_trim_single_dpm_states(rdev
,
3257 &pi
->dpm_table
.sclk_table
,
3258 state
->performance_levels
[0].sclk
,
3259 state
->performance_levels
[high_limit_count
].sclk
);
3261 ci_trim_single_dpm_states(rdev
,
3262 &pi
->dpm_table
.mclk_table
,
3263 state
->performance_levels
[0].mclk
,
3264 state
->performance_levels
[high_limit_count
].mclk
);
3266 ci_trim_pcie_dpm_states(rdev
,
3267 state
->performance_levels
[0].pcie_gen
,
3268 state
->performance_levels
[0].pcie_lane
,
3269 state
->performance_levels
[high_limit_count
].pcie_gen
,
3270 state
->performance_levels
[high_limit_count
].pcie_lane
);
3275 static int ci_apply_disp_minimum_voltage_request(struct radeon_device
*rdev
)
3277 struct radeon_clock_voltage_dependency_table
*disp_voltage_table
=
3278 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
;
3279 struct radeon_clock_voltage_dependency_table
*vddc_table
=
3280 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
;
3281 u32 requested_voltage
= 0;
3284 if (disp_voltage_table
== NULL
)
3286 if (!disp_voltage_table
->count
)
3289 for (i
= 0; i
< disp_voltage_table
->count
; i
++) {
3290 if (rdev
->clock
.current_dispclk
== disp_voltage_table
->entries
[i
].clk
)
3291 requested_voltage
= disp_voltage_table
->entries
[i
].v
;
3294 for (i
= 0; i
< vddc_table
->count
; i
++) {
3295 if (requested_voltage
<= vddc_table
->entries
[i
].v
) {
3296 requested_voltage
= vddc_table
->entries
[i
].v
;
3297 return (ci_send_msg_to_smc_with_parameter(rdev
,
3298 PPSMC_MSG_VddC_Request
,
3299 requested_voltage
* VOLTAGE_SCALE
) == PPSMC_Result_OK
) ?
3307 static int ci_upload_dpm_level_enable_mask(struct radeon_device
*rdev
)
3309 struct ci_power_info
*pi
= ci_get_pi(rdev
);
3310 PPSMC_Result result
;
3312 if (!pi
->sclk_dpm_key_disabled
) {
3313 if (pi
->dpm_level_enable_mask
.sclk_dpm_enable_mask
) {
3314 result
= ci_send_msg_to_smc_with_parameter(rdev
,
3315 PPSMC_MSG_SCLKDPM_SetEnabledMask
,
3316 pi
->dpm_level_enable_mask
.sclk_dpm_enable_mask
);
3317 if (result
!= PPSMC_Result_OK
)
3322 if (!pi
->mclk_dpm_key_disabled
) {
3323 if (pi
->dpm_level_enable_mask
.mclk_dpm_enable_mask
) {
3324 result
= ci_send_msg_to_smc_with_parameter(rdev
,
3325 PPSMC_MSG_MCLKDPM_SetEnabledMask
,
3326 pi
->dpm_level_enable_mask
.mclk_dpm_enable_mask
);
3327 if (result
!= PPSMC_Result_OK
)
3332 if (!pi
->pcie_dpm_key_disabled
) {
3333 if (pi
->dpm_level_enable_mask
.pcie_dpm_enable_mask
) {
3334 result
= ci_send_msg_to_smc_with_parameter(rdev
,
3335 PPSMC_MSG_PCIeDPM_SetEnabledMask
,
3336 pi
->dpm_level_enable_mask
.pcie_dpm_enable_mask
);
3337 if (result
!= PPSMC_Result_OK
)
3342 ci_apply_disp_minimum_voltage_request(rdev
);
3347 static void ci_find_dpm_states_clocks_in_dpm_table(struct radeon_device
*rdev
,
3348 struct radeon_ps
*radeon_state
)
3350 struct ci_power_info
*pi
= ci_get_pi(rdev
);
3351 struct ci_ps
*state
= ci_get_ps(radeon_state
);
3352 struct ci_single_dpm_table
*sclk_table
= &pi
->dpm_table
.sclk_table
;
3353 u32 sclk
= state
->performance_levels
[state
->performance_level_count
-1].sclk
;
3354 struct ci_single_dpm_table
*mclk_table
= &pi
->dpm_table
.mclk_table
;
3355 u32 mclk
= state
->performance_levels
[state
->performance_level_count
-1].mclk
;
3358 pi
->need_update_smu7_dpm_table
= 0;
3360 for (i
= 0; i
< sclk_table
->count
; i
++) {
3361 if (sclk
== sclk_table
->dpm_levels
[i
].value
)
3365 if (i
>= sclk_table
->count
) {
3366 pi
->need_update_smu7_dpm_table
|= DPMTABLE_OD_UPDATE_SCLK
;
3368 /* XXX check display min clock requirements */
3369 if (0 != CISLAND_MINIMUM_ENGINE_CLOCK
)
3370 pi
->need_update_smu7_dpm_table
|= DPMTABLE_UPDATE_SCLK
;
3373 for (i
= 0; i
< mclk_table
->count
; i
++) {
3374 if (mclk
== mclk_table
->dpm_levels
[i
].value
)
3378 if (i
>= mclk_table
->count
)
3379 pi
->need_update_smu7_dpm_table
|= DPMTABLE_OD_UPDATE_MCLK
;
3381 if (rdev
->pm
.dpm
.current_active_crtc_count
!=
3382 rdev
->pm
.dpm
.new_active_crtc_count
)
3383 pi
->need_update_smu7_dpm_table
|= DPMTABLE_UPDATE_MCLK
;
3386 static int ci_populate_and_upload_sclk_mclk_dpm_levels(struct radeon_device
*rdev
,
3387 struct radeon_ps
*radeon_state
)
3389 struct ci_power_info
*pi
= ci_get_pi(rdev
);
3390 struct ci_ps
*state
= ci_get_ps(radeon_state
);
3391 u32 sclk
= state
->performance_levels
[state
->performance_level_count
-1].sclk
;
3392 u32 mclk
= state
->performance_levels
[state
->performance_level_count
-1].mclk
;
3393 struct ci_dpm_table
*dpm_table
= &pi
->dpm_table
;
3396 if (!pi
->need_update_smu7_dpm_table
)
3399 if (pi
->need_update_smu7_dpm_table
& DPMTABLE_OD_UPDATE_SCLK
)
3400 dpm_table
->sclk_table
.dpm_levels
[dpm_table
->sclk_table
.count
-1].value
= sclk
;
3402 if (pi
->need_update_smu7_dpm_table
& DPMTABLE_OD_UPDATE_MCLK
)
3403 dpm_table
->mclk_table
.dpm_levels
[dpm_table
->mclk_table
.count
-1].value
= mclk
;
3405 if (pi
->need_update_smu7_dpm_table
& (DPMTABLE_OD_UPDATE_SCLK
| DPMTABLE_UPDATE_SCLK
)) {
3406 ret
= ci_populate_all_graphic_levels(rdev
);
3411 if (pi
->need_update_smu7_dpm_table
& (DPMTABLE_OD_UPDATE_MCLK
| DPMTABLE_UPDATE_MCLK
)) {
3412 ret
= ci_populate_all_memory_levels(rdev
);
3420 static int ci_enable_uvd_dpm(struct radeon_device
*rdev
, bool enable
)
3422 struct ci_power_info
*pi
= ci_get_pi(rdev
);
3423 const struct radeon_clock_and_voltage_limits
*max_limits
;
3426 if (rdev
->pm
.dpm
.ac_power
)
3427 max_limits
= &rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
;
3429 max_limits
= &rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_dc
;
3432 pi
->dpm_level_enable_mask
.uvd_dpm_enable_mask
= 0;
3434 for (i
= rdev
->pm
.dpm
.dyn_state
.uvd_clock_voltage_dependency_table
.count
- 1; i
>= 0; i
--) {
3435 if (rdev
->pm
.dpm
.dyn_state
.uvd_clock_voltage_dependency_table
.entries
[i
].v
<= max_limits
->vddc
) {
3436 pi
->dpm_level_enable_mask
.uvd_dpm_enable_mask
|= 1 << i
;
3438 if (!pi
->caps_uvd_dpm
)
3443 ci_send_msg_to_smc_with_parameter(rdev
,
3444 PPSMC_MSG_UVDDPM_SetEnabledMask
,
3445 pi
->dpm_level_enable_mask
.uvd_dpm_enable_mask
);
3447 if (pi
->last_mclk_dpm_enable_mask
& 0x1) {
3448 pi
->uvd_enabled
= true;
3449 pi
->dpm_level_enable_mask
.mclk_dpm_enable_mask
&= 0xFFFFFFFE;
3450 ci_send_msg_to_smc_with_parameter(rdev
,
3451 PPSMC_MSG_MCLKDPM_SetEnabledMask
,
3452 pi
->dpm_level_enable_mask
.mclk_dpm_enable_mask
);
3455 if (pi
->last_mclk_dpm_enable_mask
& 0x1) {
3456 pi
->uvd_enabled
= false;
3457 pi
->dpm_level_enable_mask
.mclk_dpm_enable_mask
|= 1;
3458 ci_send_msg_to_smc_with_parameter(rdev
,
3459 PPSMC_MSG_MCLKDPM_SetEnabledMask
,
3460 pi
->dpm_level_enable_mask
.mclk_dpm_enable_mask
);
3464 return (ci_send_msg_to_smc(rdev
, enable
?
3465 PPSMC_MSG_UVDDPM_Enable
: PPSMC_MSG_UVDDPM_Disable
) == PPSMC_Result_OK
) ?
3469 static int ci_enable_vce_dpm(struct radeon_device
*rdev
, bool enable
)
3471 struct ci_power_info
*pi
= ci_get_pi(rdev
);
3472 const struct radeon_clock_and_voltage_limits
*max_limits
;
3475 if (rdev
->pm
.dpm
.ac_power
)
3476 max_limits
= &rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
;
3478 max_limits
= &rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_dc
;
3481 pi
->dpm_level_enable_mask
.vce_dpm_enable_mask
= 0;
3482 for (i
= rdev
->pm
.dpm
.dyn_state
.vce_clock_voltage_dependency_table
.count
- 1; i
>= 0; i
--) {
3483 if (rdev
->pm
.dpm
.dyn_state
.vce_clock_voltage_dependency_table
.entries
[i
].v
<= max_limits
->vddc
) {
3484 pi
->dpm_level_enable_mask
.vce_dpm_enable_mask
|= 1 << i
;
3486 if (!pi
->caps_vce_dpm
)
3491 ci_send_msg_to_smc_with_parameter(rdev
,
3492 PPSMC_MSG_VCEDPM_SetEnabledMask
,
3493 pi
->dpm_level_enable_mask
.vce_dpm_enable_mask
);
3496 return (ci_send_msg_to_smc(rdev
, enable
?
3497 PPSMC_MSG_VCEDPM_Enable
: PPSMC_MSG_VCEDPM_Disable
) == PPSMC_Result_OK
) ?
3502 static int ci_enable_samu_dpm(struct radeon_device
*rdev
, bool enable
)
3504 struct ci_power_info
*pi
= ci_get_pi(rdev
);
3505 const struct radeon_clock_and_voltage_limits
*max_limits
;
3508 if (rdev
->pm
.dpm
.ac_power
)
3509 max_limits
= &rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
;
3511 max_limits
= &rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_dc
;
3514 pi
->dpm_level_enable_mask
.samu_dpm_enable_mask
= 0;
3515 for (i
= rdev
->pm
.dpm
.dyn_state
.samu_clock_voltage_dependency_table
.count
- 1; i
>= 0; i
--) {
3516 if (rdev
->pm
.dpm
.dyn_state
.samu_clock_voltage_dependency_table
.entries
[i
].v
<= max_limits
->vddc
) {
3517 pi
->dpm_level_enable_mask
.samu_dpm_enable_mask
|= 1 << i
;
3519 if (!pi
->caps_samu_dpm
)
3524 ci_send_msg_to_smc_with_parameter(rdev
,
3525 PPSMC_MSG_SAMUDPM_SetEnabledMask
,
3526 pi
->dpm_level_enable_mask
.samu_dpm_enable_mask
);
3528 return (ci_send_msg_to_smc(rdev
, enable
?
3529 PPSMC_MSG_SAMUDPM_Enable
: PPSMC_MSG_SAMUDPM_Disable
) == PPSMC_Result_OK
) ?
3533 static int ci_enable_acp_dpm(struct radeon_device
*rdev
, bool enable
)
3535 struct ci_power_info
*pi
= ci_get_pi(rdev
);
3536 const struct radeon_clock_and_voltage_limits
*max_limits
;
3539 if (rdev
->pm
.dpm
.ac_power
)
3540 max_limits
= &rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
;
3542 max_limits
= &rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_dc
;
3545 pi
->dpm_level_enable_mask
.acp_dpm_enable_mask
= 0;
3546 for (i
= rdev
->pm
.dpm
.dyn_state
.acp_clock_voltage_dependency_table
.count
- 1; i
>= 0; i
--) {
3547 if (rdev
->pm
.dpm
.dyn_state
.acp_clock_voltage_dependency_table
.entries
[i
].v
<= max_limits
->vddc
) {
3548 pi
->dpm_level_enable_mask
.acp_dpm_enable_mask
|= 1 << i
;
3550 if (!pi
->caps_acp_dpm
)
3555 ci_send_msg_to_smc_with_parameter(rdev
,
3556 PPSMC_MSG_ACPDPM_SetEnabledMask
,
3557 pi
->dpm_level_enable_mask
.acp_dpm_enable_mask
);
3560 return (ci_send_msg_to_smc(rdev
, enable
?
3561 PPSMC_MSG_ACPDPM_Enable
: PPSMC_MSG_ACPDPM_Disable
) == PPSMC_Result_OK
) ?
3566 static int ci_update_uvd_dpm(struct radeon_device
*rdev
, bool gate
)
3568 struct ci_power_info
*pi
= ci_get_pi(rdev
);
3572 if (pi
->caps_uvd_dpm
||
3573 (rdev
->pm
.dpm
.dyn_state
.uvd_clock_voltage_dependency_table
.count
<= 0))
3574 pi
->smc_state_table
.UvdBootLevel
= 0;
3576 pi
->smc_state_table
.UvdBootLevel
=
3577 rdev
->pm
.dpm
.dyn_state
.uvd_clock_voltage_dependency_table
.count
- 1;
3579 tmp
= RREG32_SMC(DPM_TABLE_475
);
3580 tmp
&= ~UvdBootLevel_MASK
;
3581 tmp
|= UvdBootLevel(pi
->smc_state_table
.UvdBootLevel
);
3582 WREG32_SMC(DPM_TABLE_475
, tmp
);
3585 return ci_enable_uvd_dpm(rdev
, !gate
);
3588 static u8
ci_get_vce_boot_level(struct radeon_device
*rdev
)
3591 u32 min_evclk
= 30000; /* ??? */
3592 struct radeon_vce_clock_voltage_dependency_table
*table
=
3593 &rdev
->pm
.dpm
.dyn_state
.vce_clock_voltage_dependency_table
;
3595 for (i
= 0; i
< table
->count
; i
++) {
3596 if (table
->entries
[i
].evclk
>= min_evclk
)
3600 return table
->count
- 1;
3603 static int ci_update_vce_dpm(struct radeon_device
*rdev
,
3604 struct radeon_ps
*radeon_new_state
,
3605 struct radeon_ps
*radeon_current_state
)
3607 struct ci_power_info
*pi
= ci_get_pi(rdev
);
3611 if (radeon_current_state
->evclk
!= radeon_new_state
->evclk
) {
3612 if (radeon_new_state
->evclk
) {
3613 /* turn the clocks on when encoding */
3614 cik_update_cg(rdev
, RADEON_CG_BLOCK_VCE
, false);
3616 pi
->smc_state_table
.VceBootLevel
= ci_get_vce_boot_level(rdev
);
3617 tmp
= RREG32_SMC(DPM_TABLE_475
);
3618 tmp
&= ~VceBootLevel_MASK
;
3619 tmp
|= VceBootLevel(pi
->smc_state_table
.VceBootLevel
);
3620 WREG32_SMC(DPM_TABLE_475
, tmp
);
3622 ret
= ci_enable_vce_dpm(rdev
, true);
3624 /* turn the clocks off when not encoding */
3625 cik_update_cg(rdev
, RADEON_CG_BLOCK_VCE
, true);
3627 ret
= ci_enable_vce_dpm(rdev
, false);
3634 static int ci_update_samu_dpm(struct radeon_device
*rdev
, bool gate
)
3636 return ci_enable_samu_dpm(rdev
, gate
);
3639 static int ci_update_acp_dpm(struct radeon_device
*rdev
, bool gate
)
3641 struct ci_power_info
*pi
= ci_get_pi(rdev
);
3645 pi
->smc_state_table
.AcpBootLevel
= 0;
3647 tmp
= RREG32_SMC(DPM_TABLE_475
);
3648 tmp
&= ~AcpBootLevel_MASK
;
3649 tmp
|= AcpBootLevel(pi
->smc_state_table
.AcpBootLevel
);
3650 WREG32_SMC(DPM_TABLE_475
, tmp
);
3653 return ci_enable_acp_dpm(rdev
, !gate
);
3657 static int ci_generate_dpm_level_enable_mask(struct radeon_device
*rdev
,
3658 struct radeon_ps
*radeon_state
)
3660 struct ci_power_info
*pi
= ci_get_pi(rdev
);
3663 ret
= ci_trim_dpm_states(rdev
, radeon_state
);
3667 pi
->dpm_level_enable_mask
.sclk_dpm_enable_mask
=
3668 ci_get_dpm_level_enable_mask_value(&pi
->dpm_table
.sclk_table
);
3669 pi
->dpm_level_enable_mask
.mclk_dpm_enable_mask
=
3670 ci_get_dpm_level_enable_mask_value(&pi
->dpm_table
.mclk_table
);
3671 pi
->last_mclk_dpm_enable_mask
=
3672 pi
->dpm_level_enable_mask
.mclk_dpm_enable_mask
;
3673 if (pi
->uvd_enabled
) {
3674 if (pi
->dpm_level_enable_mask
.mclk_dpm_enable_mask
& 1)
3675 pi
->dpm_level_enable_mask
.mclk_dpm_enable_mask
&= 0xFFFFFFFE;
3677 pi
->dpm_level_enable_mask
.pcie_dpm_enable_mask
=
3678 ci_get_dpm_level_enable_mask_value(&pi
->dpm_table
.pcie_speed_table
);
3683 static u32
ci_get_lowest_enabled_level(struct radeon_device
*rdev
,
3688 while ((level_mask
& (1 << level
)) == 0)
3695 int ci_dpm_force_performance_level(struct radeon_device
*rdev
,
3696 enum radeon_dpm_forced_level level
)
3698 struct ci_power_info
*pi
= ci_get_pi(rdev
);
3699 PPSMC_Result smc_result
;
3703 if (level
== RADEON_DPM_FORCED_LEVEL_HIGH
) {
3704 if ((!pi
->sclk_dpm_key_disabled
) &&
3705 pi
->dpm_level_enable_mask
.sclk_dpm_enable_mask
) {
3707 tmp
= pi
->dpm_level_enable_mask
.sclk_dpm_enable_mask
;
3711 ret
= ci_dpm_force_state_sclk(rdev
, levels
);
3714 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
3715 tmp
= (RREG32_SMC(TARGET_AND_CURRENT_PROFILE_INDEX
) &
3716 CURR_SCLK_INDEX_MASK
) >> CURR_SCLK_INDEX_SHIFT
;
3723 if ((!pi
->mclk_dpm_key_disabled
) &&
3724 pi
->dpm_level_enable_mask
.mclk_dpm_enable_mask
) {
3726 tmp
= pi
->dpm_level_enable_mask
.mclk_dpm_enable_mask
;
3730 ret
= ci_dpm_force_state_mclk(rdev
, levels
);
3733 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
3734 tmp
= (RREG32_SMC(TARGET_AND_CURRENT_PROFILE_INDEX
) &
3735 CURR_MCLK_INDEX_MASK
) >> CURR_MCLK_INDEX_SHIFT
;
3742 if ((!pi
->pcie_dpm_key_disabled
) &&
3743 pi
->dpm_level_enable_mask
.pcie_dpm_enable_mask
) {
3745 tmp
= pi
->dpm_level_enable_mask
.pcie_dpm_enable_mask
;
3749 ret
= ci_dpm_force_state_pcie(rdev
, level
);
3752 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
3753 tmp
= (RREG32_SMC(TARGET_AND_CURRENT_PROFILE_INDEX_1
) &
3754 CURR_PCIE_INDEX_MASK
) >> CURR_PCIE_INDEX_SHIFT
;
3761 } else if (level
== RADEON_DPM_FORCED_LEVEL_LOW
) {
3762 if ((!pi
->sclk_dpm_key_disabled
) &&
3763 pi
->dpm_level_enable_mask
.sclk_dpm_enable_mask
) {
3764 levels
= ci_get_lowest_enabled_level(rdev
,
3765 pi
->dpm_level_enable_mask
.sclk_dpm_enable_mask
);
3766 ret
= ci_dpm_force_state_sclk(rdev
, levels
);
3769 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
3770 tmp
= (RREG32_SMC(TARGET_AND_CURRENT_PROFILE_INDEX
) &
3771 CURR_SCLK_INDEX_MASK
) >> CURR_SCLK_INDEX_SHIFT
;
3777 if ((!pi
->mclk_dpm_key_disabled
) &&
3778 pi
->dpm_level_enable_mask
.mclk_dpm_enable_mask
) {
3779 levels
= ci_get_lowest_enabled_level(rdev
,
3780 pi
->dpm_level_enable_mask
.mclk_dpm_enable_mask
);
3781 ret
= ci_dpm_force_state_mclk(rdev
, levels
);
3784 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
3785 tmp
= (RREG32_SMC(TARGET_AND_CURRENT_PROFILE_INDEX
) &
3786 CURR_MCLK_INDEX_MASK
) >> CURR_MCLK_INDEX_SHIFT
;
3792 if ((!pi
->pcie_dpm_key_disabled
) &&
3793 pi
->dpm_level_enable_mask
.pcie_dpm_enable_mask
) {
3794 levels
= ci_get_lowest_enabled_level(rdev
,
3795 pi
->dpm_level_enable_mask
.pcie_dpm_enable_mask
);
3796 ret
= ci_dpm_force_state_pcie(rdev
, levels
);
3799 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
3800 tmp
= (RREG32_SMC(TARGET_AND_CURRENT_PROFILE_INDEX_1
) &
3801 CURR_PCIE_INDEX_MASK
) >> CURR_PCIE_INDEX_SHIFT
;
3807 } else if (level
== RADEON_DPM_FORCED_LEVEL_AUTO
) {
3808 if (!pi
->sclk_dpm_key_disabled
) {
3809 smc_result
= ci_send_msg_to_smc(rdev
, PPSMC_MSG_NoForcedLevel
);
3810 if (smc_result
!= PPSMC_Result_OK
)
3813 if (!pi
->mclk_dpm_key_disabled
) {
3814 smc_result
= ci_send_msg_to_smc(rdev
, PPSMC_MSG_MCLKDPM_NoForcedLevel
);
3815 if (smc_result
!= PPSMC_Result_OK
)
3818 if (!pi
->pcie_dpm_key_disabled
) {
3819 smc_result
= ci_send_msg_to_smc(rdev
, PPSMC_MSG_PCIeDPM_UnForceLevel
);
3820 if (smc_result
!= PPSMC_Result_OK
)
3825 rdev
->pm
.dpm
.forced_level
= level
;
3830 static int ci_set_mc_special_registers(struct radeon_device
*rdev
,
3831 struct ci_mc_reg_table
*table
)
3833 struct ci_power_info
*pi
= ci_get_pi(rdev
);
3837 for (i
= 0, j
= table
->last
; i
< table
->last
; i
++) {
3838 if (j
>= SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE
)
3840 switch(table
->mc_reg_address
[i
].s1
<< 2) {
3842 temp_reg
= RREG32(MC_PMG_CMD_EMRS
);
3843 table
->mc_reg_address
[j
].s1
= MC_PMG_CMD_EMRS
>> 2;
3844 table
->mc_reg_address
[j
].s0
= MC_SEQ_PMG_CMD_EMRS_LP
>> 2;
3845 for (k
= 0; k
< table
->num_entries
; k
++) {
3846 table
->mc_reg_table_entry
[k
].mc_data
[j
] =
3847 ((temp_reg
& 0xffff0000)) | ((table
->mc_reg_table_entry
[k
].mc_data
[i
] & 0xffff0000) >> 16);
3850 if (j
>= SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE
)
3853 temp_reg
= RREG32(MC_PMG_CMD_MRS
);
3854 table
->mc_reg_address
[j
].s1
= MC_PMG_CMD_MRS
>> 2;
3855 table
->mc_reg_address
[j
].s0
= MC_SEQ_PMG_CMD_MRS_LP
>> 2;
3856 for (k
= 0; k
< table
->num_entries
; k
++) {
3857 table
->mc_reg_table_entry
[k
].mc_data
[j
] =
3858 (temp_reg
& 0xffff0000) | (table
->mc_reg_table_entry
[k
].mc_data
[i
] & 0x0000ffff);
3860 table
->mc_reg_table_entry
[k
].mc_data
[j
] |= 0x100;
3863 if (j
> SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE
)
3866 if (!pi
->mem_gddr5
) {
3867 table
->mc_reg_address
[j
].s1
= MC_PMG_AUTO_CMD
>> 2;
3868 table
->mc_reg_address
[j
].s0
= MC_PMG_AUTO_CMD
>> 2;
3869 for (k
= 0; k
< table
->num_entries
; k
++) {
3870 table
->mc_reg_table_entry
[k
].mc_data
[j
] =
3871 (table
->mc_reg_table_entry
[k
].mc_data
[i
] & 0xffff0000) >> 16;
3874 if (j
> SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE
)
3878 case MC_SEQ_RESERVE_M
:
3879 temp_reg
= RREG32(MC_PMG_CMD_MRS1
);
3880 table
->mc_reg_address
[j
].s1
= MC_PMG_CMD_MRS1
>> 2;
3881 table
->mc_reg_address
[j
].s0
= MC_SEQ_PMG_CMD_MRS1_LP
>> 2;
3882 for (k
= 0; k
< table
->num_entries
; k
++) {
3883 table
->mc_reg_table_entry
[k
].mc_data
[j
] =
3884 (temp_reg
& 0xffff0000) | (table
->mc_reg_table_entry
[k
].mc_data
[i
] & 0x0000ffff);
3887 if (j
> SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE
)
3901 static bool ci_check_s0_mc_reg_index(u16 in_reg
, u16
*out_reg
)
3906 case MC_SEQ_RAS_TIMING
>> 2:
3907 *out_reg
= MC_SEQ_RAS_TIMING_LP
>> 2;
3909 case MC_SEQ_DLL_STBY
>> 2:
3910 *out_reg
= MC_SEQ_DLL_STBY_LP
>> 2;
3912 case MC_SEQ_G5PDX_CMD0
>> 2:
3913 *out_reg
= MC_SEQ_G5PDX_CMD0_LP
>> 2;
3915 case MC_SEQ_G5PDX_CMD1
>> 2:
3916 *out_reg
= MC_SEQ_G5PDX_CMD1_LP
>> 2;
3918 case MC_SEQ_G5PDX_CTRL
>> 2:
3919 *out_reg
= MC_SEQ_G5PDX_CTRL_LP
>> 2;
3921 case MC_SEQ_CAS_TIMING
>> 2:
3922 *out_reg
= MC_SEQ_CAS_TIMING_LP
>> 2;
3924 case MC_SEQ_MISC_TIMING
>> 2:
3925 *out_reg
= MC_SEQ_MISC_TIMING_LP
>> 2;
3927 case MC_SEQ_MISC_TIMING2
>> 2:
3928 *out_reg
= MC_SEQ_MISC_TIMING2_LP
>> 2;
3930 case MC_SEQ_PMG_DVS_CMD
>> 2:
3931 *out_reg
= MC_SEQ_PMG_DVS_CMD_LP
>> 2;
3933 case MC_SEQ_PMG_DVS_CTL
>> 2:
3934 *out_reg
= MC_SEQ_PMG_DVS_CTL_LP
>> 2;
3936 case MC_SEQ_RD_CTL_D0
>> 2:
3937 *out_reg
= MC_SEQ_RD_CTL_D0_LP
>> 2;
3939 case MC_SEQ_RD_CTL_D1
>> 2:
3940 *out_reg
= MC_SEQ_RD_CTL_D1_LP
>> 2;
3942 case MC_SEQ_WR_CTL_D0
>> 2:
3943 *out_reg
= MC_SEQ_WR_CTL_D0_LP
>> 2;
3945 case MC_SEQ_WR_CTL_D1
>> 2:
3946 *out_reg
= MC_SEQ_WR_CTL_D1_LP
>> 2;
3948 case MC_PMG_CMD_EMRS
>> 2:
3949 *out_reg
= MC_SEQ_PMG_CMD_EMRS_LP
>> 2;
3951 case MC_PMG_CMD_MRS
>> 2:
3952 *out_reg
= MC_SEQ_PMG_CMD_MRS_LP
>> 2;
3954 case MC_PMG_CMD_MRS1
>> 2:
3955 *out_reg
= MC_SEQ_PMG_CMD_MRS1_LP
>> 2;
3957 case MC_SEQ_PMG_TIMING
>> 2:
3958 *out_reg
= MC_SEQ_PMG_TIMING_LP
>> 2;
3960 case MC_PMG_CMD_MRS2
>> 2:
3961 *out_reg
= MC_SEQ_PMG_CMD_MRS2_LP
>> 2;
3963 case MC_SEQ_WR_CTL_2
>> 2:
3964 *out_reg
= MC_SEQ_WR_CTL_2_LP
>> 2;
3974 static void ci_set_valid_flag(struct ci_mc_reg_table
*table
)
3978 for (i
= 0; i
< table
->last
; i
++) {
3979 for (j
= 1; j
< table
->num_entries
; j
++) {
3980 if (table
->mc_reg_table_entry
[j
-1].mc_data
[i
] !=
3981 table
->mc_reg_table_entry
[j
].mc_data
[i
]) {
3982 table
->valid_flag
|= 1 << i
;
3989 static void ci_set_s0_mc_reg_index(struct ci_mc_reg_table
*table
)
3994 for (i
= 0; i
< table
->last
; i
++) {
3995 table
->mc_reg_address
[i
].s0
=
3996 ci_check_s0_mc_reg_index(table
->mc_reg_address
[i
].s1
, &address
) ?
3997 address
: table
->mc_reg_address
[i
].s1
;
4001 static int ci_copy_vbios_mc_reg_table(const struct atom_mc_reg_table
*table
,
4002 struct ci_mc_reg_table
*ci_table
)
4006 if (table
->last
> SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE
)
4008 if (table
->num_entries
> MAX_AC_TIMING_ENTRIES
)
4011 for (i
= 0; i
< table
->last
; i
++)
4012 ci_table
->mc_reg_address
[i
].s1
= table
->mc_reg_address
[i
].s1
;
4014 ci_table
->last
= table
->last
;
4016 for (i
= 0; i
< table
->num_entries
; i
++) {
4017 ci_table
->mc_reg_table_entry
[i
].mclk_max
=
4018 table
->mc_reg_table_entry
[i
].mclk_max
;
4019 for (j
= 0; j
< table
->last
; j
++)
4020 ci_table
->mc_reg_table_entry
[i
].mc_data
[j
] =
4021 table
->mc_reg_table_entry
[i
].mc_data
[j
];
4023 ci_table
->num_entries
= table
->num_entries
;
4028 static int ci_initialize_mc_reg_table(struct radeon_device
*rdev
)
4030 struct ci_power_info
*pi
= ci_get_pi(rdev
);
4031 struct atom_mc_reg_table
*table
;
4032 struct ci_mc_reg_table
*ci_table
= &pi
->mc_reg_table
;
4033 u8 module_index
= rv770_get_memory_module_index(rdev
);
4036 table
= kzalloc(sizeof(struct atom_mc_reg_table
), GFP_KERNEL
);
4040 WREG32(MC_SEQ_RAS_TIMING_LP
, RREG32(MC_SEQ_RAS_TIMING
));
4041 WREG32(MC_SEQ_CAS_TIMING_LP
, RREG32(MC_SEQ_CAS_TIMING
));
4042 WREG32(MC_SEQ_DLL_STBY_LP
, RREG32(MC_SEQ_DLL_STBY
));
4043 WREG32(MC_SEQ_G5PDX_CMD0_LP
, RREG32(MC_SEQ_G5PDX_CMD0
));
4044 WREG32(MC_SEQ_G5PDX_CMD1_LP
, RREG32(MC_SEQ_G5PDX_CMD1
));
4045 WREG32(MC_SEQ_G5PDX_CTRL_LP
, RREG32(MC_SEQ_G5PDX_CTRL
));
4046 WREG32(MC_SEQ_PMG_DVS_CMD_LP
, RREG32(MC_SEQ_PMG_DVS_CMD
));
4047 WREG32(MC_SEQ_PMG_DVS_CTL_LP
, RREG32(MC_SEQ_PMG_DVS_CTL
));
4048 WREG32(MC_SEQ_MISC_TIMING_LP
, RREG32(MC_SEQ_MISC_TIMING
));
4049 WREG32(MC_SEQ_MISC_TIMING2_LP
, RREG32(MC_SEQ_MISC_TIMING2
));
4050 WREG32(MC_SEQ_PMG_CMD_EMRS_LP
, RREG32(MC_PMG_CMD_EMRS
));
4051 WREG32(MC_SEQ_PMG_CMD_MRS_LP
, RREG32(MC_PMG_CMD_MRS
));
4052 WREG32(MC_SEQ_PMG_CMD_MRS1_LP
, RREG32(MC_PMG_CMD_MRS1
));
4053 WREG32(MC_SEQ_WR_CTL_D0_LP
, RREG32(MC_SEQ_WR_CTL_D0
));
4054 WREG32(MC_SEQ_WR_CTL_D1_LP
, RREG32(MC_SEQ_WR_CTL_D1
));
4055 WREG32(MC_SEQ_RD_CTL_D0_LP
, RREG32(MC_SEQ_RD_CTL_D0
));
4056 WREG32(MC_SEQ_RD_CTL_D1_LP
, RREG32(MC_SEQ_RD_CTL_D1
));
4057 WREG32(MC_SEQ_PMG_TIMING_LP
, RREG32(MC_SEQ_PMG_TIMING
));
4058 WREG32(MC_SEQ_PMG_CMD_MRS2_LP
, RREG32(MC_PMG_CMD_MRS2
));
4059 WREG32(MC_SEQ_WR_CTL_2_LP
, RREG32(MC_SEQ_WR_CTL_2
));
4061 ret
= radeon_atom_init_mc_reg_table(rdev
, module_index
, table
);
4065 ret
= ci_copy_vbios_mc_reg_table(table
, ci_table
);
4069 ci_set_s0_mc_reg_index(ci_table
);
4071 ret
= ci_set_mc_special_registers(rdev
, ci_table
);
4075 ci_set_valid_flag(ci_table
);
4083 static int ci_populate_mc_reg_addresses(struct radeon_device
*rdev
,
4084 SMU7_Discrete_MCRegisters
*mc_reg_table
)
4086 struct ci_power_info
*pi
= ci_get_pi(rdev
);
4089 for (i
= 0, j
= 0; j
< pi
->mc_reg_table
.last
; j
++) {
4090 if (pi
->mc_reg_table
.valid_flag
& (1 << j
)) {
4091 if (i
>= SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE
)
4093 mc_reg_table
->address
[i
].s0
= cpu_to_be16(pi
->mc_reg_table
.mc_reg_address
[j
].s0
);
4094 mc_reg_table
->address
[i
].s1
= cpu_to_be16(pi
->mc_reg_table
.mc_reg_address
[j
].s1
);
4099 mc_reg_table
->last
= (u8
)i
;
4104 static void ci_convert_mc_registers(const struct ci_mc_reg_entry
*entry
,
4105 SMU7_Discrete_MCRegisterSet
*data
,
4106 u32 num_entries
, u32 valid_flag
)
4110 for (i
= 0, j
= 0; j
< num_entries
; j
++) {
4111 if (valid_flag
& (1 << j
)) {
4112 data
->value
[i
] = cpu_to_be32(entry
->mc_data
[j
]);
4118 static void ci_convert_mc_reg_table_entry_to_smc(struct radeon_device
*rdev
,
4119 const u32 memory_clock
,
4120 SMU7_Discrete_MCRegisterSet
*mc_reg_table_data
)
4122 struct ci_power_info
*pi
= ci_get_pi(rdev
);
4125 for(i
= 0; i
< pi
->mc_reg_table
.num_entries
; i
++) {
4126 if (memory_clock
<= pi
->mc_reg_table
.mc_reg_table_entry
[i
].mclk_max
)
4130 if ((i
== pi
->mc_reg_table
.num_entries
) && (i
> 0))
4133 ci_convert_mc_registers(&pi
->mc_reg_table
.mc_reg_table_entry
[i
],
4134 mc_reg_table_data
, pi
->mc_reg_table
.last
,
4135 pi
->mc_reg_table
.valid_flag
);
4138 static void ci_convert_mc_reg_table_to_smc(struct radeon_device
*rdev
,
4139 SMU7_Discrete_MCRegisters
*mc_reg_table
)
4141 struct ci_power_info
*pi
= ci_get_pi(rdev
);
4144 for (i
= 0; i
< pi
->dpm_table
.mclk_table
.count
; i
++)
4145 ci_convert_mc_reg_table_entry_to_smc(rdev
,
4146 pi
->dpm_table
.mclk_table
.dpm_levels
[i
].value
,
4147 &mc_reg_table
->data
[i
]);
4150 static int ci_populate_initial_mc_reg_table(struct radeon_device
*rdev
)
4152 struct ci_power_info
*pi
= ci_get_pi(rdev
);
4155 memset(&pi
->smc_mc_reg_table
, 0, sizeof(SMU7_Discrete_MCRegisters
));
4157 ret
= ci_populate_mc_reg_addresses(rdev
, &pi
->smc_mc_reg_table
);
4160 ci_convert_mc_reg_table_to_smc(rdev
, &pi
->smc_mc_reg_table
);
4162 return ci_copy_bytes_to_smc(rdev
,
4163 pi
->mc_reg_table_start
,
4164 (u8
*)&pi
->smc_mc_reg_table
,
4165 sizeof(SMU7_Discrete_MCRegisters
),
4169 static int ci_update_and_upload_mc_reg_table(struct radeon_device
*rdev
)
4171 struct ci_power_info
*pi
= ci_get_pi(rdev
);
4173 if (!(pi
->need_update_smu7_dpm_table
& DPMTABLE_OD_UPDATE_MCLK
))
4176 memset(&pi
->smc_mc_reg_table
, 0, sizeof(SMU7_Discrete_MCRegisters
));
4178 ci_convert_mc_reg_table_to_smc(rdev
, &pi
->smc_mc_reg_table
);
4180 return ci_copy_bytes_to_smc(rdev
,
4181 pi
->mc_reg_table_start
+
4182 offsetof(SMU7_Discrete_MCRegisters
, data
[0]),
4183 (u8
*)&pi
->smc_mc_reg_table
.data
[0],
4184 sizeof(SMU7_Discrete_MCRegisterSet
) *
4185 pi
->dpm_table
.mclk_table
.count
,
4189 static void ci_enable_voltage_control(struct radeon_device
*rdev
)
4191 u32 tmp
= RREG32_SMC(GENERAL_PWRMGT
);
4193 tmp
|= VOLT_PWRMGT_EN
;
4194 WREG32_SMC(GENERAL_PWRMGT
, tmp
);
4197 static enum radeon_pcie_gen
ci_get_maximum_link_speed(struct radeon_device
*rdev
,
4198 struct radeon_ps
*radeon_state
)
4200 struct ci_ps
*state
= ci_get_ps(radeon_state
);
4202 u16 pcie_speed
, max_speed
= 0;
4204 for (i
= 0; i
< state
->performance_level_count
; i
++) {
4205 pcie_speed
= state
->performance_levels
[i
].pcie_gen
;
4206 if (max_speed
< pcie_speed
)
4207 max_speed
= pcie_speed
;
4213 static u16
ci_get_current_pcie_speed(struct radeon_device
*rdev
)
4217 speed_cntl
= RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL
) & LC_CURRENT_DATA_RATE_MASK
;
4218 speed_cntl
>>= LC_CURRENT_DATA_RATE_SHIFT
;
4220 return (u16
)speed_cntl
;
4223 static int ci_get_current_pcie_lane_number(struct radeon_device
*rdev
)
4227 link_width
= RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL
) & LC_LINK_WIDTH_RD_MASK
;
4228 link_width
>>= LC_LINK_WIDTH_RD_SHIFT
;
4230 switch (link_width
) {
4231 case RADEON_PCIE_LC_LINK_WIDTH_X1
:
4233 case RADEON_PCIE_LC_LINK_WIDTH_X2
:
4235 case RADEON_PCIE_LC_LINK_WIDTH_X4
:
4237 case RADEON_PCIE_LC_LINK_WIDTH_X8
:
4239 case RADEON_PCIE_LC_LINK_WIDTH_X12
:
4240 /* not actually supported */
4242 case RADEON_PCIE_LC_LINK_WIDTH_X0
:
4243 case RADEON_PCIE_LC_LINK_WIDTH_X16
:
4249 static void ci_request_link_speed_change_before_state_change(struct radeon_device
*rdev
,
4250 struct radeon_ps
*radeon_new_state
,
4251 struct radeon_ps
*radeon_current_state
)
4253 struct ci_power_info
*pi
= ci_get_pi(rdev
);
4254 enum radeon_pcie_gen target_link_speed
=
4255 ci_get_maximum_link_speed(rdev
, radeon_new_state
);
4256 enum radeon_pcie_gen current_link_speed
;
4258 if (pi
->force_pcie_gen
== RADEON_PCIE_GEN_INVALID
)
4259 current_link_speed
= ci_get_maximum_link_speed(rdev
, radeon_current_state
);
4261 current_link_speed
= pi
->force_pcie_gen
;
4263 pi
->force_pcie_gen
= RADEON_PCIE_GEN_INVALID
;
4264 pi
->pspp_notify_required
= false;
4265 if (target_link_speed
> current_link_speed
) {
4266 switch (target_link_speed
) {
4268 case RADEON_PCIE_GEN3
:
4269 if (radeon_acpi_pcie_performance_request(rdev
, PCIE_PERF_REQ_PECI_GEN3
, false) == 0)
4271 pi
->force_pcie_gen
= RADEON_PCIE_GEN2
;
4272 if (current_link_speed
== RADEON_PCIE_GEN2
)
4274 case RADEON_PCIE_GEN2
:
4275 if (radeon_acpi_pcie_performance_request(rdev
, PCIE_PERF_REQ_PECI_GEN2
, false) == 0)
4279 pi
->force_pcie_gen
= ci_get_current_pcie_speed(rdev
);
4283 if (target_link_speed
< current_link_speed
)
4284 pi
->pspp_notify_required
= true;
4288 static void ci_notify_link_speed_change_after_state_change(struct radeon_device
*rdev
,
4289 struct radeon_ps
*radeon_new_state
,
4290 struct radeon_ps
*radeon_current_state
)
4292 struct ci_power_info
*pi
= ci_get_pi(rdev
);
4293 enum radeon_pcie_gen target_link_speed
=
4294 ci_get_maximum_link_speed(rdev
, radeon_new_state
);
4297 if (pi
->pspp_notify_required
) {
4298 if (target_link_speed
== RADEON_PCIE_GEN3
)
4299 request
= PCIE_PERF_REQ_PECI_GEN3
;
4300 else if (target_link_speed
== RADEON_PCIE_GEN2
)
4301 request
= PCIE_PERF_REQ_PECI_GEN2
;
4303 request
= PCIE_PERF_REQ_PECI_GEN1
;
4305 if ((request
== PCIE_PERF_REQ_PECI_GEN1
) &&
4306 (ci_get_current_pcie_speed(rdev
) > 0))
4310 radeon_acpi_pcie_performance_request(rdev
, request
, false);
4315 static int ci_set_private_data_variables_based_on_pptable(struct radeon_device
*rdev
)
4317 struct ci_power_info
*pi
= ci_get_pi(rdev
);
4318 struct radeon_clock_voltage_dependency_table
*allowed_sclk_vddc_table
=
4319 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
;
4320 struct radeon_clock_voltage_dependency_table
*allowed_mclk_vddc_table
=
4321 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_mclk
;
4322 struct radeon_clock_voltage_dependency_table
*allowed_mclk_vddci_table
=
4323 &rdev
->pm
.dpm
.dyn_state
.vddci_dependency_on_mclk
;
4325 if (allowed_sclk_vddc_table
== NULL
)
4327 if (allowed_sclk_vddc_table
->count
< 1)
4329 if (allowed_mclk_vddc_table
== NULL
)
4331 if (allowed_mclk_vddc_table
->count
< 1)
4333 if (allowed_mclk_vddci_table
== NULL
)
4335 if (allowed_mclk_vddci_table
->count
< 1)
4338 pi
->min_vddc_in_pp_table
= allowed_sclk_vddc_table
->entries
[0].v
;
4339 pi
->max_vddc_in_pp_table
=
4340 allowed_sclk_vddc_table
->entries
[allowed_sclk_vddc_table
->count
- 1].v
;
4342 pi
->min_vddci_in_pp_table
= allowed_mclk_vddci_table
->entries
[0].v
;
4343 pi
->max_vddci_in_pp_table
=
4344 allowed_mclk_vddci_table
->entries
[allowed_mclk_vddci_table
->count
- 1].v
;
4346 rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
.sclk
=
4347 allowed_sclk_vddc_table
->entries
[allowed_sclk_vddc_table
->count
- 1].clk
;
4348 rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
.mclk
=
4349 allowed_mclk_vddc_table
->entries
[allowed_sclk_vddc_table
->count
- 1].clk
;
4350 rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
.vddc
=
4351 allowed_sclk_vddc_table
->entries
[allowed_sclk_vddc_table
->count
- 1].v
;
4352 rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
.vddci
=
4353 allowed_mclk_vddci_table
->entries
[allowed_mclk_vddci_table
->count
- 1].v
;
4358 static void ci_patch_with_vddc_leakage(struct radeon_device
*rdev
, u16
*vddc
)
4360 struct ci_power_info
*pi
= ci_get_pi(rdev
);
4361 struct ci_leakage_voltage
*leakage_table
= &pi
->vddc_leakage
;
4364 for (leakage_index
= 0; leakage_index
< leakage_table
->count
; leakage_index
++) {
4365 if (leakage_table
->leakage_id
[leakage_index
] == *vddc
) {
4366 *vddc
= leakage_table
->actual_voltage
[leakage_index
];
4372 static void ci_patch_with_vddci_leakage(struct radeon_device
*rdev
, u16
*vddci
)
4374 struct ci_power_info
*pi
= ci_get_pi(rdev
);
4375 struct ci_leakage_voltage
*leakage_table
= &pi
->vddci_leakage
;
4378 for (leakage_index
= 0; leakage_index
< leakage_table
->count
; leakage_index
++) {
4379 if (leakage_table
->leakage_id
[leakage_index
] == *vddci
) {
4380 *vddci
= leakage_table
->actual_voltage
[leakage_index
];
4386 static void ci_patch_clock_voltage_dependency_table_with_vddc_leakage(struct radeon_device
*rdev
,
4387 struct radeon_clock_voltage_dependency_table
*table
)
4392 for (i
= 0; i
< table
->count
; i
++)
4393 ci_patch_with_vddc_leakage(rdev
, &table
->entries
[i
].v
);
4397 static void ci_patch_clock_voltage_dependency_table_with_vddci_leakage(struct radeon_device
*rdev
,
4398 struct radeon_clock_voltage_dependency_table
*table
)
4403 for (i
= 0; i
< table
->count
; i
++)
4404 ci_patch_with_vddci_leakage(rdev
, &table
->entries
[i
].v
);
4408 static void ci_patch_vce_clock_voltage_dependency_table_with_vddc_leakage(struct radeon_device
*rdev
,
4409 struct radeon_vce_clock_voltage_dependency_table
*table
)
4414 for (i
= 0; i
< table
->count
; i
++)
4415 ci_patch_with_vddc_leakage(rdev
, &table
->entries
[i
].v
);
4419 static void ci_patch_uvd_clock_voltage_dependency_table_with_vddc_leakage(struct radeon_device
*rdev
,
4420 struct radeon_uvd_clock_voltage_dependency_table
*table
)
4425 for (i
= 0; i
< table
->count
; i
++)
4426 ci_patch_with_vddc_leakage(rdev
, &table
->entries
[i
].v
);
4430 static void ci_patch_vddc_phase_shed_limit_table_with_vddc_leakage(struct radeon_device
*rdev
,
4431 struct radeon_phase_shedding_limits_table
*table
)
4436 for (i
= 0; i
< table
->count
; i
++)
4437 ci_patch_with_vddc_leakage(rdev
, &table
->entries
[i
].voltage
);
4441 static void ci_patch_clock_voltage_limits_with_vddc_leakage(struct radeon_device
*rdev
,
4442 struct radeon_clock_and_voltage_limits
*table
)
4445 ci_patch_with_vddc_leakage(rdev
, (u16
*)&table
->vddc
);
4446 ci_patch_with_vddci_leakage(rdev
, (u16
*)&table
->vddci
);
4450 static void ci_patch_cac_leakage_table_with_vddc_leakage(struct radeon_device
*rdev
,
4451 struct radeon_cac_leakage_table
*table
)
4456 for (i
= 0; i
< table
->count
; i
++)
4457 ci_patch_with_vddc_leakage(rdev
, &table
->entries
[i
].vddc
);
4461 static void ci_patch_dependency_tables_with_leakage(struct radeon_device
*rdev
)
4464 ci_patch_clock_voltage_dependency_table_with_vddc_leakage(rdev
,
4465 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
);
4466 ci_patch_clock_voltage_dependency_table_with_vddc_leakage(rdev
,
4467 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_mclk
);
4468 ci_patch_clock_voltage_dependency_table_with_vddc_leakage(rdev
,
4469 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
);
4470 ci_patch_clock_voltage_dependency_table_with_vddci_leakage(rdev
,
4471 &rdev
->pm
.dpm
.dyn_state
.vddci_dependency_on_mclk
);
4472 ci_patch_vce_clock_voltage_dependency_table_with_vddc_leakage(rdev
,
4473 &rdev
->pm
.dpm
.dyn_state
.vce_clock_voltage_dependency_table
);
4474 ci_patch_uvd_clock_voltage_dependency_table_with_vddc_leakage(rdev
,
4475 &rdev
->pm
.dpm
.dyn_state
.uvd_clock_voltage_dependency_table
);
4476 ci_patch_clock_voltage_dependency_table_with_vddc_leakage(rdev
,
4477 &rdev
->pm
.dpm
.dyn_state
.samu_clock_voltage_dependency_table
);
4478 ci_patch_clock_voltage_dependency_table_with_vddc_leakage(rdev
,
4479 &rdev
->pm
.dpm
.dyn_state
.acp_clock_voltage_dependency_table
);
4480 ci_patch_vddc_phase_shed_limit_table_with_vddc_leakage(rdev
,
4481 &rdev
->pm
.dpm
.dyn_state
.phase_shedding_limits_table
);
4482 ci_patch_clock_voltage_limits_with_vddc_leakage(rdev
,
4483 &rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
);
4484 ci_patch_clock_voltage_limits_with_vddc_leakage(rdev
,
4485 &rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_dc
);
4486 ci_patch_cac_leakage_table_with_vddc_leakage(rdev
,
4487 &rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
);
4491 static void ci_get_memory_type(struct radeon_device
*rdev
)
4493 struct ci_power_info
*pi
= ci_get_pi(rdev
);
4496 tmp
= RREG32(MC_SEQ_MISC0
);
4498 if (((tmp
& MC_SEQ_MISC0_GDDR5_MASK
) >> MC_SEQ_MISC0_GDDR5_SHIFT
) ==
4499 MC_SEQ_MISC0_GDDR5_VALUE
)
4500 pi
->mem_gddr5
= true;
4502 pi
->mem_gddr5
= false;
4506 static void ci_update_current_ps(struct radeon_device
*rdev
,
4507 struct radeon_ps
*rps
)
4509 struct ci_ps
*new_ps
= ci_get_ps(rps
);
4510 struct ci_power_info
*pi
= ci_get_pi(rdev
);
4512 pi
->current_rps
= *rps
;
4513 pi
->current_ps
= *new_ps
;
4514 pi
->current_rps
.ps_priv
= &pi
->current_ps
;
4517 static void ci_update_requested_ps(struct radeon_device
*rdev
,
4518 struct radeon_ps
*rps
)
4520 struct ci_ps
*new_ps
= ci_get_ps(rps
);
4521 struct ci_power_info
*pi
= ci_get_pi(rdev
);
4523 pi
->requested_rps
= *rps
;
4524 pi
->requested_ps
= *new_ps
;
4525 pi
->requested_rps
.ps_priv
= &pi
->requested_ps
;
4528 int ci_dpm_pre_set_power_state(struct radeon_device
*rdev
)
4530 struct ci_power_info
*pi
= ci_get_pi(rdev
);
4531 struct radeon_ps requested_ps
= *rdev
->pm
.dpm
.requested_ps
;
4532 struct radeon_ps
*new_ps
= &requested_ps
;
4534 ci_update_requested_ps(rdev
, new_ps
);
4536 ci_apply_state_adjust_rules(rdev
, &pi
->requested_rps
);
4541 void ci_dpm_post_set_power_state(struct radeon_device
*rdev
)
4543 struct ci_power_info
*pi
= ci_get_pi(rdev
);
4544 struct radeon_ps
*new_ps
= &pi
->requested_rps
;
4546 ci_update_current_ps(rdev
, new_ps
);
4550 void ci_dpm_setup_asic(struct radeon_device
*rdev
)
4554 r
= ci_mc_load_microcode(rdev
);
4556 DRM_ERROR("Failed to load MC firmware!\n");
4557 ci_read_clock_registers(rdev
);
4558 ci_get_memory_type(rdev
);
4559 ci_enable_acpi_power_management(rdev
);
4560 ci_init_sclk_t(rdev
);
4563 int ci_dpm_enable(struct radeon_device
*rdev
)
4565 struct ci_power_info
*pi
= ci_get_pi(rdev
);
4566 struct radeon_ps
*boot_ps
= rdev
->pm
.dpm
.boot_ps
;
4569 if (ci_is_smc_running(rdev
))
4571 if (pi
->voltage_control
!= CISLANDS_VOLTAGE_CONTROL_NONE
) {
4572 ci_enable_voltage_control(rdev
);
4573 ret
= ci_construct_voltage_tables(rdev
);
4575 DRM_ERROR("ci_construct_voltage_tables failed\n");
4579 if (pi
->caps_dynamic_ac_timing
) {
4580 ret
= ci_initialize_mc_reg_table(rdev
);
4582 pi
->caps_dynamic_ac_timing
= false;
4585 ci_enable_spread_spectrum(rdev
, true);
4586 if (pi
->thermal_protection
)
4587 ci_enable_thermal_protection(rdev
, true);
4588 ci_program_sstp(rdev
);
4589 ci_enable_display_gap(rdev
);
4590 ci_program_vc(rdev
);
4591 ret
= ci_upload_firmware(rdev
);
4593 DRM_ERROR("ci_upload_firmware failed\n");
4596 ret
= ci_process_firmware_header(rdev
);
4598 DRM_ERROR("ci_process_firmware_header failed\n");
4601 ret
= ci_initial_switch_from_arb_f0_to_f1(rdev
);
4603 DRM_ERROR("ci_initial_switch_from_arb_f0_to_f1 failed\n");
4606 ret
= ci_init_smc_table(rdev
);
4608 DRM_ERROR("ci_init_smc_table failed\n");
4611 ret
= ci_init_arb_table_index(rdev
);
4613 DRM_ERROR("ci_init_arb_table_index failed\n");
4616 if (pi
->caps_dynamic_ac_timing
) {
4617 ret
= ci_populate_initial_mc_reg_table(rdev
);
4619 DRM_ERROR("ci_populate_initial_mc_reg_table failed\n");
4623 ret
= ci_populate_pm_base(rdev
);
4625 DRM_ERROR("ci_populate_pm_base failed\n");
4628 ci_dpm_start_smc(rdev
);
4629 ci_enable_vr_hot_gpio_interrupt(rdev
);
4630 ret
= ci_notify_smc_display_change(rdev
, false);
4632 DRM_ERROR("ci_notify_smc_display_change failed\n");
4635 ci_enable_sclk_control(rdev
, true);
4636 ret
= ci_enable_ulv(rdev
, true);
4638 DRM_ERROR("ci_enable_ulv failed\n");
4641 ret
= ci_enable_ds_master_switch(rdev
, true);
4643 DRM_ERROR("ci_enable_ds_master_switch failed\n");
4646 ret
= ci_start_dpm(rdev
);
4648 DRM_ERROR("ci_start_dpm failed\n");
4651 ret
= ci_enable_didt(rdev
, true);
4653 DRM_ERROR("ci_enable_didt failed\n");
4656 ret
= ci_enable_smc_cac(rdev
, true);
4658 DRM_ERROR("ci_enable_smc_cac failed\n");
4661 ret
= ci_enable_power_containment(rdev
, true);
4663 DRM_ERROR("ci_enable_power_containment failed\n");
4667 ret
= ci_power_control_set_level(rdev
);
4669 DRM_ERROR("ci_power_control_set_level failed\n");
4673 ci_enable_auto_throttle_source(rdev
, RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL
, true);
4675 ci_update_current_ps(rdev
, boot_ps
);
4680 int ci_dpm_late_enable(struct radeon_device
*rdev
)
4684 if (rdev
->irq
.installed
&&
4685 r600_is_internal_thermal_sensor(rdev
->pm
.int_thermal_type
)) {
4687 PPSMC_Result result
;
4689 ret
= ci_set_thermal_temperature_range(rdev
, R600_TEMP_RANGE_MIN
, R600_TEMP_RANGE_MAX
);
4691 DRM_ERROR("ci_set_thermal_temperature_range failed\n");
4694 rdev
->irq
.dpm_thermal
= true;
4695 radeon_irq_set(rdev
);
4697 result
= ci_send_msg_to_smc(rdev
, PPSMC_MSG_EnableThermalInterrupt
);
4699 if (result
!= PPSMC_Result_OK
)
4700 DRM_DEBUG_KMS("Could not enable thermal interrupts.\n");
4704 ci_dpm_powergate_uvd(rdev
, true);
4709 void ci_dpm_disable(struct radeon_device
*rdev
)
4711 struct ci_power_info
*pi
= ci_get_pi(rdev
);
4712 struct radeon_ps
*boot_ps
= rdev
->pm
.dpm
.boot_ps
;
4714 ci_dpm_powergate_uvd(rdev
, false);
4716 if (!ci_is_smc_running(rdev
))
4719 if (pi
->thermal_protection
)
4720 ci_enable_thermal_protection(rdev
, false);
4721 ci_enable_power_containment(rdev
, false);
4722 ci_enable_smc_cac(rdev
, false);
4723 ci_enable_didt(rdev
, false);
4724 ci_enable_spread_spectrum(rdev
, false);
4725 ci_enable_auto_throttle_source(rdev
, RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL
, false);
4727 ci_enable_ds_master_switch(rdev
, true);
4728 ci_enable_ulv(rdev
, false);
4730 ci_reset_to_default(rdev
);
4731 ci_dpm_stop_smc(rdev
);
4732 ci_force_switch_to_arb_f0(rdev
);
4734 ci_update_current_ps(rdev
, boot_ps
);
4737 int ci_dpm_set_power_state(struct radeon_device
*rdev
)
4739 struct ci_power_info
*pi
= ci_get_pi(rdev
);
4740 struct radeon_ps
*new_ps
= &pi
->requested_rps
;
4741 struct radeon_ps
*old_ps
= &pi
->current_rps
;
4744 ci_find_dpm_states_clocks_in_dpm_table(rdev
, new_ps
);
4745 if (pi
->pcie_performance_request
)
4746 ci_request_link_speed_change_before_state_change(rdev
, new_ps
, old_ps
);
4747 ret
= ci_freeze_sclk_mclk_dpm(rdev
);
4749 DRM_ERROR("ci_freeze_sclk_mclk_dpm failed\n");
4752 ret
= ci_populate_and_upload_sclk_mclk_dpm_levels(rdev
, new_ps
);
4754 DRM_ERROR("ci_populate_and_upload_sclk_mclk_dpm_levels failed\n");
4757 ret
= ci_generate_dpm_level_enable_mask(rdev
, new_ps
);
4759 DRM_ERROR("ci_generate_dpm_level_enable_mask failed\n");
4763 ret
= ci_update_vce_dpm(rdev
, new_ps
, old_ps
);
4765 DRM_ERROR("ci_update_vce_dpm failed\n");
4769 ret
= ci_update_sclk_t(rdev
);
4771 DRM_ERROR("ci_update_sclk_t failed\n");
4774 if (pi
->caps_dynamic_ac_timing
) {
4775 ret
= ci_update_and_upload_mc_reg_table(rdev
);
4777 DRM_ERROR("ci_update_and_upload_mc_reg_table failed\n");
4781 ret
= ci_program_memory_timing_parameters(rdev
);
4783 DRM_ERROR("ci_program_memory_timing_parameters failed\n");
4786 ret
= ci_unfreeze_sclk_mclk_dpm(rdev
);
4788 DRM_ERROR("ci_unfreeze_sclk_mclk_dpm failed\n");
4791 ret
= ci_upload_dpm_level_enable_mask(rdev
);
4793 DRM_ERROR("ci_upload_dpm_level_enable_mask failed\n");
4796 if (pi
->pcie_performance_request
)
4797 ci_notify_link_speed_change_after_state_change(rdev
, new_ps
, old_ps
);
4803 void ci_dpm_reset_asic(struct radeon_device
*rdev
)
4805 ci_set_boot_state(rdev
);
4809 void ci_dpm_display_configuration_changed(struct radeon_device
*rdev
)
4811 ci_program_display_gap(rdev
);
4815 struct _ATOM_POWERPLAY_INFO info
;
4816 struct _ATOM_POWERPLAY_INFO_V2 info_2
;
4817 struct _ATOM_POWERPLAY_INFO_V3 info_3
;
4818 struct _ATOM_PPLIB_POWERPLAYTABLE pplib
;
4819 struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2
;
4820 struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3
;
4823 union pplib_clock_info
{
4824 struct _ATOM_PPLIB_R600_CLOCK_INFO r600
;
4825 struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780
;
4826 struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen
;
4827 struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo
;
4828 struct _ATOM_PPLIB_SI_CLOCK_INFO si
;
4829 struct _ATOM_PPLIB_CI_CLOCK_INFO ci
;
4832 union pplib_power_state
{
4833 struct _ATOM_PPLIB_STATE v1
;
4834 struct _ATOM_PPLIB_STATE_V2 v2
;
4837 static void ci_parse_pplib_non_clock_info(struct radeon_device
*rdev
,
4838 struct radeon_ps
*rps
,
4839 struct _ATOM_PPLIB_NONCLOCK_INFO
*non_clock_info
,
4842 rps
->caps
= le32_to_cpu(non_clock_info
->ulCapsAndSettings
);
4843 rps
->class = le16_to_cpu(non_clock_info
->usClassification
);
4844 rps
->class2
= le16_to_cpu(non_clock_info
->usClassification2
);
4846 if (ATOM_PPLIB_NONCLOCKINFO_VER1
< table_rev
) {
4847 rps
->vclk
= le32_to_cpu(non_clock_info
->ulVCLK
);
4848 rps
->dclk
= le32_to_cpu(non_clock_info
->ulDCLK
);
4854 if (rps
->class & ATOM_PPLIB_CLASSIFICATION_BOOT
)
4855 rdev
->pm
.dpm
.boot_ps
= rps
;
4856 if (rps
->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE
)
4857 rdev
->pm
.dpm
.uvd_ps
= rps
;
4860 static void ci_parse_pplib_clock_info(struct radeon_device
*rdev
,
4861 struct radeon_ps
*rps
, int index
,
4862 union pplib_clock_info
*clock_info
)
4864 struct ci_power_info
*pi
= ci_get_pi(rdev
);
4865 struct ci_ps
*ps
= ci_get_ps(rps
);
4866 struct ci_pl
*pl
= &ps
->performance_levels
[index
];
4868 ps
->performance_level_count
= index
+ 1;
4870 pl
->sclk
= le16_to_cpu(clock_info
->ci
.usEngineClockLow
);
4871 pl
->sclk
|= clock_info
->ci
.ucEngineClockHigh
<< 16;
4872 pl
->mclk
= le16_to_cpu(clock_info
->ci
.usMemoryClockLow
);
4873 pl
->mclk
|= clock_info
->ci
.ucMemoryClockHigh
<< 16;
4875 pl
->pcie_gen
= r600_get_pcie_gen_support(rdev
,
4877 pi
->vbios_boot_state
.pcie_gen_bootup_value
,
4878 clock_info
->ci
.ucPCIEGen
);
4879 pl
->pcie_lane
= r600_get_pcie_lane_support(rdev
,
4880 pi
->vbios_boot_state
.pcie_lane_bootup_value
,
4881 le16_to_cpu(clock_info
->ci
.usPCIELane
));
4883 if (rps
->class & ATOM_PPLIB_CLASSIFICATION_ACPI
) {
4884 pi
->acpi_pcie_gen
= pl
->pcie_gen
;
4887 if (rps
->class2
& ATOM_PPLIB_CLASSIFICATION2_ULV
) {
4888 pi
->ulv
.supported
= true;
4890 pi
->ulv
.cg_ulv_parameter
= CISLANDS_CGULVPARAMETER_DFLT
;
4893 /* patch up boot state */
4894 if (rps
->class & ATOM_PPLIB_CLASSIFICATION_BOOT
) {
4895 pl
->mclk
= pi
->vbios_boot_state
.mclk_bootup_value
;
4896 pl
->sclk
= pi
->vbios_boot_state
.sclk_bootup_value
;
4897 pl
->pcie_gen
= pi
->vbios_boot_state
.pcie_gen_bootup_value
;
4898 pl
->pcie_lane
= pi
->vbios_boot_state
.pcie_lane_bootup_value
;
4901 switch (rps
->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK
) {
4902 case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY
:
4903 pi
->use_pcie_powersaving_levels
= true;
4904 if (pi
->pcie_gen_powersaving
.max
< pl
->pcie_gen
)
4905 pi
->pcie_gen_powersaving
.max
= pl
->pcie_gen
;
4906 if (pi
->pcie_gen_powersaving
.min
> pl
->pcie_gen
)
4907 pi
->pcie_gen_powersaving
.min
= pl
->pcie_gen
;
4908 if (pi
->pcie_lane_powersaving
.max
< pl
->pcie_lane
)
4909 pi
->pcie_lane_powersaving
.max
= pl
->pcie_lane
;
4910 if (pi
->pcie_lane_powersaving
.min
> pl
->pcie_lane
)
4911 pi
->pcie_lane_powersaving
.min
= pl
->pcie_lane
;
4913 case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE
:
4914 pi
->use_pcie_performance_levels
= true;
4915 if (pi
->pcie_gen_performance
.max
< pl
->pcie_gen
)
4916 pi
->pcie_gen_performance
.max
= pl
->pcie_gen
;
4917 if (pi
->pcie_gen_performance
.min
> pl
->pcie_gen
)
4918 pi
->pcie_gen_performance
.min
= pl
->pcie_gen
;
4919 if (pi
->pcie_lane_performance
.max
< pl
->pcie_lane
)
4920 pi
->pcie_lane_performance
.max
= pl
->pcie_lane
;
4921 if (pi
->pcie_lane_performance
.min
> pl
->pcie_lane
)
4922 pi
->pcie_lane_performance
.min
= pl
->pcie_lane
;
4929 static int ci_parse_power_table(struct radeon_device
*rdev
)
4931 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
4932 struct _ATOM_PPLIB_NONCLOCK_INFO
*non_clock_info
;
4933 union pplib_power_state
*power_state
;
4934 int i
, j
, k
, non_clock_array_index
, clock_array_index
;
4935 union pplib_clock_info
*clock_info
;
4936 struct _StateArray
*state_array
;
4937 struct _ClockInfoArray
*clock_info_array
;
4938 struct _NonClockInfoArray
*non_clock_info_array
;
4939 union power_info
*power_info
;
4940 int index
= GetIndexIntoMasterTable(DATA
, PowerPlayInfo
);
4943 u8
*power_state_offset
;
4946 if (!atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
4947 &frev
, &crev
, &data_offset
))
4949 power_info
= (union power_info
*)(mode_info
->atom_context
->bios
+ data_offset
);
4951 state_array
= (struct _StateArray
*)
4952 (mode_info
->atom_context
->bios
+ data_offset
+
4953 le16_to_cpu(power_info
->pplib
.usStateArrayOffset
));
4954 clock_info_array
= (struct _ClockInfoArray
*)
4955 (mode_info
->atom_context
->bios
+ data_offset
+
4956 le16_to_cpu(power_info
->pplib
.usClockInfoArrayOffset
));
4957 non_clock_info_array
= (struct _NonClockInfoArray
*)
4958 (mode_info
->atom_context
->bios
+ data_offset
+
4959 le16_to_cpu(power_info
->pplib
.usNonClockInfoArrayOffset
));
4961 rdev
->pm
.dpm
.ps
= kzalloc(sizeof(struct radeon_ps
) *
4962 state_array
->ucNumEntries
, GFP_KERNEL
);
4963 if (!rdev
->pm
.dpm
.ps
)
4965 power_state_offset
= (u8
*)state_array
->states
;
4966 for (i
= 0; i
< state_array
->ucNumEntries
; i
++) {
4968 power_state
= (union pplib_power_state
*)power_state_offset
;
4969 non_clock_array_index
= power_state
->v2
.nonClockInfoIndex
;
4970 non_clock_info
= (struct _ATOM_PPLIB_NONCLOCK_INFO
*)
4971 &non_clock_info_array
->nonClockInfo
[non_clock_array_index
];
4972 if (!rdev
->pm
.power_state
[i
].clock_info
)
4974 ps
= kzalloc(sizeof(struct ci_ps
), GFP_KERNEL
);
4976 kfree(rdev
->pm
.dpm
.ps
);
4979 rdev
->pm
.dpm
.ps
[i
].ps_priv
= ps
;
4980 ci_parse_pplib_non_clock_info(rdev
, &rdev
->pm
.dpm
.ps
[i
],
4982 non_clock_info_array
->ucEntrySize
);
4984 idx
= (u8
*)&power_state
->v2
.clockInfoIndex
[0];
4985 for (j
= 0; j
< power_state
->v2
.ucNumDPMLevels
; j
++) {
4986 clock_array_index
= idx
[j
];
4987 if (clock_array_index
>= clock_info_array
->ucNumEntries
)
4989 if (k
>= CISLANDS_MAX_HARDWARE_POWERLEVELS
)
4991 clock_info
= (union pplib_clock_info
*)
4992 ((u8
*)&clock_info_array
->clockInfo
[0] +
4993 (clock_array_index
* clock_info_array
->ucEntrySize
));
4994 ci_parse_pplib_clock_info(rdev
,
4995 &rdev
->pm
.dpm
.ps
[i
], k
,
4999 power_state_offset
+= 2 + power_state
->v2
.ucNumDPMLevels
;
5001 rdev
->pm
.dpm
.num_ps
= state_array
->ucNumEntries
;
5003 /* fill in the vce power states */
5004 for (i
= 0; i
< RADEON_MAX_VCE_LEVELS
; i
++) {
5006 clock_array_index
= rdev
->pm
.dpm
.vce_states
[i
].clk_idx
;
5007 clock_info
= (union pplib_clock_info
*)
5008 &clock_info_array
->clockInfo
[clock_array_index
* clock_info_array
->ucEntrySize
];
5009 sclk
= le16_to_cpu(clock_info
->ci
.usEngineClockLow
);
5010 sclk
|= clock_info
->ci
.ucEngineClockHigh
<< 16;
5011 mclk
= le16_to_cpu(clock_info
->ci
.usMemoryClockLow
);
5012 mclk
|= clock_info
->ci
.ucMemoryClockHigh
<< 16;
5013 rdev
->pm
.dpm
.vce_states
[i
].sclk
= sclk
;
5014 rdev
->pm
.dpm
.vce_states
[i
].mclk
= mclk
;
5020 static int ci_get_vbios_boot_values(struct radeon_device
*rdev
,
5021 struct ci_vbios_boot_state
*boot_state
)
5023 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
5024 int index
= GetIndexIntoMasterTable(DATA
, FirmwareInfo
);
5025 ATOM_FIRMWARE_INFO_V2_2
*firmware_info
;
5029 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
5030 &frev
, &crev
, &data_offset
)) {
5032 (ATOM_FIRMWARE_INFO_V2_2
*)(mode_info
->atom_context
->bios
+
5034 boot_state
->mvdd_bootup_value
= le16_to_cpu(firmware_info
->usBootUpMVDDCVoltage
);
5035 boot_state
->vddc_bootup_value
= le16_to_cpu(firmware_info
->usBootUpVDDCVoltage
);
5036 boot_state
->vddci_bootup_value
= le16_to_cpu(firmware_info
->usBootUpVDDCIVoltage
);
5037 boot_state
->pcie_gen_bootup_value
= ci_get_current_pcie_speed(rdev
);
5038 boot_state
->pcie_lane_bootup_value
= ci_get_current_pcie_lane_number(rdev
);
5039 boot_state
->sclk_bootup_value
= le32_to_cpu(firmware_info
->ulDefaultEngineClock
);
5040 boot_state
->mclk_bootup_value
= le32_to_cpu(firmware_info
->ulDefaultMemoryClock
);
5047 void ci_dpm_fini(struct radeon_device
*rdev
)
5051 for (i
= 0; i
< rdev
->pm
.dpm
.num_ps
; i
++) {
5052 kfree(rdev
->pm
.dpm
.ps
[i
].ps_priv
);
5054 kfree(rdev
->pm
.dpm
.ps
);
5055 kfree(rdev
->pm
.dpm
.priv
);
5056 kfree(rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
);
5057 r600_free_extended_power_table(rdev
);
5060 int ci_dpm_init(struct radeon_device
*rdev
)
5062 int index
= GetIndexIntoMasterTable(DATA
, ASIC_InternalSS_Info
);
5063 u16 data_offset
, size
;
5065 struct ci_power_info
*pi
;
5069 pi
= kzalloc(sizeof(struct ci_power_info
), GFP_KERNEL
);
5072 rdev
->pm
.dpm
.priv
= pi
;
5074 ret
= drm_pcie_get_speed_cap_mask(rdev
->ddev
, &mask
);
5076 pi
->sys_pcie_mask
= 0;
5078 pi
->sys_pcie_mask
= mask
;
5079 pi
->force_pcie_gen
= RADEON_PCIE_GEN_INVALID
;
5081 pi
->pcie_gen_performance
.max
= RADEON_PCIE_GEN1
;
5082 pi
->pcie_gen_performance
.min
= RADEON_PCIE_GEN3
;
5083 pi
->pcie_gen_powersaving
.max
= RADEON_PCIE_GEN1
;
5084 pi
->pcie_gen_powersaving
.min
= RADEON_PCIE_GEN3
;
5086 pi
->pcie_lane_performance
.max
= 0;
5087 pi
->pcie_lane_performance
.min
= 16;
5088 pi
->pcie_lane_powersaving
.max
= 0;
5089 pi
->pcie_lane_powersaving
.min
= 16;
5091 ret
= ci_get_vbios_boot_values(rdev
, &pi
->vbios_boot_state
);
5097 ret
= r600_get_platform_caps(rdev
);
5103 ret
= r600_parse_extended_power_table(rdev
);
5109 ret
= ci_parse_power_table(rdev
);
5115 pi
->dll_default_on
= false;
5116 pi
->sram_end
= SMC_RAM_END
;
5118 pi
->activity_target
[0] = CISLAND_TARGETACTIVITY_DFLT
;
5119 pi
->activity_target
[1] = CISLAND_TARGETACTIVITY_DFLT
;
5120 pi
->activity_target
[2] = CISLAND_TARGETACTIVITY_DFLT
;
5121 pi
->activity_target
[3] = CISLAND_TARGETACTIVITY_DFLT
;
5122 pi
->activity_target
[4] = CISLAND_TARGETACTIVITY_DFLT
;
5123 pi
->activity_target
[5] = CISLAND_TARGETACTIVITY_DFLT
;
5124 pi
->activity_target
[6] = CISLAND_TARGETACTIVITY_DFLT
;
5125 pi
->activity_target
[7] = CISLAND_TARGETACTIVITY_DFLT
;
5127 pi
->mclk_activity_target
= CISLAND_MCLK_TARGETACTIVITY_DFLT
;
5129 pi
->sclk_dpm_key_disabled
= 0;
5130 pi
->mclk_dpm_key_disabled
= 0;
5131 pi
->pcie_dpm_key_disabled
= 0;
5133 /* mclk dpm is unstable on some R7 260X cards with the old mc ucode */
5134 if ((rdev
->pdev
->device
== 0x6658) &&
5135 (rdev
->mc_fw
->datasize
== (BONAIRE_MC_UCODE_SIZE
* 4))) {
5136 pi
->mclk_dpm_key_disabled
= 1;
5139 pi
->caps_sclk_ds
= true;
5141 pi
->mclk_strobe_mode_threshold
= 40000;
5142 pi
->mclk_stutter_mode_threshold
= 40000;
5143 pi
->mclk_edc_enable_threshold
= 40000;
5144 pi
->mclk_edc_wr_enable_threshold
= 40000;
5146 ci_initialize_powertune_defaults(rdev
);
5148 pi
->caps_fps
= false;
5150 pi
->caps_sclk_throttle_low_notification
= false;
5152 pi
->caps_uvd_dpm
= true;
5153 pi
->caps_vce_dpm
= true;
5155 ci_get_leakage_voltages(rdev
);
5156 ci_patch_dependency_tables_with_leakage(rdev
);
5157 ci_set_private_data_variables_based_on_pptable(rdev
);
5159 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
=
5160 kzalloc(4 * sizeof(struct radeon_clock_voltage_dependency_entry
), GFP_KERNEL
);
5161 if (!rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
) {
5165 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.count
= 4;
5166 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
[0].clk
= 0;
5167 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
[0].v
= 0;
5168 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
[1].clk
= 36000;
5169 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
[1].v
= 720;
5170 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
[2].clk
= 54000;
5171 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
[2].v
= 810;
5172 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
[3].clk
= 72000;
5173 rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_dispclk
.entries
[3].v
= 900;
5175 rdev
->pm
.dpm
.dyn_state
.mclk_sclk_ratio
= 4;
5176 rdev
->pm
.dpm
.dyn_state
.sclk_mclk_delta
= 15000;
5177 rdev
->pm
.dpm
.dyn_state
.vddc_vddci_delta
= 200;
5179 rdev
->pm
.dpm
.dyn_state
.valid_sclk_values
.count
= 0;
5180 rdev
->pm
.dpm
.dyn_state
.valid_sclk_values
.values
= NULL
;
5181 rdev
->pm
.dpm
.dyn_state
.valid_mclk_values
.count
= 0;
5182 rdev
->pm
.dpm
.dyn_state
.valid_mclk_values
.values
= NULL
;
5184 if (rdev
->family
== CHIP_HAWAII
) {
5185 pi
->thermal_temp_setting
.temperature_low
= 94500;
5186 pi
->thermal_temp_setting
.temperature_high
= 95000;
5187 pi
->thermal_temp_setting
.temperature_shutdown
= 104000;
5189 pi
->thermal_temp_setting
.temperature_low
= 99500;
5190 pi
->thermal_temp_setting
.temperature_high
= 100000;
5191 pi
->thermal_temp_setting
.temperature_shutdown
= 104000;
5194 pi
->uvd_enabled
= false;
5196 pi
->voltage_control
= CISLANDS_VOLTAGE_CONTROL_NONE
;
5197 pi
->vddci_control
= CISLANDS_VOLTAGE_CONTROL_NONE
;
5198 pi
->mvdd_control
= CISLANDS_VOLTAGE_CONTROL_NONE
;
5199 if (radeon_atom_is_voltage_gpio(rdev
, VOLTAGE_TYPE_VDDC
, VOLTAGE_OBJ_GPIO_LUT
))
5200 pi
->voltage_control
= CISLANDS_VOLTAGE_CONTROL_BY_GPIO
;
5201 else if (radeon_atom_is_voltage_gpio(rdev
, VOLTAGE_TYPE_VDDC
, VOLTAGE_OBJ_SVID2
))
5202 pi
->voltage_control
= CISLANDS_VOLTAGE_CONTROL_BY_SVID2
;
5204 if (rdev
->pm
.dpm
.platform_caps
& ATOM_PP_PLATFORM_CAP_VDDCI_CONTROL
) {
5205 if (radeon_atom_is_voltage_gpio(rdev
, VOLTAGE_TYPE_VDDCI
, VOLTAGE_OBJ_GPIO_LUT
))
5206 pi
->vddci_control
= CISLANDS_VOLTAGE_CONTROL_BY_GPIO
;
5207 else if (radeon_atom_is_voltage_gpio(rdev
, VOLTAGE_TYPE_VDDCI
, VOLTAGE_OBJ_SVID2
))
5208 pi
->vddci_control
= CISLANDS_VOLTAGE_CONTROL_BY_SVID2
;
5210 rdev
->pm
.dpm
.platform_caps
&= ~ATOM_PP_PLATFORM_CAP_VDDCI_CONTROL
;
5213 if (rdev
->pm
.dpm
.platform_caps
& ATOM_PP_PLATFORM_CAP_MVDDCONTROL
) {
5214 if (radeon_atom_is_voltage_gpio(rdev
, VOLTAGE_TYPE_MVDDC
, VOLTAGE_OBJ_GPIO_LUT
))
5215 pi
->mvdd_control
= CISLANDS_VOLTAGE_CONTROL_BY_GPIO
;
5216 else if (radeon_atom_is_voltage_gpio(rdev
, VOLTAGE_TYPE_MVDDC
, VOLTAGE_OBJ_SVID2
))
5217 pi
->mvdd_control
= CISLANDS_VOLTAGE_CONTROL_BY_SVID2
;
5219 rdev
->pm
.dpm
.platform_caps
&= ~ATOM_PP_PLATFORM_CAP_MVDDCONTROL
;
5222 pi
->vddc_phase_shed_control
= true;
5224 #if defined(CONFIG_ACPI)
5225 pi
->pcie_performance_request
=
5226 radeon_acpi_is_pcie_performance_request_supported(rdev
);
5228 pi
->pcie_performance_request
= false;
5231 if (atom_parse_data_header(rdev
->mode_info
.atom_context
, index
, &size
,
5232 &frev
, &crev
, &data_offset
)) {
5233 pi
->caps_sclk_ss_support
= true;
5234 pi
->caps_mclk_ss_support
= true;
5235 pi
->dynamic_ss
= true;
5237 pi
->caps_sclk_ss_support
= false;
5238 pi
->caps_mclk_ss_support
= false;
5239 pi
->dynamic_ss
= true;
5242 if (rdev
->pm
.int_thermal_type
!= THERMAL_TYPE_NONE
)
5243 pi
->thermal_protection
= true;
5245 pi
->thermal_protection
= false;
5247 pi
->caps_dynamic_ac_timing
= true;
5249 pi
->uvd_power_gated
= false;
5251 /* make sure dc limits are valid */
5252 if ((rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_dc
.sclk
== 0) ||
5253 (rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_dc
.mclk
== 0))
5254 rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_dc
=
5255 rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
;
5260 void ci_dpm_debugfs_print_current_performance_level(struct radeon_device
*rdev
,
5263 struct ci_power_info
*pi
= ci_get_pi(rdev
);
5264 struct radeon_ps
*rps
= &pi
->current_rps
;
5265 u32 sclk
= ci_get_average_sclk_freq(rdev
);
5266 u32 mclk
= ci_get_average_mclk_freq(rdev
);
5268 seq_printf(m
, "uvd %sabled\n", pi
->uvd_enabled
? "en" : "dis");
5269 seq_printf(m
, "vce %sabled\n", rps
->vce_active
? "en" : "dis");
5270 seq_printf(m
, "power level avg sclk: %u mclk: %u\n",
5274 void ci_dpm_print_power_state(struct radeon_device
*rdev
,
5275 struct radeon_ps
*rps
)
5277 struct ci_ps
*ps
= ci_get_ps(rps
);
5281 r600_dpm_print_class_info(rps
->class, rps
->class2
);
5282 r600_dpm_print_cap_info(rps
->caps
);
5283 printk("\tuvd vclk: %d dclk: %d\n", rps
->vclk
, rps
->dclk
);
5284 for (i
= 0; i
< ps
->performance_level_count
; i
++) {
5285 pl
= &ps
->performance_levels
[i
];
5286 printk("\t\tpower level %d sclk: %u mclk: %u pcie gen: %u pcie lanes: %u\n",
5287 i
, pl
->sclk
, pl
->mclk
, pl
->pcie_gen
+ 1, pl
->pcie_lane
);
5289 r600_dpm_print_ps_status(rdev
, rps
);
5292 u32
ci_dpm_get_sclk(struct radeon_device
*rdev
, bool low
)
5294 struct ci_power_info
*pi
= ci_get_pi(rdev
);
5295 struct ci_ps
*requested_state
= ci_get_ps(&pi
->requested_rps
);
5298 return requested_state
->performance_levels
[0].sclk
;
5300 return requested_state
->performance_levels
[requested_state
->performance_level_count
- 1].sclk
;
5303 u32
ci_dpm_get_mclk(struct radeon_device
*rdev
, bool low
)
5305 struct ci_power_info
*pi
= ci_get_pi(rdev
);
5306 struct ci_ps
*requested_state
= ci_get_ps(&pi
->requested_rps
);
5309 return requested_state
->performance_levels
[0].mclk
;
5311 return requested_state
->performance_levels
[requested_state
->performance_level_count
- 1].mclk
;