vegam_smumgr.c 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302
  1. /*
  2. * Copyright 2017 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 "smu_ucode_xfer_vi.h"
  26. #include "vegam_smumgr.h"
  27. #include "smu/smu_7_1_3_d.h"
  28. #include "smu/smu_7_1_3_sh_mask.h"
  29. #include "gmc/gmc_8_1_d.h"
  30. #include "gmc/gmc_8_1_sh_mask.h"
  31. #include "oss/oss_3_0_d.h"
  32. #include "gca/gfx_8_0_d.h"
  33. #include "bif/bif_5_0_d.h"
  34. #include "bif/bif_5_0_sh_mask.h"
  35. #include "ppatomctrl.h"
  36. #include "cgs_common.h"
  37. #include "smu7_ppsmc.h"
  38. #include "smu7_dyn_defaults.h"
  39. #include "smu7_hwmgr.h"
  40. #include "hardwaremanager.h"
  41. #include "ppatomctrl.h"
  42. #include "atombios.h"
  43. #include "pppcielanes.h"
  44. #include "dce/dce_11_2_d.h"
  45. #include "dce/dce_11_2_sh_mask.h"
  46. #define PPVEGAM_TARGETACTIVITY_DFLT 50
  47. #define VOLTAGE_VID_OFFSET_SCALE1 625
  48. #define VOLTAGE_VID_OFFSET_SCALE2 100
  49. #define POWERTUNE_DEFAULT_SET_MAX 1
  50. #define VDDC_VDDCI_DELTA 200
  51. #define MC_CG_ARB_FREQ_F1 0x0b
  52. #define STRAP_ASIC_RO_LSB 2168
  53. #define STRAP_ASIC_RO_MSB 2175
  54. #define PPSMC_MSG_ApplyAvfsCksOffVoltage ((uint16_t) 0x415)
  55. #define PPSMC_MSG_EnableModeSwitchRLCNotification ((uint16_t) 0x305)
  56. static const struct vegam_pt_defaults
  57. vegam_power_tune_data_set_array[POWERTUNE_DEFAULT_SET_MAX] = {
  58. /* sviLoadLIneEn, SviLoadLineVddC, TDC_VDDC_ThrottleReleaseLimitPerc, TDC_MAWt,
  59. * TdcWaterfallCtl, DTEAmbientTempBase, DisplayCac, BAPM_TEMP_GRADIENT */
  60. { 1, 0xF, 0xFD, 0x19, 5, 45, 0, 0xB0000,
  61. { 0x79, 0x253, 0x25D, 0xAE, 0x72, 0x80, 0x83, 0x86, 0x6F, 0xC8, 0xC9, 0xC9, 0x2F, 0x4D, 0x61},
  62. { 0x17C, 0x172, 0x180, 0x1BC, 0x1B3, 0x1BD, 0x206, 0x200, 0x203, 0x25D, 0x25A, 0x255, 0x2C3, 0x2C5, 0x2B4 } },
  63. };
  64. static const sclkFcwRange_t Range_Table[NUM_SCLK_RANGE] = {
  65. {VCO_2_4, POSTDIV_DIV_BY_16, 75, 160, 112},
  66. {VCO_3_6, POSTDIV_DIV_BY_16, 112, 224, 160},
  67. {VCO_2_4, POSTDIV_DIV_BY_8, 75, 160, 112},
  68. {VCO_3_6, POSTDIV_DIV_BY_8, 112, 224, 160},
  69. {VCO_2_4, POSTDIV_DIV_BY_4, 75, 160, 112},
  70. {VCO_3_6, POSTDIV_DIV_BY_4, 112, 216, 160},
  71. {VCO_2_4, POSTDIV_DIV_BY_2, 75, 160, 108},
  72. {VCO_3_6, POSTDIV_DIV_BY_2, 112, 216, 160} };
  73. static int vegam_smu_init(struct pp_hwmgr *hwmgr)
  74. {
  75. struct vegam_smumgr *smu_data;
  76. smu_data = kzalloc(sizeof(struct vegam_smumgr), GFP_KERNEL);
  77. if (smu_data == NULL)
  78. return -ENOMEM;
  79. hwmgr->smu_backend = smu_data;
  80. if (smu7_init(hwmgr)) {
  81. kfree(smu_data);
  82. return -EINVAL;
  83. }
  84. return 0;
  85. }
  86. static int vegam_start_smu_in_protection_mode(struct pp_hwmgr *hwmgr)
  87. {
  88. int result = 0;
  89. /* Wait for smc boot up */
  90. /* PHM_WAIT_VFPF_INDIRECT_FIELD_UNEQUAL(smumgr, SMC_IND, RCU_UC_EVENTS, boot_seq_done, 0) */
  91. /* Assert reset */
  92. PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  93. SMC_SYSCON_RESET_CNTL, rst_reg, 1);
  94. result = smu7_upload_smu_firmware_image(hwmgr);
  95. if (result != 0)
  96. return result;
  97. /* Clear status */
  98. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixSMU_STATUS, 0);
  99. PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  100. SMC_SYSCON_CLOCK_CNTL_0, ck_disable, 0);
  101. /* De-assert reset */
  102. PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  103. SMC_SYSCON_RESET_CNTL, rst_reg, 0);
  104. PHM_WAIT_VFPF_INDIRECT_FIELD(hwmgr, SMC_IND, RCU_UC_EVENTS, INTERRUPTS_ENABLED, 1);
  105. /* Call Test SMU message with 0x20000 offset to trigger SMU start */
  106. smu7_send_msg_to_smc_offset(hwmgr);
  107. /* Wait done bit to be set */
  108. /* Check pass/failed indicator */
  109. PHM_WAIT_VFPF_INDIRECT_FIELD_UNEQUAL(hwmgr, SMC_IND, SMU_STATUS, SMU_DONE, 0);
  110. if (1 != PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  111. SMU_STATUS, SMU_PASS))
  112. PP_ASSERT_WITH_CODE(false, "SMU Firmware start failed!", return -1);
  113. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixFIRMWARE_FLAGS, 0);
  114. PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  115. SMC_SYSCON_RESET_CNTL, rst_reg, 1);
  116. PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  117. SMC_SYSCON_RESET_CNTL, rst_reg, 0);
  118. /* Wait for firmware to initialize */
  119. PHM_WAIT_VFPF_INDIRECT_FIELD(hwmgr, SMC_IND, FIRMWARE_FLAGS, INTERRUPTS_ENABLED, 1);
  120. return result;
  121. }
  122. static int vegam_start_smu_in_non_protection_mode(struct pp_hwmgr *hwmgr)
  123. {
  124. int result = 0;
  125. /* wait for smc boot up */
  126. PHM_WAIT_VFPF_INDIRECT_FIELD_UNEQUAL(hwmgr, SMC_IND, RCU_UC_EVENTS, boot_seq_done, 0);
  127. /* Clear firmware interrupt enable flag */
  128. /* PHM_WRITE_VFPF_INDIRECT_FIELD(pSmuMgr, SMC_IND, SMC_SYSCON_MISC_CNTL, pre_fetcher_en, 1); */
  129. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  130. ixFIRMWARE_FLAGS, 0);
  131. PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  132. SMC_SYSCON_RESET_CNTL,
  133. rst_reg, 1);
  134. result = smu7_upload_smu_firmware_image(hwmgr);
  135. if (result != 0)
  136. return result;
  137. /* Set smc instruct start point at 0x0 */
  138. smu7_program_jump_on_start(hwmgr);
  139. PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  140. SMC_SYSCON_CLOCK_CNTL_0, ck_disable, 0);
  141. PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  142. SMC_SYSCON_RESET_CNTL, rst_reg, 0);
  143. /* Wait for firmware to initialize */
  144. PHM_WAIT_VFPF_INDIRECT_FIELD(hwmgr, SMC_IND,
  145. FIRMWARE_FLAGS, INTERRUPTS_ENABLED, 1);
  146. return result;
  147. }
  148. static int vegam_start_smu(struct pp_hwmgr *hwmgr)
  149. {
  150. int result = 0;
  151. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  152. /* Only start SMC if SMC RAM is not running */
  153. if (!smu7_is_smc_ram_running(hwmgr) && hwmgr->not_vf) {
  154. smu_data->protected_mode = (uint8_t)(PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device,
  155. CGS_IND_REG__SMC, SMU_FIRMWARE, SMU_MODE));
  156. smu_data->smu7_data.security_hard_key = (uint8_t)(PHM_READ_VFPF_INDIRECT_FIELD(
  157. hwmgr->device, CGS_IND_REG__SMC, SMU_FIRMWARE, SMU_SEL));
  158. /* Check if SMU is running in protected mode */
  159. if (smu_data->protected_mode == 0)
  160. result = vegam_start_smu_in_non_protection_mode(hwmgr);
  161. else
  162. result = vegam_start_smu_in_protection_mode(hwmgr);
  163. if (result != 0)
  164. PP_ASSERT_WITH_CODE(0, "Failed to load SMU ucode.", return result);
  165. }
  166. /* Setup SoftRegsStart here for register lookup in case DummyBackEnd is used and ProcessFirmwareHeader is not executed */
  167. smu7_read_smc_sram_dword(hwmgr,
  168. SMU7_FIRMWARE_HEADER_LOCATION + offsetof(SMU75_Firmware_Header, SoftRegisters),
  169. &(smu_data->smu7_data.soft_regs_start),
  170. 0x40000);
  171. result = smu7_request_smu_load_fw(hwmgr);
  172. return result;
  173. }
  174. static int vegam_process_firmware_header(struct pp_hwmgr *hwmgr)
  175. {
  176. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  177. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  178. uint32_t tmp;
  179. int result;
  180. bool error = false;
  181. result = smu7_read_smc_sram_dword(hwmgr,
  182. SMU7_FIRMWARE_HEADER_LOCATION +
  183. offsetof(SMU75_Firmware_Header, DpmTable),
  184. &tmp, SMC_RAM_END);
  185. if (0 == result)
  186. smu_data->smu7_data.dpm_table_start = tmp;
  187. error |= (0 != result);
  188. result = smu7_read_smc_sram_dword(hwmgr,
  189. SMU7_FIRMWARE_HEADER_LOCATION +
  190. offsetof(SMU75_Firmware_Header, SoftRegisters),
  191. &tmp, SMC_RAM_END);
  192. if (!result) {
  193. data->soft_regs_start = tmp;
  194. smu_data->smu7_data.soft_regs_start = tmp;
  195. }
  196. error |= (0 != result);
  197. result = smu7_read_smc_sram_dword(hwmgr,
  198. SMU7_FIRMWARE_HEADER_LOCATION +
  199. offsetof(SMU75_Firmware_Header, mcRegisterTable),
  200. &tmp, SMC_RAM_END);
  201. if (!result)
  202. smu_data->smu7_data.mc_reg_table_start = tmp;
  203. result = smu7_read_smc_sram_dword(hwmgr,
  204. SMU7_FIRMWARE_HEADER_LOCATION +
  205. offsetof(SMU75_Firmware_Header, FanTable),
  206. &tmp, SMC_RAM_END);
  207. if (!result)
  208. smu_data->smu7_data.fan_table_start = tmp;
  209. error |= (0 != result);
  210. result = smu7_read_smc_sram_dword(hwmgr,
  211. SMU7_FIRMWARE_HEADER_LOCATION +
  212. offsetof(SMU75_Firmware_Header, mcArbDramTimingTable),
  213. &tmp, SMC_RAM_END);
  214. if (!result)
  215. smu_data->smu7_data.arb_table_start = tmp;
  216. error |= (0 != result);
  217. result = smu7_read_smc_sram_dword(hwmgr,
  218. SMU7_FIRMWARE_HEADER_LOCATION +
  219. offsetof(SMU75_Firmware_Header, Version),
  220. &tmp, SMC_RAM_END);
  221. if (!result)
  222. hwmgr->microcode_version_info.SMC = tmp;
  223. error |= (0 != result);
  224. return error ? -1 : 0;
  225. }
  226. static bool vegam_is_dpm_running(struct pp_hwmgr *hwmgr)
  227. {
  228. return (1 == PHM_READ_INDIRECT_FIELD(hwmgr->device,
  229. CGS_IND_REG__SMC, FEATURE_STATUS, VOLTAGE_CONTROLLER_ON))
  230. ? true : false;
  231. }
  232. static uint32_t vegam_get_mac_definition(uint32_t value)
  233. {
  234. switch (value) {
  235. case SMU_MAX_LEVELS_GRAPHICS:
  236. return SMU75_MAX_LEVELS_GRAPHICS;
  237. case SMU_MAX_LEVELS_MEMORY:
  238. return SMU75_MAX_LEVELS_MEMORY;
  239. case SMU_MAX_LEVELS_LINK:
  240. return SMU75_MAX_LEVELS_LINK;
  241. case SMU_MAX_ENTRIES_SMIO:
  242. return SMU75_MAX_ENTRIES_SMIO;
  243. case SMU_MAX_LEVELS_VDDC:
  244. return SMU75_MAX_LEVELS_VDDC;
  245. case SMU_MAX_LEVELS_VDDGFX:
  246. return SMU75_MAX_LEVELS_VDDGFX;
  247. case SMU_MAX_LEVELS_VDDCI:
  248. return SMU75_MAX_LEVELS_VDDCI;
  249. case SMU_MAX_LEVELS_MVDD:
  250. return SMU75_MAX_LEVELS_MVDD;
  251. case SMU_UVD_MCLK_HANDSHAKE_DISABLE:
  252. return SMU7_UVD_MCLK_HANDSHAKE_DISABLE |
  253. SMU7_VCE_MCLK_HANDSHAKE_DISABLE;
  254. }
  255. pr_warn("can't get the mac of %x\n", value);
  256. return 0;
  257. }
  258. static int vegam_update_uvd_smc_table(struct pp_hwmgr *hwmgr)
  259. {
  260. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  261. uint32_t mm_boot_level_offset, mm_boot_level_value;
  262. struct phm_ppt_v1_information *table_info =
  263. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  264. smu_data->smc_state_table.UvdBootLevel = 0;
  265. if (table_info->mm_dep_table->count > 0)
  266. smu_data->smc_state_table.UvdBootLevel =
  267. (uint8_t) (table_info->mm_dep_table->count - 1);
  268. mm_boot_level_offset = smu_data->smu7_data.dpm_table_start + offsetof(SMU75_Discrete_DpmTable,
  269. UvdBootLevel);
  270. mm_boot_level_offset /= 4;
  271. mm_boot_level_offset *= 4;
  272. mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
  273. CGS_IND_REG__SMC, mm_boot_level_offset);
  274. mm_boot_level_value &= 0x00FFFFFF;
  275. mm_boot_level_value |= smu_data->smc_state_table.UvdBootLevel << 24;
  276. cgs_write_ind_register(hwmgr->device,
  277. CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
  278. if (!phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  279. PHM_PlatformCaps_UVDDPM) ||
  280. phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  281. PHM_PlatformCaps_StablePState))
  282. smum_send_msg_to_smc_with_parameter(hwmgr,
  283. PPSMC_MSG_UVDDPM_SetEnabledMask,
  284. (uint32_t)(1 << smu_data->smc_state_table.UvdBootLevel));
  285. return 0;
  286. }
  287. static int vegam_update_vce_smc_table(struct pp_hwmgr *hwmgr)
  288. {
  289. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  290. uint32_t mm_boot_level_offset, mm_boot_level_value;
  291. struct phm_ppt_v1_information *table_info =
  292. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  293. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  294. PHM_PlatformCaps_StablePState))
  295. smu_data->smc_state_table.VceBootLevel =
  296. (uint8_t) (table_info->mm_dep_table->count - 1);
  297. else
  298. smu_data->smc_state_table.VceBootLevel = 0;
  299. mm_boot_level_offset = smu_data->smu7_data.dpm_table_start +
  300. offsetof(SMU75_Discrete_DpmTable, VceBootLevel);
  301. mm_boot_level_offset /= 4;
  302. mm_boot_level_offset *= 4;
  303. mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
  304. CGS_IND_REG__SMC, mm_boot_level_offset);
  305. mm_boot_level_value &= 0xFF00FFFF;
  306. mm_boot_level_value |= smu_data->smc_state_table.VceBootLevel << 16;
  307. cgs_write_ind_register(hwmgr->device,
  308. CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
  309. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_StablePState))
  310. smum_send_msg_to_smc_with_parameter(hwmgr,
  311. PPSMC_MSG_VCEDPM_SetEnabledMask,
  312. (uint32_t)1 << smu_data->smc_state_table.VceBootLevel);
  313. return 0;
  314. }
  315. static int vegam_update_bif_smc_table(struct pp_hwmgr *hwmgr)
  316. {
  317. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  318. struct phm_ppt_v1_information *table_info =
  319. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  320. struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table;
  321. int max_entry, i;
  322. max_entry = (SMU75_MAX_LEVELS_LINK < pcie_table->count) ?
  323. SMU75_MAX_LEVELS_LINK :
  324. pcie_table->count;
  325. /* Setup BIF_SCLK levels */
  326. for (i = 0; i < max_entry; i++)
  327. smu_data->bif_sclk_table[i] = pcie_table->entries[i].pcie_sclk;
  328. return 0;
  329. }
  330. static int vegam_update_smc_table(struct pp_hwmgr *hwmgr, uint32_t type)
  331. {
  332. switch (type) {
  333. case SMU_UVD_TABLE:
  334. vegam_update_uvd_smc_table(hwmgr);
  335. break;
  336. case SMU_VCE_TABLE:
  337. vegam_update_vce_smc_table(hwmgr);
  338. break;
  339. case SMU_BIF_TABLE:
  340. vegam_update_bif_smc_table(hwmgr);
  341. break;
  342. default:
  343. break;
  344. }
  345. return 0;
  346. }
  347. static void vegam_initialize_power_tune_defaults(struct pp_hwmgr *hwmgr)
  348. {
  349. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  350. struct phm_ppt_v1_information *table_info =
  351. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  352. if (table_info &&
  353. table_info->cac_dtp_table->usPowerTuneDataSetID <= POWERTUNE_DEFAULT_SET_MAX &&
  354. table_info->cac_dtp_table->usPowerTuneDataSetID)
  355. smu_data->power_tune_defaults =
  356. &vegam_power_tune_data_set_array
  357. [table_info->cac_dtp_table->usPowerTuneDataSetID - 1];
  358. else
  359. smu_data->power_tune_defaults = &vegam_power_tune_data_set_array[0];
  360. }
  361. static int vegam_populate_smc_mvdd_table(struct pp_hwmgr *hwmgr,
  362. SMU75_Discrete_DpmTable *table)
  363. {
  364. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  365. uint32_t count, level;
  366. if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
  367. count = data->mvdd_voltage_table.count;
  368. if (count > SMU_MAX_SMIO_LEVELS)
  369. count = SMU_MAX_SMIO_LEVELS;
  370. for (level = 0; level < count; level++) {
  371. table->SmioTable2.Pattern[level].Voltage = PP_HOST_TO_SMC_US(
  372. data->mvdd_voltage_table.entries[count].value * VOLTAGE_SCALE);
  373. /* Index into DpmTable.Smio. Drive bits from Smio entry to get this voltage level.*/
  374. table->SmioTable2.Pattern[level].Smio =
  375. (uint8_t) level;
  376. table->Smio[level] |=
  377. data->mvdd_voltage_table.entries[level].smio_low;
  378. }
  379. table->SmioMask2 = data->mvdd_voltage_table.mask_low;
  380. table->MvddLevelCount = (uint32_t) PP_HOST_TO_SMC_UL(count);
  381. }
  382. return 0;
  383. }
  384. static int vegam_populate_smc_vddci_table(struct pp_hwmgr *hwmgr,
  385. struct SMU75_Discrete_DpmTable *table)
  386. {
  387. uint32_t count, level;
  388. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  389. count = data->vddci_voltage_table.count;
  390. if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
  391. if (count > SMU_MAX_SMIO_LEVELS)
  392. count = SMU_MAX_SMIO_LEVELS;
  393. for (level = 0; level < count; ++level) {
  394. table->SmioTable1.Pattern[level].Voltage = PP_HOST_TO_SMC_US(
  395. data->vddci_voltage_table.entries[level].value * VOLTAGE_SCALE);
  396. table->SmioTable1.Pattern[level].Smio = (uint8_t) level;
  397. table->Smio[level] |= data->vddci_voltage_table.entries[level].smio_low;
  398. }
  399. }
  400. table->SmioMask1 = data->vddci_voltage_table.mask_low;
  401. return 0;
  402. }
  403. static int vegam_populate_cac_table(struct pp_hwmgr *hwmgr,
  404. struct SMU75_Discrete_DpmTable *table)
  405. {
  406. uint32_t count;
  407. uint8_t index;
  408. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  409. struct phm_ppt_v1_information *table_info =
  410. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  411. struct phm_ppt_v1_voltage_lookup_table *lookup_table =
  412. table_info->vddc_lookup_table;
  413. /* tables is already swapped, so in order to use the value from it,
  414. * we need to swap it back.
  415. * We are populating vddc CAC data to BapmVddc table
  416. * in split and merged mode
  417. */
  418. for (count = 0; count < lookup_table->count; count++) {
  419. index = phm_get_voltage_index(lookup_table,
  420. data->vddc_voltage_table.entries[count].value);
  421. table->BapmVddcVidLoSidd[count] =
  422. convert_to_vid(lookup_table->entries[index].us_cac_low);
  423. table->BapmVddcVidHiSidd[count] =
  424. convert_to_vid(lookup_table->entries[index].us_cac_mid);
  425. table->BapmVddcVidHiSidd2[count] =
  426. convert_to_vid(lookup_table->entries[index].us_cac_high);
  427. }
  428. return 0;
  429. }
  430. static int vegam_populate_smc_voltage_tables(struct pp_hwmgr *hwmgr,
  431. struct SMU75_Discrete_DpmTable *table)
  432. {
  433. vegam_populate_smc_vddci_table(hwmgr, table);
  434. vegam_populate_smc_mvdd_table(hwmgr, table);
  435. vegam_populate_cac_table(hwmgr, table);
  436. return 0;
  437. }
  438. static int vegam_populate_ulv_level(struct pp_hwmgr *hwmgr,
  439. struct SMU75_Discrete_Ulv *state)
  440. {
  441. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  442. struct phm_ppt_v1_information *table_info =
  443. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  444. state->CcPwrDynRm = 0;
  445. state->CcPwrDynRm1 = 0;
  446. state->VddcOffset = (uint16_t) table_info->us_ulv_voltage_offset;
  447. state->VddcOffsetVid = (uint8_t)(table_info->us_ulv_voltage_offset *
  448. VOLTAGE_VID_OFFSET_SCALE2 / VOLTAGE_VID_OFFSET_SCALE1);
  449. state->VddcPhase = data->vddc_phase_shed_control ^ 0x3;
  450. CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm);
  451. CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm1);
  452. CONVERT_FROM_HOST_TO_SMC_US(state->VddcOffset);
  453. return 0;
  454. }
  455. static int vegam_populate_ulv_state(struct pp_hwmgr *hwmgr,
  456. struct SMU75_Discrete_DpmTable *table)
  457. {
  458. return vegam_populate_ulv_level(hwmgr, &table->Ulv);
  459. }
  460. static int vegam_populate_smc_link_level(struct pp_hwmgr *hwmgr,
  461. struct SMU75_Discrete_DpmTable *table)
  462. {
  463. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  464. struct vegam_smumgr *smu_data =
  465. (struct vegam_smumgr *)(hwmgr->smu_backend);
  466. struct smu7_dpm_table *dpm_table = &data->dpm_table;
  467. int i;
  468. /* Index (dpm_table->pcie_speed_table.count)
  469. * is reserved for PCIE boot level. */
  470. for (i = 0; i <= dpm_table->pcie_speed_table.count; i++) {
  471. table->LinkLevel[i].PcieGenSpeed =
  472. (uint8_t)dpm_table->pcie_speed_table.dpm_levels[i].value;
  473. table->LinkLevel[i].PcieLaneCount = (uint8_t)encode_pcie_lane_width(
  474. dpm_table->pcie_speed_table.dpm_levels[i].param1);
  475. table->LinkLevel[i].EnabledForActivity = 1;
  476. table->LinkLevel[i].SPC = (uint8_t)(data->pcie_spc_cap & 0xff);
  477. table->LinkLevel[i].DownThreshold = PP_HOST_TO_SMC_UL(5);
  478. table->LinkLevel[i].UpThreshold = PP_HOST_TO_SMC_UL(30);
  479. }
  480. smu_data->smc_state_table.LinkLevelCount =
  481. (uint8_t)dpm_table->pcie_speed_table.count;
  482. /* To Do move to hwmgr */
  483. data->dpm_level_enable_mask.pcie_dpm_enable_mask =
  484. phm_get_dpm_level_enable_mask_value(&dpm_table->pcie_speed_table);
  485. return 0;
  486. }
  487. static int vegam_get_dependency_volt_by_clk(struct pp_hwmgr *hwmgr,
  488. struct phm_ppt_v1_clock_voltage_dependency_table *dep_table,
  489. uint32_t clock, SMU_VoltageLevel *voltage, uint32_t *mvdd)
  490. {
  491. uint32_t i;
  492. uint16_t vddci;
  493. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  494. *voltage = *mvdd = 0;
  495. /* clock - voltage dependency table is empty table */
  496. if (dep_table->count == 0)
  497. return -EINVAL;
  498. for (i = 0; i < dep_table->count; i++) {
  499. /* find first sclk bigger than request */
  500. if (dep_table->entries[i].clk >= clock) {
  501. *voltage |= (dep_table->entries[i].vddc *
  502. VOLTAGE_SCALE) << VDDC_SHIFT;
  503. if (SMU7_VOLTAGE_CONTROL_NONE == data->vddci_control)
  504. *voltage |= (data->vbios_boot_state.vddci_bootup_value *
  505. VOLTAGE_SCALE) << VDDCI_SHIFT;
  506. else if (dep_table->entries[i].vddci)
  507. *voltage |= (dep_table->entries[i].vddci *
  508. VOLTAGE_SCALE) << VDDCI_SHIFT;
  509. else {
  510. vddci = phm_find_closest_vddci(&(data->vddci_voltage_table),
  511. (dep_table->entries[i].vddc -
  512. (uint16_t)VDDC_VDDCI_DELTA));
  513. *voltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
  514. }
  515. if (SMU7_VOLTAGE_CONTROL_NONE == data->mvdd_control)
  516. *mvdd = data->vbios_boot_state.mvdd_bootup_value *
  517. VOLTAGE_SCALE;
  518. else if (dep_table->entries[i].mvdd)
  519. *mvdd = (uint32_t) dep_table->entries[i].mvdd *
  520. VOLTAGE_SCALE;
  521. *voltage |= 1 << PHASES_SHIFT;
  522. return 0;
  523. }
  524. }
  525. /* sclk is bigger than max sclk in the dependence table */
  526. *voltage |= (dep_table->entries[i - 1].vddc * VOLTAGE_SCALE) << VDDC_SHIFT;
  527. if (SMU7_VOLTAGE_CONTROL_NONE == data->vddci_control)
  528. *voltage |= (data->vbios_boot_state.vddci_bootup_value *
  529. VOLTAGE_SCALE) << VDDCI_SHIFT;
  530. else if (dep_table->entries[i - 1].vddci)
  531. *voltage |= (dep_table->entries[i - 1].vddci *
  532. VOLTAGE_SCALE) << VDDC_SHIFT;
  533. else {
  534. vddci = phm_find_closest_vddci(&(data->vddci_voltage_table),
  535. (dep_table->entries[i - 1].vddc -
  536. (uint16_t)VDDC_VDDCI_DELTA));
  537. *voltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
  538. }
  539. if (SMU7_VOLTAGE_CONTROL_NONE == data->mvdd_control)
  540. *mvdd = data->vbios_boot_state.mvdd_bootup_value * VOLTAGE_SCALE;
  541. else if (dep_table->entries[i].mvdd)
  542. *mvdd = (uint32_t) dep_table->entries[i - 1].mvdd * VOLTAGE_SCALE;
  543. return 0;
  544. }
  545. static void vegam_get_sclk_range_table(struct pp_hwmgr *hwmgr,
  546. SMU75_Discrete_DpmTable *table)
  547. {
  548. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  549. uint32_t i, ref_clk;
  550. struct pp_atom_ctrl_sclk_range_table range_table_from_vbios = { { {0} } };
  551. ref_clk = amdgpu_asic_get_xclk((struct amdgpu_device *)hwmgr->adev);
  552. if (0 == atomctrl_get_smc_sclk_range_table(hwmgr, &range_table_from_vbios)) {
  553. for (i = 0; i < NUM_SCLK_RANGE; i++) {
  554. table->SclkFcwRangeTable[i].vco_setting =
  555. range_table_from_vbios.entry[i].ucVco_setting;
  556. table->SclkFcwRangeTable[i].postdiv =
  557. range_table_from_vbios.entry[i].ucPostdiv;
  558. table->SclkFcwRangeTable[i].fcw_pcc =
  559. range_table_from_vbios.entry[i].usFcw_pcc;
  560. table->SclkFcwRangeTable[i].fcw_trans_upper =
  561. range_table_from_vbios.entry[i].usFcw_trans_upper;
  562. table->SclkFcwRangeTable[i].fcw_trans_lower =
  563. range_table_from_vbios.entry[i].usRcw_trans_lower;
  564. CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_pcc);
  565. CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_upper);
  566. CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_lower);
  567. }
  568. return;
  569. }
  570. for (i = 0; i < NUM_SCLK_RANGE; i++) {
  571. smu_data->range_table[i].trans_lower_frequency =
  572. (ref_clk * Range_Table[i].fcw_trans_lower) >> Range_Table[i].postdiv;
  573. smu_data->range_table[i].trans_upper_frequency =
  574. (ref_clk * Range_Table[i].fcw_trans_upper) >> Range_Table[i].postdiv;
  575. table->SclkFcwRangeTable[i].vco_setting = Range_Table[i].vco_setting;
  576. table->SclkFcwRangeTable[i].postdiv = Range_Table[i].postdiv;
  577. table->SclkFcwRangeTable[i].fcw_pcc = Range_Table[i].fcw_pcc;
  578. table->SclkFcwRangeTable[i].fcw_trans_upper = Range_Table[i].fcw_trans_upper;
  579. table->SclkFcwRangeTable[i].fcw_trans_lower = Range_Table[i].fcw_trans_lower;
  580. CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_pcc);
  581. CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_upper);
  582. CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_lower);
  583. }
  584. }
  585. static int vegam_calculate_sclk_params(struct pp_hwmgr *hwmgr,
  586. uint32_t clock, SMU_SclkSetting *sclk_setting)
  587. {
  588. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  589. const SMU75_Discrete_DpmTable *table = &(smu_data->smc_state_table);
  590. struct pp_atomctrl_clock_dividers_ai dividers;
  591. uint32_t ref_clock;
  592. uint32_t pcc_target_percent, pcc_target_freq, ss_target_percent, ss_target_freq;
  593. uint8_t i;
  594. int result;
  595. uint64_t temp;
  596. sclk_setting->SclkFrequency = clock;
  597. /* get the engine clock dividers for this clock value */
  598. result = atomctrl_get_engine_pll_dividers_ai(hwmgr, clock, &dividers);
  599. if (result == 0) {
  600. sclk_setting->Fcw_int = dividers.usSclk_fcw_int;
  601. sclk_setting->Fcw_frac = dividers.usSclk_fcw_frac;
  602. sclk_setting->Pcc_fcw_int = dividers.usPcc_fcw_int;
  603. sclk_setting->PllRange = dividers.ucSclkPllRange;
  604. sclk_setting->Sclk_slew_rate = 0x400;
  605. sclk_setting->Pcc_up_slew_rate = dividers.usPcc_fcw_slew_frac;
  606. sclk_setting->Pcc_down_slew_rate = 0xffff;
  607. sclk_setting->SSc_En = dividers.ucSscEnable;
  608. sclk_setting->Fcw1_int = dividers.usSsc_fcw1_int;
  609. sclk_setting->Fcw1_frac = dividers.usSsc_fcw1_frac;
  610. sclk_setting->Sclk_ss_slew_rate = dividers.usSsc_fcw_slew_frac;
  611. return result;
  612. }
  613. ref_clock = amdgpu_asic_get_xclk((struct amdgpu_device *)hwmgr->adev);
  614. for (i = 0; i < NUM_SCLK_RANGE; i++) {
  615. if (clock > smu_data->range_table[i].trans_lower_frequency
  616. && clock <= smu_data->range_table[i].trans_upper_frequency) {
  617. sclk_setting->PllRange = i;
  618. break;
  619. }
  620. }
  621. sclk_setting->Fcw_int = (uint16_t)
  622. ((clock << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv) /
  623. ref_clock);
  624. temp = clock << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv;
  625. temp <<= 0x10;
  626. do_div(temp, ref_clock);
  627. sclk_setting->Fcw_frac = temp & 0xffff;
  628. pcc_target_percent = 10; /* Hardcode 10% for now. */
  629. pcc_target_freq = clock - (clock * pcc_target_percent / 100);
  630. sclk_setting->Pcc_fcw_int = (uint16_t)
  631. ((pcc_target_freq << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv) /
  632. ref_clock);
  633. ss_target_percent = 2; /* Hardcode 2% for now. */
  634. sclk_setting->SSc_En = 0;
  635. if (ss_target_percent) {
  636. sclk_setting->SSc_En = 1;
  637. ss_target_freq = clock - (clock * ss_target_percent / 100);
  638. sclk_setting->Fcw1_int = (uint16_t)
  639. ((ss_target_freq << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv) /
  640. ref_clock);
  641. temp = ss_target_freq << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv;
  642. temp <<= 0x10;
  643. do_div(temp, ref_clock);
  644. sclk_setting->Fcw1_frac = temp & 0xffff;
  645. }
  646. return 0;
  647. }
  648. static uint8_t vegam_get_sleep_divider_id_from_clock(uint32_t clock,
  649. uint32_t clock_insr)
  650. {
  651. uint8_t i;
  652. uint32_t temp;
  653. uint32_t min = max(clock_insr, (uint32_t)SMU7_MINIMUM_ENGINE_CLOCK);
  654. PP_ASSERT_WITH_CODE((clock >= min),
  655. "Engine clock can't satisfy stutter requirement!",
  656. return 0);
  657. for (i = 31; ; i--) {
  658. temp = clock / (i + 1);
  659. if (temp >= min || i == 0)
  660. break;
  661. }
  662. return i;
  663. }
  664. static int vegam_populate_single_graphic_level(struct pp_hwmgr *hwmgr,
  665. uint32_t clock, struct SMU75_Discrete_GraphicsLevel *level)
  666. {
  667. int result;
  668. /* PP_Clocks minClocks; */
  669. uint32_t mvdd;
  670. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  671. struct phm_ppt_v1_information *table_info =
  672. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  673. SMU_SclkSetting curr_sclk_setting = { 0 };
  674. result = vegam_calculate_sclk_params(hwmgr, clock, &curr_sclk_setting);
  675. /* populate graphics levels */
  676. result = vegam_get_dependency_volt_by_clk(hwmgr,
  677. table_info->vdd_dep_on_sclk, clock,
  678. &level->MinVoltage, &mvdd);
  679. PP_ASSERT_WITH_CODE((0 == result),
  680. "can not find VDDC voltage value for "
  681. "VDDC engine clock dependency table",
  682. return result);
  683. level->ActivityLevel = (uint16_t)(SclkDPMTuning_VEGAM >> DPMTuning_Activity_Shift);
  684. level->CcPwrDynRm = 0;
  685. level->CcPwrDynRm1 = 0;
  686. level->EnabledForActivity = 0;
  687. level->EnabledForThrottle = 1;
  688. level->VoltageDownHyst = 0;
  689. level->PowerThrottle = 0;
  690. data->display_timing.min_clock_in_sr = hwmgr->display_config->min_core_set_clock_in_sr;
  691. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep))
  692. level->DeepSleepDivId = vegam_get_sleep_divider_id_from_clock(clock,
  693. hwmgr->display_config->min_core_set_clock_in_sr);
  694. level->SclkSetting = curr_sclk_setting;
  695. CONVERT_FROM_HOST_TO_SMC_UL(level->MinVoltage);
  696. CONVERT_FROM_HOST_TO_SMC_UL(level->CcPwrDynRm);
  697. CONVERT_FROM_HOST_TO_SMC_UL(level->CcPwrDynRm1);
  698. CONVERT_FROM_HOST_TO_SMC_US(level->ActivityLevel);
  699. CONVERT_FROM_HOST_TO_SMC_UL(level->SclkSetting.SclkFrequency);
  700. CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw_int);
  701. CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw_frac);
  702. CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Pcc_fcw_int);
  703. CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Sclk_slew_rate);
  704. CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Pcc_up_slew_rate);
  705. CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Pcc_down_slew_rate);
  706. CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw1_int);
  707. CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw1_frac);
  708. CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Sclk_ss_slew_rate);
  709. return 0;
  710. }
  711. static int vegam_populate_all_graphic_levels(struct pp_hwmgr *hwmgr)
  712. {
  713. struct smu7_hwmgr *hw_data = (struct smu7_hwmgr *)(hwmgr->backend);
  714. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  715. struct smu7_dpm_table *dpm_table = &hw_data->dpm_table;
  716. struct phm_ppt_v1_information *table_info =
  717. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  718. struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table;
  719. uint8_t pcie_entry_cnt = (uint8_t) hw_data->dpm_table.pcie_speed_table.count;
  720. int result = 0;
  721. uint32_t array = smu_data->smu7_data.dpm_table_start +
  722. offsetof(SMU75_Discrete_DpmTable, GraphicsLevel);
  723. uint32_t array_size = sizeof(struct SMU75_Discrete_GraphicsLevel) *
  724. SMU75_MAX_LEVELS_GRAPHICS;
  725. struct SMU75_Discrete_GraphicsLevel *levels =
  726. smu_data->smc_state_table.GraphicsLevel;
  727. uint32_t i, max_entry;
  728. uint8_t hightest_pcie_level_enabled = 0,
  729. lowest_pcie_level_enabled = 0,
  730. mid_pcie_level_enabled = 0,
  731. count = 0;
  732. vegam_get_sclk_range_table(hwmgr, &(smu_data->smc_state_table));
  733. for (i = 0; i < dpm_table->sclk_table.count; i++) {
  734. result = vegam_populate_single_graphic_level(hwmgr,
  735. dpm_table->sclk_table.dpm_levels[i].value,
  736. &(smu_data->smc_state_table.GraphicsLevel[i]));
  737. if (result)
  738. return result;
  739. levels[i].UpHyst = (uint8_t)
  740. (SclkDPMTuning_VEGAM >> DPMTuning_Uphyst_Shift);
  741. levels[i].DownHyst = (uint8_t)
  742. (SclkDPMTuning_VEGAM >> DPMTuning_Downhyst_Shift);
  743. /* Making sure only DPM level 0-1 have Deep Sleep Div ID populated. */
  744. if (i > 1)
  745. levels[i].DeepSleepDivId = 0;
  746. }
  747. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  748. PHM_PlatformCaps_SPLLShutdownSupport))
  749. smu_data->smc_state_table.GraphicsLevel[0].SclkSetting.SSc_En = 0;
  750. smu_data->smc_state_table.GraphicsDpmLevelCount =
  751. (uint8_t)dpm_table->sclk_table.count;
  752. hw_data->dpm_level_enable_mask.sclk_dpm_enable_mask =
  753. phm_get_dpm_level_enable_mask_value(&dpm_table->sclk_table);
  754. for (i = 0; i < dpm_table->sclk_table.count; i++)
  755. levels[i].EnabledForActivity =
  756. (hw_data->dpm_level_enable_mask.sclk_dpm_enable_mask >> i) & 0x1;
  757. if (pcie_table != NULL) {
  758. PP_ASSERT_WITH_CODE((1 <= pcie_entry_cnt),
  759. "There must be 1 or more PCIE levels defined in PPTable.",
  760. return -EINVAL);
  761. max_entry = pcie_entry_cnt - 1;
  762. for (i = 0; i < dpm_table->sclk_table.count; i++)
  763. levels[i].pcieDpmLevel =
  764. (uint8_t) ((i < max_entry) ? i : max_entry);
  765. } else {
  766. while (hw_data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
  767. ((hw_data->dpm_level_enable_mask.pcie_dpm_enable_mask &
  768. (1 << (hightest_pcie_level_enabled + 1))) != 0))
  769. hightest_pcie_level_enabled++;
  770. while (hw_data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
  771. ((hw_data->dpm_level_enable_mask.pcie_dpm_enable_mask &
  772. (1 << lowest_pcie_level_enabled)) == 0))
  773. lowest_pcie_level_enabled++;
  774. while ((count < hightest_pcie_level_enabled) &&
  775. ((hw_data->dpm_level_enable_mask.pcie_dpm_enable_mask &
  776. (1 << (lowest_pcie_level_enabled + 1 + count))) == 0))
  777. count++;
  778. mid_pcie_level_enabled = (lowest_pcie_level_enabled + 1 + count) <
  779. hightest_pcie_level_enabled ?
  780. (lowest_pcie_level_enabled + 1 + count) :
  781. hightest_pcie_level_enabled;
  782. /* set pcieDpmLevel to hightest_pcie_level_enabled */
  783. for (i = 2; i < dpm_table->sclk_table.count; i++)
  784. levels[i].pcieDpmLevel = hightest_pcie_level_enabled;
  785. /* set pcieDpmLevel to lowest_pcie_level_enabled */
  786. levels[0].pcieDpmLevel = lowest_pcie_level_enabled;
  787. /* set pcieDpmLevel to mid_pcie_level_enabled */
  788. levels[1].pcieDpmLevel = mid_pcie_level_enabled;
  789. }
  790. /* level count will send to smc once at init smc table and never change */
  791. result = smu7_copy_bytes_to_smc(hwmgr, array, (uint8_t *)levels,
  792. (uint32_t)array_size, SMC_RAM_END);
  793. return result;
  794. }
  795. static int vegam_calculate_mclk_params(struct pp_hwmgr *hwmgr,
  796. uint32_t clock, struct SMU75_Discrete_MemoryLevel *mem_level)
  797. {
  798. struct pp_atomctrl_memory_clock_param_ai mpll_param;
  799. PP_ASSERT_WITH_CODE(!atomctrl_get_memory_pll_dividers_ai(hwmgr,
  800. clock, &mpll_param),
  801. "Failed to retrieve memory pll parameter.",
  802. return -EINVAL);
  803. mem_level->MclkFrequency = (uint32_t)mpll_param.ulClock;
  804. mem_level->Fcw_int = (uint16_t)mpll_param.ulMclk_fcw_int;
  805. mem_level->Fcw_frac = (uint16_t)mpll_param.ulMclk_fcw_frac;
  806. mem_level->Postdiv = (uint8_t)mpll_param.ulPostDiv;
  807. return 0;
  808. }
  809. static int vegam_populate_single_memory_level(struct pp_hwmgr *hwmgr,
  810. uint32_t clock, struct SMU75_Discrete_MemoryLevel *mem_level)
  811. {
  812. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  813. struct phm_ppt_v1_information *table_info =
  814. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  815. int result = 0;
  816. uint32_t mclk_stutter_mode_threshold = 60000;
  817. if (table_info->vdd_dep_on_mclk) {
  818. result = vegam_get_dependency_volt_by_clk(hwmgr,
  819. table_info->vdd_dep_on_mclk, clock,
  820. &mem_level->MinVoltage, &mem_level->MinMvdd);
  821. PP_ASSERT_WITH_CODE(!result,
  822. "can not find MinVddc voltage value from memory "
  823. "VDDC voltage dependency table", return result);
  824. }
  825. result = vegam_calculate_mclk_params(hwmgr, clock, mem_level);
  826. PP_ASSERT_WITH_CODE(!result,
  827. "Failed to calculate mclk params.",
  828. return -EINVAL);
  829. mem_level->EnabledForThrottle = 1;
  830. mem_level->EnabledForActivity = 0;
  831. mem_level->VoltageDownHyst = 0;
  832. mem_level->ActivityLevel = (uint16_t)
  833. (MemoryDPMTuning_VEGAM >> DPMTuning_Activity_Shift);
  834. mem_level->StutterEnable = false;
  835. mem_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
  836. data->display_timing.num_existing_displays = hwmgr->display_config->num_display;
  837. if (mclk_stutter_mode_threshold &&
  838. (clock <= mclk_stutter_mode_threshold) &&
  839. (PHM_READ_FIELD(hwmgr->device, DPG_PIPE_STUTTER_CONTROL,
  840. STUTTER_ENABLE) & 0x1))
  841. mem_level->StutterEnable = true;
  842. if (!result) {
  843. CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MinMvdd);
  844. CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MclkFrequency);
  845. CONVERT_FROM_HOST_TO_SMC_US(mem_level->Fcw_int);
  846. CONVERT_FROM_HOST_TO_SMC_US(mem_level->Fcw_frac);
  847. CONVERT_FROM_HOST_TO_SMC_US(mem_level->ActivityLevel);
  848. CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MinVoltage);
  849. }
  850. return result;
  851. }
  852. static int vegam_populate_all_memory_levels(struct pp_hwmgr *hwmgr)
  853. {
  854. struct smu7_hwmgr *hw_data = (struct smu7_hwmgr *)(hwmgr->backend);
  855. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  856. struct smu7_dpm_table *dpm_table = &hw_data->dpm_table;
  857. int result;
  858. /* populate MCLK dpm table to SMU7 */
  859. uint32_t array = smu_data->smu7_data.dpm_table_start +
  860. offsetof(SMU75_Discrete_DpmTable, MemoryLevel);
  861. uint32_t array_size = sizeof(SMU75_Discrete_MemoryLevel) *
  862. SMU75_MAX_LEVELS_MEMORY;
  863. struct SMU75_Discrete_MemoryLevel *levels =
  864. smu_data->smc_state_table.MemoryLevel;
  865. uint32_t i;
  866. for (i = 0; i < dpm_table->mclk_table.count; i++) {
  867. PP_ASSERT_WITH_CODE((0 != dpm_table->mclk_table.dpm_levels[i].value),
  868. "can not populate memory level as memory clock is zero",
  869. return -EINVAL);
  870. result = vegam_populate_single_memory_level(hwmgr,
  871. dpm_table->mclk_table.dpm_levels[i].value,
  872. &levels[i]);
  873. if (result)
  874. return result;
  875. levels[i].UpHyst = (uint8_t)
  876. (MemoryDPMTuning_VEGAM >> DPMTuning_Uphyst_Shift);
  877. levels[i].DownHyst = (uint8_t)
  878. (MemoryDPMTuning_VEGAM >> DPMTuning_Downhyst_Shift);
  879. }
  880. smu_data->smc_state_table.MemoryDpmLevelCount =
  881. (uint8_t)dpm_table->mclk_table.count;
  882. hw_data->dpm_level_enable_mask.mclk_dpm_enable_mask =
  883. phm_get_dpm_level_enable_mask_value(&dpm_table->mclk_table);
  884. for (i = 0; i < dpm_table->mclk_table.count; i++)
  885. levels[i].EnabledForActivity =
  886. (hw_data->dpm_level_enable_mask.mclk_dpm_enable_mask >> i) & 0x1;
  887. levels[dpm_table->mclk_table.count - 1].DisplayWatermark =
  888. PPSMC_DISPLAY_WATERMARK_HIGH;
  889. /* level count will send to smc once at init smc table and never change */
  890. result = smu7_copy_bytes_to_smc(hwmgr, array, (uint8_t *)levels,
  891. (uint32_t)array_size, SMC_RAM_END);
  892. return result;
  893. }
  894. static int vegam_populate_mvdd_value(struct pp_hwmgr *hwmgr,
  895. uint32_t mclk, SMIO_Pattern *smio_pat)
  896. {
  897. const struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  898. struct phm_ppt_v1_information *table_info =
  899. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  900. uint32_t i = 0;
  901. if (SMU7_VOLTAGE_CONTROL_NONE != data->mvdd_control) {
  902. /* find mvdd value which clock is more than request */
  903. for (i = 0; i < table_info->vdd_dep_on_mclk->count; i++) {
  904. if (mclk <= table_info->vdd_dep_on_mclk->entries[i].clk) {
  905. smio_pat->Voltage = data->mvdd_voltage_table.entries[i].value;
  906. break;
  907. }
  908. }
  909. PP_ASSERT_WITH_CODE(i < table_info->vdd_dep_on_mclk->count,
  910. "MVDD Voltage is outside the supported range.",
  911. return -EINVAL);
  912. } else
  913. return -EINVAL;
  914. return 0;
  915. }
  916. static int vegam_populate_smc_acpi_level(struct pp_hwmgr *hwmgr,
  917. SMU75_Discrete_DpmTable *table)
  918. {
  919. int result = 0;
  920. uint32_t sclk_frequency;
  921. const struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  922. struct phm_ppt_v1_information *table_info =
  923. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  924. SMIO_Pattern vol_level;
  925. uint32_t mvdd;
  926. uint16_t us_mvdd;
  927. table->ACPILevel.Flags &= ~PPSMC_SWSTATE_FLAG_DC;
  928. /* Get MinVoltage and Frequency from DPM0,
  929. * already converted to SMC_UL */
  930. sclk_frequency = data->vbios_boot_state.sclk_bootup_value;
  931. result = vegam_get_dependency_volt_by_clk(hwmgr,
  932. table_info->vdd_dep_on_sclk,
  933. sclk_frequency,
  934. &table->ACPILevel.MinVoltage, &mvdd);
  935. PP_ASSERT_WITH_CODE(!result,
  936. "Cannot find ACPI VDDC voltage value "
  937. "in Clock Dependency Table",
  938. );
  939. result = vegam_calculate_sclk_params(hwmgr, sclk_frequency,
  940. &(table->ACPILevel.SclkSetting));
  941. PP_ASSERT_WITH_CODE(!result,
  942. "Error retrieving Engine Clock dividers from VBIOS.",
  943. return result);
  944. table->ACPILevel.DeepSleepDivId = 0;
  945. table->ACPILevel.CcPwrDynRm = 0;
  946. table->ACPILevel.CcPwrDynRm1 = 0;
  947. CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.Flags);
  948. CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.MinVoltage);
  949. CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm);
  950. CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm1);
  951. CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SclkSetting.SclkFrequency);
  952. CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw_int);
  953. CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw_frac);
  954. CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Pcc_fcw_int);
  955. CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Sclk_slew_rate);
  956. CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Pcc_up_slew_rate);
  957. CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Pcc_down_slew_rate);
  958. CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw1_int);
  959. CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw1_frac);
  960. CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Sclk_ss_slew_rate);
  961. /* Get MinVoltage and Frequency from DPM0, already converted to SMC_UL */
  962. table->MemoryACPILevel.MclkFrequency = data->vbios_boot_state.mclk_bootup_value;
  963. result = vegam_get_dependency_volt_by_clk(hwmgr,
  964. table_info->vdd_dep_on_mclk,
  965. table->MemoryACPILevel.MclkFrequency,
  966. &table->MemoryACPILevel.MinVoltage, &mvdd);
  967. PP_ASSERT_WITH_CODE((0 == result),
  968. "Cannot find ACPI VDDCI voltage value "
  969. "in Clock Dependency Table",
  970. );
  971. us_mvdd = 0;
  972. if ((SMU7_VOLTAGE_CONTROL_NONE == data->mvdd_control) ||
  973. (data->mclk_dpm_key_disabled))
  974. us_mvdd = data->vbios_boot_state.mvdd_bootup_value;
  975. else {
  976. if (!vegam_populate_mvdd_value(hwmgr,
  977. data->dpm_table.mclk_table.dpm_levels[0].value,
  978. &vol_level))
  979. us_mvdd = vol_level.Voltage;
  980. }
  981. if (!vegam_populate_mvdd_value(hwmgr, 0, &vol_level))
  982. table->MemoryACPILevel.MinMvdd = PP_HOST_TO_SMC_UL(vol_level.Voltage);
  983. else
  984. table->MemoryACPILevel.MinMvdd = 0;
  985. table->MemoryACPILevel.StutterEnable = false;
  986. table->MemoryACPILevel.EnabledForThrottle = 0;
  987. table->MemoryACPILevel.EnabledForActivity = 0;
  988. table->MemoryACPILevel.UpHyst = 0;
  989. table->MemoryACPILevel.DownHyst = 100;
  990. table->MemoryACPILevel.VoltageDownHyst = 0;
  991. table->MemoryACPILevel.ActivityLevel =
  992. PP_HOST_TO_SMC_US(data->current_profile_setting.mclk_activity);
  993. CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MclkFrequency);
  994. CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MinVoltage);
  995. return result;
  996. }
  997. static int vegam_populate_smc_vce_level(struct pp_hwmgr *hwmgr,
  998. SMU75_Discrete_DpmTable *table)
  999. {
  1000. int result = -EINVAL;
  1001. uint8_t count;
  1002. struct pp_atomctrl_clock_dividers_vi dividers;
  1003. struct phm_ppt_v1_information *table_info =
  1004. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1005. struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
  1006. table_info->mm_dep_table;
  1007. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1008. uint32_t vddci;
  1009. table->VceLevelCount = (uint8_t)(mm_table->count);
  1010. table->VceBootLevel = 0;
  1011. for (count = 0; count < table->VceLevelCount; count++) {
  1012. table->VceLevel[count].Frequency = mm_table->entries[count].eclk;
  1013. table->VceLevel[count].MinVoltage = 0;
  1014. table->VceLevel[count].MinVoltage |=
  1015. (mm_table->entries[count].vddc * VOLTAGE_SCALE) << VDDC_SHIFT;
  1016. if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control)
  1017. vddci = (uint32_t)phm_find_closest_vddci(&(data->vddci_voltage_table),
  1018. mm_table->entries[count].vddc - VDDC_VDDCI_DELTA);
  1019. else if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control)
  1020. vddci = mm_table->entries[count].vddc - VDDC_VDDCI_DELTA;
  1021. else
  1022. vddci = (data->vbios_boot_state.vddci_bootup_value * VOLTAGE_SCALE) << VDDCI_SHIFT;
  1023. table->VceLevel[count].MinVoltage |=
  1024. (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
  1025. table->VceLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
  1026. /*retrieve divider value for VBIOS */
  1027. result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
  1028. table->VceLevel[count].Frequency, &dividers);
  1029. PP_ASSERT_WITH_CODE((0 == result),
  1030. "can not find divide id for VCE engine clock",
  1031. return result);
  1032. table->VceLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
  1033. CONVERT_FROM_HOST_TO_SMC_UL(table->VceLevel[count].Frequency);
  1034. CONVERT_FROM_HOST_TO_SMC_UL(table->VceLevel[count].MinVoltage);
  1035. }
  1036. return result;
  1037. }
  1038. static int vegam_populate_memory_timing_parameters(struct pp_hwmgr *hwmgr,
  1039. int32_t eng_clock, int32_t mem_clock,
  1040. SMU75_Discrete_MCArbDramTimingTableEntry *arb_regs)
  1041. {
  1042. uint32_t dram_timing;
  1043. uint32_t dram_timing2;
  1044. uint32_t burst_time;
  1045. uint32_t rfsh_rate;
  1046. uint32_t misc3;
  1047. int result;
  1048. result = atomctrl_set_engine_dram_timings_rv770(hwmgr,
  1049. eng_clock, mem_clock);
  1050. PP_ASSERT_WITH_CODE(result == 0,
  1051. "Error calling VBIOS to set DRAM_TIMING.",
  1052. return result);
  1053. dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
  1054. dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
  1055. burst_time = cgs_read_register(hwmgr->device, mmMC_ARB_BURST_TIME);
  1056. rfsh_rate = cgs_read_register(hwmgr->device, mmMC_ARB_RFSH_RATE);
  1057. misc3 = cgs_read_register(hwmgr->device, mmMC_ARB_MISC3);
  1058. arb_regs->McArbDramTiming = PP_HOST_TO_SMC_UL(dram_timing);
  1059. arb_regs->McArbDramTiming2 = PP_HOST_TO_SMC_UL(dram_timing2);
  1060. arb_regs->McArbBurstTime = PP_HOST_TO_SMC_UL(burst_time);
  1061. arb_regs->McArbRfshRate = PP_HOST_TO_SMC_UL(rfsh_rate);
  1062. arb_regs->McArbMisc3 = PP_HOST_TO_SMC_UL(misc3);
  1063. return 0;
  1064. }
  1065. static int vegam_program_memory_timing_parameters(struct pp_hwmgr *hwmgr)
  1066. {
  1067. struct smu7_hwmgr *hw_data = (struct smu7_hwmgr *)(hwmgr->backend);
  1068. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  1069. struct SMU75_Discrete_MCArbDramTimingTable arb_regs;
  1070. uint32_t i, j;
  1071. int result = 0;
  1072. memset(&arb_regs, 0, sizeof(SMU75_Discrete_MCArbDramTimingTable));
  1073. for (i = 0; i < hw_data->dpm_table.sclk_table.count; i++) {
  1074. for (j = 0; j < hw_data->dpm_table.mclk_table.count; j++) {
  1075. result = vegam_populate_memory_timing_parameters(hwmgr,
  1076. hw_data->dpm_table.sclk_table.dpm_levels[i].value,
  1077. hw_data->dpm_table.mclk_table.dpm_levels[j].value,
  1078. &arb_regs.entries[i][j]);
  1079. if (result)
  1080. return result;
  1081. }
  1082. }
  1083. result = smu7_copy_bytes_to_smc(
  1084. hwmgr,
  1085. smu_data->smu7_data.arb_table_start,
  1086. (uint8_t *)&arb_regs,
  1087. sizeof(SMU75_Discrete_MCArbDramTimingTable),
  1088. SMC_RAM_END);
  1089. return result;
  1090. }
  1091. static int vegam_populate_smc_uvd_level(struct pp_hwmgr *hwmgr,
  1092. struct SMU75_Discrete_DpmTable *table)
  1093. {
  1094. int result = -EINVAL;
  1095. uint8_t count;
  1096. struct pp_atomctrl_clock_dividers_vi dividers;
  1097. struct phm_ppt_v1_information *table_info =
  1098. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1099. struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
  1100. table_info->mm_dep_table;
  1101. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1102. uint32_t vddci;
  1103. table->UvdLevelCount = (uint8_t)(mm_table->count);
  1104. table->UvdBootLevel = 0;
  1105. for (count = 0; count < table->UvdLevelCount; count++) {
  1106. table->UvdLevel[count].MinVoltage = 0;
  1107. table->UvdLevel[count].VclkFrequency = mm_table->entries[count].vclk;
  1108. table->UvdLevel[count].DclkFrequency = mm_table->entries[count].dclk;
  1109. table->UvdLevel[count].MinVoltage |=
  1110. (mm_table->entries[count].vddc * VOLTAGE_SCALE) << VDDC_SHIFT;
  1111. if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control)
  1112. vddci = (uint32_t)phm_find_closest_vddci(&(data->vddci_voltage_table),
  1113. mm_table->entries[count].vddc - VDDC_VDDCI_DELTA);
  1114. else if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control)
  1115. vddci = mm_table->entries[count].vddc - VDDC_VDDCI_DELTA;
  1116. else
  1117. vddci = (data->vbios_boot_state.vddci_bootup_value * VOLTAGE_SCALE) << VDDCI_SHIFT;
  1118. table->UvdLevel[count].MinVoltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
  1119. table->UvdLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
  1120. /* retrieve divider value for VBIOS */
  1121. result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
  1122. table->UvdLevel[count].VclkFrequency, &dividers);
  1123. PP_ASSERT_WITH_CODE((0 == result),
  1124. "can not find divide id for Vclk clock", return result);
  1125. table->UvdLevel[count].VclkDivider = (uint8_t)dividers.pll_post_divider;
  1126. result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
  1127. table->UvdLevel[count].DclkFrequency, &dividers);
  1128. PP_ASSERT_WITH_CODE((0 == result),
  1129. "can not find divide id for Dclk clock", return result);
  1130. table->UvdLevel[count].DclkDivider = (uint8_t)dividers.pll_post_divider;
  1131. CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].VclkFrequency);
  1132. CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].DclkFrequency);
  1133. CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].MinVoltage);
  1134. }
  1135. return result;
  1136. }
  1137. static int vegam_populate_smc_boot_level(struct pp_hwmgr *hwmgr,
  1138. struct SMU75_Discrete_DpmTable *table)
  1139. {
  1140. int result = 0;
  1141. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1142. table->GraphicsBootLevel = 0;
  1143. table->MemoryBootLevel = 0;
  1144. /* find boot level from dpm table */
  1145. result = phm_find_boot_level(&(data->dpm_table.sclk_table),
  1146. data->vbios_boot_state.sclk_bootup_value,
  1147. (uint32_t *)&(table->GraphicsBootLevel));
  1148. result = phm_find_boot_level(&(data->dpm_table.mclk_table),
  1149. data->vbios_boot_state.mclk_bootup_value,
  1150. (uint32_t *)&(table->MemoryBootLevel));
  1151. table->BootVddc = data->vbios_boot_state.vddc_bootup_value *
  1152. VOLTAGE_SCALE;
  1153. table->BootVddci = data->vbios_boot_state.vddci_bootup_value *
  1154. VOLTAGE_SCALE;
  1155. table->BootMVdd = data->vbios_boot_state.mvdd_bootup_value *
  1156. VOLTAGE_SCALE;
  1157. CONVERT_FROM_HOST_TO_SMC_US(table->BootVddc);
  1158. CONVERT_FROM_HOST_TO_SMC_US(table->BootVddci);
  1159. CONVERT_FROM_HOST_TO_SMC_US(table->BootMVdd);
  1160. return 0;
  1161. }
  1162. static int vegam_populate_smc_initial_state(struct pp_hwmgr *hwmgr)
  1163. {
  1164. struct smu7_hwmgr *hw_data = (struct smu7_hwmgr *)(hwmgr->backend);
  1165. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  1166. struct phm_ppt_v1_information *table_info =
  1167. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1168. uint8_t count, level;
  1169. count = (uint8_t)(table_info->vdd_dep_on_sclk->count);
  1170. for (level = 0; level < count; level++) {
  1171. if (table_info->vdd_dep_on_sclk->entries[level].clk >=
  1172. hw_data->vbios_boot_state.sclk_bootup_value) {
  1173. smu_data->smc_state_table.GraphicsBootLevel = level;
  1174. break;
  1175. }
  1176. }
  1177. count = (uint8_t)(table_info->vdd_dep_on_mclk->count);
  1178. for (level = 0; level < count; level++) {
  1179. if (table_info->vdd_dep_on_mclk->entries[level].clk >=
  1180. hw_data->vbios_boot_state.mclk_bootup_value) {
  1181. smu_data->smc_state_table.MemoryBootLevel = level;
  1182. break;
  1183. }
  1184. }
  1185. return 0;
  1186. }
  1187. static uint16_t scale_fan_gain_settings(uint16_t raw_setting)
  1188. {
  1189. uint32_t tmp;
  1190. tmp = raw_setting * 4096 / 100;
  1191. return (uint16_t)tmp;
  1192. }
  1193. static int vegam_populate_bapm_parameters_in_dpm_table(struct pp_hwmgr *hwmgr)
  1194. {
  1195. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  1196. const struct vegam_pt_defaults *defaults = smu_data->power_tune_defaults;
  1197. SMU75_Discrete_DpmTable *table = &(smu_data->smc_state_table);
  1198. struct phm_ppt_v1_information *table_info =
  1199. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1200. struct phm_cac_tdp_table *cac_dtp_table = table_info->cac_dtp_table;
  1201. struct pp_advance_fan_control_parameters *fan_table =
  1202. &hwmgr->thermal_controller.advanceFanControlParameters;
  1203. int i, j, k;
  1204. const uint16_t *pdef1;
  1205. const uint16_t *pdef2;
  1206. table->DefaultTdp = PP_HOST_TO_SMC_US((uint16_t)(cac_dtp_table->usTDP * 128));
  1207. table->TargetTdp = PP_HOST_TO_SMC_US((uint16_t)(cac_dtp_table->usTDP * 128));
  1208. PP_ASSERT_WITH_CODE(cac_dtp_table->usTargetOperatingTemp <= 255,
  1209. "Target Operating Temp is out of Range!",
  1210. );
  1211. table->TemperatureLimitEdge = PP_HOST_TO_SMC_US(
  1212. cac_dtp_table->usTargetOperatingTemp * 256);
  1213. table->TemperatureLimitHotspot = PP_HOST_TO_SMC_US(
  1214. cac_dtp_table->usTemperatureLimitHotspot * 256);
  1215. table->FanGainEdge = PP_HOST_TO_SMC_US(
  1216. scale_fan_gain_settings(fan_table->usFanGainEdge));
  1217. table->FanGainHotspot = PP_HOST_TO_SMC_US(
  1218. scale_fan_gain_settings(fan_table->usFanGainHotspot));
  1219. pdef1 = defaults->BAPMTI_R;
  1220. pdef2 = defaults->BAPMTI_RC;
  1221. for (i = 0; i < SMU75_DTE_ITERATIONS; i++) {
  1222. for (j = 0; j < SMU75_DTE_SOURCES; j++) {
  1223. for (k = 0; k < SMU75_DTE_SINKS; k++) {
  1224. table->BAPMTI_R[i][j][k] = PP_HOST_TO_SMC_US(*pdef1);
  1225. table->BAPMTI_RC[i][j][k] = PP_HOST_TO_SMC_US(*pdef2);
  1226. pdef1++;
  1227. pdef2++;
  1228. }
  1229. }
  1230. }
  1231. return 0;
  1232. }
  1233. static int vegam_populate_clock_stretcher_data_table(struct pp_hwmgr *hwmgr)
  1234. {
  1235. uint32_t ro, efuse, volt_without_cks, volt_with_cks, value, max, min;
  1236. struct vegam_smumgr *smu_data =
  1237. (struct vegam_smumgr *)(hwmgr->smu_backend);
  1238. uint8_t i, stretch_amount, stretch_amount2, volt_offset = 0;
  1239. struct phm_ppt_v1_information *table_info =
  1240. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1241. struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
  1242. table_info->vdd_dep_on_sclk;
  1243. uint32_t mask = (1 << ((STRAP_ASIC_RO_MSB - STRAP_ASIC_RO_LSB) + 1)) - 1;
  1244. stretch_amount = (uint8_t)table_info->cac_dtp_table->usClockStretchAmount;
  1245. atomctrl_read_efuse(hwmgr, STRAP_ASIC_RO_LSB, STRAP_ASIC_RO_MSB,
  1246. mask, &efuse);
  1247. min = 1200;
  1248. max = 2500;
  1249. ro = efuse * (max - min) / 255 + min;
  1250. /* Populate Sclk_CKS_masterEn0_7 and Sclk_voltageOffset */
  1251. for (i = 0; i < sclk_table->count; i++) {
  1252. smu_data->smc_state_table.Sclk_CKS_masterEn0_7 |=
  1253. sclk_table->entries[i].cks_enable << i;
  1254. volt_without_cks = (uint32_t)((2753594000U + (sclk_table->entries[i].clk/100) *
  1255. 136418 - (ro - 70) * 1000000) /
  1256. (2424180 - (sclk_table->entries[i].clk/100) * 1132925/1000));
  1257. volt_with_cks = (uint32_t)((2797202000U + sclk_table->entries[i].clk/100 *
  1258. 3232 - (ro - 65) * 1000000) /
  1259. (2522480 - sclk_table->entries[i].clk/100 * 115764/100));
  1260. if (volt_without_cks >= volt_with_cks)
  1261. volt_offset = (uint8_t)(((volt_without_cks - volt_with_cks +
  1262. sclk_table->entries[i].cks_voffset) * 100 + 624) / 625);
  1263. smu_data->smc_state_table.Sclk_voltageOffset[i] = volt_offset;
  1264. }
  1265. smu_data->smc_state_table.LdoRefSel =
  1266. (table_info->cac_dtp_table->ucCKS_LDO_REFSEL != 0) ?
  1267. table_info->cac_dtp_table->ucCKS_LDO_REFSEL : 5;
  1268. /* Populate CKS Lookup Table */
  1269. if (stretch_amount == 1 || stretch_amount == 2 || stretch_amount == 5)
  1270. stretch_amount2 = 0;
  1271. else if (stretch_amount == 3 || stretch_amount == 4)
  1272. stretch_amount2 = 1;
  1273. else {
  1274. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  1275. PHM_PlatformCaps_ClockStretcher);
  1276. PP_ASSERT_WITH_CODE(false,
  1277. "Stretch Amount in PPTable not supported\n",
  1278. return -EINVAL);
  1279. }
  1280. value = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixPWR_CKS_CNTL);
  1281. value &= 0xFFFFFFFE;
  1282. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixPWR_CKS_CNTL, value);
  1283. return 0;
  1284. }
  1285. static bool vegam_is_hw_avfs_present(struct pp_hwmgr *hwmgr)
  1286. {
  1287. uint32_t efuse;
  1288. efuse = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  1289. ixSMU_EFUSE_0 + (49 * 4));
  1290. efuse &= 0x00000001;
  1291. if (efuse)
  1292. return true;
  1293. return false;
  1294. }
  1295. static int vegam_populate_avfs_parameters(struct pp_hwmgr *hwmgr)
  1296. {
  1297. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1298. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  1299. SMU75_Discrete_DpmTable *table = &(smu_data->smc_state_table);
  1300. int result = 0;
  1301. struct pp_atom_ctrl__avfs_parameters avfs_params = {0};
  1302. AVFS_meanNsigma_t AVFS_meanNsigma = { {0} };
  1303. AVFS_Sclk_Offset_t AVFS_SclkOffset = { {0} };
  1304. uint32_t tmp, i;
  1305. struct phm_ppt_v1_information *table_info =
  1306. (struct phm_ppt_v1_information *)hwmgr->pptable;
  1307. struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
  1308. table_info->vdd_dep_on_sclk;
  1309. if (!hwmgr->avfs_supported)
  1310. return 0;
  1311. result = atomctrl_get_avfs_information(hwmgr, &avfs_params);
  1312. if (0 == result) {
  1313. table->BTCGB_VDROOP_TABLE[0].a0 =
  1314. PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSON_a0);
  1315. table->BTCGB_VDROOP_TABLE[0].a1 =
  1316. PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSON_a1);
  1317. table->BTCGB_VDROOP_TABLE[0].a2 =
  1318. PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSON_a2);
  1319. table->BTCGB_VDROOP_TABLE[1].a0 =
  1320. PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSOFF_a0);
  1321. table->BTCGB_VDROOP_TABLE[1].a1 =
  1322. PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSOFF_a1);
  1323. table->BTCGB_VDROOP_TABLE[1].a2 =
  1324. PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSOFF_a2);
  1325. table->AVFSGB_FUSE_TABLE[0].m1 =
  1326. PP_HOST_TO_SMC_UL(avfs_params.ulAVFSGB_FUSE_TABLE_CKSON_m1);
  1327. table->AVFSGB_FUSE_TABLE[0].m2 =
  1328. PP_HOST_TO_SMC_US(avfs_params.usAVFSGB_FUSE_TABLE_CKSON_m2);
  1329. table->AVFSGB_FUSE_TABLE[0].b =
  1330. PP_HOST_TO_SMC_UL(avfs_params.ulAVFSGB_FUSE_TABLE_CKSON_b);
  1331. table->AVFSGB_FUSE_TABLE[0].m1_shift = 24;
  1332. table->AVFSGB_FUSE_TABLE[0].m2_shift = 12;
  1333. table->AVFSGB_FUSE_TABLE[1].m1 =
  1334. PP_HOST_TO_SMC_UL(avfs_params.ulAVFSGB_FUSE_TABLE_CKSOFF_m1);
  1335. table->AVFSGB_FUSE_TABLE[1].m2 =
  1336. PP_HOST_TO_SMC_US(avfs_params.usAVFSGB_FUSE_TABLE_CKSOFF_m2);
  1337. table->AVFSGB_FUSE_TABLE[1].b =
  1338. PP_HOST_TO_SMC_UL(avfs_params.ulAVFSGB_FUSE_TABLE_CKSOFF_b);
  1339. table->AVFSGB_FUSE_TABLE[1].m1_shift = 24;
  1340. table->AVFSGB_FUSE_TABLE[1].m2_shift = 12;
  1341. table->MaxVoltage = PP_HOST_TO_SMC_US(avfs_params.usMaxVoltage_0_25mv);
  1342. AVFS_meanNsigma.Aconstant[0] =
  1343. PP_HOST_TO_SMC_UL(avfs_params.ulAVFS_meanNsigma_Acontant0);
  1344. AVFS_meanNsigma.Aconstant[1] =
  1345. PP_HOST_TO_SMC_UL(avfs_params.ulAVFS_meanNsigma_Acontant1);
  1346. AVFS_meanNsigma.Aconstant[2] =
  1347. PP_HOST_TO_SMC_UL(avfs_params.ulAVFS_meanNsigma_Acontant2);
  1348. AVFS_meanNsigma.DC_tol_sigma =
  1349. PP_HOST_TO_SMC_US(avfs_params.usAVFS_meanNsigma_DC_tol_sigma);
  1350. AVFS_meanNsigma.Platform_mean =
  1351. PP_HOST_TO_SMC_US(avfs_params.usAVFS_meanNsigma_Platform_mean);
  1352. AVFS_meanNsigma.PSM_Age_CompFactor =
  1353. PP_HOST_TO_SMC_US(avfs_params.usPSM_Age_ComFactor);
  1354. AVFS_meanNsigma.Platform_sigma =
  1355. PP_HOST_TO_SMC_US(avfs_params.usAVFS_meanNsigma_Platform_sigma);
  1356. for (i = 0; i < sclk_table->count; i++) {
  1357. AVFS_meanNsigma.Static_Voltage_Offset[i] =
  1358. (uint8_t)(sclk_table->entries[i].cks_voffset * 100 / 625);
  1359. AVFS_SclkOffset.Sclk_Offset[i] =
  1360. PP_HOST_TO_SMC_US((uint16_t)
  1361. (sclk_table->entries[i].sclk_offset) / 100);
  1362. }
  1363. result = smu7_read_smc_sram_dword(hwmgr,
  1364. SMU7_FIRMWARE_HEADER_LOCATION +
  1365. offsetof(SMU75_Firmware_Header, AvfsMeanNSigma),
  1366. &tmp, SMC_RAM_END);
  1367. smu7_copy_bytes_to_smc(hwmgr,
  1368. tmp,
  1369. (uint8_t *)&AVFS_meanNsigma,
  1370. sizeof(AVFS_meanNsigma_t),
  1371. SMC_RAM_END);
  1372. result = smu7_read_smc_sram_dword(hwmgr,
  1373. SMU7_FIRMWARE_HEADER_LOCATION +
  1374. offsetof(SMU75_Firmware_Header, AvfsSclkOffsetTable),
  1375. &tmp, SMC_RAM_END);
  1376. smu7_copy_bytes_to_smc(hwmgr,
  1377. tmp,
  1378. (uint8_t *)&AVFS_SclkOffset,
  1379. sizeof(AVFS_Sclk_Offset_t),
  1380. SMC_RAM_END);
  1381. data->avfs_vdroop_override_setting =
  1382. (avfs_params.ucEnableGB_VDROOP_TABLE_CKSON << BTCGB0_Vdroop_Enable_SHIFT) |
  1383. (avfs_params.ucEnableGB_VDROOP_TABLE_CKSOFF << BTCGB1_Vdroop_Enable_SHIFT) |
  1384. (avfs_params.ucEnableGB_FUSE_TABLE_CKSON << AVFSGB0_Vdroop_Enable_SHIFT) |
  1385. (avfs_params.ucEnableGB_FUSE_TABLE_CKSOFF << AVFSGB1_Vdroop_Enable_SHIFT);
  1386. data->apply_avfs_cks_off_voltage =
  1387. (avfs_params.ucEnableApplyAVFS_CKS_OFF_Voltage == 1) ? true : false;
  1388. }
  1389. return result;
  1390. }
  1391. static int vegam_populate_vr_config(struct pp_hwmgr *hwmgr,
  1392. struct SMU75_Discrete_DpmTable *table)
  1393. {
  1394. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1395. struct vegam_smumgr *smu_data =
  1396. (struct vegam_smumgr *)(hwmgr->smu_backend);
  1397. uint16_t config;
  1398. config = VR_MERGED_WITH_VDDC;
  1399. table->VRConfig |= (config << VRCONF_VDDGFX_SHIFT);
  1400. /* Set Vddc Voltage Controller */
  1401. if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
  1402. config = VR_SVI2_PLANE_1;
  1403. table->VRConfig |= config;
  1404. } else {
  1405. PP_ASSERT_WITH_CODE(false,
  1406. "VDDC should be on SVI2 control in merged mode!",
  1407. );
  1408. }
  1409. /* Set Vddci Voltage Controller */
  1410. if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) {
  1411. config = VR_SVI2_PLANE_2; /* only in merged mode */
  1412. table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
  1413. } else if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
  1414. config = VR_SMIO_PATTERN_1;
  1415. table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
  1416. } else {
  1417. config = VR_STATIC_VOLTAGE;
  1418. table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
  1419. }
  1420. /* Set Mvdd Voltage Controller */
  1421. if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) {
  1422. if (config != VR_SVI2_PLANE_2) {
  1423. config = VR_SVI2_PLANE_2;
  1424. table->VRConfig |= (config << VRCONF_MVDD_SHIFT);
  1425. cgs_write_ind_register(hwmgr->device,
  1426. CGS_IND_REG__SMC,
  1427. smu_data->smu7_data.soft_regs_start +
  1428. offsetof(SMU75_SoftRegisters, AllowMvddSwitch),
  1429. 0x1);
  1430. } else {
  1431. PP_ASSERT_WITH_CODE(false,
  1432. "SVI2 Plane 2 is already taken, set MVDD as Static",);
  1433. config = VR_STATIC_VOLTAGE;
  1434. table->VRConfig = (config << VRCONF_MVDD_SHIFT);
  1435. }
  1436. } else if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
  1437. config = VR_SMIO_PATTERN_2;
  1438. table->VRConfig = (config << VRCONF_MVDD_SHIFT);
  1439. cgs_write_ind_register(hwmgr->device,
  1440. CGS_IND_REG__SMC,
  1441. smu_data->smu7_data.soft_regs_start +
  1442. offsetof(SMU75_SoftRegisters, AllowMvddSwitch),
  1443. 0x1);
  1444. } else {
  1445. config = VR_STATIC_VOLTAGE;
  1446. table->VRConfig |= (config << VRCONF_MVDD_SHIFT);
  1447. }
  1448. return 0;
  1449. }
  1450. static int vegam_populate_svi_load_line(struct pp_hwmgr *hwmgr)
  1451. {
  1452. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  1453. const struct vegam_pt_defaults *defaults = smu_data->power_tune_defaults;
  1454. smu_data->power_tune_table.SviLoadLineEn = defaults->SviLoadLineEn;
  1455. smu_data->power_tune_table.SviLoadLineVddC = defaults->SviLoadLineVddC;
  1456. smu_data->power_tune_table.SviLoadLineTrimVddC = 3;
  1457. smu_data->power_tune_table.SviLoadLineOffsetVddC = 0;
  1458. return 0;
  1459. }
  1460. static int vegam_populate_tdc_limit(struct pp_hwmgr *hwmgr)
  1461. {
  1462. uint16_t tdc_limit;
  1463. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  1464. struct phm_ppt_v1_information *table_info =
  1465. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1466. const struct vegam_pt_defaults *defaults = smu_data->power_tune_defaults;
  1467. tdc_limit = (uint16_t)(table_info->cac_dtp_table->usTDC * 128);
  1468. smu_data->power_tune_table.TDC_VDDC_PkgLimit =
  1469. CONVERT_FROM_HOST_TO_SMC_US(tdc_limit);
  1470. smu_data->power_tune_table.TDC_VDDC_ThrottleReleaseLimitPerc =
  1471. defaults->TDC_VDDC_ThrottleReleaseLimitPerc;
  1472. smu_data->power_tune_table.TDC_MAWt = defaults->TDC_MAWt;
  1473. return 0;
  1474. }
  1475. static int vegam_populate_dw8(struct pp_hwmgr *hwmgr, uint32_t fuse_table_offset)
  1476. {
  1477. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  1478. const struct vegam_pt_defaults *defaults = smu_data->power_tune_defaults;
  1479. uint32_t temp;
  1480. if (smu7_read_smc_sram_dword(hwmgr,
  1481. fuse_table_offset +
  1482. offsetof(SMU75_Discrete_PmFuses, TdcWaterfallCtl),
  1483. (uint32_t *)&temp, SMC_RAM_END))
  1484. PP_ASSERT_WITH_CODE(false,
  1485. "Attempt to read PmFuses.DW6 (SviLoadLineEn) from SMC Failed!",
  1486. return -EINVAL);
  1487. else {
  1488. smu_data->power_tune_table.TdcWaterfallCtl = defaults->TdcWaterfallCtl;
  1489. smu_data->power_tune_table.LPMLTemperatureMin =
  1490. (uint8_t)((temp >> 16) & 0xff);
  1491. smu_data->power_tune_table.LPMLTemperatureMax =
  1492. (uint8_t)((temp >> 8) & 0xff);
  1493. smu_data->power_tune_table.Reserved = (uint8_t)(temp & 0xff);
  1494. }
  1495. return 0;
  1496. }
  1497. static int vegam_populate_temperature_scaler(struct pp_hwmgr *hwmgr)
  1498. {
  1499. int i;
  1500. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  1501. /* Currently not used. Set all to zero. */
  1502. for (i = 0; i < 16; i++)
  1503. smu_data->power_tune_table.LPMLTemperatureScaler[i] = 0;
  1504. return 0;
  1505. }
  1506. static int vegam_populate_fuzzy_fan(struct pp_hwmgr *hwmgr)
  1507. {
  1508. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  1509. /* TO DO move to hwmgr */
  1510. if ((hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity & (1 << 15))
  1511. || 0 == hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity)
  1512. hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity =
  1513. hwmgr->thermal_controller.advanceFanControlParameters.usDefaultFanOutputSensitivity;
  1514. smu_data->power_tune_table.FuzzyFan_PwmSetDelta = PP_HOST_TO_SMC_US(
  1515. hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity);
  1516. return 0;
  1517. }
  1518. static int vegam_populate_gnb_lpml(struct pp_hwmgr *hwmgr)
  1519. {
  1520. int i;
  1521. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  1522. /* Currently not used. Set all to zero. */
  1523. for (i = 0; i < 16; i++)
  1524. smu_data->power_tune_table.GnbLPML[i] = 0;
  1525. return 0;
  1526. }
  1527. static int vegam_populate_bapm_vddc_base_leakage_sidd(struct pp_hwmgr *hwmgr)
  1528. {
  1529. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  1530. struct phm_ppt_v1_information *table_info =
  1531. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1532. uint16_t hi_sidd = smu_data->power_tune_table.BapmVddCBaseLeakageHiSidd;
  1533. uint16_t lo_sidd = smu_data->power_tune_table.BapmVddCBaseLeakageLoSidd;
  1534. struct phm_cac_tdp_table *cac_table = table_info->cac_dtp_table;
  1535. hi_sidd = (uint16_t)(cac_table->usHighCACLeakage / 100 * 256);
  1536. lo_sidd = (uint16_t)(cac_table->usLowCACLeakage / 100 * 256);
  1537. smu_data->power_tune_table.BapmVddCBaseLeakageHiSidd =
  1538. CONVERT_FROM_HOST_TO_SMC_US(hi_sidd);
  1539. smu_data->power_tune_table.BapmVddCBaseLeakageLoSidd =
  1540. CONVERT_FROM_HOST_TO_SMC_US(lo_sidd);
  1541. return 0;
  1542. }
  1543. static int vegam_populate_pm_fuses(struct pp_hwmgr *hwmgr)
  1544. {
  1545. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  1546. uint32_t pm_fuse_table_offset;
  1547. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1548. PHM_PlatformCaps_PowerContainment)) {
  1549. if (smu7_read_smc_sram_dword(hwmgr,
  1550. SMU7_FIRMWARE_HEADER_LOCATION +
  1551. offsetof(SMU75_Firmware_Header, PmFuseTable),
  1552. &pm_fuse_table_offset, SMC_RAM_END))
  1553. PP_ASSERT_WITH_CODE(false,
  1554. "Attempt to get pm_fuse_table_offset Failed!",
  1555. return -EINVAL);
  1556. if (vegam_populate_svi_load_line(hwmgr))
  1557. PP_ASSERT_WITH_CODE(false,
  1558. "Attempt to populate SviLoadLine Failed!",
  1559. return -EINVAL);
  1560. if (vegam_populate_tdc_limit(hwmgr))
  1561. PP_ASSERT_WITH_CODE(false,
  1562. "Attempt to populate TDCLimit Failed!", return -EINVAL);
  1563. if (vegam_populate_dw8(hwmgr, pm_fuse_table_offset))
  1564. PP_ASSERT_WITH_CODE(false,
  1565. "Attempt to populate TdcWaterfallCtl, "
  1566. "LPMLTemperature Min and Max Failed!",
  1567. return -EINVAL);
  1568. if (0 != vegam_populate_temperature_scaler(hwmgr))
  1569. PP_ASSERT_WITH_CODE(false,
  1570. "Attempt to populate LPMLTemperatureScaler Failed!",
  1571. return -EINVAL);
  1572. if (vegam_populate_fuzzy_fan(hwmgr))
  1573. PP_ASSERT_WITH_CODE(false,
  1574. "Attempt to populate Fuzzy Fan Control parameters Failed!",
  1575. return -EINVAL);
  1576. if (vegam_populate_gnb_lpml(hwmgr))
  1577. PP_ASSERT_WITH_CODE(false,
  1578. "Attempt to populate GnbLPML Failed!",
  1579. return -EINVAL);
  1580. if (vegam_populate_bapm_vddc_base_leakage_sidd(hwmgr))
  1581. PP_ASSERT_WITH_CODE(false,
  1582. "Attempt to populate BapmVddCBaseLeakage Hi and Lo "
  1583. "Sidd Failed!", return -EINVAL);
  1584. if (smu7_copy_bytes_to_smc(hwmgr, pm_fuse_table_offset,
  1585. (uint8_t *)&smu_data->power_tune_table,
  1586. (sizeof(struct SMU75_Discrete_PmFuses) - PMFUSES_AVFSSIZE),
  1587. SMC_RAM_END))
  1588. PP_ASSERT_WITH_CODE(false,
  1589. "Attempt to download PmFuseTable Failed!",
  1590. return -EINVAL);
  1591. }
  1592. return 0;
  1593. }
  1594. static int vegam_enable_reconfig_cus(struct pp_hwmgr *hwmgr)
  1595. {
  1596. struct amdgpu_device *adev = hwmgr->adev;
  1597. smum_send_msg_to_smc_with_parameter(hwmgr,
  1598. PPSMC_MSG_EnableModeSwitchRLCNotification,
  1599. adev->gfx.cu_info.number);
  1600. return 0;
  1601. }
  1602. static int vegam_init_smc_table(struct pp_hwmgr *hwmgr)
  1603. {
  1604. int result;
  1605. struct smu7_hwmgr *hw_data = (struct smu7_hwmgr *)(hwmgr->backend);
  1606. struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
  1607. struct phm_ppt_v1_information *table_info =
  1608. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1609. struct SMU75_Discrete_DpmTable *table = &(smu_data->smc_state_table);
  1610. uint8_t i;
  1611. struct pp_atomctrl_gpio_pin_assignment gpio_pin;
  1612. struct phm_ppt_v1_gpio_table *gpio_table =
  1613. (struct phm_ppt_v1_gpio_table *)table_info->gpio_table;
  1614. pp_atomctrl_clock_dividers_vi dividers;
  1615. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  1616. PHM_PlatformCaps_AutomaticDCTransition);
  1617. vegam_initialize_power_tune_defaults(hwmgr);
  1618. if (SMU7_VOLTAGE_CONTROL_NONE != hw_data->voltage_control)
  1619. vegam_populate_smc_voltage_tables(hwmgr, table);
  1620. table->SystemFlags = 0;
  1621. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1622. PHM_PlatformCaps_AutomaticDCTransition))
  1623. table->SystemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC;
  1624. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1625. PHM_PlatformCaps_StepVddc))
  1626. table->SystemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC;
  1627. if (hw_data->is_memory_gddr5)
  1628. table->SystemFlags |= PPSMC_SYSTEMFLAG_GDDR5;
  1629. if (hw_data->ulv_supported && table_info->us_ulv_voltage_offset) {
  1630. result = vegam_populate_ulv_state(hwmgr, table);
  1631. PP_ASSERT_WITH_CODE(!result,
  1632. "Failed to initialize ULV state!", return result);
  1633. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  1634. ixCG_ULV_PARAMETER, SMU7_CGULVPARAMETER_DFLT);
  1635. }
  1636. result = vegam_populate_smc_link_level(hwmgr, table);
  1637. PP_ASSERT_WITH_CODE(!result,
  1638. "Failed to initialize Link Level!", return result);
  1639. result = vegam_populate_all_graphic_levels(hwmgr);
  1640. PP_ASSERT_WITH_CODE(!result,
  1641. "Failed to initialize Graphics Level!", return result);
  1642. result = vegam_populate_all_memory_levels(hwmgr);
  1643. PP_ASSERT_WITH_CODE(!result,
  1644. "Failed to initialize Memory Level!", return result);
  1645. result = vegam_populate_smc_acpi_level(hwmgr, table);
  1646. PP_ASSERT_WITH_CODE(!result,
  1647. "Failed to initialize ACPI Level!", return result);
  1648. result = vegam_populate_smc_vce_level(hwmgr, table);
  1649. PP_ASSERT_WITH_CODE(!result,
  1650. "Failed to initialize VCE Level!", return result);
  1651. /* Since only the initial state is completely set up at this point
  1652. * (the other states are just copies of the boot state) we only
  1653. * need to populate the ARB settings for the initial state.
  1654. */
  1655. result = vegam_program_memory_timing_parameters(hwmgr);
  1656. PP_ASSERT_WITH_CODE(!result,
  1657. "Failed to Write ARB settings for the initial state.", return result);
  1658. result = vegam_populate_smc_uvd_level(hwmgr, table);
  1659. PP_ASSERT_WITH_CODE(!result,
  1660. "Failed to initialize UVD Level!", return result);
  1661. result = vegam_populate_smc_boot_level(hwmgr, table);
  1662. PP_ASSERT_WITH_CODE(!result,
  1663. "Failed to initialize Boot Level!", return result);
  1664. result = vegam_populate_smc_initial_state(hwmgr);
  1665. PP_ASSERT_WITH_CODE(!result,
  1666. "Failed to initialize Boot State!", return result);
  1667. result = vegam_populate_bapm_parameters_in_dpm_table(hwmgr);
  1668. PP_ASSERT_WITH_CODE(!result,
  1669. "Failed to populate BAPM Parameters!", return result);
  1670. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1671. PHM_PlatformCaps_ClockStretcher)) {
  1672. result = vegam_populate_clock_stretcher_data_table(hwmgr);
  1673. PP_ASSERT_WITH_CODE(!result,
  1674. "Failed to populate Clock Stretcher Data Table!",
  1675. return result);
  1676. }
  1677. result = vegam_populate_avfs_parameters(hwmgr);
  1678. PP_ASSERT_WITH_CODE(!result,
  1679. "Failed to populate AVFS Parameters!", return result;);
  1680. table->CurrSclkPllRange = 0xff;
  1681. table->GraphicsVoltageChangeEnable = 1;
  1682. table->GraphicsThermThrottleEnable = 1;
  1683. table->GraphicsInterval = 1;
  1684. table->VoltageInterval = 1;
  1685. table->ThermalInterval = 1;
  1686. table->TemperatureLimitHigh =
  1687. table_info->cac_dtp_table->usTargetOperatingTemp *
  1688. SMU7_Q88_FORMAT_CONVERSION_UNIT;
  1689. table->TemperatureLimitLow =
  1690. (table_info->cac_dtp_table->usTargetOperatingTemp - 1) *
  1691. SMU7_Q88_FORMAT_CONVERSION_UNIT;
  1692. table->MemoryVoltageChangeEnable = 1;
  1693. table->MemoryInterval = 1;
  1694. table->VoltageResponseTime = 0;
  1695. table->PhaseResponseTime = 0;
  1696. table->MemoryThermThrottleEnable = 1;
  1697. PP_ASSERT_WITH_CODE(hw_data->dpm_table.pcie_speed_table.count >= 1,
  1698. "There must be 1 or more PCIE levels defined in PPTable.",
  1699. return -EINVAL);
  1700. table->PCIeBootLinkLevel =
  1701. hw_data->dpm_table.pcie_speed_table.count;
  1702. table->PCIeGenInterval = 1;
  1703. table->VRConfig = 0;
  1704. result = vegam_populate_vr_config(hwmgr, table);
  1705. PP_ASSERT_WITH_CODE(!result,
  1706. "Failed to populate VRConfig setting!", return result);
  1707. table->ThermGpio = 17;
  1708. table->SclkStepSize = 0x4000;
  1709. if (atomctrl_get_pp_assign_pin(hwmgr,
  1710. VDDC_VRHOT_GPIO_PINID, &gpio_pin)) {
  1711. table->VRHotGpio = gpio_pin.uc_gpio_pin_bit_shift;
  1712. if (gpio_table)
  1713. table->VRHotLevel =
  1714. table_info->gpio_table->vrhot_triggered_sclk_dpm_index;
  1715. } else {
  1716. table->VRHotGpio = SMU7_UNUSED_GPIO_PIN;
  1717. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  1718. PHM_PlatformCaps_RegulatorHot);
  1719. }
  1720. if (atomctrl_get_pp_assign_pin(hwmgr,
  1721. PP_AC_DC_SWITCH_GPIO_PINID, &gpio_pin)) {
  1722. table->AcDcGpio = gpio_pin.uc_gpio_pin_bit_shift;
  1723. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1724. PHM_PlatformCaps_AutomaticDCTransition) &&
  1725. !smum_send_msg_to_smc(hwmgr, PPSMC_MSG_UseNewGPIOScheme))
  1726. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  1727. PHM_PlatformCaps_SMCtoPPLIBAcdcGpioScheme);
  1728. } else {
  1729. table->AcDcGpio = SMU7_UNUSED_GPIO_PIN;
  1730. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  1731. PHM_PlatformCaps_AutomaticDCTransition);
  1732. }
  1733. /* Thermal Output GPIO */
  1734. if (atomctrl_get_pp_assign_pin(hwmgr,
  1735. THERMAL_INT_OUTPUT_GPIO_PINID, &gpio_pin)) {
  1736. table->ThermOutGpio = gpio_pin.uc_gpio_pin_bit_shift;
  1737. /* For porlarity read GPIOPAD_A with assigned Gpio pin
  1738. * since VBIOS will program this register to set 'inactive state',
  1739. * driver can then determine 'active state' from this and
  1740. * program SMU with correct polarity
  1741. */
  1742. table->ThermOutPolarity =
  1743. (0 == (cgs_read_register(hwmgr->device, mmGPIOPAD_A) &
  1744. (1 << gpio_pin.uc_gpio_pin_bit_shift))) ? 1:0;
  1745. table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_ONLY;
  1746. /* if required, combine VRHot/PCC with thermal out GPIO */
  1747. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1748. PHM_PlatformCaps_RegulatorHot) &&
  1749. phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1750. PHM_PlatformCaps_CombinePCCWithThermalSignal))
  1751. table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_VRHOT;
  1752. } else {
  1753. table->ThermOutGpio = 17;
  1754. table->ThermOutPolarity = 1;
  1755. table->ThermOutMode = SMU7_THERM_OUT_MODE_DISABLE;
  1756. }
  1757. /* Populate BIF_SCLK levels into SMC DPM table */
  1758. for (i = 0; i <= hw_data->dpm_table.pcie_speed_table.count; i++) {
  1759. result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
  1760. smu_data->bif_sclk_table[i], &dividers);
  1761. PP_ASSERT_WITH_CODE(!result,
  1762. "Can not find DFS divide id for Sclk",
  1763. return result);
  1764. if (i == 0)
  1765. table->Ulv.BifSclkDfs =
  1766. PP_HOST_TO_SMC_US((uint16_t)(dividers.pll_post_divider));
  1767. else
  1768. table->LinkLevel[i - 1].BifSclkDfs =
  1769. PP_HOST_TO_SMC_US((uint16_t)(dividers.pll_post_divider));
  1770. }
  1771. for (i = 0; i < SMU75_MAX_ENTRIES_SMIO; i++)
  1772. table->Smio[i] = PP_HOST_TO_SMC_UL(table->Smio[i]);
  1773. CONVERT_FROM_HOST_TO_SMC_UL(table->SystemFlags);
  1774. CONVERT_FROM_HOST_TO_SMC_UL(table->VRConfig);
  1775. CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask1);
  1776. CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask2);
  1777. CONVERT_FROM_HOST_TO_SMC_UL(table->SclkStepSize);
  1778. CONVERT_FROM_HOST_TO_SMC_UL(table->CurrSclkPllRange);
  1779. CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitHigh);
  1780. CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitLow);
  1781. CONVERT_FROM_HOST_TO_SMC_US(table->VoltageResponseTime);
  1782. CONVERT_FROM_HOST_TO_SMC_US(table->PhaseResponseTime);
  1783. /* Upload all dpm data to SMC memory.(dpm level, dpm level count etc) */
  1784. result = smu7_copy_bytes_to_smc(hwmgr,
  1785. smu_data->smu7_data.dpm_table_start +
  1786. offsetof(SMU75_Discrete_DpmTable, SystemFlags),
  1787. (uint8_t *)&(table->SystemFlags),
  1788. sizeof(SMU75_Discrete_DpmTable) - 3 * sizeof(SMU75_PIDController),
  1789. SMC_RAM_END);
  1790. PP_ASSERT_WITH_CODE(!result,
  1791. "Failed to upload dpm data to SMC memory!", return result);
  1792. result = vegam_populate_pm_fuses(hwmgr);
  1793. PP_ASSERT_WITH_CODE(!result,
  1794. "Failed to populate PM fuses to SMC memory!", return result);
  1795. result = vegam_enable_reconfig_cus(hwmgr);
  1796. PP_ASSERT_WITH_CODE(!result,
  1797. "Failed to enable reconfigurable CUs!", return result);
  1798. return 0;
  1799. }
  1800. static uint32_t vegam_get_offsetof(uint32_t type, uint32_t member)
  1801. {
  1802. switch (type) {
  1803. case SMU_SoftRegisters:
  1804. switch (member) {
  1805. case HandshakeDisables:
  1806. return offsetof(SMU75_SoftRegisters, HandshakeDisables);
  1807. case VoltageChangeTimeout:
  1808. return offsetof(SMU75_SoftRegisters, VoltageChangeTimeout);
  1809. case AverageGraphicsActivity:
  1810. return offsetof(SMU75_SoftRegisters, AverageGraphicsActivity);
  1811. case PreVBlankGap:
  1812. return offsetof(SMU75_SoftRegisters, PreVBlankGap);
  1813. case VBlankTimeout:
  1814. return offsetof(SMU75_SoftRegisters, VBlankTimeout);
  1815. case UcodeLoadStatus:
  1816. return offsetof(SMU75_SoftRegisters, UcodeLoadStatus);
  1817. case DRAM_LOG_ADDR_H:
  1818. return offsetof(SMU75_SoftRegisters, DRAM_LOG_ADDR_H);
  1819. case DRAM_LOG_ADDR_L:
  1820. return offsetof(SMU75_SoftRegisters, DRAM_LOG_ADDR_L);
  1821. case DRAM_LOG_PHY_ADDR_H:
  1822. return offsetof(SMU75_SoftRegisters, DRAM_LOG_PHY_ADDR_H);
  1823. case DRAM_LOG_PHY_ADDR_L:
  1824. return offsetof(SMU75_SoftRegisters, DRAM_LOG_PHY_ADDR_L);
  1825. case DRAM_LOG_BUFF_SIZE:
  1826. return offsetof(SMU75_SoftRegisters, DRAM_LOG_BUFF_SIZE);
  1827. }
  1828. break;
  1829. case SMU_Discrete_DpmTable:
  1830. switch (member) {
  1831. case UvdBootLevel:
  1832. return offsetof(SMU75_Discrete_DpmTable, UvdBootLevel);
  1833. case VceBootLevel:
  1834. return offsetof(SMU75_Discrete_DpmTable, VceBootLevel);
  1835. case LowSclkInterruptThreshold:
  1836. return offsetof(SMU75_Discrete_DpmTable, LowSclkInterruptThreshold);
  1837. }
  1838. break;
  1839. }
  1840. pr_warn("can't get the offset of type %x member %x\n", type, member);
  1841. return 0;
  1842. }
  1843. static int vegam_program_mem_timing_parameters(struct pp_hwmgr *hwmgr)
  1844. {
  1845. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1846. if (data->need_update_smu7_dpm_table &
  1847. (DPMTABLE_OD_UPDATE_SCLK +
  1848. DPMTABLE_UPDATE_SCLK +
  1849. DPMTABLE_UPDATE_MCLK))
  1850. return vegam_program_memory_timing_parameters(hwmgr);
  1851. return 0;
  1852. }
  1853. static int vegam_update_sclk_threshold(struct pp_hwmgr *hwmgr)
  1854. {
  1855. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1856. struct vegam_smumgr *smu_data =
  1857. (struct vegam_smumgr *)(hwmgr->smu_backend);
  1858. int result = 0;
  1859. uint32_t low_sclk_interrupt_threshold = 0;
  1860. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1861. PHM_PlatformCaps_SclkThrottleLowNotification)
  1862. && (data->low_sclk_interrupt_threshold != 0)) {
  1863. low_sclk_interrupt_threshold =
  1864. data->low_sclk_interrupt_threshold;
  1865. CONVERT_FROM_HOST_TO_SMC_UL(low_sclk_interrupt_threshold);
  1866. result = smu7_copy_bytes_to_smc(
  1867. hwmgr,
  1868. smu_data->smu7_data.dpm_table_start +
  1869. offsetof(SMU75_Discrete_DpmTable,
  1870. LowSclkInterruptThreshold),
  1871. (uint8_t *)&low_sclk_interrupt_threshold,
  1872. sizeof(uint32_t),
  1873. SMC_RAM_END);
  1874. }
  1875. PP_ASSERT_WITH_CODE((result == 0),
  1876. "Failed to update SCLK threshold!", return result);
  1877. result = vegam_program_mem_timing_parameters(hwmgr);
  1878. PP_ASSERT_WITH_CODE((result == 0),
  1879. "Failed to program memory timing parameters!",
  1880. );
  1881. return result;
  1882. }
  1883. int vegam_thermal_avfs_enable(struct pp_hwmgr *hwmgr)
  1884. {
  1885. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1886. int ret;
  1887. if (!hwmgr->avfs_supported)
  1888. return 0;
  1889. ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_EnableAvfs);
  1890. if (!ret) {
  1891. if (data->apply_avfs_cks_off_voltage)
  1892. ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_ApplyAvfsCksOffVoltage);
  1893. }
  1894. return ret;
  1895. }
  1896. static int vegam_thermal_setup_fan_table(struct pp_hwmgr *hwmgr)
  1897. {
  1898. PP_ASSERT_WITH_CODE(hwmgr->thermal_controller.fanInfo.bNoFan,
  1899. "VBIOS fan info is not correct!",
  1900. );
  1901. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  1902. PHM_PlatformCaps_MicrocodeFanControl);
  1903. return 0;
  1904. }
  1905. const struct pp_smumgr_func vegam_smu_funcs = {
  1906. .smu_init = vegam_smu_init,
  1907. .smu_fini = smu7_smu_fini,
  1908. .start_smu = vegam_start_smu,
  1909. .check_fw_load_finish = smu7_check_fw_load_finish,
  1910. .request_smu_load_fw = smu7_reload_firmware,
  1911. .request_smu_load_specific_fw = NULL,
  1912. .send_msg_to_smc = smu7_send_msg_to_smc,
  1913. .send_msg_to_smc_with_parameter = smu7_send_msg_to_smc_with_parameter,
  1914. .process_firmware_header = vegam_process_firmware_header,
  1915. .is_dpm_running = vegam_is_dpm_running,
  1916. .get_mac_definition = vegam_get_mac_definition,
  1917. .update_smc_table = vegam_update_smc_table,
  1918. .init_smc_table = vegam_init_smc_table,
  1919. .get_offsetof = vegam_get_offsetof,
  1920. .populate_all_graphic_levels = vegam_populate_all_graphic_levels,
  1921. .populate_all_memory_levels = vegam_populate_all_memory_levels,
  1922. .update_sclk_threshold = vegam_update_sclk_threshold,
  1923. .is_hw_avfs_present = vegam_is_hw_avfs_present,
  1924. .thermal_avfs_enable = vegam_thermal_avfs_enable,
  1925. .thermal_setup_fan_table = vegam_thermal_setup_fan_table,
  1926. };