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.
24 #include <linux/delay.h>
26 #include <linux/module.h>
27 #include <linux/slab.h>
28 #include <asm/div64.h>
30 #include "ppatomctrl.h"
32 #include "pptable_v1_0.h"
33 #include "pppcielanes.h"
34 #include "amd_pcie_helpers.h"
35 #include "hardwaremanager.h"
36 #include "process_pptables_v1_0.h"
37 #include "cgs_common.h"
39 #include "smu7_common.h"
42 #include "smu7_hwmgr.h"
43 #include "smu7_smumgr.h"
44 #include "smu_ucode_xfer_vi.h"
45 #include "smu7_powertune.h"
46 #include "smu7_dyn_defaults.h"
47 #include "smu7_thermal.h"
48 #include "smu7_clockpowergating.h"
49 #include "processpptables.h"
51 #define MC_CG_ARB_FREQ_F0 0x0a
52 #define MC_CG_ARB_FREQ_F1 0x0b
53 #define MC_CG_ARB_FREQ_F2 0x0c
54 #define MC_CG_ARB_FREQ_F3 0x0d
56 #define MC_CG_SEQ_DRAMCONF_S0 0x05
57 #define MC_CG_SEQ_DRAMCONF_S1 0x06
58 #define MC_CG_SEQ_YCLK_SUSPEND 0x04
59 #define MC_CG_SEQ_YCLK_RESUME 0x0a
61 #define SMC_CG_IND_START 0xc0030000
62 #define SMC_CG_IND_END 0xc0040000
64 #define VOLTAGE_SCALE 4
65 #define VOLTAGE_VID_OFFSET_SCALE1 625
66 #define VOLTAGE_VID_OFFSET_SCALE2 100
68 #define MEM_FREQ_LOW_LATENCY 25000
69 #define MEM_FREQ_HIGH_LATENCY 80000
71 #define MEM_LATENCY_HIGH 45
72 #define MEM_LATENCY_LOW 35
73 #define MEM_LATENCY_ERR 0xFFFF
75 #define MC_SEQ_MISC0_GDDR5_SHIFT 28
76 #define MC_SEQ_MISC0_GDDR5_MASK 0xf0000000
77 #define MC_SEQ_MISC0_GDDR5_VALUE 5
79 #define PCIE_BUS_CLK 10000
80 #define TCLK (PCIE_BUS_CLK / 10)
83 /** Values for the CG_THERMAL_CTRL::DPM_EVENT_SRC field. */
85 DPM_EVENT_SRC_ANALOG = 0,
86 DPM_EVENT_SRC_EXTERNAL = 1,
87 DPM_EVENT_SRC_DIGITAL = 2,
88 DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
89 DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL = 4
92 static int smu7_avfs_control(struct pp_hwmgr *hwmgr, bool enable);
93 static const unsigned long PhwVIslands_Magic = (unsigned long)(PHM_VIslands_Magic);
94 static int smu7_force_clock_level(struct pp_hwmgr *hwmgr,
95 enum pp_clock_type type, uint32_t mask);
97 static struct smu7_power_state *cast_phw_smu7_power_state(
98 struct pp_hw_power_state *hw_ps)
100 PP_ASSERT_WITH_CODE((PhwVIslands_Magic == hw_ps->magic),
101 "Invalid Powerstate Type!",
104 return (struct smu7_power_state *)hw_ps;
107 static const struct smu7_power_state *cast_const_phw_smu7_power_state(
108 const struct pp_hw_power_state *hw_ps)
110 PP_ASSERT_WITH_CODE((PhwVIslands_Magic == hw_ps->magic),
111 "Invalid Powerstate Type!",
114 return (const struct smu7_power_state *)hw_ps;
118 * Find the MC microcode version and store it in the HwMgr struct
120 * @param hwmgr the address of the powerplay hardware manager.
123 static int smu7_get_mc_microcode_version(struct pp_hwmgr *hwmgr)
125 cgs_write_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_INDEX, 0x9F);
127 hwmgr->microcode_version_info.MC = cgs_read_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_DATA);
132 static uint16_t smu7_get_current_pcie_speed(struct pp_hwmgr *hwmgr)
134 uint32_t speedCntl = 0;
136 /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
137 speedCntl = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__PCIE,
138 ixPCIE_LC_SPEED_CNTL);
139 return((uint16_t)PHM_GET_FIELD(speedCntl,
140 PCIE_LC_SPEED_CNTL, LC_CURRENT_DATA_RATE));
143 static int smu7_get_current_pcie_lane_number(struct pp_hwmgr *hwmgr)
147 /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
148 link_width = PHM_READ_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE,
149 PCIE_LC_LINK_WIDTH_CNTL, LC_LINK_WIDTH_RD);
151 PP_ASSERT_WITH_CODE((7 >= link_width),
152 "Invalid PCIe lane width!", return 0);
154 return decode_pcie_lane_width(link_width);
158 * Enable voltage control
160 * @param pHwMgr the address of the powerplay hardware manager.
161 * @return always PP_Result_OK
163 static int smu7_enable_smc_voltage_controller(struct pp_hwmgr *hwmgr)
165 if (hwmgr->feature_mask & PP_SMC_VOLTAGE_CONTROL_MASK)
166 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_Voltage_Cntl_Enable);
172 * Checks if we want to support voltage control
174 * @param hwmgr the address of the powerplay hardware manager.
176 static bool smu7_voltage_control(const struct pp_hwmgr *hwmgr)
178 const struct smu7_hwmgr *data =
179 (const struct smu7_hwmgr *)(hwmgr->backend);
181 return (SMU7_VOLTAGE_CONTROL_NONE != data->voltage_control);
185 * Enable voltage control
187 * @param hwmgr the address of the powerplay hardware manager.
190 static int smu7_enable_voltage_control(struct pp_hwmgr *hwmgr)
192 /* enable voltage control */
193 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
194 GENERAL_PWRMGT, VOLT_PWRMGT_EN, 1);
199 static int phm_get_svi2_voltage_table_v0(pp_atomctrl_voltage_table *voltage_table,
200 struct phm_clock_voltage_dependency_table *voltage_dependency_table
205 PP_ASSERT_WITH_CODE((NULL != voltage_table),
206 "Voltage Dependency Table empty.", return -EINVAL;);
208 voltage_table->mask_low = 0;
209 voltage_table->phase_delay = 0;
210 voltage_table->count = voltage_dependency_table->count;
212 for (i = 0; i < voltage_dependency_table->count; i++) {
213 voltage_table->entries[i].value =
214 voltage_dependency_table->entries[i].v;
215 voltage_table->entries[i].smio_low = 0;
223 * Create Voltage Tables.
225 * @param hwmgr the address of the powerplay hardware manager.
228 static int smu7_construct_voltage_tables(struct pp_hwmgr *hwmgr)
230 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
231 struct phm_ppt_v1_information *table_info =
232 (struct phm_ppt_v1_information *)hwmgr->pptable;
236 if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
237 result = atomctrl_get_voltage_table_v3(hwmgr,
238 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT,
239 &(data->mvdd_voltage_table));
240 PP_ASSERT_WITH_CODE((0 == result),
241 "Failed to retrieve MVDD table.",
243 } else if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) {
244 if (hwmgr->pp_table_version == PP_TABLE_V1)
245 result = phm_get_svi2_mvdd_voltage_table(&(data->mvdd_voltage_table),
246 table_info->vdd_dep_on_mclk);
247 else if (hwmgr->pp_table_version == PP_TABLE_V0)
248 result = phm_get_svi2_voltage_table_v0(&(data->mvdd_voltage_table),
249 hwmgr->dyn_state.mvdd_dependency_on_mclk);
251 PP_ASSERT_WITH_CODE((0 == result),
252 "Failed to retrieve SVI2 MVDD table from dependancy table.",
256 if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
257 result = atomctrl_get_voltage_table_v3(hwmgr,
258 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT,
259 &(data->vddci_voltage_table));
260 PP_ASSERT_WITH_CODE((0 == result),
261 "Failed to retrieve VDDCI table.",
263 } else if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) {
264 if (hwmgr->pp_table_version == PP_TABLE_V1)
265 result = phm_get_svi2_vddci_voltage_table(&(data->vddci_voltage_table),
266 table_info->vdd_dep_on_mclk);
267 else if (hwmgr->pp_table_version == PP_TABLE_V0)
268 result = phm_get_svi2_voltage_table_v0(&(data->vddci_voltage_table),
269 hwmgr->dyn_state.vddci_dependency_on_mclk);
270 PP_ASSERT_WITH_CODE((0 == result),
271 "Failed to retrieve SVI2 VDDCI table from dependancy table.",
275 if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_gfx_control) {
276 /* VDDGFX has only SVI2 voltage control */
277 result = phm_get_svi2_vdd_voltage_table(&(data->vddgfx_voltage_table),
278 table_info->vddgfx_lookup_table);
279 PP_ASSERT_WITH_CODE((0 == result),
280 "Failed to retrieve SVI2 VDDGFX table from lookup table.", return result;);
284 if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->voltage_control) {
285 result = atomctrl_get_voltage_table_v3(hwmgr,
286 VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_GPIO_LUT,
287 &data->vddc_voltage_table);
288 PP_ASSERT_WITH_CODE((0 == result),
289 "Failed to retrieve VDDC table.", return result;);
290 } else if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
292 if (hwmgr->pp_table_version == PP_TABLE_V0)
293 result = phm_get_svi2_voltage_table_v0(&data->vddc_voltage_table,
294 hwmgr->dyn_state.vddc_dependency_on_mclk);
295 else if (hwmgr->pp_table_version == PP_TABLE_V1)
296 result = phm_get_svi2_vdd_voltage_table(&(data->vddc_voltage_table),
297 table_info->vddc_lookup_table);
299 PP_ASSERT_WITH_CODE((0 == result),
300 "Failed to retrieve SVI2 VDDC table from dependancy table.", return result;);
303 tmp = smum_get_mac_definition(hwmgr->smumgr, SMU_MAX_LEVELS_VDDC);
305 (data->vddc_voltage_table.count <= tmp),
306 "Too many voltage values for VDDC. Trimming to fit state table.",
307 phm_trim_voltage_table_to_fit_state_table(tmp,
308 &(data->vddc_voltage_table)));
310 tmp = smum_get_mac_definition(hwmgr->smumgr, SMU_MAX_LEVELS_VDDGFX);
312 (data->vddgfx_voltage_table.count <= tmp),
313 "Too many voltage values for VDDC. Trimming to fit state table.",
314 phm_trim_voltage_table_to_fit_state_table(tmp,
315 &(data->vddgfx_voltage_table)));
317 tmp = smum_get_mac_definition(hwmgr->smumgr, SMU_MAX_LEVELS_VDDCI);
319 (data->vddci_voltage_table.count <= tmp),
320 "Too many voltage values for VDDCI. Trimming to fit state table.",
321 phm_trim_voltage_table_to_fit_state_table(tmp,
322 &(data->vddci_voltage_table)));
324 tmp = smum_get_mac_definition(hwmgr->smumgr, SMU_MAX_LEVELS_MVDD);
326 (data->mvdd_voltage_table.count <= tmp),
327 "Too many voltage values for MVDD. Trimming to fit state table.",
328 phm_trim_voltage_table_to_fit_state_table(tmp,
329 &(data->mvdd_voltage_table)));
335 * Programs static screed detection parameters
337 * @param hwmgr the address of the powerplay hardware manager.
340 static int smu7_program_static_screen_threshold_parameters(
341 struct pp_hwmgr *hwmgr)
343 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
345 /* Set static screen threshold unit */
346 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
347 CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD_UNIT,
348 data->static_screen_threshold_unit);
349 /* Set static screen threshold */
350 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
351 CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD,
352 data->static_screen_threshold);
358 * Setup display gap for glitch free memory clock switching.
360 * @param hwmgr the address of the powerplay hardware manager.
363 static int smu7_enable_display_gap(struct pp_hwmgr *hwmgr)
365 uint32_t display_gap =
366 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
367 ixCG_DISPLAY_GAP_CNTL);
369 display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL,
370 DISP_GAP, DISPLAY_GAP_IGNORE);
372 display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL,
373 DISP_GAP_MCHG, DISPLAY_GAP_VBLANK);
375 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
376 ixCG_DISPLAY_GAP_CNTL, display_gap);
382 * Programs activity state transition voting clients
384 * @param hwmgr the address of the powerplay hardware manager.
387 static int smu7_program_voting_clients(struct pp_hwmgr *hwmgr)
389 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
391 /* Clear reset for voting clients before enabling DPM */
392 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
393 SCLK_PWRMGT_CNTL, RESET_SCLK_CNT, 0);
394 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
395 SCLK_PWRMGT_CNTL, RESET_BUSY_CNT, 0);
397 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
398 ixCG_FREQ_TRAN_VOTING_0, data->voting_rights_clients0);
399 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
400 ixCG_FREQ_TRAN_VOTING_1, data->voting_rights_clients1);
401 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
402 ixCG_FREQ_TRAN_VOTING_2, data->voting_rights_clients2);
403 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
404 ixCG_FREQ_TRAN_VOTING_3, data->voting_rights_clients3);
405 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
406 ixCG_FREQ_TRAN_VOTING_4, data->voting_rights_clients4);
407 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
408 ixCG_FREQ_TRAN_VOTING_5, data->voting_rights_clients5);
409 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
410 ixCG_FREQ_TRAN_VOTING_6, data->voting_rights_clients6);
411 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
412 ixCG_FREQ_TRAN_VOTING_7, data->voting_rights_clients7);
417 static int smu7_clear_voting_clients(struct pp_hwmgr *hwmgr)
419 /* Reset voting clients before disabling DPM */
420 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
421 SCLK_PWRMGT_CNTL, RESET_SCLK_CNT, 1);
422 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
423 SCLK_PWRMGT_CNTL, RESET_BUSY_CNT, 1);
425 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
426 ixCG_FREQ_TRAN_VOTING_0, 0);
427 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
428 ixCG_FREQ_TRAN_VOTING_1, 0);
429 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
430 ixCG_FREQ_TRAN_VOTING_2, 0);
431 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
432 ixCG_FREQ_TRAN_VOTING_3, 0);
433 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
434 ixCG_FREQ_TRAN_VOTING_4, 0);
435 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
436 ixCG_FREQ_TRAN_VOTING_5, 0);
437 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
438 ixCG_FREQ_TRAN_VOTING_6, 0);
439 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
440 ixCG_FREQ_TRAN_VOTING_7, 0);
445 /* Copy one arb setting to another and then switch the active set.
446 * arb_src and arb_dest is one of the MC_CG_ARB_FREQ_Fx constants.
448 static int smu7_copy_and_switch_arb_sets(struct pp_hwmgr *hwmgr,
449 uint32_t arb_src, uint32_t arb_dest)
451 uint32_t mc_arb_dram_timing;
452 uint32_t mc_arb_dram_timing2;
454 uint32_t mc_cg_config;
457 case MC_CG_ARB_FREQ_F0:
458 mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
459 mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
460 burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0);
462 case MC_CG_ARB_FREQ_F1:
463 mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1);
464 mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1);
465 burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1);
472 case MC_CG_ARB_FREQ_F0:
473 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING, mc_arb_dram_timing);
474 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2, mc_arb_dram_timing2);
475 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0, burst_time);
477 case MC_CG_ARB_FREQ_F1:
478 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1, mc_arb_dram_timing);
479 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1, mc_arb_dram_timing2);
480 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1, burst_time);
486 mc_cg_config = cgs_read_register(hwmgr->device, mmMC_CG_CONFIG);
487 mc_cg_config |= 0x0000000F;
488 cgs_write_register(hwmgr->device, mmMC_CG_CONFIG, mc_cg_config);
489 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_CG, CG_ARB_REQ, arb_dest);
494 static int smu7_reset_to_default(struct pp_hwmgr *hwmgr)
496 return smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_ResetToDefaults);
500 * Initial switch from ARB F0->F1
502 * @param hwmgr the address of the powerplay hardware manager.
504 * This function is to be called from the SetPowerState table.
506 static int smu7_initial_switch_from_arbf0_to_f1(struct pp_hwmgr *hwmgr)
508 return smu7_copy_and_switch_arb_sets(hwmgr,
509 MC_CG_ARB_FREQ_F0, MC_CG_ARB_FREQ_F1);
512 static int smu7_force_switch_to_arbf0(struct pp_hwmgr *hwmgr)
516 tmp = (cgs_read_ind_register(hwmgr->device,
517 CGS_IND_REG__SMC, ixSMC_SCRATCH9) &
520 if (tmp == MC_CG_ARB_FREQ_F0)
523 return smu7_copy_and_switch_arb_sets(hwmgr,
524 tmp, MC_CG_ARB_FREQ_F0);
527 static int smu7_setup_default_pcie_table(struct pp_hwmgr *hwmgr)
529 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
531 struct phm_ppt_v1_information *table_info =
532 (struct phm_ppt_v1_information *)(hwmgr->pptable);
533 struct phm_ppt_v1_pcie_table *pcie_table = NULL;
535 uint32_t i, max_entry;
538 PP_ASSERT_WITH_CODE((data->use_pcie_performance_levels ||
539 data->use_pcie_power_saving_levels), "No pcie performance levels!",
542 if (table_info != NULL)
543 pcie_table = table_info->pcie_table;
545 if (data->use_pcie_performance_levels &&
546 !data->use_pcie_power_saving_levels) {
547 data->pcie_gen_power_saving = data->pcie_gen_performance;
548 data->pcie_lane_power_saving = data->pcie_lane_performance;
549 } else if (!data->use_pcie_performance_levels &&
550 data->use_pcie_power_saving_levels) {
551 data->pcie_gen_performance = data->pcie_gen_power_saving;
552 data->pcie_lane_performance = data->pcie_lane_power_saving;
554 tmp = smum_get_mac_definition(hwmgr->smumgr, SMU_MAX_LEVELS_LINK);
555 phm_reset_single_dpm_table(&data->dpm_table.pcie_speed_table,
557 MAX_REGULAR_DPM_NUMBER);
559 if (pcie_table != NULL) {
560 /* max_entry is used to make sure we reserve one PCIE level
561 * for boot level (fix for A+A PSPP issue).
562 * If PCIE table from PPTable have ULV entry + 8 entries,
563 * then ignore the last entry.*/
564 max_entry = (tmp < pcie_table->count) ? tmp : pcie_table->count;
565 for (i = 1; i < max_entry; i++) {
566 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, i - 1,
567 get_pcie_gen_support(data->pcie_gen_cap,
568 pcie_table->entries[i].gen_speed),
569 get_pcie_lane_support(data->pcie_lane_cap,
570 pcie_table->entries[i].lane_width));
572 data->dpm_table.pcie_speed_table.count = max_entry - 1;
573 smum_update_smc_table(hwmgr, SMU_BIF_TABLE);
575 /* Hardcode Pcie Table */
576 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 0,
577 get_pcie_gen_support(data->pcie_gen_cap,
579 get_pcie_lane_support(data->pcie_lane_cap,
581 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 1,
582 get_pcie_gen_support(data->pcie_gen_cap,
584 get_pcie_lane_support(data->pcie_lane_cap,
586 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 2,
587 get_pcie_gen_support(data->pcie_gen_cap,
589 get_pcie_lane_support(data->pcie_lane_cap,
591 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 3,
592 get_pcie_gen_support(data->pcie_gen_cap,
594 get_pcie_lane_support(data->pcie_lane_cap,
596 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 4,
597 get_pcie_gen_support(data->pcie_gen_cap,
599 get_pcie_lane_support(data->pcie_lane_cap,
601 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 5,
602 get_pcie_gen_support(data->pcie_gen_cap,
604 get_pcie_lane_support(data->pcie_lane_cap,
607 data->dpm_table.pcie_speed_table.count = 6;
609 /* Populate last level for boot PCIE level, but do not increment count. */
610 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table,
611 data->dpm_table.pcie_speed_table.count,
612 get_pcie_gen_support(data->pcie_gen_cap,
614 get_pcie_lane_support(data->pcie_lane_cap,
620 static int smu7_reset_dpm_tables(struct pp_hwmgr *hwmgr)
622 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
624 memset(&(data->dpm_table), 0x00, sizeof(data->dpm_table));
626 phm_reset_single_dpm_table(
627 &data->dpm_table.sclk_table,
628 smum_get_mac_definition(hwmgr->smumgr,
629 SMU_MAX_LEVELS_GRAPHICS),
630 MAX_REGULAR_DPM_NUMBER);
631 phm_reset_single_dpm_table(
632 &data->dpm_table.mclk_table,
633 smum_get_mac_definition(hwmgr->smumgr,
634 SMU_MAX_LEVELS_MEMORY), MAX_REGULAR_DPM_NUMBER);
636 phm_reset_single_dpm_table(
637 &data->dpm_table.vddc_table,
638 smum_get_mac_definition(hwmgr->smumgr,
639 SMU_MAX_LEVELS_VDDC),
640 MAX_REGULAR_DPM_NUMBER);
641 phm_reset_single_dpm_table(
642 &data->dpm_table.vddci_table,
643 smum_get_mac_definition(hwmgr->smumgr,
644 SMU_MAX_LEVELS_VDDCI), MAX_REGULAR_DPM_NUMBER);
646 phm_reset_single_dpm_table(
647 &data->dpm_table.mvdd_table,
648 smum_get_mac_definition(hwmgr->smumgr,
649 SMU_MAX_LEVELS_MVDD),
650 MAX_REGULAR_DPM_NUMBER);
654 * This function is to initialize all DPM state tables
655 * for SMU7 based on the dependency table.
656 * Dynamic state patching function will then trim these
657 * state tables to the allowed range based
658 * on the power policy or external client requests,
659 * such as UVD request, etc.
662 static int smu7_setup_dpm_tables_v0(struct pp_hwmgr *hwmgr)
664 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
665 struct phm_clock_voltage_dependency_table *allowed_vdd_sclk_table =
666 hwmgr->dyn_state.vddc_dependency_on_sclk;
667 struct phm_clock_voltage_dependency_table *allowed_vdd_mclk_table =
668 hwmgr->dyn_state.vddc_dependency_on_mclk;
669 struct phm_cac_leakage_table *std_voltage_table =
670 hwmgr->dyn_state.cac_leakage_table;
673 PP_ASSERT_WITH_CODE(allowed_vdd_sclk_table != NULL,
674 "SCLK dependency table is missing. This table is mandatory", return -EINVAL);
675 PP_ASSERT_WITH_CODE(allowed_vdd_sclk_table->count >= 1,
676 "SCLK dependency table has to have is missing. This table is mandatory", return -EINVAL);
678 PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table != NULL,
679 "MCLK dependency table is missing. This table is mandatory", return -EINVAL);
680 PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table->count >= 1,
681 "VMCLK dependency table has to have is missing. This table is mandatory", return -EINVAL);
684 /* Initialize Sclk DPM table based on allow Sclk values*/
685 data->dpm_table.sclk_table.count = 0;
687 for (i = 0; i < allowed_vdd_sclk_table->count; i++) {
688 if (i == 0 || data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count-1].value !=
689 allowed_vdd_sclk_table->entries[i].clk) {
690 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].value =
691 allowed_vdd_sclk_table->entries[i].clk;
692 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].enabled = 1; /*(i==0) ? 1 : 0; to do */
693 data->dpm_table.sclk_table.count++;
697 PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table != NULL,
698 "MCLK dependency table is missing. This table is mandatory", return -EINVAL);
699 /* Initialize Mclk DPM table based on allow Mclk values */
700 data->dpm_table.mclk_table.count = 0;
701 for (i = 0; i < allowed_vdd_mclk_table->count; i++) {
702 if (i == 0 || data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count-1].value !=
703 allowed_vdd_mclk_table->entries[i].clk) {
704 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].value =
705 allowed_vdd_mclk_table->entries[i].clk;
706 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].enabled = 1; /*(i==0) ? 1 : 0; */
707 data->dpm_table.mclk_table.count++;
711 /* Initialize Vddc DPM table based on allow Vddc values. And populate corresponding std values. */
712 for (i = 0; i < allowed_vdd_sclk_table->count; i++) {
713 data->dpm_table.vddc_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].v;
714 data->dpm_table.vddc_table.dpm_levels[i].param1 = std_voltage_table->entries[i].Leakage;
715 /* param1 is for corresponding std voltage */
716 data->dpm_table.vddc_table.dpm_levels[i].enabled = 1;
719 data->dpm_table.vddc_table.count = allowed_vdd_sclk_table->count;
720 allowed_vdd_mclk_table = hwmgr->dyn_state.vddci_dependency_on_mclk;
722 if (NULL != allowed_vdd_mclk_table) {
723 /* Initialize Vddci DPM table based on allow Mclk values */
724 for (i = 0; i < allowed_vdd_mclk_table->count; i++) {
725 data->dpm_table.vddci_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].v;
726 data->dpm_table.vddci_table.dpm_levels[i].enabled = 1;
728 data->dpm_table.vddci_table.count = allowed_vdd_mclk_table->count;
731 allowed_vdd_mclk_table = hwmgr->dyn_state.mvdd_dependency_on_mclk;
733 if (NULL != allowed_vdd_mclk_table) {
735 * Initialize MVDD DPM table based on allow Mclk
738 for (i = 0; i < allowed_vdd_mclk_table->count; i++) {
739 data->dpm_table.mvdd_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].v;
740 data->dpm_table.mvdd_table.dpm_levels[i].enabled = 1;
742 data->dpm_table.mvdd_table.count = allowed_vdd_mclk_table->count;
748 static int smu7_setup_dpm_tables_v1(struct pp_hwmgr *hwmgr)
750 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
751 struct phm_ppt_v1_information *table_info =
752 (struct phm_ppt_v1_information *)(hwmgr->pptable);
755 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table;
756 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table;
758 if (table_info == NULL)
761 dep_sclk_table = table_info->vdd_dep_on_sclk;
762 dep_mclk_table = table_info->vdd_dep_on_mclk;
764 PP_ASSERT_WITH_CODE(dep_sclk_table != NULL,
765 "SCLK dependency table is missing.",
767 PP_ASSERT_WITH_CODE(dep_sclk_table->count >= 1,
768 "SCLK dependency table count is 0.",
771 PP_ASSERT_WITH_CODE(dep_mclk_table != NULL,
772 "MCLK dependency table is missing.",
774 PP_ASSERT_WITH_CODE(dep_mclk_table->count >= 1,
775 "MCLK dependency table count is 0",
778 /* Initialize Sclk DPM table based on allow Sclk values */
779 data->dpm_table.sclk_table.count = 0;
780 for (i = 0; i < dep_sclk_table->count; i++) {
781 if (i == 0 || data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count - 1].value !=
782 dep_sclk_table->entries[i].clk) {
784 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].value =
785 dep_sclk_table->entries[i].clk;
787 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].enabled =
788 (i == 0) ? true : false;
789 data->dpm_table.sclk_table.count++;
793 /* Initialize Mclk DPM table based on allow Mclk values */
794 data->dpm_table.mclk_table.count = 0;
795 for (i = 0; i < dep_mclk_table->count; i++) {
796 if (i == 0 || data->dpm_table.mclk_table.dpm_levels
797 [data->dpm_table.mclk_table.count - 1].value !=
798 dep_mclk_table->entries[i].clk) {
799 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].value =
800 dep_mclk_table->entries[i].clk;
801 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].enabled =
802 (i == 0) ? true : false;
803 data->dpm_table.mclk_table.count++;
810 static int smu7_setup_default_dpm_tables(struct pp_hwmgr *hwmgr)
812 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
814 smu7_reset_dpm_tables(hwmgr);
816 if (hwmgr->pp_table_version == PP_TABLE_V1)
817 smu7_setup_dpm_tables_v1(hwmgr);
818 else if (hwmgr->pp_table_version == PP_TABLE_V0)
819 smu7_setup_dpm_tables_v0(hwmgr);
821 smu7_setup_default_pcie_table(hwmgr);
823 /* save a copy of the default DPM table */
824 memcpy(&(data->golden_dpm_table), &(data->dpm_table),
825 sizeof(struct smu7_dpm_table));
829 uint32_t smu7_get_xclk(struct pp_hwmgr *hwmgr)
831 uint32_t reference_clock, tmp;
832 struct cgs_display_info info = {0};
833 struct cgs_mode_info mode_info;
835 info.mode_info = &mode_info;
837 tmp = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_CLKPIN_CNTL_2, MUX_TCLK_TO_XCLK);
842 cgs_get_active_displays_info(hwmgr->device, &info);
843 reference_clock = mode_info.ref_clock;
845 tmp = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_CLKPIN_CNTL, XTALIN_DIVIDE);
848 return reference_clock / 4;
850 return reference_clock;
853 static int smu7_enable_vrhot_gpio_interrupt(struct pp_hwmgr *hwmgr)
856 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
857 PHM_PlatformCaps_RegulatorHot))
858 return smum_send_msg_to_smc(hwmgr->smumgr,
859 PPSMC_MSG_EnableVRHotGPIOInterrupt);
864 static int smu7_enable_sclk_control(struct pp_hwmgr *hwmgr)
866 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
871 static int smu7_enable_ulv(struct pp_hwmgr *hwmgr)
873 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
875 if (data->ulv_supported)
876 return smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_EnableULV);
881 static int smu7_disable_ulv(struct pp_hwmgr *hwmgr)
883 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
885 if (data->ulv_supported)
886 return smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_DisableULV);
891 static int smu7_enable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
893 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
894 PHM_PlatformCaps_SclkDeepSleep)) {
895 if (smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_MASTER_DeepSleep_ON))
896 PP_ASSERT_WITH_CODE(false,
897 "Attempt to enable Master Deep Sleep switch failed!",
900 if (smum_send_msg_to_smc(hwmgr->smumgr,
901 PPSMC_MSG_MASTER_DeepSleep_OFF)) {
902 PP_ASSERT_WITH_CODE(false,
903 "Attempt to disable Master Deep Sleep switch failed!",
911 static int smu7_disable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
913 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
914 PHM_PlatformCaps_SclkDeepSleep)) {
915 if (smum_send_msg_to_smc(hwmgr->smumgr,
916 PPSMC_MSG_MASTER_DeepSleep_OFF)) {
917 PP_ASSERT_WITH_CODE(false,
918 "Attempt to disable Master Deep Sleep switch failed!",
926 static int smu7_disable_handshake_uvd(struct pp_hwmgr *hwmgr)
928 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
929 uint32_t soft_register_value = 0;
930 uint32_t handshake_disables_offset = data->soft_regs_start
931 + smum_get_offsetof(hwmgr->smumgr,
932 SMU_SoftRegisters, HandshakeDisables);
934 soft_register_value = cgs_read_ind_register(hwmgr->device,
935 CGS_IND_REG__SMC, handshake_disables_offset);
936 soft_register_value |= smum_get_mac_definition(hwmgr->smumgr,
937 SMU_UVD_MCLK_HANDSHAKE_DISABLE);
938 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
939 handshake_disables_offset, soft_register_value);
943 static int smu7_enable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
945 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
947 /* enable SCLK dpm */
948 if (!data->sclk_dpm_key_disabled)
950 (0 == smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_DPM_Enable)),
951 "Failed to enable SCLK DPM during DPM Start Function!",
954 /* enable MCLK dpm */
955 if (0 == data->mclk_dpm_key_disabled) {
956 if (!(hwmgr->feature_mask & PP_UVD_HANDSHAKE_MASK))
957 smu7_disable_handshake_uvd(hwmgr);
959 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
960 PPSMC_MSG_MCLKDPM_Enable)),
961 "Failed to enable MCLK DPM during DPM Start Function!",
964 PHM_WRITE_FIELD(hwmgr->device, MC_SEQ_CNTL_3, CAC_EN, 0x1);
966 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC0_CNTL, 0x5);
967 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC1_CNTL, 0x5);
968 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_CPL_CNTL, 0x100005);
970 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC0_CNTL, 0x400005);
971 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC1_CNTL, 0x400005);
972 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_CPL_CNTL, 0x500005);
978 static int smu7_start_dpm(struct pp_hwmgr *hwmgr)
980 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
982 /*enable general power management */
984 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
985 GLOBAL_PWRMGT_EN, 1);
987 /* enable sclk deep sleep */
989 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
992 /* prepare for PCIE DPM */
994 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
995 data->soft_regs_start +
996 smum_get_offsetof(hwmgr->smumgr, SMU_SoftRegisters,
997 VoltageChangeTimeout), 0x1000);
998 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE,
999 SWRST_COMMAND_1, RESETLC, 0x0);
1001 if (smu7_enable_sclk_mclk_dpm(hwmgr)) {
1002 pr_err("Failed to enable Sclk DPM and Mclk DPM!");
1006 /* enable PCIE dpm */
1007 if (0 == data->pcie_dpm_key_disabled) {
1008 PP_ASSERT_WITH_CODE(
1009 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
1010 PPSMC_MSG_PCIeDPM_Enable)),
1011 "Failed to enable pcie DPM during DPM Start Function!",
1015 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1016 PHM_PlatformCaps_Falcon_QuickTransition)) {
1017 PP_ASSERT_WITH_CODE((0 == smum_send_msg_to_smc(hwmgr->smumgr,
1018 PPSMC_MSG_EnableACDCGPIOInterrupt)),
1019 "Failed to enable AC DC GPIO Interrupt!",
1026 static int smu7_disable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
1028 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1030 /* disable SCLK dpm */
1031 if (!data->sclk_dpm_key_disabled) {
1032 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
1033 "Trying to disable SCLK DPM when DPM is disabled",
1035 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_DPM_Disable);
1038 /* disable MCLK dpm */
1039 if (!data->mclk_dpm_key_disabled) {
1040 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
1041 "Trying to disable MCLK DPM when DPM is disabled",
1043 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_MCLKDPM_Disable);
1049 static int smu7_stop_dpm(struct pp_hwmgr *hwmgr)
1051 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1053 /* disable general power management */
1054 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
1055 GLOBAL_PWRMGT_EN, 0);
1056 /* disable sclk deep sleep */
1057 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
1060 /* disable PCIE dpm */
1061 if (!data->pcie_dpm_key_disabled) {
1062 PP_ASSERT_WITH_CODE(
1063 (smum_send_msg_to_smc(hwmgr->smumgr,
1064 PPSMC_MSG_PCIeDPM_Disable) == 0),
1065 "Failed to disable pcie DPM during DPM Stop Function!",
1069 smu7_disable_sclk_mclk_dpm(hwmgr);
1071 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
1072 "Trying to disable voltage DPM when DPM is disabled",
1075 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_Voltage_Cntl_Disable);
1080 static void smu7_set_dpm_event_sources(struct pp_hwmgr *hwmgr, uint32_t sources)
1083 enum DPM_EVENT_SRC src;
1087 pr_err("Unknown throttling event sources.");
1093 case (1 << PHM_AutoThrottleSource_Thermal):
1095 src = DPM_EVENT_SRC_DIGITAL;
1097 case (1 << PHM_AutoThrottleSource_External):
1099 src = DPM_EVENT_SRC_EXTERNAL;
1101 case (1 << PHM_AutoThrottleSource_External) |
1102 (1 << PHM_AutoThrottleSource_Thermal):
1104 src = DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL;
1107 /* Order matters - don't enable thermal protection for the wrong source. */
1109 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_THERMAL_CTRL,
1110 DPM_EVENT_SRC, src);
1111 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
1112 THERMAL_PROTECTION_DIS,
1113 !phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1114 PHM_PlatformCaps_ThermalController));
1116 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
1117 THERMAL_PROTECTION_DIS, 1);
1120 static int smu7_enable_auto_throttle_source(struct pp_hwmgr *hwmgr,
1121 PHM_AutoThrottleSource source)
1123 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1125 if (!(data->active_auto_throttle_sources & (1 << source))) {
1126 data->active_auto_throttle_sources |= 1 << source;
1127 smu7_set_dpm_event_sources(hwmgr, data->active_auto_throttle_sources);
1132 static int smu7_enable_thermal_auto_throttle(struct pp_hwmgr *hwmgr)
1134 return smu7_enable_auto_throttle_source(hwmgr, PHM_AutoThrottleSource_Thermal);
1137 static int smu7_disable_auto_throttle_source(struct pp_hwmgr *hwmgr,
1138 PHM_AutoThrottleSource source)
1140 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1142 if (data->active_auto_throttle_sources & (1 << source)) {
1143 data->active_auto_throttle_sources &= ~(1 << source);
1144 smu7_set_dpm_event_sources(hwmgr, data->active_auto_throttle_sources);
1149 static int smu7_disable_thermal_auto_throttle(struct pp_hwmgr *hwmgr)
1151 return smu7_disable_auto_throttle_source(hwmgr, PHM_AutoThrottleSource_Thermal);
1154 static int smu7_pcie_performance_request(struct pp_hwmgr *hwmgr)
1156 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1157 data->pcie_performance_request = true;
1162 static int smu7_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
1167 tmp_result = (!smum_is_dpm_running(hwmgr)) ? 0 : -1;
1168 PP_ASSERT_WITH_CODE(tmp_result == 0,
1169 "DPM is already running",
1172 if (smu7_voltage_control(hwmgr)) {
1173 tmp_result = smu7_enable_voltage_control(hwmgr);
1174 PP_ASSERT_WITH_CODE(tmp_result == 0,
1175 "Failed to enable voltage control!",
1176 result = tmp_result);
1178 tmp_result = smu7_construct_voltage_tables(hwmgr);
1179 PP_ASSERT_WITH_CODE((0 == tmp_result),
1180 "Failed to contruct voltage tables!",
1181 result = tmp_result);
1183 smum_initialize_mc_reg_table(hwmgr);
1185 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1186 PHM_PlatformCaps_EngineSpreadSpectrumSupport))
1187 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1188 GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, 1);
1190 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1191 PHM_PlatformCaps_ThermalController))
1192 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1193 GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, 0);
1195 tmp_result = smu7_program_static_screen_threshold_parameters(hwmgr);
1196 PP_ASSERT_WITH_CODE((0 == tmp_result),
1197 "Failed to program static screen threshold parameters!",
1198 result = tmp_result);
1200 tmp_result = smu7_enable_display_gap(hwmgr);
1201 PP_ASSERT_WITH_CODE((0 == tmp_result),
1202 "Failed to enable display gap!", result = tmp_result);
1204 tmp_result = smu7_program_voting_clients(hwmgr);
1205 PP_ASSERT_WITH_CODE((0 == tmp_result),
1206 "Failed to program voting clients!", result = tmp_result);
1208 tmp_result = smum_process_firmware_header(hwmgr);
1209 PP_ASSERT_WITH_CODE((0 == tmp_result),
1210 "Failed to process firmware header!", result = tmp_result);
1212 tmp_result = smu7_initial_switch_from_arbf0_to_f1(hwmgr);
1213 PP_ASSERT_WITH_CODE((0 == tmp_result),
1214 "Failed to initialize switch from ArbF0 to F1!",
1215 result = tmp_result);
1217 result = smu7_setup_default_dpm_tables(hwmgr);
1218 PP_ASSERT_WITH_CODE(0 == result,
1219 "Failed to setup default DPM tables!", return result);
1221 tmp_result = smum_init_smc_table(hwmgr);
1222 PP_ASSERT_WITH_CODE((0 == tmp_result),
1223 "Failed to initialize SMC table!", result = tmp_result);
1225 tmp_result = smu7_enable_vrhot_gpio_interrupt(hwmgr);
1226 PP_ASSERT_WITH_CODE((0 == tmp_result),
1227 "Failed to enable VR hot GPIO interrupt!", result = tmp_result);
1229 smum_send_msg_to_smc(hwmgr->smumgr, (PPSMC_Msg)PPSMC_NoDisplay);
1231 tmp_result = smu7_enable_sclk_control(hwmgr);
1232 PP_ASSERT_WITH_CODE((0 == tmp_result),
1233 "Failed to enable SCLK control!", result = tmp_result);
1235 tmp_result = smu7_enable_smc_voltage_controller(hwmgr);
1236 PP_ASSERT_WITH_CODE((0 == tmp_result),
1237 "Failed to enable voltage control!", result = tmp_result);
1239 tmp_result = smu7_enable_ulv(hwmgr);
1240 PP_ASSERT_WITH_CODE((0 == tmp_result),
1241 "Failed to enable ULV!", result = tmp_result);
1243 tmp_result = smu7_enable_deep_sleep_master_switch(hwmgr);
1244 PP_ASSERT_WITH_CODE((0 == tmp_result),
1245 "Failed to enable deep sleep master switch!", result = tmp_result);
1247 tmp_result = smu7_enable_didt_config(hwmgr);
1248 PP_ASSERT_WITH_CODE((tmp_result == 0),
1249 "Failed to enable deep sleep master switch!", result = tmp_result);
1251 tmp_result = smu7_start_dpm(hwmgr);
1252 PP_ASSERT_WITH_CODE((0 == tmp_result),
1253 "Failed to start DPM!", result = tmp_result);
1255 tmp_result = smu7_enable_smc_cac(hwmgr);
1256 PP_ASSERT_WITH_CODE((0 == tmp_result),
1257 "Failed to enable SMC CAC!", result = tmp_result);
1259 tmp_result = smu7_enable_power_containment(hwmgr);
1260 PP_ASSERT_WITH_CODE((0 == tmp_result),
1261 "Failed to enable power containment!", result = tmp_result);
1263 tmp_result = smu7_power_control_set_level(hwmgr);
1264 PP_ASSERT_WITH_CODE((0 == tmp_result),
1265 "Failed to power control set level!", result = tmp_result);
1267 tmp_result = smu7_enable_thermal_auto_throttle(hwmgr);
1268 PP_ASSERT_WITH_CODE((0 == tmp_result),
1269 "Failed to enable thermal auto throttle!", result = tmp_result);
1271 tmp_result = smu7_pcie_performance_request(hwmgr);
1272 PP_ASSERT_WITH_CODE((0 == tmp_result),
1273 "pcie performance request failed!", result = tmp_result);
1278 int smu7_disable_dpm_tasks(struct pp_hwmgr *hwmgr)
1280 int tmp_result, result = 0;
1282 tmp_result = (smum_is_dpm_running(hwmgr)) ? 0 : -1;
1283 PP_ASSERT_WITH_CODE(tmp_result == 0,
1284 "DPM is not running right now, no need to disable DPM!",
1287 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1288 PHM_PlatformCaps_ThermalController))
1289 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1290 GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, 1);
1292 tmp_result = smu7_disable_power_containment(hwmgr);
1293 PP_ASSERT_WITH_CODE((tmp_result == 0),
1294 "Failed to disable power containment!", result = tmp_result);
1296 tmp_result = smu7_disable_smc_cac(hwmgr);
1297 PP_ASSERT_WITH_CODE((tmp_result == 0),
1298 "Failed to disable SMC CAC!", result = tmp_result);
1300 tmp_result = smu7_disable_didt_config(hwmgr);
1301 PP_ASSERT_WITH_CODE((tmp_result == 0),
1302 "Failed to disable DIDT!", result = tmp_result);
1304 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1305 CG_SPLL_SPREAD_SPECTRUM, SSEN, 0);
1306 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1307 GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, 0);
1309 tmp_result = smu7_disable_thermal_auto_throttle(hwmgr);
1310 PP_ASSERT_WITH_CODE((tmp_result == 0),
1311 "Failed to disable thermal auto throttle!", result = tmp_result);
1313 tmp_result = smu7_avfs_control(hwmgr, false);
1314 PP_ASSERT_WITH_CODE((tmp_result == 0),
1315 "Failed to disable AVFS!", result = tmp_result);
1317 tmp_result = smu7_stop_dpm(hwmgr);
1318 PP_ASSERT_WITH_CODE((tmp_result == 0),
1319 "Failed to stop DPM!", result = tmp_result);
1321 tmp_result = smu7_disable_deep_sleep_master_switch(hwmgr);
1322 PP_ASSERT_WITH_CODE((tmp_result == 0),
1323 "Failed to disable deep sleep master switch!", result = tmp_result);
1325 tmp_result = smu7_disable_ulv(hwmgr);
1326 PP_ASSERT_WITH_CODE((tmp_result == 0),
1327 "Failed to disable ULV!", result = tmp_result);
1329 tmp_result = smu7_clear_voting_clients(hwmgr);
1330 PP_ASSERT_WITH_CODE((tmp_result == 0),
1331 "Failed to clear voting clients!", result = tmp_result);
1333 tmp_result = smu7_reset_to_default(hwmgr);
1334 PP_ASSERT_WITH_CODE((tmp_result == 0),
1335 "Failed to reset to default!", result = tmp_result);
1337 tmp_result = smu7_force_switch_to_arbf0(hwmgr);
1338 PP_ASSERT_WITH_CODE((tmp_result == 0),
1339 "Failed to force to switch arbf0!", result = tmp_result);
1344 int smu7_reset_asic_tasks(struct pp_hwmgr *hwmgr)
1350 static void smu7_init_dpm_defaults(struct pp_hwmgr *hwmgr)
1352 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1353 struct phm_ppt_v1_information *table_info =
1354 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1355 struct cgs_system_info sys_info = {0};
1358 data->dll_default_on = false;
1359 data->mclk_dpm0_activity_target = 0xa;
1360 data->mclk_activity_target = SMU7_MCLK_TARGETACTIVITY_DFLT;
1361 data->vddc_vddgfx_delta = 300;
1362 data->static_screen_threshold = SMU7_STATICSCREENTHRESHOLD_DFLT;
1363 data->static_screen_threshold_unit = SMU7_STATICSCREENTHRESHOLDUNIT_DFLT;
1364 data->voting_rights_clients0 = SMU7_VOTINGRIGHTSCLIENTS_DFLT0;
1365 data->voting_rights_clients1 = SMU7_VOTINGRIGHTSCLIENTS_DFLT1;
1366 data->voting_rights_clients2 = SMU7_VOTINGRIGHTSCLIENTS_DFLT2;
1367 data->voting_rights_clients3 = SMU7_VOTINGRIGHTSCLIENTS_DFLT3;
1368 data->voting_rights_clients4 = SMU7_VOTINGRIGHTSCLIENTS_DFLT4;
1369 data->voting_rights_clients5 = SMU7_VOTINGRIGHTSCLIENTS_DFLT5;
1370 data->voting_rights_clients6 = SMU7_VOTINGRIGHTSCLIENTS_DFLT6;
1371 data->voting_rights_clients7 = SMU7_VOTINGRIGHTSCLIENTS_DFLT7;
1373 data->mclk_dpm_key_disabled = hwmgr->feature_mask & PP_MCLK_DPM_MASK ? false : true;
1374 data->sclk_dpm_key_disabled = hwmgr->feature_mask & PP_SCLK_DPM_MASK ? false : true;
1375 data->pcie_dpm_key_disabled = hwmgr->feature_mask & PP_PCIE_DPM_MASK ? false : true;
1376 /* need to set voltage control types before EVV patching */
1377 data->voltage_control = SMU7_VOLTAGE_CONTROL_NONE;
1378 data->vddci_control = SMU7_VOLTAGE_CONTROL_NONE;
1379 data->mvdd_control = SMU7_VOLTAGE_CONTROL_NONE;
1380 data->enable_tdc_limit_feature = true;
1381 data->enable_pkg_pwr_tracking_feature = true;
1382 data->force_pcie_gen = PP_PCIEGenInvalid;
1383 data->ulv_supported = hwmgr->feature_mask & PP_ULV_MASK ? true : false;
1385 if (hwmgr->chip_id == CHIP_POLARIS12 || hwmgr->smumgr->is_kicker) {
1388 atomctrl_get_svi2_info(hwmgr, VOLTAGE_TYPE_VDDC, &tmp1, &tmp2,
1390 tmp3 = (tmp3 >> 5) & 0x3;
1391 data->vddc_phase_shed_control = ((tmp3 << 1) | (tmp3 >> 1)) & 0x3;
1394 data->fast_watermark_threshold = 100;
1395 if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1396 VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_SVID2))
1397 data->voltage_control = SMU7_VOLTAGE_CONTROL_BY_SVID2;
1399 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1400 PHM_PlatformCaps_ControlVDDGFX)) {
1401 if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1402 VOLTAGE_TYPE_VDDGFX, VOLTAGE_OBJ_SVID2)) {
1403 data->vdd_gfx_control = SMU7_VOLTAGE_CONTROL_BY_SVID2;
1407 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1408 PHM_PlatformCaps_EnableMVDDControl)) {
1409 if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1410 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT))
1411 data->mvdd_control = SMU7_VOLTAGE_CONTROL_BY_GPIO;
1412 else if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1413 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_SVID2))
1414 data->mvdd_control = SMU7_VOLTAGE_CONTROL_BY_SVID2;
1417 if (SMU7_VOLTAGE_CONTROL_NONE == data->vdd_gfx_control) {
1418 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1419 PHM_PlatformCaps_ControlVDDGFX);
1422 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1423 PHM_PlatformCaps_ControlVDDCI)) {
1424 if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1425 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT))
1426 data->vddci_control = SMU7_VOLTAGE_CONTROL_BY_GPIO;
1427 else if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1428 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_SVID2))
1429 data->vddci_control = SMU7_VOLTAGE_CONTROL_BY_SVID2;
1432 if (data->mvdd_control == SMU7_VOLTAGE_CONTROL_NONE)
1433 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1434 PHM_PlatformCaps_EnableMVDDControl);
1436 if (data->vddci_control == SMU7_VOLTAGE_CONTROL_NONE)
1437 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1438 PHM_PlatformCaps_ControlVDDCI);
1440 if ((hwmgr->pp_table_version != PP_TABLE_V0) && (hwmgr->feature_mask & PP_CLOCK_STRETCH_MASK)
1441 && (table_info->cac_dtp_table->usClockStretchAmount != 0))
1442 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
1443 PHM_PlatformCaps_ClockStretcher);
1445 data->pcie_gen_performance.max = PP_PCIEGen1;
1446 data->pcie_gen_performance.min = PP_PCIEGen3;
1447 data->pcie_gen_power_saving.max = PP_PCIEGen1;
1448 data->pcie_gen_power_saving.min = PP_PCIEGen3;
1449 data->pcie_lane_performance.max = 0;
1450 data->pcie_lane_performance.min = 16;
1451 data->pcie_lane_power_saving.max = 0;
1452 data->pcie_lane_power_saving.min = 16;
1454 sys_info.size = sizeof(struct cgs_system_info);
1455 sys_info.info_id = CGS_SYSTEM_INFO_PG_FLAGS;
1456 result = cgs_query_system_info(hwmgr->device, &sys_info);
1458 if (sys_info.value & AMD_PG_SUPPORT_UVD)
1459 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
1460 PHM_PlatformCaps_UVDPowerGating);
1461 if (sys_info.value & AMD_PG_SUPPORT_VCE)
1462 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
1463 PHM_PlatformCaps_VCEPowerGating);
1468 * Get Leakage VDDC based on leakage ID.
1470 * @param hwmgr the address of the powerplay hardware manager.
1473 static int smu7_get_evv_voltages(struct pp_hwmgr *hwmgr)
1475 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1478 uint16_t vddgfx = 0;
1481 struct phm_ppt_v1_information *table_info =
1482 (struct phm_ppt_v1_information *)hwmgr->pptable;
1483 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table = NULL;
1486 for (i = 0; i < SMU7_MAX_LEAKAGE_COUNT; i++) {
1487 vv_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i;
1489 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
1490 if ((hwmgr->pp_table_version == PP_TABLE_V1)
1491 && !phm_get_sclk_for_voltage_evv(hwmgr,
1492 table_info->vddgfx_lookup_table, vv_id, &sclk)) {
1493 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1494 PHM_PlatformCaps_ClockStretcher)) {
1495 sclk_table = table_info->vdd_dep_on_sclk;
1497 for (j = 1; j < sclk_table->count; j++) {
1498 if (sclk_table->entries[j].clk == sclk &&
1499 sclk_table->entries[j].cks_enable == 0) {
1505 if (0 == atomctrl_get_voltage_evv_on_sclk
1506 (hwmgr, VOLTAGE_TYPE_VDDGFX, sclk,
1508 /* need to make sure vddgfx is less than 2v or else, it could burn the ASIC. */
1509 PP_ASSERT_WITH_CODE((vddgfx < 2000 && vddgfx != 0), "Invalid VDDGFX value!", return -EINVAL);
1511 /* the voltage should not be zero nor equal to leakage ID */
1512 if (vddgfx != 0 && vddgfx != vv_id) {
1513 data->vddcgfx_leakage.actual_voltage[data->vddcgfx_leakage.count] = vddgfx;
1514 data->vddcgfx_leakage.leakage_id[data->vddcgfx_leakage.count] = vv_id;
1515 data->vddcgfx_leakage.count++;
1518 pr_info("Error retrieving EVV voltage value!\n");
1522 if ((hwmgr->pp_table_version == PP_TABLE_V0)
1523 || !phm_get_sclk_for_voltage_evv(hwmgr,
1524 table_info->vddc_lookup_table, vv_id, &sclk)) {
1525 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1526 PHM_PlatformCaps_ClockStretcher)) {
1527 if (table_info == NULL)
1529 sclk_table = table_info->vdd_dep_on_sclk;
1531 for (j = 1; j < sclk_table->count; j++) {
1532 if (sclk_table->entries[j].clk == sclk &&
1533 sclk_table->entries[j].cks_enable == 0) {
1540 if (phm_get_voltage_evv_on_sclk(hwmgr,
1542 sclk, vv_id, &vddc) == 0) {
1543 if (vddc >= 2000 || vddc == 0)
1546 pr_debug("failed to retrieving EVV voltage!\n");
1550 /* the voltage should not be zero nor equal to leakage ID */
1551 if (vddc != 0 && vddc != vv_id) {
1552 data->vddc_leakage.actual_voltage[data->vddc_leakage.count] = (uint16_t)(vddc);
1553 data->vddc_leakage.leakage_id[data->vddc_leakage.count] = vv_id;
1554 data->vddc_leakage.count++;
1564 * Change virtual leakage voltage to actual value.
1566 * @param hwmgr the address of the powerplay hardware manager.
1567 * @param pointer to changing voltage
1568 * @param pointer to leakage table
1570 static void smu7_patch_ppt_v1_with_vdd_leakage(struct pp_hwmgr *hwmgr,
1571 uint16_t *voltage, struct smu7_leakage_voltage *leakage_table)
1575 /* search for leakage voltage ID 0xff01 ~ 0xff08 */
1576 for (index = 0; index < leakage_table->count; index++) {
1577 /* if this voltage matches a leakage voltage ID */
1578 /* patch with actual leakage voltage */
1579 if (leakage_table->leakage_id[index] == *voltage) {
1580 *voltage = leakage_table->actual_voltage[index];
1585 if (*voltage > ATOM_VIRTUAL_VOLTAGE_ID0)
1586 pr_err("Voltage value looks like a Leakage ID but it's not patched \n");
1590 * Patch voltage lookup table by EVV leakages.
1592 * @param hwmgr the address of the powerplay hardware manager.
1593 * @param pointer to voltage lookup table
1594 * @param pointer to leakage table
1597 static int smu7_patch_lookup_table_with_leakage(struct pp_hwmgr *hwmgr,
1598 phm_ppt_v1_voltage_lookup_table *lookup_table,
1599 struct smu7_leakage_voltage *leakage_table)
1603 for (i = 0; i < lookup_table->count; i++)
1604 smu7_patch_ppt_v1_with_vdd_leakage(hwmgr,
1605 &lookup_table->entries[i].us_vdd, leakage_table);
1610 static int smu7_patch_clock_voltage_limits_with_vddc_leakage(
1611 struct pp_hwmgr *hwmgr, struct smu7_leakage_voltage *leakage_table,
1614 struct phm_ppt_v1_information *table_info =
1615 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1616 smu7_patch_ppt_v1_with_vdd_leakage(hwmgr, (uint16_t *)vddc, leakage_table);
1617 hwmgr->dyn_state.max_clock_voltage_on_dc.vddc =
1618 table_info->max_clock_voltage_on_dc.vddc;
1622 static int smu7_patch_voltage_dependency_tables_with_lookup_table(
1623 struct pp_hwmgr *hwmgr)
1627 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1628 struct phm_ppt_v1_information *table_info =
1629 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1631 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
1632 table_info->vdd_dep_on_sclk;
1633 struct phm_ppt_v1_clock_voltage_dependency_table *mclk_table =
1634 table_info->vdd_dep_on_mclk;
1635 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
1636 table_info->mm_dep_table;
1638 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
1639 for (entry_id = 0; entry_id < sclk_table->count; ++entry_id) {
1640 voltage_id = sclk_table->entries[entry_id].vddInd;
1641 sclk_table->entries[entry_id].vddgfx =
1642 table_info->vddgfx_lookup_table->entries[voltage_id].us_vdd;
1645 for (entry_id = 0; entry_id < sclk_table->count; ++entry_id) {
1646 voltage_id = sclk_table->entries[entry_id].vddInd;
1647 sclk_table->entries[entry_id].vddc =
1648 table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
1652 for (entry_id = 0; entry_id < mclk_table->count; ++entry_id) {
1653 voltage_id = mclk_table->entries[entry_id].vddInd;
1654 mclk_table->entries[entry_id].vddc =
1655 table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
1658 for (entry_id = 0; entry_id < mm_table->count; ++entry_id) {
1659 voltage_id = mm_table->entries[entry_id].vddcInd;
1660 mm_table->entries[entry_id].vddc =
1661 table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
1668 static int phm_add_voltage(struct pp_hwmgr *hwmgr,
1669 phm_ppt_v1_voltage_lookup_table *look_up_table,
1670 phm_ppt_v1_voltage_lookup_record *record)
1674 PP_ASSERT_WITH_CODE((NULL != look_up_table),
1675 "Lookup Table empty.", return -EINVAL);
1676 PP_ASSERT_WITH_CODE((0 != look_up_table->count),
1677 "Lookup Table empty.", return -EINVAL);
1679 i = smum_get_mac_definition(hwmgr->smumgr, SMU_MAX_LEVELS_VDDGFX);
1680 PP_ASSERT_WITH_CODE((i >= look_up_table->count),
1681 "Lookup Table is full.", return -EINVAL);
1683 /* This is to avoid entering duplicate calculated records. */
1684 for (i = 0; i < look_up_table->count; i++) {
1685 if (look_up_table->entries[i].us_vdd == record->us_vdd) {
1686 if (look_up_table->entries[i].us_calculated == 1)
1692 look_up_table->entries[i].us_calculated = 1;
1693 look_up_table->entries[i].us_vdd = record->us_vdd;
1694 look_up_table->entries[i].us_cac_low = record->us_cac_low;
1695 look_up_table->entries[i].us_cac_mid = record->us_cac_mid;
1696 look_up_table->entries[i].us_cac_high = record->us_cac_high;
1697 /* Only increment the count when we're appending, not replacing duplicate entry. */
1698 if (i == look_up_table->count)
1699 look_up_table->count++;
1705 static int smu7_calc_voltage_dependency_tables(struct pp_hwmgr *hwmgr)
1708 struct phm_ppt_v1_voltage_lookup_record v_record;
1709 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1710 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
1712 phm_ppt_v1_clock_voltage_dependency_table *sclk_table = pptable_info->vdd_dep_on_sclk;
1713 phm_ppt_v1_clock_voltage_dependency_table *mclk_table = pptable_info->vdd_dep_on_mclk;
1715 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
1716 for (entry_id = 0; entry_id < sclk_table->count; ++entry_id) {
1717 if (sclk_table->entries[entry_id].vdd_offset & (1 << 15))
1718 v_record.us_vdd = sclk_table->entries[entry_id].vddgfx +
1719 sclk_table->entries[entry_id].vdd_offset - 0xFFFF;
1721 v_record.us_vdd = sclk_table->entries[entry_id].vddgfx +
1722 sclk_table->entries[entry_id].vdd_offset;
1724 sclk_table->entries[entry_id].vddc =
1725 v_record.us_cac_low = v_record.us_cac_mid =
1726 v_record.us_cac_high = v_record.us_vdd;
1728 phm_add_voltage(hwmgr, pptable_info->vddc_lookup_table, &v_record);
1731 for (entry_id = 0; entry_id < mclk_table->count; ++entry_id) {
1732 if (mclk_table->entries[entry_id].vdd_offset & (1 << 15))
1733 v_record.us_vdd = mclk_table->entries[entry_id].vddc +
1734 mclk_table->entries[entry_id].vdd_offset - 0xFFFF;
1736 v_record.us_vdd = mclk_table->entries[entry_id].vddc +
1737 mclk_table->entries[entry_id].vdd_offset;
1739 mclk_table->entries[entry_id].vddgfx = v_record.us_cac_low =
1740 v_record.us_cac_mid = v_record.us_cac_high = v_record.us_vdd;
1741 phm_add_voltage(hwmgr, pptable_info->vddgfx_lookup_table, &v_record);
1747 static int smu7_calc_mm_voltage_dependency_table(struct pp_hwmgr *hwmgr)
1750 struct phm_ppt_v1_voltage_lookup_record v_record;
1751 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1752 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
1753 phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table = pptable_info->mm_dep_table;
1755 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
1756 for (entry_id = 0; entry_id < mm_table->count; entry_id++) {
1757 if (mm_table->entries[entry_id].vddgfx_offset & (1 << 15))
1758 v_record.us_vdd = mm_table->entries[entry_id].vddc +
1759 mm_table->entries[entry_id].vddgfx_offset - 0xFFFF;
1761 v_record.us_vdd = mm_table->entries[entry_id].vddc +
1762 mm_table->entries[entry_id].vddgfx_offset;
1764 /* Add the calculated VDDGFX to the VDDGFX lookup table */
1765 mm_table->entries[entry_id].vddgfx = v_record.us_cac_low =
1766 v_record.us_cac_mid = v_record.us_cac_high = v_record.us_vdd;
1767 phm_add_voltage(hwmgr, pptable_info->vddgfx_lookup_table, &v_record);
1773 static int smu7_sort_lookup_table(struct pp_hwmgr *hwmgr,
1774 struct phm_ppt_v1_voltage_lookup_table *lookup_table)
1776 uint32_t table_size, i, j;
1777 struct phm_ppt_v1_voltage_lookup_record tmp_voltage_lookup_record;
1778 table_size = lookup_table->count;
1780 PP_ASSERT_WITH_CODE(0 != lookup_table->count,
1781 "Lookup table is empty", return -EINVAL);
1783 /* Sorting voltages */
1784 for (i = 0; i < table_size - 1; i++) {
1785 for (j = i + 1; j > 0; j--) {
1786 if (lookup_table->entries[j].us_vdd <
1787 lookup_table->entries[j - 1].us_vdd) {
1788 tmp_voltage_lookup_record = lookup_table->entries[j - 1];
1789 lookup_table->entries[j - 1] = lookup_table->entries[j];
1790 lookup_table->entries[j] = tmp_voltage_lookup_record;
1798 static int smu7_complete_dependency_tables(struct pp_hwmgr *hwmgr)
1802 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1803 struct phm_ppt_v1_information *table_info =
1804 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1806 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
1807 tmp_result = smu7_patch_lookup_table_with_leakage(hwmgr,
1808 table_info->vddgfx_lookup_table, &(data->vddcgfx_leakage));
1809 if (tmp_result != 0)
1810 result = tmp_result;
1812 smu7_patch_ppt_v1_with_vdd_leakage(hwmgr,
1813 &table_info->max_clock_voltage_on_dc.vddgfx, &(data->vddcgfx_leakage));
1816 tmp_result = smu7_patch_lookup_table_with_leakage(hwmgr,
1817 table_info->vddc_lookup_table, &(data->vddc_leakage));
1819 result = tmp_result;
1821 tmp_result = smu7_patch_clock_voltage_limits_with_vddc_leakage(hwmgr,
1822 &(data->vddc_leakage), &table_info->max_clock_voltage_on_dc.vddc);
1824 result = tmp_result;
1827 tmp_result = smu7_patch_voltage_dependency_tables_with_lookup_table(hwmgr);
1829 result = tmp_result;
1831 tmp_result = smu7_calc_voltage_dependency_tables(hwmgr);
1833 result = tmp_result;
1835 tmp_result = smu7_calc_mm_voltage_dependency_table(hwmgr);
1837 result = tmp_result;
1839 tmp_result = smu7_sort_lookup_table(hwmgr, table_info->vddgfx_lookup_table);
1841 result = tmp_result;
1843 tmp_result = smu7_sort_lookup_table(hwmgr, table_info->vddc_lookup_table);
1845 result = tmp_result;
1850 static int smu7_set_private_data_based_on_pptable_v1(struct pp_hwmgr *hwmgr)
1852 struct phm_ppt_v1_information *table_info =
1853 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1855 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_sclk_vdd_table =
1856 table_info->vdd_dep_on_sclk;
1857 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_mclk_vdd_table =
1858 table_info->vdd_dep_on_mclk;
1860 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table != NULL,
1861 "VDD dependency on SCLK table is missing.",
1863 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table->count >= 1,
1864 "VDD dependency on SCLK table has to have is missing.",
1867 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table != NULL,
1868 "VDD dependency on MCLK table is missing",
1870 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table->count >= 1,
1871 "VDD dependency on MCLK table has to have is missing.",
1874 table_info->max_clock_voltage_on_ac.sclk =
1875 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].clk;
1876 table_info->max_clock_voltage_on_ac.mclk =
1877 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].clk;
1878 table_info->max_clock_voltage_on_ac.vddc =
1879 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].vddc;
1880 table_info->max_clock_voltage_on_ac.vddci =
1881 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].vddci;
1883 hwmgr->dyn_state.max_clock_voltage_on_ac.sclk = table_info->max_clock_voltage_on_ac.sclk;
1884 hwmgr->dyn_state.max_clock_voltage_on_ac.mclk = table_info->max_clock_voltage_on_ac.mclk;
1885 hwmgr->dyn_state.max_clock_voltage_on_ac.vddc = table_info->max_clock_voltage_on_ac.vddc;
1886 hwmgr->dyn_state.max_clock_voltage_on_ac.vddci = table_info->max_clock_voltage_on_ac.vddci;
1891 static int smu7_patch_voltage_workaround(struct pp_hwmgr *hwmgr)
1893 struct phm_ppt_v1_information *table_info =
1894 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1895 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table;
1896 struct phm_ppt_v1_voltage_lookup_table *lookup_table;
1898 uint32_t hw_revision, sub_vendor_id, sub_sys_id;
1899 struct cgs_system_info sys_info = {0};
1901 if (table_info != NULL) {
1902 dep_mclk_table = table_info->vdd_dep_on_mclk;
1903 lookup_table = table_info->vddc_lookup_table;
1907 sys_info.size = sizeof(struct cgs_system_info);
1909 sys_info.info_id = CGS_SYSTEM_INFO_PCIE_REV;
1910 cgs_query_system_info(hwmgr->device, &sys_info);
1911 hw_revision = (uint32_t)sys_info.value;
1913 sys_info.info_id = CGS_SYSTEM_INFO_PCIE_SUB_SYS_ID;
1914 cgs_query_system_info(hwmgr->device, &sys_info);
1915 sub_sys_id = (uint32_t)sys_info.value;
1917 sys_info.info_id = CGS_SYSTEM_INFO_PCIE_SUB_SYS_VENDOR_ID;
1918 cgs_query_system_info(hwmgr->device, &sys_info);
1919 sub_vendor_id = (uint32_t)sys_info.value;
1921 if (hwmgr->chip_id == CHIP_POLARIS10 && hw_revision == 0xC7 &&
1922 ((sub_sys_id == 0xb37 && sub_vendor_id == 0x1002) ||
1923 (sub_sys_id == 0x4a8 && sub_vendor_id == 0x1043) ||
1924 (sub_sys_id == 0x9480 && sub_vendor_id == 0x1682))) {
1925 if (lookup_table->entries[dep_mclk_table->entries[dep_mclk_table->count-1].vddInd].us_vdd >= 1000)
1928 for (i = 0; i < lookup_table->count; i++) {
1929 if (lookup_table->entries[i].us_vdd < 0xff01 && lookup_table->entries[i].us_vdd >= 1000) {
1930 dep_mclk_table->entries[dep_mclk_table->count-1].vddInd = (uint8_t) i;
1938 static int smu7_thermal_parameter_init(struct pp_hwmgr *hwmgr)
1940 struct pp_atomctrl_gpio_pin_assignment gpio_pin_assignment;
1942 struct phm_ppt_v1_information *table_info =
1943 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1946 if (atomctrl_get_pp_assign_pin(hwmgr, VDDC_PCC_GPIO_PINID, &gpio_pin_assignment)) {
1947 temp_reg = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCNB_PWRMGT_CNTL);
1948 switch (gpio_pin_assignment.uc_gpio_pin_bit_shift) {
1950 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x1);
1953 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x2);
1956 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW, 0x1);
1959 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, FORCE_NB_PS1, 0x1);
1962 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, DPM_ENABLED, 0x1);
1967 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCNB_PWRMGT_CNTL, temp_reg);
1970 if (table_info == NULL)
1973 if (table_info->cac_dtp_table->usDefaultTargetOperatingTemp != 0 &&
1974 hwmgr->thermal_controller.advanceFanControlParameters.ucFanControlMode) {
1975 hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMMinLimit =
1976 (uint16_t)hwmgr->thermal_controller.advanceFanControlParameters.ucMinimumPWMLimit;
1978 hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMMaxLimit =
1979 (uint16_t)hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanPWM;
1981 hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMStep = 1;
1983 hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMMaxLimit = 100;
1985 hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMMinLimit =
1986 (uint16_t)hwmgr->thermal_controller.advanceFanControlParameters.ucMinimumPWMLimit;
1988 hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMStep = 1;
1990 table_info->cac_dtp_table->usDefaultTargetOperatingTemp = (table_info->cac_dtp_table->usDefaultTargetOperatingTemp >= 50) ?
1991 (table_info->cac_dtp_table->usDefaultTargetOperatingTemp - 50) : 0;
1993 table_info->cac_dtp_table->usOperatingTempMaxLimit = table_info->cac_dtp_table->usDefaultTargetOperatingTemp;
1994 table_info->cac_dtp_table->usOperatingTempStep = 1;
1995 table_info->cac_dtp_table->usOperatingTempHyst = 1;
1997 hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanPWM =
1998 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanPWM;
2000 hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanRPM =
2001 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanRPM;
2003 hwmgr->dyn_state.cac_dtp_table->usOperatingTempMinLimit =
2004 table_info->cac_dtp_table->usOperatingTempMinLimit;
2006 hwmgr->dyn_state.cac_dtp_table->usOperatingTempMaxLimit =
2007 table_info->cac_dtp_table->usOperatingTempMaxLimit;
2009 hwmgr->dyn_state.cac_dtp_table->usDefaultTargetOperatingTemp =
2010 table_info->cac_dtp_table->usDefaultTargetOperatingTemp;
2012 hwmgr->dyn_state.cac_dtp_table->usOperatingTempStep =
2013 table_info->cac_dtp_table->usOperatingTempStep;
2015 hwmgr->dyn_state.cac_dtp_table->usTargetOperatingTemp =
2016 table_info->cac_dtp_table->usTargetOperatingTemp;
2017 if (hwmgr->feature_mask & PP_OD_FUZZY_FAN_CONTROL_MASK)
2018 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2019 PHM_PlatformCaps_ODFuzzyFanControlSupport);
2026 * Change virtual leakage voltage to actual value.
2028 * @param hwmgr the address of the powerplay hardware manager.
2029 * @param pointer to changing voltage
2030 * @param pointer to leakage table
2032 static void smu7_patch_ppt_v0_with_vdd_leakage(struct pp_hwmgr *hwmgr,
2033 uint32_t *voltage, struct smu7_leakage_voltage *leakage_table)
2037 /* search for leakage voltage ID 0xff01 ~ 0xff08 */
2038 for (index = 0; index < leakage_table->count; index++) {
2039 /* if this voltage matches a leakage voltage ID */
2040 /* patch with actual leakage voltage */
2041 if (leakage_table->leakage_id[index] == *voltage) {
2042 *voltage = leakage_table->actual_voltage[index];
2047 if (*voltage > ATOM_VIRTUAL_VOLTAGE_ID0)
2048 pr_err("Voltage value looks like a Leakage ID but it's not patched \n");
2052 static int smu7_patch_vddc(struct pp_hwmgr *hwmgr,
2053 struct phm_clock_voltage_dependency_table *tab)
2056 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2059 for (i = 0; i < tab->count; i++)
2060 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2061 &data->vddc_leakage);
2066 static int smu7_patch_vddci(struct pp_hwmgr *hwmgr,
2067 struct phm_clock_voltage_dependency_table *tab)
2070 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2073 for (i = 0; i < tab->count; i++)
2074 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2075 &data->vddci_leakage);
2080 static int smu7_patch_vce_vddc(struct pp_hwmgr *hwmgr,
2081 struct phm_vce_clock_voltage_dependency_table *tab)
2084 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2087 for (i = 0; i < tab->count; i++)
2088 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2089 &data->vddc_leakage);
2095 static int smu7_patch_uvd_vddc(struct pp_hwmgr *hwmgr,
2096 struct phm_uvd_clock_voltage_dependency_table *tab)
2099 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2102 for (i = 0; i < tab->count; i++)
2103 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2104 &data->vddc_leakage);
2109 static int smu7_patch_vddc_shed_limit(struct pp_hwmgr *hwmgr,
2110 struct phm_phase_shedding_limits_table *tab)
2113 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2116 for (i = 0; i < tab->count; i++)
2117 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].Voltage,
2118 &data->vddc_leakage);
2123 static int smu7_patch_samu_vddc(struct pp_hwmgr *hwmgr,
2124 struct phm_samu_clock_voltage_dependency_table *tab)
2127 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2130 for (i = 0; i < tab->count; i++)
2131 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2132 &data->vddc_leakage);
2137 static int smu7_patch_acp_vddc(struct pp_hwmgr *hwmgr,
2138 struct phm_acp_clock_voltage_dependency_table *tab)
2141 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2144 for (i = 0; i < tab->count; i++)
2145 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2146 &data->vddc_leakage);
2151 static int smu7_patch_limits_vddc(struct pp_hwmgr *hwmgr,
2152 struct phm_clock_and_voltage_limits *tab)
2154 uint32_t vddc, vddci;
2155 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2159 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &vddc,
2160 &data->vddc_leakage);
2163 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &vddci,
2164 &data->vddci_leakage);
2171 static int smu7_patch_cac_vddc(struct pp_hwmgr *hwmgr, struct phm_cac_leakage_table *tab)
2175 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2178 for (i = 0; i < tab->count; i++) {
2179 vddc = (uint32_t)(tab->entries[i].Vddc);
2180 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &vddc, &data->vddc_leakage);
2181 tab->entries[i].Vddc = (uint16_t)vddc;
2188 static int smu7_patch_dependency_tables_with_leakage(struct pp_hwmgr *hwmgr)
2192 tmp = smu7_patch_vddc(hwmgr, hwmgr->dyn_state.vddc_dependency_on_sclk);
2196 tmp = smu7_patch_vddc(hwmgr, hwmgr->dyn_state.vddc_dependency_on_mclk);
2200 tmp = smu7_patch_vddc(hwmgr, hwmgr->dyn_state.vddc_dep_on_dal_pwrl);
2204 tmp = smu7_patch_vddci(hwmgr, hwmgr->dyn_state.vddci_dependency_on_mclk);
2208 tmp = smu7_patch_vce_vddc(hwmgr, hwmgr->dyn_state.vce_clock_voltage_dependency_table);
2212 tmp = smu7_patch_uvd_vddc(hwmgr, hwmgr->dyn_state.uvd_clock_voltage_dependency_table);
2216 tmp = smu7_patch_samu_vddc(hwmgr, hwmgr->dyn_state.samu_clock_voltage_dependency_table);
2220 tmp = smu7_patch_acp_vddc(hwmgr, hwmgr->dyn_state.acp_clock_voltage_dependency_table);
2224 tmp = smu7_patch_vddc_shed_limit(hwmgr, hwmgr->dyn_state.vddc_phase_shed_limits_table);
2228 tmp = smu7_patch_limits_vddc(hwmgr, &hwmgr->dyn_state.max_clock_voltage_on_ac);
2232 tmp = smu7_patch_limits_vddc(hwmgr, &hwmgr->dyn_state.max_clock_voltage_on_dc);
2236 tmp = smu7_patch_cac_vddc(hwmgr, hwmgr->dyn_state.cac_leakage_table);
2244 static int smu7_set_private_data_based_on_pptable_v0(struct pp_hwmgr *hwmgr)
2246 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2248 struct phm_clock_voltage_dependency_table *allowed_sclk_vddc_table = hwmgr->dyn_state.vddc_dependency_on_sclk;
2249 struct phm_clock_voltage_dependency_table *allowed_mclk_vddc_table = hwmgr->dyn_state.vddc_dependency_on_mclk;
2250 struct phm_clock_voltage_dependency_table *allowed_mclk_vddci_table = hwmgr->dyn_state.vddci_dependency_on_mclk;
2252 PP_ASSERT_WITH_CODE(allowed_sclk_vddc_table != NULL,
2253 "VDDC dependency on SCLK table is missing. This table is mandatory\n", return -EINVAL);
2254 PP_ASSERT_WITH_CODE(allowed_sclk_vddc_table->count >= 1,
2255 "VDDC dependency on SCLK table has to have is missing. This table is mandatory\n", return -EINVAL);
2257 PP_ASSERT_WITH_CODE(allowed_mclk_vddc_table != NULL,
2258 "VDDC dependency on MCLK table is missing. This table is mandatory\n", return -EINVAL);
2259 PP_ASSERT_WITH_CODE(allowed_mclk_vddc_table->count >= 1,
2260 "VDD dependency on MCLK table has to have is missing. This table is mandatory\n", return -EINVAL);
2262 data->min_vddc_in_pptable = (uint16_t)allowed_sclk_vddc_table->entries[0].v;
2263 data->max_vddc_in_pptable = (uint16_t)allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].v;
2265 hwmgr->dyn_state.max_clock_voltage_on_ac.sclk =
2266 allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].clk;
2267 hwmgr->dyn_state.max_clock_voltage_on_ac.mclk =
2268 allowed_mclk_vddc_table->entries[allowed_mclk_vddc_table->count - 1].clk;
2269 hwmgr->dyn_state.max_clock_voltage_on_ac.vddc =
2270 allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].v;
2272 if (allowed_mclk_vddci_table != NULL && allowed_mclk_vddci_table->count >= 1) {
2273 data->min_vddci_in_pptable = (uint16_t)allowed_mclk_vddci_table->entries[0].v;
2274 data->max_vddci_in_pptable = (uint16_t)allowed_mclk_vddci_table->entries[allowed_mclk_vddci_table->count - 1].v;
2277 if (hwmgr->dyn_state.vddci_dependency_on_mclk != NULL && hwmgr->dyn_state.vddci_dependency_on_mclk->count > 1)
2278 hwmgr->dyn_state.max_clock_voltage_on_ac.vddci = hwmgr->dyn_state.vddci_dependency_on_mclk->entries[hwmgr->dyn_state.vddci_dependency_on_mclk->count - 1].v;
2283 static int smu7_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)
2285 kfree(hwmgr->dyn_state.vddc_dep_on_dal_pwrl);
2286 hwmgr->dyn_state.vddc_dep_on_dal_pwrl = NULL;
2287 kfree(hwmgr->backend);
2288 hwmgr->backend = NULL;
2293 static int smu7_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
2295 struct smu7_hwmgr *data;
2298 data = kzalloc(sizeof(struct smu7_hwmgr), GFP_KERNEL);
2302 hwmgr->backend = data;
2303 smu7_patch_voltage_workaround(hwmgr);
2304 smu7_init_dpm_defaults(hwmgr);
2306 /* Get leakage voltage based on leakage ID. */
2307 result = smu7_get_evv_voltages(hwmgr);
2310 pr_info("Get EVV Voltage Failed. Abort Driver loading!\n");
2314 if (hwmgr->pp_table_version == PP_TABLE_V1) {
2315 smu7_complete_dependency_tables(hwmgr);
2316 smu7_set_private_data_based_on_pptable_v1(hwmgr);
2317 } else if (hwmgr->pp_table_version == PP_TABLE_V0) {
2318 smu7_patch_dependency_tables_with_leakage(hwmgr);
2319 smu7_set_private_data_based_on_pptable_v0(hwmgr);
2322 /* Initalize Dynamic State Adjustment Rule Settings */
2323 result = phm_initializa_dynamic_state_adjustment_rule_settings(hwmgr);
2326 struct cgs_system_info sys_info = {0};
2328 data->is_tlu_enabled = false;
2330 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels =
2331 SMU7_MAX_HARDWARE_POWERLEVELS;
2332 hwmgr->platform_descriptor.hardwarePerformanceLevels = 2;
2333 hwmgr->platform_descriptor.minimumClocksReductionPercentage = 50;
2335 sys_info.size = sizeof(struct cgs_system_info);
2336 sys_info.info_id = CGS_SYSTEM_INFO_PCIE_GEN_INFO;
2337 result = cgs_query_system_info(hwmgr->device, &sys_info);
2339 data->pcie_gen_cap = AMDGPU_DEFAULT_PCIE_GEN_MASK;
2341 data->pcie_gen_cap = (uint32_t)sys_info.value;
2342 if (data->pcie_gen_cap & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)
2343 data->pcie_spc_cap = 20;
2344 sys_info.size = sizeof(struct cgs_system_info);
2345 sys_info.info_id = CGS_SYSTEM_INFO_PCIE_MLW;
2346 result = cgs_query_system_info(hwmgr->device, &sys_info);
2348 data->pcie_lane_cap = AMDGPU_DEFAULT_PCIE_MLW_MASK;
2350 data->pcie_lane_cap = (uint32_t)sys_info.value;
2352 hwmgr->platform_descriptor.vbiosInterruptId = 0x20000400; /* IRQ_SOURCE1_SW_INT */
2353 /* The true clock step depends on the frequency, typically 4.5 or 9 MHz. Here we use 5. */
2354 hwmgr->platform_descriptor.clockStep.engineClock = 500;
2355 hwmgr->platform_descriptor.clockStep.memoryClock = 500;
2356 smu7_thermal_parameter_init(hwmgr);
2358 /* Ignore return value in here, we are cleaning up a mess. */
2359 smu7_hwmgr_backend_fini(hwmgr);
2365 static int smu7_force_dpm_highest(struct pp_hwmgr *hwmgr)
2367 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2368 uint32_t level, tmp;
2370 if (!data->pcie_dpm_key_disabled) {
2371 if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) {
2373 tmp = data->dpm_level_enable_mask.pcie_dpm_enable_mask;
2378 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
2379 PPSMC_MSG_PCIeDPM_ForceLevel, level);
2383 if (!data->sclk_dpm_key_disabled) {
2384 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
2386 tmp = data->dpm_level_enable_mask.sclk_dpm_enable_mask;
2391 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
2392 PPSMC_MSG_SCLKDPM_SetEnabledMask,
2397 if (!data->mclk_dpm_key_disabled) {
2398 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
2400 tmp = data->dpm_level_enable_mask.mclk_dpm_enable_mask;
2405 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
2406 PPSMC_MSG_MCLKDPM_SetEnabledMask,
2414 static int smu7_upload_dpm_level_enable_mask(struct pp_hwmgr *hwmgr)
2416 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2418 if (hwmgr->pp_table_version == PP_TABLE_V1)
2419 phm_apply_dal_min_voltage_request(hwmgr);
2420 /* TO DO for v0 iceland and Ci*/
2422 if (!data->sclk_dpm_key_disabled) {
2423 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask)
2424 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
2425 PPSMC_MSG_SCLKDPM_SetEnabledMask,
2426 data->dpm_level_enable_mask.sclk_dpm_enable_mask);
2429 if (!data->mclk_dpm_key_disabled) {
2430 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask)
2431 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
2432 PPSMC_MSG_MCLKDPM_SetEnabledMask,
2433 data->dpm_level_enable_mask.mclk_dpm_enable_mask);
2439 static int smu7_unforce_dpm_levels(struct pp_hwmgr *hwmgr)
2441 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2443 if (!smum_is_dpm_running(hwmgr))
2446 if (!data->pcie_dpm_key_disabled) {
2447 smum_send_msg_to_smc(hwmgr->smumgr,
2448 PPSMC_MSG_PCIeDPM_UnForceLevel);
2451 return smu7_upload_dpm_level_enable_mask(hwmgr);
2454 static int smu7_force_dpm_lowest(struct pp_hwmgr *hwmgr)
2456 struct smu7_hwmgr *data =
2457 (struct smu7_hwmgr *)(hwmgr->backend);
2460 if (!data->sclk_dpm_key_disabled)
2461 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
2462 level = phm_get_lowest_enabled_level(hwmgr,
2463 data->dpm_level_enable_mask.sclk_dpm_enable_mask);
2464 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
2465 PPSMC_MSG_SCLKDPM_SetEnabledMask,
2470 if (!data->mclk_dpm_key_disabled) {
2471 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
2472 level = phm_get_lowest_enabled_level(hwmgr,
2473 data->dpm_level_enable_mask.mclk_dpm_enable_mask);
2474 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
2475 PPSMC_MSG_MCLKDPM_SetEnabledMask,
2480 if (!data->pcie_dpm_key_disabled) {
2481 if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) {
2482 level = phm_get_lowest_enabled_level(hwmgr,
2483 data->dpm_level_enable_mask.pcie_dpm_enable_mask);
2484 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
2485 PPSMC_MSG_PCIeDPM_ForceLevel,
2493 static int smu7_get_profiling_clk(struct pp_hwmgr *hwmgr, enum amd_dpm_forced_level level,
2494 uint32_t *sclk_mask, uint32_t *mclk_mask, uint32_t *pcie_mask)
2496 uint32_t percentage;
2497 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2498 struct smu7_dpm_table *golden_dpm_table = &data->golden_dpm_table;
2503 if (golden_dpm_table->mclk_table.count < 1)
2506 percentage = 100 * golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count - 1].value /
2507 golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count - 1].value;
2509 if (golden_dpm_table->mclk_table.count == 1) {
2511 tmp_mclk = golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count - 1].value;
2512 *mclk_mask = golden_dpm_table->mclk_table.count - 1;
2514 tmp_mclk = golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count - 2].value;
2515 *mclk_mask = golden_dpm_table->mclk_table.count - 2;
2518 tmp_sclk = tmp_mclk * percentage / 100;
2520 if (hwmgr->pp_table_version == PP_TABLE_V0) {
2521 for (count = hwmgr->dyn_state.vddc_dependency_on_sclk->count-1;
2522 count >= 0; count--) {
2523 if (tmp_sclk >= hwmgr->dyn_state.vddc_dependency_on_sclk->entries[count].clk) {
2524 tmp_sclk = hwmgr->dyn_state.vddc_dependency_on_sclk->entries[count].clk;
2529 if (count < 0 || level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK)
2532 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
2533 *sclk_mask = hwmgr->dyn_state.vddc_dependency_on_sclk->count-1;
2534 } else if (hwmgr->pp_table_version == PP_TABLE_V1) {
2535 struct phm_ppt_v1_information *table_info =
2536 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2538 for (count = table_info->vdd_dep_on_sclk->count-1; count >= 0; count--) {
2539 if (tmp_sclk >= table_info->vdd_dep_on_sclk->entries[count].clk) {
2540 tmp_sclk = table_info->vdd_dep_on_sclk->entries[count].clk;
2545 if (count < 0 || level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK)
2548 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
2549 *sclk_mask = table_info->vdd_dep_on_sclk->count - 1;
2552 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK)
2554 else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
2555 *mclk_mask = golden_dpm_table->mclk_table.count - 1;
2557 *pcie_mask = data->dpm_table.pcie_speed_table.count - 1;
2561 static int smu7_force_dpm_level(struct pp_hwmgr *hwmgr,
2562 enum amd_dpm_forced_level level)
2565 uint32_t sclk_mask = 0;
2566 uint32_t mclk_mask = 0;
2567 uint32_t pcie_mask = 0;
2570 case AMD_DPM_FORCED_LEVEL_HIGH:
2571 ret = smu7_force_dpm_highest(hwmgr);
2573 case AMD_DPM_FORCED_LEVEL_LOW:
2574 ret = smu7_force_dpm_lowest(hwmgr);
2576 case AMD_DPM_FORCED_LEVEL_AUTO:
2577 ret = smu7_unforce_dpm_levels(hwmgr);
2579 case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:
2580 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
2581 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:
2582 case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:
2583 ret = smu7_get_profiling_clk(hwmgr, level, &sclk_mask, &mclk_mask, &pcie_mask);
2586 smu7_force_clock_level(hwmgr, PP_SCLK, 1<<sclk_mask);
2587 smu7_force_clock_level(hwmgr, PP_MCLK, 1<<mclk_mask);
2588 smu7_force_clock_level(hwmgr, PP_PCIE, 1<<pcie_mask);
2590 case AMD_DPM_FORCED_LEVEL_MANUAL:
2591 case AMD_DPM_FORCED_LEVEL_PROFILE_EXIT:
2597 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK && hwmgr->dpm_level != AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
2598 smu7_fan_ctrl_set_fan_speed_percent(hwmgr, 100);
2599 else if (level != AMD_DPM_FORCED_LEVEL_PROFILE_PEAK && hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
2600 smu7_fan_ctrl_reset_fan_speed_to_default(hwmgr);
2605 static int smu7_get_power_state_size(struct pp_hwmgr *hwmgr)
2607 return sizeof(struct smu7_power_state);
2610 static int smu7_vblank_too_short(struct pp_hwmgr *hwmgr,
2611 uint32_t vblank_time_us)
2613 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2614 uint32_t switch_limit_us;
2616 switch (hwmgr->chip_id) {
2617 case CHIP_POLARIS10:
2618 case CHIP_POLARIS11:
2619 case CHIP_POLARIS12:
2620 switch_limit_us = data->is_memory_gddr5 ? 190 : 150;
2623 switch_limit_us = data->is_memory_gddr5 ? 450 : 150;
2627 if (vblank_time_us < switch_limit_us)
2633 static int smu7_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
2634 struct pp_power_state *request_ps,
2635 const struct pp_power_state *current_ps)
2638 struct smu7_power_state *smu7_ps =
2639 cast_phw_smu7_power_state(&request_ps->hardware);
2642 struct PP_Clocks minimum_clocks = {0};
2643 bool disable_mclk_switching;
2644 bool disable_mclk_switching_for_frame_lock;
2645 struct cgs_display_info info = {0};
2646 struct cgs_mode_info mode_info = {0};
2647 const struct phm_clock_and_voltage_limits *max_limits;
2649 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2650 struct phm_ppt_v1_information *table_info =
2651 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2653 int32_t stable_pstate_sclk = 0, stable_pstate_mclk = 0;
2655 info.mode_info = &mode_info;
2656 data->battery_state = (PP_StateUILabel_Battery ==
2657 request_ps->classification.ui_label);
2659 PP_ASSERT_WITH_CODE(smu7_ps->performance_level_count == 2,
2660 "VI should always have 2 performance levels",
2663 max_limits = (PP_PowerSource_AC == hwmgr->power_source) ?
2664 &(hwmgr->dyn_state.max_clock_voltage_on_ac) :
2665 &(hwmgr->dyn_state.max_clock_voltage_on_dc);
2667 /* Cap clock DPM tables at DC MAX if it is in DC. */
2668 if (PP_PowerSource_DC == hwmgr->power_source) {
2669 for (i = 0; i < smu7_ps->performance_level_count; i++) {
2670 if (smu7_ps->performance_levels[i].memory_clock > max_limits->mclk)
2671 smu7_ps->performance_levels[i].memory_clock = max_limits->mclk;
2672 if (smu7_ps->performance_levels[i].engine_clock > max_limits->sclk)
2673 smu7_ps->performance_levels[i].engine_clock = max_limits->sclk;
2677 smu7_ps->vce_clks.evclk = hwmgr->vce_arbiter.evclk;
2678 smu7_ps->vce_clks.ecclk = hwmgr->vce_arbiter.ecclk;
2680 cgs_get_active_displays_info(hwmgr->device, &info);
2682 minimum_clocks.engineClock = hwmgr->display_config.min_core_set_clock;
2683 minimum_clocks.memoryClock = hwmgr->display_config.min_mem_set_clock;
2685 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2686 PHM_PlatformCaps_StablePState)) {
2687 max_limits = &(hwmgr->dyn_state.max_clock_voltage_on_ac);
2688 stable_pstate_sclk = (max_limits->sclk * 75) / 100;
2690 for (count = table_info->vdd_dep_on_sclk->count - 1;
2691 count >= 0; count--) {
2692 if (stable_pstate_sclk >=
2693 table_info->vdd_dep_on_sclk->entries[count].clk) {
2694 stable_pstate_sclk =
2695 table_info->vdd_dep_on_sclk->entries[count].clk;
2701 stable_pstate_sclk = table_info->vdd_dep_on_sclk->entries[0].clk;
2703 stable_pstate_mclk = max_limits->mclk;
2705 minimum_clocks.engineClock = stable_pstate_sclk;
2706 minimum_clocks.memoryClock = stable_pstate_mclk;
2709 if (minimum_clocks.engineClock < hwmgr->gfx_arbiter.sclk)
2710 minimum_clocks.engineClock = hwmgr->gfx_arbiter.sclk;
2712 if (minimum_clocks.memoryClock < hwmgr->gfx_arbiter.mclk)
2713 minimum_clocks.memoryClock = hwmgr->gfx_arbiter.mclk;
2715 smu7_ps->sclk_threshold = hwmgr->gfx_arbiter.sclk_threshold;
2717 if (0 != hwmgr->gfx_arbiter.sclk_over_drive) {
2718 PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.sclk_over_drive <=
2719 hwmgr->platform_descriptor.overdriveLimit.engineClock),
2720 "Overdrive sclk exceeds limit",
2721 hwmgr->gfx_arbiter.sclk_over_drive =
2722 hwmgr->platform_descriptor.overdriveLimit.engineClock);
2724 if (hwmgr->gfx_arbiter.sclk_over_drive >= hwmgr->gfx_arbiter.sclk)
2725 smu7_ps->performance_levels[1].engine_clock =
2726 hwmgr->gfx_arbiter.sclk_over_drive;
2729 if (0 != hwmgr->gfx_arbiter.mclk_over_drive) {
2730 PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.mclk_over_drive <=
2731 hwmgr->platform_descriptor.overdriveLimit.memoryClock),
2732 "Overdrive mclk exceeds limit",
2733 hwmgr->gfx_arbiter.mclk_over_drive =
2734 hwmgr->platform_descriptor.overdriveLimit.memoryClock);
2736 if (hwmgr->gfx_arbiter.mclk_over_drive >= hwmgr->gfx_arbiter.mclk)
2737 smu7_ps->performance_levels[1].memory_clock =
2738 hwmgr->gfx_arbiter.mclk_over_drive;
2741 disable_mclk_switching_for_frame_lock = phm_cap_enabled(
2742 hwmgr->platform_descriptor.platformCaps,
2743 PHM_PlatformCaps_DisableMclkSwitchingForFrameLock);
2746 disable_mclk_switching = ((1 < info.display_count) ||
2747 disable_mclk_switching_for_frame_lock ||
2748 smu7_vblank_too_short(hwmgr, mode_info.vblank_time_us) ||
2749 (mode_info.refresh_rate > 120));
2751 sclk = smu7_ps->performance_levels[0].engine_clock;
2752 mclk = smu7_ps->performance_levels[0].memory_clock;
2754 if (disable_mclk_switching)
2755 mclk = smu7_ps->performance_levels
2756 [smu7_ps->performance_level_count - 1].memory_clock;
2758 if (sclk < minimum_clocks.engineClock)
2759 sclk = (minimum_clocks.engineClock > max_limits->sclk) ?
2760 max_limits->sclk : minimum_clocks.engineClock;
2762 if (mclk < minimum_clocks.memoryClock)
2763 mclk = (minimum_clocks.memoryClock > max_limits->mclk) ?
2764 max_limits->mclk : minimum_clocks.memoryClock;
2766 smu7_ps->performance_levels[0].engine_clock = sclk;
2767 smu7_ps->performance_levels[0].memory_clock = mclk;
2769 smu7_ps->performance_levels[1].engine_clock =
2770 (smu7_ps->performance_levels[1].engine_clock >=
2771 smu7_ps->performance_levels[0].engine_clock) ?
2772 smu7_ps->performance_levels[1].engine_clock :
2773 smu7_ps->performance_levels[0].engine_clock;
2775 if (disable_mclk_switching) {
2776 if (mclk < smu7_ps->performance_levels[1].memory_clock)
2777 mclk = smu7_ps->performance_levels[1].memory_clock;
2779 smu7_ps->performance_levels[0].memory_clock = mclk;
2780 smu7_ps->performance_levels[1].memory_clock = mclk;
2782 if (smu7_ps->performance_levels[1].memory_clock <
2783 smu7_ps->performance_levels[0].memory_clock)
2784 smu7_ps->performance_levels[1].memory_clock =
2785 smu7_ps->performance_levels[0].memory_clock;
2788 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2789 PHM_PlatformCaps_StablePState)) {
2790 for (i = 0; i < smu7_ps->performance_level_count; i++) {
2791 smu7_ps->performance_levels[i].engine_clock = stable_pstate_sclk;
2792 smu7_ps->performance_levels[i].memory_clock = stable_pstate_mclk;
2793 smu7_ps->performance_levels[i].pcie_gen = data->pcie_gen_performance.max;
2794 smu7_ps->performance_levels[i].pcie_lane = data->pcie_gen_performance.max;
2801 static uint32_t smu7_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)
2803 struct pp_power_state *ps;
2804 struct smu7_power_state *smu7_ps;
2809 ps = hwmgr->request_ps;
2814 smu7_ps = cast_phw_smu7_power_state(&ps->hardware);
2817 return smu7_ps->performance_levels[0].memory_clock;
2819 return smu7_ps->performance_levels
2820 [smu7_ps->performance_level_count-1].memory_clock;
2823 static uint32_t smu7_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)
2825 struct pp_power_state *ps;
2826 struct smu7_power_state *smu7_ps;
2831 ps = hwmgr->request_ps;
2836 smu7_ps = cast_phw_smu7_power_state(&ps->hardware);
2839 return smu7_ps->performance_levels[0].engine_clock;
2841 return smu7_ps->performance_levels
2842 [smu7_ps->performance_level_count-1].engine_clock;
2845 static int smu7_dpm_patch_boot_state(struct pp_hwmgr *hwmgr,
2846 struct pp_hw_power_state *hw_ps)
2848 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2849 struct smu7_power_state *ps = (struct smu7_power_state *)hw_ps;
2850 ATOM_FIRMWARE_INFO_V2_2 *fw_info;
2853 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
2855 /* First retrieve the Boot clocks and VDDC from the firmware info table.
2856 * We assume here that fw_info is unchanged if this call fails.
2858 fw_info = (ATOM_FIRMWARE_INFO_V2_2 *)cgs_atom_get_data_table(
2859 hwmgr->device, index,
2860 &size, &frev, &crev);
2862 /* During a test, there is no firmware info table. */
2865 /* Patch the state. */
2866 data->vbios_boot_state.sclk_bootup_value =
2867 le32_to_cpu(fw_info->ulDefaultEngineClock);
2868 data->vbios_boot_state.mclk_bootup_value =
2869 le32_to_cpu(fw_info->ulDefaultMemoryClock);
2870 data->vbios_boot_state.mvdd_bootup_value =
2871 le16_to_cpu(fw_info->usBootUpMVDDCVoltage);
2872 data->vbios_boot_state.vddc_bootup_value =
2873 le16_to_cpu(fw_info->usBootUpVDDCVoltage);
2874 data->vbios_boot_state.vddci_bootup_value =
2875 le16_to_cpu(fw_info->usBootUpVDDCIVoltage);
2876 data->vbios_boot_state.pcie_gen_bootup_value =
2877 smu7_get_current_pcie_speed(hwmgr);
2879 data->vbios_boot_state.pcie_lane_bootup_value =
2880 (uint16_t)smu7_get_current_pcie_lane_number(hwmgr);
2882 /* set boot power state */
2883 ps->performance_levels[0].memory_clock = data->vbios_boot_state.mclk_bootup_value;
2884 ps->performance_levels[0].engine_clock = data->vbios_boot_state.sclk_bootup_value;
2885 ps->performance_levels[0].pcie_gen = data->vbios_boot_state.pcie_gen_bootup_value;
2886 ps->performance_levels[0].pcie_lane = data->vbios_boot_state.pcie_lane_bootup_value;
2891 static int smu7_get_number_of_powerplay_table_entries(struct pp_hwmgr *hwmgr)
2894 unsigned long ret = 0;
2896 if (hwmgr->pp_table_version == PP_TABLE_V0) {
2897 result = pp_tables_get_num_of_entries(hwmgr, &ret);
2898 return result ? 0 : ret;
2899 } else if (hwmgr->pp_table_version == PP_TABLE_V1) {
2900 result = get_number_of_powerplay_table_entries_v1_0(hwmgr);
2906 static int smu7_get_pp_table_entry_callback_func_v1(struct pp_hwmgr *hwmgr,
2907 void *state, struct pp_power_state *power_state,
2908 void *pp_table, uint32_t classification_flag)
2910 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2911 struct smu7_power_state *smu7_power_state =
2912 (struct smu7_power_state *)(&(power_state->hardware));
2913 struct smu7_performance_level *performance_level;
2914 ATOM_Tonga_State *state_entry = (ATOM_Tonga_State *)state;
2915 ATOM_Tonga_POWERPLAYTABLE *powerplay_table =
2916 (ATOM_Tonga_POWERPLAYTABLE *)pp_table;
2917 PPTable_Generic_SubTable_Header *sclk_dep_table =
2918 (PPTable_Generic_SubTable_Header *)
2919 (((unsigned long)powerplay_table) +
2920 le16_to_cpu(powerplay_table->usSclkDependencyTableOffset));
2922 ATOM_Tonga_MCLK_Dependency_Table *mclk_dep_table =
2923 (ATOM_Tonga_MCLK_Dependency_Table *)
2924 (((unsigned long)powerplay_table) +
2925 le16_to_cpu(powerplay_table->usMclkDependencyTableOffset));
2927 /* The following fields are not initialized here: id orderedList allStatesList */
2928 power_state->classification.ui_label =
2929 (le16_to_cpu(state_entry->usClassification) &
2930 ATOM_PPLIB_CLASSIFICATION_UI_MASK) >>
2931 ATOM_PPLIB_CLASSIFICATION_UI_SHIFT;
2932 power_state->classification.flags = classification_flag;
2933 /* NOTE: There is a classification2 flag in BIOS that is not being used right now */
2935 power_state->classification.temporary_state = false;
2936 power_state->classification.to_be_deleted = false;
2938 power_state->validation.disallowOnDC =
2939 (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) &
2940 ATOM_Tonga_DISALLOW_ON_DC));
2942 power_state->pcie.lanes = 0;
2944 power_state->display.disableFrameModulation = false;
2945 power_state->display.limitRefreshrate = false;
2946 power_state->display.enableVariBright =
2947 (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) &
2948 ATOM_Tonga_ENABLE_VARIBRIGHT));
2950 power_state->validation.supportedPowerLevels = 0;
2951 power_state->uvd_clocks.VCLK = 0;
2952 power_state->uvd_clocks.DCLK = 0;
2953 power_state->temperatures.min = 0;
2954 power_state->temperatures.max = 0;
2956 performance_level = &(smu7_power_state->performance_levels
2957 [smu7_power_state->performance_level_count++]);
2959 PP_ASSERT_WITH_CODE(
2960 (smu7_power_state->performance_level_count < smum_get_mac_definition(hwmgr->smumgr, SMU_MAX_LEVELS_GRAPHICS)),
2961 "Performance levels exceeds SMC limit!",
2964 PP_ASSERT_WITH_CODE(
2965 (smu7_power_state->performance_level_count <=
2966 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels),
2967 "Performance levels exceeds Driver limit!",
2970 /* Performance levels are arranged from low to high. */
2971 performance_level->memory_clock = mclk_dep_table->entries
2972 [state_entry->ucMemoryClockIndexLow].ulMclk;
2973 if (sclk_dep_table->ucRevId == 0)
2974 performance_level->engine_clock = ((ATOM_Tonga_SCLK_Dependency_Table *)sclk_dep_table)->entries
2975 [state_entry->ucEngineClockIndexLow].ulSclk;
2976 else if (sclk_dep_table->ucRevId == 1)
2977 performance_level->engine_clock = ((ATOM_Polaris_SCLK_Dependency_Table *)sclk_dep_table)->entries
2978 [state_entry->ucEngineClockIndexLow].ulSclk;
2979 performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap,
2980 state_entry->ucPCIEGenLow);
2981 performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap,
2982 state_entry->ucPCIELaneHigh);
2984 performance_level = &(smu7_power_state->performance_levels
2985 [smu7_power_state->performance_level_count++]);
2986 performance_level->memory_clock = mclk_dep_table->entries
2987 [state_entry->ucMemoryClockIndexHigh].ulMclk;
2989 if (sclk_dep_table->ucRevId == 0)
2990 performance_level->engine_clock = ((ATOM_Tonga_SCLK_Dependency_Table *)sclk_dep_table)->entries
2991 [state_entry->ucEngineClockIndexHigh].ulSclk;
2992 else if (sclk_dep_table->ucRevId == 1)
2993 performance_level->engine_clock = ((ATOM_Polaris_SCLK_Dependency_Table *)sclk_dep_table)->entries
2994 [state_entry->ucEngineClockIndexHigh].ulSclk;
2996 performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap,
2997 state_entry->ucPCIEGenHigh);
2998 performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap,
2999 state_entry->ucPCIELaneHigh);
3004 static int smu7_get_pp_table_entry_v1(struct pp_hwmgr *hwmgr,
3005 unsigned long entry_index, struct pp_power_state *state)
3008 struct smu7_power_state *ps;
3009 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3010 struct phm_ppt_v1_information *table_info =
3011 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3012 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
3013 table_info->vdd_dep_on_mclk;
3015 state->hardware.magic = PHM_VIslands_Magic;
3017 ps = (struct smu7_power_state *)(&state->hardware);
3019 result = get_powerplay_table_entry_v1_0(hwmgr, entry_index, state,
3020 smu7_get_pp_table_entry_callback_func_v1);
3022 /* This is the earliest time we have all the dependency table and the VBIOS boot state
3023 * as PP_Tables_GetPowerPlayTableEntry retrieves the VBIOS boot state
3024 * if there is only one VDDCI/MCLK level, check if it's the same as VBIOS boot state
3026 if (dep_mclk_table != NULL && dep_mclk_table->count == 1) {
3027 if (dep_mclk_table->entries[0].clk !=
3028 data->vbios_boot_state.mclk_bootup_value)
3029 pr_debug("Single MCLK entry VDDCI/MCLK dependency table "
3030 "does not match VBIOS boot MCLK level");
3031 if (dep_mclk_table->entries[0].vddci !=
3032 data->vbios_boot_state.vddci_bootup_value)
3033 pr_debug("Single VDDCI entry VDDCI/MCLK dependency table "
3034 "does not match VBIOS boot VDDCI level");
3037 /* set DC compatible flag if this state supports DC */
3038 if (!state->validation.disallowOnDC)
3039 ps->dc_compatible = true;
3041 if (state->classification.flags & PP_StateClassificationFlag_ACPI)
3042 data->acpi_pcie_gen = ps->performance_levels[0].pcie_gen;
3044 ps->uvd_clks.vclk = state->uvd_clocks.VCLK;
3045 ps->uvd_clks.dclk = state->uvd_clocks.DCLK;
3050 switch (state->classification.ui_label) {
3051 case PP_StateUILabel_Performance:
3052 data->use_pcie_performance_levels = true;
3053 for (i = 0; i < ps->performance_level_count; i++) {
3054 if (data->pcie_gen_performance.max <
3055 ps->performance_levels[i].pcie_gen)
3056 data->pcie_gen_performance.max =
3057 ps->performance_levels[i].pcie_gen;
3059 if (data->pcie_gen_performance.min >
3060 ps->performance_levels[i].pcie_gen)
3061 data->pcie_gen_performance.min =
3062 ps->performance_levels[i].pcie_gen;
3064 if (data->pcie_lane_performance.max <
3065 ps->performance_levels[i].pcie_lane)
3066 data->pcie_lane_performance.max =
3067 ps->performance_levels[i].pcie_lane;
3068 if (data->pcie_lane_performance.min >
3069 ps->performance_levels[i].pcie_lane)
3070 data->pcie_lane_performance.min =
3071 ps->performance_levels[i].pcie_lane;
3074 case PP_StateUILabel_Battery:
3075 data->use_pcie_power_saving_levels = true;
3077 for (i = 0; i < ps->performance_level_count; i++) {
3078 if (data->pcie_gen_power_saving.max <
3079 ps->performance_levels[i].pcie_gen)
3080 data->pcie_gen_power_saving.max =
3081 ps->performance_levels[i].pcie_gen;
3083 if (data->pcie_gen_power_saving.min >
3084 ps->performance_levels[i].pcie_gen)
3085 data->pcie_gen_power_saving.min =
3086 ps->performance_levels[i].pcie_gen;
3088 if (data->pcie_lane_power_saving.max <
3089 ps->performance_levels[i].pcie_lane)
3090 data->pcie_lane_power_saving.max =
3091 ps->performance_levels[i].pcie_lane;
3093 if (data->pcie_lane_power_saving.min >
3094 ps->performance_levels[i].pcie_lane)
3095 data->pcie_lane_power_saving.min =
3096 ps->performance_levels[i].pcie_lane;
3106 static int smu7_get_pp_table_entry_callback_func_v0(struct pp_hwmgr *hwmgr,
3107 struct pp_hw_power_state *power_state,
3108 unsigned int index, const void *clock_info)
3110 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3111 struct smu7_power_state *ps = cast_phw_smu7_power_state(power_state);
3112 const ATOM_PPLIB_CI_CLOCK_INFO *visland_clk_info = clock_info;
3113 struct smu7_performance_level *performance_level;
3114 uint32_t engine_clock, memory_clock;
3115 uint16_t pcie_gen_from_bios;
3117 engine_clock = visland_clk_info->ucEngineClockHigh << 16 | visland_clk_info->usEngineClockLow;
3118 memory_clock = visland_clk_info->ucMemoryClockHigh << 16 | visland_clk_info->usMemoryClockLow;
3120 if (!(data->mc_micro_code_feature & DISABLE_MC_LOADMICROCODE) && memory_clock > data->highest_mclk)
3121 data->highest_mclk = memory_clock;
3123 PP_ASSERT_WITH_CODE(
3124 (ps->performance_level_count < smum_get_mac_definition(hwmgr->smumgr, SMU_MAX_LEVELS_GRAPHICS)),
3125 "Performance levels exceeds SMC limit!",
3128 PP_ASSERT_WITH_CODE(
3129 (ps->performance_level_count <
3130 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels),
3131 "Performance levels exceeds Driver limit, Skip!",
3134 performance_level = &(ps->performance_levels
3135 [ps->performance_level_count++]);
3137 /* Performance levels are arranged from low to high. */
3138 performance_level->memory_clock = memory_clock;
3139 performance_level->engine_clock = engine_clock;
3141 pcie_gen_from_bios = visland_clk_info->ucPCIEGen;
3143 performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap, pcie_gen_from_bios);
3144 performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap, visland_clk_info->usPCIELane);
3149 static int smu7_get_pp_table_entry_v0(struct pp_hwmgr *hwmgr,
3150 unsigned long entry_index, struct pp_power_state *state)
3153 struct smu7_power_state *ps;
3154 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3155 struct phm_clock_voltage_dependency_table *dep_mclk_table =
3156 hwmgr->dyn_state.vddci_dependency_on_mclk;
3158 memset(&state->hardware, 0x00, sizeof(struct pp_hw_power_state));
3160 state->hardware.magic = PHM_VIslands_Magic;
3162 ps = (struct smu7_power_state *)(&state->hardware);
3164 result = pp_tables_get_entry(hwmgr, entry_index, state,
3165 smu7_get_pp_table_entry_callback_func_v0);
3168 * This is the earliest time we have all the dependency table
3169 * and the VBIOS boot state as
3170 * PP_Tables_GetPowerPlayTableEntry retrieves the VBIOS boot
3171 * state if there is only one VDDCI/MCLK level, check if it's
3172 * the same as VBIOS boot state
3174 if (dep_mclk_table != NULL && dep_mclk_table->count == 1) {
3175 if (dep_mclk_table->entries[0].clk !=
3176 data->vbios_boot_state.mclk_bootup_value)
3177 pr_debug("Single MCLK entry VDDCI/MCLK dependency table "
3178 "does not match VBIOS boot MCLK level");
3179 if (dep_mclk_table->entries[0].v !=
3180 data->vbios_boot_state.vddci_bootup_value)
3181 pr_debug("Single VDDCI entry VDDCI/MCLK dependency table "
3182 "does not match VBIOS boot VDDCI level");
3185 /* set DC compatible flag if this state supports DC */
3186 if (!state->validation.disallowOnDC)
3187 ps->dc_compatible = true;
3189 if (state->classification.flags & PP_StateClassificationFlag_ACPI)
3190 data->acpi_pcie_gen = ps->performance_levels[0].pcie_gen;
3192 ps->uvd_clks.vclk = state->uvd_clocks.VCLK;
3193 ps->uvd_clks.dclk = state->uvd_clocks.DCLK;
3198 switch (state->classification.ui_label) {
3199 case PP_StateUILabel_Performance:
3200 data->use_pcie_performance_levels = true;
3202 for (i = 0; i < ps->performance_level_count; i++) {
3203 if (data->pcie_gen_performance.max <
3204 ps->performance_levels[i].pcie_gen)
3205 data->pcie_gen_performance.max =
3206 ps->performance_levels[i].pcie_gen;
3208 if (data->pcie_gen_performance.min >
3209 ps->performance_levels[i].pcie_gen)
3210 data->pcie_gen_performance.min =
3211 ps->performance_levels[i].pcie_gen;
3213 if (data->pcie_lane_performance.max <
3214 ps->performance_levels[i].pcie_lane)
3215 data->pcie_lane_performance.max =
3216 ps->performance_levels[i].pcie_lane;
3218 if (data->pcie_lane_performance.min >
3219 ps->performance_levels[i].pcie_lane)
3220 data->pcie_lane_performance.min =
3221 ps->performance_levels[i].pcie_lane;
3224 case PP_StateUILabel_Battery:
3225 data->use_pcie_power_saving_levels = true;
3227 for (i = 0; i < ps->performance_level_count; i++) {
3228 if (data->pcie_gen_power_saving.max <
3229 ps->performance_levels[i].pcie_gen)
3230 data->pcie_gen_power_saving.max =
3231 ps->performance_levels[i].pcie_gen;
3233 if (data->pcie_gen_power_saving.min >
3234 ps->performance_levels[i].pcie_gen)
3235 data->pcie_gen_power_saving.min =
3236 ps->performance_levels[i].pcie_gen;
3238 if (data->pcie_lane_power_saving.max <
3239 ps->performance_levels[i].pcie_lane)
3240 data->pcie_lane_power_saving.max =
3241 ps->performance_levels[i].pcie_lane;
3243 if (data->pcie_lane_power_saving.min >
3244 ps->performance_levels[i].pcie_lane)
3245 data->pcie_lane_power_saving.min =
3246 ps->performance_levels[i].pcie_lane;
3256 static int smu7_get_pp_table_entry(struct pp_hwmgr *hwmgr,
3257 unsigned long entry_index, struct pp_power_state *state)
3259 if (hwmgr->pp_table_version == PP_TABLE_V0)
3260 return smu7_get_pp_table_entry_v0(hwmgr, entry_index, state);
3261 else if (hwmgr->pp_table_version == PP_TABLE_V1)
3262 return smu7_get_pp_table_entry_v1(hwmgr, entry_index, state);
3267 static int smu7_get_gpu_power(struct pp_hwmgr *hwmgr,
3268 struct pp_gpu_power *query)
3270 PP_ASSERT_WITH_CODE(!smum_send_msg_to_smc(hwmgr->smumgr,
3271 PPSMC_MSG_PmStatusLogStart),
3272 "Failed to start pm status log!",
3275 msleep_interruptible(20);
3277 PP_ASSERT_WITH_CODE(!smum_send_msg_to_smc(hwmgr->smumgr,
3278 PPSMC_MSG_PmStatusLogSample),
3279 "Failed to sample pm status log!",
3282 query->vddc_power = cgs_read_ind_register(hwmgr->device,
3284 ixSMU_PM_STATUS_40);
3285 query->vddci_power = cgs_read_ind_register(hwmgr->device,
3287 ixSMU_PM_STATUS_49);
3288 query->max_gpu_power = cgs_read_ind_register(hwmgr->device,
3290 ixSMU_PM_STATUS_94);
3291 query->average_gpu_power = cgs_read_ind_register(hwmgr->device,
3293 ixSMU_PM_STATUS_95);
3298 static int smu7_read_sensor(struct pp_hwmgr *hwmgr, int idx,
3299 void *value, int *size)
3301 uint32_t sclk, mclk, activity_percent;
3303 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3305 /* size must be at least 4 bytes for all sensors */
3310 case AMDGPU_PP_SENSOR_GFX_SCLK:
3311 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetSclkFrequency);
3312 sclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
3313 *((uint32_t *)value) = sclk;
3316 case AMDGPU_PP_SENSOR_GFX_MCLK:
3317 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetMclkFrequency);
3318 mclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
3319 *((uint32_t *)value) = mclk;
3322 case AMDGPU_PP_SENSOR_GPU_LOAD:
3323 offset = data->soft_regs_start + smum_get_offsetof(hwmgr->smumgr,
3325 AverageGraphicsActivity);
3327 activity_percent = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, offset);
3328 activity_percent += 0x80;
3329 activity_percent >>= 8;
3330 *((uint32_t *)value) = activity_percent > 100 ? 100 : activity_percent;
3333 case AMDGPU_PP_SENSOR_GPU_TEMP:
3334 *((uint32_t *)value) = smu7_thermal_get_temperature(hwmgr);
3337 case AMDGPU_PP_SENSOR_UVD_POWER:
3338 *((uint32_t *)value) = data->uvd_power_gated ? 0 : 1;
3341 case AMDGPU_PP_SENSOR_VCE_POWER:
3342 *((uint32_t *)value) = data->vce_power_gated ? 0 : 1;
3345 case AMDGPU_PP_SENSOR_GPU_POWER:
3346 if (*size < sizeof(struct pp_gpu_power))
3348 *size = sizeof(struct pp_gpu_power);
3349 return smu7_get_gpu_power(hwmgr, (struct pp_gpu_power *)value);
3355 static int smu7_find_dpm_states_clocks_in_dpm_table(struct pp_hwmgr *hwmgr, const void *input)
3357 const struct phm_set_power_state_input *states =
3358 (const struct phm_set_power_state_input *)input;
3359 const struct smu7_power_state *smu7_ps =
3360 cast_const_phw_smu7_power_state(states->pnew_state);
3361 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3362 struct smu7_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
3363 uint32_t sclk = smu7_ps->performance_levels
3364 [smu7_ps->performance_level_count - 1].engine_clock;
3365 struct smu7_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
3366 uint32_t mclk = smu7_ps->performance_levels
3367 [smu7_ps->performance_level_count - 1].memory_clock;
3368 struct PP_Clocks min_clocks = {0};
3370 struct cgs_display_info info = {0};
3372 data->need_update_smu7_dpm_table = 0;
3374 for (i = 0; i < sclk_table->count; i++) {
3375 if (sclk == sclk_table->dpm_levels[i].value)
3379 if (i >= sclk_table->count)
3380 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK;
3382 /* TODO: Check SCLK in DAL's minimum clocks
3383 * in case DeepSleep divider update is required.
3385 if (data->display_timing.min_clock_in_sr != min_clocks.engineClockInSR &&
3386 (min_clocks.engineClockInSR >= SMU7_MINIMUM_ENGINE_CLOCK ||
3387 data->display_timing.min_clock_in_sr >= SMU7_MINIMUM_ENGINE_CLOCK))
3388 data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_SCLK;
3391 for (i = 0; i < mclk_table->count; i++) {
3392 if (mclk == mclk_table->dpm_levels[i].value)
3396 if (i >= mclk_table->count)
3397 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_MCLK;
3399 cgs_get_active_displays_info(hwmgr->device, &info);
3401 if (data->display_timing.num_existing_displays != info.display_count)
3402 data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_MCLK;
3407 static uint16_t smu7_get_maximum_link_speed(struct pp_hwmgr *hwmgr,
3408 const struct smu7_power_state *smu7_ps)
3411 uint32_t sclk, max_sclk = 0;
3412 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3413 struct smu7_dpm_table *dpm_table = &data->dpm_table;
3415 for (i = 0; i < smu7_ps->performance_level_count; i++) {
3416 sclk = smu7_ps->performance_levels[i].engine_clock;
3417 if (max_sclk < sclk)
3421 for (i = 0; i < dpm_table->sclk_table.count; i++) {
3422 if (dpm_table->sclk_table.dpm_levels[i].value == max_sclk)
3423 return (uint16_t) ((i >= dpm_table->pcie_speed_table.count) ?
3424 dpm_table->pcie_speed_table.dpm_levels
3425 [dpm_table->pcie_speed_table.count - 1].value :
3426 dpm_table->pcie_speed_table.dpm_levels[i].value);
3432 static int smu7_request_link_speed_change_before_state_change(
3433 struct pp_hwmgr *hwmgr, const void *input)
3435 const struct phm_set_power_state_input *states =
3436 (const struct phm_set_power_state_input *)input;
3437 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3438 const struct smu7_power_state *smu7_nps =
3439 cast_const_phw_smu7_power_state(states->pnew_state);
3440 const struct smu7_power_state *polaris10_cps =
3441 cast_const_phw_smu7_power_state(states->pcurrent_state);
3443 uint16_t target_link_speed = smu7_get_maximum_link_speed(hwmgr, smu7_nps);
3444 uint16_t current_link_speed;
3446 if (data->force_pcie_gen == PP_PCIEGenInvalid)
3447 current_link_speed = smu7_get_maximum_link_speed(hwmgr, polaris10_cps);
3449 current_link_speed = data->force_pcie_gen;
3451 data->force_pcie_gen = PP_PCIEGenInvalid;
3452 data->pspp_notify_required = false;
3454 if (target_link_speed > current_link_speed) {
3455 switch (target_link_speed) {
3457 if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN3, false))
3459 data->force_pcie_gen = PP_PCIEGen2;
3460 if (current_link_speed == PP_PCIEGen2)
3463 if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN2, false))
3466 data->force_pcie_gen = smu7_get_current_pcie_speed(hwmgr);
3470 if (target_link_speed < current_link_speed)
3471 data->pspp_notify_required = true;
3477 static int smu7_freeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
3479 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3481 if (0 == data->need_update_smu7_dpm_table)
3484 if ((0 == data->sclk_dpm_key_disabled) &&
3485 (data->need_update_smu7_dpm_table &
3486 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
3487 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
3488 "Trying to freeze SCLK DPM when DPM is disabled",
3490 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
3491 PPSMC_MSG_SCLKDPM_FreezeLevel),
3492 "Failed to freeze SCLK DPM during FreezeSclkMclkDPM Function!",
3496 if ((0 == data->mclk_dpm_key_disabled) &&
3497 (data->need_update_smu7_dpm_table &
3498 DPMTABLE_OD_UPDATE_MCLK)) {
3499 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
3500 "Trying to freeze MCLK DPM when DPM is disabled",
3502 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
3503 PPSMC_MSG_MCLKDPM_FreezeLevel),
3504 "Failed to freeze MCLK DPM during FreezeSclkMclkDPM Function!",
3511 static int smu7_populate_and_upload_sclk_mclk_dpm_levels(
3512 struct pp_hwmgr *hwmgr, const void *input)
3515 const struct phm_set_power_state_input *states =
3516 (const struct phm_set_power_state_input *)input;
3517 const struct smu7_power_state *smu7_ps =
3518 cast_const_phw_smu7_power_state(states->pnew_state);
3519 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3520 uint32_t sclk = smu7_ps->performance_levels
3521 [smu7_ps->performance_level_count - 1].engine_clock;
3522 uint32_t mclk = smu7_ps->performance_levels
3523 [smu7_ps->performance_level_count - 1].memory_clock;
3524 struct smu7_dpm_table *dpm_table = &data->dpm_table;
3526 struct smu7_dpm_table *golden_dpm_table = &data->golden_dpm_table;
3527 uint32_t dpm_count, clock_percent;
3530 if (0 == data->need_update_smu7_dpm_table)
3533 if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_SCLK) {
3534 dpm_table->sclk_table.dpm_levels
3535 [dpm_table->sclk_table.count - 1].value = sclk;
3537 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinACSupport) ||
3538 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinDCSupport)) {
3539 /* Need to do calculation based on the golden DPM table
3540 * as the Heatmap GPU Clock axis is also based on the default values
3542 PP_ASSERT_WITH_CODE(
3543 (golden_dpm_table->sclk_table.dpm_levels
3544 [golden_dpm_table->sclk_table.count - 1].value != 0),
3547 dpm_count = dpm_table->sclk_table.count < 2 ? 0 : dpm_table->sclk_table.count - 2;
3549 for (i = dpm_count; i > 1; i--) {
3550 if (sclk > golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value) {
3553 - golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value
3555 / golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value;
3557 dpm_table->sclk_table.dpm_levels[i].value =
3558 golden_dpm_table->sclk_table.dpm_levels[i].value +
3559 (golden_dpm_table->sclk_table.dpm_levels[i].value *
3562 } else if (golden_dpm_table->sclk_table.dpm_levels[dpm_table->sclk_table.count-1].value > sclk) {
3564 ((golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count - 1].value
3566 / golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value;
3568 dpm_table->sclk_table.dpm_levels[i].value =
3569 golden_dpm_table->sclk_table.dpm_levels[i].value -
3570 (golden_dpm_table->sclk_table.dpm_levels[i].value *
3571 clock_percent) / 100;
3573 dpm_table->sclk_table.dpm_levels[i].value =
3574 golden_dpm_table->sclk_table.dpm_levels[i].value;
3579 if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK) {
3580 dpm_table->mclk_table.dpm_levels
3581 [dpm_table->mclk_table.count - 1].value = mclk;
3583 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinACSupport) ||
3584 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinDCSupport)) {
3586 PP_ASSERT_WITH_CODE(
3587 (golden_dpm_table->mclk_table.dpm_levels
3588 [golden_dpm_table->mclk_table.count-1].value != 0),
3591 dpm_count = dpm_table->mclk_table.count < 2 ? 0 : dpm_table->mclk_table.count - 2;
3592 for (i = dpm_count; i > 1; i--) {
3593 if (golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value < mclk) {
3594 clock_percent = ((mclk -
3595 golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value) * 100)
3596 / golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value;
3598 dpm_table->mclk_table.dpm_levels[i].value =
3599 golden_dpm_table->mclk_table.dpm_levels[i].value +
3600 (golden_dpm_table->mclk_table.dpm_levels[i].value *
3601 clock_percent) / 100;
3603 } else if (golden_dpm_table->mclk_table.dpm_levels[dpm_table->mclk_table.count-1].value > mclk) {
3605 (golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value - mclk)
3607 / golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value;
3609 dpm_table->mclk_table.dpm_levels[i].value =
3610 golden_dpm_table->mclk_table.dpm_levels[i].value -
3611 (golden_dpm_table->mclk_table.dpm_levels[i].value *
3612 clock_percent) / 100;
3614 dpm_table->mclk_table.dpm_levels[i].value =
3615 golden_dpm_table->mclk_table.dpm_levels[i].value;
3620 if (data->need_update_smu7_dpm_table &
3621 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK)) {
3622 result = smum_populate_all_graphic_levels(hwmgr);
3623 PP_ASSERT_WITH_CODE((0 == result),
3624 "Failed to populate SCLK during PopulateNewDPMClocksStates Function!",
3628 if (data->need_update_smu7_dpm_table &
3629 (DPMTABLE_OD_UPDATE_MCLK + DPMTABLE_UPDATE_MCLK)) {
3630 /*populate MCLK dpm table to SMU7 */
3631 result = smum_populate_all_memory_levels(hwmgr);
3632 PP_ASSERT_WITH_CODE((0 == result),
3633 "Failed to populate MCLK during PopulateNewDPMClocksStates Function!",
3640 static int smu7_trim_single_dpm_states(struct pp_hwmgr *hwmgr,
3641 struct smu7_single_dpm_table *dpm_table,
3642 uint32_t low_limit, uint32_t high_limit)
3646 for (i = 0; i < dpm_table->count; i++) {
3647 if ((dpm_table->dpm_levels[i].value < low_limit)
3648 || (dpm_table->dpm_levels[i].value > high_limit))
3649 dpm_table->dpm_levels[i].enabled = false;
3651 dpm_table->dpm_levels[i].enabled = true;
3657 static int smu7_trim_dpm_states(struct pp_hwmgr *hwmgr,
3658 const struct smu7_power_state *smu7_ps)
3660 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3661 uint32_t high_limit_count;
3663 PP_ASSERT_WITH_CODE((smu7_ps->performance_level_count >= 1),
3664 "power state did not have any performance level",
3667 high_limit_count = (1 == smu7_ps->performance_level_count) ? 0 : 1;
3669 smu7_trim_single_dpm_states(hwmgr,
3670 &(data->dpm_table.sclk_table),
3671 smu7_ps->performance_levels[0].engine_clock,
3672 smu7_ps->performance_levels[high_limit_count].engine_clock);
3674 smu7_trim_single_dpm_states(hwmgr,
3675 &(data->dpm_table.mclk_table),
3676 smu7_ps->performance_levels[0].memory_clock,
3677 smu7_ps->performance_levels[high_limit_count].memory_clock);
3682 static int smu7_generate_dpm_level_enable_mask(
3683 struct pp_hwmgr *hwmgr, const void *input)
3686 const struct phm_set_power_state_input *states =
3687 (const struct phm_set_power_state_input *)input;
3688 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3689 const struct smu7_power_state *smu7_ps =
3690 cast_const_phw_smu7_power_state(states->pnew_state);
3692 result = smu7_trim_dpm_states(hwmgr, smu7_ps);
3696 data->dpm_level_enable_mask.sclk_dpm_enable_mask =
3697 phm_get_dpm_level_enable_mask_value(&data->dpm_table.sclk_table);
3698 data->dpm_level_enable_mask.mclk_dpm_enable_mask =
3699 phm_get_dpm_level_enable_mask_value(&data->dpm_table.mclk_table);
3700 data->dpm_level_enable_mask.pcie_dpm_enable_mask =
3701 phm_get_dpm_level_enable_mask_value(&data->dpm_table.pcie_speed_table);
3706 static int smu7_unfreeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
3708 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3710 if (0 == data->need_update_smu7_dpm_table)
3713 if ((0 == data->sclk_dpm_key_disabled) &&
3714 (data->need_update_smu7_dpm_table &
3715 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
3717 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
3718 "Trying to Unfreeze SCLK DPM when DPM is disabled",
3720 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
3721 PPSMC_MSG_SCLKDPM_UnfreezeLevel),
3722 "Failed to unfreeze SCLK DPM during UnFreezeSclkMclkDPM Function!",
3726 if ((0 == data->mclk_dpm_key_disabled) &&
3727 (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) {
3729 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
3730 "Trying to Unfreeze MCLK DPM when DPM is disabled",
3732 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
3733 PPSMC_MSG_SCLKDPM_UnfreezeLevel),
3734 "Failed to unfreeze MCLK DPM during UnFreezeSclkMclkDPM Function!",
3738 data->need_update_smu7_dpm_table = 0;
3743 static int smu7_notify_link_speed_change_after_state_change(
3744 struct pp_hwmgr *hwmgr, const void *input)
3746 const struct phm_set_power_state_input *states =
3747 (const struct phm_set_power_state_input *)input;
3748 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3749 const struct smu7_power_state *smu7_ps =
3750 cast_const_phw_smu7_power_state(states->pnew_state);
3751 uint16_t target_link_speed = smu7_get_maximum_link_speed(hwmgr, smu7_ps);
3754 if (data->pspp_notify_required) {
3755 if (target_link_speed == PP_PCIEGen3)
3756 request = PCIE_PERF_REQ_GEN3;
3757 else if (target_link_speed == PP_PCIEGen2)
3758 request = PCIE_PERF_REQ_GEN2;
3760 request = PCIE_PERF_REQ_GEN1;
3762 if (request == PCIE_PERF_REQ_GEN1 &&
3763 smu7_get_current_pcie_speed(hwmgr) > 0)
3766 if (acpi_pcie_perf_request(hwmgr->device, request, false)) {
3767 if (PP_PCIEGen2 == target_link_speed)
3768 pr_info("PSPP request to switch to Gen2 from Gen3 Failed!");
3770 pr_info("PSPP request to switch to Gen1 from Gen2 Failed!");
3777 static int smu7_notify_smc_display(struct pp_hwmgr *hwmgr)
3779 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3781 if (hwmgr->feature_mask & PP_VBI_TIME_SUPPORT_MASK)
3782 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3783 (PPSMC_Msg)PPSMC_MSG_SetVBITimeout, data->frame_time_x2);
3784 return (smum_send_msg_to_smc(hwmgr->smumgr, (PPSMC_Msg)PPSMC_HasDisplay) == 0) ? 0 : -EINVAL;
3787 static int smu7_set_power_state_tasks(struct pp_hwmgr *hwmgr, const void *input)
3789 int tmp_result, result = 0;
3790 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3792 tmp_result = smu7_find_dpm_states_clocks_in_dpm_table(hwmgr, input);
3793 PP_ASSERT_WITH_CODE((0 == tmp_result),
3794 "Failed to find DPM states clocks in DPM table!",
3795 result = tmp_result);
3797 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3798 PHM_PlatformCaps_PCIEPerformanceRequest)) {
3800 smu7_request_link_speed_change_before_state_change(hwmgr, input);
3801 PP_ASSERT_WITH_CODE((0 == tmp_result),
3802 "Failed to request link speed change before state change!",
3803 result = tmp_result);
3806 tmp_result = smu7_freeze_sclk_mclk_dpm(hwmgr);
3807 PP_ASSERT_WITH_CODE((0 == tmp_result),
3808 "Failed to freeze SCLK MCLK DPM!", result = tmp_result);
3810 tmp_result = smu7_populate_and_upload_sclk_mclk_dpm_levels(hwmgr, input);
3811 PP_ASSERT_WITH_CODE((0 == tmp_result),
3812 "Failed to populate and upload SCLK MCLK DPM levels!",
3813 result = tmp_result);
3815 tmp_result = smu7_generate_dpm_level_enable_mask(hwmgr, input);
3816 PP_ASSERT_WITH_CODE((0 == tmp_result),
3817 "Failed to generate DPM level enabled mask!",
3818 result = tmp_result);
3820 tmp_result = smum_update_sclk_threshold(hwmgr);
3821 PP_ASSERT_WITH_CODE((0 == tmp_result),
3822 "Failed to update SCLK threshold!",
3823 result = tmp_result);
3825 tmp_result = smu7_notify_smc_display(hwmgr);
3826 PP_ASSERT_WITH_CODE((0 == tmp_result),
3827 "Failed to notify smc display settings!",
3828 result = tmp_result);
3830 tmp_result = smu7_unfreeze_sclk_mclk_dpm(hwmgr);
3831 PP_ASSERT_WITH_CODE((0 == tmp_result),
3832 "Failed to unfreeze SCLK MCLK DPM!",
3833 result = tmp_result);
3835 tmp_result = smu7_upload_dpm_level_enable_mask(hwmgr);
3836 PP_ASSERT_WITH_CODE((0 == tmp_result),
3837 "Failed to upload DPM level enabled mask!",
3838 result = tmp_result);
3840 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3841 PHM_PlatformCaps_PCIEPerformanceRequest)) {
3843 smu7_notify_link_speed_change_after_state_change(hwmgr, input);
3844 PP_ASSERT_WITH_CODE((0 == tmp_result),
3845 "Failed to notify link speed change after state change!",
3846 result = tmp_result);
3848 data->apply_optimized_settings = false;
3852 static int smu7_set_max_fan_pwm_output(struct pp_hwmgr *hwmgr, uint16_t us_max_fan_pwm)
3854 hwmgr->thermal_controller.
3855 advanceFanControlParameters.usMaxFanPWM = us_max_fan_pwm;
3857 return smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3858 PPSMC_MSG_SetFanPwmMax, us_max_fan_pwm);
3862 smu7_notify_smc_display_change(struct pp_hwmgr *hwmgr, bool has_display)
3864 PPSMC_Msg msg = has_display ? (PPSMC_Msg)PPSMC_HasDisplay : (PPSMC_Msg)PPSMC_NoDisplay;
3866 return (smum_send_msg_to_smc(hwmgr->smumgr, msg) == 0) ? 0 : -1;
3870 smu7_notify_smc_display_config_after_ps_adjustment(struct pp_hwmgr *hwmgr)
3872 uint32_t num_active_displays = 0;
3873 struct cgs_display_info info = {0};
3875 info.mode_info = NULL;
3876 cgs_get_active_displays_info(hwmgr->device, &info);
3878 num_active_displays = info.display_count;
3880 if (num_active_displays > 1 && hwmgr->display_config.multi_monitor_in_sync != true)
3881 smu7_notify_smc_display_change(hwmgr, false);
3887 * Programs the display gap
3889 * @param hwmgr the address of the powerplay hardware manager.
3892 static int smu7_program_display_gap(struct pp_hwmgr *hwmgr)
3894 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3895 uint32_t num_active_displays = 0;
3896 uint32_t display_gap = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL);
3897 uint32_t display_gap2;
3898 uint32_t pre_vbi_time_in_us;
3899 uint32_t frame_time_in_us;
3901 uint32_t refresh_rate = 0;
3902 struct cgs_display_info info = {0};
3903 struct cgs_mode_info mode_info;
3905 info.mode_info = &mode_info;
3907 cgs_get_active_displays_info(hwmgr->device, &info);
3908 num_active_displays = info.display_count;
3910 display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL, DISP_GAP, (num_active_displays > 0) ? DISPLAY_GAP_VBLANK_OR_WM : DISPLAY_GAP_IGNORE);
3911 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL, display_gap);
3913 ref_clock = mode_info.ref_clock;
3914 refresh_rate = mode_info.refresh_rate;
3916 if (0 == refresh_rate)
3919 frame_time_in_us = 1000000 / refresh_rate;
3921 pre_vbi_time_in_us = frame_time_in_us - 200 - mode_info.vblank_time_us;
3922 data->frame_time_x2 = frame_time_in_us * 2 / 100;
3924 display_gap2 = pre_vbi_time_in_us * (ref_clock / 100);
3926 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL2, display_gap2);
3928 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3929 data->soft_regs_start + smum_get_offsetof(hwmgr->smumgr,
3931 PreVBlankGap), 0x64);
3933 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3934 data->soft_regs_start + smum_get_offsetof(hwmgr->smumgr,
3937 (frame_time_in_us - pre_vbi_time_in_us));
3942 static int smu7_display_configuration_changed_task(struct pp_hwmgr *hwmgr)
3944 return smu7_program_display_gap(hwmgr);
3948 * Set maximum target operating fan output RPM
3950 * @param hwmgr: the address of the powerplay hardware manager.
3951 * @param usMaxFanRpm: max operating fan RPM value.
3952 * @return The response that came from the SMC.
3954 static int smu7_set_max_fan_rpm_output(struct pp_hwmgr *hwmgr, uint16_t us_max_fan_rpm)
3956 hwmgr->thermal_controller.
3957 advanceFanControlParameters.usMaxFanRPM = us_max_fan_rpm;
3959 return smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3960 PPSMC_MSG_SetFanRpmMax, us_max_fan_rpm);
3963 static int smu7_register_internal_thermal_interrupt(struct pp_hwmgr *hwmgr,
3964 const void *thermal_interrupt_info)
3970 smu7_check_smc_update_required_for_display_configuration(struct pp_hwmgr *hwmgr)
3972 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3973 bool is_update_required = false;
3974 struct cgs_display_info info = {0, 0, NULL};
3976 cgs_get_active_displays_info(hwmgr->device, &info);
3978 if (data->display_timing.num_existing_displays != info.display_count)
3979 is_update_required = true;
3981 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep)) {
3982 if (data->display_timing.min_clock_in_sr != hwmgr->display_config.min_core_set_clock_in_sr &&
3983 (data->display_timing.min_clock_in_sr >= SMU7_MINIMUM_ENGINE_CLOCK ||
3984 hwmgr->display_config.min_core_set_clock_in_sr >= SMU7_MINIMUM_ENGINE_CLOCK))
3985 is_update_required = true;
3987 return is_update_required;
3990 static inline bool smu7_are_power_levels_equal(const struct smu7_performance_level *pl1,
3991 const struct smu7_performance_level *pl2)
3993 return ((pl1->memory_clock == pl2->memory_clock) &&
3994 (pl1->engine_clock == pl2->engine_clock) &&
3995 (pl1->pcie_gen == pl2->pcie_gen) &&
3996 (pl1->pcie_lane == pl2->pcie_lane));
3999 static int smu7_check_states_equal(struct pp_hwmgr *hwmgr,
4000 const struct pp_hw_power_state *pstate1,
4001 const struct pp_hw_power_state *pstate2, bool *equal)
4003 const struct smu7_power_state *psa;
4004 const struct smu7_power_state *psb;
4007 if (pstate1 == NULL || pstate2 == NULL || equal == NULL)
4010 psa = cast_const_phw_smu7_power_state(pstate1);
4011 psb = cast_const_phw_smu7_power_state(pstate2);
4012 /* If the two states don't even have the same number of performance levels they cannot be the same state. */
4013 if (psa->performance_level_count != psb->performance_level_count) {
4018 for (i = 0; i < psa->performance_level_count; i++) {
4019 if (!smu7_are_power_levels_equal(&(psa->performance_levels[i]), &(psb->performance_levels[i]))) {
4020 /* If we have found even one performance level pair that is different the states are different. */
4026 /* If all performance levels are the same try to use the UVD clocks to break the tie.*/
4027 *equal = ((psa->uvd_clks.vclk == psb->uvd_clks.vclk) && (psa->uvd_clks.dclk == psb->uvd_clks.dclk));
4028 *equal &= ((psa->vce_clks.evclk == psb->vce_clks.evclk) && (psa->vce_clks.ecclk == psb->vce_clks.ecclk));
4029 *equal &= (psa->sclk_threshold == psb->sclk_threshold);
4034 static int smu7_upload_mc_firmware(struct pp_hwmgr *hwmgr)
4036 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4038 uint32_t vbios_version;
4041 /* Read MC indirect register offset 0x9F bits [3:0] to see
4042 * if VBIOS has already loaded a full version of MC ucode
4046 smu7_get_mc_microcode_version(hwmgr);
4047 vbios_version = hwmgr->microcode_version_info.MC & 0xf;
4049 data->need_long_memory_training = false;
4051 cgs_write_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_INDEX,
4052 ixMC_IO_DEBUG_UP_13);
4053 tmp = cgs_read_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_DATA);
4055 if (tmp & (1 << 23)) {
4056 data->mem_latency_high = MEM_LATENCY_HIGH;
4057 data->mem_latency_low = MEM_LATENCY_LOW;
4059 data->mem_latency_high = 330;
4060 data->mem_latency_low = 330;
4066 static int smu7_read_clock_registers(struct pp_hwmgr *hwmgr)
4068 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4070 data->clock_registers.vCG_SPLL_FUNC_CNTL =
4071 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL);
4072 data->clock_registers.vCG_SPLL_FUNC_CNTL_2 =
4073 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_2);
4074 data->clock_registers.vCG_SPLL_FUNC_CNTL_3 =
4075 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_3);
4076 data->clock_registers.vCG_SPLL_FUNC_CNTL_4 =
4077 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_4);
4078 data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM =
4079 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_SPREAD_SPECTRUM);
4080 data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2 =
4081 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_SPREAD_SPECTRUM_2);
4082 data->clock_registers.vDLL_CNTL =
4083 cgs_read_register(hwmgr->device, mmDLL_CNTL);
4084 data->clock_registers.vMCLK_PWRMGT_CNTL =
4085 cgs_read_register(hwmgr->device, mmMCLK_PWRMGT_CNTL);
4086 data->clock_registers.vMPLL_AD_FUNC_CNTL =
4087 cgs_read_register(hwmgr->device, mmMPLL_AD_FUNC_CNTL);
4088 data->clock_registers.vMPLL_DQ_FUNC_CNTL =
4089 cgs_read_register(hwmgr->device, mmMPLL_DQ_FUNC_CNTL);
4090 data->clock_registers.vMPLL_FUNC_CNTL =
4091 cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL);
4092 data->clock_registers.vMPLL_FUNC_CNTL_1 =
4093 cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL_1);
4094 data->clock_registers.vMPLL_FUNC_CNTL_2 =
4095 cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL_2);
4096 data->clock_registers.vMPLL_SS1 =
4097 cgs_read_register(hwmgr->device, mmMPLL_SS1);
4098 data->clock_registers.vMPLL_SS2 =
4099 cgs_read_register(hwmgr->device, mmMPLL_SS2);
4105 * Find out if memory is GDDR5.
4107 * @param hwmgr the address of the powerplay hardware manager.
4110 static int smu7_get_memory_type(struct pp_hwmgr *hwmgr)
4112 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4115 temp = cgs_read_register(hwmgr->device, mmMC_SEQ_MISC0);
4117 data->is_memory_gddr5 = (MC_SEQ_MISC0_GDDR5_VALUE ==
4118 ((temp & MC_SEQ_MISC0_GDDR5_MASK) >>
4119 MC_SEQ_MISC0_GDDR5_SHIFT));
4125 * Enables Dynamic Power Management by SMC
4127 * @param hwmgr the address of the powerplay hardware manager.
4130 static int smu7_enable_acpi_power_management(struct pp_hwmgr *hwmgr)
4132 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
4133 GENERAL_PWRMGT, STATIC_PM_EN, 1);
4139 * Initialize PowerGating States for different engines
4141 * @param hwmgr the address of the powerplay hardware manager.
4144 static int smu7_init_power_gate_state(struct pp_hwmgr *hwmgr)
4146 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4148 data->uvd_power_gated = false;
4149 data->vce_power_gated = false;
4150 data->samu_power_gated = false;
4155 static int smu7_init_sclk_threshold(struct pp_hwmgr *hwmgr)
4157 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4159 data->low_sclk_interrupt_threshold = 0;
4163 static int smu7_setup_asic_task(struct pp_hwmgr *hwmgr)
4165 int tmp_result, result = 0;
4167 smu7_upload_mc_firmware(hwmgr);
4169 tmp_result = smu7_read_clock_registers(hwmgr);
4170 PP_ASSERT_WITH_CODE((0 == tmp_result),
4171 "Failed to read clock registers!", result = tmp_result);
4173 tmp_result = smu7_get_memory_type(hwmgr);
4174 PP_ASSERT_WITH_CODE((0 == tmp_result),
4175 "Failed to get memory type!", result = tmp_result);
4177 tmp_result = smu7_enable_acpi_power_management(hwmgr);
4178 PP_ASSERT_WITH_CODE((0 == tmp_result),
4179 "Failed to enable ACPI power management!", result = tmp_result);
4181 tmp_result = smu7_init_power_gate_state(hwmgr);
4182 PP_ASSERT_WITH_CODE((0 == tmp_result),
4183 "Failed to init power gate state!", result = tmp_result);
4185 tmp_result = smu7_get_mc_microcode_version(hwmgr);
4186 PP_ASSERT_WITH_CODE((0 == tmp_result),
4187 "Failed to get MC microcode version!", result = tmp_result);
4189 tmp_result = smu7_init_sclk_threshold(hwmgr);
4190 PP_ASSERT_WITH_CODE((0 == tmp_result),
4191 "Failed to init sclk threshold!", result = tmp_result);
4196 static int smu7_force_clock_level(struct pp_hwmgr *hwmgr,
4197 enum pp_clock_type type, uint32_t mask)
4199 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4201 if (hwmgr->request_dpm_level & (AMD_DPM_FORCED_LEVEL_AUTO |
4202 AMD_DPM_FORCED_LEVEL_LOW |
4203 AMD_DPM_FORCED_LEVEL_HIGH))
4208 if (!data->sclk_dpm_key_disabled)
4209 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4210 PPSMC_MSG_SCLKDPM_SetEnabledMask,
4211 data->dpm_level_enable_mask.sclk_dpm_enable_mask & mask);
4214 if (!data->mclk_dpm_key_disabled)
4215 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4216 PPSMC_MSG_MCLKDPM_SetEnabledMask,
4217 data->dpm_level_enable_mask.mclk_dpm_enable_mask & mask);
4221 uint32_t tmp = mask & data->dpm_level_enable_mask.pcie_dpm_enable_mask;
4227 if (!data->pcie_dpm_key_disabled)
4228 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4229 PPSMC_MSG_PCIeDPM_ForceLevel,
4240 static int smu7_print_clock_levels(struct pp_hwmgr *hwmgr,
4241 enum pp_clock_type type, char *buf)
4243 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4244 struct smu7_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
4245 struct smu7_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
4246 struct smu7_single_dpm_table *pcie_table = &(data->dpm_table.pcie_speed_table);
4247 int i, now, size = 0;
4248 uint32_t clock, pcie_speed;
4252 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetSclkFrequency);
4253 clock = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
4255 for (i = 0; i < sclk_table->count; i++) {
4256 if (clock > sclk_table->dpm_levels[i].value)
4262 for (i = 0; i < sclk_table->count; i++)
4263 size += sprintf(buf + size, "%d: %uMhz %s\n",
4264 i, sclk_table->dpm_levels[i].value / 100,
4265 (i == now) ? "*" : "");
4268 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetMclkFrequency);
4269 clock = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
4271 for (i = 0; i < mclk_table->count; i++) {
4272 if (clock > mclk_table->dpm_levels[i].value)
4278 for (i = 0; i < mclk_table->count; i++)
4279 size += sprintf(buf + size, "%d: %uMhz %s\n",
4280 i, mclk_table->dpm_levels[i].value / 100,
4281 (i == now) ? "*" : "");
4284 pcie_speed = smu7_get_current_pcie_speed(hwmgr);
4285 for (i = 0; i < pcie_table->count; i++) {
4286 if (pcie_speed != pcie_table->dpm_levels[i].value)
4292 for (i = 0; i < pcie_table->count; i++)
4293 size += sprintf(buf + size, "%d: %s %s\n", i,
4294 (pcie_table->dpm_levels[i].value == 0) ? "2.5GB, x8" :
4295 (pcie_table->dpm_levels[i].value == 1) ? "5.0GB, x16" :
4296 (pcie_table->dpm_levels[i].value == 2) ? "8.0GB, x16" : "",
4297 (i == now) ? "*" : "");
4305 static void smu7_set_fan_control_mode(struct pp_hwmgr *hwmgr, uint32_t mode)
4308 case AMD_FAN_CTRL_NONE:
4309 smu7_fan_ctrl_set_fan_speed_percent(hwmgr, 100);
4311 case AMD_FAN_CTRL_MANUAL:
4312 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4313 PHM_PlatformCaps_MicrocodeFanControl))
4314 smu7_fan_ctrl_stop_smc_fan_control(hwmgr);
4316 case AMD_FAN_CTRL_AUTO:
4317 if (!smu7_fan_ctrl_set_static_mode(hwmgr, mode))
4318 smu7_fan_ctrl_start_smc_fan_control(hwmgr);
4325 static uint32_t smu7_get_fan_control_mode(struct pp_hwmgr *hwmgr)
4327 return hwmgr->fan_ctrl_enabled ? AMD_FAN_CTRL_AUTO : AMD_FAN_CTRL_MANUAL;
4330 static int smu7_get_sclk_od(struct pp_hwmgr *hwmgr)
4332 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4333 struct smu7_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
4334 struct smu7_single_dpm_table *golden_sclk_table =
4335 &(data->golden_dpm_table.sclk_table);
4338 value = (sclk_table->dpm_levels[sclk_table->count - 1].value -
4339 golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value) *
4341 golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value;
4346 static int smu7_set_sclk_od(struct pp_hwmgr *hwmgr, uint32_t value)
4348 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4349 struct smu7_single_dpm_table *golden_sclk_table =
4350 &(data->golden_dpm_table.sclk_table);
4351 struct pp_power_state *ps;
4352 struct smu7_power_state *smu7_ps;
4357 ps = hwmgr->request_ps;
4362 smu7_ps = cast_phw_smu7_power_state(&ps->hardware);
4364 smu7_ps->performance_levels[smu7_ps->performance_level_count - 1].engine_clock =
4365 golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value *
4367 golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value;
4372 static int smu7_get_mclk_od(struct pp_hwmgr *hwmgr)
4374 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4375 struct smu7_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
4376 struct smu7_single_dpm_table *golden_mclk_table =
4377 &(data->golden_dpm_table.mclk_table);
4380 value = (mclk_table->dpm_levels[mclk_table->count - 1].value -
4381 golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value) *
4383 golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value;
4388 static int smu7_set_mclk_od(struct pp_hwmgr *hwmgr, uint32_t value)
4390 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4391 struct smu7_single_dpm_table *golden_mclk_table =
4392 &(data->golden_dpm_table.mclk_table);
4393 struct pp_power_state *ps;
4394 struct smu7_power_state *smu7_ps;
4399 ps = hwmgr->request_ps;
4404 smu7_ps = cast_phw_smu7_power_state(&ps->hardware);
4406 smu7_ps->performance_levels[smu7_ps->performance_level_count - 1].memory_clock =
4407 golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value *
4409 golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value;
4415 static int smu7_get_sclks(struct pp_hwmgr *hwmgr, struct amd_pp_clocks *clocks)
4417 struct phm_ppt_v1_information *table_info =
4418 (struct phm_ppt_v1_information *)hwmgr->pptable;
4419 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table = NULL;
4420 struct phm_clock_voltage_dependency_table *sclk_table;
4423 if (hwmgr->pp_table_version == PP_TABLE_V1) {
4424 if (table_info == NULL || table_info->vdd_dep_on_sclk == NULL)
4426 dep_sclk_table = table_info->vdd_dep_on_sclk;
4427 for (i = 0; i < dep_sclk_table->count; i++)
4428 clocks->clock[i] = dep_sclk_table->entries[i].clk;
4429 clocks->count = dep_sclk_table->count;
4430 } else if (hwmgr->pp_table_version == PP_TABLE_V0) {
4431 sclk_table = hwmgr->dyn_state.vddc_dependency_on_sclk;
4432 for (i = 0; i < sclk_table->count; i++)
4433 clocks->clock[i] = sclk_table->entries[i].clk;
4434 clocks->count = sclk_table->count;
4440 static uint32_t smu7_get_mem_latency(struct pp_hwmgr *hwmgr, uint32_t clk)
4442 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4444 if (clk >= MEM_FREQ_LOW_LATENCY && clk < MEM_FREQ_HIGH_LATENCY)
4445 return data->mem_latency_high;
4446 else if (clk >= MEM_FREQ_HIGH_LATENCY)
4447 return data->mem_latency_low;
4449 return MEM_LATENCY_ERR;
4452 static int smu7_get_mclks(struct pp_hwmgr *hwmgr, struct amd_pp_clocks *clocks)
4454 struct phm_ppt_v1_information *table_info =
4455 (struct phm_ppt_v1_information *)hwmgr->pptable;
4456 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table;
4458 struct phm_clock_voltage_dependency_table *mclk_table;
4460 if (hwmgr->pp_table_version == PP_TABLE_V1) {
4461 if (table_info == NULL)
4463 dep_mclk_table = table_info->vdd_dep_on_mclk;
4464 for (i = 0; i < dep_mclk_table->count; i++) {
4465 clocks->clock[i] = dep_mclk_table->entries[i].clk;
4466 clocks->latency[i] = smu7_get_mem_latency(hwmgr,
4467 dep_mclk_table->entries[i].clk);
4469 clocks->count = dep_mclk_table->count;
4470 } else if (hwmgr->pp_table_version == PP_TABLE_V0) {
4471 mclk_table = hwmgr->dyn_state.vddc_dependency_on_mclk;
4472 for (i = 0; i < mclk_table->count; i++)
4473 clocks->clock[i] = mclk_table->entries[i].clk;
4474 clocks->count = mclk_table->count;
4479 static int smu7_get_clock_by_type(struct pp_hwmgr *hwmgr, enum amd_pp_clock_type type,
4480 struct amd_pp_clocks *clocks)
4483 case amd_pp_sys_clock:
4484 smu7_get_sclks(hwmgr, clocks);
4486 case amd_pp_mem_clock:
4487 smu7_get_mclks(hwmgr, clocks);
4496 static void smu7_find_min_clock_masks(struct pp_hwmgr *hwmgr,
4497 uint32_t *sclk_mask, uint32_t *mclk_mask,
4498 uint32_t min_sclk, uint32_t min_mclk)
4500 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4501 struct smu7_dpm_table *dpm_table = &(data->dpm_table);
4504 for (i = 0; i < dpm_table->sclk_table.count; i++) {
4505 if (dpm_table->sclk_table.dpm_levels[i].enabled &&
4506 dpm_table->sclk_table.dpm_levels[i].value >= min_sclk)
4507 *sclk_mask |= 1 << i;
4510 for (i = 0; i < dpm_table->mclk_table.count; i++) {
4511 if (dpm_table->mclk_table.dpm_levels[i].enabled &&
4512 dpm_table->mclk_table.dpm_levels[i].value >= min_mclk)
4513 *mclk_mask |= 1 << i;
4517 static int smu7_set_power_profile_state(struct pp_hwmgr *hwmgr,
4518 struct amd_pp_profile *request)
4520 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4521 int tmp_result, result = 0;
4522 uint32_t sclk_mask = 0, mclk_mask = 0;
4524 if (hwmgr->chip_id == CHIP_FIJI) {
4525 if (request->type == AMD_PP_GFX_PROFILE)
4526 smu7_enable_power_containment(hwmgr);
4527 else if (request->type == AMD_PP_COMPUTE_PROFILE)
4528 smu7_disable_power_containment(hwmgr);
4531 if (hwmgr->dpm_level != AMD_DPM_FORCED_LEVEL_AUTO)
4534 tmp_result = smu7_freeze_sclk_mclk_dpm(hwmgr);
4535 PP_ASSERT_WITH_CODE(!tmp_result,
4536 "Failed to freeze SCLK MCLK DPM!",
4537 result = tmp_result);
4539 tmp_result = smum_populate_requested_graphic_levels(hwmgr, request);
4540 PP_ASSERT_WITH_CODE(!tmp_result,
4541 "Failed to populate requested graphic levels!",
4542 result = tmp_result);
4544 tmp_result = smu7_unfreeze_sclk_mclk_dpm(hwmgr);
4545 PP_ASSERT_WITH_CODE(!tmp_result,
4546 "Failed to unfreeze SCLK MCLK DPM!",
4547 result = tmp_result);
4549 smu7_find_min_clock_masks(hwmgr, &sclk_mask, &mclk_mask,
4550 request->min_sclk, request->min_mclk);
4553 if (!data->sclk_dpm_key_disabled)
4554 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4555 PPSMC_MSG_SCLKDPM_SetEnabledMask,
4556 data->dpm_level_enable_mask.
4557 sclk_dpm_enable_mask &
4562 if (!data->mclk_dpm_key_disabled)
4563 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4564 PPSMC_MSG_MCLKDPM_SetEnabledMask,
4565 data->dpm_level_enable_mask.
4566 mclk_dpm_enable_mask &
4573 static int smu7_avfs_control(struct pp_hwmgr *hwmgr, bool enable)
4575 struct pp_smumgr *smumgr = (struct pp_smumgr *)(hwmgr->smumgr);
4576 struct smu7_smumgr *smu_data = (struct smu7_smumgr *)(smumgr->backend);
4578 if (smu_data == NULL)
4581 if (smu_data->avfs.avfs_btc_status == AVFS_BTC_NOTSUPPORTED)
4585 if (!PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device,
4586 CGS_IND_REG__SMC, FEATURE_STATUS, AVS_ON))
4587 PP_ASSERT_WITH_CODE(!smum_send_msg_to_smc(
4588 hwmgr->smumgr, PPSMC_MSG_EnableAvfs),
4589 "Failed to enable AVFS!",
4591 } else if (PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device,
4592 CGS_IND_REG__SMC, FEATURE_STATUS, AVS_ON))
4593 PP_ASSERT_WITH_CODE(!smum_send_msg_to_smc(
4594 hwmgr->smumgr, PPSMC_MSG_DisableAvfs),
4595 "Failed to disable AVFS!",
4601 static const struct pp_hwmgr_func smu7_hwmgr_funcs = {
4602 .backend_init = &smu7_hwmgr_backend_init,
4603 .backend_fini = &smu7_hwmgr_backend_fini,
4604 .asic_setup = &smu7_setup_asic_task,
4605 .dynamic_state_management_enable = &smu7_enable_dpm_tasks,
4606 .apply_state_adjust_rules = smu7_apply_state_adjust_rules,
4607 .force_dpm_level = &smu7_force_dpm_level,
4608 .power_state_set = smu7_set_power_state_tasks,
4609 .get_power_state_size = smu7_get_power_state_size,
4610 .get_mclk = smu7_dpm_get_mclk,
4611 .get_sclk = smu7_dpm_get_sclk,
4612 .patch_boot_state = smu7_dpm_patch_boot_state,
4613 .get_pp_table_entry = smu7_get_pp_table_entry,
4614 .get_num_of_pp_table_entries = smu7_get_number_of_powerplay_table_entries,
4615 .powerdown_uvd = smu7_powerdown_uvd,
4616 .powergate_uvd = smu7_powergate_uvd,
4617 .powergate_vce = smu7_powergate_vce,
4618 .disable_clock_power_gating = smu7_disable_clock_power_gating,
4619 .update_clock_gatings = smu7_update_clock_gatings,
4620 .notify_smc_display_config_after_ps_adjustment = smu7_notify_smc_display_config_after_ps_adjustment,
4621 .display_config_changed = smu7_display_configuration_changed_task,
4622 .set_max_fan_pwm_output = smu7_set_max_fan_pwm_output,
4623 .set_max_fan_rpm_output = smu7_set_max_fan_rpm_output,
4624 .get_temperature = smu7_thermal_get_temperature,
4625 .stop_thermal_controller = smu7_thermal_stop_thermal_controller,
4626 .get_fan_speed_info = smu7_fan_ctrl_get_fan_speed_info,
4627 .get_fan_speed_percent = smu7_fan_ctrl_get_fan_speed_percent,
4628 .set_fan_speed_percent = smu7_fan_ctrl_set_fan_speed_percent,
4629 .reset_fan_speed_to_default = smu7_fan_ctrl_reset_fan_speed_to_default,
4630 .get_fan_speed_rpm = smu7_fan_ctrl_get_fan_speed_rpm,
4631 .set_fan_speed_rpm = smu7_fan_ctrl_set_fan_speed_rpm,
4632 .uninitialize_thermal_controller = smu7_thermal_ctrl_uninitialize_thermal_controller,
4633 .register_internal_thermal_interrupt = smu7_register_internal_thermal_interrupt,
4634 .check_smc_update_required_for_display_configuration = smu7_check_smc_update_required_for_display_configuration,
4635 .check_states_equal = smu7_check_states_equal,
4636 .set_fan_control_mode = smu7_set_fan_control_mode,
4637 .get_fan_control_mode = smu7_get_fan_control_mode,
4638 .force_clock_level = smu7_force_clock_level,
4639 .print_clock_levels = smu7_print_clock_levels,
4640 .enable_per_cu_power_gating = smu7_enable_per_cu_power_gating,
4641 .get_sclk_od = smu7_get_sclk_od,
4642 .set_sclk_od = smu7_set_sclk_od,
4643 .get_mclk_od = smu7_get_mclk_od,
4644 .set_mclk_od = smu7_set_mclk_od,
4645 .get_clock_by_type = smu7_get_clock_by_type,
4646 .read_sensor = smu7_read_sensor,
4647 .dynamic_state_management_disable = smu7_disable_dpm_tasks,
4648 .set_power_profile_state = smu7_set_power_profile_state,
4649 .avfs_control = smu7_avfs_control,
4650 .disable_smc_firmware_ctf = smu7_thermal_disable_alert,
4651 .start_thermal_controller = smu7_start_thermal_controller,
4654 uint8_t smu7_get_sleep_divider_id_from_clock(uint32_t clock,
4655 uint32_t clock_insr)
4659 uint32_t min = max(clock_insr, (uint32_t)SMU7_MINIMUM_ENGINE_CLOCK);
4661 PP_ASSERT_WITH_CODE((clock >= min), "Engine clock can't satisfy stutter requirement!", return 0);
4662 for (i = SMU7_MAX_DEEPSLEEP_DIVIDER_ID; ; i--) {
4665 if (temp >= min || i == 0)
4671 int smu7_init_function_pointers(struct pp_hwmgr *hwmgr)
4675 hwmgr->hwmgr_func = &smu7_hwmgr_funcs;
4676 if (hwmgr->pp_table_version == PP_TABLE_V0)
4677 hwmgr->pptable_func = &pptable_funcs;
4678 else if (hwmgr->pp_table_version == PP_TABLE_V1)
4679 hwmgr->pptable_func = &pptable_v1_0_funcs;