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.
29 #include "radeon_asic.h"
30 #include <linux/seq_file.h>
32 #define KV_MAX_DEEPSLEEP_DIVIDER_ID 5
33 #define KV_MINIMUM_ENGINE_CLOCK 800
34 #define SMC_RAM_END 0x40000
36 static int kv_enable_nb_dpm(struct radeon_device
*rdev
,
38 static void kv_init_graphics_levels(struct radeon_device
*rdev
);
39 static int kv_calculate_ds_divider(struct radeon_device
*rdev
);
40 static int kv_calculate_nbps_level_settings(struct radeon_device
*rdev
);
41 static int kv_calculate_dpm_settings(struct radeon_device
*rdev
);
42 static void kv_enable_new_levels(struct radeon_device
*rdev
);
43 static void kv_program_nbps_index_settings(struct radeon_device
*rdev
,
44 struct radeon_ps
*new_rps
);
45 static int kv_set_enabled_level(struct radeon_device
*rdev
, u32 level
);
46 static int kv_set_enabled_levels(struct radeon_device
*rdev
);
47 static int kv_force_dpm_highest(struct radeon_device
*rdev
);
48 static int kv_force_dpm_lowest(struct radeon_device
*rdev
);
49 static void kv_apply_state_adjust_rules(struct radeon_device
*rdev
,
50 struct radeon_ps
*new_rps
,
51 struct radeon_ps
*old_rps
);
52 static int kv_set_thermal_temperature_range(struct radeon_device
*rdev
,
53 int min_temp
, int max_temp
);
54 static int kv_init_fps_limits(struct radeon_device
*rdev
);
56 void kv_dpm_powergate_uvd(struct radeon_device
*rdev
, bool gate
);
57 static void kv_dpm_powergate_vce(struct radeon_device
*rdev
, bool gate
);
58 static void kv_dpm_powergate_samu(struct radeon_device
*rdev
, bool gate
);
59 static void kv_dpm_powergate_acp(struct radeon_device
*rdev
, bool gate
);
61 extern void cik_enter_rlc_safe_mode(struct radeon_device
*rdev
);
62 extern void cik_exit_rlc_safe_mode(struct radeon_device
*rdev
);
63 extern void cik_update_cg(struct radeon_device
*rdev
,
64 u32 block
, bool enable
);
66 static const struct kv_lcac_config_values sx_local_cac_cfg_kv
[] =
79 static const struct kv_lcac_config_values mc0_local_cac_cfg_kv
[] =
85 static const struct kv_lcac_config_values mc1_local_cac_cfg_kv
[] =
91 static const struct kv_lcac_config_values mc2_local_cac_cfg_kv
[] =
97 static const struct kv_lcac_config_values mc3_local_cac_cfg_kv
[] =
103 static const struct kv_lcac_config_values cpl_local_cac_cfg_kv
[] =
135 static const struct kv_lcac_config_reg sx0_cac_config_reg
[] =
137 { 0xc0400d00, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
140 static const struct kv_lcac_config_reg mc0_cac_config_reg
[] =
142 { 0xc0400d30, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
145 static const struct kv_lcac_config_reg mc1_cac_config_reg
[] =
147 { 0xc0400d3c, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
150 static const struct kv_lcac_config_reg mc2_cac_config_reg
[] =
152 { 0xc0400d48, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
155 static const struct kv_lcac_config_reg mc3_cac_config_reg
[] =
157 { 0xc0400d54, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
160 static const struct kv_lcac_config_reg cpl_cac_config_reg
[] =
162 { 0xc0400d80, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
165 static const struct kv_pt_config_reg didt_config_kv
[] =
167 { 0x10, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
168 { 0x10, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
169 { 0x10, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
170 { 0x10, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
171 { 0x11, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
172 { 0x11, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
173 { 0x11, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
174 { 0x11, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
175 { 0x12, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
176 { 0x12, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
177 { 0x12, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
178 { 0x12, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
179 { 0x2, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND
},
180 { 0x2, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND
},
181 { 0x2, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND
},
182 { 0x1, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND
},
183 { 0x1, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND
},
184 { 0x0, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
185 { 0x30, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
186 { 0x30, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
187 { 0x30, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
188 { 0x30, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
189 { 0x31, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
190 { 0x31, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
191 { 0x31, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
192 { 0x31, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
193 { 0x32, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
194 { 0x32, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
195 { 0x32, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
196 { 0x32, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
197 { 0x22, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND
},
198 { 0x22, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND
},
199 { 0x22, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND
},
200 { 0x21, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND
},
201 { 0x21, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND
},
202 { 0x20, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
203 { 0x50, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
204 { 0x50, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
205 { 0x50, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
206 { 0x50, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
207 { 0x51, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
208 { 0x51, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
209 { 0x51, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
210 { 0x51, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
211 { 0x52, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
212 { 0x52, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
213 { 0x52, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
214 { 0x52, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
215 { 0x42, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND
},
216 { 0x42, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND
},
217 { 0x42, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND
},
218 { 0x41, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND
},
219 { 0x41, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND
},
220 { 0x40, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
221 { 0x70, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
222 { 0x70, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
223 { 0x70, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
224 { 0x70, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
225 { 0x71, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
226 { 0x71, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
227 { 0x71, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
228 { 0x71, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
229 { 0x72, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
230 { 0x72, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
231 { 0x72, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
232 { 0x72, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
233 { 0x62, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND
},
234 { 0x62, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND
},
235 { 0x62, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND
},
236 { 0x61, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND
},
237 { 0x61, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND
},
238 { 0x60, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
242 static struct kv_ps
*kv_get_ps(struct radeon_ps
*rps
)
244 struct kv_ps
*ps
= rps
->ps_priv
;
249 static struct kv_power_info
*kv_get_pi(struct radeon_device
*rdev
)
251 struct kv_power_info
*pi
= rdev
->pm
.dpm
.priv
;
257 static void kv_program_local_cac_table(struct radeon_device
*rdev
,
258 const struct kv_lcac_config_values
*local_cac_table
,
259 const struct kv_lcac_config_reg
*local_cac_reg
)
262 const struct kv_lcac_config_values
*values
= local_cac_table
;
264 while (values
->block_id
!= 0xffffffff) {
265 count
= values
->signal_id
;
266 for (i
= 0; i
< count
; i
++) {
267 data
= ((values
->block_id
<< local_cac_reg
->block_shift
) &
268 local_cac_reg
->block_mask
);
269 data
|= ((i
<< local_cac_reg
->signal_shift
) &
270 local_cac_reg
->signal_mask
);
271 data
|= ((values
->t
<< local_cac_reg
->t_shift
) &
272 local_cac_reg
->t_mask
);
273 data
|= ((1 << local_cac_reg
->enable_shift
) &
274 local_cac_reg
->enable_mask
);
275 WREG32_SMC(local_cac_reg
->cntl
, data
);
282 static int kv_program_pt_config_registers(struct radeon_device
*rdev
,
283 const struct kv_pt_config_reg
*cac_config_regs
)
285 const struct kv_pt_config_reg
*config_regs
= cac_config_regs
;
289 if (config_regs
== NULL
)
292 while (config_regs
->offset
!= 0xFFFFFFFF) {
293 if (config_regs
->type
== KV_CONFIGREG_CACHE
) {
294 cache
|= ((config_regs
->value
<< config_regs
->shift
) & config_regs
->mask
);
296 switch (config_regs
->type
) {
297 case KV_CONFIGREG_SMC_IND
:
298 data
= RREG32_SMC(config_regs
->offset
);
300 case KV_CONFIGREG_DIDT_IND
:
301 data
= RREG32_DIDT(config_regs
->offset
);
304 data
= RREG32(config_regs
->offset
<< 2);
308 data
&= ~config_regs
->mask
;
309 data
|= ((config_regs
->value
<< config_regs
->shift
) & config_regs
->mask
);
313 switch (config_regs
->type
) {
314 case KV_CONFIGREG_SMC_IND
:
315 WREG32_SMC(config_regs
->offset
, data
);
317 case KV_CONFIGREG_DIDT_IND
:
318 WREG32_DIDT(config_regs
->offset
, data
);
321 WREG32(config_regs
->offset
<< 2, data
);
331 static void kv_do_enable_didt(struct radeon_device
*rdev
, bool enable
)
333 struct kv_power_info
*pi
= kv_get_pi(rdev
);
336 if (pi
->caps_sq_ramping
) {
337 data
= RREG32_DIDT(DIDT_SQ_CTRL0
);
339 data
|= DIDT_CTRL_EN
;
341 data
&= ~DIDT_CTRL_EN
;
342 WREG32_DIDT(DIDT_SQ_CTRL0
, data
);
345 if (pi
->caps_db_ramping
) {
346 data
= RREG32_DIDT(DIDT_DB_CTRL0
);
348 data
|= DIDT_CTRL_EN
;
350 data
&= ~DIDT_CTRL_EN
;
351 WREG32_DIDT(DIDT_DB_CTRL0
, data
);
354 if (pi
->caps_td_ramping
) {
355 data
= RREG32_DIDT(DIDT_TD_CTRL0
);
357 data
|= DIDT_CTRL_EN
;
359 data
&= ~DIDT_CTRL_EN
;
360 WREG32_DIDT(DIDT_TD_CTRL0
, data
);
363 if (pi
->caps_tcp_ramping
) {
364 data
= RREG32_DIDT(DIDT_TCP_CTRL0
);
366 data
|= DIDT_CTRL_EN
;
368 data
&= ~DIDT_CTRL_EN
;
369 WREG32_DIDT(DIDT_TCP_CTRL0
, data
);
373 static int kv_enable_didt(struct radeon_device
*rdev
, bool enable
)
375 struct kv_power_info
*pi
= kv_get_pi(rdev
);
378 if (pi
->caps_sq_ramping
||
379 pi
->caps_db_ramping
||
380 pi
->caps_td_ramping
||
381 pi
->caps_tcp_ramping
) {
382 cik_enter_rlc_safe_mode(rdev
);
385 ret
= kv_program_pt_config_registers(rdev
, didt_config_kv
);
387 cik_exit_rlc_safe_mode(rdev
);
392 kv_do_enable_didt(rdev
, enable
);
394 cik_exit_rlc_safe_mode(rdev
);
401 static void kv_initialize_hardware_cac_manager(struct radeon_device
*rdev
)
403 struct kv_power_info
*pi
= kv_get_pi(rdev
);
406 WREG32_SMC(LCAC_SX0_OVR_SEL
, 0);
407 WREG32_SMC(LCAC_SX0_OVR_VAL
, 0);
408 kv_program_local_cac_table(rdev
, sx_local_cac_cfg_kv
, sx0_cac_config_reg
);
410 WREG32_SMC(LCAC_MC0_OVR_SEL
, 0);
411 WREG32_SMC(LCAC_MC0_OVR_VAL
, 0);
412 kv_program_local_cac_table(rdev
, mc0_local_cac_cfg_kv
, mc0_cac_config_reg
);
414 WREG32_SMC(LCAC_MC1_OVR_SEL
, 0);
415 WREG32_SMC(LCAC_MC1_OVR_VAL
, 0);
416 kv_program_local_cac_table(rdev
, mc1_local_cac_cfg_kv
, mc1_cac_config_reg
);
418 WREG32_SMC(LCAC_MC2_OVR_SEL
, 0);
419 WREG32_SMC(LCAC_MC2_OVR_VAL
, 0);
420 kv_program_local_cac_table(rdev
, mc2_local_cac_cfg_kv
, mc2_cac_config_reg
);
422 WREG32_SMC(LCAC_MC3_OVR_SEL
, 0);
423 WREG32_SMC(LCAC_MC3_OVR_VAL
, 0);
424 kv_program_local_cac_table(rdev
, mc3_local_cac_cfg_kv
, mc3_cac_config_reg
);
426 WREG32_SMC(LCAC_CPL_OVR_SEL
, 0);
427 WREG32_SMC(LCAC_CPL_OVR_VAL
, 0);
428 kv_program_local_cac_table(rdev
, cpl_local_cac_cfg_kv
, cpl_cac_config_reg
);
433 static int kv_enable_smc_cac(struct radeon_device
*rdev
, bool enable
)
435 struct kv_power_info
*pi
= kv_get_pi(rdev
);
440 ret
= kv_notify_message_to_smu(rdev
, PPSMC_MSG_EnableCac
);
442 pi
->cac_enabled
= false;
444 pi
->cac_enabled
= true;
445 } else if (pi
->cac_enabled
) {
446 kv_notify_message_to_smu(rdev
, PPSMC_MSG_DisableCac
);
447 pi
->cac_enabled
= false;
454 static int kv_process_firmware_header(struct radeon_device
*rdev
)
456 struct kv_power_info
*pi
= kv_get_pi(rdev
);
460 ret
= kv_read_smc_sram_dword(rdev
, SMU7_FIRMWARE_HEADER_LOCATION
+
461 offsetof(SMU7_Firmware_Header
, DpmTable
),
465 pi
->dpm_table_start
= tmp
;
467 ret
= kv_read_smc_sram_dword(rdev
, SMU7_FIRMWARE_HEADER_LOCATION
+
468 offsetof(SMU7_Firmware_Header
, SoftRegisters
),
472 pi
->soft_regs_start
= tmp
;
477 static int kv_enable_dpm_voltage_scaling(struct radeon_device
*rdev
)
479 struct kv_power_info
*pi
= kv_get_pi(rdev
);
482 pi
->graphics_voltage_change_enable
= 1;
484 ret
= kv_copy_bytes_to_smc(rdev
,
485 pi
->dpm_table_start
+
486 offsetof(SMU7_Fusion_DpmTable
, GraphicsVoltageChangeEnable
),
487 &pi
->graphics_voltage_change_enable
,
488 sizeof(u8
), pi
->sram_end
);
493 static int kv_set_dpm_interval(struct radeon_device
*rdev
)
495 struct kv_power_info
*pi
= kv_get_pi(rdev
);
498 pi
->graphics_interval
= 1;
500 ret
= kv_copy_bytes_to_smc(rdev
,
501 pi
->dpm_table_start
+
502 offsetof(SMU7_Fusion_DpmTable
, GraphicsInterval
),
503 &pi
->graphics_interval
,
504 sizeof(u8
), pi
->sram_end
);
509 static int kv_set_dpm_boot_state(struct radeon_device
*rdev
)
511 struct kv_power_info
*pi
= kv_get_pi(rdev
);
514 ret
= kv_copy_bytes_to_smc(rdev
,
515 pi
->dpm_table_start
+
516 offsetof(SMU7_Fusion_DpmTable
, GraphicsBootLevel
),
517 &pi
->graphics_boot_level
,
518 sizeof(u8
), pi
->sram_end
);
523 static void kv_program_vc(struct radeon_device
*rdev
)
525 WREG32_SMC(CG_FTV_0
, 0x3FFFC100);
528 static void kv_clear_vc(struct radeon_device
*rdev
)
530 WREG32_SMC(CG_FTV_0
, 0);
533 static int kv_set_divider_value(struct radeon_device
*rdev
,
536 struct kv_power_info
*pi
= kv_get_pi(rdev
);
537 struct atom_clock_dividers dividers
;
540 ret
= radeon_atom_get_clock_dividers(rdev
, COMPUTE_ENGINE_PLL_PARAM
,
541 sclk
, false, ÷rs
);
545 pi
->graphics_level
[index
].SclkDid
= (u8
)dividers
.post_div
;
546 pi
->graphics_level
[index
].SclkFrequency
= cpu_to_be32(sclk
);
551 static u32
kv_convert_vid2_to_vid7(struct radeon_device
*rdev
,
552 struct sumo_vid_mapping_table
*vid_mapping_table
,
555 struct radeon_clock_voltage_dependency_table
*vddc_sclk_table
=
556 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
;
559 if (vddc_sclk_table
&& vddc_sclk_table
->count
) {
560 if (vid_2bit
< vddc_sclk_table
->count
)
561 return vddc_sclk_table
->entries
[vid_2bit
].v
;
563 return vddc_sclk_table
->entries
[vddc_sclk_table
->count
- 1].v
;
565 for (i
= 0; i
< vid_mapping_table
->num_entries
; i
++) {
566 if (vid_mapping_table
->entries
[i
].vid_2bit
== vid_2bit
)
567 return vid_mapping_table
->entries
[i
].vid_7bit
;
569 return vid_mapping_table
->entries
[vid_mapping_table
->num_entries
- 1].vid_7bit
;
573 static u32
kv_convert_vid7_to_vid2(struct radeon_device
*rdev
,
574 struct sumo_vid_mapping_table
*vid_mapping_table
,
577 struct radeon_clock_voltage_dependency_table
*vddc_sclk_table
=
578 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
;
581 if (vddc_sclk_table
&& vddc_sclk_table
->count
) {
582 for (i
= 0; i
< vddc_sclk_table
->count
; i
++) {
583 if (vddc_sclk_table
->entries
[i
].v
== vid_7bit
)
586 return vddc_sclk_table
->count
- 1;
588 for (i
= 0; i
< vid_mapping_table
->num_entries
; i
++) {
589 if (vid_mapping_table
->entries
[i
].vid_7bit
== vid_7bit
)
590 return vid_mapping_table
->entries
[i
].vid_2bit
;
593 return vid_mapping_table
->entries
[vid_mapping_table
->num_entries
- 1].vid_2bit
;
597 static u16
kv_convert_8bit_index_to_voltage(struct radeon_device
*rdev
,
600 return 6200 - (voltage
* 25);
603 static u16
kv_convert_2bit_index_to_voltage(struct radeon_device
*rdev
,
606 struct kv_power_info
*pi
= kv_get_pi(rdev
);
607 u32 vid_8bit
= kv_convert_vid2_to_vid7(rdev
,
608 &pi
->sys_info
.vid_mapping_table
,
611 return kv_convert_8bit_index_to_voltage(rdev
, (u16
)vid_8bit
);
615 static int kv_set_vid(struct radeon_device
*rdev
, u32 index
, u32 vid
)
617 struct kv_power_info
*pi
= kv_get_pi(rdev
);
619 pi
->graphics_level
[index
].VoltageDownH
= (u8
)pi
->voltage_drop_t
;
620 pi
->graphics_level
[index
].MinVddNb
=
621 cpu_to_be32(kv_convert_2bit_index_to_voltage(rdev
, vid
));
626 static int kv_set_at(struct radeon_device
*rdev
, u32 index
, u32 at
)
628 struct kv_power_info
*pi
= kv_get_pi(rdev
);
630 pi
->graphics_level
[index
].AT
= cpu_to_be16((u16
)at
);
635 static void kv_dpm_power_level_enable(struct radeon_device
*rdev
,
636 u32 index
, bool enable
)
638 struct kv_power_info
*pi
= kv_get_pi(rdev
);
640 pi
->graphics_level
[index
].EnabledForActivity
= enable
? 1 : 0;
643 static void kv_start_dpm(struct radeon_device
*rdev
)
645 u32 tmp
= RREG32_SMC(GENERAL_PWRMGT
);
647 tmp
|= GLOBAL_PWRMGT_EN
;
648 WREG32_SMC(GENERAL_PWRMGT
, tmp
);
650 kv_smc_dpm_enable(rdev
, true);
653 static void kv_stop_dpm(struct radeon_device
*rdev
)
655 kv_smc_dpm_enable(rdev
, false);
658 static void kv_start_am(struct radeon_device
*rdev
)
660 u32 sclk_pwrmgt_cntl
= RREG32_SMC(SCLK_PWRMGT_CNTL
);
662 sclk_pwrmgt_cntl
&= ~(RESET_SCLK_CNT
| RESET_BUSY_CNT
);
663 sclk_pwrmgt_cntl
|= DYNAMIC_PM_EN
;
665 WREG32_SMC(SCLK_PWRMGT_CNTL
, sclk_pwrmgt_cntl
);
668 static void kv_reset_am(struct radeon_device
*rdev
)
670 u32 sclk_pwrmgt_cntl
= RREG32_SMC(SCLK_PWRMGT_CNTL
);
672 sclk_pwrmgt_cntl
|= (RESET_SCLK_CNT
| RESET_BUSY_CNT
);
674 WREG32_SMC(SCLK_PWRMGT_CNTL
, sclk_pwrmgt_cntl
);
677 static int kv_freeze_sclk_dpm(struct radeon_device
*rdev
, bool freeze
)
679 return kv_notify_message_to_smu(rdev
, freeze
?
680 PPSMC_MSG_SCLKDPM_FreezeLevel
: PPSMC_MSG_SCLKDPM_UnfreezeLevel
);
683 static int kv_force_lowest_valid(struct radeon_device
*rdev
)
685 return kv_force_dpm_lowest(rdev
);
688 static int kv_unforce_levels(struct radeon_device
*rdev
)
690 if (rdev
->family
== CHIP_KABINI
|| rdev
->family
== CHIP_MULLINS
)
691 return kv_notify_message_to_smu(rdev
, PPSMC_MSG_NoForcedLevel
);
693 return kv_set_enabled_levels(rdev
);
696 static int kv_update_sclk_t(struct radeon_device
*rdev
)
698 struct kv_power_info
*pi
= kv_get_pi(rdev
);
699 u32 low_sclk_interrupt_t
= 0;
702 if (pi
->caps_sclk_throttle_low_notification
) {
703 low_sclk_interrupt_t
= cpu_to_be32(pi
->low_sclk_interrupt_t
);
705 ret
= kv_copy_bytes_to_smc(rdev
,
706 pi
->dpm_table_start
+
707 offsetof(SMU7_Fusion_DpmTable
, LowSclkInterruptT
),
708 (u8
*)&low_sclk_interrupt_t
,
709 sizeof(u32
), pi
->sram_end
);
714 static int kv_program_bootup_state(struct radeon_device
*rdev
)
716 struct kv_power_info
*pi
= kv_get_pi(rdev
);
718 struct radeon_clock_voltage_dependency_table
*table
=
719 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
;
721 if (table
&& table
->count
) {
722 for (i
= pi
->graphics_dpm_level_count
- 1; i
> 0; i
--) {
723 if (table
->entries
[i
].clk
== pi
->boot_pl
.sclk
)
727 pi
->graphics_boot_level
= (u8
)i
;
728 kv_dpm_power_level_enable(rdev
, i
, true);
730 struct sumo_sclk_voltage_mapping_table
*table
=
731 &pi
->sys_info
.sclk_voltage_mapping_table
;
733 if (table
->num_max_dpm_entries
== 0)
736 for (i
= pi
->graphics_dpm_level_count
- 1; i
> 0; i
--) {
737 if (table
->entries
[i
].sclk_frequency
== pi
->boot_pl
.sclk
)
741 pi
->graphics_boot_level
= (u8
)i
;
742 kv_dpm_power_level_enable(rdev
, i
, true);
747 static int kv_enable_auto_thermal_throttling(struct radeon_device
*rdev
)
749 struct kv_power_info
*pi
= kv_get_pi(rdev
);
752 pi
->graphics_therm_throttle_enable
= 1;
754 ret
= kv_copy_bytes_to_smc(rdev
,
755 pi
->dpm_table_start
+
756 offsetof(SMU7_Fusion_DpmTable
, GraphicsThermThrottleEnable
),
757 &pi
->graphics_therm_throttle_enable
,
758 sizeof(u8
), pi
->sram_end
);
763 static int kv_upload_dpm_settings(struct radeon_device
*rdev
)
765 struct kv_power_info
*pi
= kv_get_pi(rdev
);
768 ret
= kv_copy_bytes_to_smc(rdev
,
769 pi
->dpm_table_start
+
770 offsetof(SMU7_Fusion_DpmTable
, GraphicsLevel
),
771 (u8
*)&pi
->graphics_level
,
772 sizeof(SMU7_Fusion_GraphicsLevel
) * SMU7_MAX_LEVELS_GRAPHICS
,
778 ret
= kv_copy_bytes_to_smc(rdev
,
779 pi
->dpm_table_start
+
780 offsetof(SMU7_Fusion_DpmTable
, GraphicsDpmLevelCount
),
781 &pi
->graphics_dpm_level_count
,
782 sizeof(u8
), pi
->sram_end
);
787 static u32
kv_get_clock_difference(u32 a
, u32 b
)
789 return (a
>= b
) ? a
- b
: b
- a
;
792 static u32
kv_get_clk_bypass(struct radeon_device
*rdev
, u32 clk
)
794 struct kv_power_info
*pi
= kv_get_pi(rdev
);
797 if (pi
->caps_enable_dfs_bypass
) {
798 if (kv_get_clock_difference(clk
, 40000) < 200)
800 else if (kv_get_clock_difference(clk
, 30000) < 200)
802 else if (kv_get_clock_difference(clk
, 20000) < 200)
804 else if (kv_get_clock_difference(clk
, 15000) < 200)
806 else if (kv_get_clock_difference(clk
, 10000) < 200)
817 static int kv_populate_uvd_table(struct radeon_device
*rdev
)
819 struct kv_power_info
*pi
= kv_get_pi(rdev
);
820 struct radeon_uvd_clock_voltage_dependency_table
*table
=
821 &rdev
->pm
.dpm
.dyn_state
.uvd_clock_voltage_dependency_table
;
822 struct atom_clock_dividers dividers
;
826 if (table
== NULL
|| table
->count
== 0)
829 pi
->uvd_level_count
= 0;
830 for (i
= 0; i
< table
->count
; i
++) {
831 if (pi
->high_voltage_t
&&
832 (pi
->high_voltage_t
< table
->entries
[i
].v
))
835 pi
->uvd_level
[i
].VclkFrequency
= cpu_to_be32(table
->entries
[i
].vclk
);
836 pi
->uvd_level
[i
].DclkFrequency
= cpu_to_be32(table
->entries
[i
].dclk
);
837 pi
->uvd_level
[i
].MinVddNb
= cpu_to_be16(table
->entries
[i
].v
);
839 pi
->uvd_level
[i
].VClkBypassCntl
=
840 (u8
)kv_get_clk_bypass(rdev
, table
->entries
[i
].vclk
);
841 pi
->uvd_level
[i
].DClkBypassCntl
=
842 (u8
)kv_get_clk_bypass(rdev
, table
->entries
[i
].dclk
);
844 ret
= radeon_atom_get_clock_dividers(rdev
, COMPUTE_ENGINE_PLL_PARAM
,
845 table
->entries
[i
].vclk
, false, ÷rs
);
848 pi
->uvd_level
[i
].VclkDivider
= (u8
)dividers
.post_div
;
850 ret
= radeon_atom_get_clock_dividers(rdev
, COMPUTE_ENGINE_PLL_PARAM
,
851 table
->entries
[i
].dclk
, false, ÷rs
);
854 pi
->uvd_level
[i
].DclkDivider
= (u8
)dividers
.post_div
;
856 pi
->uvd_level_count
++;
859 ret
= kv_copy_bytes_to_smc(rdev
,
860 pi
->dpm_table_start
+
861 offsetof(SMU7_Fusion_DpmTable
, UvdLevelCount
),
862 (u8
*)&pi
->uvd_level_count
,
863 sizeof(u8
), pi
->sram_end
);
867 pi
->uvd_interval
= 1;
869 ret
= kv_copy_bytes_to_smc(rdev
,
870 pi
->dpm_table_start
+
871 offsetof(SMU7_Fusion_DpmTable
, UVDInterval
),
873 sizeof(u8
), pi
->sram_end
);
877 ret
= kv_copy_bytes_to_smc(rdev
,
878 pi
->dpm_table_start
+
879 offsetof(SMU7_Fusion_DpmTable
, UvdLevel
),
880 (u8
*)&pi
->uvd_level
,
881 sizeof(SMU7_Fusion_UvdLevel
) * SMU7_MAX_LEVELS_UVD
,
888 static int kv_populate_vce_table(struct radeon_device
*rdev
)
890 struct kv_power_info
*pi
= kv_get_pi(rdev
);
893 struct radeon_vce_clock_voltage_dependency_table
*table
=
894 &rdev
->pm
.dpm
.dyn_state
.vce_clock_voltage_dependency_table
;
895 struct atom_clock_dividers dividers
;
897 if (table
== NULL
|| table
->count
== 0)
900 pi
->vce_level_count
= 0;
901 for (i
= 0; i
< table
->count
; i
++) {
902 if (pi
->high_voltage_t
&&
903 pi
->high_voltage_t
< table
->entries
[i
].v
)
906 pi
->vce_level
[i
].Frequency
= cpu_to_be32(table
->entries
[i
].evclk
);
907 pi
->vce_level
[i
].MinVoltage
= cpu_to_be16(table
->entries
[i
].v
);
909 pi
->vce_level
[i
].ClkBypassCntl
=
910 (u8
)kv_get_clk_bypass(rdev
, table
->entries
[i
].evclk
);
912 ret
= radeon_atom_get_clock_dividers(rdev
, COMPUTE_ENGINE_PLL_PARAM
,
913 table
->entries
[i
].evclk
, false, ÷rs
);
916 pi
->vce_level
[i
].Divider
= (u8
)dividers
.post_div
;
918 pi
->vce_level_count
++;
921 ret
= kv_copy_bytes_to_smc(rdev
,
922 pi
->dpm_table_start
+
923 offsetof(SMU7_Fusion_DpmTable
, VceLevelCount
),
924 (u8
*)&pi
->vce_level_count
,
930 pi
->vce_interval
= 1;
932 ret
= kv_copy_bytes_to_smc(rdev
,
933 pi
->dpm_table_start
+
934 offsetof(SMU7_Fusion_DpmTable
, VCEInterval
),
935 (u8
*)&pi
->vce_interval
,
941 ret
= kv_copy_bytes_to_smc(rdev
,
942 pi
->dpm_table_start
+
943 offsetof(SMU7_Fusion_DpmTable
, VceLevel
),
944 (u8
*)&pi
->vce_level
,
945 sizeof(SMU7_Fusion_ExtClkLevel
) * SMU7_MAX_LEVELS_VCE
,
951 static int kv_populate_samu_table(struct radeon_device
*rdev
)
953 struct kv_power_info
*pi
= kv_get_pi(rdev
);
954 struct radeon_clock_voltage_dependency_table
*table
=
955 &rdev
->pm
.dpm
.dyn_state
.samu_clock_voltage_dependency_table
;
956 struct atom_clock_dividers dividers
;
960 if (table
== NULL
|| table
->count
== 0)
963 pi
->samu_level_count
= 0;
964 for (i
= 0; i
< table
->count
; i
++) {
965 if (pi
->high_voltage_t
&&
966 pi
->high_voltage_t
< table
->entries
[i
].v
)
969 pi
->samu_level
[i
].Frequency
= cpu_to_be32(table
->entries
[i
].clk
);
970 pi
->samu_level
[i
].MinVoltage
= cpu_to_be16(table
->entries
[i
].v
);
972 pi
->samu_level
[i
].ClkBypassCntl
=
973 (u8
)kv_get_clk_bypass(rdev
, table
->entries
[i
].clk
);
975 ret
= radeon_atom_get_clock_dividers(rdev
, COMPUTE_ENGINE_PLL_PARAM
,
976 table
->entries
[i
].clk
, false, ÷rs
);
979 pi
->samu_level
[i
].Divider
= (u8
)dividers
.post_div
;
981 pi
->samu_level_count
++;
984 ret
= kv_copy_bytes_to_smc(rdev
,
985 pi
->dpm_table_start
+
986 offsetof(SMU7_Fusion_DpmTable
, SamuLevelCount
),
987 (u8
*)&pi
->samu_level_count
,
993 pi
->samu_interval
= 1;
995 ret
= kv_copy_bytes_to_smc(rdev
,
996 pi
->dpm_table_start
+
997 offsetof(SMU7_Fusion_DpmTable
, SAMUInterval
),
998 (u8
*)&pi
->samu_interval
,
1004 ret
= kv_copy_bytes_to_smc(rdev
,
1005 pi
->dpm_table_start
+
1006 offsetof(SMU7_Fusion_DpmTable
, SamuLevel
),
1007 (u8
*)&pi
->samu_level
,
1008 sizeof(SMU7_Fusion_ExtClkLevel
) * SMU7_MAX_LEVELS_SAMU
,
1017 static int kv_populate_acp_table(struct radeon_device
*rdev
)
1019 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1020 struct radeon_clock_voltage_dependency_table
*table
=
1021 &rdev
->pm
.dpm
.dyn_state
.acp_clock_voltage_dependency_table
;
1022 struct atom_clock_dividers dividers
;
1026 if (table
== NULL
|| table
->count
== 0)
1029 pi
->acp_level_count
= 0;
1030 for (i
= 0; i
< table
->count
; i
++) {
1031 pi
->acp_level
[i
].Frequency
= cpu_to_be32(table
->entries
[i
].clk
);
1032 pi
->acp_level
[i
].MinVoltage
= cpu_to_be16(table
->entries
[i
].v
);
1034 ret
= radeon_atom_get_clock_dividers(rdev
, COMPUTE_ENGINE_PLL_PARAM
,
1035 table
->entries
[i
].clk
, false, ÷rs
);
1038 pi
->acp_level
[i
].Divider
= (u8
)dividers
.post_div
;
1040 pi
->acp_level_count
++;
1043 ret
= kv_copy_bytes_to_smc(rdev
,
1044 pi
->dpm_table_start
+
1045 offsetof(SMU7_Fusion_DpmTable
, AcpLevelCount
),
1046 (u8
*)&pi
->acp_level_count
,
1052 pi
->acp_interval
= 1;
1054 ret
= kv_copy_bytes_to_smc(rdev
,
1055 pi
->dpm_table_start
+
1056 offsetof(SMU7_Fusion_DpmTable
, ACPInterval
),
1057 (u8
*)&pi
->acp_interval
,
1063 ret
= kv_copy_bytes_to_smc(rdev
,
1064 pi
->dpm_table_start
+
1065 offsetof(SMU7_Fusion_DpmTable
, AcpLevel
),
1066 (u8
*)&pi
->acp_level
,
1067 sizeof(SMU7_Fusion_ExtClkLevel
) * SMU7_MAX_LEVELS_ACP
,
1075 static void kv_calculate_dfs_bypass_settings(struct radeon_device
*rdev
)
1077 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1079 struct radeon_clock_voltage_dependency_table
*table
=
1080 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
;
1082 if (table
&& table
->count
) {
1083 for (i
= 0; i
< pi
->graphics_dpm_level_count
; i
++) {
1084 if (pi
->caps_enable_dfs_bypass
) {
1085 if (kv_get_clock_difference(table
->entries
[i
].clk
, 40000) < 200)
1086 pi
->graphics_level
[i
].ClkBypassCntl
= 3;
1087 else if (kv_get_clock_difference(table
->entries
[i
].clk
, 30000) < 200)
1088 pi
->graphics_level
[i
].ClkBypassCntl
= 2;
1089 else if (kv_get_clock_difference(table
->entries
[i
].clk
, 26600) < 200)
1090 pi
->graphics_level
[i
].ClkBypassCntl
= 7;
1091 else if (kv_get_clock_difference(table
->entries
[i
].clk
, 20000) < 200)
1092 pi
->graphics_level
[i
].ClkBypassCntl
= 6;
1093 else if (kv_get_clock_difference(table
->entries
[i
].clk
, 10000) < 200)
1094 pi
->graphics_level
[i
].ClkBypassCntl
= 8;
1096 pi
->graphics_level
[i
].ClkBypassCntl
= 0;
1098 pi
->graphics_level
[i
].ClkBypassCntl
= 0;
1102 struct sumo_sclk_voltage_mapping_table
*table
=
1103 &pi
->sys_info
.sclk_voltage_mapping_table
;
1104 for (i
= 0; i
< pi
->graphics_dpm_level_count
; i
++) {
1105 if (pi
->caps_enable_dfs_bypass
) {
1106 if (kv_get_clock_difference(table
->entries
[i
].sclk_frequency
, 40000) < 200)
1107 pi
->graphics_level
[i
].ClkBypassCntl
= 3;
1108 else if (kv_get_clock_difference(table
->entries
[i
].sclk_frequency
, 30000) < 200)
1109 pi
->graphics_level
[i
].ClkBypassCntl
= 2;
1110 else if (kv_get_clock_difference(table
->entries
[i
].sclk_frequency
, 26600) < 200)
1111 pi
->graphics_level
[i
].ClkBypassCntl
= 7;
1112 else if (kv_get_clock_difference(table
->entries
[i
].sclk_frequency
, 20000) < 200)
1113 pi
->graphics_level
[i
].ClkBypassCntl
= 6;
1114 else if (kv_get_clock_difference(table
->entries
[i
].sclk_frequency
, 10000) < 200)
1115 pi
->graphics_level
[i
].ClkBypassCntl
= 8;
1117 pi
->graphics_level
[i
].ClkBypassCntl
= 0;
1119 pi
->graphics_level
[i
].ClkBypassCntl
= 0;
1125 static int kv_enable_ulv(struct radeon_device
*rdev
, bool enable
)
1127 return kv_notify_message_to_smu(rdev
, enable
?
1128 PPSMC_MSG_EnableULV
: PPSMC_MSG_DisableULV
);
1131 static void kv_reset_acp_boot_level(struct radeon_device
*rdev
)
1133 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1135 pi
->acp_boot_level
= 0xff;
1138 static void kv_update_current_ps(struct radeon_device
*rdev
,
1139 struct radeon_ps
*rps
)
1141 struct kv_ps
*new_ps
= kv_get_ps(rps
);
1142 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1144 pi
->current_rps
= *rps
;
1145 pi
->current_ps
= *new_ps
;
1146 pi
->current_rps
.ps_priv
= &pi
->current_ps
;
1149 static void kv_update_requested_ps(struct radeon_device
*rdev
,
1150 struct radeon_ps
*rps
)
1152 struct kv_ps
*new_ps
= kv_get_ps(rps
);
1153 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1155 pi
->requested_rps
= *rps
;
1156 pi
->requested_ps
= *new_ps
;
1157 pi
->requested_rps
.ps_priv
= &pi
->requested_ps
;
1160 void kv_dpm_enable_bapm(struct radeon_device
*rdev
, bool enable
)
1162 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1165 if (pi
->bapm_enable
) {
1166 ret
= kv_smc_bapm_enable(rdev
, enable
);
1168 DRM_ERROR("kv_smc_bapm_enable failed\n");
1172 static void kv_enable_thermal_int(struct radeon_device
*rdev
, bool enable
)
1176 thermal_int
= RREG32_SMC(CG_THERMAL_INT_CTRL
);
1178 thermal_int
|= THERM_INTH_MASK
| THERM_INTL_MASK
;
1180 thermal_int
&= ~(THERM_INTH_MASK
| THERM_INTL_MASK
);
1181 WREG32_SMC(CG_THERMAL_INT_CTRL
, thermal_int
);
1185 int kv_dpm_enable(struct radeon_device
*rdev
)
1187 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1190 ret
= kv_process_firmware_header(rdev
);
1192 DRM_ERROR("kv_process_firmware_header failed\n");
1195 kv_init_fps_limits(rdev
);
1196 kv_init_graphics_levels(rdev
);
1197 ret
= kv_program_bootup_state(rdev
);
1199 DRM_ERROR("kv_program_bootup_state failed\n");
1202 kv_calculate_dfs_bypass_settings(rdev
);
1203 ret
= kv_upload_dpm_settings(rdev
);
1205 DRM_ERROR("kv_upload_dpm_settings failed\n");
1208 ret
= kv_populate_uvd_table(rdev
);
1210 DRM_ERROR("kv_populate_uvd_table failed\n");
1213 ret
= kv_populate_vce_table(rdev
);
1215 DRM_ERROR("kv_populate_vce_table failed\n");
1218 ret
= kv_populate_samu_table(rdev
);
1220 DRM_ERROR("kv_populate_samu_table failed\n");
1223 ret
= kv_populate_acp_table(rdev
);
1225 DRM_ERROR("kv_populate_acp_table failed\n");
1228 kv_program_vc(rdev
);
1230 kv_initialize_hardware_cac_manager(rdev
);
1233 if (pi
->enable_auto_thermal_throttling
) {
1234 ret
= kv_enable_auto_thermal_throttling(rdev
);
1236 DRM_ERROR("kv_enable_auto_thermal_throttling failed\n");
1240 ret
= kv_enable_dpm_voltage_scaling(rdev
);
1242 DRM_ERROR("kv_enable_dpm_voltage_scaling failed\n");
1245 ret
= kv_set_dpm_interval(rdev
);
1247 DRM_ERROR("kv_set_dpm_interval failed\n");
1250 ret
= kv_set_dpm_boot_state(rdev
);
1252 DRM_ERROR("kv_set_dpm_boot_state failed\n");
1255 ret
= kv_enable_ulv(rdev
, true);
1257 DRM_ERROR("kv_enable_ulv failed\n");
1261 ret
= kv_enable_didt(rdev
, true);
1263 DRM_ERROR("kv_enable_didt failed\n");
1266 ret
= kv_enable_smc_cac(rdev
, true);
1268 DRM_ERROR("kv_enable_smc_cac failed\n");
1272 kv_reset_acp_boot_level(rdev
);
1274 ret
= kv_smc_bapm_enable(rdev
, false);
1276 DRM_ERROR("kv_smc_bapm_enable failed\n");
1280 kv_update_current_ps(rdev
, rdev
->pm
.dpm
.boot_ps
);
1285 int kv_dpm_late_enable(struct radeon_device
*rdev
)
1289 if (rdev
->irq
.installed
&&
1290 r600_is_internal_thermal_sensor(rdev
->pm
.int_thermal_type
)) {
1291 ret
= kv_set_thermal_temperature_range(rdev
, R600_TEMP_RANGE_MIN
, R600_TEMP_RANGE_MAX
);
1293 DRM_ERROR("kv_set_thermal_temperature_range failed\n");
1296 kv_enable_thermal_int(rdev
, true);
1299 /* powerdown unused blocks for now */
1300 kv_dpm_powergate_acp(rdev
, true);
1301 kv_dpm_powergate_samu(rdev
, true);
1302 kv_dpm_powergate_vce(rdev
, true);
1303 kv_dpm_powergate_uvd(rdev
, true);
1308 void kv_dpm_disable(struct radeon_device
*rdev
)
1310 kv_smc_bapm_enable(rdev
, false);
1312 if (rdev
->family
== CHIP_MULLINS
)
1313 kv_enable_nb_dpm(rdev
, false);
1315 /* powerup blocks */
1316 kv_dpm_powergate_acp(rdev
, false);
1317 kv_dpm_powergate_samu(rdev
, false);
1318 kv_dpm_powergate_vce(rdev
, false);
1319 kv_dpm_powergate_uvd(rdev
, false);
1321 kv_enable_smc_cac(rdev
, false);
1322 kv_enable_didt(rdev
, false);
1325 kv_enable_ulv(rdev
, false);
1327 kv_enable_thermal_int(rdev
, false);
1329 kv_update_current_ps(rdev
, rdev
->pm
.dpm
.boot_ps
);
1333 static int kv_write_smc_soft_register(struct radeon_device
*rdev
,
1334 u16 reg_offset
, u32 value
)
1336 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1338 return kv_copy_bytes_to_smc(rdev
, pi
->soft_regs_start
+ reg_offset
,
1339 (u8
*)&value
, sizeof(u16
), pi
->sram_end
);
1342 static int kv_read_smc_soft_register(struct radeon_device
*rdev
,
1343 u16 reg_offset
, u32
*value
)
1345 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1347 return kv_read_smc_sram_dword(rdev
, pi
->soft_regs_start
+ reg_offset
,
1348 value
, pi
->sram_end
);
1352 static void kv_init_sclk_t(struct radeon_device
*rdev
)
1354 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1356 pi
->low_sclk_interrupt_t
= 0;
1359 static int kv_init_fps_limits(struct radeon_device
*rdev
)
1361 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1368 pi
->fps_high_t
= cpu_to_be16(tmp
);
1369 ret
= kv_copy_bytes_to_smc(rdev
,
1370 pi
->dpm_table_start
+
1371 offsetof(SMU7_Fusion_DpmTable
, FpsHighT
),
1372 (u8
*)&pi
->fps_high_t
,
1373 sizeof(u16
), pi
->sram_end
);
1376 pi
->fps_low_t
= cpu_to_be16(tmp
);
1378 ret
= kv_copy_bytes_to_smc(rdev
,
1379 pi
->dpm_table_start
+
1380 offsetof(SMU7_Fusion_DpmTable
, FpsLowT
),
1381 (u8
*)&pi
->fps_low_t
,
1382 sizeof(u16
), pi
->sram_end
);
1388 static void kv_init_powergate_state(struct radeon_device
*rdev
)
1390 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1392 pi
->uvd_power_gated
= false;
1393 pi
->vce_power_gated
= false;
1394 pi
->samu_power_gated
= false;
1395 pi
->acp_power_gated
= false;
1399 static int kv_enable_uvd_dpm(struct radeon_device
*rdev
, bool enable
)
1401 return kv_notify_message_to_smu(rdev
, enable
?
1402 PPSMC_MSG_UVDDPM_Enable
: PPSMC_MSG_UVDDPM_Disable
);
1405 static int kv_enable_vce_dpm(struct radeon_device
*rdev
, bool enable
)
1407 return kv_notify_message_to_smu(rdev
, enable
?
1408 PPSMC_MSG_VCEDPM_Enable
: PPSMC_MSG_VCEDPM_Disable
);
1411 static int kv_enable_samu_dpm(struct radeon_device
*rdev
, bool enable
)
1413 return kv_notify_message_to_smu(rdev
, enable
?
1414 PPSMC_MSG_SAMUDPM_Enable
: PPSMC_MSG_SAMUDPM_Disable
);
1417 static int kv_enable_acp_dpm(struct radeon_device
*rdev
, bool enable
)
1419 return kv_notify_message_to_smu(rdev
, enable
?
1420 PPSMC_MSG_ACPDPM_Enable
: PPSMC_MSG_ACPDPM_Disable
);
1423 static int kv_update_uvd_dpm(struct radeon_device
*rdev
, bool gate
)
1425 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1426 struct radeon_uvd_clock_voltage_dependency_table
*table
=
1427 &rdev
->pm
.dpm
.dyn_state
.uvd_clock_voltage_dependency_table
;
1433 pi
->uvd_boot_level
= table
->count
- 1;
1435 pi
->uvd_boot_level
= 0;
1437 if (!pi
->caps_uvd_dpm
|| pi
->caps_stable_p_state
) {
1438 mask
= 1 << pi
->uvd_boot_level
;
1443 ret
= kv_copy_bytes_to_smc(rdev
,
1444 pi
->dpm_table_start
+
1445 offsetof(SMU7_Fusion_DpmTable
, UvdBootLevel
),
1446 (uint8_t *)&pi
->uvd_boot_level
,
1447 sizeof(u8
), pi
->sram_end
);
1451 kv_send_msg_to_smc_with_parameter(rdev
,
1452 PPSMC_MSG_UVDDPM_SetEnabledMask
,
1456 return kv_enable_uvd_dpm(rdev
, !gate
);
1459 static u8
kv_get_vce_boot_level(struct radeon_device
*rdev
, u32 evclk
)
1462 struct radeon_vce_clock_voltage_dependency_table
*table
=
1463 &rdev
->pm
.dpm
.dyn_state
.vce_clock_voltage_dependency_table
;
1465 for (i
= 0; i
< table
->count
; i
++) {
1466 if (table
->entries
[i
].evclk
>= evclk
)
1473 static int kv_update_vce_dpm(struct radeon_device
*rdev
,
1474 struct radeon_ps
*radeon_new_state
,
1475 struct radeon_ps
*radeon_current_state
)
1477 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1478 struct radeon_vce_clock_voltage_dependency_table
*table
=
1479 &rdev
->pm
.dpm
.dyn_state
.vce_clock_voltage_dependency_table
;
1482 if (radeon_new_state
->evclk
> 0 && radeon_current_state
->evclk
== 0) {
1483 kv_dpm_powergate_vce(rdev
, false);
1484 /* turn the clocks on when encoding */
1485 cik_update_cg(rdev
, RADEON_CG_BLOCK_VCE
, false);
1486 if (pi
->caps_stable_p_state
)
1487 pi
->vce_boot_level
= table
->count
- 1;
1489 pi
->vce_boot_level
= kv_get_vce_boot_level(rdev
, radeon_new_state
->evclk
);
1491 ret
= kv_copy_bytes_to_smc(rdev
,
1492 pi
->dpm_table_start
+
1493 offsetof(SMU7_Fusion_DpmTable
, VceBootLevel
),
1494 (u8
*)&pi
->vce_boot_level
,
1500 if (pi
->caps_stable_p_state
)
1501 kv_send_msg_to_smc_with_parameter(rdev
,
1502 PPSMC_MSG_VCEDPM_SetEnabledMask
,
1503 (1 << pi
->vce_boot_level
));
1505 kv_enable_vce_dpm(rdev
, true);
1506 } else if (radeon_new_state
->evclk
== 0 && radeon_current_state
->evclk
> 0) {
1507 kv_enable_vce_dpm(rdev
, false);
1508 /* turn the clocks off when not encoding */
1509 cik_update_cg(rdev
, RADEON_CG_BLOCK_VCE
, true);
1510 kv_dpm_powergate_vce(rdev
, true);
1516 static int kv_update_samu_dpm(struct radeon_device
*rdev
, bool gate
)
1518 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1519 struct radeon_clock_voltage_dependency_table
*table
=
1520 &rdev
->pm
.dpm
.dyn_state
.samu_clock_voltage_dependency_table
;
1524 if (pi
->caps_stable_p_state
)
1525 pi
->samu_boot_level
= table
->count
- 1;
1527 pi
->samu_boot_level
= 0;
1529 ret
= kv_copy_bytes_to_smc(rdev
,
1530 pi
->dpm_table_start
+
1531 offsetof(SMU7_Fusion_DpmTable
, SamuBootLevel
),
1532 (u8
*)&pi
->samu_boot_level
,
1538 if (pi
->caps_stable_p_state
)
1539 kv_send_msg_to_smc_with_parameter(rdev
,
1540 PPSMC_MSG_SAMUDPM_SetEnabledMask
,
1541 (1 << pi
->samu_boot_level
));
1544 return kv_enable_samu_dpm(rdev
, !gate
);
1547 static u8
kv_get_acp_boot_level(struct radeon_device
*rdev
)
1550 struct radeon_clock_voltage_dependency_table
*table
=
1551 &rdev
->pm
.dpm
.dyn_state
.acp_clock_voltage_dependency_table
;
1553 for (i
= 0; i
< table
->count
; i
++) {
1554 if (table
->entries
[i
].clk
>= 0) /* XXX */
1558 if (i
>= table
->count
)
1559 i
= table
->count
- 1;
1564 static void kv_update_acp_boot_level(struct radeon_device
*rdev
)
1566 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1569 if (!pi
->caps_stable_p_state
) {
1570 acp_boot_level
= kv_get_acp_boot_level(rdev
);
1571 if (acp_boot_level
!= pi
->acp_boot_level
) {
1572 pi
->acp_boot_level
= acp_boot_level
;
1573 kv_send_msg_to_smc_with_parameter(rdev
,
1574 PPSMC_MSG_ACPDPM_SetEnabledMask
,
1575 (1 << pi
->acp_boot_level
));
1580 static int kv_update_acp_dpm(struct radeon_device
*rdev
, bool gate
)
1582 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1583 struct radeon_clock_voltage_dependency_table
*table
=
1584 &rdev
->pm
.dpm
.dyn_state
.acp_clock_voltage_dependency_table
;
1588 if (pi
->caps_stable_p_state
)
1589 pi
->acp_boot_level
= table
->count
- 1;
1591 pi
->acp_boot_level
= kv_get_acp_boot_level(rdev
);
1593 ret
= kv_copy_bytes_to_smc(rdev
,
1594 pi
->dpm_table_start
+
1595 offsetof(SMU7_Fusion_DpmTable
, AcpBootLevel
),
1596 (u8
*)&pi
->acp_boot_level
,
1602 if (pi
->caps_stable_p_state
)
1603 kv_send_msg_to_smc_with_parameter(rdev
,
1604 PPSMC_MSG_ACPDPM_SetEnabledMask
,
1605 (1 << pi
->acp_boot_level
));
1608 return kv_enable_acp_dpm(rdev
, !gate
);
1611 void kv_dpm_powergate_uvd(struct radeon_device
*rdev
, bool gate
)
1613 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1615 if (pi
->uvd_power_gated
== gate
)
1618 pi
->uvd_power_gated
= gate
;
1621 if (pi
->caps_uvd_pg
) {
1622 uvd_v1_0_stop(rdev
);
1623 cik_update_cg(rdev
, RADEON_CG_BLOCK_UVD
, false);
1625 kv_update_uvd_dpm(rdev
, gate
);
1626 if (pi
->caps_uvd_pg
)
1627 kv_notify_message_to_smu(rdev
, PPSMC_MSG_UVDPowerOFF
);
1629 if (pi
->caps_uvd_pg
) {
1630 kv_notify_message_to_smu(rdev
, PPSMC_MSG_UVDPowerON
);
1631 uvd_v4_2_resume(rdev
);
1632 uvd_v1_0_start(rdev
);
1633 cik_update_cg(rdev
, RADEON_CG_BLOCK_UVD
, true);
1635 kv_update_uvd_dpm(rdev
, gate
);
1639 static void kv_dpm_powergate_vce(struct radeon_device
*rdev
, bool gate
)
1641 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1643 if (pi
->vce_power_gated
== gate
)
1646 pi
->vce_power_gated
= gate
;
1649 if (pi
->caps_vce_pg
) {
1650 /* XXX do we need a vce_v1_0_stop() ? */
1651 kv_notify_message_to_smu(rdev
, PPSMC_MSG_VCEPowerOFF
);
1654 if (pi
->caps_vce_pg
) {
1655 kv_notify_message_to_smu(rdev
, PPSMC_MSG_VCEPowerON
);
1656 vce_v2_0_resume(rdev
);
1657 vce_v1_0_start(rdev
);
1662 static void kv_dpm_powergate_samu(struct radeon_device
*rdev
, bool gate
)
1664 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1666 if (pi
->samu_power_gated
== gate
)
1669 pi
->samu_power_gated
= gate
;
1672 kv_update_samu_dpm(rdev
, true);
1673 if (pi
->caps_samu_pg
)
1674 kv_notify_message_to_smu(rdev
, PPSMC_MSG_SAMPowerOFF
);
1676 if (pi
->caps_samu_pg
)
1677 kv_notify_message_to_smu(rdev
, PPSMC_MSG_SAMPowerON
);
1678 kv_update_samu_dpm(rdev
, false);
1682 static void kv_dpm_powergate_acp(struct radeon_device
*rdev
, bool gate
)
1684 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1686 if (pi
->acp_power_gated
== gate
)
1689 if (rdev
->family
== CHIP_KABINI
|| rdev
->family
== CHIP_MULLINS
)
1692 pi
->acp_power_gated
= gate
;
1695 kv_update_acp_dpm(rdev
, true);
1696 if (pi
->caps_acp_pg
)
1697 kv_notify_message_to_smu(rdev
, PPSMC_MSG_ACPPowerOFF
);
1699 if (pi
->caps_acp_pg
)
1700 kv_notify_message_to_smu(rdev
, PPSMC_MSG_ACPPowerON
);
1701 kv_update_acp_dpm(rdev
, false);
1705 static void kv_set_valid_clock_range(struct radeon_device
*rdev
,
1706 struct radeon_ps
*new_rps
)
1708 struct kv_ps
*new_ps
= kv_get_ps(new_rps
);
1709 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1711 struct radeon_clock_voltage_dependency_table
*table
=
1712 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
;
1714 if (table
&& table
->count
) {
1715 for (i
= 0; i
< pi
->graphics_dpm_level_count
; i
++) {
1716 if ((table
->entries
[i
].clk
>= new_ps
->levels
[0].sclk
) ||
1717 (i
== (pi
->graphics_dpm_level_count
- 1))) {
1718 pi
->lowest_valid
= i
;
1723 for (i
= pi
->graphics_dpm_level_count
- 1; i
> 0; i
--) {
1724 if (table
->entries
[i
].clk
<= new_ps
->levels
[new_ps
->num_levels
- 1].sclk
)
1727 pi
->highest_valid
= i
;
1729 if (pi
->lowest_valid
> pi
->highest_valid
) {
1730 if ((new_ps
->levels
[0].sclk
- table
->entries
[pi
->highest_valid
].clk
) >
1731 (table
->entries
[pi
->lowest_valid
].clk
- new_ps
->levels
[new_ps
->num_levels
- 1].sclk
))
1732 pi
->highest_valid
= pi
->lowest_valid
;
1734 pi
->lowest_valid
= pi
->highest_valid
;
1737 struct sumo_sclk_voltage_mapping_table
*table
=
1738 &pi
->sys_info
.sclk_voltage_mapping_table
;
1740 for (i
= 0; i
< (int)pi
->graphics_dpm_level_count
; i
++) {
1741 if (table
->entries
[i
].sclk_frequency
>= new_ps
->levels
[0].sclk
||
1742 i
== (int)(pi
->graphics_dpm_level_count
- 1)) {
1743 pi
->lowest_valid
= i
;
1748 for (i
= pi
->graphics_dpm_level_count
- 1; i
> 0; i
--) {
1749 if (table
->entries
[i
].sclk_frequency
<=
1750 new_ps
->levels
[new_ps
->num_levels
- 1].sclk
)
1753 pi
->highest_valid
= i
;
1755 if (pi
->lowest_valid
> pi
->highest_valid
) {
1756 if ((new_ps
->levels
[0].sclk
-
1757 table
->entries
[pi
->highest_valid
].sclk_frequency
) >
1758 (table
->entries
[pi
->lowest_valid
].sclk_frequency
-
1759 new_ps
->levels
[new_ps
->num_levels
-1].sclk
))
1760 pi
->highest_valid
= pi
->lowest_valid
;
1762 pi
->lowest_valid
= pi
->highest_valid
;
1767 static int kv_update_dfs_bypass_settings(struct radeon_device
*rdev
,
1768 struct radeon_ps
*new_rps
)
1770 struct kv_ps
*new_ps
= kv_get_ps(new_rps
);
1771 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1775 if (pi
->caps_enable_dfs_bypass
) {
1776 clk_bypass_cntl
= new_ps
->need_dfs_bypass
?
1777 pi
->graphics_level
[pi
->graphics_boot_level
].ClkBypassCntl
: 0;
1778 ret
= kv_copy_bytes_to_smc(rdev
,
1779 (pi
->dpm_table_start
+
1780 offsetof(SMU7_Fusion_DpmTable
, GraphicsLevel
) +
1781 (pi
->graphics_boot_level
* sizeof(SMU7_Fusion_GraphicsLevel
)) +
1782 offsetof(SMU7_Fusion_GraphicsLevel
, ClkBypassCntl
)),
1784 sizeof(u8
), pi
->sram_end
);
1790 static int kv_enable_nb_dpm(struct radeon_device
*rdev
,
1793 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1797 if (pi
->enable_nb_dpm
&& !pi
->nb_dpm_enabled
) {
1798 ret
= kv_notify_message_to_smu(rdev
, PPSMC_MSG_NBDPM_Enable
);
1800 pi
->nb_dpm_enabled
= true;
1803 if (pi
->enable_nb_dpm
&& pi
->nb_dpm_enabled
) {
1804 ret
= kv_notify_message_to_smu(rdev
, PPSMC_MSG_NBDPM_Disable
);
1806 pi
->nb_dpm_enabled
= false;
1813 int kv_dpm_force_performance_level(struct radeon_device
*rdev
,
1814 enum radeon_dpm_forced_level level
)
1818 if (level
== RADEON_DPM_FORCED_LEVEL_HIGH
) {
1819 ret
= kv_force_dpm_highest(rdev
);
1822 } else if (level
== RADEON_DPM_FORCED_LEVEL_LOW
) {
1823 ret
= kv_force_dpm_lowest(rdev
);
1826 } else if (level
== RADEON_DPM_FORCED_LEVEL_AUTO
) {
1827 ret
= kv_unforce_levels(rdev
);
1832 rdev
->pm
.dpm
.forced_level
= level
;
1837 int kv_dpm_pre_set_power_state(struct radeon_device
*rdev
)
1839 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1840 struct radeon_ps requested_ps
= *rdev
->pm
.dpm
.requested_ps
;
1841 struct radeon_ps
*new_ps
= &requested_ps
;
1843 kv_update_requested_ps(rdev
, new_ps
);
1845 kv_apply_state_adjust_rules(rdev
,
1852 int kv_dpm_set_power_state(struct radeon_device
*rdev
)
1854 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1855 struct radeon_ps
*new_ps
= &pi
->requested_rps
;
1856 struct radeon_ps
*old_ps
= &pi
->current_rps
;
1859 if (pi
->bapm_enable
) {
1860 ret
= kv_smc_bapm_enable(rdev
, rdev
->pm
.dpm
.ac_power
);
1862 DRM_ERROR("kv_smc_bapm_enable failed\n");
1867 if (rdev
->family
== CHIP_KABINI
|| rdev
->family
== CHIP_MULLINS
) {
1868 if (pi
->enable_dpm
) {
1869 kv_set_valid_clock_range(rdev
, new_ps
);
1870 kv_update_dfs_bypass_settings(rdev
, new_ps
);
1871 ret
= kv_calculate_ds_divider(rdev
);
1873 DRM_ERROR("kv_calculate_ds_divider failed\n");
1876 kv_calculate_nbps_level_settings(rdev
);
1877 kv_calculate_dpm_settings(rdev
);
1878 kv_force_lowest_valid(rdev
);
1879 kv_enable_new_levels(rdev
);
1880 kv_upload_dpm_settings(rdev
);
1881 kv_program_nbps_index_settings(rdev
, new_ps
);
1882 kv_unforce_levels(rdev
);
1883 kv_set_enabled_levels(rdev
);
1884 kv_force_lowest_valid(rdev
);
1885 kv_unforce_levels(rdev
);
1887 ret
= kv_update_vce_dpm(rdev
, new_ps
, old_ps
);
1889 DRM_ERROR("kv_update_vce_dpm failed\n");
1892 kv_update_sclk_t(rdev
);
1893 if (rdev
->family
== CHIP_MULLINS
)
1894 kv_enable_nb_dpm(rdev
, true);
1897 if (pi
->enable_dpm
) {
1898 kv_set_valid_clock_range(rdev
, new_ps
);
1899 kv_update_dfs_bypass_settings(rdev
, new_ps
);
1900 ret
= kv_calculate_ds_divider(rdev
);
1902 DRM_ERROR("kv_calculate_ds_divider failed\n");
1905 kv_calculate_nbps_level_settings(rdev
);
1906 kv_calculate_dpm_settings(rdev
);
1907 kv_freeze_sclk_dpm(rdev
, true);
1908 kv_upload_dpm_settings(rdev
);
1909 kv_program_nbps_index_settings(rdev
, new_ps
);
1910 kv_freeze_sclk_dpm(rdev
, false);
1911 kv_set_enabled_levels(rdev
);
1912 ret
= kv_update_vce_dpm(rdev
, new_ps
, old_ps
);
1914 DRM_ERROR("kv_update_vce_dpm failed\n");
1917 kv_update_acp_boot_level(rdev
);
1918 kv_update_sclk_t(rdev
);
1919 kv_enable_nb_dpm(rdev
, true);
1926 void kv_dpm_post_set_power_state(struct radeon_device
*rdev
)
1928 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1929 struct radeon_ps
*new_ps
= &pi
->requested_rps
;
1931 kv_update_current_ps(rdev
, new_ps
);
1934 void kv_dpm_setup_asic(struct radeon_device
*rdev
)
1936 sumo_take_smu_control(rdev
, true);
1937 kv_init_powergate_state(rdev
);
1938 kv_init_sclk_t(rdev
);
1942 void kv_dpm_reset_asic(struct radeon_device
*rdev
)
1944 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1946 if (rdev
->family
== CHIP_KABINI
|| rdev
->family
== CHIP_MULLINS
) {
1947 kv_force_lowest_valid(rdev
);
1948 kv_init_graphics_levels(rdev
);
1949 kv_program_bootup_state(rdev
);
1950 kv_upload_dpm_settings(rdev
);
1951 kv_force_lowest_valid(rdev
);
1952 kv_unforce_levels(rdev
);
1954 kv_init_graphics_levels(rdev
);
1955 kv_program_bootup_state(rdev
);
1956 kv_freeze_sclk_dpm(rdev
, true);
1957 kv_upload_dpm_settings(rdev
);
1958 kv_freeze_sclk_dpm(rdev
, false);
1959 kv_set_enabled_level(rdev
, pi
->graphics_boot_level
);
1964 //XXX use sumo_dpm_display_configuration_changed
1966 static void kv_construct_max_power_limits_table(struct radeon_device
*rdev
,
1967 struct radeon_clock_and_voltage_limits
*table
)
1969 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1971 if (pi
->sys_info
.sclk_voltage_mapping_table
.num_max_dpm_entries
> 0) {
1972 int idx
= pi
->sys_info
.sclk_voltage_mapping_table
.num_max_dpm_entries
- 1;
1974 pi
->sys_info
.sclk_voltage_mapping_table
.entries
[idx
].sclk_frequency
;
1976 kv_convert_2bit_index_to_voltage(rdev
,
1977 pi
->sys_info
.sclk_voltage_mapping_table
.entries
[idx
].vid_2bit
);
1980 table
->mclk
= pi
->sys_info
.nbp_memory_clock
[0];
1983 static void kv_patch_voltage_values(struct radeon_device
*rdev
)
1986 struct radeon_uvd_clock_voltage_dependency_table
*uvd_table
=
1987 &rdev
->pm
.dpm
.dyn_state
.uvd_clock_voltage_dependency_table
;
1988 struct radeon_vce_clock_voltage_dependency_table
*vce_table
=
1989 &rdev
->pm
.dpm
.dyn_state
.vce_clock_voltage_dependency_table
;
1990 struct radeon_clock_voltage_dependency_table
*samu_table
=
1991 &rdev
->pm
.dpm
.dyn_state
.samu_clock_voltage_dependency_table
;
1992 struct radeon_clock_voltage_dependency_table
*acp_table
=
1993 &rdev
->pm
.dpm
.dyn_state
.acp_clock_voltage_dependency_table
;
1995 if (uvd_table
->count
) {
1996 for (i
= 0; i
< uvd_table
->count
; i
++)
1997 uvd_table
->entries
[i
].v
=
1998 kv_convert_8bit_index_to_voltage(rdev
,
1999 uvd_table
->entries
[i
].v
);
2002 if (vce_table
->count
) {
2003 for (i
= 0; i
< vce_table
->count
; i
++)
2004 vce_table
->entries
[i
].v
=
2005 kv_convert_8bit_index_to_voltage(rdev
,
2006 vce_table
->entries
[i
].v
);
2009 if (samu_table
->count
) {
2010 for (i
= 0; i
< samu_table
->count
; i
++)
2011 samu_table
->entries
[i
].v
=
2012 kv_convert_8bit_index_to_voltage(rdev
,
2013 samu_table
->entries
[i
].v
);
2016 if (acp_table
->count
) {
2017 for (i
= 0; i
< acp_table
->count
; i
++)
2018 acp_table
->entries
[i
].v
=
2019 kv_convert_8bit_index_to_voltage(rdev
,
2020 acp_table
->entries
[i
].v
);
2025 static void kv_construct_boot_state(struct radeon_device
*rdev
)
2027 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2029 pi
->boot_pl
.sclk
= pi
->sys_info
.bootup_sclk
;
2030 pi
->boot_pl
.vddc_index
= pi
->sys_info
.bootup_nb_voltage_index
;
2031 pi
->boot_pl
.ds_divider_index
= 0;
2032 pi
->boot_pl
.ss_divider_index
= 0;
2033 pi
->boot_pl
.allow_gnb_slow
= 1;
2034 pi
->boot_pl
.force_nbp_state
= 0;
2035 pi
->boot_pl
.display_wm
= 0;
2036 pi
->boot_pl
.vce_wm
= 0;
2039 static int kv_force_dpm_highest(struct radeon_device
*rdev
)
2044 ret
= kv_dpm_get_enable_mask(rdev
, &enable_mask
);
2048 for (i
= SMU7_MAX_LEVELS_GRAPHICS
- 1; i
> 0; i
--) {
2049 if (enable_mask
& (1 << i
))
2053 if (rdev
->family
== CHIP_KABINI
|| rdev
->family
== CHIP_MULLINS
)
2054 return kv_send_msg_to_smc_with_parameter(rdev
, PPSMC_MSG_DPM_ForceState
, i
);
2056 return kv_set_enabled_level(rdev
, i
);
2059 static int kv_force_dpm_lowest(struct radeon_device
*rdev
)
2064 ret
= kv_dpm_get_enable_mask(rdev
, &enable_mask
);
2068 for (i
= 0; i
< SMU7_MAX_LEVELS_GRAPHICS
; i
++) {
2069 if (enable_mask
& (1 << i
))
2073 if (rdev
->family
== CHIP_KABINI
|| rdev
->family
== CHIP_MULLINS
)
2074 return kv_send_msg_to_smc_with_parameter(rdev
, PPSMC_MSG_DPM_ForceState
, i
);
2076 return kv_set_enabled_level(rdev
, i
);
2079 static u8
kv_get_sleep_divider_id_from_clock(struct radeon_device
*rdev
,
2080 u32 sclk
, u32 min_sclk_in_sr
)
2082 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2085 u32 min
= (min_sclk_in_sr
> KV_MINIMUM_ENGINE_CLOCK
) ?
2086 min_sclk_in_sr
: KV_MINIMUM_ENGINE_CLOCK
;
2091 if (!pi
->caps_sclk_ds
)
2094 for (i
= KV_MAX_DEEPSLEEP_DIVIDER_ID
; i
> 0; i
--) {
2095 temp
= sclk
/ sumo_get_sleep_divider_from_id(i
);
2103 static int kv_get_high_voltage_limit(struct radeon_device
*rdev
, int *limit
)
2105 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2106 struct radeon_clock_voltage_dependency_table
*table
=
2107 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
;
2110 if (table
&& table
->count
) {
2111 for (i
= table
->count
- 1; i
>= 0; i
--) {
2112 if (pi
->high_voltage_t
&&
2113 (kv_convert_8bit_index_to_voltage(rdev
, table
->entries
[i
].v
) <=
2114 pi
->high_voltage_t
)) {
2120 struct sumo_sclk_voltage_mapping_table
*table
=
2121 &pi
->sys_info
.sclk_voltage_mapping_table
;
2123 for (i
= table
->num_max_dpm_entries
- 1; i
>= 0; i
--) {
2124 if (pi
->high_voltage_t
&&
2125 (kv_convert_2bit_index_to_voltage(rdev
, table
->entries
[i
].vid_2bit
) <=
2126 pi
->high_voltage_t
)) {
2137 static void kv_apply_state_adjust_rules(struct radeon_device
*rdev
,
2138 struct radeon_ps
*new_rps
,
2139 struct radeon_ps
*old_rps
)
2141 struct kv_ps
*ps
= kv_get_ps(new_rps
);
2142 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2143 u32 min_sclk
= 10000; /* ??? */
2147 struct radeon_clock_voltage_dependency_table
*table
=
2148 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
;
2149 u32 stable_p_state_sclk
= 0;
2150 struct radeon_clock_and_voltage_limits
*max_limits
=
2151 &rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
;
2153 if (new_rps
->vce_active
) {
2154 new_rps
->evclk
= rdev
->pm
.dpm
.vce_states
[rdev
->pm
.dpm
.vce_level
].evclk
;
2155 new_rps
->ecclk
= rdev
->pm
.dpm
.vce_states
[rdev
->pm
.dpm
.vce_level
].ecclk
;
2161 mclk
= max_limits
->mclk
;
2164 if (pi
->caps_stable_p_state
) {
2165 stable_p_state_sclk
= (max_limits
->sclk
* 75) / 100;
2167 for (i
= table
->count
- 1; i
>= 0; i
--) {
2168 if (stable_p_state_sclk
>= table
->entries
[i
].clk
) {
2169 stable_p_state_sclk
= table
->entries
[i
].clk
;
2175 stable_p_state_sclk
= table
->entries
[0].clk
;
2177 sclk
= stable_p_state_sclk
;
2180 if (new_rps
->vce_active
) {
2181 if (sclk
< rdev
->pm
.dpm
.vce_states
[rdev
->pm
.dpm
.vce_level
].sclk
)
2182 sclk
= rdev
->pm
.dpm
.vce_states
[rdev
->pm
.dpm
.vce_level
].sclk
;
2185 ps
->need_dfs_bypass
= true;
2187 for (i
= 0; i
< ps
->num_levels
; i
++) {
2188 if (ps
->levels
[i
].sclk
< sclk
)
2189 ps
->levels
[i
].sclk
= sclk
;
2192 if (table
&& table
->count
) {
2193 for (i
= 0; i
< ps
->num_levels
; i
++) {
2194 if (pi
->high_voltage_t
&&
2195 (pi
->high_voltage_t
<
2196 kv_convert_8bit_index_to_voltage(rdev
, ps
->levels
[i
].vddc_index
))) {
2197 kv_get_high_voltage_limit(rdev
, &limit
);
2198 ps
->levels
[i
].sclk
= table
->entries
[limit
].clk
;
2202 struct sumo_sclk_voltage_mapping_table
*table
=
2203 &pi
->sys_info
.sclk_voltage_mapping_table
;
2205 for (i
= 0; i
< ps
->num_levels
; i
++) {
2206 if (pi
->high_voltage_t
&&
2207 (pi
->high_voltage_t
<
2208 kv_convert_8bit_index_to_voltage(rdev
, ps
->levels
[i
].vddc_index
))) {
2209 kv_get_high_voltage_limit(rdev
, &limit
);
2210 ps
->levels
[i
].sclk
= table
->entries
[limit
].sclk_frequency
;
2215 if (pi
->caps_stable_p_state
) {
2216 for (i
= 0; i
< ps
->num_levels
; i
++) {
2217 ps
->levels
[i
].sclk
= stable_p_state_sclk
;
2221 pi
->video_start
= new_rps
->dclk
|| new_rps
->vclk
||
2222 new_rps
->evclk
|| new_rps
->ecclk
;
2224 if ((new_rps
->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK
) ==
2225 ATOM_PPLIB_CLASSIFICATION_UI_BATTERY
)
2226 pi
->battery_state
= true;
2228 pi
->battery_state
= false;
2230 if (rdev
->family
== CHIP_KABINI
|| rdev
->family
== CHIP_MULLINS
) {
2231 ps
->dpm0_pg_nb_ps_lo
= 0x1;
2232 ps
->dpm0_pg_nb_ps_hi
= 0x0;
2233 ps
->dpmx_nb_ps_lo
= 0x1;
2234 ps
->dpmx_nb_ps_hi
= 0x0;
2236 ps
->dpm0_pg_nb_ps_lo
= 0x3;
2237 ps
->dpm0_pg_nb_ps_hi
= 0x0;
2238 ps
->dpmx_nb_ps_lo
= 0x3;
2239 ps
->dpmx_nb_ps_hi
= 0x0;
2241 if (pi
->sys_info
.nb_dpm_enable
) {
2242 force_high
= (mclk
>= pi
->sys_info
.nbp_memory_clock
[3]) ||
2243 pi
->video_start
|| (rdev
->pm
.dpm
.new_active_crtc_count
>= 3) ||
2244 pi
->disable_nb_ps3_in_battery
;
2245 ps
->dpm0_pg_nb_ps_lo
= force_high
? 0x2 : 0x3;
2246 ps
->dpm0_pg_nb_ps_hi
= 0x2;
2247 ps
->dpmx_nb_ps_lo
= force_high
? 0x2 : 0x3;
2248 ps
->dpmx_nb_ps_hi
= 0x2;
2253 static void kv_dpm_power_level_enabled_for_throttle(struct radeon_device
*rdev
,
2254 u32 index
, bool enable
)
2256 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2258 pi
->graphics_level
[index
].EnabledForThrottle
= enable
? 1 : 0;
2261 static int kv_calculate_ds_divider(struct radeon_device
*rdev
)
2263 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2264 u32 sclk_in_sr
= 10000; /* ??? */
2267 if (pi
->lowest_valid
> pi
->highest_valid
)
2270 for (i
= pi
->lowest_valid
; i
<= pi
->highest_valid
; i
++) {
2271 pi
->graphics_level
[i
].DeepSleepDivId
=
2272 kv_get_sleep_divider_id_from_clock(rdev
,
2273 be32_to_cpu(pi
->graphics_level
[i
].SclkFrequency
),
2279 static int kv_calculate_nbps_level_settings(struct radeon_device
*rdev
)
2281 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2284 struct radeon_clock_and_voltage_limits
*max_limits
=
2285 &rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
;
2286 u32 mclk
= max_limits
->mclk
;
2288 if (pi
->lowest_valid
> pi
->highest_valid
)
2291 if (rdev
->family
== CHIP_KABINI
|| rdev
->family
== CHIP_MULLINS
) {
2292 for (i
= pi
->lowest_valid
; i
<= pi
->highest_valid
; i
++) {
2293 pi
->graphics_level
[i
].GnbSlow
= 1;
2294 pi
->graphics_level
[i
].ForceNbPs1
= 0;
2295 pi
->graphics_level
[i
].UpH
= 0;
2298 if (!pi
->sys_info
.nb_dpm_enable
)
2301 force_high
= ((mclk
>= pi
->sys_info
.nbp_memory_clock
[3]) ||
2302 (rdev
->pm
.dpm
.new_active_crtc_count
>= 3) || pi
->video_start
);
2305 for (i
= pi
->lowest_valid
; i
<= pi
->highest_valid
; i
++)
2306 pi
->graphics_level
[i
].GnbSlow
= 0;
2308 if (pi
->battery_state
)
2309 pi
->graphics_level
[0].ForceNbPs1
= 1;
2311 pi
->graphics_level
[1].GnbSlow
= 0;
2312 pi
->graphics_level
[2].GnbSlow
= 0;
2313 pi
->graphics_level
[3].GnbSlow
= 0;
2314 pi
->graphics_level
[4].GnbSlow
= 0;
2317 for (i
= pi
->lowest_valid
; i
<= pi
->highest_valid
; i
++) {
2318 pi
->graphics_level
[i
].GnbSlow
= 1;
2319 pi
->graphics_level
[i
].ForceNbPs1
= 0;
2320 pi
->graphics_level
[i
].UpH
= 0;
2323 if (pi
->sys_info
.nb_dpm_enable
&& pi
->battery_state
) {
2324 pi
->graphics_level
[pi
->lowest_valid
].UpH
= 0x28;
2325 pi
->graphics_level
[pi
->lowest_valid
].GnbSlow
= 0;
2326 if (pi
->lowest_valid
!= pi
->highest_valid
)
2327 pi
->graphics_level
[pi
->lowest_valid
].ForceNbPs1
= 1;
2333 static int kv_calculate_dpm_settings(struct radeon_device
*rdev
)
2335 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2338 if (pi
->lowest_valid
> pi
->highest_valid
)
2341 for (i
= pi
->lowest_valid
; i
<= pi
->highest_valid
; i
++)
2342 pi
->graphics_level
[i
].DisplayWatermark
= (i
== pi
->highest_valid
) ? 1 : 0;
2347 static void kv_init_graphics_levels(struct radeon_device
*rdev
)
2349 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2351 struct radeon_clock_voltage_dependency_table
*table
=
2352 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
;
2354 if (table
&& table
->count
) {
2357 pi
->graphics_dpm_level_count
= 0;
2358 for (i
= 0; i
< table
->count
; i
++) {
2359 if (pi
->high_voltage_t
&&
2360 (pi
->high_voltage_t
<
2361 kv_convert_8bit_index_to_voltage(rdev
, table
->entries
[i
].v
)))
2364 kv_set_divider_value(rdev
, i
, table
->entries
[i
].clk
);
2365 vid_2bit
= kv_convert_vid7_to_vid2(rdev
,
2366 &pi
->sys_info
.vid_mapping_table
,
2367 table
->entries
[i
].v
);
2368 kv_set_vid(rdev
, i
, vid_2bit
);
2369 kv_set_at(rdev
, i
, pi
->at
[i
]);
2370 kv_dpm_power_level_enabled_for_throttle(rdev
, i
, true);
2371 pi
->graphics_dpm_level_count
++;
2374 struct sumo_sclk_voltage_mapping_table
*table
=
2375 &pi
->sys_info
.sclk_voltage_mapping_table
;
2377 pi
->graphics_dpm_level_count
= 0;
2378 for (i
= 0; i
< table
->num_max_dpm_entries
; i
++) {
2379 if (pi
->high_voltage_t
&&
2380 pi
->high_voltage_t
<
2381 kv_convert_2bit_index_to_voltage(rdev
, table
->entries
[i
].vid_2bit
))
2384 kv_set_divider_value(rdev
, i
, table
->entries
[i
].sclk_frequency
);
2385 kv_set_vid(rdev
, i
, table
->entries
[i
].vid_2bit
);
2386 kv_set_at(rdev
, i
, pi
->at
[i
]);
2387 kv_dpm_power_level_enabled_for_throttle(rdev
, i
, true);
2388 pi
->graphics_dpm_level_count
++;
2392 for (i
= 0; i
< SMU7_MAX_LEVELS_GRAPHICS
; i
++)
2393 kv_dpm_power_level_enable(rdev
, i
, false);
2396 static void kv_enable_new_levels(struct radeon_device
*rdev
)
2398 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2401 for (i
= 0; i
< SMU7_MAX_LEVELS_GRAPHICS
; i
++) {
2402 if (i
>= pi
->lowest_valid
&& i
<= pi
->highest_valid
)
2403 kv_dpm_power_level_enable(rdev
, i
, true);
2407 static int kv_set_enabled_level(struct radeon_device
*rdev
, u32 level
)
2409 u32 new_mask
= (1 << level
);
2411 return kv_send_msg_to_smc_with_parameter(rdev
,
2412 PPSMC_MSG_SCLKDPM_SetEnabledMask
,
2416 static int kv_set_enabled_levels(struct radeon_device
*rdev
)
2418 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2419 u32 i
, new_mask
= 0;
2421 for (i
= pi
->lowest_valid
; i
<= pi
->highest_valid
; i
++)
2422 new_mask
|= (1 << i
);
2424 return kv_send_msg_to_smc_with_parameter(rdev
,
2425 PPSMC_MSG_SCLKDPM_SetEnabledMask
,
2429 static void kv_program_nbps_index_settings(struct radeon_device
*rdev
,
2430 struct radeon_ps
*new_rps
)
2432 struct kv_ps
*new_ps
= kv_get_ps(new_rps
);
2433 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2436 if (rdev
->family
== CHIP_KABINI
|| rdev
->family
== CHIP_MULLINS
)
2439 if (pi
->sys_info
.nb_dpm_enable
) {
2440 nbdpmconfig1
= RREG32_SMC(NB_DPM_CONFIG_1
);
2441 nbdpmconfig1
&= ~(Dpm0PgNbPsLo_MASK
| Dpm0PgNbPsHi_MASK
|
2442 DpmXNbPsLo_MASK
| DpmXNbPsHi_MASK
);
2443 nbdpmconfig1
|= (Dpm0PgNbPsLo(new_ps
->dpm0_pg_nb_ps_lo
) |
2444 Dpm0PgNbPsHi(new_ps
->dpm0_pg_nb_ps_hi
) |
2445 DpmXNbPsLo(new_ps
->dpmx_nb_ps_lo
) |
2446 DpmXNbPsHi(new_ps
->dpmx_nb_ps_hi
));
2447 WREG32_SMC(NB_DPM_CONFIG_1
, nbdpmconfig1
);
2451 static int kv_set_thermal_temperature_range(struct radeon_device
*rdev
,
2452 int min_temp
, int max_temp
)
2454 int low_temp
= 0 * 1000;
2455 int high_temp
= 255 * 1000;
2458 if (low_temp
< min_temp
)
2459 low_temp
= min_temp
;
2460 if (high_temp
> max_temp
)
2461 high_temp
= max_temp
;
2462 if (high_temp
< low_temp
) {
2463 DRM_ERROR("invalid thermal range: %d - %d\n", low_temp
, high_temp
);
2467 tmp
= RREG32_SMC(CG_THERMAL_INT_CTRL
);
2468 tmp
&= ~(DIG_THERM_INTH_MASK
| DIG_THERM_INTL_MASK
);
2469 tmp
|= (DIG_THERM_INTH(49 + (high_temp
/ 1000)) |
2470 DIG_THERM_INTL(49 + (low_temp
/ 1000)));
2471 WREG32_SMC(CG_THERMAL_INT_CTRL
, tmp
);
2473 rdev
->pm
.dpm
.thermal
.min_temp
= low_temp
;
2474 rdev
->pm
.dpm
.thermal
.max_temp
= high_temp
;
2480 struct _ATOM_INTEGRATED_SYSTEM_INFO info
;
2481 struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2
;
2482 struct _ATOM_INTEGRATED_SYSTEM_INFO_V5 info_5
;
2483 struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 info_6
;
2484 struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_7 info_7
;
2485 struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_8 info_8
;
2488 static int kv_parse_sys_info_table(struct radeon_device
*rdev
)
2490 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2491 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
2492 int index
= GetIndexIntoMasterTable(DATA
, IntegratedSystemInfo
);
2493 union igp_info
*igp_info
;
2498 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
2499 &frev
, &crev
, &data_offset
)) {
2500 igp_info
= (union igp_info
*)(mode_info
->atom_context
->bios
+
2504 DRM_ERROR("Unsupported IGP table: %d %d\n", frev
, crev
);
2507 pi
->sys_info
.bootup_sclk
= le32_to_cpu(igp_info
->info_8
.ulBootUpEngineClock
);
2508 pi
->sys_info
.bootup_uma_clk
= le32_to_cpu(igp_info
->info_8
.ulBootUpUMAClock
);
2509 pi
->sys_info
.bootup_nb_voltage_index
=
2510 le16_to_cpu(igp_info
->info_8
.usBootUpNBVoltage
);
2511 if (igp_info
->info_8
.ucHtcTmpLmt
== 0)
2512 pi
->sys_info
.htc_tmp_lmt
= 203;
2514 pi
->sys_info
.htc_tmp_lmt
= igp_info
->info_8
.ucHtcTmpLmt
;
2515 if (igp_info
->info_8
.ucHtcHystLmt
== 0)
2516 pi
->sys_info
.htc_hyst_lmt
= 5;
2518 pi
->sys_info
.htc_hyst_lmt
= igp_info
->info_8
.ucHtcHystLmt
;
2519 if (pi
->sys_info
.htc_tmp_lmt
<= pi
->sys_info
.htc_hyst_lmt
) {
2520 DRM_ERROR("The htcTmpLmt should be larger than htcHystLmt.\n");
2523 if (le32_to_cpu(igp_info
->info_8
.ulSystemConfig
) & (1 << 3))
2524 pi
->sys_info
.nb_dpm_enable
= true;
2526 pi
->sys_info
.nb_dpm_enable
= false;
2528 for (i
= 0; i
< KV_NUM_NBPSTATES
; i
++) {
2529 pi
->sys_info
.nbp_memory_clock
[i
] =
2530 le32_to_cpu(igp_info
->info_8
.ulNbpStateMemclkFreq
[i
]);
2531 pi
->sys_info
.nbp_n_clock
[i
] =
2532 le32_to_cpu(igp_info
->info_8
.ulNbpStateNClkFreq
[i
]);
2534 if (le32_to_cpu(igp_info
->info_8
.ulGPUCapInfo
) &
2535 SYS_INFO_GPUCAPS__ENABEL_DFS_BYPASS
)
2536 pi
->caps_enable_dfs_bypass
= true;
2538 sumo_construct_sclk_voltage_mapping_table(rdev
,
2539 &pi
->sys_info
.sclk_voltage_mapping_table
,
2540 igp_info
->info_8
.sAvail_SCLK
);
2542 sumo_construct_vid_mapping_table(rdev
,
2543 &pi
->sys_info
.vid_mapping_table
,
2544 igp_info
->info_8
.sAvail_SCLK
);
2546 kv_construct_max_power_limits_table(rdev
,
2547 &rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
);
2553 struct _ATOM_POWERPLAY_INFO info
;
2554 struct _ATOM_POWERPLAY_INFO_V2 info_2
;
2555 struct _ATOM_POWERPLAY_INFO_V3 info_3
;
2556 struct _ATOM_PPLIB_POWERPLAYTABLE pplib
;
2557 struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2
;
2558 struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3
;
2561 union pplib_clock_info
{
2562 struct _ATOM_PPLIB_R600_CLOCK_INFO r600
;
2563 struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780
;
2564 struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen
;
2565 struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo
;
2568 union pplib_power_state
{
2569 struct _ATOM_PPLIB_STATE v1
;
2570 struct _ATOM_PPLIB_STATE_V2 v2
;
2573 static void kv_patch_boot_state(struct radeon_device
*rdev
,
2576 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2579 ps
->levels
[0] = pi
->boot_pl
;
2582 static void kv_parse_pplib_non_clock_info(struct radeon_device
*rdev
,
2583 struct radeon_ps
*rps
,
2584 struct _ATOM_PPLIB_NONCLOCK_INFO
*non_clock_info
,
2587 struct kv_ps
*ps
= kv_get_ps(rps
);
2589 rps
->caps
= le32_to_cpu(non_clock_info
->ulCapsAndSettings
);
2590 rps
->class = le16_to_cpu(non_clock_info
->usClassification
);
2591 rps
->class2
= le16_to_cpu(non_clock_info
->usClassification2
);
2593 if (ATOM_PPLIB_NONCLOCKINFO_VER1
< table_rev
) {
2594 rps
->vclk
= le32_to_cpu(non_clock_info
->ulVCLK
);
2595 rps
->dclk
= le32_to_cpu(non_clock_info
->ulDCLK
);
2601 if (rps
->class & ATOM_PPLIB_CLASSIFICATION_BOOT
) {
2602 rdev
->pm
.dpm
.boot_ps
= rps
;
2603 kv_patch_boot_state(rdev
, ps
);
2605 if (rps
->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE
)
2606 rdev
->pm
.dpm
.uvd_ps
= rps
;
2609 static void kv_parse_pplib_clock_info(struct radeon_device
*rdev
,
2610 struct radeon_ps
*rps
, int index
,
2611 union pplib_clock_info
*clock_info
)
2613 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2614 struct kv_ps
*ps
= kv_get_ps(rps
);
2615 struct kv_pl
*pl
= &ps
->levels
[index
];
2618 sclk
= le16_to_cpu(clock_info
->sumo
.usEngineClockLow
);
2619 sclk
|= clock_info
->sumo
.ucEngineClockHigh
<< 16;
2621 pl
->vddc_index
= clock_info
->sumo
.vddcIndex
;
2623 ps
->num_levels
= index
+ 1;
2625 if (pi
->caps_sclk_ds
) {
2626 pl
->ds_divider_index
= 5;
2627 pl
->ss_divider_index
= 5;
2631 static int kv_parse_power_table(struct radeon_device
*rdev
)
2633 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
2634 struct _ATOM_PPLIB_NONCLOCK_INFO
*non_clock_info
;
2635 union pplib_power_state
*power_state
;
2636 int i
, j
, k
, non_clock_array_index
, clock_array_index
;
2637 union pplib_clock_info
*clock_info
;
2638 struct _StateArray
*state_array
;
2639 struct _ClockInfoArray
*clock_info_array
;
2640 struct _NonClockInfoArray
*non_clock_info_array
;
2641 union power_info
*power_info
;
2642 int index
= GetIndexIntoMasterTable(DATA
, PowerPlayInfo
);
2645 u8
*power_state_offset
;
2648 if (!atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
2649 &frev
, &crev
, &data_offset
))
2651 power_info
= (union power_info
*)(mode_info
->atom_context
->bios
+ data_offset
);
2653 state_array
= (struct _StateArray
*)
2654 (mode_info
->atom_context
->bios
+ data_offset
+
2655 le16_to_cpu(power_info
->pplib
.usStateArrayOffset
));
2656 clock_info_array
= (struct _ClockInfoArray
*)
2657 (mode_info
->atom_context
->bios
+ data_offset
+
2658 le16_to_cpu(power_info
->pplib
.usClockInfoArrayOffset
));
2659 non_clock_info_array
= (struct _NonClockInfoArray
*)
2660 (mode_info
->atom_context
->bios
+ data_offset
+
2661 le16_to_cpu(power_info
->pplib
.usNonClockInfoArrayOffset
));
2663 rdev
->pm
.dpm
.ps
= kzalloc(sizeof(struct radeon_ps
) *
2664 state_array
->ucNumEntries
, GFP_KERNEL
);
2665 if (!rdev
->pm
.dpm
.ps
)
2667 power_state_offset
= (u8
*)state_array
->states
;
2668 for (i
= 0; i
< state_array
->ucNumEntries
; i
++) {
2670 power_state
= (union pplib_power_state
*)power_state_offset
;
2671 non_clock_array_index
= power_state
->v2
.nonClockInfoIndex
;
2672 non_clock_info
= (struct _ATOM_PPLIB_NONCLOCK_INFO
*)
2673 &non_clock_info_array
->nonClockInfo
[non_clock_array_index
];
2674 if (!rdev
->pm
.power_state
[i
].clock_info
)
2676 ps
= kzalloc(sizeof(struct kv_ps
), GFP_KERNEL
);
2678 kfree(rdev
->pm
.dpm
.ps
);
2681 rdev
->pm
.dpm
.ps
[i
].ps_priv
= ps
;
2683 idx
= (u8
*)&power_state
->v2
.clockInfoIndex
[0];
2684 for (j
= 0; j
< power_state
->v2
.ucNumDPMLevels
; j
++) {
2685 clock_array_index
= idx
[j
];
2686 if (clock_array_index
>= clock_info_array
->ucNumEntries
)
2688 if (k
>= SUMO_MAX_HARDWARE_POWERLEVELS
)
2690 clock_info
= (union pplib_clock_info
*)
2691 ((u8
*)&clock_info_array
->clockInfo
[0] +
2692 (clock_array_index
* clock_info_array
->ucEntrySize
));
2693 kv_parse_pplib_clock_info(rdev
,
2694 &rdev
->pm
.dpm
.ps
[i
], k
,
2698 kv_parse_pplib_non_clock_info(rdev
, &rdev
->pm
.dpm
.ps
[i
],
2700 non_clock_info_array
->ucEntrySize
);
2701 power_state_offset
+= 2 + power_state
->v2
.ucNumDPMLevels
;
2703 rdev
->pm
.dpm
.num_ps
= state_array
->ucNumEntries
;
2705 /* fill in the vce power states */
2706 for (i
= 0; i
< RADEON_MAX_VCE_LEVELS
; i
++) {
2708 clock_array_index
= rdev
->pm
.dpm
.vce_states
[i
].clk_idx
;
2709 clock_info
= (union pplib_clock_info
*)
2710 &clock_info_array
->clockInfo
[clock_array_index
* clock_info_array
->ucEntrySize
];
2711 sclk
= le16_to_cpu(clock_info
->sumo
.usEngineClockLow
);
2712 sclk
|= clock_info
->sumo
.ucEngineClockHigh
<< 16;
2713 rdev
->pm
.dpm
.vce_states
[i
].sclk
= sclk
;
2714 rdev
->pm
.dpm
.vce_states
[i
].mclk
= 0;
2720 int kv_dpm_init(struct radeon_device
*rdev
)
2722 struct kv_power_info
*pi
;
2725 pi
= kzalloc(sizeof(struct kv_power_info
), GFP_KERNEL
);
2728 rdev
->pm
.dpm
.priv
= pi
;
2730 ret
= r600_get_platform_caps(rdev
);
2734 ret
= r600_parse_extended_power_table(rdev
);
2738 for (i
= 0; i
< SUMO_MAX_HARDWARE_POWERLEVELS
; i
++)
2739 pi
->at
[i
] = TRINITY_AT_DFLT
;
2741 pi
->sram_end
= SMC_RAM_END
;
2743 /* Enabling nb dpm on an asrock system prevents dpm from working */
2744 if (rdev
->pdev
->subsystem_vendor
== 0x1849)
2745 pi
->enable_nb_dpm
= false;
2747 pi
->enable_nb_dpm
= true;
2749 pi
->caps_power_containment
= true;
2750 pi
->caps_cac
= true;
2751 pi
->enable_didt
= false;
2752 if (pi
->enable_didt
) {
2753 pi
->caps_sq_ramping
= true;
2754 pi
->caps_db_ramping
= true;
2755 pi
->caps_td_ramping
= true;
2756 pi
->caps_tcp_ramping
= true;
2759 pi
->caps_sclk_ds
= true;
2760 pi
->enable_auto_thermal_throttling
= true;
2761 pi
->disable_nb_ps3_in_battery
= false;
2762 if (radeon_bapm
== -1) {
2763 /* only enable bapm on KB, ML by default */
2764 if (rdev
->family
== CHIP_KABINI
|| rdev
->family
== CHIP_MULLINS
)
2765 pi
->bapm_enable
= true;
2767 pi
->bapm_enable
= false;
2768 } else if (radeon_bapm
== 0) {
2769 pi
->bapm_enable
= false;
2771 pi
->bapm_enable
= true;
2773 pi
->voltage_drop_t
= 0;
2774 pi
->caps_sclk_throttle_low_notification
= false;
2775 pi
->caps_fps
= false; /* true? */
2776 pi
->caps_uvd_pg
= true;
2777 pi
->caps_uvd_dpm
= true;
2778 pi
->caps_vce_pg
= false; /* XXX true */
2779 pi
->caps_samu_pg
= false;
2780 pi
->caps_acp_pg
= false;
2781 pi
->caps_stable_p_state
= false;
2783 ret
= kv_parse_sys_info_table(rdev
);
2787 kv_patch_voltage_values(rdev
);
2788 kv_construct_boot_state(rdev
);
2790 ret
= kv_parse_power_table(rdev
);
2794 pi
->enable_dpm
= true;
2799 void kv_dpm_debugfs_print_current_performance_level(struct radeon_device
*rdev
,
2802 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2804 (RREG32_SMC(TARGET_AND_CURRENT_PROFILE_INDEX
) & CURR_SCLK_INDEX_MASK
) >>
2805 CURR_SCLK_INDEX_SHIFT
;
2809 if (current_index
>= SMU__NUM_SCLK_DPM_STATE
) {
2810 seq_printf(m
, "invalid dpm profile %d\n", current_index
);
2812 sclk
= be32_to_cpu(pi
->graphics_level
[current_index
].SclkFrequency
);
2813 tmp
= (RREG32_SMC(SMU_VOLTAGE_STATUS
) & SMU_VOLTAGE_CURRENT_LEVEL_MASK
) >>
2814 SMU_VOLTAGE_CURRENT_LEVEL_SHIFT
;
2815 vddc
= kv_convert_8bit_index_to_voltage(rdev
, (u16
)tmp
);
2816 seq_printf(m
, "uvd %sabled\n", pi
->uvd_power_gated
? "dis" : "en");
2817 seq_printf(m
, "vce %sabled\n", pi
->vce_power_gated
? "dis" : "en");
2818 seq_printf(m
, "power level %d sclk: %u vddc: %u\n",
2819 current_index
, sclk
, vddc
);
2823 u32
kv_dpm_get_current_sclk(struct radeon_device
*rdev
)
2825 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2827 (RREG32_SMC(TARGET_AND_CURRENT_PROFILE_INDEX
) & CURR_SCLK_INDEX_MASK
) >>
2828 CURR_SCLK_INDEX_SHIFT
;
2831 if (current_index
>= SMU__NUM_SCLK_DPM_STATE
) {
2834 sclk
= be32_to_cpu(pi
->graphics_level
[current_index
].SclkFrequency
);
2839 u32
kv_dpm_get_current_mclk(struct radeon_device
*rdev
)
2841 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2843 return pi
->sys_info
.bootup_uma_clk
;
2846 void kv_dpm_print_power_state(struct radeon_device
*rdev
,
2847 struct radeon_ps
*rps
)
2850 struct kv_ps
*ps
= kv_get_ps(rps
);
2852 r600_dpm_print_class_info(rps
->class, rps
->class2
);
2853 r600_dpm_print_cap_info(rps
->caps
);
2854 printk("\tuvd vclk: %d dclk: %d\n", rps
->vclk
, rps
->dclk
);
2855 for (i
= 0; i
< ps
->num_levels
; i
++) {
2856 struct kv_pl
*pl
= &ps
->levels
[i
];
2857 printk("\t\tpower level %d sclk: %u vddc: %u\n",
2859 kv_convert_8bit_index_to_voltage(rdev
, pl
->vddc_index
));
2861 r600_dpm_print_ps_status(rdev
, rps
);
2864 void kv_dpm_fini(struct radeon_device
*rdev
)
2868 for (i
= 0; i
< rdev
->pm
.dpm
.num_ps
; i
++) {
2869 kfree(rdev
->pm
.dpm
.ps
[i
].ps_priv
);
2871 kfree(rdev
->pm
.dpm
.ps
);
2872 kfree(rdev
->pm
.dpm
.priv
);
2873 r600_free_extended_power_table(rdev
);
2876 void kv_dpm_display_configuration_changed(struct radeon_device
*rdev
)
2881 u32
kv_dpm_get_sclk(struct radeon_device
*rdev
, bool low
)
2883 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2884 struct kv_ps
*requested_state
= kv_get_ps(&pi
->requested_rps
);
2887 return requested_state
->levels
[0].sclk
;
2889 return requested_state
->levels
[requested_state
->num_levels
- 1].sclk
;
2892 u32
kv_dpm_get_mclk(struct radeon_device
*rdev
, bool low
)
2894 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2896 return pi
->sys_info
.bootup_uma_clk
;