18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright 2012 Advanced Micro Devices, Inc. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 128c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software. 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 158c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 168c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 178c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 188c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 198c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 208c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 218c2ecf20Sopenharmony_ci * 228c2ecf20Sopenharmony_ci */ 238c2ecf20Sopenharmony_ci#ifndef __NI_DPM_H__ 248c2ecf20Sopenharmony_ci#define __NI_DPM_H__ 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci#include "cypress_dpm.h" 278c2ecf20Sopenharmony_ci#include "btc_dpm.h" 288c2ecf20Sopenharmony_ci#include "nislands_smc.h" 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_cistruct ni_clock_registers { 318c2ecf20Sopenharmony_ci u32 cg_spll_func_cntl; 328c2ecf20Sopenharmony_ci u32 cg_spll_func_cntl_2; 338c2ecf20Sopenharmony_ci u32 cg_spll_func_cntl_3; 348c2ecf20Sopenharmony_ci u32 cg_spll_func_cntl_4; 358c2ecf20Sopenharmony_ci u32 cg_spll_spread_spectrum; 368c2ecf20Sopenharmony_ci u32 cg_spll_spread_spectrum_2; 378c2ecf20Sopenharmony_ci u32 mclk_pwrmgt_cntl; 388c2ecf20Sopenharmony_ci u32 dll_cntl; 398c2ecf20Sopenharmony_ci u32 mpll_ad_func_cntl; 408c2ecf20Sopenharmony_ci u32 mpll_ad_func_cntl_2; 418c2ecf20Sopenharmony_ci u32 mpll_dq_func_cntl; 428c2ecf20Sopenharmony_ci u32 mpll_dq_func_cntl_2; 438c2ecf20Sopenharmony_ci u32 mpll_ss1; 448c2ecf20Sopenharmony_ci u32 mpll_ss2; 458c2ecf20Sopenharmony_ci}; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_cistruct ni_mc_reg_entry { 488c2ecf20Sopenharmony_ci u32 mclk_max; 498c2ecf20Sopenharmony_ci u32 mc_data[SMC_NISLANDS_MC_REGISTER_ARRAY_SIZE]; 508c2ecf20Sopenharmony_ci}; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistruct ni_mc_reg_table { 538c2ecf20Sopenharmony_ci u8 last; 548c2ecf20Sopenharmony_ci u8 num_entries; 558c2ecf20Sopenharmony_ci u16 valid_flag; 568c2ecf20Sopenharmony_ci struct ni_mc_reg_entry mc_reg_table_entry[MAX_AC_TIMING_ENTRIES]; 578c2ecf20Sopenharmony_ci SMC_NIslands_MCRegisterAddress mc_reg_address[SMC_NISLANDS_MC_REGISTER_ARRAY_SIZE]; 588c2ecf20Sopenharmony_ci}; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci#define NISLANDS_MCREGISTERTABLE_FIRST_DRIVERSTATE_SLOT 2 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_cienum ni_dc_cac_level 638c2ecf20Sopenharmony_ci{ 648c2ecf20Sopenharmony_ci NISLANDS_DCCAC_LEVEL_0 = 0, 658c2ecf20Sopenharmony_ci NISLANDS_DCCAC_LEVEL_1, 668c2ecf20Sopenharmony_ci NISLANDS_DCCAC_LEVEL_2, 678c2ecf20Sopenharmony_ci NISLANDS_DCCAC_LEVEL_3, 688c2ecf20Sopenharmony_ci NISLANDS_DCCAC_LEVEL_4, 698c2ecf20Sopenharmony_ci NISLANDS_DCCAC_LEVEL_5, 708c2ecf20Sopenharmony_ci NISLANDS_DCCAC_LEVEL_6, 718c2ecf20Sopenharmony_ci NISLANDS_DCCAC_LEVEL_7, 728c2ecf20Sopenharmony_ci NISLANDS_DCCAC_MAX_LEVELS 738c2ecf20Sopenharmony_ci}; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_cistruct ni_leakage_coeffients 768c2ecf20Sopenharmony_ci{ 778c2ecf20Sopenharmony_ci u32 at; 788c2ecf20Sopenharmony_ci u32 bt; 798c2ecf20Sopenharmony_ci u32 av; 808c2ecf20Sopenharmony_ci u32 bv; 818c2ecf20Sopenharmony_ci s32 t_slope; 828c2ecf20Sopenharmony_ci s32 t_intercept; 838c2ecf20Sopenharmony_ci u32 t_ref; 848c2ecf20Sopenharmony_ci}; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_cistruct ni_cac_data 878c2ecf20Sopenharmony_ci{ 888c2ecf20Sopenharmony_ci struct ni_leakage_coeffients leakage_coefficients; 898c2ecf20Sopenharmony_ci u32 i_leakage; 908c2ecf20Sopenharmony_ci s32 leakage_minimum_temperature; 918c2ecf20Sopenharmony_ci u32 pwr_const; 928c2ecf20Sopenharmony_ci u32 dc_cac_value; 938c2ecf20Sopenharmony_ci u32 bif_cac_value; 948c2ecf20Sopenharmony_ci u32 lkge_pwr; 958c2ecf20Sopenharmony_ci u8 mc_wr_weight; 968c2ecf20Sopenharmony_ci u8 mc_rd_weight; 978c2ecf20Sopenharmony_ci u8 allow_ovrflw; 988c2ecf20Sopenharmony_ci u8 num_win_tdp; 998c2ecf20Sopenharmony_ci u8 l2num_win_tdp; 1008c2ecf20Sopenharmony_ci u8 lts_truncate_n; 1018c2ecf20Sopenharmony_ci}; 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_cistruct ni_cac_weights 1048c2ecf20Sopenharmony_ci{ 1058c2ecf20Sopenharmony_ci u32 weight_tcp_sig0; 1068c2ecf20Sopenharmony_ci u32 weight_tcp_sig1; 1078c2ecf20Sopenharmony_ci u32 weight_ta_sig; 1088c2ecf20Sopenharmony_ci u32 weight_tcc_en0; 1098c2ecf20Sopenharmony_ci u32 weight_tcc_en1; 1108c2ecf20Sopenharmony_ci u32 weight_tcc_en2; 1118c2ecf20Sopenharmony_ci u32 weight_cb_en0; 1128c2ecf20Sopenharmony_ci u32 weight_cb_en1; 1138c2ecf20Sopenharmony_ci u32 weight_cb_en2; 1148c2ecf20Sopenharmony_ci u32 weight_cb_en3; 1158c2ecf20Sopenharmony_ci u32 weight_db_sig0; 1168c2ecf20Sopenharmony_ci u32 weight_db_sig1; 1178c2ecf20Sopenharmony_ci u32 weight_db_sig2; 1188c2ecf20Sopenharmony_ci u32 weight_db_sig3; 1198c2ecf20Sopenharmony_ci u32 weight_sxm_sig0; 1208c2ecf20Sopenharmony_ci u32 weight_sxm_sig1; 1218c2ecf20Sopenharmony_ci u32 weight_sxm_sig2; 1228c2ecf20Sopenharmony_ci u32 weight_sxs_sig0; 1238c2ecf20Sopenharmony_ci u32 weight_sxs_sig1; 1248c2ecf20Sopenharmony_ci u32 weight_xbr_0; 1258c2ecf20Sopenharmony_ci u32 weight_xbr_1; 1268c2ecf20Sopenharmony_ci u32 weight_xbr_2; 1278c2ecf20Sopenharmony_ci u32 weight_spi_sig0; 1288c2ecf20Sopenharmony_ci u32 weight_spi_sig1; 1298c2ecf20Sopenharmony_ci u32 weight_spi_sig2; 1308c2ecf20Sopenharmony_ci u32 weight_spi_sig3; 1318c2ecf20Sopenharmony_ci u32 weight_spi_sig4; 1328c2ecf20Sopenharmony_ci u32 weight_spi_sig5; 1338c2ecf20Sopenharmony_ci u32 weight_lds_sig0; 1348c2ecf20Sopenharmony_ci u32 weight_lds_sig1; 1358c2ecf20Sopenharmony_ci u32 weight_sc; 1368c2ecf20Sopenharmony_ci u32 weight_bif; 1378c2ecf20Sopenharmony_ci u32 weight_cp; 1388c2ecf20Sopenharmony_ci u32 weight_pa_sig0; 1398c2ecf20Sopenharmony_ci u32 weight_pa_sig1; 1408c2ecf20Sopenharmony_ci u32 weight_vgt_sig0; 1418c2ecf20Sopenharmony_ci u32 weight_vgt_sig1; 1428c2ecf20Sopenharmony_ci u32 weight_vgt_sig2; 1438c2ecf20Sopenharmony_ci u32 weight_dc_sig0; 1448c2ecf20Sopenharmony_ci u32 weight_dc_sig1; 1458c2ecf20Sopenharmony_ci u32 weight_dc_sig2; 1468c2ecf20Sopenharmony_ci u32 weight_dc_sig3; 1478c2ecf20Sopenharmony_ci u32 weight_uvd_sig0; 1488c2ecf20Sopenharmony_ci u32 weight_uvd_sig1; 1498c2ecf20Sopenharmony_ci u32 weight_spare0; 1508c2ecf20Sopenharmony_ci u32 weight_spare1; 1518c2ecf20Sopenharmony_ci u32 weight_sq_vsp; 1528c2ecf20Sopenharmony_ci u32 weight_sq_vsp0; 1538c2ecf20Sopenharmony_ci u32 weight_sq_gpr; 1548c2ecf20Sopenharmony_ci u32 ovr_mode_spare_0; 1558c2ecf20Sopenharmony_ci u32 ovr_val_spare_0; 1568c2ecf20Sopenharmony_ci u32 ovr_mode_spare_1; 1578c2ecf20Sopenharmony_ci u32 ovr_val_spare_1; 1588c2ecf20Sopenharmony_ci u32 vsp; 1598c2ecf20Sopenharmony_ci u32 vsp0; 1608c2ecf20Sopenharmony_ci u32 gpr; 1618c2ecf20Sopenharmony_ci u8 mc_read_weight; 1628c2ecf20Sopenharmony_ci u8 mc_write_weight; 1638c2ecf20Sopenharmony_ci u32 tid_cnt; 1648c2ecf20Sopenharmony_ci u32 tid_unit; 1658c2ecf20Sopenharmony_ci u32 l2_lta_window_size; 1668c2ecf20Sopenharmony_ci u32 lts_truncate; 1678c2ecf20Sopenharmony_ci u32 dc_cac[NISLANDS_DCCAC_MAX_LEVELS]; 1688c2ecf20Sopenharmony_ci u32 pcie_cac[SMC_NISLANDS_BIF_LUT_NUM_OF_ENTRIES]; 1698c2ecf20Sopenharmony_ci bool enable_power_containment_by_default; 1708c2ecf20Sopenharmony_ci}; 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_cistruct ni_ps { 1738c2ecf20Sopenharmony_ci u16 performance_level_count; 1748c2ecf20Sopenharmony_ci bool dc_compatible; 1758c2ecf20Sopenharmony_ci struct rv7xx_pl performance_levels[NISLANDS_MAX_SMC_PERFORMANCE_LEVELS_PER_SWSTATE]; 1768c2ecf20Sopenharmony_ci}; 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_cistruct ni_power_info { 1798c2ecf20Sopenharmony_ci /* must be first! */ 1808c2ecf20Sopenharmony_ci struct evergreen_power_info eg; 1818c2ecf20Sopenharmony_ci struct ni_clock_registers clock_registers; 1828c2ecf20Sopenharmony_ci struct ni_mc_reg_table mc_reg_table; 1838c2ecf20Sopenharmony_ci u32 mclk_rtt_mode_threshold; 1848c2ecf20Sopenharmony_ci /* flags */ 1858c2ecf20Sopenharmony_ci bool use_power_boost_limit; 1868c2ecf20Sopenharmony_ci bool support_cac_long_term_average; 1878c2ecf20Sopenharmony_ci bool cac_enabled; 1888c2ecf20Sopenharmony_ci bool cac_configuration_required; 1898c2ecf20Sopenharmony_ci bool driver_calculate_cac_leakage; 1908c2ecf20Sopenharmony_ci bool pc_enabled; 1918c2ecf20Sopenharmony_ci bool enable_power_containment; 1928c2ecf20Sopenharmony_ci bool enable_cac; 1938c2ecf20Sopenharmony_ci bool enable_sq_ramping; 1948c2ecf20Sopenharmony_ci /* smc offsets */ 1958c2ecf20Sopenharmony_ci u16 arb_table_start; 1968c2ecf20Sopenharmony_ci u16 fan_table_start; 1978c2ecf20Sopenharmony_ci u16 cac_table_start; 1988c2ecf20Sopenharmony_ci u16 spll_table_start; 1998c2ecf20Sopenharmony_ci /* CAC stuff */ 2008c2ecf20Sopenharmony_ci struct ni_cac_data cac_data; 2018c2ecf20Sopenharmony_ci u32 dc_cac_table[NISLANDS_DCCAC_MAX_LEVELS]; 2028c2ecf20Sopenharmony_ci const struct ni_cac_weights *cac_weights; 2038c2ecf20Sopenharmony_ci u8 lta_window_size; 2048c2ecf20Sopenharmony_ci u8 lts_truncate; 2058c2ecf20Sopenharmony_ci struct ni_ps current_ps; 2068c2ecf20Sopenharmony_ci struct ni_ps requested_ps; 2078c2ecf20Sopenharmony_ci /* scratch structs */ 2088c2ecf20Sopenharmony_ci SMC_NIslands_MCRegisters smc_mc_reg_table; 2098c2ecf20Sopenharmony_ci NISLANDS_SMC_STATETABLE smc_statetable; 2108c2ecf20Sopenharmony_ci}; 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci#define NISLANDS_INITIAL_STATE_ARB_INDEX 0 2138c2ecf20Sopenharmony_ci#define NISLANDS_ACPI_STATE_ARB_INDEX 1 2148c2ecf20Sopenharmony_ci#define NISLANDS_ULV_STATE_ARB_INDEX 2 2158c2ecf20Sopenharmony_ci#define NISLANDS_DRIVER_STATE_ARB_INDEX 3 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci#define NISLANDS_DPM2_MAX_PULSE_SKIP 256 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci#define NISLANDS_DPM2_NEAR_TDP_DEC 10 2208c2ecf20Sopenharmony_ci#define NISLANDS_DPM2_ABOVE_SAFE_INC 5 2218c2ecf20Sopenharmony_ci#define NISLANDS_DPM2_BELOW_SAFE_INC 20 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci#define NISLANDS_DPM2_TDP_SAFE_LIMIT_PERCENT 80 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci#define NISLANDS_DPM2_MAXPS_PERCENT_H 90 2268c2ecf20Sopenharmony_ci#define NISLANDS_DPM2_MAXPS_PERCENT_M 0 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci#define NISLANDS_DPM2_SQ_RAMP_MAX_POWER 0x3FFF 2298c2ecf20Sopenharmony_ci#define NISLANDS_DPM2_SQ_RAMP_MIN_POWER 0x12 2308c2ecf20Sopenharmony_ci#define NISLANDS_DPM2_SQ_RAMP_MAX_POWER_DELTA 0x15 2318c2ecf20Sopenharmony_ci#define NISLANDS_DPM2_SQ_RAMP_STI_SIZE 0x1E 2328c2ecf20Sopenharmony_ci#define NISLANDS_DPM2_SQ_RAMP_LTI_RATIO 0xF 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ciint ni_copy_and_switch_arb_sets(struct radeon_device *rdev, 2358c2ecf20Sopenharmony_ci u32 arb_freq_src, u32 arb_freq_dest); 2368c2ecf20Sopenharmony_civoid ni_update_current_ps(struct radeon_device *rdev, 2378c2ecf20Sopenharmony_ci struct radeon_ps *rps); 2388c2ecf20Sopenharmony_civoid ni_update_requested_ps(struct radeon_device *rdev, 2398c2ecf20Sopenharmony_ci struct radeon_ps *rps); 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_civoid ni_set_uvd_clock_before_set_eng_clock(struct radeon_device *rdev, 2428c2ecf20Sopenharmony_ci struct radeon_ps *new_ps, 2438c2ecf20Sopenharmony_ci struct radeon_ps *old_ps); 2448c2ecf20Sopenharmony_civoid ni_set_uvd_clock_after_set_eng_clock(struct radeon_device *rdev, 2458c2ecf20Sopenharmony_ci struct radeon_ps *new_ps, 2468c2ecf20Sopenharmony_ci struct radeon_ps *old_ps); 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_cibool ni_dpm_vblank_too_short(struct radeon_device *rdev); 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci#endif 251