xref: /openbmc/linux/drivers/gpu/drm/radeon/ni_dpm.h (revision d434e81e)
169e0b57aSAlex Deucher /*
269e0b57aSAlex Deucher  * Copyright 2012 Advanced Micro Devices, Inc.
369e0b57aSAlex Deucher  *
469e0b57aSAlex Deucher  * Permission is hereby granted, free of charge, to any person obtaining a
569e0b57aSAlex Deucher  * copy of this software and associated documentation files (the "Software"),
669e0b57aSAlex Deucher  * to deal in the Software without restriction, including without limitation
769e0b57aSAlex Deucher  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
869e0b57aSAlex Deucher  * and/or sell copies of the Software, and to permit persons to whom the
969e0b57aSAlex Deucher  * Software is furnished to do so, subject to the following conditions:
1069e0b57aSAlex Deucher  *
1169e0b57aSAlex Deucher  * The above copyright notice and this permission notice shall be included in
1269e0b57aSAlex Deucher  * all copies or substantial portions of the Software.
1369e0b57aSAlex Deucher  *
1469e0b57aSAlex Deucher  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1569e0b57aSAlex Deucher  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1669e0b57aSAlex Deucher  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1769e0b57aSAlex Deucher  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
1869e0b57aSAlex Deucher  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1969e0b57aSAlex Deucher  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2069e0b57aSAlex Deucher  * OTHER DEALINGS IN THE SOFTWARE.
2169e0b57aSAlex Deucher  *
2269e0b57aSAlex Deucher  */
2369e0b57aSAlex Deucher #ifndef __NI_DPM_H__
2469e0b57aSAlex Deucher #define __NI_DPM_H__
2569e0b57aSAlex Deucher 
2669e0b57aSAlex Deucher #include "cypress_dpm.h"
2769e0b57aSAlex Deucher #include "btc_dpm.h"
2869e0b57aSAlex Deucher #include "nislands_smc.h"
2969e0b57aSAlex Deucher 
3069e0b57aSAlex Deucher struct ni_clock_registers {
3169e0b57aSAlex Deucher 	u32 cg_spll_func_cntl;
3269e0b57aSAlex Deucher 	u32 cg_spll_func_cntl_2;
3369e0b57aSAlex Deucher 	u32 cg_spll_func_cntl_3;
3469e0b57aSAlex Deucher 	u32 cg_spll_func_cntl_4;
3569e0b57aSAlex Deucher 	u32 cg_spll_spread_spectrum;
3669e0b57aSAlex Deucher 	u32 cg_spll_spread_spectrum_2;
3769e0b57aSAlex Deucher 	u32 mclk_pwrmgt_cntl;
3869e0b57aSAlex Deucher 	u32 dll_cntl;
3969e0b57aSAlex Deucher 	u32 mpll_ad_func_cntl;
4069e0b57aSAlex Deucher 	u32 mpll_ad_func_cntl_2;
4169e0b57aSAlex Deucher 	u32 mpll_dq_func_cntl;
4269e0b57aSAlex Deucher 	u32 mpll_dq_func_cntl_2;
4369e0b57aSAlex Deucher 	u32 mpll_ss1;
4469e0b57aSAlex Deucher 	u32 mpll_ss2;
4569e0b57aSAlex Deucher };
4669e0b57aSAlex Deucher 
4769e0b57aSAlex Deucher struct ni_mc_reg_entry {
4869e0b57aSAlex Deucher 	u32 mclk_max;
4969e0b57aSAlex Deucher 	u32 mc_data[SMC_NISLANDS_MC_REGISTER_ARRAY_SIZE];
5069e0b57aSAlex Deucher };
5169e0b57aSAlex Deucher 
5269e0b57aSAlex Deucher struct ni_mc_reg_table {
5369e0b57aSAlex Deucher 	u8 last;
5469e0b57aSAlex Deucher 	u8 num_entries;
5569e0b57aSAlex Deucher 	u16 valid_flag;
5669e0b57aSAlex Deucher 	struct ni_mc_reg_entry mc_reg_table_entry[MAX_AC_TIMING_ENTRIES];
5769e0b57aSAlex Deucher 	SMC_NIslands_MCRegisterAddress mc_reg_address[SMC_NISLANDS_MC_REGISTER_ARRAY_SIZE];
5869e0b57aSAlex Deucher };
5969e0b57aSAlex Deucher 
6069e0b57aSAlex Deucher #define NISLANDS_MCREGISTERTABLE_FIRST_DRIVERSTATE_SLOT 2
6169e0b57aSAlex Deucher 
6269e0b57aSAlex Deucher enum ni_dc_cac_level
6369e0b57aSAlex Deucher {
6469e0b57aSAlex Deucher 	NISLANDS_DCCAC_LEVEL_0 = 0,
6569e0b57aSAlex Deucher 	NISLANDS_DCCAC_LEVEL_1,
6669e0b57aSAlex Deucher 	NISLANDS_DCCAC_LEVEL_2,
6769e0b57aSAlex Deucher 	NISLANDS_DCCAC_LEVEL_3,
6869e0b57aSAlex Deucher 	NISLANDS_DCCAC_LEVEL_4,
6969e0b57aSAlex Deucher 	NISLANDS_DCCAC_LEVEL_5,
7069e0b57aSAlex Deucher 	NISLANDS_DCCAC_LEVEL_6,
7169e0b57aSAlex Deucher 	NISLANDS_DCCAC_LEVEL_7,
7269e0b57aSAlex Deucher 	NISLANDS_DCCAC_MAX_LEVELS
7369e0b57aSAlex Deucher };
7469e0b57aSAlex Deucher 
7569e0b57aSAlex Deucher struct ni_leakage_coeffients
7669e0b57aSAlex Deucher {
7769e0b57aSAlex Deucher 	u32 at;
7869e0b57aSAlex Deucher 	u32 bt;
7969e0b57aSAlex Deucher 	u32 av;
8069e0b57aSAlex Deucher 	u32 bv;
8169e0b57aSAlex Deucher 	s32 t_slope;
8269e0b57aSAlex Deucher 	s32 t_intercept;
8369e0b57aSAlex Deucher 	u32 t_ref;
8469e0b57aSAlex Deucher };
8569e0b57aSAlex Deucher 
8669e0b57aSAlex Deucher struct ni_cac_data
8769e0b57aSAlex Deucher {
8869e0b57aSAlex Deucher 	struct ni_leakage_coeffients leakage_coefficients;
8969e0b57aSAlex Deucher 	u32 i_leakage;
9069e0b57aSAlex Deucher 	s32 leakage_minimum_temperature;
9169e0b57aSAlex Deucher 	u32 pwr_const;
9269e0b57aSAlex Deucher 	u32 dc_cac_value;
9369e0b57aSAlex Deucher 	u32 bif_cac_value;
9469e0b57aSAlex Deucher 	u32 lkge_pwr;
9569e0b57aSAlex Deucher 	u8 mc_wr_weight;
9669e0b57aSAlex Deucher 	u8 mc_rd_weight;
9769e0b57aSAlex Deucher 	u8 allow_ovrflw;
9869e0b57aSAlex Deucher 	u8 num_win_tdp;
9969e0b57aSAlex Deucher 	u8 l2num_win_tdp;
10069e0b57aSAlex Deucher 	u8 lts_truncate_n;
10169e0b57aSAlex Deucher };
10269e0b57aSAlex Deucher 
10369e0b57aSAlex Deucher struct ni_cac_weights
10469e0b57aSAlex Deucher {
10569e0b57aSAlex Deucher 	u32 weight_tcp_sig0;
10669e0b57aSAlex Deucher 	u32 weight_tcp_sig1;
10769e0b57aSAlex Deucher 	u32 weight_ta_sig;
10869e0b57aSAlex Deucher 	u32 weight_tcc_en0;
10969e0b57aSAlex Deucher 	u32 weight_tcc_en1;
11069e0b57aSAlex Deucher 	u32 weight_tcc_en2;
11169e0b57aSAlex Deucher 	u32 weight_cb_en0;
11269e0b57aSAlex Deucher 	u32 weight_cb_en1;
11369e0b57aSAlex Deucher 	u32 weight_cb_en2;
11469e0b57aSAlex Deucher 	u32 weight_cb_en3;
11569e0b57aSAlex Deucher 	u32 weight_db_sig0;
11669e0b57aSAlex Deucher 	u32 weight_db_sig1;
11769e0b57aSAlex Deucher 	u32 weight_db_sig2;
11869e0b57aSAlex Deucher 	u32 weight_db_sig3;
11969e0b57aSAlex Deucher 	u32 weight_sxm_sig0;
12069e0b57aSAlex Deucher 	u32 weight_sxm_sig1;
12169e0b57aSAlex Deucher 	u32 weight_sxm_sig2;
12269e0b57aSAlex Deucher 	u32 weight_sxs_sig0;
12369e0b57aSAlex Deucher 	u32 weight_sxs_sig1;
12469e0b57aSAlex Deucher 	u32 weight_xbr_0;
12569e0b57aSAlex Deucher 	u32 weight_xbr_1;
12669e0b57aSAlex Deucher 	u32 weight_xbr_2;
12769e0b57aSAlex Deucher 	u32 weight_spi_sig0;
12869e0b57aSAlex Deucher 	u32 weight_spi_sig1;
12969e0b57aSAlex Deucher 	u32 weight_spi_sig2;
13069e0b57aSAlex Deucher 	u32 weight_spi_sig3;
13169e0b57aSAlex Deucher 	u32 weight_spi_sig4;
13269e0b57aSAlex Deucher 	u32 weight_spi_sig5;
13369e0b57aSAlex Deucher 	u32 weight_lds_sig0;
13469e0b57aSAlex Deucher 	u32 weight_lds_sig1;
13569e0b57aSAlex Deucher 	u32 weight_sc;
13669e0b57aSAlex Deucher 	u32 weight_bif;
13769e0b57aSAlex Deucher 	u32 weight_cp;
13869e0b57aSAlex Deucher 	u32 weight_pa_sig0;
13969e0b57aSAlex Deucher 	u32 weight_pa_sig1;
14069e0b57aSAlex Deucher 	u32 weight_vgt_sig0;
14169e0b57aSAlex Deucher 	u32 weight_vgt_sig1;
14269e0b57aSAlex Deucher 	u32 weight_vgt_sig2;
14369e0b57aSAlex Deucher 	u32 weight_dc_sig0;
14469e0b57aSAlex Deucher 	u32 weight_dc_sig1;
14569e0b57aSAlex Deucher 	u32 weight_dc_sig2;
14669e0b57aSAlex Deucher 	u32 weight_dc_sig3;
14769e0b57aSAlex Deucher 	u32 weight_uvd_sig0;
14869e0b57aSAlex Deucher 	u32 weight_uvd_sig1;
14969e0b57aSAlex Deucher 	u32 weight_spare0;
15069e0b57aSAlex Deucher 	u32 weight_spare1;
15169e0b57aSAlex Deucher 	u32 weight_sq_vsp;
15269e0b57aSAlex Deucher 	u32 weight_sq_vsp0;
15369e0b57aSAlex Deucher 	u32 weight_sq_gpr;
15469e0b57aSAlex Deucher 	u32 ovr_mode_spare_0;
15569e0b57aSAlex Deucher 	u32 ovr_val_spare_0;
15669e0b57aSAlex Deucher 	u32 ovr_mode_spare_1;
15769e0b57aSAlex Deucher 	u32 ovr_val_spare_1;
15869e0b57aSAlex Deucher 	u32 vsp;
15969e0b57aSAlex Deucher 	u32 vsp0;
16069e0b57aSAlex Deucher 	u32 gpr;
16169e0b57aSAlex Deucher 	u8 mc_read_weight;
16269e0b57aSAlex Deucher 	u8 mc_write_weight;
16369e0b57aSAlex Deucher 	u32 tid_cnt;
16469e0b57aSAlex Deucher 	u32 tid_unit;
16569e0b57aSAlex Deucher 	u32 l2_lta_window_size;
16669e0b57aSAlex Deucher 	u32 lts_truncate;
16769e0b57aSAlex Deucher 	u32 dc_cac[NISLANDS_DCCAC_MAX_LEVELS];
16869e0b57aSAlex Deucher 	u32 pcie_cac[SMC_NISLANDS_BIF_LUT_NUM_OF_ENTRIES];
16969e0b57aSAlex Deucher 	bool enable_power_containment_by_default;
17069e0b57aSAlex Deucher };
17169e0b57aSAlex Deucher 
17269e0b57aSAlex Deucher struct ni_ps {
17369e0b57aSAlex Deucher 	u16 performance_level_count;
17469e0b57aSAlex Deucher 	bool dc_compatible;
17569e0b57aSAlex Deucher 	struct rv7xx_pl performance_levels[NISLANDS_MAX_SMC_PERFORMANCE_LEVELS_PER_SWSTATE];
17669e0b57aSAlex Deucher };
17769e0b57aSAlex Deucher 
17869e0b57aSAlex Deucher struct ni_power_info {
17969e0b57aSAlex Deucher 	/* must be first! */
18069e0b57aSAlex Deucher 	struct evergreen_power_info eg;
18169e0b57aSAlex Deucher 	struct ni_clock_registers clock_registers;
18269e0b57aSAlex Deucher 	struct ni_mc_reg_table mc_reg_table;
18369e0b57aSAlex Deucher 	u32 mclk_rtt_mode_threshold;
18469e0b57aSAlex Deucher 	/* flags */
18569e0b57aSAlex Deucher 	bool use_power_boost_limit;
18669e0b57aSAlex Deucher 	bool support_cac_long_term_average;
18769e0b57aSAlex Deucher 	bool cac_enabled;
18869e0b57aSAlex Deucher 	bool cac_configuration_required;
18969e0b57aSAlex Deucher 	bool driver_calculate_cac_leakage;
19069e0b57aSAlex Deucher 	bool pc_enabled;
19169e0b57aSAlex Deucher 	bool enable_power_containment;
19269e0b57aSAlex Deucher 	bool enable_cac;
19369e0b57aSAlex Deucher 	bool enable_sq_ramping;
19469e0b57aSAlex Deucher 	/* smc offsets */
19569e0b57aSAlex Deucher 	u16 arb_table_start;
19669e0b57aSAlex Deucher 	u16 fan_table_start;
19769e0b57aSAlex Deucher 	u16 cac_table_start;
19869e0b57aSAlex Deucher 	u16 spll_table_start;
19969e0b57aSAlex Deucher 	/* CAC stuff */
20069e0b57aSAlex Deucher 	struct ni_cac_data cac_data;
20169e0b57aSAlex Deucher 	u32 dc_cac_table[NISLANDS_DCCAC_MAX_LEVELS];
20269e0b57aSAlex Deucher 	const struct ni_cac_weights *cac_weights;
20369e0b57aSAlex Deucher 	u8 lta_window_size;
20469e0b57aSAlex Deucher 	u8 lts_truncate;
205fee3d744SAlex Deucher 	struct ni_ps current_ps;
206fee3d744SAlex Deucher 	struct ni_ps requested_ps;
20769e0b57aSAlex Deucher 	/* scratch structs */
20869e0b57aSAlex Deucher 	SMC_NIslands_MCRegisters smc_mc_reg_table;
20969e0b57aSAlex Deucher 	NISLANDS_SMC_STATETABLE smc_statetable;
21069e0b57aSAlex Deucher };
21169e0b57aSAlex Deucher 
21269e0b57aSAlex Deucher #define NISLANDS_INITIAL_STATE_ARB_INDEX    0
21369e0b57aSAlex Deucher #define NISLANDS_ACPI_STATE_ARB_INDEX       1
21469e0b57aSAlex Deucher #define NISLANDS_ULV_STATE_ARB_INDEX        2
21569e0b57aSAlex Deucher #define NISLANDS_DRIVER_STATE_ARB_INDEX     3
21669e0b57aSAlex Deucher 
21769e0b57aSAlex Deucher #define NISLANDS_DPM2_MAX_PULSE_SKIP        256
21869e0b57aSAlex Deucher 
21969e0b57aSAlex Deucher #define NISLANDS_DPM2_NEAR_TDP_DEC          10
22069e0b57aSAlex Deucher #define NISLANDS_DPM2_ABOVE_SAFE_INC        5
22169e0b57aSAlex Deucher #define NISLANDS_DPM2_BELOW_SAFE_INC        20
22269e0b57aSAlex Deucher 
22369e0b57aSAlex Deucher #define NISLANDS_DPM2_TDP_SAFE_LIMIT_PERCENT            80
22469e0b57aSAlex Deucher 
22569e0b57aSAlex Deucher #define NISLANDS_DPM2_MAXPS_PERCENT_H                   90
22669e0b57aSAlex Deucher #define NISLANDS_DPM2_MAXPS_PERCENT_M                   0
22769e0b57aSAlex Deucher 
22869e0b57aSAlex Deucher #define NISLANDS_DPM2_SQ_RAMP_MAX_POWER                 0x3FFF
22969e0b57aSAlex Deucher #define NISLANDS_DPM2_SQ_RAMP_MIN_POWER                 0x12
23069e0b57aSAlex Deucher #define NISLANDS_DPM2_SQ_RAMP_MAX_POWER_DELTA           0x15
23169e0b57aSAlex Deucher #define NISLANDS_DPM2_SQ_RAMP_STI_SIZE                  0x1E
23269e0b57aSAlex Deucher #define NISLANDS_DPM2_SQ_RAMP_LTI_RATIO                 0xF
23369e0b57aSAlex Deucher 
234a9e61410SAlex Deucher int ni_copy_and_switch_arb_sets(struct radeon_device *rdev,
235a9e61410SAlex Deucher 				u32 arb_freq_src, u32 arb_freq_dest);
236a9e61410SAlex Deucher void ni_update_current_ps(struct radeon_device *rdev,
237a9e61410SAlex Deucher 			  struct radeon_ps *rps);
238a9e61410SAlex Deucher void ni_update_requested_ps(struct radeon_device *rdev,
239a9e61410SAlex Deucher 			    struct radeon_ps *rps);
240a9e61410SAlex Deucher 
241d434e81eSAlex Deucher void ni_set_uvd_clock_before_set_eng_clock(struct radeon_device *rdev,
242d434e81eSAlex Deucher 					   struct radeon_ps *new_ps,
243d434e81eSAlex Deucher 					   struct radeon_ps *old_ps);
244d434e81eSAlex Deucher void ni_set_uvd_clock_after_set_eng_clock(struct radeon_device *rdev,
245d434e81eSAlex Deucher 					  struct radeon_ps *new_ps,
246d434e81eSAlex Deucher 					  struct radeon_ps *old_ps);
247d434e81eSAlex Deucher 
24869e0b57aSAlex Deucher #endif
249