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 * Find the MC microcode version and store it in the HwMgr struct
198 * @param 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 * Enable voltage control
238 * @param pHwMgr 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 * Checks if we want to support voltage control
260 * @param 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 * Enable voltage control
273 * @param 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 * Create Voltage Tables.
311 * @param 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 * Programs static screed detection parameters
423 * @param 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 * Setup display gap for glitch free memory clock switching.
446 * @param 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 * Programs activity state transition voting clients
470 * @param 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 * Initial switch from ARB F0->F1
565 * @param 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 int smu7_setup_default_pcie_table(struct pp_hwmgr *hwmgr)
592 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
594 struct phm_ppt_v1_information *table_info =
595 (struct phm_ppt_v1_information *)(hwmgr->pptable);
596 struct phm_ppt_v1_pcie_table *pcie_table = NULL;
598 uint32_t i, max_entry;
601 PP_ASSERT_WITH_CODE((data->use_pcie_performance_levels ||
602 data->use_pcie_power_saving_levels), "No pcie performance levels!",
605 if (table_info != NULL)
606 pcie_table = table_info->pcie_table;
608 if (data->use_pcie_performance_levels &&
609 !data->use_pcie_power_saving_levels) {
610 data->pcie_gen_power_saving = data->pcie_gen_performance;
611 data->pcie_lane_power_saving = data->pcie_lane_performance;
612 } else if (!data->use_pcie_performance_levels &&
613 data->use_pcie_power_saving_levels) {
614 data->pcie_gen_performance = data->pcie_gen_power_saving;
615 data->pcie_lane_performance = data->pcie_lane_power_saving;
617 tmp = smum_get_mac_definition(hwmgr, SMU_MAX_LEVELS_LINK);
618 phm_reset_single_dpm_table(&data->dpm_table.pcie_speed_table,
620 MAX_REGULAR_DPM_NUMBER);
622 if (pcie_table != NULL) {
623 /* max_entry is used to make sure we reserve one PCIE level
624 * for boot level (fix for A+A PSPP issue).
625 * If PCIE table from PPTable have ULV entry + 8 entries,
626 * then ignore the last entry.*/
627 max_entry = (tmp < pcie_table->count) ? tmp : pcie_table->count;
628 for (i = 1; i < max_entry; i++) {
629 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, i - 1,
630 get_pcie_gen_support(data->pcie_gen_cap,
631 pcie_table->entries[i].gen_speed),
632 get_pcie_lane_support(data->pcie_lane_cap,
633 pcie_table->entries[i].lane_width));
635 data->dpm_table.pcie_speed_table.count = max_entry - 1;
636 smum_update_smc_table(hwmgr, SMU_BIF_TABLE);
638 /* Hardcode Pcie Table */
639 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 0,
640 get_pcie_gen_support(data->pcie_gen_cap,
642 get_pcie_lane_support(data->pcie_lane_cap,
644 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 1,
645 get_pcie_gen_support(data->pcie_gen_cap,
647 get_pcie_lane_support(data->pcie_lane_cap,
649 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 2,
650 get_pcie_gen_support(data->pcie_gen_cap,
652 get_pcie_lane_support(data->pcie_lane_cap,
654 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 3,
655 get_pcie_gen_support(data->pcie_gen_cap,
657 get_pcie_lane_support(data->pcie_lane_cap,
659 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 4,
660 get_pcie_gen_support(data->pcie_gen_cap,
662 get_pcie_lane_support(data->pcie_lane_cap,
664 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 5,
665 get_pcie_gen_support(data->pcie_gen_cap,
667 get_pcie_lane_support(data->pcie_lane_cap,
670 data->dpm_table.pcie_speed_table.count = 6;
672 /* Populate last level for boot PCIE level, but do not increment count. */
673 if (hwmgr->chip_family == AMDGPU_FAMILY_CI) {
674 for (i = 0; i <= data->dpm_table.pcie_speed_table.count; i++)
675 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, i,
676 get_pcie_gen_support(data->pcie_gen_cap,
678 data->vbios_boot_state.pcie_lane_bootup_value);
680 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table,
681 data->dpm_table.pcie_speed_table.count,
682 get_pcie_gen_support(data->pcie_gen_cap,
684 get_pcie_lane_support(data->pcie_lane_cap,
690 static int smu7_reset_dpm_tables(struct pp_hwmgr *hwmgr)
692 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
694 memset(&(data->dpm_table), 0x00, sizeof(data->dpm_table));
696 phm_reset_single_dpm_table(
697 &data->dpm_table.sclk_table,
698 smum_get_mac_definition(hwmgr,
699 SMU_MAX_LEVELS_GRAPHICS),
700 MAX_REGULAR_DPM_NUMBER);
701 phm_reset_single_dpm_table(
702 &data->dpm_table.mclk_table,
703 smum_get_mac_definition(hwmgr,
704 SMU_MAX_LEVELS_MEMORY), MAX_REGULAR_DPM_NUMBER);
706 phm_reset_single_dpm_table(
707 &data->dpm_table.vddc_table,
708 smum_get_mac_definition(hwmgr,
709 SMU_MAX_LEVELS_VDDC),
710 MAX_REGULAR_DPM_NUMBER);
711 phm_reset_single_dpm_table(
712 &data->dpm_table.vddci_table,
713 smum_get_mac_definition(hwmgr,
714 SMU_MAX_LEVELS_VDDCI), MAX_REGULAR_DPM_NUMBER);
716 phm_reset_single_dpm_table(
717 &data->dpm_table.mvdd_table,
718 smum_get_mac_definition(hwmgr,
719 SMU_MAX_LEVELS_MVDD),
720 MAX_REGULAR_DPM_NUMBER);
724 * This function is to initialize all DPM state tables
725 * for SMU7 based on the dependency table.
726 * Dynamic state patching function will then trim these
727 * state tables to the allowed range based
728 * on the power policy or external client requests,
729 * such as UVD request, etc.
732 static int smu7_setup_dpm_tables_v0(struct pp_hwmgr *hwmgr)
734 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
735 struct phm_clock_voltage_dependency_table *allowed_vdd_sclk_table =
736 hwmgr->dyn_state.vddc_dependency_on_sclk;
737 struct phm_clock_voltage_dependency_table *allowed_vdd_mclk_table =
738 hwmgr->dyn_state.vddc_dependency_on_mclk;
739 struct phm_cac_leakage_table *std_voltage_table =
740 hwmgr->dyn_state.cac_leakage_table;
743 PP_ASSERT_WITH_CODE(allowed_vdd_sclk_table != NULL,
744 "SCLK dependency table is missing. This table is mandatory", return -EINVAL);
745 PP_ASSERT_WITH_CODE(allowed_vdd_sclk_table->count >= 1,
746 "SCLK dependency table has to have is missing. This table is mandatory", return -EINVAL);
748 PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table != NULL,
749 "MCLK dependency table is missing. This table is mandatory", return -EINVAL);
750 PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table->count >= 1,
751 "VMCLK dependency table has to have is missing. This table is mandatory", return -EINVAL);
754 /* Initialize Sclk DPM table based on allow Sclk values*/
755 data->dpm_table.sclk_table.count = 0;
757 for (i = 0; i < allowed_vdd_sclk_table->count; i++) {
758 if (i == 0 || data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count-1].value !=
759 allowed_vdd_sclk_table->entries[i].clk) {
760 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].value =
761 allowed_vdd_sclk_table->entries[i].clk;
762 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].enabled = (i == 0) ? 1 : 0;
763 data->dpm_table.sclk_table.count++;
767 PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table != NULL,
768 "MCLK dependency table is missing. This table is mandatory", return -EINVAL);
769 /* Initialize Mclk DPM table based on allow Mclk values */
770 data->dpm_table.mclk_table.count = 0;
771 for (i = 0; i < allowed_vdd_mclk_table->count; i++) {
772 if (i == 0 || data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count-1].value !=
773 allowed_vdd_mclk_table->entries[i].clk) {
774 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].value =
775 allowed_vdd_mclk_table->entries[i].clk;
776 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].enabled = (i == 0) ? 1 : 0;
777 data->dpm_table.mclk_table.count++;
781 /* Initialize Vddc DPM table based on allow Vddc values. And populate corresponding std values. */
782 for (i = 0; i < allowed_vdd_sclk_table->count; i++) {
783 data->dpm_table.vddc_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].v;
784 data->dpm_table.vddc_table.dpm_levels[i].param1 = std_voltage_table->entries[i].Leakage;
785 /* param1 is for corresponding std voltage */
786 data->dpm_table.vddc_table.dpm_levels[i].enabled = true;
789 data->dpm_table.vddc_table.count = allowed_vdd_sclk_table->count;
790 allowed_vdd_mclk_table = hwmgr->dyn_state.vddci_dependency_on_mclk;
792 if (NULL != allowed_vdd_mclk_table) {
793 /* Initialize Vddci DPM table based on allow Mclk values */
794 for (i = 0; i < allowed_vdd_mclk_table->count; i++) {
795 data->dpm_table.vddci_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].v;
796 data->dpm_table.vddci_table.dpm_levels[i].enabled = true;
798 data->dpm_table.vddci_table.count = allowed_vdd_mclk_table->count;
801 allowed_vdd_mclk_table = hwmgr->dyn_state.mvdd_dependency_on_mclk;
803 if (NULL != allowed_vdd_mclk_table) {
805 * Initialize MVDD DPM table based on allow Mclk
808 for (i = 0; i < allowed_vdd_mclk_table->count; i++) {
809 data->dpm_table.mvdd_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].v;
810 data->dpm_table.mvdd_table.dpm_levels[i].enabled = true;
812 data->dpm_table.mvdd_table.count = allowed_vdd_mclk_table->count;
818 static int smu7_setup_dpm_tables_v1(struct pp_hwmgr *hwmgr)
820 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
821 struct phm_ppt_v1_information *table_info =
822 (struct phm_ppt_v1_information *)(hwmgr->pptable);
825 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table;
826 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table;
828 if (table_info == NULL)
831 dep_sclk_table = table_info->vdd_dep_on_sclk;
832 dep_mclk_table = table_info->vdd_dep_on_mclk;
834 PP_ASSERT_WITH_CODE(dep_sclk_table != NULL,
835 "SCLK dependency table is missing.",
837 PP_ASSERT_WITH_CODE(dep_sclk_table->count >= 1,
838 "SCLK dependency table count is 0.",
841 PP_ASSERT_WITH_CODE(dep_mclk_table != NULL,
842 "MCLK dependency table is missing.",
844 PP_ASSERT_WITH_CODE(dep_mclk_table->count >= 1,
845 "MCLK dependency table count is 0",
848 /* Initialize Sclk DPM table based on allow Sclk values */
849 data->dpm_table.sclk_table.count = 0;
850 for (i = 0; i < dep_sclk_table->count; i++) {
851 if (i == 0 || data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count - 1].value !=
852 dep_sclk_table->entries[i].clk) {
854 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].value =
855 dep_sclk_table->entries[i].clk;
857 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].enabled =
858 (i == 0) ? true : false;
859 data->dpm_table.sclk_table.count++;
862 if (hwmgr->platform_descriptor.overdriveLimit.engineClock == 0)
863 hwmgr->platform_descriptor.overdriveLimit.engineClock = dep_sclk_table->entries[i-1].clk;
864 /* Initialize Mclk DPM table based on allow Mclk values */
865 data->dpm_table.mclk_table.count = 0;
866 for (i = 0; i < dep_mclk_table->count; i++) {
867 if (i == 0 || data->dpm_table.mclk_table.dpm_levels
868 [data->dpm_table.mclk_table.count - 1].value !=
869 dep_mclk_table->entries[i].clk) {
870 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].value =
871 dep_mclk_table->entries[i].clk;
872 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].enabled =
873 (i == 0) ? true : false;
874 data->dpm_table.mclk_table.count++;
878 if (hwmgr->platform_descriptor.overdriveLimit.memoryClock == 0)
879 hwmgr->platform_descriptor.overdriveLimit.memoryClock = dep_mclk_table->entries[i-1].clk;
883 static int smu7_odn_initial_default_setting(struct pp_hwmgr *hwmgr)
885 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
886 struct smu7_odn_dpm_table *odn_table = &(data->odn_dpm_table);
887 struct phm_ppt_v1_information *table_info =
888 (struct phm_ppt_v1_information *)(hwmgr->pptable);
891 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table;
892 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table;
893 struct phm_odn_performance_level *entries;
895 if (table_info == NULL)
898 dep_sclk_table = table_info->vdd_dep_on_sclk;
899 dep_mclk_table = table_info->vdd_dep_on_mclk;
901 odn_table->odn_core_clock_dpm_levels.num_of_pl =
902 data->golden_dpm_table.sclk_table.count;
903 entries = odn_table->odn_core_clock_dpm_levels.entries;
904 for (i=0; i<data->golden_dpm_table.sclk_table.count; i++) {
905 entries[i].clock = data->golden_dpm_table.sclk_table.dpm_levels[i].value;
906 entries[i].enabled = true;
907 entries[i].vddc = dep_sclk_table->entries[i].vddc;
910 smu_get_voltage_dependency_table_ppt_v1(dep_sclk_table,
911 (struct phm_ppt_v1_clock_voltage_dependency_table *)&(odn_table->vdd_dependency_on_sclk));
913 odn_table->odn_memory_clock_dpm_levels.num_of_pl =
914 data->golden_dpm_table.mclk_table.count;
915 entries = odn_table->odn_memory_clock_dpm_levels.entries;
916 for (i=0; i<data->golden_dpm_table.mclk_table.count; i++) {
917 entries[i].clock = data->golden_dpm_table.mclk_table.dpm_levels[i].value;
918 entries[i].enabled = true;
919 entries[i].vddc = dep_mclk_table->entries[i].vddc;
922 smu_get_voltage_dependency_table_ppt_v1(dep_mclk_table,
923 (struct phm_ppt_v1_clock_voltage_dependency_table *)&(odn_table->vdd_dependency_on_mclk));
928 static void smu7_setup_voltage_range_from_vbios(struct pp_hwmgr *hwmgr)
930 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
931 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table;
932 struct phm_ppt_v1_information *table_info =
933 (struct phm_ppt_v1_information *)(hwmgr->pptable);
934 uint32_t min_vddc = 0;
935 uint32_t max_vddc = 0;
940 dep_sclk_table = table_info->vdd_dep_on_sclk;
942 atomctrl_get_voltage_range(hwmgr, &max_vddc, &min_vddc);
944 if (min_vddc == 0 || min_vddc > 2000
945 || min_vddc > dep_sclk_table->entries[0].vddc)
946 min_vddc = dep_sclk_table->entries[0].vddc;
948 if (max_vddc == 0 || max_vddc > 2000
949 || max_vddc < dep_sclk_table->entries[dep_sclk_table->count-1].vddc)
950 max_vddc = dep_sclk_table->entries[dep_sclk_table->count-1].vddc;
952 data->odn_dpm_table.min_vddc = min_vddc;
953 data->odn_dpm_table.max_vddc = max_vddc;
956 static void smu7_check_dpm_table_updated(struct pp_hwmgr *hwmgr)
958 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
959 struct smu7_odn_dpm_table *odn_table = &(data->odn_dpm_table);
960 struct phm_ppt_v1_information *table_info =
961 (struct phm_ppt_v1_information *)(hwmgr->pptable);
964 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table;
965 struct phm_ppt_v1_clock_voltage_dependency_table *odn_dep_table;
967 if (table_info == NULL)
970 for (i = 0; i < data->dpm_table.sclk_table.count; i++) {
971 if (odn_table->odn_core_clock_dpm_levels.entries[i].clock !=
972 data->dpm_table.sclk_table.dpm_levels[i].value) {
973 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK;
978 for (i = 0; i < data->dpm_table.mclk_table.count; i++) {
979 if (odn_table->odn_memory_clock_dpm_levels.entries[i].clock !=
980 data->dpm_table.mclk_table.dpm_levels[i].value) {
981 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_MCLK;
986 dep_table = table_info->vdd_dep_on_mclk;
987 odn_dep_table = (struct phm_ppt_v1_clock_voltage_dependency_table *)&(odn_table->vdd_dependency_on_mclk);
989 for (i = 0; i < dep_table->count; i++) {
990 if (dep_table->entries[i].vddc != odn_dep_table->entries[i].vddc) {
991 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_VDDC | DPMTABLE_OD_UPDATE_MCLK;
996 dep_table = table_info->vdd_dep_on_sclk;
997 odn_dep_table = (struct phm_ppt_v1_clock_voltage_dependency_table *)&(odn_table->vdd_dependency_on_sclk);
998 for (i = 0; i < dep_table->count; i++) {
999 if (dep_table->entries[i].vddc != odn_dep_table->entries[i].vddc) {
1000 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_VDDC | DPMTABLE_OD_UPDATE_SCLK;
1004 if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_VDDC) {
1005 data->need_update_smu7_dpm_table &= ~DPMTABLE_OD_UPDATE_VDDC;
1006 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK | DPMTABLE_OD_UPDATE_MCLK;
1010 static int smu7_setup_default_dpm_tables(struct pp_hwmgr *hwmgr)
1012 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1014 smu7_reset_dpm_tables(hwmgr);
1016 if (hwmgr->pp_table_version == PP_TABLE_V1)
1017 smu7_setup_dpm_tables_v1(hwmgr);
1018 else if (hwmgr->pp_table_version == PP_TABLE_V0)
1019 smu7_setup_dpm_tables_v0(hwmgr);
1021 smu7_setup_default_pcie_table(hwmgr);
1023 /* save a copy of the default DPM table */
1024 memcpy(&(data->golden_dpm_table), &(data->dpm_table),
1025 sizeof(struct smu7_dpm_table));
1027 /* initialize ODN table */
1028 if (hwmgr->od_enabled) {
1029 if (data->odn_dpm_table.max_vddc) {
1030 smu7_check_dpm_table_updated(hwmgr);
1032 smu7_setup_voltage_range_from_vbios(hwmgr);
1033 smu7_odn_initial_default_setting(hwmgr);
1039 static int smu7_enable_vrhot_gpio_interrupt(struct pp_hwmgr *hwmgr)
1042 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1043 PHM_PlatformCaps_RegulatorHot))
1044 return smum_send_msg_to_smc(hwmgr,
1045 PPSMC_MSG_EnableVRHotGPIOInterrupt,
1051 static int smu7_enable_sclk_control(struct pp_hwmgr *hwmgr)
1053 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
1054 SCLK_PWRMGT_OFF, 0);
1058 static int smu7_enable_ulv(struct pp_hwmgr *hwmgr)
1060 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1062 if (data->ulv_supported)
1063 return smum_send_msg_to_smc(hwmgr, PPSMC_MSG_EnableULV, NULL);
1068 static int smu7_disable_ulv(struct pp_hwmgr *hwmgr)
1070 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1072 if (data->ulv_supported)
1073 return smum_send_msg_to_smc(hwmgr, PPSMC_MSG_DisableULV, NULL);
1078 static int smu7_enable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
1080 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1081 PHM_PlatformCaps_SclkDeepSleep)) {
1082 if (smum_send_msg_to_smc(hwmgr, PPSMC_MSG_MASTER_DeepSleep_ON, NULL))
1083 PP_ASSERT_WITH_CODE(false,
1084 "Attempt to enable Master Deep Sleep switch failed!",
1087 if (smum_send_msg_to_smc(hwmgr,
1088 PPSMC_MSG_MASTER_DeepSleep_OFF,
1090 PP_ASSERT_WITH_CODE(false,
1091 "Attempt to disable Master Deep Sleep switch failed!",
1099 static int smu7_disable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
1101 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1102 PHM_PlatformCaps_SclkDeepSleep)) {
1103 if (smum_send_msg_to_smc(hwmgr,
1104 PPSMC_MSG_MASTER_DeepSleep_OFF,
1106 PP_ASSERT_WITH_CODE(false,
1107 "Attempt to disable Master Deep Sleep switch failed!",
1115 static int smu7_disable_sclk_vce_handshake(struct pp_hwmgr *hwmgr)
1117 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1118 uint32_t soft_register_value = 0;
1119 uint32_t handshake_disables_offset = data->soft_regs_start
1120 + smum_get_offsetof(hwmgr,
1121 SMU_SoftRegisters, HandshakeDisables);
1123 soft_register_value = cgs_read_ind_register(hwmgr->device,
1124 CGS_IND_REG__SMC, handshake_disables_offset);
1125 soft_register_value |= SMU7_VCE_SCLK_HANDSHAKE_DISABLE;
1126 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1127 handshake_disables_offset, soft_register_value);
1131 static int smu7_disable_handshake_uvd(struct pp_hwmgr *hwmgr)
1133 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1134 uint32_t soft_register_value = 0;
1135 uint32_t handshake_disables_offset = data->soft_regs_start
1136 + smum_get_offsetof(hwmgr,
1137 SMU_SoftRegisters, HandshakeDisables);
1139 soft_register_value = cgs_read_ind_register(hwmgr->device,
1140 CGS_IND_REG__SMC, handshake_disables_offset);
1141 soft_register_value |= smum_get_mac_definition(hwmgr,
1142 SMU_UVD_MCLK_HANDSHAKE_DISABLE);
1143 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1144 handshake_disables_offset, soft_register_value);
1148 static int smu7_enable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
1150 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1152 /* enable SCLK dpm */
1153 if (!data->sclk_dpm_key_disabled) {
1154 if (hwmgr->chip_id >= CHIP_POLARIS10 &&
1155 hwmgr->chip_id <= CHIP_VEGAM)
1156 smu7_disable_sclk_vce_handshake(hwmgr);
1158 PP_ASSERT_WITH_CODE(
1159 (0 == smum_send_msg_to_smc(hwmgr, PPSMC_MSG_DPM_Enable, NULL)),
1160 "Failed to enable SCLK DPM during DPM Start Function!",
1164 /* enable MCLK dpm */
1165 if (0 == data->mclk_dpm_key_disabled) {
1166 if (!(hwmgr->feature_mask & PP_UVD_HANDSHAKE_MASK))
1167 smu7_disable_handshake_uvd(hwmgr);
1169 PP_ASSERT_WITH_CODE(
1170 (0 == smum_send_msg_to_smc(hwmgr,
1171 PPSMC_MSG_MCLKDPM_Enable,
1173 "Failed to enable MCLK DPM during DPM Start Function!",
1176 if ((hwmgr->chip_family == AMDGPU_FAMILY_CI) ||
1177 (hwmgr->chip_id == CHIP_POLARIS10) ||
1178 (hwmgr->chip_id == CHIP_POLARIS11) ||
1179 (hwmgr->chip_id == CHIP_POLARIS12) ||
1180 (hwmgr->chip_id == CHIP_TONGA))
1181 PHM_WRITE_FIELD(hwmgr->device, MC_SEQ_CNTL_3, CAC_EN, 0x1);
1184 if (hwmgr->chip_family == AMDGPU_FAMILY_CI) {
1185 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, 0xc0400d30, 0x5);
1186 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, 0xc0400d3c, 0x5);
1187 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, 0xc0400d80, 0x100005);
1189 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, 0xc0400d30, 0x400005);
1190 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, 0xc0400d3c, 0x400005);
1191 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, 0xc0400d80, 0x500005);
1193 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC0_CNTL, 0x5);
1194 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC1_CNTL, 0x5);
1195 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_CPL_CNTL, 0x100005);
1197 if (hwmgr->chip_id == CHIP_VEGAM) {
1198 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC0_CNTL, 0x400009);
1199 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC1_CNTL, 0x400009);
1201 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC0_CNTL, 0x400005);
1202 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC1_CNTL, 0x400005);
1204 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_CPL_CNTL, 0x500005);
1211 static int smu7_start_dpm(struct pp_hwmgr *hwmgr)
1213 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1215 /*enable general power management */
1217 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
1218 GLOBAL_PWRMGT_EN, 1);
1220 /* enable sclk deep sleep */
1222 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
1225 /* prepare for PCIE DPM */
1227 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1228 data->soft_regs_start +
1229 smum_get_offsetof(hwmgr, SMU_SoftRegisters,
1230 VoltageChangeTimeout), 0x1000);
1231 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE,
1232 SWRST_COMMAND_1, RESETLC, 0x0);
1234 if (hwmgr->chip_family == AMDGPU_FAMILY_CI)
1235 cgs_write_register(hwmgr->device, 0x1488,
1236 (cgs_read_register(hwmgr->device, 0x1488) & ~0x1));
1238 if (smu7_enable_sclk_mclk_dpm(hwmgr)) {
1239 pr_err("Failed to enable Sclk DPM and Mclk DPM!");
1243 /* enable PCIE dpm */
1244 if (0 == data->pcie_dpm_key_disabled) {
1245 PP_ASSERT_WITH_CODE(
1246 (0 == smum_send_msg_to_smc(hwmgr,
1247 PPSMC_MSG_PCIeDPM_Enable,
1249 "Failed to enable pcie DPM during DPM Start Function!",
1253 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1254 PHM_PlatformCaps_Falcon_QuickTransition)) {
1255 PP_ASSERT_WITH_CODE((0 == smum_send_msg_to_smc(hwmgr,
1256 PPSMC_MSG_EnableACDCGPIOInterrupt,
1258 "Failed to enable AC DC GPIO Interrupt!",
1265 static int smu7_disable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
1267 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1269 /* disable SCLK dpm */
1270 if (!data->sclk_dpm_key_disabled) {
1271 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
1272 "Trying to disable SCLK DPM when DPM is disabled",
1274 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_DPM_Disable, NULL);
1277 /* disable MCLK dpm */
1278 if (!data->mclk_dpm_key_disabled) {
1279 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
1280 "Trying to disable MCLK DPM when DPM is disabled",
1282 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_MCLKDPM_Disable, NULL);
1288 static int smu7_stop_dpm(struct pp_hwmgr *hwmgr)
1290 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1292 /* disable general power management */
1293 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
1294 GLOBAL_PWRMGT_EN, 0);
1295 /* disable sclk deep sleep */
1296 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
1299 /* disable PCIE dpm */
1300 if (!data->pcie_dpm_key_disabled) {
1301 PP_ASSERT_WITH_CODE(
1302 (smum_send_msg_to_smc(hwmgr,
1303 PPSMC_MSG_PCIeDPM_Disable,
1305 "Failed to disable pcie DPM during DPM Stop Function!",
1309 smu7_disable_sclk_mclk_dpm(hwmgr);
1311 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
1312 "Trying to disable voltage DPM when DPM is disabled",
1315 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_Voltage_Cntl_Disable, NULL);
1320 static void smu7_set_dpm_event_sources(struct pp_hwmgr *hwmgr, uint32_t sources)
1323 enum DPM_EVENT_SRC src;
1327 pr_err("Unknown throttling event sources.");
1333 case (1 << PHM_AutoThrottleSource_Thermal):
1335 src = DPM_EVENT_SRC_DIGITAL;
1337 case (1 << PHM_AutoThrottleSource_External):
1339 src = DPM_EVENT_SRC_EXTERNAL;
1341 case (1 << PHM_AutoThrottleSource_External) |
1342 (1 << PHM_AutoThrottleSource_Thermal):
1344 src = DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL;
1347 /* Order matters - don't enable thermal protection for the wrong source. */
1349 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_THERMAL_CTRL,
1350 DPM_EVENT_SRC, src);
1351 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
1352 THERMAL_PROTECTION_DIS,
1353 !phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1354 PHM_PlatformCaps_ThermalController));
1356 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
1357 THERMAL_PROTECTION_DIS, 1);
1360 static int smu7_enable_auto_throttle_source(struct pp_hwmgr *hwmgr,
1361 PHM_AutoThrottleSource source)
1363 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1365 if (!(data->active_auto_throttle_sources & (1 << source))) {
1366 data->active_auto_throttle_sources |= 1 << source;
1367 smu7_set_dpm_event_sources(hwmgr, data->active_auto_throttle_sources);
1372 static int smu7_enable_thermal_auto_throttle(struct pp_hwmgr *hwmgr)
1374 return smu7_enable_auto_throttle_source(hwmgr, PHM_AutoThrottleSource_Thermal);
1377 static int smu7_disable_auto_throttle_source(struct pp_hwmgr *hwmgr,
1378 PHM_AutoThrottleSource source)
1380 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1382 if (data->active_auto_throttle_sources & (1 << source)) {
1383 data->active_auto_throttle_sources &= ~(1 << source);
1384 smu7_set_dpm_event_sources(hwmgr, data->active_auto_throttle_sources);
1389 static int smu7_disable_thermal_auto_throttle(struct pp_hwmgr *hwmgr)
1391 return smu7_disable_auto_throttle_source(hwmgr, PHM_AutoThrottleSource_Thermal);
1394 static int smu7_pcie_performance_request(struct pp_hwmgr *hwmgr)
1396 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1397 data->pcie_performance_request = true;
1402 static int smu7_program_edc_didt_registers(struct pp_hwmgr *hwmgr,
1403 uint32_t *cac_config_regs,
1404 AtomCtrl_EDCLeakgeTable *edc_leakage_table)
1406 uint32_t data, i = 0;
1408 while (cac_config_regs[i] != 0xFFFFFFFF) {
1409 data = edc_leakage_table->DIDT_REG[i];
1410 cgs_write_ind_register(hwmgr->device,
1420 static int smu7_populate_edc_leakage_registers(struct pp_hwmgr *hwmgr)
1422 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1425 if (!data->disable_edc_leakage_controller &&
1426 data->edc_hilo_leakage_offset_from_vbios.usEdcDidtLoDpm7TableOffset &&
1427 data->edc_hilo_leakage_offset_from_vbios.usEdcDidtHiDpm7TableOffset) {
1428 ret = smu7_program_edc_didt_registers(hwmgr,
1430 &data->edc_leakage_table);
1434 ret = smum_send_msg_to_smc(hwmgr,
1435 (PPSMC_Msg)PPSMC_MSG_EnableEDCController,
1438 ret = smum_send_msg_to_smc(hwmgr,
1439 (PPSMC_Msg)PPSMC_MSG_DisableEDCController,
1446 static int smu7_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
1451 if (smu7_voltage_control(hwmgr)) {
1452 tmp_result = smu7_enable_voltage_control(hwmgr);
1453 PP_ASSERT_WITH_CODE(tmp_result == 0,
1454 "Failed to enable voltage control!",
1455 result = tmp_result);
1457 tmp_result = smu7_construct_voltage_tables(hwmgr);
1458 PP_ASSERT_WITH_CODE((0 == tmp_result),
1459 "Failed to construct voltage tables!",
1460 result = tmp_result);
1462 smum_initialize_mc_reg_table(hwmgr);
1464 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1465 PHM_PlatformCaps_EngineSpreadSpectrumSupport))
1466 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1467 GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, 1);
1469 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1470 PHM_PlatformCaps_ThermalController))
1471 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1472 GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, 0);
1474 tmp_result = smu7_program_static_screen_threshold_parameters(hwmgr);
1475 PP_ASSERT_WITH_CODE((0 == tmp_result),
1476 "Failed to program static screen threshold parameters!",
1477 result = tmp_result);
1479 tmp_result = smu7_enable_display_gap(hwmgr);
1480 PP_ASSERT_WITH_CODE((0 == tmp_result),
1481 "Failed to enable display gap!", result = tmp_result);
1483 tmp_result = smu7_program_voting_clients(hwmgr);
1484 PP_ASSERT_WITH_CODE((0 == tmp_result),
1485 "Failed to program voting clients!", result = tmp_result);
1487 tmp_result = smum_process_firmware_header(hwmgr);
1488 PP_ASSERT_WITH_CODE((0 == tmp_result),
1489 "Failed to process firmware header!", result = tmp_result);
1491 if (hwmgr->chip_id != CHIP_VEGAM) {
1492 tmp_result = smu7_initial_switch_from_arbf0_to_f1(hwmgr);
1493 PP_ASSERT_WITH_CODE((0 == tmp_result),
1494 "Failed to initialize switch from ArbF0 to F1!",
1495 result = tmp_result);
1498 result = smu7_setup_default_dpm_tables(hwmgr);
1499 PP_ASSERT_WITH_CODE(0 == result,
1500 "Failed to setup default DPM tables!", return result);
1502 tmp_result = smum_init_smc_table(hwmgr);
1503 PP_ASSERT_WITH_CODE((0 == tmp_result),
1504 "Failed to initialize SMC table!", result = tmp_result);
1506 tmp_result = smu7_enable_vrhot_gpio_interrupt(hwmgr);
1507 PP_ASSERT_WITH_CODE((0 == tmp_result),
1508 "Failed to enable VR hot GPIO interrupt!", result = tmp_result);
1510 if (hwmgr->chip_id >= CHIP_POLARIS10 &&
1511 hwmgr->chip_id <= CHIP_VEGAM) {
1512 tmp_result = smu7_notify_has_display(hwmgr);
1513 PP_ASSERT_WITH_CODE((0 == tmp_result),
1514 "Failed to enable display setting!", result = tmp_result);
1516 smum_send_msg_to_smc(hwmgr, (PPSMC_Msg)PPSMC_NoDisplay, NULL);
1519 if (hwmgr->chip_id >= CHIP_POLARIS10 &&
1520 hwmgr->chip_id <= CHIP_VEGAM) {
1521 tmp_result = smu7_populate_edc_leakage_registers(hwmgr);
1522 PP_ASSERT_WITH_CODE((0 == tmp_result),
1523 "Failed to populate edc leakage registers!", result = tmp_result);
1526 tmp_result = smu7_enable_sclk_control(hwmgr);
1527 PP_ASSERT_WITH_CODE((0 == tmp_result),
1528 "Failed to enable SCLK control!", result = tmp_result);
1530 tmp_result = smu7_enable_smc_voltage_controller(hwmgr);
1531 PP_ASSERT_WITH_CODE((0 == tmp_result),
1532 "Failed to enable voltage control!", result = tmp_result);
1534 tmp_result = smu7_enable_ulv(hwmgr);
1535 PP_ASSERT_WITH_CODE((0 == tmp_result),
1536 "Failed to enable ULV!", result = tmp_result);
1538 tmp_result = smu7_enable_deep_sleep_master_switch(hwmgr);
1539 PP_ASSERT_WITH_CODE((0 == tmp_result),
1540 "Failed to enable deep sleep master switch!", result = tmp_result);
1542 tmp_result = smu7_enable_didt_config(hwmgr);
1543 PP_ASSERT_WITH_CODE((tmp_result == 0),
1544 "Failed to enable deep sleep master switch!", result = tmp_result);
1546 tmp_result = smu7_start_dpm(hwmgr);
1547 PP_ASSERT_WITH_CODE((0 == tmp_result),
1548 "Failed to start DPM!", result = tmp_result);
1550 tmp_result = smu7_enable_smc_cac(hwmgr);
1551 PP_ASSERT_WITH_CODE((0 == tmp_result),
1552 "Failed to enable SMC CAC!", result = tmp_result);
1554 tmp_result = smu7_enable_power_containment(hwmgr);
1555 PP_ASSERT_WITH_CODE((0 == tmp_result),
1556 "Failed to enable power containment!", result = tmp_result);
1558 tmp_result = smu7_power_control_set_level(hwmgr);
1559 PP_ASSERT_WITH_CODE((0 == tmp_result),
1560 "Failed to power control set level!", result = tmp_result);
1562 tmp_result = smu7_enable_thermal_auto_throttle(hwmgr);
1563 PP_ASSERT_WITH_CODE((0 == tmp_result),
1564 "Failed to enable thermal auto throttle!", result = tmp_result);
1566 tmp_result = smu7_pcie_performance_request(hwmgr);
1567 PP_ASSERT_WITH_CODE((0 == tmp_result),
1568 "pcie performance request failed!", result = tmp_result);
1573 static int smu7_avfs_control(struct pp_hwmgr *hwmgr, bool enable)
1575 if (!hwmgr->avfs_supported)
1579 if (!PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device,
1580 CGS_IND_REG__SMC, FEATURE_STATUS, AVS_ON)) {
1581 PP_ASSERT_WITH_CODE(!smum_send_msg_to_smc(
1582 hwmgr, PPSMC_MSG_EnableAvfs, NULL),
1583 "Failed to enable AVFS!",
1586 } else if (PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device,
1587 CGS_IND_REG__SMC, FEATURE_STATUS, AVS_ON)) {
1588 PP_ASSERT_WITH_CODE(!smum_send_msg_to_smc(
1589 hwmgr, PPSMC_MSG_DisableAvfs, NULL),
1590 "Failed to disable AVFS!",
1597 static int smu7_update_avfs(struct pp_hwmgr *hwmgr)
1599 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1601 if (!hwmgr->avfs_supported)
1604 if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_VDDC) {
1605 smu7_avfs_control(hwmgr, false);
1606 } else if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_SCLK) {
1607 smu7_avfs_control(hwmgr, false);
1608 smu7_avfs_control(hwmgr, true);
1610 smu7_avfs_control(hwmgr, true);
1616 static int smu7_disable_dpm_tasks(struct pp_hwmgr *hwmgr)
1618 int tmp_result, result = 0;
1620 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1621 PHM_PlatformCaps_ThermalController))
1622 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1623 GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, 1);
1625 tmp_result = smu7_disable_power_containment(hwmgr);
1626 PP_ASSERT_WITH_CODE((tmp_result == 0),
1627 "Failed to disable power containment!", result = tmp_result);
1629 tmp_result = smu7_disable_smc_cac(hwmgr);
1630 PP_ASSERT_WITH_CODE((tmp_result == 0),
1631 "Failed to disable SMC CAC!", result = tmp_result);
1633 tmp_result = smu7_disable_didt_config(hwmgr);
1634 PP_ASSERT_WITH_CODE((tmp_result == 0),
1635 "Failed to disable DIDT!", result = tmp_result);
1637 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1638 CG_SPLL_SPREAD_SPECTRUM, SSEN, 0);
1639 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1640 GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, 0);
1642 tmp_result = smu7_disable_thermal_auto_throttle(hwmgr);
1643 PP_ASSERT_WITH_CODE((tmp_result == 0),
1644 "Failed to disable thermal auto throttle!", result = tmp_result);
1646 tmp_result = smu7_avfs_control(hwmgr, false);
1647 PP_ASSERT_WITH_CODE((tmp_result == 0),
1648 "Failed to disable AVFS!", result = tmp_result);
1650 tmp_result = smu7_stop_dpm(hwmgr);
1651 PP_ASSERT_WITH_CODE((tmp_result == 0),
1652 "Failed to stop DPM!", result = tmp_result);
1654 tmp_result = smu7_disable_deep_sleep_master_switch(hwmgr);
1655 PP_ASSERT_WITH_CODE((tmp_result == 0),
1656 "Failed to disable deep sleep master switch!", result = tmp_result);
1658 tmp_result = smu7_disable_ulv(hwmgr);
1659 PP_ASSERT_WITH_CODE((tmp_result == 0),
1660 "Failed to disable ULV!", result = tmp_result);
1662 tmp_result = smu7_clear_voting_clients(hwmgr);
1663 PP_ASSERT_WITH_CODE((tmp_result == 0),
1664 "Failed to clear voting clients!", result = tmp_result);
1666 tmp_result = smu7_reset_to_default(hwmgr);
1667 PP_ASSERT_WITH_CODE((tmp_result == 0),
1668 "Failed to reset to default!", result = tmp_result);
1670 tmp_result = smum_stop_smc(hwmgr);
1671 PP_ASSERT_WITH_CODE((tmp_result == 0),
1672 "Failed to stop smc!", result = tmp_result);
1674 tmp_result = smu7_force_switch_to_arbf0(hwmgr);
1675 PP_ASSERT_WITH_CODE((tmp_result == 0),
1676 "Failed to force to switch arbf0!", result = tmp_result);
1681 static void smu7_init_dpm_defaults(struct pp_hwmgr *hwmgr)
1683 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1684 struct phm_ppt_v1_information *table_info =
1685 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1686 struct amdgpu_device *adev = hwmgr->adev;
1690 data->dll_default_on = false;
1691 data->mclk_dpm0_activity_target = 0xa;
1692 data->vddc_vddgfx_delta = 300;
1693 data->static_screen_threshold = SMU7_STATICSCREENTHRESHOLD_DFLT;
1694 data->static_screen_threshold_unit = SMU7_STATICSCREENTHRESHOLDUNIT_DFLT;
1695 data->voting_rights_clients[0] = SMU7_VOTINGRIGHTSCLIENTS_DFLT0;
1696 data->voting_rights_clients[1]= SMU7_VOTINGRIGHTSCLIENTS_DFLT1;
1697 data->voting_rights_clients[2] = SMU7_VOTINGRIGHTSCLIENTS_DFLT2;
1698 data->voting_rights_clients[3]= SMU7_VOTINGRIGHTSCLIENTS_DFLT3;
1699 data->voting_rights_clients[4]= SMU7_VOTINGRIGHTSCLIENTS_DFLT4;
1700 data->voting_rights_clients[5]= SMU7_VOTINGRIGHTSCLIENTS_DFLT5;
1701 data->voting_rights_clients[6]= SMU7_VOTINGRIGHTSCLIENTS_DFLT6;
1702 data->voting_rights_clients[7]= SMU7_VOTINGRIGHTSCLIENTS_DFLT7;
1704 data->mclk_dpm_key_disabled = hwmgr->feature_mask & PP_MCLK_DPM_MASK ? false : true;
1705 data->sclk_dpm_key_disabled = hwmgr->feature_mask & PP_SCLK_DPM_MASK ? false : true;
1706 data->pcie_dpm_key_disabled = hwmgr->feature_mask & PP_PCIE_DPM_MASK ? false : true;
1707 /* need to set voltage control types before EVV patching */
1708 data->voltage_control = SMU7_VOLTAGE_CONTROL_NONE;
1709 data->vddci_control = SMU7_VOLTAGE_CONTROL_NONE;
1710 data->mvdd_control = SMU7_VOLTAGE_CONTROL_NONE;
1711 data->enable_tdc_limit_feature = true;
1712 data->enable_pkg_pwr_tracking_feature = true;
1713 data->force_pcie_gen = PP_PCIEGenInvalid;
1714 data->ulv_supported = hwmgr->feature_mask & PP_ULV_MASK ? true : false;
1715 data->current_profile_setting.bupdate_sclk = 1;
1716 data->current_profile_setting.sclk_up_hyst = 0;
1717 data->current_profile_setting.sclk_down_hyst = 100;
1718 data->current_profile_setting.sclk_activity = SMU7_SCLK_TARGETACTIVITY_DFLT;
1719 data->current_profile_setting.bupdate_mclk = 1;
1720 if (hwmgr->chip_id >= CHIP_POLARIS10) {
1721 if (adev->gmc.vram_width == 256) {
1722 data->current_profile_setting.mclk_up_hyst = 10;
1723 data->current_profile_setting.mclk_down_hyst = 60;
1724 data->current_profile_setting.mclk_activity = 25;
1725 } else if (adev->gmc.vram_width == 128) {
1726 data->current_profile_setting.mclk_up_hyst = 5;
1727 data->current_profile_setting.mclk_down_hyst = 16;
1728 data->current_profile_setting.mclk_activity = 20;
1729 } else if (adev->gmc.vram_width == 64) {
1730 data->current_profile_setting.mclk_up_hyst = 3;
1731 data->current_profile_setting.mclk_down_hyst = 16;
1732 data->current_profile_setting.mclk_activity = 20;
1735 data->current_profile_setting.mclk_up_hyst = 0;
1736 data->current_profile_setting.mclk_down_hyst = 100;
1737 data->current_profile_setting.mclk_activity = SMU7_MCLK_TARGETACTIVITY_DFLT;
1739 hwmgr->workload_mask = 1 << hwmgr->workload_prority[PP_SMC_POWER_PROFILE_FULLSCREEN3D];
1740 hwmgr->power_profile_mode = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
1741 hwmgr->default_power_profile_mode = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
1743 if (hwmgr->chip_id == CHIP_HAWAII) {
1744 data->thermal_temp_setting.temperature_low = 94500;
1745 data->thermal_temp_setting.temperature_high = 95000;
1746 data->thermal_temp_setting.temperature_shutdown = 104000;
1748 data->thermal_temp_setting.temperature_low = 99500;
1749 data->thermal_temp_setting.temperature_high = 100000;
1750 data->thermal_temp_setting.temperature_shutdown = 104000;
1753 data->fast_watermark_threshold = 100;
1754 if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1755 VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_SVID2))
1756 data->voltage_control = SMU7_VOLTAGE_CONTROL_BY_SVID2;
1757 else if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1758 VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_GPIO_LUT))
1759 data->voltage_control = SMU7_VOLTAGE_CONTROL_BY_GPIO;
1761 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1762 PHM_PlatformCaps_ControlVDDGFX)) {
1763 if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1764 VOLTAGE_TYPE_VDDGFX, VOLTAGE_OBJ_SVID2)) {
1765 data->vdd_gfx_control = SMU7_VOLTAGE_CONTROL_BY_SVID2;
1769 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1770 PHM_PlatformCaps_EnableMVDDControl)) {
1771 if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1772 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT))
1773 data->mvdd_control = SMU7_VOLTAGE_CONTROL_BY_GPIO;
1774 else if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1775 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_SVID2))
1776 data->mvdd_control = SMU7_VOLTAGE_CONTROL_BY_SVID2;
1779 if (SMU7_VOLTAGE_CONTROL_NONE == data->vdd_gfx_control)
1780 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1781 PHM_PlatformCaps_ControlVDDGFX);
1783 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1784 PHM_PlatformCaps_ControlVDDCI)) {
1785 if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1786 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT))
1787 data->vddci_control = SMU7_VOLTAGE_CONTROL_BY_GPIO;
1788 else if (atomctrl_is_voltage_controlled_by_gpio_v3(hwmgr,
1789 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_SVID2))
1790 data->vddci_control = SMU7_VOLTAGE_CONTROL_BY_SVID2;
1793 if (data->mvdd_control == SMU7_VOLTAGE_CONTROL_NONE)
1794 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1795 PHM_PlatformCaps_EnableMVDDControl);
1797 if (data->vddci_control == SMU7_VOLTAGE_CONTROL_NONE)
1798 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1799 PHM_PlatformCaps_ControlVDDCI);
1801 data->vddc_phase_shed_control = 1;
1802 if ((hwmgr->chip_id == CHIP_POLARIS12) ||
1803 ASICID_IS_P20(adev->pdev->device, adev->pdev->revision) ||
1804 ASICID_IS_P21(adev->pdev->device, adev->pdev->revision) ||
1805 ASICID_IS_P30(adev->pdev->device, adev->pdev->revision) ||
1806 ASICID_IS_P31(adev->pdev->device, adev->pdev->revision)) {
1807 if (data->voltage_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
1808 atomctrl_get_svi2_info(hwmgr, VOLTAGE_TYPE_VDDC, &tmp1, &tmp2,
1810 tmp3 = (tmp3 >> 5) & 0x3;
1811 data->vddc_phase_shed_control = ((tmp3 << 1) | (tmp3 >> 1)) & 0x3;
1813 } else if (hwmgr->chip_family == AMDGPU_FAMILY_CI) {
1814 data->vddc_phase_shed_control = 1;
1817 if ((hwmgr->pp_table_version != PP_TABLE_V0) && (hwmgr->feature_mask & PP_CLOCK_STRETCH_MASK)
1818 && (table_info->cac_dtp_table->usClockStretchAmount != 0))
1819 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
1820 PHM_PlatformCaps_ClockStretcher);
1822 data->pcie_gen_performance.max = PP_PCIEGen1;
1823 data->pcie_gen_performance.min = PP_PCIEGen3;
1824 data->pcie_gen_power_saving.max = PP_PCIEGen1;
1825 data->pcie_gen_power_saving.min = PP_PCIEGen3;
1826 data->pcie_lane_performance.max = 0;
1827 data->pcie_lane_performance.min = 16;
1828 data->pcie_lane_power_saving.max = 0;
1829 data->pcie_lane_power_saving.min = 16;
1832 if (adev->pg_flags & AMD_PG_SUPPORT_UVD)
1833 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
1834 PHM_PlatformCaps_UVDPowerGating);
1835 if (adev->pg_flags & AMD_PG_SUPPORT_VCE)
1836 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
1837 PHM_PlatformCaps_VCEPowerGating);
1839 data->disable_edc_leakage_controller = true;
1840 if (((adev->asic_type == CHIP_POLARIS10) && hwmgr->is_kicker) ||
1841 ((adev->asic_type == CHIP_POLARIS11) && hwmgr->is_kicker) ||
1842 (adev->asic_type == CHIP_POLARIS12) ||
1843 (adev->asic_type == CHIP_VEGAM))
1844 data->disable_edc_leakage_controller = false;
1846 if (!atomctrl_is_asic_internal_ss_supported(hwmgr)) {
1847 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1848 PHM_PlatformCaps_MemorySpreadSpectrumSupport);
1849 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1850 PHM_PlatformCaps_EngineSpreadSpectrumSupport);
1853 if ((adev->pdev->device == 0x699F) &&
1854 (adev->pdev->revision == 0xCF)) {
1855 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1856 PHM_PlatformCaps_PowerContainment);
1857 data->enable_tdc_limit_feature = false;
1858 data->enable_pkg_pwr_tracking_feature = false;
1859 data->disable_edc_leakage_controller = true;
1860 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1861 PHM_PlatformCaps_ClockStretcher);
1865 static int smu7_calculate_ro_range(struct pp_hwmgr *hwmgr)
1867 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1868 struct amdgpu_device *adev = hwmgr->adev;
1869 uint32_t asicrev1, evv_revision, max, min;
1871 atomctrl_read_efuse(hwmgr, STRAP_EVV_REVISION_LSB, STRAP_EVV_REVISION_MSB,
1874 atomctrl_read_efuse(hwmgr, 568, 579, &asicrev1);
1876 if (ASICID_IS_P20(adev->pdev->device, adev->pdev->revision) ||
1877 ASICID_IS_P30(adev->pdev->device, adev->pdev->revision)) {
1880 } else if (ASICID_IS_P21(adev->pdev->device, adev->pdev->revision) ||
1881 ASICID_IS_P31(adev->pdev->device, adev->pdev->revision)) {
1884 } else if (hwmgr->chip_id == CHIP_POLARIS10) {
1885 if (adev->pdev->subsystem_vendor == 0x106B) {
1889 if (evv_revision == 0) {
1892 } else if (evv_revision == 1) {
1893 if (asicrev1 == 326) {
1896 /* TODO: PATCH RO in VBIOS */
1901 } else if (evv_revision == 2) {
1906 } else if ((hwmgr->chip_id == CHIP_POLARIS11) ||
1907 (hwmgr->chip_id == CHIP_POLARIS12)) {
1912 data->ro_range_minimum = min;
1913 data->ro_range_maximum = max;
1915 /* TODO: PATCH RO in VBIOS here */
1921 * Get Leakage VDDC based on leakage ID.
1923 * @param hwmgr the address of the powerplay hardware manager.
1926 static int smu7_get_evv_voltages(struct pp_hwmgr *hwmgr)
1928 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1931 uint16_t vddgfx = 0;
1934 struct phm_ppt_v1_information *table_info =
1935 (struct phm_ppt_v1_information *)hwmgr->pptable;
1936 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table = NULL;
1938 if (hwmgr->chip_id == CHIP_POLARIS10 ||
1939 hwmgr->chip_id == CHIP_POLARIS11 ||
1940 hwmgr->chip_id == CHIP_POLARIS12)
1941 smu7_calculate_ro_range(hwmgr);
1943 for (i = 0; i < SMU7_MAX_LEAKAGE_COUNT; i++) {
1944 vv_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i;
1946 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
1947 if ((hwmgr->pp_table_version == PP_TABLE_V1)
1948 && !phm_get_sclk_for_voltage_evv(hwmgr,
1949 table_info->vddgfx_lookup_table, vv_id, &sclk)) {
1950 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1951 PHM_PlatformCaps_ClockStretcher)) {
1952 sclk_table = table_info->vdd_dep_on_sclk;
1954 for (j = 1; j < sclk_table->count; j++) {
1955 if (sclk_table->entries[j].clk == sclk &&
1956 sclk_table->entries[j].cks_enable == 0) {
1962 if (0 == atomctrl_get_voltage_evv_on_sclk
1963 (hwmgr, VOLTAGE_TYPE_VDDGFX, sclk,
1965 /* need to make sure vddgfx is less than 2v or else, it could burn the ASIC. */
1966 PP_ASSERT_WITH_CODE((vddgfx < 2000 && vddgfx != 0), "Invalid VDDGFX value!", return -EINVAL);
1968 /* the voltage should not be zero nor equal to leakage ID */
1969 if (vddgfx != 0 && vddgfx != vv_id) {
1970 data->vddcgfx_leakage.actual_voltage[data->vddcgfx_leakage.count] = vddgfx;
1971 data->vddcgfx_leakage.leakage_id[data->vddcgfx_leakage.count] = vv_id;
1972 data->vddcgfx_leakage.count++;
1975 pr_info("Error retrieving EVV voltage value!\n");
1979 if ((hwmgr->pp_table_version == PP_TABLE_V0)
1980 || !phm_get_sclk_for_voltage_evv(hwmgr,
1981 table_info->vddc_lookup_table, vv_id, &sclk)) {
1982 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1983 PHM_PlatformCaps_ClockStretcher)) {
1984 if (table_info == NULL)
1986 sclk_table = table_info->vdd_dep_on_sclk;
1988 for (j = 1; j < sclk_table->count; j++) {
1989 if (sclk_table->entries[j].clk == sclk &&
1990 sclk_table->entries[j].cks_enable == 0) {
1997 if (phm_get_voltage_evv_on_sclk(hwmgr,
1999 sclk, vv_id, &vddc) == 0) {
2000 if (vddc >= 2000 || vddc == 0)
2003 pr_debug("failed to retrieving EVV voltage!\n");
2007 /* the voltage should not be zero nor equal to leakage ID */
2008 if (vddc != 0 && vddc != vv_id) {
2009 data->vddc_leakage.actual_voltage[data->vddc_leakage.count] = (uint16_t)(vddc);
2010 data->vddc_leakage.leakage_id[data->vddc_leakage.count] = vv_id;
2011 data->vddc_leakage.count++;
2021 * Change virtual leakage voltage to actual value.
2023 * @param hwmgr the address of the powerplay hardware manager.
2024 * @param pointer to changing voltage
2025 * @param pointer to leakage table
2027 static void smu7_patch_ppt_v1_with_vdd_leakage(struct pp_hwmgr *hwmgr,
2028 uint16_t *voltage, struct smu7_leakage_voltage *leakage_table)
2032 /* search for leakage voltage ID 0xff01 ~ 0xff08 */
2033 for (index = 0; index < leakage_table->count; index++) {
2034 /* if this voltage matches a leakage voltage ID */
2035 /* patch with actual leakage voltage */
2036 if (leakage_table->leakage_id[index] == *voltage) {
2037 *voltage = leakage_table->actual_voltage[index];
2042 if (*voltage > ATOM_VIRTUAL_VOLTAGE_ID0)
2043 pr_err("Voltage value looks like a Leakage ID but it's not patched \n");
2047 * Patch voltage lookup table by EVV leakages.
2049 * @param hwmgr the address of the powerplay hardware manager.
2050 * @param pointer to voltage lookup table
2051 * @param pointer to leakage table
2054 static int smu7_patch_lookup_table_with_leakage(struct pp_hwmgr *hwmgr,
2055 phm_ppt_v1_voltage_lookup_table *lookup_table,
2056 struct smu7_leakage_voltage *leakage_table)
2060 for (i = 0; i < lookup_table->count; i++)
2061 smu7_patch_ppt_v1_with_vdd_leakage(hwmgr,
2062 &lookup_table->entries[i].us_vdd, leakage_table);
2067 static int smu7_patch_clock_voltage_limits_with_vddc_leakage(
2068 struct pp_hwmgr *hwmgr, struct smu7_leakage_voltage *leakage_table,
2071 struct phm_ppt_v1_information *table_info =
2072 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2073 smu7_patch_ppt_v1_with_vdd_leakage(hwmgr, (uint16_t *)vddc, leakage_table);
2074 hwmgr->dyn_state.max_clock_voltage_on_dc.vddc =
2075 table_info->max_clock_voltage_on_dc.vddc;
2079 static int smu7_patch_voltage_dependency_tables_with_lookup_table(
2080 struct pp_hwmgr *hwmgr)
2084 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2085 struct phm_ppt_v1_information *table_info =
2086 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2088 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
2089 table_info->vdd_dep_on_sclk;
2090 struct phm_ppt_v1_clock_voltage_dependency_table *mclk_table =
2091 table_info->vdd_dep_on_mclk;
2092 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
2093 table_info->mm_dep_table;
2095 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
2096 for (entry_id = 0; entry_id < sclk_table->count; ++entry_id) {
2097 voltage_id = sclk_table->entries[entry_id].vddInd;
2098 sclk_table->entries[entry_id].vddgfx =
2099 table_info->vddgfx_lookup_table->entries[voltage_id].us_vdd;
2102 for (entry_id = 0; entry_id < sclk_table->count; ++entry_id) {
2103 voltage_id = sclk_table->entries[entry_id].vddInd;
2104 sclk_table->entries[entry_id].vddc =
2105 table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
2109 for (entry_id = 0; entry_id < mclk_table->count; ++entry_id) {
2110 voltage_id = mclk_table->entries[entry_id].vddInd;
2111 mclk_table->entries[entry_id].vddc =
2112 table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
2115 for (entry_id = 0; entry_id < mm_table->count; ++entry_id) {
2116 voltage_id = mm_table->entries[entry_id].vddcInd;
2117 mm_table->entries[entry_id].vddc =
2118 table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
2125 static int phm_add_voltage(struct pp_hwmgr *hwmgr,
2126 phm_ppt_v1_voltage_lookup_table *look_up_table,
2127 phm_ppt_v1_voltage_lookup_record *record)
2131 PP_ASSERT_WITH_CODE((NULL != look_up_table),
2132 "Lookup Table empty.", return -EINVAL);
2133 PP_ASSERT_WITH_CODE((0 != look_up_table->count),
2134 "Lookup Table empty.", return -EINVAL);
2136 i = smum_get_mac_definition(hwmgr, SMU_MAX_LEVELS_VDDGFX);
2137 PP_ASSERT_WITH_CODE((i >= look_up_table->count),
2138 "Lookup Table is full.", return -EINVAL);
2140 /* This is to avoid entering duplicate calculated records. */
2141 for (i = 0; i < look_up_table->count; i++) {
2142 if (look_up_table->entries[i].us_vdd == record->us_vdd) {
2143 if (look_up_table->entries[i].us_calculated == 1)
2149 look_up_table->entries[i].us_calculated = 1;
2150 look_up_table->entries[i].us_vdd = record->us_vdd;
2151 look_up_table->entries[i].us_cac_low = record->us_cac_low;
2152 look_up_table->entries[i].us_cac_mid = record->us_cac_mid;
2153 look_up_table->entries[i].us_cac_high = record->us_cac_high;
2154 /* Only increment the count when we're appending, not replacing duplicate entry. */
2155 if (i == look_up_table->count)
2156 look_up_table->count++;
2162 static int smu7_calc_voltage_dependency_tables(struct pp_hwmgr *hwmgr)
2165 struct phm_ppt_v1_voltage_lookup_record v_record;
2166 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2167 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
2169 phm_ppt_v1_clock_voltage_dependency_table *sclk_table = pptable_info->vdd_dep_on_sclk;
2170 phm_ppt_v1_clock_voltage_dependency_table *mclk_table = pptable_info->vdd_dep_on_mclk;
2172 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
2173 for (entry_id = 0; entry_id < sclk_table->count; ++entry_id) {
2174 if (sclk_table->entries[entry_id].vdd_offset & (1 << 15))
2175 v_record.us_vdd = sclk_table->entries[entry_id].vddgfx +
2176 sclk_table->entries[entry_id].vdd_offset - 0xFFFF;
2178 v_record.us_vdd = sclk_table->entries[entry_id].vddgfx +
2179 sclk_table->entries[entry_id].vdd_offset;
2181 sclk_table->entries[entry_id].vddc =
2182 v_record.us_cac_low = v_record.us_cac_mid =
2183 v_record.us_cac_high = v_record.us_vdd;
2185 phm_add_voltage(hwmgr, pptable_info->vddc_lookup_table, &v_record);
2188 for (entry_id = 0; entry_id < mclk_table->count; ++entry_id) {
2189 if (mclk_table->entries[entry_id].vdd_offset & (1 << 15))
2190 v_record.us_vdd = mclk_table->entries[entry_id].vddc +
2191 mclk_table->entries[entry_id].vdd_offset - 0xFFFF;
2193 v_record.us_vdd = mclk_table->entries[entry_id].vddc +
2194 mclk_table->entries[entry_id].vdd_offset;
2196 mclk_table->entries[entry_id].vddgfx = v_record.us_cac_low =
2197 v_record.us_cac_mid = v_record.us_cac_high = v_record.us_vdd;
2198 phm_add_voltage(hwmgr, pptable_info->vddgfx_lookup_table, &v_record);
2204 static int smu7_calc_mm_voltage_dependency_table(struct pp_hwmgr *hwmgr)
2207 struct phm_ppt_v1_voltage_lookup_record v_record;
2208 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2209 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
2210 phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table = pptable_info->mm_dep_table;
2212 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
2213 for (entry_id = 0; entry_id < mm_table->count; entry_id++) {
2214 if (mm_table->entries[entry_id].vddgfx_offset & (1 << 15))
2215 v_record.us_vdd = mm_table->entries[entry_id].vddc +
2216 mm_table->entries[entry_id].vddgfx_offset - 0xFFFF;
2218 v_record.us_vdd = mm_table->entries[entry_id].vddc +
2219 mm_table->entries[entry_id].vddgfx_offset;
2221 /* Add the calculated VDDGFX to the VDDGFX lookup table */
2222 mm_table->entries[entry_id].vddgfx = v_record.us_cac_low =
2223 v_record.us_cac_mid = v_record.us_cac_high = v_record.us_vdd;
2224 phm_add_voltage(hwmgr, pptable_info->vddgfx_lookup_table, &v_record);
2230 static int smu7_sort_lookup_table(struct pp_hwmgr *hwmgr,
2231 struct phm_ppt_v1_voltage_lookup_table *lookup_table)
2233 uint32_t table_size, i, j;
2234 table_size = lookup_table->count;
2236 PP_ASSERT_WITH_CODE(0 != lookup_table->count,
2237 "Lookup table is empty", return -EINVAL);
2239 /* Sorting voltages */
2240 for (i = 0; i < table_size - 1; i++) {
2241 for (j = i + 1; j > 0; j--) {
2242 if (lookup_table->entries[j].us_vdd <
2243 lookup_table->entries[j - 1].us_vdd) {
2244 swap(lookup_table->entries[j - 1],
2245 lookup_table->entries[j]);
2253 static int smu7_complete_dependency_tables(struct pp_hwmgr *hwmgr)
2257 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2258 struct phm_ppt_v1_information *table_info =
2259 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2261 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
2262 tmp_result = smu7_patch_lookup_table_with_leakage(hwmgr,
2263 table_info->vddgfx_lookup_table, &(data->vddcgfx_leakage));
2264 if (tmp_result != 0)
2265 result = tmp_result;
2267 smu7_patch_ppt_v1_with_vdd_leakage(hwmgr,
2268 &table_info->max_clock_voltage_on_dc.vddgfx, &(data->vddcgfx_leakage));
2271 tmp_result = smu7_patch_lookup_table_with_leakage(hwmgr,
2272 table_info->vddc_lookup_table, &(data->vddc_leakage));
2274 result = tmp_result;
2276 tmp_result = smu7_patch_clock_voltage_limits_with_vddc_leakage(hwmgr,
2277 &(data->vddc_leakage), &table_info->max_clock_voltage_on_dc.vddc);
2279 result = tmp_result;
2282 tmp_result = smu7_patch_voltage_dependency_tables_with_lookup_table(hwmgr);
2284 result = tmp_result;
2286 tmp_result = smu7_calc_voltage_dependency_tables(hwmgr);
2288 result = tmp_result;
2290 tmp_result = smu7_calc_mm_voltage_dependency_table(hwmgr);
2292 result = tmp_result;
2294 tmp_result = smu7_sort_lookup_table(hwmgr, table_info->vddgfx_lookup_table);
2296 result = tmp_result;
2298 tmp_result = smu7_sort_lookup_table(hwmgr, table_info->vddc_lookup_table);
2300 result = tmp_result;
2305 static int smu7_find_highest_vddc(struct pp_hwmgr *hwmgr)
2307 struct phm_ppt_v1_information *table_info =
2308 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2309 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_sclk_vdd_table =
2310 table_info->vdd_dep_on_sclk;
2311 struct phm_ppt_v1_voltage_lookup_table *lookup_table =
2312 table_info->vddc_lookup_table;
2313 uint16_t highest_voltage;
2316 highest_voltage = allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].vddc;
2318 for (i = 0; i < lookup_table->count; i++) {
2319 if (lookup_table->entries[i].us_vdd < ATOM_VIRTUAL_VOLTAGE_ID0 &&
2320 lookup_table->entries[i].us_vdd > highest_voltage)
2321 highest_voltage = lookup_table->entries[i].us_vdd;
2324 return highest_voltage;
2327 static int smu7_set_private_data_based_on_pptable_v1(struct pp_hwmgr *hwmgr)
2329 struct phm_ppt_v1_information *table_info =
2330 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2332 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_sclk_vdd_table =
2333 table_info->vdd_dep_on_sclk;
2334 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_mclk_vdd_table =
2335 table_info->vdd_dep_on_mclk;
2337 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table != NULL,
2338 "VDD dependency on SCLK table is missing.",
2340 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table->count >= 1,
2341 "VDD dependency on SCLK table has to have is missing.",
2344 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table != NULL,
2345 "VDD dependency on MCLK table is missing",
2347 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table->count >= 1,
2348 "VDD dependency on MCLK table has to have is missing.",
2351 table_info->max_clock_voltage_on_ac.sclk =
2352 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].clk;
2353 table_info->max_clock_voltage_on_ac.mclk =
2354 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].clk;
2355 if (hwmgr->chip_id >= CHIP_POLARIS10 && hwmgr->chip_id <= CHIP_VEGAM)
2356 table_info->max_clock_voltage_on_ac.vddc =
2357 smu7_find_highest_vddc(hwmgr);
2359 table_info->max_clock_voltage_on_ac.vddc =
2360 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].vddc;
2361 table_info->max_clock_voltage_on_ac.vddci =
2362 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].vddci;
2364 hwmgr->dyn_state.max_clock_voltage_on_ac.sclk = table_info->max_clock_voltage_on_ac.sclk;
2365 hwmgr->dyn_state.max_clock_voltage_on_ac.mclk = table_info->max_clock_voltage_on_ac.mclk;
2366 hwmgr->dyn_state.max_clock_voltage_on_ac.vddc = table_info->max_clock_voltage_on_ac.vddc;
2367 hwmgr->dyn_state.max_clock_voltage_on_ac.vddci = table_info->max_clock_voltage_on_ac.vddci;
2372 static int smu7_patch_voltage_workaround(struct pp_hwmgr *hwmgr)
2374 struct phm_ppt_v1_information *table_info =
2375 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2376 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table;
2377 struct phm_ppt_v1_voltage_lookup_table *lookup_table;
2379 uint32_t hw_revision, sub_vendor_id, sub_sys_id;
2380 struct amdgpu_device *adev = hwmgr->adev;
2382 if (table_info != NULL) {
2383 dep_mclk_table = table_info->vdd_dep_on_mclk;
2384 lookup_table = table_info->vddc_lookup_table;
2388 hw_revision = adev->pdev->revision;
2389 sub_sys_id = adev->pdev->subsystem_device;
2390 sub_vendor_id = adev->pdev->subsystem_vendor;
2392 if (adev->pdev->device == 0x67DF && hw_revision == 0xC7 &&
2393 ((sub_sys_id == 0xb37 && sub_vendor_id == 0x1002) ||
2394 (sub_sys_id == 0x4a8 && sub_vendor_id == 0x1043) ||
2395 (sub_sys_id == 0x9480 && sub_vendor_id == 0x1682))) {
2397 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device,
2403 if (lookup_table->entries[dep_mclk_table->entries[dep_mclk_table->count-1].vddInd].us_vdd >= 1000)
2406 for (i = 0; i < lookup_table->count; i++) {
2407 if (lookup_table->entries[i].us_vdd < 0xff01 && lookup_table->entries[i].us_vdd >= 1000) {
2408 dep_mclk_table->entries[dep_mclk_table->count-1].vddInd = (uint8_t) i;
2416 static int smu7_thermal_parameter_init(struct pp_hwmgr *hwmgr)
2418 struct pp_atomctrl_gpio_pin_assignment gpio_pin_assignment;
2420 struct phm_ppt_v1_information *table_info =
2421 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2424 if (atomctrl_get_pp_assign_pin(hwmgr, VDDC_PCC_GPIO_PINID, &gpio_pin_assignment)) {
2425 temp_reg = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCNB_PWRMGT_CNTL);
2426 switch (gpio_pin_assignment.uc_gpio_pin_bit_shift) {
2428 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x1);
2431 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x2);
2434 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW, 0x1);
2437 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, FORCE_NB_PS1, 0x1);
2440 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, DPM_ENABLED, 0x1);
2445 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCNB_PWRMGT_CNTL, temp_reg);
2448 if (table_info == NULL)
2451 if (table_info->cac_dtp_table->usDefaultTargetOperatingTemp != 0 &&
2452 hwmgr->thermal_controller.advanceFanControlParameters.ucFanControlMode) {
2453 hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMMinLimit =
2454 (uint16_t)hwmgr->thermal_controller.advanceFanControlParameters.ucMinimumPWMLimit;
2456 hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMMaxLimit =
2457 (uint16_t)hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanPWM;
2459 hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMStep = 1;
2461 hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMMaxLimit = 100;
2463 hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMMinLimit =
2464 (uint16_t)hwmgr->thermal_controller.advanceFanControlParameters.ucMinimumPWMLimit;
2466 hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMStep = 1;
2468 table_info->cac_dtp_table->usDefaultTargetOperatingTemp = (table_info->cac_dtp_table->usDefaultTargetOperatingTemp >= 50) ?
2469 (table_info->cac_dtp_table->usDefaultTargetOperatingTemp - 50) : 0;
2471 table_info->cac_dtp_table->usOperatingTempMaxLimit = table_info->cac_dtp_table->usDefaultTargetOperatingTemp;
2472 table_info->cac_dtp_table->usOperatingTempStep = 1;
2473 table_info->cac_dtp_table->usOperatingTempHyst = 1;
2475 hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanPWM =
2476 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanPWM;
2478 hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanRPM =
2479 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanRPM;
2481 hwmgr->dyn_state.cac_dtp_table->usOperatingTempMinLimit =
2482 table_info->cac_dtp_table->usOperatingTempMinLimit;
2484 hwmgr->dyn_state.cac_dtp_table->usOperatingTempMaxLimit =
2485 table_info->cac_dtp_table->usOperatingTempMaxLimit;
2487 hwmgr->dyn_state.cac_dtp_table->usDefaultTargetOperatingTemp =
2488 table_info->cac_dtp_table->usDefaultTargetOperatingTemp;
2490 hwmgr->dyn_state.cac_dtp_table->usOperatingTempStep =
2491 table_info->cac_dtp_table->usOperatingTempStep;
2493 hwmgr->dyn_state.cac_dtp_table->usTargetOperatingTemp =
2494 table_info->cac_dtp_table->usTargetOperatingTemp;
2495 if (hwmgr->feature_mask & PP_OD_FUZZY_FAN_CONTROL_MASK)
2496 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2497 PHM_PlatformCaps_ODFuzzyFanControlSupport);
2504 * Change virtual leakage voltage to actual value.
2506 * @param hwmgr the address of the powerplay hardware manager.
2507 * @param pointer to changing voltage
2508 * @param pointer to leakage table
2510 static void smu7_patch_ppt_v0_with_vdd_leakage(struct pp_hwmgr *hwmgr,
2511 uint32_t *voltage, struct smu7_leakage_voltage *leakage_table)
2515 /* search for leakage voltage ID 0xff01 ~ 0xff08 */
2516 for (index = 0; index < leakage_table->count; index++) {
2517 /* if this voltage matches a leakage voltage ID */
2518 /* patch with actual leakage voltage */
2519 if (leakage_table->leakage_id[index] == *voltage) {
2520 *voltage = leakage_table->actual_voltage[index];
2525 if (*voltage > ATOM_VIRTUAL_VOLTAGE_ID0)
2526 pr_err("Voltage value looks like a Leakage ID but it's not patched \n");
2530 static int smu7_patch_vddc(struct pp_hwmgr *hwmgr,
2531 struct phm_clock_voltage_dependency_table *tab)
2534 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2537 for (i = 0; i < tab->count; i++)
2538 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2539 &data->vddc_leakage);
2544 static int smu7_patch_vddci(struct pp_hwmgr *hwmgr,
2545 struct phm_clock_voltage_dependency_table *tab)
2548 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2551 for (i = 0; i < tab->count; i++)
2552 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2553 &data->vddci_leakage);
2558 static int smu7_patch_vce_vddc(struct pp_hwmgr *hwmgr,
2559 struct phm_vce_clock_voltage_dependency_table *tab)
2562 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2565 for (i = 0; i < tab->count; i++)
2566 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2567 &data->vddc_leakage);
2573 static int smu7_patch_uvd_vddc(struct pp_hwmgr *hwmgr,
2574 struct phm_uvd_clock_voltage_dependency_table *tab)
2577 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2580 for (i = 0; i < tab->count; i++)
2581 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2582 &data->vddc_leakage);
2587 static int smu7_patch_vddc_shed_limit(struct pp_hwmgr *hwmgr,
2588 struct phm_phase_shedding_limits_table *tab)
2591 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2594 for (i = 0; i < tab->count; i++)
2595 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].Voltage,
2596 &data->vddc_leakage);
2601 static int smu7_patch_samu_vddc(struct pp_hwmgr *hwmgr,
2602 struct phm_samu_clock_voltage_dependency_table *tab)
2605 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2608 for (i = 0; i < tab->count; i++)
2609 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2610 &data->vddc_leakage);
2615 static int smu7_patch_acp_vddc(struct pp_hwmgr *hwmgr,
2616 struct phm_acp_clock_voltage_dependency_table *tab)
2619 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2622 for (i = 0; i < tab->count; i++)
2623 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
2624 &data->vddc_leakage);
2629 static int smu7_patch_limits_vddc(struct pp_hwmgr *hwmgr,
2630 struct phm_clock_and_voltage_limits *tab)
2632 uint32_t vddc, vddci;
2633 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2637 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &vddc,
2638 &data->vddc_leakage);
2641 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &vddci,
2642 &data->vddci_leakage);
2649 static int smu7_patch_cac_vddc(struct pp_hwmgr *hwmgr, struct phm_cac_leakage_table *tab)
2653 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2656 for (i = 0; i < tab->count; i++) {
2657 vddc = (uint32_t)(tab->entries[i].Vddc);
2658 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &vddc, &data->vddc_leakage);
2659 tab->entries[i].Vddc = (uint16_t)vddc;
2666 static int smu7_patch_dependency_tables_with_leakage(struct pp_hwmgr *hwmgr)
2670 tmp = smu7_patch_vddc(hwmgr, hwmgr->dyn_state.vddc_dependency_on_sclk);
2674 tmp = smu7_patch_vddc(hwmgr, hwmgr->dyn_state.vddc_dependency_on_mclk);
2678 tmp = smu7_patch_vddc(hwmgr, hwmgr->dyn_state.vddc_dep_on_dal_pwrl);
2682 tmp = smu7_patch_vddci(hwmgr, hwmgr->dyn_state.vddci_dependency_on_mclk);
2686 tmp = smu7_patch_vce_vddc(hwmgr, hwmgr->dyn_state.vce_clock_voltage_dependency_table);
2690 tmp = smu7_patch_uvd_vddc(hwmgr, hwmgr->dyn_state.uvd_clock_voltage_dependency_table);
2694 tmp = smu7_patch_samu_vddc(hwmgr, hwmgr->dyn_state.samu_clock_voltage_dependency_table);
2698 tmp = smu7_patch_acp_vddc(hwmgr, hwmgr->dyn_state.acp_clock_voltage_dependency_table);
2702 tmp = smu7_patch_vddc_shed_limit(hwmgr, hwmgr->dyn_state.vddc_phase_shed_limits_table);
2706 tmp = smu7_patch_limits_vddc(hwmgr, &hwmgr->dyn_state.max_clock_voltage_on_ac);
2710 tmp = smu7_patch_limits_vddc(hwmgr, &hwmgr->dyn_state.max_clock_voltage_on_dc);
2714 tmp = smu7_patch_cac_vddc(hwmgr, hwmgr->dyn_state.cac_leakage_table);
2722 static int smu7_set_private_data_based_on_pptable_v0(struct pp_hwmgr *hwmgr)
2724 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2726 struct phm_clock_voltage_dependency_table *allowed_sclk_vddc_table = hwmgr->dyn_state.vddc_dependency_on_sclk;
2727 struct phm_clock_voltage_dependency_table *allowed_mclk_vddc_table = hwmgr->dyn_state.vddc_dependency_on_mclk;
2728 struct phm_clock_voltage_dependency_table *allowed_mclk_vddci_table = hwmgr->dyn_state.vddci_dependency_on_mclk;
2730 PP_ASSERT_WITH_CODE(allowed_sclk_vddc_table != NULL,
2731 "VDDC dependency on SCLK table is missing. This table is mandatory",
2733 PP_ASSERT_WITH_CODE(allowed_sclk_vddc_table->count >= 1,
2734 "VDDC dependency on SCLK table has to have is missing. This table is mandatory",
2737 PP_ASSERT_WITH_CODE(allowed_mclk_vddc_table != NULL,
2738 "VDDC dependency on MCLK table is missing. This table is mandatory",
2740 PP_ASSERT_WITH_CODE(allowed_mclk_vddc_table->count >= 1,
2741 "VDD dependency on MCLK table has to have is missing. This table is mandatory",
2744 data->min_vddc_in_pptable = (uint16_t)allowed_sclk_vddc_table->entries[0].v;
2745 data->max_vddc_in_pptable = (uint16_t)allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].v;
2747 hwmgr->dyn_state.max_clock_voltage_on_ac.sclk =
2748 allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].clk;
2749 hwmgr->dyn_state.max_clock_voltage_on_ac.mclk =
2750 allowed_mclk_vddc_table->entries[allowed_mclk_vddc_table->count - 1].clk;
2751 hwmgr->dyn_state.max_clock_voltage_on_ac.vddc =
2752 allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].v;
2754 if (allowed_mclk_vddci_table != NULL && allowed_mclk_vddci_table->count >= 1) {
2755 data->min_vddci_in_pptable = (uint16_t)allowed_mclk_vddci_table->entries[0].v;
2756 data->max_vddci_in_pptable = (uint16_t)allowed_mclk_vddci_table->entries[allowed_mclk_vddci_table->count - 1].v;
2759 if (hwmgr->dyn_state.vddci_dependency_on_mclk != NULL && hwmgr->dyn_state.vddci_dependency_on_mclk->count >= 1)
2760 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;
2765 static int smu7_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)
2767 kfree(hwmgr->dyn_state.vddc_dep_on_dal_pwrl);
2768 hwmgr->dyn_state.vddc_dep_on_dal_pwrl = NULL;
2769 kfree(hwmgr->backend);
2770 hwmgr->backend = NULL;
2775 static int smu7_get_elb_voltages(struct pp_hwmgr *hwmgr)
2777 uint16_t virtual_voltage_id, vddc, vddci, efuse_voltage_id;
2778 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2781 if (atomctrl_get_leakage_id_from_efuse(hwmgr, &efuse_voltage_id) == 0) {
2782 for (i = 0; i < SMU7_MAX_LEAKAGE_COUNT; i++) {
2783 virtual_voltage_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i;
2784 if (atomctrl_get_leakage_vddc_base_on_leakage(hwmgr, &vddc, &vddci,
2786 efuse_voltage_id) == 0) {
2787 if (vddc != 0 && vddc != virtual_voltage_id) {
2788 data->vddc_leakage.actual_voltage[data->vddc_leakage.count] = vddc;
2789 data->vddc_leakage.leakage_id[data->vddc_leakage.count] = virtual_voltage_id;
2790 data->vddc_leakage.count++;
2792 if (vddci != 0 && vddci != virtual_voltage_id) {
2793 data->vddci_leakage.actual_voltage[data->vddci_leakage.count] = vddci;
2794 data->vddci_leakage.leakage_id[data->vddci_leakage.count] = virtual_voltage_id;
2795 data->vddci_leakage.count++;
2803 #define LEAKAGE_ID_MSB 463
2804 #define LEAKAGE_ID_LSB 454
2806 static int smu7_update_edc_leakage_table(struct pp_hwmgr *hwmgr)
2808 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2813 if (data->disable_edc_leakage_controller)
2816 ret = atomctrl_get_edc_hilo_leakage_offset_table(hwmgr,
2817 &data->edc_hilo_leakage_offset_from_vbios);
2821 if (data->edc_hilo_leakage_offset_from_vbios.usEdcDidtLoDpm7TableOffset &&
2822 data->edc_hilo_leakage_offset_from_vbios.usEdcDidtHiDpm7TableOffset) {
2823 atomctrl_read_efuse(hwmgr, LEAKAGE_ID_LSB, LEAKAGE_ID_MSB, &efuse);
2824 if (efuse < data->edc_hilo_leakage_offset_from_vbios.usHiLoLeakageThreshold)
2825 offset = data->edc_hilo_leakage_offset_from_vbios.usEdcDidtLoDpm7TableOffset;
2827 offset = data->edc_hilo_leakage_offset_from_vbios.usEdcDidtHiDpm7TableOffset;
2829 ret = atomctrl_get_edc_leakage_table(hwmgr,
2830 &data->edc_leakage_table,
2839 static int smu7_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
2841 struct smu7_hwmgr *data;
2844 data = kzalloc(sizeof(struct smu7_hwmgr), GFP_KERNEL);
2848 hwmgr->backend = data;
2849 smu7_patch_voltage_workaround(hwmgr);
2850 smu7_init_dpm_defaults(hwmgr);
2852 /* Get leakage voltage based on leakage ID. */
2853 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2854 PHM_PlatformCaps_EVV)) {
2855 result = smu7_get_evv_voltages(hwmgr);
2857 pr_info("Get EVV Voltage Failed. Abort Driver loading!\n");
2861 smu7_get_elb_voltages(hwmgr);
2864 if (hwmgr->pp_table_version == PP_TABLE_V1) {
2865 smu7_complete_dependency_tables(hwmgr);
2866 smu7_set_private_data_based_on_pptable_v1(hwmgr);
2867 } else if (hwmgr->pp_table_version == PP_TABLE_V0) {
2868 smu7_patch_dependency_tables_with_leakage(hwmgr);
2869 smu7_set_private_data_based_on_pptable_v0(hwmgr);
2872 /* Initalize Dynamic State Adjustment Rule Settings */
2873 result = phm_initializa_dynamic_state_adjustment_rule_settings(hwmgr);
2876 struct amdgpu_device *adev = hwmgr->adev;
2878 data->is_tlu_enabled = false;
2880 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels =
2881 SMU7_MAX_HARDWARE_POWERLEVELS;
2882 hwmgr->platform_descriptor.hardwarePerformanceLevels = 2;
2883 hwmgr->platform_descriptor.minimumClocksReductionPercentage = 50;
2885 data->pcie_gen_cap = adev->pm.pcie_gen_mask;
2886 if (data->pcie_gen_cap & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)
2887 data->pcie_spc_cap = 20;
2889 data->pcie_spc_cap = 16;
2890 data->pcie_lane_cap = adev->pm.pcie_mlw_mask;
2892 hwmgr->platform_descriptor.vbiosInterruptId = 0x20000400; /* IRQ_SOURCE1_SW_INT */
2893 /* The true clock step depends on the frequency, typically 4.5 or 9 MHz. Here we use 5. */
2894 hwmgr->platform_descriptor.clockStep.engineClock = 500;
2895 hwmgr->platform_descriptor.clockStep.memoryClock = 500;
2896 smu7_thermal_parameter_init(hwmgr);
2898 /* Ignore return value in here, we are cleaning up a mess. */
2899 smu7_hwmgr_backend_fini(hwmgr);
2902 result = smu7_update_edc_leakage_table(hwmgr);
2909 static int smu7_force_dpm_highest(struct pp_hwmgr *hwmgr)
2911 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2912 uint32_t level, tmp;
2914 if (!data->pcie_dpm_key_disabled) {
2915 if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) {
2917 tmp = data->dpm_level_enable_mask.pcie_dpm_enable_mask;
2922 smum_send_msg_to_smc_with_parameter(hwmgr,
2923 PPSMC_MSG_PCIeDPM_ForceLevel, level,
2928 if (!data->sclk_dpm_key_disabled) {
2929 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
2931 tmp = data->dpm_level_enable_mask.sclk_dpm_enable_mask;
2936 smum_send_msg_to_smc_with_parameter(hwmgr,
2937 PPSMC_MSG_SCLKDPM_SetEnabledMask,
2943 if (!data->mclk_dpm_key_disabled) {
2944 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
2946 tmp = data->dpm_level_enable_mask.mclk_dpm_enable_mask;
2951 smum_send_msg_to_smc_with_parameter(hwmgr,
2952 PPSMC_MSG_MCLKDPM_SetEnabledMask,
2961 static int smu7_upload_dpm_level_enable_mask(struct pp_hwmgr *hwmgr)
2963 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2965 if (hwmgr->pp_table_version == PP_TABLE_V1)
2966 phm_apply_dal_min_voltage_request(hwmgr);
2967 /* TO DO for v0 iceland and Ci*/
2969 if (!data->sclk_dpm_key_disabled) {
2970 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask)
2971 smum_send_msg_to_smc_with_parameter(hwmgr,
2972 PPSMC_MSG_SCLKDPM_SetEnabledMask,
2973 data->dpm_level_enable_mask.sclk_dpm_enable_mask,
2977 if (!data->mclk_dpm_key_disabled) {
2978 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask)
2979 smum_send_msg_to_smc_with_parameter(hwmgr,
2980 PPSMC_MSG_MCLKDPM_SetEnabledMask,
2981 data->dpm_level_enable_mask.mclk_dpm_enable_mask,
2988 static int smu7_unforce_dpm_levels(struct pp_hwmgr *hwmgr)
2990 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2992 if (!smum_is_dpm_running(hwmgr))
2995 if (!data->pcie_dpm_key_disabled) {
2996 smum_send_msg_to_smc(hwmgr,
2997 PPSMC_MSG_PCIeDPM_UnForceLevel,
3001 return smu7_upload_dpm_level_enable_mask(hwmgr);
3004 static int smu7_force_dpm_lowest(struct pp_hwmgr *hwmgr)
3006 struct smu7_hwmgr *data =
3007 (struct smu7_hwmgr *)(hwmgr->backend);
3010 if (!data->sclk_dpm_key_disabled)
3011 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
3012 level = phm_get_lowest_enabled_level(hwmgr,
3013 data->dpm_level_enable_mask.sclk_dpm_enable_mask);
3014 smum_send_msg_to_smc_with_parameter(hwmgr,
3015 PPSMC_MSG_SCLKDPM_SetEnabledMask,
3021 if (!data->mclk_dpm_key_disabled) {
3022 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
3023 level = phm_get_lowest_enabled_level(hwmgr,
3024 data->dpm_level_enable_mask.mclk_dpm_enable_mask);
3025 smum_send_msg_to_smc_with_parameter(hwmgr,
3026 PPSMC_MSG_MCLKDPM_SetEnabledMask,
3032 if (!data->pcie_dpm_key_disabled) {
3033 if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) {
3034 level = phm_get_lowest_enabled_level(hwmgr,
3035 data->dpm_level_enable_mask.pcie_dpm_enable_mask);
3036 smum_send_msg_to_smc_with_parameter(hwmgr,
3037 PPSMC_MSG_PCIeDPM_ForceLevel,
3046 static int smu7_get_profiling_clk(struct pp_hwmgr *hwmgr, enum amd_dpm_forced_level level,
3047 uint32_t *sclk_mask, uint32_t *mclk_mask, uint32_t *pcie_mask)
3049 uint32_t percentage;
3050 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3051 struct smu7_dpm_table *golden_dpm_table = &data->golden_dpm_table;
3056 if (golden_dpm_table->mclk_table.count < 1)
3059 percentage = 100 * golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count - 1].value /
3060 golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count - 1].value;
3062 if (golden_dpm_table->mclk_table.count == 1) {
3064 tmp_mclk = golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count - 1].value;
3065 *mclk_mask = golden_dpm_table->mclk_table.count - 1;
3067 tmp_mclk = golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count - 2].value;
3068 *mclk_mask = golden_dpm_table->mclk_table.count - 2;
3071 tmp_sclk = tmp_mclk * percentage / 100;
3073 if (hwmgr->pp_table_version == PP_TABLE_V0) {
3074 for (count = hwmgr->dyn_state.vddc_dependency_on_sclk->count-1;
3075 count >= 0; count--) {
3076 if (tmp_sclk >= hwmgr->dyn_state.vddc_dependency_on_sclk->entries[count].clk) {
3077 tmp_sclk = hwmgr->dyn_state.vddc_dependency_on_sclk->entries[count].clk;
3082 if (count < 0 || level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) {
3084 tmp_sclk = hwmgr->dyn_state.vddc_dependency_on_sclk->entries[0].clk;
3087 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
3088 *sclk_mask = hwmgr->dyn_state.vddc_dependency_on_sclk->count-1;
3089 } else if (hwmgr->pp_table_version == PP_TABLE_V1) {
3090 struct phm_ppt_v1_information *table_info =
3091 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3093 for (count = table_info->vdd_dep_on_sclk->count-1; count >= 0; count--) {
3094 if (tmp_sclk >= table_info->vdd_dep_on_sclk->entries[count].clk) {
3095 tmp_sclk = table_info->vdd_dep_on_sclk->entries[count].clk;
3100 if (count < 0 || level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) {
3102 tmp_sclk = table_info->vdd_dep_on_sclk->entries[0].clk;
3105 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
3106 *sclk_mask = table_info->vdd_dep_on_sclk->count - 1;
3109 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK)
3111 else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
3112 *mclk_mask = golden_dpm_table->mclk_table.count - 1;
3114 *pcie_mask = data->dpm_table.pcie_speed_table.count - 1;
3115 hwmgr->pstate_sclk = tmp_sclk;
3116 hwmgr->pstate_mclk = tmp_mclk;
3121 static int smu7_force_dpm_level(struct pp_hwmgr *hwmgr,
3122 enum amd_dpm_forced_level level)
3125 uint32_t sclk_mask = 0;
3126 uint32_t mclk_mask = 0;
3127 uint32_t pcie_mask = 0;
3129 if (hwmgr->pstate_sclk == 0)
3130 smu7_get_profiling_clk(hwmgr, level, &sclk_mask, &mclk_mask, &pcie_mask);
3133 case AMD_DPM_FORCED_LEVEL_HIGH:
3134 ret = smu7_force_dpm_highest(hwmgr);
3136 case AMD_DPM_FORCED_LEVEL_LOW:
3137 ret = smu7_force_dpm_lowest(hwmgr);
3139 case AMD_DPM_FORCED_LEVEL_AUTO:
3140 ret = smu7_unforce_dpm_levels(hwmgr);
3142 case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:
3143 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
3144 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:
3145 case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:
3146 ret = smu7_get_profiling_clk(hwmgr, level, &sclk_mask, &mclk_mask, &pcie_mask);
3149 smu7_force_clock_level(hwmgr, PP_SCLK, 1<<sclk_mask);
3150 smu7_force_clock_level(hwmgr, PP_MCLK, 1<<mclk_mask);
3151 smu7_force_clock_level(hwmgr, PP_PCIE, 1<<pcie_mask);
3153 case AMD_DPM_FORCED_LEVEL_MANUAL:
3154 case AMD_DPM_FORCED_LEVEL_PROFILE_EXIT:
3160 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK && hwmgr->dpm_level != AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
3161 smu7_fan_ctrl_set_fan_speed_percent(hwmgr, 100);
3162 else if (level != AMD_DPM_FORCED_LEVEL_PROFILE_PEAK && hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
3163 smu7_fan_ctrl_reset_fan_speed_to_default(hwmgr);
3168 static int smu7_get_power_state_size(struct pp_hwmgr *hwmgr)
3170 return sizeof(struct smu7_power_state);
3173 static int smu7_vblank_too_short(struct pp_hwmgr *hwmgr,
3174 uint32_t vblank_time_us)
3176 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3177 uint32_t switch_limit_us;
3179 switch (hwmgr->chip_id) {
3180 case CHIP_POLARIS10:
3181 case CHIP_POLARIS11:
3182 case CHIP_POLARIS12:
3183 if (hwmgr->is_kicker || (hwmgr->chip_id == CHIP_POLARIS12))
3184 switch_limit_us = data->is_memory_gddr5 ? 450 : 150;
3186 switch_limit_us = data->is_memory_gddr5 ? 200 : 150;
3189 switch_limit_us = 30;
3192 switch_limit_us = data->is_memory_gddr5 ? 450 : 150;
3196 if (vblank_time_us < switch_limit_us)
3202 static int smu7_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
3203 struct pp_power_state *request_ps,
3204 const struct pp_power_state *current_ps)
3206 struct amdgpu_device *adev = hwmgr->adev;
3207 struct smu7_power_state *smu7_ps =
3208 cast_phw_smu7_power_state(&request_ps->hardware);
3211 struct PP_Clocks minimum_clocks = {0};
3212 bool disable_mclk_switching;
3213 bool disable_mclk_switching_for_frame_lock;
3214 bool disable_mclk_switching_for_display;
3215 const struct phm_clock_and_voltage_limits *max_limits;
3217 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3218 struct phm_ppt_v1_information *table_info =
3219 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3221 int32_t stable_pstate_sclk = 0, stable_pstate_mclk = 0;
3223 bool latency_allowed = false;
3225 data->battery_state = (PP_StateUILabel_Battery ==
3226 request_ps->classification.ui_label);
3227 data->mclk_ignore_signal = false;
3229 PP_ASSERT_WITH_CODE(smu7_ps->performance_level_count == 2,
3230 "VI should always have 2 performance levels",
3233 max_limits = adev->pm.ac_power ?
3234 &(hwmgr->dyn_state.max_clock_voltage_on_ac) :
3235 &(hwmgr->dyn_state.max_clock_voltage_on_dc);
3237 /* Cap clock DPM tables at DC MAX if it is in DC. */
3238 if (!adev->pm.ac_power) {
3239 for (i = 0; i < smu7_ps->performance_level_count; i++) {
3240 if (smu7_ps->performance_levels[i].memory_clock > max_limits->mclk)
3241 smu7_ps->performance_levels[i].memory_clock = max_limits->mclk;
3242 if (smu7_ps->performance_levels[i].engine_clock > max_limits->sclk)
3243 smu7_ps->performance_levels[i].engine_clock = max_limits->sclk;
3247 minimum_clocks.engineClock = hwmgr->display_config->min_core_set_clock;
3248 minimum_clocks.memoryClock = hwmgr->display_config->min_mem_set_clock;
3250 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3251 PHM_PlatformCaps_StablePState)) {
3252 max_limits = &(hwmgr->dyn_state.max_clock_voltage_on_ac);
3253 stable_pstate_sclk = (max_limits->sclk * 75) / 100;
3255 for (count = table_info->vdd_dep_on_sclk->count - 1;
3256 count >= 0; count--) {
3257 if (stable_pstate_sclk >=
3258 table_info->vdd_dep_on_sclk->entries[count].clk) {
3259 stable_pstate_sclk =
3260 table_info->vdd_dep_on_sclk->entries[count].clk;
3266 stable_pstate_sclk = table_info->vdd_dep_on_sclk->entries[0].clk;
3268 stable_pstate_mclk = max_limits->mclk;
3270 minimum_clocks.engineClock = stable_pstate_sclk;
3271 minimum_clocks.memoryClock = stable_pstate_mclk;
3274 disable_mclk_switching_for_frame_lock = phm_cap_enabled(
3275 hwmgr->platform_descriptor.platformCaps,
3276 PHM_PlatformCaps_DisableMclkSwitchingForFrameLock);
3278 disable_mclk_switching_for_display = ((1 < hwmgr->display_config->num_display) &&
3279 !hwmgr->display_config->multi_monitor_in_sync) ||
3280 smu7_vblank_too_short(hwmgr, hwmgr->display_config->min_vblank_time);
3282 disable_mclk_switching = disable_mclk_switching_for_frame_lock ||
3283 disable_mclk_switching_for_display;
3285 if (hwmgr->display_config->num_display == 0) {
3286 if (hwmgr->chip_id >= CHIP_POLARIS10 && hwmgr->chip_id <= CHIP_VEGAM)
3287 data->mclk_ignore_signal = true;
3289 disable_mclk_switching = false;
3292 sclk = smu7_ps->performance_levels[0].engine_clock;
3293 mclk = smu7_ps->performance_levels[0].memory_clock;
3295 if (disable_mclk_switching &&
3296 (!(hwmgr->chip_id >= CHIP_POLARIS10 &&
3297 hwmgr->chip_id <= CHIP_VEGAM)))
3298 mclk = smu7_ps->performance_levels
3299 [smu7_ps->performance_level_count - 1].memory_clock;
3301 if (sclk < minimum_clocks.engineClock)
3302 sclk = (minimum_clocks.engineClock > max_limits->sclk) ?
3303 max_limits->sclk : minimum_clocks.engineClock;
3305 if (mclk < minimum_clocks.memoryClock)
3306 mclk = (minimum_clocks.memoryClock > max_limits->mclk) ?
3307 max_limits->mclk : minimum_clocks.memoryClock;
3309 smu7_ps->performance_levels[0].engine_clock = sclk;
3310 smu7_ps->performance_levels[0].memory_clock = mclk;
3312 smu7_ps->performance_levels[1].engine_clock =
3313 (smu7_ps->performance_levels[1].engine_clock >=
3314 smu7_ps->performance_levels[0].engine_clock) ?
3315 smu7_ps->performance_levels[1].engine_clock :
3316 smu7_ps->performance_levels[0].engine_clock;
3318 if (disable_mclk_switching) {
3319 if (mclk < smu7_ps->performance_levels[1].memory_clock)
3320 mclk = smu7_ps->performance_levels[1].memory_clock;
3322 if (hwmgr->chip_id >= CHIP_POLARIS10 && hwmgr->chip_id <= CHIP_VEGAM) {
3323 if (disable_mclk_switching_for_display) {
3324 /* Find the lowest MCLK frequency that is within
3325 * the tolerable latency defined in DAL
3327 latency = hwmgr->display_config->dce_tolerable_mclk_in_active_latency;
3328 for (i = 0; i < data->mclk_latency_table.count; i++) {
3329 if (data->mclk_latency_table.entries[i].latency <= latency) {
3330 latency_allowed = true;
3332 if ((data->mclk_latency_table.entries[i].frequency >=
3333 smu7_ps->performance_levels[0].memory_clock) &&
3334 (data->mclk_latency_table.entries[i].frequency <=
3335 smu7_ps->performance_levels[1].memory_clock)) {
3336 mclk = data->mclk_latency_table.entries[i].frequency;
3341 if ((i >= data->mclk_latency_table.count - 1) && !latency_allowed) {
3342 data->mclk_ignore_signal = true;
3344 data->mclk_ignore_signal = false;
3348 if (disable_mclk_switching_for_frame_lock)
3349 mclk = smu7_ps->performance_levels[1].memory_clock;
3352 smu7_ps->performance_levels[0].memory_clock = mclk;
3354 if (!(hwmgr->chip_id >= CHIP_POLARIS10 &&
3355 hwmgr->chip_id <= CHIP_VEGAM))
3356 smu7_ps->performance_levels[1].memory_clock = mclk;
3358 if (smu7_ps->performance_levels[1].memory_clock <
3359 smu7_ps->performance_levels[0].memory_clock)
3360 smu7_ps->performance_levels[1].memory_clock =
3361 smu7_ps->performance_levels[0].memory_clock;
3364 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3365 PHM_PlatformCaps_StablePState)) {
3366 for (i = 0; i < smu7_ps->performance_level_count; i++) {
3367 smu7_ps->performance_levels[i].engine_clock = stable_pstate_sclk;
3368 smu7_ps->performance_levels[i].memory_clock = stable_pstate_mclk;
3369 smu7_ps->performance_levels[i].pcie_gen = data->pcie_gen_performance.max;
3370 smu7_ps->performance_levels[i].pcie_lane = data->pcie_gen_performance.max;
3377 static uint32_t smu7_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)
3379 struct pp_power_state *ps;
3380 struct smu7_power_state *smu7_ps;
3385 ps = hwmgr->request_ps;
3390 smu7_ps = cast_phw_smu7_power_state(&ps->hardware);
3393 return smu7_ps->performance_levels[0].memory_clock;
3395 return smu7_ps->performance_levels
3396 [smu7_ps->performance_level_count-1].memory_clock;
3399 static uint32_t smu7_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)
3401 struct pp_power_state *ps;
3402 struct smu7_power_state *smu7_ps;
3407 ps = hwmgr->request_ps;
3412 smu7_ps = cast_phw_smu7_power_state(&ps->hardware);
3415 return smu7_ps->performance_levels[0].engine_clock;
3417 return smu7_ps->performance_levels
3418 [smu7_ps->performance_level_count-1].engine_clock;
3421 static int smu7_dpm_patch_boot_state(struct pp_hwmgr *hwmgr,
3422 struct pp_hw_power_state *hw_ps)
3424 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3425 struct smu7_power_state *ps = (struct smu7_power_state *)hw_ps;
3426 ATOM_FIRMWARE_INFO_V2_2 *fw_info;
3429 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
3431 /* First retrieve the Boot clocks and VDDC from the firmware info table.
3432 * We assume here that fw_info is unchanged if this call fails.
3434 fw_info = (ATOM_FIRMWARE_INFO_V2_2 *)smu_atom_get_data_table(hwmgr->adev, index,
3435 &size, &frev, &crev);
3437 /* During a test, there is no firmware info table. */
3440 /* Patch the state. */
3441 data->vbios_boot_state.sclk_bootup_value =
3442 le32_to_cpu(fw_info->ulDefaultEngineClock);
3443 data->vbios_boot_state.mclk_bootup_value =
3444 le32_to_cpu(fw_info->ulDefaultMemoryClock);
3445 data->vbios_boot_state.mvdd_bootup_value =
3446 le16_to_cpu(fw_info->usBootUpMVDDCVoltage);
3447 data->vbios_boot_state.vddc_bootup_value =
3448 le16_to_cpu(fw_info->usBootUpVDDCVoltage);
3449 data->vbios_boot_state.vddci_bootup_value =
3450 le16_to_cpu(fw_info->usBootUpVDDCIVoltage);
3451 data->vbios_boot_state.pcie_gen_bootup_value =
3452 smu7_get_current_pcie_speed(hwmgr);
3454 data->vbios_boot_state.pcie_lane_bootup_value =
3455 (uint16_t)smu7_get_current_pcie_lane_number(hwmgr);
3457 /* set boot power state */
3458 ps->performance_levels[0].memory_clock = data->vbios_boot_state.mclk_bootup_value;
3459 ps->performance_levels[0].engine_clock = data->vbios_boot_state.sclk_bootup_value;
3460 ps->performance_levels[0].pcie_gen = data->vbios_boot_state.pcie_gen_bootup_value;
3461 ps->performance_levels[0].pcie_lane = data->vbios_boot_state.pcie_lane_bootup_value;
3466 static int smu7_get_number_of_powerplay_table_entries(struct pp_hwmgr *hwmgr)
3469 unsigned long ret = 0;
3471 if (hwmgr->pp_table_version == PP_TABLE_V0) {
3472 result = pp_tables_get_num_of_entries(hwmgr, &ret);
3473 return result ? 0 : ret;
3474 } else if (hwmgr->pp_table_version == PP_TABLE_V1) {
3475 result = get_number_of_powerplay_table_entries_v1_0(hwmgr);
3481 static int smu7_get_pp_table_entry_callback_func_v1(struct pp_hwmgr *hwmgr,
3482 void *state, struct pp_power_state *power_state,
3483 void *pp_table, uint32_t classification_flag)
3485 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3486 struct smu7_power_state *smu7_power_state =
3487 (struct smu7_power_state *)(&(power_state->hardware));
3488 struct smu7_performance_level *performance_level;
3489 ATOM_Tonga_State *state_entry = (ATOM_Tonga_State *)state;
3490 ATOM_Tonga_POWERPLAYTABLE *powerplay_table =
3491 (ATOM_Tonga_POWERPLAYTABLE *)pp_table;
3492 PPTable_Generic_SubTable_Header *sclk_dep_table =
3493 (PPTable_Generic_SubTable_Header *)
3494 (((unsigned long)powerplay_table) +
3495 le16_to_cpu(powerplay_table->usSclkDependencyTableOffset));
3497 ATOM_Tonga_MCLK_Dependency_Table *mclk_dep_table =
3498 (ATOM_Tonga_MCLK_Dependency_Table *)
3499 (((unsigned long)powerplay_table) +
3500 le16_to_cpu(powerplay_table->usMclkDependencyTableOffset));
3502 /* The following fields are not initialized here: id orderedList allStatesList */
3503 power_state->classification.ui_label =
3504 (le16_to_cpu(state_entry->usClassification) &
3505 ATOM_PPLIB_CLASSIFICATION_UI_MASK) >>
3506 ATOM_PPLIB_CLASSIFICATION_UI_SHIFT;
3507 power_state->classification.flags = classification_flag;
3508 /* NOTE: There is a classification2 flag in BIOS that is not being used right now */
3510 power_state->classification.temporary_state = false;
3511 power_state->classification.to_be_deleted = false;
3513 power_state->validation.disallowOnDC =
3514 (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) &
3515 ATOM_Tonga_DISALLOW_ON_DC));
3517 power_state->pcie.lanes = 0;
3519 power_state->display.disableFrameModulation = false;
3520 power_state->display.limitRefreshrate = false;
3521 power_state->display.enableVariBright =
3522 (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) &
3523 ATOM_Tonga_ENABLE_VARIBRIGHT));
3525 power_state->validation.supportedPowerLevels = 0;
3526 power_state->uvd_clocks.VCLK = 0;
3527 power_state->uvd_clocks.DCLK = 0;
3528 power_state->temperatures.min = 0;
3529 power_state->temperatures.max = 0;
3531 performance_level = &(smu7_power_state->performance_levels
3532 [smu7_power_state->performance_level_count++]);
3534 PP_ASSERT_WITH_CODE(
3535 (smu7_power_state->performance_level_count < smum_get_mac_definition(hwmgr, SMU_MAX_LEVELS_GRAPHICS)),
3536 "Performance levels exceeds SMC limit!",
3539 PP_ASSERT_WITH_CODE(
3540 (smu7_power_state->performance_level_count <=
3541 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels),
3542 "Performance levels exceeds Driver limit!",
3545 /* Performance levels are arranged from low to high. */
3546 performance_level->memory_clock = mclk_dep_table->entries
3547 [state_entry->ucMemoryClockIndexLow].ulMclk;
3548 if (sclk_dep_table->ucRevId == 0)
3549 performance_level->engine_clock = ((ATOM_Tonga_SCLK_Dependency_Table *)sclk_dep_table)->entries
3550 [state_entry->ucEngineClockIndexLow].ulSclk;
3551 else if (sclk_dep_table->ucRevId == 1)
3552 performance_level->engine_clock = ((ATOM_Polaris_SCLK_Dependency_Table *)sclk_dep_table)->entries
3553 [state_entry->ucEngineClockIndexLow].ulSclk;
3554 performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap,
3555 state_entry->ucPCIEGenLow);
3556 performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap,
3557 state_entry->ucPCIELaneLow);
3559 performance_level = &(smu7_power_state->performance_levels
3560 [smu7_power_state->performance_level_count++]);
3561 performance_level->memory_clock = mclk_dep_table->entries
3562 [state_entry->ucMemoryClockIndexHigh].ulMclk;
3564 if (sclk_dep_table->ucRevId == 0)
3565 performance_level->engine_clock = ((ATOM_Tonga_SCLK_Dependency_Table *)sclk_dep_table)->entries
3566 [state_entry->ucEngineClockIndexHigh].ulSclk;
3567 else if (sclk_dep_table->ucRevId == 1)
3568 performance_level->engine_clock = ((ATOM_Polaris_SCLK_Dependency_Table *)sclk_dep_table)->entries
3569 [state_entry->ucEngineClockIndexHigh].ulSclk;
3571 performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap,
3572 state_entry->ucPCIEGenHigh);
3573 performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap,
3574 state_entry->ucPCIELaneHigh);
3579 static int smu7_get_pp_table_entry_v1(struct pp_hwmgr *hwmgr,
3580 unsigned long entry_index, struct pp_power_state *state)
3583 struct smu7_power_state *ps;
3584 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3585 struct phm_ppt_v1_information *table_info =
3586 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3587 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
3588 table_info->vdd_dep_on_mclk;
3590 state->hardware.magic = PHM_VIslands_Magic;
3592 ps = (struct smu7_power_state *)(&state->hardware);
3594 result = get_powerplay_table_entry_v1_0(hwmgr, entry_index, state,
3595 smu7_get_pp_table_entry_callback_func_v1);
3597 /* This is the earliest time we have all the dependency table and the VBIOS boot state
3598 * as PP_Tables_GetPowerPlayTableEntry retrieves the VBIOS boot state
3599 * if there is only one VDDCI/MCLK level, check if it's the same as VBIOS boot state
3601 if (dep_mclk_table != NULL && dep_mclk_table->count == 1) {
3602 if (dep_mclk_table->entries[0].clk !=
3603 data->vbios_boot_state.mclk_bootup_value)
3604 pr_debug("Single MCLK entry VDDCI/MCLK dependency table "
3605 "does not match VBIOS boot MCLK level");
3606 if (dep_mclk_table->entries[0].vddci !=
3607 data->vbios_boot_state.vddci_bootup_value)
3608 pr_debug("Single VDDCI entry VDDCI/MCLK dependency table "
3609 "does not match VBIOS boot VDDCI level");
3612 /* set DC compatible flag if this state supports DC */
3613 if (!state->validation.disallowOnDC)
3614 ps->dc_compatible = true;
3616 if (state->classification.flags & PP_StateClassificationFlag_ACPI)
3617 data->acpi_pcie_gen = ps->performance_levels[0].pcie_gen;
3619 ps->uvd_clks.vclk = state->uvd_clocks.VCLK;
3620 ps->uvd_clks.dclk = state->uvd_clocks.DCLK;
3625 switch (state->classification.ui_label) {
3626 case PP_StateUILabel_Performance:
3627 data->use_pcie_performance_levels = true;
3628 for (i = 0; i < ps->performance_level_count; i++) {
3629 if (data->pcie_gen_performance.max <
3630 ps->performance_levels[i].pcie_gen)
3631 data->pcie_gen_performance.max =
3632 ps->performance_levels[i].pcie_gen;
3634 if (data->pcie_gen_performance.min >
3635 ps->performance_levels[i].pcie_gen)
3636 data->pcie_gen_performance.min =
3637 ps->performance_levels[i].pcie_gen;
3639 if (data->pcie_lane_performance.max <
3640 ps->performance_levels[i].pcie_lane)
3641 data->pcie_lane_performance.max =
3642 ps->performance_levels[i].pcie_lane;
3643 if (data->pcie_lane_performance.min >
3644 ps->performance_levels[i].pcie_lane)
3645 data->pcie_lane_performance.min =
3646 ps->performance_levels[i].pcie_lane;
3649 case PP_StateUILabel_Battery:
3650 data->use_pcie_power_saving_levels = true;
3652 for (i = 0; i < ps->performance_level_count; i++) {
3653 if (data->pcie_gen_power_saving.max <
3654 ps->performance_levels[i].pcie_gen)
3655 data->pcie_gen_power_saving.max =
3656 ps->performance_levels[i].pcie_gen;
3658 if (data->pcie_gen_power_saving.min >
3659 ps->performance_levels[i].pcie_gen)
3660 data->pcie_gen_power_saving.min =
3661 ps->performance_levels[i].pcie_gen;
3663 if (data->pcie_lane_power_saving.max <
3664 ps->performance_levels[i].pcie_lane)
3665 data->pcie_lane_power_saving.max =
3666 ps->performance_levels[i].pcie_lane;
3668 if (data->pcie_lane_power_saving.min >
3669 ps->performance_levels[i].pcie_lane)
3670 data->pcie_lane_power_saving.min =
3671 ps->performance_levels[i].pcie_lane;
3681 static int smu7_get_pp_table_entry_callback_func_v0(struct pp_hwmgr *hwmgr,
3682 struct pp_hw_power_state *power_state,
3683 unsigned int index, const void *clock_info)
3685 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3686 struct smu7_power_state *ps = cast_phw_smu7_power_state(power_state);
3687 const ATOM_PPLIB_CI_CLOCK_INFO *visland_clk_info = clock_info;
3688 struct smu7_performance_level *performance_level;
3689 uint32_t engine_clock, memory_clock;
3690 uint16_t pcie_gen_from_bios;
3692 engine_clock = visland_clk_info->ucEngineClockHigh << 16 | visland_clk_info->usEngineClockLow;
3693 memory_clock = visland_clk_info->ucMemoryClockHigh << 16 | visland_clk_info->usMemoryClockLow;
3695 if (!(data->mc_micro_code_feature & DISABLE_MC_LOADMICROCODE) && memory_clock > data->highest_mclk)
3696 data->highest_mclk = memory_clock;
3698 PP_ASSERT_WITH_CODE(
3699 (ps->performance_level_count < smum_get_mac_definition(hwmgr, SMU_MAX_LEVELS_GRAPHICS)),
3700 "Performance levels exceeds SMC limit!",
3703 PP_ASSERT_WITH_CODE(
3704 (ps->performance_level_count <
3705 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels),
3706 "Performance levels exceeds Driver limit, Skip!",
3709 performance_level = &(ps->performance_levels
3710 [ps->performance_level_count++]);
3712 /* Performance levels are arranged from low to high. */
3713 performance_level->memory_clock = memory_clock;
3714 performance_level->engine_clock = engine_clock;
3716 pcie_gen_from_bios = visland_clk_info->ucPCIEGen;
3718 performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap, pcie_gen_from_bios);
3719 performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap, visland_clk_info->usPCIELane);
3724 static int smu7_get_pp_table_entry_v0(struct pp_hwmgr *hwmgr,
3725 unsigned long entry_index, struct pp_power_state *state)
3728 struct smu7_power_state *ps;
3729 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3730 struct phm_clock_voltage_dependency_table *dep_mclk_table =
3731 hwmgr->dyn_state.vddci_dependency_on_mclk;
3733 memset(&state->hardware, 0x00, sizeof(struct pp_hw_power_state));
3735 state->hardware.magic = PHM_VIslands_Magic;
3737 ps = (struct smu7_power_state *)(&state->hardware);
3739 result = pp_tables_get_entry(hwmgr, entry_index, state,
3740 smu7_get_pp_table_entry_callback_func_v0);
3743 * This is the earliest time we have all the dependency table
3744 * and the VBIOS boot state as
3745 * PP_Tables_GetPowerPlayTableEntry retrieves the VBIOS boot
3746 * state if there is only one VDDCI/MCLK level, check if it's
3747 * the same as VBIOS boot state
3749 if (dep_mclk_table != NULL && dep_mclk_table->count == 1) {
3750 if (dep_mclk_table->entries[0].clk !=
3751 data->vbios_boot_state.mclk_bootup_value)
3752 pr_debug("Single MCLK entry VDDCI/MCLK dependency table "
3753 "does not match VBIOS boot MCLK level");
3754 if (dep_mclk_table->entries[0].v !=
3755 data->vbios_boot_state.vddci_bootup_value)
3756 pr_debug("Single VDDCI entry VDDCI/MCLK dependency table "
3757 "does not match VBIOS boot VDDCI level");
3760 /* set DC compatible flag if this state supports DC */
3761 if (!state->validation.disallowOnDC)
3762 ps->dc_compatible = true;
3764 if (state->classification.flags & PP_StateClassificationFlag_ACPI)
3765 data->acpi_pcie_gen = ps->performance_levels[0].pcie_gen;
3767 ps->uvd_clks.vclk = state->uvd_clocks.VCLK;
3768 ps->uvd_clks.dclk = state->uvd_clocks.DCLK;
3773 switch (state->classification.ui_label) {
3774 case PP_StateUILabel_Performance:
3775 data->use_pcie_performance_levels = true;
3777 for (i = 0; i < ps->performance_level_count; i++) {
3778 if (data->pcie_gen_performance.max <
3779 ps->performance_levels[i].pcie_gen)
3780 data->pcie_gen_performance.max =
3781 ps->performance_levels[i].pcie_gen;
3783 if (data->pcie_gen_performance.min >
3784 ps->performance_levels[i].pcie_gen)
3785 data->pcie_gen_performance.min =
3786 ps->performance_levels[i].pcie_gen;
3788 if (data->pcie_lane_performance.max <
3789 ps->performance_levels[i].pcie_lane)
3790 data->pcie_lane_performance.max =
3791 ps->performance_levels[i].pcie_lane;
3793 if (data->pcie_lane_performance.min >
3794 ps->performance_levels[i].pcie_lane)
3795 data->pcie_lane_performance.min =
3796 ps->performance_levels[i].pcie_lane;
3799 case PP_StateUILabel_Battery:
3800 data->use_pcie_power_saving_levels = true;
3802 for (i = 0; i < ps->performance_level_count; i++) {
3803 if (data->pcie_gen_power_saving.max <
3804 ps->performance_levels[i].pcie_gen)
3805 data->pcie_gen_power_saving.max =
3806 ps->performance_levels[i].pcie_gen;
3808 if (data->pcie_gen_power_saving.min >
3809 ps->performance_levels[i].pcie_gen)
3810 data->pcie_gen_power_saving.min =
3811 ps->performance_levels[i].pcie_gen;
3813 if (data->pcie_lane_power_saving.max <
3814 ps->performance_levels[i].pcie_lane)
3815 data->pcie_lane_power_saving.max =
3816 ps->performance_levels[i].pcie_lane;
3818 if (data->pcie_lane_power_saving.min >
3819 ps->performance_levels[i].pcie_lane)
3820 data->pcie_lane_power_saving.min =
3821 ps->performance_levels[i].pcie_lane;
3831 static int smu7_get_pp_table_entry(struct pp_hwmgr *hwmgr,
3832 unsigned long entry_index, struct pp_power_state *state)
3834 if (hwmgr->pp_table_version == PP_TABLE_V0)
3835 return smu7_get_pp_table_entry_v0(hwmgr, entry_index, state);
3836 else if (hwmgr->pp_table_version == PP_TABLE_V1)
3837 return smu7_get_pp_table_entry_v1(hwmgr, entry_index, state);
3842 static int smu7_get_gpu_power(struct pp_hwmgr *hwmgr, u32 *query)
3844 struct amdgpu_device *adev = hwmgr->adev;
3852 * PPSMC_MSG_GetCurrPkgPwr is not supported on:
3858 if ((adev->asic_type != CHIP_HAWAII) &&
3859 (adev->asic_type != CHIP_BONAIRE) &&
3860 (adev->asic_type != CHIP_FIJI) &&
3861 (adev->asic_type != CHIP_TONGA)) {
3862 smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_GetCurrPkgPwr, 0, &tmp);
3869 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_PmStatusLogStart, NULL);
3870 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3871 ixSMU_PM_STATUS_95, 0);
3873 for (i = 0; i < 10; i++) {
3875 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_PmStatusLogSample, NULL);
3876 tmp = cgs_read_ind_register(hwmgr->device,
3878 ixSMU_PM_STATUS_95);
3887 static int smu7_read_sensor(struct pp_hwmgr *hwmgr, int idx,
3888 void *value, int *size)
3890 uint32_t sclk, mclk, activity_percent;
3891 uint32_t offset, val_vid;
3892 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3894 /* size must be at least 4 bytes for all sensors */
3899 case AMDGPU_PP_SENSOR_GFX_SCLK:
3900 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_API_GetSclkFrequency, &sclk);
3901 *((uint32_t *)value) = sclk;
3904 case AMDGPU_PP_SENSOR_GFX_MCLK:
3905 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_API_GetMclkFrequency, &mclk);
3906 *((uint32_t *)value) = mclk;
3909 case AMDGPU_PP_SENSOR_GPU_LOAD:
3910 case AMDGPU_PP_SENSOR_MEM_LOAD:
3911 offset = data->soft_regs_start + smum_get_offsetof(hwmgr,
3913 (idx == AMDGPU_PP_SENSOR_GPU_LOAD) ?
3914 AverageGraphicsActivity:
3915 AverageMemoryActivity);
3917 activity_percent = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, offset);
3918 activity_percent += 0x80;
3919 activity_percent >>= 8;
3920 *((uint32_t *)value) = activity_percent > 100 ? 100 : activity_percent;
3923 case AMDGPU_PP_SENSOR_GPU_TEMP:
3924 *((uint32_t *)value) = smu7_thermal_get_temperature(hwmgr);
3927 case AMDGPU_PP_SENSOR_UVD_POWER:
3928 *((uint32_t *)value) = data->uvd_power_gated ? 0 : 1;
3931 case AMDGPU_PP_SENSOR_VCE_POWER:
3932 *((uint32_t *)value) = data->vce_power_gated ? 0 : 1;
3935 case AMDGPU_PP_SENSOR_GPU_POWER:
3936 return smu7_get_gpu_power(hwmgr, (uint32_t *)value);
3937 case AMDGPU_PP_SENSOR_VDDGFX:
3938 if ((data->vr_config & VRCONF_VDDGFX_MASK) ==
3939 (VR_SVI2_PLANE_2 << VRCONF_VDDGFX_SHIFT))
3940 val_vid = PHM_READ_INDIRECT_FIELD(hwmgr->device,
3941 CGS_IND_REG__SMC, PWR_SVI2_STATUS, PLANE2_VID);
3943 val_vid = PHM_READ_INDIRECT_FIELD(hwmgr->device,
3944 CGS_IND_REG__SMC, PWR_SVI2_STATUS, PLANE1_VID);
3946 *((uint32_t *)value) = (uint32_t)convert_to_vddc(val_vid);
3953 static int smu7_find_dpm_states_clocks_in_dpm_table(struct pp_hwmgr *hwmgr, const void *input)
3955 const struct phm_set_power_state_input *states =
3956 (const struct phm_set_power_state_input *)input;
3957 const struct smu7_power_state *smu7_ps =
3958 cast_const_phw_smu7_power_state(states->pnew_state);
3959 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
3960 struct smu7_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
3961 uint32_t sclk = smu7_ps->performance_levels
3962 [smu7_ps->performance_level_count - 1].engine_clock;
3963 struct smu7_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
3964 uint32_t mclk = smu7_ps->performance_levels
3965 [smu7_ps->performance_level_count - 1].memory_clock;
3966 struct PP_Clocks min_clocks = {0};
3969 for (i = 0; i < sclk_table->count; i++) {
3970 if (sclk == sclk_table->dpm_levels[i].value)
3974 if (i >= sclk_table->count) {
3975 if (sclk > sclk_table->dpm_levels[i-1].value) {
3976 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK;
3977 sclk_table->dpm_levels[i-1].value = sclk;
3980 /* TODO: Check SCLK in DAL's minimum clocks
3981 * in case DeepSleep divider update is required.
3983 if (data->display_timing.min_clock_in_sr != min_clocks.engineClockInSR &&
3984 (min_clocks.engineClockInSR >= SMU7_MINIMUM_ENGINE_CLOCK ||
3985 data->display_timing.min_clock_in_sr >= SMU7_MINIMUM_ENGINE_CLOCK))
3986 data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_SCLK;
3989 for (i = 0; i < mclk_table->count; i++) {
3990 if (mclk == mclk_table->dpm_levels[i].value)
3994 if (i >= mclk_table->count) {
3995 if (mclk > mclk_table->dpm_levels[i-1].value) {
3996 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_MCLK;
3997 mclk_table->dpm_levels[i-1].value = mclk;
4001 if (data->display_timing.num_existing_displays != hwmgr->display_config->num_display)
4002 data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_MCLK;
4007 static uint16_t smu7_get_maximum_link_speed(struct pp_hwmgr *hwmgr,
4008 const struct smu7_power_state *smu7_ps)
4011 uint32_t sclk, max_sclk = 0;
4012 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4013 struct smu7_dpm_table *dpm_table = &data->dpm_table;
4015 for (i = 0; i < smu7_ps->performance_level_count; i++) {
4016 sclk = smu7_ps->performance_levels[i].engine_clock;
4017 if (max_sclk < sclk)
4021 for (i = 0; i < dpm_table->sclk_table.count; i++) {
4022 if (dpm_table->sclk_table.dpm_levels[i].value == max_sclk)
4023 return (uint16_t) ((i >= dpm_table->pcie_speed_table.count) ?
4024 dpm_table->pcie_speed_table.dpm_levels
4025 [dpm_table->pcie_speed_table.count - 1].value :
4026 dpm_table->pcie_speed_table.dpm_levels[i].value);
4032 static int smu7_request_link_speed_change_before_state_change(
4033 struct pp_hwmgr *hwmgr, const void *input)
4035 const struct phm_set_power_state_input *states =
4036 (const struct phm_set_power_state_input *)input;
4037 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4038 const struct smu7_power_state *smu7_nps =
4039 cast_const_phw_smu7_power_state(states->pnew_state);
4040 const struct smu7_power_state *polaris10_cps =
4041 cast_const_phw_smu7_power_state(states->pcurrent_state);
4043 uint16_t target_link_speed = smu7_get_maximum_link_speed(hwmgr, smu7_nps);
4044 uint16_t current_link_speed;
4046 if (data->force_pcie_gen == PP_PCIEGenInvalid)
4047 current_link_speed = smu7_get_maximum_link_speed(hwmgr, polaris10_cps);
4049 current_link_speed = data->force_pcie_gen;
4051 data->force_pcie_gen = PP_PCIEGenInvalid;
4052 data->pspp_notify_required = false;
4054 if (target_link_speed > current_link_speed) {
4055 switch (target_link_speed) {
4058 if (0 == amdgpu_acpi_pcie_performance_request(hwmgr->adev, PCIE_PERF_REQ_GEN3, false))
4060 data->force_pcie_gen = PP_PCIEGen2;
4061 if (current_link_speed == PP_PCIEGen2)
4065 if (0 == amdgpu_acpi_pcie_performance_request(hwmgr->adev, PCIE_PERF_REQ_GEN2, false))
4070 data->force_pcie_gen = smu7_get_current_pcie_speed(hwmgr);
4074 if (target_link_speed < current_link_speed)
4075 data->pspp_notify_required = true;
4081 static int smu7_freeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
4083 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4085 if (0 == data->need_update_smu7_dpm_table)
4088 if ((0 == data->sclk_dpm_key_disabled) &&
4089 (data->need_update_smu7_dpm_table &
4090 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
4091 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
4092 "Trying to freeze SCLK DPM when DPM is disabled",
4094 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr,
4095 PPSMC_MSG_SCLKDPM_FreezeLevel,
4097 "Failed to freeze SCLK DPM during FreezeSclkMclkDPM Function!",
4101 if ((0 == data->mclk_dpm_key_disabled) &&
4102 !data->mclk_ignore_signal &&
4103 (data->need_update_smu7_dpm_table &
4104 DPMTABLE_OD_UPDATE_MCLK)) {
4105 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
4106 "Trying to freeze MCLK DPM when DPM is disabled",
4108 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr,
4109 PPSMC_MSG_MCLKDPM_FreezeLevel,
4111 "Failed to freeze MCLK DPM during FreezeSclkMclkDPM Function!",
4118 static int smu7_populate_and_upload_sclk_mclk_dpm_levels(
4119 struct pp_hwmgr *hwmgr, const void *input)
4122 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4123 struct smu7_dpm_table *dpm_table = &data->dpm_table;
4125 struct smu7_odn_dpm_table *odn_table = &(data->odn_dpm_table);
4126 struct phm_odn_clock_levels *odn_sclk_table = &(odn_table->odn_core_clock_dpm_levels);
4127 struct phm_odn_clock_levels *odn_mclk_table = &(odn_table->odn_memory_clock_dpm_levels);
4129 if (0 == data->need_update_smu7_dpm_table)
4132 if (hwmgr->od_enabled && data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_SCLK) {
4133 for (count = 0; count < dpm_table->sclk_table.count; count++) {
4134 dpm_table->sclk_table.dpm_levels[count].enabled = odn_sclk_table->entries[count].enabled;
4135 dpm_table->sclk_table.dpm_levels[count].value = odn_sclk_table->entries[count].clock;
4139 if (hwmgr->od_enabled && data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK) {
4140 for (count = 0; count < dpm_table->mclk_table.count; count++) {
4141 dpm_table->mclk_table.dpm_levels[count].enabled = odn_mclk_table->entries[count].enabled;
4142 dpm_table->mclk_table.dpm_levels[count].value = odn_mclk_table->entries[count].clock;
4146 if (data->need_update_smu7_dpm_table &
4147 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK)) {
4148 result = smum_populate_all_graphic_levels(hwmgr);
4149 PP_ASSERT_WITH_CODE((0 == result),
4150 "Failed to populate SCLK during PopulateNewDPMClocksStates Function!",
4154 if (data->need_update_smu7_dpm_table &
4155 (DPMTABLE_OD_UPDATE_MCLK + DPMTABLE_UPDATE_MCLK)) {
4156 /*populate MCLK dpm table to SMU7 */
4157 result = smum_populate_all_memory_levels(hwmgr);
4158 PP_ASSERT_WITH_CODE((0 == result),
4159 "Failed to populate MCLK during PopulateNewDPMClocksStates Function!",
4166 static int smu7_trim_single_dpm_states(struct pp_hwmgr *hwmgr,
4167 struct smu7_single_dpm_table *dpm_table,
4168 uint32_t low_limit, uint32_t high_limit)
4172 /* force the trim if mclk_switching is disabled to prevent flicker */
4173 bool force_trim = (low_limit == high_limit);
4174 for (i = 0; i < dpm_table->count; i++) {
4175 /*skip the trim if od is enabled*/
4176 if ((!hwmgr->od_enabled || force_trim)
4177 && (dpm_table->dpm_levels[i].value < low_limit
4178 || dpm_table->dpm_levels[i].value > high_limit))
4179 dpm_table->dpm_levels[i].enabled = false;
4181 dpm_table->dpm_levels[i].enabled = true;
4187 static int smu7_trim_dpm_states(struct pp_hwmgr *hwmgr,
4188 const struct smu7_power_state *smu7_ps)
4190 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4191 uint32_t high_limit_count;
4193 PP_ASSERT_WITH_CODE((smu7_ps->performance_level_count >= 1),
4194 "power state did not have any performance level",
4197 high_limit_count = (1 == smu7_ps->performance_level_count) ? 0 : 1;
4199 smu7_trim_single_dpm_states(hwmgr,
4200 &(data->dpm_table.sclk_table),
4201 smu7_ps->performance_levels[0].engine_clock,
4202 smu7_ps->performance_levels[high_limit_count].engine_clock);
4204 smu7_trim_single_dpm_states(hwmgr,
4205 &(data->dpm_table.mclk_table),
4206 smu7_ps->performance_levels[0].memory_clock,
4207 smu7_ps->performance_levels[high_limit_count].memory_clock);
4212 static int smu7_generate_dpm_level_enable_mask(
4213 struct pp_hwmgr *hwmgr, const void *input)
4216 const struct phm_set_power_state_input *states =
4217 (const struct phm_set_power_state_input *)input;
4218 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4219 const struct smu7_power_state *smu7_ps =
4220 cast_const_phw_smu7_power_state(states->pnew_state);
4223 result = smu7_trim_dpm_states(hwmgr, smu7_ps);
4227 data->dpm_level_enable_mask.sclk_dpm_enable_mask =
4228 phm_get_dpm_level_enable_mask_value(&data->dpm_table.sclk_table);
4229 data->dpm_level_enable_mask.mclk_dpm_enable_mask =
4230 phm_get_dpm_level_enable_mask_value(&data->dpm_table.mclk_table);
4231 data->dpm_level_enable_mask.pcie_dpm_enable_mask =
4232 phm_get_dpm_level_enable_mask_value(&data->dpm_table.pcie_speed_table);
4237 static int smu7_unfreeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
4239 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4241 if (0 == data->need_update_smu7_dpm_table)
4244 if ((0 == data->sclk_dpm_key_disabled) &&
4245 (data->need_update_smu7_dpm_table &
4246 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
4248 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
4249 "Trying to Unfreeze SCLK DPM when DPM is disabled",
4251 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr,
4252 PPSMC_MSG_SCLKDPM_UnfreezeLevel,
4254 "Failed to unfreeze SCLK DPM during UnFreezeSclkMclkDPM Function!",
4258 if ((0 == data->mclk_dpm_key_disabled) &&
4259 !data->mclk_ignore_signal &&
4260 (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) {
4262 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
4263 "Trying to Unfreeze MCLK DPM when DPM is disabled",
4265 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr,
4266 PPSMC_MSG_MCLKDPM_UnfreezeLevel,
4268 "Failed to unfreeze MCLK DPM during UnFreezeSclkMclkDPM Function!",
4272 data->need_update_smu7_dpm_table &= DPMTABLE_OD_UPDATE_VDDC;
4277 static int smu7_notify_link_speed_change_after_state_change(
4278 struct pp_hwmgr *hwmgr, const void *input)
4280 const struct phm_set_power_state_input *states =
4281 (const struct phm_set_power_state_input *)input;
4282 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4283 const struct smu7_power_state *smu7_ps =
4284 cast_const_phw_smu7_power_state(states->pnew_state);
4285 uint16_t target_link_speed = smu7_get_maximum_link_speed(hwmgr, smu7_ps);
4288 if (data->pspp_notify_required) {
4289 if (target_link_speed == PP_PCIEGen3)
4290 request = PCIE_PERF_REQ_GEN3;
4291 else if (target_link_speed == PP_PCIEGen2)
4292 request = PCIE_PERF_REQ_GEN2;
4294 request = PCIE_PERF_REQ_GEN1;
4296 if (request == PCIE_PERF_REQ_GEN1 &&
4297 smu7_get_current_pcie_speed(hwmgr) > 0)
4301 if (amdgpu_acpi_pcie_performance_request(hwmgr->adev, request, false)) {
4302 if (PP_PCIEGen2 == target_link_speed)
4303 pr_info("PSPP request to switch to Gen2 from Gen3 Failed!");
4305 pr_info("PSPP request to switch to Gen1 from Gen2 Failed!");
4313 static int smu7_notify_no_display(struct pp_hwmgr *hwmgr)
4315 return (smum_send_msg_to_smc(hwmgr, (PPSMC_Msg)PPSMC_NoDisplay, NULL) == 0) ? 0 : -EINVAL;
4318 static int smu7_notify_has_display(struct pp_hwmgr *hwmgr)
4320 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4322 if (hwmgr->feature_mask & PP_VBI_TIME_SUPPORT_MASK) {
4323 if (hwmgr->chip_id == CHIP_VEGAM)
4324 smum_send_msg_to_smc_with_parameter(hwmgr,
4325 (PPSMC_Msg)PPSMC_MSG_SetVBITimeout_VEGAM, data->frame_time_x2,
4328 smum_send_msg_to_smc_with_parameter(hwmgr,
4329 (PPSMC_Msg)PPSMC_MSG_SetVBITimeout, data->frame_time_x2,
4331 data->last_sent_vbi_timeout = data->frame_time_x2;
4334 return (smum_send_msg_to_smc(hwmgr, (PPSMC_Msg)PPSMC_HasDisplay, NULL) == 0) ? 0 : -EINVAL;
4337 static int smu7_notify_smc_display(struct pp_hwmgr *hwmgr)
4339 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4342 if (data->mclk_ignore_signal)
4343 result = smu7_notify_no_display(hwmgr);
4345 result = smu7_notify_has_display(hwmgr);
4350 static int smu7_set_power_state_tasks(struct pp_hwmgr *hwmgr, const void *input)
4352 int tmp_result, result = 0;
4353 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4355 tmp_result = smu7_find_dpm_states_clocks_in_dpm_table(hwmgr, input);
4356 PP_ASSERT_WITH_CODE((0 == tmp_result),
4357 "Failed to find DPM states clocks in DPM table!",
4358 result = tmp_result);
4360 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4361 PHM_PlatformCaps_PCIEPerformanceRequest)) {
4363 smu7_request_link_speed_change_before_state_change(hwmgr, input);
4364 PP_ASSERT_WITH_CODE((0 == tmp_result),
4365 "Failed to request link speed change before state change!",
4366 result = tmp_result);
4369 tmp_result = smu7_freeze_sclk_mclk_dpm(hwmgr);
4370 PP_ASSERT_WITH_CODE((0 == tmp_result),
4371 "Failed to freeze SCLK MCLK DPM!", result = tmp_result);
4373 tmp_result = smu7_populate_and_upload_sclk_mclk_dpm_levels(hwmgr, input);
4374 PP_ASSERT_WITH_CODE((0 == tmp_result),
4375 "Failed to populate and upload SCLK MCLK DPM levels!",
4376 result = tmp_result);
4379 * If a custom pp table is loaded, set DPMTABLE_OD_UPDATE_VDDC flag.
4380 * That effectively disables AVFS feature.
4382 if (hwmgr->hardcode_pp_table != NULL)
4383 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_VDDC;
4385 tmp_result = smu7_update_avfs(hwmgr);
4386 PP_ASSERT_WITH_CODE((0 == tmp_result),
4387 "Failed to update avfs voltages!",
4388 result = tmp_result);
4390 tmp_result = smu7_generate_dpm_level_enable_mask(hwmgr, input);
4391 PP_ASSERT_WITH_CODE((0 == tmp_result),
4392 "Failed to generate DPM level enabled mask!",
4393 result = tmp_result);
4395 tmp_result = smum_update_sclk_threshold(hwmgr);
4396 PP_ASSERT_WITH_CODE((0 == tmp_result),
4397 "Failed to update SCLK threshold!",
4398 result = tmp_result);
4400 tmp_result = smu7_unfreeze_sclk_mclk_dpm(hwmgr);
4401 PP_ASSERT_WITH_CODE((0 == tmp_result),
4402 "Failed to unfreeze SCLK MCLK DPM!",
4403 result = tmp_result);
4405 tmp_result = smu7_upload_dpm_level_enable_mask(hwmgr);
4406 PP_ASSERT_WITH_CODE((0 == tmp_result),
4407 "Failed to upload DPM level enabled mask!",
4408 result = tmp_result);
4410 tmp_result = smu7_notify_smc_display(hwmgr);
4411 PP_ASSERT_WITH_CODE((0 == tmp_result),
4412 "Failed to notify smc display settings!",
4413 result = tmp_result);
4415 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4416 PHM_PlatformCaps_PCIEPerformanceRequest)) {
4418 smu7_notify_link_speed_change_after_state_change(hwmgr, input);
4419 PP_ASSERT_WITH_CODE((0 == tmp_result),
4420 "Failed to notify link speed change after state change!",
4421 result = tmp_result);
4423 data->apply_optimized_settings = false;
4427 static int smu7_set_max_fan_pwm_output(struct pp_hwmgr *hwmgr, uint16_t us_max_fan_pwm)
4429 hwmgr->thermal_controller.
4430 advanceFanControlParameters.usMaxFanPWM = us_max_fan_pwm;
4432 return smum_send_msg_to_smc_with_parameter(hwmgr,
4433 PPSMC_MSG_SetFanPwmMax, us_max_fan_pwm,
4438 smu7_notify_smc_display_config_after_ps_adjustment(struct pp_hwmgr *hwmgr)
4444 * Programs the display gap
4446 * @param hwmgr the address of the powerplay hardware manager.
4449 static int smu7_program_display_gap(struct pp_hwmgr *hwmgr)
4451 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4452 uint32_t display_gap = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL);
4453 uint32_t display_gap2;
4454 uint32_t pre_vbi_time_in_us;
4455 uint32_t frame_time_in_us;
4456 uint32_t ref_clock, refresh_rate;
4458 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);
4459 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL, display_gap);
4461 ref_clock = amdgpu_asic_get_xclk((struct amdgpu_device *)hwmgr->adev);
4462 refresh_rate = hwmgr->display_config->vrefresh;
4464 if (0 == refresh_rate)
4467 frame_time_in_us = 1000000 / refresh_rate;
4469 pre_vbi_time_in_us = frame_time_in_us - 200 - hwmgr->display_config->min_vblank_time;
4471 data->frame_time_x2 = frame_time_in_us * 2 / 100;
4473 if (data->frame_time_x2 < 280) {
4474 pr_debug("%s: enforce minimal VBITimeout: %d -> 280\n", __func__, data->frame_time_x2);
4475 data->frame_time_x2 = 280;
4478 display_gap2 = pre_vbi_time_in_us * (ref_clock / 100);
4480 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL2, display_gap2);
4482 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
4483 data->soft_regs_start + smum_get_offsetof(hwmgr,
4485 PreVBlankGap), 0x64);
4487 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
4488 data->soft_regs_start + smum_get_offsetof(hwmgr,
4491 (frame_time_in_us - pre_vbi_time_in_us));
4496 static int smu7_display_configuration_changed_task(struct pp_hwmgr *hwmgr)
4498 return smu7_program_display_gap(hwmgr);
4502 * Set maximum target operating fan output RPM
4504 * @param hwmgr: the address of the powerplay hardware manager.
4505 * @param usMaxFanRpm: max operating fan RPM value.
4506 * @return The response that came from the SMC.
4508 static int smu7_set_max_fan_rpm_output(struct pp_hwmgr *hwmgr, uint16_t us_max_fan_rpm)
4510 hwmgr->thermal_controller.
4511 advanceFanControlParameters.usMaxFanRPM = us_max_fan_rpm;
4513 return smum_send_msg_to_smc_with_parameter(hwmgr,
4514 PPSMC_MSG_SetFanRpmMax, us_max_fan_rpm,
4518 static const struct amdgpu_irq_src_funcs smu7_irq_funcs = {
4519 .process = phm_irq_process,
4522 static int smu7_register_irq_handlers(struct pp_hwmgr *hwmgr)
4524 struct amdgpu_irq_src *source =
4525 kzalloc(sizeof(struct amdgpu_irq_src), GFP_KERNEL);
4530 source->funcs = &smu7_irq_funcs;
4532 amdgpu_irq_add_id((struct amdgpu_device *)(hwmgr->adev),
4533 AMDGPU_IRQ_CLIENTID_LEGACY,
4534 VISLANDS30_IV_SRCID_CG_TSS_THERMAL_LOW_TO_HIGH,
4536 amdgpu_irq_add_id((struct amdgpu_device *)(hwmgr->adev),
4537 AMDGPU_IRQ_CLIENTID_LEGACY,
4538 VISLANDS30_IV_SRCID_CG_TSS_THERMAL_HIGH_TO_LOW,
4541 /* Register CTF(GPIO_19) interrupt */
4542 amdgpu_irq_add_id((struct amdgpu_device *)(hwmgr->adev),
4543 AMDGPU_IRQ_CLIENTID_LEGACY,
4544 VISLANDS30_IV_SRCID_GPIO_19,
4551 smu7_check_smc_update_required_for_display_configuration(struct pp_hwmgr *hwmgr)
4553 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4554 bool is_update_required = false;
4556 if (data->display_timing.num_existing_displays != hwmgr->display_config->num_display)
4557 is_update_required = true;
4559 if (data->display_timing.vrefresh != hwmgr->display_config->vrefresh)
4560 is_update_required = true;
4562 if (hwmgr->chip_id >= CHIP_POLARIS10 &&
4563 hwmgr->chip_id <= CHIP_VEGAM &&
4564 data->last_sent_vbi_timeout != data->frame_time_x2)
4565 is_update_required = true;
4567 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep)) {
4568 if (data->display_timing.min_clock_in_sr != hwmgr->display_config->min_core_set_clock_in_sr &&
4569 (data->display_timing.min_clock_in_sr >= SMU7_MINIMUM_ENGINE_CLOCK ||
4570 hwmgr->display_config->min_core_set_clock_in_sr >= SMU7_MINIMUM_ENGINE_CLOCK))
4571 is_update_required = true;
4573 return is_update_required;
4576 static inline bool smu7_are_power_levels_equal(const struct smu7_performance_level *pl1,
4577 const struct smu7_performance_level *pl2)
4579 return ((pl1->memory_clock == pl2->memory_clock) &&
4580 (pl1->engine_clock == pl2->engine_clock) &&
4581 (pl1->pcie_gen == pl2->pcie_gen) &&
4582 (pl1->pcie_lane == pl2->pcie_lane));
4585 static int smu7_check_states_equal(struct pp_hwmgr *hwmgr,
4586 const struct pp_hw_power_state *pstate1,
4587 const struct pp_hw_power_state *pstate2, bool *equal)
4589 const struct smu7_power_state *psa;
4590 const struct smu7_power_state *psb;
4592 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4594 if (pstate1 == NULL || pstate2 == NULL || equal == NULL)
4597 psa = cast_const_phw_smu7_power_state(pstate1);
4598 psb = cast_const_phw_smu7_power_state(pstate2);
4599 /* If the two states don't even have the same number of performance levels they cannot be the same state. */
4600 if (psa->performance_level_count != psb->performance_level_count) {
4605 for (i = 0; i < psa->performance_level_count; i++) {
4606 if (!smu7_are_power_levels_equal(&(psa->performance_levels[i]), &(psb->performance_levels[i]))) {
4607 /* If we have found even one performance level pair that is different the states are different. */
4613 /* If all performance levels are the same try to use the UVD clocks to break the tie.*/
4614 *equal = ((psa->uvd_clks.vclk == psb->uvd_clks.vclk) && (psa->uvd_clks.dclk == psb->uvd_clks.dclk));
4615 *equal &= ((psa->vce_clks.evclk == psb->vce_clks.evclk) && (psa->vce_clks.ecclk == psb->vce_clks.ecclk));
4616 *equal &= (psa->sclk_threshold == psb->sclk_threshold);
4617 /* For OD call, set value based on flag */
4618 *equal &= !(data->need_update_smu7_dpm_table & (DPMTABLE_OD_UPDATE_SCLK |
4619 DPMTABLE_OD_UPDATE_MCLK |
4620 DPMTABLE_OD_UPDATE_VDDC));
4625 static int smu7_check_mc_firmware(struct pp_hwmgr *hwmgr)
4627 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4631 /* Read MC indirect register offset 0x9F bits [3:0] to see
4632 * if VBIOS has already loaded a full version of MC ucode
4636 smu7_get_mc_microcode_version(hwmgr);
4638 data->need_long_memory_training = false;
4640 cgs_write_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_INDEX,
4641 ixMC_IO_DEBUG_UP_13);
4642 tmp = cgs_read_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_DATA);
4644 if (tmp & (1 << 23)) {
4645 data->mem_latency_high = MEM_LATENCY_HIGH;
4646 data->mem_latency_low = MEM_LATENCY_LOW;
4647 if ((hwmgr->chip_id == CHIP_POLARIS10) ||
4648 (hwmgr->chip_id == CHIP_POLARIS11) ||
4649 (hwmgr->chip_id == CHIP_POLARIS12))
4650 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_EnableFFC, NULL);
4652 data->mem_latency_high = 330;
4653 data->mem_latency_low = 330;
4654 if ((hwmgr->chip_id == CHIP_POLARIS10) ||
4655 (hwmgr->chip_id == CHIP_POLARIS11) ||
4656 (hwmgr->chip_id == CHIP_POLARIS12))
4657 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_DisableFFC, NULL);
4663 static int smu7_read_clock_registers(struct pp_hwmgr *hwmgr)
4665 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4667 data->clock_registers.vCG_SPLL_FUNC_CNTL =
4668 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL);
4669 data->clock_registers.vCG_SPLL_FUNC_CNTL_2 =
4670 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_2);
4671 data->clock_registers.vCG_SPLL_FUNC_CNTL_3 =
4672 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_3);
4673 data->clock_registers.vCG_SPLL_FUNC_CNTL_4 =
4674 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_4);
4675 data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM =
4676 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_SPREAD_SPECTRUM);
4677 data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2 =
4678 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_SPREAD_SPECTRUM_2);
4679 data->clock_registers.vDLL_CNTL =
4680 cgs_read_register(hwmgr->device, mmDLL_CNTL);
4681 data->clock_registers.vMCLK_PWRMGT_CNTL =
4682 cgs_read_register(hwmgr->device, mmMCLK_PWRMGT_CNTL);
4683 data->clock_registers.vMPLL_AD_FUNC_CNTL =
4684 cgs_read_register(hwmgr->device, mmMPLL_AD_FUNC_CNTL);
4685 data->clock_registers.vMPLL_DQ_FUNC_CNTL =
4686 cgs_read_register(hwmgr->device, mmMPLL_DQ_FUNC_CNTL);
4687 data->clock_registers.vMPLL_FUNC_CNTL =
4688 cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL);
4689 data->clock_registers.vMPLL_FUNC_CNTL_1 =
4690 cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL_1);
4691 data->clock_registers.vMPLL_FUNC_CNTL_2 =
4692 cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL_2);
4693 data->clock_registers.vMPLL_SS1 =
4694 cgs_read_register(hwmgr->device, mmMPLL_SS1);
4695 data->clock_registers.vMPLL_SS2 =
4696 cgs_read_register(hwmgr->device, mmMPLL_SS2);
4702 * Find out if memory is GDDR5.
4704 * @param hwmgr the address of the powerplay hardware manager.
4707 static int smu7_get_memory_type(struct pp_hwmgr *hwmgr)
4709 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4710 struct amdgpu_device *adev = hwmgr->adev;
4712 data->is_memory_gddr5 = (adev->gmc.vram_type == AMDGPU_VRAM_TYPE_GDDR5);
4718 * Enables Dynamic Power Management by SMC
4720 * @param hwmgr the address of the powerplay hardware manager.
4723 static int smu7_enable_acpi_power_management(struct pp_hwmgr *hwmgr)
4725 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
4726 GENERAL_PWRMGT, STATIC_PM_EN, 1);
4732 * Initialize PowerGating States for different engines
4734 * @param hwmgr the address of the powerplay hardware manager.
4737 static int smu7_init_power_gate_state(struct pp_hwmgr *hwmgr)
4739 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4741 data->uvd_power_gated = false;
4742 data->vce_power_gated = false;
4747 static int smu7_init_sclk_threshold(struct pp_hwmgr *hwmgr)
4749 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4751 data->low_sclk_interrupt_threshold = 0;
4755 static int smu7_setup_asic_task(struct pp_hwmgr *hwmgr)
4757 int tmp_result, result = 0;
4759 smu7_check_mc_firmware(hwmgr);
4761 tmp_result = smu7_read_clock_registers(hwmgr);
4762 PP_ASSERT_WITH_CODE((0 == tmp_result),
4763 "Failed to read clock registers!", result = tmp_result);
4765 tmp_result = smu7_get_memory_type(hwmgr);
4766 PP_ASSERT_WITH_CODE((0 == tmp_result),
4767 "Failed to get memory type!", result = tmp_result);
4769 tmp_result = smu7_enable_acpi_power_management(hwmgr);
4770 PP_ASSERT_WITH_CODE((0 == tmp_result),
4771 "Failed to enable ACPI power management!", result = tmp_result);
4773 tmp_result = smu7_init_power_gate_state(hwmgr);
4774 PP_ASSERT_WITH_CODE((0 == tmp_result),
4775 "Failed to init power gate state!", result = tmp_result);
4777 tmp_result = smu7_get_mc_microcode_version(hwmgr);
4778 PP_ASSERT_WITH_CODE((0 == tmp_result),
4779 "Failed to get MC microcode version!", result = tmp_result);
4781 tmp_result = smu7_init_sclk_threshold(hwmgr);
4782 PP_ASSERT_WITH_CODE((0 == tmp_result),
4783 "Failed to init sclk threshold!", result = tmp_result);
4788 static int smu7_force_clock_level(struct pp_hwmgr *hwmgr,
4789 enum pp_clock_type type, uint32_t mask)
4791 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4798 if (!data->sclk_dpm_key_disabled)
4799 smum_send_msg_to_smc_with_parameter(hwmgr,
4800 PPSMC_MSG_SCLKDPM_SetEnabledMask,
4801 data->dpm_level_enable_mask.sclk_dpm_enable_mask & mask,
4805 if (!data->mclk_dpm_key_disabled)
4806 smum_send_msg_to_smc_with_parameter(hwmgr,
4807 PPSMC_MSG_MCLKDPM_SetEnabledMask,
4808 data->dpm_level_enable_mask.mclk_dpm_enable_mask & mask,
4813 uint32_t tmp = mask & data->dpm_level_enable_mask.pcie_dpm_enable_mask;
4815 if (!data->pcie_dpm_key_disabled) {
4816 if (fls(tmp) != ffs(tmp))
4817 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_PCIeDPM_UnForceLevel,
4820 smum_send_msg_to_smc_with_parameter(hwmgr,
4821 PPSMC_MSG_PCIeDPM_ForceLevel,
4834 static int smu7_print_clock_levels(struct pp_hwmgr *hwmgr,
4835 enum pp_clock_type type, char *buf)
4837 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4838 struct smu7_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
4839 struct smu7_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
4840 struct smu7_single_dpm_table *pcie_table = &(data->dpm_table.pcie_speed_table);
4841 struct smu7_odn_dpm_table *odn_table = &(data->odn_dpm_table);
4842 struct phm_odn_clock_levels *odn_sclk_table = &(odn_table->odn_core_clock_dpm_levels);
4843 struct phm_odn_clock_levels *odn_mclk_table = &(odn_table->odn_memory_clock_dpm_levels);
4844 int i, now, size = 0;
4845 uint32_t clock, pcie_speed;
4849 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_API_GetSclkFrequency, &clock);
4851 for (i = 0; i < sclk_table->count; i++) {
4852 if (clock > sclk_table->dpm_levels[i].value)
4858 for (i = 0; i < sclk_table->count; i++)
4859 size += sprintf(buf + size, "%d: %uMhz %s\n",
4860 i, sclk_table->dpm_levels[i].value / 100,
4861 (i == now) ? "*" : "");
4864 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_API_GetMclkFrequency, &clock);
4866 for (i = 0; i < mclk_table->count; i++) {
4867 if (clock > mclk_table->dpm_levels[i].value)
4873 for (i = 0; i < mclk_table->count; i++)
4874 size += sprintf(buf + size, "%d: %uMhz %s\n",
4875 i, mclk_table->dpm_levels[i].value / 100,
4876 (i == now) ? "*" : "");
4879 pcie_speed = smu7_get_current_pcie_speed(hwmgr);
4880 for (i = 0; i < pcie_table->count; i++) {
4881 if (pcie_speed != pcie_table->dpm_levels[i].value)
4887 for (i = 0; i < pcie_table->count; i++)
4888 size += sprintf(buf + size, "%d: %s %s\n", i,
4889 (pcie_table->dpm_levels[i].value == 0) ? "2.5GT/s, x8" :
4890 (pcie_table->dpm_levels[i].value == 1) ? "5.0GT/s, x16" :
4891 (pcie_table->dpm_levels[i].value == 2) ? "8.0GT/s, x16" : "",
4892 (i == now) ? "*" : "");
4895 if (hwmgr->od_enabled) {
4896 size = sprintf(buf, "%s:\n", "OD_SCLK");
4897 for (i = 0; i < odn_sclk_table->num_of_pl; i++)
4898 size += sprintf(buf + size, "%d: %10uMHz %10umV\n",
4899 i, odn_sclk_table->entries[i].clock/100,
4900 odn_sclk_table->entries[i].vddc);
4904 if (hwmgr->od_enabled) {
4905 size = sprintf(buf, "%s:\n", "OD_MCLK");
4906 for (i = 0; i < odn_mclk_table->num_of_pl; i++)
4907 size += sprintf(buf + size, "%d: %10uMHz %10umV\n",
4908 i, odn_mclk_table->entries[i].clock/100,
4909 odn_mclk_table->entries[i].vddc);
4913 if (hwmgr->od_enabled) {
4914 size = sprintf(buf, "%s:\n", "OD_RANGE");
4915 size += sprintf(buf + size, "SCLK: %7uMHz %10uMHz\n",
4916 data->golden_dpm_table.sclk_table.dpm_levels[0].value/100,
4917 hwmgr->platform_descriptor.overdriveLimit.engineClock/100);
4918 size += sprintf(buf + size, "MCLK: %7uMHz %10uMHz\n",
4919 data->golden_dpm_table.mclk_table.dpm_levels[0].value/100,
4920 hwmgr->platform_descriptor.overdriveLimit.memoryClock/100);
4921 size += sprintf(buf + size, "VDDC: %7umV %11umV\n",
4922 data->odn_dpm_table.min_vddc,
4923 data->odn_dpm_table.max_vddc);
4932 static void smu7_set_fan_control_mode(struct pp_hwmgr *hwmgr, uint32_t mode)
4935 case AMD_FAN_CTRL_NONE:
4936 smu7_fan_ctrl_set_fan_speed_percent(hwmgr, 100);
4938 case AMD_FAN_CTRL_MANUAL:
4939 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4940 PHM_PlatformCaps_MicrocodeFanControl))
4941 smu7_fan_ctrl_stop_smc_fan_control(hwmgr);
4943 case AMD_FAN_CTRL_AUTO:
4944 if (!smu7_fan_ctrl_set_static_mode(hwmgr, mode))
4945 smu7_fan_ctrl_start_smc_fan_control(hwmgr);
4952 static uint32_t smu7_get_fan_control_mode(struct pp_hwmgr *hwmgr)
4954 return hwmgr->fan_ctrl_enabled ? AMD_FAN_CTRL_AUTO : AMD_FAN_CTRL_MANUAL;
4957 static int smu7_get_sclk_od(struct pp_hwmgr *hwmgr)
4959 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4960 struct smu7_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
4961 struct smu7_single_dpm_table *golden_sclk_table =
4962 &(data->golden_dpm_table.sclk_table);
4963 int value = sclk_table->dpm_levels[sclk_table->count - 1].value;
4964 int golden_value = golden_sclk_table->dpm_levels
4965 [golden_sclk_table->count - 1].value;
4967 value -= golden_value;
4968 value = DIV_ROUND_UP(value * 100, golden_value);
4973 static int smu7_set_sclk_od(struct pp_hwmgr *hwmgr, uint32_t value)
4975 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
4976 struct smu7_single_dpm_table *golden_sclk_table =
4977 &(data->golden_dpm_table.sclk_table);
4978 struct pp_power_state *ps;
4979 struct smu7_power_state *smu7_ps;
4984 ps = hwmgr->request_ps;
4989 smu7_ps = cast_phw_smu7_power_state(&ps->hardware);
4991 smu7_ps->performance_levels[smu7_ps->performance_level_count - 1].engine_clock =
4992 golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value *
4994 golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value;
4999 static int smu7_get_mclk_od(struct pp_hwmgr *hwmgr)
5001 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5002 struct smu7_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
5003 struct smu7_single_dpm_table *golden_mclk_table =
5004 &(data->golden_dpm_table.mclk_table);
5005 int value = mclk_table->dpm_levels[mclk_table->count - 1].value;
5006 int golden_value = golden_mclk_table->dpm_levels
5007 [golden_mclk_table->count - 1].value;
5009 value -= golden_value;
5010 value = DIV_ROUND_UP(value * 100, golden_value);
5015 static int smu7_set_mclk_od(struct pp_hwmgr *hwmgr, uint32_t value)
5017 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5018 struct smu7_single_dpm_table *golden_mclk_table =
5019 &(data->golden_dpm_table.mclk_table);
5020 struct pp_power_state *ps;
5021 struct smu7_power_state *smu7_ps;
5026 ps = hwmgr->request_ps;
5031 smu7_ps = cast_phw_smu7_power_state(&ps->hardware);
5033 smu7_ps->performance_levels[smu7_ps->performance_level_count - 1].memory_clock =
5034 golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value *
5036 golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value;
5042 static int smu7_get_sclks(struct pp_hwmgr *hwmgr, struct amd_pp_clocks *clocks)
5044 struct phm_ppt_v1_information *table_info =
5045 (struct phm_ppt_v1_information *)hwmgr->pptable;
5046 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table = NULL;
5047 struct phm_clock_voltage_dependency_table *sclk_table;
5050 if (hwmgr->pp_table_version == PP_TABLE_V1) {
5051 if (table_info == NULL || table_info->vdd_dep_on_sclk == NULL)
5053 dep_sclk_table = table_info->vdd_dep_on_sclk;
5054 for (i = 0; i < dep_sclk_table->count; i++)
5055 clocks->clock[i] = dep_sclk_table->entries[i].clk * 10;
5056 clocks->count = dep_sclk_table->count;
5057 } else if (hwmgr->pp_table_version == PP_TABLE_V0) {
5058 sclk_table = hwmgr->dyn_state.vddc_dependency_on_sclk;
5059 for (i = 0; i < sclk_table->count; i++)
5060 clocks->clock[i] = sclk_table->entries[i].clk * 10;
5061 clocks->count = sclk_table->count;
5067 static uint32_t smu7_get_mem_latency(struct pp_hwmgr *hwmgr, uint32_t clk)
5069 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5071 if (clk >= MEM_FREQ_LOW_LATENCY && clk < MEM_FREQ_HIGH_LATENCY)
5072 return data->mem_latency_high;
5073 else if (clk >= MEM_FREQ_HIGH_LATENCY)
5074 return data->mem_latency_low;
5076 return MEM_LATENCY_ERR;
5079 static int smu7_get_mclks(struct pp_hwmgr *hwmgr, struct amd_pp_clocks *clocks)
5081 struct phm_ppt_v1_information *table_info =
5082 (struct phm_ppt_v1_information *)hwmgr->pptable;
5083 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table;
5085 struct phm_clock_voltage_dependency_table *mclk_table;
5087 if (hwmgr->pp_table_version == PP_TABLE_V1) {
5088 if (table_info == NULL)
5090 dep_mclk_table = table_info->vdd_dep_on_mclk;
5091 for (i = 0; i < dep_mclk_table->count; i++) {
5092 clocks->clock[i] = dep_mclk_table->entries[i].clk * 10;
5093 clocks->latency[i] = smu7_get_mem_latency(hwmgr,
5094 dep_mclk_table->entries[i].clk);
5096 clocks->count = dep_mclk_table->count;
5097 } else if (hwmgr->pp_table_version == PP_TABLE_V0) {
5098 mclk_table = hwmgr->dyn_state.vddc_dependency_on_mclk;
5099 for (i = 0; i < mclk_table->count; i++)
5100 clocks->clock[i] = mclk_table->entries[i].clk * 10;
5101 clocks->count = mclk_table->count;
5106 static int smu7_get_clock_by_type(struct pp_hwmgr *hwmgr, enum amd_pp_clock_type type,
5107 struct amd_pp_clocks *clocks)
5110 case amd_pp_sys_clock:
5111 smu7_get_sclks(hwmgr, clocks);
5113 case amd_pp_mem_clock:
5114 smu7_get_mclks(hwmgr, clocks);
5123 static int smu7_get_sclks_with_latency(struct pp_hwmgr *hwmgr,
5124 struct pp_clock_levels_with_latency *clocks)
5126 struct phm_ppt_v1_information *table_info =
5127 (struct phm_ppt_v1_information *)hwmgr->pptable;
5128 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table =
5129 table_info->vdd_dep_on_sclk;
5132 clocks->num_levels = 0;
5133 for (i = 0; i < dep_sclk_table->count; i++) {
5134 if (dep_sclk_table->entries[i].clk) {
5135 clocks->data[clocks->num_levels].clocks_in_khz =
5136 dep_sclk_table->entries[i].clk * 10;
5137 clocks->num_levels++;
5144 static int smu7_get_mclks_with_latency(struct pp_hwmgr *hwmgr,
5145 struct pp_clock_levels_with_latency *clocks)
5147 struct phm_ppt_v1_information *table_info =
5148 (struct phm_ppt_v1_information *)hwmgr->pptable;
5149 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
5150 table_info->vdd_dep_on_mclk;
5151 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5154 clocks->num_levels = 0;
5155 data->mclk_latency_table.count = 0;
5156 for (i = 0; i < dep_mclk_table->count; i++) {
5157 if (dep_mclk_table->entries[i].clk) {
5158 clocks->data[clocks->num_levels].clocks_in_khz =
5159 dep_mclk_table->entries[i].clk * 10;
5160 data->mclk_latency_table.entries[data->mclk_latency_table.count].frequency =
5161 dep_mclk_table->entries[i].clk;
5162 clocks->data[clocks->num_levels].latency_in_us =
5163 data->mclk_latency_table.entries[data->mclk_latency_table.count].latency =
5164 smu7_get_mem_latency(hwmgr, dep_mclk_table->entries[i].clk);
5165 clocks->num_levels++;
5166 data->mclk_latency_table.count++;
5173 static int smu7_get_clock_by_type_with_latency(struct pp_hwmgr *hwmgr,
5174 enum amd_pp_clock_type type,
5175 struct pp_clock_levels_with_latency *clocks)
5177 if (!(hwmgr->chip_id >= CHIP_POLARIS10 &&
5178 hwmgr->chip_id <= CHIP_VEGAM))
5182 case amd_pp_sys_clock:
5183 smu7_get_sclks_with_latency(hwmgr, clocks);
5185 case amd_pp_mem_clock:
5186 smu7_get_mclks_with_latency(hwmgr, clocks);
5195 static int smu7_set_watermarks_for_clocks_ranges(struct pp_hwmgr *hwmgr,
5198 struct phm_ppt_v1_information *table_info =
5199 (struct phm_ppt_v1_information *)hwmgr->pptable;
5200 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
5201 table_info->vdd_dep_on_mclk;
5202 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table =
5203 table_info->vdd_dep_on_sclk;
5204 struct polaris10_smumgr *smu_data =
5205 (struct polaris10_smumgr *)(hwmgr->smu_backend);
5206 SMU74_Discrete_DpmTable *table = &(smu_data->smc_state_table);
5207 struct dm_pp_wm_sets_with_clock_ranges *watermarks =
5208 (struct dm_pp_wm_sets_with_clock_ranges *)clock_range;
5212 if (!(hwmgr->chip_id >= CHIP_POLARIS10 &&
5213 hwmgr->chip_id <= CHIP_VEGAM))
5216 for (i = 0; i < dep_mclk_table->count; i++) {
5217 for (j = 0; j < dep_sclk_table->count; j++) {
5218 valid_entry = false;
5219 for (k = 0; k < watermarks->num_wm_sets; k++) {
5220 if (dep_sclk_table->entries[i].clk / 10 >= watermarks->wm_clk_ranges[k].wm_min_eng_clk_in_khz &&
5221 dep_sclk_table->entries[i].clk / 10 < watermarks->wm_clk_ranges[k].wm_max_eng_clk_in_khz &&
5222 dep_mclk_table->entries[i].clk / 10 >= watermarks->wm_clk_ranges[k].wm_min_mem_clk_in_khz &&
5223 dep_mclk_table->entries[i].clk / 10 < watermarks->wm_clk_ranges[k].wm_max_mem_clk_in_khz) {
5225 table->DisplayWatermark[i][j] = watermarks->wm_clk_ranges[k].wm_set_id;
5229 PP_ASSERT_WITH_CODE(valid_entry,
5230 "Clock is not in range of specified clock range for watermark from DAL! Using highest water mark set.",
5231 table->DisplayWatermark[i][j] = watermarks->wm_clk_ranges[k - 1].wm_set_id);
5235 return smu7_copy_bytes_to_smc(hwmgr,
5236 smu_data->smu7_data.dpm_table_start + offsetof(SMU74_Discrete_DpmTable, DisplayWatermark),
5237 (uint8_t *)table->DisplayWatermark,
5238 sizeof(uint8_t) * SMU74_MAX_LEVELS_MEMORY * SMU74_MAX_LEVELS_GRAPHICS,
5242 static int smu7_notify_cac_buffer_info(struct pp_hwmgr *hwmgr,
5243 uint32_t virtual_addr_low,
5244 uint32_t virtual_addr_hi,
5245 uint32_t mc_addr_low,
5246 uint32_t mc_addr_hi,
5249 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5251 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
5252 data->soft_regs_start +
5253 smum_get_offsetof(hwmgr,
5254 SMU_SoftRegisters, DRAM_LOG_ADDR_H),
5257 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
5258 data->soft_regs_start +
5259 smum_get_offsetof(hwmgr,
5260 SMU_SoftRegisters, DRAM_LOG_ADDR_L),
5263 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
5264 data->soft_regs_start +
5265 smum_get_offsetof(hwmgr,
5266 SMU_SoftRegisters, DRAM_LOG_PHY_ADDR_H),
5269 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
5270 data->soft_regs_start +
5271 smum_get_offsetof(hwmgr,
5272 SMU_SoftRegisters, DRAM_LOG_PHY_ADDR_L),
5275 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
5276 data->soft_regs_start +
5277 smum_get_offsetof(hwmgr,
5278 SMU_SoftRegisters, DRAM_LOG_BUFF_SIZE),
5283 static int smu7_get_max_high_clocks(struct pp_hwmgr *hwmgr,
5284 struct amd_pp_simple_clock_info *clocks)
5286 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5287 struct smu7_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
5288 struct smu7_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
5293 clocks->memory_max_clock = mclk_table->count > 1 ?
5294 mclk_table->dpm_levels[mclk_table->count-1].value :
5295 mclk_table->dpm_levels[0].value;
5296 clocks->engine_max_clock = sclk_table->count > 1 ?
5297 sclk_table->dpm_levels[sclk_table->count-1].value :
5298 sclk_table->dpm_levels[0].value;
5302 static int smu7_get_thermal_temperature_range(struct pp_hwmgr *hwmgr,
5303 struct PP_TemperatureRange *thermal_data)
5305 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5306 struct phm_ppt_v1_information *table_info =
5307 (struct phm_ppt_v1_information *)hwmgr->pptable;
5309 memcpy(thermal_data, &SMU7ThermalPolicy[0], sizeof(struct PP_TemperatureRange));
5311 if (hwmgr->pp_table_version == PP_TABLE_V1)
5312 thermal_data->max = table_info->cac_dtp_table->usSoftwareShutdownTemp *
5313 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
5314 else if (hwmgr->pp_table_version == PP_TABLE_V0)
5315 thermal_data->max = data->thermal_temp_setting.temperature_shutdown *
5316 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
5321 static bool smu7_check_clk_voltage_valid(struct pp_hwmgr *hwmgr,
5322 enum PP_OD_DPM_TABLE_COMMAND type,
5326 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5328 if (voltage < data->odn_dpm_table.min_vddc || voltage > data->odn_dpm_table.max_vddc) {
5329 pr_info("OD voltage is out of range [%d - %d] mV\n",
5330 data->odn_dpm_table.min_vddc,
5331 data->odn_dpm_table.max_vddc);
5335 if (type == PP_OD_EDIT_SCLK_VDDC_TABLE) {
5336 if (data->golden_dpm_table.sclk_table.dpm_levels[0].value > clk ||
5337 hwmgr->platform_descriptor.overdriveLimit.engineClock < clk) {
5338 pr_info("OD engine clock is out of range [%d - %d] MHz\n",
5339 data->golden_dpm_table.sclk_table.dpm_levels[0].value/100,
5340 hwmgr->platform_descriptor.overdriveLimit.engineClock/100);
5343 } else if (type == PP_OD_EDIT_MCLK_VDDC_TABLE) {
5344 if (data->golden_dpm_table.mclk_table.dpm_levels[0].value > clk ||
5345 hwmgr->platform_descriptor.overdriveLimit.memoryClock < clk) {
5346 pr_info("OD memory clock is out of range [%d - %d] MHz\n",
5347 data->golden_dpm_table.mclk_table.dpm_levels[0].value/100,
5348 hwmgr->platform_descriptor.overdriveLimit.memoryClock/100);
5358 static int smu7_odn_edit_dpm_table(struct pp_hwmgr *hwmgr,
5359 enum PP_OD_DPM_TABLE_COMMAND type,
5360 long *input, uint32_t size)
5363 struct phm_odn_clock_levels *podn_dpm_table_in_backend = NULL;
5364 struct smu7_odn_clock_voltage_dependency_table *podn_vdd_dep_in_backend = NULL;
5365 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5369 uint32_t input_level;
5371 PP_ASSERT_WITH_CODE(input, "NULL user input for clock and voltage",
5374 if (!hwmgr->od_enabled) {
5375 pr_info("OverDrive feature not enabled\n");
5379 if (PP_OD_EDIT_SCLK_VDDC_TABLE == type) {
5380 podn_dpm_table_in_backend = &data->odn_dpm_table.odn_core_clock_dpm_levels;
5381 podn_vdd_dep_in_backend = &data->odn_dpm_table.vdd_dependency_on_sclk;
5382 PP_ASSERT_WITH_CODE((podn_dpm_table_in_backend && podn_vdd_dep_in_backend),
5383 "Failed to get ODN SCLK and Voltage tables",
5385 } else if (PP_OD_EDIT_MCLK_VDDC_TABLE == type) {
5386 podn_dpm_table_in_backend = &data->odn_dpm_table.odn_memory_clock_dpm_levels;
5387 podn_vdd_dep_in_backend = &data->odn_dpm_table.vdd_dependency_on_mclk;
5389 PP_ASSERT_WITH_CODE((podn_dpm_table_in_backend && podn_vdd_dep_in_backend),
5390 "Failed to get ODN MCLK and Voltage tables",
5392 } else if (PP_OD_RESTORE_DEFAULT_TABLE == type) {
5393 smu7_odn_initial_default_setting(hwmgr);
5395 } else if (PP_OD_COMMIT_DPM_TABLE == type) {
5396 smu7_check_dpm_table_updated(hwmgr);
5402 for (i = 0; i < size; i += 3) {
5403 if (i + 3 > size || input[i] >= podn_dpm_table_in_backend->num_of_pl) {
5404 pr_info("invalid clock voltage input \n");
5407 input_level = input[i];
5408 input_clk = input[i+1] * 100;
5409 input_vol = input[i+2];
5411 if (smu7_check_clk_voltage_valid(hwmgr, type, input_clk, input_vol)) {
5412 podn_dpm_table_in_backend->entries[input_level].clock = input_clk;
5413 podn_vdd_dep_in_backend->entries[input_level].clk = input_clk;
5414 podn_dpm_table_in_backend->entries[input_level].vddc = input_vol;
5415 podn_vdd_dep_in_backend->entries[input_level].vddc = input_vol;
5416 podn_vdd_dep_in_backend->entries[input_level].vddgfx = input_vol;
5425 static int smu7_get_power_profile_mode(struct pp_hwmgr *hwmgr, char *buf)
5427 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5428 uint32_t i, size = 0;
5431 static const char *profile_name[7] = {"BOOTUP_DEFAULT",
5439 static const char *title[8] = {"NUM",
5443 "SCLK_ACTIVE_LEVEL",
5446 "MCLK_ACTIVE_LEVEL"};
5451 size += sprintf(buf + size, "%s %16s %16s %16s %16s %16s %16s %16s\n",
5452 title[0], title[1], title[2], title[3],
5453 title[4], title[5], title[6], title[7]);
5455 len = ARRAY_SIZE(smu7_profiling);
5457 for (i = 0; i < len; i++) {
5458 if (i == hwmgr->power_profile_mode) {
5459 size += sprintf(buf + size, "%3d %14s %s: %8d %16d %16d %16d %16d %16d\n",
5460 i, profile_name[i], "*",
5461 data->current_profile_setting.sclk_up_hyst,
5462 data->current_profile_setting.sclk_down_hyst,
5463 data->current_profile_setting.sclk_activity,
5464 data->current_profile_setting.mclk_up_hyst,
5465 data->current_profile_setting.mclk_down_hyst,
5466 data->current_profile_setting.mclk_activity);
5469 if (smu7_profiling[i].bupdate_sclk)
5470 size += sprintf(buf + size, "%3d %16s: %8d %16d %16d ",
5471 i, profile_name[i], smu7_profiling[i].sclk_up_hyst,
5472 smu7_profiling[i].sclk_down_hyst,
5473 smu7_profiling[i].sclk_activity);
5475 size += sprintf(buf + size, "%3d %16s: %8s %16s %16s ",
5476 i, profile_name[i], "-", "-", "-");
5478 if (smu7_profiling[i].bupdate_mclk)
5479 size += sprintf(buf + size, "%16d %16d %16d\n",
5480 smu7_profiling[i].mclk_up_hyst,
5481 smu7_profiling[i].mclk_down_hyst,
5482 smu7_profiling[i].mclk_activity);
5484 size += sprintf(buf + size, "%16s %16s %16s\n",
5491 static void smu7_patch_compute_profile_mode(struct pp_hwmgr *hwmgr,
5492 enum PP_SMC_POWER_PROFILE requst)
5494 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5495 uint32_t tmp, level;
5497 if (requst == PP_SMC_POWER_PROFILE_COMPUTE) {
5498 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
5500 tmp = data->dpm_level_enable_mask.sclk_dpm_enable_mask;
5504 smu7_force_clock_level(hwmgr, PP_SCLK, 3 << (level-1));
5506 } else if (hwmgr->power_profile_mode == PP_SMC_POWER_PROFILE_COMPUTE) {
5507 smu7_force_clock_level(hwmgr, PP_SCLK, data->dpm_level_enable_mask.sclk_dpm_enable_mask);
5511 static int smu7_set_power_profile_mode(struct pp_hwmgr *hwmgr, long *input, uint32_t size)
5513 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
5514 struct profile_mode_setting tmp;
5515 enum PP_SMC_POWER_PROFILE mode;
5522 case PP_SMC_POWER_PROFILE_CUSTOM:
5523 if (size < 8 && size != 0)
5525 /* If only CUSTOM is passed in, use the saved values. Check
5526 * that we actually have a CUSTOM profile by ensuring that
5527 * the "use sclk" or the "use mclk" bits are set
5529 tmp = smu7_profiling[PP_SMC_POWER_PROFILE_CUSTOM];
5531 if (tmp.bupdate_sclk == 0 && tmp.bupdate_mclk == 0)
5534 tmp.bupdate_sclk = input[0];
5535 tmp.sclk_up_hyst = input[1];
5536 tmp.sclk_down_hyst = input[2];
5537 tmp.sclk_activity = input[3];
5538 tmp.bupdate_mclk = input[4];
5539 tmp.mclk_up_hyst = input[5];
5540 tmp.mclk_down_hyst = input[6];
5541 tmp.mclk_activity = input[7];
5542 smu7_profiling[PP_SMC_POWER_PROFILE_CUSTOM] = tmp;
5544 if (!smum_update_dpm_settings(hwmgr, &tmp)) {
5545 memcpy(&data->current_profile_setting, &tmp, sizeof(struct profile_mode_setting));
5546 hwmgr->power_profile_mode = mode;
5549 case PP_SMC_POWER_PROFILE_FULLSCREEN3D:
5550 case PP_SMC_POWER_PROFILE_POWERSAVING:
5551 case PP_SMC_POWER_PROFILE_VIDEO:
5552 case PP_SMC_POWER_PROFILE_VR:
5553 case PP_SMC_POWER_PROFILE_COMPUTE:
5554 if (mode == hwmgr->power_profile_mode)
5557 memcpy(&tmp, &smu7_profiling[mode], sizeof(struct profile_mode_setting));
5558 if (!smum_update_dpm_settings(hwmgr, &tmp)) {
5559 if (tmp.bupdate_sclk) {
5560 data->current_profile_setting.bupdate_sclk = tmp.bupdate_sclk;
5561 data->current_profile_setting.sclk_up_hyst = tmp.sclk_up_hyst;
5562 data->current_profile_setting.sclk_down_hyst = tmp.sclk_down_hyst;
5563 data->current_profile_setting.sclk_activity = tmp.sclk_activity;
5565 if (tmp.bupdate_mclk) {
5566 data->current_profile_setting.bupdate_mclk = tmp.bupdate_mclk;
5567 data->current_profile_setting.mclk_up_hyst = tmp.mclk_up_hyst;
5568 data->current_profile_setting.mclk_down_hyst = tmp.mclk_down_hyst;
5569 data->current_profile_setting.mclk_activity = tmp.mclk_activity;
5571 smu7_patch_compute_profile_mode(hwmgr, mode);
5572 hwmgr->power_profile_mode = mode;
5582 static int smu7_get_performance_level(struct pp_hwmgr *hwmgr, const struct pp_hw_power_state *state,
5583 PHM_PerformanceLevelDesignation designation, uint32_t index,
5584 PHM_PerformanceLevel *level)
5586 const struct smu7_power_state *ps;
5589 if (level == NULL || hwmgr == NULL || state == NULL)
5592 ps = cast_const_phw_smu7_power_state(state);
5594 i = index > ps->performance_level_count - 1 ?
5595 ps->performance_level_count - 1 : index;
5597 level->coreClock = ps->performance_levels[i].engine_clock;
5598 level->memory_clock = ps->performance_levels[i].memory_clock;
5603 static int smu7_power_off_asic(struct pp_hwmgr *hwmgr)
5607 result = smu7_disable_dpm_tasks(hwmgr);
5608 PP_ASSERT_WITH_CODE((0 == result),
5609 "[disable_dpm_tasks] Failed to disable DPM!",
5615 static const struct pp_hwmgr_func smu7_hwmgr_funcs = {
5616 .backend_init = &smu7_hwmgr_backend_init,
5617 .backend_fini = &smu7_hwmgr_backend_fini,
5618 .asic_setup = &smu7_setup_asic_task,
5619 .dynamic_state_management_enable = &smu7_enable_dpm_tasks,
5620 .apply_state_adjust_rules = smu7_apply_state_adjust_rules,
5621 .force_dpm_level = &smu7_force_dpm_level,
5622 .power_state_set = smu7_set_power_state_tasks,
5623 .get_power_state_size = smu7_get_power_state_size,
5624 .get_mclk = smu7_dpm_get_mclk,
5625 .get_sclk = smu7_dpm_get_sclk,
5626 .patch_boot_state = smu7_dpm_patch_boot_state,
5627 .get_pp_table_entry = smu7_get_pp_table_entry,
5628 .get_num_of_pp_table_entries = smu7_get_number_of_powerplay_table_entries,
5629 .powerdown_uvd = smu7_powerdown_uvd,
5630 .powergate_uvd = smu7_powergate_uvd,
5631 .powergate_vce = smu7_powergate_vce,
5632 .disable_clock_power_gating = smu7_disable_clock_power_gating,
5633 .update_clock_gatings = smu7_update_clock_gatings,
5634 .notify_smc_display_config_after_ps_adjustment = smu7_notify_smc_display_config_after_ps_adjustment,
5635 .display_config_changed = smu7_display_configuration_changed_task,
5636 .set_max_fan_pwm_output = smu7_set_max_fan_pwm_output,
5637 .set_max_fan_rpm_output = smu7_set_max_fan_rpm_output,
5638 .stop_thermal_controller = smu7_thermal_stop_thermal_controller,
5639 .get_fan_speed_info = smu7_fan_ctrl_get_fan_speed_info,
5640 .get_fan_speed_percent = smu7_fan_ctrl_get_fan_speed_percent,
5641 .set_fan_speed_percent = smu7_fan_ctrl_set_fan_speed_percent,
5642 .reset_fan_speed_to_default = smu7_fan_ctrl_reset_fan_speed_to_default,
5643 .get_fan_speed_rpm = smu7_fan_ctrl_get_fan_speed_rpm,
5644 .set_fan_speed_rpm = smu7_fan_ctrl_set_fan_speed_rpm,
5645 .uninitialize_thermal_controller = smu7_thermal_ctrl_uninitialize_thermal_controller,
5646 .register_irq_handlers = smu7_register_irq_handlers,
5647 .check_smc_update_required_for_display_configuration = smu7_check_smc_update_required_for_display_configuration,
5648 .check_states_equal = smu7_check_states_equal,
5649 .set_fan_control_mode = smu7_set_fan_control_mode,
5650 .get_fan_control_mode = smu7_get_fan_control_mode,
5651 .force_clock_level = smu7_force_clock_level,
5652 .print_clock_levels = smu7_print_clock_levels,
5653 .powergate_gfx = smu7_powergate_gfx,
5654 .get_sclk_od = smu7_get_sclk_od,
5655 .set_sclk_od = smu7_set_sclk_od,
5656 .get_mclk_od = smu7_get_mclk_od,
5657 .set_mclk_od = smu7_set_mclk_od,
5658 .get_clock_by_type = smu7_get_clock_by_type,
5659 .get_clock_by_type_with_latency = smu7_get_clock_by_type_with_latency,
5660 .set_watermarks_for_clocks_ranges = smu7_set_watermarks_for_clocks_ranges,
5661 .read_sensor = smu7_read_sensor,
5662 .dynamic_state_management_disable = smu7_disable_dpm_tasks,
5663 .avfs_control = smu7_avfs_control,
5664 .disable_smc_firmware_ctf = smu7_thermal_disable_alert,
5665 .start_thermal_controller = smu7_start_thermal_controller,
5666 .notify_cac_buffer_info = smu7_notify_cac_buffer_info,
5667 .get_max_high_clocks = smu7_get_max_high_clocks,
5668 .get_thermal_temperature_range = smu7_get_thermal_temperature_range,
5669 .odn_edit_dpm_table = smu7_odn_edit_dpm_table,
5670 .set_power_limit = smu7_set_power_limit,
5671 .get_power_profile_mode = smu7_get_power_profile_mode,
5672 .set_power_profile_mode = smu7_set_power_profile_mode,
5673 .get_performance_level = smu7_get_performance_level,
5674 .get_asic_baco_capability = smu7_baco_get_capability,
5675 .get_asic_baco_state = smu7_baco_get_state,
5676 .set_asic_baco_state = smu7_baco_set_state,
5677 .power_off_asic = smu7_power_off_asic,
5680 uint8_t smu7_get_sleep_divider_id_from_clock(uint32_t clock,
5681 uint32_t clock_insr)
5685 uint32_t min = max(clock_insr, (uint32_t)SMU7_MINIMUM_ENGINE_CLOCK);
5687 PP_ASSERT_WITH_CODE((clock >= min), "Engine clock can't satisfy stutter requirement!", return 0);
5688 for (i = SMU7_MAX_DEEPSLEEP_DIVIDER_ID; ; i--) {
5691 if (temp >= min || i == 0)
5697 int smu7_init_function_pointers(struct pp_hwmgr *hwmgr)
5699 hwmgr->hwmgr_func = &smu7_hwmgr_funcs;
5700 if (hwmgr->pp_table_version == PP_TABLE_V0)
5701 hwmgr->pptable_func = &pptable_funcs;
5702 else if (hwmgr->pp_table_version == PP_TABLE_V1)
5703 hwmgr->pptable_func = &pptable_v1_0_funcs;