polaris10_smumgr.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. /*
  2. * Copyright 2015 Advanced Micro Devices, Inc.
  3. *
  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:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  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.
  21. *
  22. */
  23. #include "pp_debug.h"
  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 "cgs_common.h"
  40. #include "polaris10_smc.h"
  41. #include "smu7_ppsmc.h"
  42. #include "smu7_smumgr.h"
  43. #define PPPOLARIS10_TARGETACTIVITY_DFLT 50
  44. static const SMU74_Discrete_GraphicsLevel avfs_graphics_level_polaris10[8] = {
  45. /* Min pcie DeepSleep Activity CgSpll CgSpll CcPwr CcPwr Sclk Enabled Enabled Voltage Power */
  46. /* Voltage, DpmLevel, DivId, Level, FuncCntl3, FuncCntl4, DynRm, DynRm1 Did, Padding,ForActivity, ForThrottle, UpHyst, DownHyst, DownHyst, Throttle */
  47. { 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 } },
  48. { 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 } },
  49. { 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 } },
  50. { 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 } },
  51. { 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 } },
  52. { 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 } },
  53. { 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 } },
  54. { 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 } }
  55. };
  56. static const SMU74_Discrete_MemoryLevel avfs_memory_level_polaris10 = {
  57. 0x100ea446, 0, 0x30750000, 0x01, 0x01, 0x01, 0x00, 0x00, 0x64, 0x00, 0x00, 0x1f00, 0x00, 0x00};
  58. static int polaris10_setup_pwr_virus(struct pp_smumgr *smumgr)
  59. {
  60. int i;
  61. int result = -1;
  62. uint32_t reg, data;
  63. const PWR_Command_Table *pvirus = pwr_virus_table;
  64. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(smumgr->backend);
  65. for (i = 0; i < PWR_VIRUS_TABLE_SIZE; i++) {
  66. switch (pvirus->command) {
  67. case PwrCmdWrite:
  68. reg = pvirus->reg;
  69. data = pvirus->data;
  70. cgs_write_register(smumgr->device, reg, data);
  71. break;
  72. case PwrCmdEnd:
  73. result = 0;
  74. break;
  75. default:
  76. pr_info("Table Exit with Invalid Command!");
  77. smu_data->avfs.avfs_btc_status = AVFS_BTC_VIRUS_FAIL;
  78. result = -1;
  79. break;
  80. }
  81. pvirus++;
  82. }
  83. return result;
  84. }
  85. static int polaris10_perform_btc(struct pp_smumgr *smumgr)
  86. {
  87. int result = 0;
  88. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(smumgr->backend);
  89. if (0 != smu_data->avfs.avfs_btc_param) {
  90. if (0 != smu7_send_msg_to_smc_with_parameter(smumgr, PPSMC_MSG_PerformBtc, smu_data->avfs.avfs_btc_param)) {
  91. pr_info("[AVFS][SmuPolaris10_PerformBtc] PerformBTC SMU msg failed");
  92. result = -1;
  93. }
  94. }
  95. if (smu_data->avfs.avfs_btc_param > 1) {
  96. /* Soft-Reset to reset the engine before loading uCode */
  97. /* halt */
  98. cgs_write_register(smumgr->device, mmCP_MEC_CNTL, 0x50000000);
  99. /* reset everything */
  100. cgs_write_register(smumgr->device, mmGRBM_SOFT_RESET, 0xffffffff);
  101. cgs_write_register(smumgr->device, mmGRBM_SOFT_RESET, 0);
  102. }
  103. return result;
  104. }
  105. static int polaris10_setup_graphics_level_structure(struct pp_smumgr *smumgr)
  106. {
  107. uint32_t vr_config;
  108. uint32_t dpm_table_start;
  109. uint16_t u16_boot_mvdd;
  110. uint32_t graphics_level_address, vr_config_address, graphics_level_size;
  111. graphics_level_size = sizeof(avfs_graphics_level_polaris10);
  112. u16_boot_mvdd = PP_HOST_TO_SMC_US(1300 * VOLTAGE_SCALE);
  113. PP_ASSERT_WITH_CODE(0 == smu7_read_smc_sram_dword(smumgr,
  114. SMU7_FIRMWARE_HEADER_LOCATION + offsetof(SMU74_Firmware_Header, DpmTable),
  115. &dpm_table_start, 0x40000),
  116. "[AVFS][Polaris10_SetupGfxLvlStruct] SMU could not communicate starting address of DPM table",
  117. return -1);
  118. /* Default value for VRConfig = VR_MERGED_WITH_VDDC + VR_STATIC_VOLTAGE(VDDCI) */
  119. vr_config = 0x01000500; /* Real value:0x50001 */
  120. vr_config_address = dpm_table_start + offsetof(SMU74_Discrete_DpmTable, VRConfig);
  121. PP_ASSERT_WITH_CODE(0 == smu7_copy_bytes_to_smc(smumgr, vr_config_address,
  122. (uint8_t *)&vr_config, sizeof(uint32_t), 0x40000),
  123. "[AVFS][Polaris10_SetupGfxLvlStruct] Problems copying VRConfig value over to SMC",
  124. return -1);
  125. graphics_level_address = dpm_table_start + offsetof(SMU74_Discrete_DpmTable, GraphicsLevel);
  126. PP_ASSERT_WITH_CODE(0 == smu7_copy_bytes_to_smc(smumgr, graphics_level_address,
  127. (uint8_t *)(&avfs_graphics_level_polaris10),
  128. graphics_level_size, 0x40000),
  129. "[AVFS][Polaris10_SetupGfxLvlStruct] Copying of SCLK DPM table failed!",
  130. return -1);
  131. graphics_level_address = dpm_table_start + offsetof(SMU74_Discrete_DpmTable, MemoryLevel);
  132. PP_ASSERT_WITH_CODE(0 == smu7_copy_bytes_to_smc(smumgr, graphics_level_address,
  133. (uint8_t *)(&avfs_memory_level_polaris10), sizeof(avfs_memory_level_polaris10), 0x40000),
  134. "[AVFS][Polaris10_SetupGfxLvlStruct] Copying of MCLK DPM table failed!",
  135. return -1);
  136. /* MVDD Boot value - neccessary for getting rid of the hang that occurs during Mclk DPM enablement */
  137. graphics_level_address = dpm_table_start + offsetof(SMU74_Discrete_DpmTable, BootMVdd);
  138. PP_ASSERT_WITH_CODE(0 == smu7_copy_bytes_to_smc(smumgr, graphics_level_address,
  139. (uint8_t *)(&u16_boot_mvdd), sizeof(u16_boot_mvdd), 0x40000),
  140. "[AVFS][Polaris10_SetupGfxLvlStruct] Copying of DPM table failed!",
  141. return -1);
  142. return 0;
  143. }
  144. static int
  145. polaris10_avfs_event_mgr(struct pp_smumgr *smumgr, bool SMU_VFT_INTACT)
  146. {
  147. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(smumgr->backend);
  148. switch (smu_data->avfs.avfs_btc_status) {
  149. case AVFS_BTC_COMPLETED_PREVIOUSLY:
  150. break;
  151. case AVFS_BTC_BOOT: /* Cold Boot State - Post SMU Start */
  152. smu_data->avfs.avfs_btc_status = AVFS_BTC_DPMTABLESETUP_FAILED;
  153. PP_ASSERT_WITH_CODE(0 == polaris10_setup_graphics_level_structure(smumgr),
  154. "[AVFS][Polaris10_AVFSEventMgr] Could not Copy Graphics Level table over to SMU",
  155. return -1);
  156. if (smu_data->avfs.avfs_btc_param > 1) {
  157. pr_info("[AVFS][Polaris10_AVFSEventMgr] AC BTC has not been successfully verified on Fiji. There may be in this setting.");
  158. smu_data->avfs.avfs_btc_status = AVFS_BTC_VIRUS_FAIL;
  159. PP_ASSERT_WITH_CODE(-1 == polaris10_setup_pwr_virus(smumgr),
  160. "[AVFS][Polaris10_AVFSEventMgr] Could not setup Pwr Virus for AVFS ",
  161. return -1);
  162. }
  163. smu_data->avfs.avfs_btc_status = AVFS_BTC_FAILED;
  164. PP_ASSERT_WITH_CODE(0 == polaris10_perform_btc(smumgr),
  165. "[AVFS][Polaris10_AVFSEventMgr] Failure at SmuPolaris10_PerformBTC. AVFS Disabled",
  166. return -1);
  167. break;
  168. case AVFS_BTC_DISABLED:
  169. case AVFS_BTC_NOTSUPPORTED:
  170. break;
  171. default:
  172. pr_info("[AVFS] Something is broken. See log!");
  173. break;
  174. }
  175. return 0;
  176. }
  177. static int polaris10_start_smu_in_protection_mode(struct pp_smumgr *smumgr)
  178. {
  179. int result = 0;
  180. /* Wait for smc boot up */
  181. /* SMUM_WAIT_VFPF_INDIRECT_FIELD_UNEQUAL(smumgr, SMC_IND, RCU_UC_EVENTS, boot_seq_done, 0) */
  182. /* Assert reset */
  183. SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
  184. SMC_SYSCON_RESET_CNTL, rst_reg, 1);
  185. result = smu7_upload_smu_firmware_image(smumgr);
  186. if (result != 0)
  187. return result;
  188. /* Clear status */
  189. cgs_write_ind_register(smumgr->device, CGS_IND_REG__SMC, ixSMU_STATUS, 0);
  190. SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
  191. SMC_SYSCON_CLOCK_CNTL_0, ck_disable, 0);
  192. /* De-assert reset */
  193. SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
  194. SMC_SYSCON_RESET_CNTL, rst_reg, 0);
  195. SMUM_WAIT_VFPF_INDIRECT_FIELD(smumgr, SMC_IND, RCU_UC_EVENTS, INTERRUPTS_ENABLED, 1);
  196. /* Call Test SMU message with 0x20000 offset to trigger SMU start */
  197. smu7_send_msg_to_smc_offset(smumgr);
  198. /* Wait done bit to be set */
  199. /* Check pass/failed indicator */
  200. SMUM_WAIT_VFPF_INDIRECT_FIELD_UNEQUAL(smumgr, SMC_IND, SMU_STATUS, SMU_DONE, 0);
  201. if (1 != SMUM_READ_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
  202. SMU_STATUS, SMU_PASS))
  203. PP_ASSERT_WITH_CODE(false, "SMU Firmware start failed!", return -1);
  204. cgs_write_ind_register(smumgr->device, CGS_IND_REG__SMC, ixFIRMWARE_FLAGS, 0);
  205. SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
  206. SMC_SYSCON_RESET_CNTL, rst_reg, 1);
  207. SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
  208. SMC_SYSCON_RESET_CNTL, rst_reg, 0);
  209. /* Wait for firmware to initialize */
  210. SMUM_WAIT_VFPF_INDIRECT_FIELD(smumgr, SMC_IND, FIRMWARE_FLAGS, INTERRUPTS_ENABLED, 1);
  211. return result;
  212. }
  213. static int polaris10_start_smu_in_non_protection_mode(struct pp_smumgr *smumgr)
  214. {
  215. int result = 0;
  216. /* wait for smc boot up */
  217. SMUM_WAIT_VFPF_INDIRECT_FIELD_UNEQUAL(smumgr, SMC_IND, RCU_UC_EVENTS, boot_seq_done, 0);
  218. /* Clear firmware interrupt enable flag */
  219. /* SMUM_WRITE_VFPF_INDIRECT_FIELD(pSmuMgr, SMC_IND, SMC_SYSCON_MISC_CNTL, pre_fetcher_en, 1); */
  220. cgs_write_ind_register(smumgr->device, CGS_IND_REG__SMC,
  221. ixFIRMWARE_FLAGS, 0);
  222. SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
  223. SMC_SYSCON_RESET_CNTL,
  224. rst_reg, 1);
  225. result = smu7_upload_smu_firmware_image(smumgr);
  226. if (result != 0)
  227. return result;
  228. /* Set smc instruct start point at 0x0 */
  229. smu7_program_jump_on_start(smumgr);
  230. SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
  231. SMC_SYSCON_CLOCK_CNTL_0, ck_disable, 0);
  232. SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
  233. SMC_SYSCON_RESET_CNTL, rst_reg, 0);
  234. /* Wait for firmware to initialize */
  235. SMUM_WAIT_VFPF_INDIRECT_FIELD(smumgr, SMC_IND,
  236. FIRMWARE_FLAGS, INTERRUPTS_ENABLED, 1);
  237. return result;
  238. }
  239. static int polaris10_start_smu(struct pp_smumgr *smumgr)
  240. {
  241. int result = 0;
  242. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(smumgr->backend);
  243. bool SMU_VFT_INTACT;
  244. /* Only start SMC if SMC RAM is not running */
  245. if (!smu7_is_smc_ram_running(smumgr)) {
  246. SMU_VFT_INTACT = false;
  247. smu_data->protected_mode = (uint8_t) (SMUM_READ_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC, SMU_FIRMWARE, SMU_MODE));
  248. smu_data->smu7_data.security_hard_key = (uint8_t) (SMUM_READ_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC, SMU_FIRMWARE, SMU_SEL));
  249. /* Check if SMU is running in protected mode */
  250. if (smu_data->protected_mode == 0) {
  251. result = polaris10_start_smu_in_non_protection_mode(smumgr);
  252. } else {
  253. result = polaris10_start_smu_in_protection_mode(smumgr);
  254. /* If failed, try with different security Key. */
  255. if (result != 0) {
  256. smu_data->smu7_data.security_hard_key ^= 1;
  257. cgs_rel_firmware(smumgr->device, CGS_UCODE_ID_SMU);
  258. result = polaris10_start_smu_in_protection_mode(smumgr);
  259. }
  260. }
  261. if (result != 0)
  262. PP_ASSERT_WITH_CODE(0, "Failed to load SMU ucode.", return result);
  263. polaris10_avfs_event_mgr(smumgr, true);
  264. } else
  265. SMU_VFT_INTACT = true; /*Driver went offline but SMU was still alive and contains the VFT table */
  266. polaris10_avfs_event_mgr(smumgr, SMU_VFT_INTACT);
  267. /* Setup SoftRegsStart here for register lookup in case DummyBackEnd is used and ProcessFirmwareHeader is not executed */
  268. smu7_read_smc_sram_dword(smumgr, SMU7_FIRMWARE_HEADER_LOCATION + offsetof(SMU74_Firmware_Header, SoftRegisters),
  269. &(smu_data->smu7_data.soft_regs_start), 0x40000);
  270. result = smu7_request_smu_load_fw(smumgr);
  271. return result;
  272. }
  273. static bool polaris10_is_hw_avfs_present(struct pp_smumgr *smumgr)
  274. {
  275. uint32_t efuse;
  276. efuse = cgs_read_ind_register(smumgr->device, CGS_IND_REG__SMC, ixSMU_EFUSE_0 + (49*4));
  277. efuse &= 0x00000001;
  278. if (efuse)
  279. return true;
  280. return false;
  281. }
  282. static int polaris10_smu_init(struct pp_smumgr *smumgr)
  283. {
  284. struct polaris10_smumgr *smu_data;
  285. int i;
  286. smu_data = kzalloc(sizeof(struct polaris10_smumgr), GFP_KERNEL);
  287. if (smu_data == NULL)
  288. return -ENOMEM;
  289. smumgr->backend = smu_data;
  290. if (smu7_init(smumgr))
  291. return -EINVAL;
  292. if (polaris10_is_hw_avfs_present(smumgr))
  293. smu_data->avfs.avfs_btc_status = AVFS_BTC_BOOT;
  294. else
  295. smu_data->avfs.avfs_btc_status = AVFS_BTC_NOTSUPPORTED;
  296. for (i = 0; i < SMU74_MAX_LEVELS_GRAPHICS; i++)
  297. smu_data->activity_target[i] = PPPOLARIS10_TARGETACTIVITY_DFLT;
  298. return 0;
  299. }
  300. const struct pp_smumgr_func polaris10_smu_funcs = {
  301. .smu_init = polaris10_smu_init,
  302. .smu_fini = smu7_smu_fini,
  303. .start_smu = polaris10_start_smu,
  304. .check_fw_load_finish = smu7_check_fw_load_finish,
  305. .request_smu_load_fw = smu7_reload_firmware,
  306. .request_smu_load_specific_fw = NULL,
  307. .send_msg_to_smc = smu7_send_msg_to_smc,
  308. .send_msg_to_smc_with_parameter = smu7_send_msg_to_smc_with_parameter,
  309. .download_pptable_settings = NULL,
  310. .upload_pptable_settings = NULL,
  311. .update_smc_table = polaris10_update_smc_table,
  312. .get_offsetof = polaris10_get_offsetof,
  313. .process_firmware_header = polaris10_process_firmware_header,
  314. .init_smc_table = polaris10_init_smc_table,
  315. .update_sclk_threshold = polaris10_update_sclk_threshold,
  316. .thermal_avfs_enable = polaris10_thermal_avfs_enable,
  317. .thermal_setup_fan_table = polaris10_thermal_setup_fan_table,
  318. .populate_all_graphic_levels = polaris10_populate_all_graphic_levels,
  319. .populate_all_memory_levels = polaris10_populate_all_memory_levels,
  320. .get_mac_definition = polaris10_get_mac_definition,
  321. .is_dpm_running = polaris10_is_dpm_running,
  322. .populate_requested_graphic_levels = polaris10_populate_requested_graphic_levels,
  323. };