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 void kv_init_graphics_levels(struct radeon_device
*rdev
);
37 static int kv_calculate_ds_divider(struct radeon_device
*rdev
);
38 static int kv_calculate_nbps_level_settings(struct radeon_device
*rdev
);
39 static int kv_calculate_dpm_settings(struct radeon_device
*rdev
);
40 static void kv_enable_new_levels(struct radeon_device
*rdev
);
41 static void kv_program_nbps_index_settings(struct radeon_device
*rdev
,
42 struct radeon_ps
*new_rps
);
43 static int kv_set_enabled_level(struct radeon_device
*rdev
, u32 level
);
44 static int kv_set_enabled_levels(struct radeon_device
*rdev
);
45 static int kv_force_dpm_highest(struct radeon_device
*rdev
);
46 static int kv_force_dpm_lowest(struct radeon_device
*rdev
);
47 static void kv_apply_state_adjust_rules(struct radeon_device
*rdev
,
48 struct radeon_ps
*new_rps
,
49 struct radeon_ps
*old_rps
);
50 static int kv_set_thermal_temperature_range(struct radeon_device
*rdev
,
51 int min_temp
, int max_temp
);
52 static int kv_init_fps_limits(struct radeon_device
*rdev
);
54 void kv_dpm_powergate_uvd(struct radeon_device
*rdev
, bool gate
);
55 static void kv_dpm_powergate_vce(struct radeon_device
*rdev
, bool gate
);
56 static void kv_dpm_powergate_samu(struct radeon_device
*rdev
, bool gate
);
57 static void kv_dpm_powergate_acp(struct radeon_device
*rdev
, bool gate
);
59 extern void cik_enter_rlc_safe_mode(struct radeon_device
*rdev
);
60 extern void cik_exit_rlc_safe_mode(struct radeon_device
*rdev
);
61 extern void cik_update_cg(struct radeon_device
*rdev
,
62 u32 block
, bool enable
);
64 static const struct kv_lcac_config_values sx_local_cac_cfg_kv
[] =
77 static const struct kv_lcac_config_values mc0_local_cac_cfg_kv
[] =
83 static const struct kv_lcac_config_values mc1_local_cac_cfg_kv
[] =
89 static const struct kv_lcac_config_values mc2_local_cac_cfg_kv
[] =
95 static const struct kv_lcac_config_values mc3_local_cac_cfg_kv
[] =
101 static const struct kv_lcac_config_values cpl_local_cac_cfg_kv
[] =
133 static const struct kv_lcac_config_reg sx0_cac_config_reg
[] =
135 { 0xc0400d00, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
138 static const struct kv_lcac_config_reg mc0_cac_config_reg
[] =
140 { 0xc0400d30, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
143 static const struct kv_lcac_config_reg mc1_cac_config_reg
[] =
145 { 0xc0400d3c, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
148 static const struct kv_lcac_config_reg mc2_cac_config_reg
[] =
150 { 0xc0400d48, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
153 static const struct kv_lcac_config_reg mc3_cac_config_reg
[] =
155 { 0xc0400d54, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
158 static const struct kv_lcac_config_reg cpl_cac_config_reg
[] =
160 { 0xc0400d80, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
163 static const struct kv_pt_config_reg didt_config_kv
[] =
165 { 0x10, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
166 { 0x10, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
167 { 0x10, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
168 { 0x10, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
169 { 0x11, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
170 { 0x11, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
171 { 0x11, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
172 { 0x11, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
173 { 0x12, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
174 { 0x12, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
175 { 0x12, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
176 { 0x12, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
177 { 0x2, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND
},
178 { 0x2, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND
},
179 { 0x2, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND
},
180 { 0x1, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND
},
181 { 0x1, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND
},
182 { 0x0, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
183 { 0x30, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
184 { 0x30, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
185 { 0x30, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
186 { 0x30, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
187 { 0x31, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
188 { 0x31, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
189 { 0x31, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
190 { 0x31, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
191 { 0x32, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
192 { 0x32, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
193 { 0x32, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
194 { 0x32, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
195 { 0x22, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND
},
196 { 0x22, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND
},
197 { 0x22, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND
},
198 { 0x21, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND
},
199 { 0x21, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND
},
200 { 0x20, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
201 { 0x50, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
202 { 0x50, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
203 { 0x50, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
204 { 0x50, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
205 { 0x51, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
206 { 0x51, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
207 { 0x51, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
208 { 0x51, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
209 { 0x52, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
210 { 0x52, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
211 { 0x52, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
212 { 0x52, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
213 { 0x42, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND
},
214 { 0x42, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND
},
215 { 0x42, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND
},
216 { 0x41, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND
},
217 { 0x41, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND
},
218 { 0x40, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
219 { 0x70, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
220 { 0x70, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
221 { 0x70, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
222 { 0x70, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
223 { 0x71, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
224 { 0x71, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
225 { 0x71, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
226 { 0x71, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
227 { 0x72, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
228 { 0x72, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND
},
229 { 0x72, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND
},
230 { 0x72, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND
},
231 { 0x62, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND
},
232 { 0x62, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND
},
233 { 0x62, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND
},
234 { 0x61, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND
},
235 { 0x61, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND
},
236 { 0x60, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND
},
240 static struct kv_ps
*kv_get_ps(struct radeon_ps
*rps
)
242 struct kv_ps
*ps
= rps
->ps_priv
;
247 static struct kv_power_info
*kv_get_pi(struct radeon_device
*rdev
)
249 struct kv_power_info
*pi
= rdev
->pm
.dpm
.priv
;
255 static void kv_program_local_cac_table(struct radeon_device
*rdev
,
256 const struct kv_lcac_config_values
*local_cac_table
,
257 const struct kv_lcac_config_reg
*local_cac_reg
)
260 const struct kv_lcac_config_values
*values
= local_cac_table
;
262 while (values
->block_id
!= 0xffffffff) {
263 count
= values
->signal_id
;
264 for (i
= 0; i
< count
; i
++) {
265 data
= ((values
->block_id
<< local_cac_reg
->block_shift
) &
266 local_cac_reg
->block_mask
);
267 data
|= ((i
<< local_cac_reg
->signal_shift
) &
268 local_cac_reg
->signal_mask
);
269 data
|= ((values
->t
<< local_cac_reg
->t_shift
) &
270 local_cac_reg
->t_mask
);
271 data
|= ((1 << local_cac_reg
->enable_shift
) &
272 local_cac_reg
->enable_mask
);
273 WREG32_SMC(local_cac_reg
->cntl
, data
);
280 static int kv_program_pt_config_registers(struct radeon_device
*rdev
,
281 const struct kv_pt_config_reg
*cac_config_regs
)
283 const struct kv_pt_config_reg
*config_regs
= cac_config_regs
;
287 if (config_regs
== NULL
)
290 while (config_regs
->offset
!= 0xFFFFFFFF) {
291 if (config_regs
->type
== KV_CONFIGREG_CACHE
) {
292 cache
|= ((config_regs
->value
<< config_regs
->shift
) & config_regs
->mask
);
294 switch (config_regs
->type
) {
295 case KV_CONFIGREG_SMC_IND
:
296 data
= RREG32_SMC(config_regs
->offset
);
298 case KV_CONFIGREG_DIDT_IND
:
299 data
= RREG32_DIDT(config_regs
->offset
);
302 data
= RREG32(config_regs
->offset
<< 2);
306 data
&= ~config_regs
->mask
;
307 data
|= ((config_regs
->value
<< config_regs
->shift
) & config_regs
->mask
);
311 switch (config_regs
->type
) {
312 case KV_CONFIGREG_SMC_IND
:
313 WREG32_SMC(config_regs
->offset
, data
);
315 case KV_CONFIGREG_DIDT_IND
:
316 WREG32_DIDT(config_regs
->offset
, data
);
319 WREG32(config_regs
->offset
<< 2, data
);
329 static void kv_do_enable_didt(struct radeon_device
*rdev
, bool enable
)
331 struct kv_power_info
*pi
= kv_get_pi(rdev
);
334 if (pi
->caps_sq_ramping
) {
335 data
= RREG32_DIDT(DIDT_SQ_CTRL0
);
337 data
|= DIDT_CTRL_EN
;
339 data
&= ~DIDT_CTRL_EN
;
340 WREG32_DIDT(DIDT_SQ_CTRL0
, data
);
343 if (pi
->caps_db_ramping
) {
344 data
= RREG32_DIDT(DIDT_DB_CTRL0
);
346 data
|= DIDT_CTRL_EN
;
348 data
&= ~DIDT_CTRL_EN
;
349 WREG32_DIDT(DIDT_DB_CTRL0
, data
);
352 if (pi
->caps_td_ramping
) {
353 data
= RREG32_DIDT(DIDT_TD_CTRL0
);
355 data
|= DIDT_CTRL_EN
;
357 data
&= ~DIDT_CTRL_EN
;
358 WREG32_DIDT(DIDT_TD_CTRL0
, data
);
361 if (pi
->caps_tcp_ramping
) {
362 data
= RREG32_DIDT(DIDT_TCP_CTRL0
);
364 data
|= DIDT_CTRL_EN
;
366 data
&= ~DIDT_CTRL_EN
;
367 WREG32_DIDT(DIDT_TCP_CTRL0
, data
);
371 static int kv_enable_didt(struct radeon_device
*rdev
, bool enable
)
373 struct kv_power_info
*pi
= kv_get_pi(rdev
);
376 if (pi
->caps_sq_ramping
||
377 pi
->caps_db_ramping
||
378 pi
->caps_td_ramping
||
379 pi
->caps_tcp_ramping
) {
380 cik_enter_rlc_safe_mode(rdev
);
383 ret
= kv_program_pt_config_registers(rdev
, didt_config_kv
);
385 cik_exit_rlc_safe_mode(rdev
);
390 kv_do_enable_didt(rdev
, enable
);
392 cik_exit_rlc_safe_mode(rdev
);
399 static void kv_initialize_hardware_cac_manager(struct radeon_device
*rdev
)
401 struct kv_power_info
*pi
= kv_get_pi(rdev
);
404 WREG32_SMC(LCAC_SX0_OVR_SEL
, 0);
405 WREG32_SMC(LCAC_SX0_OVR_VAL
, 0);
406 kv_program_local_cac_table(rdev
, sx_local_cac_cfg_kv
, sx0_cac_config_reg
);
408 WREG32_SMC(LCAC_MC0_OVR_SEL
, 0);
409 WREG32_SMC(LCAC_MC0_OVR_VAL
, 0);
410 kv_program_local_cac_table(rdev
, mc0_local_cac_cfg_kv
, mc0_cac_config_reg
);
412 WREG32_SMC(LCAC_MC1_OVR_SEL
, 0);
413 WREG32_SMC(LCAC_MC1_OVR_VAL
, 0);
414 kv_program_local_cac_table(rdev
, mc1_local_cac_cfg_kv
, mc1_cac_config_reg
);
416 WREG32_SMC(LCAC_MC2_OVR_SEL
, 0);
417 WREG32_SMC(LCAC_MC2_OVR_VAL
, 0);
418 kv_program_local_cac_table(rdev
, mc2_local_cac_cfg_kv
, mc2_cac_config_reg
);
420 WREG32_SMC(LCAC_MC3_OVR_SEL
, 0);
421 WREG32_SMC(LCAC_MC3_OVR_VAL
, 0);
422 kv_program_local_cac_table(rdev
, mc3_local_cac_cfg_kv
, mc3_cac_config_reg
);
424 WREG32_SMC(LCAC_CPL_OVR_SEL
, 0);
425 WREG32_SMC(LCAC_CPL_OVR_VAL
, 0);
426 kv_program_local_cac_table(rdev
, cpl_local_cac_cfg_kv
, cpl_cac_config_reg
);
431 static int kv_enable_smc_cac(struct radeon_device
*rdev
, bool enable
)
433 struct kv_power_info
*pi
= kv_get_pi(rdev
);
438 ret
= kv_notify_message_to_smu(rdev
, PPSMC_MSG_EnableCac
);
440 pi
->cac_enabled
= false;
442 pi
->cac_enabled
= true;
443 } else if (pi
->cac_enabled
) {
444 kv_notify_message_to_smu(rdev
, PPSMC_MSG_DisableCac
);
445 pi
->cac_enabled
= false;
452 static int kv_process_firmware_header(struct radeon_device
*rdev
)
454 struct kv_power_info
*pi
= kv_get_pi(rdev
);
458 ret
= kv_read_smc_sram_dword(rdev
, SMU7_FIRMWARE_HEADER_LOCATION
+
459 offsetof(SMU7_Firmware_Header
, DpmTable
),
463 pi
->dpm_table_start
= tmp
;
465 ret
= kv_read_smc_sram_dword(rdev
, SMU7_FIRMWARE_HEADER_LOCATION
+
466 offsetof(SMU7_Firmware_Header
, SoftRegisters
),
470 pi
->soft_regs_start
= tmp
;
475 static int kv_enable_dpm_voltage_scaling(struct radeon_device
*rdev
)
477 struct kv_power_info
*pi
= kv_get_pi(rdev
);
480 pi
->graphics_voltage_change_enable
= 1;
482 ret
= kv_copy_bytes_to_smc(rdev
,
483 pi
->dpm_table_start
+
484 offsetof(SMU7_Fusion_DpmTable
, GraphicsVoltageChangeEnable
),
485 &pi
->graphics_voltage_change_enable
,
486 sizeof(u8
), pi
->sram_end
);
491 static int kv_set_dpm_interval(struct radeon_device
*rdev
)
493 struct kv_power_info
*pi
= kv_get_pi(rdev
);
496 pi
->graphics_interval
= 1;
498 ret
= kv_copy_bytes_to_smc(rdev
,
499 pi
->dpm_table_start
+
500 offsetof(SMU7_Fusion_DpmTable
, GraphicsInterval
),
501 &pi
->graphics_interval
,
502 sizeof(u8
), pi
->sram_end
);
507 static int kv_set_dpm_boot_state(struct radeon_device
*rdev
)
509 struct kv_power_info
*pi
= kv_get_pi(rdev
);
512 ret
= kv_copy_bytes_to_smc(rdev
,
513 pi
->dpm_table_start
+
514 offsetof(SMU7_Fusion_DpmTable
, GraphicsBootLevel
),
515 &pi
->graphics_boot_level
,
516 sizeof(u8
), pi
->sram_end
);
521 static void kv_program_vc(struct radeon_device
*rdev
)
523 WREG32_SMC(CG_FTV_0
, 0x3FFFC100);
526 static void kv_clear_vc(struct radeon_device
*rdev
)
528 WREG32_SMC(CG_FTV_0
, 0);
531 static int kv_set_divider_value(struct radeon_device
*rdev
,
534 struct kv_power_info
*pi
= kv_get_pi(rdev
);
535 struct atom_clock_dividers dividers
;
538 ret
= radeon_atom_get_clock_dividers(rdev
, COMPUTE_ENGINE_PLL_PARAM
,
539 sclk
, false, ÷rs
);
543 pi
->graphics_level
[index
].SclkDid
= (u8
)dividers
.post_div
;
544 pi
->graphics_level
[index
].SclkFrequency
= cpu_to_be32(sclk
);
549 static u16
kv_convert_8bit_index_to_voltage(struct radeon_device
*rdev
,
552 return 6200 - (voltage
* 25);
555 static u16
kv_convert_2bit_index_to_voltage(struct radeon_device
*rdev
,
558 struct kv_power_info
*pi
= kv_get_pi(rdev
);
559 u32 vid_8bit
= sumo_convert_vid2_to_vid7(rdev
,
560 &pi
->sys_info
.vid_mapping_table
,
563 return kv_convert_8bit_index_to_voltage(rdev
, (u16
)vid_8bit
);
567 static int kv_set_vid(struct radeon_device
*rdev
, u32 index
, u32 vid
)
569 struct kv_power_info
*pi
= kv_get_pi(rdev
);
571 pi
->graphics_level
[index
].VoltageDownH
= (u8
)pi
->voltage_drop_t
;
572 pi
->graphics_level
[index
].MinVddNb
=
573 cpu_to_be32(kv_convert_2bit_index_to_voltage(rdev
, vid
));
578 static int kv_set_at(struct radeon_device
*rdev
, u32 index
, u32 at
)
580 struct kv_power_info
*pi
= kv_get_pi(rdev
);
582 pi
->graphics_level
[index
].AT
= cpu_to_be16((u16
)at
);
587 static void kv_dpm_power_level_enable(struct radeon_device
*rdev
,
588 u32 index
, bool enable
)
590 struct kv_power_info
*pi
= kv_get_pi(rdev
);
592 pi
->graphics_level
[index
].EnabledForActivity
= enable
? 1 : 0;
595 static void kv_start_dpm(struct radeon_device
*rdev
)
597 u32 tmp
= RREG32_SMC(GENERAL_PWRMGT
);
599 tmp
|= GLOBAL_PWRMGT_EN
;
600 WREG32_SMC(GENERAL_PWRMGT
, tmp
);
602 kv_smc_dpm_enable(rdev
, true);
605 static void kv_stop_dpm(struct radeon_device
*rdev
)
607 kv_smc_dpm_enable(rdev
, false);
610 static void kv_start_am(struct radeon_device
*rdev
)
612 u32 sclk_pwrmgt_cntl
= RREG32_SMC(SCLK_PWRMGT_CNTL
);
614 sclk_pwrmgt_cntl
&= ~(RESET_SCLK_CNT
| RESET_BUSY_CNT
);
615 sclk_pwrmgt_cntl
|= DYNAMIC_PM_EN
;
617 WREG32_SMC(SCLK_PWRMGT_CNTL
, sclk_pwrmgt_cntl
);
620 static void kv_reset_am(struct radeon_device
*rdev
)
622 u32 sclk_pwrmgt_cntl
= RREG32_SMC(SCLK_PWRMGT_CNTL
);
624 sclk_pwrmgt_cntl
|= (RESET_SCLK_CNT
| RESET_BUSY_CNT
);
626 WREG32_SMC(SCLK_PWRMGT_CNTL
, sclk_pwrmgt_cntl
);
629 static int kv_freeze_sclk_dpm(struct radeon_device
*rdev
, bool freeze
)
631 return kv_notify_message_to_smu(rdev
, freeze
?
632 PPSMC_MSG_SCLKDPM_FreezeLevel
: PPSMC_MSG_SCLKDPM_UnfreezeLevel
);
635 static int kv_force_lowest_valid(struct radeon_device
*rdev
)
637 return kv_force_dpm_lowest(rdev
);
640 static int kv_unforce_levels(struct radeon_device
*rdev
)
642 if (rdev
->family
== CHIP_KABINI
)
643 return kv_notify_message_to_smu(rdev
, PPSMC_MSG_NoForcedLevel
);
645 return kv_set_enabled_levels(rdev
);
648 static int kv_update_sclk_t(struct radeon_device
*rdev
)
650 struct kv_power_info
*pi
= kv_get_pi(rdev
);
651 u32 low_sclk_interrupt_t
= 0;
654 if (pi
->caps_sclk_throttle_low_notification
) {
655 low_sclk_interrupt_t
= cpu_to_be32(pi
->low_sclk_interrupt_t
);
657 ret
= kv_copy_bytes_to_smc(rdev
,
658 pi
->dpm_table_start
+
659 offsetof(SMU7_Fusion_DpmTable
, LowSclkInterruptT
),
660 (u8
*)&low_sclk_interrupt_t
,
661 sizeof(u32
), pi
->sram_end
);
666 static int kv_program_bootup_state(struct radeon_device
*rdev
)
668 struct kv_power_info
*pi
= kv_get_pi(rdev
);
670 struct radeon_clock_voltage_dependency_table
*table
=
671 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
;
673 if (table
&& table
->count
) {
674 for (i
= pi
->graphics_dpm_level_count
- 1; i
> 0; i
--) {
675 if (table
->entries
[i
].clk
== pi
->boot_pl
.sclk
)
679 pi
->graphics_boot_level
= (u8
)i
;
680 kv_dpm_power_level_enable(rdev
, i
, true);
682 struct sumo_sclk_voltage_mapping_table
*table
=
683 &pi
->sys_info
.sclk_voltage_mapping_table
;
685 if (table
->num_max_dpm_entries
== 0)
688 for (i
= pi
->graphics_dpm_level_count
- 1; i
> 0; i
--) {
689 if (table
->entries
[i
].sclk_frequency
== pi
->boot_pl
.sclk
)
693 pi
->graphics_boot_level
= (u8
)i
;
694 kv_dpm_power_level_enable(rdev
, i
, true);
699 static int kv_enable_auto_thermal_throttling(struct radeon_device
*rdev
)
701 struct kv_power_info
*pi
= kv_get_pi(rdev
);
704 pi
->graphics_therm_throttle_enable
= 1;
706 ret
= kv_copy_bytes_to_smc(rdev
,
707 pi
->dpm_table_start
+
708 offsetof(SMU7_Fusion_DpmTable
, GraphicsThermThrottleEnable
),
709 &pi
->graphics_therm_throttle_enable
,
710 sizeof(u8
), pi
->sram_end
);
715 static int kv_upload_dpm_settings(struct radeon_device
*rdev
)
717 struct kv_power_info
*pi
= kv_get_pi(rdev
);
720 ret
= kv_copy_bytes_to_smc(rdev
,
721 pi
->dpm_table_start
+
722 offsetof(SMU7_Fusion_DpmTable
, GraphicsLevel
),
723 (u8
*)&pi
->graphics_level
,
724 sizeof(SMU7_Fusion_GraphicsLevel
) * SMU7_MAX_LEVELS_GRAPHICS
,
730 ret
= kv_copy_bytes_to_smc(rdev
,
731 pi
->dpm_table_start
+
732 offsetof(SMU7_Fusion_DpmTable
, GraphicsDpmLevelCount
),
733 &pi
->graphics_dpm_level_count
,
734 sizeof(u8
), pi
->sram_end
);
739 static u32
kv_get_clock_difference(u32 a
, u32 b
)
741 return (a
>= b
) ? a
- b
: b
- a
;
744 static u32
kv_get_clk_bypass(struct radeon_device
*rdev
, u32 clk
)
746 struct kv_power_info
*pi
= kv_get_pi(rdev
);
749 if (pi
->caps_enable_dfs_bypass
) {
750 if (kv_get_clock_difference(clk
, 40000) < 200)
752 else if (kv_get_clock_difference(clk
, 30000) < 200)
754 else if (kv_get_clock_difference(clk
, 20000) < 200)
756 else if (kv_get_clock_difference(clk
, 15000) < 200)
758 else if (kv_get_clock_difference(clk
, 10000) < 200)
769 static int kv_populate_uvd_table(struct radeon_device
*rdev
)
771 struct kv_power_info
*pi
= kv_get_pi(rdev
);
772 struct radeon_uvd_clock_voltage_dependency_table
*table
=
773 &rdev
->pm
.dpm
.dyn_state
.uvd_clock_voltage_dependency_table
;
774 struct atom_clock_dividers dividers
;
778 if (table
== NULL
|| table
->count
== 0)
781 pi
->uvd_level_count
= 0;
782 for (i
= 0; i
< table
->count
; i
++) {
783 if (pi
->high_voltage_t
&&
784 (pi
->high_voltage_t
< table
->entries
[i
].v
))
787 pi
->uvd_level
[i
].VclkFrequency
= cpu_to_be32(table
->entries
[i
].vclk
);
788 pi
->uvd_level
[i
].DclkFrequency
= cpu_to_be32(table
->entries
[i
].dclk
);
789 pi
->uvd_level
[i
].MinVddNb
= cpu_to_be16(table
->entries
[i
].v
);
791 pi
->uvd_level
[i
].VClkBypassCntl
=
792 (u8
)kv_get_clk_bypass(rdev
, table
->entries
[i
].vclk
);
793 pi
->uvd_level
[i
].DClkBypassCntl
=
794 (u8
)kv_get_clk_bypass(rdev
, table
->entries
[i
].dclk
);
796 ret
= radeon_atom_get_clock_dividers(rdev
, COMPUTE_ENGINE_PLL_PARAM
,
797 table
->entries
[i
].vclk
, false, ÷rs
);
800 pi
->uvd_level
[i
].VclkDivider
= (u8
)dividers
.post_div
;
802 ret
= radeon_atom_get_clock_dividers(rdev
, COMPUTE_ENGINE_PLL_PARAM
,
803 table
->entries
[i
].dclk
, false, ÷rs
);
806 pi
->uvd_level
[i
].DclkDivider
= (u8
)dividers
.post_div
;
808 pi
->uvd_level_count
++;
811 ret
= kv_copy_bytes_to_smc(rdev
,
812 pi
->dpm_table_start
+
813 offsetof(SMU7_Fusion_DpmTable
, UvdLevelCount
),
814 (u8
*)&pi
->uvd_level_count
,
815 sizeof(u8
), pi
->sram_end
);
819 pi
->uvd_interval
= 1;
821 ret
= kv_copy_bytes_to_smc(rdev
,
822 pi
->dpm_table_start
+
823 offsetof(SMU7_Fusion_DpmTable
, UVDInterval
),
825 sizeof(u8
), pi
->sram_end
);
829 ret
= kv_copy_bytes_to_smc(rdev
,
830 pi
->dpm_table_start
+
831 offsetof(SMU7_Fusion_DpmTable
, UvdLevel
),
832 (u8
*)&pi
->uvd_level
,
833 sizeof(SMU7_Fusion_UvdLevel
) * SMU7_MAX_LEVELS_UVD
,
840 static int kv_populate_vce_table(struct radeon_device
*rdev
)
842 struct kv_power_info
*pi
= kv_get_pi(rdev
);
845 struct radeon_vce_clock_voltage_dependency_table
*table
=
846 &rdev
->pm
.dpm
.dyn_state
.vce_clock_voltage_dependency_table
;
847 struct atom_clock_dividers dividers
;
849 if (table
== NULL
|| table
->count
== 0)
852 pi
->vce_level_count
= 0;
853 for (i
= 0; i
< table
->count
; i
++) {
854 if (pi
->high_voltage_t
&&
855 pi
->high_voltage_t
< table
->entries
[i
].v
)
858 pi
->vce_level
[i
].Frequency
= cpu_to_be32(table
->entries
[i
].evclk
);
859 pi
->vce_level
[i
].MinVoltage
= cpu_to_be16(table
->entries
[i
].v
);
861 pi
->vce_level
[i
].ClkBypassCntl
=
862 (u8
)kv_get_clk_bypass(rdev
, table
->entries
[i
].evclk
);
864 ret
= radeon_atom_get_clock_dividers(rdev
, COMPUTE_ENGINE_PLL_PARAM
,
865 table
->entries
[i
].evclk
, false, ÷rs
);
868 pi
->vce_level
[i
].Divider
= (u8
)dividers
.post_div
;
870 pi
->vce_level_count
++;
873 ret
= kv_copy_bytes_to_smc(rdev
,
874 pi
->dpm_table_start
+
875 offsetof(SMU7_Fusion_DpmTable
, VceLevelCount
),
876 (u8
*)&pi
->vce_level_count
,
882 pi
->vce_interval
= 1;
884 ret
= kv_copy_bytes_to_smc(rdev
,
885 pi
->dpm_table_start
+
886 offsetof(SMU7_Fusion_DpmTable
, VCEInterval
),
887 (u8
*)&pi
->vce_interval
,
893 ret
= kv_copy_bytes_to_smc(rdev
,
894 pi
->dpm_table_start
+
895 offsetof(SMU7_Fusion_DpmTable
, VceLevel
),
896 (u8
*)&pi
->vce_level
,
897 sizeof(SMU7_Fusion_ExtClkLevel
) * SMU7_MAX_LEVELS_VCE
,
903 static int kv_populate_samu_table(struct radeon_device
*rdev
)
905 struct kv_power_info
*pi
= kv_get_pi(rdev
);
906 struct radeon_clock_voltage_dependency_table
*table
=
907 &rdev
->pm
.dpm
.dyn_state
.samu_clock_voltage_dependency_table
;
908 struct atom_clock_dividers dividers
;
912 if (table
== NULL
|| table
->count
== 0)
915 pi
->samu_level_count
= 0;
916 for (i
= 0; i
< table
->count
; i
++) {
917 if (pi
->high_voltage_t
&&
918 pi
->high_voltage_t
< table
->entries
[i
].v
)
921 pi
->samu_level
[i
].Frequency
= cpu_to_be32(table
->entries
[i
].clk
);
922 pi
->samu_level
[i
].MinVoltage
= cpu_to_be16(table
->entries
[i
].v
);
924 pi
->samu_level
[i
].ClkBypassCntl
=
925 (u8
)kv_get_clk_bypass(rdev
, table
->entries
[i
].clk
);
927 ret
= radeon_atom_get_clock_dividers(rdev
, COMPUTE_ENGINE_PLL_PARAM
,
928 table
->entries
[i
].clk
, false, ÷rs
);
931 pi
->samu_level
[i
].Divider
= (u8
)dividers
.post_div
;
933 pi
->samu_level_count
++;
936 ret
= kv_copy_bytes_to_smc(rdev
,
937 pi
->dpm_table_start
+
938 offsetof(SMU7_Fusion_DpmTable
, SamuLevelCount
),
939 (u8
*)&pi
->samu_level_count
,
945 pi
->samu_interval
= 1;
947 ret
= kv_copy_bytes_to_smc(rdev
,
948 pi
->dpm_table_start
+
949 offsetof(SMU7_Fusion_DpmTable
, SAMUInterval
),
950 (u8
*)&pi
->samu_interval
,
956 ret
= kv_copy_bytes_to_smc(rdev
,
957 pi
->dpm_table_start
+
958 offsetof(SMU7_Fusion_DpmTable
, SamuLevel
),
959 (u8
*)&pi
->samu_level
,
960 sizeof(SMU7_Fusion_ExtClkLevel
) * SMU7_MAX_LEVELS_SAMU
,
969 static int kv_populate_acp_table(struct radeon_device
*rdev
)
971 struct kv_power_info
*pi
= kv_get_pi(rdev
);
972 struct radeon_clock_voltage_dependency_table
*table
=
973 &rdev
->pm
.dpm
.dyn_state
.acp_clock_voltage_dependency_table
;
974 struct atom_clock_dividers dividers
;
978 if (table
== NULL
|| table
->count
== 0)
981 pi
->acp_level_count
= 0;
982 for (i
= 0; i
< table
->count
; i
++) {
983 pi
->acp_level
[i
].Frequency
= cpu_to_be32(table
->entries
[i
].clk
);
984 pi
->acp_level
[i
].MinVoltage
= cpu_to_be16(table
->entries
[i
].v
);
986 ret
= radeon_atom_get_clock_dividers(rdev
, COMPUTE_ENGINE_PLL_PARAM
,
987 table
->entries
[i
].clk
, false, ÷rs
);
990 pi
->acp_level
[i
].Divider
= (u8
)dividers
.post_div
;
992 pi
->acp_level_count
++;
995 ret
= kv_copy_bytes_to_smc(rdev
,
996 pi
->dpm_table_start
+
997 offsetof(SMU7_Fusion_DpmTable
, AcpLevelCount
),
998 (u8
*)&pi
->acp_level_count
,
1004 pi
->acp_interval
= 1;
1006 ret
= kv_copy_bytes_to_smc(rdev
,
1007 pi
->dpm_table_start
+
1008 offsetof(SMU7_Fusion_DpmTable
, ACPInterval
),
1009 (u8
*)&pi
->acp_interval
,
1015 ret
= kv_copy_bytes_to_smc(rdev
,
1016 pi
->dpm_table_start
+
1017 offsetof(SMU7_Fusion_DpmTable
, AcpLevel
),
1018 (u8
*)&pi
->acp_level
,
1019 sizeof(SMU7_Fusion_ExtClkLevel
) * SMU7_MAX_LEVELS_ACP
,
1027 static void kv_calculate_dfs_bypass_settings(struct radeon_device
*rdev
)
1029 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1031 struct radeon_clock_voltage_dependency_table
*table
=
1032 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
;
1034 if (table
&& table
->count
) {
1035 for (i
= 0; i
< pi
->graphics_dpm_level_count
; i
++) {
1036 if (pi
->caps_enable_dfs_bypass
) {
1037 if (kv_get_clock_difference(table
->entries
[i
].clk
, 40000) < 200)
1038 pi
->graphics_level
[i
].ClkBypassCntl
= 3;
1039 else if (kv_get_clock_difference(table
->entries
[i
].clk
, 30000) < 200)
1040 pi
->graphics_level
[i
].ClkBypassCntl
= 2;
1041 else if (kv_get_clock_difference(table
->entries
[i
].clk
, 26600) < 200)
1042 pi
->graphics_level
[i
].ClkBypassCntl
= 7;
1043 else if (kv_get_clock_difference(table
->entries
[i
].clk
, 20000) < 200)
1044 pi
->graphics_level
[i
].ClkBypassCntl
= 6;
1045 else if (kv_get_clock_difference(table
->entries
[i
].clk
, 10000) < 200)
1046 pi
->graphics_level
[i
].ClkBypassCntl
= 8;
1048 pi
->graphics_level
[i
].ClkBypassCntl
= 0;
1050 pi
->graphics_level
[i
].ClkBypassCntl
= 0;
1054 struct sumo_sclk_voltage_mapping_table
*table
=
1055 &pi
->sys_info
.sclk_voltage_mapping_table
;
1056 for (i
= 0; i
< pi
->graphics_dpm_level_count
; i
++) {
1057 if (pi
->caps_enable_dfs_bypass
) {
1058 if (kv_get_clock_difference(table
->entries
[i
].sclk_frequency
, 40000) < 200)
1059 pi
->graphics_level
[i
].ClkBypassCntl
= 3;
1060 else if (kv_get_clock_difference(table
->entries
[i
].sclk_frequency
, 30000) < 200)
1061 pi
->graphics_level
[i
].ClkBypassCntl
= 2;
1062 else if (kv_get_clock_difference(table
->entries
[i
].sclk_frequency
, 26600) < 200)
1063 pi
->graphics_level
[i
].ClkBypassCntl
= 7;
1064 else if (kv_get_clock_difference(table
->entries
[i
].sclk_frequency
, 20000) < 200)
1065 pi
->graphics_level
[i
].ClkBypassCntl
= 6;
1066 else if (kv_get_clock_difference(table
->entries
[i
].sclk_frequency
, 10000) < 200)
1067 pi
->graphics_level
[i
].ClkBypassCntl
= 8;
1069 pi
->graphics_level
[i
].ClkBypassCntl
= 0;
1071 pi
->graphics_level
[i
].ClkBypassCntl
= 0;
1077 static int kv_enable_ulv(struct radeon_device
*rdev
, bool enable
)
1079 return kv_notify_message_to_smu(rdev
, enable
?
1080 PPSMC_MSG_EnableULV
: PPSMC_MSG_DisableULV
);
1083 static void kv_reset_acp_boot_level(struct radeon_device
*rdev
)
1085 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1087 pi
->acp_boot_level
= 0xff;
1090 static void kv_update_current_ps(struct radeon_device
*rdev
,
1091 struct radeon_ps
*rps
)
1093 struct kv_ps
*new_ps
= kv_get_ps(rps
);
1094 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1096 pi
->current_rps
= *rps
;
1097 pi
->current_ps
= *new_ps
;
1098 pi
->current_rps
.ps_priv
= &pi
->current_ps
;
1101 static void kv_update_requested_ps(struct radeon_device
*rdev
,
1102 struct radeon_ps
*rps
)
1104 struct kv_ps
*new_ps
= kv_get_ps(rps
);
1105 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1107 pi
->requested_rps
= *rps
;
1108 pi
->requested_ps
= *new_ps
;
1109 pi
->requested_rps
.ps_priv
= &pi
->requested_ps
;
1112 void kv_dpm_enable_bapm(struct radeon_device
*rdev
, bool enable
)
1114 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1117 if (pi
->bapm_enable
) {
1118 ret
= kv_smc_bapm_enable(rdev
, enable
);
1120 DRM_ERROR("kv_smc_bapm_enable failed\n");
1124 int kv_dpm_enable(struct radeon_device
*rdev
)
1126 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1129 ret
= kv_process_firmware_header(rdev
);
1131 DRM_ERROR("kv_process_firmware_header failed\n");
1134 kv_init_fps_limits(rdev
);
1135 kv_init_graphics_levels(rdev
);
1136 ret
= kv_program_bootup_state(rdev
);
1138 DRM_ERROR("kv_program_bootup_state failed\n");
1141 kv_calculate_dfs_bypass_settings(rdev
);
1142 ret
= kv_upload_dpm_settings(rdev
);
1144 DRM_ERROR("kv_upload_dpm_settings failed\n");
1147 ret
= kv_populate_uvd_table(rdev
);
1149 DRM_ERROR("kv_populate_uvd_table failed\n");
1152 ret
= kv_populate_vce_table(rdev
);
1154 DRM_ERROR("kv_populate_vce_table failed\n");
1157 ret
= kv_populate_samu_table(rdev
);
1159 DRM_ERROR("kv_populate_samu_table failed\n");
1162 ret
= kv_populate_acp_table(rdev
);
1164 DRM_ERROR("kv_populate_acp_table failed\n");
1167 kv_program_vc(rdev
);
1169 kv_initialize_hardware_cac_manager(rdev
);
1172 if (pi
->enable_auto_thermal_throttling
) {
1173 ret
= kv_enable_auto_thermal_throttling(rdev
);
1175 DRM_ERROR("kv_enable_auto_thermal_throttling failed\n");
1179 ret
= kv_enable_dpm_voltage_scaling(rdev
);
1181 DRM_ERROR("kv_enable_dpm_voltage_scaling failed\n");
1184 ret
= kv_set_dpm_interval(rdev
);
1186 DRM_ERROR("kv_set_dpm_interval failed\n");
1189 ret
= kv_set_dpm_boot_state(rdev
);
1191 DRM_ERROR("kv_set_dpm_boot_state failed\n");
1194 ret
= kv_enable_ulv(rdev
, true);
1196 DRM_ERROR("kv_enable_ulv failed\n");
1200 ret
= kv_enable_didt(rdev
, true);
1202 DRM_ERROR("kv_enable_didt failed\n");
1205 ret
= kv_enable_smc_cac(rdev
, true);
1207 DRM_ERROR("kv_enable_smc_cac failed\n");
1211 kv_reset_acp_boot_level(rdev
);
1213 ret
= kv_smc_bapm_enable(rdev
, false);
1215 DRM_ERROR("kv_smc_bapm_enable failed\n");
1219 kv_update_current_ps(rdev
, rdev
->pm
.dpm
.boot_ps
);
1224 int kv_dpm_late_enable(struct radeon_device
*rdev
)
1228 if (rdev
->irq
.installed
&&
1229 r600_is_internal_thermal_sensor(rdev
->pm
.int_thermal_type
)) {
1230 ret
= kv_set_thermal_temperature_range(rdev
, R600_TEMP_RANGE_MIN
, R600_TEMP_RANGE_MAX
);
1232 DRM_ERROR("kv_set_thermal_temperature_range failed\n");
1235 rdev
->irq
.dpm_thermal
= true;
1236 radeon_irq_set(rdev
);
1239 /* powerdown unused blocks for now */
1240 kv_dpm_powergate_acp(rdev
, true);
1241 kv_dpm_powergate_samu(rdev
, true);
1242 kv_dpm_powergate_vce(rdev
, true);
1243 kv_dpm_powergate_uvd(rdev
, true);
1248 void kv_dpm_disable(struct radeon_device
*rdev
)
1250 kv_smc_bapm_enable(rdev
, false);
1252 /* powerup blocks */
1253 kv_dpm_powergate_acp(rdev
, false);
1254 kv_dpm_powergate_samu(rdev
, false);
1255 kv_dpm_powergate_vce(rdev
, false);
1256 kv_dpm_powergate_uvd(rdev
, false);
1258 kv_enable_smc_cac(rdev
, false);
1259 kv_enable_didt(rdev
, false);
1262 kv_enable_ulv(rdev
, false);
1265 kv_update_current_ps(rdev
, rdev
->pm
.dpm
.boot_ps
);
1269 static int kv_write_smc_soft_register(struct radeon_device
*rdev
,
1270 u16 reg_offset
, u32 value
)
1272 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1274 return kv_copy_bytes_to_smc(rdev
, pi
->soft_regs_start
+ reg_offset
,
1275 (u8
*)&value
, sizeof(u16
), pi
->sram_end
);
1278 static int kv_read_smc_soft_register(struct radeon_device
*rdev
,
1279 u16 reg_offset
, u32
*value
)
1281 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1283 return kv_read_smc_sram_dword(rdev
, pi
->soft_regs_start
+ reg_offset
,
1284 value
, pi
->sram_end
);
1288 static void kv_init_sclk_t(struct radeon_device
*rdev
)
1290 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1292 pi
->low_sclk_interrupt_t
= 0;
1295 static int kv_init_fps_limits(struct radeon_device
*rdev
)
1297 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1304 pi
->fps_high_t
= cpu_to_be16(tmp
);
1305 ret
= kv_copy_bytes_to_smc(rdev
,
1306 pi
->dpm_table_start
+
1307 offsetof(SMU7_Fusion_DpmTable
, FpsHighT
),
1308 (u8
*)&pi
->fps_high_t
,
1309 sizeof(u16
), pi
->sram_end
);
1312 pi
->fps_low_t
= cpu_to_be16(tmp
);
1314 ret
= kv_copy_bytes_to_smc(rdev
,
1315 pi
->dpm_table_start
+
1316 offsetof(SMU7_Fusion_DpmTable
, FpsLowT
),
1317 (u8
*)&pi
->fps_low_t
,
1318 sizeof(u16
), pi
->sram_end
);
1324 static void kv_init_powergate_state(struct radeon_device
*rdev
)
1326 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1328 pi
->uvd_power_gated
= false;
1329 pi
->vce_power_gated
= false;
1330 pi
->samu_power_gated
= false;
1331 pi
->acp_power_gated
= false;
1335 static int kv_enable_uvd_dpm(struct radeon_device
*rdev
, bool enable
)
1337 return kv_notify_message_to_smu(rdev
, enable
?
1338 PPSMC_MSG_UVDDPM_Enable
: PPSMC_MSG_UVDDPM_Disable
);
1342 static int kv_enable_vce_dpm(struct radeon_device
*rdev
, bool enable
)
1344 return kv_notify_message_to_smu(rdev
, enable
?
1345 PPSMC_MSG_VCEDPM_Enable
: PPSMC_MSG_VCEDPM_Disable
);
1349 static int kv_enable_samu_dpm(struct radeon_device
*rdev
, bool enable
)
1351 return kv_notify_message_to_smu(rdev
, enable
?
1352 PPSMC_MSG_SAMUDPM_Enable
: PPSMC_MSG_SAMUDPM_Disable
);
1355 static int kv_enable_acp_dpm(struct radeon_device
*rdev
, bool enable
)
1357 return kv_notify_message_to_smu(rdev
, enable
?
1358 PPSMC_MSG_ACPDPM_Enable
: PPSMC_MSG_ACPDPM_Disable
);
1361 static int kv_update_uvd_dpm(struct radeon_device
*rdev
, bool gate
)
1363 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1364 struct radeon_uvd_clock_voltage_dependency_table
*table
=
1365 &rdev
->pm
.dpm
.dyn_state
.uvd_clock_voltage_dependency_table
;
1369 if (!pi
->caps_uvd_dpm
|| table
->count
|| pi
->caps_stable_p_state
)
1370 pi
->uvd_boot_level
= table
->count
- 1;
1372 pi
->uvd_boot_level
= 0;
1374 ret
= kv_copy_bytes_to_smc(rdev
,
1375 pi
->dpm_table_start
+
1376 offsetof(SMU7_Fusion_DpmTable
, UvdBootLevel
),
1377 (uint8_t *)&pi
->uvd_boot_level
,
1378 sizeof(u8
), pi
->sram_end
);
1382 if (!pi
->caps_uvd_dpm
||
1383 pi
->caps_stable_p_state
)
1384 kv_send_msg_to_smc_with_parameter(rdev
,
1385 PPSMC_MSG_UVDDPM_SetEnabledMask
,
1386 (1 << pi
->uvd_boot_level
));
1389 return kv_enable_uvd_dpm(rdev
, !gate
);
1393 static u8
kv_get_vce_boot_level(struct radeon_device
*rdev
)
1396 struct radeon_vce_clock_voltage_dependency_table
*table
=
1397 &rdev
->pm
.dpm
.dyn_state
.vce_clock_voltage_dependency_table
;
1399 for (i
= 0; i
< table
->count
; i
++) {
1400 if (table
->entries
[i
].evclk
>= 0) /* XXX */
1407 static int kv_update_vce_dpm(struct radeon_device
*rdev
,
1408 struct radeon_ps
*radeon_new_state
,
1409 struct radeon_ps
*radeon_current_state
)
1411 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1412 struct radeon_vce_clock_voltage_dependency_table
*table
=
1413 &rdev
->pm
.dpm
.dyn_state
.vce_clock_voltage_dependency_table
;
1416 if (radeon_new_state
->evclk
> 0 && radeon_current_state
->evclk
== 0) {
1417 if (pi
->caps_stable_p_state
)
1418 pi
->vce_boot_level
= table
->count
- 1;
1420 pi
->vce_boot_level
= kv_get_vce_boot_level(rdev
);
1422 ret
= kv_copy_bytes_to_smc(rdev
,
1423 pi
->dpm_table_start
+
1424 offsetof(SMU7_Fusion_DpmTable
, VceBootLevel
),
1425 (u8
*)&pi
->vce_boot_level
,
1431 if (pi
->caps_stable_p_state
)
1432 kv_send_msg_to_smc_with_parameter(rdev
,
1433 PPSMC_MSG_VCEDPM_SetEnabledMask
,
1434 (1 << pi
->vce_boot_level
));
1436 kv_enable_vce_dpm(rdev
, true);
1437 } else if (radeon_new_state
->evclk
== 0 && radeon_current_state
->evclk
> 0) {
1438 kv_enable_vce_dpm(rdev
, false);
1445 static int kv_update_samu_dpm(struct radeon_device
*rdev
, bool gate
)
1447 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1448 struct radeon_clock_voltage_dependency_table
*table
=
1449 &rdev
->pm
.dpm
.dyn_state
.samu_clock_voltage_dependency_table
;
1453 if (pi
->caps_stable_p_state
)
1454 pi
->samu_boot_level
= table
->count
- 1;
1456 pi
->samu_boot_level
= 0;
1458 ret
= kv_copy_bytes_to_smc(rdev
,
1459 pi
->dpm_table_start
+
1460 offsetof(SMU7_Fusion_DpmTable
, SamuBootLevel
),
1461 (u8
*)&pi
->samu_boot_level
,
1467 if (pi
->caps_stable_p_state
)
1468 kv_send_msg_to_smc_with_parameter(rdev
,
1469 PPSMC_MSG_SAMUDPM_SetEnabledMask
,
1470 (1 << pi
->samu_boot_level
));
1473 return kv_enable_samu_dpm(rdev
, !gate
);
1476 static u8
kv_get_acp_boot_level(struct radeon_device
*rdev
)
1479 struct radeon_clock_voltage_dependency_table
*table
=
1480 &rdev
->pm
.dpm
.dyn_state
.acp_clock_voltage_dependency_table
;
1482 for (i
= 0; i
< table
->count
; i
++) {
1483 if (table
->entries
[i
].clk
>= 0) /* XXX */
1487 if (i
>= table
->count
)
1488 i
= table
->count
- 1;
1493 static void kv_update_acp_boot_level(struct radeon_device
*rdev
)
1495 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1498 if (!pi
->caps_stable_p_state
) {
1499 acp_boot_level
= kv_get_acp_boot_level(rdev
);
1500 if (acp_boot_level
!= pi
->acp_boot_level
) {
1501 pi
->acp_boot_level
= acp_boot_level
;
1502 kv_send_msg_to_smc_with_parameter(rdev
,
1503 PPSMC_MSG_ACPDPM_SetEnabledMask
,
1504 (1 << pi
->acp_boot_level
));
1509 static int kv_update_acp_dpm(struct radeon_device
*rdev
, bool gate
)
1511 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1512 struct radeon_clock_voltage_dependency_table
*table
=
1513 &rdev
->pm
.dpm
.dyn_state
.acp_clock_voltage_dependency_table
;
1517 if (pi
->caps_stable_p_state
)
1518 pi
->acp_boot_level
= table
->count
- 1;
1520 pi
->acp_boot_level
= kv_get_acp_boot_level(rdev
);
1522 ret
= kv_copy_bytes_to_smc(rdev
,
1523 pi
->dpm_table_start
+
1524 offsetof(SMU7_Fusion_DpmTable
, AcpBootLevel
),
1525 (u8
*)&pi
->acp_boot_level
,
1531 if (pi
->caps_stable_p_state
)
1532 kv_send_msg_to_smc_with_parameter(rdev
,
1533 PPSMC_MSG_ACPDPM_SetEnabledMask
,
1534 (1 << pi
->acp_boot_level
));
1537 return kv_enable_acp_dpm(rdev
, !gate
);
1540 void kv_dpm_powergate_uvd(struct radeon_device
*rdev
, bool gate
)
1542 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1544 if (pi
->uvd_power_gated
== gate
)
1547 pi
->uvd_power_gated
= gate
;
1550 if (pi
->caps_uvd_pg
) {
1551 uvd_v1_0_stop(rdev
);
1552 cik_update_cg(rdev
, RADEON_CG_BLOCK_UVD
, false);
1554 kv_update_uvd_dpm(rdev
, gate
);
1555 if (pi
->caps_uvd_pg
)
1556 kv_notify_message_to_smu(rdev
, PPSMC_MSG_UVDPowerOFF
);
1558 if (pi
->caps_uvd_pg
) {
1559 kv_notify_message_to_smu(rdev
, PPSMC_MSG_UVDPowerON
);
1560 uvd_v4_2_resume(rdev
);
1561 uvd_v1_0_start(rdev
);
1562 cik_update_cg(rdev
, RADEON_CG_BLOCK_UVD
, true);
1564 kv_update_uvd_dpm(rdev
, gate
);
1568 static void kv_dpm_powergate_vce(struct radeon_device
*rdev
, bool gate
)
1570 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1572 if (pi
->vce_power_gated
== gate
)
1575 pi
->vce_power_gated
= gate
;
1578 if (pi
->caps_vce_pg
)
1579 kv_notify_message_to_smu(rdev
, PPSMC_MSG_VCEPowerOFF
);
1581 if (pi
->caps_vce_pg
)
1582 kv_notify_message_to_smu(rdev
, PPSMC_MSG_VCEPowerON
);
1586 static void kv_dpm_powergate_samu(struct radeon_device
*rdev
, bool gate
)
1588 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1590 if (pi
->samu_power_gated
== gate
)
1593 pi
->samu_power_gated
= gate
;
1596 kv_update_samu_dpm(rdev
, true);
1597 if (pi
->caps_samu_pg
)
1598 kv_notify_message_to_smu(rdev
, PPSMC_MSG_SAMPowerOFF
);
1600 if (pi
->caps_samu_pg
)
1601 kv_notify_message_to_smu(rdev
, PPSMC_MSG_SAMPowerON
);
1602 kv_update_samu_dpm(rdev
, false);
1606 static void kv_dpm_powergate_acp(struct radeon_device
*rdev
, bool gate
)
1608 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1610 if (pi
->acp_power_gated
== gate
)
1613 if (rdev
->family
== CHIP_KABINI
)
1616 pi
->acp_power_gated
= gate
;
1619 kv_update_acp_dpm(rdev
, true);
1620 if (pi
->caps_acp_pg
)
1621 kv_notify_message_to_smu(rdev
, PPSMC_MSG_ACPPowerOFF
);
1623 if (pi
->caps_acp_pg
)
1624 kv_notify_message_to_smu(rdev
, PPSMC_MSG_ACPPowerON
);
1625 kv_update_acp_dpm(rdev
, false);
1629 static void kv_set_valid_clock_range(struct radeon_device
*rdev
,
1630 struct radeon_ps
*new_rps
)
1632 struct kv_ps
*new_ps
= kv_get_ps(new_rps
);
1633 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1635 struct radeon_clock_voltage_dependency_table
*table
=
1636 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
;
1638 if (table
&& table
->count
) {
1639 for (i
= 0; i
< pi
->graphics_dpm_level_count
; i
++) {
1640 if ((table
->entries
[i
].clk
>= new_ps
->levels
[0].sclk
) ||
1641 (i
== (pi
->graphics_dpm_level_count
- 1))) {
1642 pi
->lowest_valid
= i
;
1647 for (i
= pi
->graphics_dpm_level_count
- 1; i
> 0; i
--) {
1648 if (table
->entries
[i
].clk
<= new_ps
->levels
[new_ps
->num_levels
- 1].sclk
)
1651 pi
->highest_valid
= i
;
1653 if (pi
->lowest_valid
> pi
->highest_valid
) {
1654 if ((new_ps
->levels
[0].sclk
- table
->entries
[pi
->highest_valid
].clk
) >
1655 (table
->entries
[pi
->lowest_valid
].clk
- new_ps
->levels
[new_ps
->num_levels
- 1].sclk
))
1656 pi
->highest_valid
= pi
->lowest_valid
;
1658 pi
->lowest_valid
= pi
->highest_valid
;
1661 struct sumo_sclk_voltage_mapping_table
*table
=
1662 &pi
->sys_info
.sclk_voltage_mapping_table
;
1664 for (i
= 0; i
< (int)pi
->graphics_dpm_level_count
; i
++) {
1665 if (table
->entries
[i
].sclk_frequency
>= new_ps
->levels
[0].sclk
||
1666 i
== (int)(pi
->graphics_dpm_level_count
- 1)) {
1667 pi
->lowest_valid
= i
;
1672 for (i
= pi
->graphics_dpm_level_count
- 1; i
> 0; i
--) {
1673 if (table
->entries
[i
].sclk_frequency
<=
1674 new_ps
->levels
[new_ps
->num_levels
- 1].sclk
)
1677 pi
->highest_valid
= i
;
1679 if (pi
->lowest_valid
> pi
->highest_valid
) {
1680 if ((new_ps
->levels
[0].sclk
-
1681 table
->entries
[pi
->highest_valid
].sclk_frequency
) >
1682 (table
->entries
[pi
->lowest_valid
].sclk_frequency
-
1683 new_ps
->levels
[new_ps
->num_levels
-1].sclk
))
1684 pi
->highest_valid
= pi
->lowest_valid
;
1686 pi
->lowest_valid
= pi
->highest_valid
;
1691 static int kv_update_dfs_bypass_settings(struct radeon_device
*rdev
,
1692 struct radeon_ps
*new_rps
)
1694 struct kv_ps
*new_ps
= kv_get_ps(new_rps
);
1695 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1699 if (pi
->caps_enable_dfs_bypass
) {
1700 clk_bypass_cntl
= new_ps
->need_dfs_bypass
?
1701 pi
->graphics_level
[pi
->graphics_boot_level
].ClkBypassCntl
: 0;
1702 ret
= kv_copy_bytes_to_smc(rdev
,
1703 (pi
->dpm_table_start
+
1704 offsetof(SMU7_Fusion_DpmTable
, GraphicsLevel
) +
1705 (pi
->graphics_boot_level
* sizeof(SMU7_Fusion_GraphicsLevel
)) +
1706 offsetof(SMU7_Fusion_GraphicsLevel
, ClkBypassCntl
)),
1708 sizeof(u8
), pi
->sram_end
);
1714 static int kv_enable_nb_dpm(struct radeon_device
*rdev
)
1716 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1719 if (pi
->enable_nb_dpm
&& !pi
->nb_dpm_enabled
) {
1720 ret
= kv_notify_message_to_smu(rdev
, PPSMC_MSG_NBDPM_Enable
);
1722 pi
->nb_dpm_enabled
= true;
1728 int kv_dpm_force_performance_level(struct radeon_device
*rdev
,
1729 enum radeon_dpm_forced_level level
)
1733 if (level
== RADEON_DPM_FORCED_LEVEL_HIGH
) {
1734 ret
= kv_force_dpm_highest(rdev
);
1737 } else if (level
== RADEON_DPM_FORCED_LEVEL_LOW
) {
1738 ret
= kv_force_dpm_lowest(rdev
);
1741 } else if (level
== RADEON_DPM_FORCED_LEVEL_AUTO
) {
1742 ret
= kv_unforce_levels(rdev
);
1747 rdev
->pm
.dpm
.forced_level
= level
;
1752 int kv_dpm_pre_set_power_state(struct radeon_device
*rdev
)
1754 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1755 struct radeon_ps requested_ps
= *rdev
->pm
.dpm
.requested_ps
;
1756 struct radeon_ps
*new_ps
= &requested_ps
;
1758 kv_update_requested_ps(rdev
, new_ps
);
1760 kv_apply_state_adjust_rules(rdev
,
1767 int kv_dpm_set_power_state(struct radeon_device
*rdev
)
1769 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1770 struct radeon_ps
*new_ps
= &pi
->requested_rps
;
1771 /*struct radeon_ps *old_ps = &pi->current_rps;*/
1774 if (pi
->bapm_enable
) {
1775 ret
= kv_smc_bapm_enable(rdev
, rdev
->pm
.dpm
.ac_power
);
1777 DRM_ERROR("kv_smc_bapm_enable failed\n");
1782 if (rdev
->family
== CHIP_KABINI
) {
1783 if (pi
->enable_dpm
) {
1784 kv_set_valid_clock_range(rdev
, new_ps
);
1785 kv_update_dfs_bypass_settings(rdev
, new_ps
);
1786 ret
= kv_calculate_ds_divider(rdev
);
1788 DRM_ERROR("kv_calculate_ds_divider failed\n");
1791 kv_calculate_nbps_level_settings(rdev
);
1792 kv_calculate_dpm_settings(rdev
);
1793 kv_force_lowest_valid(rdev
);
1794 kv_enable_new_levels(rdev
);
1795 kv_upload_dpm_settings(rdev
);
1796 kv_program_nbps_index_settings(rdev
, new_ps
);
1797 kv_unforce_levels(rdev
);
1798 kv_set_enabled_levels(rdev
);
1799 kv_force_lowest_valid(rdev
);
1800 kv_unforce_levels(rdev
);
1802 ret
= kv_update_vce_dpm(rdev
, new_ps
, old_ps
);
1804 DRM_ERROR("kv_update_vce_dpm failed\n");
1808 kv_update_sclk_t(rdev
);
1811 if (pi
->enable_dpm
) {
1812 kv_set_valid_clock_range(rdev
, new_ps
);
1813 kv_update_dfs_bypass_settings(rdev
, new_ps
);
1814 ret
= kv_calculate_ds_divider(rdev
);
1816 DRM_ERROR("kv_calculate_ds_divider failed\n");
1819 kv_calculate_nbps_level_settings(rdev
);
1820 kv_calculate_dpm_settings(rdev
);
1821 kv_freeze_sclk_dpm(rdev
, true);
1822 kv_upload_dpm_settings(rdev
);
1823 kv_program_nbps_index_settings(rdev
, new_ps
);
1824 kv_freeze_sclk_dpm(rdev
, false);
1825 kv_set_enabled_levels(rdev
);
1827 ret
= kv_update_vce_dpm(rdev
, new_ps
, old_ps
);
1829 DRM_ERROR("kv_update_vce_dpm failed\n");
1833 kv_update_acp_boot_level(rdev
);
1834 kv_update_sclk_t(rdev
);
1835 kv_enable_nb_dpm(rdev
);
1842 void kv_dpm_post_set_power_state(struct radeon_device
*rdev
)
1844 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1845 struct radeon_ps
*new_ps
= &pi
->requested_rps
;
1847 kv_update_current_ps(rdev
, new_ps
);
1850 void kv_dpm_setup_asic(struct radeon_device
*rdev
)
1852 sumo_take_smu_control(rdev
, true);
1853 kv_init_powergate_state(rdev
);
1854 kv_init_sclk_t(rdev
);
1857 void kv_dpm_reset_asic(struct radeon_device
*rdev
)
1859 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1861 if (rdev
->family
== CHIP_KABINI
) {
1862 kv_force_lowest_valid(rdev
);
1863 kv_init_graphics_levels(rdev
);
1864 kv_program_bootup_state(rdev
);
1865 kv_upload_dpm_settings(rdev
);
1866 kv_force_lowest_valid(rdev
);
1867 kv_unforce_levels(rdev
);
1869 kv_init_graphics_levels(rdev
);
1870 kv_program_bootup_state(rdev
);
1871 kv_freeze_sclk_dpm(rdev
, true);
1872 kv_upload_dpm_settings(rdev
);
1873 kv_freeze_sclk_dpm(rdev
, false);
1874 kv_set_enabled_level(rdev
, pi
->graphics_boot_level
);
1878 //XXX use sumo_dpm_display_configuration_changed
1880 static void kv_construct_max_power_limits_table(struct radeon_device
*rdev
,
1881 struct radeon_clock_and_voltage_limits
*table
)
1883 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1885 if (pi
->sys_info
.sclk_voltage_mapping_table
.num_max_dpm_entries
> 0) {
1886 int idx
= pi
->sys_info
.sclk_voltage_mapping_table
.num_max_dpm_entries
- 1;
1888 pi
->sys_info
.sclk_voltage_mapping_table
.entries
[idx
].sclk_frequency
;
1890 kv_convert_2bit_index_to_voltage(rdev
,
1891 pi
->sys_info
.sclk_voltage_mapping_table
.entries
[idx
].vid_2bit
);
1894 table
->mclk
= pi
->sys_info
.nbp_memory_clock
[0];
1897 static void kv_patch_voltage_values(struct radeon_device
*rdev
)
1900 struct radeon_uvd_clock_voltage_dependency_table
*table
=
1901 &rdev
->pm
.dpm
.dyn_state
.uvd_clock_voltage_dependency_table
;
1904 for (i
= 0; i
< table
->count
; i
++)
1905 table
->entries
[i
].v
=
1906 kv_convert_8bit_index_to_voltage(rdev
,
1907 table
->entries
[i
].v
);
1912 static void kv_construct_boot_state(struct radeon_device
*rdev
)
1914 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1916 pi
->boot_pl
.sclk
= pi
->sys_info
.bootup_sclk
;
1917 pi
->boot_pl
.vddc_index
= pi
->sys_info
.bootup_nb_voltage_index
;
1918 pi
->boot_pl
.ds_divider_index
= 0;
1919 pi
->boot_pl
.ss_divider_index
= 0;
1920 pi
->boot_pl
.allow_gnb_slow
= 1;
1921 pi
->boot_pl
.force_nbp_state
= 0;
1922 pi
->boot_pl
.display_wm
= 0;
1923 pi
->boot_pl
.vce_wm
= 0;
1926 static int kv_force_dpm_highest(struct radeon_device
*rdev
)
1931 ret
= kv_dpm_get_enable_mask(rdev
, &enable_mask
);
1935 for (i
= SMU7_MAX_LEVELS_GRAPHICS
- 1; i
> 0; i
--) {
1936 if (enable_mask
& (1 << i
))
1940 if (rdev
->family
== CHIP_KABINI
)
1941 return kv_send_msg_to_smc_with_parameter(rdev
, PPSMC_MSG_DPM_ForceState
, i
);
1943 return kv_set_enabled_level(rdev
, i
);
1946 static int kv_force_dpm_lowest(struct radeon_device
*rdev
)
1951 ret
= kv_dpm_get_enable_mask(rdev
, &enable_mask
);
1955 for (i
= 0; i
< SMU7_MAX_LEVELS_GRAPHICS
; i
++) {
1956 if (enable_mask
& (1 << i
))
1960 if (rdev
->family
== CHIP_KABINI
)
1961 return kv_send_msg_to_smc_with_parameter(rdev
, PPSMC_MSG_DPM_ForceState
, i
);
1963 return kv_set_enabled_level(rdev
, i
);
1966 static u8
kv_get_sleep_divider_id_from_clock(struct radeon_device
*rdev
,
1967 u32 sclk
, u32 min_sclk_in_sr
)
1969 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1972 u32 min
= (min_sclk_in_sr
> KV_MINIMUM_ENGINE_CLOCK
) ?
1973 min_sclk_in_sr
: KV_MINIMUM_ENGINE_CLOCK
;
1978 if (!pi
->caps_sclk_ds
)
1981 for (i
= KV_MAX_DEEPSLEEP_DIVIDER_ID
; i
> 0; i
--) {
1982 temp
= sclk
/ sumo_get_sleep_divider_from_id(i
);
1990 static int kv_get_high_voltage_limit(struct radeon_device
*rdev
, int *limit
)
1992 struct kv_power_info
*pi
= kv_get_pi(rdev
);
1993 struct radeon_clock_voltage_dependency_table
*table
=
1994 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
;
1997 if (table
&& table
->count
) {
1998 for (i
= table
->count
- 1; i
>= 0; i
--) {
1999 if (pi
->high_voltage_t
&&
2000 (kv_convert_8bit_index_to_voltage(rdev
, table
->entries
[i
].v
) <=
2001 pi
->high_voltage_t
)) {
2007 struct sumo_sclk_voltage_mapping_table
*table
=
2008 &pi
->sys_info
.sclk_voltage_mapping_table
;
2010 for (i
= table
->num_max_dpm_entries
- 1; i
>= 0; i
--) {
2011 if (pi
->high_voltage_t
&&
2012 (kv_convert_2bit_index_to_voltage(rdev
, table
->entries
[i
].vid_2bit
) <=
2013 pi
->high_voltage_t
)) {
2024 static void kv_apply_state_adjust_rules(struct radeon_device
*rdev
,
2025 struct radeon_ps
*new_rps
,
2026 struct radeon_ps
*old_rps
)
2028 struct kv_ps
*ps
= kv_get_ps(new_rps
);
2029 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2030 u32 min_sclk
= 10000; /* ??? */
2034 struct radeon_clock_voltage_dependency_table
*table
=
2035 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
;
2036 u32 stable_p_state_sclk
= 0;
2037 struct radeon_clock_and_voltage_limits
*max_limits
=
2038 &rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
;
2040 mclk
= max_limits
->mclk
;
2043 if (pi
->caps_stable_p_state
) {
2044 stable_p_state_sclk
= (max_limits
->sclk
* 75) / 100;
2046 for (i
= table
->count
- 1; i
>= 0; i
++) {
2047 if (stable_p_state_sclk
>= table
->entries
[i
].clk
) {
2048 stable_p_state_sclk
= table
->entries
[i
].clk
;
2054 stable_p_state_sclk
= table
->entries
[0].clk
;
2056 sclk
= stable_p_state_sclk
;
2059 ps
->need_dfs_bypass
= true;
2061 for (i
= 0; i
< ps
->num_levels
; i
++) {
2062 if (ps
->levels
[i
].sclk
< sclk
)
2063 ps
->levels
[i
].sclk
= sclk
;
2066 if (table
&& table
->count
) {
2067 for (i
= 0; i
< ps
->num_levels
; i
++) {
2068 if (pi
->high_voltage_t
&&
2069 (pi
->high_voltage_t
<
2070 kv_convert_8bit_index_to_voltage(rdev
, ps
->levels
[i
].vddc_index
))) {
2071 kv_get_high_voltage_limit(rdev
, &limit
);
2072 ps
->levels
[i
].sclk
= table
->entries
[limit
].clk
;
2076 struct sumo_sclk_voltage_mapping_table
*table
=
2077 &pi
->sys_info
.sclk_voltage_mapping_table
;
2079 for (i
= 0; i
< ps
->num_levels
; i
++) {
2080 if (pi
->high_voltage_t
&&
2081 (pi
->high_voltage_t
<
2082 kv_convert_8bit_index_to_voltage(rdev
, ps
->levels
[i
].vddc_index
))) {
2083 kv_get_high_voltage_limit(rdev
, &limit
);
2084 ps
->levels
[i
].sclk
= table
->entries
[limit
].sclk_frequency
;
2089 if (pi
->caps_stable_p_state
) {
2090 for (i
= 0; i
< ps
->num_levels
; i
++) {
2091 ps
->levels
[i
].sclk
= stable_p_state_sclk
;
2095 pi
->video_start
= new_rps
->dclk
|| new_rps
->vclk
;
2097 if ((new_rps
->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK
) ==
2098 ATOM_PPLIB_CLASSIFICATION_UI_BATTERY
)
2099 pi
->battery_state
= true;
2101 pi
->battery_state
= false;
2103 if (rdev
->family
== CHIP_KABINI
) {
2104 ps
->dpm0_pg_nb_ps_lo
= 0x1;
2105 ps
->dpm0_pg_nb_ps_hi
= 0x0;
2106 ps
->dpmx_nb_ps_lo
= 0x1;
2107 ps
->dpmx_nb_ps_hi
= 0x0;
2109 ps
->dpm0_pg_nb_ps_lo
= 0x3;
2110 ps
->dpm0_pg_nb_ps_hi
= 0x0;
2111 ps
->dpmx_nb_ps_lo
= 0x3;
2112 ps
->dpmx_nb_ps_hi
= 0x0;
2114 if (pi
->sys_info
.nb_dpm_enable
) {
2115 force_high
= (mclk
>= pi
->sys_info
.nbp_memory_clock
[3]) ||
2116 pi
->video_start
|| (rdev
->pm
.dpm
.new_active_crtc_count
>= 3) ||
2117 pi
->disable_nb_ps3_in_battery
;
2118 ps
->dpm0_pg_nb_ps_lo
= force_high
? 0x2 : 0x3;
2119 ps
->dpm0_pg_nb_ps_hi
= 0x2;
2120 ps
->dpmx_nb_ps_lo
= force_high
? 0x2 : 0x3;
2121 ps
->dpmx_nb_ps_hi
= 0x2;
2126 static void kv_dpm_power_level_enabled_for_throttle(struct radeon_device
*rdev
,
2127 u32 index
, bool enable
)
2129 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2131 pi
->graphics_level
[index
].EnabledForThrottle
= enable
? 1 : 0;
2134 static int kv_calculate_ds_divider(struct radeon_device
*rdev
)
2136 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2137 u32 sclk_in_sr
= 10000; /* ??? */
2140 if (pi
->lowest_valid
> pi
->highest_valid
)
2143 for (i
= pi
->lowest_valid
; i
<= pi
->highest_valid
; i
++) {
2144 pi
->graphics_level
[i
].DeepSleepDivId
=
2145 kv_get_sleep_divider_id_from_clock(rdev
,
2146 be32_to_cpu(pi
->graphics_level
[i
].SclkFrequency
),
2152 static int kv_calculate_nbps_level_settings(struct radeon_device
*rdev
)
2154 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2157 struct radeon_clock_and_voltage_limits
*max_limits
=
2158 &rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
;
2159 u32 mclk
= max_limits
->mclk
;
2161 if (pi
->lowest_valid
> pi
->highest_valid
)
2164 if (rdev
->family
== CHIP_KABINI
) {
2165 for (i
= pi
->lowest_valid
; i
<= pi
->highest_valid
; i
++) {
2166 pi
->graphics_level
[i
].GnbSlow
= 1;
2167 pi
->graphics_level
[i
].ForceNbPs1
= 0;
2168 pi
->graphics_level
[i
].UpH
= 0;
2171 if (!pi
->sys_info
.nb_dpm_enable
)
2174 force_high
= ((mclk
>= pi
->sys_info
.nbp_memory_clock
[3]) ||
2175 (rdev
->pm
.dpm
.new_active_crtc_count
>= 3) || pi
->video_start
);
2178 for (i
= pi
->lowest_valid
; i
<= pi
->highest_valid
; i
++)
2179 pi
->graphics_level
[i
].GnbSlow
= 0;
2181 if (pi
->battery_state
)
2182 pi
->graphics_level
[0].ForceNbPs1
= 1;
2184 pi
->graphics_level
[1].GnbSlow
= 0;
2185 pi
->graphics_level
[2].GnbSlow
= 0;
2186 pi
->graphics_level
[3].GnbSlow
= 0;
2187 pi
->graphics_level
[4].GnbSlow
= 0;
2190 for (i
= pi
->lowest_valid
; i
<= pi
->highest_valid
; i
++) {
2191 pi
->graphics_level
[i
].GnbSlow
= 1;
2192 pi
->graphics_level
[i
].ForceNbPs1
= 0;
2193 pi
->graphics_level
[i
].UpH
= 0;
2196 if (pi
->sys_info
.nb_dpm_enable
&& pi
->battery_state
) {
2197 pi
->graphics_level
[pi
->lowest_valid
].UpH
= 0x28;
2198 pi
->graphics_level
[pi
->lowest_valid
].GnbSlow
= 0;
2199 if (pi
->lowest_valid
!= pi
->highest_valid
)
2200 pi
->graphics_level
[pi
->lowest_valid
].ForceNbPs1
= 1;
2206 static int kv_calculate_dpm_settings(struct radeon_device
*rdev
)
2208 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2211 if (pi
->lowest_valid
> pi
->highest_valid
)
2214 for (i
= pi
->lowest_valid
; i
<= pi
->highest_valid
; i
++)
2215 pi
->graphics_level
[i
].DisplayWatermark
= (i
== pi
->highest_valid
) ? 1 : 0;
2220 static void kv_init_graphics_levels(struct radeon_device
*rdev
)
2222 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2224 struct radeon_clock_voltage_dependency_table
*table
=
2225 &rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
;
2227 if (table
&& table
->count
) {
2230 pi
->graphics_dpm_level_count
= 0;
2231 for (i
= 0; i
< table
->count
; i
++) {
2232 if (pi
->high_voltage_t
&&
2233 (pi
->high_voltage_t
<
2234 kv_convert_8bit_index_to_voltage(rdev
, table
->entries
[i
].v
)))
2237 kv_set_divider_value(rdev
, i
, table
->entries
[i
].clk
);
2238 vid_2bit
= sumo_convert_vid7_to_vid2(rdev
,
2239 &pi
->sys_info
.vid_mapping_table
,
2240 table
->entries
[i
].v
);
2241 kv_set_vid(rdev
, i
, vid_2bit
);
2242 kv_set_at(rdev
, i
, pi
->at
[i
]);
2243 kv_dpm_power_level_enabled_for_throttle(rdev
, i
, true);
2244 pi
->graphics_dpm_level_count
++;
2247 struct sumo_sclk_voltage_mapping_table
*table
=
2248 &pi
->sys_info
.sclk_voltage_mapping_table
;
2250 pi
->graphics_dpm_level_count
= 0;
2251 for (i
= 0; i
< table
->num_max_dpm_entries
; i
++) {
2252 if (pi
->high_voltage_t
&&
2253 pi
->high_voltage_t
<
2254 kv_convert_2bit_index_to_voltage(rdev
, table
->entries
[i
].vid_2bit
))
2257 kv_set_divider_value(rdev
, i
, table
->entries
[i
].sclk_frequency
);
2258 kv_set_vid(rdev
, i
, table
->entries
[i
].vid_2bit
);
2259 kv_set_at(rdev
, i
, pi
->at
[i
]);
2260 kv_dpm_power_level_enabled_for_throttle(rdev
, i
, true);
2261 pi
->graphics_dpm_level_count
++;
2265 for (i
= 0; i
< SMU7_MAX_LEVELS_GRAPHICS
; i
++)
2266 kv_dpm_power_level_enable(rdev
, i
, false);
2269 static void kv_enable_new_levels(struct radeon_device
*rdev
)
2271 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2274 for (i
= 0; i
< SMU7_MAX_LEVELS_GRAPHICS
; i
++) {
2275 if (i
>= pi
->lowest_valid
&& i
<= pi
->highest_valid
)
2276 kv_dpm_power_level_enable(rdev
, i
, true);
2280 static int kv_set_enabled_level(struct radeon_device
*rdev
, u32 level
)
2282 u32 new_mask
= (1 << level
);
2284 return kv_send_msg_to_smc_with_parameter(rdev
,
2285 PPSMC_MSG_SCLKDPM_SetEnabledMask
,
2289 static int kv_set_enabled_levels(struct radeon_device
*rdev
)
2291 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2292 u32 i
, new_mask
= 0;
2294 for (i
= pi
->lowest_valid
; i
<= pi
->highest_valid
; i
++)
2295 new_mask
|= (1 << i
);
2297 return kv_send_msg_to_smc_with_parameter(rdev
,
2298 PPSMC_MSG_SCLKDPM_SetEnabledMask
,
2302 static void kv_program_nbps_index_settings(struct radeon_device
*rdev
,
2303 struct radeon_ps
*new_rps
)
2305 struct kv_ps
*new_ps
= kv_get_ps(new_rps
);
2306 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2309 if (rdev
->family
== CHIP_KABINI
)
2312 if (pi
->sys_info
.nb_dpm_enable
) {
2313 nbdpmconfig1
= RREG32_SMC(NB_DPM_CONFIG_1
);
2314 nbdpmconfig1
&= ~(Dpm0PgNbPsLo_MASK
| Dpm0PgNbPsHi_MASK
|
2315 DpmXNbPsLo_MASK
| DpmXNbPsHi_MASK
);
2316 nbdpmconfig1
|= (Dpm0PgNbPsLo(new_ps
->dpm0_pg_nb_ps_lo
) |
2317 Dpm0PgNbPsHi(new_ps
->dpm0_pg_nb_ps_hi
) |
2318 DpmXNbPsLo(new_ps
->dpmx_nb_ps_lo
) |
2319 DpmXNbPsHi(new_ps
->dpmx_nb_ps_hi
));
2320 WREG32_SMC(NB_DPM_CONFIG_1
, nbdpmconfig1
);
2324 static int kv_set_thermal_temperature_range(struct radeon_device
*rdev
,
2325 int min_temp
, int max_temp
)
2327 int low_temp
= 0 * 1000;
2328 int high_temp
= 255 * 1000;
2331 if (low_temp
< min_temp
)
2332 low_temp
= min_temp
;
2333 if (high_temp
> max_temp
)
2334 high_temp
= max_temp
;
2335 if (high_temp
< low_temp
) {
2336 DRM_ERROR("invalid thermal range: %d - %d\n", low_temp
, high_temp
);
2340 tmp
= RREG32_SMC(CG_THERMAL_INT_CTRL
);
2341 tmp
&= ~(DIG_THERM_INTH_MASK
| DIG_THERM_INTL_MASK
);
2342 tmp
|= (DIG_THERM_INTH(49 + (high_temp
/ 1000)) |
2343 DIG_THERM_INTL(49 + (low_temp
/ 1000)));
2344 WREG32_SMC(CG_THERMAL_INT_CTRL
, tmp
);
2346 rdev
->pm
.dpm
.thermal
.min_temp
= low_temp
;
2347 rdev
->pm
.dpm
.thermal
.max_temp
= high_temp
;
2353 struct _ATOM_INTEGRATED_SYSTEM_INFO info
;
2354 struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2
;
2355 struct _ATOM_INTEGRATED_SYSTEM_INFO_V5 info_5
;
2356 struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 info_6
;
2357 struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_7 info_7
;
2358 struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_8 info_8
;
2361 static int kv_parse_sys_info_table(struct radeon_device
*rdev
)
2363 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2364 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
2365 int index
= GetIndexIntoMasterTable(DATA
, IntegratedSystemInfo
);
2366 union igp_info
*igp_info
;
2371 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
2372 &frev
, &crev
, &data_offset
)) {
2373 igp_info
= (union igp_info
*)(mode_info
->atom_context
->bios
+
2377 DRM_ERROR("Unsupported IGP table: %d %d\n", frev
, crev
);
2380 pi
->sys_info
.bootup_sclk
= le32_to_cpu(igp_info
->info_8
.ulBootUpEngineClock
);
2381 pi
->sys_info
.bootup_uma_clk
= le32_to_cpu(igp_info
->info_8
.ulBootUpUMAClock
);
2382 pi
->sys_info
.bootup_nb_voltage_index
=
2383 le16_to_cpu(igp_info
->info_8
.usBootUpNBVoltage
);
2384 if (igp_info
->info_8
.ucHtcTmpLmt
== 0)
2385 pi
->sys_info
.htc_tmp_lmt
= 203;
2387 pi
->sys_info
.htc_tmp_lmt
= igp_info
->info_8
.ucHtcTmpLmt
;
2388 if (igp_info
->info_8
.ucHtcHystLmt
== 0)
2389 pi
->sys_info
.htc_hyst_lmt
= 5;
2391 pi
->sys_info
.htc_hyst_lmt
= igp_info
->info_8
.ucHtcHystLmt
;
2392 if (pi
->sys_info
.htc_tmp_lmt
<= pi
->sys_info
.htc_hyst_lmt
) {
2393 DRM_ERROR("The htcTmpLmt should be larger than htcHystLmt.\n");
2396 if (le32_to_cpu(igp_info
->info_8
.ulSystemConfig
) & (1 << 3))
2397 pi
->sys_info
.nb_dpm_enable
= true;
2399 pi
->sys_info
.nb_dpm_enable
= false;
2401 for (i
= 0; i
< KV_NUM_NBPSTATES
; i
++) {
2402 pi
->sys_info
.nbp_memory_clock
[i
] =
2403 le32_to_cpu(igp_info
->info_8
.ulNbpStateMemclkFreq
[i
]);
2404 pi
->sys_info
.nbp_n_clock
[i
] =
2405 le32_to_cpu(igp_info
->info_8
.ulNbpStateNClkFreq
[i
]);
2407 if (le32_to_cpu(igp_info
->info_8
.ulGPUCapInfo
) &
2408 SYS_INFO_GPUCAPS__ENABEL_DFS_BYPASS
)
2409 pi
->caps_enable_dfs_bypass
= true;
2411 sumo_construct_sclk_voltage_mapping_table(rdev
,
2412 &pi
->sys_info
.sclk_voltage_mapping_table
,
2413 igp_info
->info_8
.sAvail_SCLK
);
2415 sumo_construct_vid_mapping_table(rdev
,
2416 &pi
->sys_info
.vid_mapping_table
,
2417 igp_info
->info_8
.sAvail_SCLK
);
2419 kv_construct_max_power_limits_table(rdev
,
2420 &rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
);
2426 struct _ATOM_POWERPLAY_INFO info
;
2427 struct _ATOM_POWERPLAY_INFO_V2 info_2
;
2428 struct _ATOM_POWERPLAY_INFO_V3 info_3
;
2429 struct _ATOM_PPLIB_POWERPLAYTABLE pplib
;
2430 struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2
;
2431 struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3
;
2434 union pplib_clock_info
{
2435 struct _ATOM_PPLIB_R600_CLOCK_INFO r600
;
2436 struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780
;
2437 struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen
;
2438 struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo
;
2441 union pplib_power_state
{
2442 struct _ATOM_PPLIB_STATE v1
;
2443 struct _ATOM_PPLIB_STATE_V2 v2
;
2446 static void kv_patch_boot_state(struct radeon_device
*rdev
,
2449 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2452 ps
->levels
[0] = pi
->boot_pl
;
2455 static void kv_parse_pplib_non_clock_info(struct radeon_device
*rdev
,
2456 struct radeon_ps
*rps
,
2457 struct _ATOM_PPLIB_NONCLOCK_INFO
*non_clock_info
,
2460 struct kv_ps
*ps
= kv_get_ps(rps
);
2462 rps
->caps
= le32_to_cpu(non_clock_info
->ulCapsAndSettings
);
2463 rps
->class = le16_to_cpu(non_clock_info
->usClassification
);
2464 rps
->class2
= le16_to_cpu(non_clock_info
->usClassification2
);
2466 if (ATOM_PPLIB_NONCLOCKINFO_VER1
< table_rev
) {
2467 rps
->vclk
= le32_to_cpu(non_clock_info
->ulVCLK
);
2468 rps
->dclk
= le32_to_cpu(non_clock_info
->ulDCLK
);
2474 if (rps
->class & ATOM_PPLIB_CLASSIFICATION_BOOT
) {
2475 rdev
->pm
.dpm
.boot_ps
= rps
;
2476 kv_patch_boot_state(rdev
, ps
);
2478 if (rps
->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE
)
2479 rdev
->pm
.dpm
.uvd_ps
= rps
;
2482 static void kv_parse_pplib_clock_info(struct radeon_device
*rdev
,
2483 struct radeon_ps
*rps
, int index
,
2484 union pplib_clock_info
*clock_info
)
2486 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2487 struct kv_ps
*ps
= kv_get_ps(rps
);
2488 struct kv_pl
*pl
= &ps
->levels
[index
];
2491 sclk
= le16_to_cpu(clock_info
->sumo
.usEngineClockLow
);
2492 sclk
|= clock_info
->sumo
.ucEngineClockHigh
<< 16;
2494 pl
->vddc_index
= clock_info
->sumo
.vddcIndex
;
2496 ps
->num_levels
= index
+ 1;
2498 if (pi
->caps_sclk_ds
) {
2499 pl
->ds_divider_index
= 5;
2500 pl
->ss_divider_index
= 5;
2504 static int kv_parse_power_table(struct radeon_device
*rdev
)
2506 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
2507 struct _ATOM_PPLIB_NONCLOCK_INFO
*non_clock_info
;
2508 union pplib_power_state
*power_state
;
2509 int i
, j
, k
, non_clock_array_index
, clock_array_index
;
2510 union pplib_clock_info
*clock_info
;
2511 struct _StateArray
*state_array
;
2512 struct _ClockInfoArray
*clock_info_array
;
2513 struct _NonClockInfoArray
*non_clock_info_array
;
2514 union power_info
*power_info
;
2515 int index
= GetIndexIntoMasterTable(DATA
, PowerPlayInfo
);
2518 u8
*power_state_offset
;
2521 if (!atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
2522 &frev
, &crev
, &data_offset
))
2524 power_info
= (union power_info
*)(mode_info
->atom_context
->bios
+ data_offset
);
2526 state_array
= (struct _StateArray
*)
2527 (mode_info
->atom_context
->bios
+ data_offset
+
2528 le16_to_cpu(power_info
->pplib
.usStateArrayOffset
));
2529 clock_info_array
= (struct _ClockInfoArray
*)
2530 (mode_info
->atom_context
->bios
+ data_offset
+
2531 le16_to_cpu(power_info
->pplib
.usClockInfoArrayOffset
));
2532 non_clock_info_array
= (struct _NonClockInfoArray
*)
2533 (mode_info
->atom_context
->bios
+ data_offset
+
2534 le16_to_cpu(power_info
->pplib
.usNonClockInfoArrayOffset
));
2536 rdev
->pm
.dpm
.ps
= kzalloc(sizeof(struct radeon_ps
) *
2537 state_array
->ucNumEntries
, GFP_KERNEL
);
2538 if (!rdev
->pm
.dpm
.ps
)
2540 power_state_offset
= (u8
*)state_array
->states
;
2541 rdev
->pm
.dpm
.platform_caps
= le32_to_cpu(power_info
->pplib
.ulPlatformCaps
);
2542 rdev
->pm
.dpm
.backbias_response_time
= le16_to_cpu(power_info
->pplib
.usBackbiasTime
);
2543 rdev
->pm
.dpm
.voltage_response_time
= le16_to_cpu(power_info
->pplib
.usVoltageTime
);
2544 for (i
= 0; i
< state_array
->ucNumEntries
; i
++) {
2546 power_state
= (union pplib_power_state
*)power_state_offset
;
2547 non_clock_array_index
= power_state
->v2
.nonClockInfoIndex
;
2548 non_clock_info
= (struct _ATOM_PPLIB_NONCLOCK_INFO
*)
2549 &non_clock_info_array
->nonClockInfo
[non_clock_array_index
];
2550 if (!rdev
->pm
.power_state
[i
].clock_info
)
2552 ps
= kzalloc(sizeof(struct kv_ps
), GFP_KERNEL
);
2554 kfree(rdev
->pm
.dpm
.ps
);
2557 rdev
->pm
.dpm
.ps
[i
].ps_priv
= ps
;
2559 idx
= (u8
*)&power_state
->v2
.clockInfoIndex
[0];
2560 for (j
= 0; j
< power_state
->v2
.ucNumDPMLevels
; j
++) {
2561 clock_array_index
= idx
[j
];
2562 if (clock_array_index
>= clock_info_array
->ucNumEntries
)
2564 if (k
>= SUMO_MAX_HARDWARE_POWERLEVELS
)
2566 clock_info
= (union pplib_clock_info
*)
2567 ((u8
*)&clock_info_array
->clockInfo
[0] +
2568 (clock_array_index
* clock_info_array
->ucEntrySize
));
2569 kv_parse_pplib_clock_info(rdev
,
2570 &rdev
->pm
.dpm
.ps
[i
], k
,
2574 kv_parse_pplib_non_clock_info(rdev
, &rdev
->pm
.dpm
.ps
[i
],
2576 non_clock_info_array
->ucEntrySize
);
2577 power_state_offset
+= 2 + power_state
->v2
.ucNumDPMLevels
;
2579 rdev
->pm
.dpm
.num_ps
= state_array
->ucNumEntries
;
2583 int kv_dpm_init(struct radeon_device
*rdev
)
2585 struct kv_power_info
*pi
;
2588 pi
= kzalloc(sizeof(struct kv_power_info
), GFP_KERNEL
);
2591 rdev
->pm
.dpm
.priv
= pi
;
2593 ret
= r600_parse_extended_power_table(rdev
);
2597 for (i
= 0; i
< SUMO_MAX_HARDWARE_POWERLEVELS
; i
++)
2598 pi
->at
[i
] = TRINITY_AT_DFLT
;
2600 pi
->sram_end
= SMC_RAM_END
;
2602 if (rdev
->family
== CHIP_KABINI
)
2603 pi
->high_voltage_t
= 4001;
2605 pi
->enable_nb_dpm
= true;
2607 pi
->caps_power_containment
= true;
2608 pi
->caps_cac
= true;
2609 pi
->enable_didt
= false;
2610 if (pi
->enable_didt
) {
2611 pi
->caps_sq_ramping
= true;
2612 pi
->caps_db_ramping
= true;
2613 pi
->caps_td_ramping
= true;
2614 pi
->caps_tcp_ramping
= true;
2617 pi
->caps_sclk_ds
= true;
2618 pi
->enable_auto_thermal_throttling
= true;
2619 pi
->disable_nb_ps3_in_battery
= false;
2620 pi
->bapm_enable
= false;
2621 pi
->voltage_drop_t
= 0;
2622 pi
->caps_sclk_throttle_low_notification
= false;
2623 pi
->caps_fps
= false; /* true? */
2624 pi
->caps_uvd_pg
= true;
2625 pi
->caps_uvd_dpm
= true;
2626 pi
->caps_vce_pg
= false;
2627 pi
->caps_samu_pg
= false;
2628 pi
->caps_acp_pg
= false;
2629 pi
->caps_stable_p_state
= false;
2631 ret
= kv_parse_sys_info_table(rdev
);
2635 kv_patch_voltage_values(rdev
);
2636 kv_construct_boot_state(rdev
);
2638 ret
= kv_parse_power_table(rdev
);
2642 pi
->enable_dpm
= true;
2647 void kv_dpm_debugfs_print_current_performance_level(struct radeon_device
*rdev
,
2650 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2652 (RREG32_SMC(TARGET_AND_CURRENT_PROFILE_INDEX
) & CURR_SCLK_INDEX_MASK
) >>
2653 CURR_SCLK_INDEX_SHIFT
;
2657 if (current_index
>= SMU__NUM_SCLK_DPM_STATE
) {
2658 seq_printf(m
, "invalid dpm profile %d\n", current_index
);
2660 sclk
= be32_to_cpu(pi
->graphics_level
[current_index
].SclkFrequency
);
2661 tmp
= (RREG32_SMC(SMU_VOLTAGE_STATUS
) & SMU_VOLTAGE_CURRENT_LEVEL_MASK
) >>
2662 SMU_VOLTAGE_CURRENT_LEVEL_SHIFT
;
2663 vddc
= kv_convert_8bit_index_to_voltage(rdev
, (u16
)tmp
);
2664 seq_printf(m
, "power level %d sclk: %u vddc: %u\n",
2665 current_index
, sclk
, vddc
);
2669 void kv_dpm_print_power_state(struct radeon_device
*rdev
,
2670 struct radeon_ps
*rps
)
2673 struct kv_ps
*ps
= kv_get_ps(rps
);
2675 r600_dpm_print_class_info(rps
->class, rps
->class2
);
2676 r600_dpm_print_cap_info(rps
->caps
);
2677 printk("\tuvd vclk: %d dclk: %d\n", rps
->vclk
, rps
->dclk
);
2678 for (i
= 0; i
< ps
->num_levels
; i
++) {
2679 struct kv_pl
*pl
= &ps
->levels
[i
];
2680 printk("\t\tpower level %d sclk: %u vddc: %u\n",
2682 kv_convert_8bit_index_to_voltage(rdev
, pl
->vddc_index
));
2684 r600_dpm_print_ps_status(rdev
, rps
);
2687 void kv_dpm_fini(struct radeon_device
*rdev
)
2691 for (i
= 0; i
< rdev
->pm
.dpm
.num_ps
; i
++) {
2692 kfree(rdev
->pm
.dpm
.ps
[i
].ps_priv
);
2694 kfree(rdev
->pm
.dpm
.ps
);
2695 kfree(rdev
->pm
.dpm
.priv
);
2696 r600_free_extended_power_table(rdev
);
2699 void kv_dpm_display_configuration_changed(struct radeon_device
*rdev
)
2704 u32
kv_dpm_get_sclk(struct radeon_device
*rdev
, bool low
)
2706 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2707 struct kv_ps
*requested_state
= kv_get_ps(&pi
->requested_rps
);
2710 return requested_state
->levels
[0].sclk
;
2712 return requested_state
->levels
[requested_state
->num_levels
- 1].sclk
;
2715 u32
kv_dpm_get_mclk(struct radeon_device
*rdev
, bool low
)
2717 struct kv_power_info
*pi
= kv_get_pi(rdev
);
2719 return pi
->sys_info
.bootup_uma_clk
;