polaris10_smumgr.c 33.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
/*
 * 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 "smumgr.h"
#include "smu74.h"
#include "smu_ucode_xfer_vi.h"
27
#include "polaris10_smumgr.h"
28 29 30 31 32 33 34 35 36
#include "smu74_discrete.h"
#include "smu/smu_7_1_3_d.h"
#include "smu/smu_7_1_3_sh_mask.h"
#include "gmc/gmc_8_1_d.h"
#include "gmc/gmc_8_1_sh_mask.h"
#include "oss/oss_3_0_d.h"
#include "gca/gfx_8_0_d.h"
#include "bif/bif_5_0_d.h"
#include "bif/bif_5_0_sh_mask.h"
37
#include "polaris10_pwrvirus.h"
38 39 40
#include "ppatomctrl.h"
#include "pp_debug.h"
#include "cgs_common.h"
41 42
#include "polaris10_smc.h"
#include "smu7_ppsmc.h"
43

44
#define POLARIS10_SMC_SIZE 0x20000
45 46 47 48 49 50

/* Microcode file is stored in this buffer */
#define BUFFER_SIZE                 80000
#define MAX_STRING_SIZE             15
#define BUFFER_SIZETWO              131072  /* 128 *1024 */

51
#define PPPOLARIS10_TARGETACTIVITY_DFLT                     50
52

53
static const SMU74_Discrete_GraphicsLevel avfs_graphics_level_polaris10[8] = {
54 55
	/*  Min      pcie   DeepSleep Activity  CgSpll      CgSpll    CcPwr  CcPwr  Sclk         Enabled      Enabled                       Voltage    Power */
	/* Voltage, DpmLevel, DivId,  Level,  FuncCntl3,  FuncCntl4,  DynRm, DynRm1 Did, Padding,ForActivity, ForThrottle, UpHyst, DownHyst, DownHyst, Throttle */
56 57 58 59 60 61 62 63
	{ 0x100ea446, 0x00, 0x03, 0x3200, 0, 0, 0, 0, 0, 0, 0x01, 0x01, 0x0a, 0x00, 0x00, 0x00, { 0x30750000, 0x3000, 0, 0x2600, 0, 0, 0x0004, 0x8f02, 0xffff, 0x2f00, 0x300e, 0x2700 } },
	{ 0x400ea446, 0x01, 0x04, 0x3200, 0, 0, 0, 0, 0, 0, 0x01, 0x01, 0x0a, 0x00, 0x00, 0x00, { 0x409c0000, 0x2000, 0, 0x1e00, 1, 1, 0x0004, 0x8300, 0xffff, 0x1f00, 0xcb5e, 0x1a00 } },
	{ 0x740ea446, 0x01, 0x00, 0x3200, 0, 0, 0, 0, 0, 0, 0x01, 0x01, 0x0a, 0x00, 0x00, 0x00, { 0x50c30000, 0x2800, 0, 0x2000, 1, 1, 0x0004, 0x0c02, 0xffff, 0x2700, 0x6433, 0x2100 } },
	{ 0xa40ea446, 0x01, 0x00, 0x3200, 0, 0, 0, 0, 0, 0, 0x01, 0x01, 0x0a, 0x00, 0x00, 0x00, { 0x60ea0000, 0x3000, 0, 0x2600, 1, 1, 0x0004, 0x8f02, 0xffff, 0x2f00, 0x300e, 0x2700 } },
	{ 0xd80ea446, 0x01, 0x00, 0x3200, 0, 0, 0, 0, 0, 0, 0x01, 0x01, 0x0a, 0x00, 0x00, 0x00, { 0x70110100, 0x3800, 0, 0x2c00, 1, 1, 0x0004, 0x1203, 0xffff, 0x3600, 0xc9e2, 0x2e00 } },
	{ 0x3c0fa446, 0x01, 0x00, 0x3200, 0, 0, 0, 0, 0, 0, 0x01, 0x01, 0x0a, 0x00, 0x00, 0x00, { 0x80380100, 0x2000, 0, 0x1e00, 2, 1, 0x0004, 0x8300, 0xffff, 0x1f00, 0xcb5e, 0x1a00 } },
	{ 0x6c0fa446, 0x01, 0x00, 0x3200, 0, 0, 0, 0, 0, 0, 0x01, 0x01, 0x0a, 0x00, 0x00, 0x00, { 0x905f0100, 0x2400, 0, 0x1e00, 2, 1, 0x0004, 0x8901, 0xffff, 0x2300, 0x314c, 0x1d00 } },
	{ 0xa00fa446, 0x01, 0x00, 0x3200, 0, 0, 0, 0, 0, 0, 0x01, 0x01, 0x0a, 0x00, 0x00, 0x00, { 0xa0860100, 0x2800, 0, 0x2000, 2, 1, 0x0004, 0x0c02, 0xffff, 0x2700, 0x6433, 0x2100 } }
64 65
};

66 67
static const SMU74_Discrete_MemoryLevel avfs_memory_level_polaris10 = {
	0x100ea446, 0, 0x30750000, 0x01, 0x01, 0x01, 0x00, 0x00, 0x64, 0x00, 0x00, 0x1f00, 0x00, 0x00};
68 69 70 71 72 73

/**
* Set the address for reading/writing the SMC SRAM space.
* @param    smumgr  the address of the powerplay hardware manager.
* @param    smcAddress the address in the SMC RAM to access.
*/
74
static int polaris10_set_smc_sram_address(struct pp_smumgr *smumgr, uint32_t smc_addr, uint32_t limit)
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
{
	PP_ASSERT_WITH_CODE((0 == (3 & smc_addr)), "SMC address must be 4 byte aligned.", return -EINVAL);
	PP_ASSERT_WITH_CODE((limit > (smc_addr + 3)), "SMC addr is beyond the SMC RAM area.", return -EINVAL);

	cgs_write_register(smumgr->device, mmSMC_IND_INDEX_11, smc_addr);
	SMUM_WRITE_FIELD(smumgr->device, SMC_IND_ACCESS_CNTL, AUTO_INCREMENT_IND_11, 0);

	return 0;
}

/**
* Copy bytes from SMC RAM space into driver memory.
*
* @param    smumgr  the address of the powerplay SMU manager.
* @param    smc_start_address the start address in the SMC RAM to copy bytes from
* @param    src the byte array to copy the bytes to.
* @param    byte_count the number of bytes to copy.
*/
93
int polaris10_copy_bytes_from_smc(struct pp_smumgr *smumgr, uint32_t smc_start_address, uint32_t *dest, uint32_t byte_count, uint32_t limit)
94 95 96 97 98 99 100 101 102 103 104 105 106
{
	uint32_t data;
	uint32_t addr;
	uint8_t *dest_byte;
	uint8_t i, data_byte[4] = {0};
	uint32_t *pdata = (uint32_t *)&data_byte;

	PP_ASSERT_WITH_CODE((0 == (3 & smc_start_address)), "SMC address must be 4 byte aligned.", return -1;);
	PP_ASSERT_WITH_CODE((limit > (smc_start_address + byte_count)), "SMC address is beyond the SMC RAM area.", return -1);

	addr = smc_start_address;

	while (byte_count >= 4) {
107
		polaris10_read_smc_sram_dword(smumgr, addr, &data, limit);
108 109 110 111 112 113 114 115 116

		*dest = PP_SMC_TO_HOST_UL(data);

		dest += 1;
		byte_count -= 4;
		addr += 4;
	}

	if (byte_count) {
117
		polaris10_read_smc_sram_dword(smumgr, addr, &data, limit);
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
		*pdata = PP_SMC_TO_HOST_UL(data);
	/* Cast dest into byte type in dest_byte.  This way, we don't overflow if the allocated memory is not 4-byte aligned. */
		dest_byte = (uint8_t *)dest;
		for (i = 0; i < byte_count; i++)
			dest_byte[i] = data_byte[i];
	}

	return 0;
}

/**
* Copy bytes from an array into the SMC RAM space.
*
* @param    pSmuMgr  the address of the powerplay SMU manager.
* @param    smc_start_address the start address in the SMC RAM to copy bytes to.
* @param    src the byte array to copy the bytes from.
* @param    byte_count the number of bytes to copy.
*/
136
int polaris10_copy_bytes_to_smc(struct pp_smumgr *smumgr, uint32_t smc_start_address,
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
				const uint8_t *src, uint32_t byte_count, uint32_t limit)
{
	int result;
	uint32_t data = 0;
	uint32_t original_data;
	uint32_t addr = 0;
	uint32_t extra_shift;

	PP_ASSERT_WITH_CODE((0 == (3 & smc_start_address)), "SMC address must be 4 byte aligned.", return -1);
	PP_ASSERT_WITH_CODE((limit > (smc_start_address + byte_count)), "SMC address is beyond the SMC RAM area.", return -1);

	addr = smc_start_address;

	while (byte_count >= 4) {
	/* Bytes are written into the SMC addres space with the MSB first. */
		data = src[0] * 0x1000000 + src[1] * 0x10000 + src[2] * 0x100 + src[3];

154
		result = polaris10_set_smc_sram_address(smumgr, addr, limit);
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169

		if (0 != result)
			return result;

		cgs_write_register(smumgr->device, mmSMC_IND_DATA_11, data);

		src += 4;
		byte_count -= 4;
		addr += 4;
	}

	if (0 != byte_count) {

		data = 0;

170
		result = polaris10_set_smc_sram_address(smumgr, addr, limit);
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189

		if (0 != result)
			return result;


		original_data = cgs_read_register(smumgr->device, mmSMC_IND_DATA_11);

		extra_shift = 8 * (4 - byte_count);

		while (byte_count > 0) {
			/* Bytes are written into the SMC addres space with the MSB first. */
			data = (0x100 * data) + *src++;
			byte_count--;
		}

		data <<= extra_shift;

		data |= (original_data & ~((~0UL) << extra_shift));

190
		result = polaris10_set_smc_sram_address(smumgr, addr, limit);
191 192 193 194 195 196 197 198 199 200 201

		if (0 != result)
			return result;

		cgs_write_register(smumgr->device, mmSMC_IND_DATA_11, data);
	}

	return 0;
}


202
static int polaris10_program_jump_on_start(struct pp_smumgr *smumgr)
203
{
204
	static const unsigned char data[4] = { 0xE0, 0x00, 0x80, 0x40 };
205

206
	polaris10_copy_bytes_to_smc(smumgr, 0x0, data, 4, sizeof(data)+1);
207 208 209 210 211 212 213 214 215

	return 0;
}

/**
* Return if the SMC is currently running.
*
* @param    smumgr  the address of the powerplay hardware manager.
*/
216
bool polaris10_is_smc_ram_running(struct pp_smumgr *smumgr)
217 218 219 220 221
{
	return ((0 == SMUM_READ_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC, SMC_SYSCON_CLOCK_CNTL_0, ck_disable))
	&& (0x20100 <= cgs_read_ind_register(smumgr->device, CGS_IND_REG__SMC, ixSMC_PC_C)));
}

222 223 224 225 226 227 228 229 230 231 232 233
static bool polaris10_is_hw_avfs_present(struct pp_smumgr *smumgr)
{
	uint32_t efuse;

	efuse = cgs_read_ind_register(smumgr->device, CGS_IND_REG__SMC, ixSMU_EFUSE_0 + (49*4));
	efuse &= 0x00000001;
	if (efuse)
		return true;

	return false;
}

234 235 236 237 238 239 240
/**
* Send a message to the SMC, and wait for its response.
*
* @param    smumgr  the address of the powerplay hardware manager.
* @param    msg the message to send.
* @return   The response that came from the SMC.
*/
241
int polaris10_send_msg_to_smc(struct pp_smumgr *smumgr, uint16_t msg)
242
{
243 244
	int ret;

245
	if (!polaris10_is_smc_ram_running(smumgr))
246 247
		return -1;

248

249 250
	SMUM_WAIT_FIELD_UNEQUAL(smumgr, SMC_RESP_0, SMC_RESP, 0);

251
	ret = SMUM_READ_FIELD(smumgr->device, SMC_RESP_0, SMC_RESP);
252

253 254
	if (ret != 1)
		printk("\n failed to send pre message %x ret is %d \n",  msg, ret);
255 256 257 258 259

	cgs_write_register(smumgr->device, mmSMC_MESSAGE_0, msg);

	SMUM_WAIT_FIELD_UNEQUAL(smumgr, SMC_RESP_0, SMC_RESP, 0);

260 261 262 263
	ret = SMUM_READ_FIELD(smumgr->device, SMC_RESP_0, SMC_RESP);

	if (ret != 1)
		printk("\n failed to send message %x ret is %d \n",  msg, ret);
264 265 266 267 268 269 270 271 272 273 274 275

	return 0;
}


/**
* Send a message to the SMC, and do not wait for its response.
*
* @param    smumgr  the address of the powerplay hardware manager.
* @param    msg the message to send.
* @return   Always return 0.
*/
276
int polaris10_send_msg_to_smc_without_waiting(struct pp_smumgr *smumgr, uint16_t msg)
277 278 279 280 281 282 283 284 285 286 287 288 289 290
{
	cgs_write_register(smumgr->device, mmSMC_MESSAGE_0, msg);

	return 0;
}

/**
* Send a message to the SMC with parameter
*
* @param    smumgr:  the address of the powerplay hardware manager.
* @param    msg: the message to send.
* @param    parameter: the parameter to send
* @return   The response that came from the SMC.
*/
291
int polaris10_send_msg_to_smc_with_parameter(struct pp_smumgr *smumgr, uint16_t msg, uint32_t parameter)
292
{
293
	if (!polaris10_is_smc_ram_running(smumgr)) {
294 295 296 297 298 299 300
		return -1;
	}

	SMUM_WAIT_FIELD_UNEQUAL(smumgr, SMC_RESP_0, SMC_RESP, 0);

	cgs_write_register(smumgr->device, mmSMC_MSG_ARG_0, parameter);

301
	return polaris10_send_msg_to_smc(smumgr, msg);
302 303 304 305 306 307 308 309 310 311 312
}


/**
* Send a message to the SMC with parameter, do not wait for response
*
* @param    smumgr:  the address of the powerplay hardware manager.
* @param    msg: the message to send.
* @param    parameter: the parameter to send
* @return   The response that came from the SMC.
*/
313
int polaris10_send_msg_to_smc_with_parameter_without_waiting(struct pp_smumgr *smumgr, uint16_t msg, uint32_t parameter)
314 315 316
{
	cgs_write_register(smumgr->device, mmSMC_MSG_ARG_0, parameter);

317
	return polaris10_send_msg_to_smc_without_waiting(smumgr, msg);
318 319
}

320
int polaris10_send_msg_to_smc_offset(struct pp_smumgr *smumgr)
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
{
	cgs_write_register(smumgr->device, mmSMC_MSG_ARG_0, 0x20000);

	cgs_write_register(smumgr->device, mmSMC_MESSAGE_0, PPSMC_MSG_Test);

	SMUM_WAIT_FIELD_UNEQUAL(smumgr, SMC_RESP_0, SMC_RESP, 0);

	if (1 != SMUM_READ_FIELD(smumgr->device, SMC_RESP_0, SMC_RESP))
		printk("Failed to send Message.\n");

	return 0;
}

/**
* Wait until the SMC is doing nithing. Doing nothing means that the SMC is either turned off or it is sitting on the STOP instruction.
*
* @param    smumgr  the address of the powerplay hardware manager.
* @param    msg the message to send.
* @return   The response that came from the SMC.
*/
341
int polaris10_wait_for_smc_inactive(struct pp_smumgr *smumgr)
342 343
{
	/* If the SMC is not even on it qualifies as inactive. */
344
	if (!polaris10_is_smc_ram_running(smumgr))
345 346 347 348 349 350 351 352 353 354 355 356 357
		return -1;

	SMUM_WAIT_VFPF_INDIRECT_FIELD(smumgr, SMC_IND, SMC_SYSCON_CLOCK_CNTL_0, cken, 0);
	return 0;
}


/**
* Upload the SMC firmware to the SMC microcontroller.
*
* @param    smumgr  the address of the powerplay hardware manager.
* @param    pFirmware the data structure containing the various sections of the firmware.
*/
358
static int polaris10_upload_smc_firmware_data(struct pp_smumgr *smumgr, uint32_t length, uint32_t *src, uint32_t limit)
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
{
	uint32_t byte_count = length;

	PP_ASSERT_WITH_CODE((limit >= byte_count), "SMC address is beyond the SMC RAM area.", return -1);

	cgs_write_register(smumgr->device, mmSMC_IND_INDEX_11, 0x20000);
	SMUM_WRITE_FIELD(smumgr->device, SMC_IND_ACCESS_CNTL, AUTO_INCREMENT_IND_11, 1);

	for (; byte_count >= 4; byte_count -= 4)
		cgs_write_register(smumgr->device, mmSMC_IND_DATA_11, *src++);

	SMUM_WRITE_FIELD(smumgr->device, SMC_IND_ACCESS_CNTL, AUTO_INCREMENT_IND_11, 0);

	PP_ASSERT_WITH_CODE((0 == byte_count), "SMC size must be dividable by 4.", return -1);

	return 0;
}

377
static enum cgs_ucode_id polaris10_convert_fw_type_to_cgs(uint32_t fw_type)
378 379 380 381 382 383 384
{
	enum cgs_ucode_id result = CGS_UCODE_ID_MAXIMUM;

	switch (fw_type) {
	case UCODE_ID_SMU:
		result = CGS_UCODE_ID_SMU;
		break;
385 386 387
	case UCODE_ID_SMU_SK:
		result = CGS_UCODE_ID_SMU_SK;
		break;
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
	case UCODE_ID_SDMA0:
		result = CGS_UCODE_ID_SDMA0;
		break;
	case UCODE_ID_SDMA1:
		result = CGS_UCODE_ID_SDMA1;
		break;
	case UCODE_ID_CP_CE:
		result = CGS_UCODE_ID_CP_CE;
		break;
	case UCODE_ID_CP_PFP:
		result = CGS_UCODE_ID_CP_PFP;
		break;
	case UCODE_ID_CP_ME:
		result = CGS_UCODE_ID_CP_ME;
		break;
	case UCODE_ID_CP_MEC:
		result = CGS_UCODE_ID_CP_MEC;
		break;
	case UCODE_ID_CP_MEC_JT1:
		result = CGS_UCODE_ID_CP_MEC_JT1;
		break;
	case UCODE_ID_CP_MEC_JT2:
		result = CGS_UCODE_ID_CP_MEC_JT2;
		break;
	case UCODE_ID_RLC_G:
		result = CGS_UCODE_ID_RLC_G;
		break;
	default:
		break;
	}

	return result;
}

422
static int polaris10_upload_smu_firmware_image(struct pp_smumgr *smumgr)
423 424
{
	int result = 0;
425
	struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(smumgr->backend);
426 427 428

	struct cgs_firmware_info info = {0};

429 430
	if (smu_data->security_hard_key == 1)
		cgs_get_firmware_info(smumgr->device,
431
			polaris10_convert_fw_type_to_cgs(UCODE_ID_SMU), &info);
432 433
	else
		cgs_get_firmware_info(smumgr->device,
434
			polaris10_convert_fw_type_to_cgs(UCODE_ID_SMU_SK), &info);
435 436

	/* TO DO cgs_init_samu_load_smu(smumgr->device, (uint32_t *)info.kptr, info.image_size, smu_data->post_initial_boot);*/
437
	result = polaris10_upload_smc_firmware_data(smumgr, info.image_size, (uint32_t *)info.kptr, POLARIS10_SMC_SIZE);
438 439 440 441 442 443 444 445 446 447 448

	return result;
}

/**
* Read a 32bit value from the SMC SRAM space.
* ALL PARAMETERS ARE IN HOST BYTE ORDER.
* @param    smumgr  the address of the powerplay hardware manager.
* @param    smcAddress the address in the SMC RAM to access.
* @param    value and output parameter for the data read from the SMC SRAM.
*/
449
int polaris10_read_smc_sram_dword(struct pp_smumgr *smumgr, uint32_t smc_addr, uint32_t *value, uint32_t limit)
450 451 452
{
	int result;

453
	result = polaris10_set_smc_sram_address(smumgr, smc_addr, limit);
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468

	if (result)
		return result;

	*value = cgs_read_register(smumgr->device, mmSMC_IND_DATA_11);
	return 0;
}

/**
* Write a 32bit value to the SMC SRAM space.
* ALL PARAMETERS ARE IN HOST BYTE ORDER.
* @param    smumgr  the address of the powerplay hardware manager.
* @param    smc_addr the address in the SMC RAM to access.
* @param    value to write to the SMC SRAM.
*/
469
int polaris10_write_smc_sram_dword(struct pp_smumgr *smumgr, uint32_t smc_addr, uint32_t value, uint32_t limit)
470 471 472
{
	int result;

473
	result = polaris10_set_smc_sram_address(smumgr, smc_addr, limit);
474 475 476 477 478 479 480 481 482 483

	if (result)
		return result;

	cgs_write_register(smumgr->device, mmSMC_IND_DATA_11, value);

	return 0;
}


484
int polaris10_smu_fini(struct pp_smumgr *smumgr)
485 486 487 488 489
{
	if (smumgr->backend) {
		kfree(smumgr->backend);
		smumgr->backend = NULL;
	}
490
	cgs_rel_firmware(smumgr->device, CGS_UCODE_ID_SMU);
491 492 493 494
	return 0;
}

/* Convert the firmware type to SMU type mask. For MEC, we need to check all MEC related type */
495
static uint32_t polaris10_get_mask_for_firmware_type(uint32_t fw_type)
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
{
	uint32_t result = 0;

	switch (fw_type) {
	case UCODE_ID_SDMA0:
		result = UCODE_ID_SDMA0_MASK;
		break;
	case UCODE_ID_SDMA1:
		result = UCODE_ID_SDMA1_MASK;
		break;
	case UCODE_ID_CP_CE:
		result = UCODE_ID_CP_CE_MASK;
		break;
	case UCODE_ID_CP_PFP:
		result = UCODE_ID_CP_PFP_MASK;
		break;
	case UCODE_ID_CP_ME:
		result = UCODE_ID_CP_ME_MASK;
		break;
	case UCODE_ID_CP_MEC_JT1:
	case UCODE_ID_CP_MEC_JT2:
		result = UCODE_ID_CP_MEC_MASK;
		break;
	case UCODE_ID_RLC_G:
		result = UCODE_ID_RLC_G_MASK;
		break;
	default:
		printk("UCode type is out of range! \n");
		result = 0;
	}

	return result;
}

/* Populate one firmware image to the data structure */

532
static int polaris10_populate_single_firmware_entry(struct pp_smumgr *smumgr,
533 534 535 536 537 538 539
						uint32_t fw_type,
						struct SMU_Entry *entry)
{
	int result = 0;
	struct cgs_firmware_info info = {0};

	result = cgs_get_firmware_info(smumgr->device,
540
				polaris10_convert_fw_type_to_cgs(fw_type),
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
				&info);

	if (!result) {
		entry->version = info.version;
		entry->id = (uint16_t)fw_type;
		entry->image_addr_high = smu_upper_32_bits(info.mc_addr);
		entry->image_addr_low = smu_lower_32_bits(info.mc_addr);
		entry->meta_data_addr_high = 0;
		entry->meta_data_addr_low = 0;
		entry->data_size_byte = info.image_size;
		entry->num_register_entries = 0;
	}

	if (fw_type == UCODE_ID_RLC_G)
		entry->flags = 1;
	else
		entry->flags = 0;

	return 0;
}

562
static int polaris10_request_smu_load_fw(struct pp_smumgr *smumgr)
563
{
564
	struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(smumgr->backend);
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
	uint32_t fw_to_load;

	int result = 0;
	struct SMU_DRAMData_TOC *toc;

	if (!smumgr->reload_fw) {
		printk(KERN_INFO "[ powerplay ] skip reloading...\n");
		return 0;
	}

	if (smu_data->soft_regs_start)
		cgs_write_ind_register(smumgr->device, CGS_IND_REG__SMC,
					smu_data->soft_regs_start + offsetof(SMU74_SoftRegisters, UcodeLoadStatus),
					0x0);

580 581
	polaris10_send_msg_to_smc_with_parameter(smumgr, PPSMC_MSG_SMU_DRAM_ADDR_HI, smu_data->smu_buffer.mc_addr_high);
	polaris10_send_msg_to_smc_with_parameter(smumgr, PPSMC_MSG_SMU_DRAM_ADDR_LO, smu_data->smu_buffer.mc_addr_low);
582 583 584 585 586

	toc = (struct SMU_DRAMData_TOC *)smu_data->header;
	toc->num_entries = 0;
	toc->structure_version = 1;

587 588 589 590 591 592 593 594 595
	PP_ASSERT_WITH_CODE(0 == polaris10_populate_single_firmware_entry(smumgr, UCODE_ID_RLC_G, &toc->entry[toc->num_entries++]), "Failed to Get Firmware Entry.", return -1);
	PP_ASSERT_WITH_CODE(0 == polaris10_populate_single_firmware_entry(smumgr, UCODE_ID_CP_CE, &toc->entry[toc->num_entries++]), "Failed to Get Firmware Entry.", return -1);
	PP_ASSERT_WITH_CODE(0 == polaris10_populate_single_firmware_entry(smumgr, UCODE_ID_CP_PFP, &toc->entry[toc->num_entries++]), "Failed to Get Firmware Entry.", return -1);
	PP_ASSERT_WITH_CODE(0 == polaris10_populate_single_firmware_entry(smumgr, UCODE_ID_CP_ME, &toc->entry[toc->num_entries++]), "Failed to Get Firmware Entry.", return -1);
	PP_ASSERT_WITH_CODE(0 == polaris10_populate_single_firmware_entry(smumgr, UCODE_ID_CP_MEC, &toc->entry[toc->num_entries++]), "Failed to Get Firmware Entry.", return -1);
	PP_ASSERT_WITH_CODE(0 == polaris10_populate_single_firmware_entry(smumgr, UCODE_ID_CP_MEC_JT1, &toc->entry[toc->num_entries++]), "Failed to Get Firmware Entry.", return -1);
	PP_ASSERT_WITH_CODE(0 == polaris10_populate_single_firmware_entry(smumgr, UCODE_ID_CP_MEC_JT2, &toc->entry[toc->num_entries++]), "Failed to Get Firmware Entry.", return -1);
	PP_ASSERT_WITH_CODE(0 == polaris10_populate_single_firmware_entry(smumgr, UCODE_ID_SDMA0, &toc->entry[toc->num_entries++]), "Failed to Get Firmware Entry.", return -1);
	PP_ASSERT_WITH_CODE(0 == polaris10_populate_single_firmware_entry(smumgr, UCODE_ID_SDMA1, &toc->entry[toc->num_entries++]), "Failed to Get Firmware Entry.", return -1);
596

597 598
	polaris10_send_msg_to_smc_with_parameter(smumgr, PPSMC_MSG_DRV_DRAM_ADDR_HI, smu_data->header_buffer.mc_addr_high);
	polaris10_send_msg_to_smc_with_parameter(smumgr, PPSMC_MSG_DRV_DRAM_ADDR_LO, smu_data->header_buffer.mc_addr_low);
599 600 601 602 603 604 605 606 607

	fw_to_load = UCODE_ID_RLC_G_MASK
		   + UCODE_ID_SDMA0_MASK
		   + UCODE_ID_SDMA1_MASK
		   + UCODE_ID_CP_CE_MASK
		   + UCODE_ID_CP_ME_MASK
		   + UCODE_ID_CP_PFP_MASK
		   + UCODE_ID_CP_MEC_MASK;

608
	if (polaris10_send_msg_to_smc_with_parameter(smumgr, PPSMC_MSG_LoadUcodes, fw_to_load))
609 610 611 612 613 614
		printk(KERN_ERR "Fail to Request SMU Load uCode");

	return result;
}

/* Check if the FW has been loaded, SMU will not return if loading has not finished. */
615
static int polaris10_check_fw_load_finish(struct pp_smumgr *smumgr, uint32_t fw_type)
616
{
617 618
	struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(smumgr->backend);
	uint32_t fw_mask = polaris10_get_mask_for_firmware_type(fw_type);
619 620 621 622 623 624 625 626 627
	uint32_t ret;
	/* Check SOFT_REGISTERS_TABLE_28.UcodeLoadStatus */
	ret = smum_wait_on_indirect_register(smumgr, mmSMC_IND_INDEX_11,
					smu_data->soft_regs_start + offsetof(SMU74_SoftRegisters, UcodeLoadStatus),
					fw_mask, fw_mask);

	return ret;
}

628
static int polaris10_reload_firmware(struct pp_smumgr *smumgr)
629 630 631 632
{
	return smumgr->smumgr_funcs->start_smu(smumgr);
}

633
static int polaris10_setup_pwr_virus(struct pp_smumgr *smumgr)
634 635 636 637 638
{
	int i;
	int result = -1;
	uint32_t reg, data;

639
	const PWR_Command_Table *pvirus = pwr_virus_table;
640
	struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(smumgr->backend);
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666


	for (i = 0; i < PWR_VIRUS_TABLE_SIZE; i++) {
		switch (pvirus->command) {
		case PwrCmdWrite:
			reg  = pvirus->reg;
			data = pvirus->data;
			cgs_write_register(smumgr->device, reg, data);
			break;

		case PwrCmdEnd:
			result = 0;
			break;

		default:
			printk("Table Exit with Invalid Command!");
			smu_data->avfs.avfs_btc_status = AVFS_BTC_VIRUS_FAIL;
			result = -1;
			break;
		}
		pvirus++;
	}

	return result;
}

667
static int polaris10_perform_btc(struct pp_smumgr *smumgr)
668 669
{
	int result = 0;
670
	struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(smumgr->backend);
671 672

	if (0 != smu_data->avfs.avfs_btc_param) {
673 674
		if (0 != polaris10_send_msg_to_smc_with_parameter(smumgr, PPSMC_MSG_PerformBtc, smu_data->avfs.avfs_btc_param)) {
			printk("[AVFS][SmuPolaris10_PerformBtc] PerformBTC SMU msg failed");
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
			result = -1;
		}
	}
	if (smu_data->avfs.avfs_btc_param > 1) {
		/* Soft-Reset to reset the engine before loading uCode */
		/* halt */
		cgs_write_register(smumgr->device, mmCP_MEC_CNTL, 0x50000000);
		/* reset everything */
		cgs_write_register(smumgr->device, mmGRBM_SOFT_RESET, 0xffffffff);
		cgs_write_register(smumgr->device, mmGRBM_SOFT_RESET, 0);
	}
	return result;
}


690
int polaris10_setup_graphics_level_structure(struct pp_smumgr *smumgr)
691 692 693 694 695 696 697
{
	uint32_t vr_config;
	uint32_t dpm_table_start;

	uint16_t u16_boot_mvdd;
	uint32_t graphics_level_address, vr_config_address, graphics_level_size;

698
	graphics_level_size = sizeof(avfs_graphics_level_polaris10);
699 700
	u16_boot_mvdd = PP_HOST_TO_SMC_US(1300 * VOLTAGE_SCALE);

701
	PP_ASSERT_WITH_CODE(0 == polaris10_read_smc_sram_dword(smumgr,
702 703
				SMU7_FIRMWARE_HEADER_LOCATION + offsetof(SMU74_Firmware_Header, DpmTable),
				&dpm_table_start, 0x40000),
704
			"[AVFS][Polaris10_SetupGfxLvlStruct] SMU could not communicate starting address of DPM table",
705 706 707 708 709 710 711
			return -1);

	/*  Default value for VRConfig = VR_MERGED_WITH_VDDC + VR_STATIC_VOLTAGE(VDDCI) */
	vr_config = 0x01000500; /* Real value:0x50001 */

	vr_config_address = dpm_table_start + offsetof(SMU74_Discrete_DpmTable, VRConfig);

712
	PP_ASSERT_WITH_CODE(0 == polaris10_copy_bytes_to_smc(smumgr, vr_config_address,
713
				(uint8_t *)&vr_config, sizeof(uint32_t), 0x40000),
714
			"[AVFS][Polaris10_SetupGfxLvlStruct] Problems copying VRConfig value over to SMC",
715 716 717 718
			return -1);

	graphics_level_address = dpm_table_start + offsetof(SMU74_Discrete_DpmTable, GraphicsLevel);

719 720
	PP_ASSERT_WITH_CODE(0 == polaris10_copy_bytes_to_smc(smumgr, graphics_level_address,
				(uint8_t *)(&avfs_graphics_level_polaris10),
721
				graphics_level_size, 0x40000),
722
			"[AVFS][Polaris10_SetupGfxLvlStruct] Copying of SCLK DPM table failed!",
723 724 725 726
			return -1);

	graphics_level_address = dpm_table_start + offsetof(SMU74_Discrete_DpmTable, MemoryLevel);

727 728 729
	PP_ASSERT_WITH_CODE(0 == polaris10_copy_bytes_to_smc(smumgr, graphics_level_address,
				(uint8_t *)(&avfs_memory_level_polaris10), sizeof(avfs_memory_level_polaris10), 0x40000),
				"[AVFS][Polaris10_SetupGfxLvlStruct] Copying of MCLK DPM table failed!",
730 731 732 733 734 735
			return -1);

	/* MVDD Boot value - neccessary for getting rid of the hang that occurs during Mclk DPM enablement */

	graphics_level_address = dpm_table_start + offsetof(SMU74_Discrete_DpmTable, BootMVdd);

736
	PP_ASSERT_WITH_CODE(0 == polaris10_copy_bytes_to_smc(smumgr, graphics_level_address,
737
			(uint8_t *)(&u16_boot_mvdd), sizeof(u16_boot_mvdd), 0x40000),
738
			"[AVFS][Polaris10_SetupGfxLvlStruct] Copying of DPM table failed!",
739 740 741 742 743
			return -1);

	return 0;
}

744
int polaris10_avfs_event_mgr(struct pp_smumgr *smumgr, bool SMU_VFT_INTACT)
745
{
746
	struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(smumgr->backend);
747 748 749 750 751 752 753 754

	switch (smu_data->avfs.avfs_btc_status) {
	case AVFS_BTC_COMPLETED_PREVIOUSLY:
		break;

	case AVFS_BTC_BOOT: /* Cold Boot State - Post SMU Start */

		smu_data->avfs.avfs_btc_status = AVFS_BTC_DPMTABLESETUP_FAILED;
755 756
		PP_ASSERT_WITH_CODE(0 == polaris10_setup_graphics_level_structure(smumgr),
		"[AVFS][Polaris10_AVFSEventMgr] Could not Copy Graphics Level table over to SMU",
757 758 759
		return -1);

		if (smu_data->avfs.avfs_btc_param > 1) {
760
			printk("[AVFS][Polaris10_AVFSEventMgr] AC BTC has not been successfully verified on Fiji. There may be in this setting.");
761
			smu_data->avfs.avfs_btc_status = AVFS_BTC_VIRUS_FAIL;
762 763
			PP_ASSERT_WITH_CODE(-1 == polaris10_setup_pwr_virus(smumgr),
			"[AVFS][Polaris10_AVFSEventMgr] Could not setup Pwr Virus for AVFS ",
764 765 766 767
			return -1);
		}

		smu_data->avfs.avfs_btc_status = AVFS_BTC_FAILED;
768 769
		PP_ASSERT_WITH_CODE(0 == polaris10_perform_btc(smumgr),
					"[AVFS][Polaris10_AVFSEventMgr] Failure at SmuPolaris10_PerformBTC. AVFS Disabled",
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
				 return -1);

		break;

	case AVFS_BTC_DISABLED:
	case AVFS_BTC_NOTSUPPORTED:
		break;

	default:
		printk("[AVFS] Something is broken. See log!");
		break;
	}

	return 0;
}

786
static int polaris10_start_smu_in_protection_mode(struct pp_smumgr *smumgr)
787 788 789 790 791 792 793 794 795 796
{
	int result = 0;

	/* Wait for smc boot up */
	/* SMUM_WAIT_VFPF_INDIRECT_FIELD_UNEQUAL(smumgr, SMC_IND, RCU_UC_EVENTS, boot_seq_done, 0) */

	/* Assert reset */
	SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
					SMC_SYSCON_RESET_CNTL, rst_reg, 1);

797
	result = polaris10_upload_smu_firmware_image(smumgr);
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
	if (result != 0)
		return result;

	/* Clear status */
	cgs_write_ind_register(smumgr->device, CGS_IND_REG__SMC, ixSMU_STATUS, 0);

	SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
					SMC_SYSCON_CLOCK_CNTL_0, ck_disable, 0);

	/* De-assert reset */
	SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
					SMC_SYSCON_RESET_CNTL, rst_reg, 0);


	SMUM_WAIT_VFPF_INDIRECT_FIELD(smumgr, SMC_IND, RCU_UC_EVENTS, INTERRUPTS_ENABLED, 1);


	/* Call Test SMU message with 0x20000 offset to trigger SMU start */
816
	polaris10_send_msg_to_smc_offset(smumgr);
817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840

	/* Wait done bit to be set */
	/* Check pass/failed indicator */

	SMUM_WAIT_VFPF_INDIRECT_FIELD_UNEQUAL(smumgr, SMC_IND, SMU_STATUS, SMU_DONE, 0);

	if (1 != SMUM_READ_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
						SMU_STATUS, SMU_PASS))
		PP_ASSERT_WITH_CODE(false, "SMU Firmware start failed!", return -1);

	cgs_write_ind_register(smumgr->device, CGS_IND_REG__SMC, ixFIRMWARE_FLAGS, 0);

	SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
					SMC_SYSCON_RESET_CNTL, rst_reg, 1);

	SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
					SMC_SYSCON_RESET_CNTL, rst_reg, 0);

	/* Wait for firmware to initialize */
	SMUM_WAIT_VFPF_INDIRECT_FIELD(smumgr, SMC_IND, FIRMWARE_FLAGS, INTERRUPTS_ENABLED, 1);

	return result;
}

841
static int polaris10_start_smu_in_non_protection_mode(struct pp_smumgr *smumgr)
842 843 844 845 846 847 848 849 850 851 852 853 854 855 856
{
	int result = 0;

	/* wait for smc boot up */
	SMUM_WAIT_VFPF_INDIRECT_FIELD_UNEQUAL(smumgr, SMC_IND, RCU_UC_EVENTS, boot_seq_done, 0);

	/* Clear firmware interrupt enable flag */
	/* SMUM_WRITE_VFPF_INDIRECT_FIELD(pSmuMgr, SMC_IND, SMC_SYSCON_MISC_CNTL, pre_fetcher_en, 1); */
	cgs_write_ind_register(smumgr->device, CGS_IND_REG__SMC,
				ixFIRMWARE_FLAGS, 0);

	SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
					SMC_SYSCON_RESET_CNTL,
					rst_reg, 1);

857
	result = polaris10_upload_smu_firmware_image(smumgr);
858 859 860 861
	if (result != 0)
		return result;

	/* Set smc instruct start point at 0x0 */
862
	polaris10_program_jump_on_start(smumgr);
863 864 865 866 867 868 869 870 871 872 873 874 875 876 877

	SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
					SMC_SYSCON_CLOCK_CNTL_0, ck_disable, 0);

	SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
					SMC_SYSCON_RESET_CNTL, rst_reg, 0);

	/* Wait for firmware to initialize */

	SMUM_WAIT_VFPF_INDIRECT_FIELD(smumgr, SMC_IND,
					FIRMWARE_FLAGS, INTERRUPTS_ENABLED, 1);

	return result;
}

878
static int polaris10_start_smu(struct pp_smumgr *smumgr)
879 880
{
	int result = 0;
881
	struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(smumgr->backend);
882 883 884
	bool SMU_VFT_INTACT;

	/* Only start SMC if SMC RAM is not running */
885
	if (!polaris10_is_smc_ram_running(smumgr)) {
886
		SMU_VFT_INTACT = false;
887 888 889
		smu_data->protected_mode = (uint8_t) (SMUM_READ_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC, SMU_FIRMWARE, SMU_MODE));
		smu_data->security_hard_key = (uint8_t) (SMUM_READ_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC, SMU_FIRMWARE, SMU_SEL));

890
		/* Check if SMU is running in protected mode */
891
		if (smu_data->protected_mode == 0) {
892
			result = polaris10_start_smu_in_non_protection_mode(smumgr);
893
		} else {
894
			result = polaris10_start_smu_in_protection_mode(smumgr);
895

896 897 898
			/* If failed, try with different security Key. */
			if (result != 0) {
				smu_data->security_hard_key ^= 1;
899
				result = polaris10_start_smu_in_protection_mode(smumgr);
900 901 902
			}
		}

903 904 905
		if (result != 0)
			PP_ASSERT_WITH_CODE(0, "Failed to load SMU ucode.", return result);

906
		polaris10_avfs_event_mgr(smumgr, true);
907 908 909 910
	} else
		SMU_VFT_INTACT = true; /*Driver went offline but SMU was still alive and contains the VFT table */

	smu_data->post_initial_boot = true;
911
	polaris10_avfs_event_mgr(smumgr, SMU_VFT_INTACT);
912
	/* Setup SoftRegsStart here for register lookup in case DummyBackEnd is used and ProcessFirmwareHeader is not executed */
913
	polaris10_read_smc_sram_dword(smumgr, SMU7_FIRMWARE_HEADER_LOCATION + offsetof(SMU74_Firmware_Header, SoftRegisters),
914 915
					&(smu_data->soft_regs_start), 0x40000);

916
	result = polaris10_request_smu_load_fw(smumgr);
917 918 919 920

	return result;
}

921
static int polaris10_smu_init(struct pp_smumgr *smumgr)
922
{
923
	struct polaris10_smumgr *smu_data;
924 925
	uint8_t *internal_buf;
	uint64_t mc_addr = 0;
926 927
	int i;

928
	/* Allocate memory for backend private data */
929
	smu_data = (struct polaris10_smumgr *)(smumgr->backend);
930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975
	smu_data->header_buffer.data_size =
		((sizeof(struct SMU_DRAMData_TOC) / 4096) + 1) * 4096;
	smu_data->smu_buffer.data_size = 200*4096;
	smu_data->avfs.avfs_btc_status = AVFS_BTC_NOTSUPPORTED;
/* Allocate FW image data structure and header buffer and
 * send the header buffer address to SMU */
	smu_allocate_memory(smumgr->device,
		smu_data->header_buffer.data_size,
		CGS_GPU_MEM_TYPE__VISIBLE_CONTIG_FB,
		PAGE_SIZE,
		&mc_addr,
		&smu_data->header_buffer.kaddr,
		&smu_data->header_buffer.handle);

	smu_data->header = smu_data->header_buffer.kaddr;
	smu_data->header_buffer.mc_addr_high = smu_upper_32_bits(mc_addr);
	smu_data->header_buffer.mc_addr_low = smu_lower_32_bits(mc_addr);

	PP_ASSERT_WITH_CODE((NULL != smu_data->header),
		"Out of memory.",
		kfree(smumgr->backend);
		cgs_free_gpu_mem(smumgr->device,
		(cgs_handle_t)smu_data->header_buffer.handle);
		return -1);

/* Allocate buffer for SMU internal buffer and send the address to SMU.
 * Iceland SMU does not need internal buffer.*/
	smu_allocate_memory(smumgr->device,
		smu_data->smu_buffer.data_size,
		CGS_GPU_MEM_TYPE__VISIBLE_CONTIG_FB,
		PAGE_SIZE,
		&mc_addr,
		&smu_data->smu_buffer.kaddr,
		&smu_data->smu_buffer.handle);

	internal_buf = smu_data->smu_buffer.kaddr;
	smu_data->smu_buffer.mc_addr_high = smu_upper_32_bits(mc_addr);
	smu_data->smu_buffer.mc_addr_low = smu_lower_32_bits(mc_addr);

	PP_ASSERT_WITH_CODE((NULL != internal_buf),
		"Out of memory.",
		kfree(smumgr->backend);
		cgs_free_gpu_mem(smumgr->device,
		(cgs_handle_t)smu_data->smu_buffer.handle);
		return -1;);

976 977 978 979 980
	if (polaris10_is_hw_avfs_present(smumgr))
		smu_data->avfs.avfs_btc_status = AVFS_BTC_BOOT;
	else
		smu_data->avfs.avfs_btc_status = AVFS_BTC_NOTSUPPORTED;

981 982 983
	for (i = 0; i < SMU74_MAX_LEVELS_GRAPHICS; i++)
		smu_data->activity_target[i] = PPPOLARIS10_TARGETACTIVITY_DFLT;

984 985 986
	return 0;
}

987
static const struct pp_smumgr_func polaris10_smu_funcs = {
988 989 990 991 992
	.smu_init = polaris10_smu_init,
	.smu_fini = polaris10_smu_fini,
	.start_smu = polaris10_start_smu,
	.check_fw_load_finish = polaris10_check_fw_load_finish,
	.request_smu_load_fw = polaris10_reload_firmware,
993
	.request_smu_load_specific_fw = NULL,
994 995
	.send_msg_to_smc = polaris10_send_msg_to_smc,
	.send_msg_to_smc_with_parameter = polaris10_send_msg_to_smc_with_parameter,
996 997
	.download_pptable_settings = NULL,
	.upload_pptable_settings = NULL,
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008
	.update_smc_table = polaris10_update_smc_table,
	.get_offsetof = polaris10_get_offsetof,
	.process_firmware_header = polaris10_process_firmware_header,
	.init_smc_table = polaris10_init_smc_table,
	.update_sclk_threshold = polaris10_update_sclk_threshold,
	.thermal_avfs_enable = polaris10_thermal_avfs_enable,
	.thermal_setup_fan_table = polaris10_thermal_setup_fan_table,
	.populate_all_graphic_levels = polaris10_populate_all_graphic_levels,
	.populate_all_memory_levels = polaris10_populate_all_memory_levels,
	.get_mac_definition = polaris10_get_mac_definition,
	.is_dpm_running = polaris10_is_dpm_running,
1009 1010
};

1011
int polaris10_smum_init(struct pp_smumgr *smumgr)
1012
{
1013
	struct polaris10_smumgr *polaris10_smu = NULL;
1014

1015
	polaris10_smu = kzalloc(sizeof(struct polaris10_smumgr), GFP_KERNEL);
1016

1017
	if (polaris10_smu == NULL)
1018 1019
		return -1;

1020
	smumgr->backend = polaris10_smu;
1021
	smumgr->smumgr_funcs = &polaris10_smu_funcs;
1022 1023 1024

	return 0;
}