2 * Copyright 2019 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.
25 #include <linux/firmware.h>
27 #include "amdgpu_smu.h"
28 #include "atomfirmware.h"
29 #include "amdgpu_atomfirmware.h"
30 #include "smu_v11_0.h"
31 #include "smu11_driver_if.h"
32 #include "soc15_common.h"
34 #include "power_state.h"
35 #include "vega20_ppt.h"
36 #include "vega20_pptable.h"
37 #include "vega20_ppsmc.h"
38 #include "nbio/nbio_7_4_sh_mask.h"
39 #include "asic_reg/thm/thm_11_0_2_offset.h"
40 #include "asic_reg/thm/thm_11_0_2_sh_mask.h"
42 #define smnPCIE_LC_SPEED_CNTL 0x11140290
43 #define smnPCIE_LC_LINK_WIDTH_CNTL 0x11140288
45 #define CTF_OFFSET_EDGE 5
46 #define CTF_OFFSET_HOTSPOT 5
47 #define CTF_OFFSET_HBM 5
49 #define MSG_MAP(msg) \
50 [SMU_MSG_##msg] = {1, PPSMC_MSG_##msg}
52 #define SMC_DPM_FEATURE (FEATURE_DPM_PREFETCHER_MASK | \
53 FEATURE_DPM_GFXCLK_MASK | \
54 FEATURE_DPM_UCLK_MASK | \
55 FEATURE_DPM_SOCCLK_MASK | \
56 FEATURE_DPM_UVD_MASK | \
57 FEATURE_DPM_VCE_MASK | \
58 FEATURE_DPM_MP0CLK_MASK | \
59 FEATURE_DPM_LINK_MASK | \
60 FEATURE_DPM_DCEFCLK_MASK)
62 static struct smu_11_0_cmn2aisc_mapping vega20_message_map[SMU_MSG_MAX_COUNT] = {
64 MSG_MAP(GetSmuVersion),
65 MSG_MAP(GetDriverIfVersion),
66 MSG_MAP(SetAllowedFeaturesMaskLow),
67 MSG_MAP(SetAllowedFeaturesMaskHigh),
68 MSG_MAP(EnableAllSmuFeatures),
69 MSG_MAP(DisableAllSmuFeatures),
70 MSG_MAP(EnableSmuFeaturesLow),
71 MSG_MAP(EnableSmuFeaturesHigh),
72 MSG_MAP(DisableSmuFeaturesLow),
73 MSG_MAP(DisableSmuFeaturesHigh),
74 MSG_MAP(GetEnabledSmuFeaturesLow),
75 MSG_MAP(GetEnabledSmuFeaturesHigh),
76 MSG_MAP(SetWorkloadMask),
78 MSG_MAP(SetDriverDramAddrHigh),
79 MSG_MAP(SetDriverDramAddrLow),
80 MSG_MAP(SetToolsDramAddrHigh),
81 MSG_MAP(SetToolsDramAddrLow),
82 MSG_MAP(TransferTableSmu2Dram),
83 MSG_MAP(TransferTableDram2Smu),
84 MSG_MAP(UseDefaultPPTable),
85 MSG_MAP(UseBackupPPTable),
87 MSG_MAP(RequestI2CBus),
88 MSG_MAP(ReleaseI2CBus),
89 MSG_MAP(SetFloorSocVoltage),
91 MSG_MAP(StartBacoMonitor),
92 MSG_MAP(CancelBacoMonitor),
94 MSG_MAP(SetSoftMinByFreq),
95 MSG_MAP(SetSoftMaxByFreq),
96 MSG_MAP(SetHardMinByFreq),
97 MSG_MAP(SetHardMaxByFreq),
98 MSG_MAP(GetMinDpmFreq),
99 MSG_MAP(GetMaxDpmFreq),
100 MSG_MAP(GetDpmFreqByIndex),
101 MSG_MAP(GetDpmClockFreq),
102 MSG_MAP(GetSsVoltageByDpm),
103 MSG_MAP(SetMemoryChannelConfig),
104 MSG_MAP(SetGeminiMode),
105 MSG_MAP(SetGeminiApertureHigh),
106 MSG_MAP(SetGeminiApertureLow),
107 MSG_MAP(SetMinLinkDpmByIndex),
108 MSG_MAP(OverridePcieParameters),
109 MSG_MAP(OverDriveSetPercentage),
110 MSG_MAP(SetMinDeepSleepDcefclk),
111 MSG_MAP(ReenableAcDcInterrupt),
112 MSG_MAP(NotifyPowerSource),
113 MSG_MAP(SetUclkFastSwitch),
114 MSG_MAP(SetUclkDownHyst),
115 MSG_MAP(GetCurrentRpm),
116 MSG_MAP(SetVideoFps),
118 MSG_MAP(SetFanTemperatureTarget),
119 MSG_MAP(PrepareMp1ForUnload),
120 MSG_MAP(DramLogSetDramAddrHigh),
121 MSG_MAP(DramLogSetDramAddrLow),
122 MSG_MAP(DramLogSetDramSize),
123 MSG_MAP(SetFanMaxRpm),
124 MSG_MAP(SetFanMinPwm),
125 MSG_MAP(ConfigureGfxDidt),
126 MSG_MAP(NumOfDisplays),
127 MSG_MAP(RemoveMargins),
128 MSG_MAP(ReadSerialNumTop32),
129 MSG_MAP(ReadSerialNumBottom32),
130 MSG_MAP(SetSystemVirtualDramAddrHigh),
131 MSG_MAP(SetSystemVirtualDramAddrLow),
133 MSG_MAP(SetFclkGfxClkRatio),
134 MSG_MAP(AllowGfxOff),
135 MSG_MAP(DisallowGfxOff),
136 MSG_MAP(GetPptLimit),
137 MSG_MAP(GetDcModeMaxDpmFreq),
138 MSG_MAP(GetDebugData),
139 MSG_MAP(SetXgmiMode),
142 MSG_MAP(PrepareMp1ForReset),
143 MSG_MAP(PrepareMp1ForShutdown),
144 MSG_MAP(SetMGpuFanBoostLimitRpm),
145 MSG_MAP(GetAVFSVoltageByDpm),
148 static struct smu_11_0_cmn2aisc_mapping vega20_clk_map[SMU_CLK_COUNT] = {
149 CLK_MAP(GFXCLK, PPCLK_GFXCLK),
150 CLK_MAP(VCLK, PPCLK_VCLK),
151 CLK_MAP(DCLK, PPCLK_DCLK),
152 CLK_MAP(ECLK, PPCLK_ECLK),
153 CLK_MAP(SOCCLK, PPCLK_SOCCLK),
154 CLK_MAP(UCLK, PPCLK_UCLK),
155 CLK_MAP(DCEFCLK, PPCLK_DCEFCLK),
156 CLK_MAP(DISPCLK, PPCLK_DISPCLK),
157 CLK_MAP(PIXCLK, PPCLK_PIXCLK),
158 CLK_MAP(PHYCLK, PPCLK_PHYCLK),
159 CLK_MAP(FCLK, PPCLK_FCLK),
162 static struct smu_11_0_cmn2aisc_mapping vega20_feature_mask_map[SMU_FEATURE_COUNT] = {
163 FEA_MAP(DPM_PREFETCHER),
172 FEA_MAP(DPM_DCEFCLK),
179 FEA_MAP(GFX_PER_CU_CG),
186 FEA_MAP(LED_DISPLAY),
187 FEA_MAP(FAN_CONTROL),
198 static struct smu_11_0_cmn2aisc_mapping vega20_table_map[SMU_TABLE_COUNT] = {
202 TAB_MAP(AVFS_PSM_DEBUG),
203 TAB_MAP(AVFS_FUSE_OVERRIDE),
204 TAB_MAP(PMSTATUSLOG),
205 TAB_MAP(SMU_METRICS),
206 TAB_MAP(DRIVER_SMU_CONFIG),
207 TAB_MAP(ACTIVITY_MONITOR_COEFF),
211 static struct smu_11_0_cmn2aisc_mapping vega20_pwr_src_map[SMU_POWER_SOURCE_COUNT] = {
216 static struct smu_11_0_cmn2aisc_mapping vega20_workload_map[PP_SMC_POWER_PROFILE_COUNT] = {
217 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT, WORKLOAD_DEFAULT_BIT),
218 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_FULLSCREEN3D, WORKLOAD_PPLIB_FULL_SCREEN_3D_BIT),
219 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_POWERSAVING, WORKLOAD_PPLIB_POWER_SAVING_BIT),
220 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_VIDEO, WORKLOAD_PPLIB_VIDEO_BIT),
221 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_VR, WORKLOAD_PPLIB_VR_BIT),
222 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_COMPUTE, WORKLOAD_PPLIB_CUSTOM_BIT),
223 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_CUSTOM, WORKLOAD_PPLIB_CUSTOM_BIT),
226 static int vega20_get_smu_table_index(struct smu_context *smc, uint32_t index)
228 struct smu_11_0_cmn2aisc_mapping mapping;
230 if (index >= SMU_TABLE_COUNT)
233 mapping = vega20_table_map[index];
234 if (!(mapping.valid_mapping)) {
238 return mapping.map_to;
241 static int vega20_get_pwr_src_index(struct smu_context *smc, uint32_t index)
243 struct smu_11_0_cmn2aisc_mapping mapping;
245 if (index >= SMU_POWER_SOURCE_COUNT)
248 mapping = vega20_pwr_src_map[index];
249 if (!(mapping.valid_mapping)) {
253 return mapping.map_to;
256 static int vega20_get_smu_feature_index(struct smu_context *smc, uint32_t index)
258 struct smu_11_0_cmn2aisc_mapping mapping;
260 if (index >= SMU_FEATURE_COUNT)
263 mapping = vega20_feature_mask_map[index];
264 if (!(mapping.valid_mapping)) {
268 return mapping.map_to;
271 static int vega20_get_smu_clk_index(struct smu_context *smc, uint32_t index)
273 struct smu_11_0_cmn2aisc_mapping mapping;
275 if (index >= SMU_CLK_COUNT)
278 mapping = vega20_clk_map[index];
279 if (!(mapping.valid_mapping)) {
283 return mapping.map_to;
286 static int vega20_get_smu_msg_index(struct smu_context *smc, uint32_t index)
288 struct smu_11_0_cmn2aisc_mapping mapping;
290 if (index >= SMU_MSG_MAX_COUNT)
293 mapping = vega20_message_map[index];
294 if (!(mapping.valid_mapping)) {
298 return mapping.map_to;
301 static int vega20_get_workload_type(struct smu_context *smu, enum PP_SMC_POWER_PROFILE profile)
303 struct smu_11_0_cmn2aisc_mapping mapping;
305 if (profile > PP_SMC_POWER_PROFILE_CUSTOM)
308 mapping = vega20_workload_map[profile];
309 if (!(mapping.valid_mapping)) {
313 return mapping.map_to;
316 static int vega20_tables_init(struct smu_context *smu, struct smu_table *tables)
318 struct smu_table_context *smu_table = &smu->smu_table;
320 SMU_TABLE_INIT(tables, SMU_TABLE_PPTABLE, sizeof(PPTable_t),
321 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
322 SMU_TABLE_INIT(tables, SMU_TABLE_WATERMARKS, sizeof(Watermarks_t),
323 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
324 SMU_TABLE_INIT(tables, SMU_TABLE_SMU_METRICS, sizeof(SmuMetrics_t),
325 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
326 SMU_TABLE_INIT(tables, SMU_TABLE_OVERDRIVE, sizeof(OverDriveTable_t),
327 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
328 SMU_TABLE_INIT(tables, SMU_TABLE_PMSTATUSLOG, SMU11_TOOL_SIZE,
329 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
330 SMU_TABLE_INIT(tables, SMU_TABLE_ACTIVITY_MONITOR_COEFF,
331 sizeof(DpmActivityMonitorCoeffInt_t), PAGE_SIZE,
332 AMDGPU_GEM_DOMAIN_VRAM);
334 smu_table->metrics_table = kzalloc(sizeof(SmuMetrics_t), GFP_KERNEL);
335 if (!smu_table->metrics_table)
337 smu_table->metrics_time = 0;
342 static int vega20_allocate_dpm_context(struct smu_context *smu)
344 struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
346 if (smu_dpm->dpm_context)
349 smu_dpm->dpm_context = kzalloc(sizeof(struct vega20_dpm_table),
351 if (!smu_dpm->dpm_context)
354 if (smu_dpm->golden_dpm_context)
357 smu_dpm->golden_dpm_context = kzalloc(sizeof(struct vega20_dpm_table),
359 if (!smu_dpm->golden_dpm_context)
362 smu_dpm->dpm_context_size = sizeof(struct vega20_dpm_table);
364 smu_dpm->dpm_current_power_state = kzalloc(sizeof(struct smu_power_state),
366 if (!smu_dpm->dpm_current_power_state)
369 smu_dpm->dpm_request_power_state = kzalloc(sizeof(struct smu_power_state),
371 if (!smu_dpm->dpm_request_power_state)
377 static int vega20_setup_od8_information(struct smu_context *smu)
379 ATOM_Vega20_POWERPLAYTABLE *powerplay_table = NULL;
380 struct smu_table_context *table_context = &smu->smu_table;
381 struct vega20_od8_settings *od8_settings = (struct vega20_od8_settings *)smu->od_settings;
383 uint32_t od_feature_count, od_feature_array_size,
384 od_setting_count, od_setting_array_size;
386 if (!table_context->power_play_table)
389 powerplay_table = table_context->power_play_table;
391 if (powerplay_table->OverDrive8Table.ucODTableRevision == 1) {
392 /* Setup correct ODFeatureCount, and store ODFeatureArray from
393 * powerplay table to od_feature_capabilities */
395 (le32_to_cpu(powerplay_table->OverDrive8Table.ODFeatureCount) >
396 ATOM_VEGA20_ODFEATURE_COUNT) ?
397 ATOM_VEGA20_ODFEATURE_COUNT :
398 le32_to_cpu(powerplay_table->OverDrive8Table.ODFeatureCount);
400 od_feature_array_size = sizeof(uint8_t) * od_feature_count;
402 if (od8_settings->od_feature_capabilities)
405 od8_settings->od_feature_capabilities = kmemdup(&powerplay_table->OverDrive8Table.ODFeatureCapabilities,
406 od_feature_array_size,
408 if (!od8_settings->od_feature_capabilities)
411 /* Setup correct ODSettingCount, and store ODSettingArray from
412 * powerplay table to od_settings_max and od_setting_min */
414 (le32_to_cpu(powerplay_table->OverDrive8Table.ODSettingCount) >
415 ATOM_VEGA20_ODSETTING_COUNT) ?
416 ATOM_VEGA20_ODSETTING_COUNT :
417 le32_to_cpu(powerplay_table->OverDrive8Table.ODSettingCount);
419 od_setting_array_size = sizeof(uint32_t) * od_setting_count;
421 if (od8_settings->od_settings_max)
424 od8_settings->od_settings_max = kmemdup(&powerplay_table->OverDrive8Table.ODSettingsMax,
425 od_setting_array_size,
428 if (!od8_settings->od_settings_max) {
429 kfree(od8_settings->od_feature_capabilities);
430 od8_settings->od_feature_capabilities = NULL;
434 if (od8_settings->od_settings_min)
437 od8_settings->od_settings_min = kmemdup(&powerplay_table->OverDrive8Table.ODSettingsMin,
438 od_setting_array_size,
441 if (!od8_settings->od_settings_min) {
442 kfree(od8_settings->od_feature_capabilities);
443 od8_settings->od_feature_capabilities = NULL;
444 kfree(od8_settings->od_settings_max);
445 od8_settings->od_settings_max = NULL;
453 static int vega20_store_powerplay_table(struct smu_context *smu)
455 ATOM_Vega20_POWERPLAYTABLE *powerplay_table = NULL;
456 struct smu_table_context *table_context = &smu->smu_table;
458 if (!table_context->power_play_table)
461 powerplay_table = table_context->power_play_table;
463 memcpy(table_context->driver_pptable, &powerplay_table->smcPPTable,
466 table_context->thermal_controller_type = powerplay_table->ucThermalControllerType;
467 table_context->TDPODLimit = le32_to_cpu(powerplay_table->OverDrive8Table.ODSettingsMax[ATOM_VEGA20_ODSETTING_POWERPERCENTAGE]);
472 static int vega20_append_powerplay_table(struct smu_context *smu)
474 struct smu_table_context *table_context = &smu->smu_table;
475 PPTable_t *smc_pptable = table_context->driver_pptable;
476 struct atom_smc_dpm_info_v4_4 *smc_dpm_table;
479 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
482 ret = smu_get_atom_data_table(smu, index, NULL, NULL, NULL,
483 (uint8_t **)&smc_dpm_table);
487 smc_pptable->MaxVoltageStepGfx = smc_dpm_table->maxvoltagestepgfx;
488 smc_pptable->MaxVoltageStepSoc = smc_dpm_table->maxvoltagestepsoc;
490 smc_pptable->VddGfxVrMapping = smc_dpm_table->vddgfxvrmapping;
491 smc_pptable->VddSocVrMapping = smc_dpm_table->vddsocvrmapping;
492 smc_pptable->VddMem0VrMapping = smc_dpm_table->vddmem0vrmapping;
493 smc_pptable->VddMem1VrMapping = smc_dpm_table->vddmem1vrmapping;
495 smc_pptable->GfxUlvPhaseSheddingMask = smc_dpm_table->gfxulvphasesheddingmask;
496 smc_pptable->SocUlvPhaseSheddingMask = smc_dpm_table->soculvphasesheddingmask;
497 smc_pptable->ExternalSensorPresent = smc_dpm_table->externalsensorpresent;
499 smc_pptable->GfxMaxCurrent = smc_dpm_table->gfxmaxcurrent;
500 smc_pptable->GfxOffset = smc_dpm_table->gfxoffset;
501 smc_pptable->Padding_TelemetryGfx = smc_dpm_table->padding_telemetrygfx;
503 smc_pptable->SocMaxCurrent = smc_dpm_table->socmaxcurrent;
504 smc_pptable->SocOffset = smc_dpm_table->socoffset;
505 smc_pptable->Padding_TelemetrySoc = smc_dpm_table->padding_telemetrysoc;
507 smc_pptable->Mem0MaxCurrent = smc_dpm_table->mem0maxcurrent;
508 smc_pptable->Mem0Offset = smc_dpm_table->mem0offset;
509 smc_pptable->Padding_TelemetryMem0 = smc_dpm_table->padding_telemetrymem0;
511 smc_pptable->Mem1MaxCurrent = smc_dpm_table->mem1maxcurrent;
512 smc_pptable->Mem1Offset = smc_dpm_table->mem1offset;
513 smc_pptable->Padding_TelemetryMem1 = smc_dpm_table->padding_telemetrymem1;
515 smc_pptable->AcDcGpio = smc_dpm_table->acdcgpio;
516 smc_pptable->AcDcPolarity = smc_dpm_table->acdcpolarity;
517 smc_pptable->VR0HotGpio = smc_dpm_table->vr0hotgpio;
518 smc_pptable->VR0HotPolarity = smc_dpm_table->vr0hotpolarity;
520 smc_pptable->VR1HotGpio = smc_dpm_table->vr1hotgpio;
521 smc_pptable->VR1HotPolarity = smc_dpm_table->vr1hotpolarity;
522 smc_pptable->Padding1 = smc_dpm_table->padding1;
523 smc_pptable->Padding2 = smc_dpm_table->padding2;
525 smc_pptable->LedPin0 = smc_dpm_table->ledpin0;
526 smc_pptable->LedPin1 = smc_dpm_table->ledpin1;
527 smc_pptable->LedPin2 = smc_dpm_table->ledpin2;
529 smc_pptable->PllGfxclkSpreadEnabled = smc_dpm_table->pllgfxclkspreadenabled;
530 smc_pptable->PllGfxclkSpreadPercent = smc_dpm_table->pllgfxclkspreadpercent;
531 smc_pptable->PllGfxclkSpreadFreq = smc_dpm_table->pllgfxclkspreadfreq;
533 smc_pptable->UclkSpreadEnabled = 0;
534 smc_pptable->UclkSpreadPercent = smc_dpm_table->uclkspreadpercent;
535 smc_pptable->UclkSpreadFreq = smc_dpm_table->uclkspreadfreq;
537 smc_pptable->FclkSpreadEnabled = smc_dpm_table->fclkspreadenabled;
538 smc_pptable->FclkSpreadPercent = smc_dpm_table->fclkspreadpercent;
539 smc_pptable->FclkSpreadFreq = smc_dpm_table->fclkspreadfreq;
541 smc_pptable->FllGfxclkSpreadEnabled = smc_dpm_table->fllgfxclkspreadenabled;
542 smc_pptable->FllGfxclkSpreadPercent = smc_dpm_table->fllgfxclkspreadpercent;
543 smc_pptable->FllGfxclkSpreadFreq = smc_dpm_table->fllgfxclkspreadfreq;
545 for (i = 0; i < I2C_CONTROLLER_NAME_COUNT; i++) {
546 smc_pptable->I2cControllers[i].Enabled =
547 smc_dpm_table->i2ccontrollers[i].enabled;
548 smc_pptable->I2cControllers[i].SlaveAddress =
549 smc_dpm_table->i2ccontrollers[i].slaveaddress;
550 smc_pptable->I2cControllers[i].ControllerPort =
551 smc_dpm_table->i2ccontrollers[i].controllerport;
552 smc_pptable->I2cControllers[i].ThermalThrottler =
553 smc_dpm_table->i2ccontrollers[i].thermalthrottler;
554 smc_pptable->I2cControllers[i].I2cProtocol =
555 smc_dpm_table->i2ccontrollers[i].i2cprotocol;
556 smc_pptable->I2cControllers[i].I2cSpeed =
557 smc_dpm_table->i2ccontrollers[i].i2cspeed;
563 static int vega20_check_powerplay_table(struct smu_context *smu)
565 ATOM_Vega20_POWERPLAYTABLE *powerplay_table = NULL;
566 struct smu_table_context *table_context = &smu->smu_table;
568 powerplay_table = table_context->power_play_table;
570 if (powerplay_table->sHeader.format_revision < ATOM_VEGA20_TABLE_REVISION_VEGA20) {
571 pr_err("Unsupported PPTable format!");
575 if (!powerplay_table->sHeader.structuresize) {
576 pr_err("Invalid PowerPlay Table!");
583 static int vega20_run_btc_afll(struct smu_context *smu)
585 return smu_send_smc_msg(smu, SMU_MSG_RunAfllBtc);
588 #define FEATURE_MASK(feature) (1ULL << feature)
590 vega20_get_allowed_feature_mask(struct smu_context *smu,
591 uint32_t *feature_mask, uint32_t num)
596 memset(feature_mask, 0, sizeof(uint32_t) * num);
598 *(uint64_t *)feature_mask |= FEATURE_MASK(FEATURE_DPM_PREFETCHER_BIT)
599 | FEATURE_MASK(FEATURE_DPM_GFXCLK_BIT)
600 | FEATURE_MASK(FEATURE_DPM_UCLK_BIT)
601 | FEATURE_MASK(FEATURE_DPM_SOCCLK_BIT)
602 | FEATURE_MASK(FEATURE_DPM_UVD_BIT)
603 | FEATURE_MASK(FEATURE_DPM_VCE_BIT)
604 | FEATURE_MASK(FEATURE_ULV_BIT)
605 | FEATURE_MASK(FEATURE_DPM_MP0CLK_BIT)
606 | FEATURE_MASK(FEATURE_DPM_LINK_BIT)
607 | FEATURE_MASK(FEATURE_DPM_DCEFCLK_BIT)
608 | FEATURE_MASK(FEATURE_PPT_BIT)
609 | FEATURE_MASK(FEATURE_TDC_BIT)
610 | FEATURE_MASK(FEATURE_THERMAL_BIT)
611 | FEATURE_MASK(FEATURE_GFX_PER_CU_CG_BIT)
612 | FEATURE_MASK(FEATURE_RM_BIT)
613 | FEATURE_MASK(FEATURE_ACDC_BIT)
614 | FEATURE_MASK(FEATURE_VR0HOT_BIT)
615 | FEATURE_MASK(FEATURE_VR1HOT_BIT)
616 | FEATURE_MASK(FEATURE_FW_CTF_BIT)
617 | FEATURE_MASK(FEATURE_LED_DISPLAY_BIT)
618 | FEATURE_MASK(FEATURE_FAN_CONTROL_BIT)
619 | FEATURE_MASK(FEATURE_GFX_EDC_BIT)
620 | FEATURE_MASK(FEATURE_GFXOFF_BIT)
621 | FEATURE_MASK(FEATURE_CG_BIT)
622 | FEATURE_MASK(FEATURE_DPM_FCLK_BIT)
623 | FEATURE_MASK(FEATURE_XGMI_BIT);
628 amd_pm_state_type vega20_get_current_power_state(struct smu_context *smu)
630 enum amd_pm_state_type pm_type;
631 struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
633 if (!smu_dpm_ctx->dpm_context ||
634 !smu_dpm_ctx->dpm_current_power_state)
637 mutex_lock(&(smu->mutex));
638 switch (smu_dpm_ctx->dpm_current_power_state->classification.ui_label) {
639 case SMU_STATE_UI_LABEL_BATTERY:
640 pm_type = POWER_STATE_TYPE_BATTERY;
642 case SMU_STATE_UI_LABEL_BALLANCED:
643 pm_type = POWER_STATE_TYPE_BALANCED;
645 case SMU_STATE_UI_LABEL_PERFORMANCE:
646 pm_type = POWER_STATE_TYPE_PERFORMANCE;
649 if (smu_dpm_ctx->dpm_current_power_state->classification.flags & SMU_STATE_CLASSIFICATION_FLAG_BOOT)
650 pm_type = POWER_STATE_TYPE_INTERNAL_BOOT;
652 pm_type = POWER_STATE_TYPE_DEFAULT;
655 mutex_unlock(&(smu->mutex));
661 vega20_set_single_dpm_table(struct smu_context *smu,
662 struct vega20_single_dpm_table *single_dpm_table,
666 uint32_t i, num_of_levels = 0, clk;
668 ret = smu_send_smc_msg_with_param(smu,
669 SMU_MSG_GetDpmFreqByIndex,
670 (clk_id << 16 | 0xFF));
672 pr_err("[GetNumOfDpmLevel] failed to get dpm levels!");
676 smu_read_smc_arg(smu, &num_of_levels);
677 if (!num_of_levels) {
678 pr_err("[GetNumOfDpmLevel] number of clk levels is invalid!");
682 single_dpm_table->count = num_of_levels;
684 for (i = 0; i < num_of_levels; i++) {
685 ret = smu_send_smc_msg_with_param(smu,
686 SMU_MSG_GetDpmFreqByIndex,
689 pr_err("[GetDpmFreqByIndex] failed to get dpm freq by index!");
692 smu_read_smc_arg(smu, &clk);
694 pr_err("[GetDpmFreqByIndex] clk value is invalid!");
697 single_dpm_table->dpm_levels[i].value = clk;
698 single_dpm_table->dpm_levels[i].enabled = true;
703 static void vega20_init_single_dpm_state(struct vega20_dpm_state *dpm_state)
705 dpm_state->soft_min_level = 0x0;
706 dpm_state->soft_max_level = 0xffff;
707 dpm_state->hard_min_level = 0x0;
708 dpm_state->hard_max_level = 0xffff;
711 static int vega20_set_default_dpm_table(struct smu_context *smu)
715 struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
716 struct vega20_dpm_table *dpm_table = NULL;
717 struct vega20_single_dpm_table *single_dpm_table;
719 dpm_table = smu_dpm->dpm_context;
722 single_dpm_table = &(dpm_table->soc_table);
724 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_SOCCLK_BIT)) {
725 ret = vega20_set_single_dpm_table(smu, single_dpm_table,
728 pr_err("[SetupDefaultDpmTable] failed to get socclk dpm levels!");
732 single_dpm_table->count = 1;
733 single_dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.socclk / 100;
735 vega20_init_single_dpm_state(&(single_dpm_table->dpm_state));
738 single_dpm_table = &(dpm_table->gfx_table);
740 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_GFXCLK_BIT)) {
741 ret = vega20_set_single_dpm_table(smu, single_dpm_table,
744 pr_err("[SetupDefaultDpmTable] failed to get gfxclk dpm levels!");
748 single_dpm_table->count = 1;
749 single_dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.gfxclk / 100;
751 vega20_init_single_dpm_state(&(single_dpm_table->dpm_state));
754 single_dpm_table = &(dpm_table->mem_table);
756 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT)) {
757 ret = vega20_set_single_dpm_table(smu, single_dpm_table,
760 pr_err("[SetupDefaultDpmTable] failed to get memclk dpm levels!");
764 single_dpm_table->count = 1;
765 single_dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.uclk / 100;
767 vega20_init_single_dpm_state(&(single_dpm_table->dpm_state));
770 single_dpm_table = &(dpm_table->eclk_table);
772 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_VCE_BIT)) {
773 ret = vega20_set_single_dpm_table(smu, single_dpm_table, PPCLK_ECLK);
775 pr_err("[SetupDefaultDpmTable] failed to get eclk dpm levels!");
779 single_dpm_table->count = 1;
780 single_dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.eclk / 100;
782 vega20_init_single_dpm_state(&(single_dpm_table->dpm_state));
785 single_dpm_table = &(dpm_table->vclk_table);
787 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_UVD_BIT)) {
788 ret = vega20_set_single_dpm_table(smu, single_dpm_table, PPCLK_VCLK);
790 pr_err("[SetupDefaultDpmTable] failed to get vclk dpm levels!");
794 single_dpm_table->count = 1;
795 single_dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.vclk / 100;
797 vega20_init_single_dpm_state(&(single_dpm_table->dpm_state));
800 single_dpm_table = &(dpm_table->dclk_table);
802 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_UVD_BIT)) {
803 ret = vega20_set_single_dpm_table(smu, single_dpm_table, PPCLK_DCLK);
805 pr_err("[SetupDefaultDpmTable] failed to get dclk dpm levels!");
809 single_dpm_table->count = 1;
810 single_dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.dclk / 100;
812 vega20_init_single_dpm_state(&(single_dpm_table->dpm_state));
815 single_dpm_table = &(dpm_table->dcef_table);
817 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_DCEFCLK_BIT)) {
818 ret = vega20_set_single_dpm_table(smu, single_dpm_table,
821 pr_err("[SetupDefaultDpmTable] failed to get dcefclk dpm levels!");
825 single_dpm_table->count = 1;
826 single_dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.dcefclk / 100;
828 vega20_init_single_dpm_state(&(single_dpm_table->dpm_state));
831 single_dpm_table = &(dpm_table->pixel_table);
833 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_DCEFCLK_BIT)) {
834 ret = vega20_set_single_dpm_table(smu, single_dpm_table,
837 pr_err("[SetupDefaultDpmTable] failed to get pixclk dpm levels!");
841 single_dpm_table->count = 0;
843 vega20_init_single_dpm_state(&(single_dpm_table->dpm_state));
846 single_dpm_table = &(dpm_table->display_table);
848 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_DCEFCLK_BIT)) {
849 ret = vega20_set_single_dpm_table(smu, single_dpm_table,
852 pr_err("[SetupDefaultDpmTable] failed to get dispclk dpm levels!");
856 single_dpm_table->count = 0;
858 vega20_init_single_dpm_state(&(single_dpm_table->dpm_state));
861 single_dpm_table = &(dpm_table->phy_table);
863 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_DCEFCLK_BIT)) {
864 ret = vega20_set_single_dpm_table(smu, single_dpm_table,
867 pr_err("[SetupDefaultDpmTable] failed to get phyclk dpm levels!");
871 single_dpm_table->count = 0;
873 vega20_init_single_dpm_state(&(single_dpm_table->dpm_state));
876 single_dpm_table = &(dpm_table->fclk_table);
878 if (smu_feature_is_enabled(smu,FEATURE_DPM_FCLK_BIT)) {
879 ret = vega20_set_single_dpm_table(smu, single_dpm_table,
882 pr_err("[SetupDefaultDpmTable] failed to get fclk dpm levels!");
886 single_dpm_table->count = 0;
888 vega20_init_single_dpm_state(&(single_dpm_table->dpm_state));
890 memcpy(smu_dpm->golden_dpm_context, dpm_table,
891 sizeof(struct vega20_dpm_table));
896 static int vega20_populate_umd_state_clk(struct smu_context *smu)
898 struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
899 struct vega20_dpm_table *dpm_table = NULL;
900 struct vega20_single_dpm_table *gfx_table = NULL;
901 struct vega20_single_dpm_table *mem_table = NULL;
903 dpm_table = smu_dpm->dpm_context;
904 gfx_table = &(dpm_table->gfx_table);
905 mem_table = &(dpm_table->mem_table);
907 smu->pstate_sclk = gfx_table->dpm_levels[0].value;
908 smu->pstate_mclk = mem_table->dpm_levels[0].value;
910 if (gfx_table->count > VEGA20_UMD_PSTATE_GFXCLK_LEVEL &&
911 mem_table->count > VEGA20_UMD_PSTATE_MCLK_LEVEL) {
912 smu->pstate_sclk = gfx_table->dpm_levels[VEGA20_UMD_PSTATE_GFXCLK_LEVEL].value;
913 smu->pstate_mclk = mem_table->dpm_levels[VEGA20_UMD_PSTATE_MCLK_LEVEL].value;
916 smu->pstate_sclk = smu->pstate_sclk * 100;
917 smu->pstate_mclk = smu->pstate_mclk * 100;
922 static int vega20_get_clk_table(struct smu_context *smu,
923 struct pp_clock_levels_with_latency *clocks,
924 struct vega20_single_dpm_table *dpm_table)
928 count = (dpm_table->count > MAX_NUM_CLOCKS) ? MAX_NUM_CLOCKS : dpm_table->count;
929 clocks->num_levels = count;
931 for (i = 0; i < count; i++) {
932 clocks->data[i].clocks_in_khz =
933 dpm_table->dpm_levels[i].value * 1000;
934 clocks->data[i].latency_in_us = 0;
940 static int vega20_print_clk_levels(struct smu_context *smu,
941 enum smu_clk_type type, char *buf)
943 int i, now, size = 0;
945 uint32_t gen_speed, lane_width;
946 struct amdgpu_device *adev = smu->adev;
947 struct pp_clock_levels_with_latency clocks;
948 struct vega20_single_dpm_table *single_dpm_table;
949 struct smu_table_context *table_context = &smu->smu_table;
950 struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
951 struct vega20_dpm_table *dpm_table = NULL;
952 struct vega20_od8_settings *od8_settings =
953 (struct vega20_od8_settings *)smu->od_settings;
954 OverDriveTable_t *od_table =
955 (OverDriveTable_t *)(table_context->overdrive_table);
956 PPTable_t *pptable = (PPTable_t *)table_context->driver_pptable;
958 dpm_table = smu_dpm->dpm_context;
962 ret = smu_get_current_clk_freq(smu, SMU_GFXCLK, &now);
964 pr_err("Attempt to get current gfx clk Failed!");
968 single_dpm_table = &(dpm_table->gfx_table);
969 ret = vega20_get_clk_table(smu, &clocks, single_dpm_table);
971 pr_err("Attempt to get gfx clk levels Failed!");
975 for (i = 0; i < clocks.num_levels; i++)
976 size += sprintf(buf + size, "%d: %uMhz %s\n", i,
977 clocks.data[i].clocks_in_khz / 1000,
978 (clocks.data[i].clocks_in_khz == now * 10)
983 ret = smu_get_current_clk_freq(smu, SMU_UCLK, &now);
985 pr_err("Attempt to get current mclk Failed!");
989 single_dpm_table = &(dpm_table->mem_table);
990 ret = vega20_get_clk_table(smu, &clocks, single_dpm_table);
992 pr_err("Attempt to get memory clk levels Failed!");
996 for (i = 0; i < clocks.num_levels; i++)
997 size += sprintf(buf + size, "%d: %uMhz %s\n",
998 i, clocks.data[i].clocks_in_khz / 1000,
999 (clocks.data[i].clocks_in_khz == now * 10)
1004 ret = smu_get_current_clk_freq(smu, SMU_SOCCLK, &now);
1006 pr_err("Attempt to get current socclk Failed!");
1010 single_dpm_table = &(dpm_table->soc_table);
1011 ret = vega20_get_clk_table(smu, &clocks, single_dpm_table);
1013 pr_err("Attempt to get socclk levels Failed!");
1017 for (i = 0; i < clocks.num_levels; i++)
1018 size += sprintf(buf + size, "%d: %uMhz %s\n",
1019 i, clocks.data[i].clocks_in_khz / 1000,
1020 (clocks.data[i].clocks_in_khz == now * 10)
1025 ret = smu_get_current_clk_freq(smu, SMU_FCLK, &now);
1027 pr_err("Attempt to get current fclk Failed!");
1031 single_dpm_table = &(dpm_table->fclk_table);
1032 for (i = 0; i < single_dpm_table->count; i++)
1033 size += sprintf(buf + size, "%d: %uMhz %s\n",
1034 i, single_dpm_table->dpm_levels[i].value,
1035 (single_dpm_table->dpm_levels[i].value == now / 100)
1040 ret = smu_get_current_clk_freq(smu, SMU_DCEFCLK, &now);
1042 pr_err("Attempt to get current dcefclk Failed!");
1046 single_dpm_table = &(dpm_table->dcef_table);
1047 ret = vega20_get_clk_table(smu, &clocks, single_dpm_table);
1049 pr_err("Attempt to get dcefclk levels Failed!");
1053 for (i = 0; i < clocks.num_levels; i++)
1054 size += sprintf(buf + size, "%d: %uMhz %s\n",
1055 i, clocks.data[i].clocks_in_khz / 1000,
1056 (clocks.data[i].clocks_in_khz == now * 10) ? "*" : "");
1060 gen_speed = (RREG32_PCIE(smnPCIE_LC_SPEED_CNTL) &
1061 PSWUSP0_PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE_MASK)
1062 >> PSWUSP0_PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE__SHIFT;
1063 lane_width = (RREG32_PCIE(smnPCIE_LC_LINK_WIDTH_CNTL) &
1064 PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD_MASK)
1065 >> PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD__SHIFT;
1066 for (i = 0; i < NUM_LINK_LEVELS; i++)
1067 size += sprintf(buf + size, "%d: %s %s %dMhz %s\n", i,
1068 (pptable->PcieGenSpeed[i] == 0) ? "2.5GT/s," :
1069 (pptable->PcieGenSpeed[i] == 1) ? "5.0GT/s," :
1070 (pptable->PcieGenSpeed[i] == 2) ? "8.0GT/s," :
1071 (pptable->PcieGenSpeed[i] == 3) ? "16.0GT/s," : "",
1072 (pptable->PcieLaneCount[i] == 1) ? "x1" :
1073 (pptable->PcieLaneCount[i] == 2) ? "x2" :
1074 (pptable->PcieLaneCount[i] == 3) ? "x4" :
1075 (pptable->PcieLaneCount[i] == 4) ? "x8" :
1076 (pptable->PcieLaneCount[i] == 5) ? "x12" :
1077 (pptable->PcieLaneCount[i] == 6) ? "x16" : "",
1078 pptable->LclkFreq[i],
1079 (gen_speed == pptable->PcieGenSpeed[i]) &&
1080 (lane_width == pptable->PcieLaneCount[i]) ?
1085 if (od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMIN].feature_id &&
1086 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMAX].feature_id) {
1087 size = sprintf(buf, "%s:\n", "OD_SCLK");
1088 size += sprintf(buf + size, "0: %10uMhz\n",
1089 od_table->GfxclkFmin);
1090 size += sprintf(buf + size, "1: %10uMhz\n",
1091 od_table->GfxclkFmax);
1097 if (od8_settings->od8_settings_array[OD8_SETTING_UCLK_FMAX].feature_id) {
1098 size = sprintf(buf, "%s:\n", "OD_MCLK");
1099 size += sprintf(buf + size, "1: %10uMhz\n",
1100 od_table->UclkFmax);
1105 case SMU_OD_VDDC_CURVE:
1106 if (od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ1].feature_id &&
1107 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ2].feature_id &&
1108 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ3].feature_id &&
1109 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE1].feature_id &&
1110 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE2].feature_id &&
1111 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE3].feature_id) {
1112 size = sprintf(buf, "%s:\n", "OD_VDDC_CURVE");
1113 size += sprintf(buf + size, "0: %10uMhz %10dmV\n",
1114 od_table->GfxclkFreq1,
1115 od_table->GfxclkVolt1 / VOLTAGE_SCALE);
1116 size += sprintf(buf + size, "1: %10uMhz %10dmV\n",
1117 od_table->GfxclkFreq2,
1118 od_table->GfxclkVolt2 / VOLTAGE_SCALE);
1119 size += sprintf(buf + size, "2: %10uMhz %10dmV\n",
1120 od_table->GfxclkFreq3,
1121 od_table->GfxclkVolt3 / VOLTAGE_SCALE);
1127 size = sprintf(buf, "%s:\n", "OD_RANGE");
1129 if (od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMIN].feature_id &&
1130 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMAX].feature_id) {
1131 size += sprintf(buf + size, "SCLK: %7uMhz %10uMhz\n",
1132 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMIN].min_value,
1133 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMAX].max_value);
1136 if (od8_settings->od8_settings_array[OD8_SETTING_UCLK_FMAX].feature_id) {
1137 single_dpm_table = &(dpm_table->mem_table);
1138 ret = vega20_get_clk_table(smu, &clocks, single_dpm_table);
1140 pr_err("Attempt to get memory clk levels Failed!");
1144 size += sprintf(buf + size, "MCLK: %7uMhz %10uMhz\n",
1145 clocks.data[0].clocks_in_khz / 1000,
1146 od8_settings->od8_settings_array[OD8_SETTING_UCLK_FMAX].max_value);
1149 if (od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ1].feature_id &&
1150 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ2].feature_id &&
1151 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ3].feature_id &&
1152 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE1].feature_id &&
1153 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE2].feature_id &&
1154 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE3].feature_id) {
1155 size += sprintf(buf + size, "VDDC_CURVE_SCLK[0]: %7uMhz %10uMhz\n",
1156 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ1].min_value,
1157 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ1].max_value);
1158 size += sprintf(buf + size, "VDDC_CURVE_VOLT[0]: %7dmV %11dmV\n",
1159 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE1].min_value,
1160 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE1].max_value);
1161 size += sprintf(buf + size, "VDDC_CURVE_SCLK[1]: %7uMhz %10uMhz\n",
1162 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ2].min_value,
1163 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ2].max_value);
1164 size += sprintf(buf + size, "VDDC_CURVE_VOLT[1]: %7dmV %11dmV\n",
1165 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE2].min_value,
1166 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE2].max_value);
1167 size += sprintf(buf + size, "VDDC_CURVE_SCLK[2]: %7uMhz %10uMhz\n",
1168 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ3].min_value,
1169 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ3].max_value);
1170 size += sprintf(buf + size, "VDDC_CURVE_VOLT[2]: %7dmV %11dmV\n",
1171 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE3].min_value,
1172 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE3].max_value);
1183 static int vega20_upload_dpm_level(struct smu_context *smu, bool max,
1184 uint32_t feature_mask)
1186 struct vega20_dpm_table *dpm_table;
1187 struct vega20_single_dpm_table *single_dpm_table;
1191 dpm_table = smu->smu_dpm.dpm_context;
1193 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_GFXCLK_BIT) &&
1194 (feature_mask & FEATURE_DPM_GFXCLK_MASK)) {
1195 single_dpm_table = &(dpm_table->gfx_table);
1196 freq = max ? single_dpm_table->dpm_state.soft_max_level :
1197 single_dpm_table->dpm_state.soft_min_level;
1198 ret = smu_send_smc_msg_with_param(smu,
1199 (max ? SMU_MSG_SetSoftMaxByFreq : SMU_MSG_SetSoftMinByFreq),
1200 (PPCLK_GFXCLK << 16) | (freq & 0xffff));
1202 pr_err("Failed to set soft %s gfxclk !\n",
1203 max ? "max" : "min");
1208 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT) &&
1209 (feature_mask & FEATURE_DPM_UCLK_MASK)) {
1210 single_dpm_table = &(dpm_table->mem_table);
1211 freq = max ? single_dpm_table->dpm_state.soft_max_level :
1212 single_dpm_table->dpm_state.soft_min_level;
1213 ret = smu_send_smc_msg_with_param(smu,
1214 (max ? SMU_MSG_SetSoftMaxByFreq : SMU_MSG_SetSoftMinByFreq),
1215 (PPCLK_UCLK << 16) | (freq & 0xffff));
1217 pr_err("Failed to set soft %s memclk !\n",
1218 max ? "max" : "min");
1223 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_SOCCLK_BIT) &&
1224 (feature_mask & FEATURE_DPM_SOCCLK_MASK)) {
1225 single_dpm_table = &(dpm_table->soc_table);
1226 freq = max ? single_dpm_table->dpm_state.soft_max_level :
1227 single_dpm_table->dpm_state.soft_min_level;
1228 ret = smu_send_smc_msg_with_param(smu,
1229 (max ? SMU_MSG_SetSoftMaxByFreq : SMU_MSG_SetSoftMinByFreq),
1230 (PPCLK_SOCCLK << 16) | (freq & 0xffff));
1232 pr_err("Failed to set soft %s socclk !\n",
1233 max ? "max" : "min");
1238 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_FCLK_BIT) &&
1239 (feature_mask & FEATURE_DPM_FCLK_MASK)) {
1240 single_dpm_table = &(dpm_table->fclk_table);
1241 freq = max ? single_dpm_table->dpm_state.soft_max_level :
1242 single_dpm_table->dpm_state.soft_min_level;
1243 ret = smu_send_smc_msg_with_param(smu,
1244 (max ? SMU_MSG_SetSoftMaxByFreq : SMU_MSG_SetSoftMinByFreq),
1245 (PPCLK_FCLK << 16) | (freq & 0xffff));
1247 pr_err("Failed to set soft %s fclk !\n",
1248 max ? "max" : "min");
1253 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_DCEFCLK_BIT) &&
1254 (feature_mask & FEATURE_DPM_DCEFCLK_MASK)) {
1255 single_dpm_table = &(dpm_table->dcef_table);
1256 freq = single_dpm_table->dpm_state.hard_min_level;
1258 ret = smu_send_smc_msg_with_param(smu,
1259 SMU_MSG_SetHardMinByFreq,
1260 (PPCLK_DCEFCLK << 16) | (freq & 0xffff));
1262 pr_err("Failed to set hard min dcefclk !\n");
1271 static int vega20_force_clk_levels(struct smu_context *smu,
1272 enum smu_clk_type clk_type, uint32_t mask)
1274 struct vega20_dpm_table *dpm_table;
1275 struct vega20_single_dpm_table *single_dpm_table;
1276 uint32_t soft_min_level, soft_max_level, hard_min_level;
1277 struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
1280 if (smu_dpm->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL) {
1281 pr_info("force clock level is for dpm manual mode only.\n");
1285 mutex_lock(&(smu->mutex));
1287 soft_min_level = mask ? (ffs(mask) - 1) : 0;
1288 soft_max_level = mask ? (fls(mask) - 1) : 0;
1290 dpm_table = smu->smu_dpm.dpm_context;
1294 single_dpm_table = &(dpm_table->gfx_table);
1296 if (soft_max_level >= single_dpm_table->count) {
1297 pr_err("Clock level specified %d is over max allowed %d\n",
1298 soft_max_level, single_dpm_table->count - 1);
1303 single_dpm_table->dpm_state.soft_min_level =
1304 single_dpm_table->dpm_levels[soft_min_level].value;
1305 single_dpm_table->dpm_state.soft_max_level =
1306 single_dpm_table->dpm_levels[soft_max_level].value;
1308 ret = vega20_upload_dpm_level(smu, false, FEATURE_DPM_GFXCLK_MASK);
1310 pr_err("Failed to upload boot level to lowest!\n");
1314 ret = vega20_upload_dpm_level(smu, true, FEATURE_DPM_GFXCLK_MASK);
1316 pr_err("Failed to upload dpm max level to highest!\n");
1321 single_dpm_table = &(dpm_table->mem_table);
1323 if (soft_max_level >= single_dpm_table->count) {
1324 pr_err("Clock level specified %d is over max allowed %d\n",
1325 soft_max_level, single_dpm_table->count - 1);
1330 single_dpm_table->dpm_state.soft_min_level =
1331 single_dpm_table->dpm_levels[soft_min_level].value;
1332 single_dpm_table->dpm_state.soft_max_level =
1333 single_dpm_table->dpm_levels[soft_max_level].value;
1335 ret = vega20_upload_dpm_level(smu, false, FEATURE_DPM_UCLK_MASK);
1337 pr_err("Failed to upload boot level to lowest!\n");
1341 ret = vega20_upload_dpm_level(smu, true, FEATURE_DPM_UCLK_MASK);
1343 pr_err("Failed to upload dpm max level to highest!\n");
1348 single_dpm_table = &(dpm_table->soc_table);
1350 if (soft_max_level >= single_dpm_table->count) {
1351 pr_err("Clock level specified %d is over max allowed %d\n",
1352 soft_max_level, single_dpm_table->count - 1);
1357 single_dpm_table->dpm_state.soft_min_level =
1358 single_dpm_table->dpm_levels[soft_min_level].value;
1359 single_dpm_table->dpm_state.soft_max_level =
1360 single_dpm_table->dpm_levels[soft_max_level].value;
1362 ret = vega20_upload_dpm_level(smu, false, FEATURE_DPM_SOCCLK_MASK);
1364 pr_err("Failed to upload boot level to lowest!\n");
1368 ret = vega20_upload_dpm_level(smu, true, FEATURE_DPM_SOCCLK_MASK);
1370 pr_err("Failed to upload dpm max level to highest!\n");
1375 single_dpm_table = &(dpm_table->fclk_table);
1377 if (soft_max_level >= single_dpm_table->count) {
1378 pr_err("Clock level specified %d is over max allowed %d\n",
1379 soft_max_level, single_dpm_table->count - 1);
1384 single_dpm_table->dpm_state.soft_min_level =
1385 single_dpm_table->dpm_levels[soft_min_level].value;
1386 single_dpm_table->dpm_state.soft_max_level =
1387 single_dpm_table->dpm_levels[soft_max_level].value;
1389 ret = vega20_upload_dpm_level(smu, false, FEATURE_DPM_FCLK_MASK);
1391 pr_err("Failed to upload boot level to lowest!\n");
1395 ret = vega20_upload_dpm_level(smu, true, FEATURE_DPM_FCLK_MASK);
1397 pr_err("Failed to upload dpm max level to highest!\n");
1402 hard_min_level = soft_min_level;
1403 single_dpm_table = &(dpm_table->dcef_table);
1405 if (hard_min_level >= single_dpm_table->count) {
1406 pr_err("Clock level specified %d is over max allowed %d\n",
1407 hard_min_level, single_dpm_table->count - 1);
1412 single_dpm_table->dpm_state.hard_min_level =
1413 single_dpm_table->dpm_levels[hard_min_level].value;
1415 ret = vega20_upload_dpm_level(smu, false, FEATURE_DPM_DCEFCLK_MASK);
1417 pr_err("Failed to upload boot level to lowest!\n");
1422 if (soft_min_level >= NUM_LINK_LEVELS ||
1423 soft_max_level >= NUM_LINK_LEVELS) {
1428 ret = smu_send_smc_msg_with_param(smu,
1429 SMU_MSG_SetMinLinkDpmByIndex, soft_min_level);
1431 pr_err("Failed to set min link dpm level!\n");
1439 mutex_unlock(&(smu->mutex));
1443 static int vega20_get_clock_by_type_with_latency(struct smu_context *smu,
1444 enum smu_clk_type clk_type,
1445 struct pp_clock_levels_with_latency *clocks)
1448 struct vega20_single_dpm_table *single_dpm_table;
1449 struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
1450 struct vega20_dpm_table *dpm_table = NULL;
1452 dpm_table = smu_dpm->dpm_context;
1454 mutex_lock(&smu->mutex);
1458 single_dpm_table = &(dpm_table->gfx_table);
1459 ret = vega20_get_clk_table(smu, clocks, single_dpm_table);
1462 single_dpm_table = &(dpm_table->mem_table);
1463 ret = vega20_get_clk_table(smu, clocks, single_dpm_table);
1466 single_dpm_table = &(dpm_table->dcef_table);
1467 ret = vega20_get_clk_table(smu, clocks, single_dpm_table);
1470 single_dpm_table = &(dpm_table->soc_table);
1471 ret = vega20_get_clk_table(smu, clocks, single_dpm_table);
1477 mutex_unlock(&smu->mutex);
1481 static int vega20_overdrive_get_gfx_clk_base_voltage(struct smu_context *smu,
1487 ret = smu_send_smc_msg_with_param(smu,
1488 SMU_MSG_GetAVFSVoltageByDpm,
1489 ((AVFS_CURVE << 24) | (OD8_HOTCURVE_TEMPERATURE << 16) | freq));
1491 pr_err("[GetBaseVoltage] failed to get GFXCLK AVFS voltage from SMU!");
1495 smu_read_smc_arg(smu, voltage);
1496 *voltage = *voltage / VOLTAGE_SCALE;
1501 static int vega20_set_default_od8_setttings(struct smu_context *smu)
1503 struct smu_table_context *table_context = &smu->smu_table;
1504 OverDriveTable_t *od_table = (OverDriveTable_t *)(table_context->overdrive_table);
1505 struct vega20_od8_settings *od8_settings = NULL;
1506 PPTable_t *smc_pptable = table_context->driver_pptable;
1509 if (smu->od_settings)
1512 od8_settings = kzalloc(sizeof(struct vega20_od8_settings), GFP_KERNEL);
1517 smu->od_settings = (void *)od8_settings;
1519 ret = vega20_setup_od8_information(smu);
1521 pr_err("Retrieve board OD limits failed!\n");
1525 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_SOCCLK_BIT)) {
1526 if (od8_settings->od_feature_capabilities[ATOM_VEGA20_ODFEATURE_GFXCLK_LIMITS] &&
1527 od8_settings->od_settings_max[OD8_SETTING_GFXCLK_FMAX] > 0 &&
1528 od8_settings->od_settings_min[OD8_SETTING_GFXCLK_FMIN] > 0 &&
1529 (od8_settings->od_settings_max[OD8_SETTING_GFXCLK_FMAX] >=
1530 od8_settings->od_settings_min[OD8_SETTING_GFXCLK_FMIN])) {
1531 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMIN].feature_id =
1533 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMAX].feature_id =
1535 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMIN].default_value =
1536 od_table->GfxclkFmin;
1537 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMAX].default_value =
1538 od_table->GfxclkFmax;
1541 if (od8_settings->od_feature_capabilities[ATOM_VEGA20_ODFEATURE_GFXCLK_CURVE] &&
1542 (od8_settings->od_settings_min[OD8_SETTING_GFXCLK_VOLTAGE1] >=
1543 smc_pptable->MinVoltageGfx / VOLTAGE_SCALE) &&
1544 (od8_settings->od_settings_max[OD8_SETTING_GFXCLK_VOLTAGE3] <=
1545 smc_pptable->MaxVoltageGfx / VOLTAGE_SCALE) &&
1546 (od8_settings->od_settings_min[OD8_SETTING_GFXCLK_VOLTAGE1] <=
1547 od8_settings->od_settings_max[OD8_SETTING_GFXCLK_VOLTAGE3])) {
1548 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ1].feature_id =
1550 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE1].feature_id =
1552 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ2].feature_id =
1554 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE2].feature_id =
1556 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ3].feature_id =
1558 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE3].feature_id =
1561 od_table->GfxclkFreq1 = od_table->GfxclkFmin;
1562 od_table->GfxclkFreq2 = (od_table->GfxclkFmin + od_table->GfxclkFmax) / 2;
1563 od_table->GfxclkFreq3 = od_table->GfxclkFmax;
1564 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ1].default_value =
1565 od_table->GfxclkFreq1;
1566 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ2].default_value =
1567 od_table->GfxclkFreq2;
1568 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ3].default_value =
1569 od_table->GfxclkFreq3;
1571 ret = vega20_overdrive_get_gfx_clk_base_voltage(smu,
1572 &od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE1].default_value,
1573 od_table->GfxclkFreq1);
1575 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE1].default_value = 0;
1576 od_table->GfxclkVolt1 =
1577 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE1].default_value
1579 ret = vega20_overdrive_get_gfx_clk_base_voltage(smu,
1580 &od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE2].default_value,
1581 od_table->GfxclkFreq2);
1583 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE2].default_value = 0;
1584 od_table->GfxclkVolt2 =
1585 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE2].default_value
1587 ret = vega20_overdrive_get_gfx_clk_base_voltage(smu,
1588 &od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE3].default_value,
1589 od_table->GfxclkFreq3);
1591 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE3].default_value = 0;
1592 od_table->GfxclkVolt3 =
1593 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE3].default_value
1598 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT)) {
1599 if (od8_settings->od_feature_capabilities[ATOM_VEGA20_ODFEATURE_UCLK_MAX] &&
1600 od8_settings->od_settings_min[OD8_SETTING_UCLK_FMAX] > 0 &&
1601 od8_settings->od_settings_max[OD8_SETTING_UCLK_FMAX] > 0 &&
1602 (od8_settings->od_settings_max[OD8_SETTING_UCLK_FMAX] >=
1603 od8_settings->od_settings_min[OD8_SETTING_UCLK_FMAX])) {
1604 od8_settings->od8_settings_array[OD8_SETTING_UCLK_FMAX].feature_id =
1606 od8_settings->od8_settings_array[OD8_SETTING_UCLK_FMAX].default_value =
1611 if (od8_settings->od_feature_capabilities[ATOM_VEGA20_ODFEATURE_POWER_LIMIT] &&
1612 od8_settings->od_settings_min[OD8_SETTING_POWER_PERCENTAGE] > 0 &&
1613 od8_settings->od_settings_min[OD8_SETTING_POWER_PERCENTAGE] <= 100 &&
1614 od8_settings->od_settings_max[OD8_SETTING_POWER_PERCENTAGE] > 0 &&
1615 od8_settings->od_settings_max[OD8_SETTING_POWER_PERCENTAGE] <= 100) {
1616 od8_settings->od8_settings_array[OD8_SETTING_POWER_PERCENTAGE].feature_id =
1618 od8_settings->od8_settings_array[OD8_SETTING_POWER_PERCENTAGE].default_value =
1619 od_table->OverDrivePct;
1622 if (smu_feature_is_enabled(smu, SMU_FEATURE_FAN_CONTROL_BIT)) {
1623 if (od8_settings->od_feature_capabilities[ATOM_VEGA20_ODFEATURE_FAN_ACOUSTIC_LIMIT] &&
1624 od8_settings->od_settings_min[OD8_SETTING_FAN_ACOUSTIC_LIMIT] > 0 &&
1625 od8_settings->od_settings_max[OD8_SETTING_FAN_ACOUSTIC_LIMIT] > 0 &&
1626 (od8_settings->od_settings_max[OD8_SETTING_FAN_ACOUSTIC_LIMIT] >=
1627 od8_settings->od_settings_min[OD8_SETTING_FAN_ACOUSTIC_LIMIT])) {
1628 od8_settings->od8_settings_array[OD8_SETTING_FAN_ACOUSTIC_LIMIT].feature_id =
1629 OD8_ACOUSTIC_LIMIT_SCLK;
1630 od8_settings->od8_settings_array[OD8_SETTING_FAN_ACOUSTIC_LIMIT].default_value =
1631 od_table->FanMaximumRpm;
1634 if (od8_settings->od_feature_capabilities[ATOM_VEGA20_ODFEATURE_FAN_SPEED_MIN] &&
1635 od8_settings->od_settings_min[OD8_SETTING_FAN_MIN_SPEED] > 0 &&
1636 od8_settings->od_settings_max[OD8_SETTING_FAN_MIN_SPEED] > 0 &&
1637 (od8_settings->od_settings_max[OD8_SETTING_FAN_MIN_SPEED] >=
1638 od8_settings->od_settings_min[OD8_SETTING_FAN_MIN_SPEED])) {
1639 od8_settings->od8_settings_array[OD8_SETTING_FAN_MIN_SPEED].feature_id =
1641 od8_settings->od8_settings_array[OD8_SETTING_FAN_MIN_SPEED].default_value =
1642 od_table->FanMinimumPwm * smc_pptable->FanMaximumRpm / 100;
1646 if (smu_feature_is_enabled(smu, SMU_FEATURE_THERMAL_BIT)) {
1647 if (od8_settings->od_feature_capabilities[ATOM_VEGA20_ODFEATURE_TEMPERATURE_FAN] &&
1648 od8_settings->od_settings_min[OD8_SETTING_FAN_TARGET_TEMP] > 0 &&
1649 od8_settings->od_settings_max[OD8_SETTING_FAN_TARGET_TEMP] > 0 &&
1650 (od8_settings->od_settings_max[OD8_SETTING_FAN_TARGET_TEMP] >=
1651 od8_settings->od_settings_min[OD8_SETTING_FAN_TARGET_TEMP])) {
1652 od8_settings->od8_settings_array[OD8_SETTING_FAN_TARGET_TEMP].feature_id =
1653 OD8_TEMPERATURE_FAN;
1654 od8_settings->od8_settings_array[OD8_SETTING_FAN_TARGET_TEMP].default_value =
1655 od_table->FanTargetTemperature;
1658 if (od8_settings->od_feature_capabilities[ATOM_VEGA20_ODFEATURE_TEMPERATURE_SYSTEM] &&
1659 od8_settings->od_settings_min[OD8_SETTING_OPERATING_TEMP_MAX] > 0 &&
1660 od8_settings->od_settings_max[OD8_SETTING_OPERATING_TEMP_MAX] > 0 &&
1661 (od8_settings->od_settings_max[OD8_SETTING_OPERATING_TEMP_MAX] >=
1662 od8_settings->od_settings_min[OD8_SETTING_OPERATING_TEMP_MAX])) {
1663 od8_settings->od8_settings_array[OD8_SETTING_OPERATING_TEMP_MAX].feature_id =
1664 OD8_TEMPERATURE_SYSTEM;
1665 od8_settings->od8_settings_array[OD8_SETTING_OPERATING_TEMP_MAX].default_value =
1666 od_table->MaxOpTemp;
1670 for (i = 0; i < OD8_SETTING_COUNT; i++) {
1671 if (od8_settings->od8_settings_array[i].feature_id) {
1672 od8_settings->od8_settings_array[i].min_value =
1673 od8_settings->od_settings_min[i];
1674 od8_settings->od8_settings_array[i].max_value =
1675 od8_settings->od_settings_max[i];
1676 od8_settings->od8_settings_array[i].current_value =
1677 od8_settings->od8_settings_array[i].default_value;
1679 od8_settings->od8_settings_array[i].min_value = 0;
1680 od8_settings->od8_settings_array[i].max_value = 0;
1681 od8_settings->od8_settings_array[i].current_value = 0;
1688 static int vega20_get_metrics_table(struct smu_context *smu,
1689 SmuMetrics_t *metrics_table)
1691 struct smu_table_context *smu_table= &smu->smu_table;
1694 if (!smu_table->metrics_time || time_after(jiffies, smu_table->metrics_time + HZ / 1000)) {
1695 ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS, 0,
1696 (void *)smu_table->metrics_table, false);
1698 pr_info("Failed to export SMU metrics table!\n");
1701 smu_table->metrics_time = jiffies;
1704 memcpy(metrics_table, smu_table->metrics_table, sizeof(SmuMetrics_t));
1709 static int vega20_set_default_od_settings(struct smu_context *smu,
1712 struct smu_table_context *table_context = &smu->smu_table;
1716 if (table_context->overdrive_table)
1719 table_context->overdrive_table = kzalloc(sizeof(OverDriveTable_t), GFP_KERNEL);
1721 if (!table_context->overdrive_table)
1724 ret = smu_update_table(smu, SMU_TABLE_OVERDRIVE, 0,
1725 table_context->overdrive_table, false);
1727 pr_err("Failed to export over drive table!\n");
1731 ret = vega20_set_default_od8_setttings(smu);
1736 ret = smu_update_table(smu, SMU_TABLE_OVERDRIVE, 0,
1737 table_context->overdrive_table, true);
1739 pr_err("Failed to import over drive table!\n");
1746 static int vega20_get_od_percentage(struct smu_context *smu,
1747 enum smu_clk_type clk_type)
1749 struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
1750 struct vega20_dpm_table *dpm_table = NULL;
1751 struct vega20_dpm_table *golden_table = NULL;
1752 struct vega20_single_dpm_table *single_dpm_table;
1753 struct vega20_single_dpm_table *golden_dpm_table;
1754 int value, golden_value;
1756 dpm_table = smu_dpm->dpm_context;
1757 golden_table = smu_dpm->golden_dpm_context;
1761 single_dpm_table = &(dpm_table->gfx_table);
1762 golden_dpm_table = &(golden_table->gfx_table);
1765 single_dpm_table = &(dpm_table->mem_table);
1766 golden_dpm_table = &(golden_table->mem_table);
1773 value = single_dpm_table->dpm_levels[single_dpm_table->count - 1].value;
1774 golden_value = golden_dpm_table->dpm_levels[golden_dpm_table->count - 1].value;
1776 value -= golden_value;
1777 value = DIV_ROUND_UP(value * 100, golden_value);
1782 static int vega20_get_power_profile_mode(struct smu_context *smu, char *buf)
1784 DpmActivityMonitorCoeffInt_t activity_monitor;
1785 uint32_t i, size = 0;
1786 int16_t workload_type = 0;
1787 static const char *profile_name[] = {
1795 static const char *title[] = {
1796 "PROFILE_INDEX(NAME)",
1800 "MinActiveFreqType",
1805 "PD_Data_error_coeff",
1806 "PD_Data_error_rate_coeff"};
1809 if (!smu->pm_enabled || !buf)
1812 size += sprintf(buf + size, "%16s %s %s %s %s %s %s %s %s %s %s\n",
1813 title[0], title[1], title[2], title[3], title[4], title[5],
1814 title[6], title[7], title[8], title[9], title[10]);
1816 for (i = 0; i <= PP_SMC_POWER_PROFILE_CUSTOM; i++) {
1817 /* conv PP_SMC_POWER_PROFILE* to WORKLOAD_PPLIB_*_BIT */
1818 workload_type = smu_workload_get_type(smu, i);
1819 if (workload_type < 0)
1822 result = smu_update_table(smu,
1823 SMU_TABLE_ACTIVITY_MONITOR_COEFF, workload_type,
1824 (void *)(&activity_monitor), false);
1826 pr_err("[%s] Failed to get activity monitor!", __func__);
1830 size += sprintf(buf + size, "%2d %14s%s:\n",
1831 i, profile_name[i], (i == smu->power_profile_mode) ? "*" : " ");
1833 size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n",
1837 activity_monitor.Gfx_FPS,
1838 activity_monitor.Gfx_UseRlcBusy,
1839 activity_monitor.Gfx_MinActiveFreqType,
1840 activity_monitor.Gfx_MinActiveFreq,
1841 activity_monitor.Gfx_BoosterFreqType,
1842 activity_monitor.Gfx_BoosterFreq,
1843 activity_monitor.Gfx_PD_Data_limit_c,
1844 activity_monitor.Gfx_PD_Data_error_coeff,
1845 activity_monitor.Gfx_PD_Data_error_rate_coeff);
1847 size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n",
1851 activity_monitor.Soc_FPS,
1852 activity_monitor.Soc_UseRlcBusy,
1853 activity_monitor.Soc_MinActiveFreqType,
1854 activity_monitor.Soc_MinActiveFreq,
1855 activity_monitor.Soc_BoosterFreqType,
1856 activity_monitor.Soc_BoosterFreq,
1857 activity_monitor.Soc_PD_Data_limit_c,
1858 activity_monitor.Soc_PD_Data_error_coeff,
1859 activity_monitor.Soc_PD_Data_error_rate_coeff);
1861 size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n",
1865 activity_monitor.Mem_FPS,
1866 activity_monitor.Mem_UseRlcBusy,
1867 activity_monitor.Mem_MinActiveFreqType,
1868 activity_monitor.Mem_MinActiveFreq,
1869 activity_monitor.Mem_BoosterFreqType,
1870 activity_monitor.Mem_BoosterFreq,
1871 activity_monitor.Mem_PD_Data_limit_c,
1872 activity_monitor.Mem_PD_Data_error_coeff,
1873 activity_monitor.Mem_PD_Data_error_rate_coeff);
1875 size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n",
1879 activity_monitor.Fclk_FPS,
1880 activity_monitor.Fclk_UseRlcBusy,
1881 activity_monitor.Fclk_MinActiveFreqType,
1882 activity_monitor.Fclk_MinActiveFreq,
1883 activity_monitor.Fclk_BoosterFreqType,
1884 activity_monitor.Fclk_BoosterFreq,
1885 activity_monitor.Fclk_PD_Data_limit_c,
1886 activity_monitor.Fclk_PD_Data_error_coeff,
1887 activity_monitor.Fclk_PD_Data_error_rate_coeff);
1893 static int vega20_set_power_profile_mode(struct smu_context *smu, long *input, uint32_t size)
1895 DpmActivityMonitorCoeffInt_t activity_monitor;
1896 int workload_type = 0, ret = 0;
1898 smu->power_profile_mode = input[size];
1900 if (!smu->pm_enabled)
1902 if (smu->power_profile_mode > PP_SMC_POWER_PROFILE_CUSTOM) {
1903 pr_err("Invalid power profile mode %d\n", smu->power_profile_mode);
1907 if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
1908 ret = smu_update_table(smu,
1909 SMU_TABLE_ACTIVITY_MONITOR_COEFF, WORKLOAD_PPLIB_CUSTOM_BIT,
1910 (void *)(&activity_monitor), false);
1912 pr_err("[%s] Failed to get activity monitor!", __func__);
1917 case 0: /* Gfxclk */
1918 activity_monitor.Gfx_FPS = input[1];
1919 activity_monitor.Gfx_UseRlcBusy = input[2];
1920 activity_monitor.Gfx_MinActiveFreqType = input[3];
1921 activity_monitor.Gfx_MinActiveFreq = input[4];
1922 activity_monitor.Gfx_BoosterFreqType = input[5];
1923 activity_monitor.Gfx_BoosterFreq = input[6];
1924 activity_monitor.Gfx_PD_Data_limit_c = input[7];
1925 activity_monitor.Gfx_PD_Data_error_coeff = input[8];
1926 activity_monitor.Gfx_PD_Data_error_rate_coeff = input[9];
1928 case 1: /* Socclk */
1929 activity_monitor.Soc_FPS = input[1];
1930 activity_monitor.Soc_UseRlcBusy = input[2];
1931 activity_monitor.Soc_MinActiveFreqType = input[3];
1932 activity_monitor.Soc_MinActiveFreq = input[4];
1933 activity_monitor.Soc_BoosterFreqType = input[5];
1934 activity_monitor.Soc_BoosterFreq = input[6];
1935 activity_monitor.Soc_PD_Data_limit_c = input[7];
1936 activity_monitor.Soc_PD_Data_error_coeff = input[8];
1937 activity_monitor.Soc_PD_Data_error_rate_coeff = input[9];
1940 activity_monitor.Mem_FPS = input[1];
1941 activity_monitor.Mem_UseRlcBusy = input[2];
1942 activity_monitor.Mem_MinActiveFreqType = input[3];
1943 activity_monitor.Mem_MinActiveFreq = input[4];
1944 activity_monitor.Mem_BoosterFreqType = input[5];
1945 activity_monitor.Mem_BoosterFreq = input[6];
1946 activity_monitor.Mem_PD_Data_limit_c = input[7];
1947 activity_monitor.Mem_PD_Data_error_coeff = input[8];
1948 activity_monitor.Mem_PD_Data_error_rate_coeff = input[9];
1951 activity_monitor.Fclk_FPS = input[1];
1952 activity_monitor.Fclk_UseRlcBusy = input[2];
1953 activity_monitor.Fclk_MinActiveFreqType = input[3];
1954 activity_monitor.Fclk_MinActiveFreq = input[4];
1955 activity_monitor.Fclk_BoosterFreqType = input[5];
1956 activity_monitor.Fclk_BoosterFreq = input[6];
1957 activity_monitor.Fclk_PD_Data_limit_c = input[7];
1958 activity_monitor.Fclk_PD_Data_error_coeff = input[8];
1959 activity_monitor.Fclk_PD_Data_error_rate_coeff = input[9];
1963 ret = smu_update_table(smu,
1964 SMU_TABLE_ACTIVITY_MONITOR_COEFF, WORKLOAD_PPLIB_CUSTOM_BIT,
1965 (void *)(&activity_monitor), true);
1967 pr_err("[%s] Failed to set activity monitor!", __func__);
1972 /* conv PP_SMC_POWER_PROFILE* to WORKLOAD_PPLIB_*_BIT */
1973 workload_type = smu_workload_get_type(smu, smu->power_profile_mode);
1974 if (workload_type < 0)
1976 smu_send_smc_msg_with_param(smu, SMU_MSG_SetWorkloadMask,
1977 1 << workload_type);
1983 vega20_get_profiling_clk_mask(struct smu_context *smu,
1984 enum amd_dpm_forced_level level,
1985 uint32_t *sclk_mask,
1986 uint32_t *mclk_mask,
1989 struct vega20_dpm_table *dpm_table = (struct vega20_dpm_table *)smu->smu_dpm.dpm_context;
1990 struct vega20_single_dpm_table *gfx_dpm_table;
1991 struct vega20_single_dpm_table *mem_dpm_table;
1992 struct vega20_single_dpm_table *soc_dpm_table;
1994 if (!smu->smu_dpm.dpm_context)
1997 gfx_dpm_table = &dpm_table->gfx_table;
1998 mem_dpm_table = &dpm_table->mem_table;
1999 soc_dpm_table = &dpm_table->soc_table;
2005 if (gfx_dpm_table->count > VEGA20_UMD_PSTATE_GFXCLK_LEVEL &&
2006 mem_dpm_table->count > VEGA20_UMD_PSTATE_MCLK_LEVEL &&
2007 soc_dpm_table->count > VEGA20_UMD_PSTATE_SOCCLK_LEVEL) {
2008 *sclk_mask = VEGA20_UMD_PSTATE_GFXCLK_LEVEL;
2009 *mclk_mask = VEGA20_UMD_PSTATE_MCLK_LEVEL;
2010 *soc_mask = VEGA20_UMD_PSTATE_SOCCLK_LEVEL;
2013 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) {
2015 } else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK) {
2017 } else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
2018 *sclk_mask = gfx_dpm_table->count - 1;
2019 *mclk_mask = mem_dpm_table->count - 1;
2020 *soc_mask = soc_dpm_table->count - 1;
2027 vega20_set_uclk_to_highest_dpm_level(struct smu_context *smu,
2028 struct vega20_single_dpm_table *dpm_table)
2031 struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
2032 if (!smu_dpm_ctx->dpm_context)
2035 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT)) {
2036 if (dpm_table->count <= 0) {
2037 pr_err("[%s] Dpm table has no entry!", __func__);
2041 if (dpm_table->count > NUM_UCLK_DPM_LEVELS) {
2042 pr_err("[%s] Dpm table has too many entries!", __func__);
2046 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2047 ret = smu_send_smc_msg_with_param(smu,
2048 SMU_MSG_SetHardMinByFreq,
2049 (PPCLK_UCLK << 16) | dpm_table->dpm_state.hard_min_level);
2051 pr_err("[%s] Set hard min uclk failed!", __func__);
2059 static int vega20_pre_display_config_changed(struct smu_context *smu)
2062 struct vega20_dpm_table *dpm_table = smu->smu_dpm.dpm_context;
2064 if (!smu->smu_dpm.dpm_context)
2067 smu_send_smc_msg_with_param(smu, SMU_MSG_NumOfDisplays, 0);
2068 ret = vega20_set_uclk_to_highest_dpm_level(smu,
2069 &dpm_table->mem_table);
2071 pr_err("Failed to set uclk to highest dpm level");
2075 static int vega20_display_config_changed(struct smu_context *smu)
2079 if ((smu->watermarks_bitmap & WATERMARKS_EXIST) &&
2080 !(smu->watermarks_bitmap & WATERMARKS_LOADED)) {
2081 ret = smu_write_watermarks_table(smu);
2083 pr_err("Failed to update WMTABLE!");
2086 smu->watermarks_bitmap |= WATERMARKS_LOADED;
2089 if ((smu->watermarks_bitmap & WATERMARKS_EXIST) &&
2090 smu_feature_is_supported(smu, SMU_FEATURE_DPM_DCEFCLK_BIT) &&
2091 smu_feature_is_supported(smu, SMU_FEATURE_DPM_SOCCLK_BIT)) {
2092 smu_send_smc_msg_with_param(smu,
2093 SMU_MSG_NumOfDisplays,
2094 smu->display_config->num_display);
2100 static int vega20_apply_clocks_adjust_rules(struct smu_context *smu)
2102 struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
2103 struct vega20_dpm_table *dpm_ctx = (struct vega20_dpm_table *)(smu_dpm_ctx->dpm_context);
2104 struct vega20_single_dpm_table *dpm_table;
2105 bool vblank_too_short = false;
2106 bool disable_mclk_switching;
2107 uint32_t i, latency;
2109 disable_mclk_switching = ((1 < smu->display_config->num_display) &&
2110 !smu->display_config->multi_monitor_in_sync) || vblank_too_short;
2111 latency = smu->display_config->dce_tolerable_mclk_in_active_latency;
2114 dpm_table = &(dpm_ctx->gfx_table);
2115 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
2116 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2117 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
2118 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2120 if (VEGA20_UMD_PSTATE_GFXCLK_LEVEL < dpm_table->count) {
2121 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_GFXCLK_LEVEL].value;
2122 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_GFXCLK_LEVEL].value;
2125 if (smu_dpm_ctx->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) {
2126 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
2127 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[0].value;
2130 if (smu_dpm_ctx->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
2131 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2132 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2136 dpm_table = &(dpm_ctx->mem_table);
2137 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
2138 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2139 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
2140 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2142 if (VEGA20_UMD_PSTATE_MCLK_LEVEL < dpm_table->count) {
2143 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_MCLK_LEVEL].value;
2144 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_MCLK_LEVEL].value;
2147 if (smu_dpm_ctx->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK) {
2148 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
2149 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[0].value;
2152 if (smu_dpm_ctx->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
2153 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2154 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2157 /* honour DAL's UCLK Hardmin */
2158 if (dpm_table->dpm_state.hard_min_level < (smu->display_config->min_mem_set_clock / 100))
2159 dpm_table->dpm_state.hard_min_level = smu->display_config->min_mem_set_clock / 100;
2161 /* Hardmin is dependent on displayconfig */
2162 if (disable_mclk_switching) {
2163 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2164 for (i = 0; i < smu_dpm_ctx->mclk_latency_table->count - 1; i++) {
2165 if (smu_dpm_ctx->mclk_latency_table->entries[i].latency <= latency) {
2166 if (dpm_table->dpm_levels[i].value >= (smu->display_config->min_mem_set_clock / 100)) {
2167 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[i].value;
2174 if (smu->display_config->nb_pstate_switch_disable)
2175 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2178 dpm_table = &(dpm_ctx->vclk_table);
2179 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
2180 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2181 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
2182 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2184 if (VEGA20_UMD_PSTATE_UVDCLK_LEVEL < dpm_table->count) {
2185 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_UVDCLK_LEVEL].value;
2186 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_UVDCLK_LEVEL].value;
2189 if (smu_dpm_ctx->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
2190 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2191 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2195 dpm_table = &(dpm_ctx->dclk_table);
2196 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
2197 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2198 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
2199 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2201 if (VEGA20_UMD_PSTATE_UVDCLK_LEVEL < dpm_table->count) {
2202 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_UVDCLK_LEVEL].value;
2203 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_UVDCLK_LEVEL].value;
2206 if (smu_dpm_ctx->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
2207 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2208 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2212 dpm_table = &(dpm_ctx->soc_table);
2213 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
2214 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2215 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
2216 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2218 if (VEGA20_UMD_PSTATE_SOCCLK_LEVEL < dpm_table->count) {
2219 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_SOCCLK_LEVEL].value;
2220 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_SOCCLK_LEVEL].value;
2223 if (smu_dpm_ctx->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
2224 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2225 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2229 dpm_table = &(dpm_ctx->eclk_table);
2230 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
2231 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2232 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
2233 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2235 if (VEGA20_UMD_PSTATE_VCEMCLK_LEVEL < dpm_table->count) {
2236 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_VCEMCLK_LEVEL].value;
2237 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_VCEMCLK_LEVEL].value;
2240 if (smu_dpm_ctx->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
2241 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2242 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2248 vega20_notify_smc_dispaly_config(struct smu_context *smu)
2250 struct vega20_dpm_table *dpm_table = smu->smu_dpm.dpm_context;
2251 struct vega20_single_dpm_table *memtable = &dpm_table->mem_table;
2252 struct smu_clocks min_clocks = {0};
2253 struct pp_display_clock_request clock_req;
2256 min_clocks.dcef_clock = smu->display_config->min_dcef_set_clk;
2257 min_clocks.dcef_clock_in_sr = smu->display_config->min_dcef_deep_sleep_set_clk;
2258 min_clocks.memory_clock = smu->display_config->min_mem_set_clock;
2260 if (smu_feature_is_supported(smu, SMU_FEATURE_DPM_DCEFCLK_BIT)) {
2261 clock_req.clock_type = amd_pp_dcef_clock;
2262 clock_req.clock_freq_in_khz = min_clocks.dcef_clock * 10;
2263 if (!smu->funcs->display_clock_voltage_request(smu, &clock_req)) {
2264 if (smu_feature_is_supported(smu, SMU_FEATURE_DS_DCEFCLK_BIT)) {
2265 ret = smu_send_smc_msg_with_param(smu,
2266 SMU_MSG_SetMinDeepSleepDcefclk,
2267 min_clocks.dcef_clock_in_sr/100);
2269 pr_err("Attempt to set divider for DCEFCLK Failed!");
2274 pr_info("Attempt to set Hard Min for DCEFCLK Failed!");
2278 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT)) {
2279 memtable->dpm_state.hard_min_level = min_clocks.memory_clock/100;
2280 ret = smu_send_smc_msg_with_param(smu,
2281 SMU_MSG_SetHardMinByFreq,
2282 (PPCLK_UCLK << 16) | memtable->dpm_state.hard_min_level);
2284 pr_err("[%s] Set hard min uclk failed!", __func__);
2292 static uint32_t vega20_find_lowest_dpm_level(struct vega20_single_dpm_table *table)
2296 for (i = 0; i < table->count; i++) {
2297 if (table->dpm_levels[i].enabled)
2300 if (i >= table->count) {
2302 table->dpm_levels[i].enabled = true;
2308 static uint32_t vega20_find_highest_dpm_level(struct vega20_single_dpm_table *table)
2313 pr_err("[%s] DPM Table does not exist!", __func__);
2316 if (table->count <= 0) {
2317 pr_err("[%s] DPM Table has no entry!", __func__);
2320 if (table->count > MAX_REGULAR_DPM_NUMBER) {
2321 pr_err("[%s] DPM Table has too many entries!", __func__);
2322 return MAX_REGULAR_DPM_NUMBER - 1;
2325 for (i = table->count - 1; i >= 0; i--) {
2326 if (table->dpm_levels[i].enabled)
2331 table->dpm_levels[i].enabled = true;
2337 static int vega20_force_dpm_limit_value(struct smu_context *smu, bool highest)
2339 uint32_t soft_level;
2341 struct vega20_dpm_table *dpm_table =
2342 (struct vega20_dpm_table *)smu->smu_dpm.dpm_context;
2345 soft_level = vega20_find_highest_dpm_level(&(dpm_table->gfx_table));
2347 soft_level = vega20_find_lowest_dpm_level(&(dpm_table->gfx_table));
2349 dpm_table->gfx_table.dpm_state.soft_min_level =
2350 dpm_table->gfx_table.dpm_state.soft_max_level =
2351 dpm_table->gfx_table.dpm_levels[soft_level].value;
2354 soft_level = vega20_find_highest_dpm_level(&(dpm_table->mem_table));
2356 soft_level = vega20_find_lowest_dpm_level(&(dpm_table->mem_table));
2358 dpm_table->mem_table.dpm_state.soft_min_level =
2359 dpm_table->mem_table.dpm_state.soft_max_level =
2360 dpm_table->mem_table.dpm_levels[soft_level].value;
2363 soft_level = vega20_find_highest_dpm_level(&(dpm_table->soc_table));
2365 soft_level = vega20_find_lowest_dpm_level(&(dpm_table->soc_table));
2367 dpm_table->soc_table.dpm_state.soft_min_level =
2368 dpm_table->soc_table.dpm_state.soft_max_level =
2369 dpm_table->soc_table.dpm_levels[soft_level].value;
2371 ret = vega20_upload_dpm_level(smu, false, 0xFFFFFFFF);
2373 pr_err("Failed to upload boot level to %s!\n",
2374 highest ? "highest" : "lowest");
2378 ret = vega20_upload_dpm_level(smu, true, 0xFFFFFFFF);
2380 pr_err("Failed to upload dpm max level to %s!\n!",
2381 highest ? "highest" : "lowest");
2388 static int vega20_unforce_dpm_levels(struct smu_context *smu)
2390 uint32_t soft_min_level, soft_max_level;
2392 struct vega20_dpm_table *dpm_table =
2393 (struct vega20_dpm_table *)smu->smu_dpm.dpm_context;
2395 soft_min_level = vega20_find_lowest_dpm_level(&(dpm_table->gfx_table));
2396 soft_max_level = vega20_find_highest_dpm_level(&(dpm_table->gfx_table));
2397 dpm_table->gfx_table.dpm_state.soft_min_level =
2398 dpm_table->gfx_table.dpm_levels[soft_min_level].value;
2399 dpm_table->gfx_table.dpm_state.soft_max_level =
2400 dpm_table->gfx_table.dpm_levels[soft_max_level].value;
2402 soft_min_level = vega20_find_lowest_dpm_level(&(dpm_table->mem_table));
2403 soft_max_level = vega20_find_highest_dpm_level(&(dpm_table->mem_table));
2404 dpm_table->mem_table.dpm_state.soft_min_level =
2405 dpm_table->gfx_table.dpm_levels[soft_min_level].value;
2406 dpm_table->mem_table.dpm_state.soft_max_level =
2407 dpm_table->gfx_table.dpm_levels[soft_max_level].value;
2409 soft_min_level = vega20_find_lowest_dpm_level(&(dpm_table->soc_table));
2410 soft_max_level = vega20_find_highest_dpm_level(&(dpm_table->soc_table));
2411 dpm_table->soc_table.dpm_state.soft_min_level =
2412 dpm_table->soc_table.dpm_levels[soft_min_level].value;
2413 dpm_table->soc_table.dpm_state.soft_max_level =
2414 dpm_table->soc_table.dpm_levels[soft_max_level].value;
2416 ret = vega20_upload_dpm_level(smu, false, 0xFFFFFFFF);
2418 pr_err("Failed to upload DPM Bootup Levels!");
2422 ret = vega20_upload_dpm_level(smu, true, 0xFFFFFFFF);
2424 pr_err("Failed to upload DPM Max Levels!");
2431 static int vega20_update_specified_od8_value(struct smu_context *smu,
2435 struct smu_table_context *table_context = &smu->smu_table;
2436 OverDriveTable_t *od_table =
2437 (OverDriveTable_t *)(table_context->overdrive_table);
2438 struct vega20_od8_settings *od8_settings =
2439 (struct vega20_od8_settings *)smu->od_settings;
2442 case OD8_SETTING_GFXCLK_FMIN:
2443 od_table->GfxclkFmin = (uint16_t)value;
2446 case OD8_SETTING_GFXCLK_FMAX:
2447 if (value < od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMAX].min_value ||
2448 value > od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMAX].max_value)
2450 od_table->GfxclkFmax = (uint16_t)value;
2453 case OD8_SETTING_GFXCLK_FREQ1:
2454 od_table->GfxclkFreq1 = (uint16_t)value;
2457 case OD8_SETTING_GFXCLK_VOLTAGE1:
2458 od_table->GfxclkVolt1 = (uint16_t)value;
2461 case OD8_SETTING_GFXCLK_FREQ2:
2462 od_table->GfxclkFreq2 = (uint16_t)value;
2465 case OD8_SETTING_GFXCLK_VOLTAGE2:
2466 od_table->GfxclkVolt2 = (uint16_t)value;
2469 case OD8_SETTING_GFXCLK_FREQ3:
2470 od_table->GfxclkFreq3 = (uint16_t)value;
2473 case OD8_SETTING_GFXCLK_VOLTAGE3:
2474 od_table->GfxclkVolt3 = (uint16_t)value;
2477 case OD8_SETTING_UCLK_FMAX:
2478 if (value < od8_settings->od8_settings_array[OD8_SETTING_UCLK_FMAX].min_value ||
2479 value > od8_settings->od8_settings_array[OD8_SETTING_UCLK_FMAX].max_value)
2481 od_table->UclkFmax = (uint16_t)value;
2484 case OD8_SETTING_POWER_PERCENTAGE:
2485 od_table->OverDrivePct = (int16_t)value;
2488 case OD8_SETTING_FAN_ACOUSTIC_LIMIT:
2489 od_table->FanMaximumRpm = (uint16_t)value;
2492 case OD8_SETTING_FAN_MIN_SPEED:
2493 od_table->FanMinimumPwm = (uint16_t)value;
2496 case OD8_SETTING_FAN_TARGET_TEMP:
2497 od_table->FanTargetTemperature = (uint16_t)value;
2500 case OD8_SETTING_OPERATING_TEMP_MAX:
2501 od_table->MaxOpTemp = (uint16_t)value;
2508 static int vega20_update_od8_settings(struct smu_context *smu,
2512 struct smu_table_context *table_context = &smu->smu_table;
2515 ret = smu_update_table(smu, SMU_TABLE_OVERDRIVE, 0,
2516 table_context->overdrive_table, false);
2518 pr_err("Failed to export over drive table!\n");
2522 ret = vega20_update_specified_od8_value(smu, index, value);
2526 ret = smu_update_table(smu, SMU_TABLE_OVERDRIVE, 0,
2527 table_context->overdrive_table, true);
2529 pr_err("Failed to import over drive table!\n");
2536 static int vega20_set_od_percentage(struct smu_context *smu,
2537 enum smu_clk_type clk_type,
2540 struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
2541 struct vega20_dpm_table *dpm_table = NULL;
2542 struct vega20_dpm_table *golden_table = NULL;
2543 struct vega20_single_dpm_table *single_dpm_table;
2544 struct vega20_single_dpm_table *golden_dpm_table;
2545 uint32_t od_clk, index;
2547 int feature_enabled;
2550 mutex_lock(&(smu->mutex));
2552 dpm_table = smu_dpm->dpm_context;
2553 golden_table = smu_dpm->golden_dpm_context;
2557 single_dpm_table = &(dpm_table->gfx_table);
2558 golden_dpm_table = &(golden_table->gfx_table);
2559 feature_enabled = smu_feature_is_enabled(smu, SMU_FEATURE_DPM_GFXCLK_BIT);
2560 clk_id = PPCLK_GFXCLK;
2561 index = OD8_SETTING_GFXCLK_FMAX;
2564 single_dpm_table = &(dpm_table->mem_table);
2565 golden_dpm_table = &(golden_table->mem_table);
2566 feature_enabled = smu_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT);
2567 clk_id = PPCLK_UCLK;
2568 index = OD8_SETTING_UCLK_FMAX;
2578 od_clk = golden_dpm_table->dpm_levels[golden_dpm_table->count - 1].value * value;
2580 od_clk += golden_dpm_table->dpm_levels[golden_dpm_table->count - 1].value;
2582 ret = vega20_update_od8_settings(smu, index, od_clk);
2584 pr_err("[Setoverdrive] failed to set od clk!\n");
2588 if (feature_enabled) {
2589 ret = vega20_set_single_dpm_table(smu, single_dpm_table,
2592 pr_err("[Setoverdrive] failed to refresh dpm table!\n");
2596 single_dpm_table->count = 1;
2597 single_dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.gfxclk / 100;
2600 ret = smu_handle_task(smu, smu_dpm->dpm_level,
2601 AMD_PP_TASK_READJUST_POWER_STATE);
2604 mutex_unlock(&(smu->mutex));
2609 static int vega20_odn_edit_dpm_table(struct smu_context *smu,
2610 enum PP_OD_DPM_TABLE_COMMAND type,
2611 long *input, uint32_t size)
2613 struct smu_table_context *table_context = &smu->smu_table;
2614 OverDriveTable_t *od_table =
2615 (OverDriveTable_t *)(table_context->overdrive_table);
2616 struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
2617 struct vega20_dpm_table *dpm_table = NULL;
2618 struct vega20_single_dpm_table *single_dpm_table;
2619 struct vega20_od8_settings *od8_settings =
2620 (struct vega20_od8_settings *)smu->od_settings;
2621 struct pp_clock_levels_with_latency clocks;
2622 int32_t input_index, input_clk, input_vol, i;
2626 dpm_table = smu_dpm->dpm_context;
2629 pr_warn("NULL user input for clock and voltage\n");
2634 case PP_OD_EDIT_SCLK_VDDC_TABLE:
2635 if (!(od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMIN].feature_id &&
2636 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMAX].feature_id)) {
2637 pr_info("Sclk min/max frequency overdrive not supported\n");
2641 for (i = 0; i < size; i += 2) {
2643 pr_info("invalid number of input parameters %d\n", size);
2647 input_index = input[i];
2648 input_clk = input[i + 1];
2650 if (input_index != 0 && input_index != 1) {
2651 pr_info("Invalid index %d\n", input_index);
2652 pr_info("Support min/max sclk frequency settingonly which index by 0/1\n");
2656 if (input_clk < od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMIN].min_value ||
2657 input_clk > od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMAX].max_value) {
2658 pr_info("clock freq %d is not within allowed range [%d - %d]\n",
2660 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMIN].min_value,
2661 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMAX].max_value);
2665 if (input_index == 0 && od_table->GfxclkFmin != input_clk) {
2666 od_table->GfxclkFmin = input_clk;
2667 od8_settings->od_gfxclk_update = true;
2668 } else if (input_index == 1 && od_table->GfxclkFmax != input_clk) {
2669 od_table->GfxclkFmax = input_clk;
2670 od8_settings->od_gfxclk_update = true;
2676 case PP_OD_EDIT_MCLK_VDDC_TABLE:
2677 if (!od8_settings->od8_settings_array[OD8_SETTING_UCLK_FMAX].feature_id) {
2678 pr_info("Mclk max frequency overdrive not supported\n");
2682 single_dpm_table = &(dpm_table->mem_table);
2683 ret = vega20_get_clk_table(smu, &clocks, single_dpm_table);
2685 pr_err("Attempt to get memory clk levels Failed!");
2689 for (i = 0; i < size; i += 2) {
2691 pr_info("invalid number of input parameters %d\n",
2696 input_index = input[i];
2697 input_clk = input[i + 1];
2699 if (input_index != 1) {
2700 pr_info("Invalid index %d\n", input_index);
2701 pr_info("Support max Mclk frequency setting only which index by 1\n");
2705 if (input_clk < clocks.data[0].clocks_in_khz / 1000 ||
2706 input_clk > od8_settings->od8_settings_array[OD8_SETTING_UCLK_FMAX].max_value) {
2707 pr_info("clock freq %d is not within allowed range [%d - %d]\n",
2709 clocks.data[0].clocks_in_khz / 1000,
2710 od8_settings->od8_settings_array[OD8_SETTING_UCLK_FMAX].max_value);
2714 if (input_index == 1 && od_table->UclkFmax != input_clk) {
2715 od8_settings->od_gfxclk_update = true;
2716 od_table->UclkFmax = input_clk;
2722 case PP_OD_EDIT_VDDC_CURVE:
2723 if (!(od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ1].feature_id &&
2724 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ2].feature_id &&
2725 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ3].feature_id &&
2726 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE1].feature_id &&
2727 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE2].feature_id &&
2728 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE3].feature_id)) {
2729 pr_info("Voltage curve calibrate not supported\n");
2733 for (i = 0; i < size; i += 3) {
2735 pr_info("invalid number of input parameters %d\n",
2740 input_index = input[i];
2741 input_clk = input[i + 1];
2742 input_vol = input[i + 2];
2744 if (input_index > 2) {
2745 pr_info("Setting for point %d is not supported\n",
2747 pr_info("Three supported points index by 0, 1, 2\n");
2751 od8_id = OD8_SETTING_GFXCLK_FREQ1 + 2 * input_index;
2752 if (input_clk < od8_settings->od8_settings_array[od8_id].min_value ||
2753 input_clk > od8_settings->od8_settings_array[od8_id].max_value) {
2754 pr_info("clock freq %d is not within allowed range [%d - %d]\n",
2756 od8_settings->od8_settings_array[od8_id].min_value,
2757 od8_settings->od8_settings_array[od8_id].max_value);
2761 od8_id = OD8_SETTING_GFXCLK_VOLTAGE1 + 2 * input_index;
2762 if (input_vol < od8_settings->od8_settings_array[od8_id].min_value ||
2763 input_vol > od8_settings->od8_settings_array[od8_id].max_value) {
2764 pr_info("clock voltage %d is not within allowed range [%d- %d]\n",
2766 od8_settings->od8_settings_array[od8_id].min_value,
2767 od8_settings->od8_settings_array[od8_id].max_value);
2771 switch (input_index) {
2773 od_table->GfxclkFreq1 = input_clk;
2774 od_table->GfxclkVolt1 = input_vol * VOLTAGE_SCALE;
2777 od_table->GfxclkFreq2 = input_clk;
2778 od_table->GfxclkVolt2 = input_vol * VOLTAGE_SCALE;
2781 od_table->GfxclkFreq3 = input_clk;
2782 od_table->GfxclkVolt3 = input_vol * VOLTAGE_SCALE;
2789 case PP_OD_RESTORE_DEFAULT_TABLE:
2790 ret = smu_update_table(smu, SMU_TABLE_OVERDRIVE, 0, table_context->overdrive_table, false);
2792 pr_err("Failed to export over drive table!\n");
2798 case PP_OD_COMMIT_DPM_TABLE:
2799 ret = smu_update_table(smu, SMU_TABLE_OVERDRIVE, 0, table_context->overdrive_table, true);
2801 pr_err("Failed to import over drive table!\n");
2805 /* retrieve updated gfxclk table */
2806 if (od8_settings->od_gfxclk_update) {
2807 od8_settings->od_gfxclk_update = false;
2808 single_dpm_table = &(dpm_table->gfx_table);
2810 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_GFXCLK_BIT)) {
2811 ret = vega20_set_single_dpm_table(smu, single_dpm_table,
2814 pr_err("[Setoverdrive] failed to refresh dpm table!\n");
2818 single_dpm_table->count = 1;
2819 single_dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.gfxclk / 100;
2829 if (type == PP_OD_COMMIT_DPM_TABLE) {
2830 mutex_lock(&(smu->mutex));
2831 ret = smu_handle_task(smu, smu_dpm->dpm_level,
2832 AMD_PP_TASK_READJUST_POWER_STATE);
2833 mutex_unlock(&(smu->mutex));
2839 static int vega20_dpm_set_uvd_enable(struct smu_context *smu, bool enable)
2841 if (!smu_feature_is_supported(smu, SMU_FEATURE_DPM_UVD_BIT))
2844 if (enable == smu_feature_is_enabled(smu, SMU_FEATURE_DPM_UVD_BIT))
2847 return smu_feature_set_enabled(smu, SMU_FEATURE_DPM_UVD_BIT, enable);
2850 static int vega20_dpm_set_vce_enable(struct smu_context *smu, bool enable)
2852 if (!smu_feature_is_supported(smu, SMU_FEATURE_DPM_VCE_BIT))
2855 if (enable == smu_feature_is_enabled(smu, SMU_FEATURE_DPM_VCE_BIT))
2858 return smu_feature_set_enabled(smu, SMU_FEATURE_DPM_VCE_BIT, enable);
2861 static int vega20_get_enabled_smc_features(struct smu_context *smu,
2862 uint64_t *features_enabled)
2864 uint32_t feature_mask[2] = {0, 0};
2867 ret = smu_feature_get_enabled_mask(smu, feature_mask, 2);
2871 *features_enabled = ((((uint64_t)feature_mask[0] << SMU_FEATURES_LOW_SHIFT) & SMU_FEATURES_LOW_MASK) |
2872 (((uint64_t)feature_mask[1] << SMU_FEATURES_HIGH_SHIFT) & SMU_FEATURES_HIGH_MASK));
2877 static int vega20_enable_smc_features(struct smu_context *smu,
2878 bool enable, uint64_t feature_mask)
2880 uint32_t smu_features_low, smu_features_high;
2883 smu_features_low = (uint32_t)((feature_mask & SMU_FEATURES_LOW_MASK) >> SMU_FEATURES_LOW_SHIFT);
2884 smu_features_high = (uint32_t)((feature_mask & SMU_FEATURES_HIGH_MASK) >> SMU_FEATURES_HIGH_SHIFT);
2887 ret = smu_send_smc_msg_with_param(smu, SMU_MSG_EnableSmuFeaturesLow,
2891 ret = smu_send_smc_msg_with_param(smu, SMU_MSG_EnableSmuFeaturesHigh,
2896 ret = smu_send_smc_msg_with_param(smu, SMU_MSG_DisableSmuFeaturesLow,
2900 ret = smu_send_smc_msg_with_param(smu, SMU_MSG_DisableSmuFeaturesHigh,
2910 static int vega20_get_ppfeature_status(struct smu_context *smu, char *buf)
2912 static const char *ppfeature_name[] = {
2947 static const char *output_title[] = {
2951 uint64_t features_enabled;
2956 ret = vega20_get_enabled_smc_features(smu, &features_enabled);
2960 size += sprintf(buf + size, "Current ppfeatures: 0x%016llx\n", features_enabled);
2961 size += sprintf(buf + size, "%-19s %-22s %s\n",
2965 for (i = 0; i < GNLD_FEATURES_MAX; i++) {
2966 size += sprintf(buf + size, "%-19s 0x%016llx %6s\n",
2969 (features_enabled & (1ULL << i)) ? "Y" : "N");
2975 static int vega20_set_ppfeature_status(struct smu_context *smu, uint64_t new_ppfeature_masks)
2977 uint64_t features_enabled;
2978 uint64_t features_to_enable;
2979 uint64_t features_to_disable;
2982 if (new_ppfeature_masks >= (1ULL << GNLD_FEATURES_MAX))
2985 ret = vega20_get_enabled_smc_features(smu, &features_enabled);
2989 features_to_disable =
2990 features_enabled & ~new_ppfeature_masks;
2991 features_to_enable =
2992 ~features_enabled & new_ppfeature_masks;
2994 pr_debug("features_to_disable 0x%llx\n", features_to_disable);
2995 pr_debug("features_to_enable 0x%llx\n", features_to_enable);
2997 if (features_to_disable) {
2998 ret = vega20_enable_smc_features(smu, false, features_to_disable);
3003 if (features_to_enable) {
3004 ret = vega20_enable_smc_features(smu, true, features_to_enable);
3012 static bool vega20_is_dpm_running(struct smu_context *smu)
3015 uint32_t feature_mask[2];
3016 unsigned long feature_enabled;
3017 ret = smu_feature_get_enabled_mask(smu, feature_mask, 2);
3018 feature_enabled = (unsigned long)((uint64_t)feature_mask[0] |
3019 ((uint64_t)feature_mask[1] << 32));
3020 return !!(feature_enabled & SMC_DPM_FEATURE);
3023 static int vega20_set_thermal_fan_table(struct smu_context *smu)
3026 struct smu_table_context *table_context = &smu->smu_table;
3027 PPTable_t *pptable = table_context->driver_pptable;
3029 ret = smu_send_smc_msg_with_param(smu, SMU_MSG_SetFanTemperatureTarget,
3030 (uint32_t)pptable->FanTargetTemperature);
3035 static int vega20_get_fan_speed_rpm(struct smu_context *smu,
3040 ret = smu_send_smc_msg(smu, SMU_MSG_GetCurrentRpm);
3043 pr_err("Attempt to get current RPM from SMC Failed!\n");
3047 smu_read_smc_arg(smu, speed);
3052 static int vega20_get_fan_speed_percent(struct smu_context *smu,
3056 uint32_t current_rpm = 0, percent = 0;
3057 PPTable_t *pptable = smu->smu_table.driver_pptable;
3059 ret = vega20_get_fan_speed_rpm(smu, ¤t_rpm);
3063 percent = current_rpm * 100 / pptable->FanMaximumRpm;
3064 *speed = percent > 100 ? 100 : percent;
3069 static int vega20_get_gpu_power(struct smu_context *smu, uint32_t *value)
3072 SmuMetrics_t metrics;
3077 ret = vega20_get_metrics_table(smu, &metrics);
3081 *value = metrics.CurrSocketPower << 8;
3086 static int vega20_get_current_activity_percent(struct smu_context *smu,
3087 enum amd_pp_sensors sensor,
3091 SmuMetrics_t metrics;
3096 ret = vega20_get_metrics_table(smu, &metrics);
3101 case AMDGPU_PP_SENSOR_GPU_LOAD:
3102 *value = metrics.AverageGfxActivity;
3104 case AMDGPU_PP_SENSOR_MEM_LOAD:
3105 *value = metrics.AverageUclkActivity;
3108 pr_err("Invalid sensor for retrieving clock activity\n");
3115 static int vega20_thermal_get_temperature(struct smu_context *smu,
3116 enum amd_pp_sensors sensor,
3119 struct amdgpu_device *adev = smu->adev;
3120 SmuMetrics_t metrics;
3127 ret = vega20_get_metrics_table(smu, &metrics);
3132 case AMDGPU_PP_SENSOR_HOTSPOT_TEMP:
3133 temp = RREG32_SOC15(THM, 0, mmCG_MULT_THERMAL_STATUS);
3134 temp = (temp & CG_MULT_THERMAL_STATUS__CTF_TEMP_MASK) >>
3135 CG_MULT_THERMAL_STATUS__CTF_TEMP__SHIFT;
3137 temp = temp & 0x1ff;
3138 temp *= SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
3142 case AMDGPU_PP_SENSOR_EDGE_TEMP:
3143 *value = metrics.TemperatureEdge *
3144 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
3146 case AMDGPU_PP_SENSOR_MEM_TEMP:
3147 *value = metrics.TemperatureHBM *
3148 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
3151 pr_err("Invalid sensor for retrieving temp\n");
3157 static int vega20_read_sensor(struct smu_context *smu,
3158 enum amd_pp_sensors sensor,
3159 void *data, uint32_t *size)
3162 struct smu_table_context *table_context = &smu->smu_table;
3163 PPTable_t *pptable = table_context->driver_pptable;
3166 case AMDGPU_PP_SENSOR_MAX_FAN_RPM:
3167 *(uint32_t *)data = pptable->FanMaximumRpm;
3170 case AMDGPU_PP_SENSOR_MEM_LOAD:
3171 case AMDGPU_PP_SENSOR_GPU_LOAD:
3172 ret = vega20_get_current_activity_percent(smu,
3177 case AMDGPU_PP_SENSOR_GPU_POWER:
3178 ret = vega20_get_gpu_power(smu, (uint32_t *)data);
3181 case AMDGPU_PP_SENSOR_HOTSPOT_TEMP:
3182 case AMDGPU_PP_SENSOR_EDGE_TEMP:
3183 case AMDGPU_PP_SENSOR_MEM_TEMP:
3184 ret = vega20_thermal_get_temperature(smu, sensor, (uint32_t *)data);
3194 static int vega20_set_watermarks_table(struct smu_context *smu,
3195 void *watermarks, struct
3196 dm_pp_wm_sets_with_clock_ranges_soc15
3200 Watermarks_t *table = watermarks;
3202 if (!table || !clock_ranges)
3205 if (clock_ranges->num_wm_dmif_sets > 4 ||
3206 clock_ranges->num_wm_mcif_sets > 4)
3209 for (i = 0; i < clock_ranges->num_wm_dmif_sets; i++) {
3210 table->WatermarkRow[1][i].MinClock =
3211 cpu_to_le16((uint16_t)
3212 (clock_ranges->wm_dmif_clocks_ranges[i].wm_min_dcfclk_clk_in_khz /
3214 table->WatermarkRow[1][i].MaxClock =
3215 cpu_to_le16((uint16_t)
3216 (clock_ranges->wm_dmif_clocks_ranges[i].wm_max_dcfclk_clk_in_khz /
3218 table->WatermarkRow[1][i].MinUclk =
3219 cpu_to_le16((uint16_t)
3220 (clock_ranges->wm_dmif_clocks_ranges[i].wm_min_mem_clk_in_khz /
3222 table->WatermarkRow[1][i].MaxUclk =
3223 cpu_to_le16((uint16_t)
3224 (clock_ranges->wm_dmif_clocks_ranges[i].wm_max_mem_clk_in_khz /
3226 table->WatermarkRow[1][i].WmSetting = (uint8_t)
3227 clock_ranges->wm_dmif_clocks_ranges[i].wm_set_id;
3230 for (i = 0; i < clock_ranges->num_wm_mcif_sets; i++) {
3231 table->WatermarkRow[0][i].MinClock =
3232 cpu_to_le16((uint16_t)
3233 (clock_ranges->wm_mcif_clocks_ranges[i].wm_min_socclk_clk_in_khz /
3235 table->WatermarkRow[0][i].MaxClock =
3236 cpu_to_le16((uint16_t)
3237 (clock_ranges->wm_mcif_clocks_ranges[i].wm_max_socclk_clk_in_khz /
3239 table->WatermarkRow[0][i].MinUclk =
3240 cpu_to_le16((uint16_t)
3241 (clock_ranges->wm_mcif_clocks_ranges[i].wm_min_mem_clk_in_khz /
3243 table->WatermarkRow[0][i].MaxUclk =
3244 cpu_to_le16((uint16_t)
3245 (clock_ranges->wm_mcif_clocks_ranges[i].wm_max_mem_clk_in_khz /
3247 table->WatermarkRow[0][i].WmSetting = (uint8_t)
3248 clock_ranges->wm_mcif_clocks_ranges[i].wm_set_id;
3254 static int vega20_get_thermal_temperature_range(struct smu_context *smu,
3255 struct smu_temperature_range *range)
3257 struct smu_table_context *table_context = &smu->smu_table;
3258 ATOM_Vega20_POWERPLAYTABLE *powerplay_table = table_context->power_play_table;
3259 PPTable_t *pptable = smu->smu_table.driver_pptable;
3261 if (!range || !powerplay_table)
3264 /* The unit is temperature */
3266 range->max = powerplay_table->usSoftwareShutdownTemp;
3267 range->edge_emergency_max = (pptable->TedgeLimit + CTF_OFFSET_EDGE);
3268 range->hotspot_crit_max = pptable->ThotspotLimit;
3269 range->hotspot_emergency_max = (pptable->ThotspotLimit + CTF_OFFSET_HOTSPOT);
3270 range->mem_crit_max = pptable->ThbmLimit;
3271 range->mem_emergency_max = (pptable->ThbmLimit + CTF_OFFSET_HBM);
3277 static const struct pptable_funcs vega20_ppt_funcs = {
3278 .tables_init = vega20_tables_init,
3279 .alloc_dpm_context = vega20_allocate_dpm_context,
3280 .store_powerplay_table = vega20_store_powerplay_table,
3281 .check_powerplay_table = vega20_check_powerplay_table,
3282 .append_powerplay_table = vega20_append_powerplay_table,
3283 .get_smu_msg_index = vega20_get_smu_msg_index,
3284 .get_smu_clk_index = vega20_get_smu_clk_index,
3285 .get_smu_feature_index = vega20_get_smu_feature_index,
3286 .get_smu_table_index = vega20_get_smu_table_index,
3287 .get_smu_power_index = vega20_get_pwr_src_index,
3288 .get_workload_type = vega20_get_workload_type,
3289 .run_afll_btc = vega20_run_btc_afll,
3290 .get_allowed_feature_mask = vega20_get_allowed_feature_mask,
3291 .get_current_power_state = vega20_get_current_power_state,
3292 .set_default_dpm_table = vega20_set_default_dpm_table,
3293 .set_power_state = NULL,
3294 .populate_umd_state_clk = vega20_populate_umd_state_clk,
3295 .print_clk_levels = vega20_print_clk_levels,
3296 .force_clk_levels = vega20_force_clk_levels,
3297 .get_clock_by_type_with_latency = vega20_get_clock_by_type_with_latency,
3298 .get_od_percentage = vega20_get_od_percentage,
3299 .get_power_profile_mode = vega20_get_power_profile_mode,
3300 .set_power_profile_mode = vega20_set_power_profile_mode,
3301 .set_od_percentage = vega20_set_od_percentage,
3302 .set_default_od_settings = vega20_set_default_od_settings,
3303 .od_edit_dpm_table = vega20_odn_edit_dpm_table,
3304 .dpm_set_uvd_enable = vega20_dpm_set_uvd_enable,
3305 .dpm_set_vce_enable = vega20_dpm_set_vce_enable,
3306 .read_sensor = vega20_read_sensor,
3307 .pre_display_config_changed = vega20_pre_display_config_changed,
3308 .display_config_changed = vega20_display_config_changed,
3309 .apply_clocks_adjust_rules = vega20_apply_clocks_adjust_rules,
3310 .notify_smc_dispaly_config = vega20_notify_smc_dispaly_config,
3311 .force_dpm_limit_value = vega20_force_dpm_limit_value,
3312 .unforce_dpm_levels = vega20_unforce_dpm_levels,
3313 .get_profiling_clk_mask = vega20_get_profiling_clk_mask,
3314 .set_ppfeature_status = vega20_set_ppfeature_status,
3315 .get_ppfeature_status = vega20_get_ppfeature_status,
3316 .is_dpm_running = vega20_is_dpm_running,
3317 .set_thermal_fan_table = vega20_set_thermal_fan_table,
3318 .get_fan_speed_percent = vega20_get_fan_speed_percent,
3319 .get_fan_speed_rpm = vega20_get_fan_speed_rpm,
3320 .set_watermarks_table = vega20_set_watermarks_table,
3321 .get_thermal_temperature_range = vega20_get_thermal_temperature_range
3324 void vega20_set_ppt_funcs(struct smu_context *smu)
3326 struct smu_table_context *smu_table = &smu->smu_table;
3328 smu->ppt_funcs = &vega20_ppt_funcs;
3329 smu->smc_if_version = SMU11_DRIVER_IF_VERSION;
3330 smu_table->table_count = TABLE_COUNT;