2 * Copyright 2011 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.
22 * Authors: Alex Deucher
27 #include "radeon_asic.h"
32 const u32 r600_utc
[R600_PM_NUMBER_OF_TC
] =
51 const u32 r600_dtc
[R600_PM_NUMBER_OF_TC
] =
70 void r600_dpm_print_class_info(u32
class, u32 class2
)
72 printk("\tui class: ");
73 switch (class & ATOM_PPLIB_CLASSIFICATION_UI_MASK
) {
74 case ATOM_PPLIB_CLASSIFICATION_UI_NONE
:
78 case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY
:
81 case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED
:
84 case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE
:
85 printk("performance\n");
88 printk("\tinternal class: ");
89 if (((class & ~ATOM_PPLIB_CLASSIFICATION_UI_MASK
) == 0) &&
93 if (class & ATOM_PPLIB_CLASSIFICATION_BOOT
)
95 if (class & ATOM_PPLIB_CLASSIFICATION_THERMAL
)
97 if (class & ATOM_PPLIB_CLASSIFICATION_LIMITEDPOWERSOURCE
)
98 printk("limited_pwr ");
99 if (class & ATOM_PPLIB_CLASSIFICATION_REST
)
101 if (class & ATOM_PPLIB_CLASSIFICATION_FORCED
)
103 if (class & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE
)
105 if (class & ATOM_PPLIB_CLASSIFICATION_OVERDRIVETEMPLATE
)
107 if (class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE
)
109 if (class & ATOM_PPLIB_CLASSIFICATION_3DLOW
)
111 if (class & ATOM_PPLIB_CLASSIFICATION_ACPI
)
113 if (class & ATOM_PPLIB_CLASSIFICATION_HD2STATE
)
115 if (class & ATOM_PPLIB_CLASSIFICATION_HDSTATE
)
117 if (class & ATOM_PPLIB_CLASSIFICATION_SDSTATE
)
119 if (class2
& ATOM_PPLIB_CLASSIFICATION2_LIMITEDPOWERSOURCE_2
)
120 printk("limited_pwr2 ");
121 if (class2
& ATOM_PPLIB_CLASSIFICATION2_ULV
)
123 if (class2
& ATOM_PPLIB_CLASSIFICATION2_MVC
)
129 void r600_dpm_print_cap_info(u32 caps
)
132 if (caps
& ATOM_PPLIB_SINGLE_DISPLAY_ONLY
)
133 printk("single_disp ");
134 if (caps
& ATOM_PPLIB_SUPPORTS_VIDEO_PLAYBACK
)
136 if (caps
& ATOM_PPLIB_DISALLOW_ON_DC
)
141 void r600_dpm_print_ps_status(struct radeon_device
*rdev
,
142 struct radeon_ps
*rps
)
144 printk("\tstatus: ");
145 if (rps
== rdev
->pm
.dpm
.current_ps
)
147 if (rps
== rdev
->pm
.dpm
.requested_ps
)
149 if (rps
== rdev
->pm
.dpm
.boot_ps
)
154 u32
r600_dpm_get_vblank_time(struct radeon_device
*rdev
)
156 struct drm_device
*dev
= rdev
->ddev
;
157 struct drm_crtc
*crtc
;
158 struct radeon_crtc
*radeon_crtc
;
159 u32 line_time_us
, vblank_lines
;
160 u32 vblank_time_us
= 0xffffffff; /* if the displays are off, vblank time is max */
162 if (rdev
->num_crtc
&& rdev
->mode_info
.mode_config_initialized
) {
163 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
164 radeon_crtc
= to_radeon_crtc(crtc
);
165 if (crtc
->enabled
&& radeon_crtc
->enabled
&& radeon_crtc
->hw_mode
.clock
) {
166 line_time_us
= (radeon_crtc
->hw_mode
.crtc_htotal
* 1000) /
167 radeon_crtc
->hw_mode
.clock
;
168 vblank_lines
= radeon_crtc
->hw_mode
.crtc_vblank_end
-
169 radeon_crtc
->hw_mode
.crtc_vdisplay
+
170 (radeon_crtc
->v_border
* 2);
171 vblank_time_us
= vblank_lines
* line_time_us
;
177 return vblank_time_us
;
180 u32
r600_dpm_get_vrefresh(struct radeon_device
*rdev
)
182 struct drm_device
*dev
= rdev
->ddev
;
183 struct drm_crtc
*crtc
;
184 struct radeon_crtc
*radeon_crtc
;
187 if (rdev
->num_crtc
&& rdev
->mode_info
.mode_config_initialized
) {
188 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
189 radeon_crtc
= to_radeon_crtc(crtc
);
190 if (crtc
->enabled
&& radeon_crtc
->enabled
&& radeon_crtc
->hw_mode
.clock
) {
191 vrefresh
= radeon_crtc
->hw_mode
.vrefresh
;
199 void r600_calculate_u_and_p(u32 i
, u32 r_c
, u32 p_b
,
206 i_c
= (i
* r_c
) / 100;
215 *p
= i_c
/ (1 << (2 * (*u
)));
218 int r600_calculate_at(u32 t
, u32 h
, u32 fh
, u32 fl
, u32
*tl
, u32
*th
)
223 if ((fl
== 0) || (fh
== 0) || (fl
> fh
))
227 t1
= (t
* (k
- 100));
228 a
= (1000 * (100 * h
+ t1
)) / (10000 + (t1
/ 100));
230 ah
= ((a
* t
) + 5000) / 10000;
239 void r600_gfx_clockgating_enable(struct radeon_device
*rdev
, bool enable
)
244 WREG32_P(SCLK_PWRMGT_CNTL
, DYN_GFX_CLK_OFF_EN
, ~DYN_GFX_CLK_OFF_EN
);
246 WREG32_P(SCLK_PWRMGT_CNTL
, 0, ~DYN_GFX_CLK_OFF_EN
);
248 WREG32(CG_RLC_REQ_AND_RSP
, 0x2);
250 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
251 if (((RREG32(CG_RLC_REQ_AND_RSP
) & CG_RLC_RSP_TYPE_MASK
) >> CG_RLC_RSP_TYPE_SHIFT
) == 1)
256 WREG32(CG_RLC_REQ_AND_RSP
, 0x0);
258 WREG32(GRBM_PWR_CNTL
, 0x1);
259 RREG32(GRBM_PWR_CNTL
);
263 void r600_dynamicpm_enable(struct radeon_device
*rdev
, bool enable
)
266 WREG32_P(GENERAL_PWRMGT
, GLOBAL_PWRMGT_EN
, ~GLOBAL_PWRMGT_EN
);
268 WREG32_P(GENERAL_PWRMGT
, 0, ~GLOBAL_PWRMGT_EN
);
271 void r600_enable_thermal_protection(struct radeon_device
*rdev
, bool enable
)
274 WREG32_P(GENERAL_PWRMGT
, 0, ~THERMAL_PROTECTION_DIS
);
276 WREG32_P(GENERAL_PWRMGT
, THERMAL_PROTECTION_DIS
, ~THERMAL_PROTECTION_DIS
);
279 void r600_enable_acpi_pm(struct radeon_device
*rdev
)
281 WREG32_P(GENERAL_PWRMGT
, STATIC_PM_EN
, ~STATIC_PM_EN
);
284 void r600_enable_dynamic_pcie_gen2(struct radeon_device
*rdev
, bool enable
)
287 WREG32_P(GENERAL_PWRMGT
, ENABLE_GEN2PCIE
, ~ENABLE_GEN2PCIE
);
289 WREG32_P(GENERAL_PWRMGT
, 0, ~ENABLE_GEN2PCIE
);
292 bool r600_dynamicpm_enabled(struct radeon_device
*rdev
)
294 if (RREG32(GENERAL_PWRMGT
) & GLOBAL_PWRMGT_EN
)
300 void r600_enable_sclk_control(struct radeon_device
*rdev
, bool enable
)
303 WREG32_P(SCLK_PWRMGT_CNTL
, 0, ~SCLK_PWRMGT_OFF
);
305 WREG32_P(SCLK_PWRMGT_CNTL
, SCLK_PWRMGT_OFF
, ~SCLK_PWRMGT_OFF
);
308 void r600_enable_mclk_control(struct radeon_device
*rdev
, bool enable
)
311 WREG32_P(MCLK_PWRMGT_CNTL
, 0, ~MPLL_PWRMGT_OFF
);
313 WREG32_P(MCLK_PWRMGT_CNTL
, MPLL_PWRMGT_OFF
, ~MPLL_PWRMGT_OFF
);
316 void r600_enable_spll_bypass(struct radeon_device
*rdev
, bool enable
)
319 WREG32_P(CG_SPLL_FUNC_CNTL
, SPLL_BYPASS_EN
, ~SPLL_BYPASS_EN
);
321 WREG32_P(CG_SPLL_FUNC_CNTL
, 0, ~SPLL_BYPASS_EN
);
324 void r600_wait_for_spll_change(struct radeon_device
*rdev
)
328 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
329 if (RREG32(CG_SPLL_FUNC_CNTL
) & SPLL_CHG_STATUS
)
335 void r600_set_bsp(struct radeon_device
*rdev
, u32 u
, u32 p
)
337 WREG32(CG_BSP
, BSP(p
) | BSU(u
));
340 void r600_set_at(struct radeon_device
*rdev
,
341 u32 l_to_m
, u32 m_to_h
,
342 u32 h_to_m
, u32 m_to_l
)
344 WREG32(CG_RT
, FLS(l_to_m
) | FMS(m_to_h
));
345 WREG32(CG_LT
, FHS(h_to_m
) | FMS(m_to_l
));
348 void r600_set_tc(struct radeon_device
*rdev
,
349 u32 index
, u32 u_t
, u32 d_t
)
351 WREG32(CG_FFCT_0
+ (index
* 4), UTC_0(u_t
) | DTC_0(d_t
));
354 void r600_select_td(struct radeon_device
*rdev
,
357 if (td
== R600_TD_AUTO
)
358 WREG32_P(SCLK_PWRMGT_CNTL
, 0, ~FIR_FORCE_TREND_SEL
);
360 WREG32_P(SCLK_PWRMGT_CNTL
, FIR_FORCE_TREND_SEL
, ~FIR_FORCE_TREND_SEL
);
361 if (td
== R600_TD_UP
)
362 WREG32_P(SCLK_PWRMGT_CNTL
, 0, ~FIR_TREND_MODE
);
363 if (td
== R600_TD_DOWN
)
364 WREG32_P(SCLK_PWRMGT_CNTL
, FIR_TREND_MODE
, ~FIR_TREND_MODE
);
367 void r600_set_vrc(struct radeon_device
*rdev
, u32 vrv
)
372 void r600_set_tpu(struct radeon_device
*rdev
, u32 u
)
374 WREG32_P(CG_TPC
, TPU(u
), ~TPU_MASK
);
377 void r600_set_tpc(struct radeon_device
*rdev
, u32 c
)
379 WREG32_P(CG_TPC
, TPCC(c
), ~TPCC_MASK
);
382 void r600_set_sstu(struct radeon_device
*rdev
, u32 u
)
384 WREG32_P(CG_SSP
, CG_SSTU(u
), ~CG_SSTU_MASK
);
387 void r600_set_sst(struct radeon_device
*rdev
, u32 t
)
389 WREG32_P(CG_SSP
, CG_SST(t
), ~CG_SST_MASK
);
392 void r600_set_git(struct radeon_device
*rdev
, u32 t
)
394 WREG32_P(CG_GIT
, CG_GICST(t
), ~CG_GICST_MASK
);
397 void r600_set_fctu(struct radeon_device
*rdev
, u32 u
)
399 WREG32_P(CG_FC_T
, FC_TU(u
), ~FC_TU_MASK
);
402 void r600_set_fct(struct radeon_device
*rdev
, u32 t
)
404 WREG32_P(CG_FC_T
, FC_T(t
), ~FC_T_MASK
);
407 void r600_set_ctxcgtt3d_rphc(struct radeon_device
*rdev
, u32 p
)
409 WREG32_P(CG_CTX_CGTT3D_R
, PHC(p
), ~PHC_MASK
);
412 void r600_set_ctxcgtt3d_rsdc(struct radeon_device
*rdev
, u32 s
)
414 WREG32_P(CG_CTX_CGTT3D_R
, SDC(s
), ~SDC_MASK
);
417 void r600_set_vddc3d_oorsu(struct radeon_device
*rdev
, u32 u
)
419 WREG32_P(CG_VDDC3D_OOR
, SU(u
), ~SU_MASK
);
422 void r600_set_vddc3d_oorphc(struct radeon_device
*rdev
, u32 p
)
424 WREG32_P(CG_VDDC3D_OOR
, PHC(p
), ~PHC_MASK
);
427 void r600_set_vddc3d_oorsdc(struct radeon_device
*rdev
, u32 s
)
429 WREG32_P(CG_VDDC3D_OOR
, SDC(s
), ~SDC_MASK
);
432 void r600_set_mpll_lock_time(struct radeon_device
*rdev
, u32 lock_time
)
434 WREG32_P(MPLL_TIME
, MPLL_LOCK_TIME(lock_time
), ~MPLL_LOCK_TIME_MASK
);
437 void r600_set_mpll_reset_time(struct radeon_device
*rdev
, u32 reset_time
)
439 WREG32_P(MPLL_TIME
, MPLL_RESET_TIME(reset_time
), ~MPLL_RESET_TIME_MASK
);
442 void r600_engine_clock_entry_enable(struct radeon_device
*rdev
,
443 u32 index
, bool enable
)
446 WREG32_P(SCLK_FREQ_SETTING_STEP_0_PART2
+ (index
* 4 * 2),
447 STEP_0_SPLL_ENTRY_VALID
, ~STEP_0_SPLL_ENTRY_VALID
);
449 WREG32_P(SCLK_FREQ_SETTING_STEP_0_PART2
+ (index
* 4 * 2),
450 0, ~STEP_0_SPLL_ENTRY_VALID
);
453 void r600_engine_clock_entry_enable_pulse_skipping(struct radeon_device
*rdev
,
454 u32 index
, bool enable
)
457 WREG32_P(SCLK_FREQ_SETTING_STEP_0_PART2
+ (index
* 4 * 2),
458 STEP_0_SPLL_STEP_ENABLE
, ~STEP_0_SPLL_STEP_ENABLE
);
460 WREG32_P(SCLK_FREQ_SETTING_STEP_0_PART2
+ (index
* 4 * 2),
461 0, ~STEP_0_SPLL_STEP_ENABLE
);
464 void r600_engine_clock_entry_enable_post_divider(struct radeon_device
*rdev
,
465 u32 index
, bool enable
)
468 WREG32_P(SCLK_FREQ_SETTING_STEP_0_PART2
+ (index
* 4 * 2),
469 STEP_0_POST_DIV_EN
, ~STEP_0_POST_DIV_EN
);
471 WREG32_P(SCLK_FREQ_SETTING_STEP_0_PART2
+ (index
* 4 * 2),
472 0, ~STEP_0_POST_DIV_EN
);
475 void r600_engine_clock_entry_set_post_divider(struct radeon_device
*rdev
,
476 u32 index
, u32 divider
)
478 WREG32_P(SCLK_FREQ_SETTING_STEP_0_PART1
+ (index
* 4 * 2),
479 STEP_0_SPLL_POST_DIV(divider
), ~STEP_0_SPLL_POST_DIV_MASK
);
482 void r600_engine_clock_entry_set_reference_divider(struct radeon_device
*rdev
,
483 u32 index
, u32 divider
)
485 WREG32_P(SCLK_FREQ_SETTING_STEP_0_PART1
+ (index
* 4 * 2),
486 STEP_0_SPLL_REF_DIV(divider
), ~STEP_0_SPLL_REF_DIV_MASK
);
489 void r600_engine_clock_entry_set_feedback_divider(struct radeon_device
*rdev
,
490 u32 index
, u32 divider
)
492 WREG32_P(SCLK_FREQ_SETTING_STEP_0_PART1
+ (index
* 4 * 2),
493 STEP_0_SPLL_FB_DIV(divider
), ~STEP_0_SPLL_FB_DIV_MASK
);
496 void r600_engine_clock_entry_set_step_time(struct radeon_device
*rdev
,
497 u32 index
, u32 step_time
)
499 WREG32_P(SCLK_FREQ_SETTING_STEP_0_PART1
+ (index
* 4 * 2),
500 STEP_0_SPLL_STEP_TIME(step_time
), ~STEP_0_SPLL_STEP_TIME_MASK
);
503 void r600_vid_rt_set_ssu(struct radeon_device
*rdev
, u32 u
)
505 WREG32_P(VID_RT
, SSTU(u
), ~SSTU_MASK
);
508 void r600_vid_rt_set_vru(struct radeon_device
*rdev
, u32 u
)
510 WREG32_P(VID_RT
, VID_CRTU(u
), ~VID_CRTU_MASK
);
513 void r600_vid_rt_set_vrt(struct radeon_device
*rdev
, u32 rt
)
515 WREG32_P(VID_RT
, VID_CRT(rt
), ~VID_CRT_MASK
);
518 void r600_voltage_control_enable_pins(struct radeon_device
*rdev
,
521 WREG32(LOWER_GPIO_ENABLE
, mask
& 0xffffffff);
522 WREG32(UPPER_GPIO_ENABLE
, upper_32_bits(mask
));
526 void r600_voltage_control_program_voltages(struct radeon_device
*rdev
,
527 enum r600_power_level index
, u64 pins
)
530 u32 ix
= 3 - (3 & index
);
532 WREG32(CTXSW_VID_LOWER_GPIO_CNTL
+ (ix
* 4), pins
& 0xffffffff);
534 mask
= 7 << (3 * ix
);
535 tmp
= RREG32(VID_UPPER_GPIO_CNTL
);
536 tmp
= (tmp
& ~mask
) | ((pins
>> (32 - (3 * ix
))) & mask
);
537 WREG32(VID_UPPER_GPIO_CNTL
, tmp
);
540 void r600_voltage_control_deactivate_static_control(struct radeon_device
*rdev
,
545 gpio
= RREG32(GPIOPAD_MASK
);
547 WREG32(GPIOPAD_MASK
, gpio
);
549 gpio
= RREG32(GPIOPAD_EN
);
551 WREG32(GPIOPAD_EN
, gpio
);
553 gpio
= RREG32(GPIOPAD_A
);
555 WREG32(GPIOPAD_A
, gpio
);
558 void r600_power_level_enable(struct radeon_device
*rdev
,
559 enum r600_power_level index
, bool enable
)
561 u32 ix
= 3 - (3 & index
);
564 WREG32_P(CTXSW_PROFILE_INDEX
+ (ix
* 4), CTXSW_FREQ_STATE_ENABLE
,
565 ~CTXSW_FREQ_STATE_ENABLE
);
567 WREG32_P(CTXSW_PROFILE_INDEX
+ (ix
* 4), 0,
568 ~CTXSW_FREQ_STATE_ENABLE
);
571 void r600_power_level_set_voltage_index(struct radeon_device
*rdev
,
572 enum r600_power_level index
, u32 voltage_index
)
574 u32 ix
= 3 - (3 & index
);
576 WREG32_P(CTXSW_PROFILE_INDEX
+ (ix
* 4),
577 CTXSW_FREQ_VIDS_CFG_INDEX(voltage_index
), ~CTXSW_FREQ_VIDS_CFG_INDEX_MASK
);
580 void r600_power_level_set_mem_clock_index(struct radeon_device
*rdev
,
581 enum r600_power_level index
, u32 mem_clock_index
)
583 u32 ix
= 3 - (3 & index
);
585 WREG32_P(CTXSW_PROFILE_INDEX
+ (ix
* 4),
586 CTXSW_FREQ_MCLK_CFG_INDEX(mem_clock_index
), ~CTXSW_FREQ_MCLK_CFG_INDEX_MASK
);
589 void r600_power_level_set_eng_clock_index(struct radeon_device
*rdev
,
590 enum r600_power_level index
, u32 eng_clock_index
)
592 u32 ix
= 3 - (3 & index
);
594 WREG32_P(CTXSW_PROFILE_INDEX
+ (ix
* 4),
595 CTXSW_FREQ_SCLK_CFG_INDEX(eng_clock_index
), ~CTXSW_FREQ_SCLK_CFG_INDEX_MASK
);
598 void r600_power_level_set_watermark_id(struct radeon_device
*rdev
,
599 enum r600_power_level index
,
600 enum r600_display_watermark watermark_id
)
602 u32 ix
= 3 - (3 & index
);
605 if (watermark_id
== R600_DISPLAY_WATERMARK_HIGH
)
606 tmp
= CTXSW_FREQ_DISPLAY_WATERMARK
;
607 WREG32_P(CTXSW_PROFILE_INDEX
+ (ix
* 4), tmp
, ~CTXSW_FREQ_DISPLAY_WATERMARK
);
610 void r600_power_level_set_pcie_gen2(struct radeon_device
*rdev
,
611 enum r600_power_level index
, bool compatible
)
613 u32 ix
= 3 - (3 & index
);
617 tmp
= CTXSW_FREQ_GEN2PCIE_VOLT
;
618 WREG32_P(CTXSW_PROFILE_INDEX
+ (ix
* 4), tmp
, ~CTXSW_FREQ_GEN2PCIE_VOLT
);
621 enum r600_power_level
r600_power_level_get_current_index(struct radeon_device
*rdev
)
625 tmp
= RREG32(TARGET_AND_CURRENT_PROFILE_INDEX
) & CURRENT_PROFILE_INDEX_MASK
;
626 tmp
>>= CURRENT_PROFILE_INDEX_SHIFT
;
630 enum r600_power_level
r600_power_level_get_target_index(struct radeon_device
*rdev
)
634 tmp
= RREG32(TARGET_AND_CURRENT_PROFILE_INDEX
) & TARGET_PROFILE_INDEX_MASK
;
635 tmp
>>= TARGET_PROFILE_INDEX_SHIFT
;
639 void r600_power_level_set_enter_index(struct radeon_device
*rdev
,
640 enum r600_power_level index
)
642 WREG32_P(TARGET_AND_CURRENT_PROFILE_INDEX
, DYN_PWR_ENTER_INDEX(index
),
643 ~DYN_PWR_ENTER_INDEX_MASK
);
646 void r600_wait_for_power_level_unequal(struct radeon_device
*rdev
,
647 enum r600_power_level index
)
651 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
652 if (r600_power_level_get_target_index(rdev
) != index
)
657 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
658 if (r600_power_level_get_current_index(rdev
) != index
)
664 void r600_wait_for_power_level(struct radeon_device
*rdev
,
665 enum r600_power_level index
)
669 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
670 if (r600_power_level_get_target_index(rdev
) == index
)
675 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
676 if (r600_power_level_get_current_index(rdev
) == index
)
682 void r600_start_dpm(struct radeon_device
*rdev
)
684 r600_enable_sclk_control(rdev
, false);
685 r600_enable_mclk_control(rdev
, false);
687 r600_dynamicpm_enable(rdev
, true);
689 radeon_wait_for_vblank(rdev
, 0);
690 radeon_wait_for_vblank(rdev
, 1);
692 r600_enable_spll_bypass(rdev
, true);
693 r600_wait_for_spll_change(rdev
);
694 r600_enable_spll_bypass(rdev
, false);
695 r600_wait_for_spll_change(rdev
);
697 r600_enable_spll_bypass(rdev
, true);
698 r600_wait_for_spll_change(rdev
);
699 r600_enable_spll_bypass(rdev
, false);
700 r600_wait_for_spll_change(rdev
);
702 r600_enable_sclk_control(rdev
, true);
703 r600_enable_mclk_control(rdev
, true);
706 void r600_stop_dpm(struct radeon_device
*rdev
)
708 r600_dynamicpm_enable(rdev
, false);
711 int r600_dpm_pre_set_power_state(struct radeon_device
*rdev
)
716 void r600_dpm_post_set_power_state(struct radeon_device
*rdev
)
721 bool r600_is_uvd_state(u32
class, u32 class2
)
723 if (class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE
)
725 if (class & ATOM_PPLIB_CLASSIFICATION_HD2STATE
)
727 if (class & ATOM_PPLIB_CLASSIFICATION_HDSTATE
)
729 if (class & ATOM_PPLIB_CLASSIFICATION_SDSTATE
)
731 if (class2
& ATOM_PPLIB_CLASSIFICATION2_MVC
)
736 static int r600_set_thermal_temperature_range(struct radeon_device
*rdev
,
737 int min_temp
, int max_temp
)
739 int low_temp
= 0 * 1000;
740 int high_temp
= 255 * 1000;
742 if (low_temp
< min_temp
)
744 if (high_temp
> max_temp
)
745 high_temp
= max_temp
;
746 if (high_temp
< low_temp
) {
747 DRM_ERROR("invalid thermal range: %d - %d\n", low_temp
, high_temp
);
751 WREG32_P(CG_THERMAL_INT
, DIG_THERM_INTH(high_temp
/ 1000), ~DIG_THERM_INTH_MASK
);
752 WREG32_P(CG_THERMAL_INT
, DIG_THERM_INTL(low_temp
/ 1000), ~DIG_THERM_INTL_MASK
);
753 WREG32_P(CG_THERMAL_CTRL
, DIG_THERM_DPM(high_temp
/ 1000), ~DIG_THERM_DPM_MASK
);
755 rdev
->pm
.dpm
.thermal
.min_temp
= low_temp
;
756 rdev
->pm
.dpm
.thermal
.max_temp
= high_temp
;
761 bool r600_is_internal_thermal_sensor(enum radeon_int_thermal_type sensor
)
764 case THERMAL_TYPE_RV6XX
:
765 case THERMAL_TYPE_RV770
:
766 case THERMAL_TYPE_EVERGREEN
:
767 case THERMAL_TYPE_SUMO
:
768 case THERMAL_TYPE_NI
:
769 case THERMAL_TYPE_SI
:
770 case THERMAL_TYPE_CI
:
771 case THERMAL_TYPE_KV
:
773 case THERMAL_TYPE_ADT7473_WITH_INTERNAL
:
774 case THERMAL_TYPE_EMC2103_WITH_INTERNAL
:
775 return false; /* need special handling */
776 case THERMAL_TYPE_NONE
:
777 case THERMAL_TYPE_EXTERNAL
:
778 case THERMAL_TYPE_EXTERNAL_GPIO
:
784 int r600_dpm_late_enable(struct radeon_device
*rdev
)
788 if (rdev
->irq
.installed
&&
789 r600_is_internal_thermal_sensor(rdev
->pm
.int_thermal_type
)) {
790 ret
= r600_set_thermal_temperature_range(rdev
, R600_TEMP_RANGE_MIN
, R600_TEMP_RANGE_MAX
);
793 rdev
->irq
.dpm_thermal
= true;
794 radeon_irq_set(rdev
);
801 struct _ATOM_POWERPLAY_INFO info
;
802 struct _ATOM_POWERPLAY_INFO_V2 info_2
;
803 struct _ATOM_POWERPLAY_INFO_V3 info_3
;
804 struct _ATOM_PPLIB_POWERPLAYTABLE pplib
;
805 struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2
;
806 struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3
;
807 struct _ATOM_PPLIB_POWERPLAYTABLE4 pplib4
;
808 struct _ATOM_PPLIB_POWERPLAYTABLE5 pplib5
;
812 struct _ATOM_PPLIB_FANTABLE fan
;
813 struct _ATOM_PPLIB_FANTABLE2 fan2
;
816 static int r600_parse_clk_voltage_dep_table(struct radeon_clock_voltage_dependency_table
*radeon_table
,
817 ATOM_PPLIB_Clock_Voltage_Dependency_Table
*atom_table
)
819 u32 size
= atom_table
->ucNumEntries
*
820 sizeof(struct radeon_clock_voltage_dependency_entry
);
822 ATOM_PPLIB_Clock_Voltage_Dependency_Record
*entry
;
824 radeon_table
->entries
= kzalloc(size
, GFP_KERNEL
);
825 if (!radeon_table
->entries
)
828 entry
= &atom_table
->entries
[0];
829 for (i
= 0; i
< atom_table
->ucNumEntries
; i
++) {
830 radeon_table
->entries
[i
].clk
= le16_to_cpu(entry
->usClockLow
) |
831 (entry
->ucClockHigh
<< 16);
832 radeon_table
->entries
[i
].v
= le16_to_cpu(entry
->usVoltage
);
833 entry
= (ATOM_PPLIB_Clock_Voltage_Dependency_Record
*)
834 ((u8
*)entry
+ sizeof(ATOM_PPLIB_Clock_Voltage_Dependency_Record
));
836 radeon_table
->count
= atom_table
->ucNumEntries
;
841 int r600_get_platform_caps(struct radeon_device
*rdev
)
843 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
844 union power_info
*power_info
;
845 int index
= GetIndexIntoMasterTable(DATA
, PowerPlayInfo
);
849 if (!atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
850 &frev
, &crev
, &data_offset
))
852 power_info
= (union power_info
*)(mode_info
->atom_context
->bios
+ data_offset
);
854 rdev
->pm
.dpm
.platform_caps
= le32_to_cpu(power_info
->pplib
.ulPlatformCaps
);
855 rdev
->pm
.dpm
.backbias_response_time
= le16_to_cpu(power_info
->pplib
.usBackbiasTime
);
856 rdev
->pm
.dpm
.voltage_response_time
= le16_to_cpu(power_info
->pplib
.usVoltageTime
);
861 /* sizeof(ATOM_PPLIB_EXTENDEDHEADER) */
862 #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V2 12
863 #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V3 14
864 #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V4 16
865 #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V5 18
866 #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V6 20
867 #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V7 22
869 int r600_parse_extended_power_table(struct radeon_device
*rdev
)
871 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
872 union power_info
*power_info
;
873 union fan_info
*fan_info
;
874 ATOM_PPLIB_Clock_Voltage_Dependency_Table
*dep_table
;
875 int index
= GetIndexIntoMasterTable(DATA
, PowerPlayInfo
);
880 if (!atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
881 &frev
, &crev
, &data_offset
))
883 power_info
= (union power_info
*)((uint8_t*)mode_info
->atom_context
->bios
+ data_offset
);
886 if (le16_to_cpu(power_info
->pplib
.usTableSize
) >=
887 sizeof(struct _ATOM_PPLIB_POWERPLAYTABLE3
)) {
888 if (power_info
->pplib3
.usFanTableOffset
) {
889 fan_info
= (union fan_info
*)((uint8_t*)mode_info
->atom_context
->bios
+ data_offset
+
890 le16_to_cpu(power_info
->pplib3
.usFanTableOffset
));
891 rdev
->pm
.dpm
.fan
.t_hyst
= fan_info
->fan
.ucTHyst
;
892 rdev
->pm
.dpm
.fan
.t_min
= le16_to_cpu(fan_info
->fan
.usTMin
);
893 rdev
->pm
.dpm
.fan
.t_med
= le16_to_cpu(fan_info
->fan
.usTMed
);
894 rdev
->pm
.dpm
.fan
.t_high
= le16_to_cpu(fan_info
->fan
.usTHigh
);
895 rdev
->pm
.dpm
.fan
.pwm_min
= le16_to_cpu(fan_info
->fan
.usPWMMin
);
896 rdev
->pm
.dpm
.fan
.pwm_med
= le16_to_cpu(fan_info
->fan
.usPWMMed
);
897 rdev
->pm
.dpm
.fan
.pwm_high
= le16_to_cpu(fan_info
->fan
.usPWMHigh
);
898 if (fan_info
->fan
.ucFanTableFormat
>= 2)
899 rdev
->pm
.dpm
.fan
.t_max
= le16_to_cpu(fan_info
->fan2
.usTMax
);
901 rdev
->pm
.dpm
.fan
.t_max
= 10900;
902 rdev
->pm
.dpm
.fan
.cycle_delay
= 100000;
903 rdev
->pm
.dpm
.fan
.ucode_fan_control
= true;
907 /* clock dependancy tables, shedding tables */
908 if (le16_to_cpu(power_info
->pplib
.usTableSize
) >=
909 sizeof(struct _ATOM_PPLIB_POWERPLAYTABLE4
)) {
910 if (power_info
->pplib4
.usVddcDependencyOnSCLKOffset
) {
911 dep_table
= (ATOM_PPLIB_Clock_Voltage_Dependency_Table
*)
912 ((uint8_t*)mode_info
->atom_context
->bios
+ data_offset
+
913 le16_to_cpu(power_info
->pplib4
.usVddcDependencyOnSCLKOffset
));
914 ret
= r600_parse_clk_voltage_dep_table(&rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
,
919 if (power_info
->pplib4
.usVddciDependencyOnMCLKOffset
) {
920 dep_table
= (ATOM_PPLIB_Clock_Voltage_Dependency_Table
*)
921 ((uint8_t*)mode_info
->atom_context
->bios
+ data_offset
+
922 le16_to_cpu(power_info
->pplib4
.usVddciDependencyOnMCLKOffset
));
923 ret
= r600_parse_clk_voltage_dep_table(&rdev
->pm
.dpm
.dyn_state
.vddci_dependency_on_mclk
,
926 kfree(rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
.entries
);
930 if (power_info
->pplib4
.usVddcDependencyOnMCLKOffset
) {
931 dep_table
= (ATOM_PPLIB_Clock_Voltage_Dependency_Table
*)
932 ((uint8_t*)mode_info
->atom_context
->bios
+ data_offset
+
933 le16_to_cpu(power_info
->pplib4
.usVddcDependencyOnMCLKOffset
));
934 ret
= r600_parse_clk_voltage_dep_table(&rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_mclk
,
937 kfree(rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
.entries
);
938 kfree(rdev
->pm
.dpm
.dyn_state
.vddci_dependency_on_mclk
.entries
);
942 if (power_info
->pplib4
.usMvddDependencyOnMCLKOffset
) {
943 dep_table
= (ATOM_PPLIB_Clock_Voltage_Dependency_Table
*)
944 (mode_info
->atom_context
->bios
+ data_offset
+
945 le16_to_cpu(power_info
->pplib4
.usMvddDependencyOnMCLKOffset
));
946 ret
= r600_parse_clk_voltage_dep_table(&rdev
->pm
.dpm
.dyn_state
.mvdd_dependency_on_mclk
,
949 kfree(rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
.entries
);
950 kfree(rdev
->pm
.dpm
.dyn_state
.vddci_dependency_on_mclk
.entries
);
951 kfree(rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_mclk
.entries
);
955 if (power_info
->pplib4
.usMaxClockVoltageOnDCOffset
) {
956 ATOM_PPLIB_Clock_Voltage_Limit_Table
*clk_v
=
957 (ATOM_PPLIB_Clock_Voltage_Limit_Table
*)
958 ((uint8_t*)mode_info
->atom_context
->bios
+ data_offset
+
959 le16_to_cpu(power_info
->pplib4
.usMaxClockVoltageOnDCOffset
));
960 if (clk_v
->ucNumEntries
) {
961 rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_dc
.sclk
=
962 le16_to_cpu(clk_v
->entries
[0].usSclkLow
) |
963 (clk_v
->entries
[0].ucSclkHigh
<< 16);
964 rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_dc
.mclk
=
965 le16_to_cpu(clk_v
->entries
[0].usMclkLow
) |
966 (clk_v
->entries
[0].ucMclkHigh
<< 16);
967 rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_dc
.vddc
=
968 le16_to_cpu(clk_v
->entries
[0].usVddc
);
969 rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_dc
.vddci
=
970 le16_to_cpu(clk_v
->entries
[0].usVddci
);
973 if (power_info
->pplib4
.usVddcPhaseShedLimitsTableOffset
) {
974 ATOM_PPLIB_PhaseSheddingLimits_Table
*psl
=
975 (ATOM_PPLIB_PhaseSheddingLimits_Table
*)
976 ((uint8_t*)mode_info
->atom_context
->bios
+ data_offset
+
977 le16_to_cpu(power_info
->pplib4
.usVddcPhaseShedLimitsTableOffset
));
978 ATOM_PPLIB_PhaseSheddingLimits_Record
*entry
;
980 rdev
->pm
.dpm
.dyn_state
.phase_shedding_limits_table
.entries
=
981 kzalloc(psl
->ucNumEntries
*
982 sizeof(struct radeon_phase_shedding_limits_entry
),
984 if (!rdev
->pm
.dpm
.dyn_state
.phase_shedding_limits_table
.entries
) {
985 r600_free_extended_power_table(rdev
);
989 entry
= &psl
->entries
[0];
990 for (i
= 0; i
< psl
->ucNumEntries
; i
++) {
991 rdev
->pm
.dpm
.dyn_state
.phase_shedding_limits_table
.entries
[i
].sclk
=
992 le16_to_cpu(entry
->usSclkLow
) | (entry
->ucSclkHigh
<< 16);
993 rdev
->pm
.dpm
.dyn_state
.phase_shedding_limits_table
.entries
[i
].mclk
=
994 le16_to_cpu(entry
->usMclkLow
) | (entry
->ucMclkHigh
<< 16);
995 rdev
->pm
.dpm
.dyn_state
.phase_shedding_limits_table
.entries
[i
].voltage
=
996 le16_to_cpu(entry
->usVoltage
);
997 entry
= (ATOM_PPLIB_PhaseSheddingLimits_Record
*)
998 ((u8
*)entry
+ sizeof(ATOM_PPLIB_PhaseSheddingLimits_Record
));
1000 rdev
->pm
.dpm
.dyn_state
.phase_shedding_limits_table
.count
=
1006 if (le16_to_cpu(power_info
->pplib
.usTableSize
) >=
1007 sizeof(struct _ATOM_PPLIB_POWERPLAYTABLE5
)) {
1008 rdev
->pm
.dpm
.tdp_limit
= le32_to_cpu(power_info
->pplib5
.ulTDPLimit
);
1009 rdev
->pm
.dpm
.near_tdp_limit
= le32_to_cpu(power_info
->pplib5
.ulNearTDPLimit
);
1010 rdev
->pm
.dpm
.near_tdp_limit_adjusted
= rdev
->pm
.dpm
.near_tdp_limit
;
1011 rdev
->pm
.dpm
.tdp_od_limit
= le16_to_cpu(power_info
->pplib5
.usTDPODLimit
);
1012 if (rdev
->pm
.dpm
.tdp_od_limit
)
1013 rdev
->pm
.dpm
.power_control
= true;
1015 rdev
->pm
.dpm
.power_control
= false;
1016 rdev
->pm
.dpm
.tdp_adjustment
= 0;
1017 rdev
->pm
.dpm
.sq_ramping_threshold
= le32_to_cpu(power_info
->pplib5
.ulSQRampingThreshold
);
1018 rdev
->pm
.dpm
.cac_leakage
= le32_to_cpu(power_info
->pplib5
.ulCACLeakage
);
1019 rdev
->pm
.dpm
.load_line_slope
= le16_to_cpu(power_info
->pplib5
.usLoadLineSlope
);
1020 if (power_info
->pplib5
.usCACLeakageTableOffset
) {
1021 ATOM_PPLIB_CAC_Leakage_Table
*cac_table
=
1022 (ATOM_PPLIB_CAC_Leakage_Table
*)
1023 ((uint8_t*)mode_info
->atom_context
->bios
+ data_offset
+
1024 le16_to_cpu(power_info
->pplib5
.usCACLeakageTableOffset
));
1025 ATOM_PPLIB_CAC_Leakage_Record
*entry
;
1026 u32 size
= cac_table
->ucNumEntries
* sizeof(struct radeon_cac_leakage_table
);
1027 rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.entries
= kzalloc(size
, GFP_KERNEL
);
1028 if (!rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.entries
) {
1029 r600_free_extended_power_table(rdev
);
1032 entry
= &cac_table
->entries
[0];
1033 for (i
= 0; i
< cac_table
->ucNumEntries
; i
++) {
1034 if (rdev
->pm
.dpm
.platform_caps
& ATOM_PP_PLATFORM_CAP_EVV
) {
1035 rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.entries
[i
].vddc1
=
1036 le16_to_cpu(entry
->usVddc1
);
1037 rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.entries
[i
].vddc2
=
1038 le16_to_cpu(entry
->usVddc2
);
1039 rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.entries
[i
].vddc3
=
1040 le16_to_cpu(entry
->usVddc3
);
1042 rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.entries
[i
].vddc
=
1043 le16_to_cpu(entry
->usVddc
);
1044 rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.entries
[i
].leakage
=
1045 le32_to_cpu(entry
->ulLeakageValue
);
1047 entry
= (ATOM_PPLIB_CAC_Leakage_Record
*)
1048 ((u8
*)entry
+ sizeof(ATOM_PPLIB_CAC_Leakage_Record
));
1050 rdev
->pm
.dpm
.dyn_state
.cac_leakage_table
.count
= cac_table
->ucNumEntries
;
1055 if (le16_to_cpu(power_info
->pplib
.usTableSize
) >=
1056 sizeof(struct _ATOM_PPLIB_POWERPLAYTABLE3
)) {
1057 ATOM_PPLIB_EXTENDEDHEADER
*ext_hdr
= (ATOM_PPLIB_EXTENDEDHEADER
*)
1058 (mode_info
->atom_context
->bios
+ data_offset
+
1059 le16_to_cpu(power_info
->pplib3
.usExtendendedHeaderOffset
));
1060 if ((le16_to_cpu(ext_hdr
->usSize
) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V2
) &&
1061 ext_hdr
->usVCETableOffset
) {
1062 VCEClockInfoArray
*array
= (VCEClockInfoArray
*)
1063 (mode_info
->atom_context
->bios
+ data_offset
+
1064 le16_to_cpu(ext_hdr
->usVCETableOffset
) + 1);
1065 ATOM_PPLIB_VCE_Clock_Voltage_Limit_Table
*limits
=
1066 (ATOM_PPLIB_VCE_Clock_Voltage_Limit_Table
*)
1067 (mode_info
->atom_context
->bios
+ data_offset
+
1068 le16_to_cpu(ext_hdr
->usVCETableOffset
) + 1 +
1069 1 + array
->ucNumEntries
* sizeof(VCEClockInfo
));
1070 ATOM_PPLIB_VCE_State_Table
*states
=
1071 (ATOM_PPLIB_VCE_State_Table
*)
1072 (mode_info
->atom_context
->bios
+ data_offset
+
1073 le16_to_cpu(ext_hdr
->usVCETableOffset
) + 1 +
1074 1 + (array
->ucNumEntries
* sizeof (VCEClockInfo
)) +
1075 1 + (limits
->numEntries
* sizeof(ATOM_PPLIB_VCE_Clock_Voltage_Limit_Record
)));
1076 ATOM_PPLIB_VCE_Clock_Voltage_Limit_Record
*entry
;
1077 ATOM_PPLIB_VCE_State_Record
*state_entry
;
1078 VCEClockInfo
*vce_clk
;
1079 u32 size
= limits
->numEntries
*
1080 sizeof(struct radeon_vce_clock_voltage_dependency_entry
);
1081 rdev
->pm
.dpm
.dyn_state
.vce_clock_voltage_dependency_table
.entries
=
1082 kzalloc(size
, GFP_KERNEL
);
1083 if (!rdev
->pm
.dpm
.dyn_state
.vce_clock_voltage_dependency_table
.entries
) {
1084 r600_free_extended_power_table(rdev
);
1087 rdev
->pm
.dpm
.dyn_state
.vce_clock_voltage_dependency_table
.count
=
1089 entry
= &limits
->entries
[0];
1090 state_entry
= &states
->entries
[0];
1091 for (i
= 0; i
< limits
->numEntries
; i
++) {
1092 vce_clk
= (VCEClockInfo
*)
1093 ((u8
*)&array
->entries
[0] +
1094 (entry
->ucVCEClockInfoIndex
* sizeof(VCEClockInfo
)));
1095 rdev
->pm
.dpm
.dyn_state
.vce_clock_voltage_dependency_table
.entries
[i
].evclk
=
1096 le16_to_cpu(vce_clk
->usEVClkLow
) | (vce_clk
->ucEVClkHigh
<< 16);
1097 rdev
->pm
.dpm
.dyn_state
.vce_clock_voltage_dependency_table
.entries
[i
].ecclk
=
1098 le16_to_cpu(vce_clk
->usECClkLow
) | (vce_clk
->ucECClkHigh
<< 16);
1099 rdev
->pm
.dpm
.dyn_state
.vce_clock_voltage_dependency_table
.entries
[i
].v
=
1100 le16_to_cpu(entry
->usVoltage
);
1101 entry
= (ATOM_PPLIB_VCE_Clock_Voltage_Limit_Record
*)
1102 ((u8
*)entry
+ sizeof(ATOM_PPLIB_VCE_Clock_Voltage_Limit_Record
));
1104 for (i
= 0; i
< states
->numEntries
; i
++) {
1105 if (i
>= RADEON_MAX_VCE_LEVELS
)
1107 vce_clk
= (VCEClockInfo
*)
1108 ((u8
*)&array
->entries
[0] +
1109 (state_entry
->ucVCEClockInfoIndex
* sizeof(VCEClockInfo
)));
1110 rdev
->pm
.dpm
.vce_states
[i
].evclk
=
1111 le16_to_cpu(vce_clk
->usEVClkLow
) | (vce_clk
->ucEVClkHigh
<< 16);
1112 rdev
->pm
.dpm
.vce_states
[i
].ecclk
=
1113 le16_to_cpu(vce_clk
->usECClkLow
) | (vce_clk
->ucECClkHigh
<< 16);
1114 rdev
->pm
.dpm
.vce_states
[i
].clk_idx
=
1115 state_entry
->ucClockInfoIndex
& 0x3f;
1116 rdev
->pm
.dpm
.vce_states
[i
].pstate
=
1117 (state_entry
->ucClockInfoIndex
& 0xc0) >> 6;
1118 state_entry
= (ATOM_PPLIB_VCE_State_Record
*)
1119 ((u8
*)state_entry
+ sizeof(ATOM_PPLIB_VCE_State_Record
));
1122 if ((le16_to_cpu(ext_hdr
->usSize
) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V3
) &&
1123 ext_hdr
->usUVDTableOffset
) {
1124 UVDClockInfoArray
*array
= (UVDClockInfoArray
*)
1125 (mode_info
->atom_context
->bios
+ data_offset
+
1126 le16_to_cpu(ext_hdr
->usUVDTableOffset
) + 1);
1127 ATOM_PPLIB_UVD_Clock_Voltage_Limit_Table
*limits
=
1128 (ATOM_PPLIB_UVD_Clock_Voltage_Limit_Table
*)
1129 (mode_info
->atom_context
->bios
+ data_offset
+
1130 le16_to_cpu(ext_hdr
->usUVDTableOffset
) + 1 +
1131 1 + (array
->ucNumEntries
* sizeof (UVDClockInfo
)));
1132 ATOM_PPLIB_UVD_Clock_Voltage_Limit_Record
*entry
;
1133 u32 size
= limits
->numEntries
*
1134 sizeof(struct radeon_uvd_clock_voltage_dependency_entry
);
1135 rdev
->pm
.dpm
.dyn_state
.uvd_clock_voltage_dependency_table
.entries
=
1136 kzalloc(size
, GFP_KERNEL
);
1137 if (!rdev
->pm
.dpm
.dyn_state
.uvd_clock_voltage_dependency_table
.entries
) {
1138 r600_free_extended_power_table(rdev
);
1141 rdev
->pm
.dpm
.dyn_state
.uvd_clock_voltage_dependency_table
.count
=
1143 entry
= &limits
->entries
[0];
1144 for (i
= 0; i
< limits
->numEntries
; i
++) {
1145 UVDClockInfo
*uvd_clk
= (UVDClockInfo
*)
1146 ((u8
*)&array
->entries
[0] +
1147 (entry
->ucUVDClockInfoIndex
* sizeof(UVDClockInfo
)));
1148 rdev
->pm
.dpm
.dyn_state
.uvd_clock_voltage_dependency_table
.entries
[i
].vclk
=
1149 le16_to_cpu(uvd_clk
->usVClkLow
) | (uvd_clk
->ucVClkHigh
<< 16);
1150 rdev
->pm
.dpm
.dyn_state
.uvd_clock_voltage_dependency_table
.entries
[i
].dclk
=
1151 le16_to_cpu(uvd_clk
->usDClkLow
) | (uvd_clk
->ucDClkHigh
<< 16);
1152 rdev
->pm
.dpm
.dyn_state
.uvd_clock_voltage_dependency_table
.entries
[i
].v
=
1153 le16_to_cpu(entry
->usVoltage
);
1154 entry
= (ATOM_PPLIB_UVD_Clock_Voltage_Limit_Record
*)
1155 ((u8
*)entry
+ sizeof(ATOM_PPLIB_UVD_Clock_Voltage_Limit_Record
));
1158 if ((le16_to_cpu(ext_hdr
->usSize
) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V4
) &&
1159 ext_hdr
->usSAMUTableOffset
) {
1160 ATOM_PPLIB_SAMClk_Voltage_Limit_Table
*limits
=
1161 (ATOM_PPLIB_SAMClk_Voltage_Limit_Table
*)
1162 (mode_info
->atom_context
->bios
+ data_offset
+
1163 le16_to_cpu(ext_hdr
->usSAMUTableOffset
) + 1);
1164 ATOM_PPLIB_SAMClk_Voltage_Limit_Record
*entry
;
1165 u32 size
= limits
->numEntries
*
1166 sizeof(struct radeon_clock_voltage_dependency_entry
);
1167 rdev
->pm
.dpm
.dyn_state
.samu_clock_voltage_dependency_table
.entries
=
1168 kzalloc(size
, GFP_KERNEL
);
1169 if (!rdev
->pm
.dpm
.dyn_state
.samu_clock_voltage_dependency_table
.entries
) {
1170 r600_free_extended_power_table(rdev
);
1173 rdev
->pm
.dpm
.dyn_state
.samu_clock_voltage_dependency_table
.count
=
1175 entry
= &limits
->entries
[0];
1176 for (i
= 0; i
< limits
->numEntries
; i
++) {
1177 rdev
->pm
.dpm
.dyn_state
.samu_clock_voltage_dependency_table
.entries
[i
].clk
=
1178 le16_to_cpu(entry
->usSAMClockLow
) | (entry
->ucSAMClockHigh
<< 16);
1179 rdev
->pm
.dpm
.dyn_state
.samu_clock_voltage_dependency_table
.entries
[i
].v
=
1180 le16_to_cpu(entry
->usVoltage
);
1181 entry
= (ATOM_PPLIB_SAMClk_Voltage_Limit_Record
*)
1182 ((u8
*)entry
+ sizeof(ATOM_PPLIB_SAMClk_Voltage_Limit_Record
));
1185 if ((le16_to_cpu(ext_hdr
->usSize
) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V5
) &&
1186 ext_hdr
->usPPMTableOffset
) {
1187 ATOM_PPLIB_PPM_Table
*ppm
= (ATOM_PPLIB_PPM_Table
*)
1188 (mode_info
->atom_context
->bios
+ data_offset
+
1189 le16_to_cpu(ext_hdr
->usPPMTableOffset
));
1190 rdev
->pm
.dpm
.dyn_state
.ppm_table
=
1191 kzalloc(sizeof(struct radeon_ppm_table
), GFP_KERNEL
);
1192 if (!rdev
->pm
.dpm
.dyn_state
.ppm_table
) {
1193 r600_free_extended_power_table(rdev
);
1196 rdev
->pm
.dpm
.dyn_state
.ppm_table
->ppm_design
= ppm
->ucPpmDesign
;
1197 rdev
->pm
.dpm
.dyn_state
.ppm_table
->cpu_core_number
=
1198 le16_to_cpu(ppm
->usCpuCoreNumber
);
1199 rdev
->pm
.dpm
.dyn_state
.ppm_table
->platform_tdp
=
1200 le32_to_cpu(ppm
->ulPlatformTDP
);
1201 rdev
->pm
.dpm
.dyn_state
.ppm_table
->small_ac_platform_tdp
=
1202 le32_to_cpu(ppm
->ulSmallACPlatformTDP
);
1203 rdev
->pm
.dpm
.dyn_state
.ppm_table
->platform_tdc
=
1204 le32_to_cpu(ppm
->ulPlatformTDC
);
1205 rdev
->pm
.dpm
.dyn_state
.ppm_table
->small_ac_platform_tdc
=
1206 le32_to_cpu(ppm
->ulSmallACPlatformTDC
);
1207 rdev
->pm
.dpm
.dyn_state
.ppm_table
->apu_tdp
=
1208 le32_to_cpu(ppm
->ulApuTDP
);
1209 rdev
->pm
.dpm
.dyn_state
.ppm_table
->dgpu_tdp
=
1210 le32_to_cpu(ppm
->ulDGpuTDP
);
1211 rdev
->pm
.dpm
.dyn_state
.ppm_table
->dgpu_ulv_power
=
1212 le32_to_cpu(ppm
->ulDGpuUlvPower
);
1213 rdev
->pm
.dpm
.dyn_state
.ppm_table
->tj_max
=
1214 le32_to_cpu(ppm
->ulTjmax
);
1216 if ((le16_to_cpu(ext_hdr
->usSize
) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V6
) &&
1217 ext_hdr
->usACPTableOffset
) {
1218 ATOM_PPLIB_ACPClk_Voltage_Limit_Table
*limits
=
1219 (ATOM_PPLIB_ACPClk_Voltage_Limit_Table
*)
1220 (mode_info
->atom_context
->bios
+ data_offset
+
1221 le16_to_cpu(ext_hdr
->usACPTableOffset
) + 1);
1222 ATOM_PPLIB_ACPClk_Voltage_Limit_Record
*entry
;
1223 u32 size
= limits
->numEntries
*
1224 sizeof(struct radeon_clock_voltage_dependency_entry
);
1225 rdev
->pm
.dpm
.dyn_state
.acp_clock_voltage_dependency_table
.entries
=
1226 kzalloc(size
, GFP_KERNEL
);
1227 if (!rdev
->pm
.dpm
.dyn_state
.acp_clock_voltage_dependency_table
.entries
) {
1228 r600_free_extended_power_table(rdev
);
1231 rdev
->pm
.dpm
.dyn_state
.acp_clock_voltage_dependency_table
.count
=
1233 entry
= &limits
->entries
[0];
1234 for (i
= 0; i
< limits
->numEntries
; i
++) {
1235 rdev
->pm
.dpm
.dyn_state
.acp_clock_voltage_dependency_table
.entries
[i
].clk
=
1236 le16_to_cpu(entry
->usACPClockLow
) | (entry
->ucACPClockHigh
<< 16);
1237 rdev
->pm
.dpm
.dyn_state
.acp_clock_voltage_dependency_table
.entries
[i
].v
=
1238 le16_to_cpu(entry
->usVoltage
);
1239 entry
= (ATOM_PPLIB_ACPClk_Voltage_Limit_Record
*)
1240 ((u8
*)entry
+ sizeof(ATOM_PPLIB_ACPClk_Voltage_Limit_Record
));
1243 if ((le16_to_cpu(ext_hdr
->usSize
) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V7
) &&
1244 ext_hdr
->usPowerTuneTableOffset
) {
1245 u8 rev
= *(u8
*)(mode_info
->atom_context
->bios
+ data_offset
+
1246 le16_to_cpu(ext_hdr
->usPowerTuneTableOffset
));
1247 ATOM_PowerTune_Table
*pt
;
1248 rdev
->pm
.dpm
.dyn_state
.cac_tdp_table
=
1249 kzalloc(sizeof(struct radeon_cac_tdp_table
), GFP_KERNEL
);
1250 if (!rdev
->pm
.dpm
.dyn_state
.cac_tdp_table
) {
1251 r600_free_extended_power_table(rdev
);
1255 ATOM_PPLIB_POWERTUNE_Table_V1
*ppt
= (ATOM_PPLIB_POWERTUNE_Table_V1
*)
1256 (mode_info
->atom_context
->bios
+ data_offset
+
1257 le16_to_cpu(ext_hdr
->usPowerTuneTableOffset
));
1258 rdev
->pm
.dpm
.dyn_state
.cac_tdp_table
->maximum_power_delivery_limit
=
1259 le16_to_cpu(ppt
->usMaximumPowerDeliveryLimit
);
1260 pt
= &ppt
->power_tune_table
;
1262 ATOM_PPLIB_POWERTUNE_Table
*ppt
= (ATOM_PPLIB_POWERTUNE_Table
*)
1263 (mode_info
->atom_context
->bios
+ data_offset
+
1264 le16_to_cpu(ext_hdr
->usPowerTuneTableOffset
));
1265 rdev
->pm
.dpm
.dyn_state
.cac_tdp_table
->maximum_power_delivery_limit
= 255;
1266 pt
= &ppt
->power_tune_table
;
1268 rdev
->pm
.dpm
.dyn_state
.cac_tdp_table
->tdp
= le16_to_cpu(pt
->usTDP
);
1269 rdev
->pm
.dpm
.dyn_state
.cac_tdp_table
->configurable_tdp
=
1270 le16_to_cpu(pt
->usConfigurableTDP
);
1271 rdev
->pm
.dpm
.dyn_state
.cac_tdp_table
->tdc
= le16_to_cpu(pt
->usTDC
);
1272 rdev
->pm
.dpm
.dyn_state
.cac_tdp_table
->battery_power_limit
=
1273 le16_to_cpu(pt
->usBatteryPowerLimit
);
1274 rdev
->pm
.dpm
.dyn_state
.cac_tdp_table
->small_power_limit
=
1275 le16_to_cpu(pt
->usSmallPowerLimit
);
1276 rdev
->pm
.dpm
.dyn_state
.cac_tdp_table
->low_cac_leakage
=
1277 le16_to_cpu(pt
->usLowCACLeakage
);
1278 rdev
->pm
.dpm
.dyn_state
.cac_tdp_table
->high_cac_leakage
=
1279 le16_to_cpu(pt
->usHighCACLeakage
);
1286 void r600_free_extended_power_table(struct radeon_device
*rdev
)
1288 struct radeon_dpm_dynamic_state
*dyn_state
= &rdev
->pm
.dpm
.dyn_state
;
1290 kfree(dyn_state
->vddc_dependency_on_sclk
.entries
);
1291 kfree(dyn_state
->vddci_dependency_on_mclk
.entries
);
1292 kfree(dyn_state
->vddc_dependency_on_mclk
.entries
);
1293 kfree(dyn_state
->mvdd_dependency_on_mclk
.entries
);
1294 kfree(dyn_state
->cac_leakage_table
.entries
);
1295 kfree(dyn_state
->phase_shedding_limits_table
.entries
);
1296 kfree(dyn_state
->ppm_table
);
1297 kfree(dyn_state
->cac_tdp_table
);
1298 kfree(dyn_state
->vce_clock_voltage_dependency_table
.entries
);
1299 kfree(dyn_state
->uvd_clock_voltage_dependency_table
.entries
);
1300 kfree(dyn_state
->samu_clock_voltage_dependency_table
.entries
);
1301 kfree(dyn_state
->acp_clock_voltage_dependency_table
.entries
);
1304 enum radeon_pcie_gen
r600_get_pcie_gen_support(struct radeon_device
*rdev
,
1306 enum radeon_pcie_gen asic_gen
,
1307 enum radeon_pcie_gen default_gen
)
1310 case RADEON_PCIE_GEN1
:
1311 return RADEON_PCIE_GEN1
;
1312 case RADEON_PCIE_GEN2
:
1313 return RADEON_PCIE_GEN2
;
1314 case RADEON_PCIE_GEN3
:
1315 return RADEON_PCIE_GEN3
;
1317 if ((sys_mask
& DRM_PCIE_SPEED_80
) && (default_gen
== RADEON_PCIE_GEN3
))
1318 return RADEON_PCIE_GEN3
;
1319 else if ((sys_mask
& DRM_PCIE_SPEED_50
) && (default_gen
== RADEON_PCIE_GEN2
))
1320 return RADEON_PCIE_GEN2
;
1322 return RADEON_PCIE_GEN1
;
1324 return RADEON_PCIE_GEN1
;
1327 u16
r600_get_pcie_lane_support(struct radeon_device
*rdev
,
1331 switch (asic_lanes
) {
1334 return default_lanes
;
1350 u8
r600_encode_pci_lane_width(u32 lanes
)
1352 u8 encoded_lanes
[] = { 0, 1, 2, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 6 };
1357 return encoded_lanes
[lanes
];