]>
Commit | Line | Data |
---|---|---|
c82baa28 | 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> | |
26 | #include "linux/delay.h" | |
27 | #include "pp_acpi.h" | |
28 | #include "hwmgr.h" | |
29 | #include <atombios.h> | |
30 | #include "tonga_hwmgr.h" | |
31 | #include "pptable.h" | |
32 | #include "processpptables.h" | |
33 | #include "tonga_processpptables.h" | |
34 | #include "tonga_pptable.h" | |
35 | #include "pp_debug.h" | |
36 | #include "tonga_ppsmc.h" | |
37 | #include "cgs_common.h" | |
38 | #include "pppcielanes.h" | |
39 | #include "tonga_dyn_defaults.h" | |
40 | #include "smumgr.h" | |
41 | #include "tonga_smumgr.h" | |
42 | ||
43 | #include "smu/smu_7_1_2_d.h" | |
44 | #include "smu/smu_7_1_2_sh_mask.h" | |
45 | ||
46 | #include "gmc/gmc_8_1_d.h" | |
47 | #include "gmc/gmc_8_1_sh_mask.h" | |
48 | ||
49 | #include "bif/bif_5_0_d.h" | |
50 | #include "bif/bif_5_0_sh_mask.h" | |
51 | ||
52 | #define MC_CG_ARB_FREQ_F0 0x0a | |
53 | #define MC_CG_ARB_FREQ_F1 0x0b | |
54 | #define MC_CG_ARB_FREQ_F2 0x0c | |
55 | #define MC_CG_ARB_FREQ_F3 0x0d | |
56 | ||
57 | #define MC_CG_SEQ_DRAMCONF_S0 0x05 | |
58 | #define MC_CG_SEQ_DRAMCONF_S1 0x06 | |
59 | #define MC_CG_SEQ_YCLK_SUSPEND 0x04 | |
60 | #define MC_CG_SEQ_YCLK_RESUME 0x0a | |
61 | ||
62 | #define PCIE_BUS_CLK 10000 | |
63 | #define TCLK (PCIE_BUS_CLK / 10) | |
64 | ||
65 | #define SMC_RAM_END 0x40000 | |
66 | #define SMC_CG_IND_START 0xc0030000 | |
67 | #define SMC_CG_IND_END 0xc0040000 /* First byte after SMC_CG_IND*/ | |
68 | ||
69 | #define VOLTAGE_SCALE 4 | |
70 | #define VOLTAGE_VID_OFFSET_SCALE1 625 | |
71 | #define VOLTAGE_VID_OFFSET_SCALE2 100 | |
72 | ||
73 | #define VDDC_VDDCI_DELTA 200 | |
74 | #define VDDC_VDDGFX_DELTA 300 | |
75 | ||
76 | #define MC_SEQ_MISC0_GDDR5_SHIFT 28 | |
77 | #define MC_SEQ_MISC0_GDDR5_MASK 0xf0000000 | |
78 | #define MC_SEQ_MISC0_GDDR5_VALUE 5 | |
79 | ||
80 | typedef uint32_t PECI_RegistryValue; | |
81 | ||
82 | /* [2.5%,~2.5%] Clock stretched is multiple of 2.5% vs not and [Fmin, Fmax, LDO_REFSEL, USE_FOR_LOW_FREQ] */ | |
83 | uint16_t PP_ClockStretcherLookupTable[2][4] = { | |
84 | {600, 1050, 3, 0}, | |
85 | {600, 1050, 6, 1} }; | |
86 | ||
87 | /* [FF, SS] type, [] 4 voltage ranges, and [Floor Freq, Boundary Freq, VID min , VID max] */ | |
88 | uint32_t PP_ClockStretcherDDTTable[2][4][4] = { | |
89 | { {265, 529, 120, 128}, {325, 650, 96, 119}, {430, 860, 32, 95}, {0, 0, 0, 31} }, | |
90 | { {275, 550, 104, 112}, {319, 638, 96, 103}, {360, 720, 64, 95}, {384, 768, 32, 63} } }; | |
91 | ||
92 | /* [Use_For_Low_freq] value, [0%, 5%, 10%, 7.14%, 14.28%, 20%] (coming from PWR_CKS_CNTL.stretch_amount reg spec) */ | |
93 | uint8_t PP_ClockStretchAmountConversion[2][6] = { | |
94 | {0, 1, 3, 2, 4, 5}, | |
95 | {0, 2, 4, 5, 6, 5} }; | |
96 | ||
97 | /* Values for the CG_THERMAL_CTRL::DPM_EVENT_SRC field. */ | |
98 | enum DPM_EVENT_SRC { | |
99 | DPM_EVENT_SRC_ANALOG = 0, /* Internal analog trip point */ | |
100 | DPM_EVENT_SRC_EXTERNAL = 1, /* External (GPIO 17) signal */ | |
101 | DPM_EVENT_SRC_DIGITAL = 2, /* Internal digital trip point (DIG_THERM_DPM) */ | |
102 | DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3, /* Internal analog or external */ | |
103 | DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL = 4 /* Internal digital or external */ | |
104 | }; | |
105 | typedef enum DPM_EVENT_SRC DPM_EVENT_SRC; | |
106 | ||
107 | enum DISPLAY_GAP { | |
108 | DISPLAY_GAP_VBLANK_OR_WM = 0, /* Wait for vblank or MCHG watermark. */ | |
109 | DISPLAY_GAP_VBLANK = 1, /* Wait for vblank. */ | |
110 | DISPLAY_GAP_WATERMARK = 2, /* Wait for MCHG watermark. (Note that HW may deassert WM in VBI depending on DC_STUTTER_CNTL.) */ | |
111 | DISPLAY_GAP_IGNORE = 3 /* Do not wait. */ | |
112 | }; | |
113 | typedef enum DISPLAY_GAP DISPLAY_GAP; | |
114 | ||
115 | const unsigned long PhwTonga_Magic = (unsigned long)(PHM_VIslands_Magic); | |
116 | ||
117 | struct tonga_power_state *cast_phw_tonga_power_state( | |
118 | struct pp_hw_power_state *hw_ps) | |
119 | { | |
120 | PP_ASSERT_WITH_CODE((PhwTonga_Magic == hw_ps->magic), | |
121 | "Invalid Powerstate Type!", | |
122 | return NULL;); | |
123 | ||
124 | return (struct tonga_power_state *)hw_ps; | |
125 | } | |
126 | ||
127 | const struct tonga_power_state *cast_const_phw_tonga_power_state( | |
128 | const struct pp_hw_power_state *hw_ps) | |
129 | { | |
130 | PP_ASSERT_WITH_CODE((PhwTonga_Magic == hw_ps->magic), | |
131 | "Invalid Powerstate Type!", | |
132 | return NULL;); | |
133 | ||
134 | return (const struct tonga_power_state *)hw_ps; | |
135 | } | |
136 | ||
137 | int tonga_add_voltage(struct pp_hwmgr *hwmgr, | |
138 | phm_ppt_v1_voltage_lookup_table *look_up_table, | |
139 | phm_ppt_v1_voltage_lookup_record *record) | |
140 | { | |
141 | uint32_t i; | |
142 | PP_ASSERT_WITH_CODE((NULL != look_up_table), | |
143 | "Lookup Table empty.", return -1;); | |
144 | PP_ASSERT_WITH_CODE((0 != look_up_table->count), | |
145 | "Lookup Table empty.", return -1;); | |
146 | PP_ASSERT_WITH_CODE((SMU72_MAX_LEVELS_VDDGFX >= look_up_table->count), | |
147 | "Lookup Table is full.", return -1;); | |
148 | ||
149 | /* This is to avoid entering duplicate calculated records. */ | |
150 | for (i = 0; i < look_up_table->count; i++) { | |
151 | if (look_up_table->entries[i].us_vdd == record->us_vdd) { | |
152 | if (look_up_table->entries[i].us_calculated == 1) | |
153 | return 0; | |
154 | else | |
155 | break; | |
156 | } | |
157 | } | |
158 | ||
159 | look_up_table->entries[i].us_calculated = 1; | |
160 | look_up_table->entries[i].us_vdd = record->us_vdd; | |
161 | look_up_table->entries[i].us_cac_low = record->us_cac_low; | |
162 | look_up_table->entries[i].us_cac_mid = record->us_cac_mid; | |
163 | look_up_table->entries[i].us_cac_high = record->us_cac_high; | |
164 | /* Only increment the count when we're appending, not replacing duplicate entry. */ | |
165 | if (i == look_up_table->count) | |
166 | look_up_table->count++; | |
167 | ||
168 | return 0; | |
169 | } | |
170 | ||
171 | uint8_t tonga_get_voltage_id(pp_atomctrl_voltage_table *voltage_table, | |
172 | uint32_t voltage) | |
173 | { | |
174 | uint8_t count = (uint8_t) (voltage_table->count); | |
175 | uint8_t i = 0; | |
176 | ||
177 | PP_ASSERT_WITH_CODE((NULL != voltage_table), | |
178 | "Voltage Table empty.", return 0;); | |
179 | PP_ASSERT_WITH_CODE((0 != count), | |
180 | "Voltage Table empty.", return 0;); | |
181 | ||
182 | for (i = 0; i < count; i++) { | |
183 | /* find first voltage bigger than requested */ | |
184 | if (voltage_table->entries[i].value >= voltage) | |
185 | return i; | |
186 | } | |
187 | ||
188 | /* voltage is bigger than max voltage in the table */ | |
189 | return i - 1; | |
190 | } | |
191 | ||
192 | /** | |
193 | * @brief PhwTonga_GetVoltageOrder | |
194 | * Returns index of requested voltage record in lookup(table) | |
195 | * @param hwmgr - pointer to hardware manager | |
196 | * @param lookupTable - lookup list to search in | |
197 | * @param voltage - voltage to look for | |
198 | * @return 0 on success | |
199 | */ | |
200 | uint8_t tonga_get_voltage_index(phm_ppt_v1_voltage_lookup_table *look_up_table, | |
201 | uint16_t voltage) | |
202 | { | |
203 | uint8_t count = (uint8_t) (look_up_table->count); | |
204 | uint8_t i; | |
205 | ||
206 | PP_ASSERT_WITH_CODE((NULL != look_up_table), "Lookup Table empty.", return 0;); | |
207 | PP_ASSERT_WITH_CODE((0 != count), "Lookup Table empty.", return 0;); | |
208 | ||
209 | for (i = 0; i < count; i++) { | |
210 | /* find first voltage equal or bigger than requested */ | |
211 | if (look_up_table->entries[i].us_vdd >= voltage) | |
212 | return i; | |
213 | } | |
214 | ||
215 | /* voltage is bigger than max voltage in the table */ | |
216 | return i-1; | |
217 | } | |
218 | ||
219 | bool tonga_is_dpm_running(struct pp_hwmgr *hwmgr) | |
220 | { | |
221 | /* | |
222 | * We return the status of Voltage Control instead of checking SCLK/MCLK DPM | |
223 | * because we may have test scenarios that need us intentionly disable SCLK/MCLK DPM, | |
224 | * whereas voltage control is a fundemental change that will not be disabled | |
225 | */ | |
226 | ||
227 | return (0 == PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, | |
228 | FEATURE_STATUS, VOLTAGE_CONTROLLER_ON) ? 1 : 0); | |
229 | } | |
230 | ||
231 | /** | |
232 | * Re-generate the DPM level mask value | |
233 | * @param hwmgr the address of the hardware manager | |
234 | */ | |
235 | static uint32_t tonga_get_dpm_level_enable_mask_value( | |
236 | struct tonga_single_dpm_table * dpm_table) | |
237 | { | |
238 | uint32_t i; | |
239 | uint32_t mask_value = 0; | |
240 | ||
241 | for (i = dpm_table->count; i > 0; i--) { | |
242 | mask_value = mask_value << 1; | |
243 | ||
244 | if (dpm_table->dpm_levels[i-1].enabled) | |
245 | mask_value |= 0x1; | |
246 | else | |
247 | mask_value &= 0xFFFFFFFE; | |
248 | } | |
249 | return mask_value; | |
250 | } | |
251 | ||
252 | /** | |
253 | * Retrieve DPM default values from registry (if available) | |
254 | * | |
255 | * @param hwmgr the address of the powerplay hardware manager. | |
256 | */ | |
257 | void tonga_initialize_dpm_defaults(struct pp_hwmgr *hwmgr) | |
258 | { | |
259 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
260 | phw_tonga_ulv_parm *ulv = &(data->ulv); | |
261 | uint32_t tmp; | |
262 | ||
263 | ulv->ch_ulv_parameter = PPTONGA_CGULVPARAMETER_DFLT; | |
264 | data->voting_rights_clients0 = PPTONGA_VOTINGRIGHTSCLIENTS_DFLT0; | |
265 | data->voting_rights_clients1 = PPTONGA_VOTINGRIGHTSCLIENTS_DFLT1; | |
266 | data->voting_rights_clients2 = PPTONGA_VOTINGRIGHTSCLIENTS_DFLT2; | |
267 | data->voting_rights_clients3 = PPTONGA_VOTINGRIGHTSCLIENTS_DFLT3; | |
268 | data->voting_rights_clients4 = PPTONGA_VOTINGRIGHTSCLIENTS_DFLT4; | |
269 | data->voting_rights_clients5 = PPTONGA_VOTINGRIGHTSCLIENTS_DFLT5; | |
270 | data->voting_rights_clients6 = PPTONGA_VOTINGRIGHTSCLIENTS_DFLT6; | |
271 | data->voting_rights_clients7 = PPTONGA_VOTINGRIGHTSCLIENTS_DFLT7; | |
272 | ||
273 | data->static_screen_threshold_unit = PPTONGA_STATICSCREENTHRESHOLDUNIT_DFLT; | |
274 | data->static_screen_threshold = PPTONGA_STATICSCREENTHRESHOLD_DFLT; | |
275 | ||
276 | phm_cap_unset(hwmgr->platform_descriptor.platformCaps, | |
277 | PHM_PlatformCaps_ABM); | |
278 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
279 | PHM_PlatformCaps_NonABMSupportInPPLib); | |
280 | ||
281 | tmp = 0; | |
282 | if (tmp == 0) | |
283 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
284 | PHM_PlatformCaps_DynamicACTiming); | |
285 | ||
286 | tmp = 0; | |
287 | if (0 != tmp) | |
288 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
289 | PHM_PlatformCaps_DisableMemoryTransition); | |
290 | ||
291 | data->mclk_strobe_mode_threshold = 40000; | |
292 | data->mclk_stutter_mode_threshold = 30000; | |
293 | data->mclk_edc_enable_threshold = 40000; | |
294 | data->mclk_edc_wr_enable_threshold = 40000; | |
295 | ||
296 | tmp = 0; | |
297 | if (tmp != 0) | |
298 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
299 | PHM_PlatformCaps_DisableMCLS); | |
300 | ||
301 | data->pcie_gen_performance.max = PP_PCIEGen1; | |
302 | data->pcie_gen_performance.min = PP_PCIEGen3; | |
303 | data->pcie_gen_power_saving.max = PP_PCIEGen1; | |
304 | data->pcie_gen_power_saving.min = PP_PCIEGen3; | |
305 | ||
306 | data->pcie_lane_performance.max = 0; | |
307 | data->pcie_lane_performance.min = 16; | |
308 | data->pcie_lane_power_saving.max = 0; | |
309 | data->pcie_lane_power_saving.min = 16; | |
310 | ||
311 | tmp = 0; | |
312 | ||
313 | if (tmp) | |
314 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
315 | PHM_PlatformCaps_SclkThrottleLowNotification); | |
316 | ||
317 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
318 | PHM_PlatformCaps_DynamicUVDState); | |
319 | ||
320 | } | |
321 | ||
322 | int tonga_update_sclk_threshold(struct pp_hwmgr *hwmgr) | |
323 | { | |
324 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
325 | ||
326 | int result = 0; | |
327 | uint32_t low_sclk_interrupt_threshold = 0; | |
328 | ||
329 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
330 | PHM_PlatformCaps_SclkThrottleLowNotification) | |
331 | && (hwmgr->gfx_arbiter.sclk_threshold != data->low_sclk_interrupt_threshold)) { | |
332 | data->low_sclk_interrupt_threshold = hwmgr->gfx_arbiter.sclk_threshold; | |
333 | low_sclk_interrupt_threshold = data->low_sclk_interrupt_threshold; | |
334 | ||
335 | CONVERT_FROM_HOST_TO_SMC_UL(low_sclk_interrupt_threshold); | |
336 | ||
337 | result = tonga_copy_bytes_to_smc( | |
338 | hwmgr->smumgr, | |
339 | data->dpm_table_start + offsetof(SMU72_Discrete_DpmTable, | |
340 | LowSclkInterruptThreshold), | |
341 | (uint8_t *)&low_sclk_interrupt_threshold, | |
342 | sizeof(uint32_t), | |
343 | data->sram_end | |
344 | ); | |
345 | } | |
346 | ||
347 | return result; | |
348 | } | |
349 | ||
350 | /** | |
351 | * Find SCLK value that is associated with specified virtual_voltage_Id. | |
352 | * | |
353 | * @param hwmgr the address of the powerplay hardware manager. | |
354 | * @param virtual_voltage_Id voltageId to look for. | |
355 | * @param sclk output value . | |
356 | * @return always 0 if success and 2 if association not found | |
357 | */ | |
358 | static int tonga_get_sclk_for_voltage_evv(struct pp_hwmgr *hwmgr, | |
359 | phm_ppt_v1_voltage_lookup_table *lookup_table, | |
360 | uint16_t virtual_voltage_id, uint32_t *sclk) | |
361 | { | |
362 | uint8_t entryId; | |
363 | uint8_t voltageId; | |
364 | struct phm_ppt_v1_information *pptable_info = | |
365 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
366 | ||
367 | PP_ASSERT_WITH_CODE(lookup_table->count != 0, "Lookup table is empty", return -1); | |
368 | ||
369 | /* search for leakage voltage ID 0xff01 ~ 0xff08 and sckl */ | |
370 | for (entryId = 0; entryId < pptable_info->vdd_dep_on_sclk->count; entryId++) { | |
371 | voltageId = pptable_info->vdd_dep_on_sclk->entries[entryId].vddInd; | |
372 | if (lookup_table->entries[voltageId].us_vdd == virtual_voltage_id) | |
373 | break; | |
374 | } | |
375 | ||
376 | PP_ASSERT_WITH_CODE(entryId < pptable_info->vdd_dep_on_sclk->count, | |
377 | "Can't find requested voltage id in vdd_dep_on_sclk table!", | |
378 | return -1; | |
379 | ); | |
380 | ||
381 | *sclk = pptable_info->vdd_dep_on_sclk->entries[entryId].clk; | |
382 | ||
383 | return 0; | |
384 | } | |
385 | ||
386 | /** | |
387 | * Get Leakage VDDC based on leakage ID. | |
388 | * | |
389 | * @param hwmgr the address of the powerplay hardware manager. | |
390 | * @return 2 if vddgfx returned is greater than 2V or if BIOS | |
391 | */ | |
392 | int tonga_get_evv_voltage(struct pp_hwmgr *hwmgr) | |
393 | { | |
394 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
395 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
396 | phm_ppt_v1_clock_voltage_dependency_table *sclk_table = pptable_info->vdd_dep_on_sclk; | |
397 | uint16_t virtual_voltage_id; | |
398 | uint16_t vddc = 0; | |
399 | uint16_t vddgfx = 0; | |
400 | uint16_t i, j; | |
401 | uint32_t sclk = 0; | |
402 | ||
403 | /* retrieve voltage for leakage ID (0xff01 + i) */ | |
404 | for (i = 0; i < TONGA_MAX_LEAKAGE_COUNT; i++) { | |
405 | virtual_voltage_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i; | |
406 | ||
407 | /* in split mode we should have only vddgfx EVV leakages */ | |
408 | if (data->vdd_gfx_control == TONGA_VOLTAGE_CONTROL_BY_SVID2) { | |
409 | if (0 == tonga_get_sclk_for_voltage_evv(hwmgr, | |
410 | pptable_info->vddgfx_lookup_table, virtual_voltage_id, &sclk)) { | |
411 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
412 | PHM_PlatformCaps_ClockStretcher)) { | |
413 | for (j = 1; j < sclk_table->count; j++) { | |
414 | if (sclk_table->entries[j].clk == sclk && | |
415 | sclk_table->entries[j].cks_enable == 0) { | |
416 | sclk += 5000; | |
417 | break; | |
418 | } | |
419 | } | |
420 | } | |
421 | PP_ASSERT_WITH_CODE(0 == atomctrl_get_voltage_evv_on_sclk | |
422 | (hwmgr, VOLTAGE_TYPE_VDDGFX, sclk, | |
423 | virtual_voltage_id, &vddgfx), | |
424 | "Error retrieving EVV voltage value!", continue); | |
425 | ||
426 | /* need to make sure vddgfx is less than 2v or else, it could burn the ASIC. */ | |
427 | PP_ASSERT_WITH_CODE((vddgfx < 2000 && vddgfx != 0), "Invalid VDDGFX value!", return -1); | |
428 | ||
429 | /* the voltage should not be zero nor equal to leakage ID */ | |
430 | if (vddgfx != 0 && vddgfx != virtual_voltage_id) { | |
431 | data->vddcgfx_leakage.actual_voltage[data->vddcgfx_leakage.count] = vddgfx; | |
432 | data->vddcgfx_leakage.leakage_id[data->vddcgfx_leakage.count] = virtual_voltage_id; | |
433 | data->vddcgfx_leakage.count++; | |
434 | } | |
435 | } | |
436 | } else { | |
437 | /* in merged mode we have only vddc EVV leakages */ | |
438 | if (0 == tonga_get_sclk_for_voltage_evv(hwmgr, | |
439 | pptable_info->vddc_lookup_table, | |
440 | virtual_voltage_id, &sclk)) { | |
441 | PP_ASSERT_WITH_CODE(0 == atomctrl_get_voltage_evv_on_sclk | |
442 | (hwmgr, VOLTAGE_TYPE_VDDC, sclk, | |
443 | virtual_voltage_id, &vddc), | |
444 | "Error retrieving EVV voltage value!", continue); | |
445 | ||
446 | /* need to make sure vddc is less than 2v or else, it could burn the ASIC. */ | |
447 | if (vddc > 2000) | |
448 | printk(KERN_ERR "[ powerplay ] Invalid VDDC value! \n"); | |
449 | ||
450 | /* the voltage should not be zero nor equal to leakage ID */ | |
451 | if (vddc != 0 && vddc != virtual_voltage_id) { | |
452 | data->vddc_leakage.actual_voltage[data->vddc_leakage.count] = vddc; | |
453 | data->vddc_leakage.leakage_id[data->vddc_leakage.count] = virtual_voltage_id; | |
454 | data->vddc_leakage.count++; | |
455 | } | |
456 | } | |
457 | } | |
458 | } | |
459 | ||
460 | return 0; | |
461 | } | |
462 | ||
463 | int tonga_enable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr) | |
464 | { | |
465 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
466 | ||
467 | /* enable SCLK dpm */ | |
468 | if (0 == data->sclk_dpm_key_disabled) { | |
469 | PP_ASSERT_WITH_CODE( | |
470 | (0 == smum_send_msg_to_smc(hwmgr->smumgr, | |
471 | PPSMC_MSG_DPM_Enable)), | |
472 | "Failed to enable SCLK DPM during DPM Start Function!", | |
473 | return -1); | |
474 | } | |
475 | ||
476 | /* enable MCLK dpm */ | |
477 | if (0 == data->mclk_dpm_key_disabled) { | |
478 | PP_ASSERT_WITH_CODE( | |
479 | (0 == smum_send_msg_to_smc(hwmgr->smumgr, | |
480 | PPSMC_MSG_MCLKDPM_Enable)), | |
481 | "Failed to enable MCLK DPM during DPM Start Function!", | |
482 | return -1); | |
483 | ||
484 | PHM_WRITE_FIELD(hwmgr->device, MC_SEQ_CNTL_3, CAC_EN, 0x1); | |
485 | ||
486 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
487 | ixLCAC_MC0_CNTL, 0x05);/* CH0,1 read */ | |
488 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
489 | ixLCAC_MC1_CNTL, 0x05);/* CH2,3 read */ | |
490 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
491 | ixLCAC_CPL_CNTL, 0x100005);/*Read */ | |
492 | ||
493 | udelay(10); | |
494 | ||
495 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
496 | ixLCAC_MC0_CNTL, 0x400005);/* CH0,1 write */ | |
497 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
498 | ixLCAC_MC1_CNTL, 0x400005);/* CH2,3 write */ | |
499 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
500 | ixLCAC_CPL_CNTL, 0x500005);/* write */ | |
501 | ||
502 | } | |
503 | ||
504 | return 0; | |
505 | } | |
506 | ||
507 | int tonga_start_dpm(struct pp_hwmgr *hwmgr) | |
508 | { | |
509 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
510 | ||
511 | /* enable general power management */ | |
512 | PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT, GLOBAL_PWRMGT_EN, 1); | |
513 | /* enable sclk deep sleep */ | |
514 | PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL, DYNAMIC_PM_EN, 1); | |
515 | ||
516 | /* prepare for PCIE DPM */ | |
517 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, data->soft_regs_start + | |
518 | offsetof(SMU72_SoftRegisters, VoltageChangeTimeout), 0x1000); | |
519 | ||
520 | PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE, SWRST_COMMAND_1, RESETLC, 0x0); | |
521 | ||
522 | PP_ASSERT_WITH_CODE( | |
523 | (0 == smum_send_msg_to_smc(hwmgr->smumgr, | |
524 | PPSMC_MSG_Voltage_Cntl_Enable)), | |
525 | "Failed to enable voltage DPM during DPM Start Function!", | |
526 | return -1); | |
527 | ||
528 | if (0 != tonga_enable_sclk_mclk_dpm(hwmgr)) { | |
529 | PP_ASSERT_WITH_CODE(0, "Failed to enable Sclk DPM and Mclk DPM!", return -1); | |
530 | } | |
531 | ||
532 | /* enable PCIE dpm */ | |
533 | if (0 == data->pcie_dpm_key_disabled) { | |
534 | PP_ASSERT_WITH_CODE( | |
535 | (0 == smum_send_msg_to_smc(hwmgr->smumgr, | |
536 | PPSMC_MSG_PCIeDPM_Enable)), | |
537 | "Failed to enable pcie DPM during DPM Start Function!", | |
538 | return -1 | |
539 | ); | |
540 | } | |
541 | ||
542 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
543 | PHM_PlatformCaps_Falcon_QuickTransition)) { | |
544 | smum_send_msg_to_smc(hwmgr->smumgr, | |
545 | PPSMC_MSG_EnableACDCGPIOInterrupt); | |
546 | } | |
547 | ||
548 | return 0; | |
549 | } | |
550 | ||
551 | int tonga_disable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr) | |
552 | { | |
553 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
554 | ||
555 | /* disable SCLK dpm */ | |
556 | if (0 == data->sclk_dpm_key_disabled) { | |
557 | /* Checking if DPM is running. If we discover hang because of this, we should skip this message.*/ | |
558 | PP_ASSERT_WITH_CODE( | |
559 | (0 == tonga_is_dpm_running(hwmgr)), | |
560 | "Trying to Disable SCLK DPM when DPM is disabled", | |
561 | return -1 | |
562 | ); | |
563 | ||
564 | PP_ASSERT_WITH_CODE( | |
565 | (0 == smum_send_msg_to_smc(hwmgr->smumgr, | |
566 | PPSMC_MSG_DPM_Disable)), | |
567 | "Failed to disable SCLK DPM during DPM stop Function!", | |
568 | return -1); | |
569 | } | |
570 | ||
571 | /* disable MCLK dpm */ | |
572 | if (0 == data->mclk_dpm_key_disabled) { | |
573 | /* Checking if DPM is running. If we discover hang because of this, we should skip this message. */ | |
574 | PP_ASSERT_WITH_CODE( | |
575 | (0 == tonga_is_dpm_running(hwmgr)), | |
576 | "Trying to Disable MCLK DPM when DPM is disabled", | |
577 | return -1 | |
578 | ); | |
579 | ||
580 | PP_ASSERT_WITH_CODE( | |
581 | (0 == smum_send_msg_to_smc(hwmgr->smumgr, | |
582 | PPSMC_MSG_MCLKDPM_Disable)), | |
583 | "Failed to Disable MCLK DPM during DPM stop Function!", | |
584 | return -1); | |
585 | } | |
586 | ||
587 | return 0; | |
588 | } | |
589 | ||
590 | int tonga_stop_dpm(struct pp_hwmgr *hwmgr) | |
591 | { | |
592 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
593 | ||
594 | PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT, GLOBAL_PWRMGT_EN, 0); | |
595 | /* disable sclk deep sleep*/ | |
596 | PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL, DYNAMIC_PM_EN, 0); | |
597 | ||
598 | /* disable PCIE dpm */ | |
599 | if (0 == data->pcie_dpm_key_disabled) { | |
600 | /* Checking if DPM is running. If we discover hang because of this, we should skip this message.*/ | |
601 | PP_ASSERT_WITH_CODE( | |
602 | (0 == tonga_is_dpm_running(hwmgr)), | |
603 | "Trying to Disable PCIE DPM when DPM is disabled", | |
604 | return -1 | |
605 | ); | |
606 | PP_ASSERT_WITH_CODE( | |
607 | (0 == smum_send_msg_to_smc(hwmgr->smumgr, | |
608 | PPSMC_MSG_PCIeDPM_Disable)), | |
609 | "Failed to disable pcie DPM during DPM stop Function!", | |
610 | return -1); | |
611 | } | |
612 | ||
613 | if (0 != tonga_disable_sclk_mclk_dpm(hwmgr)) | |
614 | PP_ASSERT_WITH_CODE(0, "Failed to disable Sclk DPM and Mclk DPM!", return -1); | |
615 | ||
616 | /* Checking if DPM is running. If we discover hang because of this, we should skip this message.*/ | |
617 | PP_ASSERT_WITH_CODE( | |
618 | (0 == tonga_is_dpm_running(hwmgr)), | |
619 | "Trying to Disable Voltage CNTL when DPM is disabled", | |
620 | return -1 | |
621 | ); | |
622 | ||
623 | PP_ASSERT_WITH_CODE( | |
624 | (0 == smum_send_msg_to_smc(hwmgr->smumgr, | |
625 | PPSMC_MSG_Voltage_Cntl_Disable)), | |
626 | "Failed to disable voltage DPM during DPM stop Function!", | |
627 | return -1); | |
628 | ||
629 | return 0; | |
630 | } | |
631 | ||
632 | int tonga_enable_sclk_control(struct pp_hwmgr *hwmgr) | |
633 | { | |
634 | PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL, SCLK_PWRMGT_OFF, 0); | |
635 | ||
636 | return 0; | |
637 | } | |
638 | ||
639 | /** | |
640 | * Send a message to the SMC and return a parameter | |
641 | * | |
642 | * @param hwmgr: the address of the powerplay hardware manager. | |
643 | * @param msg: the message to send. | |
644 | * @param parameter: pointer to the received parameter | |
645 | * @return The response that came from the SMC. | |
646 | */ | |
647 | PPSMC_Result tonga_send_msg_to_smc_return_parameter( | |
648 | struct pp_hwmgr *hwmgr, | |
649 | PPSMC_Msg msg, | |
650 | uint32_t *parameter) | |
651 | { | |
652 | int result; | |
653 | ||
654 | result = smum_send_msg_to_smc(hwmgr->smumgr, msg); | |
655 | ||
656 | if ((0 == result) && parameter) { | |
657 | *parameter = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0); | |
658 | } | |
659 | ||
660 | return result; | |
661 | } | |
662 | ||
663 | /** | |
664 | * force DPM power State | |
665 | * | |
666 | * @param hwmgr: the address of the powerplay hardware manager. | |
667 | * @param n : DPM level | |
668 | * @return The response that came from the SMC. | |
669 | */ | |
670 | int tonga_dpm_force_state(struct pp_hwmgr *hwmgr, uint32_t n) | |
671 | { | |
672 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
673 | uint32_t level_mask = 1 << n; | |
674 | ||
675 | /* Checking if DPM is running. If we discover hang because of this, we should skip this message. */ | |
676 | PP_ASSERT_WITH_CODE(0 == tonga_is_dpm_running(hwmgr), | |
677 | "Trying to force SCLK when DPM is disabled", return -1;); | |
678 | if (0 == data->sclk_dpm_key_disabled) | |
679 | return (0 == smum_send_msg_to_smc_with_parameter( | |
680 | hwmgr->smumgr, | |
681 | (PPSMC_Msg)(PPSMC_MSG_SCLKDPM_SetEnabledMask), | |
682 | level_mask) ? 0 : 1); | |
683 | ||
684 | return 0; | |
685 | } | |
686 | ||
687 | /** | |
688 | * force DPM power State | |
689 | * | |
690 | * @param hwmgr: the address of the powerplay hardware manager. | |
691 | * @param n : DPM level | |
692 | * @return The response that came from the SMC. | |
693 | */ | |
694 | int tonga_dpm_force_state_mclk(struct pp_hwmgr *hwmgr, uint32_t n) | |
695 | { | |
696 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
697 | uint32_t level_mask = 1 << n; | |
698 | ||
699 | /* Checking if DPM is running. If we discover hang because of this, we should skip this message. */ | |
700 | PP_ASSERT_WITH_CODE(0 == tonga_is_dpm_running(hwmgr), | |
701 | "Trying to Force MCLK when DPM is disabled", return -1;); | |
702 | if (0 == data->mclk_dpm_key_disabled) | |
703 | return (0 == smum_send_msg_to_smc_with_parameter( | |
704 | hwmgr->smumgr, | |
705 | (PPSMC_Msg)(PPSMC_MSG_MCLKDPM_SetEnabledMask), | |
706 | level_mask) ? 0 : 1); | |
707 | ||
708 | return 0; | |
709 | } | |
710 | ||
711 | /** | |
712 | * force DPM power State | |
713 | * | |
714 | * @param hwmgr: the address of the powerplay hardware manager. | |
715 | * @param n : DPM level | |
716 | * @return The response that came from the SMC. | |
717 | */ | |
718 | int tonga_dpm_force_state_pcie(struct pp_hwmgr *hwmgr, uint32_t n) | |
719 | { | |
720 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
721 | ||
722 | /* Checking if DPM is running. If we discover hang because of this, we should skip this message.*/ | |
723 | PP_ASSERT_WITH_CODE(0 == tonga_is_dpm_running(hwmgr), | |
724 | "Trying to Force PCIE level when DPM is disabled", return -1;); | |
725 | if (0 == data->pcie_dpm_key_disabled) | |
726 | return (0 == smum_send_msg_to_smc_with_parameter( | |
727 | hwmgr->smumgr, | |
728 | (PPSMC_Msg)(PPSMC_MSG_PCIeDPM_ForceLevel), | |
729 | n) ? 0 : 1); | |
730 | ||
731 | return 0; | |
732 | } | |
733 | ||
734 | /** | |
735 | * Set the initial state by calling SMC to switch to this state directly | |
736 | * | |
737 | * @param hwmgr the address of the powerplay hardware manager. | |
738 | * @return always 0 | |
739 | */ | |
740 | int tonga_set_boot_state(struct pp_hwmgr *hwmgr) | |
741 | { | |
742 | /* | |
743 | * SMC only stores one state that SW will ask to switch too, | |
744 | * so we switch the the just uploaded one | |
745 | */ | |
746 | return (0 == tonga_disable_sclk_mclk_dpm(hwmgr)) ? 0 : 1; | |
747 | } | |
748 | ||
749 | /** | |
750 | * Get the location of various tables inside the FW image. | |
751 | * | |
752 | * @param hwmgr the address of the powerplay hardware manager. | |
753 | * @return always 0 | |
754 | */ | |
755 | int tonga_process_firmware_header(struct pp_hwmgr *hwmgr) | |
756 | { | |
757 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
758 | struct tonga_smumgr *tonga_smu = (struct tonga_smumgr *)(hwmgr->smumgr->backend); | |
759 | ||
760 | uint32_t tmp; | |
761 | int result; | |
762 | bool error = 0; | |
763 | ||
764 | result = tonga_read_smc_sram_dword(hwmgr->smumgr, | |
765 | SMU72_FIRMWARE_HEADER_LOCATION + | |
766 | offsetof(SMU72_Firmware_Header, DpmTable), | |
767 | &tmp, data->sram_end); | |
768 | ||
769 | if (0 == result) { | |
770 | data->dpm_table_start = tmp; | |
771 | } | |
772 | ||
773 | error |= (0 != result); | |
774 | ||
775 | result = tonga_read_smc_sram_dword(hwmgr->smumgr, | |
776 | SMU72_FIRMWARE_HEADER_LOCATION + | |
777 | offsetof(SMU72_Firmware_Header, SoftRegisters), | |
778 | &tmp, data->sram_end); | |
779 | ||
780 | if (0 == result) { | |
781 | data->soft_regs_start = tmp; | |
782 | tonga_smu->ulSoftRegsStart = tmp; | |
783 | } | |
784 | ||
785 | error |= (0 != result); | |
786 | ||
787 | ||
788 | result = tonga_read_smc_sram_dword(hwmgr->smumgr, | |
789 | SMU72_FIRMWARE_HEADER_LOCATION + | |
790 | offsetof(SMU72_Firmware_Header, mcRegisterTable), | |
791 | &tmp, data->sram_end); | |
792 | ||
793 | if (0 == result) { | |
794 | data->mc_reg_table_start = tmp; | |
795 | } | |
796 | ||
797 | result = tonga_read_smc_sram_dword(hwmgr->smumgr, | |
798 | SMU72_FIRMWARE_HEADER_LOCATION + | |
799 | offsetof(SMU72_Firmware_Header, FanTable), | |
800 | &tmp, data->sram_end); | |
801 | ||
802 | if (0 == result) { | |
803 | data->fan_table_start = tmp; | |
804 | } | |
805 | ||
806 | error |= (0 != result); | |
807 | ||
808 | result = tonga_read_smc_sram_dword(hwmgr->smumgr, | |
809 | SMU72_FIRMWARE_HEADER_LOCATION + | |
810 | offsetof(SMU72_Firmware_Header, mcArbDramTimingTable), | |
811 | &tmp, data->sram_end); | |
812 | ||
813 | if (0 == result) { | |
814 | data->arb_table_start = tmp; | |
815 | } | |
816 | ||
817 | error |= (0 != result); | |
818 | ||
819 | ||
820 | result = tonga_read_smc_sram_dword(hwmgr->smumgr, | |
821 | SMU72_FIRMWARE_HEADER_LOCATION + | |
822 | offsetof(SMU72_Firmware_Header, Version), | |
823 | &tmp, data->sram_end); | |
824 | ||
825 | if (0 == result) { | |
826 | hwmgr->microcode_version_info.SMC = tmp; | |
827 | } | |
828 | ||
829 | error |= (0 != result); | |
830 | ||
831 | return error ? 1 : 0; | |
832 | } | |
833 | ||
834 | /** | |
835 | * Read clock related registers. | |
836 | * | |
837 | * @param hwmgr the address of the powerplay hardware manager. | |
838 | * @return always 0 | |
839 | */ | |
840 | int tonga_read_clock_registers(struct pp_hwmgr *hwmgr) | |
841 | { | |
842 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
843 | ||
844 | data->clock_registers.vCG_SPLL_FUNC_CNTL = | |
845 | cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL); | |
846 | data->clock_registers.vCG_SPLL_FUNC_CNTL_2 = | |
847 | cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_2); | |
848 | data->clock_registers.vCG_SPLL_FUNC_CNTL_3 = | |
849 | cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_3); | |
850 | data->clock_registers.vCG_SPLL_FUNC_CNTL_4 = | |
851 | cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_4); | |
852 | data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM = | |
853 | cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_SPREAD_SPECTRUM); | |
854 | data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2 = | |
855 | cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_SPREAD_SPECTRUM_2); | |
856 | data->clock_registers.vDLL_CNTL = | |
857 | cgs_read_register(hwmgr->device, mmDLL_CNTL); | |
858 | data->clock_registers.vMCLK_PWRMGT_CNTL = | |
859 | cgs_read_register(hwmgr->device, mmMCLK_PWRMGT_CNTL); | |
860 | data->clock_registers.vMPLL_AD_FUNC_CNTL = | |
861 | cgs_read_register(hwmgr->device, mmMPLL_AD_FUNC_CNTL); | |
862 | data->clock_registers.vMPLL_DQ_FUNC_CNTL = | |
863 | cgs_read_register(hwmgr->device, mmMPLL_DQ_FUNC_CNTL); | |
864 | data->clock_registers.vMPLL_FUNC_CNTL = | |
865 | cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL); | |
866 | data->clock_registers.vMPLL_FUNC_CNTL_1 = | |
867 | cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL_1); | |
868 | data->clock_registers.vMPLL_FUNC_CNTL_2 = | |
869 | cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL_2); | |
870 | data->clock_registers.vMPLL_SS1 = | |
871 | cgs_read_register(hwmgr->device, mmMPLL_SS1); | |
872 | data->clock_registers.vMPLL_SS2 = | |
873 | cgs_read_register(hwmgr->device, mmMPLL_SS2); | |
874 | ||
875 | return 0; | |
876 | } | |
877 | ||
878 | /** | |
879 | * Find out if memory is GDDR5. | |
880 | * | |
881 | * @param hwmgr the address of the powerplay hardware manager. | |
882 | * @return always 0 | |
883 | */ | |
884 | int tonga_get_memory_type(struct pp_hwmgr *hwmgr) | |
885 | { | |
886 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
887 | uint32_t temp; | |
888 | ||
889 | temp = cgs_read_register(hwmgr->device, mmMC_SEQ_MISC0); | |
890 | ||
891 | data->is_memory_GDDR5 = (MC_SEQ_MISC0_GDDR5_VALUE == | |
892 | ((temp & MC_SEQ_MISC0_GDDR5_MASK) >> | |
893 | MC_SEQ_MISC0_GDDR5_SHIFT)); | |
894 | ||
895 | return 0; | |
896 | } | |
897 | ||
898 | /** | |
899 | * Enables Dynamic Power Management by SMC | |
900 | * | |
901 | * @param hwmgr the address of the powerplay hardware manager. | |
902 | * @return always 0 | |
903 | */ | |
904 | int tonga_enable_acpi_power_management(struct pp_hwmgr *hwmgr) | |
905 | { | |
906 | PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT, STATIC_PM_EN, 1); | |
907 | ||
908 | return 0; | |
909 | } | |
910 | ||
911 | /** | |
912 | * Initialize PowerGating States for different engines | |
913 | * | |
914 | * @param hwmgr the address of the powerplay hardware manager. | |
915 | * @return always 0 | |
916 | */ | |
917 | int tonga_init_power_gate_state(struct pp_hwmgr *hwmgr) | |
918 | { | |
919 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
920 | ||
921 | data->uvd_power_gated = 0; | |
922 | data->vce_power_gated = 0; | |
923 | data->samu_power_gated = 0; | |
924 | data->acp_power_gated = 0; | |
925 | data->pg_acp_init = 1; | |
926 | ||
927 | return 0; | |
928 | } | |
929 | ||
930 | /** | |
931 | * Checks if DPM is enabled | |
932 | * | |
933 | * @param hwmgr the address of the powerplay hardware manager. | |
934 | * @return always 0 | |
935 | */ | |
936 | int tonga_check_for_dpm_running(struct pp_hwmgr *hwmgr) | |
937 | { | |
938 | /* | |
939 | * We return the status of Voltage Control instead of checking SCLK/MCLK DPM | |
940 | * because we may have test scenarios that need us intentionly disable SCLK/MCLK DPM, | |
941 | * whereas voltage control is a fundemental change that will not be disabled | |
942 | */ | |
943 | return (0 == tonga_is_dpm_running(hwmgr) ? 0 : 1); | |
944 | } | |
945 | ||
946 | /** | |
947 | * Checks if DPM is stopped | |
948 | * | |
949 | * @param hwmgr the address of the powerplay hardware manager. | |
950 | * @return always 0 | |
951 | */ | |
952 | int tonga_check_for_dpm_stopped(struct pp_hwmgr *hwmgr) | |
953 | { | |
954 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
955 | ||
956 | if (0 != tonga_is_dpm_running(hwmgr)) { | |
957 | /* If HW Virtualization is enabled, dpm_table_start will not have a valid value */ | |
958 | if (!data->dpm_table_start) { | |
959 | return 1; | |
960 | } | |
961 | } | |
962 | ||
963 | return 0; | |
964 | } | |
965 | ||
966 | /** | |
967 | * Remove repeated voltage values and create table with unique values. | |
968 | * | |
969 | * @param hwmgr the address of the powerplay hardware manager. | |
970 | * @param voltage_table the pointer to changing voltage table | |
971 | * @return 1 in success | |
972 | */ | |
973 | ||
974 | static int tonga_trim_voltage_table(struct pp_hwmgr *hwmgr, | |
975 | pp_atomctrl_voltage_table *voltage_table) | |
976 | { | |
977 | uint32_t table_size, i, j; | |
978 | uint16_t vvalue; | |
979 | bool bVoltageFound = 0; | |
980 | pp_atomctrl_voltage_table *table; | |
981 | ||
982 | PP_ASSERT_WITH_CODE((NULL != voltage_table), "Voltage Table empty.", return -1;); | |
983 | table_size = sizeof(pp_atomctrl_voltage_table); | |
984 | table = kzalloc(table_size, GFP_KERNEL); | |
985 | ||
986 | if (NULL == table) | |
987 | return -ENOMEM; | |
988 | ||
989 | memset(table, 0x00, table_size); | |
990 | table->mask_low = voltage_table->mask_low; | |
991 | table->phase_delay = voltage_table->phase_delay; | |
992 | ||
993 | for (i = 0; i < voltage_table->count; i++) { | |
994 | vvalue = voltage_table->entries[i].value; | |
995 | bVoltageFound = 0; | |
996 | ||
997 | for (j = 0; j < table->count; j++) { | |
998 | if (vvalue == table->entries[j].value) { | |
999 | bVoltageFound = 1; | |
1000 | break; | |
1001 | } | |
1002 | } | |
1003 | ||
1004 | if (!bVoltageFound) { | |
1005 | table->entries[table->count].value = vvalue; | |
1006 | table->entries[table->count].smio_low = | |
1007 | voltage_table->entries[i].smio_low; | |
1008 | table->count++; | |
1009 | } | |
1010 | } | |
1011 | ||
1012 | memcpy(table, voltage_table, sizeof(pp_atomctrl_voltage_table)); | |
1013 | ||
1014 | kfree(table); | |
1015 | ||
1016 | return 0; | |
1017 | } | |
1018 | ||
1019 | static int tonga_get_svi2_vdd_ci_voltage_table( | |
1020 | struct pp_hwmgr *hwmgr, | |
1021 | phm_ppt_v1_clock_voltage_dependency_table *voltage_dependency_table) | |
1022 | { | |
1023 | uint32_t i; | |
1024 | int result; | |
1025 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
1026 | pp_atomctrl_voltage_table *vddci_voltage_table = &(data->vddci_voltage_table); | |
1027 | ||
1028 | PP_ASSERT_WITH_CODE((0 != voltage_dependency_table->count), | |
1029 | "Voltage Dependency Table empty.", return -1;); | |
1030 | ||
1031 | vddci_voltage_table->mask_low = 0; | |
1032 | vddci_voltage_table->phase_delay = 0; | |
1033 | vddci_voltage_table->count = voltage_dependency_table->count; | |
1034 | ||
1035 | for (i = 0; i < voltage_dependency_table->count; i++) { | |
1036 | vddci_voltage_table->entries[i].value = | |
1037 | voltage_dependency_table->entries[i].vddci; | |
1038 | vddci_voltage_table->entries[i].smio_low = 0; | |
1039 | } | |
1040 | ||
1041 | result = tonga_trim_voltage_table(hwmgr, vddci_voltage_table); | |
1042 | PP_ASSERT_WITH_CODE((0 == result), | |
1043 | "Failed to trim VDDCI table.", return result;); | |
1044 | ||
1045 | return 0; | |
1046 | } | |
1047 | ||
1048 | ||
1049 | ||
1050 | static int tonga_get_svi2_vdd_voltage_table( | |
1051 | struct pp_hwmgr *hwmgr, | |
1052 | phm_ppt_v1_voltage_lookup_table *look_up_table, | |
1053 | pp_atomctrl_voltage_table *voltage_table) | |
1054 | { | |
1055 | uint8_t i = 0; | |
1056 | ||
1057 | PP_ASSERT_WITH_CODE((0 != look_up_table->count), | |
1058 | "Voltage Lookup Table empty.", return -1;); | |
1059 | ||
1060 | voltage_table->mask_low = 0; | |
1061 | voltage_table->phase_delay = 0; | |
1062 | ||
1063 | voltage_table->count = look_up_table->count; | |
1064 | ||
1065 | for (i = 0; i < voltage_table->count; i++) { | |
1066 | voltage_table->entries[i].value = look_up_table->entries[i].us_vdd; | |
1067 | voltage_table->entries[i].smio_low = 0; | |
1068 | } | |
1069 | ||
1070 | return 0; | |
1071 | } | |
1072 | ||
1073 | /* | |
1074 | * -------------------------------------------------------- Voltage Tables -------------------------------------------------------------------------- | |
1075 | * If the voltage table would be bigger than what will fit into the state table on the SMC keep only the higher entries. | |
1076 | */ | |
1077 | ||
1078 | static void tonga_trim_voltage_table_to_fit_state_table( | |
1079 | struct pp_hwmgr *hwmgr, | |
1080 | uint32_t max_voltage_steps, | |
1081 | pp_atomctrl_voltage_table *voltage_table) | |
1082 | { | |
1083 | unsigned int i, diff; | |
1084 | ||
1085 | if (voltage_table->count <= max_voltage_steps) { | |
1086 | return; | |
1087 | } | |
1088 | ||
1089 | diff = voltage_table->count - max_voltage_steps; | |
1090 | ||
1091 | for (i = 0; i < max_voltage_steps; i++) { | |
1092 | voltage_table->entries[i] = voltage_table->entries[i + diff]; | |
1093 | } | |
1094 | ||
1095 | voltage_table->count = max_voltage_steps; | |
1096 | ||
1097 | return; | |
1098 | } | |
1099 | ||
1100 | /** | |
1101 | * Create Voltage Tables. | |
1102 | * | |
1103 | * @param hwmgr the address of the powerplay hardware manager. | |
1104 | * @return always 0 | |
1105 | */ | |
1106 | int tonga_construct_voltage_tables(struct pp_hwmgr *hwmgr) | |
1107 | { | |
1108 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
1109 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
1110 | int result; | |
1111 | ||
1112 | /* MVDD has only GPIO voltage control */ | |
1113 | if (TONGA_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) { | |
1114 | result = atomctrl_get_voltage_table_v3(hwmgr, | |
1115 | VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT, &(data->mvdd_voltage_table)); | |
1116 | PP_ASSERT_WITH_CODE((0 == result), | |
1117 | "Failed to retrieve MVDD table.", return result;); | |
1118 | } | |
1119 | ||
1120 | if (TONGA_VOLTAGE_CONTROL_BY_GPIO == data->vdd_ci_control) { | |
1121 | /* GPIO voltage */ | |
1122 | result = atomctrl_get_voltage_table_v3(hwmgr, | |
1123 | VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT, &(data->vddci_voltage_table)); | |
1124 | PP_ASSERT_WITH_CODE((0 == result), | |
1125 | "Failed to retrieve VDDCI table.", return result;); | |
1126 | } else if (TONGA_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_ci_control) { | |
1127 | /* SVI2 voltage */ | |
1128 | result = tonga_get_svi2_vdd_ci_voltage_table(hwmgr, | |
1129 | pptable_info->vdd_dep_on_mclk); | |
1130 | PP_ASSERT_WITH_CODE((0 == result), | |
1131 | "Failed to retrieve SVI2 VDDCI table from dependancy table.", return result;); | |
1132 | } | |
1133 | ||
1134 | if (TONGA_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_gfx_control) { | |
1135 | /* VDDGFX has only SVI2 voltage control */ | |
1136 | result = tonga_get_svi2_vdd_voltage_table(hwmgr, | |
1137 | pptable_info->vddgfx_lookup_table, &(data->vddgfx_voltage_table)); | |
1138 | PP_ASSERT_WITH_CODE((0 == result), | |
1139 | "Failed to retrieve SVI2 VDDGFX table from lookup table.", return result;); | |
1140 | } | |
1141 | ||
1142 | if (TONGA_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) { | |
1143 | /* VDDC has only SVI2 voltage control */ | |
1144 | result = tonga_get_svi2_vdd_voltage_table(hwmgr, | |
1145 | pptable_info->vddc_lookup_table, &(data->vddc_voltage_table)); | |
1146 | PP_ASSERT_WITH_CODE((0 == result), | |
1147 | "Failed to retrieve SVI2 VDDC table from lookup table.", return result;); | |
1148 | } | |
1149 | ||
1150 | PP_ASSERT_WITH_CODE( | |
1151 | (data->vddc_voltage_table.count <= (SMU72_MAX_LEVELS_VDDC)), | |
1152 | "Too many voltage values for VDDC. Trimming to fit state table.", | |
1153 | tonga_trim_voltage_table_to_fit_state_table(hwmgr, | |
1154 | SMU72_MAX_LEVELS_VDDC, &(data->vddc_voltage_table)); | |
1155 | ); | |
1156 | ||
1157 | PP_ASSERT_WITH_CODE( | |
1158 | (data->vddgfx_voltage_table.count <= (SMU72_MAX_LEVELS_VDDGFX)), | |
1159 | "Too many voltage values for VDDGFX. Trimming to fit state table.", | |
1160 | tonga_trim_voltage_table_to_fit_state_table(hwmgr, | |
1161 | SMU72_MAX_LEVELS_VDDGFX, &(data->vddgfx_voltage_table)); | |
1162 | ); | |
1163 | ||
1164 | PP_ASSERT_WITH_CODE( | |
1165 | (data->vddci_voltage_table.count <= (SMU72_MAX_LEVELS_VDDCI)), | |
1166 | "Too many voltage values for VDDCI. Trimming to fit state table.", | |
1167 | tonga_trim_voltage_table_to_fit_state_table(hwmgr, | |
1168 | SMU72_MAX_LEVELS_VDDCI, &(data->vddci_voltage_table)); | |
1169 | ); | |
1170 | ||
1171 | PP_ASSERT_WITH_CODE( | |
1172 | (data->mvdd_voltage_table.count <= (SMU72_MAX_LEVELS_MVDD)), | |
1173 | "Too many voltage values for MVDD. Trimming to fit state table.", | |
1174 | tonga_trim_voltage_table_to_fit_state_table(hwmgr, | |
1175 | SMU72_MAX_LEVELS_MVDD, &(data->mvdd_voltage_table)); | |
1176 | ); | |
1177 | ||
1178 | return 0; | |
1179 | } | |
1180 | ||
1181 | /** | |
1182 | * Vddc table preparation for SMC. | |
1183 | * | |
1184 | * @param hwmgr the address of the hardware manager | |
1185 | * @param table the SMC DPM table structure to be populated | |
1186 | * @return always 0 | |
1187 | */ | |
1188 | static int tonga_populate_smc_vddc_table(struct pp_hwmgr *hwmgr, | |
1189 | SMU72_Discrete_DpmTable *table) | |
1190 | { | |
1191 | unsigned int count; | |
1192 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
1193 | ||
1194 | if (TONGA_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) { | |
1195 | table->VddcLevelCount = data->vddc_voltage_table.count; | |
1196 | for (count = 0; count < table->VddcLevelCount; count++) { | |
1197 | table->VddcTable[count] = | |
1198 | PP_HOST_TO_SMC_US(data->vddc_voltage_table.entries[count].value * VOLTAGE_SCALE); | |
1199 | } | |
1200 | CONVERT_FROM_HOST_TO_SMC_UL(table->VddcLevelCount); | |
1201 | } | |
1202 | return 0; | |
1203 | } | |
1204 | ||
1205 | /** | |
1206 | * VddGfx table preparation for SMC. | |
1207 | * | |
1208 | * @param hwmgr the address of the hardware manager | |
1209 | * @param table the SMC DPM table structure to be populated | |
1210 | * @return always 0 | |
1211 | */ | |
1212 | static int tonga_populate_smc_vdd_gfx_table(struct pp_hwmgr *hwmgr, | |
1213 | SMU72_Discrete_DpmTable *table) | |
1214 | { | |
1215 | unsigned int count; | |
1216 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
1217 | ||
1218 | if (TONGA_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_gfx_control) { | |
1219 | table->VddGfxLevelCount = data->vddgfx_voltage_table.count; | |
1220 | for (count = 0; count < data->vddgfx_voltage_table.count; count++) { | |
1221 | table->VddGfxTable[count] = | |
1222 | PP_HOST_TO_SMC_US(data->vddgfx_voltage_table.entries[count].value * VOLTAGE_SCALE); | |
1223 | } | |
1224 | CONVERT_FROM_HOST_TO_SMC_UL(table->VddGfxLevelCount); | |
1225 | } | |
1226 | return 0; | |
1227 | } | |
1228 | ||
1229 | /** | |
1230 | * Vddci table preparation for SMC. | |
1231 | * | |
1232 | * @param *hwmgr The address of the hardware manager. | |
1233 | * @param *table The SMC DPM table structure to be populated. | |
1234 | * @return 0 | |
1235 | */ | |
1236 | static int tonga_populate_smc_vdd_ci_table(struct pp_hwmgr *hwmgr, | |
1237 | SMU72_Discrete_DpmTable *table) | |
1238 | { | |
1239 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
1240 | uint32_t count; | |
1241 | ||
1242 | table->VddciLevelCount = data->vddci_voltage_table.count; | |
1243 | for (count = 0; count < table->VddciLevelCount; count++) { | |
1244 | if (TONGA_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_ci_control) { | |
1245 | table->VddciTable[count] = | |
1246 | PP_HOST_TO_SMC_US(data->vddci_voltage_table.entries[count].value * VOLTAGE_SCALE); | |
1247 | } else if (TONGA_VOLTAGE_CONTROL_BY_GPIO == data->vdd_ci_control) { | |
1248 | table->SmioTable1.Pattern[count].Voltage = | |
1249 | PP_HOST_TO_SMC_US(data->vddci_voltage_table.entries[count].value * VOLTAGE_SCALE); | |
1250 | /* Index into DpmTable.Smio. Drive bits from Smio entry to get this voltage level. */ | |
1251 | table->SmioTable1.Pattern[count].Smio = | |
1252 | (uint8_t) count; | |
1253 | table->Smio[count] |= | |
1254 | data->vddci_voltage_table.entries[count].smio_low; | |
1255 | table->VddciTable[count] = | |
1256 | PP_HOST_TO_SMC_US(data->vddci_voltage_table.entries[count].value * VOLTAGE_SCALE); | |
1257 | } | |
1258 | } | |
1259 | ||
1260 | table->SmioMask1 = data->vddci_voltage_table.mask_low; | |
1261 | CONVERT_FROM_HOST_TO_SMC_UL(table->VddciLevelCount); | |
1262 | ||
1263 | return 0; | |
1264 | } | |
1265 | ||
1266 | /** | |
1267 | * Mvdd table preparation for SMC. | |
1268 | * | |
1269 | * @param *hwmgr The address of the hardware manager. | |
1270 | * @param *table The SMC DPM table structure to be populated. | |
1271 | * @return 0 | |
1272 | */ | |
1273 | static int tonga_populate_smc_mvdd_table(struct pp_hwmgr *hwmgr, | |
1274 | SMU72_Discrete_DpmTable *table) | |
1275 | { | |
1276 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
1277 | uint32_t count; | |
1278 | ||
1279 | if (TONGA_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) { | |
1280 | table->MvddLevelCount = data->mvdd_voltage_table.count; | |
1281 | for (count = 0; count < table->MvddLevelCount; count++) { | |
1282 | table->SmioTable2.Pattern[count].Voltage = | |
1283 | PP_HOST_TO_SMC_US(data->mvdd_voltage_table.entries[count].value * VOLTAGE_SCALE); | |
1284 | /* Index into DpmTable.Smio. Drive bits from Smio entry to get this voltage level.*/ | |
1285 | table->SmioTable2.Pattern[count].Smio = | |
1286 | (uint8_t) count; | |
1287 | table->Smio[count] |= | |
1288 | data->mvdd_voltage_table.entries[count].smio_low; | |
1289 | } | |
1290 | table->SmioMask2 = data->vddci_voltage_table.mask_low; | |
1291 | ||
1292 | CONVERT_FROM_HOST_TO_SMC_UL(table->MvddLevelCount); | |
1293 | } | |
1294 | ||
1295 | return 0; | |
1296 | } | |
1297 | ||
1298 | /** | |
1299 | * Convert a voltage value in mv unit to VID number required by SMU firmware | |
1300 | */ | |
1301 | static uint8_t convert_to_vid(uint16_t vddc) | |
1302 | { | |
1303 | return (uint8_t) ((6200 - (vddc * VOLTAGE_SCALE)) / 25); | |
1304 | } | |
1305 | ||
1306 | ||
1307 | /** | |
1308 | * Preparation of vddc and vddgfx CAC tables for SMC. | |
1309 | * | |
1310 | * @param hwmgr the address of the hardware manager | |
1311 | * @param table the SMC DPM table structure to be populated | |
1312 | * @return always 0 | |
1313 | */ | |
1314 | static int tonga_populate_cac_tables(struct pp_hwmgr *hwmgr, | |
1315 | SMU72_Discrete_DpmTable *table) | |
1316 | { | |
1317 | uint32_t count; | |
1318 | uint8_t index; | |
1319 | int result = 0; | |
1320 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
1321 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
1322 | struct phm_ppt_v1_voltage_lookup_table *vddgfx_lookup_table = pptable_info->vddgfx_lookup_table; | |
1323 | struct phm_ppt_v1_voltage_lookup_table *vddc_lookup_table = pptable_info->vddc_lookup_table; | |
1324 | ||
1325 | /* pTables is already swapped, so in order to use the value from it, we need to swap it back. */ | |
1326 | uint32_t vddcLevelCount = PP_SMC_TO_HOST_UL(table->VddcLevelCount); | |
1327 | uint32_t vddgfxLevelCount = PP_SMC_TO_HOST_UL(table->VddGfxLevelCount); | |
1328 | ||
1329 | for (count = 0; count < vddcLevelCount; count++) { | |
1330 | /* We are populating vddc CAC data to BapmVddc table in split and merged mode */ | |
1331 | index = tonga_get_voltage_index(vddc_lookup_table, | |
1332 | data->vddc_voltage_table.entries[count].value); | |
1333 | table->BapmVddcVidLoSidd[count] = | |
1334 | convert_to_vid(vddc_lookup_table->entries[index].us_cac_low); | |
1335 | table->BapmVddcVidHiSidd[count] = | |
1336 | convert_to_vid(vddc_lookup_table->entries[index].us_cac_mid); | |
1337 | table->BapmVddcVidHiSidd2[count] = | |
1338 | convert_to_vid(vddc_lookup_table->entries[index].us_cac_high); | |
1339 | } | |
1340 | ||
1341 | if ((data->vdd_gfx_control == TONGA_VOLTAGE_CONTROL_BY_SVID2)) { | |
1342 | /* We are populating vddgfx CAC data to BapmVddgfx table in split mode */ | |
1343 | for (count = 0; count < vddgfxLevelCount; count++) { | |
1344 | index = tonga_get_voltage_index(vddgfx_lookup_table, | |
1345 | data->vddgfx_voltage_table.entries[count].value); | |
1346 | table->BapmVddGfxVidLoSidd[count] = | |
1347 | convert_to_vid(vddgfx_lookup_table->entries[index].us_cac_low); | |
1348 | table->BapmVddGfxVidHiSidd[count] = | |
1349 | convert_to_vid(vddgfx_lookup_table->entries[index].us_cac_mid); | |
1350 | table->BapmVddGfxVidHiSidd2[count] = | |
1351 | convert_to_vid(vddgfx_lookup_table->entries[index].us_cac_high); | |
1352 | } | |
1353 | } else { | |
1354 | for (count = 0; count < vddcLevelCount; count++) { | |
1355 | index = tonga_get_voltage_index(vddc_lookup_table, | |
1356 | data->vddc_voltage_table.entries[count].value); | |
1357 | table->BapmVddGfxVidLoSidd[count] = | |
1358 | convert_to_vid(vddc_lookup_table->entries[index].us_cac_low); | |
1359 | table->BapmVddGfxVidHiSidd[count] = | |
1360 | convert_to_vid(vddc_lookup_table->entries[index].us_cac_mid); | |
1361 | table->BapmVddGfxVidHiSidd2[count] = | |
1362 | convert_to_vid(vddc_lookup_table->entries[index].us_cac_high); | |
1363 | } | |
1364 | } | |
1365 | ||
1366 | return result; | |
1367 | } | |
1368 | ||
1369 | ||
1370 | /** | |
1371 | * Preparation of voltage tables for SMC. | |
1372 | * | |
1373 | * @param hwmgr the address of the hardware manager | |
1374 | * @param table the SMC DPM table structure to be populated | |
1375 | * @return always 0 | |
1376 | */ | |
1377 | ||
1378 | int tonga_populate_smc_voltage_tables(struct pp_hwmgr *hwmgr, | |
1379 | SMU72_Discrete_DpmTable *table) | |
1380 | { | |
1381 | int result; | |
1382 | ||
1383 | result = tonga_populate_smc_vddc_table(hwmgr, table); | |
1384 | PP_ASSERT_WITH_CODE(0 == result, | |
1385 | "can not populate VDDC voltage table to SMC", return -1); | |
1386 | ||
1387 | result = tonga_populate_smc_vdd_ci_table(hwmgr, table); | |
1388 | PP_ASSERT_WITH_CODE(0 == result, | |
1389 | "can not populate VDDCI voltage table to SMC", return -1); | |
1390 | ||
1391 | result = tonga_populate_smc_vdd_gfx_table(hwmgr, table); | |
1392 | PP_ASSERT_WITH_CODE(0 == result, | |
1393 | "can not populate VDDGFX voltage table to SMC", return -1); | |
1394 | ||
1395 | result = tonga_populate_smc_mvdd_table(hwmgr, table); | |
1396 | PP_ASSERT_WITH_CODE(0 == result, | |
1397 | "can not populate MVDD voltage table to SMC", return -1); | |
1398 | ||
1399 | result = tonga_populate_cac_tables(hwmgr, table); | |
1400 | PP_ASSERT_WITH_CODE(0 == result, | |
1401 | "can not populate CAC voltage tables to SMC", return -1); | |
1402 | ||
1403 | return 0; | |
1404 | } | |
1405 | ||
1406 | /** | |
1407 | * Populates the SMC VRConfig field in DPM table. | |
1408 | * | |
1409 | * @param hwmgr the address of the hardware manager | |
1410 | * @param table the SMC DPM table structure to be populated | |
1411 | * @return always 0 | |
1412 | */ | |
1413 | static int tonga_populate_vr_config(struct pp_hwmgr *hwmgr, | |
1414 | SMU72_Discrete_DpmTable *table) | |
1415 | { | |
1416 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
1417 | uint16_t config; | |
1418 | ||
1419 | if (TONGA_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_gfx_control) { | |
1420 | /* Splitted mode */ | |
1421 | config = VR_SVI2_PLANE_1; | |
1422 | table->VRConfig |= (config<<VRCONF_VDDGFX_SHIFT); | |
1423 | ||
1424 | if (TONGA_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) { | |
1425 | config = VR_SVI2_PLANE_2; | |
1426 | table->VRConfig |= config; | |
1427 | } else { | |
1428 | printk(KERN_ERR "[ powerplay ] VDDC and VDDGFX should be both on SVI2 control in splitted mode! \n"); | |
1429 | } | |
1430 | } else { | |
1431 | /* Merged mode */ | |
1432 | config = VR_MERGED_WITH_VDDC; | |
1433 | table->VRConfig |= (config<<VRCONF_VDDGFX_SHIFT); | |
1434 | ||
1435 | /* Set Vddc Voltage Controller */ | |
1436 | if (TONGA_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) { | |
1437 | config = VR_SVI2_PLANE_1; | |
1438 | table->VRConfig |= config; | |
1439 | } else { | |
1440 | printk(KERN_ERR "[ powerplay ] VDDC should be on SVI2 control in merged mode! \n"); | |
1441 | } | |
1442 | } | |
1443 | ||
1444 | /* Set Vddci Voltage Controller */ | |
1445 | if (TONGA_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_ci_control) { | |
1446 | config = VR_SVI2_PLANE_2; /* only in merged mode */ | |
1447 | table->VRConfig |= (config<<VRCONF_VDDCI_SHIFT); | |
1448 | } else if (TONGA_VOLTAGE_CONTROL_BY_GPIO == data->vdd_ci_control) { | |
1449 | config = VR_SMIO_PATTERN_1; | |
1450 | table->VRConfig |= (config<<VRCONF_VDDCI_SHIFT); | |
1451 | } | |
1452 | ||
1453 | /* Set Mvdd Voltage Controller */ | |
1454 | if (TONGA_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) { | |
1455 | config = VR_SMIO_PATTERN_2; | |
1456 | table->VRConfig |= (config<<VRCONF_MVDD_SHIFT); | |
1457 | } | |
1458 | ||
1459 | return 0; | |
1460 | } | |
1461 | ||
1462 | static int tonga_get_dependecy_volt_by_clk(struct pp_hwmgr *hwmgr, | |
1463 | phm_ppt_v1_clock_voltage_dependency_table *allowed_clock_voltage_table, | |
1464 | uint32_t clock, SMU_VoltageLevel *voltage, uint32_t *mvdd) | |
1465 | { | |
1466 | uint32_t i = 0; | |
1467 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
1468 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
1469 | ||
1470 | /* clock - voltage dependency table is empty table */ | |
1471 | if (allowed_clock_voltage_table->count == 0) | |
1472 | return -1; | |
1473 | ||
1474 | for (i = 0; i < allowed_clock_voltage_table->count; i++) { | |
1475 | /* find first sclk bigger than request */ | |
1476 | if (allowed_clock_voltage_table->entries[i].clk >= clock) { | |
1477 | voltage->VddGfx = tonga_get_voltage_index(pptable_info->vddgfx_lookup_table, | |
1478 | allowed_clock_voltage_table->entries[i].vddgfx); | |
1479 | ||
1480 | voltage->Vddc = tonga_get_voltage_index(pptable_info->vddc_lookup_table, | |
1481 | allowed_clock_voltage_table->entries[i].vddc); | |
1482 | ||
1483 | if (allowed_clock_voltage_table->entries[i].vddci) { | |
1484 | voltage->Vddci = tonga_get_voltage_id(&data->vddci_voltage_table, | |
1485 | allowed_clock_voltage_table->entries[i].vddci); | |
1486 | } else { | |
1487 | voltage->Vddci = tonga_get_voltage_id(&data->vddci_voltage_table, | |
1488 | allowed_clock_voltage_table->entries[i].vddc - data->vddc_vddci_delta); | |
1489 | } | |
1490 | ||
1491 | if (allowed_clock_voltage_table->entries[i].mvdd) { | |
1492 | *mvdd = (uint32_t) allowed_clock_voltage_table->entries[i].mvdd; | |
1493 | } | |
1494 | ||
1495 | voltage->Phases = 1; | |
1496 | return 0; | |
1497 | } | |
1498 | } | |
1499 | ||
1500 | /* sclk is bigger than max sclk in the dependence table */ | |
1501 | voltage->VddGfx = tonga_get_voltage_index(pptable_info->vddgfx_lookup_table, | |
1502 | allowed_clock_voltage_table->entries[i-1].vddgfx); | |
1503 | voltage->Vddc = tonga_get_voltage_index(pptable_info->vddc_lookup_table, | |
1504 | allowed_clock_voltage_table->entries[i-1].vddc); | |
1505 | ||
1506 | if (allowed_clock_voltage_table->entries[i-1].vddci) { | |
1507 | voltage->Vddci = tonga_get_voltage_id(&data->vddci_voltage_table, | |
1508 | allowed_clock_voltage_table->entries[i-1].vddci); | |
1509 | } | |
1510 | if (allowed_clock_voltage_table->entries[i-1].mvdd) { | |
1511 | *mvdd = (uint32_t) allowed_clock_voltage_table->entries[i-1].mvdd; | |
1512 | } | |
1513 | ||
1514 | return 0; | |
1515 | } | |
1516 | ||
1517 | /** | |
1518 | * Call SMC to reset S0/S1 to S1 and Reset SMIO to initial value | |
1519 | * | |
1520 | * @param hwmgr the address of the powerplay hardware manager. | |
1521 | * @return always 0 | |
1522 | */ | |
1523 | int tonga_reset_to_default(struct pp_hwmgr *hwmgr) | |
1524 | { | |
1525 | return (smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_ResetToDefaults) == 0) ? 0 : 1; | |
1526 | } | |
1527 | ||
1528 | int tonga_populate_memory_timing_parameters( | |
1529 | struct pp_hwmgr *hwmgr, | |
1530 | uint32_t engine_clock, | |
1531 | uint32_t memory_clock, | |
1532 | struct SMU72_Discrete_MCArbDramTimingTableEntry *arb_regs | |
1533 | ) | |
1534 | { | |
1535 | uint32_t dramTiming; | |
1536 | uint32_t dramTiming2; | |
1537 | uint32_t burstTime; | |
1538 | int result; | |
1539 | ||
1540 | result = atomctrl_set_engine_dram_timings_rv770(hwmgr, | |
1541 | engine_clock, memory_clock); | |
1542 | ||
1543 | PP_ASSERT_WITH_CODE(result == 0, | |
1544 | "Error calling VBIOS to set DRAM_TIMING.", return result); | |
1545 | ||
1546 | dramTiming = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING); | |
1547 | dramTiming2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2); | |
1548 | burstTime = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0); | |
1549 | ||
1550 | arb_regs->McArbDramTiming = PP_HOST_TO_SMC_UL(dramTiming); | |
1551 | arb_regs->McArbDramTiming2 = PP_HOST_TO_SMC_UL(dramTiming2); | |
1552 | arb_regs->McArbBurstTime = (uint8_t)burstTime; | |
1553 | ||
1554 | return 0; | |
1555 | } | |
1556 | ||
1557 | /** | |
1558 | * Setup parameters for the MC ARB. | |
1559 | * | |
1560 | * @param hwmgr the address of the powerplay hardware manager. | |
1561 | * @return always 0 | |
1562 | * This function is to be called from the SetPowerState table. | |
1563 | */ | |
1564 | int tonga_program_memory_timing_parameters(struct pp_hwmgr *hwmgr) | |
1565 | { | |
1566 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
1567 | int result = 0; | |
1568 | SMU72_Discrete_MCArbDramTimingTable arb_regs; | |
1569 | uint32_t i, j; | |
1570 | ||
1571 | memset(&arb_regs, 0x00, sizeof(SMU72_Discrete_MCArbDramTimingTable)); | |
1572 | ||
1573 | for (i = 0; i < data->dpm_table.sclk_table.count; i++) { | |
1574 | for (j = 0; j < data->dpm_table.mclk_table.count; j++) { | |
1575 | result = tonga_populate_memory_timing_parameters | |
1576 | (hwmgr, data->dpm_table.sclk_table.dpm_levels[i].value, | |
1577 | data->dpm_table.mclk_table.dpm_levels[j].value, | |
1578 | &arb_regs.entries[i][j]); | |
1579 | ||
1580 | if (0 != result) { | |
1581 | break; | |
1582 | } | |
1583 | } | |
1584 | } | |
1585 | ||
1586 | if (0 == result) { | |
1587 | result = tonga_copy_bytes_to_smc( | |
1588 | hwmgr->smumgr, | |
1589 | data->arb_table_start, | |
1590 | (uint8_t *)&arb_regs, | |
1591 | sizeof(SMU72_Discrete_MCArbDramTimingTable), | |
1592 | data->sram_end | |
1593 | ); | |
1594 | } | |
1595 | ||
1596 | return result; | |
1597 | } | |
1598 | ||
1599 | static int tonga_populate_smc_link_level(struct pp_hwmgr *hwmgr, SMU72_Discrete_DpmTable *table) | |
1600 | { | |
1601 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
1602 | struct tonga_dpm_table *dpm_table = &data->dpm_table; | |
1603 | uint32_t i; | |
1604 | ||
1605 | /* Index (dpm_table->pcie_speed_table.count) is reserved for PCIE boot level. */ | |
1606 | for (i = 0; i <= dpm_table->pcie_speed_table.count; i++) { | |
1607 | table->LinkLevel[i].PcieGenSpeed = | |
1608 | (uint8_t)dpm_table->pcie_speed_table.dpm_levels[i].value; | |
1609 | table->LinkLevel[i].PcieLaneCount = | |
1610 | (uint8_t)encode_pcie_lane_width(dpm_table->pcie_speed_table.dpm_levels[i].param1); | |
1611 | table->LinkLevel[i].EnabledForActivity = | |
1612 | 1; | |
1613 | table->LinkLevel[i].SPC = | |
1614 | (uint8_t)(data->pcie_spc_cap & 0xff); | |
1615 | table->LinkLevel[i].DownThreshold = | |
1616 | PP_HOST_TO_SMC_UL(5); | |
1617 | table->LinkLevel[i].UpThreshold = | |
1618 | PP_HOST_TO_SMC_UL(30); | |
1619 | } | |
1620 | ||
1621 | data->smc_state_table.LinkLevelCount = | |
1622 | (uint8_t)dpm_table->pcie_speed_table.count; | |
1623 | data->dpm_level_enable_mask.pcie_dpm_enable_mask = | |
1624 | tonga_get_dpm_level_enable_mask_value(&dpm_table->pcie_speed_table); | |
1625 | ||
1626 | return 0; | |
1627 | } | |
1628 | ||
1629 | ||
1630 | static int tonga_populate_smc_vce_level(struct pp_hwmgr *hwmgr, | |
1631 | SMU72_Discrete_DpmTable *table) | |
1632 | { | |
1633 | int result = 0; | |
1634 | ||
1635 | uint8_t count; | |
1636 | pp_atomctrl_clock_dividers_vi dividers; | |
1637 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
1638 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
1639 | phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table = pptable_info->mm_dep_table; | |
1640 | ||
1641 | table->VceLevelCount = (uint8_t) (mm_table->count); | |
1642 | table->VceBootLevel = 0; | |
1643 | ||
1644 | for (count = 0; count < table->VceLevelCount; count++) { | |
1645 | table->VceLevel[count].Frequency = | |
1646 | mm_table->entries[count].eclk; | |
1647 | table->VceLevel[count].MinVoltage.Vddc = | |
1648 | tonga_get_voltage_index(pptable_info->vddc_lookup_table, | |
1649 | mm_table->entries[count].vddc); | |
1650 | table->VceLevel[count].MinVoltage.VddGfx = | |
1651 | (data->vdd_gfx_control == TONGA_VOLTAGE_CONTROL_BY_SVID2) ? | |
1652 | tonga_get_voltage_index(pptable_info->vddgfx_lookup_table, | |
1653 | mm_table->entries[count].vddgfx) : 0; | |
1654 | table->VceLevel[count].MinVoltage.Vddci = | |
1655 | tonga_get_voltage_id(&data->vddci_voltage_table, | |
1656 | mm_table->entries[count].vddc - data->vddc_vddci_delta); | |
1657 | table->VceLevel[count].MinVoltage.Phases = 1; | |
1658 | ||
1659 | /* retrieve divider value for VBIOS */ | |
1660 | result = atomctrl_get_dfs_pll_dividers_vi(hwmgr, | |
1661 | table->VceLevel[count].Frequency, ÷rs); | |
1662 | PP_ASSERT_WITH_CODE((0 == result), | |
1663 | "can not find divide id for VCE engine clock", return result); | |
1664 | ||
1665 | table->VceLevel[count].Divider = (uint8_t)dividers.pll_post_divider; | |
1666 | ||
1667 | CONVERT_FROM_HOST_TO_SMC_UL(table->VceLevel[count].Frequency); | |
1668 | } | |
1669 | ||
1670 | return result; | |
1671 | } | |
1672 | ||
1673 | static int tonga_populate_smc_acp_level(struct pp_hwmgr *hwmgr, | |
1674 | SMU72_Discrete_DpmTable *table) | |
1675 | { | |
1676 | int result = 0; | |
1677 | uint8_t count; | |
1678 | pp_atomctrl_clock_dividers_vi dividers; | |
1679 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
1680 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
1681 | phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table = pptable_info->mm_dep_table; | |
1682 | ||
1683 | table->AcpLevelCount = (uint8_t) (mm_table->count); | |
1684 | table->AcpBootLevel = 0; | |
1685 | ||
1686 | for (count = 0; count < table->AcpLevelCount; count++) { | |
1687 | table->AcpLevel[count].Frequency = | |
1688 | pptable_info->mm_dep_table->entries[count].aclk; | |
1689 | table->AcpLevel[count].MinVoltage.Vddc = | |
1690 | tonga_get_voltage_index(pptable_info->vddc_lookup_table, | |
1691 | mm_table->entries[count].vddc); | |
1692 | table->AcpLevel[count].MinVoltage.VddGfx = | |
1693 | (data->vdd_gfx_control == TONGA_VOLTAGE_CONTROL_BY_SVID2) ? | |
1694 | tonga_get_voltage_index(pptable_info->vddgfx_lookup_table, | |
1695 | mm_table->entries[count].vddgfx) : 0; | |
1696 | table->AcpLevel[count].MinVoltage.Vddci = | |
1697 | tonga_get_voltage_id(&data->vddci_voltage_table, | |
1698 | mm_table->entries[count].vddc - data->vddc_vddci_delta); | |
1699 | table->AcpLevel[count].MinVoltage.Phases = 1; | |
1700 | ||
1701 | /* retrieve divider value for VBIOS */ | |
1702 | result = atomctrl_get_dfs_pll_dividers_vi(hwmgr, | |
1703 | table->AcpLevel[count].Frequency, ÷rs); | |
1704 | PP_ASSERT_WITH_CODE((0 == result), | |
1705 | "can not find divide id for engine clock", return result); | |
1706 | ||
1707 | table->AcpLevel[count].Divider = (uint8_t)dividers.pll_post_divider; | |
1708 | ||
1709 | CONVERT_FROM_HOST_TO_SMC_UL(table->AcpLevel[count].Frequency); | |
1710 | } | |
1711 | ||
1712 | return result; | |
1713 | } | |
1714 | ||
1715 | static int tonga_populate_smc_samu_level(struct pp_hwmgr *hwmgr, | |
1716 | SMU72_Discrete_DpmTable *table) | |
1717 | { | |
1718 | int result = 0; | |
1719 | uint8_t count; | |
1720 | pp_atomctrl_clock_dividers_vi dividers; | |
1721 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
1722 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
1723 | phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table = pptable_info->mm_dep_table; | |
1724 | ||
1725 | table->SamuBootLevel = 0; | |
1726 | table->SamuLevelCount = (uint8_t) (mm_table->count); | |
1727 | ||
1728 | for (count = 0; count < table->SamuLevelCount; count++) { | |
1729 | /* not sure whether we need evclk or not */ | |
1730 | table->SamuLevel[count].Frequency = | |
1731 | pptable_info->mm_dep_table->entries[count].samclock; | |
1732 | table->SamuLevel[count].MinVoltage.Vddc = | |
1733 | tonga_get_voltage_index(pptable_info->vddc_lookup_table, | |
1734 | mm_table->entries[count].vddc); | |
1735 | table->SamuLevel[count].MinVoltage.VddGfx = | |
1736 | (data->vdd_gfx_control == TONGA_VOLTAGE_CONTROL_BY_SVID2) ? | |
1737 | tonga_get_voltage_index(pptable_info->vddgfx_lookup_table, | |
1738 | mm_table->entries[count].vddgfx) : 0; | |
1739 | table->SamuLevel[count].MinVoltage.Vddci = | |
1740 | tonga_get_voltage_id(&data->vddci_voltage_table, | |
1741 | mm_table->entries[count].vddc - data->vddc_vddci_delta); | |
1742 | table->SamuLevel[count].MinVoltage.Phases = 1; | |
1743 | ||
1744 | /* retrieve divider value for VBIOS */ | |
1745 | result = atomctrl_get_dfs_pll_dividers_vi(hwmgr, | |
1746 | table->SamuLevel[count].Frequency, ÷rs); | |
1747 | PP_ASSERT_WITH_CODE((0 == result), | |
1748 | "can not find divide id for samu clock", return result); | |
1749 | ||
1750 | table->SamuLevel[count].Divider = (uint8_t)dividers.pll_post_divider; | |
1751 | ||
1752 | CONVERT_FROM_HOST_TO_SMC_UL(table->SamuLevel[count].Frequency); | |
1753 | } | |
1754 | ||
1755 | return result; | |
1756 | } | |
1757 | ||
1758 | /** | |
1759 | * Populates the SMC MCLK structure using the provided memory clock | |
1760 | * | |
1761 | * @param hwmgr the address of the hardware manager | |
1762 | * @param memory_clock the memory clock to use to populate the structure | |
1763 | * @param sclk the SMC SCLK structure to be populated | |
1764 | */ | |
1765 | static int tonga_calculate_mclk_params( | |
1766 | struct pp_hwmgr *hwmgr, | |
1767 | uint32_t memory_clock, | |
1768 | SMU72_Discrete_MemoryLevel *mclk, | |
1769 | bool strobe_mode, | |
1770 | bool dllStateOn | |
1771 | ) | |
1772 | { | |
1773 | const tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
1774 | uint32_t dll_cntl = data->clock_registers.vDLL_CNTL; | |
1775 | uint32_t mclk_pwrmgt_cntl = data->clock_registers.vMCLK_PWRMGT_CNTL; | |
1776 | uint32_t mpll_ad_func_cntl = data->clock_registers.vMPLL_AD_FUNC_CNTL; | |
1777 | uint32_t mpll_dq_func_cntl = data->clock_registers.vMPLL_DQ_FUNC_CNTL; | |
1778 | uint32_t mpll_func_cntl = data->clock_registers.vMPLL_FUNC_CNTL; | |
1779 | uint32_t mpll_func_cntl_1 = data->clock_registers.vMPLL_FUNC_CNTL_1; | |
1780 | uint32_t mpll_func_cntl_2 = data->clock_registers.vMPLL_FUNC_CNTL_2; | |
1781 | uint32_t mpll_ss1 = data->clock_registers.vMPLL_SS1; | |
1782 | uint32_t mpll_ss2 = data->clock_registers.vMPLL_SS2; | |
1783 | ||
1784 | pp_atomctrl_memory_clock_param mpll_param; | |
1785 | int result; | |
1786 | ||
1787 | result = atomctrl_get_memory_pll_dividers_si(hwmgr, | |
1788 | memory_clock, &mpll_param, strobe_mode); | |
1789 | PP_ASSERT_WITH_CODE(0 == result, | |
1790 | "Error retrieving Memory Clock Parameters from VBIOS.", return result); | |
1791 | ||
1792 | /* MPLL_FUNC_CNTL setup*/ | |
1793 | mpll_func_cntl = PHM_SET_FIELD(mpll_func_cntl, MPLL_FUNC_CNTL, BWCTRL, mpll_param.bw_ctrl); | |
1794 | ||
1795 | /* MPLL_FUNC_CNTL_1 setup*/ | |
1796 | mpll_func_cntl_1 = PHM_SET_FIELD(mpll_func_cntl_1, | |
1797 | MPLL_FUNC_CNTL_1, CLKF, mpll_param.mpll_fb_divider.cl_kf); | |
1798 | mpll_func_cntl_1 = PHM_SET_FIELD(mpll_func_cntl_1, | |
1799 | MPLL_FUNC_CNTL_1, CLKFRAC, mpll_param.mpll_fb_divider.clk_frac); | |
1800 | mpll_func_cntl_1 = PHM_SET_FIELD(mpll_func_cntl_1, | |
1801 | MPLL_FUNC_CNTL_1, VCO_MODE, mpll_param.vco_mode); | |
1802 | ||
1803 | /* MPLL_AD_FUNC_CNTL setup*/ | |
1804 | mpll_ad_func_cntl = PHM_SET_FIELD(mpll_ad_func_cntl, | |
1805 | MPLL_AD_FUNC_CNTL, YCLK_POST_DIV, mpll_param.mpll_post_divider); | |
1806 | ||
1807 | if (data->is_memory_GDDR5) { | |
1808 | /* MPLL_DQ_FUNC_CNTL setup*/ | |
1809 | mpll_dq_func_cntl = PHM_SET_FIELD(mpll_dq_func_cntl, | |
1810 | MPLL_DQ_FUNC_CNTL, YCLK_SEL, mpll_param.yclk_sel); | |
1811 | mpll_dq_func_cntl = PHM_SET_FIELD(mpll_dq_func_cntl, | |
1812 | MPLL_DQ_FUNC_CNTL, YCLK_POST_DIV, mpll_param.mpll_post_divider); | |
1813 | } | |
1814 | ||
1815 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
1816 | PHM_PlatformCaps_MemorySpreadSpectrumSupport)) { | |
1817 | /* | |
1818 | ************************************ | |
1819 | Fref = Reference Frequency | |
1820 | NF = Feedback divider ratio | |
1821 | NR = Reference divider ratio | |
1822 | Fnom = Nominal VCO output frequency = Fref * NF / NR | |
1823 | Fs = Spreading Rate | |
1824 | D = Percentage down-spread / 2 | |
1825 | Fint = Reference input frequency to PFD = Fref / NR | |
1826 | NS = Spreading rate divider ratio = int(Fint / (2 * Fs)) | |
1827 | CLKS = NS - 1 = ISS_STEP_NUM[11:0] | |
1828 | NV = D * Fs / Fnom * 4 * ((Fnom/Fref * NR) ^ 2) | |
1829 | CLKV = 65536 * NV = ISS_STEP_SIZE[25:0] | |
1830 | ************************************* | |
1831 | */ | |
1832 | pp_atomctrl_internal_ss_info ss_info; | |
1833 | uint32_t freq_nom; | |
1834 | uint32_t tmp; | |
1835 | uint32_t reference_clock = atomctrl_get_mpll_reference_clock(hwmgr); | |
1836 | ||
1837 | /* for GDDR5 for all modes and DDR3 */ | |
1838 | if (1 == mpll_param.qdr) | |
1839 | freq_nom = memory_clock * 4 * (1 << mpll_param.mpll_post_divider); | |
1840 | else | |
1841 | freq_nom = memory_clock * 2 * (1 << mpll_param.mpll_post_divider); | |
1842 | ||
1843 | /* tmp = (freq_nom / reference_clock * reference_divider) ^ 2 Note: S.I. reference_divider = 1*/ | |
1844 | tmp = (freq_nom / reference_clock); | |
1845 | tmp = tmp * tmp; | |
1846 | ||
1847 | if (0 == atomctrl_get_memory_clock_spread_spectrum(hwmgr, freq_nom, &ss_info)) { | |
1848 | /* ss_info.speed_spectrum_percentage -- in unit of 0.01% */ | |
1849 | /* ss.Info.speed_spectrum_rate -- in unit of khz */ | |
1850 | /* CLKS = reference_clock / (2 * speed_spectrum_rate * reference_divider) * 10 */ | |
1851 | /* = reference_clock * 5 / speed_spectrum_rate */ | |
1852 | uint32_t clks = reference_clock * 5 / ss_info.speed_spectrum_rate; | |
1853 | ||
1854 | /* CLKV = 65536 * speed_spectrum_percentage / 2 * spreadSpecrumRate / freq_nom * 4 / 100000 * ((freq_nom / reference_clock) ^ 2) */ | |
1855 | /* = 131 * speed_spectrum_percentage * speed_spectrum_rate / 100 * ((freq_nom / reference_clock) ^ 2) / freq_nom */ | |
1856 | uint32_t clkv = | |
1857 | (uint32_t)((((131 * ss_info.speed_spectrum_percentage * | |
1858 | ss_info.speed_spectrum_rate) / 100) * tmp) / freq_nom); | |
1859 | ||
1860 | mpll_ss1 = PHM_SET_FIELD(mpll_ss1, MPLL_SS1, CLKV, clkv); | |
1861 | mpll_ss2 = PHM_SET_FIELD(mpll_ss2, MPLL_SS2, CLKS, clks); | |
1862 | } | |
1863 | } | |
1864 | ||
1865 | /* MCLK_PWRMGT_CNTL setup */ | |
1866 | mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl, | |
1867 | MCLK_PWRMGT_CNTL, DLL_SPEED, mpll_param.dll_speed); | |
1868 | mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl, | |
1869 | MCLK_PWRMGT_CNTL, MRDCK0_PDNB, dllStateOn); | |
1870 | mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl, | |
1871 | MCLK_PWRMGT_CNTL, MRDCK1_PDNB, dllStateOn); | |
1872 | ||
1873 | ||
1874 | /* Save the result data to outpupt memory level structure */ | |
1875 | mclk->MclkFrequency = memory_clock; | |
1876 | mclk->MpllFuncCntl = mpll_func_cntl; | |
1877 | mclk->MpllFuncCntl_1 = mpll_func_cntl_1; | |
1878 | mclk->MpllFuncCntl_2 = mpll_func_cntl_2; | |
1879 | mclk->MpllAdFuncCntl = mpll_ad_func_cntl; | |
1880 | mclk->MpllDqFuncCntl = mpll_dq_func_cntl; | |
1881 | mclk->MclkPwrmgtCntl = mclk_pwrmgt_cntl; | |
1882 | mclk->DllCntl = dll_cntl; | |
1883 | mclk->MpllSs1 = mpll_ss1; | |
1884 | mclk->MpllSs2 = mpll_ss2; | |
1885 | ||
1886 | return 0; | |
1887 | } | |
1888 | ||
1889 | static uint8_t tonga_get_mclk_frequency_ratio(uint32_t memory_clock, | |
1890 | bool strobe_mode) | |
1891 | { | |
1892 | uint8_t mc_para_index; | |
1893 | ||
1894 | if (strobe_mode) { | |
1895 | if (memory_clock < 12500) { | |
1896 | mc_para_index = 0x00; | |
1897 | } else if (memory_clock > 47500) { | |
1898 | mc_para_index = 0x0f; | |
1899 | } else { | |
1900 | mc_para_index = (uint8_t)((memory_clock - 10000) / 2500); | |
1901 | } | |
1902 | } else { | |
1903 | if (memory_clock < 65000) { | |
1904 | mc_para_index = 0x00; | |
1905 | } else if (memory_clock > 135000) { | |
1906 | mc_para_index = 0x0f; | |
1907 | } else { | |
1908 | mc_para_index = (uint8_t)((memory_clock - 60000) / 5000); | |
1909 | } | |
1910 | } | |
1911 | ||
1912 | return mc_para_index; | |
1913 | } | |
1914 | ||
1915 | static uint8_t tonga_get_ddr3_mclk_frequency_ratio(uint32_t memory_clock) | |
1916 | { | |
1917 | uint8_t mc_para_index; | |
1918 | ||
1919 | if (memory_clock < 10000) { | |
1920 | mc_para_index = 0; | |
1921 | } else if (memory_clock >= 80000) { | |
1922 | mc_para_index = 0x0f; | |
1923 | } else { | |
1924 | mc_para_index = (uint8_t)((memory_clock - 10000) / 5000 + 1); | |
1925 | } | |
1926 | ||
1927 | return mc_para_index; | |
1928 | } | |
1929 | ||
1930 | static int tonga_populate_single_memory_level( | |
1931 | struct pp_hwmgr *hwmgr, | |
1932 | uint32_t memory_clock, | |
1933 | SMU72_Discrete_MemoryLevel *memory_level | |
1934 | ) | |
1935 | { | |
1936 | uint32_t minMvdd = 0; | |
1937 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
1938 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
1939 | int result = 0; | |
1940 | bool dllStateOn; | |
1941 | struct cgs_display_info info = {0}; | |
1942 | ||
1943 | ||
1944 | if (NULL != pptable_info->vdd_dep_on_mclk) { | |
1945 | result = tonga_get_dependecy_volt_by_clk(hwmgr, | |
1946 | pptable_info->vdd_dep_on_mclk, memory_clock, &memory_level->MinVoltage, &minMvdd); | |
1947 | PP_ASSERT_WITH_CODE((0 == result), | |
1948 | "can not find MinVddc voltage value from memory VDDC voltage dependency table", return result); | |
1949 | } | |
1950 | ||
1951 | if (data->mvdd_control == TONGA_VOLTAGE_CONTROL_NONE) { | |
1952 | memory_level->MinMvdd = data->vbios_boot_state.mvdd_bootup_value; | |
1953 | } else { | |
1954 | memory_level->MinMvdd = minMvdd; | |
1955 | } | |
1956 | memory_level->EnabledForThrottle = 1; | |
1957 | memory_level->EnabledForActivity = 0; | |
1958 | memory_level->UpHyst = 0; | |
1959 | memory_level->DownHyst = 100; | |
1960 | memory_level->VoltageDownHyst = 0; | |
1961 | ||
1962 | /* Indicates maximum activity level for this performance level.*/ | |
1963 | memory_level->ActivityLevel = (uint16_t)data->mclk_activity_target; | |
1964 | memory_level->StutterEnable = 0; | |
1965 | memory_level->StrobeEnable = 0; | |
1966 | memory_level->EdcReadEnable = 0; | |
1967 | memory_level->EdcWriteEnable = 0; | |
1968 | memory_level->RttEnable = 0; | |
1969 | ||
1970 | /* default set to low watermark. Highest level will be set to high later.*/ | |
1971 | memory_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW; | |
1972 | ||
1973 | cgs_get_active_displays_info(hwmgr->device, &info); | |
1974 | data->display_timing.num_existing_displays = info.display_count; | |
1975 | ||
1976 | if ((data->mclk_stutter_mode_threshold != 0) && | |
1977 | (memory_clock <= data->mclk_stutter_mode_threshold) && | |
1978 | (data->is_uvd_enabled == 0) | |
1979 | #if defined(LINUX) | |
1980 | && (PHM_READ_FIELD(hwmgr->device, DPG_PIPE_STUTTER_CONTROL, STUTTER_ENABLE) & 0x1) | |
1981 | && (data->display_timing.num_existing_displays <= 2) | |
1982 | && (data->display_timing.num_existing_displays != 0) | |
1983 | #endif | |
1984 | ) | |
1985 | memory_level->StutterEnable = 1; | |
1986 | ||
1987 | /* decide strobe mode*/ | |
1988 | memory_level->StrobeEnable = (data->mclk_strobe_mode_threshold != 0) && | |
1989 | (memory_clock <= data->mclk_strobe_mode_threshold); | |
1990 | ||
1991 | /* decide EDC mode and memory clock ratio*/ | |
1992 | if (data->is_memory_GDDR5) { | |
1993 | memory_level->StrobeRatio = tonga_get_mclk_frequency_ratio(memory_clock, | |
1994 | memory_level->StrobeEnable); | |
1995 | ||
1996 | if ((data->mclk_edc_enable_threshold != 0) && | |
1997 | (memory_clock > data->mclk_edc_enable_threshold)) { | |
1998 | memory_level->EdcReadEnable = 1; | |
1999 | } | |
2000 | ||
2001 | if ((data->mclk_edc_wr_enable_threshold != 0) && | |
2002 | (memory_clock > data->mclk_edc_wr_enable_threshold)) { | |
2003 | memory_level->EdcWriteEnable = 1; | |
2004 | } | |
2005 | ||
2006 | if (memory_level->StrobeEnable) { | |
2007 | if (tonga_get_mclk_frequency_ratio(memory_clock, 1) >= | |
2008 | ((cgs_read_register(hwmgr->device, mmMC_SEQ_MISC7) >> 16) & 0xf)) { | |
2009 | dllStateOn = ((cgs_read_register(hwmgr->device, mmMC_SEQ_MISC5) >> 1) & 0x1) ? 1 : 0; | |
2010 | } else { | |
2011 | dllStateOn = ((cgs_read_register(hwmgr->device, mmMC_SEQ_MISC6) >> 1) & 0x1) ? 1 : 0; | |
2012 | } | |
2013 | ||
2014 | } else { | |
2015 | dllStateOn = data->dll_defaule_on; | |
2016 | } | |
2017 | } else { | |
2018 | memory_level->StrobeRatio = | |
2019 | tonga_get_ddr3_mclk_frequency_ratio(memory_clock); | |
2020 | dllStateOn = ((cgs_read_register(hwmgr->device, mmMC_SEQ_MISC5) >> 1) & 0x1) ? 1 : 0; | |
2021 | } | |
2022 | ||
2023 | result = tonga_calculate_mclk_params(hwmgr, | |
2024 | memory_clock, memory_level, memory_level->StrobeEnable, dllStateOn); | |
2025 | ||
2026 | if (0 == result) { | |
2027 | CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MinMvdd); | |
2028 | /* MCLK frequency in units of 10KHz*/ | |
2029 | CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MclkFrequency); | |
2030 | /* Indicates maximum activity level for this performance level.*/ | |
2031 | CONVERT_FROM_HOST_TO_SMC_US(memory_level->ActivityLevel); | |
2032 | CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllFuncCntl); | |
2033 | CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllFuncCntl_1); | |
2034 | CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllFuncCntl_2); | |
2035 | CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllAdFuncCntl); | |
2036 | CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllDqFuncCntl); | |
2037 | CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MclkPwrmgtCntl); | |
2038 | CONVERT_FROM_HOST_TO_SMC_UL(memory_level->DllCntl); | |
2039 | CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllSs1); | |
2040 | CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllSs2); | |
2041 | } | |
2042 | ||
2043 | return result; | |
2044 | } | |
2045 | ||
2046 | /** | |
2047 | * Populates the SMC MVDD structure using the provided memory clock. | |
2048 | * | |
2049 | * @param hwmgr the address of the hardware manager | |
2050 | * @param mclk the MCLK value to be used in the decision if MVDD should be high or low. | |
2051 | * @param voltage the SMC VOLTAGE structure to be populated | |
2052 | */ | |
2053 | int tonga_populate_mvdd_value(struct pp_hwmgr *hwmgr, uint32_t mclk, SMIO_Pattern *smio_pattern) | |
2054 | { | |
2055 | const tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
2056 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
2057 | uint32_t i = 0; | |
2058 | ||
2059 | if (TONGA_VOLTAGE_CONTROL_NONE != data->mvdd_control) { | |
2060 | /* find mvdd value which clock is more than request */ | |
2061 | for (i = 0; i < pptable_info->vdd_dep_on_mclk->count; i++) { | |
2062 | if (mclk <= pptable_info->vdd_dep_on_mclk->entries[i].clk) { | |
2063 | /* Always round to higher voltage. */ | |
2064 | smio_pattern->Voltage = data->mvdd_voltage_table.entries[i].value; | |
2065 | break; | |
2066 | } | |
2067 | } | |
2068 | ||
2069 | PP_ASSERT_WITH_CODE(i < pptable_info->vdd_dep_on_mclk->count, | |
2070 | "MVDD Voltage is outside the supported range.", return -1); | |
2071 | ||
2072 | } else { | |
2073 | return -1; | |
2074 | } | |
2075 | ||
2076 | return 0; | |
2077 | } | |
2078 | ||
2079 | ||
2080 | static int tonga_populate_smv_acpi_level(struct pp_hwmgr *hwmgr, | |
2081 | SMU72_Discrete_DpmTable *table) | |
2082 | { | |
2083 | int result = 0; | |
2084 | const tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
2085 | pp_atomctrl_clock_dividers_vi dividers; | |
2086 | SMIO_Pattern voltage_level; | |
2087 | uint32_t spll_func_cntl = data->clock_registers.vCG_SPLL_FUNC_CNTL; | |
2088 | uint32_t spll_func_cntl_2 = data->clock_registers.vCG_SPLL_FUNC_CNTL_2; | |
2089 | uint32_t dll_cntl = data->clock_registers.vDLL_CNTL; | |
2090 | uint32_t mclk_pwrmgt_cntl = data->clock_registers.vMCLK_PWRMGT_CNTL; | |
2091 | ||
2092 | /* The ACPI state should not do DPM on DC (or ever).*/ | |
2093 | table->ACPILevel.Flags &= ~PPSMC_SWSTATE_FLAG_DC; | |
2094 | ||
2095 | table->ACPILevel.MinVoltage = data->smc_state_table.GraphicsLevel[0].MinVoltage; | |
2096 | ||
2097 | /* assign zero for now*/ | |
2098 | table->ACPILevel.SclkFrequency = atomctrl_get_reference_clock(hwmgr); | |
2099 | ||
2100 | /* get the engine clock dividers for this clock value*/ | |
2101 | result = atomctrl_get_engine_pll_dividers_vi(hwmgr, | |
2102 | table->ACPILevel.SclkFrequency, ÷rs); | |
2103 | ||
2104 | PP_ASSERT_WITH_CODE(result == 0, | |
2105 | "Error retrieving Engine Clock dividers from VBIOS.", return result); | |
2106 | ||
2107 | /* divider ID for required SCLK*/ | |
2108 | table->ACPILevel.SclkDid = (uint8_t)dividers.pll_post_divider; | |
2109 | table->ACPILevel.DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW; | |
2110 | table->ACPILevel.DeepSleepDivId = 0; | |
2111 | ||
2112 | spll_func_cntl = PHM_SET_FIELD(spll_func_cntl, | |
2113 | CG_SPLL_FUNC_CNTL, SPLL_PWRON, 0); | |
2114 | spll_func_cntl = PHM_SET_FIELD(spll_func_cntl, | |
2115 | CG_SPLL_FUNC_CNTL, SPLL_RESET, 1); | |
2116 | spll_func_cntl_2 = PHM_SET_FIELD(spll_func_cntl_2, | |
2117 | CG_SPLL_FUNC_CNTL_2, SCLK_MUX_SEL, 4); | |
2118 | ||
2119 | table->ACPILevel.CgSpllFuncCntl = spll_func_cntl; | |
2120 | table->ACPILevel.CgSpllFuncCntl2 = spll_func_cntl_2; | |
2121 | table->ACPILevel.CgSpllFuncCntl3 = data->clock_registers.vCG_SPLL_FUNC_CNTL_3; | |
2122 | table->ACPILevel.CgSpllFuncCntl4 = data->clock_registers.vCG_SPLL_FUNC_CNTL_4; | |
2123 | table->ACPILevel.SpllSpreadSpectrum = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM; | |
2124 | table->ACPILevel.SpllSpreadSpectrum2 = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2; | |
2125 | table->ACPILevel.CcPwrDynRm = 0; | |
2126 | table->ACPILevel.CcPwrDynRm1 = 0; | |
2127 | ||
2128 | ||
2129 | /* For various features to be enabled/disabled while this level is active.*/ | |
2130 | CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.Flags); | |
2131 | /* SCLK frequency in units of 10KHz*/ | |
2132 | CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SclkFrequency); | |
2133 | CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl); | |
2134 | CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl2); | |
2135 | CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl3); | |
2136 | CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl4); | |
2137 | CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SpllSpreadSpectrum); | |
2138 | CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SpllSpreadSpectrum2); | |
2139 | CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm); | |
2140 | CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm1); | |
2141 | ||
2142 | /* table->MemoryACPILevel.MinVddcPhases = table->ACPILevel.MinVddcPhases;*/ | |
2143 | table->MemoryACPILevel.MinVoltage = data->smc_state_table.MemoryLevel[0].MinVoltage; | |
2144 | ||
2145 | /* CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MinVoltage);*/ | |
2146 | ||
2147 | if (0 == tonga_populate_mvdd_value(hwmgr, 0, &voltage_level)) | |
2148 | table->MemoryACPILevel.MinMvdd = | |
2149 | PP_HOST_TO_SMC_UL(voltage_level.Voltage * VOLTAGE_SCALE); | |
2150 | else | |
2151 | table->MemoryACPILevel.MinMvdd = 0; | |
2152 | ||
2153 | /* Force reset on DLL*/ | |
2154 | mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl, | |
2155 | MCLK_PWRMGT_CNTL, MRDCK0_RESET, 0x1); | |
2156 | mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl, | |
2157 | MCLK_PWRMGT_CNTL, MRDCK1_RESET, 0x1); | |
2158 | ||
2159 | /* Disable DLL in ACPIState*/ | |
2160 | mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl, | |
2161 | MCLK_PWRMGT_CNTL, MRDCK0_PDNB, 0); | |
2162 | mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl, | |
2163 | MCLK_PWRMGT_CNTL, MRDCK1_PDNB, 0); | |
2164 | ||
2165 | /* Enable DLL bypass signal*/ | |
2166 | dll_cntl = PHM_SET_FIELD(dll_cntl, | |
2167 | DLL_CNTL, MRDCK0_BYPASS, 0); | |
2168 | dll_cntl = PHM_SET_FIELD(dll_cntl, | |
2169 | DLL_CNTL, MRDCK1_BYPASS, 0); | |
2170 | ||
2171 | table->MemoryACPILevel.DllCntl = | |
2172 | PP_HOST_TO_SMC_UL(dll_cntl); | |
2173 | table->MemoryACPILevel.MclkPwrmgtCntl = | |
2174 | PP_HOST_TO_SMC_UL(mclk_pwrmgt_cntl); | |
2175 | table->MemoryACPILevel.MpllAdFuncCntl = | |
2176 | PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_AD_FUNC_CNTL); | |
2177 | table->MemoryACPILevel.MpllDqFuncCntl = | |
2178 | PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_DQ_FUNC_CNTL); | |
2179 | table->MemoryACPILevel.MpllFuncCntl = | |
2180 | PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_FUNC_CNTL); | |
2181 | table->MemoryACPILevel.MpllFuncCntl_1 = | |
2182 | PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_FUNC_CNTL_1); | |
2183 | table->MemoryACPILevel.MpllFuncCntl_2 = | |
2184 | PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_FUNC_CNTL_2); | |
2185 | table->MemoryACPILevel.MpllSs1 = | |
2186 | PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_SS1); | |
2187 | table->MemoryACPILevel.MpllSs2 = | |
2188 | PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_SS2); | |
2189 | ||
2190 | table->MemoryACPILevel.EnabledForThrottle = 0; | |
2191 | table->MemoryACPILevel.EnabledForActivity = 0; | |
2192 | table->MemoryACPILevel.UpHyst = 0; | |
2193 | table->MemoryACPILevel.DownHyst = 100; | |
2194 | table->MemoryACPILevel.VoltageDownHyst = 0; | |
2195 | /* Indicates maximum activity level for this performance level.*/ | |
2196 | table->MemoryACPILevel.ActivityLevel = PP_HOST_TO_SMC_US((uint16_t)data->mclk_activity_target); | |
2197 | ||
2198 | table->MemoryACPILevel.StutterEnable = 0; | |
2199 | table->MemoryACPILevel.StrobeEnable = 0; | |
2200 | table->MemoryACPILevel.EdcReadEnable = 0; | |
2201 | table->MemoryACPILevel.EdcWriteEnable = 0; | |
2202 | table->MemoryACPILevel.RttEnable = 0; | |
2203 | ||
2204 | return result; | |
2205 | } | |
2206 | ||
2207 | static int tonga_find_boot_level(struct tonga_single_dpm_table *table, uint32_t value, uint32_t *boot_level) | |
2208 | { | |
2209 | int result = 0; | |
2210 | uint32_t i; | |
2211 | ||
2212 | for (i = 0; i < table->count; i++) { | |
2213 | if (value == table->dpm_levels[i].value) { | |
2214 | *boot_level = i; | |
2215 | result = 0; | |
2216 | } | |
2217 | } | |
2218 | return result; | |
2219 | } | |
2220 | ||
2221 | static int tonga_populate_smc_boot_level(struct pp_hwmgr *hwmgr, | |
2222 | SMU72_Discrete_DpmTable *table) | |
2223 | { | |
2224 | int result = 0; | |
2225 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
2226 | ||
2227 | table->GraphicsBootLevel = 0; /* 0 == DPM[0] (low), etc. */ | |
2228 | table->MemoryBootLevel = 0; /* 0 == DPM[0] (low), etc. */ | |
2229 | ||
2230 | /* find boot level from dpm table*/ | |
2231 | result = tonga_find_boot_level(&(data->dpm_table.sclk_table), | |
2232 | data->vbios_boot_state.sclk_bootup_value, | |
2233 | (uint32_t *)&(data->smc_state_table.GraphicsBootLevel)); | |
2234 | ||
2235 | if (0 != result) { | |
2236 | data->smc_state_table.GraphicsBootLevel = 0; | |
2237 | printk(KERN_ERR "[ powerplay ] VBIOS did not find boot engine clock value \ | |
2238 | in dependency table. Using Graphics DPM level 0!"); | |
2239 | result = 0; | |
2240 | } | |
2241 | ||
2242 | result = tonga_find_boot_level(&(data->dpm_table.mclk_table), | |
2243 | data->vbios_boot_state.mclk_bootup_value, | |
2244 | (uint32_t *)&(data->smc_state_table.MemoryBootLevel)); | |
2245 | ||
2246 | if (0 != result) { | |
2247 | data->smc_state_table.MemoryBootLevel = 0; | |
2248 | printk(KERN_ERR "[ powerplay ] VBIOS did not find boot engine clock value \ | |
2249 | in dependency table. Using Memory DPM level 0!"); | |
2250 | result = 0; | |
2251 | } | |
2252 | ||
2253 | table->BootVoltage.Vddc = | |
2254 | tonga_get_voltage_id(&(data->vddc_voltage_table), | |
2255 | data->vbios_boot_state.vddc_bootup_value); | |
2256 | table->BootVoltage.VddGfx = | |
2257 | tonga_get_voltage_id(&(data->vddgfx_voltage_table), | |
2258 | data->vbios_boot_state.vddgfx_bootup_value); | |
2259 | table->BootVoltage.Vddci = | |
2260 | tonga_get_voltage_id(&(data->vddci_voltage_table), | |
2261 | data->vbios_boot_state.vddci_bootup_value); | |
2262 | table->BootMVdd = data->vbios_boot_state.mvdd_bootup_value; | |
2263 | ||
2264 | CONVERT_FROM_HOST_TO_SMC_US(table->BootMVdd); | |
2265 | ||
2266 | return result; | |
2267 | } | |
2268 | ||
2269 | ||
2270 | /** | |
2271 | * Calculates the SCLK dividers using the provided engine clock | |
2272 | * | |
2273 | * @param hwmgr the address of the hardware manager | |
2274 | * @param engine_clock the engine clock to use to populate the structure | |
2275 | * @param sclk the SMC SCLK structure to be populated | |
2276 | */ | |
2277 | int tonga_calculate_sclk_params(struct pp_hwmgr *hwmgr, | |
2278 | uint32_t engine_clock, SMU72_Discrete_GraphicsLevel *sclk) | |
2279 | { | |
2280 | const tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
2281 | pp_atomctrl_clock_dividers_vi dividers; | |
2282 | uint32_t spll_func_cntl = data->clock_registers.vCG_SPLL_FUNC_CNTL; | |
2283 | uint32_t spll_func_cntl_3 = data->clock_registers.vCG_SPLL_FUNC_CNTL_3; | |
2284 | uint32_t spll_func_cntl_4 = data->clock_registers.vCG_SPLL_FUNC_CNTL_4; | |
2285 | uint32_t cg_spll_spread_spectrum = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM; | |
2286 | uint32_t cg_spll_spread_spectrum_2 = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2; | |
2287 | uint32_t reference_clock; | |
2288 | uint32_t reference_divider; | |
2289 | uint32_t fbdiv; | |
2290 | int result; | |
2291 | ||
2292 | /* get the engine clock dividers for this clock value*/ | |
2293 | result = atomctrl_get_engine_pll_dividers_vi(hwmgr, engine_clock, ÷rs); | |
2294 | ||
2295 | PP_ASSERT_WITH_CODE(result == 0, | |
2296 | "Error retrieving Engine Clock dividers from VBIOS.", return result); | |
2297 | ||
2298 | /* To get FBDIV we need to multiply this by 16384 and divide it by Fref.*/ | |
2299 | reference_clock = atomctrl_get_reference_clock(hwmgr); | |
2300 | ||
2301 | reference_divider = 1 + dividers.uc_pll_ref_div; | |
2302 | ||
2303 | /* low 14 bits is fraction and high 12 bits is divider*/ | |
2304 | fbdiv = dividers.ul_fb_div.ul_fb_divider & 0x3FFFFFF; | |
2305 | ||
2306 | /* SPLL_FUNC_CNTL setup*/ | |
2307 | spll_func_cntl = PHM_SET_FIELD(spll_func_cntl, | |
2308 | CG_SPLL_FUNC_CNTL, SPLL_REF_DIV, dividers.uc_pll_ref_div); | |
2309 | spll_func_cntl = PHM_SET_FIELD(spll_func_cntl, | |
2310 | CG_SPLL_FUNC_CNTL, SPLL_PDIV_A, dividers.uc_pll_post_div); | |
2311 | ||
2312 | /* SPLL_FUNC_CNTL_3 setup*/ | |
2313 | spll_func_cntl_3 = PHM_SET_FIELD(spll_func_cntl_3, | |
2314 | CG_SPLL_FUNC_CNTL_3, SPLL_FB_DIV, fbdiv); | |
2315 | ||
2316 | /* set to use fractional accumulation*/ | |
2317 | spll_func_cntl_3 = PHM_SET_FIELD(spll_func_cntl_3, | |
2318 | CG_SPLL_FUNC_CNTL_3, SPLL_DITHEN, 1); | |
2319 | ||
2320 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
2321 | PHM_PlatformCaps_EngineSpreadSpectrumSupport)) { | |
2322 | pp_atomctrl_internal_ss_info ss_info; | |
2323 | ||
2324 | uint32_t vcoFreq = engine_clock * dividers.uc_pll_post_div; | |
2325 | if (0 == atomctrl_get_engine_clock_spread_spectrum(hwmgr, vcoFreq, &ss_info)) { | |
2326 | /* | |
2327 | * ss_info.speed_spectrum_percentage -- in unit of 0.01% | |
2328 | * ss_info.speed_spectrum_rate -- in unit of khz | |
2329 | */ | |
2330 | /* clks = reference_clock * 10 / (REFDIV + 1) / speed_spectrum_rate / 2 */ | |
2331 | uint32_t clkS = reference_clock * 5 / (reference_divider * ss_info.speed_spectrum_rate); | |
2332 | ||
2333 | /* clkv = 2 * D * fbdiv / NS */ | |
2334 | uint32_t clkV = 4 * ss_info.speed_spectrum_percentage * fbdiv / (clkS * 10000); | |
2335 | ||
2336 | cg_spll_spread_spectrum = | |
2337 | PHM_SET_FIELD(cg_spll_spread_spectrum, CG_SPLL_SPREAD_SPECTRUM, CLKS, clkS); | |
2338 | cg_spll_spread_spectrum = | |
2339 | PHM_SET_FIELD(cg_spll_spread_spectrum, CG_SPLL_SPREAD_SPECTRUM, SSEN, 1); | |
2340 | cg_spll_spread_spectrum_2 = | |
2341 | PHM_SET_FIELD(cg_spll_spread_spectrum_2, CG_SPLL_SPREAD_SPECTRUM_2, CLKV, clkV); | |
2342 | } | |
2343 | } | |
2344 | ||
2345 | sclk->SclkFrequency = engine_clock; | |
2346 | sclk->CgSpllFuncCntl3 = spll_func_cntl_3; | |
2347 | sclk->CgSpllFuncCntl4 = spll_func_cntl_4; | |
2348 | sclk->SpllSpreadSpectrum = cg_spll_spread_spectrum; | |
2349 | sclk->SpllSpreadSpectrum2 = cg_spll_spread_spectrum_2; | |
2350 | sclk->SclkDid = (uint8_t)dividers.pll_post_divider; | |
2351 | ||
2352 | return 0; | |
2353 | } | |
2354 | ||
2355 | /** | |
2356 | * Populates single SMC SCLK structure using the provided engine clock | |
2357 | * | |
2358 | * @param hwmgr the address of the hardware manager | |
2359 | * @param engine_clock the engine clock to use to populate the structure | |
2360 | * @param sclk the SMC SCLK structure to be populated | |
2361 | */ | |
2362 | static int tonga_populate_single_graphic_level(struct pp_hwmgr *hwmgr, uint32_t engine_clock, uint16_t sclk_activity_level_threshold, SMU72_Discrete_GraphicsLevel *graphic_level) | |
2363 | { | |
2364 | int result; | |
2365 | uint32_t threshold; | |
2366 | uint32_t mvdd; | |
2367 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
2368 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
2369 | ||
2370 | result = tonga_calculate_sclk_params(hwmgr, engine_clock, graphic_level); | |
2371 | ||
2372 | ||
2373 | /* populate graphics levels*/ | |
2374 | result = tonga_get_dependecy_volt_by_clk(hwmgr, | |
2375 | pptable_info->vdd_dep_on_sclk, engine_clock, | |
2376 | &graphic_level->MinVoltage, &mvdd); | |
2377 | PP_ASSERT_WITH_CODE((0 == result), | |
2378 | "can not find VDDC voltage value for VDDC \ | |
2379 | engine clock dependency table", return result); | |
2380 | ||
2381 | /* SCLK frequency in units of 10KHz*/ | |
2382 | graphic_level->SclkFrequency = engine_clock; | |
2383 | ||
2384 | /* Indicates maximum activity level for this performance level. 50% for now*/ | |
2385 | graphic_level->ActivityLevel = sclk_activity_level_threshold; | |
2386 | ||
2387 | graphic_level->CcPwrDynRm = 0; | |
2388 | graphic_level->CcPwrDynRm1 = 0; | |
2389 | /* this level can be used if activity is high enough.*/ | |
2390 | graphic_level->EnabledForActivity = 0; | |
2391 | /* this level can be used for throttling.*/ | |
2392 | graphic_level->EnabledForThrottle = 1; | |
2393 | graphic_level->UpHyst = 0; | |
2394 | graphic_level->DownHyst = 0; | |
2395 | graphic_level->VoltageDownHyst = 0; | |
2396 | graphic_level->PowerThrottle = 0; | |
2397 | ||
2398 | threshold = engine_clock * data->fast_watemark_threshold / 100; | |
2399 | /* | |
2400 | *get the DAL clock. do it in funture. | |
2401 | PECI_GetMinClockSettings(hwmgr->peci, &minClocks); | |
2402 | data->display_timing.min_clock_insr = minClocks.engineClockInSR; | |
2403 | ||
2404 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep)) | |
2405 | { | |
2406 | graphic_level->DeepSleepDivId = PhwTonga_GetSleepDividerIdFromClock(hwmgr, engine_clock, minClocks.engineClockInSR); | |
2407 | } | |
2408 | */ | |
2409 | ||
2410 | /* Default to slow, highest DPM level will be set to PPSMC_DISPLAY_WATERMARK_LOW later.*/ | |
2411 | graphic_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW; | |
2412 | ||
2413 | if (0 == result) { | |
2414 | /* CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->MinVoltage);*/ | |
2415 | /* CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->MinVddcPhases);*/ | |
2416 | CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->SclkFrequency); | |
2417 | CONVERT_FROM_HOST_TO_SMC_US(graphic_level->ActivityLevel); | |
2418 | CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->CgSpllFuncCntl3); | |
2419 | CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->CgSpllFuncCntl4); | |
2420 | CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->SpllSpreadSpectrum); | |
2421 | CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->SpllSpreadSpectrum2); | |
2422 | CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->CcPwrDynRm); | |
2423 | CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->CcPwrDynRm1); | |
2424 | } | |
2425 | ||
2426 | return result; | |
2427 | } | |
2428 | ||
2429 | /** | |
2430 | * Populates all SMC SCLK levels' structure based on the trimmed allowed dpm engine clock states | |
2431 | * | |
2432 | * @param hwmgr the address of the hardware manager | |
2433 | */ | |
2434 | static int tonga_populate_all_graphic_levels(struct pp_hwmgr *hwmgr) | |
2435 | { | |
2436 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
2437 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
2438 | struct tonga_dpm_table *dpm_table = &data->dpm_table; | |
2439 | phm_ppt_v1_pcie_table *pcie_table = pptable_info->pcie_table; | |
2440 | uint8_t pcie_entry_count = (uint8_t) data->dpm_table.pcie_speed_table.count; | |
2441 | int result = 0; | |
2442 | uint32_t level_array_adress = data->dpm_table_start + | |
2443 | offsetof(SMU72_Discrete_DpmTable, GraphicsLevel); | |
2444 | uint32_t level_array_size = sizeof(SMU72_Discrete_GraphicsLevel) * | |
2445 | SMU72_MAX_LEVELS_GRAPHICS; /* 64 -> long; 32 -> int*/ | |
2446 | SMU72_Discrete_GraphicsLevel *levels = data->smc_state_table.GraphicsLevel; | |
2447 | uint32_t i, maxEntry; | |
2448 | uint8_t highest_pcie_level_enabled = 0, lowest_pcie_level_enabled = 0, mid_pcie_level_enabled = 0, count = 0; | |
2449 | PECI_RegistryValue reg_value; | |
2450 | memset(levels, 0x00, level_array_size); | |
2451 | ||
2452 | for (i = 0; i < dpm_table->sclk_table.count; i++) { | |
2453 | result = tonga_populate_single_graphic_level(hwmgr, | |
2454 | dpm_table->sclk_table.dpm_levels[i].value, | |
2455 | (uint16_t)data->activity_target[i], | |
2456 | &(data->smc_state_table.GraphicsLevel[i])); | |
2457 | ||
2458 | if (0 != result) | |
2459 | return result; | |
2460 | ||
2461 | /* Making sure only DPM level 0-1 have Deep Sleep Div ID populated. */ | |
2462 | if (i > 1) | |
2463 | data->smc_state_table.GraphicsLevel[i].DeepSleepDivId = 0; | |
2464 | ||
2465 | if (0 == i) { | |
2466 | reg_value = 0; | |
2467 | if (reg_value != 0) | |
2468 | data->smc_state_table.GraphicsLevel[0].UpHyst = (uint8_t)reg_value; | |
2469 | } | |
2470 | ||
2471 | if (1 == i) { | |
2472 | reg_value = 0; | |
2473 | if (reg_value != 0) | |
2474 | data->smc_state_table.GraphicsLevel[1].UpHyst = (uint8_t)reg_value; | |
2475 | } | |
2476 | } | |
2477 | ||
2478 | /* Only enable level 0 for now. */ | |
2479 | data->smc_state_table.GraphicsLevel[0].EnabledForActivity = 1; | |
2480 | ||
2481 | /* set highest level watermark to high */ | |
2482 | if (dpm_table->sclk_table.count > 1) | |
2483 | data->smc_state_table.GraphicsLevel[dpm_table->sclk_table.count-1].DisplayWatermark = | |
2484 | PPSMC_DISPLAY_WATERMARK_HIGH; | |
2485 | ||
2486 | data->smc_state_table.GraphicsDpmLevelCount = | |
2487 | (uint8_t)dpm_table->sclk_table.count; | |
2488 | data->dpm_level_enable_mask.sclk_dpm_enable_mask = | |
2489 | tonga_get_dpm_level_enable_mask_value(&dpm_table->sclk_table); | |
2490 | ||
2491 | if (pcie_table != NULL) { | |
2492 | PP_ASSERT_WITH_CODE((pcie_entry_count >= 1), | |
2493 | "There must be 1 or more PCIE levels defined in PPTable.", return -1); | |
2494 | maxEntry = pcie_entry_count - 1; /* for indexing, we need to decrement by 1.*/ | |
2495 | for (i = 0; i < dpm_table->sclk_table.count; i++) { | |
2496 | data->smc_state_table.GraphicsLevel[i].pcieDpmLevel = | |
2497 | (uint8_t) ((i < maxEntry) ? i : maxEntry); | |
2498 | } | |
2499 | } else { | |
2500 | if (0 == data->dpm_level_enable_mask.pcie_dpm_enable_mask) | |
2501 | printk(KERN_ERR "[ powerplay ] Pcie Dpm Enablemask is 0!"); | |
2502 | ||
2503 | while (data->dpm_level_enable_mask.pcie_dpm_enable_mask && | |
2504 | ((data->dpm_level_enable_mask.pcie_dpm_enable_mask & | |
2505 | (1<<(highest_pcie_level_enabled+1))) != 0)) { | |
2506 | highest_pcie_level_enabled++; | |
2507 | } | |
2508 | ||
2509 | while (data->dpm_level_enable_mask.pcie_dpm_enable_mask && | |
2510 | ((data->dpm_level_enable_mask.pcie_dpm_enable_mask & | |
2511 | (1<<lowest_pcie_level_enabled)) == 0)) { | |
2512 | lowest_pcie_level_enabled++; | |
2513 | } | |
2514 | ||
2515 | while ((count < highest_pcie_level_enabled) && | |
2516 | ((data->dpm_level_enable_mask.pcie_dpm_enable_mask & | |
2517 | (1<<(lowest_pcie_level_enabled+1+count))) == 0)) { | |
2518 | count++; | |
2519 | } | |
2520 | mid_pcie_level_enabled = (lowest_pcie_level_enabled+1+count) < highest_pcie_level_enabled ? | |
2521 | (lowest_pcie_level_enabled+1+count) : highest_pcie_level_enabled; | |
2522 | ||
2523 | ||
2524 | /* set pcieDpmLevel to highest_pcie_level_enabled*/ | |
2525 | for (i = 2; i < dpm_table->sclk_table.count; i++) { | |
2526 | data->smc_state_table.GraphicsLevel[i].pcieDpmLevel = highest_pcie_level_enabled; | |
2527 | } | |
2528 | ||
2529 | /* set pcieDpmLevel to lowest_pcie_level_enabled*/ | |
2530 | data->smc_state_table.GraphicsLevel[0].pcieDpmLevel = lowest_pcie_level_enabled; | |
2531 | ||
2532 | /* set pcieDpmLevel to mid_pcie_level_enabled*/ | |
2533 | data->smc_state_table.GraphicsLevel[1].pcieDpmLevel = mid_pcie_level_enabled; | |
2534 | } | |
2535 | /* level count will send to smc once at init smc table and never change*/ | |
2536 | result = tonga_copy_bytes_to_smc(hwmgr->smumgr, level_array_adress, (uint8_t *)levels, (uint32_t)level_array_size, data->sram_end); | |
2537 | ||
2538 | if (0 != result) | |
2539 | return result; | |
2540 | ||
2541 | return 0; | |
2542 | } | |
2543 | ||
2544 | /** | |
2545 | * Populates all SMC MCLK levels' structure based on the trimmed allowed dpm memory clock states | |
2546 | * | |
2547 | * @param hwmgr the address of the hardware manager | |
2548 | */ | |
2549 | ||
2550 | static int tonga_populate_all_memory_levels(struct pp_hwmgr *hwmgr) | |
2551 | { | |
2552 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
2553 | struct tonga_dpm_table *dpm_table = &data->dpm_table; | |
2554 | int result; | |
2555 | /* populate MCLK dpm table to SMU7 */ | |
2556 | uint32_t level_array_adress = data->dpm_table_start + offsetof(SMU72_Discrete_DpmTable, MemoryLevel); | |
2557 | uint32_t level_array_size = sizeof(SMU72_Discrete_MemoryLevel) * SMU72_MAX_LEVELS_MEMORY; | |
2558 | SMU72_Discrete_MemoryLevel *levels = data->smc_state_table.MemoryLevel; | |
2559 | uint32_t i; | |
2560 | ||
2561 | memset(levels, 0x00, level_array_size); | |
2562 | ||
2563 | for (i = 0; i < dpm_table->mclk_table.count; i++) { | |
2564 | PP_ASSERT_WITH_CODE((0 != dpm_table->mclk_table.dpm_levels[i].value), | |
2565 | "can not populate memory level as memory clock is zero", return -1); | |
2566 | result = tonga_populate_single_memory_level(hwmgr, dpm_table->mclk_table.dpm_levels[i].value, | |
2567 | &(data->smc_state_table.MemoryLevel[i])); | |
2568 | if (0 != result) { | |
2569 | return result; | |
2570 | } | |
2571 | } | |
2572 | ||
2573 | /* Only enable level 0 for now.*/ | |
2574 | data->smc_state_table.MemoryLevel[0].EnabledForActivity = 1; | |
2575 | ||
2576 | /* | |
2577 | * in order to prevent MC activity from stutter mode to push DPM up. | |
2578 | * the UVD change complements this by putting the MCLK in a higher state | |
2579 | * by default such that we are not effected by up threshold or and MCLK DPM latency. | |
2580 | */ | |
2581 | data->smc_state_table.MemoryLevel[0].ActivityLevel = 0x1F; | |
2582 | CONVERT_FROM_HOST_TO_SMC_US(data->smc_state_table.MemoryLevel[0].ActivityLevel); | |
2583 | ||
2584 | data->smc_state_table.MemoryDpmLevelCount = (uint8_t)dpm_table->mclk_table.count; | |
2585 | data->dpm_level_enable_mask.mclk_dpm_enable_mask = tonga_get_dpm_level_enable_mask_value(&dpm_table->mclk_table); | |
2586 | /* set highest level watermark to high*/ | |
2587 | data->smc_state_table.MemoryLevel[dpm_table->mclk_table.count-1].DisplayWatermark = PPSMC_DISPLAY_WATERMARK_HIGH; | |
2588 | ||
2589 | /* level count will send to smc once at init smc table and never change*/ | |
2590 | result = tonga_copy_bytes_to_smc(hwmgr->smumgr, | |
2591 | level_array_adress, (uint8_t *)levels, (uint32_t)level_array_size, data->sram_end); | |
2592 | ||
2593 | if (0 != result) { | |
2594 | return result; | |
2595 | } | |
2596 | ||
2597 | return 0; | |
2598 | } | |
2599 | ||
2600 | struct TONGA_DLL_SPEED_SETTING { | |
2601 | uint16_t Min; /* Minimum Data Rate*/ | |
2602 | uint16_t Max; /* Maximum Data Rate*/ | |
2603 | uint32_t dll_speed; /* The desired DLL_SPEED setting*/ | |
2604 | }; | |
2605 | ||
2606 | static int tonga_populate_clock_stretcher_data_table(struct pp_hwmgr *hwmgr) | |
2607 | { | |
2608 | return 0; | |
2609 | } | |
2610 | ||
2611 | /* ---------------------------------------- ULV related functions ----------------------------------------------------*/ | |
2612 | ||
2613 | ||
2614 | static int tonga_reset_single_dpm_table( | |
2615 | struct pp_hwmgr *hwmgr, | |
2616 | struct tonga_single_dpm_table *dpm_table, | |
2617 | uint32_t count) | |
2618 | { | |
2619 | uint32_t i; | |
2620 | if (!(count <= MAX_REGULAR_DPM_NUMBER)) | |
2621 | printk(KERN_ERR "[ powerplay ] Fatal error, can not set up single DPM \ | |
2622 | table entries to exceed max number! \n"); | |
2623 | ||
2624 | dpm_table->count = count; | |
2625 | for (i = 0; i < MAX_REGULAR_DPM_NUMBER; i++) { | |
2626 | dpm_table->dpm_levels[i].enabled = 0; | |
2627 | } | |
2628 | ||
2629 | return 0; | |
2630 | } | |
2631 | ||
2632 | static void tonga_setup_pcie_table_entry( | |
2633 | struct tonga_single_dpm_table *dpm_table, | |
2634 | uint32_t index, uint32_t pcie_gen, | |
2635 | uint32_t pcie_lanes) | |
2636 | { | |
2637 | dpm_table->dpm_levels[index].value = pcie_gen; | |
2638 | dpm_table->dpm_levels[index].param1 = pcie_lanes; | |
2639 | dpm_table->dpm_levels[index].enabled = 1; | |
2640 | } | |
2641 | ||
2642 | bool is_pcie_gen3_supported(uint32_t pcie_link_speed_cap) | |
2643 | { | |
2644 | if (pcie_link_speed_cap & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3) | |
2645 | return 1; | |
2646 | ||
2647 | return 0; | |
2648 | } | |
2649 | ||
2650 | bool is_pcie_gen2_supported(uint32_t pcie_link_speed_cap) | |
2651 | { | |
2652 | if (pcie_link_speed_cap & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2) | |
2653 | return 1; | |
2654 | ||
2655 | return 0; | |
2656 | } | |
2657 | ||
2658 | /* Get the new PCIE speed given the ASIC PCIE Cap and the NewState's requested PCIE speed*/ | |
2659 | uint16_t get_pcie_gen_support(uint32_t pcie_link_speed_cap, uint16_t ns_pcie_gen) | |
2660 | { | |
2661 | uint32_t asic_pcie_link_speed_cap = (pcie_link_speed_cap & | |
2662 | CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_MASK); | |
2663 | uint32_t sys_pcie_link_speed_cap = (pcie_link_speed_cap & | |
2664 | CAIL_PCIE_LINK_SPEED_SUPPORT_MASK); | |
2665 | ||
2666 | switch (asic_pcie_link_speed_cap) { | |
2667 | case CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1: | |
2668 | return PP_PCIEGen1; | |
2669 | ||
2670 | case CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2: | |
2671 | return PP_PCIEGen2; | |
2672 | ||
2673 | case CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3: | |
2674 | return PP_PCIEGen3; | |
2675 | ||
2676 | default: | |
2677 | if (is_pcie_gen3_supported(sys_pcie_link_speed_cap) && | |
2678 | (ns_pcie_gen == PP_PCIEGen3)) { | |
2679 | return PP_PCIEGen3; | |
2680 | } else if (is_pcie_gen2_supported(sys_pcie_link_speed_cap) && | |
2681 | ((ns_pcie_gen == PP_PCIEGen3) || (ns_pcie_gen == PP_PCIEGen2))) { | |
2682 | return PP_PCIEGen2; | |
2683 | } | |
2684 | } | |
2685 | ||
2686 | return PP_PCIEGen1; | |
2687 | } | |
2688 | ||
2689 | uint16_t get_pcie_lane_support(uint32_t pcie_lane_width_cap, uint16_t ns_pcie_lanes) | |
2690 | { | |
2691 | int i, j; | |
2692 | uint16_t new_pcie_lanes = ns_pcie_lanes; | |
2693 | uint16_t pcie_lanes[7] = {1, 2, 4, 8, 12, 16, 32}; | |
2694 | ||
2695 | switch (pcie_lane_width_cap) { | |
2696 | case 0: | |
2697 | printk(KERN_ERR "[ powerplay ] No valid PCIE lane width reported by CAIL!"); | |
2698 | break; | |
2699 | case CAIL_PCIE_LINK_WIDTH_SUPPORT_X1: | |
2700 | new_pcie_lanes = 1; | |
2701 | break; | |
2702 | case CAIL_PCIE_LINK_WIDTH_SUPPORT_X2: | |
2703 | new_pcie_lanes = 2; | |
2704 | break; | |
2705 | case CAIL_PCIE_LINK_WIDTH_SUPPORT_X4: | |
2706 | new_pcie_lanes = 4; | |
2707 | break; | |
2708 | case CAIL_PCIE_LINK_WIDTH_SUPPORT_X8: | |
2709 | new_pcie_lanes = 8; | |
2710 | break; | |
2711 | case CAIL_PCIE_LINK_WIDTH_SUPPORT_X12: | |
2712 | new_pcie_lanes = 12; | |
2713 | break; | |
2714 | case CAIL_PCIE_LINK_WIDTH_SUPPORT_X16: | |
2715 | new_pcie_lanes = 16; | |
2716 | break; | |
2717 | case CAIL_PCIE_LINK_WIDTH_SUPPORT_X32: | |
2718 | new_pcie_lanes = 32; | |
2719 | break; | |
2720 | default: | |
2721 | for (i = 0; i < 7; i++) { | |
2722 | if (ns_pcie_lanes == pcie_lanes[i]) { | |
2723 | if (pcie_lane_width_cap & (0x10000 << i)) { | |
2724 | break; | |
2725 | } else { | |
2726 | for (j = i - 1; j >= 0; j--) { | |
2727 | if (pcie_lane_width_cap & (0x10000 << j)) { | |
2728 | new_pcie_lanes = pcie_lanes[j]; | |
2729 | break; | |
2730 | } | |
2731 | } | |
2732 | ||
2733 | if (j < 0) { | |
2734 | for (j = i + 1; j < 7; j++) { | |
2735 | if (pcie_lane_width_cap & (0x10000 << j)) { | |
2736 | new_pcie_lanes = pcie_lanes[j]; | |
2737 | break; | |
2738 | } | |
2739 | } | |
2740 | if (j > 7) | |
2741 | printk(KERN_ERR "[ powerplay ] Cannot find a valid PCIE lane width!"); | |
2742 | } | |
2743 | } | |
2744 | break; | |
2745 | } | |
2746 | } | |
2747 | break; | |
2748 | } | |
2749 | ||
2750 | return new_pcie_lanes; | |
2751 | } | |
2752 | ||
2753 | static int tonga_setup_default_pcie_tables(struct pp_hwmgr *hwmgr) | |
2754 | { | |
2755 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
2756 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
2757 | phm_ppt_v1_pcie_table *pcie_table = pptable_info->pcie_table; | |
2758 | uint32_t i, maxEntry; | |
2759 | ||
2760 | if (data->use_pcie_performance_levels && !data->use_pcie_power_saving_levels) { | |
2761 | data->pcie_gen_power_saving = data->pcie_gen_performance; | |
2762 | data->pcie_lane_power_saving = data->pcie_lane_performance; | |
2763 | } else if (!data->use_pcie_performance_levels && data->use_pcie_power_saving_levels) { | |
2764 | data->pcie_gen_performance = data->pcie_gen_power_saving; | |
2765 | data->pcie_lane_performance = data->pcie_lane_power_saving; | |
2766 | } | |
2767 | ||
2768 | tonga_reset_single_dpm_table(hwmgr, &data->dpm_table.pcie_speed_table, SMU72_MAX_LEVELS_LINK); | |
2769 | ||
2770 | if (pcie_table != NULL) { | |
2771 | /* | |
2772 | * maxEntry is used to make sure we reserve one PCIE level for boot level (fix for A+A PSPP issue). | |
2773 | * If PCIE table from PPTable have ULV entry + 8 entries, then ignore the last entry. | |
2774 | */ | |
2775 | maxEntry = (SMU72_MAX_LEVELS_LINK < pcie_table->count) ? | |
2776 | SMU72_MAX_LEVELS_LINK : pcie_table->count; | |
2777 | for (i = 1; i < maxEntry; i++) { | |
2778 | tonga_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, i-1, | |
2779 | get_pcie_gen_support(data->pcie_gen_cap, pcie_table->entries[i].gen_speed), | |
2780 | get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane)); | |
2781 | } | |
2782 | data->dpm_table.pcie_speed_table.count = maxEntry - 1; | |
2783 | } else { | |
2784 | /* Hardcode Pcie Table */ | |
2785 | tonga_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 0, | |
2786 | get_pcie_gen_support(data->pcie_gen_cap, PP_Min_PCIEGen), | |
2787 | get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane)); | |
2788 | tonga_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 1, | |
2789 | get_pcie_gen_support(data->pcie_gen_cap, PP_Min_PCIEGen), | |
2790 | get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane)); | |
2791 | tonga_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 2, | |
2792 | get_pcie_gen_support(data->pcie_gen_cap, PP_Max_PCIEGen), | |
2793 | get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane)); | |
2794 | tonga_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 3, | |
2795 | get_pcie_gen_support(data->pcie_gen_cap, PP_Max_PCIEGen), | |
2796 | get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane)); | |
2797 | tonga_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 4, | |
2798 | get_pcie_gen_support(data->pcie_gen_cap, PP_Max_PCIEGen), | |
2799 | get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane)); | |
2800 | tonga_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 5, | |
2801 | get_pcie_gen_support(data->pcie_gen_cap, PP_Max_PCIEGen), | |
2802 | get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane)); | |
2803 | data->dpm_table.pcie_speed_table.count = 6; | |
2804 | } | |
2805 | /* Populate last level for boot PCIE level, but do not increment count. */ | |
2806 | tonga_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, | |
2807 | data->dpm_table.pcie_speed_table.count, | |
2808 | get_pcie_gen_support(data->pcie_gen_cap, PP_Min_PCIEGen), | |
2809 | get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane)); | |
2810 | ||
2811 | return 0; | |
2812 | ||
2813 | } | |
2814 | ||
2815 | /* | |
2816 | * This function is to initalize all DPM state tables for SMU7 based on the dependency table. | |
2817 | * Dynamic state patching function will then trim these state tables to the allowed range based | |
2818 | * on the power policy or external client requests, such as UVD request, etc. | |
2819 | */ | |
2820 | static int tonga_setup_default_dpm_tables(struct pp_hwmgr *hwmgr) | |
2821 | { | |
2822 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
2823 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
2824 | uint32_t i; | |
2825 | ||
2826 | phm_ppt_v1_clock_voltage_dependency_table *allowed_vdd_sclk_table = | |
2827 | pptable_info->vdd_dep_on_sclk; | |
2828 | phm_ppt_v1_clock_voltage_dependency_table *allowed_vdd_mclk_table = | |
2829 | pptable_info->vdd_dep_on_mclk; | |
2830 | ||
2831 | PP_ASSERT_WITH_CODE(allowed_vdd_sclk_table != NULL, | |
2832 | "SCLK dependency table is missing. This table is mandatory", return -1); | |
2833 | PP_ASSERT_WITH_CODE(allowed_vdd_sclk_table->count >= 1, | |
2834 | "SCLK dependency table has to have is missing. This table is mandatory", return -1); | |
2835 | ||
2836 | PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table != NULL, | |
2837 | "MCLK dependency table is missing. This table is mandatory", return -1); | |
2838 | PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table->count >= 1, | |
2839 | "VMCLK dependency table has to have is missing. This table is mandatory", return -1); | |
2840 | ||
2841 | /* clear the state table to reset everything to default */ | |
2842 | memset(&(data->dpm_table), 0x00, sizeof(data->dpm_table)); | |
2843 | tonga_reset_single_dpm_table(hwmgr, &data->dpm_table.sclk_table, SMU72_MAX_LEVELS_GRAPHICS); | |
2844 | tonga_reset_single_dpm_table(hwmgr, &data->dpm_table.mclk_table, SMU72_MAX_LEVELS_MEMORY); | |
2845 | /* tonga_reset_single_dpm_table(hwmgr, &tonga_hwmgr->dpm_table.VddcTable, SMU72_MAX_LEVELS_VDDC); */ | |
2846 | /* tonga_reset_single_dpm_table(hwmgr, &tonga_hwmgr->dpm_table.vdd_gfx_table, SMU72_MAX_LEVELS_VDDGFX);*/ | |
2847 | /* tonga_reset_single_dpm_table(hwmgr, &tonga_hwmgr->dpm_table.vdd_ci_table, SMU72_MAX_LEVELS_VDDCI);*/ | |
2848 | /* tonga_reset_single_dpm_table(hwmgr, &tonga_hwmgr->dpm_table.mvdd_table, SMU72_MAX_LEVELS_MVDD);*/ | |
2849 | ||
2850 | PP_ASSERT_WITH_CODE(allowed_vdd_sclk_table != NULL, | |
2851 | "SCLK dependency table is missing. This table is mandatory", return -1); | |
2852 | /* Initialize Sclk DPM table based on allow Sclk values*/ | |
2853 | data->dpm_table.sclk_table.count = 0; | |
2854 | ||
2855 | for (i = 0; i < allowed_vdd_sclk_table->count; i++) { | |
2856 | if (i == 0 || data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count-1].value != | |
2857 | allowed_vdd_sclk_table->entries[i].clk) { | |
2858 | data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].value = | |
2859 | allowed_vdd_sclk_table->entries[i].clk; | |
2860 | data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].enabled = 1; /*(i==0) ? 1 : 0; to do */ | |
2861 | data->dpm_table.sclk_table.count++; | |
2862 | } | |
2863 | } | |
2864 | ||
2865 | PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table != NULL, | |
2866 | "MCLK dependency table is missing. This table is mandatory", return -1); | |
2867 | /* Initialize Mclk DPM table based on allow Mclk values */ | |
2868 | data->dpm_table.mclk_table.count = 0; | |
2869 | for (i = 0; i < allowed_vdd_mclk_table->count; i++) { | |
2870 | if (i == 0 || data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count-1].value != | |
2871 | allowed_vdd_mclk_table->entries[i].clk) { | |
2872 | data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].value = | |
2873 | allowed_vdd_mclk_table->entries[i].clk; | |
2874 | data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].enabled = 1; /*(i==0) ? 1 : 0; */ | |
2875 | data->dpm_table.mclk_table.count++; | |
2876 | } | |
2877 | } | |
2878 | ||
2879 | /* Initialize Vddc DPM table based on allow Vddc values. And populate corresponding std values. */ | |
2880 | for (i = 0; i < allowed_vdd_sclk_table->count; i++) { | |
2881 | data->dpm_table.vddc_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].vddc; | |
2882 | /* tonga_hwmgr->dpm_table.VddcTable.dpm_levels[i].param1 = stdVoltageTable->entries[i].Leakage; */ | |
2883 | /* param1 is for corresponding std voltage */ | |
2884 | data->dpm_table.vddc_table.dpm_levels[i].enabled = 1; | |
2885 | } | |
2886 | data->dpm_table.vddc_table.count = allowed_vdd_sclk_table->count; | |
2887 | ||
2888 | if (NULL != allowed_vdd_mclk_table) { | |
2889 | /* Initialize Vddci DPM table based on allow Mclk values */ | |
2890 | for (i = 0; i < allowed_vdd_mclk_table->count; i++) { | |
2891 | data->dpm_table.vdd_ci_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].vddci; | |
2892 | data->dpm_table.vdd_ci_table.dpm_levels[i].enabled = 1; | |
2893 | data->dpm_table.mvdd_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].mvdd; | |
2894 | data->dpm_table.mvdd_table.dpm_levels[i].enabled = 1; | |
2895 | } | |
2896 | data->dpm_table.vdd_ci_table.count = allowed_vdd_mclk_table->count; | |
2897 | data->dpm_table.mvdd_table.count = allowed_vdd_mclk_table->count; | |
2898 | } | |
2899 | ||
2900 | /* setup PCIE gen speed levels*/ | |
2901 | tonga_setup_default_pcie_tables(hwmgr); | |
2902 | ||
2903 | /* save a copy of the default DPM table*/ | |
2904 | memcpy(&(data->golden_dpm_table), &(data->dpm_table), sizeof(struct tonga_dpm_table)); | |
2905 | ||
2906 | return 0; | |
2907 | } | |
2908 | ||
2909 | int tonga_populate_smc_initial_state(struct pp_hwmgr *hwmgr, | |
2910 | const struct tonga_power_state *bootState) | |
2911 | { | |
2912 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
2913 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
2914 | uint8_t count, level; | |
2915 | ||
2916 | count = (uint8_t) (pptable_info->vdd_dep_on_sclk->count); | |
2917 | for (level = 0; level < count; level++) { | |
2918 | if (pptable_info->vdd_dep_on_sclk->entries[level].clk >= | |
2919 | bootState->performance_levels[0].engine_clock) { | |
2920 | data->smc_state_table.GraphicsBootLevel = level; | |
2921 | break; | |
2922 | } | |
2923 | } | |
2924 | ||
2925 | count = (uint8_t) (pptable_info->vdd_dep_on_mclk->count); | |
2926 | for (level = 0; level < count; level++) { | |
2927 | if (pptable_info->vdd_dep_on_mclk->entries[level].clk >= | |
2928 | bootState->performance_levels[0].memory_clock) { | |
2929 | data->smc_state_table.MemoryBootLevel = level; | |
2930 | break; | |
2931 | } | |
2932 | } | |
2933 | ||
2934 | return 0; | |
2935 | } | |
2936 | ||
2937 | /** | |
2938 | * Initializes the SMC table and uploads it | |
2939 | * | |
2940 | * @param hwmgr the address of the powerplay hardware manager. | |
2941 | * @param pInput the pointer to input data (PowerState) | |
2942 | * @return always 0 | |
2943 | */ | |
2944 | int tonga_init_smc_table(struct pp_hwmgr *hwmgr) | |
2945 | { | |
2946 | int result; | |
2947 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
2948 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
2949 | SMU72_Discrete_DpmTable *table = &(data->smc_state_table); | |
2950 | const phw_tonga_ulv_parm *ulv = &(data->ulv); | |
2951 | uint8_t i; | |
2952 | PECI_RegistryValue reg_value; | |
2953 | pp_atomctrl_gpio_pin_assignment gpio_pin_assignment; | |
2954 | ||
2955 | result = tonga_setup_default_dpm_tables(hwmgr); | |
2956 | PP_ASSERT_WITH_CODE(0 == result, | |
2957 | "Failed to setup default DPM tables!", return result;); | |
2958 | memset(&(data->smc_state_table), 0x00, sizeof(data->smc_state_table)); | |
2959 | if (TONGA_VOLTAGE_CONTROL_NONE != data->voltage_control) { | |
2960 | tonga_populate_smc_voltage_tables(hwmgr, table); | |
2961 | } | |
2962 | ||
2963 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
2964 | PHM_PlatformCaps_AutomaticDCTransition)) { | |
2965 | table->SystemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC; | |
2966 | } | |
2967 | ||
2968 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
2969 | PHM_PlatformCaps_StepVddc)) { | |
2970 | table->SystemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC; | |
2971 | } | |
2972 | ||
2973 | if (data->is_memory_GDDR5) { | |
2974 | table->SystemFlags |= PPSMC_SYSTEMFLAG_GDDR5; | |
2975 | } | |
2976 | ||
2977 | i = PHM_READ_FIELD(hwmgr->device, CC_MC_MAX_CHANNEL, NOOFCHAN); | |
2978 | ||
2979 | if (i == 1 || i == 0) { | |
2980 | table->SystemFlags |= PPSMC_SYSTEMFLAG_12CHANNEL; | |
2981 | } | |
2982 | ||
2983 | if (ulv->ulv_supported && pptable_info->us_ulv_voltage_offset) { | |
2984 | PP_ASSERT_WITH_CODE(0 == result, | |
2985 | "Failed to initialize ULV state!", return result;); | |
2986 | ||
2987 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
2988 | ixCG_ULV_PARAMETER, ulv->ch_ulv_parameter); | |
2989 | } | |
2990 | ||
2991 | result = tonga_populate_smc_link_level(hwmgr, table); | |
2992 | PP_ASSERT_WITH_CODE(0 == result, | |
2993 | "Failed to initialize Link Level!", return result;); | |
2994 | ||
2995 | result = tonga_populate_all_graphic_levels(hwmgr); | |
2996 | PP_ASSERT_WITH_CODE(0 == result, | |
2997 | "Failed to initialize Graphics Level!", return result;); | |
2998 | ||
2999 | result = tonga_populate_all_memory_levels(hwmgr); | |
3000 | PP_ASSERT_WITH_CODE(0 == result, | |
3001 | "Failed to initialize Memory Level!", return result;); | |
3002 | ||
3003 | result = tonga_populate_smv_acpi_level(hwmgr, table); | |
3004 | PP_ASSERT_WITH_CODE(0 == result, | |
3005 | "Failed to initialize ACPI Level!", return result;); | |
3006 | ||
3007 | result = tonga_populate_smc_vce_level(hwmgr, table); | |
3008 | PP_ASSERT_WITH_CODE(0 == result, | |
3009 | "Failed to initialize VCE Level!", return result;); | |
3010 | ||
3011 | result = tonga_populate_smc_acp_level(hwmgr, table); | |
3012 | PP_ASSERT_WITH_CODE(0 == result, | |
3013 | "Failed to initialize ACP Level!", return result;); | |
3014 | ||
3015 | result = tonga_populate_smc_samu_level(hwmgr, table); | |
3016 | PP_ASSERT_WITH_CODE(0 == result, | |
3017 | "Failed to initialize SAMU Level!", return result;); | |
3018 | ||
3019 | /* Since only the initial state is completely set up at this point (the other states are just copies of the boot state) we only */ | |
3020 | /* need to populate the ARB settings for the initial state. */ | |
3021 | result = tonga_program_memory_timing_parameters(hwmgr); | |
3022 | PP_ASSERT_WITH_CODE(0 == result, | |
3023 | "Failed to Write ARB settings for the initial state.", return result;); | |
3024 | ||
3025 | result = tonga_populate_smc_boot_level(hwmgr, table); | |
3026 | PP_ASSERT_WITH_CODE(0 == result, | |
3027 | "Failed to initialize Boot Level!", return result;); | |
3028 | ||
3029 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
3030 | PHM_PlatformCaps_ClockStretcher)) { | |
3031 | result = tonga_populate_clock_stretcher_data_table(hwmgr); | |
3032 | PP_ASSERT_WITH_CODE(0 == result, | |
3033 | "Failed to populate Clock Stretcher Data Table!", return result;); | |
3034 | } | |
3035 | table->GraphicsVoltageChangeEnable = 1; | |
3036 | table->GraphicsThermThrottleEnable = 1; | |
3037 | table->GraphicsInterval = 1; | |
3038 | table->VoltageInterval = 1; | |
3039 | table->ThermalInterval = 1; | |
3040 | table->TemperatureLimitHigh = | |
3041 | pptable_info->cac_dtp_table->usTargetOperatingTemp * | |
3042 | TONGA_Q88_FORMAT_CONVERSION_UNIT; | |
3043 | table->TemperatureLimitLow = | |
3044 | (pptable_info->cac_dtp_table->usTargetOperatingTemp - 1) * | |
3045 | TONGA_Q88_FORMAT_CONVERSION_UNIT; | |
3046 | table->MemoryVoltageChangeEnable = 1; | |
3047 | table->MemoryInterval = 1; | |
3048 | table->VoltageResponseTime = 0; | |
3049 | table->PhaseResponseTime = 0; | |
3050 | table->MemoryThermThrottleEnable = 1; | |
3051 | ||
3052 | /* | |
3053 | * Cail reads current link status and reports it as cap (we cannot change this due to some previous issues we had) | |
3054 | * SMC drops the link status to lowest level after enabling DPM by PowerPlay. After pnp or toggling CF, driver gets reloaded again | |
3055 | * but this time Cail reads current link status which was set to low by SMC and reports it as cap to powerplay | |
3056 | * To avoid it, we set PCIeBootLinkLevel to highest dpm level | |
3057 | */ | |
3058 | PP_ASSERT_WITH_CODE((1 <= data->dpm_table.pcie_speed_table.count), | |
3059 | "There must be 1 or more PCIE levels defined in PPTable.", | |
3060 | return -1); | |
3061 | ||
3062 | table->PCIeBootLinkLevel = (uint8_t) (data->dpm_table.pcie_speed_table.count); | |
3063 | ||
3064 | table->PCIeGenInterval = 1; | |
3065 | ||
3066 | result = tonga_populate_vr_config(hwmgr, table); | |
3067 | PP_ASSERT_WITH_CODE(0 == result, | |
3068 | "Failed to populate VRConfig setting!", return result); | |
3069 | ||
3070 | table->ThermGpio = 17; | |
3071 | table->SclkStepSize = 0x4000; | |
3072 | ||
3073 | reg_value = 0; | |
3074 | if ((0 == reg_value) && | |
3075 | (0 == atomctrl_get_pp_assign_pin(hwmgr, | |
3076 | VDDC_VRHOT_GPIO_PINID, &gpio_pin_assignment))) { | |
3077 | table->VRHotGpio = gpio_pin_assignment.uc_gpio_pin_bit_shift; | |
3078 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
3079 | PHM_PlatformCaps_RegulatorHot); | |
3080 | } else { | |
3081 | table->VRHotGpio = TONGA_UNUSED_GPIO_PIN; | |
3082 | phm_cap_unset(hwmgr->platform_descriptor.platformCaps, | |
3083 | PHM_PlatformCaps_RegulatorHot); | |
3084 | } | |
3085 | ||
3086 | /* ACDC Switch GPIO */ | |
3087 | reg_value = 0; | |
3088 | if ((0 == reg_value) && | |
3089 | (0 == atomctrl_get_pp_assign_pin(hwmgr, | |
3090 | PP_AC_DC_SWITCH_GPIO_PINID, &gpio_pin_assignment))) { | |
3091 | table->AcDcGpio = gpio_pin_assignment.uc_gpio_pin_bit_shift; | |
3092 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
3093 | PHM_PlatformCaps_AutomaticDCTransition); | |
3094 | } else { | |
3095 | table->AcDcGpio = TONGA_UNUSED_GPIO_PIN; | |
3096 | phm_cap_unset(hwmgr->platform_descriptor.platformCaps, | |
3097 | PHM_PlatformCaps_AutomaticDCTransition); | |
3098 | } | |
3099 | ||
3100 | phm_cap_unset(hwmgr->platform_descriptor.platformCaps, | |
3101 | PHM_PlatformCaps_Falcon_QuickTransition); | |
3102 | ||
3103 | reg_value = 0; | |
3104 | if (1 == reg_value) { | |
3105 | phm_cap_unset(hwmgr->platform_descriptor.platformCaps, | |
3106 | PHM_PlatformCaps_AutomaticDCTransition); | |
3107 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
3108 | PHM_PlatformCaps_Falcon_QuickTransition); | |
3109 | } | |
3110 | ||
3111 | reg_value = 0; | |
3112 | if ((0 == reg_value) && | |
3113 | (0 == atomctrl_get_pp_assign_pin(hwmgr, | |
3114 | THERMAL_INT_OUTPUT_GPIO_PINID, &gpio_pin_assignment))) { | |
3115 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
3116 | PHM_PlatformCaps_ThermalOutGPIO); | |
3117 | ||
3118 | table->ThermOutGpio = gpio_pin_assignment.uc_gpio_pin_bit_shift; | |
3119 | ||
3120 | table->ThermOutPolarity = | |
3121 | (0 == (cgs_read_register(hwmgr->device, mmGPIOPAD_A) & | |
3122 | (1 << gpio_pin_assignment.uc_gpio_pin_bit_shift))) ? 1:0; | |
3123 | ||
3124 | table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_ONLY; | |
3125 | ||
3126 | /* if required, combine VRHot/PCC with thermal out GPIO*/ | |
3127 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
3128 | PHM_PlatformCaps_RegulatorHot) && | |
3129 | phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
3130 | PHM_PlatformCaps_CombinePCCWithThermalSignal)){ | |
3131 | table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_VRHOT; | |
3132 | } | |
3133 | } else { | |
3134 | phm_cap_unset(hwmgr->platform_descriptor.platformCaps, | |
3135 | PHM_PlatformCaps_ThermalOutGPIO); | |
3136 | ||
3137 | table->ThermOutGpio = 17; | |
3138 | table->ThermOutPolarity = 1; | |
3139 | table->ThermOutMode = SMU7_THERM_OUT_MODE_DISABLE; | |
3140 | } | |
3141 | ||
3142 | for (i = 0; i < SMU72_MAX_ENTRIES_SMIO; i++) { | |
3143 | table->Smio[i] = PP_HOST_TO_SMC_UL(table->Smio[i]); | |
3144 | } | |
3145 | CONVERT_FROM_HOST_TO_SMC_UL(table->SystemFlags); | |
3146 | CONVERT_FROM_HOST_TO_SMC_UL(table->VRConfig); | |
3147 | CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask1); | |
3148 | CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask2); | |
3149 | CONVERT_FROM_HOST_TO_SMC_UL(table->SclkStepSize); | |
3150 | CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitHigh); | |
3151 | CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitLow); | |
3152 | CONVERT_FROM_HOST_TO_SMC_US(table->VoltageResponseTime); | |
3153 | CONVERT_FROM_HOST_TO_SMC_US(table->PhaseResponseTime); | |
3154 | ||
3155 | /* Upload all dpm data to SMC memory.(dpm level, dpm level count etc) */ | |
3156 | result = tonga_copy_bytes_to_smc(hwmgr->smumgr, data->dpm_table_start + | |
3157 | offsetof(SMU72_Discrete_DpmTable, SystemFlags), | |
3158 | (uint8_t *)&(table->SystemFlags), | |
3159 | sizeof(SMU72_Discrete_DpmTable)-3 * sizeof(SMU72_PIDController), | |
3160 | data->sram_end); | |
3161 | ||
3162 | PP_ASSERT_WITH_CODE(0 == result, | |
3163 | "Failed to upload dpm data to SMC memory!", return result;); | |
3164 | ||
3165 | return result; | |
3166 | } | |
3167 | ||
3168 | /* Look up the voltaged based on DAL's requested level. and then send the requested VDDC voltage to SMC*/ | |
3169 | static void tonga_apply_dal_minimum_voltage_request(struct pp_hwmgr *hwmgr) | |
3170 | { | |
3171 | return; | |
3172 | } | |
3173 | ||
3174 | int tonga_upload_dpm_level_enable_mask(struct pp_hwmgr *hwmgr) | |
3175 | { | |
3176 | PPSMC_Result result; | |
3177 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
3178 | ||
3179 | /* Apply minimum voltage based on DAL's request level */ | |
3180 | tonga_apply_dal_minimum_voltage_request(hwmgr); | |
3181 | ||
3182 | if (0 == data->sclk_dpm_key_disabled) { | |
3183 | /* Checking if DPM is running. If we discover hang because of this, we should skip this message.*/ | |
3184 | if (0 != tonga_is_dpm_running(hwmgr)) | |
3185 | printk(KERN_ERR "[ powerplay ] Trying to set Enable Mask when DPM is disabled \n"); | |
3186 | ||
3187 | if (0 != data->dpm_level_enable_mask.sclk_dpm_enable_mask) { | |
3188 | result = smum_send_msg_to_smc_with_parameter( | |
3189 | hwmgr->smumgr, | |
3190 | (PPSMC_Msg)PPSMC_MSG_SCLKDPM_SetEnabledMask, | |
3191 | data->dpm_level_enable_mask.sclk_dpm_enable_mask); | |
3192 | PP_ASSERT_WITH_CODE((0 == result), | |
3193 | "Set Sclk Dpm enable Mask failed", return -1); | |
3194 | } | |
3195 | } | |
3196 | ||
3197 | if (0 == data->mclk_dpm_key_disabled) { | |
3198 | /* Checking if DPM is running. If we discover hang because of this, we should skip this message.*/ | |
3199 | if (0 != tonga_is_dpm_running(hwmgr)) | |
3200 | printk(KERN_ERR "[ powerplay ] Trying to set Enable Mask when DPM is disabled \n"); | |
3201 | ||
3202 | if (0 != data->dpm_level_enable_mask.mclk_dpm_enable_mask) { | |
3203 | result = smum_send_msg_to_smc_with_parameter( | |
3204 | hwmgr->smumgr, | |
3205 | (PPSMC_Msg)PPSMC_MSG_MCLKDPM_SetEnabledMask, | |
3206 | data->dpm_level_enable_mask.mclk_dpm_enable_mask); | |
3207 | PP_ASSERT_WITH_CODE((0 == result), | |
3208 | "Set Mclk Dpm enable Mask failed", return -1); | |
3209 | } | |
3210 | } | |
3211 | ||
3212 | return 0; | |
3213 | } | |
3214 | ||
3215 | ||
3216 | int tonga_force_dpm_highest(struct pp_hwmgr *hwmgr) | |
3217 | { | |
3218 | uint32_t level, tmp; | |
3219 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
3220 | ||
3221 | if (0 == data->pcie_dpm_key_disabled) { | |
3222 | /* PCIE */ | |
3223 | if (data->dpm_level_enable_mask.pcie_dpm_enable_mask != 0) { | |
3224 | level = 0; | |
3225 | tmp = data->dpm_level_enable_mask.pcie_dpm_enable_mask; | |
3226 | while (tmp >>= 1) | |
3227 | level++ ; | |
3228 | ||
3229 | if (0 != level) { | |
3230 | PP_ASSERT_WITH_CODE((0 == tonga_dpm_force_state_pcie(hwmgr, level)), | |
3231 | "force highest pcie dpm state failed!", return -1); | |
3232 | } | |
3233 | } | |
3234 | } | |
3235 | ||
3236 | if (0 == data->sclk_dpm_key_disabled) { | |
3237 | /* SCLK */ | |
3238 | if (data->dpm_level_enable_mask.sclk_dpm_enable_mask != 0) { | |
3239 | level = 0; | |
3240 | tmp = data->dpm_level_enable_mask.sclk_dpm_enable_mask; | |
3241 | while (tmp >>= 1) | |
3242 | level++ ; | |
3243 | ||
3244 | if (0 != level) { | |
3245 | PP_ASSERT_WITH_CODE((0 == tonga_dpm_force_state(hwmgr, level)), | |
3246 | "force highest sclk dpm state failed!", return -1); | |
3247 | if (PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, | |
3248 | CGS_IND_REG__SMC, TARGET_AND_CURRENT_PROFILE_INDEX, CURR_SCLK_INDEX) != level) | |
3249 | printk(KERN_ERR "[ powerplay ] Target_and_current_Profile_Index. \ | |
3250 | Curr_Sclk_Index does not match the level \n"); | |
3251 | ||
3252 | } | |
3253 | } | |
3254 | } | |
3255 | ||
3256 | if (0 == data->mclk_dpm_key_disabled) { | |
3257 | /* MCLK */ | |
3258 | if (data->dpm_level_enable_mask.mclk_dpm_enable_mask != 0) { | |
3259 | level = 0; | |
3260 | tmp = data->dpm_level_enable_mask.mclk_dpm_enable_mask; | |
3261 | while (tmp >>= 1) | |
3262 | level++ ; | |
3263 | ||
3264 | if (0 != level) { | |
3265 | PP_ASSERT_WITH_CODE((0 == tonga_dpm_force_state_mclk(hwmgr, level)), | |
3266 | "force highest mclk dpm state failed!", return -1); | |
3267 | if (PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, | |
3268 | TARGET_AND_CURRENT_PROFILE_INDEX, CURR_MCLK_INDEX) != level) | |
3269 | printk(KERN_ERR "[ powerplay ] Target_and_current_Profile_Index. \ | |
3270 | Curr_Sclk_Index does not match the level \n"); | |
3271 | } | |
3272 | } | |
3273 | } | |
3274 | ||
3275 | return 0; | |
3276 | } | |
3277 | ||
3278 | /** | |
3279 | * Find the MC microcode version and store it in the HwMgr struct | |
3280 | * | |
3281 | * @param hwmgr the address of the powerplay hardware manager. | |
3282 | * @return always 0 | |
3283 | */ | |
3284 | int tonga_get_mc_microcode_version (struct pp_hwmgr *hwmgr) | |
3285 | { | |
3286 | cgs_write_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_INDEX, 0x9F); | |
3287 | ||
3288 | hwmgr->microcode_version_info.MC = cgs_read_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_DATA); | |
3289 | ||
3290 | return 0; | |
3291 | } | |
3292 | ||
3293 | /** | |
3294 | * Initialize Dynamic State Adjustment Rule Settings | |
3295 | * | |
3296 | * @param hwmgr the address of the powerplay hardware manager. | |
3297 | */ | |
3298 | int tonga_initializa_dynamic_state_adjustment_rule_settings(struct pp_hwmgr *hwmgr) | |
3299 | { | |
3300 | uint32_t table_size; | |
3301 | struct phm_clock_voltage_dependency_table *table_clk_vlt; | |
3302 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
3303 | ||
3304 | hwmgr->dyn_state.mclk_sclk_ratio = 4; | |
3305 | hwmgr->dyn_state.sclk_mclk_delta = 15000; /* 150 MHz */ | |
3306 | hwmgr->dyn_state.vddc_vddci_delta = 200; /* 200mV */ | |
3307 | ||
3308 | /* initialize vddc_dep_on_dal_pwrl table */ | |
3309 | table_size = sizeof(uint32_t) + 4 * sizeof(struct phm_clock_voltage_dependency_record); | |
3310 | table_clk_vlt = (struct phm_clock_voltage_dependency_table *)kzalloc(table_size, GFP_KERNEL); | |
3311 | ||
3312 | if (NULL == table_clk_vlt) { | |
3313 | printk(KERN_ERR "[ powerplay ] Can not allocate space for vddc_dep_on_dal_pwrl! \n"); | |
3314 | return -ENOMEM; | |
3315 | } else { | |
3316 | table_clk_vlt->count = 4; | |
3317 | table_clk_vlt->entries[0].clk = PP_DAL_POWERLEVEL_ULTRALOW; | |
3318 | table_clk_vlt->entries[0].v = 0; | |
3319 | table_clk_vlt->entries[1].clk = PP_DAL_POWERLEVEL_LOW; | |
3320 | table_clk_vlt->entries[1].v = 720; | |
3321 | table_clk_vlt->entries[2].clk = PP_DAL_POWERLEVEL_NOMINAL; | |
3322 | table_clk_vlt->entries[2].v = 810; | |
3323 | table_clk_vlt->entries[3].clk = PP_DAL_POWERLEVEL_PERFORMANCE; | |
3324 | table_clk_vlt->entries[3].v = 900; | |
3325 | pptable_info->vddc_dep_on_dal_pwrl = table_clk_vlt; | |
3326 | hwmgr->dyn_state.vddc_dep_on_dal_pwrl = table_clk_vlt; | |
3327 | } | |
3328 | ||
3329 | return 0; | |
3330 | } | |
3331 | ||
3332 | static int tonga_set_private_var_based_on_pptale(struct pp_hwmgr *hwmgr) | |
3333 | { | |
3334 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
3335 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
3336 | ||
3337 | phm_ppt_v1_clock_voltage_dependency_table *allowed_sclk_vdd_table = | |
3338 | pptable_info->vdd_dep_on_sclk; | |
3339 | phm_ppt_v1_clock_voltage_dependency_table *allowed_mclk_vdd_table = | |
3340 | pptable_info->vdd_dep_on_mclk; | |
3341 | ||
3342 | PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table != NULL, | |
3343 | "VDD dependency on SCLK table is missing. \ | |
3344 | This table is mandatory", return -1); | |
3345 | PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table->count >= 1, | |
3346 | "VDD dependency on SCLK table has to have is missing. \ | |
3347 | This table is mandatory", return -1); | |
3348 | ||
3349 | PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table != NULL, | |
3350 | "VDD dependency on MCLK table is missing. \ | |
3351 | This table is mandatory", return -1); | |
3352 | PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table->count >= 1, | |
3353 | "VDD dependency on MCLK table has to have is missing. \ | |
3354 | This table is mandatory", return -1); | |
3355 | ||
3356 | data->min_vddc_in_pp_table = (uint16_t)allowed_sclk_vdd_table->entries[0].vddc; | |
3357 | data->max_vddc_in_pp_table = (uint16_t)allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].vddc; | |
3358 | ||
3359 | pptable_info->max_clock_voltage_on_ac.sclk = | |
3360 | allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].clk; | |
3361 | pptable_info->max_clock_voltage_on_ac.mclk = | |
3362 | allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].clk; | |
3363 | pptable_info->max_clock_voltage_on_ac.vddc = | |
3364 | allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].vddc; | |
3365 | pptable_info->max_clock_voltage_on_ac.vddci = | |
3366 | allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].vddci; | |
3367 | ||
3368 | hwmgr->dyn_state.max_clock_voltage_on_ac.sclk = | |
3369 | pptable_info->max_clock_voltage_on_ac.sclk; | |
3370 | hwmgr->dyn_state.max_clock_voltage_on_ac.mclk = | |
3371 | pptable_info->max_clock_voltage_on_ac.mclk; | |
3372 | hwmgr->dyn_state.max_clock_voltage_on_ac.vddc = | |
3373 | pptable_info->max_clock_voltage_on_ac.vddc; | |
3374 | hwmgr->dyn_state.max_clock_voltage_on_ac.vddci = | |
3375 | pptable_info->max_clock_voltage_on_ac.vddci; | |
3376 | ||
3377 | return 0; | |
3378 | } | |
3379 | ||
3380 | int tonga_unforce_dpm_levels(struct pp_hwmgr *hwmgr) | |
3381 | { | |
3382 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
3383 | int result = 1; | |
3384 | ||
3385 | PP_ASSERT_WITH_CODE (0 == tonga_is_dpm_running(hwmgr), | |
3386 | "Trying to Unforce DPM when DPM is disabled. Returning without sending SMC message.", | |
3387 | return result); | |
3388 | ||
3389 | if (0 == data->pcie_dpm_key_disabled) { | |
3390 | PP_ASSERT_WITH_CODE((0 == smum_send_msg_to_smc( | |
3391 | hwmgr->smumgr, | |
3392 | PPSMC_MSG_PCIeDPM_UnForceLevel)), | |
3393 | "unforce pcie level failed!", | |
3394 | return -1); | |
3395 | } | |
3396 | ||
3397 | result = tonga_upload_dpm_level_enable_mask(hwmgr); | |
3398 | ||
3399 | return result; | |
3400 | } | |
3401 | ||
3402 | static uint32_t tonga_get_lowest_enable_level( | |
3403 | struct pp_hwmgr *hwmgr, uint32_t level_mask) | |
3404 | { | |
3405 | uint32_t level = 0; | |
3406 | ||
3407 | while (0 == (level_mask & (1 << level))) | |
3408 | level++; | |
3409 | ||
3410 | return level; | |
3411 | } | |
3412 | ||
3413 | static int tonga_force_dpm_lowest(struct pp_hwmgr *hwmgr) | |
3414 | { | |
3415 | uint32_t level = 0; | |
3416 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
3417 | ||
3418 | /* for now force only sclk */ | |
3419 | if (0 != data->dpm_level_enable_mask.sclk_dpm_enable_mask) { | |
3420 | level = tonga_get_lowest_enable_level(hwmgr, | |
3421 | data->dpm_level_enable_mask.sclk_dpm_enable_mask); | |
3422 | ||
3423 | PP_ASSERT_WITH_CODE((0 == tonga_dpm_force_state(hwmgr, level)), | |
3424 | "force sclk dpm state failed!", return -1); | |
3425 | ||
3426 | if (PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, | |
3427 | CGS_IND_REG__SMC, TARGET_AND_CURRENT_PROFILE_INDEX, CURR_SCLK_INDEX) != level) | |
3428 | printk(KERN_ERR "[ powerplay ] Target_and_current_Profile_Index. \ | |
3429 | Curr_Sclk_Index does not match the level \n"); | |
3430 | } | |
3431 | ||
3432 | return 0; | |
3433 | } | |
3434 | ||
3435 | static int tonga_patch_voltage_dependency_tables_with_lookup_table(struct pp_hwmgr *hwmgr) | |
3436 | { | |
3437 | uint8_t entryId; | |
3438 | uint8_t voltageId; | |
3439 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
3440 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
3441 | ||
3442 | phm_ppt_v1_clock_voltage_dependency_table *sclk_table = pptable_info->vdd_dep_on_sclk; | |
3443 | phm_ppt_v1_clock_voltage_dependency_table *mclk_table = pptable_info->vdd_dep_on_mclk; | |
3444 | phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table = pptable_info->mm_dep_table; | |
3445 | ||
3446 | if (data->vdd_gfx_control == TONGA_VOLTAGE_CONTROL_BY_SVID2) { | |
3447 | for (entryId = 0; entryId < sclk_table->count; ++entryId) { | |
3448 | voltageId = sclk_table->entries[entryId].vddInd; | |
3449 | sclk_table->entries[entryId].vddgfx = | |
3450 | pptable_info->vddgfx_lookup_table->entries[voltageId].us_vdd; | |
3451 | } | |
3452 | } else { | |
3453 | for (entryId = 0; entryId < sclk_table->count; ++entryId) { | |
3454 | voltageId = sclk_table->entries[entryId].vddInd; | |
3455 | sclk_table->entries[entryId].vddc = | |
3456 | pptable_info->vddc_lookup_table->entries[voltageId].us_vdd; | |
3457 | } | |
3458 | } | |
3459 | ||
3460 | for (entryId = 0; entryId < mclk_table->count; ++entryId) { | |
3461 | voltageId = mclk_table->entries[entryId].vddInd; | |
3462 | mclk_table->entries[entryId].vddc = | |
3463 | pptable_info->vddc_lookup_table->entries[voltageId].us_vdd; | |
3464 | } | |
3465 | ||
3466 | for (entryId = 0; entryId < mm_table->count; ++entryId) { | |
3467 | voltageId = mm_table->entries[entryId].vddcInd; | |
3468 | mm_table->entries[entryId].vddc = | |
3469 | pptable_info->vddc_lookup_table->entries[voltageId].us_vdd; | |
3470 | } | |
3471 | ||
3472 | return 0; | |
3473 | ||
3474 | } | |
3475 | ||
3476 | static int tonga_calc_voltage_dependency_tables(struct pp_hwmgr *hwmgr) | |
3477 | { | |
3478 | uint8_t entryId; | |
3479 | phm_ppt_v1_voltage_lookup_record v_record; | |
3480 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
3481 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
3482 | ||
3483 | phm_ppt_v1_clock_voltage_dependency_table *sclk_table = pptable_info->vdd_dep_on_sclk; | |
3484 | phm_ppt_v1_clock_voltage_dependency_table *mclk_table = pptable_info->vdd_dep_on_mclk; | |
3485 | ||
3486 | if (data->vdd_gfx_control == TONGA_VOLTAGE_CONTROL_BY_SVID2) { | |
3487 | for (entryId = 0; entryId < sclk_table->count; ++entryId) { | |
3488 | if (sclk_table->entries[entryId].vdd_offset & (1 << 15)) | |
3489 | v_record.us_vdd = sclk_table->entries[entryId].vddgfx + | |
3490 | sclk_table->entries[entryId].vdd_offset - 0xFFFF; | |
3491 | else | |
3492 | v_record.us_vdd = sclk_table->entries[entryId].vddgfx + | |
3493 | sclk_table->entries[entryId].vdd_offset; | |
3494 | ||
3495 | sclk_table->entries[entryId].vddc = | |
3496 | v_record.us_cac_low = v_record.us_cac_mid = | |
3497 | v_record.us_cac_high = v_record.us_vdd; | |
3498 | ||
3499 | tonga_add_voltage(hwmgr, pptable_info->vddc_lookup_table, &v_record); | |
3500 | } | |
3501 | ||
3502 | for (entryId = 0; entryId < mclk_table->count; ++entryId) { | |
3503 | if (mclk_table->entries[entryId].vdd_offset & (1 << 15)) | |
3504 | v_record.us_vdd = mclk_table->entries[entryId].vddc + | |
3505 | mclk_table->entries[entryId].vdd_offset - 0xFFFF; | |
3506 | else | |
3507 | v_record.us_vdd = mclk_table->entries[entryId].vddc + | |
3508 | mclk_table->entries[entryId].vdd_offset; | |
3509 | ||
3510 | mclk_table->entries[entryId].vddgfx = v_record.us_cac_low = | |
3511 | v_record.us_cac_mid = v_record.us_cac_high = v_record.us_vdd; | |
3512 | tonga_add_voltage(hwmgr, pptable_info->vddgfx_lookup_table, &v_record); | |
3513 | } | |
3514 | } | |
3515 | ||
3516 | return 0; | |
3517 | ||
3518 | } | |
3519 | ||
3520 | static int tonga_calc_mm_voltage_dependency_table(struct pp_hwmgr *hwmgr) | |
3521 | { | |
3522 | uint32_t entryId; | |
3523 | phm_ppt_v1_voltage_lookup_record v_record; | |
3524 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
3525 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
3526 | phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table = pptable_info->mm_dep_table; | |
3527 | ||
3528 | if (data->vdd_gfx_control == TONGA_VOLTAGE_CONTROL_BY_SVID2) { | |
3529 | for (entryId = 0; entryId < mm_table->count; entryId++) { | |
3530 | if (mm_table->entries[entryId].vddgfx_offset & (1 << 15)) | |
3531 | v_record.us_vdd = mm_table->entries[entryId].vddc + | |
3532 | mm_table->entries[entryId].vddgfx_offset - 0xFFFF; | |
3533 | else | |
3534 | v_record.us_vdd = mm_table->entries[entryId].vddc + | |
3535 | mm_table->entries[entryId].vddgfx_offset; | |
3536 | ||
3537 | /* Add the calculated VDDGFX to the VDDGFX lookup table */ | |
3538 | mm_table->entries[entryId].vddgfx = v_record.us_cac_low = | |
3539 | v_record.us_cac_mid = v_record.us_cac_high = v_record.us_vdd; | |
3540 | tonga_add_voltage(hwmgr, pptable_info->vddgfx_lookup_table, &v_record); | |
3541 | } | |
3542 | } | |
3543 | return 0; | |
3544 | } | |
3545 | ||
3546 | ||
3547 | /** | |
3548 | * Change virtual leakage voltage to actual value. | |
3549 | * | |
3550 | * @param hwmgr the address of the powerplay hardware manager. | |
3551 | * @param pointer to changing voltage | |
3552 | * @param pointer to leakage table | |
3553 | */ | |
3554 | static void tonga_patch_with_vdd_leakage(struct pp_hwmgr *hwmgr, | |
3555 | uint16_t *voltage, phw_tonga_leakage_voltage *pLeakageTable) | |
3556 | { | |
3557 | uint32_t leakage_index; | |
3558 | ||
3559 | /* search for leakage voltage ID 0xff01 ~ 0xff08 */ | |
3560 | for (leakage_index = 0; leakage_index < pLeakageTable->count; leakage_index++) { | |
3561 | /* if this voltage matches a leakage voltage ID */ | |
3562 | /* patch with actual leakage voltage */ | |
3563 | if (pLeakageTable->leakage_id[leakage_index] == *voltage) { | |
3564 | *voltage = pLeakageTable->actual_voltage[leakage_index]; | |
3565 | break; | |
3566 | } | |
3567 | } | |
3568 | ||
3569 | if (*voltage > ATOM_VIRTUAL_VOLTAGE_ID0) | |
3570 | printk(KERN_ERR "[ powerplay ] Voltage value looks like a Leakage ID but it's not patched \n"); | |
3571 | } | |
3572 | ||
3573 | /** | |
3574 | * Patch voltage lookup table by EVV leakages. | |
3575 | * | |
3576 | * @param hwmgr the address of the powerplay hardware manager. | |
3577 | * @param pointer to voltage lookup table | |
3578 | * @param pointer to leakage table | |
3579 | * @return always 0 | |
3580 | */ | |
3581 | static int tonga_patch_lookup_table_with_leakage(struct pp_hwmgr *hwmgr, | |
3582 | phm_ppt_v1_voltage_lookup_table *lookup_table, | |
3583 | phw_tonga_leakage_voltage *pLeakageTable) | |
3584 | { | |
3585 | uint32_t i; | |
3586 | ||
3587 | for (i = 0; i < lookup_table->count; i++) { | |
3588 | tonga_patch_with_vdd_leakage(hwmgr, | |
3589 | &lookup_table->entries[i].us_vdd, pLeakageTable); | |
3590 | } | |
3591 | ||
3592 | return 0; | |
3593 | } | |
3594 | ||
3595 | static int tonga_patch_clock_voltage_lomits_with_vddc_leakage(struct pp_hwmgr *hwmgr, | |
3596 | phw_tonga_leakage_voltage *pLeakageTable, uint16_t *Vddc) | |
3597 | { | |
3598 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
3599 | ||
3600 | tonga_patch_with_vdd_leakage(hwmgr, (uint16_t *)Vddc, pLeakageTable); | |
3601 | hwmgr->dyn_state.max_clock_voltage_on_dc.vddc = | |
3602 | pptable_info->max_clock_voltage_on_dc.vddc; | |
3603 | ||
3604 | return 0; | |
3605 | } | |
3606 | ||
3607 | static int tonga_patch_clock_voltage_limits_with_vddgfx_leakage( | |
3608 | struct pp_hwmgr *hwmgr, phw_tonga_leakage_voltage *pLeakageTable, | |
3609 | uint16_t *Vddgfx) | |
3610 | { | |
3611 | tonga_patch_with_vdd_leakage(hwmgr, (uint16_t *)Vddgfx, pLeakageTable); | |
3612 | return 0; | |
3613 | } | |
3614 | ||
3615 | int tonga_sort_lookup_table(struct pp_hwmgr *hwmgr, | |
3616 | phm_ppt_v1_voltage_lookup_table *lookup_table) | |
3617 | { | |
3618 | uint32_t table_size, i, j; | |
3619 | phm_ppt_v1_voltage_lookup_record tmp_voltage_lookup_record; | |
3620 | table_size = lookup_table->count; | |
3621 | ||
3622 | PP_ASSERT_WITH_CODE(0 != lookup_table->count, | |
3623 | "Lookup table is empty", return -1); | |
3624 | ||
3625 | /* Sorting voltages */ | |
3626 | for (i = 0; i < table_size - 1; i++) { | |
3627 | for (j = i + 1; j > 0; j--) { | |
3628 | if (lookup_table->entries[j].us_vdd < lookup_table->entries[j-1].us_vdd) { | |
3629 | tmp_voltage_lookup_record = lookup_table->entries[j-1]; | |
3630 | lookup_table->entries[j-1] = lookup_table->entries[j]; | |
3631 | lookup_table->entries[j] = tmp_voltage_lookup_record; | |
3632 | } | |
3633 | } | |
3634 | } | |
3635 | ||
3636 | return 0; | |
3637 | } | |
3638 | ||
3639 | static int tonga_complete_dependency_tables(struct pp_hwmgr *hwmgr) | |
3640 | { | |
3641 | int result = 0; | |
3642 | int tmp_result; | |
3643 | tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
3644 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
3645 | ||
3646 | if (data->vdd_gfx_control == TONGA_VOLTAGE_CONTROL_BY_SVID2) { | |
3647 | tmp_result = tonga_patch_lookup_table_with_leakage(hwmgr, | |
3648 | pptable_info->vddgfx_lookup_table, &(data->vddcgfx_leakage)); | |
3649 | if (tmp_result != 0) | |
3650 | result = tmp_result; | |
3651 | ||
3652 | tmp_result = tonga_patch_clock_voltage_limits_with_vddgfx_leakage(hwmgr, | |
3653 | &(data->vddcgfx_leakage), &pptable_info->max_clock_voltage_on_dc.vddgfx); | |
3654 | if (tmp_result != 0) | |
3655 | result = tmp_result; | |
3656 | } else { | |
3657 | tmp_result = tonga_patch_lookup_table_with_leakage(hwmgr, | |
3658 | pptable_info->vddc_lookup_table, &(data->vddc_leakage)); | |
3659 | if (tmp_result != 0) | |
3660 | result = tmp_result; | |
3661 | ||
3662 | tmp_result = tonga_patch_clock_voltage_lomits_with_vddc_leakage(hwmgr, | |
3663 | &(data->vddc_leakage), &pptable_info->max_clock_voltage_on_dc.vddc); | |
3664 | if (tmp_result != 0) | |
3665 | result = tmp_result; | |
3666 | } | |
3667 | ||
3668 | tmp_result = tonga_patch_voltage_dependency_tables_with_lookup_table(hwmgr); | |
3669 | if (tmp_result != 0) | |
3670 | result = tmp_result; | |
3671 | ||
3672 | tmp_result = tonga_calc_voltage_dependency_tables(hwmgr); | |
3673 | if (tmp_result != 0) | |
3674 | result = tmp_result; | |
3675 | ||
3676 | tmp_result = tonga_calc_mm_voltage_dependency_table(hwmgr); | |
3677 | if (tmp_result != 0) | |
3678 | result = tmp_result; | |
3679 | ||
3680 | tmp_result = tonga_sort_lookup_table(hwmgr, pptable_info->vddgfx_lookup_table); | |
3681 | if (tmp_result != 0) | |
3682 | result = tmp_result; | |
3683 | ||
3684 | tmp_result = tonga_sort_lookup_table(hwmgr, pptable_info->vddc_lookup_table); | |
3685 | if (tmp_result != 0) | |
3686 | result = tmp_result; | |
3687 | ||
3688 | return result; | |
3689 | } | |
3690 | ||
3691 | int tonga_init_sclk_threshold(struct pp_hwmgr *hwmgr) | |
3692 | { | |
3693 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
3694 | data->low_sclk_interrupt_threshold = 0; | |
3695 | ||
3696 | return 0; | |
3697 | } | |
3698 | ||
3699 | int tonga_setup_asic_task(struct pp_hwmgr *hwmgr) | |
3700 | { | |
3701 | int tmp_result, result = 0; | |
3702 | ||
3703 | tmp_result = tonga_read_clock_registers(hwmgr); | |
3704 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
3705 | "Failed to read clock registers!", result = tmp_result); | |
3706 | ||
3707 | tmp_result = tonga_get_memory_type(hwmgr); | |
3708 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
3709 | "Failed to get memory type!", result = tmp_result); | |
3710 | ||
3711 | tmp_result = tonga_enable_acpi_power_management(hwmgr); | |
3712 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
3713 | "Failed to enable ACPI power management!", result = tmp_result); | |
3714 | ||
3715 | tmp_result = tonga_init_power_gate_state(hwmgr); | |
3716 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
3717 | "Failed to init power gate state!", result = tmp_result); | |
3718 | ||
3719 | tmp_result = tonga_get_mc_microcode_version(hwmgr); | |
3720 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
3721 | "Failed to get MC microcode version!", result = tmp_result); | |
3722 | ||
3723 | tmp_result = tonga_init_sclk_threshold(hwmgr); | |
3724 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
3725 | "Failed to init sclk threshold!", result = tmp_result); | |
3726 | ||
3727 | return result; | |
3728 | } | |
3729 | ||
3730 | /** | |
3731 | * Enable voltage control | |
3732 | * | |
3733 | * @param hwmgr the address of the powerplay hardware manager. | |
3734 | * @return always 0 | |
3735 | */ | |
3736 | int tonga_enable_voltage_control(struct pp_hwmgr *hwmgr) | |
3737 | { | |
3738 | /* enable voltage control */ | |
3739 | PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT, VOLT_PWRMGT_EN, 1); | |
3740 | ||
3741 | return 0; | |
3742 | } | |
3743 | ||
3744 | /** | |
3745 | * Checks if we want to support voltage control | |
3746 | * | |
3747 | * @param hwmgr the address of the powerplay hardware manager. | |
3748 | */ | |
3749 | bool cf_tonga_voltage_control(const struct pp_hwmgr *hwmgr) | |
3750 | { | |
3751 | const struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
3752 | ||
3753 | return(TONGA_VOLTAGE_CONTROL_NONE != data->voltage_control); | |
3754 | } | |
3755 | ||
3756 | /*---------------------------MC----------------------------*/ | |
3757 | ||
3758 | uint8_t tonga_get_memory_modile_index(struct pp_hwmgr *hwmgr) | |
3759 | { | |
3760 | return (uint8_t) (0xFF & (cgs_read_register(hwmgr->device, mmBIOS_SCRATCH_4) >> 16)); | |
3761 | } | |
3762 | ||
3763 | bool tonga_check_s0_mc_reg_index(uint16_t inReg, uint16_t *outReg) | |
3764 | { | |
3765 | bool result = 1; | |
3766 | ||
3767 | switch (inReg) { | |
3768 | case mmMC_SEQ_RAS_TIMING: | |
3769 | *outReg = mmMC_SEQ_RAS_TIMING_LP; | |
3770 | break; | |
3771 | ||
3772 | case mmMC_SEQ_DLL_STBY: | |
3773 | *outReg = mmMC_SEQ_DLL_STBY_LP; | |
3774 | break; | |
3775 | ||
3776 | case mmMC_SEQ_G5PDX_CMD0: | |
3777 | *outReg = mmMC_SEQ_G5PDX_CMD0_LP; | |
3778 | break; | |
3779 | ||
3780 | case mmMC_SEQ_G5PDX_CMD1: | |
3781 | *outReg = mmMC_SEQ_G5PDX_CMD1_LP; | |
3782 | break; | |
3783 | ||
3784 | case mmMC_SEQ_G5PDX_CTRL: | |
3785 | *outReg = mmMC_SEQ_G5PDX_CTRL_LP; | |
3786 | break; | |
3787 | ||
3788 | case mmMC_SEQ_CAS_TIMING: | |
3789 | *outReg = mmMC_SEQ_CAS_TIMING_LP; | |
3790 | break; | |
3791 | ||
3792 | case mmMC_SEQ_MISC_TIMING: | |
3793 | *outReg = mmMC_SEQ_MISC_TIMING_LP; | |
3794 | break; | |
3795 | ||
3796 | case mmMC_SEQ_MISC_TIMING2: | |
3797 | *outReg = mmMC_SEQ_MISC_TIMING2_LP; | |
3798 | break; | |
3799 | ||
3800 | case mmMC_SEQ_PMG_DVS_CMD: | |
3801 | *outReg = mmMC_SEQ_PMG_DVS_CMD_LP; | |
3802 | break; | |
3803 | ||
3804 | case mmMC_SEQ_PMG_DVS_CTL: | |
3805 | *outReg = mmMC_SEQ_PMG_DVS_CTL_LP; | |
3806 | break; | |
3807 | ||
3808 | case mmMC_SEQ_RD_CTL_D0: | |
3809 | *outReg = mmMC_SEQ_RD_CTL_D0_LP; | |
3810 | break; | |
3811 | ||
3812 | case mmMC_SEQ_RD_CTL_D1: | |
3813 | *outReg = mmMC_SEQ_RD_CTL_D1_LP; | |
3814 | break; | |
3815 | ||
3816 | case mmMC_SEQ_WR_CTL_D0: | |
3817 | *outReg = mmMC_SEQ_WR_CTL_D0_LP; | |
3818 | break; | |
3819 | ||
3820 | case mmMC_SEQ_WR_CTL_D1: | |
3821 | *outReg = mmMC_SEQ_WR_CTL_D1_LP; | |
3822 | break; | |
3823 | ||
3824 | case mmMC_PMG_CMD_EMRS: | |
3825 | *outReg = mmMC_SEQ_PMG_CMD_EMRS_LP; | |
3826 | break; | |
3827 | ||
3828 | case mmMC_PMG_CMD_MRS: | |
3829 | *outReg = mmMC_SEQ_PMG_CMD_MRS_LP; | |
3830 | break; | |
3831 | ||
3832 | case mmMC_PMG_CMD_MRS1: | |
3833 | *outReg = mmMC_SEQ_PMG_CMD_MRS1_LP; | |
3834 | break; | |
3835 | ||
3836 | case mmMC_SEQ_PMG_TIMING: | |
3837 | *outReg = mmMC_SEQ_PMG_TIMING_LP; | |
3838 | break; | |
3839 | ||
3840 | case mmMC_PMG_CMD_MRS2: | |
3841 | *outReg = mmMC_SEQ_PMG_CMD_MRS2_LP; | |
3842 | break; | |
3843 | ||
3844 | case mmMC_SEQ_WR_CTL_2: | |
3845 | *outReg = mmMC_SEQ_WR_CTL_2_LP; | |
3846 | break; | |
3847 | ||
3848 | default: | |
3849 | result = 0; | |
3850 | break; | |
3851 | } | |
3852 | ||
3853 | return result; | |
3854 | } | |
3855 | ||
3856 | int tonga_set_s0_mc_reg_index(phw_tonga_mc_reg_table *table) | |
3857 | { | |
3858 | uint32_t i; | |
3859 | uint16_t address; | |
3860 | ||
3861 | for (i = 0; i < table->last; i++) { | |
3862 | table->mc_reg_address[i].s0 = | |
3863 | tonga_check_s0_mc_reg_index(table->mc_reg_address[i].s1, &address) | |
3864 | ? address : table->mc_reg_address[i].s1; | |
3865 | } | |
3866 | return 0; | |
3867 | } | |
3868 | ||
3869 | int tonga_copy_vbios_smc_reg_table(const pp_atomctrl_mc_reg_table *table, phw_tonga_mc_reg_table *ni_table) | |
3870 | { | |
3871 | uint8_t i, j; | |
3872 | ||
3873 | PP_ASSERT_WITH_CODE((table->last <= SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE), | |
3874 | "Invalid VramInfo table.", return -1); | |
3875 | PP_ASSERT_WITH_CODE((table->num_entries <= MAX_AC_TIMING_ENTRIES), | |
3876 | "Invalid VramInfo table.", return -1); | |
3877 | ||
3878 | for (i = 0; i < table->last; i++) { | |
3879 | ni_table->mc_reg_address[i].s1 = table->mc_reg_address[i].s1; | |
3880 | } | |
3881 | ni_table->last = table->last; | |
3882 | ||
3883 | for (i = 0; i < table->num_entries; i++) { | |
3884 | ni_table->mc_reg_table_entry[i].mclk_max = | |
3885 | table->mc_reg_table_entry[i].mclk_max; | |
3886 | for (j = 0; j < table->last; j++) { | |
3887 | ni_table->mc_reg_table_entry[i].mc_data[j] = | |
3888 | table->mc_reg_table_entry[i].mc_data[j]; | |
3889 | } | |
3890 | } | |
3891 | ni_table->num_entries = table->num_entries; | |
3892 | ||
3893 | return 0; | |
3894 | } | |
3895 | ||
3896 | /** | |
3897 | * VBIOS omits some information to reduce size, we need to recover them here. | |
3898 | * 1. when we see mmMC_SEQ_MISC1, bit[31:16] EMRS1, need to be write to mmMC_PMG_CMD_EMRS /_LP[15:0]. | |
3899 | * Bit[15:0] MRS, need to be update mmMC_PMG_CMD_MRS/_LP[15:0] | |
3900 | * 2. when we see mmMC_SEQ_RESERVE_M, bit[15:0] EMRS2, need to be write to mmMC_PMG_CMD_MRS1/_LP[15:0]. | |
3901 | * 3. need to set these data for each clock range | |
3902 | * | |
3903 | * @param hwmgr the address of the powerplay hardware manager. | |
3904 | * @param table the address of MCRegTable | |
3905 | * @return always 0 | |
3906 | */ | |
3907 | int tonga_set_mc_special_registers(struct pp_hwmgr *hwmgr, phw_tonga_mc_reg_table *table) | |
3908 | { | |
3909 | uint8_t i, j, k; | |
3910 | uint32_t temp_reg; | |
3911 | const tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
3912 | ||
3913 | for (i = 0, j = table->last; i < table->last; i++) { | |
3914 | PP_ASSERT_WITH_CODE((j < SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE), | |
3915 | "Invalid VramInfo table.", return -1); | |
3916 | switch (table->mc_reg_address[i].s1) { | |
3917 | /* | |
3918 | * mmMC_SEQ_MISC1, bit[31:16] EMRS1, need to be write to mmMC_PMG_CMD_EMRS /_LP[15:0]. | |
3919 | * Bit[15:0] MRS, need to be update mmMC_PMG_CMD_MRS/_LP[15:0] | |
3920 | */ | |
3921 | case mmMC_SEQ_MISC1: | |
3922 | temp_reg = cgs_read_register(hwmgr->device, mmMC_PMG_CMD_EMRS); | |
3923 | table->mc_reg_address[j].s1 = mmMC_PMG_CMD_EMRS; | |
3924 | table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_EMRS_LP; | |
3925 | for (k = 0; k < table->num_entries; k++) { | |
3926 | table->mc_reg_table_entry[k].mc_data[j] = | |
3927 | ((temp_reg & 0xffff0000)) | | |
3928 | ((table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16); | |
3929 | } | |
3930 | j++; | |
3931 | PP_ASSERT_WITH_CODE((j < SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE), | |
3932 | "Invalid VramInfo table.", return -1); | |
3933 | ||
3934 | temp_reg = cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS); | |
3935 | table->mc_reg_address[j].s1 = mmMC_PMG_CMD_MRS; | |
3936 | table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_MRS_LP; | |
3937 | for (k = 0; k < table->num_entries; k++) { | |
3938 | table->mc_reg_table_entry[k].mc_data[j] = | |
3939 | (temp_reg & 0xffff0000) | | |
3940 | (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff); | |
3941 | ||
3942 | if (!data->is_memory_GDDR5) { | |
3943 | table->mc_reg_table_entry[k].mc_data[j] |= 0x100; | |
3944 | } | |
3945 | } | |
3946 | j++; | |
3947 | PP_ASSERT_WITH_CODE((j <= SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE), | |
3948 | "Invalid VramInfo table.", return -1); | |
3949 | ||
3950 | if (!data->is_memory_GDDR5) { | |
3951 | table->mc_reg_address[j].s1 = mmMC_PMG_AUTO_CMD; | |
3952 | table->mc_reg_address[j].s0 = mmMC_PMG_AUTO_CMD; | |
3953 | for (k = 0; k < table->num_entries; k++) { | |
3954 | table->mc_reg_table_entry[k].mc_data[j] = | |
3955 | (table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16; | |
3956 | } | |
3957 | j++; | |
3958 | PP_ASSERT_WITH_CODE((j <= SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE), | |
3959 | "Invalid VramInfo table.", return -1); | |
3960 | } | |
3961 | ||
3962 | break; | |
3963 | ||
3964 | case mmMC_SEQ_RESERVE_M: | |
3965 | temp_reg = cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS1); | |
3966 | table->mc_reg_address[j].s1 = mmMC_PMG_CMD_MRS1; | |
3967 | table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_MRS1_LP; | |
3968 | for (k = 0; k < table->num_entries; k++) { | |
3969 | table->mc_reg_table_entry[k].mc_data[j] = | |
3970 | (temp_reg & 0xffff0000) | | |
3971 | (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff); | |
3972 | } | |
3973 | j++; | |
3974 | PP_ASSERT_WITH_CODE((j <= SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE), | |
3975 | "Invalid VramInfo table.", return -1); | |
3976 | break; | |
3977 | ||
3978 | default: | |
3979 | break; | |
3980 | } | |
3981 | ||
3982 | } | |
3983 | ||
3984 | table->last = j; | |
3985 | ||
3986 | return 0; | |
3987 | } | |
3988 | ||
3989 | int tonga_set_valid_flag(phw_tonga_mc_reg_table *table) | |
3990 | { | |
3991 | uint8_t i, j; | |
3992 | for (i = 0; i < table->last; i++) { | |
3993 | for (j = 1; j < table->num_entries; j++) { | |
3994 | if (table->mc_reg_table_entry[j-1].mc_data[i] != | |
3995 | table->mc_reg_table_entry[j].mc_data[i]) { | |
3996 | table->validflag |= (1<<i); | |
3997 | break; | |
3998 | } | |
3999 | } | |
4000 | } | |
4001 | ||
4002 | return 0; | |
4003 | } | |
4004 | ||
4005 | int tonga_initialize_mc_reg_table(struct pp_hwmgr *hwmgr) | |
4006 | { | |
4007 | int result; | |
4008 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
4009 | pp_atomctrl_mc_reg_table *table; | |
4010 | phw_tonga_mc_reg_table *ni_table = &data->tonga_mc_reg_table; | |
4011 | uint8_t module_index = tonga_get_memory_modile_index(hwmgr); | |
4012 | ||
4013 | table = kzalloc(sizeof(pp_atomctrl_mc_reg_table), GFP_KERNEL); | |
4014 | ||
4015 | if (NULL == table) | |
4016 | return -1; | |
4017 | ||
4018 | /* Program additional LP registers that are no longer programmed by VBIOS */ | |
4019 | cgs_write_register(hwmgr->device, mmMC_SEQ_RAS_TIMING_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_RAS_TIMING)); | |
4020 | cgs_write_register(hwmgr->device, mmMC_SEQ_CAS_TIMING_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_CAS_TIMING)); | |
4021 | cgs_write_register(hwmgr->device, mmMC_SEQ_DLL_STBY_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_DLL_STBY)); | |
4022 | cgs_write_register(hwmgr->device, mmMC_SEQ_G5PDX_CMD0_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_G5PDX_CMD0)); | |
4023 | cgs_write_register(hwmgr->device, mmMC_SEQ_G5PDX_CMD1_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_G5PDX_CMD1)); | |
4024 | cgs_write_register(hwmgr->device, mmMC_SEQ_G5PDX_CTRL_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_G5PDX_CTRL)); | |
4025 | cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_DVS_CMD_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_PMG_DVS_CMD)); | |
4026 | cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_DVS_CTL_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_PMG_DVS_CTL)); | |
4027 | cgs_write_register(hwmgr->device, mmMC_SEQ_MISC_TIMING_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_MISC_TIMING)); | |
4028 | cgs_write_register(hwmgr->device, mmMC_SEQ_MISC_TIMING2_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_MISC_TIMING2)); | |
4029 | cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_CMD_EMRS_LP, cgs_read_register(hwmgr->device, mmMC_PMG_CMD_EMRS)); | |
4030 | cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_CMD_MRS_LP, cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS)); | |
4031 | cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_CMD_MRS1_LP, cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS1)); | |
4032 | cgs_write_register(hwmgr->device, mmMC_SEQ_WR_CTL_D0_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_WR_CTL_D0)); | |
4033 | cgs_write_register(hwmgr->device, mmMC_SEQ_WR_CTL_D1_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_WR_CTL_D1)); | |
4034 | cgs_write_register(hwmgr->device, mmMC_SEQ_RD_CTL_D0_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_RD_CTL_D0)); | |
4035 | cgs_write_register(hwmgr->device, mmMC_SEQ_RD_CTL_D1_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_RD_CTL_D1)); | |
4036 | cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_TIMING_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_PMG_TIMING)); | |
4037 | cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_CMD_MRS2_LP, cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS2)); | |
4038 | cgs_write_register(hwmgr->device, mmMC_SEQ_WR_CTL_2_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_WR_CTL_2)); | |
4039 | ||
4040 | memset(table, 0x00, sizeof(pp_atomctrl_mc_reg_table)); | |
4041 | ||
4042 | result = atomctrl_initialize_mc_reg_table(hwmgr, module_index, table); | |
4043 | ||
4044 | if (0 == result) | |
4045 | result = tonga_copy_vbios_smc_reg_table(table, ni_table); | |
4046 | ||
4047 | if (0 == result) { | |
4048 | tonga_set_s0_mc_reg_index(ni_table); | |
4049 | result = tonga_set_mc_special_registers(hwmgr, ni_table); | |
4050 | } | |
4051 | ||
4052 | if (0 == result) | |
4053 | tonga_set_valid_flag(ni_table); | |
4054 | ||
4055 | kfree(table); | |
4056 | return result; | |
4057 | } | |
4058 | ||
4059 | /* | |
4060 | * Copy one arb setting to another and then switch the active set. | |
4061 | * arbFreqSrc and arbFreqDest is one of the MC_CG_ARB_FREQ_Fx constants. | |
4062 | */ | |
4063 | int tonga_copy_and_switch_arb_sets(struct pp_hwmgr *hwmgr, | |
4064 | uint32_t arbFreqSrc, uint32_t arbFreqDest) | |
4065 | { | |
4066 | uint32_t mc_arb_dram_timing; | |
4067 | uint32_t mc_arb_dram_timing2; | |
4068 | uint32_t burst_time; | |
4069 | uint32_t mc_cg_config; | |
4070 | ||
4071 | switch (arbFreqSrc) { | |
4072 | case MC_CG_ARB_FREQ_F0: | |
4073 | mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING); | |
4074 | mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2); | |
4075 | burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0); | |
4076 | break; | |
4077 | ||
4078 | case MC_CG_ARB_FREQ_F1: | |
4079 | mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1); | |
4080 | mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1); | |
4081 | burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1); | |
4082 | break; | |
4083 | ||
4084 | default: | |
4085 | return -1; | |
4086 | } | |
4087 | ||
4088 | switch (arbFreqDest) { | |
4089 | case MC_CG_ARB_FREQ_F0: | |
4090 | cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING, mc_arb_dram_timing); | |
4091 | cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2, mc_arb_dram_timing2); | |
4092 | PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0, burst_time); | |
4093 | break; | |
4094 | ||
4095 | case MC_CG_ARB_FREQ_F1: | |
4096 | cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1, mc_arb_dram_timing); | |
4097 | cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1, mc_arb_dram_timing2); | |
4098 | PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1, burst_time); | |
4099 | break; | |
4100 | ||
4101 | default: | |
4102 | return -1; | |
4103 | } | |
4104 | ||
4105 | mc_cg_config = cgs_read_register(hwmgr->device, mmMC_CG_CONFIG); | |
4106 | mc_cg_config |= 0x0000000F; | |
4107 | cgs_write_register(hwmgr->device, mmMC_CG_CONFIG, mc_cg_config); | |
4108 | PHM_WRITE_FIELD(hwmgr->device, MC_ARB_CG, CG_ARB_REQ, arbFreqDest); | |
4109 | ||
4110 | return 0; | |
4111 | } | |
4112 | ||
4113 | /** | |
4114 | * Initial switch from ARB F0->F1 | |
4115 | * | |
4116 | * @param hwmgr the address of the powerplay hardware manager. | |
4117 | * @return always 0 | |
4118 | * This function is to be called from the SetPowerState table. | |
4119 | */ | |
4120 | int tonga_initial_switch_from_arb_f0_to_f1(struct pp_hwmgr *hwmgr) | |
4121 | { | |
4122 | return tonga_copy_and_switch_arb_sets(hwmgr, MC_CG_ARB_FREQ_F0, MC_CG_ARB_FREQ_F1); | |
4123 | } | |
4124 | ||
4125 | /** | |
4126 | * Initialize the ARB DRAM timing table's index field. | |
4127 | * | |
4128 | * @param hwmgr the address of the powerplay hardware manager. | |
4129 | * @return always 0 | |
4130 | */ | |
4131 | int tonga_init_arb_table_index(struct pp_hwmgr *hwmgr) | |
4132 | { | |
4133 | const tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
4134 | uint32_t tmp; | |
4135 | int result; | |
4136 | ||
4137 | /* | |
4138 | * This is a read-modify-write on the first byte of the ARB table. | |
4139 | * The first byte in the SMU72_Discrete_MCArbDramTimingTable structure is the field 'current'. | |
4140 | * This solution is ugly, but we never write the whole table only individual fields in it. | |
4141 | * In reality this field should not be in that structure but in a soft register. | |
4142 | */ | |
4143 | result = tonga_read_smc_sram_dword(hwmgr->smumgr, | |
4144 | data->arb_table_start, &tmp, data->sram_end); | |
4145 | ||
4146 | if (0 != result) | |
4147 | return result; | |
4148 | ||
4149 | tmp &= 0x00FFFFFF; | |
4150 | tmp |= ((uint32_t)MC_CG_ARB_FREQ_F1) << 24; | |
4151 | ||
4152 | return tonga_write_smc_sram_dword(hwmgr->smumgr, | |
4153 | data->arb_table_start, tmp, data->sram_end); | |
4154 | } | |
4155 | ||
4156 | int tonga_populate_mc_reg_address(struct pp_hwmgr *hwmgr, SMU72_Discrete_MCRegisters *mc_reg_table) | |
4157 | { | |
4158 | const struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
4159 | ||
4160 | uint32_t i, j; | |
4161 | ||
4162 | for (i = 0, j = 0; j < data->tonga_mc_reg_table.last; j++) { | |
4163 | if (data->tonga_mc_reg_table.validflag & 1<<j) { | |
4164 | PP_ASSERT_WITH_CODE(i < SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE, | |
4165 | "Index of mc_reg_table->address[] array out of boundary", return -1); | |
4166 | mc_reg_table->address[i].s0 = | |
4167 | PP_HOST_TO_SMC_US(data->tonga_mc_reg_table.mc_reg_address[j].s0); | |
4168 | mc_reg_table->address[i].s1 = | |
4169 | PP_HOST_TO_SMC_US(data->tonga_mc_reg_table.mc_reg_address[j].s1); | |
4170 | i++; | |
4171 | } | |
4172 | } | |
4173 | ||
4174 | mc_reg_table->last = (uint8_t)i; | |
4175 | ||
4176 | return 0; | |
4177 | } | |
4178 | ||
4179 | /*convert register values from driver to SMC format */ | |
4180 | void tonga_convert_mc_registers( | |
4181 | const phw_tonga_mc_reg_entry * pEntry, | |
4182 | SMU72_Discrete_MCRegisterSet *pData, | |
4183 | uint32_t numEntries, uint32_t validflag) | |
4184 | { | |
4185 | uint32_t i, j; | |
4186 | ||
4187 | for (i = 0, j = 0; j < numEntries; j++) { | |
4188 | if (validflag & 1<<j) { | |
4189 | pData->value[i] = PP_HOST_TO_SMC_UL(pEntry->mc_data[j]); | |
4190 | i++; | |
4191 | } | |
4192 | } | |
4193 | } | |
4194 | ||
4195 | /* find the entry in the memory range table, then populate the value to SMC's tonga_mc_reg_table */ | |
4196 | int tonga_convert_mc_reg_table_entry_to_smc( | |
4197 | struct pp_hwmgr *hwmgr, | |
4198 | const uint32_t memory_clock, | |
4199 | SMU72_Discrete_MCRegisterSet *mc_reg_table_data | |
4200 | ) | |
4201 | { | |
4202 | const tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
4203 | uint32_t i = 0; | |
4204 | ||
4205 | for (i = 0; i < data->tonga_mc_reg_table.num_entries; i++) { | |
4206 | if (memory_clock <= | |
4207 | data->tonga_mc_reg_table.mc_reg_table_entry[i].mclk_max) { | |
4208 | break; | |
4209 | } | |
4210 | } | |
4211 | ||
4212 | if ((i == data->tonga_mc_reg_table.num_entries) && (i > 0)) | |
4213 | --i; | |
4214 | ||
4215 | tonga_convert_mc_registers(&data->tonga_mc_reg_table.mc_reg_table_entry[i], | |
4216 | mc_reg_table_data, data->tonga_mc_reg_table.last, data->tonga_mc_reg_table.validflag); | |
4217 | ||
4218 | return 0; | |
4219 | } | |
4220 | ||
4221 | int tonga_convert_mc_reg_table_to_smc(struct pp_hwmgr *hwmgr, | |
4222 | SMU72_Discrete_MCRegisters *mc_reg_table) | |
4223 | { | |
4224 | int result = 0; | |
4225 | tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
4226 | int res; | |
4227 | uint32_t i; | |
4228 | ||
4229 | for (i = 0; i < data->dpm_table.mclk_table.count; i++) { | |
4230 | res = tonga_convert_mc_reg_table_entry_to_smc( | |
4231 | hwmgr, | |
4232 | data->dpm_table.mclk_table.dpm_levels[i].value, | |
4233 | &mc_reg_table->data[i] | |
4234 | ); | |
4235 | ||
4236 | if (0 != res) | |
4237 | result = res; | |
4238 | } | |
4239 | ||
4240 | return result; | |
4241 | } | |
4242 | ||
4243 | int tonga_populate_initial_mc_reg_table(struct pp_hwmgr *hwmgr) | |
4244 | { | |
4245 | int result; | |
4246 | struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
4247 | ||
4248 | memset(&data->mc_reg_table, 0x00, sizeof(SMU72_Discrete_MCRegisters)); | |
4249 | result = tonga_populate_mc_reg_address(hwmgr, &(data->mc_reg_table)); | |
4250 | PP_ASSERT_WITH_CODE(0 == result, | |
4251 | "Failed to initialize MCRegTable for the MC register addresses!", return result;); | |
4252 | ||
4253 | result = tonga_convert_mc_reg_table_to_smc(hwmgr, &data->mc_reg_table); | |
4254 | PP_ASSERT_WITH_CODE(0 == result, | |
4255 | "Failed to initialize MCRegTable for driver state!", return result;); | |
4256 | ||
4257 | return tonga_copy_bytes_to_smc(hwmgr->smumgr, data->mc_reg_table_start, | |
4258 | (uint8_t *)&data->mc_reg_table, sizeof(SMU72_Discrete_MCRegisters), data->sram_end); | |
4259 | } | |
4260 | ||
4261 | /** | |
4262 | * Programs static screed detection parameters | |
4263 | * | |
4264 | * @param hwmgr the address of the powerplay hardware manager. | |
4265 | * @return always 0 | |
4266 | */ | |
4267 | int tonga_program_static_screen_threshold_parameters(struct pp_hwmgr *hwmgr) | |
4268 | { | |
4269 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
4270 | ||
4271 | /* Set static screen threshold unit*/ | |
4272 | PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, | |
4273 | CGS_IND_REG__SMC, CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD_UNIT, | |
4274 | data->static_screen_threshold_unit); | |
4275 | /* Set static screen threshold*/ | |
4276 | PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, | |
4277 | CGS_IND_REG__SMC, CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD, | |
4278 | data->static_screen_threshold); | |
4279 | ||
4280 | return 0; | |
4281 | } | |
4282 | ||
4283 | /** | |
4284 | * Setup display gap for glitch free memory clock switching. | |
4285 | * | |
4286 | * @param hwmgr the address of the powerplay hardware manager. | |
4287 | * @return always 0 | |
4288 | */ | |
4289 | int tonga_enable_display_gap(struct pp_hwmgr *hwmgr) | |
4290 | { | |
4291 | uint32_t display_gap = cgs_read_ind_register(hwmgr->device, | |
4292 | CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL); | |
4293 | ||
4294 | display_gap = PHM_SET_FIELD(display_gap, | |
4295 | CG_DISPLAY_GAP_CNTL, DISP_GAP, DISPLAY_GAP_IGNORE); | |
4296 | ||
4297 | display_gap = PHM_SET_FIELD(display_gap, | |
4298 | CG_DISPLAY_GAP_CNTL, DISP_GAP_MCHG, DISPLAY_GAP_VBLANK); | |
4299 | ||
4300 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
4301 | ixCG_DISPLAY_GAP_CNTL, display_gap); | |
4302 | ||
4303 | return 0; | |
4304 | } | |
4305 | ||
4306 | /** | |
4307 | * Programs activity state transition voting clients | |
4308 | * | |
4309 | * @param hwmgr the address of the powerplay hardware manager. | |
4310 | * @return always 0 | |
4311 | */ | |
4312 | int tonga_program_voting_clients(struct pp_hwmgr *hwmgr) | |
4313 | { | |
4314 | tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend); | |
4315 | ||
4316 | /* Clear reset for voting clients before enabling DPM */ | |
4317 | PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, | |
4318 | SCLK_PWRMGT_CNTL, RESET_SCLK_CNT, 0); | |
4319 | PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, | |
4320 | SCLK_PWRMGT_CNTL, RESET_BUSY_CNT, 0); | |
4321 | ||
4322 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
4323 | ixCG_FREQ_TRAN_VOTING_0, data->voting_rights_clients0); | |
4324 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
4325 | ixCG_FREQ_TRAN_VOTING_1, data->voting_rights_clients1); | |
4326 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
4327 | ixCG_FREQ_TRAN_VOTING_2, data->voting_rights_clients2); | |
4328 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
4329 | ixCG_FREQ_TRAN_VOTING_3, data->voting_rights_clients3); | |
4330 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
4331 | ixCG_FREQ_TRAN_VOTING_4, data->voting_rights_clients4); | |
4332 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
4333 | ixCG_FREQ_TRAN_VOTING_5, data->voting_rights_clients5); | |
4334 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
4335 | ixCG_FREQ_TRAN_VOTING_6, data->voting_rights_clients6); | |
4336 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
4337 | ixCG_FREQ_TRAN_VOTING_7, data->voting_rights_clients7); | |
4338 | ||
4339 | return 0; | |
4340 | } | |
4341 | ||
4342 | ||
4343 | int tonga_enable_dpm_tasks(struct pp_hwmgr *hwmgr) | |
4344 | { | |
4345 | int tmp_result, result = 0; | |
4346 | ||
4347 | tmp_result = tonga_check_for_dpm_stopped(hwmgr); | |
4348 | ||
4349 | if (cf_tonga_voltage_control(hwmgr)) { | |
4350 | tmp_result = tonga_enable_voltage_control(hwmgr); | |
4351 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
4352 | "Failed to enable voltage control!", result = tmp_result); | |
4353 | ||
4354 | tmp_result = tonga_construct_voltage_tables(hwmgr); | |
4355 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
4356 | "Failed to contruct voltage tables!", result = tmp_result); | |
4357 | } | |
4358 | ||
4359 | tmp_result = tonga_initialize_mc_reg_table(hwmgr); | |
4360 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
4361 | "Failed to initialize MC reg table!", result = tmp_result); | |
4362 | ||
4363 | tmp_result = tonga_program_static_screen_threshold_parameters(hwmgr); | |
4364 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
4365 | "Failed to program static screen threshold parameters!", result = tmp_result); | |
4366 | ||
4367 | tmp_result = tonga_enable_display_gap(hwmgr); | |
4368 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
4369 | "Failed to enable display gap!", result = tmp_result); | |
4370 | ||
4371 | tmp_result = tonga_program_voting_clients(hwmgr); | |
4372 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
4373 | "Failed to program voting clients!", result = tmp_result); | |
4374 | ||
4375 | tmp_result = tonga_process_firmware_header(hwmgr); | |
4376 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
4377 | "Failed to process firmware header!", result = tmp_result); | |
4378 | ||
4379 | tmp_result = tonga_initial_switch_from_arb_f0_to_f1(hwmgr); | |
4380 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
4381 | "Failed to initialize switch from ArbF0 to F1!", result = tmp_result); | |
4382 | ||
4383 | tmp_result = tonga_init_smc_table(hwmgr); | |
4384 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
4385 | "Failed to initialize SMC table!", result = tmp_result); | |
4386 | ||
4387 | tmp_result = tonga_init_arb_table_index(hwmgr); | |
4388 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
4389 | "Failed to initialize ARB table index!", result = tmp_result); | |
4390 | ||
4391 | tmp_result = tonga_populate_initial_mc_reg_table(hwmgr); | |
4392 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
4393 | "Failed to populate initialize MC Reg table!", result = tmp_result); | |
4394 | ||
4395 | /* enable SCLK control */ | |
4396 | tmp_result = tonga_enable_sclk_control(hwmgr); | |
4397 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
4398 | "Failed to enable SCLK control!", result = tmp_result); | |
4399 | ||
4400 | /* enable DPM */ | |
4401 | tmp_result = tonga_start_dpm(hwmgr); | |
4402 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
4403 | "Failed to start DPM!", result = tmp_result); | |
4404 | ||
4405 | return result; | |
4406 | } | |
4407 | ||
4408 | int tonga_disable_dpm_tasks(struct pp_hwmgr *hwmgr) | |
4409 | { | |
4410 | int tmp_result, result = 0; | |
4411 | ||
4412 | tmp_result = tonga_check_for_dpm_running(hwmgr); | |
4413 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
4414 | "SMC is still running!", return 0); | |
4415 | ||
4416 | tmp_result = tonga_stop_dpm(hwmgr); | |
4417 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
4418 | "Failed to stop DPM!", result = tmp_result); | |
4419 | ||
4420 | tmp_result = tonga_reset_to_default(hwmgr); | |
4421 | PP_ASSERT_WITH_CODE((0 == tmp_result), | |
4422 | "Failed to reset to default!", result = tmp_result); | |
4423 | ||
4424 | return result; | |
4425 | } | |
4426 | ||
4427 | int tonga_reset_asic_tasks(struct pp_hwmgr *hwmgr) | |
4428 | { | |
4429 | int result; | |
4430 | ||
4431 | result = tonga_set_boot_state(hwmgr); | |
4432 | if (0 != result) | |
4433 | printk(KERN_ERR "[ powerplay ] Failed to reset asic via set boot state! \n"); | |
4434 | ||
4435 | return result; | |
4436 | } | |
4437 | ||
4438 | int tonga_hwmgr_backend_fini(struct pp_hwmgr *hwmgr) | |
4439 | { | |
4440 | if (NULL != hwmgr->dyn_state.vddc_dep_on_dal_pwrl) { | |
4441 | kfree(hwmgr->dyn_state.vddc_dep_on_dal_pwrl); | |
4442 | hwmgr->dyn_state.vddc_dep_on_dal_pwrl = NULL; | |
4443 | } | |
4444 | ||
4445 | if (NULL != hwmgr->backend) { | |
4446 | kfree(hwmgr->backend); | |
4447 | hwmgr->backend = NULL; | |
4448 | } | |
4449 | ||
4450 | return 0; | |
4451 | } | |
4452 | ||
4453 | /** | |
4454 | * Initializes the Volcanic Islands Hardware Manager | |
4455 | * | |
4456 | * @param hwmgr the address of the powerplay hardware manager. | |
4457 | * @return 1 if success; otherwise appropriate error code. | |
4458 | */ | |
4459 | int tonga_hwmgr_backend_init(struct pp_hwmgr *hwmgr) | |
4460 | { | |
4461 | int result = 0; | |
4462 | SMU72_Discrete_DpmTable *table = NULL; | |
4463 | tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
4464 | pp_atomctrl_gpio_pin_assignment gpio_pin_assignment; | |
4465 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
4466 | phw_tonga_ulv_parm *ulv; | |
4467 | ||
4468 | PP_ASSERT_WITH_CODE((NULL != hwmgr), | |
4469 | "Invalid Parameter!", return -1;); | |
4470 | ||
4471 | data->dll_defaule_on = 0; | |
4472 | data->sram_end = SMC_RAM_END; | |
4473 | ||
4474 | data->activity_target[0] = PPTONGA_TARGETACTIVITY_DFLT; | |
4475 | data->activity_target[1] = PPTONGA_TARGETACTIVITY_DFLT; | |
4476 | data->activity_target[2] = PPTONGA_TARGETACTIVITY_DFLT; | |
4477 | data->activity_target[3] = PPTONGA_TARGETACTIVITY_DFLT; | |
4478 | data->activity_target[4] = PPTONGA_TARGETACTIVITY_DFLT; | |
4479 | data->activity_target[5] = PPTONGA_TARGETACTIVITY_DFLT; | |
4480 | data->activity_target[6] = PPTONGA_TARGETACTIVITY_DFLT; | |
4481 | data->activity_target[7] = PPTONGA_TARGETACTIVITY_DFLT; | |
4482 | ||
4483 | data->vddc_vddci_delta = VDDC_VDDCI_DELTA; | |
4484 | data->vddc_vddgfx_delta = VDDC_VDDGFX_DELTA; | |
4485 | data->mclk_activity_target = PPTONGA_MCLK_TARGETACTIVITY_DFLT; | |
4486 | ||
4487 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
4488 | PHM_PlatformCaps_DisableVoltageIsland); | |
4489 | ||
4490 | data->sclk_dpm_key_disabled = 0; | |
4491 | data->mclk_dpm_key_disabled = 0; | |
4492 | data->pcie_dpm_key_disabled = 0; | |
4493 | data->pcc_monitor_enabled = 0; | |
4494 | ||
4495 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
4496 | PHM_PlatformCaps_UnTabledHardwareInterface); | |
4497 | ||
4498 | data->gpio_debug = 0; | |
4499 | data->engine_clock_data = 0; | |
4500 | data->memory_clock_data = 0; | |
4501 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
4502 | PHM_PlatformCaps_DynamicPatchPowerState); | |
4503 | ||
4504 | /* need to set voltage control types before EVV patching*/ | |
4505 | data->voltage_control = TONGA_VOLTAGE_CONTROL_NONE; | |
4506 | data->vdd_ci_control = TONGA_VOLTAGE_CONTROL_NONE; | |
4507 | data->vdd_gfx_control = TONGA_VOLTAGE_CONTROL_NONE; | |
4508 | data->mvdd_control = TONGA_VOLTAGE_CONTROL_NONE; | |
4509 | ||
4510 | if (0 == atomctrl_is_voltage_controled_by_gpio_v3(hwmgr, | |
4511 | VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_SVID2)) { | |
4512 | data->voltage_control = TONGA_VOLTAGE_CONTROL_BY_SVID2; | |
4513 | } | |
4514 | ||
4515 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
4516 | PHM_PlatformCaps_ControlVDDGFX)) { | |
4517 | if (0 == atomctrl_is_voltage_controled_by_gpio_v3(hwmgr, | |
4518 | VOLTAGE_TYPE_VDDGFX, VOLTAGE_OBJ_SVID2)) { | |
4519 | data->vdd_gfx_control = TONGA_VOLTAGE_CONTROL_BY_SVID2; | |
4520 | } | |
4521 | } | |
4522 | ||
4523 | if (TONGA_VOLTAGE_CONTROL_NONE == data->vdd_gfx_control) { | |
4524 | phm_cap_unset(hwmgr->platform_descriptor.platformCaps, | |
4525 | PHM_PlatformCaps_ControlVDDGFX); | |
4526 | } | |
4527 | ||
4528 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
4529 | PHM_PlatformCaps_EnableMVDDControl)) { | |
4530 | if (0 == atomctrl_is_voltage_controled_by_gpio_v3(hwmgr, | |
4531 | VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT)) { | |
4532 | data->mvdd_control = TONGA_VOLTAGE_CONTROL_BY_GPIO; | |
4533 | } | |
4534 | } | |
4535 | ||
4536 | if (TONGA_VOLTAGE_CONTROL_NONE == data->mvdd_control) { | |
4537 | phm_cap_unset(hwmgr->platform_descriptor.platformCaps, | |
4538 | PHM_PlatformCaps_EnableMVDDControl); | |
4539 | } | |
4540 | ||
4541 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, | |
4542 | PHM_PlatformCaps_ControlVDDCI)) { | |
4543 | if (0 == atomctrl_is_voltage_controled_by_gpio_v3(hwmgr, | |
4544 | VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT)) | |
4545 | data->vdd_ci_control = TONGA_VOLTAGE_CONTROL_BY_GPIO; | |
4546 | else if (0 == atomctrl_is_voltage_controled_by_gpio_v3(hwmgr, | |
4547 | VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_SVID2)) | |
4548 | data->vdd_ci_control = TONGA_VOLTAGE_CONTROL_BY_SVID2; | |
4549 | } | |
4550 | ||
4551 | if (TONGA_VOLTAGE_CONTROL_NONE == data->vdd_ci_control) | |
4552 | phm_cap_unset(hwmgr->platform_descriptor.platformCaps, | |
4553 | PHM_PlatformCaps_ControlVDDCI); | |
4554 | ||
4555 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
4556 | PHM_PlatformCaps_TablelessHardwareInterface); | |
4557 | ||
4558 | if (pptable_info->cac_dtp_table->usClockStretchAmount != 0) | |
4559 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
4560 | PHM_PlatformCaps_ClockStretcher); | |
4561 | ||
4562 | /* Initializes DPM default values*/ | |
4563 | tonga_initialize_dpm_defaults(hwmgr); | |
4564 | ||
4565 | /* Get leakage voltage based on leakage ID.*/ | |
4566 | PP_ASSERT_WITH_CODE((0 == tonga_get_evv_voltage(hwmgr)), | |
4567 | "Get EVV Voltage Failed. Abort Driver loading!", return -1); | |
4568 | ||
4569 | tonga_complete_dependency_tables(hwmgr); | |
4570 | ||
4571 | /* Parse pptable data read from VBIOS*/ | |
4572 | tonga_set_private_var_based_on_pptale(hwmgr); | |
4573 | ||
4574 | /* ULV Support*/ | |
4575 | ulv = &(data->ulv); | |
4576 | ulv->ulv_supported = 0; | |
4577 | ||
4578 | /* Initalize Dynamic State Adjustment Rule Settings*/ | |
4579 | result = tonga_initializa_dynamic_state_adjustment_rule_settings(hwmgr); | |
4580 | data->uvd_enabled = 0; | |
4581 | ||
4582 | table = &(data->smc_state_table); | |
4583 | ||
4584 | /* | |
4585 | * if ucGPIO_ID=VDDC_PCC_GPIO_PINID in GPIO_LUTable, | |
4586 | * Peak Current Control feature is enabled and we should program PCC HW register | |
4587 | */ | |
4588 | if (0 == atomctrl_get_pp_assign_pin(hwmgr, VDDC_PCC_GPIO_PINID, &gpio_pin_assignment)) { | |
4589 | uint32_t temp_reg = cgs_read_ind_register(hwmgr->device, | |
4590 | CGS_IND_REG__SMC, ixCNB_PWRMGT_CNTL); | |
4591 | ||
4592 | switch (gpio_pin_assignment.uc_gpio_pin_bit_shift) { | |
4593 | case 0: | |
4594 | temp_reg = PHM_SET_FIELD(temp_reg, | |
4595 | CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x1); | |
4596 | break; | |
4597 | case 1: | |
4598 | temp_reg = PHM_SET_FIELD(temp_reg, | |
4599 | CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x2); | |
4600 | break; | |
4601 | case 2: | |
4602 | temp_reg = PHM_SET_FIELD(temp_reg, | |
4603 | CNB_PWRMGT_CNTL, GNB_SLOW, 0x1); | |
4604 | break; | |
4605 | case 3: | |
4606 | temp_reg = PHM_SET_FIELD(temp_reg, | |
4607 | CNB_PWRMGT_CNTL, FORCE_NB_PS1, 0x1); | |
4608 | break; | |
4609 | case 4: | |
4610 | temp_reg = PHM_SET_FIELD(temp_reg, | |
4611 | CNB_PWRMGT_CNTL, DPM_ENABLED, 0x1); | |
4612 | break; | |
4613 | default: | |
4614 | printk(KERN_ERR "[ powerplay ] Failed to setup PCC HW register! \ | |
4615 | Wrong GPIO assigned for VDDC_PCC_GPIO_PINID! \n"); | |
4616 | break; | |
4617 | } | |
4618 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, | |
4619 | ixCNB_PWRMGT_CNTL, temp_reg); | |
4620 | } | |
4621 | ||
4622 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
4623 | PHM_PlatformCaps_EnableSMU7ThermalManagement); | |
4624 | phm_cap_set(hwmgr->platform_descriptor.platformCaps, | |
4625 | PHM_PlatformCaps_SMU7); | |
4626 | ||
4627 | data->vddc_phase_shed_control = 0; | |
4628 | ||
4629 | if (0 == result) { | |
4630 | data->is_tlu_enabled = 0; | |
4631 | hwmgr->platform_descriptor.hardwareActivityPerformanceLevels = | |
4632 | TONGA_MAX_HARDWARE_POWERLEVELS; | |
4633 | hwmgr->platform_descriptor.hardwarePerformanceLevels = 2; | |
4634 | hwmgr->platform_descriptor.minimumClocksReductionPercentage = 50; | |
4635 | ||
4636 | data->pcie_gen_cap = 0x30007; | |
4637 | data->pcie_lane_cap = 0x2f0000; | |
4638 | } else { | |
4639 | /* Ignore return value in here, we are cleaning up a mess. */ | |
4640 | tonga_hwmgr_backend_fini(hwmgr); | |
4641 | } | |
4642 | ||
4643 | return result; | |
4644 | } | |
4645 | ||
4646 | static int tonga_force_dpm_level(struct pp_hwmgr *hwmgr, | |
4647 | enum amd_dpm_forced_level level) | |
4648 | { | |
4649 | int ret = 0; | |
4650 | ||
4651 | switch (level) { | |
4652 | case AMD_DPM_FORCED_LEVEL_HIGH: | |
4653 | ret = tonga_force_dpm_highest(hwmgr); | |
4654 | if (ret) | |
4655 | return ret; | |
4656 | break; | |
4657 | case AMD_DPM_FORCED_LEVEL_LOW: | |
4658 | ret = tonga_force_dpm_lowest(hwmgr); | |
4659 | if (ret) | |
4660 | return ret; | |
4661 | break; | |
4662 | case AMD_DPM_FORCED_LEVEL_AUTO: | |
4663 | ret = tonga_unforce_dpm_levels(hwmgr); | |
4664 | if (ret) | |
4665 | return ret; | |
4666 | break; | |
4667 | default: | |
4668 | break; | |
4669 | } | |
4670 | ||
4671 | hwmgr->dpm_level = level; | |
4672 | return ret; | |
4673 | } | |
4674 | ||
4675 | static int tonga_apply_state_adjust_rules(struct pp_hwmgr *hwmgr, | |
4676 | struct pp_power_state *prequest_ps, | |
4677 | const struct pp_power_state *pcurrent_ps) | |
4678 | { | |
4679 | struct tonga_power_state *tonga_ps = | |
4680 | cast_phw_tonga_power_state(&prequest_ps->hardware); | |
4681 | ||
4682 | uint32_t sclk; | |
4683 | uint32_t mclk; | |
4684 | struct PP_Clocks minimum_clocks = {0}; | |
4685 | bool disable_mclk_switching; | |
4686 | bool disable_mclk_switching_for_frame_lock; | |
4687 | struct cgs_display_info info = {0}; | |
4688 | const struct phm_clock_and_voltage_limits *max_limits; | |
4689 | uint32_t i; | |
4690 | tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
4691 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
4692 | ||
4693 | int32_t count; | |
4694 | int32_t stable_pstate_sclk = 0, stable_pstate_mclk = 0; | |
4695 | ||
4696 | data->battery_state = (PP_StateUILabel_Battery == prequest_ps->classification.ui_label); | |
4697 | ||
4698 | PP_ASSERT_WITH_CODE(tonga_ps->performance_level_count == 2, | |
4699 | "VI should always have 2 performance levels", | |
4700 | ); | |
4701 | ||
4702 | max_limits = (PP_PowerSource_AC == hwmgr->power_source) ? | |
4703 | &(hwmgr->dyn_state.max_clock_voltage_on_ac) : | |
4704 | &(hwmgr->dyn_state.max_clock_voltage_on_dc); | |
4705 | ||
4706 | if (PP_PowerSource_DC == hwmgr->power_source) { | |
4707 | for (i = 0; i < tonga_ps->performance_level_count; i++) { | |
4708 | if (tonga_ps->performance_levels[i].memory_clock > max_limits->mclk) | |
4709 | tonga_ps->performance_levels[i].memory_clock = max_limits->mclk; | |
4710 | if (tonga_ps->performance_levels[i].engine_clock > max_limits->sclk) | |
4711 | tonga_ps->performance_levels[i].engine_clock = max_limits->sclk; | |
4712 | } | |
4713 | } | |
4714 | ||
4715 | tonga_ps->vce_clocks.EVCLK = hwmgr->vce_arbiter.evclk; | |
4716 | tonga_ps->vce_clocks.ECCLK = hwmgr->vce_arbiter.ecclk; | |
4717 | ||
4718 | tonga_ps->acp_clk = hwmgr->acp_arbiter.acpclk; | |
4719 | ||
4720 | cgs_get_active_displays_info(hwmgr->device, &info); | |
4721 | ||
4722 | /*TO DO result = PHM_CheckVBlankTime(hwmgr, &vblankTooShort);*/ | |
4723 | ||
4724 | /* TO DO GetMinClockSettings(hwmgr->pPECI, &minimum_clocks); */ | |
4725 | ||
4726 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_StablePState)) { | |
4727 | ||
4728 | max_limits = &(hwmgr->dyn_state.max_clock_voltage_on_ac); | |
4729 | stable_pstate_sclk = (max_limits->sclk * 75) / 100; | |
4730 | ||
4731 | for (count = pptable_info->vdd_dep_on_sclk->count-1; count >= 0; count--) { | |
4732 | if (stable_pstate_sclk >= pptable_info->vdd_dep_on_sclk->entries[count].clk) { | |
4733 | stable_pstate_sclk = pptable_info->vdd_dep_on_sclk->entries[count].clk; | |
4734 | break; | |
4735 | } | |
4736 | } | |
4737 | ||
4738 | if (count < 0) | |
4739 | stable_pstate_sclk = pptable_info->vdd_dep_on_sclk->entries[0].clk; | |
4740 | ||
4741 | stable_pstate_mclk = max_limits->mclk; | |
4742 | ||
4743 | minimum_clocks.engineClock = stable_pstate_sclk; | |
4744 | minimum_clocks.memoryClock = stable_pstate_mclk; | |
4745 | } | |
4746 | ||
4747 | if (minimum_clocks.engineClock < hwmgr->gfx_arbiter.sclk) | |
4748 | minimum_clocks.engineClock = hwmgr->gfx_arbiter.sclk; | |
4749 | ||
4750 | if (minimum_clocks.memoryClock < hwmgr->gfx_arbiter.mclk) | |
4751 | minimum_clocks.memoryClock = hwmgr->gfx_arbiter.mclk; | |
4752 | ||
4753 | tonga_ps->sclk_threshold = hwmgr->gfx_arbiter.sclk_threshold; | |
4754 | ||
4755 | if (0 != hwmgr->gfx_arbiter.sclk_over_drive) { | |
4756 | PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.sclk_over_drive <= hwmgr->platform_descriptor.overdriveLimit.engineClock), | |
4757 | "Overdrive sclk exceeds limit", | |
4758 | hwmgr->gfx_arbiter.sclk_over_drive = hwmgr->platform_descriptor.overdriveLimit.engineClock); | |
4759 | ||
4760 | if (hwmgr->gfx_arbiter.sclk_over_drive >= hwmgr->gfx_arbiter.sclk) | |
4761 | tonga_ps->performance_levels[1].engine_clock = hwmgr->gfx_arbiter.sclk_over_drive; | |
4762 | } | |
4763 | ||
4764 | if (0 != hwmgr->gfx_arbiter.mclk_over_drive) { | |
4765 | PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.mclk_over_drive <= hwmgr->platform_descriptor.overdriveLimit.memoryClock), | |
4766 | "Overdrive mclk exceeds limit", | |
4767 | hwmgr->gfx_arbiter.mclk_over_drive = hwmgr->platform_descriptor.overdriveLimit.memoryClock); | |
4768 | ||
4769 | if (hwmgr->gfx_arbiter.mclk_over_drive >= hwmgr->gfx_arbiter.mclk) | |
4770 | tonga_ps->performance_levels[1].memory_clock = hwmgr->gfx_arbiter.mclk_over_drive; | |
4771 | } | |
4772 | ||
4773 | disable_mclk_switching_for_frame_lock = phm_cap_enabled( | |
4774 | hwmgr->platform_descriptor.platformCaps, | |
4775 | PHM_PlatformCaps_DisableMclkSwitchingForFrameLock); | |
4776 | ||
4777 | disable_mclk_switching = (1 < info.display_count) || | |
4778 | disable_mclk_switching_for_frame_lock; | |
4779 | ||
4780 | sclk = tonga_ps->performance_levels[0].engine_clock; | |
4781 | mclk = tonga_ps->performance_levels[0].memory_clock; | |
4782 | ||
4783 | if (disable_mclk_switching) | |
4784 | mclk = tonga_ps->performance_levels[tonga_ps->performance_level_count - 1].memory_clock; | |
4785 | ||
4786 | if (sclk < minimum_clocks.engineClock) | |
4787 | sclk = (minimum_clocks.engineClock > max_limits->sclk) ? max_limits->sclk : minimum_clocks.engineClock; | |
4788 | ||
4789 | if (mclk < minimum_clocks.memoryClock) | |
4790 | mclk = (minimum_clocks.memoryClock > max_limits->mclk) ? max_limits->mclk : minimum_clocks.memoryClock; | |
4791 | ||
4792 | tonga_ps->performance_levels[0].engine_clock = sclk; | |
4793 | tonga_ps->performance_levels[0].memory_clock = mclk; | |
4794 | ||
4795 | tonga_ps->performance_levels[1].engine_clock = | |
4796 | (tonga_ps->performance_levels[1].engine_clock >= tonga_ps->performance_levels[0].engine_clock) ? | |
4797 | tonga_ps->performance_levels[1].engine_clock : | |
4798 | tonga_ps->performance_levels[0].engine_clock; | |
4799 | ||
4800 | if (disable_mclk_switching) { | |
4801 | if (mclk < tonga_ps->performance_levels[1].memory_clock) | |
4802 | mclk = tonga_ps->performance_levels[1].memory_clock; | |
4803 | ||
4804 | tonga_ps->performance_levels[0].memory_clock = mclk; | |
4805 | tonga_ps->performance_levels[1].memory_clock = mclk; | |
4806 | } else { | |
4807 | if (tonga_ps->performance_levels[1].memory_clock < tonga_ps->performance_levels[0].memory_clock) | |
4808 | tonga_ps->performance_levels[1].memory_clock = tonga_ps->performance_levels[0].memory_clock; | |
4809 | } | |
4810 | ||
4811 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_StablePState)) { | |
4812 | for (i=0; i < tonga_ps->performance_level_count; i++) { | |
4813 | tonga_ps->performance_levels[i].engine_clock = stable_pstate_sclk; | |
4814 | tonga_ps->performance_levels[i].memory_clock = stable_pstate_mclk; | |
4815 | tonga_ps->performance_levels[i].pcie_gen = data->pcie_gen_performance.max; | |
4816 | tonga_ps->performance_levels[i].pcie_lane = data->pcie_gen_performance.max; | |
4817 | } | |
4818 | } | |
4819 | ||
4820 | return 0; | |
4821 | } | |
4822 | ||
4823 | int tonga_get_power_state_size(struct pp_hwmgr *hwmgr) | |
4824 | { | |
4825 | return sizeof(struct tonga_power_state); | |
4826 | } | |
4827 | ||
4828 | static int tonga_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low) | |
4829 | { | |
4830 | struct pp_power_state *ps; | |
4831 | struct tonga_power_state *tonga_ps; | |
4832 | ||
4833 | if (hwmgr == NULL) | |
4834 | return -EINVAL; | |
4835 | ||
4836 | ps = hwmgr->request_ps; | |
4837 | ||
4838 | if (ps == NULL) | |
4839 | return -EINVAL; | |
4840 | ||
4841 | tonga_ps = cast_phw_tonga_power_state(&ps->hardware); | |
4842 | ||
4843 | if (low) | |
4844 | return tonga_ps->performance_levels[0].memory_clock; | |
4845 | else | |
4846 | return tonga_ps->performance_levels[tonga_ps->performance_level_count-1].memory_clock; | |
4847 | } | |
4848 | ||
4849 | static int tonga_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low) | |
4850 | { | |
4851 | struct pp_power_state *ps; | |
4852 | struct tonga_power_state *tonga_ps; | |
4853 | ||
4854 | if (hwmgr == NULL) | |
4855 | return -EINVAL; | |
4856 | ||
4857 | ps = hwmgr->request_ps; | |
4858 | ||
4859 | if (ps == NULL) | |
4860 | return -EINVAL; | |
4861 | ||
4862 | tonga_ps = cast_phw_tonga_power_state(&ps->hardware); | |
4863 | ||
4864 | if (low) | |
4865 | return tonga_ps->performance_levels[0].engine_clock; | |
4866 | else | |
4867 | return tonga_ps->performance_levels[tonga_ps->performance_level_count-1].engine_clock; | |
4868 | } | |
4869 | ||
4870 | static uint16_t tonga_get_current_pcie_speed( | |
4871 | struct pp_hwmgr *hwmgr) | |
4872 | { | |
4873 | uint32_t speed_cntl = 0; | |
4874 | ||
4875 | speed_cntl = cgs_read_ind_register(hwmgr->device, | |
4876 | CGS_IND_REG__PCIE, | |
4877 | ixPCIE_LC_SPEED_CNTL); | |
4878 | return((uint16_t)PHM_GET_FIELD(speed_cntl, | |
4879 | PCIE_LC_SPEED_CNTL, LC_CURRENT_DATA_RATE)); | |
4880 | } | |
4881 | ||
4882 | static int tonga_get_current_pcie_lane_number( | |
4883 | struct pp_hwmgr *hwmgr) | |
4884 | { | |
4885 | uint32_t link_width; | |
4886 | ||
4887 | link_width = PHM_READ_INDIRECT_FIELD(hwmgr->device, | |
4888 | CGS_IND_REG__PCIE, | |
4889 | PCIE_LC_LINK_WIDTH_CNTL, | |
4890 | LC_LINK_WIDTH_RD); | |
4891 | ||
4892 | PP_ASSERT_WITH_CODE((7 >= link_width), | |
4893 | "Invalid PCIe lane width!", return 0); | |
4894 | ||
4895 | return decode_pcie_lane_width(link_width); | |
4896 | } | |
4897 | ||
4898 | static int tonga_dpm_patch_boot_state(struct pp_hwmgr *hwmgr, | |
4899 | struct pp_hw_power_state *hw_ps) | |
4900 | { | |
4901 | struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
4902 | struct tonga_power_state *ps = (struct tonga_power_state *)hw_ps; | |
4903 | ATOM_FIRMWARE_INFO_V2_2 *fw_info; | |
4904 | uint16_t size; | |
4905 | uint8_t frev, crev; | |
4906 | int index = GetIndexIntoMasterTable(DATA, FirmwareInfo); | |
4907 | ||
4908 | /* First retrieve the Boot clocks and VDDC from the firmware info table. | |
4909 | * We assume here that fw_info is unchanged if this call fails. | |
4910 | */ | |
4911 | fw_info = (ATOM_FIRMWARE_INFO_V2_2 *)cgs_atom_get_data_table( | |
4912 | hwmgr->device, index, | |
4913 | &size, &frev, &crev); | |
4914 | if (!fw_info) | |
4915 | /* During a test, there is no firmware info table. */ | |
4916 | return 0; | |
4917 | ||
4918 | /* Patch the state. */ | |
4919 | data->vbios_boot_state.sclk_bootup_value = le32_to_cpu(fw_info->ulDefaultEngineClock); | |
4920 | data->vbios_boot_state.mclk_bootup_value = le32_to_cpu(fw_info->ulDefaultMemoryClock); | |
4921 | data->vbios_boot_state.mvdd_bootup_value = le16_to_cpu(fw_info->usBootUpMVDDCVoltage); | |
4922 | data->vbios_boot_state.vddc_bootup_value = le16_to_cpu(fw_info->usBootUpVDDCVoltage); | |
4923 | data->vbios_boot_state.vddci_bootup_value = le16_to_cpu(fw_info->usBootUpVDDCIVoltage); | |
4924 | data->vbios_boot_state.pcie_gen_bootup_value = tonga_get_current_pcie_speed(hwmgr); | |
4925 | data->vbios_boot_state.pcie_lane_bootup_value = | |
4926 | (uint16_t)tonga_get_current_pcie_lane_number(hwmgr); | |
4927 | ||
4928 | /* set boot power state */ | |
4929 | ps->performance_levels[0].memory_clock = data->vbios_boot_state.mclk_bootup_value; | |
4930 | ps->performance_levels[0].engine_clock = data->vbios_boot_state.sclk_bootup_value; | |
4931 | ps->performance_levels[0].pcie_gen = data->vbios_boot_state.pcie_gen_bootup_value; | |
4932 | ps->performance_levels[0].pcie_lane = data->vbios_boot_state.pcie_lane_bootup_value; | |
4933 | ||
4934 | return 0; | |
4935 | } | |
4936 | ||
4937 | static int tonga_get_pp_table_entry_callback_func(struct pp_hwmgr *hwmgr, | |
4938 | void *state, struct pp_power_state *power_state, | |
4939 | void *pp_table, uint32_t classification_flag) | |
4940 | { | |
4941 | struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
4942 | ||
4943 | struct tonga_power_state *tonga_ps = | |
4944 | (struct tonga_power_state *)(&(power_state->hardware)); | |
4945 | ||
4946 | struct tonga_performance_level *performance_level; | |
4947 | ||
4948 | ATOM_Tonga_State *state_entry = (ATOM_Tonga_State *)state; | |
4949 | ||
4950 | ATOM_Tonga_POWERPLAYTABLE *powerplay_table = | |
4951 | (ATOM_Tonga_POWERPLAYTABLE *)pp_table; | |
4952 | ||
4953 | ATOM_Tonga_SCLK_Dependency_Table *sclk_dep_table = | |
4954 | (ATOM_Tonga_SCLK_Dependency_Table *) | |
4955 | (((uint64_t)powerplay_table) + | |
4956 | le16_to_cpu(powerplay_table->usSclkDependencyTableOffset)); | |
4957 | ||
4958 | ATOM_Tonga_MCLK_Dependency_Table *mclk_dep_table = | |
4959 | (ATOM_Tonga_MCLK_Dependency_Table *) | |
4960 | (((uint64_t)powerplay_table) + | |
4961 | le16_to_cpu(powerplay_table->usMclkDependencyTableOffset)); | |
4962 | ||
4963 | /* The following fields are not initialized here: id orderedList allStatesList */ | |
4964 | power_state->classification.ui_label = | |
4965 | (le16_to_cpu(state_entry->usClassification) & | |
4966 | ATOM_PPLIB_CLASSIFICATION_UI_MASK) >> | |
4967 | ATOM_PPLIB_CLASSIFICATION_UI_SHIFT; | |
4968 | power_state->classification.flags = classification_flag; | |
4969 | /* NOTE: There is a classification2 flag in BIOS that is not being used right now */ | |
4970 | ||
4971 | power_state->classification.temporary_state = false; | |
4972 | power_state->classification.to_be_deleted = false; | |
4973 | ||
4974 | power_state->validation.disallowOnDC = | |
4975 | (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) & ATOM_Tonga_DISALLOW_ON_DC)); | |
4976 | ||
4977 | power_state->pcie.lanes = 0; | |
4978 | ||
4979 | power_state->display.disableFrameModulation = false; | |
4980 | power_state->display.limitRefreshrate = false; | |
4981 | power_state->display.enableVariBright = | |
4982 | (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) & ATOM_Tonga_ENABLE_VARIBRIGHT)); | |
4983 | ||
4984 | power_state->validation.supportedPowerLevels = 0; | |
4985 | power_state->uvd_clocks.VCLK = 0; | |
4986 | power_state->uvd_clocks.DCLK = 0; | |
4987 | power_state->temperatures.min = 0; | |
4988 | power_state->temperatures.max = 0; | |
4989 | ||
4990 | performance_level = &(tonga_ps->performance_levels | |
4991 | [tonga_ps->performance_level_count++]); | |
4992 | ||
4993 | PP_ASSERT_WITH_CODE( | |
4994 | (tonga_ps->performance_level_count < SMU72_MAX_LEVELS_GRAPHICS), | |
4995 | "Performance levels exceeds SMC limit!", | |
4996 | return -1); | |
4997 | ||
4998 | PP_ASSERT_WITH_CODE( | |
4999 | (tonga_ps->performance_level_count <= | |
5000 | hwmgr->platform_descriptor.hardwareActivityPerformanceLevels), | |
5001 | "Performance levels exceeds Driver limit!", | |
5002 | return -1); | |
5003 | ||
5004 | /* Performance levels are arranged from low to high. */ | |
5005 | performance_level->memory_clock = | |
5006 | le32_to_cpu(mclk_dep_table->entries[state_entry->ucMemoryClockIndexLow].ulMclk); | |
5007 | ||
5008 | performance_level->engine_clock = | |
5009 | le32_to_cpu(sclk_dep_table->entries[state_entry->ucEngineClockIndexLow].ulSclk); | |
5010 | ||
5011 | performance_level->pcie_gen = get_pcie_gen_support( | |
5012 | data->pcie_gen_cap, | |
5013 | state_entry->ucPCIEGenLow); | |
5014 | ||
5015 | performance_level->pcie_lane = get_pcie_lane_support( | |
5016 | data->pcie_lane_cap, | |
5017 | state_entry->ucPCIELaneHigh); | |
5018 | ||
5019 | performance_level = | |
5020 | &(tonga_ps->performance_levels[tonga_ps->performance_level_count++]); | |
5021 | ||
5022 | performance_level->memory_clock = | |
5023 | le32_to_cpu(mclk_dep_table->entries[state_entry->ucMemoryClockIndexHigh].ulMclk); | |
5024 | ||
5025 | performance_level->engine_clock = | |
5026 | le32_to_cpu(sclk_dep_table->entries[state_entry->ucEngineClockIndexHigh].ulSclk); | |
5027 | ||
5028 | performance_level->pcie_gen = get_pcie_gen_support( | |
5029 | data->pcie_gen_cap, | |
5030 | state_entry->ucPCIEGenHigh); | |
5031 | ||
5032 | performance_level->pcie_lane = get_pcie_lane_support( | |
5033 | data->pcie_lane_cap, | |
5034 | state_entry->ucPCIELaneHigh); | |
5035 | ||
5036 | return 0; | |
5037 | } | |
5038 | ||
5039 | static int tonga_get_pp_table_entry(struct pp_hwmgr *hwmgr, | |
5040 | unsigned long entry_index, struct pp_power_state *ps) | |
5041 | { | |
5042 | int result; | |
5043 | struct tonga_power_state *tonga_ps; | |
5044 | struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
5045 | ||
5046 | struct phm_ppt_v1_information *table_info = | |
5047 | (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
5048 | ||
5049 | struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table = | |
5050 | table_info->vdd_dep_on_mclk; | |
5051 | ||
5052 | ps->hardware.magic = PhwTonga_Magic; | |
5053 | ||
5054 | tonga_ps = cast_phw_tonga_power_state(&(ps->hardware)); | |
5055 | ||
5056 | result = tonga_get_powerplay_table_entry(hwmgr, entry_index, ps, | |
5057 | tonga_get_pp_table_entry_callback_func); | |
5058 | ||
5059 | /* This is the earliest time we have all the dependency table and the VBIOS boot state | |
5060 | * as PP_Tables_GetPowerPlayTableEntry retrieves the VBIOS boot state | |
5061 | * if there is only one VDDCI/MCLK level, check if it's the same as VBIOS boot state | |
5062 | */ | |
5063 | if (dep_mclk_table != NULL && dep_mclk_table->count == 1) { | |
5064 | if (dep_mclk_table->entries[0].clk != | |
5065 | data->vbios_boot_state.mclk_bootup_value) | |
5066 | printk(KERN_ERR "Single MCLK entry VDDCI/MCLK dependency table " | |
5067 | "does not match VBIOS boot MCLK level"); | |
5068 | if (dep_mclk_table->entries[0].vddci != | |
5069 | data->vbios_boot_state.vddci_bootup_value) | |
5070 | printk(KERN_ERR "Single VDDCI entry VDDCI/MCLK dependency table " | |
5071 | "does not match VBIOS boot VDDCI level"); | |
5072 | } | |
5073 | ||
5074 | /* set DC compatible flag if this state supports DC */ | |
5075 | if (!ps->validation.disallowOnDC) | |
5076 | tonga_ps->dc_compatible = true; | |
5077 | ||
5078 | if (ps->classification.flags & PP_StateClassificationFlag_ACPI) | |
5079 | data->acpi_pcie_gen = tonga_ps->performance_levels[0].pcie_gen; | |
5080 | else if (ps->classification.flags & PP_StateClassificationFlag_Boot) { | |
5081 | if (data->bacos.best_match == 0xffff) { | |
5082 | /* For V.I. use boot state as base BACO state */ | |
5083 | data->bacos.best_match = PP_StateClassificationFlag_Boot; | |
5084 | data->bacos.performance_level = tonga_ps->performance_levels[0]; | |
5085 | } | |
5086 | } | |
5087 | ||
5088 | tonga_ps->uvd_clocks.VCLK = ps->uvd_clocks.VCLK; | |
5089 | tonga_ps->uvd_clocks.DCLK = ps->uvd_clocks.DCLK; | |
5090 | ||
5091 | if (!result) { | |
5092 | uint32_t i; | |
5093 | ||
5094 | switch (ps->classification.ui_label) { | |
5095 | case PP_StateUILabel_Performance: | |
5096 | data->use_pcie_performance_levels = true; | |
5097 | ||
5098 | for (i = 0; i < tonga_ps->performance_level_count; i++) { | |
5099 | if (data->pcie_gen_performance.max < | |
5100 | tonga_ps->performance_levels[i].pcie_gen) | |
5101 | data->pcie_gen_performance.max = | |
5102 | tonga_ps->performance_levels[i].pcie_gen; | |
5103 | ||
5104 | if (data->pcie_gen_performance.min > | |
5105 | tonga_ps->performance_levels[i].pcie_gen) | |
5106 | data->pcie_gen_performance.min = | |
5107 | tonga_ps->performance_levels[i].pcie_gen; | |
5108 | ||
5109 | if (data->pcie_lane_performance.max < | |
5110 | tonga_ps->performance_levels[i].pcie_lane) | |
5111 | data->pcie_lane_performance.max = | |
5112 | tonga_ps->performance_levels[i].pcie_lane; | |
5113 | ||
5114 | if (data->pcie_lane_performance.min > | |
5115 | tonga_ps->performance_levels[i].pcie_lane) | |
5116 | data->pcie_lane_performance.min = | |
5117 | tonga_ps->performance_levels[i].pcie_lane; | |
5118 | } | |
5119 | break; | |
5120 | case PP_StateUILabel_Battery: | |
5121 | data->use_pcie_power_saving_levels = true; | |
5122 | ||
5123 | for (i = 0; i < tonga_ps->performance_level_count; i++) { | |
5124 | if (data->pcie_gen_power_saving.max < | |
5125 | tonga_ps->performance_levels[i].pcie_gen) | |
5126 | data->pcie_gen_power_saving.max = | |
5127 | tonga_ps->performance_levels[i].pcie_gen; | |
5128 | ||
5129 | if (data->pcie_gen_power_saving.min > | |
5130 | tonga_ps->performance_levels[i].pcie_gen) | |
5131 | data->pcie_gen_power_saving.min = | |
5132 | tonga_ps->performance_levels[i].pcie_gen; | |
5133 | ||
5134 | if (data->pcie_lane_power_saving.max < | |
5135 | tonga_ps->performance_levels[i].pcie_lane) | |
5136 | data->pcie_lane_power_saving.max = | |
5137 | tonga_ps->performance_levels[i].pcie_lane; | |
5138 | ||
5139 | if (data->pcie_lane_power_saving.min > | |
5140 | tonga_ps->performance_levels[i].pcie_lane) | |
5141 | data->pcie_lane_power_saving.min = | |
5142 | tonga_ps->performance_levels[i].pcie_lane; | |
5143 | } | |
5144 | break; | |
5145 | default: | |
5146 | break; | |
5147 | } | |
5148 | } | |
5149 | return 0; | |
5150 | } | |
5151 | ||
5152 | static void | |
5153 | tonga_print_current_perforce_level(struct pp_hwmgr *hwmgr, struct seq_file *m) | |
5154 | { | |
5155 | uint32_t sclk, mclk; | |
5156 | ||
5157 | smum_send_msg_to_smc(hwmgr->smumgr, (PPSMC_Msg)(PPSMC_MSG_API_GetSclkFrequency)); | |
5158 | ||
5159 | sclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0); | |
5160 | ||
5161 | smum_send_msg_to_smc(hwmgr->smumgr, (PPSMC_Msg)(PPSMC_MSG_API_GetMclkFrequency)); | |
5162 | ||
5163 | mclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0); | |
5164 | seq_printf(m, "\n [ mclk ]: %u MHz\n\n [ sclk ]: %u MHz\n", mclk/100, sclk/100); | |
5165 | } | |
5166 | ||
5167 | static int tonga_find_dpm_states_clocks_in_dpm_table(struct pp_hwmgr *hwmgr, const void *input) | |
5168 | { | |
5169 | const struct phm_set_power_state_input *states = (const struct phm_set_power_state_input *)input; | |
5170 | const struct tonga_power_state *tonga_ps = cast_const_phw_tonga_power_state(states->pnew_state); | |
5171 | struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
5172 | struct tonga_single_dpm_table *psclk_table = &(data->dpm_table.sclk_table); | |
5173 | uint32_t sclk = tonga_ps->performance_levels[tonga_ps->performance_level_count-1].engine_clock; | |
5174 | struct tonga_single_dpm_table *pmclk_table = &(data->dpm_table.mclk_table); | |
5175 | uint32_t mclk = tonga_ps->performance_levels[tonga_ps->performance_level_count-1].memory_clock; | |
5176 | struct PP_Clocks min_clocks = {0}; | |
5177 | uint32_t i; | |
5178 | struct cgs_display_info info = {0}; | |
5179 | ||
5180 | data->need_update_smu7_dpm_table = 0; | |
5181 | ||
5182 | for (i = 0; i < psclk_table->count; i++) { | |
5183 | if (sclk == psclk_table->dpm_levels[i].value) | |
5184 | break; | |
5185 | } | |
5186 | ||
5187 | if (i >= psclk_table->count) | |
5188 | data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK; | |
5189 | else { | |
5190 | /* TODO: Check SCLK in DAL's minimum clocks in case DeepSleep divider update is required.*/ | |
5191 | if(data->display_timing.min_clock_insr != min_clocks.engineClockInSR) | |
5192 | data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_SCLK; | |
5193 | } | |
5194 | ||
5195 | for (i=0; i < pmclk_table->count; i++) { | |
5196 | if (mclk == pmclk_table->dpm_levels[i].value) | |
5197 | break; | |
5198 | } | |
5199 | ||
5200 | if (i >= pmclk_table->count) | |
5201 | data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_MCLK; | |
5202 | ||
5203 | cgs_get_active_displays_info(hwmgr->device, &info); | |
5204 | ||
5205 | if (data->display_timing.num_existing_displays != info.display_count) | |
5206 | data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_MCLK; | |
5207 | ||
5208 | return 0; | |
5209 | } | |
5210 | ||
5211 | static uint16_t tonga_get_maximum_link_speed(struct pp_hwmgr *hwmgr, const struct tonga_power_state *hw_ps) | |
5212 | { | |
5213 | uint32_t i; | |
5214 | uint32_t sclk, max_sclk = 0; | |
5215 | struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
5216 | struct tonga_dpm_table *pdpm_table = &data->dpm_table; | |
5217 | ||
5218 | for (i = 0; i < hw_ps->performance_level_count; i++) { | |
5219 | sclk = hw_ps->performance_levels[i].engine_clock; | |
5220 | if (max_sclk < sclk) | |
5221 | max_sclk = sclk; | |
5222 | } | |
5223 | ||
5224 | for (i = 0; i < pdpm_table->sclk_table.count; i++) { | |
5225 | if (pdpm_table->sclk_table.dpm_levels[i].value == max_sclk) | |
5226 | return (uint16_t) ((i >= pdpm_table->pcie_speed_table.count) ? | |
5227 | pdpm_table->pcie_speed_table.dpm_levels[pdpm_table->pcie_speed_table.count-1].value : | |
5228 | pdpm_table->pcie_speed_table.dpm_levels[i].value); | |
5229 | } | |
5230 | ||
5231 | return 0; | |
5232 | } | |
5233 | ||
5234 | static int tonga_request_link_speed_change_before_state_change(struct pp_hwmgr *hwmgr, const void *input) | |
5235 | { | |
5236 | const struct phm_set_power_state_input *states = (const struct phm_set_power_state_input *)input; | |
5237 | struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
5238 | const struct tonga_power_state *tonga_nps = cast_const_phw_tonga_power_state(states->pnew_state); | |
5239 | const struct tonga_power_state *tonga_cps = cast_const_phw_tonga_power_state(states->pcurrent_state); | |
5240 | ||
5241 | uint16_t target_link_speed = tonga_get_maximum_link_speed(hwmgr, tonga_nps); | |
5242 | uint16_t current_link_speed; | |
5243 | ||
5244 | if (data->force_pcie_gen == PP_PCIEGenInvalid) | |
5245 | current_link_speed = tonga_get_maximum_link_speed(hwmgr, tonga_cps); | |
5246 | else | |
5247 | current_link_speed = data->force_pcie_gen; | |
5248 | ||
5249 | data->force_pcie_gen = PP_PCIEGenInvalid; | |
5250 | data->pspp_notify_required = false; | |
5251 | if (target_link_speed > current_link_speed) { | |
5252 | switch(target_link_speed) { | |
5253 | case PP_PCIEGen3: | |
5254 | if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN3, false)) | |
5255 | break; | |
5256 | data->force_pcie_gen = PP_PCIEGen2; | |
5257 | if (current_link_speed == PP_PCIEGen2) | |
5258 | break; | |
5259 | case PP_PCIEGen2: | |
5260 | if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN2, false)) | |
5261 | break; | |
5262 | default: | |
5263 | data->force_pcie_gen = tonga_get_current_pcie_speed(hwmgr); | |
5264 | break; | |
5265 | } | |
5266 | } else { | |
5267 | if (target_link_speed < current_link_speed) | |
5268 | data->pspp_notify_required = true; | |
5269 | } | |
5270 | ||
5271 | return 0; | |
5272 | } | |
5273 | ||
5274 | static int tonga_freeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr) | |
5275 | { | |
5276 | struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
5277 | ||
5278 | if (0 == data->need_update_smu7_dpm_table) | |
5279 | return 0; | |
5280 | ||
5281 | if ((0 == data->sclk_dpm_key_disabled) && | |
5282 | (data->need_update_smu7_dpm_table & | |
5283 | (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) { | |
5284 | PP_ASSERT_WITH_CODE( | |
5285 | true == tonga_is_dpm_running(hwmgr), | |
5286 | "Trying to freeze SCLK DPM when DPM is disabled", | |
5287 | ); | |
5288 | PP_ASSERT_WITH_CODE( | |
5289 | 0 == smum_send_msg_to_smc(hwmgr->smumgr, | |
5290 | PPSMC_MSG_SCLKDPM_FreezeLevel), | |
5291 | "Failed to freeze SCLK DPM during FreezeSclkMclkDPM Function!", | |
5292 | return -1); | |
5293 | } | |
5294 | ||
5295 | if ((0 == data->mclk_dpm_key_disabled) && | |
5296 | (data->need_update_smu7_dpm_table & | |
5297 | DPMTABLE_OD_UPDATE_MCLK)) { | |
5298 | PP_ASSERT_WITH_CODE(true == tonga_is_dpm_running(hwmgr), | |
5299 | "Trying to freeze MCLK DPM when DPM is disabled", | |
5300 | ); | |
5301 | PP_ASSERT_WITH_CODE( | |
5302 | 0 == smum_send_msg_to_smc(hwmgr->smumgr, | |
5303 | PPSMC_MSG_MCLKDPM_FreezeLevel), | |
5304 | "Failed to freeze MCLK DPM during FreezeSclkMclkDPM Function!", | |
5305 | return -1); | |
5306 | } | |
5307 | ||
5308 | return 0; | |
5309 | } | |
5310 | ||
5311 | static int tonga_populate_and_upload_sclk_mclk_dpm_levels(struct pp_hwmgr *hwmgr, const void *input) | |
5312 | { | |
5313 | int result = 0; | |
5314 | ||
5315 | const struct phm_set_power_state_input *states = (const struct phm_set_power_state_input *)input; | |
5316 | const struct tonga_power_state *tonga_ps = cast_const_phw_tonga_power_state(states->pnew_state); | |
5317 | struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
5318 | uint32_t sclk = tonga_ps->performance_levels[tonga_ps->performance_level_count-1].engine_clock; | |
5319 | uint32_t mclk = tonga_ps->performance_levels[tonga_ps->performance_level_count-1].memory_clock; | |
5320 | struct tonga_dpm_table *pdpm_table = &data->dpm_table; | |
5321 | ||
5322 | struct tonga_dpm_table *pgolden_dpm_table = &data->golden_dpm_table; | |
5323 | uint32_t dpm_count, clock_percent; | |
5324 | uint32_t i; | |
5325 | ||
5326 | if (0 == data->need_update_smu7_dpm_table) | |
5327 | return 0; | |
5328 | ||
5329 | if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_SCLK) { | |
5330 | pdpm_table->sclk_table.dpm_levels[pdpm_table->sclk_table.count-1].value = sclk; | |
5331 | ||
5332 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinACSupport) || | |
5333 | phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinDCSupport)) { | |
5334 | /* Need to do calculation based on the golden DPM table | |
5335 | * as the Heatmap GPU Clock axis is also based on the default values | |
5336 | */ | |
5337 | PP_ASSERT_WITH_CODE( | |
5338 | (pgolden_dpm_table->sclk_table.dpm_levels[pgolden_dpm_table->sclk_table.count-1].value != 0), | |
5339 | "Divide by 0!", | |
5340 | return -1); | |
5341 | dpm_count = pdpm_table->sclk_table.count < 2 ? 0 : pdpm_table->sclk_table.count-2; | |
5342 | for (i = dpm_count; i > 1; i--) { | |
5343 | if (sclk > pgolden_dpm_table->sclk_table.dpm_levels[pgolden_dpm_table->sclk_table.count-1].value) { | |
5344 | clock_percent = ((sclk - pgolden_dpm_table->sclk_table.dpm_levels[pgolden_dpm_table->sclk_table.count-1].value)*100) / | |
5345 | pgolden_dpm_table->sclk_table.dpm_levels[pgolden_dpm_table->sclk_table.count-1].value; | |
5346 | ||
5347 | pdpm_table->sclk_table.dpm_levels[i].value = | |
5348 | pgolden_dpm_table->sclk_table.dpm_levels[i].value + | |
5349 | (pgolden_dpm_table->sclk_table.dpm_levels[i].value * clock_percent)/100; | |
5350 | ||
5351 | } else if (pgolden_dpm_table->sclk_table.dpm_levels[pdpm_table->sclk_table.count-1].value > sclk) { | |
5352 | clock_percent = ((pgolden_dpm_table->sclk_table.dpm_levels[pgolden_dpm_table->sclk_table.count-1].value - sclk)*100) / | |
5353 | pgolden_dpm_table->sclk_table.dpm_levels[pgolden_dpm_table->sclk_table.count-1].value; | |
5354 | ||
5355 | pdpm_table->sclk_table.dpm_levels[i].value = | |
5356 | pgolden_dpm_table->sclk_table.dpm_levels[i].value - | |
5357 | (pgolden_dpm_table->sclk_table.dpm_levels[i].value * clock_percent)/100; | |
5358 | } else | |
5359 | pdpm_table->sclk_table.dpm_levels[i].value = | |
5360 | pgolden_dpm_table->sclk_table.dpm_levels[i].value; | |
5361 | } | |
5362 | } | |
5363 | } | |
5364 | ||
5365 | if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK) { | |
5366 | pdpm_table->mclk_table.dpm_levels[pdpm_table->mclk_table.count-1].value = mclk; | |
5367 | ||
5368 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinACSupport) || | |
5369 | phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinDCSupport)) { | |
5370 | ||
5371 | PP_ASSERT_WITH_CODE( | |
5372 | (pgolden_dpm_table->mclk_table.dpm_levels[pgolden_dpm_table->mclk_table.count-1].value != 0), | |
5373 | "Divide by 0!", | |
5374 | return -1); | |
5375 | dpm_count = pdpm_table->mclk_table.count < 2? 0 : pdpm_table->mclk_table.count-2; | |
5376 | for (i = dpm_count; i > 1; i--) { | |
5377 | if (mclk > pgolden_dpm_table->mclk_table.dpm_levels[pgolden_dpm_table->mclk_table.count-1].value) { | |
5378 | clock_percent = ((mclk - pgolden_dpm_table->mclk_table.dpm_levels[pgolden_dpm_table->mclk_table.count-1].value)*100) / | |
5379 | pgolden_dpm_table->mclk_table.dpm_levels[pgolden_dpm_table->mclk_table.count-1].value; | |
5380 | ||
5381 | pdpm_table->mclk_table.dpm_levels[i].value = | |
5382 | pgolden_dpm_table->mclk_table.dpm_levels[i].value + | |
5383 | (pgolden_dpm_table->mclk_table.dpm_levels[i].value * clock_percent)/100; | |
5384 | ||
5385 | } else if (pgolden_dpm_table->mclk_table.dpm_levels[pdpm_table->mclk_table.count-1].value > mclk) { | |
5386 | clock_percent = ((pgolden_dpm_table->mclk_table.dpm_levels[pgolden_dpm_table->mclk_table.count-1].value - mclk)*100) / | |
5387 | pgolden_dpm_table->mclk_table.dpm_levels[pgolden_dpm_table->mclk_table.count-1].value; | |
5388 | ||
5389 | pdpm_table->mclk_table.dpm_levels[i].value = | |
5390 | pgolden_dpm_table->mclk_table.dpm_levels[i].value - | |
5391 | (pgolden_dpm_table->mclk_table.dpm_levels[i].value * clock_percent)/100; | |
5392 | } else | |
5393 | pdpm_table->mclk_table.dpm_levels[i].value = pgolden_dpm_table->mclk_table.dpm_levels[i].value; | |
5394 | } | |
5395 | } | |
5396 | } | |
5397 | ||
5398 | if (data->need_update_smu7_dpm_table & (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK)) { | |
5399 | result = tonga_populate_all_memory_levels(hwmgr); | |
5400 | PP_ASSERT_WITH_CODE((0 == result), | |
5401 | "Failed to populate SCLK during PopulateNewDPMClocksStates Function!", | |
5402 | return result); | |
5403 | } | |
5404 | ||
5405 | if (data->need_update_smu7_dpm_table & (DPMTABLE_OD_UPDATE_MCLK + DPMTABLE_UPDATE_MCLK)) { | |
5406 | /*populate MCLK dpm table to SMU7 */ | |
5407 | result = tonga_populate_all_memory_levels(hwmgr); | |
5408 | PP_ASSERT_WITH_CODE((0 == result), | |
5409 | "Failed to populate MCLK during PopulateNewDPMClocksStates Function!", | |
5410 | return result); | |
5411 | } | |
5412 | ||
5413 | return result; | |
5414 | } | |
5415 | ||
5416 | static int tonga_trim_single_dpm_states(struct pp_hwmgr *hwmgr, | |
5417 | struct tonga_single_dpm_table * pdpm_table, | |
5418 | uint32_t low_limit, uint32_t high_limit) | |
5419 | { | |
5420 | uint32_t i; | |
5421 | ||
5422 | for (i = 0; i < pdpm_table->count; i++) { | |
5423 | if ((pdpm_table->dpm_levels[i].value < low_limit) || | |
5424 | (pdpm_table->dpm_levels[i].value > high_limit)) | |
5425 | pdpm_table->dpm_levels[i].enabled = false; | |
5426 | else | |
5427 | pdpm_table->dpm_levels[i].enabled = true; | |
5428 | } | |
5429 | return 0; | |
5430 | } | |
5431 | ||
5432 | static int tonga_trim_dpm_states(struct pp_hwmgr *hwmgr, const struct tonga_power_state *hw_state) | |
5433 | { | |
5434 | int result = 0; | |
5435 | struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
5436 | uint32_t high_limit_count; | |
5437 | ||
5438 | PP_ASSERT_WITH_CODE((hw_state->performance_level_count >= 1), | |
5439 | "power state did not have any performance level", | |
5440 | return -1); | |
5441 | ||
5442 | high_limit_count = (1 == hw_state->performance_level_count) ? 0: 1; | |
5443 | ||
5444 | tonga_trim_single_dpm_states(hwmgr, | |
5445 | &(data->dpm_table.sclk_table), | |
5446 | hw_state->performance_levels[0].engine_clock, | |
5447 | hw_state->performance_levels[high_limit_count].engine_clock); | |
5448 | ||
5449 | tonga_trim_single_dpm_states(hwmgr, | |
5450 | &(data->dpm_table.mclk_table), | |
5451 | hw_state->performance_levels[0].memory_clock, | |
5452 | hw_state->performance_levels[high_limit_count].memory_clock); | |
5453 | ||
5454 | return result; | |
5455 | } | |
5456 | ||
5457 | static int tonga_generate_dpm_level_enable_mask(struct pp_hwmgr *hwmgr, const void *input) | |
5458 | { | |
5459 | int result; | |
5460 | const struct phm_set_power_state_input *states = (const struct phm_set_power_state_input *)input; | |
5461 | struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
5462 | const struct tonga_power_state *tonga_ps = cast_const_phw_tonga_power_state(states->pnew_state); | |
5463 | ||
5464 | ||
5465 | result = tonga_trim_dpm_states(hwmgr, tonga_ps); | |
5466 | if (0 != result) | |
5467 | return result; | |
5468 | ||
5469 | data->dpm_level_enable_mask.sclk_dpm_enable_mask = tonga_get_dpm_level_enable_mask_value(&data->dpm_table.sclk_table); | |
5470 | data->dpm_level_enable_mask.mclk_dpm_enable_mask = tonga_get_dpm_level_enable_mask_value(&data->dpm_table.mclk_table); | |
5471 | data->last_mclk_dpm_enable_mask = data->dpm_level_enable_mask.mclk_dpm_enable_mask; | |
5472 | if (data->uvd_enabled) | |
5473 | data->dpm_level_enable_mask.mclk_dpm_enable_mask &= 0xFFFFFFFE; | |
5474 | ||
5475 | data->dpm_level_enable_mask.pcie_dpm_enable_mask = tonga_get_dpm_level_enable_mask_value(&data->dpm_table.pcie_speed_table); | |
5476 | ||
5477 | return 0; | |
5478 | } | |
5479 | ||
5480 | static int tonga_enable_disable_vce_dpm(struct pp_hwmgr *hwmgr, bool enable) | |
5481 | { | |
5482 | return smum_send_msg_to_smc(hwmgr->smumgr, enable? | |
5483 | (PPSMC_Msg)PPSMC_MSG_VCEDPM_Enable : | |
5484 | (PPSMC_Msg)PPSMC_MSG_VCEDPM_Disable); | |
5485 | } | |
5486 | ||
5487 | static int tonga_update_vce_dpm(struct pp_hwmgr *hwmgr, const void *input) | |
5488 | { | |
5489 | const struct phm_set_power_state_input *states = (const struct phm_set_power_state_input *)input; | |
5490 | struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
5491 | const struct tonga_power_state *tonga_nps = cast_const_phw_tonga_power_state(states->pnew_state); | |
5492 | const struct tonga_power_state *tonga_cps = cast_const_phw_tonga_power_state(states->pcurrent_state); | |
5493 | ||
5494 | uint32_t mm_boot_level_offset, mm_boot_level_value; | |
5495 | struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable); | |
5496 | ||
5497 | if(tonga_nps->vce_clocks.EVCLK >0 && | |
5498 | (tonga_cps == NULL || tonga_cps->vce_clocks.EVCLK == 0)) { | |
5499 | data->smc_state_table.VceBootLevel = (uint8_t) (pptable_info->mm_dep_table->count - 1); | |
5500 | ||
5501 | mm_boot_level_offset = data->dpm_table_start + offsetof(SMU72_Discrete_DpmTable, VceBootLevel); | |
5502 | mm_boot_level_offset /= 4; | |
5503 | mm_boot_level_offset *= 4; | |
5504 | mm_boot_level_value = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, mm_boot_level_offset); | |
5505 | mm_boot_level_value &= 0xFF00FFFF; | |
5506 | mm_boot_level_value |= data->smc_state_table.VceBootLevel << 16; | |
5507 | cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value); | |
5508 | ||
5509 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_StablePState)) { | |
5510 | smum_send_msg_to_smc_with_parameter( | |
5511 | hwmgr->smumgr, | |
5512 | (PPSMC_Msg)(PPSMC_MSG_VCEDPM_SetEnabledMask), | |
5513 | (uint32_t)1 << data->smc_state_table.VceBootLevel); | |
5514 | ||
5515 | tonga_enable_disable_vce_dpm(hwmgr, true); | |
5516 | } else if (tonga_nps->vce_clocks.EVCLK == 0 && tonga_cps != NULL && tonga_cps->vce_clocks.EVCLK > 0) | |
5517 | tonga_enable_disable_vce_dpm(hwmgr, false); | |
5518 | } | |
5519 | ||
5520 | return 0; | |
5521 | } | |
5522 | ||
5523 | static int tonga_update_and_upload_mc_reg_table(struct pp_hwmgr *hwmgr) | |
5524 | { | |
5525 | struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
5526 | ||
5527 | uint32_t address; | |
5528 | int32_t result; | |
5529 | ||
5530 | if (0 == (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) | |
5531 | return 0; | |
5532 | ||
5533 | ||
5534 | memset(&data->mc_reg_table, 0, sizeof(SMU72_Discrete_MCRegisters)); | |
5535 | ||
5536 | result = tonga_convert_mc_reg_table_to_smc(hwmgr, &(data->mc_reg_table)); | |
5537 | ||
5538 | if(result != 0) | |
5539 | return result; | |
5540 | ||
5541 | ||
5542 | address = data->mc_reg_table_start + (uint32_t)offsetof(SMU72_Discrete_MCRegisters, data[0]); | |
5543 | ||
5544 | return tonga_copy_bytes_to_smc(hwmgr->smumgr, address, | |
5545 | (uint8_t *)&data->mc_reg_table.data[0], | |
5546 | sizeof(SMU72_Discrete_MCRegisterSet) * data->dpm_table.mclk_table.count, | |
5547 | data->sram_end); | |
5548 | } | |
5549 | ||
5550 | static int tonga_program_memory_timing_parameters_conditionally(struct pp_hwmgr *hwmgr) | |
5551 | { | |
5552 | struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
5553 | ||
5554 | if (data->need_update_smu7_dpm_table & | |
5555 | (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_OD_UPDATE_MCLK)) | |
5556 | return tonga_program_memory_timing_parameters(hwmgr); | |
5557 | ||
5558 | return 0; | |
5559 | } | |
5560 | ||
5561 | static int tonga_unfreeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr) | |
5562 | { | |
5563 | struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
5564 | ||
5565 | if (0 == data->need_update_smu7_dpm_table) | |
5566 | return 0; | |
5567 | ||
5568 | if ((0 == data->sclk_dpm_key_disabled) && | |
5569 | (data->need_update_smu7_dpm_table & | |
5570 | (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) { | |
5571 | ||
5572 | PP_ASSERT_WITH_CODE(true == tonga_is_dpm_running(hwmgr), | |
5573 | "Trying to Unfreeze SCLK DPM when DPM is disabled", | |
5574 | ); | |
5575 | PP_ASSERT_WITH_CODE( | |
5576 | 0 == smum_send_msg_to_smc(hwmgr->smumgr, | |
5577 | PPSMC_MSG_SCLKDPM_UnfreezeLevel), | |
5578 | "Failed to unfreeze SCLK DPM during UnFreezeSclkMclkDPM Function!", | |
5579 | return -1); | |
5580 | } | |
5581 | ||
5582 | if ((0 == data->mclk_dpm_key_disabled) && | |
5583 | (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) { | |
5584 | ||
5585 | PP_ASSERT_WITH_CODE( | |
5586 | true == tonga_is_dpm_running(hwmgr), | |
5587 | "Trying to Unfreeze MCLK DPM when DPM is disabled", | |
5588 | ); | |
5589 | PP_ASSERT_WITH_CODE( | |
5590 | 0 == smum_send_msg_to_smc(hwmgr->smumgr, | |
5591 | PPSMC_MSG_SCLKDPM_UnfreezeLevel), | |
5592 | "Failed to unfreeze MCLK DPM during UnFreezeSclkMclkDPM Function!", | |
5593 | return -1); | |
5594 | } | |
5595 | ||
5596 | data->need_update_smu7_dpm_table = 0; | |
5597 | ||
5598 | return 0; | |
5599 | } | |
5600 | ||
5601 | static int tonga_notify_link_speed_change_after_state_change(struct pp_hwmgr *hwmgr, const void *input) | |
5602 | { | |
5603 | const struct phm_set_power_state_input *states = (const struct phm_set_power_state_input *)input; | |
5604 | struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend); | |
5605 | const struct tonga_power_state *tonga_ps = cast_const_phw_tonga_power_state(states->pnew_state); | |
5606 | uint16_t target_link_speed = tonga_get_maximum_link_speed(hwmgr, tonga_ps); | |
5607 | uint8_t request; | |
5608 | ||
5609 | if (data->pspp_notify_required || | |
5610 | data->pcie_performance_request) { | |
5611 | if (target_link_speed == PP_PCIEGen3) | |
5612 | request = PCIE_PERF_REQ_GEN3; | |
5613 | else if (target_link_speed == PP_PCIEGen2) | |
5614 | request = PCIE_PERF_REQ_GEN2; | |
5615 | else | |
5616 | request = PCIE_PERF_REQ_GEN1; | |
5617 | ||
5618 | if(request == PCIE_PERF_REQ_GEN1 && tonga_get_current_pcie_speed(hwmgr) > 0) { | |
5619 | data->pcie_performance_request = false; | |
5620 | return 0; | |
5621 | } | |
5622 | ||
5623 | if (0 != acpi_pcie_perf_request(hwmgr->device, request, false)) { | |
5624 | if (PP_PCIEGen2 == target_link_speed) | |
5625 | printk("PSPP request to switch to Gen2 from Gen3 Failed!"); | |
5626 | else | |
5627 | printk("PSPP request to switch to Gen1 from Gen2 Failed!"); | |
5628 | } | |
5629 | } | |
5630 | ||
5631 | data->pcie_performance_request = false; | |
5632 | return 0; | |
5633 | } | |
5634 | ||
5635 | static int tonga_set_power_state_tasks(struct pp_hwmgr *hwmgr, const void *input) | |
5636 | { | |
5637 | int tmp_result, result = 0; | |
5638 | ||
5639 | tmp_result = tonga_find_dpm_states_clocks_in_dpm_table(hwmgr, input); | |
5640 | PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to find DPM states clocks in DPM table!", result = tmp_result); | |
5641 | ||
5642 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_PCIEPerformanceRequest)) { | |
5643 | tmp_result = tonga_request_link_speed_change_before_state_change(hwmgr, input); | |
5644 | PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to request link speed change before state change!", result = tmp_result); | |
5645 | } | |
5646 | ||
5647 | tmp_result = tonga_freeze_sclk_mclk_dpm(hwmgr); | |
5648 | PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to freeze SCLK MCLK DPM!", result = tmp_result); | |
5649 | ||
5650 | tmp_result = tonga_populate_and_upload_sclk_mclk_dpm_levels(hwmgr, input); | |
5651 | PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to populate and upload SCLK MCLK DPM levels!", result = tmp_result); | |
5652 | ||
5653 | tmp_result = tonga_generate_dpm_level_enable_mask(hwmgr, input); | |
5654 | PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to generate DPM level enabled mask!", result = tmp_result); | |
5655 | ||
5656 | tmp_result = tonga_update_vce_dpm(hwmgr, input); | |
5657 | PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to update VCE DPM!", result = tmp_result); | |
5658 | ||
5659 | tmp_result = tonga_update_sclk_threshold(hwmgr); | |
5660 | PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to update SCLK threshold!", result = tmp_result); | |
5661 | ||
5662 | tmp_result = tonga_update_and_upload_mc_reg_table(hwmgr); | |
5663 | PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to upload MC reg table!", result = tmp_result); | |
5664 | ||
5665 | tmp_result = tonga_program_memory_timing_parameters_conditionally(hwmgr); | |
5666 | PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to program memory timing parameters!", result = tmp_result); | |
5667 | ||
5668 | tmp_result = tonga_unfreeze_sclk_mclk_dpm(hwmgr); | |
5669 | PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to unfreeze SCLK MCLK DPM!", result = tmp_result); | |
5670 | ||
5671 | tmp_result = tonga_upload_dpm_level_enable_mask(hwmgr); | |
5672 | PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to upload DPM level enabled mask!", result = tmp_result); | |
5673 | ||
5674 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_PCIEPerformanceRequest)) { | |
5675 | tmp_result = tonga_notify_link_speed_change_after_state_change(hwmgr, input); | |
5676 | PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to notify link speed change after state change!", result = tmp_result); | |
5677 | } | |
5678 | ||
5679 | return result; | |
5680 | } | |
5681 | ||
5682 | static const struct pp_hwmgr_func tonga_hwmgr_funcs = { | |
5683 | .backend_init = &tonga_hwmgr_backend_init, | |
5684 | .backend_fini = &tonga_hwmgr_backend_fini, | |
5685 | .asic_setup = &tonga_setup_asic_task, | |
5686 | .dynamic_state_management_enable = &tonga_enable_dpm_tasks, | |
5687 | .apply_state_adjust_rules = tonga_apply_state_adjust_rules, | |
5688 | .force_dpm_level = &tonga_force_dpm_level, | |
5689 | .power_state_set = tonga_set_power_state_tasks, | |
5690 | .get_power_state_size = tonga_get_power_state_size, | |
5691 | .get_mclk = tonga_dpm_get_mclk, | |
5692 | .get_sclk = tonga_dpm_get_sclk, | |
5693 | .patch_boot_state = tonga_dpm_patch_boot_state, | |
5694 | .get_pp_table_entry = tonga_get_pp_table_entry, | |
5695 | .get_num_of_pp_table_entries = tonga_get_number_of_powerplay_table_entries, | |
5696 | .print_current_perforce_level = tonga_print_current_perforce_level, | |
5697 | }; | |
5698 | ||
5699 | int tonga_hwmgr_init(struct pp_hwmgr *hwmgr) | |
5700 | { | |
5701 | tonga_hwmgr *data; | |
5702 | ||
5703 | data = kzalloc (sizeof(tonga_hwmgr), GFP_KERNEL); | |
5704 | if (data == NULL) | |
5705 | return -ENOMEM; | |
5706 | memset(data, 0x00, sizeof(tonga_hwmgr)); | |
5707 | ||
5708 | hwmgr->backend = data; | |
5709 | hwmgr->hwmgr_func = &tonga_hwmgr_funcs; | |
5710 | hwmgr->pptable_func = &tonga_pptable_funcs; | |
5711 | ||
5712 | return 0; | |
5713 | } | |
5714 |