smu10_hwmgr.c 31.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
/*
 * Copyright 2015 Advanced Micro Devices, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 */
#include "pp_debug.h"
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include "atom-types.h"
#include "atombios.h"
#include "processpptables.h"
#include "cgs_common.h"
#include "smumgr.h"
#include "hwmgr.h"
#include "hardwaremanager.h"
#include "rv_ppsmc.h"
R
Rex Zhu 已提交
35
#include "smu10_hwmgr.h"
36
#include "power_state.h"
37
#include "soc15_common.h"
38

R
Rex Zhu 已提交
39 40
#define SMU10_MAX_DEEPSLEEP_DIVIDER_ID     5
#define SMU10_MINIMUM_ENGINE_CLOCK         800   /* 8Mhz, the low boundary of engine clock allowed on this chip */
41
#define SCLK_MIN_DIV_INTV_SHIFT         12
R
Rex Zhu 已提交
42
#define SMU10_DISPCLK_BYPASS_THRESHOLD     10000 /* 100Mhz */
43 44
#define SMC_RAM_END                     0x40000

45 46 47 48 49 50 51
#define mmPWR_MISC_CNTL_STATUS					0x0183
#define mmPWR_MISC_CNTL_STATUS_BASE_IDX				0
#define PWR_MISC_CNTL_STATUS__PWR_GFX_RLC_CGPG_EN__SHIFT	0x0
#define PWR_MISC_CNTL_STATUS__PWR_GFXOFF_STATUS__SHIFT		0x1
#define PWR_MISC_CNTL_STATUS__PWR_GFX_RLC_CGPG_EN_MASK		0x00000001L
#define PWR_MISC_CNTL_STATUS__PWR_GFXOFF_STATUS_MASK		0x00000006L

R
Rex Zhu 已提交
52
static const unsigned long SMU10_Magic = (unsigned long) PHM_Rv_Magic;
53 54


R
Rex Zhu 已提交
55
static int smu10_display_clock_voltage_request(struct pp_hwmgr *hwmgr,
56
		struct pp_display_clock_request *clock_req);
57 58


R
Rex Zhu 已提交
59
static struct smu10_power_state *cast_smu10_ps(struct pp_hw_power_state *hw_ps)
60
{
R
Rex Zhu 已提交
61
	if (SMU10_Magic != hw_ps->magic)
62 63
		return NULL;

R
Rex Zhu 已提交
64
	return (struct smu10_power_state *)hw_ps;
65 66
}

R
Rex Zhu 已提交
67
static const struct smu10_power_state *cast_const_smu10_ps(
68 69
				const struct pp_hw_power_state *hw_ps)
{
R
Rex Zhu 已提交
70
	if (SMU10_Magic != hw_ps->magic)
71 72
		return NULL;

R
Rex Zhu 已提交
73
	return (struct smu10_power_state *)hw_ps;
74 75
}

R
Rex Zhu 已提交
76
static int smu10_initialize_dpm_defaults(struct pp_hwmgr *hwmgr)
77
{
R
Rex Zhu 已提交
78
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
79

R
Rex Zhu 已提交
80 81 82 83 84 85 86
	smu10_data->dce_slow_sclk_threshold = 30000;
	smu10_data->thermal_auto_throttling_treshold = 0;
	smu10_data->is_nb_dpm_enabled = 1;
	smu10_data->dpm_flags = 1;
	smu10_data->need_min_deep_sleep_dcefclk = true;
	smu10_data->num_active_display = 0;
	smu10_data->deep_sleep_dcefclk = 0;
87

88 89 90 91 92
	if (hwmgr->feature_mask & PP_GFXOFF_MASK)
		smu10_data->gfx_off_controled_by_driver = true;
	else
		smu10_data->gfx_off_controled_by_driver = false;

93 94 95 96 97 98 99
	phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
					PHM_PlatformCaps_SclkDeepSleep);

	phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
				PHM_PlatformCaps_SclkThrottleLowNotification);

	phm_cap_set(hwmgr->platform_descriptor.platformCaps,
100
				PHM_PlatformCaps_PowerPlaySupport);
101 102 103
	return 0;
}

R
Rex Zhu 已提交
104
static int smu10_construct_max_power_limits_table(struct pp_hwmgr *hwmgr,
105 106 107 108 109
			struct phm_clock_and_voltage_limits *table)
{
	return 0;
}

R
Rex Zhu 已提交
110
static int smu10_init_dynamic_state_adjustment_rule_settings(
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
							struct pp_hwmgr *hwmgr)
{
	uint32_t table_size =
		sizeof(struct phm_clock_voltage_dependency_table) +
		(7 * sizeof(struct phm_clock_voltage_dependency_record));

	struct phm_clock_voltage_dependency_table *table_clk_vlt =
					kzalloc(table_size, GFP_KERNEL);

	if (NULL == table_clk_vlt) {
		pr_err("Can not allocate memory!\n");
		return -ENOMEM;
	}

	table_clk_vlt->count = 8;
	table_clk_vlt->entries[0].clk = PP_DAL_POWERLEVEL_0;
	table_clk_vlt->entries[0].v = 0;
	table_clk_vlt->entries[1].clk = PP_DAL_POWERLEVEL_1;
	table_clk_vlt->entries[1].v = 1;
	table_clk_vlt->entries[2].clk = PP_DAL_POWERLEVEL_2;
	table_clk_vlt->entries[2].v = 2;
	table_clk_vlt->entries[3].clk = PP_DAL_POWERLEVEL_3;
	table_clk_vlt->entries[3].v = 3;
	table_clk_vlt->entries[4].clk = PP_DAL_POWERLEVEL_4;
	table_clk_vlt->entries[4].v = 4;
	table_clk_vlt->entries[5].clk = PP_DAL_POWERLEVEL_5;
	table_clk_vlt->entries[5].v = 5;
	table_clk_vlt->entries[6].clk = PP_DAL_POWERLEVEL_6;
	table_clk_vlt->entries[6].v = 6;
	table_clk_vlt->entries[7].clk = PP_DAL_POWERLEVEL_7;
	table_clk_vlt->entries[7].v = 7;
	hwmgr->dyn_state.vddc_dep_on_dal_pwrl = table_clk_vlt;

	return 0;
}

R
Rex Zhu 已提交
147
static int smu10_get_system_info_data(struct pp_hwmgr *hwmgr)
148
{
R
Rex Zhu 已提交
149
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)hwmgr->backend;
150

R
Rex Zhu 已提交
151 152
	smu10_data->sys_info.htc_hyst_lmt = 5;
	smu10_data->sys_info.htc_tmp_lmt = 203;
153

R
Rex Zhu 已提交
154 155
	if (smu10_data->thermal_auto_throttling_treshold == 0)
		 smu10_data->thermal_auto_throttling_treshold = 203;
156

R
Rex Zhu 已提交
157
	smu10_construct_max_power_limits_table (hwmgr,
158 159
				    &hwmgr->dyn_state.max_clock_voltage_on_ac);

R
Rex Zhu 已提交
160
	smu10_init_dynamic_state_adjustment_rule_settings(hwmgr);
161 162 163 164

	return 0;
}

R
Rex Zhu 已提交
165
static int smu10_construct_boot_state(struct pp_hwmgr *hwmgr)
166 167 168 169
{
	return 0;
}

R
Rex Zhu 已提交
170
static int smu10_set_clock_limit(struct pp_hwmgr *hwmgr, const void *input)
171
{
172 173 174
	struct PP_Clocks clocks = {0};
	struct pp_display_clock_request clock_req;

175
	clocks.dcefClock = hwmgr->display_config->min_dcef_set_clk;
176 177 178
	clock_req.clock_type = amd_pp_dcf_clock;
	clock_req.clock_freq_in_khz = clocks.dcefClock * 10;

R
Rex Zhu 已提交
179
	PP_ASSERT_WITH_CODE(!smu10_display_clock_voltage_request(hwmgr, &clock_req),
180 181
				"Attempt to set DCF Clock Failed!", return -EINVAL);

182 183 184
	return 0;
}

R
Rex Zhu 已提交
185
static int smu10_set_deep_sleep_dcefclk(struct pp_hwmgr *hwmgr, uint32_t clock)
186
{
R
Rex Zhu 已提交
187
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
188

R
Rex Zhu 已提交
189 190
	if (smu10_data->need_min_deep_sleep_dcefclk && smu10_data->deep_sleep_dcefclk != clock/100) {
		smu10_data->deep_sleep_dcefclk = clock/100;
191
		smum_send_msg_to_smc_with_parameter(hwmgr,
192
					PPSMC_MSG_SetMinDeepSleepDcefclk,
R
Rex Zhu 已提交
193
					smu10_data->deep_sleep_dcefclk);
194 195 196 197
	}
	return 0;
}

R
Rex Zhu 已提交
198
static int smu10_set_active_display_count(struct pp_hwmgr *hwmgr, uint32_t count)
199
{
R
Rex Zhu 已提交
200
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
201

R
Rex Zhu 已提交
202 203
	if (smu10_data->num_active_display != count) {
		smu10_data->num_active_display = count;
204
		smum_send_msg_to_smc_with_parameter(hwmgr,
205
				PPSMC_MSG_SetDisplayCount,
R
Rex Zhu 已提交
206
				smu10_data->num_active_display);
207
	}
208

209 210 211
	return 0;
}

R
Rex Zhu 已提交
212
static int smu10_set_power_state_tasks(struct pp_hwmgr *hwmgr, const void *input)
213
{
R
Rex Zhu 已提交
214
	return smu10_set_clock_limit(hwmgr, input);
215
}
216

R
Rex Zhu 已提交
217
static int smu10_init_power_gate_state(struct pp_hwmgr *hwmgr)
218
{
R
Rex Zhu 已提交
219
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
220
	struct amdgpu_device *adev = hwmgr->adev;
221

R
Rex Zhu 已提交
222 223 224
	smu10_data->vcn_power_gated = true;
	smu10_data->isp_tileA_power_gated = true;
	smu10_data->isp_tileB_power_gated = true;
225

226 227 228 229 230 231
	if (adev->pg_flags & AMD_PG_SUPPORT_GFX_PG)
		return smum_send_msg_to_smc_with_parameter(hwmgr,
							   PPSMC_MSG_SetGfxCGPG,
							   true);
	else
		return 0;
232 233 234
}


R
Rex Zhu 已提交
235
static int smu10_setup_asic_task(struct pp_hwmgr *hwmgr)
236
{
R
Rex Zhu 已提交
237
	return smu10_init_power_gate_state(hwmgr);
238
}
239

R
Rex Zhu 已提交
240
static int smu10_reset_cc6_data(struct pp_hwmgr *hwmgr)
241
{
R
Rex Zhu 已提交
242
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
243

R
Rex Zhu 已提交
244 245 246 247
	smu10_data->separation_time = 0;
	smu10_data->cc6_disable = false;
	smu10_data->pstate_disable = false;
	smu10_data->cc6_setting_changed = false;
248 249 250 251

	return 0;
}

R
Rex Zhu 已提交
252
static int smu10_power_off_asic(struct pp_hwmgr *hwmgr)
253
{
R
Rex Zhu 已提交
254
	return smu10_reset_cc6_data(hwmgr);
255
}
256

257 258 259 260 261 262 263 264 265 266 267 268 269
static bool smu10_is_gfx_on(struct pp_hwmgr *hwmgr)
{
	uint32_t reg;
	struct amdgpu_device *adev = hwmgr->adev;

	reg = RREG32_SOC15(PWR, 0, mmPWR_MISC_CNTL_STATUS);
	if ((reg & PWR_MISC_CNTL_STATUS__PWR_GFXOFF_STATUS_MASK) ==
	    (0x2 << PWR_MISC_CNTL_STATUS__PWR_GFXOFF_STATUS__SHIFT))
		return true;

	return false;
}

R
Rex Zhu 已提交
270
static int smu10_disable_gfx_off(struct pp_hwmgr *hwmgr)
271
{
R
Rex Zhu 已提交
272
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
273

274
	if (smu10_data->gfx_off_controled_by_driver) {
275
		smum_send_msg_to_smc(hwmgr, PPSMC_MSG_DisableGfxOff);
276

277 278 279 280 281
		/* confirm gfx is back to "on" state */
		while (!smu10_is_gfx_on(hwmgr))
			msleep(1);
	}

282 283 284
	return 0;
}

R
Rex Zhu 已提交
285
static int smu10_disable_dpm_tasks(struct pp_hwmgr *hwmgr)
286
{
R
Rex Zhu 已提交
287
	return smu10_disable_gfx_off(hwmgr);
288
}
289

R
Rex Zhu 已提交
290
static int smu10_enable_gfx_off(struct pp_hwmgr *hwmgr)
291
{
R
Rex Zhu 已提交
292
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
293

R
Rex Zhu 已提交
294
	if (smu10_data->gfx_off_controled_by_driver)
295
		smum_send_msg_to_smc(hwmgr, PPSMC_MSG_EnableGfxOff);
296 297 298 299

	return 0;
}

R
Rex Zhu 已提交
300
static int smu10_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
301
{
R
Rex Zhu 已提交
302
	return smu10_enable_gfx_off(hwmgr);
303
}
304

305 306 307 308 309 310 311 312
static int smu10_gfx_off_control(struct pp_hwmgr *hwmgr, bool enable)
{
	if (enable)
		return smu10_enable_gfx_off(hwmgr);
	else
		return smu10_disable_gfx_off(hwmgr);
}

R
Rex Zhu 已提交
313
static int smu10_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
314 315 316 317 318 319 320
				struct pp_power_state  *prequest_ps,
			const struct pp_power_state *pcurrent_ps)
{
	return 0;
}

/* temporary hardcoded clock voltage breakdown tables */
321
static const DpmClock_t VddDcfClk[]= {
322 323 324 325 326
	{ 300, 2600},
	{ 600, 3200},
	{ 600, 3600},
};

327
static const DpmClock_t VddSocClk[]= {
328 329 330 331 332
	{ 478, 2600},
	{ 722, 3200},
	{ 722, 3600},
};

333
static const DpmClock_t VddFClk[]= {
334 335 336 337 338
	{ 400, 2600},
	{1200, 3200},
	{1200, 3600},
};

339
static const DpmClock_t VddDispClk[]= {
340 341 342 343 344
	{ 435, 2600},
	{ 661, 3200},
	{1086, 3600},
};

345
static const DpmClock_t VddDppClk[]= {
346 347 348 349 350
	{ 435, 2600},
	{ 661, 3200},
	{ 661, 3600},
};

351
static const DpmClock_t VddPhyClk[]= {
352 353 354 355 356
	{ 540, 2600},
	{ 810, 3200},
	{ 810, 3600},
};

R
Rex Zhu 已提交
357 358
static int smu10_get_clock_voltage_dependency_table(struct pp_hwmgr *hwmgr,
			struct smu10_voltage_dependency_table **pptable,
359
			uint32_t num_entry, const DpmClock_t *pclk_dependency_table)
360 361
{
	uint32_t table_size, i;
R
Rex Zhu 已提交
362
	struct smu10_voltage_dependency_table *ptable;
363

R
Rex Zhu 已提交
364
	table_size = sizeof(uint32_t) + sizeof(struct smu10_voltage_dependency_table) * num_entry;
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
	ptable = kzalloc(table_size, GFP_KERNEL);

	if (NULL == ptable)
		return -ENOMEM;

	ptable->count = num_entry;

	for (i = 0; i < ptable->count; i++) {
		ptable->entries[i].clk         = pclk_dependency_table->Freq * 100;
		ptable->entries[i].vol         = pclk_dependency_table->Vol;
		pclk_dependency_table++;
	}

	*pptable = ptable;

	return 0;
}


R
Rex Zhu 已提交
384
static int smu10_populate_clock_table(struct pp_hwmgr *hwmgr)
385 386 387
{
	int result;

R
Rex Zhu 已提交
388 389 390
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
	DpmClocks_t  *table = &(smu10_data->clock_table);
	struct smu10_clock_voltage_information *pinfo = &(smu10_data->clock_vol_info);
391

392
	result = smum_smc_table_manager(hwmgr, (uint8_t *)table, SMU10_CLOCKTABLE, true);
393 394 395 396 397 398

	PP_ASSERT_WITH_CODE((0 == result),
			"Attempt to copy clock table from smc failed",
			return result);

	if (0 == result && table->DcefClocks[0].Freq != 0) {
R
Rex Zhu 已提交
399
		smu10_get_clock_voltage_dependency_table(hwmgr, &pinfo->vdd_dep_on_dcefclk,
400
						NUM_DCEFCLK_DPM_LEVELS,
R
Rex Zhu 已提交
401 402
						&smu10_data->clock_table.DcefClocks[0]);
		smu10_get_clock_voltage_dependency_table(hwmgr, &pinfo->vdd_dep_on_socclk,
403
						NUM_SOCCLK_DPM_LEVELS,
R
Rex Zhu 已提交
404 405
						&smu10_data->clock_table.SocClocks[0]);
		smu10_get_clock_voltage_dependency_table(hwmgr, &pinfo->vdd_dep_on_fclk,
406
						NUM_FCLK_DPM_LEVELS,
R
Rex Zhu 已提交
407 408
						&smu10_data->clock_table.FClocks[0]);
		smu10_get_clock_voltage_dependency_table(hwmgr, &pinfo->vdd_dep_on_mclk,
409
						NUM_MEMCLK_DPM_LEVELS,
R
Rex Zhu 已提交
410
						&smu10_data->clock_table.MemClocks[0]);
411
	} else {
R
Rex Zhu 已提交
412
		smu10_get_clock_voltage_dependency_table(hwmgr, &pinfo->vdd_dep_on_dcefclk,
413 414
						ARRAY_SIZE(VddDcfClk),
						&VddDcfClk[0]);
R
Rex Zhu 已提交
415
		smu10_get_clock_voltage_dependency_table(hwmgr, &pinfo->vdd_dep_on_socclk,
416 417
						ARRAY_SIZE(VddSocClk),
						&VddSocClk[0]);
R
Rex Zhu 已提交
418
		smu10_get_clock_voltage_dependency_table(hwmgr, &pinfo->vdd_dep_on_fclk,
419 420
						ARRAY_SIZE(VddFClk),
						&VddFClk[0]);
421
	}
R
Rex Zhu 已提交
422
	smu10_get_clock_voltage_dependency_table(hwmgr, &pinfo->vdd_dep_on_dispclk,
423 424
					ARRAY_SIZE(VddDispClk),
					&VddDispClk[0]);
R
Rex Zhu 已提交
425
	smu10_get_clock_voltage_dependency_table(hwmgr, &pinfo->vdd_dep_on_dppclk,
426
					ARRAY_SIZE(VddDppClk), &VddDppClk[0]);
R
Rex Zhu 已提交
427
	smu10_get_clock_voltage_dependency_table(hwmgr, &pinfo->vdd_dep_on_phyclk,
428
					ARRAY_SIZE(VddPhyClk), &VddPhyClk[0]);
429

430
	smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetMinGfxclkFrequency);
431
	result = smum_get_argument(hwmgr);
R
Rex Zhu 已提交
432
	smu10_data->gfx_min_freq_limit = result * 100;
433

434
	smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetMaxGfxclkFrequency);
435
	result = smum_get_argument(hwmgr);
R
Rex Zhu 已提交
436
	smu10_data->gfx_max_freq_limit = result * 100;
437

438 439 440
	return 0;
}

R
Rex Zhu 已提交
441
static int smu10_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
442 443
{
	int result = 0;
R
Rex Zhu 已提交
444
	struct smu10_hwmgr *data;
445

R
Rex Zhu 已提交
446
	data = kzalloc(sizeof(struct smu10_hwmgr), GFP_KERNEL);
447 448 449 450 451
	if (data == NULL)
		return -ENOMEM;

	hwmgr->backend = data;

R
Rex Zhu 已提交
452
	result = smu10_initialize_dpm_defaults(hwmgr);
453
	if (result != 0) {
R
Rex Zhu 已提交
454
		pr_err("smu10_initialize_dpm_defaults failed\n");
455 456 457
		return result;
	}

R
Rex Zhu 已提交
458
	smu10_populate_clock_table(hwmgr);
459

R
Rex Zhu 已提交
460
	result = smu10_get_system_info_data(hwmgr);
461
	if (result != 0) {
R
Rex Zhu 已提交
462
		pr_err("smu10_get_system_info_data failed\n");
463 464 465
		return result;
	}

R
Rex Zhu 已提交
466
	smu10_construct_boot_state(hwmgr);
467 468

	hwmgr->platform_descriptor.hardwareActivityPerformanceLevels =
R
Rex Zhu 已提交
469
						SMU10_MAX_HARDWARE_POWERLEVELS;
470 471

	hwmgr->platform_descriptor.hardwarePerformanceLevels =
R
Rex Zhu 已提交
472
						SMU10_MAX_HARDWARE_POWERLEVELS;
473 474 475 476 477 478 479 480 481

	hwmgr->platform_descriptor.vbiosInterruptId = 0;

	hwmgr->platform_descriptor.clockStep.engineClock = 500;

	hwmgr->platform_descriptor.clockStep.memoryClock = 500;

	hwmgr->platform_descriptor.minimumClocksReductionPercentage = 50;

R
Rex Zhu 已提交
482 483
	hwmgr->pstate_sclk = SMU10_UMD_PSTATE_GFXCLK;
	hwmgr->pstate_mclk = SMU10_UMD_PSTATE_FCLK;
R
Rex Zhu 已提交
484

485 486 487
	return result;
}

R
Rex Zhu 已提交
488
static int smu10_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)
489
{
R
Rex Zhu 已提交
490 491
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
	struct smu10_clock_voltage_information *pinfo = &(smu10_data->clock_vol_info);
492

493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
	kfree(pinfo->vdd_dep_on_dcefclk);
	pinfo->vdd_dep_on_dcefclk = NULL;
	kfree(pinfo->vdd_dep_on_socclk);
	pinfo->vdd_dep_on_socclk = NULL;
	kfree(pinfo->vdd_dep_on_fclk);
	pinfo->vdd_dep_on_fclk = NULL;
	kfree(pinfo->vdd_dep_on_dispclk);
	pinfo->vdd_dep_on_dispclk = NULL;
	kfree(pinfo->vdd_dep_on_dppclk);
	pinfo->vdd_dep_on_dppclk = NULL;
	kfree(pinfo->vdd_dep_on_phyclk);
	pinfo->vdd_dep_on_phyclk = NULL;

	kfree(hwmgr->dyn_state.vddc_dep_on_dal_pwrl);
	hwmgr->dyn_state.vddc_dep_on_dal_pwrl = NULL;
508

509 510 511 512 513 514
	kfree(hwmgr->backend);
	hwmgr->backend = NULL;

	return 0;
}

R
Rex Zhu 已提交
515
static int smu10_dpm_force_dpm_level(struct pp_hwmgr *hwmgr,
516 517
				enum amd_dpm_forced_level level)
{
518 519 520 521 522 523 524 525 526 527
	if (hwmgr->smu_version < 0x1E3700) {
		pr_info("smu firmware version too old, can not set dpm level\n");
		return 0;
	}

	switch (level) {
	case AMD_DPM_FORCED_LEVEL_HIGH:
	case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinGfxClk,
R
Rex Zhu 已提交
528
						SMU10_UMD_PSTATE_PEAK_GFXCLK);
529 530
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinFclkByFreq,
R
Rex Zhu 已提交
531
						SMU10_UMD_PSTATE_PEAK_FCLK);
532 533
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinSocclkByFreq,
R
Rex Zhu 已提交
534
						SMU10_UMD_PSTATE_PEAK_SOCCLK);
535 536
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinVcn,
R
Rex Zhu 已提交
537
						SMU10_UMD_PSTATE_VCE);
538 539 540

		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxGfxClk,
R
Rex Zhu 已提交
541
						SMU10_UMD_PSTATE_PEAK_GFXCLK);
542 543
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxFclkByFreq,
R
Rex Zhu 已提交
544
						SMU10_UMD_PSTATE_PEAK_FCLK);
545 546
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxSocclkByFreq,
R
Rex Zhu 已提交
547
						SMU10_UMD_PSTATE_PEAK_SOCCLK);
548 549
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxVcn,
R
Rex Zhu 已提交
550
						SMU10_UMD_PSTATE_VCE);
551 552 553 554
		break;
	case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinGfxClk,
R
Rex Zhu 已提交
555
						SMU10_UMD_PSTATE_MIN_GFXCLK);
556 557
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxGfxClk,
R
Rex Zhu 已提交
558
						SMU10_UMD_PSTATE_MIN_GFXCLK);
559 560 561 562
		break;
	case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinFclkByFreq,
R
Rex Zhu 已提交
563
						SMU10_UMD_PSTATE_MIN_FCLK);
564 565
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxFclkByFreq,
R
Rex Zhu 已提交
566
						SMU10_UMD_PSTATE_MIN_FCLK);
567 568 569 570
		break;
	case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinGfxClk,
R
Rex Zhu 已提交
571
						SMU10_UMD_PSTATE_GFXCLK);
572 573
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinFclkByFreq,
R
Rex Zhu 已提交
574
						SMU10_UMD_PSTATE_FCLK);
575 576
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinSocclkByFreq,
R
Rex Zhu 已提交
577
						SMU10_UMD_PSTATE_SOCCLK);
578 579
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinVcn,
R
Rex Zhu 已提交
580
						SMU10_UMD_PSTATE_VCE);
581 582 583

		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxGfxClk,
R
Rex Zhu 已提交
584
						SMU10_UMD_PSTATE_GFXCLK);
585 586
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxFclkByFreq,
R
Rex Zhu 已提交
587
						SMU10_UMD_PSTATE_FCLK);
588 589
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxSocclkByFreq,
R
Rex Zhu 已提交
590
						SMU10_UMD_PSTATE_SOCCLK);
591 592
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxVcn,
R
Rex Zhu 已提交
593
						SMU10_UMD_PSTATE_VCE);
594 595 596 597
		break;
	case AMD_DPM_FORCED_LEVEL_AUTO:
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinGfxClk,
R
Rex Zhu 已提交
598
						SMU10_UMD_PSTATE_MIN_GFXCLK);
599 600
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinFclkByFreq,
R
Rex Zhu 已提交
601
						SMU10_UMD_PSTATE_MIN_FCLK);
602 603
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinSocclkByFreq,
R
Rex Zhu 已提交
604
						SMU10_UMD_PSTATE_MIN_SOCCLK);
605 606
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinVcn,
R
Rex Zhu 已提交
607
						SMU10_UMD_PSTATE_MIN_VCE);
608 609 610

		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxGfxClk,
R
Rex Zhu 已提交
611
						SMU10_UMD_PSTATE_PEAK_GFXCLK);
612 613
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxFclkByFreq,
R
Rex Zhu 已提交
614
						SMU10_UMD_PSTATE_PEAK_FCLK);
615 616
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxSocclkByFreq,
R
Rex Zhu 已提交
617
						SMU10_UMD_PSTATE_PEAK_SOCCLK);
618 619
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxVcn,
R
Rex Zhu 已提交
620
						SMU10_UMD_PSTATE_VCE);
621 622 623 624
		break;
	case AMD_DPM_FORCED_LEVEL_LOW:
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinGfxClk,
R
Rex Zhu 已提交
625
						SMU10_UMD_PSTATE_MIN_GFXCLK);
626 627
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxGfxClk,
R
Rex Zhu 已提交
628
						SMU10_UMD_PSTATE_MIN_GFXCLK);
629 630
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinFclkByFreq,
R
Rex Zhu 已提交
631
						SMU10_UMD_PSTATE_MIN_FCLK);
632 633
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxFclkByFreq,
R
Rex Zhu 已提交
634
						SMU10_UMD_PSTATE_MIN_FCLK);
635 636 637 638 639 640
		break;
	case AMD_DPM_FORCED_LEVEL_MANUAL:
	case AMD_DPM_FORCED_LEVEL_PROFILE_EXIT:
	default:
		break;
	}
641 642 643
	return 0;
}

R
Rex Zhu 已提交
644
static uint32_t smu10_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)
645
{
R
Rex Zhu 已提交
646
	struct smu10_hwmgr *data;
647 648 649 650

	if (hwmgr == NULL)
		return -EINVAL;

R
Rex Zhu 已提交
651
	data = (struct smu10_hwmgr *)(hwmgr->backend);
652 653 654 655 656 657

	if (low)
		return data->clock_vol_info.vdd_dep_on_fclk->entries[0].clk;
	else
		return data->clock_vol_info.vdd_dep_on_fclk->entries[
			data->clock_vol_info.vdd_dep_on_fclk->count - 1].clk;
658 659
}

R
Rex Zhu 已提交
660
static uint32_t smu10_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)
661
{
R
Rex Zhu 已提交
662
	struct smu10_hwmgr *data;
663 664 665 666

	if (hwmgr == NULL)
		return -EINVAL;

R
Rex Zhu 已提交
667
	data = (struct smu10_hwmgr *)(hwmgr->backend);
668 669 670 671 672

	if (low)
		return data->gfx_min_freq_limit;
	else
		return data->gfx_max_freq_limit;
673 674
}

R
Rex Zhu 已提交
675
static int smu10_dpm_patch_boot_state(struct pp_hwmgr *hwmgr,
676 677 678 679 680
					struct pp_hw_power_state *hw_ps)
{
	return 0;
}

R
Rex Zhu 已提交
681
static int smu10_dpm_get_pp_table_entry_callback(
682 683 684 685 686
						     struct pp_hwmgr *hwmgr,
					   struct pp_hw_power_state *hw_ps,
							  unsigned int index,
						     const void *clock_info)
{
R
Rex Zhu 已提交
687
	struct smu10_power_state *smu10_ps = cast_smu10_ps(hw_ps);
688

R
Rex Zhu 已提交
689
	smu10_ps->levels[index].engine_clock = 0;
690

R
Rex Zhu 已提交
691 692
	smu10_ps->levels[index].vddc_index = 0;
	smu10_ps->level = index + 1;
693 694

	if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep)) {
R
Rex Zhu 已提交
695 696
		smu10_ps->levels[index].ds_divider_index = 5;
		smu10_ps->levels[index].ss_divider_index = 5;
697 698 699 700 701
	}

	return 0;
}

R
Rex Zhu 已提交
702
static int smu10_dpm_get_num_of_pp_table_entries(struct pp_hwmgr *hwmgr)
703 704 705 706 707 708 709 710 711
{
	int result;
	unsigned long ret = 0;

	result = pp_tables_get_num_of_entries(hwmgr, &ret);

	return result ? 0 : ret;
}

R
Rex Zhu 已提交
712
static int smu10_dpm_get_pp_table_entry(struct pp_hwmgr *hwmgr,
713 714 715
		    unsigned long entry, struct pp_power_state *ps)
{
	int result;
R
Rex Zhu 已提交
716
	struct smu10_power_state *smu10_ps;
717

R
Rex Zhu 已提交
718
	ps->hardware.magic = SMU10_Magic;
719

R
Rex Zhu 已提交
720
	smu10_ps = cast_smu10_ps(&(ps->hardware));
721 722

	result = pp_tables_get_entry(hwmgr, entry, ps,
R
Rex Zhu 已提交
723
			smu10_dpm_get_pp_table_entry_callback);
724

R
Rex Zhu 已提交
725 726
	smu10_ps->uvd_clocks.vclk = ps->uvd_clocks.VCLK;
	smu10_ps->uvd_clocks.dclk = ps->uvd_clocks.DCLK;
727 728 729 730

	return result;
}

R
Rex Zhu 已提交
731
static int smu10_get_power_state_size(struct pp_hwmgr *hwmgr)
732
{
R
Rex Zhu 已提交
733
	return sizeof(struct smu10_power_state);
734 735
}

R
Rex Zhu 已提交
736
static int smu10_set_cpu_power_state(struct pp_hwmgr *hwmgr)
737 738 739 740 741
{
	return 0;
}


R
Rex Zhu 已提交
742
static int smu10_store_cc6_data(struct pp_hwmgr *hwmgr, uint32_t separation_time,
743 744
			bool cc6_disable, bool pstate_disable, bool pstate_switch_disable)
{
745 746 747 748 749 750 751 752 753 754
	struct smu10_hwmgr *data = (struct smu10_hwmgr *)(hwmgr->backend);

	if (separation_time != data->separation_time ||
			cc6_disable != data->cc6_disable ||
			pstate_disable != data->pstate_disable) {
		data->separation_time = separation_time;
		data->cc6_disable = cc6_disable;
		data->pstate_disable = pstate_disable;
		data->cc6_setting_changed = true;
	}
755 756 757
	return 0;
}

R
Rex Zhu 已提交
758
static int smu10_get_dal_power_level(struct pp_hwmgr *hwmgr,
759 760 761 762 763
		struct amd_pp_simple_clock_info *info)
{
	return -EINVAL;
}

R
Rex Zhu 已提交
764
static int smu10_force_clock_level(struct pp_hwmgr *hwmgr,
765 766 767 768 769
		enum pp_clock_type type, uint32_t mask)
{
	return 0;
}

R
Rex Zhu 已提交
770
static int smu10_print_clock_levels(struct pp_hwmgr *hwmgr,
771 772
		enum pp_clock_type type, char *buf)
{
R
Rex Zhu 已提交
773 774
	struct smu10_hwmgr *data = (struct smu10_hwmgr *)(hwmgr->backend);
	struct smu10_voltage_dependency_table *mclk_table =
775 776 777 778 779
			data->clock_vol_info.vdd_dep_on_fclk;
	int i, now, size = 0;

	switch (type) {
	case PP_SCLK:
780
		smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetGfxclkFrequency);
781
		now = smum_get_argument(hwmgr);
782 783 784 785 786 787 788 789 790 791 792

		size += sprintf(buf + size, "0: %uMhz %s\n",
				data->gfx_min_freq_limit / 100,
				((data->gfx_min_freq_limit / 100)
				 == now) ? "*" : "");
		size += sprintf(buf + size, "1: %uMhz %s\n",
				data->gfx_max_freq_limit / 100,
				((data->gfx_max_freq_limit / 100)
				 == now) ? "*" : "");
		break;
	case PP_MCLK:
793
		smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetFclkFrequency);
794
		now = smum_get_argument(hwmgr);
795 796 797 798 799 800 801 802 803 804 805 806 807

		for (i = 0; i < mclk_table->count; i++)
			size += sprintf(buf + size, "%d: %uMhz %s\n",
					i,
					mclk_table->entries[i].clk / 100,
					((mclk_table->entries[i].clk / 100)
					 == now) ? "*" : "");
		break;
	default:
		break;
	}

	return size;
808 809
}

R
Rex Zhu 已提交
810
static int smu10_get_performance_level(struct pp_hwmgr *hwmgr, const struct pp_hw_power_state *state,
811 812 813
				PHM_PerformanceLevelDesignation designation, uint32_t index,
				PHM_PerformanceLevel *level)
{
R
Rex Zhu 已提交
814
	struct smu10_hwmgr *data;
815 816 817 818

	if (level == NULL || hwmgr == NULL || state == NULL)
		return -EINVAL;

R
Rex Zhu 已提交
819
	data = (struct smu10_hwmgr *)(hwmgr->backend);
820

821
	if (index == 0) {
822
		level->memory_clock = data->clock_vol_info.vdd_dep_on_fclk->entries[0].clk;
823 824 825 826 827
		level->coreClock = data->gfx_min_freq_limit;
	} else {
		level->memory_clock = data->clock_vol_info.vdd_dep_on_fclk->entries[
			data->clock_vol_info.vdd_dep_on_fclk->count - 1].clk;
		level->coreClock = data->gfx_max_freq_limit;
828
	}
829

830 831 832 833 834 835
	level->nonLocalMemoryFreq = 0;
	level->nonLocalMemoryWidth = 0;

	return 0;
}

R
Rex Zhu 已提交
836
static int smu10_get_current_shallow_sleep_clocks(struct pp_hwmgr *hwmgr,
837 838
	const struct pp_hw_power_state *state, struct pp_clock_info *clock_info)
{
R
Rex Zhu 已提交
839
	const struct smu10_power_state *ps = cast_const_smu10_ps(state);
840 841 842 843 844 845 846 847 848 849 850 851 852 853

	clock_info->min_eng_clk = ps->levels[0].engine_clock / (1 << (ps->levels[0].ss_divider_index));
	clock_info->max_eng_clk = ps->levels[ps->level - 1].engine_clock / (1 << (ps->levels[ps->level - 1].ss_divider_index));

	return 0;
}

#define MEM_FREQ_LOW_LATENCY        25000
#define MEM_FREQ_HIGH_LATENCY       80000
#define MEM_LATENCY_HIGH            245
#define MEM_LATENCY_LOW             35
#define MEM_LATENCY_ERR             0xFFFF


R
Rex Zhu 已提交
854
static uint32_t smu10_get_mem_latency(struct pp_hwmgr *hwmgr,
855 856 857 858 859 860 861 862 863 864 865
		uint32_t clock)
{
	if (clock >= MEM_FREQ_LOW_LATENCY &&
			clock < MEM_FREQ_HIGH_LATENCY)
		return MEM_LATENCY_HIGH;
	else if (clock >= MEM_FREQ_HIGH_LATENCY)
		return MEM_LATENCY_LOW;
	else
		return MEM_LATENCY_ERR;
}

R
Rex Zhu 已提交
866
static int smu10_get_clock_by_type_with_latency(struct pp_hwmgr *hwmgr,
867
		enum amd_pp_clock_type type,
868 869 870
		struct pp_clock_levels_with_latency *clocks)
{
	uint32_t i;
R
Rex Zhu 已提交
871 872 873
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
	struct smu10_clock_voltage_information *pinfo = &(smu10_data->clock_vol_info);
	struct smu10_voltage_dependency_table *pclk_vol_table;
874
	bool latency_required = false;
875

876 877
	if (pinfo == NULL)
		return -EINVAL;
878 879 880

	switch (type) {
	case amd_pp_mem_clock:
881 882
		pclk_vol_table = pinfo->vdd_dep_on_mclk;
		latency_required = true;
883
		break;
884 885 886
	case amd_pp_f_clock:
		pclk_vol_table = pinfo->vdd_dep_on_fclk;
		latency_required = true;
887
		break;
888 889
	case amd_pp_dcf_clock:
		pclk_vol_table = pinfo->vdd_dep_on_dcefclk;
890
		break;
891 892 893 894 895 896 897 898
	case amd_pp_disp_clock:
		pclk_vol_table = pinfo->vdd_dep_on_dispclk;
		break;
	case amd_pp_phy_clock:
		pclk_vol_table = pinfo->vdd_dep_on_phyclk;
		break;
	case amd_pp_dpp_clock:
		pclk_vol_table = pinfo->vdd_dep_on_dppclk;
899
	default:
900 901 902 903 904 905 906 907 908 909
		return -EINVAL;
	}

	if (pclk_vol_table == NULL || pclk_vol_table->count == 0)
		return -EINVAL;

	clocks->num_levels = 0;
	for (i = 0; i < pclk_vol_table->count; i++) {
		clocks->data[i].clocks_in_khz = pclk_vol_table->entries[i].clk;
		clocks->data[i].latency_in_us = latency_required ?
R
Rex Zhu 已提交
910
						smu10_get_mem_latency(hwmgr,
911 912 913
						pclk_vol_table->entries[i].clk) :
						0;
		clocks->num_levels++;
914 915 916 917 918
	}

	return 0;
}

R
Rex Zhu 已提交
919
static int smu10_get_clock_by_type_with_voltage(struct pp_hwmgr *hwmgr,
920 921 922 923
		enum amd_pp_clock_type type,
		struct pp_clock_levels_with_voltage *clocks)
{
	uint32_t i;
R
Rex Zhu 已提交
924 925 926
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
	struct smu10_clock_voltage_information *pinfo = &(smu10_data->clock_vol_info);
	struct smu10_voltage_dependency_table *pclk_vol_table = NULL;
927 928 929

	if (pinfo == NULL)
		return -EINVAL;
930 931 932 933 934

	switch (type) {
	case amd_pp_mem_clock:
		pclk_vol_table = pinfo->vdd_dep_on_mclk;
		break;
935 936
	case amd_pp_f_clock:
		pclk_vol_table = pinfo->vdd_dep_on_fclk;
937
		break;
938 939
	case amd_pp_dcf_clock:
		pclk_vol_table = pinfo->vdd_dep_on_dcefclk;
940
		break;
941 942
	case amd_pp_soc_clock:
		pclk_vol_table = pinfo->vdd_dep_on_socclk;
943 944 945 946 947
		break;
	default:
		return -EINVAL;
	}

948
	if (pclk_vol_table == NULL || pclk_vol_table->count == 0)
949 950
		return -EINVAL;

951
	clocks->num_levels = 0;
952 953 954 955 956 957 958 959 960
	for (i = 0; i < pclk_vol_table->count; i++) {
		clocks->data[i].clocks_in_khz = pclk_vol_table->entries[i].clk;
		clocks->data[i].voltage_in_mv = pclk_vol_table->entries[i].vol;
		clocks->num_levels++;
	}

	return 0;
}

R
Rex Zhu 已提交
961
static int smu10_display_clock_voltage_request(struct pp_hwmgr *hwmgr,
962 963
		struct pp_display_clock_request *clock_req)
{
R
Rex Zhu 已提交
964
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
965
	enum amd_pp_clock_type clk_type = clock_req->clock_type;
966
	uint32_t clk_freq = clock_req->clock_freq_in_khz / 1000;
967 968 969
	PPSMC_Msg        msg;

	switch (clk_type) {
970
	case amd_pp_dcf_clock:
R
Rex Zhu 已提交
971
		if (clk_freq == smu10_data->dcf_actual_hard_min_freq)
972
			return 0;
973
		msg =  PPSMC_MSG_SetHardMinDcefclkByFreq;
R
Rex Zhu 已提交
974
		smu10_data->dcf_actual_hard_min_freq = clk_freq;
975 976 977 978
		break;
	case amd_pp_soc_clock:
		 msg = PPSMC_MSG_SetHardMinSocclkByFreq;
		break;
979
	case amd_pp_f_clock:
R
Rex Zhu 已提交
980
		if (clk_freq == smu10_data->f_actual_hard_min_freq)
981
			return 0;
R
Rex Zhu 已提交
982
		smu10_data->f_actual_hard_min_freq = clk_freq;
983 984 985 986 987 988 989
		msg = PPSMC_MSG_SetHardMinFclkByFreq;
		break;
	default:
		pr_info("[DisplayClockVoltageRequest]Invalid Clock Type!");
		return -EINVAL;
	}

990
	smum_send_msg_to_smc_with_parameter(hwmgr, msg, clk_freq);
991

992
	return 0;
993 994
}

R
Rex Zhu 已提交
995
static int smu10_get_max_high_clocks(struct pp_hwmgr *hwmgr, struct amd_pp_simple_clock_info *clocks)
996
{
997 998
	clocks->engine_max_clock = 80000; /* driver can't get engine clock, temp hard code to 800MHz */
	return 0;
999 1000
}

R
Rex Zhu 已提交
1001
static int smu10_thermal_get_temperature(struct pp_hwmgr *hwmgr)
1002
{
1003 1004
	struct amdgpu_device *adev = hwmgr->adev;
	uint32_t reg_value = RREG32_SOC15(THM, 0, mmTHM_TCON_CUR_TMP);
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
	int cur_temp =
		(reg_value & THM_TCON_CUR_TMP__CUR_TEMP_MASK) >> THM_TCON_CUR_TMP__CUR_TEMP__SHIFT;

	if (cur_temp & THM_TCON_CUR_TMP__CUR_TEMP_RANGE_SEL_MASK)
		cur_temp = ((cur_temp / 8) - 49) * PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
	else
		cur_temp = (cur_temp / 8) * PP_TEMPERATURE_UNITS_PER_CENTIGRADES;

	return cur_temp;
}

R
Rex Zhu 已提交
1016
static int smu10_read_sensor(struct pp_hwmgr *hwmgr, int idx,
1017 1018
			  void *value, int *size)
{
1019 1020 1021
	uint32_t sclk, mclk;
	int ret = 0;

1022
	switch (idx) {
1023
	case AMDGPU_PP_SENSOR_GFX_SCLK:
1024
		smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetGfxclkFrequency);
1025
		sclk = smum_get_argument(hwmgr);
1026
			/* in units of 10KHZ */
1027 1028
		*((uint32_t *)value) = sclk * 100;
		*size = 4;
1029 1030
		break;
	case AMDGPU_PP_SENSOR_GFX_MCLK:
1031
		smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetFclkFrequency);
1032
		mclk = smum_get_argument(hwmgr);
1033
			/* in units of 10KHZ */
1034 1035
		*((uint32_t *)value) = mclk * 100;
		*size = 4;
1036
		break;
1037
	case AMDGPU_PP_SENSOR_GPU_TEMP:
R
Rex Zhu 已提交
1038
		*((uint32_t *)value) = smu10_thermal_get_temperature(hwmgr);
1039
		break;
1040
	default:
1041 1042
		ret = -EINVAL;
		break;
1043
	}
1044 1045

	return ret;
1046 1047
}

1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059
static int smu10_set_watermarks_for_clocks_ranges(struct pp_hwmgr *hwmgr,
		struct pp_wm_sets_with_clock_ranges_soc15 *wm_with_clock_ranges)
{
	struct smu10_hwmgr *data = hwmgr->backend;
	Watermarks_t *table = &(data->water_marks_table);
	int result = 0;

	smu_set_watermarks_for_clocks_ranges(table,wm_with_clock_ranges);
	smum_smc_table_manager(hwmgr, (uint8_t *)table, (uint16_t)SMU10_WMTABLE, false);
	data->water_marks_exist = true;
	return result;
}
R
Rex Zhu 已提交
1060
static int smu10_set_mmhub_powergating_by_smu(struct pp_hwmgr *hwmgr)
1061 1062 1063 1064
{
	return smum_send_msg_to_smc(hwmgr, PPSMC_MSG_PowerGateMmHub);
}

R
Rex Zhu 已提交
1065 1066 1067
static const struct pp_hwmgr_func smu10_hwmgr_funcs = {
	.backend_init = smu10_hwmgr_backend_init,
	.backend_fini = smu10_hwmgr_backend_fini,
1068
	.asic_setup = NULL,
R
Rex Zhu 已提交
1069 1070 1071
	.apply_state_adjust_rules = smu10_apply_state_adjust_rules,
	.force_dpm_level = smu10_dpm_force_dpm_level,
	.get_power_state_size = smu10_get_power_state_size,
1072 1073 1074
	.powerdown_uvd = NULL,
	.powergate_uvd = NULL,
	.powergate_vce = NULL,
R
Rex Zhu 已提交
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
	.get_mclk = smu10_dpm_get_mclk,
	.get_sclk = smu10_dpm_get_sclk,
	.patch_boot_state = smu10_dpm_patch_boot_state,
	.get_pp_table_entry = smu10_dpm_get_pp_table_entry,
	.get_num_of_pp_table_entries = smu10_dpm_get_num_of_pp_table_entries,
	.set_cpu_power_state = smu10_set_cpu_power_state,
	.store_cc6_data = smu10_store_cc6_data,
	.force_clock_level = smu10_force_clock_level,
	.print_clock_levels = smu10_print_clock_levels,
	.get_dal_power_level = smu10_get_dal_power_level,
	.get_performance_level = smu10_get_performance_level,
	.get_current_shallow_sleep_clocks = smu10_get_current_shallow_sleep_clocks,
	.get_clock_by_type_with_latency = smu10_get_clock_by_type_with_latency,
	.get_clock_by_type_with_voltage = smu10_get_clock_by_type_with_voltage,
1089
	.set_watermarks_for_clocks_ranges = smu10_set_watermarks_for_clocks_ranges,
R
Rex Zhu 已提交
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
	.get_max_high_clocks = smu10_get_max_high_clocks,
	.read_sensor = smu10_read_sensor,
	.set_active_display_count = smu10_set_active_display_count,
	.set_deep_sleep_dcefclk = smu10_set_deep_sleep_dcefclk,
	.dynamic_state_management_enable = smu10_enable_dpm_tasks,
	.power_off_asic = smu10_power_off_asic,
	.asic_setup = smu10_setup_asic_task,
	.power_state_set = smu10_set_power_state_tasks,
	.dynamic_state_management_disable = smu10_disable_dpm_tasks,
	.set_mmhub_powergating_by_smu = smu10_set_mmhub_powergating_by_smu,
1100
	.gfx_off_control = smu10_gfx_off_control,
1101 1102
};

R
Rex Zhu 已提交
1103
int smu10_init_function_pointers(struct pp_hwmgr *hwmgr)
1104
{
R
Rex Zhu 已提交
1105
	hwmgr->hwmgr_func = &smu10_hwmgr_funcs;
1106 1107 1108
	hwmgr->pptable_func = &pptable_funcs;
	return 0;
}