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/pci.h>
28 #include <linux/slab.h>
29 #include <asm/div64.h>
30 #if IS_ENABLED(CONFIG_X86_64)
31 #include <asm/intel-family.h>
33 #include <drm/amdgpu_drm.h>
34 #include "ppatomctrl.h"
36 #include "pptable_v1_0.h"
37 #include "pppcielanes.h"
38 #include "amd_pcie_helpers.h"
39 #include "hardwaremanager.h"
40 #include "process_pptables_v1_0.h"
41 #include "cgs_common.h"
43 #include "smu7_common.h"
46 #include "smu7_hwmgr.h"
47 #include "smu_ucode_xfer_vi.h"
48 #include "smu7_powertune.h"
49 #include "smu7_dyn_defaults.h"
50 #include "smu7_thermal.h"
51 #include "smu7_clockpowergating.h"
52 #include "processpptables.h"
53 #include "pp_thermal.h"
54 #include "smu7_baco.h"
55 #include "smu7_smumgr.h"
56 #include "polaris10_smumgr.h"
58 #include "ivsrcid/ivsrcid_vislands30.h"
60 #define MC_CG_ARB_FREQ_F0 0x0a
61 #define MC_CG_ARB_FREQ_F1 0x0b
62 #define MC_CG_ARB_FREQ_F2 0x0c
63 #define MC_CG_ARB_FREQ_F3 0x0d
65 #define MC_CG_SEQ_DRAMCONF_S0 0x05
66 #define MC_CG_SEQ_DRAMCONF_S1 0x06
67 #define MC_CG_SEQ_YCLK_SUSPEND 0x04
68 #define MC_CG_SEQ_YCLK_RESUME 0x0a
70 #define SMC_CG_IND_START 0xc0030000
71 #define SMC_CG_IND_END 0xc0040000
73 #define MEM_FREQ_LOW_LATENCY 25000
74 #define MEM_FREQ_HIGH_LATENCY 80000
76 #define MEM_LATENCY_HIGH 45
77 #define MEM_LATENCY_LOW 35
78 #define MEM_LATENCY_ERR 0xFFFF
80 #define MC_SEQ_MISC0_GDDR5_SHIFT 28
81 #define MC_SEQ_MISC0_GDDR5_MASK 0xf0000000
82 #define MC_SEQ_MISC0_GDDR5_VALUE 5
84 #define PCIE_BUS_CLK 10000
85 #define TCLK (PCIE_BUS_CLK / 10)
87 static struct profile_mode_setting smu7_profiling[7] =
88 {{0, 0, 0, 0, 0, 0, 0, 0},
89 {1, 0, 100, 30, 1, 0, 100, 10},
90 {1, 10, 0, 30, 0, 0, 0, 0},
91 {0, 0, 0, 0, 1, 10, 16, 31},
92 {1, 0, 11, 50, 1, 0, 100, 10},
93 {1, 0, 5, 30, 0, 0, 0, 0},
94 {0, 0, 0, 0, 0, 0, 0, 0},
97 #define PPSMC_MSG_SetVBITimeout_VEGAM ((uint16_t) 0x310)
99 #define ixPWR_SVI2_PLANE1_LOAD 0xC0200280
100 #define PWR_SVI2_PLANE1_LOAD__PSI1_MASK 0x00000020L
101 #define PWR_SVI2_PLANE1_LOAD__PSI0_EN_MASK 0x00000040L
102 #define PWR_SVI2_PLANE1_LOAD__PSI1__SHIFT 0x00000005
103 #define PWR_SVI2_PLANE1_LOAD__PSI0_EN__SHIFT 0x00000006
105 #define STRAP_EVV_REVISION_MSB 2211
106 #define STRAP_EVV_REVISION_LSB 2208
108 /** Values for the CG_THERMAL_CTRL::DPM_EVENT_SRC field. */
110 DPM_EVENT_SRC_ANALOG = 0,
111 DPM_EVENT_SRC_EXTERNAL = 1,
112 DPM_EVENT_SRC_DIGITAL = 2,
113 DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
114 DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL = 4
117 #define ixDIDT_SQ_EDC_CTRL 0x0013
118 #define ixDIDT_SQ_EDC_THRESHOLD 0x0014
119 #define ixDIDT_SQ_EDC_STALL_PATTERN_1_2 0x0015
120 #define ixDIDT_SQ_EDC_STALL_PATTERN_3_4 0x0016
121 #define ixDIDT_SQ_EDC_STALL_PATTERN_5_6 0x0017
122 #define ixDIDT_SQ_EDC_STALL_PATTERN_7 0x0018
124 #define ixDIDT_TD_EDC_CTRL 0x0053
125 #define ixDIDT_TD_EDC_THRESHOLD 0x0054
126 #define ixDIDT_TD_EDC_STALL_PATTERN_1_2 0x0055
127 #define ixDIDT_TD_EDC_STALL_PATTERN_3_4 0x0056
128 #define ixDIDT_TD_EDC_STALL_PATTERN_5_6 0x0057
129 #define ixDIDT_TD_EDC_STALL_PATTERN_7 0x0058
131 #define ixDIDT_TCP_EDC_CTRL 0x0073
132 #define ixDIDT_TCP_EDC_THRESHOLD 0x0074
133 #define ixDIDT_TCP_EDC_STALL_PATTERN_1_2 0x0075
134 #define ixDIDT_TCP_EDC_STALL_PATTERN_3_4 0x0076
135 #define ixDIDT_TCP_EDC_STALL_PATTERN_5_6 0x0077
136 #define ixDIDT_TCP_EDC_STALL_PATTERN_7 0x0078
138 #define ixDIDT_DB_EDC_CTRL 0x0033
139 #define ixDIDT_DB_EDC_THRESHOLD 0x0034
140 #define ixDIDT_DB_EDC_STALL_PATTERN_1_2 0x0035
141 #define ixDIDT_DB_EDC_STALL_PATTERN_3_4 0x0036
142 #define ixDIDT_DB_EDC_STALL_PATTERN_5_6 0x0037
143 #define ixDIDT_DB_EDC_STALL_PATTERN_7 0x0038
145 uint32_t DIDTEDCConfig_P12[] = {
146 ixDIDT_SQ_EDC_STALL_PATTERN_1_2,
147 ixDIDT_SQ_EDC_STALL_PATTERN_3_4,
148 ixDIDT_SQ_EDC_STALL_PATTERN_5_6,
149 ixDIDT_SQ_EDC_STALL_PATTERN_7,
150 ixDIDT_SQ_EDC_THRESHOLD,
152 ixDIDT_TD_EDC_STALL_PATTERN_1_2,
153 ixDIDT_TD_EDC_STALL_PATTERN_3_4,
154 ixDIDT_TD_EDC_STALL_PATTERN_5_6,
155 ixDIDT_TD_EDC_STALL_PATTERN_7,
156 ixDIDT_TD_EDC_THRESHOLD,
158 ixDIDT_TCP_EDC_STALL_PATTERN_1_2,
159 ixDIDT_TCP_EDC_STALL_PATTERN_3_4,
160 ixDIDT_TCP_EDC_STALL_PATTERN_5_6,
161 ixDIDT_TCP_EDC_STALL_PATTERN_7,
162 ixDIDT_TCP_EDC_THRESHOLD,
164 ixDIDT_DB_EDC_STALL_PATTERN_1_2,
165 ixDIDT_DB_EDC_STALL_PATTERN_3_4,
166 ixDIDT_DB_EDC_STALL_PATTERN_5_6,
167 ixDIDT_DB_EDC_STALL_PATTERN_7,
168 ixDIDT_DB_EDC_THRESHOLD,
170 0xFFFFFFFF // End of list
173 static const unsigned long PhwVIslands_Magic = (unsigned long)(PHM_VIslands_Magic);
174 static int smu7_force_clock_level(struct pp_hwmgr *hwmgr,
175 enum pp_clock_type type, uint32_t mask);
176 static int smu7_notify_has_display(struct pp_hwmgr *hwmgr);
178 static struct smu7_power_state *cast_phw_smu7_power_state(
179 struct pp_hw_power_state *hw_ps)
181 PP_ASSERT_WITH_CODE((PhwVIslands_Magic == hw_ps->magic),
182 "Invalid Powerstate Type!",
185 return (struct smu7_power_state *)hw_ps;
188 static const struct smu7_power_state *cast_const_phw_smu7_power_state(
189 const struct pp_hw_power_state *hw_ps)
191 PP_ASSERT_WITH_CODE((PhwVIslands_Magic == hw_ps->magic),
192 "Invalid Powerstate Type!",
195 return (const struct smu7_power_state *)hw_ps;
199 * smu7_get_mc_microcode_version - Find the MC microcode version and store it in the HwMgr struct
201 * @hwmgr: the address of the powerplay hardware manager.
204 static int smu7_get_mc_microcode_version(struct pp_hwmgr *hwmgr)
206 cgs_write_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_INDEX, 0x9F);
208 hwmgr->microcode_version_info.MC = cgs_read_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_DATA);
213 static uint16_t smu7_get_current_pcie_speed(struct pp_hwmgr *hwmgr)
215 uint32_t speedCntl = 0;
217 /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
218 speedCntl = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__PCIE,
219 ixPCIE_LC_SPEED_CNTL);
220 return((uint16_t)PHM_GET_FIELD(speedCntl,
221 PCIE_LC_SPEED_CNTL, LC_CURRENT_DATA_RATE));
224 static int smu7_get_current_pcie_lane_number(struct pp_hwmgr *hwmgr)
228 /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
229 link_width = PHM_READ_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE,
230 PCIE_LC_LINK_WIDTH_CNTL, LC_LINK_WIDTH_RD);
232 PP_ASSERT_WITH_CODE((7 >= link_width),
233 "Invalid PCIe lane width!", return 0);
235 return decode_pcie_lane_width(link_width);
239 * smu7_enable_smc_voltage_controller - Enable voltage control
241 * @hwmgr: the address of the powerplay hardware manager.
242 * Return: always PP_Result_OK
244 static int smu7_enable_smc_voltage_controller(struct pp_hwmgr *hwmgr)
246 if (hwmgr->chip_id >= CHIP_POLARIS10 &&
247 hwmgr->chip_id <= CHIP_VEGAM) {
248 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device,
249 CGS_IND_REG__SMC, PWR_SVI2_PLANE1_LOAD, PSI1, 0);
250 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device,
251 CGS_IND_REG__SMC, PWR_SVI2_PLANE1_LOAD, PSI0_EN, 0);
254 if (hwmgr->feature_mask & PP_SMC_VOLTAGE_CONTROL_MASK)
255 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_Voltage_Cntl_Enable, NULL);
261 * smu7_voltage_control - Checks if we want to support voltage control
263 * @hwmgr: the address of the powerplay hardware manager.
265 static bool smu7_voltage_control(const struct pp_hwmgr *hwmgr)
267 const struct smu7_hwmgr *data =
268 (const struct smu7_hwmgr *)(hwmgr->backend);
270 return (SMU7_VOLTAGE_CONTROL_NONE != data->voltage_control);
274 * smu7_enable_voltage_control - Enable voltage control
276 * @hwmgr: the address of the powerplay hardware manager.
279 static int smu7_enable_voltage_control(struct pp_hwmgr *hwmgr)
281 /* enable voltage control */
282 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
283 GENERAL_PWRMGT, VOLT_PWRMGT_EN, 1);
288 static int phm_get_svi2_voltage_table_v0(pp_atomctrl_voltage_table *voltage_table,
289 struct phm_clock_voltage_dependency_table *voltage_dependency_table
294 PP_ASSERT_WITH_CODE((NULL != voltage_table),
295 "Voltage Dependency Table empty.", return -EINVAL;);
297 voltage_table->mask_low = 0;
298 voltage_table->phase_delay = 0;
299 voltage_table->count = voltage_dependency_table->count;
301 for (i = 0; i < voltage_dependency_table->count; i++) {
302 voltage_table->entries[i].value =
303 voltage_dependency_table->entries[i].v;
304 voltage_table->entries[i].smio_low = 0;
312 * smu7_construct_voltage_tables - Create Voltage Tables.
314 * @hwmgr: the address of the powerplay hardware manager.
317 static int smu7_construct_voltage_tables(struct pp_hwmgr *hwmgr)
319 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
320 struct phm_ppt_v1_information *table_info =
321 (struct phm_ppt_v1_information *)hwmgr->pptable;
325 if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
326 result = atomctrl_get_voltage_table_v3(hwmgr,
327 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT,
328 &(data->mvdd_voltage_table));
329 PP_ASSERT_WITH_CODE((0 == result),
330 "Failed to retrieve MVDD table.",
332 } else if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) {
333 if (hwmgr->pp_table_version == PP_TABLE_V1)
334 result = phm_get_svi2_mvdd_voltage_table(&(data->mvdd_voltage_table),
335 table_info->vdd_dep_on_mclk);
336 else if (hwmgr->pp_table_version == PP_TABLE_V0)
337 result = phm_get_svi2_voltage_table_v0(&(data->mvdd_voltage_table),
338 hwmgr->dyn_state.mvdd_dependency_on_mclk);
340 PP_ASSERT_WITH_CODE((0 == result),
341 "Failed to retrieve SVI2 MVDD table from dependency table.",
345 if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
346 result = atomctrl_get_voltage_table_v3(hwmgr,
347 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT,
348 &(data->vddci_voltage_table));
349 PP_ASSERT_WITH_CODE((0 == result),
350 "Failed to retrieve VDDCI table.",
352 } else if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) {
353 if (hwmgr->pp_table_version == PP_TABLE_V1)
354 result = phm_get_svi2_vddci_voltage_table(&(data->vddci_voltage_table),
355 table_info->vdd_dep_on_mclk);
356 else if (hwmgr->pp_table_version == PP_TABLE_V0)
357 result = phm_get_svi2_voltage_table_v0(&(data->vddci_voltage_table),
358 hwmgr->dyn_state.vddci_dependency_on_mclk);
359 PP_ASSERT_WITH_CODE((0 == result),
360 "Failed to retrieve SVI2 VDDCI table from dependency table.",
364 if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_gfx_control) {
365 /* VDDGFX has only SVI2 voltage control */
366 result = phm_get_svi2_vdd_voltage_table(&(data->vddgfx_voltage_table),
367 table_info->vddgfx_lookup_table);
368 PP_ASSERT_WITH_CODE((0 == result),
369 "Failed to retrieve SVI2 VDDGFX table from lookup table.", return result;);
373 if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->voltage_control) {
374 result = atomctrl_get_voltage_table_v3(hwmgr,
375 VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_GPIO_LUT,
376 &data->vddc_voltage_table);
377 PP_ASSERT_WITH_CODE((0 == result),
378 "Failed to retrieve VDDC table.", return result;);
379 } else if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
381 if (hwmgr->pp_table_version == PP_TABLE_V0)
382 result = phm_get_svi2_voltage_table_v0(&data->vddc_voltage_table,
383 hwmgr->dyn_state.vddc_dependency_on_mclk);
384 else if (hwmgr->pp_table_version == PP_TABLE_V1)
385 result = phm_get_svi2_vdd_voltage_table(&(data->vddc_voltage_table),
386 table_info->vddc_lookup_table);
388 PP_ASSERT_WITH_CODE((0 == result),
389 "Failed to retrieve SVI2 VDDC table from dependency table.", return result;);
392 tmp = smum_get_mac_definition(hwmgr, SMU_MAX_LEVELS_VDDC);
394 (data->vddc_voltage_table.count <= tmp),
395 "Too many voltage values for VDDC. Trimming to fit state table.",
396 phm_trim_voltage_table_to_fit_state_table(tmp,
397 &(data->vddc_voltage_table)));
399 tmp = smum_get_mac_definition(hwmgr, SMU_MAX_LEVELS_VDDGFX);
401 (data->vddgfx_voltage_table.count <= tmp),
402 "Too many voltage values for VDDC. Trimming to fit state table.",
403 phm_trim_voltage_table_to_fit_state_table(tmp,
404 &(data->vddgfx_voltage_table)));
406 tmp = smum_get_mac_definition(hwmgr, SMU_MAX_LEVELS_VDDCI);
408 (data->vddci_voltage_table.count <= tmp),
409 "Too many voltage values for VDDCI. Trimming to fit state table.",
410 phm_trim_voltage_table_to_fit_state_table(tmp,
411 &(data->vddci_voltage_table)));
413 tmp = smum_get_mac_definition(hwmgr, SMU_MAX_LEVELS_MVDD);
415 (data->mvdd_voltage_table.count <= tmp),
416 "Too many voltage values for MVDD. Trimming to fit state table.",
417 phm_trim_voltage_table_to_fit_state_table(tmp,
418 &(data->mvdd_voltage_table)));
424 * smu7_program_static_screen_threshold_parameters - Programs static screed detection parameters
426 * @hwmgr: the address of the powerplay hardware manager.
429 static int smu7_program_static_screen_threshold_parameters(
430 struct pp_hwmgr *hwmgr)
432 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
434 /* Set static screen threshold unit */
435 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
436 CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD_UNIT,
437 data->static_screen_threshold_unit);
438 /* Set static screen threshold */
439 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
440 CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD,
441 data->static_screen_threshold);
447 * smu7_enable_display_gap - Setup display gap for glitch free memory clock switching.
449 * @hwmgr: the address of the powerplay hardware manager.
452 static int smu7_enable_display_gap(struct pp_hwmgr *hwmgr)
454 uint32_t display_gap =
455 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
456 ixCG_DISPLAY_GAP_CNTL);
458 display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL,
459 DISP_GAP, DISPLAY_GAP_IGNORE);
461 display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL,
462 DISP_GAP_MCHG, DISPLAY_GAP_VBLANK);
464 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
465 ixCG_DISPLAY_GAP_CNTL, display_gap);
471 * smu7_program_voting_clients - Programs activity state transition voting clients
473 * @hwmgr: the address of the powerplay hardware manager.
476 static int smu7_program_voting_clients(struct pp_hwmgr *hwmgr)
478 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
481 /* Clear reset for voting clients before enabling DPM */
482 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
483 SCLK_PWRMGT_CNTL, RESET_SCLK_CNT, 0);
484 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
485 SCLK_PWRMGT_CNTL, RESET_BUSY_CNT, 0);
487 for (i = 0; i < 8; i++)
488 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
489 ixCG_FREQ_TRAN_VOTING_0 + i * 4,
490 data->voting_rights_clients[i]);
494 static int smu7_clear_voting_clients(struct pp_hwmgr *hwmgr)
498 /* Reset voting clients before disabling DPM */
499 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
500 SCLK_PWRMGT_CNTL, RESET_SCLK_CNT, 1);
501 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
502 SCLK_PWRMGT_CNTL, RESET_BUSY_CNT, 1);
504 for (i = 0; i < 8; i++)
505 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
506 ixCG_FREQ_TRAN_VOTING_0 + i * 4, 0);
511 /* Copy one arb setting to another and then switch the active set.
512 * arb_src and arb_dest is one of the MC_CG_ARB_FREQ_Fx constants.
514 static int smu7_copy_and_switch_arb_sets(struct pp_hwmgr *hwmgr,
515 uint32_t arb_src, uint32_t arb_dest)
517 uint32_t mc_arb_dram_timing;
518 uint32_t mc_arb_dram_timing2;
520 uint32_t mc_cg_config;
523 case MC_CG_ARB_FREQ_F0:
524 mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
525 mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
526 burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0);
528 case MC_CG_ARB_FREQ_F1:
529 mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1);
530 mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1);
531 burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1);
538 case MC_CG_ARB_FREQ_F0:
539 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING, mc_arb_dram_timing);
540 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2, mc_arb_dram_timing2);
541 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0, burst_time);
543 case MC_CG_ARB_FREQ_F1:
544 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1, mc_arb_dram_timing);
545 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1, mc_arb_dram_timing2);
546 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1, burst_time);
552 mc_cg_config = cgs_read_register(hwmgr->device, mmMC_CG_CONFIG);
553 mc_cg_config |= 0x0000000F;
554 cgs_write_register(hwmgr->device, mmMC_CG_CONFIG, mc_cg_config);
555 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_CG, CG_ARB_REQ, arb_dest);
560 static int smu7_reset_to_default(struct pp_hwmgr *hwmgr)
562 return smum_send_msg_to_smc(hwmgr, PPSMC_MSG_ResetToDefaults, NULL);
566 * smu7_initial_switch_from_arbf0_to_f1 - Initial switch from ARB F0->F1
568 * @hwmgr: the address of the powerplay hardware manager.
570 * This function is to be called from the SetPowerState table.
572 static int smu7_initial_switch_from_arbf0_to_f1(struct pp_hwmgr *hwmgr)
574 return smu7_copy_and_switch_arb_sets(hwmgr,
575 MC_CG_ARB_FREQ_F0, MC_CG_ARB_FREQ_F1);
578 static int smu7_force_switch_to_arbf0(struct pp_hwmgr *hwmgr)
582 tmp = (cgs_read_ind_register(hwmgr->device,
583 CGS_IND_REG__SMC, ixSMC_SCRATCH9) &
586 if (tmp == MC_CG_ARB_FREQ_F0)
589 return smu7_copy_and_switch_arb_sets(hwmgr,
590 tmp, MC_CG_ARB_FREQ_F0);
593 static uint16_t smu7_override_pcie_speed(struct pp_hwmgr *hwmgr)
595 struct amdgpu_device *adev = (struct amdgpu_device *)(hwmgr->adev);
596 uint16_t pcie_gen = 0;
598 if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN4 &&
599 adev->pm.pcie_gen_mask & CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN4)
601 else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3 &&
602 adev->pm.pcie_gen_mask & CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3)
604 else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 &&
605 adev->pm.pcie_gen_mask & CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2)
607 else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1 &&
608 adev->pm.pcie_gen_mask & CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1)
614 static uint16_t smu7_override_pcie_width(struct pp_hwmgr *hwmgr)
616 struct amdgpu_device *adev = (struct amdgpu_device *)(hwmgr->adev);
617 uint16_t pcie_width = 0;
619 if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16)
621 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12)
623 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8)
625 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4)
627 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2)
629 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X1)
635 static int smu7_setup_default_pcie_table(struct pp_hwmgr *hwmgr)
637 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
639 struct phm_ppt_v1_information *table_info =
640 (struct phm_ppt_v1_information *)(hwmgr->pptable);
641 struct phm_ppt_v1_pcie_table *pcie_table = NULL;
643 uint32_t i, max_entry;
646 PP_ASSERT_WITH_CODE((data->use_pcie_performance_levels ||
647 data->use_pcie_power_saving_levels), "No pcie performance levels!",
650 if (table_info != NULL)
651 pcie_table = table_info->pcie_table;
653 if (data->use_pcie_performance_levels &&
654 !data->use_pcie_power_saving_levels) {
655 data->pcie_gen_power_saving = data->pcie_gen_performance;
656 data->pcie_lane_power_saving = data->pcie_lane_performance;
657 } else if (!data->use_pcie_performance_levels &&
658 data->use_pcie_power_saving_levels) {
659 data->pcie_gen_performance = data->pcie_gen_power_saving;
660 data->pcie_lane_performance = data->pcie_lane_power_saving;
662 tmp = smum_get_mac_definition(hwmgr, SMU_MAX_LEVELS_LINK);
663 phm_reset_single_dpm_table(&data->dpm_table.pcie_speed_table,
665 MAX_REGULAR_DPM_NUMBER);
667 if (pcie_table != NULL) {
668 /* max_entry is used to make sure we reserve one PCIE level
669 * for boot level (fix for A+A PSPP issue).
670 * If PCIE table from PPTable have ULV entry + 8 entries,
671 * then ignore the last entry.*/
672 max_entry = (tmp < pcie_table->count) ? tmp : pcie_table->count;
673 for (i = 1; i < max_entry; i++) {
674 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, i - 1,
675 get_pcie_gen_support(data->pcie_gen_cap,
676 pcie_table->entries[i].gen_speed),
677 get_pcie_lane_support(data->pcie_lane_cap,
678 pcie_table->entries[i].lane_width));
680 data->dpm_table.pcie_speed_table.count = max_entry - 1;
681 smum_update_smc_table(hwmgr, SMU_BIF_TABLE);
683 /* Hardcode Pcie Table */
684 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 0,
685 get_pcie_gen_support(data->pcie_gen_cap,
687 get_pcie_lane_support(data->pcie_lane_cap,
689 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 1,
690 get_pcie_gen_support(data->pcie_gen_cap,
692 get_pcie_lane_support(data->pcie_lane_cap,
694 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 2,
695 get_pcie_gen_support(data->pcie_gen_cap,
697 get_pcie_lane_support(data->pcie_lane_cap,
699 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 3,
700 get_pcie_gen_support(data->pcie_gen_cap,
702 get_pcie_lane_support(data->pcie_lane_cap,
704 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 4,
705 get_pcie_gen_support(data->pcie_gen_cap,
707 get_pcie_lane_support(data->pcie_lane_cap,
709 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 5,
710 get_pcie_gen_support(data->pcie_gen_cap,
712 get_pcie_lane_support(data->pcie_lane_cap,
715 data->dpm_table.pcie_speed_table.count = 6;
717 /* Populate last level for boot PCIE level, but do not increment count. */
718 if (hwmgr->chip_family == AMDGPU_FAMILY_CI) {
719 for (i = 0; i <= data->dpm_table.pcie_speed_table.count; i++)
720 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, i,
721 get_pcie_gen_support(data->pcie_gen_cap,
723 data->vbios_boot_state.pcie_lane_bootup_value);
725 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table,
726 data->dpm_table.pcie_speed_table.count,
727 get_pcie_gen_support(data->pcie_gen_cap,
729 get_pcie_lane_support(data->pcie_lane_cap,
732 if (data->pcie_dpm_key_disabled)
733 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table,
734 data->dpm_table.pcie_speed_table.count,
735 smu7_override_pcie_speed(hwmgr), smu7_override_pcie_width(hwmgr));
740 static int smu7_reset_dpm_tables(struct pp_hwmgr *hwmgr)
742 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
744 memset(&(data->dpm_table), 0x00, sizeof(data->dpm_table));
746 phm_reset_single_dpm_table(
747 &data->dpm_table.sclk_table,
748 smum_get_mac_definition(hwmgr,
749 SMU_MAX_LEVELS_GRAPHICS),
750 MAX_REGULAR_DPM_NUMBER);
751 phm_reset_single_dpm_table(
752 &data->dpm_table.mclk_table,
753 smum_get_mac_definition(hwmgr,
754 SMU_MAX_LEVELS_MEMORY), MAX_REGULAR_DPM_NUMBER);
756 phm_reset_single_dpm_table(
757 &data->dpm_table.vddc_table,
758 smum_get_mac_definition(hwmgr,
759 SMU_MAX_LEVELS_VDDC),
760 MAX_REGULAR_DPM_NUMBER);
761 phm_reset_single_dpm_table(
762 &data->dpm_table.vddci_table,
763 smum_get_mac_definition(hwmgr,
764 SMU_MAX_LEVELS_VDDCI), MAX_REGULAR_DPM_NUMBER);
766 phm_reset_single_dpm_table(
767 &data->dpm_table.mvdd_table,
768 smum_get_mac_definition(hwmgr,
769 SMU_MAX_LEVELS_MVDD),
770 MAX_REGULAR_DPM_NUMBER);
774 * This function is to initialize all DPM state tables
775 * for SMU7 based on the dependency table.
776 * Dynamic state patching function will then trim these
777 * state tables to the allowed range based
778 * on the power policy or external client requests,
779 * such as UVD request, etc.
782 static int smu7_setup_dpm_tables_v0(struct pp_hwmgr *hwmgr)
784 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
785 struct phm_clock_voltage_dependency_table *allowed_vdd_sclk_table =
786 hwmgr->dyn_state.vddc_dependency_on_sclk;
787 struct phm_clock_voltage_dependency_table *allowed_vdd_mclk_table =
788 hwmgr->dyn_state.vddc_dependency_on_mclk;
789 struct phm_cac_leakage_table *std_voltage_table =
790 hwmgr->dyn_state.cac_leakage_table;
793 PP_ASSERT_WITH_CODE(allowed_vdd_sclk_table != NULL,
794 "SCLK dependency table is missing. This table is mandatory", return -EINVAL);
795 PP_ASSERT_WITH_CODE(allowed_vdd_sclk_table->count >= 1,
796 "SCLK dependency table has to have is missing. This table is mandatory", return -EINVAL);
798 PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table != NULL,
799 "MCLK dependency table is missing. This table is mandatory", return -EINVAL);
800 PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table->count >= 1,
801 "VMCLK dependency table has to have is missing. This table is mandatory", return -EINVAL);
804 /* Initialize Sclk DPM table based on allow Sclk values*/
805 data->dpm_table.sclk_table.count = 0;
807 for (i = 0; i < allowed_vdd_sclk_table->count; i++) {
808 if (i == 0 || data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count-1].value !=
809 allowed_vdd_sclk_table->entries[i].clk) {
810 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].value =
811 allowed_vdd_sclk_table->entries[i].clk;
812 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].enabled = (i == 0) ? 1 : 0;
813 data->dpm_table.sclk_table.count++;
817 PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table != NULL,
818 "MCLK dependency table is missing. This table is mandatory", return -EINVAL);
819 /* Initialize Mclk DPM table based on allow Mclk values */
820 data->dpm_table.mclk_table.count = 0;
821 for (i = 0; i < allowed_vdd_mclk_table->count; i++) {
822 if (i == 0 || data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count-1].value !=
823 allowed_vdd_mclk_table->entries[i].clk) {
824 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].value =
825 allowed_vdd_mclk_table->entries[i].clk;
826 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].enabled = (i == 0) ? 1 : 0;
827 data->dpm_table.mclk_table.count++;
831 /* Initialize Vddc DPM table based on allow Vddc values. And populate corresponding std values. */
832 for (i = 0; i < allowed_vdd_sclk_table->count; i++) {
833 data->dpm_table.vddc_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].v;
834 data->dpm_table.vddc_table.dpm_levels[i].param1 = std_voltage_table->entries[i].Leakage;
835 /* param1 is for corresponding std voltage */
836 data->dpm_table.vddc_table.dpm_levels[i].enabled = true;
839 data->dpm_table.vddc_table.count = allowed_vdd_sclk_table->count;
840 allowed_vdd_mclk_table = hwmgr->dyn_state.vddci_dependency_on_mclk;
842 if (NULL != allowed_vdd_mclk_table) {
843 /* Initialize Vddci DPM table based on allow Mclk values */
844 for (i = 0; i < allowed_vdd_mclk_table->count; i++) {
845 data->dpm_table.vddci_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].v;
846 data->dpm_table.vddci_table.dpm_levels[i].enabled = true;
848 data->dpm_table.vddci_table.count = allowed_vdd_mclk_table->count;
851 allowed_vdd_mclk_table = hwmgr->dyn_state.mvdd_dependency_on_mclk;
853 if (NULL != allowed_vdd_mclk_table) {
855 * Initialize MVDD DPM table based on allow Mclk
858 for (i = 0; i < allowed_vdd_mclk_table->count; i++) {
859 data->dpm_table.mvdd_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].v;
860 data->dpm_table.mvdd_table.dpm_levels[i].enabled = true;
862 data->dpm_table.mvdd_table.count = allowed_vdd_mclk_table->count;
868 static int smu7_setup_dpm_tables_v1(struct pp_hwmgr *hwmgr)
870 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
871 struct phm_ppt_v1_information *table_info =
872 (struct phm_ppt_v1_information *)(hwmgr->pptable);
875 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table;
876 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table;
878 if (table_info == NULL)
881 dep_sclk_table = table_info->vdd_dep_on_sclk;
882 dep_mclk_table = table_info->vdd_dep_on_mclk;
884 PP_ASSERT_WITH_CODE(dep_sclk_table != NULL,
885 "SCLK dependency table is missing.",
887 PP_ASSERT_WITH_CODE(dep_sclk_table->count >= 1,
888 "SCLK dependency table count is 0.",
891 PP_ASSERT_WITH_CODE(dep_mclk_table != NULL,
892 "MCLK dependency table is missing.",
894 PP_ASSERT_WITH_CODE(dep_mclk_table->count >= 1,
895 "MCLK dependency table count is 0",
898 /* Initialize Sclk DPM table based on allow Sclk values */
899 data->dpm_table.sclk_table.count = 0;
900 for (i = 0; i < dep_sclk_table->count; i++) {
901 if (i == 0 || data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count - 1].value !=
902 dep_sclk_table->entries[i].clk) {
904 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].value =
905 dep_sclk_table->entries[i].clk;
907 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].enabled =
908 (i == 0) ? true : false;
909 data->dpm_table.sclk_table.count++;
912 if (hwmgr->platform_descriptor.overdriveLimit.engineClock == 0)
913 hwmgr->platform_descriptor.overdriveLimit.engineClock = dep_sclk_table->entries[i-1].clk;
914 /* Initialize Mclk DPM table based on allow Mclk values */
915 data->dpm_table.mclk_table.count = 0;
916 for (i = 0; i < dep_mclk_table->count; i++) {
917 if (i == 0 || data->dpm_table.mclk_table.dpm_levels
918 [data->dpm_table.mclk_table.count - 1].value !=
919 dep_mclk_table->entries[i].clk) {
920 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].value =
921 dep_mclk_table->entries[i].clk;
922 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].enabled =
923 (i == 0) ? true : false;
924 data->dpm_table.mclk_table.count++;
928 if (hwmgr->platform_descriptor.overdriveLimit.memoryClock == 0)
929 hwmgr->platform_descriptor.overdriveLimit.memoryClock = dep_mclk_table->entries[i-1].clk;
933 static int smu7_odn_initial_default_setting(struct pp_hwmgr *hwmgr)
935 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
936 struct smu7_odn_dpm_table *odn_table = &(data->odn_dpm_table);
937 struct phm_ppt_v1_information *table_info =
938 (struct phm_ppt_v1_information *)(hwmgr->pptable);
941 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table;
942 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table;
943 struct phm_odn_performance_level *entries;
945 if (table_info == NULL)
948 dep_sclk_table = table_info->vdd_dep_on_sclk;
949 dep_mclk_table = table_info->vdd_dep_on_mclk;
951 odn_table->odn_core_clock_dpm_levels.num_of_pl =
952 data->golden_dpm_table.sclk_table.count;
953 entries = odn_table->odn_core_clock_dpm_levels.entries;
954 for (i=0; i<data->golden_dpm_table.sclk_table.count; i++) {
955 entries[i].clock = data->golden_dpm_table.sclk_table.dpm_levels[i].value;
956 entries[i].enabled = true;
957 entries[i].vddc = dep_sclk_table->entries[i].vddc;
960 smu_get_voltage_dependency_table_ppt_v1(dep_sclk_table,
961 (struct phm_ppt_v1_clock_voltage_dependency_table *)&(odn_table->vdd_dependency_on_sclk));
963 odn_table->odn_memory_clock_dpm_levels.num_of_pl =
964 data->golden_dpm_table.mclk_table.count;
965 entries = odn_table->odn_memory_clock_dpm_levels.entries;
966 for (i=0; i<data->golden_dpm_table.mclk_table.count; i++) {
967 entries[i].clock = data->golden_dpm_table.mclk_table.dpm_levels[i].value;
968 entries[i].enabled = true;
969 entries[i].vddc = dep_mclk_table->entries[i].vddc;
972 smu_get_voltage_dependency_table_ppt_v1(dep_mclk_table,
973 (struct phm_ppt_v1_clock_voltage_dependency_table *)&(odn_table->vdd_dependency_on_mclk));
978 static void smu7_setup_voltage_range_from_vbios(struct pp_hwmgr *hwmgr)
980 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
981 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table;
982 struct phm_ppt_v1_information *table_info =
983 (struct phm_ppt_v1_information *)(hwmgr->pptable);
984 uint32_t min_vddc = 0;
985 uint32_t max_vddc = 0;
990 dep_sclk_table = table_info->vdd_dep_on_sclk;
992 atomctrl_get_voltage_range(hwmgr, &max_vddc, &min_vddc);
994 if (min_vddc == 0 || min_vddc > 2000
995 || min_vddc > dep_sclk_table->entries[0].vddc)
996 min_vddc = dep_sclk_table->entries[0].vddc;
998 if (max_vddc == 0 || max_vddc > 2000
999 || max_vddc < dep_sclk_table->entries[dep_sclk_table->count-1].vddc)
1000 max_vddc = dep_sclk_table->entries[dep_sclk_table->count-1].vddc;
1002 data->odn_dpm_table.min_vddc = min_vddc;
1003 data->odn_dpm_table.max_vddc = max_vddc;
1006 static void smu7_check_dpm_table_updated(struct pp_hwmgr *hwmgr)
1008 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1009 struct smu7_odn_dpm_table *odn_table = &(data->odn_dpm_table);
1010 struct phm_ppt_v1_information *table_info =
1011 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1014 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table;
1015 struct phm_ppt_v1_clock_voltage_dependency_table *odn_dep_table;
1017 if (table_info == NULL)
1020 for (i = 0; i < data->dpm_table.sclk_table.count; i++) {
1021 if (odn_table->odn_core_clock_dpm_levels.entries[i].clock !=
1022 data->dpm_table.sclk_table.dpm_levels[i].value) {
1023 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK;
1028 for (i = 0; i < data->dpm_table.mclk_table.count; i++) {
1029 if (odn_table->odn_memory_clock_dpm_levels.entries[i].clock !=
1030 data->dpm_table.mclk_table.dpm_levels[i].value) {
1031 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_MCLK;
1036 dep_table = table_info->vdd_dep_on_mclk;
1037 odn_dep_table = (struct phm_ppt_v1_clock_voltage_dependency_table *)&(odn_table->vdd_dependency_on_mclk);
1039 for (i = 0; i < dep_table->count; i++) {
1040 if (dep_table->entries[i].vddc != odn_dep_table->entries[i].vddc) {
1041 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_VDDC | DPMTABLE_OD_UPDATE_MCLK;
1046 dep_table = table_info->vdd_dep_on_sclk;
1047 odn_dep_table = (struct phm_ppt_v1_clock_voltage_dependency_table *)&(odn_table->vdd_dependency_on_sclk);
1048 for (i = 0; i < dep_table->count; i++) {
1049 if (dep_table->entries[i].vddc != odn_dep_table->entries[i].vddc) {
1050 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_VDDC | DPMTABLE_OD_UPDATE_SCLK;
1054 if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_VDDC) {
1055 data->need_update_smu7_dpm_table &= ~DPMTABLE_OD_UPDATE_VDDC;
1056 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK | DPMTABLE_OD_UPDATE_MCLK;
1060 static int smu7_setup_default_dpm_tables(struct pp_hwmgr *hwmgr)
1062 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1064 smu7_reset_dpm_tables(hwmgr);
1066 if (hwmgr->pp_table_version == PP_TABLE_V1)
1067 smu7_setup_dpm_tables_v1(hwmgr);
1068 else if (hwmgr->pp_table_version == PP_TABLE_V0)
1069 smu7_setup_dpm_tables_v0(hwmgr);
1071 smu7_setup_default_pcie_table(hwmgr);
1073 /* save a copy of the default DPM table */
1074 memcpy(&(data->golden_dpm_table), &(data->dpm_table),
1075 sizeof(struct smu7_dpm_table));
1077 /* initialize ODN table */
1078 if (hwmgr->od_enabled) {
1079 if (data->odn_dpm_table.max_vddc) {
1080 smu7_check_dpm_table_updated(hwmgr);
1082 smu7_setup_voltage_range_from_vbios(hwmgr);
1083 smu7_odn_initial_default_setting(hwmgr);
1089 static int smu7_enable_vrhot_gpio_interrupt(struct pp_hwmgr *hwmgr)
1092 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1093 PHM_PlatformCaps_RegulatorHot))
1094 return smum_send_msg_to_smc(hwmgr,
1095 PPSMC_MSG_EnableVRHotGPIOInterrupt,
1101 static int smu7_enable_sclk_control(struct pp_hwmgr *hwmgr)
1103 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
1104 SCLK_PWRMGT_OFF, 0);
1108 static int smu7_enable_ulv(struct pp_hwmgr *hwmgr)
1110 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1112 if (data->ulv_supported)
1113 return smum_send_msg_to_smc(hwmgr, PPSMC_MSG_EnableULV, NULL);
1118 static int smu7_disable_ulv(struct pp_hwmgr *hwmgr)
1120 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1122 if (data->ulv_supported)
1123 return smum_send_msg_to_smc(hwmgr, PPSMC_MSG_DisableULV, NULL);
1128 static int smu7_enable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
1130 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1131 PHM_PlatformCaps_SclkDeepSleep)) {
1132 if (smum_send_msg_to_smc(hwmgr, PPSMC_MSG_MASTER_DeepSleep_ON, NULL))
1133 PP_ASSERT_WITH_CODE(false,
1134 "Attempt to enable Master Deep Sleep switch failed!",
1137 if (smum_send_msg_to_smc(hwmgr,
1138 PPSMC_MSG_MASTER_DeepSleep_OFF,
1140 PP_ASSERT_WITH_CODE(false,
1141 "Attempt to disable Master Deep Sleep switch failed!",
1149 static int smu7_disable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
1151 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1152 PHM_PlatformCaps_SclkDeepSleep)) {
1153 if (smum_send_msg_to_smc(hwmgr,
1154 PPSMC_MSG_MASTER_DeepSleep_OFF,
1156 PP_ASSERT_WITH_CODE(false,
1157 "Attempt to disable Master Deep Sleep switch failed!",
1165 static int smu7_disable_sclk_vce_handshake(struct pp_hwmgr *hwmgr)
1167 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1168 uint32_t soft_register_value = 0;
1169 uint32_t handshake_disables_offset = data->soft_regs_start
1170 + smum_get_offsetof(hwmgr,
1171 SMU_SoftRegisters, HandshakeDisables);
1173 soft_register_value = cgs_read_ind_register(hwmgr->device,
1174 CGS_IND_REG__SMC, handshake_disables_offset);
1175 soft_register_value |= SMU7_VCE_SCLK_HANDSHAKE_DISABLE;
1176 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1177 handshake_disables_offset, soft_register_value);
1181 static int smu7_disable_handshake_uvd(struct pp_hwmgr *hwmgr)
1183 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1184 uint32_t soft_register_value = 0;
1185 uint32_t handshake_disables_offset = data->soft_regs_start
1186 + smum_get_offsetof(hwmgr,
1187 SMU_SoftRegisters, HandshakeDisables);
1189 soft_register_value = cgs_read_ind_register(hwmgr->device,
1190 CGS_IND_REG__SMC, handshake_disables_offset);
1191 soft_register_value |= smum_get_mac_definition(hwmgr,
1192 SMU_UVD_MCLK_HANDSHAKE_DISABLE);
1193 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1194 handshake_disables_offset, soft_register_value);
1198 static int smu7_enable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
1200 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1202 /* enable SCLK dpm */
1203 if (!data->sclk_dpm_key_disabled) {
1204 if (hwmgr->chip_id >= CHIP_POLARIS10 &&
1205 hwmgr->chip_id <= CHIP_VEGAM)
1206 smu7_disable_sclk_vce_handshake(hwmgr);
1208 PP_ASSERT_WITH_CODE(
1209 (0 == smum_send_msg_to_smc(hwmgr, PPSMC_MSG_DPM_Enable, NULL)),
1210 "Failed to enable SCLK DPM during DPM Start Function!",
1214 /* enable MCLK dpm */
1215 if (0 == data->mclk_dpm_key_disabled) {
1216 if (!(hwmgr->feature_mask & PP_UVD_HANDSHAKE_MASK))
1217 smu7_disable_handshake_uvd(hwmgr);
1219 PP_ASSERT_WITH_CODE(
1220 (0 == smum_send_msg_to_smc(hwmgr,
1221 PPSMC_MSG_MCLKDPM_Enable,
1223 "Failed to enable MCLK DPM during DPM Start Function!",
1226 if ((hwmgr->chip_family == AMDGPU_FAMILY_CI) ||
1227 (hwmgr->chip_id == CHIP_POLARIS10) ||
1228 (hwmgr->chip_id == CHIP_POLARIS11) ||
1229 (hwmgr->chip_id == CHIP_POLARIS12) ||
1230 (hwmgr->chip_id == CHIP_TONGA) ||
1231 (hwmgr->chip_id == CHIP_TOPAZ))
1232 PHM_WRITE_FIELD(hwmgr->device, MC_SEQ_CNTL_3, CAC_EN, 0x1);
1235 if (hwmgr->chip_family == AMDGPU_FAMILY_CI) {
1236 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, 0xc0400d30, 0x5);
1237 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, 0xc0400d3c, 0x5);
1238 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, 0xc0400d80, 0x100005);
1240 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, 0xc0400d30, 0x400005);
1241 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, 0xc0400d3c, 0x400005);
1242 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, 0xc0400d80, 0x500005);
1244 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC0_CNTL, 0x5);
1245 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC1_CNTL, 0x5);
1246 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_CPL_CNTL, 0x100005);
1248 if (hwmgr->chip_id == CHIP_VEGAM) {
1249 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC0_CNTL, 0x400009);
1250 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC1_CNTL, 0x400009);
1252 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC0_CNTL, 0x400005);
1253 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC1_CNTL, 0x400005);
1255 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_CPL_CNTL, 0x500005);
1262 static int smu7_start_dpm(struct pp_hwmgr *hwmgr)
1264 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1266 /*enable general power management */
1268 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
1269 GLOBAL_PWRMGT_EN, 1);
1271 /* enable sclk deep sleep */
1273 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
1276 /* prepare for PCIE DPM */
1278 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1279 data->soft_regs_start +
1280 smum_get_offsetof(hwmgr, SMU_SoftRegisters,
1281 VoltageChangeTimeout), 0x1000);
1282 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE,
1283 SWRST_COMMAND_1, RESETLC, 0x0);
1285 if (hwmgr->chip_family == AMDGPU_FAMILY_CI)
1286 cgs_write_register(hwmgr->device, 0x1488,
1287 (cgs_read_register(hwmgr->device, 0x1488) & ~0x1));
1289 if (smu7_enable_sclk_mclk_dpm(hwmgr)) {
1290 pr_err("Failed to enable Sclk DPM and Mclk DPM!");
1294 /* enable PCIE dpm */
1295 if (0 == data->pcie_dpm_key_disabled) {
1296 PP_ASSERT_WITH_CODE(
1297 (0 == smum_send_msg_to_smc(hwmgr,
1298 PPSMC_MSG_PCIeDPM_Enable,
1300 "Failed to enable pcie DPM during DPM Start Function!",
1303 PP_ASSERT_WITH_CODE(
1304 (0 == smum_send_msg_to_smc(hwmgr,
1305 PPSMC_MSG_PCIeDPM_Disable,
1307 "Failed to disable pcie DPM during DPM Start Function!",
1311 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1312 PHM_PlatformCaps_Falcon_QuickTransition)) {
1313 PP_ASSERT_WITH_CODE((0 == smum_send_msg_to_smc(hwmgr,
1314 PPSMC_MSG_EnableACDCGPIOInterrupt,
1316 "Failed to enable AC DC GPIO Interrupt!",
1323 static int smu7_disable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
1325 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1327 /* disable SCLK dpm */
1328 if (!data->sclk_dpm_key_disabled) {
1329 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
1330 "Trying to disable SCLK DPM when DPM is disabled",
1332 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_DPM_Disable, NULL);
1335 /* disable MCLK dpm */
1336 if (!data->mclk_dpm_key_disabled) {
1337 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
1338 "Trying to disable MCLK DPM when DPM is disabled",
1340 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_MCLKDPM_Disable, NULL);
1346 static int smu7_stop_dpm(struct pp_hwmgr *hwmgr)
1348 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1350 /* disable general power management */
1351 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
1352 GLOBAL_PWRMGT_EN, 0);
1353 /* disable sclk deep sleep */
1354 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
1357 /* disable PCIE dpm */
1358 if (!data->pcie_dpm_key_disabled) {
1359 PP_ASSERT_WITH_CODE(
1360 (smum_send_msg_to_smc(hwmgr,
1361 PPSMC_MSG_PCIeDPM_Disable,
1363 "Failed to disable pcie DPM during DPM Stop Function!",
1367 smu7_disable_sclk_mclk_dpm(hwmgr);
1369 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
1370 "Trying to disable voltage DPM when DPM is disabled",
1373 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_Voltage_Cntl_Disable, NULL);
1378 static void smu7_set_dpm_event_sources(struct pp_hwmgr *hwmgr, uint32_t sources)
1381 enum DPM_EVENT_SRC src;
1385 pr_err("Unknown throttling event sources.");
1391 case (1 << PHM_AutoThrottleSource_Thermal):
1393 src = DPM_EVENT_SRC_DIGITAL;
1395 case (1 << PHM_AutoThrottleSource_External):
1397 src = DPM_EVENT_SRC_EXTERNAL;
1399 case (1 << PHM_AutoThrottleSource_External) |
1400 (1 << PHM_AutoThrottleSource_Thermal):
1402 src = DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL;
1405 /* Order matters - don't enable thermal protection for the wrong source. */
1407 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_THERMAL_CTRL,
1408 DPM_EVENT_SRC, src);
1409 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
1410 THERMAL_PROTECTION_DIS,
1411 !phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1412 PHM_PlatformCaps_ThermalController));
1414 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
1415 THERMAL_PROTECTION_DIS, 1);
1418 static int smu7_enable_auto_throttle_source(struct pp_hwmgr *hwmgr,
1419 PHM_AutoThrottleSource source)
1421 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1423 if (!(data->active_auto_throttle_sources & (1 << source))) {
1424 data->active_auto_throttle_sources |= 1 << source;
1425 smu7_set_dpm_event_sources(hwmgr, data->active_auto_throttle_sources);
1430 static int smu7_enable_thermal_auto_throttle(struct pp_hwmgr *hwmgr)
1432 return smu7_enable_auto_throttle_source(hwmgr, PHM_AutoThrottleSource_Thermal);
1435 static int smu7_disable_auto_throttle_source(struct pp_hwmgr *hwmgr,
1436 PHM_AutoThrottleSource source)
1438 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1440 if (data->active_auto_throttle_sources & (1 << source)) {
1441 data->active_auto_throttle_sources &= ~(1 << source);
1442 smu7_set_dpm_event_sources(hwmgr, data->active_auto_throttle_sources);
1447 static int smu7_disable_thermal_auto_throttle(struct pp_hwmgr *hwmgr)
1449 return smu7_disable_auto_throttle_source(hwmgr, PHM_AutoThrottleSource_Thermal);
1452 static int smu7_pcie_performance_request(struct pp_hwmgr *hwmgr)
1454 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1455 data->pcie_performance_request = true;
1460 static int smu7_program_edc_didt_registers(struct pp_hwmgr *hwmgr,
1461 uint32_t *cac_config_regs,
1462 AtomCtrl_EDCLeakgeTable *edc_leakage_table)
1464 uint32_t data, i = 0;
1466 while (cac_config_regs[i] != 0xFFFFFFFF) {
1467 data = edc_leakage_table->DIDT_REG[i];
1468 cgs_write_ind_register(hwmgr->device,
1478 static int smu7_populate_edc_leakage_registers(struct pp_hwmgr *hwmgr)
1480 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1483 if (!data->disable_edc_leakage_controller &&
1484 data->edc_hilo_leakage_offset_from_vbios.usEdcDidtLoDpm7TableOffset &&
1485 data->edc_hilo_leakage_offset_from_vbios.usEdcDidtHiDpm7TableOffset) {
1486 ret = smu7_program_edc_didt_registers(hwmgr,
1488 &data->edc_leakage_table);
1492 ret = smum_send_msg_to_smc(hwmgr,
1493 (PPSMC_Msg)PPSMC_MSG_EnableEDCController,
1496 ret = smum_send_msg_to_smc(hwmgr,
1497 (PPSMC_Msg)PPSMC_MSG_DisableEDCController,
1504 static int smu7_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
1509 if (smu7_voltage_control(hwmgr)) {
1510 tmp_result = smu7_enable_voltage_control(hwmgr);
1511 PP_ASSERT_WITH_CODE(tmp_result == 0,
1512 "Failed to enable voltage control!",
1513 result = tmp_result);
1515 tmp_result = smu7_construct_voltage_tables(hwmgr);
1516 PP_ASSERT_WITH_CODE((0 == tmp_result),
1517 "Failed to construct voltage tables!",
1518 result = tmp_result);
1520 smum_initialize_mc_reg_table(hwmgr);
1522 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1523 PHM_PlatformCaps_EngineSpreadSpectrumSupport))
1524 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1525 GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, 1);
1527 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1528 PHM_PlatformCaps_ThermalController))
1529 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1530 GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, 0);
1532 tmp_result = smu7_program_static_screen_threshold_parameters(hwmgr);
1533 PP_ASSERT_WITH_CODE((0 == tmp_result),
1534 "Failed to program static screen threshold parameters!",
1535 result = tmp_result);
1537 tmp_result = smu7_enable_display_gap(hwmgr);
1538 PP_ASSERT_WITH_CODE((0 == tmp_result),
1539 "Failed to enable display gap!", result = tmp_result);
1541 tmp_result = smu7_program_voting_clients(hwmgr);
1542 PP_ASSERT_WITH_CODE((0 == tmp_result),
1543 "Failed to program voting clients!", result = tmp_result);
1545 tmp_result = smum_process_firmware_header(hwmgr);
1546 PP_ASSERT_WITH_CODE((0 == tmp_result),
1547 "Failed to process firmware header!", result = tmp_result);
1549 if (hwmgr->chip_id != CHIP_VEGAM) {
1550 tmp_result = smu7_initial_switch_from_arbf0_to_f1(hwmgr);
1551 PP_ASSERT_WITH_CODE((0 == tmp_result),
1552 "Failed to initialize switch from ArbF0 to F1!",
1553 result = tmp_result);
1556 result = smu7_setup_default_dpm_tables(hwmgr);
1557 PP_ASSERT_WITH_CODE(0 == result,
1558 "Failed to setup default DPM tables!", return result);
1560 tmp_result = smum_init_smc_table(hwmgr);
1561 PP_ASSERT_WITH_CODE((0 == tmp_result),
1562 "Failed to initialize SMC table!", result = tmp_result);
1564 tmp_result = smu7_enable_vrhot_gpio_interrupt(hwmgr);
1565 PP_ASSERT_WITH_CODE((0 == tmp_result),
1566 "Failed to enable VR hot GPIO interrupt!", result = tmp_result);
1568 if (hwmgr->chip_id >= CHIP_POLARIS10 &&
1569 hwmgr->chip_id <= CHIP_VEGAM) {
1570 tmp_result = smu7_notify_has_display(hwmgr);
1571 PP_ASSERT_WITH_CODE((0 == tmp_result),
1572 "Failed to enable display setting!", result = tmp_result);
1574 smum_send_msg_to_smc(hwmgr, (PPSMC_Msg)PPSMC_NoDisplay, NULL);
1577 if (hwmgr->chip_id >= CHIP_POLARIS10 &&
1578 hwmgr->chip_id <= CHIP_VEGAM) {
1579 tmp_result = smu7_populate_edc_leakage_registers(hwmgr);
1580 PP_ASSERT_WITH_CODE((0 == tmp_result),
1581 "Failed to populate edc leakage registers!", result = tmp_result);
1584 tmp_result = smu7_enable_sclk_control(hwmgr);
1585 PP_ASSERT_WITH_CODE((0 == tmp_result),
1586 "Failed to enable SCLK control!", result = tmp_result);
1588 tmp_result = smu7_enable_smc_voltage_controller(hwmgr);
1589 PP_ASSERT_WITH_CODE((0 == tmp_result),
1590 "Failed to enable voltage control!", result = tmp_result);
1592 tmp_result = smu7_enable_ulv(hwmgr);
1593 PP_ASSERT_WITH_CODE((0 == tmp_result),
1594 "Failed to enable ULV!", result = tmp_result);
1596 tmp_result = smu7_enable_deep_sleep_master_switch(hwmgr);
1597 PP_ASSERT_WITH_CODE((0 == tmp_result),
1598 "Failed to enable deep sleep master switch!", result = tmp_result);
1600 tmp_result = smu7_enable_didt_config(hwmgr);
1601 PP_ASSERT_WITH_CODE((tmp_result == 0),
1602 "Failed to enable deep sleep master switch!", result = tmp_result);
1604 tmp_result = smu7_start_dpm(hwmgr);
1605 PP_ASSERT_WITH_CODE((0 == tmp_result),
1606 "Failed to start DPM!", result = tmp_result);
1608 tmp_result = smu7_enable_smc_cac(hwmgr);
1609 PP_ASSERT_WITH_CODE((0 == tmp_result),
1610 "Failed to enable SMC CAC!", result = tmp_result);
1612 tmp_result = smu7_enable_power_containment(hwmgr);
1613 PP_ASSERT_WITH_CODE((0 == tmp_result),
1614 "Failed to enable power containment!", result = tmp_result);
1616 tmp_result = smu7_power_control_set_level(hwmgr);
1617 PP_ASSERT_WITH_CODE((0 == tmp_result),
1618 "Failed to power control set level!", result = tmp_result);
1620 tmp_result = smu7_enable_thermal_auto_throttle(hwmgr);
1621 PP_ASSERT_WITH_CODE((0 == tmp_result),
1622 "Failed to enable thermal auto throttle!", result = tmp_result);
1624 tmp_result = smu7_pcie_performance_request(hwmgr);
1625 PP_ASSERT_WITH_CODE((0 == tmp_result),
1626 "pcie performance request failed!", result = tmp_result);
1631 static int smu7_avfs_control(struct pp_hwmgr *hwmgr, bool enable)
1633 if (!hwmgr->avfs_supported)
1637 if (!PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device,
1638 CGS_IND_REG__SMC, FEATURE_STATUS, AVS_ON)) {
1639 PP_ASSERT_WITH_CODE(!smum_send_msg_to_smc(
1640 hwmgr, PPSMC_MSG_EnableAvfs, NULL),
1641 "Failed to enable AVFS!",
1644 } else if (PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device,
1645 CGS_IND_REG__SMC, FEATURE_STATUS, AVS_ON)) {
1646 PP_ASSERT_WITH_CODE(!smum_send_msg_to_smc(
1647 hwmgr, PPSMC_MSG_DisableAvfs, NULL),
1648 "Failed to disable AVFS!",
1655 static int smu7_update_avfs(struct pp_hwmgr *hwmgr)
1657 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1659 if (!hwmgr->avfs_supported)
1662 if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_VDDC) {
1663 smu7_avfs_control(hwmgr, false);
1664 } else if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_SCLK) {
1665 smu7_avfs_control(hwmgr, false);
1666 smu7_avfs_control(hwmgr, true);
1668 smu7_avfs_control(hwmgr, true);
1674 static int smu7_disable_dpm_tasks(struct pp_hwmgr *hwmgr)
1676 int tmp_result, result = 0;
1678 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1679 PHM_PlatformCaps_ThermalController))
1680 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1681 GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, 1);
1683 tmp_result = smu7_disable_power_containment(hwmgr);
1684 PP_ASSERT_WITH_CODE((tmp_result == 0),
1685 "Failed to disable power containment!", result = tmp_result);
1687 tmp_result = smu7_disable_smc_cac(hwmgr);
1688 PP_ASSERT_WITH_CODE((tmp_result == 0),
1689 "Failed to disable SMC CAC!", result = tmp_result);
1691 tmp_result = smu7_disable_didt_config(hwmgr);
1692 PP_ASSERT_WITH_CODE((tmp_result == 0),
1693 "Failed to disable DIDT!", result = tmp_result);
1695 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1696 CG_SPLL_SPREAD_SPECTRUM, SSEN, 0);
1697 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1698 GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, 0);
1700 tmp_result = smu7_disable_thermal_auto_throttle(hwmgr);
1701 PP_ASSERT_WITH_CODE((tmp_result == 0),
1702 "Failed to disable thermal auto throttle!", result = tmp_result);
1704 tmp_result = smu7_avfs_control(hwmgr, false);
1705 PP_ASSERT_WITH_CODE((tmp_result == 0),
1706 "Failed to disable AVFS!", result = tmp_result);
1708 tmp_result = smu7_stop_dpm(hwmgr);
1709 PP_ASSERT_WITH_CODE((tmp_result == 0),
1710 "Failed to stop DPM!", result = tmp_result);
1712 tmp_result = smu7_disable_deep_sleep_master_switch(hwmgr);
1713 PP_ASSERT_WITH_CODE((tmp_result == 0),
1714 "Failed to disable deep sleep master switch!", result = tmp_result);
1716 tmp_result = smu7_disable_ulv(hwmgr);
1717 PP_ASSERT_WITH_CODE((tmp_result == 0),
1718 "Failed to disable ULV!", result = tmp_result);
1720 tmp_result = smu7_clear_voting_clients(hwmgr);
1721 PP_ASSERT_WITH_CODE((tmp_result == 0),
1722 "Failed to clear voting clients!", result = tmp_result);
1724 tmp_result = smu7_reset_to_default(hwmgr);
1725 PP_ASSERT_WITH_CODE((tmp_result == 0),
1726 "Failed to reset to default!", result = tmp_result);
1728 tmp_result = smum_stop_smc(hwmgr);
1729 PP_ASSERT_WITH_CODE((tmp_result == 0),
1730 "Failed to stop smc!", result = tmp_result);
1732 tmp_result = smu7_force_switch_to_arbf0(hwmgr);
1733 PP_ASSERT_WITH_CODE((tmp_result == 0),
1734 "Failed to force to switch arbf0!", result = tmp_result);
1739 static bool intel_core_rkl_chk(void)
1741 #if IS_ENABLED(CONFIG_X86_64)
1742 struct cpuinfo_x86 *c = &cpu_data(0);
1744 return (c->x86 == 6 && c->x86_model == INTEL_FAM6_ROCKETLAKE);
1750 static void smu7_init_dpm_defaults(struct pp_hwmgr *hwmgr)
1752 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1753 struct phm_ppt_v1_information *table_info =
1754 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1755 struct amdgpu_device *adev = hwmgr->adev;
1759 data->dll_default_on = false;
1760 data->mclk_dpm0_activity_target = 0xa;
1761 data->vddc_vddgfx_delta = 300;
1762 data->static_screen_threshold = SMU7_STATICSCREENTHRESHOLD_DFLT;
1763 data->static_screen_threshold_unit = SMU7_STATICSCREENTHRESHOLDUNIT_DFLT;
1764 data->voting_rights_clients[0] = SMU7_VOTINGRIGHTSCLIENTS_DFLT0;
1765 data->voting_rights_clients[1]= SMU7_VOTINGRIGHTSCLIENTS_DFLT1;
1766 data->voting_rights_clients[2] = SMU7_VOTINGRIGHTSCLIENTS_DFLT2;
1767 data->voting_rights_clients[3]= SMU7_VOTINGRIGHTSCLIENTS_DFLT3;
1768 data->voting_rights_clients[4]= SMU7_VOTINGRIGHTSCLIENTS_DFLT4;
1769 data->voting_rights_clients[5]= SMU7_VOTINGRIGHTSCLIENTS_DFLT5;
1770 data->voting_rights_clients[6]= SMU7_VOTINGRIGHTSCLIENTS_DFLT6;
1771 data->voting_rights_clients[7]= SMU7_VOTINGRIGHTSCLIENTS_DFLT7;
1773 data->mclk_dpm_key_disabled = hwmgr->feature_mask & PP_MCLK_DPM_MASK ? false : true;
1774 data->sclk_dpm_key_disabled = hwmgr->feature_mask & PP_SCLK_DPM_MASK ? false : true;
1775 data->pcie_dpm_key_disabled =
1776 intel_core_rkl_chk() || !(hwmgr->feature_mask & PP_PCIE_DPM_MASK);
1777 /* need to set voltage control types before EVV patching */
1778 data->voltage_control = SMU7_VOLTAGE_CONTROL_NONE;
1779 data->vddci_control = SMU7_VOLTAGE_CONTROL_NONE;
1780 data->mvdd_control = SMU7_VOLTAGE_CONTROL_NONE;
1781 data->enable_tdc_limit_feature = true;
1782 data->enable_pkg_pwr_tracking_feature = true;
1783 data->force_pcie_gen = PP_PCIEGenInvalid;
1784 data->ulv_supported = hwmgr->feature_mask & PP_ULV_MASK ? true : false;
1785 data->current_profile_setting.bupdate_sclk = 1;
1786 data->current_profile_setting.sclk_up_hyst = 0;
1787 data->current_profile_setting.sclk_down_hyst = 100;
1788 data->current_profile_setting.sclk_activity = SMU7_SCLK_TARGETACTIVITY_DFLT;
1789 data->current_profile_setting.bupdate_mclk = 1;
1790 if (hwmgr->chip_id >= CHIP_POLARIS10) {
1791 if (adev->gmc.vram_width == 256) {
1792 data->current_profile_setting.mclk_up_hyst = 10;
1793 data->current_profile_setting.mclk_down_hyst = 60;
1794 data->current_profile_setting.mclk_activity = 25;
1795 } else if (adev->gmc.vram_width == 128) {
1796 data->current_profile_setting.mclk_up_hyst = 5;
1797 data->current_profile_setting.mclk_down_hyst = 16;
1798 data->current_profile_setting.mclk_activity = 20;
1799 } else if (adev->gmc.vram_width == 64) {
1800 data->current_profile_setting.mclk_up_hyst = 3;
1801 data->current_profile_setting.mclk_down_hyst = 16;
1802 data->current_profile_setting.mclk_activity = 20;
1805 data->current_profile_setting.mclk_up_hyst = 0;
1806 data->current_profile_setting.mclk_down_hyst = 100;
1807 data->current_profile_setting.mclk_activity = SMU7_MCLK_TARGETACTIVITY_DFLT;
1809 hwmgr->workload_mask = 1 << hwmgr->workload_prority[PP_SMC_POWER_PROFILE_FULLSCREEN3D];
1810 hwmgr->power_profile_mode = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
1811 hwmgr->default_power_profile_mode = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
1813 if (hwmgr->chip_id == CHIP_HAWAII) {
1814 data->thermal_temp_setting.temperature_low = 94500;
1815 data->thermal_temp_setting.temperature_high = 95000;
1816 data->thermal_temp_setting.temperature_shutdown = 104000;
1818 data->thermal_temp_setting.temperature_low = 99500;
1819 data->thermal_temp_setting.temperature_high = 100000;
1820 data->thermal_temp_setting.temperature_shutdown = 104000;
1823 data->fast_watermark_threshold = 100;
1824 if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1825 VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_SVID2))
1826 data->voltage_control = SMU7_VOLTAGE_CONTROL_BY_SVID2;
1827 else if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1828 VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_GPIO_LUT))
1829 data->voltage_control = SMU7_VOLTAGE_CONTROL_BY_GPIO;
1831 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1832 PHM_PlatformCaps_ControlVDDGFX)) {
1833 if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1834 VOLTAGE_TYPE_VDDGFX, VOLTAGE_OBJ_SVID2)) {
1835 data->vdd_gfx_control = SMU7_VOLTAGE_CONTROL_BY_SVID2;
1839 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1840 PHM_PlatformCaps_EnableMVDDControl)) {
1841 if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1842 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT))
1843 data->mvdd_control = SMU7_VOLTAGE_CONTROL_BY_GPIO;
1844 else if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1845 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_SVID2))
1846 data->mvdd_control = SMU7_VOLTAGE_CONTROL_BY_SVID2;
1849 if (SMU7_VOLTAGE_CONTROL_NONE == data->vdd_gfx_control)
1850 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1851 PHM_PlatformCaps_ControlVDDGFX);
1853 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1854 PHM_PlatformCaps_ControlVDDCI)) {
1855 if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1856 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT))
1857 data->vddci_control = SMU7_VOLTAGE_CONTROL_BY_GPIO;
1858 else if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1859 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_SVID2))
1860 data->vddci_control = SMU7_VOLTAGE_CONTROL_BY_SVID2;
1863 if (data->mvdd_control == SMU7_VOLTAGE_CONTROL_NONE)
1864 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1865 PHM_PlatformCaps_EnableMVDDControl);
1867 if (data->vddci_control == SMU7_VOLTAGE_CONTROL_NONE)
1868 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1869 PHM_PlatformCaps_ControlVDDCI);
1871 data->vddc_phase_shed_control = 1;
1872 if ((hwmgr->chip_id == CHIP_POLARIS12) ||
1873 ASICID_IS_P20(adev->pdev->device, adev->pdev->revision) ||
1874 ASICID_IS_P21(adev->pdev->device, adev->pdev->revision) ||
1875 ASICID_IS_P30(adev->pdev->device, adev->pdev->revision) ||
1876 ASICID_IS_P31(adev->pdev->device, adev->pdev->revision)) {
1877 if (data->voltage_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
1878 atomctrl_get_svi2_info(hwmgr, VOLTAGE_TYPE_VDDC, &tmp1, &tmp2,
1880 tmp3 = (tmp3 >> 5) & 0x3;
1881 data->vddc_phase_shed_control = ((tmp3 << 1) | (tmp3 >> 1)) & 0x3;
1883 } else if (hwmgr->chip_family == AMDGPU_FAMILY_CI) {
1884 data->vddc_phase_shed_control = 1;
1887 if ((hwmgr->pp_table_version != PP_TABLE_V0) && (hwmgr->feature_mask & PP_CLOCK_STRETCH_MASK)
1888 && (table_info->cac_dtp_table->usClockStretchAmount != 0))
1889 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
1890 PHM_PlatformCaps_ClockStretcher);
1892 data->pcie_gen_performance.max = PP_PCIEGen1;
1893 data->pcie_gen_performance.min = PP_PCIEGen3;
1894 data->pcie_gen_power_saving.max = PP_PCIEGen1;
1895 data->pcie_gen_power_saving.min = PP_PCIEGen3;
1896 data->pcie_lane_performance.max = 0;
1897 data->pcie_lane_performance.min = 16;
1898 data->pcie_lane_power_saving.max = 0;
1899 data->pcie_lane_power_saving.min = 16;
1902 if (adev->pg_flags & AMD_PG_SUPPORT_UVD)
1903 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
1904 PHM_PlatformCaps_UVDPowerGating);
1905 if (adev->pg_flags & AMD_PG_SUPPORT_VCE)
1906 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
1907 PHM_PlatformCaps_VCEPowerGating);
1909 data->disable_edc_leakage_controller = true;
1910 if (((adev->asic_type == CHIP_POLARIS10) && hwmgr->is_kicker) ||
1911 ((adev->asic_type == CHIP_POLARIS11) && hwmgr->is_kicker) ||
1912 (adev->asic_type == CHIP_POLARIS12) ||
1913 (adev->asic_type == CHIP_VEGAM))
1914 data->disable_edc_leakage_controller = false;
1916 if (!atomctrl_is_asic_internal_ss_supported(hwmgr)) {
1917 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1918 PHM_PlatformCaps_MemorySpreadSpectrumSupport);
1919 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1920 PHM_PlatformCaps_EngineSpreadSpectrumSupport);
1923 if ((adev->pdev->device == 0x699F) &&
1924 (adev->pdev->revision == 0xCF)) {
1925 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1926 PHM_PlatformCaps_PowerContainment);
1927 data->enable_tdc_limit_feature = false;
1928 data->enable_pkg_pwr_tracking_feature = false;
1929 data->disable_edc_leakage_controller = true;
1930 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1931 PHM_PlatformCaps_ClockStretcher);
1935 static int smu7_calculate_ro_range(struct pp_hwmgr *hwmgr)
1937 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1938 struct amdgpu_device *adev = hwmgr->adev;
1939 uint32_t asicrev1, evv_revision, max = 0, min = 0;
1941 atomctrl_read_efuse(hwmgr, STRAP_EVV_REVISION_LSB, STRAP_EVV_REVISION_MSB,
1944 atomctrl_read_efuse(hwmgr, 568, 579, &asicrev1);
1946 if (ASICID_IS_P20(adev->pdev->device, adev->pdev->revision) ||
1947 ASICID_IS_P30(adev->pdev->device, adev->pdev->revision)) {
1950 } else if (ASICID_IS_P21(adev->pdev->device, adev->pdev->revision) ||
1951 ASICID_IS_P31(adev->pdev->device, adev->pdev->revision)) {
1954 } else if (hwmgr->chip_id == CHIP_POLARIS10) {
1955 if (adev->pdev->subsystem_vendor == 0x106B) {
1959 if (evv_revision == 0) {
1962 } else if (evv_revision == 1) {
1963 if (asicrev1 == 326) {
1966 /* TODO: PATCH RO in VBIOS */
1971 } else if (evv_revision == 2) {
1981 data->ro_range_minimum = min;
1982 data->ro_range_maximum = max;
1984 /* TODO: PATCH RO in VBIOS here */
1990 * smu7_get_evv_voltages - Get Leakage VDDC based on leakage ID.
1992 * @hwmgr: the address of the powerplay hardware manager.
1995 static int smu7_get_evv_voltages(struct pp_hwmgr *hwmgr)
1997 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2000 uint16_t vddgfx = 0;
2003 struct phm_ppt_v1_information *table_info =
2004 (struct phm_ppt_v1_information *)hwmgr->pptable;
2005 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table = NULL;
2007 if (hwmgr->chip_id == CHIP_POLARIS10 ||
2008 hwmgr->chip_id == CHIP_POLARIS11 ||
2009 hwmgr->chip_id == CHIP_POLARIS12)
2010 smu7_calculate_ro_range(hwmgr);
2012 for (i = 0; i < SMU7_MAX_LEAKAGE_COUNT; i++) {
2013 vv_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i;
2015 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
2016 if ((hwmgr->pp_table_version == PP_TABLE_V1)
2017 && !phm_get_sclk_for_voltage_evv(hwmgr,
2018 table_info->vddgfx_lookup_table, vv_id, &sclk)) {
2019 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2020 PHM_PlatformCaps_ClockStretcher)) {
2021 sclk_table = table_info->vdd_dep_on_sclk;
2023 for (j = 1; j < sclk_table->count; j++) {
2024 if (sclk_table->entries[j].clk == sclk &&
2025 sclk_table->entries[j].cks_enable == 0) {
2031 if (0 == atomctrl_get_voltage_evv_on_sclk
2032 (hwmgr, VOLTAGE_TYPE_VDDGFX, sclk,
2034 /* need to make sure vddgfx is less than 2v or else, it could burn the ASIC. */
2035 PP_ASSERT_WITH_CODE((vddgfx < 2000 && vddgfx != 0), "Invalid VDDGFX value!", return -EINVAL);
2037 /* the voltage should not be zero nor equal to leakage ID */
2038 if (vddgfx != 0 && vddgfx != vv_id) {
2039 data->vddcgfx_leakage.actual_voltage[data->vddcgfx_leakage.count] = vddgfx;
2040 data->vddcgfx_leakage.leakage_id[data->vddcgfx_leakage.count] = vv_id;
2041 data->vddcgfx_leakage.count++;
2044 pr_info("Error retrieving EVV voltage value!\n");
2048 if ((hwmgr->pp_table_version == PP_TABLE_V0)
2049 || !phm_get_sclk_for_voltage_evv(hwmgr,
2050 table_info->vddc_lookup_table, vv_id, &sclk)) {
2051 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2052 PHM_PlatformCaps_ClockStretcher)) {
2053 if (table_info == NULL)
2055 sclk_table = table_info->vdd_dep_on_sclk;
2057 for (j = 1; j < sclk_table->count; j++) {
2058 if (sclk_table->entries[j].clk == sclk &&
2059 sclk_table->entries[j].cks_enable == 0) {
2066 if (phm_get_voltage_evv_on_sclk(hwmgr,
2068 sclk, vv_id, &vddc) == 0) {
2069 if (vddc >= 2000 || vddc == 0)
2072 pr_debug("failed to retrieving EVV voltage!\n");
2076 /* the voltage should not be zero nor equal to leakage ID */
2077 if (vddc != 0 && vddc != vv_id) {
2078 data->vddc_leakage.actual_voltage[data->vddc_leakage.count] = (uint16_t)(vddc);
2079 data->vddc_leakage.leakage_id[data->vddc_leakage.count] = vv_id;
2080 data->vddc_leakage.count++;
2090 * smu7_patch_ppt_v1_with_vdd_leakage - Change virtual leakage voltage to actual value.
2092 * @hwmgr: the address of the powerplay hardware manager.
2093 * @voltage: pointer to changing voltage
2094 * @leakage_table: pointer to leakage table
2096 static void smu7_patch_ppt_v1_with_vdd_leakage(struct pp_hwmgr *hwmgr,
2097 uint16_t *voltage, struct smu7_leakage_voltage *leakage_table)
2101 /* search for leakage voltage ID 0xff01 ~ 0xff08 */
2102 for (index = 0; index < leakage_table->count; index++) {
2103 /* if this voltage matches a leakage voltage ID */
2104 /* patch with actual leakage voltage */
2105 if (leakage_table->leakage_id[index] == *voltage) {
2106 *voltage = leakage_table->actual_voltage[index];
2111 if (*voltage > ATOM_VIRTUAL_VOLTAGE_ID0)
2112 pr_err("Voltage value looks like a Leakage ID but it's not patched \n");
2116 * smu7_patch_lookup_table_with_leakage - Patch voltage lookup table by EVV leakages.
2118 * @hwmgr: the address of the powerplay hardware manager.
2119 * @lookup_table: pointer to voltage lookup table
2120 * @leakage_table: pointer to leakage table
2123 static int smu7_patch_lookup_table_with_leakage(struct pp_hwmgr *hwmgr,
2124 phm_ppt_v1_voltage_lookup_table *lookup_table,
2125 struct smu7_leakage_voltage *leakage_table)
2129 for (i = 0; i < lookup_table->count; i++)
2130 smu7_patch_ppt_v1_with_vdd_leakage(hwmgr,
2131 &lookup_table->entries[i].us_vdd, leakage_table);
2136 static int smu7_patch_clock_voltage_limits_with_vddc_leakage(
2137 struct pp_hwmgr *hwmgr, struct smu7_leakage_voltage *leakage_table,
2140 struct phm_ppt_v1_information *table_info =
2141 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2142 smu7_patch_ppt_v1_with_vdd_leakage(hwmgr, (uint16_t *)vddc, leakage_table);
2143 hwmgr->dyn_state.max_clock_voltage_on_dc.vddc =
2144 table_info->max_clock_voltage_on_dc.vddc;
2148 static int smu7_patch_voltage_dependency_tables_with_lookup_table(
2149 struct pp_hwmgr *hwmgr)
2153 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2154 struct phm_ppt_v1_information *table_info =
2155 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2157 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
2158 table_info->vdd_dep_on_sclk;
2159 struct phm_ppt_v1_clock_voltage_dependency_table *mclk_table =
2160 table_info->vdd_dep_on_mclk;
2161 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
2162 table_info->mm_dep_table;
2164 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
2165 for (entry_id = 0; entry_id < sclk_table->count; ++entry_id) {
2166 voltage_id = sclk_table->entries[entry_id].vddInd;
2167 sclk_table->entries[entry_id].vddgfx =
2168 table_info->vddgfx_lookup_table->entries[voltage_id].us_vdd;
2171 for (entry_id = 0; entry_id < sclk_table->count; ++entry_id) {
2172 voltage_id = sclk_table->entries[entry_id].vddInd;
2173 sclk_table->entries[entry_id].vddc =
2174 table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
2178 for (entry_id = 0; entry_id < mclk_table->count; ++entry_id) {
2179 voltage_id = mclk_table->entries[entry_id].vddInd;
2180 mclk_table->entries[entry_id].vddc =
2181 table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
2184 for (entry_id = 0; entry_id < mm_table->count; ++entry_id) {
2185 voltage_id = mm_table->entries[entry_id].vddcInd;
2186 mm_table->entries[entry_id].vddc =
2187 table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
2194 static int phm_add_voltage(struct pp_hwmgr *hwmgr,
2195 phm_ppt_v1_voltage_lookup_table *look_up_table,
2196 phm_ppt_v1_voltage_lookup_record *record)
2200 PP_ASSERT_WITH_CODE((NULL != look_up_table),
2201 "Lookup Table empty.", return -EINVAL);
2202 PP_ASSERT_WITH_CODE((0 != look_up_table->count),
2203 "Lookup Table empty.", return -EINVAL);
2205 i = smum_get_mac_definition(hwmgr, SMU_MAX_LEVELS_VDDGFX);
2206 PP_ASSERT_WITH_CODE((i >= look_up_table->count),
2207 "Lookup Table is full.", return -EINVAL);
2209 /* This is to avoid entering duplicate calculated records. */
2210 for (i = 0; i < look_up_table->count; i++) {
2211 if (look_up_table->entries[i].us_vdd == record->us_vdd) {
2212 if (look_up_table->entries[i].us_calculated == 1)
2218 look_up_table->entries[i].us_calculated = 1;
2219 look_up_table->entries[i].us_vdd = record->us_vdd;
2220 look_up_table->entries[i].us_cac_low = record->us_cac_low;
2221 look_up_table->entries[i].us_cac_mid = record->us_cac_mid;
2222 look_up_table->entries[i].us_cac_high = record->us_cac_high;
2223 /* Only increment the count when we're appending, not replacing duplicate entry. */
2224 if (i == look_up_table->count)
2225 look_up_table->count++;
2231 static int smu7_calc_voltage_dependency_tables(struct pp_hwmgr *hwmgr)
2234 struct phm_ppt_v1_voltage_lookup_record v_record;
2235 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2236 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
2238 phm_ppt_v1_clock_voltage_dependency_table *sclk_table = pptable_info->vdd_dep_on_sclk;
2239 phm_ppt_v1_clock_voltage_dependency_table *mclk_table = pptable_info->vdd_dep_on_mclk;
2241 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
2242 for (entry_id = 0; entry_id < sclk_table->count; ++entry_id) {
2243 if (sclk_table->entries[entry_id].vdd_offset & (1 << 15))
2244 v_record.us_vdd = sclk_table->entries[entry_id].vddgfx +
2245 sclk_table->entries[entry_id].vdd_offset - 0xFFFF;
2247 v_record.us_vdd = sclk_table->entries[entry_id].vddgfx +
2248 sclk_table->entries[entry_id].vdd_offset;
2250 sclk_table->entries[entry_id].vddc =
2251 v_record.us_cac_low = v_record.us_cac_mid =
2252 v_record.us_cac_high = v_record.us_vdd;
2254 phm_add_voltage(hwmgr, pptable_info->vddc_lookup_table, &v_record);
2257 for (entry_id = 0; entry_id < mclk_table->count; ++entry_id) {
2258 if (mclk_table->entries[entry_id].vdd_offset & (1 << 15))
2259 v_record.us_vdd = mclk_table->entries[entry_id].vddc +
2260 mclk_table->entries[entry_id].vdd_offset - 0xFFFF;
2262 v_record.us_vdd = mclk_table->entries[entry_id].vddc +
2263 mclk_table->entries[entry_id].vdd_offset;
2265 mclk_table->entries[entry_id].vddgfx = v_record.us_cac_low =
2266 v_record.us_cac_mid = v_record.us_cac_high = v_record.us_vdd;
2267 phm_add_voltage(hwmgr, pptable_info->vddgfx_lookup_table, &v_record);
2273 static int smu7_calc_mm_voltage_dependency_table(struct pp_hwmgr *hwmgr)
2276 struct phm_ppt_v1_voltage_lookup_record v_record;
2277 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2278 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
2279 phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table = pptable_info->mm_dep_table;
2281 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
2282 for (entry_id = 0; entry_id < mm_table->count; entry_id++) {
2283 if (mm_table->entries[entry_id].vddgfx_offset & (1 << 15))
2284 v_record.us_vdd = mm_table->entries[entry_id].vddc +
2285 mm_table->entries[entry_id].vddgfx_offset - 0xFFFF;
2287 v_record.us_vdd = mm_table->entries[entry_id].vddc +
2288 mm_table->entries[entry_id].vddgfx_offset;
2290 /* Add the calculated VDDGFX to the VDDGFX lookup table */
2291 mm_table->entries[entry_id].vddgfx = v_record.us_cac_low =
2292 v_record.us_cac_mid = v_record.us_cac_high = v_record.us_vdd;
2293 phm_add_voltage(hwmgr, pptable_info->vddgfx_lookup_table, &v_record);
2299 static int smu7_sort_lookup_table(struct pp_hwmgr *hwmgr,
2300 struct phm_ppt_v1_voltage_lookup_table *lookup_table)
2302 uint32_t table_size, i, j;
2303 table_size = lookup_table->count;
2305 PP_ASSERT_WITH_CODE(0 != lookup_table->count,
2306 "Lookup table is empty", return -EINVAL);
2308 /* Sorting voltages */
2309 for (i = 0; i < table_size - 1; i++) {
2310 for (j = i + 1; j > 0; j--) {
2311 if (lookup_table->entries[j].us_vdd <
2312 lookup_table->entries[j - 1].us_vdd) {
2313 swap(lookup_table->entries[j - 1],
2314 lookup_table->entries[j]);
2322 static int smu7_complete_dependency_tables(struct pp_hwmgr *hwmgr)
2326 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2327 struct phm_ppt_v1_information *table_info =
2328 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2330 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
2331 tmp_result = smu7_patch_lookup_table_with_leakage(hwmgr,
2332 table_info->vddgfx_lookup_table, &(data->vddcgfx_leakage));
2333 if (tmp_result != 0)
2334 result = tmp_result;
2336 smu7_patch_ppt_v1_with_vdd_leakage(hwmgr,
2337 &table_info->max_clock_voltage_on_dc.vddgfx, &(data->vddcgfx_leakage));
2340 tmp_result = smu7_patch_lookup_table_with_leakage(hwmgr,
2341 table_info->vddc_lookup_table, &(data->vddc_leakage));
2343 result = tmp_result;
2345 tmp_result = smu7_patch_clock_voltage_limits_with_vddc_leakage(hwmgr,
2346 &(data->vddc_leakage), &table_info->max_clock_voltage_on_dc.vddc);
2348 result = tmp_result;
2351 tmp_result = smu7_patch_voltage_dependency_tables_with_lookup_table(hwmgr);
2353 result = tmp_result;
2355 tmp_result = smu7_calc_voltage_dependency_tables(hwmgr);
2357 result = tmp_result;
2359 tmp_result = smu7_calc_mm_voltage_dependency_table(hwmgr);
2361 result = tmp_result;
2363 tmp_result = smu7_sort_lookup_table(hwmgr, table_info->vddgfx_lookup_table);
2365 result = tmp_result;
2367 tmp_result = smu7_sort_lookup_table(hwmgr, table_info->vddc_lookup_table);
2369 result = tmp_result;
2374 static int smu7_find_highest_vddc(struct pp_hwmgr *hwmgr)
2376 struct phm_ppt_v1_information *table_info =
2377 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2378 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_sclk_vdd_table =
2379 table_info->vdd_dep_on_sclk;
2380 struct phm_ppt_v1_voltage_lookup_table *lookup_table =
2381 table_info->vddc_lookup_table;
2382 uint16_t highest_voltage;
2385 highest_voltage = allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].vddc;
2387 for (i = 0; i < lookup_table->count; i++) {
2388 if (lookup_table->entries[i].us_vdd < ATOM_VIRTUAL_VOLTAGE_ID0 &&
2389 lookup_table->entries[i].us_vdd > highest_voltage)
2390 highest_voltage = lookup_table->entries[i].us_vdd;
2393 return highest_voltage;
2396 static int smu7_set_private_data_based_on_pptable_v1(struct pp_hwmgr *hwmgr)
2398 struct phm_ppt_v1_information *table_info =
2399 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2401 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_sclk_vdd_table =
2402 table_info->vdd_dep_on_sclk;
2403 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_mclk_vdd_table =
2404 table_info->vdd_dep_on_mclk;
2406 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table != NULL,
2407 "VDD dependency on SCLK table is missing.",
2409 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table->count >= 1,
2410 "VDD dependency on SCLK table has to have is missing.",
2413 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table != NULL,
2414 "VDD dependency on MCLK table is missing",
2416 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table->count >= 1,
2417 "VDD dependency on MCLK table has to have is missing.",
2420 table_info->max_clock_voltage_on_ac.sclk =
2421 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].clk;
2422 table_info->max_clock_voltage_on_ac.mclk =
2423 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].clk;
2424 if (hwmgr->chip_id >= CHIP_POLARIS10 && hwmgr->chip_id <= CHIP_VEGAM)
2425 table_info->max_clock_voltage_on_ac.vddc =
2426 smu7_find_highest_vddc(hwmgr);
2428 table_info->max_clock_voltage_on_ac.vddc =
2429 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].vddc;
2430 table_info->max_clock_voltage_on_ac.vddci =
2431 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].vddci;
2433 hwmgr->dyn_state.max_clock_voltage_on_ac.sclk = table_info->max_clock_voltage_on_ac.sclk;
2434 hwmgr->dyn_state.max_clock_voltage_on_ac.mclk = table_info->max_clock_voltage_on_ac.mclk;
2435 hwmgr->dyn_state.max_clock_voltage_on_ac.vddc = table_info->max_clock_voltage_on_ac.vddc;
2436 hwmgr->dyn_state.max_clock_voltage_on_ac.vddci = table_info->max_clock_voltage_on_ac.vddci;
2441 static int smu7_patch_voltage_workaround(struct pp_hwmgr *hwmgr)
2443 struct phm_ppt_v1_information *table_info =
2444 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2445 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table;
2446 struct phm_ppt_v1_voltage_lookup_table *lookup_table;
2448 uint32_t hw_revision, sub_vendor_id, sub_sys_id;
2449 struct amdgpu_device *adev = hwmgr->adev;
2451 if (table_info != NULL) {
2452 dep_mclk_table = table_info->vdd_dep_on_mclk;
2453 lookup_table = table_info->vddc_lookup_table;
2457 hw_revision = adev->pdev->revision;
2458 sub_sys_id = adev->pdev->subsystem_device;
2459 sub_vendor_id = adev->pdev->subsystem_vendor;
2461 if (adev->pdev->device == 0x67DF && hw_revision == 0xC7 &&
2462 ((sub_sys_id == 0xb37 && sub_vendor_id == 0x1002) ||
2463 (sub_sys_id == 0x4a8 && sub_vendor_id == 0x1043) ||
2464 (sub_sys_id == 0x9480 && sub_vendor_id == 0x1682))) {
2466 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device,
2472 if (lookup_table->entries[dep_mclk_table->entries[dep_mclk_table->count-1].vddInd].us_vdd >= 1000)
2475 for (i = 0; i < lookup_table->count; i++) {
2476 if (lookup_table->entries[i].us_vdd < 0xff01 && lookup_table->entries[i].us_vdd >= 1000) {
2477 dep_mclk_table->entries[dep_mclk_table->count-1].vddInd = (uint8_t) i;
2485 static int smu7_thermal_parameter_init(struct pp_hwmgr *hwmgr)
2487 struct pp_atomctrl_gpio_pin_assignment gpio_pin_assignment;
2489 struct phm_ppt_v1_information *table_info =
2490 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2493 if (atomctrl_get_pp_assign_pin(hwmgr, VDDC_PCC_GPIO_PINID, &gpio_pin_assignment)) {
2494 temp_reg = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCNB_PWRMGT_CNTL);
2495 switch (gpio_pin_assignment.uc_gpio_pin_bit_shift) {
2497 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x1);
2500 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x2);
2503 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW, 0x1);
2506 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, FORCE_NB_PS1, 0x1);
2509 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, DPM_ENABLED, 0x1);
2514 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCNB_PWRMGT_CNTL, temp_reg);
2517 if (table_info == NULL)
2520 if (table_info->cac_dtp_table->usDefaultTargetOperatingTemp != 0 &&
2521 hwmgr->thermal_controller.advanceFanControlParameters.ucFanControlMode) {
2522 hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMMinLimit =
2523 (uint16_t)hwmgr->thermal_controller.advanceFanControlParameters.ucMinimumPWMLimit;
2525 hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMMaxLimit =
2526 (uint16_t)hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanPWM;
2528 hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMStep = 1;
2530 hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMMaxLimit = 100;
2532 hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMMinLimit =
2533 (uint16_t)hwmgr->thermal_controller.advanceFanControlParameters.ucMinimumPWMLimit;
2535 hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMStep = 1;
2537 table_info->cac_dtp_table->usDefaultTargetOperatingTemp = (table_info->cac_dtp_table->usDefaultTargetOperatingTemp >= 50) ?
2538 (table_info->cac_dtp_table->usDefaultTargetOperatingTemp - 50) : 0;
2540 table_info->cac_dtp_table->usOperatingTempMaxLimit = table_info->cac_dtp_table->usDefaultTargetOperatingTemp;
2541 table_info->cac_dtp_table->usOperatingTempStep = 1;
2542 table_info->cac_dtp_table->usOperatingTempHyst = 1;
2544 hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanPWM =
2545 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanPWM;
2547 hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanRPM =
2548 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanRPM;
2550 hwmgr->dyn_state.cac_dtp_table->usOperatingTempMinLimit =
2551 table_info->cac_dtp_table->usOperatingTempMinLimit;
2553 hwmgr->dyn_state.cac_dtp_table->usOperatingTempMaxLimit =
2554 table_info->cac_dtp_table->usOperatingTempMaxLimit;
2556 hwmgr->dyn_state.cac_dtp_table->usDefaultTargetOperatingTemp =
2557 table_info->cac_dtp_table->usDefaultTargetOperatingTemp;
2559 hwmgr->dyn_state.cac_dtp_table->usOperatingTempStep =
2560 table_info->cac_dtp_table->usOperatingTempStep;
2562 hwmgr->dyn_state.cac_dtp_table->usTargetOperatingTemp =
2563 table_info->cac_dtp_table->usTargetOperatingTemp;
2564 if (hwmgr->feature_mask & PP_OD_FUZZY_FAN_CONTROL_MASK)
2565 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2566 PHM_PlatformCaps_ODFuzzyFanControlSupport);
2573 * smu7_patch_ppt_v0_with_vdd_leakage - Change virtual leakage voltage to actual value.
2575 * @hwmgr: the address of the powerplay hardware manager.
2576 * @voltage: pointer to changing voltage
2577 * @leakage_table: pointer to leakage table
2579 static void smu7_patch_ppt_v0_with_vdd_leakage(struct pp_hwmgr *hwmgr,
2580 uint32_t *voltage, struct smu7_leakage_voltage *leakage_table)
2584 /* search for leakage voltage ID 0xff01 ~ 0xff08 */
2585 for (index = 0; index < leakage_table->count; index++) {
2586 /* if this voltage matches a leakage voltage ID */
2587 /* patch with actual leakage voltage */
2588 if (leakage_table->leakage_id[index] == *voltage) {
2589 *voltage = leakage_table->actual_voltage[index];
2594 if (*voltage > ATOM_VIRTUAL_VOLTAGE_ID0)
2595 pr_err("Voltage value looks like a Leakage ID but it's not patched \n");
2599 static int smu7_patch_vddc(struct pp_hwmgr *hwmgr,
2600 struct phm_clock_voltage_dependency_table *tab)
2603 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2606 for (i = 0; i < tab->count; i++)
2607 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2608 &data->vddc_leakage);
2613 static int smu7_patch_vddci(struct pp_hwmgr *hwmgr,
2614 struct phm_clock_voltage_dependency_table *tab)
2617 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2620 for (i = 0; i < tab->count; i++)
2621 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2622 &data->vddci_leakage);
2627 static int smu7_patch_vce_vddc(struct pp_hwmgr *hwmgr,
2628 struct phm_vce_clock_voltage_dependency_table *tab)
2631 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2634 for (i = 0; i < tab->count; i++)
2635 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2636 &data->vddc_leakage);
2642 static int smu7_patch_uvd_vddc(struct pp_hwmgr *hwmgr,
2643 struct phm_uvd_clock_voltage_dependency_table *tab)
2646 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2649 for (i = 0; i < tab->count; i++)
2650 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2651 &data->vddc_leakage);
2656 static int smu7_patch_vddc_shed_limit(struct pp_hwmgr *hwmgr,
2657 struct phm_phase_shedding_limits_table *tab)
2660 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2663 for (i = 0; i < tab->count; i++)
2664 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].Voltage,
2665 &data->vddc_leakage);
2670 static int smu7_patch_samu_vddc(struct pp_hwmgr *hwmgr,
2671 struct phm_samu_clock_voltage_dependency_table *tab)
2674 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2677 for (i = 0; i < tab->count; i++)
2678 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2679 &data->vddc_leakage);
2684 static int smu7_patch_acp_vddc(struct pp_hwmgr *hwmgr,
2685 struct phm_acp_clock_voltage_dependency_table *tab)
2688 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2691 for (i = 0; i < tab->count; i++)
2692 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2693 &data->vddc_leakage);
2698 static int smu7_patch_limits_vddc(struct pp_hwmgr *hwmgr,
2699 struct phm_clock_and_voltage_limits *tab)
2701 uint32_t vddc, vddci;
2702 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2706 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &vddc,
2707 &data->vddc_leakage);
2710 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &vddci,
2711 &data->vddci_leakage);
2718 static int smu7_patch_cac_vddc(struct pp_hwmgr *hwmgr, struct phm_cac_leakage_table *tab)
2722 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2725 for (i = 0; i < tab->count; i++) {
2726 vddc = (uint32_t)(tab->entries[i].Vddc);
2727 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &vddc, &data->vddc_leakage);
2728 tab->entries[i].Vddc = (uint16_t)vddc;
2735 static int smu7_patch_dependency_tables_with_leakage(struct pp_hwmgr *hwmgr)
2739 tmp = smu7_patch_vddc(hwmgr, hwmgr->dyn_state.vddc_dependency_on_sclk);
2743 tmp = smu7_patch_vddc(hwmgr, hwmgr->dyn_state.vddc_dependency_on_mclk);
2747 tmp = smu7_patch_vddc(hwmgr, hwmgr->dyn_state.vddc_dep_on_dal_pwrl);
2751 tmp = smu7_patch_vddci(hwmgr, hwmgr->dyn_state.vddci_dependency_on_mclk);
2755 tmp = smu7_patch_vce_vddc(hwmgr, hwmgr->dyn_state.vce_clock_voltage_dependency_table);
2759 tmp = smu7_patch_uvd_vddc(hwmgr, hwmgr->dyn_state.uvd_clock_voltage_dependency_table);
2763 tmp = smu7_patch_samu_vddc(hwmgr, hwmgr->dyn_state.samu_clock_voltage_dependency_table);
2767 tmp = smu7_patch_acp_vddc(hwmgr, hwmgr->dyn_state.acp_clock_voltage_dependency_table);
2771 tmp = smu7_patch_vddc_shed_limit(hwmgr, hwmgr->dyn_state.vddc_phase_shed_limits_table);
2775 tmp = smu7_patch_limits_vddc(hwmgr, &hwmgr->dyn_state.max_clock_voltage_on_ac);
2779 tmp = smu7_patch_limits_vddc(hwmgr, &hwmgr->dyn_state.max_clock_voltage_on_dc);
2783 tmp = smu7_patch_cac_vddc(hwmgr, hwmgr->dyn_state.cac_leakage_table);
2791 static int smu7_set_private_data_based_on_pptable_v0(struct pp_hwmgr *hwmgr)
2793 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2795 struct phm_clock_voltage_dependency_table *allowed_sclk_vddc_table = hwmgr->dyn_state.vddc_dependency_on_sclk;
2796 struct phm_clock_voltage_dependency_table *allowed_mclk_vddc_table = hwmgr->dyn_state.vddc_dependency_on_mclk;
2797 struct phm_clock_voltage_dependency_table *allowed_mclk_vddci_table = hwmgr->dyn_state.vddci_dependency_on_mclk;
2799 PP_ASSERT_WITH_CODE(allowed_sclk_vddc_table != NULL,
2800 "VDDC dependency on SCLK table is missing. This table is mandatory",
2802 PP_ASSERT_WITH_CODE(allowed_sclk_vddc_table->count >= 1,
2803 "VDDC dependency on SCLK table has to have is missing. This table is mandatory",
2806 PP_ASSERT_WITH_CODE(allowed_mclk_vddc_table != NULL,
2807 "VDDC dependency on MCLK table is missing. This table is mandatory",
2809 PP_ASSERT_WITH_CODE(allowed_mclk_vddc_table->count >= 1,
2810 "VDD dependency on MCLK table has to have is missing. This table is mandatory",
2813 data->min_vddc_in_pptable = (uint16_t)allowed_sclk_vddc_table->entries[0].v;
2814 data->max_vddc_in_pptable = (uint16_t)allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].v;
2816 hwmgr->dyn_state.max_clock_voltage_on_ac.sclk =
2817 allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].clk;
2818 hwmgr->dyn_state.max_clock_voltage_on_ac.mclk =
2819 allowed_mclk_vddc_table->entries[allowed_mclk_vddc_table->count - 1].clk;
2820 hwmgr->dyn_state.max_clock_voltage_on_ac.vddc =
2821 allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].v;
2823 if (allowed_mclk_vddci_table != NULL && allowed_mclk_vddci_table->count >= 1) {
2824 data->min_vddci_in_pptable = (uint16_t)allowed_mclk_vddci_table->entries[0].v;
2825 data->max_vddci_in_pptable = (uint16_t)allowed_mclk_vddci_table->entries[allowed_mclk_vddci_table->count - 1].v;
2828 if (hwmgr->dyn_state.vddci_dependency_on_mclk != NULL && hwmgr->dyn_state.vddci_dependency_on_mclk->count >= 1)
2829 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;
2834 static int smu7_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)
2836 kfree(hwmgr->dyn_state.vddc_dep_on_dal_pwrl);
2837 hwmgr->dyn_state.vddc_dep_on_dal_pwrl = NULL;
2838 kfree(hwmgr->backend);
2839 hwmgr->backend = NULL;
2844 static int smu7_get_elb_voltages(struct pp_hwmgr *hwmgr)
2846 uint16_t virtual_voltage_id, vddc, vddci, efuse_voltage_id;
2847 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2850 if (atomctrl_get_leakage_id_from_efuse(hwmgr, &efuse_voltage_id) == 0) {
2851 for (i = 0; i < SMU7_MAX_LEAKAGE_COUNT; i++) {
2852 virtual_voltage_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i;
2853 if (atomctrl_get_leakage_vddc_base_on_leakage(hwmgr, &vddc, &vddci,
2855 efuse_voltage_id) == 0) {
2856 if (vddc != 0 && vddc != virtual_voltage_id) {
2857 data->vddc_leakage.actual_voltage[data->vddc_leakage.count] = vddc;
2858 data->vddc_leakage.leakage_id[data->vddc_leakage.count] = virtual_voltage_id;
2859 data->vddc_leakage.count++;
2861 if (vddci != 0 && vddci != virtual_voltage_id) {
2862 data->vddci_leakage.actual_voltage[data->vddci_leakage.count] = vddci;
2863 data->vddci_leakage.leakage_id[data->vddci_leakage.count] = virtual_voltage_id;
2864 data->vddci_leakage.count++;
2872 #define LEAKAGE_ID_MSB 463
2873 #define LEAKAGE_ID_LSB 454
2875 static int smu7_update_edc_leakage_table(struct pp_hwmgr *hwmgr)
2877 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2882 if (data->disable_edc_leakage_controller)
2885 ret = atomctrl_get_edc_hilo_leakage_offset_table(hwmgr,
2886 &data->edc_hilo_leakage_offset_from_vbios);
2890 if (data->edc_hilo_leakage_offset_from_vbios.usEdcDidtLoDpm7TableOffset &&
2891 data->edc_hilo_leakage_offset_from_vbios.usEdcDidtHiDpm7TableOffset) {
2892 atomctrl_read_efuse(hwmgr, LEAKAGE_ID_LSB, LEAKAGE_ID_MSB, &efuse);
2893 if (efuse < data->edc_hilo_leakage_offset_from_vbios.usHiLoLeakageThreshold)
2894 offset = data->edc_hilo_leakage_offset_from_vbios.usEdcDidtLoDpm7TableOffset;
2896 offset = data->edc_hilo_leakage_offset_from_vbios.usEdcDidtHiDpm7TableOffset;
2898 ret = atomctrl_get_edc_leakage_table(hwmgr,
2899 &data->edc_leakage_table,
2908 static int smu7_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
2910 struct smu7_hwmgr *data;
2913 data = kzalloc(sizeof(struct smu7_hwmgr), GFP_KERNEL);
2917 hwmgr->backend = data;
2918 smu7_patch_voltage_workaround(hwmgr);
2919 smu7_init_dpm_defaults(hwmgr);
2921 /* Get leakage voltage based on leakage ID. */
2922 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2923 PHM_PlatformCaps_EVV)) {
2924 result = smu7_get_evv_voltages(hwmgr);
2926 pr_info("Get EVV Voltage Failed. Abort Driver loading!\n");
2930 smu7_get_elb_voltages(hwmgr);
2933 if (hwmgr->pp_table_version == PP_TABLE_V1) {
2934 smu7_complete_dependency_tables(hwmgr);
2935 smu7_set_private_data_based_on_pptable_v1(hwmgr);
2936 } else if (hwmgr->pp_table_version == PP_TABLE_V0) {
2937 smu7_patch_dependency_tables_with_leakage(hwmgr);
2938 smu7_set_private_data_based_on_pptable_v0(hwmgr);
2941 /* Initalize Dynamic State Adjustment Rule Settings */
2942 result = phm_initializa_dynamic_state_adjustment_rule_settings(hwmgr);
2945 struct amdgpu_device *adev = hwmgr->adev;
2947 data->is_tlu_enabled = false;
2949 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels =
2950 SMU7_MAX_HARDWARE_POWERLEVELS;
2951 hwmgr->platform_descriptor.hardwarePerformanceLevels = 2;
2952 hwmgr->platform_descriptor.minimumClocksReductionPercentage = 50;
2954 data->pcie_gen_cap = adev->pm.pcie_gen_mask;
2955 if (data->pcie_gen_cap & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)
2956 data->pcie_spc_cap = 20;
2958 data->pcie_spc_cap = 16;
2959 data->pcie_lane_cap = adev->pm.pcie_mlw_mask;
2961 hwmgr->platform_descriptor.vbiosInterruptId = 0x20000400; /* IRQ_SOURCE1_SW_INT */
2962 /* The true clock step depends on the frequency, typically 4.5 or 9 MHz. Here we use 5. */
2963 hwmgr->platform_descriptor.clockStep.engineClock = 500;
2964 hwmgr->platform_descriptor.clockStep.memoryClock = 500;
2965 smu7_thermal_parameter_init(hwmgr);
2967 /* Ignore return value in here, we are cleaning up a mess. */
2968 smu7_hwmgr_backend_fini(hwmgr);
2971 result = smu7_update_edc_leakage_table(hwmgr);
2978 static int smu7_force_dpm_highest(struct pp_hwmgr *hwmgr)
2980 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2981 uint32_t level, tmp;
2983 if (!data->pcie_dpm_key_disabled) {
2984 if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) {
2986 tmp = data->dpm_level_enable_mask.pcie_dpm_enable_mask;
2991 smum_send_msg_to_smc_with_parameter(hwmgr,
2992 PPSMC_MSG_PCIeDPM_ForceLevel, level,
2997 if (!data->sclk_dpm_key_disabled) {
2998 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
3000 tmp = data->dpm_level_enable_mask.sclk_dpm_enable_mask;
3005 smum_send_msg_to_smc_with_parameter(hwmgr,
3006 PPSMC_MSG_SCLKDPM_SetEnabledMask,
3012 if (!data->mclk_dpm_key_disabled) {
3013 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
3015 tmp = data->dpm_level_enable_mask.mclk_dpm_enable_mask;
3020 smum_send_msg_to_smc_with_parameter(hwmgr,
3021 PPSMC_MSG_MCLKDPM_SetEnabledMask,
3030 static int smu7_upload_dpm_level_enable_mask(struct pp_hwmgr *hwmgr)
3032 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3034 if (hwmgr->pp_table_version == PP_TABLE_V1)
3035 phm_apply_dal_min_voltage_request(hwmgr);
3036 /* TO DO for v0 iceland and Ci*/
3038 if (!data->sclk_dpm_key_disabled) {
3039 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask)
3040 smum_send_msg_to_smc_with_parameter(hwmgr,
3041 PPSMC_MSG_SCLKDPM_SetEnabledMask,
3042 data->dpm_level_enable_mask.sclk_dpm_enable_mask,
3046 if (!data->mclk_dpm_key_disabled) {
3047 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask)
3048 smum_send_msg_to_smc_with_parameter(hwmgr,
3049 PPSMC_MSG_MCLKDPM_SetEnabledMask,
3050 data->dpm_level_enable_mask.mclk_dpm_enable_mask,
3057 static int smu7_unforce_dpm_levels(struct pp_hwmgr *hwmgr)
3059 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3061 if (!smum_is_dpm_running(hwmgr))
3064 if (!data->pcie_dpm_key_disabled) {
3065 smum_send_msg_to_smc(hwmgr,
3066 PPSMC_MSG_PCIeDPM_UnForceLevel,
3070 return smu7_upload_dpm_level_enable_mask(hwmgr);
3073 static int smu7_force_dpm_lowest(struct pp_hwmgr *hwmgr)
3075 struct smu7_hwmgr *data =
3076 (struct smu7_hwmgr *)(hwmgr->backend);
3079 if (!data->sclk_dpm_key_disabled)
3080 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
3081 level = phm_get_lowest_enabled_level(hwmgr,
3082 data->dpm_level_enable_mask.sclk_dpm_enable_mask);
3083 smum_send_msg_to_smc_with_parameter(hwmgr,
3084 PPSMC_MSG_SCLKDPM_SetEnabledMask,
3090 if (!data->mclk_dpm_key_disabled) {
3091 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
3092 level = phm_get_lowest_enabled_level(hwmgr,
3093 data->dpm_level_enable_mask.mclk_dpm_enable_mask);
3094 smum_send_msg_to_smc_with_parameter(hwmgr,
3095 PPSMC_MSG_MCLKDPM_SetEnabledMask,
3101 if (!data->pcie_dpm_key_disabled) {
3102 if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) {
3103 level = phm_get_lowest_enabled_level(hwmgr,
3104 data->dpm_level_enable_mask.pcie_dpm_enable_mask);
3105 smum_send_msg_to_smc_with_parameter(hwmgr,
3106 PPSMC_MSG_PCIeDPM_ForceLevel,
3115 static int smu7_get_profiling_clk(struct pp_hwmgr *hwmgr, enum amd_dpm_forced_level level,
3116 uint32_t *sclk_mask, uint32_t *mclk_mask, uint32_t *pcie_mask)
3118 uint32_t percentage;
3119 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3120 struct smu7_dpm_table *golden_dpm_table = &data->golden_dpm_table;
3125 if (golden_dpm_table->mclk_table.count < 1)
3128 percentage = 100 * golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count - 1].value /
3129 golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count - 1].value;
3131 if (golden_dpm_table->mclk_table.count == 1) {
3133 tmp_mclk = golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count - 1].value;
3134 *mclk_mask = golden_dpm_table->mclk_table.count - 1;
3136 tmp_mclk = golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count - 2].value;
3137 *mclk_mask = golden_dpm_table->mclk_table.count - 2;
3140 tmp_sclk = tmp_mclk * percentage / 100;
3142 if (hwmgr->pp_table_version == PP_TABLE_V0) {
3143 for (count = hwmgr->dyn_state.vddc_dependency_on_sclk->count-1;
3144 count >= 0; count--) {
3145 if (tmp_sclk >= hwmgr->dyn_state.vddc_dependency_on_sclk->entries[count].clk) {
3146 tmp_sclk = hwmgr->dyn_state.vddc_dependency_on_sclk->entries[count].clk;
3151 if (count < 0 || level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) {
3153 tmp_sclk = hwmgr->dyn_state.vddc_dependency_on_sclk->entries[0].clk;
3156 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
3157 *sclk_mask = hwmgr->dyn_state.vddc_dependency_on_sclk->count-1;
3158 } else if (hwmgr->pp_table_version == PP_TABLE_V1) {
3159 struct phm_ppt_v1_information *table_info =
3160 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3162 for (count = table_info->vdd_dep_on_sclk->count-1; count >= 0; count--) {
3163 if (tmp_sclk >= table_info->vdd_dep_on_sclk->entries[count].clk) {
3164 tmp_sclk = table_info->vdd_dep_on_sclk->entries[count].clk;
3169 if (count < 0 || level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) {
3171 tmp_sclk = table_info->vdd_dep_on_sclk->entries[0].clk;
3174 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
3175 *sclk_mask = table_info->vdd_dep_on_sclk->count - 1;
3178 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK)
3180 else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
3181 *mclk_mask = golden_dpm_table->mclk_table.count - 1;
3183 *pcie_mask = data->dpm_table.pcie_speed_table.count - 1;
3184 hwmgr->pstate_sclk = tmp_sclk;
3185 hwmgr->pstate_mclk = tmp_mclk;
3190 static int smu7_force_dpm_level(struct pp_hwmgr *hwmgr,
3191 enum amd_dpm_forced_level level)
3194 uint32_t sclk_mask = 0;
3195 uint32_t mclk_mask = 0;
3196 uint32_t pcie_mask = 0;
3198 if (hwmgr->pstate_sclk == 0)
3199 smu7_get_profiling_clk(hwmgr, level, &sclk_mask, &mclk_mask, &pcie_mask);
3202 case AMD_DPM_FORCED_LEVEL_HIGH:
3203 ret = smu7_force_dpm_highest(hwmgr);
3205 case AMD_DPM_FORCED_LEVEL_LOW:
3206 ret = smu7_force_dpm_lowest(hwmgr);
3208 case AMD_DPM_FORCED_LEVEL_AUTO:
3209 ret = smu7_unforce_dpm_levels(hwmgr);
3211 case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:
3212 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
3213 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:
3214 case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:
3215 ret = smu7_get_profiling_clk(hwmgr, level, &sclk_mask, &mclk_mask, &pcie_mask);
3218 smu7_force_clock_level(hwmgr, PP_SCLK, 1<<sclk_mask);
3219 smu7_force_clock_level(hwmgr, PP_MCLK, 1<<mclk_mask);
3220 smu7_force_clock_level(hwmgr, PP_PCIE, 1<<pcie_mask);
3222 case AMD_DPM_FORCED_LEVEL_MANUAL:
3223 case AMD_DPM_FORCED_LEVEL_PROFILE_EXIT:
3229 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK && hwmgr->dpm_level != AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
3230 smu7_fan_ctrl_set_fan_speed_pwm(hwmgr, 255);
3231 else if (level != AMD_DPM_FORCED_LEVEL_PROFILE_PEAK && hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
3232 smu7_fan_ctrl_reset_fan_speed_to_default(hwmgr);
3237 static int smu7_get_power_state_size(struct pp_hwmgr *hwmgr)
3239 return sizeof(struct smu7_power_state);
3242 static int smu7_vblank_too_short(struct pp_hwmgr *hwmgr,
3243 uint32_t vblank_time_us)
3245 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3246 uint32_t switch_limit_us;
3248 switch (hwmgr->chip_id) {
3249 case CHIP_POLARIS10:
3250 case CHIP_POLARIS11:
3251 case CHIP_POLARIS12:
3252 if (hwmgr->is_kicker || (hwmgr->chip_id == CHIP_POLARIS12))
3253 switch_limit_us = data->is_memory_gddr5 ? 450 : 150;
3255 switch_limit_us = data->is_memory_gddr5 ? 200 : 150;
3258 switch_limit_us = 30;
3261 switch_limit_us = data->is_memory_gddr5 ? 450 : 150;
3265 if (vblank_time_us < switch_limit_us)
3271 static int smu7_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
3272 struct pp_power_state *request_ps,
3273 const struct pp_power_state *current_ps)
3275 struct amdgpu_device *adev = hwmgr->adev;
3276 struct smu7_power_state *smu7_ps =
3277 cast_phw_smu7_power_state(&request_ps->hardware);
3280 struct PP_Clocks minimum_clocks = {0};
3281 bool disable_mclk_switching;
3282 bool disable_mclk_switching_for_frame_lock;
3283 bool disable_mclk_switching_for_display;
3284 const struct phm_clock_and_voltage_limits *max_limits;
3286 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3287 struct phm_ppt_v1_information *table_info =
3288 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3290 int32_t stable_pstate_sclk = 0, stable_pstate_mclk = 0;
3292 bool latency_allowed = false;
3294 data->battery_state = (PP_StateUILabel_Battery ==
3295 request_ps->classification.ui_label);
3296 data->mclk_ignore_signal = false;
3298 PP_ASSERT_WITH_CODE(smu7_ps->performance_level_count == 2,
3299 "VI should always have 2 performance levels",
3302 max_limits = adev->pm.ac_power ?
3303 &(hwmgr->dyn_state.max_clock_voltage_on_ac) :
3304 &(hwmgr->dyn_state.max_clock_voltage_on_dc);
3306 /* Cap clock DPM tables at DC MAX if it is in DC. */
3307 if (!adev->pm.ac_power) {
3308 for (i = 0; i < smu7_ps->performance_level_count; i++) {
3309 if (smu7_ps->performance_levels[i].memory_clock > max_limits->mclk)
3310 smu7_ps->performance_levels[i].memory_clock = max_limits->mclk;
3311 if (smu7_ps->performance_levels[i].engine_clock > max_limits->sclk)
3312 smu7_ps->performance_levels[i].engine_clock = max_limits->sclk;
3316 minimum_clocks.engineClock = hwmgr->display_config->min_core_set_clock;
3317 minimum_clocks.memoryClock = hwmgr->display_config->min_mem_set_clock;
3319 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3320 PHM_PlatformCaps_StablePState)) {
3321 max_limits = &(hwmgr->dyn_state.max_clock_voltage_on_ac);
3322 stable_pstate_sclk = (max_limits->sclk * 75) / 100;
3324 for (count = table_info->vdd_dep_on_sclk->count - 1;
3325 count >= 0; count--) {
3326 if (stable_pstate_sclk >=
3327 table_info->vdd_dep_on_sclk->entries[count].clk) {
3328 stable_pstate_sclk =
3329 table_info->vdd_dep_on_sclk->entries[count].clk;
3335 stable_pstate_sclk = table_info->vdd_dep_on_sclk->entries[0].clk;
3337 stable_pstate_mclk = max_limits->mclk;
3339 minimum_clocks.engineClock = stable_pstate_sclk;
3340 minimum_clocks.memoryClock = stable_pstate_mclk;
3343 disable_mclk_switching_for_frame_lock = phm_cap_enabled(
3344 hwmgr->platform_descriptor.platformCaps,
3345 PHM_PlatformCaps_DisableMclkSwitchingForFrameLock);
3347 disable_mclk_switching_for_display = ((1 < hwmgr->display_config->num_display) &&
3348 !hwmgr->display_config->multi_monitor_in_sync) ||
3349 (hwmgr->display_config->num_display &&
3350 smu7_vblank_too_short(hwmgr, hwmgr->display_config->min_vblank_time));
3352 disable_mclk_switching = disable_mclk_switching_for_frame_lock ||
3353 disable_mclk_switching_for_display;
3355 if (hwmgr->display_config->num_display == 0) {
3356 if (hwmgr->chip_id >= CHIP_POLARIS10 && hwmgr->chip_id <= CHIP_VEGAM)
3357 data->mclk_ignore_signal = true;
3359 disable_mclk_switching = false;
3362 sclk = smu7_ps->performance_levels[0].engine_clock;
3363 mclk = smu7_ps->performance_levels[0].memory_clock;
3365 if (disable_mclk_switching &&
3366 (!(hwmgr->chip_id >= CHIP_POLARIS10 &&
3367 hwmgr->chip_id <= CHIP_VEGAM)))
3368 mclk = smu7_ps->performance_levels
3369 [smu7_ps->performance_level_count - 1].memory_clock;
3371 if (sclk < minimum_clocks.engineClock)
3372 sclk = (minimum_clocks.engineClock > max_limits->sclk) ?
3373 max_limits->sclk : minimum_clocks.engineClock;
3375 if (mclk < minimum_clocks.memoryClock)
3376 mclk = (minimum_clocks.memoryClock > max_limits->mclk) ?
3377 max_limits->mclk : minimum_clocks.memoryClock;
3379 smu7_ps->performance_levels[0].engine_clock = sclk;
3380 smu7_ps->performance_levels[0].memory_clock = mclk;
3382 smu7_ps->performance_levels[1].engine_clock =
3383 (smu7_ps->performance_levels[1].engine_clock >=
3384 smu7_ps->performance_levels[0].engine_clock) ?
3385 smu7_ps->performance_levels[1].engine_clock :
3386 smu7_ps->performance_levels[0].engine_clock;
3388 if (disable_mclk_switching) {
3389 if (mclk < smu7_ps->performance_levels[1].memory_clock)
3390 mclk = smu7_ps->performance_levels[1].memory_clock;
3392 if (hwmgr->chip_id >= CHIP_POLARIS10 && hwmgr->chip_id <= CHIP_VEGAM) {
3393 if (disable_mclk_switching_for_display) {
3394 /* Find the lowest MCLK frequency that is within
3395 * the tolerable latency defined in DAL
3397 latency = hwmgr->display_config->dce_tolerable_mclk_in_active_latency;
3398 for (i = 0; i < data->mclk_latency_table.count; i++) {
3399 if (data->mclk_latency_table.entries[i].latency <= latency) {
3400 latency_allowed = true;
3402 if ((data->mclk_latency_table.entries[i].frequency >=
3403 smu7_ps->performance_levels[0].memory_clock) &&
3404 (data->mclk_latency_table.entries[i].frequency <=
3405 smu7_ps->performance_levels[1].memory_clock)) {
3406 mclk = data->mclk_latency_table.entries[i].frequency;
3411 if ((i >= data->mclk_latency_table.count - 1) && !latency_allowed) {
3412 data->mclk_ignore_signal = true;
3414 data->mclk_ignore_signal = false;
3418 if (disable_mclk_switching_for_frame_lock)
3419 mclk = smu7_ps->performance_levels[1].memory_clock;
3422 smu7_ps->performance_levels[0].memory_clock = mclk;
3424 if (!(hwmgr->chip_id >= CHIP_POLARIS10 &&
3425 hwmgr->chip_id <= CHIP_VEGAM))
3426 smu7_ps->performance_levels[1].memory_clock = mclk;
3428 if (smu7_ps->performance_levels[1].memory_clock <
3429 smu7_ps->performance_levels[0].memory_clock)
3430 smu7_ps->performance_levels[1].memory_clock =
3431 smu7_ps->performance_levels[0].memory_clock;
3434 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3435 PHM_PlatformCaps_StablePState)) {
3436 for (i = 0; i < smu7_ps->performance_level_count; i++) {
3437 smu7_ps->performance_levels[i].engine_clock = stable_pstate_sclk;
3438 smu7_ps->performance_levels[i].memory_clock = stable_pstate_mclk;
3439 smu7_ps->performance_levels[i].pcie_gen = data->pcie_gen_performance.max;
3440 smu7_ps->performance_levels[i].pcie_lane = data->pcie_gen_performance.max;
3447 static uint32_t smu7_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)
3449 struct pp_power_state *ps;
3450 struct smu7_power_state *smu7_ps;
3455 ps = hwmgr->request_ps;
3460 smu7_ps = cast_phw_smu7_power_state(&ps->hardware);
3463 return smu7_ps->performance_levels[0].memory_clock;
3465 return smu7_ps->performance_levels
3466 [smu7_ps->performance_level_count-1].memory_clock;
3469 static uint32_t smu7_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)
3471 struct pp_power_state *ps;
3472 struct smu7_power_state *smu7_ps;
3477 ps = hwmgr->request_ps;
3482 smu7_ps = cast_phw_smu7_power_state(&ps->hardware);
3485 return smu7_ps->performance_levels[0].engine_clock;
3487 return smu7_ps->performance_levels
3488 [smu7_ps->performance_level_count-1].engine_clock;
3491 static int smu7_dpm_patch_boot_state(struct pp_hwmgr *hwmgr,
3492 struct pp_hw_power_state *hw_ps)
3494 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3495 struct smu7_power_state *ps = (struct smu7_power_state *)hw_ps;
3496 ATOM_FIRMWARE_INFO_V2_2 *fw_info;
3499 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
3501 /* First retrieve the Boot clocks and VDDC from the firmware info table.
3502 * We assume here that fw_info is unchanged if this call fails.
3504 fw_info = (ATOM_FIRMWARE_INFO_V2_2 *)smu_atom_get_data_table(hwmgr->adev, index,
3505 &size, &frev, &crev);
3507 /* During a test, there is no firmware info table. */
3510 /* Patch the state. */
3511 data->vbios_boot_state.sclk_bootup_value =
3512 le32_to_cpu(fw_info->ulDefaultEngineClock);
3513 data->vbios_boot_state.mclk_bootup_value =
3514 le32_to_cpu(fw_info->ulDefaultMemoryClock);
3515 data->vbios_boot_state.mvdd_bootup_value =
3516 le16_to_cpu(fw_info->usBootUpMVDDCVoltage);
3517 data->vbios_boot_state.vddc_bootup_value =
3518 le16_to_cpu(fw_info->usBootUpVDDCVoltage);
3519 data->vbios_boot_state.vddci_bootup_value =
3520 le16_to_cpu(fw_info->usBootUpVDDCIVoltage);
3521 data->vbios_boot_state.pcie_gen_bootup_value =
3522 smu7_get_current_pcie_speed(hwmgr);
3524 data->vbios_boot_state.pcie_lane_bootup_value =
3525 (uint16_t)smu7_get_current_pcie_lane_number(hwmgr);
3527 /* set boot power state */
3528 ps->performance_levels[0].memory_clock = data->vbios_boot_state.mclk_bootup_value;
3529 ps->performance_levels[0].engine_clock = data->vbios_boot_state.sclk_bootup_value;
3530 ps->performance_levels[0].pcie_gen = data->vbios_boot_state.pcie_gen_bootup_value;
3531 ps->performance_levels[0].pcie_lane = data->vbios_boot_state.pcie_lane_bootup_value;
3536 static int smu7_get_number_of_powerplay_table_entries(struct pp_hwmgr *hwmgr)
3539 unsigned long ret = 0;
3541 if (hwmgr->pp_table_version == PP_TABLE_V0) {
3542 result = pp_tables_get_num_of_entries(hwmgr, &ret);
3543 return result ? 0 : ret;
3544 } else if (hwmgr->pp_table_version == PP_TABLE_V1) {
3545 result = get_number_of_powerplay_table_entries_v1_0(hwmgr);
3551 static int smu7_get_pp_table_entry_callback_func_v1(struct pp_hwmgr *hwmgr,
3552 void *state, struct pp_power_state *power_state,
3553 void *pp_table, uint32_t classification_flag)
3555 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3556 struct smu7_power_state *smu7_power_state =
3557 (struct smu7_power_state *)(&(power_state->hardware));
3558 struct smu7_performance_level *performance_level;
3559 ATOM_Tonga_State *state_entry = (ATOM_Tonga_State *)state;
3560 ATOM_Tonga_POWERPLAYTABLE *powerplay_table =
3561 (ATOM_Tonga_POWERPLAYTABLE *)pp_table;
3562 PPTable_Generic_SubTable_Header *sclk_dep_table =
3563 (PPTable_Generic_SubTable_Header *)
3564 (((unsigned long)powerplay_table) +
3565 le16_to_cpu(powerplay_table->usSclkDependencyTableOffset));
3567 ATOM_Tonga_MCLK_Dependency_Table *mclk_dep_table =
3568 (ATOM_Tonga_MCLK_Dependency_Table *)
3569 (((unsigned long)powerplay_table) +
3570 le16_to_cpu(powerplay_table->usMclkDependencyTableOffset));
3572 /* The following fields are not initialized here: id orderedList allStatesList */
3573 power_state->classification.ui_label =
3574 (le16_to_cpu(state_entry->usClassification) &
3575 ATOM_PPLIB_CLASSIFICATION_UI_MASK) >>
3576 ATOM_PPLIB_CLASSIFICATION_UI_SHIFT;
3577 power_state->classification.flags = classification_flag;
3578 /* NOTE: There is a classification2 flag in BIOS that is not being used right now */
3580 power_state->classification.temporary_state = false;
3581 power_state->classification.to_be_deleted = false;
3583 power_state->validation.disallowOnDC =
3584 (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) &
3585 ATOM_Tonga_DISALLOW_ON_DC));
3587 power_state->pcie.lanes = 0;
3589 power_state->display.disableFrameModulation = false;
3590 power_state->display.limitRefreshrate = false;
3591 power_state->display.enableVariBright =
3592 (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) &
3593 ATOM_Tonga_ENABLE_VARIBRIGHT));
3595 power_state->validation.supportedPowerLevels = 0;
3596 power_state->uvd_clocks.VCLK = 0;
3597 power_state->uvd_clocks.DCLK = 0;
3598 power_state->temperatures.min = 0;
3599 power_state->temperatures.max = 0;
3601 performance_level = &(smu7_power_state->performance_levels
3602 [smu7_power_state->performance_level_count++]);
3604 PP_ASSERT_WITH_CODE(
3605 (smu7_power_state->performance_level_count < smum_get_mac_definition(hwmgr, SMU_MAX_LEVELS_GRAPHICS)),
3606 "Performance levels exceeds SMC limit!",
3609 PP_ASSERT_WITH_CODE(
3610 (smu7_power_state->performance_level_count <=
3611 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels),
3612 "Performance levels exceeds Driver limit!",
3615 /* Performance levels are arranged from low to high. */
3616 performance_level->memory_clock = mclk_dep_table->entries
3617 [state_entry->ucMemoryClockIndexLow].ulMclk;
3618 if (sclk_dep_table->ucRevId == 0)
3619 performance_level->engine_clock = ((ATOM_Tonga_SCLK_Dependency_Table *)sclk_dep_table)->entries
3620 [state_entry->ucEngineClockIndexLow].ulSclk;
3621 else if (sclk_dep_table->ucRevId == 1)
3622 performance_level->engine_clock = ((ATOM_Polaris_SCLK_Dependency_Table *)sclk_dep_table)->entries
3623 [state_entry->ucEngineClockIndexLow].ulSclk;
3624 performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap,
3625 state_entry->ucPCIEGenLow);
3626 performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap,
3627 state_entry->ucPCIELaneLow);
3629 performance_level = &(smu7_power_state->performance_levels
3630 [smu7_power_state->performance_level_count++]);
3631 performance_level->memory_clock = mclk_dep_table->entries
3632 [state_entry->ucMemoryClockIndexHigh].ulMclk;
3634 if (sclk_dep_table->ucRevId == 0)
3635 performance_level->engine_clock = ((ATOM_Tonga_SCLK_Dependency_Table *)sclk_dep_table)->entries
3636 [state_entry->ucEngineClockIndexHigh].ulSclk;
3637 else if (sclk_dep_table->ucRevId == 1)
3638 performance_level->engine_clock = ((ATOM_Polaris_SCLK_Dependency_Table *)sclk_dep_table)->entries
3639 [state_entry->ucEngineClockIndexHigh].ulSclk;
3641 performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap,
3642 state_entry->ucPCIEGenHigh);
3643 performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap,
3644 state_entry->ucPCIELaneHigh);
3649 static int smu7_get_pp_table_entry_v1(struct pp_hwmgr *hwmgr,
3650 unsigned long entry_index, struct pp_power_state *state)
3653 struct smu7_power_state *ps;
3654 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3655 struct phm_ppt_v1_information *table_info =
3656 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3657 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
3658 table_info->vdd_dep_on_mclk;
3660 state->hardware.magic = PHM_VIslands_Magic;
3662 ps = (struct smu7_power_state *)(&state->hardware);
3664 result = get_powerplay_table_entry_v1_0(hwmgr, entry_index, state,
3665 smu7_get_pp_table_entry_callback_func_v1);
3667 /* This is the earliest time we have all the dependency table and the VBIOS boot state
3668 * as PP_Tables_GetPowerPlayTableEntry retrieves the VBIOS boot state
3669 * if there is only one VDDCI/MCLK level, check if it's the same as VBIOS boot state
3671 if (dep_mclk_table != NULL && dep_mclk_table->count == 1) {
3672 if (dep_mclk_table->entries[0].clk !=
3673 data->vbios_boot_state.mclk_bootup_value)
3674 pr_debug("Single MCLK entry VDDCI/MCLK dependency table "
3675 "does not match VBIOS boot MCLK level");
3676 if (dep_mclk_table->entries[0].vddci !=
3677 data->vbios_boot_state.vddci_bootup_value)
3678 pr_debug("Single VDDCI entry VDDCI/MCLK dependency table "
3679 "does not match VBIOS boot VDDCI level");
3682 /* set DC compatible flag if this state supports DC */
3683 if (!state->validation.disallowOnDC)
3684 ps->dc_compatible = true;
3686 if (state->classification.flags & PP_StateClassificationFlag_ACPI)
3687 data->acpi_pcie_gen = ps->performance_levels[0].pcie_gen;
3689 ps->uvd_clks.vclk = state->uvd_clocks.VCLK;
3690 ps->uvd_clks.dclk = state->uvd_clocks.DCLK;
3695 switch (state->classification.ui_label) {
3696 case PP_StateUILabel_Performance:
3697 data->use_pcie_performance_levels = true;
3698 for (i = 0; i < ps->performance_level_count; i++) {
3699 if (data->pcie_gen_performance.max <
3700 ps->performance_levels[i].pcie_gen)
3701 data->pcie_gen_performance.max =
3702 ps->performance_levels[i].pcie_gen;
3704 if (data->pcie_gen_performance.min >
3705 ps->performance_levels[i].pcie_gen)
3706 data->pcie_gen_performance.min =
3707 ps->performance_levels[i].pcie_gen;
3709 if (data->pcie_lane_performance.max <
3710 ps->performance_levels[i].pcie_lane)
3711 data->pcie_lane_performance.max =
3712 ps->performance_levels[i].pcie_lane;
3713 if (data->pcie_lane_performance.min >
3714 ps->performance_levels[i].pcie_lane)
3715 data->pcie_lane_performance.min =
3716 ps->performance_levels[i].pcie_lane;
3719 case PP_StateUILabel_Battery:
3720 data->use_pcie_power_saving_levels = true;
3722 for (i = 0; i < ps->performance_level_count; i++) {
3723 if (data->pcie_gen_power_saving.max <
3724 ps->performance_levels[i].pcie_gen)
3725 data->pcie_gen_power_saving.max =
3726 ps->performance_levels[i].pcie_gen;
3728 if (data->pcie_gen_power_saving.min >
3729 ps->performance_levels[i].pcie_gen)
3730 data->pcie_gen_power_saving.min =
3731 ps->performance_levels[i].pcie_gen;
3733 if (data->pcie_lane_power_saving.max <
3734 ps->performance_levels[i].pcie_lane)
3735 data->pcie_lane_power_saving.max =
3736 ps->performance_levels[i].pcie_lane;
3738 if (data->pcie_lane_power_saving.min >
3739 ps->performance_levels[i].pcie_lane)
3740 data->pcie_lane_power_saving.min =
3741 ps->performance_levels[i].pcie_lane;
3751 static int smu7_get_pp_table_entry_callback_func_v0(struct pp_hwmgr *hwmgr,
3752 struct pp_hw_power_state *power_state,
3753 unsigned int index, const void *clock_info)
3755 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3756 struct smu7_power_state *ps = cast_phw_smu7_power_state(power_state);
3757 const ATOM_PPLIB_CI_CLOCK_INFO *visland_clk_info = clock_info;
3758 struct smu7_performance_level *performance_level;
3759 uint32_t engine_clock, memory_clock;
3760 uint16_t pcie_gen_from_bios;
3762 engine_clock = visland_clk_info->ucEngineClockHigh << 16 | visland_clk_info->usEngineClockLow;
3763 memory_clock = visland_clk_info->ucMemoryClockHigh << 16 | visland_clk_info->usMemoryClockLow;
3765 if (!(data->mc_micro_code_feature & DISABLE_MC_LOADMICROCODE) && memory_clock > data->highest_mclk)
3766 data->highest_mclk = memory_clock;
3768 PP_ASSERT_WITH_CODE(
3769 (ps->performance_level_count < smum_get_mac_definition(hwmgr, SMU_MAX_LEVELS_GRAPHICS)),
3770 "Performance levels exceeds SMC limit!",
3773 PP_ASSERT_WITH_CODE(
3774 (ps->performance_level_count <
3775 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels),
3776 "Performance levels exceeds Driver limit, Skip!",
3779 performance_level = &(ps->performance_levels
3780 [ps->performance_level_count++]);
3782 /* Performance levels are arranged from low to high. */
3783 performance_level->memory_clock = memory_clock;
3784 performance_level->engine_clock = engine_clock;
3786 pcie_gen_from_bios = visland_clk_info->ucPCIEGen;
3788 performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap, pcie_gen_from_bios);
3789 performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap, visland_clk_info->usPCIELane);
3794 static int smu7_get_pp_table_entry_v0(struct pp_hwmgr *hwmgr,
3795 unsigned long entry_index, struct pp_power_state *state)
3798 struct smu7_power_state *ps;
3799 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3800 struct phm_clock_voltage_dependency_table *dep_mclk_table =
3801 hwmgr->dyn_state.vddci_dependency_on_mclk;
3803 memset(&state->hardware, 0x00, sizeof(struct pp_hw_power_state));
3805 state->hardware.magic = PHM_VIslands_Magic;
3807 ps = (struct smu7_power_state *)(&state->hardware);
3809 result = pp_tables_get_entry(hwmgr, entry_index, state,
3810 smu7_get_pp_table_entry_callback_func_v0);
3813 * This is the earliest time we have all the dependency table
3814 * and the VBIOS boot state as
3815 * PP_Tables_GetPowerPlayTableEntry retrieves the VBIOS boot
3816 * state if there is only one VDDCI/MCLK level, check if it's
3817 * the same as VBIOS boot state
3819 if (dep_mclk_table != NULL && dep_mclk_table->count == 1) {
3820 if (dep_mclk_table->entries[0].clk !=
3821 data->vbios_boot_state.mclk_bootup_value)
3822 pr_debug("Single MCLK entry VDDCI/MCLK dependency table "
3823 "does not match VBIOS boot MCLK level");
3824 if (dep_mclk_table->entries[0].v !=
3825 data->vbios_boot_state.vddci_bootup_value)
3826 pr_debug("Single VDDCI entry VDDCI/MCLK dependency table "
3827 "does not match VBIOS boot VDDCI level");
3830 /* set DC compatible flag if this state supports DC */
3831 if (!state->validation.disallowOnDC)
3832 ps->dc_compatible = true;
3834 if (state->classification.flags & PP_StateClassificationFlag_ACPI)
3835 data->acpi_pcie_gen = ps->performance_levels[0].pcie_gen;
3837 ps->uvd_clks.vclk = state->uvd_clocks.VCLK;
3838 ps->uvd_clks.dclk = state->uvd_clocks.DCLK;
3843 switch (state->classification.ui_label) {
3844 case PP_StateUILabel_Performance:
3845 data->use_pcie_performance_levels = true;
3847 for (i = 0; i < ps->performance_level_count; i++) {
3848 if (data->pcie_gen_performance.max <
3849 ps->performance_levels[i].pcie_gen)
3850 data->pcie_gen_performance.max =
3851 ps->performance_levels[i].pcie_gen;
3853 if (data->pcie_gen_performance.min >
3854 ps->performance_levels[i].pcie_gen)
3855 data->pcie_gen_performance.min =
3856 ps->performance_levels[i].pcie_gen;
3858 if (data->pcie_lane_performance.max <
3859 ps->performance_levels[i].pcie_lane)
3860 data->pcie_lane_performance.max =
3861 ps->performance_levels[i].pcie_lane;
3863 if (data->pcie_lane_performance.min >
3864 ps->performance_levels[i].pcie_lane)
3865 data->pcie_lane_performance.min =
3866 ps->performance_levels[i].pcie_lane;
3869 case PP_StateUILabel_Battery:
3870 data->use_pcie_power_saving_levels = true;
3872 for (i = 0; i < ps->performance_level_count; i++) {
3873 if (data->pcie_gen_power_saving.max <
3874 ps->performance_levels[i].pcie_gen)
3875 data->pcie_gen_power_saving.max =
3876 ps->performance_levels[i].pcie_gen;
3878 if (data->pcie_gen_power_saving.min >
3879 ps->performance_levels[i].pcie_gen)
3880 data->pcie_gen_power_saving.min =
3881 ps->performance_levels[i].pcie_gen;
3883 if (data->pcie_lane_power_saving.max <
3884 ps->performance_levels[i].pcie_lane)
3885 data->pcie_lane_power_saving.max =
3886 ps->performance_levels[i].pcie_lane;
3888 if (data->pcie_lane_power_saving.min >
3889 ps->performance_levels[i].pcie_lane)
3890 data->pcie_lane_power_saving.min =
3891 ps->performance_levels[i].pcie_lane;
3901 static int smu7_get_pp_table_entry(struct pp_hwmgr *hwmgr,
3902 unsigned long entry_index, struct pp_power_state *state)
3904 if (hwmgr->pp_table_version == PP_TABLE_V0)
3905 return smu7_get_pp_table_entry_v0(hwmgr, entry_index, state);
3906 else if (hwmgr->pp_table_version == PP_TABLE_V1)
3907 return smu7_get_pp_table_entry_v1(hwmgr, entry_index, state);
3912 static int smu7_get_gpu_power(struct pp_hwmgr *hwmgr, u32 *query)
3914 struct amdgpu_device *adev = hwmgr->adev;
3922 * PPSMC_MSG_GetCurrPkgPwr is not supported on:
3928 if ((adev->asic_type != CHIP_HAWAII) &&
3929 (adev->asic_type != CHIP_BONAIRE) &&
3930 (adev->asic_type != CHIP_FIJI) &&
3931 (adev->asic_type != CHIP_TONGA)) {
3932 smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_GetCurrPkgPwr, 0, &tmp);
3939 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_PmStatusLogStart, NULL);
3940 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3941 ixSMU_PM_STATUS_95, 0);
3943 for (i = 0; i < 10; i++) {
3945 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_PmStatusLogSample, NULL);
3946 tmp = cgs_read_ind_register(hwmgr->device,
3948 ixSMU_PM_STATUS_95);
3957 static int smu7_read_sensor(struct pp_hwmgr *hwmgr, int idx,
3958 void *value, int *size)
3960 uint32_t sclk, mclk, activity_percent;
3961 uint32_t offset, val_vid;
3962 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3964 /* size must be at least 4 bytes for all sensors */
3969 case AMDGPU_PP_SENSOR_GFX_SCLK:
3970 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_API_GetSclkFrequency, &sclk);
3971 *((uint32_t *)value) = sclk;
3974 case AMDGPU_PP_SENSOR_GFX_MCLK:
3975 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_API_GetMclkFrequency, &mclk);
3976 *((uint32_t *)value) = mclk;
3979 case AMDGPU_PP_SENSOR_GPU_LOAD:
3980 case AMDGPU_PP_SENSOR_MEM_LOAD:
3981 offset = data->soft_regs_start + smum_get_offsetof(hwmgr,
3983 (idx == AMDGPU_PP_SENSOR_GPU_LOAD) ?
3984 AverageGraphicsActivity:
3985 AverageMemoryActivity);
3987 activity_percent = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, offset);
3988 activity_percent += 0x80;
3989 activity_percent >>= 8;
3990 *((uint32_t *)value) = activity_percent > 100 ? 100 : activity_percent;
3993 case AMDGPU_PP_SENSOR_GPU_TEMP:
3994 *((uint32_t *)value) = smu7_thermal_get_temperature(hwmgr);
3997 case AMDGPU_PP_SENSOR_UVD_POWER:
3998 *((uint32_t *)value) = data->uvd_power_gated ? 0 : 1;
4001 case AMDGPU_PP_SENSOR_VCE_POWER:
4002 *((uint32_t *)value) = data->vce_power_gated ? 0 : 1;
4005 case AMDGPU_PP_SENSOR_GPU_POWER:
4006 return smu7_get_gpu_power(hwmgr, (uint32_t *)value);
4007 case AMDGPU_PP_SENSOR_VDDGFX:
4008 if ((data->vr_config & VRCONF_VDDGFX_MASK) ==
4009 (VR_SVI2_PLANE_2 << VRCONF_VDDGFX_SHIFT))
4010 val_vid = PHM_READ_INDIRECT_FIELD(hwmgr->device,
4011 CGS_IND_REG__SMC, PWR_SVI2_STATUS, PLANE2_VID);
4013 val_vid = PHM_READ_INDIRECT_FIELD(hwmgr->device,
4014 CGS_IND_REG__SMC, PWR_SVI2_STATUS, PLANE1_VID);
4016 *((uint32_t *)value) = (uint32_t)convert_to_vddc(val_vid);
4023 static int smu7_find_dpm_states_clocks_in_dpm_table(struct pp_hwmgr *hwmgr, const void *input)
4025 const struct phm_set_power_state_input *states =
4026 (const struct phm_set_power_state_input *)input;
4027 const struct smu7_power_state *smu7_ps =
4028 cast_const_phw_smu7_power_state(states->pnew_state);
4029 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4030 struct smu7_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
4031 uint32_t sclk = smu7_ps->performance_levels
4032 [smu7_ps->performance_level_count - 1].engine_clock;
4033 struct smu7_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
4034 uint32_t mclk = smu7_ps->performance_levels
4035 [smu7_ps->performance_level_count - 1].memory_clock;
4036 struct PP_Clocks min_clocks = {0};
4039 for (i = 0; i < sclk_table->count; i++) {
4040 if (sclk == sclk_table->dpm_levels[i].value)
4044 if (i >= sclk_table->count) {
4045 if (sclk > sclk_table->dpm_levels[i-1].value) {
4046 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK;
4047 sclk_table->dpm_levels[i-1].value = sclk;
4050 /* TODO: Check SCLK in DAL's minimum clocks
4051 * in case DeepSleep divider update is required.
4053 if (data->display_timing.min_clock_in_sr != min_clocks.engineClockInSR &&
4054 (min_clocks.engineClockInSR >= SMU7_MINIMUM_ENGINE_CLOCK ||
4055 data->display_timing.min_clock_in_sr >= SMU7_MINIMUM_ENGINE_CLOCK))
4056 data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_SCLK;
4059 for (i = 0; i < mclk_table->count; i++) {
4060 if (mclk == mclk_table->dpm_levels[i].value)
4064 if (i >= mclk_table->count) {
4065 if (mclk > mclk_table->dpm_levels[i-1].value) {
4066 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_MCLK;
4067 mclk_table->dpm_levels[i-1].value = mclk;
4071 if (data->display_timing.num_existing_displays != hwmgr->display_config->num_display)
4072 data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_MCLK;
4077 static uint16_t smu7_get_maximum_link_speed(struct pp_hwmgr *hwmgr,
4078 const struct smu7_power_state *smu7_ps)
4081 uint32_t sclk, max_sclk = 0;
4082 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4083 struct smu7_dpm_table *dpm_table = &data->dpm_table;
4085 for (i = 0; i < smu7_ps->performance_level_count; i++) {
4086 sclk = smu7_ps->performance_levels[i].engine_clock;
4087 if (max_sclk < sclk)
4091 for (i = 0; i < dpm_table->sclk_table.count; i++) {
4092 if (dpm_table->sclk_table.dpm_levels[i].value == max_sclk)
4093 return (uint16_t) ((i >= dpm_table->pcie_speed_table.count) ?
4094 dpm_table->pcie_speed_table.dpm_levels
4095 [dpm_table->pcie_speed_table.count - 1].value :
4096 dpm_table->pcie_speed_table.dpm_levels[i].value);
4102 static int smu7_request_link_speed_change_before_state_change(
4103 struct pp_hwmgr *hwmgr, const void *input)
4105 const struct phm_set_power_state_input *states =
4106 (const struct phm_set_power_state_input *)input;
4107 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4108 const struct smu7_power_state *smu7_nps =
4109 cast_const_phw_smu7_power_state(states->pnew_state);
4110 const struct smu7_power_state *polaris10_cps =
4111 cast_const_phw_smu7_power_state(states->pcurrent_state);
4113 uint16_t target_link_speed = smu7_get_maximum_link_speed(hwmgr, smu7_nps);
4114 uint16_t current_link_speed;
4116 if (data->force_pcie_gen == PP_PCIEGenInvalid)
4117 current_link_speed = smu7_get_maximum_link_speed(hwmgr, polaris10_cps);
4119 current_link_speed = data->force_pcie_gen;
4121 data->force_pcie_gen = PP_PCIEGenInvalid;
4122 data->pspp_notify_required = false;
4124 if (target_link_speed > current_link_speed) {
4125 switch (target_link_speed) {
4128 if (0 == amdgpu_acpi_pcie_performance_request(hwmgr->adev, PCIE_PERF_REQ_GEN3, false))
4130 data->force_pcie_gen = PP_PCIEGen2;
4131 if (current_link_speed == PP_PCIEGen2)
4135 if (0 == amdgpu_acpi_pcie_performance_request(hwmgr->adev, PCIE_PERF_REQ_GEN2, false))
4140 data->force_pcie_gen = smu7_get_current_pcie_speed(hwmgr);
4144 if (target_link_speed < current_link_speed)
4145 data->pspp_notify_required = true;
4151 static int smu7_freeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
4153 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4155 if (0 == data->need_update_smu7_dpm_table)
4158 if ((0 == data->sclk_dpm_key_disabled) &&
4159 (data->need_update_smu7_dpm_table &
4160 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
4161 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
4162 "Trying to freeze SCLK DPM when DPM is disabled",
4164 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr,
4165 PPSMC_MSG_SCLKDPM_FreezeLevel,
4167 "Failed to freeze SCLK DPM during FreezeSclkMclkDPM Function!",
4171 if ((0 == data->mclk_dpm_key_disabled) &&
4172 !data->mclk_ignore_signal &&
4173 (data->need_update_smu7_dpm_table &
4174 DPMTABLE_OD_UPDATE_MCLK)) {
4175 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
4176 "Trying to freeze MCLK DPM when DPM is disabled",
4178 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr,
4179 PPSMC_MSG_MCLKDPM_FreezeLevel,
4181 "Failed to freeze MCLK DPM during FreezeSclkMclkDPM Function!",
4188 static int smu7_populate_and_upload_sclk_mclk_dpm_levels(
4189 struct pp_hwmgr *hwmgr, const void *input)
4192 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4193 struct smu7_dpm_table *dpm_table = &data->dpm_table;
4195 struct smu7_odn_dpm_table *odn_table = &(data->odn_dpm_table);
4196 struct phm_odn_clock_levels *odn_sclk_table = &(odn_table->odn_core_clock_dpm_levels);
4197 struct phm_odn_clock_levels *odn_mclk_table = &(odn_table->odn_memory_clock_dpm_levels);
4199 if (0 == data->need_update_smu7_dpm_table)
4202 if (hwmgr->od_enabled && data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_SCLK) {
4203 for (count = 0; count < dpm_table->sclk_table.count; count++) {
4204 dpm_table->sclk_table.dpm_levels[count].enabled = odn_sclk_table->entries[count].enabled;
4205 dpm_table->sclk_table.dpm_levels[count].value = odn_sclk_table->entries[count].clock;
4209 if (hwmgr->od_enabled && data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK) {
4210 for (count = 0; count < dpm_table->mclk_table.count; count++) {
4211 dpm_table->mclk_table.dpm_levels[count].enabled = odn_mclk_table->entries[count].enabled;
4212 dpm_table->mclk_table.dpm_levels[count].value = odn_mclk_table->entries[count].clock;
4216 if (data->need_update_smu7_dpm_table &
4217 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK)) {
4218 result = smum_populate_all_graphic_levels(hwmgr);
4219 PP_ASSERT_WITH_CODE((0 == result),
4220 "Failed to populate SCLK during PopulateNewDPMClocksStates Function!",
4224 if (data->need_update_smu7_dpm_table &
4225 (DPMTABLE_OD_UPDATE_MCLK + DPMTABLE_UPDATE_MCLK)) {
4226 /*populate MCLK dpm table to SMU7 */
4227 result = smum_populate_all_memory_levels(hwmgr);
4228 PP_ASSERT_WITH_CODE((0 == result),
4229 "Failed to populate MCLK during PopulateNewDPMClocksStates Function!",
4236 static int smu7_trim_single_dpm_states(struct pp_hwmgr *hwmgr,
4237 struct smu7_single_dpm_table *dpm_table,
4238 uint32_t low_limit, uint32_t high_limit)
4242 /* force the trim if mclk_switching is disabled to prevent flicker */
4243 bool force_trim = (low_limit == high_limit);
4244 for (i = 0; i < dpm_table->count; i++) {
4245 /*skip the trim if od is enabled*/
4246 if ((!hwmgr->od_enabled || force_trim)
4247 && (dpm_table->dpm_levels[i].value < low_limit
4248 || dpm_table->dpm_levels[i].value > high_limit))
4249 dpm_table->dpm_levels[i].enabled = false;
4251 dpm_table->dpm_levels[i].enabled = true;
4257 static int smu7_trim_dpm_states(struct pp_hwmgr *hwmgr,
4258 const struct smu7_power_state *smu7_ps)
4260 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4261 uint32_t high_limit_count;
4263 PP_ASSERT_WITH_CODE((smu7_ps->performance_level_count >= 1),
4264 "power state did not have any performance level",
4267 high_limit_count = (1 == smu7_ps->performance_level_count) ? 0 : 1;
4269 smu7_trim_single_dpm_states(hwmgr,
4270 &(data->dpm_table.sclk_table),
4271 smu7_ps->performance_levels[0].engine_clock,
4272 smu7_ps->performance_levels[high_limit_count].engine_clock);
4274 smu7_trim_single_dpm_states(hwmgr,
4275 &(data->dpm_table.mclk_table),
4276 smu7_ps->performance_levels[0].memory_clock,
4277 smu7_ps->performance_levels[high_limit_count].memory_clock);
4282 static int smu7_generate_dpm_level_enable_mask(
4283 struct pp_hwmgr *hwmgr, const void *input)
4286 const struct phm_set_power_state_input *states =
4287 (const struct phm_set_power_state_input *)input;
4288 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4289 const struct smu7_power_state *smu7_ps =
4290 cast_const_phw_smu7_power_state(states->pnew_state);
4293 result = smu7_trim_dpm_states(hwmgr, smu7_ps);
4297 data->dpm_level_enable_mask.sclk_dpm_enable_mask =
4298 phm_get_dpm_level_enable_mask_value(&data->dpm_table.sclk_table);
4299 data->dpm_level_enable_mask.mclk_dpm_enable_mask =
4300 phm_get_dpm_level_enable_mask_value(&data->dpm_table.mclk_table);
4301 data->dpm_level_enable_mask.pcie_dpm_enable_mask =
4302 phm_get_dpm_level_enable_mask_value(&data->dpm_table.pcie_speed_table);
4307 static int smu7_unfreeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
4309 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4311 if (0 == data->need_update_smu7_dpm_table)
4314 if ((0 == data->sclk_dpm_key_disabled) &&
4315 (data->need_update_smu7_dpm_table &
4316 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
4318 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
4319 "Trying to Unfreeze SCLK DPM when DPM is disabled",
4321 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr,
4322 PPSMC_MSG_SCLKDPM_UnfreezeLevel,
4324 "Failed to unfreeze SCLK DPM during UnFreezeSclkMclkDPM Function!",
4328 if ((0 == data->mclk_dpm_key_disabled) &&
4329 !data->mclk_ignore_signal &&
4330 (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) {
4332 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
4333 "Trying to Unfreeze MCLK DPM when DPM is disabled",
4335 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr,
4336 PPSMC_MSG_MCLKDPM_UnfreezeLevel,
4338 "Failed to unfreeze MCLK DPM during UnFreezeSclkMclkDPM Function!",
4342 data->need_update_smu7_dpm_table &= DPMTABLE_OD_UPDATE_VDDC;
4347 static int smu7_notify_link_speed_change_after_state_change(
4348 struct pp_hwmgr *hwmgr, const void *input)
4350 const struct phm_set_power_state_input *states =
4351 (const struct phm_set_power_state_input *)input;
4352 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4353 const struct smu7_power_state *smu7_ps =
4354 cast_const_phw_smu7_power_state(states->pnew_state);
4355 uint16_t target_link_speed = smu7_get_maximum_link_speed(hwmgr, smu7_ps);
4358 if (data->pspp_notify_required) {
4359 if (target_link_speed == PP_PCIEGen3)
4360 request = PCIE_PERF_REQ_GEN3;
4361 else if (target_link_speed == PP_PCIEGen2)
4362 request = PCIE_PERF_REQ_GEN2;
4364 request = PCIE_PERF_REQ_GEN1;
4366 if (request == PCIE_PERF_REQ_GEN1 &&
4367 smu7_get_current_pcie_speed(hwmgr) > 0)
4371 if (amdgpu_acpi_pcie_performance_request(hwmgr->adev, request, false)) {
4372 if (PP_PCIEGen2 == target_link_speed)
4373 pr_info("PSPP request to switch to Gen2 from Gen3 Failed!");
4375 pr_info("PSPP request to switch to Gen1 from Gen2 Failed!");
4383 static int smu7_notify_no_display(struct pp_hwmgr *hwmgr)
4385 return (smum_send_msg_to_smc(hwmgr, (PPSMC_Msg)PPSMC_NoDisplay, NULL) == 0) ? 0 : -EINVAL;
4388 static int smu7_notify_has_display(struct pp_hwmgr *hwmgr)
4390 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4392 if (hwmgr->feature_mask & PP_VBI_TIME_SUPPORT_MASK) {
4393 if (hwmgr->chip_id == CHIP_VEGAM)
4394 smum_send_msg_to_smc_with_parameter(hwmgr,
4395 (PPSMC_Msg)PPSMC_MSG_SetVBITimeout_VEGAM, data->frame_time_x2,
4398 smum_send_msg_to_smc_with_parameter(hwmgr,
4399 (PPSMC_Msg)PPSMC_MSG_SetVBITimeout, data->frame_time_x2,
4401 data->last_sent_vbi_timeout = data->frame_time_x2;
4404 return (smum_send_msg_to_smc(hwmgr, (PPSMC_Msg)PPSMC_HasDisplay, NULL) == 0) ? 0 : -EINVAL;
4407 static int smu7_notify_smc_display(struct pp_hwmgr *hwmgr)
4409 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4412 if (data->mclk_ignore_signal)
4413 result = smu7_notify_no_display(hwmgr);
4415 result = smu7_notify_has_display(hwmgr);
4420 static int smu7_set_power_state_tasks(struct pp_hwmgr *hwmgr, const void *input)
4422 int tmp_result, result = 0;
4423 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4425 tmp_result = smu7_find_dpm_states_clocks_in_dpm_table(hwmgr, input);
4426 PP_ASSERT_WITH_CODE((0 == tmp_result),
4427 "Failed to find DPM states clocks in DPM table!",
4428 result = tmp_result);
4430 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4431 PHM_PlatformCaps_PCIEPerformanceRequest)) {
4433 smu7_request_link_speed_change_before_state_change(hwmgr, input);
4434 PP_ASSERT_WITH_CODE((0 == tmp_result),
4435 "Failed to request link speed change before state change!",
4436 result = tmp_result);
4439 tmp_result = smu7_freeze_sclk_mclk_dpm(hwmgr);
4440 PP_ASSERT_WITH_CODE((0 == tmp_result),
4441 "Failed to freeze SCLK MCLK DPM!", result = tmp_result);
4443 tmp_result = smu7_populate_and_upload_sclk_mclk_dpm_levels(hwmgr, input);
4444 PP_ASSERT_WITH_CODE((0 == tmp_result),
4445 "Failed to populate and upload SCLK MCLK DPM levels!",
4446 result = tmp_result);
4449 * If a custom pp table is loaded, set DPMTABLE_OD_UPDATE_VDDC flag.
4450 * That effectively disables AVFS feature.
4452 if (hwmgr->hardcode_pp_table != NULL)
4453 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_VDDC;
4455 tmp_result = smu7_update_avfs(hwmgr);
4456 PP_ASSERT_WITH_CODE((0 == tmp_result),
4457 "Failed to update avfs voltages!",
4458 result = tmp_result);
4460 tmp_result = smu7_generate_dpm_level_enable_mask(hwmgr, input);
4461 PP_ASSERT_WITH_CODE((0 == tmp_result),
4462 "Failed to generate DPM level enabled mask!",
4463 result = tmp_result);
4465 tmp_result = smum_update_sclk_threshold(hwmgr);
4466 PP_ASSERT_WITH_CODE((0 == tmp_result),
4467 "Failed to update SCLK threshold!",
4468 result = tmp_result);
4470 tmp_result = smu7_unfreeze_sclk_mclk_dpm(hwmgr);
4471 PP_ASSERT_WITH_CODE((0 == tmp_result),
4472 "Failed to unfreeze SCLK MCLK DPM!",
4473 result = tmp_result);
4475 tmp_result = smu7_upload_dpm_level_enable_mask(hwmgr);
4476 PP_ASSERT_WITH_CODE((0 == tmp_result),
4477 "Failed to upload DPM level enabled mask!",
4478 result = tmp_result);
4480 tmp_result = smu7_notify_smc_display(hwmgr);
4481 PP_ASSERT_WITH_CODE((0 == tmp_result),
4482 "Failed to notify smc display settings!",
4483 result = tmp_result);
4485 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4486 PHM_PlatformCaps_PCIEPerformanceRequest)) {
4488 smu7_notify_link_speed_change_after_state_change(hwmgr, input);
4489 PP_ASSERT_WITH_CODE((0 == tmp_result),
4490 "Failed to notify link speed change after state change!",
4491 result = tmp_result);
4493 data->apply_optimized_settings = false;
4497 static int smu7_set_max_fan_pwm_output(struct pp_hwmgr *hwmgr, uint16_t us_max_fan_pwm)
4499 hwmgr->thermal_controller.
4500 advanceFanControlParameters.usMaxFanPWM = us_max_fan_pwm;
4502 return smum_send_msg_to_smc_with_parameter(hwmgr,
4503 PPSMC_MSG_SetFanPwmMax, us_max_fan_pwm,
4508 smu7_notify_smc_display_config_after_ps_adjustment(struct pp_hwmgr *hwmgr)
4514 * smu7_program_display_gap - Programs the display gap
4516 * @hwmgr: the address of the powerplay hardware manager.
4519 static int smu7_program_display_gap(struct pp_hwmgr *hwmgr)
4521 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4522 uint32_t display_gap = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL);
4523 uint32_t display_gap2;
4524 uint32_t pre_vbi_time_in_us;
4525 uint32_t frame_time_in_us;
4526 uint32_t ref_clock, refresh_rate;
4528 display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL, DISP_GAP, (hwmgr->display_config->num_display > 0) ? DISPLAY_GAP_VBLANK_OR_WM : DISPLAY_GAP_IGNORE);
4529 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL, display_gap);
4531 ref_clock = amdgpu_asic_get_xclk((struct amdgpu_device *)hwmgr->adev);
4532 refresh_rate = hwmgr->display_config->vrefresh;
4534 if (0 == refresh_rate)
4537 frame_time_in_us = 1000000 / refresh_rate;
4539 pre_vbi_time_in_us = frame_time_in_us - 200 - hwmgr->display_config->min_vblank_time;
4541 data->frame_time_x2 = frame_time_in_us * 2 / 100;
4543 if (data->frame_time_x2 < 280) {
4544 pr_debug("%s: enforce minimal VBITimeout: %d -> 280\n", __func__, data->frame_time_x2);
4545 data->frame_time_x2 = 280;
4548 display_gap2 = pre_vbi_time_in_us * (ref_clock / 100);
4550 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL2, display_gap2);
4552 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
4553 data->soft_regs_start + smum_get_offsetof(hwmgr,
4555 PreVBlankGap), 0x64);
4557 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
4558 data->soft_regs_start + smum_get_offsetof(hwmgr,
4561 (frame_time_in_us - pre_vbi_time_in_us));
4566 static int smu7_display_configuration_changed_task(struct pp_hwmgr *hwmgr)
4568 return smu7_program_display_gap(hwmgr);
4572 * smu7_set_max_fan_rpm_output - Set maximum target operating fan output RPM
4574 * @hwmgr: the address of the powerplay hardware manager.
4575 * @us_max_fan_rpm: max operating fan RPM value.
4576 * Return: The response that came from the SMC.
4578 static int smu7_set_max_fan_rpm_output(struct pp_hwmgr *hwmgr, uint16_t us_max_fan_rpm)
4580 hwmgr->thermal_controller.
4581 advanceFanControlParameters.usMaxFanRPM = us_max_fan_rpm;
4583 return smum_send_msg_to_smc_with_parameter(hwmgr,
4584 PPSMC_MSG_SetFanRpmMax, us_max_fan_rpm,
4588 static const struct amdgpu_irq_src_funcs smu7_irq_funcs = {
4589 .process = phm_irq_process,
4592 static int smu7_register_irq_handlers(struct pp_hwmgr *hwmgr)
4594 struct amdgpu_irq_src *source =
4595 kzalloc(sizeof(struct amdgpu_irq_src), GFP_KERNEL);
4600 source->funcs = &smu7_irq_funcs;
4602 amdgpu_irq_add_id((struct amdgpu_device *)(hwmgr->adev),
4603 AMDGPU_IRQ_CLIENTID_LEGACY,
4604 VISLANDS30_IV_SRCID_CG_TSS_THERMAL_LOW_TO_HIGH,
4606 amdgpu_irq_add_id((struct amdgpu_device *)(hwmgr->adev),
4607 AMDGPU_IRQ_CLIENTID_LEGACY,
4608 VISLANDS30_IV_SRCID_CG_TSS_THERMAL_HIGH_TO_LOW,
4611 /* Register CTF(GPIO_19) interrupt */
4612 amdgpu_irq_add_id((struct amdgpu_device *)(hwmgr->adev),
4613 AMDGPU_IRQ_CLIENTID_LEGACY,
4614 VISLANDS30_IV_SRCID_GPIO_19,
4621 smu7_check_smc_update_required_for_display_configuration(struct pp_hwmgr *hwmgr)
4623 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4624 bool is_update_required = false;
4626 if (data->display_timing.num_existing_displays != hwmgr->display_config->num_display)
4627 is_update_required = true;
4629 if (data->display_timing.vrefresh != hwmgr->display_config->vrefresh)
4630 is_update_required = true;
4632 if (hwmgr->chip_id >= CHIP_POLARIS10 &&
4633 hwmgr->chip_id <= CHIP_VEGAM &&
4634 data->last_sent_vbi_timeout != data->frame_time_x2)
4635 is_update_required = true;
4637 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep)) {
4638 if (data->display_timing.min_clock_in_sr != hwmgr->display_config->min_core_set_clock_in_sr &&
4639 (data->display_timing.min_clock_in_sr >= SMU7_MINIMUM_ENGINE_CLOCK ||
4640 hwmgr->display_config->min_core_set_clock_in_sr >= SMU7_MINIMUM_ENGINE_CLOCK))
4641 is_update_required = true;
4643 return is_update_required;
4646 static inline bool smu7_are_power_levels_equal(const struct smu7_performance_level *pl1,
4647 const struct smu7_performance_level *pl2)
4649 return ((pl1->memory_clock == pl2->memory_clock) &&
4650 (pl1->engine_clock == pl2->engine_clock) &&
4651 (pl1->pcie_gen == pl2->pcie_gen) &&
4652 (pl1->pcie_lane == pl2->pcie_lane));
4655 static int smu7_check_states_equal(struct pp_hwmgr *hwmgr,
4656 const struct pp_hw_power_state *pstate1,
4657 const struct pp_hw_power_state *pstate2, bool *equal)
4659 const struct smu7_power_state *psa;
4660 const struct smu7_power_state *psb;
4662 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4664 if (pstate1 == NULL || pstate2 == NULL || equal == NULL)
4667 psa = cast_const_phw_smu7_power_state(pstate1);
4668 psb = cast_const_phw_smu7_power_state(pstate2);
4669 /* If the two states don't even have the same number of performance levels they cannot be the same state. */
4670 if (psa->performance_level_count != psb->performance_level_count) {
4675 for (i = 0; i < psa->performance_level_count; i++) {
4676 if (!smu7_are_power_levels_equal(&(psa->performance_levels[i]), &(psb->performance_levels[i]))) {
4677 /* If we have found even one performance level pair that is different the states are different. */
4683 /* If all performance levels are the same try to use the UVD clocks to break the tie.*/
4684 *equal = ((psa->uvd_clks.vclk == psb->uvd_clks.vclk) && (psa->uvd_clks.dclk == psb->uvd_clks.dclk));
4685 *equal &= ((psa->vce_clks.evclk == psb->vce_clks.evclk) && (psa->vce_clks.ecclk == psb->vce_clks.ecclk));
4686 *equal &= (psa->sclk_threshold == psb->sclk_threshold);
4687 /* For OD call, set value based on flag */
4688 *equal &= !(data->need_update_smu7_dpm_table & (DPMTABLE_OD_UPDATE_SCLK |
4689 DPMTABLE_OD_UPDATE_MCLK |
4690 DPMTABLE_OD_UPDATE_VDDC));
4695 static int smu7_check_mc_firmware(struct pp_hwmgr *hwmgr)
4697 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4701 /* Read MC indirect register offset 0x9F bits [3:0] to see
4702 * if VBIOS has already loaded a full version of MC ucode
4706 smu7_get_mc_microcode_version(hwmgr);
4708 data->need_long_memory_training = false;
4710 cgs_write_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_INDEX,
4711 ixMC_IO_DEBUG_UP_13);
4712 tmp = cgs_read_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_DATA);
4714 if (tmp & (1 << 23)) {
4715 data->mem_latency_high = MEM_LATENCY_HIGH;
4716 data->mem_latency_low = MEM_LATENCY_LOW;
4717 if ((hwmgr->chip_id == CHIP_POLARIS10) ||
4718 (hwmgr->chip_id == CHIP_POLARIS11) ||
4719 (hwmgr->chip_id == CHIP_POLARIS12))
4720 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_EnableFFC, NULL);
4722 data->mem_latency_high = 330;
4723 data->mem_latency_low = 330;
4724 if ((hwmgr->chip_id == CHIP_POLARIS10) ||
4725 (hwmgr->chip_id == CHIP_POLARIS11) ||
4726 (hwmgr->chip_id == CHIP_POLARIS12))
4727 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_DisableFFC, NULL);
4733 static int smu7_read_clock_registers(struct pp_hwmgr *hwmgr)
4735 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4737 data->clock_registers.vCG_SPLL_FUNC_CNTL =
4738 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL);
4739 data->clock_registers.vCG_SPLL_FUNC_CNTL_2 =
4740 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_2);
4741 data->clock_registers.vCG_SPLL_FUNC_CNTL_3 =
4742 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_3);
4743 data->clock_registers.vCG_SPLL_FUNC_CNTL_4 =
4744 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_4);
4745 data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM =
4746 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_SPREAD_SPECTRUM);
4747 data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2 =
4748 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_SPREAD_SPECTRUM_2);
4749 data->clock_registers.vDLL_CNTL =
4750 cgs_read_register(hwmgr->device, mmDLL_CNTL);
4751 data->clock_registers.vMCLK_PWRMGT_CNTL =
4752 cgs_read_register(hwmgr->device, mmMCLK_PWRMGT_CNTL);
4753 data->clock_registers.vMPLL_AD_FUNC_CNTL =
4754 cgs_read_register(hwmgr->device, mmMPLL_AD_FUNC_CNTL);
4755 data->clock_registers.vMPLL_DQ_FUNC_CNTL =
4756 cgs_read_register(hwmgr->device, mmMPLL_DQ_FUNC_CNTL);
4757 data->clock_registers.vMPLL_FUNC_CNTL =
4758 cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL);
4759 data->clock_registers.vMPLL_FUNC_CNTL_1 =
4760 cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL_1);
4761 data->clock_registers.vMPLL_FUNC_CNTL_2 =
4762 cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL_2);
4763 data->clock_registers.vMPLL_SS1 =
4764 cgs_read_register(hwmgr->device, mmMPLL_SS1);
4765 data->clock_registers.vMPLL_SS2 =
4766 cgs_read_register(hwmgr->device, mmMPLL_SS2);
4772 * smu7_get_memory_type - Find out if memory is GDDR5.
4774 * @hwmgr: the address of the powerplay hardware manager.
4777 static int smu7_get_memory_type(struct pp_hwmgr *hwmgr)
4779 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4780 struct amdgpu_device *adev = hwmgr->adev;
4782 data->is_memory_gddr5 = (adev->gmc.vram_type == AMDGPU_VRAM_TYPE_GDDR5);
4788 * smu7_enable_acpi_power_management - Enables Dynamic Power Management by SMC
4790 * @hwmgr: the address of the powerplay hardware manager.
4793 static int smu7_enable_acpi_power_management(struct pp_hwmgr *hwmgr)
4795 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
4796 GENERAL_PWRMGT, STATIC_PM_EN, 1);
4802 * smu7_init_power_gate_state - Initialize PowerGating States for different engines
4804 * @hwmgr: the address of the powerplay hardware manager.
4807 static int smu7_init_power_gate_state(struct pp_hwmgr *hwmgr)
4809 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4811 data->uvd_power_gated = false;
4812 data->vce_power_gated = false;
4817 static int smu7_init_sclk_threshold(struct pp_hwmgr *hwmgr)
4819 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4821 data->low_sclk_interrupt_threshold = 0;
4825 static int smu7_setup_asic_task(struct pp_hwmgr *hwmgr)
4827 int tmp_result, result = 0;
4829 smu7_check_mc_firmware(hwmgr);
4831 tmp_result = smu7_read_clock_registers(hwmgr);
4832 PP_ASSERT_WITH_CODE((0 == tmp_result),
4833 "Failed to read clock registers!", result = tmp_result);
4835 tmp_result = smu7_get_memory_type(hwmgr);
4836 PP_ASSERT_WITH_CODE((0 == tmp_result),
4837 "Failed to get memory type!", result = tmp_result);
4839 tmp_result = smu7_enable_acpi_power_management(hwmgr);
4840 PP_ASSERT_WITH_CODE((0 == tmp_result),
4841 "Failed to enable ACPI power management!", result = tmp_result);
4843 tmp_result = smu7_init_power_gate_state(hwmgr);
4844 PP_ASSERT_WITH_CODE((0 == tmp_result),
4845 "Failed to init power gate state!", result = tmp_result);
4847 tmp_result = smu7_get_mc_microcode_version(hwmgr);
4848 PP_ASSERT_WITH_CODE((0 == tmp_result),
4849 "Failed to get MC microcode version!", result = tmp_result);
4851 tmp_result = smu7_init_sclk_threshold(hwmgr);
4852 PP_ASSERT_WITH_CODE((0 == tmp_result),
4853 "Failed to init sclk threshold!", result = tmp_result);
4858 static int smu7_force_clock_level(struct pp_hwmgr *hwmgr,
4859 enum pp_clock_type type, uint32_t mask)
4861 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4868 if (!data->sclk_dpm_key_disabled)
4869 smum_send_msg_to_smc_with_parameter(hwmgr,
4870 PPSMC_MSG_SCLKDPM_SetEnabledMask,
4871 data->dpm_level_enable_mask.sclk_dpm_enable_mask & mask,
4875 if (!data->mclk_dpm_key_disabled)
4876 smum_send_msg_to_smc_with_parameter(hwmgr,
4877 PPSMC_MSG_MCLKDPM_SetEnabledMask,
4878 data->dpm_level_enable_mask.mclk_dpm_enable_mask & mask,
4883 uint32_t tmp = mask & data->dpm_level_enable_mask.pcie_dpm_enable_mask;
4885 if (!data->pcie_dpm_key_disabled) {
4886 if (fls(tmp) != ffs(tmp))
4887 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_PCIeDPM_UnForceLevel,
4890 smum_send_msg_to_smc_with_parameter(hwmgr,
4891 PPSMC_MSG_PCIeDPM_ForceLevel,
4904 static int smu7_print_clock_levels(struct pp_hwmgr *hwmgr,
4905 enum pp_clock_type type, char *buf)
4907 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4908 struct smu7_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
4909 struct smu7_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
4910 struct smu7_single_dpm_table *pcie_table = &(data->dpm_table.pcie_speed_table);
4911 struct smu7_odn_dpm_table *odn_table = &(data->odn_dpm_table);
4912 struct phm_odn_clock_levels *odn_sclk_table = &(odn_table->odn_core_clock_dpm_levels);
4913 struct phm_odn_clock_levels *odn_mclk_table = &(odn_table->odn_memory_clock_dpm_levels);
4915 uint32_t i, now, clock, pcie_speed;
4919 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_API_GetSclkFrequency, &clock);
4921 for (i = 0; i < sclk_table->count; i++) {
4922 if (clock > sclk_table->dpm_levels[i].value)
4928 for (i = 0; i < sclk_table->count; i++)
4929 size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n",
4930 i, sclk_table->dpm_levels[i].value / 100,
4931 (i == now) ? "*" : "");
4934 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_API_GetMclkFrequency, &clock);
4936 for (i = 0; i < mclk_table->count; i++) {
4937 if (clock > mclk_table->dpm_levels[i].value)
4943 for (i = 0; i < mclk_table->count; i++)
4944 size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n",
4945 i, mclk_table->dpm_levels[i].value / 100,
4946 (i == now) ? "*" : "");
4949 pcie_speed = smu7_get_current_pcie_speed(hwmgr);
4950 for (i = 0; i < pcie_table->count; i++) {
4951 if (pcie_speed != pcie_table->dpm_levels[i].value)
4957 for (i = 0; i < pcie_table->count; i++)
4958 size += sysfs_emit_at(buf, size, "%d: %s %s\n", i,
4959 (pcie_table->dpm_levels[i].value == 0) ? "2.5GT/s, x8" :
4960 (pcie_table->dpm_levels[i].value == 1) ? "5.0GT/s, x16" :
4961 (pcie_table->dpm_levels[i].value == 2) ? "8.0GT/s, x16" : "",
4962 (i == now) ? "*" : "");
4965 if (hwmgr->od_enabled) {
4966 size = sysfs_emit(buf, "%s:\n", "OD_SCLK");
4967 for (i = 0; i < odn_sclk_table->num_of_pl; i++)
4968 size += sysfs_emit_at(buf, size, "%d: %10uMHz %10umV\n",
4969 i, odn_sclk_table->entries[i].clock/100,
4970 odn_sclk_table->entries[i].vddc);
4974 if (hwmgr->od_enabled) {
4975 size = sysfs_emit(buf, "%s:\n", "OD_MCLK");
4976 for (i = 0; i < odn_mclk_table->num_of_pl; i++)
4977 size += sysfs_emit_at(buf, size, "%d: %10uMHz %10umV\n",
4978 i, odn_mclk_table->entries[i].clock/100,
4979 odn_mclk_table->entries[i].vddc);
4983 if (hwmgr->od_enabled) {
4984 size = sysfs_emit(buf, "%s:\n", "OD_RANGE");
4985 size += sysfs_emit_at(buf, size, "SCLK: %7uMHz %10uMHz\n",
4986 data->golden_dpm_table.sclk_table.dpm_levels[0].value/100,
4987 hwmgr->platform_descriptor.overdriveLimit.engineClock/100);
4988 size += sysfs_emit_at(buf, size, "MCLK: %7uMHz %10uMHz\n",
4989 data->golden_dpm_table.mclk_table.dpm_levels[0].value/100,
4990 hwmgr->platform_descriptor.overdriveLimit.memoryClock/100);
4991 size += sysfs_emit_at(buf, size, "VDDC: %7umV %11umV\n",
4992 data->odn_dpm_table.min_vddc,
4993 data->odn_dpm_table.max_vddc);
5002 static void smu7_set_fan_control_mode(struct pp_hwmgr *hwmgr, uint32_t mode)
5005 case AMD_FAN_CTRL_NONE:
5006 smu7_fan_ctrl_set_fan_speed_pwm(hwmgr, 255);
5008 case AMD_FAN_CTRL_MANUAL:
5009 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
5010 PHM_PlatformCaps_MicrocodeFanControl))
5011 smu7_fan_ctrl_stop_smc_fan_control(hwmgr);
5013 case AMD_FAN_CTRL_AUTO:
5014 if (!smu7_fan_ctrl_set_static_mode(hwmgr, mode))
5015 smu7_fan_ctrl_start_smc_fan_control(hwmgr);
5022 static uint32_t smu7_get_fan_control_mode(struct pp_hwmgr *hwmgr)
5024 return hwmgr->fan_ctrl_enabled ? AMD_FAN_CTRL_AUTO : AMD_FAN_CTRL_MANUAL;
5027 static int smu7_get_sclk_od(struct pp_hwmgr *hwmgr)
5029 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5030 struct smu7_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
5031 struct smu7_single_dpm_table *golden_sclk_table =
5032 &(data->golden_dpm_table.sclk_table);
5033 int value = sclk_table->dpm_levels[sclk_table->count - 1].value;
5034 int golden_value = golden_sclk_table->dpm_levels
5035 [golden_sclk_table->count - 1].value;
5037 value -= golden_value;
5038 value = DIV_ROUND_UP(value * 100, golden_value);
5043 static int smu7_set_sclk_od(struct pp_hwmgr *hwmgr, uint32_t value)
5045 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5046 struct smu7_single_dpm_table *golden_sclk_table =
5047 &(data->golden_dpm_table.sclk_table);
5048 struct pp_power_state *ps;
5049 struct smu7_power_state *smu7_ps;
5054 ps = hwmgr->request_ps;
5059 smu7_ps = cast_phw_smu7_power_state(&ps->hardware);
5061 smu7_ps->performance_levels[smu7_ps->performance_level_count - 1].engine_clock =
5062 golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value *
5064 golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value;
5069 static int smu7_get_mclk_od(struct pp_hwmgr *hwmgr)
5071 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5072 struct smu7_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
5073 struct smu7_single_dpm_table *golden_mclk_table =
5074 &(data->golden_dpm_table.mclk_table);
5075 int value = mclk_table->dpm_levels[mclk_table->count - 1].value;
5076 int golden_value = golden_mclk_table->dpm_levels
5077 [golden_mclk_table->count - 1].value;
5079 value -= golden_value;
5080 value = DIV_ROUND_UP(value * 100, golden_value);
5085 static int smu7_set_mclk_od(struct pp_hwmgr *hwmgr, uint32_t value)
5087 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5088 struct smu7_single_dpm_table *golden_mclk_table =
5089 &(data->golden_dpm_table.mclk_table);
5090 struct pp_power_state *ps;
5091 struct smu7_power_state *smu7_ps;
5096 ps = hwmgr->request_ps;
5101 smu7_ps = cast_phw_smu7_power_state(&ps->hardware);
5103 smu7_ps->performance_levels[smu7_ps->performance_level_count - 1].memory_clock =
5104 golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value *
5106 golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value;
5112 static int smu7_get_sclks(struct pp_hwmgr *hwmgr, struct amd_pp_clocks *clocks)
5114 struct phm_ppt_v1_information *table_info =
5115 (struct phm_ppt_v1_information *)hwmgr->pptable;
5116 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table = NULL;
5117 struct phm_clock_voltage_dependency_table *sclk_table;
5120 if (hwmgr->pp_table_version == PP_TABLE_V1) {
5121 if (table_info == NULL || table_info->vdd_dep_on_sclk == NULL)
5123 dep_sclk_table = table_info->vdd_dep_on_sclk;
5124 for (i = 0; i < dep_sclk_table->count; i++)
5125 clocks->clock[i] = dep_sclk_table->entries[i].clk * 10;
5126 clocks->count = dep_sclk_table->count;
5127 } else if (hwmgr->pp_table_version == PP_TABLE_V0) {
5128 sclk_table = hwmgr->dyn_state.vddc_dependency_on_sclk;
5129 for (i = 0; i < sclk_table->count; i++)
5130 clocks->clock[i] = sclk_table->entries[i].clk * 10;
5131 clocks->count = sclk_table->count;
5137 static uint32_t smu7_get_mem_latency(struct pp_hwmgr *hwmgr, uint32_t clk)
5139 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5141 if (clk >= MEM_FREQ_LOW_LATENCY && clk < MEM_FREQ_HIGH_LATENCY)
5142 return data->mem_latency_high;
5143 else if (clk >= MEM_FREQ_HIGH_LATENCY)
5144 return data->mem_latency_low;
5146 return MEM_LATENCY_ERR;
5149 static int smu7_get_mclks(struct pp_hwmgr *hwmgr, struct amd_pp_clocks *clocks)
5151 struct phm_ppt_v1_information *table_info =
5152 (struct phm_ppt_v1_information *)hwmgr->pptable;
5153 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table;
5155 struct phm_clock_voltage_dependency_table *mclk_table;
5157 if (hwmgr->pp_table_version == PP_TABLE_V1) {
5158 if (table_info == NULL)
5160 dep_mclk_table = table_info->vdd_dep_on_mclk;
5161 for (i = 0; i < dep_mclk_table->count; i++) {
5162 clocks->clock[i] = dep_mclk_table->entries[i].clk * 10;
5163 clocks->latency[i] = smu7_get_mem_latency(hwmgr,
5164 dep_mclk_table->entries[i].clk);
5166 clocks->count = dep_mclk_table->count;
5167 } else if (hwmgr->pp_table_version == PP_TABLE_V0) {
5168 mclk_table = hwmgr->dyn_state.vddc_dependency_on_mclk;
5169 for (i = 0; i < mclk_table->count; i++)
5170 clocks->clock[i] = mclk_table->entries[i].clk * 10;
5171 clocks->count = mclk_table->count;
5176 static int smu7_get_clock_by_type(struct pp_hwmgr *hwmgr, enum amd_pp_clock_type type,
5177 struct amd_pp_clocks *clocks)
5180 case amd_pp_sys_clock:
5181 smu7_get_sclks(hwmgr, clocks);
5183 case amd_pp_mem_clock:
5184 smu7_get_mclks(hwmgr, clocks);
5193 static int smu7_get_sclks_with_latency(struct pp_hwmgr *hwmgr,
5194 struct pp_clock_levels_with_latency *clocks)
5196 struct phm_ppt_v1_information *table_info =
5197 (struct phm_ppt_v1_information *)hwmgr->pptable;
5198 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table =
5199 table_info->vdd_dep_on_sclk;
5202 clocks->num_levels = 0;
5203 for (i = 0; i < dep_sclk_table->count; i++) {
5204 if (dep_sclk_table->entries[i].clk) {
5205 clocks->data[clocks->num_levels].clocks_in_khz =
5206 dep_sclk_table->entries[i].clk * 10;
5207 clocks->num_levels++;
5214 static int smu7_get_mclks_with_latency(struct pp_hwmgr *hwmgr,
5215 struct pp_clock_levels_with_latency *clocks)
5217 struct phm_ppt_v1_information *table_info =
5218 (struct phm_ppt_v1_information *)hwmgr->pptable;
5219 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
5220 table_info->vdd_dep_on_mclk;
5221 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5224 clocks->num_levels = 0;
5225 data->mclk_latency_table.count = 0;
5226 for (i = 0; i < dep_mclk_table->count; i++) {
5227 if (dep_mclk_table->entries[i].clk) {
5228 clocks->data[clocks->num_levels].clocks_in_khz =
5229 dep_mclk_table->entries[i].clk * 10;
5230 data->mclk_latency_table.entries[data->mclk_latency_table.count].frequency =
5231 dep_mclk_table->entries[i].clk;
5232 clocks->data[clocks->num_levels].latency_in_us =
5233 data->mclk_latency_table.entries[data->mclk_latency_table.count].latency =
5234 smu7_get_mem_latency(hwmgr, dep_mclk_table->entries[i].clk);
5235 clocks->num_levels++;
5236 data->mclk_latency_table.count++;
5243 static int smu7_get_clock_by_type_with_latency(struct pp_hwmgr *hwmgr,
5244 enum amd_pp_clock_type type,
5245 struct pp_clock_levels_with_latency *clocks)
5247 if (!(hwmgr->chip_id >= CHIP_POLARIS10 &&
5248 hwmgr->chip_id <= CHIP_VEGAM))
5252 case amd_pp_sys_clock:
5253 smu7_get_sclks_with_latency(hwmgr, clocks);
5255 case amd_pp_mem_clock:
5256 smu7_get_mclks_with_latency(hwmgr, clocks);
5265 static int smu7_set_watermarks_for_clocks_ranges(struct pp_hwmgr *hwmgr,
5268 struct phm_ppt_v1_information *table_info =
5269 (struct phm_ppt_v1_information *)hwmgr->pptable;
5270 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
5271 table_info->vdd_dep_on_mclk;
5272 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table =
5273 table_info->vdd_dep_on_sclk;
5274 struct polaris10_smumgr *smu_data =
5275 (struct polaris10_smumgr *)(hwmgr->smu_backend);
5276 SMU74_Discrete_DpmTable *table = &(smu_data->smc_state_table);
5277 struct dm_pp_wm_sets_with_clock_ranges *watermarks =
5278 (struct dm_pp_wm_sets_with_clock_ranges *)clock_range;
5282 if (!(hwmgr->chip_id >= CHIP_POLARIS10 &&
5283 hwmgr->chip_id <= CHIP_VEGAM))
5286 for (i = 0; i < dep_mclk_table->count; i++) {
5287 for (j = 0; j < dep_sclk_table->count; j++) {
5288 valid_entry = false;
5289 for (k = 0; k < watermarks->num_wm_sets; k++) {
5290 if (dep_sclk_table->entries[i].clk >= watermarks->wm_clk_ranges[k].wm_min_eng_clk_in_khz / 10 &&
5291 dep_sclk_table->entries[i].clk < watermarks->wm_clk_ranges[k].wm_max_eng_clk_in_khz / 10 &&
5292 dep_mclk_table->entries[i].clk >= watermarks->wm_clk_ranges[k].wm_min_mem_clk_in_khz / 10 &&
5293 dep_mclk_table->entries[i].clk < watermarks->wm_clk_ranges[k].wm_max_mem_clk_in_khz / 10) {
5295 table->DisplayWatermark[i][j] = watermarks->wm_clk_ranges[k].wm_set_id;
5299 PP_ASSERT_WITH_CODE(valid_entry,
5300 "Clock is not in range of specified clock range for watermark from DAL! Using highest water mark set.",
5301 table->DisplayWatermark[i][j] = watermarks->wm_clk_ranges[k - 1].wm_set_id);
5305 return smu7_copy_bytes_to_smc(hwmgr,
5306 smu_data->smu7_data.dpm_table_start + offsetof(SMU74_Discrete_DpmTable, DisplayWatermark),
5307 (uint8_t *)table->DisplayWatermark,
5308 sizeof(uint8_t) * SMU74_MAX_LEVELS_MEMORY * SMU74_MAX_LEVELS_GRAPHICS,
5312 static int smu7_notify_cac_buffer_info(struct pp_hwmgr *hwmgr,
5313 uint32_t virtual_addr_low,
5314 uint32_t virtual_addr_hi,
5315 uint32_t mc_addr_low,
5316 uint32_t mc_addr_hi,
5319 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5321 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
5322 data->soft_regs_start +
5323 smum_get_offsetof(hwmgr,
5324 SMU_SoftRegisters, DRAM_LOG_ADDR_H),
5327 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
5328 data->soft_regs_start +
5329 smum_get_offsetof(hwmgr,
5330 SMU_SoftRegisters, DRAM_LOG_ADDR_L),
5333 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
5334 data->soft_regs_start +
5335 smum_get_offsetof(hwmgr,
5336 SMU_SoftRegisters, DRAM_LOG_PHY_ADDR_H),
5339 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
5340 data->soft_regs_start +
5341 smum_get_offsetof(hwmgr,
5342 SMU_SoftRegisters, DRAM_LOG_PHY_ADDR_L),
5345 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
5346 data->soft_regs_start +
5347 smum_get_offsetof(hwmgr,
5348 SMU_SoftRegisters, DRAM_LOG_BUFF_SIZE),
5353 static int smu7_get_max_high_clocks(struct pp_hwmgr *hwmgr,
5354 struct amd_pp_simple_clock_info *clocks)
5356 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5357 struct smu7_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
5358 struct smu7_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
5363 clocks->memory_max_clock = mclk_table->count > 1 ?
5364 mclk_table->dpm_levels[mclk_table->count-1].value :
5365 mclk_table->dpm_levels[0].value;
5366 clocks->engine_max_clock = sclk_table->count > 1 ?
5367 sclk_table->dpm_levels[sclk_table->count-1].value :
5368 sclk_table->dpm_levels[0].value;
5372 static int smu7_get_thermal_temperature_range(struct pp_hwmgr *hwmgr,
5373 struct PP_TemperatureRange *thermal_data)
5375 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5376 struct phm_ppt_v1_information *table_info =
5377 (struct phm_ppt_v1_information *)hwmgr->pptable;
5379 memcpy(thermal_data, &SMU7ThermalPolicy[0], sizeof(struct PP_TemperatureRange));
5381 if (hwmgr->pp_table_version == PP_TABLE_V1)
5382 thermal_data->max = table_info->cac_dtp_table->usSoftwareShutdownTemp *
5383 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
5384 else if (hwmgr->pp_table_version == PP_TABLE_V0)
5385 thermal_data->max = data->thermal_temp_setting.temperature_shutdown *
5386 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
5391 static bool smu7_check_clk_voltage_valid(struct pp_hwmgr *hwmgr,
5392 enum PP_OD_DPM_TABLE_COMMAND type,
5396 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5398 if (voltage < data->odn_dpm_table.min_vddc || voltage > data->odn_dpm_table.max_vddc) {
5399 pr_info("OD voltage is out of range [%d - %d] mV\n",
5400 data->odn_dpm_table.min_vddc,
5401 data->odn_dpm_table.max_vddc);
5405 if (type == PP_OD_EDIT_SCLK_VDDC_TABLE) {
5406 if (data->golden_dpm_table.sclk_table.dpm_levels[0].value > clk ||
5407 hwmgr->platform_descriptor.overdriveLimit.engineClock < clk) {
5408 pr_info("OD engine clock is out of range [%d - %d] MHz\n",
5409 data->golden_dpm_table.sclk_table.dpm_levels[0].value/100,
5410 hwmgr->platform_descriptor.overdriveLimit.engineClock/100);
5413 } else if (type == PP_OD_EDIT_MCLK_VDDC_TABLE) {
5414 if (data->golden_dpm_table.mclk_table.dpm_levels[0].value > clk ||
5415 hwmgr->platform_descriptor.overdriveLimit.memoryClock < clk) {
5416 pr_info("OD memory clock is out of range [%d - %d] MHz\n",
5417 data->golden_dpm_table.mclk_table.dpm_levels[0].value/100,
5418 hwmgr->platform_descriptor.overdriveLimit.memoryClock/100);
5428 static int smu7_odn_edit_dpm_table(struct pp_hwmgr *hwmgr,
5429 enum PP_OD_DPM_TABLE_COMMAND type,
5430 long *input, uint32_t size)
5433 struct phm_odn_clock_levels *podn_dpm_table_in_backend = NULL;
5434 struct smu7_odn_clock_voltage_dependency_table *podn_vdd_dep_in_backend = NULL;
5435 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5439 uint32_t input_level;
5441 PP_ASSERT_WITH_CODE(input, "NULL user input for clock and voltage",
5444 if (!hwmgr->od_enabled) {
5445 pr_info("OverDrive feature not enabled\n");
5449 if (PP_OD_EDIT_SCLK_VDDC_TABLE == type) {
5450 podn_dpm_table_in_backend = &data->odn_dpm_table.odn_core_clock_dpm_levels;
5451 podn_vdd_dep_in_backend = &data->odn_dpm_table.vdd_dependency_on_sclk;
5452 PP_ASSERT_WITH_CODE((podn_dpm_table_in_backend && podn_vdd_dep_in_backend),
5453 "Failed to get ODN SCLK and Voltage tables",
5455 } else if (PP_OD_EDIT_MCLK_VDDC_TABLE == type) {
5456 podn_dpm_table_in_backend = &data->odn_dpm_table.odn_memory_clock_dpm_levels;
5457 podn_vdd_dep_in_backend = &data->odn_dpm_table.vdd_dependency_on_mclk;
5459 PP_ASSERT_WITH_CODE((podn_dpm_table_in_backend && podn_vdd_dep_in_backend),
5460 "Failed to get ODN MCLK and Voltage tables",
5462 } else if (PP_OD_RESTORE_DEFAULT_TABLE == type) {
5463 smu7_odn_initial_default_setting(hwmgr);
5465 } else if (PP_OD_COMMIT_DPM_TABLE == type) {
5466 smu7_check_dpm_table_updated(hwmgr);
5472 for (i = 0; i < size; i += 3) {
5473 if (i + 3 > size || input[i] >= podn_dpm_table_in_backend->num_of_pl) {
5474 pr_info("invalid clock voltage input \n");
5477 input_level = input[i];
5478 input_clk = input[i+1] * 100;
5479 input_vol = input[i+2];
5481 if (smu7_check_clk_voltage_valid(hwmgr, type, input_clk, input_vol)) {
5482 podn_dpm_table_in_backend->entries[input_level].clock = input_clk;
5483 podn_vdd_dep_in_backend->entries[input_level].clk = input_clk;
5484 podn_dpm_table_in_backend->entries[input_level].vddc = input_vol;
5485 podn_vdd_dep_in_backend->entries[input_level].vddc = input_vol;
5486 podn_vdd_dep_in_backend->entries[input_level].vddgfx = input_vol;
5495 static int smu7_get_power_profile_mode(struct pp_hwmgr *hwmgr, char *buf)
5497 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5498 uint32_t i, size = 0;
5501 static const char *profile_name[7] = {"BOOTUP_DEFAULT",
5509 static const char *title[8] = {"NUM",
5513 "SCLK_ACTIVE_LEVEL",
5516 "MCLK_ACTIVE_LEVEL"};
5521 size += sysfs_emit_at(buf, size, "%s %16s %16s %16s %16s %16s %16s %16s\n",
5522 title[0], title[1], title[2], title[3],
5523 title[4], title[5], title[6], title[7]);
5525 len = ARRAY_SIZE(smu7_profiling);
5527 for (i = 0; i < len; i++) {
5528 if (i == hwmgr->power_profile_mode) {
5529 size += sysfs_emit_at(buf, size, "%3d %14s %s: %8d %16d %16d %16d %16d %16d\n",
5530 i, profile_name[i], "*",
5531 data->current_profile_setting.sclk_up_hyst,
5532 data->current_profile_setting.sclk_down_hyst,
5533 data->current_profile_setting.sclk_activity,
5534 data->current_profile_setting.mclk_up_hyst,
5535 data->current_profile_setting.mclk_down_hyst,
5536 data->current_profile_setting.mclk_activity);
5539 if (smu7_profiling[i].bupdate_sclk)
5540 size += sysfs_emit_at(buf, size, "%3d %16s: %8d %16d %16d ",
5541 i, profile_name[i], smu7_profiling[i].sclk_up_hyst,
5542 smu7_profiling[i].sclk_down_hyst,
5543 smu7_profiling[i].sclk_activity);
5545 size += sysfs_emit_at(buf, size, "%3d %16s: %8s %16s %16s ",
5546 i, profile_name[i], "-", "-", "-");
5548 if (smu7_profiling[i].bupdate_mclk)
5549 size += sysfs_emit_at(buf, size, "%16d %16d %16d\n",
5550 smu7_profiling[i].mclk_up_hyst,
5551 smu7_profiling[i].mclk_down_hyst,
5552 smu7_profiling[i].mclk_activity);
5554 size += sysfs_emit_at(buf, size, "%16s %16s %16s\n",
5561 static void smu7_patch_compute_profile_mode(struct pp_hwmgr *hwmgr,
5562 enum PP_SMC_POWER_PROFILE requst)
5564 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5565 uint32_t tmp, level;
5567 if (requst == PP_SMC_POWER_PROFILE_COMPUTE) {
5568 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
5570 tmp = data->dpm_level_enable_mask.sclk_dpm_enable_mask;
5574 smu7_force_clock_level(hwmgr, PP_SCLK, 3 << (level-1));
5576 } else if (hwmgr->power_profile_mode == PP_SMC_POWER_PROFILE_COMPUTE) {
5577 smu7_force_clock_level(hwmgr, PP_SCLK, data->dpm_level_enable_mask.sclk_dpm_enable_mask);
5581 static int smu7_set_power_profile_mode(struct pp_hwmgr *hwmgr, long *input, uint32_t size)
5583 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5584 struct profile_mode_setting tmp;
5585 enum PP_SMC_POWER_PROFILE mode;
5592 case PP_SMC_POWER_PROFILE_CUSTOM:
5593 if (size < 8 && size != 0)
5595 /* If only CUSTOM is passed in, use the saved values. Check
5596 * that we actually have a CUSTOM profile by ensuring that
5597 * the "use sclk" or the "use mclk" bits are set
5599 tmp = smu7_profiling[PP_SMC_POWER_PROFILE_CUSTOM];
5601 if (tmp.bupdate_sclk == 0 && tmp.bupdate_mclk == 0)
5604 tmp.bupdate_sclk = input[0];
5605 tmp.sclk_up_hyst = input[1];
5606 tmp.sclk_down_hyst = input[2];
5607 tmp.sclk_activity = input[3];
5608 tmp.bupdate_mclk = input[4];
5609 tmp.mclk_up_hyst = input[5];
5610 tmp.mclk_down_hyst = input[6];
5611 tmp.mclk_activity = input[7];
5612 smu7_profiling[PP_SMC_POWER_PROFILE_CUSTOM] = tmp;
5614 if (!smum_update_dpm_settings(hwmgr, &tmp)) {
5615 memcpy(&data->current_profile_setting, &tmp, sizeof(struct profile_mode_setting));
5616 hwmgr->power_profile_mode = mode;
5619 case PP_SMC_POWER_PROFILE_FULLSCREEN3D:
5620 case PP_SMC_POWER_PROFILE_POWERSAVING:
5621 case PP_SMC_POWER_PROFILE_VIDEO:
5622 case PP_SMC_POWER_PROFILE_VR:
5623 case PP_SMC_POWER_PROFILE_COMPUTE:
5624 if (mode == hwmgr->power_profile_mode)
5627 memcpy(&tmp, &smu7_profiling[mode], sizeof(struct profile_mode_setting));
5628 if (!smum_update_dpm_settings(hwmgr, &tmp)) {
5629 if (tmp.bupdate_sclk) {
5630 data->current_profile_setting.bupdate_sclk = tmp.bupdate_sclk;
5631 data->current_profile_setting.sclk_up_hyst = tmp.sclk_up_hyst;
5632 data->current_profile_setting.sclk_down_hyst = tmp.sclk_down_hyst;
5633 data->current_profile_setting.sclk_activity = tmp.sclk_activity;
5635 if (tmp.bupdate_mclk) {
5636 data->current_profile_setting.bupdate_mclk = tmp.bupdate_mclk;
5637 data->current_profile_setting.mclk_up_hyst = tmp.mclk_up_hyst;
5638 data->current_profile_setting.mclk_down_hyst = tmp.mclk_down_hyst;
5639 data->current_profile_setting.mclk_activity = tmp.mclk_activity;
5641 smu7_patch_compute_profile_mode(hwmgr, mode);
5642 hwmgr->power_profile_mode = mode;
5652 static int smu7_get_performance_level(struct pp_hwmgr *hwmgr, const struct pp_hw_power_state *state,
5653 PHM_PerformanceLevelDesignation designation, uint32_t index,
5654 PHM_PerformanceLevel *level)
5656 const struct smu7_power_state *ps;
5659 if (level == NULL || hwmgr == NULL || state == NULL)
5662 ps = cast_const_phw_smu7_power_state(state);
5664 i = index > ps->performance_level_count - 1 ?
5665 ps->performance_level_count - 1 : index;
5667 level->coreClock = ps->performance_levels[i].engine_clock;
5668 level->memory_clock = ps->performance_levels[i].memory_clock;
5673 static int smu7_power_off_asic(struct pp_hwmgr *hwmgr)
5677 result = smu7_disable_dpm_tasks(hwmgr);
5678 PP_ASSERT_WITH_CODE((0 == result),
5679 "[disable_dpm_tasks] Failed to disable DPM!",
5685 static const struct pp_hwmgr_func smu7_hwmgr_funcs = {
5686 .backend_init = &smu7_hwmgr_backend_init,
5687 .backend_fini = &smu7_hwmgr_backend_fini,
5688 .asic_setup = &smu7_setup_asic_task,
5689 .dynamic_state_management_enable = &smu7_enable_dpm_tasks,
5690 .apply_state_adjust_rules = smu7_apply_state_adjust_rules,
5691 .force_dpm_level = &smu7_force_dpm_level,
5692 .power_state_set = smu7_set_power_state_tasks,
5693 .get_power_state_size = smu7_get_power_state_size,
5694 .get_mclk = smu7_dpm_get_mclk,
5695 .get_sclk = smu7_dpm_get_sclk,
5696 .patch_boot_state = smu7_dpm_patch_boot_state,
5697 .get_pp_table_entry = smu7_get_pp_table_entry,
5698 .get_num_of_pp_table_entries = smu7_get_number_of_powerplay_table_entries,
5699 .powerdown_uvd = smu7_powerdown_uvd,
5700 .powergate_uvd = smu7_powergate_uvd,
5701 .powergate_vce = smu7_powergate_vce,
5702 .disable_clock_power_gating = smu7_disable_clock_power_gating,
5703 .update_clock_gatings = smu7_update_clock_gatings,
5704 .notify_smc_display_config_after_ps_adjustment = smu7_notify_smc_display_config_after_ps_adjustment,
5705 .display_config_changed = smu7_display_configuration_changed_task,
5706 .set_max_fan_pwm_output = smu7_set_max_fan_pwm_output,
5707 .set_max_fan_rpm_output = smu7_set_max_fan_rpm_output,
5708 .stop_thermal_controller = smu7_thermal_stop_thermal_controller,
5709 .get_fan_speed_info = smu7_fan_ctrl_get_fan_speed_info,
5710 .get_fan_speed_pwm = smu7_fan_ctrl_get_fan_speed_pwm,
5711 .set_fan_speed_pwm = smu7_fan_ctrl_set_fan_speed_pwm,
5712 .reset_fan_speed_to_default = smu7_fan_ctrl_reset_fan_speed_to_default,
5713 .get_fan_speed_rpm = smu7_fan_ctrl_get_fan_speed_rpm,
5714 .set_fan_speed_rpm = smu7_fan_ctrl_set_fan_speed_rpm,
5715 .uninitialize_thermal_controller = smu7_thermal_ctrl_uninitialize_thermal_controller,
5716 .register_irq_handlers = smu7_register_irq_handlers,
5717 .check_smc_update_required_for_display_configuration = smu7_check_smc_update_required_for_display_configuration,
5718 .check_states_equal = smu7_check_states_equal,
5719 .set_fan_control_mode = smu7_set_fan_control_mode,
5720 .get_fan_control_mode = smu7_get_fan_control_mode,
5721 .force_clock_level = smu7_force_clock_level,
5722 .print_clock_levels = smu7_print_clock_levels,
5723 .powergate_gfx = smu7_powergate_gfx,
5724 .get_sclk_od = smu7_get_sclk_od,
5725 .set_sclk_od = smu7_set_sclk_od,
5726 .get_mclk_od = smu7_get_mclk_od,
5727 .set_mclk_od = smu7_set_mclk_od,
5728 .get_clock_by_type = smu7_get_clock_by_type,
5729 .get_clock_by_type_with_latency = smu7_get_clock_by_type_with_latency,
5730 .set_watermarks_for_clocks_ranges = smu7_set_watermarks_for_clocks_ranges,
5731 .read_sensor = smu7_read_sensor,
5732 .dynamic_state_management_disable = smu7_disable_dpm_tasks,
5733 .avfs_control = smu7_avfs_control,
5734 .disable_smc_firmware_ctf = smu7_thermal_disable_alert,
5735 .start_thermal_controller = smu7_start_thermal_controller,
5736 .notify_cac_buffer_info = smu7_notify_cac_buffer_info,
5737 .get_max_high_clocks = smu7_get_max_high_clocks,
5738 .get_thermal_temperature_range = smu7_get_thermal_temperature_range,
5739 .odn_edit_dpm_table = smu7_odn_edit_dpm_table,
5740 .set_power_limit = smu7_set_power_limit,
5741 .get_power_profile_mode = smu7_get_power_profile_mode,
5742 .set_power_profile_mode = smu7_set_power_profile_mode,
5743 .get_performance_level = smu7_get_performance_level,
5744 .get_asic_baco_capability = smu7_baco_get_capability,
5745 .get_asic_baco_state = smu7_baco_get_state,
5746 .set_asic_baco_state = smu7_baco_set_state,
5747 .power_off_asic = smu7_power_off_asic,
5750 uint8_t smu7_get_sleep_divider_id_from_clock(uint32_t clock,
5751 uint32_t clock_insr)
5755 uint32_t min = max(clock_insr, (uint32_t)SMU7_MINIMUM_ENGINE_CLOCK);
5757 PP_ASSERT_WITH_CODE((clock >= min), "Engine clock can't satisfy stutter requirement!", return 0);
5758 for (i = SMU7_MAX_DEEPSLEEP_DIVIDER_ID; ; i--) {
5761 if (temp >= min || i == 0)
5767 int smu7_init_function_pointers(struct pp_hwmgr *hwmgr)
5769 hwmgr->hwmgr_func = &smu7_hwmgr_funcs;
5770 if (hwmgr->pp_table_version == PP_TABLE_V0)
5771 hwmgr->pptable_func = &pptable_funcs;
5772 else if (hwmgr->pp_table_version == PP_TABLE_V1)
5773 hwmgr->pptable_func = &pptable_v1_0_funcs;