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 uint16_t polaris10_clock_stretcher_lookup_table[2][4] = { {600, 1050, 3, 0},
105 /* [FF, SS] type, [] 4 voltage ranges, and [Floor Freq, Boundary Freq, VID min , VID max] */
106 uint32_t polaris10_clock_stretcher_ddt_table[2][4][4] = { { {265, 529, 120, 128}, {325, 650, 96, 119}, {430, 860, 32, 95}, {0, 0, 0, 31} },
107 { {275, 550, 104, 112}, {319, 638, 96, 103}, {360, 720, 64, 95}, {384, 768, 32, 63} } };
109 /* [Use_For_Low_freq] value, [0%, 5%, 10%, 7.14%, 14.28%, 20%] (coming from PWR_CKS_CNTL.stretch_amount reg spec) */
110 uint8_t polaris10_clock_stretch_amount_conversion[2][6] = { {0, 1, 3, 2, 4, 5},
111 {0, 2, 4, 5, 6, 5} };
113 /** Values for the CG_THERMAL_CTRL::DPM_EVENT_SRC field. */
115 DPM_EVENT_SRC_ANALOG = 0,
116 DPM_EVENT_SRC_EXTERNAL = 1,
117 DPM_EVENT_SRC_DIGITAL = 2,
118 DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
119 DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL = 4
122 const unsigned long PhwPolaris10_Magic = (unsigned long)(PHM_VIslands_Magic);
124 struct polaris10_power_state *cast_phw_polaris10_power_state(
125 struct pp_hw_power_state *hw_ps)
127 PP_ASSERT_WITH_CODE((PhwPolaris10_Magic == hw_ps->magic),
128 "Invalid Powerstate Type!",
131 return (struct polaris10_power_state *)hw_ps;
134 const struct polaris10_power_state *cast_const_phw_polaris10_power_state(
135 const struct pp_hw_power_state *hw_ps)
137 PP_ASSERT_WITH_CODE((PhwPolaris10_Magic == hw_ps->magic),
138 "Invalid Powerstate Type!",
141 return (const struct polaris10_power_state *)hw_ps;
144 static bool polaris10_is_dpm_running(struct pp_hwmgr *hwmgr)
146 return (1 == PHM_READ_INDIRECT_FIELD(hwmgr->device,
147 CGS_IND_REG__SMC, FEATURE_STATUS, VOLTAGE_CONTROLLER_ON))
152 * Find the MC microcode version and store it in the HwMgr struct
154 * @param hwmgr the address of the powerplay hardware manager.
157 int phm_get_mc_microcode_version (struct pp_hwmgr *hwmgr)
159 cgs_write_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_INDEX, 0x9F);
161 hwmgr->microcode_version_info.MC = cgs_read_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_DATA);
166 uint16_t phm_get_current_pcie_speed(struct pp_hwmgr *hwmgr)
168 uint32_t speedCntl = 0;
170 /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
171 speedCntl = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__PCIE,
172 ixPCIE_LC_SPEED_CNTL);
173 return((uint16_t)PHM_GET_FIELD(speedCntl,
174 PCIE_LC_SPEED_CNTL, LC_CURRENT_DATA_RATE));
177 int phm_get_current_pcie_lane_number(struct pp_hwmgr *hwmgr)
181 /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
182 link_width = PHM_READ_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE,
183 PCIE_LC_LINK_WIDTH_CNTL, LC_LINK_WIDTH_RD);
185 PP_ASSERT_WITH_CODE((7 >= link_width),
186 "Invalid PCIe lane width!", return 0);
188 return decode_pcie_lane_width(link_width);
191 void phm_apply_dal_min_voltage_request(struct pp_hwmgr *hwmgr)
193 struct phm_ppt_v1_information *table_info =
194 (struct phm_ppt_v1_information *)hwmgr->pptable;
195 struct phm_clock_voltage_dependency_table *table =
196 table_info->vddc_dep_on_dal_pwrl;
197 struct phm_ppt_v1_clock_voltage_dependency_table *vddc_table;
198 enum PP_DAL_POWERLEVEL dal_power_level = hwmgr->dal_power_level;
199 uint32_t req_vddc = 0, req_volt, i;
201 if (!table && !(dal_power_level >= PP_DAL_POWERLEVEL_ULTRALOW &&
202 dal_power_level <= PP_DAL_POWERLEVEL_PERFORMANCE))
205 for (i = 0; i < table->count; i++) {
206 if (dal_power_level == table->entries[i].clk) {
207 req_vddc = table->entries[i].v;
212 vddc_table = table_info->vdd_dep_on_sclk;
213 for (i = 0; i < vddc_table->count; i++) {
214 if (req_vddc <= vddc_table->entries[i].vddc) {
215 req_volt = (((uint32_t)vddc_table->entries[i].vddc) * VOLTAGE_SCALE)
217 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
218 PPSMC_MSG_VddC_Request, req_volt);
222 printk(KERN_ERR "DAL requested level can not"
223 " found a available voltage in VDDC DPM Table \n");
227 * Enable voltage control
229 * @param pHwMgr the address of the powerplay hardware manager.
230 * @return always PP_Result_OK
232 int polaris10_enable_smc_voltage_controller(struct pp_hwmgr *hwmgr)
235 (hwmgr->smumgr->smumgr_funcs->send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_Voltage_Cntl_Enable) == 0),
236 "Failed to enable voltage DPM during DPM Start Function!",
244 * Checks if we want to support voltage control
246 * @param hwmgr the address of the powerplay hardware manager.
248 static bool polaris10_voltage_control(const struct pp_hwmgr *hwmgr)
250 const struct polaris10_hwmgr *data =
251 (const struct polaris10_hwmgr *)(hwmgr->backend);
253 return (POLARIS10_VOLTAGE_CONTROL_NONE != data->voltage_control);
257 * Enable voltage control
259 * @param hwmgr the address of the powerplay hardware manager.
262 static int polaris10_enable_voltage_control(struct pp_hwmgr *hwmgr)
264 /* enable voltage control */
265 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
266 GENERAL_PWRMGT, VOLT_PWRMGT_EN, 1);
272 * Create Voltage Tables.
274 * @param hwmgr the address of the powerplay hardware manager.
277 static int polaris10_construct_voltage_tables(struct pp_hwmgr *hwmgr)
279 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
280 struct phm_ppt_v1_information *table_info =
281 (struct phm_ppt_v1_information *)hwmgr->pptable;
284 if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
285 result = atomctrl_get_voltage_table_v3(hwmgr,
286 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT,
287 &(data->mvdd_voltage_table));
288 PP_ASSERT_WITH_CODE((0 == result),
289 "Failed to retrieve MVDD table.",
291 } else if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) {
292 result = phm_get_svi2_mvdd_voltage_table(&(data->mvdd_voltage_table),
293 table_info->vdd_dep_on_mclk);
294 PP_ASSERT_WITH_CODE((0 == result),
295 "Failed to retrieve SVI2 MVDD table from dependancy table.",
299 if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
300 result = atomctrl_get_voltage_table_v3(hwmgr,
301 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT,
302 &(data->vddci_voltage_table));
303 PP_ASSERT_WITH_CODE((0 == result),
304 "Failed to retrieve VDDCI table.",
306 } else if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) {
307 result = phm_get_svi2_vddci_voltage_table(&(data->vddci_voltage_table),
308 table_info->vdd_dep_on_mclk);
309 PP_ASSERT_WITH_CODE((0 == result),
310 "Failed to retrieve SVI2 VDDCI table from dependancy table.",
314 if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
315 result = phm_get_svi2_vdd_voltage_table(&(data->vddc_voltage_table),
316 table_info->vddc_lookup_table);
317 PP_ASSERT_WITH_CODE((0 == result),
318 "Failed to retrieve SVI2 VDDC table from lookup table.",
323 (data->vddc_voltage_table.count <= (SMU74_MAX_LEVELS_VDDC)),
324 "Too many voltage values for VDDC. Trimming to fit state table.",
325 phm_trim_voltage_table_to_fit_state_table(SMU74_MAX_LEVELS_VDDC,
326 &(data->vddc_voltage_table)));
329 (data->vddci_voltage_table.count <= (SMU74_MAX_LEVELS_VDDCI)),
330 "Too many voltage values for VDDCI. Trimming to fit state table.",
331 phm_trim_voltage_table_to_fit_state_table(SMU74_MAX_LEVELS_VDDCI,
332 &(data->vddci_voltage_table)));
335 (data->mvdd_voltage_table.count <= (SMU74_MAX_LEVELS_MVDD)),
336 "Too many voltage values for MVDD. Trimming to fit state table.",
337 phm_trim_voltage_table_to_fit_state_table(SMU74_MAX_LEVELS_MVDD,
338 &(data->mvdd_voltage_table)));
344 * Programs static screed detection parameters
346 * @param hwmgr the address of the powerplay hardware manager.
349 static int polaris10_program_static_screen_threshold_parameters(
350 struct pp_hwmgr *hwmgr)
352 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
354 /* Set static screen threshold unit */
355 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
356 CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD_UNIT,
357 data->static_screen_threshold_unit);
358 /* Set static screen threshold */
359 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
360 CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD,
361 data->static_screen_threshold);
367 * Setup display gap for glitch free memory clock switching.
369 * @param hwmgr the address of the powerplay hardware manager.
372 static int polaris10_enable_display_gap(struct pp_hwmgr *hwmgr)
374 uint32_t display_gap =
375 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
376 ixCG_DISPLAY_GAP_CNTL);
378 display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL,
379 DISP_GAP, DISPLAY_GAP_IGNORE);
381 display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL,
382 DISP_GAP_MCHG, DISPLAY_GAP_VBLANK);
384 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
385 ixCG_DISPLAY_GAP_CNTL, display_gap);
391 * Programs activity state transition voting clients
393 * @param hwmgr the address of the powerplay hardware manager.
396 static int polaris10_program_voting_clients(struct pp_hwmgr *hwmgr)
398 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
400 /* Clear reset for voting clients before enabling DPM */
401 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
402 SCLK_PWRMGT_CNTL, RESET_SCLK_CNT, 0);
403 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
404 SCLK_PWRMGT_CNTL, RESET_BUSY_CNT, 0);
406 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
407 ixCG_FREQ_TRAN_VOTING_0, data->voting_rights_clients0);
408 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
409 ixCG_FREQ_TRAN_VOTING_1, data->voting_rights_clients1);
410 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
411 ixCG_FREQ_TRAN_VOTING_2, data->voting_rights_clients2);
412 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
413 ixCG_FREQ_TRAN_VOTING_3, data->voting_rights_clients3);
414 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
415 ixCG_FREQ_TRAN_VOTING_4, data->voting_rights_clients4);
416 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
417 ixCG_FREQ_TRAN_VOTING_5, data->voting_rights_clients5);
418 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
419 ixCG_FREQ_TRAN_VOTING_6, data->voting_rights_clients6);
420 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
421 ixCG_FREQ_TRAN_VOTING_7, data->voting_rights_clients7);
427 * Get the location of various tables inside the FW image.
429 * @param hwmgr the address of the powerplay hardware manager.
432 static int polaris10_process_firmware_header(struct pp_hwmgr *hwmgr)
434 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
435 struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smumgr->backend);
440 result = polaris10_read_smc_sram_dword(hwmgr->smumgr,
441 SMU7_FIRMWARE_HEADER_LOCATION +
442 offsetof(SMU74_Firmware_Header, DpmTable),
443 &tmp, data->sram_end);
446 data->dpm_table_start = tmp;
448 error |= (0 != result);
450 result = polaris10_read_smc_sram_dword(hwmgr->smumgr,
451 SMU7_FIRMWARE_HEADER_LOCATION +
452 offsetof(SMU74_Firmware_Header, SoftRegisters),
453 &tmp, data->sram_end);
456 data->soft_regs_start = tmp;
457 smu_data->soft_regs_start = tmp;
460 error |= (0 != result);
462 result = polaris10_read_smc_sram_dword(hwmgr->smumgr,
463 SMU7_FIRMWARE_HEADER_LOCATION +
464 offsetof(SMU74_Firmware_Header, mcRegisterTable),
465 &tmp, data->sram_end);
468 data->mc_reg_table_start = tmp;
470 result = polaris10_read_smc_sram_dword(hwmgr->smumgr,
471 SMU7_FIRMWARE_HEADER_LOCATION +
472 offsetof(SMU74_Firmware_Header, FanTable),
473 &tmp, data->sram_end);
476 data->fan_table_start = tmp;
478 error |= (0 != result);
480 result = polaris10_read_smc_sram_dword(hwmgr->smumgr,
481 SMU7_FIRMWARE_HEADER_LOCATION +
482 offsetof(SMU74_Firmware_Header, mcArbDramTimingTable),
483 &tmp, data->sram_end);
486 data->arb_table_start = tmp;
488 error |= (0 != result);
490 result = polaris10_read_smc_sram_dword(hwmgr->smumgr,
491 SMU7_FIRMWARE_HEADER_LOCATION +
492 offsetof(SMU74_Firmware_Header, Version),
493 &tmp, data->sram_end);
496 hwmgr->microcode_version_info.SMC = tmp;
498 error |= (0 != result);
500 return error ? -1 : 0;
503 /* Copy one arb setting to another and then switch the active set.
504 * arb_src and arb_dest is one of the MC_CG_ARB_FREQ_Fx constants.
506 static int polaris10_copy_and_switch_arb_sets(struct pp_hwmgr *hwmgr,
507 uint32_t arb_src, uint32_t arb_dest)
509 uint32_t mc_arb_dram_timing;
510 uint32_t mc_arb_dram_timing2;
512 uint32_t mc_cg_config;
515 case MC_CG_ARB_FREQ_F0:
516 mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
517 mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
518 burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0);
520 case MC_CG_ARB_FREQ_F1:
521 mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1);
522 mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1);
523 burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1);
530 case MC_CG_ARB_FREQ_F0:
531 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING, mc_arb_dram_timing);
532 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2, mc_arb_dram_timing2);
533 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0, burst_time);
535 case MC_CG_ARB_FREQ_F1:
536 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1, mc_arb_dram_timing);
537 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1, mc_arb_dram_timing2);
538 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1, burst_time);
544 mc_cg_config = cgs_read_register(hwmgr->device, mmMC_CG_CONFIG);
545 mc_cg_config |= 0x0000000F;
546 cgs_write_register(hwmgr->device, mmMC_CG_CONFIG, mc_cg_config);
547 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_CG, CG_ARB_REQ, arb_dest);
553 * Initial switch from ARB F0->F1
555 * @param hwmgr the address of the powerplay hardware manager.
557 * This function is to be called from the SetPowerState table.
559 static int polaris10_initial_switch_from_arbf0_to_f1(struct pp_hwmgr *hwmgr)
561 return polaris10_copy_and_switch_arb_sets(hwmgr,
562 MC_CG_ARB_FREQ_F0, MC_CG_ARB_FREQ_F1);
565 static int polaris10_setup_default_pcie_table(struct pp_hwmgr *hwmgr)
567 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
568 struct phm_ppt_v1_information *table_info =
569 (struct phm_ppt_v1_information *)(hwmgr->pptable);
570 struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table;
571 uint32_t i, max_entry;
573 PP_ASSERT_WITH_CODE((data->use_pcie_performance_levels ||
574 data->use_pcie_power_saving_levels), "No pcie performance levels!",
577 if (data->use_pcie_performance_levels &&
578 !data->use_pcie_power_saving_levels) {
579 data->pcie_gen_power_saving = data->pcie_gen_performance;
580 data->pcie_lane_power_saving = data->pcie_lane_performance;
581 } else if (!data->use_pcie_performance_levels &&
582 data->use_pcie_power_saving_levels) {
583 data->pcie_gen_performance = data->pcie_gen_power_saving;
584 data->pcie_lane_performance = data->pcie_lane_power_saving;
587 phm_reset_single_dpm_table(&data->dpm_table.pcie_speed_table,
588 SMU74_MAX_LEVELS_LINK,
589 MAX_REGULAR_DPM_NUMBER);
591 if (pcie_table != NULL) {
592 /* max_entry is used to make sure we reserve one PCIE level
593 * for boot level (fix for A+A PSPP issue).
594 * If PCIE table from PPTable have ULV entry + 8 entries,
595 * then ignore the last entry.*/
596 max_entry = (SMU74_MAX_LEVELS_LINK < pcie_table->count) ?
597 SMU74_MAX_LEVELS_LINK : pcie_table->count;
598 for (i = 1; i < max_entry; i++) {
599 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, i - 1,
600 get_pcie_gen_support(data->pcie_gen_cap,
601 pcie_table->entries[i].gen_speed),
602 get_pcie_lane_support(data->pcie_lane_cap,
603 pcie_table->entries[i].lane_width));
605 data->dpm_table.pcie_speed_table.count = max_entry - 1;
607 /* Setup BIF_SCLK levels */
608 for (i = 0; i < max_entry; i++)
609 data->bif_sclk_table[i] = pcie_table->entries[i].pcie_sclk;
611 /* Hardcode Pcie Table */
612 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 0,
613 get_pcie_gen_support(data->pcie_gen_cap,
615 get_pcie_lane_support(data->pcie_lane_cap,
617 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 1,
618 get_pcie_gen_support(data->pcie_gen_cap,
620 get_pcie_lane_support(data->pcie_lane_cap,
622 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 2,
623 get_pcie_gen_support(data->pcie_gen_cap,
625 get_pcie_lane_support(data->pcie_lane_cap,
627 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 3,
628 get_pcie_gen_support(data->pcie_gen_cap,
630 get_pcie_lane_support(data->pcie_lane_cap,
632 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 4,
633 get_pcie_gen_support(data->pcie_gen_cap,
635 get_pcie_lane_support(data->pcie_lane_cap,
637 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 5,
638 get_pcie_gen_support(data->pcie_gen_cap,
640 get_pcie_lane_support(data->pcie_lane_cap,
643 data->dpm_table.pcie_speed_table.count = 6;
645 /* Populate last level for boot PCIE level, but do not increment count. */
646 phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table,
647 data->dpm_table.pcie_speed_table.count,
648 get_pcie_gen_support(data->pcie_gen_cap,
650 get_pcie_lane_support(data->pcie_lane_cap,
657 * This function is to initalize all DPM state tables
658 * for SMU7 based on the dependency table.
659 * Dynamic state patching function will then trim these
660 * state tables to the allowed range based
661 * on the power policy or external client requests,
662 * such as UVD request, etc.
664 int polaris10_setup_default_dpm_tables(struct pp_hwmgr *hwmgr)
666 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
667 struct phm_ppt_v1_information *table_info =
668 (struct phm_ppt_v1_information *)(hwmgr->pptable);
671 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table =
672 table_info->vdd_dep_on_sclk;
673 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
674 table_info->vdd_dep_on_mclk;
676 PP_ASSERT_WITH_CODE(dep_sclk_table != NULL,
677 "SCLK dependency table is missing. This table is mandatory",
679 PP_ASSERT_WITH_CODE(dep_sclk_table->count >= 1,
680 "SCLK dependency table has to have is missing."
681 "This table is mandatory",
684 PP_ASSERT_WITH_CODE(dep_mclk_table != NULL,
685 "MCLK dependency table is missing. This table is mandatory",
687 PP_ASSERT_WITH_CODE(dep_mclk_table->count >= 1,
688 "MCLK dependency table has to have is missing."
689 "This table is mandatory",
692 /* clear the state table to reset everything to default */
693 phm_reset_single_dpm_table(
694 &data->dpm_table.sclk_table, SMU74_MAX_LEVELS_GRAPHICS, MAX_REGULAR_DPM_NUMBER);
695 phm_reset_single_dpm_table(
696 &data->dpm_table.mclk_table, SMU74_MAX_LEVELS_MEMORY, MAX_REGULAR_DPM_NUMBER);
699 /* Initialize Sclk DPM table based on allow Sclk values */
700 data->dpm_table.sclk_table.count = 0;
701 for (i = 0; i < dep_sclk_table->count; i++) {
702 if (i == 0 || data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count - 1].value !=
703 dep_sclk_table->entries[i].clk) {
705 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].value =
706 dep_sclk_table->entries[i].clk;
708 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].enabled =
709 (i == 0) ? true : false;
710 data->dpm_table.sclk_table.count++;
714 /* Initialize Mclk DPM table based on allow Mclk values */
715 data->dpm_table.mclk_table.count = 0;
716 for (i = 0; i < dep_mclk_table->count; i++) {
717 if (i == 0 || data->dpm_table.mclk_table.dpm_levels
718 [data->dpm_table.mclk_table.count - 1].value !=
719 dep_mclk_table->entries[i].clk) {
720 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].value =
721 dep_mclk_table->entries[i].clk;
722 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].enabled =
723 (i == 0) ? true : false;
724 data->dpm_table.mclk_table.count++;
728 /* setup PCIE gen speed levels */
729 polaris10_setup_default_pcie_table(hwmgr);
731 /* save a copy of the default DPM table */
732 memcpy(&(data->golden_dpm_table), &(data->dpm_table),
733 sizeof(struct polaris10_dpm_table));
738 uint8_t convert_to_vid(uint16_t vddc)
740 return (uint8_t) ((6200 - (vddc * VOLTAGE_SCALE)) / 25);
744 * Mvdd table preparation for SMC.
746 * @param *hwmgr The address of the hardware manager.
747 * @param *table The SMC DPM table structure to be populated.
750 static int polaris10_populate_smc_mvdd_table(struct pp_hwmgr *hwmgr,
751 SMU74_Discrete_DpmTable *table)
753 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
754 uint32_t count, level;
756 if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
757 count = data->mvdd_voltage_table.count;
758 if (count > SMU_MAX_SMIO_LEVELS)
759 count = SMU_MAX_SMIO_LEVELS;
760 for (level = 0; level < count; level++) {
761 table->SmioTable2.Pattern[level].Voltage =
762 PP_HOST_TO_SMC_US(data->mvdd_voltage_table.entries[count].value * VOLTAGE_SCALE);
763 /* Index into DpmTable.Smio. Drive bits from Smio entry to get this voltage level.*/
764 table->SmioTable2.Pattern[level].Smio =
766 table->Smio[level] |=
767 data->mvdd_voltage_table.entries[level].smio_low;
769 table->SmioMask2 = data->vddci_voltage_table.mask_low;
771 table->MvddLevelCount = (uint32_t) PP_HOST_TO_SMC_UL(count);
777 static int polaris10_populate_smc_vddci_table(struct pp_hwmgr *hwmgr,
778 struct SMU74_Discrete_DpmTable *table)
780 uint32_t count, level;
781 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
783 count = data->vddci_voltage_table.count;
785 if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
786 if (count > SMU_MAX_SMIO_LEVELS)
787 count = SMU_MAX_SMIO_LEVELS;
788 for (level = 0; level < count; ++level) {
789 table->SmioTable1.Pattern[level].Voltage =
790 PP_HOST_TO_SMC_US(data->vddci_voltage_table.entries[level].value * VOLTAGE_SCALE);
791 table->SmioTable1.Pattern[level].Smio = (uint8_t) level;
793 table->Smio[level] |= data->vddci_voltage_table.entries[level].smio_low;
797 table->SmioMask1 = data->vddci_voltage_table.mask_low;
803 * Preparation of vddc and vddgfx CAC tables for SMC.
805 * @param hwmgr the address of the hardware manager
806 * @param table the SMC DPM table structure to be populated
809 static int polaris10_populate_cac_table(struct pp_hwmgr *hwmgr,
810 struct SMU74_Discrete_DpmTable *table)
814 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
815 struct phm_ppt_v1_information *table_info =
816 (struct phm_ppt_v1_information *)(hwmgr->pptable);
817 struct phm_ppt_v1_voltage_lookup_table *lookup_table =
818 table_info->vddc_lookup_table;
819 /* tables is already swapped, so in order to use the value from it,
820 * we need to swap it back.
821 * We are populating vddc CAC data to BapmVddc table
822 * in split and merged mode
824 for (count = 0; count < lookup_table->count; count++) {
825 index = phm_get_voltage_index(lookup_table,
826 data->vddc_voltage_table.entries[count].value);
827 table->BapmVddcVidLoSidd[count] = convert_to_vid(lookup_table->entries[index].us_cac_low);
828 table->BapmVddcVidHiSidd[count] = convert_to_vid(lookup_table->entries[index].us_cac_mid);
829 table->BapmVddcVidHiSidd2[count] = convert_to_vid(lookup_table->entries[index].us_cac_high);
836 * Preparation of voltage tables for SMC.
838 * @param hwmgr the address of the hardware manager
839 * @param table the SMC DPM table structure to be populated
843 int polaris10_populate_smc_voltage_tables(struct pp_hwmgr *hwmgr,
844 struct SMU74_Discrete_DpmTable *table)
846 polaris10_populate_smc_vddci_table(hwmgr, table);
847 polaris10_populate_smc_mvdd_table(hwmgr, table);
848 polaris10_populate_cac_table(hwmgr, table);
853 static int polaris10_populate_ulv_level(struct pp_hwmgr *hwmgr,
854 struct SMU74_Discrete_Ulv *state)
856 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
857 struct phm_ppt_v1_information *table_info =
858 (struct phm_ppt_v1_information *)(hwmgr->pptable);
860 state->CcPwrDynRm = 0;
861 state->CcPwrDynRm1 = 0;
863 state->VddcOffset = (uint16_t) table_info->us_ulv_voltage_offset;
864 state->VddcOffsetVid = (uint8_t)(table_info->us_ulv_voltage_offset *
865 VOLTAGE_VID_OFFSET_SCALE2 / VOLTAGE_VID_OFFSET_SCALE1);
867 state->VddcPhase = (data->vddc_phase_shed_control) ? 0 : 1;
869 CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm);
870 CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm1);
871 CONVERT_FROM_HOST_TO_SMC_US(state->VddcOffset);
876 static int polaris10_populate_ulv_state(struct pp_hwmgr *hwmgr,
877 struct SMU74_Discrete_DpmTable *table)
879 return polaris10_populate_ulv_level(hwmgr, &table->Ulv);
882 static int polaris10_populate_smc_link_level(struct pp_hwmgr *hwmgr,
883 struct SMU74_Discrete_DpmTable *table)
885 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
886 struct polaris10_dpm_table *dpm_table = &data->dpm_table;
889 /* Index (dpm_table->pcie_speed_table.count)
890 * is reserved for PCIE boot level. */
891 for (i = 0; i <= dpm_table->pcie_speed_table.count; i++) {
892 table->LinkLevel[i].PcieGenSpeed =
893 (uint8_t)dpm_table->pcie_speed_table.dpm_levels[i].value;
894 table->LinkLevel[i].PcieLaneCount = (uint8_t)encode_pcie_lane_width(
895 dpm_table->pcie_speed_table.dpm_levels[i].param1);
896 table->LinkLevel[i].EnabledForActivity = 1;
897 table->LinkLevel[i].SPC = (uint8_t)(data->pcie_spc_cap & 0xff);
898 table->LinkLevel[i].DownThreshold = PP_HOST_TO_SMC_UL(5);
899 table->LinkLevel[i].UpThreshold = PP_HOST_TO_SMC_UL(30);
902 data->smc_state_table.LinkLevelCount =
903 (uint8_t)dpm_table->pcie_speed_table.count;
904 data->dpm_level_enable_mask.pcie_dpm_enable_mask =
905 phm_get_dpm_level_enable_mask_value(&dpm_table->pcie_speed_table);
910 static uint32_t polaris10_get_xclk(struct pp_hwmgr *hwmgr)
912 uint32_t reference_clock, tmp;
913 struct cgs_display_info info = {0};
914 struct cgs_mode_info mode_info;
916 info.mode_info = &mode_info;
918 tmp = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_CLKPIN_CNTL_2, MUX_TCLK_TO_XCLK);
923 cgs_get_active_displays_info(hwmgr->device, &info);
924 reference_clock = mode_info.ref_clock;
926 tmp = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_CLKPIN_CNTL, XTALIN_DIVIDE);
929 return reference_clock / 4;
931 return reference_clock;
935 * Calculates the SCLK dividers using the provided engine clock
937 * @param hwmgr the address of the hardware manager
938 * @param clock the engine clock to use to populate the structure
939 * @param sclk the SMC SCLK structure to be populated
941 static int polaris10_calculate_sclk_params(struct pp_hwmgr *hwmgr,
942 uint32_t clock, SMU_SclkSetting *sclk_setting)
944 const struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
945 const SMU74_Discrete_DpmTable *table = &(data->smc_state_table);
946 struct pp_atomctrl_clock_dividers_ai dividers;
949 uint32_t pcc_target_percent, pcc_target_freq, ss_target_percent, ss_target_freq;
954 sclk_setting->SclkFrequency = clock;
955 /* get the engine clock dividers for this clock value */
956 result = atomctrl_get_engine_pll_dividers_ai(hwmgr, clock, ÷rs);
958 sclk_setting->Fcw_int = dividers.usSclk_fcw_int;
959 sclk_setting->Fcw_frac = dividers.usSclk_fcw_frac;
960 sclk_setting->Pcc_fcw_int = dividers.usPcc_fcw_int;
961 sclk_setting->PllRange = dividers.ucSclkPllRange;
962 sclk_setting->Sclk_slew_rate = 0x400;
963 sclk_setting->Pcc_up_slew_rate = dividers.usPcc_fcw_slew_frac;
964 sclk_setting->Pcc_down_slew_rate = 0xffff;
965 sclk_setting->SSc_En = dividers.ucSscEnable;
966 sclk_setting->Fcw1_int = dividers.usSsc_fcw1_int;
967 sclk_setting->Fcw1_frac = dividers.usSsc_fcw1_frac;
968 sclk_setting->Sclk_ss_slew_rate = dividers.usSsc_fcw_slew_frac;
972 ref_clock = polaris10_get_xclk(hwmgr);
974 for (i = 0; i < NUM_SCLK_RANGE; i++) {
975 if (clock > data->range_table[i].trans_lower_frequency
976 && clock <= data->range_table[i].trans_upper_frequency) {
977 sclk_setting->PllRange = i;
982 sclk_setting->Fcw_int = (uint16_t)((clock << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv) / ref_clock);
983 temp = clock << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv;
985 do_div(temp, ref_clock);
986 sclk_setting->Fcw_frac = temp & 0xffff;
988 pcc_target_percent = 10; /* Hardcode 10% for now. */
989 pcc_target_freq = clock - (clock * pcc_target_percent / 100);
990 sclk_setting->Pcc_fcw_int = (uint16_t)((pcc_target_freq << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv) / ref_clock);
992 ss_target_percent = 2; /* Hardcode 2% for now. */
993 sclk_setting->SSc_En = 0;
994 if (ss_target_percent) {
995 sclk_setting->SSc_En = 1;
996 ss_target_freq = clock - (clock * ss_target_percent / 100);
997 sclk_setting->Fcw1_int = (uint16_t)((ss_target_freq << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv) / ref_clock);
998 temp = ss_target_freq << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv;
1000 do_div(temp, ref_clock);
1001 sclk_setting->Fcw1_frac = temp & 0xffff;
1007 static int polaris10_get_dependency_volt_by_clk(struct pp_hwmgr *hwmgr,
1008 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table,
1009 uint32_t clock, SMU_VoltageLevel *voltage, uint32_t *mvdd)
1013 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1015 *voltage = *mvdd = 0;
1017 /* clock - voltage dependency table is empty table */
1018 if (dep_table->count == 0)
1021 for (i = 0; i < dep_table->count; i++) {
1022 /* find first sclk bigger than request */
1023 if (dep_table->entries[i].clk >= clock) {
1024 *voltage |= (dep_table->entries[i].vddc *
1025 VOLTAGE_SCALE) << VDDC_SHIFT;
1026 if (POLARIS10_VOLTAGE_CONTROL_NONE == data->vddci_control)
1027 *voltage |= (data->vbios_boot_state.vddci_bootup_value *
1028 VOLTAGE_SCALE) << VDDCI_SHIFT;
1029 else if (dep_table->entries[i].vddci)
1030 *voltage |= (dep_table->entries[i].vddci *
1031 VOLTAGE_SCALE) << VDDCI_SHIFT;
1033 vddci = phm_find_closest_vddci(&(data->vddci_voltage_table),
1034 (dep_table->entries[i].vddc -
1035 (uint16_t)data->vddc_vddci_delta));
1036 *voltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
1039 if (POLARIS10_VOLTAGE_CONTROL_NONE == data->mvdd_control)
1040 *mvdd = data->vbios_boot_state.mvdd_bootup_value *
1042 else if (dep_table->entries[i].mvdd)
1043 *mvdd = (uint32_t) dep_table->entries[i].mvdd *
1046 *voltage |= 1 << PHASES_SHIFT;
1051 /* sclk is bigger than max sclk in the dependence table */
1052 *voltage |= (dep_table->entries[i - 1].vddc * VOLTAGE_SCALE) << VDDC_SHIFT;
1054 if (POLARIS10_VOLTAGE_CONTROL_NONE == data->vddci_control)
1055 *voltage |= (data->vbios_boot_state.vddci_bootup_value *
1056 VOLTAGE_SCALE) << VDDCI_SHIFT;
1057 else if (dep_table->entries[i-1].vddci) {
1058 vddci = phm_find_closest_vddci(&(data->vddci_voltage_table),
1059 (dep_table->entries[i].vddc -
1060 (uint16_t)data->vddc_vddci_delta));
1061 *voltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
1064 if (POLARIS10_VOLTAGE_CONTROL_NONE == data->mvdd_control)
1065 *mvdd = data->vbios_boot_state.mvdd_bootup_value * VOLTAGE_SCALE;
1066 else if (dep_table->entries[i].mvdd)
1067 *mvdd = (uint32_t) dep_table->entries[i - 1].mvdd * VOLTAGE_SCALE;
1072 sclkFcwRange_t Range_Table[NUM_SCLK_RANGE] = { {VCO_2_4, POSTDIV_DIV_BY_16, 75, 160, 112},
1073 {VCO_3_6, POSTDIV_DIV_BY_16, 112, 224, 160},
1074 {VCO_2_4, POSTDIV_DIV_BY_8, 75, 160, 112},
1075 {VCO_3_6, POSTDIV_DIV_BY_8, 112, 224, 160},
1076 {VCO_2_4, POSTDIV_DIV_BY_4, 75, 160, 112},
1077 {VCO_3_6, POSTDIV_DIV_BY_4, 112, 216, 160},
1078 {VCO_2_4, POSTDIV_DIV_BY_2, 75, 160, 108},
1079 {VCO_3_6, POSTDIV_DIV_BY_2, 112, 216, 160} };
1081 static void polaris10_get_sclk_range_table(struct pp_hwmgr *hwmgr)
1083 uint32_t i, ref_clk;
1084 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1085 SMU74_Discrete_DpmTable *table = &(data->smc_state_table);
1086 struct pp_atom_ctrl_sclk_range_table range_table_from_vbios = { { {0} } };
1088 ref_clk = polaris10_get_xclk(hwmgr);
1090 if (0 == atomctrl_get_smc_sclk_range_table(hwmgr, &range_table_from_vbios)) {
1091 for (i = 0; i < NUM_SCLK_RANGE; i++) {
1092 table->SclkFcwRangeTable[i].vco_setting = range_table_from_vbios.entry[i].ucVco_setting;
1093 table->SclkFcwRangeTable[i].postdiv = range_table_from_vbios.entry[i].ucPostdiv;
1094 table->SclkFcwRangeTable[i].fcw_pcc = range_table_from_vbios.entry[i].usFcw_pcc;
1096 table->SclkFcwRangeTable[i].fcw_trans_upper = range_table_from_vbios.entry[i].usFcw_trans_upper;
1097 table->SclkFcwRangeTable[i].fcw_trans_lower = range_table_from_vbios.entry[i].usRcw_trans_lower;
1099 CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_pcc);
1100 CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_upper);
1101 CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_lower);
1106 for (i = 0; i < NUM_SCLK_RANGE; i++) {
1108 data->range_table[i].trans_lower_frequency = (ref_clk * Range_Table[i].fcw_trans_lower) >> Range_Table[i].postdiv;
1109 data->range_table[i].trans_upper_frequency = (ref_clk * Range_Table[i].fcw_trans_upper) >> Range_Table[i].postdiv;
1111 table->SclkFcwRangeTable[i].vco_setting = Range_Table[i].vco_setting;
1112 table->SclkFcwRangeTable[i].postdiv = Range_Table[i].postdiv;
1113 table->SclkFcwRangeTable[i].fcw_pcc = Range_Table[i].fcw_pcc;
1115 table->SclkFcwRangeTable[i].fcw_trans_upper = Range_Table[i].fcw_trans_upper;
1116 table->SclkFcwRangeTable[i].fcw_trans_lower = Range_Table[i].fcw_trans_lower;
1118 CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_pcc);
1119 CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_upper);
1120 CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_lower);
1125 * Populates single SMC SCLK structure using the provided engine clock
1127 * @param hwmgr the address of the hardware manager
1128 * @param clock the engine clock to use to populate the structure
1129 * @param sclk the SMC SCLK structure to be populated
1132 static int polaris10_populate_single_graphic_level(struct pp_hwmgr *hwmgr,
1133 uint32_t clock, uint16_t sclk_al_threshold,
1134 struct SMU74_Discrete_GraphicsLevel *level)
1136 int result, i, temp;
1137 /* PP_Clocks minClocks; */
1139 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1140 struct phm_ppt_v1_information *table_info =
1141 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1142 SMU_SclkSetting curr_sclk_setting = { 0 };
1144 result = polaris10_calculate_sclk_params(hwmgr, clock, &curr_sclk_setting);
1146 /* populate graphics levels */
1147 result = polaris10_get_dependency_volt_by_clk(hwmgr,
1148 table_info->vdd_dep_on_sclk, clock,
1149 &level->MinVoltage, &mvdd);
1151 PP_ASSERT_WITH_CODE((0 == result),
1152 "can not find VDDC voltage value for "
1153 "VDDC engine clock dependency table",
1155 level->ActivityLevel = sclk_al_threshold;
1157 level->CcPwrDynRm = 0;
1158 level->CcPwrDynRm1 = 0;
1159 level->EnabledForActivity = 0;
1160 level->EnabledForThrottle = 1;
1162 level->DownHyst = 0;
1163 level->VoltageDownHyst = 0;
1164 level->PowerThrottle = 0;
1167 * TODO: get minimum clocks from dal configaration
1168 * PECI_GetMinClockSettings(hwmgr->pPECI, &minClocks);
1170 /* data->DisplayTiming.minClockInSR = minClocks.engineClockInSR; */
1172 /* get level->DeepSleepDivId
1173 if (phm_cap_enabled(hwmgr->platformDescriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep))
1174 level->DeepSleepDivId = PhwFiji_GetSleepDividerIdFromClock(hwmgr, clock, minClocks.engineClockInSR);
1176 PP_ASSERT_WITH_CODE((clock >= 2500), "Engine clock can't satisfy stutter requirement!", return 0);
1177 for (i = POLARIS10_MAX_DEEPSLEEP_DIVIDER_ID; ; i--) {
1178 temp = clock / (1UL << i);
1180 if (temp >= 2500 || i == 0)
1184 level->DeepSleepDivId = i;
1186 /* Default to slow, highest DPM level will be
1187 * set to PPSMC_DISPLAY_WATERMARK_LOW later.
1189 if (data->update_up_hyst)
1190 level->UpHyst = (uint8_t)data->up_hyst;
1191 if (data->update_down_hyst)
1192 level->DownHyst = (uint8_t)data->down_hyst;
1194 level->SclkSetting = curr_sclk_setting;
1196 CONVERT_FROM_HOST_TO_SMC_UL(level->MinVoltage);
1197 CONVERT_FROM_HOST_TO_SMC_UL(level->CcPwrDynRm);
1198 CONVERT_FROM_HOST_TO_SMC_UL(level->CcPwrDynRm1);
1199 CONVERT_FROM_HOST_TO_SMC_US(level->ActivityLevel);
1200 CONVERT_FROM_HOST_TO_SMC_UL(level->SclkSetting.SclkFrequency);
1201 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw_int);
1202 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw_frac);
1203 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Pcc_fcw_int);
1204 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Sclk_slew_rate);
1205 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Pcc_up_slew_rate);
1206 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Pcc_down_slew_rate);
1207 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw1_int);
1208 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw1_frac);
1209 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Sclk_ss_slew_rate);
1214 * Populates all SMC SCLK levels' structure based on the trimmed allowed dpm engine clock states
1216 * @param hwmgr the address of the hardware manager
1218 static int polaris10_populate_all_graphic_levels(struct pp_hwmgr *hwmgr)
1220 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1221 struct polaris10_dpm_table *dpm_table = &data->dpm_table;
1222 struct phm_ppt_v1_information *table_info =
1223 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1224 struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table;
1225 uint8_t pcie_entry_cnt = (uint8_t) data->dpm_table.pcie_speed_table.count;
1227 uint32_t array = data->dpm_table_start +
1228 offsetof(SMU74_Discrete_DpmTable, GraphicsLevel);
1229 uint32_t array_size = sizeof(struct SMU74_Discrete_GraphicsLevel) *
1230 SMU74_MAX_LEVELS_GRAPHICS;
1231 struct SMU74_Discrete_GraphicsLevel *levels =
1232 data->smc_state_table.GraphicsLevel;
1233 uint32_t i, max_entry;
1234 uint8_t hightest_pcie_level_enabled = 0,
1235 lowest_pcie_level_enabled = 0,
1236 mid_pcie_level_enabled = 0,
1239 polaris10_get_sclk_range_table(hwmgr);
1241 for (i = 0; i < dpm_table->sclk_table.count; i++) {
1243 result = polaris10_populate_single_graphic_level(hwmgr,
1244 dpm_table->sclk_table.dpm_levels[i].value,
1245 (uint16_t)data->activity_target[i],
1246 &(data->smc_state_table.GraphicsLevel[i]));
1250 /* Making sure only DPM level 0-1 have Deep Sleep Div ID populated. */
1252 levels[i].DeepSleepDivId = 0;
1254 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1255 PHM_PlatformCaps_SPLLShutdownSupport))
1256 data->smc_state_table.GraphicsLevel[0].SclkSetting.SSc_En = 0;
1258 data->smc_state_table.GraphicsLevel[0].EnabledForActivity = 1;
1259 data->smc_state_table.GraphicsDpmLevelCount =
1260 (uint8_t)dpm_table->sclk_table.count;
1261 data->dpm_level_enable_mask.sclk_dpm_enable_mask =
1262 phm_get_dpm_level_enable_mask_value(&dpm_table->sclk_table);
1265 if (pcie_table != NULL) {
1266 PP_ASSERT_WITH_CODE((1 <= pcie_entry_cnt),
1267 "There must be 1 or more PCIE levels defined in PPTable.",
1269 max_entry = pcie_entry_cnt - 1;
1270 for (i = 0; i < dpm_table->sclk_table.count; i++)
1271 levels[i].pcieDpmLevel =
1272 (uint8_t) ((i < max_entry) ? i : max_entry);
1274 while (data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
1275 ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
1276 (1 << (hightest_pcie_level_enabled + 1))) != 0))
1277 hightest_pcie_level_enabled++;
1279 while (data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
1280 ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
1281 (1 << lowest_pcie_level_enabled)) == 0))
1282 lowest_pcie_level_enabled++;
1284 while ((count < hightest_pcie_level_enabled) &&
1285 ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
1286 (1 << (lowest_pcie_level_enabled + 1 + count))) == 0))
1289 mid_pcie_level_enabled = (lowest_pcie_level_enabled + 1 + count) <
1290 hightest_pcie_level_enabled ?
1291 (lowest_pcie_level_enabled + 1 + count) :
1292 hightest_pcie_level_enabled;
1294 /* set pcieDpmLevel to hightest_pcie_level_enabled */
1295 for (i = 2; i < dpm_table->sclk_table.count; i++)
1296 levels[i].pcieDpmLevel = hightest_pcie_level_enabled;
1298 /* set pcieDpmLevel to lowest_pcie_level_enabled */
1299 levels[0].pcieDpmLevel = lowest_pcie_level_enabled;
1301 /* set pcieDpmLevel to mid_pcie_level_enabled */
1302 levels[1].pcieDpmLevel = mid_pcie_level_enabled;
1304 /* level count will send to smc once at init smc table and never change */
1305 result = polaris10_copy_bytes_to_smc(hwmgr->smumgr, array, (uint8_t *)levels,
1306 (uint32_t)array_size, data->sram_end);
1311 static int polaris10_populate_single_memory_level(struct pp_hwmgr *hwmgr,
1312 uint32_t clock, struct SMU74_Discrete_MemoryLevel *mem_level)
1314 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1315 struct phm_ppt_v1_information *table_info =
1316 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1318 struct cgs_display_info info = {0, 0, NULL};
1320 cgs_get_active_displays_info(hwmgr->device, &info);
1322 if (table_info->vdd_dep_on_mclk) {
1323 result = polaris10_get_dependency_volt_by_clk(hwmgr,
1324 table_info->vdd_dep_on_mclk, clock,
1325 &mem_level->MinVoltage, &mem_level->MinMvdd);
1326 PP_ASSERT_WITH_CODE((0 == result),
1327 "can not find MinVddc voltage value from memory "
1328 "VDDC voltage dependency table", return result);
1331 mem_level->MclkFrequency = clock;
1332 mem_level->StutterEnable = 0;
1333 mem_level->EnabledForThrottle = 1;
1334 mem_level->EnabledForActivity = 0;
1335 mem_level->UpHyst = 0;
1336 mem_level->DownHyst = 100;
1337 mem_level->VoltageDownHyst = 0;
1338 mem_level->ActivityLevel = (uint16_t)data->mclk_activity_target;
1339 mem_level->StutterEnable = false;
1341 mem_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
1343 data->display_timing.num_existing_displays = info.display_count;
1345 if ((data->mclk_stutter_mode_threshold) &&
1346 (clock <= data->mclk_stutter_mode_threshold) &&
1347 (PHM_READ_FIELD(hwmgr->device, DPG_PIPE_STUTTER_CONTROL,
1348 STUTTER_ENABLE) & 0x1))
1349 mem_level->StutterEnable = true;
1352 CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MinMvdd);
1353 CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MclkFrequency);
1354 CONVERT_FROM_HOST_TO_SMC_US(mem_level->ActivityLevel);
1355 CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MinVoltage);
1361 * Populates all SMC MCLK levels' structure based on the trimmed allowed dpm memory clock states
1363 * @param hwmgr the address of the hardware manager
1365 static int polaris10_populate_all_memory_levels(struct pp_hwmgr *hwmgr)
1367 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1368 struct polaris10_dpm_table *dpm_table = &data->dpm_table;
1370 /* populate MCLK dpm table to SMU7 */
1371 uint32_t array = data->dpm_table_start +
1372 offsetof(SMU74_Discrete_DpmTable, MemoryLevel);
1373 uint32_t array_size = sizeof(SMU74_Discrete_MemoryLevel) *
1374 SMU74_MAX_LEVELS_MEMORY;
1375 struct SMU74_Discrete_MemoryLevel *levels =
1376 data->smc_state_table.MemoryLevel;
1379 for (i = 0; i < dpm_table->mclk_table.count; i++) {
1380 PP_ASSERT_WITH_CODE((0 != dpm_table->mclk_table.dpm_levels[i].value),
1381 "can not populate memory level as memory clock is zero",
1383 result = polaris10_populate_single_memory_level(hwmgr,
1384 dpm_table->mclk_table.dpm_levels[i].value,
1386 if (i == dpm_table->mclk_table.count - 1) {
1387 levels[i].DisplayWatermark = PPSMC_DISPLAY_WATERMARK_HIGH;
1388 levels[i].EnabledForActivity = 1;
1394 /* in order to prevent MC activity from stutter mode to push DPM up.
1395 * the UVD change complements this by putting the MCLK in
1396 * a higher state by default such that we are not effected by
1397 * up threshold or and MCLK DPM latency.
1399 levels[0].ActivityLevel = (uint16_t)data->mclk_dpm0_activity_target;
1400 CONVERT_FROM_HOST_TO_SMC_US(levels[0].ActivityLevel);
1402 data->smc_state_table.MemoryDpmLevelCount =
1403 (uint8_t)dpm_table->mclk_table.count;
1404 data->dpm_level_enable_mask.mclk_dpm_enable_mask =
1405 phm_get_dpm_level_enable_mask_value(&dpm_table->mclk_table);
1407 /* level count will send to smc once at init smc table and never change */
1408 result = polaris10_copy_bytes_to_smc(hwmgr->smumgr, array, (uint8_t *)levels,
1409 (uint32_t)array_size, data->sram_end);
1415 * Populates the SMC MVDD structure using the provided memory clock.
1417 * @param hwmgr the address of the hardware manager
1418 * @param mclk the MCLK value to be used in the decision if MVDD should be high or low.
1419 * @param voltage the SMC VOLTAGE structure to be populated
1421 int polaris10_populate_mvdd_value(struct pp_hwmgr *hwmgr,
1422 uint32_t mclk, SMIO_Pattern *smio_pat)
1424 const struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1425 struct phm_ppt_v1_information *table_info =
1426 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1429 if (POLARIS10_VOLTAGE_CONTROL_NONE != data->mvdd_control) {
1430 /* find mvdd value which clock is more than request */
1431 for (i = 0; i < table_info->vdd_dep_on_mclk->count; i++) {
1432 if (mclk <= table_info->vdd_dep_on_mclk->entries[i].clk) {
1433 smio_pat->Voltage = data->mvdd_voltage_table.entries[i].value;
1437 PP_ASSERT_WITH_CODE(i < table_info->vdd_dep_on_mclk->count,
1438 "MVDD Voltage is outside the supported range.",
1446 static int polaris10_populate_smc_acpi_level(struct pp_hwmgr *hwmgr,
1447 SMU74_Discrete_DpmTable *table)
1450 uint32_t sclk_frequency;
1451 const struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1452 struct phm_ppt_v1_information *table_info =
1453 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1454 SMIO_Pattern vol_level;
1458 table->ACPILevel.Flags &= ~PPSMC_SWSTATE_FLAG_DC;
1460 if (!data->sclk_dpm_key_disabled) {
1461 /* Get MinVoltage and Frequency from DPM0,
1462 * already converted to SMC_UL */
1463 sclk_frequency = data->dpm_table.sclk_table.dpm_levels[0].value;
1464 result = polaris10_get_dependency_volt_by_clk(hwmgr,
1465 table_info->vdd_dep_on_sclk,
1466 table->ACPILevel.SclkFrequency,
1467 &table->ACPILevel.MinVoltage, &mvdd);
1468 PP_ASSERT_WITH_CODE((0 == result),
1469 "Cannot find ACPI VDDC voltage value "
1470 "in Clock Dependency Table", );
1472 sclk_frequency = data->vbios_boot_state.sclk_bootup_value;
1473 table->ACPILevel.MinVoltage =
1474 data->vbios_boot_state.vddc_bootup_value * VOLTAGE_SCALE;
1477 result = polaris10_calculate_sclk_params(hwmgr, sclk_frequency, &(table->ACPILevel.SclkSetting));
1478 PP_ASSERT_WITH_CODE(result == 0, "Error retrieving Engine Clock dividers from VBIOS.", return result);
1480 table->ACPILevel.DeepSleepDivId = 0;
1481 table->ACPILevel.CcPwrDynRm = 0;
1482 table->ACPILevel.CcPwrDynRm1 = 0;
1484 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.Flags);
1485 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.MinVoltage);
1486 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm);
1487 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm1);
1489 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SclkSetting.SclkFrequency);
1490 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw_int);
1491 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw_frac);
1492 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Pcc_fcw_int);
1493 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Sclk_slew_rate);
1494 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Pcc_up_slew_rate);
1495 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Pcc_down_slew_rate);
1496 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw1_int);
1497 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw1_frac);
1498 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Sclk_ss_slew_rate);
1500 if (!data->mclk_dpm_key_disabled) {
1501 /* Get MinVoltage and Frequency from DPM0, already converted to SMC_UL */
1502 table->MemoryACPILevel.MclkFrequency =
1503 data->dpm_table.mclk_table.dpm_levels[0].value;
1504 result = polaris10_get_dependency_volt_by_clk(hwmgr,
1505 table_info->vdd_dep_on_mclk,
1506 table->MemoryACPILevel.MclkFrequency,
1507 &table->MemoryACPILevel.MinVoltage, &mvdd);
1508 PP_ASSERT_WITH_CODE((0 == result),
1509 "Cannot find ACPI VDDCI voltage value "
1510 "in Clock Dependency Table",
1513 table->MemoryACPILevel.MclkFrequency =
1514 data->vbios_boot_state.mclk_bootup_value;
1515 table->MemoryACPILevel.MinVoltage =
1516 data->vbios_boot_state.vddci_bootup_value * VOLTAGE_SCALE;
1520 if ((POLARIS10_VOLTAGE_CONTROL_NONE == data->mvdd_control) ||
1521 (data->mclk_dpm_key_disabled))
1522 us_mvdd = data->vbios_boot_state.mvdd_bootup_value;
1524 if (!polaris10_populate_mvdd_value(hwmgr,
1525 data->dpm_table.mclk_table.dpm_levels[0].value,
1527 us_mvdd = vol_level.Voltage;
1530 if (0 == polaris10_populate_mvdd_value(hwmgr, 0, &vol_level))
1531 table->MemoryACPILevel.MinMvdd = PP_HOST_TO_SMC_UL(vol_level.Voltage);
1533 table->MemoryACPILevel.MinMvdd = 0;
1535 table->MemoryACPILevel.StutterEnable = false;
1537 table->MemoryACPILevel.EnabledForThrottle = 0;
1538 table->MemoryACPILevel.EnabledForActivity = 0;
1539 table->MemoryACPILevel.UpHyst = 0;
1540 table->MemoryACPILevel.DownHyst = 100;
1541 table->MemoryACPILevel.VoltageDownHyst = 0;
1542 table->MemoryACPILevel.ActivityLevel =
1543 PP_HOST_TO_SMC_US((uint16_t)data->mclk_activity_target);
1545 CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MclkFrequency);
1546 CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MinVoltage);
1551 static int polaris10_populate_smc_vce_level(struct pp_hwmgr *hwmgr,
1552 SMU74_Discrete_DpmTable *table)
1554 int result = -EINVAL;
1556 struct pp_atomctrl_clock_dividers_vi dividers;
1557 struct phm_ppt_v1_information *table_info =
1558 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1559 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
1560 table_info->mm_dep_table;
1561 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1563 table->VceLevelCount = (uint8_t)(mm_table->count);
1564 table->VceBootLevel = 0;
1566 for (count = 0; count < table->VceLevelCount; count++) {
1567 table->VceLevel[count].Frequency = mm_table->entries[count].eclk;
1568 table->VceLevel[count].MinVoltage |=
1569 (mm_table->entries[count].vddc * VOLTAGE_SCALE) << VDDC_SHIFT;
1570 table->VceLevel[count].MinVoltage |=
1571 ((mm_table->entries[count].vddc - data->vddc_vddci_delta) *
1572 VOLTAGE_SCALE) << VDDCI_SHIFT;
1573 table->VceLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
1575 /*retrieve divider value for VBIOS */
1576 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
1577 table->VceLevel[count].Frequency, ÷rs);
1578 PP_ASSERT_WITH_CODE((0 == result),
1579 "can not find divide id for VCE engine clock",
1582 table->VceLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
1584 CONVERT_FROM_HOST_TO_SMC_UL(table->VceLevel[count].Frequency);
1585 CONVERT_FROM_HOST_TO_SMC_UL(table->VceLevel[count].MinVoltage);
1590 static int polaris10_populate_smc_samu_level(struct pp_hwmgr *hwmgr,
1591 SMU74_Discrete_DpmTable *table)
1593 int result = -EINVAL;
1595 struct pp_atomctrl_clock_dividers_vi dividers;
1596 struct phm_ppt_v1_information *table_info =
1597 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1598 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
1599 table_info->mm_dep_table;
1600 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1602 table->SamuBootLevel = 0;
1603 table->SamuLevelCount = (uint8_t)(mm_table->count);
1605 for (count = 0; count < table->SamuLevelCount; count++) {
1606 /* not sure whether we need evclk or not */
1607 table->SamuLevel[count].Frequency = mm_table->entries[count].samclock;
1608 table->SamuLevel[count].MinVoltage |= (mm_table->entries[count].vddc *
1609 VOLTAGE_SCALE) << VDDC_SHIFT;
1610 table->SamuLevel[count].MinVoltage |= ((mm_table->entries[count].vddc -
1611 data->vddc_vddci_delta) * VOLTAGE_SCALE) << VDDCI_SHIFT;
1612 table->SamuLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
1614 /* retrieve divider value for VBIOS */
1615 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
1616 table->SamuLevel[count].Frequency, ÷rs);
1617 PP_ASSERT_WITH_CODE((0 == result),
1618 "can not find divide id for samu clock", return result);
1620 table->SamuLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
1622 CONVERT_FROM_HOST_TO_SMC_UL(table->SamuLevel[count].Frequency);
1623 CONVERT_FROM_HOST_TO_SMC_UL(table->SamuLevel[count].MinVoltage);
1628 static int polaris10_populate_memory_timing_parameters(struct pp_hwmgr *hwmgr,
1629 int32_t eng_clock, int32_t mem_clock,
1630 SMU74_Discrete_MCArbDramTimingTableEntry *arb_regs)
1632 uint32_t dram_timing;
1633 uint32_t dram_timing2;
1634 uint32_t burst_time;
1637 result = atomctrl_set_engine_dram_timings_rv770(hwmgr,
1638 eng_clock, mem_clock);
1639 PP_ASSERT_WITH_CODE(result == 0,
1640 "Error calling VBIOS to set DRAM_TIMING.", return result);
1642 dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
1643 dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
1644 burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0);
1647 arb_regs->McArbDramTiming = PP_HOST_TO_SMC_UL(dram_timing);
1648 arb_regs->McArbDramTiming2 = PP_HOST_TO_SMC_UL(dram_timing2);
1649 arb_regs->McArbBurstTime = (uint8_t)burst_time;
1654 static int polaris10_program_memory_timing_parameters(struct pp_hwmgr *hwmgr)
1656 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1657 struct SMU74_Discrete_MCArbDramTimingTable arb_regs;
1661 for (i = 0; i < data->dpm_table.sclk_table.count; i++) {
1662 for (j = 0; j < data->dpm_table.mclk_table.count; j++) {
1663 result = polaris10_populate_memory_timing_parameters(hwmgr,
1664 data->dpm_table.sclk_table.dpm_levels[i].value,
1665 data->dpm_table.mclk_table.dpm_levels[j].value,
1666 &arb_regs.entries[i][j]);
1668 result = atomctrl_set_ac_timing_ai(hwmgr, data->dpm_table.mclk_table.dpm_levels[j].value, j);
1674 result = polaris10_copy_bytes_to_smc(
1676 data->arb_table_start,
1677 (uint8_t *)&arb_regs,
1678 sizeof(SMU74_Discrete_MCArbDramTimingTable),
1683 static int polaris10_populate_smc_uvd_level(struct pp_hwmgr *hwmgr,
1684 struct SMU74_Discrete_DpmTable *table)
1686 int result = -EINVAL;
1688 struct pp_atomctrl_clock_dividers_vi dividers;
1689 struct phm_ppt_v1_information *table_info =
1690 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1691 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
1692 table_info->mm_dep_table;
1693 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1695 table->UvdLevelCount = (uint8_t)(mm_table->count);
1696 table->UvdBootLevel = 0;
1698 for (count = 0; count < table->UvdLevelCount; count++) {
1699 table->UvdLevel[count].VclkFrequency = mm_table->entries[count].vclk;
1700 table->UvdLevel[count].DclkFrequency = mm_table->entries[count].dclk;
1701 table->UvdLevel[count].MinVoltage |= (mm_table->entries[count].vddc *
1702 VOLTAGE_SCALE) << VDDC_SHIFT;
1703 table->UvdLevel[count].MinVoltage |= ((mm_table->entries[count].vddc -
1704 data->vddc_vddci_delta) * VOLTAGE_SCALE) << VDDCI_SHIFT;
1705 table->UvdLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
1707 /* retrieve divider value for VBIOS */
1708 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
1709 table->UvdLevel[count].VclkFrequency, ÷rs);
1710 PP_ASSERT_WITH_CODE((0 == result),
1711 "can not find divide id for Vclk clock", return result);
1713 table->UvdLevel[count].VclkDivider = (uint8_t)dividers.pll_post_divider;
1715 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
1716 table->UvdLevel[count].DclkFrequency, ÷rs);
1717 PP_ASSERT_WITH_CODE((0 == result),
1718 "can not find divide id for Dclk clock", return result);
1720 table->UvdLevel[count].DclkDivider = (uint8_t)dividers.pll_post_divider;
1722 CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].VclkFrequency);
1723 CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].DclkFrequency);
1724 CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].MinVoltage);
1730 static int polaris10_populate_smc_boot_level(struct pp_hwmgr *hwmgr,
1731 struct SMU74_Discrete_DpmTable *table)
1734 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1736 table->GraphicsBootLevel = 0;
1737 table->MemoryBootLevel = 0;
1739 /* find boot level from dpm table */
1740 result = phm_find_boot_level(&(data->dpm_table.sclk_table),
1741 data->vbios_boot_state.sclk_bootup_value,
1742 (uint32_t *)&(table->GraphicsBootLevel));
1744 result = phm_find_boot_level(&(data->dpm_table.mclk_table),
1745 data->vbios_boot_state.mclk_bootup_value,
1746 (uint32_t *)&(table->MemoryBootLevel));
1748 table->BootVddc = data->vbios_boot_state.vddc_bootup_value *
1750 table->BootVddci = data->vbios_boot_state.vddci_bootup_value *
1752 table->BootMVdd = data->vbios_boot_state.mvdd_bootup_value *
1755 CONVERT_FROM_HOST_TO_SMC_US(table->BootVddc);
1756 CONVERT_FROM_HOST_TO_SMC_US(table->BootVddci);
1757 CONVERT_FROM_HOST_TO_SMC_US(table->BootMVdd);
1763 static int polaris10_populate_smc_initailial_state(struct pp_hwmgr *hwmgr)
1765 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1766 struct phm_ppt_v1_information *table_info =
1767 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1768 uint8_t count, level;
1770 count = (uint8_t)(table_info->vdd_dep_on_sclk->count);
1772 for (level = 0; level < count; level++) {
1773 if (table_info->vdd_dep_on_sclk->entries[level].clk >=
1774 data->vbios_boot_state.sclk_bootup_value) {
1775 data->smc_state_table.GraphicsBootLevel = level;
1780 count = (uint8_t)(table_info->vdd_dep_on_mclk->count);
1781 for (level = 0; level < count; level++) {
1782 if (table_info->vdd_dep_on_mclk->entries[level].clk >=
1783 data->vbios_boot_state.mclk_bootup_value) {
1784 data->smc_state_table.MemoryBootLevel = level;
1792 static int polaris10_populate_clock_stretcher_data_table(struct pp_hwmgr *hwmgr)
1794 uint32_t ro, efuse, efuse2, clock_freq, volt_without_cks,
1795 volt_with_cks, value;
1796 uint16_t clock_freq_u16;
1797 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1798 uint8_t type, i, j, cks_setting, stretch_amount, stretch_amount2,
1800 struct phm_ppt_v1_information *table_info =
1801 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1802 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
1803 table_info->vdd_dep_on_sclk;
1805 stretch_amount = (uint8_t)table_info->cac_dtp_table->usClockStretchAmount;
1807 /* Read SMU_Eefuse to read and calculate RO and determine
1808 * if the part is SS or FF. if RO >= 1660MHz, part is FF.
1810 efuse = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1811 ixSMU_EFUSE_0 + (146 * 4));
1812 efuse2 = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1813 ixSMU_EFUSE_0 + (148 * 4));
1814 efuse &= 0xFF000000;
1815 efuse = efuse >> 24;
1819 ro = (2300 - 1350) * efuse / 255 + 1350;
1821 ro = (2500 - 1000) * efuse / 255 + 1000;
1828 /* Populate Stretch amount */
1829 data->smc_state_table.ClockStretcherAmount = stretch_amount;
1831 /* Populate Sclk_CKS_masterEn0_7 and Sclk_voltageOffset */
1832 for (i = 0; i < sclk_table->count; i++) {
1833 data->smc_state_table.Sclk_CKS_masterEn0_7 |=
1834 sclk_table->entries[i].cks_enable << i;
1835 volt_without_cks = (uint32_t)((14041 *
1836 (sclk_table->entries[i].clk/100) / 10000 + 3571 + 75 - ro) * 1000 /
1837 (4026 - (13924 * (sclk_table->entries[i].clk/100) / 10000)));
1838 volt_with_cks = (uint32_t)((13946 *
1839 (sclk_table->entries[i].clk/100) / 10000 + 3320 + 45 - ro) * 1000 /
1840 (3664 - (11454 * (sclk_table->entries[i].clk/100) / 10000)));
1841 if (volt_without_cks >= volt_with_cks)
1842 volt_offset = (uint8_t)(((volt_without_cks - volt_with_cks +
1843 sclk_table->entries[i].cks_voffset) * 100 / 625) + 1);
1844 data->smc_state_table.Sclk_voltageOffset[i] = volt_offset;
1847 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE,
1848 STRETCH_ENABLE, 0x0);
1849 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE,
1851 /* PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE, staticEnable, 0x1); */
1852 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE,
1855 /* Populate CKS Lookup Table */
1856 if (stretch_amount == 1 || stretch_amount == 2 || stretch_amount == 5)
1857 stretch_amount2 = 0;
1858 else if (stretch_amount == 3 || stretch_amount == 4)
1859 stretch_amount2 = 1;
1861 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1862 PHM_PlatformCaps_ClockStretcher);
1863 PP_ASSERT_WITH_CODE(false,
1864 "Stretch Amount in PPTable not supported\n",
1868 value = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1870 value &= 0xFFC2FF87;
1871 data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].minFreq =
1872 polaris10_clock_stretcher_lookup_table[stretch_amount2][0];
1873 data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].maxFreq =
1874 polaris10_clock_stretcher_lookup_table[stretch_amount2][1];
1875 clock_freq_u16 = (uint16_t)(PP_SMC_TO_HOST_UL(data->smc_state_table.
1876 GraphicsLevel[data->smc_state_table.GraphicsDpmLevelCount - 1].SclkSetting.SclkFrequency) / 100);
1877 if (polaris10_clock_stretcher_lookup_table[stretch_amount2][0] < clock_freq_u16
1878 && polaris10_clock_stretcher_lookup_table[stretch_amount2][1] > clock_freq_u16) {
1879 /* Program PWR_CKS_CNTL. CKS_USE_FOR_LOW_FREQ */
1880 value |= (polaris10_clock_stretcher_lookup_table[stretch_amount2][3]) << 16;
1881 /* Program PWR_CKS_CNTL. CKS_LDO_REFSEL */
1882 value |= (polaris10_clock_stretcher_lookup_table[stretch_amount2][2]) << 18;
1883 /* Program PWR_CKS_CNTL. CKS_STRETCH_AMOUNT */
1884 value |= (polaris10_clock_stretch_amount_conversion
1885 [polaris10_clock_stretcher_lookup_table[stretch_amount2][3]]
1886 [stretch_amount]) << 3;
1888 CONVERT_FROM_HOST_TO_SMC_US(data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].minFreq);
1889 CONVERT_FROM_HOST_TO_SMC_US(data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].maxFreq);
1890 data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].setting =
1891 polaris10_clock_stretcher_lookup_table[stretch_amount2][2] & 0x7F;
1892 data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].setting |=
1893 (polaris10_clock_stretcher_lookup_table[stretch_amount2][3]) << 7;
1895 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1896 ixPWR_CKS_CNTL, value);
1898 /* Populate DDT Lookup Table */
1899 for (i = 0; i < 4; i++) {
1900 /* Assign the minimum and maximum VID stored
1901 * in the last row of Clock Stretcher Voltage Table.
1903 data->smc_state_table.ClockStretcherDataTable.ClockStretcherDataTableEntry[i].minVID =
1904 (uint8_t) polaris10_clock_stretcher_ddt_table[type][i][2];
1905 data->smc_state_table.ClockStretcherDataTable.ClockStretcherDataTableEntry[i].maxVID =
1906 (uint8_t) polaris10_clock_stretcher_ddt_table[type][i][3];
1907 /* Loop through each SCLK and check the frequency
1908 * to see if it lies within the frequency for clock stretcher.
1910 for (j = 0; j < data->smc_state_table.GraphicsDpmLevelCount; j++) {
1912 clock_freq = PP_SMC_TO_HOST_UL(
1913 data->smc_state_table.GraphicsLevel[j].SclkSetting.SclkFrequency);
1914 /* Check the allowed frequency against the sclk level[j].
1915 * Sclk's endianness has already been converted,
1916 * and it's in 10Khz unit,
1917 * as opposed to Data table, which is in Mhz unit.
1919 if (clock_freq >= (polaris10_clock_stretcher_ddt_table[type][i][0]) * 100) {
1921 if (clock_freq < (polaris10_clock_stretcher_ddt_table[type][i][1]) * 100)
1924 data->smc_state_table.ClockStretcherDataTable.ClockStretcherDataTableEntry[i].setting
1925 |= cks_setting << (j * 2);
1927 CONVERT_FROM_HOST_TO_SMC_US(
1928 data->smc_state_table.ClockStretcherDataTable.ClockStretcherDataTableEntry[i].setting);
1931 value = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixPWR_CKS_CNTL);
1932 value &= 0xFFFFFFFE;
1933 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixPWR_CKS_CNTL, value);
1939 * Populates the SMC VRConfig field in DPM table.
1941 * @param hwmgr the address of the hardware manager
1942 * @param table the SMC DPM table structure to be populated
1945 static int polaris10_populate_vr_config(struct pp_hwmgr *hwmgr,
1946 struct SMU74_Discrete_DpmTable *table)
1948 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1951 config = VR_MERGED_WITH_VDDC;
1952 table->VRConfig |= (config << VRCONF_VDDGFX_SHIFT);
1954 /* Set Vddc Voltage Controller */
1955 if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
1956 config = VR_SVI2_PLANE_1;
1957 table->VRConfig |= config;
1959 PP_ASSERT_WITH_CODE(false,
1960 "VDDC should be on SVI2 control in merged mode!",
1963 /* Set Vddci Voltage Controller */
1964 if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) {
1965 config = VR_SVI2_PLANE_2; /* only in merged mode */
1966 table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
1967 } else if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
1968 config = VR_SMIO_PATTERN_1;
1969 table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
1971 config = VR_STATIC_VOLTAGE;
1972 table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
1974 /* Set Mvdd Voltage Controller */
1975 if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) {
1976 config = VR_SVI2_PLANE_2;
1977 table->VRConfig |= (config << VRCONF_MVDD_SHIFT);
1978 } else if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
1979 config = VR_SMIO_PATTERN_2;
1980 table->VRConfig |= (config << VRCONF_MVDD_SHIFT);
1982 config = VR_STATIC_VOLTAGE;
1983 table->VRConfig |= (config << VRCONF_MVDD_SHIFT);
1990 * Initializes the SMC table and uploads it
1992 * @param hwmgr the address of the powerplay hardware manager.
1995 static int polaris10_init_smc_table(struct pp_hwmgr *hwmgr)
1998 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
1999 struct phm_ppt_v1_information *table_info =
2000 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2001 struct SMU74_Discrete_DpmTable *table = &(data->smc_state_table);
2002 const struct polaris10_ulv_parm *ulv = &(data->ulv);
2004 struct pp_atomctrl_gpio_pin_assignment gpio_pin;
2005 pp_atomctrl_clock_dividers_vi dividers;
2007 result = polaris10_setup_default_dpm_tables(hwmgr);
2008 PP_ASSERT_WITH_CODE(0 == result,
2009 "Failed to setup default DPM tables!", return result);
2011 if (POLARIS10_VOLTAGE_CONTROL_NONE != data->voltage_control)
2012 polaris10_populate_smc_voltage_tables(hwmgr, table);
2014 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2015 PHM_PlatformCaps_AutomaticDCTransition))
2016 table->SystemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC;
2018 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2019 PHM_PlatformCaps_StepVddc))
2020 table->SystemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC;
2022 if (data->is_memory_gddr5)
2023 table->SystemFlags |= PPSMC_SYSTEMFLAG_GDDR5;
2025 if (ulv->ulv_supported && table_info->us_ulv_voltage_offset) {
2026 result = polaris10_populate_ulv_state(hwmgr, table);
2027 PP_ASSERT_WITH_CODE(0 == result,
2028 "Failed to initialize ULV state!", return result);
2029 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2030 ixCG_ULV_PARAMETER, PPPOLARIS10_CGULVPARAMETER_DFLT);
2033 result = polaris10_populate_smc_link_level(hwmgr, table);
2034 PP_ASSERT_WITH_CODE(0 == result,
2035 "Failed to initialize Link Level!", return result);
2037 result = polaris10_populate_all_graphic_levels(hwmgr);
2038 PP_ASSERT_WITH_CODE(0 == result,
2039 "Failed to initialize Graphics Level!", return result);
2041 result = polaris10_populate_all_memory_levels(hwmgr);
2042 PP_ASSERT_WITH_CODE(0 == result,
2043 "Failed to initialize Memory Level!", return result);
2045 result = polaris10_populate_smc_acpi_level(hwmgr, table);
2046 PP_ASSERT_WITH_CODE(0 == result,
2047 "Failed to initialize ACPI Level!", return result);
2049 result = polaris10_populate_smc_vce_level(hwmgr, table);
2050 PP_ASSERT_WITH_CODE(0 == result,
2051 "Failed to initialize VCE Level!", return result);
2053 result = polaris10_populate_smc_samu_level(hwmgr, table);
2054 PP_ASSERT_WITH_CODE(0 == result,
2055 "Failed to initialize SAMU Level!", return result);
2057 /* Since only the initial state is completely set up at this point
2058 * (the other states are just copies of the boot state) we only
2059 * need to populate the ARB settings for the initial state.
2061 result = polaris10_program_memory_timing_parameters(hwmgr);
2062 PP_ASSERT_WITH_CODE(0 == result,
2063 "Failed to Write ARB settings for the initial state.", return result);
2065 result = polaris10_populate_smc_uvd_level(hwmgr, table);
2066 PP_ASSERT_WITH_CODE(0 == result,
2067 "Failed to initialize UVD Level!", return result);
2069 result = polaris10_populate_smc_boot_level(hwmgr, table);
2070 PP_ASSERT_WITH_CODE(0 == result,
2071 "Failed to initialize Boot Level!", return result);
2073 result = polaris10_populate_smc_initailial_state(hwmgr);
2074 PP_ASSERT_WITH_CODE(0 == result,
2075 "Failed to initialize Boot State!", return result);
2077 result = polaris10_populate_bapm_parameters_in_dpm_table(hwmgr);
2078 PP_ASSERT_WITH_CODE(0 == result,
2079 "Failed to populate BAPM Parameters!", return result);
2081 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2082 PHM_PlatformCaps_ClockStretcher)) {
2083 result = polaris10_populate_clock_stretcher_data_table(hwmgr);
2084 PP_ASSERT_WITH_CODE(0 == result,
2085 "Failed to populate Clock Stretcher Data Table!",
2089 table->GraphicsVoltageChangeEnable = 1;
2090 table->GraphicsThermThrottleEnable = 1;
2091 table->GraphicsInterval = 1;
2092 table->VoltageInterval = 1;
2093 table->ThermalInterval = 1;
2094 table->TemperatureLimitHigh =
2095 table_info->cac_dtp_table->usTargetOperatingTemp *
2096 POLARIS10_Q88_FORMAT_CONVERSION_UNIT;
2097 table->TemperatureLimitLow =
2098 (table_info->cac_dtp_table->usTargetOperatingTemp - 1) *
2099 POLARIS10_Q88_FORMAT_CONVERSION_UNIT;
2100 table->MemoryVoltageChangeEnable = 1;
2101 table->MemoryInterval = 1;
2102 table->VoltageResponseTime = 0;
2103 table->PhaseResponseTime = 0;
2104 table->MemoryThermThrottleEnable = 1;
2105 table->PCIeBootLinkLevel = 0;
2106 table->PCIeGenInterval = 1;
2108 result = polaris10_populate_vr_config(hwmgr, table);
2109 PP_ASSERT_WITH_CODE(0 == result,
2110 "Failed to populate VRConfig setting!", return result);
2112 table->ThermGpio = 17;
2113 table->SclkStepSize = 0x4000;
2115 if (atomctrl_get_pp_assign_pin(hwmgr, VDDC_VRHOT_GPIO_PINID, &gpio_pin)) {
2116 table->VRHotGpio = gpio_pin.uc_gpio_pin_bit_shift;
2118 table->VRHotGpio = POLARIS10_UNUSED_GPIO_PIN;
2119 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2120 PHM_PlatformCaps_RegulatorHot);
2123 if (atomctrl_get_pp_assign_pin(hwmgr, PP_AC_DC_SWITCH_GPIO_PINID,
2125 table->AcDcGpio = gpio_pin.uc_gpio_pin_bit_shift;
2126 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2127 PHM_PlatformCaps_AutomaticDCTransition);
2129 table->AcDcGpio = POLARIS10_UNUSED_GPIO_PIN;
2130 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2131 PHM_PlatformCaps_AutomaticDCTransition);
2134 /* Thermal Output GPIO */
2135 if (atomctrl_get_pp_assign_pin(hwmgr, THERMAL_INT_OUTPUT_GPIO_PINID,
2137 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2138 PHM_PlatformCaps_ThermalOutGPIO);
2140 table->ThermOutGpio = gpio_pin.uc_gpio_pin_bit_shift;
2142 /* For porlarity read GPIOPAD_A with assigned Gpio pin
2143 * since VBIOS will program this register to set 'inactive state',
2144 * driver can then determine 'active state' from this and
2145 * program SMU with correct polarity
2147 table->ThermOutPolarity = (0 == (cgs_read_register(hwmgr->device, mmGPIOPAD_A)
2148 & (1 << gpio_pin.uc_gpio_pin_bit_shift))) ? 1:0;
2149 table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_ONLY;
2151 /* if required, combine VRHot/PCC with thermal out GPIO */
2152 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_RegulatorHot)
2153 && phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_CombinePCCWithThermalSignal))
2154 table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_VRHOT;
2156 table->ThermOutGpio = 17;
2157 table->ThermOutPolarity = 1;
2158 table->ThermOutMode = SMU7_THERM_OUT_MODE_DISABLE;
2161 /* Populate BIF_SCLK levels into SMC DPM table */
2162 for (i = 0; i <= data->dpm_table.pcie_speed_table.count; i++) {
2163 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr, data->bif_sclk_table[i], ÷rs);
2164 PP_ASSERT_WITH_CODE((result == 0), "Can not find DFS divide id for Sclk", return result);
2167 table->Ulv.BifSclkDfs = PP_HOST_TO_SMC_US((USHORT)(dividers.pll_post_divider));
2169 table->LinkLevel[i-1].BifSclkDfs = PP_HOST_TO_SMC_US((USHORT)(dividers.pll_post_divider));
2172 for (i = 0; i < SMU74_MAX_ENTRIES_SMIO; i++)
2173 table->Smio[i] = PP_HOST_TO_SMC_UL(table->Smio[i]);
2175 CONVERT_FROM_HOST_TO_SMC_UL(table->SystemFlags);
2176 CONVERT_FROM_HOST_TO_SMC_UL(table->VRConfig);
2177 CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask1);
2178 CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask2);
2179 CONVERT_FROM_HOST_TO_SMC_UL(table->SclkStepSize);
2180 CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitHigh);
2181 CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitLow);
2182 CONVERT_FROM_HOST_TO_SMC_US(table->VoltageResponseTime);
2183 CONVERT_FROM_HOST_TO_SMC_US(table->PhaseResponseTime);
2185 /* Upload all dpm data to SMC memory.(dpm level, dpm level count etc) */
2186 result = polaris10_copy_bytes_to_smc(hwmgr->smumgr,
2187 data->dpm_table_start +
2188 offsetof(SMU74_Discrete_DpmTable, SystemFlags),
2189 (uint8_t *)&(table->SystemFlags),
2190 sizeof(SMU74_Discrete_DpmTable) - 3 * sizeof(SMU74_PIDController),
2192 PP_ASSERT_WITH_CODE(0 == result,
2193 "Failed to upload dpm data to SMC memory!", return result);
2199 * Initialize the ARB DRAM timing table's index field.
2201 * @param hwmgr the address of the powerplay hardware manager.
2204 static int polaris10_init_arb_table_index(struct pp_hwmgr *hwmgr)
2206 const struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2210 /* This is a read-modify-write on the first byte of the ARB table.
2211 * The first byte in the SMU73_Discrete_MCArbDramTimingTable structure
2212 * is the field 'current'.
2213 * This solution is ugly, but we never write the whole table only
2214 * individual fields in it.
2215 * In reality this field should not be in that structure
2216 * but in a soft register.
2218 result = polaris10_read_smc_sram_dword(hwmgr->smumgr,
2219 data->arb_table_start, &tmp, data->sram_end);
2225 tmp |= ((uint32_t)MC_CG_ARB_FREQ_F1) << 24;
2227 return polaris10_write_smc_sram_dword(hwmgr->smumgr,
2228 data->arb_table_start, tmp, data->sram_end);
2231 static int polaris10_enable_vrhot_gpio_interrupt(struct pp_hwmgr *hwmgr)
2233 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2234 PHM_PlatformCaps_RegulatorHot))
2235 return smum_send_msg_to_smc(hwmgr->smumgr,
2236 PPSMC_MSG_EnableVRHotGPIOInterrupt);
2241 static int polaris10_enable_sclk_control(struct pp_hwmgr *hwmgr)
2243 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
2244 SCLK_PWRMGT_OFF, 0);
2248 static int polaris10_enable_ulv(struct pp_hwmgr *hwmgr)
2250 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2251 struct polaris10_ulv_parm *ulv = &(data->ulv);
2253 if (ulv->ulv_supported)
2254 return smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_EnableULV);
2259 static int polaris10_enable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
2261 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2262 PHM_PlatformCaps_SclkDeepSleep)) {
2263 if (smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_MASTER_DeepSleep_ON))
2264 PP_ASSERT_WITH_CODE(false,
2265 "Attempt to enable Master Deep Sleep switch failed!",
2268 if (smum_send_msg_to_smc(hwmgr->smumgr,
2269 PPSMC_MSG_MASTER_DeepSleep_OFF)) {
2270 PP_ASSERT_WITH_CODE(false,
2271 "Attempt to disable Master Deep Sleep switch failed!",
2279 static int polaris10_enable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
2281 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2283 /* enable SCLK dpm */
2284 if (!data->sclk_dpm_key_disabled)
2285 PP_ASSERT_WITH_CODE(
2286 (0 == smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_DPM_Enable)),
2287 "Failed to enable SCLK DPM during DPM Start Function!",
2290 /* enable MCLK dpm */
2291 if (0 == data->mclk_dpm_key_disabled) {
2293 PP_ASSERT_WITH_CODE(
2294 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
2295 PPSMC_MSG_MCLKDPM_Enable)),
2296 "Failed to enable MCLK DPM during DPM Start Function!",
2300 PHM_WRITE_FIELD(hwmgr->device, MC_SEQ_CNTL_3, CAC_EN, 0x1);
2302 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC0_CNTL, 0x5);
2303 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC1_CNTL, 0x5);
2304 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_CPL_CNTL, 0x100005);
2306 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC0_CNTL, 0x400005);
2307 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC1_CNTL, 0x400005);
2308 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_CPL_CNTL, 0x500005);
2314 static int polaris10_start_dpm(struct pp_hwmgr *hwmgr)
2316 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2318 /*enable general power management */
2320 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
2321 GLOBAL_PWRMGT_EN, 1);
2323 /* enable sclk deep sleep */
2325 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
2328 /* prepare for PCIE DPM */
2330 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2331 data->soft_regs_start + offsetof(SMU74_SoftRegisters,
2332 VoltageChangeTimeout), 0x1000);
2333 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE,
2334 SWRST_COMMAND_1, RESETLC, 0x0);
2336 PP_ASSERT_WITH_CODE(
2337 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
2338 PPSMC_MSG_Voltage_Cntl_Enable)),
2339 "Failed to enable voltage DPM during DPM Start Function!",
2343 if (polaris10_enable_sclk_mclk_dpm(hwmgr)) {
2344 printk(KERN_ERR "Failed to enable Sclk DPM and Mclk DPM!");
2348 /* enable PCIE dpm */
2349 if (0 == data->pcie_dpm_key_disabled) {
2350 PP_ASSERT_WITH_CODE(
2351 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
2352 PPSMC_MSG_PCIeDPM_Enable)),
2353 "Failed to enable pcie DPM during DPM Start Function!",
2357 PP_ASSERT_WITH_CODE((0 == smum_send_msg_to_smc(hwmgr->smumgr,
2358 PPSMC_MSG_EnableACDCGPIOInterrupt)),
2359 "Failed to enable AC DC GPIO Interrupt!",
2365 static void polaris10_set_dpm_event_sources(struct pp_hwmgr *hwmgr, uint32_t sources)
2368 enum DPM_EVENT_SRC src;
2372 printk(KERN_ERR "Unknown throttling event sources.");
2378 case (1 << PHM_AutoThrottleSource_Thermal):
2380 src = DPM_EVENT_SRC_DIGITAL;
2382 case (1 << PHM_AutoThrottleSource_External):
2384 src = DPM_EVENT_SRC_EXTERNAL;
2386 case (1 << PHM_AutoThrottleSource_External) |
2387 (1 << PHM_AutoThrottleSource_Thermal):
2389 src = DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL;
2392 /* Order matters - don't enable thermal protection for the wrong source. */
2394 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_THERMAL_CTRL,
2395 DPM_EVENT_SRC, src);
2396 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
2397 THERMAL_PROTECTION_DIS,
2398 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2399 PHM_PlatformCaps_ThermalController));
2401 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
2402 THERMAL_PROTECTION_DIS, 1);
2405 static int polaris10_enable_auto_throttle_source(struct pp_hwmgr *hwmgr,
2406 PHM_AutoThrottleSource source)
2408 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2410 if (!(data->active_auto_throttle_sources & (1 << source))) {
2411 data->active_auto_throttle_sources |= 1 << source;
2412 polaris10_set_dpm_event_sources(hwmgr, data->active_auto_throttle_sources);
2417 static int polaris10_enable_thermal_auto_throttle(struct pp_hwmgr *hwmgr)
2419 return polaris10_enable_auto_throttle_source(hwmgr, PHM_AutoThrottleSource_Thermal);
2422 int polaris10_pcie_performance_request(struct pp_hwmgr *hwmgr)
2424 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2425 data->pcie_performance_request = true;
2430 int polaris10_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
2432 int tmp_result, result = 0;
2433 tmp_result = (!polaris10_is_dpm_running(hwmgr)) ? 0 : -1;
2434 PP_ASSERT_WITH_CODE(result == 0,
2435 "DPM is already running right now, no need to enable DPM!",
2438 if (polaris10_voltage_control(hwmgr)) {
2439 tmp_result = polaris10_enable_voltage_control(hwmgr);
2440 PP_ASSERT_WITH_CODE(tmp_result == 0,
2441 "Failed to enable voltage control!",
2442 result = tmp_result);
2444 tmp_result = polaris10_construct_voltage_tables(hwmgr);
2445 PP_ASSERT_WITH_CODE((0 == tmp_result),
2446 "Failed to contruct voltage tables!",
2447 result = tmp_result);
2450 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2451 PHM_PlatformCaps_EngineSpreadSpectrumSupport))
2452 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
2453 GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, 1);
2455 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2456 PHM_PlatformCaps_ThermalController))
2457 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
2458 GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, 0);
2460 tmp_result = polaris10_program_static_screen_threshold_parameters(hwmgr);
2461 PP_ASSERT_WITH_CODE((0 == tmp_result),
2462 "Failed to program static screen threshold parameters!",
2463 result = tmp_result);
2465 tmp_result = polaris10_enable_display_gap(hwmgr);
2466 PP_ASSERT_WITH_CODE((0 == tmp_result),
2467 "Failed to enable display gap!", result = tmp_result);
2469 tmp_result = polaris10_program_voting_clients(hwmgr);
2470 PP_ASSERT_WITH_CODE((0 == tmp_result),
2471 "Failed to program voting clients!", result = tmp_result);
2473 tmp_result = polaris10_process_firmware_header(hwmgr);
2474 PP_ASSERT_WITH_CODE((0 == tmp_result),
2475 "Failed to process firmware header!", result = tmp_result);
2477 tmp_result = polaris10_initial_switch_from_arbf0_to_f1(hwmgr);
2478 PP_ASSERT_WITH_CODE((0 == tmp_result),
2479 "Failed to initialize switch from ArbF0 to F1!",
2480 result = tmp_result);
2482 tmp_result = polaris10_init_smc_table(hwmgr);
2483 PP_ASSERT_WITH_CODE((0 == tmp_result),
2484 "Failed to initialize SMC table!", result = tmp_result);
2486 tmp_result = polaris10_init_arb_table_index(hwmgr);
2487 PP_ASSERT_WITH_CODE((0 == tmp_result),
2488 "Failed to initialize ARB table index!", result = tmp_result);
2490 tmp_result = polaris10_populate_pm_fuses(hwmgr);
2491 PP_ASSERT_WITH_CODE((0 == tmp_result),
2492 "Failed to populate PM fuses!", result = tmp_result);
2494 tmp_result = polaris10_enable_vrhot_gpio_interrupt(hwmgr);
2495 PP_ASSERT_WITH_CODE((0 == tmp_result),
2496 "Failed to enable VR hot GPIO interrupt!", result = tmp_result);
2498 tmp_result = polaris10_enable_sclk_control(hwmgr);
2499 PP_ASSERT_WITH_CODE((0 == tmp_result),
2500 "Failed to enable SCLK control!", result = tmp_result);
2502 tmp_result = polaris10_enable_smc_voltage_controller(hwmgr);
2503 PP_ASSERT_WITH_CODE((0 == tmp_result),
2504 "Failed to enable voltage control!", result = tmp_result);
2506 tmp_result = polaris10_enable_ulv(hwmgr);
2507 PP_ASSERT_WITH_CODE((0 == tmp_result),
2508 "Failed to enable ULV!", result = tmp_result);
2510 tmp_result = polaris10_enable_deep_sleep_master_switch(hwmgr);
2511 PP_ASSERT_WITH_CODE((0 == tmp_result),
2512 "Failed to enable deep sleep master switch!", result = tmp_result);
2514 tmp_result = polaris10_start_dpm(hwmgr);
2515 PP_ASSERT_WITH_CODE((0 == tmp_result),
2516 "Failed to start DPM!", result = tmp_result);
2518 tmp_result = polaris10_enable_smc_cac(hwmgr);
2519 PP_ASSERT_WITH_CODE((0 == tmp_result),
2520 "Failed to enable SMC CAC!", result = tmp_result);
2522 tmp_result = polaris10_enable_power_containment(hwmgr);
2523 PP_ASSERT_WITH_CODE((0 == tmp_result),
2524 "Failed to enable power containment!", result = tmp_result);
2526 tmp_result = polaris10_power_control_set_level(hwmgr);
2527 PP_ASSERT_WITH_CODE((0 == tmp_result),
2528 "Failed to power control set level!", result = tmp_result);
2530 tmp_result = polaris10_enable_thermal_auto_throttle(hwmgr);
2531 PP_ASSERT_WITH_CODE((0 == tmp_result),
2532 "Failed to enable thermal auto throttle!", result = tmp_result);
2534 tmp_result = polaris10_pcie_performance_request(hwmgr);
2535 PP_ASSERT_WITH_CODE((0 == tmp_result),
2536 "Failed to enable thermal auto throttle!", result = tmp_result);
2541 int polaris10_disable_dpm_tasks(struct pp_hwmgr *hwmgr)
2547 int polaris10_reset_asic_tasks(struct pp_hwmgr *hwmgr)
2553 int polaris10_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)
2555 return phm_hwmgr_backend_fini(hwmgr);
2558 int polaris10_set_features_platform_caps(struct pp_hwmgr *hwmgr)
2560 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2562 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2563 PHM_PlatformCaps_SclkDeepSleep);
2565 if (data->mvdd_control == POLARIS10_VOLTAGE_CONTROL_NONE)
2566 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2567 PHM_PlatformCaps_EnableMVDDControl);
2569 if (data->vddci_control == POLARIS10_VOLTAGE_CONTROL_NONE)
2570 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2571 PHM_PlatformCaps_ControlVDDCI);
2573 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2574 PHM_PlatformCaps_TablelessHardwareInterface);
2576 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2577 PHM_PlatformCaps_EnableSMU7ThermalManagement);
2579 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2580 PHM_PlatformCaps_DynamicPowerManagement);
2582 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2583 PHM_PlatformCaps_TablelessHardwareInterface);
2585 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2586 PHM_PlatformCaps_SMC);
2588 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2589 PHM_PlatformCaps_NonABMSupportInPPLib);
2591 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2592 PHM_PlatformCaps_DynamicUVDState);
2594 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2595 PHM_PlatformCaps_SclkThrottleLowNotification);
2597 /* power tune caps Assume disabled */
2598 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2599 PHM_PlatformCaps_PowerContainment);
2600 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2601 PHM_PlatformCaps_CAC);
2602 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2603 PHM_PlatformCaps_SQRamping);
2604 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2605 PHM_PlatformCaps_DBRamping);
2606 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2607 PHM_PlatformCaps_TDRamping);
2608 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2609 PHM_PlatformCaps_TCPRamping);
2611 if (hwmgr->chip_id == CHIP_POLARIS11)
2612 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2613 PHM_PlatformCaps_SPLLShutdownSupport);
2617 static void polaris10_init_dpm_defaults(struct pp_hwmgr *hwmgr)
2619 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2621 polaris10_initialize_power_tune_defaults(hwmgr);
2623 data->pcie_gen_performance.max = PP_PCIEGen1;
2624 data->pcie_gen_performance.min = PP_PCIEGen3;
2625 data->pcie_gen_power_saving.max = PP_PCIEGen1;
2626 data->pcie_gen_power_saving.min = PP_PCIEGen3;
2627 data->pcie_lane_performance.max = 0;
2628 data->pcie_lane_performance.min = 16;
2629 data->pcie_lane_power_saving.max = 0;
2630 data->pcie_lane_power_saving.min = 16;
2634 * Get Leakage VDDC based on leakage ID.
2636 * @param hwmgr the address of the powerplay hardware manager.
2639 static int polaris10_get_evv_voltages(struct pp_hwmgr *hwmgr)
2641 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2646 struct phm_ppt_v1_information *table_info =
2647 (struct phm_ppt_v1_information *)hwmgr->pptable;
2648 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
2649 table_info->vdd_dep_on_sclk;
2652 for (i = 0; i < POLARIS10_MAX_LEAKAGE_COUNT; i++) {
2653 vv_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i;
2654 if (!phm_get_sclk_for_voltage_evv(hwmgr,
2655 table_info->vddc_lookup_table, vv_id, &sclk)) {
2656 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2657 PHM_PlatformCaps_ClockStretcher)) {
2658 for (j = 1; j < sclk_table->count; j++) {
2659 if (sclk_table->entries[j].clk == sclk &&
2660 sclk_table->entries[j].cks_enable == 0) {
2668 PP_ASSERT_WITH_CODE(0 == atomctrl_get_voltage_evv_on_sclk_ai(hwmgr,
2669 VOLTAGE_TYPE_VDDC, sclk, vv_id, &vddc),
2670 "Error retrieving EVV voltage value!",
2674 /* need to make sure vddc is less than 2v or else, it could burn the ASIC. */
2675 PP_ASSERT_WITH_CODE((vddc < 2000 && vddc != 0),
2676 "Invalid VDDC value", result = -EINVAL;);
2678 /* the voltage should not be zero nor equal to leakage ID */
2679 if (vddc != 0 && vddc != vv_id) {
2680 data->vddc_leakage.actual_voltage[data->vddc_leakage.count] = (uint16_t)(vddc/100);
2681 data->vddc_leakage.leakage_id[data->vddc_leakage.count] = vv_id;
2682 data->vddc_leakage.count++;
2691 * Change virtual leakage voltage to actual value.
2693 * @param hwmgr the address of the powerplay hardware manager.
2694 * @param pointer to changing voltage
2695 * @param pointer to leakage table
2697 static void polaris10_patch_with_vdd_leakage(struct pp_hwmgr *hwmgr,
2698 uint16_t *voltage, struct polaris10_leakage_voltage *leakage_table)
2702 /* search for leakage voltage ID 0xff01 ~ 0xff08 */
2703 for (index = 0; index < leakage_table->count; index++) {
2704 /* if this voltage matches a leakage voltage ID */
2705 /* patch with actual leakage voltage */
2706 if (leakage_table->leakage_id[index] == *voltage) {
2707 *voltage = leakage_table->actual_voltage[index];
2712 if (*voltage > ATOM_VIRTUAL_VOLTAGE_ID0)
2713 printk(KERN_ERR "Voltage value looks like a Leakage ID but it's not patched \n");
2717 * Patch voltage lookup table by EVV leakages.
2719 * @param hwmgr the address of the powerplay hardware manager.
2720 * @param pointer to voltage lookup table
2721 * @param pointer to leakage table
2724 static int polaris10_patch_lookup_table_with_leakage(struct pp_hwmgr *hwmgr,
2725 phm_ppt_v1_voltage_lookup_table *lookup_table,
2726 struct polaris10_leakage_voltage *leakage_table)
2730 for (i = 0; i < lookup_table->count; i++)
2731 polaris10_patch_with_vdd_leakage(hwmgr,
2732 &lookup_table->entries[i].us_vdd, leakage_table);
2737 static int polaris10_patch_clock_voltage_limits_with_vddc_leakage(
2738 struct pp_hwmgr *hwmgr, struct polaris10_leakage_voltage *leakage_table,
2741 struct phm_ppt_v1_information *table_info =
2742 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2743 polaris10_patch_with_vdd_leakage(hwmgr, (uint16_t *)vddc, leakage_table);
2744 hwmgr->dyn_state.max_clock_voltage_on_dc.vddc =
2745 table_info->max_clock_voltage_on_dc.vddc;
2749 static int polaris10_patch_voltage_dependency_tables_with_lookup_table(
2750 struct pp_hwmgr *hwmgr)
2754 struct phm_ppt_v1_information *table_info =
2755 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2757 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
2758 table_info->vdd_dep_on_sclk;
2759 struct phm_ppt_v1_clock_voltage_dependency_table *mclk_table =
2760 table_info->vdd_dep_on_mclk;
2761 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
2762 table_info->mm_dep_table;
2764 for (entryId = 0; entryId < sclk_table->count; ++entryId) {
2765 voltageId = sclk_table->entries[entryId].vddInd;
2766 sclk_table->entries[entryId].vddc =
2767 table_info->vddc_lookup_table->entries[voltageId].us_vdd;
2770 for (entryId = 0; entryId < mclk_table->count; ++entryId) {
2771 voltageId = mclk_table->entries[entryId].vddInd;
2772 mclk_table->entries[entryId].vddc =
2773 table_info->vddc_lookup_table->entries[voltageId].us_vdd;
2776 for (entryId = 0; entryId < mm_table->count; ++entryId) {
2777 voltageId = mm_table->entries[entryId].vddcInd;
2778 mm_table->entries[entryId].vddc =
2779 table_info->vddc_lookup_table->entries[voltageId].us_vdd;
2786 static int polaris10_calc_voltage_dependency_tables(struct pp_hwmgr *hwmgr)
2788 /* Need to determine if we need calculated voltage. */
2792 static int polaris10_calc_mm_voltage_dependency_table(struct pp_hwmgr *hwmgr)
2794 /* Need to determine if we need calculated voltage from mm table. */
2798 static int polaris10_sort_lookup_table(struct pp_hwmgr *hwmgr,
2799 struct phm_ppt_v1_voltage_lookup_table *lookup_table)
2801 uint32_t table_size, i, j;
2802 struct phm_ppt_v1_voltage_lookup_record tmp_voltage_lookup_record;
2803 table_size = lookup_table->count;
2805 PP_ASSERT_WITH_CODE(0 != lookup_table->count,
2806 "Lookup table is empty", return -EINVAL);
2808 /* Sorting voltages */
2809 for (i = 0; i < table_size - 1; i++) {
2810 for (j = i + 1; j > 0; j--) {
2811 if (lookup_table->entries[j].us_vdd <
2812 lookup_table->entries[j - 1].us_vdd) {
2813 tmp_voltage_lookup_record = lookup_table->entries[j - 1];
2814 lookup_table->entries[j - 1] = lookup_table->entries[j];
2815 lookup_table->entries[j] = tmp_voltage_lookup_record;
2823 static int polaris10_complete_dependency_tables(struct pp_hwmgr *hwmgr)
2827 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2828 struct phm_ppt_v1_information *table_info =
2829 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2831 tmp_result = polaris10_patch_lookup_table_with_leakage(hwmgr,
2832 table_info->vddc_lookup_table, &(data->vddc_leakage));
2834 result = tmp_result;
2836 tmp_result = polaris10_patch_clock_voltage_limits_with_vddc_leakage(hwmgr,
2837 &(data->vddc_leakage), &table_info->max_clock_voltage_on_dc.vddc);
2839 result = tmp_result;
2841 tmp_result = polaris10_patch_voltage_dependency_tables_with_lookup_table(hwmgr);
2843 result = tmp_result;
2845 tmp_result = polaris10_calc_voltage_dependency_tables(hwmgr);
2847 result = tmp_result;
2849 tmp_result = polaris10_calc_mm_voltage_dependency_table(hwmgr);
2851 result = tmp_result;
2853 tmp_result = polaris10_sort_lookup_table(hwmgr, table_info->vddc_lookup_table);
2855 result = tmp_result;
2860 static int polaris10_set_private_data_based_on_pptable(struct pp_hwmgr *hwmgr)
2862 struct phm_ppt_v1_information *table_info =
2863 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2865 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_sclk_vdd_table =
2866 table_info->vdd_dep_on_sclk;
2867 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_mclk_vdd_table =
2868 table_info->vdd_dep_on_mclk;
2870 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table != NULL,
2871 "VDD dependency on SCLK table is missing. \
2872 This table is mandatory", return -EINVAL);
2873 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table->count >= 1,
2874 "VDD dependency on SCLK table has to have is missing. \
2875 This table is mandatory", return -EINVAL);
2877 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table != NULL,
2878 "VDD dependency on MCLK table is missing. \
2879 This table is mandatory", return -EINVAL);
2880 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table->count >= 1,
2881 "VDD dependency on MCLK table has to have is missing. \
2882 This table is mandatory", return -EINVAL);
2884 table_info->max_clock_voltage_on_ac.sclk =
2885 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].clk;
2886 table_info->max_clock_voltage_on_ac.mclk =
2887 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].clk;
2888 table_info->max_clock_voltage_on_ac.vddc =
2889 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].vddc;
2890 table_info->max_clock_voltage_on_ac.vddci =
2891 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].vddci;
2896 int polaris10_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
2898 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
2899 struct pp_atomctrl_gpio_pin_assignment gpio_pin_assignment;
2903 data->dll_default_on = false;
2904 data->sram_end = SMC_RAM_END;
2906 data->disable_dpm_mask = 0xFF;
2907 data->static_screen_threshold = PPPOLARIS10_STATICSCREENTHRESHOLD_DFLT;
2908 data->static_screen_threshold_unit = PPPOLARIS10_STATICSCREENTHRESHOLD_DFLT;
2909 data->activity_target[0] = PPPOLARIS10_TARGETACTIVITY_DFLT;
2910 data->activity_target[1] = PPPOLARIS10_TARGETACTIVITY_DFLT;
2911 data->activity_target[2] = PPPOLARIS10_TARGETACTIVITY_DFLT;
2912 data->activity_target[3] = PPPOLARIS10_TARGETACTIVITY_DFLT;
2913 data->activity_target[4] = PPPOLARIS10_TARGETACTIVITY_DFLT;
2914 data->activity_target[5] = PPPOLARIS10_TARGETACTIVITY_DFLT;
2915 data->activity_target[6] = PPPOLARIS10_TARGETACTIVITY_DFLT;
2916 data->activity_target[7] = PPPOLARIS10_TARGETACTIVITY_DFLT;
2918 data->voting_rights_clients0 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT0;
2919 data->voting_rights_clients1 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT1;
2920 data->voting_rights_clients2 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT2;
2921 data->voting_rights_clients3 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT3;
2922 data->voting_rights_clients4 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT4;
2923 data->voting_rights_clients5 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT5;
2924 data->voting_rights_clients6 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT6;
2925 data->voting_rights_clients7 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT7;
2927 data->vddc_vddci_delta = VDDC_VDDCI_DELTA;
2929 data->mclk_activity_target = PPPOLARIS10_MCLK_TARGETACTIVITY_DFLT;
2931 /* need to set voltage control types before EVV patching */
2932 data->voltage_control = POLARIS10_VOLTAGE_CONTROL_NONE;
2933 data->vddci_control = POLARIS10_VOLTAGE_CONTROL_NONE;
2934 data->mvdd_control = POLARIS10_VOLTAGE_CONTROL_NONE;
2936 if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
2937 VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_SVID2))
2938 data->voltage_control = POLARIS10_VOLTAGE_CONTROL_BY_SVID2;
2940 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2941 PHM_PlatformCaps_DynamicPatchPowerState);
2943 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2944 PHM_PlatformCaps_EnableMVDDControl)) {
2945 if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
2946 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT))
2947 data->mvdd_control = POLARIS10_VOLTAGE_CONTROL_BY_GPIO;
2948 else if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
2949 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_SVID2))
2950 data->mvdd_control = POLARIS10_VOLTAGE_CONTROL_BY_SVID2;
2953 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2954 PHM_PlatformCaps_ControlVDDCI)) {
2955 if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
2956 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT))
2957 data->vddci_control = POLARIS10_VOLTAGE_CONTROL_BY_GPIO;
2958 else if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
2959 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_SVID2))
2960 data->vddci_control = POLARIS10_VOLTAGE_CONTROL_BY_SVID2;
2963 polaris10_set_features_platform_caps(hwmgr);
2965 polaris10_init_dpm_defaults(hwmgr);
2967 /* Get leakage voltage based on leakage ID. */
2968 result = polaris10_get_evv_voltages(hwmgr);
2971 printk("Get EVV Voltage Failed. Abort Driver loading!\n");
2975 polaris10_complete_dependency_tables(hwmgr);
2976 polaris10_set_private_data_based_on_pptable(hwmgr);
2978 /* Initalize Dynamic State Adjustment Rule Settings */
2979 result = phm_initializa_dynamic_state_adjustment_rule_settings(hwmgr);
2982 struct cgs_system_info sys_info = {0};
2984 data->is_tlu_enabled = 0;
2986 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels =
2987 POLARIS10_MAX_HARDWARE_POWERLEVELS;
2988 hwmgr->platform_descriptor.hardwarePerformanceLevels = 2;
2989 hwmgr->platform_descriptor.minimumClocksReductionPercentage = 50;
2990 hwmgr->platform_descriptor.vbiosInterruptId = 0x20000400; /* IRQ_SOURCE1_SW_INT */
2991 /* The true clock step depends on the frequency, typically 4.5 or 9 MHz. Here we use 5. */
2992 hwmgr->platform_descriptor.clockStep.engineClock = 500;
2993 hwmgr->platform_descriptor.clockStep.memoryClock = 500;
2995 if (atomctrl_get_pp_assign_pin(hwmgr, VDDC_PCC_GPIO_PINID, &gpio_pin_assignment)) {
2996 temp_reg = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCNB_PWRMGT_CNTL);
2997 switch (gpio_pin_assignment.uc_gpio_pin_bit_shift) {
2999 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x1);
3002 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x2);
3005 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW, 0x1);
3008 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, FORCE_NB_PS1, 0x1);
3011 temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, DPM_ENABLED, 0x1);
3014 PP_ASSERT_WITH_CODE(0,
3015 "Failed to setup PCC HW register! Wrong GPIO assigned for VDDC_PCC_GPIO_PINID!",
3019 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCNB_PWRMGT_CNTL, temp_reg);
3022 sys_info.size = sizeof(struct cgs_system_info);
3023 sys_info.info_id = CGS_SYSTEM_INFO_PCIE_GEN_INFO;
3024 result = cgs_query_system_info(hwmgr->device, &sys_info);
3026 data->pcie_gen_cap = 0x30007;
3028 data->pcie_gen_cap = (uint32_t)sys_info.value;
3029 if (data->pcie_gen_cap & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)
3030 data->pcie_spc_cap = 20;
3031 sys_info.size = sizeof(struct cgs_system_info);
3032 sys_info.info_id = CGS_SYSTEM_INFO_PCIE_MLW;
3033 result = cgs_query_system_info(hwmgr->device, &sys_info);
3035 data->pcie_lane_cap = 0x2f0000;
3037 data->pcie_lane_cap = (uint32_t)sys_info.value;
3039 /* Ignore return value in here, we are cleaning up a mess. */
3040 polaris10_hwmgr_backend_fini(hwmgr);
3046 static int polaris10_force_dpm_highest(struct pp_hwmgr *hwmgr)
3048 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3049 uint32_t level, tmp;
3051 if (!data->pcie_dpm_key_disabled) {
3052 if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) {
3054 tmp = data->dpm_level_enable_mask.pcie_dpm_enable_mask;
3059 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3060 PPSMC_MSG_PCIeDPM_ForceLevel, level);
3064 if (!data->sclk_dpm_key_disabled) {
3065 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
3067 tmp = data->dpm_level_enable_mask.sclk_dpm_enable_mask;
3072 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3073 PPSMC_MSG_SCLKDPM_SetEnabledMask,
3078 if (!data->mclk_dpm_key_disabled) {
3079 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
3081 tmp = data->dpm_level_enable_mask.mclk_dpm_enable_mask;
3086 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3087 PPSMC_MSG_MCLKDPM_SetEnabledMask,
3095 static int polaris10_upload_dpm_level_enable_mask(struct pp_hwmgr *hwmgr)
3097 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3099 phm_apply_dal_min_voltage_request(hwmgr);
3101 if (!data->sclk_dpm_key_disabled) {
3102 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask)
3103 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3104 PPSMC_MSG_SCLKDPM_SetEnabledMask,
3105 data->dpm_level_enable_mask.sclk_dpm_enable_mask);
3108 if (!data->mclk_dpm_key_disabled) {
3109 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask)
3110 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3111 PPSMC_MSG_MCLKDPM_SetEnabledMask,
3112 data->dpm_level_enable_mask.mclk_dpm_enable_mask);
3118 static int polaris10_unforce_dpm_levels(struct pp_hwmgr *hwmgr)
3120 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3122 if (!polaris10_is_dpm_running(hwmgr))
3125 if (!data->pcie_dpm_key_disabled) {
3126 smum_send_msg_to_smc(hwmgr->smumgr,
3127 PPSMC_MSG_PCIeDPM_UnForceLevel);
3130 return polaris10_upload_dpm_level_enable_mask(hwmgr);
3133 static int polaris10_force_dpm_lowest(struct pp_hwmgr *hwmgr)
3135 struct polaris10_hwmgr *data =
3136 (struct polaris10_hwmgr *)(hwmgr->backend);
3139 if (!data->sclk_dpm_key_disabled)
3140 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
3141 level = phm_get_lowest_enabled_level(hwmgr,
3142 data->dpm_level_enable_mask.sclk_dpm_enable_mask);
3143 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3144 PPSMC_MSG_SCLKDPM_SetEnabledMask,
3149 if (!data->mclk_dpm_key_disabled) {
3150 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
3151 level = phm_get_lowest_enabled_level(hwmgr,
3152 data->dpm_level_enable_mask.mclk_dpm_enable_mask);
3153 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3154 PPSMC_MSG_MCLKDPM_SetEnabledMask,
3159 if (!data->pcie_dpm_key_disabled) {
3160 if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) {
3161 level = phm_get_lowest_enabled_level(hwmgr,
3162 data->dpm_level_enable_mask.pcie_dpm_enable_mask);
3163 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3164 PPSMC_MSG_PCIeDPM_ForceLevel,
3172 static int polaris10_force_dpm_level(struct pp_hwmgr *hwmgr,
3173 enum amd_dpm_forced_level level)
3178 case AMD_DPM_FORCED_LEVEL_HIGH:
3179 ret = polaris10_force_dpm_highest(hwmgr);
3183 case AMD_DPM_FORCED_LEVEL_LOW:
3184 ret = polaris10_force_dpm_lowest(hwmgr);
3188 case AMD_DPM_FORCED_LEVEL_AUTO:
3189 ret = polaris10_unforce_dpm_levels(hwmgr);
3197 hwmgr->dpm_level = level;
3202 static int polaris10_get_power_state_size(struct pp_hwmgr *hwmgr)
3204 return sizeof(struct polaris10_power_state);
3208 static int polaris10_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
3209 struct pp_power_state *request_ps,
3210 const struct pp_power_state *current_ps)
3213 struct polaris10_power_state *polaris10_ps =
3214 cast_phw_polaris10_power_state(&request_ps->hardware);
3217 struct PP_Clocks minimum_clocks = {0};
3218 bool disable_mclk_switching;
3219 bool disable_mclk_switching_for_frame_lock;
3220 struct cgs_display_info info = {0};
3221 const struct phm_clock_and_voltage_limits *max_limits;
3223 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3224 struct phm_ppt_v1_information *table_info =
3225 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3227 int32_t stable_pstate_sclk = 0, stable_pstate_mclk = 0;
3229 data->battery_state = (PP_StateUILabel_Battery ==
3230 request_ps->classification.ui_label);
3232 PP_ASSERT_WITH_CODE(polaris10_ps->performance_level_count == 2,
3233 "VI should always have 2 performance levels",
3236 max_limits = (PP_PowerSource_AC == hwmgr->power_source) ?
3237 &(hwmgr->dyn_state.max_clock_voltage_on_ac) :
3238 &(hwmgr->dyn_state.max_clock_voltage_on_dc);
3240 /* Cap clock DPM tables at DC MAX if it is in DC. */
3241 if (PP_PowerSource_DC == hwmgr->power_source) {
3242 for (i = 0; i < polaris10_ps->performance_level_count; i++) {
3243 if (polaris10_ps->performance_levels[i].memory_clock > max_limits->mclk)
3244 polaris10_ps->performance_levels[i].memory_clock = max_limits->mclk;
3245 if (polaris10_ps->performance_levels[i].engine_clock > max_limits->sclk)
3246 polaris10_ps->performance_levels[i].engine_clock = max_limits->sclk;
3250 polaris10_ps->vce_clks.evclk = hwmgr->vce_arbiter.evclk;
3251 polaris10_ps->vce_clks.ecclk = hwmgr->vce_arbiter.ecclk;
3253 cgs_get_active_displays_info(hwmgr->device, &info);
3255 /*TO DO result = PHM_CheckVBlankTime(hwmgr, &vblankTooShort);*/
3257 /* TO DO GetMinClockSettings(hwmgr->pPECI, &minimum_clocks); */
3259 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3260 PHM_PlatformCaps_StablePState)) {
3261 max_limits = &(hwmgr->dyn_state.max_clock_voltage_on_ac);
3262 stable_pstate_sclk = (max_limits->sclk * 75) / 100;
3264 for (count = table_info->vdd_dep_on_sclk->count - 1;
3265 count >= 0; count--) {
3266 if (stable_pstate_sclk >=
3267 table_info->vdd_dep_on_sclk->entries[count].clk) {
3268 stable_pstate_sclk =
3269 table_info->vdd_dep_on_sclk->entries[count].clk;
3275 stable_pstate_sclk = table_info->vdd_dep_on_sclk->entries[0].clk;
3277 stable_pstate_mclk = max_limits->mclk;
3279 minimum_clocks.engineClock = stable_pstate_sclk;
3280 minimum_clocks.memoryClock = stable_pstate_mclk;
3283 if (minimum_clocks.engineClock < hwmgr->gfx_arbiter.sclk)
3284 minimum_clocks.engineClock = hwmgr->gfx_arbiter.sclk;
3286 if (minimum_clocks.memoryClock < hwmgr->gfx_arbiter.mclk)
3287 minimum_clocks.memoryClock = hwmgr->gfx_arbiter.mclk;
3289 polaris10_ps->sclk_threshold = hwmgr->gfx_arbiter.sclk_threshold;
3291 if (0 != hwmgr->gfx_arbiter.sclk_over_drive) {
3292 PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.sclk_over_drive <=
3293 hwmgr->platform_descriptor.overdriveLimit.engineClock),
3294 "Overdrive sclk exceeds limit",
3295 hwmgr->gfx_arbiter.sclk_over_drive =
3296 hwmgr->platform_descriptor.overdriveLimit.engineClock);
3298 if (hwmgr->gfx_arbiter.sclk_over_drive >= hwmgr->gfx_arbiter.sclk)
3299 polaris10_ps->performance_levels[1].engine_clock =
3300 hwmgr->gfx_arbiter.sclk_over_drive;
3303 if (0 != hwmgr->gfx_arbiter.mclk_over_drive) {
3304 PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.mclk_over_drive <=
3305 hwmgr->platform_descriptor.overdriveLimit.memoryClock),
3306 "Overdrive mclk exceeds limit",
3307 hwmgr->gfx_arbiter.mclk_over_drive =
3308 hwmgr->platform_descriptor.overdriveLimit.memoryClock);
3310 if (hwmgr->gfx_arbiter.mclk_over_drive >= hwmgr->gfx_arbiter.mclk)
3311 polaris10_ps->performance_levels[1].memory_clock =
3312 hwmgr->gfx_arbiter.mclk_over_drive;
3315 disable_mclk_switching_for_frame_lock = phm_cap_enabled(
3316 hwmgr->platform_descriptor.platformCaps,
3317 PHM_PlatformCaps_DisableMclkSwitchingForFrameLock);
3319 disable_mclk_switching = (1 < info.display_count) ||
3320 disable_mclk_switching_for_frame_lock;
3322 sclk = polaris10_ps->performance_levels[0].engine_clock;
3323 mclk = polaris10_ps->performance_levels[0].memory_clock;
3325 if (disable_mclk_switching)
3326 mclk = polaris10_ps->performance_levels
3327 [polaris10_ps->performance_level_count - 1].memory_clock;
3329 if (sclk < minimum_clocks.engineClock)
3330 sclk = (minimum_clocks.engineClock > max_limits->sclk) ?
3331 max_limits->sclk : minimum_clocks.engineClock;
3333 if (mclk < minimum_clocks.memoryClock)
3334 mclk = (minimum_clocks.memoryClock > max_limits->mclk) ?
3335 max_limits->mclk : minimum_clocks.memoryClock;
3337 polaris10_ps->performance_levels[0].engine_clock = sclk;
3338 polaris10_ps->performance_levels[0].memory_clock = mclk;
3340 polaris10_ps->performance_levels[1].engine_clock =
3341 (polaris10_ps->performance_levels[1].engine_clock >=
3342 polaris10_ps->performance_levels[0].engine_clock) ?
3343 polaris10_ps->performance_levels[1].engine_clock :
3344 polaris10_ps->performance_levels[0].engine_clock;
3346 if (disable_mclk_switching) {
3347 if (mclk < polaris10_ps->performance_levels[1].memory_clock)
3348 mclk = polaris10_ps->performance_levels[1].memory_clock;
3350 polaris10_ps->performance_levels[0].memory_clock = mclk;
3351 polaris10_ps->performance_levels[1].memory_clock = mclk;
3353 if (polaris10_ps->performance_levels[1].memory_clock <
3354 polaris10_ps->performance_levels[0].memory_clock)
3355 polaris10_ps->performance_levels[1].memory_clock =
3356 polaris10_ps->performance_levels[0].memory_clock;
3359 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3360 PHM_PlatformCaps_StablePState)) {
3361 for (i = 0; i < polaris10_ps->performance_level_count; i++) {
3362 polaris10_ps->performance_levels[i].engine_clock = stable_pstate_sclk;
3363 polaris10_ps->performance_levels[i].memory_clock = stable_pstate_mclk;
3364 polaris10_ps->performance_levels[i].pcie_gen = data->pcie_gen_performance.max;
3365 polaris10_ps->performance_levels[i].pcie_lane = data->pcie_gen_performance.max;
3372 static int polaris10_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)
3374 struct pp_power_state *ps;
3375 struct polaris10_power_state *polaris10_ps;
3380 ps = hwmgr->request_ps;
3385 polaris10_ps = cast_phw_polaris10_power_state(&ps->hardware);
3388 return polaris10_ps->performance_levels[0].memory_clock;
3390 return polaris10_ps->performance_levels
3391 [polaris10_ps->performance_level_count-1].memory_clock;
3394 static int polaris10_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)
3396 struct pp_power_state *ps;
3397 struct polaris10_power_state *polaris10_ps;
3402 ps = hwmgr->request_ps;
3407 polaris10_ps = cast_phw_polaris10_power_state(&ps->hardware);
3410 return polaris10_ps->performance_levels[0].engine_clock;
3412 return polaris10_ps->performance_levels
3413 [polaris10_ps->performance_level_count-1].engine_clock;
3416 static int polaris10_dpm_patch_boot_state(struct pp_hwmgr *hwmgr,
3417 struct pp_hw_power_state *hw_ps)
3419 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3420 struct polaris10_power_state *ps = (struct polaris10_power_state *)hw_ps;
3421 ATOM_FIRMWARE_INFO_V2_2 *fw_info;
3424 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
3426 /* First retrieve the Boot clocks and VDDC from the firmware info table.
3427 * We assume here that fw_info is unchanged if this call fails.
3429 fw_info = (ATOM_FIRMWARE_INFO_V2_2 *)cgs_atom_get_data_table(
3430 hwmgr->device, index,
3431 &size, &frev, &crev);
3433 /* During a test, there is no firmware info table. */
3436 /* Patch the state. */
3437 data->vbios_boot_state.sclk_bootup_value =
3438 le32_to_cpu(fw_info->ulDefaultEngineClock);
3439 data->vbios_boot_state.mclk_bootup_value =
3440 le32_to_cpu(fw_info->ulDefaultMemoryClock);
3441 data->vbios_boot_state.mvdd_bootup_value =
3442 le16_to_cpu(fw_info->usBootUpMVDDCVoltage);
3443 data->vbios_boot_state.vddc_bootup_value =
3444 le16_to_cpu(fw_info->usBootUpVDDCVoltage);
3445 data->vbios_boot_state.vddci_bootup_value =
3446 le16_to_cpu(fw_info->usBootUpVDDCIVoltage);
3447 data->vbios_boot_state.pcie_gen_bootup_value =
3448 phm_get_current_pcie_speed(hwmgr);
3450 data->vbios_boot_state.pcie_lane_bootup_value =
3451 (uint16_t)phm_get_current_pcie_lane_number(hwmgr);
3453 /* set boot power state */
3454 ps->performance_levels[0].memory_clock = data->vbios_boot_state.mclk_bootup_value;
3455 ps->performance_levels[0].engine_clock = data->vbios_boot_state.sclk_bootup_value;
3456 ps->performance_levels[0].pcie_gen = data->vbios_boot_state.pcie_gen_bootup_value;
3457 ps->performance_levels[0].pcie_lane = data->vbios_boot_state.pcie_lane_bootup_value;
3462 static int polaris10_get_pp_table_entry_callback_func(struct pp_hwmgr *hwmgr,
3463 void *state, struct pp_power_state *power_state,
3464 void *pp_table, uint32_t classification_flag)
3466 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3467 struct polaris10_power_state *polaris10_power_state =
3468 (struct polaris10_power_state *)(&(power_state->hardware));
3469 struct polaris10_performance_level *performance_level;
3470 ATOM_Tonga_State *state_entry = (ATOM_Tonga_State *)state;
3471 ATOM_Tonga_POWERPLAYTABLE *powerplay_table =
3472 (ATOM_Tonga_POWERPLAYTABLE *)pp_table;
3473 ATOM_Tonga_SCLK_Dependency_Table *sclk_dep_table =
3474 (ATOM_Tonga_SCLK_Dependency_Table *)
3475 (((unsigned long)powerplay_table) +
3476 le16_to_cpu(powerplay_table->usSclkDependencyTableOffset));
3477 ATOM_Tonga_MCLK_Dependency_Table *mclk_dep_table =
3478 (ATOM_Tonga_MCLK_Dependency_Table *)
3479 (((unsigned long)powerplay_table) +
3480 le16_to_cpu(powerplay_table->usMclkDependencyTableOffset));
3482 /* The following fields are not initialized here: id orderedList allStatesList */
3483 power_state->classification.ui_label =
3484 (le16_to_cpu(state_entry->usClassification) &
3485 ATOM_PPLIB_CLASSIFICATION_UI_MASK) >>
3486 ATOM_PPLIB_CLASSIFICATION_UI_SHIFT;
3487 power_state->classification.flags = classification_flag;
3488 /* NOTE: There is a classification2 flag in BIOS that is not being used right now */
3490 power_state->classification.temporary_state = false;
3491 power_state->classification.to_be_deleted = false;
3493 power_state->validation.disallowOnDC =
3494 (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) &
3495 ATOM_Tonga_DISALLOW_ON_DC));
3497 power_state->pcie.lanes = 0;
3499 power_state->display.disableFrameModulation = false;
3500 power_state->display.limitRefreshrate = false;
3501 power_state->display.enableVariBright =
3502 (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) &
3503 ATOM_Tonga_ENABLE_VARIBRIGHT));
3505 power_state->validation.supportedPowerLevels = 0;
3506 power_state->uvd_clocks.VCLK = 0;
3507 power_state->uvd_clocks.DCLK = 0;
3508 power_state->temperatures.min = 0;
3509 power_state->temperatures.max = 0;
3511 performance_level = &(polaris10_power_state->performance_levels
3512 [polaris10_power_state->performance_level_count++]);
3514 PP_ASSERT_WITH_CODE(
3515 (polaris10_power_state->performance_level_count < SMU74_MAX_LEVELS_GRAPHICS),
3516 "Performance levels exceeds SMC limit!",
3519 PP_ASSERT_WITH_CODE(
3520 (polaris10_power_state->performance_level_count <=
3521 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels),
3522 "Performance levels exceeds Driver limit!",
3525 /* Performance levels are arranged from low to high. */
3526 performance_level->memory_clock = mclk_dep_table->entries
3527 [state_entry->ucMemoryClockIndexLow].ulMclk;
3528 performance_level->engine_clock = sclk_dep_table->entries
3529 [state_entry->ucEngineClockIndexLow].ulSclk;
3530 performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap,
3531 state_entry->ucPCIEGenLow);
3532 performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap,
3533 state_entry->ucPCIELaneHigh);
3535 performance_level = &(polaris10_power_state->performance_levels
3536 [polaris10_power_state->performance_level_count++]);
3537 performance_level->memory_clock = mclk_dep_table->entries
3538 [state_entry->ucMemoryClockIndexHigh].ulMclk;
3539 performance_level->engine_clock = sclk_dep_table->entries
3540 [state_entry->ucEngineClockIndexHigh].ulSclk;
3541 performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap,
3542 state_entry->ucPCIEGenHigh);
3543 performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap,
3544 state_entry->ucPCIELaneHigh);
3549 static int polaris10_get_pp_table_entry(struct pp_hwmgr *hwmgr,
3550 unsigned long entry_index, struct pp_power_state *state)
3553 struct polaris10_power_state *ps;
3554 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3555 struct phm_ppt_v1_information *table_info =
3556 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3557 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
3558 table_info->vdd_dep_on_mclk;
3560 state->hardware.magic = PHM_VIslands_Magic;
3562 ps = (struct polaris10_power_state *)(&state->hardware);
3564 result = tonga_get_powerplay_table_entry(hwmgr, entry_index, state,
3565 polaris10_get_pp_table_entry_callback_func);
3567 /* This is the earliest time we have all the dependency table and the VBIOS boot state
3568 * as PP_Tables_GetPowerPlayTableEntry retrieves the VBIOS boot state
3569 * if there is only one VDDCI/MCLK level, check if it's the same as VBIOS boot state
3571 if (dep_mclk_table != NULL && dep_mclk_table->count == 1) {
3572 if (dep_mclk_table->entries[0].clk !=
3573 data->vbios_boot_state.mclk_bootup_value)
3574 printk(KERN_ERR "Single MCLK entry VDDCI/MCLK dependency table "
3575 "does not match VBIOS boot MCLK level");
3576 if (dep_mclk_table->entries[0].vddci !=
3577 data->vbios_boot_state.vddci_bootup_value)
3578 printk(KERN_ERR "Single VDDCI entry VDDCI/MCLK dependency table "
3579 "does not match VBIOS boot VDDCI level");
3582 /* set DC compatible flag if this state supports DC */
3583 if (!state->validation.disallowOnDC)
3584 ps->dc_compatible = true;
3586 if (state->classification.flags & PP_StateClassificationFlag_ACPI)
3587 data->acpi_pcie_gen = ps->performance_levels[0].pcie_gen;
3589 ps->uvd_clks.vclk = state->uvd_clocks.VCLK;
3590 ps->uvd_clks.dclk = state->uvd_clocks.DCLK;
3595 switch (state->classification.ui_label) {
3596 case PP_StateUILabel_Performance:
3597 data->use_pcie_performance_levels = true;
3599 for (i = 0; i < ps->performance_level_count; i++) {
3600 if (data->pcie_gen_performance.max <
3601 ps->performance_levels[i].pcie_gen)
3602 data->pcie_gen_performance.max =
3603 ps->performance_levels[i].pcie_gen;
3605 if (data->pcie_gen_performance.min >
3606 ps->performance_levels[i].pcie_gen)
3607 data->pcie_gen_performance.min =
3608 ps->performance_levels[i].pcie_gen;
3610 if (data->pcie_lane_performance.max <
3611 ps->performance_levels[i].pcie_lane)
3612 data->pcie_lane_performance.max =
3613 ps->performance_levels[i].pcie_lane;
3615 if (data->pcie_lane_performance.min >
3616 ps->performance_levels[i].pcie_lane)
3617 data->pcie_lane_performance.min =
3618 ps->performance_levels[i].pcie_lane;
3621 case PP_StateUILabel_Battery:
3622 data->use_pcie_power_saving_levels = true;
3624 for (i = 0; i < ps->performance_level_count; i++) {
3625 if (data->pcie_gen_power_saving.max <
3626 ps->performance_levels[i].pcie_gen)
3627 data->pcie_gen_power_saving.max =
3628 ps->performance_levels[i].pcie_gen;
3630 if (data->pcie_gen_power_saving.min >
3631 ps->performance_levels[i].pcie_gen)
3632 data->pcie_gen_power_saving.min =
3633 ps->performance_levels[i].pcie_gen;
3635 if (data->pcie_lane_power_saving.max <
3636 ps->performance_levels[i].pcie_lane)
3637 data->pcie_lane_power_saving.max =
3638 ps->performance_levels[i].pcie_lane;
3640 if (data->pcie_lane_power_saving.min >
3641 ps->performance_levels[i].pcie_lane)
3642 data->pcie_lane_power_saving.min =
3643 ps->performance_levels[i].pcie_lane;
3654 polaris10_print_current_perforce_level(struct pp_hwmgr *hwmgr, struct seq_file *m)
3656 uint32_t sclk, mclk, activity_percent;
3658 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3660 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetSclkFrequency);
3662 sclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
3664 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetMclkFrequency);
3666 mclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
3667 seq_printf(m, "\n [ mclk ]: %u MHz\n\n [ sclk ]: %u MHz\n",
3668 mclk / 100, sclk / 100);
3670 offset = data->soft_regs_start + offsetof(SMU74_SoftRegisters, AverageGraphicsActivity);
3671 activity_percent = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, offset);
3672 activity_percent += 0x80;
3673 activity_percent >>= 8;
3675 seq_printf(m, "\n [GPU load]: %u%%\n\n", activity_percent > 100 ? 100 : activity_percent);
3677 seq_printf(m, "uvd %sabled\n", data->uvd_power_gated ? "dis" : "en");
3679 seq_printf(m, "vce %sabled\n", data->vce_power_gated ? "dis" : "en");
3682 static int polaris10_find_dpm_states_clocks_in_dpm_table(struct pp_hwmgr *hwmgr, const void *input)
3684 const struct phm_set_power_state_input *states =
3685 (const struct phm_set_power_state_input *)input;
3686 const struct polaris10_power_state *polaris10_ps =
3687 cast_const_phw_polaris10_power_state(states->pnew_state);
3688 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3689 struct polaris10_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
3690 uint32_t sclk = polaris10_ps->performance_levels
3691 [polaris10_ps->performance_level_count - 1].engine_clock;
3692 struct polaris10_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
3693 uint32_t mclk = polaris10_ps->performance_levels
3694 [polaris10_ps->performance_level_count - 1].memory_clock;
3695 struct PP_Clocks min_clocks = {0};
3697 struct cgs_display_info info = {0};
3699 data->need_update_smu7_dpm_table = 0;
3701 for (i = 0; i < sclk_table->count; i++) {
3702 if (sclk == sclk_table->dpm_levels[i].value)
3706 if (i >= sclk_table->count)
3707 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK;
3709 /* TODO: Check SCLK in DAL's minimum clocks
3710 * in case DeepSleep divider update is required.
3712 if (data->display_timing.min_clock_in_sr != min_clocks.engineClockInSR &&
3713 (min_clocks.engineClockInSR >= POLARIS10_MINIMUM_ENGINE_CLOCK ||
3714 data->display_timing.min_clock_in_sr >= POLARIS10_MINIMUM_ENGINE_CLOCK))
3715 data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_SCLK;
3718 for (i = 0; i < mclk_table->count; i++) {
3719 if (mclk == mclk_table->dpm_levels[i].value)
3723 if (i >= mclk_table->count)
3724 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_MCLK;
3726 cgs_get_active_displays_info(hwmgr->device, &info);
3728 if (data->display_timing.num_existing_displays != info.display_count)
3729 data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_MCLK;
3734 static uint16_t polaris10_get_maximum_link_speed(struct pp_hwmgr *hwmgr,
3735 const struct polaris10_power_state *polaris10_ps)
3738 uint32_t sclk, max_sclk = 0;
3739 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3740 struct polaris10_dpm_table *dpm_table = &data->dpm_table;
3742 for (i = 0; i < polaris10_ps->performance_level_count; i++) {
3743 sclk = polaris10_ps->performance_levels[i].engine_clock;
3744 if (max_sclk < sclk)
3748 for (i = 0; i < dpm_table->sclk_table.count; i++) {
3749 if (dpm_table->sclk_table.dpm_levels[i].value == max_sclk)
3750 return (uint16_t) ((i >= dpm_table->pcie_speed_table.count) ?
3751 dpm_table->pcie_speed_table.dpm_levels
3752 [dpm_table->pcie_speed_table.count - 1].value :
3753 dpm_table->pcie_speed_table.dpm_levels[i].value);
3759 static int polaris10_request_link_speed_change_before_state_change(
3760 struct pp_hwmgr *hwmgr, const void *input)
3762 const struct phm_set_power_state_input *states =
3763 (const struct phm_set_power_state_input *)input;
3764 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3765 const struct polaris10_power_state *polaris10_nps =
3766 cast_const_phw_polaris10_power_state(states->pnew_state);
3767 const struct polaris10_power_state *polaris10_cps =
3768 cast_const_phw_polaris10_power_state(states->pcurrent_state);
3770 uint16_t target_link_speed = polaris10_get_maximum_link_speed(hwmgr, polaris10_nps);
3771 uint16_t current_link_speed;
3773 if (data->force_pcie_gen == PP_PCIEGenInvalid)
3774 current_link_speed = polaris10_get_maximum_link_speed(hwmgr, polaris10_cps);
3776 current_link_speed = data->force_pcie_gen;
3778 data->force_pcie_gen = PP_PCIEGenInvalid;
3779 data->pspp_notify_required = false;
3781 if (target_link_speed > current_link_speed) {
3782 switch (target_link_speed) {
3784 if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN3, false))
3786 data->force_pcie_gen = PP_PCIEGen2;
3787 if (current_link_speed == PP_PCIEGen2)
3790 if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN2, false))
3793 data->force_pcie_gen = phm_get_current_pcie_speed(hwmgr);
3797 if (target_link_speed < current_link_speed)
3798 data->pspp_notify_required = true;
3804 static int polaris10_freeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
3806 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3808 if (0 == data->need_update_smu7_dpm_table)
3811 if ((0 == data->sclk_dpm_key_disabled) &&
3812 (data->need_update_smu7_dpm_table &
3813 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
3814 PP_ASSERT_WITH_CODE(true == polaris10_is_dpm_running(hwmgr),
3815 "Trying to freeze SCLK DPM when DPM is disabled",
3817 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
3818 PPSMC_MSG_SCLKDPM_FreezeLevel),
3819 "Failed to freeze SCLK DPM during FreezeSclkMclkDPM Function!",
3823 if ((0 == data->mclk_dpm_key_disabled) &&
3824 (data->need_update_smu7_dpm_table &
3825 DPMTABLE_OD_UPDATE_MCLK)) {
3826 PP_ASSERT_WITH_CODE(true == polaris10_is_dpm_running(hwmgr),
3827 "Trying to freeze MCLK DPM when DPM is disabled",
3829 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
3830 PPSMC_MSG_MCLKDPM_FreezeLevel),
3831 "Failed to freeze MCLK DPM during FreezeSclkMclkDPM Function!",
3838 static int polaris10_populate_and_upload_sclk_mclk_dpm_levels(
3839 struct pp_hwmgr *hwmgr, const void *input)
3842 const struct phm_set_power_state_input *states =
3843 (const struct phm_set_power_state_input *)input;
3844 const struct polaris10_power_state *polaris10_ps =
3845 cast_const_phw_polaris10_power_state(states->pnew_state);
3846 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3847 uint32_t sclk = polaris10_ps->performance_levels
3848 [polaris10_ps->performance_level_count - 1].engine_clock;
3849 uint32_t mclk = polaris10_ps->performance_levels
3850 [polaris10_ps->performance_level_count - 1].memory_clock;
3851 struct polaris10_dpm_table *dpm_table = &data->dpm_table;
3853 struct polaris10_dpm_table *golden_dpm_table = &data->golden_dpm_table;
3854 uint32_t dpm_count, clock_percent;
3857 if (0 == data->need_update_smu7_dpm_table)
3860 if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_SCLK) {
3861 dpm_table->sclk_table.dpm_levels
3862 [dpm_table->sclk_table.count - 1].value = sclk;
3864 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinACSupport) ||
3865 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinDCSupport)) {
3866 /* Need to do calculation based on the golden DPM table
3867 * as the Heatmap GPU Clock axis is also based on the default values
3869 PP_ASSERT_WITH_CODE(
3870 (golden_dpm_table->sclk_table.dpm_levels
3871 [golden_dpm_table->sclk_table.count - 1].value != 0),
3874 dpm_count = dpm_table->sclk_table.count < 2 ? 0 : dpm_table->sclk_table.count - 2;
3876 for (i = dpm_count; i > 1; i--) {
3877 if (sclk > golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value) {
3880 - golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value
3882 / golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value;
3884 dpm_table->sclk_table.dpm_levels[i].value =
3885 golden_dpm_table->sclk_table.dpm_levels[i].value +
3886 (golden_dpm_table->sclk_table.dpm_levels[i].value *
3889 } else if (golden_dpm_table->sclk_table.dpm_levels[dpm_table->sclk_table.count-1].value > sclk) {
3891 ((golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count - 1].value
3893 / golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value;
3895 dpm_table->sclk_table.dpm_levels[i].value =
3896 golden_dpm_table->sclk_table.dpm_levels[i].value -
3897 (golden_dpm_table->sclk_table.dpm_levels[i].value *
3898 clock_percent) / 100;
3900 dpm_table->sclk_table.dpm_levels[i].value =
3901 golden_dpm_table->sclk_table.dpm_levels[i].value;
3906 if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK) {
3907 dpm_table->mclk_table.dpm_levels
3908 [dpm_table->mclk_table.count - 1].value = mclk;
3910 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinACSupport) ||
3911 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinDCSupport)) {
3913 PP_ASSERT_WITH_CODE(
3914 (golden_dpm_table->mclk_table.dpm_levels
3915 [golden_dpm_table->mclk_table.count-1].value != 0),
3918 dpm_count = dpm_table->mclk_table.count < 2 ? 0 : dpm_table->mclk_table.count - 2;
3919 for (i = dpm_count; i > 1; i--) {
3920 if (golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value < mclk) {
3921 clock_percent = ((mclk -
3922 golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value) * 100)
3923 / golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value;
3925 dpm_table->mclk_table.dpm_levels[i].value =
3926 golden_dpm_table->mclk_table.dpm_levels[i].value +
3927 (golden_dpm_table->mclk_table.dpm_levels[i].value *
3928 clock_percent) / 100;
3930 } else if (golden_dpm_table->mclk_table.dpm_levels[dpm_table->mclk_table.count-1].value > mclk) {
3932 (golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value - mclk)
3934 / golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value;
3936 dpm_table->mclk_table.dpm_levels[i].value =
3937 golden_dpm_table->mclk_table.dpm_levels[i].value -
3938 (golden_dpm_table->mclk_table.dpm_levels[i].value *
3939 clock_percent) / 100;
3941 dpm_table->mclk_table.dpm_levels[i].value =
3942 golden_dpm_table->mclk_table.dpm_levels[i].value;
3947 if (data->need_update_smu7_dpm_table &
3948 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK)) {
3949 result = polaris10_populate_all_graphic_levels(hwmgr);
3950 PP_ASSERT_WITH_CODE((0 == result),
3951 "Failed to populate SCLK during PopulateNewDPMClocksStates Function!",
3955 if (data->need_update_smu7_dpm_table &
3956 (DPMTABLE_OD_UPDATE_MCLK + DPMTABLE_UPDATE_MCLK)) {
3957 /*populate MCLK dpm table to SMU7 */
3958 result = polaris10_populate_all_memory_levels(hwmgr);
3959 PP_ASSERT_WITH_CODE((0 == result),
3960 "Failed to populate MCLK during PopulateNewDPMClocksStates Function!",
3967 static int polaris10_trim_single_dpm_states(struct pp_hwmgr *hwmgr,
3968 struct polaris10_single_dpm_table *dpm_table,
3969 uint32_t low_limit, uint32_t high_limit)
3973 for (i = 0; i < dpm_table->count; i++) {
3974 if ((dpm_table->dpm_levels[i].value < low_limit)
3975 || (dpm_table->dpm_levels[i].value > high_limit))
3976 dpm_table->dpm_levels[i].enabled = false;
3978 dpm_table->dpm_levels[i].enabled = true;
3984 static int polaris10_trim_dpm_states(struct pp_hwmgr *hwmgr,
3985 const struct polaris10_power_state *polaris10_ps)
3988 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
3989 uint32_t high_limit_count;
3991 PP_ASSERT_WITH_CODE((polaris10_ps->performance_level_count >= 1),
3992 "power state did not have any performance level",
3995 high_limit_count = (1 == polaris10_ps->performance_level_count) ? 0 : 1;
3997 polaris10_trim_single_dpm_states(hwmgr,
3998 &(data->dpm_table.sclk_table),
3999 polaris10_ps->performance_levels[0].engine_clock,
4000 polaris10_ps->performance_levels[high_limit_count].engine_clock);
4002 polaris10_trim_single_dpm_states(hwmgr,
4003 &(data->dpm_table.mclk_table),
4004 polaris10_ps->performance_levels[0].memory_clock,
4005 polaris10_ps->performance_levels[high_limit_count].memory_clock);
4010 static int polaris10_generate_dpm_level_enable_mask(
4011 struct pp_hwmgr *hwmgr, const void *input)
4014 const struct phm_set_power_state_input *states =
4015 (const struct phm_set_power_state_input *)input;
4016 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4017 const struct polaris10_power_state *polaris10_ps =
4018 cast_const_phw_polaris10_power_state(states->pnew_state);
4020 result = polaris10_trim_dpm_states(hwmgr, polaris10_ps);
4024 data->dpm_level_enable_mask.sclk_dpm_enable_mask =
4025 phm_get_dpm_level_enable_mask_value(&data->dpm_table.sclk_table);
4026 data->dpm_level_enable_mask.mclk_dpm_enable_mask =
4027 phm_get_dpm_level_enable_mask_value(&data->dpm_table.mclk_table);
4028 data->dpm_level_enable_mask.pcie_dpm_enable_mask =
4029 phm_get_dpm_level_enable_mask_value(&data->dpm_table.pcie_speed_table);
4034 int polaris10_enable_disable_uvd_dpm(struct pp_hwmgr *hwmgr, bool enable)
4036 return smum_send_msg_to_smc(hwmgr->smumgr, enable ?
4037 PPSMC_MSG_UVDDPM_Enable :
4038 PPSMC_MSG_UVDDPM_Disable);
4041 int polaris10_enable_disable_vce_dpm(struct pp_hwmgr *hwmgr, bool enable)
4043 return smum_send_msg_to_smc(hwmgr->smumgr, enable?
4044 PPSMC_MSG_VCEDPM_Enable :
4045 PPSMC_MSG_VCEDPM_Disable);
4048 int polaris10_enable_disable_samu_dpm(struct pp_hwmgr *hwmgr, bool enable)
4050 return smum_send_msg_to_smc(hwmgr->smumgr, enable?
4051 PPSMC_MSG_SAMUDPM_Enable :
4052 PPSMC_MSG_SAMUDPM_Disable);
4055 int polaris10_update_uvd_dpm(struct pp_hwmgr *hwmgr, bool bgate)
4057 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4058 uint32_t mm_boot_level_offset, mm_boot_level_value;
4059 struct phm_ppt_v1_information *table_info =
4060 (struct phm_ppt_v1_information *)(hwmgr->pptable);
4063 data->smc_state_table.UvdBootLevel = 0;
4064 if (table_info->mm_dep_table->count > 0)
4065 data->smc_state_table.UvdBootLevel =
4066 (uint8_t) (table_info->mm_dep_table->count - 1);
4067 mm_boot_level_offset = data->dpm_table_start +
4068 offsetof(SMU74_Discrete_DpmTable, UvdBootLevel);
4069 mm_boot_level_offset /= 4;
4070 mm_boot_level_offset *= 4;
4071 mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
4072 CGS_IND_REG__SMC, mm_boot_level_offset);
4073 mm_boot_level_value &= 0x00FFFFFF;
4074 mm_boot_level_value |= data->smc_state_table.UvdBootLevel << 24;
4075 cgs_write_ind_register(hwmgr->device,
4076 CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
4078 if (!phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4079 PHM_PlatformCaps_UVDDPM) ||
4080 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4081 PHM_PlatformCaps_StablePState))
4082 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4083 PPSMC_MSG_UVDDPM_SetEnabledMask,
4084 (uint32_t)(1 << data->smc_state_table.UvdBootLevel));
4087 return polaris10_enable_disable_uvd_dpm(hwmgr, !bgate);
4090 static int polaris10_update_vce_dpm(struct pp_hwmgr *hwmgr, const void *input)
4092 const struct phm_set_power_state_input *states =
4093 (const struct phm_set_power_state_input *)input;
4094 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4095 const struct polaris10_power_state *polaris10_nps =
4096 cast_const_phw_polaris10_power_state(states->pnew_state);
4097 const struct polaris10_power_state *polaris10_cps =
4098 cast_const_phw_polaris10_power_state(states->pcurrent_state);
4100 uint32_t mm_boot_level_offset, mm_boot_level_value;
4101 struct phm_ppt_v1_information *table_info =
4102 (struct phm_ppt_v1_information *)(hwmgr->pptable);
4104 if (polaris10_nps->vce_clks.evclk > 0 &&
4105 (polaris10_cps == NULL || polaris10_cps->vce_clks.evclk == 0)) {
4107 data->smc_state_table.VceBootLevel =
4108 (uint8_t) (table_info->mm_dep_table->count - 1);
4110 mm_boot_level_offset = data->dpm_table_start +
4111 offsetof(SMU74_Discrete_DpmTable, VceBootLevel);
4112 mm_boot_level_offset /= 4;
4113 mm_boot_level_offset *= 4;
4114 mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
4115 CGS_IND_REG__SMC, mm_boot_level_offset);
4116 mm_boot_level_value &= 0xFF00FFFF;
4117 mm_boot_level_value |= data->smc_state_table.VceBootLevel << 16;
4118 cgs_write_ind_register(hwmgr->device,
4119 CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
4121 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_StablePState)) {
4122 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4123 PPSMC_MSG_VCEDPM_SetEnabledMask,
4124 (uint32_t)1 << data->smc_state_table.VceBootLevel);
4126 polaris10_enable_disable_vce_dpm(hwmgr, true);
4127 } else if (polaris10_nps->vce_clks.evclk == 0 &&
4128 polaris10_cps != NULL &&
4129 polaris10_cps->vce_clks.evclk > 0)
4130 polaris10_enable_disable_vce_dpm(hwmgr, false);
4136 int polaris10_update_samu_dpm(struct pp_hwmgr *hwmgr, bool bgate)
4138 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4139 uint32_t mm_boot_level_offset, mm_boot_level_value;
4140 struct phm_ppt_v1_information *table_info =
4141 (struct phm_ppt_v1_information *)(hwmgr->pptable);
4144 data->smc_state_table.SamuBootLevel =
4145 (uint8_t) (table_info->mm_dep_table->count - 1);
4146 mm_boot_level_offset = data->dpm_table_start +
4147 offsetof(SMU74_Discrete_DpmTable, SamuBootLevel);
4148 mm_boot_level_offset /= 4;
4149 mm_boot_level_offset *= 4;
4150 mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
4151 CGS_IND_REG__SMC, mm_boot_level_offset);
4152 mm_boot_level_value &= 0xFFFFFF00;
4153 mm_boot_level_value |= data->smc_state_table.SamuBootLevel << 0;
4154 cgs_write_ind_register(hwmgr->device,
4155 CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
4157 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4158 PHM_PlatformCaps_StablePState))
4159 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4160 PPSMC_MSG_SAMUDPM_SetEnabledMask,
4161 (uint32_t)(1 << data->smc_state_table.SamuBootLevel));
4164 return polaris10_enable_disable_samu_dpm(hwmgr, !bgate);
4167 static int polaris10_update_sclk_threshold(struct pp_hwmgr *hwmgr)
4169 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4172 uint32_t low_sclk_interrupt_threshold = 0;
4174 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4175 PHM_PlatformCaps_SclkThrottleLowNotification)
4176 && (hwmgr->gfx_arbiter.sclk_threshold !=
4177 data->low_sclk_interrupt_threshold)) {
4178 data->low_sclk_interrupt_threshold =
4179 hwmgr->gfx_arbiter.sclk_threshold;
4180 low_sclk_interrupt_threshold =
4181 data->low_sclk_interrupt_threshold;
4183 CONVERT_FROM_HOST_TO_SMC_UL(low_sclk_interrupt_threshold);
4185 result = polaris10_copy_bytes_to_smc(
4187 data->dpm_table_start +
4188 offsetof(SMU74_Discrete_DpmTable,
4189 LowSclkInterruptThreshold),
4190 (uint8_t *)&low_sclk_interrupt_threshold,
4198 static int polaris10_program_mem_timing_parameters(struct pp_hwmgr *hwmgr)
4200 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4202 if (data->need_update_smu7_dpm_table &
4203 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_OD_UPDATE_MCLK))
4204 return polaris10_program_memory_timing_parameters(hwmgr);
4209 static int polaris10_unfreeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
4211 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4213 if (0 == data->need_update_smu7_dpm_table)
4216 if ((0 == data->sclk_dpm_key_disabled) &&
4217 (data->need_update_smu7_dpm_table &
4218 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
4220 PP_ASSERT_WITH_CODE(true == polaris10_is_dpm_running(hwmgr),
4221 "Trying to Unfreeze SCLK DPM when DPM is disabled",
4223 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
4224 PPSMC_MSG_SCLKDPM_UnfreezeLevel),
4225 "Failed to unfreeze SCLK DPM during UnFreezeSclkMclkDPM Function!",
4229 if ((0 == data->mclk_dpm_key_disabled) &&
4230 (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) {
4232 PP_ASSERT_WITH_CODE(true == polaris10_is_dpm_running(hwmgr),
4233 "Trying to Unfreeze MCLK DPM when DPM is disabled",
4235 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
4236 PPSMC_MSG_SCLKDPM_UnfreezeLevel),
4237 "Failed to unfreeze MCLK DPM during UnFreezeSclkMclkDPM Function!",
4241 data->need_update_smu7_dpm_table = 0;
4246 static int polaris10_notify_link_speed_change_after_state_change(
4247 struct pp_hwmgr *hwmgr, const void *input)
4249 const struct phm_set_power_state_input *states =
4250 (const struct phm_set_power_state_input *)input;
4251 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4252 const struct polaris10_power_state *polaris10_ps =
4253 cast_const_phw_polaris10_power_state(states->pnew_state);
4254 uint16_t target_link_speed = polaris10_get_maximum_link_speed(hwmgr, polaris10_ps);
4257 if (data->pspp_notify_required) {
4258 if (target_link_speed == PP_PCIEGen3)
4259 request = PCIE_PERF_REQ_GEN3;
4260 else if (target_link_speed == PP_PCIEGen2)
4261 request = PCIE_PERF_REQ_GEN2;
4263 request = PCIE_PERF_REQ_GEN1;
4265 if (request == PCIE_PERF_REQ_GEN1 &&
4266 phm_get_current_pcie_speed(hwmgr) > 0)
4269 if (acpi_pcie_perf_request(hwmgr->device, request, false)) {
4270 if (PP_PCIEGen2 == target_link_speed)
4271 printk("PSPP request to switch to Gen2 from Gen3 Failed!");
4273 printk("PSPP request to switch to Gen1 from Gen2 Failed!");
4280 static int polaris10_set_power_state_tasks(struct pp_hwmgr *hwmgr, const void *input)
4282 int tmp_result, result = 0;
4283 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4285 tmp_result = polaris10_find_dpm_states_clocks_in_dpm_table(hwmgr, input);
4286 PP_ASSERT_WITH_CODE((0 == tmp_result),
4287 "Failed to find DPM states clocks in DPM table!",
4288 result = tmp_result);
4290 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4291 PHM_PlatformCaps_PCIEPerformanceRequest)) {
4293 polaris10_request_link_speed_change_before_state_change(hwmgr, input);
4294 PP_ASSERT_WITH_CODE((0 == tmp_result),
4295 "Failed to request link speed change before state change!",
4296 result = tmp_result);
4299 tmp_result = polaris10_freeze_sclk_mclk_dpm(hwmgr);
4300 PP_ASSERT_WITH_CODE((0 == tmp_result),
4301 "Failed to freeze SCLK MCLK DPM!", result = tmp_result);
4303 tmp_result = polaris10_populate_and_upload_sclk_mclk_dpm_levels(hwmgr, input);
4304 PP_ASSERT_WITH_CODE((0 == tmp_result),
4305 "Failed to populate and upload SCLK MCLK DPM levels!",
4306 result = tmp_result);
4308 tmp_result = polaris10_generate_dpm_level_enable_mask(hwmgr, input);
4309 PP_ASSERT_WITH_CODE((0 == tmp_result),
4310 "Failed to generate DPM level enabled mask!",
4311 result = tmp_result);
4313 tmp_result = polaris10_update_vce_dpm(hwmgr, input);
4314 PP_ASSERT_WITH_CODE((0 == tmp_result),
4315 "Failed to update VCE DPM!",
4316 result = tmp_result);
4318 tmp_result = polaris10_update_sclk_threshold(hwmgr);
4319 PP_ASSERT_WITH_CODE((0 == tmp_result),
4320 "Failed to update SCLK threshold!",
4321 result = tmp_result);
4323 tmp_result = polaris10_program_mem_timing_parameters(hwmgr);
4324 PP_ASSERT_WITH_CODE((0 == tmp_result),
4325 "Failed to program memory timing parameters!",
4326 result = tmp_result);
4328 tmp_result = polaris10_unfreeze_sclk_mclk_dpm(hwmgr);
4329 PP_ASSERT_WITH_CODE((0 == tmp_result),
4330 "Failed to unfreeze SCLK MCLK DPM!",
4331 result = tmp_result);
4333 tmp_result = polaris10_upload_dpm_level_enable_mask(hwmgr);
4334 PP_ASSERT_WITH_CODE((0 == tmp_result),
4335 "Failed to upload DPM level enabled mask!",
4336 result = tmp_result);
4338 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4339 PHM_PlatformCaps_PCIEPerformanceRequest)) {
4341 polaris10_notify_link_speed_change_after_state_change(hwmgr, input);
4342 PP_ASSERT_WITH_CODE((0 == tmp_result),
4343 "Failed to notify link speed change after state change!",
4344 result = tmp_result);
4346 data->apply_optimized_settings = false;
4350 static int polaris10_set_max_fan_pwm_output(struct pp_hwmgr *hwmgr, uint16_t us_max_fan_pwm)
4352 hwmgr->thermal_controller.
4353 advanceFanControlParameters.usMaxFanPWM = us_max_fan_pwm;
4355 if (phm_is_hw_access_blocked(hwmgr))
4358 return smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4359 PPSMC_MSG_SetFanPwmMax, us_max_fan_pwm);
4362 int polaris10_notify_smc_display_change(struct pp_hwmgr *hwmgr, bool has_display)
4364 PPSMC_Msg msg = has_display ? (PPSMC_Msg)PPSMC_HasDisplay : (PPSMC_Msg)PPSMC_NoDisplay;
4366 return (smum_send_msg_to_smc(hwmgr->smumgr, msg) == 0) ? 0 : -1;
4369 int polaris10_notify_smc_display_config_after_ps_adjustment(struct pp_hwmgr *hwmgr)
4371 uint32_t num_active_displays = 0;
4372 struct cgs_display_info info = {0};
4373 info.mode_info = NULL;
4375 cgs_get_active_displays_info(hwmgr->device, &info);
4377 num_active_displays = info.display_count;
4379 if (num_active_displays > 1) /* to do && (pHwMgr->pPECI->displayConfiguration.bMultiMonitorInSync != TRUE)) */
4380 polaris10_notify_smc_display_change(hwmgr, false);
4382 polaris10_notify_smc_display_change(hwmgr, true);
4388 * Programs the display gap
4390 * @param hwmgr the address of the powerplay hardware manager.
4393 int polaris10_program_display_gap(struct pp_hwmgr *hwmgr)
4395 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4396 uint32_t num_active_displays = 0;
4397 uint32_t display_gap = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL);
4398 uint32_t display_gap2;
4399 uint32_t pre_vbi_time_in_us;
4400 uint32_t frame_time_in_us;
4402 uint32_t refresh_rate = 0;
4403 struct cgs_display_info info = {0};
4404 struct cgs_mode_info mode_info;
4406 info.mode_info = &mode_info;
4408 cgs_get_active_displays_info(hwmgr->device, &info);
4409 num_active_displays = info.display_count;
4411 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);
4412 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL, display_gap);
4414 ref_clock = mode_info.ref_clock;
4415 refresh_rate = mode_info.refresh_rate;
4417 if (0 == refresh_rate)
4420 frame_time_in_us = 1000000 / refresh_rate;
4422 pre_vbi_time_in_us = frame_time_in_us - 200 - mode_info.vblank_time_us;
4423 display_gap2 = pre_vbi_time_in_us * (ref_clock / 100);
4425 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL2, display_gap2);
4427 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, data->soft_regs_start + offsetof(SMU74_SoftRegisters, PreVBlankGap), 0x64);
4429 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));
4431 polaris10_notify_smc_display_change(hwmgr, num_active_displays != 0);
4437 int polaris10_display_configuration_changed_task(struct pp_hwmgr *hwmgr)
4439 return polaris10_program_display_gap(hwmgr);
4443 * Set maximum target operating fan output RPM
4445 * @param hwmgr: the address of the powerplay hardware manager.
4446 * @param usMaxFanRpm: max operating fan RPM value.
4447 * @return The response that came from the SMC.
4449 static int polaris10_set_max_fan_rpm_output(struct pp_hwmgr *hwmgr, uint16_t us_max_fan_rpm)
4451 hwmgr->thermal_controller.
4452 advanceFanControlParameters.usMaxFanRPM = us_max_fan_rpm;
4454 if (phm_is_hw_access_blocked(hwmgr))
4457 return smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4458 PPSMC_MSG_SetFanRpmMax, us_max_fan_rpm);
4461 int polaris10_register_internal_thermal_interrupt(struct pp_hwmgr *hwmgr,
4462 const void *thermal_interrupt_info)
4467 bool polaris10_check_smc_update_required_for_display_configuration(struct pp_hwmgr *hwmgr)
4469 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4470 bool is_update_required = false;
4471 struct cgs_display_info info = {0, 0, NULL};
4473 cgs_get_active_displays_info(hwmgr->device, &info);
4475 if (data->display_timing.num_existing_displays != info.display_count)
4476 is_update_required = true;
4477 /* TO DO NEED TO GET DEEP SLEEP CLOCK FROM DAL
4478 if (phm_cap_enabled(hwmgr->hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep)) {
4479 cgs_get_min_clock_settings(hwmgr->device, &min_clocks);
4480 if (min_clocks.engineClockInSR != data->display_timing.minClockInSR &&
4481 (min_clocks.engineClockInSR >= POLARIS10_MINIMUM_ENGINE_CLOCK ||
4482 data->display_timing.minClockInSR >= POLARIS10_MINIMUM_ENGINE_CLOCK))
4483 is_update_required = true;
4485 return is_update_required;
4488 static inline bool polaris10_are_power_levels_equal(const struct polaris10_performance_level *pl1,
4489 const struct polaris10_performance_level *pl2)
4491 return ((pl1->memory_clock == pl2->memory_clock) &&
4492 (pl1->engine_clock == pl2->engine_clock) &&
4493 (pl1->pcie_gen == pl2->pcie_gen) &&
4494 (pl1->pcie_lane == pl2->pcie_lane));
4497 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)
4499 const struct polaris10_power_state *psa = cast_const_phw_polaris10_power_state(pstate1);
4500 const struct polaris10_power_state *psb = cast_const_phw_polaris10_power_state(pstate2);
4503 if (pstate1 == NULL || pstate2 == NULL || equal == NULL)
4506 /* If the two states don't even have the same number of performance levels they cannot be the same state. */
4507 if (psa->performance_level_count != psb->performance_level_count) {
4512 for (i = 0; i < psa->performance_level_count; i++) {
4513 if (!polaris10_are_power_levels_equal(&(psa->performance_levels[i]), &(psb->performance_levels[i]))) {
4514 /* If we have found even one performance level pair that is different the states are different. */
4520 /* If all performance levels are the same try to use the UVD clocks to break the tie.*/
4521 *equal = ((psa->uvd_clks.vclk == psb->uvd_clks.vclk) && (psa->uvd_clks.dclk == psb->uvd_clks.dclk));
4522 *equal &= ((psa->vce_clks.evclk == psb->vce_clks.evclk) && (psa->vce_clks.ecclk == psb->vce_clks.ecclk));
4523 *equal &= (psa->sclk_threshold == psb->sclk_threshold);
4528 int polaris10_upload_mc_firmware(struct pp_hwmgr *hwmgr)
4530 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4532 uint32_t vbios_version;
4534 /* Read MC indirect register offset 0x9F bits [3:0] to see if VBIOS has already loaded a full version of MC ucode or not.*/
4536 phm_get_mc_microcode_version(hwmgr);
4537 vbios_version = hwmgr->microcode_version_info.MC & 0xf;
4538 /* Full version of MC ucode has already been loaded. */
4539 if (vbios_version == 0) {
4540 data->need_long_memory_training = false;
4544 data->need_long_memory_training = true;
4547 * PPMCME_FirmwareDescriptorEntry *pfd = NULL;
4548 pfd = &tonga_mcmeFirmware;
4549 if (0 == PHM_READ_FIELD(hwmgr->device, MC_SEQ_SUP_CNTL, RUN))
4550 polaris10_load_mc_microcode(hwmgr, pfd->dpmThreshold,
4551 pfd->cfgArray, pfd->cfgSize, pfd->ioDebugArray,
4552 pfd->ioDebugSize, pfd->ucodeArray, pfd->ucodeSize);
4558 * Read clock related registers.
4560 * @param hwmgr the address of the powerplay hardware manager.
4563 static int polaris10_read_clock_registers(struct pp_hwmgr *hwmgr)
4565 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4567 data->clock_registers.vCG_SPLL_FUNC_CNTL = cgs_read_ind_register(hwmgr->device,
4568 CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL)
4569 & CG_SPLL_FUNC_CNTL__SPLL_BYPASS_EN_MASK;
4571 data->clock_registers.vCG_SPLL_FUNC_CNTL_2 = cgs_read_ind_register(hwmgr->device,
4572 CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_2)
4573 & CG_SPLL_FUNC_CNTL_2__SCLK_MUX_SEL_MASK;
4575 data->clock_registers.vCG_SPLL_FUNC_CNTL_4 = cgs_read_ind_register(hwmgr->device,
4576 CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_4)
4577 & CG_SPLL_FUNC_CNTL_4__SPLL_SPARE_MASK;
4583 * Find out if memory is GDDR5.
4585 * @param hwmgr the address of the powerplay hardware manager.
4588 static int polaris10_get_memory_type(struct pp_hwmgr *hwmgr)
4590 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4593 temp = cgs_read_register(hwmgr->device, mmMC_SEQ_MISC0);
4595 data->is_memory_gddr5 = (MC_SEQ_MISC0_GDDR5_VALUE ==
4596 ((temp & MC_SEQ_MISC0_GDDR5_MASK) >>
4597 MC_SEQ_MISC0_GDDR5_SHIFT));
4603 * Enables Dynamic Power Management by SMC
4605 * @param hwmgr the address of the powerplay hardware manager.
4608 static int polaris10_enable_acpi_power_management(struct pp_hwmgr *hwmgr)
4610 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
4611 GENERAL_PWRMGT, STATIC_PM_EN, 1);
4617 * Initialize PowerGating States for different engines
4619 * @param hwmgr the address of the powerplay hardware manager.
4622 static int polaris10_init_power_gate_state(struct pp_hwmgr *hwmgr)
4624 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4626 data->uvd_power_gated = false;
4627 data->vce_power_gated = false;
4628 data->samu_power_gated = false;
4633 static int polaris10_init_sclk_threshold(struct pp_hwmgr *hwmgr)
4635 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4636 data->low_sclk_interrupt_threshold = 0;
4641 int polaris10_setup_asic_task(struct pp_hwmgr *hwmgr)
4643 int tmp_result, result = 0;
4645 polaris10_upload_mc_firmware(hwmgr);
4647 tmp_result = polaris10_read_clock_registers(hwmgr);
4648 PP_ASSERT_WITH_CODE((0 == tmp_result),
4649 "Failed to read clock registers!", result = tmp_result);
4651 tmp_result = polaris10_get_memory_type(hwmgr);
4652 PP_ASSERT_WITH_CODE((0 == tmp_result),
4653 "Failed to get memory type!", result = tmp_result);
4655 tmp_result = polaris10_enable_acpi_power_management(hwmgr);
4656 PP_ASSERT_WITH_CODE((0 == tmp_result),
4657 "Failed to enable ACPI power management!", result = tmp_result);
4659 tmp_result = polaris10_init_power_gate_state(hwmgr);
4660 PP_ASSERT_WITH_CODE((0 == tmp_result),
4661 "Failed to init power gate state!", result = tmp_result);
4663 tmp_result = phm_get_mc_microcode_version(hwmgr);
4664 PP_ASSERT_WITH_CODE((0 == tmp_result),
4665 "Failed to get MC microcode version!", result = tmp_result);
4667 tmp_result = polaris10_init_sclk_threshold(hwmgr);
4668 PP_ASSERT_WITH_CODE((0 == tmp_result),
4669 "Failed to init sclk threshold!", result = tmp_result);
4674 static int polaris10_get_pp_table(struct pp_hwmgr *hwmgr, char **table)
4676 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4678 *table = (char *)&data->smc_state_table;
4680 return sizeof(struct SMU74_Discrete_DpmTable);
4683 static int polaris10_set_pp_table(struct pp_hwmgr *hwmgr, const char *buf, size_t size)
4685 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4687 void *table = (void *)&data->smc_state_table;
4689 memcpy(table, buf, size);
4694 static int polaris10_force_clock_level(struct pp_hwmgr *hwmgr,
4695 enum pp_clock_type type, int level)
4697 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4699 if (hwmgr->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL)
4704 if (!data->sclk_dpm_key_disabled)
4705 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4706 PPSMC_MSG_SCLKDPM_SetEnabledMask,
4710 if (!data->mclk_dpm_key_disabled)
4711 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4712 PPSMC_MSG_MCLKDPM_SetEnabledMask,
4716 if (!data->pcie_dpm_key_disabled)
4717 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4718 PPSMC_MSG_PCIeDPM_ForceLevel,
4728 static uint16_t polaris10_get_current_pcie_speed(struct pp_hwmgr *hwmgr)
4730 uint32_t speedCntl = 0;
4732 /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
4733 speedCntl = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__PCIE,
4734 ixPCIE_LC_SPEED_CNTL);
4735 return((uint16_t)PHM_GET_FIELD(speedCntl,
4736 PCIE_LC_SPEED_CNTL, LC_CURRENT_DATA_RATE));
4739 static int polaris10_print_clock_levels(struct pp_hwmgr *hwmgr,
4740 enum pp_clock_type type, char *buf)
4742 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
4743 struct polaris10_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
4744 struct polaris10_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
4745 struct polaris10_single_dpm_table *pcie_table = &(data->dpm_table.pcie_speed_table);
4746 int i, now, size = 0;
4747 uint32_t clock, pcie_speed;
4751 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetSclkFrequency);
4752 clock = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
4754 for (i = 0; i < sclk_table->count; i++) {
4755 if (clock > sclk_table->dpm_levels[i].value)
4761 for (i = 0; i < sclk_table->count; i++)
4762 size += sprintf(buf + size, "%d: %uMhz %s\n",
4763 i, sclk_table->dpm_levels[i].value / 100,
4764 (i == now) ? "*" : "");
4767 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetMclkFrequency);
4768 clock = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
4770 for (i = 0; i < mclk_table->count; i++) {
4771 if (clock > mclk_table->dpm_levels[i].value)
4777 for (i = 0; i < mclk_table->count; i++)
4778 size += sprintf(buf + size, "%d: %uMhz %s\n",
4779 i, mclk_table->dpm_levels[i].value / 100,
4780 (i == now) ? "*" : "");
4783 pcie_speed = polaris10_get_current_pcie_speed(hwmgr);
4784 for (i = 0; i < pcie_table->count; i++) {
4785 if (pcie_speed != pcie_table->dpm_levels[i].value)
4791 for (i = 0; i < pcie_table->count; i++)
4792 size += sprintf(buf + size, "%d: %s %s\n", i,
4793 (pcie_table->dpm_levels[i].value == 0) ? "2.5GB, x8" :
4794 (pcie_table->dpm_levels[i].value == 1) ? "5.0GB, x16" :
4795 (pcie_table->dpm_levels[i].value == 2) ? "8.0GB, x16" : "",
4796 (i == now) ? "*" : "");
4804 static const struct pp_hwmgr_func polaris10_hwmgr_funcs = {
4805 .backend_init = &polaris10_hwmgr_backend_init,
4806 .backend_fini = &polaris10_hwmgr_backend_fini,
4807 .asic_setup = &polaris10_setup_asic_task,
4808 .dynamic_state_management_enable = &polaris10_enable_dpm_tasks,
4809 .apply_state_adjust_rules = polaris10_apply_state_adjust_rules,
4810 .force_dpm_level = &polaris10_force_dpm_level,
4811 .power_state_set = polaris10_set_power_state_tasks,
4812 .get_power_state_size = polaris10_get_power_state_size,
4813 .get_mclk = polaris10_dpm_get_mclk,
4814 .get_sclk = polaris10_dpm_get_sclk,
4815 .patch_boot_state = polaris10_dpm_patch_boot_state,
4816 .get_pp_table_entry = polaris10_get_pp_table_entry,
4817 .get_num_of_pp_table_entries = tonga_get_number_of_powerplay_table_entries,
4818 .print_current_perforce_level = polaris10_print_current_perforce_level,
4819 .powerdown_uvd = polaris10_phm_powerdown_uvd,
4820 .powergate_uvd = polaris10_phm_powergate_uvd,
4821 .powergate_vce = polaris10_phm_powergate_vce,
4822 .disable_clock_power_gating = polaris10_phm_disable_clock_power_gating,
4823 .update_clock_gatings = polaris10_phm_update_clock_gatings,
4824 .notify_smc_display_config_after_ps_adjustment = polaris10_notify_smc_display_config_after_ps_adjustment,
4825 .display_config_changed = polaris10_display_configuration_changed_task,
4826 .set_max_fan_pwm_output = polaris10_set_max_fan_pwm_output,
4827 .set_max_fan_rpm_output = polaris10_set_max_fan_rpm_output,
4828 .get_temperature = polaris10_thermal_get_temperature,
4829 .stop_thermal_controller = polaris10_thermal_stop_thermal_controller,
4830 .get_fan_speed_info = polaris10_fan_ctrl_get_fan_speed_info,
4831 .get_fan_speed_percent = polaris10_fan_ctrl_get_fan_speed_percent,
4832 .set_fan_speed_percent = polaris10_fan_ctrl_set_fan_speed_percent,
4833 .reset_fan_speed_to_default = polaris10_fan_ctrl_reset_fan_speed_to_default,
4834 .get_fan_speed_rpm = polaris10_fan_ctrl_get_fan_speed_rpm,
4835 .set_fan_speed_rpm = polaris10_fan_ctrl_set_fan_speed_rpm,
4836 .uninitialize_thermal_controller = polaris10_thermal_ctrl_uninitialize_thermal_controller,
4837 .register_internal_thermal_interrupt = polaris10_register_internal_thermal_interrupt,
4838 .check_smc_update_required_for_display_configuration = polaris10_check_smc_update_required_for_display_configuration,
4839 .check_states_equal = polaris10_check_states_equal,
4840 .get_pp_table = polaris10_get_pp_table,
4841 .set_pp_table = polaris10_set_pp_table,
4842 .force_clock_level = polaris10_force_clock_level,
4843 .print_clock_levels = polaris10_print_clock_levels,
4844 .enable_per_cu_power_gating = polaris10_phm_enable_per_cu_power_gating,
4847 int polaris10_hwmgr_init(struct pp_hwmgr *hwmgr)
4849 struct polaris10_hwmgr *data;
4851 data = kzalloc (sizeof(struct polaris10_hwmgr), GFP_KERNEL);
4855 hwmgr->backend = data;
4856 hwmgr->hwmgr_func = &polaris10_hwmgr_funcs;
4857 hwmgr->pptable_func = &tonga_pptable_funcs;
4858 pp_polaris10_thermal_initialize(hwmgr);