polaris10_smc.c 84 KB

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