1*1bb76ff1Sjsg /* 2*1bb76ff1Sjsg * Copyright 2013 Advanced Micro Devices, Inc. 3*1bb76ff1Sjsg * 4*1bb76ff1Sjsg * Permission is hereby granted, free of charge, to any person obtaining a 5*1bb76ff1Sjsg * copy of this software and associated documentation files (the "Software"), 6*1bb76ff1Sjsg * to deal in the Software without restriction, including without limitation 7*1bb76ff1Sjsg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8*1bb76ff1Sjsg * and/or sell copies of the Software, and to permit persons to whom the 9*1bb76ff1Sjsg * Software is furnished to do so, subject to the following conditions: 10*1bb76ff1Sjsg * 11*1bb76ff1Sjsg * The above copyright notice and this permission notice shall be included in 12*1bb76ff1Sjsg * all copies or substantial portions of the Software. 13*1bb76ff1Sjsg * 14*1bb76ff1Sjsg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15*1bb76ff1Sjsg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16*1bb76ff1Sjsg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17*1bb76ff1Sjsg * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18*1bb76ff1Sjsg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19*1bb76ff1Sjsg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20*1bb76ff1Sjsg * OTHER DEALINGS IN THE SOFTWARE. 21*1bb76ff1Sjsg * 22*1bb76ff1Sjsg */ 23*1bb76ff1Sjsg #ifndef __KV_DPM_H__ 24*1bb76ff1Sjsg #define __KV_DPM_H__ 25*1bb76ff1Sjsg 26*1bb76ff1Sjsg #define SMU__NUM_SCLK_DPM_STATE 8 27*1bb76ff1Sjsg #define SMU__NUM_MCLK_DPM_LEVELS 4 28*1bb76ff1Sjsg #define SMU__NUM_LCLK_DPM_LEVELS 8 29*1bb76ff1Sjsg #define SMU__NUM_PCIE_DPM_LEVELS 0 /* ??? */ 30*1bb76ff1Sjsg #include "smu7_fusion.h" 31*1bb76ff1Sjsg #include "ppsmc.h" 32*1bb76ff1Sjsg 33*1bb76ff1Sjsg #define SUMO_MAX_HARDWARE_POWERLEVELS 5 34*1bb76ff1Sjsg 35*1bb76ff1Sjsg #define SUMO_MAX_NUMBER_VOLTAGES 4 36*1bb76ff1Sjsg 37*1bb76ff1Sjsg struct sumo_vid_mapping_entry { 38*1bb76ff1Sjsg u16 vid_2bit; 39*1bb76ff1Sjsg u16 vid_7bit; 40*1bb76ff1Sjsg }; 41*1bb76ff1Sjsg 42*1bb76ff1Sjsg struct sumo_vid_mapping_table { 43*1bb76ff1Sjsg u32 num_entries; 44*1bb76ff1Sjsg struct sumo_vid_mapping_entry entries[SUMO_MAX_NUMBER_VOLTAGES]; 45*1bb76ff1Sjsg }; 46*1bb76ff1Sjsg 47*1bb76ff1Sjsg struct sumo_sclk_voltage_mapping_entry { 48*1bb76ff1Sjsg u32 sclk_frequency; 49*1bb76ff1Sjsg u16 vid_2bit; 50*1bb76ff1Sjsg u16 rsv; 51*1bb76ff1Sjsg }; 52*1bb76ff1Sjsg 53*1bb76ff1Sjsg struct sumo_sclk_voltage_mapping_table { 54*1bb76ff1Sjsg u32 num_max_dpm_entries; 55*1bb76ff1Sjsg struct sumo_sclk_voltage_mapping_entry entries[SUMO_MAX_HARDWARE_POWERLEVELS]; 56*1bb76ff1Sjsg }; 57*1bb76ff1Sjsg 58*1bb76ff1Sjsg #define TRINITY_AT_DFLT 30 59*1bb76ff1Sjsg 60*1bb76ff1Sjsg #define KV_NUM_NBPSTATES 4 61*1bb76ff1Sjsg 62*1bb76ff1Sjsg enum kv_pt_config_reg_type { 63*1bb76ff1Sjsg KV_CONFIGREG_MMR = 0, 64*1bb76ff1Sjsg KV_CONFIGREG_SMC_IND, 65*1bb76ff1Sjsg KV_CONFIGREG_DIDT_IND, 66*1bb76ff1Sjsg KV_CONFIGREG_CACHE, 67*1bb76ff1Sjsg KV_CONFIGREG_MAX 68*1bb76ff1Sjsg }; 69*1bb76ff1Sjsg 70*1bb76ff1Sjsg struct kv_pt_config_reg { 71*1bb76ff1Sjsg u32 offset; 72*1bb76ff1Sjsg u32 mask; 73*1bb76ff1Sjsg u32 shift; 74*1bb76ff1Sjsg u32 value; 75*1bb76ff1Sjsg enum kv_pt_config_reg_type type; 76*1bb76ff1Sjsg }; 77*1bb76ff1Sjsg 78*1bb76ff1Sjsg struct kv_lcac_config_values { 79*1bb76ff1Sjsg u32 block_id; 80*1bb76ff1Sjsg u32 signal_id; 81*1bb76ff1Sjsg u32 t; 82*1bb76ff1Sjsg }; 83*1bb76ff1Sjsg 84*1bb76ff1Sjsg struct kv_lcac_config_reg { 85*1bb76ff1Sjsg u32 cntl; 86*1bb76ff1Sjsg u32 block_mask; 87*1bb76ff1Sjsg u32 block_shift; 88*1bb76ff1Sjsg u32 signal_mask; 89*1bb76ff1Sjsg u32 signal_shift; 90*1bb76ff1Sjsg u32 t_mask; 91*1bb76ff1Sjsg u32 t_shift; 92*1bb76ff1Sjsg u32 enable_mask; 93*1bb76ff1Sjsg u32 enable_shift; 94*1bb76ff1Sjsg }; 95*1bb76ff1Sjsg 96*1bb76ff1Sjsg struct kv_pl { 97*1bb76ff1Sjsg u32 sclk; 98*1bb76ff1Sjsg u8 vddc_index; 99*1bb76ff1Sjsg u8 ds_divider_index; 100*1bb76ff1Sjsg u8 ss_divider_index; 101*1bb76ff1Sjsg u8 allow_gnb_slow; 102*1bb76ff1Sjsg u8 force_nbp_state; 103*1bb76ff1Sjsg u8 display_wm; 104*1bb76ff1Sjsg u8 vce_wm; 105*1bb76ff1Sjsg }; 106*1bb76ff1Sjsg 107*1bb76ff1Sjsg struct kv_ps { 108*1bb76ff1Sjsg struct kv_pl levels[SUMO_MAX_HARDWARE_POWERLEVELS]; 109*1bb76ff1Sjsg u32 num_levels; 110*1bb76ff1Sjsg bool need_dfs_bypass; 111*1bb76ff1Sjsg u8 dpm0_pg_nb_ps_lo; 112*1bb76ff1Sjsg u8 dpm0_pg_nb_ps_hi; 113*1bb76ff1Sjsg u8 dpmx_nb_ps_lo; 114*1bb76ff1Sjsg u8 dpmx_nb_ps_hi; 115*1bb76ff1Sjsg }; 116*1bb76ff1Sjsg 117*1bb76ff1Sjsg struct kv_sys_info { 118*1bb76ff1Sjsg u32 bootup_uma_clk; 119*1bb76ff1Sjsg u32 bootup_sclk; 120*1bb76ff1Sjsg u32 dentist_vco_freq; 121*1bb76ff1Sjsg u32 nb_dpm_enable; 122*1bb76ff1Sjsg u32 nbp_memory_clock[KV_NUM_NBPSTATES]; 123*1bb76ff1Sjsg u32 nbp_n_clock[KV_NUM_NBPSTATES]; 124*1bb76ff1Sjsg u16 bootup_nb_voltage_index; 125*1bb76ff1Sjsg u8 htc_tmp_lmt; 126*1bb76ff1Sjsg u8 htc_hyst_lmt; 127*1bb76ff1Sjsg struct sumo_sclk_voltage_mapping_table sclk_voltage_mapping_table; 128*1bb76ff1Sjsg struct sumo_vid_mapping_table vid_mapping_table; 129*1bb76ff1Sjsg u32 uma_channel_number; 130*1bb76ff1Sjsg }; 131*1bb76ff1Sjsg 132*1bb76ff1Sjsg struct kv_power_info { 133*1bb76ff1Sjsg u32 at[SUMO_MAX_HARDWARE_POWERLEVELS]; 134*1bb76ff1Sjsg u32 voltage_drop_t; 135*1bb76ff1Sjsg struct kv_sys_info sys_info; 136*1bb76ff1Sjsg struct kv_pl boot_pl; 137*1bb76ff1Sjsg bool enable_nb_ps_policy; 138*1bb76ff1Sjsg bool disable_nb_ps3_in_battery; 139*1bb76ff1Sjsg bool video_start; 140*1bb76ff1Sjsg bool battery_state; 141*1bb76ff1Sjsg u32 lowest_valid; 142*1bb76ff1Sjsg u32 highest_valid; 143*1bb76ff1Sjsg u16 high_voltage_t; 144*1bb76ff1Sjsg bool cac_enabled; 145*1bb76ff1Sjsg bool bapm_enable; 146*1bb76ff1Sjsg /* smc offsets */ 147*1bb76ff1Sjsg u32 sram_end; 148*1bb76ff1Sjsg u32 dpm_table_start; 149*1bb76ff1Sjsg u32 soft_regs_start; 150*1bb76ff1Sjsg /* dpm SMU tables */ 151*1bb76ff1Sjsg u8 graphics_dpm_level_count; 152*1bb76ff1Sjsg u8 uvd_level_count; 153*1bb76ff1Sjsg u8 vce_level_count; 154*1bb76ff1Sjsg u8 acp_level_count; 155*1bb76ff1Sjsg u8 samu_level_count; 156*1bb76ff1Sjsg u16 fps_high_t; 157*1bb76ff1Sjsg SMU7_Fusion_GraphicsLevel graphics_level[SMU__NUM_SCLK_DPM_STATE]; 158*1bb76ff1Sjsg SMU7_Fusion_ACPILevel acpi_level; 159*1bb76ff1Sjsg SMU7_Fusion_UvdLevel uvd_level[SMU7_MAX_LEVELS_UVD]; 160*1bb76ff1Sjsg SMU7_Fusion_ExtClkLevel vce_level[SMU7_MAX_LEVELS_VCE]; 161*1bb76ff1Sjsg SMU7_Fusion_ExtClkLevel acp_level[SMU7_MAX_LEVELS_ACP]; 162*1bb76ff1Sjsg SMU7_Fusion_ExtClkLevel samu_level[SMU7_MAX_LEVELS_SAMU]; 163*1bb76ff1Sjsg u8 uvd_boot_level; 164*1bb76ff1Sjsg u8 vce_boot_level; 165*1bb76ff1Sjsg u8 acp_boot_level; 166*1bb76ff1Sjsg u8 samu_boot_level; 167*1bb76ff1Sjsg u8 uvd_interval; 168*1bb76ff1Sjsg u8 vce_interval; 169*1bb76ff1Sjsg u8 acp_interval; 170*1bb76ff1Sjsg u8 samu_interval; 171*1bb76ff1Sjsg u8 graphics_boot_level; 172*1bb76ff1Sjsg u8 graphics_interval; 173*1bb76ff1Sjsg u8 graphics_therm_throttle_enable; 174*1bb76ff1Sjsg u8 graphics_voltage_change_enable; 175*1bb76ff1Sjsg u8 graphics_clk_slow_enable; 176*1bb76ff1Sjsg u8 graphics_clk_slow_divider; 177*1bb76ff1Sjsg u8 fps_low_t; 178*1bb76ff1Sjsg u32 low_sclk_interrupt_t; 179*1bb76ff1Sjsg bool uvd_power_gated; 180*1bb76ff1Sjsg bool vce_power_gated; 181*1bb76ff1Sjsg bool acp_power_gated; 182*1bb76ff1Sjsg bool samu_power_gated; 183*1bb76ff1Sjsg bool nb_dpm_enabled; 184*1bb76ff1Sjsg /* flags */ 185*1bb76ff1Sjsg bool enable_didt; 186*1bb76ff1Sjsg bool enable_dpm; 187*1bb76ff1Sjsg bool enable_auto_thermal_throttling; 188*1bb76ff1Sjsg bool enable_nb_dpm; 189*1bb76ff1Sjsg /* caps */ 190*1bb76ff1Sjsg bool caps_cac; 191*1bb76ff1Sjsg bool caps_power_containment; 192*1bb76ff1Sjsg bool caps_sq_ramping; 193*1bb76ff1Sjsg bool caps_db_ramping; 194*1bb76ff1Sjsg bool caps_td_ramping; 195*1bb76ff1Sjsg bool caps_tcp_ramping; 196*1bb76ff1Sjsg bool caps_sclk_throttle_low_notification; 197*1bb76ff1Sjsg bool caps_fps; 198*1bb76ff1Sjsg bool caps_uvd_dpm; 199*1bb76ff1Sjsg bool caps_uvd_pg; 200*1bb76ff1Sjsg bool caps_vce_pg; 201*1bb76ff1Sjsg bool caps_samu_pg; 202*1bb76ff1Sjsg bool caps_acp_pg; 203*1bb76ff1Sjsg bool caps_stable_p_state; 204*1bb76ff1Sjsg bool caps_enable_dfs_bypass; 205*1bb76ff1Sjsg bool caps_sclk_ds; 206*1bb76ff1Sjsg struct amdgpu_ps current_rps; 207*1bb76ff1Sjsg struct kv_ps current_ps; 208*1bb76ff1Sjsg struct amdgpu_ps requested_rps; 209*1bb76ff1Sjsg struct kv_ps requested_ps; 210*1bb76ff1Sjsg }; 211*1bb76ff1Sjsg 212*1bb76ff1Sjsg /* XXX are these ok? */ 213*1bb76ff1Sjsg #define KV_TEMP_RANGE_MIN (90 * 1000) 214*1bb76ff1Sjsg #define KV_TEMP_RANGE_MAX (120 * 1000) 215*1bb76ff1Sjsg 216*1bb76ff1Sjsg /* kv_smc.c */ 217*1bb76ff1Sjsg int amdgpu_kv_notify_message_to_smu(struct amdgpu_device *adev, u32 id); 218*1bb76ff1Sjsg int amdgpu_kv_dpm_get_enable_mask(struct amdgpu_device *adev, u32 *enable_mask); 219*1bb76ff1Sjsg int amdgpu_kv_send_msg_to_smc_with_parameter(struct amdgpu_device *adev, 220*1bb76ff1Sjsg PPSMC_Msg msg, u32 parameter); 221*1bb76ff1Sjsg int amdgpu_kv_read_smc_sram_dword(struct amdgpu_device *adev, u32 smc_address, 222*1bb76ff1Sjsg u32 *value, u32 limit); 223*1bb76ff1Sjsg int amdgpu_kv_smc_dpm_enable(struct amdgpu_device *adev, bool enable); 224*1bb76ff1Sjsg int amdgpu_kv_smc_bapm_enable(struct amdgpu_device *adev, bool enable); 225*1bb76ff1Sjsg int amdgpu_kv_copy_bytes_to_smc(struct amdgpu_device *adev, 226*1bb76ff1Sjsg u32 smc_start_address, 227*1bb76ff1Sjsg const u8 *src, u32 byte_count, u32 limit); 228*1bb76ff1Sjsg 229*1bb76ff1Sjsg #endif 230