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 #include <drm/amdgpu_drm.h>
31 #include "ppatomctrl.h"
33 #include "pptable_v1_0.h"
34 #include "pppcielanes.h"
35 #include "amd_pcie_helpers.h"
36 #include "hardwaremanager.h"
37 #include "process_pptables_v1_0.h"
38 #include "cgs_common.h"
40 #include "smu7_common.h"
43 #include "smu7_hwmgr.h"
44 #include "smu_ucode_xfer_vi.h"
45 #include "smu7_powertune.h"
46 #include "smu7_dyn_defaults.h"
47 #include "smu7_thermal.h"
48 #include "smu7_clockpowergating.h"
49 #include "processpptables.h"
50 #include "pp_thermal.h"
51 #include "smu7_baco.h"
52 #include "smu7_smumgr.h"
53 #include "polaris10_smumgr.h"
55 #include "ivsrcid/ivsrcid_vislands30.h"
57 #define MC_CG_ARB_FREQ_F0 0x0a
58 #define MC_CG_ARB_FREQ_F1 0x0b
59 #define MC_CG_ARB_FREQ_F2 0x0c
60 #define MC_CG_ARB_FREQ_F3 0x0d
62 #define MC_CG_SEQ_DRAMCONF_S0 0x05
63 #define MC_CG_SEQ_DRAMCONF_S1 0x06
64 #define MC_CG_SEQ_YCLK_SUSPEND 0x04
65 #define MC_CG_SEQ_YCLK_RESUME 0x0a
67 #define SMC_CG_IND_START 0xc0030000
68 #define SMC_CG_IND_END 0xc0040000
70 #define MEM_FREQ_LOW_LATENCY 25000
71 #define MEM_FREQ_HIGH_LATENCY 80000
73 #define MEM_LATENCY_HIGH 45
74 #define MEM_LATENCY_LOW 35
75 #define MEM_LATENCY_ERR 0xFFFF
77 #define MC_SEQ_MISC0_GDDR5_SHIFT 28
78 #define MC_SEQ_MISC0_GDDR5_MASK 0xf0000000
79 #define MC_SEQ_MISC0_GDDR5_VALUE 5
81 #define PCIE_BUS_CLK 10000
82 #define TCLK (PCIE_BUS_CLK / 10)
84 static struct profile_mode_setting smu7_profiling[7] =
85 {{0, 0, 0, 0, 0, 0, 0, 0},
86 {1, 0, 100, 30, 1, 0, 100, 10},
87 {1, 10, 0, 30, 0, 0, 0, 0},
88 {0, 0, 0, 0, 1, 10, 16, 31},
89 {1, 0, 11, 50, 1, 0, 100, 10},
90 {1, 0, 5, 30, 0, 0, 0, 0},
91 {0, 0, 0, 0, 0, 0, 0, 0},
94 #define PPSMC_MSG_SetVBITimeout_VEGAM ((uint16_t) 0x310)
96 #define ixPWR_SVI2_PLANE1_LOAD 0xC0200280
97 #define PWR_SVI2_PLANE1_LOAD__PSI1_MASK 0x00000020L
98 #define PWR_SVI2_PLANE1_LOAD__PSI0_EN_MASK 0x00000040L
99 #define PWR_SVI2_PLANE1_LOAD__PSI1__SHIFT 0x00000005
100 #define PWR_SVI2_PLANE1_LOAD__PSI0_EN__SHIFT 0x00000006
102 #define STRAP_EVV_REVISION_MSB 2211
103 #define STRAP_EVV_REVISION_LSB 2208
105 /** Values for the CG_THERMAL_CTRL::DPM_EVENT_SRC field. */
107 DPM_EVENT_SRC_ANALOG = 0,
108 DPM_EVENT_SRC_EXTERNAL = 1,
109 DPM_EVENT_SRC_DIGITAL = 2,
110 DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
111 DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL = 4
114 #define ixDIDT_SQ_EDC_CTRL 0x0013
115 #define ixDIDT_SQ_EDC_THRESHOLD 0x0014
116 #define ixDIDT_SQ_EDC_STALL_PATTERN_1_2 0x0015
117 #define ixDIDT_SQ_EDC_STALL_PATTERN_3_4 0x0016
118 #define ixDIDT_SQ_EDC_STALL_PATTERN_5_6 0x0017
119 #define ixDIDT_SQ_EDC_STALL_PATTERN_7 0x0018
121 #define ixDIDT_TD_EDC_CTRL 0x0053
122 #define ixDIDT_TD_EDC_THRESHOLD 0x0054
123 #define ixDIDT_TD_EDC_STALL_PATTERN_1_2 0x0055
124 #define ixDIDT_TD_EDC_STALL_PATTERN_3_4 0x0056
125 #define ixDIDT_TD_EDC_STALL_PATTERN_5_6 0x0057
126 #define ixDIDT_TD_EDC_STALL_PATTERN_7 0x0058
128 #define ixDIDT_TCP_EDC_CTRL 0x0073
129 #define ixDIDT_TCP_EDC_THRESHOLD 0x0074
130 #define ixDIDT_TCP_EDC_STALL_PATTERN_1_2 0x0075
131 #define ixDIDT_TCP_EDC_STALL_PATTERN_3_4 0x0076
132 #define ixDIDT_TCP_EDC_STALL_PATTERN_5_6 0x0077
133 #define ixDIDT_TCP_EDC_STALL_PATTERN_7 0x0078
135 #define ixDIDT_DB_EDC_CTRL 0x0033
136 #define ixDIDT_DB_EDC_THRESHOLD 0x0034
137 #define ixDIDT_DB_EDC_STALL_PATTERN_1_2 0x0035
138 #define ixDIDT_DB_EDC_STALL_PATTERN_3_4 0x0036
139 #define ixDIDT_DB_EDC_STALL_PATTERN_5_6 0x0037
140 #define ixDIDT_DB_EDC_STALL_PATTERN_7 0x0038
142 uint32_t DIDTEDCConfig_P12[] = {
143 ixDIDT_SQ_EDC_STALL_PATTERN_1_2,
144 ixDIDT_SQ_EDC_STALL_PATTERN_3_4,
145 ixDIDT_SQ_EDC_STALL_PATTERN_5_6,
146 ixDIDT_SQ_EDC_STALL_PATTERN_7,
147 ixDIDT_SQ_EDC_THRESHOLD,
149 ixDIDT_TD_EDC_STALL_PATTERN_1_2,
150 ixDIDT_TD_EDC_STALL_PATTERN_3_4,
151 ixDIDT_TD_EDC_STALL_PATTERN_5_6,
152 ixDIDT_TD_EDC_STALL_PATTERN_7,
153 ixDIDT_TD_EDC_THRESHOLD,
155 ixDIDT_TCP_EDC_STALL_PATTERN_1_2,
156 ixDIDT_TCP_EDC_STALL_PATTERN_3_4,
157 ixDIDT_TCP_EDC_STALL_PATTERN_5_6,
158 ixDIDT_TCP_EDC_STALL_PATTERN_7,
159 ixDIDT_TCP_EDC_THRESHOLD,
161 ixDIDT_DB_EDC_STALL_PATTERN_1_2,
162 ixDIDT_DB_EDC_STALL_PATTERN_3_4,
163 ixDIDT_DB_EDC_STALL_PATTERN_5_6,
164 ixDIDT_DB_EDC_STALL_PATTERN_7,
165 ixDIDT_DB_EDC_THRESHOLD,
167 0xFFFFFFFF // End of list
170 static const unsigned long PhwVIslands_Magic = (unsigned long)(PHM_VIslands_Magic);
171 static int smu7_force_clock_level(struct pp_hwmgr *hwmgr,
172 enum pp_clock_type type, uint32_t mask);
173 static int smu7_notify_has_display(struct pp_hwmgr *hwmgr);
175 static struct smu7_power_state *cast_phw_smu7_power_state(
176 struct pp_hw_power_state *hw_ps)
178 PP_ASSERT_WITH_CODE((PhwVIslands_Magic == hw_ps->magic),
179 "Invalid Powerstate Type!",
182 return (struct smu7_power_state *)hw_ps;
185 static const struct smu7_power_state *cast_const_phw_smu7_power_state(
186 const struct pp_hw_power_state *hw_ps)
188 PP_ASSERT_WITH_CODE((PhwVIslands_Magic == hw_ps->magic),
189 "Invalid Powerstate Type!",
192 return (const struct smu7_power_state *)hw_ps;
196 * smu7_get_mc_microcode_version - Find the MC microcode version and store it in the HwMgr struct
198 * @hwmgr: the address of the powerplay hardware manager.
201 static int smu7_get_mc_microcode_version(struct pp_hwmgr *hwmgr)
203 cgs_write_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_INDEX, 0x9F);
205 hwmgr->microcode_version_info.MC = cgs_read_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_DATA);
210 static uint16_t smu7_get_current_pcie_speed(struct pp_hwmgr *hwmgr)
212 uint32_t speedCntl = 0;
214 /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
215 speedCntl = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__PCIE,
216 ixPCIE_LC_SPEED_CNTL);
217 return((uint16_t)PHM_GET_FIELD(speedCntl,
218 PCIE_LC_SPEED_CNTL, LC_CURRENT_DATA_RATE));
221 static int smu7_get_current_pcie_lane_number(struct pp_hwmgr *hwmgr)
225 /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
226 link_width = PHM_READ_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE,
227 PCIE_LC_LINK_WIDTH_CNTL, LC_LINK_WIDTH_RD);
229 PP_ASSERT_WITH_CODE((7 >= link_width),
230 "Invalid PCIe lane width!", return 0);
232 return decode_pcie_lane_width(link_width);
236 * smu7_enable_smc_voltage_controller - Enable voltage control
238 * @hwmgr: the address of the powerplay hardware manager.
239 * Return: always PP_Result_OK
241 static int smu7_enable_smc_voltage_controller(struct pp_hwmgr *hwmgr)
243 if (hwmgr->chip_id >= CHIP_POLARIS10 &&
244 hwmgr->chip_id <= CHIP_VEGAM) {
245 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device,
246 CGS_IND_REG__SMC, PWR_SVI2_PLANE1_LOAD, PSI1, 0);
247 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device,
248 CGS_IND_REG__SMC, PWR_SVI2_PLANE1_LOAD, PSI0_EN, 0);
251 if (hwmgr->feature_mask & PP_SMC_VOLTAGE_CONTROL_MASK)
252 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_Voltage_Cntl_Enable, NULL);
258 * smu7_voltage_control - Checks if we want to support voltage control
260 * @hwmgr: the address of the powerplay hardware manager.
262 static bool smu7_voltage_control(const struct pp_hwmgr *hwmgr)
264 const struct smu7_hwmgr *data =
265 (const struct smu7_hwmgr *)(hwmgr->backend);
267 return (SMU7_VOLTAGE_CONTROL_NONE != data->voltage_control);
271 * smu7_enable_voltage_control - Enable voltage control
273 * @hwmgr: the address of the powerplay hardware manager.
276 static int smu7_enable_voltage_control(struct pp_hwmgr *hwmgr)
278 /* enable voltage control */
279 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
280 GENERAL_PWRMGT, VOLT_PWRMGT_EN, 1);
285 static int phm_get_svi2_voltage_table_v0(pp_atomctrl_voltage_table *voltage_table,
286 struct phm_clock_voltage_dependency_table *voltage_dependency_table
291 PP_ASSERT_WITH_CODE((NULL != voltage_table),
292 "Voltage Dependency Table empty.", return -EINVAL;);
294 voltage_table->mask_low = 0;
295 voltage_table->phase_delay = 0;
296 voltage_table->count = voltage_dependency_table->count;
298 for (i = 0; i < voltage_dependency_table->count; i++) {
299 voltage_table->entries[i].value =
300 voltage_dependency_table->entries[i].v;
301 voltage_table->entries[i].smio_low = 0;
309 * smu7_construct_voltage_tables - Create Voltage Tables.
311 * @hwmgr: the address of the powerplay hardware manager.
314 static int smu7_construct_voltage_tables(struct pp_hwmgr *hwmgr)
316 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
317 struct phm_ppt_v1_information *table_info =
318 (struct phm_ppt_v1_information *)hwmgr->pptable;
322 if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
323 result = atomctrl_get_voltage_table_v3(hwmgr,
324 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT,
325 &(data->mvdd_voltage_table));
326 PP_ASSERT_WITH_CODE((0 == result),
327 "Failed to retrieve MVDD table.",
329 } else if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) {
330 if (hwmgr->pp_table_version == PP_TABLE_V1)
331 result = phm_get_svi2_mvdd_voltage_table(&(data->mvdd_voltage_table),
332 table_info->vdd_dep_on_mclk);
333 else if (hwmgr->pp_table_version == PP_TABLE_V0)
334 result = phm_get_svi2_voltage_table_v0(&(data->mvdd_voltage_table),
335 hwmgr->dyn_state.mvdd_dependency_on_mclk);
337 PP_ASSERT_WITH_CODE((0 == result),
338 "Failed to retrieve SVI2 MVDD table from dependency table.",
342 if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
343 result = atomctrl_get_voltage_table_v3(hwmgr,
344 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT,
345 &(data->vddci_voltage_table));
346 PP_ASSERT_WITH_CODE((0 == result),
347 "Failed to retrieve VDDCI table.",
349 } else if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) {
350 if (hwmgr->pp_table_version == PP_TABLE_V1)
351 result = phm_get_svi2_vddci_voltage_table(&(data->vddci_voltage_table),
352 table_info->vdd_dep_on_mclk);
353 else if (hwmgr->pp_table_version == PP_TABLE_V0)
354 result = phm_get_svi2_voltage_table_v0(&(data->vddci_voltage_table),
355 hwmgr->dyn_state.vddci_dependency_on_mclk);
356 PP_ASSERT_WITH_CODE((0 == result),
357 "Failed to retrieve SVI2 VDDCI table from dependency table.",
361 if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_gfx_control) {
362 /* VDDGFX has only SVI2 voltage control */
363 result = phm_get_svi2_vdd_voltage_table(&(data->vddgfx_voltage_table),
364 table_info->vddgfx_lookup_table);
365 PP_ASSERT_WITH_CODE((0 == result),
366 "Failed to retrieve SVI2 VDDGFX table from lookup table.", return result;);
370 if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->voltage_control) {
371 result = atomctrl_get_voltage_table_v3(hwmgr,
372 VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_GPIO_LUT,
373 &data->vddc_voltage_table);
374 PP_ASSERT_WITH_CODE((0 == result),
375 "Failed to retrieve VDDC table.", return result;);
376 } else if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
378 if (hwmgr->pp_table_version == PP_TABLE_V0)
379 result = phm_get_svi2_voltage_table_v0(&data->vddc_voltage_table,
380 hwmgr->dyn_state.vddc_dependency_on_mclk);
381 else if (hwmgr->pp_table_version == PP_TABLE_V1)
382 result = phm_get_svi2_vdd_voltage_table(&(data->vddc_voltage_table),
383 table_info->vddc_lookup_table);
385 PP_ASSERT_WITH_CODE((0 == result),
386 "Failed to retrieve SVI2 VDDC table from dependency table.", return result;);
389 tmp = smum_get_mac_definition(hwmgr, SMU_MAX_LEVELS_VDDC);
391 (data->vddc_voltage_table.count <= tmp),
392 "Too many voltage values for VDDC. Trimming to fit state table.",
393 phm_trim_voltage_table_to_fit_state_table(tmp,
394 &(data->vddc_voltage_table)));
396 tmp = smum_get_mac_definition(hwmgr, SMU_MAX_LEVELS_VDDGFX);
398 (data->vddgfx_voltage_table.count <= tmp),
399 "Too many voltage values for VDDC. Trimming to fit state table.",
400 phm_trim_voltage_table_to_fit_state_table(tmp,
401 &(data->vddgfx_voltage_table)));
403 tmp = smum_get_mac_definition(hwmgr, SMU_MAX_LEVELS_VDDCI);
405 (data->vddci_voltage_table.count <= tmp),
406 "Too many voltage values for VDDCI. Trimming to fit state table.",
407 phm_trim_voltage_table_to_fit_state_table(tmp,
408 &(data->vddci_voltage_table)));
410 tmp = smum_get_mac_definition(hwmgr, SMU_MAX_LEVELS_MVDD);
412 (data->mvdd_voltage_table.count <= tmp),
413 "Too many voltage values for MVDD. Trimming to fit state table.",
414 phm_trim_voltage_table_to_fit_state_table(tmp,
415 &(data->mvdd_voltage_table)));
421 * smu7_program_static_screen_threshold_parameters - Programs static screed detection parameters
423 * @hwmgr: the address of the powerplay hardware manager.
426 static int smu7_program_static_screen_threshold_parameters(
427 struct pp_hwmgr *hwmgr)
429 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
431 /* Set static screen threshold unit */
432 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
433 CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD_UNIT,
434 data->static_screen_threshold_unit);
435 /* Set static screen threshold */
436 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
437 CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD,
438 data->static_screen_threshold);
444 * smu7_enable_display_gap - Setup display gap for glitch free memory clock switching.
446 * @hwmgr: the address of the powerplay hardware manager.
449 static int smu7_enable_display_gap(struct pp_hwmgr *hwmgr)
451 uint32_t display_gap =
452 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
453 ixCG_DISPLAY_GAP_CNTL);
455 display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL,
456 DISP_GAP, DISPLAY_GAP_IGNORE);
458 display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL,
459 DISP_GAP_MCHG, DISPLAY_GAP_VBLANK);
461 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
462 ixCG_DISPLAY_GAP_CNTL, display_gap);
468 * smu7_program_voting_clients - Programs activity state transition voting clients
470 * @hwmgr: the address of the powerplay hardware manager.
473 static int smu7_program_voting_clients(struct pp_hwmgr *hwmgr)
475 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
478 /* Clear reset for voting clients before enabling DPM */
479 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
480 SCLK_PWRMGT_CNTL, RESET_SCLK_CNT, 0);
481 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
482 SCLK_PWRMGT_CNTL, RESET_BUSY_CNT, 0);
484 for (i = 0; i < 8; i++)
485 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
486 ixCG_FREQ_TRAN_VOTING_0 + i * 4,
487 data->voting_rights_clients[i]);
491 static int smu7_clear_voting_clients(struct pp_hwmgr *hwmgr)
495 /* Reset voting clients before disabling DPM */
496 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
497 SCLK_PWRMGT_CNTL, RESET_SCLK_CNT, 1);
498 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
499 SCLK_PWRMGT_CNTL, RESET_BUSY_CNT, 1);
501 for (i = 0; i < 8; i++)
502 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
503 ixCG_FREQ_TRAN_VOTING_0 + i * 4, 0);
508 /* Copy one arb setting to another and then switch the active set.
509 * arb_src and arb_dest is one of the MC_CG_ARB_FREQ_Fx constants.
511 static int smu7_copy_and_switch_arb_sets(struct pp_hwmgr *hwmgr,
512 uint32_t arb_src, uint32_t arb_dest)
514 uint32_t mc_arb_dram_timing;
515 uint32_t mc_arb_dram_timing2;
517 uint32_t mc_cg_config;
520 case MC_CG_ARB_FREQ_F0:
521 mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
522 mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
523 burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0);
525 case MC_CG_ARB_FREQ_F1:
526 mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1);
527 mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1);
528 burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1);
535 case MC_CG_ARB_FREQ_F0:
536 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING, mc_arb_dram_timing);
537 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2, mc_arb_dram_timing2);
538 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0, burst_time);
540 case MC_CG_ARB_FREQ_F1:
541 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1, mc_arb_dram_timing);
542 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1, mc_arb_dram_timing2);
543 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1, burst_time);
549 mc_cg_config = cgs_read_register(hwmgr->device, mmMC_CG_CONFIG);
550 mc_cg_config |= 0x0000000F;
551 cgs_write_register(hwmgr->device, mmMC_CG_CONFIG, mc_cg_config);
552 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_CG, CG_ARB_REQ, arb_dest);
557 static int smu7_reset_to_default(struct pp_hwmgr *hwmgr)
559 return smum_send_msg_to_smc(hwmgr, PPSMC_MSG_ResetToDefaults, NULL);
563 * smu7_initial_switch_from_arbf0_to_f1 - Initial switch from ARB F0->F1
565 * @hwmgr: the address of the powerplay hardware manager.
567 * This function is to be called from the SetPowerState table.
569 static int smu7_initial_switch_from_arbf0_to_f1(struct pp_hwmgr *hwmgr)
571 return smu7_copy_and_switch_arb_sets(hwmgr,
572 MC_CG_ARB_FREQ_F0, MC_CG_ARB_FREQ_F1);
575 static int smu7_force_switch_to_arbf0(struct pp_hwmgr *hwmgr)
579 tmp = (cgs_read_ind_register(hwmgr->device,
580 CGS_IND_REG__SMC, ixSMC_SCRATCH9) &
583 if (tmp == MC_CG_ARB_FREQ_F0)
586 return smu7_copy_and_switch_arb_sets(hwmgr,
587 tmp, MC_CG_ARB_FREQ_F0);
590 static uint16_t smu7_override_pcie_speed(struct pp_hwmgr *hwmgr)
592 struct amdgpu_device *adev = (struct amdgpu_device *)(hwmgr->adev);
593 uint16_t pcie_gen = 0;
595 if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN4 &&
596 adev->pm.pcie_gen_mask & CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN4)
598 else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3 &&
599 adev->pm.pcie_gen_mask & CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3)
601 else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 &&
602 adev->pm.pcie_gen_mask & CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2)
604 else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1 &&
605 adev->pm.pcie_gen_mask & CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1)
611 static uint16_t smu7_override_pcie_width(struct pp_hwmgr *hwmgr)
613 struct amdgpu_device *adev = (struct amdgpu_device *)(hwmgr->adev);
614 uint16_t pcie_width = 0;
616 if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16)
618 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12)
620 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8)
622 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4)
624 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2)
626 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X1)
632 static int smu7_setup_default_pcie_table(struct pp_hwmgr *hwmgr)
634 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
636 struct phm_ppt_v1_information *table_info =
637 (struct phm_ppt_v1_information *)(hwmgr->pptable);
638 struct phm_ppt_v1_pcie_table *pcie_table = NULL;
640 uint32_t i, max_entry;
643 PP_ASSERT_WITH_CODE((data->use_pcie_performance_levels ||
644 data->use_pcie_power_saving_levels), "No pcie performance levels!",
647 if (table_info != NULL)
648 pcie_table = table_info->pcie_table;
650 if (data->use_pcie_performance_levels &&
651 !data->use_pcie_power_saving_levels) {
652 data->pcie_gen_power_saving = data->pcie_gen_performance;
653 data->pcie_lane_power_saving = data->pcie_lane_performance;
654 } else if (!data->use_pcie_performance_levels &&
655 data->use_pcie_power_saving_levels) {
656 data->pcie_gen_performance = data->pcie_gen_power_saving;
657 data->pcie_lane_performance = data->pcie_lane_power_saving;
659 tmp = smum_get_mac_definition(hwmgr, SMU_MAX_LEVELS_LINK);
660 phm_reset_single_dpm_table(&data->dpm_table.pcie_speed_table,
662 MAX_REGULAR_DPM_NUMBER);
664 if (pcie_table != NULL) {
665 /* max_entry is used to make sure we reserve one PCIE level
666 * for boot level (fix for A+A PSPP issue).
667 * If PCIE table from PPTable have ULV entry + 8 entries,
668 * then ignore the last entry.*/
669 max_entry = (tmp < pcie_table->count) ? tmp : pcie_table->count;
670 for (i = 1; i < max_entry; i++) {
671 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, i - 1,
672 get_pcie_gen_support(data->pcie_gen_cap,
673 pcie_table->entries[i].gen_speed),
674 get_pcie_lane_support(data->pcie_lane_cap,
675 pcie_table->entries[i].lane_width));
677 data->dpm_table.pcie_speed_table.count = max_entry - 1;
678 smum_update_smc_table(hwmgr, SMU_BIF_TABLE);
680 /* Hardcode Pcie Table */
681 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 0,
682 get_pcie_gen_support(data->pcie_gen_cap,
684 get_pcie_lane_support(data->pcie_lane_cap,
686 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 1,
687 get_pcie_gen_support(data->pcie_gen_cap,
689 get_pcie_lane_support(data->pcie_lane_cap,
691 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 2,
692 get_pcie_gen_support(data->pcie_gen_cap,
694 get_pcie_lane_support(data->pcie_lane_cap,
696 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 3,
697 get_pcie_gen_support(data->pcie_gen_cap,
699 get_pcie_lane_support(data->pcie_lane_cap,
701 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 4,
702 get_pcie_gen_support(data->pcie_gen_cap,
704 get_pcie_lane_support(data->pcie_lane_cap,
706 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 5,
707 get_pcie_gen_support(data->pcie_gen_cap,
709 get_pcie_lane_support(data->pcie_lane_cap,
712 data->dpm_table.pcie_speed_table.count = 6;
714 /* Populate last level for boot PCIE level, but do not increment count. */
715 if (hwmgr->chip_family == AMDGPU_FAMILY_CI) {
716 for (i = 0; i <= data->dpm_table.pcie_speed_table.count; i++)
717 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, i,
718 get_pcie_gen_support(data->pcie_gen_cap,
720 data->vbios_boot_state.pcie_lane_bootup_value);
722 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table,
723 data->dpm_table.pcie_speed_table.count,
724 get_pcie_gen_support(data->pcie_gen_cap,
726 get_pcie_lane_support(data->pcie_lane_cap,
729 if (data->pcie_dpm_key_disabled)
730 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table,
731 data->dpm_table.pcie_speed_table.count,
732 smu7_override_pcie_speed(hwmgr), smu7_override_pcie_width(hwmgr));
737 static int smu7_reset_dpm_tables(struct pp_hwmgr *hwmgr)
739 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
741 memset(&(data->dpm_table), 0x00, sizeof(data->dpm_table));
743 phm_reset_single_dpm_table(
744 &data->dpm_table.sclk_table,
745 smum_get_mac_definition(hwmgr,
746 SMU_MAX_LEVELS_GRAPHICS),
747 MAX_REGULAR_DPM_NUMBER);
748 phm_reset_single_dpm_table(
749 &data->dpm_table.mclk_table,
750 smum_get_mac_definition(hwmgr,
751 SMU_MAX_LEVELS_MEMORY), MAX_REGULAR_DPM_NUMBER);
753 phm_reset_single_dpm_table(
754 &data->dpm_table.vddc_table,
755 smum_get_mac_definition(hwmgr,
756 SMU_MAX_LEVELS_VDDC),
757 MAX_REGULAR_DPM_NUMBER);
758 phm_reset_single_dpm_table(
759 &data->dpm_table.vddci_table,
760 smum_get_mac_definition(hwmgr,
761 SMU_MAX_LEVELS_VDDCI), MAX_REGULAR_DPM_NUMBER);
763 phm_reset_single_dpm_table(
764 &data->dpm_table.mvdd_table,
765 smum_get_mac_definition(hwmgr,
766 SMU_MAX_LEVELS_MVDD),
767 MAX_REGULAR_DPM_NUMBER);
771 * This function is to initialize all DPM state tables
772 * for SMU7 based on the dependency table.
773 * Dynamic state patching function will then trim these
774 * state tables to the allowed range based
775 * on the power policy or external client requests,
776 * such as UVD request, etc.
779 static int smu7_setup_dpm_tables_v0(struct pp_hwmgr *hwmgr)
781 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
782 struct phm_clock_voltage_dependency_table *allowed_vdd_sclk_table =
783 hwmgr->dyn_state.vddc_dependency_on_sclk;
784 struct phm_clock_voltage_dependency_table *allowed_vdd_mclk_table =
785 hwmgr->dyn_state.vddc_dependency_on_mclk;
786 struct phm_cac_leakage_table *std_voltage_table =
787 hwmgr->dyn_state.cac_leakage_table;
790 PP_ASSERT_WITH_CODE(allowed_vdd_sclk_table != NULL,
791 "SCLK dependency table is missing. This table is mandatory", return -EINVAL);
792 PP_ASSERT_WITH_CODE(allowed_vdd_sclk_table->count >= 1,
793 "SCLK dependency table has to have is missing. This table is mandatory", return -EINVAL);
795 PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table != NULL,
796 "MCLK dependency table is missing. This table is mandatory", return -EINVAL);
797 PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table->count >= 1,
798 "VMCLK dependency table has to have is missing. This table is mandatory", return -EINVAL);
801 /* Initialize Sclk DPM table based on allow Sclk values*/
802 data->dpm_table.sclk_table.count = 0;
804 for (i = 0; i < allowed_vdd_sclk_table->count; i++) {
805 if (i == 0 || data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count-1].value !=
806 allowed_vdd_sclk_table->entries[i].clk) {
807 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].value =
808 allowed_vdd_sclk_table->entries[i].clk;
809 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].enabled = (i == 0) ? 1 : 0;
810 data->dpm_table.sclk_table.count++;
814 PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table != NULL,
815 "MCLK dependency table is missing. This table is mandatory", return -EINVAL);
816 /* Initialize Mclk DPM table based on allow Mclk values */
817 data->dpm_table.mclk_table.count = 0;
818 for (i = 0; i < allowed_vdd_mclk_table->count; i++) {
819 if (i == 0 || data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count-1].value !=
820 allowed_vdd_mclk_table->entries[i].clk) {
821 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].value =
822 allowed_vdd_mclk_table->entries[i].clk;
823 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].enabled = (i == 0) ? 1 : 0;
824 data->dpm_table.mclk_table.count++;
828 /* Initialize Vddc DPM table based on allow Vddc values. And populate corresponding std values. */
829 for (i = 0; i < allowed_vdd_sclk_table->count; i++) {
830 data->dpm_table.vddc_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].v;
831 data->dpm_table.vddc_table.dpm_levels[i].param1 = std_voltage_table->entries[i].Leakage;
832 /* param1 is for corresponding std voltage */
833 data->dpm_table.vddc_table.dpm_levels[i].enabled = true;
836 data->dpm_table.vddc_table.count = allowed_vdd_sclk_table->count;
837 allowed_vdd_mclk_table = hwmgr->dyn_state.vddci_dependency_on_mclk;
839 if (NULL != allowed_vdd_mclk_table) {
840 /* Initialize Vddci DPM table based on allow Mclk values */
841 for (i = 0; i < allowed_vdd_mclk_table->count; i++) {
842 data->dpm_table.vddci_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].v;
843 data->dpm_table.vddci_table.dpm_levels[i].enabled = true;
845 data->dpm_table.vddci_table.count = allowed_vdd_mclk_table->count;
848 allowed_vdd_mclk_table = hwmgr->dyn_state.mvdd_dependency_on_mclk;
850 if (NULL != allowed_vdd_mclk_table) {
852 * Initialize MVDD DPM table based on allow Mclk
855 for (i = 0; i < allowed_vdd_mclk_table->count; i++) {
856 data->dpm_table.mvdd_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].v;
857 data->dpm_table.mvdd_table.dpm_levels[i].enabled = true;
859 data->dpm_table.mvdd_table.count = allowed_vdd_mclk_table->count;
865 static int smu7_setup_dpm_tables_v1(struct pp_hwmgr *hwmgr)
867 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
868 struct phm_ppt_v1_information *table_info =
869 (struct phm_ppt_v1_information *)(hwmgr->pptable);
872 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table;
873 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table;
875 if (table_info == NULL)
878 dep_sclk_table = table_info->vdd_dep_on_sclk;
879 dep_mclk_table = table_info->vdd_dep_on_mclk;
881 PP_ASSERT_WITH_CODE(dep_sclk_table != NULL,
882 "SCLK dependency table is missing.",
884 PP_ASSERT_WITH_CODE(dep_sclk_table->count >= 1,
885 "SCLK dependency table count is 0.",
888 PP_ASSERT_WITH_CODE(dep_mclk_table != NULL,
889 "MCLK dependency table is missing.",
891 PP_ASSERT_WITH_CODE(dep_mclk_table->count >= 1,
892 "MCLK dependency table count is 0",
895 /* Initialize Sclk DPM table based on allow Sclk values */
896 data->dpm_table.sclk_table.count = 0;
897 for (i = 0; i < dep_sclk_table->count; i++) {
898 if (i == 0 || data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count - 1].value !=
899 dep_sclk_table->entries[i].clk) {
901 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].value =
902 dep_sclk_table->entries[i].clk;
904 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].enabled =
905 (i == 0) ? true : false;
906 data->dpm_table.sclk_table.count++;
909 if (hwmgr->platform_descriptor.overdriveLimit.engineClock == 0)
910 hwmgr->platform_descriptor.overdriveLimit.engineClock = dep_sclk_table->entries[i-1].clk;
911 /* Initialize Mclk DPM table based on allow Mclk values */
912 data->dpm_table.mclk_table.count = 0;
913 for (i = 0; i < dep_mclk_table->count; i++) {
914 if (i == 0 || data->dpm_table.mclk_table.dpm_levels
915 [data->dpm_table.mclk_table.count - 1].value !=
916 dep_mclk_table->entries[i].clk) {
917 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].value =
918 dep_mclk_table->entries[i].clk;
919 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].enabled =
920 (i == 0) ? true : false;
921 data->dpm_table.mclk_table.count++;
925 if (hwmgr->platform_descriptor.overdriveLimit.memoryClock == 0)
926 hwmgr->platform_descriptor.overdriveLimit.memoryClock = dep_mclk_table->entries[i-1].clk;
930 static int smu7_odn_initial_default_setting(struct pp_hwmgr *hwmgr)
932 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
933 struct smu7_odn_dpm_table *odn_table = &(data->odn_dpm_table);
934 struct phm_ppt_v1_information *table_info =
935 (struct phm_ppt_v1_information *)(hwmgr->pptable);
938 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table;
939 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table;
940 struct phm_odn_performance_level *entries;
942 if (table_info == NULL)
945 dep_sclk_table = table_info->vdd_dep_on_sclk;
946 dep_mclk_table = table_info->vdd_dep_on_mclk;
948 odn_table->odn_core_clock_dpm_levels.num_of_pl =
949 data->golden_dpm_table.sclk_table.count;
950 entries = odn_table->odn_core_clock_dpm_levels.entries;
951 for (i=0; i<data->golden_dpm_table.sclk_table.count; i++) {
952 entries[i].clock = data->golden_dpm_table.sclk_table.dpm_levels[i].value;
953 entries[i].enabled = true;
954 entries[i].vddc = dep_sclk_table->entries[i].vddc;
957 smu_get_voltage_dependency_table_ppt_v1(dep_sclk_table,
958 (struct phm_ppt_v1_clock_voltage_dependency_table *)&(odn_table->vdd_dependency_on_sclk));
960 odn_table->odn_memory_clock_dpm_levels.num_of_pl =
961 data->golden_dpm_table.mclk_table.count;
962 entries = odn_table->odn_memory_clock_dpm_levels.entries;
963 for (i=0; i<data->golden_dpm_table.mclk_table.count; i++) {
964 entries[i].clock = data->golden_dpm_table.mclk_table.dpm_levels[i].value;
965 entries[i].enabled = true;
966 entries[i].vddc = dep_mclk_table->entries[i].vddc;
969 smu_get_voltage_dependency_table_ppt_v1(dep_mclk_table,
970 (struct phm_ppt_v1_clock_voltage_dependency_table *)&(odn_table->vdd_dependency_on_mclk));
975 static void smu7_setup_voltage_range_from_vbios(struct pp_hwmgr *hwmgr)
977 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
978 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table;
979 struct phm_ppt_v1_information *table_info =
980 (struct phm_ppt_v1_information *)(hwmgr->pptable);
981 uint32_t min_vddc = 0;
982 uint32_t max_vddc = 0;
987 dep_sclk_table = table_info->vdd_dep_on_sclk;
989 atomctrl_get_voltage_range(hwmgr, &max_vddc, &min_vddc);
991 if (min_vddc == 0 || min_vddc > 2000
992 || min_vddc > dep_sclk_table->entries[0].vddc)
993 min_vddc = dep_sclk_table->entries[0].vddc;
995 if (max_vddc == 0 || max_vddc > 2000
996 || max_vddc < dep_sclk_table->entries[dep_sclk_table->count-1].vddc)
997 max_vddc = dep_sclk_table->entries[dep_sclk_table->count-1].vddc;
999 data->odn_dpm_table.min_vddc = min_vddc;
1000 data->odn_dpm_table.max_vddc = max_vddc;
1003 static void smu7_check_dpm_table_updated(struct pp_hwmgr *hwmgr)
1005 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1006 struct smu7_odn_dpm_table *odn_table = &(data->odn_dpm_table);
1007 struct phm_ppt_v1_information *table_info =
1008 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1011 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table;
1012 struct phm_ppt_v1_clock_voltage_dependency_table *odn_dep_table;
1014 if (table_info == NULL)
1017 for (i = 0; i < data->dpm_table.sclk_table.count; i++) {
1018 if (odn_table->odn_core_clock_dpm_levels.entries[i].clock !=
1019 data->dpm_table.sclk_table.dpm_levels[i].value) {
1020 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK;
1025 for (i = 0; i < data->dpm_table.mclk_table.count; i++) {
1026 if (odn_table->odn_memory_clock_dpm_levels.entries[i].clock !=
1027 data->dpm_table.mclk_table.dpm_levels[i].value) {
1028 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_MCLK;
1033 dep_table = table_info->vdd_dep_on_mclk;
1034 odn_dep_table = (struct phm_ppt_v1_clock_voltage_dependency_table *)&(odn_table->vdd_dependency_on_mclk);
1036 for (i = 0; i < dep_table->count; i++) {
1037 if (dep_table->entries[i].vddc != odn_dep_table->entries[i].vddc) {
1038 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_VDDC | DPMTABLE_OD_UPDATE_MCLK;
1043 dep_table = table_info->vdd_dep_on_sclk;
1044 odn_dep_table = (struct phm_ppt_v1_clock_voltage_dependency_table *)&(odn_table->vdd_dependency_on_sclk);
1045 for (i = 0; i < dep_table->count; i++) {
1046 if (dep_table->entries[i].vddc != odn_dep_table->entries[i].vddc) {
1047 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_VDDC | DPMTABLE_OD_UPDATE_SCLK;
1051 if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_VDDC) {
1052 data->need_update_smu7_dpm_table &= ~DPMTABLE_OD_UPDATE_VDDC;
1053 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK | DPMTABLE_OD_UPDATE_MCLK;
1057 static int smu7_setup_default_dpm_tables(struct pp_hwmgr *hwmgr)
1059 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1061 smu7_reset_dpm_tables(hwmgr);
1063 if (hwmgr->pp_table_version == PP_TABLE_V1)
1064 smu7_setup_dpm_tables_v1(hwmgr);
1065 else if (hwmgr->pp_table_version == PP_TABLE_V0)
1066 smu7_setup_dpm_tables_v0(hwmgr);
1068 smu7_setup_default_pcie_table(hwmgr);
1070 /* save a copy of the default DPM table */
1071 memcpy(&(data->golden_dpm_table), &(data->dpm_table),
1072 sizeof(struct smu7_dpm_table));
1074 /* initialize ODN table */
1075 if (hwmgr->od_enabled) {
1076 if (data->odn_dpm_table.max_vddc) {
1077 smu7_check_dpm_table_updated(hwmgr);
1079 smu7_setup_voltage_range_from_vbios(hwmgr);
1080 smu7_odn_initial_default_setting(hwmgr);
1086 static int smu7_enable_vrhot_gpio_interrupt(struct pp_hwmgr *hwmgr)
1089 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1090 PHM_PlatformCaps_RegulatorHot))
1091 return smum_send_msg_to_smc(hwmgr,
1092 PPSMC_MSG_EnableVRHotGPIOInterrupt,
1098 static int smu7_enable_sclk_control(struct pp_hwmgr *hwmgr)
1100 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
1101 SCLK_PWRMGT_OFF, 0);
1105 static int smu7_enable_ulv(struct pp_hwmgr *hwmgr)
1107 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1109 if (data->ulv_supported)
1110 return smum_send_msg_to_smc(hwmgr, PPSMC_MSG_EnableULV, NULL);
1115 static int smu7_disable_ulv(struct pp_hwmgr *hwmgr)
1117 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1119 if (data->ulv_supported)
1120 return smum_send_msg_to_smc(hwmgr, PPSMC_MSG_DisableULV, NULL);
1125 static int smu7_enable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
1127 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1128 PHM_PlatformCaps_SclkDeepSleep)) {
1129 if (smum_send_msg_to_smc(hwmgr, PPSMC_MSG_MASTER_DeepSleep_ON, NULL))
1130 PP_ASSERT_WITH_CODE(false,
1131 "Attempt to enable Master Deep Sleep switch failed!",
1134 if (smum_send_msg_to_smc(hwmgr,
1135 PPSMC_MSG_MASTER_DeepSleep_OFF,
1137 PP_ASSERT_WITH_CODE(false,
1138 "Attempt to disable Master Deep Sleep switch failed!",
1146 static int smu7_disable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
1148 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1149 PHM_PlatformCaps_SclkDeepSleep)) {
1150 if (smum_send_msg_to_smc(hwmgr,
1151 PPSMC_MSG_MASTER_DeepSleep_OFF,
1153 PP_ASSERT_WITH_CODE(false,
1154 "Attempt to disable Master Deep Sleep switch failed!",
1162 static int smu7_disable_sclk_vce_handshake(struct pp_hwmgr *hwmgr)
1164 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1165 uint32_t soft_register_value = 0;
1166 uint32_t handshake_disables_offset = data->soft_regs_start
1167 + smum_get_offsetof(hwmgr,
1168 SMU_SoftRegisters, HandshakeDisables);
1170 soft_register_value = cgs_read_ind_register(hwmgr->device,
1171 CGS_IND_REG__SMC, handshake_disables_offset);
1172 soft_register_value |= SMU7_VCE_SCLK_HANDSHAKE_DISABLE;
1173 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1174 handshake_disables_offset, soft_register_value);
1178 static int smu7_disable_handshake_uvd(struct pp_hwmgr *hwmgr)
1180 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1181 uint32_t soft_register_value = 0;
1182 uint32_t handshake_disables_offset = data->soft_regs_start
1183 + smum_get_offsetof(hwmgr,
1184 SMU_SoftRegisters, HandshakeDisables);
1186 soft_register_value = cgs_read_ind_register(hwmgr->device,
1187 CGS_IND_REG__SMC, handshake_disables_offset);
1188 soft_register_value |= smum_get_mac_definition(hwmgr,
1189 SMU_UVD_MCLK_HANDSHAKE_DISABLE);
1190 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1191 handshake_disables_offset, soft_register_value);
1195 static int smu7_enable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
1197 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1199 /* enable SCLK dpm */
1200 if (!data->sclk_dpm_key_disabled) {
1201 if (hwmgr->chip_id >= CHIP_POLARIS10 &&
1202 hwmgr->chip_id <= CHIP_VEGAM)
1203 smu7_disable_sclk_vce_handshake(hwmgr);
1205 PP_ASSERT_WITH_CODE(
1206 (0 == smum_send_msg_to_smc(hwmgr, PPSMC_MSG_DPM_Enable, NULL)),
1207 "Failed to enable SCLK DPM during DPM Start Function!",
1211 /* enable MCLK dpm */
1212 if (0 == data->mclk_dpm_key_disabled) {
1213 if (!(hwmgr->feature_mask & PP_UVD_HANDSHAKE_MASK))
1214 smu7_disable_handshake_uvd(hwmgr);
1216 PP_ASSERT_WITH_CODE(
1217 (0 == smum_send_msg_to_smc(hwmgr,
1218 PPSMC_MSG_MCLKDPM_Enable,
1220 "Failed to enable MCLK DPM during DPM Start Function!",
1223 if ((hwmgr->chip_family == AMDGPU_FAMILY_CI) ||
1224 (hwmgr->chip_id == CHIP_POLARIS10) ||
1225 (hwmgr->chip_id == CHIP_POLARIS11) ||
1226 (hwmgr->chip_id == CHIP_POLARIS12) ||
1227 (hwmgr->chip_id == CHIP_TONGA))
1228 PHM_WRITE_FIELD(hwmgr->device, MC_SEQ_CNTL_3, CAC_EN, 0x1);
1231 if (hwmgr->chip_family == AMDGPU_FAMILY_CI) {
1232 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, 0xc0400d30, 0x5);
1233 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, 0xc0400d3c, 0x5);
1234 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, 0xc0400d80, 0x100005);
1236 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, 0xc0400d30, 0x400005);
1237 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, 0xc0400d3c, 0x400005);
1238 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, 0xc0400d80, 0x500005);
1240 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC0_CNTL, 0x5);
1241 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC1_CNTL, 0x5);
1242 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_CPL_CNTL, 0x100005);
1244 if (hwmgr->chip_id == CHIP_VEGAM) {
1245 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC0_CNTL, 0x400009);
1246 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC1_CNTL, 0x400009);
1248 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC0_CNTL, 0x400005);
1249 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC1_CNTL, 0x400005);
1251 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_CPL_CNTL, 0x500005);
1258 static int smu7_start_dpm(struct pp_hwmgr *hwmgr)
1260 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1262 /*enable general power management */
1264 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
1265 GLOBAL_PWRMGT_EN, 1);
1267 /* enable sclk deep sleep */
1269 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
1272 /* prepare for PCIE DPM */
1274 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1275 data->soft_regs_start +
1276 smum_get_offsetof(hwmgr, SMU_SoftRegisters,
1277 VoltageChangeTimeout), 0x1000);
1278 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE,
1279 SWRST_COMMAND_1, RESETLC, 0x0);
1281 if (hwmgr->chip_family == AMDGPU_FAMILY_CI)
1282 cgs_write_register(hwmgr->device, 0x1488,
1283 (cgs_read_register(hwmgr->device, 0x1488) & ~0x1));
1285 if (smu7_enable_sclk_mclk_dpm(hwmgr)) {
1286 pr_err("Failed to enable Sclk DPM and Mclk DPM!");
1290 /* enable PCIE dpm */
1291 if (0 == data->pcie_dpm_key_disabled) {
1292 PP_ASSERT_WITH_CODE(
1293 (0 == smum_send_msg_to_smc(hwmgr,
1294 PPSMC_MSG_PCIeDPM_Enable,
1296 "Failed to enable pcie DPM during DPM Start Function!",
1299 PP_ASSERT_WITH_CODE(
1300 (0 == smum_send_msg_to_smc(hwmgr,
1301 PPSMC_MSG_PCIeDPM_Disable,
1303 "Failed to disble pcie DPM during DPM Start Function!",
1307 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1308 PHM_PlatformCaps_Falcon_QuickTransition)) {
1309 PP_ASSERT_WITH_CODE((0 == smum_send_msg_to_smc(hwmgr,
1310 PPSMC_MSG_EnableACDCGPIOInterrupt,
1312 "Failed to enable AC DC GPIO Interrupt!",
1319 static int smu7_disable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
1321 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1323 /* disable SCLK dpm */
1324 if (!data->sclk_dpm_key_disabled) {
1325 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
1326 "Trying to disable SCLK DPM when DPM is disabled",
1328 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_DPM_Disable, NULL);
1331 /* disable MCLK dpm */
1332 if (!data->mclk_dpm_key_disabled) {
1333 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
1334 "Trying to disable MCLK DPM when DPM is disabled",
1336 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_MCLKDPM_Disable, NULL);
1342 static int smu7_stop_dpm(struct pp_hwmgr *hwmgr)
1344 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1346 /* disable general power management */
1347 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
1348 GLOBAL_PWRMGT_EN, 0);
1349 /* disable sclk deep sleep */
1350 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
1353 /* disable PCIE dpm */
1354 if (!data->pcie_dpm_key_disabled) {
1355 PP_ASSERT_WITH_CODE(
1356 (smum_send_msg_to_smc(hwmgr,
1357 PPSMC_MSG_PCIeDPM_Disable,
1359 "Failed to disable pcie DPM during DPM Stop Function!",
1363 smu7_disable_sclk_mclk_dpm(hwmgr);
1365 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
1366 "Trying to disable voltage DPM when DPM is disabled",
1369 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_Voltage_Cntl_Disable, NULL);
1374 static void smu7_set_dpm_event_sources(struct pp_hwmgr *hwmgr, uint32_t sources)
1377 enum DPM_EVENT_SRC src;
1381 pr_err("Unknown throttling event sources.");
1387 case (1 << PHM_AutoThrottleSource_Thermal):
1389 src = DPM_EVENT_SRC_DIGITAL;
1391 case (1 << PHM_AutoThrottleSource_External):
1393 src = DPM_EVENT_SRC_EXTERNAL;
1395 case (1 << PHM_AutoThrottleSource_External) |
1396 (1 << PHM_AutoThrottleSource_Thermal):
1398 src = DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL;
1401 /* Order matters - don't enable thermal protection for the wrong source. */
1403 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_THERMAL_CTRL,
1404 DPM_EVENT_SRC, src);
1405 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
1406 THERMAL_PROTECTION_DIS,
1407 !phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1408 PHM_PlatformCaps_ThermalController));
1410 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
1411 THERMAL_PROTECTION_DIS, 1);
1414 static int smu7_enable_auto_throttle_source(struct pp_hwmgr *hwmgr,
1415 PHM_AutoThrottleSource source)
1417 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1419 if (!(data->active_auto_throttle_sources & (1 << source))) {
1420 data->active_auto_throttle_sources |= 1 << source;
1421 smu7_set_dpm_event_sources(hwmgr, data->active_auto_throttle_sources);
1426 static int smu7_enable_thermal_auto_throttle(struct pp_hwmgr *hwmgr)
1428 return smu7_enable_auto_throttle_source(hwmgr, PHM_AutoThrottleSource_Thermal);
1431 static int smu7_disable_auto_throttle_source(struct pp_hwmgr *hwmgr,
1432 PHM_AutoThrottleSource source)
1434 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1436 if (data->active_auto_throttle_sources & (1 << source)) {
1437 data->active_auto_throttle_sources &= ~(1 << source);
1438 smu7_set_dpm_event_sources(hwmgr, data->active_auto_throttle_sources);
1443 static int smu7_disable_thermal_auto_throttle(struct pp_hwmgr *hwmgr)
1445 return smu7_disable_auto_throttle_source(hwmgr, PHM_AutoThrottleSource_Thermal);
1448 static int smu7_pcie_performance_request(struct pp_hwmgr *hwmgr)
1450 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1451 data->pcie_performance_request = true;
1456 static int smu7_program_edc_didt_registers(struct pp_hwmgr *hwmgr,
1457 uint32_t *cac_config_regs,
1458 AtomCtrl_EDCLeakgeTable *edc_leakage_table)
1460 uint32_t data, i = 0;
1462 while (cac_config_regs[i] != 0xFFFFFFFF) {
1463 data = edc_leakage_table->DIDT_REG[i];
1464 cgs_write_ind_register(hwmgr->device,
1474 static int smu7_populate_edc_leakage_registers(struct pp_hwmgr *hwmgr)
1476 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1479 if (!data->disable_edc_leakage_controller &&
1480 data->edc_hilo_leakage_offset_from_vbios.usEdcDidtLoDpm7TableOffset &&
1481 data->edc_hilo_leakage_offset_from_vbios.usEdcDidtHiDpm7TableOffset) {
1482 ret = smu7_program_edc_didt_registers(hwmgr,
1484 &data->edc_leakage_table);
1488 ret = smum_send_msg_to_smc(hwmgr,
1489 (PPSMC_Msg)PPSMC_MSG_EnableEDCController,
1492 ret = smum_send_msg_to_smc(hwmgr,
1493 (PPSMC_Msg)PPSMC_MSG_DisableEDCController,
1500 static int smu7_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
1505 if (smu7_voltage_control(hwmgr)) {
1506 tmp_result = smu7_enable_voltage_control(hwmgr);
1507 PP_ASSERT_WITH_CODE(tmp_result == 0,
1508 "Failed to enable voltage control!",
1509 result = tmp_result);
1511 tmp_result = smu7_construct_voltage_tables(hwmgr);
1512 PP_ASSERT_WITH_CODE((0 == tmp_result),
1513 "Failed to construct voltage tables!",
1514 result = tmp_result);
1516 smum_initialize_mc_reg_table(hwmgr);
1518 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1519 PHM_PlatformCaps_EngineSpreadSpectrumSupport))
1520 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1521 GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, 1);
1523 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1524 PHM_PlatformCaps_ThermalController))
1525 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1526 GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, 0);
1528 tmp_result = smu7_program_static_screen_threshold_parameters(hwmgr);
1529 PP_ASSERT_WITH_CODE((0 == tmp_result),
1530 "Failed to program static screen threshold parameters!",
1531 result = tmp_result);
1533 tmp_result = smu7_enable_display_gap(hwmgr);
1534 PP_ASSERT_WITH_CODE((0 == tmp_result),
1535 "Failed to enable display gap!", result = tmp_result);
1537 tmp_result = smu7_program_voting_clients(hwmgr);
1538 PP_ASSERT_WITH_CODE((0 == tmp_result),
1539 "Failed to program voting clients!", result = tmp_result);
1541 tmp_result = smum_process_firmware_header(hwmgr);
1542 PP_ASSERT_WITH_CODE((0 == tmp_result),
1543 "Failed to process firmware header!", result = tmp_result);
1545 if (hwmgr->chip_id != CHIP_VEGAM) {
1546 tmp_result = smu7_initial_switch_from_arbf0_to_f1(hwmgr);
1547 PP_ASSERT_WITH_CODE((0 == tmp_result),
1548 "Failed to initialize switch from ArbF0 to F1!",
1549 result = tmp_result);
1552 result = smu7_setup_default_dpm_tables(hwmgr);
1553 PP_ASSERT_WITH_CODE(0 == result,
1554 "Failed to setup default DPM tables!", return result);
1556 tmp_result = smum_init_smc_table(hwmgr);
1557 PP_ASSERT_WITH_CODE((0 == tmp_result),
1558 "Failed to initialize SMC table!", result = tmp_result);
1560 tmp_result = smu7_enable_vrhot_gpio_interrupt(hwmgr);
1561 PP_ASSERT_WITH_CODE((0 == tmp_result),
1562 "Failed to enable VR hot GPIO interrupt!", result = tmp_result);
1564 if (hwmgr->chip_id >= CHIP_POLARIS10 &&
1565 hwmgr->chip_id <= CHIP_VEGAM) {
1566 tmp_result = smu7_notify_has_display(hwmgr);
1567 PP_ASSERT_WITH_CODE((0 == tmp_result),
1568 "Failed to enable display setting!", result = tmp_result);
1570 smum_send_msg_to_smc(hwmgr, (PPSMC_Msg)PPSMC_NoDisplay, NULL);
1573 if (hwmgr->chip_id >= CHIP_POLARIS10 &&
1574 hwmgr->chip_id <= CHIP_VEGAM) {
1575 tmp_result = smu7_populate_edc_leakage_registers(hwmgr);
1576 PP_ASSERT_WITH_CODE((0 == tmp_result),
1577 "Failed to populate edc leakage registers!", result = tmp_result);
1580 tmp_result = smu7_enable_sclk_control(hwmgr);
1581 PP_ASSERT_WITH_CODE((0 == tmp_result),
1582 "Failed to enable SCLK control!", result = tmp_result);
1584 tmp_result = smu7_enable_smc_voltage_controller(hwmgr);
1585 PP_ASSERT_WITH_CODE((0 == tmp_result),
1586 "Failed to enable voltage control!", result = tmp_result);
1588 tmp_result = smu7_enable_ulv(hwmgr);
1589 PP_ASSERT_WITH_CODE((0 == tmp_result),
1590 "Failed to enable ULV!", result = tmp_result);
1592 tmp_result = smu7_enable_deep_sleep_master_switch(hwmgr);
1593 PP_ASSERT_WITH_CODE((0 == tmp_result),
1594 "Failed to enable deep sleep master switch!", result = tmp_result);
1596 tmp_result = smu7_enable_didt_config(hwmgr);
1597 PP_ASSERT_WITH_CODE((tmp_result == 0),
1598 "Failed to enable deep sleep master switch!", result = tmp_result);
1600 tmp_result = smu7_start_dpm(hwmgr);
1601 PP_ASSERT_WITH_CODE((0 == tmp_result),
1602 "Failed to start DPM!", result = tmp_result);
1604 tmp_result = smu7_enable_smc_cac(hwmgr);
1605 PP_ASSERT_WITH_CODE((0 == tmp_result),
1606 "Failed to enable SMC CAC!", result = tmp_result);
1608 tmp_result = smu7_enable_power_containment(hwmgr);
1609 PP_ASSERT_WITH_CODE((0 == tmp_result),
1610 "Failed to enable power containment!", result = tmp_result);
1612 tmp_result = smu7_power_control_set_level(hwmgr);
1613 PP_ASSERT_WITH_CODE((0 == tmp_result),
1614 "Failed to power control set level!", result = tmp_result);
1616 tmp_result = smu7_enable_thermal_auto_throttle(hwmgr);
1617 PP_ASSERT_WITH_CODE((0 == tmp_result),
1618 "Failed to enable thermal auto throttle!", result = tmp_result);
1620 tmp_result = smu7_pcie_performance_request(hwmgr);
1621 PP_ASSERT_WITH_CODE((0 == tmp_result),
1622 "pcie performance request failed!", result = tmp_result);
1627 static int smu7_avfs_control(struct pp_hwmgr *hwmgr, bool enable)
1629 if (!hwmgr->avfs_supported)
1633 if (!PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device,
1634 CGS_IND_REG__SMC, FEATURE_STATUS, AVS_ON)) {
1635 PP_ASSERT_WITH_CODE(!smum_send_msg_to_smc(
1636 hwmgr, PPSMC_MSG_EnableAvfs, NULL),
1637 "Failed to enable AVFS!",
1640 } else if (PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device,
1641 CGS_IND_REG__SMC, FEATURE_STATUS, AVS_ON)) {
1642 PP_ASSERT_WITH_CODE(!smum_send_msg_to_smc(
1643 hwmgr, PPSMC_MSG_DisableAvfs, NULL),
1644 "Failed to disable AVFS!",
1651 static int smu7_update_avfs(struct pp_hwmgr *hwmgr)
1653 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1655 if (!hwmgr->avfs_supported)
1658 if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_VDDC) {
1659 smu7_avfs_control(hwmgr, false);
1660 } else if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_SCLK) {
1661 smu7_avfs_control(hwmgr, false);
1662 smu7_avfs_control(hwmgr, true);
1664 smu7_avfs_control(hwmgr, true);
1670 static int smu7_disable_dpm_tasks(struct pp_hwmgr *hwmgr)
1672 int tmp_result, result = 0;
1674 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1675 PHM_PlatformCaps_ThermalController))
1676 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1677 GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, 1);
1679 tmp_result = smu7_disable_power_containment(hwmgr);
1680 PP_ASSERT_WITH_CODE((tmp_result == 0),
1681 "Failed to disable power containment!", result = tmp_result);
1683 tmp_result = smu7_disable_smc_cac(hwmgr);
1684 PP_ASSERT_WITH_CODE((tmp_result == 0),
1685 "Failed to disable SMC CAC!", result = tmp_result);
1687 tmp_result = smu7_disable_didt_config(hwmgr);
1688 PP_ASSERT_WITH_CODE((tmp_result == 0),
1689 "Failed to disable DIDT!", result = tmp_result);
1691 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1692 CG_SPLL_SPREAD_SPECTRUM, SSEN, 0);
1693 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1694 GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, 0);
1696 tmp_result = smu7_disable_thermal_auto_throttle(hwmgr);
1697 PP_ASSERT_WITH_CODE((tmp_result == 0),
1698 "Failed to disable thermal auto throttle!", result = tmp_result);
1700 tmp_result = smu7_avfs_control(hwmgr, false);
1701 PP_ASSERT_WITH_CODE((tmp_result == 0),
1702 "Failed to disable AVFS!", result = tmp_result);
1704 tmp_result = smu7_stop_dpm(hwmgr);
1705 PP_ASSERT_WITH_CODE((tmp_result == 0),
1706 "Failed to stop DPM!", result = tmp_result);
1708 tmp_result = smu7_disable_deep_sleep_master_switch(hwmgr);
1709 PP_ASSERT_WITH_CODE((tmp_result == 0),
1710 "Failed to disable deep sleep master switch!", result = tmp_result);
1712 tmp_result = smu7_disable_ulv(hwmgr);
1713 PP_ASSERT_WITH_CODE((tmp_result == 0),
1714 "Failed to disable ULV!", result = tmp_result);
1716 tmp_result = smu7_clear_voting_clients(hwmgr);
1717 PP_ASSERT_WITH_CODE((tmp_result == 0),
1718 "Failed to clear voting clients!", result = tmp_result);
1720 tmp_result = smu7_reset_to_default(hwmgr);
1721 PP_ASSERT_WITH_CODE((tmp_result == 0),
1722 "Failed to reset to default!", result = tmp_result);
1724 tmp_result = smum_stop_smc(hwmgr);
1725 PP_ASSERT_WITH_CODE((tmp_result == 0),
1726 "Failed to stop smc!", result = tmp_result);
1728 tmp_result = smu7_force_switch_to_arbf0(hwmgr);
1729 PP_ASSERT_WITH_CODE((tmp_result == 0),
1730 "Failed to force to switch arbf0!", result = tmp_result);
1735 static void smu7_init_dpm_defaults(struct pp_hwmgr *hwmgr)
1737 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1738 struct phm_ppt_v1_information *table_info =
1739 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1740 struct amdgpu_device *adev = hwmgr->adev;
1744 data->dll_default_on = false;
1745 data->mclk_dpm0_activity_target = 0xa;
1746 data->vddc_vddgfx_delta = 300;
1747 data->static_screen_threshold = SMU7_STATICSCREENTHRESHOLD_DFLT;
1748 data->static_screen_threshold_unit = SMU7_STATICSCREENTHRESHOLDUNIT_DFLT;
1749 data->voting_rights_clients[0] = SMU7_VOTINGRIGHTSCLIENTS_DFLT0;
1750 data->voting_rights_clients[1]= SMU7_VOTINGRIGHTSCLIENTS_DFLT1;
1751 data->voting_rights_clients[2] = SMU7_VOTINGRIGHTSCLIENTS_DFLT2;
1752 data->voting_rights_clients[3]= SMU7_VOTINGRIGHTSCLIENTS_DFLT3;
1753 data->voting_rights_clients[4]= SMU7_VOTINGRIGHTSCLIENTS_DFLT4;
1754 data->voting_rights_clients[5]= SMU7_VOTINGRIGHTSCLIENTS_DFLT5;
1755 data->voting_rights_clients[6]= SMU7_VOTINGRIGHTSCLIENTS_DFLT6;
1756 data->voting_rights_clients[7]= SMU7_VOTINGRIGHTSCLIENTS_DFLT7;
1758 data->mclk_dpm_key_disabled = hwmgr->feature_mask & PP_MCLK_DPM_MASK ? false : true;
1759 data->sclk_dpm_key_disabled = hwmgr->feature_mask & PP_SCLK_DPM_MASK ? false : true;
1760 data->pcie_dpm_key_disabled = hwmgr->feature_mask & PP_PCIE_DPM_MASK ? false : true;
1761 /* need to set voltage control types before EVV patching */
1762 data->voltage_control = SMU7_VOLTAGE_CONTROL_NONE;
1763 data->vddci_control = SMU7_VOLTAGE_CONTROL_NONE;
1764 data->mvdd_control = SMU7_VOLTAGE_CONTROL_NONE;
1765 data->enable_tdc_limit_feature = true;
1766 data->enable_pkg_pwr_tracking_feature = true;
1767 data->force_pcie_gen = PP_PCIEGenInvalid;
1768 data->ulv_supported = hwmgr->feature_mask & PP_ULV_MASK ? true : false;
1769 data->current_profile_setting.bupdate_sclk = 1;
1770 data->current_profile_setting.sclk_up_hyst = 0;
1771 data->current_profile_setting.sclk_down_hyst = 100;
1772 data->current_profile_setting.sclk_activity = SMU7_SCLK_TARGETACTIVITY_DFLT;
1773 data->current_profile_setting.bupdate_mclk = 1;
1774 if (hwmgr->chip_id >= CHIP_POLARIS10) {
1775 if (adev->gmc.vram_width == 256) {
1776 data->current_profile_setting.mclk_up_hyst = 10;
1777 data->current_profile_setting.mclk_down_hyst = 60;
1778 data->current_profile_setting.mclk_activity = 25;
1779 } else if (adev->gmc.vram_width == 128) {
1780 data->current_profile_setting.mclk_up_hyst = 5;
1781 data->current_profile_setting.mclk_down_hyst = 16;
1782 data->current_profile_setting.mclk_activity = 20;
1783 } else if (adev->gmc.vram_width == 64) {
1784 data->current_profile_setting.mclk_up_hyst = 3;
1785 data->current_profile_setting.mclk_down_hyst = 16;
1786 data->current_profile_setting.mclk_activity = 20;
1789 data->current_profile_setting.mclk_up_hyst = 0;
1790 data->current_profile_setting.mclk_down_hyst = 100;
1791 data->current_profile_setting.mclk_activity = SMU7_MCLK_TARGETACTIVITY_DFLT;
1793 hwmgr->workload_mask = 1 << hwmgr->workload_prority[PP_SMC_POWER_PROFILE_FULLSCREEN3D];
1794 hwmgr->power_profile_mode = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
1795 hwmgr->default_power_profile_mode = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
1797 if (hwmgr->chip_id == CHIP_HAWAII) {
1798 data->thermal_temp_setting.temperature_low = 94500;
1799 data->thermal_temp_setting.temperature_high = 95000;
1800 data->thermal_temp_setting.temperature_shutdown = 104000;
1802 data->thermal_temp_setting.temperature_low = 99500;
1803 data->thermal_temp_setting.temperature_high = 100000;
1804 data->thermal_temp_setting.temperature_shutdown = 104000;
1807 data->fast_watermark_threshold = 100;
1808 if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1809 VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_SVID2))
1810 data->voltage_control = SMU7_VOLTAGE_CONTROL_BY_SVID2;
1811 else if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1812 VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_GPIO_LUT))
1813 data->voltage_control = SMU7_VOLTAGE_CONTROL_BY_GPIO;
1815 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1816 PHM_PlatformCaps_ControlVDDGFX)) {
1817 if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1818 VOLTAGE_TYPE_VDDGFX, VOLTAGE_OBJ_SVID2)) {
1819 data->vdd_gfx_control = SMU7_VOLTAGE_CONTROL_BY_SVID2;
1823 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1824 PHM_PlatformCaps_EnableMVDDControl)) {
1825 if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1826 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT))
1827 data->mvdd_control = SMU7_VOLTAGE_CONTROL_BY_GPIO;
1828 else if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1829 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_SVID2))
1830 data->mvdd_control = SMU7_VOLTAGE_CONTROL_BY_SVID2;
1833 if (SMU7_VOLTAGE_CONTROL_NONE == data->vdd_gfx_control)
1834 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1835 PHM_PlatformCaps_ControlVDDGFX);
1837 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1838 PHM_PlatformCaps_ControlVDDCI)) {
1839 if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1840 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT))
1841 data->vddci_control = SMU7_VOLTAGE_CONTROL_BY_GPIO;
1842 else if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1843 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_SVID2))
1844 data->vddci_control = SMU7_VOLTAGE_CONTROL_BY_SVID2;
1847 if (data->mvdd_control == SMU7_VOLTAGE_CONTROL_NONE)
1848 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1849 PHM_PlatformCaps_EnableMVDDControl);
1851 if (data->vddci_control == SMU7_VOLTAGE_CONTROL_NONE)
1852 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1853 PHM_PlatformCaps_ControlVDDCI);
1855 data->vddc_phase_shed_control = 1;
1856 if ((hwmgr->chip_id == CHIP_POLARIS12) ||
1857 ASICID_IS_P20(adev->pdev->device, adev->pdev->revision) ||
1858 ASICID_IS_P21(adev->pdev->device, adev->pdev->revision) ||
1859 ASICID_IS_P30(adev->pdev->device, adev->pdev->revision) ||
1860 ASICID_IS_P31(adev->pdev->device, adev->pdev->revision)) {
1861 if (data->voltage_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
1862 atomctrl_get_svi2_info(hwmgr, VOLTAGE_TYPE_VDDC, &tmp1, &tmp2,
1864 tmp3 = (tmp3 >> 5) & 0x3;
1865 data->vddc_phase_shed_control = ((tmp3 << 1) | (tmp3 >> 1)) & 0x3;
1867 } else if (hwmgr->chip_family == AMDGPU_FAMILY_CI) {
1868 data->vddc_phase_shed_control = 1;
1871 if ((hwmgr->pp_table_version != PP_TABLE_V0) && (hwmgr->feature_mask & PP_CLOCK_STRETCH_MASK)
1872 && (table_info->cac_dtp_table->usClockStretchAmount != 0))
1873 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
1874 PHM_PlatformCaps_ClockStretcher);
1876 data->pcie_gen_performance.max = PP_PCIEGen1;
1877 data->pcie_gen_performance.min = PP_PCIEGen3;
1878 data->pcie_gen_power_saving.max = PP_PCIEGen1;
1879 data->pcie_gen_power_saving.min = PP_PCIEGen3;
1880 data->pcie_lane_performance.max = 0;
1881 data->pcie_lane_performance.min = 16;
1882 data->pcie_lane_power_saving.max = 0;
1883 data->pcie_lane_power_saving.min = 16;
1886 if (adev->pg_flags & AMD_PG_SUPPORT_UVD)
1887 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
1888 PHM_PlatformCaps_UVDPowerGating);
1889 if (adev->pg_flags & AMD_PG_SUPPORT_VCE)
1890 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
1891 PHM_PlatformCaps_VCEPowerGating);
1893 data->disable_edc_leakage_controller = true;
1894 if (((adev->asic_type == CHIP_POLARIS10) && hwmgr->is_kicker) ||
1895 ((adev->asic_type == CHIP_POLARIS11) && hwmgr->is_kicker) ||
1896 (adev->asic_type == CHIP_POLARIS12) ||
1897 (adev->asic_type == CHIP_VEGAM))
1898 data->disable_edc_leakage_controller = false;
1900 if (!atomctrl_is_asic_internal_ss_supported(hwmgr)) {
1901 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1902 PHM_PlatformCaps_MemorySpreadSpectrumSupport);
1903 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1904 PHM_PlatformCaps_EngineSpreadSpectrumSupport);
1907 if ((adev->pdev->device == 0x699F) &&
1908 (adev->pdev->revision == 0xCF)) {
1909 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1910 PHM_PlatformCaps_PowerContainment);
1911 data->enable_tdc_limit_feature = false;
1912 data->enable_pkg_pwr_tracking_feature = false;
1913 data->disable_edc_leakage_controller = true;
1914 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1915 PHM_PlatformCaps_ClockStretcher);
1919 static int smu7_calculate_ro_range(struct pp_hwmgr *hwmgr)
1921 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1922 struct amdgpu_device *adev = hwmgr->adev;
1923 uint32_t asicrev1, evv_revision, max = 0, min = 0;
1925 atomctrl_read_efuse(hwmgr, STRAP_EVV_REVISION_LSB, STRAP_EVV_REVISION_MSB,
1928 atomctrl_read_efuse(hwmgr, 568, 579, &asicrev1);
1930 if (ASICID_IS_P20(adev->pdev->device, adev->pdev->revision) ||
1931 ASICID_IS_P30(adev->pdev->device, adev->pdev->revision)) {
1934 } else if (ASICID_IS_P21(adev->pdev->device, adev->pdev->revision) ||
1935 ASICID_IS_P31(adev->pdev->device, adev->pdev->revision)) {
1938 } else if (hwmgr->chip_id == CHIP_POLARIS10) {
1939 if (adev->pdev->subsystem_vendor == 0x106B) {
1943 if (evv_revision == 0) {
1946 } else if (evv_revision == 1) {
1947 if (asicrev1 == 326) {
1950 /* TODO: PATCH RO in VBIOS */
1955 } else if (evv_revision == 2) {
1965 data->ro_range_minimum = min;
1966 data->ro_range_maximum = max;
1968 /* TODO: PATCH RO in VBIOS here */
1974 * smu7_get_evv_voltages - Get Leakage VDDC based on leakage ID.
1976 * @hwmgr: the address of the powerplay hardware manager.
1979 static int smu7_get_evv_voltages(struct pp_hwmgr *hwmgr)
1981 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1984 uint16_t vddgfx = 0;
1987 struct phm_ppt_v1_information *table_info =
1988 (struct phm_ppt_v1_information *)hwmgr->pptable;
1989 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table = NULL;
1991 if (hwmgr->chip_id == CHIP_POLARIS10 ||
1992 hwmgr->chip_id == CHIP_POLARIS11 ||
1993 hwmgr->chip_id == CHIP_POLARIS12)
1994 smu7_calculate_ro_range(hwmgr);
1996 for (i = 0; i < SMU7_MAX_LEAKAGE_COUNT; i++) {
1997 vv_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i;
1999 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
2000 if ((hwmgr->pp_table_version == PP_TABLE_V1)
2001 && !phm_get_sclk_for_voltage_evv(hwmgr,
2002 table_info->vddgfx_lookup_table, vv_id, &sclk)) {
2003 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2004 PHM_PlatformCaps_ClockStretcher)) {
2005 sclk_table = table_info->vdd_dep_on_sclk;
2007 for (j = 1; j < sclk_table->count; j++) {
2008 if (sclk_table->entries[j].clk == sclk &&
2009 sclk_table->entries[j].cks_enable == 0) {
2015 if (0 == atomctrl_get_voltage_evv_on_sclk
2016 (hwmgr, VOLTAGE_TYPE_VDDGFX, sclk,
2018 /* need to make sure vddgfx is less than 2v or else, it could burn the ASIC. */
2019 PP_ASSERT_WITH_CODE((vddgfx < 2000 && vddgfx != 0), "Invalid VDDGFX value!", return -EINVAL);
2021 /* the voltage should not be zero nor equal to leakage ID */
2022 if (vddgfx != 0 && vddgfx != vv_id) {
2023 data->vddcgfx_leakage.actual_voltage[data->vddcgfx_leakage.count] = vddgfx;
2024 data->vddcgfx_leakage.leakage_id[data->vddcgfx_leakage.count] = vv_id;
2025 data->vddcgfx_leakage.count++;
2028 pr_info("Error retrieving EVV voltage value!\n");
2032 if ((hwmgr->pp_table_version == PP_TABLE_V0)
2033 || !phm_get_sclk_for_voltage_evv(hwmgr,
2034 table_info->vddc_lookup_table, vv_id, &sclk)) {
2035 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2036 PHM_PlatformCaps_ClockStretcher)) {
2037 if (table_info == NULL)
2039 sclk_table = table_info->vdd_dep_on_sclk;
2041 for (j = 1; j < sclk_table->count; j++) {
2042 if (sclk_table->entries[j].clk == sclk &&
2043 sclk_table->entries[j].cks_enable == 0) {
2050 if (phm_get_voltage_evv_on_sclk(hwmgr,
2052 sclk, vv_id, &vddc) == 0) {
2053 if (vddc >= 2000 || vddc == 0)
2056 pr_debug("failed to retrieving EVV voltage!\n");
2060 /* the voltage should not be zero nor equal to leakage ID */
2061 if (vddc != 0 && vddc != vv_id) {
2062 data->vddc_leakage.actual_voltage[data->vddc_leakage.count] = (uint16_t)(vddc);
2063 data->vddc_leakage.leakage_id[data->vddc_leakage.count] = vv_id;
2064 data->vddc_leakage.count++;
2074 * smu7_patch_ppt_v1_with_vdd_leakage - Change virtual leakage voltage to actual value.
2076 * @hwmgr: the address of the powerplay hardware manager.
2077 * @voltage: pointer to changing voltage
2078 * @leakage_table: pointer to leakage table
2080 static void smu7_patch_ppt_v1_with_vdd_leakage(struct pp_hwmgr *hwmgr,
2081 uint16_t *voltage, struct smu7_leakage_voltage *leakage_table)
2085 /* search for leakage voltage ID 0xff01 ~ 0xff08 */
2086 for (index = 0; index < leakage_table->count; index++) {
2087 /* if this voltage matches a leakage voltage ID */
2088 /* patch with actual leakage voltage */
2089 if (leakage_table->leakage_id[index] == *voltage) {
2090 *voltage = leakage_table->actual_voltage[index];
2095 if (*voltage > ATOM_VIRTUAL_VOLTAGE_ID0)
2096 pr_err("Voltage value looks like a Leakage ID but it's not patched \n");
2100 * smu7_patch_lookup_table_with_leakage - Patch voltage lookup table by EVV leakages.
2102 * @hwmgr: the address of the powerplay hardware manager.
2103 * @lookup_table: pointer to voltage lookup table
2104 * @leakage_table: pointer to leakage table
2107 static int smu7_patch_lookup_table_with_leakage(struct pp_hwmgr *hwmgr,
2108 phm_ppt_v1_voltage_lookup_table *lookup_table,
2109 struct smu7_leakage_voltage *leakage_table)
2113 for (i = 0; i < lookup_table->count; i++)
2114 smu7_patch_ppt_v1_with_vdd_leakage(hwmgr,
2115 &lookup_table->entries[i].us_vdd, leakage_table);
2120 static int smu7_patch_clock_voltage_limits_with_vddc_leakage(
2121 struct pp_hwmgr *hwmgr, struct smu7_leakage_voltage *leakage_table,
2124 struct phm_ppt_v1_information *table_info =
2125 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2126 smu7_patch_ppt_v1_with_vdd_leakage(hwmgr, (uint16_t *)vddc, leakage_table);
2127 hwmgr->dyn_state.max_clock_voltage_on_dc.vddc =
2128 table_info->max_clock_voltage_on_dc.vddc;
2132 static int smu7_patch_voltage_dependency_tables_with_lookup_table(
2133 struct pp_hwmgr *hwmgr)
2137 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2138 struct phm_ppt_v1_information *table_info =
2139 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2141 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
2142 table_info->vdd_dep_on_sclk;
2143 struct phm_ppt_v1_clock_voltage_dependency_table *mclk_table =
2144 table_info->vdd_dep_on_mclk;
2145 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
2146 table_info->mm_dep_table;
2148 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
2149 for (entry_id = 0; entry_id < sclk_table->count; ++entry_id) {
2150 voltage_id = sclk_table->entries[entry_id].vddInd;
2151 sclk_table->entries[entry_id].vddgfx =
2152 table_info->vddgfx_lookup_table->entries[voltage_id].us_vdd;
2155 for (entry_id = 0; entry_id < sclk_table->count; ++entry_id) {
2156 voltage_id = sclk_table->entries[entry_id].vddInd;
2157 sclk_table->entries[entry_id].vddc =
2158 table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
2162 for (entry_id = 0; entry_id < mclk_table->count; ++entry_id) {
2163 voltage_id = mclk_table->entries[entry_id].vddInd;
2164 mclk_table->entries[entry_id].vddc =
2165 table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
2168 for (entry_id = 0; entry_id < mm_table->count; ++entry_id) {
2169 voltage_id = mm_table->entries[entry_id].vddcInd;
2170 mm_table->entries[entry_id].vddc =
2171 table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
2178 static int phm_add_voltage(struct pp_hwmgr *hwmgr,
2179 phm_ppt_v1_voltage_lookup_table *look_up_table,
2180 phm_ppt_v1_voltage_lookup_record *record)
2184 PP_ASSERT_WITH_CODE((NULL != look_up_table),
2185 "Lookup Table empty.", return -EINVAL);
2186 PP_ASSERT_WITH_CODE((0 != look_up_table->count),
2187 "Lookup Table empty.", return -EINVAL);
2189 i = smum_get_mac_definition(hwmgr, SMU_MAX_LEVELS_VDDGFX);
2190 PP_ASSERT_WITH_CODE((i >= look_up_table->count),
2191 "Lookup Table is full.", return -EINVAL);
2193 /* This is to avoid entering duplicate calculated records. */
2194 for (i = 0; i < look_up_table->count; i++) {
2195 if (look_up_table->entries[i].us_vdd == record->us_vdd) {
2196 if (look_up_table->entries[i].us_calculated == 1)
2202 look_up_table->entries[i].us_calculated = 1;
2203 look_up_table->entries[i].us_vdd = record->us_vdd;
2204 look_up_table->entries[i].us_cac_low = record->us_cac_low;
2205 look_up_table->entries[i].us_cac_mid = record->us_cac_mid;
2206 look_up_table->entries[i].us_cac_high = record->us_cac_high;
2207 /* Only increment the count when we're appending, not replacing duplicate entry. */
2208 if (i == look_up_table->count)
2209 look_up_table->count++;
2215 static int smu7_calc_voltage_dependency_tables(struct pp_hwmgr *hwmgr)
2218 struct phm_ppt_v1_voltage_lookup_record v_record;
2219 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2220 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
2222 phm_ppt_v1_clock_voltage_dependency_table *sclk_table = pptable_info->vdd_dep_on_sclk;
2223 phm_ppt_v1_clock_voltage_dependency_table *mclk_table = pptable_info->vdd_dep_on_mclk;
2225 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
2226 for (entry_id = 0; entry_id < sclk_table->count; ++entry_id) {
2227 if (sclk_table->entries[entry_id].vdd_offset & (1 << 15))
2228 v_record.us_vdd = sclk_table->entries[entry_id].vddgfx +
2229 sclk_table->entries[entry_id].vdd_offset - 0xFFFF;
2231 v_record.us_vdd = sclk_table->entries[entry_id].vddgfx +
2232 sclk_table->entries[entry_id].vdd_offset;
2234 sclk_table->entries[entry_id].vddc =
2235 v_record.us_cac_low = v_record.us_cac_mid =
2236 v_record.us_cac_high = v_record.us_vdd;
2238 phm_add_voltage(hwmgr, pptable_info->vddc_lookup_table, &v_record);
2241 for (entry_id = 0; entry_id < mclk_table->count; ++entry_id) {
2242 if (mclk_table->entries[entry_id].vdd_offset & (1 << 15))
2243 v_record.us_vdd = mclk_table->entries[entry_id].vddc +
2244 mclk_table->entries[entry_id].vdd_offset - 0xFFFF;
2246 v_record.us_vdd = mclk_table->entries[entry_id].vddc +
2247 mclk_table->entries[entry_id].vdd_offset;
2249 mclk_table->entries[entry_id].vddgfx = v_record.us_cac_low =
2250 v_record.us_cac_mid = v_record.us_cac_high = v_record.us_vdd;
2251 phm_add_voltage(hwmgr, pptable_info->vddgfx_lookup_table, &v_record);
2257 static int smu7_calc_mm_voltage_dependency_table(struct pp_hwmgr *hwmgr)
2260 struct phm_ppt_v1_voltage_lookup_record v_record;
2261 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2262 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
2263 phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table = pptable_info->mm_dep_table;
2265 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
2266 for (entry_id = 0; entry_id < mm_table->count; entry_id++) {
2267 if (mm_table->entries[entry_id].vddgfx_offset & (1 << 15))
2268 v_record.us_vdd = mm_table->entries[entry_id].vddc +
2269 mm_table->entries[entry_id].vddgfx_offset - 0xFFFF;
2271 v_record.us_vdd = mm_table->entries[entry_id].vddc +
2272 mm_table->entries[entry_id].vddgfx_offset;
2274 /* Add the calculated VDDGFX to the VDDGFX lookup table */
2275 mm_table->entries[entry_id].vddgfx = v_record.us_cac_low =
2276 v_record.us_cac_mid = v_record.us_cac_high = v_record.us_vdd;
2277 phm_add_voltage(hwmgr, pptable_info->vddgfx_lookup_table, &v_record);
2283 static int smu7_sort_lookup_table(struct pp_hwmgr *hwmgr,
2284 struct phm_ppt_v1_voltage_lookup_table *lookup_table)
2286 uint32_t table_size, i, j;
2287 table_size = lookup_table->count;
2289 PP_ASSERT_WITH_CODE(0 != lookup_table->count,
2290 "Lookup table is empty", return -EINVAL);
2292 /* Sorting voltages */
2293 for (i = 0; i < table_size - 1; i++) {
2294 for (j = i + 1; j > 0; j--) {
2295 if (lookup_table->entries[j].us_vdd <
2296 lookup_table->entries[j - 1].us_vdd) {
2297 swap(lookup_table->entries[j - 1],
2298 lookup_table->entries[j]);
2306 static int smu7_complete_dependency_tables(struct pp_hwmgr *hwmgr)
2310 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2311 struct phm_ppt_v1_information *table_info =
2312 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2314 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
2315 tmp_result = smu7_patch_lookup_table_with_leakage(hwmgr,
2316 table_info->vddgfx_lookup_table, &(data->vddcgfx_leakage));
2317 if (tmp_result != 0)
2318 result = tmp_result;
2320 smu7_patch_ppt_v1_with_vdd_leakage(hwmgr,
2321 &table_info->max_clock_voltage_on_dc.vddgfx, &(data->vddcgfx_leakage));
2324 tmp_result = smu7_patch_lookup_table_with_leakage(hwmgr,
2325 table_info->vddc_lookup_table, &(data->vddc_leakage));
2327 result = tmp_result;
2329 tmp_result = smu7_patch_clock_voltage_limits_with_vddc_leakage(hwmgr,
2330 &(data->vddc_leakage), &table_info->max_clock_voltage_on_dc.vddc);
2332 result = tmp_result;
2335 tmp_result = smu7_patch_voltage_dependency_tables_with_lookup_table(hwmgr);
2337 result = tmp_result;
2339 tmp_result = smu7_calc_voltage_dependency_tables(hwmgr);
2341 result = tmp_result;
2343 tmp_result = smu7_calc_mm_voltage_dependency_table(hwmgr);
2345 result = tmp_result;
2347 tmp_result = smu7_sort_lookup_table(hwmgr, table_info->vddgfx_lookup_table);
2349 result = tmp_result;
2351 tmp_result = smu7_sort_lookup_table(hwmgr, table_info->vddc_lookup_table);
2353 result = tmp_result;
2358 static int smu7_find_highest_vddc(struct pp_hwmgr *hwmgr)
2360 struct phm_ppt_v1_information *table_info =
2361 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2362 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_sclk_vdd_table =
2363 table_info->vdd_dep_on_sclk;
2364 struct phm_ppt_v1_voltage_lookup_table *lookup_table =
2365 table_info->vddc_lookup_table;
2366 uint16_t highest_voltage;
2369 highest_voltage = allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].vddc;
2371 for (i = 0; i < lookup_table->count; i++) {
2372 if (lookup_table->entries[i].us_vdd < ATOM_VIRTUAL_VOLTAGE_ID0 &&
2373 lookup_table->entries[i].us_vdd > highest_voltage)
2374 highest_voltage = lookup_table->entries[i].us_vdd;
2377 return highest_voltage;
2380 static int smu7_set_private_data_based_on_pptable_v1(struct pp_hwmgr *hwmgr)
2382 struct phm_ppt_v1_information *table_info =
2383 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2385 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_sclk_vdd_table =
2386 table_info->vdd_dep_on_sclk;
2387 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_mclk_vdd_table =
2388 table_info->vdd_dep_on_mclk;
2390 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table != NULL,
2391 "VDD dependency on SCLK table is missing.",
2393 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table->count >= 1,
2394 "VDD dependency on SCLK table has to have is missing.",
2397 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table != NULL,
2398 "VDD dependency on MCLK table is missing",
2400 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table->count >= 1,
2401 "VDD dependency on MCLK table has to have is missing.",
2404 table_info->max_clock_voltage_on_ac.sclk =
2405 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].clk;
2406 table_info->max_clock_voltage_on_ac.mclk =
2407 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].clk;
2408 if (hwmgr->chip_id >= CHIP_POLARIS10 && hwmgr->chip_id <= CHIP_VEGAM)
2409 table_info->max_clock_voltage_on_ac.vddc =
2410 smu7_find_highest_vddc(hwmgr);
2412 table_info->max_clock_voltage_on_ac.vddc =
2413 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].vddc;
2414 table_info->max_clock_voltage_on_ac.vddci =
2415 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].vddci;
2417 hwmgr->dyn_state.max_clock_voltage_on_ac.sclk = table_info->max_clock_voltage_on_ac.sclk;
2418 hwmgr->dyn_state.max_clock_voltage_on_ac.mclk = table_info->max_clock_voltage_on_ac.mclk;
2419 hwmgr->dyn_state.max_clock_voltage_on_ac.vddc = table_info->max_clock_voltage_on_ac.vddc;
2420 hwmgr->dyn_state.max_clock_voltage_on_ac.vddci = table_info->max_clock_voltage_on_ac.vddci;
2425 static int smu7_patch_voltage_workaround(struct pp_hwmgr *hwmgr)
2427 struct phm_ppt_v1_information *table_info =
2428 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2429 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table;
2430 struct phm_ppt_v1_voltage_lookup_table *lookup_table;
2432 uint32_t hw_revision, sub_vendor_id, sub_sys_id;
2433 struct amdgpu_device *adev = hwmgr->adev;
2435 if (table_info != NULL) {
2436 dep_mclk_table = table_info->vdd_dep_on_mclk;
2437 lookup_table = table_info->vddc_lookup_table;
2441 hw_revision = adev->pdev->revision;
2442 sub_sys_id = adev->pdev->subsystem_device;
2443 sub_vendor_id = adev->pdev->subsystem_vendor;
2445 if (adev->pdev->device == 0x67DF && hw_revision == 0xC7 &&
2446 ((sub_sys_id == 0xb37 && sub_vendor_id == 0x1002) ||
2447 (sub_sys_id == 0x4a8 && sub_vendor_id == 0x1043) ||
2448 (sub_sys_id == 0x9480 && sub_vendor_id == 0x1682))) {
2450 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device,
2456 if (lookup_table->entries[dep_mclk_table->entries[dep_mclk_table->count-1].vddInd].us_vdd >= 1000)
2459 for (i = 0; i < lookup_table->count; i++) {
2460 if (lookup_table->entries[i].us_vdd < 0xff01 && lookup_table->entries[i].us_vdd >= 1000) {
2461 dep_mclk_table->entries[dep_mclk_table->count-1].vddInd = (uint8_t) i;
2469 static int smu7_thermal_parameter_init(struct pp_hwmgr *hwmgr)
2471 struct pp_atomctrl_gpio_pin_assignment gpio_pin_assignment;
2473 struct phm_ppt_v1_information *table_info =
2474 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2477 if (atomctrl_get_pp_assign_pin(hwmgr, VDDC_PCC_GPIO_PINID, &gpio_pin_assignment)) {
2478 temp_reg = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCNB_PWRMGT_CNTL);
2479 switch (gpio_pin_assignment.uc_gpio_pin_bit_shift) {
2481 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x1);
2484 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x2);
2487 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW, 0x1);
2490 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, FORCE_NB_PS1, 0x1);
2493 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, DPM_ENABLED, 0x1);
2498 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCNB_PWRMGT_CNTL, temp_reg);
2501 if (table_info == NULL)
2504 if (table_info->cac_dtp_table->usDefaultTargetOperatingTemp != 0 &&
2505 hwmgr->thermal_controller.advanceFanControlParameters.ucFanControlMode) {
2506 hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMMinLimit =
2507 (uint16_t)hwmgr->thermal_controller.advanceFanControlParameters.ucMinimumPWMLimit;
2509 hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMMaxLimit =
2510 (uint16_t)hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanPWM;
2512 hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMStep = 1;
2514 hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMMaxLimit = 100;
2516 hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMMinLimit =
2517 (uint16_t)hwmgr->thermal_controller.advanceFanControlParameters.ucMinimumPWMLimit;
2519 hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMStep = 1;
2521 table_info->cac_dtp_table->usDefaultTargetOperatingTemp = (table_info->cac_dtp_table->usDefaultTargetOperatingTemp >= 50) ?
2522 (table_info->cac_dtp_table->usDefaultTargetOperatingTemp - 50) : 0;
2524 table_info->cac_dtp_table->usOperatingTempMaxLimit = table_info->cac_dtp_table->usDefaultTargetOperatingTemp;
2525 table_info->cac_dtp_table->usOperatingTempStep = 1;
2526 table_info->cac_dtp_table->usOperatingTempHyst = 1;
2528 hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanPWM =
2529 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanPWM;
2531 hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanRPM =
2532 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanRPM;
2534 hwmgr->dyn_state.cac_dtp_table->usOperatingTempMinLimit =
2535 table_info->cac_dtp_table->usOperatingTempMinLimit;
2537 hwmgr->dyn_state.cac_dtp_table->usOperatingTempMaxLimit =
2538 table_info->cac_dtp_table->usOperatingTempMaxLimit;
2540 hwmgr->dyn_state.cac_dtp_table->usDefaultTargetOperatingTemp =
2541 table_info->cac_dtp_table->usDefaultTargetOperatingTemp;
2543 hwmgr->dyn_state.cac_dtp_table->usOperatingTempStep =
2544 table_info->cac_dtp_table->usOperatingTempStep;
2546 hwmgr->dyn_state.cac_dtp_table->usTargetOperatingTemp =
2547 table_info->cac_dtp_table->usTargetOperatingTemp;
2548 if (hwmgr->feature_mask & PP_OD_FUZZY_FAN_CONTROL_MASK)
2549 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2550 PHM_PlatformCaps_ODFuzzyFanControlSupport);
2557 * smu7_patch_ppt_v0_with_vdd_leakage - Change virtual leakage voltage to actual value.
2559 * @hwmgr: the address of the powerplay hardware manager.
2560 * @voltage: pointer to changing voltage
2561 * @leakage_table: pointer to leakage table
2563 static void smu7_patch_ppt_v0_with_vdd_leakage(struct pp_hwmgr *hwmgr,
2564 uint32_t *voltage, struct smu7_leakage_voltage *leakage_table)
2568 /* search for leakage voltage ID 0xff01 ~ 0xff08 */
2569 for (index = 0; index < leakage_table->count; index++) {
2570 /* if this voltage matches a leakage voltage ID */
2571 /* patch with actual leakage voltage */
2572 if (leakage_table->leakage_id[index] == *voltage) {
2573 *voltage = leakage_table->actual_voltage[index];
2578 if (*voltage > ATOM_VIRTUAL_VOLTAGE_ID0)
2579 pr_err("Voltage value looks like a Leakage ID but it's not patched \n");
2583 static int smu7_patch_vddc(struct pp_hwmgr *hwmgr,
2584 struct phm_clock_voltage_dependency_table *tab)
2587 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2590 for (i = 0; i < tab->count; i++)
2591 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2592 &data->vddc_leakage);
2597 static int smu7_patch_vddci(struct pp_hwmgr *hwmgr,
2598 struct phm_clock_voltage_dependency_table *tab)
2601 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2604 for (i = 0; i < tab->count; i++)
2605 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2606 &data->vddci_leakage);
2611 static int smu7_patch_vce_vddc(struct pp_hwmgr *hwmgr,
2612 struct phm_vce_clock_voltage_dependency_table *tab)
2615 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2618 for (i = 0; i < tab->count; i++)
2619 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2620 &data->vddc_leakage);
2626 static int smu7_patch_uvd_vddc(struct pp_hwmgr *hwmgr,
2627 struct phm_uvd_clock_voltage_dependency_table *tab)
2630 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2633 for (i = 0; i < tab->count; i++)
2634 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2635 &data->vddc_leakage);
2640 static int smu7_patch_vddc_shed_limit(struct pp_hwmgr *hwmgr,
2641 struct phm_phase_shedding_limits_table *tab)
2644 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2647 for (i = 0; i < tab->count; i++)
2648 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].Voltage,
2649 &data->vddc_leakage);
2654 static int smu7_patch_samu_vddc(struct pp_hwmgr *hwmgr,
2655 struct phm_samu_clock_voltage_dependency_table *tab)
2658 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2661 for (i = 0; i < tab->count; i++)
2662 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2663 &data->vddc_leakage);
2668 static int smu7_patch_acp_vddc(struct pp_hwmgr *hwmgr,
2669 struct phm_acp_clock_voltage_dependency_table *tab)
2672 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2675 for (i = 0; i < tab->count; i++)
2676 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2677 &data->vddc_leakage);
2682 static int smu7_patch_limits_vddc(struct pp_hwmgr *hwmgr,
2683 struct phm_clock_and_voltage_limits *tab)
2685 uint32_t vddc, vddci;
2686 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2690 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &vddc,
2691 &data->vddc_leakage);
2694 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &vddci,
2695 &data->vddci_leakage);
2702 static int smu7_patch_cac_vddc(struct pp_hwmgr *hwmgr, struct phm_cac_leakage_table *tab)
2706 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2709 for (i = 0; i < tab->count; i++) {
2710 vddc = (uint32_t)(tab->entries[i].Vddc);
2711 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &vddc, &data->vddc_leakage);
2712 tab->entries[i].Vddc = (uint16_t)vddc;
2719 static int smu7_patch_dependency_tables_with_leakage(struct pp_hwmgr *hwmgr)
2723 tmp = smu7_patch_vddc(hwmgr, hwmgr->dyn_state.vddc_dependency_on_sclk);
2727 tmp = smu7_patch_vddc(hwmgr, hwmgr->dyn_state.vddc_dependency_on_mclk);
2731 tmp = smu7_patch_vddc(hwmgr, hwmgr->dyn_state.vddc_dep_on_dal_pwrl);
2735 tmp = smu7_patch_vddci(hwmgr, hwmgr->dyn_state.vddci_dependency_on_mclk);
2739 tmp = smu7_patch_vce_vddc(hwmgr, hwmgr->dyn_state.vce_clock_voltage_dependency_table);
2743 tmp = smu7_patch_uvd_vddc(hwmgr, hwmgr->dyn_state.uvd_clock_voltage_dependency_table);
2747 tmp = smu7_patch_samu_vddc(hwmgr, hwmgr->dyn_state.samu_clock_voltage_dependency_table);
2751 tmp = smu7_patch_acp_vddc(hwmgr, hwmgr->dyn_state.acp_clock_voltage_dependency_table);
2755 tmp = smu7_patch_vddc_shed_limit(hwmgr, hwmgr->dyn_state.vddc_phase_shed_limits_table);
2759 tmp = smu7_patch_limits_vddc(hwmgr, &hwmgr->dyn_state.max_clock_voltage_on_ac);
2763 tmp = smu7_patch_limits_vddc(hwmgr, &hwmgr->dyn_state.max_clock_voltage_on_dc);
2767 tmp = smu7_patch_cac_vddc(hwmgr, hwmgr->dyn_state.cac_leakage_table);
2775 static int smu7_set_private_data_based_on_pptable_v0(struct pp_hwmgr *hwmgr)
2777 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2779 struct phm_clock_voltage_dependency_table *allowed_sclk_vddc_table = hwmgr->dyn_state.vddc_dependency_on_sclk;
2780 struct phm_clock_voltage_dependency_table *allowed_mclk_vddc_table = hwmgr->dyn_state.vddc_dependency_on_mclk;
2781 struct phm_clock_voltage_dependency_table *allowed_mclk_vddci_table = hwmgr->dyn_state.vddci_dependency_on_mclk;
2783 PP_ASSERT_WITH_CODE(allowed_sclk_vddc_table != NULL,
2784 "VDDC dependency on SCLK table is missing. This table is mandatory",
2786 PP_ASSERT_WITH_CODE(allowed_sclk_vddc_table->count >= 1,
2787 "VDDC dependency on SCLK table has to have is missing. This table is mandatory",
2790 PP_ASSERT_WITH_CODE(allowed_mclk_vddc_table != NULL,
2791 "VDDC dependency on MCLK table is missing. This table is mandatory",
2793 PP_ASSERT_WITH_CODE(allowed_mclk_vddc_table->count >= 1,
2794 "VDD dependency on MCLK table has to have is missing. This table is mandatory",
2797 data->min_vddc_in_pptable = (uint16_t)allowed_sclk_vddc_table->entries[0].v;
2798 data->max_vddc_in_pptable = (uint16_t)allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].v;
2800 hwmgr->dyn_state.max_clock_voltage_on_ac.sclk =
2801 allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].clk;
2802 hwmgr->dyn_state.max_clock_voltage_on_ac.mclk =
2803 allowed_mclk_vddc_table->entries[allowed_mclk_vddc_table->count - 1].clk;
2804 hwmgr->dyn_state.max_clock_voltage_on_ac.vddc =
2805 allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].v;
2807 if (allowed_mclk_vddci_table != NULL && allowed_mclk_vddci_table->count >= 1) {
2808 data->min_vddci_in_pptable = (uint16_t)allowed_mclk_vddci_table->entries[0].v;
2809 data->max_vddci_in_pptable = (uint16_t)allowed_mclk_vddci_table->entries[allowed_mclk_vddci_table->count - 1].v;
2812 if (hwmgr->dyn_state.vddci_dependency_on_mclk != NULL && hwmgr->dyn_state.vddci_dependency_on_mclk->count >= 1)
2813 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;
2818 static int smu7_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)
2820 kfree(hwmgr->dyn_state.vddc_dep_on_dal_pwrl);
2821 hwmgr->dyn_state.vddc_dep_on_dal_pwrl = NULL;
2822 kfree(hwmgr->backend);
2823 hwmgr->backend = NULL;
2828 static int smu7_get_elb_voltages(struct pp_hwmgr *hwmgr)
2830 uint16_t virtual_voltage_id, vddc, vddci, efuse_voltage_id;
2831 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2834 if (atomctrl_get_leakage_id_from_efuse(hwmgr, &efuse_voltage_id) == 0) {
2835 for (i = 0; i < SMU7_MAX_LEAKAGE_COUNT; i++) {
2836 virtual_voltage_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i;
2837 if (atomctrl_get_leakage_vddc_base_on_leakage(hwmgr, &vddc, &vddci,
2839 efuse_voltage_id) == 0) {
2840 if (vddc != 0 && vddc != virtual_voltage_id) {
2841 data->vddc_leakage.actual_voltage[data->vddc_leakage.count] = vddc;
2842 data->vddc_leakage.leakage_id[data->vddc_leakage.count] = virtual_voltage_id;
2843 data->vddc_leakage.count++;
2845 if (vddci != 0 && vddci != virtual_voltage_id) {
2846 data->vddci_leakage.actual_voltage[data->vddci_leakage.count] = vddci;
2847 data->vddci_leakage.leakage_id[data->vddci_leakage.count] = virtual_voltage_id;
2848 data->vddci_leakage.count++;
2856 #define LEAKAGE_ID_MSB 463
2857 #define LEAKAGE_ID_LSB 454
2859 static int smu7_update_edc_leakage_table(struct pp_hwmgr *hwmgr)
2861 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2866 if (data->disable_edc_leakage_controller)
2869 ret = atomctrl_get_edc_hilo_leakage_offset_table(hwmgr,
2870 &data->edc_hilo_leakage_offset_from_vbios);
2874 if (data->edc_hilo_leakage_offset_from_vbios.usEdcDidtLoDpm7TableOffset &&
2875 data->edc_hilo_leakage_offset_from_vbios.usEdcDidtHiDpm7TableOffset) {
2876 atomctrl_read_efuse(hwmgr, LEAKAGE_ID_LSB, LEAKAGE_ID_MSB, &efuse);
2877 if (efuse < data->edc_hilo_leakage_offset_from_vbios.usHiLoLeakageThreshold)
2878 offset = data->edc_hilo_leakage_offset_from_vbios.usEdcDidtLoDpm7TableOffset;
2880 offset = data->edc_hilo_leakage_offset_from_vbios.usEdcDidtHiDpm7TableOffset;
2882 ret = atomctrl_get_edc_leakage_table(hwmgr,
2883 &data->edc_leakage_table,
2892 static int smu7_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
2894 struct smu7_hwmgr *data;
2897 data = kzalloc(sizeof(struct smu7_hwmgr), GFP_KERNEL);
2901 hwmgr->backend = data;
2902 smu7_patch_voltage_workaround(hwmgr);
2903 smu7_init_dpm_defaults(hwmgr);
2905 /* Get leakage voltage based on leakage ID. */
2906 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2907 PHM_PlatformCaps_EVV)) {
2908 result = smu7_get_evv_voltages(hwmgr);
2910 pr_info("Get EVV Voltage Failed. Abort Driver loading!\n");
2914 smu7_get_elb_voltages(hwmgr);
2917 if (hwmgr->pp_table_version == PP_TABLE_V1) {
2918 smu7_complete_dependency_tables(hwmgr);
2919 smu7_set_private_data_based_on_pptable_v1(hwmgr);
2920 } else if (hwmgr->pp_table_version == PP_TABLE_V0) {
2921 smu7_patch_dependency_tables_with_leakage(hwmgr);
2922 smu7_set_private_data_based_on_pptable_v0(hwmgr);
2925 /* Initalize Dynamic State Adjustment Rule Settings */
2926 result = phm_initializa_dynamic_state_adjustment_rule_settings(hwmgr);
2929 struct amdgpu_device *adev = hwmgr->adev;
2931 data->is_tlu_enabled = false;
2933 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels =
2934 SMU7_MAX_HARDWARE_POWERLEVELS;
2935 hwmgr->platform_descriptor.hardwarePerformanceLevels = 2;
2936 hwmgr->platform_descriptor.minimumClocksReductionPercentage = 50;
2938 data->pcie_gen_cap = adev->pm.pcie_gen_mask;
2939 if (data->pcie_gen_cap & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)
2940 data->pcie_spc_cap = 20;
2942 data->pcie_spc_cap = 16;
2943 data->pcie_lane_cap = adev->pm.pcie_mlw_mask;
2945 hwmgr->platform_descriptor.vbiosInterruptId = 0x20000400; /* IRQ_SOURCE1_SW_INT */
2946 /* The true clock step depends on the frequency, typically 4.5 or 9 MHz. Here we use 5. */
2947 hwmgr->platform_descriptor.clockStep.engineClock = 500;
2948 hwmgr->platform_descriptor.clockStep.memoryClock = 500;
2949 smu7_thermal_parameter_init(hwmgr);
2951 /* Ignore return value in here, we are cleaning up a mess. */
2952 smu7_hwmgr_backend_fini(hwmgr);
2955 result = smu7_update_edc_leakage_table(hwmgr);
2962 static int smu7_force_dpm_highest(struct pp_hwmgr *hwmgr)
2964 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2965 uint32_t level, tmp;
2967 if (!data->pcie_dpm_key_disabled) {
2968 if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) {
2970 tmp = data->dpm_level_enable_mask.pcie_dpm_enable_mask;
2975 smum_send_msg_to_smc_with_parameter(hwmgr,
2976 PPSMC_MSG_PCIeDPM_ForceLevel, level,
2981 if (!data->sclk_dpm_key_disabled) {
2982 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
2984 tmp = data->dpm_level_enable_mask.sclk_dpm_enable_mask;
2989 smum_send_msg_to_smc_with_parameter(hwmgr,
2990 PPSMC_MSG_SCLKDPM_SetEnabledMask,
2996 if (!data->mclk_dpm_key_disabled) {
2997 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
2999 tmp = data->dpm_level_enable_mask.mclk_dpm_enable_mask;
3004 smum_send_msg_to_smc_with_parameter(hwmgr,
3005 PPSMC_MSG_MCLKDPM_SetEnabledMask,
3014 static int smu7_upload_dpm_level_enable_mask(struct pp_hwmgr *hwmgr)
3016 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3018 if (hwmgr->pp_table_version == PP_TABLE_V1)
3019 phm_apply_dal_min_voltage_request(hwmgr);
3020 /* TO DO for v0 iceland and Ci*/
3022 if (!data->sclk_dpm_key_disabled) {
3023 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask)
3024 smum_send_msg_to_smc_with_parameter(hwmgr,
3025 PPSMC_MSG_SCLKDPM_SetEnabledMask,
3026 data->dpm_level_enable_mask.sclk_dpm_enable_mask,
3030 if (!data->mclk_dpm_key_disabled) {
3031 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask)
3032 smum_send_msg_to_smc_with_parameter(hwmgr,
3033 PPSMC_MSG_MCLKDPM_SetEnabledMask,
3034 data->dpm_level_enable_mask.mclk_dpm_enable_mask,
3041 static int smu7_unforce_dpm_levels(struct pp_hwmgr *hwmgr)
3043 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3045 if (!smum_is_dpm_running(hwmgr))
3048 if (!data->pcie_dpm_key_disabled) {
3049 smum_send_msg_to_smc(hwmgr,
3050 PPSMC_MSG_PCIeDPM_UnForceLevel,
3054 return smu7_upload_dpm_level_enable_mask(hwmgr);
3057 static int smu7_force_dpm_lowest(struct pp_hwmgr *hwmgr)
3059 struct smu7_hwmgr *data =
3060 (struct smu7_hwmgr *)(hwmgr->backend);
3063 if (!data->sclk_dpm_key_disabled)
3064 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
3065 level = phm_get_lowest_enabled_level(hwmgr,
3066 data->dpm_level_enable_mask.sclk_dpm_enable_mask);
3067 smum_send_msg_to_smc_with_parameter(hwmgr,
3068 PPSMC_MSG_SCLKDPM_SetEnabledMask,
3074 if (!data->mclk_dpm_key_disabled) {
3075 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
3076 level = phm_get_lowest_enabled_level(hwmgr,
3077 data->dpm_level_enable_mask.mclk_dpm_enable_mask);
3078 smum_send_msg_to_smc_with_parameter(hwmgr,
3079 PPSMC_MSG_MCLKDPM_SetEnabledMask,
3085 if (!data->pcie_dpm_key_disabled) {
3086 if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) {
3087 level = phm_get_lowest_enabled_level(hwmgr,
3088 data->dpm_level_enable_mask.pcie_dpm_enable_mask);
3089 smum_send_msg_to_smc_with_parameter(hwmgr,
3090 PPSMC_MSG_PCIeDPM_ForceLevel,
3099 static int smu7_get_profiling_clk(struct pp_hwmgr *hwmgr, enum amd_dpm_forced_level level,
3100 uint32_t *sclk_mask, uint32_t *mclk_mask, uint32_t *pcie_mask)
3102 uint32_t percentage;
3103 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3104 struct smu7_dpm_table *golden_dpm_table = &data->golden_dpm_table;
3109 if (golden_dpm_table->mclk_table.count < 1)
3112 percentage = 100 * golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count - 1].value /
3113 golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count - 1].value;
3115 if (golden_dpm_table->mclk_table.count == 1) {
3117 tmp_mclk = golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count - 1].value;
3118 *mclk_mask = golden_dpm_table->mclk_table.count - 1;
3120 tmp_mclk = golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count - 2].value;
3121 *mclk_mask = golden_dpm_table->mclk_table.count - 2;
3124 tmp_sclk = tmp_mclk * percentage / 100;
3126 if (hwmgr->pp_table_version == PP_TABLE_V0) {
3127 for (count = hwmgr->dyn_state.vddc_dependency_on_sclk->count-1;
3128 count >= 0; count--) {
3129 if (tmp_sclk >= hwmgr->dyn_state.vddc_dependency_on_sclk->entries[count].clk) {
3130 tmp_sclk = hwmgr->dyn_state.vddc_dependency_on_sclk->entries[count].clk;
3135 if (count < 0 || level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) {
3137 tmp_sclk = hwmgr->dyn_state.vddc_dependency_on_sclk->entries[0].clk;
3140 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
3141 *sclk_mask = hwmgr->dyn_state.vddc_dependency_on_sclk->count-1;
3142 } else if (hwmgr->pp_table_version == PP_TABLE_V1) {
3143 struct phm_ppt_v1_information *table_info =
3144 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3146 for (count = table_info->vdd_dep_on_sclk->count-1; count >= 0; count--) {
3147 if (tmp_sclk >= table_info->vdd_dep_on_sclk->entries[count].clk) {
3148 tmp_sclk = table_info->vdd_dep_on_sclk->entries[count].clk;
3153 if (count < 0 || level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) {
3155 tmp_sclk = table_info->vdd_dep_on_sclk->entries[0].clk;
3158 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
3159 *sclk_mask = table_info->vdd_dep_on_sclk->count - 1;
3162 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK)
3164 else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
3165 *mclk_mask = golden_dpm_table->mclk_table.count - 1;
3167 *pcie_mask = data->dpm_table.pcie_speed_table.count - 1;
3168 hwmgr->pstate_sclk = tmp_sclk;
3169 hwmgr->pstate_mclk = tmp_mclk;
3174 static int smu7_force_dpm_level(struct pp_hwmgr *hwmgr,
3175 enum amd_dpm_forced_level level)
3178 uint32_t sclk_mask = 0;
3179 uint32_t mclk_mask = 0;
3180 uint32_t pcie_mask = 0;
3182 if (hwmgr->pstate_sclk == 0)
3183 smu7_get_profiling_clk(hwmgr, level, &sclk_mask, &mclk_mask, &pcie_mask);
3186 case AMD_DPM_FORCED_LEVEL_HIGH:
3187 ret = smu7_force_dpm_highest(hwmgr);
3189 case AMD_DPM_FORCED_LEVEL_LOW:
3190 ret = smu7_force_dpm_lowest(hwmgr);
3192 case AMD_DPM_FORCED_LEVEL_AUTO:
3193 ret = smu7_unforce_dpm_levels(hwmgr);
3195 case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:
3196 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
3197 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:
3198 case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:
3199 ret = smu7_get_profiling_clk(hwmgr, level, &sclk_mask, &mclk_mask, &pcie_mask);
3202 smu7_force_clock_level(hwmgr, PP_SCLK, 1<<sclk_mask);
3203 smu7_force_clock_level(hwmgr, PP_MCLK, 1<<mclk_mask);
3204 smu7_force_clock_level(hwmgr, PP_PCIE, 1<<pcie_mask);
3206 case AMD_DPM_FORCED_LEVEL_MANUAL:
3207 case AMD_DPM_FORCED_LEVEL_PROFILE_EXIT:
3213 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK && hwmgr->dpm_level != AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
3214 smu7_fan_ctrl_set_fan_speed_percent(hwmgr, 100);
3215 else if (level != AMD_DPM_FORCED_LEVEL_PROFILE_PEAK && hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
3216 smu7_fan_ctrl_reset_fan_speed_to_default(hwmgr);
3221 static int smu7_get_power_state_size(struct pp_hwmgr *hwmgr)
3223 return sizeof(struct smu7_power_state);
3226 static int smu7_vblank_too_short(struct pp_hwmgr *hwmgr,
3227 uint32_t vblank_time_us)
3229 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3230 uint32_t switch_limit_us;
3232 switch (hwmgr->chip_id) {
3233 case CHIP_POLARIS10:
3234 case CHIP_POLARIS11:
3235 case CHIP_POLARIS12:
3236 if (hwmgr->is_kicker || (hwmgr->chip_id == CHIP_POLARIS12))
3237 switch_limit_us = data->is_memory_gddr5 ? 450 : 150;
3239 switch_limit_us = data->is_memory_gddr5 ? 200 : 150;
3242 switch_limit_us = 30;
3245 switch_limit_us = data->is_memory_gddr5 ? 450 : 150;
3249 if (vblank_time_us < switch_limit_us)
3255 static int smu7_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
3256 struct pp_power_state *request_ps,
3257 const struct pp_power_state *current_ps)
3259 struct amdgpu_device *adev = hwmgr->adev;
3260 struct smu7_power_state *smu7_ps =
3261 cast_phw_smu7_power_state(&request_ps->hardware);
3264 struct PP_Clocks minimum_clocks = {0};
3265 bool disable_mclk_switching;
3266 bool disable_mclk_switching_for_frame_lock;
3267 bool disable_mclk_switching_for_display;
3268 const struct phm_clock_and_voltage_limits *max_limits;
3270 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3271 struct phm_ppt_v1_information *table_info =
3272 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3274 int32_t stable_pstate_sclk = 0, stable_pstate_mclk = 0;
3276 bool latency_allowed = false;
3278 data->battery_state = (PP_StateUILabel_Battery ==
3279 request_ps->classification.ui_label);
3280 data->mclk_ignore_signal = false;
3282 PP_ASSERT_WITH_CODE(smu7_ps->performance_level_count == 2,
3283 "VI should always have 2 performance levels",
3286 max_limits = adev->pm.ac_power ?
3287 &(hwmgr->dyn_state.max_clock_voltage_on_ac) :
3288 &(hwmgr->dyn_state.max_clock_voltage_on_dc);
3290 /* Cap clock DPM tables at DC MAX if it is in DC. */
3291 if (!adev->pm.ac_power) {
3292 for (i = 0; i < smu7_ps->performance_level_count; i++) {
3293 if (smu7_ps->performance_levels[i].memory_clock > max_limits->mclk)
3294 smu7_ps->performance_levels[i].memory_clock = max_limits->mclk;
3295 if (smu7_ps->performance_levels[i].engine_clock > max_limits->sclk)
3296 smu7_ps->performance_levels[i].engine_clock = max_limits->sclk;
3300 minimum_clocks.engineClock = hwmgr->display_config->min_core_set_clock;
3301 minimum_clocks.memoryClock = hwmgr->display_config->min_mem_set_clock;
3303 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3304 PHM_PlatformCaps_StablePState)) {
3305 max_limits = &(hwmgr->dyn_state.max_clock_voltage_on_ac);
3306 stable_pstate_sclk = (max_limits->sclk * 75) / 100;
3308 for (count = table_info->vdd_dep_on_sclk->count - 1;
3309 count >= 0; count--) {
3310 if (stable_pstate_sclk >=
3311 table_info->vdd_dep_on_sclk->entries[count].clk) {
3312 stable_pstate_sclk =
3313 table_info->vdd_dep_on_sclk->entries[count].clk;
3319 stable_pstate_sclk = table_info->vdd_dep_on_sclk->entries[0].clk;
3321 stable_pstate_mclk = max_limits->mclk;
3323 minimum_clocks.engineClock = stable_pstate_sclk;
3324 minimum_clocks.memoryClock = stable_pstate_mclk;
3327 disable_mclk_switching_for_frame_lock = phm_cap_enabled(
3328 hwmgr->platform_descriptor.platformCaps,
3329 PHM_PlatformCaps_DisableMclkSwitchingForFrameLock);
3331 disable_mclk_switching_for_display = ((1 < hwmgr->display_config->num_display) &&
3332 !hwmgr->display_config->multi_monitor_in_sync) ||
3333 (hwmgr->display_config->num_display &&
3334 smu7_vblank_too_short(hwmgr, hwmgr->display_config->min_vblank_time));
3336 disable_mclk_switching = disable_mclk_switching_for_frame_lock ||
3337 disable_mclk_switching_for_display;
3339 if (hwmgr->display_config->num_display == 0) {
3340 if (hwmgr->chip_id >= CHIP_POLARIS10 && hwmgr->chip_id <= CHIP_VEGAM)
3341 data->mclk_ignore_signal = true;
3343 disable_mclk_switching = false;
3346 sclk = smu7_ps->performance_levels[0].engine_clock;
3347 mclk = smu7_ps->performance_levels[0].memory_clock;
3349 if (disable_mclk_switching &&
3350 (!(hwmgr->chip_id >= CHIP_POLARIS10 &&
3351 hwmgr->chip_id <= CHIP_VEGAM)))
3352 mclk = smu7_ps->performance_levels
3353 [smu7_ps->performance_level_count - 1].memory_clock;
3355 if (sclk < minimum_clocks.engineClock)
3356 sclk = (minimum_clocks.engineClock > max_limits->sclk) ?
3357 max_limits->sclk : minimum_clocks.engineClock;
3359 if (mclk < minimum_clocks.memoryClock)
3360 mclk = (minimum_clocks.memoryClock > max_limits->mclk) ?
3361 max_limits->mclk : minimum_clocks.memoryClock;
3363 smu7_ps->performance_levels[0].engine_clock = sclk;
3364 smu7_ps->performance_levels[0].memory_clock = mclk;
3366 smu7_ps->performance_levels[1].engine_clock =
3367 (smu7_ps->performance_levels[1].engine_clock >=
3368 smu7_ps->performance_levels[0].engine_clock) ?
3369 smu7_ps->performance_levels[1].engine_clock :
3370 smu7_ps->performance_levels[0].engine_clock;
3372 if (disable_mclk_switching) {
3373 if (mclk < smu7_ps->performance_levels[1].memory_clock)
3374 mclk = smu7_ps->performance_levels[1].memory_clock;
3376 if (hwmgr->chip_id >= CHIP_POLARIS10 && hwmgr->chip_id <= CHIP_VEGAM) {
3377 if (disable_mclk_switching_for_display) {
3378 /* Find the lowest MCLK frequency that is within
3379 * the tolerable latency defined in DAL
3381 latency = hwmgr->display_config->dce_tolerable_mclk_in_active_latency;
3382 for (i = 0; i < data->mclk_latency_table.count; i++) {
3383 if (data->mclk_latency_table.entries[i].latency <= latency) {
3384 latency_allowed = true;
3386 if ((data->mclk_latency_table.entries[i].frequency >=
3387 smu7_ps->performance_levels[0].memory_clock) &&
3388 (data->mclk_latency_table.entries[i].frequency <=
3389 smu7_ps->performance_levels[1].memory_clock)) {
3390 mclk = data->mclk_latency_table.entries[i].frequency;
3395 if ((i >= data->mclk_latency_table.count - 1) && !latency_allowed) {
3396 data->mclk_ignore_signal = true;
3398 data->mclk_ignore_signal = false;
3402 if (disable_mclk_switching_for_frame_lock)
3403 mclk = smu7_ps->performance_levels[1].memory_clock;
3406 smu7_ps->performance_levels[0].memory_clock = mclk;
3408 if (!(hwmgr->chip_id >= CHIP_POLARIS10 &&
3409 hwmgr->chip_id <= CHIP_VEGAM))
3410 smu7_ps->performance_levels[1].memory_clock = mclk;
3412 if (smu7_ps->performance_levels[1].memory_clock <
3413 smu7_ps->performance_levels[0].memory_clock)
3414 smu7_ps->performance_levels[1].memory_clock =
3415 smu7_ps->performance_levels[0].memory_clock;
3418 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3419 PHM_PlatformCaps_StablePState)) {
3420 for (i = 0; i < smu7_ps->performance_level_count; i++) {
3421 smu7_ps->performance_levels[i].engine_clock = stable_pstate_sclk;
3422 smu7_ps->performance_levels[i].memory_clock = stable_pstate_mclk;
3423 smu7_ps->performance_levels[i].pcie_gen = data->pcie_gen_performance.max;
3424 smu7_ps->performance_levels[i].pcie_lane = data->pcie_gen_performance.max;
3431 static uint32_t smu7_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)
3433 struct pp_power_state *ps;
3434 struct smu7_power_state *smu7_ps;
3439 ps = hwmgr->request_ps;
3444 smu7_ps = cast_phw_smu7_power_state(&ps->hardware);
3447 return smu7_ps->performance_levels[0].memory_clock;
3449 return smu7_ps->performance_levels
3450 [smu7_ps->performance_level_count-1].memory_clock;
3453 static uint32_t smu7_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)
3455 struct pp_power_state *ps;
3456 struct smu7_power_state *smu7_ps;
3461 ps = hwmgr->request_ps;
3466 smu7_ps = cast_phw_smu7_power_state(&ps->hardware);
3469 return smu7_ps->performance_levels[0].engine_clock;
3471 return smu7_ps->performance_levels
3472 [smu7_ps->performance_level_count-1].engine_clock;
3475 static int smu7_dpm_patch_boot_state(struct pp_hwmgr *hwmgr,
3476 struct pp_hw_power_state *hw_ps)
3478 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3479 struct smu7_power_state *ps = (struct smu7_power_state *)hw_ps;
3480 ATOM_FIRMWARE_INFO_V2_2 *fw_info;
3483 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
3485 /* First retrieve the Boot clocks and VDDC from the firmware info table.
3486 * We assume here that fw_info is unchanged if this call fails.
3488 fw_info = (ATOM_FIRMWARE_INFO_V2_2 *)smu_atom_get_data_table(hwmgr->adev, index,
3489 &size, &frev, &crev);
3491 /* During a test, there is no firmware info table. */
3494 /* Patch the state. */
3495 data->vbios_boot_state.sclk_bootup_value =
3496 le32_to_cpu(fw_info->ulDefaultEngineClock);
3497 data->vbios_boot_state.mclk_bootup_value =
3498 le32_to_cpu(fw_info->ulDefaultMemoryClock);
3499 data->vbios_boot_state.mvdd_bootup_value =
3500 le16_to_cpu(fw_info->usBootUpMVDDCVoltage);
3501 data->vbios_boot_state.vddc_bootup_value =
3502 le16_to_cpu(fw_info->usBootUpVDDCVoltage);
3503 data->vbios_boot_state.vddci_bootup_value =
3504 le16_to_cpu(fw_info->usBootUpVDDCIVoltage);
3505 data->vbios_boot_state.pcie_gen_bootup_value =
3506 smu7_get_current_pcie_speed(hwmgr);
3508 data->vbios_boot_state.pcie_lane_bootup_value =
3509 (uint16_t)smu7_get_current_pcie_lane_number(hwmgr);
3511 /* set boot power state */
3512 ps->performance_levels[0].memory_clock = data->vbios_boot_state.mclk_bootup_value;
3513 ps->performance_levels[0].engine_clock = data->vbios_boot_state.sclk_bootup_value;
3514 ps->performance_levels[0].pcie_gen = data->vbios_boot_state.pcie_gen_bootup_value;
3515 ps->performance_levels[0].pcie_lane = data->vbios_boot_state.pcie_lane_bootup_value;
3520 static int smu7_get_number_of_powerplay_table_entries(struct pp_hwmgr *hwmgr)
3523 unsigned long ret = 0;
3525 if (hwmgr->pp_table_version == PP_TABLE_V0) {
3526 result = pp_tables_get_num_of_entries(hwmgr, &ret);
3527 return result ? 0 : ret;
3528 } else if (hwmgr->pp_table_version == PP_TABLE_V1) {
3529 result = get_number_of_powerplay_table_entries_v1_0(hwmgr);
3535 static int smu7_get_pp_table_entry_callback_func_v1(struct pp_hwmgr *hwmgr,
3536 void *state, struct pp_power_state *power_state,
3537 void *pp_table, uint32_t classification_flag)
3539 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3540 struct smu7_power_state *smu7_power_state =
3541 (struct smu7_power_state *)(&(power_state->hardware));
3542 struct smu7_performance_level *performance_level;
3543 ATOM_Tonga_State *state_entry = (ATOM_Tonga_State *)state;
3544 ATOM_Tonga_POWERPLAYTABLE *powerplay_table =
3545 (ATOM_Tonga_POWERPLAYTABLE *)pp_table;
3546 PPTable_Generic_SubTable_Header *sclk_dep_table =
3547 (PPTable_Generic_SubTable_Header *)
3548 (((unsigned long)powerplay_table) +
3549 le16_to_cpu(powerplay_table->usSclkDependencyTableOffset));
3551 ATOM_Tonga_MCLK_Dependency_Table *mclk_dep_table =
3552 (ATOM_Tonga_MCLK_Dependency_Table *)
3553 (((unsigned long)powerplay_table) +
3554 le16_to_cpu(powerplay_table->usMclkDependencyTableOffset));
3556 /* The following fields are not initialized here: id orderedList allStatesList */
3557 power_state->classification.ui_label =
3558 (le16_to_cpu(state_entry->usClassification) &
3559 ATOM_PPLIB_CLASSIFICATION_UI_MASK) >>
3560 ATOM_PPLIB_CLASSIFICATION_UI_SHIFT;
3561 power_state->classification.flags = classification_flag;
3562 /* NOTE: There is a classification2 flag in BIOS that is not being used right now */
3564 power_state->classification.temporary_state = false;
3565 power_state->classification.to_be_deleted = false;
3567 power_state->validation.disallowOnDC =
3568 (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) &
3569 ATOM_Tonga_DISALLOW_ON_DC));
3571 power_state->pcie.lanes = 0;
3573 power_state->display.disableFrameModulation = false;
3574 power_state->display.limitRefreshrate = false;
3575 power_state->display.enableVariBright =
3576 (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) &
3577 ATOM_Tonga_ENABLE_VARIBRIGHT));
3579 power_state->validation.supportedPowerLevels = 0;
3580 power_state->uvd_clocks.VCLK = 0;
3581 power_state->uvd_clocks.DCLK = 0;
3582 power_state->temperatures.min = 0;
3583 power_state->temperatures.max = 0;
3585 performance_level = &(smu7_power_state->performance_levels
3586 [smu7_power_state->performance_level_count++]);
3588 PP_ASSERT_WITH_CODE(
3589 (smu7_power_state->performance_level_count < smum_get_mac_definition(hwmgr, SMU_MAX_LEVELS_GRAPHICS)),
3590 "Performance levels exceeds SMC limit!",
3593 PP_ASSERT_WITH_CODE(
3594 (smu7_power_state->performance_level_count <=
3595 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels),
3596 "Performance levels exceeds Driver limit!",
3599 /* Performance levels are arranged from low to high. */
3600 performance_level->memory_clock = mclk_dep_table->entries
3601 [state_entry->ucMemoryClockIndexLow].ulMclk;
3602 if (sclk_dep_table->ucRevId == 0)
3603 performance_level->engine_clock = ((ATOM_Tonga_SCLK_Dependency_Table *)sclk_dep_table)->entries
3604 [state_entry->ucEngineClockIndexLow].ulSclk;
3605 else if (sclk_dep_table->ucRevId == 1)
3606 performance_level->engine_clock = ((ATOM_Polaris_SCLK_Dependency_Table *)sclk_dep_table)->entries
3607 [state_entry->ucEngineClockIndexLow].ulSclk;
3608 performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap,
3609 state_entry->ucPCIEGenLow);
3610 performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap,
3611 state_entry->ucPCIELaneLow);
3613 performance_level = &(smu7_power_state->performance_levels
3614 [smu7_power_state->performance_level_count++]);
3615 performance_level->memory_clock = mclk_dep_table->entries
3616 [state_entry->ucMemoryClockIndexHigh].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->ucEngineClockIndexHigh].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->ucEngineClockIndexHigh].ulSclk;
3625 performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap,
3626 state_entry->ucPCIEGenHigh);
3627 performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap,
3628 state_entry->ucPCIELaneHigh);
3633 static int smu7_get_pp_table_entry_v1(struct pp_hwmgr *hwmgr,
3634 unsigned long entry_index, struct pp_power_state *state)
3637 struct smu7_power_state *ps;
3638 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3639 struct phm_ppt_v1_information *table_info =
3640 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3641 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
3642 table_info->vdd_dep_on_mclk;
3644 state->hardware.magic = PHM_VIslands_Magic;
3646 ps = (struct smu7_power_state *)(&state->hardware);
3648 result = get_powerplay_table_entry_v1_0(hwmgr, entry_index, state,
3649 smu7_get_pp_table_entry_callback_func_v1);
3651 /* This is the earliest time we have all the dependency table and the VBIOS boot state
3652 * as PP_Tables_GetPowerPlayTableEntry retrieves the VBIOS boot state
3653 * if there is only one VDDCI/MCLK level, check if it's the same as VBIOS boot state
3655 if (dep_mclk_table != NULL && dep_mclk_table->count == 1) {
3656 if (dep_mclk_table->entries[0].clk !=
3657 data->vbios_boot_state.mclk_bootup_value)
3658 pr_debug("Single MCLK entry VDDCI/MCLK dependency table "
3659 "does not match VBIOS boot MCLK level");
3660 if (dep_mclk_table->entries[0].vddci !=
3661 data->vbios_boot_state.vddci_bootup_value)
3662 pr_debug("Single VDDCI entry VDDCI/MCLK dependency table "
3663 "does not match VBIOS boot VDDCI level");
3666 /* set DC compatible flag if this state supports DC */
3667 if (!state->validation.disallowOnDC)
3668 ps->dc_compatible = true;
3670 if (state->classification.flags & PP_StateClassificationFlag_ACPI)
3671 data->acpi_pcie_gen = ps->performance_levels[0].pcie_gen;
3673 ps->uvd_clks.vclk = state->uvd_clocks.VCLK;
3674 ps->uvd_clks.dclk = state->uvd_clocks.DCLK;
3679 switch (state->classification.ui_label) {
3680 case PP_StateUILabel_Performance:
3681 data->use_pcie_performance_levels = true;
3682 for (i = 0; i < ps->performance_level_count; i++) {
3683 if (data->pcie_gen_performance.max <
3684 ps->performance_levels[i].pcie_gen)
3685 data->pcie_gen_performance.max =
3686 ps->performance_levels[i].pcie_gen;
3688 if (data->pcie_gen_performance.min >
3689 ps->performance_levels[i].pcie_gen)
3690 data->pcie_gen_performance.min =
3691 ps->performance_levels[i].pcie_gen;
3693 if (data->pcie_lane_performance.max <
3694 ps->performance_levels[i].pcie_lane)
3695 data->pcie_lane_performance.max =
3696 ps->performance_levels[i].pcie_lane;
3697 if (data->pcie_lane_performance.min >
3698 ps->performance_levels[i].pcie_lane)
3699 data->pcie_lane_performance.min =
3700 ps->performance_levels[i].pcie_lane;
3703 case PP_StateUILabel_Battery:
3704 data->use_pcie_power_saving_levels = true;
3706 for (i = 0; i < ps->performance_level_count; i++) {
3707 if (data->pcie_gen_power_saving.max <
3708 ps->performance_levels[i].pcie_gen)
3709 data->pcie_gen_power_saving.max =
3710 ps->performance_levels[i].pcie_gen;
3712 if (data->pcie_gen_power_saving.min >
3713 ps->performance_levels[i].pcie_gen)
3714 data->pcie_gen_power_saving.min =
3715 ps->performance_levels[i].pcie_gen;
3717 if (data->pcie_lane_power_saving.max <
3718 ps->performance_levels[i].pcie_lane)
3719 data->pcie_lane_power_saving.max =
3720 ps->performance_levels[i].pcie_lane;
3722 if (data->pcie_lane_power_saving.min >
3723 ps->performance_levels[i].pcie_lane)
3724 data->pcie_lane_power_saving.min =
3725 ps->performance_levels[i].pcie_lane;
3735 static int smu7_get_pp_table_entry_callback_func_v0(struct pp_hwmgr *hwmgr,
3736 struct pp_hw_power_state *power_state,
3737 unsigned int index, const void *clock_info)
3739 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3740 struct smu7_power_state *ps = cast_phw_smu7_power_state(power_state);
3741 const ATOM_PPLIB_CI_CLOCK_INFO *visland_clk_info = clock_info;
3742 struct smu7_performance_level *performance_level;
3743 uint32_t engine_clock, memory_clock;
3744 uint16_t pcie_gen_from_bios;
3746 engine_clock = visland_clk_info->ucEngineClockHigh << 16 | visland_clk_info->usEngineClockLow;
3747 memory_clock = visland_clk_info->ucMemoryClockHigh << 16 | visland_clk_info->usMemoryClockLow;
3749 if (!(data->mc_micro_code_feature & DISABLE_MC_LOADMICROCODE) && memory_clock > data->highest_mclk)
3750 data->highest_mclk = memory_clock;
3752 PP_ASSERT_WITH_CODE(
3753 (ps->performance_level_count < smum_get_mac_definition(hwmgr, SMU_MAX_LEVELS_GRAPHICS)),
3754 "Performance levels exceeds SMC limit!",
3757 PP_ASSERT_WITH_CODE(
3758 (ps->performance_level_count <
3759 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels),
3760 "Performance levels exceeds Driver limit, Skip!",
3763 performance_level = &(ps->performance_levels
3764 [ps->performance_level_count++]);
3766 /* Performance levels are arranged from low to high. */
3767 performance_level->memory_clock = memory_clock;
3768 performance_level->engine_clock = engine_clock;
3770 pcie_gen_from_bios = visland_clk_info->ucPCIEGen;
3772 performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap, pcie_gen_from_bios);
3773 performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap, visland_clk_info->usPCIELane);
3778 static int smu7_get_pp_table_entry_v0(struct pp_hwmgr *hwmgr,
3779 unsigned long entry_index, struct pp_power_state *state)
3782 struct smu7_power_state *ps;
3783 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3784 struct phm_clock_voltage_dependency_table *dep_mclk_table =
3785 hwmgr->dyn_state.vddci_dependency_on_mclk;
3787 memset(&state->hardware, 0x00, sizeof(struct pp_hw_power_state));
3789 state->hardware.magic = PHM_VIslands_Magic;
3791 ps = (struct smu7_power_state *)(&state->hardware);
3793 result = pp_tables_get_entry(hwmgr, entry_index, state,
3794 smu7_get_pp_table_entry_callback_func_v0);
3797 * This is the earliest time we have all the dependency table
3798 * and the VBIOS boot state as
3799 * PP_Tables_GetPowerPlayTableEntry retrieves the VBIOS boot
3800 * state if there is only one VDDCI/MCLK level, check if it's
3801 * the same as VBIOS boot state
3803 if (dep_mclk_table != NULL && dep_mclk_table->count == 1) {
3804 if (dep_mclk_table->entries[0].clk !=
3805 data->vbios_boot_state.mclk_bootup_value)
3806 pr_debug("Single MCLK entry VDDCI/MCLK dependency table "
3807 "does not match VBIOS boot MCLK level");
3808 if (dep_mclk_table->entries[0].v !=
3809 data->vbios_boot_state.vddci_bootup_value)
3810 pr_debug("Single VDDCI entry VDDCI/MCLK dependency table "
3811 "does not match VBIOS boot VDDCI level");
3814 /* set DC compatible flag if this state supports DC */
3815 if (!state->validation.disallowOnDC)
3816 ps->dc_compatible = true;
3818 if (state->classification.flags & PP_StateClassificationFlag_ACPI)
3819 data->acpi_pcie_gen = ps->performance_levels[0].pcie_gen;
3821 ps->uvd_clks.vclk = state->uvd_clocks.VCLK;
3822 ps->uvd_clks.dclk = state->uvd_clocks.DCLK;
3827 switch (state->classification.ui_label) {
3828 case PP_StateUILabel_Performance:
3829 data->use_pcie_performance_levels = true;
3831 for (i = 0; i < ps->performance_level_count; i++) {
3832 if (data->pcie_gen_performance.max <
3833 ps->performance_levels[i].pcie_gen)
3834 data->pcie_gen_performance.max =
3835 ps->performance_levels[i].pcie_gen;
3837 if (data->pcie_gen_performance.min >
3838 ps->performance_levels[i].pcie_gen)
3839 data->pcie_gen_performance.min =
3840 ps->performance_levels[i].pcie_gen;
3842 if (data->pcie_lane_performance.max <
3843 ps->performance_levels[i].pcie_lane)
3844 data->pcie_lane_performance.max =
3845 ps->performance_levels[i].pcie_lane;
3847 if (data->pcie_lane_performance.min >
3848 ps->performance_levels[i].pcie_lane)
3849 data->pcie_lane_performance.min =
3850 ps->performance_levels[i].pcie_lane;
3853 case PP_StateUILabel_Battery:
3854 data->use_pcie_power_saving_levels = true;
3856 for (i = 0; i < ps->performance_level_count; i++) {
3857 if (data->pcie_gen_power_saving.max <
3858 ps->performance_levels[i].pcie_gen)
3859 data->pcie_gen_power_saving.max =
3860 ps->performance_levels[i].pcie_gen;
3862 if (data->pcie_gen_power_saving.min >
3863 ps->performance_levels[i].pcie_gen)
3864 data->pcie_gen_power_saving.min =
3865 ps->performance_levels[i].pcie_gen;
3867 if (data->pcie_lane_power_saving.max <
3868 ps->performance_levels[i].pcie_lane)
3869 data->pcie_lane_power_saving.max =
3870 ps->performance_levels[i].pcie_lane;
3872 if (data->pcie_lane_power_saving.min >
3873 ps->performance_levels[i].pcie_lane)
3874 data->pcie_lane_power_saving.min =
3875 ps->performance_levels[i].pcie_lane;
3885 static int smu7_get_pp_table_entry(struct pp_hwmgr *hwmgr,
3886 unsigned long entry_index, struct pp_power_state *state)
3888 if (hwmgr->pp_table_version == PP_TABLE_V0)
3889 return smu7_get_pp_table_entry_v0(hwmgr, entry_index, state);
3890 else if (hwmgr->pp_table_version == PP_TABLE_V1)
3891 return smu7_get_pp_table_entry_v1(hwmgr, entry_index, state);
3896 static int smu7_get_gpu_power(struct pp_hwmgr *hwmgr, u32 *query)
3898 struct amdgpu_device *adev = hwmgr->adev;
3906 * PPSMC_MSG_GetCurrPkgPwr is not supported on:
3912 if ((adev->asic_type != CHIP_HAWAII) &&
3913 (adev->asic_type != CHIP_BONAIRE) &&
3914 (adev->asic_type != CHIP_FIJI) &&
3915 (adev->asic_type != CHIP_TONGA)) {
3916 smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_GetCurrPkgPwr, 0, &tmp);
3923 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_PmStatusLogStart, NULL);
3924 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3925 ixSMU_PM_STATUS_95, 0);
3927 for (i = 0; i < 10; i++) {
3929 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_PmStatusLogSample, NULL);
3930 tmp = cgs_read_ind_register(hwmgr->device,
3932 ixSMU_PM_STATUS_95);
3941 static int smu7_read_sensor(struct pp_hwmgr *hwmgr, int idx,
3942 void *value, int *size)
3944 uint32_t sclk, mclk, activity_percent;
3945 uint32_t offset, val_vid;
3946 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3948 /* size must be at least 4 bytes for all sensors */
3953 case AMDGPU_PP_SENSOR_GFX_SCLK:
3954 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_API_GetSclkFrequency, &sclk);
3955 *((uint32_t *)value) = sclk;
3958 case AMDGPU_PP_SENSOR_GFX_MCLK:
3959 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_API_GetMclkFrequency, &mclk);
3960 *((uint32_t *)value) = mclk;
3963 case AMDGPU_PP_SENSOR_GPU_LOAD:
3964 case AMDGPU_PP_SENSOR_MEM_LOAD:
3965 offset = data->soft_regs_start + smum_get_offsetof(hwmgr,
3967 (idx == AMDGPU_PP_SENSOR_GPU_LOAD) ?
3968 AverageGraphicsActivity:
3969 AverageMemoryActivity);
3971 activity_percent = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, offset);
3972 activity_percent += 0x80;
3973 activity_percent >>= 8;
3974 *((uint32_t *)value) = activity_percent > 100 ? 100 : activity_percent;
3977 case AMDGPU_PP_SENSOR_GPU_TEMP:
3978 *((uint32_t *)value) = smu7_thermal_get_temperature(hwmgr);
3981 case AMDGPU_PP_SENSOR_UVD_POWER:
3982 *((uint32_t *)value) = data->uvd_power_gated ? 0 : 1;
3985 case AMDGPU_PP_SENSOR_VCE_POWER:
3986 *((uint32_t *)value) = data->vce_power_gated ? 0 : 1;
3989 case AMDGPU_PP_SENSOR_GPU_POWER:
3990 return smu7_get_gpu_power(hwmgr, (uint32_t *)value);
3991 case AMDGPU_PP_SENSOR_VDDGFX:
3992 if ((data->vr_config & VRCONF_VDDGFX_MASK) ==
3993 (VR_SVI2_PLANE_2 << VRCONF_VDDGFX_SHIFT))
3994 val_vid = PHM_READ_INDIRECT_FIELD(hwmgr->device,
3995 CGS_IND_REG__SMC, PWR_SVI2_STATUS, PLANE2_VID);
3997 val_vid = PHM_READ_INDIRECT_FIELD(hwmgr->device,
3998 CGS_IND_REG__SMC, PWR_SVI2_STATUS, PLANE1_VID);
4000 *((uint32_t *)value) = (uint32_t)convert_to_vddc(val_vid);
4007 static int smu7_find_dpm_states_clocks_in_dpm_table(struct pp_hwmgr *hwmgr, const void *input)
4009 const struct phm_set_power_state_input *states =
4010 (const struct phm_set_power_state_input *)input;
4011 const struct smu7_power_state *smu7_ps =
4012 cast_const_phw_smu7_power_state(states->pnew_state);
4013 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4014 struct smu7_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
4015 uint32_t sclk = smu7_ps->performance_levels
4016 [smu7_ps->performance_level_count - 1].engine_clock;
4017 struct smu7_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
4018 uint32_t mclk = smu7_ps->performance_levels
4019 [smu7_ps->performance_level_count - 1].memory_clock;
4020 struct PP_Clocks min_clocks = {0};
4023 for (i = 0; i < sclk_table->count; i++) {
4024 if (sclk == sclk_table->dpm_levels[i].value)
4028 if (i >= sclk_table->count) {
4029 if (sclk > sclk_table->dpm_levels[i-1].value) {
4030 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK;
4031 sclk_table->dpm_levels[i-1].value = sclk;
4034 /* TODO: Check SCLK in DAL's minimum clocks
4035 * in case DeepSleep divider update is required.
4037 if (data->display_timing.min_clock_in_sr != min_clocks.engineClockInSR &&
4038 (min_clocks.engineClockInSR >= SMU7_MINIMUM_ENGINE_CLOCK ||
4039 data->display_timing.min_clock_in_sr >= SMU7_MINIMUM_ENGINE_CLOCK))
4040 data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_SCLK;
4043 for (i = 0; i < mclk_table->count; i++) {
4044 if (mclk == mclk_table->dpm_levels[i].value)
4048 if (i >= mclk_table->count) {
4049 if (mclk > mclk_table->dpm_levels[i-1].value) {
4050 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_MCLK;
4051 mclk_table->dpm_levels[i-1].value = mclk;
4055 if (data->display_timing.num_existing_displays != hwmgr->display_config->num_display)
4056 data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_MCLK;
4061 static uint16_t smu7_get_maximum_link_speed(struct pp_hwmgr *hwmgr,
4062 const struct smu7_power_state *smu7_ps)
4065 uint32_t sclk, max_sclk = 0;
4066 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4067 struct smu7_dpm_table *dpm_table = &data->dpm_table;
4069 for (i = 0; i < smu7_ps->performance_level_count; i++) {
4070 sclk = smu7_ps->performance_levels[i].engine_clock;
4071 if (max_sclk < sclk)
4075 for (i = 0; i < dpm_table->sclk_table.count; i++) {
4076 if (dpm_table->sclk_table.dpm_levels[i].value == max_sclk)
4077 return (uint16_t) ((i >= dpm_table->pcie_speed_table.count) ?
4078 dpm_table->pcie_speed_table.dpm_levels
4079 [dpm_table->pcie_speed_table.count - 1].value :
4080 dpm_table->pcie_speed_table.dpm_levels[i].value);
4086 static int smu7_request_link_speed_change_before_state_change(
4087 struct pp_hwmgr *hwmgr, const void *input)
4089 const struct phm_set_power_state_input *states =
4090 (const struct phm_set_power_state_input *)input;
4091 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4092 const struct smu7_power_state *smu7_nps =
4093 cast_const_phw_smu7_power_state(states->pnew_state);
4094 const struct smu7_power_state *polaris10_cps =
4095 cast_const_phw_smu7_power_state(states->pcurrent_state);
4097 uint16_t target_link_speed = smu7_get_maximum_link_speed(hwmgr, smu7_nps);
4098 uint16_t current_link_speed;
4100 if (data->force_pcie_gen == PP_PCIEGenInvalid)
4101 current_link_speed = smu7_get_maximum_link_speed(hwmgr, polaris10_cps);
4103 current_link_speed = data->force_pcie_gen;
4105 data->force_pcie_gen = PP_PCIEGenInvalid;
4106 data->pspp_notify_required = false;
4108 if (target_link_speed > current_link_speed) {
4109 switch (target_link_speed) {
4112 if (0 == amdgpu_acpi_pcie_performance_request(hwmgr->adev, PCIE_PERF_REQ_GEN3, false))
4114 data->force_pcie_gen = PP_PCIEGen2;
4115 if (current_link_speed == PP_PCIEGen2)
4119 if (0 == amdgpu_acpi_pcie_performance_request(hwmgr->adev, PCIE_PERF_REQ_GEN2, false))
4124 data->force_pcie_gen = smu7_get_current_pcie_speed(hwmgr);
4128 if (target_link_speed < current_link_speed)
4129 data->pspp_notify_required = true;
4135 static int smu7_freeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
4137 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4139 if (0 == data->need_update_smu7_dpm_table)
4142 if ((0 == data->sclk_dpm_key_disabled) &&
4143 (data->need_update_smu7_dpm_table &
4144 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
4145 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
4146 "Trying to freeze SCLK DPM when DPM is disabled",
4148 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr,
4149 PPSMC_MSG_SCLKDPM_FreezeLevel,
4151 "Failed to freeze SCLK DPM during FreezeSclkMclkDPM Function!",
4155 if ((0 == data->mclk_dpm_key_disabled) &&
4156 !data->mclk_ignore_signal &&
4157 (data->need_update_smu7_dpm_table &
4158 DPMTABLE_OD_UPDATE_MCLK)) {
4159 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
4160 "Trying to freeze MCLK DPM when DPM is disabled",
4162 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr,
4163 PPSMC_MSG_MCLKDPM_FreezeLevel,
4165 "Failed to freeze MCLK DPM during FreezeSclkMclkDPM Function!",
4172 static int smu7_populate_and_upload_sclk_mclk_dpm_levels(
4173 struct pp_hwmgr *hwmgr, const void *input)
4176 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4177 struct smu7_dpm_table *dpm_table = &data->dpm_table;
4179 struct smu7_odn_dpm_table *odn_table = &(data->odn_dpm_table);
4180 struct phm_odn_clock_levels *odn_sclk_table = &(odn_table->odn_core_clock_dpm_levels);
4181 struct phm_odn_clock_levels *odn_mclk_table = &(odn_table->odn_memory_clock_dpm_levels);
4183 if (0 == data->need_update_smu7_dpm_table)
4186 if (hwmgr->od_enabled && data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_SCLK) {
4187 for (count = 0; count < dpm_table->sclk_table.count; count++) {
4188 dpm_table->sclk_table.dpm_levels[count].enabled = odn_sclk_table->entries[count].enabled;
4189 dpm_table->sclk_table.dpm_levels[count].value = odn_sclk_table->entries[count].clock;
4193 if (hwmgr->od_enabled && data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK) {
4194 for (count = 0; count < dpm_table->mclk_table.count; count++) {
4195 dpm_table->mclk_table.dpm_levels[count].enabled = odn_mclk_table->entries[count].enabled;
4196 dpm_table->mclk_table.dpm_levels[count].value = odn_mclk_table->entries[count].clock;
4200 if (data->need_update_smu7_dpm_table &
4201 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK)) {
4202 result = smum_populate_all_graphic_levels(hwmgr);
4203 PP_ASSERT_WITH_CODE((0 == result),
4204 "Failed to populate SCLK during PopulateNewDPMClocksStates Function!",
4208 if (data->need_update_smu7_dpm_table &
4209 (DPMTABLE_OD_UPDATE_MCLK + DPMTABLE_UPDATE_MCLK)) {
4210 /*populate MCLK dpm table to SMU7 */
4211 result = smum_populate_all_memory_levels(hwmgr);
4212 PP_ASSERT_WITH_CODE((0 == result),
4213 "Failed to populate MCLK during PopulateNewDPMClocksStates Function!",
4220 static int smu7_trim_single_dpm_states(struct pp_hwmgr *hwmgr,
4221 struct smu7_single_dpm_table *dpm_table,
4222 uint32_t low_limit, uint32_t high_limit)
4226 /* force the trim if mclk_switching is disabled to prevent flicker */
4227 bool force_trim = (low_limit == high_limit);
4228 for (i = 0; i < dpm_table->count; i++) {
4229 /*skip the trim if od is enabled*/
4230 if ((!hwmgr->od_enabled || force_trim)
4231 && (dpm_table->dpm_levels[i].value < low_limit
4232 || dpm_table->dpm_levels[i].value > high_limit))
4233 dpm_table->dpm_levels[i].enabled = false;
4235 dpm_table->dpm_levels[i].enabled = true;
4241 static int smu7_trim_dpm_states(struct pp_hwmgr *hwmgr,
4242 const struct smu7_power_state *smu7_ps)
4244 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4245 uint32_t high_limit_count;
4247 PP_ASSERT_WITH_CODE((smu7_ps->performance_level_count >= 1),
4248 "power state did not have any performance level",
4251 high_limit_count = (1 == smu7_ps->performance_level_count) ? 0 : 1;
4253 smu7_trim_single_dpm_states(hwmgr,
4254 &(data->dpm_table.sclk_table),
4255 smu7_ps->performance_levels[0].engine_clock,
4256 smu7_ps->performance_levels[high_limit_count].engine_clock);
4258 smu7_trim_single_dpm_states(hwmgr,
4259 &(data->dpm_table.mclk_table),
4260 smu7_ps->performance_levels[0].memory_clock,
4261 smu7_ps->performance_levels[high_limit_count].memory_clock);
4266 static int smu7_generate_dpm_level_enable_mask(
4267 struct pp_hwmgr *hwmgr, const void *input)
4270 const struct phm_set_power_state_input *states =
4271 (const struct phm_set_power_state_input *)input;
4272 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4273 const struct smu7_power_state *smu7_ps =
4274 cast_const_phw_smu7_power_state(states->pnew_state);
4277 result = smu7_trim_dpm_states(hwmgr, smu7_ps);
4281 data->dpm_level_enable_mask.sclk_dpm_enable_mask =
4282 phm_get_dpm_level_enable_mask_value(&data->dpm_table.sclk_table);
4283 data->dpm_level_enable_mask.mclk_dpm_enable_mask =
4284 phm_get_dpm_level_enable_mask_value(&data->dpm_table.mclk_table);
4285 data->dpm_level_enable_mask.pcie_dpm_enable_mask =
4286 phm_get_dpm_level_enable_mask_value(&data->dpm_table.pcie_speed_table);
4291 static int smu7_unfreeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
4293 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4295 if (0 == data->need_update_smu7_dpm_table)
4298 if ((0 == data->sclk_dpm_key_disabled) &&
4299 (data->need_update_smu7_dpm_table &
4300 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
4302 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
4303 "Trying to Unfreeze SCLK DPM when DPM is disabled",
4305 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr,
4306 PPSMC_MSG_SCLKDPM_UnfreezeLevel,
4308 "Failed to unfreeze SCLK DPM during UnFreezeSclkMclkDPM Function!",
4312 if ((0 == data->mclk_dpm_key_disabled) &&
4313 !data->mclk_ignore_signal &&
4314 (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) {
4316 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
4317 "Trying to Unfreeze MCLK DPM when DPM is disabled",
4319 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr,
4320 PPSMC_MSG_MCLKDPM_UnfreezeLevel,
4322 "Failed to unfreeze MCLK DPM during UnFreezeSclkMclkDPM Function!",
4326 data->need_update_smu7_dpm_table &= DPMTABLE_OD_UPDATE_VDDC;
4331 static int smu7_notify_link_speed_change_after_state_change(
4332 struct pp_hwmgr *hwmgr, const void *input)
4334 const struct phm_set_power_state_input *states =
4335 (const struct phm_set_power_state_input *)input;
4336 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4337 const struct smu7_power_state *smu7_ps =
4338 cast_const_phw_smu7_power_state(states->pnew_state);
4339 uint16_t target_link_speed = smu7_get_maximum_link_speed(hwmgr, smu7_ps);
4342 if (data->pspp_notify_required) {
4343 if (target_link_speed == PP_PCIEGen3)
4344 request = PCIE_PERF_REQ_GEN3;
4345 else if (target_link_speed == PP_PCIEGen2)
4346 request = PCIE_PERF_REQ_GEN2;
4348 request = PCIE_PERF_REQ_GEN1;
4350 if (request == PCIE_PERF_REQ_GEN1 &&
4351 smu7_get_current_pcie_speed(hwmgr) > 0)
4355 if (amdgpu_acpi_pcie_performance_request(hwmgr->adev, request, false)) {
4356 if (PP_PCIEGen2 == target_link_speed)
4357 pr_info("PSPP request to switch to Gen2 from Gen3 Failed!");
4359 pr_info("PSPP request to switch to Gen1 from Gen2 Failed!");
4367 static int smu7_notify_no_display(struct pp_hwmgr *hwmgr)
4369 return (smum_send_msg_to_smc(hwmgr, (PPSMC_Msg)PPSMC_NoDisplay, NULL) == 0) ? 0 : -EINVAL;
4372 static int smu7_notify_has_display(struct pp_hwmgr *hwmgr)
4374 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4376 if (hwmgr->feature_mask & PP_VBI_TIME_SUPPORT_MASK) {
4377 if (hwmgr->chip_id == CHIP_VEGAM)
4378 smum_send_msg_to_smc_with_parameter(hwmgr,
4379 (PPSMC_Msg)PPSMC_MSG_SetVBITimeout_VEGAM, data->frame_time_x2,
4382 smum_send_msg_to_smc_with_parameter(hwmgr,
4383 (PPSMC_Msg)PPSMC_MSG_SetVBITimeout, data->frame_time_x2,
4385 data->last_sent_vbi_timeout = data->frame_time_x2;
4388 return (smum_send_msg_to_smc(hwmgr, (PPSMC_Msg)PPSMC_HasDisplay, NULL) == 0) ? 0 : -EINVAL;
4391 static int smu7_notify_smc_display(struct pp_hwmgr *hwmgr)
4393 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4396 if (data->mclk_ignore_signal)
4397 result = smu7_notify_no_display(hwmgr);
4399 result = smu7_notify_has_display(hwmgr);
4404 static int smu7_set_power_state_tasks(struct pp_hwmgr *hwmgr, const void *input)
4406 int tmp_result, result = 0;
4407 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4409 tmp_result = smu7_find_dpm_states_clocks_in_dpm_table(hwmgr, input);
4410 PP_ASSERT_WITH_CODE((0 == tmp_result),
4411 "Failed to find DPM states clocks in DPM table!",
4412 result = tmp_result);
4414 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4415 PHM_PlatformCaps_PCIEPerformanceRequest)) {
4417 smu7_request_link_speed_change_before_state_change(hwmgr, input);
4418 PP_ASSERT_WITH_CODE((0 == tmp_result),
4419 "Failed to request link speed change before state change!",
4420 result = tmp_result);
4423 tmp_result = smu7_freeze_sclk_mclk_dpm(hwmgr);
4424 PP_ASSERT_WITH_CODE((0 == tmp_result),
4425 "Failed to freeze SCLK MCLK DPM!", result = tmp_result);
4427 tmp_result = smu7_populate_and_upload_sclk_mclk_dpm_levels(hwmgr, input);
4428 PP_ASSERT_WITH_CODE((0 == tmp_result),
4429 "Failed to populate and upload SCLK MCLK DPM levels!",
4430 result = tmp_result);
4433 * If a custom pp table is loaded, set DPMTABLE_OD_UPDATE_VDDC flag.
4434 * That effectively disables AVFS feature.
4436 if (hwmgr->hardcode_pp_table != NULL)
4437 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_VDDC;
4439 tmp_result = smu7_update_avfs(hwmgr);
4440 PP_ASSERT_WITH_CODE((0 == tmp_result),
4441 "Failed to update avfs voltages!",
4442 result = tmp_result);
4444 tmp_result = smu7_generate_dpm_level_enable_mask(hwmgr, input);
4445 PP_ASSERT_WITH_CODE((0 == tmp_result),
4446 "Failed to generate DPM level enabled mask!",
4447 result = tmp_result);
4449 tmp_result = smum_update_sclk_threshold(hwmgr);
4450 PP_ASSERT_WITH_CODE((0 == tmp_result),
4451 "Failed to update SCLK threshold!",
4452 result = tmp_result);
4454 tmp_result = smu7_unfreeze_sclk_mclk_dpm(hwmgr);
4455 PP_ASSERT_WITH_CODE((0 == tmp_result),
4456 "Failed to unfreeze SCLK MCLK DPM!",
4457 result = tmp_result);
4459 tmp_result = smu7_upload_dpm_level_enable_mask(hwmgr);
4460 PP_ASSERT_WITH_CODE((0 == tmp_result),
4461 "Failed to upload DPM level enabled mask!",
4462 result = tmp_result);
4464 tmp_result = smu7_notify_smc_display(hwmgr);
4465 PP_ASSERT_WITH_CODE((0 == tmp_result),
4466 "Failed to notify smc display settings!",
4467 result = tmp_result);
4469 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4470 PHM_PlatformCaps_PCIEPerformanceRequest)) {
4472 smu7_notify_link_speed_change_after_state_change(hwmgr, input);
4473 PP_ASSERT_WITH_CODE((0 == tmp_result),
4474 "Failed to notify link speed change after state change!",
4475 result = tmp_result);
4477 data->apply_optimized_settings = false;
4481 static int smu7_set_max_fan_pwm_output(struct pp_hwmgr *hwmgr, uint16_t us_max_fan_pwm)
4483 hwmgr->thermal_controller.
4484 advanceFanControlParameters.usMaxFanPWM = us_max_fan_pwm;
4486 return smum_send_msg_to_smc_with_parameter(hwmgr,
4487 PPSMC_MSG_SetFanPwmMax, us_max_fan_pwm,
4492 smu7_notify_smc_display_config_after_ps_adjustment(struct pp_hwmgr *hwmgr)
4498 * smu7_program_display_gap - Programs the display gap
4500 * @hwmgr: the address of the powerplay hardware manager.
4503 static int smu7_program_display_gap(struct pp_hwmgr *hwmgr)
4505 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4506 uint32_t display_gap = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL);
4507 uint32_t display_gap2;
4508 uint32_t pre_vbi_time_in_us;
4509 uint32_t frame_time_in_us;
4510 uint32_t ref_clock, refresh_rate;
4512 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);
4513 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL, display_gap);
4515 ref_clock = amdgpu_asic_get_xclk((struct amdgpu_device *)hwmgr->adev);
4516 refresh_rate = hwmgr->display_config->vrefresh;
4518 if (0 == refresh_rate)
4521 frame_time_in_us = 1000000 / refresh_rate;
4523 pre_vbi_time_in_us = frame_time_in_us - 200 - hwmgr->display_config->min_vblank_time;
4525 data->frame_time_x2 = frame_time_in_us * 2 / 100;
4527 if (data->frame_time_x2 < 280) {
4528 pr_debug("%s: enforce minimal VBITimeout: %d -> 280\n", __func__, data->frame_time_x2);
4529 data->frame_time_x2 = 280;
4532 display_gap2 = pre_vbi_time_in_us * (ref_clock / 100);
4534 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL2, display_gap2);
4536 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
4537 data->soft_regs_start + smum_get_offsetof(hwmgr,
4539 PreVBlankGap), 0x64);
4541 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
4542 data->soft_regs_start + smum_get_offsetof(hwmgr,
4545 (frame_time_in_us - pre_vbi_time_in_us));
4550 static int smu7_display_configuration_changed_task(struct pp_hwmgr *hwmgr)
4552 return smu7_program_display_gap(hwmgr);
4556 * smu7_set_max_fan_rpm_output - Set maximum target operating fan output RPM
4558 * @hwmgr: the address of the powerplay hardware manager.
4559 * @us_max_fan_rpm: max operating fan RPM value.
4560 * Return: The response that came from the SMC.
4562 static int smu7_set_max_fan_rpm_output(struct pp_hwmgr *hwmgr, uint16_t us_max_fan_rpm)
4564 hwmgr->thermal_controller.
4565 advanceFanControlParameters.usMaxFanRPM = us_max_fan_rpm;
4567 return smum_send_msg_to_smc_with_parameter(hwmgr,
4568 PPSMC_MSG_SetFanRpmMax, us_max_fan_rpm,
4572 static const struct amdgpu_irq_src_funcs smu7_irq_funcs = {
4573 .process = phm_irq_process,
4576 static int smu7_register_irq_handlers(struct pp_hwmgr *hwmgr)
4578 struct amdgpu_irq_src *source =
4579 kzalloc(sizeof(struct amdgpu_irq_src), GFP_KERNEL);
4584 source->funcs = &smu7_irq_funcs;
4586 amdgpu_irq_add_id((struct amdgpu_device *)(hwmgr->adev),
4587 AMDGPU_IRQ_CLIENTID_LEGACY,
4588 VISLANDS30_IV_SRCID_CG_TSS_THERMAL_LOW_TO_HIGH,
4590 amdgpu_irq_add_id((struct amdgpu_device *)(hwmgr->adev),
4591 AMDGPU_IRQ_CLIENTID_LEGACY,
4592 VISLANDS30_IV_SRCID_CG_TSS_THERMAL_HIGH_TO_LOW,
4595 /* Register CTF(GPIO_19) interrupt */
4596 amdgpu_irq_add_id((struct amdgpu_device *)(hwmgr->adev),
4597 AMDGPU_IRQ_CLIENTID_LEGACY,
4598 VISLANDS30_IV_SRCID_GPIO_19,
4605 smu7_check_smc_update_required_for_display_configuration(struct pp_hwmgr *hwmgr)
4607 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4608 bool is_update_required = false;
4610 if (data->display_timing.num_existing_displays != hwmgr->display_config->num_display)
4611 is_update_required = true;
4613 if (data->display_timing.vrefresh != hwmgr->display_config->vrefresh)
4614 is_update_required = true;
4616 if (hwmgr->chip_id >= CHIP_POLARIS10 &&
4617 hwmgr->chip_id <= CHIP_VEGAM &&
4618 data->last_sent_vbi_timeout != data->frame_time_x2)
4619 is_update_required = true;
4621 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep)) {
4622 if (data->display_timing.min_clock_in_sr != hwmgr->display_config->min_core_set_clock_in_sr &&
4623 (data->display_timing.min_clock_in_sr >= SMU7_MINIMUM_ENGINE_CLOCK ||
4624 hwmgr->display_config->min_core_set_clock_in_sr >= SMU7_MINIMUM_ENGINE_CLOCK))
4625 is_update_required = true;
4627 return is_update_required;
4630 static inline bool smu7_are_power_levels_equal(const struct smu7_performance_level *pl1,
4631 const struct smu7_performance_level *pl2)
4633 return ((pl1->memory_clock == pl2->memory_clock) &&
4634 (pl1->engine_clock == pl2->engine_clock) &&
4635 (pl1->pcie_gen == pl2->pcie_gen) &&
4636 (pl1->pcie_lane == pl2->pcie_lane));
4639 static int smu7_check_states_equal(struct pp_hwmgr *hwmgr,
4640 const struct pp_hw_power_state *pstate1,
4641 const struct pp_hw_power_state *pstate2, bool *equal)
4643 const struct smu7_power_state *psa;
4644 const struct smu7_power_state *psb;
4646 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4648 if (pstate1 == NULL || pstate2 == NULL || equal == NULL)
4651 psa = cast_const_phw_smu7_power_state(pstate1);
4652 psb = cast_const_phw_smu7_power_state(pstate2);
4653 /* If the two states don't even have the same number of performance levels they cannot be the same state. */
4654 if (psa->performance_level_count != psb->performance_level_count) {
4659 for (i = 0; i < psa->performance_level_count; i++) {
4660 if (!smu7_are_power_levels_equal(&(psa->performance_levels[i]), &(psb->performance_levels[i]))) {
4661 /* If we have found even one performance level pair that is different the states are different. */
4667 /* If all performance levels are the same try to use the UVD clocks to break the tie.*/
4668 *equal = ((psa->uvd_clks.vclk == psb->uvd_clks.vclk) && (psa->uvd_clks.dclk == psb->uvd_clks.dclk));
4669 *equal &= ((psa->vce_clks.evclk == psb->vce_clks.evclk) && (psa->vce_clks.ecclk == psb->vce_clks.ecclk));
4670 *equal &= (psa->sclk_threshold == psb->sclk_threshold);
4671 /* For OD call, set value based on flag */
4672 *equal &= !(data->need_update_smu7_dpm_table & (DPMTABLE_OD_UPDATE_SCLK |
4673 DPMTABLE_OD_UPDATE_MCLK |
4674 DPMTABLE_OD_UPDATE_VDDC));
4679 static int smu7_check_mc_firmware(struct pp_hwmgr *hwmgr)
4681 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4685 /* Read MC indirect register offset 0x9F bits [3:0] to see
4686 * if VBIOS has already loaded a full version of MC ucode
4690 smu7_get_mc_microcode_version(hwmgr);
4692 data->need_long_memory_training = false;
4694 cgs_write_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_INDEX,
4695 ixMC_IO_DEBUG_UP_13);
4696 tmp = cgs_read_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_DATA);
4698 if (tmp & (1 << 23)) {
4699 data->mem_latency_high = MEM_LATENCY_HIGH;
4700 data->mem_latency_low = MEM_LATENCY_LOW;
4701 if ((hwmgr->chip_id == CHIP_POLARIS10) ||
4702 (hwmgr->chip_id == CHIP_POLARIS11) ||
4703 (hwmgr->chip_id == CHIP_POLARIS12))
4704 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_EnableFFC, NULL);
4706 data->mem_latency_high = 330;
4707 data->mem_latency_low = 330;
4708 if ((hwmgr->chip_id == CHIP_POLARIS10) ||
4709 (hwmgr->chip_id == CHIP_POLARIS11) ||
4710 (hwmgr->chip_id == CHIP_POLARIS12))
4711 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_DisableFFC, NULL);
4717 static int smu7_read_clock_registers(struct pp_hwmgr *hwmgr)
4719 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4721 data->clock_registers.vCG_SPLL_FUNC_CNTL =
4722 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL);
4723 data->clock_registers.vCG_SPLL_FUNC_CNTL_2 =
4724 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_2);
4725 data->clock_registers.vCG_SPLL_FUNC_CNTL_3 =
4726 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_3);
4727 data->clock_registers.vCG_SPLL_FUNC_CNTL_4 =
4728 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_4);
4729 data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM =
4730 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_SPREAD_SPECTRUM);
4731 data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2 =
4732 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_SPREAD_SPECTRUM_2);
4733 data->clock_registers.vDLL_CNTL =
4734 cgs_read_register(hwmgr->device, mmDLL_CNTL);
4735 data->clock_registers.vMCLK_PWRMGT_CNTL =
4736 cgs_read_register(hwmgr->device, mmMCLK_PWRMGT_CNTL);
4737 data->clock_registers.vMPLL_AD_FUNC_CNTL =
4738 cgs_read_register(hwmgr->device, mmMPLL_AD_FUNC_CNTL);
4739 data->clock_registers.vMPLL_DQ_FUNC_CNTL =
4740 cgs_read_register(hwmgr->device, mmMPLL_DQ_FUNC_CNTL);
4741 data->clock_registers.vMPLL_FUNC_CNTL =
4742 cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL);
4743 data->clock_registers.vMPLL_FUNC_CNTL_1 =
4744 cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL_1);
4745 data->clock_registers.vMPLL_FUNC_CNTL_2 =
4746 cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL_2);
4747 data->clock_registers.vMPLL_SS1 =
4748 cgs_read_register(hwmgr->device, mmMPLL_SS1);
4749 data->clock_registers.vMPLL_SS2 =
4750 cgs_read_register(hwmgr->device, mmMPLL_SS2);
4756 * smu7_get_memory_type - Find out if memory is GDDR5.
4758 * @hwmgr: the address of the powerplay hardware manager.
4761 static int smu7_get_memory_type(struct pp_hwmgr *hwmgr)
4763 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4764 struct amdgpu_device *adev = hwmgr->adev;
4766 data->is_memory_gddr5 = (adev->gmc.vram_type == AMDGPU_VRAM_TYPE_GDDR5);
4772 * smu7_enable_acpi_power_management - Enables Dynamic Power Management by SMC
4774 * @hwmgr: the address of the powerplay hardware manager.
4777 static int smu7_enable_acpi_power_management(struct pp_hwmgr *hwmgr)
4779 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
4780 GENERAL_PWRMGT, STATIC_PM_EN, 1);
4786 * smu7_init_power_gate_state - Initialize PowerGating States for different engines
4788 * @hwmgr: the address of the powerplay hardware manager.
4791 static int smu7_init_power_gate_state(struct pp_hwmgr *hwmgr)
4793 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4795 data->uvd_power_gated = false;
4796 data->vce_power_gated = false;
4801 static int smu7_init_sclk_threshold(struct pp_hwmgr *hwmgr)
4803 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4805 data->low_sclk_interrupt_threshold = 0;
4809 static int smu7_setup_asic_task(struct pp_hwmgr *hwmgr)
4811 int tmp_result, result = 0;
4813 smu7_check_mc_firmware(hwmgr);
4815 tmp_result = smu7_read_clock_registers(hwmgr);
4816 PP_ASSERT_WITH_CODE((0 == tmp_result),
4817 "Failed to read clock registers!", result = tmp_result);
4819 tmp_result = smu7_get_memory_type(hwmgr);
4820 PP_ASSERT_WITH_CODE((0 == tmp_result),
4821 "Failed to get memory type!", result = tmp_result);
4823 tmp_result = smu7_enable_acpi_power_management(hwmgr);
4824 PP_ASSERT_WITH_CODE((0 == tmp_result),
4825 "Failed to enable ACPI power management!", result = tmp_result);
4827 tmp_result = smu7_init_power_gate_state(hwmgr);
4828 PP_ASSERT_WITH_CODE((0 == tmp_result),
4829 "Failed to init power gate state!", result = tmp_result);
4831 tmp_result = smu7_get_mc_microcode_version(hwmgr);
4832 PP_ASSERT_WITH_CODE((0 == tmp_result),
4833 "Failed to get MC microcode version!", result = tmp_result);
4835 tmp_result = smu7_init_sclk_threshold(hwmgr);
4836 PP_ASSERT_WITH_CODE((0 == tmp_result),
4837 "Failed to init sclk threshold!", result = tmp_result);
4842 static int smu7_force_clock_level(struct pp_hwmgr *hwmgr,
4843 enum pp_clock_type type, uint32_t mask)
4845 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4852 if (!data->sclk_dpm_key_disabled)
4853 smum_send_msg_to_smc_with_parameter(hwmgr,
4854 PPSMC_MSG_SCLKDPM_SetEnabledMask,
4855 data->dpm_level_enable_mask.sclk_dpm_enable_mask & mask,
4859 if (!data->mclk_dpm_key_disabled)
4860 smum_send_msg_to_smc_with_parameter(hwmgr,
4861 PPSMC_MSG_MCLKDPM_SetEnabledMask,
4862 data->dpm_level_enable_mask.mclk_dpm_enable_mask & mask,
4867 uint32_t tmp = mask & data->dpm_level_enable_mask.pcie_dpm_enable_mask;
4869 if (!data->pcie_dpm_key_disabled) {
4870 if (fls(tmp) != ffs(tmp))
4871 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_PCIeDPM_UnForceLevel,
4874 smum_send_msg_to_smc_with_parameter(hwmgr,
4875 PPSMC_MSG_PCIeDPM_ForceLevel,
4888 static int smu7_print_clock_levels(struct pp_hwmgr *hwmgr,
4889 enum pp_clock_type type, char *buf)
4891 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4892 struct smu7_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
4893 struct smu7_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
4894 struct smu7_single_dpm_table *pcie_table = &(data->dpm_table.pcie_speed_table);
4895 struct smu7_odn_dpm_table *odn_table = &(data->odn_dpm_table);
4896 struct phm_odn_clock_levels *odn_sclk_table = &(odn_table->odn_core_clock_dpm_levels);
4897 struct phm_odn_clock_levels *odn_mclk_table = &(odn_table->odn_memory_clock_dpm_levels);
4898 int i, now, size = 0;
4899 uint32_t clock, pcie_speed;
4903 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_API_GetSclkFrequency, &clock);
4905 for (i = 0; i < sclk_table->count; i++) {
4906 if (clock > sclk_table->dpm_levels[i].value)
4912 for (i = 0; i < sclk_table->count; i++)
4913 size += sprintf(buf + size, "%d: %uMhz %s\n",
4914 i, sclk_table->dpm_levels[i].value / 100,
4915 (i == now) ? "*" : "");
4918 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_API_GetMclkFrequency, &clock);
4920 for (i = 0; i < mclk_table->count; i++) {
4921 if (clock > mclk_table->dpm_levels[i].value)
4927 for (i = 0; i < mclk_table->count; i++)
4928 size += sprintf(buf + size, "%d: %uMhz %s\n",
4929 i, mclk_table->dpm_levels[i].value / 100,
4930 (i == now) ? "*" : "");
4933 pcie_speed = smu7_get_current_pcie_speed(hwmgr);
4934 for (i = 0; i < pcie_table->count; i++) {
4935 if (pcie_speed != pcie_table->dpm_levels[i].value)
4941 for (i = 0; i < pcie_table->count; i++)
4942 size += sprintf(buf + size, "%d: %s %s\n", i,
4943 (pcie_table->dpm_levels[i].value == 0) ? "2.5GT/s, x8" :
4944 (pcie_table->dpm_levels[i].value == 1) ? "5.0GT/s, x16" :
4945 (pcie_table->dpm_levels[i].value == 2) ? "8.0GT/s, x16" : "",
4946 (i == now) ? "*" : "");
4949 if (hwmgr->od_enabled) {
4950 size = sprintf(buf, "%s:\n", "OD_SCLK");
4951 for (i = 0; i < odn_sclk_table->num_of_pl; i++)
4952 size += sprintf(buf + size, "%d: %10uMHz %10umV\n",
4953 i, odn_sclk_table->entries[i].clock/100,
4954 odn_sclk_table->entries[i].vddc);
4958 if (hwmgr->od_enabled) {
4959 size = sprintf(buf, "%s:\n", "OD_MCLK");
4960 for (i = 0; i < odn_mclk_table->num_of_pl; i++)
4961 size += sprintf(buf + size, "%d: %10uMHz %10umV\n",
4962 i, odn_mclk_table->entries[i].clock/100,
4963 odn_mclk_table->entries[i].vddc);
4967 if (hwmgr->od_enabled) {
4968 size = sprintf(buf, "%s:\n", "OD_RANGE");
4969 size += sprintf(buf + size, "SCLK: %7uMHz %10uMHz\n",
4970 data->golden_dpm_table.sclk_table.dpm_levels[0].value/100,
4971 hwmgr->platform_descriptor.overdriveLimit.engineClock/100);
4972 size += sprintf(buf + size, "MCLK: %7uMHz %10uMHz\n",
4973 data->golden_dpm_table.mclk_table.dpm_levels[0].value/100,
4974 hwmgr->platform_descriptor.overdriveLimit.memoryClock/100);
4975 size += sprintf(buf + size, "VDDC: %7umV %11umV\n",
4976 data->odn_dpm_table.min_vddc,
4977 data->odn_dpm_table.max_vddc);
4986 static void smu7_set_fan_control_mode(struct pp_hwmgr *hwmgr, uint32_t mode)
4989 case AMD_FAN_CTRL_NONE:
4990 smu7_fan_ctrl_set_fan_speed_percent(hwmgr, 100);
4992 case AMD_FAN_CTRL_MANUAL:
4993 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4994 PHM_PlatformCaps_MicrocodeFanControl))
4995 smu7_fan_ctrl_stop_smc_fan_control(hwmgr);
4997 case AMD_FAN_CTRL_AUTO:
4998 if (!smu7_fan_ctrl_set_static_mode(hwmgr, mode))
4999 smu7_fan_ctrl_start_smc_fan_control(hwmgr);
5006 static uint32_t smu7_get_fan_control_mode(struct pp_hwmgr *hwmgr)
5008 return hwmgr->fan_ctrl_enabled ? AMD_FAN_CTRL_AUTO : AMD_FAN_CTRL_MANUAL;
5011 static int smu7_get_sclk_od(struct pp_hwmgr *hwmgr)
5013 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5014 struct smu7_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
5015 struct smu7_single_dpm_table *golden_sclk_table =
5016 &(data->golden_dpm_table.sclk_table);
5017 int value = sclk_table->dpm_levels[sclk_table->count - 1].value;
5018 int golden_value = golden_sclk_table->dpm_levels
5019 [golden_sclk_table->count - 1].value;
5021 value -= golden_value;
5022 value = DIV_ROUND_UP(value * 100, golden_value);
5027 static int smu7_set_sclk_od(struct pp_hwmgr *hwmgr, uint32_t value)
5029 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5030 struct smu7_single_dpm_table *golden_sclk_table =
5031 &(data->golden_dpm_table.sclk_table);
5032 struct pp_power_state *ps;
5033 struct smu7_power_state *smu7_ps;
5038 ps = hwmgr->request_ps;
5043 smu7_ps = cast_phw_smu7_power_state(&ps->hardware);
5045 smu7_ps->performance_levels[smu7_ps->performance_level_count - 1].engine_clock =
5046 golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value *
5048 golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value;
5053 static int smu7_get_mclk_od(struct pp_hwmgr *hwmgr)
5055 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5056 struct smu7_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
5057 struct smu7_single_dpm_table *golden_mclk_table =
5058 &(data->golden_dpm_table.mclk_table);
5059 int value = mclk_table->dpm_levels[mclk_table->count - 1].value;
5060 int golden_value = golden_mclk_table->dpm_levels
5061 [golden_mclk_table->count - 1].value;
5063 value -= golden_value;
5064 value = DIV_ROUND_UP(value * 100, golden_value);
5069 static int smu7_set_mclk_od(struct pp_hwmgr *hwmgr, uint32_t value)
5071 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5072 struct smu7_single_dpm_table *golden_mclk_table =
5073 &(data->golden_dpm_table.mclk_table);
5074 struct pp_power_state *ps;
5075 struct smu7_power_state *smu7_ps;
5080 ps = hwmgr->request_ps;
5085 smu7_ps = cast_phw_smu7_power_state(&ps->hardware);
5087 smu7_ps->performance_levels[smu7_ps->performance_level_count - 1].memory_clock =
5088 golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value *
5090 golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value;
5096 static int smu7_get_sclks(struct pp_hwmgr *hwmgr, struct amd_pp_clocks *clocks)
5098 struct phm_ppt_v1_information *table_info =
5099 (struct phm_ppt_v1_information *)hwmgr->pptable;
5100 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table = NULL;
5101 struct phm_clock_voltage_dependency_table *sclk_table;
5104 if (hwmgr->pp_table_version == PP_TABLE_V1) {
5105 if (table_info == NULL || table_info->vdd_dep_on_sclk == NULL)
5107 dep_sclk_table = table_info->vdd_dep_on_sclk;
5108 for (i = 0; i < dep_sclk_table->count; i++)
5109 clocks->clock[i] = dep_sclk_table->entries[i].clk * 10;
5110 clocks->count = dep_sclk_table->count;
5111 } else if (hwmgr->pp_table_version == PP_TABLE_V0) {
5112 sclk_table = hwmgr->dyn_state.vddc_dependency_on_sclk;
5113 for (i = 0; i < sclk_table->count; i++)
5114 clocks->clock[i] = sclk_table->entries[i].clk * 10;
5115 clocks->count = sclk_table->count;
5121 static uint32_t smu7_get_mem_latency(struct pp_hwmgr *hwmgr, uint32_t clk)
5123 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5125 if (clk >= MEM_FREQ_LOW_LATENCY && clk < MEM_FREQ_HIGH_LATENCY)
5126 return data->mem_latency_high;
5127 else if (clk >= MEM_FREQ_HIGH_LATENCY)
5128 return data->mem_latency_low;
5130 return MEM_LATENCY_ERR;
5133 static int smu7_get_mclks(struct pp_hwmgr *hwmgr, struct amd_pp_clocks *clocks)
5135 struct phm_ppt_v1_information *table_info =
5136 (struct phm_ppt_v1_information *)hwmgr->pptable;
5137 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table;
5139 struct phm_clock_voltage_dependency_table *mclk_table;
5141 if (hwmgr->pp_table_version == PP_TABLE_V1) {
5142 if (table_info == NULL)
5144 dep_mclk_table = table_info->vdd_dep_on_mclk;
5145 for (i = 0; i < dep_mclk_table->count; i++) {
5146 clocks->clock[i] = dep_mclk_table->entries[i].clk * 10;
5147 clocks->latency[i] = smu7_get_mem_latency(hwmgr,
5148 dep_mclk_table->entries[i].clk);
5150 clocks->count = dep_mclk_table->count;
5151 } else if (hwmgr->pp_table_version == PP_TABLE_V0) {
5152 mclk_table = hwmgr->dyn_state.vddc_dependency_on_mclk;
5153 for (i = 0; i < mclk_table->count; i++)
5154 clocks->clock[i] = mclk_table->entries[i].clk * 10;
5155 clocks->count = mclk_table->count;
5160 static int smu7_get_clock_by_type(struct pp_hwmgr *hwmgr, enum amd_pp_clock_type type,
5161 struct amd_pp_clocks *clocks)
5164 case amd_pp_sys_clock:
5165 smu7_get_sclks(hwmgr, clocks);
5167 case amd_pp_mem_clock:
5168 smu7_get_mclks(hwmgr, clocks);
5177 static int smu7_get_sclks_with_latency(struct pp_hwmgr *hwmgr,
5178 struct pp_clock_levels_with_latency *clocks)
5180 struct phm_ppt_v1_information *table_info =
5181 (struct phm_ppt_v1_information *)hwmgr->pptable;
5182 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table =
5183 table_info->vdd_dep_on_sclk;
5186 clocks->num_levels = 0;
5187 for (i = 0; i < dep_sclk_table->count; i++) {
5188 if (dep_sclk_table->entries[i].clk) {
5189 clocks->data[clocks->num_levels].clocks_in_khz =
5190 dep_sclk_table->entries[i].clk * 10;
5191 clocks->num_levels++;
5198 static int smu7_get_mclks_with_latency(struct pp_hwmgr *hwmgr,
5199 struct pp_clock_levels_with_latency *clocks)
5201 struct phm_ppt_v1_information *table_info =
5202 (struct phm_ppt_v1_information *)hwmgr->pptable;
5203 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
5204 table_info->vdd_dep_on_mclk;
5205 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5208 clocks->num_levels = 0;
5209 data->mclk_latency_table.count = 0;
5210 for (i = 0; i < dep_mclk_table->count; i++) {
5211 if (dep_mclk_table->entries[i].clk) {
5212 clocks->data[clocks->num_levels].clocks_in_khz =
5213 dep_mclk_table->entries[i].clk * 10;
5214 data->mclk_latency_table.entries[data->mclk_latency_table.count].frequency =
5215 dep_mclk_table->entries[i].clk;
5216 clocks->data[clocks->num_levels].latency_in_us =
5217 data->mclk_latency_table.entries[data->mclk_latency_table.count].latency =
5218 smu7_get_mem_latency(hwmgr, dep_mclk_table->entries[i].clk);
5219 clocks->num_levels++;
5220 data->mclk_latency_table.count++;
5227 static int smu7_get_clock_by_type_with_latency(struct pp_hwmgr *hwmgr,
5228 enum amd_pp_clock_type type,
5229 struct pp_clock_levels_with_latency *clocks)
5231 if (!(hwmgr->chip_id >= CHIP_POLARIS10 &&
5232 hwmgr->chip_id <= CHIP_VEGAM))
5236 case amd_pp_sys_clock:
5237 smu7_get_sclks_with_latency(hwmgr, clocks);
5239 case amd_pp_mem_clock:
5240 smu7_get_mclks_with_latency(hwmgr, clocks);
5249 static int smu7_set_watermarks_for_clocks_ranges(struct pp_hwmgr *hwmgr,
5252 struct phm_ppt_v1_information *table_info =
5253 (struct phm_ppt_v1_information *)hwmgr->pptable;
5254 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
5255 table_info->vdd_dep_on_mclk;
5256 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table =
5257 table_info->vdd_dep_on_sclk;
5258 struct polaris10_smumgr *smu_data =
5259 (struct polaris10_smumgr *)(hwmgr->smu_backend);
5260 SMU74_Discrete_DpmTable *table = &(smu_data->smc_state_table);
5261 struct dm_pp_wm_sets_with_clock_ranges *watermarks =
5262 (struct dm_pp_wm_sets_with_clock_ranges *)clock_range;
5266 if (!(hwmgr->chip_id >= CHIP_POLARIS10 &&
5267 hwmgr->chip_id <= CHIP_VEGAM))
5270 for (i = 0; i < dep_mclk_table->count; i++) {
5271 for (j = 0; j < dep_sclk_table->count; j++) {
5272 valid_entry = false;
5273 for (k = 0; k < watermarks->num_wm_sets; k++) {
5274 if (dep_sclk_table->entries[i].clk >= watermarks->wm_clk_ranges[k].wm_min_eng_clk_in_khz / 10 &&
5275 dep_sclk_table->entries[i].clk < watermarks->wm_clk_ranges[k].wm_max_eng_clk_in_khz / 10 &&
5276 dep_mclk_table->entries[i].clk >= watermarks->wm_clk_ranges[k].wm_min_mem_clk_in_khz / 10 &&
5277 dep_mclk_table->entries[i].clk < watermarks->wm_clk_ranges[k].wm_max_mem_clk_in_khz / 10) {
5279 table->DisplayWatermark[i][j] = watermarks->wm_clk_ranges[k].wm_set_id;
5283 PP_ASSERT_WITH_CODE(valid_entry,
5284 "Clock is not in range of specified clock range for watermark from DAL! Using highest water mark set.",
5285 table->DisplayWatermark[i][j] = watermarks->wm_clk_ranges[k - 1].wm_set_id);
5289 return smu7_copy_bytes_to_smc(hwmgr,
5290 smu_data->smu7_data.dpm_table_start + offsetof(SMU74_Discrete_DpmTable, DisplayWatermark),
5291 (uint8_t *)table->DisplayWatermark,
5292 sizeof(uint8_t) * SMU74_MAX_LEVELS_MEMORY * SMU74_MAX_LEVELS_GRAPHICS,
5296 static int smu7_notify_cac_buffer_info(struct pp_hwmgr *hwmgr,
5297 uint32_t virtual_addr_low,
5298 uint32_t virtual_addr_hi,
5299 uint32_t mc_addr_low,
5300 uint32_t mc_addr_hi,
5303 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5305 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
5306 data->soft_regs_start +
5307 smum_get_offsetof(hwmgr,
5308 SMU_SoftRegisters, DRAM_LOG_ADDR_H),
5311 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
5312 data->soft_regs_start +
5313 smum_get_offsetof(hwmgr,
5314 SMU_SoftRegisters, DRAM_LOG_ADDR_L),
5317 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
5318 data->soft_regs_start +
5319 smum_get_offsetof(hwmgr,
5320 SMU_SoftRegisters, DRAM_LOG_PHY_ADDR_H),
5323 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
5324 data->soft_regs_start +
5325 smum_get_offsetof(hwmgr,
5326 SMU_SoftRegisters, DRAM_LOG_PHY_ADDR_L),
5329 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
5330 data->soft_regs_start +
5331 smum_get_offsetof(hwmgr,
5332 SMU_SoftRegisters, DRAM_LOG_BUFF_SIZE),
5337 static int smu7_get_max_high_clocks(struct pp_hwmgr *hwmgr,
5338 struct amd_pp_simple_clock_info *clocks)
5340 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5341 struct smu7_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
5342 struct smu7_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
5347 clocks->memory_max_clock = mclk_table->count > 1 ?
5348 mclk_table->dpm_levels[mclk_table->count-1].value :
5349 mclk_table->dpm_levels[0].value;
5350 clocks->engine_max_clock = sclk_table->count > 1 ?
5351 sclk_table->dpm_levels[sclk_table->count-1].value :
5352 sclk_table->dpm_levels[0].value;
5356 static int smu7_get_thermal_temperature_range(struct pp_hwmgr *hwmgr,
5357 struct PP_TemperatureRange *thermal_data)
5359 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5360 struct phm_ppt_v1_information *table_info =
5361 (struct phm_ppt_v1_information *)hwmgr->pptable;
5363 memcpy(thermal_data, &SMU7ThermalPolicy[0], sizeof(struct PP_TemperatureRange));
5365 if (hwmgr->pp_table_version == PP_TABLE_V1)
5366 thermal_data->max = table_info->cac_dtp_table->usSoftwareShutdownTemp *
5367 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
5368 else if (hwmgr->pp_table_version == PP_TABLE_V0)
5369 thermal_data->max = data->thermal_temp_setting.temperature_shutdown *
5370 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
5375 static bool smu7_check_clk_voltage_valid(struct pp_hwmgr *hwmgr,
5376 enum PP_OD_DPM_TABLE_COMMAND type,
5380 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5382 if (voltage < data->odn_dpm_table.min_vddc || voltage > data->odn_dpm_table.max_vddc) {
5383 pr_info("OD voltage is out of range [%d - %d] mV\n",
5384 data->odn_dpm_table.min_vddc,
5385 data->odn_dpm_table.max_vddc);
5389 if (type == PP_OD_EDIT_SCLK_VDDC_TABLE) {
5390 if (data->golden_dpm_table.sclk_table.dpm_levels[0].value > clk ||
5391 hwmgr->platform_descriptor.overdriveLimit.engineClock < clk) {
5392 pr_info("OD engine clock is out of range [%d - %d] MHz\n",
5393 data->golden_dpm_table.sclk_table.dpm_levels[0].value/100,
5394 hwmgr->platform_descriptor.overdriveLimit.engineClock/100);
5397 } else if (type == PP_OD_EDIT_MCLK_VDDC_TABLE) {
5398 if (data->golden_dpm_table.mclk_table.dpm_levels[0].value > clk ||
5399 hwmgr->platform_descriptor.overdriveLimit.memoryClock < clk) {
5400 pr_info("OD memory clock is out of range [%d - %d] MHz\n",
5401 data->golden_dpm_table.mclk_table.dpm_levels[0].value/100,
5402 hwmgr->platform_descriptor.overdriveLimit.memoryClock/100);
5412 static int smu7_odn_edit_dpm_table(struct pp_hwmgr *hwmgr,
5413 enum PP_OD_DPM_TABLE_COMMAND type,
5414 long *input, uint32_t size)
5417 struct phm_odn_clock_levels *podn_dpm_table_in_backend = NULL;
5418 struct smu7_odn_clock_voltage_dependency_table *podn_vdd_dep_in_backend = NULL;
5419 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5423 uint32_t input_level;
5425 PP_ASSERT_WITH_CODE(input, "NULL user input for clock and voltage",
5428 if (!hwmgr->od_enabled) {
5429 pr_info("OverDrive feature not enabled\n");
5433 if (PP_OD_EDIT_SCLK_VDDC_TABLE == type) {
5434 podn_dpm_table_in_backend = &data->odn_dpm_table.odn_core_clock_dpm_levels;
5435 podn_vdd_dep_in_backend = &data->odn_dpm_table.vdd_dependency_on_sclk;
5436 PP_ASSERT_WITH_CODE((podn_dpm_table_in_backend && podn_vdd_dep_in_backend),
5437 "Failed to get ODN SCLK and Voltage tables",
5439 } else if (PP_OD_EDIT_MCLK_VDDC_TABLE == type) {
5440 podn_dpm_table_in_backend = &data->odn_dpm_table.odn_memory_clock_dpm_levels;
5441 podn_vdd_dep_in_backend = &data->odn_dpm_table.vdd_dependency_on_mclk;
5443 PP_ASSERT_WITH_CODE((podn_dpm_table_in_backend && podn_vdd_dep_in_backend),
5444 "Failed to get ODN MCLK and Voltage tables",
5446 } else if (PP_OD_RESTORE_DEFAULT_TABLE == type) {
5447 smu7_odn_initial_default_setting(hwmgr);
5449 } else if (PP_OD_COMMIT_DPM_TABLE == type) {
5450 smu7_check_dpm_table_updated(hwmgr);
5456 for (i = 0; i < size; i += 3) {
5457 if (i + 3 > size || input[i] >= podn_dpm_table_in_backend->num_of_pl) {
5458 pr_info("invalid clock voltage input \n");
5461 input_level = input[i];
5462 input_clk = input[i+1] * 100;
5463 input_vol = input[i+2];
5465 if (smu7_check_clk_voltage_valid(hwmgr, type, input_clk, input_vol)) {
5466 podn_dpm_table_in_backend->entries[input_level].clock = input_clk;
5467 podn_vdd_dep_in_backend->entries[input_level].clk = input_clk;
5468 podn_dpm_table_in_backend->entries[input_level].vddc = input_vol;
5469 podn_vdd_dep_in_backend->entries[input_level].vddc = input_vol;
5470 podn_vdd_dep_in_backend->entries[input_level].vddgfx = input_vol;
5479 static int smu7_get_power_profile_mode(struct pp_hwmgr *hwmgr, char *buf)
5481 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5482 uint32_t i, size = 0;
5485 static const char *profile_name[7] = {"BOOTUP_DEFAULT",
5493 static const char *title[8] = {"NUM",
5497 "SCLK_ACTIVE_LEVEL",
5500 "MCLK_ACTIVE_LEVEL"};
5505 size += sprintf(buf + size, "%s %16s %16s %16s %16s %16s %16s %16s\n",
5506 title[0], title[1], title[2], title[3],
5507 title[4], title[5], title[6], title[7]);
5509 len = ARRAY_SIZE(smu7_profiling);
5511 for (i = 0; i < len; i++) {
5512 if (i == hwmgr->power_profile_mode) {
5513 size += sprintf(buf + size, "%3d %14s %s: %8d %16d %16d %16d %16d %16d\n",
5514 i, profile_name[i], "*",
5515 data->current_profile_setting.sclk_up_hyst,
5516 data->current_profile_setting.sclk_down_hyst,
5517 data->current_profile_setting.sclk_activity,
5518 data->current_profile_setting.mclk_up_hyst,
5519 data->current_profile_setting.mclk_down_hyst,
5520 data->current_profile_setting.mclk_activity);
5523 if (smu7_profiling[i].bupdate_sclk)
5524 size += sprintf(buf + size, "%3d %16s: %8d %16d %16d ",
5525 i, profile_name[i], smu7_profiling[i].sclk_up_hyst,
5526 smu7_profiling[i].sclk_down_hyst,
5527 smu7_profiling[i].sclk_activity);
5529 size += sprintf(buf + size, "%3d %16s: %8s %16s %16s ",
5530 i, profile_name[i], "-", "-", "-");
5532 if (smu7_profiling[i].bupdate_mclk)
5533 size += sprintf(buf + size, "%16d %16d %16d\n",
5534 smu7_profiling[i].mclk_up_hyst,
5535 smu7_profiling[i].mclk_down_hyst,
5536 smu7_profiling[i].mclk_activity);
5538 size += sprintf(buf + size, "%16s %16s %16s\n",
5545 static void smu7_patch_compute_profile_mode(struct pp_hwmgr *hwmgr,
5546 enum PP_SMC_POWER_PROFILE requst)
5548 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5549 uint32_t tmp, level;
5551 if (requst == PP_SMC_POWER_PROFILE_COMPUTE) {
5552 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
5554 tmp = data->dpm_level_enable_mask.sclk_dpm_enable_mask;
5558 smu7_force_clock_level(hwmgr, PP_SCLK, 3 << (level-1));
5560 } else if (hwmgr->power_profile_mode == PP_SMC_POWER_PROFILE_COMPUTE) {
5561 smu7_force_clock_level(hwmgr, PP_SCLK, data->dpm_level_enable_mask.sclk_dpm_enable_mask);
5565 static int smu7_set_power_profile_mode(struct pp_hwmgr *hwmgr, long *input, uint32_t size)
5567 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5568 struct profile_mode_setting tmp;
5569 enum PP_SMC_POWER_PROFILE mode;
5576 case PP_SMC_POWER_PROFILE_CUSTOM:
5577 if (size < 8 && size != 0)
5579 /* If only CUSTOM is passed in, use the saved values. Check
5580 * that we actually have a CUSTOM profile by ensuring that
5581 * the "use sclk" or the "use mclk" bits are set
5583 tmp = smu7_profiling[PP_SMC_POWER_PROFILE_CUSTOM];
5585 if (tmp.bupdate_sclk == 0 && tmp.bupdate_mclk == 0)
5588 tmp.bupdate_sclk = input[0];
5589 tmp.sclk_up_hyst = input[1];
5590 tmp.sclk_down_hyst = input[2];
5591 tmp.sclk_activity = input[3];
5592 tmp.bupdate_mclk = input[4];
5593 tmp.mclk_up_hyst = input[5];
5594 tmp.mclk_down_hyst = input[6];
5595 tmp.mclk_activity = input[7];
5596 smu7_profiling[PP_SMC_POWER_PROFILE_CUSTOM] = tmp;
5598 if (!smum_update_dpm_settings(hwmgr, &tmp)) {
5599 memcpy(&data->current_profile_setting, &tmp, sizeof(struct profile_mode_setting));
5600 hwmgr->power_profile_mode = mode;
5603 case PP_SMC_POWER_PROFILE_FULLSCREEN3D:
5604 case PP_SMC_POWER_PROFILE_POWERSAVING:
5605 case PP_SMC_POWER_PROFILE_VIDEO:
5606 case PP_SMC_POWER_PROFILE_VR:
5607 case PP_SMC_POWER_PROFILE_COMPUTE:
5608 if (mode == hwmgr->power_profile_mode)
5611 memcpy(&tmp, &smu7_profiling[mode], sizeof(struct profile_mode_setting));
5612 if (!smum_update_dpm_settings(hwmgr, &tmp)) {
5613 if (tmp.bupdate_sclk) {
5614 data->current_profile_setting.bupdate_sclk = tmp.bupdate_sclk;
5615 data->current_profile_setting.sclk_up_hyst = tmp.sclk_up_hyst;
5616 data->current_profile_setting.sclk_down_hyst = tmp.sclk_down_hyst;
5617 data->current_profile_setting.sclk_activity = tmp.sclk_activity;
5619 if (tmp.bupdate_mclk) {
5620 data->current_profile_setting.bupdate_mclk = tmp.bupdate_mclk;
5621 data->current_profile_setting.mclk_up_hyst = tmp.mclk_up_hyst;
5622 data->current_profile_setting.mclk_down_hyst = tmp.mclk_down_hyst;
5623 data->current_profile_setting.mclk_activity = tmp.mclk_activity;
5625 smu7_patch_compute_profile_mode(hwmgr, mode);
5626 hwmgr->power_profile_mode = mode;
5636 static int smu7_get_performance_level(struct pp_hwmgr *hwmgr, const struct pp_hw_power_state *state,
5637 PHM_PerformanceLevelDesignation designation, uint32_t index,
5638 PHM_PerformanceLevel *level)
5640 const struct smu7_power_state *ps;
5643 if (level == NULL || hwmgr == NULL || state == NULL)
5646 ps = cast_const_phw_smu7_power_state(state);
5648 i = index > ps->performance_level_count - 1 ?
5649 ps->performance_level_count - 1 : index;
5651 level->coreClock = ps->performance_levels[i].engine_clock;
5652 level->memory_clock = ps->performance_levels[i].memory_clock;
5657 static int smu7_power_off_asic(struct pp_hwmgr *hwmgr)
5661 result = smu7_disable_dpm_tasks(hwmgr);
5662 PP_ASSERT_WITH_CODE((0 == result),
5663 "[disable_dpm_tasks] Failed to disable DPM!",
5669 static const struct pp_hwmgr_func smu7_hwmgr_funcs = {
5670 .backend_init = &smu7_hwmgr_backend_init,
5671 .backend_fini = &smu7_hwmgr_backend_fini,
5672 .asic_setup = &smu7_setup_asic_task,
5673 .dynamic_state_management_enable = &smu7_enable_dpm_tasks,
5674 .apply_state_adjust_rules = smu7_apply_state_adjust_rules,
5675 .force_dpm_level = &smu7_force_dpm_level,
5676 .power_state_set = smu7_set_power_state_tasks,
5677 .get_power_state_size = smu7_get_power_state_size,
5678 .get_mclk = smu7_dpm_get_mclk,
5679 .get_sclk = smu7_dpm_get_sclk,
5680 .patch_boot_state = smu7_dpm_patch_boot_state,
5681 .get_pp_table_entry = smu7_get_pp_table_entry,
5682 .get_num_of_pp_table_entries = smu7_get_number_of_powerplay_table_entries,
5683 .powerdown_uvd = smu7_powerdown_uvd,
5684 .powergate_uvd = smu7_powergate_uvd,
5685 .powergate_vce = smu7_powergate_vce,
5686 .disable_clock_power_gating = smu7_disable_clock_power_gating,
5687 .update_clock_gatings = smu7_update_clock_gatings,
5688 .notify_smc_display_config_after_ps_adjustment = smu7_notify_smc_display_config_after_ps_adjustment,
5689 .display_config_changed = smu7_display_configuration_changed_task,
5690 .set_max_fan_pwm_output = smu7_set_max_fan_pwm_output,
5691 .set_max_fan_rpm_output = smu7_set_max_fan_rpm_output,
5692 .stop_thermal_controller = smu7_thermal_stop_thermal_controller,
5693 .get_fan_speed_info = smu7_fan_ctrl_get_fan_speed_info,
5694 .get_fan_speed_percent = smu7_fan_ctrl_get_fan_speed_percent,
5695 .set_fan_speed_percent = smu7_fan_ctrl_set_fan_speed_percent,
5696 .reset_fan_speed_to_default = smu7_fan_ctrl_reset_fan_speed_to_default,
5697 .get_fan_speed_rpm = smu7_fan_ctrl_get_fan_speed_rpm,
5698 .set_fan_speed_rpm = smu7_fan_ctrl_set_fan_speed_rpm,
5699 .uninitialize_thermal_controller = smu7_thermal_ctrl_uninitialize_thermal_controller,
5700 .register_irq_handlers = smu7_register_irq_handlers,
5701 .check_smc_update_required_for_display_configuration = smu7_check_smc_update_required_for_display_configuration,
5702 .check_states_equal = smu7_check_states_equal,
5703 .set_fan_control_mode = smu7_set_fan_control_mode,
5704 .get_fan_control_mode = smu7_get_fan_control_mode,
5705 .force_clock_level = smu7_force_clock_level,
5706 .print_clock_levels = smu7_print_clock_levels,
5707 .powergate_gfx = smu7_powergate_gfx,
5708 .get_sclk_od = smu7_get_sclk_od,
5709 .set_sclk_od = smu7_set_sclk_od,
5710 .get_mclk_od = smu7_get_mclk_od,
5711 .set_mclk_od = smu7_set_mclk_od,
5712 .get_clock_by_type = smu7_get_clock_by_type,
5713 .get_clock_by_type_with_latency = smu7_get_clock_by_type_with_latency,
5714 .set_watermarks_for_clocks_ranges = smu7_set_watermarks_for_clocks_ranges,
5715 .read_sensor = smu7_read_sensor,
5716 .dynamic_state_management_disable = smu7_disable_dpm_tasks,
5717 .avfs_control = smu7_avfs_control,
5718 .disable_smc_firmware_ctf = smu7_thermal_disable_alert,
5719 .start_thermal_controller = smu7_start_thermal_controller,
5720 .notify_cac_buffer_info = smu7_notify_cac_buffer_info,
5721 .get_max_high_clocks = smu7_get_max_high_clocks,
5722 .get_thermal_temperature_range = smu7_get_thermal_temperature_range,
5723 .odn_edit_dpm_table = smu7_odn_edit_dpm_table,
5724 .set_power_limit = smu7_set_power_limit,
5725 .get_power_profile_mode = smu7_get_power_profile_mode,
5726 .set_power_profile_mode = smu7_set_power_profile_mode,
5727 .get_performance_level = smu7_get_performance_level,
5728 .get_asic_baco_capability = smu7_baco_get_capability,
5729 .get_asic_baco_state = smu7_baco_get_state,
5730 .set_asic_baco_state = smu7_baco_set_state,
5731 .power_off_asic = smu7_power_off_asic,
5734 uint8_t smu7_get_sleep_divider_id_from_clock(uint32_t clock,
5735 uint32_t clock_insr)
5739 uint32_t min = max(clock_insr, (uint32_t)SMU7_MINIMUM_ENGINE_CLOCK);
5741 PP_ASSERT_WITH_CODE((clock >= min), "Engine clock can't satisfy stutter requirement!", return 0);
5742 for (i = SMU7_MAX_DEEPSLEEP_DIVIDER_ID; ; i--) {
5745 if (temp >= min || i == 0)
5751 int smu7_init_function_pointers(struct pp_hwmgr *hwmgr)
5753 hwmgr->hwmgr_func = &smu7_hwmgr_funcs;
5754 if (hwmgr->pp_table_version == PP_TABLE_V0)
5755 hwmgr->pptable_func = &pptable_funcs;
5756 else if (hwmgr->pp_table_version == PP_TABLE_V1)
5757 hwmgr->pptable_func = &pptable_v1_0_funcs;