]>
Commit | Line | Data |
---|---|---|
a23eefa2 RZ |
1 | /* |
2 | * Copyright 2015 Advanced Micro Devices, Inc. | |
3 | * | |
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: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | * | |
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. | |
21 | * | |
22 | */ | |
23 | #include <linux/module.h> | |
24 | #include <linux/slab.h> | |
25 | #include <linux/fb.h> | |
ae17c999 | 26 | #include <asm/div64.h> |
a23eefa2 RZ |
27 | #include "linux/delay.h" |
28 | #include "pp_acpi.h" | |
29 | #include "hwmgr.h" | |
2cc0c0b5 FC |
30 | #include "polaris10_hwmgr.h" |
31 | #include "polaris10_powertune.h" | |
32 | #include "polaris10_dyn_defaults.h" | |
33 | #include "polaris10_smumgr.h" | |
a23eefa2 RZ |
34 | #include "pp_debug.h" |
35 | #include "ppatomctrl.h" | |
36 | #include "atombios.h" | |
37 | #include "tonga_pptable.h" | |
38 | #include "pppcielanes.h" | |
39 | #include "amd_pcie_helpers.h" | |
40 | #include "hardwaremanager.h" | |
41 | #include "tonga_processpptables.h" | |
42 | #include "cgs_common.h" | |
43 | #include "smu74.h" | |
44 | #include "smu_ucode_xfer_vi.h" | |
45 | #include "smu74_discrete.h" | |
46 | #include "smu/smu_7_1_3_d.h" | |
47 | #include "smu/smu_7_1_3_sh_mask.h" | |
48 | #include "gmc/gmc_8_1_d.h" | |
49 | #include "gmc/gmc_8_1_sh_mask.h" | |
50 | #include "oss/oss_3_0_d.h" | |
51 | #include "gca/gfx_8_0_d.h" | |
52 | #include "bif/bif_5_0_d.h" | |
53 | #include "bif/bif_5_0_sh_mask.h" | |
54 | #include "gmc/gmc_8_1_d.h" | |
55 | #include "gmc/gmc_8_1_sh_mask.h" | |
56 | #include "bif/bif_5_0_d.h" | |
57 | #include "bif/bif_5_0_sh_mask.h" | |
58 | #include "dce/dce_10_0_d.h" | |
59 | #include "dce/dce_10_0_sh_mask.h" | |
60 | ||
2cc0c0b5 FC |
61 | #include "polaris10_thermal.h" |
62 | #include "polaris10_clockpowergating.h" | |
eede5262 | 63 | |
a23eefa2 RZ |
64 | #define MC_CG_ARB_FREQ_F0 0x0a |
65 | #define MC_CG_ARB_FREQ_F1 0x0b | |
66 | #define MC_CG_ARB_FREQ_F2 0x0c | |
67 | #define MC_CG_ARB_FREQ_F3 0x0d | |
68 | ||
69 | #define MC_CG_SEQ_DRAMCONF_S0 0x05 | |
70 | #define MC_CG_SEQ_DRAMCONF_S1 0x06 | |
71 | #define MC_CG_SEQ_YCLK_SUSPEND 0x04 | |
72 | #define MC_CG_SEQ_YCLK_RESUME 0x0a | |
73 | ||
74 | ||
75 | #define SMC_RAM_END 0x40000 | |
76 | ||
77 | #define SMC_CG_IND_START 0xc0030000 | |
78 | #define SMC_CG_IND_END 0xc0040000 | |
79 | ||
80 | #define VOLTAGE_SCALE 4 | |
81 | #define VOLTAGE_VID_OFFSET_SCALE1 625 | |
82 | #define VOLTAGE_VID_OFFSET_SCALE2 100 | |
83 | ||
84 | #define VDDC_VDDCI_DELTA 200 | |
85 | ||
86 | #define MEM_FREQ_LOW_LATENCY 25000 | |
87 | #define MEM_FREQ_HIGH_LATENCY 80000 | |
88 | ||
89 | #define MEM_LATENCY_HIGH 45 | |
90 | #define MEM_LATENCY_LOW 35 | |
91 | #define MEM_LATENCY_ERR 0xFFFF | |
92 | ||
93 | #define MC_SEQ_MISC0_GDDR5_SHIFT 28 | |
94 | #define MC_SEQ_MISC0_GDDR5_MASK 0xf0000000 | |
95 | #define MC_SEQ_MISC0_GDDR5_VALUE 5 | |
96 | ||
97 | ||
98 | #define PCIE_BUS_CLK 10000 | |
99 | #define TCLK (PCIE_BUS_CLK / 10) | |
100 | ||
101 | ||
2cc0c0b5 | 102 | uint16_t polaris10_clock_stretcher_lookup_table[2][4] = { {600, 1050, 3, 0}, |
a23eefa2 RZ |
103 | {600, 1050, 6, 1} }; |
104 | ||
105 | /* [FF, SS] type, [] 4 voltage ranges, and [Floor Freq, Boundary Freq, VID min , VID max] */ | |
2cc0c0b5 | 106 | uint32_t polaris10_clock_stretcher_ddt_table[2][4][4] = { { {265, 529, 120, 128}, {325, 650, 96, 119}, {430, 860, 32, 95}, {0, 0, 0, 31} }, |
a23eefa2 RZ |
107 | { {275, 550, 104, 112}, {319, 638, 96, 103}, {360, 720, 64, 95}, {384, 768, 32, 63} } }; |
108 | ||
109 | /* [Use_For_Low_freq] value, [0%, 5%, 10%, 7.14%, 14.28%, 20%] (coming from PWR_CKS_CNTL.stretch_amount reg spec) */ | |
2cc0c0b5 | 110 | uint8_t polaris10_clock_stretch_amount_conversion[2][6] = { {0, 1, 3, 2, 4, 5}, |
a23eefa2 RZ |
111 | {0, 2, 4, 5, 6, 5} }; |
112 | ||
113 | /** Values for the CG_THERMAL_CTRL::DPM_EVENT_SRC field. */ | |
114 | enum DPM_EVENT_SRC { | |
115 | DPM_EVENT_SRC_ANALOG = 0, | |
116 | DPM_EVENT_SRC_EXTERNAL = 1, | |
117 | DPM_EVENT_SRC_DIGITAL = 2, | |
118 | DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3, | |
119 | DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL = 4 | |
120 | }; | |
121 | ||
2cc0c0b5 | 122 | const unsigned long PhwPolaris10_Magic = (unsigned long)(PHM_VIslands_Magic); |
a23eefa2 | 123 | |
2cc0c0b5 | 124 | struct polaris10_power_state *cast_phw_polaris10_power_state( |
a23eefa2 RZ |
125 | struct pp_hw_power_state *hw_ps) |
126 | { | |
2cc0c0b5 | 127 | PP_ASSERT_WITH_CODE((PhwPolaris10_Magic == hw_ps->magic), |
a23eefa2 RZ |
128 | "Invalid Powerstate Type!", |
129 | return NULL); | |
130 | ||
2cc0c0b5 | 131 | return (struct polaris10_power_state *)hw_ps; |
a23eefa2 RZ |
132 | } |
133 | ||
2cc0c0b5 | 134 | const struct polaris10_power_state *cast_const_phw_polaris10_power_state( |
a23eefa2 RZ |
135 | const struct pp_hw_power_state *hw_ps) |
136 | { | |
2cc0c0b5 | 137 | PP_ASSERT_WITH_CODE((PhwPolaris10_Magic == hw_ps->magic), |
a23eefa2 RZ |
138 | "Invalid Powerstate Type!", |
139 | return NULL); | |
140 | ||
2cc0c0b5 | 141 | return (const struct polaris10_power_state *)hw_ps; |
a23eefa2 RZ |
142 | } |
143 | ||
2cc0c0b5 | 144 | static bool polaris10_is_dpm_running(struct pp_hwmgr *hwmgr) |
a23eefa2 RZ |
145 | { |
146 | return (1 == PHM_READ_INDIRECT_FIELD(hwmgr->device, | |
147 | CGS_IND_REG__SMC, FEATURE_STATUS, VOLTAGE_CONTROLLER_ON)) | |
148 | ? true : false; | |
149 | } | |
150 | ||
151 | /** | |
152 | * Find the MC microcode version and store it in the HwMgr struct | |
153 | * | |
154 | * @param hwmgr the address of the powerplay hardware manager. | |
155 | * @return always 0 | |
156 | */ | |
157 | int phm_get_mc_microcode_version (struct pp_hwmgr *hwmgr) | |
158 | { | |
159 | cgs_write_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_INDEX, 0x9F); | |
160 | ||
161 | hwmgr->microcode_version_info.MC = cgs_read_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_DATA); | |
162 | ||
163 | return 0; | |
164 | } | |
165 | ||
166 | uint16_t phm_get_current_pcie_speed(struct pp_hwmgr *hwmgr) | |
167 | { | |
168 | uint32_t speedCntl = 0; | |
169 | ||
170 | /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */ | |
171 | speedCntl = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__PCIE, | |
172 | ixPCIE_LC_SPEED_CNTL); | |
173 | return((uint16_t)PHM_GET_FIELD(speedCntl, | |
174 | PCIE_LC_SPEED_CNTL, LC_CURRENT_DATA_RATE)); | |
175 | } | |
176 | ||
177 | int phm_get_current_pcie_lane_number(struct pp_hwmgr *hwmgr) | |
178 | { | |
179 | uint32_t link_width; | |
180 | ||
181 | /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */ | |
182 | link_width = PHM_READ_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE, | |
183 | PCIE_LC_LINK_WIDTH_CNTL, LC_LINK_WIDTH_RD); | |
184 | ||
185 | PP_ASSERT_WITH_CODE((7 >= link_width), | |
186 | "Invalid PCIe lane width!", return 0); | |
187 | ||
188 | return decode_pcie_lane_width(link_width); | |
189 | } | |
190 | ||
191 | void phm_apply_dal_min_voltage_request(struct pp_hwmgr *hwmgr) | |
192 | { | |
193 | struct phm_ppt_v1_information *table_info = | |
194 | (struct phm_ppt_v1_information *)hwmgr->pptable; | |
195 | struct phm_clock_voltage_dependency_table *table = | |
196 | table_info->vddc_dep_on_dal_pwrl; | |
197 | struct phm_ppt_v1_clock_voltage_dependency_table *vddc_table; | |
198 | enum PP_DAL_POWERLEVEL dal_power_level = hwmgr->dal_power_level; | |
199 | uint32_t req_vddc = 0, req_volt, i; | |
200 | ||
201 | if (!table && !(dal_power_level >= PP_DAL_POWERLEVEL_ULTRALOW && | |
202 | dal_power_level <= PP_DAL_POWERLEVEL_PERFORMANCE)) | |
203 | return; | |
204 | ||
205 | for (i = 0; i < table->count; i++) { | |
206 | if (dal_power_level == table->entries[i].clk) { | |
207 | req_vddc = table->entries[i].v; | |
208 | break; | |
209 | } | |
210 | } | |
211 | ||
212 | vddc_table = table_info->vdd_dep_on_sclk; | |
213 | for (i = 0; i < vddc_table->count; i++) { | |
214 | if (req_vddc <= vddc_table->entries[i].vddc) { | |
215 | req_volt = (((uint32_t)vddc_table->entries[i].vddc) * VOLTAGE_SCALE) | |
216 | << VDDC_SHIFT; | |
217 | smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, | |
218 | PPSMC_MSG_VddC_Request, req_volt); | |
219 | return; | |
220 | } | |
221 | } | |
222 | printk(KERN_ERR "DAL requested level can not" | |
223 | " found a available voltage in VDDC DPM Table \n"); | |
224 | } | |
225 | ||
e85c7d66 | 226 | /** |
227 | * Enable voltage control | |
228 | * | |
229 | * @param pHwMgr the address of the powerplay hardware manager. | |
230 | * @return always PP_Result_OK | |
231 | */ | |
2cc0c0b5 | 232 | int polaris10_enable_smc_voltage_controller(struct pp_hwmgr *hwmgr) |
e85c7d66 | 233 | { |
234 | PP_ASSERT_WITH_CODE( | |
235 | (hwmgr->smumgr->smumgr_funcs->send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_Voltage_Cntl_Enable) == 0), | |
236 | "Failed to enable voltage DPM during DPM Start Function!", | |
237 | return 1; | |
238 | ); | |
239 | ||
240 | return 0; | |
241 | } | |
a23eefa2 RZ |
242 | |
243 | /** | |
244 | * Checks if we want to support voltage control | |
245 | * | |
246 | * @param hwmgr the address of the powerplay hardware manager. | |
247 | */ | |
2cc0c0b5 | 248 | static bool polaris10_voltage_control(const struct pp_hwmgr *hwmgr) |
a23eefa2 | 249 | { |
2cc0c0b5 FC |
250 | const struct polaris10_hwmgr *data = |
251 | (const struct polaris10_hwmgr *)(hwmgr->backend); | |
a23eefa2 | 252 | |
2cc0c0b5 | 253 | return (POLARIS10_VOLTAGE_CONTROL_NONE != data->voltage_control); |
a23eefa2 RZ |
254 | } |
255 | ||
256 | /** | |
257 | * Enable voltage control | |
258 | * | |
259 | * @param hwmgr the address of the powerplay hardware manager. | |
260 | * @return always 0 | |
261 | */ | |
2cc0c0b5 | 262 | static int polaris10_enable_voltage_control(struct pp_hwmgr *hwmgr) |
a23eefa2 RZ |
263 | { |
264 | /* enable voltage control */ | |
265 | PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, | |
266 | GENERAL_PWRMGT, VOLT_PWRMGT_EN, 1); | |
267 | ||
268 | return 0; | |
269 | } | |
270 | ||
271 | /** | |
272 | * Create Voltage Tables. | |
273 | * | |
274 | * @param hwmgr the address of the powerplay hardware manager. | |
275 | * @return always 0 | |
276 | */ | |
2cc0c0b5 | 277 | static int polaris10_construct_voltage_tables(struct pp_hwmgr *hwmgr) |
a23eefa2 | 278 | { |
2cc0c0b5 | 279 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
280 | struct phm_ppt_v1_information *table_info = |
281 | (struct phm_ppt_v1_information *)hwmgr->pptable; | |
282 | int result; | |
283 | ||
2cc0c0b5 | 284 | if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) { |
a23eefa2 RZ |
285 | result = atomctrl_get_voltage_table_v3(hwmgr, |
286 | VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT, | |
287 | &(data->mvdd_voltage_table)); | |
288 | PP_ASSERT_WITH_CODE((0 == result), | |
289 | "Failed to retrieve MVDD table.", | |
290 | return result); | |
2cc0c0b5 | 291 | } else if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) { |
a23eefa2 RZ |
292 | result = phm_get_svi2_mvdd_voltage_table(&(data->mvdd_voltage_table), |
293 | table_info->vdd_dep_on_mclk); | |
294 | PP_ASSERT_WITH_CODE((0 == result), | |
295 | "Failed to retrieve SVI2 MVDD table from dependancy table.", | |
296 | return result;); | |
297 | } | |
298 | ||
2cc0c0b5 | 299 | if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) { |
a23eefa2 RZ |
300 | result = atomctrl_get_voltage_table_v3(hwmgr, |
301 | VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT, | |
302 | &(data->vddci_voltage_table)); | |
303 | PP_ASSERT_WITH_CODE((0 == result), | |
304 | "Failed to retrieve VDDCI table.", | |
305 | return result); | |
2cc0c0b5 | 306 | } else if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) { |
a23eefa2 RZ |
307 | result = phm_get_svi2_vddci_voltage_table(&(data->vddci_voltage_table), |
308 | table_info->vdd_dep_on_mclk); | |
309 | PP_ASSERT_WITH_CODE((0 == result), | |
310 | "Failed to retrieve SVI2 VDDCI table from dependancy table.", | |
311 | return result); | |
312 | } | |
313 | ||
2cc0c0b5 | 314 | if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) { |
a23eefa2 RZ |
315 | result = phm_get_svi2_vdd_voltage_table(&(data->vddc_voltage_table), |
316 | table_info->vddc_lookup_table); | |
317 | PP_ASSERT_WITH_CODE((0 == result), | |
318 | "Failed to retrieve SVI2 VDDC table from lookup table.", | |
319 | return result); | |
320 | } | |
321 | ||
322 | PP_ASSERT_WITH_CODE( | |
323 | (data->vddc_voltage_table.count <= (SMU74_MAX_LEVELS_VDDC)), | |
324 | "Too many voltage values for VDDC. Trimming to fit state table.", | |
325 | phm_trim_voltage_table_to_fit_state_table(SMU74_MAX_LEVELS_VDDC, | |
326 | &(data->vddc_voltage_table))); | |
327 | ||
328 | PP_ASSERT_WITH_CODE( | |
329 | (data->vddci_voltage_table.count <= (SMU74_MAX_LEVELS_VDDCI)), | |
330 | "Too many voltage values for VDDCI. Trimming to fit state table.", | |
331 | phm_trim_voltage_table_to_fit_state_table(SMU74_MAX_LEVELS_VDDCI, | |
332 | &(data->vddci_voltage_table))); | |
333 | ||
334 | PP_ASSERT_WITH_CODE( | |
335 | (data->mvdd_voltage_table.count <= (SMU74_MAX_LEVELS_MVDD)), | |
336 | "Too many voltage values for MVDD. Trimming to fit state table.", | |
337 | phm_trim_voltage_table_to_fit_state_table(SMU74_MAX_LEVELS_MVDD, | |
338 | &(data->mvdd_voltage_table))); | |
339 | ||
340 | return 0; | |
341 | } | |
342 | ||
343 | /** | |
344 | * Programs static screed detection parameters | |
345 | * | |
346 | * @param hwmgr the address of the powerplay hardware manager. | |
347 | * @return always 0 | |
348 | */ | |
2cc0c0b5 | 349 | static int polaris10_program_static_screen_threshold_parameters( |
a23eefa2 RZ |
350 | struct pp_hwmgr *hwmgr) |
351 | { | |
2cc0c0b5 | 352 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
353 | |
354 | /* Set static screen threshold unit */ | |
355 | PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, | |
356 | CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD_UNIT, | |
357 | data->static_screen_threshold_unit); | |
358 | /* Set static screen threshold */ | |
359 | PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, | |
360 | CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD, | |
361 | data->static_screen_threshold); | |
362 | ||
363 | return 0; | |
364 | } | |
365 | ||
366 | /** | |
367 | * Setup display gap for glitch free memory clock switching. | |
368 | * | |
369 | * @param hwmgr the address of the powerplay hardware manager. | |
370 | * @return always 0 | |
371 | */ | |
2cc0c0b5 | 372 | static int polaris10_enable_display_gap(struct pp_hwmgr *hwmgr) |
a23eefa2 RZ |
373 | { |
374 | uint32_t display_gap = | |
375 | cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
376 | ixCG_DISPLAY_GAP_CNTL); | |
377 | ||
378 | display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL, | |
379 | DISP_GAP, DISPLAY_GAP_IGNORE); | |
380 | ||
381 | display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL, | |
382 | DISP_GAP_MCHG, DISPLAY_GAP_VBLANK); | |
383 | ||
384 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
385 | ixCG_DISPLAY_GAP_CNTL, display_gap); | |
386 | ||
387 | return 0; | |
388 | } | |
389 | ||
390 | /** | |
391 | * Programs activity state transition voting clients | |
392 | * | |
393 | * @param hwmgr the address of the powerplay hardware manager. | |
394 | * @return always 0 | |
395 | */ | |
2cc0c0b5 | 396 | static int polaris10_program_voting_clients(struct pp_hwmgr *hwmgr) |
a23eefa2 | 397 | { |
2cc0c0b5 | 398 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
399 | |
400 | /* Clear reset for voting clients before enabling DPM */ | |
401 | PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, | |
402 | SCLK_PWRMGT_CNTL, RESET_SCLK_CNT, 0); | |
403 | PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, | |
404 | SCLK_PWRMGT_CNTL, RESET_BUSY_CNT, 0); | |
405 | ||
406 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
407 | ixCG_FREQ_TRAN_VOTING_0, data->voting_rights_clients0); | |
408 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
409 | ixCG_FREQ_TRAN_VOTING_1, data->voting_rights_clients1); | |
410 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
411 | ixCG_FREQ_TRAN_VOTING_2, data->voting_rights_clients2); | |
412 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
413 | ixCG_FREQ_TRAN_VOTING_3, data->voting_rights_clients3); | |
414 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
415 | ixCG_FREQ_TRAN_VOTING_4, data->voting_rights_clients4); | |
416 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
417 | ixCG_FREQ_TRAN_VOTING_5, data->voting_rights_clients5); | |
418 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
419 | ixCG_FREQ_TRAN_VOTING_6, data->voting_rights_clients6); | |
420 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
421 | ixCG_FREQ_TRAN_VOTING_7, data->voting_rights_clients7); | |
422 | ||
423 | return 0; | |
424 | } | |
425 | ||
426 | /** | |
427 | * Get the location of various tables inside the FW image. | |
428 | * | |
429 | * @param hwmgr the address of the powerplay hardware manager. | |
430 | * @return always 0 | |
431 | */ | |
2cc0c0b5 | 432 | static int polaris10_process_firmware_header(struct pp_hwmgr *hwmgr) |
a23eefa2 | 433 | { |
2cc0c0b5 FC |
434 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
435 | struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smumgr->backend); | |
a23eefa2 RZ |
436 | uint32_t tmp; |
437 | int result; | |
438 | bool error = false; | |
439 | ||
2cc0c0b5 | 440 | result = polaris10_read_smc_sram_dword(hwmgr->smumgr, |
a23eefa2 RZ |
441 | SMU7_FIRMWARE_HEADER_LOCATION + |
442 | offsetof(SMU74_Firmware_Header, DpmTable), | |
443 | &tmp, data->sram_end); | |
444 | ||
445 | if (0 == result) | |
446 | data->dpm_table_start = tmp; | |
447 | ||
448 | error |= (0 != result); | |
449 | ||
2cc0c0b5 | 450 | result = polaris10_read_smc_sram_dword(hwmgr->smumgr, |
a23eefa2 RZ |
451 | SMU7_FIRMWARE_HEADER_LOCATION + |
452 | offsetof(SMU74_Firmware_Header, SoftRegisters), | |
453 | &tmp, data->sram_end); | |
454 | ||
455 | if (!result) { | |
456 | data->soft_regs_start = tmp; | |
457 | smu_data->soft_regs_start = tmp; | |
458 | } | |
459 | ||
460 | error |= (0 != result); | |
461 | ||
2cc0c0b5 | 462 | result = polaris10_read_smc_sram_dword(hwmgr->smumgr, |
a23eefa2 RZ |
463 | SMU7_FIRMWARE_HEADER_LOCATION + |
464 | offsetof(SMU74_Firmware_Header, mcRegisterTable), | |
465 | &tmp, data->sram_end); | |
466 | ||
467 | if (!result) | |
468 | data->mc_reg_table_start = tmp; | |
469 | ||
2cc0c0b5 | 470 | result = polaris10_read_smc_sram_dword(hwmgr->smumgr, |
a23eefa2 RZ |
471 | SMU7_FIRMWARE_HEADER_LOCATION + |
472 | offsetof(SMU74_Firmware_Header, FanTable), | |
473 | &tmp, data->sram_end); | |
474 | ||
475 | if (!result) | |
476 | data->fan_table_start = tmp; | |
477 | ||
478 | error |= (0 != result); | |
479 | ||
2cc0c0b5 | 480 | result = polaris10_read_smc_sram_dword(hwmgr->smumgr, |
a23eefa2 RZ |
481 | SMU7_FIRMWARE_HEADER_LOCATION + |
482 | offsetof(SMU74_Firmware_Header, mcArbDramTimingTable), | |
483 | &tmp, data->sram_end); | |
484 | ||
485 | if (!result) | |
486 | data->arb_table_start = tmp; | |
487 | ||
488 | error |= (0 != result); | |
489 | ||
2cc0c0b5 | 490 | result = polaris10_read_smc_sram_dword(hwmgr->smumgr, |
a23eefa2 RZ |
491 | SMU7_FIRMWARE_HEADER_LOCATION + |
492 | offsetof(SMU74_Firmware_Header, Version), | |
493 | &tmp, data->sram_end); | |
494 | ||
495 | if (!result) | |
496 | hwmgr->microcode_version_info.SMC = tmp; | |
497 | ||
498 | error |= (0 != result); | |
499 | ||
500 | return error ? -1 : 0; | |
501 | } | |
502 | ||
503 | /* Copy one arb setting to another and then switch the active set. | |
504 | * arb_src and arb_dest is one of the MC_CG_ARB_FREQ_Fx constants. | |
505 | */ | |
2cc0c0b5 | 506 | static int polaris10_copy_and_switch_arb_sets(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
507 | uint32_t arb_src, uint32_t arb_dest) |
508 | { | |
509 | uint32_t mc_arb_dram_timing; | |
510 | uint32_t mc_arb_dram_timing2; | |
511 | uint32_t burst_time; | |
512 | uint32_t mc_cg_config; | |
513 | ||
514 | switch (arb_src) { | |
515 | case MC_CG_ARB_FREQ_F0: | |
516 | mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING); | |
517 | mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2); | |
518 | burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0); | |
519 | break; | |
520 | case MC_CG_ARB_FREQ_F1: | |
521 | mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1); | |
522 | mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1); | |
523 | burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1); | |
524 | break; | |
525 | default: | |
526 | return -EINVAL; | |
527 | } | |
528 | ||
529 | switch (arb_dest) { | |
530 | case MC_CG_ARB_FREQ_F0: | |
531 | cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING, mc_arb_dram_timing); | |
532 | cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2, mc_arb_dram_timing2); | |
533 | PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0, burst_time); | |
534 | break; | |
535 | case MC_CG_ARB_FREQ_F1: | |
536 | cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1, mc_arb_dram_timing); | |
537 | cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1, mc_arb_dram_timing2); | |
538 | PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1, burst_time); | |
539 | break; | |
540 | default: | |
541 | return -EINVAL; | |
542 | } | |
543 | ||
544 | mc_cg_config = cgs_read_register(hwmgr->device, mmMC_CG_CONFIG); | |
545 | mc_cg_config |= 0x0000000F; | |
546 | cgs_write_register(hwmgr->device, mmMC_CG_CONFIG, mc_cg_config); | |
547 | PHM_WRITE_FIELD(hwmgr->device, MC_ARB_CG, CG_ARB_REQ, arb_dest); | |
548 | ||
549 | return 0; | |
550 | } | |
551 | ||
552 | /** | |
553 | * Initial switch from ARB F0->F1 | |
554 | * | |
555 | * @param hwmgr the address of the powerplay hardware manager. | |
556 | * @return always 0 | |
557 | * This function is to be called from the SetPowerState table. | |
558 | */ | |
2cc0c0b5 | 559 | static int polaris10_initial_switch_from_arbf0_to_f1(struct pp_hwmgr *hwmgr) |
a23eefa2 | 560 | { |
2cc0c0b5 | 561 | return polaris10_copy_and_switch_arb_sets(hwmgr, |
a23eefa2 RZ |
562 | MC_CG_ARB_FREQ_F0, MC_CG_ARB_FREQ_F1); |
563 | } | |
564 | ||
2cc0c0b5 | 565 | static int polaris10_setup_default_pcie_table(struct pp_hwmgr *hwmgr) |
a23eefa2 | 566 | { |
2cc0c0b5 | 567 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
568 | struct phm_ppt_v1_information *table_info = |
569 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
570 | struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table; | |
571 | uint32_t i, max_entry; | |
572 | ||
573 | PP_ASSERT_WITH_CODE((data->use_pcie_performance_levels || | |
574 | data->use_pcie_power_saving_levels), "No pcie performance levels!", | |
575 | return -EINVAL); | |
576 | ||
577 | if (data->use_pcie_performance_levels && | |
578 | !data->use_pcie_power_saving_levels) { | |
579 | data->pcie_gen_power_saving = data->pcie_gen_performance; | |
580 | data->pcie_lane_power_saving = data->pcie_lane_performance; | |
581 | } else if (!data->use_pcie_performance_levels && | |
582 | data->use_pcie_power_saving_levels) { | |
583 | data->pcie_gen_performance = data->pcie_gen_power_saving; | |
584 | data->pcie_lane_performance = data->pcie_lane_power_saving; | |
585 | } | |
586 | ||
587 | phm_reset_single_dpm_table(&data->dpm_table.pcie_speed_table, | |
588 | SMU74_MAX_LEVELS_LINK, | |
589 | MAX_REGULAR_DPM_NUMBER); | |
590 | ||
591 | if (pcie_table != NULL) { | |
592 | /* max_entry is used to make sure we reserve one PCIE level | |
593 | * for boot level (fix for A+A PSPP issue). | |
594 | * If PCIE table from PPTable have ULV entry + 8 entries, | |
595 | * then ignore the last entry.*/ | |
596 | max_entry = (SMU74_MAX_LEVELS_LINK < pcie_table->count) ? | |
597 | SMU74_MAX_LEVELS_LINK : pcie_table->count; | |
598 | for (i = 1; i < max_entry; i++) { | |
599 | phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, i - 1, | |
600 | get_pcie_gen_support(data->pcie_gen_cap, | |
601 | pcie_table->entries[i].gen_speed), | |
602 | get_pcie_lane_support(data->pcie_lane_cap, | |
603 | pcie_table->entries[i].lane_width)); | |
604 | } | |
605 | data->dpm_table.pcie_speed_table.count = max_entry - 1; | |
e85c7d66 | 606 | |
607 | /* Setup BIF_SCLK levels */ | |
608 | for (i = 0; i < max_entry; i++) | |
609 | data->bif_sclk_table[i] = pcie_table->entries[i].pcie_sclk; | |
a23eefa2 RZ |
610 | } else { |
611 | /* Hardcode Pcie Table */ | |
612 | phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 0, | |
613 | get_pcie_gen_support(data->pcie_gen_cap, | |
614 | PP_Min_PCIEGen), | |
615 | get_pcie_lane_support(data->pcie_lane_cap, | |
616 | PP_Max_PCIELane)); | |
617 | phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 1, | |
618 | get_pcie_gen_support(data->pcie_gen_cap, | |
619 | PP_Min_PCIEGen), | |
620 | get_pcie_lane_support(data->pcie_lane_cap, | |
621 | PP_Max_PCIELane)); | |
622 | phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 2, | |
623 | get_pcie_gen_support(data->pcie_gen_cap, | |
624 | PP_Max_PCIEGen), | |
625 | get_pcie_lane_support(data->pcie_lane_cap, | |
626 | PP_Max_PCIELane)); | |
627 | phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 3, | |
628 | get_pcie_gen_support(data->pcie_gen_cap, | |
629 | PP_Max_PCIEGen), | |
630 | get_pcie_lane_support(data->pcie_lane_cap, | |
631 | PP_Max_PCIELane)); | |
632 | phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 4, | |
633 | get_pcie_gen_support(data->pcie_gen_cap, | |
634 | PP_Max_PCIEGen), | |
635 | get_pcie_lane_support(data->pcie_lane_cap, | |
636 | PP_Max_PCIELane)); | |
637 | phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 5, | |
638 | get_pcie_gen_support(data->pcie_gen_cap, | |
639 | PP_Max_PCIEGen), | |
640 | get_pcie_lane_support(data->pcie_lane_cap, | |
641 | PP_Max_PCIELane)); | |
642 | ||
643 | data->dpm_table.pcie_speed_table.count = 6; | |
644 | } | |
645 | /* Populate last level for boot PCIE level, but do not increment count. */ | |
646 | phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, | |
647 | data->dpm_table.pcie_speed_table.count, | |
648 | get_pcie_gen_support(data->pcie_gen_cap, | |
649 | PP_Min_PCIEGen), | |
650 | get_pcie_lane_support(data->pcie_lane_cap, | |
651 | PP_Max_PCIELane)); | |
652 | ||
653 | return 0; | |
654 | } | |
655 | ||
656 | /* | |
657 | * This function is to initalize all DPM state tables | |
658 | * for SMU7 based on the dependency table. | |
659 | * Dynamic state patching function will then trim these | |
660 | * state tables to the allowed range based | |
661 | * on the power policy or external client requests, | |
662 | * such as UVD request, etc. | |
663 | */ | |
2cc0c0b5 | 664 | int polaris10_setup_default_dpm_tables(struct pp_hwmgr *hwmgr) |
a23eefa2 | 665 | { |
2cc0c0b5 | 666 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
667 | struct phm_ppt_v1_information *table_info = |
668 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
669 | uint32_t i; | |
670 | ||
671 | struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table = | |
672 | table_info->vdd_dep_on_sclk; | |
673 | struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table = | |
674 | table_info->vdd_dep_on_mclk; | |
675 | ||
676 | PP_ASSERT_WITH_CODE(dep_sclk_table != NULL, | |
677 | "SCLK dependency table is missing. This table is mandatory", | |
678 | return -EINVAL); | |
679 | PP_ASSERT_WITH_CODE(dep_sclk_table->count >= 1, | |
680 | "SCLK dependency table has to have is missing." | |
681 | "This table is mandatory", | |
682 | return -EINVAL); | |
683 | ||
684 | PP_ASSERT_WITH_CODE(dep_mclk_table != NULL, | |
685 | "MCLK dependency table is missing. This table is mandatory", | |
686 | return -EINVAL); | |
687 | PP_ASSERT_WITH_CODE(dep_mclk_table->count >= 1, | |
688 | "MCLK dependency table has to have is missing." | |
689 | "This table is mandatory", | |
690 | return -EINVAL); | |
691 | ||
692 | /* clear the state table to reset everything to default */ | |
693 | phm_reset_single_dpm_table( | |
694 | &data->dpm_table.sclk_table, SMU74_MAX_LEVELS_GRAPHICS, MAX_REGULAR_DPM_NUMBER); | |
695 | phm_reset_single_dpm_table( | |
696 | &data->dpm_table.mclk_table, SMU74_MAX_LEVELS_MEMORY, MAX_REGULAR_DPM_NUMBER); | |
697 | ||
698 | ||
699 | /* Initialize Sclk DPM table based on allow Sclk values */ | |
700 | data->dpm_table.sclk_table.count = 0; | |
701 | for (i = 0; i < dep_sclk_table->count; i++) { | |
702 | if (i == 0 || data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count - 1].value != | |
703 | dep_sclk_table->entries[i].clk) { | |
704 | ||
705 | data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].value = | |
706 | dep_sclk_table->entries[i].clk; | |
707 | ||
708 | data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].enabled = | |
709 | (i == 0) ? true : false; | |
710 | data->dpm_table.sclk_table.count++; | |
711 | } | |
712 | } | |
713 | ||
714 | /* Initialize Mclk DPM table based on allow Mclk values */ | |
715 | data->dpm_table.mclk_table.count = 0; | |
716 | for (i = 0; i < dep_mclk_table->count; i++) { | |
717 | if (i == 0 || data->dpm_table.mclk_table.dpm_levels | |
718 | [data->dpm_table.mclk_table.count - 1].value != | |
719 | dep_mclk_table->entries[i].clk) { | |
720 | data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].value = | |
721 | dep_mclk_table->entries[i].clk; | |
722 | data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].enabled = | |
723 | (i == 0) ? true : false; | |
724 | data->dpm_table.mclk_table.count++; | |
725 | } | |
726 | } | |
727 | ||
728 | /* setup PCIE gen speed levels */ | |
2cc0c0b5 | 729 | polaris10_setup_default_pcie_table(hwmgr); |
a23eefa2 RZ |
730 | |
731 | /* save a copy of the default DPM table */ | |
732 | memcpy(&(data->golden_dpm_table), &(data->dpm_table), | |
2cc0c0b5 | 733 | sizeof(struct polaris10_dpm_table)); |
a23eefa2 RZ |
734 | |
735 | return 0; | |
736 | } | |
737 | ||
738 | uint8_t convert_to_vid(uint16_t vddc) | |
739 | { | |
740 | return (uint8_t) ((6200 - (vddc * VOLTAGE_SCALE)) / 25); | |
741 | } | |
742 | ||
743 | /** | |
744 | * Mvdd table preparation for SMC. | |
745 | * | |
746 | * @param *hwmgr The address of the hardware manager. | |
747 | * @param *table The SMC DPM table structure to be populated. | |
748 | * @return 0 | |
749 | */ | |
2cc0c0b5 | 750 | static int polaris10_populate_smc_mvdd_table(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
751 | SMU74_Discrete_DpmTable *table) |
752 | { | |
2cc0c0b5 | 753 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
754 | uint32_t count, level; |
755 | ||
2cc0c0b5 | 756 | if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) { |
a23eefa2 RZ |
757 | count = data->mvdd_voltage_table.count; |
758 | if (count > SMU_MAX_SMIO_LEVELS) | |
759 | count = SMU_MAX_SMIO_LEVELS; | |
760 | for (level = 0; level < count; level++) { | |
761 | table->SmioTable2.Pattern[level].Voltage = | |
762 | PP_HOST_TO_SMC_US(data->mvdd_voltage_table.entries[count].value * VOLTAGE_SCALE); | |
763 | /* Index into DpmTable.Smio. Drive bits from Smio entry to get this voltage level.*/ | |
764 | table->SmioTable2.Pattern[level].Smio = | |
765 | (uint8_t) level; | |
766 | table->Smio[level] |= | |
767 | data->mvdd_voltage_table.entries[level].smio_low; | |
768 | } | |
769 | table->SmioMask2 = data->vddci_voltage_table.mask_low; | |
770 | ||
771 | table->MvddLevelCount = (uint32_t) PP_HOST_TO_SMC_UL(count); | |
772 | } | |
773 | ||
774 | return 0; | |
775 | } | |
776 | ||
2cc0c0b5 | 777 | static int polaris10_populate_smc_vddci_table(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
778 | struct SMU74_Discrete_DpmTable *table) |
779 | { | |
780 | uint32_t count, level; | |
2cc0c0b5 | 781 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
782 | |
783 | count = data->vddci_voltage_table.count; | |
784 | ||
2cc0c0b5 | 785 | if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) { |
a23eefa2 RZ |
786 | if (count > SMU_MAX_SMIO_LEVELS) |
787 | count = SMU_MAX_SMIO_LEVELS; | |
788 | for (level = 0; level < count; ++level) { | |
789 | table->SmioTable1.Pattern[level].Voltage = | |
790 | PP_HOST_TO_SMC_US(data->vddci_voltage_table.entries[level].value * VOLTAGE_SCALE); | |
791 | table->SmioTable1.Pattern[level].Smio = (uint8_t) level; | |
792 | ||
793 | table->Smio[level] |= data->vddci_voltage_table.entries[level].smio_low; | |
794 | } | |
795 | } | |
796 | ||
797 | table->SmioMask1 = data->vddci_voltage_table.mask_low; | |
798 | ||
799 | return 0; | |
800 | } | |
801 | ||
802 | /** | |
803 | * Preparation of vddc and vddgfx CAC tables for SMC. | |
804 | * | |
805 | * @param hwmgr the address of the hardware manager | |
806 | * @param table the SMC DPM table structure to be populated | |
807 | * @return always 0 | |
808 | */ | |
2cc0c0b5 | 809 | static int polaris10_populate_cac_table(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
810 | struct SMU74_Discrete_DpmTable *table) |
811 | { | |
812 | uint32_t count; | |
813 | uint8_t index; | |
2cc0c0b5 | 814 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
815 | struct phm_ppt_v1_information *table_info = |
816 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
817 | struct phm_ppt_v1_voltage_lookup_table *lookup_table = | |
818 | table_info->vddc_lookup_table; | |
819 | /* tables is already swapped, so in order to use the value from it, | |
820 | * we need to swap it back. | |
821 | * We are populating vddc CAC data to BapmVddc table | |
822 | * in split and merged mode | |
823 | */ | |
824 | for (count = 0; count < lookup_table->count; count++) { | |
825 | index = phm_get_voltage_index(lookup_table, | |
826 | data->vddc_voltage_table.entries[count].value); | |
827 | table->BapmVddcVidLoSidd[count] = convert_to_vid(lookup_table->entries[index].us_cac_low); | |
828 | table->BapmVddcVidHiSidd[count] = convert_to_vid(lookup_table->entries[index].us_cac_mid); | |
829 | table->BapmVddcVidHiSidd2[count] = convert_to_vid(lookup_table->entries[index].us_cac_high); | |
830 | } | |
831 | ||
832 | return 0; | |
833 | } | |
834 | ||
835 | /** | |
836 | * Preparation of voltage tables for SMC. | |
837 | * | |
838 | * @param hwmgr the address of the hardware manager | |
839 | * @param table the SMC DPM table structure to be populated | |
840 | * @return always 0 | |
841 | */ | |
842 | ||
2cc0c0b5 | 843 | int polaris10_populate_smc_voltage_tables(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
844 | struct SMU74_Discrete_DpmTable *table) |
845 | { | |
2cc0c0b5 FC |
846 | polaris10_populate_smc_vddci_table(hwmgr, table); |
847 | polaris10_populate_smc_mvdd_table(hwmgr, table); | |
848 | polaris10_populate_cac_table(hwmgr, table); | |
a23eefa2 RZ |
849 | |
850 | return 0; | |
851 | } | |
852 | ||
2cc0c0b5 | 853 | static int polaris10_populate_ulv_level(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
854 | struct SMU74_Discrete_Ulv *state) |
855 | { | |
2cc0c0b5 | 856 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
857 | struct phm_ppt_v1_information *table_info = |
858 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
859 | ||
860 | state->CcPwrDynRm = 0; | |
861 | state->CcPwrDynRm1 = 0; | |
862 | ||
863 | state->VddcOffset = (uint16_t) table_info->us_ulv_voltage_offset; | |
864 | state->VddcOffsetVid = (uint8_t)(table_info->us_ulv_voltage_offset * | |
865 | VOLTAGE_VID_OFFSET_SCALE2 / VOLTAGE_VID_OFFSET_SCALE1); | |
866 | ||
867 | state->VddcPhase = (data->vddc_phase_shed_control) ? 0 : 1; | |
868 | ||
869 | CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm); | |
870 | CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm1); | |
871 | CONVERT_FROM_HOST_TO_SMC_US(state->VddcOffset); | |
872 | ||
873 | return 0; | |
874 | } | |
875 | ||
2cc0c0b5 | 876 | static int polaris10_populate_ulv_state(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
877 | struct SMU74_Discrete_DpmTable *table) |
878 | { | |
2cc0c0b5 | 879 | return polaris10_populate_ulv_level(hwmgr, &table->Ulv); |
a23eefa2 RZ |
880 | } |
881 | ||
2cc0c0b5 | 882 | static int polaris10_populate_smc_link_level(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
883 | struct SMU74_Discrete_DpmTable *table) |
884 | { | |
2cc0c0b5 FC |
885 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
886 | struct polaris10_dpm_table *dpm_table = &data->dpm_table; | |
a23eefa2 RZ |
887 | int i; |
888 | ||
889 | /* Index (dpm_table->pcie_speed_table.count) | |
890 | * is reserved for PCIE boot level. */ | |
891 | for (i = 0; i <= dpm_table->pcie_speed_table.count; i++) { | |
892 | table->LinkLevel[i].PcieGenSpeed = | |
893 | (uint8_t)dpm_table->pcie_speed_table.dpm_levels[i].value; | |
894 | table->LinkLevel[i].PcieLaneCount = (uint8_t)encode_pcie_lane_width( | |
895 | dpm_table->pcie_speed_table.dpm_levels[i].param1); | |
896 | table->LinkLevel[i].EnabledForActivity = 1; | |
897 | table->LinkLevel[i].SPC = (uint8_t)(data->pcie_spc_cap & 0xff); | |
898 | table->LinkLevel[i].DownThreshold = PP_HOST_TO_SMC_UL(5); | |
899 | table->LinkLevel[i].UpThreshold = PP_HOST_TO_SMC_UL(30); | |
900 | } | |
901 | ||
902 | data->smc_state_table.LinkLevelCount = | |
903 | (uint8_t)dpm_table->pcie_speed_table.count; | |
904 | data->dpm_level_enable_mask.pcie_dpm_enable_mask = | |
905 | phm_get_dpm_level_enable_mask_value(&dpm_table->pcie_speed_table); | |
906 | ||
907 | return 0; | |
908 | } | |
909 | ||
2cc0c0b5 | 910 | static uint32_t polaris10_get_xclk(struct pp_hwmgr *hwmgr) |
a23eefa2 RZ |
911 | { |
912 | uint32_t reference_clock, tmp; | |
913 | struct cgs_display_info info = {0}; | |
914 | struct cgs_mode_info mode_info; | |
915 | ||
916 | info.mode_info = &mode_info; | |
917 | ||
918 | tmp = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_CLKPIN_CNTL_2, MUX_TCLK_TO_XCLK); | |
919 | ||
920 | if (tmp) | |
921 | return TCLK; | |
922 | ||
923 | cgs_get_active_displays_info(hwmgr->device, &info); | |
924 | reference_clock = mode_info.ref_clock; | |
925 | ||
926 | tmp = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_CLKPIN_CNTL, XTALIN_DIVIDE); | |
927 | ||
928 | if (0 != tmp) | |
929 | return reference_clock / 4; | |
930 | ||
931 | return reference_clock; | |
932 | } | |
933 | ||
934 | /** | |
935 | * Calculates the SCLK dividers using the provided engine clock | |
936 | * | |
937 | * @param hwmgr the address of the hardware manager | |
938 | * @param clock the engine clock to use to populate the structure | |
939 | * @param sclk the SMC SCLK structure to be populated | |
940 | */ | |
2cc0c0b5 | 941 | static int polaris10_calculate_sclk_params(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
942 | uint32_t clock, SMU_SclkSetting *sclk_setting) |
943 | { | |
2cc0c0b5 | 944 | const struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
945 | const SMU74_Discrete_DpmTable *table = &(data->smc_state_table); |
946 | struct pp_atomctrl_clock_dividers_ai dividers; | |
947 | ||
948 | uint32_t ref_clock; | |
949 | uint32_t pcc_target_percent, pcc_target_freq, ss_target_percent, ss_target_freq; | |
950 | uint8_t i; | |
951 | int result; | |
952 | uint64_t temp; | |
953 | ||
954 | sclk_setting->SclkFrequency = clock; | |
955 | /* get the engine clock dividers for this clock value */ | |
956 | result = atomctrl_get_engine_pll_dividers_ai(hwmgr, clock, ÷rs); | |
957 | if (result == 0) { | |
958 | sclk_setting->Fcw_int = dividers.usSclk_fcw_int; | |
959 | sclk_setting->Fcw_frac = dividers.usSclk_fcw_frac; | |
960 | sclk_setting->Pcc_fcw_int = dividers.usPcc_fcw_int; | |
961 | sclk_setting->PllRange = dividers.ucSclkPllRange; | |
e85c7d66 | 962 | sclk_setting->Sclk_slew_rate = 0x400; |
963 | sclk_setting->Pcc_up_slew_rate = dividers.usPcc_fcw_slew_frac; | |
964 | sclk_setting->Pcc_down_slew_rate = 0xffff; | |
a23eefa2 RZ |
965 | sclk_setting->SSc_En = dividers.ucSscEnable; |
966 | sclk_setting->Fcw1_int = dividers.usSsc_fcw1_int; | |
967 | sclk_setting->Fcw1_frac = dividers.usSsc_fcw1_frac; | |
e85c7d66 | 968 | sclk_setting->Sclk_ss_slew_rate = dividers.usSsc_fcw_slew_frac; |
a23eefa2 RZ |
969 | return result; |
970 | } | |
971 | ||
2cc0c0b5 | 972 | ref_clock = polaris10_get_xclk(hwmgr); |
a23eefa2 RZ |
973 | |
974 | for (i = 0; i < NUM_SCLK_RANGE; i++) { | |
975 | if (clock > data->range_table[i].trans_lower_frequency | |
976 | && clock <= data->range_table[i].trans_upper_frequency) { | |
977 | sclk_setting->PllRange = i; | |
978 | break; | |
979 | } | |
980 | } | |
981 | ||
982 | sclk_setting->Fcw_int = (uint16_t)((clock << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv) / ref_clock); | |
983 | temp = clock << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv; | |
984 | temp <<= 0x10; | |
ae17c999 SG |
985 | do_div(temp, ref_clock); |
986 | sclk_setting->Fcw_frac = temp & 0xffff; | |
a23eefa2 RZ |
987 | |
988 | pcc_target_percent = 10; /* Hardcode 10% for now. */ | |
989 | pcc_target_freq = clock - (clock * pcc_target_percent / 100); | |
990 | sclk_setting->Pcc_fcw_int = (uint16_t)((pcc_target_freq << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv) / ref_clock); | |
991 | ||
992 | ss_target_percent = 2; /* Hardcode 2% for now. */ | |
993 | sclk_setting->SSc_En = 0; | |
994 | if (ss_target_percent) { | |
995 | sclk_setting->SSc_En = 1; | |
996 | ss_target_freq = clock - (clock * ss_target_percent / 100); | |
997 | sclk_setting->Fcw1_int = (uint16_t)((ss_target_freq << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv) / ref_clock); | |
998 | temp = ss_target_freq << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv; | |
999 | temp <<= 0x10; | |
ae17c999 SG |
1000 | do_div(temp, ref_clock); |
1001 | sclk_setting->Fcw1_frac = temp & 0xffff; | |
a23eefa2 RZ |
1002 | } |
1003 | ||
1004 | return 0; | |
1005 | } | |
1006 | ||
2cc0c0b5 | 1007 | static int polaris10_get_dependency_volt_by_clk(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
1008 | struct phm_ppt_v1_clock_voltage_dependency_table *dep_table, |
1009 | uint32_t clock, SMU_VoltageLevel *voltage, uint32_t *mvdd) | |
1010 | { | |
1011 | uint32_t i; | |
1012 | uint16_t vddci; | |
2cc0c0b5 | 1013 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
1014 | |
1015 | *voltage = *mvdd = 0; | |
1016 | ||
1017 | /* clock - voltage dependency table is empty table */ | |
1018 | if (dep_table->count == 0) | |
1019 | return -EINVAL; | |
1020 | ||
1021 | for (i = 0; i < dep_table->count; i++) { | |
1022 | /* find first sclk bigger than request */ | |
1023 | if (dep_table->entries[i].clk >= clock) { | |
1024 | *voltage |= (dep_table->entries[i].vddc * | |
1025 | VOLTAGE_SCALE) << VDDC_SHIFT; | |
2cc0c0b5 | 1026 | if (POLARIS10_VOLTAGE_CONTROL_NONE == data->vddci_control) |
a23eefa2 RZ |
1027 | *voltage |= (data->vbios_boot_state.vddci_bootup_value * |
1028 | VOLTAGE_SCALE) << VDDCI_SHIFT; | |
1029 | else if (dep_table->entries[i].vddci) | |
1030 | *voltage |= (dep_table->entries[i].vddci * | |
1031 | VOLTAGE_SCALE) << VDDCI_SHIFT; | |
1032 | else { | |
1033 | vddci = phm_find_closest_vddci(&(data->vddci_voltage_table), | |
1034 | (dep_table->entries[i].vddc - | |
1035 | (uint16_t)data->vddc_vddci_delta)); | |
1036 | *voltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT; | |
1037 | } | |
1038 | ||
2cc0c0b5 | 1039 | if (POLARIS10_VOLTAGE_CONTROL_NONE == data->mvdd_control) |
a23eefa2 RZ |
1040 | *mvdd = data->vbios_boot_state.mvdd_bootup_value * |
1041 | VOLTAGE_SCALE; | |
1042 | else if (dep_table->entries[i].mvdd) | |
1043 | *mvdd = (uint32_t) dep_table->entries[i].mvdd * | |
1044 | VOLTAGE_SCALE; | |
1045 | ||
1046 | *voltage |= 1 << PHASES_SHIFT; | |
1047 | return 0; | |
1048 | } | |
1049 | } | |
1050 | ||
1051 | /* sclk is bigger than max sclk in the dependence table */ | |
1052 | *voltage |= (dep_table->entries[i - 1].vddc * VOLTAGE_SCALE) << VDDC_SHIFT; | |
1053 | ||
2cc0c0b5 | 1054 | if (POLARIS10_VOLTAGE_CONTROL_NONE == data->vddci_control) |
a23eefa2 RZ |
1055 | *voltage |= (data->vbios_boot_state.vddci_bootup_value * |
1056 | VOLTAGE_SCALE) << VDDCI_SHIFT; | |
1057 | else if (dep_table->entries[i-1].vddci) { | |
1058 | vddci = phm_find_closest_vddci(&(data->vddci_voltage_table), | |
1059 | (dep_table->entries[i].vddc - | |
1060 | (uint16_t)data->vddc_vddci_delta)); | |
1061 | *voltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT; | |
1062 | } | |
1063 | ||
2cc0c0b5 | 1064 | if (POLARIS10_VOLTAGE_CONTROL_NONE == data->mvdd_control) |
a23eefa2 RZ |
1065 | *mvdd = data->vbios_boot_state.mvdd_bootup_value * VOLTAGE_SCALE; |
1066 | else if (dep_table->entries[i].mvdd) | |
1067 | *mvdd = (uint32_t) dep_table->entries[i - 1].mvdd * VOLTAGE_SCALE; | |
1068 | ||
1069 | return 0; | |
1070 | } | |
1071 | ||
1072 | sclkFcwRange_t Range_Table[NUM_SCLK_RANGE] = { {VCO_2_4, POSTDIV_DIV_BY_16, 75, 160, 112}, | |
1073 | {VCO_3_6, POSTDIV_DIV_BY_16, 112, 224, 160}, | |
1074 | {VCO_2_4, POSTDIV_DIV_BY_8, 75, 160, 112}, | |
1075 | {VCO_3_6, POSTDIV_DIV_BY_8, 112, 224, 160}, | |
1076 | {VCO_2_4, POSTDIV_DIV_BY_4, 75, 160, 112}, | |
1077 | {VCO_3_6, POSTDIV_DIV_BY_4, 112, 216, 160}, | |
1078 | {VCO_2_4, POSTDIV_DIV_BY_2, 75, 160, 108}, | |
1079 | {VCO_3_6, POSTDIV_DIV_BY_2, 112, 216, 160} }; | |
1080 | ||
2cc0c0b5 | 1081 | static void polaris10_get_sclk_range_table(struct pp_hwmgr *hwmgr) |
a23eefa2 RZ |
1082 | { |
1083 | uint32_t i, ref_clk; | |
2cc0c0b5 | 1084 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
1085 | SMU74_Discrete_DpmTable *table = &(data->smc_state_table); |
1086 | struct pp_atom_ctrl_sclk_range_table range_table_from_vbios = { { {0} } }; | |
1087 | ||
2cc0c0b5 | 1088 | ref_clk = polaris10_get_xclk(hwmgr); |
a23eefa2 RZ |
1089 | |
1090 | if (0 == atomctrl_get_smc_sclk_range_table(hwmgr, &range_table_from_vbios)) { | |
1091 | for (i = 0; i < NUM_SCLK_RANGE; i++) { | |
1092 | table->SclkFcwRangeTable[i].vco_setting = range_table_from_vbios.entry[i].ucVco_setting; | |
1093 | table->SclkFcwRangeTable[i].postdiv = range_table_from_vbios.entry[i].ucPostdiv; | |
1094 | table->SclkFcwRangeTable[i].fcw_pcc = range_table_from_vbios.entry[i].usFcw_pcc; | |
1095 | ||
1096 | table->SclkFcwRangeTable[i].fcw_trans_upper = range_table_from_vbios.entry[i].usFcw_trans_upper; | |
1097 | table->SclkFcwRangeTable[i].fcw_trans_lower = range_table_from_vbios.entry[i].usRcw_trans_lower; | |
1098 | ||
1099 | CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_pcc); | |
1100 | CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_upper); | |
1101 | CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_lower); | |
1102 | } | |
1103 | return; | |
1104 | } | |
1105 | ||
1106 | for (i = 0; i < NUM_SCLK_RANGE; i++) { | |
1107 | ||
1108 | data->range_table[i].trans_lower_frequency = (ref_clk * Range_Table[i].fcw_trans_lower) >> Range_Table[i].postdiv; | |
1109 | data->range_table[i].trans_upper_frequency = (ref_clk * Range_Table[i].fcw_trans_upper) >> Range_Table[i].postdiv; | |
1110 | ||
1111 | table->SclkFcwRangeTable[i].vco_setting = Range_Table[i].vco_setting; | |
1112 | table->SclkFcwRangeTable[i].postdiv = Range_Table[i].postdiv; | |
1113 | table->SclkFcwRangeTable[i].fcw_pcc = Range_Table[i].fcw_pcc; | |
1114 | ||
1115 | table->SclkFcwRangeTable[i].fcw_trans_upper = Range_Table[i].fcw_trans_upper; | |
1116 | table->SclkFcwRangeTable[i].fcw_trans_lower = Range_Table[i].fcw_trans_lower; | |
1117 | ||
1118 | CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_pcc); | |
1119 | CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_upper); | |
1120 | CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_lower); | |
1121 | } | |
1122 | } | |
1123 | ||
1124 | /** | |
1125 | * Populates single SMC SCLK structure using the provided engine clock | |
1126 | * | |
1127 | * @param hwmgr the address of the hardware manager | |
1128 | * @param clock the engine clock to use to populate the structure | |
1129 | * @param sclk the SMC SCLK structure to be populated | |
1130 | */ | |
1131 | ||
2cc0c0b5 | 1132 | static int polaris10_populate_single_graphic_level(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
1133 | uint32_t clock, uint16_t sclk_al_threshold, |
1134 | struct SMU74_Discrete_GraphicsLevel *level) | |
1135 | { | |
1136 | int result, i, temp; | |
1137 | /* PP_Clocks minClocks; */ | |
1138 | uint32_t mvdd; | |
2cc0c0b5 | 1139 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
1140 | struct phm_ppt_v1_information *table_info = |
1141 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
1142 | SMU_SclkSetting curr_sclk_setting = { 0 }; | |
1143 | ||
2cc0c0b5 | 1144 | result = polaris10_calculate_sclk_params(hwmgr, clock, &curr_sclk_setting); |
a23eefa2 RZ |
1145 | |
1146 | /* populate graphics levels */ | |
2cc0c0b5 | 1147 | result = polaris10_get_dependency_volt_by_clk(hwmgr, |
a23eefa2 RZ |
1148 | table_info->vdd_dep_on_sclk, clock, |
1149 | &level->MinVoltage, &mvdd); | |
1150 | ||
1151 | PP_ASSERT_WITH_CODE((0 == result), | |
1152 | "can not find VDDC voltage value for " | |
1153 | "VDDC engine clock dependency table", | |
1154 | return result); | |
1155 | level->ActivityLevel = sclk_al_threshold; | |
1156 | ||
1157 | level->CcPwrDynRm = 0; | |
1158 | level->CcPwrDynRm1 = 0; | |
1159 | level->EnabledForActivity = 0; | |
1160 | level->EnabledForThrottle = 1; | |
1161 | level->UpHyst = 10; | |
1162 | level->DownHyst = 0; | |
1163 | level->VoltageDownHyst = 0; | |
1164 | level->PowerThrottle = 0; | |
1165 | ||
1166 | /* | |
1167 | * TODO: get minimum clocks from dal configaration | |
1168 | * PECI_GetMinClockSettings(hwmgr->pPECI, &minClocks); | |
1169 | */ | |
1170 | /* data->DisplayTiming.minClockInSR = minClocks.engineClockInSR; */ | |
1171 | ||
1172 | /* get level->DeepSleepDivId | |
1173 | if (phm_cap_enabled(hwmgr->platformDescriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep)) | |
1174 | level->DeepSleepDivId = PhwFiji_GetSleepDividerIdFromClock(hwmgr, clock, minClocks.engineClockInSR); | |
1175 | */ | |
1176 | PP_ASSERT_WITH_CODE((clock >= 2500), "Engine clock can't satisfy stutter requirement!", return 0); | |
2cc0c0b5 | 1177 | for (i = POLARIS10_MAX_DEEPSLEEP_DIVIDER_ID; ; i--) { |
a23eefa2 RZ |
1178 | temp = clock / (1UL << i); |
1179 | ||
1180 | if (temp >= 2500 || i == 0) | |
1181 | break; | |
1182 | } | |
1183 | ||
1184 | level->DeepSleepDivId = i; | |
1185 | ||
1186 | /* Default to slow, highest DPM level will be | |
1187 | * set to PPSMC_DISPLAY_WATERMARK_LOW later. | |
1188 | */ | |
1189 | if (data->update_up_hyst) | |
1190 | level->UpHyst = (uint8_t)data->up_hyst; | |
1191 | if (data->update_down_hyst) | |
1192 | level->DownHyst = (uint8_t)data->down_hyst; | |
1193 | ||
1194 | level->SclkSetting = curr_sclk_setting; | |
1195 | ||
1196 | CONVERT_FROM_HOST_TO_SMC_UL(level->MinVoltage); | |
1197 | CONVERT_FROM_HOST_TO_SMC_UL(level->CcPwrDynRm); | |
1198 | CONVERT_FROM_HOST_TO_SMC_UL(level->CcPwrDynRm1); | |
1199 | CONVERT_FROM_HOST_TO_SMC_US(level->ActivityLevel); | |
1200 | CONVERT_FROM_HOST_TO_SMC_UL(level->SclkSetting.SclkFrequency); | |
1201 | CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw_int); | |
1202 | CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw_frac); | |
1203 | CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Pcc_fcw_int); | |
e85c7d66 | 1204 | CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Sclk_slew_rate); |
1205 | CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Pcc_up_slew_rate); | |
1206 | CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Pcc_down_slew_rate); | |
a23eefa2 RZ |
1207 | CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw1_int); |
1208 | CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw1_frac); | |
e85c7d66 | 1209 | CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Sclk_ss_slew_rate); |
a23eefa2 RZ |
1210 | return 0; |
1211 | } | |
1212 | ||
1213 | /** | |
1214 | * Populates all SMC SCLK levels' structure based on the trimmed allowed dpm engine clock states | |
1215 | * | |
1216 | * @param hwmgr the address of the hardware manager | |
1217 | */ | |
2cc0c0b5 | 1218 | static int polaris10_populate_all_graphic_levels(struct pp_hwmgr *hwmgr) |
a23eefa2 | 1219 | { |
2cc0c0b5 FC |
1220 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
1221 | struct polaris10_dpm_table *dpm_table = &data->dpm_table; | |
a23eefa2 RZ |
1222 | struct phm_ppt_v1_information *table_info = |
1223 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
1224 | struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table; | |
1225 | uint8_t pcie_entry_cnt = (uint8_t) data->dpm_table.pcie_speed_table.count; | |
1226 | int result = 0; | |
1227 | uint32_t array = data->dpm_table_start + | |
1228 | offsetof(SMU74_Discrete_DpmTable, GraphicsLevel); | |
1229 | uint32_t array_size = sizeof(struct SMU74_Discrete_GraphicsLevel) * | |
1230 | SMU74_MAX_LEVELS_GRAPHICS; | |
1231 | struct SMU74_Discrete_GraphicsLevel *levels = | |
1232 | data->smc_state_table.GraphicsLevel; | |
1233 | uint32_t i, max_entry; | |
1234 | uint8_t hightest_pcie_level_enabled = 0, | |
1235 | lowest_pcie_level_enabled = 0, | |
1236 | mid_pcie_level_enabled = 0, | |
1237 | count = 0; | |
1238 | ||
2cc0c0b5 | 1239 | polaris10_get_sclk_range_table(hwmgr); |
a23eefa2 RZ |
1240 | |
1241 | for (i = 0; i < dpm_table->sclk_table.count; i++) { | |
1242 | ||
2cc0c0b5 | 1243 | result = polaris10_populate_single_graphic_level(hwmgr, |
a23eefa2 RZ |
1244 | dpm_table->sclk_table.dpm_levels[i].value, |
1245 | (uint16_t)data->activity_target[i], | |
1246 | &(data->smc_state_table.GraphicsLevel[i])); | |
1247 | if (result) | |
1248 | return result; | |
1249 | ||
1250 | /* Making sure only DPM level 0-1 have Deep Sleep Div ID populated. */ | |
1251 | if (i > 1) | |
1252 | levels[i].DeepSleepDivId = 0; | |
1253 | } | |
5de95e55 RZ |
1254 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, |
1255 | PHM_PlatformCaps_SPLLShutdownSupport)) | |
1256 | data->smc_state_table.GraphicsLevel[0].SclkSetting.SSc_En = 0; | |
a23eefa2 RZ |
1257 | |
1258 | data->smc_state_table.GraphicsLevel[0].EnabledForActivity = 1; | |
1259 | data->smc_state_table.GraphicsDpmLevelCount = | |
1260 | (uint8_t)dpm_table->sclk_table.count; | |
1261 | data->dpm_level_enable_mask.sclk_dpm_enable_mask = | |
1262 | phm_get_dpm_level_enable_mask_value(&dpm_table->sclk_table); | |
1263 | ||
1264 | ||
1265 | if (pcie_table != NULL) { | |
1266 | PP_ASSERT_WITH_CODE((1 <= pcie_entry_cnt), | |
1267 | "There must be 1 or more PCIE levels defined in PPTable.", | |
1268 | return -EINVAL); | |
1269 | max_entry = pcie_entry_cnt - 1; | |
1270 | for (i = 0; i < dpm_table->sclk_table.count; i++) | |
1271 | levels[i].pcieDpmLevel = | |
1272 | (uint8_t) ((i < max_entry) ? i : max_entry); | |
1273 | } else { | |
1274 | while (data->dpm_level_enable_mask.pcie_dpm_enable_mask && | |
1275 | ((data->dpm_level_enable_mask.pcie_dpm_enable_mask & | |
1276 | (1 << (hightest_pcie_level_enabled + 1))) != 0)) | |
1277 | hightest_pcie_level_enabled++; | |
1278 | ||
1279 | while (data->dpm_level_enable_mask.pcie_dpm_enable_mask && | |
1280 | ((data->dpm_level_enable_mask.pcie_dpm_enable_mask & | |
1281 | (1 << lowest_pcie_level_enabled)) == 0)) | |
1282 | lowest_pcie_level_enabled++; | |
1283 | ||
1284 | while ((count < hightest_pcie_level_enabled) && | |
1285 | ((data->dpm_level_enable_mask.pcie_dpm_enable_mask & | |
1286 | (1 << (lowest_pcie_level_enabled + 1 + count))) == 0)) | |
1287 | count++; | |
1288 | ||
1289 | mid_pcie_level_enabled = (lowest_pcie_level_enabled + 1 + count) < | |
1290 | hightest_pcie_level_enabled ? | |
1291 | (lowest_pcie_level_enabled + 1 + count) : | |
1292 | hightest_pcie_level_enabled; | |
1293 | ||
1294 | /* set pcieDpmLevel to hightest_pcie_level_enabled */ | |
1295 | for (i = 2; i < dpm_table->sclk_table.count; i++) | |
1296 | levels[i].pcieDpmLevel = hightest_pcie_level_enabled; | |
1297 | ||
1298 | /* set pcieDpmLevel to lowest_pcie_level_enabled */ | |
1299 | levels[0].pcieDpmLevel = lowest_pcie_level_enabled; | |
1300 | ||
1301 | /* set pcieDpmLevel to mid_pcie_level_enabled */ | |
1302 | levels[1].pcieDpmLevel = mid_pcie_level_enabled; | |
1303 | } | |
1304 | /* level count will send to smc once at init smc table and never change */ | |
2cc0c0b5 | 1305 | result = polaris10_copy_bytes_to_smc(hwmgr->smumgr, array, (uint8_t *)levels, |
a23eefa2 RZ |
1306 | (uint32_t)array_size, data->sram_end); |
1307 | ||
1308 | return result; | |
1309 | } | |
1310 | ||
2cc0c0b5 | 1311 | static int polaris10_populate_single_memory_level(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
1312 | uint32_t clock, struct SMU74_Discrete_MemoryLevel *mem_level) |
1313 | { | |
2cc0c0b5 | 1314 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
1315 | struct phm_ppt_v1_information *table_info = |
1316 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
1317 | int result = 0; | |
1318 | struct cgs_display_info info = {0, 0, NULL}; | |
1319 | ||
1320 | cgs_get_active_displays_info(hwmgr->device, &info); | |
1321 | ||
1322 | if (table_info->vdd_dep_on_mclk) { | |
2cc0c0b5 | 1323 | result = polaris10_get_dependency_volt_by_clk(hwmgr, |
a23eefa2 RZ |
1324 | table_info->vdd_dep_on_mclk, clock, |
1325 | &mem_level->MinVoltage, &mem_level->MinMvdd); | |
1326 | PP_ASSERT_WITH_CODE((0 == result), | |
1327 | "can not find MinVddc voltage value from memory " | |
1328 | "VDDC voltage dependency table", return result); | |
1329 | } | |
1330 | ||
1331 | mem_level->MclkFrequency = clock; | |
1332 | mem_level->StutterEnable = 0; | |
1333 | mem_level->EnabledForThrottle = 1; | |
1334 | mem_level->EnabledForActivity = 0; | |
1335 | mem_level->UpHyst = 0; | |
1336 | mem_level->DownHyst = 100; | |
1337 | mem_level->VoltageDownHyst = 0; | |
1338 | mem_level->ActivityLevel = (uint16_t)data->mclk_activity_target; | |
1339 | mem_level->StutterEnable = false; | |
1340 | ||
1341 | mem_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW; | |
1342 | ||
1343 | data->display_timing.num_existing_displays = info.display_count; | |
1344 | ||
1345 | if ((data->mclk_stutter_mode_threshold) && | |
1346 | (clock <= data->mclk_stutter_mode_threshold) && | |
1347 | (PHM_READ_FIELD(hwmgr->device, DPG_PIPE_STUTTER_CONTROL, | |
1348 | STUTTER_ENABLE) & 0x1)) | |
1349 | mem_level->StutterEnable = true; | |
1350 | ||
1351 | if (!result) { | |
1352 | CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MinMvdd); | |
1353 | CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MclkFrequency); | |
1354 | CONVERT_FROM_HOST_TO_SMC_US(mem_level->ActivityLevel); | |
1355 | CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MinVoltage); | |
1356 | } | |
1357 | return result; | |
1358 | } | |
1359 | ||
1360 | /** | |
1361 | * Populates all SMC MCLK levels' structure based on the trimmed allowed dpm memory clock states | |
1362 | * | |
1363 | * @param hwmgr the address of the hardware manager | |
1364 | */ | |
2cc0c0b5 | 1365 | static int polaris10_populate_all_memory_levels(struct pp_hwmgr *hwmgr) |
a23eefa2 | 1366 | { |
2cc0c0b5 FC |
1367 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
1368 | struct polaris10_dpm_table *dpm_table = &data->dpm_table; | |
a23eefa2 RZ |
1369 | int result; |
1370 | /* populate MCLK dpm table to SMU7 */ | |
1371 | uint32_t array = data->dpm_table_start + | |
1372 | offsetof(SMU74_Discrete_DpmTable, MemoryLevel); | |
1373 | uint32_t array_size = sizeof(SMU74_Discrete_MemoryLevel) * | |
1374 | SMU74_MAX_LEVELS_MEMORY; | |
1375 | struct SMU74_Discrete_MemoryLevel *levels = | |
1376 | data->smc_state_table.MemoryLevel; | |
1377 | uint32_t i; | |
1378 | ||
1379 | for (i = 0; i < dpm_table->mclk_table.count; i++) { | |
1380 | PP_ASSERT_WITH_CODE((0 != dpm_table->mclk_table.dpm_levels[i].value), | |
1381 | "can not populate memory level as memory clock is zero", | |
1382 | return -EINVAL); | |
2cc0c0b5 | 1383 | result = polaris10_populate_single_memory_level(hwmgr, |
a23eefa2 RZ |
1384 | dpm_table->mclk_table.dpm_levels[i].value, |
1385 | &levels[i]); | |
b4c6f99e RZ |
1386 | if (i == dpm_table->mclk_table.count - 1) { |
1387 | levels[i].DisplayWatermark = PPSMC_DISPLAY_WATERMARK_HIGH; | |
1388 | levels[i].EnabledForActivity = 1; | |
1389 | } | |
a23eefa2 RZ |
1390 | if (result) |
1391 | return result; | |
1392 | } | |
1393 | ||
a23eefa2 RZ |
1394 | /* in order to prevent MC activity from stutter mode to push DPM up. |
1395 | * the UVD change complements this by putting the MCLK in | |
1396 | * a higher state by default such that we are not effected by | |
1397 | * up threshold or and MCLK DPM latency. | |
1398 | */ | |
1399 | levels[0].ActivityLevel = (uint16_t)data->mclk_dpm0_activity_target; | |
1400 | CONVERT_FROM_HOST_TO_SMC_US(levels[0].ActivityLevel); | |
1401 | ||
1402 | data->smc_state_table.MemoryDpmLevelCount = | |
1403 | (uint8_t)dpm_table->mclk_table.count; | |
1404 | data->dpm_level_enable_mask.mclk_dpm_enable_mask = | |
1405 | phm_get_dpm_level_enable_mask_value(&dpm_table->mclk_table); | |
a23eefa2 RZ |
1406 | |
1407 | /* level count will send to smc once at init smc table and never change */ | |
2cc0c0b5 | 1408 | result = polaris10_copy_bytes_to_smc(hwmgr->smumgr, array, (uint8_t *)levels, |
a23eefa2 RZ |
1409 | (uint32_t)array_size, data->sram_end); |
1410 | ||
1411 | return result; | |
1412 | } | |
1413 | ||
1414 | /** | |
1415 | * Populates the SMC MVDD structure using the provided memory clock. | |
1416 | * | |
1417 | * @param hwmgr the address of the hardware manager | |
1418 | * @param mclk the MCLK value to be used in the decision if MVDD should be high or low. | |
1419 | * @param voltage the SMC VOLTAGE structure to be populated | |
1420 | */ | |
2cc0c0b5 | 1421 | int polaris10_populate_mvdd_value(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
1422 | uint32_t mclk, SMIO_Pattern *smio_pat) |
1423 | { | |
2cc0c0b5 | 1424 | const struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
1425 | struct phm_ppt_v1_information *table_info = |
1426 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
1427 | uint32_t i = 0; | |
1428 | ||
2cc0c0b5 | 1429 | if (POLARIS10_VOLTAGE_CONTROL_NONE != data->mvdd_control) { |
a23eefa2 RZ |
1430 | /* find mvdd value which clock is more than request */ |
1431 | for (i = 0; i < table_info->vdd_dep_on_mclk->count; i++) { | |
1432 | if (mclk <= table_info->vdd_dep_on_mclk->entries[i].clk) { | |
1433 | smio_pat->Voltage = data->mvdd_voltage_table.entries[i].value; | |
1434 | break; | |
1435 | } | |
1436 | } | |
1437 | PP_ASSERT_WITH_CODE(i < table_info->vdd_dep_on_mclk->count, | |
1438 | "MVDD Voltage is outside the supported range.", | |
1439 | return -EINVAL); | |
1440 | } else | |
1441 | return -EINVAL; | |
1442 | ||
1443 | return 0; | |
1444 | } | |
1445 | ||
2cc0c0b5 | 1446 | static int polaris10_populate_smc_acpi_level(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
1447 | SMU74_Discrete_DpmTable *table) |
1448 | { | |
1449 | int result = 0; | |
1450 | uint32_t sclk_frequency; | |
2cc0c0b5 | 1451 | const struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
1452 | struct phm_ppt_v1_information *table_info = |
1453 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
1454 | SMIO_Pattern vol_level; | |
1455 | uint32_t mvdd; | |
1456 | uint16_t us_mvdd; | |
1457 | ||
1458 | table->ACPILevel.Flags &= ~PPSMC_SWSTATE_FLAG_DC; | |
1459 | ||
1460 | if (!data->sclk_dpm_key_disabled) { | |
1461 | /* Get MinVoltage and Frequency from DPM0, | |
1462 | * already converted to SMC_UL */ | |
1463 | sclk_frequency = data->dpm_table.sclk_table.dpm_levels[0].value; | |
2cc0c0b5 | 1464 | result = polaris10_get_dependency_volt_by_clk(hwmgr, |
a23eefa2 RZ |
1465 | table_info->vdd_dep_on_sclk, |
1466 | table->ACPILevel.SclkFrequency, | |
1467 | &table->ACPILevel.MinVoltage, &mvdd); | |
1468 | PP_ASSERT_WITH_CODE((0 == result), | |
1469 | "Cannot find ACPI VDDC voltage value " | |
1470 | "in Clock Dependency Table", ); | |
1471 | } else { | |
1472 | sclk_frequency = data->vbios_boot_state.sclk_bootup_value; | |
1473 | table->ACPILevel.MinVoltage = | |
1474 | data->vbios_boot_state.vddc_bootup_value * VOLTAGE_SCALE; | |
1475 | } | |
1476 | ||
2cc0c0b5 | 1477 | result = polaris10_calculate_sclk_params(hwmgr, sclk_frequency, &(table->ACPILevel.SclkSetting)); |
a23eefa2 RZ |
1478 | PP_ASSERT_WITH_CODE(result == 0, "Error retrieving Engine Clock dividers from VBIOS.", return result); |
1479 | ||
1480 | table->ACPILevel.DeepSleepDivId = 0; | |
1481 | table->ACPILevel.CcPwrDynRm = 0; | |
1482 | table->ACPILevel.CcPwrDynRm1 = 0; | |
1483 | ||
1484 | CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.Flags); | |
1485 | CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.MinVoltage); | |
1486 | CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm); | |
1487 | CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm1); | |
1488 | ||
1489 | CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SclkSetting.SclkFrequency); | |
1490 | CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw_int); | |
1491 | CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw_frac); | |
1492 | CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Pcc_fcw_int); | |
e85c7d66 | 1493 | CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Sclk_slew_rate); |
1494 | CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Pcc_up_slew_rate); | |
1495 | CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Pcc_down_slew_rate); | |
a23eefa2 RZ |
1496 | CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw1_int); |
1497 | CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw1_frac); | |
e85c7d66 | 1498 | CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Sclk_ss_slew_rate); |
a23eefa2 RZ |
1499 | |
1500 | if (!data->mclk_dpm_key_disabled) { | |
1501 | /* Get MinVoltage and Frequency from DPM0, already converted to SMC_UL */ | |
1502 | table->MemoryACPILevel.MclkFrequency = | |
1503 | data->dpm_table.mclk_table.dpm_levels[0].value; | |
2cc0c0b5 | 1504 | result = polaris10_get_dependency_volt_by_clk(hwmgr, |
a23eefa2 RZ |
1505 | table_info->vdd_dep_on_mclk, |
1506 | table->MemoryACPILevel.MclkFrequency, | |
1507 | &table->MemoryACPILevel.MinVoltage, &mvdd); | |
1508 | PP_ASSERT_WITH_CODE((0 == result), | |
1509 | "Cannot find ACPI VDDCI voltage value " | |
1510 | "in Clock Dependency Table", | |
1511 | ); | |
1512 | } else { | |
1513 | table->MemoryACPILevel.MclkFrequency = | |
1514 | data->vbios_boot_state.mclk_bootup_value; | |
1515 | table->MemoryACPILevel.MinVoltage = | |
1516 | data->vbios_boot_state.vddci_bootup_value * VOLTAGE_SCALE; | |
1517 | } | |
1518 | ||
1519 | us_mvdd = 0; | |
2cc0c0b5 | 1520 | if ((POLARIS10_VOLTAGE_CONTROL_NONE == data->mvdd_control) || |
a23eefa2 RZ |
1521 | (data->mclk_dpm_key_disabled)) |
1522 | us_mvdd = data->vbios_boot_state.mvdd_bootup_value; | |
1523 | else { | |
2cc0c0b5 | 1524 | if (!polaris10_populate_mvdd_value(hwmgr, |
a23eefa2 RZ |
1525 | data->dpm_table.mclk_table.dpm_levels[0].value, |
1526 | &vol_level)) | |
1527 | us_mvdd = vol_level.Voltage; | |
1528 | } | |
1529 | ||
2cc0c0b5 | 1530 | if (0 == polaris10_populate_mvdd_value(hwmgr, 0, &vol_level)) |
a23eefa2 RZ |
1531 | table->MemoryACPILevel.MinMvdd = PP_HOST_TO_SMC_UL(vol_level.Voltage); |
1532 | else | |
1533 | table->MemoryACPILevel.MinMvdd = 0; | |
1534 | ||
1535 | table->MemoryACPILevel.StutterEnable = false; | |
1536 | ||
1537 | table->MemoryACPILevel.EnabledForThrottle = 0; | |
1538 | table->MemoryACPILevel.EnabledForActivity = 0; | |
1539 | table->MemoryACPILevel.UpHyst = 0; | |
1540 | table->MemoryACPILevel.DownHyst = 100; | |
1541 | table->MemoryACPILevel.VoltageDownHyst = 0; | |
1542 | table->MemoryACPILevel.ActivityLevel = | |
1543 | PP_HOST_TO_SMC_US((uint16_t)data->mclk_activity_target); | |
1544 | ||
1545 | CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MclkFrequency); | |
1546 | CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MinVoltage); | |
1547 | ||
1548 | return result; | |
1549 | } | |
1550 | ||
2cc0c0b5 | 1551 | static int polaris10_populate_smc_vce_level(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
1552 | SMU74_Discrete_DpmTable *table) |
1553 | { | |
1554 | int result = -EINVAL; | |
1555 | uint8_t count; | |
1556 | struct pp_atomctrl_clock_dividers_vi dividers; | |
1557 | struct phm_ppt_v1_information *table_info = | |
1558 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
1559 | struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table = | |
1560 | table_info->mm_dep_table; | |
2cc0c0b5 | 1561 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
1562 | |
1563 | table->VceLevelCount = (uint8_t)(mm_table->count); | |
1564 | table->VceBootLevel = 0; | |
1565 | ||
1566 | for (count = 0; count < table->VceLevelCount; count++) { | |
1567 | table->VceLevel[count].Frequency = mm_table->entries[count].eclk; | |
1568 | table->VceLevel[count].MinVoltage |= | |
1569 | (mm_table->entries[count].vddc * VOLTAGE_SCALE) << VDDC_SHIFT; | |
1570 | table->VceLevel[count].MinVoltage |= | |
1571 | ((mm_table->entries[count].vddc - data->vddc_vddci_delta) * | |
1572 | VOLTAGE_SCALE) << VDDCI_SHIFT; | |
1573 | table->VceLevel[count].MinVoltage |= 1 << PHASES_SHIFT; | |
1574 | ||
1575 | /*retrieve divider value for VBIOS */ | |
1576 | result = atomctrl_get_dfs_pll_dividers_vi(hwmgr, | |
1577 | table->VceLevel[count].Frequency, ÷rs); | |
1578 | PP_ASSERT_WITH_CODE((0 == result), | |
1579 | "can not find divide id for VCE engine clock", | |
1580 | return result); | |
1581 | ||
1582 | table->VceLevel[count].Divider = (uint8_t)dividers.pll_post_divider; | |
1583 | ||
1584 | CONVERT_FROM_HOST_TO_SMC_UL(table->VceLevel[count].Frequency); | |
1585 | CONVERT_FROM_HOST_TO_SMC_UL(table->VceLevel[count].MinVoltage); | |
1586 | } | |
1587 | return result; | |
1588 | } | |
1589 | ||
2cc0c0b5 | 1590 | static int polaris10_populate_smc_samu_level(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
1591 | SMU74_Discrete_DpmTable *table) |
1592 | { | |
1593 | int result = -EINVAL; | |
1594 | uint8_t count; | |
1595 | struct pp_atomctrl_clock_dividers_vi dividers; | |
1596 | struct phm_ppt_v1_information *table_info = | |
1597 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
1598 | struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table = | |
1599 | table_info->mm_dep_table; | |
2cc0c0b5 | 1600 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
1601 | |
1602 | table->SamuBootLevel = 0; | |
1603 | table->SamuLevelCount = (uint8_t)(mm_table->count); | |
1604 | ||
1605 | for (count = 0; count < table->SamuLevelCount; count++) { | |
1606 | /* not sure whether we need evclk or not */ | |
1607 | table->SamuLevel[count].Frequency = mm_table->entries[count].samclock; | |
1608 | table->SamuLevel[count].MinVoltage |= (mm_table->entries[count].vddc * | |
1609 | VOLTAGE_SCALE) << VDDC_SHIFT; | |
1610 | table->SamuLevel[count].MinVoltage |= ((mm_table->entries[count].vddc - | |
1611 | data->vddc_vddci_delta) * VOLTAGE_SCALE) << VDDCI_SHIFT; | |
1612 | table->SamuLevel[count].MinVoltage |= 1 << PHASES_SHIFT; | |
1613 | ||
1614 | /* retrieve divider value for VBIOS */ | |
1615 | result = atomctrl_get_dfs_pll_dividers_vi(hwmgr, | |
1616 | table->SamuLevel[count].Frequency, ÷rs); | |
1617 | PP_ASSERT_WITH_CODE((0 == result), | |
1618 | "can not find divide id for samu clock", return result); | |
1619 | ||
1620 | table->SamuLevel[count].Divider = (uint8_t)dividers.pll_post_divider; | |
1621 | ||
1622 | CONVERT_FROM_HOST_TO_SMC_UL(table->SamuLevel[count].Frequency); | |
1623 | CONVERT_FROM_HOST_TO_SMC_UL(table->SamuLevel[count].MinVoltage); | |
1624 | } | |
1625 | return result; | |
1626 | } | |
1627 | ||
2cc0c0b5 | 1628 | static int polaris10_populate_memory_timing_parameters(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
1629 | int32_t eng_clock, int32_t mem_clock, |
1630 | SMU74_Discrete_MCArbDramTimingTableEntry *arb_regs) | |
1631 | { | |
1632 | uint32_t dram_timing; | |
1633 | uint32_t dram_timing2; | |
1634 | uint32_t burst_time; | |
1635 | int result; | |
1636 | ||
1637 | result = atomctrl_set_engine_dram_timings_rv770(hwmgr, | |
1638 | eng_clock, mem_clock); | |
1639 | PP_ASSERT_WITH_CODE(result == 0, | |
1640 | "Error calling VBIOS to set DRAM_TIMING.", return result); | |
1641 | ||
1642 | dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING); | |
1643 | dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2); | |
1644 | burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0); | |
1645 | ||
1646 | ||
1647 | arb_regs->McArbDramTiming = PP_HOST_TO_SMC_UL(dram_timing); | |
1648 | arb_regs->McArbDramTiming2 = PP_HOST_TO_SMC_UL(dram_timing2); | |
1649 | arb_regs->McArbBurstTime = (uint8_t)burst_time; | |
1650 | ||
1651 | return 0; | |
1652 | } | |
1653 | ||
2cc0c0b5 | 1654 | static int polaris10_program_memory_timing_parameters(struct pp_hwmgr *hwmgr) |
a23eefa2 | 1655 | { |
2cc0c0b5 | 1656 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
1657 | struct SMU74_Discrete_MCArbDramTimingTable arb_regs; |
1658 | uint32_t i, j; | |
1659 | int result = 0; | |
1660 | ||
1661 | for (i = 0; i < data->dpm_table.sclk_table.count; i++) { | |
1662 | for (j = 0; j < data->dpm_table.mclk_table.count; j++) { | |
2cc0c0b5 | 1663 | result = polaris10_populate_memory_timing_parameters(hwmgr, |
a23eefa2 RZ |
1664 | data->dpm_table.sclk_table.dpm_levels[i].value, |
1665 | data->dpm_table.mclk_table.dpm_levels[j].value, | |
1666 | &arb_regs.entries[i][j]); | |
1667 | if (result == 0) | |
1668 | result = atomctrl_set_ac_timing_ai(hwmgr, data->dpm_table.mclk_table.dpm_levels[j].value, j); | |
1669 | if (result != 0) | |
1670 | return result; | |
1671 | } | |
1672 | } | |
1673 | ||
2cc0c0b5 | 1674 | result = polaris10_copy_bytes_to_smc( |
a23eefa2 RZ |
1675 | hwmgr->smumgr, |
1676 | data->arb_table_start, | |
1677 | (uint8_t *)&arb_regs, | |
1678 | sizeof(SMU74_Discrete_MCArbDramTimingTable), | |
1679 | data->sram_end); | |
1680 | return result; | |
1681 | } | |
1682 | ||
2cc0c0b5 | 1683 | static int polaris10_populate_smc_uvd_level(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
1684 | struct SMU74_Discrete_DpmTable *table) |
1685 | { | |
1686 | int result = -EINVAL; | |
1687 | uint8_t count; | |
1688 | struct pp_atomctrl_clock_dividers_vi dividers; | |
1689 | struct phm_ppt_v1_information *table_info = | |
1690 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
1691 | struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table = | |
1692 | table_info->mm_dep_table; | |
2cc0c0b5 | 1693 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
1694 | |
1695 | table->UvdLevelCount = (uint8_t)(mm_table->count); | |
1696 | table->UvdBootLevel = 0; | |
1697 | ||
1698 | for (count = 0; count < table->UvdLevelCount; count++) { | |
1699 | table->UvdLevel[count].VclkFrequency = mm_table->entries[count].vclk; | |
1700 | table->UvdLevel[count].DclkFrequency = mm_table->entries[count].dclk; | |
1701 | table->UvdLevel[count].MinVoltage |= (mm_table->entries[count].vddc * | |
1702 | VOLTAGE_SCALE) << VDDC_SHIFT; | |
1703 | table->UvdLevel[count].MinVoltage |= ((mm_table->entries[count].vddc - | |
1704 | data->vddc_vddci_delta) * VOLTAGE_SCALE) << VDDCI_SHIFT; | |
1705 | table->UvdLevel[count].MinVoltage |= 1 << PHASES_SHIFT; | |
1706 | ||
1707 | /* retrieve divider value for VBIOS */ | |
1708 | result = atomctrl_get_dfs_pll_dividers_vi(hwmgr, | |
1709 | table->UvdLevel[count].VclkFrequency, ÷rs); | |
1710 | PP_ASSERT_WITH_CODE((0 == result), | |
1711 | "can not find divide id for Vclk clock", return result); | |
1712 | ||
1713 | table->UvdLevel[count].VclkDivider = (uint8_t)dividers.pll_post_divider; | |
1714 | ||
1715 | result = atomctrl_get_dfs_pll_dividers_vi(hwmgr, | |
1716 | table->UvdLevel[count].DclkFrequency, ÷rs); | |
1717 | PP_ASSERT_WITH_CODE((0 == result), | |
1718 | "can not find divide id for Dclk clock", return result); | |
1719 | ||
1720 | table->UvdLevel[count].DclkDivider = (uint8_t)dividers.pll_post_divider; | |
1721 | ||
1722 | CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].VclkFrequency); | |
1723 | CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].DclkFrequency); | |
1724 | CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].MinVoltage); | |
1725 | ||
1726 | } | |
1727 | return result; | |
1728 | } | |
1729 | ||
2cc0c0b5 | 1730 | static int polaris10_populate_smc_boot_level(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
1731 | struct SMU74_Discrete_DpmTable *table) |
1732 | { | |
1733 | int result = 0; | |
2cc0c0b5 | 1734 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
1735 | |
1736 | table->GraphicsBootLevel = 0; | |
1737 | table->MemoryBootLevel = 0; | |
1738 | ||
1739 | /* find boot level from dpm table */ | |
1740 | result = phm_find_boot_level(&(data->dpm_table.sclk_table), | |
1741 | data->vbios_boot_state.sclk_bootup_value, | |
1742 | (uint32_t *)&(table->GraphicsBootLevel)); | |
1743 | ||
1744 | result = phm_find_boot_level(&(data->dpm_table.mclk_table), | |
1745 | data->vbios_boot_state.mclk_bootup_value, | |
1746 | (uint32_t *)&(table->MemoryBootLevel)); | |
1747 | ||
1748 | table->BootVddc = data->vbios_boot_state.vddc_bootup_value * | |
1749 | VOLTAGE_SCALE; | |
1750 | table->BootVddci = data->vbios_boot_state.vddci_bootup_value * | |
1751 | VOLTAGE_SCALE; | |
1752 | table->BootMVdd = data->vbios_boot_state.mvdd_bootup_value * | |
1753 | VOLTAGE_SCALE; | |
1754 | ||
1755 | CONVERT_FROM_HOST_TO_SMC_US(table->BootVddc); | |
1756 | CONVERT_FROM_HOST_TO_SMC_US(table->BootVddci); | |
1757 | CONVERT_FROM_HOST_TO_SMC_US(table->BootMVdd); | |
1758 | ||
1759 | return 0; | |
1760 | } | |
1761 | ||
1762 | ||
2cc0c0b5 | 1763 | static int polaris10_populate_smc_initailial_state(struct pp_hwmgr *hwmgr) |
a23eefa2 | 1764 | { |
2cc0c0b5 | 1765 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
1766 | struct phm_ppt_v1_information *table_info = |
1767 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
1768 | uint8_t count, level; | |
1769 | ||
1770 | count = (uint8_t)(table_info->vdd_dep_on_sclk->count); | |
1771 | ||
1772 | for (level = 0; level < count; level++) { | |
1773 | if (table_info->vdd_dep_on_sclk->entries[level].clk >= | |
1774 | data->vbios_boot_state.sclk_bootup_value) { | |
1775 | data->smc_state_table.GraphicsBootLevel = level; | |
1776 | break; | |
1777 | } | |
1778 | } | |
1779 | ||
1780 | count = (uint8_t)(table_info->vdd_dep_on_mclk->count); | |
1781 | for (level = 0; level < count; level++) { | |
1782 | if (table_info->vdd_dep_on_mclk->entries[level].clk >= | |
1783 | data->vbios_boot_state.mclk_bootup_value) { | |
1784 | data->smc_state_table.MemoryBootLevel = level; | |
1785 | break; | |
1786 | } | |
1787 | } | |
1788 | ||
1789 | return 0; | |
1790 | } | |
1791 | ||
2cc0c0b5 | 1792 | static int polaris10_populate_clock_stretcher_data_table(struct pp_hwmgr *hwmgr) |
a23eefa2 RZ |
1793 | { |
1794 | uint32_t ro, efuse, efuse2, clock_freq, volt_without_cks, | |
1795 | volt_with_cks, value; | |
1796 | uint16_t clock_freq_u16; | |
2cc0c0b5 | 1797 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
1798 | uint8_t type, i, j, cks_setting, stretch_amount, stretch_amount2, |
1799 | volt_offset = 0; | |
1800 | struct phm_ppt_v1_information *table_info = | |
1801 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
1802 | struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table = | |
1803 | table_info->vdd_dep_on_sclk; | |
1804 | ||
1805 | stretch_amount = (uint8_t)table_info->cac_dtp_table->usClockStretchAmount; | |
1806 | ||
1807 | /* Read SMU_Eefuse to read and calculate RO and determine | |
1808 | * if the part is SS or FF. if RO >= 1660MHz, part is FF. | |
1809 | */ | |
1810 | efuse = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
1811 | ixSMU_EFUSE_0 + (146 * 4)); | |
1812 | efuse2 = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
1813 | ixSMU_EFUSE_0 + (148 * 4)); | |
1814 | efuse &= 0xFF000000; | |
1815 | efuse = efuse >> 24; | |
1816 | efuse2 &= 0xF; | |
1817 | ||
1818 | if (efuse2 == 1) | |
1819 | ro = (2300 - 1350) * efuse / 255 + 1350; | |
1820 | else | |
1821 | ro = (2500 - 1000) * efuse / 255 + 1000; | |
1822 | ||
1823 | if (ro >= 1660) | |
1824 | type = 0; | |
1825 | else | |
1826 | type = 1; | |
1827 | ||
1828 | /* Populate Stretch amount */ | |
1829 | data->smc_state_table.ClockStretcherAmount = stretch_amount; | |
1830 | ||
1831 | /* Populate Sclk_CKS_masterEn0_7 and Sclk_voltageOffset */ | |
1832 | for (i = 0; i < sclk_table->count; i++) { | |
1833 | data->smc_state_table.Sclk_CKS_masterEn0_7 |= | |
1834 | sclk_table->entries[i].cks_enable << i; | |
1835 | volt_without_cks = (uint32_t)((14041 * | |
1836 | (sclk_table->entries[i].clk/100) / 10000 + 3571 + 75 - ro) * 1000 / | |
1837 | (4026 - (13924 * (sclk_table->entries[i].clk/100) / 10000))); | |
1838 | volt_with_cks = (uint32_t)((13946 * | |
1839 | (sclk_table->entries[i].clk/100) / 10000 + 3320 + 45 - ro) * 1000 / | |
1840 | (3664 - (11454 * (sclk_table->entries[i].clk/100) / 10000))); | |
1841 | if (volt_without_cks >= volt_with_cks) | |
1842 | volt_offset = (uint8_t)(((volt_without_cks - volt_with_cks + | |
1843 | sclk_table->entries[i].cks_voffset) * 100 / 625) + 1); | |
1844 | data->smc_state_table.Sclk_voltageOffset[i] = volt_offset; | |
1845 | } | |
1846 | ||
1847 | PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE, | |
1848 | STRETCH_ENABLE, 0x0); | |
1849 | PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE, | |
1850 | masterReset, 0x1); | |
1851 | /* PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE, staticEnable, 0x1); */ | |
1852 | PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE, | |
1853 | masterReset, 0x0); | |
1854 | ||
1855 | /* Populate CKS Lookup Table */ | |
1856 | if (stretch_amount == 1 || stretch_amount == 2 || stretch_amount == 5) | |
1857 | stretch_amount2 = 0; | |
1858 | else if (stretch_amount == 3 || stretch_amount == 4) | |
1859 | stretch_amount2 = 1; | |
1860 | else { | |
1861 | phm_cap_unset(hwmgr->platform_descriptor.platformCaps, | |
1862 | PHM_PlatformCaps_ClockStretcher); | |
1863 | PP_ASSERT_WITH_CODE(false, | |
1864 | "Stretch Amount in PPTable not supported\n", | |
1865 | return -EINVAL); | |
1866 | } | |
1867 | ||
1868 | value = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
1869 | ixPWR_CKS_CNTL); | |
1870 | value &= 0xFFC2FF87; | |
1871 | data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].minFreq = | |
2cc0c0b5 | 1872 | polaris10_clock_stretcher_lookup_table[stretch_amount2][0]; |
a23eefa2 | 1873 | data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].maxFreq = |
2cc0c0b5 | 1874 | polaris10_clock_stretcher_lookup_table[stretch_amount2][1]; |
a23eefa2 RZ |
1875 | clock_freq_u16 = (uint16_t)(PP_SMC_TO_HOST_UL(data->smc_state_table. |
1876 | GraphicsLevel[data->smc_state_table.GraphicsDpmLevelCount - 1].SclkSetting.SclkFrequency) / 100); | |
2cc0c0b5 FC |
1877 | if (polaris10_clock_stretcher_lookup_table[stretch_amount2][0] < clock_freq_u16 |
1878 | && polaris10_clock_stretcher_lookup_table[stretch_amount2][1] > clock_freq_u16) { | |
a23eefa2 | 1879 | /* Program PWR_CKS_CNTL. CKS_USE_FOR_LOW_FREQ */ |
2cc0c0b5 | 1880 | value |= (polaris10_clock_stretcher_lookup_table[stretch_amount2][3]) << 16; |
a23eefa2 | 1881 | /* Program PWR_CKS_CNTL. CKS_LDO_REFSEL */ |
2cc0c0b5 | 1882 | value |= (polaris10_clock_stretcher_lookup_table[stretch_amount2][2]) << 18; |
a23eefa2 | 1883 | /* Program PWR_CKS_CNTL. CKS_STRETCH_AMOUNT */ |
2cc0c0b5 FC |
1884 | value |= (polaris10_clock_stretch_amount_conversion |
1885 | [polaris10_clock_stretcher_lookup_table[stretch_amount2][3]] | |
a23eefa2 RZ |
1886 | [stretch_amount]) << 3; |
1887 | } | |
1888 | CONVERT_FROM_HOST_TO_SMC_US(data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].minFreq); | |
1889 | CONVERT_FROM_HOST_TO_SMC_US(data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].maxFreq); | |
1890 | data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].setting = | |
2cc0c0b5 | 1891 | polaris10_clock_stretcher_lookup_table[stretch_amount2][2] & 0x7F; |
a23eefa2 | 1892 | data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].setting |= |
2cc0c0b5 | 1893 | (polaris10_clock_stretcher_lookup_table[stretch_amount2][3]) << 7; |
a23eefa2 RZ |
1894 | |
1895 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
1896 | ixPWR_CKS_CNTL, value); | |
1897 | ||
1898 | /* Populate DDT Lookup Table */ | |
1899 | for (i = 0; i < 4; i++) { | |
1900 | /* Assign the minimum and maximum VID stored | |
1901 | * in the last row of Clock Stretcher Voltage Table. | |
1902 | */ | |
1903 | data->smc_state_table.ClockStretcherDataTable.ClockStretcherDataTableEntry[i].minVID = | |
2cc0c0b5 | 1904 | (uint8_t) polaris10_clock_stretcher_ddt_table[type][i][2]; |
a23eefa2 | 1905 | data->smc_state_table.ClockStretcherDataTable.ClockStretcherDataTableEntry[i].maxVID = |
2cc0c0b5 | 1906 | (uint8_t) polaris10_clock_stretcher_ddt_table[type][i][3]; |
a23eefa2 RZ |
1907 | /* Loop through each SCLK and check the frequency |
1908 | * to see if it lies within the frequency for clock stretcher. | |
1909 | */ | |
1910 | for (j = 0; j < data->smc_state_table.GraphicsDpmLevelCount; j++) { | |
1911 | cks_setting = 0; | |
1912 | clock_freq = PP_SMC_TO_HOST_UL( | |
1913 | data->smc_state_table.GraphicsLevel[j].SclkSetting.SclkFrequency); | |
1914 | /* Check the allowed frequency against the sclk level[j]. | |
1915 | * Sclk's endianness has already been converted, | |
1916 | * and it's in 10Khz unit, | |
1917 | * as opposed to Data table, which is in Mhz unit. | |
1918 | */ | |
2cc0c0b5 | 1919 | if (clock_freq >= (polaris10_clock_stretcher_ddt_table[type][i][0]) * 100) { |
a23eefa2 | 1920 | cks_setting |= 0x2; |
2cc0c0b5 | 1921 | if (clock_freq < (polaris10_clock_stretcher_ddt_table[type][i][1]) * 100) |
a23eefa2 RZ |
1922 | cks_setting |= 0x1; |
1923 | } | |
1924 | data->smc_state_table.ClockStretcherDataTable.ClockStretcherDataTableEntry[i].setting | |
1925 | |= cks_setting << (j * 2); | |
1926 | } | |
1927 | CONVERT_FROM_HOST_TO_SMC_US( | |
1928 | data->smc_state_table.ClockStretcherDataTable.ClockStretcherDataTableEntry[i].setting); | |
1929 | } | |
1930 | ||
1931 | value = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixPWR_CKS_CNTL); | |
1932 | value &= 0xFFFFFFFE; | |
1933 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixPWR_CKS_CNTL, value); | |
1934 | ||
1935 | return 0; | |
1936 | } | |
1937 | ||
1938 | /** | |
1939 | * Populates the SMC VRConfig field in DPM table. | |
1940 | * | |
1941 | * @param hwmgr the address of the hardware manager | |
1942 | * @param table the SMC DPM table structure to be populated | |
1943 | * @return always 0 | |
1944 | */ | |
2cc0c0b5 | 1945 | static int polaris10_populate_vr_config(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
1946 | struct SMU74_Discrete_DpmTable *table) |
1947 | { | |
2cc0c0b5 | 1948 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
1949 | uint16_t config; |
1950 | ||
1951 | config = VR_MERGED_WITH_VDDC; | |
1952 | table->VRConfig |= (config << VRCONF_VDDGFX_SHIFT); | |
1953 | ||
1954 | /* Set Vddc Voltage Controller */ | |
2cc0c0b5 | 1955 | if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) { |
a23eefa2 RZ |
1956 | config = VR_SVI2_PLANE_1; |
1957 | table->VRConfig |= config; | |
1958 | } else { | |
1959 | PP_ASSERT_WITH_CODE(false, | |
1960 | "VDDC should be on SVI2 control in merged mode!", | |
1961 | ); | |
1962 | } | |
1963 | /* Set Vddci Voltage Controller */ | |
2cc0c0b5 | 1964 | if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) { |
a23eefa2 RZ |
1965 | config = VR_SVI2_PLANE_2; /* only in merged mode */ |
1966 | table->VRConfig |= (config << VRCONF_VDDCI_SHIFT); | |
2cc0c0b5 | 1967 | } else if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) { |
a23eefa2 RZ |
1968 | config = VR_SMIO_PATTERN_1; |
1969 | table->VRConfig |= (config << VRCONF_VDDCI_SHIFT); | |
1970 | } else { | |
1971 | config = VR_STATIC_VOLTAGE; | |
1972 | table->VRConfig |= (config << VRCONF_VDDCI_SHIFT); | |
1973 | } | |
1974 | /* Set Mvdd Voltage Controller */ | |
2cc0c0b5 | 1975 | if (POLARIS10_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) { |
a23eefa2 RZ |
1976 | config = VR_SVI2_PLANE_2; |
1977 | table->VRConfig |= (config << VRCONF_MVDD_SHIFT); | |
2cc0c0b5 | 1978 | } else if (POLARIS10_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) { |
a23eefa2 RZ |
1979 | config = VR_SMIO_PATTERN_2; |
1980 | table->VRConfig |= (config << VRCONF_MVDD_SHIFT); | |
1981 | } else { | |
1982 | config = VR_STATIC_VOLTAGE; | |
1983 | table->VRConfig |= (config << VRCONF_MVDD_SHIFT); | |
1984 | } | |
1985 | ||
1986 | return 0; | |
1987 | } | |
1988 | ||
1989 | /** | |
1990 | * Initializes the SMC table and uploads it | |
1991 | * | |
1992 | * @param hwmgr the address of the powerplay hardware manager. | |
1993 | * @return always 0 | |
1994 | */ | |
2cc0c0b5 | 1995 | static int polaris10_init_smc_table(struct pp_hwmgr *hwmgr) |
a23eefa2 RZ |
1996 | { |
1997 | int result; | |
2cc0c0b5 | 1998 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
1999 | struct phm_ppt_v1_information *table_info = |
2000 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
2001 | struct SMU74_Discrete_DpmTable *table = &(data->smc_state_table); | |
2cc0c0b5 | 2002 | const struct polaris10_ulv_parm *ulv = &(data->ulv); |
a23eefa2 RZ |
2003 | uint8_t i; |
2004 | struct pp_atomctrl_gpio_pin_assignment gpio_pin; | |
e85c7d66 | 2005 | pp_atomctrl_clock_dividers_vi dividers; |
a23eefa2 | 2006 | |
2cc0c0b5 | 2007 | result = polaris10_setup_default_dpm_tables(hwmgr); |
a23eefa2 RZ |
2008 | PP_ASSERT_WITH_CODE(0 == result, |
2009 | "Failed to setup default DPM tables!", return result); | |
2010 | ||
2cc0c0b5 FC |
2011 | if (POLARIS10_VOLTAGE_CONTROL_NONE != data->voltage_control) |
2012 | polaris10_populate_smc_voltage_tables(hwmgr, table); | |
a23eefa2 RZ |
2013 | |
2014 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
2015 | PHM_PlatformCaps_AutomaticDCTransition)) | |
2016 | table->SystemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC; | |
2017 | ||
2018 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
2019 | PHM_PlatformCaps_StepVddc)) | |
2020 | table->SystemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC; | |
2021 | ||
2022 | if (data->is_memory_gddr5) | |
2023 | table->SystemFlags |= PPSMC_SYSTEMFLAG_GDDR5; | |
2024 | ||
2025 | if (ulv->ulv_supported && table_info->us_ulv_voltage_offset) { | |
2cc0c0b5 | 2026 | result = polaris10_populate_ulv_state(hwmgr, table); |
a23eefa2 RZ |
2027 | PP_ASSERT_WITH_CODE(0 == result, |
2028 | "Failed to initialize ULV state!", return result); | |
2029 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
2cc0c0b5 | 2030 | ixCG_ULV_PARAMETER, PPPOLARIS10_CGULVPARAMETER_DFLT); |
a23eefa2 RZ |
2031 | } |
2032 | ||
2cc0c0b5 | 2033 | result = polaris10_populate_smc_link_level(hwmgr, table); |
a23eefa2 RZ |
2034 | PP_ASSERT_WITH_CODE(0 == result, |
2035 | "Failed to initialize Link Level!", return result); | |
2036 | ||
2cc0c0b5 | 2037 | result = polaris10_populate_all_graphic_levels(hwmgr); |
a23eefa2 RZ |
2038 | PP_ASSERT_WITH_CODE(0 == result, |
2039 | "Failed to initialize Graphics Level!", return result); | |
2040 | ||
2cc0c0b5 | 2041 | result = polaris10_populate_all_memory_levels(hwmgr); |
a23eefa2 RZ |
2042 | PP_ASSERT_WITH_CODE(0 == result, |
2043 | "Failed to initialize Memory Level!", return result); | |
2044 | ||
2cc0c0b5 | 2045 | result = polaris10_populate_smc_acpi_level(hwmgr, table); |
a23eefa2 RZ |
2046 | PP_ASSERT_WITH_CODE(0 == result, |
2047 | "Failed to initialize ACPI Level!", return result); | |
2048 | ||
2cc0c0b5 | 2049 | result = polaris10_populate_smc_vce_level(hwmgr, table); |
a23eefa2 RZ |
2050 | PP_ASSERT_WITH_CODE(0 == result, |
2051 | "Failed to initialize VCE Level!", return result); | |
2052 | ||
2cc0c0b5 | 2053 | result = polaris10_populate_smc_samu_level(hwmgr, table); |
a23eefa2 RZ |
2054 | PP_ASSERT_WITH_CODE(0 == result, |
2055 | "Failed to initialize SAMU Level!", return result); | |
2056 | ||
2057 | /* Since only the initial state is completely set up at this point | |
2058 | * (the other states are just copies of the boot state) we only | |
2059 | * need to populate the ARB settings for the initial state. | |
2060 | */ | |
2cc0c0b5 | 2061 | result = polaris10_program_memory_timing_parameters(hwmgr); |
a23eefa2 RZ |
2062 | PP_ASSERT_WITH_CODE(0 == result, |
2063 | "Failed to Write ARB settings for the initial state.", return result); | |
2064 | ||
2cc0c0b5 | 2065 | result = polaris10_populate_smc_uvd_level(hwmgr, table); |
a23eefa2 RZ |
2066 | PP_ASSERT_WITH_CODE(0 == result, |
2067 | "Failed to initialize UVD Level!", return result); | |
2068 | ||
2cc0c0b5 | 2069 | result = polaris10_populate_smc_boot_level(hwmgr, table); |
a23eefa2 RZ |
2070 | PP_ASSERT_WITH_CODE(0 == result, |
2071 | "Failed to initialize Boot Level!", return result); | |
2072 | ||
2cc0c0b5 | 2073 | result = polaris10_populate_smc_initailial_state(hwmgr); |
a23eefa2 RZ |
2074 | PP_ASSERT_WITH_CODE(0 == result, |
2075 | "Failed to initialize Boot State!", return result); | |
2076 | ||
2cc0c0b5 | 2077 | result = polaris10_populate_bapm_parameters_in_dpm_table(hwmgr); |
a23eefa2 RZ |
2078 | PP_ASSERT_WITH_CODE(0 == result, |
2079 | "Failed to populate BAPM Parameters!", return result); | |
2080 | ||
2081 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
2082 | PHM_PlatformCaps_ClockStretcher)) { | |
2cc0c0b5 | 2083 | result = polaris10_populate_clock_stretcher_data_table(hwmgr); |
a23eefa2 RZ |
2084 | PP_ASSERT_WITH_CODE(0 == result, |
2085 | "Failed to populate Clock Stretcher Data Table!", | |
2086 | return result); | |
2087 | } | |
2088 | ||
2089 | table->GraphicsVoltageChangeEnable = 1; | |
2090 | table->GraphicsThermThrottleEnable = 1; | |
2091 | table->GraphicsInterval = 1; | |
2092 | table->VoltageInterval = 1; | |
2093 | table->ThermalInterval = 1; | |
2094 | table->TemperatureLimitHigh = | |
2095 | table_info->cac_dtp_table->usTargetOperatingTemp * | |
2cc0c0b5 | 2096 | POLARIS10_Q88_FORMAT_CONVERSION_UNIT; |
a23eefa2 RZ |
2097 | table->TemperatureLimitLow = |
2098 | (table_info->cac_dtp_table->usTargetOperatingTemp - 1) * | |
2cc0c0b5 | 2099 | POLARIS10_Q88_FORMAT_CONVERSION_UNIT; |
a23eefa2 RZ |
2100 | table->MemoryVoltageChangeEnable = 1; |
2101 | table->MemoryInterval = 1; | |
2102 | table->VoltageResponseTime = 0; | |
2103 | table->PhaseResponseTime = 0; | |
2104 | table->MemoryThermThrottleEnable = 1; | |
2105 | table->PCIeBootLinkLevel = 0; | |
2106 | table->PCIeGenInterval = 1; | |
2107 | ||
2cc0c0b5 | 2108 | result = polaris10_populate_vr_config(hwmgr, table); |
a23eefa2 RZ |
2109 | PP_ASSERT_WITH_CODE(0 == result, |
2110 | "Failed to populate VRConfig setting!", return result); | |
2111 | ||
2112 | table->ThermGpio = 17; | |
2113 | table->SclkStepSize = 0x4000; | |
2114 | ||
2115 | if (atomctrl_get_pp_assign_pin(hwmgr, VDDC_VRHOT_GPIO_PINID, &gpio_pin)) { | |
2116 | table->VRHotGpio = gpio_pin.uc_gpio_pin_bit_shift; | |
2117 | } else { | |
2cc0c0b5 | 2118 | table->VRHotGpio = POLARIS10_UNUSED_GPIO_PIN; |
a23eefa2 RZ |
2119 | phm_cap_unset(hwmgr->platform_descriptor.platformCaps, |
2120 | PHM_PlatformCaps_RegulatorHot); | |
2121 | } | |
2122 | ||
2123 | if (atomctrl_get_pp_assign_pin(hwmgr, PP_AC_DC_SWITCH_GPIO_PINID, | |
2124 | &gpio_pin)) { | |
2125 | table->AcDcGpio = gpio_pin.uc_gpio_pin_bit_shift; | |
2126 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
2127 | PHM_PlatformCaps_AutomaticDCTransition); | |
2128 | } else { | |
2cc0c0b5 | 2129 | table->AcDcGpio = POLARIS10_UNUSED_GPIO_PIN; |
a23eefa2 RZ |
2130 | phm_cap_unset(hwmgr->platform_descriptor.platformCaps, |
2131 | PHM_PlatformCaps_AutomaticDCTransition); | |
2132 | } | |
2133 | ||
2134 | /* Thermal Output GPIO */ | |
2135 | if (atomctrl_get_pp_assign_pin(hwmgr, THERMAL_INT_OUTPUT_GPIO_PINID, | |
2136 | &gpio_pin)) { | |
2137 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
2138 | PHM_PlatformCaps_ThermalOutGPIO); | |
2139 | ||
2140 | table->ThermOutGpio = gpio_pin.uc_gpio_pin_bit_shift; | |
2141 | ||
2142 | /* For porlarity read GPIOPAD_A with assigned Gpio pin | |
2143 | * since VBIOS will program this register to set 'inactive state', | |
2144 | * driver can then determine 'active state' from this and | |
2145 | * program SMU with correct polarity | |
2146 | */ | |
2147 | table->ThermOutPolarity = (0 == (cgs_read_register(hwmgr->device, mmGPIOPAD_A) | |
2148 | & (1 << gpio_pin.uc_gpio_pin_bit_shift))) ? 1:0; | |
2149 | table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_ONLY; | |
2150 | ||
2151 | /* if required, combine VRHot/PCC with thermal out GPIO */ | |
2152 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_RegulatorHot) | |
2153 | && phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_CombinePCCWithThermalSignal)) | |
2154 | table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_VRHOT; | |
2155 | } else { | |
2156 | table->ThermOutGpio = 17; | |
2157 | table->ThermOutPolarity = 1; | |
2158 | table->ThermOutMode = SMU7_THERM_OUT_MODE_DISABLE; | |
2159 | } | |
2160 | ||
e85c7d66 | 2161 | /* Populate BIF_SCLK levels into SMC DPM table */ |
2162 | for (i = 0; i <= data->dpm_table.pcie_speed_table.count; i++) { | |
2163 | result = atomctrl_get_dfs_pll_dividers_vi(hwmgr, data->bif_sclk_table[i], ÷rs); | |
2164 | PP_ASSERT_WITH_CODE((result == 0), "Can not find DFS divide id for Sclk", return result); | |
2165 | ||
2166 | if (i == 0) | |
2167 | table->Ulv.BifSclkDfs = PP_HOST_TO_SMC_US((USHORT)(dividers.pll_post_divider)); | |
2168 | else | |
2169 | table->LinkLevel[i-1].BifSclkDfs = PP_HOST_TO_SMC_US((USHORT)(dividers.pll_post_divider)); | |
2170 | } | |
2171 | ||
a23eefa2 RZ |
2172 | for (i = 0; i < SMU74_MAX_ENTRIES_SMIO; i++) |
2173 | table->Smio[i] = PP_HOST_TO_SMC_UL(table->Smio[i]); | |
2174 | ||
2175 | CONVERT_FROM_HOST_TO_SMC_UL(table->SystemFlags); | |
2176 | CONVERT_FROM_HOST_TO_SMC_UL(table->VRConfig); | |
2177 | CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask1); | |
2178 | CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask2); | |
2179 | CONVERT_FROM_HOST_TO_SMC_UL(table->SclkStepSize); | |
2180 | CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitHigh); | |
2181 | CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitLow); | |
2182 | CONVERT_FROM_HOST_TO_SMC_US(table->VoltageResponseTime); | |
2183 | CONVERT_FROM_HOST_TO_SMC_US(table->PhaseResponseTime); | |
2184 | ||
2185 | /* Upload all dpm data to SMC memory.(dpm level, dpm level count etc) */ | |
2cc0c0b5 | 2186 | result = polaris10_copy_bytes_to_smc(hwmgr->smumgr, |
a23eefa2 RZ |
2187 | data->dpm_table_start + |
2188 | offsetof(SMU74_Discrete_DpmTable, SystemFlags), | |
2189 | (uint8_t *)&(table->SystemFlags), | |
2190 | sizeof(SMU74_Discrete_DpmTable) - 3 * sizeof(SMU74_PIDController), | |
2191 | data->sram_end); | |
2192 | PP_ASSERT_WITH_CODE(0 == result, | |
2193 | "Failed to upload dpm data to SMC memory!", return result); | |
2194 | ||
2195 | return 0; | |
2196 | } | |
2197 | ||
2198 | /** | |
2199 | * Initialize the ARB DRAM timing table's index field. | |
2200 | * | |
2201 | * @param hwmgr the address of the powerplay hardware manager. | |
2202 | * @return always 0 | |
2203 | */ | |
2cc0c0b5 | 2204 | static int polaris10_init_arb_table_index(struct pp_hwmgr *hwmgr) |
a23eefa2 | 2205 | { |
2cc0c0b5 | 2206 | const struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
2207 | uint32_t tmp; |
2208 | int result; | |
2209 | ||
2210 | /* This is a read-modify-write on the first byte of the ARB table. | |
2211 | * The first byte in the SMU73_Discrete_MCArbDramTimingTable structure | |
2212 | * is the field 'current'. | |
2213 | * This solution is ugly, but we never write the whole table only | |
2214 | * individual fields in it. | |
2215 | * In reality this field should not be in that structure | |
2216 | * but in a soft register. | |
2217 | */ | |
2cc0c0b5 | 2218 | result = polaris10_read_smc_sram_dword(hwmgr->smumgr, |
a23eefa2 RZ |
2219 | data->arb_table_start, &tmp, data->sram_end); |
2220 | ||
2221 | if (result) | |
2222 | return result; | |
2223 | ||
2224 | tmp &= 0x00FFFFFF; | |
2225 | tmp |= ((uint32_t)MC_CG_ARB_FREQ_F1) << 24; | |
2226 | ||
2cc0c0b5 | 2227 | return polaris10_write_smc_sram_dword(hwmgr->smumgr, |
a23eefa2 RZ |
2228 | data->arb_table_start, tmp, data->sram_end); |
2229 | } | |
2230 | ||
2cc0c0b5 | 2231 | static int polaris10_enable_vrhot_gpio_interrupt(struct pp_hwmgr *hwmgr) |
a23eefa2 RZ |
2232 | { |
2233 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
2234 | PHM_PlatformCaps_RegulatorHot)) | |
2235 | return smum_send_msg_to_smc(hwmgr->smumgr, | |
2236 | PPSMC_MSG_EnableVRHotGPIOInterrupt); | |
2237 | ||
2238 | return 0; | |
2239 | } | |
2240 | ||
2cc0c0b5 | 2241 | static int polaris10_enable_sclk_control(struct pp_hwmgr *hwmgr) |
a23eefa2 RZ |
2242 | { |
2243 | PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL, | |
2244 | SCLK_PWRMGT_OFF, 0); | |
2245 | return 0; | |
2246 | } | |
2247 | ||
2cc0c0b5 | 2248 | static int polaris10_enable_ulv(struct pp_hwmgr *hwmgr) |
a23eefa2 | 2249 | { |
2cc0c0b5 FC |
2250 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
2251 | struct polaris10_ulv_parm *ulv = &(data->ulv); | |
a23eefa2 RZ |
2252 | |
2253 | if (ulv->ulv_supported) | |
2254 | return smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_EnableULV); | |
2255 | ||
2256 | return 0; | |
2257 | } | |
2258 | ||
2cc0c0b5 | 2259 | static int polaris10_enable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr) |
a23eefa2 RZ |
2260 | { |
2261 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
2262 | PHM_PlatformCaps_SclkDeepSleep)) { | |
2263 | if (smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_MASTER_DeepSleep_ON)) | |
2264 | PP_ASSERT_WITH_CODE(false, | |
2265 | "Attempt to enable Master Deep Sleep switch failed!", | |
2266 | return -1); | |
2267 | } else { | |
2268 | if (smum_send_msg_to_smc(hwmgr->smumgr, | |
2269 | PPSMC_MSG_MASTER_DeepSleep_OFF)) { | |
2270 | PP_ASSERT_WITH_CODE(false, | |
2271 | "Attempt to disable Master Deep Sleep switch failed!", | |
2272 | return -1); | |
2273 | } | |
2274 | } | |
2275 | ||
2276 | return 0; | |
2277 | } | |
2278 | ||
2cc0c0b5 | 2279 | static int polaris10_enable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr) |
a23eefa2 | 2280 | { |
2cc0c0b5 | 2281 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
2282 | |
2283 | /* enable SCLK dpm */ | |
2284 | if (!data->sclk_dpm_key_disabled) | |
2285 | PP_ASSERT_WITH_CODE( | |
2286 | (0 == smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_DPM_Enable)), | |
2287 | "Failed to enable SCLK DPM during DPM Start Function!", | |
2288 | return -1); | |
2289 | ||
2290 | /* enable MCLK dpm */ | |
2291 | if (0 == data->mclk_dpm_key_disabled) { | |
2292 | ||
2293 | PP_ASSERT_WITH_CODE( | |
2294 | (0 == smum_send_msg_to_smc(hwmgr->smumgr, | |
2295 | PPSMC_MSG_MCLKDPM_Enable)), | |
2296 | "Failed to enable MCLK DPM during DPM Start Function!", | |
2297 | return -1); | |
2298 | ||
2299 | ||
2300 | PHM_WRITE_FIELD(hwmgr->device, MC_SEQ_CNTL_3, CAC_EN, 0x1); | |
2301 | ||
2302 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC0_CNTL, 0x5); | |
2303 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC1_CNTL, 0x5); | |
2304 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_CPL_CNTL, 0x100005); | |
2305 | udelay(10); | |
2306 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC0_CNTL, 0x400005); | |
2307 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC1_CNTL, 0x400005); | |
2308 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_CPL_CNTL, 0x500005); | |
2309 | } | |
2310 | ||
2311 | return 0; | |
2312 | } | |
2313 | ||
2cc0c0b5 | 2314 | static int polaris10_start_dpm(struct pp_hwmgr *hwmgr) |
a23eefa2 | 2315 | { |
2cc0c0b5 | 2316 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
2317 | |
2318 | /*enable general power management */ | |
2319 | ||
2320 | PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT, | |
2321 | GLOBAL_PWRMGT_EN, 1); | |
2322 | ||
2323 | /* enable sclk deep sleep */ | |
2324 | ||
2325 | PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL, | |
2326 | DYNAMIC_PM_EN, 1); | |
2327 | ||
2328 | /* prepare for PCIE DPM */ | |
2329 | ||
2330 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
2331 | data->soft_regs_start + offsetof(SMU74_SoftRegisters, | |
2332 | VoltageChangeTimeout), 0x1000); | |
2333 | PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE, | |
2334 | SWRST_COMMAND_1, RESETLC, 0x0); | |
e85c7d66 | 2335 | /* |
a23eefa2 RZ |
2336 | PP_ASSERT_WITH_CODE( |
2337 | (0 == smum_send_msg_to_smc(hwmgr->smumgr, | |
2338 | PPSMC_MSG_Voltage_Cntl_Enable)), | |
2339 | "Failed to enable voltage DPM during DPM Start Function!", | |
2340 | return -1); | |
e85c7d66 | 2341 | */ |
a23eefa2 | 2342 | |
2cc0c0b5 | 2343 | if (polaris10_enable_sclk_mclk_dpm(hwmgr)) { |
a23eefa2 RZ |
2344 | printk(KERN_ERR "Failed to enable Sclk DPM and Mclk DPM!"); |
2345 | return -1; | |
2346 | } | |
2347 | ||
2348 | /* enable PCIE dpm */ | |
2349 | if (0 == data->pcie_dpm_key_disabled) { | |
2350 | PP_ASSERT_WITH_CODE( | |
2351 | (0 == smum_send_msg_to_smc(hwmgr->smumgr, | |
2352 | PPSMC_MSG_PCIeDPM_Enable)), | |
2353 | "Failed to enable pcie DPM during DPM Start Function!", | |
2354 | return -1); | |
2355 | } | |
2356 | ||
c8c67448 EH |
2357 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, |
2358 | PHM_PlatformCaps_Falcon_QuickTransition)) { | |
2359 | PP_ASSERT_WITH_CODE((0 == smum_send_msg_to_smc(hwmgr->smumgr, | |
2360 | PPSMC_MSG_EnableACDCGPIOInterrupt)), | |
2361 | "Failed to enable AC DC GPIO Interrupt!", | |
2362 | ); | |
2363 | } | |
a23eefa2 RZ |
2364 | |
2365 | return 0; | |
2366 | } | |
2367 | ||
2cc0c0b5 | 2368 | static void polaris10_set_dpm_event_sources(struct pp_hwmgr *hwmgr, uint32_t sources) |
a23eefa2 RZ |
2369 | { |
2370 | bool protection; | |
2371 | enum DPM_EVENT_SRC src; | |
2372 | ||
2373 | switch (sources) { | |
2374 | default: | |
2375 | printk(KERN_ERR "Unknown throttling event sources."); | |
2376 | /* fall through */ | |
2377 | case 0: | |
2378 | protection = false; | |
2379 | /* src is unused */ | |
2380 | break; | |
2381 | case (1 << PHM_AutoThrottleSource_Thermal): | |
2382 | protection = true; | |
2383 | src = DPM_EVENT_SRC_DIGITAL; | |
2384 | break; | |
2385 | case (1 << PHM_AutoThrottleSource_External): | |
2386 | protection = true; | |
2387 | src = DPM_EVENT_SRC_EXTERNAL; | |
2388 | break; | |
2389 | case (1 << PHM_AutoThrottleSource_External) | | |
2390 | (1 << PHM_AutoThrottleSource_Thermal): | |
2391 | protection = true; | |
2392 | src = DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL; | |
2393 | break; | |
2394 | } | |
2395 | /* Order matters - don't enable thermal protection for the wrong source. */ | |
2396 | if (protection) { | |
2397 | PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_THERMAL_CTRL, | |
2398 | DPM_EVENT_SRC, src); | |
2399 | PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT, | |
2400 | THERMAL_PROTECTION_DIS, | |
f0911de8 | 2401 | !phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, |
a23eefa2 RZ |
2402 | PHM_PlatformCaps_ThermalController)); |
2403 | } else | |
2404 | PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT, | |
2405 | THERMAL_PROTECTION_DIS, 1); | |
2406 | } | |
2407 | ||
2cc0c0b5 | 2408 | static int polaris10_enable_auto_throttle_source(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
2409 | PHM_AutoThrottleSource source) |
2410 | { | |
2cc0c0b5 | 2411 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
2412 | |
2413 | if (!(data->active_auto_throttle_sources & (1 << source))) { | |
2414 | data->active_auto_throttle_sources |= 1 << source; | |
2cc0c0b5 | 2415 | polaris10_set_dpm_event_sources(hwmgr, data->active_auto_throttle_sources); |
a23eefa2 RZ |
2416 | } |
2417 | return 0; | |
2418 | } | |
2419 | ||
2cc0c0b5 | 2420 | static int polaris10_enable_thermal_auto_throttle(struct pp_hwmgr *hwmgr) |
a23eefa2 | 2421 | { |
2cc0c0b5 | 2422 | return polaris10_enable_auto_throttle_source(hwmgr, PHM_AutoThrottleSource_Thermal); |
a23eefa2 RZ |
2423 | } |
2424 | ||
2cc0c0b5 | 2425 | int polaris10_pcie_performance_request(struct pp_hwmgr *hwmgr) |
a23eefa2 | 2426 | { |
2cc0c0b5 | 2427 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
2428 | data->pcie_performance_request = true; |
2429 | ||
2430 | return 0; | |
2431 | } | |
2432 | ||
2cc0c0b5 | 2433 | int polaris10_enable_dpm_tasks(struct pp_hwmgr *hwmgr) |
a23eefa2 RZ |
2434 | { |
2435 | int tmp_result, result = 0; | |
2cc0c0b5 | 2436 | tmp_result = (!polaris10_is_dpm_running(hwmgr)) ? 0 : -1; |
a23eefa2 RZ |
2437 | PP_ASSERT_WITH_CODE(result == 0, |
2438 | "DPM is already running right now, no need to enable DPM!", | |
2439 | return 0); | |
2440 | ||
2cc0c0b5 FC |
2441 | if (polaris10_voltage_control(hwmgr)) { |
2442 | tmp_result = polaris10_enable_voltage_control(hwmgr); | |
a23eefa2 RZ |
2443 | PP_ASSERT_WITH_CODE(tmp_result == 0, |
2444 | "Failed to enable voltage control!", | |
2445 | result = tmp_result); | |
2446 | ||
2cc0c0b5 | 2447 | tmp_result = polaris10_construct_voltage_tables(hwmgr); |
a23eefa2 RZ |
2448 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
2449 | "Failed to contruct voltage tables!", | |
2450 | result = tmp_result); | |
2451 | } | |
2452 | ||
2453 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
2454 | PHM_PlatformCaps_EngineSpreadSpectrumSupport)) | |
2455 | PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, | |
2456 | GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, 1); | |
2457 | ||
2458 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
2459 | PHM_PlatformCaps_ThermalController)) | |
2460 | PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, | |
2461 | GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, 0); | |
2462 | ||
2cc0c0b5 | 2463 | tmp_result = polaris10_program_static_screen_threshold_parameters(hwmgr); |
a23eefa2 RZ |
2464 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
2465 | "Failed to program static screen threshold parameters!", | |
2466 | result = tmp_result); | |
2467 | ||
2cc0c0b5 | 2468 | tmp_result = polaris10_enable_display_gap(hwmgr); |
a23eefa2 RZ |
2469 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
2470 | "Failed to enable display gap!", result = tmp_result); | |
2471 | ||
2cc0c0b5 | 2472 | tmp_result = polaris10_program_voting_clients(hwmgr); |
a23eefa2 RZ |
2473 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
2474 | "Failed to program voting clients!", result = tmp_result); | |
2475 | ||
2cc0c0b5 | 2476 | tmp_result = polaris10_process_firmware_header(hwmgr); |
a23eefa2 RZ |
2477 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
2478 | "Failed to process firmware header!", result = tmp_result); | |
2479 | ||
2cc0c0b5 | 2480 | tmp_result = polaris10_initial_switch_from_arbf0_to_f1(hwmgr); |
a23eefa2 RZ |
2481 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
2482 | "Failed to initialize switch from ArbF0 to F1!", | |
2483 | result = tmp_result); | |
2484 | ||
2cc0c0b5 | 2485 | tmp_result = polaris10_init_smc_table(hwmgr); |
a23eefa2 RZ |
2486 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
2487 | "Failed to initialize SMC table!", result = tmp_result); | |
2488 | ||
2cc0c0b5 | 2489 | tmp_result = polaris10_init_arb_table_index(hwmgr); |
a23eefa2 RZ |
2490 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
2491 | "Failed to initialize ARB table index!", result = tmp_result); | |
2492 | ||
2cc0c0b5 | 2493 | tmp_result = polaris10_populate_pm_fuses(hwmgr); |
a23eefa2 RZ |
2494 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
2495 | "Failed to populate PM fuses!", result = tmp_result); | |
2496 | ||
2cc0c0b5 | 2497 | tmp_result = polaris10_enable_vrhot_gpio_interrupt(hwmgr); |
a23eefa2 RZ |
2498 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
2499 | "Failed to enable VR hot GPIO interrupt!", result = tmp_result); | |
2500 | ||
2cc0c0b5 | 2501 | tmp_result = polaris10_enable_sclk_control(hwmgr); |
a23eefa2 RZ |
2502 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
2503 | "Failed to enable SCLK control!", result = tmp_result); | |
2504 | ||
2cc0c0b5 | 2505 | tmp_result = polaris10_enable_smc_voltage_controller(hwmgr); |
e85c7d66 | 2506 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
2507 | "Failed to enable voltage control!", result = tmp_result); | |
2508 | ||
2cc0c0b5 | 2509 | tmp_result = polaris10_enable_ulv(hwmgr); |
a23eefa2 RZ |
2510 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
2511 | "Failed to enable ULV!", result = tmp_result); | |
2512 | ||
2cc0c0b5 | 2513 | tmp_result = polaris10_enable_deep_sleep_master_switch(hwmgr); |
a23eefa2 RZ |
2514 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
2515 | "Failed to enable deep sleep master switch!", result = tmp_result); | |
2516 | ||
2cc0c0b5 | 2517 | tmp_result = polaris10_start_dpm(hwmgr); |
a23eefa2 RZ |
2518 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
2519 | "Failed to start DPM!", result = tmp_result); | |
2520 | ||
2cc0c0b5 | 2521 | tmp_result = polaris10_enable_smc_cac(hwmgr); |
a23eefa2 RZ |
2522 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
2523 | "Failed to enable SMC CAC!", result = tmp_result); | |
2524 | ||
2cc0c0b5 | 2525 | tmp_result = polaris10_enable_power_containment(hwmgr); |
a23eefa2 RZ |
2526 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
2527 | "Failed to enable power containment!", result = tmp_result); | |
2528 | ||
2cc0c0b5 | 2529 | tmp_result = polaris10_power_control_set_level(hwmgr); |
a23eefa2 RZ |
2530 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
2531 | "Failed to power control set level!", result = tmp_result); | |
2532 | ||
2cc0c0b5 | 2533 | tmp_result = polaris10_enable_thermal_auto_throttle(hwmgr); |
a23eefa2 RZ |
2534 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
2535 | "Failed to enable thermal auto throttle!", result = tmp_result); | |
2536 | ||
2cc0c0b5 | 2537 | tmp_result = polaris10_pcie_performance_request(hwmgr); |
a23eefa2 | 2538 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
5f88567c | 2539 | "pcie performance request failed!", result = tmp_result); |
a23eefa2 RZ |
2540 | |
2541 | return result; | |
2542 | } | |
2543 | ||
2cc0c0b5 | 2544 | int polaris10_disable_dpm_tasks(struct pp_hwmgr *hwmgr) |
a23eefa2 RZ |
2545 | { |
2546 | ||
2547 | return 0; | |
2548 | } | |
2549 | ||
2cc0c0b5 | 2550 | int polaris10_reset_asic_tasks(struct pp_hwmgr *hwmgr) |
a23eefa2 RZ |
2551 | { |
2552 | ||
2553 | return 0; | |
2554 | } | |
2555 | ||
2cc0c0b5 | 2556 | int polaris10_hwmgr_backend_fini(struct pp_hwmgr *hwmgr) |
a23eefa2 RZ |
2557 | { |
2558 | return phm_hwmgr_backend_fini(hwmgr); | |
2559 | } | |
2560 | ||
2cc0c0b5 | 2561 | int polaris10_set_features_platform_caps(struct pp_hwmgr *hwmgr) |
a23eefa2 | 2562 | { |
2cc0c0b5 | 2563 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
2564 | |
2565 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
2566 | PHM_PlatformCaps_SclkDeepSleep); | |
2567 | ||
f0911de8 RZ |
2568 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, |
2569 | PHM_PlatformCaps_DynamicPatchPowerState); | |
2570 | ||
2cc0c0b5 | 2571 | if (data->mvdd_control == POLARIS10_VOLTAGE_CONTROL_NONE) |
a23eefa2 RZ |
2572 | phm_cap_unset(hwmgr->platform_descriptor.platformCaps, |
2573 | PHM_PlatformCaps_EnableMVDDControl); | |
2574 | ||
2cc0c0b5 | 2575 | if (data->vddci_control == POLARIS10_VOLTAGE_CONTROL_NONE) |
a23eefa2 RZ |
2576 | phm_cap_unset(hwmgr->platform_descriptor.platformCaps, |
2577 | PHM_PlatformCaps_ControlVDDCI); | |
2578 | ||
2579 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
2580 | PHM_PlatformCaps_TablelessHardwareInterface); | |
2581 | ||
2582 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
2583 | PHM_PlatformCaps_EnableSMU7ThermalManagement); | |
2584 | ||
2585 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
2586 | PHM_PlatformCaps_DynamicPowerManagement); | |
2587 | ||
f0911de8 RZ |
2588 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, |
2589 | PHM_PlatformCaps_UnTabledHardwareInterface); | |
2590 | ||
a23eefa2 RZ |
2591 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, |
2592 | PHM_PlatformCaps_TablelessHardwareInterface); | |
2593 | ||
2594 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
2595 | PHM_PlatformCaps_SMC); | |
2596 | ||
2597 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
2598 | PHM_PlatformCaps_NonABMSupportInPPLib); | |
2599 | ||
2600 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
2601 | PHM_PlatformCaps_DynamicUVDState); | |
2602 | ||
2603 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
2604 | PHM_PlatformCaps_SclkThrottleLowNotification); | |
2605 | ||
2606 | /* power tune caps Assume disabled */ | |
a23eefa2 RZ |
2607 | phm_cap_unset(hwmgr->platform_descriptor.platformCaps, |
2608 | PHM_PlatformCaps_SQRamping); | |
2609 | phm_cap_unset(hwmgr->platform_descriptor.platformCaps, | |
2610 | PHM_PlatformCaps_DBRamping); | |
2611 | phm_cap_unset(hwmgr->platform_descriptor.platformCaps, | |
2612 | PHM_PlatformCaps_TDRamping); | |
2613 | phm_cap_unset(hwmgr->platform_descriptor.platformCaps, | |
2614 | PHM_PlatformCaps_TCPRamping); | |
2615 | ||
f0911de8 RZ |
2616 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, |
2617 | PHM_PlatformCaps_PowerContainment); | |
2618 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
2619 | PHM_PlatformCaps_CAC); | |
2620 | ||
2621 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
2622 | PHM_PlatformCaps_RegulatorHot); | |
2623 | ||
2624 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
2625 | PHM_PlatformCaps_AutomaticDCTransition); | |
2626 | ||
2627 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
2628 | PHM_PlatformCaps_ODFuzzyFanControlSupport); | |
2629 | ||
2630 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
2631 | PHM_PlatformCaps_FanSpeedInTableIsRPM); | |
5de95e55 RZ |
2632 | if (hwmgr->chip_id == CHIP_POLARIS11) |
2633 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
2634 | PHM_PlatformCaps_SPLLShutdownSupport); | |
a23eefa2 RZ |
2635 | return 0; |
2636 | } | |
2637 | ||
2cc0c0b5 | 2638 | static void polaris10_init_dpm_defaults(struct pp_hwmgr *hwmgr) |
a23eefa2 | 2639 | { |
2cc0c0b5 | 2640 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 | 2641 | |
2cc0c0b5 | 2642 | polaris10_initialize_power_tune_defaults(hwmgr); |
a23eefa2 RZ |
2643 | |
2644 | data->pcie_gen_performance.max = PP_PCIEGen1; | |
2645 | data->pcie_gen_performance.min = PP_PCIEGen3; | |
2646 | data->pcie_gen_power_saving.max = PP_PCIEGen1; | |
2647 | data->pcie_gen_power_saving.min = PP_PCIEGen3; | |
2648 | data->pcie_lane_performance.max = 0; | |
2649 | data->pcie_lane_performance.min = 16; | |
2650 | data->pcie_lane_power_saving.max = 0; | |
2651 | data->pcie_lane_power_saving.min = 16; | |
2652 | } | |
2653 | ||
2654 | /** | |
2655 | * Get Leakage VDDC based on leakage ID. | |
2656 | * | |
2657 | * @param hwmgr the address of the powerplay hardware manager. | |
2658 | * @return always 0 | |
2659 | */ | |
2cc0c0b5 | 2660 | static int polaris10_get_evv_voltages(struct pp_hwmgr *hwmgr) |
a23eefa2 | 2661 | { |
2cc0c0b5 | 2662 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
2663 | uint16_t vv_id; |
2664 | uint16_t vddc = 0; | |
2665 | uint16_t i, j; | |
2666 | uint32_t sclk = 0; | |
2667 | struct phm_ppt_v1_information *table_info = | |
2668 | (struct phm_ppt_v1_information *)hwmgr->pptable; | |
2669 | struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table = | |
2670 | table_info->vdd_dep_on_sclk; | |
2671 | int result; | |
2672 | ||
2cc0c0b5 | 2673 | for (i = 0; i < POLARIS10_MAX_LEAKAGE_COUNT; i++) { |
a23eefa2 RZ |
2674 | vv_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i; |
2675 | if (!phm_get_sclk_for_voltage_evv(hwmgr, | |
2676 | table_info->vddc_lookup_table, vv_id, &sclk)) { | |
2677 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
2678 | PHM_PlatformCaps_ClockStretcher)) { | |
2679 | for (j = 1; j < sclk_table->count; j++) { | |
2680 | if (sclk_table->entries[j].clk == sclk && | |
2681 | sclk_table->entries[j].cks_enable == 0) { | |
2682 | sclk += 5000; | |
2683 | break; | |
2684 | } | |
2685 | } | |
2686 | } | |
2687 | ||
2688 | ||
2689 | PP_ASSERT_WITH_CODE(0 == atomctrl_get_voltage_evv_on_sclk_ai(hwmgr, | |
2690 | VOLTAGE_TYPE_VDDC, sclk, vv_id, &vddc), | |
2691 | "Error retrieving EVV voltage value!", | |
2692 | continue); | |
2693 | ||
2694 | ||
2695 | /* need to make sure vddc is less than 2v or else, it could burn the ASIC. */ | |
2696 | PP_ASSERT_WITH_CODE((vddc < 2000 && vddc != 0), | |
2697 | "Invalid VDDC value", result = -EINVAL;); | |
2698 | ||
2699 | /* the voltage should not be zero nor equal to leakage ID */ | |
2700 | if (vddc != 0 && vddc != vv_id) { | |
2701 | data->vddc_leakage.actual_voltage[data->vddc_leakage.count] = (uint16_t)(vddc/100); | |
2702 | data->vddc_leakage.leakage_id[data->vddc_leakage.count] = vv_id; | |
2703 | data->vddc_leakage.count++; | |
2704 | } | |
2705 | } | |
2706 | } | |
2707 | ||
2708 | return 0; | |
2709 | } | |
2710 | ||
2711 | /** | |
2712 | * Change virtual leakage voltage to actual value. | |
2713 | * | |
2714 | * @param hwmgr the address of the powerplay hardware manager. | |
2715 | * @param pointer to changing voltage | |
2716 | * @param pointer to leakage table | |
2717 | */ | |
2cc0c0b5 FC |
2718 | static void polaris10_patch_with_vdd_leakage(struct pp_hwmgr *hwmgr, |
2719 | uint16_t *voltage, struct polaris10_leakage_voltage *leakage_table) | |
a23eefa2 RZ |
2720 | { |
2721 | uint32_t index; | |
2722 | ||
2723 | /* search for leakage voltage ID 0xff01 ~ 0xff08 */ | |
2724 | for (index = 0; index < leakage_table->count; index++) { | |
2725 | /* if this voltage matches a leakage voltage ID */ | |
2726 | /* patch with actual leakage voltage */ | |
2727 | if (leakage_table->leakage_id[index] == *voltage) { | |
2728 | *voltage = leakage_table->actual_voltage[index]; | |
2729 | break; | |
2730 | } | |
2731 | } | |
2732 | ||
2733 | if (*voltage > ATOM_VIRTUAL_VOLTAGE_ID0) | |
2734 | printk(KERN_ERR "Voltage value looks like a Leakage ID but it's not patched \n"); | |
2735 | } | |
2736 | ||
2737 | /** | |
2738 | * Patch voltage lookup table by EVV leakages. | |
2739 | * | |
2740 | * @param hwmgr the address of the powerplay hardware manager. | |
2741 | * @param pointer to voltage lookup table | |
2742 | * @param pointer to leakage table | |
2743 | * @return always 0 | |
2744 | */ | |
2cc0c0b5 | 2745 | static int polaris10_patch_lookup_table_with_leakage(struct pp_hwmgr *hwmgr, |
a23eefa2 | 2746 | phm_ppt_v1_voltage_lookup_table *lookup_table, |
2cc0c0b5 | 2747 | struct polaris10_leakage_voltage *leakage_table) |
a23eefa2 RZ |
2748 | { |
2749 | uint32_t i; | |
2750 | ||
2751 | for (i = 0; i < lookup_table->count; i++) | |
2cc0c0b5 | 2752 | polaris10_patch_with_vdd_leakage(hwmgr, |
a23eefa2 RZ |
2753 | &lookup_table->entries[i].us_vdd, leakage_table); |
2754 | ||
2755 | return 0; | |
2756 | } | |
2757 | ||
2cc0c0b5 FC |
2758 | static int polaris10_patch_clock_voltage_limits_with_vddc_leakage( |
2759 | struct pp_hwmgr *hwmgr, struct polaris10_leakage_voltage *leakage_table, | |
a23eefa2 RZ |
2760 | uint16_t *vddc) |
2761 | { | |
2762 | struct phm_ppt_v1_information *table_info = | |
2763 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
2cc0c0b5 | 2764 | polaris10_patch_with_vdd_leakage(hwmgr, (uint16_t *)vddc, leakage_table); |
a23eefa2 RZ |
2765 | hwmgr->dyn_state.max_clock_voltage_on_dc.vddc = |
2766 | table_info->max_clock_voltage_on_dc.vddc; | |
2767 | return 0; | |
2768 | } | |
2769 | ||
2cc0c0b5 | 2770 | static int polaris10_patch_voltage_dependency_tables_with_lookup_table( |
a23eefa2 RZ |
2771 | struct pp_hwmgr *hwmgr) |
2772 | { | |
2773 | uint8_t entryId; | |
2774 | uint8_t voltageId; | |
2775 | struct phm_ppt_v1_information *table_info = | |
2776 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
2777 | ||
2778 | struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table = | |
2779 | table_info->vdd_dep_on_sclk; | |
2780 | struct phm_ppt_v1_clock_voltage_dependency_table *mclk_table = | |
2781 | table_info->vdd_dep_on_mclk; | |
2782 | struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table = | |
2783 | table_info->mm_dep_table; | |
2784 | ||
2785 | for (entryId = 0; entryId < sclk_table->count; ++entryId) { | |
2786 | voltageId = sclk_table->entries[entryId].vddInd; | |
2787 | sclk_table->entries[entryId].vddc = | |
2788 | table_info->vddc_lookup_table->entries[voltageId].us_vdd; | |
2789 | } | |
2790 | ||
2791 | for (entryId = 0; entryId < mclk_table->count; ++entryId) { | |
2792 | voltageId = mclk_table->entries[entryId].vddInd; | |
2793 | mclk_table->entries[entryId].vddc = | |
2794 | table_info->vddc_lookup_table->entries[voltageId].us_vdd; | |
2795 | } | |
2796 | ||
2797 | for (entryId = 0; entryId < mm_table->count; ++entryId) { | |
2798 | voltageId = mm_table->entries[entryId].vddcInd; | |
2799 | mm_table->entries[entryId].vddc = | |
2800 | table_info->vddc_lookup_table->entries[voltageId].us_vdd; | |
2801 | } | |
2802 | ||
2803 | return 0; | |
2804 | ||
2805 | } | |
2806 | ||
2cc0c0b5 | 2807 | static int polaris10_calc_voltage_dependency_tables(struct pp_hwmgr *hwmgr) |
a23eefa2 RZ |
2808 | { |
2809 | /* Need to determine if we need calculated voltage. */ | |
2810 | return 0; | |
2811 | } | |
2812 | ||
2cc0c0b5 | 2813 | static int polaris10_calc_mm_voltage_dependency_table(struct pp_hwmgr *hwmgr) |
a23eefa2 RZ |
2814 | { |
2815 | /* Need to determine if we need calculated voltage from mm table. */ | |
2816 | return 0; | |
2817 | } | |
2818 | ||
2cc0c0b5 | 2819 | static int polaris10_sort_lookup_table(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
2820 | struct phm_ppt_v1_voltage_lookup_table *lookup_table) |
2821 | { | |
2822 | uint32_t table_size, i, j; | |
2823 | struct phm_ppt_v1_voltage_lookup_record tmp_voltage_lookup_record; | |
2824 | table_size = lookup_table->count; | |
2825 | ||
2826 | PP_ASSERT_WITH_CODE(0 != lookup_table->count, | |
2827 | "Lookup table is empty", return -EINVAL); | |
2828 | ||
2829 | /* Sorting voltages */ | |
2830 | for (i = 0; i < table_size - 1; i++) { | |
2831 | for (j = i + 1; j > 0; j--) { | |
2832 | if (lookup_table->entries[j].us_vdd < | |
2833 | lookup_table->entries[j - 1].us_vdd) { | |
2834 | tmp_voltage_lookup_record = lookup_table->entries[j - 1]; | |
2835 | lookup_table->entries[j - 1] = lookup_table->entries[j]; | |
2836 | lookup_table->entries[j] = tmp_voltage_lookup_record; | |
2837 | } | |
2838 | } | |
2839 | } | |
2840 | ||
2841 | return 0; | |
2842 | } | |
2843 | ||
2cc0c0b5 | 2844 | static int polaris10_complete_dependency_tables(struct pp_hwmgr *hwmgr) |
a23eefa2 RZ |
2845 | { |
2846 | int result = 0; | |
2847 | int tmp_result; | |
2cc0c0b5 | 2848 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
2849 | struct phm_ppt_v1_information *table_info = |
2850 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
2851 | ||
2cc0c0b5 | 2852 | tmp_result = polaris10_patch_lookup_table_with_leakage(hwmgr, |
a23eefa2 RZ |
2853 | table_info->vddc_lookup_table, &(data->vddc_leakage)); |
2854 | if (tmp_result) | |
2855 | result = tmp_result; | |
2856 | ||
2cc0c0b5 | 2857 | tmp_result = polaris10_patch_clock_voltage_limits_with_vddc_leakage(hwmgr, |
a23eefa2 RZ |
2858 | &(data->vddc_leakage), &table_info->max_clock_voltage_on_dc.vddc); |
2859 | if (tmp_result) | |
2860 | result = tmp_result; | |
2861 | ||
2cc0c0b5 | 2862 | tmp_result = polaris10_patch_voltage_dependency_tables_with_lookup_table(hwmgr); |
a23eefa2 RZ |
2863 | if (tmp_result) |
2864 | result = tmp_result; | |
2865 | ||
2cc0c0b5 | 2866 | tmp_result = polaris10_calc_voltage_dependency_tables(hwmgr); |
a23eefa2 RZ |
2867 | if (tmp_result) |
2868 | result = tmp_result; | |
2869 | ||
2cc0c0b5 | 2870 | tmp_result = polaris10_calc_mm_voltage_dependency_table(hwmgr); |
a23eefa2 RZ |
2871 | if (tmp_result) |
2872 | result = tmp_result; | |
2873 | ||
2cc0c0b5 | 2874 | tmp_result = polaris10_sort_lookup_table(hwmgr, table_info->vddc_lookup_table); |
a23eefa2 RZ |
2875 | if (tmp_result) |
2876 | result = tmp_result; | |
2877 | ||
2878 | return result; | |
2879 | } | |
2880 | ||
2cc0c0b5 | 2881 | static int polaris10_set_private_data_based_on_pptable(struct pp_hwmgr *hwmgr) |
a23eefa2 RZ |
2882 | { |
2883 | struct phm_ppt_v1_information *table_info = | |
2884 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
2885 | ||
2886 | struct phm_ppt_v1_clock_voltage_dependency_table *allowed_sclk_vdd_table = | |
2887 | table_info->vdd_dep_on_sclk; | |
2888 | struct phm_ppt_v1_clock_voltage_dependency_table *allowed_mclk_vdd_table = | |
2889 | table_info->vdd_dep_on_mclk; | |
2890 | ||
2891 | PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table != NULL, | |
2892 | "VDD dependency on SCLK table is missing. \ | |
2893 | This table is mandatory", return -EINVAL); | |
2894 | PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table->count >= 1, | |
2895 | "VDD dependency on SCLK table has to have is missing. \ | |
2896 | This table is mandatory", return -EINVAL); | |
2897 | ||
2898 | PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table != NULL, | |
2899 | "VDD dependency on MCLK table is missing. \ | |
2900 | This table is mandatory", return -EINVAL); | |
2901 | PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table->count >= 1, | |
2902 | "VDD dependency on MCLK table has to have is missing. \ | |
2903 | This table is mandatory", return -EINVAL); | |
2904 | ||
2905 | table_info->max_clock_voltage_on_ac.sclk = | |
2906 | allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].clk; | |
2907 | table_info->max_clock_voltage_on_ac.mclk = | |
2908 | allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].clk; | |
2909 | table_info->max_clock_voltage_on_ac.vddc = | |
2910 | allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].vddc; | |
2911 | table_info->max_clock_voltage_on_ac.vddci = | |
2912 | allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].vddci; | |
2913 | ||
f0911de8 RZ |
2914 | hwmgr->dyn_state.max_clock_voltage_on_ac.sclk = table_info->max_clock_voltage_on_ac.sclk; |
2915 | hwmgr->dyn_state.max_clock_voltage_on_ac.mclk = table_info->max_clock_voltage_on_ac.mclk; | |
2916 | hwmgr->dyn_state.max_clock_voltage_on_ac.vddc = table_info->max_clock_voltage_on_ac.vddc; | |
2917 | hwmgr->dyn_state.max_clock_voltage_on_ac.vddci =table_info->max_clock_voltage_on_ac.vddci; | |
2918 | ||
a23eefa2 RZ |
2919 | return 0; |
2920 | } | |
2921 | ||
2cc0c0b5 | 2922 | int polaris10_hwmgr_backend_init(struct pp_hwmgr *hwmgr) |
a23eefa2 | 2923 | { |
2cc0c0b5 | 2924 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
2925 | struct pp_atomctrl_gpio_pin_assignment gpio_pin_assignment; |
2926 | uint32_t temp_reg; | |
2927 | int result; | |
f0911de8 RZ |
2928 | struct phm_ppt_v1_information *table_info = |
2929 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
a23eefa2 RZ |
2930 | |
2931 | data->dll_default_on = false; | |
2932 | data->sram_end = SMC_RAM_END; | |
2933 | ||
2934 | data->disable_dpm_mask = 0xFF; | |
2cc0c0b5 FC |
2935 | data->static_screen_threshold = PPPOLARIS10_STATICSCREENTHRESHOLD_DFLT; |
2936 | data->static_screen_threshold_unit = PPPOLARIS10_STATICSCREENTHRESHOLD_DFLT; | |
2937 | data->activity_target[0] = PPPOLARIS10_TARGETACTIVITY_DFLT; | |
2938 | data->activity_target[1] = PPPOLARIS10_TARGETACTIVITY_DFLT; | |
2939 | data->activity_target[2] = PPPOLARIS10_TARGETACTIVITY_DFLT; | |
2940 | data->activity_target[3] = PPPOLARIS10_TARGETACTIVITY_DFLT; | |
2941 | data->activity_target[4] = PPPOLARIS10_TARGETACTIVITY_DFLT; | |
2942 | data->activity_target[5] = PPPOLARIS10_TARGETACTIVITY_DFLT; | |
2943 | data->activity_target[6] = PPPOLARIS10_TARGETACTIVITY_DFLT; | |
2944 | data->activity_target[7] = PPPOLARIS10_TARGETACTIVITY_DFLT; | |
2945 | ||
2946 | data->voting_rights_clients0 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT0; | |
2947 | data->voting_rights_clients1 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT1; | |
2948 | data->voting_rights_clients2 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT2; | |
2949 | data->voting_rights_clients3 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT3; | |
2950 | data->voting_rights_clients4 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT4; | |
2951 | data->voting_rights_clients5 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT5; | |
2952 | data->voting_rights_clients6 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT6; | |
2953 | data->voting_rights_clients7 = PPPOLARIS10_VOTINGRIGHTSCLIENTS_DFLT7; | |
a23eefa2 RZ |
2954 | |
2955 | data->vddc_vddci_delta = VDDC_VDDCI_DELTA; | |
2956 | ||
2cc0c0b5 | 2957 | data->mclk_activity_target = PPPOLARIS10_MCLK_TARGETACTIVITY_DFLT; |
a23eefa2 RZ |
2958 | |
2959 | /* need to set voltage control types before EVV patching */ | |
2cc0c0b5 FC |
2960 | data->voltage_control = POLARIS10_VOLTAGE_CONTROL_NONE; |
2961 | data->vddci_control = POLARIS10_VOLTAGE_CONTROL_NONE; | |
2962 | data->mvdd_control = POLARIS10_VOLTAGE_CONTROL_NONE; | |
a23eefa2 RZ |
2963 | |
2964 | if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr, | |
2965 | VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_SVID2)) | |
2cc0c0b5 | 2966 | data->voltage_control = POLARIS10_VOLTAGE_CONTROL_BY_SVID2; |
a23eefa2 | 2967 | |
a23eefa2 RZ |
2968 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, |
2969 | PHM_PlatformCaps_EnableMVDDControl)) { | |
2970 | if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr, | |
2971 | VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT)) | |
2cc0c0b5 | 2972 | data->mvdd_control = POLARIS10_VOLTAGE_CONTROL_BY_GPIO; |
a23eefa2 RZ |
2973 | else if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr, |
2974 | VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_SVID2)) | |
2cc0c0b5 | 2975 | data->mvdd_control = POLARIS10_VOLTAGE_CONTROL_BY_SVID2; |
a23eefa2 RZ |
2976 | } |
2977 | ||
2978 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
2979 | PHM_PlatformCaps_ControlVDDCI)) { | |
2980 | if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr, | |
2981 | VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT)) | |
2cc0c0b5 | 2982 | data->vddci_control = POLARIS10_VOLTAGE_CONTROL_BY_GPIO; |
a23eefa2 RZ |
2983 | else if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr, |
2984 | VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_SVID2)) | |
2cc0c0b5 | 2985 | data->vddci_control = POLARIS10_VOLTAGE_CONTROL_BY_SVID2; |
a23eefa2 RZ |
2986 | } |
2987 | ||
2cc0c0b5 | 2988 | polaris10_set_features_platform_caps(hwmgr); |
a23eefa2 | 2989 | |
2cc0c0b5 | 2990 | polaris10_init_dpm_defaults(hwmgr); |
a23eefa2 RZ |
2991 | |
2992 | /* Get leakage voltage based on leakage ID. */ | |
2cc0c0b5 | 2993 | result = polaris10_get_evv_voltages(hwmgr); |
a23eefa2 RZ |
2994 | |
2995 | if (result) { | |
2996 | printk("Get EVV Voltage Failed. Abort Driver loading!\n"); | |
2997 | return -1; | |
2998 | } | |
2999 | ||
2cc0c0b5 FC |
3000 | polaris10_complete_dependency_tables(hwmgr); |
3001 | polaris10_set_private_data_based_on_pptable(hwmgr); | |
a23eefa2 RZ |
3002 | |
3003 | /* Initalize Dynamic State Adjustment Rule Settings */ | |
3004 | result = phm_initializa_dynamic_state_adjustment_rule_settings(hwmgr); | |
3005 | ||
3006 | if (0 == result) { | |
3007 | struct cgs_system_info sys_info = {0}; | |
3008 | ||
3009 | data->is_tlu_enabled = 0; | |
3010 | ||
3011 | hwmgr->platform_descriptor.hardwareActivityPerformanceLevels = | |
2cc0c0b5 | 3012 | POLARIS10_MAX_HARDWARE_POWERLEVELS; |
a23eefa2 RZ |
3013 | hwmgr->platform_descriptor.hardwarePerformanceLevels = 2; |
3014 | hwmgr->platform_descriptor.minimumClocksReductionPercentage = 50; | |
f0911de8 | 3015 | |
a23eefa2 RZ |
3016 | |
3017 | if (atomctrl_get_pp_assign_pin(hwmgr, VDDC_PCC_GPIO_PINID, &gpio_pin_assignment)) { | |
3018 | temp_reg = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCNB_PWRMGT_CNTL); | |
3019 | switch (gpio_pin_assignment.uc_gpio_pin_bit_shift) { | |
3020 | case 0: | |
3021 | temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x1); | |
3022 | break; | |
3023 | case 1: | |
3024 | temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x2); | |
3025 | break; | |
3026 | case 2: | |
3027 | temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW, 0x1); | |
3028 | break; | |
3029 | case 3: | |
3030 | temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, FORCE_NB_PS1, 0x1); | |
3031 | break; | |
3032 | case 4: | |
3033 | temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, DPM_ENABLED, 0x1); | |
3034 | break; | |
3035 | default: | |
3036 | PP_ASSERT_WITH_CODE(0, | |
3037 | "Failed to setup PCC HW register! Wrong GPIO assigned for VDDC_PCC_GPIO_PINID!", | |
3038 | ); | |
3039 | break; | |
3040 | } | |
3041 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCNB_PWRMGT_CNTL, temp_reg); | |
3042 | } | |
3043 | ||
f0911de8 RZ |
3044 | if (table_info->cac_dtp_table->usDefaultTargetOperatingTemp != 0 && |
3045 | hwmgr->thermal_controller.advanceFanControlParameters.ucFanControlMode) { | |
3046 | hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMMinLimit = | |
3047 | (uint16_t)hwmgr->thermal_controller.advanceFanControlParameters.ucMinimumPWMLimit; | |
3048 | ||
3049 | hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMMaxLimit = | |
3050 | (uint16_t)hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanPWM; | |
3051 | ||
3052 | hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMStep = 1; | |
3053 | ||
3054 | hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMMaxLimit = 100; | |
3055 | ||
3056 | hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMMinLimit = | |
3057 | (uint16_t)hwmgr->thermal_controller.advanceFanControlParameters.ucMinimumPWMLimit; | |
3058 | ||
3059 | hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMStep = 1; | |
3060 | ||
3061 | table_info->cac_dtp_table->usDefaultTargetOperatingTemp = (table_info->cac_dtp_table->usDefaultTargetOperatingTemp >= 50) ? | |
3062 | (table_info->cac_dtp_table->usDefaultTargetOperatingTemp -50) : 0; | |
3063 | ||
3064 | table_info->cac_dtp_table->usOperatingTempMaxLimit = table_info->cac_dtp_table->usDefaultTargetOperatingTemp; | |
3065 | table_info->cac_dtp_table->usOperatingTempStep = 1; | |
3066 | table_info->cac_dtp_table->usOperatingTempHyst = 1; | |
3067 | ||
3068 | hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanPWM = | |
3069 | hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanPWM; | |
3070 | ||
3071 | hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanRPM = | |
3072 | hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanRPM; | |
3073 | ||
3074 | hwmgr->dyn_state.cac_dtp_table->usOperatingTempMinLimit = | |
3075 | table_info->cac_dtp_table->usOperatingTempMinLimit; | |
3076 | ||
3077 | hwmgr->dyn_state.cac_dtp_table->usOperatingTempMaxLimit = | |
3078 | table_info->cac_dtp_table->usOperatingTempMaxLimit; | |
3079 | ||
3080 | hwmgr->dyn_state.cac_dtp_table->usDefaultTargetOperatingTemp = | |
3081 | table_info->cac_dtp_table->usDefaultTargetOperatingTemp; | |
3082 | ||
3083 | hwmgr->dyn_state.cac_dtp_table->usOperatingTempStep = | |
3084 | table_info->cac_dtp_table->usOperatingTempStep; | |
3085 | ||
3086 | hwmgr->dyn_state.cac_dtp_table->usTargetOperatingTemp = | |
3087 | table_info->cac_dtp_table->usTargetOperatingTemp; | |
3088 | } | |
3089 | ||
a23eefa2 RZ |
3090 | sys_info.size = sizeof(struct cgs_system_info); |
3091 | sys_info.info_id = CGS_SYSTEM_INFO_PCIE_GEN_INFO; | |
3092 | result = cgs_query_system_info(hwmgr->device, &sys_info); | |
3093 | if (result) | |
3094 | data->pcie_gen_cap = 0x30007; | |
3095 | else | |
3096 | data->pcie_gen_cap = (uint32_t)sys_info.value; | |
3097 | if (data->pcie_gen_cap & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3) | |
3098 | data->pcie_spc_cap = 20; | |
3099 | sys_info.size = sizeof(struct cgs_system_info); | |
3100 | sys_info.info_id = CGS_SYSTEM_INFO_PCIE_MLW; | |
3101 | result = cgs_query_system_info(hwmgr->device, &sys_info); | |
3102 | if (result) | |
3103 | data->pcie_lane_cap = 0x2f0000; | |
3104 | else | |
3105 | data->pcie_lane_cap = (uint32_t)sys_info.value; | |
f0911de8 RZ |
3106 | |
3107 | hwmgr->platform_descriptor.vbiosInterruptId = 0x20000400; /* IRQ_SOURCE1_SW_INT */ | |
3108 | /* The true clock step depends on the frequency, typically 4.5 or 9 MHz. Here we use 5. */ | |
3109 | hwmgr->platform_descriptor.clockStep.engineClock = 500; | |
3110 | hwmgr->platform_descriptor.clockStep.memoryClock = 500; | |
a23eefa2 RZ |
3111 | } else { |
3112 | /* Ignore return value in here, we are cleaning up a mess. */ | |
2cc0c0b5 | 3113 | polaris10_hwmgr_backend_fini(hwmgr); |
a23eefa2 RZ |
3114 | } |
3115 | ||
3116 | return 0; | |
3117 | } | |
3118 | ||
2cc0c0b5 | 3119 | static int polaris10_force_dpm_highest(struct pp_hwmgr *hwmgr) |
a23eefa2 | 3120 | { |
2cc0c0b5 | 3121 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
3122 | uint32_t level, tmp; |
3123 | ||
3124 | if (!data->pcie_dpm_key_disabled) { | |
3125 | if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) { | |
3126 | level = 0; | |
3127 | tmp = data->dpm_level_enable_mask.pcie_dpm_enable_mask; | |
3128 | while (tmp >>= 1) | |
3129 | level++; | |
3130 | ||
3131 | if (level) | |
3132 | smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, | |
3133 | PPSMC_MSG_PCIeDPM_ForceLevel, level); | |
3134 | } | |
3135 | } | |
3136 | ||
3137 | if (!data->sclk_dpm_key_disabled) { | |
3138 | if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) { | |
3139 | level = 0; | |
3140 | tmp = data->dpm_level_enable_mask.sclk_dpm_enable_mask; | |
3141 | while (tmp >>= 1) | |
3142 | level++; | |
3143 | ||
3144 | if (level) | |
3145 | smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, | |
3146 | PPSMC_MSG_SCLKDPM_SetEnabledMask, | |
3147 | (1 << level)); | |
3148 | } | |
3149 | } | |
3150 | ||
3151 | if (!data->mclk_dpm_key_disabled) { | |
3152 | if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) { | |
3153 | level = 0; | |
3154 | tmp = data->dpm_level_enable_mask.mclk_dpm_enable_mask; | |
3155 | while (tmp >>= 1) | |
3156 | level++; | |
3157 | ||
3158 | if (level) | |
3159 | smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, | |
3160 | PPSMC_MSG_MCLKDPM_SetEnabledMask, | |
3161 | (1 << level)); | |
3162 | } | |
3163 | } | |
3164 | ||
3165 | return 0; | |
3166 | } | |
3167 | ||
2cc0c0b5 | 3168 | static int polaris10_upload_dpm_level_enable_mask(struct pp_hwmgr *hwmgr) |
a23eefa2 | 3169 | { |
2cc0c0b5 | 3170 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
3171 | |
3172 | phm_apply_dal_min_voltage_request(hwmgr); | |
3173 | ||
3174 | if (!data->sclk_dpm_key_disabled) { | |
3175 | if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) | |
3176 | smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, | |
3177 | PPSMC_MSG_SCLKDPM_SetEnabledMask, | |
3178 | data->dpm_level_enable_mask.sclk_dpm_enable_mask); | |
3179 | } | |
3180 | ||
3181 | if (!data->mclk_dpm_key_disabled) { | |
3182 | if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) | |
3183 | smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, | |
3184 | PPSMC_MSG_MCLKDPM_SetEnabledMask, | |
3185 | data->dpm_level_enable_mask.mclk_dpm_enable_mask); | |
3186 | } | |
3187 | ||
3188 | return 0; | |
3189 | } | |
3190 | ||
2cc0c0b5 | 3191 | static int polaris10_unforce_dpm_levels(struct pp_hwmgr *hwmgr) |
a23eefa2 | 3192 | { |
2cc0c0b5 | 3193 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 | 3194 | |
2cc0c0b5 | 3195 | if (!polaris10_is_dpm_running(hwmgr)) |
a23eefa2 RZ |
3196 | return -EINVAL; |
3197 | ||
3198 | if (!data->pcie_dpm_key_disabled) { | |
3199 | smum_send_msg_to_smc(hwmgr->smumgr, | |
3200 | PPSMC_MSG_PCIeDPM_UnForceLevel); | |
3201 | } | |
3202 | ||
2cc0c0b5 | 3203 | return polaris10_upload_dpm_level_enable_mask(hwmgr); |
a23eefa2 RZ |
3204 | } |
3205 | ||
2cc0c0b5 | 3206 | static int polaris10_force_dpm_lowest(struct pp_hwmgr *hwmgr) |
a23eefa2 | 3207 | { |
2cc0c0b5 FC |
3208 | struct polaris10_hwmgr *data = |
3209 | (struct polaris10_hwmgr *)(hwmgr->backend); | |
a23eefa2 RZ |
3210 | uint32_t level; |
3211 | ||
3212 | if (!data->sclk_dpm_key_disabled) | |
3213 | if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) { | |
3214 | level = phm_get_lowest_enabled_level(hwmgr, | |
3215 | data->dpm_level_enable_mask.sclk_dpm_enable_mask); | |
3216 | smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, | |
3217 | PPSMC_MSG_SCLKDPM_SetEnabledMask, | |
3218 | (1 << level)); | |
3219 | ||
3220 | } | |
2043f43e | 3221 | |
a23eefa2 RZ |
3222 | if (!data->mclk_dpm_key_disabled) { |
3223 | if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) { | |
3224 | level = phm_get_lowest_enabled_level(hwmgr, | |
3225 | data->dpm_level_enable_mask.mclk_dpm_enable_mask); | |
3226 | smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, | |
3227 | PPSMC_MSG_MCLKDPM_SetEnabledMask, | |
3228 | (1 << level)); | |
3229 | } | |
3230 | } | |
2043f43e | 3231 | |
a23eefa2 RZ |
3232 | if (!data->pcie_dpm_key_disabled) { |
3233 | if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) { | |
3234 | level = phm_get_lowest_enabled_level(hwmgr, | |
3235 | data->dpm_level_enable_mask.pcie_dpm_enable_mask); | |
3236 | smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, | |
3237 | PPSMC_MSG_PCIeDPM_ForceLevel, | |
3238 | (level)); | |
3239 | } | |
3240 | } | |
3241 | ||
3242 | return 0; | |
3243 | ||
3244 | } | |
2cc0c0b5 | 3245 | static int polaris10_force_dpm_level(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
3246 | enum amd_dpm_forced_level level) |
3247 | { | |
3248 | int ret = 0; | |
3249 | ||
3250 | switch (level) { | |
3251 | case AMD_DPM_FORCED_LEVEL_HIGH: | |
2cc0c0b5 | 3252 | ret = polaris10_force_dpm_highest(hwmgr); |
a23eefa2 RZ |
3253 | if (ret) |
3254 | return ret; | |
3255 | break; | |
3256 | case AMD_DPM_FORCED_LEVEL_LOW: | |
2cc0c0b5 | 3257 | ret = polaris10_force_dpm_lowest(hwmgr); |
a23eefa2 RZ |
3258 | if (ret) |
3259 | return ret; | |
3260 | break; | |
3261 | case AMD_DPM_FORCED_LEVEL_AUTO: | |
2cc0c0b5 | 3262 | ret = polaris10_unforce_dpm_levels(hwmgr); |
a23eefa2 RZ |
3263 | if (ret) |
3264 | return ret; | |
3265 | break; | |
3266 | default: | |
3267 | break; | |
3268 | } | |
3269 | ||
3270 | hwmgr->dpm_level = level; | |
3271 | ||
3272 | return ret; | |
3273 | } | |
3274 | ||
2cc0c0b5 | 3275 | static int polaris10_get_power_state_size(struct pp_hwmgr *hwmgr) |
a23eefa2 | 3276 | { |
2cc0c0b5 | 3277 | return sizeof(struct polaris10_power_state); |
a23eefa2 RZ |
3278 | } |
3279 | ||
3280 | ||
2cc0c0b5 | 3281 | static int polaris10_apply_state_adjust_rules(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
3282 | struct pp_power_state *request_ps, |
3283 | const struct pp_power_state *current_ps) | |
3284 | { | |
3285 | ||
2cc0c0b5 FC |
3286 | struct polaris10_power_state *polaris10_ps = |
3287 | cast_phw_polaris10_power_state(&request_ps->hardware); | |
a23eefa2 RZ |
3288 | uint32_t sclk; |
3289 | uint32_t mclk; | |
3290 | struct PP_Clocks minimum_clocks = {0}; | |
3291 | bool disable_mclk_switching; | |
3292 | bool disable_mclk_switching_for_frame_lock; | |
3293 | struct cgs_display_info info = {0}; | |
3294 | const struct phm_clock_and_voltage_limits *max_limits; | |
3295 | uint32_t i; | |
2cc0c0b5 | 3296 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
3297 | struct phm_ppt_v1_information *table_info = |
3298 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
3299 | int32_t count; | |
3300 | int32_t stable_pstate_sclk = 0, stable_pstate_mclk = 0; | |
3301 | ||
3302 | data->battery_state = (PP_StateUILabel_Battery == | |
3303 | request_ps->classification.ui_label); | |
3304 | ||
2cc0c0b5 | 3305 | PP_ASSERT_WITH_CODE(polaris10_ps->performance_level_count == 2, |
a23eefa2 RZ |
3306 | "VI should always have 2 performance levels", |
3307 | ); | |
3308 | ||
3309 | max_limits = (PP_PowerSource_AC == hwmgr->power_source) ? | |
3310 | &(hwmgr->dyn_state.max_clock_voltage_on_ac) : | |
3311 | &(hwmgr->dyn_state.max_clock_voltage_on_dc); | |
3312 | ||
3313 | /* Cap clock DPM tables at DC MAX if it is in DC. */ | |
3314 | if (PP_PowerSource_DC == hwmgr->power_source) { | |
2cc0c0b5 FC |
3315 | for (i = 0; i < polaris10_ps->performance_level_count; i++) { |
3316 | if (polaris10_ps->performance_levels[i].memory_clock > max_limits->mclk) | |
3317 | polaris10_ps->performance_levels[i].memory_clock = max_limits->mclk; | |
3318 | if (polaris10_ps->performance_levels[i].engine_clock > max_limits->sclk) | |
3319 | polaris10_ps->performance_levels[i].engine_clock = max_limits->sclk; | |
a23eefa2 RZ |
3320 | } |
3321 | } | |
3322 | ||
2cc0c0b5 FC |
3323 | polaris10_ps->vce_clks.evclk = hwmgr->vce_arbiter.evclk; |
3324 | polaris10_ps->vce_clks.ecclk = hwmgr->vce_arbiter.ecclk; | |
a23eefa2 RZ |
3325 | |
3326 | cgs_get_active_displays_info(hwmgr->device, &info); | |
3327 | ||
3328 | /*TO DO result = PHM_CheckVBlankTime(hwmgr, &vblankTooShort);*/ | |
3329 | ||
3330 | /* TO DO GetMinClockSettings(hwmgr->pPECI, &minimum_clocks); */ | |
3331 | ||
3332 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
3333 | PHM_PlatformCaps_StablePState)) { | |
3334 | max_limits = &(hwmgr->dyn_state.max_clock_voltage_on_ac); | |
3335 | stable_pstate_sclk = (max_limits->sclk * 75) / 100; | |
3336 | ||
3337 | for (count = table_info->vdd_dep_on_sclk->count - 1; | |
3338 | count >= 0; count--) { | |
3339 | if (stable_pstate_sclk >= | |
3340 | table_info->vdd_dep_on_sclk->entries[count].clk) { | |
3341 | stable_pstate_sclk = | |
3342 | table_info->vdd_dep_on_sclk->entries[count].clk; | |
3343 | break; | |
3344 | } | |
3345 | } | |
3346 | ||
3347 | if (count < 0) | |
3348 | stable_pstate_sclk = table_info->vdd_dep_on_sclk->entries[0].clk; | |
3349 | ||
3350 | stable_pstate_mclk = max_limits->mclk; | |
3351 | ||
3352 | minimum_clocks.engineClock = stable_pstate_sclk; | |
3353 | minimum_clocks.memoryClock = stable_pstate_mclk; | |
3354 | } | |
3355 | ||
3356 | if (minimum_clocks.engineClock < hwmgr->gfx_arbiter.sclk) | |
3357 | minimum_clocks.engineClock = hwmgr->gfx_arbiter.sclk; | |
3358 | ||
3359 | if (minimum_clocks.memoryClock < hwmgr->gfx_arbiter.mclk) | |
3360 | minimum_clocks.memoryClock = hwmgr->gfx_arbiter.mclk; | |
3361 | ||
2cc0c0b5 | 3362 | polaris10_ps->sclk_threshold = hwmgr->gfx_arbiter.sclk_threshold; |
a23eefa2 RZ |
3363 | |
3364 | if (0 != hwmgr->gfx_arbiter.sclk_over_drive) { | |
3365 | PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.sclk_over_drive <= | |
3366 | hwmgr->platform_descriptor.overdriveLimit.engineClock), | |
3367 | "Overdrive sclk exceeds limit", | |
3368 | hwmgr->gfx_arbiter.sclk_over_drive = | |
3369 | hwmgr->platform_descriptor.overdriveLimit.engineClock); | |
3370 | ||
3371 | if (hwmgr->gfx_arbiter.sclk_over_drive >= hwmgr->gfx_arbiter.sclk) | |
2cc0c0b5 | 3372 | polaris10_ps->performance_levels[1].engine_clock = |
a23eefa2 RZ |
3373 | hwmgr->gfx_arbiter.sclk_over_drive; |
3374 | } | |
3375 | ||
3376 | if (0 != hwmgr->gfx_arbiter.mclk_over_drive) { | |
3377 | PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.mclk_over_drive <= | |
3378 | hwmgr->platform_descriptor.overdriveLimit.memoryClock), | |
3379 | "Overdrive mclk exceeds limit", | |
3380 | hwmgr->gfx_arbiter.mclk_over_drive = | |
3381 | hwmgr->platform_descriptor.overdriveLimit.memoryClock); | |
3382 | ||
3383 | if (hwmgr->gfx_arbiter.mclk_over_drive >= hwmgr->gfx_arbiter.mclk) | |
2cc0c0b5 | 3384 | polaris10_ps->performance_levels[1].memory_clock = |
a23eefa2 RZ |
3385 | hwmgr->gfx_arbiter.mclk_over_drive; |
3386 | } | |
3387 | ||
3388 | disable_mclk_switching_for_frame_lock = phm_cap_enabled( | |
3389 | hwmgr->platform_descriptor.platformCaps, | |
3390 | PHM_PlatformCaps_DisableMclkSwitchingForFrameLock); | |
3391 | ||
3392 | disable_mclk_switching = (1 < info.display_count) || | |
3393 | disable_mclk_switching_for_frame_lock; | |
3394 | ||
2cc0c0b5 FC |
3395 | sclk = polaris10_ps->performance_levels[0].engine_clock; |
3396 | mclk = polaris10_ps->performance_levels[0].memory_clock; | |
a23eefa2 RZ |
3397 | |
3398 | if (disable_mclk_switching) | |
2cc0c0b5 FC |
3399 | mclk = polaris10_ps->performance_levels |
3400 | [polaris10_ps->performance_level_count - 1].memory_clock; | |
a23eefa2 RZ |
3401 | |
3402 | if (sclk < minimum_clocks.engineClock) | |
3403 | sclk = (minimum_clocks.engineClock > max_limits->sclk) ? | |
3404 | max_limits->sclk : minimum_clocks.engineClock; | |
3405 | ||
3406 | if (mclk < minimum_clocks.memoryClock) | |
3407 | mclk = (minimum_clocks.memoryClock > max_limits->mclk) ? | |
3408 | max_limits->mclk : minimum_clocks.memoryClock; | |
3409 | ||
2cc0c0b5 FC |
3410 | polaris10_ps->performance_levels[0].engine_clock = sclk; |
3411 | polaris10_ps->performance_levels[0].memory_clock = mclk; | |
a23eefa2 | 3412 | |
2cc0c0b5 FC |
3413 | polaris10_ps->performance_levels[1].engine_clock = |
3414 | (polaris10_ps->performance_levels[1].engine_clock >= | |
3415 | polaris10_ps->performance_levels[0].engine_clock) ? | |
3416 | polaris10_ps->performance_levels[1].engine_clock : | |
3417 | polaris10_ps->performance_levels[0].engine_clock; | |
a23eefa2 RZ |
3418 | |
3419 | if (disable_mclk_switching) { | |
2cc0c0b5 FC |
3420 | if (mclk < polaris10_ps->performance_levels[1].memory_clock) |
3421 | mclk = polaris10_ps->performance_levels[1].memory_clock; | |
a23eefa2 | 3422 | |
2cc0c0b5 FC |
3423 | polaris10_ps->performance_levels[0].memory_clock = mclk; |
3424 | polaris10_ps->performance_levels[1].memory_clock = mclk; | |
a23eefa2 | 3425 | } else { |
2cc0c0b5 FC |
3426 | if (polaris10_ps->performance_levels[1].memory_clock < |
3427 | polaris10_ps->performance_levels[0].memory_clock) | |
3428 | polaris10_ps->performance_levels[1].memory_clock = | |
3429 | polaris10_ps->performance_levels[0].memory_clock; | |
a23eefa2 RZ |
3430 | } |
3431 | ||
3432 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
3433 | PHM_PlatformCaps_StablePState)) { | |
2cc0c0b5 FC |
3434 | for (i = 0; i < polaris10_ps->performance_level_count; i++) { |
3435 | polaris10_ps->performance_levels[i].engine_clock = stable_pstate_sclk; | |
3436 | polaris10_ps->performance_levels[i].memory_clock = stable_pstate_mclk; | |
3437 | polaris10_ps->performance_levels[i].pcie_gen = data->pcie_gen_performance.max; | |
3438 | polaris10_ps->performance_levels[i].pcie_lane = data->pcie_gen_performance.max; | |
a23eefa2 RZ |
3439 | } |
3440 | } | |
3441 | return 0; | |
3442 | } | |
3443 | ||
3444 | ||
2cc0c0b5 | 3445 | static int polaris10_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low) |
a23eefa2 RZ |
3446 | { |
3447 | struct pp_power_state *ps; | |
2cc0c0b5 | 3448 | struct polaris10_power_state *polaris10_ps; |
a23eefa2 RZ |
3449 | |
3450 | if (hwmgr == NULL) | |
3451 | return -EINVAL; | |
3452 | ||
3453 | ps = hwmgr->request_ps; | |
3454 | ||
3455 | if (ps == NULL) | |
3456 | return -EINVAL; | |
3457 | ||
2cc0c0b5 | 3458 | polaris10_ps = cast_phw_polaris10_power_state(&ps->hardware); |
a23eefa2 RZ |
3459 | |
3460 | if (low) | |
2cc0c0b5 | 3461 | return polaris10_ps->performance_levels[0].memory_clock; |
a23eefa2 | 3462 | else |
2cc0c0b5 FC |
3463 | return polaris10_ps->performance_levels |
3464 | [polaris10_ps->performance_level_count-1].memory_clock; | |
a23eefa2 RZ |
3465 | } |
3466 | ||
2cc0c0b5 | 3467 | static int polaris10_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low) |
a23eefa2 RZ |
3468 | { |
3469 | struct pp_power_state *ps; | |
2cc0c0b5 | 3470 | struct polaris10_power_state *polaris10_ps; |
a23eefa2 RZ |
3471 | |
3472 | if (hwmgr == NULL) | |
3473 | return -EINVAL; | |
3474 | ||
3475 | ps = hwmgr->request_ps; | |
3476 | ||
3477 | if (ps == NULL) | |
3478 | return -EINVAL; | |
3479 | ||
2cc0c0b5 | 3480 | polaris10_ps = cast_phw_polaris10_power_state(&ps->hardware); |
a23eefa2 RZ |
3481 | |
3482 | if (low) | |
2cc0c0b5 | 3483 | return polaris10_ps->performance_levels[0].engine_clock; |
a23eefa2 | 3484 | else |
2cc0c0b5 FC |
3485 | return polaris10_ps->performance_levels |
3486 | [polaris10_ps->performance_level_count-1].engine_clock; | |
a23eefa2 RZ |
3487 | } |
3488 | ||
2cc0c0b5 | 3489 | static int polaris10_dpm_patch_boot_state(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
3490 | struct pp_hw_power_state *hw_ps) |
3491 | { | |
2cc0c0b5 FC |
3492 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
3493 | struct polaris10_power_state *ps = (struct polaris10_power_state *)hw_ps; | |
a23eefa2 RZ |
3494 | ATOM_FIRMWARE_INFO_V2_2 *fw_info; |
3495 | uint16_t size; | |
3496 | uint8_t frev, crev; | |
3497 | int index = GetIndexIntoMasterTable(DATA, FirmwareInfo); | |
3498 | ||
3499 | /* First retrieve the Boot clocks and VDDC from the firmware info table. | |
3500 | * We assume here that fw_info is unchanged if this call fails. | |
3501 | */ | |
3502 | fw_info = (ATOM_FIRMWARE_INFO_V2_2 *)cgs_atom_get_data_table( | |
3503 | hwmgr->device, index, | |
3504 | &size, &frev, &crev); | |
3505 | if (!fw_info) | |
3506 | /* During a test, there is no firmware info table. */ | |
3507 | return 0; | |
3508 | ||
3509 | /* Patch the state. */ | |
3510 | data->vbios_boot_state.sclk_bootup_value = | |
3511 | le32_to_cpu(fw_info->ulDefaultEngineClock); | |
3512 | data->vbios_boot_state.mclk_bootup_value = | |
3513 | le32_to_cpu(fw_info->ulDefaultMemoryClock); | |
3514 | data->vbios_boot_state.mvdd_bootup_value = | |
3515 | le16_to_cpu(fw_info->usBootUpMVDDCVoltage); | |
3516 | data->vbios_boot_state.vddc_bootup_value = | |
3517 | le16_to_cpu(fw_info->usBootUpVDDCVoltage); | |
3518 | data->vbios_boot_state.vddci_bootup_value = | |
3519 | le16_to_cpu(fw_info->usBootUpVDDCIVoltage); | |
3520 | data->vbios_boot_state.pcie_gen_bootup_value = | |
3521 | phm_get_current_pcie_speed(hwmgr); | |
3522 | ||
3523 | data->vbios_boot_state.pcie_lane_bootup_value = | |
3524 | (uint16_t)phm_get_current_pcie_lane_number(hwmgr); | |
3525 | ||
3526 | /* set boot power state */ | |
3527 | ps->performance_levels[0].memory_clock = data->vbios_boot_state.mclk_bootup_value; | |
3528 | ps->performance_levels[0].engine_clock = data->vbios_boot_state.sclk_bootup_value; | |
3529 | ps->performance_levels[0].pcie_gen = data->vbios_boot_state.pcie_gen_bootup_value; | |
3530 | ps->performance_levels[0].pcie_lane = data->vbios_boot_state.pcie_lane_bootup_value; | |
3531 | ||
3532 | return 0; | |
3533 | } | |
3534 | ||
2cc0c0b5 | 3535 | static int polaris10_get_pp_table_entry_callback_func(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
3536 | void *state, struct pp_power_state *power_state, |
3537 | void *pp_table, uint32_t classification_flag) | |
3538 | { | |
2cc0c0b5 FC |
3539 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
3540 | struct polaris10_power_state *polaris10_power_state = | |
3541 | (struct polaris10_power_state *)(&(power_state->hardware)); | |
3542 | struct polaris10_performance_level *performance_level; | |
a23eefa2 RZ |
3543 | ATOM_Tonga_State *state_entry = (ATOM_Tonga_State *)state; |
3544 | ATOM_Tonga_POWERPLAYTABLE *powerplay_table = | |
3545 | (ATOM_Tonga_POWERPLAYTABLE *)pp_table; | |
3546 | ATOM_Tonga_SCLK_Dependency_Table *sclk_dep_table = | |
3547 | (ATOM_Tonga_SCLK_Dependency_Table *) | |
3548 | (((unsigned long)powerplay_table) + | |
3549 | le16_to_cpu(powerplay_table->usSclkDependencyTableOffset)); | |
3550 | ATOM_Tonga_MCLK_Dependency_Table *mclk_dep_table = | |
3551 | (ATOM_Tonga_MCLK_Dependency_Table *) | |
3552 | (((unsigned long)powerplay_table) + | |
3553 | le16_to_cpu(powerplay_table->usMclkDependencyTableOffset)); | |
3554 | ||
3555 | /* The following fields are not initialized here: id orderedList allStatesList */ | |
3556 | power_state->classification.ui_label = | |
3557 | (le16_to_cpu(state_entry->usClassification) & | |
3558 | ATOM_PPLIB_CLASSIFICATION_UI_MASK) >> | |
3559 | ATOM_PPLIB_CLASSIFICATION_UI_SHIFT; | |
3560 | power_state->classification.flags = classification_flag; | |
3561 | /* NOTE: There is a classification2 flag in BIOS that is not being used right now */ | |
3562 | ||
3563 | power_state->classification.temporary_state = false; | |
3564 | power_state->classification.to_be_deleted = false; | |
3565 | ||
3566 | power_state->validation.disallowOnDC = | |
3567 | (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) & | |
3568 | ATOM_Tonga_DISALLOW_ON_DC)); | |
3569 | ||
3570 | power_state->pcie.lanes = 0; | |
3571 | ||
3572 | power_state->display.disableFrameModulation = false; | |
3573 | power_state->display.limitRefreshrate = false; | |
3574 | power_state->display.enableVariBright = | |
3575 | (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) & | |
3576 | ATOM_Tonga_ENABLE_VARIBRIGHT)); | |
3577 | ||
3578 | power_state->validation.supportedPowerLevels = 0; | |
3579 | power_state->uvd_clocks.VCLK = 0; | |
3580 | power_state->uvd_clocks.DCLK = 0; | |
3581 | power_state->temperatures.min = 0; | |
3582 | power_state->temperatures.max = 0; | |
3583 | ||
2cc0c0b5 FC |
3584 | performance_level = &(polaris10_power_state->performance_levels |
3585 | [polaris10_power_state->performance_level_count++]); | |
a23eefa2 RZ |
3586 | |
3587 | PP_ASSERT_WITH_CODE( | |
2cc0c0b5 | 3588 | (polaris10_power_state->performance_level_count < SMU74_MAX_LEVELS_GRAPHICS), |
a23eefa2 RZ |
3589 | "Performance levels exceeds SMC limit!", |
3590 | return -1); | |
3591 | ||
3592 | PP_ASSERT_WITH_CODE( | |
2cc0c0b5 | 3593 | (polaris10_power_state->performance_level_count <= |
a23eefa2 RZ |
3594 | hwmgr->platform_descriptor.hardwareActivityPerformanceLevels), |
3595 | "Performance levels exceeds Driver limit!", | |
3596 | return -1); | |
3597 | ||
3598 | /* Performance levels are arranged from low to high. */ | |
3599 | performance_level->memory_clock = mclk_dep_table->entries | |
3600 | [state_entry->ucMemoryClockIndexLow].ulMclk; | |
3601 | performance_level->engine_clock = sclk_dep_table->entries | |
3602 | [state_entry->ucEngineClockIndexLow].ulSclk; | |
3603 | performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap, | |
3604 | state_entry->ucPCIEGenLow); | |
3605 | performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap, | |
3606 | state_entry->ucPCIELaneHigh); | |
3607 | ||
2cc0c0b5 FC |
3608 | performance_level = &(polaris10_power_state->performance_levels |
3609 | [polaris10_power_state->performance_level_count++]); | |
a23eefa2 RZ |
3610 | performance_level->memory_clock = mclk_dep_table->entries |
3611 | [state_entry->ucMemoryClockIndexHigh].ulMclk; | |
3612 | performance_level->engine_clock = sclk_dep_table->entries | |
3613 | [state_entry->ucEngineClockIndexHigh].ulSclk; | |
3614 | performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap, | |
3615 | state_entry->ucPCIEGenHigh); | |
3616 | performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap, | |
3617 | state_entry->ucPCIELaneHigh); | |
3618 | ||
3619 | return 0; | |
3620 | } | |
3621 | ||
2cc0c0b5 | 3622 | static int polaris10_get_pp_table_entry(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
3623 | unsigned long entry_index, struct pp_power_state *state) |
3624 | { | |
3625 | int result; | |
2cc0c0b5 FC |
3626 | struct polaris10_power_state *ps; |
3627 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); | |
a23eefa2 RZ |
3628 | struct phm_ppt_v1_information *table_info = |
3629 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
3630 | struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table = | |
3631 | table_info->vdd_dep_on_mclk; | |
3632 | ||
3633 | state->hardware.magic = PHM_VIslands_Magic; | |
3634 | ||
2cc0c0b5 | 3635 | ps = (struct polaris10_power_state *)(&state->hardware); |
a23eefa2 RZ |
3636 | |
3637 | result = tonga_get_powerplay_table_entry(hwmgr, entry_index, state, | |
2cc0c0b5 | 3638 | polaris10_get_pp_table_entry_callback_func); |
a23eefa2 RZ |
3639 | |
3640 | /* This is the earliest time we have all the dependency table and the VBIOS boot state | |
3641 | * as PP_Tables_GetPowerPlayTableEntry retrieves the VBIOS boot state | |
3642 | * if there is only one VDDCI/MCLK level, check if it's the same as VBIOS boot state | |
3643 | */ | |
3644 | if (dep_mclk_table != NULL && dep_mclk_table->count == 1) { | |
3645 | if (dep_mclk_table->entries[0].clk != | |
3646 | data->vbios_boot_state.mclk_bootup_value) | |
3647 | printk(KERN_ERR "Single MCLK entry VDDCI/MCLK dependency table " | |
3648 | "does not match VBIOS boot MCLK level"); | |
3649 | if (dep_mclk_table->entries[0].vddci != | |
3650 | data->vbios_boot_state.vddci_bootup_value) | |
3651 | printk(KERN_ERR "Single VDDCI entry VDDCI/MCLK dependency table " | |
3652 | "does not match VBIOS boot VDDCI level"); | |
3653 | } | |
3654 | ||
3655 | /* set DC compatible flag if this state supports DC */ | |
3656 | if (!state->validation.disallowOnDC) | |
3657 | ps->dc_compatible = true; | |
3658 | ||
3659 | if (state->classification.flags & PP_StateClassificationFlag_ACPI) | |
3660 | data->acpi_pcie_gen = ps->performance_levels[0].pcie_gen; | |
3661 | ||
3662 | ps->uvd_clks.vclk = state->uvd_clocks.VCLK; | |
3663 | ps->uvd_clks.dclk = state->uvd_clocks.DCLK; | |
3664 | ||
3665 | if (!result) { | |
3666 | uint32_t i; | |
3667 | ||
3668 | switch (state->classification.ui_label) { | |
3669 | case PP_StateUILabel_Performance: | |
3670 | data->use_pcie_performance_levels = true; | |
3671 | ||
3672 | for (i = 0; i < ps->performance_level_count; i++) { | |
3673 | if (data->pcie_gen_performance.max < | |
3674 | ps->performance_levels[i].pcie_gen) | |
3675 | data->pcie_gen_performance.max = | |
3676 | ps->performance_levels[i].pcie_gen; | |
3677 | ||
3678 | if (data->pcie_gen_performance.min > | |
3679 | ps->performance_levels[i].pcie_gen) | |
3680 | data->pcie_gen_performance.min = | |
3681 | ps->performance_levels[i].pcie_gen; | |
3682 | ||
3683 | if (data->pcie_lane_performance.max < | |
3684 | ps->performance_levels[i].pcie_lane) | |
3685 | data->pcie_lane_performance.max = | |
3686 | ps->performance_levels[i].pcie_lane; | |
3687 | ||
3688 | if (data->pcie_lane_performance.min > | |
3689 | ps->performance_levels[i].pcie_lane) | |
3690 | data->pcie_lane_performance.min = | |
3691 | ps->performance_levels[i].pcie_lane; | |
3692 | } | |
3693 | break; | |
3694 | case PP_StateUILabel_Battery: | |
3695 | data->use_pcie_power_saving_levels = true; | |
3696 | ||
3697 | for (i = 0; i < ps->performance_level_count; i++) { | |
3698 | if (data->pcie_gen_power_saving.max < | |
3699 | ps->performance_levels[i].pcie_gen) | |
3700 | data->pcie_gen_power_saving.max = | |
3701 | ps->performance_levels[i].pcie_gen; | |
3702 | ||
3703 | if (data->pcie_gen_power_saving.min > | |
3704 | ps->performance_levels[i].pcie_gen) | |
3705 | data->pcie_gen_power_saving.min = | |
3706 | ps->performance_levels[i].pcie_gen; | |
3707 | ||
3708 | if (data->pcie_lane_power_saving.max < | |
3709 | ps->performance_levels[i].pcie_lane) | |
3710 | data->pcie_lane_power_saving.max = | |
3711 | ps->performance_levels[i].pcie_lane; | |
3712 | ||
3713 | if (data->pcie_lane_power_saving.min > | |
3714 | ps->performance_levels[i].pcie_lane) | |
3715 | data->pcie_lane_power_saving.min = | |
3716 | ps->performance_levels[i].pcie_lane; | |
3717 | } | |
3718 | break; | |
3719 | default: | |
3720 | break; | |
3721 | } | |
3722 | } | |
3723 | return 0; | |
3724 | } | |
3725 | ||
3726 | static void | |
2cc0c0b5 | 3727 | polaris10_print_current_perforce_level(struct pp_hwmgr *hwmgr, struct seq_file *m) |
a23eefa2 | 3728 | { |
b2d96143 RZ |
3729 | uint32_t sclk, mclk, activity_percent; |
3730 | uint32_t offset; | |
3731 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); | |
a23eefa2 RZ |
3732 | |
3733 | smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetSclkFrequency); | |
3734 | ||
3735 | sclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0); | |
3736 | ||
3737 | smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetMclkFrequency); | |
3738 | ||
3739 | mclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0); | |
3740 | seq_printf(m, "\n [ mclk ]: %u MHz\n\n [ sclk ]: %u MHz\n", | |
3741 | mclk / 100, sclk / 100); | |
b2d96143 RZ |
3742 | |
3743 | offset = data->soft_regs_start + offsetof(SMU74_SoftRegisters, AverageGraphicsActivity); | |
3744 | activity_percent = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, offset); | |
3745 | activity_percent += 0x80; | |
3746 | activity_percent >>= 8; | |
3747 | ||
3748 | seq_printf(m, "\n [GPU load]: %u%%\n\n", activity_percent > 100 ? 100 : activity_percent); | |
3749 | ||
3750 | seq_printf(m, "uvd %sabled\n", data->uvd_power_gated ? "dis" : "en"); | |
3751 | ||
3752 | seq_printf(m, "vce %sabled\n", data->vce_power_gated ? "dis" : "en"); | |
a23eefa2 RZ |
3753 | } |
3754 | ||
2cc0c0b5 | 3755 | static int polaris10_find_dpm_states_clocks_in_dpm_table(struct pp_hwmgr *hwmgr, const void *input) |
a23eefa2 RZ |
3756 | { |
3757 | const struct phm_set_power_state_input *states = | |
3758 | (const struct phm_set_power_state_input *)input; | |
2cc0c0b5 FC |
3759 | const struct polaris10_power_state *polaris10_ps = |
3760 | cast_const_phw_polaris10_power_state(states->pnew_state); | |
3761 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); | |
3762 | struct polaris10_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table); | |
3763 | uint32_t sclk = polaris10_ps->performance_levels | |
3764 | [polaris10_ps->performance_level_count - 1].engine_clock; | |
3765 | struct polaris10_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table); | |
3766 | uint32_t mclk = polaris10_ps->performance_levels | |
3767 | [polaris10_ps->performance_level_count - 1].memory_clock; | |
a23eefa2 RZ |
3768 | struct PP_Clocks min_clocks = {0}; |
3769 | uint32_t i; | |
3770 | struct cgs_display_info info = {0}; | |
3771 | ||
3772 | data->need_update_smu7_dpm_table = 0; | |
3773 | ||
3774 | for (i = 0; i < sclk_table->count; i++) { | |
3775 | if (sclk == sclk_table->dpm_levels[i].value) | |
3776 | break; | |
3777 | } | |
3778 | ||
3779 | if (i >= sclk_table->count) | |
3780 | data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK; | |
3781 | else { | |
3782 | /* TODO: Check SCLK in DAL's minimum clocks | |
3783 | * in case DeepSleep divider update is required. | |
3784 | */ | |
2cc0c0b5 FC |
3785 | if (data->display_timing.min_clock_in_sr != min_clocks.engineClockInSR && |
3786 | (min_clocks.engineClockInSR >= POLARIS10_MINIMUM_ENGINE_CLOCK || | |
3787 | data->display_timing.min_clock_in_sr >= POLARIS10_MINIMUM_ENGINE_CLOCK)) | |
a23eefa2 RZ |
3788 | data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_SCLK; |
3789 | } | |
3790 | ||
3791 | for (i = 0; i < mclk_table->count; i++) { | |
3792 | if (mclk == mclk_table->dpm_levels[i].value) | |
3793 | break; | |
3794 | } | |
3795 | ||
3796 | if (i >= mclk_table->count) | |
3797 | data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_MCLK; | |
3798 | ||
3799 | cgs_get_active_displays_info(hwmgr->device, &info); | |
3800 | ||
3801 | if (data->display_timing.num_existing_displays != info.display_count) | |
3802 | data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_MCLK; | |
3803 | ||
3804 | return 0; | |
3805 | } | |
3806 | ||
2cc0c0b5 FC |
3807 | static uint16_t polaris10_get_maximum_link_speed(struct pp_hwmgr *hwmgr, |
3808 | const struct polaris10_power_state *polaris10_ps) | |
a23eefa2 RZ |
3809 | { |
3810 | uint32_t i; | |
3811 | uint32_t sclk, max_sclk = 0; | |
2cc0c0b5 FC |
3812 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
3813 | struct polaris10_dpm_table *dpm_table = &data->dpm_table; | |
a23eefa2 | 3814 | |
2cc0c0b5 FC |
3815 | for (i = 0; i < polaris10_ps->performance_level_count; i++) { |
3816 | sclk = polaris10_ps->performance_levels[i].engine_clock; | |
a23eefa2 RZ |
3817 | if (max_sclk < sclk) |
3818 | max_sclk = sclk; | |
3819 | } | |
3820 | ||
3821 | for (i = 0; i < dpm_table->sclk_table.count; i++) { | |
3822 | if (dpm_table->sclk_table.dpm_levels[i].value == max_sclk) | |
3823 | return (uint16_t) ((i >= dpm_table->pcie_speed_table.count) ? | |
3824 | dpm_table->pcie_speed_table.dpm_levels | |
3825 | [dpm_table->pcie_speed_table.count - 1].value : | |
3826 | dpm_table->pcie_speed_table.dpm_levels[i].value); | |
3827 | } | |
3828 | ||
3829 | return 0; | |
3830 | } | |
3831 | ||
2cc0c0b5 | 3832 | static int polaris10_request_link_speed_change_before_state_change( |
a23eefa2 RZ |
3833 | struct pp_hwmgr *hwmgr, const void *input) |
3834 | { | |
3835 | const struct phm_set_power_state_input *states = | |
3836 | (const struct phm_set_power_state_input *)input; | |
2cc0c0b5 FC |
3837 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
3838 | const struct polaris10_power_state *polaris10_nps = | |
3839 | cast_const_phw_polaris10_power_state(states->pnew_state); | |
3840 | const struct polaris10_power_state *polaris10_cps = | |
3841 | cast_const_phw_polaris10_power_state(states->pcurrent_state); | |
a23eefa2 | 3842 | |
2cc0c0b5 | 3843 | uint16_t target_link_speed = polaris10_get_maximum_link_speed(hwmgr, polaris10_nps); |
a23eefa2 RZ |
3844 | uint16_t current_link_speed; |
3845 | ||
3846 | if (data->force_pcie_gen == PP_PCIEGenInvalid) | |
2cc0c0b5 | 3847 | current_link_speed = polaris10_get_maximum_link_speed(hwmgr, polaris10_cps); |
a23eefa2 RZ |
3848 | else |
3849 | current_link_speed = data->force_pcie_gen; | |
3850 | ||
3851 | data->force_pcie_gen = PP_PCIEGenInvalid; | |
3852 | data->pspp_notify_required = false; | |
3853 | ||
3854 | if (target_link_speed > current_link_speed) { | |
3855 | switch (target_link_speed) { | |
3856 | case PP_PCIEGen3: | |
3857 | if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN3, false)) | |
3858 | break; | |
3859 | data->force_pcie_gen = PP_PCIEGen2; | |
3860 | if (current_link_speed == PP_PCIEGen2) | |
3861 | break; | |
3862 | case PP_PCIEGen2: | |
3863 | if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN2, false)) | |
3864 | break; | |
3865 | default: | |
3866 | data->force_pcie_gen = phm_get_current_pcie_speed(hwmgr); | |
3867 | break; | |
3868 | } | |
3869 | } else { | |
3870 | if (target_link_speed < current_link_speed) | |
3871 | data->pspp_notify_required = true; | |
3872 | } | |
3873 | ||
3874 | return 0; | |
3875 | } | |
3876 | ||
2cc0c0b5 | 3877 | static int polaris10_freeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr) |
a23eefa2 | 3878 | { |
2cc0c0b5 | 3879 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
3880 | |
3881 | if (0 == data->need_update_smu7_dpm_table) | |
3882 | return 0; | |
3883 | ||
3884 | if ((0 == data->sclk_dpm_key_disabled) && | |
3885 | (data->need_update_smu7_dpm_table & | |
3886 | (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) { | |
2cc0c0b5 | 3887 | PP_ASSERT_WITH_CODE(true == polaris10_is_dpm_running(hwmgr), |
a23eefa2 RZ |
3888 | "Trying to freeze SCLK DPM when DPM is disabled", |
3889 | ); | |
3890 | PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr, | |
3891 | PPSMC_MSG_SCLKDPM_FreezeLevel), | |
3892 | "Failed to freeze SCLK DPM during FreezeSclkMclkDPM Function!", | |
3893 | return -1); | |
3894 | } | |
3895 | ||
3896 | if ((0 == data->mclk_dpm_key_disabled) && | |
3897 | (data->need_update_smu7_dpm_table & | |
3898 | DPMTABLE_OD_UPDATE_MCLK)) { | |
2cc0c0b5 | 3899 | PP_ASSERT_WITH_CODE(true == polaris10_is_dpm_running(hwmgr), |
a23eefa2 RZ |
3900 | "Trying to freeze MCLK DPM when DPM is disabled", |
3901 | ); | |
3902 | PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr, | |
3903 | PPSMC_MSG_MCLKDPM_FreezeLevel), | |
3904 | "Failed to freeze MCLK DPM during FreezeSclkMclkDPM Function!", | |
3905 | return -1); | |
3906 | } | |
3907 | ||
3908 | return 0; | |
3909 | } | |
3910 | ||
2cc0c0b5 | 3911 | static int polaris10_populate_and_upload_sclk_mclk_dpm_levels( |
a23eefa2 RZ |
3912 | struct pp_hwmgr *hwmgr, const void *input) |
3913 | { | |
3914 | int result = 0; | |
3915 | const struct phm_set_power_state_input *states = | |
3916 | (const struct phm_set_power_state_input *)input; | |
2cc0c0b5 FC |
3917 | const struct polaris10_power_state *polaris10_ps = |
3918 | cast_const_phw_polaris10_power_state(states->pnew_state); | |
3919 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); | |
3920 | uint32_t sclk = polaris10_ps->performance_levels | |
3921 | [polaris10_ps->performance_level_count - 1].engine_clock; | |
3922 | uint32_t mclk = polaris10_ps->performance_levels | |
3923 | [polaris10_ps->performance_level_count - 1].memory_clock; | |
3924 | struct polaris10_dpm_table *dpm_table = &data->dpm_table; | |
3925 | ||
3926 | struct polaris10_dpm_table *golden_dpm_table = &data->golden_dpm_table; | |
a23eefa2 RZ |
3927 | uint32_t dpm_count, clock_percent; |
3928 | uint32_t i; | |
3929 | ||
3930 | if (0 == data->need_update_smu7_dpm_table) | |
3931 | return 0; | |
3932 | ||
3933 | if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_SCLK) { | |
3934 | dpm_table->sclk_table.dpm_levels | |
3935 | [dpm_table->sclk_table.count - 1].value = sclk; | |
3936 | ||
3937 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinACSupport) || | |
3938 | phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinDCSupport)) { | |
3939 | /* Need to do calculation based on the golden DPM table | |
3940 | * as the Heatmap GPU Clock axis is also based on the default values | |
3941 | */ | |
3942 | PP_ASSERT_WITH_CODE( | |
3943 | (golden_dpm_table->sclk_table.dpm_levels | |
3944 | [golden_dpm_table->sclk_table.count - 1].value != 0), | |
3945 | "Divide by 0!", | |
3946 | return -1); | |
3947 | dpm_count = dpm_table->sclk_table.count < 2 ? 0 : dpm_table->sclk_table.count - 2; | |
3948 | ||
3949 | for (i = dpm_count; i > 1; i--) { | |
3950 | if (sclk > golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value) { | |
3951 | clock_percent = | |
3952 | ((sclk | |
3953 | - golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value | |
3954 | ) * 100) | |
3955 | / golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value; | |
3956 | ||
3957 | dpm_table->sclk_table.dpm_levels[i].value = | |
3958 | golden_dpm_table->sclk_table.dpm_levels[i].value + | |
3959 | (golden_dpm_table->sclk_table.dpm_levels[i].value * | |
3960 | clock_percent)/100; | |
3961 | ||
3962 | } else if (golden_dpm_table->sclk_table.dpm_levels[dpm_table->sclk_table.count-1].value > sclk) { | |
3963 | clock_percent = | |
3964 | ((golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count - 1].value | |
3965 | - sclk) * 100) | |
3966 | / golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value; | |
3967 | ||
3968 | dpm_table->sclk_table.dpm_levels[i].value = | |
3969 | golden_dpm_table->sclk_table.dpm_levels[i].value - | |
3970 | (golden_dpm_table->sclk_table.dpm_levels[i].value * | |
3971 | clock_percent) / 100; | |
3972 | } else | |
3973 | dpm_table->sclk_table.dpm_levels[i].value = | |
3974 | golden_dpm_table->sclk_table.dpm_levels[i].value; | |
3975 | } | |
3976 | } | |
3977 | } | |
3978 | ||
3979 | if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK) { | |
3980 | dpm_table->mclk_table.dpm_levels | |
3981 | [dpm_table->mclk_table.count - 1].value = mclk; | |
3982 | ||
3983 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinACSupport) || | |
3984 | phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinDCSupport)) { | |
3985 | ||
3986 | PP_ASSERT_WITH_CODE( | |
3987 | (golden_dpm_table->mclk_table.dpm_levels | |
3988 | [golden_dpm_table->mclk_table.count-1].value != 0), | |
3989 | "Divide by 0!", | |
3990 | return -1); | |
3991 | dpm_count = dpm_table->mclk_table.count < 2 ? 0 : dpm_table->mclk_table.count - 2; | |
3992 | for (i = dpm_count; i > 1; i--) { | |
3993 | if (golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value < mclk) { | |
3994 | clock_percent = ((mclk - | |
3995 | golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value) * 100) | |
3996 | / golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value; | |
3997 | ||
3998 | dpm_table->mclk_table.dpm_levels[i].value = | |
3999 | golden_dpm_table->mclk_table.dpm_levels[i].value + | |
4000 | (golden_dpm_table->mclk_table.dpm_levels[i].value * | |
4001 | clock_percent) / 100; | |
4002 | ||
4003 | } else if (golden_dpm_table->mclk_table.dpm_levels[dpm_table->mclk_table.count-1].value > mclk) { | |
4004 | clock_percent = ( | |
4005 | (golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value - mclk) | |
4006 | * 100) | |
4007 | / golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value; | |
4008 | ||
4009 | dpm_table->mclk_table.dpm_levels[i].value = | |
4010 | golden_dpm_table->mclk_table.dpm_levels[i].value - | |
4011 | (golden_dpm_table->mclk_table.dpm_levels[i].value * | |
4012 | clock_percent) / 100; | |
4013 | } else | |
4014 | dpm_table->mclk_table.dpm_levels[i].value = | |
4015 | golden_dpm_table->mclk_table.dpm_levels[i].value; | |
4016 | } | |
4017 | } | |
4018 | } | |
4019 | ||
4020 | if (data->need_update_smu7_dpm_table & | |
4021 | (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK)) { | |
2cc0c0b5 | 4022 | result = polaris10_populate_all_graphic_levels(hwmgr); |
a23eefa2 RZ |
4023 | PP_ASSERT_WITH_CODE((0 == result), |
4024 | "Failed to populate SCLK during PopulateNewDPMClocksStates Function!", | |
4025 | return result); | |
4026 | } | |
4027 | ||
4028 | if (data->need_update_smu7_dpm_table & | |
4029 | (DPMTABLE_OD_UPDATE_MCLK + DPMTABLE_UPDATE_MCLK)) { | |
4030 | /*populate MCLK dpm table to SMU7 */ | |
2cc0c0b5 | 4031 | result = polaris10_populate_all_memory_levels(hwmgr); |
a23eefa2 RZ |
4032 | PP_ASSERT_WITH_CODE((0 == result), |
4033 | "Failed to populate MCLK during PopulateNewDPMClocksStates Function!", | |
4034 | return result); | |
4035 | } | |
4036 | ||
4037 | return result; | |
4038 | } | |
4039 | ||
2cc0c0b5 FC |
4040 | static int polaris10_trim_single_dpm_states(struct pp_hwmgr *hwmgr, |
4041 | struct polaris10_single_dpm_table *dpm_table, | |
a23eefa2 RZ |
4042 | uint32_t low_limit, uint32_t high_limit) |
4043 | { | |
4044 | uint32_t i; | |
a23eefa2 RZ |
4045 | |
4046 | for (i = 0; i < dpm_table->count; i++) { | |
4047 | if ((dpm_table->dpm_levels[i].value < low_limit) | |
4048 | || (dpm_table->dpm_levels[i].value > high_limit)) | |
4049 | dpm_table->dpm_levels[i].enabled = false; | |
a23eefa2 RZ |
4050 | else |
4051 | dpm_table->dpm_levels[i].enabled = true; | |
4052 | } | |
4053 | ||
4054 | return 0; | |
4055 | } | |
4056 | ||
2cc0c0b5 FC |
4057 | static int polaris10_trim_dpm_states(struct pp_hwmgr *hwmgr, |
4058 | const struct polaris10_power_state *polaris10_ps) | |
a23eefa2 RZ |
4059 | { |
4060 | int result = 0; | |
2cc0c0b5 | 4061 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
4062 | uint32_t high_limit_count; |
4063 | ||
2cc0c0b5 | 4064 | PP_ASSERT_WITH_CODE((polaris10_ps->performance_level_count >= 1), |
a23eefa2 RZ |
4065 | "power state did not have any performance level", |
4066 | return -1); | |
4067 | ||
2cc0c0b5 | 4068 | high_limit_count = (1 == polaris10_ps->performance_level_count) ? 0 : 1; |
a23eefa2 | 4069 | |
2cc0c0b5 | 4070 | polaris10_trim_single_dpm_states(hwmgr, |
a23eefa2 | 4071 | &(data->dpm_table.sclk_table), |
2cc0c0b5 FC |
4072 | polaris10_ps->performance_levels[0].engine_clock, |
4073 | polaris10_ps->performance_levels[high_limit_count].engine_clock); | |
a23eefa2 | 4074 | |
2cc0c0b5 | 4075 | polaris10_trim_single_dpm_states(hwmgr, |
a23eefa2 | 4076 | &(data->dpm_table.mclk_table), |
2cc0c0b5 FC |
4077 | polaris10_ps->performance_levels[0].memory_clock, |
4078 | polaris10_ps->performance_levels[high_limit_count].memory_clock); | |
a23eefa2 RZ |
4079 | |
4080 | return result; | |
4081 | } | |
4082 | ||
2cc0c0b5 | 4083 | static int polaris10_generate_dpm_level_enable_mask( |
a23eefa2 RZ |
4084 | struct pp_hwmgr *hwmgr, const void *input) |
4085 | { | |
4086 | int result; | |
4087 | const struct phm_set_power_state_input *states = | |
4088 | (const struct phm_set_power_state_input *)input; | |
2cc0c0b5 FC |
4089 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
4090 | const struct polaris10_power_state *polaris10_ps = | |
4091 | cast_const_phw_polaris10_power_state(states->pnew_state); | |
a23eefa2 | 4092 | |
2cc0c0b5 | 4093 | result = polaris10_trim_dpm_states(hwmgr, polaris10_ps); |
a23eefa2 RZ |
4094 | if (result) |
4095 | return result; | |
4096 | ||
4097 | data->dpm_level_enable_mask.sclk_dpm_enable_mask = | |
4098 | phm_get_dpm_level_enable_mask_value(&data->dpm_table.sclk_table); | |
4099 | data->dpm_level_enable_mask.mclk_dpm_enable_mask = | |
4100 | phm_get_dpm_level_enable_mask_value(&data->dpm_table.mclk_table); | |
4101 | data->dpm_level_enable_mask.pcie_dpm_enable_mask = | |
4102 | phm_get_dpm_level_enable_mask_value(&data->dpm_table.pcie_speed_table); | |
4103 | ||
4104 | return 0; | |
4105 | } | |
4106 | ||
2cc0c0b5 | 4107 | int polaris10_enable_disable_uvd_dpm(struct pp_hwmgr *hwmgr, bool enable) |
a23eefa2 RZ |
4108 | { |
4109 | return smum_send_msg_to_smc(hwmgr->smumgr, enable ? | |
92c6d645 EH |
4110 | PPSMC_MSG_UVDDPM_Enable : |
4111 | PPSMC_MSG_UVDDPM_Disable); | |
4112 | } | |
4113 | ||
2cc0c0b5 | 4114 | int polaris10_enable_disable_vce_dpm(struct pp_hwmgr *hwmgr, bool enable) |
92c6d645 EH |
4115 | { |
4116 | return smum_send_msg_to_smc(hwmgr->smumgr, enable? | |
a23eefa2 RZ |
4117 | PPSMC_MSG_VCEDPM_Enable : |
4118 | PPSMC_MSG_VCEDPM_Disable); | |
4119 | } | |
4120 | ||
2cc0c0b5 | 4121 | int polaris10_enable_disable_samu_dpm(struct pp_hwmgr *hwmgr, bool enable) |
92c6d645 EH |
4122 | { |
4123 | return smum_send_msg_to_smc(hwmgr->smumgr, enable? | |
4124 | PPSMC_MSG_SAMUDPM_Enable : | |
4125 | PPSMC_MSG_SAMUDPM_Disable); | |
4126 | } | |
4127 | ||
2cc0c0b5 | 4128 | int polaris10_update_uvd_dpm(struct pp_hwmgr *hwmgr, bool bgate) |
92c6d645 | 4129 | { |
2cc0c0b5 | 4130 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
92c6d645 EH |
4131 | uint32_t mm_boot_level_offset, mm_boot_level_value; |
4132 | struct phm_ppt_v1_information *table_info = | |
4133 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
4134 | ||
4135 | if (!bgate) { | |
4136 | data->smc_state_table.UvdBootLevel = 0; | |
4137 | if (table_info->mm_dep_table->count > 0) | |
4138 | data->smc_state_table.UvdBootLevel = | |
4139 | (uint8_t) (table_info->mm_dep_table->count - 1); | |
4140 | mm_boot_level_offset = data->dpm_table_start + | |
4141 | offsetof(SMU74_Discrete_DpmTable, UvdBootLevel); | |
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 &= 0x00FFFFFF; | |
4147 | mm_boot_level_value |= data->smc_state_table.UvdBootLevel << 24; | |
4148 | cgs_write_ind_register(hwmgr->device, | |
4149 | CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value); | |
4150 | ||
4151 | if (!phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
4152 | PHM_PlatformCaps_UVDDPM) || | |
4153 | phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
4154 | PHM_PlatformCaps_StablePState)) | |
4155 | smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, | |
4156 | PPSMC_MSG_UVDDPM_SetEnabledMask, | |
4157 | (uint32_t)(1 << data->smc_state_table.UvdBootLevel)); | |
4158 | } | |
4159 | ||
2cc0c0b5 | 4160 | return polaris10_enable_disable_uvd_dpm(hwmgr, !bgate); |
92c6d645 EH |
4161 | } |
4162 | ||
2cc0c0b5 | 4163 | static int polaris10_update_vce_dpm(struct pp_hwmgr *hwmgr, const void *input) |
a23eefa2 RZ |
4164 | { |
4165 | const struct phm_set_power_state_input *states = | |
4166 | (const struct phm_set_power_state_input *)input; | |
2cc0c0b5 FC |
4167 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
4168 | const struct polaris10_power_state *polaris10_nps = | |
4169 | cast_const_phw_polaris10_power_state(states->pnew_state); | |
4170 | const struct polaris10_power_state *polaris10_cps = | |
4171 | cast_const_phw_polaris10_power_state(states->pcurrent_state); | |
a23eefa2 RZ |
4172 | |
4173 | uint32_t mm_boot_level_offset, mm_boot_level_value; | |
4174 | struct phm_ppt_v1_information *table_info = | |
4175 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
4176 | ||
2cc0c0b5 FC |
4177 | if (polaris10_nps->vce_clks.evclk > 0 && |
4178 | (polaris10_cps == NULL || polaris10_cps->vce_clks.evclk == 0)) { | |
a23eefa2 RZ |
4179 | |
4180 | data->smc_state_table.VceBootLevel = | |
4181 | (uint8_t) (table_info->mm_dep_table->count - 1); | |
4182 | ||
4183 | mm_boot_level_offset = data->dpm_table_start + | |
4184 | offsetof(SMU74_Discrete_DpmTable, VceBootLevel); | |
4185 | mm_boot_level_offset /= 4; | |
4186 | mm_boot_level_offset *= 4; | |
4187 | mm_boot_level_value = cgs_read_ind_register(hwmgr->device, | |
4188 | CGS_IND_REG__SMC, mm_boot_level_offset); | |
4189 | mm_boot_level_value &= 0xFF00FFFF; | |
4190 | mm_boot_level_value |= data->smc_state_table.VceBootLevel << 16; | |
4191 | cgs_write_ind_register(hwmgr->device, | |
4192 | CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value); | |
4193 | ||
4194 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_StablePState)) { | |
4195 | smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, | |
4196 | PPSMC_MSG_VCEDPM_SetEnabledMask, | |
4197 | (uint32_t)1 << data->smc_state_table.VceBootLevel); | |
4198 | ||
2cc0c0b5 FC |
4199 | polaris10_enable_disable_vce_dpm(hwmgr, true); |
4200 | } else if (polaris10_nps->vce_clks.evclk == 0 && | |
4201 | polaris10_cps != NULL && | |
4202 | polaris10_cps->vce_clks.evclk > 0) | |
4203 | polaris10_enable_disable_vce_dpm(hwmgr, false); | |
a23eefa2 RZ |
4204 | } |
4205 | ||
4206 | return 0; | |
4207 | } | |
4208 | ||
2cc0c0b5 | 4209 | int polaris10_update_samu_dpm(struct pp_hwmgr *hwmgr, bool bgate) |
92c6d645 | 4210 | { |
2cc0c0b5 | 4211 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
92c6d645 EH |
4212 | uint32_t mm_boot_level_offset, mm_boot_level_value; |
4213 | struct phm_ppt_v1_information *table_info = | |
4214 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
4215 | ||
4216 | if (!bgate) { | |
4217 | data->smc_state_table.SamuBootLevel = | |
4218 | (uint8_t) (table_info->mm_dep_table->count - 1); | |
4219 | mm_boot_level_offset = data->dpm_table_start + | |
4220 | offsetof(SMU74_Discrete_DpmTable, SamuBootLevel); | |
4221 | mm_boot_level_offset /= 4; | |
4222 | mm_boot_level_offset *= 4; | |
4223 | mm_boot_level_value = cgs_read_ind_register(hwmgr->device, | |
4224 | CGS_IND_REG__SMC, mm_boot_level_offset); | |
4225 | mm_boot_level_value &= 0xFFFFFF00; | |
4226 | mm_boot_level_value |= data->smc_state_table.SamuBootLevel << 0; | |
4227 | cgs_write_ind_register(hwmgr->device, | |
4228 | CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value); | |
4229 | ||
4230 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
4231 | PHM_PlatformCaps_StablePState)) | |
4232 | smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, | |
4233 | PPSMC_MSG_SAMUDPM_SetEnabledMask, | |
4234 | (uint32_t)(1 << data->smc_state_table.SamuBootLevel)); | |
4235 | } | |
4236 | ||
2cc0c0b5 | 4237 | return polaris10_enable_disable_samu_dpm(hwmgr, !bgate); |
92c6d645 EH |
4238 | } |
4239 | ||
2cc0c0b5 | 4240 | static int polaris10_update_sclk_threshold(struct pp_hwmgr *hwmgr) |
a23eefa2 | 4241 | { |
2cc0c0b5 | 4242 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
4243 | |
4244 | int result = 0; | |
4245 | uint32_t low_sclk_interrupt_threshold = 0; | |
4246 | ||
4247 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
4248 | PHM_PlatformCaps_SclkThrottleLowNotification) | |
4249 | && (hwmgr->gfx_arbiter.sclk_threshold != | |
4250 | data->low_sclk_interrupt_threshold)) { | |
4251 | data->low_sclk_interrupt_threshold = | |
4252 | hwmgr->gfx_arbiter.sclk_threshold; | |
4253 | low_sclk_interrupt_threshold = | |
4254 | data->low_sclk_interrupt_threshold; | |
4255 | ||
4256 | CONVERT_FROM_HOST_TO_SMC_UL(low_sclk_interrupt_threshold); | |
4257 | ||
2cc0c0b5 | 4258 | result = polaris10_copy_bytes_to_smc( |
a23eefa2 RZ |
4259 | hwmgr->smumgr, |
4260 | data->dpm_table_start + | |
4261 | offsetof(SMU74_Discrete_DpmTable, | |
4262 | LowSclkInterruptThreshold), | |
4263 | (uint8_t *)&low_sclk_interrupt_threshold, | |
4264 | sizeof(uint32_t), | |
4265 | data->sram_end); | |
4266 | } | |
4267 | ||
4268 | return result; | |
4269 | } | |
4270 | ||
2cc0c0b5 | 4271 | static int polaris10_program_mem_timing_parameters(struct pp_hwmgr *hwmgr) |
a23eefa2 | 4272 | { |
2cc0c0b5 | 4273 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
4274 | |
4275 | if (data->need_update_smu7_dpm_table & | |
4276 | (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_OD_UPDATE_MCLK)) | |
2cc0c0b5 | 4277 | return polaris10_program_memory_timing_parameters(hwmgr); |
a23eefa2 RZ |
4278 | |
4279 | return 0; | |
4280 | } | |
4281 | ||
2cc0c0b5 | 4282 | static int polaris10_unfreeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr) |
a23eefa2 | 4283 | { |
2cc0c0b5 | 4284 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
4285 | |
4286 | if (0 == data->need_update_smu7_dpm_table) | |
4287 | return 0; | |
4288 | ||
4289 | if ((0 == data->sclk_dpm_key_disabled) && | |
4290 | (data->need_update_smu7_dpm_table & | |
4291 | (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) { | |
4292 | ||
2cc0c0b5 | 4293 | PP_ASSERT_WITH_CODE(true == polaris10_is_dpm_running(hwmgr), |
a23eefa2 RZ |
4294 | "Trying to Unfreeze SCLK DPM when DPM is disabled", |
4295 | ); | |
4296 | PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr, | |
4297 | PPSMC_MSG_SCLKDPM_UnfreezeLevel), | |
4298 | "Failed to unfreeze SCLK DPM during UnFreezeSclkMclkDPM Function!", | |
4299 | return -1); | |
4300 | } | |
4301 | ||
4302 | if ((0 == data->mclk_dpm_key_disabled) && | |
4303 | (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) { | |
4304 | ||
2cc0c0b5 | 4305 | PP_ASSERT_WITH_CODE(true == polaris10_is_dpm_running(hwmgr), |
a23eefa2 RZ |
4306 | "Trying to Unfreeze MCLK DPM when DPM is disabled", |
4307 | ); | |
4308 | PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr, | |
4309 | PPSMC_MSG_SCLKDPM_UnfreezeLevel), | |
4310 | "Failed to unfreeze MCLK DPM during UnFreezeSclkMclkDPM Function!", | |
4311 | return -1); | |
4312 | } | |
4313 | ||
4314 | data->need_update_smu7_dpm_table = 0; | |
4315 | ||
4316 | return 0; | |
4317 | } | |
4318 | ||
2cc0c0b5 | 4319 | static int polaris10_notify_link_speed_change_after_state_change( |
a23eefa2 RZ |
4320 | struct pp_hwmgr *hwmgr, const void *input) |
4321 | { | |
4322 | const struct phm_set_power_state_input *states = | |
4323 | (const struct phm_set_power_state_input *)input; | |
2cc0c0b5 FC |
4324 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
4325 | const struct polaris10_power_state *polaris10_ps = | |
4326 | cast_const_phw_polaris10_power_state(states->pnew_state); | |
4327 | uint16_t target_link_speed = polaris10_get_maximum_link_speed(hwmgr, polaris10_ps); | |
a23eefa2 RZ |
4328 | uint8_t request; |
4329 | ||
4330 | if (data->pspp_notify_required) { | |
4331 | if (target_link_speed == PP_PCIEGen3) | |
4332 | request = PCIE_PERF_REQ_GEN3; | |
4333 | else if (target_link_speed == PP_PCIEGen2) | |
4334 | request = PCIE_PERF_REQ_GEN2; | |
4335 | else | |
4336 | request = PCIE_PERF_REQ_GEN1; | |
4337 | ||
4338 | if (request == PCIE_PERF_REQ_GEN1 && | |
4339 | phm_get_current_pcie_speed(hwmgr) > 0) | |
4340 | return 0; | |
4341 | ||
4342 | if (acpi_pcie_perf_request(hwmgr->device, request, false)) { | |
4343 | if (PP_PCIEGen2 == target_link_speed) | |
4344 | printk("PSPP request to switch to Gen2 from Gen3 Failed!"); | |
4345 | else | |
4346 | printk("PSPP request to switch to Gen1 from Gen2 Failed!"); | |
4347 | } | |
4348 | } | |
4349 | ||
4350 | return 0; | |
4351 | } | |
4352 | ||
2cc0c0b5 | 4353 | static int polaris10_set_power_state_tasks(struct pp_hwmgr *hwmgr, const void *input) |
a23eefa2 RZ |
4354 | { |
4355 | int tmp_result, result = 0; | |
2cc0c0b5 | 4356 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 | 4357 | |
2cc0c0b5 | 4358 | tmp_result = polaris10_find_dpm_states_clocks_in_dpm_table(hwmgr, input); |
a23eefa2 RZ |
4359 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
4360 | "Failed to find DPM states clocks in DPM table!", | |
4361 | result = tmp_result); | |
4362 | ||
4363 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
4364 | PHM_PlatformCaps_PCIEPerformanceRequest)) { | |
4365 | tmp_result = | |
2cc0c0b5 | 4366 | polaris10_request_link_speed_change_before_state_change(hwmgr, input); |
a23eefa2 RZ |
4367 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
4368 | "Failed to request link speed change before state change!", | |
4369 | result = tmp_result); | |
4370 | } | |
4371 | ||
2cc0c0b5 | 4372 | tmp_result = polaris10_freeze_sclk_mclk_dpm(hwmgr); |
a23eefa2 RZ |
4373 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
4374 | "Failed to freeze SCLK MCLK DPM!", result = tmp_result); | |
4375 | ||
2cc0c0b5 | 4376 | tmp_result = polaris10_populate_and_upload_sclk_mclk_dpm_levels(hwmgr, input); |
a23eefa2 RZ |
4377 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
4378 | "Failed to populate and upload SCLK MCLK DPM levels!", | |
4379 | result = tmp_result); | |
4380 | ||
2cc0c0b5 | 4381 | tmp_result = polaris10_generate_dpm_level_enable_mask(hwmgr, input); |
a23eefa2 RZ |
4382 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
4383 | "Failed to generate DPM level enabled mask!", | |
4384 | result = tmp_result); | |
4385 | ||
2cc0c0b5 | 4386 | tmp_result = polaris10_update_vce_dpm(hwmgr, input); |
a23eefa2 RZ |
4387 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
4388 | "Failed to update VCE DPM!", | |
4389 | result = tmp_result); | |
4390 | ||
2cc0c0b5 | 4391 | tmp_result = polaris10_update_sclk_threshold(hwmgr); |
a23eefa2 RZ |
4392 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
4393 | "Failed to update SCLK threshold!", | |
4394 | result = tmp_result); | |
4395 | ||
2cc0c0b5 | 4396 | tmp_result = polaris10_program_mem_timing_parameters(hwmgr); |
a23eefa2 RZ |
4397 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
4398 | "Failed to program memory timing parameters!", | |
4399 | result = tmp_result); | |
4400 | ||
2cc0c0b5 | 4401 | tmp_result = polaris10_unfreeze_sclk_mclk_dpm(hwmgr); |
a23eefa2 RZ |
4402 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
4403 | "Failed to unfreeze SCLK MCLK DPM!", | |
4404 | result = tmp_result); | |
4405 | ||
2cc0c0b5 | 4406 | tmp_result = polaris10_upload_dpm_level_enable_mask(hwmgr); |
a23eefa2 RZ |
4407 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
4408 | "Failed to upload DPM level enabled mask!", | |
4409 | result = tmp_result); | |
4410 | ||
4411 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
4412 | PHM_PlatformCaps_PCIEPerformanceRequest)) { | |
4413 | tmp_result = | |
2cc0c0b5 | 4414 | polaris10_notify_link_speed_change_after_state_change(hwmgr, input); |
a23eefa2 RZ |
4415 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
4416 | "Failed to notify link speed change after state change!", | |
4417 | result = tmp_result); | |
4418 | } | |
4419 | data->apply_optimized_settings = false; | |
4420 | return result; | |
4421 | } | |
4422 | ||
2cc0c0b5 | 4423 | static int polaris10_set_max_fan_pwm_output(struct pp_hwmgr *hwmgr, uint16_t us_max_fan_pwm) |
a23eefa2 | 4424 | { |
eede5262 EH |
4425 | hwmgr->thermal_controller. |
4426 | advanceFanControlParameters.usMaxFanPWM = us_max_fan_pwm; | |
a23eefa2 | 4427 | |
eede5262 | 4428 | if (phm_is_hw_access_blocked(hwmgr)) |
a23eefa2 | 4429 | return 0; |
eede5262 EH |
4430 | |
4431 | return smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, | |
4432 | PPSMC_MSG_SetFanPwmMax, us_max_fan_pwm); | |
a23eefa2 RZ |
4433 | } |
4434 | ||
2cc0c0b5 | 4435 | int polaris10_notify_smc_display_change(struct pp_hwmgr *hwmgr, bool has_display) |
a23eefa2 RZ |
4436 | { |
4437 | PPSMC_Msg msg = has_display ? (PPSMC_Msg)PPSMC_HasDisplay : (PPSMC_Msg)PPSMC_NoDisplay; | |
4438 | ||
4439 | return (smum_send_msg_to_smc(hwmgr->smumgr, msg) == 0) ? 0 : -1; | |
4440 | } | |
4441 | ||
2cc0c0b5 | 4442 | int polaris10_notify_smc_display_config_after_ps_adjustment(struct pp_hwmgr *hwmgr) |
a23eefa2 RZ |
4443 | { |
4444 | uint32_t num_active_displays = 0; | |
4445 | struct cgs_display_info info = {0}; | |
4446 | info.mode_info = NULL; | |
4447 | ||
4448 | cgs_get_active_displays_info(hwmgr->device, &info); | |
4449 | ||
4450 | num_active_displays = info.display_count; | |
4451 | ||
4452 | if (num_active_displays > 1) /* to do && (pHwMgr->pPECI->displayConfiguration.bMultiMonitorInSync != TRUE)) */ | |
2cc0c0b5 | 4453 | polaris10_notify_smc_display_change(hwmgr, false); |
a23eefa2 | 4454 | else |
2cc0c0b5 | 4455 | polaris10_notify_smc_display_change(hwmgr, true); |
a23eefa2 RZ |
4456 | |
4457 | return 0; | |
4458 | } | |
4459 | ||
4460 | /** | |
4461 | * Programs the display gap | |
4462 | * | |
4463 | * @param hwmgr the address of the powerplay hardware manager. | |
4464 | * @return always OK | |
4465 | */ | |
2cc0c0b5 | 4466 | int polaris10_program_display_gap(struct pp_hwmgr *hwmgr) |
a23eefa2 | 4467 | { |
2cc0c0b5 | 4468 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
4469 | uint32_t num_active_displays = 0; |
4470 | uint32_t display_gap = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL); | |
4471 | uint32_t display_gap2; | |
4472 | uint32_t pre_vbi_time_in_us; | |
4473 | uint32_t frame_time_in_us; | |
4474 | uint32_t ref_clock; | |
4475 | uint32_t refresh_rate = 0; | |
4476 | struct cgs_display_info info = {0}; | |
4477 | struct cgs_mode_info mode_info; | |
4478 | ||
4479 | info.mode_info = &mode_info; | |
4480 | ||
4481 | cgs_get_active_displays_info(hwmgr->device, &info); | |
4482 | num_active_displays = info.display_count; | |
4483 | ||
4484 | 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); | |
4485 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL, display_gap); | |
4486 | ||
4487 | ref_clock = mode_info.ref_clock; | |
4488 | refresh_rate = mode_info.refresh_rate; | |
4489 | ||
4490 | if (0 == refresh_rate) | |
4491 | refresh_rate = 60; | |
4492 | ||
4493 | frame_time_in_us = 1000000 / refresh_rate; | |
4494 | ||
4495 | pre_vbi_time_in_us = frame_time_in_us - 200 - mode_info.vblank_time_us; | |
4496 | display_gap2 = pre_vbi_time_in_us * (ref_clock / 100); | |
4497 | ||
4498 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL2, display_gap2); | |
4499 | ||
4500 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, data->soft_regs_start + offsetof(SMU74_SoftRegisters, PreVBlankGap), 0x64); | |
4501 | ||
4502 | 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)); | |
4503 | ||
2cc0c0b5 | 4504 | polaris10_notify_smc_display_change(hwmgr, num_active_displays != 0); |
a23eefa2 RZ |
4505 | |
4506 | return 0; | |
4507 | } | |
4508 | ||
4509 | ||
2cc0c0b5 | 4510 | int polaris10_display_configuration_changed_task(struct pp_hwmgr *hwmgr) |
a23eefa2 | 4511 | { |
2cc0c0b5 | 4512 | return polaris10_program_display_gap(hwmgr); |
a23eefa2 RZ |
4513 | } |
4514 | ||
4515 | /** | |
4516 | * Set maximum target operating fan output RPM | |
4517 | * | |
4518 | * @param hwmgr: the address of the powerplay hardware manager. | |
4519 | * @param usMaxFanRpm: max operating fan RPM value. | |
4520 | * @return The response that came from the SMC. | |
4521 | */ | |
2cc0c0b5 | 4522 | static int polaris10_set_max_fan_rpm_output(struct pp_hwmgr *hwmgr, uint16_t us_max_fan_rpm) |
a23eefa2 | 4523 | { |
eede5262 EH |
4524 | hwmgr->thermal_controller. |
4525 | advanceFanControlParameters.usMaxFanRPM = us_max_fan_rpm; | |
4526 | ||
4527 | if (phm_is_hw_access_blocked(hwmgr)) | |
4528 | return 0; | |
4529 | ||
4530 | return smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, | |
4531 | PPSMC_MSG_SetFanRpmMax, us_max_fan_rpm); | |
a23eefa2 RZ |
4532 | } |
4533 | ||
2cc0c0b5 | 4534 | int polaris10_register_internal_thermal_interrupt(struct pp_hwmgr *hwmgr, |
a23eefa2 RZ |
4535 | const void *thermal_interrupt_info) |
4536 | { | |
4537 | return 0; | |
4538 | } | |
4539 | ||
2cc0c0b5 | 4540 | bool polaris10_check_smc_update_required_for_display_configuration(struct pp_hwmgr *hwmgr) |
a23eefa2 | 4541 | { |
2cc0c0b5 | 4542 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
4543 | bool is_update_required = false; |
4544 | struct cgs_display_info info = {0, 0, NULL}; | |
4545 | ||
4546 | cgs_get_active_displays_info(hwmgr->device, &info); | |
4547 | ||
4548 | if (data->display_timing.num_existing_displays != info.display_count) | |
4549 | is_update_required = true; | |
4550 | /* TO DO NEED TO GET DEEP SLEEP CLOCK FROM DAL | |
4551 | if (phm_cap_enabled(hwmgr->hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep)) { | |
4552 | cgs_get_min_clock_settings(hwmgr->device, &min_clocks); | |
2cc0c0b5 FC |
4553 | if (min_clocks.engineClockInSR != data->display_timing.minClockInSR && |
4554 | (min_clocks.engineClockInSR >= POLARIS10_MINIMUM_ENGINE_CLOCK || | |
4555 | data->display_timing.minClockInSR >= POLARIS10_MINIMUM_ENGINE_CLOCK)) | |
a23eefa2 RZ |
4556 | is_update_required = true; |
4557 | */ | |
4558 | return is_update_required; | |
4559 | } | |
4560 | ||
2cc0c0b5 FC |
4561 | static inline bool polaris10_are_power_levels_equal(const struct polaris10_performance_level *pl1, |
4562 | const struct polaris10_performance_level *pl2) | |
a23eefa2 RZ |
4563 | { |
4564 | return ((pl1->memory_clock == pl2->memory_clock) && | |
4565 | (pl1->engine_clock == pl2->engine_clock) && | |
4566 | (pl1->pcie_gen == pl2->pcie_gen) && | |
4567 | (pl1->pcie_lane == pl2->pcie_lane)); | |
4568 | } | |
4569 | ||
2cc0c0b5 | 4570 | 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) |
a23eefa2 | 4571 | { |
2cc0c0b5 FC |
4572 | const struct polaris10_power_state *psa = cast_const_phw_polaris10_power_state(pstate1); |
4573 | const struct polaris10_power_state *psb = cast_const_phw_polaris10_power_state(pstate2); | |
a23eefa2 RZ |
4574 | int i; |
4575 | ||
4576 | if (pstate1 == NULL || pstate2 == NULL || equal == NULL) | |
4577 | return -EINVAL; | |
4578 | ||
4579 | /* If the two states don't even have the same number of performance levels they cannot be the same state. */ | |
4580 | if (psa->performance_level_count != psb->performance_level_count) { | |
4581 | *equal = false; | |
4582 | return 0; | |
4583 | } | |
4584 | ||
4585 | for (i = 0; i < psa->performance_level_count; i++) { | |
2cc0c0b5 | 4586 | if (!polaris10_are_power_levels_equal(&(psa->performance_levels[i]), &(psb->performance_levels[i]))) { |
a23eefa2 RZ |
4587 | /* If we have found even one performance level pair that is different the states are different. */ |
4588 | *equal = false; | |
4589 | return 0; | |
4590 | } | |
4591 | } | |
4592 | ||
4593 | /* If all performance levels are the same try to use the UVD clocks to break the tie.*/ | |
4594 | *equal = ((psa->uvd_clks.vclk == psb->uvd_clks.vclk) && (psa->uvd_clks.dclk == psb->uvd_clks.dclk)); | |
4595 | *equal &= ((psa->vce_clks.evclk == psb->vce_clks.evclk) && (psa->vce_clks.ecclk == psb->vce_clks.ecclk)); | |
4596 | *equal &= (psa->sclk_threshold == psb->sclk_threshold); | |
4597 | ||
4598 | return 0; | |
4599 | } | |
4600 | ||
2cc0c0b5 | 4601 | int polaris10_upload_mc_firmware(struct pp_hwmgr *hwmgr) |
a23eefa2 | 4602 | { |
2cc0c0b5 | 4603 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
4604 | |
4605 | uint32_t vbios_version; | |
4606 | ||
4607 | /* Read MC indirect register offset 0x9F bits [3:0] to see if VBIOS has already loaded a full version of MC ucode or not.*/ | |
4608 | ||
4609 | phm_get_mc_microcode_version(hwmgr); | |
4610 | vbios_version = hwmgr->microcode_version_info.MC & 0xf; | |
4611 | /* Full version of MC ucode has already been loaded. */ | |
4612 | if (vbios_version == 0) { | |
4613 | data->need_long_memory_training = false; | |
4614 | return 0; | |
4615 | } | |
4616 | ||
4617 | data->need_long_memory_training = true; | |
4618 | ||
4619 | /* | |
4620 | * PPMCME_FirmwareDescriptorEntry *pfd = NULL; | |
4621 | pfd = &tonga_mcmeFirmware; | |
4622 | if (0 == PHM_READ_FIELD(hwmgr->device, MC_SEQ_SUP_CNTL, RUN)) | |
2cc0c0b5 | 4623 | polaris10_load_mc_microcode(hwmgr, pfd->dpmThreshold, |
a23eefa2 RZ |
4624 | pfd->cfgArray, pfd->cfgSize, pfd->ioDebugArray, |
4625 | pfd->ioDebugSize, pfd->ucodeArray, pfd->ucodeSize); | |
4626 | */ | |
4627 | return 0; | |
4628 | } | |
4629 | ||
4630 | /** | |
4631 | * Read clock related registers. | |
4632 | * | |
4633 | * @param hwmgr the address of the powerplay hardware manager. | |
4634 | * @return always 0 | |
4635 | */ | |
2cc0c0b5 | 4636 | static int polaris10_read_clock_registers(struct pp_hwmgr *hwmgr) |
a23eefa2 | 4637 | { |
2cc0c0b5 | 4638 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
4639 | |
4640 | data->clock_registers.vCG_SPLL_FUNC_CNTL = cgs_read_ind_register(hwmgr->device, | |
4641 | CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL) | |
4642 | & CG_SPLL_FUNC_CNTL__SPLL_BYPASS_EN_MASK; | |
4643 | ||
4644 | data->clock_registers.vCG_SPLL_FUNC_CNTL_2 = cgs_read_ind_register(hwmgr->device, | |
4645 | CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_2) | |
4646 | & CG_SPLL_FUNC_CNTL_2__SCLK_MUX_SEL_MASK; | |
4647 | ||
4648 | data->clock_registers.vCG_SPLL_FUNC_CNTL_4 = cgs_read_ind_register(hwmgr->device, | |
4649 | CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_4) | |
4650 | & CG_SPLL_FUNC_CNTL_4__SPLL_SPARE_MASK; | |
4651 | ||
4652 | return 0; | |
4653 | } | |
4654 | ||
4655 | /** | |
4656 | * Find out if memory is GDDR5. | |
4657 | * | |
4658 | * @param hwmgr the address of the powerplay hardware manager. | |
4659 | * @return always 0 | |
4660 | */ | |
2cc0c0b5 | 4661 | static int polaris10_get_memory_type(struct pp_hwmgr *hwmgr) |
a23eefa2 | 4662 | { |
2cc0c0b5 | 4663 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
4664 | uint32_t temp; |
4665 | ||
4666 | temp = cgs_read_register(hwmgr->device, mmMC_SEQ_MISC0); | |
4667 | ||
4668 | data->is_memory_gddr5 = (MC_SEQ_MISC0_GDDR5_VALUE == | |
4669 | ((temp & MC_SEQ_MISC0_GDDR5_MASK) >> | |
4670 | MC_SEQ_MISC0_GDDR5_SHIFT)); | |
4671 | ||
4672 | return 0; | |
4673 | } | |
4674 | ||
4675 | /** | |
4676 | * Enables Dynamic Power Management by SMC | |
4677 | * | |
4678 | * @param hwmgr the address of the powerplay hardware manager. | |
4679 | * @return always 0 | |
4680 | */ | |
2cc0c0b5 | 4681 | static int polaris10_enable_acpi_power_management(struct pp_hwmgr *hwmgr) |
a23eefa2 RZ |
4682 | { |
4683 | PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, | |
4684 | GENERAL_PWRMGT, STATIC_PM_EN, 1); | |
4685 | ||
4686 | return 0; | |
4687 | } | |
4688 | ||
4689 | /** | |
4690 | * Initialize PowerGating States for different engines | |
4691 | * | |
4692 | * @param hwmgr the address of the powerplay hardware manager. | |
4693 | * @return always 0 | |
4694 | */ | |
2cc0c0b5 | 4695 | static int polaris10_init_power_gate_state(struct pp_hwmgr *hwmgr) |
a23eefa2 | 4696 | { |
2cc0c0b5 | 4697 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
4698 | |
4699 | data->uvd_power_gated = false; | |
4700 | data->vce_power_gated = false; | |
4701 | data->samu_power_gated = false; | |
4702 | ||
4703 | return 0; | |
4704 | } | |
4705 | ||
2cc0c0b5 | 4706 | static int polaris10_init_sclk_threshold(struct pp_hwmgr *hwmgr) |
a23eefa2 | 4707 | { |
2cc0c0b5 | 4708 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); |
a23eefa2 RZ |
4709 | data->low_sclk_interrupt_threshold = 0; |
4710 | ||
4711 | return 0; | |
4712 | } | |
4713 | ||
2cc0c0b5 | 4714 | int polaris10_setup_asic_task(struct pp_hwmgr *hwmgr) |
a23eefa2 RZ |
4715 | { |
4716 | int tmp_result, result = 0; | |
4717 | ||
2cc0c0b5 | 4718 | polaris10_upload_mc_firmware(hwmgr); |
a23eefa2 | 4719 | |
2cc0c0b5 | 4720 | tmp_result = polaris10_read_clock_registers(hwmgr); |
a23eefa2 RZ |
4721 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
4722 | "Failed to read clock registers!", result = tmp_result); | |
4723 | ||
2cc0c0b5 | 4724 | tmp_result = polaris10_get_memory_type(hwmgr); |
a23eefa2 RZ |
4725 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
4726 | "Failed to get memory type!", result = tmp_result); | |
4727 | ||
2cc0c0b5 | 4728 | tmp_result = polaris10_enable_acpi_power_management(hwmgr); |
a23eefa2 RZ |
4729 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
4730 | "Failed to enable ACPI power management!", result = tmp_result); | |
4731 | ||
2cc0c0b5 | 4732 | tmp_result = polaris10_init_power_gate_state(hwmgr); |
a23eefa2 RZ |
4733 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
4734 | "Failed to init power gate state!", result = tmp_result); | |
4735 | ||
4736 | tmp_result = phm_get_mc_microcode_version(hwmgr); | |
4737 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
4738 | "Failed to get MC microcode version!", result = tmp_result); | |
4739 | ||
2cc0c0b5 | 4740 | tmp_result = polaris10_init_sclk_threshold(hwmgr); |
a23eefa2 RZ |
4741 | PP_ASSERT_WITH_CODE((0 == tmp_result), |
4742 | "Failed to init sclk threshold!", result = tmp_result); | |
4743 | ||
4744 | return result; | |
4745 | } | |
4746 | ||
2cc0c0b5 FC |
4747 | static int polaris10_get_pp_table(struct pp_hwmgr *hwmgr, char **table) |
4748 | { | |
4749 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); | |
4750 | ||
4751 | *table = (char *)&data->smc_state_table; | |
4752 | ||
4753 | return sizeof(struct SMU74_Discrete_DpmTable); | |
4754 | } | |
4755 | ||
4756 | static int polaris10_set_pp_table(struct pp_hwmgr *hwmgr, const char *buf, size_t size) | |
4757 | { | |
4758 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); | |
4759 | ||
4760 | void *table = (void *)&data->smc_state_table; | |
4761 | ||
4762 | memcpy(table, buf, size); | |
4763 | ||
4764 | return 0; | |
4765 | } | |
4766 | ||
4767 | static int polaris10_force_clock_level(struct pp_hwmgr *hwmgr, | |
4768 | enum pp_clock_type type, int level) | |
4769 | { | |
4770 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); | |
4771 | ||
4772 | if (hwmgr->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL) | |
4773 | return -EINVAL; | |
4774 | ||
4775 | switch (type) { | |
4776 | case PP_SCLK: | |
4777 | if (!data->sclk_dpm_key_disabled) | |
4778 | smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, | |
4779 | PPSMC_MSG_SCLKDPM_SetEnabledMask, | |
4780 | (1 << level)); | |
4781 | break; | |
4782 | case PP_MCLK: | |
4783 | if (!data->mclk_dpm_key_disabled) | |
4784 | smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, | |
4785 | PPSMC_MSG_MCLKDPM_SetEnabledMask, | |
4786 | (1 << level)); | |
4787 | break; | |
4788 | case PP_PCIE: | |
4789 | if (!data->pcie_dpm_key_disabled) | |
4790 | smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, | |
4791 | PPSMC_MSG_PCIeDPM_ForceLevel, | |
4792 | (1 << level)); | |
4793 | break; | |
4794 | default: | |
4795 | break; | |
4796 | } | |
4797 | ||
4798 | return 0; | |
4799 | } | |
4800 | ||
4801 | static uint16_t polaris10_get_current_pcie_speed(struct pp_hwmgr *hwmgr) | |
4802 | { | |
4803 | uint32_t speedCntl = 0; | |
4804 | ||
4805 | /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */ | |
4806 | speedCntl = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__PCIE, | |
4807 | ixPCIE_LC_SPEED_CNTL); | |
4808 | return((uint16_t)PHM_GET_FIELD(speedCntl, | |
4809 | PCIE_LC_SPEED_CNTL, LC_CURRENT_DATA_RATE)); | |
4810 | } | |
4811 | ||
4812 | static int polaris10_print_clock_levels(struct pp_hwmgr *hwmgr, | |
4813 | enum pp_clock_type type, char *buf) | |
4814 | { | |
4815 | struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend); | |
4816 | struct polaris10_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table); | |
4817 | struct polaris10_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table); | |
4818 | struct polaris10_single_dpm_table *pcie_table = &(data->dpm_table.pcie_speed_table); | |
4819 | int i, now, size = 0; | |
4820 | uint32_t clock, pcie_speed; | |
4821 | ||
4822 | switch (type) { | |
4823 | case PP_SCLK: | |
4824 | smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetSclkFrequency); | |
4825 | clock = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0); | |
4826 | ||
4827 | for (i = 0; i < sclk_table->count; i++) { | |
4828 | if (clock > sclk_table->dpm_levels[i].value) | |
4829 | continue; | |
4830 | break; | |
4831 | } | |
4832 | now = i; | |
4833 | ||
4834 | for (i = 0; i < sclk_table->count; i++) | |
4835 | size += sprintf(buf + size, "%d: %uMhz %s\n", | |
4836 | i, sclk_table->dpm_levels[i].value / 100, | |
4837 | (i == now) ? "*" : ""); | |
4838 | break; | |
4839 | case PP_MCLK: | |
4840 | smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetMclkFrequency); | |
4841 | clock = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0); | |
4842 | ||
4843 | for (i = 0; i < mclk_table->count; i++) { | |
4844 | if (clock > mclk_table->dpm_levels[i].value) | |
4845 | continue; | |
4846 | break; | |
4847 | } | |
4848 | now = i; | |
4849 | ||
4850 | for (i = 0; i < mclk_table->count; i++) | |
4851 | size += sprintf(buf + size, "%d: %uMhz %s\n", | |
4852 | i, mclk_table->dpm_levels[i].value / 100, | |
4853 | (i == now) ? "*" : ""); | |
4854 | break; | |
4855 | case PP_PCIE: | |
4856 | pcie_speed = polaris10_get_current_pcie_speed(hwmgr); | |
4857 | for (i = 0; i < pcie_table->count; i++) { | |
4858 | if (pcie_speed != pcie_table->dpm_levels[i].value) | |
4859 | continue; | |
4860 | break; | |
4861 | } | |
4862 | now = i; | |
4863 | ||
4864 | for (i = 0; i < pcie_table->count; i++) | |
4865 | size += sprintf(buf + size, "%d: %s %s\n", i, | |
4866 | (pcie_table->dpm_levels[i].value == 0) ? "2.5GB, x8" : | |
4867 | (pcie_table->dpm_levels[i].value == 1) ? "5.0GB, x16" : | |
4868 | (pcie_table->dpm_levels[i].value == 2) ? "8.0GB, x16" : "", | |
4869 | (i == now) ? "*" : ""); | |
4870 | break; | |
4871 | default: | |
4872 | break; | |
4873 | } | |
4874 | return size; | |
4875 | } | |
4876 | ||
9e26bbb3 RZ |
4877 | static int polaris10_set_fan_control_mode(struct pp_hwmgr *hwmgr, uint32_t mode) |
4878 | { | |
4879 | if (mode) { | |
4880 | /* stop auto-manage */ | |
4881 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
4882 | PHM_PlatformCaps_MicrocodeFanControl)) | |
4883 | polaris10_fan_ctrl_stop_smc_fan_control(hwmgr); | |
4884 | polaris10_fan_ctrl_set_static_mode(hwmgr, mode); | |
4885 | } else | |
4886 | /* restart auto-manage */ | |
4887 | polaris10_fan_ctrl_reset_fan_speed_to_default(hwmgr); | |
4888 | ||
4889 | return 0; | |
4890 | } | |
4891 | ||
4892 | static int polaris10_get_fan_control_mode(struct pp_hwmgr *hwmgr) | |
4893 | { | |
4894 | if (hwmgr->fan_ctrl_is_in_default_mode) | |
4895 | return hwmgr->fan_ctrl_default_mode; | |
4896 | else | |
4897 | return PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, | |
4898 | CG_FDO_CTRL2, FDO_PWM_MODE); | |
4899 | } | |
4900 | ||
2cc0c0b5 FC |
4901 | static const struct pp_hwmgr_func polaris10_hwmgr_funcs = { |
4902 | .backend_init = &polaris10_hwmgr_backend_init, | |
4903 | .backend_fini = &polaris10_hwmgr_backend_fini, | |
4904 | .asic_setup = &polaris10_setup_asic_task, | |
4905 | .dynamic_state_management_enable = &polaris10_enable_dpm_tasks, | |
4906 | .apply_state_adjust_rules = polaris10_apply_state_adjust_rules, | |
4907 | .force_dpm_level = &polaris10_force_dpm_level, | |
4908 | .power_state_set = polaris10_set_power_state_tasks, | |
4909 | .get_power_state_size = polaris10_get_power_state_size, | |
4910 | .get_mclk = polaris10_dpm_get_mclk, | |
4911 | .get_sclk = polaris10_dpm_get_sclk, | |
4912 | .patch_boot_state = polaris10_dpm_patch_boot_state, | |
4913 | .get_pp_table_entry = polaris10_get_pp_table_entry, | |
a23eefa2 | 4914 | .get_num_of_pp_table_entries = tonga_get_number_of_powerplay_table_entries, |
2cc0c0b5 FC |
4915 | .print_current_perforce_level = polaris10_print_current_perforce_level, |
4916 | .powerdown_uvd = polaris10_phm_powerdown_uvd, | |
4917 | .powergate_uvd = polaris10_phm_powergate_uvd, | |
4918 | .powergate_vce = polaris10_phm_powergate_vce, | |
4919 | .disable_clock_power_gating = polaris10_phm_disable_clock_power_gating, | |
4920 | .update_clock_gatings = polaris10_phm_update_clock_gatings, | |
4921 | .notify_smc_display_config_after_ps_adjustment = polaris10_notify_smc_display_config_after_ps_adjustment, | |
4922 | .display_config_changed = polaris10_display_configuration_changed_task, | |
4923 | .set_max_fan_pwm_output = polaris10_set_max_fan_pwm_output, | |
4924 | .set_max_fan_rpm_output = polaris10_set_max_fan_rpm_output, | |
4925 | .get_temperature = polaris10_thermal_get_temperature, | |
4926 | .stop_thermal_controller = polaris10_thermal_stop_thermal_controller, | |
4927 | .get_fan_speed_info = polaris10_fan_ctrl_get_fan_speed_info, | |
4928 | .get_fan_speed_percent = polaris10_fan_ctrl_get_fan_speed_percent, | |
4929 | .set_fan_speed_percent = polaris10_fan_ctrl_set_fan_speed_percent, | |
4930 | .reset_fan_speed_to_default = polaris10_fan_ctrl_reset_fan_speed_to_default, | |
4931 | .get_fan_speed_rpm = polaris10_fan_ctrl_get_fan_speed_rpm, | |
4932 | .set_fan_speed_rpm = polaris10_fan_ctrl_set_fan_speed_rpm, | |
4933 | .uninitialize_thermal_controller = polaris10_thermal_ctrl_uninitialize_thermal_controller, | |
4934 | .register_internal_thermal_interrupt = polaris10_register_internal_thermal_interrupt, | |
4935 | .check_smc_update_required_for_display_configuration = polaris10_check_smc_update_required_for_display_configuration, | |
4936 | .check_states_equal = polaris10_check_states_equal, | |
9e26bbb3 RZ |
4937 | .set_fan_control_mode = polaris10_set_fan_control_mode, |
4938 | .get_fan_control_mode = polaris10_get_fan_control_mode, | |
2cc0c0b5 FC |
4939 | .get_pp_table = polaris10_get_pp_table, |
4940 | .set_pp_table = polaris10_set_pp_table, | |
4941 | .force_clock_level = polaris10_force_clock_level, | |
4942 | .print_clock_levels = polaris10_print_clock_levels, | |
4943 | .enable_per_cu_power_gating = polaris10_phm_enable_per_cu_power_gating, | |
a23eefa2 RZ |
4944 | }; |
4945 | ||
2cc0c0b5 | 4946 | int polaris10_hwmgr_init(struct pp_hwmgr *hwmgr) |
a23eefa2 | 4947 | { |
2cc0c0b5 | 4948 | struct polaris10_hwmgr *data; |
a23eefa2 | 4949 | |
2cc0c0b5 | 4950 | data = kzalloc (sizeof(struct polaris10_hwmgr), GFP_KERNEL); |
a23eefa2 RZ |
4951 | if (data == NULL) |
4952 | return -ENOMEM; | |
4953 | ||
4954 | hwmgr->backend = data; | |
2cc0c0b5 | 4955 | hwmgr->hwmgr_func = &polaris10_hwmgr_funcs; |
a23eefa2 | 4956 | hwmgr->pptable_func = &tonga_pptable_funcs; |
2cc0c0b5 | 4957 | pp_polaris10_thermal_initialize(hwmgr); |
a23eefa2 RZ |
4958 | |
4959 | return 0; | |
4960 | } |