polaris10_smumgr.c 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522
  1. /*
  2. * Copyright 2015 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. */
  23. #include "pp_debug.h"
  24. #include "smumgr.h"
  25. #include "smu74.h"
  26. #include "smu_ucode_xfer_vi.h"
  27. #include "polaris10_smumgr.h"
  28. #include "smu74_discrete.h"
  29. #include "smu/smu_7_1_3_d.h"
  30. #include "smu/smu_7_1_3_sh_mask.h"
  31. #include "gmc/gmc_8_1_d.h"
  32. #include "gmc/gmc_8_1_sh_mask.h"
  33. #include "oss/oss_3_0_d.h"
  34. #include "gca/gfx_8_0_d.h"
  35. #include "bif/bif_5_0_d.h"
  36. #include "bif/bif_5_0_sh_mask.h"
  37. #include "ppatomctrl.h"
  38. #include "cgs_common.h"
  39. #include "smu7_ppsmc.h"
  40. #include "smu7_smumgr.h"
  41. #include "smu7_dyn_defaults.h"
  42. #include "smu7_hwmgr.h"
  43. #include "hardwaremanager.h"
  44. #include "ppatomctrl.h"
  45. #include "atombios.h"
  46. #include "pppcielanes.h"
  47. #include "dce/dce_10_0_d.h"
  48. #include "dce/dce_10_0_sh_mask.h"
  49. #define POLARIS10_SMC_SIZE 0x20000
  50. #define POWERTUNE_DEFAULT_SET_MAX 1
  51. #define VDDC_VDDCI_DELTA 200
  52. #define MC_CG_ARB_FREQ_F1 0x0b
  53. static const struct polaris10_pt_defaults polaris10_power_tune_data_set_array[POWERTUNE_DEFAULT_SET_MAX] = {
  54. /* sviLoadLIneEn, SviLoadLineVddC, TDC_VDDC_ThrottleReleaseLimitPerc, TDC_MAWt,
  55. * TdcWaterfallCtl, DTEAmbientTempBase, DisplayCac, BAPM_TEMP_GRADIENT */
  56. { 1, 0xF, 0xFD, 0x19, 5, 45, 0, 0xB0000,
  57. { 0x79, 0x253, 0x25D, 0xAE, 0x72, 0x80, 0x83, 0x86, 0x6F, 0xC8, 0xC9, 0xC9, 0x2F, 0x4D, 0x61},
  58. { 0x17C, 0x172, 0x180, 0x1BC, 0x1B3, 0x1BD, 0x206, 0x200, 0x203, 0x25D, 0x25A, 0x255, 0x2C3, 0x2C5, 0x2B4 } },
  59. };
  60. static const sclkFcwRange_t Range_Table[NUM_SCLK_RANGE] = {
  61. {VCO_2_4, POSTDIV_DIV_BY_16, 75, 160, 112},
  62. {VCO_3_6, POSTDIV_DIV_BY_16, 112, 224, 160},
  63. {VCO_2_4, POSTDIV_DIV_BY_8, 75, 160, 112},
  64. {VCO_3_6, POSTDIV_DIV_BY_8, 112, 224, 160},
  65. {VCO_2_4, POSTDIV_DIV_BY_4, 75, 160, 112},
  66. {VCO_3_6, POSTDIV_DIV_BY_4, 112, 216, 160},
  67. {VCO_2_4, POSTDIV_DIV_BY_2, 75, 160, 108},
  68. {VCO_3_6, POSTDIV_DIV_BY_2, 112, 216, 160} };
  69. #define PPPOLARIS10_TARGETACTIVITY_DFLT 50
  70. static const SMU74_Discrete_GraphicsLevel avfs_graphics_level_polaris10[8] = {
  71. /* Min pcie DeepSleep Activity CgSpll CgSpll CcPwr CcPwr Sclk Enabled Enabled Voltage Power */
  72. /* Voltage, DpmLevel, DivId, Level, FuncCntl3, FuncCntl4, DynRm, DynRm1 Did, Padding,ForActivity, ForThrottle, UpHyst, DownHyst, DownHyst, Throttle */
  73. { 0x100ea446, 0x00, 0x03, 0x3200, 0, 0, 0, 0, 0, 0, 0x01, 0x01, 0x0a, 0x00, 0x00, 0x00, { 0x30750000, 0x3000, 0, 0x2600, 0, 0, 0x0004, 0x8f02, 0xffff, 0x2f00, 0x300e, 0x2700 } },
  74. { 0x400ea446, 0x01, 0x04, 0x3200, 0, 0, 0, 0, 0, 0, 0x01, 0x01, 0x0a, 0x00, 0x00, 0x00, { 0x409c0000, 0x2000, 0, 0x1e00, 1, 1, 0x0004, 0x8300, 0xffff, 0x1f00, 0xcb5e, 0x1a00 } },
  75. { 0x740ea446, 0x01, 0x00, 0x3200, 0, 0, 0, 0, 0, 0, 0x01, 0x01, 0x0a, 0x00, 0x00, 0x00, { 0x50c30000, 0x2800, 0, 0x2000, 1, 1, 0x0004, 0x0c02, 0xffff, 0x2700, 0x6433, 0x2100 } },
  76. { 0xa40ea446, 0x01, 0x00, 0x3200, 0, 0, 0, 0, 0, 0, 0x01, 0x01, 0x0a, 0x00, 0x00, 0x00, { 0x60ea0000, 0x3000, 0, 0x2600, 1, 1, 0x0004, 0x8f02, 0xffff, 0x2f00, 0x300e, 0x2700 } },
  77. { 0xd80ea446, 0x01, 0x00, 0x3200, 0, 0, 0, 0, 0, 0, 0x01, 0x01, 0x0a, 0x00, 0x00, 0x00, { 0x70110100, 0x3800, 0, 0x2c00, 1, 1, 0x0004, 0x1203, 0xffff, 0x3600, 0xc9e2, 0x2e00 } },
  78. { 0x3c0fa446, 0x01, 0x00, 0x3200, 0, 0, 0, 0, 0, 0, 0x01, 0x01, 0x0a, 0x00, 0x00, 0x00, { 0x80380100, 0x2000, 0, 0x1e00, 2, 1, 0x0004, 0x8300, 0xffff, 0x1f00, 0xcb5e, 0x1a00 } },
  79. { 0x6c0fa446, 0x01, 0x00, 0x3200, 0, 0, 0, 0, 0, 0, 0x01, 0x01, 0x0a, 0x00, 0x00, 0x00, { 0x905f0100, 0x2400, 0, 0x1e00, 2, 1, 0x0004, 0x8901, 0xffff, 0x2300, 0x314c, 0x1d00 } },
  80. { 0xa00fa446, 0x01, 0x00, 0x3200, 0, 0, 0, 0, 0, 0, 0x01, 0x01, 0x0a, 0x00, 0x00, 0x00, { 0xa0860100, 0x2800, 0, 0x2000, 2, 1, 0x0004, 0x0c02, 0xffff, 0x2700, 0x6433, 0x2100 } }
  81. };
  82. static const SMU74_Discrete_MemoryLevel avfs_memory_level_polaris10 = {
  83. 0x100ea446, 0, 0x30750000, 0x01, 0x01, 0x01, 0x00, 0x00, 0x64, 0x00, 0x00, 0x1f00, 0x00, 0x00};
  84. static int polaris10_perform_btc(struct pp_hwmgr *hwmgr)
  85. {
  86. int result = 0;
  87. struct smu7_smumgr *smu_data = (struct smu7_smumgr *)(hwmgr->smu_backend);
  88. if (0 != smu_data->avfs_btc_param) {
  89. if (0 != smu7_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_PerformBtc, smu_data->avfs_btc_param)) {
  90. pr_info("[AVFS][SmuPolaris10_PerformBtc] PerformBTC SMU msg failed");
  91. result = -1;
  92. }
  93. }
  94. if (smu_data->avfs_btc_param > 1) {
  95. /* Soft-Reset to reset the engine before loading uCode */
  96. /* halt */
  97. cgs_write_register(hwmgr->device, mmCP_MEC_CNTL, 0x50000000);
  98. /* reset everything */
  99. cgs_write_register(hwmgr->device, mmGRBM_SOFT_RESET, 0xffffffff);
  100. cgs_write_register(hwmgr->device, mmGRBM_SOFT_RESET, 0);
  101. }
  102. return result;
  103. }
  104. static int polaris10_setup_graphics_level_structure(struct pp_hwmgr *hwmgr)
  105. {
  106. uint32_t vr_config;
  107. uint32_t dpm_table_start;
  108. uint16_t u16_boot_mvdd;
  109. uint32_t graphics_level_address, vr_config_address, graphics_level_size;
  110. graphics_level_size = sizeof(avfs_graphics_level_polaris10);
  111. u16_boot_mvdd = PP_HOST_TO_SMC_US(1300 * VOLTAGE_SCALE);
  112. PP_ASSERT_WITH_CODE(0 == smu7_read_smc_sram_dword(hwmgr,
  113. SMU7_FIRMWARE_HEADER_LOCATION + offsetof(SMU74_Firmware_Header, DpmTable),
  114. &dpm_table_start, 0x40000),
  115. "[AVFS][Polaris10_SetupGfxLvlStruct] SMU could not communicate starting address of DPM table",
  116. return -1);
  117. /* Default value for VRConfig = VR_MERGED_WITH_VDDC + VR_STATIC_VOLTAGE(VDDCI) */
  118. vr_config = 0x01000500; /* Real value:0x50001 */
  119. vr_config_address = dpm_table_start + offsetof(SMU74_Discrete_DpmTable, VRConfig);
  120. PP_ASSERT_WITH_CODE(0 == smu7_copy_bytes_to_smc(hwmgr, vr_config_address,
  121. (uint8_t *)&vr_config, sizeof(uint32_t), 0x40000),
  122. "[AVFS][Polaris10_SetupGfxLvlStruct] Problems copying VRConfig value over to SMC",
  123. return -1);
  124. graphics_level_address = dpm_table_start + offsetof(SMU74_Discrete_DpmTable, GraphicsLevel);
  125. PP_ASSERT_WITH_CODE(0 == smu7_copy_bytes_to_smc(hwmgr, graphics_level_address,
  126. (uint8_t *)(&avfs_graphics_level_polaris10),
  127. graphics_level_size, 0x40000),
  128. "[AVFS][Polaris10_SetupGfxLvlStruct] Copying of SCLK DPM table failed!",
  129. return -1);
  130. graphics_level_address = dpm_table_start + offsetof(SMU74_Discrete_DpmTable, MemoryLevel);
  131. PP_ASSERT_WITH_CODE(0 == smu7_copy_bytes_to_smc(hwmgr, graphics_level_address,
  132. (uint8_t *)(&avfs_memory_level_polaris10), sizeof(avfs_memory_level_polaris10), 0x40000),
  133. "[AVFS][Polaris10_SetupGfxLvlStruct] Copying of MCLK DPM table failed!",
  134. return -1);
  135. /* MVDD Boot value - neccessary for getting rid of the hang that occurs during Mclk DPM enablement */
  136. graphics_level_address = dpm_table_start + offsetof(SMU74_Discrete_DpmTable, BootMVdd);
  137. PP_ASSERT_WITH_CODE(0 == smu7_copy_bytes_to_smc(hwmgr, graphics_level_address,
  138. (uint8_t *)(&u16_boot_mvdd), sizeof(u16_boot_mvdd), 0x40000),
  139. "[AVFS][Polaris10_SetupGfxLvlStruct] Copying of DPM table failed!",
  140. return -1);
  141. return 0;
  142. }
  143. static int polaris10_avfs_event_mgr(struct pp_hwmgr *hwmgr)
  144. {
  145. struct smu7_smumgr *smu_data = (struct smu7_smumgr *)(hwmgr->smu_backend);
  146. if (!hwmgr->avfs_supported)
  147. return 0;
  148. PP_ASSERT_WITH_CODE(0 == polaris10_setup_graphics_level_structure(hwmgr),
  149. "[AVFS][Polaris10_AVFSEventMgr] Could not Copy Graphics Level table over to SMU",
  150. return -EINVAL);
  151. if (smu_data->avfs_btc_param > 1) {
  152. pr_info("[AVFS][Polaris10_AVFSEventMgr] AC BTC has not been successfully verified on Fiji. There may be in this setting.");
  153. PP_ASSERT_WITH_CODE(0 == smu7_setup_pwr_virus(hwmgr),
  154. "[AVFS][Polaris10_AVFSEventMgr] Could not setup Pwr Virus for AVFS ",
  155. return -EINVAL);
  156. }
  157. PP_ASSERT_WITH_CODE(0 == polaris10_perform_btc(hwmgr),
  158. "[AVFS][Polaris10_AVFSEventMgr] Failure at SmuPolaris10_PerformBTC. AVFS Disabled",
  159. return -EINVAL);
  160. return 0;
  161. }
  162. static int polaris10_start_smu_in_protection_mode(struct pp_hwmgr *hwmgr)
  163. {
  164. int result = 0;
  165. /* Wait for smc boot up */
  166. /* PHM_WAIT_VFPF_INDIRECT_FIELD_UNEQUAL(smumgr, SMC_IND, RCU_UC_EVENTS, boot_seq_done, 0) */
  167. /* Assert reset */
  168. PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  169. SMC_SYSCON_RESET_CNTL, rst_reg, 1);
  170. result = smu7_upload_smu_firmware_image(hwmgr);
  171. if (result != 0)
  172. return result;
  173. /* Clear status */
  174. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixSMU_STATUS, 0);
  175. PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  176. SMC_SYSCON_CLOCK_CNTL_0, ck_disable, 0);
  177. /* De-assert reset */
  178. PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  179. SMC_SYSCON_RESET_CNTL, rst_reg, 0);
  180. PHM_WAIT_VFPF_INDIRECT_FIELD(hwmgr, SMC_IND, RCU_UC_EVENTS, INTERRUPTS_ENABLED, 1);
  181. /* Call Test SMU message with 0x20000 offset to trigger SMU start */
  182. smu7_send_msg_to_smc_offset(hwmgr);
  183. /* Wait done bit to be set */
  184. /* Check pass/failed indicator */
  185. PHM_WAIT_VFPF_INDIRECT_FIELD_UNEQUAL(hwmgr, SMC_IND, SMU_STATUS, SMU_DONE, 0);
  186. if (1 != PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  187. SMU_STATUS, SMU_PASS))
  188. PP_ASSERT_WITH_CODE(false, "SMU Firmware start failed!", return -1);
  189. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixFIRMWARE_FLAGS, 0);
  190. PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  191. SMC_SYSCON_RESET_CNTL, rst_reg, 1);
  192. PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  193. SMC_SYSCON_RESET_CNTL, rst_reg, 0);
  194. /* Wait for firmware to initialize */
  195. PHM_WAIT_VFPF_INDIRECT_FIELD(hwmgr, SMC_IND, FIRMWARE_FLAGS, INTERRUPTS_ENABLED, 1);
  196. return result;
  197. }
  198. static int polaris10_start_smu_in_non_protection_mode(struct pp_hwmgr *hwmgr)
  199. {
  200. int result = 0;
  201. /* wait for smc boot up */
  202. PHM_WAIT_VFPF_INDIRECT_FIELD_UNEQUAL(hwmgr, SMC_IND, RCU_UC_EVENTS, boot_seq_done, 0);
  203. /* Clear firmware interrupt enable flag */
  204. /* PHM_WRITE_VFPF_INDIRECT_FIELD(pSmuMgr, SMC_IND, SMC_SYSCON_MISC_CNTL, pre_fetcher_en, 1); */
  205. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  206. ixFIRMWARE_FLAGS, 0);
  207. PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  208. SMC_SYSCON_RESET_CNTL,
  209. rst_reg, 1);
  210. result = smu7_upload_smu_firmware_image(hwmgr);
  211. if (result != 0)
  212. return result;
  213. /* Set smc instruct start point at 0x0 */
  214. smu7_program_jump_on_start(hwmgr);
  215. PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  216. SMC_SYSCON_CLOCK_CNTL_0, ck_disable, 0);
  217. PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  218. SMC_SYSCON_RESET_CNTL, rst_reg, 0);
  219. /* Wait for firmware to initialize */
  220. PHM_WAIT_VFPF_INDIRECT_FIELD(hwmgr, SMC_IND,
  221. FIRMWARE_FLAGS, INTERRUPTS_ENABLED, 1);
  222. return result;
  223. }
  224. static int polaris10_start_smu(struct pp_hwmgr *hwmgr)
  225. {
  226. int result = 0;
  227. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  228. /* Only start SMC if SMC RAM is not running */
  229. if (!smu7_is_smc_ram_running(hwmgr) && hwmgr->not_vf) {
  230. smu_data->protected_mode = (uint8_t) (PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SMU_FIRMWARE, SMU_MODE));
  231. smu_data->smu7_data.security_hard_key = (uint8_t) (PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SMU_FIRMWARE, SMU_SEL));
  232. /* Check if SMU is running in protected mode */
  233. if (smu_data->protected_mode == 0)
  234. result = polaris10_start_smu_in_non_protection_mode(hwmgr);
  235. else
  236. result = polaris10_start_smu_in_protection_mode(hwmgr);
  237. if (result != 0)
  238. PP_ASSERT_WITH_CODE(0, "Failed to load SMU ucode.", return result);
  239. polaris10_avfs_event_mgr(hwmgr);
  240. }
  241. /* Setup SoftRegsStart here for register lookup in case DummyBackEnd is used and ProcessFirmwareHeader is not executed */
  242. smu7_read_smc_sram_dword(hwmgr, SMU7_FIRMWARE_HEADER_LOCATION + offsetof(SMU74_Firmware_Header, SoftRegisters),
  243. &(smu_data->smu7_data.soft_regs_start), 0x40000);
  244. result = smu7_request_smu_load_fw(hwmgr);
  245. return result;
  246. }
  247. static bool polaris10_is_hw_avfs_present(struct pp_hwmgr *hwmgr)
  248. {
  249. uint32_t efuse;
  250. efuse = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixSMU_EFUSE_0 + (49*4));
  251. efuse &= 0x00000001;
  252. if (efuse)
  253. return true;
  254. return false;
  255. }
  256. static int polaris10_smu_init(struct pp_hwmgr *hwmgr)
  257. {
  258. struct polaris10_smumgr *smu_data;
  259. smu_data = kzalloc(sizeof(struct polaris10_smumgr), GFP_KERNEL);
  260. if (smu_data == NULL)
  261. return -ENOMEM;
  262. hwmgr->smu_backend = smu_data;
  263. if (smu7_init(hwmgr)) {
  264. kfree(smu_data);
  265. return -EINVAL;
  266. }
  267. return 0;
  268. }
  269. static int polaris10_get_dependency_volt_by_clk(struct pp_hwmgr *hwmgr,
  270. struct phm_ppt_v1_clock_voltage_dependency_table *dep_table,
  271. uint32_t clock, SMU_VoltageLevel *voltage, uint32_t *mvdd)
  272. {
  273. uint32_t i;
  274. uint16_t vddci;
  275. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  276. *voltage = *mvdd = 0;
  277. /* clock - voltage dependency table is empty table */
  278. if (dep_table->count == 0)
  279. return -EINVAL;
  280. for (i = 0; i < dep_table->count; i++) {
  281. /* find first sclk bigger than request */
  282. if (dep_table->entries[i].clk >= clock) {
  283. *voltage |= (dep_table->entries[i].vddc *
  284. VOLTAGE_SCALE) << VDDC_SHIFT;
  285. if (SMU7_VOLTAGE_CONTROL_NONE == data->vddci_control)
  286. *voltage |= (data->vbios_boot_state.vddci_bootup_value *
  287. VOLTAGE_SCALE) << VDDCI_SHIFT;
  288. else if (dep_table->entries[i].vddci)
  289. *voltage |= (dep_table->entries[i].vddci *
  290. VOLTAGE_SCALE) << VDDCI_SHIFT;
  291. else {
  292. vddci = phm_find_closest_vddci(&(data->vddci_voltage_table),
  293. (dep_table->entries[i].vddc -
  294. (uint16_t)VDDC_VDDCI_DELTA));
  295. *voltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
  296. }
  297. if (SMU7_VOLTAGE_CONTROL_NONE == data->mvdd_control)
  298. *mvdd = data->vbios_boot_state.mvdd_bootup_value *
  299. VOLTAGE_SCALE;
  300. else if (dep_table->entries[i].mvdd)
  301. *mvdd = (uint32_t) dep_table->entries[i].mvdd *
  302. VOLTAGE_SCALE;
  303. *voltage |= 1 << PHASES_SHIFT;
  304. return 0;
  305. }
  306. }
  307. /* sclk is bigger than max sclk in the dependence table */
  308. *voltage |= (dep_table->entries[i - 1].vddc * VOLTAGE_SCALE) << VDDC_SHIFT;
  309. if (SMU7_VOLTAGE_CONTROL_NONE == data->vddci_control)
  310. *voltage |= (data->vbios_boot_state.vddci_bootup_value *
  311. VOLTAGE_SCALE) << VDDCI_SHIFT;
  312. else if (dep_table->entries[i-1].vddci) {
  313. vddci = phm_find_closest_vddci(&(data->vddci_voltage_table),
  314. (dep_table->entries[i].vddc -
  315. (uint16_t)VDDC_VDDCI_DELTA));
  316. *voltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
  317. }
  318. if (SMU7_VOLTAGE_CONTROL_NONE == data->mvdd_control)
  319. *mvdd = data->vbios_boot_state.mvdd_bootup_value * VOLTAGE_SCALE;
  320. else if (dep_table->entries[i].mvdd)
  321. *mvdd = (uint32_t) dep_table->entries[i - 1].mvdd * VOLTAGE_SCALE;
  322. return 0;
  323. }
  324. static uint16_t scale_fan_gain_settings(uint16_t raw_setting)
  325. {
  326. uint32_t tmp;
  327. tmp = raw_setting * 4096 / 100;
  328. return (uint16_t)tmp;
  329. }
  330. static int polaris10_populate_bapm_parameters_in_dpm_table(struct pp_hwmgr *hwmgr)
  331. {
  332. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  333. const struct polaris10_pt_defaults *defaults = smu_data->power_tune_defaults;
  334. SMU74_Discrete_DpmTable *table = &(smu_data->smc_state_table);
  335. struct phm_ppt_v1_information *table_info =
  336. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  337. struct phm_cac_tdp_table *cac_dtp_table = table_info->cac_dtp_table;
  338. struct pp_advance_fan_control_parameters *fan_table =
  339. &hwmgr->thermal_controller.advanceFanControlParameters;
  340. int i, j, k;
  341. const uint16_t *pdef1;
  342. const uint16_t *pdef2;
  343. table->DefaultTdp = PP_HOST_TO_SMC_US((uint16_t)(cac_dtp_table->usTDP * 128));
  344. table->TargetTdp = PP_HOST_TO_SMC_US((uint16_t)(cac_dtp_table->usTDP * 128));
  345. PP_ASSERT_WITH_CODE(cac_dtp_table->usTargetOperatingTemp <= 255,
  346. "Target Operating Temp is out of Range!",
  347. );
  348. table->TemperatureLimitEdge = PP_HOST_TO_SMC_US(
  349. cac_dtp_table->usTargetOperatingTemp * 256);
  350. table->TemperatureLimitHotspot = PP_HOST_TO_SMC_US(
  351. cac_dtp_table->usTemperatureLimitHotspot * 256);
  352. table->FanGainEdge = PP_HOST_TO_SMC_US(
  353. scale_fan_gain_settings(fan_table->usFanGainEdge));
  354. table->FanGainHotspot = PP_HOST_TO_SMC_US(
  355. scale_fan_gain_settings(fan_table->usFanGainHotspot));
  356. pdef1 = defaults->BAPMTI_R;
  357. pdef2 = defaults->BAPMTI_RC;
  358. for (i = 0; i < SMU74_DTE_ITERATIONS; i++) {
  359. for (j = 0; j < SMU74_DTE_SOURCES; j++) {
  360. for (k = 0; k < SMU74_DTE_SINKS; k++) {
  361. table->BAPMTI_R[i][j][k] = PP_HOST_TO_SMC_US(*pdef1);
  362. table->BAPMTI_RC[i][j][k] = PP_HOST_TO_SMC_US(*pdef2);
  363. pdef1++;
  364. pdef2++;
  365. }
  366. }
  367. }
  368. return 0;
  369. }
  370. static int polaris10_populate_svi_load_line(struct pp_hwmgr *hwmgr)
  371. {
  372. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  373. const struct polaris10_pt_defaults *defaults = smu_data->power_tune_defaults;
  374. smu_data->power_tune_table.SviLoadLineEn = defaults->SviLoadLineEn;
  375. smu_data->power_tune_table.SviLoadLineVddC = defaults->SviLoadLineVddC;
  376. smu_data->power_tune_table.SviLoadLineTrimVddC = 3;
  377. smu_data->power_tune_table.SviLoadLineOffsetVddC = 0;
  378. return 0;
  379. }
  380. static int polaris10_populate_tdc_limit(struct pp_hwmgr *hwmgr)
  381. {
  382. uint16_t tdc_limit;
  383. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  384. struct phm_ppt_v1_information *table_info =
  385. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  386. const struct polaris10_pt_defaults *defaults = smu_data->power_tune_defaults;
  387. tdc_limit = (uint16_t)(table_info->cac_dtp_table->usTDC * 128);
  388. smu_data->power_tune_table.TDC_VDDC_PkgLimit =
  389. CONVERT_FROM_HOST_TO_SMC_US(tdc_limit);
  390. smu_data->power_tune_table.TDC_VDDC_ThrottleReleaseLimitPerc =
  391. defaults->TDC_VDDC_ThrottleReleaseLimitPerc;
  392. smu_data->power_tune_table.TDC_MAWt = defaults->TDC_MAWt;
  393. return 0;
  394. }
  395. static int polaris10_populate_dw8(struct pp_hwmgr *hwmgr, uint32_t fuse_table_offset)
  396. {
  397. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  398. const struct polaris10_pt_defaults *defaults = smu_data->power_tune_defaults;
  399. uint32_t temp;
  400. if (smu7_read_smc_sram_dword(hwmgr,
  401. fuse_table_offset +
  402. offsetof(SMU74_Discrete_PmFuses, TdcWaterfallCtl),
  403. (uint32_t *)&temp, SMC_RAM_END))
  404. PP_ASSERT_WITH_CODE(false,
  405. "Attempt to read PmFuses.DW6 (SviLoadLineEn) from SMC Failed!",
  406. return -EINVAL);
  407. else {
  408. smu_data->power_tune_table.TdcWaterfallCtl = defaults->TdcWaterfallCtl;
  409. smu_data->power_tune_table.LPMLTemperatureMin =
  410. (uint8_t)((temp >> 16) & 0xff);
  411. smu_data->power_tune_table.LPMLTemperatureMax =
  412. (uint8_t)((temp >> 8) & 0xff);
  413. smu_data->power_tune_table.Reserved = (uint8_t)(temp & 0xff);
  414. }
  415. return 0;
  416. }
  417. static int polaris10_populate_temperature_scaler(struct pp_hwmgr *hwmgr)
  418. {
  419. int i;
  420. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  421. /* Currently not used. Set all to zero. */
  422. for (i = 0; i < 16; i++)
  423. smu_data->power_tune_table.LPMLTemperatureScaler[i] = 0;
  424. return 0;
  425. }
  426. static int polaris10_populate_fuzzy_fan(struct pp_hwmgr *hwmgr)
  427. {
  428. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  429. /* TO DO move to hwmgr */
  430. if ((hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity & (1 << 15))
  431. || 0 == hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity)
  432. hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity =
  433. hwmgr->thermal_controller.advanceFanControlParameters.usDefaultFanOutputSensitivity;
  434. smu_data->power_tune_table.FuzzyFan_PwmSetDelta = PP_HOST_TO_SMC_US(
  435. hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity);
  436. return 0;
  437. }
  438. static int polaris10_populate_gnb_lpml(struct pp_hwmgr *hwmgr)
  439. {
  440. int i;
  441. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  442. /* Currently not used. Set all to zero. */
  443. for (i = 0; i < 16; i++)
  444. smu_data->power_tune_table.GnbLPML[i] = 0;
  445. return 0;
  446. }
  447. static int polaris10_populate_bapm_vddc_base_leakage_sidd(struct pp_hwmgr *hwmgr)
  448. {
  449. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  450. struct phm_ppt_v1_information *table_info =
  451. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  452. uint16_t hi_sidd = smu_data->power_tune_table.BapmVddCBaseLeakageHiSidd;
  453. uint16_t lo_sidd = smu_data->power_tune_table.BapmVddCBaseLeakageLoSidd;
  454. struct phm_cac_tdp_table *cac_table = table_info->cac_dtp_table;
  455. hi_sidd = (uint16_t)(cac_table->usHighCACLeakage / 100 * 256);
  456. lo_sidd = (uint16_t)(cac_table->usLowCACLeakage / 100 * 256);
  457. smu_data->power_tune_table.BapmVddCBaseLeakageHiSidd =
  458. CONVERT_FROM_HOST_TO_SMC_US(hi_sidd);
  459. smu_data->power_tune_table.BapmVddCBaseLeakageLoSidd =
  460. CONVERT_FROM_HOST_TO_SMC_US(lo_sidd);
  461. return 0;
  462. }
  463. static int polaris10_populate_pm_fuses(struct pp_hwmgr *hwmgr)
  464. {
  465. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  466. uint32_t pm_fuse_table_offset;
  467. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  468. PHM_PlatformCaps_PowerContainment)) {
  469. if (smu7_read_smc_sram_dword(hwmgr,
  470. SMU7_FIRMWARE_HEADER_LOCATION +
  471. offsetof(SMU74_Firmware_Header, PmFuseTable),
  472. &pm_fuse_table_offset, SMC_RAM_END))
  473. PP_ASSERT_WITH_CODE(false,
  474. "Attempt to get pm_fuse_table_offset Failed!",
  475. return -EINVAL);
  476. if (polaris10_populate_svi_load_line(hwmgr))
  477. PP_ASSERT_WITH_CODE(false,
  478. "Attempt to populate SviLoadLine Failed!",
  479. return -EINVAL);
  480. if (polaris10_populate_tdc_limit(hwmgr))
  481. PP_ASSERT_WITH_CODE(false,
  482. "Attempt to populate TDCLimit Failed!", return -EINVAL);
  483. if (polaris10_populate_dw8(hwmgr, pm_fuse_table_offset))
  484. PP_ASSERT_WITH_CODE(false,
  485. "Attempt to populate TdcWaterfallCtl, "
  486. "LPMLTemperature Min and Max Failed!",
  487. return -EINVAL);
  488. if (0 != polaris10_populate_temperature_scaler(hwmgr))
  489. PP_ASSERT_WITH_CODE(false,
  490. "Attempt to populate LPMLTemperatureScaler Failed!",
  491. return -EINVAL);
  492. if (polaris10_populate_fuzzy_fan(hwmgr))
  493. PP_ASSERT_WITH_CODE(false,
  494. "Attempt to populate Fuzzy Fan Control parameters Failed!",
  495. return -EINVAL);
  496. if (polaris10_populate_gnb_lpml(hwmgr))
  497. PP_ASSERT_WITH_CODE(false,
  498. "Attempt to populate GnbLPML Failed!",
  499. return -EINVAL);
  500. if (polaris10_populate_bapm_vddc_base_leakage_sidd(hwmgr))
  501. PP_ASSERT_WITH_CODE(false,
  502. "Attempt to populate BapmVddCBaseLeakage Hi and Lo "
  503. "Sidd Failed!", return -EINVAL);
  504. if (smu7_copy_bytes_to_smc(hwmgr, pm_fuse_table_offset,
  505. (uint8_t *)&smu_data->power_tune_table,
  506. (sizeof(struct SMU74_Discrete_PmFuses) - 92), SMC_RAM_END))
  507. PP_ASSERT_WITH_CODE(false,
  508. "Attempt to download PmFuseTable Failed!",
  509. return -EINVAL);
  510. }
  511. return 0;
  512. }
  513. static int polaris10_populate_smc_mvdd_table(struct pp_hwmgr *hwmgr,
  514. SMU74_Discrete_DpmTable *table)
  515. {
  516. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  517. uint32_t count, level;
  518. if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
  519. count = data->mvdd_voltage_table.count;
  520. if (count > SMU_MAX_SMIO_LEVELS)
  521. count = SMU_MAX_SMIO_LEVELS;
  522. for (level = 0; level < count; level++) {
  523. table->SmioTable2.Pattern[level].Voltage =
  524. PP_HOST_TO_SMC_US(data->mvdd_voltage_table.entries[count].value * VOLTAGE_SCALE);
  525. /* Index into DpmTable.Smio. Drive bits from Smio entry to get this voltage level.*/
  526. table->SmioTable2.Pattern[level].Smio =
  527. (uint8_t) level;
  528. table->Smio[level] |=
  529. data->mvdd_voltage_table.entries[level].smio_low;
  530. }
  531. table->SmioMask2 = data->mvdd_voltage_table.mask_low;
  532. table->MvddLevelCount = (uint32_t) PP_HOST_TO_SMC_UL(count);
  533. }
  534. return 0;
  535. }
  536. static int polaris10_populate_smc_vddci_table(struct pp_hwmgr *hwmgr,
  537. struct SMU74_Discrete_DpmTable *table)
  538. {
  539. uint32_t count, level;
  540. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  541. count = data->vddci_voltage_table.count;
  542. if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
  543. if (count > SMU_MAX_SMIO_LEVELS)
  544. count = SMU_MAX_SMIO_LEVELS;
  545. for (level = 0; level < count; ++level) {
  546. table->SmioTable1.Pattern[level].Voltage =
  547. PP_HOST_TO_SMC_US(data->vddci_voltage_table.entries[level].value * VOLTAGE_SCALE);
  548. table->SmioTable1.Pattern[level].Smio = (uint8_t) level;
  549. table->Smio[level] |= data->vddci_voltage_table.entries[level].smio_low;
  550. }
  551. }
  552. table->SmioMask1 = data->vddci_voltage_table.mask_low;
  553. return 0;
  554. }
  555. static int polaris10_populate_cac_table(struct pp_hwmgr *hwmgr,
  556. struct SMU74_Discrete_DpmTable *table)
  557. {
  558. uint32_t count;
  559. uint8_t index;
  560. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  561. struct phm_ppt_v1_information *table_info =
  562. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  563. struct phm_ppt_v1_voltage_lookup_table *lookup_table =
  564. table_info->vddc_lookup_table;
  565. /* tables is already swapped, so in order to use the value from it,
  566. * we need to swap it back.
  567. * We are populating vddc CAC data to BapmVddc table
  568. * in split and merged mode
  569. */
  570. for (count = 0; count < lookup_table->count; count++) {
  571. index = phm_get_voltage_index(lookup_table,
  572. data->vddc_voltage_table.entries[count].value);
  573. table->BapmVddcVidLoSidd[count] = convert_to_vid(lookup_table->entries[index].us_cac_low);
  574. table->BapmVddcVidHiSidd[count] = convert_to_vid(lookup_table->entries[index].us_cac_mid);
  575. table->BapmVddcVidHiSidd2[count] = convert_to_vid(lookup_table->entries[index].us_cac_high);
  576. }
  577. return 0;
  578. }
  579. static int polaris10_populate_smc_voltage_tables(struct pp_hwmgr *hwmgr,
  580. struct SMU74_Discrete_DpmTable *table)
  581. {
  582. polaris10_populate_smc_vddci_table(hwmgr, table);
  583. polaris10_populate_smc_mvdd_table(hwmgr, table);
  584. polaris10_populate_cac_table(hwmgr, table);
  585. return 0;
  586. }
  587. static int polaris10_populate_ulv_level(struct pp_hwmgr *hwmgr,
  588. struct SMU74_Discrete_Ulv *state)
  589. {
  590. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  591. struct phm_ppt_v1_information *table_info =
  592. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  593. state->CcPwrDynRm = 0;
  594. state->CcPwrDynRm1 = 0;
  595. state->VddcOffset = (uint16_t) table_info->us_ulv_voltage_offset;
  596. state->VddcOffsetVid = (uint8_t)(table_info->us_ulv_voltage_offset *
  597. VOLTAGE_VID_OFFSET_SCALE2 / VOLTAGE_VID_OFFSET_SCALE1);
  598. if (hwmgr->chip_id == CHIP_POLARIS12 || hwmgr->is_kicker)
  599. state->VddcPhase = data->vddc_phase_shed_control ^ 0x3;
  600. else
  601. state->VddcPhase = (data->vddc_phase_shed_control) ? 0 : 1;
  602. CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm);
  603. CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm1);
  604. CONVERT_FROM_HOST_TO_SMC_US(state->VddcOffset);
  605. return 0;
  606. }
  607. static int polaris10_populate_ulv_state(struct pp_hwmgr *hwmgr,
  608. struct SMU74_Discrete_DpmTable *table)
  609. {
  610. return polaris10_populate_ulv_level(hwmgr, &table->Ulv);
  611. }
  612. static int polaris10_populate_smc_link_level(struct pp_hwmgr *hwmgr,
  613. struct SMU74_Discrete_DpmTable *table)
  614. {
  615. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  616. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  617. struct smu7_dpm_table *dpm_table = &data->dpm_table;
  618. int i;
  619. /* Index (dpm_table->pcie_speed_table.count)
  620. * is reserved for PCIE boot level. */
  621. for (i = 0; i <= dpm_table->pcie_speed_table.count; i++) {
  622. table->LinkLevel[i].PcieGenSpeed =
  623. (uint8_t)dpm_table->pcie_speed_table.dpm_levels[i].value;
  624. table->LinkLevel[i].PcieLaneCount = (uint8_t)encode_pcie_lane_width(
  625. dpm_table->pcie_speed_table.dpm_levels[i].param1);
  626. table->LinkLevel[i].EnabledForActivity = 1;
  627. table->LinkLevel[i].SPC = (uint8_t)(data->pcie_spc_cap & 0xff);
  628. table->LinkLevel[i].DownThreshold = PP_HOST_TO_SMC_UL(5);
  629. table->LinkLevel[i].UpThreshold = PP_HOST_TO_SMC_UL(30);
  630. }
  631. smu_data->smc_state_table.LinkLevelCount =
  632. (uint8_t)dpm_table->pcie_speed_table.count;
  633. /* To Do move to hwmgr */
  634. data->dpm_level_enable_mask.pcie_dpm_enable_mask =
  635. phm_get_dpm_level_enable_mask_value(&dpm_table->pcie_speed_table);
  636. return 0;
  637. }
  638. static void polaris10_get_sclk_range_table(struct pp_hwmgr *hwmgr,
  639. SMU74_Discrete_DpmTable *table)
  640. {
  641. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  642. uint32_t i, ref_clk;
  643. struct pp_atom_ctrl_sclk_range_table range_table_from_vbios = { { {0} } };
  644. ref_clk = amdgpu_asic_get_xclk((struct amdgpu_device *)hwmgr->adev);
  645. if (0 == atomctrl_get_smc_sclk_range_table(hwmgr, &range_table_from_vbios)) {
  646. for (i = 0; i < NUM_SCLK_RANGE; i++) {
  647. table->SclkFcwRangeTable[i].vco_setting = range_table_from_vbios.entry[i].ucVco_setting;
  648. table->SclkFcwRangeTable[i].postdiv = range_table_from_vbios.entry[i].ucPostdiv;
  649. table->SclkFcwRangeTable[i].fcw_pcc = range_table_from_vbios.entry[i].usFcw_pcc;
  650. table->SclkFcwRangeTable[i].fcw_trans_upper = range_table_from_vbios.entry[i].usFcw_trans_upper;
  651. table->SclkFcwRangeTable[i].fcw_trans_lower = range_table_from_vbios.entry[i].usRcw_trans_lower;
  652. CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_pcc);
  653. CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_upper);
  654. CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_lower);
  655. }
  656. return;
  657. }
  658. for (i = 0; i < NUM_SCLK_RANGE; i++) {
  659. smu_data->range_table[i].trans_lower_frequency = (ref_clk * Range_Table[i].fcw_trans_lower) >> Range_Table[i].postdiv;
  660. smu_data->range_table[i].trans_upper_frequency = (ref_clk * Range_Table[i].fcw_trans_upper) >> Range_Table[i].postdiv;
  661. table->SclkFcwRangeTable[i].vco_setting = Range_Table[i].vco_setting;
  662. table->SclkFcwRangeTable[i].postdiv = Range_Table[i].postdiv;
  663. table->SclkFcwRangeTable[i].fcw_pcc = Range_Table[i].fcw_pcc;
  664. table->SclkFcwRangeTable[i].fcw_trans_upper = Range_Table[i].fcw_trans_upper;
  665. table->SclkFcwRangeTable[i].fcw_trans_lower = Range_Table[i].fcw_trans_lower;
  666. CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_pcc);
  667. CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_upper);
  668. CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_lower);
  669. }
  670. }
  671. static int polaris10_calculate_sclk_params(struct pp_hwmgr *hwmgr,
  672. uint32_t clock, SMU_SclkSetting *sclk_setting)
  673. {
  674. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  675. const SMU74_Discrete_DpmTable *table = &(smu_data->smc_state_table);
  676. struct pp_atomctrl_clock_dividers_ai dividers;
  677. uint32_t ref_clock;
  678. uint32_t pcc_target_percent, pcc_target_freq, ss_target_percent, ss_target_freq;
  679. uint8_t i;
  680. int result;
  681. uint64_t temp;
  682. sclk_setting->SclkFrequency = clock;
  683. /* get the engine clock dividers for this clock value */
  684. result = atomctrl_get_engine_pll_dividers_ai(hwmgr, clock, &dividers);
  685. if (result == 0) {
  686. sclk_setting->Fcw_int = dividers.usSclk_fcw_int;
  687. sclk_setting->Fcw_frac = dividers.usSclk_fcw_frac;
  688. sclk_setting->Pcc_fcw_int = dividers.usPcc_fcw_int;
  689. sclk_setting->PllRange = dividers.ucSclkPllRange;
  690. sclk_setting->Sclk_slew_rate = 0x400;
  691. sclk_setting->Pcc_up_slew_rate = dividers.usPcc_fcw_slew_frac;
  692. sclk_setting->Pcc_down_slew_rate = 0xffff;
  693. sclk_setting->SSc_En = dividers.ucSscEnable;
  694. sclk_setting->Fcw1_int = dividers.usSsc_fcw1_int;
  695. sclk_setting->Fcw1_frac = dividers.usSsc_fcw1_frac;
  696. sclk_setting->Sclk_ss_slew_rate = dividers.usSsc_fcw_slew_frac;
  697. return result;
  698. }
  699. ref_clock = amdgpu_asic_get_xclk((struct amdgpu_device *)hwmgr->adev);
  700. for (i = 0; i < NUM_SCLK_RANGE; i++) {
  701. if (clock > smu_data->range_table[i].trans_lower_frequency
  702. && clock <= smu_data->range_table[i].trans_upper_frequency) {
  703. sclk_setting->PllRange = i;
  704. break;
  705. }
  706. }
  707. sclk_setting->Fcw_int = (uint16_t)((clock << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv) / ref_clock);
  708. temp = clock << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv;
  709. temp <<= 0x10;
  710. do_div(temp, ref_clock);
  711. sclk_setting->Fcw_frac = temp & 0xffff;
  712. pcc_target_percent = 10; /* Hardcode 10% for now. */
  713. pcc_target_freq = clock - (clock * pcc_target_percent / 100);
  714. sclk_setting->Pcc_fcw_int = (uint16_t)((pcc_target_freq << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv) / ref_clock);
  715. ss_target_percent = 2; /* Hardcode 2% for now. */
  716. sclk_setting->SSc_En = 0;
  717. if (ss_target_percent) {
  718. sclk_setting->SSc_En = 1;
  719. ss_target_freq = clock - (clock * ss_target_percent / 100);
  720. sclk_setting->Fcw1_int = (uint16_t)((ss_target_freq << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv) / ref_clock);
  721. temp = ss_target_freq << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv;
  722. temp <<= 0x10;
  723. do_div(temp, ref_clock);
  724. sclk_setting->Fcw1_frac = temp & 0xffff;
  725. }
  726. return 0;
  727. }
  728. static int polaris10_populate_single_graphic_level(struct pp_hwmgr *hwmgr,
  729. uint32_t clock, struct SMU74_Discrete_GraphicsLevel *level)
  730. {
  731. int result;
  732. /* PP_Clocks minClocks; */
  733. uint32_t mvdd;
  734. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  735. struct phm_ppt_v1_information *table_info =
  736. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  737. SMU_SclkSetting curr_sclk_setting = { 0 };
  738. phm_ppt_v1_clock_voltage_dependency_table *vdd_dep_table = NULL;
  739. result = polaris10_calculate_sclk_params(hwmgr, clock, &curr_sclk_setting);
  740. if (hwmgr->od_enabled)
  741. vdd_dep_table = (phm_ppt_v1_clock_voltage_dependency_table *)&data->odn_dpm_table.vdd_dependency_on_sclk;
  742. else
  743. vdd_dep_table = table_info->vdd_dep_on_sclk;
  744. /* populate graphics levels */
  745. result = polaris10_get_dependency_volt_by_clk(hwmgr,
  746. vdd_dep_table, clock,
  747. &level->MinVoltage, &mvdd);
  748. PP_ASSERT_WITH_CODE((0 == result),
  749. "can not find VDDC voltage value for "
  750. "VDDC engine clock dependency table",
  751. return result);
  752. level->ActivityLevel = data->current_profile_setting.sclk_activity;
  753. level->CcPwrDynRm = 0;
  754. level->CcPwrDynRm1 = 0;
  755. level->EnabledForActivity = 0;
  756. level->EnabledForThrottle = 1;
  757. level->UpHyst = data->current_profile_setting.sclk_up_hyst;
  758. level->DownHyst = data->current_profile_setting.sclk_down_hyst;
  759. level->VoltageDownHyst = 0;
  760. level->PowerThrottle = 0;
  761. data->display_timing.min_clock_in_sr = hwmgr->display_config->min_core_set_clock_in_sr;
  762. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep))
  763. level->DeepSleepDivId = smu7_get_sleep_divider_id_from_clock(clock,
  764. hwmgr->display_config->min_core_set_clock_in_sr);
  765. /* Default to slow, highest DPM level will be
  766. * set to PPSMC_DISPLAY_WATERMARK_LOW later.
  767. */
  768. if (data->update_up_hyst)
  769. level->UpHyst = (uint8_t)data->up_hyst;
  770. if (data->update_down_hyst)
  771. level->DownHyst = (uint8_t)data->down_hyst;
  772. level->SclkSetting = curr_sclk_setting;
  773. CONVERT_FROM_HOST_TO_SMC_UL(level->MinVoltage);
  774. CONVERT_FROM_HOST_TO_SMC_UL(level->CcPwrDynRm);
  775. CONVERT_FROM_HOST_TO_SMC_UL(level->CcPwrDynRm1);
  776. CONVERT_FROM_HOST_TO_SMC_US(level->ActivityLevel);
  777. CONVERT_FROM_HOST_TO_SMC_UL(level->SclkSetting.SclkFrequency);
  778. CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw_int);
  779. CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw_frac);
  780. CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Pcc_fcw_int);
  781. CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Sclk_slew_rate);
  782. CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Pcc_up_slew_rate);
  783. CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Pcc_down_slew_rate);
  784. CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw1_int);
  785. CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw1_frac);
  786. CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Sclk_ss_slew_rate);
  787. return 0;
  788. }
  789. static int polaris10_populate_all_graphic_levels(struct pp_hwmgr *hwmgr)
  790. {
  791. struct smu7_hwmgr *hw_data = (struct smu7_hwmgr *)(hwmgr->backend);
  792. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  793. struct smu7_dpm_table *dpm_table = &hw_data->dpm_table;
  794. struct phm_ppt_v1_information *table_info =
  795. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  796. struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table;
  797. uint8_t pcie_entry_cnt = (uint8_t) hw_data->dpm_table.pcie_speed_table.count;
  798. int result = 0;
  799. uint32_t array = smu_data->smu7_data.dpm_table_start +
  800. offsetof(SMU74_Discrete_DpmTable, GraphicsLevel);
  801. uint32_t array_size = sizeof(struct SMU74_Discrete_GraphicsLevel) *
  802. SMU74_MAX_LEVELS_GRAPHICS;
  803. struct SMU74_Discrete_GraphicsLevel *levels =
  804. smu_data->smc_state_table.GraphicsLevel;
  805. uint32_t i, max_entry;
  806. uint8_t hightest_pcie_level_enabled = 0,
  807. lowest_pcie_level_enabled = 0,
  808. mid_pcie_level_enabled = 0,
  809. count = 0;
  810. polaris10_get_sclk_range_table(hwmgr, &(smu_data->smc_state_table));
  811. for (i = 0; i < dpm_table->sclk_table.count; i++) {
  812. result = polaris10_populate_single_graphic_level(hwmgr,
  813. dpm_table->sclk_table.dpm_levels[i].value,
  814. &(smu_data->smc_state_table.GraphicsLevel[i]));
  815. if (result)
  816. return result;
  817. /* Making sure only DPM level 0-1 have Deep Sleep Div ID populated. */
  818. if (i > 1)
  819. levels[i].DeepSleepDivId = 0;
  820. }
  821. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  822. PHM_PlatformCaps_SPLLShutdownSupport))
  823. smu_data->smc_state_table.GraphicsLevel[0].SclkSetting.SSc_En = 0;
  824. smu_data->smc_state_table.GraphicsLevel[0].EnabledForActivity = 1;
  825. smu_data->smc_state_table.GraphicsDpmLevelCount =
  826. (uint8_t)dpm_table->sclk_table.count;
  827. hw_data->dpm_level_enable_mask.sclk_dpm_enable_mask =
  828. phm_get_dpm_level_enable_mask_value(&dpm_table->sclk_table);
  829. if (pcie_table != NULL) {
  830. PP_ASSERT_WITH_CODE((1 <= pcie_entry_cnt),
  831. "There must be 1 or more PCIE levels defined in PPTable.",
  832. return -EINVAL);
  833. max_entry = pcie_entry_cnt - 1;
  834. for (i = 0; i < dpm_table->sclk_table.count; i++)
  835. levels[i].pcieDpmLevel =
  836. (uint8_t) ((i < max_entry) ? i : max_entry);
  837. } else {
  838. while (hw_data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
  839. ((hw_data->dpm_level_enable_mask.pcie_dpm_enable_mask &
  840. (1 << (hightest_pcie_level_enabled + 1))) != 0))
  841. hightest_pcie_level_enabled++;
  842. while (hw_data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
  843. ((hw_data->dpm_level_enable_mask.pcie_dpm_enable_mask &
  844. (1 << lowest_pcie_level_enabled)) == 0))
  845. lowest_pcie_level_enabled++;
  846. while ((count < hightest_pcie_level_enabled) &&
  847. ((hw_data->dpm_level_enable_mask.pcie_dpm_enable_mask &
  848. (1 << (lowest_pcie_level_enabled + 1 + count))) == 0))
  849. count++;
  850. mid_pcie_level_enabled = (lowest_pcie_level_enabled + 1 + count) <
  851. hightest_pcie_level_enabled ?
  852. (lowest_pcie_level_enabled + 1 + count) :
  853. hightest_pcie_level_enabled;
  854. /* set pcieDpmLevel to hightest_pcie_level_enabled */
  855. for (i = 2; i < dpm_table->sclk_table.count; i++)
  856. levels[i].pcieDpmLevel = hightest_pcie_level_enabled;
  857. /* set pcieDpmLevel to lowest_pcie_level_enabled */
  858. levels[0].pcieDpmLevel = lowest_pcie_level_enabled;
  859. /* set pcieDpmLevel to mid_pcie_level_enabled */
  860. levels[1].pcieDpmLevel = mid_pcie_level_enabled;
  861. }
  862. /* level count will send to smc once at init smc table and never change */
  863. result = smu7_copy_bytes_to_smc(hwmgr, array, (uint8_t *)levels,
  864. (uint32_t)array_size, SMC_RAM_END);
  865. return result;
  866. }
  867. static int polaris10_populate_single_memory_level(struct pp_hwmgr *hwmgr,
  868. uint32_t clock, struct SMU74_Discrete_MemoryLevel *mem_level)
  869. {
  870. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  871. struct phm_ppt_v1_information *table_info =
  872. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  873. int result = 0;
  874. uint32_t mclk_stutter_mode_threshold = 40000;
  875. phm_ppt_v1_clock_voltage_dependency_table *vdd_dep_table = NULL;
  876. if (hwmgr->od_enabled)
  877. vdd_dep_table = (phm_ppt_v1_clock_voltage_dependency_table *)&data->odn_dpm_table.vdd_dependency_on_mclk;
  878. else
  879. vdd_dep_table = table_info->vdd_dep_on_mclk;
  880. if (vdd_dep_table) {
  881. result = polaris10_get_dependency_volt_by_clk(hwmgr,
  882. vdd_dep_table, clock,
  883. &mem_level->MinVoltage, &mem_level->MinMvdd);
  884. PP_ASSERT_WITH_CODE((0 == result),
  885. "can not find MinVddc voltage value from memory "
  886. "VDDC voltage dependency table", return result);
  887. }
  888. mem_level->MclkFrequency = clock;
  889. mem_level->EnabledForThrottle = 1;
  890. mem_level->EnabledForActivity = 0;
  891. mem_level->UpHyst = data->current_profile_setting.mclk_up_hyst;
  892. mem_level->DownHyst = data->current_profile_setting.mclk_down_hyst;
  893. mem_level->VoltageDownHyst = 0;
  894. mem_level->ActivityLevel = data->current_profile_setting.mclk_activity;
  895. mem_level->StutterEnable = false;
  896. mem_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
  897. data->display_timing.num_existing_displays = hwmgr->display_config->num_display;
  898. if (mclk_stutter_mode_threshold &&
  899. (clock <= mclk_stutter_mode_threshold) &&
  900. (PHM_READ_FIELD(hwmgr->device, DPG_PIPE_STUTTER_CONTROL,
  901. STUTTER_ENABLE) & 0x1))
  902. mem_level->StutterEnable = true;
  903. if (!result) {
  904. CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MinMvdd);
  905. CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MclkFrequency);
  906. CONVERT_FROM_HOST_TO_SMC_US(mem_level->ActivityLevel);
  907. CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MinVoltage);
  908. }
  909. return result;
  910. }
  911. static int polaris10_populate_all_memory_levels(struct pp_hwmgr *hwmgr)
  912. {
  913. struct smu7_hwmgr *hw_data = (struct smu7_hwmgr *)(hwmgr->backend);
  914. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  915. struct smu7_dpm_table *dpm_table = &hw_data->dpm_table;
  916. int result;
  917. /* populate MCLK dpm table to SMU7 */
  918. uint32_t array = smu_data->smu7_data.dpm_table_start +
  919. offsetof(SMU74_Discrete_DpmTable, MemoryLevel);
  920. uint32_t array_size = sizeof(SMU74_Discrete_MemoryLevel) *
  921. SMU74_MAX_LEVELS_MEMORY;
  922. struct SMU74_Discrete_MemoryLevel *levels =
  923. smu_data->smc_state_table.MemoryLevel;
  924. uint32_t i;
  925. for (i = 0; i < dpm_table->mclk_table.count; i++) {
  926. PP_ASSERT_WITH_CODE((0 != dpm_table->mclk_table.dpm_levels[i].value),
  927. "can not populate memory level as memory clock is zero",
  928. return -EINVAL);
  929. result = polaris10_populate_single_memory_level(hwmgr,
  930. dpm_table->mclk_table.dpm_levels[i].value,
  931. &levels[i]);
  932. if (i == dpm_table->mclk_table.count - 1) {
  933. levels[i].DisplayWatermark = PPSMC_DISPLAY_WATERMARK_HIGH;
  934. levels[i].EnabledForActivity = 1;
  935. }
  936. if (result)
  937. return result;
  938. }
  939. /* In order to prevent MC activity from stutter mode to push DPM up,
  940. * the UVD change complements this by putting the MCLK in
  941. * a higher state by default such that we are not affected by
  942. * up threshold or and MCLK DPM latency.
  943. */
  944. levels[0].ActivityLevel = 0x1f;
  945. CONVERT_FROM_HOST_TO_SMC_US(levels[0].ActivityLevel);
  946. smu_data->smc_state_table.MemoryDpmLevelCount =
  947. (uint8_t)dpm_table->mclk_table.count;
  948. hw_data->dpm_level_enable_mask.mclk_dpm_enable_mask =
  949. phm_get_dpm_level_enable_mask_value(&dpm_table->mclk_table);
  950. /* level count will send to smc once at init smc table and never change */
  951. result = smu7_copy_bytes_to_smc(hwmgr, array, (uint8_t *)levels,
  952. (uint32_t)array_size, SMC_RAM_END);
  953. return result;
  954. }
  955. static int polaris10_populate_mvdd_value(struct pp_hwmgr *hwmgr,
  956. uint32_t mclk, SMIO_Pattern *smio_pat)
  957. {
  958. const struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  959. struct phm_ppt_v1_information *table_info =
  960. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  961. uint32_t i = 0;
  962. if (SMU7_VOLTAGE_CONTROL_NONE != data->mvdd_control) {
  963. /* find mvdd value which clock is more than request */
  964. for (i = 0; i < table_info->vdd_dep_on_mclk->count; i++) {
  965. if (mclk <= table_info->vdd_dep_on_mclk->entries[i].clk) {
  966. smio_pat->Voltage = data->mvdd_voltage_table.entries[i].value;
  967. break;
  968. }
  969. }
  970. PP_ASSERT_WITH_CODE(i < table_info->vdd_dep_on_mclk->count,
  971. "MVDD Voltage is outside the supported range.",
  972. return -EINVAL);
  973. } else
  974. return -EINVAL;
  975. return 0;
  976. }
  977. static int polaris10_populate_smc_acpi_level(struct pp_hwmgr *hwmgr,
  978. SMU74_Discrete_DpmTable *table)
  979. {
  980. int result = 0;
  981. uint32_t sclk_frequency;
  982. const struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  983. struct phm_ppt_v1_information *table_info =
  984. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  985. SMIO_Pattern vol_level;
  986. uint32_t mvdd;
  987. table->ACPILevel.Flags &= ~PPSMC_SWSTATE_FLAG_DC;
  988. /* Get MinVoltage and Frequency from DPM0,
  989. * already converted to SMC_UL */
  990. sclk_frequency = data->vbios_boot_state.sclk_bootup_value;
  991. result = polaris10_get_dependency_volt_by_clk(hwmgr,
  992. table_info->vdd_dep_on_sclk,
  993. sclk_frequency,
  994. &table->ACPILevel.MinVoltage, &mvdd);
  995. PP_ASSERT_WITH_CODE((0 == result),
  996. "Cannot find ACPI VDDC voltage value "
  997. "in Clock Dependency Table",
  998. );
  999. result = polaris10_calculate_sclk_params(hwmgr, sclk_frequency, &(table->ACPILevel.SclkSetting));
  1000. PP_ASSERT_WITH_CODE(result == 0, "Error retrieving Engine Clock dividers from VBIOS.", return result);
  1001. table->ACPILevel.DeepSleepDivId = 0;
  1002. table->ACPILevel.CcPwrDynRm = 0;
  1003. table->ACPILevel.CcPwrDynRm1 = 0;
  1004. CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.Flags);
  1005. CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.MinVoltage);
  1006. CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm);
  1007. CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm1);
  1008. CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SclkSetting.SclkFrequency);
  1009. CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw_int);
  1010. CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw_frac);
  1011. CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Pcc_fcw_int);
  1012. CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Sclk_slew_rate);
  1013. CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Pcc_up_slew_rate);
  1014. CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Pcc_down_slew_rate);
  1015. CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw1_int);
  1016. CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw1_frac);
  1017. CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Sclk_ss_slew_rate);
  1018. /* Get MinVoltage and Frequency from DPM0, already converted to SMC_UL */
  1019. table->MemoryACPILevel.MclkFrequency = data->vbios_boot_state.mclk_bootup_value;
  1020. result = polaris10_get_dependency_volt_by_clk(hwmgr,
  1021. table_info->vdd_dep_on_mclk,
  1022. table->MemoryACPILevel.MclkFrequency,
  1023. &table->MemoryACPILevel.MinVoltage, &mvdd);
  1024. PP_ASSERT_WITH_CODE((0 == result),
  1025. "Cannot find ACPI VDDCI voltage value "
  1026. "in Clock Dependency Table",
  1027. );
  1028. if (!((SMU7_VOLTAGE_CONTROL_NONE == data->mvdd_control) ||
  1029. (data->mclk_dpm_key_disabled)))
  1030. polaris10_populate_mvdd_value(hwmgr,
  1031. data->dpm_table.mclk_table.dpm_levels[0].value,
  1032. &vol_level);
  1033. if (0 == polaris10_populate_mvdd_value(hwmgr, 0, &vol_level))
  1034. table->MemoryACPILevel.MinMvdd = PP_HOST_TO_SMC_UL(vol_level.Voltage);
  1035. else
  1036. table->MemoryACPILevel.MinMvdd = 0;
  1037. table->MemoryACPILevel.StutterEnable = false;
  1038. table->MemoryACPILevel.EnabledForThrottle = 0;
  1039. table->MemoryACPILevel.EnabledForActivity = 0;
  1040. table->MemoryACPILevel.UpHyst = 0;
  1041. table->MemoryACPILevel.DownHyst = 100;
  1042. table->MemoryACPILevel.VoltageDownHyst = 0;
  1043. table->MemoryACPILevel.ActivityLevel =
  1044. PP_HOST_TO_SMC_US(data->current_profile_setting.mclk_activity);
  1045. CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MclkFrequency);
  1046. CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MinVoltage);
  1047. return result;
  1048. }
  1049. static int polaris10_populate_smc_vce_level(struct pp_hwmgr *hwmgr,
  1050. SMU74_Discrete_DpmTable *table)
  1051. {
  1052. int result = -EINVAL;
  1053. uint8_t count;
  1054. struct pp_atomctrl_clock_dividers_vi dividers;
  1055. struct phm_ppt_v1_information *table_info =
  1056. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1057. struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
  1058. table_info->mm_dep_table;
  1059. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1060. uint32_t vddci;
  1061. table->VceLevelCount = (uint8_t)(mm_table->count);
  1062. table->VceBootLevel = 0;
  1063. for (count = 0; count < table->VceLevelCount; count++) {
  1064. table->VceLevel[count].Frequency = mm_table->entries[count].eclk;
  1065. table->VceLevel[count].MinVoltage = 0;
  1066. table->VceLevel[count].MinVoltage |=
  1067. (mm_table->entries[count].vddc * VOLTAGE_SCALE) << VDDC_SHIFT;
  1068. if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control)
  1069. vddci = (uint32_t)phm_find_closest_vddci(&(data->vddci_voltage_table),
  1070. mm_table->entries[count].vddc - VDDC_VDDCI_DELTA);
  1071. else if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control)
  1072. vddci = mm_table->entries[count].vddc - VDDC_VDDCI_DELTA;
  1073. else
  1074. vddci = (data->vbios_boot_state.vddci_bootup_value * VOLTAGE_SCALE) << VDDCI_SHIFT;
  1075. table->VceLevel[count].MinVoltage |=
  1076. (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
  1077. table->VceLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
  1078. /*retrieve divider value for VBIOS */
  1079. result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
  1080. table->VceLevel[count].Frequency, &dividers);
  1081. PP_ASSERT_WITH_CODE((0 == result),
  1082. "can not find divide id for VCE engine clock",
  1083. return result);
  1084. table->VceLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
  1085. CONVERT_FROM_HOST_TO_SMC_UL(table->VceLevel[count].Frequency);
  1086. CONVERT_FROM_HOST_TO_SMC_UL(table->VceLevel[count].MinVoltage);
  1087. }
  1088. return result;
  1089. }
  1090. static int polaris10_populate_memory_timing_parameters(struct pp_hwmgr *hwmgr,
  1091. int32_t eng_clock, int32_t mem_clock,
  1092. SMU74_Discrete_MCArbDramTimingTableEntry *arb_regs)
  1093. {
  1094. uint32_t dram_timing;
  1095. uint32_t dram_timing2;
  1096. uint32_t burst_time;
  1097. int result;
  1098. result = atomctrl_set_engine_dram_timings_rv770(hwmgr,
  1099. eng_clock, mem_clock);
  1100. PP_ASSERT_WITH_CODE(result == 0,
  1101. "Error calling VBIOS to set DRAM_TIMING.", return result);
  1102. dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
  1103. dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
  1104. burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0);
  1105. arb_regs->McArbDramTiming = PP_HOST_TO_SMC_UL(dram_timing);
  1106. arb_regs->McArbDramTiming2 = PP_HOST_TO_SMC_UL(dram_timing2);
  1107. arb_regs->McArbBurstTime = (uint8_t)burst_time;
  1108. return 0;
  1109. }
  1110. static int polaris10_program_memory_timing_parameters(struct pp_hwmgr *hwmgr)
  1111. {
  1112. struct smu7_hwmgr *hw_data = (struct smu7_hwmgr *)(hwmgr->backend);
  1113. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  1114. struct SMU74_Discrete_MCArbDramTimingTable arb_regs;
  1115. uint32_t i, j;
  1116. int result = 0;
  1117. for (i = 0; i < hw_data->dpm_table.sclk_table.count; i++) {
  1118. for (j = 0; j < hw_data->dpm_table.mclk_table.count; j++) {
  1119. result = polaris10_populate_memory_timing_parameters(hwmgr,
  1120. hw_data->dpm_table.sclk_table.dpm_levels[i].value,
  1121. hw_data->dpm_table.mclk_table.dpm_levels[j].value,
  1122. &arb_regs.entries[i][j]);
  1123. if (result == 0)
  1124. result = atomctrl_set_ac_timing_ai(hwmgr, hw_data->dpm_table.mclk_table.dpm_levels[j].value, j);
  1125. if (result != 0)
  1126. return result;
  1127. }
  1128. }
  1129. result = smu7_copy_bytes_to_smc(
  1130. hwmgr,
  1131. smu_data->smu7_data.arb_table_start,
  1132. (uint8_t *)&arb_regs,
  1133. sizeof(SMU74_Discrete_MCArbDramTimingTable),
  1134. SMC_RAM_END);
  1135. return result;
  1136. }
  1137. static int polaris10_populate_smc_uvd_level(struct pp_hwmgr *hwmgr,
  1138. struct SMU74_Discrete_DpmTable *table)
  1139. {
  1140. int result = -EINVAL;
  1141. uint8_t count;
  1142. struct pp_atomctrl_clock_dividers_vi dividers;
  1143. struct phm_ppt_v1_information *table_info =
  1144. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1145. struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
  1146. table_info->mm_dep_table;
  1147. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1148. uint32_t vddci;
  1149. table->UvdLevelCount = (uint8_t)(mm_table->count);
  1150. table->UvdBootLevel = 0;
  1151. for (count = 0; count < table->UvdLevelCount; count++) {
  1152. table->UvdLevel[count].MinVoltage = 0;
  1153. table->UvdLevel[count].VclkFrequency = mm_table->entries[count].vclk;
  1154. table->UvdLevel[count].DclkFrequency = mm_table->entries[count].dclk;
  1155. table->UvdLevel[count].MinVoltage |= (mm_table->entries[count].vddc *
  1156. VOLTAGE_SCALE) << VDDC_SHIFT;
  1157. if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control)
  1158. vddci = (uint32_t)phm_find_closest_vddci(&(data->vddci_voltage_table),
  1159. mm_table->entries[count].vddc - VDDC_VDDCI_DELTA);
  1160. else if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control)
  1161. vddci = mm_table->entries[count].vddc - VDDC_VDDCI_DELTA;
  1162. else
  1163. vddci = (data->vbios_boot_state.vddci_bootup_value * VOLTAGE_SCALE) << VDDCI_SHIFT;
  1164. table->UvdLevel[count].MinVoltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
  1165. table->UvdLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
  1166. /* retrieve divider value for VBIOS */
  1167. result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
  1168. table->UvdLevel[count].VclkFrequency, &dividers);
  1169. PP_ASSERT_WITH_CODE((0 == result),
  1170. "can not find divide id for Vclk clock", return result);
  1171. table->UvdLevel[count].VclkDivider = (uint8_t)dividers.pll_post_divider;
  1172. result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
  1173. table->UvdLevel[count].DclkFrequency, &dividers);
  1174. PP_ASSERT_WITH_CODE((0 == result),
  1175. "can not find divide id for Dclk clock", return result);
  1176. table->UvdLevel[count].DclkDivider = (uint8_t)dividers.pll_post_divider;
  1177. CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].VclkFrequency);
  1178. CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].DclkFrequency);
  1179. CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].MinVoltage);
  1180. }
  1181. return result;
  1182. }
  1183. static int polaris10_populate_smc_boot_level(struct pp_hwmgr *hwmgr,
  1184. struct SMU74_Discrete_DpmTable *table)
  1185. {
  1186. int result = 0;
  1187. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1188. table->GraphicsBootLevel = 0;
  1189. table->MemoryBootLevel = 0;
  1190. /* find boot level from dpm table */
  1191. result = phm_find_boot_level(&(data->dpm_table.sclk_table),
  1192. data->vbios_boot_state.sclk_bootup_value,
  1193. (uint32_t *)&(table->GraphicsBootLevel));
  1194. result = phm_find_boot_level(&(data->dpm_table.mclk_table),
  1195. data->vbios_boot_state.mclk_bootup_value,
  1196. (uint32_t *)&(table->MemoryBootLevel));
  1197. table->BootVddc = data->vbios_boot_state.vddc_bootup_value *
  1198. VOLTAGE_SCALE;
  1199. table->BootVddci = data->vbios_boot_state.vddci_bootup_value *
  1200. VOLTAGE_SCALE;
  1201. table->BootMVdd = data->vbios_boot_state.mvdd_bootup_value *
  1202. VOLTAGE_SCALE;
  1203. CONVERT_FROM_HOST_TO_SMC_US(table->BootVddc);
  1204. CONVERT_FROM_HOST_TO_SMC_US(table->BootVddci);
  1205. CONVERT_FROM_HOST_TO_SMC_US(table->BootMVdd);
  1206. return 0;
  1207. }
  1208. static int polaris10_populate_smc_initailial_state(struct pp_hwmgr *hwmgr)
  1209. {
  1210. struct smu7_hwmgr *hw_data = (struct smu7_hwmgr *)(hwmgr->backend);
  1211. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  1212. struct phm_ppt_v1_information *table_info =
  1213. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1214. uint8_t count, level;
  1215. count = (uint8_t)(table_info->vdd_dep_on_sclk->count);
  1216. for (level = 0; level < count; level++) {
  1217. if (table_info->vdd_dep_on_sclk->entries[level].clk >=
  1218. hw_data->vbios_boot_state.sclk_bootup_value) {
  1219. smu_data->smc_state_table.GraphicsBootLevel = level;
  1220. break;
  1221. }
  1222. }
  1223. count = (uint8_t)(table_info->vdd_dep_on_mclk->count);
  1224. for (level = 0; level < count; level++) {
  1225. if (table_info->vdd_dep_on_mclk->entries[level].clk >=
  1226. hw_data->vbios_boot_state.mclk_bootup_value) {
  1227. smu_data->smc_state_table.MemoryBootLevel = level;
  1228. break;
  1229. }
  1230. }
  1231. return 0;
  1232. }
  1233. static int polaris10_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 polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  1237. uint8_t i, stretch_amount, volt_offset = 0;
  1238. struct phm_ppt_v1_information *table_info =
  1239. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1240. struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
  1241. table_info->vdd_dep_on_sclk;
  1242. stretch_amount = (uint8_t)table_info->cac_dtp_table->usClockStretchAmount;
  1243. /* Read SMU_Eefuse to read and calculate RO and determine
  1244. * if the part is SS or FF. if RO >= 1660MHz, part is FF.
  1245. */
  1246. efuse = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  1247. ixSMU_EFUSE_0 + (67 * 4));
  1248. efuse &= 0xFF000000;
  1249. efuse = efuse >> 24;
  1250. if (hwmgr->chip_id == CHIP_POLARIS10) {
  1251. if (hwmgr->is_kicker) {
  1252. min = 1200;
  1253. max = 2500;
  1254. } else {
  1255. min = 1000;
  1256. max = 2300;
  1257. }
  1258. } else if (hwmgr->chip_id == CHIP_POLARIS11) {
  1259. if (hwmgr->is_kicker) {
  1260. min = 900;
  1261. max = 2100;
  1262. } else {
  1263. min = 1100;
  1264. max = 2100;
  1265. }
  1266. } else {
  1267. min = 1100;
  1268. max = 2100;
  1269. }
  1270. ro = efuse * (max - min) / 255 + min;
  1271. /* Populate Sclk_CKS_masterEn0_7 and Sclk_voltageOffset */
  1272. for (i = 0; i < sclk_table->count; i++) {
  1273. smu_data->smc_state_table.Sclk_CKS_masterEn0_7 |=
  1274. sclk_table->entries[i].cks_enable << i;
  1275. if (hwmgr->chip_id == CHIP_POLARIS10) {
  1276. volt_without_cks = (uint32_t)((2753594000U + (sclk_table->entries[i].clk/100) * 136418 - (ro - 70) * 1000000) / \
  1277. (2424180 - (sclk_table->entries[i].clk/100) * 1132925/1000));
  1278. volt_with_cks = (uint32_t)((2797202000U + sclk_table->entries[i].clk/100 * 3232 - (ro - 65) * 1000000) / \
  1279. (2522480 - sclk_table->entries[i].clk/100 * 115764/100));
  1280. } else {
  1281. volt_without_cks = (uint32_t)((2416794800U + (sclk_table->entries[i].clk/100) * 1476925/10 - (ro - 50) * 1000000) / \
  1282. (2625416 - (sclk_table->entries[i].clk/100) * (12586807/10000)));
  1283. volt_with_cks = (uint32_t)((2999656000U - sclk_table->entries[i].clk/100 * 392803 - (ro - 44) * 1000000) / \
  1284. (3422454 - sclk_table->entries[i].clk/100 * (18886376/10000)));
  1285. }
  1286. if (volt_without_cks >= volt_with_cks)
  1287. volt_offset = (uint8_t)(((volt_without_cks - volt_with_cks +
  1288. sclk_table->entries[i].cks_voffset) * 100 + 624) / 625);
  1289. smu_data->smc_state_table.Sclk_voltageOffset[i] = volt_offset;
  1290. }
  1291. smu_data->smc_state_table.LdoRefSel = (table_info->cac_dtp_table->ucCKS_LDO_REFSEL != 0) ? table_info->cac_dtp_table->ucCKS_LDO_REFSEL : 6;
  1292. /* Populate CKS Lookup Table */
  1293. if (stretch_amount == 0 || stretch_amount > 5) {
  1294. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  1295. PHM_PlatformCaps_ClockStretcher);
  1296. PP_ASSERT_WITH_CODE(false,
  1297. "Stretch Amount in PPTable not supported",
  1298. return -EINVAL);
  1299. }
  1300. value = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixPWR_CKS_CNTL);
  1301. value &= 0xFFFFFFFE;
  1302. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixPWR_CKS_CNTL, value);
  1303. return 0;
  1304. }
  1305. static int polaris10_populate_vr_config(struct pp_hwmgr *hwmgr,
  1306. struct SMU74_Discrete_DpmTable *table)
  1307. {
  1308. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1309. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  1310. uint16_t config;
  1311. config = VR_MERGED_WITH_VDDC;
  1312. table->VRConfig |= (config << VRCONF_VDDGFX_SHIFT);
  1313. /* Set Vddc Voltage Controller */
  1314. if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
  1315. config = VR_SVI2_PLANE_1;
  1316. table->VRConfig |= config;
  1317. } else {
  1318. PP_ASSERT_WITH_CODE(false,
  1319. "VDDC should be on SVI2 control in merged mode!",
  1320. );
  1321. }
  1322. /* Set Vddci Voltage Controller */
  1323. if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) {
  1324. config = VR_SVI2_PLANE_2; /* only in merged mode */
  1325. table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
  1326. } else if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
  1327. config = VR_SMIO_PATTERN_1;
  1328. table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
  1329. } else {
  1330. config = VR_STATIC_VOLTAGE;
  1331. table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
  1332. }
  1333. /* Set Mvdd Voltage Controller */
  1334. if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) {
  1335. config = VR_SVI2_PLANE_2;
  1336. table->VRConfig |= (config << VRCONF_MVDD_SHIFT);
  1337. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, smu_data->smu7_data.soft_regs_start +
  1338. offsetof(SMU74_SoftRegisters, AllowMvddSwitch), 0x1);
  1339. } else {
  1340. config = VR_STATIC_VOLTAGE;
  1341. table->VRConfig |= (config << VRCONF_MVDD_SHIFT);
  1342. }
  1343. return 0;
  1344. }
  1345. static int polaris10_populate_avfs_parameters(struct pp_hwmgr *hwmgr)
  1346. {
  1347. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1348. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  1349. SMU74_Discrete_DpmTable *table = &(smu_data->smc_state_table);
  1350. int result = 0;
  1351. struct pp_atom_ctrl__avfs_parameters avfs_params = {0};
  1352. AVFS_meanNsigma_t AVFS_meanNsigma = { {0} };
  1353. AVFS_Sclk_Offset_t AVFS_SclkOffset = { {0} };
  1354. uint32_t tmp, i;
  1355. struct phm_ppt_v1_information *table_info =
  1356. (struct phm_ppt_v1_information *)hwmgr->pptable;
  1357. struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
  1358. table_info->vdd_dep_on_sclk;
  1359. if (!hwmgr->avfs_supported)
  1360. return 0;
  1361. result = atomctrl_get_avfs_information(hwmgr, &avfs_params);
  1362. if (0 == result) {
  1363. table->BTCGB_VDROOP_TABLE[0].a0 = PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSON_a0);
  1364. table->BTCGB_VDROOP_TABLE[0].a1 = PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSON_a1);
  1365. table->BTCGB_VDROOP_TABLE[0].a2 = PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSON_a2);
  1366. table->BTCGB_VDROOP_TABLE[1].a0 = PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSOFF_a0);
  1367. table->BTCGB_VDROOP_TABLE[1].a1 = PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSOFF_a1);
  1368. table->BTCGB_VDROOP_TABLE[1].a2 = PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSOFF_a2);
  1369. table->AVFSGB_VDROOP_TABLE[0].m1 = PP_HOST_TO_SMC_UL(avfs_params.ulAVFSGB_FUSE_TABLE_CKSON_m1);
  1370. table->AVFSGB_VDROOP_TABLE[0].m2 = PP_HOST_TO_SMC_US(avfs_params.usAVFSGB_FUSE_TABLE_CKSON_m2);
  1371. table->AVFSGB_VDROOP_TABLE[0].b = PP_HOST_TO_SMC_UL(avfs_params.ulAVFSGB_FUSE_TABLE_CKSON_b);
  1372. table->AVFSGB_VDROOP_TABLE[0].m1_shift = 24;
  1373. table->AVFSGB_VDROOP_TABLE[0].m2_shift = 12;
  1374. table->AVFSGB_VDROOP_TABLE[1].m1 = PP_HOST_TO_SMC_UL(avfs_params.ulAVFSGB_FUSE_TABLE_CKSOFF_m1);
  1375. table->AVFSGB_VDROOP_TABLE[1].m2 = PP_HOST_TO_SMC_US(avfs_params.usAVFSGB_FUSE_TABLE_CKSOFF_m2);
  1376. table->AVFSGB_VDROOP_TABLE[1].b = PP_HOST_TO_SMC_UL(avfs_params.ulAVFSGB_FUSE_TABLE_CKSOFF_b);
  1377. table->AVFSGB_VDROOP_TABLE[1].m1_shift = 24;
  1378. table->AVFSGB_VDROOP_TABLE[1].m2_shift = 12;
  1379. table->MaxVoltage = PP_HOST_TO_SMC_US(avfs_params.usMaxVoltage_0_25mv);
  1380. AVFS_meanNsigma.Aconstant[0] = PP_HOST_TO_SMC_UL(avfs_params.ulAVFS_meanNsigma_Acontant0);
  1381. AVFS_meanNsigma.Aconstant[1] = PP_HOST_TO_SMC_UL(avfs_params.ulAVFS_meanNsigma_Acontant1);
  1382. AVFS_meanNsigma.Aconstant[2] = PP_HOST_TO_SMC_UL(avfs_params.ulAVFS_meanNsigma_Acontant2);
  1383. AVFS_meanNsigma.DC_tol_sigma = PP_HOST_TO_SMC_US(avfs_params.usAVFS_meanNsigma_DC_tol_sigma);
  1384. AVFS_meanNsigma.Platform_mean = PP_HOST_TO_SMC_US(avfs_params.usAVFS_meanNsigma_Platform_mean);
  1385. AVFS_meanNsigma.PSM_Age_CompFactor = PP_HOST_TO_SMC_US(avfs_params.usPSM_Age_ComFactor);
  1386. AVFS_meanNsigma.Platform_sigma = PP_HOST_TO_SMC_US(avfs_params.usAVFS_meanNsigma_Platform_sigma);
  1387. for (i = 0; i < NUM_VFT_COLUMNS; i++) {
  1388. AVFS_meanNsigma.Static_Voltage_Offset[i] = (uint8_t)(sclk_table->entries[i].cks_voffset * 100 / 625);
  1389. AVFS_SclkOffset.Sclk_Offset[i] = PP_HOST_TO_SMC_US((uint16_t)(sclk_table->entries[i].sclk_offset) / 100);
  1390. }
  1391. result = smu7_read_smc_sram_dword(hwmgr,
  1392. SMU7_FIRMWARE_HEADER_LOCATION + offsetof(SMU74_Firmware_Header, AvfsMeanNSigma),
  1393. &tmp, SMC_RAM_END);
  1394. smu7_copy_bytes_to_smc(hwmgr,
  1395. tmp,
  1396. (uint8_t *)&AVFS_meanNsigma,
  1397. sizeof(AVFS_meanNsigma_t),
  1398. SMC_RAM_END);
  1399. result = smu7_read_smc_sram_dword(hwmgr,
  1400. SMU7_FIRMWARE_HEADER_LOCATION + offsetof(SMU74_Firmware_Header, AvfsSclkOffsetTable),
  1401. &tmp, SMC_RAM_END);
  1402. smu7_copy_bytes_to_smc(hwmgr,
  1403. tmp,
  1404. (uint8_t *)&AVFS_SclkOffset,
  1405. sizeof(AVFS_Sclk_Offset_t),
  1406. SMC_RAM_END);
  1407. data->avfs_vdroop_override_setting = (avfs_params.ucEnableGB_VDROOP_TABLE_CKSON << BTCGB0_Vdroop_Enable_SHIFT) |
  1408. (avfs_params.ucEnableGB_VDROOP_TABLE_CKSOFF << BTCGB1_Vdroop_Enable_SHIFT) |
  1409. (avfs_params.ucEnableGB_FUSE_TABLE_CKSON << AVFSGB0_Vdroop_Enable_SHIFT) |
  1410. (avfs_params.ucEnableGB_FUSE_TABLE_CKSOFF << AVFSGB1_Vdroop_Enable_SHIFT);
  1411. data->apply_avfs_cks_off_voltage = (avfs_params.ucEnableApplyAVFS_CKS_OFF_Voltage == 1) ? true : false;
  1412. }
  1413. return result;
  1414. }
  1415. static int polaris10_init_arb_table_index(struct pp_hwmgr *hwmgr)
  1416. {
  1417. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  1418. uint32_t tmp;
  1419. int result;
  1420. /* This is a read-modify-write on the first byte of the ARB table.
  1421. * The first byte in the SMU73_Discrete_MCArbDramTimingTable structure
  1422. * is the field 'current'.
  1423. * This solution is ugly, but we never write the whole table only
  1424. * individual fields in it.
  1425. * In reality this field should not be in that structure
  1426. * but in a soft register.
  1427. */
  1428. result = smu7_read_smc_sram_dword(hwmgr,
  1429. smu_data->smu7_data.arb_table_start, &tmp, SMC_RAM_END);
  1430. if (result)
  1431. return result;
  1432. tmp &= 0x00FFFFFF;
  1433. tmp |= ((uint32_t)MC_CG_ARB_FREQ_F1) << 24;
  1434. return smu7_write_smc_sram_dword(hwmgr,
  1435. smu_data->smu7_data.arb_table_start, tmp, SMC_RAM_END);
  1436. }
  1437. static void polaris10_initialize_power_tune_defaults(struct pp_hwmgr *hwmgr)
  1438. {
  1439. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  1440. struct phm_ppt_v1_information *table_info =
  1441. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1442. if (table_info &&
  1443. table_info->cac_dtp_table->usPowerTuneDataSetID <= POWERTUNE_DEFAULT_SET_MAX &&
  1444. table_info->cac_dtp_table->usPowerTuneDataSetID)
  1445. smu_data->power_tune_defaults =
  1446. &polaris10_power_tune_data_set_array
  1447. [table_info->cac_dtp_table->usPowerTuneDataSetID - 1];
  1448. else
  1449. smu_data->power_tune_defaults = &polaris10_power_tune_data_set_array[0];
  1450. }
  1451. static int polaris10_init_smc_table(struct pp_hwmgr *hwmgr)
  1452. {
  1453. int result;
  1454. struct smu7_hwmgr *hw_data = (struct smu7_hwmgr *)(hwmgr->backend);
  1455. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  1456. struct phm_ppt_v1_information *table_info =
  1457. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1458. struct SMU74_Discrete_DpmTable *table = &(smu_data->smc_state_table);
  1459. uint8_t i;
  1460. struct pp_atomctrl_gpio_pin_assignment gpio_pin;
  1461. pp_atomctrl_clock_dividers_vi dividers;
  1462. polaris10_initialize_power_tune_defaults(hwmgr);
  1463. if (SMU7_VOLTAGE_CONTROL_NONE != hw_data->voltage_control)
  1464. polaris10_populate_smc_voltage_tables(hwmgr, table);
  1465. table->SystemFlags = 0;
  1466. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1467. PHM_PlatformCaps_AutomaticDCTransition))
  1468. table->SystemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC;
  1469. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1470. PHM_PlatformCaps_StepVddc))
  1471. table->SystemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC;
  1472. if (hw_data->is_memory_gddr5)
  1473. table->SystemFlags |= PPSMC_SYSTEMFLAG_GDDR5;
  1474. if (hw_data->ulv_supported && table_info->us_ulv_voltage_offset) {
  1475. result = polaris10_populate_ulv_state(hwmgr, table);
  1476. PP_ASSERT_WITH_CODE(0 == result,
  1477. "Failed to initialize ULV state!", return result);
  1478. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  1479. ixCG_ULV_PARAMETER, SMU7_CGULVPARAMETER_DFLT);
  1480. }
  1481. result = polaris10_populate_smc_link_level(hwmgr, table);
  1482. PP_ASSERT_WITH_CODE(0 == result,
  1483. "Failed to initialize Link Level!", return result);
  1484. result = polaris10_populate_all_graphic_levels(hwmgr);
  1485. PP_ASSERT_WITH_CODE(0 == result,
  1486. "Failed to initialize Graphics Level!", return result);
  1487. result = polaris10_populate_all_memory_levels(hwmgr);
  1488. PP_ASSERT_WITH_CODE(0 == result,
  1489. "Failed to initialize Memory Level!", return result);
  1490. result = polaris10_populate_smc_acpi_level(hwmgr, table);
  1491. PP_ASSERT_WITH_CODE(0 == result,
  1492. "Failed to initialize ACPI Level!", return result);
  1493. result = polaris10_populate_smc_vce_level(hwmgr, table);
  1494. PP_ASSERT_WITH_CODE(0 == result,
  1495. "Failed to initialize VCE Level!", return result);
  1496. /* Since only the initial state is completely set up at this point
  1497. * (the other states are just copies of the boot state) we only
  1498. * need to populate the ARB settings for the initial state.
  1499. */
  1500. result = polaris10_program_memory_timing_parameters(hwmgr);
  1501. PP_ASSERT_WITH_CODE(0 == result,
  1502. "Failed to Write ARB settings for the initial state.", return result);
  1503. result = polaris10_populate_smc_uvd_level(hwmgr, table);
  1504. PP_ASSERT_WITH_CODE(0 == result,
  1505. "Failed to initialize UVD Level!", return result);
  1506. result = polaris10_populate_smc_boot_level(hwmgr, table);
  1507. PP_ASSERT_WITH_CODE(0 == result,
  1508. "Failed to initialize Boot Level!", return result);
  1509. result = polaris10_populate_smc_initailial_state(hwmgr);
  1510. PP_ASSERT_WITH_CODE(0 == result,
  1511. "Failed to initialize Boot State!", return result);
  1512. result = polaris10_populate_bapm_parameters_in_dpm_table(hwmgr);
  1513. PP_ASSERT_WITH_CODE(0 == result,
  1514. "Failed to populate BAPM Parameters!", return result);
  1515. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1516. PHM_PlatformCaps_ClockStretcher)) {
  1517. result = polaris10_populate_clock_stretcher_data_table(hwmgr);
  1518. PP_ASSERT_WITH_CODE(0 == result,
  1519. "Failed to populate Clock Stretcher Data Table!",
  1520. return result);
  1521. }
  1522. result = polaris10_populate_avfs_parameters(hwmgr);
  1523. PP_ASSERT_WITH_CODE(0 == result, "Failed to populate AVFS Parameters!", return result;);
  1524. table->CurrSclkPllRange = 0xff;
  1525. table->GraphicsVoltageChangeEnable = 1;
  1526. table->GraphicsThermThrottleEnable = 1;
  1527. table->GraphicsInterval = 1;
  1528. table->VoltageInterval = 1;
  1529. table->ThermalInterval = 1;
  1530. table->TemperatureLimitHigh =
  1531. table_info->cac_dtp_table->usTargetOperatingTemp *
  1532. SMU7_Q88_FORMAT_CONVERSION_UNIT;
  1533. table->TemperatureLimitLow =
  1534. (table_info->cac_dtp_table->usTargetOperatingTemp - 1) *
  1535. SMU7_Q88_FORMAT_CONVERSION_UNIT;
  1536. table->MemoryVoltageChangeEnable = 1;
  1537. table->MemoryInterval = 1;
  1538. table->VoltageResponseTime = 0;
  1539. table->PhaseResponseTime = 0;
  1540. table->MemoryThermThrottleEnable = 1;
  1541. table->PCIeBootLinkLevel = 0;
  1542. table->PCIeGenInterval = 1;
  1543. table->VRConfig = 0;
  1544. result = polaris10_populate_vr_config(hwmgr, table);
  1545. PP_ASSERT_WITH_CODE(0 == result,
  1546. "Failed to populate VRConfig setting!", return result);
  1547. hw_data->vr_config = table->VRConfig;
  1548. table->ThermGpio = 17;
  1549. table->SclkStepSize = 0x4000;
  1550. if (atomctrl_get_pp_assign_pin(hwmgr, VDDC_VRHOT_GPIO_PINID, &gpio_pin)) {
  1551. table->VRHotGpio = gpio_pin.uc_gpio_pin_bit_shift;
  1552. } else {
  1553. table->VRHotGpio = SMU7_UNUSED_GPIO_PIN;
  1554. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  1555. PHM_PlatformCaps_RegulatorHot);
  1556. }
  1557. if (atomctrl_get_pp_assign_pin(hwmgr, PP_AC_DC_SWITCH_GPIO_PINID,
  1558. &gpio_pin)) {
  1559. table->AcDcGpio = gpio_pin.uc_gpio_pin_bit_shift;
  1560. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  1561. PHM_PlatformCaps_AutomaticDCTransition);
  1562. } else {
  1563. table->AcDcGpio = SMU7_UNUSED_GPIO_PIN;
  1564. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  1565. PHM_PlatformCaps_AutomaticDCTransition);
  1566. }
  1567. /* Thermal Output GPIO */
  1568. if (atomctrl_get_pp_assign_pin(hwmgr, THERMAL_INT_OUTPUT_GPIO_PINID,
  1569. &gpio_pin)) {
  1570. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  1571. PHM_PlatformCaps_ThermalOutGPIO);
  1572. table->ThermOutGpio = gpio_pin.uc_gpio_pin_bit_shift;
  1573. /* For porlarity read GPIOPAD_A with assigned Gpio pin
  1574. * since VBIOS will program this register to set 'inactive state',
  1575. * driver can then determine 'active state' from this and
  1576. * program SMU with correct polarity
  1577. */
  1578. table->ThermOutPolarity = (0 == (cgs_read_register(hwmgr->device, mmGPIOPAD_A)
  1579. & (1 << gpio_pin.uc_gpio_pin_bit_shift))) ? 1:0;
  1580. table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_ONLY;
  1581. /* if required, combine VRHot/PCC with thermal out GPIO */
  1582. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_RegulatorHot)
  1583. && phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_CombinePCCWithThermalSignal))
  1584. table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_VRHOT;
  1585. } else {
  1586. table->ThermOutGpio = 17;
  1587. table->ThermOutPolarity = 1;
  1588. table->ThermOutMode = SMU7_THERM_OUT_MODE_DISABLE;
  1589. }
  1590. /* Populate BIF_SCLK levels into SMC DPM table */
  1591. for (i = 0; i <= hw_data->dpm_table.pcie_speed_table.count; i++) {
  1592. result = atomctrl_get_dfs_pll_dividers_vi(hwmgr, smu_data->bif_sclk_table[i], &dividers);
  1593. PP_ASSERT_WITH_CODE((result == 0), "Can not find DFS divide id for Sclk", return result);
  1594. if (i == 0)
  1595. table->Ulv.BifSclkDfs = PP_HOST_TO_SMC_US((USHORT)(dividers.pll_post_divider));
  1596. else
  1597. table->LinkLevel[i-1].BifSclkDfs = PP_HOST_TO_SMC_US((USHORT)(dividers.pll_post_divider));
  1598. }
  1599. for (i = 0; i < SMU74_MAX_ENTRIES_SMIO; i++)
  1600. table->Smio[i] = PP_HOST_TO_SMC_UL(table->Smio[i]);
  1601. CONVERT_FROM_HOST_TO_SMC_UL(table->SystemFlags);
  1602. CONVERT_FROM_HOST_TO_SMC_UL(table->VRConfig);
  1603. CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask1);
  1604. CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask2);
  1605. CONVERT_FROM_HOST_TO_SMC_UL(table->SclkStepSize);
  1606. CONVERT_FROM_HOST_TO_SMC_UL(table->CurrSclkPllRange);
  1607. CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitHigh);
  1608. CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitLow);
  1609. CONVERT_FROM_HOST_TO_SMC_US(table->VoltageResponseTime);
  1610. CONVERT_FROM_HOST_TO_SMC_US(table->PhaseResponseTime);
  1611. /* Upload all dpm data to SMC memory.(dpm level, dpm level count etc) */
  1612. result = smu7_copy_bytes_to_smc(hwmgr,
  1613. smu_data->smu7_data.dpm_table_start +
  1614. offsetof(SMU74_Discrete_DpmTable, SystemFlags),
  1615. (uint8_t *)&(table->SystemFlags),
  1616. sizeof(SMU74_Discrete_DpmTable) - 3 * sizeof(SMU74_PIDController),
  1617. SMC_RAM_END);
  1618. PP_ASSERT_WITH_CODE(0 == result,
  1619. "Failed to upload dpm data to SMC memory!", return result);
  1620. result = polaris10_init_arb_table_index(hwmgr);
  1621. PP_ASSERT_WITH_CODE(0 == result,
  1622. "Failed to upload arb data to SMC memory!", return result);
  1623. result = polaris10_populate_pm_fuses(hwmgr);
  1624. PP_ASSERT_WITH_CODE(0 == result,
  1625. "Failed to populate PM fuses to SMC memory!", return result);
  1626. return 0;
  1627. }
  1628. static int polaris10_program_mem_timing_parameters(struct pp_hwmgr *hwmgr)
  1629. {
  1630. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1631. if (data->need_update_smu7_dpm_table &
  1632. (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_OD_UPDATE_MCLK))
  1633. return polaris10_program_memory_timing_parameters(hwmgr);
  1634. return 0;
  1635. }
  1636. int polaris10_thermal_avfs_enable(struct pp_hwmgr *hwmgr)
  1637. {
  1638. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1639. if (!hwmgr->avfs_supported)
  1640. return 0;
  1641. smum_send_msg_to_smc_with_parameter(hwmgr,
  1642. PPSMC_MSG_SetGBDroopSettings, data->avfs_vdroop_override_setting);
  1643. smum_send_msg_to_smc(hwmgr, PPSMC_MSG_EnableAvfs);
  1644. /* Apply avfs cks-off voltages to avoid the overshoot
  1645. * when switching to the highest sclk frequency
  1646. */
  1647. if (data->apply_avfs_cks_off_voltage)
  1648. smum_send_msg_to_smc(hwmgr, PPSMC_MSG_ApplyAvfsCksOffVoltage);
  1649. return 0;
  1650. }
  1651. static int polaris10_thermal_setup_fan_table(struct pp_hwmgr *hwmgr)
  1652. {
  1653. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  1654. SMU74_Discrete_FanTable fan_table = { FDO_MODE_HARDWARE };
  1655. uint32_t duty100;
  1656. uint32_t t_diff1, t_diff2, pwm_diff1, pwm_diff2;
  1657. uint16_t fdo_min, slope1, slope2;
  1658. uint32_t reference_clock;
  1659. int res;
  1660. uint64_t tmp64;
  1661. if (hwmgr->thermal_controller.fanInfo.bNoFan) {
  1662. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  1663. PHM_PlatformCaps_MicrocodeFanControl);
  1664. return 0;
  1665. }
  1666. if (smu_data->smu7_data.fan_table_start == 0) {
  1667. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  1668. PHM_PlatformCaps_MicrocodeFanControl);
  1669. return 0;
  1670. }
  1671. duty100 = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  1672. CG_FDO_CTRL1, FMAX_DUTY100);
  1673. if (duty100 == 0) {
  1674. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  1675. PHM_PlatformCaps_MicrocodeFanControl);
  1676. return 0;
  1677. }
  1678. /* use hardware fan control */
  1679. if (hwmgr->thermal_controller.use_hw_fan_control)
  1680. return 0;
  1681. tmp64 = hwmgr->thermal_controller.advanceFanControlParameters.
  1682. usPWMMin * duty100;
  1683. do_div(tmp64, 10000);
  1684. fdo_min = (uint16_t)tmp64;
  1685. t_diff1 = hwmgr->thermal_controller.advanceFanControlParameters.usTMed -
  1686. hwmgr->thermal_controller.advanceFanControlParameters.usTMin;
  1687. t_diff2 = hwmgr->thermal_controller.advanceFanControlParameters.usTHigh -
  1688. hwmgr->thermal_controller.advanceFanControlParameters.usTMed;
  1689. pwm_diff1 = hwmgr->thermal_controller.advanceFanControlParameters.usPWMMed -
  1690. hwmgr->thermal_controller.advanceFanControlParameters.usPWMMin;
  1691. pwm_diff2 = hwmgr->thermal_controller.advanceFanControlParameters.usPWMHigh -
  1692. hwmgr->thermal_controller.advanceFanControlParameters.usPWMMed;
  1693. slope1 = (uint16_t)((50 + ((16 * duty100 * pwm_diff1) / t_diff1)) / 100);
  1694. slope2 = (uint16_t)((50 + ((16 * duty100 * pwm_diff2) / t_diff2)) / 100);
  1695. fan_table.TempMin = cpu_to_be16((50 + hwmgr->
  1696. thermal_controller.advanceFanControlParameters.usTMin) / 100);
  1697. fan_table.TempMed = cpu_to_be16((50 + hwmgr->
  1698. thermal_controller.advanceFanControlParameters.usTMed) / 100);
  1699. fan_table.TempMax = cpu_to_be16((50 + hwmgr->
  1700. thermal_controller.advanceFanControlParameters.usTMax) / 100);
  1701. fan_table.Slope1 = cpu_to_be16(slope1);
  1702. fan_table.Slope2 = cpu_to_be16(slope2);
  1703. fan_table.FdoMin = cpu_to_be16(fdo_min);
  1704. fan_table.HystDown = cpu_to_be16(hwmgr->
  1705. thermal_controller.advanceFanControlParameters.ucTHyst);
  1706. fan_table.HystUp = cpu_to_be16(1);
  1707. fan_table.HystSlope = cpu_to_be16(1);
  1708. fan_table.TempRespLim = cpu_to_be16(5);
  1709. reference_clock = amdgpu_asic_get_xclk((struct amdgpu_device *)hwmgr->adev);
  1710. fan_table.RefreshPeriod = cpu_to_be32((hwmgr->
  1711. thermal_controller.advanceFanControlParameters.ulCycleDelay *
  1712. reference_clock) / 1600);
  1713. fan_table.FdoMax = cpu_to_be16((uint16_t)duty100);
  1714. fan_table.TempSrc = (uint8_t)PHM_READ_VFPF_INDIRECT_FIELD(
  1715. hwmgr->device, CGS_IND_REG__SMC,
  1716. CG_MULT_THERMAL_CTRL, TEMP_SEL);
  1717. res = smu7_copy_bytes_to_smc(hwmgr, smu_data->smu7_data.fan_table_start,
  1718. (uint8_t *)&fan_table, (uint32_t)sizeof(fan_table),
  1719. SMC_RAM_END);
  1720. if (!res && hwmgr->thermal_controller.
  1721. advanceFanControlParameters.ucMinimumPWMLimit)
  1722. res = smum_send_msg_to_smc_with_parameter(hwmgr,
  1723. PPSMC_MSG_SetFanMinPwm,
  1724. hwmgr->thermal_controller.
  1725. advanceFanControlParameters.ucMinimumPWMLimit);
  1726. if (!res && hwmgr->thermal_controller.
  1727. advanceFanControlParameters.ulMinFanSCLKAcousticLimit)
  1728. res = smum_send_msg_to_smc_with_parameter(hwmgr,
  1729. PPSMC_MSG_SetFanSclkTarget,
  1730. hwmgr->thermal_controller.
  1731. advanceFanControlParameters.ulMinFanSCLKAcousticLimit);
  1732. if (res)
  1733. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  1734. PHM_PlatformCaps_MicrocodeFanControl);
  1735. return 0;
  1736. }
  1737. static int polaris10_update_uvd_smc_table(struct pp_hwmgr *hwmgr)
  1738. {
  1739. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  1740. uint32_t mm_boot_level_offset, mm_boot_level_value;
  1741. struct phm_ppt_v1_information *table_info =
  1742. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1743. smu_data->smc_state_table.UvdBootLevel = 0;
  1744. if (table_info->mm_dep_table->count > 0)
  1745. smu_data->smc_state_table.UvdBootLevel =
  1746. (uint8_t) (table_info->mm_dep_table->count - 1);
  1747. mm_boot_level_offset = smu_data->smu7_data.dpm_table_start + offsetof(SMU74_Discrete_DpmTable,
  1748. UvdBootLevel);
  1749. mm_boot_level_offset /= 4;
  1750. mm_boot_level_offset *= 4;
  1751. mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
  1752. CGS_IND_REG__SMC, mm_boot_level_offset);
  1753. mm_boot_level_value &= 0x00FFFFFF;
  1754. mm_boot_level_value |= smu_data->smc_state_table.UvdBootLevel << 24;
  1755. cgs_write_ind_register(hwmgr->device,
  1756. CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
  1757. if (!phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1758. PHM_PlatformCaps_UVDDPM) ||
  1759. phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1760. PHM_PlatformCaps_StablePState))
  1761. smum_send_msg_to_smc_with_parameter(hwmgr,
  1762. PPSMC_MSG_UVDDPM_SetEnabledMask,
  1763. (uint32_t)(1 << smu_data->smc_state_table.UvdBootLevel));
  1764. return 0;
  1765. }
  1766. static int polaris10_update_vce_smc_table(struct pp_hwmgr *hwmgr)
  1767. {
  1768. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  1769. uint32_t mm_boot_level_offset, mm_boot_level_value;
  1770. struct phm_ppt_v1_information *table_info =
  1771. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1772. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1773. PHM_PlatformCaps_StablePState))
  1774. smu_data->smc_state_table.VceBootLevel =
  1775. (uint8_t) (table_info->mm_dep_table->count - 1);
  1776. else
  1777. smu_data->smc_state_table.VceBootLevel = 0;
  1778. mm_boot_level_offset = smu_data->smu7_data.dpm_table_start +
  1779. offsetof(SMU74_Discrete_DpmTable, VceBootLevel);
  1780. mm_boot_level_offset /= 4;
  1781. mm_boot_level_offset *= 4;
  1782. mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
  1783. CGS_IND_REG__SMC, mm_boot_level_offset);
  1784. mm_boot_level_value &= 0xFF00FFFF;
  1785. mm_boot_level_value |= smu_data->smc_state_table.VceBootLevel << 16;
  1786. cgs_write_ind_register(hwmgr->device,
  1787. CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
  1788. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_StablePState))
  1789. smum_send_msg_to_smc_with_parameter(hwmgr,
  1790. PPSMC_MSG_VCEDPM_SetEnabledMask,
  1791. (uint32_t)1 << smu_data->smc_state_table.VceBootLevel);
  1792. return 0;
  1793. }
  1794. static int polaris10_update_bif_smc_table(struct pp_hwmgr *hwmgr)
  1795. {
  1796. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  1797. struct phm_ppt_v1_information *table_info =
  1798. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1799. struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table;
  1800. int max_entry, i;
  1801. max_entry = (SMU74_MAX_LEVELS_LINK < pcie_table->count) ?
  1802. SMU74_MAX_LEVELS_LINK :
  1803. pcie_table->count;
  1804. /* Setup BIF_SCLK levels */
  1805. for (i = 0; i < max_entry; i++)
  1806. smu_data->bif_sclk_table[i] = pcie_table->entries[i].pcie_sclk;
  1807. return 0;
  1808. }
  1809. static int polaris10_update_smc_table(struct pp_hwmgr *hwmgr, uint32_t type)
  1810. {
  1811. switch (type) {
  1812. case SMU_UVD_TABLE:
  1813. polaris10_update_uvd_smc_table(hwmgr);
  1814. break;
  1815. case SMU_VCE_TABLE:
  1816. polaris10_update_vce_smc_table(hwmgr);
  1817. break;
  1818. case SMU_BIF_TABLE:
  1819. polaris10_update_bif_smc_table(hwmgr);
  1820. default:
  1821. break;
  1822. }
  1823. return 0;
  1824. }
  1825. static int polaris10_update_sclk_threshold(struct pp_hwmgr *hwmgr)
  1826. {
  1827. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1828. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  1829. int result = 0;
  1830. uint32_t low_sclk_interrupt_threshold = 0;
  1831. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1832. PHM_PlatformCaps_SclkThrottleLowNotification)
  1833. && (data->low_sclk_interrupt_threshold != 0)) {
  1834. low_sclk_interrupt_threshold =
  1835. data->low_sclk_interrupt_threshold;
  1836. CONVERT_FROM_HOST_TO_SMC_UL(low_sclk_interrupt_threshold);
  1837. result = smu7_copy_bytes_to_smc(
  1838. hwmgr,
  1839. smu_data->smu7_data.dpm_table_start +
  1840. offsetof(SMU74_Discrete_DpmTable,
  1841. LowSclkInterruptThreshold),
  1842. (uint8_t *)&low_sclk_interrupt_threshold,
  1843. sizeof(uint32_t),
  1844. SMC_RAM_END);
  1845. }
  1846. PP_ASSERT_WITH_CODE((result == 0),
  1847. "Failed to update SCLK threshold!", return result);
  1848. result = polaris10_program_mem_timing_parameters(hwmgr);
  1849. PP_ASSERT_WITH_CODE((result == 0),
  1850. "Failed to program memory timing parameters!",
  1851. );
  1852. return result;
  1853. }
  1854. static uint32_t polaris10_get_offsetof(uint32_t type, uint32_t member)
  1855. {
  1856. switch (type) {
  1857. case SMU_SoftRegisters:
  1858. switch (member) {
  1859. case HandshakeDisables:
  1860. return offsetof(SMU74_SoftRegisters, HandshakeDisables);
  1861. case VoltageChangeTimeout:
  1862. return offsetof(SMU74_SoftRegisters, VoltageChangeTimeout);
  1863. case AverageGraphicsActivity:
  1864. return offsetof(SMU74_SoftRegisters, AverageGraphicsActivity);
  1865. case PreVBlankGap:
  1866. return offsetof(SMU74_SoftRegisters, PreVBlankGap);
  1867. case VBlankTimeout:
  1868. return offsetof(SMU74_SoftRegisters, VBlankTimeout);
  1869. case UcodeLoadStatus:
  1870. return offsetof(SMU74_SoftRegisters, UcodeLoadStatus);
  1871. case DRAM_LOG_ADDR_H:
  1872. return offsetof(SMU74_SoftRegisters, DRAM_LOG_ADDR_H);
  1873. case DRAM_LOG_ADDR_L:
  1874. return offsetof(SMU74_SoftRegisters, DRAM_LOG_ADDR_L);
  1875. case DRAM_LOG_PHY_ADDR_H:
  1876. return offsetof(SMU74_SoftRegisters, DRAM_LOG_PHY_ADDR_H);
  1877. case DRAM_LOG_PHY_ADDR_L:
  1878. return offsetof(SMU74_SoftRegisters, DRAM_LOG_PHY_ADDR_L);
  1879. case DRAM_LOG_BUFF_SIZE:
  1880. return offsetof(SMU74_SoftRegisters, DRAM_LOG_BUFF_SIZE);
  1881. }
  1882. case SMU_Discrete_DpmTable:
  1883. switch (member) {
  1884. case UvdBootLevel:
  1885. return offsetof(SMU74_Discrete_DpmTable, UvdBootLevel);
  1886. case VceBootLevel:
  1887. return offsetof(SMU74_Discrete_DpmTable, VceBootLevel);
  1888. case LowSclkInterruptThreshold:
  1889. return offsetof(SMU74_Discrete_DpmTable, LowSclkInterruptThreshold);
  1890. }
  1891. }
  1892. pr_warn("can't get the offset of type %x member %x\n", type, member);
  1893. return 0;
  1894. }
  1895. static uint32_t polaris10_get_mac_definition(uint32_t value)
  1896. {
  1897. switch (value) {
  1898. case SMU_MAX_LEVELS_GRAPHICS:
  1899. return SMU74_MAX_LEVELS_GRAPHICS;
  1900. case SMU_MAX_LEVELS_MEMORY:
  1901. return SMU74_MAX_LEVELS_MEMORY;
  1902. case SMU_MAX_LEVELS_LINK:
  1903. return SMU74_MAX_LEVELS_LINK;
  1904. case SMU_MAX_ENTRIES_SMIO:
  1905. return SMU74_MAX_ENTRIES_SMIO;
  1906. case SMU_MAX_LEVELS_VDDC:
  1907. return SMU74_MAX_LEVELS_VDDC;
  1908. case SMU_MAX_LEVELS_VDDGFX:
  1909. return SMU74_MAX_LEVELS_VDDGFX;
  1910. case SMU_MAX_LEVELS_VDDCI:
  1911. return SMU74_MAX_LEVELS_VDDCI;
  1912. case SMU_MAX_LEVELS_MVDD:
  1913. return SMU74_MAX_LEVELS_MVDD;
  1914. case SMU_UVD_MCLK_HANDSHAKE_DISABLE:
  1915. return SMU7_UVD_MCLK_HANDSHAKE_DISABLE;
  1916. }
  1917. pr_warn("can't get the mac of %x\n", value);
  1918. return 0;
  1919. }
  1920. static int polaris10_process_firmware_header(struct pp_hwmgr *hwmgr)
  1921. {
  1922. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
  1923. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1924. uint32_t tmp;
  1925. int result;
  1926. bool error = false;
  1927. result = smu7_read_smc_sram_dword(hwmgr,
  1928. SMU7_FIRMWARE_HEADER_LOCATION +
  1929. offsetof(SMU74_Firmware_Header, DpmTable),
  1930. &tmp, SMC_RAM_END);
  1931. if (0 == result)
  1932. smu_data->smu7_data.dpm_table_start = tmp;
  1933. error |= (0 != result);
  1934. result = smu7_read_smc_sram_dword(hwmgr,
  1935. SMU7_FIRMWARE_HEADER_LOCATION +
  1936. offsetof(SMU74_Firmware_Header, SoftRegisters),
  1937. &tmp, SMC_RAM_END);
  1938. if (!result) {
  1939. data->soft_regs_start = tmp;
  1940. smu_data->smu7_data.soft_regs_start = tmp;
  1941. }
  1942. error |= (0 != result);
  1943. result = smu7_read_smc_sram_dword(hwmgr,
  1944. SMU7_FIRMWARE_HEADER_LOCATION +
  1945. offsetof(SMU74_Firmware_Header, mcRegisterTable),
  1946. &tmp, SMC_RAM_END);
  1947. if (!result)
  1948. smu_data->smu7_data.mc_reg_table_start = tmp;
  1949. result = smu7_read_smc_sram_dword(hwmgr,
  1950. SMU7_FIRMWARE_HEADER_LOCATION +
  1951. offsetof(SMU74_Firmware_Header, FanTable),
  1952. &tmp, SMC_RAM_END);
  1953. if (!result)
  1954. smu_data->smu7_data.fan_table_start = tmp;
  1955. error |= (0 != result);
  1956. result = smu7_read_smc_sram_dword(hwmgr,
  1957. SMU7_FIRMWARE_HEADER_LOCATION +
  1958. offsetof(SMU74_Firmware_Header, mcArbDramTimingTable),
  1959. &tmp, SMC_RAM_END);
  1960. if (!result)
  1961. smu_data->smu7_data.arb_table_start = tmp;
  1962. error |= (0 != result);
  1963. result = smu7_read_smc_sram_dword(hwmgr,
  1964. SMU7_FIRMWARE_HEADER_LOCATION +
  1965. offsetof(SMU74_Firmware_Header, Version),
  1966. &tmp, SMC_RAM_END);
  1967. if (!result)
  1968. hwmgr->microcode_version_info.SMC = tmp;
  1969. error |= (0 != result);
  1970. return error ? -1 : 0;
  1971. }
  1972. static bool polaris10_is_dpm_running(struct pp_hwmgr *hwmgr)
  1973. {
  1974. return (1 == PHM_READ_INDIRECT_FIELD(hwmgr->device,
  1975. CGS_IND_REG__SMC, FEATURE_STATUS, VOLTAGE_CONTROLLER_ON))
  1976. ? true : false;
  1977. }
  1978. static int polaris10_update_dpm_settings(struct pp_hwmgr *hwmgr,
  1979. void *profile_setting)
  1980. {
  1981. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1982. struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)
  1983. (hwmgr->smu_backend);
  1984. struct profile_mode_setting *setting;
  1985. struct SMU74_Discrete_GraphicsLevel *levels =
  1986. smu_data->smc_state_table.GraphicsLevel;
  1987. uint32_t array = smu_data->smu7_data.dpm_table_start +
  1988. offsetof(SMU74_Discrete_DpmTable, GraphicsLevel);
  1989. uint32_t mclk_array = smu_data->smu7_data.dpm_table_start +
  1990. offsetof(SMU74_Discrete_DpmTable, MemoryLevel);
  1991. struct SMU74_Discrete_MemoryLevel *mclk_levels =
  1992. smu_data->smc_state_table.MemoryLevel;
  1993. uint32_t i;
  1994. uint32_t offset, up_hyst_offset, down_hyst_offset, clk_activity_offset, tmp;
  1995. if (profile_setting == NULL)
  1996. return -EINVAL;
  1997. setting = (struct profile_mode_setting *)profile_setting;
  1998. if (setting->bupdate_sclk) {
  1999. if (!data->sclk_dpm_key_disabled)
  2000. smum_send_msg_to_smc(hwmgr, PPSMC_MSG_SCLKDPM_FreezeLevel);
  2001. for (i = 0; i < smu_data->smc_state_table.GraphicsDpmLevelCount; i++) {
  2002. if (levels[i].ActivityLevel !=
  2003. cpu_to_be16(setting->sclk_activity)) {
  2004. levels[i].ActivityLevel = cpu_to_be16(setting->sclk_activity);
  2005. clk_activity_offset = array + (sizeof(SMU74_Discrete_GraphicsLevel) * i)
  2006. + offsetof(SMU74_Discrete_GraphicsLevel, ActivityLevel);
  2007. offset = clk_activity_offset & ~0x3;
  2008. tmp = PP_HOST_TO_SMC_UL(cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, offset));
  2009. tmp = phm_set_field_to_u32(clk_activity_offset, tmp, levels[i].ActivityLevel, sizeof(uint16_t));
  2010. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, offset, PP_HOST_TO_SMC_UL(tmp));
  2011. }
  2012. if (levels[i].UpHyst != setting->sclk_up_hyst ||
  2013. levels[i].DownHyst != setting->sclk_down_hyst) {
  2014. levels[i].UpHyst = setting->sclk_up_hyst;
  2015. levels[i].DownHyst = setting->sclk_down_hyst;
  2016. up_hyst_offset = array + (sizeof(SMU74_Discrete_GraphicsLevel) * i)
  2017. + offsetof(SMU74_Discrete_GraphicsLevel, UpHyst);
  2018. down_hyst_offset = array + (sizeof(SMU74_Discrete_GraphicsLevel) * i)
  2019. + offsetof(SMU74_Discrete_GraphicsLevel, DownHyst);
  2020. offset = up_hyst_offset & ~0x3;
  2021. tmp = PP_HOST_TO_SMC_UL(cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, offset));
  2022. tmp = phm_set_field_to_u32(up_hyst_offset, tmp, levels[i].UpHyst, sizeof(uint8_t));
  2023. tmp = phm_set_field_to_u32(down_hyst_offset, tmp, levels[i].DownHyst, sizeof(uint8_t));
  2024. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, offset, PP_HOST_TO_SMC_UL(tmp));
  2025. }
  2026. }
  2027. if (!data->sclk_dpm_key_disabled)
  2028. smum_send_msg_to_smc(hwmgr, PPSMC_MSG_SCLKDPM_UnfreezeLevel);
  2029. }
  2030. if (setting->bupdate_mclk) {
  2031. if (!data->mclk_dpm_key_disabled)
  2032. smum_send_msg_to_smc(hwmgr, PPSMC_MSG_MCLKDPM_FreezeLevel);
  2033. for (i = 0; i < smu_data->smc_state_table.MemoryDpmLevelCount; i++) {
  2034. if (mclk_levels[i].ActivityLevel !=
  2035. cpu_to_be16(setting->mclk_activity)) {
  2036. mclk_levels[i].ActivityLevel = cpu_to_be16(setting->mclk_activity);
  2037. clk_activity_offset = mclk_array + (sizeof(SMU74_Discrete_MemoryLevel) * i)
  2038. + offsetof(SMU74_Discrete_MemoryLevel, ActivityLevel);
  2039. offset = clk_activity_offset & ~0x3;
  2040. tmp = PP_HOST_TO_SMC_UL(cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, offset));
  2041. tmp = phm_set_field_to_u32(clk_activity_offset, tmp, mclk_levels[i].ActivityLevel, sizeof(uint16_t));
  2042. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, offset, PP_HOST_TO_SMC_UL(tmp));
  2043. }
  2044. if (mclk_levels[i].UpHyst != setting->mclk_up_hyst ||
  2045. mclk_levels[i].DownHyst != setting->mclk_down_hyst) {
  2046. mclk_levels[i].UpHyst = setting->mclk_up_hyst;
  2047. mclk_levels[i].DownHyst = setting->mclk_down_hyst;
  2048. up_hyst_offset = mclk_array + (sizeof(SMU74_Discrete_MemoryLevel) * i)
  2049. + offsetof(SMU74_Discrete_MemoryLevel, UpHyst);
  2050. down_hyst_offset = mclk_array + (sizeof(SMU74_Discrete_MemoryLevel) * i)
  2051. + offsetof(SMU74_Discrete_MemoryLevel, DownHyst);
  2052. offset = up_hyst_offset & ~0x3;
  2053. tmp = PP_HOST_TO_SMC_UL(cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, offset));
  2054. tmp = phm_set_field_to_u32(up_hyst_offset, tmp, mclk_levels[i].UpHyst, sizeof(uint8_t));
  2055. tmp = phm_set_field_to_u32(down_hyst_offset, tmp, mclk_levels[i].DownHyst, sizeof(uint8_t));
  2056. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, offset, PP_HOST_TO_SMC_UL(tmp));
  2057. }
  2058. }
  2059. if (!data->mclk_dpm_key_disabled)
  2060. smum_send_msg_to_smc(hwmgr, PPSMC_MSG_MCLKDPM_UnfreezeLevel);
  2061. }
  2062. return 0;
  2063. }
  2064. const struct pp_smumgr_func polaris10_smu_funcs = {
  2065. .smu_init = polaris10_smu_init,
  2066. .smu_fini = smu7_smu_fini,
  2067. .start_smu = polaris10_start_smu,
  2068. .check_fw_load_finish = smu7_check_fw_load_finish,
  2069. .request_smu_load_fw = smu7_reload_firmware,
  2070. .request_smu_load_specific_fw = NULL,
  2071. .send_msg_to_smc = smu7_send_msg_to_smc,
  2072. .send_msg_to_smc_with_parameter = smu7_send_msg_to_smc_with_parameter,
  2073. .download_pptable_settings = NULL,
  2074. .upload_pptable_settings = NULL,
  2075. .update_smc_table = polaris10_update_smc_table,
  2076. .get_offsetof = polaris10_get_offsetof,
  2077. .process_firmware_header = polaris10_process_firmware_header,
  2078. .init_smc_table = polaris10_init_smc_table,
  2079. .update_sclk_threshold = polaris10_update_sclk_threshold,
  2080. .thermal_avfs_enable = polaris10_thermal_avfs_enable,
  2081. .thermal_setup_fan_table = polaris10_thermal_setup_fan_table,
  2082. .populate_all_graphic_levels = polaris10_populate_all_graphic_levels,
  2083. .populate_all_memory_levels = polaris10_populate_all_memory_levels,
  2084. .get_mac_definition = polaris10_get_mac_definition,
  2085. .is_dpm_running = polaris10_is_dpm_running,
  2086. .is_hw_avfs_present = polaris10_is_hw_avfs_present,
  2087. .update_dpm_settings = polaris10_update_dpm_settings,
  2088. };