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

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
	struct amdgpu_device *adev = hwmgr->adev;
210

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

215 216 217 218 219 220
	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;
221 222 223
}


R
Rex Zhu 已提交
224
static int smu10_setup_asic_task(struct pp_hwmgr *hwmgr)
225
{
R
Rex Zhu 已提交
226
	return smu10_init_power_gate_state(hwmgr);
227
}
228

R
Rex Zhu 已提交
229
static int smu10_reset_cc6_data(struct pp_hwmgr *hwmgr)
230
{
R
Rex Zhu 已提交
231
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
232

R
Rex Zhu 已提交
233 234 235 236
	smu10_data->separation_time = 0;
	smu10_data->cc6_disable = false;
	smu10_data->pstate_disable = false;
	smu10_data->cc6_setting_changed = false;
237 238 239 240

	return 0;
}

R
Rex Zhu 已提交
241
static int smu10_power_off_asic(struct pp_hwmgr *hwmgr)
242
{
R
Rex Zhu 已提交
243
	return smu10_reset_cc6_data(hwmgr);
244
}
245

R
Rex Zhu 已提交
246
static int smu10_disable_gfx_off(struct pp_hwmgr *hwmgr)
247
{
R
Rex Zhu 已提交
248
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
249

R
Rex Zhu 已提交
250
	if (smu10_data->gfx_off_controled_by_driver)
251
		smum_send_msg_to_smc(hwmgr, PPSMC_MSG_DisableGfxOff);
252 253 254 255

	return 0;
}

R
Rex Zhu 已提交
256
static int smu10_disable_dpm_tasks(struct pp_hwmgr *hwmgr)
257
{
R
Rex Zhu 已提交
258
	return smu10_disable_gfx_off(hwmgr);
259
}
260

R
Rex Zhu 已提交
261
static int smu10_enable_gfx_off(struct pp_hwmgr *hwmgr)
262
{
R
Rex Zhu 已提交
263
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
264

R
Rex Zhu 已提交
265
	if (smu10_data->gfx_off_controled_by_driver)
266
		smum_send_msg_to_smc(hwmgr, PPSMC_MSG_EnableGfxOff);
267 268 269 270

	return 0;
}

R
Rex Zhu 已提交
271
static int smu10_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
272
{
R
Rex Zhu 已提交
273
	return smu10_enable_gfx_off(hwmgr);
274
}
275

R
Rex Zhu 已提交
276
static int smu10_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
277 278 279 280 281 282 283
				struct pp_power_state  *prequest_ps,
			const struct pp_power_state *pcurrent_ps)
{
	return 0;
}

/* temporary hardcoded clock voltage breakdown tables */
284
static const DpmClock_t VddDcfClk[]= {
285 286 287 288 289
	{ 300, 2600},
	{ 600, 3200},
	{ 600, 3600},
};

290
static const DpmClock_t VddSocClk[]= {
291 292 293 294 295
	{ 478, 2600},
	{ 722, 3200},
	{ 722, 3600},
};

296
static const DpmClock_t VddFClk[]= {
297 298 299 300 301
	{ 400, 2600},
	{1200, 3200},
	{1200, 3600},
};

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

308
static const DpmClock_t VddDppClk[]= {
309 310 311 312 313
	{ 435, 2600},
	{ 661, 3200},
	{ 661, 3600},
};

314
static const DpmClock_t VddPhyClk[]= {
315 316 317 318 319
	{ 540, 2600},
	{ 810, 3200},
	{ 810, 3600},
};

R
Rex Zhu 已提交
320 321
static int smu10_get_clock_voltage_dependency_table(struct pp_hwmgr *hwmgr,
			struct smu10_voltage_dependency_table **pptable,
322
			uint32_t num_entry, const DpmClock_t *pclk_dependency_table)
323 324
{
	uint32_t table_size, i;
R
Rex Zhu 已提交
325
	struct smu10_voltage_dependency_table *ptable;
326

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

R
Rex Zhu 已提交
351 352 353
	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);
354

355
	result = smum_smc_table_manager(hwmgr, (uint8_t *)table, SMU10_CLOCKTABLE, true);
356 357 358 359 360 361

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

393
	smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetMinGfxclkFrequency);
394
	result = smum_get_argument(hwmgr);
R
Rex Zhu 已提交
395
	smu10_data->gfx_min_freq_limit = result * 100;
396

397
	smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetMaxGfxclkFrequency);
398
	result = smum_get_argument(hwmgr);
R
Rex Zhu 已提交
399
	smu10_data->gfx_max_freq_limit = result * 100;
400

401 402 403
	return 0;
}

R
Rex Zhu 已提交
404
static int smu10_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
405 406
{
	int result = 0;
R
Rex Zhu 已提交
407
	struct smu10_hwmgr *data;
408

R
Rex Zhu 已提交
409
	data = kzalloc(sizeof(struct smu10_hwmgr), GFP_KERNEL);
410 411 412 413 414
	if (data == NULL)
		return -ENOMEM;

	hwmgr->backend = data;

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

R
Rex Zhu 已提交
421
	smu10_populate_clock_table(hwmgr);
422

R
Rex Zhu 已提交
423
	result = smu10_get_system_info_data(hwmgr);
424
	if (result != 0) {
R
Rex Zhu 已提交
425
		pr_err("smu10_get_system_info_data failed\n");
426 427 428
		return result;
	}

R
Rex Zhu 已提交
429
	smu10_construct_boot_state(hwmgr);
430 431

	hwmgr->platform_descriptor.hardwareActivityPerformanceLevels =
R
Rex Zhu 已提交
432
						SMU10_MAX_HARDWARE_POWERLEVELS;
433 434

	hwmgr->platform_descriptor.hardwarePerformanceLevels =
R
Rex Zhu 已提交
435
						SMU10_MAX_HARDWARE_POWERLEVELS;
436 437 438 439 440 441 442 443 444

	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 已提交
445 446
	hwmgr->pstate_sclk = SMU10_UMD_PSTATE_GFXCLK;
	hwmgr->pstate_mclk = SMU10_UMD_PSTATE_FCLK;
R
Rex Zhu 已提交
447

448 449 450
	return result;
}

R
Rex Zhu 已提交
451
static int smu10_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)
452
{
R
Rex Zhu 已提交
453 454
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
	struct smu10_clock_voltage_information *pinfo = &(smu10_data->clock_vol_info);
455

456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
	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;
471

472 473 474 475 476 477
	kfree(hwmgr->backend);
	hwmgr->backend = NULL;

	return 0;
}

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

		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxGfxClk,
R
Rex Zhu 已提交
504
						SMU10_UMD_PSTATE_PEAK_GFXCLK);
505 506
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxFclkByFreq,
R
Rex Zhu 已提交
507
						SMU10_UMD_PSTATE_PEAK_FCLK);
508 509
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxSocclkByFreq,
R
Rex Zhu 已提交
510
						SMU10_UMD_PSTATE_PEAK_SOCCLK);
511 512
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxVcn,
R
Rex Zhu 已提交
513
						SMU10_UMD_PSTATE_VCE);
514 515 516 517
		break;
	case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinGfxClk,
R
Rex Zhu 已提交
518
						SMU10_UMD_PSTATE_MIN_GFXCLK);
519 520
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxGfxClk,
R
Rex Zhu 已提交
521
						SMU10_UMD_PSTATE_MIN_GFXCLK);
522 523 524 525
		break;
	case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinFclkByFreq,
R
Rex Zhu 已提交
526
						SMU10_UMD_PSTATE_MIN_FCLK);
527 528
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxFclkByFreq,
R
Rex Zhu 已提交
529
						SMU10_UMD_PSTATE_MIN_FCLK);
530 531 532 533
		break;
	case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinGfxClk,
R
Rex Zhu 已提交
534
						SMU10_UMD_PSTATE_GFXCLK);
535 536
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinFclkByFreq,
R
Rex Zhu 已提交
537
						SMU10_UMD_PSTATE_FCLK);
538 539
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinSocclkByFreq,
R
Rex Zhu 已提交
540
						SMU10_UMD_PSTATE_SOCCLK);
541 542
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinVcn,
R
Rex Zhu 已提交
543
						SMU10_UMD_PSTATE_VCE);
544 545 546

		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxGfxClk,
R
Rex Zhu 已提交
547
						SMU10_UMD_PSTATE_GFXCLK);
548 549
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxFclkByFreq,
R
Rex Zhu 已提交
550
						SMU10_UMD_PSTATE_FCLK);
551 552
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxSocclkByFreq,
R
Rex Zhu 已提交
553
						SMU10_UMD_PSTATE_SOCCLK);
554 555
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetSoftMaxVcn,
R
Rex Zhu 已提交
556
						SMU10_UMD_PSTATE_VCE);
557 558 559 560
		break;
	case AMD_DPM_FORCED_LEVEL_AUTO:
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinGfxClk,
R
Rex Zhu 已提交
561
						SMU10_UMD_PSTATE_MIN_GFXCLK);
562 563
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinFclkByFreq,
R
Rex Zhu 已提交
564
						SMU10_UMD_PSTATE_MIN_FCLK);
565 566
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinSocclkByFreq,
R
Rex Zhu 已提交
567
						SMU10_UMD_PSTATE_MIN_SOCCLK);
568 569
		smum_send_msg_to_smc_with_parameter(hwmgr,
						PPSMC_MSG_SetHardMinVcn,
R
Rex Zhu 已提交
570
						SMU10_UMD_PSTATE_MIN_VCE);
571 572 573

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

R
Rex Zhu 已提交
607
static uint32_t smu10_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)
608
{
R
Rex Zhu 已提交
609
	struct smu10_hwmgr *data;
610 611 612 613

	if (hwmgr == NULL)
		return -EINVAL;

R
Rex Zhu 已提交
614
	data = (struct smu10_hwmgr *)(hwmgr->backend);
615 616 617 618 619 620

	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;
621 622
}

R
Rex Zhu 已提交
623
static uint32_t smu10_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)
624
{
R
Rex Zhu 已提交
625
	struct smu10_hwmgr *data;
626 627 628 629

	if (hwmgr == NULL)
		return -EINVAL;

R
Rex Zhu 已提交
630
	data = (struct smu10_hwmgr *)(hwmgr->backend);
631 632 633 634 635

	if (low)
		return data->gfx_min_freq_limit;
	else
		return data->gfx_max_freq_limit;
636 637
}

R
Rex Zhu 已提交
638
static int smu10_dpm_patch_boot_state(struct pp_hwmgr *hwmgr,
639 640 641 642 643
					struct pp_hw_power_state *hw_ps)
{
	return 0;
}

R
Rex Zhu 已提交
644
static int smu10_dpm_get_pp_table_entry_callback(
645 646 647 648 649
						     struct pp_hwmgr *hwmgr,
					   struct pp_hw_power_state *hw_ps,
							  unsigned int index,
						     const void *clock_info)
{
R
Rex Zhu 已提交
650
	struct smu10_power_state *smu10_ps = cast_smu10_ps(hw_ps);
651

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

R
Rex Zhu 已提交
654 655
	smu10_ps->levels[index].vddc_index = 0;
	smu10_ps->level = index + 1;
656 657

	if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep)) {
R
Rex Zhu 已提交
658 659
		smu10_ps->levels[index].ds_divider_index = 5;
		smu10_ps->levels[index].ss_divider_index = 5;
660 661 662 663 664
	}

	return 0;
}

R
Rex Zhu 已提交
665
static int smu10_dpm_get_num_of_pp_table_entries(struct pp_hwmgr *hwmgr)
666 667 668 669 670 671 672 673 674
{
	int result;
	unsigned long ret = 0;

	result = pp_tables_get_num_of_entries(hwmgr, &ret);

	return result ? 0 : ret;
}

R
Rex Zhu 已提交
675
static int smu10_dpm_get_pp_table_entry(struct pp_hwmgr *hwmgr,
676 677 678
		    unsigned long entry, struct pp_power_state *ps)
{
	int result;
R
Rex Zhu 已提交
679
	struct smu10_power_state *smu10_ps;
680

R
Rex Zhu 已提交
681
	ps->hardware.magic = SMU10_Magic;
682

R
Rex Zhu 已提交
683
	smu10_ps = cast_smu10_ps(&(ps->hardware));
684 685

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

R
Rex Zhu 已提交
688 689
	smu10_ps->uvd_clocks.vclk = ps->uvd_clocks.VCLK;
	smu10_ps->uvd_clocks.dclk = ps->uvd_clocks.DCLK;
690 691 692 693

	return result;
}

R
Rex Zhu 已提交
694
static int smu10_get_power_state_size(struct pp_hwmgr *hwmgr)
695
{
R
Rex Zhu 已提交
696
	return sizeof(struct smu10_power_state);
697 698
}

R
Rex Zhu 已提交
699
static int smu10_set_cpu_power_state(struct pp_hwmgr *hwmgr)
700 701 702 703 704
{
	return 0;
}


R
Rex Zhu 已提交
705
static int smu10_store_cc6_data(struct pp_hwmgr *hwmgr, uint32_t separation_time,
706 707
			bool cc6_disable, bool pstate_disable, bool pstate_switch_disable)
{
708 709 710 711 712 713 714 715 716 717
	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;
	}
718 719 720
	return 0;
}

R
Rex Zhu 已提交
721
static int smu10_get_dal_power_level(struct pp_hwmgr *hwmgr,
722 723 724 725 726
		struct amd_pp_simple_clock_info *info)
{
	return -EINVAL;
}

R
Rex Zhu 已提交
727
static int smu10_force_clock_level(struct pp_hwmgr *hwmgr,
728 729 730 731 732
		enum pp_clock_type type, uint32_t mask)
{
	return 0;
}

R
Rex Zhu 已提交
733
static int smu10_print_clock_levels(struct pp_hwmgr *hwmgr,
734 735
		enum pp_clock_type type, char *buf)
{
R
Rex Zhu 已提交
736 737
	struct smu10_hwmgr *data = (struct smu10_hwmgr *)(hwmgr->backend);
	struct smu10_voltage_dependency_table *mclk_table =
738 739 740 741 742
			data->clock_vol_info.vdd_dep_on_fclk;
	int i, now, size = 0;

	switch (type) {
	case PP_SCLK:
743
		smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetGfxclkFrequency);
744
		now = smum_get_argument(hwmgr);
745 746 747 748 749 750 751 752 753 754 755

		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:
756
		smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetFclkFrequency);
757
		now = smum_get_argument(hwmgr);
758 759 760 761 762 763 764 765 766 767 768 769 770

		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;
771 772
}

R
Rex Zhu 已提交
773
static int smu10_get_performance_level(struct pp_hwmgr *hwmgr, const struct pp_hw_power_state *state,
774 775 776
				PHM_PerformanceLevelDesignation designation, uint32_t index,
				PHM_PerformanceLevel *level)
{
R
Rex Zhu 已提交
777
	struct smu10_hwmgr *data;
778 779 780 781

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

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

784
	if (index == 0) {
785
		level->memory_clock = data->clock_vol_info.vdd_dep_on_fclk->entries[0].clk;
786 787 788 789 790
		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;
791
	}
792

793 794 795 796 797 798
	level->nonLocalMemoryFreq = 0;
	level->nonLocalMemoryWidth = 0;

	return 0;
}

R
Rex Zhu 已提交
799
static int smu10_get_current_shallow_sleep_clocks(struct pp_hwmgr *hwmgr,
800 801
	const struct pp_hw_power_state *state, struct pp_clock_info *clock_info)
{
R
Rex Zhu 已提交
802
	const struct smu10_power_state *ps = cast_const_smu10_ps(state);
803 804 805 806 807 808 809 810 811 812 813 814 815 816

	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 已提交
817
static uint32_t smu10_get_mem_latency(struct pp_hwmgr *hwmgr,
818 819 820 821 822 823 824 825 826 827 828
		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 已提交
829
static int smu10_get_clock_by_type_with_latency(struct pp_hwmgr *hwmgr,
830
		enum amd_pp_clock_type type,
831 832 833
		struct pp_clock_levels_with_latency *clocks)
{
	uint32_t i;
R
Rex Zhu 已提交
834 835 836
	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;
837
	bool latency_required = false;
838

839 840
	if (pinfo == NULL)
		return -EINVAL;
841 842 843

	switch (type) {
	case amd_pp_mem_clock:
844 845
		pclk_vol_table = pinfo->vdd_dep_on_mclk;
		latency_required = true;
846
		break;
847 848 849
	case amd_pp_f_clock:
		pclk_vol_table = pinfo->vdd_dep_on_fclk;
		latency_required = true;
850
		break;
851 852
	case amd_pp_dcf_clock:
		pclk_vol_table = pinfo->vdd_dep_on_dcefclk;
853
		break;
854 855 856 857 858 859 860 861
	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;
862
	default:
863 864 865 866 867 868 869 870 871 872
		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 已提交
873
						smu10_get_mem_latency(hwmgr,
874 875 876
						pclk_vol_table->entries[i].clk) :
						0;
		clocks->num_levels++;
877 878 879 880 881
	}

	return 0;
}

R
Rex Zhu 已提交
882
static int smu10_get_clock_by_type_with_voltage(struct pp_hwmgr *hwmgr,
883 884 885 886
		enum amd_pp_clock_type type,
		struct pp_clock_levels_with_voltage *clocks)
{
	uint32_t i;
R
Rex Zhu 已提交
887 888 889
	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;
890 891 892

	if (pinfo == NULL)
		return -EINVAL;
893 894 895 896 897

	switch (type) {
	case amd_pp_mem_clock:
		pclk_vol_table = pinfo->vdd_dep_on_mclk;
		break;
898 899
	case amd_pp_f_clock:
		pclk_vol_table = pinfo->vdd_dep_on_fclk;
900
		break;
901 902
	case amd_pp_dcf_clock:
		pclk_vol_table = pinfo->vdd_dep_on_dcefclk;
903
		break;
904 905
	case amd_pp_soc_clock:
		pclk_vol_table = pinfo->vdd_dep_on_socclk;
906 907 908 909 910
		break;
	default:
		return -EINVAL;
	}

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

914
	clocks->num_levels = 0;
915 916 917 918 919 920 921 922 923
	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 已提交
924
static int smu10_display_clock_voltage_request(struct pp_hwmgr *hwmgr,
925 926
		struct pp_display_clock_request *clock_req)
{
R
Rex Zhu 已提交
927
	struct smu10_hwmgr *smu10_data = (struct smu10_hwmgr *)(hwmgr->backend);
928
	enum amd_pp_clock_type clk_type = clock_req->clock_type;
929
	uint32_t clk_freq = clock_req->clock_freq_in_khz / 1000;
930 931 932
	PPSMC_Msg        msg;

	switch (clk_type) {
933
	case amd_pp_dcf_clock:
R
Rex Zhu 已提交
934
		if (clk_freq == smu10_data->dcf_actual_hard_min_freq)
935
			return 0;
936
		msg =  PPSMC_MSG_SetHardMinDcefclkByFreq;
R
Rex Zhu 已提交
937
		smu10_data->dcf_actual_hard_min_freq = clk_freq;
938 939 940 941
		break;
	case amd_pp_soc_clock:
		 msg = PPSMC_MSG_SetHardMinSocclkByFreq;
		break;
942
	case amd_pp_f_clock:
R
Rex Zhu 已提交
943
		if (clk_freq == smu10_data->f_actual_hard_min_freq)
944
			return 0;
R
Rex Zhu 已提交
945
		smu10_data->f_actual_hard_min_freq = clk_freq;
946 947 948 949 950 951 952
		msg = PPSMC_MSG_SetHardMinFclkByFreq;
		break;
	default:
		pr_info("[DisplayClockVoltageRequest]Invalid Clock Type!");
		return -EINVAL;
	}

953
	smum_send_msg_to_smc_with_parameter(hwmgr, msg, clk_freq);
954

955
	return 0;
956 957
}

R
Rex Zhu 已提交
958
static int smu10_get_max_high_clocks(struct pp_hwmgr *hwmgr, struct amd_pp_simple_clock_info *clocks)
959
{
960 961
	clocks->engine_max_clock = 80000; /* driver can't get engine clock, temp hard code to 800MHz */
	return 0;
962 963
}

R
Rex Zhu 已提交
964
static int smu10_thermal_get_temperature(struct pp_hwmgr *hwmgr)
965
{
966 967
	struct amdgpu_device *adev = hwmgr->adev;
	uint32_t reg_value = RREG32_SOC15(THM, 0, mmTHM_TCON_CUR_TMP);
968 969 970 971 972 973 974 975 976 977 978
	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 已提交
979
static int smu10_read_sensor(struct pp_hwmgr *hwmgr, int idx,
980 981
			  void *value, int *size)
{
982 983 984
	uint32_t sclk, mclk;
	int ret = 0;

985
	switch (idx) {
986
	case AMDGPU_PP_SENSOR_GFX_SCLK:
987
		smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetGfxclkFrequency);
988
		sclk = smum_get_argument(hwmgr);
989
			/* in units of 10KHZ */
990 991
		*((uint32_t *)value) = sclk * 100;
		*size = 4;
992 993
		break;
	case AMDGPU_PP_SENSOR_GFX_MCLK:
994
		smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetFclkFrequency);
995
		mclk = smum_get_argument(hwmgr);
996
			/* in units of 10KHZ */
997 998
		*((uint32_t *)value) = mclk * 100;
		*size = 4;
999
		break;
1000
	case AMDGPU_PP_SENSOR_GPU_TEMP:
R
Rex Zhu 已提交
1001
		*((uint32_t *)value) = smu10_thermal_get_temperature(hwmgr);
1002
		break;
1003
	default:
1004 1005
		ret = -EINVAL;
		break;
1006
	}
1007 1008

	return ret;
1009 1010
}

1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
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 已提交
1023
static int smu10_set_mmhub_powergating_by_smu(struct pp_hwmgr *hwmgr)
1024 1025 1026 1027
{
	return smum_send_msg_to_smc(hwmgr, PPSMC_MSG_PowerGateMmHub);
}

R
Rex Zhu 已提交
1028 1029 1030
static const struct pp_hwmgr_func smu10_hwmgr_funcs = {
	.backend_init = smu10_hwmgr_backend_init,
	.backend_fini = smu10_hwmgr_backend_fini,
1031
	.asic_setup = NULL,
R
Rex Zhu 已提交
1032 1033 1034
	.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,
1035 1036 1037
	.powerdown_uvd = NULL,
	.powergate_uvd = NULL,
	.powergate_vce = NULL,
R
Rex Zhu 已提交
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
	.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,
1052
	.set_watermarks_for_clocks_ranges = smu10_set_watermarks_for_clocks_ranges,
R
Rex Zhu 已提交
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062
	.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,
1063 1064
};

R
Rex Zhu 已提交
1065
int smu10_init_function_pointers(struct pp_hwmgr *hwmgr)
1066
{
R
Rex Zhu 已提交
1067
	hwmgr->hwmgr_func = &smu10_hwmgr_funcs;
1068 1069 1070
	hwmgr->pptable_func = &pptable_funcs;
	return 0;
}