drm/exynos: Stop using drm_framebuffer_unregister_private
[linux/fpc-iii.git] / drivers / gpu / drm / amd / powerplay / smumgr / polaris10_smumgr.c
blobf38a68747df00f68d9e695be6e351d247a211bd7
1 /*
2 * Copyright 2015 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
24 #include "smumgr.h"
25 #include "smu74.h"
26 #include "smu_ucode_xfer_vi.h"
27 #include "polaris10_smumgr.h"
28 #include "smu74_discrete.h"
29 #include "smu/smu_7_1_3_d.h"
30 #include "smu/smu_7_1_3_sh_mask.h"
31 #include "gmc/gmc_8_1_d.h"
32 #include "gmc/gmc_8_1_sh_mask.h"
33 #include "oss/oss_3_0_d.h"
34 #include "gca/gfx_8_0_d.h"
35 #include "bif/bif_5_0_d.h"
36 #include "bif/bif_5_0_sh_mask.h"
37 #include "polaris10_pwrvirus.h"
38 #include "ppatomctrl.h"
39 #include "pp_debug.h"
40 #include "cgs_common.h"
41 #include "polaris10_smc.h"
42 #include "smu7_ppsmc.h"
43 #include "smu7_smumgr.h"
45 #define PPPOLARIS10_TARGETACTIVITY_DFLT 50
47 static const SMU74_Discrete_GraphicsLevel avfs_graphics_level_polaris10[8] = {
48 /* Min pcie DeepSleep Activity CgSpll CgSpll CcPwr CcPwr Sclk Enabled Enabled Voltage Power */
49 /* Voltage, DpmLevel, DivId, Level, FuncCntl3, FuncCntl4, DynRm, DynRm1 Did, Padding,ForActivity, ForThrottle, UpHyst, DownHyst, DownHyst, Throttle */
50 { 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 } },
51 { 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 } },
52 { 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 } },
53 { 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 } },
54 { 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 } },
55 { 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 } },
56 { 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 } },
57 { 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 } }
60 static const SMU74_Discrete_MemoryLevel avfs_memory_level_polaris10 = {
61 0x100ea446, 0, 0x30750000, 0x01, 0x01, 0x01, 0x00, 0x00, 0x64, 0x00, 0x00, 0x1f00, 0x00, 0x00};
64 static int polaris10_setup_pwr_virus(struct pp_smumgr *smumgr)
66 int i;
67 int result = -1;
68 uint32_t reg, data;
70 const PWR_Command_Table *pvirus = pwr_virus_table;
71 struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(smumgr->backend);
74 for (i = 0; i < PWR_VIRUS_TABLE_SIZE; i++) {
75 switch (pvirus->command) {
76 case PwrCmdWrite:
77 reg = pvirus->reg;
78 data = pvirus->data;
79 cgs_write_register(smumgr->device, reg, data);
80 break;
82 case PwrCmdEnd:
83 result = 0;
84 break;
86 default:
87 printk("Table Exit with Invalid Command!");
88 smu_data->avfs.avfs_btc_status = AVFS_BTC_VIRUS_FAIL;
89 result = -1;
90 break;
92 pvirus++;
95 return result;
98 static int polaris10_perform_btc(struct pp_smumgr *smumgr)
100 int result = 0;
101 struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(smumgr->backend);
103 if (0 != smu_data->avfs.avfs_btc_param) {
104 if (0 != smu7_send_msg_to_smc_with_parameter(smumgr, PPSMC_MSG_PerformBtc, smu_data->avfs.avfs_btc_param)) {
105 printk("[AVFS][SmuPolaris10_PerformBtc] PerformBTC SMU msg failed");
106 result = -1;
109 if (smu_data->avfs.avfs_btc_param > 1) {
110 /* Soft-Reset to reset the engine before loading uCode */
111 /* halt */
112 cgs_write_register(smumgr->device, mmCP_MEC_CNTL, 0x50000000);
113 /* reset everything */
114 cgs_write_register(smumgr->device, mmGRBM_SOFT_RESET, 0xffffffff);
115 cgs_write_register(smumgr->device, mmGRBM_SOFT_RESET, 0);
117 return result;
121 static int polaris10_setup_graphics_level_structure(struct pp_smumgr *smumgr)
123 uint32_t vr_config;
124 uint32_t dpm_table_start;
126 uint16_t u16_boot_mvdd;
127 uint32_t graphics_level_address, vr_config_address, graphics_level_size;
129 graphics_level_size = sizeof(avfs_graphics_level_polaris10);
130 u16_boot_mvdd = PP_HOST_TO_SMC_US(1300 * VOLTAGE_SCALE);
132 PP_ASSERT_WITH_CODE(0 == smu7_read_smc_sram_dword(smumgr,
133 SMU7_FIRMWARE_HEADER_LOCATION + offsetof(SMU74_Firmware_Header, DpmTable),
134 &dpm_table_start, 0x40000),
135 "[AVFS][Polaris10_SetupGfxLvlStruct] SMU could not communicate starting address of DPM table",
136 return -1);
138 /* Default value for VRConfig = VR_MERGED_WITH_VDDC + VR_STATIC_VOLTAGE(VDDCI) */
139 vr_config = 0x01000500; /* Real value:0x50001 */
141 vr_config_address = dpm_table_start + offsetof(SMU74_Discrete_DpmTable, VRConfig);
143 PP_ASSERT_WITH_CODE(0 == smu7_copy_bytes_to_smc(smumgr, vr_config_address,
144 (uint8_t *)&vr_config, sizeof(uint32_t), 0x40000),
145 "[AVFS][Polaris10_SetupGfxLvlStruct] Problems copying VRConfig value over to SMC",
146 return -1);
148 graphics_level_address = dpm_table_start + offsetof(SMU74_Discrete_DpmTable, GraphicsLevel);
150 PP_ASSERT_WITH_CODE(0 == smu7_copy_bytes_to_smc(smumgr, graphics_level_address,
151 (uint8_t *)(&avfs_graphics_level_polaris10),
152 graphics_level_size, 0x40000),
153 "[AVFS][Polaris10_SetupGfxLvlStruct] Copying of SCLK DPM table failed!",
154 return -1);
156 graphics_level_address = dpm_table_start + offsetof(SMU74_Discrete_DpmTable, MemoryLevel);
158 PP_ASSERT_WITH_CODE(0 == smu7_copy_bytes_to_smc(smumgr, graphics_level_address,
159 (uint8_t *)(&avfs_memory_level_polaris10), sizeof(avfs_memory_level_polaris10), 0x40000),
160 "[AVFS][Polaris10_SetupGfxLvlStruct] Copying of MCLK DPM table failed!",
161 return -1);
163 /* MVDD Boot value - neccessary for getting rid of the hang that occurs during Mclk DPM enablement */
165 graphics_level_address = dpm_table_start + offsetof(SMU74_Discrete_DpmTable, BootMVdd);
167 PP_ASSERT_WITH_CODE(0 == smu7_copy_bytes_to_smc(smumgr, graphics_level_address,
168 (uint8_t *)(&u16_boot_mvdd), sizeof(u16_boot_mvdd), 0x40000),
169 "[AVFS][Polaris10_SetupGfxLvlStruct] Copying of DPM table failed!",
170 return -1);
172 return 0;
175 static int
176 polaris10_avfs_event_mgr(struct pp_smumgr *smumgr, bool SMU_VFT_INTACT)
178 struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(smumgr->backend);
180 switch (smu_data->avfs.avfs_btc_status) {
181 case AVFS_BTC_COMPLETED_PREVIOUSLY:
182 break;
184 case AVFS_BTC_BOOT: /* Cold Boot State - Post SMU Start */
186 smu_data->avfs.avfs_btc_status = AVFS_BTC_DPMTABLESETUP_FAILED;
187 PP_ASSERT_WITH_CODE(0 == polaris10_setup_graphics_level_structure(smumgr),
188 "[AVFS][Polaris10_AVFSEventMgr] Could not Copy Graphics Level table over to SMU",
189 return -1);
191 if (smu_data->avfs.avfs_btc_param > 1) {
192 printk("[AVFS][Polaris10_AVFSEventMgr] AC BTC has not been successfully verified on Fiji. There may be in this setting.");
193 smu_data->avfs.avfs_btc_status = AVFS_BTC_VIRUS_FAIL;
194 PP_ASSERT_WITH_CODE(-1 == polaris10_setup_pwr_virus(smumgr),
195 "[AVFS][Polaris10_AVFSEventMgr] Could not setup Pwr Virus for AVFS ",
196 return -1);
199 smu_data->avfs.avfs_btc_status = AVFS_BTC_FAILED;
200 PP_ASSERT_WITH_CODE(0 == polaris10_perform_btc(smumgr),
201 "[AVFS][Polaris10_AVFSEventMgr] Failure at SmuPolaris10_PerformBTC. AVFS Disabled",
202 return -1);
204 break;
206 case AVFS_BTC_DISABLED:
207 case AVFS_BTC_NOTSUPPORTED:
208 break;
210 default:
211 printk("[AVFS] Something is broken. See log!");
212 break;
215 return 0;
218 static int polaris10_start_smu_in_protection_mode(struct pp_smumgr *smumgr)
220 int result = 0;
222 /* Wait for smc boot up */
223 /* SMUM_WAIT_VFPF_INDIRECT_FIELD_UNEQUAL(smumgr, SMC_IND, RCU_UC_EVENTS, boot_seq_done, 0) */
225 /* Assert reset */
226 SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
227 SMC_SYSCON_RESET_CNTL, rst_reg, 1);
229 result = smu7_upload_smu_firmware_image(smumgr);
230 if (result != 0)
231 return result;
233 /* Clear status */
234 cgs_write_ind_register(smumgr->device, CGS_IND_REG__SMC, ixSMU_STATUS, 0);
236 SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
237 SMC_SYSCON_CLOCK_CNTL_0, ck_disable, 0);
239 /* De-assert reset */
240 SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
241 SMC_SYSCON_RESET_CNTL, rst_reg, 0);
244 SMUM_WAIT_VFPF_INDIRECT_FIELD(smumgr, SMC_IND, RCU_UC_EVENTS, INTERRUPTS_ENABLED, 1);
247 /* Call Test SMU message with 0x20000 offset to trigger SMU start */
248 smu7_send_msg_to_smc_offset(smumgr);
250 /* Wait done bit to be set */
251 /* Check pass/failed indicator */
253 SMUM_WAIT_VFPF_INDIRECT_FIELD_UNEQUAL(smumgr, SMC_IND, SMU_STATUS, SMU_DONE, 0);
255 if (1 != SMUM_READ_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
256 SMU_STATUS, SMU_PASS))
257 PP_ASSERT_WITH_CODE(false, "SMU Firmware start failed!", return -1);
259 cgs_write_ind_register(smumgr->device, CGS_IND_REG__SMC, ixFIRMWARE_FLAGS, 0);
261 SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
262 SMC_SYSCON_RESET_CNTL, rst_reg, 1);
264 SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
265 SMC_SYSCON_RESET_CNTL, rst_reg, 0);
267 /* Wait for firmware to initialize */
268 SMUM_WAIT_VFPF_INDIRECT_FIELD(smumgr, SMC_IND, FIRMWARE_FLAGS, INTERRUPTS_ENABLED, 1);
270 return result;
273 static int polaris10_start_smu_in_non_protection_mode(struct pp_smumgr *smumgr)
275 int result = 0;
277 /* wait for smc boot up */
278 SMUM_WAIT_VFPF_INDIRECT_FIELD_UNEQUAL(smumgr, SMC_IND, RCU_UC_EVENTS, boot_seq_done, 0);
280 /* Clear firmware interrupt enable flag */
281 /* SMUM_WRITE_VFPF_INDIRECT_FIELD(pSmuMgr, SMC_IND, SMC_SYSCON_MISC_CNTL, pre_fetcher_en, 1); */
282 cgs_write_ind_register(smumgr->device, CGS_IND_REG__SMC,
283 ixFIRMWARE_FLAGS, 0);
285 SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
286 SMC_SYSCON_RESET_CNTL,
287 rst_reg, 1);
289 result = smu7_upload_smu_firmware_image(smumgr);
290 if (result != 0)
291 return result;
293 /* Set smc instruct start point at 0x0 */
294 smu7_program_jump_on_start(smumgr);
296 SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
297 SMC_SYSCON_CLOCK_CNTL_0, ck_disable, 0);
299 SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
300 SMC_SYSCON_RESET_CNTL, rst_reg, 0);
302 /* Wait for firmware to initialize */
304 SMUM_WAIT_VFPF_INDIRECT_FIELD(smumgr, SMC_IND,
305 FIRMWARE_FLAGS, INTERRUPTS_ENABLED, 1);
307 return result;
310 static int polaris10_start_smu(struct pp_smumgr *smumgr)
312 int result = 0;
313 struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(smumgr->backend);
314 bool SMU_VFT_INTACT;
316 /* Only start SMC if SMC RAM is not running */
317 if (!smu7_is_smc_ram_running(smumgr)) {
318 SMU_VFT_INTACT = false;
319 smu_data->protected_mode = (uint8_t) (SMUM_READ_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC, SMU_FIRMWARE, SMU_MODE));
320 smu_data->smu7_data.security_hard_key = (uint8_t) (SMUM_READ_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC, SMU_FIRMWARE, SMU_SEL));
322 /* Check if SMU is running in protected mode */
323 if (smu_data->protected_mode == 0) {
324 result = polaris10_start_smu_in_non_protection_mode(smumgr);
325 } else {
326 result = polaris10_start_smu_in_protection_mode(smumgr);
328 /* If failed, try with different security Key. */
329 if (result != 0) {
330 smu_data->smu7_data.security_hard_key ^= 1;
331 result = polaris10_start_smu_in_protection_mode(smumgr);
335 if (result != 0)
336 PP_ASSERT_WITH_CODE(0, "Failed to load SMU ucode.", return result);
338 polaris10_avfs_event_mgr(smumgr, true);
339 } else
340 SMU_VFT_INTACT = true; /*Driver went offline but SMU was still alive and contains the VFT table */
342 polaris10_avfs_event_mgr(smumgr, SMU_VFT_INTACT);
343 /* Setup SoftRegsStart here for register lookup in case DummyBackEnd is used and ProcessFirmwareHeader is not executed */
344 smu7_read_smc_sram_dword(smumgr, SMU7_FIRMWARE_HEADER_LOCATION + offsetof(SMU74_Firmware_Header, SoftRegisters),
345 &(smu_data->smu7_data.soft_regs_start), 0x40000);
347 result = smu7_request_smu_load_fw(smumgr);
349 return result;
352 static bool polaris10_is_hw_avfs_present(struct pp_smumgr *smumgr)
354 uint32_t efuse;
356 efuse = cgs_read_ind_register(smumgr->device, CGS_IND_REG__SMC, ixSMU_EFUSE_0 + (49*4));
357 efuse &= 0x00000001;
358 if (efuse)
359 return true;
361 return false;
364 static int polaris10_smu_init(struct pp_smumgr *smumgr)
366 struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(smumgr->backend);
367 int i;
369 if (smu7_init(smumgr))
370 return -EINVAL;
372 if (polaris10_is_hw_avfs_present(smumgr))
373 smu_data->avfs.avfs_btc_status = AVFS_BTC_BOOT;
374 else
375 smu_data->avfs.avfs_btc_status = AVFS_BTC_NOTSUPPORTED;
377 for (i = 0; i < SMU74_MAX_LEVELS_GRAPHICS; i++)
378 smu_data->activity_target[i] = PPPOLARIS10_TARGETACTIVITY_DFLT;
380 return 0;
383 static const struct pp_smumgr_func polaris10_smu_funcs = {
384 .smu_init = polaris10_smu_init,
385 .smu_fini = smu7_smu_fini,
386 .start_smu = polaris10_start_smu,
387 .check_fw_load_finish = smu7_check_fw_load_finish,
388 .request_smu_load_fw = smu7_reload_firmware,
389 .request_smu_load_specific_fw = NULL,
390 .send_msg_to_smc = smu7_send_msg_to_smc,
391 .send_msg_to_smc_with_parameter = smu7_send_msg_to_smc_with_parameter,
392 .download_pptable_settings = NULL,
393 .upload_pptable_settings = NULL,
394 .update_smc_table = polaris10_update_smc_table,
395 .get_offsetof = polaris10_get_offsetof,
396 .process_firmware_header = polaris10_process_firmware_header,
397 .init_smc_table = polaris10_init_smc_table,
398 .update_sclk_threshold = polaris10_update_sclk_threshold,
399 .thermal_avfs_enable = polaris10_thermal_avfs_enable,
400 .thermal_setup_fan_table = polaris10_thermal_setup_fan_table,
401 .populate_all_graphic_levels = polaris10_populate_all_graphic_levels,
402 .populate_all_memory_levels = polaris10_populate_all_memory_levels,
403 .get_mac_definition = polaris10_get_mac_definition,
404 .is_dpm_running = polaris10_is_dpm_running,
407 int polaris10_smum_init(struct pp_smumgr *smumgr)
409 struct polaris10_smumgr *polaris10_smu = NULL;
411 polaris10_smu = kzalloc(sizeof(struct polaris10_smumgr), GFP_KERNEL);
413 if (polaris10_smu == NULL)
414 return -EINVAL;
416 smumgr->backend = polaris10_smu;
417 smumgr->smumgr_funcs = &polaris10_smu_funcs;
419 return 0;