xref: /dflybsd-src/sys/dev/drm/radeon/ni_dpm.h (revision 57e252bfa9ffec9f583f486376e43c8b2c0b8809)
1*57e252bfSMichael Neumann /*
2*57e252bfSMichael Neumann  * Copyright 2012 Advanced Micro Devices, Inc.
3*57e252bfSMichael Neumann  *
4*57e252bfSMichael Neumann  * Permission is hereby granted, free of charge, to any person obtaining a
5*57e252bfSMichael Neumann  * copy of this software and associated documentation files (the "Software"),
6*57e252bfSMichael Neumann  * to deal in the Software without restriction, including without limitation
7*57e252bfSMichael Neumann  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*57e252bfSMichael Neumann  * and/or sell copies of the Software, and to permit persons to whom the
9*57e252bfSMichael Neumann  * Software is furnished to do so, subject to the following conditions:
10*57e252bfSMichael Neumann  *
11*57e252bfSMichael Neumann  * The above copyright notice and this permission notice shall be included in
12*57e252bfSMichael Neumann  * all copies or substantial portions of the Software.
13*57e252bfSMichael Neumann  *
14*57e252bfSMichael Neumann  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*57e252bfSMichael Neumann  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*57e252bfSMichael Neumann  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17*57e252bfSMichael Neumann  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18*57e252bfSMichael Neumann  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19*57e252bfSMichael Neumann  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20*57e252bfSMichael Neumann  * OTHER DEALINGS IN THE SOFTWARE.
21*57e252bfSMichael Neumann  *
22*57e252bfSMichael Neumann  */
23*57e252bfSMichael Neumann #ifndef __NI_DPM_H__
24*57e252bfSMichael Neumann #define __NI_DPM_H__
25*57e252bfSMichael Neumann 
26*57e252bfSMichael Neumann #include "cypress_dpm.h"
27*57e252bfSMichael Neumann #include "btc_dpm.h"
28*57e252bfSMichael Neumann #include "nislands_smc.h"
29*57e252bfSMichael Neumann 
30*57e252bfSMichael Neumann struct ni_clock_registers {
31*57e252bfSMichael Neumann 	u32 cg_spll_func_cntl;
32*57e252bfSMichael Neumann 	u32 cg_spll_func_cntl_2;
33*57e252bfSMichael Neumann 	u32 cg_spll_func_cntl_3;
34*57e252bfSMichael Neumann 	u32 cg_spll_func_cntl_4;
35*57e252bfSMichael Neumann 	u32 cg_spll_spread_spectrum;
36*57e252bfSMichael Neumann 	u32 cg_spll_spread_spectrum_2;
37*57e252bfSMichael Neumann 	u32 mclk_pwrmgt_cntl;
38*57e252bfSMichael Neumann 	u32 dll_cntl;
39*57e252bfSMichael Neumann 	u32 mpll_ad_func_cntl;
40*57e252bfSMichael Neumann 	u32 mpll_ad_func_cntl_2;
41*57e252bfSMichael Neumann 	u32 mpll_dq_func_cntl;
42*57e252bfSMichael Neumann 	u32 mpll_dq_func_cntl_2;
43*57e252bfSMichael Neumann 	u32 mpll_ss1;
44*57e252bfSMichael Neumann 	u32 mpll_ss2;
45*57e252bfSMichael Neumann };
46*57e252bfSMichael Neumann 
47*57e252bfSMichael Neumann struct ni_mc_reg_entry {
48*57e252bfSMichael Neumann 	u32 mclk_max;
49*57e252bfSMichael Neumann 	u32 mc_data[SMC_NISLANDS_MC_REGISTER_ARRAY_SIZE];
50*57e252bfSMichael Neumann };
51*57e252bfSMichael Neumann 
52*57e252bfSMichael Neumann struct ni_mc_reg_table {
53*57e252bfSMichael Neumann 	u8 last;
54*57e252bfSMichael Neumann 	u8 num_entries;
55*57e252bfSMichael Neumann 	u16 valid_flag;
56*57e252bfSMichael Neumann 	struct ni_mc_reg_entry mc_reg_table_entry[MAX_AC_TIMING_ENTRIES];
57*57e252bfSMichael Neumann 	SMC_NIslands_MCRegisterAddress mc_reg_address[SMC_NISLANDS_MC_REGISTER_ARRAY_SIZE];
58*57e252bfSMichael Neumann };
59*57e252bfSMichael Neumann 
60*57e252bfSMichael Neumann #define NISLANDS_MCREGISTERTABLE_FIRST_DRIVERSTATE_SLOT 2
61*57e252bfSMichael Neumann 
62*57e252bfSMichael Neumann enum ni_dc_cac_level
63*57e252bfSMichael Neumann {
64*57e252bfSMichael Neumann 	NISLANDS_DCCAC_LEVEL_0 = 0,
65*57e252bfSMichael Neumann 	NISLANDS_DCCAC_LEVEL_1,
66*57e252bfSMichael Neumann 	NISLANDS_DCCAC_LEVEL_2,
67*57e252bfSMichael Neumann 	NISLANDS_DCCAC_LEVEL_3,
68*57e252bfSMichael Neumann 	NISLANDS_DCCAC_LEVEL_4,
69*57e252bfSMichael Neumann 	NISLANDS_DCCAC_LEVEL_5,
70*57e252bfSMichael Neumann 	NISLANDS_DCCAC_LEVEL_6,
71*57e252bfSMichael Neumann 	NISLANDS_DCCAC_LEVEL_7,
72*57e252bfSMichael Neumann 	NISLANDS_DCCAC_MAX_LEVELS
73*57e252bfSMichael Neumann };
74*57e252bfSMichael Neumann 
75*57e252bfSMichael Neumann struct ni_leakage_coeffients
76*57e252bfSMichael Neumann {
77*57e252bfSMichael Neumann 	u32 at;
78*57e252bfSMichael Neumann 	u32 bt;
79*57e252bfSMichael Neumann 	u32 av;
80*57e252bfSMichael Neumann 	u32 bv;
81*57e252bfSMichael Neumann 	s32 t_slope;
82*57e252bfSMichael Neumann 	s32 t_intercept;
83*57e252bfSMichael Neumann 	u32 t_ref;
84*57e252bfSMichael Neumann };
85*57e252bfSMichael Neumann 
86*57e252bfSMichael Neumann struct ni_cac_data
87*57e252bfSMichael Neumann {
88*57e252bfSMichael Neumann 	struct ni_leakage_coeffients leakage_coefficients;
89*57e252bfSMichael Neumann 	u32 i_leakage;
90*57e252bfSMichael Neumann 	s32 leakage_minimum_temperature;
91*57e252bfSMichael Neumann 	u32 pwr_const;
92*57e252bfSMichael Neumann 	u32 dc_cac_value;
93*57e252bfSMichael Neumann 	u32 bif_cac_value;
94*57e252bfSMichael Neumann 	u32 lkge_pwr;
95*57e252bfSMichael Neumann 	u8 mc_wr_weight;
96*57e252bfSMichael Neumann 	u8 mc_rd_weight;
97*57e252bfSMichael Neumann 	u8 allow_ovrflw;
98*57e252bfSMichael Neumann 	u8 num_win_tdp;
99*57e252bfSMichael Neumann 	u8 l2num_win_tdp;
100*57e252bfSMichael Neumann 	u8 lts_truncate_n;
101*57e252bfSMichael Neumann };
102*57e252bfSMichael Neumann 
103*57e252bfSMichael Neumann struct ni_cac_weights
104*57e252bfSMichael Neumann {
105*57e252bfSMichael Neumann 	u32 weight_tcp_sig0;
106*57e252bfSMichael Neumann 	u32 weight_tcp_sig1;
107*57e252bfSMichael Neumann 	u32 weight_ta_sig;
108*57e252bfSMichael Neumann 	u32 weight_tcc_en0;
109*57e252bfSMichael Neumann 	u32 weight_tcc_en1;
110*57e252bfSMichael Neumann 	u32 weight_tcc_en2;
111*57e252bfSMichael Neumann 	u32 weight_cb_en0;
112*57e252bfSMichael Neumann 	u32 weight_cb_en1;
113*57e252bfSMichael Neumann 	u32 weight_cb_en2;
114*57e252bfSMichael Neumann 	u32 weight_cb_en3;
115*57e252bfSMichael Neumann 	u32 weight_db_sig0;
116*57e252bfSMichael Neumann 	u32 weight_db_sig1;
117*57e252bfSMichael Neumann 	u32 weight_db_sig2;
118*57e252bfSMichael Neumann 	u32 weight_db_sig3;
119*57e252bfSMichael Neumann 	u32 weight_sxm_sig0;
120*57e252bfSMichael Neumann 	u32 weight_sxm_sig1;
121*57e252bfSMichael Neumann 	u32 weight_sxm_sig2;
122*57e252bfSMichael Neumann 	u32 weight_sxs_sig0;
123*57e252bfSMichael Neumann 	u32 weight_sxs_sig1;
124*57e252bfSMichael Neumann 	u32 weight_xbr_0;
125*57e252bfSMichael Neumann 	u32 weight_xbr_1;
126*57e252bfSMichael Neumann 	u32 weight_xbr_2;
127*57e252bfSMichael Neumann 	u32 weight_spi_sig0;
128*57e252bfSMichael Neumann 	u32 weight_spi_sig1;
129*57e252bfSMichael Neumann 	u32 weight_spi_sig2;
130*57e252bfSMichael Neumann 	u32 weight_spi_sig3;
131*57e252bfSMichael Neumann 	u32 weight_spi_sig4;
132*57e252bfSMichael Neumann 	u32 weight_spi_sig5;
133*57e252bfSMichael Neumann 	u32 weight_lds_sig0;
134*57e252bfSMichael Neumann 	u32 weight_lds_sig1;
135*57e252bfSMichael Neumann 	u32 weight_sc;
136*57e252bfSMichael Neumann 	u32 weight_bif;
137*57e252bfSMichael Neumann 	u32 weight_cp;
138*57e252bfSMichael Neumann 	u32 weight_pa_sig0;
139*57e252bfSMichael Neumann 	u32 weight_pa_sig1;
140*57e252bfSMichael Neumann 	u32 weight_vgt_sig0;
141*57e252bfSMichael Neumann 	u32 weight_vgt_sig1;
142*57e252bfSMichael Neumann 	u32 weight_vgt_sig2;
143*57e252bfSMichael Neumann 	u32 weight_dc_sig0;
144*57e252bfSMichael Neumann 	u32 weight_dc_sig1;
145*57e252bfSMichael Neumann 	u32 weight_dc_sig2;
146*57e252bfSMichael Neumann 	u32 weight_dc_sig3;
147*57e252bfSMichael Neumann 	u32 weight_uvd_sig0;
148*57e252bfSMichael Neumann 	u32 weight_uvd_sig1;
149*57e252bfSMichael Neumann 	u32 weight_spare0;
150*57e252bfSMichael Neumann 	u32 weight_spare1;
151*57e252bfSMichael Neumann 	u32 weight_sq_vsp;
152*57e252bfSMichael Neumann 	u32 weight_sq_vsp0;
153*57e252bfSMichael Neumann 	u32 weight_sq_gpr;
154*57e252bfSMichael Neumann 	u32 ovr_mode_spare_0;
155*57e252bfSMichael Neumann 	u32 ovr_val_spare_0;
156*57e252bfSMichael Neumann 	u32 ovr_mode_spare_1;
157*57e252bfSMichael Neumann 	u32 ovr_val_spare_1;
158*57e252bfSMichael Neumann 	u32 vsp;
159*57e252bfSMichael Neumann 	u32 vsp0;
160*57e252bfSMichael Neumann 	u32 gpr;
161*57e252bfSMichael Neumann 	u8 mc_read_weight;
162*57e252bfSMichael Neumann 	u8 mc_write_weight;
163*57e252bfSMichael Neumann 	u32 tid_cnt;
164*57e252bfSMichael Neumann 	u32 tid_unit;
165*57e252bfSMichael Neumann 	u32 l2_lta_window_size;
166*57e252bfSMichael Neumann 	u32 lts_truncate;
167*57e252bfSMichael Neumann 	u32 dc_cac[NISLANDS_DCCAC_MAX_LEVELS];
168*57e252bfSMichael Neumann 	u32 pcie_cac[SMC_NISLANDS_BIF_LUT_NUM_OF_ENTRIES];
169*57e252bfSMichael Neumann 	bool enable_power_containment_by_default;
170*57e252bfSMichael Neumann };
171*57e252bfSMichael Neumann 
172*57e252bfSMichael Neumann struct ni_ps {
173*57e252bfSMichael Neumann 	u16 performance_level_count;
174*57e252bfSMichael Neumann 	bool dc_compatible;
175*57e252bfSMichael Neumann 	struct rv7xx_pl performance_levels[NISLANDS_MAX_SMC_PERFORMANCE_LEVELS_PER_SWSTATE];
176*57e252bfSMichael Neumann };
177*57e252bfSMichael Neumann 
178*57e252bfSMichael Neumann struct ni_power_info {
179*57e252bfSMichael Neumann 	/* must be first! */
180*57e252bfSMichael Neumann 	struct evergreen_power_info eg;
181*57e252bfSMichael Neumann 	struct ni_clock_registers clock_registers;
182*57e252bfSMichael Neumann 	struct ni_mc_reg_table mc_reg_table;
183*57e252bfSMichael Neumann 	u32 mclk_rtt_mode_threshold;
184*57e252bfSMichael Neumann 	/* flags */
185*57e252bfSMichael Neumann 	bool use_power_boost_limit;
186*57e252bfSMichael Neumann 	bool support_cac_long_term_average;
187*57e252bfSMichael Neumann 	bool cac_enabled;
188*57e252bfSMichael Neumann 	bool cac_configuration_required;
189*57e252bfSMichael Neumann 	bool driver_calculate_cac_leakage;
190*57e252bfSMichael Neumann 	bool pc_enabled;
191*57e252bfSMichael Neumann 	bool enable_power_containment;
192*57e252bfSMichael Neumann 	bool enable_cac;
193*57e252bfSMichael Neumann 	bool enable_sq_ramping;
194*57e252bfSMichael Neumann 	/* smc offsets */
195*57e252bfSMichael Neumann 	u16 arb_table_start;
196*57e252bfSMichael Neumann 	u16 fan_table_start;
197*57e252bfSMichael Neumann 	u16 cac_table_start;
198*57e252bfSMichael Neumann 	u16 spll_table_start;
199*57e252bfSMichael Neumann 	/* CAC stuff */
200*57e252bfSMichael Neumann 	struct ni_cac_data cac_data;
201*57e252bfSMichael Neumann 	u32 dc_cac_table[NISLANDS_DCCAC_MAX_LEVELS];
202*57e252bfSMichael Neumann 	const struct ni_cac_weights *cac_weights;
203*57e252bfSMichael Neumann 	u8 lta_window_size;
204*57e252bfSMichael Neumann 	u8 lts_truncate;
205*57e252bfSMichael Neumann 	struct ni_ps current_ps;
206*57e252bfSMichael Neumann 	struct ni_ps requested_ps;
207*57e252bfSMichael Neumann 	/* scratch structs */
208*57e252bfSMichael Neumann 	SMC_NIslands_MCRegisters smc_mc_reg_table;
209*57e252bfSMichael Neumann 	NISLANDS_SMC_STATETABLE smc_statetable;
210*57e252bfSMichael Neumann };
211*57e252bfSMichael Neumann 
212*57e252bfSMichael Neumann #define NISLANDS_INITIAL_STATE_ARB_INDEX    0
213*57e252bfSMichael Neumann #define NISLANDS_ACPI_STATE_ARB_INDEX       1
214*57e252bfSMichael Neumann #define NISLANDS_ULV_STATE_ARB_INDEX        2
215*57e252bfSMichael Neumann #define NISLANDS_DRIVER_STATE_ARB_INDEX     3
216*57e252bfSMichael Neumann 
217*57e252bfSMichael Neumann #define NISLANDS_DPM2_MAX_PULSE_SKIP        256
218*57e252bfSMichael Neumann 
219*57e252bfSMichael Neumann #define NISLANDS_DPM2_NEAR_TDP_DEC          10
220*57e252bfSMichael Neumann #define NISLANDS_DPM2_ABOVE_SAFE_INC        5
221*57e252bfSMichael Neumann #define NISLANDS_DPM2_BELOW_SAFE_INC        20
222*57e252bfSMichael Neumann 
223*57e252bfSMichael Neumann #define NISLANDS_DPM2_TDP_SAFE_LIMIT_PERCENT            80
224*57e252bfSMichael Neumann 
225*57e252bfSMichael Neumann #define NISLANDS_DPM2_MAXPS_PERCENT_H                   90
226*57e252bfSMichael Neumann #define NISLANDS_DPM2_MAXPS_PERCENT_M                   0
227*57e252bfSMichael Neumann 
228*57e252bfSMichael Neumann #define NISLANDS_DPM2_SQ_RAMP_MAX_POWER                 0x3FFF
229*57e252bfSMichael Neumann #define NISLANDS_DPM2_SQ_RAMP_MIN_POWER                 0x12
230*57e252bfSMichael Neumann #define NISLANDS_DPM2_SQ_RAMP_MAX_POWER_DELTA           0x15
231*57e252bfSMichael Neumann #define NISLANDS_DPM2_SQ_RAMP_STI_SIZE                  0x1E
232*57e252bfSMichael Neumann #define NISLANDS_DPM2_SQ_RAMP_LTI_RATIO                 0xF
233*57e252bfSMichael Neumann 
234*57e252bfSMichael Neumann int ni_copy_and_switch_arb_sets(struct radeon_device *rdev,
235*57e252bfSMichael Neumann 				u32 arb_freq_src, u32 arb_freq_dest);
236*57e252bfSMichael Neumann void ni_update_current_ps(struct radeon_device *rdev,
237*57e252bfSMichael Neumann 			  struct radeon_ps *rps);
238*57e252bfSMichael Neumann void ni_update_requested_ps(struct radeon_device *rdev,
239*57e252bfSMichael Neumann 			    struct radeon_ps *rps);
240*57e252bfSMichael Neumann 
241*57e252bfSMichael Neumann void ni_set_uvd_clock_before_set_eng_clock(struct radeon_device *rdev,
242*57e252bfSMichael Neumann 					   struct radeon_ps *new_ps,
243*57e252bfSMichael Neumann 					   struct radeon_ps *old_ps);
244*57e252bfSMichael Neumann void ni_set_uvd_clock_after_set_eng_clock(struct radeon_device *rdev,
245*57e252bfSMichael Neumann 					  struct radeon_ps *new_ps,
246*57e252bfSMichael Neumann 					  struct radeon_ps *old_ps);
247*57e252bfSMichael Neumann 
248*57e252bfSMichael Neumann bool ni_dpm_vblank_too_short(struct radeon_device *rdev);
249*57e252bfSMichael Neumann 
250*57e252bfSMichael Neumann #endif
251