xref: /linux/drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c (revision ec8a42e7343234802b9054874fe01810880289ce)
1 /*
2  * Copyright 2019 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  */
23 
24 #define SWSMU_CODE_LAYER_L2
25 
26 #include <linux/firmware.h>
27 #include <linux/pci.h>
28 #include <linux/i2c.h>
29 #include "amdgpu.h"
30 #include "amdgpu_smu.h"
31 #include "atomfirmware.h"
32 #include "amdgpu_atomfirmware.h"
33 #include "amdgpu_atombios.h"
34 #include "soc15_common.h"
35 #include "smu_v11_0.h"
36 #include "smu11_driver_if_navi10.h"
37 #include "atom.h"
38 #include "navi10_ppt.h"
39 #include "smu_v11_0_pptable.h"
40 #include "smu_v11_0_ppsmc.h"
41 #include "nbio/nbio_2_3_offset.h"
42 #include "nbio/nbio_2_3_sh_mask.h"
43 #include "thm/thm_11_0_2_offset.h"
44 #include "thm/thm_11_0_2_sh_mask.h"
45 
46 #include "asic_reg/mp/mp_11_0_sh_mask.h"
47 #include "smu_cmn.h"
48 #include "smu_11_0_cdr_table.h"
49 
50 /*
51  * DO NOT use these for err/warn/info/debug messages.
52  * Use dev_err, dev_warn, dev_info and dev_dbg instead.
53  * They are more MGPU friendly.
54  */
55 #undef pr_err
56 #undef pr_warn
57 #undef pr_info
58 #undef pr_debug
59 
60 #define to_amdgpu_device(x) (container_of(x, struct amdgpu_device, pm.smu_i2c))
61 
62 #define FEATURE_MASK(feature) (1ULL << feature)
63 #define SMC_DPM_FEATURE ( \
64 	FEATURE_MASK(FEATURE_DPM_PREFETCHER_BIT) | \
65 	FEATURE_MASK(FEATURE_DPM_GFXCLK_BIT)	 | \
66 	FEATURE_MASK(FEATURE_DPM_GFX_PACE_BIT)	 | \
67 	FEATURE_MASK(FEATURE_DPM_UCLK_BIT)	 | \
68 	FEATURE_MASK(FEATURE_DPM_SOCCLK_BIT)	 | \
69 	FEATURE_MASK(FEATURE_DPM_MP0CLK_BIT)	 | \
70 	FEATURE_MASK(FEATURE_DPM_LINK_BIT)	 | \
71 	FEATURE_MASK(FEATURE_DPM_DCEFCLK_BIT))
72 
73 static struct cmn2asic_msg_mapping navi10_message_map[SMU_MSG_MAX_COUNT] = {
74 	MSG_MAP(TestMessage,			PPSMC_MSG_TestMessage,			1),
75 	MSG_MAP(GetSmuVersion,			PPSMC_MSG_GetSmuVersion,		1),
76 	MSG_MAP(GetDriverIfVersion,		PPSMC_MSG_GetDriverIfVersion,		1),
77 	MSG_MAP(SetAllowedFeaturesMaskLow,	PPSMC_MSG_SetAllowedFeaturesMaskLow,	0),
78 	MSG_MAP(SetAllowedFeaturesMaskHigh,	PPSMC_MSG_SetAllowedFeaturesMaskHigh,	0),
79 	MSG_MAP(EnableAllSmuFeatures,		PPSMC_MSG_EnableAllSmuFeatures,		0),
80 	MSG_MAP(DisableAllSmuFeatures,		PPSMC_MSG_DisableAllSmuFeatures,	0),
81 	MSG_MAP(EnableSmuFeaturesLow,		PPSMC_MSG_EnableSmuFeaturesLow,		1),
82 	MSG_MAP(EnableSmuFeaturesHigh,		PPSMC_MSG_EnableSmuFeaturesHigh,	1),
83 	MSG_MAP(DisableSmuFeaturesLow,		PPSMC_MSG_DisableSmuFeaturesLow,	1),
84 	MSG_MAP(DisableSmuFeaturesHigh,		PPSMC_MSG_DisableSmuFeaturesHigh,	1),
85 	MSG_MAP(GetEnabledSmuFeaturesLow,	PPSMC_MSG_GetEnabledSmuFeaturesLow,	1),
86 	MSG_MAP(GetEnabledSmuFeaturesHigh,	PPSMC_MSG_GetEnabledSmuFeaturesHigh,	1),
87 	MSG_MAP(SetWorkloadMask,		PPSMC_MSG_SetWorkloadMask,		1),
88 	MSG_MAP(SetPptLimit,			PPSMC_MSG_SetPptLimit,			0),
89 	MSG_MAP(SetDriverDramAddrHigh,		PPSMC_MSG_SetDriverDramAddrHigh,	0),
90 	MSG_MAP(SetDriverDramAddrLow,		PPSMC_MSG_SetDriverDramAddrLow,		0),
91 	MSG_MAP(SetToolsDramAddrHigh,		PPSMC_MSG_SetToolsDramAddrHigh,		0),
92 	MSG_MAP(SetToolsDramAddrLow,		PPSMC_MSG_SetToolsDramAddrLow,		0),
93 	MSG_MAP(TransferTableSmu2Dram,		PPSMC_MSG_TransferTableSmu2Dram,	0),
94 	MSG_MAP(TransferTableDram2Smu,		PPSMC_MSG_TransferTableDram2Smu,	0),
95 	MSG_MAP(UseDefaultPPTable,		PPSMC_MSG_UseDefaultPPTable,		0),
96 	MSG_MAP(UseBackupPPTable,		PPSMC_MSG_UseBackupPPTable,		0),
97 	MSG_MAP(RunBtc,				PPSMC_MSG_RunBtc,			0),
98 	MSG_MAP(EnterBaco,			PPSMC_MSG_EnterBaco,			0),
99 	MSG_MAP(SetSoftMinByFreq,		PPSMC_MSG_SetSoftMinByFreq,		0),
100 	MSG_MAP(SetSoftMaxByFreq,		PPSMC_MSG_SetSoftMaxByFreq,		0),
101 	MSG_MAP(SetHardMinByFreq,		PPSMC_MSG_SetHardMinByFreq,		1),
102 	MSG_MAP(SetHardMaxByFreq,		PPSMC_MSG_SetHardMaxByFreq,		0),
103 	MSG_MAP(GetMinDpmFreq,			PPSMC_MSG_GetMinDpmFreq,		1),
104 	MSG_MAP(GetMaxDpmFreq,			PPSMC_MSG_GetMaxDpmFreq,		1),
105 	MSG_MAP(GetDpmFreqByIndex,		PPSMC_MSG_GetDpmFreqByIndex,		1),
106 	MSG_MAP(SetMemoryChannelConfig,		PPSMC_MSG_SetMemoryChannelConfig,	0),
107 	MSG_MAP(SetGeminiMode,			PPSMC_MSG_SetGeminiMode,		0),
108 	MSG_MAP(SetGeminiApertureHigh,		PPSMC_MSG_SetGeminiApertureHigh,	0),
109 	MSG_MAP(SetGeminiApertureLow,		PPSMC_MSG_SetGeminiApertureLow,		0),
110 	MSG_MAP(OverridePcieParameters,		PPSMC_MSG_OverridePcieParameters,	0),
111 	MSG_MAP(SetMinDeepSleepDcefclk,		PPSMC_MSG_SetMinDeepSleepDcefclk,	0),
112 	MSG_MAP(ReenableAcDcInterrupt,		PPSMC_MSG_ReenableAcDcInterrupt,	0),
113 	MSG_MAP(NotifyPowerSource,		PPSMC_MSG_NotifyPowerSource,		0),
114 	MSG_MAP(SetUclkFastSwitch,		PPSMC_MSG_SetUclkFastSwitch,		0),
115 	MSG_MAP(SetVideoFps,			PPSMC_MSG_SetVideoFps,			0),
116 	MSG_MAP(PrepareMp1ForUnload,		PPSMC_MSG_PrepareMp1ForUnload,		1),
117 	MSG_MAP(DramLogSetDramAddrHigh,		PPSMC_MSG_DramLogSetDramAddrHigh,	0),
118 	MSG_MAP(DramLogSetDramAddrLow,		PPSMC_MSG_DramLogSetDramAddrLow,	0),
119 	MSG_MAP(DramLogSetDramSize,		PPSMC_MSG_DramLogSetDramSize,		0),
120 	MSG_MAP(ConfigureGfxDidt,		PPSMC_MSG_ConfigureGfxDidt,		0),
121 	MSG_MAP(NumOfDisplays,			PPSMC_MSG_NumOfDisplays,		0),
122 	MSG_MAP(SetSystemVirtualDramAddrHigh,	PPSMC_MSG_SetSystemVirtualDramAddrHigh,	0),
123 	MSG_MAP(SetSystemVirtualDramAddrLow,	PPSMC_MSG_SetSystemVirtualDramAddrLow,	0),
124 	MSG_MAP(AllowGfxOff,			PPSMC_MSG_AllowGfxOff,			0),
125 	MSG_MAP(DisallowGfxOff,			PPSMC_MSG_DisallowGfxOff,		0),
126 	MSG_MAP(GetPptLimit,			PPSMC_MSG_GetPptLimit,			0),
127 	MSG_MAP(GetDcModeMaxDpmFreq,		PPSMC_MSG_GetDcModeMaxDpmFreq,		1),
128 	MSG_MAP(GetDebugData,			PPSMC_MSG_GetDebugData,			0),
129 	MSG_MAP(ExitBaco,			PPSMC_MSG_ExitBaco,			0),
130 	MSG_MAP(PrepareMp1ForReset,		PPSMC_MSG_PrepareMp1ForReset,		0),
131 	MSG_MAP(PrepareMp1ForShutdown,		PPSMC_MSG_PrepareMp1ForShutdown,	0),
132 	MSG_MAP(PowerUpVcn,			PPSMC_MSG_PowerUpVcn,			0),
133 	MSG_MAP(PowerDownVcn,			PPSMC_MSG_PowerDownVcn,			0),
134 	MSG_MAP(PowerUpJpeg,			PPSMC_MSG_PowerUpJpeg,			0),
135 	MSG_MAP(PowerDownJpeg,			PPSMC_MSG_PowerDownJpeg,		0),
136 	MSG_MAP(BacoAudioD3PME,			PPSMC_MSG_BacoAudioD3PME,		0),
137 	MSG_MAP(ArmD3,				PPSMC_MSG_ArmD3,			0),
138 	MSG_MAP(DAL_DISABLE_DUMMY_PSTATE_CHANGE,PPSMC_MSG_DALDisableDummyPstateChange,	0),
139 	MSG_MAP(DAL_ENABLE_DUMMY_PSTATE_CHANGE,	PPSMC_MSG_DALEnableDummyPstateChange,	0),
140 	MSG_MAP(GetVoltageByDpm,		PPSMC_MSG_GetVoltageByDpm,		0),
141 	MSG_MAP(GetVoltageByDpmOverdrive,	PPSMC_MSG_GetVoltageByDpmOverdrive,	0),
142 	MSG_MAP(SetMGpuFanBoostLimitRpm,	PPSMC_MSG_SetMGpuFanBoostLimitRpm,	0),
143 	MSG_MAP(SET_DRIVER_DUMMY_TABLE_DRAM_ADDR_HIGH, PPSMC_MSG_SetDriverDummyTableDramAddrHigh, 0),
144 	MSG_MAP(SET_DRIVER_DUMMY_TABLE_DRAM_ADDR_LOW, PPSMC_MSG_SetDriverDummyTableDramAddrLow, 0),
145 	MSG_MAP(GET_UMC_FW_WA,			PPSMC_MSG_GetUMCFWWA,			0),
146 };
147 
148 static struct cmn2asic_mapping navi10_clk_map[SMU_CLK_COUNT] = {
149 	CLK_MAP(GFXCLK, PPCLK_GFXCLK),
150 	CLK_MAP(SCLK,	PPCLK_GFXCLK),
151 	CLK_MAP(SOCCLK, PPCLK_SOCCLK),
152 	CLK_MAP(FCLK, PPCLK_SOCCLK),
153 	CLK_MAP(UCLK, PPCLK_UCLK),
154 	CLK_MAP(MCLK, PPCLK_UCLK),
155 	CLK_MAP(DCLK, PPCLK_DCLK),
156 	CLK_MAP(VCLK, PPCLK_VCLK),
157 	CLK_MAP(DCEFCLK, PPCLK_DCEFCLK),
158 	CLK_MAP(DISPCLK, PPCLK_DISPCLK),
159 	CLK_MAP(PIXCLK, PPCLK_PIXCLK),
160 	CLK_MAP(PHYCLK, PPCLK_PHYCLK),
161 };
162 
163 static struct cmn2asic_mapping navi10_feature_mask_map[SMU_FEATURE_COUNT] = {
164 	FEA_MAP(DPM_PREFETCHER),
165 	FEA_MAP(DPM_GFXCLK),
166 	FEA_MAP(DPM_GFX_PACE),
167 	FEA_MAP(DPM_UCLK),
168 	FEA_MAP(DPM_SOCCLK),
169 	FEA_MAP(DPM_MP0CLK),
170 	FEA_MAP(DPM_LINK),
171 	FEA_MAP(DPM_DCEFCLK),
172 	FEA_MAP(MEM_VDDCI_SCALING),
173 	FEA_MAP(MEM_MVDD_SCALING),
174 	FEA_MAP(DS_GFXCLK),
175 	FEA_MAP(DS_SOCCLK),
176 	FEA_MAP(DS_LCLK),
177 	FEA_MAP(DS_DCEFCLK),
178 	FEA_MAP(DS_UCLK),
179 	FEA_MAP(GFX_ULV),
180 	FEA_MAP(FW_DSTATE),
181 	FEA_MAP(GFXOFF),
182 	FEA_MAP(BACO),
183 	FEA_MAP(VCN_PG),
184 	FEA_MAP(JPEG_PG),
185 	FEA_MAP(USB_PG),
186 	FEA_MAP(RSMU_SMN_CG),
187 	FEA_MAP(PPT),
188 	FEA_MAP(TDC),
189 	FEA_MAP(GFX_EDC),
190 	FEA_MAP(APCC_PLUS),
191 	FEA_MAP(GTHR),
192 	FEA_MAP(ACDC),
193 	FEA_MAP(VR0HOT),
194 	FEA_MAP(VR1HOT),
195 	FEA_MAP(FW_CTF),
196 	FEA_MAP(FAN_CONTROL),
197 	FEA_MAP(THERMAL),
198 	FEA_MAP(GFX_DCS),
199 	FEA_MAP(RM),
200 	FEA_MAP(LED_DISPLAY),
201 	FEA_MAP(GFX_SS),
202 	FEA_MAP(OUT_OF_BAND_MONITOR),
203 	FEA_MAP(TEMP_DEPENDENT_VMIN),
204 	FEA_MAP(MMHUB_PG),
205 	FEA_MAP(ATHUB_PG),
206 	FEA_MAP(APCC_DFLL),
207 };
208 
209 static struct cmn2asic_mapping navi10_table_map[SMU_TABLE_COUNT] = {
210 	TAB_MAP(PPTABLE),
211 	TAB_MAP(WATERMARKS),
212 	TAB_MAP(AVFS),
213 	TAB_MAP(AVFS_PSM_DEBUG),
214 	TAB_MAP(AVFS_FUSE_OVERRIDE),
215 	TAB_MAP(PMSTATUSLOG),
216 	TAB_MAP(SMU_METRICS),
217 	TAB_MAP(DRIVER_SMU_CONFIG),
218 	TAB_MAP(ACTIVITY_MONITOR_COEFF),
219 	TAB_MAP(OVERDRIVE),
220 	TAB_MAP(I2C_COMMANDS),
221 	TAB_MAP(PACE),
222 };
223 
224 static struct cmn2asic_mapping navi10_pwr_src_map[SMU_POWER_SOURCE_COUNT] = {
225 	PWR_MAP(AC),
226 	PWR_MAP(DC),
227 };
228 
229 static struct cmn2asic_mapping navi10_workload_map[PP_SMC_POWER_PROFILE_COUNT] = {
230 	WORKLOAD_MAP(PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT,	WORKLOAD_PPLIB_DEFAULT_BIT),
231 	WORKLOAD_MAP(PP_SMC_POWER_PROFILE_FULLSCREEN3D,		WORKLOAD_PPLIB_FULL_SCREEN_3D_BIT),
232 	WORKLOAD_MAP(PP_SMC_POWER_PROFILE_POWERSAVING,		WORKLOAD_PPLIB_POWER_SAVING_BIT),
233 	WORKLOAD_MAP(PP_SMC_POWER_PROFILE_VIDEO,		WORKLOAD_PPLIB_VIDEO_BIT),
234 	WORKLOAD_MAP(PP_SMC_POWER_PROFILE_VR,			WORKLOAD_PPLIB_VR_BIT),
235 	WORKLOAD_MAP(PP_SMC_POWER_PROFILE_COMPUTE,		WORKLOAD_PPLIB_COMPUTE_BIT),
236 	WORKLOAD_MAP(PP_SMC_POWER_PROFILE_CUSTOM,		WORKLOAD_PPLIB_CUSTOM_BIT),
237 };
238 
239 static bool is_asic_secure(struct smu_context *smu)
240 {
241 	struct amdgpu_device *adev = smu->adev;
242 	bool is_secure = true;
243 	uint32_t mp0_fw_intf;
244 
245 	mp0_fw_intf = RREG32_PCIE(MP0_Public |
246 				   (smnMP0_FW_INTF & 0xffffffff));
247 
248 	if (!(mp0_fw_intf & (1 << 19)))
249 		is_secure = false;
250 
251 	return is_secure;
252 }
253 
254 static int
255 navi10_get_allowed_feature_mask(struct smu_context *smu,
256 				  uint32_t *feature_mask, uint32_t num)
257 {
258 	struct amdgpu_device *adev = smu->adev;
259 
260 	if (num > 2)
261 		return -EINVAL;
262 
263 	memset(feature_mask, 0, sizeof(uint32_t) * num);
264 
265 	*(uint64_t *)feature_mask |= FEATURE_MASK(FEATURE_DPM_PREFETCHER_BIT)
266 				| FEATURE_MASK(FEATURE_DPM_MP0CLK_BIT)
267 				| FEATURE_MASK(FEATURE_RSMU_SMN_CG_BIT)
268 				| FEATURE_MASK(FEATURE_DS_SOCCLK_BIT)
269 				| FEATURE_MASK(FEATURE_PPT_BIT)
270 				| FEATURE_MASK(FEATURE_TDC_BIT)
271 				| FEATURE_MASK(FEATURE_GFX_EDC_BIT)
272 				| FEATURE_MASK(FEATURE_APCC_PLUS_BIT)
273 				| FEATURE_MASK(FEATURE_VR0HOT_BIT)
274 				| FEATURE_MASK(FEATURE_FAN_CONTROL_BIT)
275 				| FEATURE_MASK(FEATURE_THERMAL_BIT)
276 				| FEATURE_MASK(FEATURE_LED_DISPLAY_BIT)
277 				| FEATURE_MASK(FEATURE_DS_LCLK_BIT)
278 				| FEATURE_MASK(FEATURE_DS_DCEFCLK_BIT)
279 				| FEATURE_MASK(FEATURE_FW_DSTATE_BIT)
280 				| FEATURE_MASK(FEATURE_BACO_BIT)
281 				| FEATURE_MASK(FEATURE_GFX_SS_BIT)
282 				| FEATURE_MASK(FEATURE_APCC_DFLL_BIT)
283 				| FEATURE_MASK(FEATURE_FW_CTF_BIT)
284 				| FEATURE_MASK(FEATURE_OUT_OF_BAND_MONITOR_BIT);
285 
286 	if (adev->pm.pp_feature & PP_SCLK_DPM_MASK)
287 		*(uint64_t *)feature_mask |= FEATURE_MASK(FEATURE_DPM_GFXCLK_BIT);
288 
289 	if (adev->pm.pp_feature & PP_PCIE_DPM_MASK)
290 		*(uint64_t *)feature_mask |= FEATURE_MASK(FEATURE_DPM_LINK_BIT);
291 
292 	if (adev->pm.pp_feature & PP_DCEFCLK_DPM_MASK)
293 		*(uint64_t *)feature_mask |= FEATURE_MASK(FEATURE_DPM_DCEFCLK_BIT);
294 
295 	if (adev->pm.pp_feature & PP_ULV_MASK)
296 		*(uint64_t *)feature_mask |= FEATURE_MASK(FEATURE_GFX_ULV_BIT);
297 
298 	if (adev->pm.pp_feature & PP_SCLK_DEEP_SLEEP_MASK)
299 		*(uint64_t *)feature_mask |= FEATURE_MASK(FEATURE_DS_GFXCLK_BIT);
300 
301 	if (adev->pm.pp_feature & PP_GFXOFF_MASK)
302 		*(uint64_t *)feature_mask |= FEATURE_MASK(FEATURE_GFXOFF_BIT);
303 
304 	if (smu->adev->pg_flags & AMD_PG_SUPPORT_MMHUB)
305 		*(uint64_t *)feature_mask |= FEATURE_MASK(FEATURE_MMHUB_PG_BIT);
306 
307 	if (smu->adev->pg_flags & AMD_PG_SUPPORT_ATHUB)
308 		*(uint64_t *)feature_mask |= FEATURE_MASK(FEATURE_ATHUB_PG_BIT);
309 
310 	if (smu->adev->pg_flags & AMD_PG_SUPPORT_VCN)
311 		*(uint64_t *)feature_mask |= FEATURE_MASK(FEATURE_VCN_PG_BIT);
312 
313 	if (smu->adev->pg_flags & AMD_PG_SUPPORT_JPEG)
314 		*(uint64_t *)feature_mask |= FEATURE_MASK(FEATURE_JPEG_PG_BIT);
315 
316 	if (smu->dc_controlled_by_gpio)
317 		*(uint64_t *)feature_mask |= FEATURE_MASK(FEATURE_ACDC_BIT);
318 
319 	if (adev->pm.pp_feature & PP_SOCCLK_DPM_MASK)
320 		*(uint64_t *)feature_mask |= FEATURE_MASK(FEATURE_DPM_SOCCLK_BIT);
321 
322 	/* DPM UCLK enablement should be skipped for navi10 A0 secure board */
323 	if (!(is_asic_secure(smu) &&
324 	     (adev->asic_type == CHIP_NAVI10) &&
325 	     (adev->rev_id == 0)) &&
326 	    (adev->pm.pp_feature & PP_MCLK_DPM_MASK))
327 		*(uint64_t *)feature_mask |= FEATURE_MASK(FEATURE_DPM_UCLK_BIT)
328 				| FEATURE_MASK(FEATURE_MEM_VDDCI_SCALING_BIT)
329 				| FEATURE_MASK(FEATURE_MEM_MVDD_SCALING_BIT);
330 
331 	/* DS SOCCLK enablement should be skipped for navi10 A0 secure board */
332 	if (is_asic_secure(smu) &&
333 	    (adev->asic_type == CHIP_NAVI10) &&
334 	    (adev->rev_id == 0))
335 		*(uint64_t *)feature_mask &=
336 				~FEATURE_MASK(FEATURE_DS_SOCCLK_BIT);
337 
338 	return 0;
339 }
340 
341 static int navi10_check_powerplay_table(struct smu_context *smu)
342 {
343 	struct smu_table_context *table_context = &smu->smu_table;
344 	struct smu_11_0_powerplay_table *powerplay_table =
345 		table_context->power_play_table;
346 	struct smu_baco_context *smu_baco = &smu->smu_baco;
347 
348 	if (powerplay_table->platform_caps & SMU_11_0_PP_PLATFORM_CAP_HARDWAREDC)
349 		smu->dc_controlled_by_gpio = true;
350 
351 	if (powerplay_table->platform_caps & SMU_11_0_PP_PLATFORM_CAP_BACO ||
352 	    powerplay_table->platform_caps & SMU_11_0_PP_PLATFORM_CAP_MACO)
353 		smu_baco->platform_support = true;
354 
355 	table_context->thermal_controller_type =
356 		powerplay_table->thermal_controller_type;
357 
358 	/*
359 	 * Instead of having its own buffer space and get overdrive_table copied,
360 	 * smu->od_settings just points to the actual overdrive_table
361 	 */
362 	smu->od_settings = &powerplay_table->overdrive_table;
363 
364 	return 0;
365 }
366 
367 static int navi10_append_powerplay_table(struct smu_context *smu)
368 {
369 	struct amdgpu_device *adev = smu->adev;
370 	struct smu_table_context *table_context = &smu->smu_table;
371 	PPTable_t *smc_pptable = table_context->driver_pptable;
372 	struct atom_smc_dpm_info_v4_5 *smc_dpm_table;
373 	struct atom_smc_dpm_info_v4_7 *smc_dpm_table_v4_7;
374 	int index, ret;
375 
376 	index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
377 					   smc_dpm_info);
378 
379 	ret = amdgpu_atombios_get_data_table(adev, index, NULL, NULL, NULL,
380 				      (uint8_t **)&smc_dpm_table);
381 	if (ret)
382 		return ret;
383 
384 	dev_info(adev->dev, "smc_dpm_info table revision(format.content): %d.%d\n",
385 			smc_dpm_table->table_header.format_revision,
386 			smc_dpm_table->table_header.content_revision);
387 
388 	if (smc_dpm_table->table_header.format_revision != 4) {
389 		dev_err(adev->dev, "smc_dpm_info table format revision is not 4!\n");
390 		return -EINVAL;
391 	}
392 
393 	switch (smc_dpm_table->table_header.content_revision) {
394 	case 5: /* nv10 and nv14 */
395 		memcpy(smc_pptable->I2cControllers, smc_dpm_table->I2cControllers,
396 			sizeof(*smc_dpm_table) - sizeof(smc_dpm_table->table_header));
397 		break;
398 	case 7: /* nv12 */
399 		ret = amdgpu_atombios_get_data_table(adev, index, NULL, NULL, NULL,
400 					      (uint8_t **)&smc_dpm_table_v4_7);
401 		if (ret)
402 			return ret;
403 		memcpy(smc_pptable->I2cControllers, smc_dpm_table_v4_7->I2cControllers,
404 			sizeof(*smc_dpm_table_v4_7) - sizeof(smc_dpm_table_v4_7->table_header));
405 		break;
406 	default:
407 		dev_err(smu->adev->dev, "smc_dpm_info with unsupported content revision %d!\n",
408 				smc_dpm_table->table_header.content_revision);
409 		return -EINVAL;
410 	}
411 
412 	if (adev->pm.pp_feature & PP_GFXOFF_MASK) {
413 		/* TODO: remove it once SMU fw fix it */
414 		smc_pptable->DebugOverrides |= DPM_OVERRIDE_DISABLE_DFLL_PLL_SHUTDOWN;
415 	}
416 
417 	return 0;
418 }
419 
420 static int navi10_store_powerplay_table(struct smu_context *smu)
421 {
422 	struct smu_table_context *table_context = &smu->smu_table;
423 	struct smu_11_0_powerplay_table *powerplay_table =
424 		table_context->power_play_table;
425 
426 	memcpy(table_context->driver_pptable, &powerplay_table->smc_pptable,
427 	       sizeof(PPTable_t));
428 
429 	return 0;
430 }
431 
432 static int navi10_setup_pptable(struct smu_context *smu)
433 {
434 	int ret = 0;
435 
436 	ret = smu_v11_0_setup_pptable(smu);
437 	if (ret)
438 		return ret;
439 
440 	ret = navi10_store_powerplay_table(smu);
441 	if (ret)
442 		return ret;
443 
444 	ret = navi10_append_powerplay_table(smu);
445 	if (ret)
446 		return ret;
447 
448 	ret = navi10_check_powerplay_table(smu);
449 	if (ret)
450 		return ret;
451 
452 	return ret;
453 }
454 
455 static int navi10_tables_init(struct smu_context *smu)
456 {
457 	struct smu_table_context *smu_table = &smu->smu_table;
458 	struct smu_table *tables = smu_table->tables;
459 	struct amdgpu_device *adev = smu->adev;
460 
461 	SMU_TABLE_INIT(tables, SMU_TABLE_PPTABLE, sizeof(PPTable_t),
462 		       PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
463 	SMU_TABLE_INIT(tables, SMU_TABLE_WATERMARKS, sizeof(Watermarks_t),
464 		       PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
465 	if (adev->asic_type == CHIP_NAVI12)
466 		SMU_TABLE_INIT(tables, SMU_TABLE_SMU_METRICS, sizeof(SmuMetrics_NV12_t),
467 			       PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
468 	else
469 		SMU_TABLE_INIT(tables, SMU_TABLE_SMU_METRICS, sizeof(SmuMetrics_t),
470 			       PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
471 	SMU_TABLE_INIT(tables, SMU_TABLE_I2C_COMMANDS, sizeof(SwI2cRequest_t),
472 		       PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
473 	SMU_TABLE_INIT(tables, SMU_TABLE_OVERDRIVE, sizeof(OverDriveTable_t),
474 		       PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
475 	SMU_TABLE_INIT(tables, SMU_TABLE_PMSTATUSLOG, SMU11_TOOL_SIZE,
476 		       PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
477 	SMU_TABLE_INIT(tables, SMU_TABLE_ACTIVITY_MONITOR_COEFF,
478 		       sizeof(DpmActivityMonitorCoeffInt_t), PAGE_SIZE,
479 		       AMDGPU_GEM_DOMAIN_VRAM);
480 
481 	smu_table->metrics_table = kzalloc(adev->asic_type == CHIP_NAVI12 ?
482 					   sizeof(SmuMetrics_NV12_t) :
483 					   sizeof(SmuMetrics_t), GFP_KERNEL);
484 	if (!smu_table->metrics_table)
485 		goto err0_out;
486 	smu_table->metrics_time = 0;
487 
488 	smu_table->gpu_metrics_table_size = sizeof(struct gpu_metrics_v1_0);
489 	smu_table->gpu_metrics_table = kzalloc(smu_table->gpu_metrics_table_size, GFP_KERNEL);
490 	if (!smu_table->gpu_metrics_table)
491 		goto err1_out;
492 
493 	smu_table->watermarks_table = kzalloc(sizeof(Watermarks_t), GFP_KERNEL);
494 	if (!smu_table->watermarks_table)
495 		goto err2_out;
496 
497 	return 0;
498 
499 err2_out:
500 	kfree(smu_table->gpu_metrics_table);
501 err1_out:
502 	kfree(smu_table->metrics_table);
503 err0_out:
504 	return -ENOMEM;
505 }
506 
507 static int navi10_get_smu_metrics_data(struct smu_context *smu,
508 				       MetricsMember_t member,
509 				       uint32_t *value)
510 {
511 	struct smu_table_context *smu_table= &smu->smu_table;
512 	/*
513 	 * This works for NV12 also. As although NV12 uses a different
514 	 * SmuMetrics structure from other NV1X ASICs, they share the
515 	 * same offsets for the heading parts(those members used here).
516 	 */
517 	SmuMetrics_t *metrics = (SmuMetrics_t *)smu_table->metrics_table;
518 	int ret = 0;
519 
520 	mutex_lock(&smu->metrics_lock);
521 
522 	ret = smu_cmn_get_metrics_table_locked(smu,
523 					       NULL,
524 					       false);
525 	if (ret) {
526 		mutex_unlock(&smu->metrics_lock);
527 		return ret;
528 	}
529 
530 	switch (member) {
531 	case METRICS_CURR_GFXCLK:
532 		*value = metrics->CurrClock[PPCLK_GFXCLK];
533 		break;
534 	case METRICS_CURR_SOCCLK:
535 		*value = metrics->CurrClock[PPCLK_SOCCLK];
536 		break;
537 	case METRICS_CURR_UCLK:
538 		*value = metrics->CurrClock[PPCLK_UCLK];
539 		break;
540 	case METRICS_CURR_VCLK:
541 		*value = metrics->CurrClock[PPCLK_VCLK];
542 		break;
543 	case METRICS_CURR_DCLK:
544 		*value = metrics->CurrClock[PPCLK_DCLK];
545 		break;
546 	case METRICS_CURR_DCEFCLK:
547 		*value = metrics->CurrClock[PPCLK_DCEFCLK];
548 		break;
549 	case METRICS_AVERAGE_GFXCLK:
550 		*value = metrics->AverageGfxclkFrequency;
551 		break;
552 	case METRICS_AVERAGE_SOCCLK:
553 		*value = metrics->AverageSocclkFrequency;
554 		break;
555 	case METRICS_AVERAGE_UCLK:
556 		*value = metrics->AverageUclkFrequency;
557 		break;
558 	case METRICS_AVERAGE_GFXACTIVITY:
559 		*value = metrics->AverageGfxActivity;
560 		break;
561 	case METRICS_AVERAGE_MEMACTIVITY:
562 		*value = metrics->AverageUclkActivity;
563 		break;
564 	case METRICS_AVERAGE_SOCKETPOWER:
565 		*value = metrics->AverageSocketPower << 8;
566 		break;
567 	case METRICS_TEMPERATURE_EDGE:
568 		*value = metrics->TemperatureEdge *
569 			SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
570 		break;
571 	case METRICS_TEMPERATURE_HOTSPOT:
572 		*value = metrics->TemperatureHotspot *
573 			SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
574 		break;
575 	case METRICS_TEMPERATURE_MEM:
576 		*value = metrics->TemperatureMem *
577 			SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
578 		break;
579 	case METRICS_TEMPERATURE_VRGFX:
580 		*value = metrics->TemperatureVrGfx *
581 			SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
582 		break;
583 	case METRICS_TEMPERATURE_VRSOC:
584 		*value = metrics->TemperatureVrSoc *
585 			SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
586 		break;
587 	case METRICS_THROTTLER_STATUS:
588 		*value = metrics->ThrottlerStatus;
589 		break;
590 	case METRICS_CURR_FANSPEED:
591 		*value = metrics->CurrFanSpeed;
592 		break;
593 	default:
594 		*value = UINT_MAX;
595 		break;
596 	}
597 
598 	mutex_unlock(&smu->metrics_lock);
599 
600 	return ret;
601 }
602 
603 static int navi10_allocate_dpm_context(struct smu_context *smu)
604 {
605 	struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
606 
607 	smu_dpm->dpm_context = kzalloc(sizeof(struct smu_11_0_dpm_context),
608 				       GFP_KERNEL);
609 	if (!smu_dpm->dpm_context)
610 		return -ENOMEM;
611 
612 	smu_dpm->dpm_context_size = sizeof(struct smu_11_0_dpm_context);
613 
614 	return 0;
615 }
616 
617 static int navi10_init_smc_tables(struct smu_context *smu)
618 {
619 	int ret = 0;
620 
621 	ret = navi10_tables_init(smu);
622 	if (ret)
623 		return ret;
624 
625 	ret = navi10_allocate_dpm_context(smu);
626 	if (ret)
627 		return ret;
628 
629 	return smu_v11_0_init_smc_tables(smu);
630 }
631 
632 static int navi10_set_default_dpm_table(struct smu_context *smu)
633 {
634 	struct smu_11_0_dpm_context *dpm_context = smu->smu_dpm.dpm_context;
635 	PPTable_t *driver_ppt = smu->smu_table.driver_pptable;
636 	struct smu_11_0_dpm_table *dpm_table;
637 	int ret = 0;
638 
639 	/* socclk dpm table setup */
640 	dpm_table = &dpm_context->dpm_tables.soc_table;
641 	if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_DPM_SOCCLK_BIT)) {
642 		ret = smu_v11_0_set_single_dpm_table(smu,
643 						     SMU_SOCCLK,
644 						     dpm_table);
645 		if (ret)
646 			return ret;
647 		dpm_table->is_fine_grained =
648 			!driver_ppt->DpmDescriptor[PPCLK_SOCCLK].SnapToDiscrete;
649 	} else {
650 		dpm_table->count = 1;
651 		dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.socclk / 100;
652 		dpm_table->dpm_levels[0].enabled = true;
653 		dpm_table->min = dpm_table->dpm_levels[0].value;
654 		dpm_table->max = dpm_table->dpm_levels[0].value;
655 	}
656 
657 	/* gfxclk dpm table setup */
658 	dpm_table = &dpm_context->dpm_tables.gfx_table;
659 	if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_DPM_GFXCLK_BIT)) {
660 		ret = smu_v11_0_set_single_dpm_table(smu,
661 						     SMU_GFXCLK,
662 						     dpm_table);
663 		if (ret)
664 			return ret;
665 		dpm_table->is_fine_grained =
666 			!driver_ppt->DpmDescriptor[PPCLK_GFXCLK].SnapToDiscrete;
667 	} else {
668 		dpm_table->count = 1;
669 		dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.gfxclk / 100;
670 		dpm_table->dpm_levels[0].enabled = true;
671 		dpm_table->min = dpm_table->dpm_levels[0].value;
672 		dpm_table->max = dpm_table->dpm_levels[0].value;
673 	}
674 
675 	/* uclk dpm table setup */
676 	dpm_table = &dpm_context->dpm_tables.uclk_table;
677 	if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT)) {
678 		ret = smu_v11_0_set_single_dpm_table(smu,
679 						     SMU_UCLK,
680 						     dpm_table);
681 		if (ret)
682 			return ret;
683 		dpm_table->is_fine_grained =
684 			!driver_ppt->DpmDescriptor[PPCLK_UCLK].SnapToDiscrete;
685 	} else {
686 		dpm_table->count = 1;
687 		dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.uclk / 100;
688 		dpm_table->dpm_levels[0].enabled = true;
689 		dpm_table->min = dpm_table->dpm_levels[0].value;
690 		dpm_table->max = dpm_table->dpm_levels[0].value;
691 	}
692 
693 	/* vclk dpm table setup */
694 	dpm_table = &dpm_context->dpm_tables.vclk_table;
695 	if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_VCN_PG_BIT)) {
696 		ret = smu_v11_0_set_single_dpm_table(smu,
697 						     SMU_VCLK,
698 						     dpm_table);
699 		if (ret)
700 			return ret;
701 		dpm_table->is_fine_grained =
702 			!driver_ppt->DpmDescriptor[PPCLK_VCLK].SnapToDiscrete;
703 	} else {
704 		dpm_table->count = 1;
705 		dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.vclk / 100;
706 		dpm_table->dpm_levels[0].enabled = true;
707 		dpm_table->min = dpm_table->dpm_levels[0].value;
708 		dpm_table->max = dpm_table->dpm_levels[0].value;
709 	}
710 
711 	/* dclk dpm table setup */
712 	dpm_table = &dpm_context->dpm_tables.dclk_table;
713 	if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_VCN_PG_BIT)) {
714 		ret = smu_v11_0_set_single_dpm_table(smu,
715 						     SMU_DCLK,
716 						     dpm_table);
717 		if (ret)
718 			return ret;
719 		dpm_table->is_fine_grained =
720 			!driver_ppt->DpmDescriptor[PPCLK_DCLK].SnapToDiscrete;
721 	} else {
722 		dpm_table->count = 1;
723 		dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.dclk / 100;
724 		dpm_table->dpm_levels[0].enabled = true;
725 		dpm_table->min = dpm_table->dpm_levels[0].value;
726 		dpm_table->max = dpm_table->dpm_levels[0].value;
727 	}
728 
729 	/* dcefclk dpm table setup */
730 	dpm_table = &dpm_context->dpm_tables.dcef_table;
731 	if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_DPM_DCEFCLK_BIT)) {
732 		ret = smu_v11_0_set_single_dpm_table(smu,
733 						     SMU_DCEFCLK,
734 						     dpm_table);
735 		if (ret)
736 			return ret;
737 		dpm_table->is_fine_grained =
738 			!driver_ppt->DpmDescriptor[PPCLK_DCEFCLK].SnapToDiscrete;
739 	} else {
740 		dpm_table->count = 1;
741 		dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.dcefclk / 100;
742 		dpm_table->dpm_levels[0].enabled = true;
743 		dpm_table->min = dpm_table->dpm_levels[0].value;
744 		dpm_table->max = dpm_table->dpm_levels[0].value;
745 	}
746 
747 	/* pixelclk dpm table setup */
748 	dpm_table = &dpm_context->dpm_tables.pixel_table;
749 	if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_DPM_DCEFCLK_BIT)) {
750 		ret = smu_v11_0_set_single_dpm_table(smu,
751 						     SMU_PIXCLK,
752 						     dpm_table);
753 		if (ret)
754 			return ret;
755 		dpm_table->is_fine_grained =
756 			!driver_ppt->DpmDescriptor[PPCLK_PIXCLK].SnapToDiscrete;
757 	} else {
758 		dpm_table->count = 1;
759 		dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.dcefclk / 100;
760 		dpm_table->dpm_levels[0].enabled = true;
761 		dpm_table->min = dpm_table->dpm_levels[0].value;
762 		dpm_table->max = dpm_table->dpm_levels[0].value;
763 	}
764 
765 	/* displayclk dpm table setup */
766 	dpm_table = &dpm_context->dpm_tables.display_table;
767 	if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_DPM_DCEFCLK_BIT)) {
768 		ret = smu_v11_0_set_single_dpm_table(smu,
769 						     SMU_DISPCLK,
770 						     dpm_table);
771 		if (ret)
772 			return ret;
773 		dpm_table->is_fine_grained =
774 			!driver_ppt->DpmDescriptor[PPCLK_DISPCLK].SnapToDiscrete;
775 	} else {
776 		dpm_table->count = 1;
777 		dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.dcefclk / 100;
778 		dpm_table->dpm_levels[0].enabled = true;
779 		dpm_table->min = dpm_table->dpm_levels[0].value;
780 		dpm_table->max = dpm_table->dpm_levels[0].value;
781 	}
782 
783 	/* phyclk dpm table setup */
784 	dpm_table = &dpm_context->dpm_tables.phy_table;
785 	if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_DPM_DCEFCLK_BIT)) {
786 		ret = smu_v11_0_set_single_dpm_table(smu,
787 						     SMU_PHYCLK,
788 						     dpm_table);
789 		if (ret)
790 			return ret;
791 		dpm_table->is_fine_grained =
792 			!driver_ppt->DpmDescriptor[PPCLK_PHYCLK].SnapToDiscrete;
793 	} else {
794 		dpm_table->count = 1;
795 		dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.dcefclk / 100;
796 		dpm_table->dpm_levels[0].enabled = true;
797 		dpm_table->min = dpm_table->dpm_levels[0].value;
798 		dpm_table->max = dpm_table->dpm_levels[0].value;
799 	}
800 
801 	return 0;
802 }
803 
804 static int navi10_dpm_set_vcn_enable(struct smu_context *smu, bool enable)
805 {
806 	int ret = 0;
807 
808 	if (enable) {
809 		/* vcn dpm on is a prerequisite for vcn power gate messages */
810 		if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_VCN_PG_BIT)) {
811 			ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_PowerUpVcn, 1, NULL);
812 			if (ret)
813 				return ret;
814 		}
815 	} else {
816 		if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_VCN_PG_BIT)) {
817 			ret = smu_cmn_send_smc_msg(smu, SMU_MSG_PowerDownVcn, NULL);
818 			if (ret)
819 				return ret;
820 		}
821 	}
822 
823 	return ret;
824 }
825 
826 static int navi10_dpm_set_jpeg_enable(struct smu_context *smu, bool enable)
827 {
828 	int ret = 0;
829 
830 	if (enable) {
831 		if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_JPEG_PG_BIT)) {
832 			ret = smu_cmn_send_smc_msg(smu, SMU_MSG_PowerUpJpeg, NULL);
833 			if (ret)
834 				return ret;
835 		}
836 	} else {
837 		if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_JPEG_PG_BIT)) {
838 			ret = smu_cmn_send_smc_msg(smu, SMU_MSG_PowerDownJpeg, NULL);
839 			if (ret)
840 				return ret;
841 		}
842 	}
843 
844 	return ret;
845 }
846 
847 static int navi10_get_current_clk_freq_by_table(struct smu_context *smu,
848 				       enum smu_clk_type clk_type,
849 				       uint32_t *value)
850 {
851 	MetricsMember_t member_type;
852 	int clk_id = 0;
853 
854 	clk_id = smu_cmn_to_asic_specific_index(smu,
855 						CMN2ASIC_MAPPING_CLK,
856 						clk_type);
857 	if (clk_id < 0)
858 		return clk_id;
859 
860 	switch (clk_id) {
861 	case PPCLK_GFXCLK:
862 		member_type = METRICS_CURR_GFXCLK;
863 		break;
864 	case PPCLK_UCLK:
865 		member_type = METRICS_CURR_UCLK;
866 		break;
867 	case PPCLK_SOCCLK:
868 		member_type = METRICS_CURR_SOCCLK;
869 		break;
870 	case PPCLK_VCLK:
871 		member_type = METRICS_CURR_VCLK;
872 		break;
873 	case PPCLK_DCLK:
874 		member_type = METRICS_CURR_DCLK;
875 		break;
876 	case PPCLK_DCEFCLK:
877 		member_type = METRICS_CURR_DCEFCLK;
878 		break;
879 	default:
880 		return -EINVAL;
881 	}
882 
883 	return navi10_get_smu_metrics_data(smu,
884 					   member_type,
885 					   value);
886 }
887 
888 static bool navi10_is_support_fine_grained_dpm(struct smu_context *smu, enum smu_clk_type clk_type)
889 {
890 	PPTable_t *pptable = smu->smu_table.driver_pptable;
891 	DpmDescriptor_t *dpm_desc = NULL;
892 	uint32_t clk_index = 0;
893 
894 	clk_index = smu_cmn_to_asic_specific_index(smu,
895 						   CMN2ASIC_MAPPING_CLK,
896 						   clk_type);
897 	dpm_desc = &pptable->DpmDescriptor[clk_index];
898 
899 	/* 0 - Fine grained DPM, 1 - Discrete DPM */
900 	return dpm_desc->SnapToDiscrete == 0 ? true : false;
901 }
902 
903 static inline bool navi10_od_feature_is_supported(struct smu_11_0_overdrive_table *od_table, enum SMU_11_0_ODFEATURE_CAP cap)
904 {
905 	return od_table->cap[cap];
906 }
907 
908 static void navi10_od_setting_get_range(struct smu_11_0_overdrive_table *od_table,
909 					enum SMU_11_0_ODSETTING_ID setting,
910 					uint32_t *min, uint32_t *max)
911 {
912 	if (min)
913 		*min = od_table->min[setting];
914 	if (max)
915 		*max = od_table->max[setting];
916 }
917 
918 static int navi10_print_clk_levels(struct smu_context *smu,
919 			enum smu_clk_type clk_type, char *buf)
920 {
921 	uint16_t *curve_settings;
922 	int i, size = 0, ret = 0;
923 	uint32_t cur_value = 0, value = 0, count = 0;
924 	uint32_t freq_values[3] = {0};
925 	uint32_t mark_index = 0;
926 	struct smu_table_context *table_context = &smu->smu_table;
927 	uint32_t gen_speed, lane_width;
928 	struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
929 	struct smu_11_0_dpm_context *dpm_context = smu_dpm->dpm_context;
930 	PPTable_t *pptable = (PPTable_t *)table_context->driver_pptable;
931 	OverDriveTable_t *od_table =
932 		(OverDriveTable_t *)table_context->overdrive_table;
933 	struct smu_11_0_overdrive_table *od_settings = smu->od_settings;
934 	uint32_t min_value, max_value;
935 
936 	switch (clk_type) {
937 	case SMU_GFXCLK:
938 	case SMU_SCLK:
939 	case SMU_SOCCLK:
940 	case SMU_MCLK:
941 	case SMU_UCLK:
942 	case SMU_FCLK:
943 	case SMU_DCEFCLK:
944 		ret = navi10_get_current_clk_freq_by_table(smu, clk_type, &cur_value);
945 		if (ret)
946 			return size;
947 
948 		ret = smu_v11_0_get_dpm_level_count(smu, clk_type, &count);
949 		if (ret)
950 			return size;
951 
952 		if (!navi10_is_support_fine_grained_dpm(smu, clk_type)) {
953 			for (i = 0; i < count; i++) {
954 				ret = smu_v11_0_get_dpm_freq_by_index(smu, clk_type, i, &value);
955 				if (ret)
956 					return size;
957 
958 				size += sprintf(buf + size, "%d: %uMhz %s\n", i, value,
959 						cur_value == value ? "*" : "");
960 			}
961 		} else {
962 			ret = smu_v11_0_get_dpm_freq_by_index(smu, clk_type, 0, &freq_values[0]);
963 			if (ret)
964 				return size;
965 			ret = smu_v11_0_get_dpm_freq_by_index(smu, clk_type, count - 1, &freq_values[2]);
966 			if (ret)
967 				return size;
968 
969 			freq_values[1] = cur_value;
970 			mark_index = cur_value == freq_values[0] ? 0 :
971 				     cur_value == freq_values[2] ? 2 : 1;
972 			if (mark_index != 1)
973 				freq_values[1] = (freq_values[0] + freq_values[2]) / 2;
974 
975 			for (i = 0; i < 3; i++) {
976 				size += sprintf(buf + size, "%d: %uMhz %s\n", i, freq_values[i],
977 						i == mark_index ? "*" : "");
978 			}
979 
980 		}
981 		break;
982 	case SMU_PCIE:
983 		gen_speed = smu_v11_0_get_current_pcie_link_speed_level(smu);
984 		lane_width = smu_v11_0_get_current_pcie_link_width_level(smu);
985 		for (i = 0; i < NUM_LINK_LEVELS; i++)
986 			size += sprintf(buf + size, "%d: %s %s %dMhz %s\n", i,
987 					(dpm_context->dpm_tables.pcie_table.pcie_gen[i] == 0) ? "2.5GT/s," :
988 					(dpm_context->dpm_tables.pcie_table.pcie_gen[i] == 1) ? "5.0GT/s," :
989 					(dpm_context->dpm_tables.pcie_table.pcie_gen[i] == 2) ? "8.0GT/s," :
990 					(dpm_context->dpm_tables.pcie_table.pcie_gen[i] == 3) ? "16.0GT/s," : "",
991 					(dpm_context->dpm_tables.pcie_table.pcie_lane[i] == 1) ? "x1" :
992 					(dpm_context->dpm_tables.pcie_table.pcie_lane[i] == 2) ? "x2" :
993 					(dpm_context->dpm_tables.pcie_table.pcie_lane[i] == 3) ? "x4" :
994 					(dpm_context->dpm_tables.pcie_table.pcie_lane[i] == 4) ? "x8" :
995 					(dpm_context->dpm_tables.pcie_table.pcie_lane[i] == 5) ? "x12" :
996 					(dpm_context->dpm_tables.pcie_table.pcie_lane[i] == 6) ? "x16" : "",
997 					pptable->LclkFreq[i],
998 					(gen_speed == dpm_context->dpm_tables.pcie_table.pcie_gen[i]) &&
999 					(lane_width == dpm_context->dpm_tables.pcie_table.pcie_lane[i]) ?
1000 					"*" : "");
1001 		break;
1002 	case SMU_OD_SCLK:
1003 		if (!smu->od_enabled || !od_table || !od_settings)
1004 			break;
1005 		if (!navi10_od_feature_is_supported(od_settings, SMU_11_0_ODCAP_GFXCLK_LIMITS))
1006 			break;
1007 		size += sprintf(buf + size, "OD_SCLK:\n");
1008 		size += sprintf(buf + size, "0: %uMhz\n1: %uMhz\n", od_table->GfxclkFmin, od_table->GfxclkFmax);
1009 		break;
1010 	case SMU_OD_MCLK:
1011 		if (!smu->od_enabled || !od_table || !od_settings)
1012 			break;
1013 		if (!navi10_od_feature_is_supported(od_settings, SMU_11_0_ODCAP_UCLK_MAX))
1014 			break;
1015 		size += sprintf(buf + size, "OD_MCLK:\n");
1016 		size += sprintf(buf + size, "1: %uMHz\n", od_table->UclkFmax);
1017 		break;
1018 	case SMU_OD_VDDC_CURVE:
1019 		if (!smu->od_enabled || !od_table || !od_settings)
1020 			break;
1021 		if (!navi10_od_feature_is_supported(od_settings, SMU_11_0_ODCAP_GFXCLK_CURVE))
1022 			break;
1023 		size += sprintf(buf + size, "OD_VDDC_CURVE:\n");
1024 		for (i = 0; i < 3; i++) {
1025 			switch (i) {
1026 			case 0:
1027 				curve_settings = &od_table->GfxclkFreq1;
1028 				break;
1029 			case 1:
1030 				curve_settings = &od_table->GfxclkFreq2;
1031 				break;
1032 			case 2:
1033 				curve_settings = &od_table->GfxclkFreq3;
1034 				break;
1035 			default:
1036 				break;
1037 			}
1038 			size += sprintf(buf + size, "%d: %uMHz %umV\n", i, curve_settings[0], curve_settings[1] / NAVI10_VOLTAGE_SCALE);
1039 		}
1040 		break;
1041 	case SMU_OD_RANGE:
1042 		if (!smu->od_enabled || !od_table || !od_settings)
1043 			break;
1044 		size = sprintf(buf, "%s:\n", "OD_RANGE");
1045 
1046 		if (navi10_od_feature_is_supported(od_settings, SMU_11_0_ODCAP_GFXCLK_LIMITS)) {
1047 			navi10_od_setting_get_range(od_settings, SMU_11_0_ODSETTING_GFXCLKFMIN,
1048 						    &min_value, NULL);
1049 			navi10_od_setting_get_range(od_settings, SMU_11_0_ODSETTING_GFXCLKFMAX,
1050 						    NULL, &max_value);
1051 			size += sprintf(buf + size, "SCLK: %7uMhz %10uMhz\n",
1052 					min_value, max_value);
1053 		}
1054 
1055 		if (navi10_od_feature_is_supported(od_settings, SMU_11_0_ODCAP_UCLK_MAX)) {
1056 			navi10_od_setting_get_range(od_settings, SMU_11_0_ODSETTING_UCLKFMAX,
1057 						    &min_value, &max_value);
1058 			size += sprintf(buf + size, "MCLK: %7uMhz %10uMhz\n",
1059 					min_value, max_value);
1060 		}
1061 
1062 		if (navi10_od_feature_is_supported(od_settings, SMU_11_0_ODCAP_GFXCLK_CURVE)) {
1063 			navi10_od_setting_get_range(od_settings, SMU_11_0_ODSETTING_VDDGFXCURVEFREQ_P1,
1064 						    &min_value, &max_value);
1065 			size += sprintf(buf + size, "VDDC_CURVE_SCLK[0]: %7uMhz %10uMhz\n",
1066 					min_value, max_value);
1067 			navi10_od_setting_get_range(od_settings, SMU_11_0_ODSETTING_VDDGFXCURVEVOLTAGE_P1,
1068 						    &min_value, &max_value);
1069 			size += sprintf(buf + size, "VDDC_CURVE_VOLT[0]: %7dmV %11dmV\n",
1070 					min_value, max_value);
1071 			navi10_od_setting_get_range(od_settings, SMU_11_0_ODSETTING_VDDGFXCURVEFREQ_P2,
1072 						    &min_value, &max_value);
1073 			size += sprintf(buf + size, "VDDC_CURVE_SCLK[1]: %7uMhz %10uMhz\n",
1074 					min_value, max_value);
1075 			navi10_od_setting_get_range(od_settings, SMU_11_0_ODSETTING_VDDGFXCURVEVOLTAGE_P2,
1076 						    &min_value, &max_value);
1077 			size += sprintf(buf + size, "VDDC_CURVE_VOLT[1]: %7dmV %11dmV\n",
1078 					min_value, max_value);
1079 			navi10_od_setting_get_range(od_settings, SMU_11_0_ODSETTING_VDDGFXCURVEFREQ_P3,
1080 						    &min_value, &max_value);
1081 			size += sprintf(buf + size, "VDDC_CURVE_SCLK[2]: %7uMhz %10uMhz\n",
1082 					min_value, max_value);
1083 			navi10_od_setting_get_range(od_settings, SMU_11_0_ODSETTING_VDDGFXCURVEVOLTAGE_P3,
1084 						    &min_value, &max_value);
1085 			size += sprintf(buf + size, "VDDC_CURVE_VOLT[2]: %7dmV %11dmV\n",
1086 					min_value, max_value);
1087 		}
1088 
1089 		break;
1090 	default:
1091 		break;
1092 	}
1093 
1094 	return size;
1095 }
1096 
1097 static int navi10_force_clk_levels(struct smu_context *smu,
1098 				   enum smu_clk_type clk_type, uint32_t mask)
1099 {
1100 
1101 	int ret = 0, size = 0;
1102 	uint32_t soft_min_level = 0, soft_max_level = 0, min_freq = 0, max_freq = 0;
1103 
1104 	soft_min_level = mask ? (ffs(mask) - 1) : 0;
1105 	soft_max_level = mask ? (fls(mask) - 1) : 0;
1106 
1107 	switch (clk_type) {
1108 	case SMU_GFXCLK:
1109 	case SMU_SCLK:
1110 	case SMU_SOCCLK:
1111 	case SMU_MCLK:
1112 	case SMU_UCLK:
1113 	case SMU_DCEFCLK:
1114 	case SMU_FCLK:
1115 		/* There is only 2 levels for fine grained DPM */
1116 		if (navi10_is_support_fine_grained_dpm(smu, clk_type)) {
1117 			soft_max_level = (soft_max_level >= 1 ? 1 : 0);
1118 			soft_min_level = (soft_min_level >= 1 ? 1 : 0);
1119 		}
1120 
1121 		ret = smu_v11_0_get_dpm_freq_by_index(smu, clk_type, soft_min_level, &min_freq);
1122 		if (ret)
1123 			return size;
1124 
1125 		ret = smu_v11_0_get_dpm_freq_by_index(smu, clk_type, soft_max_level, &max_freq);
1126 		if (ret)
1127 			return size;
1128 
1129 		ret = smu_v11_0_set_soft_freq_limited_range(smu, clk_type, min_freq, max_freq);
1130 		if (ret)
1131 			return size;
1132 		break;
1133 	default:
1134 		break;
1135 	}
1136 
1137 	return size;
1138 }
1139 
1140 static int navi10_populate_umd_state_clk(struct smu_context *smu)
1141 {
1142 	struct smu_11_0_dpm_context *dpm_context =
1143 				smu->smu_dpm.dpm_context;
1144 	struct smu_11_0_dpm_table *gfx_table =
1145 				&dpm_context->dpm_tables.gfx_table;
1146 	struct smu_11_0_dpm_table *mem_table =
1147 				&dpm_context->dpm_tables.uclk_table;
1148 	struct smu_11_0_dpm_table *soc_table =
1149 				&dpm_context->dpm_tables.soc_table;
1150 	struct smu_umd_pstate_table *pstate_table =
1151 				&smu->pstate_table;
1152 	struct amdgpu_device *adev = smu->adev;
1153 	uint32_t sclk_freq;
1154 
1155 	pstate_table->gfxclk_pstate.min = gfx_table->min;
1156 	switch (adev->asic_type) {
1157 	case CHIP_NAVI10:
1158 		switch (adev->pdev->revision) {
1159 		case 0xf0: /* XTX */
1160 		case 0xc0:
1161 			sclk_freq = NAVI10_PEAK_SCLK_XTX;
1162 			break;
1163 		case 0xf1: /* XT */
1164 		case 0xc1:
1165 			sclk_freq = NAVI10_PEAK_SCLK_XT;
1166 			break;
1167 		default: /* XL */
1168 			sclk_freq = NAVI10_PEAK_SCLK_XL;
1169 			break;
1170 		}
1171 		break;
1172 	case CHIP_NAVI14:
1173 		switch (adev->pdev->revision) {
1174 		case 0xc7: /* XT */
1175 		case 0xf4:
1176 			sclk_freq = NAVI14_UMD_PSTATE_PEAK_XT_GFXCLK;
1177 			break;
1178 		case 0xc1: /* XTM */
1179 		case 0xf2:
1180 			sclk_freq = NAVI14_UMD_PSTATE_PEAK_XTM_GFXCLK;
1181 			break;
1182 		case 0xc3: /* XLM */
1183 		case 0xf3:
1184 			sclk_freq = NAVI14_UMD_PSTATE_PEAK_XLM_GFXCLK;
1185 			break;
1186 		case 0xc5: /* XTX */
1187 		case 0xf6:
1188 			sclk_freq = NAVI14_UMD_PSTATE_PEAK_XLM_GFXCLK;
1189 			break;
1190 		default: /* XL */
1191 			sclk_freq = NAVI14_UMD_PSTATE_PEAK_XL_GFXCLK;
1192 			break;
1193 		}
1194 		break;
1195 	case CHIP_NAVI12:
1196 		sclk_freq = NAVI12_UMD_PSTATE_PEAK_GFXCLK;
1197 		break;
1198 	default:
1199 		sclk_freq = gfx_table->dpm_levels[gfx_table->count - 1].value;
1200 		break;
1201 	}
1202 	pstate_table->gfxclk_pstate.peak = sclk_freq;
1203 
1204 	pstate_table->uclk_pstate.min = mem_table->min;
1205 	pstate_table->uclk_pstate.peak = mem_table->max;
1206 
1207 	pstate_table->socclk_pstate.min = soc_table->min;
1208 	pstate_table->socclk_pstate.peak = soc_table->max;
1209 
1210 	if (gfx_table->max > NAVI10_UMD_PSTATE_PROFILING_GFXCLK &&
1211 	    mem_table->max > NAVI10_UMD_PSTATE_PROFILING_MEMCLK &&
1212 	    soc_table->max > NAVI10_UMD_PSTATE_PROFILING_SOCCLK) {
1213 		pstate_table->gfxclk_pstate.standard =
1214 			NAVI10_UMD_PSTATE_PROFILING_GFXCLK;
1215 		pstate_table->uclk_pstate.standard =
1216 			NAVI10_UMD_PSTATE_PROFILING_MEMCLK;
1217 		pstate_table->socclk_pstate.standard =
1218 			NAVI10_UMD_PSTATE_PROFILING_SOCCLK;
1219 	} else {
1220 		pstate_table->gfxclk_pstate.standard =
1221 			pstate_table->gfxclk_pstate.min;
1222 		pstate_table->uclk_pstate.standard =
1223 			pstate_table->uclk_pstate.min;
1224 		pstate_table->socclk_pstate.standard =
1225 			pstate_table->socclk_pstate.min;
1226 	}
1227 
1228 	return 0;
1229 }
1230 
1231 static int navi10_get_clock_by_type_with_latency(struct smu_context *smu,
1232 						 enum smu_clk_type clk_type,
1233 						 struct pp_clock_levels_with_latency *clocks)
1234 {
1235 	int ret = 0, i = 0;
1236 	uint32_t level_count = 0, freq = 0;
1237 
1238 	switch (clk_type) {
1239 	case SMU_GFXCLK:
1240 	case SMU_DCEFCLK:
1241 	case SMU_SOCCLK:
1242 	case SMU_MCLK:
1243 	case SMU_UCLK:
1244 		ret = smu_v11_0_get_dpm_level_count(smu, clk_type, &level_count);
1245 		if (ret)
1246 			return ret;
1247 
1248 		level_count = min(level_count, (uint32_t)MAX_NUM_CLOCKS);
1249 		clocks->num_levels = level_count;
1250 
1251 		for (i = 0; i < level_count; i++) {
1252 			ret = smu_v11_0_get_dpm_freq_by_index(smu, clk_type, i, &freq);
1253 			if (ret)
1254 				return ret;
1255 
1256 			clocks->data[i].clocks_in_khz = freq * 1000;
1257 			clocks->data[i].latency_in_us = 0;
1258 		}
1259 		break;
1260 	default:
1261 		break;
1262 	}
1263 
1264 	return ret;
1265 }
1266 
1267 static int navi10_pre_display_config_changed(struct smu_context *smu)
1268 {
1269 	int ret = 0;
1270 	uint32_t max_freq = 0;
1271 
1272 	ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_NumOfDisplays, 0, NULL);
1273 	if (ret)
1274 		return ret;
1275 
1276 	if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT)) {
1277 		ret = smu_v11_0_get_dpm_ultimate_freq(smu, SMU_UCLK, NULL, &max_freq);
1278 		if (ret)
1279 			return ret;
1280 		ret = smu_v11_0_set_hard_freq_limited_range(smu, SMU_UCLK, 0, max_freq);
1281 		if (ret)
1282 			return ret;
1283 	}
1284 
1285 	return ret;
1286 }
1287 
1288 static int navi10_display_config_changed(struct smu_context *smu)
1289 {
1290 	int ret = 0;
1291 
1292 	if ((smu->watermarks_bitmap & WATERMARKS_EXIST) &&
1293 	    smu_cmn_feature_is_supported(smu, SMU_FEATURE_DPM_DCEFCLK_BIT) &&
1294 	    smu_cmn_feature_is_supported(smu, SMU_FEATURE_DPM_SOCCLK_BIT)) {
1295 		ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_NumOfDisplays,
1296 						  smu->display_config->num_display,
1297 						  NULL);
1298 		if (ret)
1299 			return ret;
1300 	}
1301 
1302 	return ret;
1303 }
1304 
1305 static bool navi10_is_dpm_running(struct smu_context *smu)
1306 {
1307 	int ret = 0;
1308 	uint32_t feature_mask[2];
1309 	uint64_t feature_enabled;
1310 
1311 	ret = smu_cmn_get_enabled_mask(smu, feature_mask, 2);
1312 	if (ret)
1313 		return false;
1314 
1315 	feature_enabled = (uint64_t)feature_mask[1] << 32 | feature_mask[0];
1316 
1317 	return !!(feature_enabled & SMC_DPM_FEATURE);
1318 }
1319 
1320 static int navi10_get_fan_speed_rpm(struct smu_context *smu,
1321 				    uint32_t *speed)
1322 {
1323 	if (!speed)
1324 		return -EINVAL;
1325 
1326 	return navi10_get_smu_metrics_data(smu,
1327 					   METRICS_CURR_FANSPEED,
1328 					   speed);
1329 }
1330 
1331 static int navi10_get_fan_parameters(struct smu_context *smu)
1332 {
1333 	PPTable_t *pptable = smu->smu_table.driver_pptable;
1334 
1335 	smu->fan_max_rpm = pptable->FanMaximumRpm;
1336 
1337 	return 0;
1338 }
1339 
1340 static int navi10_get_power_profile_mode(struct smu_context *smu, char *buf)
1341 {
1342 	DpmActivityMonitorCoeffInt_t activity_monitor;
1343 	uint32_t i, size = 0;
1344 	int16_t workload_type = 0;
1345 	static const char *profile_name[] = {
1346 					"BOOTUP_DEFAULT",
1347 					"3D_FULL_SCREEN",
1348 					"POWER_SAVING",
1349 					"VIDEO",
1350 					"VR",
1351 					"COMPUTE",
1352 					"CUSTOM"};
1353 	static const char *title[] = {
1354 			"PROFILE_INDEX(NAME)",
1355 			"CLOCK_TYPE(NAME)",
1356 			"FPS",
1357 			"MinFreqType",
1358 			"MinActiveFreqType",
1359 			"MinActiveFreq",
1360 			"BoosterFreqType",
1361 			"BoosterFreq",
1362 			"PD_Data_limit_c",
1363 			"PD_Data_error_coeff",
1364 			"PD_Data_error_rate_coeff"};
1365 	int result = 0;
1366 
1367 	if (!buf)
1368 		return -EINVAL;
1369 
1370 	size += sprintf(buf + size, "%16s %s %s %s %s %s %s %s %s %s %s\n",
1371 			title[0], title[1], title[2], title[3], title[4], title[5],
1372 			title[6], title[7], title[8], title[9], title[10]);
1373 
1374 	for (i = 0; i <= PP_SMC_POWER_PROFILE_CUSTOM; i++) {
1375 		/* conv PP_SMC_POWER_PROFILE* to WORKLOAD_PPLIB_*_BIT */
1376 		workload_type = smu_cmn_to_asic_specific_index(smu,
1377 							       CMN2ASIC_MAPPING_WORKLOAD,
1378 							       i);
1379 		if (workload_type < 0)
1380 			return -EINVAL;
1381 
1382 		result = smu_cmn_update_table(smu,
1383 					  SMU_TABLE_ACTIVITY_MONITOR_COEFF, workload_type,
1384 					  (void *)(&activity_monitor), false);
1385 		if (result) {
1386 			dev_err(smu->adev->dev, "[%s] Failed to get activity monitor!", __func__);
1387 			return result;
1388 		}
1389 
1390 		size += sprintf(buf + size, "%2d %14s%s:\n",
1391 			i, profile_name[i], (i == smu->power_profile_mode) ? "*" : " ");
1392 
1393 		size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n",
1394 			" ",
1395 			0,
1396 			"GFXCLK",
1397 			activity_monitor.Gfx_FPS,
1398 			activity_monitor.Gfx_MinFreqStep,
1399 			activity_monitor.Gfx_MinActiveFreqType,
1400 			activity_monitor.Gfx_MinActiveFreq,
1401 			activity_monitor.Gfx_BoosterFreqType,
1402 			activity_monitor.Gfx_BoosterFreq,
1403 			activity_monitor.Gfx_PD_Data_limit_c,
1404 			activity_monitor.Gfx_PD_Data_error_coeff,
1405 			activity_monitor.Gfx_PD_Data_error_rate_coeff);
1406 
1407 		size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n",
1408 			" ",
1409 			1,
1410 			"SOCCLK",
1411 			activity_monitor.Soc_FPS,
1412 			activity_monitor.Soc_MinFreqStep,
1413 			activity_monitor.Soc_MinActiveFreqType,
1414 			activity_monitor.Soc_MinActiveFreq,
1415 			activity_monitor.Soc_BoosterFreqType,
1416 			activity_monitor.Soc_BoosterFreq,
1417 			activity_monitor.Soc_PD_Data_limit_c,
1418 			activity_monitor.Soc_PD_Data_error_coeff,
1419 			activity_monitor.Soc_PD_Data_error_rate_coeff);
1420 
1421 		size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n",
1422 			" ",
1423 			2,
1424 			"MEMLK",
1425 			activity_monitor.Mem_FPS,
1426 			activity_monitor.Mem_MinFreqStep,
1427 			activity_monitor.Mem_MinActiveFreqType,
1428 			activity_monitor.Mem_MinActiveFreq,
1429 			activity_monitor.Mem_BoosterFreqType,
1430 			activity_monitor.Mem_BoosterFreq,
1431 			activity_monitor.Mem_PD_Data_limit_c,
1432 			activity_monitor.Mem_PD_Data_error_coeff,
1433 			activity_monitor.Mem_PD_Data_error_rate_coeff);
1434 	}
1435 
1436 	return size;
1437 }
1438 
1439 static int navi10_set_power_profile_mode(struct smu_context *smu, long *input, uint32_t size)
1440 {
1441 	DpmActivityMonitorCoeffInt_t activity_monitor;
1442 	int workload_type, ret = 0;
1443 
1444 	smu->power_profile_mode = input[size];
1445 
1446 	if (smu->power_profile_mode > PP_SMC_POWER_PROFILE_CUSTOM) {
1447 		dev_err(smu->adev->dev, "Invalid power profile mode %d\n", smu->power_profile_mode);
1448 		return -EINVAL;
1449 	}
1450 
1451 	if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
1452 
1453 		ret = smu_cmn_update_table(smu,
1454 				       SMU_TABLE_ACTIVITY_MONITOR_COEFF, WORKLOAD_PPLIB_CUSTOM_BIT,
1455 				       (void *)(&activity_monitor), false);
1456 		if (ret) {
1457 			dev_err(smu->adev->dev, "[%s] Failed to get activity monitor!", __func__);
1458 			return ret;
1459 		}
1460 
1461 		switch (input[0]) {
1462 		case 0: /* Gfxclk */
1463 			activity_monitor.Gfx_FPS = input[1];
1464 			activity_monitor.Gfx_MinFreqStep = input[2];
1465 			activity_monitor.Gfx_MinActiveFreqType = input[3];
1466 			activity_monitor.Gfx_MinActiveFreq = input[4];
1467 			activity_monitor.Gfx_BoosterFreqType = input[5];
1468 			activity_monitor.Gfx_BoosterFreq = input[6];
1469 			activity_monitor.Gfx_PD_Data_limit_c = input[7];
1470 			activity_monitor.Gfx_PD_Data_error_coeff = input[8];
1471 			activity_monitor.Gfx_PD_Data_error_rate_coeff = input[9];
1472 			break;
1473 		case 1: /* Socclk */
1474 			activity_monitor.Soc_FPS = input[1];
1475 			activity_monitor.Soc_MinFreqStep = input[2];
1476 			activity_monitor.Soc_MinActiveFreqType = input[3];
1477 			activity_monitor.Soc_MinActiveFreq = input[4];
1478 			activity_monitor.Soc_BoosterFreqType = input[5];
1479 			activity_monitor.Soc_BoosterFreq = input[6];
1480 			activity_monitor.Soc_PD_Data_limit_c = input[7];
1481 			activity_monitor.Soc_PD_Data_error_coeff = input[8];
1482 			activity_monitor.Soc_PD_Data_error_rate_coeff = input[9];
1483 			break;
1484 		case 2: /* Memlk */
1485 			activity_monitor.Mem_FPS = input[1];
1486 			activity_monitor.Mem_MinFreqStep = input[2];
1487 			activity_monitor.Mem_MinActiveFreqType = input[3];
1488 			activity_monitor.Mem_MinActiveFreq = input[4];
1489 			activity_monitor.Mem_BoosterFreqType = input[5];
1490 			activity_monitor.Mem_BoosterFreq = input[6];
1491 			activity_monitor.Mem_PD_Data_limit_c = input[7];
1492 			activity_monitor.Mem_PD_Data_error_coeff = input[8];
1493 			activity_monitor.Mem_PD_Data_error_rate_coeff = input[9];
1494 			break;
1495 		}
1496 
1497 		ret = smu_cmn_update_table(smu,
1498 				       SMU_TABLE_ACTIVITY_MONITOR_COEFF, WORKLOAD_PPLIB_CUSTOM_BIT,
1499 				       (void *)(&activity_monitor), true);
1500 		if (ret) {
1501 			dev_err(smu->adev->dev, "[%s] Failed to set activity monitor!", __func__);
1502 			return ret;
1503 		}
1504 	}
1505 
1506 	/* conv PP_SMC_POWER_PROFILE* to WORKLOAD_PPLIB_*_BIT */
1507 	workload_type = smu_cmn_to_asic_specific_index(smu,
1508 						       CMN2ASIC_MAPPING_WORKLOAD,
1509 						       smu->power_profile_mode);
1510 	if (workload_type < 0)
1511 		return -EINVAL;
1512 	smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetWorkloadMask,
1513 				    1 << workload_type, NULL);
1514 
1515 	return ret;
1516 }
1517 
1518 static int navi10_notify_smc_display_config(struct smu_context *smu)
1519 {
1520 	struct smu_clocks min_clocks = {0};
1521 	struct pp_display_clock_request clock_req;
1522 	int ret = 0;
1523 
1524 	min_clocks.dcef_clock = smu->display_config->min_dcef_set_clk;
1525 	min_clocks.dcef_clock_in_sr = smu->display_config->min_dcef_deep_sleep_set_clk;
1526 	min_clocks.memory_clock = smu->display_config->min_mem_set_clock;
1527 
1528 	if (smu_cmn_feature_is_supported(smu, SMU_FEATURE_DPM_DCEFCLK_BIT)) {
1529 		clock_req.clock_type = amd_pp_dcef_clock;
1530 		clock_req.clock_freq_in_khz = min_clocks.dcef_clock * 10;
1531 
1532 		ret = smu_v11_0_display_clock_voltage_request(smu, &clock_req);
1533 		if (!ret) {
1534 			if (smu_cmn_feature_is_supported(smu, SMU_FEATURE_DS_DCEFCLK_BIT)) {
1535 				ret = smu_cmn_send_smc_msg_with_param(smu,
1536 								  SMU_MSG_SetMinDeepSleepDcefclk,
1537 								  min_clocks.dcef_clock_in_sr/100,
1538 								  NULL);
1539 				if (ret) {
1540 					dev_err(smu->adev->dev, "Attempt to set divider for DCEFCLK Failed!");
1541 					return ret;
1542 				}
1543 			}
1544 		} else {
1545 			dev_info(smu->adev->dev, "Attempt to set Hard Min for DCEFCLK Failed!");
1546 		}
1547 	}
1548 
1549 	if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT)) {
1550 		ret = smu_v11_0_set_hard_freq_limited_range(smu, SMU_UCLK, min_clocks.memory_clock/100, 0);
1551 		if (ret) {
1552 			dev_err(smu->adev->dev, "[%s] Set hard min uclk failed!", __func__);
1553 			return ret;
1554 		}
1555 	}
1556 
1557 	return 0;
1558 }
1559 
1560 static int navi10_set_watermarks_table(struct smu_context *smu,
1561 				       struct pp_smu_wm_range_sets *clock_ranges)
1562 {
1563 	Watermarks_t *table = smu->smu_table.watermarks_table;
1564 	int ret = 0;
1565 	int i;
1566 
1567 	if (clock_ranges) {
1568 		if (clock_ranges->num_reader_wm_sets > NUM_WM_RANGES ||
1569 		    clock_ranges->num_writer_wm_sets > NUM_WM_RANGES)
1570 			return -EINVAL;
1571 
1572 		for (i = 0; i < clock_ranges->num_reader_wm_sets; i++) {
1573 			table->WatermarkRow[WM_DCEFCLK][i].MinClock =
1574 				clock_ranges->reader_wm_sets[i].min_drain_clk_mhz;
1575 			table->WatermarkRow[WM_DCEFCLK][i].MaxClock =
1576 				clock_ranges->reader_wm_sets[i].max_drain_clk_mhz;
1577 			table->WatermarkRow[WM_DCEFCLK][i].MinUclk =
1578 				clock_ranges->reader_wm_sets[i].min_fill_clk_mhz;
1579 			table->WatermarkRow[WM_DCEFCLK][i].MaxUclk =
1580 				clock_ranges->reader_wm_sets[i].max_fill_clk_mhz;
1581 
1582 			table->WatermarkRow[WM_DCEFCLK][i].WmSetting =
1583 				clock_ranges->reader_wm_sets[i].wm_inst;
1584 		}
1585 
1586 		for (i = 0; i < clock_ranges->num_writer_wm_sets; i++) {
1587 			table->WatermarkRow[WM_SOCCLK][i].MinClock =
1588 				clock_ranges->writer_wm_sets[i].min_fill_clk_mhz;
1589 			table->WatermarkRow[WM_SOCCLK][i].MaxClock =
1590 				clock_ranges->writer_wm_sets[i].max_fill_clk_mhz;
1591 			table->WatermarkRow[WM_SOCCLK][i].MinUclk =
1592 				clock_ranges->writer_wm_sets[i].min_drain_clk_mhz;
1593 			table->WatermarkRow[WM_SOCCLK][i].MaxUclk =
1594 				clock_ranges->writer_wm_sets[i].max_drain_clk_mhz;
1595 
1596 			table->WatermarkRow[WM_SOCCLK][i].WmSetting =
1597 				clock_ranges->writer_wm_sets[i].wm_inst;
1598 		}
1599 
1600 		smu->watermarks_bitmap |= WATERMARKS_EXIST;
1601 	}
1602 
1603 	/* pass data to smu controller */
1604 	if ((smu->watermarks_bitmap & WATERMARKS_EXIST) &&
1605 	     !(smu->watermarks_bitmap & WATERMARKS_LOADED)) {
1606 		ret = smu_cmn_write_watermarks_table(smu);
1607 		if (ret) {
1608 			dev_err(smu->adev->dev, "Failed to update WMTABLE!");
1609 			return ret;
1610 		}
1611 		smu->watermarks_bitmap |= WATERMARKS_LOADED;
1612 	}
1613 
1614 	return 0;
1615 }
1616 
1617 static int navi10_read_sensor(struct smu_context *smu,
1618 				 enum amd_pp_sensors sensor,
1619 				 void *data, uint32_t *size)
1620 {
1621 	int ret = 0;
1622 	struct smu_table_context *table_context = &smu->smu_table;
1623 	PPTable_t *pptable = table_context->driver_pptable;
1624 
1625 	if(!data || !size)
1626 		return -EINVAL;
1627 
1628 	mutex_lock(&smu->sensor_lock);
1629 	switch (sensor) {
1630 	case AMDGPU_PP_SENSOR_MAX_FAN_RPM:
1631 		*(uint32_t *)data = pptable->FanMaximumRpm;
1632 		*size = 4;
1633 		break;
1634 	case AMDGPU_PP_SENSOR_MEM_LOAD:
1635 		ret = navi10_get_smu_metrics_data(smu,
1636 						  METRICS_AVERAGE_MEMACTIVITY,
1637 						  (uint32_t *)data);
1638 		*size = 4;
1639 		break;
1640 	case AMDGPU_PP_SENSOR_GPU_LOAD:
1641 		ret = navi10_get_smu_metrics_data(smu,
1642 						  METRICS_AVERAGE_GFXACTIVITY,
1643 						  (uint32_t *)data);
1644 		*size = 4;
1645 		break;
1646 	case AMDGPU_PP_SENSOR_GPU_POWER:
1647 		ret = navi10_get_smu_metrics_data(smu,
1648 						  METRICS_AVERAGE_SOCKETPOWER,
1649 						  (uint32_t *)data);
1650 		*size = 4;
1651 		break;
1652 	case AMDGPU_PP_SENSOR_HOTSPOT_TEMP:
1653 		ret = navi10_get_smu_metrics_data(smu,
1654 						  METRICS_TEMPERATURE_HOTSPOT,
1655 						  (uint32_t *)data);
1656 		*size = 4;
1657 		break;
1658 	case AMDGPU_PP_SENSOR_EDGE_TEMP:
1659 		ret = navi10_get_smu_metrics_data(smu,
1660 						  METRICS_TEMPERATURE_EDGE,
1661 						  (uint32_t *)data);
1662 		*size = 4;
1663 		break;
1664 	case AMDGPU_PP_SENSOR_MEM_TEMP:
1665 		ret = navi10_get_smu_metrics_data(smu,
1666 						  METRICS_TEMPERATURE_MEM,
1667 						  (uint32_t *)data);
1668 		*size = 4;
1669 		break;
1670 	case AMDGPU_PP_SENSOR_GFX_MCLK:
1671 		ret = navi10_get_current_clk_freq_by_table(smu, SMU_UCLK, (uint32_t *)data);
1672 		*(uint32_t *)data *= 100;
1673 		*size = 4;
1674 		break;
1675 	case AMDGPU_PP_SENSOR_GFX_SCLK:
1676 		ret = navi10_get_current_clk_freq_by_table(smu, SMU_GFXCLK, (uint32_t *)data);
1677 		*(uint32_t *)data *= 100;
1678 		*size = 4;
1679 		break;
1680 	case AMDGPU_PP_SENSOR_VDDGFX:
1681 		ret = smu_v11_0_get_gfx_vdd(smu, (uint32_t *)data);
1682 		*size = 4;
1683 		break;
1684 	default:
1685 		ret = -EOPNOTSUPP;
1686 		break;
1687 	}
1688 	mutex_unlock(&smu->sensor_lock);
1689 
1690 	return ret;
1691 }
1692 
1693 static int navi10_get_uclk_dpm_states(struct smu_context *smu, uint32_t *clocks_in_khz, uint32_t *num_states)
1694 {
1695 	uint32_t num_discrete_levels = 0;
1696 	uint16_t *dpm_levels = NULL;
1697 	uint16_t i = 0;
1698 	struct smu_table_context *table_context = &smu->smu_table;
1699 	PPTable_t *driver_ppt = NULL;
1700 
1701 	if (!clocks_in_khz || !num_states || !table_context->driver_pptable)
1702 		return -EINVAL;
1703 
1704 	driver_ppt = table_context->driver_pptable;
1705 	num_discrete_levels = driver_ppt->DpmDescriptor[PPCLK_UCLK].NumDiscreteLevels;
1706 	dpm_levels = driver_ppt->FreqTableUclk;
1707 
1708 	if (num_discrete_levels == 0 || dpm_levels == NULL)
1709 		return -EINVAL;
1710 
1711 	*num_states = num_discrete_levels;
1712 	for (i = 0; i < num_discrete_levels; i++) {
1713 		/* convert to khz */
1714 		*clocks_in_khz = (*dpm_levels) * 1000;
1715 		clocks_in_khz++;
1716 		dpm_levels++;
1717 	}
1718 
1719 	return 0;
1720 }
1721 
1722 static int navi10_get_thermal_temperature_range(struct smu_context *smu,
1723 						struct smu_temperature_range *range)
1724 {
1725 	struct smu_table_context *table_context = &smu->smu_table;
1726 	struct smu_11_0_powerplay_table *powerplay_table =
1727 				table_context->power_play_table;
1728 	PPTable_t *pptable = smu->smu_table.driver_pptable;
1729 
1730 	if (!range)
1731 		return -EINVAL;
1732 
1733 	memcpy(range, &smu11_thermal_policy[0], sizeof(struct smu_temperature_range));
1734 
1735 	range->max = pptable->TedgeLimit *
1736 		SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
1737 	range->edge_emergency_max = (pptable->TedgeLimit + CTF_OFFSET_EDGE) *
1738 		SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
1739 	range->hotspot_crit_max = pptable->ThotspotLimit *
1740 		SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
1741 	range->hotspot_emergency_max = (pptable->ThotspotLimit + CTF_OFFSET_HOTSPOT) *
1742 		SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
1743 	range->mem_crit_max = pptable->TmemLimit *
1744 		SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
1745 	range->mem_emergency_max = (pptable->TmemLimit + CTF_OFFSET_MEM)*
1746 		SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
1747 	range->software_shutdown_temp = powerplay_table->software_shutdown_temp;
1748 
1749 	return 0;
1750 }
1751 
1752 static int navi10_display_disable_memory_clock_switch(struct smu_context *smu,
1753 						bool disable_memory_clock_switch)
1754 {
1755 	int ret = 0;
1756 	struct smu_11_0_max_sustainable_clocks *max_sustainable_clocks =
1757 		(struct smu_11_0_max_sustainable_clocks *)
1758 			smu->smu_table.max_sustainable_clocks;
1759 	uint32_t min_memory_clock = smu->hard_min_uclk_req_from_dal;
1760 	uint32_t max_memory_clock = max_sustainable_clocks->uclock;
1761 
1762 	if(smu->disable_uclk_switch == disable_memory_clock_switch)
1763 		return 0;
1764 
1765 	if(disable_memory_clock_switch)
1766 		ret = smu_v11_0_set_hard_freq_limited_range(smu, SMU_UCLK, max_memory_clock, 0);
1767 	else
1768 		ret = smu_v11_0_set_hard_freq_limited_range(smu, SMU_UCLK, min_memory_clock, 0);
1769 
1770 	if(!ret)
1771 		smu->disable_uclk_switch = disable_memory_clock_switch;
1772 
1773 	return ret;
1774 }
1775 
1776 static int navi10_get_power_limit(struct smu_context *smu)
1777 {
1778 	struct smu_11_0_powerplay_table *powerplay_table =
1779 		(struct smu_11_0_powerplay_table *)smu->smu_table.power_play_table;
1780 	struct smu_11_0_overdrive_table *od_settings = smu->od_settings;
1781 	PPTable_t *pptable = smu->smu_table.driver_pptable;
1782 	uint32_t power_limit, od_percent;
1783 
1784 	if (smu_v11_0_get_current_power_limit(smu, &power_limit)) {
1785 		/* the last hope to figure out the ppt limit */
1786 		if (!pptable) {
1787 			dev_err(smu->adev->dev, "Cannot get PPT limit due to pptable missing!");
1788 			return -EINVAL;
1789 		}
1790 		power_limit =
1791 			pptable->SocketPowerLimitAc[PPT_THROTTLER_PPT0];
1792 	}
1793 	smu->current_power_limit = power_limit;
1794 
1795 	if (smu->od_enabled &&
1796 	    navi10_od_feature_is_supported(od_settings, SMU_11_0_ODCAP_POWER_LIMIT)) {
1797 		od_percent = le32_to_cpu(powerplay_table->overdrive_table.max[SMU_11_0_ODSETTING_POWERPERCENTAGE]);
1798 
1799 		dev_dbg(smu->adev->dev, "ODSETTING_POWERPERCENTAGE: %d (default: %d)\n", od_percent, power_limit);
1800 
1801 		power_limit *= (100 + od_percent);
1802 		power_limit /= 100;
1803 	}
1804 	smu->max_power_limit = power_limit;
1805 
1806 	return 0;
1807 }
1808 
1809 static int navi10_update_pcie_parameters(struct smu_context *smu,
1810 				     uint32_t pcie_gen_cap,
1811 				     uint32_t pcie_width_cap)
1812 {
1813 	struct smu_11_0_dpm_context *dpm_context = smu->smu_dpm.dpm_context;
1814 	PPTable_t *pptable = smu->smu_table.driver_pptable;
1815 	uint32_t smu_pcie_arg;
1816 	int ret, i;
1817 
1818 	/* lclk dpm table setup */
1819 	for (i = 0; i < MAX_PCIE_CONF; i++) {
1820 		dpm_context->dpm_tables.pcie_table.pcie_gen[i] = pptable->PcieGenSpeed[i];
1821 		dpm_context->dpm_tables.pcie_table.pcie_lane[i] = pptable->PcieLaneCount[i];
1822 	}
1823 
1824 	for (i = 0; i < NUM_LINK_LEVELS; i++) {
1825 		smu_pcie_arg = (i << 16) |
1826 			((pptable->PcieGenSpeed[i] <= pcie_gen_cap) ? (pptable->PcieGenSpeed[i] << 8) :
1827 				(pcie_gen_cap << 8)) | ((pptable->PcieLaneCount[i] <= pcie_width_cap) ?
1828 					pptable->PcieLaneCount[i] : pcie_width_cap);
1829 		ret = smu_cmn_send_smc_msg_with_param(smu,
1830 					  SMU_MSG_OverridePcieParameters,
1831 					  smu_pcie_arg,
1832 					  NULL);
1833 
1834 		if (ret)
1835 			return ret;
1836 
1837 		if (pptable->PcieGenSpeed[i] > pcie_gen_cap)
1838 			dpm_context->dpm_tables.pcie_table.pcie_gen[i] = pcie_gen_cap;
1839 		if (pptable->PcieLaneCount[i] > pcie_width_cap)
1840 			dpm_context->dpm_tables.pcie_table.pcie_lane[i] = pcie_width_cap;
1841 	}
1842 
1843 	return 0;
1844 }
1845 
1846 static inline void navi10_dump_od_table(struct smu_context *smu,
1847 					OverDriveTable_t *od_table)
1848 {
1849 	dev_dbg(smu->adev->dev, "OD: Gfxclk: (%d, %d)\n", od_table->GfxclkFmin, od_table->GfxclkFmax);
1850 	dev_dbg(smu->adev->dev, "OD: Gfx1: (%d, %d)\n", od_table->GfxclkFreq1, od_table->GfxclkVolt1);
1851 	dev_dbg(smu->adev->dev, "OD: Gfx2: (%d, %d)\n", od_table->GfxclkFreq2, od_table->GfxclkVolt2);
1852 	dev_dbg(smu->adev->dev, "OD: Gfx3: (%d, %d)\n", od_table->GfxclkFreq3, od_table->GfxclkVolt3);
1853 	dev_dbg(smu->adev->dev, "OD: UclkFmax: %d\n", od_table->UclkFmax);
1854 	dev_dbg(smu->adev->dev, "OD: OverDrivePct: %d\n", od_table->OverDrivePct);
1855 }
1856 
1857 static int navi10_od_setting_check_range(struct smu_context *smu,
1858 					 struct smu_11_0_overdrive_table *od_table,
1859 					 enum SMU_11_0_ODSETTING_ID setting,
1860 					 uint32_t value)
1861 {
1862 	if (value < od_table->min[setting]) {
1863 		dev_warn(smu->adev->dev, "OD setting (%d, %d) is less than the minimum allowed (%d)\n", setting, value, od_table->min[setting]);
1864 		return -EINVAL;
1865 	}
1866 	if (value > od_table->max[setting]) {
1867 		dev_warn(smu->adev->dev, "OD setting (%d, %d) is greater than the maximum allowed (%d)\n", setting, value, od_table->max[setting]);
1868 		return -EINVAL;
1869 	}
1870 	return 0;
1871 }
1872 
1873 static int navi10_overdrive_get_gfx_clk_base_voltage(struct smu_context *smu,
1874 						     uint16_t *voltage,
1875 						     uint32_t freq)
1876 {
1877 	uint32_t param = (freq & 0xFFFF) | (PPCLK_GFXCLK << 16);
1878 	uint32_t value = 0;
1879 	int ret;
1880 
1881 	ret = smu_cmn_send_smc_msg_with_param(smu,
1882 					  SMU_MSG_GetVoltageByDpm,
1883 					  param,
1884 					  &value);
1885 	if (ret) {
1886 		dev_err(smu->adev->dev, "[GetBaseVoltage] failed to get GFXCLK AVFS voltage from SMU!");
1887 		return ret;
1888 	}
1889 
1890 	*voltage = (uint16_t)value;
1891 
1892 	return 0;
1893 }
1894 
1895 static bool navi10_is_baco_supported(struct smu_context *smu)
1896 {
1897 	struct amdgpu_device *adev = smu->adev;
1898 	uint32_t val;
1899 
1900 	if (amdgpu_sriov_vf(adev) || (!smu_v11_0_baco_is_support(smu)))
1901 		return false;
1902 
1903 	val = RREG32_SOC15(NBIO, 0, mmRCC_BIF_STRAP0);
1904 	return (val & RCC_BIF_STRAP0__STRAP_PX_CAPABLE_MASK) ? true : false;
1905 }
1906 
1907 static int navi10_set_default_od_settings(struct smu_context *smu)
1908 {
1909 	OverDriveTable_t *od_table =
1910 		(OverDriveTable_t *)smu->smu_table.overdrive_table;
1911 	OverDriveTable_t *boot_od_table =
1912 		(OverDriveTable_t *)smu->smu_table.boot_overdrive_table;
1913 	int ret = 0;
1914 
1915 	ret = smu_cmn_update_table(smu, SMU_TABLE_OVERDRIVE, 0, (void *)od_table, false);
1916 	if (ret) {
1917 		dev_err(smu->adev->dev, "Failed to get overdrive table!\n");
1918 		return ret;
1919 	}
1920 
1921 	if (!od_table->GfxclkVolt1) {
1922 		ret = navi10_overdrive_get_gfx_clk_base_voltage(smu,
1923 								&od_table->GfxclkVolt1,
1924 								od_table->GfxclkFreq1);
1925 		if (ret)
1926 			return ret;
1927 	}
1928 
1929 	if (!od_table->GfxclkVolt2) {
1930 		ret = navi10_overdrive_get_gfx_clk_base_voltage(smu,
1931 								&od_table->GfxclkVolt2,
1932 								od_table->GfxclkFreq2);
1933 		if (ret)
1934 			return ret;
1935 	}
1936 
1937 	if (!od_table->GfxclkVolt3) {
1938 		ret = navi10_overdrive_get_gfx_clk_base_voltage(smu,
1939 								&od_table->GfxclkVolt3,
1940 								od_table->GfxclkFreq3);
1941 		if (ret)
1942 			return ret;
1943 	}
1944 
1945 	memcpy(boot_od_table, od_table, sizeof(OverDriveTable_t));
1946 
1947 	navi10_dump_od_table(smu, od_table);
1948 
1949 	return 0;
1950 }
1951 
1952 static int navi10_od_edit_dpm_table(struct smu_context *smu, enum PP_OD_DPM_TABLE_COMMAND type, long input[], uint32_t size) {
1953 	int i;
1954 	int ret = 0;
1955 	struct smu_table_context *table_context = &smu->smu_table;
1956 	OverDriveTable_t *od_table;
1957 	struct smu_11_0_overdrive_table *od_settings;
1958 	enum SMU_11_0_ODSETTING_ID freq_setting, voltage_setting;
1959 	uint16_t *freq_ptr, *voltage_ptr;
1960 	od_table = (OverDriveTable_t *)table_context->overdrive_table;
1961 
1962 	if (!smu->od_enabled) {
1963 		dev_warn(smu->adev->dev, "OverDrive is not enabled!\n");
1964 		return -EINVAL;
1965 	}
1966 
1967 	if (!smu->od_settings) {
1968 		dev_err(smu->adev->dev, "OD board limits are not set!\n");
1969 		return -ENOENT;
1970 	}
1971 
1972 	od_settings = smu->od_settings;
1973 
1974 	switch (type) {
1975 	case PP_OD_EDIT_SCLK_VDDC_TABLE:
1976 		if (!navi10_od_feature_is_supported(od_settings, SMU_11_0_ODCAP_GFXCLK_LIMITS)) {
1977 			dev_warn(smu->adev->dev, "GFXCLK_LIMITS not supported!\n");
1978 			return -ENOTSUPP;
1979 		}
1980 		if (!table_context->overdrive_table) {
1981 			dev_err(smu->adev->dev, "Overdrive is not initialized\n");
1982 			return -EINVAL;
1983 		}
1984 		for (i = 0; i < size; i += 2) {
1985 			if (i + 2 > size) {
1986 				dev_info(smu->adev->dev, "invalid number of input parameters %d\n", size);
1987 				return -EINVAL;
1988 			}
1989 			switch (input[i]) {
1990 			case 0:
1991 				freq_setting = SMU_11_0_ODSETTING_GFXCLKFMIN;
1992 				freq_ptr = &od_table->GfxclkFmin;
1993 				if (input[i + 1] > od_table->GfxclkFmax) {
1994 					dev_info(smu->adev->dev, "GfxclkFmin (%ld) must be <= GfxclkFmax (%u)!\n",
1995 						input[i + 1],
1996 						od_table->GfxclkFmin);
1997 					return -EINVAL;
1998 				}
1999 				break;
2000 			case 1:
2001 				freq_setting = SMU_11_0_ODSETTING_GFXCLKFMAX;
2002 				freq_ptr = &od_table->GfxclkFmax;
2003 				if (input[i + 1] < od_table->GfxclkFmin) {
2004 					dev_info(smu->adev->dev, "GfxclkFmax (%ld) must be >= GfxclkFmin (%u)!\n",
2005 						input[i + 1],
2006 						od_table->GfxclkFmax);
2007 					return -EINVAL;
2008 				}
2009 				break;
2010 			default:
2011 				dev_info(smu->adev->dev, "Invalid SCLK_VDDC_TABLE index: %ld\n", input[i]);
2012 				dev_info(smu->adev->dev, "Supported indices: [0:min,1:max]\n");
2013 				return -EINVAL;
2014 			}
2015 			ret = navi10_od_setting_check_range(smu, od_settings, freq_setting, input[i + 1]);
2016 			if (ret)
2017 				return ret;
2018 			*freq_ptr = input[i + 1];
2019 		}
2020 		break;
2021 	case PP_OD_EDIT_MCLK_VDDC_TABLE:
2022 		if (!navi10_od_feature_is_supported(od_settings, SMU_11_0_ODCAP_UCLK_MAX)) {
2023 			dev_warn(smu->adev->dev, "UCLK_MAX not supported!\n");
2024 			return -ENOTSUPP;
2025 		}
2026 		if (size < 2) {
2027 			dev_info(smu->adev->dev, "invalid number of parameters: %d\n", size);
2028 			return -EINVAL;
2029 		}
2030 		if (input[0] != 1) {
2031 			dev_info(smu->adev->dev, "Invalid MCLK_VDDC_TABLE index: %ld\n", input[0]);
2032 			dev_info(smu->adev->dev, "Supported indices: [1:max]\n");
2033 			return -EINVAL;
2034 		}
2035 		ret = navi10_od_setting_check_range(smu, od_settings, SMU_11_0_ODSETTING_UCLKFMAX, input[1]);
2036 		if (ret)
2037 			return ret;
2038 		od_table->UclkFmax = input[1];
2039 		break;
2040 	case PP_OD_RESTORE_DEFAULT_TABLE:
2041 		if (!(table_context->overdrive_table && table_context->boot_overdrive_table)) {
2042 			dev_err(smu->adev->dev, "Overdrive table was not initialized!\n");
2043 			return -EINVAL;
2044 		}
2045 		memcpy(table_context->overdrive_table, table_context->boot_overdrive_table, sizeof(OverDriveTable_t));
2046 		break;
2047 	case PP_OD_COMMIT_DPM_TABLE:
2048 		navi10_dump_od_table(smu, od_table);
2049 		ret = smu_cmn_update_table(smu, SMU_TABLE_OVERDRIVE, 0, (void *)od_table, true);
2050 		if (ret) {
2051 			dev_err(smu->adev->dev, "Failed to import overdrive table!\n");
2052 			return ret;
2053 		}
2054 		break;
2055 	case PP_OD_EDIT_VDDC_CURVE:
2056 		if (!navi10_od_feature_is_supported(od_settings, SMU_11_0_ODCAP_GFXCLK_CURVE)) {
2057 			dev_warn(smu->adev->dev, "GFXCLK_CURVE not supported!\n");
2058 			return -ENOTSUPP;
2059 		}
2060 		if (size < 3) {
2061 			dev_info(smu->adev->dev, "invalid number of parameters: %d\n", size);
2062 			return -EINVAL;
2063 		}
2064 		if (!od_table) {
2065 			dev_info(smu->adev->dev, "Overdrive is not initialized\n");
2066 			return -EINVAL;
2067 		}
2068 
2069 		switch (input[0]) {
2070 		case 0:
2071 			freq_setting = SMU_11_0_ODSETTING_VDDGFXCURVEFREQ_P1;
2072 			voltage_setting = SMU_11_0_ODSETTING_VDDGFXCURVEVOLTAGE_P1;
2073 			freq_ptr = &od_table->GfxclkFreq1;
2074 			voltage_ptr = &od_table->GfxclkVolt1;
2075 			break;
2076 		case 1:
2077 			freq_setting = SMU_11_0_ODSETTING_VDDGFXCURVEFREQ_P2;
2078 			voltage_setting = SMU_11_0_ODSETTING_VDDGFXCURVEVOLTAGE_P2;
2079 			freq_ptr = &od_table->GfxclkFreq2;
2080 			voltage_ptr = &od_table->GfxclkVolt2;
2081 			break;
2082 		case 2:
2083 			freq_setting = SMU_11_0_ODSETTING_VDDGFXCURVEFREQ_P3;
2084 			voltage_setting = SMU_11_0_ODSETTING_VDDGFXCURVEVOLTAGE_P3;
2085 			freq_ptr = &od_table->GfxclkFreq3;
2086 			voltage_ptr = &od_table->GfxclkVolt3;
2087 			break;
2088 		default:
2089 			dev_info(smu->adev->dev, "Invalid VDDC_CURVE index: %ld\n", input[0]);
2090 			dev_info(smu->adev->dev, "Supported indices: [0, 1, 2]\n");
2091 			return -EINVAL;
2092 		}
2093 		ret = navi10_od_setting_check_range(smu, od_settings, freq_setting, input[1]);
2094 		if (ret)
2095 			return ret;
2096 		// Allow setting zero to disable the OverDrive VDDC curve
2097 		if (input[2] != 0) {
2098 			ret = navi10_od_setting_check_range(smu, od_settings, voltage_setting, input[2]);
2099 			if (ret)
2100 				return ret;
2101 			*freq_ptr = input[1];
2102 			*voltage_ptr = ((uint16_t)input[2]) * NAVI10_VOLTAGE_SCALE;
2103 			dev_dbg(smu->adev->dev, "OD: set curve %ld: (%d, %d)\n", input[0], *freq_ptr, *voltage_ptr);
2104 		} else {
2105 			// If setting 0, disable all voltage curve settings
2106 			od_table->GfxclkVolt1 = 0;
2107 			od_table->GfxclkVolt2 = 0;
2108 			od_table->GfxclkVolt3 = 0;
2109 		}
2110 		navi10_dump_od_table(smu, od_table);
2111 		break;
2112 	default:
2113 		return -ENOSYS;
2114 	}
2115 	return ret;
2116 }
2117 
2118 static int navi10_run_btc(struct smu_context *smu)
2119 {
2120 	int ret = 0;
2121 
2122 	ret = smu_cmn_send_smc_msg(smu, SMU_MSG_RunBtc, NULL);
2123 	if (ret)
2124 		dev_err(smu->adev->dev, "RunBtc failed!\n");
2125 
2126 	return ret;
2127 }
2128 
2129 static bool navi10_need_umc_cdr_workaround(struct smu_context *smu)
2130 {
2131 	struct amdgpu_device *adev = smu->adev;
2132 
2133 	if (!smu_cmn_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT))
2134 		return false;
2135 
2136 	if (adev->asic_type == CHIP_NAVI10 ||
2137 	    adev->asic_type == CHIP_NAVI14)
2138 		return true;
2139 
2140 	return false;
2141 }
2142 
2143 static int navi10_umc_hybrid_cdr_workaround(struct smu_context *smu)
2144 {
2145 	uint32_t uclk_count, uclk_min, uclk_max;
2146 	int ret = 0;
2147 
2148 	/* This workaround can be applied only with uclk dpm enabled */
2149 	if (!smu_cmn_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT))
2150 		return 0;
2151 
2152 	ret = smu_v11_0_get_dpm_level_count(smu, SMU_UCLK, &uclk_count);
2153 	if (ret)
2154 		return ret;
2155 
2156 	ret = smu_v11_0_get_dpm_freq_by_index(smu, SMU_UCLK, (uint16_t)(uclk_count - 1), &uclk_max);
2157 	if (ret)
2158 		return ret;
2159 
2160 	/*
2161 	 * The NAVI10_UMC_HYBRID_CDR_WORKAROUND_UCLK_THRESHOLD is 750Mhz.
2162 	 * This workaround is needed only when the max uclk frequency
2163 	 * not greater than that.
2164 	 */
2165 	if (uclk_max > 0x2EE)
2166 		return 0;
2167 
2168 	ret = smu_v11_0_get_dpm_freq_by_index(smu, SMU_UCLK, (uint16_t)0, &uclk_min);
2169 	if (ret)
2170 		return ret;
2171 
2172 	/* Force UCLK out of the highest DPM */
2173 	ret = smu_v11_0_set_hard_freq_limited_range(smu, SMU_UCLK, 0, uclk_min);
2174 	if (ret)
2175 		return ret;
2176 
2177 	/* Revert the UCLK Hardmax */
2178 	ret = smu_v11_0_set_hard_freq_limited_range(smu, SMU_UCLK, 0, uclk_max);
2179 	if (ret)
2180 		return ret;
2181 
2182 	/*
2183 	 * In this case, SMU already disabled dummy pstate during enablement
2184 	 * of UCLK DPM, we have to re-enabled it.
2185 	 */
2186 	return smu_cmn_send_smc_msg(smu, SMU_MSG_DAL_ENABLE_DUMMY_PSTATE_CHANGE, NULL);
2187 }
2188 
2189 static int navi10_set_dummy_pstates_table_location(struct smu_context *smu)
2190 {
2191 	struct smu_table_context *smu_table = &smu->smu_table;
2192 	struct smu_table *dummy_read_table =
2193 				&smu_table->dummy_read_1_table;
2194 	char *dummy_table = dummy_read_table->cpu_addr;
2195 	int ret = 0;
2196 	uint32_t i;
2197 
2198 	for (i = 0; i < 0x40000; i += 0x1000 * 2) {
2199 		memcpy(dummy_table, &NoDbiPrbs7[0], 0x1000);
2200 		dummy_table += 0x1000;
2201 		memcpy(dummy_table, &DbiPrbs7[0], 0x1000);
2202 		dummy_table += 0x1000;
2203 	}
2204 
2205 	amdgpu_asic_flush_hdp(smu->adev, NULL);
2206 
2207 	ret = smu_cmn_send_smc_msg_with_param(smu,
2208 					      SMU_MSG_SET_DRIVER_DUMMY_TABLE_DRAM_ADDR_HIGH,
2209 					      upper_32_bits(dummy_read_table->mc_address),
2210 					      NULL);
2211 	if (ret)
2212 		return ret;
2213 
2214 	return smu_cmn_send_smc_msg_with_param(smu,
2215 					       SMU_MSG_SET_DRIVER_DUMMY_TABLE_DRAM_ADDR_LOW,
2216 					       lower_32_bits(dummy_read_table->mc_address),
2217 					       NULL);
2218 }
2219 
2220 static int navi10_run_umc_cdr_workaround(struct smu_context *smu)
2221 {
2222 	struct amdgpu_device *adev = smu->adev;
2223 	uint8_t umc_fw_greater_than_v136 = false;
2224 	uint8_t umc_fw_disable_cdr = false;
2225 	uint32_t pmfw_version;
2226 	uint32_t param;
2227 	int ret = 0;
2228 
2229 	if (!navi10_need_umc_cdr_workaround(smu))
2230 		return 0;
2231 
2232 	ret = smu_cmn_get_smc_version(smu, NULL, &pmfw_version);
2233 	if (ret) {
2234 		dev_err(adev->dev, "Failed to get smu version!\n");
2235 		return ret;
2236 	}
2237 
2238 	/*
2239 	 * The messages below are only supported by Navi10 42.53.0 and later
2240 	 * PMFWs and Navi14 53.29.0 and later PMFWs.
2241 	 * - PPSMC_MSG_SetDriverDummyTableDramAddrHigh
2242 	 * - PPSMC_MSG_SetDriverDummyTableDramAddrLow
2243 	 * - PPSMC_MSG_GetUMCFWWA
2244 	 */
2245 	if (((adev->asic_type == CHIP_NAVI10) && (pmfw_version >= 0x2a3500)) ||
2246 	    ((adev->asic_type == CHIP_NAVI14) && (pmfw_version >= 0x351D00))) {
2247 		ret = smu_cmn_send_smc_msg_with_param(smu,
2248 						      SMU_MSG_GET_UMC_FW_WA,
2249 						      0,
2250 						      &param);
2251 		if (ret)
2252 			return ret;
2253 
2254 		/* First bit indicates if the UMC f/w is above v137 */
2255 		umc_fw_greater_than_v136 = param & 0x1;
2256 
2257 		/* Second bit indicates if hybrid-cdr is disabled */
2258 		umc_fw_disable_cdr = param & 0x2;
2259 
2260 		/* w/a only allowed if UMC f/w is <= 136 */
2261 		if (umc_fw_greater_than_v136)
2262 			return 0;
2263 
2264 		if (umc_fw_disable_cdr) {
2265 			if (adev->asic_type == CHIP_NAVI10)
2266 				return navi10_umc_hybrid_cdr_workaround(smu);
2267 		} else {
2268 			return navi10_set_dummy_pstates_table_location(smu);
2269 		}
2270 	} else {
2271 		if (adev->asic_type == CHIP_NAVI10)
2272 			return navi10_umc_hybrid_cdr_workaround(smu);
2273 	}
2274 
2275 	return 0;
2276 }
2277 
2278 static ssize_t navi10_get_gpu_metrics(struct smu_context *smu,
2279 				      void **table)
2280 {
2281 	struct smu_table_context *smu_table = &smu->smu_table;
2282 	struct gpu_metrics_v1_0 *gpu_metrics =
2283 		(struct gpu_metrics_v1_0 *)smu_table->gpu_metrics_table;
2284 	struct amdgpu_device *adev = smu->adev;
2285 	SmuMetrics_NV12_t nv12_metrics = { 0 };
2286 	SmuMetrics_t metrics;
2287 	int ret = 0;
2288 
2289 	mutex_lock(&smu->metrics_lock);
2290 
2291 	ret = smu_cmn_get_metrics_table_locked(smu,
2292 					       NULL,
2293 					       true);
2294 	if (ret) {
2295 		mutex_unlock(&smu->metrics_lock);
2296 		return ret;
2297 	}
2298 
2299 	memcpy(&metrics, smu_table->metrics_table, sizeof(SmuMetrics_t));
2300 	if (adev->asic_type == CHIP_NAVI12)
2301 		memcpy(&nv12_metrics, smu_table->metrics_table, sizeof(SmuMetrics_NV12_t));
2302 
2303 	mutex_unlock(&smu->metrics_lock);
2304 
2305 	smu_v11_0_init_gpu_metrics_v1_0(gpu_metrics);
2306 
2307 	gpu_metrics->temperature_edge = metrics.TemperatureEdge;
2308 	gpu_metrics->temperature_hotspot = metrics.TemperatureHotspot;
2309 	gpu_metrics->temperature_mem = metrics.TemperatureMem;
2310 	gpu_metrics->temperature_vrgfx = metrics.TemperatureVrGfx;
2311 	gpu_metrics->temperature_vrsoc = metrics.TemperatureVrSoc;
2312 	gpu_metrics->temperature_vrmem = metrics.TemperatureVrMem0;
2313 
2314 	gpu_metrics->average_gfx_activity = metrics.AverageGfxActivity;
2315 	gpu_metrics->average_umc_activity = metrics.AverageUclkActivity;
2316 
2317 	gpu_metrics->average_socket_power = metrics.AverageSocketPower;
2318 
2319 	gpu_metrics->average_gfxclk_frequency = metrics.AverageGfxclkFrequency;
2320 	gpu_metrics->average_socclk_frequency = metrics.AverageSocclkFrequency;
2321 	gpu_metrics->average_uclk_frequency = metrics.AverageUclkFrequency;
2322 
2323 	if (adev->asic_type == CHIP_NAVI12) {
2324 		gpu_metrics->energy_accumulator = nv12_metrics.EnergyAccumulator;
2325 		gpu_metrics->average_vclk0_frequency = nv12_metrics.AverageVclkFrequency;
2326 		gpu_metrics->average_dclk0_frequency = nv12_metrics.AverageDclkFrequency;
2327 		gpu_metrics->average_mm_activity = nv12_metrics.VcnActivityPercentage;
2328 	}
2329 
2330 	gpu_metrics->current_gfxclk = metrics.CurrClock[PPCLK_GFXCLK];
2331 	gpu_metrics->current_socclk = metrics.CurrClock[PPCLK_SOCCLK];
2332 	gpu_metrics->current_uclk = metrics.CurrClock[PPCLK_UCLK];
2333 	gpu_metrics->current_vclk0 = metrics.CurrClock[PPCLK_VCLK];
2334 	gpu_metrics->current_dclk0 = metrics.CurrClock[PPCLK_DCLK];
2335 
2336 	gpu_metrics->throttle_status = metrics.ThrottlerStatus;
2337 
2338 	gpu_metrics->current_fan_speed = metrics.CurrFanSpeed;
2339 
2340 	gpu_metrics->pcie_link_width =
2341 			smu_v11_0_get_current_pcie_link_width(smu);
2342 	gpu_metrics->pcie_link_speed =
2343 			smu_v11_0_get_current_pcie_link_speed(smu);
2344 
2345 	*table = (void *)gpu_metrics;
2346 
2347 	return sizeof(struct gpu_metrics_v1_0);
2348 }
2349 
2350 static int navi10_enable_mgpu_fan_boost(struct smu_context *smu)
2351 {
2352 	struct amdgpu_device *adev = smu->adev;
2353 	uint32_t param = 0;
2354 
2355 	/* Navi12 does not support this */
2356 	if (adev->asic_type == CHIP_NAVI12)
2357 		return 0;
2358 
2359 	/* Workaround for WS SKU */
2360 	if (adev->pdev->device == 0x7312 &&
2361 	    adev->pdev->revision == 0)
2362 		param = 0xD188;
2363 
2364 	return smu_cmn_send_smc_msg_with_param(smu,
2365 					       SMU_MSG_SetMGpuFanBoostLimitRpm,
2366 					       param,
2367 					       NULL);
2368 }
2369 
2370 static int navi10_post_smu_init(struct smu_context *smu)
2371 {
2372 	struct amdgpu_device *adev = smu->adev;
2373 	int ret = 0;
2374 
2375 	if (amdgpu_sriov_vf(adev))
2376 		return 0;
2377 
2378 	ret = navi10_run_umc_cdr_workaround(smu);
2379 	if (ret) {
2380 		dev_err(adev->dev, "Failed to apply umc cdr workaround!\n");
2381 		return ret;
2382 	}
2383 
2384 	if (!smu->dc_controlled_by_gpio) {
2385 		/*
2386 		 * For Navi1X, manually switch it to AC mode as PMFW
2387 		 * may boot it with DC mode.
2388 		 */
2389 		ret = smu_v11_0_set_power_source(smu,
2390 						 adev->pm.ac_power ?
2391 						 SMU_POWER_SOURCE_AC :
2392 						 SMU_POWER_SOURCE_DC);
2393 		if (ret) {
2394 			dev_err(adev->dev, "Failed to switch to %s mode!\n",
2395 					adev->pm.ac_power ? "AC" : "DC");
2396 			return ret;
2397 		}
2398 	}
2399 
2400 	return ret;
2401 }
2402 
2403 static const struct pptable_funcs navi10_ppt_funcs = {
2404 	.get_allowed_feature_mask = navi10_get_allowed_feature_mask,
2405 	.set_default_dpm_table = navi10_set_default_dpm_table,
2406 	.dpm_set_vcn_enable = navi10_dpm_set_vcn_enable,
2407 	.dpm_set_jpeg_enable = navi10_dpm_set_jpeg_enable,
2408 	.print_clk_levels = navi10_print_clk_levels,
2409 	.force_clk_levels = navi10_force_clk_levels,
2410 	.populate_umd_state_clk = navi10_populate_umd_state_clk,
2411 	.get_clock_by_type_with_latency = navi10_get_clock_by_type_with_latency,
2412 	.pre_display_config_changed = navi10_pre_display_config_changed,
2413 	.display_config_changed = navi10_display_config_changed,
2414 	.notify_smc_display_config = navi10_notify_smc_display_config,
2415 	.is_dpm_running = navi10_is_dpm_running,
2416 	.get_fan_speed_rpm = navi10_get_fan_speed_rpm,
2417 	.get_power_profile_mode = navi10_get_power_profile_mode,
2418 	.set_power_profile_mode = navi10_set_power_profile_mode,
2419 	.set_watermarks_table = navi10_set_watermarks_table,
2420 	.read_sensor = navi10_read_sensor,
2421 	.get_uclk_dpm_states = navi10_get_uclk_dpm_states,
2422 	.set_performance_level = smu_v11_0_set_performance_level,
2423 	.get_thermal_temperature_range = navi10_get_thermal_temperature_range,
2424 	.display_disable_memory_clock_switch = navi10_display_disable_memory_clock_switch,
2425 	.get_power_limit = navi10_get_power_limit,
2426 	.update_pcie_parameters = navi10_update_pcie_parameters,
2427 	.init_microcode = smu_v11_0_init_microcode,
2428 	.load_microcode = smu_v11_0_load_microcode,
2429 	.fini_microcode = smu_v11_0_fini_microcode,
2430 	.init_smc_tables = navi10_init_smc_tables,
2431 	.fini_smc_tables = smu_v11_0_fini_smc_tables,
2432 	.init_power = smu_v11_0_init_power,
2433 	.fini_power = smu_v11_0_fini_power,
2434 	.check_fw_status = smu_v11_0_check_fw_status,
2435 	.setup_pptable = navi10_setup_pptable,
2436 	.get_vbios_bootup_values = smu_v11_0_get_vbios_bootup_values,
2437 	.check_fw_version = smu_v11_0_check_fw_version,
2438 	.write_pptable = smu_cmn_write_pptable,
2439 	.set_driver_table_location = smu_v11_0_set_driver_table_location,
2440 	.set_tool_table_location = smu_v11_0_set_tool_table_location,
2441 	.notify_memory_pool_location = smu_v11_0_notify_memory_pool_location,
2442 	.system_features_control = smu_v11_0_system_features_control,
2443 	.send_smc_msg_with_param = smu_cmn_send_smc_msg_with_param,
2444 	.send_smc_msg = smu_cmn_send_smc_msg,
2445 	.init_display_count = smu_v11_0_init_display_count,
2446 	.set_allowed_mask = smu_v11_0_set_allowed_mask,
2447 	.get_enabled_mask = smu_cmn_get_enabled_mask,
2448 	.feature_is_enabled = smu_cmn_feature_is_enabled,
2449 	.disable_all_features_with_exception = smu_cmn_disable_all_features_with_exception,
2450 	.notify_display_change = smu_v11_0_notify_display_change,
2451 	.set_power_limit = smu_v11_0_set_power_limit,
2452 	.init_max_sustainable_clocks = smu_v11_0_init_max_sustainable_clocks,
2453 	.enable_thermal_alert = smu_v11_0_enable_thermal_alert,
2454 	.disable_thermal_alert = smu_v11_0_disable_thermal_alert,
2455 	.set_min_dcef_deep_sleep = smu_v11_0_set_min_deep_sleep_dcefclk,
2456 	.display_clock_voltage_request = smu_v11_0_display_clock_voltage_request,
2457 	.get_fan_control_mode = smu_v11_0_get_fan_control_mode,
2458 	.set_fan_control_mode = smu_v11_0_set_fan_control_mode,
2459 	.set_fan_speed_percent = smu_v11_0_set_fan_speed_percent,
2460 	.set_fan_speed_rpm = smu_v11_0_set_fan_speed_rpm,
2461 	.set_xgmi_pstate = smu_v11_0_set_xgmi_pstate,
2462 	.gfx_off_control = smu_v11_0_gfx_off_control,
2463 	.register_irq_handler = smu_v11_0_register_irq_handler,
2464 	.set_azalia_d3_pme = smu_v11_0_set_azalia_d3_pme,
2465 	.get_max_sustainable_clocks_by_dc = smu_v11_0_get_max_sustainable_clocks_by_dc,
2466 	.baco_is_support= navi10_is_baco_supported,
2467 	.baco_get_state = smu_v11_0_baco_get_state,
2468 	.baco_set_state = smu_v11_0_baco_set_state,
2469 	.baco_enter = smu_v11_0_baco_enter,
2470 	.baco_exit = smu_v11_0_baco_exit,
2471 	.get_dpm_ultimate_freq = smu_v11_0_get_dpm_ultimate_freq,
2472 	.set_soft_freq_limited_range = smu_v11_0_set_soft_freq_limited_range,
2473 	.set_default_od_settings = navi10_set_default_od_settings,
2474 	.od_edit_dpm_table = navi10_od_edit_dpm_table,
2475 	.run_btc = navi10_run_btc,
2476 	.set_power_source = smu_v11_0_set_power_source,
2477 	.get_pp_feature_mask = smu_cmn_get_pp_feature_mask,
2478 	.set_pp_feature_mask = smu_cmn_set_pp_feature_mask,
2479 	.get_gpu_metrics = navi10_get_gpu_metrics,
2480 	.enable_mgpu_fan_boost = navi10_enable_mgpu_fan_boost,
2481 	.gfx_ulv_control = smu_v11_0_gfx_ulv_control,
2482 	.deep_sleep_control = smu_v11_0_deep_sleep_control,
2483 	.get_fan_parameters = navi10_get_fan_parameters,
2484 	.post_init = navi10_post_smu_init,
2485 	.interrupt_work = smu_v11_0_interrupt_work,
2486 };
2487 
2488 void navi10_set_ppt_funcs(struct smu_context *smu)
2489 {
2490 	smu->ppt_funcs = &navi10_ppt_funcs;
2491 	smu->message_map = navi10_message_map;
2492 	smu->clock_map = navi10_clk_map;
2493 	smu->feature_map = navi10_feature_mask_map;
2494 	smu->table_map = navi10_table_map;
2495 	smu->pwr_src_map = navi10_pwr_src_map;
2496 	smu->workload_map = navi10_workload_map;
2497 }
2498