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.
23 #include <linux/module.h>
24 #include <linux/slab.h>
26 #include <asm/div64.h>
27 #include "linux/delay.h"
30 #include "polaris10_hwmgr.h"
31 #include "polaris10_powertune.h"
32 #include "polaris10_dyn_defaults.h"
33 #include "polaris10_smumgr.h"
35 #include "ppatomctrl.h"
37 #include "tonga_pptable.h"
38 #include "pppcielanes.h"
39 #include "amd_pcie_helpers.h"
40 #include "hardwaremanager.h"
41 #include "tonga_processpptables.h"
42 #include "cgs_common.h"
44 #include "smu_ucode_xfer_vi.h"
45 #include "smu74_discrete.h"
46 #include "smu/smu_7_1_3_d.h"
47 #include "smu/smu_7_1_3_sh_mask.h"
48 #include "gmc/gmc_8_1_d.h"
49 #include "gmc/gmc_8_1_sh_mask.h"
50 #include "oss/oss_3_0_d.h"
51 #include "gca/gfx_8_0_d.h"
52 #include "bif/bif_5_0_d.h"
53 #include "bif/bif_5_0_sh_mask.h"
54 #include "gmc/gmc_8_1_d.h"
55 #include "gmc/gmc_8_1_sh_mask.h"
56 #include "bif/bif_5_0_d.h"
57 #include "bif/bif_5_0_sh_mask.h"
58 #include "dce/dce_10_0_d.h"
59 #include "dce/dce_10_0_sh_mask.h"
61 #include "polaris10_thermal.h"
62 #include "polaris10_clockpowergating.h"
64 #define MC_CG_ARB_FREQ_F0 0x0a
65 #define MC_CG_ARB_FREQ_F1 0x0b
66 #define MC_CG_ARB_FREQ_F2 0x0c
67 #define MC_CG_ARB_FREQ_F3 0x0d
69 #define MC_CG_SEQ_DRAMCONF_S0 0x05
70 #define MC_CG_SEQ_DRAMCONF_S1 0x06
71 #define MC_CG_SEQ_YCLK_SUSPEND 0x04
72 #define MC_CG_SEQ_YCLK_RESUME 0x0a
75 #define SMC_RAM_END 0x40000
77 #define SMC_CG_IND_START 0xc0030000
78 #define SMC_CG_IND_END 0xc0040000
80 #define VOLTAGE_SCALE 4
81 #define VOLTAGE_VID_OFFSET_SCALE1 625
82 #define VOLTAGE_VID_OFFSET_SCALE2 100
84 #define VDDC_VDDCI_DELTA 200
86 #define MEM_FREQ_LOW_LATENCY 25000
87 #define MEM_FREQ_HIGH_LATENCY 80000
89 #define MEM_LATENCY_HIGH 45
90 #define MEM_LATENCY_LOW 35
91 #define MEM_LATENCY_ERR 0xFFFF
93 #define MC_SEQ_MISC0_GDDR5_SHIFT 28
94 #define MC_SEQ_MISC0_GDDR5_MASK 0xf0000000
95 #define MC_SEQ_MISC0_GDDR5_VALUE 5
98 #define PCIE_BUS_CLK 10000
99 #define TCLK (PCIE_BUS_CLK / 10)
102 static const uint16_t polaris10_clock_stretcher_lookup_table[2][4] =
103 { {600, 1050, 3, 0}, {600, 1050, 6, 1} };
105 /* [FF, SS] type, [] 4 voltage ranges, and [Floor Freq, Boundary Freq, VID min , VID max] */
106 static const uint32_t polaris10_clock_stretcher_ddt_table[2][4][4] =
107 { { {265, 529, 120, 128}, {325, 650, 96, 119}, {430, 860, 32, 95}, {0, 0, 0, 31} },
108 { {275, 550, 104, 112}, {319, 638, 96, 103}, {360, 720, 64, 95}, {384, 768, 32, 63} } };
110 /* [Use_For_Low_freq] value, [0%, 5%, 10%, 7.14%, 14.28%, 20%] (coming from PWR_CKS_CNTL.stretch_amount reg spec) */
111 static const uint8_t polaris10_clock_stretch_amount_conversion[2][6] =
112 { {0, 1, 3, 2, 4, 5}, {0, 2, 4, 5, 6, 5} };
114 /** Values for the CG_THERMAL_CTRL::DPM_EVENT_SRC field. */
116 DPM_EVENT_SRC_ANALOG = 0,
117 DPM_EVENT_SRC_EXTERNAL = 1,
118 DPM_EVENT_SRC_DIGITAL = 2,
119 DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
120 DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL = 4
123 static const unsigned long PhwPolaris10_Magic = (unsigned long)(PHM_VIslands_Magic);
125 struct polaris10_power_state *cast_phw_polaris10_power_state(
126 struct pp_hw_power_state *hw_ps)
128 PP_ASSERT_WITH_CODE((PhwPolaris10_Magic == hw_ps->magic),
129 "Invalid Powerstate Type!",
132 return (struct polaris10_power_state *)hw_ps;
135 const struct polaris10_power_state *cast_const_phw_polaris10_power_state(
136 const struct pp_hw_power_state *hw_ps)
138 PP_ASSERT_WITH_CODE((PhwPolaris10_Magic == hw_ps->magic),
139 "Invalid Powerstate Type!",
142 return (const struct polaris10_power_state *)hw_ps;
145 static bool polaris10_is_dpm_running(struct pp_hwmgr *hwmgr)
147 return (1 == PHM_READ_INDIRECT_FIELD(hwmgr->device,
148 CGS_IND_REG__SMC, FEATURE_STATUS, VOLTAGE_CONTROLLER_ON))
153 * Find the MC microcode version and store it in the HwMgr struct
155 * @param hwmgr the address of the powerplay hardware manager.
158 int phm_get_mc_microcode_version (struct pp_hwmgr *hwmgr)
160 cgs_write_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_INDEX, 0x9F);
162 hwmgr->microcode_version_info.MC = cgs_read_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_DATA);
167 uint16_t phm_get_current_pcie_speed(struct pp_hwmgr *hwmgr)
169 uint32_t speedCntl = 0;
171 /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
172 speedCntl = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__PCIE,
173 ixPCIE_LC_SPEED_CNTL);
174 return((uint16_t)PHM_GET_FIELD(speedCntl,
175 PCIE_LC_SPEED_CNTL, LC_CURRENT_DATA_RATE));
178 int phm_get_current_pcie_lane_number(struct pp_hwmgr *hwmgr)
182 /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
183 link_width = PHM_READ_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE,
184 PCIE_LC_LINK_WIDTH_CNTL, LC_LINK_WIDTH_RD);
186 PP_ASSERT_WITH_CODE((7 >= link_width),
187 "Invalid PCIe lane width!", return 0);
189 return decode_pcie_lane_width(link_width);
193 * Enable voltage control
195 * @param pHwMgr the address of the powerplay hardware manager.
196 * @return always PP_Result_OK
198 int polaris10_enable_smc_voltage_controller(struct pp_hwmgr *hwmgr)
201 (hwmgr->smumgr->smumgr_funcs->send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_Voltage_Cntl_Enable) == 0),
202 "Failed to enable voltage DPM during DPM Start Function!",
210 * Checks if we want to support voltage control
212 * @param hwmgr the address of the powerplay hardware manager.
214 static bool polaris10_voltage_control(const struct pp_hwmgr *hwmgr)
216 const struct polaris10_hwmgr *data =
217 (const struct polaris10_hwmgr *)(hwmgr->backend);
219 return (POLARIS10_VOLTAGE_CONTROL_NONE != data->voltage_control);
223 * Enable voltage control
225 * @param hwmgr the address of the powerplay hardware manager.
228 static int polaris10_enable_voltage_control(struct pp_hwmgr *hwmgr)
230 /* enable voltage control */
231 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
232 GENERAL_PWRMGT, VOLT_PWRMGT_EN, 1);
238 * Create Voltage Tables.
240 * @param hwmgr the address of the powerplay hardware manager.
243 static int polaris10_construct_voltage_tables(struct pp_hwmgr *hwmgr)
245 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
246 struct phm_ppt_v1_information *table_info =
247 (struct phm_ppt_v1_information *)hwmgr->pptable;
250 if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
251 result = atomctrl_get_voltage_table_v3(hwmgr,
252 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT,
253 &(data->mvdd_voltage_table));
254 PP_ASSERT_WITH_CODE((0 == result),
255 "Failed to retrieve MVDD table.",
257 } else if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) {
258 result = phm_get_svi2_mvdd_voltage_table(&(data->mvdd_voltage_table),
259 table_info->vdd_dep_on_mclk);
260 PP_ASSERT_WITH_CODE((0 == result),
261 "Failed to retrieve SVI2 MVDD table from dependancy table.",
265 if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
266 result = atomctrl_get_voltage_table_v3(hwmgr,
267 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT,
268 &(data->vddci_voltage_table));
269 PP_ASSERT_WITH_CODE((0 == result),
270 "Failed to retrieve VDDCI table.",
272 } else if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) {
273 result = phm_get_svi2_vddci_voltage_table(&(data->vddci_voltage_table),
274 table_info->vdd_dep_on_mclk);
275 PP_ASSERT_WITH_CODE((0 == result),
276 "Failed to retrieve SVI2 VDDCI table from dependancy table.",
280 if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
281 result = phm_get_svi2_vdd_voltage_table(&(data->vddc_voltage_table),
282 table_info->vddc_lookup_table);
283 PP_ASSERT_WITH_CODE((0 == result),
284 "Failed to retrieve SVI2 VDDC table from lookup table.",
289 (data->vddc_voltage_table.count <= (SMU74_MAX_LEVELS_VDDC)),
290 "Too many voltage values for VDDC. Trimming to fit state table.",
291 phm_trim_voltage_table_to_fit_state_table(SMU74_MAX_LEVELS_VDDC,
292 &(data->vddc_voltage_table)));
295 (data->vddci_voltage_table.count <= (SMU74_MAX_LEVELS_VDDCI)),
296 "Too many voltage values for VDDCI. Trimming to fit state table.",
297 phm_trim_voltage_table_to_fit_state_table(SMU74_MAX_LEVELS_VDDCI,
298 &(data->vddci_voltage_table)));
301 (data->mvdd_voltage_table.count <= (SMU74_MAX_LEVELS_MVDD)),
302 "Too many voltage values for MVDD. Trimming to fit state table.",
303 phm_trim_voltage_table_to_fit_state_table(SMU74_MAX_LEVELS_MVDD,
304 &(data->mvdd_voltage_table)));
310 * Programs static screed detection parameters
312 * @param hwmgr the address of the powerplay hardware manager.
315 static int polaris10_program_static_screen_threshold_parameters(
316 struct pp_hwmgr *hwmgr)
318 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
320 /* Set static screen threshold unit */
321 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
322 CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD_UNIT,
323 data->static_screen_threshold_unit);
324 /* Set static screen threshold */
325 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
326 CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD,
327 data->static_screen_threshold);
333 * Setup display gap for glitch free memory clock switching.
335 * @param hwmgr the address of the powerplay hardware manager.
338 static int polaris10_enable_display_gap(struct pp_hwmgr *hwmgr)
340 uint32_t display_gap =
341 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
342 ixCG_DISPLAY_GAP_CNTL);
344 display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL,
345 DISP_GAP, DISPLAY_GAP_IGNORE);
347 display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL,
348 DISP_GAP_MCHG, DISPLAY_GAP_VBLANK);
350 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
351 ixCG_DISPLAY_GAP_CNTL, display_gap);
357 * Programs activity state transition voting clients
359 * @param hwmgr the address of the powerplay hardware manager.
362 static int polaris10_program_voting_clients(struct pp_hwmgr *hwmgr)
364 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
366 /* Clear reset for voting clients before enabling DPM */
367 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
368 SCLK_PWRMGT_CNTL, RESET_SCLK_CNT, 0);
369 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
370 SCLK_PWRMGT_CNTL, RESET_BUSY_CNT, 0);
372 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
373 ixCG_FREQ_TRAN_VOTING_0, data->voting_rights_clients0);
374 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
375 ixCG_FREQ_TRAN_VOTING_1, data->voting_rights_clients1);
376 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
377 ixCG_FREQ_TRAN_VOTING_2, data->voting_rights_clients2);
378 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
379 ixCG_FREQ_TRAN_VOTING_3, data->voting_rights_clients3);
380 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
381 ixCG_FREQ_TRAN_VOTING_4, data->voting_rights_clients4);
382 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
383 ixCG_FREQ_TRAN_VOTING_5, data->voting_rights_clients5);
384 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
385 ixCG_FREQ_TRAN_VOTING_6, data->voting_rights_clients6);
386 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
387 ixCG_FREQ_TRAN_VOTING_7, data->voting_rights_clients7);
392 static int polaris10_clear_voting_clients(struct pp_hwmgr *hwmgr)
394 /* Reset voting clients before disabling DPM */
395 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
396 SCLK_PWRMGT_CNTL, RESET_SCLK_CNT, 1);
397 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
398 SCLK_PWRMGT_CNTL, RESET_BUSY_CNT, 1);
400 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
401 ixCG_FREQ_TRAN_VOTING_0, 0);
402 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
403 ixCG_FREQ_TRAN_VOTING_1, 0);
404 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
405 ixCG_FREQ_TRAN_VOTING_2, 0);
406 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
407 ixCG_FREQ_TRAN_VOTING_3, 0);
408 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
409 ixCG_FREQ_TRAN_VOTING_4, 0);
410 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
411 ixCG_FREQ_TRAN_VOTING_5, 0);
412 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
413 ixCG_FREQ_TRAN_VOTING_6, 0);
414 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
415 ixCG_FREQ_TRAN_VOTING_7, 0);
421 * Get the location of various tables inside the FW image.
423 * @param hwmgr the address of the powerplay hardware manager.
426 static int polaris10_process_firmware_header(struct pp_hwmgr *hwmgr)
428 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
429 struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smumgr->backend);
434 result = polaris10_read_smc_sram_dword(hwmgr->smumgr,
435 SMU7_FIRMWARE_HEADER_LOCATION +
436 offsetof(SMU74_Firmware_Header, DpmTable),
437 &tmp, data->sram_end);
440 data->dpm_table_start = tmp;
442 error |= (0 != result);
444 result = polaris10_read_smc_sram_dword(hwmgr->smumgr,
445 SMU7_FIRMWARE_HEADER_LOCATION +
446 offsetof(SMU74_Firmware_Header, SoftRegisters),
447 &tmp, data->sram_end);
450 data->soft_regs_start = tmp;
451 smu_data->soft_regs_start = tmp;
454 error |= (0 != result);
456 result = polaris10_read_smc_sram_dword(hwmgr->smumgr,
457 SMU7_FIRMWARE_HEADER_LOCATION +
458 offsetof(SMU74_Firmware_Header, mcRegisterTable),
459 &tmp, data->sram_end);
462 data->mc_reg_table_start = tmp;
464 result = polaris10_read_smc_sram_dword(hwmgr->smumgr,
465 SMU7_FIRMWARE_HEADER_LOCATION +
466 offsetof(SMU74_Firmware_Header, FanTable),
467 &tmp, data->sram_end);
470 data->fan_table_start = tmp;
472 error |= (0 != result);
474 result = polaris10_read_smc_sram_dword(hwmgr->smumgr,
475 SMU7_FIRMWARE_HEADER_LOCATION +
476 offsetof(SMU74_Firmware_Header, mcArbDramTimingTable),
477 &tmp, data->sram_end);
480 data->arb_table_start = tmp;
482 error |= (0 != result);
484 result = polaris10_read_smc_sram_dword(hwmgr->smumgr,
485 SMU7_FIRMWARE_HEADER_LOCATION +
486 offsetof(SMU74_Firmware_Header, Version),
487 &tmp, data->sram_end);
490 hwmgr->microcode_version_info.SMC = tmp;
492 error |= (0 != result);
494 return error ? -1 : 0;
497 /* Copy one arb setting to another and then switch the active set.
498 * arb_src and arb_dest is one of the MC_CG_ARB_FREQ_Fx constants.
500 static int polaris10_copy_and_switch_arb_sets(struct pp_hwmgr *hwmgr,
501 uint32_t arb_src, uint32_t arb_dest)
503 uint32_t mc_arb_dram_timing;
504 uint32_t mc_arb_dram_timing2;
506 uint32_t mc_cg_config;
509 case MC_CG_ARB_FREQ_F0:
510 mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
511 mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
512 burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0);
514 case MC_CG_ARB_FREQ_F1:
515 mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1);
516 mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1);
517 burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1);
524 case MC_CG_ARB_FREQ_F0:
525 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING, mc_arb_dram_timing);
526 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2, mc_arb_dram_timing2);
527 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0, burst_time);
529 case MC_CG_ARB_FREQ_F1:
530 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1, mc_arb_dram_timing);
531 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1, mc_arb_dram_timing2);
532 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1, burst_time);
538 mc_cg_config = cgs_read_register(hwmgr->device, mmMC_CG_CONFIG);
539 mc_cg_config |= 0x0000000F;
540 cgs_write_register(hwmgr->device, mmMC_CG_CONFIG, mc_cg_config);
541 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_CG, CG_ARB_REQ, arb_dest);
546 static int polaris10_reset_to_default(struct pp_hwmgr *hwmgr)
548 return smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_ResetToDefaults);
552 * Initial switch from ARB F0->F1
554 * @param hwmgr the address of the powerplay hardware manager.
556 * This function is to be called from the SetPowerState table.
558 static int polaris10_initial_switch_from_arbf0_to_f1(struct pp_hwmgr *hwmgr)
560 return polaris10_copy_and_switch_arb_sets(hwmgr,
561 MC_CG_ARB_FREQ_F0, MC_CG_ARB_FREQ_F1);
564 static int polaris10_force_switch_to_arbf0(struct pp_hwmgr *hwmgr)
568 tmp = (cgs_read_ind_register(hwmgr->device,
569 CGS_IND_REG__SMC, ixSMC_SCRATCH9) &
572 if (tmp == MC_CG_ARB_FREQ_F0)
575 return polaris10_copy_and_switch_arb_sets(hwmgr,
576 tmp, MC_CG_ARB_FREQ_F0);
579 static int polaris10_setup_default_pcie_table(struct pp_hwmgr *hwmgr)
581 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
582 struct phm_ppt_v1_information *table_info =
583 (struct phm_ppt_v1_information *)(hwmgr->pptable);
584 struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table;
585 uint32_t i, max_entry;
587 PP_ASSERT_WITH_CODE((data->use_pcie_performance_levels ||
588 data->use_pcie_power_saving_levels), "No pcie performance levels!",
591 if (data->use_pcie_performance_levels &&
592 !data->use_pcie_power_saving_levels) {
593 data->pcie_gen_power_saving = data->pcie_gen_performance;
594 data->pcie_lane_power_saving = data->pcie_lane_performance;
595 } else if (!data->use_pcie_performance_levels &&
596 data->use_pcie_power_saving_levels) {
597 data->pcie_gen_performance = data->pcie_gen_power_saving;
598 data->pcie_lane_performance = data->pcie_lane_power_saving;
601 phm_reset_single_dpm_table(&data->dpm_table.pcie_speed_table,
602 SMU74_MAX_LEVELS_LINK,
603 MAX_REGULAR_DPM_NUMBER);
605 if (pcie_table != NULL) {
606 /* max_entry is used to make sure we reserve one PCIE level
607 * for boot level (fix for A+A PSPP issue).
608 * If PCIE table from PPTable have ULV entry + 8 entries,
609 * then ignore the last entry.*/
610 max_entry = (SMU74_MAX_LEVELS_LINK < pcie_table->count) ?
611 SMU74_MAX_LEVELS_LINK : pcie_table->count;
612 for (i = 1; i < max_entry; i++) {
613 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, i - 1,
614 get_pcie_gen_support(data->pcie_gen_cap,
615 pcie_table->entries[i].gen_speed),
616 get_pcie_lane_support(data->pcie_lane_cap,
617 pcie_table->entries[i].lane_width));
619 data->dpm_table.pcie_speed_table.count = max_entry - 1;
621 /* Setup BIF_SCLK levels */
622 for (i = 0; i < max_entry; i++)
623 data->bif_sclk_table[i] = pcie_table->entries[i].pcie_sclk;
625 /* Hardcode Pcie Table */
626 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 0,
627 get_pcie_gen_support(data->pcie_gen_cap,
629 get_pcie_lane_support(data->pcie_lane_cap,
631 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 1,
632 get_pcie_gen_support(data->pcie_gen_cap,
634 get_pcie_lane_support(data->pcie_lane_cap,
636 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 2,
637 get_pcie_gen_support(data->pcie_gen_cap,
639 get_pcie_lane_support(data->pcie_lane_cap,
641 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 3,
642 get_pcie_gen_support(data->pcie_gen_cap,
644 get_pcie_lane_support(data->pcie_lane_cap,
646 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 4,
647 get_pcie_gen_support(data->pcie_gen_cap,
649 get_pcie_lane_support(data->pcie_lane_cap,
651 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 5,
652 get_pcie_gen_support(data->pcie_gen_cap,
654 get_pcie_lane_support(data->pcie_lane_cap,
657 data->dpm_table.pcie_speed_table.count = 6;
659 /* Populate last level for boot PCIE level, but do not increment count. */
660 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table,
661 data->dpm_table.pcie_speed_table.count,
662 get_pcie_gen_support(data->pcie_gen_cap,
664 get_pcie_lane_support(data->pcie_lane_cap,
671 * This function is to initalize all DPM state tables
672 * for SMU7 based on the dependency table.
673 * Dynamic state patching function will then trim these
674 * state tables to the allowed range based
675 * on the power policy or external client requests,
676 * such as UVD request, etc.
678 int polaris10_setup_default_dpm_tables(struct pp_hwmgr *hwmgr)
680 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
681 struct phm_ppt_v1_information *table_info =
682 (struct phm_ppt_v1_information *)(hwmgr->pptable);
685 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table =
686 table_info->vdd_dep_on_sclk;
687 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
688 table_info->vdd_dep_on_mclk;
690 PP_ASSERT_WITH_CODE(dep_sclk_table != NULL,
691 "SCLK dependency table is missing. This table is mandatory",
693 PP_ASSERT_WITH_CODE(dep_sclk_table->count >= 1,
694 "SCLK dependency table has to have is missing."
695 "This table is mandatory",
698 PP_ASSERT_WITH_CODE(dep_mclk_table != NULL,
699 "MCLK dependency table is missing. This table is mandatory",
701 PP_ASSERT_WITH_CODE(dep_mclk_table->count >= 1,
702 "MCLK dependency table has to have is missing."
703 "This table is mandatory",
706 /* clear the state table to reset everything to default */
707 phm_reset_single_dpm_table(
708 &data->dpm_table.sclk_table, SMU74_MAX_LEVELS_GRAPHICS, MAX_REGULAR_DPM_NUMBER);
709 phm_reset_single_dpm_table(
710 &data->dpm_table.mclk_table, SMU74_MAX_LEVELS_MEMORY, MAX_REGULAR_DPM_NUMBER);
713 /* Initialize Sclk DPM table based on allow Sclk values */
714 data->dpm_table.sclk_table.count = 0;
715 for (i = 0; i < dep_sclk_table->count; i++) {
716 if (i == 0 || data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count - 1].value !=
717 dep_sclk_table->entries[i].clk) {
719 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].value =
720 dep_sclk_table->entries[i].clk;
722 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].enabled =
723 (i == 0) ? true : false;
724 data->dpm_table.sclk_table.count++;
728 /* Initialize Mclk DPM table based on allow Mclk values */
729 data->dpm_table.mclk_table.count = 0;
730 for (i = 0; i < dep_mclk_table->count; i++) {
731 if (i == 0 || data->dpm_table.mclk_table.dpm_levels
732 [data->dpm_table.mclk_table.count - 1].value !=
733 dep_mclk_table->entries[i].clk) {
734 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].value =
735 dep_mclk_table->entries[i].clk;
736 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].enabled =
737 (i == 0) ? true : false;
738 data->dpm_table.mclk_table.count++;
742 /* setup PCIE gen speed levels */
743 polaris10_setup_default_pcie_table(hwmgr);
745 /* save a copy of the default DPM table */
746 memcpy(&(data->golden_dpm_table), &(data->dpm_table),
747 sizeof(struct polaris10_dpm_table));
752 uint8_t convert_to_vid(uint16_t vddc)
754 return (uint8_t) ((6200 - (vddc * VOLTAGE_SCALE)) / 25);
758 * Mvdd table preparation for SMC.
760 * @param *hwmgr The address of the hardware manager.
761 * @param *table The SMC DPM table structure to be populated.
764 static int polaris10_populate_smc_mvdd_table(struct pp_hwmgr *hwmgr,
765 SMU74_Discrete_DpmTable *table)
767 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
768 uint32_t count, level;
770 if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
771 count = data->mvdd_voltage_table.count;
772 if (count > SMU_MAX_SMIO_LEVELS)
773 count = SMU_MAX_SMIO_LEVELS;
774 for (level = 0; level < count; level++) {
775 table->SmioTable2.Pattern[level].Voltage =
776 PP_HOST_TO_SMC_US(data->mvdd_voltage_table.entries[count].value * VOLTAGE_SCALE);
777 /* Index into DpmTable.Smio. Drive bits from Smio entry to get this voltage level.*/
778 table->SmioTable2.Pattern[level].Smio =
780 table->Smio[level] |=
781 data->mvdd_voltage_table.entries[level].smio_low;
783 table->SmioMask2 = data->mvdd_voltage_table.mask_low;
785 table->MvddLevelCount = (uint32_t) PP_HOST_TO_SMC_UL(count);
791 static int polaris10_populate_smc_vddci_table(struct pp_hwmgr *hwmgr,
792 struct SMU74_Discrete_DpmTable *table)
794 uint32_t count, level;
795 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
797 count = data->vddci_voltage_table.count;
799 if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
800 if (count > SMU_MAX_SMIO_LEVELS)
801 count = SMU_MAX_SMIO_LEVELS;
802 for (level = 0; level < count; ++level) {
803 table->SmioTable1.Pattern[level].Voltage =
804 PP_HOST_TO_SMC_US(data->vddci_voltage_table.entries[level].value * VOLTAGE_SCALE);
805 table->SmioTable1.Pattern[level].Smio = (uint8_t) level;
807 table->Smio[level] |= data->vddci_voltage_table.entries[level].smio_low;
811 table->SmioMask1 = data->vddci_voltage_table.mask_low;
817 * Preparation of vddc and vddgfx CAC tables for SMC.
819 * @param hwmgr the address of the hardware manager
820 * @param table the SMC DPM table structure to be populated
823 static int polaris10_populate_cac_table(struct pp_hwmgr *hwmgr,
824 struct SMU74_Discrete_DpmTable *table)
828 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
829 struct phm_ppt_v1_information *table_info =
830 (struct phm_ppt_v1_information *)(hwmgr->pptable);
831 struct phm_ppt_v1_voltage_lookup_table *lookup_table =
832 table_info->vddc_lookup_table;
833 /* tables is already swapped, so in order to use the value from it,
834 * we need to swap it back.
835 * We are populating vddc CAC data to BapmVddc table
836 * in split and merged mode
838 for (count = 0; count < lookup_table->count; count++) {
839 index = phm_get_voltage_index(lookup_table,
840 data->vddc_voltage_table.entries[count].value);
841 table->BapmVddcVidLoSidd[count] = convert_to_vid(lookup_table->entries[index].us_cac_low);
842 table->BapmVddcVidHiSidd[count] = convert_to_vid(lookup_table->entries[index].us_cac_mid);
843 table->BapmVddcVidHiSidd2[count] = convert_to_vid(lookup_table->entries[index].us_cac_high);
850 * Preparation of voltage tables for SMC.
852 * @param hwmgr the address of the hardware manager
853 * @param table the SMC DPM table structure to be populated
857 int polaris10_populate_smc_voltage_tables(struct pp_hwmgr *hwmgr,
858 struct SMU74_Discrete_DpmTable *table)
860 polaris10_populate_smc_vddci_table(hwmgr, table);
861 polaris10_populate_smc_mvdd_table(hwmgr, table);
862 polaris10_populate_cac_table(hwmgr, table);
867 static int polaris10_populate_ulv_level(struct pp_hwmgr *hwmgr,
868 struct SMU74_Discrete_Ulv *state)
870 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
871 struct phm_ppt_v1_information *table_info =
872 (struct phm_ppt_v1_information *)(hwmgr->pptable);
874 state->CcPwrDynRm = 0;
875 state->CcPwrDynRm1 = 0;
877 state->VddcOffset = (uint16_t) table_info->us_ulv_voltage_offset;
878 state->VddcOffsetVid = (uint8_t)(table_info->us_ulv_voltage_offset *
879 VOLTAGE_VID_OFFSET_SCALE2 / VOLTAGE_VID_OFFSET_SCALE1);
881 state->VddcPhase = (data->vddc_phase_shed_control) ? 0 : 1;
883 CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm);
884 CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm1);
885 CONVERT_FROM_HOST_TO_SMC_US(state->VddcOffset);
890 static int polaris10_populate_ulv_state(struct pp_hwmgr *hwmgr,
891 struct SMU74_Discrete_DpmTable *table)
893 return polaris10_populate_ulv_level(hwmgr, &table->Ulv);
896 static int polaris10_populate_smc_link_level(struct pp_hwmgr *hwmgr,
897 struct SMU74_Discrete_DpmTable *table)
899 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
900 struct polaris10_dpm_table *dpm_table = &data->dpm_table;
903 /* Index (dpm_table->pcie_speed_table.count)
904 * is reserved for PCIE boot level. */
905 for (i = 0; i <= dpm_table->pcie_speed_table.count; i++) {
906 table->LinkLevel[i].PcieGenSpeed =
907 (uint8_t)dpm_table->pcie_speed_table.dpm_levels[i].value;
908 table->LinkLevel[i].PcieLaneCount = (uint8_t)encode_pcie_lane_width(
909 dpm_table->pcie_speed_table.dpm_levels[i].param1);
910 table->LinkLevel[i].EnabledForActivity = 1;
911 table->LinkLevel[i].SPC = (uint8_t)(data->pcie_spc_cap & 0xff);
912 table->LinkLevel[i].DownThreshold = PP_HOST_TO_SMC_UL(5);
913 table->LinkLevel[i].UpThreshold = PP_HOST_TO_SMC_UL(30);
916 data->smc_state_table.LinkLevelCount =
917 (uint8_t)dpm_table->pcie_speed_table.count;
918 data->dpm_level_enable_mask.pcie_dpm_enable_mask =
919 phm_get_dpm_level_enable_mask_value(&dpm_table->pcie_speed_table);
924 static uint32_t polaris10_get_xclk(struct pp_hwmgr *hwmgr)
926 uint32_t reference_clock, tmp;
927 struct cgs_display_info info = {0};
928 struct cgs_mode_info mode_info;
930 info.mode_info = &mode_info;
932 tmp = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_CLKPIN_CNTL_2, MUX_TCLK_TO_XCLK);
937 cgs_get_active_displays_info(hwmgr->device, &info);
938 reference_clock = mode_info.ref_clock;
940 tmp = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_CLKPIN_CNTL, XTALIN_DIVIDE);
943 return reference_clock / 4;
945 return reference_clock;
949 * Calculates the SCLK dividers using the provided engine clock
951 * @param hwmgr the address of the hardware manager
952 * @param clock the engine clock to use to populate the structure
953 * @param sclk the SMC SCLK structure to be populated
955 static int polaris10_calculate_sclk_params(struct pp_hwmgr *hwmgr,
956 uint32_t clock, SMU_SclkSetting *sclk_setting)
958 const struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
959 const SMU74_Discrete_DpmTable *table = &(data->smc_state_table);
960 struct pp_atomctrl_clock_dividers_ai dividers;
963 uint32_t pcc_target_percent, pcc_target_freq, ss_target_percent, ss_target_freq;
968 sclk_setting->SclkFrequency = clock;
969 /* get the engine clock dividers for this clock value */
970 result = atomctrl_get_engine_pll_dividers_ai(hwmgr, clock, ÷rs);
972 sclk_setting->Fcw_int = dividers.usSclk_fcw_int;
973 sclk_setting->Fcw_frac = dividers.usSclk_fcw_frac;
974 sclk_setting->Pcc_fcw_int = dividers.usPcc_fcw_int;
975 sclk_setting->PllRange = dividers.ucSclkPllRange;
976 sclk_setting->Sclk_slew_rate = 0x400;
977 sclk_setting->Pcc_up_slew_rate = dividers.usPcc_fcw_slew_frac;
978 sclk_setting->Pcc_down_slew_rate = 0xffff;
979 sclk_setting->SSc_En = dividers.ucSscEnable;
980 sclk_setting->Fcw1_int = dividers.usSsc_fcw1_int;
981 sclk_setting->Fcw1_frac = dividers.usSsc_fcw1_frac;
982 sclk_setting->Sclk_ss_slew_rate = dividers.usSsc_fcw_slew_frac;
986 ref_clock = polaris10_get_xclk(hwmgr);
988 for (i = 0; i < NUM_SCLK_RANGE; i++) {
989 if (clock > data->range_table[i].trans_lower_frequency
990 && clock <= data->range_table[i].trans_upper_frequency) {
991 sclk_setting->PllRange = i;
996 sclk_setting->Fcw_int = (uint16_t)((clock << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv) / ref_clock);
997 temp = clock << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv;
999 do_div(temp, ref_clock);
1000 sclk_setting->Fcw_frac = temp & 0xffff;
1002 pcc_target_percent = 10; /* Hardcode 10% for now. */
1003 pcc_target_freq = clock - (clock * pcc_target_percent / 100);
1004 sclk_setting->Pcc_fcw_int = (uint16_t)((pcc_target_freq << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv) / ref_clock);
1006 ss_target_percent = 2; /* Hardcode 2% for now. */
1007 sclk_setting->SSc_En = 0;
1008 if (ss_target_percent) {
1009 sclk_setting->SSc_En = 1;
1010 ss_target_freq = clock - (clock * ss_target_percent / 100);
1011 sclk_setting->Fcw1_int = (uint16_t)((ss_target_freq << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv) / ref_clock);
1012 temp = ss_target_freq << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv;
1014 do_div(temp, ref_clock);
1015 sclk_setting->Fcw1_frac = temp & 0xffff;
1021 static int polaris10_get_dependency_volt_by_clk(struct pp_hwmgr *hwmgr,
1022 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table,
1023 uint32_t clock, SMU_VoltageLevel *voltage, uint32_t *mvdd)
1027 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1029 *voltage = *mvdd = 0;
1031 /* clock - voltage dependency table is empty table */
1032 if (dep_table->count == 0)
1035 for (i = 0; i < dep_table->count; i++) {
1036 /* find first sclk bigger than request */
1037 if (dep_table->entries[i].clk >= clock) {
1038 *voltage |= (dep_table->entries[i].vddc *
1039 VOLTAGE_SCALE) << VDDC_SHIFT;
1040 if (POLARIS10_VOLTAGE_CONTROL_NONE == data->vddci_control)
1041 *voltage |= (data->vbios_boot_state.vddci_bootup_value *
1042 VOLTAGE_SCALE) << VDDCI_SHIFT;
1043 else if (dep_table->entries[i].vddci)
1044 *voltage |= (dep_table->entries[i].vddci *
1045 VOLTAGE_SCALE) << VDDCI_SHIFT;
1047 vddci = phm_find_closest_vddci(&(data->vddci_voltage_table),
1048 (dep_table->entries[i].vddc -
1049 (uint16_t)data->vddc_vddci_delta));
1050 *voltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
1053 if (POLARIS10_VOLTAGE_CONTROL_NONE == data->mvdd_control)
1054 *mvdd = data->vbios_boot_state.mvdd_bootup_value *
1056 else if (dep_table->entries[i].mvdd)
1057 *mvdd = (uint32_t) dep_table->entries[i].mvdd *
1060 *voltage |= 1 << PHASES_SHIFT;
1065 /* sclk is bigger than max sclk in the dependence table */
1066 *voltage |= (dep_table->entries[i - 1].vddc * VOLTAGE_SCALE) << VDDC_SHIFT;
1068 if (POLARIS10_VOLTAGE_CONTROL_NONE == data->vddci_control)
1069 *voltage |= (data->vbios_boot_state.vddci_bootup_value *
1070 VOLTAGE_SCALE) << VDDCI_SHIFT;
1071 else if (dep_table->entries[i-1].vddci) {
1072 vddci = phm_find_closest_vddci(&(data->vddci_voltage_table),
1073 (dep_table->entries[i].vddc -
1074 (uint16_t)data->vddc_vddci_delta));
1075 *voltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
1078 if (POLARIS10_VOLTAGE_CONTROL_NONE == data->mvdd_control)
1079 *mvdd = data->vbios_boot_state.mvdd_bootup_value * VOLTAGE_SCALE;
1080 else if (dep_table->entries[i].mvdd)
1081 *mvdd = (uint32_t) dep_table->entries[i - 1].mvdd * VOLTAGE_SCALE;
1086 static const sclkFcwRange_t Range_Table[NUM_SCLK_RANGE] =
1087 { {VCO_2_4, POSTDIV_DIV_BY_16, 75, 160, 112},
1088 {VCO_3_6, POSTDIV_DIV_BY_16, 112, 224, 160},
1089 {VCO_2_4, POSTDIV_DIV_BY_8, 75, 160, 112},
1090 {VCO_3_6, POSTDIV_DIV_BY_8, 112, 224, 160},
1091 {VCO_2_4, POSTDIV_DIV_BY_4, 75, 160, 112},
1092 {VCO_3_6, POSTDIV_DIV_BY_4, 112, 216, 160},
1093 {VCO_2_4, POSTDIV_DIV_BY_2, 75, 160, 108},
1094 {VCO_3_6, POSTDIV_DIV_BY_2, 112, 216, 160} };
1096 static void polaris10_get_sclk_range_table(struct pp_hwmgr *hwmgr)
1098 uint32_t i, ref_clk;
1099 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1100 SMU74_Discrete_DpmTable *table = &(data->smc_state_table);
1101 struct pp_atom_ctrl_sclk_range_table range_table_from_vbios = { { {0} } };
1103 ref_clk = polaris10_get_xclk(hwmgr);
1105 if (0 == atomctrl_get_smc_sclk_range_table(hwmgr, &range_table_from_vbios)) {
1106 for (i = 0; i < NUM_SCLK_RANGE; i++) {
1107 table->SclkFcwRangeTable[i].vco_setting = range_table_from_vbios.entry[i].ucVco_setting;
1108 table->SclkFcwRangeTable[i].postdiv = range_table_from_vbios.entry[i].ucPostdiv;
1109 table->SclkFcwRangeTable[i].fcw_pcc = range_table_from_vbios.entry[i].usFcw_pcc;
1111 table->SclkFcwRangeTable[i].fcw_trans_upper = range_table_from_vbios.entry[i].usFcw_trans_upper;
1112 table->SclkFcwRangeTable[i].fcw_trans_lower = range_table_from_vbios.entry[i].usRcw_trans_lower;
1114 CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_pcc);
1115 CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_upper);
1116 CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_lower);
1121 for (i = 0; i < NUM_SCLK_RANGE; i++) {
1123 data->range_table[i].trans_lower_frequency = (ref_clk * Range_Table[i].fcw_trans_lower) >> Range_Table[i].postdiv;
1124 data->range_table[i].trans_upper_frequency = (ref_clk * Range_Table[i].fcw_trans_upper) >> Range_Table[i].postdiv;
1126 table->SclkFcwRangeTable[i].vco_setting = Range_Table[i].vco_setting;
1127 table->SclkFcwRangeTable[i].postdiv = Range_Table[i].postdiv;
1128 table->SclkFcwRangeTable[i].fcw_pcc = Range_Table[i].fcw_pcc;
1130 table->SclkFcwRangeTable[i].fcw_trans_upper = Range_Table[i].fcw_trans_upper;
1131 table->SclkFcwRangeTable[i].fcw_trans_lower = Range_Table[i].fcw_trans_lower;
1133 CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_pcc);
1134 CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_upper);
1135 CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_lower);
1140 * Populates single SMC SCLK structure using the provided engine clock
1142 * @param hwmgr the address of the hardware manager
1143 * @param clock the engine clock to use to populate the structure
1144 * @param sclk the SMC SCLK structure to be populated
1147 static int polaris10_populate_single_graphic_level(struct pp_hwmgr *hwmgr,
1148 uint32_t clock, uint16_t sclk_al_threshold,
1149 struct SMU74_Discrete_GraphicsLevel *level)
1151 int result, i, temp;
1152 /* PP_Clocks minClocks; */
1154 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1155 struct phm_ppt_v1_information *table_info =
1156 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1157 SMU_SclkSetting curr_sclk_setting = { 0 };
1159 result = polaris10_calculate_sclk_params(hwmgr, clock, &curr_sclk_setting);
1161 /* populate graphics levels */
1162 result = polaris10_get_dependency_volt_by_clk(hwmgr,
1163 table_info->vdd_dep_on_sclk, clock,
1164 &level->MinVoltage, &mvdd);
1166 PP_ASSERT_WITH_CODE((0 == result),
1167 "can not find VDDC voltage value for "
1168 "VDDC engine clock dependency table",
1170 level->ActivityLevel = sclk_al_threshold;
1172 level->CcPwrDynRm = 0;
1173 level->CcPwrDynRm1 = 0;
1174 level->EnabledForActivity = 0;
1175 level->EnabledForThrottle = 1;
1177 level->DownHyst = 0;
1178 level->VoltageDownHyst = 0;
1179 level->PowerThrottle = 0;
1182 * TODO: get minimum clocks from dal configaration
1183 * PECI_GetMinClockSettings(hwmgr->pPECI, &minClocks);
1185 /* data->DisplayTiming.minClockInSR = minClocks.engineClockInSR; */
1187 /* get level->DeepSleepDivId
1188 if (phm_cap_enabled(hwmgr->platformDescriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep))
1189 level->DeepSleepDivId = PhwFiji_GetSleepDividerIdFromClock(hwmgr, clock, minClocks.engineClockInSR);
1191 PP_ASSERT_WITH_CODE((clock >= POLARIS10_MINIMUM_ENGINE_CLOCK), "Engine clock can't satisfy stutter requirement!", return 0);
1192 for (i = POLARIS10_MAX_DEEPSLEEP_DIVIDER_ID; ; i--) {
1195 if (temp >= POLARIS10_MINIMUM_ENGINE_CLOCK || i == 0)
1199 level->DeepSleepDivId = i;
1201 /* Default to slow, highest DPM level will be
1202 * set to PPSMC_DISPLAY_WATERMARK_LOW later.
1204 if (data->update_up_hyst)
1205 level->UpHyst = (uint8_t)data->up_hyst;
1206 if (data->update_down_hyst)
1207 level->DownHyst = (uint8_t)data->down_hyst;
1209 level->SclkSetting = curr_sclk_setting;
1211 CONVERT_FROM_HOST_TO_SMC_UL(level->MinVoltage);
1212 CONVERT_FROM_HOST_TO_SMC_UL(level->CcPwrDynRm);
1213 CONVERT_FROM_HOST_TO_SMC_UL(level->CcPwrDynRm1);
1214 CONVERT_FROM_HOST_TO_SMC_US(level->ActivityLevel);
1215 CONVERT_FROM_HOST_TO_SMC_UL(level->SclkSetting.SclkFrequency);
1216 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw_int);
1217 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw_frac);
1218 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Pcc_fcw_int);
1219 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Sclk_slew_rate);
1220 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Pcc_up_slew_rate);
1221 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Pcc_down_slew_rate);
1222 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw1_int);
1223 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw1_frac);
1224 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Sclk_ss_slew_rate);
1229 * Populates all SMC SCLK levels' structure based on the trimmed allowed dpm engine clock states
1231 * @param hwmgr the address of the hardware manager
1233 static int polaris10_populate_all_graphic_levels(struct pp_hwmgr *hwmgr)
1235 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1236 struct polaris10_dpm_table *dpm_table = &data->dpm_table;
1237 struct phm_ppt_v1_information *table_info =
1238 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1239 struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table;
1240 uint8_t pcie_entry_cnt = (uint8_t) data->dpm_table.pcie_speed_table.count;
1242 uint32_t array = data->dpm_table_start +
1243 offsetof(SMU74_Discrete_DpmTable, GraphicsLevel);
1244 uint32_t array_size = sizeof(struct SMU74_Discrete_GraphicsLevel) *
1245 SMU74_MAX_LEVELS_GRAPHICS;
1246 struct SMU74_Discrete_GraphicsLevel *levels =
1247 data->smc_state_table.GraphicsLevel;
1248 uint32_t i, max_entry;
1249 uint8_t hightest_pcie_level_enabled = 0,
1250 lowest_pcie_level_enabled = 0,
1251 mid_pcie_level_enabled = 0,
1254 polaris10_get_sclk_range_table(hwmgr);
1256 for (i = 0; i < dpm_table->sclk_table.count; i++) {
1258 result = polaris10_populate_single_graphic_level(hwmgr,
1259 dpm_table->sclk_table.dpm_levels[i].value,
1260 (uint16_t)data->activity_target[i],
1261 &(data->smc_state_table.GraphicsLevel[i]));
1265 /* Making sure only DPM level 0-1 have Deep Sleep Div ID populated. */
1267 levels[i].DeepSleepDivId = 0;
1269 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1270 PHM_PlatformCaps_SPLLShutdownSupport))
1271 data->smc_state_table.GraphicsLevel[0].SclkSetting.SSc_En = 0;
1273 data->smc_state_table.GraphicsLevel[0].EnabledForActivity = 1;
1274 data->smc_state_table.GraphicsDpmLevelCount =
1275 (uint8_t)dpm_table->sclk_table.count;
1276 data->dpm_level_enable_mask.sclk_dpm_enable_mask =
1277 phm_get_dpm_level_enable_mask_value(&dpm_table->sclk_table);
1280 if (pcie_table != NULL) {
1281 PP_ASSERT_WITH_CODE((1 <= pcie_entry_cnt),
1282 "There must be 1 or more PCIE levels defined in PPTable.",
1284 max_entry = pcie_entry_cnt - 1;
1285 for (i = 0; i < dpm_table->sclk_table.count; i++)
1286 levels[i].pcieDpmLevel =
1287 (uint8_t) ((i < max_entry) ? i : max_entry);
1289 while (data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
1290 ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
1291 (1 << (hightest_pcie_level_enabled + 1))) != 0))
1292 hightest_pcie_level_enabled++;
1294 while (data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
1295 ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
1296 (1 << lowest_pcie_level_enabled)) == 0))
1297 lowest_pcie_level_enabled++;
1299 while ((count < hightest_pcie_level_enabled) &&
1300 ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
1301 (1 << (lowest_pcie_level_enabled + 1 + count))) == 0))
1304 mid_pcie_level_enabled = (lowest_pcie_level_enabled + 1 + count) <
1305 hightest_pcie_level_enabled ?
1306 (lowest_pcie_level_enabled + 1 + count) :
1307 hightest_pcie_level_enabled;
1309 /* set pcieDpmLevel to hightest_pcie_level_enabled */
1310 for (i = 2; i < dpm_table->sclk_table.count; i++)
1311 levels[i].pcieDpmLevel = hightest_pcie_level_enabled;
1313 /* set pcieDpmLevel to lowest_pcie_level_enabled */
1314 levels[0].pcieDpmLevel = lowest_pcie_level_enabled;
1316 /* set pcieDpmLevel to mid_pcie_level_enabled */
1317 levels[1].pcieDpmLevel = mid_pcie_level_enabled;
1319 /* level count will send to smc once at init smc table and never change */
1320 result = polaris10_copy_bytes_to_smc(hwmgr->smumgr, array, (uint8_t *)levels,
1321 (uint32_t)array_size, data->sram_end);
1326 static int polaris10_populate_single_memory_level(struct pp_hwmgr *hwmgr,
1327 uint32_t clock, struct SMU74_Discrete_MemoryLevel *mem_level)
1329 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1330 struct phm_ppt_v1_information *table_info =
1331 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1333 struct cgs_display_info info = {0, 0, NULL};
1335 cgs_get_active_displays_info(hwmgr->device, &info);
1337 if (table_info->vdd_dep_on_mclk) {
1338 result = polaris10_get_dependency_volt_by_clk(hwmgr,
1339 table_info->vdd_dep_on_mclk, clock,
1340 &mem_level->MinVoltage, &mem_level->MinMvdd);
1341 PP_ASSERT_WITH_CODE((0 == result),
1342 "can not find MinVddc voltage value from memory "
1343 "VDDC voltage dependency table", return result);
1346 mem_level->MclkFrequency = clock;
1347 mem_level->EnabledForThrottle = 1;
1348 mem_level->EnabledForActivity = 0;
1349 mem_level->UpHyst = 0;
1350 mem_level->DownHyst = 100;
1351 mem_level->VoltageDownHyst = 0;
1352 mem_level->ActivityLevel = (uint16_t)data->mclk_activity_target;
1353 mem_level->StutterEnable = false;
1354 mem_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
1356 data->display_timing.num_existing_displays = info.display_count;
1358 if ((data->mclk_stutter_mode_threshold) &&
1359 (clock <= data->mclk_stutter_mode_threshold) &&
1360 (PHM_READ_FIELD(hwmgr->device, DPG_PIPE_STUTTER_CONTROL,
1361 STUTTER_ENABLE) & 0x1))
1362 mem_level->StutterEnable = true;
1365 CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MinMvdd);
1366 CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MclkFrequency);
1367 CONVERT_FROM_HOST_TO_SMC_US(mem_level->ActivityLevel);
1368 CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MinVoltage);
1374 * Populates all SMC MCLK levels' structure based on the trimmed allowed dpm memory clock states
1376 * @param hwmgr the address of the hardware manager
1378 static int polaris10_populate_all_memory_levels(struct pp_hwmgr *hwmgr)
1380 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1381 struct polaris10_dpm_table *dpm_table = &data->dpm_table;
1383 /* populate MCLK dpm table to SMU7 */
1384 uint32_t array = data->dpm_table_start +
1385 offsetof(SMU74_Discrete_DpmTable, MemoryLevel);
1386 uint32_t array_size = sizeof(SMU74_Discrete_MemoryLevel) *
1387 SMU74_MAX_LEVELS_MEMORY;
1388 struct SMU74_Discrete_MemoryLevel *levels =
1389 data->smc_state_table.MemoryLevel;
1392 for (i = 0; i < dpm_table->mclk_table.count; i++) {
1393 PP_ASSERT_WITH_CODE((0 != dpm_table->mclk_table.dpm_levels[i].value),
1394 "can not populate memory level as memory clock is zero",
1396 result = polaris10_populate_single_memory_level(hwmgr,
1397 dpm_table->mclk_table.dpm_levels[i].value,
1399 if (i == dpm_table->mclk_table.count - 1) {
1400 levels[i].DisplayWatermark = PPSMC_DISPLAY_WATERMARK_HIGH;
1401 levels[i].EnabledForActivity = 1;
1407 /* In order to prevent MC activity from stutter mode to push DPM up,
1408 * the UVD change complements this by putting the MCLK in
1409 * a higher state by default such that we are not affected by
1410 * up threshold or and MCLK DPM latency.
1412 levels[0].ActivityLevel = 0x1f;
1413 CONVERT_FROM_HOST_TO_SMC_US(levels[0].ActivityLevel);
1415 data->smc_state_table.MemoryDpmLevelCount =
1416 (uint8_t)dpm_table->mclk_table.count;
1417 data->dpm_level_enable_mask.mclk_dpm_enable_mask =
1418 phm_get_dpm_level_enable_mask_value(&dpm_table->mclk_table);
1420 /* level count will send to smc once at init smc table and never change */
1421 result = polaris10_copy_bytes_to_smc(hwmgr->smumgr, array, (uint8_t *)levels,
1422 (uint32_t)array_size, data->sram_end);
1428 * Populates the SMC MVDD structure using the provided memory clock.
1430 * @param hwmgr the address of the hardware manager
1431 * @param mclk the MCLK value to be used in the decision if MVDD should be high or low.
1432 * @param voltage the SMC VOLTAGE structure to be populated
1434 int polaris10_populate_mvdd_value(struct pp_hwmgr *hwmgr,
1435 uint32_t mclk, SMIO_Pattern *smio_pat)
1437 const struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1438 struct phm_ppt_v1_information *table_info =
1439 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1442 if (POLARIS10_VOLTAGE_CONTROL_NONE != data->mvdd_control) {
1443 /* find mvdd value which clock is more than request */
1444 for (i = 0; i < table_info->vdd_dep_on_mclk->count; i++) {
1445 if (mclk <= table_info->vdd_dep_on_mclk->entries[i].clk) {
1446 smio_pat->Voltage = data->mvdd_voltage_table.entries[i].value;
1450 PP_ASSERT_WITH_CODE(i < table_info->vdd_dep_on_mclk->count,
1451 "MVDD Voltage is outside the supported range.",
1459 static int polaris10_populate_smc_acpi_level(struct pp_hwmgr *hwmgr,
1460 SMU74_Discrete_DpmTable *table)
1463 uint32_t sclk_frequency;
1464 const struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1465 struct phm_ppt_v1_information *table_info =
1466 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1467 SMIO_Pattern vol_level;
1471 table->ACPILevel.Flags &= ~PPSMC_SWSTATE_FLAG_DC;
1474 /* Get MinVoltage and Frequency from DPM0,
1475 * already converted to SMC_UL */
1476 sclk_frequency = data->dpm_table.sclk_table.dpm_levels[0].value;
1477 result = polaris10_get_dependency_volt_by_clk(hwmgr,
1478 table_info->vdd_dep_on_sclk,
1480 &table->ACPILevel.MinVoltage, &mvdd);
1481 PP_ASSERT_WITH_CODE((0 == result),
1482 "Cannot find ACPI VDDC voltage value "
1483 "in Clock Dependency Table",
1487 result = polaris10_calculate_sclk_params(hwmgr, sclk_frequency, &(table->ACPILevel.SclkSetting));
1488 PP_ASSERT_WITH_CODE(result == 0, "Error retrieving Engine Clock dividers from VBIOS.", return result);
1490 table->ACPILevel.DeepSleepDivId = 0;
1491 table->ACPILevel.CcPwrDynRm = 0;
1492 table->ACPILevel.CcPwrDynRm1 = 0;
1494 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.Flags);
1495 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.MinVoltage);
1496 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm);
1497 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm1);
1499 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SclkSetting.SclkFrequency);
1500 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw_int);
1501 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw_frac);
1502 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Pcc_fcw_int);
1503 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Sclk_slew_rate);
1504 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Pcc_up_slew_rate);
1505 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Pcc_down_slew_rate);
1506 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw1_int);
1507 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw1_frac);
1508 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Sclk_ss_slew_rate);
1511 /* Get MinVoltage and Frequency from DPM0, already converted to SMC_UL */
1512 table->MemoryACPILevel.MclkFrequency =
1513 data->dpm_table.mclk_table.dpm_levels[0].value;
1514 result = polaris10_get_dependency_volt_by_clk(hwmgr,
1515 table_info->vdd_dep_on_mclk,
1516 table->MemoryACPILevel.MclkFrequency,
1517 &table->MemoryACPILevel.MinVoltage, &mvdd);
1518 PP_ASSERT_WITH_CODE((0 == result),
1519 "Cannot find ACPI VDDCI voltage value "
1520 "in Clock Dependency Table",
1524 if ((POLARIS10_VOLTAGE_CONTROL_NONE == data->mvdd_control) ||
1525 (data->mclk_dpm_key_disabled))
1526 us_mvdd = data->vbios_boot_state.mvdd_bootup_value;
1528 if (!polaris10_populate_mvdd_value(hwmgr,
1529 data->dpm_table.mclk_table.dpm_levels[0].value,
1531 us_mvdd = vol_level.Voltage;
1534 if (0 == polaris10_populate_mvdd_value(hwmgr, 0, &vol_level))
1535 table->MemoryACPILevel.MinMvdd = PP_HOST_TO_SMC_UL(vol_level.Voltage);
1537 table->MemoryACPILevel.MinMvdd = 0;
1539 table->MemoryACPILevel.StutterEnable = false;
1541 table->MemoryACPILevel.EnabledForThrottle = 0;
1542 table->MemoryACPILevel.EnabledForActivity = 0;
1543 table->MemoryACPILevel.UpHyst = 0;
1544 table->MemoryACPILevel.DownHyst = 100;
1545 table->MemoryACPILevel.VoltageDownHyst = 0;
1546 table->MemoryACPILevel.ActivityLevel =
1547 PP_HOST_TO_SMC_US((uint16_t)data->mclk_activity_target);
1549 CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MclkFrequency);
1550 CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MinVoltage);
1555 static int polaris10_populate_smc_vce_level(struct pp_hwmgr *hwmgr,
1556 SMU74_Discrete_DpmTable *table)
1558 int result = -EINVAL;
1560 struct pp_atomctrl_clock_dividers_vi dividers;
1561 struct phm_ppt_v1_information *table_info =
1562 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1563 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
1564 table_info->mm_dep_table;
1565 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1568 table->VceLevelCount = (uint8_t)(mm_table->count);
1569 table->VceBootLevel = 0;
1571 for (count = 0; count < table->VceLevelCount; count++) {
1572 table->VceLevel[count].Frequency = mm_table->entries[count].eclk;
1573 table->VceLevel[count].MinVoltage = 0;
1574 table->VceLevel[count].MinVoltage |=
1575 (mm_table->entries[count].vddc * VOLTAGE_SCALE) << VDDC_SHIFT;
1577 if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control)
1578 vddci = (uint32_t)phm_find_closest_vddci(&(data->vddci_voltage_table),
1579 mm_table->entries[count].vddc - VDDC_VDDCI_DELTA);
1580 else if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control)
1581 vddci = mm_table->entries[count].vddc - VDDC_VDDCI_DELTA;
1583 vddci = (data->vbios_boot_state.vddci_bootup_value * VOLTAGE_SCALE) << VDDCI_SHIFT;
1586 table->VceLevel[count].MinVoltage |=
1587 (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
1588 table->VceLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
1590 /*retrieve divider value for VBIOS */
1591 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
1592 table->VceLevel[count].Frequency, ÷rs);
1593 PP_ASSERT_WITH_CODE((0 == result),
1594 "can not find divide id for VCE engine clock",
1597 table->VceLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
1599 CONVERT_FROM_HOST_TO_SMC_UL(table->VceLevel[count].Frequency);
1600 CONVERT_FROM_HOST_TO_SMC_UL(table->VceLevel[count].MinVoltage);
1605 static int polaris10_populate_smc_samu_level(struct pp_hwmgr *hwmgr,
1606 SMU74_Discrete_DpmTable *table)
1608 int result = -EINVAL;
1610 struct pp_atomctrl_clock_dividers_vi dividers;
1611 struct phm_ppt_v1_information *table_info =
1612 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1613 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
1614 table_info->mm_dep_table;
1615 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1618 table->SamuBootLevel = 0;
1619 table->SamuLevelCount = (uint8_t)(mm_table->count);
1621 for (count = 0; count < table->SamuLevelCount; count++) {
1622 /* not sure whether we need evclk or not */
1623 table->SamuLevel[count].MinVoltage = 0;
1624 table->SamuLevel[count].Frequency = mm_table->entries[count].samclock;
1625 table->SamuLevel[count].MinVoltage |= (mm_table->entries[count].vddc *
1626 VOLTAGE_SCALE) << VDDC_SHIFT;
1628 if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control)
1629 vddci = (uint32_t)phm_find_closest_vddci(&(data->vddci_voltage_table),
1630 mm_table->entries[count].vddc - VDDC_VDDCI_DELTA);
1631 else if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control)
1632 vddci = mm_table->entries[count].vddc - VDDC_VDDCI_DELTA;
1634 vddci = (data->vbios_boot_state.vddci_bootup_value * VOLTAGE_SCALE) << VDDCI_SHIFT;
1636 table->SamuLevel[count].MinVoltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
1637 table->SamuLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
1639 /* retrieve divider value for VBIOS */
1640 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
1641 table->SamuLevel[count].Frequency, ÷rs);
1642 PP_ASSERT_WITH_CODE((0 == result),
1643 "can not find divide id for samu clock", return result);
1645 table->SamuLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
1647 CONVERT_FROM_HOST_TO_SMC_UL(table->SamuLevel[count].Frequency);
1648 CONVERT_FROM_HOST_TO_SMC_UL(table->SamuLevel[count].MinVoltage);
1653 static int polaris10_populate_memory_timing_parameters(struct pp_hwmgr *hwmgr,
1654 int32_t eng_clock, int32_t mem_clock,
1655 SMU74_Discrete_MCArbDramTimingTableEntry *arb_regs)
1657 uint32_t dram_timing;
1658 uint32_t dram_timing2;
1659 uint32_t burst_time;
1662 result = atomctrl_set_engine_dram_timings_rv770(hwmgr,
1663 eng_clock, mem_clock);
1664 PP_ASSERT_WITH_CODE(result == 0,
1665 "Error calling VBIOS to set DRAM_TIMING.", return result);
1667 dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
1668 dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
1669 burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0);
1672 arb_regs->McArbDramTiming = PP_HOST_TO_SMC_UL(dram_timing);
1673 arb_regs->McArbDramTiming2 = PP_HOST_TO_SMC_UL(dram_timing2);
1674 arb_regs->McArbBurstTime = (uint8_t)burst_time;
1679 static int polaris10_program_memory_timing_parameters(struct pp_hwmgr *hwmgr)
1681 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1682 struct SMU74_Discrete_MCArbDramTimingTable arb_regs;
1686 for (i = 0; i < data->dpm_table.sclk_table.count; i++) {
1687 for (j = 0; j < data->dpm_table.mclk_table.count; j++) {
1688 result = polaris10_populate_memory_timing_parameters(hwmgr,
1689 data->dpm_table.sclk_table.dpm_levels[i].value,
1690 data->dpm_table.mclk_table.dpm_levels[j].value,
1691 &arb_regs.entries[i][j]);
1693 result = atomctrl_set_ac_timing_ai(hwmgr, data->dpm_table.mclk_table.dpm_levels[j].value, j);
1699 result = polaris10_copy_bytes_to_smc(
1701 data->arb_table_start,
1702 (uint8_t *)&arb_regs,
1703 sizeof(SMU74_Discrete_MCArbDramTimingTable),
1708 static int polaris10_populate_smc_uvd_level(struct pp_hwmgr *hwmgr,
1709 struct SMU74_Discrete_DpmTable *table)
1711 int result = -EINVAL;
1713 struct pp_atomctrl_clock_dividers_vi dividers;
1714 struct phm_ppt_v1_information *table_info =
1715 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1716 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
1717 table_info->mm_dep_table;
1718 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1721 table->UvdLevelCount = (uint8_t)(mm_table->count);
1722 table->UvdBootLevel = 0;
1724 for (count = 0; count < table->UvdLevelCount; count++) {
1725 table->UvdLevel[count].MinVoltage = 0;
1726 table->UvdLevel[count].VclkFrequency = mm_table->entries[count].vclk;
1727 table->UvdLevel[count].DclkFrequency = mm_table->entries[count].dclk;
1728 table->UvdLevel[count].MinVoltage |= (mm_table->entries[count].vddc *
1729 VOLTAGE_SCALE) << VDDC_SHIFT;
1731 if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control)
1732 vddci = (uint32_t)phm_find_closest_vddci(&(data->vddci_voltage_table),
1733 mm_table->entries[count].vddc - VDDC_VDDCI_DELTA);
1734 else if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control)
1735 vddci = mm_table->entries[count].vddc - VDDC_VDDCI_DELTA;
1737 vddci = (data->vbios_boot_state.vddci_bootup_value * VOLTAGE_SCALE) << VDDCI_SHIFT;
1739 table->UvdLevel[count].MinVoltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
1740 table->UvdLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
1742 /* retrieve divider value for VBIOS */
1743 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
1744 table->UvdLevel[count].VclkFrequency, ÷rs);
1745 PP_ASSERT_WITH_CODE((0 == result),
1746 "can not find divide id for Vclk clock", return result);
1748 table->UvdLevel[count].VclkDivider = (uint8_t)dividers.pll_post_divider;
1750 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
1751 table->UvdLevel[count].DclkFrequency, ÷rs);
1752 PP_ASSERT_WITH_CODE((0 == result),
1753 "can not find divide id for Dclk clock", return result);
1755 table->UvdLevel[count].DclkDivider = (uint8_t)dividers.pll_post_divider;
1757 CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].VclkFrequency);
1758 CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].DclkFrequency);
1759 CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].MinVoltage);
1765 static int polaris10_populate_smc_boot_level(struct pp_hwmgr *hwmgr,
1766 struct SMU74_Discrete_DpmTable *table)
1769 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1771 table->GraphicsBootLevel = 0;
1772 table->MemoryBootLevel = 0;
1774 /* find boot level from dpm table */
1775 result = phm_find_boot_level(&(data->dpm_table.sclk_table),
1776 data->vbios_boot_state.sclk_bootup_value,
1777 (uint32_t *)&(table->GraphicsBootLevel));
1779 result = phm_find_boot_level(&(data->dpm_table.mclk_table),
1780 data->vbios_boot_state.mclk_bootup_value,
1781 (uint32_t *)&(table->MemoryBootLevel));
1783 table->BootVddc = data->vbios_boot_state.vddc_bootup_value *
1785 table->BootVddci = data->vbios_boot_state.vddci_bootup_value *
1787 table->BootMVdd = data->vbios_boot_state.mvdd_bootup_value *
1790 CONVERT_FROM_HOST_TO_SMC_US(table->BootVddc);
1791 CONVERT_FROM_HOST_TO_SMC_US(table->BootVddci);
1792 CONVERT_FROM_HOST_TO_SMC_US(table->BootMVdd);
1798 static int polaris10_populate_smc_initailial_state(struct pp_hwmgr *hwmgr)
1800 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1801 struct phm_ppt_v1_information *table_info =
1802 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1803 uint8_t count, level;
1805 count = (uint8_t)(table_info->vdd_dep_on_sclk->count);
1807 for (level = 0; level < count; level++) {
1808 if (table_info->vdd_dep_on_sclk->entries[level].clk >=
1809 data->vbios_boot_state.sclk_bootup_value) {
1810 data->smc_state_table.GraphicsBootLevel = level;
1815 count = (uint8_t)(table_info->vdd_dep_on_mclk->count);
1816 for (level = 0; level < count; level++) {
1817 if (table_info->vdd_dep_on_mclk->entries[level].clk >=
1818 data->vbios_boot_state.mclk_bootup_value) {
1819 data->smc_state_table.MemoryBootLevel = level;
1827 static int polaris10_populate_clock_stretcher_data_table(struct pp_hwmgr *hwmgr)
1829 uint32_t ro, efuse, volt_without_cks, volt_with_cks, value, max, min;
1830 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1831 uint8_t i, stretch_amount, volt_offset = 0;
1832 struct phm_ppt_v1_information *table_info =
1833 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1834 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
1835 table_info->vdd_dep_on_sclk;
1837 stretch_amount = (uint8_t)table_info->cac_dtp_table->usClockStretchAmount;
1839 /* Read SMU_Eefuse to read and calculate RO and determine
1840 * if the part is SS or FF. if RO >= 1660MHz, part is FF.
1842 efuse = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1843 ixSMU_EFUSE_0 + (67 * 4));
1844 efuse &= 0xFF000000;
1845 efuse = efuse >> 24;
1847 if (hwmgr->chip_id == CHIP_POLARIS10) {
1855 ro = efuse * (max -min)/255 + min;
1857 /* Populate Sclk_CKS_masterEn0_7 and Sclk_voltageOffset */
1858 for (i = 0; i < sclk_table->count; i++) {
1859 data->smc_state_table.Sclk_CKS_masterEn0_7 |=
1860 sclk_table->entries[i].cks_enable << i;
1861 if (hwmgr->chip_id == CHIP_POLARIS10) {
1862 volt_without_cks = (uint32_t)((2753594000U + (sclk_table->entries[i].clk/100) * 136418 -(ro - 70) * 1000000) / \
1863 (2424180 - (sclk_table->entries[i].clk/100) * 1132925/1000));
1864 volt_with_cks = (uint32_t)((2797202000U + sclk_table->entries[i].clk/100 * 3232 - (ro - 65) * 1000000) / \
1865 (2522480 - sclk_table->entries[i].clk/100 * 115764/100));
1867 volt_without_cks = (uint32_t)((2416794800U + (sclk_table->entries[i].clk/100) * 1476925/10 -(ro - 50) * 1000000) / \
1868 (2625416 - (sclk_table->entries[i].clk/100) * (12586807/10000)));
1869 volt_with_cks = (uint32_t)((2999656000U - sclk_table->entries[i].clk/100 * 392803 - (ro - 44) * 1000000) / \
1870 (3422454 - sclk_table->entries[i].clk/100 * (18886376/10000)));
1873 if (volt_without_cks >= volt_with_cks)
1874 volt_offset = (uint8_t)(((volt_without_cks - volt_with_cks +
1875 sclk_table->entries[i].cks_voffset) * 100 + 624) / 625);
1877 data->smc_state_table.Sclk_voltageOffset[i] = volt_offset;
1880 data->smc_state_table.LdoRefSel = (table_info->cac_dtp_table->ucCKS_LDO_REFSEL != 0) ? table_info->cac_dtp_table->ucCKS_LDO_REFSEL : 6;
1881 /* Populate CKS Lookup Table */
1882 if (stretch_amount != 1 && stretch_amount != 2 && stretch_amount != 3 &&
1883 stretch_amount != 4 && stretch_amount != 5) {
1884 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1885 PHM_PlatformCaps_ClockStretcher);
1886 PP_ASSERT_WITH_CODE(false,
1887 "Stretch Amount in PPTable not supported\n",
1891 value = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixPWR_CKS_CNTL);
1892 value &= 0xFFFFFFFE;
1893 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixPWR_CKS_CNTL, value);
1899 * Populates the SMC VRConfig field in DPM table.
1901 * @param hwmgr the address of the hardware manager
1902 * @param table the SMC DPM table structure to be populated
1905 static int polaris10_populate_vr_config(struct pp_hwmgr *hwmgr,
1906 struct SMU74_Discrete_DpmTable *table)
1908 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1911 config = VR_MERGED_WITH_VDDC;
1912 table->VRConfig |= (config << VRCONF_VDDGFX_SHIFT);
1914 /* Set Vddc Voltage Controller */
1915 if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
1916 config = VR_SVI2_PLANE_1;
1917 table->VRConfig |= config;
1919 PP_ASSERT_WITH_CODE(false,
1920 "VDDC should be on SVI2 control in merged mode!",
1923 /* Set Vddci Voltage Controller */
1924 if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) {
1925 config = VR_SVI2_PLANE_2; /* only in merged mode */
1926 table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
1927 } else if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
1928 config = VR_SMIO_PATTERN_1;
1929 table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
1931 config = VR_STATIC_VOLTAGE;
1932 table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
1934 /* Set Mvdd Voltage Controller */
1935 if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) {
1936 config = VR_SVI2_PLANE_2;
1937 table->VRConfig |= (config << VRCONF_MVDD_SHIFT);
1938 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, data->soft_regs_start +
1939 offsetof(SMU74_SoftRegisters, AllowMvddSwitch), 0x1);
1941 config = VR_STATIC_VOLTAGE;
1942 table->VRConfig |= (config << VRCONF_MVDD_SHIFT);
1949 int polaris10_populate_avfs_parameters(struct pp_hwmgr *hwmgr)
1951 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1952 SMU74_Discrete_DpmTable *table = &(data->smc_state_table);
1954 struct pp_atom_ctrl__avfs_parameters avfs_params = {0};
1955 AVFS_meanNsigma_t AVFS_meanNsigma = { {0} };
1956 AVFS_Sclk_Offset_t AVFS_SclkOffset = { {0} };
1958 struct pp_smumgr *smumgr = hwmgr->smumgr;
1959 struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(smumgr->backend);
1961 struct phm_ppt_v1_information *table_info =
1962 (struct phm_ppt_v1_information *)hwmgr->pptable;
1963 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
1964 table_info->vdd_dep_on_sclk;
1967 if (smu_data->avfs.avfs_btc_status == AVFS_BTC_NOTSUPPORTED)
1970 result = atomctrl_get_avfs_information(hwmgr, &avfs_params);
1973 table->BTCGB_VDROOP_TABLE[0].a0 = PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSON_a0);
1974 table->BTCGB_VDROOP_TABLE[0].a1 = PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSON_a1);
1975 table->BTCGB_VDROOP_TABLE[0].a2 = PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSON_a2);
1976 table->BTCGB_VDROOP_TABLE[1].a0 = PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSOFF_a0);
1977 table->BTCGB_VDROOP_TABLE[1].a1 = PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSOFF_a1);
1978 table->BTCGB_VDROOP_TABLE[1].a2 = PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSOFF_a2);
1979 table->AVFSGB_VDROOP_TABLE[0].m1 = PP_HOST_TO_SMC_UL(avfs_params.ulAVFSGB_FUSE_TABLE_CKSON_m1);
1980 table->AVFSGB_VDROOP_TABLE[0].m2 = PP_HOST_TO_SMC_US(avfs_params.usAVFSGB_FUSE_TABLE_CKSON_m2);
1981 table->AVFSGB_VDROOP_TABLE[0].b = PP_HOST_TO_SMC_UL(avfs_params.ulAVFSGB_FUSE_TABLE_CKSON_b);
1982 table->AVFSGB_VDROOP_TABLE[0].m1_shift = 24;
1983 table->AVFSGB_VDROOP_TABLE[0].m2_shift = 12;
1984 table->AVFSGB_VDROOP_TABLE[1].m1 = PP_HOST_TO_SMC_UL(avfs_params.ulAVFSGB_FUSE_TABLE_CKSOFF_m1);
1985 table->AVFSGB_VDROOP_TABLE[1].m2 = PP_HOST_TO_SMC_US(avfs_params.usAVFSGB_FUSE_TABLE_CKSOFF_m2);
1986 table->AVFSGB_VDROOP_TABLE[1].b = PP_HOST_TO_SMC_UL(avfs_params.ulAVFSGB_FUSE_TABLE_CKSOFF_b);
1987 table->AVFSGB_VDROOP_TABLE[1].m1_shift = 24;
1988 table->AVFSGB_VDROOP_TABLE[1].m2_shift = 12;
1989 table->MaxVoltage = PP_HOST_TO_SMC_US(avfs_params.usMaxVoltage_0_25mv);
1990 AVFS_meanNsigma.Aconstant[0] = PP_HOST_TO_SMC_UL(avfs_params.ulAVFS_meanNsigma_Acontant0);
1991 AVFS_meanNsigma.Aconstant[1] = PP_HOST_TO_SMC_UL(avfs_params.ulAVFS_meanNsigma_Acontant1);
1992 AVFS_meanNsigma.Aconstant[2] = PP_HOST_TO_SMC_UL(avfs_params.ulAVFS_meanNsigma_Acontant2);
1993 AVFS_meanNsigma.DC_tol_sigma = PP_HOST_TO_SMC_US(avfs_params.usAVFS_meanNsigma_DC_tol_sigma);
1994 AVFS_meanNsigma.Platform_mean = PP_HOST_TO_SMC_US(avfs_params.usAVFS_meanNsigma_Platform_mean);
1995 AVFS_meanNsigma.PSM_Age_CompFactor = PP_HOST_TO_SMC_US(avfs_params.usPSM_Age_ComFactor);
1996 AVFS_meanNsigma.Platform_sigma = PP_HOST_TO_SMC_US(avfs_params.usAVFS_meanNsigma_Platform_sigma);
1998 for (i = 0; i < NUM_VFT_COLUMNS; i++) {
1999 AVFS_meanNsigma.Static_Voltage_Offset[i] = (uint8_t)(sclk_table->entries[i].cks_voffset * 100 / 625);
2000 AVFS_SclkOffset.Sclk_Offset[i] = PP_HOST_TO_SMC_US((uint16_t)(sclk_table->entries[i].sclk_offset) / 100);
2003 result = polaris10_read_smc_sram_dword(smumgr,
2004 SMU7_FIRMWARE_HEADER_LOCATION + offsetof(SMU74_Firmware_Header, AvfsMeanNSigma),
2005 &tmp, data->sram_end);
2007 polaris10_copy_bytes_to_smc(smumgr,
2009 (uint8_t *)&AVFS_meanNsigma,
2010 sizeof(AVFS_meanNsigma_t),
2013 result = polaris10_read_smc_sram_dword(smumgr,
2014 SMU7_FIRMWARE_HEADER_LOCATION + offsetof(SMU74_Firmware_Header, AvfsSclkOffsetTable),
2015 &tmp, data->sram_end);
2016 polaris10_copy_bytes_to_smc(smumgr,
2018 (uint8_t *)&AVFS_SclkOffset,
2019 sizeof(AVFS_Sclk_Offset_t),
2022 data->avfs_vdroop_override_setting = (avfs_params.ucEnableGB_VDROOP_TABLE_CKSON << BTCGB0_Vdroop_Enable_SHIFT) |
2023 (avfs_params.ucEnableGB_VDROOP_TABLE_CKSOFF << BTCGB1_Vdroop_Enable_SHIFT) |
2024 (avfs_params.ucEnableGB_FUSE_TABLE_CKSON << AVFSGB0_Vdroop_Enable_SHIFT) |
2025 (avfs_params.ucEnableGB_FUSE_TABLE_CKSOFF << AVFSGB1_Vdroop_Enable_SHIFT);
2026 data->apply_avfs_cks_off_voltage = (avfs_params.ucEnableApplyAVFS_CKS_OFF_Voltage == 1) ? true : false;
2033 * Initializes the SMC table and uploads it
2035 * @param hwmgr the address of the powerplay hardware manager.
2038 static int polaris10_init_smc_table(struct pp_hwmgr *hwmgr)
2041 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2042 struct phm_ppt_v1_information *table_info =
2043 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2044 struct SMU74_Discrete_DpmTable *table = &(data->smc_state_table);
2045 const struct polaris10_ulv_parm *ulv = &(data->ulv);
2047 struct pp_atomctrl_gpio_pin_assignment gpio_pin;
2048 pp_atomctrl_clock_dividers_vi dividers;
2050 result = polaris10_setup_default_dpm_tables(hwmgr);
2051 PP_ASSERT_WITH_CODE(0 == result,
2052 "Failed to setup default DPM tables!", return result);
2054 if (POLARIS10_VOLTAGE_CONTROL_NONE != data->voltage_control)
2055 polaris10_populate_smc_voltage_tables(hwmgr, table);
2057 table->SystemFlags = 0;
2058 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2059 PHM_PlatformCaps_AutomaticDCTransition))
2060 table->SystemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC;
2062 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2063 PHM_PlatformCaps_StepVddc))
2064 table->SystemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC;
2066 if (data->is_memory_gddr5)
2067 table->SystemFlags |= PPSMC_SYSTEMFLAG_GDDR5;
2069 if (ulv->ulv_supported && table_info->us_ulv_voltage_offset) {
2070 result = polaris10_populate_ulv_state(hwmgr, table);
2071 PP_ASSERT_WITH_CODE(0 == result,
2072 "Failed to initialize ULV state!", return result);
2073 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2074 ixCG_ULV_PARAMETER, PPPOLARIS10_CGULVPARAMETER_DFLT);
2077 result = polaris10_populate_smc_link_level(hwmgr, table);
2078 PP_ASSERT_WITH_CODE(0 == result,
2079 "Failed to initialize Link Level!", return result);
2081 result = polaris10_populate_all_graphic_levels(hwmgr);
2082 PP_ASSERT_WITH_CODE(0 == result,
2083 "Failed to initialize Graphics Level!", return result);
2085 result = polaris10_populate_all_memory_levels(hwmgr);
2086 PP_ASSERT_WITH_CODE(0 == result,
2087 "Failed to initialize Memory Level!", return result);
2089 result = polaris10_populate_smc_acpi_level(hwmgr, table);
2090 PP_ASSERT_WITH_CODE(0 == result,
2091 "Failed to initialize ACPI Level!", return result);
2093 result = polaris10_populate_smc_vce_level(hwmgr, table);
2094 PP_ASSERT_WITH_CODE(0 == result,
2095 "Failed to initialize VCE Level!", return result);
2097 result = polaris10_populate_smc_samu_level(hwmgr, table);
2098 PP_ASSERT_WITH_CODE(0 == result,
2099 "Failed to initialize SAMU Level!", return result);
2101 /* Since only the initial state is completely set up at this point
2102 * (the other states are just copies of the boot state) we only
2103 * need to populate the ARB settings for the initial state.
2105 result = polaris10_program_memory_timing_parameters(hwmgr);
2106 PP_ASSERT_WITH_CODE(0 == result,
2107 "Failed to Write ARB settings for the initial state.", return result);
2109 result = polaris10_populate_smc_uvd_level(hwmgr, table);
2110 PP_ASSERT_WITH_CODE(0 == result,
2111 "Failed to initialize UVD Level!", return result);
2113 result = polaris10_populate_smc_boot_level(hwmgr, table);
2114 PP_ASSERT_WITH_CODE(0 == result,
2115 "Failed to initialize Boot Level!", return result);
2117 result = polaris10_populate_smc_initailial_state(hwmgr);
2118 PP_ASSERT_WITH_CODE(0 == result,
2119 "Failed to initialize Boot State!", return result);
2121 result = polaris10_populate_bapm_parameters_in_dpm_table(hwmgr);
2122 PP_ASSERT_WITH_CODE(0 == result,
2123 "Failed to populate BAPM Parameters!", return result);
2125 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2126 PHM_PlatformCaps_ClockStretcher)) {
2127 result = polaris10_populate_clock_stretcher_data_table(hwmgr);
2128 PP_ASSERT_WITH_CODE(0 == result,
2129 "Failed to populate Clock Stretcher Data Table!",
2133 result = polaris10_populate_avfs_parameters(hwmgr);
2134 PP_ASSERT_WITH_CODE(0 == result, "Failed to populate AVFS Parameters!", return result;);
2136 table->CurrSclkPllRange = 0xff;
2137 table->GraphicsVoltageChangeEnable = 1;
2138 table->GraphicsThermThrottleEnable = 1;
2139 table->GraphicsInterval = 1;
2140 table->VoltageInterval = 1;
2141 table->ThermalInterval = 1;
2142 table->TemperatureLimitHigh =
2143 table_info->cac_dtp_table->usTargetOperatingTemp *
2144 POLARIS10_Q88_FORMAT_CONVERSION_UNIT;
2145 table->TemperatureLimitLow =
2146 (table_info->cac_dtp_table->usTargetOperatingTemp - 1) *
2147 POLARIS10_Q88_FORMAT_CONVERSION_UNIT;
2148 table->MemoryVoltageChangeEnable = 1;
2149 table->MemoryInterval = 1;
2150 table->VoltageResponseTime = 0;
2151 table->PhaseResponseTime = 0;
2152 table->MemoryThermThrottleEnable = 1;
2153 table->PCIeBootLinkLevel = 0;
2154 table->PCIeGenInterval = 1;
2155 table->VRConfig = 0;
2157 result = polaris10_populate_vr_config(hwmgr, table);
2158 PP_ASSERT_WITH_CODE(0 == result,
2159 "Failed to populate VRConfig setting!", return result);
2161 table->ThermGpio = 17;
2162 table->SclkStepSize = 0x4000;
2164 if (atomctrl_get_pp_assign_pin(hwmgr, VDDC_VRHOT_GPIO_PINID, &gpio_pin)) {
2165 table->VRHotGpio = gpio_pin.uc_gpio_pin_bit_shift;
2167 table->VRHotGpio = POLARIS10_UNUSED_GPIO_PIN;
2168 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2169 PHM_PlatformCaps_RegulatorHot);
2172 if (atomctrl_get_pp_assign_pin(hwmgr, PP_AC_DC_SWITCH_GPIO_PINID,
2174 table->AcDcGpio = gpio_pin.uc_gpio_pin_bit_shift;
2175 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2176 PHM_PlatformCaps_AutomaticDCTransition);
2178 table->AcDcGpio = POLARIS10_UNUSED_GPIO_PIN;
2179 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2180 PHM_PlatformCaps_AutomaticDCTransition);
2183 /* Thermal Output GPIO */
2184 if (atomctrl_get_pp_assign_pin(hwmgr, THERMAL_INT_OUTPUT_GPIO_PINID,
2186 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2187 PHM_PlatformCaps_ThermalOutGPIO);
2189 table->ThermOutGpio = gpio_pin.uc_gpio_pin_bit_shift;
2191 /* For porlarity read GPIOPAD_A with assigned Gpio pin
2192 * since VBIOS will program this register to set 'inactive state',
2193 * driver can then determine 'active state' from this and
2194 * program SMU with correct polarity
2196 table->ThermOutPolarity = (0 == (cgs_read_register(hwmgr->device, mmGPIOPAD_A)
2197 & (1 << gpio_pin.uc_gpio_pin_bit_shift))) ? 1:0;
2198 table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_ONLY;
2200 /* if required, combine VRHot/PCC with thermal out GPIO */
2201 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_RegulatorHot)
2202 && phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_CombinePCCWithThermalSignal))
2203 table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_VRHOT;
2205 table->ThermOutGpio = 17;
2206 table->ThermOutPolarity = 1;
2207 table->ThermOutMode = SMU7_THERM_OUT_MODE_DISABLE;
2210 /* Populate BIF_SCLK levels into SMC DPM table */
2211 for (i = 0; i <= data->dpm_table.pcie_speed_table.count; i++) {
2212 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr, data->bif_sclk_table[i], ÷rs);
2213 PP_ASSERT_WITH_CODE((result == 0), "Can not find DFS divide id for Sclk", return result);
2216 table->Ulv.BifSclkDfs = PP_HOST_TO_SMC_US((USHORT)(dividers.pll_post_divider));
2218 table->LinkLevel[i-1].BifSclkDfs = PP_HOST_TO_SMC_US((USHORT)(dividers.pll_post_divider));
2221 for (i = 0; i < SMU74_MAX_ENTRIES_SMIO; i++)
2222 table->Smio[i] = PP_HOST_TO_SMC_UL(table->Smio[i]);
2224 CONVERT_FROM_HOST_TO_SMC_UL(table->SystemFlags);
2225 CONVERT_FROM_HOST_TO_SMC_UL(table->VRConfig);
2226 CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask1);
2227 CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask2);
2228 CONVERT_FROM_HOST_TO_SMC_UL(table->SclkStepSize);
2229 CONVERT_FROM_HOST_TO_SMC_UL(table->CurrSclkPllRange);
2230 CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitHigh);
2231 CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitLow);
2232 CONVERT_FROM_HOST_TO_SMC_US(table->VoltageResponseTime);
2233 CONVERT_FROM_HOST_TO_SMC_US(table->PhaseResponseTime);
2235 /* Upload all dpm data to SMC memory.(dpm level, dpm level count etc) */
2236 result = polaris10_copy_bytes_to_smc(hwmgr->smumgr,
2237 data->dpm_table_start +
2238 offsetof(SMU74_Discrete_DpmTable, SystemFlags),
2239 (uint8_t *)&(table->SystemFlags),
2240 sizeof(SMU74_Discrete_DpmTable) - 3 * sizeof(SMU74_PIDController),
2242 PP_ASSERT_WITH_CODE(0 == result,
2243 "Failed to upload dpm data to SMC memory!", return result);
2249 * Initialize the ARB DRAM timing table's index field.
2251 * @param hwmgr the address of the powerplay hardware manager.
2254 static int polaris10_init_arb_table_index(struct pp_hwmgr *hwmgr)
2256 const struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2260 /* This is a read-modify-write on the first byte of the ARB table.
2261 * The first byte in the SMU73_Discrete_MCArbDramTimingTable structure
2262 * is the field 'current'.
2263 * This solution is ugly, but we never write the whole table only
2264 * individual fields in it.
2265 * In reality this field should not be in that structure
2266 * but in a soft register.
2268 result = polaris10_read_smc_sram_dword(hwmgr->smumgr,
2269 data->arb_table_start, &tmp, data->sram_end);
2275 tmp |= ((uint32_t)MC_CG_ARB_FREQ_F1) << 24;
2277 return polaris10_write_smc_sram_dword(hwmgr->smumgr,
2278 data->arb_table_start, tmp, data->sram_end);
2281 static int polaris10_enable_vrhot_gpio_interrupt(struct pp_hwmgr *hwmgr)
2283 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2284 PHM_PlatformCaps_RegulatorHot))
2285 return smum_send_msg_to_smc(hwmgr->smumgr,
2286 PPSMC_MSG_EnableVRHotGPIOInterrupt);
2291 static int polaris10_enable_sclk_control(struct pp_hwmgr *hwmgr)
2293 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
2294 SCLK_PWRMGT_OFF, 0);
2298 static int polaris10_enable_ulv(struct pp_hwmgr *hwmgr)
2300 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2301 struct polaris10_ulv_parm *ulv = &(data->ulv);
2303 if (ulv->ulv_supported)
2304 return smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_EnableULV);
2309 static int polaris10_disable_ulv(struct pp_hwmgr *hwmgr)
2311 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2312 struct polaris10_ulv_parm *ulv = &(data->ulv);
2314 if (ulv->ulv_supported)
2315 return smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_DisableULV);
2320 static int polaris10_enable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
2322 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2323 PHM_PlatformCaps_SclkDeepSleep)) {
2324 if (smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_MASTER_DeepSleep_ON))
2325 PP_ASSERT_WITH_CODE(false,
2326 "Attempt to enable Master Deep Sleep switch failed!",
2329 if (smum_send_msg_to_smc(hwmgr->smumgr,
2330 PPSMC_MSG_MASTER_DeepSleep_OFF)) {
2331 PP_ASSERT_WITH_CODE(false,
2332 "Attempt to disable Master Deep Sleep switch failed!",
2340 static int polaris10_disable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
2342 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2343 PHM_PlatformCaps_SclkDeepSleep)) {
2344 if (smum_send_msg_to_smc(hwmgr->smumgr,
2345 PPSMC_MSG_MASTER_DeepSleep_OFF)) {
2346 PP_ASSERT_WITH_CODE(false,
2347 "Attempt to disable Master Deep Sleep switch failed!",
2355 static int polaris10_enable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
2357 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2358 uint32_t soft_register_value = 0;
2359 uint32_t handshake_disables_offset = data->soft_regs_start
2360 + offsetof(SMU74_SoftRegisters, HandshakeDisables);
2362 /* enable SCLK dpm */
2363 if (!data->sclk_dpm_key_disabled)
2364 PP_ASSERT_WITH_CODE(
2365 (0 == smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_DPM_Enable)),
2366 "Failed to enable SCLK DPM during DPM Start Function!",
2369 /* enable MCLK dpm */
2370 if (0 == data->mclk_dpm_key_disabled) {
2371 /* Disable UVD - SMU handshake for MCLK. */
2372 soft_register_value = cgs_read_ind_register(hwmgr->device,
2373 CGS_IND_REG__SMC, handshake_disables_offset);
2374 soft_register_value |= SMU7_UVD_MCLK_HANDSHAKE_DISABLE;
2375 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2376 handshake_disables_offset, soft_register_value);
2378 PP_ASSERT_WITH_CODE(
2379 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
2380 PPSMC_MSG_MCLKDPM_Enable)),
2381 "Failed to enable MCLK DPM during DPM Start Function!",
2384 PHM_WRITE_FIELD(hwmgr->device, MC_SEQ_CNTL_3, CAC_EN, 0x1);
2386 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC0_CNTL, 0x5);
2387 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC1_CNTL, 0x5);
2388 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_CPL_CNTL, 0x100005);
2390 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC0_CNTL, 0x400005);
2391 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC1_CNTL, 0x400005);
2392 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_CPL_CNTL, 0x500005);
2398 static int polaris10_start_dpm(struct pp_hwmgr *hwmgr)
2400 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2402 /*enable general power management */
2404 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
2405 GLOBAL_PWRMGT_EN, 1);
2407 /* enable sclk deep sleep */
2409 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
2412 /* prepare for PCIE DPM */
2414 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2415 data->soft_regs_start + offsetof(SMU74_SoftRegisters,
2416 VoltageChangeTimeout), 0x1000);
2417 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE,
2418 SWRST_COMMAND_1, RESETLC, 0x0);
2420 PP_ASSERT_WITH_CODE(
2421 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
2422 PPSMC_MSG_Voltage_Cntl_Enable)),
2423 "Failed to enable voltage DPM during DPM Start Function!",
2427 if (polaris10_enable_sclk_mclk_dpm(hwmgr)) {
2428 printk(KERN_ERR "Failed to enable Sclk DPM and Mclk DPM!");
2432 /* enable PCIE dpm */
2433 if (0 == data->pcie_dpm_key_disabled) {
2434 PP_ASSERT_WITH_CODE(
2435 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
2436 PPSMC_MSG_PCIeDPM_Enable)),
2437 "Failed to enable pcie DPM during DPM Start Function!",
2441 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2442 PHM_PlatformCaps_Falcon_QuickTransition)) {
2443 PP_ASSERT_WITH_CODE((0 == smum_send_msg_to_smc(hwmgr->smumgr,
2444 PPSMC_MSG_EnableACDCGPIOInterrupt)),
2445 "Failed to enable AC DC GPIO Interrupt!",
2452 static int polaris10_disable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
2454 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2456 /* disable SCLK dpm */
2457 if (!data->sclk_dpm_key_disabled)
2458 PP_ASSERT_WITH_CODE(
2459 (smum_send_msg_to_smc(hwmgr->smumgr,
2460 PPSMC_MSG_DPM_Disable) == 0),
2461 "Failed to disable SCLK DPM!",
2464 /* disable MCLK dpm */
2465 if (!data->mclk_dpm_key_disabled) {
2466 PP_ASSERT_WITH_CODE(
2467 (smum_send_msg_to_smc(hwmgr->smumgr,
2468 PPSMC_MSG_MCLKDPM_Disable) == 0),
2469 "Failed to disable MCLK DPM!",
2476 static int polaris10_stop_dpm(struct pp_hwmgr *hwmgr)
2478 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2480 /* disable general power management */
2481 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
2482 GLOBAL_PWRMGT_EN, 0);
2483 /* disable sclk deep sleep */
2484 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
2487 /* disable PCIE dpm */
2488 if (!data->pcie_dpm_key_disabled) {
2489 PP_ASSERT_WITH_CODE(
2490 (smum_send_msg_to_smc(hwmgr->smumgr,
2491 PPSMC_MSG_PCIeDPM_Disable) == 0),
2492 "Failed to disable pcie DPM during DPM Stop Function!",
2496 if (polaris10_disable_sclk_mclk_dpm(hwmgr)) {
2497 printk(KERN_ERR "Failed to disable Sclk DPM and Mclk DPM!");
2504 static void polaris10_set_dpm_event_sources(struct pp_hwmgr *hwmgr, uint32_t sources)
2507 enum DPM_EVENT_SRC src;
2511 printk(KERN_ERR "Unknown throttling event sources.");
2517 case (1 << PHM_AutoThrottleSource_Thermal):
2519 src = DPM_EVENT_SRC_DIGITAL;
2521 case (1 << PHM_AutoThrottleSource_External):
2523 src = DPM_EVENT_SRC_EXTERNAL;
2525 case (1 << PHM_AutoThrottleSource_External) |
2526 (1 << PHM_AutoThrottleSource_Thermal):
2528 src = DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL;
2531 /* Order matters - don't enable thermal protection for the wrong source. */
2533 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_THERMAL_CTRL,
2534 DPM_EVENT_SRC, src);
2535 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
2536 THERMAL_PROTECTION_DIS,
2537 !phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2538 PHM_PlatformCaps_ThermalController));
2540 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
2541 THERMAL_PROTECTION_DIS, 1);
2544 static int polaris10_enable_auto_throttle_source(struct pp_hwmgr *hwmgr,
2545 PHM_AutoThrottleSource source)
2547 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2549 if (!(data->active_auto_throttle_sources & (1 << source))) {
2550 data->active_auto_throttle_sources |= 1 << source;
2551 polaris10_set_dpm_event_sources(hwmgr, data->active_auto_throttle_sources);
2556 static int polaris10_enable_thermal_auto_throttle(struct pp_hwmgr *hwmgr)
2558 return polaris10_enable_auto_throttle_source(hwmgr, PHM_AutoThrottleSource_Thermal);
2561 static int polaris10_disable_auto_throttle_source(struct pp_hwmgr *hwmgr,
2562 PHM_AutoThrottleSource source)
2564 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2566 if (data->active_auto_throttle_sources & (1 << source)) {
2567 data->active_auto_throttle_sources &= ~(1 << source);
2568 polaris10_set_dpm_event_sources(hwmgr, data->active_auto_throttle_sources);
2573 static int polaris10_disable_thermal_auto_throttle(struct pp_hwmgr *hwmgr)
2575 return polaris10_disable_auto_throttle_source(hwmgr, PHM_AutoThrottleSource_Thermal);
2578 int polaris10_pcie_performance_request(struct pp_hwmgr *hwmgr)
2580 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2581 data->pcie_performance_request = true;
2586 int polaris10_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
2588 int tmp_result, result = 0;
2589 tmp_result = (!polaris10_is_dpm_running(hwmgr)) ? 0 : -1;
2590 PP_ASSERT_WITH_CODE(result == 0,
2591 "DPM is already running right now, no need to enable DPM!",
2594 if (polaris10_voltage_control(hwmgr)) {
2595 tmp_result = polaris10_enable_voltage_control(hwmgr);
2596 PP_ASSERT_WITH_CODE(tmp_result == 0,
2597 "Failed to enable voltage control!",
2598 result = tmp_result);
2600 tmp_result = polaris10_construct_voltage_tables(hwmgr);
2601 PP_ASSERT_WITH_CODE((0 == tmp_result),
2602 "Failed to contruct voltage tables!",
2603 result = tmp_result);
2606 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2607 PHM_PlatformCaps_EngineSpreadSpectrumSupport))
2608 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
2609 GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, 1);
2611 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2612 PHM_PlatformCaps_ThermalController))
2613 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
2614 GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, 0);
2616 tmp_result = polaris10_program_static_screen_threshold_parameters(hwmgr);
2617 PP_ASSERT_WITH_CODE((0 == tmp_result),
2618 "Failed to program static screen threshold parameters!",
2619 result = tmp_result);
2621 tmp_result = polaris10_enable_display_gap(hwmgr);
2622 PP_ASSERT_WITH_CODE((0 == tmp_result),
2623 "Failed to enable display gap!", result = tmp_result);
2625 tmp_result = polaris10_program_voting_clients(hwmgr);
2626 PP_ASSERT_WITH_CODE((0 == tmp_result),
2627 "Failed to program voting clients!", result = tmp_result);
2629 tmp_result = polaris10_process_firmware_header(hwmgr);
2630 PP_ASSERT_WITH_CODE((0 == tmp_result),
2631 "Failed to process firmware header!", result = tmp_result);
2633 tmp_result = polaris10_initial_switch_from_arbf0_to_f1(hwmgr);
2634 PP_ASSERT_WITH_CODE((0 == tmp_result),
2635 "Failed to initialize switch from ArbF0 to F1!",
2636 result = tmp_result);
2638 tmp_result = polaris10_init_smc_table(hwmgr);
2639 PP_ASSERT_WITH_CODE((0 == tmp_result),
2640 "Failed to initialize SMC table!", result = tmp_result);
2642 tmp_result = polaris10_init_arb_table_index(hwmgr);
2643 PP_ASSERT_WITH_CODE((0 == tmp_result),
2644 "Failed to initialize ARB table index!", result = tmp_result);
2646 tmp_result = polaris10_populate_pm_fuses(hwmgr);
2647 PP_ASSERT_WITH_CODE((0 == tmp_result),
2648 "Failed to populate PM fuses!", result = tmp_result);
2650 tmp_result = polaris10_enable_vrhot_gpio_interrupt(hwmgr);
2651 PP_ASSERT_WITH_CODE((0 == tmp_result),
2652 "Failed to enable VR hot GPIO interrupt!", result = tmp_result);
2654 smum_send_msg_to_smc(hwmgr->smumgr, (PPSMC_Msg)PPSMC_HasDisplay);
2656 tmp_result = polaris10_enable_sclk_control(hwmgr);
2657 PP_ASSERT_WITH_CODE((0 == tmp_result),
2658 "Failed to enable SCLK control!", result = tmp_result);
2660 tmp_result = polaris10_enable_smc_voltage_controller(hwmgr);
2661 PP_ASSERT_WITH_CODE((0 == tmp_result),
2662 "Failed to enable voltage control!", result = tmp_result);
2664 tmp_result = polaris10_enable_ulv(hwmgr);
2665 PP_ASSERT_WITH_CODE((0 == tmp_result),
2666 "Failed to enable ULV!", result = tmp_result);
2668 tmp_result = polaris10_enable_deep_sleep_master_switch(hwmgr);
2669 PP_ASSERT_WITH_CODE((0 == tmp_result),
2670 "Failed to enable deep sleep master switch!", result = tmp_result);
2672 tmp_result = polaris10_start_dpm(hwmgr);
2673 PP_ASSERT_WITH_CODE((0 == tmp_result),
2674 "Failed to start DPM!", result = tmp_result);
2676 tmp_result = polaris10_enable_smc_cac(hwmgr);
2677 PP_ASSERT_WITH_CODE((0 == tmp_result),
2678 "Failed to enable SMC CAC!", result = tmp_result);
2680 tmp_result = polaris10_enable_power_containment(hwmgr);
2681 PP_ASSERT_WITH_CODE((0 == tmp_result),
2682 "Failed to enable power containment!", result = tmp_result);
2684 tmp_result = polaris10_power_control_set_level(hwmgr);
2685 PP_ASSERT_WITH_CODE((0 == tmp_result),
2686 "Failed to power control set level!", result = tmp_result);
2688 tmp_result = polaris10_enable_thermal_auto_throttle(hwmgr);
2689 PP_ASSERT_WITH_CODE((0 == tmp_result),
2690 "Failed to enable thermal auto throttle!", result = tmp_result);
2692 tmp_result = polaris10_pcie_performance_request(hwmgr);
2693 PP_ASSERT_WITH_CODE((0 == tmp_result),
2694 "pcie performance request failed!", result = tmp_result);
2699 int polaris10_disable_dpm_tasks(struct pp_hwmgr *hwmgr)
2701 int tmp_result, result = 0;
2703 tmp_result = (polaris10_is_dpm_running(hwmgr)) ? 0 : -1;
2704 PP_ASSERT_WITH_CODE(tmp_result == 0,
2705 "DPM is not running right now, no need to disable DPM!",
2708 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2709 PHM_PlatformCaps_ThermalController))
2710 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
2711 GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, 1);
2713 tmp_result = polaris10_disable_power_containment(hwmgr);
2714 PP_ASSERT_WITH_CODE((tmp_result == 0),
2715 "Failed to disable power containment!", result = tmp_result);
2717 tmp_result = polaris10_disable_smc_cac(hwmgr);
2718 PP_ASSERT_WITH_CODE((tmp_result == 0),
2719 "Failed to disable SMC CAC!", result = tmp_result);
2721 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
2722 CG_SPLL_SPREAD_SPECTRUM, SSEN, 0);
2723 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
2724 GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, 0);
2726 tmp_result = polaris10_disable_thermal_auto_throttle(hwmgr);
2727 PP_ASSERT_WITH_CODE((tmp_result == 0),
2728 "Failed to disable thermal auto throttle!", result = tmp_result);
2730 tmp_result = polaris10_stop_dpm(hwmgr);
2731 PP_ASSERT_WITH_CODE((tmp_result == 0),
2732 "Failed to stop DPM!", result = tmp_result);
2734 tmp_result = polaris10_disable_deep_sleep_master_switch(hwmgr);
2735 PP_ASSERT_WITH_CODE((tmp_result == 0),
2736 "Failed to disable deep sleep master switch!", result = tmp_result);
2738 tmp_result = polaris10_disable_ulv(hwmgr);
2739 PP_ASSERT_WITH_CODE((tmp_result == 0),
2740 "Failed to disable ULV!", result = tmp_result);
2742 tmp_result = polaris10_clear_voting_clients(hwmgr);
2743 PP_ASSERT_WITH_CODE((tmp_result == 0),
2744 "Failed to clear voting clients!", result = tmp_result);
2746 tmp_result = polaris10_reset_to_default(hwmgr);
2747 PP_ASSERT_WITH_CODE((tmp_result == 0),
2748 "Failed to reset to default!", result = tmp_result);
2750 tmp_result = polaris10_force_switch_to_arbf0(hwmgr);
2751 PP_ASSERT_WITH_CODE((tmp_result == 0),
2752 "Failed to force to switch arbf0!", result = tmp_result);
2757 int polaris10_reset_asic_tasks(struct pp_hwmgr *hwmgr)
2763 int polaris10_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)
2765 return phm_hwmgr_backend_fini(hwmgr);
2768 int polaris10_set_features_platform_caps(struct pp_hwmgr *hwmgr)
2770 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2772 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2773 PHM_PlatformCaps_SclkDeepSleep);
2775 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2776 PHM_PlatformCaps_DynamicPatchPowerState);
2778 if (data->mvdd_control == POLARIS10_VOLTAGE_CONTROL_NONE)
2779 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2780 PHM_PlatformCaps_EnableMVDDControl);
2782 if (data->vddci_control == POLARIS10_VOLTAGE_CONTROL_NONE)
2783 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2784 PHM_PlatformCaps_ControlVDDCI);
2786 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2787 PHM_PlatformCaps_TablelessHardwareInterface);
2789 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2790 PHM_PlatformCaps_EnableSMU7ThermalManagement);
2792 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2793 PHM_PlatformCaps_DynamicPowerManagement);
2795 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2796 PHM_PlatformCaps_UnTabledHardwareInterface);
2798 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2799 PHM_PlatformCaps_TablelessHardwareInterface);
2801 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2802 PHM_PlatformCaps_SMC);
2804 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2805 PHM_PlatformCaps_NonABMSupportInPPLib);
2807 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2808 PHM_PlatformCaps_DynamicUVDState);
2810 /* power tune caps Assume disabled */
2811 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2812 PHM_PlatformCaps_SQRamping);
2813 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2814 PHM_PlatformCaps_DBRamping);
2815 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2816 PHM_PlatformCaps_TDRamping);
2817 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2818 PHM_PlatformCaps_TCPRamping);
2820 if (hwmgr->powercontainment_enabled)
2821 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2822 PHM_PlatformCaps_PowerContainment);
2824 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2825 PHM_PlatformCaps_PowerContainment);
2827 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2828 PHM_PlatformCaps_CAC);
2830 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2831 PHM_PlatformCaps_RegulatorHot);
2833 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2834 PHM_PlatformCaps_AutomaticDCTransition);
2836 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2837 PHM_PlatformCaps_ODFuzzyFanControlSupport);
2839 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2840 PHM_PlatformCaps_FanSpeedInTableIsRPM);
2842 if (hwmgr->chip_id == CHIP_POLARIS11)
2843 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2844 PHM_PlatformCaps_SPLLShutdownSupport);
2848 static void polaris10_init_dpm_defaults(struct pp_hwmgr *hwmgr)
2850 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2852 polaris10_initialize_power_tune_defaults(hwmgr);
2854 data->pcie_gen_performance.max = PP_PCIEGen1;
2855 data->pcie_gen_performance.min = PP_PCIEGen3;
2856 data->pcie_gen_power_saving.max = PP_PCIEGen1;
2857 data->pcie_gen_power_saving.min = PP_PCIEGen3;
2858 data->pcie_lane_performance.max = 0;
2859 data->pcie_lane_performance.min = 16;
2860 data->pcie_lane_power_saving.max = 0;
2861 data->pcie_lane_power_saving.min = 16;
2865 * Get Leakage VDDC based on leakage ID.
2867 * @param hwmgr the address of the powerplay hardware manager.
2870 static int polaris10_get_evv_voltages(struct pp_hwmgr *hwmgr)
2872 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2877 struct phm_ppt_v1_information *table_info =
2878 (struct phm_ppt_v1_information *)hwmgr->pptable;
2879 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
2880 table_info->vdd_dep_on_sclk;
2883 for (i = 0; i < POLARIS10_MAX_LEAKAGE_COUNT; i++) {
2884 vv_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i;
2885 if (!phm_get_sclk_for_voltage_evv(hwmgr,
2886 table_info->vddc_lookup_table, vv_id, &sclk)) {
2887 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2888 PHM_PlatformCaps_ClockStretcher)) {
2889 for (j = 1; j < sclk_table->count; j++) {
2890 if (sclk_table->entries[j].clk == sclk &&
2891 sclk_table->entries[j].cks_enable == 0) {
2898 if (atomctrl_get_voltage_evv_on_sclk_ai(hwmgr,
2900 sclk, vv_id, &vddc) != 0) {
2901 printk(KERN_WARNING "failed to retrieving EVV voltage!\n");
2905 /* need to make sure vddc is less than 2v or else, it could burn the ASIC.
2906 * real voltage level in unit of 0.01mv */
2907 PP_ASSERT_WITH_CODE((vddc < 200000 && vddc != 0),
2908 "Invalid VDDC value", result = -EINVAL;);
2910 /* the voltage should not be zero nor equal to leakage ID */
2911 if (vddc != 0 && vddc != vv_id) {
2912 data->vddc_leakage.actual_voltage[data->vddc_leakage.count] = (uint16_t)(vddc/100);
2913 data->vddc_leakage.leakage_id[data->vddc_leakage.count] = vv_id;
2914 data->vddc_leakage.count++;
2923 * Change virtual leakage voltage to actual value.
2925 * @param hwmgr the address of the powerplay hardware manager.
2926 * @param pointer to changing voltage
2927 * @param pointer to leakage table
2929 static void polaris10_patch_with_vdd_leakage(struct pp_hwmgr *hwmgr,
2930 uint16_t *voltage, struct polaris10_leakage_voltage *leakage_table)
2934 /* search for leakage voltage ID 0xff01 ~ 0xff08 */
2935 for (index = 0; index < leakage_table->count; index++) {
2936 /* if this voltage matches a leakage voltage ID */
2937 /* patch with actual leakage voltage */
2938 if (leakage_table->leakage_id[index] == *voltage) {
2939 *voltage = leakage_table->actual_voltage[index];
2944 if (*voltage > ATOM_VIRTUAL_VOLTAGE_ID0)
2945 printk(KERN_ERR "Voltage value looks like a Leakage ID but it's not patched \n");
2949 * Patch voltage lookup table by EVV leakages.
2951 * @param hwmgr the address of the powerplay hardware manager.
2952 * @param pointer to voltage lookup table
2953 * @param pointer to leakage table
2956 static int polaris10_patch_lookup_table_with_leakage(struct pp_hwmgr *hwmgr,
2957 phm_ppt_v1_voltage_lookup_table *lookup_table,
2958 struct polaris10_leakage_voltage *leakage_table)
2962 for (i = 0; i < lookup_table->count; i++)
2963 polaris10_patch_with_vdd_leakage(hwmgr,
2964 &lookup_table->entries[i].us_vdd, leakage_table);
2969 static int polaris10_patch_clock_voltage_limits_with_vddc_leakage(
2970 struct pp_hwmgr *hwmgr, struct polaris10_leakage_voltage *leakage_table,
2973 struct phm_ppt_v1_information *table_info =
2974 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2975 polaris10_patch_with_vdd_leakage(hwmgr, (uint16_t *)vddc, leakage_table);
2976 hwmgr->dyn_state.max_clock_voltage_on_dc.vddc =
2977 table_info->max_clock_voltage_on_dc.vddc;
2981 static int polaris10_patch_voltage_dependency_tables_with_lookup_table(
2982 struct pp_hwmgr *hwmgr)
2986 struct phm_ppt_v1_information *table_info =
2987 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2989 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
2990 table_info->vdd_dep_on_sclk;
2991 struct phm_ppt_v1_clock_voltage_dependency_table *mclk_table =
2992 table_info->vdd_dep_on_mclk;
2993 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
2994 table_info->mm_dep_table;
2996 for (entryId = 0; entryId < sclk_table->count; ++entryId) {
2997 voltageId = sclk_table->entries[entryId].vddInd;
2998 sclk_table->entries[entryId].vddc =
2999 table_info->vddc_lookup_table->entries[voltageId].us_vdd;
3002 for (entryId = 0; entryId < mclk_table->count; ++entryId) {
3003 voltageId = mclk_table->entries[entryId].vddInd;
3004 mclk_table->entries[entryId].vddc =
3005 table_info->vddc_lookup_table->entries[voltageId].us_vdd;
3008 for (entryId = 0; entryId < mm_table->count; ++entryId) {
3009 voltageId = mm_table->entries[entryId].vddcInd;
3010 mm_table->entries[entryId].vddc =
3011 table_info->vddc_lookup_table->entries[voltageId].us_vdd;
3018 static int polaris10_calc_voltage_dependency_tables(struct pp_hwmgr *hwmgr)
3020 /* Need to determine if we need calculated voltage. */
3024 static int polaris10_calc_mm_voltage_dependency_table(struct pp_hwmgr *hwmgr)
3026 /* Need to determine if we need calculated voltage from mm table. */
3030 static int polaris10_sort_lookup_table(struct pp_hwmgr *hwmgr,
3031 struct phm_ppt_v1_voltage_lookup_table *lookup_table)
3033 uint32_t table_size, i, j;
3034 struct phm_ppt_v1_voltage_lookup_record tmp_voltage_lookup_record;
3035 table_size = lookup_table->count;
3037 PP_ASSERT_WITH_CODE(0 != lookup_table->count,
3038 "Lookup table is empty", return -EINVAL);
3040 /* Sorting voltages */
3041 for (i = 0; i < table_size - 1; i++) {
3042 for (j = i + 1; j > 0; j--) {
3043 if (lookup_table->entries[j].us_vdd <
3044 lookup_table->entries[j - 1].us_vdd) {
3045 tmp_voltage_lookup_record = lookup_table->entries[j - 1];
3046 lookup_table->entries[j - 1] = lookup_table->entries[j];
3047 lookup_table->entries[j] = tmp_voltage_lookup_record;
3055 static int polaris10_complete_dependency_tables(struct pp_hwmgr *hwmgr)
3059 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3060 struct phm_ppt_v1_information *table_info =
3061 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3063 tmp_result = polaris10_patch_lookup_table_with_leakage(hwmgr,
3064 table_info->vddc_lookup_table, &(data->vddc_leakage));
3066 result = tmp_result;
3068 tmp_result = polaris10_patch_clock_voltage_limits_with_vddc_leakage(hwmgr,
3069 &(data->vddc_leakage), &table_info->max_clock_voltage_on_dc.vddc);
3071 result = tmp_result;
3073 tmp_result = polaris10_patch_voltage_dependency_tables_with_lookup_table(hwmgr);
3075 result = tmp_result;
3077 tmp_result = polaris10_calc_voltage_dependency_tables(hwmgr);
3079 result = tmp_result;
3081 tmp_result = polaris10_calc_mm_voltage_dependency_table(hwmgr);
3083 result = tmp_result;
3085 tmp_result = polaris10_sort_lookup_table(hwmgr, table_info->vddc_lookup_table);
3087 result = tmp_result;
3092 static int polaris10_set_private_data_based_on_pptable(struct pp_hwmgr *hwmgr)
3094 struct phm_ppt_v1_information *table_info =
3095 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3097 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_sclk_vdd_table =
3098 table_info->vdd_dep_on_sclk;
3099 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_mclk_vdd_table =
3100 table_info->vdd_dep_on_mclk;
3102 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table != NULL,
3103 "VDD dependency on SCLK table is missing. \
3104 This table is mandatory", return -EINVAL);
3105 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table->count >= 1,
3106 "VDD dependency on SCLK table has to have is missing. \
3107 This table is mandatory", return -EINVAL);
3109 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table != NULL,
3110 "VDD dependency on MCLK table is missing. \
3111 This table is mandatory", return -EINVAL);
3112 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table->count >= 1,
3113 "VDD dependency on MCLK table has to have is missing. \
3114 This table is mandatory", return -EINVAL);
3116 table_info->max_clock_voltage_on_ac.sclk =
3117 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].clk;
3118 table_info->max_clock_voltage_on_ac.mclk =
3119 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].clk;
3120 table_info->max_clock_voltage_on_ac.vddc =
3121 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].vddc;
3122 table_info->max_clock_voltage_on_ac.vddci =
3123 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].vddci;
3125 hwmgr->dyn_state.max_clock_voltage_on_ac.sclk = table_info->max_clock_voltage_on_ac.sclk;
3126 hwmgr->dyn_state.max_clock_voltage_on_ac.mclk = table_info->max_clock_voltage_on_ac.mclk;
3127 hwmgr->dyn_state.max_clock_voltage_on_ac.vddc = table_info->max_clock_voltage_on_ac.vddc;
3128 hwmgr->dyn_state.max_clock_voltage_on_ac.vddci =table_info->max_clock_voltage_on_ac.vddci;
3133 int polaris10_patch_voltage_workaround(struct pp_hwmgr *hwmgr)
3135 struct phm_ppt_v1_information *table_info =
3136 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3137 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
3138 table_info->vdd_dep_on_mclk;
3139 struct phm_ppt_v1_voltage_lookup_table *lookup_table =
3140 table_info->vddc_lookup_table;
3143 if (hwmgr->chip_id == CHIP_POLARIS10 && hwmgr->hw_revision == 0xC7) {
3144 if (lookup_table->entries[dep_mclk_table->entries[dep_mclk_table->count-1].vddInd].us_vdd >= 1000)
3147 for (i = 0; i < lookup_table->count; i++) {
3148 if (lookup_table->entries[i].us_vdd < 0xff01 && lookup_table->entries[i].us_vdd >= 1000) {
3149 dep_mclk_table->entries[dep_mclk_table->count-1].vddInd = (uint8_t) i;
3158 int polaris10_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
3160 struct polaris10_hwmgr *data;
3161 struct pp_atomctrl_gpio_pin_assignment gpio_pin_assignment;
3164 struct phm_ppt_v1_information *table_info =
3165 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3167 data = kzalloc(sizeof(struct polaris10_hwmgr), GFP_KERNEL);
3171 hwmgr->backend = data;
3173 data->dll_default_on = false;
3174 data->sram_end = SMC_RAM_END;
3175 data->mclk_dpm0_activity_target = 0xa;
3176 data->disable_dpm_mask = 0xFF;
3177 data->static_screen_threshold = PPPOLARIS10_STATICSCREENTHRESHOLD_DFLT;
3178 data->static_screen_threshold_unit = PPPOLARIS10_STATICSCREENTHRESHOLD_DFLT;
3179 data->activity_target[0] = PPPOLARIS10_TARGETACTIVITY_DFLT;
3180 data->activity_target[1] = PPPOLARIS10_TARGETACTIVITY_DFLT;
3181 data->activity_target[2] = PPPOLARIS10_TARGETACTIVITY_DFLT;
3182 data->activity_target[3] = PPPOLARIS10_TARGETACTIVITY_DFLT;
3183 data->activity_target[4] = PPPOLARIS10_TARGETACTIVITY_DFLT;
3184 data->activity_target[5] = PPPOLARIS10_TARGETACTIVITY_DFLT;
3185 data->activity_target[6] = PPPOLARIS10_TARGETACTIVITY_DFLT;
3186 data->activity_target[7] = PPPOLARIS10_TARGETACTIVITY_DFLT;
3188 data->voting_rights_clients0 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT0;
3189 data->voting_rights_clients1 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT1;
3190 data->voting_rights_clients2 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT2;
3191 data->voting_rights_clients3 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT3;
3192 data->voting_rights_clients4 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT4;
3193 data->voting_rights_clients5 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT5;
3194 data->voting_rights_clients6 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT6;
3195 data->voting_rights_clients7 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT7;
3197 data->vddc_vddci_delta = VDDC_VDDCI_DELTA;
3199 data->mclk_activity_target = PPPOLARIS10_MCLK_TARGETACTIVITY_DFLT;
3201 /* need to set voltage control types before EVV patching */
3202 data->voltage_control = POLARIS10_VOLTAGE_CONTROL_NONE;
3203 data->vddci_control = POLARIS10_VOLTAGE_CONTROL_NONE;
3204 data->mvdd_control = POLARIS10_VOLTAGE_CONTROL_NONE;
3206 data->enable_tdc_limit_feature = true;
3207 data->enable_pkg_pwr_tracking_feature = true;
3208 data->force_pcie_gen = PP_PCIEGenInvalid;
3209 data->mclk_stutter_mode_threshold = 40000;
3211 if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
3212 VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_SVID2))
3213 data->voltage_control = POLARIS10_VOLTAGE_CONTROL_BY_SVID2;
3215 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3216 PHM_PlatformCaps_EnableMVDDControl)) {
3217 if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
3218 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT))
3219 data->mvdd_control = POLARIS10_VOLTAGE_CONTROL_BY_GPIO;
3220 else if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
3221 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_SVID2))
3222 data->mvdd_control = POLARIS10_VOLTAGE_CONTROL_BY_SVID2;
3225 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3226 PHM_PlatformCaps_ControlVDDCI)) {
3227 if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
3228 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT))
3229 data->vddci_control = POLARIS10_VOLTAGE_CONTROL_BY_GPIO;
3230 else if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
3231 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_SVID2))
3232 data->vddci_control = POLARIS10_VOLTAGE_CONTROL_BY_SVID2;
3235 if (table_info->cac_dtp_table->usClockStretchAmount != 0)
3236 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3237 PHM_PlatformCaps_ClockStretcher);
3239 polaris10_set_features_platform_caps(hwmgr);
3241 polaris10_patch_voltage_workaround(hwmgr);
3242 polaris10_init_dpm_defaults(hwmgr);
3244 /* Get leakage voltage based on leakage ID. */
3245 result = polaris10_get_evv_voltages(hwmgr);
3248 printk("Get EVV Voltage Failed. Abort Driver loading!\n");
3252 polaris10_complete_dependency_tables(hwmgr);
3253 polaris10_set_private_data_based_on_pptable(hwmgr);
3255 /* Initalize Dynamic State Adjustment Rule Settings */
3256 result = phm_initializa_dynamic_state_adjustment_rule_settings(hwmgr);
3259 struct cgs_system_info sys_info = {0};
3261 data->is_tlu_enabled = 0;
3263 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels =
3264 POLARIS10_MAX_HARDWARE_POWERLEVELS;
3265 hwmgr->platform_descriptor.hardwarePerformanceLevels = 2;
3266 hwmgr->platform_descriptor.minimumClocksReductionPercentage = 50;
3269 if (atomctrl_get_pp_assign_pin(hwmgr, VDDC_PCC_GPIO_PINID, &gpio_pin_assignment)) {
3270 temp_reg = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCNB_PWRMGT_CNTL);
3271 switch (gpio_pin_assignment.uc_gpio_pin_bit_shift) {
3273 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x1);
3276 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x2);
3279 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW, 0x1);
3282 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, FORCE_NB_PS1, 0x1);
3285 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, DPM_ENABLED, 0x1);
3288 PP_ASSERT_WITH_CODE(0,
3289 "Failed to setup PCC HW register! Wrong GPIO assigned for VDDC_PCC_GPIO_PINID!",
3293 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCNB_PWRMGT_CNTL, temp_reg);
3296 if (table_info->cac_dtp_table->usDefaultTargetOperatingTemp != 0 &&
3297 hwmgr->thermal_controller.advanceFanControlParameters.ucFanControlMode) {
3298 hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMMinLimit =
3299 (uint16_t)hwmgr->thermal_controller.advanceFanControlParameters.ucMinimumPWMLimit;
3301 hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMMaxLimit =
3302 (uint16_t)hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanPWM;
3304 hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMStep = 1;
3306 hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMMaxLimit = 100;
3308 hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMMinLimit =
3309 (uint16_t)hwmgr->thermal_controller.advanceFanControlParameters.ucMinimumPWMLimit;
3311 hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMStep = 1;
3313 table_info->cac_dtp_table->usDefaultTargetOperatingTemp = (table_info->cac_dtp_table->usDefaultTargetOperatingTemp >= 50) ?
3314 (table_info->cac_dtp_table->usDefaultTargetOperatingTemp -50) : 0;
3316 table_info->cac_dtp_table->usOperatingTempMaxLimit = table_info->cac_dtp_table->usDefaultTargetOperatingTemp;
3317 table_info->cac_dtp_table->usOperatingTempStep = 1;
3318 table_info->cac_dtp_table->usOperatingTempHyst = 1;
3320 hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanPWM =
3321 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanPWM;
3323 hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanRPM =
3324 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanRPM;
3326 hwmgr->dyn_state.cac_dtp_table->usOperatingTempMinLimit =
3327 table_info->cac_dtp_table->usOperatingTempMinLimit;
3329 hwmgr->dyn_state.cac_dtp_table->usOperatingTempMaxLimit =
3330 table_info->cac_dtp_table->usOperatingTempMaxLimit;
3332 hwmgr->dyn_state.cac_dtp_table->usDefaultTargetOperatingTemp =
3333 table_info->cac_dtp_table->usDefaultTargetOperatingTemp;
3335 hwmgr->dyn_state.cac_dtp_table->usOperatingTempStep =
3336 table_info->cac_dtp_table->usOperatingTempStep;
3338 hwmgr->dyn_state.cac_dtp_table->usTargetOperatingTemp =
3339 table_info->cac_dtp_table->usTargetOperatingTemp;
3342 sys_info.size = sizeof(struct cgs_system_info);
3343 sys_info.info_id = CGS_SYSTEM_INFO_PCIE_GEN_INFO;
3344 result = cgs_query_system_info(hwmgr->device, &sys_info);
3346 data->pcie_gen_cap = AMDGPU_DEFAULT_PCIE_GEN_MASK;
3348 data->pcie_gen_cap = (uint32_t)sys_info.value;
3349 if (data->pcie_gen_cap & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)
3350 data->pcie_spc_cap = 20;
3351 sys_info.size = sizeof(struct cgs_system_info);
3352 sys_info.info_id = CGS_SYSTEM_INFO_PCIE_MLW;
3353 result = cgs_query_system_info(hwmgr->device, &sys_info);
3355 data->pcie_lane_cap = AMDGPU_DEFAULT_PCIE_MLW_MASK;
3357 data->pcie_lane_cap = (uint32_t)sys_info.value;
3359 hwmgr->platform_descriptor.vbiosInterruptId = 0x20000400; /* IRQ_SOURCE1_SW_INT */
3360 /* The true clock step depends on the frequency, typically 4.5 or 9 MHz. Here we use 5. */
3361 hwmgr->platform_descriptor.clockStep.engineClock = 500;
3362 hwmgr->platform_descriptor.clockStep.memoryClock = 500;
3364 /* Ignore return value in here, we are cleaning up a mess. */
3365 polaris10_hwmgr_backend_fini(hwmgr);
3371 static int polaris10_force_dpm_highest(struct pp_hwmgr *hwmgr)
3373 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3374 uint32_t level, tmp;
3376 if (!data->pcie_dpm_key_disabled) {
3377 if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) {
3379 tmp = data->dpm_level_enable_mask.pcie_dpm_enable_mask;
3384 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3385 PPSMC_MSG_PCIeDPM_ForceLevel, level);
3389 if (!data->sclk_dpm_key_disabled) {
3390 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
3392 tmp = data->dpm_level_enable_mask.sclk_dpm_enable_mask;
3397 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3398 PPSMC_MSG_SCLKDPM_SetEnabledMask,
3403 if (!data->mclk_dpm_key_disabled) {
3404 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
3406 tmp = data->dpm_level_enable_mask.mclk_dpm_enable_mask;
3411 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3412 PPSMC_MSG_MCLKDPM_SetEnabledMask,
3420 static int polaris10_upload_dpm_level_enable_mask(struct pp_hwmgr *hwmgr)
3422 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3424 phm_apply_dal_min_voltage_request(hwmgr);
3426 if (!data->sclk_dpm_key_disabled) {
3427 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask)
3428 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3429 PPSMC_MSG_SCLKDPM_SetEnabledMask,
3430 data->dpm_level_enable_mask.sclk_dpm_enable_mask);
3433 if (!data->mclk_dpm_key_disabled) {
3434 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask)
3435 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3436 PPSMC_MSG_MCLKDPM_SetEnabledMask,
3437 data->dpm_level_enable_mask.mclk_dpm_enable_mask);
3443 static int polaris10_unforce_dpm_levels(struct pp_hwmgr *hwmgr)
3445 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3447 if (!polaris10_is_dpm_running(hwmgr))
3450 if (!data->pcie_dpm_key_disabled) {
3451 smum_send_msg_to_smc(hwmgr->smumgr,
3452 PPSMC_MSG_PCIeDPM_UnForceLevel);
3455 return polaris10_upload_dpm_level_enable_mask(hwmgr);
3458 static int polaris10_force_dpm_lowest(struct pp_hwmgr *hwmgr)
3460 struct polaris10_hwmgr *data =
3461 (struct polaris10_hwmgr *)(hwmgr->backend);
3464 if (!data->sclk_dpm_key_disabled)
3465 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
3466 level = phm_get_lowest_enabled_level(hwmgr,
3467 data->dpm_level_enable_mask.sclk_dpm_enable_mask);
3468 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3469 PPSMC_MSG_SCLKDPM_SetEnabledMask,
3474 if (!data->mclk_dpm_key_disabled) {
3475 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
3476 level = phm_get_lowest_enabled_level(hwmgr,
3477 data->dpm_level_enable_mask.mclk_dpm_enable_mask);
3478 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3479 PPSMC_MSG_MCLKDPM_SetEnabledMask,
3484 if (!data->pcie_dpm_key_disabled) {
3485 if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) {
3486 level = phm_get_lowest_enabled_level(hwmgr,
3487 data->dpm_level_enable_mask.pcie_dpm_enable_mask);
3488 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3489 PPSMC_MSG_PCIeDPM_ForceLevel,
3497 static int polaris10_force_dpm_level(struct pp_hwmgr *hwmgr,
3498 enum amd_dpm_forced_level level)
3503 case AMD_DPM_FORCED_LEVEL_HIGH:
3504 ret = polaris10_force_dpm_highest(hwmgr);
3508 case AMD_DPM_FORCED_LEVEL_LOW:
3509 ret = polaris10_force_dpm_lowest(hwmgr);
3513 case AMD_DPM_FORCED_LEVEL_AUTO:
3514 ret = polaris10_unforce_dpm_levels(hwmgr);
3522 hwmgr->dpm_level = level;
3527 static int polaris10_get_power_state_size(struct pp_hwmgr *hwmgr)
3529 return sizeof(struct polaris10_power_state);
3533 static int polaris10_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
3534 struct pp_power_state *request_ps,
3535 const struct pp_power_state *current_ps)
3538 struct polaris10_power_state *polaris10_ps =
3539 cast_phw_polaris10_power_state(&request_ps->hardware);
3542 struct PP_Clocks minimum_clocks = {0};
3543 bool disable_mclk_switching;
3544 bool disable_mclk_switching_for_frame_lock;
3545 struct cgs_display_info info = {0};
3546 const struct phm_clock_and_voltage_limits *max_limits;
3548 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3549 struct phm_ppt_v1_information *table_info =
3550 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3552 int32_t stable_pstate_sclk = 0, stable_pstate_mclk = 0;
3554 data->battery_state = (PP_StateUILabel_Battery ==
3555 request_ps->classification.ui_label);
3557 PP_ASSERT_WITH_CODE(polaris10_ps->performance_level_count == 2,
3558 "VI should always have 2 performance levels",
3561 max_limits = (PP_PowerSource_AC == hwmgr->power_source) ?
3562 &(hwmgr->dyn_state.max_clock_voltage_on_ac) :
3563 &(hwmgr->dyn_state.max_clock_voltage_on_dc);
3565 /* Cap clock DPM tables at DC MAX if it is in DC. */
3566 if (PP_PowerSource_DC == hwmgr->power_source) {
3567 for (i = 0; i < polaris10_ps->performance_level_count; i++) {
3568 if (polaris10_ps->performance_levels[i].memory_clock > max_limits->mclk)
3569 polaris10_ps->performance_levels[i].memory_clock = max_limits->mclk;
3570 if (polaris10_ps->performance_levels[i].engine_clock > max_limits->sclk)
3571 polaris10_ps->performance_levels[i].engine_clock = max_limits->sclk;
3575 polaris10_ps->vce_clks.evclk = hwmgr->vce_arbiter.evclk;
3576 polaris10_ps->vce_clks.ecclk = hwmgr->vce_arbiter.ecclk;
3578 cgs_get_active_displays_info(hwmgr->device, &info);
3580 /*TO DO result = PHM_CheckVBlankTime(hwmgr, &vblankTooShort);*/
3582 /* TO DO GetMinClockSettings(hwmgr->pPECI, &minimum_clocks); */
3584 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3585 PHM_PlatformCaps_StablePState)) {
3586 max_limits = &(hwmgr->dyn_state.max_clock_voltage_on_ac);
3587 stable_pstate_sclk = (max_limits->sclk * 75) / 100;
3589 for (count = table_info->vdd_dep_on_sclk->count - 1;
3590 count >= 0; count--) {
3591 if (stable_pstate_sclk >=
3592 table_info->vdd_dep_on_sclk->entries[count].clk) {
3593 stable_pstate_sclk =
3594 table_info->vdd_dep_on_sclk->entries[count].clk;
3600 stable_pstate_sclk = table_info->vdd_dep_on_sclk->entries[0].clk;
3602 stable_pstate_mclk = max_limits->mclk;
3604 minimum_clocks.engineClock = stable_pstate_sclk;
3605 minimum_clocks.memoryClock = stable_pstate_mclk;
3608 if (minimum_clocks.engineClock < hwmgr->gfx_arbiter.sclk)
3609 minimum_clocks.engineClock = hwmgr->gfx_arbiter.sclk;
3611 if (minimum_clocks.memoryClock < hwmgr->gfx_arbiter.mclk)
3612 minimum_clocks.memoryClock = hwmgr->gfx_arbiter.mclk;
3614 polaris10_ps->sclk_threshold = hwmgr->gfx_arbiter.sclk_threshold;
3616 if (0 != hwmgr->gfx_arbiter.sclk_over_drive) {
3617 PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.sclk_over_drive <=
3618 hwmgr->platform_descriptor.overdriveLimit.engineClock),
3619 "Overdrive sclk exceeds limit",
3620 hwmgr->gfx_arbiter.sclk_over_drive =
3621 hwmgr->platform_descriptor.overdriveLimit.engineClock);
3623 if (hwmgr->gfx_arbiter.sclk_over_drive >= hwmgr->gfx_arbiter.sclk)
3624 polaris10_ps->performance_levels[1].engine_clock =
3625 hwmgr->gfx_arbiter.sclk_over_drive;
3628 if (0 != hwmgr->gfx_arbiter.mclk_over_drive) {
3629 PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.mclk_over_drive <=
3630 hwmgr->platform_descriptor.overdriveLimit.memoryClock),
3631 "Overdrive mclk exceeds limit",
3632 hwmgr->gfx_arbiter.mclk_over_drive =
3633 hwmgr->platform_descriptor.overdriveLimit.memoryClock);
3635 if (hwmgr->gfx_arbiter.mclk_over_drive >= hwmgr->gfx_arbiter.mclk)
3636 polaris10_ps->performance_levels[1].memory_clock =
3637 hwmgr->gfx_arbiter.mclk_over_drive;
3640 disable_mclk_switching_for_frame_lock = phm_cap_enabled(
3641 hwmgr->platform_descriptor.platformCaps,
3642 PHM_PlatformCaps_DisableMclkSwitchingForFrameLock);
3644 disable_mclk_switching = (1 < info.display_count) ||
3645 disable_mclk_switching_for_frame_lock;
3647 sclk = polaris10_ps->performance_levels[0].engine_clock;
3648 mclk = polaris10_ps->performance_levels[0].memory_clock;
3650 if (disable_mclk_switching)
3651 mclk = polaris10_ps->performance_levels
3652 [polaris10_ps->performance_level_count - 1].memory_clock;
3654 if (sclk < minimum_clocks.engineClock)
3655 sclk = (minimum_clocks.engineClock > max_limits->sclk) ?
3656 max_limits->sclk : minimum_clocks.engineClock;
3658 if (mclk < minimum_clocks.memoryClock)
3659 mclk = (minimum_clocks.memoryClock > max_limits->mclk) ?
3660 max_limits->mclk : minimum_clocks.memoryClock;
3662 polaris10_ps->performance_levels[0].engine_clock = sclk;
3663 polaris10_ps->performance_levels[0].memory_clock = mclk;
3665 polaris10_ps->performance_levels[1].engine_clock =
3666 (polaris10_ps->performance_levels[1].engine_clock >=
3667 polaris10_ps->performance_levels[0].engine_clock) ?
3668 polaris10_ps->performance_levels[1].engine_clock :
3669 polaris10_ps->performance_levels[0].engine_clock;
3671 if (disable_mclk_switching) {
3672 if (mclk < polaris10_ps->performance_levels[1].memory_clock)
3673 mclk = polaris10_ps->performance_levels[1].memory_clock;
3675 polaris10_ps->performance_levels[0].memory_clock = mclk;
3676 polaris10_ps->performance_levels[1].memory_clock = mclk;
3678 if (polaris10_ps->performance_levels[1].memory_clock <
3679 polaris10_ps->performance_levels[0].memory_clock)
3680 polaris10_ps->performance_levels[1].memory_clock =
3681 polaris10_ps->performance_levels[0].memory_clock;
3684 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3685 PHM_PlatformCaps_StablePState)) {
3686 for (i = 0; i < polaris10_ps->performance_level_count; i++) {
3687 polaris10_ps->performance_levels[i].engine_clock = stable_pstate_sclk;
3688 polaris10_ps->performance_levels[i].memory_clock = stable_pstate_mclk;
3689 polaris10_ps->performance_levels[i].pcie_gen = data->pcie_gen_performance.max;
3690 polaris10_ps->performance_levels[i].pcie_lane = data->pcie_gen_performance.max;
3697 static int polaris10_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)
3699 struct pp_power_state *ps;
3700 struct polaris10_power_state *polaris10_ps;
3705 ps = hwmgr->request_ps;
3710 polaris10_ps = cast_phw_polaris10_power_state(&ps->hardware);
3713 return polaris10_ps->performance_levels[0].memory_clock;
3715 return polaris10_ps->performance_levels
3716 [polaris10_ps->performance_level_count-1].memory_clock;
3719 static int polaris10_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)
3721 struct pp_power_state *ps;
3722 struct polaris10_power_state *polaris10_ps;
3727 ps = hwmgr->request_ps;
3732 polaris10_ps = cast_phw_polaris10_power_state(&ps->hardware);
3735 return polaris10_ps->performance_levels[0].engine_clock;
3737 return polaris10_ps->performance_levels
3738 [polaris10_ps->performance_level_count-1].engine_clock;
3741 static int polaris10_dpm_patch_boot_state(struct pp_hwmgr *hwmgr,
3742 struct pp_hw_power_state *hw_ps)
3744 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3745 struct polaris10_power_state *ps = (struct polaris10_power_state *)hw_ps;
3746 ATOM_FIRMWARE_INFO_V2_2 *fw_info;
3749 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
3751 /* First retrieve the Boot clocks and VDDC from the firmware info table.
3752 * We assume here that fw_info is unchanged if this call fails.
3754 fw_info = (ATOM_FIRMWARE_INFO_V2_2 *)cgs_atom_get_data_table(
3755 hwmgr->device, index,
3756 &size, &frev, &crev);
3758 /* During a test, there is no firmware info table. */
3761 /* Patch the state. */
3762 data->vbios_boot_state.sclk_bootup_value =
3763 le32_to_cpu(fw_info->ulDefaultEngineClock);
3764 data->vbios_boot_state.mclk_bootup_value =
3765 le32_to_cpu(fw_info->ulDefaultMemoryClock);
3766 data->vbios_boot_state.mvdd_bootup_value =
3767 le16_to_cpu(fw_info->usBootUpMVDDCVoltage);
3768 data->vbios_boot_state.vddc_bootup_value =
3769 le16_to_cpu(fw_info->usBootUpVDDCVoltage);
3770 data->vbios_boot_state.vddci_bootup_value =
3771 le16_to_cpu(fw_info->usBootUpVDDCIVoltage);
3772 data->vbios_boot_state.pcie_gen_bootup_value =
3773 phm_get_current_pcie_speed(hwmgr);
3775 data->vbios_boot_state.pcie_lane_bootup_value =
3776 (uint16_t)phm_get_current_pcie_lane_number(hwmgr);
3778 /* set boot power state */
3779 ps->performance_levels[0].memory_clock = data->vbios_boot_state.mclk_bootup_value;
3780 ps->performance_levels[0].engine_clock = data->vbios_boot_state.sclk_bootup_value;
3781 ps->performance_levels[0].pcie_gen = data->vbios_boot_state.pcie_gen_bootup_value;
3782 ps->performance_levels[0].pcie_lane = data->vbios_boot_state.pcie_lane_bootup_value;
3787 static int polaris10_get_pp_table_entry_callback_func(struct pp_hwmgr *hwmgr,
3788 void *state, struct pp_power_state *power_state,
3789 void *pp_table, uint32_t classification_flag)
3791 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3792 struct polaris10_power_state *polaris10_power_state =
3793 (struct polaris10_power_state *)(&(power_state->hardware));
3794 struct polaris10_performance_level *performance_level;
3795 ATOM_Tonga_State *state_entry = (ATOM_Tonga_State *)state;
3796 ATOM_Tonga_POWERPLAYTABLE *powerplay_table =
3797 (ATOM_Tonga_POWERPLAYTABLE *)pp_table;
3798 PPTable_Generic_SubTable_Header *sclk_dep_table =
3799 (PPTable_Generic_SubTable_Header *)
3800 (((unsigned long)powerplay_table) +
3801 le16_to_cpu(powerplay_table->usSclkDependencyTableOffset));
3803 ATOM_Tonga_MCLK_Dependency_Table *mclk_dep_table =
3804 (ATOM_Tonga_MCLK_Dependency_Table *)
3805 (((unsigned long)powerplay_table) +
3806 le16_to_cpu(powerplay_table->usMclkDependencyTableOffset));
3808 /* The following fields are not initialized here: id orderedList allStatesList */
3809 power_state->classification.ui_label =
3810 (le16_to_cpu(state_entry->usClassification) &
3811 ATOM_PPLIB_CLASSIFICATION_UI_MASK) >>
3812 ATOM_PPLIB_CLASSIFICATION_UI_SHIFT;
3813 power_state->classification.flags = classification_flag;
3814 /* NOTE: There is a classification2 flag in BIOS that is not being used right now */
3816 power_state->classification.temporary_state = false;
3817 power_state->classification.to_be_deleted = false;
3819 power_state->validation.disallowOnDC =
3820 (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) &
3821 ATOM_Tonga_DISALLOW_ON_DC));
3823 power_state->pcie.lanes = 0;
3825 power_state->display.disableFrameModulation = false;
3826 power_state->display.limitRefreshrate = false;
3827 power_state->display.enableVariBright =
3828 (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) &
3829 ATOM_Tonga_ENABLE_VARIBRIGHT));
3831 power_state->validation.supportedPowerLevels = 0;
3832 power_state->uvd_clocks.VCLK = 0;
3833 power_state->uvd_clocks.DCLK = 0;
3834 power_state->temperatures.min = 0;
3835 power_state->temperatures.max = 0;
3837 performance_level = &(polaris10_power_state->performance_levels
3838 [polaris10_power_state->performance_level_count++]);
3840 PP_ASSERT_WITH_CODE(
3841 (polaris10_power_state->performance_level_count < SMU74_MAX_LEVELS_GRAPHICS),
3842 "Performance levels exceeds SMC limit!",
3845 PP_ASSERT_WITH_CODE(
3846 (polaris10_power_state->performance_level_count <=
3847 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels),
3848 "Performance levels exceeds Driver limit!",
3851 /* Performance levels are arranged from low to high. */
3852 performance_level->memory_clock = mclk_dep_table->entries
3853 [state_entry->ucMemoryClockIndexLow].ulMclk;
3854 if (sclk_dep_table->ucRevId == 0)
3855 performance_level->engine_clock = ((ATOM_Tonga_SCLK_Dependency_Table *)sclk_dep_table)->entries
3856 [state_entry->ucEngineClockIndexLow].ulSclk;
3857 else if (sclk_dep_table->ucRevId == 1)
3858 performance_level->engine_clock = ((ATOM_Polaris_SCLK_Dependency_Table *)sclk_dep_table)->entries
3859 [state_entry->ucEngineClockIndexLow].ulSclk;
3860 performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap,
3861 state_entry->ucPCIEGenLow);
3862 performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap,
3863 state_entry->ucPCIELaneHigh);
3865 performance_level = &(polaris10_power_state->performance_levels
3866 [polaris10_power_state->performance_level_count++]);
3867 performance_level->memory_clock = mclk_dep_table->entries
3868 [state_entry->ucMemoryClockIndexHigh].ulMclk;
3870 if (sclk_dep_table->ucRevId == 0)
3871 performance_level->engine_clock = ((ATOM_Tonga_SCLK_Dependency_Table *)sclk_dep_table)->entries
3872 [state_entry->ucEngineClockIndexHigh].ulSclk;
3873 else if (sclk_dep_table->ucRevId == 1)
3874 performance_level->engine_clock = ((ATOM_Polaris_SCLK_Dependency_Table *)sclk_dep_table)->entries
3875 [state_entry->ucEngineClockIndexHigh].ulSclk;
3877 performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap,
3878 state_entry->ucPCIEGenHigh);
3879 performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap,
3880 state_entry->ucPCIELaneHigh);
3885 static int polaris10_get_pp_table_entry(struct pp_hwmgr *hwmgr,
3886 unsigned long entry_index, struct pp_power_state *state)
3889 struct polaris10_power_state *ps;
3890 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3891 struct phm_ppt_v1_information *table_info =
3892 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3893 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
3894 table_info->vdd_dep_on_mclk;
3896 state->hardware.magic = PHM_VIslands_Magic;
3898 ps = (struct polaris10_power_state *)(&state->hardware);
3900 result = tonga_get_powerplay_table_entry(hwmgr, entry_index, state,
3901 polaris10_get_pp_table_entry_callback_func);
3903 /* This is the earliest time we have all the dependency table and the VBIOS boot state
3904 * as PP_Tables_GetPowerPlayTableEntry retrieves the VBIOS boot state
3905 * if there is only one VDDCI/MCLK level, check if it's the same as VBIOS boot state
3907 if (dep_mclk_table != NULL && dep_mclk_table->count == 1) {
3908 if (dep_mclk_table->entries[0].clk !=
3909 data->vbios_boot_state.mclk_bootup_value)
3910 printk(KERN_ERR "Single MCLK entry VDDCI/MCLK dependency table "
3911 "does not match VBIOS boot MCLK level");
3912 if (dep_mclk_table->entries[0].vddci !=
3913 data->vbios_boot_state.vddci_bootup_value)
3914 printk(KERN_ERR "Single VDDCI entry VDDCI/MCLK dependency table "
3915 "does not match VBIOS boot VDDCI level");
3918 /* set DC compatible flag if this state supports DC */
3919 if (!state->validation.disallowOnDC)
3920 ps->dc_compatible = true;
3922 if (state->classification.flags & PP_StateClassificationFlag_ACPI)
3923 data->acpi_pcie_gen = ps->performance_levels[0].pcie_gen;
3925 ps->uvd_clks.vclk = state->uvd_clocks.VCLK;
3926 ps->uvd_clks.dclk = state->uvd_clocks.DCLK;
3931 switch (state->classification.ui_label) {
3932 case PP_StateUILabel_Performance:
3933 data->use_pcie_performance_levels = true;
3934 for (i = 0; i < ps->performance_level_count; i++) {
3935 if (data->pcie_gen_performance.max <
3936 ps->performance_levels[i].pcie_gen)
3937 data->pcie_gen_performance.max =
3938 ps->performance_levels[i].pcie_gen;
3940 if (data->pcie_gen_performance.min >
3941 ps->performance_levels[i].pcie_gen)
3942 data->pcie_gen_performance.min =
3943 ps->performance_levels[i].pcie_gen;
3945 if (data->pcie_lane_performance.max <
3946 ps->performance_levels[i].pcie_lane)
3947 data->pcie_lane_performance.max =
3948 ps->performance_levels[i].pcie_lane;
3949 if (data->pcie_lane_performance.min >
3950 ps->performance_levels[i].pcie_lane)
3951 data->pcie_lane_performance.min =
3952 ps->performance_levels[i].pcie_lane;
3955 case PP_StateUILabel_Battery:
3956 data->use_pcie_power_saving_levels = true;
3958 for (i = 0; i < ps->performance_level_count; i++) {
3959 if (data->pcie_gen_power_saving.max <
3960 ps->performance_levels[i].pcie_gen)
3961 data->pcie_gen_power_saving.max =
3962 ps->performance_levels[i].pcie_gen;
3964 if (data->pcie_gen_power_saving.min >
3965 ps->performance_levels[i].pcie_gen)
3966 data->pcie_gen_power_saving.min =
3967 ps->performance_levels[i].pcie_gen;
3969 if (data->pcie_lane_power_saving.max <
3970 ps->performance_levels[i].pcie_lane)
3971 data->pcie_lane_power_saving.max =
3972 ps->performance_levels[i].pcie_lane;
3974 if (data->pcie_lane_power_saving.min >
3975 ps->performance_levels[i].pcie_lane)
3976 data->pcie_lane_power_saving.min =
3977 ps->performance_levels[i].pcie_lane;
3988 polaris10_print_current_perforce_level(struct pp_hwmgr *hwmgr, struct seq_file *m)
3990 uint32_t sclk, mclk, activity_percent;
3992 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3994 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetSclkFrequency);
3996 sclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
3998 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetMclkFrequency);
4000 mclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
4001 seq_printf(m, "\n [ mclk ]: %u MHz\n\n [ sclk ]: %u MHz\n",
4002 mclk / 100, sclk / 100);
4004 offset = data->soft_regs_start + offsetof(SMU74_SoftRegisters, AverageGraphicsActivity);
4005 activity_percent = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, offset);
4006 activity_percent += 0x80;
4007 activity_percent >>= 8;
4009 seq_printf(m, "\n [GPU load]: %u%%\n\n", activity_percent > 100 ? 100 : activity_percent);
4011 seq_printf(m, "uvd %sabled\n", data->uvd_power_gated ? "dis" : "en");
4013 seq_printf(m, "vce %sabled\n", data->vce_power_gated ? "dis" : "en");
4016 static int polaris10_find_dpm_states_clocks_in_dpm_table(struct pp_hwmgr *hwmgr, const void *input)
4018 const struct phm_set_power_state_input *states =
4019 (const struct phm_set_power_state_input *)input;
4020 const struct polaris10_power_state *polaris10_ps =
4021 cast_const_phw_polaris10_power_state(states->pnew_state);
4022 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4023 struct polaris10_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
4024 uint32_t sclk = polaris10_ps->performance_levels
4025 [polaris10_ps->performance_level_count - 1].engine_clock;
4026 struct polaris10_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
4027 uint32_t mclk = polaris10_ps->performance_levels
4028 [polaris10_ps->performance_level_count - 1].memory_clock;
4029 struct PP_Clocks min_clocks = {0};
4031 struct cgs_display_info info = {0};
4033 data->need_update_smu7_dpm_table = 0;
4035 for (i = 0; i < sclk_table->count; i++) {
4036 if (sclk == sclk_table->dpm_levels[i].value)
4040 if (i >= sclk_table->count)
4041 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK;
4043 /* TODO: Check SCLK in DAL's minimum clocks
4044 * in case DeepSleep divider update is required.
4046 if (data->display_timing.min_clock_in_sr != min_clocks.engineClockInSR &&
4047 (min_clocks.engineClockInSR >= POLARIS10_MINIMUM_ENGINE_CLOCK ||
4048 data->display_timing.min_clock_in_sr >= POLARIS10_MINIMUM_ENGINE_CLOCK))
4049 data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_SCLK;
4052 for (i = 0; i < mclk_table->count; i++) {
4053 if (mclk == mclk_table->dpm_levels[i].value)
4057 if (i >= mclk_table->count)
4058 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_MCLK;
4060 cgs_get_active_displays_info(hwmgr->device, &info);
4062 if (data->display_timing.num_existing_displays != info.display_count)
4063 data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_MCLK;
4068 static uint16_t polaris10_get_maximum_link_speed(struct pp_hwmgr *hwmgr,
4069 const struct polaris10_power_state *polaris10_ps)
4072 uint32_t sclk, max_sclk = 0;
4073 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4074 struct polaris10_dpm_table *dpm_table = &data->dpm_table;
4076 for (i = 0; i < polaris10_ps->performance_level_count; i++) {
4077 sclk = polaris10_ps->performance_levels[i].engine_clock;
4078 if (max_sclk < sclk)
4082 for (i = 0; i < dpm_table->sclk_table.count; i++) {
4083 if (dpm_table->sclk_table.dpm_levels[i].value == max_sclk)
4084 return (uint16_t) ((i >= dpm_table->pcie_speed_table.count) ?
4085 dpm_table->pcie_speed_table.dpm_levels
4086 [dpm_table->pcie_speed_table.count - 1].value :
4087 dpm_table->pcie_speed_table.dpm_levels[i].value);
4093 static int polaris10_request_link_speed_change_before_state_change(
4094 struct pp_hwmgr *hwmgr, const void *input)
4096 const struct phm_set_power_state_input *states =
4097 (const struct phm_set_power_state_input *)input;
4098 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4099 const struct polaris10_power_state *polaris10_nps =
4100 cast_const_phw_polaris10_power_state(states->pnew_state);
4101 const struct polaris10_power_state *polaris10_cps =
4102 cast_const_phw_polaris10_power_state(states->pcurrent_state);
4104 uint16_t target_link_speed = polaris10_get_maximum_link_speed(hwmgr, polaris10_nps);
4105 uint16_t current_link_speed;
4107 if (data->force_pcie_gen == PP_PCIEGenInvalid)
4108 current_link_speed = polaris10_get_maximum_link_speed(hwmgr, polaris10_cps);
4110 current_link_speed = data->force_pcie_gen;
4112 data->force_pcie_gen = PP_PCIEGenInvalid;
4113 data->pspp_notify_required = false;
4115 if (target_link_speed > current_link_speed) {
4116 switch (target_link_speed) {
4118 if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN3, false))
4120 data->force_pcie_gen = PP_PCIEGen2;
4121 if (current_link_speed == PP_PCIEGen2)
4124 if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN2, false))
4127 data->force_pcie_gen = phm_get_current_pcie_speed(hwmgr);
4131 if (target_link_speed < current_link_speed)
4132 data->pspp_notify_required = true;
4138 static int polaris10_freeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
4140 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4142 if (0 == data->need_update_smu7_dpm_table)
4145 if ((0 == data->sclk_dpm_key_disabled) &&
4146 (data->need_update_smu7_dpm_table &
4147 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
4148 PP_ASSERT_WITH_CODE(true == polaris10_is_dpm_running(hwmgr),
4149 "Trying to freeze SCLK DPM when DPM is disabled",
4151 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
4152 PPSMC_MSG_SCLKDPM_FreezeLevel),
4153 "Failed to freeze SCLK DPM during FreezeSclkMclkDPM Function!",
4157 if ((0 == data->mclk_dpm_key_disabled) &&
4158 (data->need_update_smu7_dpm_table &
4159 DPMTABLE_OD_UPDATE_MCLK)) {
4160 PP_ASSERT_WITH_CODE(true == polaris10_is_dpm_running(hwmgr),
4161 "Trying to freeze MCLK DPM when DPM is disabled",
4163 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
4164 PPSMC_MSG_MCLKDPM_FreezeLevel),
4165 "Failed to freeze MCLK DPM during FreezeSclkMclkDPM Function!",
4172 static int polaris10_populate_and_upload_sclk_mclk_dpm_levels(
4173 struct pp_hwmgr *hwmgr, const void *input)
4176 const struct phm_set_power_state_input *states =
4177 (const struct phm_set_power_state_input *)input;
4178 const struct polaris10_power_state *polaris10_ps =
4179 cast_const_phw_polaris10_power_state(states->pnew_state);
4180 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4181 uint32_t sclk = polaris10_ps->performance_levels
4182 [polaris10_ps->performance_level_count - 1].engine_clock;
4183 uint32_t mclk = polaris10_ps->performance_levels
4184 [polaris10_ps->performance_level_count - 1].memory_clock;
4185 struct polaris10_dpm_table *dpm_table = &data->dpm_table;
4187 struct polaris10_dpm_table *golden_dpm_table = &data->golden_dpm_table;
4188 uint32_t dpm_count, clock_percent;
4191 if (0 == data->need_update_smu7_dpm_table)
4194 if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_SCLK) {
4195 dpm_table->sclk_table.dpm_levels
4196 [dpm_table->sclk_table.count - 1].value = sclk;
4198 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinACSupport) ||
4199 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinDCSupport)) {
4200 /* Need to do calculation based on the golden DPM table
4201 * as the Heatmap GPU Clock axis is also based on the default values
4203 PP_ASSERT_WITH_CODE(
4204 (golden_dpm_table->sclk_table.dpm_levels
4205 [golden_dpm_table->sclk_table.count - 1].value != 0),
4208 dpm_count = dpm_table->sclk_table.count < 2 ? 0 : dpm_table->sclk_table.count - 2;
4210 for (i = dpm_count; i > 1; i--) {
4211 if (sclk > golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value) {
4214 - golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value
4216 / golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value;
4218 dpm_table->sclk_table.dpm_levels[i].value =
4219 golden_dpm_table->sclk_table.dpm_levels[i].value +
4220 (golden_dpm_table->sclk_table.dpm_levels[i].value *
4223 } else if (golden_dpm_table->sclk_table.dpm_levels[dpm_table->sclk_table.count-1].value > sclk) {
4225 ((golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count - 1].value
4227 / golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value;
4229 dpm_table->sclk_table.dpm_levels[i].value =
4230 golden_dpm_table->sclk_table.dpm_levels[i].value -
4231 (golden_dpm_table->sclk_table.dpm_levels[i].value *
4232 clock_percent) / 100;
4234 dpm_table->sclk_table.dpm_levels[i].value =
4235 golden_dpm_table->sclk_table.dpm_levels[i].value;
4240 if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK) {
4241 dpm_table->mclk_table.dpm_levels
4242 [dpm_table->mclk_table.count - 1].value = mclk;
4244 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinACSupport) ||
4245 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinDCSupport)) {
4247 PP_ASSERT_WITH_CODE(
4248 (golden_dpm_table->mclk_table.dpm_levels
4249 [golden_dpm_table->mclk_table.count-1].value != 0),
4252 dpm_count = dpm_table->mclk_table.count < 2 ? 0 : dpm_table->mclk_table.count - 2;
4253 for (i = dpm_count; i > 1; i--) {
4254 if (golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value < mclk) {
4255 clock_percent = ((mclk -
4256 golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value) * 100)
4257 / golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value;
4259 dpm_table->mclk_table.dpm_levels[i].value =
4260 golden_dpm_table->mclk_table.dpm_levels[i].value +
4261 (golden_dpm_table->mclk_table.dpm_levels[i].value *
4262 clock_percent) / 100;
4264 } else if (golden_dpm_table->mclk_table.dpm_levels[dpm_table->mclk_table.count-1].value > mclk) {
4266 (golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value - mclk)
4268 / golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value;
4270 dpm_table->mclk_table.dpm_levels[i].value =
4271 golden_dpm_table->mclk_table.dpm_levels[i].value -
4272 (golden_dpm_table->mclk_table.dpm_levels[i].value *
4273 clock_percent) / 100;
4275 dpm_table->mclk_table.dpm_levels[i].value =
4276 golden_dpm_table->mclk_table.dpm_levels[i].value;
4281 if (data->need_update_smu7_dpm_table &
4282 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK)) {
4283 result = polaris10_populate_all_graphic_levels(hwmgr);
4284 PP_ASSERT_WITH_CODE((0 == result),
4285 "Failed to populate SCLK during PopulateNewDPMClocksStates Function!",
4289 if (data->need_update_smu7_dpm_table &
4290 (DPMTABLE_OD_UPDATE_MCLK + DPMTABLE_UPDATE_MCLK)) {
4291 /*populate MCLK dpm table to SMU7 */
4292 result = polaris10_populate_all_memory_levels(hwmgr);
4293 PP_ASSERT_WITH_CODE((0 == result),
4294 "Failed to populate MCLK during PopulateNewDPMClocksStates Function!",
4301 static int polaris10_trim_single_dpm_states(struct pp_hwmgr *hwmgr,
4302 struct polaris10_single_dpm_table *dpm_table,
4303 uint32_t low_limit, uint32_t high_limit)
4307 for (i = 0; i < dpm_table->count; i++) {
4308 if ((dpm_table->dpm_levels[i].value < low_limit)
4309 || (dpm_table->dpm_levels[i].value > high_limit))
4310 dpm_table->dpm_levels[i].enabled = false;
4312 dpm_table->dpm_levels[i].enabled = true;
4318 static int polaris10_trim_dpm_states(struct pp_hwmgr *hwmgr,
4319 const struct polaris10_power_state *polaris10_ps)
4322 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4323 uint32_t high_limit_count;
4325 PP_ASSERT_WITH_CODE((polaris10_ps->performance_level_count >= 1),
4326 "power state did not have any performance level",
4329 high_limit_count = (1 == polaris10_ps->performance_level_count) ? 0 : 1;
4331 polaris10_trim_single_dpm_states(hwmgr,
4332 &(data->dpm_table.sclk_table),
4333 polaris10_ps->performance_levels[0].engine_clock,
4334 polaris10_ps->performance_levels[high_limit_count].engine_clock);
4336 polaris10_trim_single_dpm_states(hwmgr,
4337 &(data->dpm_table.mclk_table),
4338 polaris10_ps->performance_levels[0].memory_clock,
4339 polaris10_ps->performance_levels[high_limit_count].memory_clock);
4344 static int polaris10_generate_dpm_level_enable_mask(
4345 struct pp_hwmgr *hwmgr, const void *input)
4348 const struct phm_set_power_state_input *states =
4349 (const struct phm_set_power_state_input *)input;
4350 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4351 const struct polaris10_power_state *polaris10_ps =
4352 cast_const_phw_polaris10_power_state(states->pnew_state);
4354 result = polaris10_trim_dpm_states(hwmgr, polaris10_ps);
4358 data->dpm_level_enable_mask.sclk_dpm_enable_mask =
4359 phm_get_dpm_level_enable_mask_value(&data->dpm_table.sclk_table);
4360 data->dpm_level_enable_mask.mclk_dpm_enable_mask =
4361 phm_get_dpm_level_enable_mask_value(&data->dpm_table.mclk_table);
4362 data->dpm_level_enable_mask.pcie_dpm_enable_mask =
4363 phm_get_dpm_level_enable_mask_value(&data->dpm_table.pcie_speed_table);
4368 int polaris10_enable_disable_uvd_dpm(struct pp_hwmgr *hwmgr, bool enable)
4370 return smum_send_msg_to_smc(hwmgr->smumgr, enable ?
4371 PPSMC_MSG_UVDDPM_Enable :
4372 PPSMC_MSG_UVDDPM_Disable);
4375 int polaris10_enable_disable_vce_dpm(struct pp_hwmgr *hwmgr, bool enable)
4377 return smum_send_msg_to_smc(hwmgr->smumgr, enable?
4378 PPSMC_MSG_VCEDPM_Enable :
4379 PPSMC_MSG_VCEDPM_Disable);
4382 int polaris10_enable_disable_samu_dpm(struct pp_hwmgr *hwmgr, bool enable)
4384 return smum_send_msg_to_smc(hwmgr->smumgr, enable?
4385 PPSMC_MSG_SAMUDPM_Enable :
4386 PPSMC_MSG_SAMUDPM_Disable);
4389 int polaris10_update_uvd_dpm(struct pp_hwmgr *hwmgr, bool bgate)
4391 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4392 uint32_t mm_boot_level_offset, mm_boot_level_value;
4393 struct phm_ppt_v1_information *table_info =
4394 (struct phm_ppt_v1_information *)(hwmgr->pptable);
4397 data->smc_state_table.UvdBootLevel = 0;
4398 if (table_info->mm_dep_table->count > 0)
4399 data->smc_state_table.UvdBootLevel =
4400 (uint8_t) (table_info->mm_dep_table->count - 1);
4401 mm_boot_level_offset = data->dpm_table_start +
4402 offsetof(SMU74_Discrete_DpmTable, UvdBootLevel);
4403 mm_boot_level_offset /= 4;
4404 mm_boot_level_offset *= 4;
4405 mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
4406 CGS_IND_REG__SMC, mm_boot_level_offset);
4407 mm_boot_level_value &= 0x00FFFFFF;
4408 mm_boot_level_value |= data->smc_state_table.UvdBootLevel << 24;
4409 cgs_write_ind_register(hwmgr->device,
4410 CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
4412 if (!phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4413 PHM_PlatformCaps_UVDDPM) ||
4414 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4415 PHM_PlatformCaps_StablePState))
4416 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4417 PPSMC_MSG_UVDDPM_SetEnabledMask,
4418 (uint32_t)(1 << data->smc_state_table.UvdBootLevel));
4421 return polaris10_enable_disable_uvd_dpm(hwmgr, !bgate);
4424 static int polaris10_update_vce_dpm(struct pp_hwmgr *hwmgr, const void *input)
4426 const struct phm_set_power_state_input *states =
4427 (const struct phm_set_power_state_input *)input;
4428 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4429 const struct polaris10_power_state *polaris10_nps =
4430 cast_const_phw_polaris10_power_state(states->pnew_state);
4431 const struct polaris10_power_state *polaris10_cps =
4432 cast_const_phw_polaris10_power_state(states->pcurrent_state);
4434 uint32_t mm_boot_level_offset, mm_boot_level_value;
4435 struct phm_ppt_v1_information *table_info =
4436 (struct phm_ppt_v1_information *)(hwmgr->pptable);
4438 if (polaris10_nps->vce_clks.evclk > 0 &&
4439 (polaris10_cps == NULL || polaris10_cps->vce_clks.evclk == 0)) {
4441 data->smc_state_table.VceBootLevel =
4442 (uint8_t) (table_info->mm_dep_table->count - 1);
4444 mm_boot_level_offset = data->dpm_table_start +
4445 offsetof(SMU74_Discrete_DpmTable, VceBootLevel);
4446 mm_boot_level_offset /= 4;
4447 mm_boot_level_offset *= 4;
4448 mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
4449 CGS_IND_REG__SMC, mm_boot_level_offset);
4450 mm_boot_level_value &= 0xFF00FFFF;
4451 mm_boot_level_value |= data->smc_state_table.VceBootLevel << 16;
4452 cgs_write_ind_register(hwmgr->device,
4453 CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
4455 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_StablePState)) {
4456 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4457 PPSMC_MSG_VCEDPM_SetEnabledMask,
4458 (uint32_t)1 << data->smc_state_table.VceBootLevel);
4460 polaris10_enable_disable_vce_dpm(hwmgr, true);
4461 } else if (polaris10_nps->vce_clks.evclk == 0 &&
4462 polaris10_cps != NULL &&
4463 polaris10_cps->vce_clks.evclk > 0)
4464 polaris10_enable_disable_vce_dpm(hwmgr, false);
4470 int polaris10_update_samu_dpm(struct pp_hwmgr *hwmgr, bool bgate)
4472 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4473 uint32_t mm_boot_level_offset, mm_boot_level_value;
4476 data->smc_state_table.SamuBootLevel = 0;
4477 mm_boot_level_offset = data->dpm_table_start +
4478 offsetof(SMU74_Discrete_DpmTable, SamuBootLevel);
4479 mm_boot_level_offset /= 4;
4480 mm_boot_level_offset *= 4;
4481 mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
4482 CGS_IND_REG__SMC, mm_boot_level_offset);
4483 mm_boot_level_value &= 0xFFFFFF00;
4484 mm_boot_level_value |= data->smc_state_table.SamuBootLevel << 0;
4485 cgs_write_ind_register(hwmgr->device,
4486 CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
4488 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4489 PHM_PlatformCaps_StablePState))
4490 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4491 PPSMC_MSG_SAMUDPM_SetEnabledMask,
4492 (uint32_t)(1 << data->smc_state_table.SamuBootLevel));
4495 return polaris10_enable_disable_samu_dpm(hwmgr, !bgate);
4498 static int polaris10_update_sclk_threshold(struct pp_hwmgr *hwmgr)
4500 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4503 uint32_t low_sclk_interrupt_threshold = 0;
4505 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4506 PHM_PlatformCaps_SclkThrottleLowNotification)
4507 && (hwmgr->gfx_arbiter.sclk_threshold !=
4508 data->low_sclk_interrupt_threshold)) {
4509 data->low_sclk_interrupt_threshold =
4510 hwmgr->gfx_arbiter.sclk_threshold;
4511 low_sclk_interrupt_threshold =
4512 data->low_sclk_interrupt_threshold;
4514 CONVERT_FROM_HOST_TO_SMC_UL(low_sclk_interrupt_threshold);
4516 result = polaris10_copy_bytes_to_smc(
4518 data->dpm_table_start +
4519 offsetof(SMU74_Discrete_DpmTable,
4520 LowSclkInterruptThreshold),
4521 (uint8_t *)&low_sclk_interrupt_threshold,
4529 static int polaris10_program_mem_timing_parameters(struct pp_hwmgr *hwmgr)
4531 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4533 if (data->need_update_smu7_dpm_table &
4534 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_OD_UPDATE_MCLK))
4535 return polaris10_program_memory_timing_parameters(hwmgr);
4540 static int polaris10_unfreeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
4542 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4544 if (0 == data->need_update_smu7_dpm_table)
4547 if ((0 == data->sclk_dpm_key_disabled) &&
4548 (data->need_update_smu7_dpm_table &
4549 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
4551 PP_ASSERT_WITH_CODE(true == polaris10_is_dpm_running(hwmgr),
4552 "Trying to Unfreeze SCLK DPM when DPM is disabled",
4554 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
4555 PPSMC_MSG_SCLKDPM_UnfreezeLevel),
4556 "Failed to unfreeze SCLK DPM during UnFreezeSclkMclkDPM Function!",
4560 if ((0 == data->mclk_dpm_key_disabled) &&
4561 (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) {
4563 PP_ASSERT_WITH_CODE(true == polaris10_is_dpm_running(hwmgr),
4564 "Trying to Unfreeze MCLK DPM when DPM is disabled",
4566 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
4567 PPSMC_MSG_SCLKDPM_UnfreezeLevel),
4568 "Failed to unfreeze MCLK DPM during UnFreezeSclkMclkDPM Function!",
4572 data->need_update_smu7_dpm_table = 0;
4577 static int polaris10_notify_link_speed_change_after_state_change(
4578 struct pp_hwmgr *hwmgr, const void *input)
4580 const struct phm_set_power_state_input *states =
4581 (const struct phm_set_power_state_input *)input;
4582 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4583 const struct polaris10_power_state *polaris10_ps =
4584 cast_const_phw_polaris10_power_state(states->pnew_state);
4585 uint16_t target_link_speed = polaris10_get_maximum_link_speed(hwmgr, polaris10_ps);
4588 if (data->pspp_notify_required) {
4589 if (target_link_speed == PP_PCIEGen3)
4590 request = PCIE_PERF_REQ_GEN3;
4591 else if (target_link_speed == PP_PCIEGen2)
4592 request = PCIE_PERF_REQ_GEN2;
4594 request = PCIE_PERF_REQ_GEN1;
4596 if (request == PCIE_PERF_REQ_GEN1 &&
4597 phm_get_current_pcie_speed(hwmgr) > 0)
4600 if (acpi_pcie_perf_request(hwmgr->device, request, false)) {
4601 if (PP_PCIEGen2 == target_link_speed)
4602 printk("PSPP request to switch to Gen2 from Gen3 Failed!");
4604 printk("PSPP request to switch to Gen1 from Gen2 Failed!");
4611 static int polaris10_notify_smc_display(struct pp_hwmgr *hwmgr)
4613 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4615 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4616 (PPSMC_Msg)PPSMC_MSG_SetVBITimeout, data->frame_time_x2);
4617 return (smum_send_msg_to_smc(hwmgr->smumgr, (PPSMC_Msg)PPSMC_HasDisplay) == 0) ? 0 : -EINVAL;
4620 static int polaris10_set_power_state_tasks(struct pp_hwmgr *hwmgr, const void *input)
4622 int tmp_result, result = 0;
4623 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4625 tmp_result = polaris10_find_dpm_states_clocks_in_dpm_table(hwmgr, input);
4626 PP_ASSERT_WITH_CODE((0 == tmp_result),
4627 "Failed to find DPM states clocks in DPM table!",
4628 result = tmp_result);
4630 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4631 PHM_PlatformCaps_PCIEPerformanceRequest)) {
4633 polaris10_request_link_speed_change_before_state_change(hwmgr, input);
4634 PP_ASSERT_WITH_CODE((0 == tmp_result),
4635 "Failed to request link speed change before state change!",
4636 result = tmp_result);
4639 tmp_result = polaris10_freeze_sclk_mclk_dpm(hwmgr);
4640 PP_ASSERT_WITH_CODE((0 == tmp_result),
4641 "Failed to freeze SCLK MCLK DPM!", result = tmp_result);
4643 tmp_result = polaris10_populate_and_upload_sclk_mclk_dpm_levels(hwmgr, input);
4644 PP_ASSERT_WITH_CODE((0 == tmp_result),
4645 "Failed to populate and upload SCLK MCLK DPM levels!",
4646 result = tmp_result);
4648 tmp_result = polaris10_generate_dpm_level_enable_mask(hwmgr, input);
4649 PP_ASSERT_WITH_CODE((0 == tmp_result),
4650 "Failed to generate DPM level enabled mask!",
4651 result = tmp_result);
4653 tmp_result = polaris10_update_vce_dpm(hwmgr, input);
4654 PP_ASSERT_WITH_CODE((0 == tmp_result),
4655 "Failed to update VCE DPM!",
4656 result = tmp_result);
4658 tmp_result = polaris10_update_sclk_threshold(hwmgr);
4659 PP_ASSERT_WITH_CODE((0 == tmp_result),
4660 "Failed to update SCLK threshold!",
4661 result = tmp_result);
4663 tmp_result = polaris10_program_mem_timing_parameters(hwmgr);
4664 PP_ASSERT_WITH_CODE((0 == tmp_result),
4665 "Failed to program memory timing parameters!",
4666 result = tmp_result);
4668 tmp_result = polaris10_notify_smc_display(hwmgr);
4669 PP_ASSERT_WITH_CODE((0 == tmp_result),
4670 "Failed to notify smc display settings!",
4671 result = tmp_result);
4673 tmp_result = polaris10_unfreeze_sclk_mclk_dpm(hwmgr);
4674 PP_ASSERT_WITH_CODE((0 == tmp_result),
4675 "Failed to unfreeze SCLK MCLK DPM!",
4676 result = tmp_result);
4678 tmp_result = polaris10_upload_dpm_level_enable_mask(hwmgr);
4679 PP_ASSERT_WITH_CODE((0 == tmp_result),
4680 "Failed to upload DPM level enabled mask!",
4681 result = tmp_result);
4683 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4684 PHM_PlatformCaps_PCIEPerformanceRequest)) {
4686 polaris10_notify_link_speed_change_after_state_change(hwmgr, input);
4687 PP_ASSERT_WITH_CODE((0 == tmp_result),
4688 "Failed to notify link speed change after state change!",
4689 result = tmp_result);
4691 data->apply_optimized_settings = false;
4695 static int polaris10_set_max_fan_pwm_output(struct pp_hwmgr *hwmgr, uint16_t us_max_fan_pwm)
4697 hwmgr->thermal_controller.
4698 advanceFanControlParameters.usMaxFanPWM = us_max_fan_pwm;
4700 if (phm_is_hw_access_blocked(hwmgr))
4703 return smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4704 PPSMC_MSG_SetFanPwmMax, us_max_fan_pwm);
4708 int polaris10_notify_smc_display_change(struct pp_hwmgr *hwmgr, bool has_display)
4710 PPSMC_Msg msg = has_display ? (PPSMC_Msg)PPSMC_HasDisplay : (PPSMC_Msg)PPSMC_NoDisplay;
4712 return (smum_send_msg_to_smc(hwmgr->smumgr, msg) == 0) ? 0 : -1;
4715 int polaris10_notify_smc_display_config_after_ps_adjustment(struct pp_hwmgr *hwmgr)
4717 uint32_t num_active_displays = 0;
4718 struct cgs_display_info info = {0};
4719 info.mode_info = NULL;
4721 cgs_get_active_displays_info(hwmgr->device, &info);
4723 num_active_displays = info.display_count;
4725 if (num_active_displays > 1) /* to do && (pHwMgr->pPECI->displayConfiguration.bMultiMonitorInSync != TRUE)) */
4726 polaris10_notify_smc_display_change(hwmgr, false);
4732 * Programs the display gap
4734 * @param hwmgr the address of the powerplay hardware manager.
4737 int polaris10_program_display_gap(struct pp_hwmgr *hwmgr)
4739 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4740 uint32_t num_active_displays = 0;
4741 uint32_t display_gap = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL);
4742 uint32_t display_gap2;
4743 uint32_t pre_vbi_time_in_us;
4744 uint32_t frame_time_in_us;
4746 uint32_t refresh_rate = 0;
4747 struct cgs_display_info info = {0};
4748 struct cgs_mode_info mode_info;
4750 info.mode_info = &mode_info;
4752 cgs_get_active_displays_info(hwmgr->device, &info);
4753 num_active_displays = info.display_count;
4755 display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL, DISP_GAP, (num_active_displays > 0) ? DISPLAY_GAP_VBLANK_OR_WM : DISPLAY_GAP_IGNORE);
4756 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL, display_gap);
4758 ref_clock = mode_info.ref_clock;
4759 refresh_rate = mode_info.refresh_rate;
4761 if (0 == refresh_rate)
4764 frame_time_in_us = 1000000 / refresh_rate;
4766 pre_vbi_time_in_us = frame_time_in_us - 200 - mode_info.vblank_time_us;
4767 data->frame_time_x2 = frame_time_in_us * 2 / 100;
4769 display_gap2 = pre_vbi_time_in_us * (ref_clock / 100);
4771 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL2, display_gap2);
4773 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, data->soft_regs_start + offsetof(SMU74_SoftRegisters, PreVBlankGap), 0x64);
4775 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, data->soft_regs_start + offsetof(SMU74_SoftRegisters, VBlankTimeout), (frame_time_in_us - pre_vbi_time_in_us));
4781 int polaris10_display_configuration_changed_task(struct pp_hwmgr *hwmgr)
4783 return polaris10_program_display_gap(hwmgr);
4787 * Set maximum target operating fan output RPM
4789 * @param hwmgr: the address of the powerplay hardware manager.
4790 * @param usMaxFanRpm: max operating fan RPM value.
4791 * @return The response that came from the SMC.
4793 static int polaris10_set_max_fan_rpm_output(struct pp_hwmgr *hwmgr, uint16_t us_max_fan_rpm)
4795 hwmgr->thermal_controller.
4796 advanceFanControlParameters.usMaxFanRPM = us_max_fan_rpm;
4798 if (phm_is_hw_access_blocked(hwmgr))
4801 return smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4802 PPSMC_MSG_SetFanRpmMax, us_max_fan_rpm);
4805 int polaris10_register_internal_thermal_interrupt(struct pp_hwmgr *hwmgr,
4806 const void *thermal_interrupt_info)
4811 bool polaris10_check_smc_update_required_for_display_configuration(struct pp_hwmgr *hwmgr)
4813 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4814 bool is_update_required = false;
4815 struct cgs_display_info info = {0, 0, NULL};
4817 cgs_get_active_displays_info(hwmgr->device, &info);
4819 if (data->display_timing.num_existing_displays != info.display_count)
4820 is_update_required = true;
4821 /* TO DO NEED TO GET DEEP SLEEP CLOCK FROM DAL
4822 if (phm_cap_enabled(hwmgr->hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep)) {
4823 cgs_get_min_clock_settings(hwmgr->device, &min_clocks);
4824 if (min_clocks.engineClockInSR != data->display_timing.minClockInSR &&
4825 (min_clocks.engineClockInSR >= POLARIS10_MINIMUM_ENGINE_CLOCK ||
4826 data->display_timing.minClockInSR >= POLARIS10_MINIMUM_ENGINE_CLOCK))
4827 is_update_required = true;
4829 return is_update_required;
4832 static inline bool polaris10_are_power_levels_equal(const struct polaris10_performance_level *pl1,
4833 const struct polaris10_performance_level *pl2)
4835 return ((pl1->memory_clock == pl2->memory_clock) &&
4836 (pl1->engine_clock == pl2->engine_clock) &&
4837 (pl1->pcie_gen == pl2->pcie_gen) &&
4838 (pl1->pcie_lane == pl2->pcie_lane));
4841 int polaris10_check_states_equal(struct pp_hwmgr *hwmgr, const struct pp_hw_power_state *pstate1, const struct pp_hw_power_state *pstate2, bool *equal)
4843 const struct polaris10_power_state *psa = cast_const_phw_polaris10_power_state(pstate1);
4844 const struct polaris10_power_state *psb = cast_const_phw_polaris10_power_state(pstate2);
4847 if (pstate1 == NULL || pstate2 == NULL || equal == NULL)
4850 /* If the two states don't even have the same number of performance levels they cannot be the same state. */
4851 if (psa->performance_level_count != psb->performance_level_count) {
4856 for (i = 0; i < psa->performance_level_count; i++) {
4857 if (!polaris10_are_power_levels_equal(&(psa->performance_levels[i]), &(psb->performance_levels[i]))) {
4858 /* If we have found even one performance level pair that is different the states are different. */
4864 /* If all performance levels are the same try to use the UVD clocks to break the tie.*/
4865 *equal = ((psa->uvd_clks.vclk == psb->uvd_clks.vclk) && (psa->uvd_clks.dclk == psb->uvd_clks.dclk));
4866 *equal &= ((psa->vce_clks.evclk == psb->vce_clks.evclk) && (psa->vce_clks.ecclk == psb->vce_clks.ecclk));
4867 *equal &= (psa->sclk_threshold == psb->sclk_threshold);
4872 int polaris10_upload_mc_firmware(struct pp_hwmgr *hwmgr)
4874 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4876 uint32_t vbios_version;
4878 /* Read MC indirect register offset 0x9F bits [3:0] to see if VBIOS has already loaded a full version of MC ucode or not.*/
4880 phm_get_mc_microcode_version(hwmgr);
4881 vbios_version = hwmgr->microcode_version_info.MC & 0xf;
4882 /* Full version of MC ucode has already been loaded. */
4883 if (vbios_version == 0) {
4884 data->need_long_memory_training = false;
4888 data->need_long_memory_training = false;
4891 * PPMCME_FirmwareDescriptorEntry *pfd = NULL;
4892 pfd = &tonga_mcmeFirmware;
4893 if (0 == PHM_READ_FIELD(hwmgr->device, MC_SEQ_SUP_CNTL, RUN))
4894 polaris10_load_mc_microcode(hwmgr, pfd->dpmThreshold,
4895 pfd->cfgArray, pfd->cfgSize, pfd->ioDebugArray,
4896 pfd->ioDebugSize, pfd->ucodeArray, pfd->ucodeSize);
4902 * Read clock related registers.
4904 * @param hwmgr the address of the powerplay hardware manager.
4907 static int polaris10_read_clock_registers(struct pp_hwmgr *hwmgr)
4909 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4911 data->clock_registers.vCG_SPLL_FUNC_CNTL = cgs_read_ind_register(hwmgr->device,
4912 CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL)
4913 & CG_SPLL_FUNC_CNTL__SPLL_BYPASS_EN_MASK;
4915 data->clock_registers.vCG_SPLL_FUNC_CNTL_2 = cgs_read_ind_register(hwmgr->device,
4916 CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_2)
4917 & CG_SPLL_FUNC_CNTL_2__SCLK_MUX_SEL_MASK;
4919 data->clock_registers.vCG_SPLL_FUNC_CNTL_4 = cgs_read_ind_register(hwmgr->device,
4920 CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_4)
4921 & CG_SPLL_FUNC_CNTL_4__SPLL_SPARE_MASK;
4927 * Find out if memory is GDDR5.
4929 * @param hwmgr the address of the powerplay hardware manager.
4932 static int polaris10_get_memory_type(struct pp_hwmgr *hwmgr)
4934 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4937 temp = cgs_read_register(hwmgr->device, mmMC_SEQ_MISC0);
4939 data->is_memory_gddr5 = (MC_SEQ_MISC0_GDDR5_VALUE ==
4940 ((temp & MC_SEQ_MISC0_GDDR5_MASK) >>
4941 MC_SEQ_MISC0_GDDR5_SHIFT));
4947 * Enables Dynamic Power Management by SMC
4949 * @param hwmgr the address of the powerplay hardware manager.
4952 static int polaris10_enable_acpi_power_management(struct pp_hwmgr *hwmgr)
4954 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
4955 GENERAL_PWRMGT, STATIC_PM_EN, 1);
4961 * Initialize PowerGating States for different engines
4963 * @param hwmgr the address of the powerplay hardware manager.
4966 static int polaris10_init_power_gate_state(struct pp_hwmgr *hwmgr)
4968 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4970 data->uvd_power_gated = false;
4971 data->vce_power_gated = false;
4972 data->samu_power_gated = false;
4977 static int polaris10_init_sclk_threshold(struct pp_hwmgr *hwmgr)
4979 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4980 data->low_sclk_interrupt_threshold = 0;
4985 int polaris10_setup_asic_task(struct pp_hwmgr *hwmgr)
4987 int tmp_result, result = 0;
4989 polaris10_upload_mc_firmware(hwmgr);
4991 tmp_result = polaris10_read_clock_registers(hwmgr);
4992 PP_ASSERT_WITH_CODE((0 == tmp_result),
4993 "Failed to read clock registers!", result = tmp_result);
4995 tmp_result = polaris10_get_memory_type(hwmgr);
4996 PP_ASSERT_WITH_CODE((0 == tmp_result),
4997 "Failed to get memory type!", result = tmp_result);
4999 tmp_result = polaris10_enable_acpi_power_management(hwmgr);
5000 PP_ASSERT_WITH_CODE((0 == tmp_result),
5001 "Failed to enable ACPI power management!", result = tmp_result);
5003 tmp_result = polaris10_init_power_gate_state(hwmgr);
5004 PP_ASSERT_WITH_CODE((0 == tmp_result),
5005 "Failed to init power gate state!", result = tmp_result);
5007 tmp_result = phm_get_mc_microcode_version(hwmgr);
5008 PP_ASSERT_WITH_CODE((0 == tmp_result),
5009 "Failed to get MC microcode version!", result = tmp_result);
5011 tmp_result = polaris10_init_sclk_threshold(hwmgr);
5012 PP_ASSERT_WITH_CODE((0 == tmp_result),
5013 "Failed to init sclk threshold!", result = tmp_result);
5018 static int polaris10_force_clock_level(struct pp_hwmgr *hwmgr,
5019 enum pp_clock_type type, uint32_t mask)
5021 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
5023 if (hwmgr->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL)
5028 if (!data->sclk_dpm_key_disabled)
5029 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
5030 PPSMC_MSG_SCLKDPM_SetEnabledMask,
5031 data->dpm_level_enable_mask.sclk_dpm_enable_mask & mask);
5034 if (!data->mclk_dpm_key_disabled)
5035 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
5036 PPSMC_MSG_MCLKDPM_SetEnabledMask,
5037 data->dpm_level_enable_mask.mclk_dpm_enable_mask & mask);
5041 uint32_t tmp = mask & data->dpm_level_enable_mask.pcie_dpm_enable_mask;
5047 if (!data->pcie_dpm_key_disabled)
5048 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
5049 PPSMC_MSG_PCIeDPM_ForceLevel,
5060 static uint16_t polaris10_get_current_pcie_speed(struct pp_hwmgr *hwmgr)
5062 uint32_t speedCntl = 0;
5064 /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
5065 speedCntl = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__PCIE,
5066 ixPCIE_LC_SPEED_CNTL);
5067 return((uint16_t)PHM_GET_FIELD(speedCntl,
5068 PCIE_LC_SPEED_CNTL, LC_CURRENT_DATA_RATE));
5071 static int polaris10_print_clock_levels(struct pp_hwmgr *hwmgr,
5072 enum pp_clock_type type, char *buf)
5074 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
5075 struct polaris10_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
5076 struct polaris10_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
5077 struct polaris10_single_dpm_table *pcie_table = &(data->dpm_table.pcie_speed_table);
5078 int i, now, size = 0;
5079 uint32_t clock, pcie_speed;
5083 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetSclkFrequency);
5084 clock = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
5086 for (i = 0; i < sclk_table->count; i++) {
5087 if (clock > sclk_table->dpm_levels[i].value)
5093 for (i = 0; i < sclk_table->count; i++)
5094 size += sprintf(buf + size, "%d: %uMhz %s\n",
5095 i, sclk_table->dpm_levels[i].value / 100,
5096 (i == now) ? "*" : "");
5099 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetMclkFrequency);
5100 clock = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
5102 for (i = 0; i < mclk_table->count; i++) {
5103 if (clock > mclk_table->dpm_levels[i].value)
5109 for (i = 0; i < mclk_table->count; i++)
5110 size += sprintf(buf + size, "%d: %uMhz %s\n",
5111 i, mclk_table->dpm_levels[i].value / 100,
5112 (i == now) ? "*" : "");
5115 pcie_speed = polaris10_get_current_pcie_speed(hwmgr);
5116 for (i = 0; i < pcie_table->count; i++) {
5117 if (pcie_speed != pcie_table->dpm_levels[i].value)
5123 for (i = 0; i < pcie_table->count; i++)
5124 size += sprintf(buf + size, "%d: %s %s\n", i,
5125 (pcie_table->dpm_levels[i].value == 0) ? "2.5GB, x8" :
5126 (pcie_table->dpm_levels[i].value == 1) ? "5.0GB, x16" :
5127 (pcie_table->dpm_levels[i].value == 2) ? "8.0GB, x16" : "",
5128 (i == now) ? "*" : "");
5136 static int polaris10_set_fan_control_mode(struct pp_hwmgr *hwmgr, uint32_t mode)
5139 /* stop auto-manage */
5140 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
5141 PHM_PlatformCaps_MicrocodeFanControl))
5142 polaris10_fan_ctrl_stop_smc_fan_control(hwmgr);
5143 polaris10_fan_ctrl_set_static_mode(hwmgr, mode);
5145 /* restart auto-manage */
5146 polaris10_fan_ctrl_reset_fan_speed_to_default(hwmgr);
5151 static int polaris10_get_fan_control_mode(struct pp_hwmgr *hwmgr)
5153 if (hwmgr->fan_ctrl_is_in_default_mode)
5154 return hwmgr->fan_ctrl_default_mode;
5156 return PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
5157 CG_FDO_CTRL2, FDO_PWM_MODE);
5160 static int polaris10_get_sclk_od(struct pp_hwmgr *hwmgr)
5162 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
5163 struct polaris10_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
5164 struct polaris10_single_dpm_table *golden_sclk_table =
5165 &(data->golden_dpm_table.sclk_table);
5168 value = (sclk_table->dpm_levels[sclk_table->count - 1].value -
5169 golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value) *
5171 golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value;
5176 static int polaris10_set_sclk_od(struct pp_hwmgr *hwmgr, uint32_t value)
5178 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
5179 struct polaris10_single_dpm_table *golden_sclk_table =
5180 &(data->golden_dpm_table.sclk_table);
5181 struct pp_power_state *ps;
5182 struct polaris10_power_state *polaris10_ps;
5187 ps = hwmgr->request_ps;
5192 polaris10_ps = cast_phw_polaris10_power_state(&ps->hardware);
5194 polaris10_ps->performance_levels[polaris10_ps->performance_level_count - 1].engine_clock =
5195 golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value *
5197 golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value;
5202 static int polaris10_get_mclk_od(struct pp_hwmgr *hwmgr)
5204 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
5205 struct polaris10_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
5206 struct polaris10_single_dpm_table *golden_mclk_table =
5207 &(data->golden_dpm_table.mclk_table);
5210 value = (mclk_table->dpm_levels[mclk_table->count - 1].value -
5211 golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value) *
5213 golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value;
5218 static int polaris10_set_mclk_od(struct pp_hwmgr *hwmgr, uint32_t value)
5220 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
5221 struct polaris10_single_dpm_table *golden_mclk_table =
5222 &(data->golden_dpm_table.mclk_table);
5223 struct pp_power_state *ps;
5224 struct polaris10_power_state *polaris10_ps;
5229 ps = hwmgr->request_ps;
5234 polaris10_ps = cast_phw_polaris10_power_state(&ps->hardware);
5236 polaris10_ps->performance_levels[polaris10_ps->performance_level_count - 1].memory_clock =
5237 golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value *
5239 golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value;
5243 static const struct pp_hwmgr_func polaris10_hwmgr_funcs = {
5244 .backend_init = &polaris10_hwmgr_backend_init,
5245 .backend_fini = &polaris10_hwmgr_backend_fini,
5246 .asic_setup = &polaris10_setup_asic_task,
5247 .dynamic_state_management_enable = &polaris10_enable_dpm_tasks,
5248 .apply_state_adjust_rules = polaris10_apply_state_adjust_rules,
5249 .force_dpm_level = &polaris10_force_dpm_level,
5250 .power_state_set = polaris10_set_power_state_tasks,
5251 .get_power_state_size = polaris10_get_power_state_size,
5252 .get_mclk = polaris10_dpm_get_mclk,
5253 .get_sclk = polaris10_dpm_get_sclk,
5254 .patch_boot_state = polaris10_dpm_patch_boot_state,
5255 .get_pp_table_entry = polaris10_get_pp_table_entry,
5256 .get_num_of_pp_table_entries = tonga_get_number_of_powerplay_table_entries,
5257 .print_current_perforce_level = polaris10_print_current_perforce_level,
5258 .powerdown_uvd = polaris10_phm_powerdown_uvd,
5259 .powergate_uvd = polaris10_phm_powergate_uvd,
5260 .powergate_vce = polaris10_phm_powergate_vce,
5261 .disable_clock_power_gating = polaris10_phm_disable_clock_power_gating,
5262 .update_clock_gatings = polaris10_phm_update_clock_gatings,
5263 .notify_smc_display_config_after_ps_adjustment = polaris10_notify_smc_display_config_after_ps_adjustment,
5264 .display_config_changed = polaris10_display_configuration_changed_task,
5265 .set_max_fan_pwm_output = polaris10_set_max_fan_pwm_output,
5266 .set_max_fan_rpm_output = polaris10_set_max_fan_rpm_output,
5267 .get_temperature = polaris10_thermal_get_temperature,
5268 .stop_thermal_controller = polaris10_thermal_stop_thermal_controller,
5269 .get_fan_speed_info = polaris10_fan_ctrl_get_fan_speed_info,
5270 .get_fan_speed_percent = polaris10_fan_ctrl_get_fan_speed_percent,
5271 .set_fan_speed_percent = polaris10_fan_ctrl_set_fan_speed_percent,
5272 .reset_fan_speed_to_default = polaris10_fan_ctrl_reset_fan_speed_to_default,
5273 .get_fan_speed_rpm = polaris10_fan_ctrl_get_fan_speed_rpm,
5274 .set_fan_speed_rpm = polaris10_fan_ctrl_set_fan_speed_rpm,
5275 .uninitialize_thermal_controller = polaris10_thermal_ctrl_uninitialize_thermal_controller,
5276 .register_internal_thermal_interrupt = polaris10_register_internal_thermal_interrupt,
5277 .check_smc_update_required_for_display_configuration = polaris10_check_smc_update_required_for_display_configuration,
5278 .check_states_equal = polaris10_check_states_equal,
5279 .set_fan_control_mode = polaris10_set_fan_control_mode,
5280 .get_fan_control_mode = polaris10_get_fan_control_mode,
5281 .force_clock_level = polaris10_force_clock_level,
5282 .print_clock_levels = polaris10_print_clock_levels,
5283 .enable_per_cu_power_gating = polaris10_phm_enable_per_cu_power_gating,
5284 .get_sclk_od = polaris10_get_sclk_od,
5285 .set_sclk_od = polaris10_set_sclk_od,
5286 .get_mclk_od = polaris10_get_mclk_od,
5287 .set_mclk_od = polaris10_set_mclk_od,
5290 int polaris10_hwmgr_init(struct pp_hwmgr *hwmgr)
5292 hwmgr->hwmgr_func = &polaris10_hwmgr_funcs;
5293 hwmgr->pptable_func = &tonga_pptable_funcs;
5294 pp_polaris10_thermal_initialize(hwmgr);