smu10_hwmgr.c 29.5 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

R
Rex Zhu 已提交
45
static const unsigned long SMU10_Magic = (unsigned long) PHM_Rv_Magic;
46 47


R
Rex Zhu 已提交
48
static int smu10_display_clock_voltage_request(struct pp_hwmgr *hwmgr,
49
		struct pp_display_clock_request *clock_req);
50 51


R
Rex Zhu 已提交
52
static struct smu10_power_state *cast_smu10_ps(struct pp_hw_power_state *hw_ps)
53
{
R
Rex Zhu 已提交
54
	if (SMU10_Magic != hw_ps->magic)
55 56
		return NULL;

R
Rex Zhu 已提交
57
	return (struct smu10_power_state *)hw_ps;
58 59
}

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

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

R
Rex Zhu 已提交
69
static int smu10_initialize_dpm_defaults(struct pp_hwmgr *hwmgr)
70
{
R
Rex Zhu 已提交
71
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
72

R
Rex Zhu 已提交
73 74 75 76 77 78 79 80
	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->gfx_off_controled_by_driver = false;
	smu10_data->need_min_deep_sleep_dcefclk = true;
	smu10_data->num_active_display = 0;
	smu10_data->deep_sleep_dcefclk = 0;
81 82 83 84 85 86 87 88

	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,
89
				PHM_PlatformCaps_PowerPlaySupport);
90 91 92
	return 0;
}

R
Rex Zhu 已提交
93
static int smu10_construct_max_power_limits_table(struct pp_hwmgr *hwmgr,
94 95 96 97 98
			struct phm_clock_and_voltage_limits *table)
{
	return 0;
}

R
Rex Zhu 已提交
99
static int smu10_init_dynamic_state_adjustment_rule_settings(
100 101 102 103 104 105 106 107 108 109 110 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
							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 已提交
136
static int smu10_get_system_info_data(struct pp_hwmgr *hwmgr)
137
{
R
Rex Zhu 已提交
138
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)hwmgr->backend;
139

R
Rex Zhu 已提交
140 141
	smu10_data->sys_info.htc_hyst_lmt = 5;
	smu10_data->sys_info.htc_tmp_lmt = 203;
142

R
Rex Zhu 已提交
143 144
	if (smu10_data->thermal_auto_throttling_treshold == 0)
		 smu10_data->thermal_auto_throttling_treshold = 203;
145

R
Rex Zhu 已提交
146
	smu10_construct_max_power_limits_table (hwmgr,
147 148
				    &hwmgr->dyn_state.max_clock_voltage_on_ac);

R
Rex Zhu 已提交
149
	smu10_init_dynamic_state_adjustment_rule_settings(hwmgr);
150 151 152 153

	return 0;
}

R
Rex Zhu 已提交
154
static int smu10_construct_boot_state(struct pp_hwmgr *hwmgr)
155 156 157 158
{
	return 0;
}

R
Rex Zhu 已提交
159
static int smu10_set_clock_limit(struct pp_hwmgr *hwmgr, const void *input)
160
{
161 162 163
	struct PP_Clocks clocks = {0};
	struct pp_display_clock_request clock_req;

164
	clocks.dcefClock = hwmgr->display_config->min_dcef_set_clk;
165 166 167
	clock_req.clock_type = amd_pp_dcf_clock;
	clock_req.clock_freq_in_khz = clocks.dcefClock * 10;

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

171 172 173
	return 0;
}

R
Rex Zhu 已提交
174
static int smu10_set_deep_sleep_dcefclk(struct pp_hwmgr *hwmgr, uint32_t clock)
175
{
R
Rex Zhu 已提交
176
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
177

R
Rex Zhu 已提交
178 179
	if (smu10_data->need_min_deep_sleep_dcefclk && smu10_data->deep_sleep_dcefclk != clock/100) {
		smu10_data->deep_sleep_dcefclk = clock/100;
180
		smum_send_msg_to_smc_with_parameter(hwmgr,
181
					PPSMC_MSG_SetMinDeepSleepDcefclk,
R
Rex Zhu 已提交
182
					smu10_data->deep_sleep_dcefclk);
183 184 185 186
	}
	return 0;
}

R
Rex Zhu 已提交
187
static int smu10_set_active_display_count(struct pp_hwmgr *hwmgr, uint32_t count)
188
{
R
Rex Zhu 已提交
189
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
190

R
Rex Zhu 已提交
191 192
	if (smu10_data->num_active_display != count) {
		smu10_data->num_active_display = count;
193
		smum_send_msg_to_smc_with_parameter(hwmgr,
194
				PPSMC_MSG_SetDisplayCount,
R
Rex Zhu 已提交
195
				smu10_data->num_active_display);
196
	}
197

198 199 200
	return 0;
}

R
Rex Zhu 已提交
201
static int smu10_set_power_state_tasks(struct pp_hwmgr *hwmgr, const void *input)
202
{
R
Rex Zhu 已提交
203
	return smu10_set_clock_limit(hwmgr, input);
204
}
205

R
Rex Zhu 已提交
206
static int smu10_init_power_gate_state(struct pp_hwmgr *hwmgr)
207
{
R
Rex Zhu 已提交
208
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
209

R
Rex Zhu 已提交
210 211 212
	smu10_data->vcn_power_gated = true;
	smu10_data->isp_tileA_power_gated = true;
	smu10_data->isp_tileB_power_gated = true;
213 214 215 216 217

	return 0;
}


R
Rex Zhu 已提交
218
static int smu10_setup_asic_task(struct pp_hwmgr *hwmgr)
219
{
R
Rex Zhu 已提交
220
	return smu10_init_power_gate_state(hwmgr);
221
}
222

R
Rex Zhu 已提交
223
static int smu10_reset_cc6_data(struct pp_hwmgr *hwmgr)
224
{
R
Rex Zhu 已提交
225
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
226

R
Rex Zhu 已提交
227 228 229 230
	smu10_data->separation_time = 0;
	smu10_data->cc6_disable = false;
	smu10_data->pstate_disable = false;
	smu10_data->cc6_setting_changed = false;
231 232 233 234

	return 0;
}

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

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

R
Rex Zhu 已提交
244
	if (smu10_data->gfx_off_controled_by_driver)
245
		smum_send_msg_to_smc(hwmgr, PPSMC_MSG_DisableGfxOff);
246 247 248 249

	return 0;
}

R
Rex Zhu 已提交
250
static int smu10_disable_dpm_tasks(struct pp_hwmgr *hwmgr)
251
{
R
Rex Zhu 已提交
252
	return smu10_disable_gfx_off(hwmgr);
253
}
254

R
Rex Zhu 已提交
255
static int smu10_enable_gfx_off(struct pp_hwmgr *hwmgr)
256
{
R
Rex Zhu 已提交
257
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
258

R
Rex Zhu 已提交
259
	if (smu10_data->gfx_off_controled_by_driver)
260
		smum_send_msg_to_smc(hwmgr, PPSMC_MSG_EnableGfxOff);
261 262 263 264

	return 0;
}

R
Rex Zhu 已提交
265
static int smu10_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
266
{
R
Rex Zhu 已提交
267
	return smu10_enable_gfx_off(hwmgr);
268
}
269

R
Rex Zhu 已提交
270
static int smu10_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
271 272 273 274 275 276 277
				struct pp_power_state  *prequest_ps,
			const struct pp_power_state *pcurrent_ps)
{
	return 0;
}

/* temporary hardcoded clock voltage breakdown tables */
278
static const DpmClock_t VddDcfClk[]= {
279 280 281 282 283
	{ 300, 2600},
	{ 600, 3200},
	{ 600, 3600},
};

284
static const DpmClock_t VddSocClk[]= {
285 286 287 288 289
	{ 478, 2600},
	{ 722, 3200},
	{ 722, 3600},
};

290
static const DpmClock_t VddFClk[]= {
291 292 293 294 295
	{ 400, 2600},
	{1200, 3200},
	{1200, 3600},
};

296
static const DpmClock_t VddDispClk[]= {
297 298 299 300 301
	{ 435, 2600},
	{ 661, 3200},
	{1086, 3600},
};

302
static const DpmClock_t VddDppClk[]= {
303 304 305 306 307
	{ 435, 2600},
	{ 661, 3200},
	{ 661, 3600},
};

308
static const DpmClock_t VddPhyClk[]= {
309 310 311 312 313
	{ 540, 2600},
	{ 810, 3200},
	{ 810, 3600},
};

R
Rex Zhu 已提交
314 315
static int smu10_get_clock_voltage_dependency_table(struct pp_hwmgr *hwmgr,
			struct smu10_voltage_dependency_table **pptable,
316
			uint32_t num_entry, const DpmClock_t *pclk_dependency_table)
317 318
{
	uint32_t table_size, i;
R
Rex Zhu 已提交
319
	struct smu10_voltage_dependency_table *ptable;
320

R
Rex Zhu 已提交
321
	table_size = sizeof(uint32_t) + sizeof(struct smu10_voltage_dependency_table) * num_entry;
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
	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 已提交
341
static int smu10_populate_clock_table(struct pp_hwmgr *hwmgr)
342 343 344
{
	int result;

R
Rex Zhu 已提交
345 346 347
	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);
348

349
	result = smum_smc_table_manager(hwmgr, (uint8_t *)table, SMU10_CLOCKTABLE, true);
350 351 352 353 354 355

	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 已提交
356
		smu10_get_clock_voltage_dependency_table(hwmgr, &pinfo->vdd_dep_on_dcefclk,
357
						NUM_DCEFCLK_DPM_LEVELS,
R
Rex Zhu 已提交
358 359
						&smu10_data->clock_table.DcefClocks[0]);
		smu10_get_clock_voltage_dependency_table(hwmgr, &pinfo->vdd_dep_on_socclk,
360
						NUM_SOCCLK_DPM_LEVELS,
R
Rex Zhu 已提交
361 362
						&smu10_data->clock_table.SocClocks[0]);
		smu10_get_clock_voltage_dependency_table(hwmgr, &pinfo->vdd_dep_on_fclk,
363
						NUM_FCLK_DPM_LEVELS,
R
Rex Zhu 已提交
364 365
						&smu10_data->clock_table.FClocks[0]);
		smu10_get_clock_voltage_dependency_table(hwmgr, &pinfo->vdd_dep_on_mclk,
366
						NUM_MEMCLK_DPM_LEVELS,
R
Rex Zhu 已提交
367
						&smu10_data->clock_table.MemClocks[0]);
368
	} else {
R
Rex Zhu 已提交
369
		smu10_get_clock_voltage_dependency_table(hwmgr, &pinfo->vdd_dep_on_dcefclk,
370 371
						ARRAY_SIZE(VddDcfClk),
						&VddDcfClk[0]);
R
Rex Zhu 已提交
372
		smu10_get_clock_voltage_dependency_table(hwmgr, &pinfo->vdd_dep_on_socclk,
373 374
						ARRAY_SIZE(VddSocClk),
						&VddSocClk[0]);
R
Rex Zhu 已提交
375
		smu10_get_clock_voltage_dependency_table(hwmgr, &pinfo->vdd_dep_on_fclk,
376 377
						ARRAY_SIZE(VddFClk),
						&VddFClk[0]);
378
	}
R
Rex Zhu 已提交
379
	smu10_get_clock_voltage_dependency_table(hwmgr, &pinfo->vdd_dep_on_dispclk,
380 381
					ARRAY_SIZE(VddDispClk),
					&VddDispClk[0]);
R
Rex Zhu 已提交
382
	smu10_get_clock_voltage_dependency_table(hwmgr, &pinfo->vdd_dep_on_dppclk,
383
					ARRAY_SIZE(VddDppClk), &VddDppClk[0]);
R
Rex Zhu 已提交
384
	smu10_get_clock_voltage_dependency_table(hwmgr, &pinfo->vdd_dep_on_phyclk,
385
					ARRAY_SIZE(VddPhyClk), &VddPhyClk[0]);
386

387
	smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetMinGfxclkFrequency);
388
	result = smum_get_argument(hwmgr);
R
Rex Zhu 已提交
389
	smu10_data->gfx_min_freq_limit = result * 100;
390

391
	smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetMaxGfxclkFrequency);
392
	result = smum_get_argument(hwmgr);
R
Rex Zhu 已提交
393
	smu10_data->gfx_max_freq_limit = result * 100;
394

395 396 397
	return 0;
}

R
Rex Zhu 已提交
398
static int smu10_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
399 400
{
	int result = 0;
R
Rex Zhu 已提交
401
	struct smu10_hwmgr *data;
402

R
Rex Zhu 已提交
403
	data = kzalloc(sizeof(struct smu10_hwmgr), GFP_KERNEL);
404 405 406 407 408
	if (data == NULL)
		return -ENOMEM;

	hwmgr->backend = data;

R
Rex Zhu 已提交
409
	result = smu10_initialize_dpm_defaults(hwmgr);
410
	if (result != 0) {
R
Rex Zhu 已提交
411
		pr_err("smu10_initialize_dpm_defaults failed\n");
412 413 414
		return result;
	}

R
Rex Zhu 已提交
415
	smu10_populate_clock_table(hwmgr);
416

R
Rex Zhu 已提交
417
	result = smu10_get_system_info_data(hwmgr);
418
	if (result != 0) {
R
Rex Zhu 已提交
419
		pr_err("smu10_get_system_info_data failed\n");
420 421 422
		return result;
	}

R
Rex Zhu 已提交
423
	smu10_construct_boot_state(hwmgr);
424 425

	hwmgr->platform_descriptor.hardwareActivityPerformanceLevels =
R
Rex Zhu 已提交
426
						SMU10_MAX_HARDWARE_POWERLEVELS;
427 428

	hwmgr->platform_descriptor.hardwarePerformanceLevels =
R
Rex Zhu 已提交
429
						SMU10_MAX_HARDWARE_POWERLEVELS;
430 431 432 433 434 435 436 437 438

	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 已提交
439 440
	hwmgr->pstate_sclk = SMU10_UMD_PSTATE_GFXCLK;
	hwmgr->pstate_mclk = SMU10_UMD_PSTATE_FCLK;
R
Rex Zhu 已提交
441

442 443 444
	return result;
}

R
Rex Zhu 已提交
445
static int smu10_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)
446
{
R
Rex Zhu 已提交
447 448
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
	struct smu10_clock_voltage_information *pinfo = &(smu10_data->clock_vol_info);
449

450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
	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;
465

466 467 468 469 470 471
	kfree(hwmgr->backend);
	hwmgr->backend = NULL;

	return 0;
}

R
Rex Zhu 已提交
472
static int smu10_dpm_force_dpm_level(struct pp_hwmgr *hwmgr,
473 474
				enum amd_dpm_forced_level level)
{
475 476 477 478 479 480 481 482 483 484
	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 已提交
485
						SMU10_UMD_PSTATE_PEAK_GFXCLK);
486 487
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinFclkByFreq,
R
Rex Zhu 已提交
488
						SMU10_UMD_PSTATE_PEAK_FCLK);
489 490
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinSocclkByFreq,
R
Rex Zhu 已提交
491
						SMU10_UMD_PSTATE_PEAK_SOCCLK);
492 493
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinVcn,
R
Rex Zhu 已提交
494
						SMU10_UMD_PSTATE_VCE);
495 496 497

		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxGfxClk,
R
Rex Zhu 已提交
498
						SMU10_UMD_PSTATE_PEAK_GFXCLK);
499 500
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxFclkByFreq,
R
Rex Zhu 已提交
501
						SMU10_UMD_PSTATE_PEAK_FCLK);
502 503
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxSocclkByFreq,
R
Rex Zhu 已提交
504
						SMU10_UMD_PSTATE_PEAK_SOCCLK);
505 506
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxVcn,
R
Rex Zhu 已提交
507
						SMU10_UMD_PSTATE_VCE);
508 509 510 511
		break;
	case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinGfxClk,
R
Rex Zhu 已提交
512
						SMU10_UMD_PSTATE_MIN_GFXCLK);
513 514
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxGfxClk,
R
Rex Zhu 已提交
515
						SMU10_UMD_PSTATE_MIN_GFXCLK);
516 517 518 519
		break;
	case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinFclkByFreq,
R
Rex Zhu 已提交
520
						SMU10_UMD_PSTATE_MIN_FCLK);
521 522
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxFclkByFreq,
R
Rex Zhu 已提交
523
						SMU10_UMD_PSTATE_MIN_FCLK);
524 525 526 527
		break;
	case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinGfxClk,
R
Rex Zhu 已提交
528
						SMU10_UMD_PSTATE_GFXCLK);
529 530
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinFclkByFreq,
R
Rex Zhu 已提交
531
						SMU10_UMD_PSTATE_FCLK);
532 533
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinSocclkByFreq,
R
Rex Zhu 已提交
534
						SMU10_UMD_PSTATE_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_GFXCLK);
542 543
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxFclkByFreq,
R
Rex Zhu 已提交
544
						SMU10_UMD_PSTATE_FCLK);
545 546
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxSocclkByFreq,
R
Rex Zhu 已提交
547
						SMU10_UMD_PSTATE_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_AUTO:
		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_SetHardMinFclkByFreq,
R
Rex Zhu 已提交
558
						SMU10_UMD_PSTATE_MIN_FCLK);
559 560
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinSocclkByFreq,
R
Rex Zhu 已提交
561
						SMU10_UMD_PSTATE_MIN_SOCCLK);
562 563
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinVcn,
R
Rex Zhu 已提交
564
						SMU10_UMD_PSTATE_MIN_VCE);
565 566 567

		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxGfxClk,
R
Rex Zhu 已提交
568
						SMU10_UMD_PSTATE_PEAK_GFXCLK);
569 570
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxFclkByFreq,
R
Rex Zhu 已提交
571
						SMU10_UMD_PSTATE_PEAK_FCLK);
572 573
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxSocclkByFreq,
R
Rex Zhu 已提交
574
						SMU10_UMD_PSTATE_PEAK_SOCCLK);
575 576
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxVcn,
R
Rex Zhu 已提交
577
						SMU10_UMD_PSTATE_VCE);
578 579 580 581
		break;
	case AMD_DPM_FORCED_LEVEL_LOW:
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinGfxClk,
R
Rex Zhu 已提交
582
						SMU10_UMD_PSTATE_MIN_GFXCLK);
583 584
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxGfxClk,
R
Rex Zhu 已提交
585
						SMU10_UMD_PSTATE_MIN_GFXCLK);
586 587
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinFclkByFreq,
R
Rex Zhu 已提交
588
						SMU10_UMD_PSTATE_MIN_FCLK);
589 590
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxFclkByFreq,
R
Rex Zhu 已提交
591
						SMU10_UMD_PSTATE_MIN_FCLK);
592 593 594 595 596 597
		break;
	case AMD_DPM_FORCED_LEVEL_MANUAL:
	case AMD_DPM_FORCED_LEVEL_PROFILE_EXIT:
	default:
		break;
	}
598 599 600
	return 0;
}

R
Rex Zhu 已提交
601
static uint32_t smu10_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)
602
{
R
Rex Zhu 已提交
603
	struct smu10_hwmgr *data;
604 605 606 607

	if (hwmgr == NULL)
		return -EINVAL;

R
Rex Zhu 已提交
608
	data = (struct smu10_hwmgr *)(hwmgr->backend);
609 610 611 612 613 614

	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;
615 616
}

R
Rex Zhu 已提交
617
static uint32_t smu10_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)
618
{
R
Rex Zhu 已提交
619
	struct smu10_hwmgr *data;
620 621 622 623

	if (hwmgr == NULL)
		return -EINVAL;

R
Rex Zhu 已提交
624
	data = (struct smu10_hwmgr *)(hwmgr->backend);
625 626 627 628 629

	if (low)
		return data->gfx_min_freq_limit;
	else
		return data->gfx_max_freq_limit;
630 631
}

R
Rex Zhu 已提交
632
static int smu10_dpm_patch_boot_state(struct pp_hwmgr *hwmgr,
633 634 635 636 637
					struct pp_hw_power_state *hw_ps)
{
	return 0;
}

R
Rex Zhu 已提交
638
static int smu10_dpm_get_pp_table_entry_callback(
639 640 641 642 643
						     struct pp_hwmgr *hwmgr,
					   struct pp_hw_power_state *hw_ps,
							  unsigned int index,
						     const void *clock_info)
{
R
Rex Zhu 已提交
644
	struct smu10_power_state *smu10_ps = cast_smu10_ps(hw_ps);
645

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

R
Rex Zhu 已提交
648 649
	smu10_ps->levels[index].vddc_index = 0;
	smu10_ps->level = index + 1;
650 651

	if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep)) {
R
Rex Zhu 已提交
652 653
		smu10_ps->levels[index].ds_divider_index = 5;
		smu10_ps->levels[index].ss_divider_index = 5;
654 655 656 657 658
	}

	return 0;
}

R
Rex Zhu 已提交
659
static int smu10_dpm_get_num_of_pp_table_entries(struct pp_hwmgr *hwmgr)
660 661 662 663 664 665 666 667 668
{
	int result;
	unsigned long ret = 0;

	result = pp_tables_get_num_of_entries(hwmgr, &ret);

	return result ? 0 : ret;
}

R
Rex Zhu 已提交
669
static int smu10_dpm_get_pp_table_entry(struct pp_hwmgr *hwmgr,
670 671 672
		    unsigned long entry, struct pp_power_state *ps)
{
	int result;
R
Rex Zhu 已提交
673
	struct smu10_power_state *smu10_ps;
674

R
Rex Zhu 已提交
675
	ps->hardware.magic = SMU10_Magic;
676

R
Rex Zhu 已提交
677
	smu10_ps = cast_smu10_ps(&(ps->hardware));
678 679

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

R
Rex Zhu 已提交
682 683
	smu10_ps->uvd_clocks.vclk = ps->uvd_clocks.VCLK;
	smu10_ps->uvd_clocks.dclk = ps->uvd_clocks.DCLK;
684 685 686 687

	return result;
}

R
Rex Zhu 已提交
688
static int smu10_get_power_state_size(struct pp_hwmgr *hwmgr)
689
{
R
Rex Zhu 已提交
690
	return sizeof(struct smu10_power_state);
691 692
}

R
Rex Zhu 已提交
693
static int smu10_set_cpu_power_state(struct pp_hwmgr *hwmgr)
694 695 696 697 698
{
	return 0;
}


R
Rex Zhu 已提交
699
static int smu10_store_cc6_data(struct pp_hwmgr *hwmgr, uint32_t separation_time,
700 701 702 703 704
			bool cc6_disable, bool pstate_disable, bool pstate_switch_disable)
{
	return 0;
}

R
Rex Zhu 已提交
705
static int smu10_get_dal_power_level(struct pp_hwmgr *hwmgr,
706 707 708 709 710
		struct amd_pp_simple_clock_info *info)
{
	return -EINVAL;
}

R
Rex Zhu 已提交
711
static int smu10_force_clock_level(struct pp_hwmgr *hwmgr,
712 713 714 715 716
		enum pp_clock_type type, uint32_t mask)
{
	return 0;
}

R
Rex Zhu 已提交
717
static int smu10_print_clock_levels(struct pp_hwmgr *hwmgr,
718 719
		enum pp_clock_type type, char *buf)
{
R
Rex Zhu 已提交
720 721
	struct smu10_hwmgr *data = (struct smu10_hwmgr *)(hwmgr->backend);
	struct smu10_voltage_dependency_table *mclk_table =
722 723 724 725 726
			data->clock_vol_info.vdd_dep_on_fclk;
	int i, now, size = 0;

	switch (type) {
	case PP_SCLK:
727
		smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetGfxclkFrequency);
728
		now = smum_get_argument(hwmgr);
729 730 731 732 733 734 735 736 737 738 739

		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:
740
		smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetFclkFrequency);
741
		now = smum_get_argument(hwmgr);
742 743 744 745 746 747 748 749 750 751 752 753 754

		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;
755 756
}

R
Rex Zhu 已提交
757
static int smu10_get_performance_level(struct pp_hwmgr *hwmgr, const struct pp_hw_power_state *state,
758 759 760
				PHM_PerformanceLevelDesignation designation, uint32_t index,
				PHM_PerformanceLevel *level)
{
R
Rex Zhu 已提交
761
	struct smu10_hwmgr *data;
762 763 764 765

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

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

768
	if (index == 0) {
769
		level->memory_clock = data->clock_vol_info.vdd_dep_on_fclk->entries[0].clk;
770 771 772 773 774
		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;
775
	}
776

777 778 779 780 781 782
	level->nonLocalMemoryFreq = 0;
	level->nonLocalMemoryWidth = 0;

	return 0;
}

R
Rex Zhu 已提交
783
static int smu10_get_current_shallow_sleep_clocks(struct pp_hwmgr *hwmgr,
784 785
	const struct pp_hw_power_state *state, struct pp_clock_info *clock_info)
{
R
Rex Zhu 已提交
786
	const struct smu10_power_state *ps = cast_const_smu10_ps(state);
787 788 789 790 791 792 793 794 795 796 797 798 799 800

	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 已提交
801
static uint32_t smu10_get_mem_latency(struct pp_hwmgr *hwmgr,
802 803 804 805 806 807 808 809 810 811 812
		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 已提交
813
static int smu10_get_clock_by_type_with_latency(struct pp_hwmgr *hwmgr,
814
		enum amd_pp_clock_type type,
815 816 817
		struct pp_clock_levels_with_latency *clocks)
{
	uint32_t i;
R
Rex Zhu 已提交
818 819 820
	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;
821
	bool latency_required = false;
822

823 824
	if (pinfo == NULL)
		return -EINVAL;
825 826 827

	switch (type) {
	case amd_pp_mem_clock:
828 829
		pclk_vol_table = pinfo->vdd_dep_on_mclk;
		latency_required = true;
830
		break;
831 832 833
	case amd_pp_f_clock:
		pclk_vol_table = pinfo->vdd_dep_on_fclk;
		latency_required = true;
834
		break;
835 836
	case amd_pp_dcf_clock:
		pclk_vol_table = pinfo->vdd_dep_on_dcefclk;
837
		break;
838 839 840 841 842 843 844 845
	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;
846
	default:
847 848 849 850 851 852 853 854 855 856
		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 已提交
857
						smu10_get_mem_latency(hwmgr,
858 859 860
						pclk_vol_table->entries[i].clk) :
						0;
		clocks->num_levels++;
861 862 863 864 865
	}

	return 0;
}

R
Rex Zhu 已提交
866
static int smu10_get_clock_by_type_with_voltage(struct pp_hwmgr *hwmgr,
867 868 869 870
		enum amd_pp_clock_type type,
		struct pp_clock_levels_with_voltage *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 = NULL;
874 875 876

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

	switch (type) {
	case amd_pp_mem_clock:
		pclk_vol_table = pinfo->vdd_dep_on_mclk;
		break;
882 883
	case amd_pp_f_clock:
		pclk_vol_table = pinfo->vdd_dep_on_fclk;
884
		break;
885 886
	case amd_pp_dcf_clock:
		pclk_vol_table = pinfo->vdd_dep_on_dcefclk;
887
		break;
888 889
	case amd_pp_soc_clock:
		pclk_vol_table = pinfo->vdd_dep_on_socclk;
890 891 892 893 894
		break;
	default:
		return -EINVAL;
	}

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

898
	clocks->num_levels = 0;
899 900 901 902 903 904 905 906 907
	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 已提交
908
static int smu10_display_clock_voltage_request(struct pp_hwmgr *hwmgr,
909 910
		struct pp_display_clock_request *clock_req)
{
R
Rex Zhu 已提交
911
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
912
	enum amd_pp_clock_type clk_type = clock_req->clock_type;
913
	uint32_t clk_freq = clock_req->clock_freq_in_khz / 1000;
914 915 916
	PPSMC_Msg        msg;

	switch (clk_type) {
917
	case amd_pp_dcf_clock:
R
Rex Zhu 已提交
918
		if (clk_freq == smu10_data->dcf_actual_hard_min_freq)
919
			return 0;
920
		msg =  PPSMC_MSG_SetHardMinDcefclkByFreq;
R
Rex Zhu 已提交
921
		smu10_data->dcf_actual_hard_min_freq = clk_freq;
922 923 924 925
		break;
	case amd_pp_soc_clock:
		 msg = PPSMC_MSG_SetHardMinSocclkByFreq;
		break;
926
	case amd_pp_f_clock:
R
Rex Zhu 已提交
927
		if (clk_freq == smu10_data->f_actual_hard_min_freq)
928
			return 0;
R
Rex Zhu 已提交
929
		smu10_data->f_actual_hard_min_freq = clk_freq;
930 931 932 933 934 935 936
		msg = PPSMC_MSG_SetHardMinFclkByFreq;
		break;
	default:
		pr_info("[DisplayClockVoltageRequest]Invalid Clock Type!");
		return -EINVAL;
	}

937
	smum_send_msg_to_smc_with_parameter(hwmgr, msg, clk_freq);
938

939
	return 0;
940 941
}

R
Rex Zhu 已提交
942
static int smu10_get_max_high_clocks(struct pp_hwmgr *hwmgr, struct amd_pp_simple_clock_info *clocks)
943
{
944 945
	clocks->engine_max_clock = 80000; /* driver can't get engine clock, temp hard code to 800MHz */
	return 0;
946 947
}

R
Rex Zhu 已提交
948
static int smu10_thermal_get_temperature(struct pp_hwmgr *hwmgr)
949
{
950 951
	struct amdgpu_device *adev = hwmgr->adev;
	uint32_t reg_value = RREG32_SOC15(THM, 0, mmTHM_TCON_CUR_TMP);
952 953 954 955 956 957 958 959 960 961 962
	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 已提交
963
static int smu10_read_sensor(struct pp_hwmgr *hwmgr, int idx,
964 965
			  void *value, int *size)
{
966 967 968
	uint32_t sclk, mclk;
	int ret = 0;

969
	switch (idx) {
970
	case AMDGPU_PP_SENSOR_GFX_SCLK:
971
		smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetGfxclkFrequency);
972
		sclk = smum_get_argument(hwmgr);
973
			/* in units of 10KHZ */
974 975
		*((uint32_t *)value) = sclk * 100;
		*size = 4;
976 977
		break;
	case AMDGPU_PP_SENSOR_GFX_MCLK:
978
		smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetFclkFrequency);
979
		mclk = smum_get_argument(hwmgr);
980
			/* in units of 10KHZ */
981 982
		*((uint32_t *)value) = mclk * 100;
		*size = 4;
983
		break;
984
	case AMDGPU_PP_SENSOR_GPU_TEMP:
R
Rex Zhu 已提交
985
		*((uint32_t *)value) = smu10_thermal_get_temperature(hwmgr);
986
		break;
987
	default:
988 989
		ret = -EINVAL;
		break;
990
	}
991 992

	return ret;
993 994
}

R
Rex Zhu 已提交
995
static int smu10_set_mmhub_powergating_by_smu(struct pp_hwmgr *hwmgr)
996 997 998 999
{
	return smum_send_msg_to_smc(hwmgr, PPSMC_MSG_PowerGateMmHub);
}

R
Rex Zhu 已提交
1000 1001 1002
static const struct pp_hwmgr_func smu10_hwmgr_funcs = {
	.backend_init = smu10_hwmgr_backend_init,
	.backend_fini = smu10_hwmgr_backend_fini,
1003
	.asic_setup = NULL,
R
Rex Zhu 已提交
1004 1005 1006
	.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,
1007 1008 1009
	.powerdown_uvd = NULL,
	.powergate_uvd = NULL,
	.powergate_vce = NULL,
R
Rex Zhu 已提交
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033
	.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,
	.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,
1034 1035
};

R
Rex Zhu 已提交
1036
int smu10_init_function_pointers(struct pp_hwmgr *hwmgr)
1037
{
R
Rex Zhu 已提交
1038
	hwmgr->hwmgr_func = &smu10_hwmgr_funcs;
1039 1040 1041
	hwmgr->pptable_func = &pptable_funcs;
	return 0;
}