2 * Copyright 2015 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 #include "polaris10_hwmgr.h"
27 #include "polaris10_powertune.h"
28 #include "polaris10_smumgr.h"
29 #include "smu74_discrete.h"
32 #define VOLTAGE_SCALE 4
33 #define POWERTUNE_DEFAULT_SET_MAX 1
35 static const struct polaris10_pt_defaults polaris10_power_tune_data_set_array[POWERTUNE_DEFAULT_SET_MAX] = {
36 /* sviLoadLIneEn, SviLoadLineVddC, TDC_VDDC_ThrottleReleaseLimitPerc, TDC_MAWt,
37 * TdcWaterfallCtl, DTEAmbientTempBase, DisplayCac, BAPM_TEMP_GRADIENT */
38 { 1, 0xF, 0xFD, 0x19, 5, 45, 0, 0xB0000,
39 { 0x79, 0x253, 0x25D, 0xAE, 0x72, 0x80, 0x83, 0x86, 0x6F, 0xC8, 0xC9, 0xC9, 0x2F, 0x4D, 0x61},
40 { 0x17C, 0x172, 0x180, 0x1BC, 0x1B3, 0x1BD, 0x206, 0x200, 0x203, 0x25D, 0x25A, 0x255, 0x2C3, 0x2C5, 0x2B4 } },
43 void polaris10_initialize_power_tune_defaults(struct pp_hwmgr *hwmgr)
45 struct polaris10_hwmgr *polaris10_hwmgr = (struct polaris10_hwmgr *)(hwmgr->backend);
46 struct phm_ppt_v1_information *table_info =
47 (struct phm_ppt_v1_information *)(hwmgr->pptable);
50 table_info->cac_dtp_table->usPowerTuneDataSetID <= POWERTUNE_DEFAULT_SET_MAX &&
51 table_info->cac_dtp_table->usPowerTuneDataSetID)
52 polaris10_hwmgr->power_tune_defaults =
53 &polaris10_power_tune_data_set_array
54 [table_info->cac_dtp_table->usPowerTuneDataSetID - 1];
56 polaris10_hwmgr->power_tune_defaults = &polaris10_power_tune_data_set_array[0];
60 static uint16_t scale_fan_gain_settings(uint16_t raw_setting)
63 tmp = raw_setting * 4096 / 100;
67 int polaris10_populate_bapm_parameters_in_dpm_table(struct pp_hwmgr *hwmgr)
69 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
70 const struct polaris10_pt_defaults *defaults = data->power_tune_defaults;
71 SMU74_Discrete_DpmTable *dpm_table = &(data->smc_state_table);
72 struct phm_ppt_v1_information *table_info =
73 (struct phm_ppt_v1_information *)(hwmgr->pptable);
74 struct phm_cac_tdp_table *cac_dtp_table = table_info->cac_dtp_table;
75 struct pp_advance_fan_control_parameters *fan_table=
76 &hwmgr->thermal_controller.advanceFanControlParameters;
78 const uint16_t *pdef1;
79 const uint16_t *pdef2;
81 dpm_table->DefaultTdp = PP_HOST_TO_SMC_US((uint16_t)(cac_dtp_table->usTDP * 128));
82 dpm_table->TargetTdp = PP_HOST_TO_SMC_US((uint16_t)(cac_dtp_table->usTDP * 128));
84 PP_ASSERT_WITH_CODE(cac_dtp_table->usTargetOperatingTemp <= 255,
85 "Target Operating Temp is out of Range!",
88 dpm_table->TemperatureLimitEdge = PP_HOST_TO_SMC_US(
89 cac_dtp_table->usTargetOperatingTemp * 256);
90 dpm_table->TemperatureLimitHotspot = PP_HOST_TO_SMC_US(
91 cac_dtp_table->usTemperatureLimitHotspot * 256);
92 dpm_table->FanGainEdge = PP_HOST_TO_SMC_US(
93 scale_fan_gain_settings(fan_table->usFanGainEdge));
94 dpm_table->FanGainHotspot = PP_HOST_TO_SMC_US(
95 scale_fan_gain_settings(fan_table->usFanGainHotspot));
97 pdef1 = defaults->BAPMTI_R;
98 pdef2 = defaults->BAPMTI_RC;
100 for (i = 0; i < SMU74_DTE_ITERATIONS; i++) {
101 for (j = 0; j < SMU74_DTE_SOURCES; j++) {
102 for (k = 0; k < SMU74_DTE_SINKS; k++) {
103 dpm_table->BAPMTI_R[i][j][k] = PP_HOST_TO_SMC_US(*pdef1);
104 dpm_table->BAPMTI_RC[i][j][k] = PP_HOST_TO_SMC_US(*pdef2);
114 static int polaris10_populate_svi_load_line(struct pp_hwmgr *hwmgr)
116 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
117 const struct polaris10_pt_defaults *defaults = data->power_tune_defaults;
119 data->power_tune_table.SviLoadLineEn = defaults->SviLoadLineEn;
120 data->power_tune_table.SviLoadLineVddC = defaults->SviLoadLineVddC;
121 data->power_tune_table.SviLoadLineTrimVddC = 3;
122 data->power_tune_table.SviLoadLineOffsetVddC = 0;
127 static int polaris10_populate_tdc_limit(struct pp_hwmgr *hwmgr)
130 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
131 struct phm_ppt_v1_information *table_info =
132 (struct phm_ppt_v1_information *)(hwmgr->pptable);
133 const struct polaris10_pt_defaults *defaults = data->power_tune_defaults;
135 tdc_limit = (uint16_t)(table_info->cac_dtp_table->usTDC * 128);
136 data->power_tune_table.TDC_VDDC_PkgLimit =
137 CONVERT_FROM_HOST_TO_SMC_US(tdc_limit);
138 data->power_tune_table.TDC_VDDC_ThrottleReleaseLimitPerc =
139 defaults->TDC_VDDC_ThrottleReleaseLimitPerc;
140 data->power_tune_table.TDC_MAWt = defaults->TDC_MAWt;
145 static int polaris10_populate_dw8(struct pp_hwmgr *hwmgr, uint32_t fuse_table_offset)
147 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
148 const struct polaris10_pt_defaults *defaults = data->power_tune_defaults;
151 if (polaris10_read_smc_sram_dword(hwmgr->smumgr,
153 offsetof(SMU74_Discrete_PmFuses, TdcWaterfallCtl),
154 (uint32_t *)&temp, data->sram_end))
155 PP_ASSERT_WITH_CODE(false,
156 "Attempt to read PmFuses.DW6 (SviLoadLineEn) from SMC Failed!",
159 data->power_tune_table.TdcWaterfallCtl = defaults->TdcWaterfallCtl;
160 data->power_tune_table.LPMLTemperatureMin =
161 (uint8_t)((temp >> 16) & 0xff);
162 data->power_tune_table.LPMLTemperatureMax =
163 (uint8_t)((temp >> 8) & 0xff);
164 data->power_tune_table.Reserved = (uint8_t)(temp & 0xff);
169 static int polaris10_populate_temperature_scaler(struct pp_hwmgr *hwmgr)
172 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
174 /* Currently not used. Set all to zero. */
175 for (i = 0; i < 16; i++)
176 data->power_tune_table.LPMLTemperatureScaler[i] = 0;
181 static int polaris10_populate_fuzzy_fan(struct pp_hwmgr *hwmgr)
183 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
185 if ((hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity & (1 << 15))
186 || 0 == hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity)
187 hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity =
188 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultFanOutputSensitivity;
190 data->power_tune_table.FuzzyFan_PwmSetDelta = PP_HOST_TO_SMC_US(
191 hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity);
195 static int polaris10_populate_gnb_lpml(struct pp_hwmgr *hwmgr)
198 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
200 /* Currently not used. Set all to zero. */
201 for (i = 0; i < 16; i++)
202 data->power_tune_table.GnbLPML[i] = 0;
207 static int polaris10_min_max_vgnb_lpml_id_from_bapm_vddc(struct pp_hwmgr *hwmgr)
212 static int polaris10_populate_bapm_vddc_base_leakage_sidd(struct pp_hwmgr *hwmgr)
214 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
215 struct phm_ppt_v1_information *table_info =
216 (struct phm_ppt_v1_information *)(hwmgr->pptable);
217 uint16_t hi_sidd = data->power_tune_table.BapmVddCBaseLeakageHiSidd;
218 uint16_t lo_sidd = data->power_tune_table.BapmVddCBaseLeakageLoSidd;
219 struct phm_cac_tdp_table *cac_table = table_info->cac_dtp_table;
221 hi_sidd = (uint16_t)(cac_table->usHighCACLeakage / 100 * 256);
222 lo_sidd = (uint16_t)(cac_table->usLowCACLeakage / 100 * 256);
224 data->power_tune_table.BapmVddCBaseLeakageHiSidd =
225 CONVERT_FROM_HOST_TO_SMC_US(hi_sidd);
226 data->power_tune_table.BapmVddCBaseLeakageLoSidd =
227 CONVERT_FROM_HOST_TO_SMC_US(lo_sidd);
232 int polaris10_populate_pm_fuses(struct pp_hwmgr *hwmgr)
234 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
235 uint32_t pm_fuse_table_offset;
237 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
238 PHM_PlatformCaps_PowerContainment)) {
239 if (polaris10_read_smc_sram_dword(hwmgr->smumgr,
240 SMU7_FIRMWARE_HEADER_LOCATION +
241 offsetof(SMU74_Firmware_Header, PmFuseTable),
242 &pm_fuse_table_offset, data->sram_end))
243 PP_ASSERT_WITH_CODE(false,
244 "Attempt to get pm_fuse_table_offset Failed!",
247 if (polaris10_populate_svi_load_line(hwmgr))
248 PP_ASSERT_WITH_CODE(false,
249 "Attempt to populate SviLoadLine Failed!",
252 if (polaris10_populate_tdc_limit(hwmgr))
253 PP_ASSERT_WITH_CODE(false,
254 "Attempt to populate TDCLimit Failed!", return -EINVAL);
256 if (polaris10_populate_dw8(hwmgr, pm_fuse_table_offset))
257 PP_ASSERT_WITH_CODE(false,
258 "Attempt to populate TdcWaterfallCtl, "
259 "LPMLTemperature Min and Max Failed!",
262 if (0 != polaris10_populate_temperature_scaler(hwmgr))
263 PP_ASSERT_WITH_CODE(false,
264 "Attempt to populate LPMLTemperatureScaler Failed!",
267 if (polaris10_populate_fuzzy_fan(hwmgr))
268 PP_ASSERT_WITH_CODE(false,
269 "Attempt to populate Fuzzy Fan Control parameters Failed!",
272 if (polaris10_populate_gnb_lpml(hwmgr))
273 PP_ASSERT_WITH_CODE(false,
274 "Attempt to populate GnbLPML Failed!",
277 if (polaris10_min_max_vgnb_lpml_id_from_bapm_vddc(hwmgr))
278 PP_ASSERT_WITH_CODE(false,
279 "Attempt to populate GnbLPML Min and Max Vid Failed!",
282 if (polaris10_populate_bapm_vddc_base_leakage_sidd(hwmgr))
283 PP_ASSERT_WITH_CODE(false,
284 "Attempt to populate BapmVddCBaseLeakage Hi and Lo "
285 "Sidd Failed!", return -EINVAL);
287 if (polaris10_copy_bytes_to_smc(hwmgr->smumgr, pm_fuse_table_offset,
288 (uint8_t *)&data->power_tune_table,
289 sizeof(struct SMU74_Discrete_PmFuses), data->sram_end))
290 PP_ASSERT_WITH_CODE(false,
291 "Attempt to download PmFuseTable Failed!",
297 int polaris10_enable_smc_cac(struct pp_hwmgr *hwmgr)
299 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
302 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
303 PHM_PlatformCaps_CAC)) {
305 smc_result = smum_send_msg_to_smc(hwmgr->smumgr,
306 (uint16_t)(PPSMC_MSG_EnableCac));
307 PP_ASSERT_WITH_CODE((0 == smc_result),
308 "Failed to enable CAC in SMC.", result = -1);
310 data->cac_enabled = (0 == smc_result) ? true : false;
315 int polaris10_set_power_limit(struct pp_hwmgr *hwmgr, uint32_t n)
317 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
319 if (data->power_containment_features &
320 POWERCONTAINMENT_FEATURE_PkgPwrLimit)
321 return smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
322 PPSMC_MSG_PkgPwrSetLimit, n);
326 static int polaris10_set_overdriver_target_tdp(struct pp_hwmgr *pHwMgr, uint32_t target_tdp)
328 return smum_send_msg_to_smc_with_parameter(pHwMgr->smumgr,
329 PPSMC_MSG_OverDriveSetTargetTdp, target_tdp);
332 int polaris10_enable_power_containment(struct pp_hwmgr *hwmgr)
334 struct polaris10_hwmgr *data = (struct polaris10_hwmgr *)(hwmgr->backend);
335 struct phm_ppt_v1_information *table_info =
336 (struct phm_ppt_v1_information *)(hwmgr->pptable);
340 data->power_containment_features = 0;
341 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
342 PHM_PlatformCaps_PowerContainment)) {
344 if (data->enable_tdc_limit_feature) {
345 smc_result = smum_send_msg_to_smc(hwmgr->smumgr,
346 (uint16_t)(PPSMC_MSG_TDCLimitEnable));
347 PP_ASSERT_WITH_CODE((0 == smc_result),
348 "Failed to enable TDCLimit in SMC.", result = -1;);
350 data->power_containment_features |=
351 POWERCONTAINMENT_FEATURE_TDCLimit;
354 if (data->enable_pkg_pwr_tracking_feature) {
355 smc_result = smum_send_msg_to_smc(hwmgr->smumgr,
356 (uint16_t)(PPSMC_MSG_PkgPwrLimitEnable));
357 PP_ASSERT_WITH_CODE((0 == smc_result),
358 "Failed to enable PkgPwrTracking in SMC.", result = -1;);
359 if (0 == smc_result) {
360 struct phm_cac_tdp_table *cac_table =
361 table_info->cac_dtp_table;
362 uint32_t default_limit =
363 (uint32_t)(cac_table->usMaximumPowerDeliveryLimit * 256);
365 data->power_containment_features |=
366 POWERCONTAINMENT_FEATURE_PkgPwrLimit;
368 if (polaris10_set_power_limit(hwmgr, default_limit))
369 printk(KERN_ERR "Failed to set Default Power Limit in SMC!");
376 int polaris10_power_control_set_level(struct pp_hwmgr *hwmgr)
378 struct phm_ppt_v1_information *table_info =
379 (struct phm_ppt_v1_information *)(hwmgr->pptable);
380 struct phm_cac_tdp_table *cac_table = table_info->cac_dtp_table;
381 int adjust_percent, target_tdp;
384 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
385 PHM_PlatformCaps_PowerContainment)) {
386 /* adjustment percentage has already been validated */
387 adjust_percent = hwmgr->platform_descriptor.TDPAdjustmentPolarity ?
388 hwmgr->platform_descriptor.TDPAdjustment :
389 (-1 * hwmgr->platform_descriptor.TDPAdjustment);
390 /* SMC requested that target_tdp to be 7 bit fraction in DPM table
391 * but message to be 8 bit fraction for messages
393 target_tdp = ((100 + adjust_percent) * (int)(cac_table->usTDP * 256)) / 100;
394 result = polaris10_set_overdriver_target_tdp(hwmgr, (uint32_t)target_tdp);