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 "linux/delay.h"
29 #include "polaris10_hwmgr.h"
30 #include "polaris10_powertune.h"
31 #include "polaris10_dyn_defaults.h"
32 #include "polaris10_smumgr.h"
34 #include "ppatomctrl.h"
36 #include "tonga_pptable.h"
37 #include "pppcielanes.h"
38 #include "amd_pcie_helpers.h"
39 #include "hardwaremanager.h"
40 #include "tonga_processpptables.h"
41 #include "cgs_common.h"
43 #include "smu_ucode_xfer_vi.h"
44 #include "smu74_discrete.h"
45 #include "smu/smu_7_1_3_d.h"
46 #include "smu/smu_7_1_3_sh_mask.h"
47 #include "gmc/gmc_8_1_d.h"
48 #include "gmc/gmc_8_1_sh_mask.h"
49 #include "oss/oss_3_0_d.h"
50 #include "gca/gfx_8_0_d.h"
51 #include "bif/bif_5_0_d.h"
52 #include "bif/bif_5_0_sh_mask.h"
53 #include "gmc/gmc_8_1_d.h"
54 #include "gmc/gmc_8_1_sh_mask.h"
55 #include "bif/bif_5_0_d.h"
56 #include "bif/bif_5_0_sh_mask.h"
57 #include "dce/dce_10_0_d.h"
58 #include "dce/dce_10_0_sh_mask.h"
60 #include "polaris10_thermal.h"
61 #include "polaris10_clockpowergating.h"
63 #define MC_CG_ARB_FREQ_F0 0x0a
64 #define MC_CG_ARB_FREQ_F1 0x0b
65 #define MC_CG_ARB_FREQ_F2 0x0c
66 #define MC_CG_ARB_FREQ_F3 0x0d
68 #define MC_CG_SEQ_DRAMCONF_S0 0x05
69 #define MC_CG_SEQ_DRAMCONF_S1 0x06
70 #define MC_CG_SEQ_YCLK_SUSPEND 0x04
71 #define MC_CG_SEQ_YCLK_RESUME 0x0a
74 #define SMC_RAM_END 0x40000
76 #define SMC_CG_IND_START 0xc0030000
77 #define SMC_CG_IND_END 0xc0040000
79 #define VOLTAGE_SCALE 4
80 #define VOLTAGE_VID_OFFSET_SCALE1 625
81 #define VOLTAGE_VID_OFFSET_SCALE2 100
83 #define VDDC_VDDCI_DELTA 200
85 #define MEM_FREQ_LOW_LATENCY 25000
86 #define MEM_FREQ_HIGH_LATENCY 80000
88 #define MEM_LATENCY_HIGH 45
89 #define MEM_LATENCY_LOW 35
90 #define MEM_LATENCY_ERR 0xFFFF
92 #define MC_SEQ_MISC0_GDDR5_SHIFT 28
93 #define MC_SEQ_MISC0_GDDR5_MASK 0xf0000000
94 #define MC_SEQ_MISC0_GDDR5_VALUE 5
97 #define PCIE_BUS_CLK 10000
98 #define TCLK (PCIE_BUS_CLK / 10)
101 uint16_t polaris10_clock_stretcher_lookup_table
[2][4] = { {600, 1050, 3, 0},
104 /* [FF, SS] type, [] 4 voltage ranges, and [Floor Freq, Boundary Freq, VID min , VID max] */
105 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} },
106 { {275, 550, 104, 112}, {319, 638, 96, 103}, {360, 720, 64, 95}, {384, 768, 32, 63} } };
108 /* [Use_For_Low_freq] value, [0%, 5%, 10%, 7.14%, 14.28%, 20%] (coming from PWR_CKS_CNTL.stretch_amount reg spec) */
109 uint8_t polaris10_clock_stretch_amount_conversion
[2][6] = { {0, 1, 3, 2, 4, 5},
110 {0, 2, 4, 5, 6, 5} };
112 /** Values for the CG_THERMAL_CTRL::DPM_EVENT_SRC field. */
114 DPM_EVENT_SRC_ANALOG
= 0,
115 DPM_EVENT_SRC_EXTERNAL
= 1,
116 DPM_EVENT_SRC_DIGITAL
= 2,
117 DPM_EVENT_SRC_ANALOG_OR_EXTERNAL
= 3,
118 DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL
= 4
121 const unsigned long PhwPolaris10_Magic
= (unsigned long)(PHM_VIslands_Magic
);
123 struct polaris10_power_state
*cast_phw_polaris10_power_state(
124 struct pp_hw_power_state
*hw_ps
)
126 PP_ASSERT_WITH_CODE((PhwPolaris10_Magic
== hw_ps
->magic
),
127 "Invalid Powerstate Type!",
130 return (struct polaris10_power_state
*)hw_ps
;
133 const struct polaris10_power_state
*cast_const_phw_polaris10_power_state(
134 const struct pp_hw_power_state
*hw_ps
)
136 PP_ASSERT_WITH_CODE((PhwPolaris10_Magic
== hw_ps
->magic
),
137 "Invalid Powerstate Type!",
140 return (const struct polaris10_power_state
*)hw_ps
;
143 static bool polaris10_is_dpm_running(struct pp_hwmgr
*hwmgr
)
145 return (1 == PHM_READ_INDIRECT_FIELD(hwmgr
->device
,
146 CGS_IND_REG__SMC
, FEATURE_STATUS
, VOLTAGE_CONTROLLER_ON
))
151 * Find the MC microcode version and store it in the HwMgr struct
153 * @param hwmgr the address of the powerplay hardware manager.
156 int phm_get_mc_microcode_version (struct pp_hwmgr
*hwmgr
)
158 cgs_write_register(hwmgr
->device
, mmMC_SEQ_IO_DEBUG_INDEX
, 0x9F);
160 hwmgr
->microcode_version_info
.MC
= cgs_read_register(hwmgr
->device
, mmMC_SEQ_IO_DEBUG_DATA
);
165 uint16_t phm_get_current_pcie_speed(struct pp_hwmgr
*hwmgr
)
167 uint32_t speedCntl
= 0;
169 /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
170 speedCntl
= cgs_read_ind_register(hwmgr
->device
, CGS_IND_REG__PCIE
,
171 ixPCIE_LC_SPEED_CNTL
);
172 return((uint16_t)PHM_GET_FIELD(speedCntl
,
173 PCIE_LC_SPEED_CNTL
, LC_CURRENT_DATA_RATE
));
176 int phm_get_current_pcie_lane_number(struct pp_hwmgr
*hwmgr
)
180 /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
181 link_width
= PHM_READ_INDIRECT_FIELD(hwmgr
->device
, CGS_IND_REG__PCIE
,
182 PCIE_LC_LINK_WIDTH_CNTL
, LC_LINK_WIDTH_RD
);
184 PP_ASSERT_WITH_CODE((7 >= link_width
),
185 "Invalid PCIe lane width!", return 0);
187 return decode_pcie_lane_width(link_width
);
190 void phm_apply_dal_min_voltage_request(struct pp_hwmgr
*hwmgr
)
192 struct phm_ppt_v1_information
*table_info
=
193 (struct phm_ppt_v1_information
*)hwmgr
->pptable
;
194 struct phm_clock_voltage_dependency_table
*table
=
195 table_info
->vddc_dep_on_dal_pwrl
;
196 struct phm_ppt_v1_clock_voltage_dependency_table
*vddc_table
;
197 enum PP_DAL_POWERLEVEL dal_power_level
= hwmgr
->dal_power_level
;
198 uint32_t req_vddc
= 0, req_volt
, i
;
200 if (!table
&& !(dal_power_level
>= PP_DAL_POWERLEVEL_ULTRALOW
&&
201 dal_power_level
<= PP_DAL_POWERLEVEL_PERFORMANCE
))
204 for (i
= 0; i
< table
->count
; i
++) {
205 if (dal_power_level
== table
->entries
[i
].clk
) {
206 req_vddc
= table
->entries
[i
].v
;
211 vddc_table
= table_info
->vdd_dep_on_sclk
;
212 for (i
= 0; i
< vddc_table
->count
; i
++) {
213 if (req_vddc
<= vddc_table
->entries
[i
].vddc
) {
214 req_volt
= (((uint32_t)vddc_table
->entries
[i
].vddc
) * VOLTAGE_SCALE
)
216 smum_send_msg_to_smc_with_parameter(hwmgr
->smumgr
,
217 PPSMC_MSG_VddC_Request
, req_volt
);
221 printk(KERN_ERR
"DAL requested level can not"
222 " found a available voltage in VDDC DPM Table \n");
226 * Enable voltage control
228 * @param pHwMgr the address of the powerplay hardware manager.
229 * @return always PP_Result_OK
231 int polaris10_enable_smc_voltage_controller(struct pp_hwmgr
*hwmgr
)
234 (hwmgr
->smumgr
->smumgr_funcs
->send_msg_to_smc(hwmgr
->smumgr
, PPSMC_MSG_Voltage_Cntl_Enable
) == 0),
235 "Failed to enable voltage DPM during DPM Start Function!",
243 * Checks if we want to support voltage control
245 * @param hwmgr the address of the powerplay hardware manager.
247 static bool polaris10_voltage_control(const struct pp_hwmgr
*hwmgr
)
249 const struct polaris10_hwmgr
*data
=
250 (const struct polaris10_hwmgr
*)(hwmgr
->backend
);
252 return (POLARIS10_VOLTAGE_CONTROL_NONE
!= data
->voltage_control
);
256 * Enable voltage control
258 * @param hwmgr the address of the powerplay hardware manager.
261 static int polaris10_enable_voltage_control(struct pp_hwmgr
*hwmgr
)
263 /* enable voltage control */
264 PHM_WRITE_INDIRECT_FIELD(hwmgr
->device
, CGS_IND_REG__SMC
,
265 GENERAL_PWRMGT
, VOLT_PWRMGT_EN
, 1);
271 * Create Voltage Tables.
273 * @param hwmgr the address of the powerplay hardware manager.
276 static int polaris10_construct_voltage_tables(struct pp_hwmgr
*hwmgr
)
278 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
279 struct phm_ppt_v1_information
*table_info
=
280 (struct phm_ppt_v1_information
*)hwmgr
->pptable
;
283 if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO
== data
->mvdd_control
) {
284 result
= atomctrl_get_voltage_table_v3(hwmgr
,
285 VOLTAGE_TYPE_MVDDC
, VOLTAGE_OBJ_GPIO_LUT
,
286 &(data
->mvdd_voltage_table
));
287 PP_ASSERT_WITH_CODE((0 == result
),
288 "Failed to retrieve MVDD table.",
290 } else if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2
== data
->mvdd_control
) {
291 result
= phm_get_svi2_mvdd_voltage_table(&(data
->mvdd_voltage_table
),
292 table_info
->vdd_dep_on_mclk
);
293 PP_ASSERT_WITH_CODE((0 == result
),
294 "Failed to retrieve SVI2 MVDD table from dependancy table.",
298 if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO
== data
->vddci_control
) {
299 result
= atomctrl_get_voltage_table_v3(hwmgr
,
300 VOLTAGE_TYPE_VDDCI
, VOLTAGE_OBJ_GPIO_LUT
,
301 &(data
->vddci_voltage_table
));
302 PP_ASSERT_WITH_CODE((0 == result
),
303 "Failed to retrieve VDDCI table.",
305 } else if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2
== data
->vddci_control
) {
306 result
= phm_get_svi2_vddci_voltage_table(&(data
->vddci_voltage_table
),
307 table_info
->vdd_dep_on_mclk
);
308 PP_ASSERT_WITH_CODE((0 == result
),
309 "Failed to retrieve SVI2 VDDCI table from dependancy table.",
313 if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2
== data
->voltage_control
) {
314 result
= phm_get_svi2_vdd_voltage_table(&(data
->vddc_voltage_table
),
315 table_info
->vddc_lookup_table
);
316 PP_ASSERT_WITH_CODE((0 == result
),
317 "Failed to retrieve SVI2 VDDC table from lookup table.",
322 (data
->vddc_voltage_table
.count
<= (SMU74_MAX_LEVELS_VDDC
)),
323 "Too many voltage values for VDDC. Trimming to fit state table.",
324 phm_trim_voltage_table_to_fit_state_table(SMU74_MAX_LEVELS_VDDC
,
325 &(data
->vddc_voltage_table
)));
328 (data
->vddci_voltage_table
.count
<= (SMU74_MAX_LEVELS_VDDCI
)),
329 "Too many voltage values for VDDCI. Trimming to fit state table.",
330 phm_trim_voltage_table_to_fit_state_table(SMU74_MAX_LEVELS_VDDCI
,
331 &(data
->vddci_voltage_table
)));
334 (data
->mvdd_voltage_table
.count
<= (SMU74_MAX_LEVELS_MVDD
)),
335 "Too many voltage values for MVDD. Trimming to fit state table.",
336 phm_trim_voltage_table_to_fit_state_table(SMU74_MAX_LEVELS_MVDD
,
337 &(data
->mvdd_voltage_table
)));
343 * Programs static screed detection parameters
345 * @param hwmgr the address of the powerplay hardware manager.
348 static int polaris10_program_static_screen_threshold_parameters(
349 struct pp_hwmgr
*hwmgr
)
351 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
353 /* Set static screen threshold unit */
354 PHM_WRITE_INDIRECT_FIELD(hwmgr
->device
, CGS_IND_REG__SMC
,
355 CG_STATIC_SCREEN_PARAMETER
, STATIC_SCREEN_THRESHOLD_UNIT
,
356 data
->static_screen_threshold_unit
);
357 /* Set static screen threshold */
358 PHM_WRITE_INDIRECT_FIELD(hwmgr
->device
, CGS_IND_REG__SMC
,
359 CG_STATIC_SCREEN_PARAMETER
, STATIC_SCREEN_THRESHOLD
,
360 data
->static_screen_threshold
);
366 * Setup display gap for glitch free memory clock switching.
368 * @param hwmgr the address of the powerplay hardware manager.
371 static int polaris10_enable_display_gap(struct pp_hwmgr
*hwmgr
)
373 uint32_t display_gap
=
374 cgs_read_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
,
375 ixCG_DISPLAY_GAP_CNTL
);
377 display_gap
= PHM_SET_FIELD(display_gap
, CG_DISPLAY_GAP_CNTL
,
378 DISP_GAP
, DISPLAY_GAP_IGNORE
);
380 display_gap
= PHM_SET_FIELD(display_gap
, CG_DISPLAY_GAP_CNTL
,
381 DISP_GAP_MCHG
, DISPLAY_GAP_VBLANK
);
383 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
,
384 ixCG_DISPLAY_GAP_CNTL
, display_gap
);
390 * Programs activity state transition voting clients
392 * @param hwmgr the address of the powerplay hardware manager.
395 static int polaris10_program_voting_clients(struct pp_hwmgr
*hwmgr
)
397 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
399 /* Clear reset for voting clients before enabling DPM */
400 PHM_WRITE_INDIRECT_FIELD(hwmgr
->device
, CGS_IND_REG__SMC
,
401 SCLK_PWRMGT_CNTL
, RESET_SCLK_CNT
, 0);
402 PHM_WRITE_INDIRECT_FIELD(hwmgr
->device
, CGS_IND_REG__SMC
,
403 SCLK_PWRMGT_CNTL
, RESET_BUSY_CNT
, 0);
405 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
,
406 ixCG_FREQ_TRAN_VOTING_0
, data
->voting_rights_clients0
);
407 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
,
408 ixCG_FREQ_TRAN_VOTING_1
, data
->voting_rights_clients1
);
409 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
,
410 ixCG_FREQ_TRAN_VOTING_2
, data
->voting_rights_clients2
);
411 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
,
412 ixCG_FREQ_TRAN_VOTING_3
, data
->voting_rights_clients3
);
413 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
,
414 ixCG_FREQ_TRAN_VOTING_4
, data
->voting_rights_clients4
);
415 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
,
416 ixCG_FREQ_TRAN_VOTING_5
, data
->voting_rights_clients5
);
417 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
,
418 ixCG_FREQ_TRAN_VOTING_6
, data
->voting_rights_clients6
);
419 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
,
420 ixCG_FREQ_TRAN_VOTING_7
, data
->voting_rights_clients7
);
426 * Get the location of various tables inside the FW image.
428 * @param hwmgr the address of the powerplay hardware manager.
431 static int polaris10_process_firmware_header(struct pp_hwmgr
*hwmgr
)
433 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
434 struct polaris10_smumgr
*smu_data
= (struct polaris10_smumgr
*)(hwmgr
->smumgr
->backend
);
439 result
= polaris10_read_smc_sram_dword(hwmgr
->smumgr
,
440 SMU7_FIRMWARE_HEADER_LOCATION
+
441 offsetof(SMU74_Firmware_Header
, DpmTable
),
442 &tmp
, data
->sram_end
);
445 data
->dpm_table_start
= tmp
;
447 error
|= (0 != result
);
449 result
= polaris10_read_smc_sram_dword(hwmgr
->smumgr
,
450 SMU7_FIRMWARE_HEADER_LOCATION
+
451 offsetof(SMU74_Firmware_Header
, SoftRegisters
),
452 &tmp
, data
->sram_end
);
455 data
->soft_regs_start
= tmp
;
456 smu_data
->soft_regs_start
= tmp
;
459 error
|= (0 != result
);
461 result
= polaris10_read_smc_sram_dword(hwmgr
->smumgr
,
462 SMU7_FIRMWARE_HEADER_LOCATION
+
463 offsetof(SMU74_Firmware_Header
, mcRegisterTable
),
464 &tmp
, data
->sram_end
);
467 data
->mc_reg_table_start
= tmp
;
469 result
= polaris10_read_smc_sram_dword(hwmgr
->smumgr
,
470 SMU7_FIRMWARE_HEADER_LOCATION
+
471 offsetof(SMU74_Firmware_Header
, FanTable
),
472 &tmp
, data
->sram_end
);
475 data
->fan_table_start
= tmp
;
477 error
|= (0 != result
);
479 result
= polaris10_read_smc_sram_dword(hwmgr
->smumgr
,
480 SMU7_FIRMWARE_HEADER_LOCATION
+
481 offsetof(SMU74_Firmware_Header
, mcArbDramTimingTable
),
482 &tmp
, data
->sram_end
);
485 data
->arb_table_start
= tmp
;
487 error
|= (0 != result
);
489 result
= polaris10_read_smc_sram_dword(hwmgr
->smumgr
,
490 SMU7_FIRMWARE_HEADER_LOCATION
+
491 offsetof(SMU74_Firmware_Header
, Version
),
492 &tmp
, data
->sram_end
);
495 hwmgr
->microcode_version_info
.SMC
= tmp
;
497 error
|= (0 != result
);
499 return error
? -1 : 0;
502 /* Copy one arb setting to another and then switch the active set.
503 * arb_src and arb_dest is one of the MC_CG_ARB_FREQ_Fx constants.
505 static int polaris10_copy_and_switch_arb_sets(struct pp_hwmgr
*hwmgr
,
506 uint32_t arb_src
, uint32_t arb_dest
)
508 uint32_t mc_arb_dram_timing
;
509 uint32_t mc_arb_dram_timing2
;
511 uint32_t mc_cg_config
;
514 case MC_CG_ARB_FREQ_F0
:
515 mc_arb_dram_timing
= cgs_read_register(hwmgr
->device
, mmMC_ARB_DRAM_TIMING
);
516 mc_arb_dram_timing2
= cgs_read_register(hwmgr
->device
, mmMC_ARB_DRAM_TIMING2
);
517 burst_time
= PHM_READ_FIELD(hwmgr
->device
, MC_ARB_BURST_TIME
, STATE0
);
519 case MC_CG_ARB_FREQ_F1
:
520 mc_arb_dram_timing
= cgs_read_register(hwmgr
->device
, mmMC_ARB_DRAM_TIMING_1
);
521 mc_arb_dram_timing2
= cgs_read_register(hwmgr
->device
, mmMC_ARB_DRAM_TIMING2_1
);
522 burst_time
= PHM_READ_FIELD(hwmgr
->device
, MC_ARB_BURST_TIME
, STATE1
);
529 case MC_CG_ARB_FREQ_F0
:
530 cgs_write_register(hwmgr
->device
, mmMC_ARB_DRAM_TIMING
, mc_arb_dram_timing
);
531 cgs_write_register(hwmgr
->device
, mmMC_ARB_DRAM_TIMING2
, mc_arb_dram_timing2
);
532 PHM_WRITE_FIELD(hwmgr
->device
, MC_ARB_BURST_TIME
, STATE0
, burst_time
);
534 case MC_CG_ARB_FREQ_F1
:
535 cgs_write_register(hwmgr
->device
, mmMC_ARB_DRAM_TIMING_1
, mc_arb_dram_timing
);
536 cgs_write_register(hwmgr
->device
, mmMC_ARB_DRAM_TIMING2_1
, mc_arb_dram_timing2
);
537 PHM_WRITE_FIELD(hwmgr
->device
, MC_ARB_BURST_TIME
, STATE1
, burst_time
);
543 mc_cg_config
= cgs_read_register(hwmgr
->device
, mmMC_CG_CONFIG
);
544 mc_cg_config
|= 0x0000000F;
545 cgs_write_register(hwmgr
->device
, mmMC_CG_CONFIG
, mc_cg_config
);
546 PHM_WRITE_FIELD(hwmgr
->device
, MC_ARB_CG
, CG_ARB_REQ
, arb_dest
);
552 * Initial switch from ARB F0->F1
554 * @param hwmgr the address of the powerplay hardware manager.
556 * This function is to be called from the SetPowerState table.
558 static int polaris10_initial_switch_from_arbf0_to_f1(struct pp_hwmgr
*hwmgr
)
560 return polaris10_copy_and_switch_arb_sets(hwmgr
,
561 MC_CG_ARB_FREQ_F0
, MC_CG_ARB_FREQ_F1
);
564 static int polaris10_setup_default_pcie_table(struct pp_hwmgr
*hwmgr
)
566 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
567 struct phm_ppt_v1_information
*table_info
=
568 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
569 struct phm_ppt_v1_pcie_table
*pcie_table
= table_info
->pcie_table
;
570 uint32_t i
, max_entry
;
572 PP_ASSERT_WITH_CODE((data
->use_pcie_performance_levels
||
573 data
->use_pcie_power_saving_levels
), "No pcie performance levels!",
576 if (data
->use_pcie_performance_levels
&&
577 !data
->use_pcie_power_saving_levels
) {
578 data
->pcie_gen_power_saving
= data
->pcie_gen_performance
;
579 data
->pcie_lane_power_saving
= data
->pcie_lane_performance
;
580 } else if (!data
->use_pcie_performance_levels
&&
581 data
->use_pcie_power_saving_levels
) {
582 data
->pcie_gen_performance
= data
->pcie_gen_power_saving
;
583 data
->pcie_lane_performance
= data
->pcie_lane_power_saving
;
586 phm_reset_single_dpm_table(&data
->dpm_table
.pcie_speed_table
,
587 SMU74_MAX_LEVELS_LINK
,
588 MAX_REGULAR_DPM_NUMBER
);
590 if (pcie_table
!= NULL
) {
591 /* max_entry is used to make sure we reserve one PCIE level
592 * for boot level (fix for A+A PSPP issue).
593 * If PCIE table from PPTable have ULV entry + 8 entries,
594 * then ignore the last entry.*/
595 max_entry
= (SMU74_MAX_LEVELS_LINK
< pcie_table
->count
) ?
596 SMU74_MAX_LEVELS_LINK
: pcie_table
->count
;
597 for (i
= 1; i
< max_entry
; i
++) {
598 phm_setup_pcie_table_entry(&data
->dpm_table
.pcie_speed_table
, i
- 1,
599 get_pcie_gen_support(data
->pcie_gen_cap
,
600 pcie_table
->entries
[i
].gen_speed
),
601 get_pcie_lane_support(data
->pcie_lane_cap
,
602 pcie_table
->entries
[i
].lane_width
));
604 data
->dpm_table
.pcie_speed_table
.count
= max_entry
- 1;
606 /* Setup BIF_SCLK levels */
607 for (i
= 0; i
< max_entry
; i
++)
608 data
->bif_sclk_table
[i
] = pcie_table
->entries
[i
].pcie_sclk
;
610 /* Hardcode Pcie Table */
611 phm_setup_pcie_table_entry(&data
->dpm_table
.pcie_speed_table
, 0,
612 get_pcie_gen_support(data
->pcie_gen_cap
,
614 get_pcie_lane_support(data
->pcie_lane_cap
,
616 phm_setup_pcie_table_entry(&data
->dpm_table
.pcie_speed_table
, 1,
617 get_pcie_gen_support(data
->pcie_gen_cap
,
619 get_pcie_lane_support(data
->pcie_lane_cap
,
621 phm_setup_pcie_table_entry(&data
->dpm_table
.pcie_speed_table
, 2,
622 get_pcie_gen_support(data
->pcie_gen_cap
,
624 get_pcie_lane_support(data
->pcie_lane_cap
,
626 phm_setup_pcie_table_entry(&data
->dpm_table
.pcie_speed_table
, 3,
627 get_pcie_gen_support(data
->pcie_gen_cap
,
629 get_pcie_lane_support(data
->pcie_lane_cap
,
631 phm_setup_pcie_table_entry(&data
->dpm_table
.pcie_speed_table
, 4,
632 get_pcie_gen_support(data
->pcie_gen_cap
,
634 get_pcie_lane_support(data
->pcie_lane_cap
,
636 phm_setup_pcie_table_entry(&data
->dpm_table
.pcie_speed_table
, 5,
637 get_pcie_gen_support(data
->pcie_gen_cap
,
639 get_pcie_lane_support(data
->pcie_lane_cap
,
642 data
->dpm_table
.pcie_speed_table
.count
= 6;
644 /* Populate last level for boot PCIE level, but do not increment count. */
645 phm_setup_pcie_table_entry(&data
->dpm_table
.pcie_speed_table
,
646 data
->dpm_table
.pcie_speed_table
.count
,
647 get_pcie_gen_support(data
->pcie_gen_cap
,
649 get_pcie_lane_support(data
->pcie_lane_cap
,
656 * This function is to initalize all DPM state tables
657 * for SMU7 based on the dependency table.
658 * Dynamic state patching function will then trim these
659 * state tables to the allowed range based
660 * on the power policy or external client requests,
661 * such as UVD request, etc.
663 int polaris10_setup_default_dpm_tables(struct pp_hwmgr
*hwmgr
)
665 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
666 struct phm_ppt_v1_information
*table_info
=
667 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
670 struct phm_ppt_v1_clock_voltage_dependency_table
*dep_sclk_table
=
671 table_info
->vdd_dep_on_sclk
;
672 struct phm_ppt_v1_clock_voltage_dependency_table
*dep_mclk_table
=
673 table_info
->vdd_dep_on_mclk
;
675 PP_ASSERT_WITH_CODE(dep_sclk_table
!= NULL
,
676 "SCLK dependency table is missing. This table is mandatory",
678 PP_ASSERT_WITH_CODE(dep_sclk_table
->count
>= 1,
679 "SCLK dependency table has to have is missing."
680 "This table is mandatory",
683 PP_ASSERT_WITH_CODE(dep_mclk_table
!= NULL
,
684 "MCLK dependency table is missing. This table is mandatory",
686 PP_ASSERT_WITH_CODE(dep_mclk_table
->count
>= 1,
687 "MCLK dependency table has to have is missing."
688 "This table is mandatory",
691 /* clear the state table to reset everything to default */
692 phm_reset_single_dpm_table(
693 &data
->dpm_table
.sclk_table
, SMU74_MAX_LEVELS_GRAPHICS
, MAX_REGULAR_DPM_NUMBER
);
694 phm_reset_single_dpm_table(
695 &data
->dpm_table
.mclk_table
, SMU74_MAX_LEVELS_MEMORY
, MAX_REGULAR_DPM_NUMBER
);
698 /* Initialize Sclk DPM table based on allow Sclk values */
699 data
->dpm_table
.sclk_table
.count
= 0;
700 for (i
= 0; i
< dep_sclk_table
->count
; i
++) {
701 if (i
== 0 || data
->dpm_table
.sclk_table
.dpm_levels
[data
->dpm_table
.sclk_table
.count
- 1].value
!=
702 dep_sclk_table
->entries
[i
].clk
) {
704 data
->dpm_table
.sclk_table
.dpm_levels
[data
->dpm_table
.sclk_table
.count
].value
=
705 dep_sclk_table
->entries
[i
].clk
;
707 data
->dpm_table
.sclk_table
.dpm_levels
[data
->dpm_table
.sclk_table
.count
].enabled
=
708 (i
== 0) ? true : false;
709 data
->dpm_table
.sclk_table
.count
++;
713 /* Initialize Mclk DPM table based on allow Mclk values */
714 data
->dpm_table
.mclk_table
.count
= 0;
715 for (i
= 0; i
< dep_mclk_table
->count
; i
++) {
716 if (i
== 0 || data
->dpm_table
.mclk_table
.dpm_levels
717 [data
->dpm_table
.mclk_table
.count
- 1].value
!=
718 dep_mclk_table
->entries
[i
].clk
) {
719 data
->dpm_table
.mclk_table
.dpm_levels
[data
->dpm_table
.mclk_table
.count
].value
=
720 dep_mclk_table
->entries
[i
].clk
;
721 data
->dpm_table
.mclk_table
.dpm_levels
[data
->dpm_table
.mclk_table
.count
].enabled
=
722 (i
== 0) ? true : false;
723 data
->dpm_table
.mclk_table
.count
++;
727 /* setup PCIE gen speed levels */
728 polaris10_setup_default_pcie_table(hwmgr
);
730 /* save a copy of the default DPM table */
731 memcpy(&(data
->golden_dpm_table
), &(data
->dpm_table
),
732 sizeof(struct polaris10_dpm_table
));
737 uint8_t convert_to_vid(uint16_t vddc
)
739 return (uint8_t) ((6200 - (vddc
* VOLTAGE_SCALE
)) / 25);
743 * Mvdd table preparation for SMC.
745 * @param *hwmgr The address of the hardware manager.
746 * @param *table The SMC DPM table structure to be populated.
749 static int polaris10_populate_smc_mvdd_table(struct pp_hwmgr
*hwmgr
,
750 SMU74_Discrete_DpmTable
*table
)
752 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
753 uint32_t count
, level
;
755 if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO
== data
->mvdd_control
) {
756 count
= data
->mvdd_voltage_table
.count
;
757 if (count
> SMU_MAX_SMIO_LEVELS
)
758 count
= SMU_MAX_SMIO_LEVELS
;
759 for (level
= 0; level
< count
; level
++) {
760 table
->SmioTable2
.Pattern
[level
].Voltage
=
761 PP_HOST_TO_SMC_US(data
->mvdd_voltage_table
.entries
[count
].value
* VOLTAGE_SCALE
);
762 /* Index into DpmTable.Smio. Drive bits from Smio entry to get this voltage level.*/
763 table
->SmioTable2
.Pattern
[level
].Smio
=
765 table
->Smio
[level
] |=
766 data
->mvdd_voltage_table
.entries
[level
].smio_low
;
768 table
->SmioMask2
= data
->vddci_voltage_table
.mask_low
;
770 table
->MvddLevelCount
= (uint32_t) PP_HOST_TO_SMC_UL(count
);
776 static int polaris10_populate_smc_vddci_table(struct pp_hwmgr
*hwmgr
,
777 struct SMU74_Discrete_DpmTable
*table
)
779 uint32_t count
, level
;
780 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
782 count
= data
->vddci_voltage_table
.count
;
784 if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO
== data
->vddci_control
) {
785 if (count
> SMU_MAX_SMIO_LEVELS
)
786 count
= SMU_MAX_SMIO_LEVELS
;
787 for (level
= 0; level
< count
; ++level
) {
788 table
->SmioTable1
.Pattern
[level
].Voltage
=
789 PP_HOST_TO_SMC_US(data
->vddci_voltage_table
.entries
[level
].value
* VOLTAGE_SCALE
);
790 table
->SmioTable1
.Pattern
[level
].Smio
= (uint8_t) level
;
792 table
->Smio
[level
] |= data
->vddci_voltage_table
.entries
[level
].smio_low
;
796 table
->SmioMask1
= data
->vddci_voltage_table
.mask_low
;
802 * Preparation of vddc and vddgfx CAC tables for SMC.
804 * @param hwmgr the address of the hardware manager
805 * @param table the SMC DPM table structure to be populated
808 static int polaris10_populate_cac_table(struct pp_hwmgr
*hwmgr
,
809 struct SMU74_Discrete_DpmTable
*table
)
813 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
814 struct phm_ppt_v1_information
*table_info
=
815 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
816 struct phm_ppt_v1_voltage_lookup_table
*lookup_table
=
817 table_info
->vddc_lookup_table
;
818 /* tables is already swapped, so in order to use the value from it,
819 * we need to swap it back.
820 * We are populating vddc CAC data to BapmVddc table
821 * in split and merged mode
823 for (count
= 0; count
< lookup_table
->count
; count
++) {
824 index
= phm_get_voltage_index(lookup_table
,
825 data
->vddc_voltage_table
.entries
[count
].value
);
826 table
->BapmVddcVidLoSidd
[count
] = convert_to_vid(lookup_table
->entries
[index
].us_cac_low
);
827 table
->BapmVddcVidHiSidd
[count
] = convert_to_vid(lookup_table
->entries
[index
].us_cac_mid
);
828 table
->BapmVddcVidHiSidd2
[count
] = convert_to_vid(lookup_table
->entries
[index
].us_cac_high
);
835 * Preparation of voltage tables for SMC.
837 * @param hwmgr the address of the hardware manager
838 * @param table the SMC DPM table structure to be populated
842 int polaris10_populate_smc_voltage_tables(struct pp_hwmgr
*hwmgr
,
843 struct SMU74_Discrete_DpmTable
*table
)
845 polaris10_populate_smc_vddci_table(hwmgr
, table
);
846 polaris10_populate_smc_mvdd_table(hwmgr
, table
);
847 polaris10_populate_cac_table(hwmgr
, table
);
852 static int polaris10_populate_ulv_level(struct pp_hwmgr
*hwmgr
,
853 struct SMU74_Discrete_Ulv
*state
)
855 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
856 struct phm_ppt_v1_information
*table_info
=
857 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
859 state
->CcPwrDynRm
= 0;
860 state
->CcPwrDynRm1
= 0;
862 state
->VddcOffset
= (uint16_t) table_info
->us_ulv_voltage_offset
;
863 state
->VddcOffsetVid
= (uint8_t)(table_info
->us_ulv_voltage_offset
*
864 VOLTAGE_VID_OFFSET_SCALE2
/ VOLTAGE_VID_OFFSET_SCALE1
);
866 state
->VddcPhase
= (data
->vddc_phase_shed_control
) ? 0 : 1;
868 CONVERT_FROM_HOST_TO_SMC_UL(state
->CcPwrDynRm
);
869 CONVERT_FROM_HOST_TO_SMC_UL(state
->CcPwrDynRm1
);
870 CONVERT_FROM_HOST_TO_SMC_US(state
->VddcOffset
);
875 static int polaris10_populate_ulv_state(struct pp_hwmgr
*hwmgr
,
876 struct SMU74_Discrete_DpmTable
*table
)
878 return polaris10_populate_ulv_level(hwmgr
, &table
->Ulv
);
881 static int polaris10_populate_smc_link_level(struct pp_hwmgr
*hwmgr
,
882 struct SMU74_Discrete_DpmTable
*table
)
884 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
885 struct polaris10_dpm_table
*dpm_table
= &data
->dpm_table
;
888 /* Index (dpm_table->pcie_speed_table.count)
889 * is reserved for PCIE boot level. */
890 for (i
= 0; i
<= dpm_table
->pcie_speed_table
.count
; i
++) {
891 table
->LinkLevel
[i
].PcieGenSpeed
=
892 (uint8_t)dpm_table
->pcie_speed_table
.dpm_levels
[i
].value
;
893 table
->LinkLevel
[i
].PcieLaneCount
= (uint8_t)encode_pcie_lane_width(
894 dpm_table
->pcie_speed_table
.dpm_levels
[i
].param1
);
895 table
->LinkLevel
[i
].EnabledForActivity
= 1;
896 table
->LinkLevel
[i
].SPC
= (uint8_t)(data
->pcie_spc_cap
& 0xff);
897 table
->LinkLevel
[i
].DownThreshold
= PP_HOST_TO_SMC_UL(5);
898 table
->LinkLevel
[i
].UpThreshold
= PP_HOST_TO_SMC_UL(30);
901 data
->smc_state_table
.LinkLevelCount
=
902 (uint8_t)dpm_table
->pcie_speed_table
.count
;
903 data
->dpm_level_enable_mask
.pcie_dpm_enable_mask
=
904 phm_get_dpm_level_enable_mask_value(&dpm_table
->pcie_speed_table
);
909 static uint32_t polaris10_get_xclk(struct pp_hwmgr
*hwmgr
)
911 uint32_t reference_clock
, tmp
;
912 struct cgs_display_info info
= {0};
913 struct cgs_mode_info mode_info
;
915 info
.mode_info
= &mode_info
;
917 tmp
= PHM_READ_VFPF_INDIRECT_FIELD(hwmgr
->device
, CGS_IND_REG__SMC
, CG_CLKPIN_CNTL_2
, MUX_TCLK_TO_XCLK
);
922 cgs_get_active_displays_info(hwmgr
->device
, &info
);
923 reference_clock
= mode_info
.ref_clock
;
925 tmp
= PHM_READ_VFPF_INDIRECT_FIELD(hwmgr
->device
, CGS_IND_REG__SMC
, CG_CLKPIN_CNTL
, XTALIN_DIVIDE
);
928 return reference_clock
/ 4;
930 return reference_clock
;
934 * Calculates the SCLK dividers using the provided engine clock
936 * @param hwmgr the address of the hardware manager
937 * @param clock the engine clock to use to populate the structure
938 * @param sclk the SMC SCLK structure to be populated
940 static int polaris10_calculate_sclk_params(struct pp_hwmgr
*hwmgr
,
941 uint32_t clock
, SMU_SclkSetting
*sclk_setting
)
943 const struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
944 const SMU74_Discrete_DpmTable
*table
= &(data
->smc_state_table
);
945 struct pp_atomctrl_clock_dividers_ai dividers
;
948 uint32_t pcc_target_percent
, pcc_target_freq
, ss_target_percent
, ss_target_freq
;
953 sclk_setting
->SclkFrequency
= clock
;
954 /* get the engine clock dividers for this clock value */
955 result
= atomctrl_get_engine_pll_dividers_ai(hwmgr
, clock
, ÷rs
);
957 sclk_setting
->Fcw_int
= dividers
.usSclk_fcw_int
;
958 sclk_setting
->Fcw_frac
= dividers
.usSclk_fcw_frac
;
959 sclk_setting
->Pcc_fcw_int
= dividers
.usPcc_fcw_int
;
960 sclk_setting
->PllRange
= dividers
.ucSclkPllRange
;
961 sclk_setting
->Sclk_slew_rate
= 0x400;
962 sclk_setting
->Pcc_up_slew_rate
= dividers
.usPcc_fcw_slew_frac
;
963 sclk_setting
->Pcc_down_slew_rate
= 0xffff;
964 sclk_setting
->SSc_En
= dividers
.ucSscEnable
;
965 sclk_setting
->Fcw1_int
= dividers
.usSsc_fcw1_int
;
966 sclk_setting
->Fcw1_frac
= dividers
.usSsc_fcw1_frac
;
967 sclk_setting
->Sclk_ss_slew_rate
= dividers
.usSsc_fcw_slew_frac
;
971 ref_clock
= polaris10_get_xclk(hwmgr
);
973 for (i
= 0; i
< NUM_SCLK_RANGE
; i
++) {
974 if (clock
> data
->range_table
[i
].trans_lower_frequency
975 && clock
<= data
->range_table
[i
].trans_upper_frequency
) {
976 sclk_setting
->PllRange
= i
;
981 sclk_setting
->Fcw_int
= (uint16_t)((clock
<< table
->SclkFcwRangeTable
[sclk_setting
->PllRange
].postdiv
) / ref_clock
);
982 temp
= clock
<< table
->SclkFcwRangeTable
[sclk_setting
->PllRange
].postdiv
;
984 sclk_setting
->Fcw_frac
= (uint16_t)(0xFFFF & (temp
/ ref_clock
));
986 pcc_target_percent
= 10; /* Hardcode 10% for now. */
987 pcc_target_freq
= clock
- (clock
* pcc_target_percent
/ 100);
988 sclk_setting
->Pcc_fcw_int
= (uint16_t)((pcc_target_freq
<< table
->SclkFcwRangeTable
[sclk_setting
->PllRange
].postdiv
) / ref_clock
);
990 ss_target_percent
= 2; /* Hardcode 2% for now. */
991 sclk_setting
->SSc_En
= 0;
992 if (ss_target_percent
) {
993 sclk_setting
->SSc_En
= 1;
994 ss_target_freq
= clock
- (clock
* ss_target_percent
/ 100);
995 sclk_setting
->Fcw1_int
= (uint16_t)((ss_target_freq
<< table
->SclkFcwRangeTable
[sclk_setting
->PllRange
].postdiv
) / ref_clock
);
996 temp
= ss_target_freq
<< table
->SclkFcwRangeTable
[sclk_setting
->PllRange
].postdiv
;
998 sclk_setting
->Fcw1_frac
= (uint16_t)(0xFFFF & (temp
/ ref_clock
));
1004 static int polaris10_get_dependency_volt_by_clk(struct pp_hwmgr
*hwmgr
,
1005 struct phm_ppt_v1_clock_voltage_dependency_table
*dep_table
,
1006 uint32_t clock
, SMU_VoltageLevel
*voltage
, uint32_t *mvdd
)
1010 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
1012 *voltage
= *mvdd
= 0;
1014 /* clock - voltage dependency table is empty table */
1015 if (dep_table
->count
== 0)
1018 for (i
= 0; i
< dep_table
->count
; i
++) {
1019 /* find first sclk bigger than request */
1020 if (dep_table
->entries
[i
].clk
>= clock
) {
1021 *voltage
|= (dep_table
->entries
[i
].vddc
*
1022 VOLTAGE_SCALE
) << VDDC_SHIFT
;
1023 if (POLARIS10_VOLTAGE_CONTROL_NONE
== data
->vddci_control
)
1024 *voltage
|= (data
->vbios_boot_state
.vddci_bootup_value
*
1025 VOLTAGE_SCALE
) << VDDCI_SHIFT
;
1026 else if (dep_table
->entries
[i
].vddci
)
1027 *voltage
|= (dep_table
->entries
[i
].vddci
*
1028 VOLTAGE_SCALE
) << VDDCI_SHIFT
;
1030 vddci
= phm_find_closest_vddci(&(data
->vddci_voltage_table
),
1031 (dep_table
->entries
[i
].vddc
-
1032 (uint16_t)data
->vddc_vddci_delta
));
1033 *voltage
|= (vddci
* VOLTAGE_SCALE
) << VDDCI_SHIFT
;
1036 if (POLARIS10_VOLTAGE_CONTROL_NONE
== data
->mvdd_control
)
1037 *mvdd
= data
->vbios_boot_state
.mvdd_bootup_value
*
1039 else if (dep_table
->entries
[i
].mvdd
)
1040 *mvdd
= (uint32_t) dep_table
->entries
[i
].mvdd
*
1043 *voltage
|= 1 << PHASES_SHIFT
;
1048 /* sclk is bigger than max sclk in the dependence table */
1049 *voltage
|= (dep_table
->entries
[i
- 1].vddc
* VOLTAGE_SCALE
) << VDDC_SHIFT
;
1051 if (POLARIS10_VOLTAGE_CONTROL_NONE
== data
->vddci_control
)
1052 *voltage
|= (data
->vbios_boot_state
.vddci_bootup_value
*
1053 VOLTAGE_SCALE
) << VDDCI_SHIFT
;
1054 else if (dep_table
->entries
[i
-1].vddci
) {
1055 vddci
= phm_find_closest_vddci(&(data
->vddci_voltage_table
),
1056 (dep_table
->entries
[i
].vddc
-
1057 (uint16_t)data
->vddc_vddci_delta
));
1058 *voltage
|= (vddci
* VOLTAGE_SCALE
) << VDDCI_SHIFT
;
1061 if (POLARIS10_VOLTAGE_CONTROL_NONE
== data
->mvdd_control
)
1062 *mvdd
= data
->vbios_boot_state
.mvdd_bootup_value
* VOLTAGE_SCALE
;
1063 else if (dep_table
->entries
[i
].mvdd
)
1064 *mvdd
= (uint32_t) dep_table
->entries
[i
- 1].mvdd
* VOLTAGE_SCALE
;
1069 sclkFcwRange_t Range_Table
[NUM_SCLK_RANGE
] = { {VCO_2_4
, POSTDIV_DIV_BY_16
, 75, 160, 112},
1070 {VCO_3_6
, POSTDIV_DIV_BY_16
, 112, 224, 160},
1071 {VCO_2_4
, POSTDIV_DIV_BY_8
, 75, 160, 112},
1072 {VCO_3_6
, POSTDIV_DIV_BY_8
, 112, 224, 160},
1073 {VCO_2_4
, POSTDIV_DIV_BY_4
, 75, 160, 112},
1074 {VCO_3_6
, POSTDIV_DIV_BY_4
, 112, 216, 160},
1075 {VCO_2_4
, POSTDIV_DIV_BY_2
, 75, 160, 108},
1076 {VCO_3_6
, POSTDIV_DIV_BY_2
, 112, 216, 160} };
1078 static void polaris10_get_sclk_range_table(struct pp_hwmgr
*hwmgr
)
1080 uint32_t i
, ref_clk
;
1081 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
1082 SMU74_Discrete_DpmTable
*table
= &(data
->smc_state_table
);
1083 struct pp_atom_ctrl_sclk_range_table range_table_from_vbios
= { { {0} } };
1085 ref_clk
= polaris10_get_xclk(hwmgr
);
1087 if (0 == atomctrl_get_smc_sclk_range_table(hwmgr
, &range_table_from_vbios
)) {
1088 for (i
= 0; i
< NUM_SCLK_RANGE
; i
++) {
1089 table
->SclkFcwRangeTable
[i
].vco_setting
= range_table_from_vbios
.entry
[i
].ucVco_setting
;
1090 table
->SclkFcwRangeTable
[i
].postdiv
= range_table_from_vbios
.entry
[i
].ucPostdiv
;
1091 table
->SclkFcwRangeTable
[i
].fcw_pcc
= range_table_from_vbios
.entry
[i
].usFcw_pcc
;
1093 table
->SclkFcwRangeTable
[i
].fcw_trans_upper
= range_table_from_vbios
.entry
[i
].usFcw_trans_upper
;
1094 table
->SclkFcwRangeTable
[i
].fcw_trans_lower
= range_table_from_vbios
.entry
[i
].usRcw_trans_lower
;
1096 CONVERT_FROM_HOST_TO_SMC_US(table
->SclkFcwRangeTable
[i
].fcw_pcc
);
1097 CONVERT_FROM_HOST_TO_SMC_US(table
->SclkFcwRangeTable
[i
].fcw_trans_upper
);
1098 CONVERT_FROM_HOST_TO_SMC_US(table
->SclkFcwRangeTable
[i
].fcw_trans_lower
);
1103 for (i
= 0; i
< NUM_SCLK_RANGE
; i
++) {
1105 data
->range_table
[i
].trans_lower_frequency
= (ref_clk
* Range_Table
[i
].fcw_trans_lower
) >> Range_Table
[i
].postdiv
;
1106 data
->range_table
[i
].trans_upper_frequency
= (ref_clk
* Range_Table
[i
].fcw_trans_upper
) >> Range_Table
[i
].postdiv
;
1108 table
->SclkFcwRangeTable
[i
].vco_setting
= Range_Table
[i
].vco_setting
;
1109 table
->SclkFcwRangeTable
[i
].postdiv
= Range_Table
[i
].postdiv
;
1110 table
->SclkFcwRangeTable
[i
].fcw_pcc
= Range_Table
[i
].fcw_pcc
;
1112 table
->SclkFcwRangeTable
[i
].fcw_trans_upper
= Range_Table
[i
].fcw_trans_upper
;
1113 table
->SclkFcwRangeTable
[i
].fcw_trans_lower
= Range_Table
[i
].fcw_trans_lower
;
1115 CONVERT_FROM_HOST_TO_SMC_US(table
->SclkFcwRangeTable
[i
].fcw_pcc
);
1116 CONVERT_FROM_HOST_TO_SMC_US(table
->SclkFcwRangeTable
[i
].fcw_trans_upper
);
1117 CONVERT_FROM_HOST_TO_SMC_US(table
->SclkFcwRangeTable
[i
].fcw_trans_lower
);
1122 * Populates single SMC SCLK structure using the provided engine clock
1124 * @param hwmgr the address of the hardware manager
1125 * @param clock the engine clock to use to populate the structure
1126 * @param sclk the SMC SCLK structure to be populated
1129 static int polaris10_populate_single_graphic_level(struct pp_hwmgr
*hwmgr
,
1130 uint32_t clock
, uint16_t sclk_al_threshold
,
1131 struct SMU74_Discrete_GraphicsLevel
*level
)
1133 int result
, i
, temp
;
1134 /* PP_Clocks minClocks; */
1136 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
1137 struct phm_ppt_v1_information
*table_info
=
1138 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
1139 SMU_SclkSetting curr_sclk_setting
= { 0 };
1141 result
= polaris10_calculate_sclk_params(hwmgr
, clock
, &curr_sclk_setting
);
1143 /* populate graphics levels */
1144 result
= polaris10_get_dependency_volt_by_clk(hwmgr
,
1145 table_info
->vdd_dep_on_sclk
, clock
,
1146 &level
->MinVoltage
, &mvdd
);
1148 PP_ASSERT_WITH_CODE((0 == result
),
1149 "can not find VDDC voltage value for "
1150 "VDDC engine clock dependency table",
1152 level
->ActivityLevel
= sclk_al_threshold
;
1154 level
->CcPwrDynRm
= 0;
1155 level
->CcPwrDynRm1
= 0;
1156 level
->EnabledForActivity
= 0;
1157 level
->EnabledForThrottle
= 1;
1159 level
->DownHyst
= 0;
1160 level
->VoltageDownHyst
= 0;
1161 level
->PowerThrottle
= 0;
1164 * TODO: get minimum clocks from dal configaration
1165 * PECI_GetMinClockSettings(hwmgr->pPECI, &minClocks);
1167 /* data->DisplayTiming.minClockInSR = minClocks.engineClockInSR; */
1169 /* get level->DeepSleepDivId
1170 if (phm_cap_enabled(hwmgr->platformDescriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep))
1171 level->DeepSleepDivId = PhwFiji_GetSleepDividerIdFromClock(hwmgr, clock, minClocks.engineClockInSR);
1173 PP_ASSERT_WITH_CODE((clock
>= 2500), "Engine clock can't satisfy stutter requirement!", return 0);
1174 for (i
= POLARIS10_MAX_DEEPSLEEP_DIVIDER_ID
; ; i
--) {
1175 temp
= clock
/ (1UL << i
);
1177 if (temp
>= 2500 || i
== 0)
1181 level
->DeepSleepDivId
= i
;
1183 /* Default to slow, highest DPM level will be
1184 * set to PPSMC_DISPLAY_WATERMARK_LOW later.
1186 if (data
->update_up_hyst
)
1187 level
->UpHyst
= (uint8_t)data
->up_hyst
;
1188 if (data
->update_down_hyst
)
1189 level
->DownHyst
= (uint8_t)data
->down_hyst
;
1191 level
->SclkSetting
= curr_sclk_setting
;
1193 CONVERT_FROM_HOST_TO_SMC_UL(level
->MinVoltage
);
1194 CONVERT_FROM_HOST_TO_SMC_UL(level
->CcPwrDynRm
);
1195 CONVERT_FROM_HOST_TO_SMC_UL(level
->CcPwrDynRm1
);
1196 CONVERT_FROM_HOST_TO_SMC_US(level
->ActivityLevel
);
1197 CONVERT_FROM_HOST_TO_SMC_UL(level
->SclkSetting
.SclkFrequency
);
1198 CONVERT_FROM_HOST_TO_SMC_US(level
->SclkSetting
.Fcw_int
);
1199 CONVERT_FROM_HOST_TO_SMC_US(level
->SclkSetting
.Fcw_frac
);
1200 CONVERT_FROM_HOST_TO_SMC_US(level
->SclkSetting
.Pcc_fcw_int
);
1201 CONVERT_FROM_HOST_TO_SMC_US(level
->SclkSetting
.Sclk_slew_rate
);
1202 CONVERT_FROM_HOST_TO_SMC_US(level
->SclkSetting
.Pcc_up_slew_rate
);
1203 CONVERT_FROM_HOST_TO_SMC_US(level
->SclkSetting
.Pcc_down_slew_rate
);
1204 CONVERT_FROM_HOST_TO_SMC_US(level
->SclkSetting
.Fcw1_int
);
1205 CONVERT_FROM_HOST_TO_SMC_US(level
->SclkSetting
.Fcw1_frac
);
1206 CONVERT_FROM_HOST_TO_SMC_US(level
->SclkSetting
.Sclk_ss_slew_rate
);
1211 * Populates all SMC SCLK levels' structure based on the trimmed allowed dpm engine clock states
1213 * @param hwmgr the address of the hardware manager
1215 static int polaris10_populate_all_graphic_levels(struct pp_hwmgr
*hwmgr
)
1217 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
1218 struct polaris10_dpm_table
*dpm_table
= &data
->dpm_table
;
1219 struct phm_ppt_v1_information
*table_info
=
1220 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
1221 struct phm_ppt_v1_pcie_table
*pcie_table
= table_info
->pcie_table
;
1222 uint8_t pcie_entry_cnt
= (uint8_t) data
->dpm_table
.pcie_speed_table
.count
;
1224 uint32_t array
= data
->dpm_table_start
+
1225 offsetof(SMU74_Discrete_DpmTable
, GraphicsLevel
);
1226 uint32_t array_size
= sizeof(struct SMU74_Discrete_GraphicsLevel
) *
1227 SMU74_MAX_LEVELS_GRAPHICS
;
1228 struct SMU74_Discrete_GraphicsLevel
*levels
=
1229 data
->smc_state_table
.GraphicsLevel
;
1230 uint32_t i
, max_entry
;
1231 uint8_t hightest_pcie_level_enabled
= 0,
1232 lowest_pcie_level_enabled
= 0,
1233 mid_pcie_level_enabled
= 0,
1236 polaris10_get_sclk_range_table(hwmgr
);
1238 for (i
= 0; i
< dpm_table
->sclk_table
.count
; i
++) {
1240 result
= polaris10_populate_single_graphic_level(hwmgr
,
1241 dpm_table
->sclk_table
.dpm_levels
[i
].value
,
1242 (uint16_t)data
->activity_target
[i
],
1243 &(data
->smc_state_table
.GraphicsLevel
[i
]));
1247 /* Making sure only DPM level 0-1 have Deep Sleep Div ID populated. */
1249 levels
[i
].DeepSleepDivId
= 0;
1252 data
->smc_state_table
.GraphicsLevel
[0].EnabledForActivity
= 1;
1253 data
->smc_state_table
.GraphicsDpmLevelCount
=
1254 (uint8_t)dpm_table
->sclk_table
.count
;
1255 data
->dpm_level_enable_mask
.sclk_dpm_enable_mask
=
1256 phm_get_dpm_level_enable_mask_value(&dpm_table
->sclk_table
);
1259 if (pcie_table
!= NULL
) {
1260 PP_ASSERT_WITH_CODE((1 <= pcie_entry_cnt
),
1261 "There must be 1 or more PCIE levels defined in PPTable.",
1263 max_entry
= pcie_entry_cnt
- 1;
1264 for (i
= 0; i
< dpm_table
->sclk_table
.count
; i
++)
1265 levels
[i
].pcieDpmLevel
=
1266 (uint8_t) ((i
< max_entry
) ? i
: max_entry
);
1268 while (data
->dpm_level_enable_mask
.pcie_dpm_enable_mask
&&
1269 ((data
->dpm_level_enable_mask
.pcie_dpm_enable_mask
&
1270 (1 << (hightest_pcie_level_enabled
+ 1))) != 0))
1271 hightest_pcie_level_enabled
++;
1273 while (data
->dpm_level_enable_mask
.pcie_dpm_enable_mask
&&
1274 ((data
->dpm_level_enable_mask
.pcie_dpm_enable_mask
&
1275 (1 << lowest_pcie_level_enabled
)) == 0))
1276 lowest_pcie_level_enabled
++;
1278 while ((count
< hightest_pcie_level_enabled
) &&
1279 ((data
->dpm_level_enable_mask
.pcie_dpm_enable_mask
&
1280 (1 << (lowest_pcie_level_enabled
+ 1 + count
))) == 0))
1283 mid_pcie_level_enabled
= (lowest_pcie_level_enabled
+ 1 + count
) <
1284 hightest_pcie_level_enabled
?
1285 (lowest_pcie_level_enabled
+ 1 + count
) :
1286 hightest_pcie_level_enabled
;
1288 /* set pcieDpmLevel to hightest_pcie_level_enabled */
1289 for (i
= 2; i
< dpm_table
->sclk_table
.count
; i
++)
1290 levels
[i
].pcieDpmLevel
= hightest_pcie_level_enabled
;
1292 /* set pcieDpmLevel to lowest_pcie_level_enabled */
1293 levels
[0].pcieDpmLevel
= lowest_pcie_level_enabled
;
1295 /* set pcieDpmLevel to mid_pcie_level_enabled */
1296 levels
[1].pcieDpmLevel
= mid_pcie_level_enabled
;
1298 /* level count will send to smc once at init smc table and never change */
1299 result
= polaris10_copy_bytes_to_smc(hwmgr
->smumgr
, array
, (uint8_t *)levels
,
1300 (uint32_t)array_size
, data
->sram_end
);
1305 static int polaris10_populate_single_memory_level(struct pp_hwmgr
*hwmgr
,
1306 uint32_t clock
, struct SMU74_Discrete_MemoryLevel
*mem_level
)
1308 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
1309 struct phm_ppt_v1_information
*table_info
=
1310 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
1312 struct cgs_display_info info
= {0, 0, NULL
};
1314 cgs_get_active_displays_info(hwmgr
->device
, &info
);
1316 if (table_info
->vdd_dep_on_mclk
) {
1317 result
= polaris10_get_dependency_volt_by_clk(hwmgr
,
1318 table_info
->vdd_dep_on_mclk
, clock
,
1319 &mem_level
->MinVoltage
, &mem_level
->MinMvdd
);
1320 PP_ASSERT_WITH_CODE((0 == result
),
1321 "can not find MinVddc voltage value from memory "
1322 "VDDC voltage dependency table", return result
);
1325 mem_level
->MclkFrequency
= clock
;
1326 mem_level
->StutterEnable
= 0;
1327 mem_level
->EnabledForThrottle
= 1;
1328 mem_level
->EnabledForActivity
= 0;
1329 mem_level
->UpHyst
= 0;
1330 mem_level
->DownHyst
= 100;
1331 mem_level
->VoltageDownHyst
= 0;
1332 mem_level
->ActivityLevel
= (uint16_t)data
->mclk_activity_target
;
1333 mem_level
->StutterEnable
= false;
1335 mem_level
->DisplayWatermark
= PPSMC_DISPLAY_WATERMARK_LOW
;
1337 data
->display_timing
.num_existing_displays
= info
.display_count
;
1339 if ((data
->mclk_stutter_mode_threshold
) &&
1340 (clock
<= data
->mclk_stutter_mode_threshold
) &&
1341 (PHM_READ_FIELD(hwmgr
->device
, DPG_PIPE_STUTTER_CONTROL
,
1342 STUTTER_ENABLE
) & 0x1))
1343 mem_level
->StutterEnable
= true;
1346 CONVERT_FROM_HOST_TO_SMC_UL(mem_level
->MinMvdd
);
1347 CONVERT_FROM_HOST_TO_SMC_UL(mem_level
->MclkFrequency
);
1348 CONVERT_FROM_HOST_TO_SMC_US(mem_level
->ActivityLevel
);
1349 CONVERT_FROM_HOST_TO_SMC_UL(mem_level
->MinVoltage
);
1355 * Populates all SMC MCLK levels' structure based on the trimmed allowed dpm memory clock states
1357 * @param hwmgr the address of the hardware manager
1359 static int polaris10_populate_all_memory_levels(struct pp_hwmgr
*hwmgr
)
1361 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
1362 struct polaris10_dpm_table
*dpm_table
= &data
->dpm_table
;
1364 /* populate MCLK dpm table to SMU7 */
1365 uint32_t array
= data
->dpm_table_start
+
1366 offsetof(SMU74_Discrete_DpmTable
, MemoryLevel
);
1367 uint32_t array_size
= sizeof(SMU74_Discrete_MemoryLevel
) *
1368 SMU74_MAX_LEVELS_MEMORY
;
1369 struct SMU74_Discrete_MemoryLevel
*levels
=
1370 data
->smc_state_table
.MemoryLevel
;
1373 for (i
= 0; i
< dpm_table
->mclk_table
.count
; i
++) {
1374 PP_ASSERT_WITH_CODE((0 != dpm_table
->mclk_table
.dpm_levels
[i
].value
),
1375 "can not populate memory level as memory clock is zero",
1377 result
= polaris10_populate_single_memory_level(hwmgr
,
1378 dpm_table
->mclk_table
.dpm_levels
[i
].value
,
1380 if (i
== dpm_table
->mclk_table
.count
- 1) {
1381 levels
[i
].DisplayWatermark
= PPSMC_DISPLAY_WATERMARK_HIGH
;
1382 levels
[i
].EnabledForActivity
= 1;
1388 /* in order to prevent MC activity from stutter mode to push DPM up.
1389 * the UVD change complements this by putting the MCLK in
1390 * a higher state by default such that we are not effected by
1391 * up threshold or and MCLK DPM latency.
1393 levels
[0].ActivityLevel
= (uint16_t)data
->mclk_dpm0_activity_target
;
1394 CONVERT_FROM_HOST_TO_SMC_US(levels
[0].ActivityLevel
);
1396 data
->smc_state_table
.MemoryDpmLevelCount
=
1397 (uint8_t)dpm_table
->mclk_table
.count
;
1398 data
->dpm_level_enable_mask
.mclk_dpm_enable_mask
=
1399 phm_get_dpm_level_enable_mask_value(&dpm_table
->mclk_table
);
1401 /* level count will send to smc once at init smc table and never change */
1402 result
= polaris10_copy_bytes_to_smc(hwmgr
->smumgr
, array
, (uint8_t *)levels
,
1403 (uint32_t)array_size
, data
->sram_end
);
1409 * Populates the SMC MVDD structure using the provided memory clock.
1411 * @param hwmgr the address of the hardware manager
1412 * @param mclk the MCLK value to be used in the decision if MVDD should be high or low.
1413 * @param voltage the SMC VOLTAGE structure to be populated
1415 int polaris10_populate_mvdd_value(struct pp_hwmgr
*hwmgr
,
1416 uint32_t mclk
, SMIO_Pattern
*smio_pat
)
1418 const struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
1419 struct phm_ppt_v1_information
*table_info
=
1420 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
1423 if (POLARIS10_VOLTAGE_CONTROL_NONE
!= data
->mvdd_control
) {
1424 /* find mvdd value which clock is more than request */
1425 for (i
= 0; i
< table_info
->vdd_dep_on_mclk
->count
; i
++) {
1426 if (mclk
<= table_info
->vdd_dep_on_mclk
->entries
[i
].clk
) {
1427 smio_pat
->Voltage
= data
->mvdd_voltage_table
.entries
[i
].value
;
1431 PP_ASSERT_WITH_CODE(i
< table_info
->vdd_dep_on_mclk
->count
,
1432 "MVDD Voltage is outside the supported range.",
1440 static int polaris10_populate_smc_acpi_level(struct pp_hwmgr
*hwmgr
,
1441 SMU74_Discrete_DpmTable
*table
)
1444 uint32_t sclk_frequency
;
1445 const struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
1446 struct phm_ppt_v1_information
*table_info
=
1447 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
1448 SMIO_Pattern vol_level
;
1452 table
->ACPILevel
.Flags
&= ~PPSMC_SWSTATE_FLAG_DC
;
1454 if (!data
->sclk_dpm_key_disabled
) {
1455 /* Get MinVoltage and Frequency from DPM0,
1456 * already converted to SMC_UL */
1457 sclk_frequency
= data
->dpm_table
.sclk_table
.dpm_levels
[0].value
;
1458 result
= polaris10_get_dependency_volt_by_clk(hwmgr
,
1459 table_info
->vdd_dep_on_sclk
,
1460 table
->ACPILevel
.SclkFrequency
,
1461 &table
->ACPILevel
.MinVoltage
, &mvdd
);
1462 PP_ASSERT_WITH_CODE((0 == result
),
1463 "Cannot find ACPI VDDC voltage value "
1464 "in Clock Dependency Table", );
1466 sclk_frequency
= data
->vbios_boot_state
.sclk_bootup_value
;
1467 table
->ACPILevel
.MinVoltage
=
1468 data
->vbios_boot_state
.vddc_bootup_value
* VOLTAGE_SCALE
;
1471 result
= polaris10_calculate_sclk_params(hwmgr
, sclk_frequency
, &(table
->ACPILevel
.SclkSetting
));
1472 PP_ASSERT_WITH_CODE(result
== 0, "Error retrieving Engine Clock dividers from VBIOS.", return result
);
1474 table
->ACPILevel
.DeepSleepDivId
= 0;
1475 table
->ACPILevel
.CcPwrDynRm
= 0;
1476 table
->ACPILevel
.CcPwrDynRm1
= 0;
1478 CONVERT_FROM_HOST_TO_SMC_UL(table
->ACPILevel
.Flags
);
1479 CONVERT_FROM_HOST_TO_SMC_UL(table
->ACPILevel
.MinVoltage
);
1480 CONVERT_FROM_HOST_TO_SMC_UL(table
->ACPILevel
.CcPwrDynRm
);
1481 CONVERT_FROM_HOST_TO_SMC_UL(table
->ACPILevel
.CcPwrDynRm1
);
1483 CONVERT_FROM_HOST_TO_SMC_UL(table
->ACPILevel
.SclkSetting
.SclkFrequency
);
1484 CONVERT_FROM_HOST_TO_SMC_US(table
->ACPILevel
.SclkSetting
.Fcw_int
);
1485 CONVERT_FROM_HOST_TO_SMC_US(table
->ACPILevel
.SclkSetting
.Fcw_frac
);
1486 CONVERT_FROM_HOST_TO_SMC_US(table
->ACPILevel
.SclkSetting
.Pcc_fcw_int
);
1487 CONVERT_FROM_HOST_TO_SMC_US(table
->ACPILevel
.SclkSetting
.Sclk_slew_rate
);
1488 CONVERT_FROM_HOST_TO_SMC_US(table
->ACPILevel
.SclkSetting
.Pcc_up_slew_rate
);
1489 CONVERT_FROM_HOST_TO_SMC_US(table
->ACPILevel
.SclkSetting
.Pcc_down_slew_rate
);
1490 CONVERT_FROM_HOST_TO_SMC_US(table
->ACPILevel
.SclkSetting
.Fcw1_int
);
1491 CONVERT_FROM_HOST_TO_SMC_US(table
->ACPILevel
.SclkSetting
.Fcw1_frac
);
1492 CONVERT_FROM_HOST_TO_SMC_US(table
->ACPILevel
.SclkSetting
.Sclk_ss_slew_rate
);
1494 if (!data
->mclk_dpm_key_disabled
) {
1495 /* Get MinVoltage and Frequency from DPM0, already converted to SMC_UL */
1496 table
->MemoryACPILevel
.MclkFrequency
=
1497 data
->dpm_table
.mclk_table
.dpm_levels
[0].value
;
1498 result
= polaris10_get_dependency_volt_by_clk(hwmgr
,
1499 table_info
->vdd_dep_on_mclk
,
1500 table
->MemoryACPILevel
.MclkFrequency
,
1501 &table
->MemoryACPILevel
.MinVoltage
, &mvdd
);
1502 PP_ASSERT_WITH_CODE((0 == result
),
1503 "Cannot find ACPI VDDCI voltage value "
1504 "in Clock Dependency Table",
1507 table
->MemoryACPILevel
.MclkFrequency
=
1508 data
->vbios_boot_state
.mclk_bootup_value
;
1509 table
->MemoryACPILevel
.MinVoltage
=
1510 data
->vbios_boot_state
.vddci_bootup_value
* VOLTAGE_SCALE
;
1514 if ((POLARIS10_VOLTAGE_CONTROL_NONE
== data
->mvdd_control
) ||
1515 (data
->mclk_dpm_key_disabled
))
1516 us_mvdd
= data
->vbios_boot_state
.mvdd_bootup_value
;
1518 if (!polaris10_populate_mvdd_value(hwmgr
,
1519 data
->dpm_table
.mclk_table
.dpm_levels
[0].value
,
1521 us_mvdd
= vol_level
.Voltage
;
1524 if (0 == polaris10_populate_mvdd_value(hwmgr
, 0, &vol_level
))
1525 table
->MemoryACPILevel
.MinMvdd
= PP_HOST_TO_SMC_UL(vol_level
.Voltage
);
1527 table
->MemoryACPILevel
.MinMvdd
= 0;
1529 table
->MemoryACPILevel
.StutterEnable
= false;
1531 table
->MemoryACPILevel
.EnabledForThrottle
= 0;
1532 table
->MemoryACPILevel
.EnabledForActivity
= 0;
1533 table
->MemoryACPILevel
.UpHyst
= 0;
1534 table
->MemoryACPILevel
.DownHyst
= 100;
1535 table
->MemoryACPILevel
.VoltageDownHyst
= 0;
1536 table
->MemoryACPILevel
.ActivityLevel
=
1537 PP_HOST_TO_SMC_US((uint16_t)data
->mclk_activity_target
);
1539 CONVERT_FROM_HOST_TO_SMC_UL(table
->MemoryACPILevel
.MclkFrequency
);
1540 CONVERT_FROM_HOST_TO_SMC_UL(table
->MemoryACPILevel
.MinVoltage
);
1545 static int polaris10_populate_smc_vce_level(struct pp_hwmgr
*hwmgr
,
1546 SMU74_Discrete_DpmTable
*table
)
1548 int result
= -EINVAL
;
1550 struct pp_atomctrl_clock_dividers_vi dividers
;
1551 struct phm_ppt_v1_information
*table_info
=
1552 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
1553 struct phm_ppt_v1_mm_clock_voltage_dependency_table
*mm_table
=
1554 table_info
->mm_dep_table
;
1555 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
1557 table
->VceLevelCount
= (uint8_t)(mm_table
->count
);
1558 table
->VceBootLevel
= 0;
1560 for (count
= 0; count
< table
->VceLevelCount
; count
++) {
1561 table
->VceLevel
[count
].Frequency
= mm_table
->entries
[count
].eclk
;
1562 table
->VceLevel
[count
].MinVoltage
|=
1563 (mm_table
->entries
[count
].vddc
* VOLTAGE_SCALE
) << VDDC_SHIFT
;
1564 table
->VceLevel
[count
].MinVoltage
|=
1565 ((mm_table
->entries
[count
].vddc
- data
->vddc_vddci_delta
) *
1566 VOLTAGE_SCALE
) << VDDCI_SHIFT
;
1567 table
->VceLevel
[count
].MinVoltage
|= 1 << PHASES_SHIFT
;
1569 /*retrieve divider value for VBIOS */
1570 result
= atomctrl_get_dfs_pll_dividers_vi(hwmgr
,
1571 table
->VceLevel
[count
].Frequency
, ÷rs
);
1572 PP_ASSERT_WITH_CODE((0 == result
),
1573 "can not find divide id for VCE engine clock",
1576 table
->VceLevel
[count
].Divider
= (uint8_t)dividers
.pll_post_divider
;
1578 CONVERT_FROM_HOST_TO_SMC_UL(table
->VceLevel
[count
].Frequency
);
1579 CONVERT_FROM_HOST_TO_SMC_UL(table
->VceLevel
[count
].MinVoltage
);
1584 static int polaris10_populate_smc_samu_level(struct pp_hwmgr
*hwmgr
,
1585 SMU74_Discrete_DpmTable
*table
)
1587 int result
= -EINVAL
;
1589 struct pp_atomctrl_clock_dividers_vi dividers
;
1590 struct phm_ppt_v1_information
*table_info
=
1591 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
1592 struct phm_ppt_v1_mm_clock_voltage_dependency_table
*mm_table
=
1593 table_info
->mm_dep_table
;
1594 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
1596 table
->SamuBootLevel
= 0;
1597 table
->SamuLevelCount
= (uint8_t)(mm_table
->count
);
1599 for (count
= 0; count
< table
->SamuLevelCount
; count
++) {
1600 /* not sure whether we need evclk or not */
1601 table
->SamuLevel
[count
].Frequency
= mm_table
->entries
[count
].samclock
;
1602 table
->SamuLevel
[count
].MinVoltage
|= (mm_table
->entries
[count
].vddc
*
1603 VOLTAGE_SCALE
) << VDDC_SHIFT
;
1604 table
->SamuLevel
[count
].MinVoltage
|= ((mm_table
->entries
[count
].vddc
-
1605 data
->vddc_vddci_delta
) * VOLTAGE_SCALE
) << VDDCI_SHIFT
;
1606 table
->SamuLevel
[count
].MinVoltage
|= 1 << PHASES_SHIFT
;
1608 /* retrieve divider value for VBIOS */
1609 result
= atomctrl_get_dfs_pll_dividers_vi(hwmgr
,
1610 table
->SamuLevel
[count
].Frequency
, ÷rs
);
1611 PP_ASSERT_WITH_CODE((0 == result
),
1612 "can not find divide id for samu clock", return result
);
1614 table
->SamuLevel
[count
].Divider
= (uint8_t)dividers
.pll_post_divider
;
1616 CONVERT_FROM_HOST_TO_SMC_UL(table
->SamuLevel
[count
].Frequency
);
1617 CONVERT_FROM_HOST_TO_SMC_UL(table
->SamuLevel
[count
].MinVoltage
);
1622 static int polaris10_populate_memory_timing_parameters(struct pp_hwmgr
*hwmgr
,
1623 int32_t eng_clock
, int32_t mem_clock
,
1624 SMU74_Discrete_MCArbDramTimingTableEntry
*arb_regs
)
1626 uint32_t dram_timing
;
1627 uint32_t dram_timing2
;
1628 uint32_t burst_time
;
1631 result
= atomctrl_set_engine_dram_timings_rv770(hwmgr
,
1632 eng_clock
, mem_clock
);
1633 PP_ASSERT_WITH_CODE(result
== 0,
1634 "Error calling VBIOS to set DRAM_TIMING.", return result
);
1636 dram_timing
= cgs_read_register(hwmgr
->device
, mmMC_ARB_DRAM_TIMING
);
1637 dram_timing2
= cgs_read_register(hwmgr
->device
, mmMC_ARB_DRAM_TIMING2
);
1638 burst_time
= PHM_READ_FIELD(hwmgr
->device
, MC_ARB_BURST_TIME
, STATE0
);
1641 arb_regs
->McArbDramTiming
= PP_HOST_TO_SMC_UL(dram_timing
);
1642 arb_regs
->McArbDramTiming2
= PP_HOST_TO_SMC_UL(dram_timing2
);
1643 arb_regs
->McArbBurstTime
= (uint8_t)burst_time
;
1648 static int polaris10_program_memory_timing_parameters(struct pp_hwmgr
*hwmgr
)
1650 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
1651 struct SMU74_Discrete_MCArbDramTimingTable arb_regs
;
1655 for (i
= 0; i
< data
->dpm_table
.sclk_table
.count
; i
++) {
1656 for (j
= 0; j
< data
->dpm_table
.mclk_table
.count
; j
++) {
1657 result
= polaris10_populate_memory_timing_parameters(hwmgr
,
1658 data
->dpm_table
.sclk_table
.dpm_levels
[i
].value
,
1659 data
->dpm_table
.mclk_table
.dpm_levels
[j
].value
,
1660 &arb_regs
.entries
[i
][j
]);
1662 result
= atomctrl_set_ac_timing_ai(hwmgr
, data
->dpm_table
.mclk_table
.dpm_levels
[j
].value
, j
);
1668 result
= polaris10_copy_bytes_to_smc(
1670 data
->arb_table_start
,
1671 (uint8_t *)&arb_regs
,
1672 sizeof(SMU74_Discrete_MCArbDramTimingTable
),
1677 static int polaris10_populate_smc_uvd_level(struct pp_hwmgr
*hwmgr
,
1678 struct SMU74_Discrete_DpmTable
*table
)
1680 int result
= -EINVAL
;
1682 struct pp_atomctrl_clock_dividers_vi dividers
;
1683 struct phm_ppt_v1_information
*table_info
=
1684 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
1685 struct phm_ppt_v1_mm_clock_voltage_dependency_table
*mm_table
=
1686 table_info
->mm_dep_table
;
1687 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
1689 table
->UvdLevelCount
= (uint8_t)(mm_table
->count
);
1690 table
->UvdBootLevel
= 0;
1692 for (count
= 0; count
< table
->UvdLevelCount
; count
++) {
1693 table
->UvdLevel
[count
].VclkFrequency
= mm_table
->entries
[count
].vclk
;
1694 table
->UvdLevel
[count
].DclkFrequency
= mm_table
->entries
[count
].dclk
;
1695 table
->UvdLevel
[count
].MinVoltage
|= (mm_table
->entries
[count
].vddc
*
1696 VOLTAGE_SCALE
) << VDDC_SHIFT
;
1697 table
->UvdLevel
[count
].MinVoltage
|= ((mm_table
->entries
[count
].vddc
-
1698 data
->vddc_vddci_delta
) * VOLTAGE_SCALE
) << VDDCI_SHIFT
;
1699 table
->UvdLevel
[count
].MinVoltage
|= 1 << PHASES_SHIFT
;
1701 /* retrieve divider value for VBIOS */
1702 result
= atomctrl_get_dfs_pll_dividers_vi(hwmgr
,
1703 table
->UvdLevel
[count
].VclkFrequency
, ÷rs
);
1704 PP_ASSERT_WITH_CODE((0 == result
),
1705 "can not find divide id for Vclk clock", return result
);
1707 table
->UvdLevel
[count
].VclkDivider
= (uint8_t)dividers
.pll_post_divider
;
1709 result
= atomctrl_get_dfs_pll_dividers_vi(hwmgr
,
1710 table
->UvdLevel
[count
].DclkFrequency
, ÷rs
);
1711 PP_ASSERT_WITH_CODE((0 == result
),
1712 "can not find divide id for Dclk clock", return result
);
1714 table
->UvdLevel
[count
].DclkDivider
= (uint8_t)dividers
.pll_post_divider
;
1716 CONVERT_FROM_HOST_TO_SMC_UL(table
->UvdLevel
[count
].VclkFrequency
);
1717 CONVERT_FROM_HOST_TO_SMC_UL(table
->UvdLevel
[count
].DclkFrequency
);
1718 CONVERT_FROM_HOST_TO_SMC_UL(table
->UvdLevel
[count
].MinVoltage
);
1724 static int polaris10_populate_smc_boot_level(struct pp_hwmgr
*hwmgr
,
1725 struct SMU74_Discrete_DpmTable
*table
)
1728 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
1730 table
->GraphicsBootLevel
= 0;
1731 table
->MemoryBootLevel
= 0;
1733 /* find boot level from dpm table */
1734 result
= phm_find_boot_level(&(data
->dpm_table
.sclk_table
),
1735 data
->vbios_boot_state
.sclk_bootup_value
,
1736 (uint32_t *)&(table
->GraphicsBootLevel
));
1738 result
= phm_find_boot_level(&(data
->dpm_table
.mclk_table
),
1739 data
->vbios_boot_state
.mclk_bootup_value
,
1740 (uint32_t *)&(table
->MemoryBootLevel
));
1742 table
->BootVddc
= data
->vbios_boot_state
.vddc_bootup_value
*
1744 table
->BootVddci
= data
->vbios_boot_state
.vddci_bootup_value
*
1746 table
->BootMVdd
= data
->vbios_boot_state
.mvdd_bootup_value
*
1749 CONVERT_FROM_HOST_TO_SMC_US(table
->BootVddc
);
1750 CONVERT_FROM_HOST_TO_SMC_US(table
->BootVddci
);
1751 CONVERT_FROM_HOST_TO_SMC_US(table
->BootMVdd
);
1757 static int polaris10_populate_smc_initailial_state(struct pp_hwmgr
*hwmgr
)
1759 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
1760 struct phm_ppt_v1_information
*table_info
=
1761 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
1762 uint8_t count
, level
;
1764 count
= (uint8_t)(table_info
->vdd_dep_on_sclk
->count
);
1766 for (level
= 0; level
< count
; level
++) {
1767 if (table_info
->vdd_dep_on_sclk
->entries
[level
].clk
>=
1768 data
->vbios_boot_state
.sclk_bootup_value
) {
1769 data
->smc_state_table
.GraphicsBootLevel
= level
;
1774 count
= (uint8_t)(table_info
->vdd_dep_on_mclk
->count
);
1775 for (level
= 0; level
< count
; level
++) {
1776 if (table_info
->vdd_dep_on_mclk
->entries
[level
].clk
>=
1777 data
->vbios_boot_state
.mclk_bootup_value
) {
1778 data
->smc_state_table
.MemoryBootLevel
= level
;
1786 static int polaris10_populate_clock_stretcher_data_table(struct pp_hwmgr
*hwmgr
)
1788 uint32_t ro
, efuse
, efuse2
, clock_freq
, volt_without_cks
,
1789 volt_with_cks
, value
;
1790 uint16_t clock_freq_u16
;
1791 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
1792 uint8_t type
, i
, j
, cks_setting
, stretch_amount
, stretch_amount2
,
1794 struct phm_ppt_v1_information
*table_info
=
1795 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
1796 struct phm_ppt_v1_clock_voltage_dependency_table
*sclk_table
=
1797 table_info
->vdd_dep_on_sclk
;
1799 stretch_amount
= (uint8_t)table_info
->cac_dtp_table
->usClockStretchAmount
;
1801 /* Read SMU_Eefuse to read and calculate RO and determine
1802 * if the part is SS or FF. if RO >= 1660MHz, part is FF.
1804 efuse
= cgs_read_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
,
1805 ixSMU_EFUSE_0
+ (146 * 4));
1806 efuse2
= cgs_read_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
,
1807 ixSMU_EFUSE_0
+ (148 * 4));
1808 efuse
&= 0xFF000000;
1809 efuse
= efuse
>> 24;
1813 ro
= (2300 - 1350) * efuse
/ 255 + 1350;
1815 ro
= (2500 - 1000) * efuse
/ 255 + 1000;
1822 /* Populate Stretch amount */
1823 data
->smc_state_table
.ClockStretcherAmount
= stretch_amount
;
1825 /* Populate Sclk_CKS_masterEn0_7 and Sclk_voltageOffset */
1826 for (i
= 0; i
< sclk_table
->count
; i
++) {
1827 data
->smc_state_table
.Sclk_CKS_masterEn0_7
|=
1828 sclk_table
->entries
[i
].cks_enable
<< i
;
1829 volt_without_cks
= (uint32_t)((14041 *
1830 (sclk_table
->entries
[i
].clk
/100) / 10000 + 3571 + 75 - ro
) * 1000 /
1831 (4026 - (13924 * (sclk_table
->entries
[i
].clk
/100) / 10000)));
1832 volt_with_cks
= (uint32_t)((13946 *
1833 (sclk_table
->entries
[i
].clk
/100) / 10000 + 3320 + 45 - ro
) * 1000 /
1834 (3664 - (11454 * (sclk_table
->entries
[i
].clk
/100) / 10000)));
1835 if (volt_without_cks
>= volt_with_cks
)
1836 volt_offset
= (uint8_t)(((volt_without_cks
- volt_with_cks
+
1837 sclk_table
->entries
[i
].cks_voffset
) * 100 / 625) + 1);
1838 data
->smc_state_table
.Sclk_voltageOffset
[i
] = volt_offset
;
1841 PHM_WRITE_INDIRECT_FIELD(hwmgr
->device
, CGS_IND_REG__SMC
, PWR_CKS_ENABLE
,
1842 STRETCH_ENABLE
, 0x0);
1843 PHM_WRITE_INDIRECT_FIELD(hwmgr
->device
, CGS_IND_REG__SMC
, PWR_CKS_ENABLE
,
1845 /* PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE, staticEnable, 0x1); */
1846 PHM_WRITE_INDIRECT_FIELD(hwmgr
->device
, CGS_IND_REG__SMC
, PWR_CKS_ENABLE
,
1849 /* Populate CKS Lookup Table */
1850 if (stretch_amount
== 1 || stretch_amount
== 2 || stretch_amount
== 5)
1851 stretch_amount2
= 0;
1852 else if (stretch_amount
== 3 || stretch_amount
== 4)
1853 stretch_amount2
= 1;
1855 phm_cap_unset(hwmgr
->platform_descriptor
.platformCaps
,
1856 PHM_PlatformCaps_ClockStretcher
);
1857 PP_ASSERT_WITH_CODE(false,
1858 "Stretch Amount in PPTable not supported\n",
1862 value
= cgs_read_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
,
1864 value
&= 0xFFC2FF87;
1865 data
->smc_state_table
.CKS_LOOKUPTable
.CKS_LOOKUPTableEntry
[0].minFreq
=
1866 polaris10_clock_stretcher_lookup_table
[stretch_amount2
][0];
1867 data
->smc_state_table
.CKS_LOOKUPTable
.CKS_LOOKUPTableEntry
[0].maxFreq
=
1868 polaris10_clock_stretcher_lookup_table
[stretch_amount2
][1];
1869 clock_freq_u16
= (uint16_t)(PP_SMC_TO_HOST_UL(data
->smc_state_table
.
1870 GraphicsLevel
[data
->smc_state_table
.GraphicsDpmLevelCount
- 1].SclkSetting
.SclkFrequency
) / 100);
1871 if (polaris10_clock_stretcher_lookup_table
[stretch_amount2
][0] < clock_freq_u16
1872 && polaris10_clock_stretcher_lookup_table
[stretch_amount2
][1] > clock_freq_u16
) {
1873 /* Program PWR_CKS_CNTL. CKS_USE_FOR_LOW_FREQ */
1874 value
|= (polaris10_clock_stretcher_lookup_table
[stretch_amount2
][3]) << 16;
1875 /* Program PWR_CKS_CNTL. CKS_LDO_REFSEL */
1876 value
|= (polaris10_clock_stretcher_lookup_table
[stretch_amount2
][2]) << 18;
1877 /* Program PWR_CKS_CNTL. CKS_STRETCH_AMOUNT */
1878 value
|= (polaris10_clock_stretch_amount_conversion
1879 [polaris10_clock_stretcher_lookup_table
[stretch_amount2
][3]]
1880 [stretch_amount
]) << 3;
1882 CONVERT_FROM_HOST_TO_SMC_US(data
->smc_state_table
.CKS_LOOKUPTable
.CKS_LOOKUPTableEntry
[0].minFreq
);
1883 CONVERT_FROM_HOST_TO_SMC_US(data
->smc_state_table
.CKS_LOOKUPTable
.CKS_LOOKUPTableEntry
[0].maxFreq
);
1884 data
->smc_state_table
.CKS_LOOKUPTable
.CKS_LOOKUPTableEntry
[0].setting
=
1885 polaris10_clock_stretcher_lookup_table
[stretch_amount2
][2] & 0x7F;
1886 data
->smc_state_table
.CKS_LOOKUPTable
.CKS_LOOKUPTableEntry
[0].setting
|=
1887 (polaris10_clock_stretcher_lookup_table
[stretch_amount2
][3]) << 7;
1889 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
,
1890 ixPWR_CKS_CNTL
, value
);
1892 /* Populate DDT Lookup Table */
1893 for (i
= 0; i
< 4; i
++) {
1894 /* Assign the minimum and maximum VID stored
1895 * in the last row of Clock Stretcher Voltage Table.
1897 data
->smc_state_table
.ClockStretcherDataTable
.ClockStretcherDataTableEntry
[i
].minVID
=
1898 (uint8_t) polaris10_clock_stretcher_ddt_table
[type
][i
][2];
1899 data
->smc_state_table
.ClockStretcherDataTable
.ClockStretcherDataTableEntry
[i
].maxVID
=
1900 (uint8_t) polaris10_clock_stretcher_ddt_table
[type
][i
][3];
1901 /* Loop through each SCLK and check the frequency
1902 * to see if it lies within the frequency for clock stretcher.
1904 for (j
= 0; j
< data
->smc_state_table
.GraphicsDpmLevelCount
; j
++) {
1906 clock_freq
= PP_SMC_TO_HOST_UL(
1907 data
->smc_state_table
.GraphicsLevel
[j
].SclkSetting
.SclkFrequency
);
1908 /* Check the allowed frequency against the sclk level[j].
1909 * Sclk's endianness has already been converted,
1910 * and it's in 10Khz unit,
1911 * as opposed to Data table, which is in Mhz unit.
1913 if (clock_freq
>= (polaris10_clock_stretcher_ddt_table
[type
][i
][0]) * 100) {
1915 if (clock_freq
< (polaris10_clock_stretcher_ddt_table
[type
][i
][1]) * 100)
1918 data
->smc_state_table
.ClockStretcherDataTable
.ClockStretcherDataTableEntry
[i
].setting
1919 |= cks_setting
<< (j
* 2);
1921 CONVERT_FROM_HOST_TO_SMC_US(
1922 data
->smc_state_table
.ClockStretcherDataTable
.ClockStretcherDataTableEntry
[i
].setting
);
1925 value
= cgs_read_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
, ixPWR_CKS_CNTL
);
1926 value
&= 0xFFFFFFFE;
1927 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
, ixPWR_CKS_CNTL
, value
);
1933 * Populates the SMC VRConfig field in DPM table.
1935 * @param hwmgr the address of the hardware manager
1936 * @param table the SMC DPM table structure to be populated
1939 static int polaris10_populate_vr_config(struct pp_hwmgr
*hwmgr
,
1940 struct SMU74_Discrete_DpmTable
*table
)
1942 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
1945 config
= VR_MERGED_WITH_VDDC
;
1946 table
->VRConfig
|= (config
<< VRCONF_VDDGFX_SHIFT
);
1948 /* Set Vddc Voltage Controller */
1949 if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2
== data
->voltage_control
) {
1950 config
= VR_SVI2_PLANE_1
;
1951 table
->VRConfig
|= config
;
1953 PP_ASSERT_WITH_CODE(false,
1954 "VDDC should be on SVI2 control in merged mode!",
1957 /* Set Vddci Voltage Controller */
1958 if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2
== data
->vddci_control
) {
1959 config
= VR_SVI2_PLANE_2
; /* only in merged mode */
1960 table
->VRConfig
|= (config
<< VRCONF_VDDCI_SHIFT
);
1961 } else if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO
== data
->vddci_control
) {
1962 config
= VR_SMIO_PATTERN_1
;
1963 table
->VRConfig
|= (config
<< VRCONF_VDDCI_SHIFT
);
1965 config
= VR_STATIC_VOLTAGE
;
1966 table
->VRConfig
|= (config
<< VRCONF_VDDCI_SHIFT
);
1968 /* Set Mvdd Voltage Controller */
1969 if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2
== data
->mvdd_control
) {
1970 config
= VR_SVI2_PLANE_2
;
1971 table
->VRConfig
|= (config
<< VRCONF_MVDD_SHIFT
);
1972 } else if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO
== data
->mvdd_control
) {
1973 config
= VR_SMIO_PATTERN_2
;
1974 table
->VRConfig
|= (config
<< VRCONF_MVDD_SHIFT
);
1976 config
= VR_STATIC_VOLTAGE
;
1977 table
->VRConfig
|= (config
<< VRCONF_MVDD_SHIFT
);
1984 * Initializes the SMC table and uploads it
1986 * @param hwmgr the address of the powerplay hardware manager.
1989 static int polaris10_init_smc_table(struct pp_hwmgr
*hwmgr
)
1992 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
1993 struct phm_ppt_v1_information
*table_info
=
1994 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
1995 struct SMU74_Discrete_DpmTable
*table
= &(data
->smc_state_table
);
1996 const struct polaris10_ulv_parm
*ulv
= &(data
->ulv
);
1998 struct pp_atomctrl_gpio_pin_assignment gpio_pin
;
1999 pp_atomctrl_clock_dividers_vi dividers
;
2001 result
= polaris10_setup_default_dpm_tables(hwmgr
);
2002 PP_ASSERT_WITH_CODE(0 == result
,
2003 "Failed to setup default DPM tables!", return result
);
2005 if (POLARIS10_VOLTAGE_CONTROL_NONE
!= data
->voltage_control
)
2006 polaris10_populate_smc_voltage_tables(hwmgr
, table
);
2008 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
,
2009 PHM_PlatformCaps_AutomaticDCTransition
))
2010 table
->SystemFlags
|= PPSMC_SYSTEMFLAG_GPIO_DC
;
2012 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
,
2013 PHM_PlatformCaps_StepVddc
))
2014 table
->SystemFlags
|= PPSMC_SYSTEMFLAG_STEPVDDC
;
2016 if (data
->is_memory_gddr5
)
2017 table
->SystemFlags
|= PPSMC_SYSTEMFLAG_GDDR5
;
2019 if (ulv
->ulv_supported
&& table_info
->us_ulv_voltage_offset
) {
2020 result
= polaris10_populate_ulv_state(hwmgr
, table
);
2021 PP_ASSERT_WITH_CODE(0 == result
,
2022 "Failed to initialize ULV state!", return result
);
2023 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
,
2024 ixCG_ULV_PARAMETER
, PPPOLARIS10_CGULVPARAMETER_DFLT
);
2027 result
= polaris10_populate_smc_link_level(hwmgr
, table
);
2028 PP_ASSERT_WITH_CODE(0 == result
,
2029 "Failed to initialize Link Level!", return result
);
2031 result
= polaris10_populate_all_graphic_levels(hwmgr
);
2032 PP_ASSERT_WITH_CODE(0 == result
,
2033 "Failed to initialize Graphics Level!", return result
);
2035 result
= polaris10_populate_all_memory_levels(hwmgr
);
2036 PP_ASSERT_WITH_CODE(0 == result
,
2037 "Failed to initialize Memory Level!", return result
);
2039 result
= polaris10_populate_smc_acpi_level(hwmgr
, table
);
2040 PP_ASSERT_WITH_CODE(0 == result
,
2041 "Failed to initialize ACPI Level!", return result
);
2043 result
= polaris10_populate_smc_vce_level(hwmgr
, table
);
2044 PP_ASSERT_WITH_CODE(0 == result
,
2045 "Failed to initialize VCE Level!", return result
);
2047 result
= polaris10_populate_smc_samu_level(hwmgr
, table
);
2048 PP_ASSERT_WITH_CODE(0 == result
,
2049 "Failed to initialize SAMU Level!", return result
);
2051 /* Since only the initial state is completely set up at this point
2052 * (the other states are just copies of the boot state) we only
2053 * need to populate the ARB settings for the initial state.
2055 result
= polaris10_program_memory_timing_parameters(hwmgr
);
2056 PP_ASSERT_WITH_CODE(0 == result
,
2057 "Failed to Write ARB settings for the initial state.", return result
);
2059 result
= polaris10_populate_smc_uvd_level(hwmgr
, table
);
2060 PP_ASSERT_WITH_CODE(0 == result
,
2061 "Failed to initialize UVD Level!", return result
);
2063 result
= polaris10_populate_smc_boot_level(hwmgr
, table
);
2064 PP_ASSERT_WITH_CODE(0 == result
,
2065 "Failed to initialize Boot Level!", return result
);
2067 result
= polaris10_populate_smc_initailial_state(hwmgr
);
2068 PP_ASSERT_WITH_CODE(0 == result
,
2069 "Failed to initialize Boot State!", return result
);
2071 result
= polaris10_populate_bapm_parameters_in_dpm_table(hwmgr
);
2072 PP_ASSERT_WITH_CODE(0 == result
,
2073 "Failed to populate BAPM Parameters!", return result
);
2075 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
,
2076 PHM_PlatformCaps_ClockStretcher
)) {
2077 result
= polaris10_populate_clock_stretcher_data_table(hwmgr
);
2078 PP_ASSERT_WITH_CODE(0 == result
,
2079 "Failed to populate Clock Stretcher Data Table!",
2083 table
->GraphicsVoltageChangeEnable
= 1;
2084 table
->GraphicsThermThrottleEnable
= 1;
2085 table
->GraphicsInterval
= 1;
2086 table
->VoltageInterval
= 1;
2087 table
->ThermalInterval
= 1;
2088 table
->TemperatureLimitHigh
=
2089 table_info
->cac_dtp_table
->usTargetOperatingTemp
*
2090 POLARIS10_Q88_FORMAT_CONVERSION_UNIT
;
2091 table
->TemperatureLimitLow
=
2092 (table_info
->cac_dtp_table
->usTargetOperatingTemp
- 1) *
2093 POLARIS10_Q88_FORMAT_CONVERSION_UNIT
;
2094 table
->MemoryVoltageChangeEnable
= 1;
2095 table
->MemoryInterval
= 1;
2096 table
->VoltageResponseTime
= 0;
2097 table
->PhaseResponseTime
= 0;
2098 table
->MemoryThermThrottleEnable
= 1;
2099 table
->PCIeBootLinkLevel
= 0;
2100 table
->PCIeGenInterval
= 1;
2102 result
= polaris10_populate_vr_config(hwmgr
, table
);
2103 PP_ASSERT_WITH_CODE(0 == result
,
2104 "Failed to populate VRConfig setting!", return result
);
2106 table
->ThermGpio
= 17;
2107 table
->SclkStepSize
= 0x4000;
2109 if (atomctrl_get_pp_assign_pin(hwmgr
, VDDC_VRHOT_GPIO_PINID
, &gpio_pin
)) {
2110 table
->VRHotGpio
= gpio_pin
.uc_gpio_pin_bit_shift
;
2112 table
->VRHotGpio
= POLARIS10_UNUSED_GPIO_PIN
;
2113 phm_cap_unset(hwmgr
->platform_descriptor
.platformCaps
,
2114 PHM_PlatformCaps_RegulatorHot
);
2117 if (atomctrl_get_pp_assign_pin(hwmgr
, PP_AC_DC_SWITCH_GPIO_PINID
,
2119 table
->AcDcGpio
= gpio_pin
.uc_gpio_pin_bit_shift
;
2120 phm_cap_set(hwmgr
->platform_descriptor
.platformCaps
,
2121 PHM_PlatformCaps_AutomaticDCTransition
);
2123 table
->AcDcGpio
= POLARIS10_UNUSED_GPIO_PIN
;
2124 phm_cap_unset(hwmgr
->platform_descriptor
.platformCaps
,
2125 PHM_PlatformCaps_AutomaticDCTransition
);
2128 /* Thermal Output GPIO */
2129 if (atomctrl_get_pp_assign_pin(hwmgr
, THERMAL_INT_OUTPUT_GPIO_PINID
,
2131 phm_cap_set(hwmgr
->platform_descriptor
.platformCaps
,
2132 PHM_PlatformCaps_ThermalOutGPIO
);
2134 table
->ThermOutGpio
= gpio_pin
.uc_gpio_pin_bit_shift
;
2136 /* For porlarity read GPIOPAD_A with assigned Gpio pin
2137 * since VBIOS will program this register to set 'inactive state',
2138 * driver can then determine 'active state' from this and
2139 * program SMU with correct polarity
2141 table
->ThermOutPolarity
= (0 == (cgs_read_register(hwmgr
->device
, mmGPIOPAD_A
)
2142 & (1 << gpio_pin
.uc_gpio_pin_bit_shift
))) ? 1:0;
2143 table
->ThermOutMode
= SMU7_THERM_OUT_MODE_THERM_ONLY
;
2145 /* if required, combine VRHot/PCC with thermal out GPIO */
2146 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
, PHM_PlatformCaps_RegulatorHot
)
2147 && phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
, PHM_PlatformCaps_CombinePCCWithThermalSignal
))
2148 table
->ThermOutMode
= SMU7_THERM_OUT_MODE_THERM_VRHOT
;
2150 table
->ThermOutGpio
= 17;
2151 table
->ThermOutPolarity
= 1;
2152 table
->ThermOutMode
= SMU7_THERM_OUT_MODE_DISABLE
;
2155 /* Populate BIF_SCLK levels into SMC DPM table */
2156 for (i
= 0; i
<= data
->dpm_table
.pcie_speed_table
.count
; i
++) {
2157 result
= atomctrl_get_dfs_pll_dividers_vi(hwmgr
, data
->bif_sclk_table
[i
], ÷rs
);
2158 PP_ASSERT_WITH_CODE((result
== 0), "Can not find DFS divide id for Sclk", return result
);
2161 table
->Ulv
.BifSclkDfs
= PP_HOST_TO_SMC_US((USHORT
)(dividers
.pll_post_divider
));
2163 table
->LinkLevel
[i
-1].BifSclkDfs
= PP_HOST_TO_SMC_US((USHORT
)(dividers
.pll_post_divider
));
2166 for (i
= 0; i
< SMU74_MAX_ENTRIES_SMIO
; i
++)
2167 table
->Smio
[i
] = PP_HOST_TO_SMC_UL(table
->Smio
[i
]);
2169 CONVERT_FROM_HOST_TO_SMC_UL(table
->SystemFlags
);
2170 CONVERT_FROM_HOST_TO_SMC_UL(table
->VRConfig
);
2171 CONVERT_FROM_HOST_TO_SMC_UL(table
->SmioMask1
);
2172 CONVERT_FROM_HOST_TO_SMC_UL(table
->SmioMask2
);
2173 CONVERT_FROM_HOST_TO_SMC_UL(table
->SclkStepSize
);
2174 CONVERT_FROM_HOST_TO_SMC_US(table
->TemperatureLimitHigh
);
2175 CONVERT_FROM_HOST_TO_SMC_US(table
->TemperatureLimitLow
);
2176 CONVERT_FROM_HOST_TO_SMC_US(table
->VoltageResponseTime
);
2177 CONVERT_FROM_HOST_TO_SMC_US(table
->PhaseResponseTime
);
2179 /* Upload all dpm data to SMC memory.(dpm level, dpm level count etc) */
2180 result
= polaris10_copy_bytes_to_smc(hwmgr
->smumgr
,
2181 data
->dpm_table_start
+
2182 offsetof(SMU74_Discrete_DpmTable
, SystemFlags
),
2183 (uint8_t *)&(table
->SystemFlags
),
2184 sizeof(SMU74_Discrete_DpmTable
) - 3 * sizeof(SMU74_PIDController
),
2186 PP_ASSERT_WITH_CODE(0 == result
,
2187 "Failed to upload dpm data to SMC memory!", return result
);
2193 * Initialize the ARB DRAM timing table's index field.
2195 * @param hwmgr the address of the powerplay hardware manager.
2198 static int polaris10_init_arb_table_index(struct pp_hwmgr
*hwmgr
)
2200 const struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
2204 /* This is a read-modify-write on the first byte of the ARB table.
2205 * The first byte in the SMU73_Discrete_MCArbDramTimingTable structure
2206 * is the field 'current'.
2207 * This solution is ugly, but we never write the whole table only
2208 * individual fields in it.
2209 * In reality this field should not be in that structure
2210 * but in a soft register.
2212 result
= polaris10_read_smc_sram_dword(hwmgr
->smumgr
,
2213 data
->arb_table_start
, &tmp
, data
->sram_end
);
2219 tmp
|= ((uint32_t)MC_CG_ARB_FREQ_F1
) << 24;
2221 return polaris10_write_smc_sram_dword(hwmgr
->smumgr
,
2222 data
->arb_table_start
, tmp
, data
->sram_end
);
2225 static int polaris10_enable_vrhot_gpio_interrupt(struct pp_hwmgr
*hwmgr
)
2227 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
,
2228 PHM_PlatformCaps_RegulatorHot
))
2229 return smum_send_msg_to_smc(hwmgr
->smumgr
,
2230 PPSMC_MSG_EnableVRHotGPIOInterrupt
);
2235 static int polaris10_enable_sclk_control(struct pp_hwmgr
*hwmgr
)
2237 PHM_WRITE_INDIRECT_FIELD(hwmgr
->device
, CGS_IND_REG__SMC
, SCLK_PWRMGT_CNTL
,
2238 SCLK_PWRMGT_OFF
, 0);
2242 static int polaris10_enable_ulv(struct pp_hwmgr
*hwmgr
)
2244 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
2245 struct polaris10_ulv_parm
*ulv
= &(data
->ulv
);
2247 if (ulv
->ulv_supported
)
2248 return smum_send_msg_to_smc(hwmgr
->smumgr
, PPSMC_MSG_EnableULV
);
2253 static int polaris10_enable_deep_sleep_master_switch(struct pp_hwmgr
*hwmgr
)
2255 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
,
2256 PHM_PlatformCaps_SclkDeepSleep
)) {
2257 if (smum_send_msg_to_smc(hwmgr
->smumgr
, PPSMC_MSG_MASTER_DeepSleep_ON
))
2258 PP_ASSERT_WITH_CODE(false,
2259 "Attempt to enable Master Deep Sleep switch failed!",
2262 if (smum_send_msg_to_smc(hwmgr
->smumgr
,
2263 PPSMC_MSG_MASTER_DeepSleep_OFF
)) {
2264 PP_ASSERT_WITH_CODE(false,
2265 "Attempt to disable Master Deep Sleep switch failed!",
2273 static int polaris10_enable_sclk_mclk_dpm(struct pp_hwmgr
*hwmgr
)
2275 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
2277 /* enable SCLK dpm */
2278 if (!data
->sclk_dpm_key_disabled
)
2279 PP_ASSERT_WITH_CODE(
2280 (0 == smum_send_msg_to_smc(hwmgr
->smumgr
, PPSMC_MSG_DPM_Enable
)),
2281 "Failed to enable SCLK DPM during DPM Start Function!",
2284 /* enable MCLK dpm */
2285 if (0 == data
->mclk_dpm_key_disabled
) {
2287 PP_ASSERT_WITH_CODE(
2288 (0 == smum_send_msg_to_smc(hwmgr
->smumgr
,
2289 PPSMC_MSG_MCLKDPM_Enable
)),
2290 "Failed to enable MCLK DPM during DPM Start Function!",
2294 PHM_WRITE_FIELD(hwmgr
->device
, MC_SEQ_CNTL_3
, CAC_EN
, 0x1);
2296 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
, ixLCAC_MC0_CNTL
, 0x5);
2297 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
, ixLCAC_MC1_CNTL
, 0x5);
2298 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
, ixLCAC_CPL_CNTL
, 0x100005);
2300 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
, ixLCAC_MC0_CNTL
, 0x400005);
2301 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
, ixLCAC_MC1_CNTL
, 0x400005);
2302 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
, ixLCAC_CPL_CNTL
, 0x500005);
2308 static int polaris10_start_dpm(struct pp_hwmgr
*hwmgr
)
2310 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
2312 /*enable general power management */
2314 PHM_WRITE_INDIRECT_FIELD(hwmgr
->device
, CGS_IND_REG__SMC
, GENERAL_PWRMGT
,
2315 GLOBAL_PWRMGT_EN
, 1);
2317 /* enable sclk deep sleep */
2319 PHM_WRITE_INDIRECT_FIELD(hwmgr
->device
, CGS_IND_REG__SMC
, SCLK_PWRMGT_CNTL
,
2322 /* prepare for PCIE DPM */
2324 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
,
2325 data
->soft_regs_start
+ offsetof(SMU74_SoftRegisters
,
2326 VoltageChangeTimeout
), 0x1000);
2327 PHM_WRITE_INDIRECT_FIELD(hwmgr
->device
, CGS_IND_REG__PCIE
,
2328 SWRST_COMMAND_1
, RESETLC
, 0x0);
2330 PP_ASSERT_WITH_CODE(
2331 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
2332 PPSMC_MSG_Voltage_Cntl_Enable)),
2333 "Failed to enable voltage DPM during DPM Start Function!",
2337 if (polaris10_enable_sclk_mclk_dpm(hwmgr
)) {
2338 printk(KERN_ERR
"Failed to enable Sclk DPM and Mclk DPM!");
2342 /* enable PCIE dpm */
2343 if (0 == data
->pcie_dpm_key_disabled
) {
2344 PP_ASSERT_WITH_CODE(
2345 (0 == smum_send_msg_to_smc(hwmgr
->smumgr
,
2346 PPSMC_MSG_PCIeDPM_Enable
)),
2347 "Failed to enable pcie DPM during DPM Start Function!",
2351 PP_ASSERT_WITH_CODE((0 == smum_send_msg_to_smc(hwmgr
->smumgr
,
2352 PPSMC_MSG_EnableACDCGPIOInterrupt
)),
2353 "Failed to enable AC DC GPIO Interrupt!",
2359 static void polaris10_set_dpm_event_sources(struct pp_hwmgr
*hwmgr
, uint32_t sources
)
2362 enum DPM_EVENT_SRC src
;
2366 printk(KERN_ERR
"Unknown throttling event sources.");
2372 case (1 << PHM_AutoThrottleSource_Thermal
):
2374 src
= DPM_EVENT_SRC_DIGITAL
;
2376 case (1 << PHM_AutoThrottleSource_External
):
2378 src
= DPM_EVENT_SRC_EXTERNAL
;
2380 case (1 << PHM_AutoThrottleSource_External
) |
2381 (1 << PHM_AutoThrottleSource_Thermal
):
2383 src
= DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL
;
2386 /* Order matters - don't enable thermal protection for the wrong source. */
2388 PHM_WRITE_INDIRECT_FIELD(hwmgr
->device
, CGS_IND_REG__SMC
, CG_THERMAL_CTRL
,
2389 DPM_EVENT_SRC
, src
);
2390 PHM_WRITE_INDIRECT_FIELD(hwmgr
->device
, CGS_IND_REG__SMC
, GENERAL_PWRMGT
,
2391 THERMAL_PROTECTION_DIS
,
2392 phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
,
2393 PHM_PlatformCaps_ThermalController
));
2395 PHM_WRITE_INDIRECT_FIELD(hwmgr
->device
, CGS_IND_REG__SMC
, GENERAL_PWRMGT
,
2396 THERMAL_PROTECTION_DIS
, 1);
2399 static int polaris10_enable_auto_throttle_source(struct pp_hwmgr
*hwmgr
,
2400 PHM_AutoThrottleSource source
)
2402 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
2404 if (!(data
->active_auto_throttle_sources
& (1 << source
))) {
2405 data
->active_auto_throttle_sources
|= 1 << source
;
2406 polaris10_set_dpm_event_sources(hwmgr
, data
->active_auto_throttle_sources
);
2411 static int polaris10_enable_thermal_auto_throttle(struct pp_hwmgr
*hwmgr
)
2413 return polaris10_enable_auto_throttle_source(hwmgr
, PHM_AutoThrottleSource_Thermal
);
2416 int polaris10_pcie_performance_request(struct pp_hwmgr
*hwmgr
)
2418 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
2419 data
->pcie_performance_request
= true;
2424 int polaris10_enable_dpm_tasks(struct pp_hwmgr
*hwmgr
)
2426 int tmp_result
, result
= 0;
2427 tmp_result
= (!polaris10_is_dpm_running(hwmgr
)) ? 0 : -1;
2428 PP_ASSERT_WITH_CODE(result
== 0,
2429 "DPM is already running right now, no need to enable DPM!",
2432 if (polaris10_voltage_control(hwmgr
)) {
2433 tmp_result
= polaris10_enable_voltage_control(hwmgr
);
2434 PP_ASSERT_WITH_CODE(tmp_result
== 0,
2435 "Failed to enable voltage control!",
2436 result
= tmp_result
);
2438 tmp_result
= polaris10_construct_voltage_tables(hwmgr
);
2439 PP_ASSERT_WITH_CODE((0 == tmp_result
),
2440 "Failed to contruct voltage tables!",
2441 result
= tmp_result
);
2444 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
,
2445 PHM_PlatformCaps_EngineSpreadSpectrumSupport
))
2446 PHM_WRITE_INDIRECT_FIELD(hwmgr
->device
, CGS_IND_REG__SMC
,
2447 GENERAL_PWRMGT
, DYN_SPREAD_SPECTRUM_EN
, 1);
2449 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
,
2450 PHM_PlatformCaps_ThermalController
))
2451 PHM_WRITE_INDIRECT_FIELD(hwmgr
->device
, CGS_IND_REG__SMC
,
2452 GENERAL_PWRMGT
, THERMAL_PROTECTION_DIS
, 0);
2454 tmp_result
= polaris10_program_static_screen_threshold_parameters(hwmgr
);
2455 PP_ASSERT_WITH_CODE((0 == tmp_result
),
2456 "Failed to program static screen threshold parameters!",
2457 result
= tmp_result
);
2459 tmp_result
= polaris10_enable_display_gap(hwmgr
);
2460 PP_ASSERT_WITH_CODE((0 == tmp_result
),
2461 "Failed to enable display gap!", result
= tmp_result
);
2463 tmp_result
= polaris10_program_voting_clients(hwmgr
);
2464 PP_ASSERT_WITH_CODE((0 == tmp_result
),
2465 "Failed to program voting clients!", result
= tmp_result
);
2467 tmp_result
= polaris10_process_firmware_header(hwmgr
);
2468 PP_ASSERT_WITH_CODE((0 == tmp_result
),
2469 "Failed to process firmware header!", result
= tmp_result
);
2471 tmp_result
= polaris10_initial_switch_from_arbf0_to_f1(hwmgr
);
2472 PP_ASSERT_WITH_CODE((0 == tmp_result
),
2473 "Failed to initialize switch from ArbF0 to F1!",
2474 result
= tmp_result
);
2476 tmp_result
= polaris10_init_smc_table(hwmgr
);
2477 PP_ASSERT_WITH_CODE((0 == tmp_result
),
2478 "Failed to initialize SMC table!", result
= tmp_result
);
2480 tmp_result
= polaris10_init_arb_table_index(hwmgr
);
2481 PP_ASSERT_WITH_CODE((0 == tmp_result
),
2482 "Failed to initialize ARB table index!", result
= tmp_result
);
2484 tmp_result
= polaris10_populate_pm_fuses(hwmgr
);
2485 PP_ASSERT_WITH_CODE((0 == tmp_result
),
2486 "Failed to populate PM fuses!", result
= tmp_result
);
2488 tmp_result
= polaris10_enable_vrhot_gpio_interrupt(hwmgr
);
2489 PP_ASSERT_WITH_CODE((0 == tmp_result
),
2490 "Failed to enable VR hot GPIO interrupt!", result
= tmp_result
);
2492 tmp_result
= polaris10_enable_sclk_control(hwmgr
);
2493 PP_ASSERT_WITH_CODE((0 == tmp_result
),
2494 "Failed to enable SCLK control!", result
= tmp_result
);
2496 tmp_result
= polaris10_enable_smc_voltage_controller(hwmgr
);
2497 PP_ASSERT_WITH_CODE((0 == tmp_result
),
2498 "Failed to enable voltage control!", result
= tmp_result
);
2500 tmp_result
= polaris10_enable_ulv(hwmgr
);
2501 PP_ASSERT_WITH_CODE((0 == tmp_result
),
2502 "Failed to enable ULV!", result
= tmp_result
);
2504 tmp_result
= polaris10_enable_deep_sleep_master_switch(hwmgr
);
2505 PP_ASSERT_WITH_CODE((0 == tmp_result
),
2506 "Failed to enable deep sleep master switch!", result
= tmp_result
);
2508 tmp_result
= polaris10_start_dpm(hwmgr
);
2509 PP_ASSERT_WITH_CODE((0 == tmp_result
),
2510 "Failed to start DPM!", result
= tmp_result
);
2512 tmp_result
= polaris10_enable_smc_cac(hwmgr
);
2513 PP_ASSERT_WITH_CODE((0 == tmp_result
),
2514 "Failed to enable SMC CAC!", result
= tmp_result
);
2516 tmp_result
= polaris10_enable_power_containment(hwmgr
);
2517 PP_ASSERT_WITH_CODE((0 == tmp_result
),
2518 "Failed to enable power containment!", result
= tmp_result
);
2520 tmp_result
= polaris10_power_control_set_level(hwmgr
);
2521 PP_ASSERT_WITH_CODE((0 == tmp_result
),
2522 "Failed to power control set level!", result
= tmp_result
);
2524 tmp_result
= polaris10_enable_thermal_auto_throttle(hwmgr
);
2525 PP_ASSERT_WITH_CODE((0 == tmp_result
),
2526 "Failed to enable thermal auto throttle!", result
= tmp_result
);
2528 tmp_result
= polaris10_pcie_performance_request(hwmgr
);
2529 PP_ASSERT_WITH_CODE((0 == tmp_result
),
2530 "Failed to enable thermal auto throttle!", result
= tmp_result
);
2535 int polaris10_disable_dpm_tasks(struct pp_hwmgr
*hwmgr
)
2541 int polaris10_reset_asic_tasks(struct pp_hwmgr
*hwmgr
)
2547 int polaris10_hwmgr_backend_fini(struct pp_hwmgr
*hwmgr
)
2549 return phm_hwmgr_backend_fini(hwmgr
);
2552 int polaris10_set_features_platform_caps(struct pp_hwmgr
*hwmgr
)
2554 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
2556 phm_cap_set(hwmgr
->platform_descriptor
.platformCaps
,
2557 PHM_PlatformCaps_SclkDeepSleep
);
2559 if (data
->mvdd_control
== POLARIS10_VOLTAGE_CONTROL_NONE
)
2560 phm_cap_unset(hwmgr
->platform_descriptor
.platformCaps
,
2561 PHM_PlatformCaps_EnableMVDDControl
);
2563 if (data
->vddci_control
== POLARIS10_VOLTAGE_CONTROL_NONE
)
2564 phm_cap_unset(hwmgr
->platform_descriptor
.platformCaps
,
2565 PHM_PlatformCaps_ControlVDDCI
);
2567 phm_cap_set(hwmgr
->platform_descriptor
.platformCaps
,
2568 PHM_PlatformCaps_TablelessHardwareInterface
);
2570 phm_cap_set(hwmgr
->platform_descriptor
.platformCaps
,
2571 PHM_PlatformCaps_EnableSMU7ThermalManagement
);
2573 phm_cap_set(hwmgr
->platform_descriptor
.platformCaps
,
2574 PHM_PlatformCaps_DynamicPowerManagement
);
2576 phm_cap_set(hwmgr
->platform_descriptor
.platformCaps
,
2577 PHM_PlatformCaps_TablelessHardwareInterface
);
2579 phm_cap_set(hwmgr
->platform_descriptor
.platformCaps
,
2580 PHM_PlatformCaps_SMC
);
2582 phm_cap_set(hwmgr
->platform_descriptor
.platformCaps
,
2583 PHM_PlatformCaps_NonABMSupportInPPLib
);
2585 phm_cap_set(hwmgr
->platform_descriptor
.platformCaps
,
2586 PHM_PlatformCaps_DynamicUVDState
);
2588 phm_cap_set(hwmgr
->platform_descriptor
.platformCaps
,
2589 PHM_PlatformCaps_SclkThrottleLowNotification
);
2591 /* power tune caps Assume disabled */
2592 phm_cap_unset(hwmgr
->platform_descriptor
.platformCaps
,
2593 PHM_PlatformCaps_PowerContainment
);
2594 phm_cap_unset(hwmgr
->platform_descriptor
.platformCaps
,
2595 PHM_PlatformCaps_CAC
);
2596 phm_cap_unset(hwmgr
->platform_descriptor
.platformCaps
,
2597 PHM_PlatformCaps_SQRamping
);
2598 phm_cap_unset(hwmgr
->platform_descriptor
.platformCaps
,
2599 PHM_PlatformCaps_DBRamping
);
2600 phm_cap_unset(hwmgr
->platform_descriptor
.platformCaps
,
2601 PHM_PlatformCaps_TDRamping
);
2602 phm_cap_unset(hwmgr
->platform_descriptor
.platformCaps
,
2603 PHM_PlatformCaps_TCPRamping
);
2608 static void polaris10_init_dpm_defaults(struct pp_hwmgr
*hwmgr
)
2610 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
2612 polaris10_initialize_power_tune_defaults(hwmgr
);
2614 data
->pcie_gen_performance
.max
= PP_PCIEGen1
;
2615 data
->pcie_gen_performance
.min
= PP_PCIEGen3
;
2616 data
->pcie_gen_power_saving
.max
= PP_PCIEGen1
;
2617 data
->pcie_gen_power_saving
.min
= PP_PCIEGen3
;
2618 data
->pcie_lane_performance
.max
= 0;
2619 data
->pcie_lane_performance
.min
= 16;
2620 data
->pcie_lane_power_saving
.max
= 0;
2621 data
->pcie_lane_power_saving
.min
= 16;
2625 * Get Leakage VDDC based on leakage ID.
2627 * @param hwmgr the address of the powerplay hardware manager.
2630 static int polaris10_get_evv_voltages(struct pp_hwmgr
*hwmgr
)
2632 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
2637 struct phm_ppt_v1_information
*table_info
=
2638 (struct phm_ppt_v1_information
*)hwmgr
->pptable
;
2639 struct phm_ppt_v1_clock_voltage_dependency_table
*sclk_table
=
2640 table_info
->vdd_dep_on_sclk
;
2643 for (i
= 0; i
< POLARIS10_MAX_LEAKAGE_COUNT
; i
++) {
2644 vv_id
= ATOM_VIRTUAL_VOLTAGE_ID0
+ i
;
2645 if (!phm_get_sclk_for_voltage_evv(hwmgr
,
2646 table_info
->vddc_lookup_table
, vv_id
, &sclk
)) {
2647 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
,
2648 PHM_PlatformCaps_ClockStretcher
)) {
2649 for (j
= 1; j
< sclk_table
->count
; j
++) {
2650 if (sclk_table
->entries
[j
].clk
== sclk
&&
2651 sclk_table
->entries
[j
].cks_enable
== 0) {
2659 PP_ASSERT_WITH_CODE(0 == atomctrl_get_voltage_evv_on_sclk_ai(hwmgr
,
2660 VOLTAGE_TYPE_VDDC
, sclk
, vv_id
, &vddc
),
2661 "Error retrieving EVV voltage value!",
2665 /* need to make sure vddc is less than 2v or else, it could burn the ASIC. */
2666 PP_ASSERT_WITH_CODE((vddc
< 2000 && vddc
!= 0),
2667 "Invalid VDDC value", result
= -EINVAL
;);
2669 /* the voltage should not be zero nor equal to leakage ID */
2670 if (vddc
!= 0 && vddc
!= vv_id
) {
2671 data
->vddc_leakage
.actual_voltage
[data
->vddc_leakage
.count
] = (uint16_t)(vddc
/100);
2672 data
->vddc_leakage
.leakage_id
[data
->vddc_leakage
.count
] = vv_id
;
2673 data
->vddc_leakage
.count
++;
2682 * Change virtual leakage voltage to actual value.
2684 * @param hwmgr the address of the powerplay hardware manager.
2685 * @param pointer to changing voltage
2686 * @param pointer to leakage table
2688 static void polaris10_patch_with_vdd_leakage(struct pp_hwmgr
*hwmgr
,
2689 uint16_t *voltage
, struct polaris10_leakage_voltage
*leakage_table
)
2693 /* search for leakage voltage ID 0xff01 ~ 0xff08 */
2694 for (index
= 0; index
< leakage_table
->count
; index
++) {
2695 /* if this voltage matches a leakage voltage ID */
2696 /* patch with actual leakage voltage */
2697 if (leakage_table
->leakage_id
[index
] == *voltage
) {
2698 *voltage
= leakage_table
->actual_voltage
[index
];
2703 if (*voltage
> ATOM_VIRTUAL_VOLTAGE_ID0
)
2704 printk(KERN_ERR
"Voltage value looks like a Leakage ID but it's not patched \n");
2708 * Patch voltage lookup table by EVV leakages.
2710 * @param hwmgr the address of the powerplay hardware manager.
2711 * @param pointer to voltage lookup table
2712 * @param pointer to leakage table
2715 static int polaris10_patch_lookup_table_with_leakage(struct pp_hwmgr
*hwmgr
,
2716 phm_ppt_v1_voltage_lookup_table
*lookup_table
,
2717 struct polaris10_leakage_voltage
*leakage_table
)
2721 for (i
= 0; i
< lookup_table
->count
; i
++)
2722 polaris10_patch_with_vdd_leakage(hwmgr
,
2723 &lookup_table
->entries
[i
].us_vdd
, leakage_table
);
2728 static int polaris10_patch_clock_voltage_limits_with_vddc_leakage(
2729 struct pp_hwmgr
*hwmgr
, struct polaris10_leakage_voltage
*leakage_table
,
2732 struct phm_ppt_v1_information
*table_info
=
2733 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
2734 polaris10_patch_with_vdd_leakage(hwmgr
, (uint16_t *)vddc
, leakage_table
);
2735 hwmgr
->dyn_state
.max_clock_voltage_on_dc
.vddc
=
2736 table_info
->max_clock_voltage_on_dc
.vddc
;
2740 static int polaris10_patch_voltage_dependency_tables_with_lookup_table(
2741 struct pp_hwmgr
*hwmgr
)
2745 struct phm_ppt_v1_information
*table_info
=
2746 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
2748 struct phm_ppt_v1_clock_voltage_dependency_table
*sclk_table
=
2749 table_info
->vdd_dep_on_sclk
;
2750 struct phm_ppt_v1_clock_voltage_dependency_table
*mclk_table
=
2751 table_info
->vdd_dep_on_mclk
;
2752 struct phm_ppt_v1_mm_clock_voltage_dependency_table
*mm_table
=
2753 table_info
->mm_dep_table
;
2755 for (entryId
= 0; entryId
< sclk_table
->count
; ++entryId
) {
2756 voltageId
= sclk_table
->entries
[entryId
].vddInd
;
2757 sclk_table
->entries
[entryId
].vddc
=
2758 table_info
->vddc_lookup_table
->entries
[voltageId
].us_vdd
;
2761 for (entryId
= 0; entryId
< mclk_table
->count
; ++entryId
) {
2762 voltageId
= mclk_table
->entries
[entryId
].vddInd
;
2763 mclk_table
->entries
[entryId
].vddc
=
2764 table_info
->vddc_lookup_table
->entries
[voltageId
].us_vdd
;
2767 for (entryId
= 0; entryId
< mm_table
->count
; ++entryId
) {
2768 voltageId
= mm_table
->entries
[entryId
].vddcInd
;
2769 mm_table
->entries
[entryId
].vddc
=
2770 table_info
->vddc_lookup_table
->entries
[voltageId
].us_vdd
;
2777 static int polaris10_calc_voltage_dependency_tables(struct pp_hwmgr
*hwmgr
)
2779 /* Need to determine if we need calculated voltage. */
2783 static int polaris10_calc_mm_voltage_dependency_table(struct pp_hwmgr
*hwmgr
)
2785 /* Need to determine if we need calculated voltage from mm table. */
2789 static int polaris10_sort_lookup_table(struct pp_hwmgr
*hwmgr
,
2790 struct phm_ppt_v1_voltage_lookup_table
*lookup_table
)
2792 uint32_t table_size
, i
, j
;
2793 struct phm_ppt_v1_voltage_lookup_record tmp_voltage_lookup_record
;
2794 table_size
= lookup_table
->count
;
2796 PP_ASSERT_WITH_CODE(0 != lookup_table
->count
,
2797 "Lookup table is empty", return -EINVAL
);
2799 /* Sorting voltages */
2800 for (i
= 0; i
< table_size
- 1; i
++) {
2801 for (j
= i
+ 1; j
> 0; j
--) {
2802 if (lookup_table
->entries
[j
].us_vdd
<
2803 lookup_table
->entries
[j
- 1].us_vdd
) {
2804 tmp_voltage_lookup_record
= lookup_table
->entries
[j
- 1];
2805 lookup_table
->entries
[j
- 1] = lookup_table
->entries
[j
];
2806 lookup_table
->entries
[j
] = tmp_voltage_lookup_record
;
2814 static int polaris10_complete_dependency_tables(struct pp_hwmgr
*hwmgr
)
2818 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
2819 struct phm_ppt_v1_information
*table_info
=
2820 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
2822 tmp_result
= polaris10_patch_lookup_table_with_leakage(hwmgr
,
2823 table_info
->vddc_lookup_table
, &(data
->vddc_leakage
));
2825 result
= tmp_result
;
2827 tmp_result
= polaris10_patch_clock_voltage_limits_with_vddc_leakage(hwmgr
,
2828 &(data
->vddc_leakage
), &table_info
->max_clock_voltage_on_dc
.vddc
);
2830 result
= tmp_result
;
2832 tmp_result
= polaris10_patch_voltage_dependency_tables_with_lookup_table(hwmgr
);
2834 result
= tmp_result
;
2836 tmp_result
= polaris10_calc_voltage_dependency_tables(hwmgr
);
2838 result
= tmp_result
;
2840 tmp_result
= polaris10_calc_mm_voltage_dependency_table(hwmgr
);
2842 result
= tmp_result
;
2844 tmp_result
= polaris10_sort_lookup_table(hwmgr
, table_info
->vddc_lookup_table
);
2846 result
= tmp_result
;
2851 static int polaris10_set_private_data_based_on_pptable(struct pp_hwmgr
*hwmgr
)
2853 struct phm_ppt_v1_information
*table_info
=
2854 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
2856 struct phm_ppt_v1_clock_voltage_dependency_table
*allowed_sclk_vdd_table
=
2857 table_info
->vdd_dep_on_sclk
;
2858 struct phm_ppt_v1_clock_voltage_dependency_table
*allowed_mclk_vdd_table
=
2859 table_info
->vdd_dep_on_mclk
;
2861 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table
!= NULL
,
2862 "VDD dependency on SCLK table is missing. \
2863 This table is mandatory", return -EINVAL
);
2864 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table
->count
>= 1,
2865 "VDD dependency on SCLK table has to have is missing. \
2866 This table is mandatory", return -EINVAL
);
2868 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table
!= NULL
,
2869 "VDD dependency on MCLK table is missing. \
2870 This table is mandatory", return -EINVAL
);
2871 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table
->count
>= 1,
2872 "VDD dependency on MCLK table has to have is missing. \
2873 This table is mandatory", return -EINVAL
);
2875 table_info
->max_clock_voltage_on_ac
.sclk
=
2876 allowed_sclk_vdd_table
->entries
[allowed_sclk_vdd_table
->count
- 1].clk
;
2877 table_info
->max_clock_voltage_on_ac
.mclk
=
2878 allowed_mclk_vdd_table
->entries
[allowed_mclk_vdd_table
->count
- 1].clk
;
2879 table_info
->max_clock_voltage_on_ac
.vddc
=
2880 allowed_sclk_vdd_table
->entries
[allowed_sclk_vdd_table
->count
- 1].vddc
;
2881 table_info
->max_clock_voltage_on_ac
.vddci
=
2882 allowed_mclk_vdd_table
->entries
[allowed_mclk_vdd_table
->count
- 1].vddci
;
2887 int polaris10_hwmgr_backend_init(struct pp_hwmgr
*hwmgr
)
2889 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
2890 struct pp_atomctrl_gpio_pin_assignment gpio_pin_assignment
;
2894 data
->dll_default_on
= false;
2895 data
->sram_end
= SMC_RAM_END
;
2897 data
->disable_dpm_mask
= 0xFF;
2898 data
->static_screen_threshold
= PPPOLARIS10_STATICSCREENTHRESHOLD_DFLT
;
2899 data
->static_screen_threshold_unit
= PPPOLARIS10_STATICSCREENTHRESHOLD_DFLT
;
2900 data
->activity_target
[0] = PPPOLARIS10_TARGETACTIVITY_DFLT
;
2901 data
->activity_target
[1] = PPPOLARIS10_TARGETACTIVITY_DFLT
;
2902 data
->activity_target
[2] = PPPOLARIS10_TARGETACTIVITY_DFLT
;
2903 data
->activity_target
[3] = PPPOLARIS10_TARGETACTIVITY_DFLT
;
2904 data
->activity_target
[4] = PPPOLARIS10_TARGETACTIVITY_DFLT
;
2905 data
->activity_target
[5] = PPPOLARIS10_TARGETACTIVITY_DFLT
;
2906 data
->activity_target
[6] = PPPOLARIS10_TARGETACTIVITY_DFLT
;
2907 data
->activity_target
[7] = PPPOLARIS10_TARGETACTIVITY_DFLT
;
2909 data
->voting_rights_clients0
= PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT0
;
2910 data
->voting_rights_clients1
= PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT1
;
2911 data
->voting_rights_clients2
= PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT2
;
2912 data
->voting_rights_clients3
= PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT3
;
2913 data
->voting_rights_clients4
= PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT4
;
2914 data
->voting_rights_clients5
= PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT5
;
2915 data
->voting_rights_clients6
= PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT6
;
2916 data
->voting_rights_clients7
= PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT7
;
2918 data
->vddc_vddci_delta
= VDDC_VDDCI_DELTA
;
2920 data
->mclk_activity_target
= PPPOLARIS10_MCLK_TARGETACTIVITY_DFLT
;
2922 /* need to set voltage control types before EVV patching */
2923 data
->voltage_control
= POLARIS10_VOLTAGE_CONTROL_NONE
;
2924 data
->vddci_control
= POLARIS10_VOLTAGE_CONTROL_NONE
;
2925 data
->mvdd_control
= POLARIS10_VOLTAGE_CONTROL_NONE
;
2927 if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr
,
2928 VOLTAGE_TYPE_VDDC
, VOLTAGE_OBJ_SVID2
))
2929 data
->voltage_control
= POLARIS10_VOLTAGE_CONTROL_BY_SVID2
;
2931 phm_cap_set(hwmgr
->platform_descriptor
.platformCaps
,
2932 PHM_PlatformCaps_DynamicPatchPowerState
);
2934 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
,
2935 PHM_PlatformCaps_EnableMVDDControl
)) {
2936 if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr
,
2937 VOLTAGE_TYPE_MVDDC
, VOLTAGE_OBJ_GPIO_LUT
))
2938 data
->mvdd_control
= POLARIS10_VOLTAGE_CONTROL_BY_GPIO
;
2939 else if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr
,
2940 VOLTAGE_TYPE_MVDDC
, VOLTAGE_OBJ_SVID2
))
2941 data
->mvdd_control
= POLARIS10_VOLTAGE_CONTROL_BY_SVID2
;
2944 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
,
2945 PHM_PlatformCaps_ControlVDDCI
)) {
2946 if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr
,
2947 VOLTAGE_TYPE_VDDCI
, VOLTAGE_OBJ_GPIO_LUT
))
2948 data
->vddci_control
= POLARIS10_VOLTAGE_CONTROL_BY_GPIO
;
2949 else if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr
,
2950 VOLTAGE_TYPE_VDDCI
, VOLTAGE_OBJ_SVID2
))
2951 data
->vddci_control
= POLARIS10_VOLTAGE_CONTROL_BY_SVID2
;
2954 polaris10_set_features_platform_caps(hwmgr
);
2956 polaris10_init_dpm_defaults(hwmgr
);
2958 /* Get leakage voltage based on leakage ID. */
2959 result
= polaris10_get_evv_voltages(hwmgr
);
2962 printk("Get EVV Voltage Failed. Abort Driver loading!\n");
2966 polaris10_complete_dependency_tables(hwmgr
);
2967 polaris10_set_private_data_based_on_pptable(hwmgr
);
2969 /* Initalize Dynamic State Adjustment Rule Settings */
2970 result
= phm_initializa_dynamic_state_adjustment_rule_settings(hwmgr
);
2973 struct cgs_system_info sys_info
= {0};
2975 data
->is_tlu_enabled
= 0;
2977 hwmgr
->platform_descriptor
.hardwareActivityPerformanceLevels
=
2978 POLARIS10_MAX_HARDWARE_POWERLEVELS
;
2979 hwmgr
->platform_descriptor
.hardwarePerformanceLevels
= 2;
2980 hwmgr
->platform_descriptor
.minimumClocksReductionPercentage
= 50;
2981 hwmgr
->platform_descriptor
.vbiosInterruptId
= 0x20000400; /* IRQ_SOURCE1_SW_INT */
2982 /* The true clock step depends on the frequency, typically 4.5 or 9 MHz. Here we use 5. */
2983 hwmgr
->platform_descriptor
.clockStep
.engineClock
= 500;
2984 hwmgr
->platform_descriptor
.clockStep
.memoryClock
= 500;
2986 if (atomctrl_get_pp_assign_pin(hwmgr
, VDDC_PCC_GPIO_PINID
, &gpio_pin_assignment
)) {
2987 temp_reg
= cgs_read_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
, ixCNB_PWRMGT_CNTL
);
2988 switch (gpio_pin_assignment
.uc_gpio_pin_bit_shift
) {
2990 temp_reg
= PHM_SET_FIELD(temp_reg
, CNB_PWRMGT_CNTL
, GNB_SLOW_MODE
, 0x1);
2993 temp_reg
= PHM_SET_FIELD(temp_reg
, CNB_PWRMGT_CNTL
, GNB_SLOW_MODE
, 0x2);
2996 temp_reg
= PHM_SET_FIELD(temp_reg
, CNB_PWRMGT_CNTL
, GNB_SLOW
, 0x1);
2999 temp_reg
= PHM_SET_FIELD(temp_reg
, CNB_PWRMGT_CNTL
, FORCE_NB_PS1
, 0x1);
3002 temp_reg
= PHM_SET_FIELD(temp_reg
, CNB_PWRMGT_CNTL
, DPM_ENABLED
, 0x1);
3005 PP_ASSERT_WITH_CODE(0,
3006 "Failed to setup PCC HW register! Wrong GPIO assigned for VDDC_PCC_GPIO_PINID!",
3010 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
, ixCNB_PWRMGT_CNTL
, temp_reg
);
3013 sys_info
.size
= sizeof(struct cgs_system_info
);
3014 sys_info
.info_id
= CGS_SYSTEM_INFO_PCIE_GEN_INFO
;
3015 result
= cgs_query_system_info(hwmgr
->device
, &sys_info
);
3017 data
->pcie_gen_cap
= 0x30007;
3019 data
->pcie_gen_cap
= (uint32_t)sys_info
.value
;
3020 if (data
->pcie_gen_cap
& CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3
)
3021 data
->pcie_spc_cap
= 20;
3022 sys_info
.size
= sizeof(struct cgs_system_info
);
3023 sys_info
.info_id
= CGS_SYSTEM_INFO_PCIE_MLW
;
3024 result
= cgs_query_system_info(hwmgr
->device
, &sys_info
);
3026 data
->pcie_lane_cap
= 0x2f0000;
3028 data
->pcie_lane_cap
= (uint32_t)sys_info
.value
;
3030 /* Ignore return value in here, we are cleaning up a mess. */
3031 polaris10_hwmgr_backend_fini(hwmgr
);
3037 static int polaris10_force_dpm_highest(struct pp_hwmgr
*hwmgr
)
3039 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
3040 uint32_t level
, tmp
;
3042 if (!data
->pcie_dpm_key_disabled
) {
3043 if (data
->dpm_level_enable_mask
.pcie_dpm_enable_mask
) {
3045 tmp
= data
->dpm_level_enable_mask
.pcie_dpm_enable_mask
;
3050 smum_send_msg_to_smc_with_parameter(hwmgr
->smumgr
,
3051 PPSMC_MSG_PCIeDPM_ForceLevel
, level
);
3055 if (!data
->sclk_dpm_key_disabled
) {
3056 if (data
->dpm_level_enable_mask
.sclk_dpm_enable_mask
) {
3058 tmp
= data
->dpm_level_enable_mask
.sclk_dpm_enable_mask
;
3063 smum_send_msg_to_smc_with_parameter(hwmgr
->smumgr
,
3064 PPSMC_MSG_SCLKDPM_SetEnabledMask
,
3069 if (!data
->mclk_dpm_key_disabled
) {
3070 if (data
->dpm_level_enable_mask
.mclk_dpm_enable_mask
) {
3072 tmp
= data
->dpm_level_enable_mask
.mclk_dpm_enable_mask
;
3077 smum_send_msg_to_smc_with_parameter(hwmgr
->smumgr
,
3078 PPSMC_MSG_MCLKDPM_SetEnabledMask
,
3086 static int polaris10_upload_dpm_level_enable_mask(struct pp_hwmgr
*hwmgr
)
3088 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
3090 phm_apply_dal_min_voltage_request(hwmgr
);
3092 if (!data
->sclk_dpm_key_disabled
) {
3093 if (data
->dpm_level_enable_mask
.sclk_dpm_enable_mask
)
3094 smum_send_msg_to_smc_with_parameter(hwmgr
->smumgr
,
3095 PPSMC_MSG_SCLKDPM_SetEnabledMask
,
3096 data
->dpm_level_enable_mask
.sclk_dpm_enable_mask
);
3099 if (!data
->mclk_dpm_key_disabled
) {
3100 if (data
->dpm_level_enable_mask
.mclk_dpm_enable_mask
)
3101 smum_send_msg_to_smc_with_parameter(hwmgr
->smumgr
,
3102 PPSMC_MSG_MCLKDPM_SetEnabledMask
,
3103 data
->dpm_level_enable_mask
.mclk_dpm_enable_mask
);
3109 static int polaris10_unforce_dpm_levels(struct pp_hwmgr
*hwmgr
)
3111 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
3113 if (!polaris10_is_dpm_running(hwmgr
))
3116 if (!data
->pcie_dpm_key_disabled
) {
3117 smum_send_msg_to_smc(hwmgr
->smumgr
,
3118 PPSMC_MSG_PCIeDPM_UnForceLevel
);
3121 return polaris10_upload_dpm_level_enable_mask(hwmgr
);
3124 static int polaris10_force_dpm_lowest(struct pp_hwmgr
*hwmgr
)
3126 struct polaris10_hwmgr
*data
=
3127 (struct polaris10_hwmgr
*)(hwmgr
->backend
);
3130 if (!data
->sclk_dpm_key_disabled
)
3131 if (data
->dpm_level_enable_mask
.sclk_dpm_enable_mask
) {
3132 level
= phm_get_lowest_enabled_level(hwmgr
,
3133 data
->dpm_level_enable_mask
.sclk_dpm_enable_mask
);
3134 smum_send_msg_to_smc_with_parameter(hwmgr
->smumgr
,
3135 PPSMC_MSG_SCLKDPM_SetEnabledMask
,
3139 /* uvd is enabled, can't set mclk low right now
3140 if (!data->mclk_dpm_key_disabled) {
3141 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
3142 level = phm_get_lowest_enabled_level(hwmgr,
3143 data->dpm_level_enable_mask.mclk_dpm_enable_mask);
3144 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3145 PPSMC_MSG_MCLKDPM_SetEnabledMask,
3150 if (!data
->pcie_dpm_key_disabled
) {
3151 if (data
->dpm_level_enable_mask
.pcie_dpm_enable_mask
) {
3152 level
= phm_get_lowest_enabled_level(hwmgr
,
3153 data
->dpm_level_enable_mask
.pcie_dpm_enable_mask
);
3154 smum_send_msg_to_smc_with_parameter(hwmgr
->smumgr
,
3155 PPSMC_MSG_PCIeDPM_ForceLevel
,
3163 static int polaris10_force_dpm_level(struct pp_hwmgr
*hwmgr
,
3164 enum amd_dpm_forced_level level
)
3169 case AMD_DPM_FORCED_LEVEL_HIGH
:
3170 ret
= polaris10_force_dpm_highest(hwmgr
);
3174 case AMD_DPM_FORCED_LEVEL_LOW
:
3175 ret
= polaris10_force_dpm_lowest(hwmgr
);
3179 case AMD_DPM_FORCED_LEVEL_AUTO
:
3180 ret
= polaris10_unforce_dpm_levels(hwmgr
);
3188 hwmgr
->dpm_level
= level
;
3193 static int polaris10_get_power_state_size(struct pp_hwmgr
*hwmgr
)
3195 return sizeof(struct polaris10_power_state
);
3199 static int polaris10_apply_state_adjust_rules(struct pp_hwmgr
*hwmgr
,
3200 struct pp_power_state
*request_ps
,
3201 const struct pp_power_state
*current_ps
)
3204 struct polaris10_power_state
*polaris10_ps
=
3205 cast_phw_polaris10_power_state(&request_ps
->hardware
);
3208 struct PP_Clocks minimum_clocks
= {0};
3209 bool disable_mclk_switching
;
3210 bool disable_mclk_switching_for_frame_lock
;
3211 struct cgs_display_info info
= {0};
3212 const struct phm_clock_and_voltage_limits
*max_limits
;
3214 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
3215 struct phm_ppt_v1_information
*table_info
=
3216 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
3218 int32_t stable_pstate_sclk
= 0, stable_pstate_mclk
= 0;
3220 data
->battery_state
= (PP_StateUILabel_Battery
==
3221 request_ps
->classification
.ui_label
);
3223 PP_ASSERT_WITH_CODE(polaris10_ps
->performance_level_count
== 2,
3224 "VI should always have 2 performance levels",
3227 max_limits
= (PP_PowerSource_AC
== hwmgr
->power_source
) ?
3228 &(hwmgr
->dyn_state
.max_clock_voltage_on_ac
) :
3229 &(hwmgr
->dyn_state
.max_clock_voltage_on_dc
);
3231 /* Cap clock DPM tables at DC MAX if it is in DC. */
3232 if (PP_PowerSource_DC
== hwmgr
->power_source
) {
3233 for (i
= 0; i
< polaris10_ps
->performance_level_count
; i
++) {
3234 if (polaris10_ps
->performance_levels
[i
].memory_clock
> max_limits
->mclk
)
3235 polaris10_ps
->performance_levels
[i
].memory_clock
= max_limits
->mclk
;
3236 if (polaris10_ps
->performance_levels
[i
].engine_clock
> max_limits
->sclk
)
3237 polaris10_ps
->performance_levels
[i
].engine_clock
= max_limits
->sclk
;
3241 polaris10_ps
->vce_clks
.evclk
= hwmgr
->vce_arbiter
.evclk
;
3242 polaris10_ps
->vce_clks
.ecclk
= hwmgr
->vce_arbiter
.ecclk
;
3244 cgs_get_active_displays_info(hwmgr
->device
, &info
);
3246 /*TO DO result = PHM_CheckVBlankTime(hwmgr, &vblankTooShort);*/
3248 /* TO DO GetMinClockSettings(hwmgr->pPECI, &minimum_clocks); */
3250 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
,
3251 PHM_PlatformCaps_StablePState
)) {
3252 max_limits
= &(hwmgr
->dyn_state
.max_clock_voltage_on_ac
);
3253 stable_pstate_sclk
= (max_limits
->sclk
* 75) / 100;
3255 for (count
= table_info
->vdd_dep_on_sclk
->count
- 1;
3256 count
>= 0; count
--) {
3257 if (stable_pstate_sclk
>=
3258 table_info
->vdd_dep_on_sclk
->entries
[count
].clk
) {
3259 stable_pstate_sclk
=
3260 table_info
->vdd_dep_on_sclk
->entries
[count
].clk
;
3266 stable_pstate_sclk
= table_info
->vdd_dep_on_sclk
->entries
[0].clk
;
3268 stable_pstate_mclk
= max_limits
->mclk
;
3270 minimum_clocks
.engineClock
= stable_pstate_sclk
;
3271 minimum_clocks
.memoryClock
= stable_pstate_mclk
;
3274 if (minimum_clocks
.engineClock
< hwmgr
->gfx_arbiter
.sclk
)
3275 minimum_clocks
.engineClock
= hwmgr
->gfx_arbiter
.sclk
;
3277 if (minimum_clocks
.memoryClock
< hwmgr
->gfx_arbiter
.mclk
)
3278 minimum_clocks
.memoryClock
= hwmgr
->gfx_arbiter
.mclk
;
3280 polaris10_ps
->sclk_threshold
= hwmgr
->gfx_arbiter
.sclk_threshold
;
3282 if (0 != hwmgr
->gfx_arbiter
.sclk_over_drive
) {
3283 PP_ASSERT_WITH_CODE((hwmgr
->gfx_arbiter
.sclk_over_drive
<=
3284 hwmgr
->platform_descriptor
.overdriveLimit
.engineClock
),
3285 "Overdrive sclk exceeds limit",
3286 hwmgr
->gfx_arbiter
.sclk_over_drive
=
3287 hwmgr
->platform_descriptor
.overdriveLimit
.engineClock
);
3289 if (hwmgr
->gfx_arbiter
.sclk_over_drive
>= hwmgr
->gfx_arbiter
.sclk
)
3290 polaris10_ps
->performance_levels
[1].engine_clock
=
3291 hwmgr
->gfx_arbiter
.sclk_over_drive
;
3294 if (0 != hwmgr
->gfx_arbiter
.mclk_over_drive
) {
3295 PP_ASSERT_WITH_CODE((hwmgr
->gfx_arbiter
.mclk_over_drive
<=
3296 hwmgr
->platform_descriptor
.overdriveLimit
.memoryClock
),
3297 "Overdrive mclk exceeds limit",
3298 hwmgr
->gfx_arbiter
.mclk_over_drive
=
3299 hwmgr
->platform_descriptor
.overdriveLimit
.memoryClock
);
3301 if (hwmgr
->gfx_arbiter
.mclk_over_drive
>= hwmgr
->gfx_arbiter
.mclk
)
3302 polaris10_ps
->performance_levels
[1].memory_clock
=
3303 hwmgr
->gfx_arbiter
.mclk_over_drive
;
3306 disable_mclk_switching_for_frame_lock
= phm_cap_enabled(
3307 hwmgr
->platform_descriptor
.platformCaps
,
3308 PHM_PlatformCaps_DisableMclkSwitchingForFrameLock
);
3310 disable_mclk_switching
= (1 < info
.display_count
) ||
3311 disable_mclk_switching_for_frame_lock
;
3313 sclk
= polaris10_ps
->performance_levels
[0].engine_clock
;
3314 mclk
= polaris10_ps
->performance_levels
[0].memory_clock
;
3316 if (disable_mclk_switching
)
3317 mclk
= polaris10_ps
->performance_levels
3318 [polaris10_ps
->performance_level_count
- 1].memory_clock
;
3320 if (sclk
< minimum_clocks
.engineClock
)
3321 sclk
= (minimum_clocks
.engineClock
> max_limits
->sclk
) ?
3322 max_limits
->sclk
: minimum_clocks
.engineClock
;
3324 if (mclk
< minimum_clocks
.memoryClock
)
3325 mclk
= (minimum_clocks
.memoryClock
> max_limits
->mclk
) ?
3326 max_limits
->mclk
: minimum_clocks
.memoryClock
;
3328 polaris10_ps
->performance_levels
[0].engine_clock
= sclk
;
3329 polaris10_ps
->performance_levels
[0].memory_clock
= mclk
;
3331 polaris10_ps
->performance_levels
[1].engine_clock
=
3332 (polaris10_ps
->performance_levels
[1].engine_clock
>=
3333 polaris10_ps
->performance_levels
[0].engine_clock
) ?
3334 polaris10_ps
->performance_levels
[1].engine_clock
:
3335 polaris10_ps
->performance_levels
[0].engine_clock
;
3337 if (disable_mclk_switching
) {
3338 if (mclk
< polaris10_ps
->performance_levels
[1].memory_clock
)
3339 mclk
= polaris10_ps
->performance_levels
[1].memory_clock
;
3341 polaris10_ps
->performance_levels
[0].memory_clock
= mclk
;
3342 polaris10_ps
->performance_levels
[1].memory_clock
= mclk
;
3344 if (polaris10_ps
->performance_levels
[1].memory_clock
<
3345 polaris10_ps
->performance_levels
[0].memory_clock
)
3346 polaris10_ps
->performance_levels
[1].memory_clock
=
3347 polaris10_ps
->performance_levels
[0].memory_clock
;
3350 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
,
3351 PHM_PlatformCaps_StablePState
)) {
3352 for (i
= 0; i
< polaris10_ps
->performance_level_count
; i
++) {
3353 polaris10_ps
->performance_levels
[i
].engine_clock
= stable_pstate_sclk
;
3354 polaris10_ps
->performance_levels
[i
].memory_clock
= stable_pstate_mclk
;
3355 polaris10_ps
->performance_levels
[i
].pcie_gen
= data
->pcie_gen_performance
.max
;
3356 polaris10_ps
->performance_levels
[i
].pcie_lane
= data
->pcie_gen_performance
.max
;
3363 static int polaris10_dpm_get_mclk(struct pp_hwmgr
*hwmgr
, bool low
)
3365 struct pp_power_state
*ps
;
3366 struct polaris10_power_state
*polaris10_ps
;
3371 ps
= hwmgr
->request_ps
;
3376 polaris10_ps
= cast_phw_polaris10_power_state(&ps
->hardware
);
3379 return polaris10_ps
->performance_levels
[0].memory_clock
;
3381 return polaris10_ps
->performance_levels
3382 [polaris10_ps
->performance_level_count
-1].memory_clock
;
3385 static int polaris10_dpm_get_sclk(struct pp_hwmgr
*hwmgr
, bool low
)
3387 struct pp_power_state
*ps
;
3388 struct polaris10_power_state
*polaris10_ps
;
3393 ps
= hwmgr
->request_ps
;
3398 polaris10_ps
= cast_phw_polaris10_power_state(&ps
->hardware
);
3401 return polaris10_ps
->performance_levels
[0].engine_clock
;
3403 return polaris10_ps
->performance_levels
3404 [polaris10_ps
->performance_level_count
-1].engine_clock
;
3407 static int polaris10_dpm_patch_boot_state(struct pp_hwmgr
*hwmgr
,
3408 struct pp_hw_power_state
*hw_ps
)
3410 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
3411 struct polaris10_power_state
*ps
= (struct polaris10_power_state
*)hw_ps
;
3412 ATOM_FIRMWARE_INFO_V2_2
*fw_info
;
3415 int index
= GetIndexIntoMasterTable(DATA
, FirmwareInfo
);
3417 /* First retrieve the Boot clocks and VDDC from the firmware info table.
3418 * We assume here that fw_info is unchanged if this call fails.
3420 fw_info
= (ATOM_FIRMWARE_INFO_V2_2
*)cgs_atom_get_data_table(
3421 hwmgr
->device
, index
,
3422 &size
, &frev
, &crev
);
3424 /* During a test, there is no firmware info table. */
3427 /* Patch the state. */
3428 data
->vbios_boot_state
.sclk_bootup_value
=
3429 le32_to_cpu(fw_info
->ulDefaultEngineClock
);
3430 data
->vbios_boot_state
.mclk_bootup_value
=
3431 le32_to_cpu(fw_info
->ulDefaultMemoryClock
);
3432 data
->vbios_boot_state
.mvdd_bootup_value
=
3433 le16_to_cpu(fw_info
->usBootUpMVDDCVoltage
);
3434 data
->vbios_boot_state
.vddc_bootup_value
=
3435 le16_to_cpu(fw_info
->usBootUpVDDCVoltage
);
3436 data
->vbios_boot_state
.vddci_bootup_value
=
3437 le16_to_cpu(fw_info
->usBootUpVDDCIVoltage
);
3438 data
->vbios_boot_state
.pcie_gen_bootup_value
=
3439 phm_get_current_pcie_speed(hwmgr
);
3441 data
->vbios_boot_state
.pcie_lane_bootup_value
=
3442 (uint16_t)phm_get_current_pcie_lane_number(hwmgr
);
3444 /* set boot power state */
3445 ps
->performance_levels
[0].memory_clock
= data
->vbios_boot_state
.mclk_bootup_value
;
3446 ps
->performance_levels
[0].engine_clock
= data
->vbios_boot_state
.sclk_bootup_value
;
3447 ps
->performance_levels
[0].pcie_gen
= data
->vbios_boot_state
.pcie_gen_bootup_value
;
3448 ps
->performance_levels
[0].pcie_lane
= data
->vbios_boot_state
.pcie_lane_bootup_value
;
3453 static int polaris10_get_pp_table_entry_callback_func(struct pp_hwmgr
*hwmgr
,
3454 void *state
, struct pp_power_state
*power_state
,
3455 void *pp_table
, uint32_t classification_flag
)
3457 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
3458 struct polaris10_power_state
*polaris10_power_state
=
3459 (struct polaris10_power_state
*)(&(power_state
->hardware
));
3460 struct polaris10_performance_level
*performance_level
;
3461 ATOM_Tonga_State
*state_entry
= (ATOM_Tonga_State
*)state
;
3462 ATOM_Tonga_POWERPLAYTABLE
*powerplay_table
=
3463 (ATOM_Tonga_POWERPLAYTABLE
*)pp_table
;
3464 ATOM_Tonga_SCLK_Dependency_Table
*sclk_dep_table
=
3465 (ATOM_Tonga_SCLK_Dependency_Table
*)
3466 (((unsigned long)powerplay_table
) +
3467 le16_to_cpu(powerplay_table
->usSclkDependencyTableOffset
));
3468 ATOM_Tonga_MCLK_Dependency_Table
*mclk_dep_table
=
3469 (ATOM_Tonga_MCLK_Dependency_Table
*)
3470 (((unsigned long)powerplay_table
) +
3471 le16_to_cpu(powerplay_table
->usMclkDependencyTableOffset
));
3473 /* The following fields are not initialized here: id orderedList allStatesList */
3474 power_state
->classification
.ui_label
=
3475 (le16_to_cpu(state_entry
->usClassification
) &
3476 ATOM_PPLIB_CLASSIFICATION_UI_MASK
) >>
3477 ATOM_PPLIB_CLASSIFICATION_UI_SHIFT
;
3478 power_state
->classification
.flags
= classification_flag
;
3479 /* NOTE: There is a classification2 flag in BIOS that is not being used right now */
3481 power_state
->classification
.temporary_state
= false;
3482 power_state
->classification
.to_be_deleted
= false;
3484 power_state
->validation
.disallowOnDC
=
3485 (0 != (le32_to_cpu(state_entry
->ulCapsAndSettings
) &
3486 ATOM_Tonga_DISALLOW_ON_DC
));
3488 power_state
->pcie
.lanes
= 0;
3490 power_state
->display
.disableFrameModulation
= false;
3491 power_state
->display
.limitRefreshrate
= false;
3492 power_state
->display
.enableVariBright
=
3493 (0 != (le32_to_cpu(state_entry
->ulCapsAndSettings
) &
3494 ATOM_Tonga_ENABLE_VARIBRIGHT
));
3496 power_state
->validation
.supportedPowerLevels
= 0;
3497 power_state
->uvd_clocks
.VCLK
= 0;
3498 power_state
->uvd_clocks
.DCLK
= 0;
3499 power_state
->temperatures
.min
= 0;
3500 power_state
->temperatures
.max
= 0;
3502 performance_level
= &(polaris10_power_state
->performance_levels
3503 [polaris10_power_state
->performance_level_count
++]);
3505 PP_ASSERT_WITH_CODE(
3506 (polaris10_power_state
->performance_level_count
< SMU74_MAX_LEVELS_GRAPHICS
),
3507 "Performance levels exceeds SMC limit!",
3510 PP_ASSERT_WITH_CODE(
3511 (polaris10_power_state
->performance_level_count
<=
3512 hwmgr
->platform_descriptor
.hardwareActivityPerformanceLevels
),
3513 "Performance levels exceeds Driver limit!",
3516 /* Performance levels are arranged from low to high. */
3517 performance_level
->memory_clock
= mclk_dep_table
->entries
3518 [state_entry
->ucMemoryClockIndexLow
].ulMclk
;
3519 performance_level
->engine_clock
= sclk_dep_table
->entries
3520 [state_entry
->ucEngineClockIndexLow
].ulSclk
;
3521 performance_level
->pcie_gen
= get_pcie_gen_support(data
->pcie_gen_cap
,
3522 state_entry
->ucPCIEGenLow
);
3523 performance_level
->pcie_lane
= get_pcie_lane_support(data
->pcie_lane_cap
,
3524 state_entry
->ucPCIELaneHigh
);
3526 performance_level
= &(polaris10_power_state
->performance_levels
3527 [polaris10_power_state
->performance_level_count
++]);
3528 performance_level
->memory_clock
= mclk_dep_table
->entries
3529 [state_entry
->ucMemoryClockIndexHigh
].ulMclk
;
3530 performance_level
->engine_clock
= sclk_dep_table
->entries
3531 [state_entry
->ucEngineClockIndexHigh
].ulSclk
;
3532 performance_level
->pcie_gen
= get_pcie_gen_support(data
->pcie_gen_cap
,
3533 state_entry
->ucPCIEGenHigh
);
3534 performance_level
->pcie_lane
= get_pcie_lane_support(data
->pcie_lane_cap
,
3535 state_entry
->ucPCIELaneHigh
);
3540 static int polaris10_get_pp_table_entry(struct pp_hwmgr
*hwmgr
,
3541 unsigned long entry_index
, struct pp_power_state
*state
)
3544 struct polaris10_power_state
*ps
;
3545 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
3546 struct phm_ppt_v1_information
*table_info
=
3547 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
3548 struct phm_ppt_v1_clock_voltage_dependency_table
*dep_mclk_table
=
3549 table_info
->vdd_dep_on_mclk
;
3551 state
->hardware
.magic
= PHM_VIslands_Magic
;
3553 ps
= (struct polaris10_power_state
*)(&state
->hardware
);
3555 result
= tonga_get_powerplay_table_entry(hwmgr
, entry_index
, state
,
3556 polaris10_get_pp_table_entry_callback_func
);
3558 /* This is the earliest time we have all the dependency table and the VBIOS boot state
3559 * as PP_Tables_GetPowerPlayTableEntry retrieves the VBIOS boot state
3560 * if there is only one VDDCI/MCLK level, check if it's the same as VBIOS boot state
3562 if (dep_mclk_table
!= NULL
&& dep_mclk_table
->count
== 1) {
3563 if (dep_mclk_table
->entries
[0].clk
!=
3564 data
->vbios_boot_state
.mclk_bootup_value
)
3565 printk(KERN_ERR
"Single MCLK entry VDDCI/MCLK dependency table "
3566 "does not match VBIOS boot MCLK level");
3567 if (dep_mclk_table
->entries
[0].vddci
!=
3568 data
->vbios_boot_state
.vddci_bootup_value
)
3569 printk(KERN_ERR
"Single VDDCI entry VDDCI/MCLK dependency table "
3570 "does not match VBIOS boot VDDCI level");
3573 /* set DC compatible flag if this state supports DC */
3574 if (!state
->validation
.disallowOnDC
)
3575 ps
->dc_compatible
= true;
3577 if (state
->classification
.flags
& PP_StateClassificationFlag_ACPI
)
3578 data
->acpi_pcie_gen
= ps
->performance_levels
[0].pcie_gen
;
3580 ps
->uvd_clks
.vclk
= state
->uvd_clocks
.VCLK
;
3581 ps
->uvd_clks
.dclk
= state
->uvd_clocks
.DCLK
;
3586 switch (state
->classification
.ui_label
) {
3587 case PP_StateUILabel_Performance
:
3588 data
->use_pcie_performance_levels
= true;
3590 for (i
= 0; i
< ps
->performance_level_count
; i
++) {
3591 if (data
->pcie_gen_performance
.max
<
3592 ps
->performance_levels
[i
].pcie_gen
)
3593 data
->pcie_gen_performance
.max
=
3594 ps
->performance_levels
[i
].pcie_gen
;
3596 if (data
->pcie_gen_performance
.min
>
3597 ps
->performance_levels
[i
].pcie_gen
)
3598 data
->pcie_gen_performance
.min
=
3599 ps
->performance_levels
[i
].pcie_gen
;
3601 if (data
->pcie_lane_performance
.max
<
3602 ps
->performance_levels
[i
].pcie_lane
)
3603 data
->pcie_lane_performance
.max
=
3604 ps
->performance_levels
[i
].pcie_lane
;
3606 if (data
->pcie_lane_performance
.min
>
3607 ps
->performance_levels
[i
].pcie_lane
)
3608 data
->pcie_lane_performance
.min
=
3609 ps
->performance_levels
[i
].pcie_lane
;
3612 case PP_StateUILabel_Battery
:
3613 data
->use_pcie_power_saving_levels
= true;
3615 for (i
= 0; i
< ps
->performance_level_count
; i
++) {
3616 if (data
->pcie_gen_power_saving
.max
<
3617 ps
->performance_levels
[i
].pcie_gen
)
3618 data
->pcie_gen_power_saving
.max
=
3619 ps
->performance_levels
[i
].pcie_gen
;
3621 if (data
->pcie_gen_power_saving
.min
>
3622 ps
->performance_levels
[i
].pcie_gen
)
3623 data
->pcie_gen_power_saving
.min
=
3624 ps
->performance_levels
[i
].pcie_gen
;
3626 if (data
->pcie_lane_power_saving
.max
<
3627 ps
->performance_levels
[i
].pcie_lane
)
3628 data
->pcie_lane_power_saving
.max
=
3629 ps
->performance_levels
[i
].pcie_lane
;
3631 if (data
->pcie_lane_power_saving
.min
>
3632 ps
->performance_levels
[i
].pcie_lane
)
3633 data
->pcie_lane_power_saving
.min
=
3634 ps
->performance_levels
[i
].pcie_lane
;
3645 polaris10_print_current_perforce_level(struct pp_hwmgr
*hwmgr
, struct seq_file
*m
)
3647 uint32_t sclk
, mclk
, activity_percent
;
3649 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
3651 smum_send_msg_to_smc(hwmgr
->smumgr
, PPSMC_MSG_API_GetSclkFrequency
);
3653 sclk
= cgs_read_register(hwmgr
->device
, mmSMC_MSG_ARG_0
);
3655 smum_send_msg_to_smc(hwmgr
->smumgr
, PPSMC_MSG_API_GetMclkFrequency
);
3657 mclk
= cgs_read_register(hwmgr
->device
, mmSMC_MSG_ARG_0
);
3658 seq_printf(m
, "\n [ mclk ]: %u MHz\n\n [ sclk ]: %u MHz\n",
3659 mclk
/ 100, sclk
/ 100);
3661 offset
= data
->soft_regs_start
+ offsetof(SMU74_SoftRegisters
, AverageGraphicsActivity
);
3662 activity_percent
= cgs_read_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
, offset
);
3663 activity_percent
+= 0x80;
3664 activity_percent
>>= 8;
3666 seq_printf(m
, "\n [GPU load]: %u%%\n\n", activity_percent
> 100 ? 100 : activity_percent
);
3668 seq_printf(m
, "uvd %sabled\n", data
->uvd_power_gated
? "dis" : "en");
3670 seq_printf(m
, "vce %sabled\n", data
->vce_power_gated
? "dis" : "en");
3673 static int polaris10_find_dpm_states_clocks_in_dpm_table(struct pp_hwmgr
*hwmgr
, const void *input
)
3675 const struct phm_set_power_state_input
*states
=
3676 (const struct phm_set_power_state_input
*)input
;
3677 const struct polaris10_power_state
*polaris10_ps
=
3678 cast_const_phw_polaris10_power_state(states
->pnew_state
);
3679 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
3680 struct polaris10_single_dpm_table
*sclk_table
= &(data
->dpm_table
.sclk_table
);
3681 uint32_t sclk
= polaris10_ps
->performance_levels
3682 [polaris10_ps
->performance_level_count
- 1].engine_clock
;
3683 struct polaris10_single_dpm_table
*mclk_table
= &(data
->dpm_table
.mclk_table
);
3684 uint32_t mclk
= polaris10_ps
->performance_levels
3685 [polaris10_ps
->performance_level_count
- 1].memory_clock
;
3686 struct PP_Clocks min_clocks
= {0};
3688 struct cgs_display_info info
= {0};
3690 data
->need_update_smu7_dpm_table
= 0;
3692 for (i
= 0; i
< sclk_table
->count
; i
++) {
3693 if (sclk
== sclk_table
->dpm_levels
[i
].value
)
3697 if (i
>= sclk_table
->count
)
3698 data
->need_update_smu7_dpm_table
|= DPMTABLE_OD_UPDATE_SCLK
;
3700 /* TODO: Check SCLK in DAL's minimum clocks
3701 * in case DeepSleep divider update is required.
3703 if (data
->display_timing
.min_clock_in_sr
!= min_clocks
.engineClockInSR
&&
3704 (min_clocks
.engineClockInSR
>= POLARIS10_MINIMUM_ENGINE_CLOCK
||
3705 data
->display_timing
.min_clock_in_sr
>= POLARIS10_MINIMUM_ENGINE_CLOCK
))
3706 data
->need_update_smu7_dpm_table
|= DPMTABLE_UPDATE_SCLK
;
3709 for (i
= 0; i
< mclk_table
->count
; i
++) {
3710 if (mclk
== mclk_table
->dpm_levels
[i
].value
)
3714 if (i
>= mclk_table
->count
)
3715 data
->need_update_smu7_dpm_table
|= DPMTABLE_OD_UPDATE_MCLK
;
3717 cgs_get_active_displays_info(hwmgr
->device
, &info
);
3719 if (data
->display_timing
.num_existing_displays
!= info
.display_count
)
3720 data
->need_update_smu7_dpm_table
|= DPMTABLE_UPDATE_MCLK
;
3725 static uint16_t polaris10_get_maximum_link_speed(struct pp_hwmgr
*hwmgr
,
3726 const struct polaris10_power_state
*polaris10_ps
)
3729 uint32_t sclk
, max_sclk
= 0;
3730 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
3731 struct polaris10_dpm_table
*dpm_table
= &data
->dpm_table
;
3733 for (i
= 0; i
< polaris10_ps
->performance_level_count
; i
++) {
3734 sclk
= polaris10_ps
->performance_levels
[i
].engine_clock
;
3735 if (max_sclk
< sclk
)
3739 for (i
= 0; i
< dpm_table
->sclk_table
.count
; i
++) {
3740 if (dpm_table
->sclk_table
.dpm_levels
[i
].value
== max_sclk
)
3741 return (uint16_t) ((i
>= dpm_table
->pcie_speed_table
.count
) ?
3742 dpm_table
->pcie_speed_table
.dpm_levels
3743 [dpm_table
->pcie_speed_table
.count
- 1].value
:
3744 dpm_table
->pcie_speed_table
.dpm_levels
[i
].value
);
3750 static int polaris10_request_link_speed_change_before_state_change(
3751 struct pp_hwmgr
*hwmgr
, const void *input
)
3753 const struct phm_set_power_state_input
*states
=
3754 (const struct phm_set_power_state_input
*)input
;
3755 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
3756 const struct polaris10_power_state
*polaris10_nps
=
3757 cast_const_phw_polaris10_power_state(states
->pnew_state
);
3758 const struct polaris10_power_state
*polaris10_cps
=
3759 cast_const_phw_polaris10_power_state(states
->pcurrent_state
);
3761 uint16_t target_link_speed
= polaris10_get_maximum_link_speed(hwmgr
, polaris10_nps
);
3762 uint16_t current_link_speed
;
3764 if (data
->force_pcie_gen
== PP_PCIEGenInvalid
)
3765 current_link_speed
= polaris10_get_maximum_link_speed(hwmgr
, polaris10_cps
);
3767 current_link_speed
= data
->force_pcie_gen
;
3769 data
->force_pcie_gen
= PP_PCIEGenInvalid
;
3770 data
->pspp_notify_required
= false;
3772 if (target_link_speed
> current_link_speed
) {
3773 switch (target_link_speed
) {
3775 if (0 == acpi_pcie_perf_request(hwmgr
->device
, PCIE_PERF_REQ_GEN3
, false))
3777 data
->force_pcie_gen
= PP_PCIEGen2
;
3778 if (current_link_speed
== PP_PCIEGen2
)
3781 if (0 == acpi_pcie_perf_request(hwmgr
->device
, PCIE_PERF_REQ_GEN2
, false))
3784 data
->force_pcie_gen
= phm_get_current_pcie_speed(hwmgr
);
3788 if (target_link_speed
< current_link_speed
)
3789 data
->pspp_notify_required
= true;
3795 static int polaris10_freeze_sclk_mclk_dpm(struct pp_hwmgr
*hwmgr
)
3797 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
3799 if (0 == data
->need_update_smu7_dpm_table
)
3802 if ((0 == data
->sclk_dpm_key_disabled
) &&
3803 (data
->need_update_smu7_dpm_table
&
3804 (DPMTABLE_OD_UPDATE_SCLK
+ DPMTABLE_UPDATE_SCLK
))) {
3805 PP_ASSERT_WITH_CODE(true == polaris10_is_dpm_running(hwmgr
),
3806 "Trying to freeze SCLK DPM when DPM is disabled",
3808 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr
->smumgr
,
3809 PPSMC_MSG_SCLKDPM_FreezeLevel
),
3810 "Failed to freeze SCLK DPM during FreezeSclkMclkDPM Function!",
3814 if ((0 == data
->mclk_dpm_key_disabled
) &&
3815 (data
->need_update_smu7_dpm_table
&
3816 DPMTABLE_OD_UPDATE_MCLK
)) {
3817 PP_ASSERT_WITH_CODE(true == polaris10_is_dpm_running(hwmgr
),
3818 "Trying to freeze MCLK DPM when DPM is disabled",
3820 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr
->smumgr
,
3821 PPSMC_MSG_MCLKDPM_FreezeLevel
),
3822 "Failed to freeze MCLK DPM during FreezeSclkMclkDPM Function!",
3829 static int polaris10_populate_and_upload_sclk_mclk_dpm_levels(
3830 struct pp_hwmgr
*hwmgr
, const void *input
)
3833 const struct phm_set_power_state_input
*states
=
3834 (const struct phm_set_power_state_input
*)input
;
3835 const struct polaris10_power_state
*polaris10_ps
=
3836 cast_const_phw_polaris10_power_state(states
->pnew_state
);
3837 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
3838 uint32_t sclk
= polaris10_ps
->performance_levels
3839 [polaris10_ps
->performance_level_count
- 1].engine_clock
;
3840 uint32_t mclk
= polaris10_ps
->performance_levels
3841 [polaris10_ps
->performance_level_count
- 1].memory_clock
;
3842 struct polaris10_dpm_table
*dpm_table
= &data
->dpm_table
;
3844 struct polaris10_dpm_table
*golden_dpm_table
= &data
->golden_dpm_table
;
3845 uint32_t dpm_count
, clock_percent
;
3848 if (0 == data
->need_update_smu7_dpm_table
)
3851 if (data
->need_update_smu7_dpm_table
& DPMTABLE_OD_UPDATE_SCLK
) {
3852 dpm_table
->sclk_table
.dpm_levels
3853 [dpm_table
->sclk_table
.count
- 1].value
= sclk
;
3855 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
, PHM_PlatformCaps_OD6PlusinACSupport
) ||
3856 phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
, PHM_PlatformCaps_OD6PlusinDCSupport
)) {
3857 /* Need to do calculation based on the golden DPM table
3858 * as the Heatmap GPU Clock axis is also based on the default values
3860 PP_ASSERT_WITH_CODE(
3861 (golden_dpm_table
->sclk_table
.dpm_levels
3862 [golden_dpm_table
->sclk_table
.count
- 1].value
!= 0),
3865 dpm_count
= dpm_table
->sclk_table
.count
< 2 ? 0 : dpm_table
->sclk_table
.count
- 2;
3867 for (i
= dpm_count
; i
> 1; i
--) {
3868 if (sclk
> golden_dpm_table
->sclk_table
.dpm_levels
[golden_dpm_table
->sclk_table
.count
-1].value
) {
3871 - golden_dpm_table
->sclk_table
.dpm_levels
[golden_dpm_table
->sclk_table
.count
-1].value
3873 / golden_dpm_table
->sclk_table
.dpm_levels
[golden_dpm_table
->sclk_table
.count
-1].value
;
3875 dpm_table
->sclk_table
.dpm_levels
[i
].value
=
3876 golden_dpm_table
->sclk_table
.dpm_levels
[i
].value
+
3877 (golden_dpm_table
->sclk_table
.dpm_levels
[i
].value
*
3880 } else if (golden_dpm_table
->sclk_table
.dpm_levels
[dpm_table
->sclk_table
.count
-1].value
> sclk
) {
3882 ((golden_dpm_table
->sclk_table
.dpm_levels
[golden_dpm_table
->sclk_table
.count
- 1].value
3884 / golden_dpm_table
->sclk_table
.dpm_levels
[golden_dpm_table
->sclk_table
.count
-1].value
;
3886 dpm_table
->sclk_table
.dpm_levels
[i
].value
=
3887 golden_dpm_table
->sclk_table
.dpm_levels
[i
].value
-
3888 (golden_dpm_table
->sclk_table
.dpm_levels
[i
].value
*
3889 clock_percent
) / 100;
3891 dpm_table
->sclk_table
.dpm_levels
[i
].value
=
3892 golden_dpm_table
->sclk_table
.dpm_levels
[i
].value
;
3897 if (data
->need_update_smu7_dpm_table
& DPMTABLE_OD_UPDATE_MCLK
) {
3898 dpm_table
->mclk_table
.dpm_levels
3899 [dpm_table
->mclk_table
.count
- 1].value
= mclk
;
3901 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
, PHM_PlatformCaps_OD6PlusinACSupport
) ||
3902 phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
, PHM_PlatformCaps_OD6PlusinDCSupport
)) {
3904 PP_ASSERT_WITH_CODE(
3905 (golden_dpm_table
->mclk_table
.dpm_levels
3906 [golden_dpm_table
->mclk_table
.count
-1].value
!= 0),
3909 dpm_count
= dpm_table
->mclk_table
.count
< 2 ? 0 : dpm_table
->mclk_table
.count
- 2;
3910 for (i
= dpm_count
; i
> 1; i
--) {
3911 if (golden_dpm_table
->mclk_table
.dpm_levels
[golden_dpm_table
->mclk_table
.count
-1].value
< mclk
) {
3912 clock_percent
= ((mclk
-
3913 golden_dpm_table
->mclk_table
.dpm_levels
[golden_dpm_table
->mclk_table
.count
-1].value
) * 100)
3914 / golden_dpm_table
->mclk_table
.dpm_levels
[golden_dpm_table
->mclk_table
.count
-1].value
;
3916 dpm_table
->mclk_table
.dpm_levels
[i
].value
=
3917 golden_dpm_table
->mclk_table
.dpm_levels
[i
].value
+
3918 (golden_dpm_table
->mclk_table
.dpm_levels
[i
].value
*
3919 clock_percent
) / 100;
3921 } else if (golden_dpm_table
->mclk_table
.dpm_levels
[dpm_table
->mclk_table
.count
-1].value
> mclk
) {
3923 (golden_dpm_table
->mclk_table
.dpm_levels
[golden_dpm_table
->mclk_table
.count
-1].value
- mclk
)
3925 / golden_dpm_table
->mclk_table
.dpm_levels
[golden_dpm_table
->mclk_table
.count
-1].value
;
3927 dpm_table
->mclk_table
.dpm_levels
[i
].value
=
3928 golden_dpm_table
->mclk_table
.dpm_levels
[i
].value
-
3929 (golden_dpm_table
->mclk_table
.dpm_levels
[i
].value
*
3930 clock_percent
) / 100;
3932 dpm_table
->mclk_table
.dpm_levels
[i
].value
=
3933 golden_dpm_table
->mclk_table
.dpm_levels
[i
].value
;
3938 if (data
->need_update_smu7_dpm_table
&
3939 (DPMTABLE_OD_UPDATE_SCLK
+ DPMTABLE_UPDATE_SCLK
)) {
3940 result
= polaris10_populate_all_graphic_levels(hwmgr
);
3941 PP_ASSERT_WITH_CODE((0 == result
),
3942 "Failed to populate SCLK during PopulateNewDPMClocksStates Function!",
3946 if (data
->need_update_smu7_dpm_table
&
3947 (DPMTABLE_OD_UPDATE_MCLK
+ DPMTABLE_UPDATE_MCLK
)) {
3948 /*populate MCLK dpm table to SMU7 */
3949 result
= polaris10_populate_all_memory_levels(hwmgr
);
3950 PP_ASSERT_WITH_CODE((0 == result
),
3951 "Failed to populate MCLK during PopulateNewDPMClocksStates Function!",
3958 static int polaris10_trim_single_dpm_states(struct pp_hwmgr
*hwmgr
,
3959 struct polaris10_single_dpm_table
*dpm_table
,
3960 uint32_t low_limit
, uint32_t high_limit
)
3963 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
3965 for (i
= 0; i
< dpm_table
->count
; i
++) {
3966 if ((dpm_table
->dpm_levels
[i
].value
< low_limit
)
3967 || (dpm_table
->dpm_levels
[i
].value
> high_limit
))
3968 dpm_table
->dpm_levels
[i
].enabled
= false;
3969 else if (((1 << i
) & data
->disable_dpm_mask
) == 0)
3970 dpm_table
->dpm_levels
[i
].enabled
= false;
3972 dpm_table
->dpm_levels
[i
].enabled
= true;
3978 static int polaris10_trim_dpm_states(struct pp_hwmgr
*hwmgr
,
3979 const struct polaris10_power_state
*polaris10_ps
)
3982 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
3983 uint32_t high_limit_count
;
3985 PP_ASSERT_WITH_CODE((polaris10_ps
->performance_level_count
>= 1),
3986 "power state did not have any performance level",
3989 high_limit_count
= (1 == polaris10_ps
->performance_level_count
) ? 0 : 1;
3991 polaris10_trim_single_dpm_states(hwmgr
,
3992 &(data
->dpm_table
.sclk_table
),
3993 polaris10_ps
->performance_levels
[0].engine_clock
,
3994 polaris10_ps
->performance_levels
[high_limit_count
].engine_clock
);
3996 polaris10_trim_single_dpm_states(hwmgr
,
3997 &(data
->dpm_table
.mclk_table
),
3998 polaris10_ps
->performance_levels
[0].memory_clock
,
3999 polaris10_ps
->performance_levels
[high_limit_count
].memory_clock
);
4004 static int polaris10_generate_dpm_level_enable_mask(
4005 struct pp_hwmgr
*hwmgr
, const void *input
)
4008 const struct phm_set_power_state_input
*states
=
4009 (const struct phm_set_power_state_input
*)input
;
4010 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
4011 const struct polaris10_power_state
*polaris10_ps
=
4012 cast_const_phw_polaris10_power_state(states
->pnew_state
);
4014 result
= polaris10_trim_dpm_states(hwmgr
, polaris10_ps
);
4018 data
->dpm_level_enable_mask
.sclk_dpm_enable_mask
=
4019 phm_get_dpm_level_enable_mask_value(&data
->dpm_table
.sclk_table
);
4020 data
->dpm_level_enable_mask
.mclk_dpm_enable_mask
=
4021 phm_get_dpm_level_enable_mask_value(&data
->dpm_table
.mclk_table
);
4022 data
->dpm_level_enable_mask
.pcie_dpm_enable_mask
=
4023 phm_get_dpm_level_enable_mask_value(&data
->dpm_table
.pcie_speed_table
);
4028 int polaris10_enable_disable_uvd_dpm(struct pp_hwmgr
*hwmgr
, bool enable
)
4030 return smum_send_msg_to_smc(hwmgr
->smumgr
, enable
?
4031 PPSMC_MSG_UVDDPM_Enable
:
4032 PPSMC_MSG_UVDDPM_Disable
);
4035 int polaris10_enable_disable_vce_dpm(struct pp_hwmgr
*hwmgr
, bool enable
)
4037 return smum_send_msg_to_smc(hwmgr
->smumgr
, enable
?
4038 PPSMC_MSG_VCEDPM_Enable
:
4039 PPSMC_MSG_VCEDPM_Disable
);
4042 int polaris10_enable_disable_samu_dpm(struct pp_hwmgr
*hwmgr
, bool enable
)
4044 return smum_send_msg_to_smc(hwmgr
->smumgr
, enable
?
4045 PPSMC_MSG_SAMUDPM_Enable
:
4046 PPSMC_MSG_SAMUDPM_Disable
);
4049 int polaris10_update_uvd_dpm(struct pp_hwmgr
*hwmgr
, bool bgate
)
4051 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
4052 uint32_t mm_boot_level_offset
, mm_boot_level_value
;
4053 struct phm_ppt_v1_information
*table_info
=
4054 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
4057 data
->smc_state_table
.UvdBootLevel
= 0;
4058 if (table_info
->mm_dep_table
->count
> 0)
4059 data
->smc_state_table
.UvdBootLevel
=
4060 (uint8_t) (table_info
->mm_dep_table
->count
- 1);
4061 mm_boot_level_offset
= data
->dpm_table_start
+
4062 offsetof(SMU74_Discrete_DpmTable
, UvdBootLevel
);
4063 mm_boot_level_offset
/= 4;
4064 mm_boot_level_offset
*= 4;
4065 mm_boot_level_value
= cgs_read_ind_register(hwmgr
->device
,
4066 CGS_IND_REG__SMC
, mm_boot_level_offset
);
4067 mm_boot_level_value
&= 0x00FFFFFF;
4068 mm_boot_level_value
|= data
->smc_state_table
.UvdBootLevel
<< 24;
4069 cgs_write_ind_register(hwmgr
->device
,
4070 CGS_IND_REG__SMC
, mm_boot_level_offset
, mm_boot_level_value
);
4072 if (!phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
,
4073 PHM_PlatformCaps_UVDDPM
) ||
4074 phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
,
4075 PHM_PlatformCaps_StablePState
))
4076 smum_send_msg_to_smc_with_parameter(hwmgr
->smumgr
,
4077 PPSMC_MSG_UVDDPM_SetEnabledMask
,
4078 (uint32_t)(1 << data
->smc_state_table
.UvdBootLevel
));
4081 return polaris10_enable_disable_uvd_dpm(hwmgr
, !bgate
);
4084 static int polaris10_update_vce_dpm(struct pp_hwmgr
*hwmgr
, const void *input
)
4086 const struct phm_set_power_state_input
*states
=
4087 (const struct phm_set_power_state_input
*)input
;
4088 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
4089 const struct polaris10_power_state
*polaris10_nps
=
4090 cast_const_phw_polaris10_power_state(states
->pnew_state
);
4091 const struct polaris10_power_state
*polaris10_cps
=
4092 cast_const_phw_polaris10_power_state(states
->pcurrent_state
);
4094 uint32_t mm_boot_level_offset
, mm_boot_level_value
;
4095 struct phm_ppt_v1_information
*table_info
=
4096 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
4098 if (polaris10_nps
->vce_clks
.evclk
> 0 &&
4099 (polaris10_cps
== NULL
|| polaris10_cps
->vce_clks
.evclk
== 0)) {
4101 data
->smc_state_table
.VceBootLevel
=
4102 (uint8_t) (table_info
->mm_dep_table
->count
- 1);
4104 mm_boot_level_offset
= data
->dpm_table_start
+
4105 offsetof(SMU74_Discrete_DpmTable
, VceBootLevel
);
4106 mm_boot_level_offset
/= 4;
4107 mm_boot_level_offset
*= 4;
4108 mm_boot_level_value
= cgs_read_ind_register(hwmgr
->device
,
4109 CGS_IND_REG__SMC
, mm_boot_level_offset
);
4110 mm_boot_level_value
&= 0xFF00FFFF;
4111 mm_boot_level_value
|= data
->smc_state_table
.VceBootLevel
<< 16;
4112 cgs_write_ind_register(hwmgr
->device
,
4113 CGS_IND_REG__SMC
, mm_boot_level_offset
, mm_boot_level_value
);
4115 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
, PHM_PlatformCaps_StablePState
)) {
4116 smum_send_msg_to_smc_with_parameter(hwmgr
->smumgr
,
4117 PPSMC_MSG_VCEDPM_SetEnabledMask
,
4118 (uint32_t)1 << data
->smc_state_table
.VceBootLevel
);
4120 polaris10_enable_disable_vce_dpm(hwmgr
, true);
4121 } else if (polaris10_nps
->vce_clks
.evclk
== 0 &&
4122 polaris10_cps
!= NULL
&&
4123 polaris10_cps
->vce_clks
.evclk
> 0)
4124 polaris10_enable_disable_vce_dpm(hwmgr
, false);
4130 int polaris10_update_samu_dpm(struct pp_hwmgr
*hwmgr
, bool bgate
)
4132 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
4133 uint32_t mm_boot_level_offset
, mm_boot_level_value
;
4134 struct phm_ppt_v1_information
*table_info
=
4135 (struct phm_ppt_v1_information
*)(hwmgr
->pptable
);
4138 data
->smc_state_table
.SamuBootLevel
=
4139 (uint8_t) (table_info
->mm_dep_table
->count
- 1);
4140 mm_boot_level_offset
= data
->dpm_table_start
+
4141 offsetof(SMU74_Discrete_DpmTable
, SamuBootLevel
);
4142 mm_boot_level_offset
/= 4;
4143 mm_boot_level_offset
*= 4;
4144 mm_boot_level_value
= cgs_read_ind_register(hwmgr
->device
,
4145 CGS_IND_REG__SMC
, mm_boot_level_offset
);
4146 mm_boot_level_value
&= 0xFFFFFF00;
4147 mm_boot_level_value
|= data
->smc_state_table
.SamuBootLevel
<< 0;
4148 cgs_write_ind_register(hwmgr
->device
,
4149 CGS_IND_REG__SMC
, mm_boot_level_offset
, mm_boot_level_value
);
4151 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
,
4152 PHM_PlatformCaps_StablePState
))
4153 smum_send_msg_to_smc_with_parameter(hwmgr
->smumgr
,
4154 PPSMC_MSG_SAMUDPM_SetEnabledMask
,
4155 (uint32_t)(1 << data
->smc_state_table
.SamuBootLevel
));
4158 return polaris10_enable_disable_samu_dpm(hwmgr
, !bgate
);
4161 static int polaris10_update_sclk_threshold(struct pp_hwmgr
*hwmgr
)
4163 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
4166 uint32_t low_sclk_interrupt_threshold
= 0;
4168 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
,
4169 PHM_PlatformCaps_SclkThrottleLowNotification
)
4170 && (hwmgr
->gfx_arbiter
.sclk_threshold
!=
4171 data
->low_sclk_interrupt_threshold
)) {
4172 data
->low_sclk_interrupt_threshold
=
4173 hwmgr
->gfx_arbiter
.sclk_threshold
;
4174 low_sclk_interrupt_threshold
=
4175 data
->low_sclk_interrupt_threshold
;
4177 CONVERT_FROM_HOST_TO_SMC_UL(low_sclk_interrupt_threshold
);
4179 result
= polaris10_copy_bytes_to_smc(
4181 data
->dpm_table_start
+
4182 offsetof(SMU74_Discrete_DpmTable
,
4183 LowSclkInterruptThreshold
),
4184 (uint8_t *)&low_sclk_interrupt_threshold
,
4192 static int polaris10_program_mem_timing_parameters(struct pp_hwmgr
*hwmgr
)
4194 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
4196 if (data
->need_update_smu7_dpm_table
&
4197 (DPMTABLE_OD_UPDATE_SCLK
+ DPMTABLE_OD_UPDATE_MCLK
))
4198 return polaris10_program_memory_timing_parameters(hwmgr
);
4203 static int polaris10_unfreeze_sclk_mclk_dpm(struct pp_hwmgr
*hwmgr
)
4205 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
4207 if (0 == data
->need_update_smu7_dpm_table
)
4210 if ((0 == data
->sclk_dpm_key_disabled
) &&
4211 (data
->need_update_smu7_dpm_table
&
4212 (DPMTABLE_OD_UPDATE_SCLK
+ DPMTABLE_UPDATE_SCLK
))) {
4214 PP_ASSERT_WITH_CODE(true == polaris10_is_dpm_running(hwmgr
),
4215 "Trying to Unfreeze SCLK DPM when DPM is disabled",
4217 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr
->smumgr
,
4218 PPSMC_MSG_SCLKDPM_UnfreezeLevel
),
4219 "Failed to unfreeze SCLK DPM during UnFreezeSclkMclkDPM Function!",
4223 if ((0 == data
->mclk_dpm_key_disabled
) &&
4224 (data
->need_update_smu7_dpm_table
& DPMTABLE_OD_UPDATE_MCLK
)) {
4226 PP_ASSERT_WITH_CODE(true == polaris10_is_dpm_running(hwmgr
),
4227 "Trying to Unfreeze MCLK DPM when DPM is disabled",
4229 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr
->smumgr
,
4230 PPSMC_MSG_SCLKDPM_UnfreezeLevel
),
4231 "Failed to unfreeze MCLK DPM during UnFreezeSclkMclkDPM Function!",
4235 data
->need_update_smu7_dpm_table
= 0;
4240 static int polaris10_notify_link_speed_change_after_state_change(
4241 struct pp_hwmgr
*hwmgr
, const void *input
)
4243 const struct phm_set_power_state_input
*states
=
4244 (const struct phm_set_power_state_input
*)input
;
4245 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
4246 const struct polaris10_power_state
*polaris10_ps
=
4247 cast_const_phw_polaris10_power_state(states
->pnew_state
);
4248 uint16_t target_link_speed
= polaris10_get_maximum_link_speed(hwmgr
, polaris10_ps
);
4251 if (data
->pspp_notify_required
) {
4252 if (target_link_speed
== PP_PCIEGen3
)
4253 request
= PCIE_PERF_REQ_GEN3
;
4254 else if (target_link_speed
== PP_PCIEGen2
)
4255 request
= PCIE_PERF_REQ_GEN2
;
4257 request
= PCIE_PERF_REQ_GEN1
;
4259 if (request
== PCIE_PERF_REQ_GEN1
&&
4260 phm_get_current_pcie_speed(hwmgr
) > 0)
4263 if (acpi_pcie_perf_request(hwmgr
->device
, request
, false)) {
4264 if (PP_PCIEGen2
== target_link_speed
)
4265 printk("PSPP request to switch to Gen2 from Gen3 Failed!");
4267 printk("PSPP request to switch to Gen1 from Gen2 Failed!");
4274 static int polaris10_set_power_state_tasks(struct pp_hwmgr
*hwmgr
, const void *input
)
4276 int tmp_result
, result
= 0;
4277 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
4279 tmp_result
= polaris10_find_dpm_states_clocks_in_dpm_table(hwmgr
, input
);
4280 PP_ASSERT_WITH_CODE((0 == tmp_result
),
4281 "Failed to find DPM states clocks in DPM table!",
4282 result
= tmp_result
);
4284 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
,
4285 PHM_PlatformCaps_PCIEPerformanceRequest
)) {
4287 polaris10_request_link_speed_change_before_state_change(hwmgr
, input
);
4288 PP_ASSERT_WITH_CODE((0 == tmp_result
),
4289 "Failed to request link speed change before state change!",
4290 result
= tmp_result
);
4293 tmp_result
= polaris10_freeze_sclk_mclk_dpm(hwmgr
);
4294 PP_ASSERT_WITH_CODE((0 == tmp_result
),
4295 "Failed to freeze SCLK MCLK DPM!", result
= tmp_result
);
4297 tmp_result
= polaris10_populate_and_upload_sclk_mclk_dpm_levels(hwmgr
, input
);
4298 PP_ASSERT_WITH_CODE((0 == tmp_result
),
4299 "Failed to populate and upload SCLK MCLK DPM levels!",
4300 result
= tmp_result
);
4302 tmp_result
= polaris10_generate_dpm_level_enable_mask(hwmgr
, input
);
4303 PP_ASSERT_WITH_CODE((0 == tmp_result
),
4304 "Failed to generate DPM level enabled mask!",
4305 result
= tmp_result
);
4307 tmp_result
= polaris10_update_vce_dpm(hwmgr
, input
);
4308 PP_ASSERT_WITH_CODE((0 == tmp_result
),
4309 "Failed to update VCE DPM!",
4310 result
= tmp_result
);
4312 tmp_result
= polaris10_update_sclk_threshold(hwmgr
);
4313 PP_ASSERT_WITH_CODE((0 == tmp_result
),
4314 "Failed to update SCLK threshold!",
4315 result
= tmp_result
);
4317 tmp_result
= polaris10_program_mem_timing_parameters(hwmgr
);
4318 PP_ASSERT_WITH_CODE((0 == tmp_result
),
4319 "Failed to program memory timing parameters!",
4320 result
= tmp_result
);
4322 tmp_result
= polaris10_unfreeze_sclk_mclk_dpm(hwmgr
);
4323 PP_ASSERT_WITH_CODE((0 == tmp_result
),
4324 "Failed to unfreeze SCLK MCLK DPM!",
4325 result
= tmp_result
);
4327 tmp_result
= polaris10_upload_dpm_level_enable_mask(hwmgr
);
4328 PP_ASSERT_WITH_CODE((0 == tmp_result
),
4329 "Failed to upload DPM level enabled mask!",
4330 result
= tmp_result
);
4332 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
,
4333 PHM_PlatformCaps_PCIEPerformanceRequest
)) {
4335 polaris10_notify_link_speed_change_after_state_change(hwmgr
, input
);
4336 PP_ASSERT_WITH_CODE((0 == tmp_result
),
4337 "Failed to notify link speed change after state change!",
4338 result
= tmp_result
);
4340 data
->apply_optimized_settings
= false;
4344 static int polaris10_set_max_fan_pwm_output(struct pp_hwmgr
*hwmgr
, uint16_t us_max_fan_pwm
)
4346 hwmgr
->thermal_controller
.
4347 advanceFanControlParameters
.usMaxFanPWM
= us_max_fan_pwm
;
4349 if (phm_is_hw_access_blocked(hwmgr
))
4352 return smum_send_msg_to_smc_with_parameter(hwmgr
->smumgr
,
4353 PPSMC_MSG_SetFanPwmMax
, us_max_fan_pwm
);
4356 int polaris10_notify_smc_display_change(struct pp_hwmgr
*hwmgr
, bool has_display
)
4358 PPSMC_Msg msg
= has_display
? (PPSMC_Msg
)PPSMC_HasDisplay
: (PPSMC_Msg
)PPSMC_NoDisplay
;
4360 return (smum_send_msg_to_smc(hwmgr
->smumgr
, msg
) == 0) ? 0 : -1;
4363 int polaris10_notify_smc_display_config_after_ps_adjustment(struct pp_hwmgr
*hwmgr
)
4365 uint32_t num_active_displays
= 0;
4366 struct cgs_display_info info
= {0};
4367 info
.mode_info
= NULL
;
4369 cgs_get_active_displays_info(hwmgr
->device
, &info
);
4371 num_active_displays
= info
.display_count
;
4373 if (num_active_displays
> 1) /* to do && (pHwMgr->pPECI->displayConfiguration.bMultiMonitorInSync != TRUE)) */
4374 polaris10_notify_smc_display_change(hwmgr
, false);
4376 polaris10_notify_smc_display_change(hwmgr
, true);
4382 * Programs the display gap
4384 * @param hwmgr the address of the powerplay hardware manager.
4387 int polaris10_program_display_gap(struct pp_hwmgr
*hwmgr
)
4389 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
4390 uint32_t num_active_displays
= 0;
4391 uint32_t display_gap
= cgs_read_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
, ixCG_DISPLAY_GAP_CNTL
);
4392 uint32_t display_gap2
;
4393 uint32_t pre_vbi_time_in_us
;
4394 uint32_t frame_time_in_us
;
4396 uint32_t refresh_rate
= 0;
4397 struct cgs_display_info info
= {0};
4398 struct cgs_mode_info mode_info
;
4400 info
.mode_info
= &mode_info
;
4402 cgs_get_active_displays_info(hwmgr
->device
, &info
);
4403 num_active_displays
= info
.display_count
;
4405 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
);
4406 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
, ixCG_DISPLAY_GAP_CNTL
, display_gap
);
4408 ref_clock
= mode_info
.ref_clock
;
4409 refresh_rate
= mode_info
.refresh_rate
;
4411 if (0 == refresh_rate
)
4414 frame_time_in_us
= 1000000 / refresh_rate
;
4416 pre_vbi_time_in_us
= frame_time_in_us
- 200 - mode_info
.vblank_time_us
;
4417 display_gap2
= pre_vbi_time_in_us
* (ref_clock
/ 100);
4419 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
, ixCG_DISPLAY_GAP_CNTL2
, display_gap2
);
4421 cgs_write_ind_register(hwmgr
->device
, CGS_IND_REG__SMC
, data
->soft_regs_start
+ offsetof(SMU74_SoftRegisters
, PreVBlankGap
), 0x64);
4423 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
));
4425 polaris10_notify_smc_display_change(hwmgr
, num_active_displays
!= 0);
4431 int polaris10_display_configuration_changed_task(struct pp_hwmgr
*hwmgr
)
4433 return polaris10_program_display_gap(hwmgr
);
4437 * Set maximum target operating fan output RPM
4439 * @param hwmgr: the address of the powerplay hardware manager.
4440 * @param usMaxFanRpm: max operating fan RPM value.
4441 * @return The response that came from the SMC.
4443 static int polaris10_set_max_fan_rpm_output(struct pp_hwmgr
*hwmgr
, uint16_t us_max_fan_rpm
)
4445 hwmgr
->thermal_controller
.
4446 advanceFanControlParameters
.usMaxFanRPM
= us_max_fan_rpm
;
4448 if (phm_is_hw_access_blocked(hwmgr
))
4451 return smum_send_msg_to_smc_with_parameter(hwmgr
->smumgr
,
4452 PPSMC_MSG_SetFanRpmMax
, us_max_fan_rpm
);
4455 int polaris10_register_internal_thermal_interrupt(struct pp_hwmgr
*hwmgr
,
4456 const void *thermal_interrupt_info
)
4461 bool polaris10_check_smc_update_required_for_display_configuration(struct pp_hwmgr
*hwmgr
)
4463 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
4464 bool is_update_required
= false;
4465 struct cgs_display_info info
= {0, 0, NULL
};
4467 cgs_get_active_displays_info(hwmgr
->device
, &info
);
4469 if (data
->display_timing
.num_existing_displays
!= info
.display_count
)
4470 is_update_required
= true;
4471 /* TO DO NEED TO GET DEEP SLEEP CLOCK FROM DAL
4472 if (phm_cap_enabled(hwmgr->hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep)) {
4473 cgs_get_min_clock_settings(hwmgr->device, &min_clocks);
4474 if (min_clocks.engineClockInSR != data->display_timing.minClockInSR &&
4475 (min_clocks.engineClockInSR >= POLARIS10_MINIMUM_ENGINE_CLOCK ||
4476 data->display_timing.minClockInSR >= POLARIS10_MINIMUM_ENGINE_CLOCK))
4477 is_update_required = true;
4479 return is_update_required
;
4482 static inline bool polaris10_are_power_levels_equal(const struct polaris10_performance_level
*pl1
,
4483 const struct polaris10_performance_level
*pl2
)
4485 return ((pl1
->memory_clock
== pl2
->memory_clock
) &&
4486 (pl1
->engine_clock
== pl2
->engine_clock
) &&
4487 (pl1
->pcie_gen
== pl2
->pcie_gen
) &&
4488 (pl1
->pcie_lane
== pl2
->pcie_lane
));
4491 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
)
4493 const struct polaris10_power_state
*psa
= cast_const_phw_polaris10_power_state(pstate1
);
4494 const struct polaris10_power_state
*psb
= cast_const_phw_polaris10_power_state(pstate2
);
4497 if (pstate1
== NULL
|| pstate2
== NULL
|| equal
== NULL
)
4500 /* If the two states don't even have the same number of performance levels they cannot be the same state. */
4501 if (psa
->performance_level_count
!= psb
->performance_level_count
) {
4506 for (i
= 0; i
< psa
->performance_level_count
; i
++) {
4507 if (!polaris10_are_power_levels_equal(&(psa
->performance_levels
[i
]), &(psb
->performance_levels
[i
]))) {
4508 /* If we have found even one performance level pair that is different the states are different. */
4514 /* If all performance levels are the same try to use the UVD clocks to break the tie.*/
4515 *equal
= ((psa
->uvd_clks
.vclk
== psb
->uvd_clks
.vclk
) && (psa
->uvd_clks
.dclk
== psb
->uvd_clks
.dclk
));
4516 *equal
&= ((psa
->vce_clks
.evclk
== psb
->vce_clks
.evclk
) && (psa
->vce_clks
.ecclk
== psb
->vce_clks
.ecclk
));
4517 *equal
&= (psa
->sclk_threshold
== psb
->sclk_threshold
);
4522 int polaris10_upload_mc_firmware(struct pp_hwmgr
*hwmgr
)
4524 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
4526 uint32_t vbios_version
;
4528 /* Read MC indirect register offset 0x9F bits [3:0] to see if VBIOS has already loaded a full version of MC ucode or not.*/
4530 phm_get_mc_microcode_version(hwmgr
);
4531 vbios_version
= hwmgr
->microcode_version_info
.MC
& 0xf;
4532 /* Full version of MC ucode has already been loaded. */
4533 if (vbios_version
== 0) {
4534 data
->need_long_memory_training
= false;
4538 data
->need_long_memory_training
= true;
4541 * PPMCME_FirmwareDescriptorEntry *pfd = NULL;
4542 pfd = &tonga_mcmeFirmware;
4543 if (0 == PHM_READ_FIELD(hwmgr->device, MC_SEQ_SUP_CNTL, RUN))
4544 polaris10_load_mc_microcode(hwmgr, pfd->dpmThreshold,
4545 pfd->cfgArray, pfd->cfgSize, pfd->ioDebugArray,
4546 pfd->ioDebugSize, pfd->ucodeArray, pfd->ucodeSize);
4552 * Read clock related registers.
4554 * @param hwmgr the address of the powerplay hardware manager.
4557 static int polaris10_read_clock_registers(struct pp_hwmgr
*hwmgr
)
4559 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
4561 data
->clock_registers
.vCG_SPLL_FUNC_CNTL
= cgs_read_ind_register(hwmgr
->device
,
4562 CGS_IND_REG__SMC
, ixCG_SPLL_FUNC_CNTL
)
4563 & CG_SPLL_FUNC_CNTL__SPLL_BYPASS_EN_MASK
;
4565 data
->clock_registers
.vCG_SPLL_FUNC_CNTL_2
= cgs_read_ind_register(hwmgr
->device
,
4566 CGS_IND_REG__SMC
, ixCG_SPLL_FUNC_CNTL_2
)
4567 & CG_SPLL_FUNC_CNTL_2__SCLK_MUX_SEL_MASK
;
4569 data
->clock_registers
.vCG_SPLL_FUNC_CNTL_4
= cgs_read_ind_register(hwmgr
->device
,
4570 CGS_IND_REG__SMC
, ixCG_SPLL_FUNC_CNTL_4
)
4571 & CG_SPLL_FUNC_CNTL_4__SPLL_SPARE_MASK
;
4577 * Find out if memory is GDDR5.
4579 * @param hwmgr the address of the powerplay hardware manager.
4582 static int polaris10_get_memory_type(struct pp_hwmgr
*hwmgr
)
4584 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
4587 temp
= cgs_read_register(hwmgr
->device
, mmMC_SEQ_MISC0
);
4589 data
->is_memory_gddr5
= (MC_SEQ_MISC0_GDDR5_VALUE
==
4590 ((temp
& MC_SEQ_MISC0_GDDR5_MASK
) >>
4591 MC_SEQ_MISC0_GDDR5_SHIFT
));
4597 * Enables Dynamic Power Management by SMC
4599 * @param hwmgr the address of the powerplay hardware manager.
4602 static int polaris10_enable_acpi_power_management(struct pp_hwmgr
*hwmgr
)
4604 PHM_WRITE_INDIRECT_FIELD(hwmgr
->device
, CGS_IND_REG__SMC
,
4605 GENERAL_PWRMGT
, STATIC_PM_EN
, 1);
4611 * Initialize PowerGating States for different engines
4613 * @param hwmgr the address of the powerplay hardware manager.
4616 static int polaris10_init_power_gate_state(struct pp_hwmgr
*hwmgr
)
4618 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
4620 data
->uvd_power_gated
= false;
4621 data
->vce_power_gated
= false;
4622 data
->samu_power_gated
= false;
4627 static int polaris10_init_sclk_threshold(struct pp_hwmgr
*hwmgr
)
4629 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
4630 data
->low_sclk_interrupt_threshold
= 0;
4635 int polaris10_setup_asic_task(struct pp_hwmgr
*hwmgr
)
4637 int tmp_result
, result
= 0;
4639 polaris10_upload_mc_firmware(hwmgr
);
4641 tmp_result
= polaris10_read_clock_registers(hwmgr
);
4642 PP_ASSERT_WITH_CODE((0 == tmp_result
),
4643 "Failed to read clock registers!", result
= tmp_result
);
4645 tmp_result
= polaris10_get_memory_type(hwmgr
);
4646 PP_ASSERT_WITH_CODE((0 == tmp_result
),
4647 "Failed to get memory type!", result
= tmp_result
);
4649 tmp_result
= polaris10_enable_acpi_power_management(hwmgr
);
4650 PP_ASSERT_WITH_CODE((0 == tmp_result
),
4651 "Failed to enable ACPI power management!", result
= tmp_result
);
4653 tmp_result
= polaris10_init_power_gate_state(hwmgr
);
4654 PP_ASSERT_WITH_CODE((0 == tmp_result
),
4655 "Failed to init power gate state!", result
= tmp_result
);
4657 tmp_result
= phm_get_mc_microcode_version(hwmgr
);
4658 PP_ASSERT_WITH_CODE((0 == tmp_result
),
4659 "Failed to get MC microcode version!", result
= tmp_result
);
4661 tmp_result
= polaris10_init_sclk_threshold(hwmgr
);
4662 PP_ASSERT_WITH_CODE((0 == tmp_result
),
4663 "Failed to init sclk threshold!", result
= tmp_result
);
4668 static int polaris10_get_pp_table(struct pp_hwmgr
*hwmgr
, char **table
)
4670 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
4672 *table
= (char *)&data
->smc_state_table
;
4674 return sizeof(struct SMU74_Discrete_DpmTable
);
4677 static int polaris10_set_pp_table(struct pp_hwmgr
*hwmgr
, const char *buf
, size_t size
)
4679 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
4681 void *table
= (void *)&data
->smc_state_table
;
4683 memcpy(table
, buf
, size
);
4688 static int polaris10_force_clock_level(struct pp_hwmgr
*hwmgr
,
4689 enum pp_clock_type type
, int level
)
4691 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
4693 if (hwmgr
->dpm_level
!= AMD_DPM_FORCED_LEVEL_MANUAL
)
4698 if (!data
->sclk_dpm_key_disabled
)
4699 smum_send_msg_to_smc_with_parameter(hwmgr
->smumgr
,
4700 PPSMC_MSG_SCLKDPM_SetEnabledMask
,
4704 if (!data
->mclk_dpm_key_disabled
)
4705 smum_send_msg_to_smc_with_parameter(hwmgr
->smumgr
,
4706 PPSMC_MSG_MCLKDPM_SetEnabledMask
,
4710 if (!data
->pcie_dpm_key_disabled
)
4711 smum_send_msg_to_smc_with_parameter(hwmgr
->smumgr
,
4712 PPSMC_MSG_PCIeDPM_ForceLevel
,
4722 static uint16_t polaris10_get_current_pcie_speed(struct pp_hwmgr
*hwmgr
)
4724 uint32_t speedCntl
= 0;
4726 /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
4727 speedCntl
= cgs_read_ind_register(hwmgr
->device
, CGS_IND_REG__PCIE
,
4728 ixPCIE_LC_SPEED_CNTL
);
4729 return((uint16_t)PHM_GET_FIELD(speedCntl
,
4730 PCIE_LC_SPEED_CNTL
, LC_CURRENT_DATA_RATE
));
4733 static int polaris10_print_clock_levels(struct pp_hwmgr
*hwmgr
,
4734 enum pp_clock_type type
, char *buf
)
4736 struct polaris10_hwmgr
*data
= (struct polaris10_hwmgr
*)(hwmgr
->backend
);
4737 struct polaris10_single_dpm_table
*sclk_table
= &(data
->dpm_table
.sclk_table
);
4738 struct polaris10_single_dpm_table
*mclk_table
= &(data
->dpm_table
.mclk_table
);
4739 struct polaris10_single_dpm_table
*pcie_table
= &(data
->dpm_table
.pcie_speed_table
);
4740 int i
, now
, size
= 0;
4741 uint32_t clock
, pcie_speed
;
4745 smum_send_msg_to_smc(hwmgr
->smumgr
, PPSMC_MSG_API_GetSclkFrequency
);
4746 clock
= cgs_read_register(hwmgr
->device
, mmSMC_MSG_ARG_0
);
4748 for (i
= 0; i
< sclk_table
->count
; i
++) {
4749 if (clock
> sclk_table
->dpm_levels
[i
].value
)
4755 for (i
= 0; i
< sclk_table
->count
; i
++)
4756 size
+= sprintf(buf
+ size
, "%d: %uMhz %s\n",
4757 i
, sclk_table
->dpm_levels
[i
].value
/ 100,
4758 (i
== now
) ? "*" : "");
4761 smum_send_msg_to_smc(hwmgr
->smumgr
, PPSMC_MSG_API_GetMclkFrequency
);
4762 clock
= cgs_read_register(hwmgr
->device
, mmSMC_MSG_ARG_0
);
4764 for (i
= 0; i
< mclk_table
->count
; i
++) {
4765 if (clock
> mclk_table
->dpm_levels
[i
].value
)
4771 for (i
= 0; i
< mclk_table
->count
; i
++)
4772 size
+= sprintf(buf
+ size
, "%d: %uMhz %s\n",
4773 i
, mclk_table
->dpm_levels
[i
].value
/ 100,
4774 (i
== now
) ? "*" : "");
4777 pcie_speed
= polaris10_get_current_pcie_speed(hwmgr
);
4778 for (i
= 0; i
< pcie_table
->count
; i
++) {
4779 if (pcie_speed
!= pcie_table
->dpm_levels
[i
].value
)
4785 for (i
= 0; i
< pcie_table
->count
; i
++)
4786 size
+= sprintf(buf
+ size
, "%d: %s %s\n", i
,
4787 (pcie_table
->dpm_levels
[i
].value
== 0) ? "2.5GB, x8" :
4788 (pcie_table
->dpm_levels
[i
].value
== 1) ? "5.0GB, x16" :
4789 (pcie_table
->dpm_levels
[i
].value
== 2) ? "8.0GB, x16" : "",
4790 (i
== now
) ? "*" : "");
4798 static const struct pp_hwmgr_func polaris10_hwmgr_funcs
= {
4799 .backend_init
= &polaris10_hwmgr_backend_init
,
4800 .backend_fini
= &polaris10_hwmgr_backend_fini
,
4801 .asic_setup
= &polaris10_setup_asic_task
,
4802 .dynamic_state_management_enable
= &polaris10_enable_dpm_tasks
,
4803 .apply_state_adjust_rules
= polaris10_apply_state_adjust_rules
,
4804 .force_dpm_level
= &polaris10_force_dpm_level
,
4805 .power_state_set
= polaris10_set_power_state_tasks
,
4806 .get_power_state_size
= polaris10_get_power_state_size
,
4807 .get_mclk
= polaris10_dpm_get_mclk
,
4808 .get_sclk
= polaris10_dpm_get_sclk
,
4809 .patch_boot_state
= polaris10_dpm_patch_boot_state
,
4810 .get_pp_table_entry
= polaris10_get_pp_table_entry
,
4811 .get_num_of_pp_table_entries
= tonga_get_number_of_powerplay_table_entries
,
4812 .print_current_perforce_level
= polaris10_print_current_perforce_level
,
4813 .powerdown_uvd
= polaris10_phm_powerdown_uvd
,
4814 .powergate_uvd
= polaris10_phm_powergate_uvd
,
4815 .powergate_vce
= polaris10_phm_powergate_vce
,
4816 .disable_clock_power_gating
= polaris10_phm_disable_clock_power_gating
,
4817 .update_clock_gatings
= polaris10_phm_update_clock_gatings
,
4818 .notify_smc_display_config_after_ps_adjustment
= polaris10_notify_smc_display_config_after_ps_adjustment
,
4819 .display_config_changed
= polaris10_display_configuration_changed_task
,
4820 .set_max_fan_pwm_output
= polaris10_set_max_fan_pwm_output
,
4821 .set_max_fan_rpm_output
= polaris10_set_max_fan_rpm_output
,
4822 .get_temperature
= polaris10_thermal_get_temperature
,
4823 .stop_thermal_controller
= polaris10_thermal_stop_thermal_controller
,
4824 .get_fan_speed_info
= polaris10_fan_ctrl_get_fan_speed_info
,
4825 .get_fan_speed_percent
= polaris10_fan_ctrl_get_fan_speed_percent
,
4826 .set_fan_speed_percent
= polaris10_fan_ctrl_set_fan_speed_percent
,
4827 .reset_fan_speed_to_default
= polaris10_fan_ctrl_reset_fan_speed_to_default
,
4828 .get_fan_speed_rpm
= polaris10_fan_ctrl_get_fan_speed_rpm
,
4829 .set_fan_speed_rpm
= polaris10_fan_ctrl_set_fan_speed_rpm
,
4830 .uninitialize_thermal_controller
= polaris10_thermal_ctrl_uninitialize_thermal_controller
,
4831 .register_internal_thermal_interrupt
= polaris10_register_internal_thermal_interrupt
,
4832 .check_smc_update_required_for_display_configuration
= polaris10_check_smc_update_required_for_display_configuration
,
4833 .check_states_equal
= polaris10_check_states_equal
,
4834 .get_pp_table
= polaris10_get_pp_table
,
4835 .set_pp_table
= polaris10_set_pp_table
,
4836 .force_clock_level
= polaris10_force_clock_level
,
4837 .print_clock_levels
= polaris10_print_clock_levels
,
4838 .enable_per_cu_power_gating
= polaris10_phm_enable_per_cu_power_gating
,
4841 int polaris10_hwmgr_init(struct pp_hwmgr
*hwmgr
)
4843 struct polaris10_hwmgr
*data
;
4845 data
= kzalloc (sizeof(struct polaris10_hwmgr
), GFP_KERNEL
);
4849 hwmgr
->backend
= data
;
4850 hwmgr
->hwmgr_func
= &polaris10_hwmgr_funcs
;
4851 hwmgr
->pptable_func
= &tonga_pptable_funcs
;
4852 pp_polaris10_thermal_initialize(hwmgr
);