2 * Copyright 2015 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.
27 #include "smu72_discrete.h"
28 #include "ppatomctrl.h"
29 #include "ppinterrupt.h"
30 #include "tonga_powertune.h"
31 #include "pp_endian.h"
33 #define TONGA_MAX_HARDWARE_POWERLEVELS 2
34 #define TONGA_DYNCLK_NUMBER_OF_TREND_COEFFICIENTS 15
36 struct tonga_performance_level
{
37 uint32_t memory_clock
;
38 uint32_t engine_clock
;
43 struct _phw_tonga_bacos
{
46 struct tonga_performance_level performance_level
;
48 typedef struct _phw_tonga_bacos phw_tonga_bacos
;
50 struct _phw_tonga_uvd_clocks
{
55 typedef struct _phw_tonga_uvd_clocks phw_tonga_uvd_clocks
;
57 struct _phw_tonga_vce_clocks
{
62 typedef struct _phw_tonga_vce_clocks phw_tonga_vce_clocks
;
64 struct tonga_power_state
{
66 phw_tonga_uvd_clocks uvd_clocks
;
67 phw_tonga_vce_clocks vce_clocks
;
70 uint16_t performance_level_count
;
72 uint32_t sclk_threshold
;
73 struct tonga_performance_level performance_levels
[TONGA_MAX_HARDWARE_POWERLEVELS
];
76 struct _phw_tonga_dpm_level
{
81 typedef struct _phw_tonga_dpm_level phw_tonga_dpm_level
;
83 #define TONGA_MAX_DEEPSLEEP_DIVIDER_ID 5
84 #define MAX_REGULAR_DPM_NUMBER 8
85 #define TONGA_MINIMUM_ENGINE_CLOCK 2500
87 struct tonga_single_dpm_table
{
89 phw_tonga_dpm_level dpm_levels
[MAX_REGULAR_DPM_NUMBER
];
92 struct tonga_dpm_table
{
93 struct tonga_single_dpm_table sclk_table
;
94 struct tonga_single_dpm_table mclk_table
;
95 struct tonga_single_dpm_table pcie_speed_table
;
96 struct tonga_single_dpm_table vddc_table
;
97 struct tonga_single_dpm_table vdd_gfx_table
;
98 struct tonga_single_dpm_table vdd_ci_table
;
99 struct tonga_single_dpm_table mvdd_table
;
101 typedef struct _phw_tonga_dpm_table phw_tonga_dpm_table
;
104 struct _phw_tonga_clock_regisiters
{
105 uint32_t vCG_SPLL_FUNC_CNTL
;
106 uint32_t vCG_SPLL_FUNC_CNTL_2
;
107 uint32_t vCG_SPLL_FUNC_CNTL_3
;
108 uint32_t vCG_SPLL_FUNC_CNTL_4
;
109 uint32_t vCG_SPLL_SPREAD_SPECTRUM
;
110 uint32_t vCG_SPLL_SPREAD_SPECTRUM_2
;
112 uint32_t vMCLK_PWRMGT_CNTL
;
113 uint32_t vMPLL_AD_FUNC_CNTL
;
114 uint32_t vMPLL_DQ_FUNC_CNTL
;
115 uint32_t vMPLL_FUNC_CNTL
;
116 uint32_t vMPLL_FUNC_CNTL_1
;
117 uint32_t vMPLL_FUNC_CNTL_2
;
121 typedef struct _phw_tonga_clock_regisiters phw_tonga_clock_registers
;
123 struct _phw_tonga_voltage_smio_registers
{
124 uint32_t vs0_vid_lower_smio_cntl
;
126 typedef struct _phw_tonga_voltage_smio_registers phw_tonga_voltage_smio_registers
;
129 struct _phw_tonga_mc_reg_entry
{
131 uint32_t mc_data
[SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE
];
133 typedef struct _phw_tonga_mc_reg_entry phw_tonga_mc_reg_entry
;
135 struct _phw_tonga_mc_reg_table
{
136 uint8_t last
; /* number of registers*/
137 uint8_t num_entries
; /* number of entries in mc_reg_table_entry used*/
138 uint16_t validflag
; /* indicate the corresponding register is valid or not. 1: valid, 0: invalid. bit0->address[0], bit1->address[1], etc.*/
139 phw_tonga_mc_reg_entry mc_reg_table_entry
[MAX_AC_TIMING_ENTRIES
];
140 SMU72_Discrete_MCRegisterAddress mc_reg_address
[SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE
];
142 typedef struct _phw_tonga_mc_reg_table phw_tonga_mc_reg_table
;
144 #define DISABLE_MC_LOADMICROCODE 1
145 #define DISABLE_MC_CFGPROGRAMMING 2
147 /*Ultra Low Voltage parameter structure */
148 struct _phw_tonga_ulv_parm
{
150 uint32_t ch_ulv_parameter
;
151 uint32_t ulv_volt_change_delay
;
152 struct tonga_performance_level ulv_power_level
;
154 typedef struct _phw_tonga_ulv_parm phw_tonga_ulv_parm
;
156 #define TONGA_MAX_LEAKAGE_COUNT 8
158 struct _phw_tonga_leakage_voltage
{
160 uint16_t leakage_id
[TONGA_MAX_LEAKAGE_COUNT
];
161 uint16_t actual_voltage
[TONGA_MAX_LEAKAGE_COUNT
];
163 typedef struct _phw_tonga_leakage_voltage phw_tonga_leakage_voltage
;
165 struct _phw_tonga_display_timing
{
166 uint32_t min_clock_insr
;
167 uint32_t num_existing_displays
;
169 typedef struct _phw_tonga_display_timing phw_tonga_display_timing
;
171 struct _phw_tonga_dpmlevel_enable_mask
{
172 uint32_t uvd_dpm_enable_mask
;
173 uint32_t vce_dpm_enable_mask
;
174 uint32_t acp_dpm_enable_mask
;
175 uint32_t samu_dpm_enable_mask
;
176 uint32_t sclk_dpm_enable_mask
;
177 uint32_t mclk_dpm_enable_mask
;
178 uint32_t pcie_dpm_enable_mask
;
180 typedef struct _phw_tonga_dpmlevel_enable_mask phw_tonga_dpmlevel_enable_mask
;
182 struct _phw_tonga_pcie_perf_range
{
186 typedef struct _phw_tonga_pcie_perf_range phw_tonga_pcie_perf_range
;
188 struct _phw_tonga_vbios_boot_state
{
189 uint16_t mvdd_bootup_value
;
190 uint16_t vddc_bootup_value
;
191 uint16_t vddci_bootup_value
;
192 uint16_t vddgfx_bootup_value
;
193 uint32_t sclk_bootup_value
;
194 uint32_t mclk_bootup_value
;
195 uint16_t pcie_gen_bootup_value
;
196 uint16_t pcie_lane_bootup_value
;
198 typedef struct _phw_tonga_vbios_boot_state phw_tonga_vbios_boot_state
;
200 #define DPMTABLE_OD_UPDATE_SCLK 0x00000001
201 #define DPMTABLE_OD_UPDATE_MCLK 0x00000002
202 #define DPMTABLE_UPDATE_SCLK 0x00000004
203 #define DPMTABLE_UPDATE_MCLK 0x00000008
205 /* We need to review which fields are needed. */
206 /* This is mostly a copy of the RV7xx/Evergreen structure which is close, but not identical to the N.Islands one. */
208 struct tonga_dpm_table dpm_table
;
209 struct tonga_dpm_table golden_dpm_table
;
211 uint32_t voting_rights_clients0
;
212 uint32_t voting_rights_clients1
;
213 uint32_t voting_rights_clients2
;
214 uint32_t voting_rights_clients3
;
215 uint32_t voting_rights_clients4
;
216 uint32_t voting_rights_clients5
;
217 uint32_t voting_rights_clients6
;
218 uint32_t voting_rights_clients7
;
219 uint32_t static_screen_threshold_unit
;
220 uint32_t static_screen_threshold
;
221 uint32_t voltage_control
;
222 uint32_t vdd_gfx_control
;
224 uint32_t vddc_vddci_delta
;
225 uint32_t vddc_vddgfx_delta
;
227 struct pp_interrupt_registration_info internal_high_thermal_interrupt_info
;
228 struct pp_interrupt_registration_info internal_low_thermal_interrupt_info
;
229 struct pp_interrupt_registration_info smc_to_host_interrupt_info
;
230 uint32_t active_auto_throttle_sources
;
232 struct pp_interrupt_registration_info external_throttle_interrupt
;
233 irq_handler_func_t external_throttle_callback
;
234 void *external_throttle_context
;
236 struct pp_interrupt_registration_info ctf_interrupt_info
;
237 irq_handler_func_t ctf_callback
;
240 phw_tonga_clock_registers clock_registers
;
241 phw_tonga_voltage_smio_registers voltage_smio_registers
;
243 bool is_memory_GDDR5
;
245 bool pspp_notify_required
; /* Flag to indicate if PSPP notification to SBIOS is required */
246 uint16_t force_pcie_gen
; /* The forced PCI-E speed if not 0xffff */
247 uint16_t acpi_pcie_gen
; /* The PCI-E speed at ACPI time */
248 uint32_t pcie_gen_cap
; /* The PCI-E speed capabilities bitmap from CAIL */
249 uint32_t pcie_lane_cap
; /* The PCI-E lane capabilities bitmap from CAIL */
250 uint32_t pcie_spc_cap
; /* Symbol Per Clock Capabilities from registry */
251 phw_tonga_leakage_voltage vddc_leakage
; /* The Leakage VDDC supported (based on leakage ID).*/
252 phw_tonga_leakage_voltage vddcgfx_leakage
; /* The Leakage VDDC supported (based on leakage ID). */
253 phw_tonga_leakage_voltage vddci_leakage
; /* The Leakage VDDCI supported (based on leakage ID). */
255 uint32_t mvdd_control
;
256 uint32_t vddc_mask_low
;
257 uint32_t mvdd_mask_low
;
258 uint16_t max_vddc_in_pp_table
; /* the maximum VDDC value in the powerplay table*/
259 uint16_t min_vddc_in_pp_table
;
260 uint16_t max_vddci_in_pp_table
; /* the maximum VDDCI value in the powerplay table */
261 uint16_t min_vddci_in_pp_table
;
262 uint32_t mclk_strobe_mode_threshold
;
263 uint32_t mclk_stutter_mode_threshold
;
264 uint32_t mclk_edc_enable_threshold
;
265 uint32_t mclk_edc_wr_enable_threshold
;
267 bool is_xdma_enabled
;
268 phw_tonga_vbios_boot_state vbios_boot_state
;
272 bool pcie_performance_request
;
274 /* -------------- SMC SRAM Address of firmware header tables ----------------*/
275 uint32_t sram_end
; /* The first address after the SMC SRAM. */
276 uint32_t dpm_table_start
; /* The start of the dpm table in the SMC SRAM. */
277 uint32_t soft_regs_start
; /* The start of the soft registers in the SMC SRAM. */
278 uint32_t mc_reg_table_start
; /* The start of the mc register table in the SMC SRAM. */
279 uint32_t fan_table_start
; /* The start of the fan table in the SMC SRAM. */
280 uint32_t arb_table_start
; /* The start of the ARB setting table in the SMC SRAM. */
281 SMU72_Discrete_DpmTable smc_state_table
; /* The carbon copy of the SMC state table. */
282 SMU72_Discrete_MCRegisters mc_reg_table
;
283 SMU72_Discrete_Ulv ulv_setting
; /* The carbon copy of ULV setting. */
284 /* -------------- Stuff originally coming from Evergreen --------------------*/
285 phw_tonga_mc_reg_table tonga_mc_reg_table
;
286 uint32_t vdd_ci_control
;
287 pp_atomctrl_voltage_table vddc_voltage_table
;
288 pp_atomctrl_voltage_table vddci_voltage_table
;
289 pp_atomctrl_voltage_table vddgfx_voltage_table
;
290 pp_atomctrl_voltage_table mvdd_voltage_table
;
292 uint32_t mgcg_cgtt_local2
;
293 uint32_t mgcg_cgtt_local3
;
295 uint32_t mc_micro_code_feature
;
296 uint32_t highest_mclk
;
297 uint16_t acpi_vdd_ci
;
298 uint8_t mvdd_high_index
;
299 uint8_t mvdd_low_index
;
301 bool performance_request_registered
;
304 /* ----------------- Low Power Features ---------------------*/
305 phw_tonga_bacos bacos
;
306 phw_tonga_ulv_parm ulv
;
307 /* ----------------- CAC Stuff ---------------------*/
308 uint32_t cac_table_start
;
309 bool cac_configuration_required
; /* TRUE if PP_CACConfigurationRequired == 1 */
310 bool driver_calculate_cac_leakage
; /* TRUE if PP_DriverCalculateCACLeakage == 1 */
312 /* ----------------- DPM2 Parameters ---------------------*/
313 uint32_t power_containment_features
;
314 bool enable_bapm_feature
;
315 bool enable_tdc_limit_feature
;
316 bool enable_pkg_pwr_tracking_feature
;
317 bool disable_uvd_power_tune_feature
;
318 struct tonga_pt_defaults
*power_tune_defaults
;
319 SMU72_Discrete_PmFuses power_tune_table
;
320 uint32_t dte_tj_offset
; /* Fudge factor in DPM table to correct HW DTE errors */
321 uint32_t fast_watermark_threshold
; /* use fast watermark if clock is equal or above this. In percentage of the target high sclk. */
324 bool enable_dte_feature
;
327 /* ----------------- Phase Shedding ---------------------*/
328 bool vddc_phase_shed_control
;
329 /* --------------------- DI/DT --------------------------*/
330 phw_tonga_display_timing display_timing
;
331 /* --------- ReadRegistry data for memory and engine clock margins ---- */
332 uint32_t engine_clock_data
;
333 uint32_t memory_clock_data
;
334 /* -------- Thermal Temperature Setting --------------*/
335 phw_tonga_dpmlevel_enable_mask dpm_level_enable_mask
;
336 uint32_t need_update_smu7_dpm_table
;
337 uint32_t sclk_dpm_key_disabled
;
338 uint32_t mclk_dpm_key_disabled
;
339 uint32_t pcie_dpm_key_disabled
;
340 uint32_t min_engine_clocks
; /* used to store the previous dal min sclock */
341 phw_tonga_pcie_perf_range pcie_gen_performance
;
342 phw_tonga_pcie_perf_range pcie_lane_performance
;
343 phw_tonga_pcie_perf_range pcie_gen_power_saving
;
344 phw_tonga_pcie_perf_range pcie_lane_power_saving
;
345 bool use_pcie_performance_levels
;
346 bool use_pcie_power_saving_levels
;
347 uint32_t activity_target
[SMU72_MAX_LEVELS_GRAPHICS
]; /* percentage value from 0-100, default 50 */
348 uint32_t mclk_activity_target
;
349 uint32_t low_sclk_interrupt_threshold
;
350 uint32_t last_mclk_dpm_enable_mask
;
352 uint32_t pcc_monitor_enabled
;
354 /* --------- Power Gating States ------------*/
355 bool uvd_power_gated
; /* 1: gated, 0:not gated */
356 bool vce_power_gated
; /* 1: gated, 0:not gated */
357 bool samu_power_gated
; /* 1: gated, 0:not gated */
358 bool acp_power_gated
; /* 1: gated, 0:not gated */
362 typedef struct tonga_hwmgr tonga_hwmgr
;
364 #define TONGA_DPM2_NEAR_TDP_DEC 10
365 #define TONGA_DPM2_ABOVE_SAFE_INC 5
366 #define TONGA_DPM2_BELOW_SAFE_INC 20
368 #define TONGA_DPM2_LTA_WINDOW_SIZE 7 /* Log2 of the LTA window size (l2numWin_TDP). Eg. If LTA windows size is 128, then this value should be Log2(128) = 7. */
370 #define TONGA_DPM2_LTS_TRUNCATE 0
372 #define TONGA_DPM2_TDP_SAFE_LIMIT_PERCENT 80 /* Maximum 100 */
374 #define TONGA_DPM2_MAXPS_PERCENT_H 90 /* Maximum 0xFF */
375 #define TONGA_DPM2_MAXPS_PERCENT_M 90 /* Maximum 0xFF */
377 #define TONGA_DPM2_PWREFFICIENCYRATIO_MARGIN 50
379 #define TONGA_DPM2_SQ_RAMP_MAX_POWER 0x3FFF
380 #define TONGA_DPM2_SQ_RAMP_MIN_POWER 0x12
381 #define TONGA_DPM2_SQ_RAMP_MAX_POWER_DELTA 0x15
382 #define TONGA_DPM2_SQ_RAMP_SHORT_TERM_INTERVAL_SIZE 0x1E
383 #define TONGA_DPM2_SQ_RAMP_LONG_TERM_INTERVAL_RATIO 0xF
385 #define TONGA_VOLTAGE_CONTROL_NONE 0x0
386 #define TONGA_VOLTAGE_CONTROL_BY_GPIO 0x1
387 #define TONGA_VOLTAGE_CONTROL_BY_SVID2 0x2
388 #define TONGA_VOLTAGE_CONTROL_MERGED 0x3
390 #define TONGA_Q88_FORMAT_CONVERSION_UNIT 256 /*To convert to Q8.8 format for firmware */
392 #define TONGA_UNUSED_GPIO_PIN 0x7F
394 int tonga_hwmgr_init(struct pp_hwmgr
*hwmgr
);
395 int tonga_update_vce_dpm(struct pp_hwmgr
*hwmgr
, const void *input
);
396 int tonga_update_uvd_dpm(struct pp_hwmgr
*hwmgr
, bool bgate
);
397 int tonga_enable_disable_uvd_dpm(struct pp_hwmgr
*hwmgr
, bool enable
);
398 int tonga_enable_disable_vce_dpm(struct pp_hwmgr
*hwmgr
, bool enable
);
399 uint32_t tonga_get_xclk(struct pp_hwmgr
*hwmgr
);