kv_dpm.c 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898
  1. /*
  2. * Copyright 2013 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 "drmP.h"
  24. #include "radeon.h"
  25. #include "cikd.h"
  26. #include "r600_dpm.h"
  27. #include "kv_dpm.h"
  28. #include "radeon_asic.h"
  29. #include <linux/seq_file.h>
  30. #define KV_MAX_DEEPSLEEP_DIVIDER_ID 5
  31. #define KV_MINIMUM_ENGINE_CLOCK 800
  32. #define SMC_RAM_END 0x40000
  33. static int kv_enable_nb_dpm(struct radeon_device *rdev,
  34. bool enable);
  35. static void kv_init_graphics_levels(struct radeon_device *rdev);
  36. static int kv_calculate_ds_divider(struct radeon_device *rdev);
  37. static int kv_calculate_nbps_level_settings(struct radeon_device *rdev);
  38. static int kv_calculate_dpm_settings(struct radeon_device *rdev);
  39. static void kv_enable_new_levels(struct radeon_device *rdev);
  40. static void kv_program_nbps_index_settings(struct radeon_device *rdev,
  41. struct radeon_ps *new_rps);
  42. static int kv_set_enabled_level(struct radeon_device *rdev, u32 level);
  43. static int kv_set_enabled_levels(struct radeon_device *rdev);
  44. static int kv_force_dpm_highest(struct radeon_device *rdev);
  45. static int kv_force_dpm_lowest(struct radeon_device *rdev);
  46. static void kv_apply_state_adjust_rules(struct radeon_device *rdev,
  47. struct radeon_ps *new_rps,
  48. struct radeon_ps *old_rps);
  49. static int kv_set_thermal_temperature_range(struct radeon_device *rdev,
  50. int min_temp, int max_temp);
  51. static int kv_init_fps_limits(struct radeon_device *rdev);
  52. void kv_dpm_powergate_uvd(struct radeon_device *rdev, bool gate);
  53. static void kv_dpm_powergate_vce(struct radeon_device *rdev, bool gate);
  54. static void kv_dpm_powergate_samu(struct radeon_device *rdev, bool gate);
  55. static void kv_dpm_powergate_acp(struct radeon_device *rdev, bool gate);
  56. extern void cik_enter_rlc_safe_mode(struct radeon_device *rdev);
  57. extern void cik_exit_rlc_safe_mode(struct radeon_device *rdev);
  58. extern void cik_update_cg(struct radeon_device *rdev,
  59. u32 block, bool enable);
  60. static const struct kv_lcac_config_values sx_local_cac_cfg_kv[] =
  61. {
  62. { 0, 4, 1 },
  63. { 1, 4, 1 },
  64. { 2, 5, 1 },
  65. { 3, 4, 2 },
  66. { 4, 1, 1 },
  67. { 5, 5, 2 },
  68. { 6, 6, 1 },
  69. { 7, 9, 2 },
  70. { 0xffffffff }
  71. };
  72. static const struct kv_lcac_config_values mc0_local_cac_cfg_kv[] =
  73. {
  74. { 0, 4, 1 },
  75. { 0xffffffff }
  76. };
  77. static const struct kv_lcac_config_values mc1_local_cac_cfg_kv[] =
  78. {
  79. { 0, 4, 1 },
  80. { 0xffffffff }
  81. };
  82. static const struct kv_lcac_config_values mc2_local_cac_cfg_kv[] =
  83. {
  84. { 0, 4, 1 },
  85. { 0xffffffff }
  86. };
  87. static const struct kv_lcac_config_values mc3_local_cac_cfg_kv[] =
  88. {
  89. { 0, 4, 1 },
  90. { 0xffffffff }
  91. };
  92. static const struct kv_lcac_config_values cpl_local_cac_cfg_kv[] =
  93. {
  94. { 0, 4, 1 },
  95. { 1, 4, 1 },
  96. { 2, 5, 1 },
  97. { 3, 4, 1 },
  98. { 4, 1, 1 },
  99. { 5, 5, 1 },
  100. { 6, 6, 1 },
  101. { 7, 9, 1 },
  102. { 8, 4, 1 },
  103. { 9, 2, 1 },
  104. { 10, 3, 1 },
  105. { 11, 6, 1 },
  106. { 12, 8, 2 },
  107. { 13, 1, 1 },
  108. { 14, 2, 1 },
  109. { 15, 3, 1 },
  110. { 16, 1, 1 },
  111. { 17, 4, 1 },
  112. { 18, 3, 1 },
  113. { 19, 1, 1 },
  114. { 20, 8, 1 },
  115. { 21, 5, 1 },
  116. { 22, 1, 1 },
  117. { 23, 1, 1 },
  118. { 24, 4, 1 },
  119. { 27, 6, 1 },
  120. { 28, 1, 1 },
  121. { 0xffffffff }
  122. };
  123. static const struct kv_lcac_config_reg sx0_cac_config_reg[] =
  124. {
  125. { 0xc0400d00, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
  126. };
  127. static const struct kv_lcac_config_reg mc0_cac_config_reg[] =
  128. {
  129. { 0xc0400d30, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
  130. };
  131. static const struct kv_lcac_config_reg mc1_cac_config_reg[] =
  132. {
  133. { 0xc0400d3c, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
  134. };
  135. static const struct kv_lcac_config_reg mc2_cac_config_reg[] =
  136. {
  137. { 0xc0400d48, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
  138. };
  139. static const struct kv_lcac_config_reg mc3_cac_config_reg[] =
  140. {
  141. { 0xc0400d54, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
  142. };
  143. static const struct kv_lcac_config_reg cpl_cac_config_reg[] =
  144. {
  145. { 0xc0400d80, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
  146. };
  147. static const struct kv_pt_config_reg didt_config_kv[] =
  148. {
  149. { 0x10, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
  150. { 0x10, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
  151. { 0x10, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
  152. { 0x10, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
  153. { 0x11, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
  154. { 0x11, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
  155. { 0x11, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
  156. { 0x11, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
  157. { 0x12, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
  158. { 0x12, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
  159. { 0x12, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
  160. { 0x12, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
  161. { 0x2, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND },
  162. { 0x2, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND },
  163. { 0x2, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND },
  164. { 0x1, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND },
  165. { 0x1, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND },
  166. { 0x0, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND },
  167. { 0x30, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
  168. { 0x30, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
  169. { 0x30, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
  170. { 0x30, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
  171. { 0x31, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
  172. { 0x31, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
  173. { 0x31, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
  174. { 0x31, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
  175. { 0x32, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
  176. { 0x32, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
  177. { 0x32, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
  178. { 0x32, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
  179. { 0x22, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND },
  180. { 0x22, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND },
  181. { 0x22, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND },
  182. { 0x21, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND },
  183. { 0x21, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND },
  184. { 0x20, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND },
  185. { 0x50, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
  186. { 0x50, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
  187. { 0x50, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
  188. { 0x50, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
  189. { 0x51, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
  190. { 0x51, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
  191. { 0x51, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
  192. { 0x51, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
  193. { 0x52, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
  194. { 0x52, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
  195. { 0x52, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
  196. { 0x52, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
  197. { 0x42, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND },
  198. { 0x42, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND },
  199. { 0x42, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND },
  200. { 0x41, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND },
  201. { 0x41, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND },
  202. { 0x40, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND },
  203. { 0x70, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
  204. { 0x70, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
  205. { 0x70, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
  206. { 0x70, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
  207. { 0x71, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
  208. { 0x71, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
  209. { 0x71, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
  210. { 0x71, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
  211. { 0x72, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
  212. { 0x72, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
  213. { 0x72, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
  214. { 0x72, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
  215. { 0x62, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND },
  216. { 0x62, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND },
  217. { 0x62, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND },
  218. { 0x61, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND },
  219. { 0x61, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND },
  220. { 0x60, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND },
  221. { 0xFFFFFFFF }
  222. };
  223. static struct kv_ps *kv_get_ps(struct radeon_ps *rps)
  224. {
  225. struct kv_ps *ps = rps->ps_priv;
  226. return ps;
  227. }
  228. static struct kv_power_info *kv_get_pi(struct radeon_device *rdev)
  229. {
  230. struct kv_power_info *pi = rdev->pm.dpm.priv;
  231. return pi;
  232. }
  233. #if 0
  234. static void kv_program_local_cac_table(struct radeon_device *rdev,
  235. const struct kv_lcac_config_values *local_cac_table,
  236. const struct kv_lcac_config_reg *local_cac_reg)
  237. {
  238. u32 i, count, data;
  239. const struct kv_lcac_config_values *values = local_cac_table;
  240. while (values->block_id != 0xffffffff) {
  241. count = values->signal_id;
  242. for (i = 0; i < count; i++) {
  243. data = ((values->block_id << local_cac_reg->block_shift) &
  244. local_cac_reg->block_mask);
  245. data |= ((i << local_cac_reg->signal_shift) &
  246. local_cac_reg->signal_mask);
  247. data |= ((values->t << local_cac_reg->t_shift) &
  248. local_cac_reg->t_mask);
  249. data |= ((1 << local_cac_reg->enable_shift) &
  250. local_cac_reg->enable_mask);
  251. WREG32_SMC(local_cac_reg->cntl, data);
  252. }
  253. values++;
  254. }
  255. }
  256. #endif
  257. static int kv_program_pt_config_registers(struct radeon_device *rdev,
  258. const struct kv_pt_config_reg *cac_config_regs)
  259. {
  260. const struct kv_pt_config_reg *config_regs = cac_config_regs;
  261. u32 data;
  262. u32 cache = 0;
  263. if (config_regs == NULL)
  264. return -EINVAL;
  265. while (config_regs->offset != 0xFFFFFFFF) {
  266. if (config_regs->type == KV_CONFIGREG_CACHE) {
  267. cache |= ((config_regs->value << config_regs->shift) & config_regs->mask);
  268. } else {
  269. switch (config_regs->type) {
  270. case KV_CONFIGREG_SMC_IND:
  271. data = RREG32_SMC(config_regs->offset);
  272. break;
  273. case KV_CONFIGREG_DIDT_IND:
  274. data = RREG32_DIDT(config_regs->offset);
  275. break;
  276. default:
  277. data = RREG32(config_regs->offset << 2);
  278. break;
  279. }
  280. data &= ~config_regs->mask;
  281. data |= ((config_regs->value << config_regs->shift) & config_regs->mask);
  282. data |= cache;
  283. cache = 0;
  284. switch (config_regs->type) {
  285. case KV_CONFIGREG_SMC_IND:
  286. WREG32_SMC(config_regs->offset, data);
  287. break;
  288. case KV_CONFIGREG_DIDT_IND:
  289. WREG32_DIDT(config_regs->offset, data);
  290. break;
  291. default:
  292. WREG32(config_regs->offset << 2, data);
  293. break;
  294. }
  295. }
  296. config_regs++;
  297. }
  298. return 0;
  299. }
  300. static void kv_do_enable_didt(struct radeon_device *rdev, bool enable)
  301. {
  302. struct kv_power_info *pi = kv_get_pi(rdev);
  303. u32 data;
  304. if (pi->caps_sq_ramping) {
  305. data = RREG32_DIDT(DIDT_SQ_CTRL0);
  306. if (enable)
  307. data |= DIDT_CTRL_EN;
  308. else
  309. data &= ~DIDT_CTRL_EN;
  310. WREG32_DIDT(DIDT_SQ_CTRL0, data);
  311. }
  312. if (pi->caps_db_ramping) {
  313. data = RREG32_DIDT(DIDT_DB_CTRL0);
  314. if (enable)
  315. data |= DIDT_CTRL_EN;
  316. else
  317. data &= ~DIDT_CTRL_EN;
  318. WREG32_DIDT(DIDT_DB_CTRL0, data);
  319. }
  320. if (pi->caps_td_ramping) {
  321. data = RREG32_DIDT(DIDT_TD_CTRL0);
  322. if (enable)
  323. data |= DIDT_CTRL_EN;
  324. else
  325. data &= ~DIDT_CTRL_EN;
  326. WREG32_DIDT(DIDT_TD_CTRL0, data);
  327. }
  328. if (pi->caps_tcp_ramping) {
  329. data = RREG32_DIDT(DIDT_TCP_CTRL0);
  330. if (enable)
  331. data |= DIDT_CTRL_EN;
  332. else
  333. data &= ~DIDT_CTRL_EN;
  334. WREG32_DIDT(DIDT_TCP_CTRL0, data);
  335. }
  336. }
  337. static int kv_enable_didt(struct radeon_device *rdev, bool enable)
  338. {
  339. struct kv_power_info *pi = kv_get_pi(rdev);
  340. int ret;
  341. if (pi->caps_sq_ramping ||
  342. pi->caps_db_ramping ||
  343. pi->caps_td_ramping ||
  344. pi->caps_tcp_ramping) {
  345. cik_enter_rlc_safe_mode(rdev);
  346. if (enable) {
  347. ret = kv_program_pt_config_registers(rdev, didt_config_kv);
  348. if (ret) {
  349. cik_exit_rlc_safe_mode(rdev);
  350. return ret;
  351. }
  352. }
  353. kv_do_enable_didt(rdev, enable);
  354. cik_exit_rlc_safe_mode(rdev);
  355. }
  356. return 0;
  357. }
  358. #if 0
  359. static void kv_initialize_hardware_cac_manager(struct radeon_device *rdev)
  360. {
  361. struct kv_power_info *pi = kv_get_pi(rdev);
  362. if (pi->caps_cac) {
  363. WREG32_SMC(LCAC_SX0_OVR_SEL, 0);
  364. WREG32_SMC(LCAC_SX0_OVR_VAL, 0);
  365. kv_program_local_cac_table(rdev, sx_local_cac_cfg_kv, sx0_cac_config_reg);
  366. WREG32_SMC(LCAC_MC0_OVR_SEL, 0);
  367. WREG32_SMC(LCAC_MC0_OVR_VAL, 0);
  368. kv_program_local_cac_table(rdev, mc0_local_cac_cfg_kv, mc0_cac_config_reg);
  369. WREG32_SMC(LCAC_MC1_OVR_SEL, 0);
  370. WREG32_SMC(LCAC_MC1_OVR_VAL, 0);
  371. kv_program_local_cac_table(rdev, mc1_local_cac_cfg_kv, mc1_cac_config_reg);
  372. WREG32_SMC(LCAC_MC2_OVR_SEL, 0);
  373. WREG32_SMC(LCAC_MC2_OVR_VAL, 0);
  374. kv_program_local_cac_table(rdev, mc2_local_cac_cfg_kv, mc2_cac_config_reg);
  375. WREG32_SMC(LCAC_MC3_OVR_SEL, 0);
  376. WREG32_SMC(LCAC_MC3_OVR_VAL, 0);
  377. kv_program_local_cac_table(rdev, mc3_local_cac_cfg_kv, mc3_cac_config_reg);
  378. WREG32_SMC(LCAC_CPL_OVR_SEL, 0);
  379. WREG32_SMC(LCAC_CPL_OVR_VAL, 0);
  380. kv_program_local_cac_table(rdev, cpl_local_cac_cfg_kv, cpl_cac_config_reg);
  381. }
  382. }
  383. #endif
  384. static int kv_enable_smc_cac(struct radeon_device *rdev, bool enable)
  385. {
  386. struct kv_power_info *pi = kv_get_pi(rdev);
  387. int ret = 0;
  388. if (pi->caps_cac) {
  389. if (enable) {
  390. ret = kv_notify_message_to_smu(rdev, PPSMC_MSG_EnableCac);
  391. if (ret)
  392. pi->cac_enabled = false;
  393. else
  394. pi->cac_enabled = true;
  395. } else if (pi->cac_enabled) {
  396. kv_notify_message_to_smu(rdev, PPSMC_MSG_DisableCac);
  397. pi->cac_enabled = false;
  398. }
  399. }
  400. return ret;
  401. }
  402. static int kv_process_firmware_header(struct radeon_device *rdev)
  403. {
  404. struct kv_power_info *pi = kv_get_pi(rdev);
  405. u32 tmp;
  406. int ret;
  407. ret = kv_read_smc_sram_dword(rdev, SMU7_FIRMWARE_HEADER_LOCATION +
  408. offsetof(SMU7_Firmware_Header, DpmTable),
  409. &tmp, pi->sram_end);
  410. if (ret == 0)
  411. pi->dpm_table_start = tmp;
  412. ret = kv_read_smc_sram_dword(rdev, SMU7_FIRMWARE_HEADER_LOCATION +
  413. offsetof(SMU7_Firmware_Header, SoftRegisters),
  414. &tmp, pi->sram_end);
  415. if (ret == 0)
  416. pi->soft_regs_start = tmp;
  417. return ret;
  418. }
  419. static int kv_enable_dpm_voltage_scaling(struct radeon_device *rdev)
  420. {
  421. struct kv_power_info *pi = kv_get_pi(rdev);
  422. int ret;
  423. pi->graphics_voltage_change_enable = 1;
  424. ret = kv_copy_bytes_to_smc(rdev,
  425. pi->dpm_table_start +
  426. offsetof(SMU7_Fusion_DpmTable, GraphicsVoltageChangeEnable),
  427. &pi->graphics_voltage_change_enable,
  428. sizeof(u8), pi->sram_end);
  429. return ret;
  430. }
  431. static int kv_set_dpm_interval(struct radeon_device *rdev)
  432. {
  433. struct kv_power_info *pi = kv_get_pi(rdev);
  434. int ret;
  435. pi->graphics_interval = 1;
  436. ret = kv_copy_bytes_to_smc(rdev,
  437. pi->dpm_table_start +
  438. offsetof(SMU7_Fusion_DpmTable, GraphicsInterval),
  439. &pi->graphics_interval,
  440. sizeof(u8), pi->sram_end);
  441. return ret;
  442. }
  443. static int kv_set_dpm_boot_state(struct radeon_device *rdev)
  444. {
  445. struct kv_power_info *pi = kv_get_pi(rdev);
  446. int ret;
  447. ret = kv_copy_bytes_to_smc(rdev,
  448. pi->dpm_table_start +
  449. offsetof(SMU7_Fusion_DpmTable, GraphicsBootLevel),
  450. &pi->graphics_boot_level,
  451. sizeof(u8), pi->sram_end);
  452. return ret;
  453. }
  454. static void kv_program_vc(struct radeon_device *rdev)
  455. {
  456. WREG32_SMC(CG_FTV_0, 0x3FFFC100);
  457. }
  458. static void kv_clear_vc(struct radeon_device *rdev)
  459. {
  460. WREG32_SMC(CG_FTV_0, 0);
  461. }
  462. static int kv_set_divider_value(struct radeon_device *rdev,
  463. u32 index, u32 sclk)
  464. {
  465. struct kv_power_info *pi = kv_get_pi(rdev);
  466. struct atom_clock_dividers dividers;
  467. int ret;
  468. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  469. sclk, false, &dividers);
  470. if (ret)
  471. return ret;
  472. pi->graphics_level[index].SclkDid = (u8)dividers.post_div;
  473. pi->graphics_level[index].SclkFrequency = cpu_to_be32(sclk);
  474. return 0;
  475. }
  476. static u32 kv_convert_vid2_to_vid7(struct radeon_device *rdev,
  477. struct sumo_vid_mapping_table *vid_mapping_table,
  478. u32 vid_2bit)
  479. {
  480. struct radeon_clock_voltage_dependency_table *vddc_sclk_table =
  481. &rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
  482. u32 i;
  483. if (vddc_sclk_table && vddc_sclk_table->count) {
  484. if (vid_2bit < vddc_sclk_table->count)
  485. return vddc_sclk_table->entries[vid_2bit].v;
  486. else
  487. return vddc_sclk_table->entries[vddc_sclk_table->count - 1].v;
  488. } else {
  489. for (i = 0; i < vid_mapping_table->num_entries; i++) {
  490. if (vid_mapping_table->entries[i].vid_2bit == vid_2bit)
  491. return vid_mapping_table->entries[i].vid_7bit;
  492. }
  493. return vid_mapping_table->entries[vid_mapping_table->num_entries - 1].vid_7bit;
  494. }
  495. }
  496. static u32 kv_convert_vid7_to_vid2(struct radeon_device *rdev,
  497. struct sumo_vid_mapping_table *vid_mapping_table,
  498. u32 vid_7bit)
  499. {
  500. struct radeon_clock_voltage_dependency_table *vddc_sclk_table =
  501. &rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
  502. u32 i;
  503. if (vddc_sclk_table && vddc_sclk_table->count) {
  504. for (i = 0; i < vddc_sclk_table->count; i++) {
  505. if (vddc_sclk_table->entries[i].v == vid_7bit)
  506. return i;
  507. }
  508. return vddc_sclk_table->count - 1;
  509. } else {
  510. for (i = 0; i < vid_mapping_table->num_entries; i++) {
  511. if (vid_mapping_table->entries[i].vid_7bit == vid_7bit)
  512. return vid_mapping_table->entries[i].vid_2bit;
  513. }
  514. return vid_mapping_table->entries[vid_mapping_table->num_entries - 1].vid_2bit;
  515. }
  516. }
  517. static u16 kv_convert_8bit_index_to_voltage(struct radeon_device *rdev,
  518. u16 voltage)
  519. {
  520. return 6200 - (voltage * 25);
  521. }
  522. static u16 kv_convert_2bit_index_to_voltage(struct radeon_device *rdev,
  523. u32 vid_2bit)
  524. {
  525. struct kv_power_info *pi = kv_get_pi(rdev);
  526. u32 vid_8bit = kv_convert_vid2_to_vid7(rdev,
  527. &pi->sys_info.vid_mapping_table,
  528. vid_2bit);
  529. return kv_convert_8bit_index_to_voltage(rdev, (u16)vid_8bit);
  530. }
  531. static int kv_set_vid(struct radeon_device *rdev, u32 index, u32 vid)
  532. {
  533. struct kv_power_info *pi = kv_get_pi(rdev);
  534. pi->graphics_level[index].VoltageDownH = (u8)pi->voltage_drop_t;
  535. pi->graphics_level[index].MinVddNb =
  536. cpu_to_be32(kv_convert_2bit_index_to_voltage(rdev, vid));
  537. return 0;
  538. }
  539. static int kv_set_at(struct radeon_device *rdev, u32 index, u32 at)
  540. {
  541. struct kv_power_info *pi = kv_get_pi(rdev);
  542. pi->graphics_level[index].AT = cpu_to_be16((u16)at);
  543. return 0;
  544. }
  545. static void kv_dpm_power_level_enable(struct radeon_device *rdev,
  546. u32 index, bool enable)
  547. {
  548. struct kv_power_info *pi = kv_get_pi(rdev);
  549. pi->graphics_level[index].EnabledForActivity = enable ? 1 : 0;
  550. }
  551. static void kv_start_dpm(struct radeon_device *rdev)
  552. {
  553. u32 tmp = RREG32_SMC(GENERAL_PWRMGT);
  554. tmp |= GLOBAL_PWRMGT_EN;
  555. WREG32_SMC(GENERAL_PWRMGT, tmp);
  556. kv_smc_dpm_enable(rdev, true);
  557. }
  558. static void kv_stop_dpm(struct radeon_device *rdev)
  559. {
  560. kv_smc_dpm_enable(rdev, false);
  561. }
  562. static void kv_start_am(struct radeon_device *rdev)
  563. {
  564. u32 sclk_pwrmgt_cntl = RREG32_SMC(SCLK_PWRMGT_CNTL);
  565. sclk_pwrmgt_cntl &= ~(RESET_SCLK_CNT | RESET_BUSY_CNT);
  566. sclk_pwrmgt_cntl |= DYNAMIC_PM_EN;
  567. WREG32_SMC(SCLK_PWRMGT_CNTL, sclk_pwrmgt_cntl);
  568. }
  569. static void kv_reset_am(struct radeon_device *rdev)
  570. {
  571. u32 sclk_pwrmgt_cntl = RREG32_SMC(SCLK_PWRMGT_CNTL);
  572. sclk_pwrmgt_cntl |= (RESET_SCLK_CNT | RESET_BUSY_CNT);
  573. WREG32_SMC(SCLK_PWRMGT_CNTL, sclk_pwrmgt_cntl);
  574. }
  575. static int kv_freeze_sclk_dpm(struct radeon_device *rdev, bool freeze)
  576. {
  577. return kv_notify_message_to_smu(rdev, freeze ?
  578. PPSMC_MSG_SCLKDPM_FreezeLevel : PPSMC_MSG_SCLKDPM_UnfreezeLevel);
  579. }
  580. static int kv_force_lowest_valid(struct radeon_device *rdev)
  581. {
  582. return kv_force_dpm_lowest(rdev);
  583. }
  584. static int kv_unforce_levels(struct radeon_device *rdev)
  585. {
  586. if (rdev->family == CHIP_KABINI || rdev->family == CHIP_MULLINS)
  587. return kv_notify_message_to_smu(rdev, PPSMC_MSG_NoForcedLevel);
  588. else
  589. return kv_set_enabled_levels(rdev);
  590. }
  591. static int kv_update_sclk_t(struct radeon_device *rdev)
  592. {
  593. struct kv_power_info *pi = kv_get_pi(rdev);
  594. u32 low_sclk_interrupt_t = 0;
  595. int ret = 0;
  596. if (pi->caps_sclk_throttle_low_notification) {
  597. low_sclk_interrupt_t = cpu_to_be32(pi->low_sclk_interrupt_t);
  598. ret = kv_copy_bytes_to_smc(rdev,
  599. pi->dpm_table_start +
  600. offsetof(SMU7_Fusion_DpmTable, LowSclkInterruptT),
  601. (u8 *)&low_sclk_interrupt_t,
  602. sizeof(u32), pi->sram_end);
  603. }
  604. return ret;
  605. }
  606. static int kv_program_bootup_state(struct radeon_device *rdev)
  607. {
  608. struct kv_power_info *pi = kv_get_pi(rdev);
  609. u32 i;
  610. struct radeon_clock_voltage_dependency_table *table =
  611. &rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
  612. if (table && table->count) {
  613. for (i = pi->graphics_dpm_level_count - 1; i > 0; i--) {
  614. if (table->entries[i].clk == pi->boot_pl.sclk)
  615. break;
  616. }
  617. pi->graphics_boot_level = (u8)i;
  618. kv_dpm_power_level_enable(rdev, i, true);
  619. } else {
  620. struct sumo_sclk_voltage_mapping_table *table =
  621. &pi->sys_info.sclk_voltage_mapping_table;
  622. if (table->num_max_dpm_entries == 0)
  623. return -EINVAL;
  624. for (i = pi->graphics_dpm_level_count - 1; i > 0; i--) {
  625. if (table->entries[i].sclk_frequency == pi->boot_pl.sclk)
  626. break;
  627. }
  628. pi->graphics_boot_level = (u8)i;
  629. kv_dpm_power_level_enable(rdev, i, true);
  630. }
  631. return 0;
  632. }
  633. static int kv_enable_auto_thermal_throttling(struct radeon_device *rdev)
  634. {
  635. struct kv_power_info *pi = kv_get_pi(rdev);
  636. int ret;
  637. pi->graphics_therm_throttle_enable = 1;
  638. ret = kv_copy_bytes_to_smc(rdev,
  639. pi->dpm_table_start +
  640. offsetof(SMU7_Fusion_DpmTable, GraphicsThermThrottleEnable),
  641. &pi->graphics_therm_throttle_enable,
  642. sizeof(u8), pi->sram_end);
  643. return ret;
  644. }
  645. static int kv_upload_dpm_settings(struct radeon_device *rdev)
  646. {
  647. struct kv_power_info *pi = kv_get_pi(rdev);
  648. int ret;
  649. ret = kv_copy_bytes_to_smc(rdev,
  650. pi->dpm_table_start +
  651. offsetof(SMU7_Fusion_DpmTable, GraphicsLevel),
  652. (u8 *)&pi->graphics_level,
  653. sizeof(SMU7_Fusion_GraphicsLevel) * SMU7_MAX_LEVELS_GRAPHICS,
  654. pi->sram_end);
  655. if (ret)
  656. return ret;
  657. ret = kv_copy_bytes_to_smc(rdev,
  658. pi->dpm_table_start +
  659. offsetof(SMU7_Fusion_DpmTable, GraphicsDpmLevelCount),
  660. &pi->graphics_dpm_level_count,
  661. sizeof(u8), pi->sram_end);
  662. return ret;
  663. }
  664. static u32 kv_get_clock_difference(u32 a, u32 b)
  665. {
  666. return (a >= b) ? a - b : b - a;
  667. }
  668. static u32 kv_get_clk_bypass(struct radeon_device *rdev, u32 clk)
  669. {
  670. struct kv_power_info *pi = kv_get_pi(rdev);
  671. u32 value;
  672. if (pi->caps_enable_dfs_bypass) {
  673. if (kv_get_clock_difference(clk, 40000) < 200)
  674. value = 3;
  675. else if (kv_get_clock_difference(clk, 30000) < 200)
  676. value = 2;
  677. else if (kv_get_clock_difference(clk, 20000) < 200)
  678. value = 7;
  679. else if (kv_get_clock_difference(clk, 15000) < 200)
  680. value = 6;
  681. else if (kv_get_clock_difference(clk, 10000) < 200)
  682. value = 8;
  683. else
  684. value = 0;
  685. } else {
  686. value = 0;
  687. }
  688. return value;
  689. }
  690. static int kv_populate_uvd_table(struct radeon_device *rdev)
  691. {
  692. struct kv_power_info *pi = kv_get_pi(rdev);
  693. struct radeon_uvd_clock_voltage_dependency_table *table =
  694. &rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table;
  695. struct atom_clock_dividers dividers;
  696. int ret;
  697. u32 i;
  698. if (table == NULL || table->count == 0)
  699. return 0;
  700. pi->uvd_level_count = 0;
  701. for (i = 0; i < table->count; i++) {
  702. if (pi->high_voltage_t &&
  703. (pi->high_voltage_t < table->entries[i].v))
  704. break;
  705. pi->uvd_level[i].VclkFrequency = cpu_to_be32(table->entries[i].vclk);
  706. pi->uvd_level[i].DclkFrequency = cpu_to_be32(table->entries[i].dclk);
  707. pi->uvd_level[i].MinVddNb = cpu_to_be16(table->entries[i].v);
  708. pi->uvd_level[i].VClkBypassCntl =
  709. (u8)kv_get_clk_bypass(rdev, table->entries[i].vclk);
  710. pi->uvd_level[i].DClkBypassCntl =
  711. (u8)kv_get_clk_bypass(rdev, table->entries[i].dclk);
  712. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  713. table->entries[i].vclk, false, &dividers);
  714. if (ret)
  715. return ret;
  716. pi->uvd_level[i].VclkDivider = (u8)dividers.post_div;
  717. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  718. table->entries[i].dclk, false, &dividers);
  719. if (ret)
  720. return ret;
  721. pi->uvd_level[i].DclkDivider = (u8)dividers.post_div;
  722. pi->uvd_level_count++;
  723. }
  724. ret = kv_copy_bytes_to_smc(rdev,
  725. pi->dpm_table_start +
  726. offsetof(SMU7_Fusion_DpmTable, UvdLevelCount),
  727. (u8 *)&pi->uvd_level_count,
  728. sizeof(u8), pi->sram_end);
  729. if (ret)
  730. return ret;
  731. pi->uvd_interval = 1;
  732. ret = kv_copy_bytes_to_smc(rdev,
  733. pi->dpm_table_start +
  734. offsetof(SMU7_Fusion_DpmTable, UVDInterval),
  735. &pi->uvd_interval,
  736. sizeof(u8), pi->sram_end);
  737. if (ret)
  738. return ret;
  739. ret = kv_copy_bytes_to_smc(rdev,
  740. pi->dpm_table_start +
  741. offsetof(SMU7_Fusion_DpmTable, UvdLevel),
  742. (u8 *)&pi->uvd_level,
  743. sizeof(SMU7_Fusion_UvdLevel) * SMU7_MAX_LEVELS_UVD,
  744. pi->sram_end);
  745. return ret;
  746. }
  747. static int kv_populate_vce_table(struct radeon_device *rdev)
  748. {
  749. struct kv_power_info *pi = kv_get_pi(rdev);
  750. int ret;
  751. u32 i;
  752. struct radeon_vce_clock_voltage_dependency_table *table =
  753. &rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table;
  754. struct atom_clock_dividers dividers;
  755. if (table == NULL || table->count == 0)
  756. return 0;
  757. pi->vce_level_count = 0;
  758. for (i = 0; i < table->count; i++) {
  759. if (pi->high_voltage_t &&
  760. pi->high_voltage_t < table->entries[i].v)
  761. break;
  762. pi->vce_level[i].Frequency = cpu_to_be32(table->entries[i].evclk);
  763. pi->vce_level[i].MinVoltage = cpu_to_be16(table->entries[i].v);
  764. pi->vce_level[i].ClkBypassCntl =
  765. (u8)kv_get_clk_bypass(rdev, table->entries[i].evclk);
  766. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  767. table->entries[i].evclk, false, &dividers);
  768. if (ret)
  769. return ret;
  770. pi->vce_level[i].Divider = (u8)dividers.post_div;
  771. pi->vce_level_count++;
  772. }
  773. ret = kv_copy_bytes_to_smc(rdev,
  774. pi->dpm_table_start +
  775. offsetof(SMU7_Fusion_DpmTable, VceLevelCount),
  776. (u8 *)&pi->vce_level_count,
  777. sizeof(u8),
  778. pi->sram_end);
  779. if (ret)
  780. return ret;
  781. pi->vce_interval = 1;
  782. ret = kv_copy_bytes_to_smc(rdev,
  783. pi->dpm_table_start +
  784. offsetof(SMU7_Fusion_DpmTable, VCEInterval),
  785. (u8 *)&pi->vce_interval,
  786. sizeof(u8),
  787. pi->sram_end);
  788. if (ret)
  789. return ret;
  790. ret = kv_copy_bytes_to_smc(rdev,
  791. pi->dpm_table_start +
  792. offsetof(SMU7_Fusion_DpmTable, VceLevel),
  793. (u8 *)&pi->vce_level,
  794. sizeof(SMU7_Fusion_ExtClkLevel) * SMU7_MAX_LEVELS_VCE,
  795. pi->sram_end);
  796. return ret;
  797. }
  798. static int kv_populate_samu_table(struct radeon_device *rdev)
  799. {
  800. struct kv_power_info *pi = kv_get_pi(rdev);
  801. struct radeon_clock_voltage_dependency_table *table =
  802. &rdev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table;
  803. struct atom_clock_dividers dividers;
  804. int ret;
  805. u32 i;
  806. if (table == NULL || table->count == 0)
  807. return 0;
  808. pi->samu_level_count = 0;
  809. for (i = 0; i < table->count; i++) {
  810. if (pi->high_voltage_t &&
  811. pi->high_voltage_t < table->entries[i].v)
  812. break;
  813. pi->samu_level[i].Frequency = cpu_to_be32(table->entries[i].clk);
  814. pi->samu_level[i].MinVoltage = cpu_to_be16(table->entries[i].v);
  815. pi->samu_level[i].ClkBypassCntl =
  816. (u8)kv_get_clk_bypass(rdev, table->entries[i].clk);
  817. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  818. table->entries[i].clk, false, &dividers);
  819. if (ret)
  820. return ret;
  821. pi->samu_level[i].Divider = (u8)dividers.post_div;
  822. pi->samu_level_count++;
  823. }
  824. ret = kv_copy_bytes_to_smc(rdev,
  825. pi->dpm_table_start +
  826. offsetof(SMU7_Fusion_DpmTable, SamuLevelCount),
  827. (u8 *)&pi->samu_level_count,
  828. sizeof(u8),
  829. pi->sram_end);
  830. if (ret)
  831. return ret;
  832. pi->samu_interval = 1;
  833. ret = kv_copy_bytes_to_smc(rdev,
  834. pi->dpm_table_start +
  835. offsetof(SMU7_Fusion_DpmTable, SAMUInterval),
  836. (u8 *)&pi->samu_interval,
  837. sizeof(u8),
  838. pi->sram_end);
  839. if (ret)
  840. return ret;
  841. ret = kv_copy_bytes_to_smc(rdev,
  842. pi->dpm_table_start +
  843. offsetof(SMU7_Fusion_DpmTable, SamuLevel),
  844. (u8 *)&pi->samu_level,
  845. sizeof(SMU7_Fusion_ExtClkLevel) * SMU7_MAX_LEVELS_SAMU,
  846. pi->sram_end);
  847. if (ret)
  848. return ret;
  849. return ret;
  850. }
  851. static int kv_populate_acp_table(struct radeon_device *rdev)
  852. {
  853. struct kv_power_info *pi = kv_get_pi(rdev);
  854. struct radeon_clock_voltage_dependency_table *table =
  855. &rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table;
  856. struct atom_clock_dividers dividers;
  857. int ret;
  858. u32 i;
  859. if (table == NULL || table->count == 0)
  860. return 0;
  861. pi->acp_level_count = 0;
  862. for (i = 0; i < table->count; i++) {
  863. pi->acp_level[i].Frequency = cpu_to_be32(table->entries[i].clk);
  864. pi->acp_level[i].MinVoltage = cpu_to_be16(table->entries[i].v);
  865. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  866. table->entries[i].clk, false, &dividers);
  867. if (ret)
  868. return ret;
  869. pi->acp_level[i].Divider = (u8)dividers.post_div;
  870. pi->acp_level_count++;
  871. }
  872. ret = kv_copy_bytes_to_smc(rdev,
  873. pi->dpm_table_start +
  874. offsetof(SMU7_Fusion_DpmTable, AcpLevelCount),
  875. (u8 *)&pi->acp_level_count,
  876. sizeof(u8),
  877. pi->sram_end);
  878. if (ret)
  879. return ret;
  880. pi->acp_interval = 1;
  881. ret = kv_copy_bytes_to_smc(rdev,
  882. pi->dpm_table_start +
  883. offsetof(SMU7_Fusion_DpmTable, ACPInterval),
  884. (u8 *)&pi->acp_interval,
  885. sizeof(u8),
  886. pi->sram_end);
  887. if (ret)
  888. return ret;
  889. ret = kv_copy_bytes_to_smc(rdev,
  890. pi->dpm_table_start +
  891. offsetof(SMU7_Fusion_DpmTable, AcpLevel),
  892. (u8 *)&pi->acp_level,
  893. sizeof(SMU7_Fusion_ExtClkLevel) * SMU7_MAX_LEVELS_ACP,
  894. pi->sram_end);
  895. if (ret)
  896. return ret;
  897. return ret;
  898. }
  899. static void kv_calculate_dfs_bypass_settings(struct radeon_device *rdev)
  900. {
  901. struct kv_power_info *pi = kv_get_pi(rdev);
  902. u32 i;
  903. struct radeon_clock_voltage_dependency_table *table =
  904. &rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
  905. if (table && table->count) {
  906. for (i = 0; i < pi->graphics_dpm_level_count; i++) {
  907. if (pi->caps_enable_dfs_bypass) {
  908. if (kv_get_clock_difference(table->entries[i].clk, 40000) < 200)
  909. pi->graphics_level[i].ClkBypassCntl = 3;
  910. else if (kv_get_clock_difference(table->entries[i].clk, 30000) < 200)
  911. pi->graphics_level[i].ClkBypassCntl = 2;
  912. else if (kv_get_clock_difference(table->entries[i].clk, 26600) < 200)
  913. pi->graphics_level[i].ClkBypassCntl = 7;
  914. else if (kv_get_clock_difference(table->entries[i].clk , 20000) < 200)
  915. pi->graphics_level[i].ClkBypassCntl = 6;
  916. else if (kv_get_clock_difference(table->entries[i].clk , 10000) < 200)
  917. pi->graphics_level[i].ClkBypassCntl = 8;
  918. else
  919. pi->graphics_level[i].ClkBypassCntl = 0;
  920. } else {
  921. pi->graphics_level[i].ClkBypassCntl = 0;
  922. }
  923. }
  924. } else {
  925. struct sumo_sclk_voltage_mapping_table *table =
  926. &pi->sys_info.sclk_voltage_mapping_table;
  927. for (i = 0; i < pi->graphics_dpm_level_count; i++) {
  928. if (pi->caps_enable_dfs_bypass) {
  929. if (kv_get_clock_difference(table->entries[i].sclk_frequency, 40000) < 200)
  930. pi->graphics_level[i].ClkBypassCntl = 3;
  931. else if (kv_get_clock_difference(table->entries[i].sclk_frequency, 30000) < 200)
  932. pi->graphics_level[i].ClkBypassCntl = 2;
  933. else if (kv_get_clock_difference(table->entries[i].sclk_frequency, 26600) < 200)
  934. pi->graphics_level[i].ClkBypassCntl = 7;
  935. else if (kv_get_clock_difference(table->entries[i].sclk_frequency, 20000) < 200)
  936. pi->graphics_level[i].ClkBypassCntl = 6;
  937. else if (kv_get_clock_difference(table->entries[i].sclk_frequency, 10000) < 200)
  938. pi->graphics_level[i].ClkBypassCntl = 8;
  939. else
  940. pi->graphics_level[i].ClkBypassCntl = 0;
  941. } else {
  942. pi->graphics_level[i].ClkBypassCntl = 0;
  943. }
  944. }
  945. }
  946. }
  947. static int kv_enable_ulv(struct radeon_device *rdev, bool enable)
  948. {
  949. return kv_notify_message_to_smu(rdev, enable ?
  950. PPSMC_MSG_EnableULV : PPSMC_MSG_DisableULV);
  951. }
  952. static void kv_reset_acp_boot_level(struct radeon_device *rdev)
  953. {
  954. struct kv_power_info *pi = kv_get_pi(rdev);
  955. pi->acp_boot_level = 0xff;
  956. }
  957. static void kv_update_current_ps(struct radeon_device *rdev,
  958. struct radeon_ps *rps)
  959. {
  960. struct kv_ps *new_ps = kv_get_ps(rps);
  961. struct kv_power_info *pi = kv_get_pi(rdev);
  962. pi->current_rps = *rps;
  963. pi->current_ps = *new_ps;
  964. pi->current_rps.ps_priv = &pi->current_ps;
  965. }
  966. static void kv_update_requested_ps(struct radeon_device *rdev,
  967. struct radeon_ps *rps)
  968. {
  969. struct kv_ps *new_ps = kv_get_ps(rps);
  970. struct kv_power_info *pi = kv_get_pi(rdev);
  971. pi->requested_rps = *rps;
  972. pi->requested_ps = *new_ps;
  973. pi->requested_rps.ps_priv = &pi->requested_ps;
  974. }
  975. void kv_dpm_enable_bapm(struct radeon_device *rdev, bool enable)
  976. {
  977. struct kv_power_info *pi = kv_get_pi(rdev);
  978. int ret;
  979. if (pi->bapm_enable) {
  980. ret = kv_smc_bapm_enable(rdev, enable);
  981. if (ret)
  982. DRM_ERROR("kv_smc_bapm_enable failed\n");
  983. }
  984. }
  985. static void kv_enable_thermal_int(struct radeon_device *rdev, bool enable)
  986. {
  987. u32 thermal_int;
  988. thermal_int = RREG32_SMC(CG_THERMAL_INT_CTRL);
  989. if (enable)
  990. thermal_int |= THERM_INTH_MASK | THERM_INTL_MASK;
  991. else
  992. thermal_int &= ~(THERM_INTH_MASK | THERM_INTL_MASK);
  993. WREG32_SMC(CG_THERMAL_INT_CTRL, thermal_int);
  994. }
  995. int kv_dpm_enable(struct radeon_device *rdev)
  996. {
  997. struct kv_power_info *pi = kv_get_pi(rdev);
  998. int ret;
  999. ret = kv_process_firmware_header(rdev);
  1000. if (ret) {
  1001. DRM_ERROR("kv_process_firmware_header failed\n");
  1002. return ret;
  1003. }
  1004. kv_init_fps_limits(rdev);
  1005. kv_init_graphics_levels(rdev);
  1006. ret = kv_program_bootup_state(rdev);
  1007. if (ret) {
  1008. DRM_ERROR("kv_program_bootup_state failed\n");
  1009. return ret;
  1010. }
  1011. kv_calculate_dfs_bypass_settings(rdev);
  1012. ret = kv_upload_dpm_settings(rdev);
  1013. if (ret) {
  1014. DRM_ERROR("kv_upload_dpm_settings failed\n");
  1015. return ret;
  1016. }
  1017. ret = kv_populate_uvd_table(rdev);
  1018. if (ret) {
  1019. DRM_ERROR("kv_populate_uvd_table failed\n");
  1020. return ret;
  1021. }
  1022. ret = kv_populate_vce_table(rdev);
  1023. if (ret) {
  1024. DRM_ERROR("kv_populate_vce_table failed\n");
  1025. return ret;
  1026. }
  1027. ret = kv_populate_samu_table(rdev);
  1028. if (ret) {
  1029. DRM_ERROR("kv_populate_samu_table failed\n");
  1030. return ret;
  1031. }
  1032. ret = kv_populate_acp_table(rdev);
  1033. if (ret) {
  1034. DRM_ERROR("kv_populate_acp_table failed\n");
  1035. return ret;
  1036. }
  1037. kv_program_vc(rdev);
  1038. #if 0
  1039. kv_initialize_hardware_cac_manager(rdev);
  1040. #endif
  1041. kv_start_am(rdev);
  1042. if (pi->enable_auto_thermal_throttling) {
  1043. ret = kv_enable_auto_thermal_throttling(rdev);
  1044. if (ret) {
  1045. DRM_ERROR("kv_enable_auto_thermal_throttling failed\n");
  1046. return ret;
  1047. }
  1048. }
  1049. ret = kv_enable_dpm_voltage_scaling(rdev);
  1050. if (ret) {
  1051. DRM_ERROR("kv_enable_dpm_voltage_scaling failed\n");
  1052. return ret;
  1053. }
  1054. ret = kv_set_dpm_interval(rdev);
  1055. if (ret) {
  1056. DRM_ERROR("kv_set_dpm_interval failed\n");
  1057. return ret;
  1058. }
  1059. ret = kv_set_dpm_boot_state(rdev);
  1060. if (ret) {
  1061. DRM_ERROR("kv_set_dpm_boot_state failed\n");
  1062. return ret;
  1063. }
  1064. ret = kv_enable_ulv(rdev, true);
  1065. if (ret) {
  1066. DRM_ERROR("kv_enable_ulv failed\n");
  1067. return ret;
  1068. }
  1069. kv_start_dpm(rdev);
  1070. ret = kv_enable_didt(rdev, true);
  1071. if (ret) {
  1072. DRM_ERROR("kv_enable_didt failed\n");
  1073. return ret;
  1074. }
  1075. ret = kv_enable_smc_cac(rdev, true);
  1076. if (ret) {
  1077. DRM_ERROR("kv_enable_smc_cac failed\n");
  1078. return ret;
  1079. }
  1080. kv_reset_acp_boot_level(rdev);
  1081. ret = kv_smc_bapm_enable(rdev, false);
  1082. if (ret) {
  1083. DRM_ERROR("kv_smc_bapm_enable failed\n");
  1084. return ret;
  1085. }
  1086. kv_update_current_ps(rdev, rdev->pm.dpm.boot_ps);
  1087. return ret;
  1088. }
  1089. int kv_dpm_late_enable(struct radeon_device *rdev)
  1090. {
  1091. int ret = 0;
  1092. if (rdev->irq.installed &&
  1093. r600_is_internal_thermal_sensor(rdev->pm.int_thermal_type)) {
  1094. ret = kv_set_thermal_temperature_range(rdev, R600_TEMP_RANGE_MIN, R600_TEMP_RANGE_MAX);
  1095. if (ret) {
  1096. DRM_ERROR("kv_set_thermal_temperature_range failed\n");
  1097. return ret;
  1098. }
  1099. kv_enable_thermal_int(rdev, true);
  1100. }
  1101. /* powerdown unused blocks for now */
  1102. kv_dpm_powergate_acp(rdev, true);
  1103. kv_dpm_powergate_samu(rdev, true);
  1104. kv_dpm_powergate_vce(rdev, true);
  1105. kv_dpm_powergate_uvd(rdev, true);
  1106. return ret;
  1107. }
  1108. void kv_dpm_disable(struct radeon_device *rdev)
  1109. {
  1110. kv_smc_bapm_enable(rdev, false);
  1111. if (rdev->family == CHIP_MULLINS)
  1112. kv_enable_nb_dpm(rdev, false);
  1113. /* powerup blocks */
  1114. kv_dpm_powergate_acp(rdev, false);
  1115. kv_dpm_powergate_samu(rdev, false);
  1116. kv_dpm_powergate_vce(rdev, false);
  1117. kv_dpm_powergate_uvd(rdev, false);
  1118. kv_enable_smc_cac(rdev, false);
  1119. kv_enable_didt(rdev, false);
  1120. kv_clear_vc(rdev);
  1121. kv_stop_dpm(rdev);
  1122. kv_enable_ulv(rdev, false);
  1123. kv_reset_am(rdev);
  1124. kv_enable_thermal_int(rdev, false);
  1125. kv_update_current_ps(rdev, rdev->pm.dpm.boot_ps);
  1126. }
  1127. #if 0
  1128. static int kv_write_smc_soft_register(struct radeon_device *rdev,
  1129. u16 reg_offset, u32 value)
  1130. {
  1131. struct kv_power_info *pi = kv_get_pi(rdev);
  1132. return kv_copy_bytes_to_smc(rdev, pi->soft_regs_start + reg_offset,
  1133. (u8 *)&value, sizeof(u16), pi->sram_end);
  1134. }
  1135. static int kv_read_smc_soft_register(struct radeon_device *rdev,
  1136. u16 reg_offset, u32 *value)
  1137. {
  1138. struct kv_power_info *pi = kv_get_pi(rdev);
  1139. return kv_read_smc_sram_dword(rdev, pi->soft_regs_start + reg_offset,
  1140. value, pi->sram_end);
  1141. }
  1142. #endif
  1143. static void kv_init_sclk_t(struct radeon_device *rdev)
  1144. {
  1145. struct kv_power_info *pi = kv_get_pi(rdev);
  1146. pi->low_sclk_interrupt_t = 0;
  1147. }
  1148. static int kv_init_fps_limits(struct radeon_device *rdev)
  1149. {
  1150. struct kv_power_info *pi = kv_get_pi(rdev);
  1151. int ret = 0;
  1152. if (pi->caps_fps) {
  1153. u16 tmp;
  1154. tmp = 45;
  1155. pi->fps_high_t = cpu_to_be16(tmp);
  1156. ret = kv_copy_bytes_to_smc(rdev,
  1157. pi->dpm_table_start +
  1158. offsetof(SMU7_Fusion_DpmTable, FpsHighT),
  1159. (u8 *)&pi->fps_high_t,
  1160. sizeof(u16), pi->sram_end);
  1161. tmp = 30;
  1162. pi->fps_low_t = cpu_to_be16(tmp);
  1163. ret = kv_copy_bytes_to_smc(rdev,
  1164. pi->dpm_table_start +
  1165. offsetof(SMU7_Fusion_DpmTable, FpsLowT),
  1166. (u8 *)&pi->fps_low_t,
  1167. sizeof(u16), pi->sram_end);
  1168. }
  1169. return ret;
  1170. }
  1171. static void kv_init_powergate_state(struct radeon_device *rdev)
  1172. {
  1173. struct kv_power_info *pi = kv_get_pi(rdev);
  1174. pi->uvd_power_gated = false;
  1175. pi->vce_power_gated = false;
  1176. pi->samu_power_gated = false;
  1177. pi->acp_power_gated = false;
  1178. }
  1179. static int kv_enable_uvd_dpm(struct radeon_device *rdev, bool enable)
  1180. {
  1181. return kv_notify_message_to_smu(rdev, enable ?
  1182. PPSMC_MSG_UVDDPM_Enable : PPSMC_MSG_UVDDPM_Disable);
  1183. }
  1184. static int kv_enable_vce_dpm(struct radeon_device *rdev, bool enable)
  1185. {
  1186. return kv_notify_message_to_smu(rdev, enable ?
  1187. PPSMC_MSG_VCEDPM_Enable : PPSMC_MSG_VCEDPM_Disable);
  1188. }
  1189. static int kv_enable_samu_dpm(struct radeon_device *rdev, bool enable)
  1190. {
  1191. return kv_notify_message_to_smu(rdev, enable ?
  1192. PPSMC_MSG_SAMUDPM_Enable : PPSMC_MSG_SAMUDPM_Disable);
  1193. }
  1194. static int kv_enable_acp_dpm(struct radeon_device *rdev, bool enable)
  1195. {
  1196. return kv_notify_message_to_smu(rdev, enable ?
  1197. PPSMC_MSG_ACPDPM_Enable : PPSMC_MSG_ACPDPM_Disable);
  1198. }
  1199. static int kv_update_uvd_dpm(struct radeon_device *rdev, bool gate)
  1200. {
  1201. struct kv_power_info *pi = kv_get_pi(rdev);
  1202. struct radeon_uvd_clock_voltage_dependency_table *table =
  1203. &rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table;
  1204. int ret;
  1205. u32 mask;
  1206. if (!gate) {
  1207. if (table->count)
  1208. pi->uvd_boot_level = table->count - 1;
  1209. else
  1210. pi->uvd_boot_level = 0;
  1211. if (!pi->caps_uvd_dpm || pi->caps_stable_p_state) {
  1212. mask = 1 << pi->uvd_boot_level;
  1213. } else {
  1214. mask = 0x1f;
  1215. }
  1216. ret = kv_copy_bytes_to_smc(rdev,
  1217. pi->dpm_table_start +
  1218. offsetof(SMU7_Fusion_DpmTable, UvdBootLevel),
  1219. (uint8_t *)&pi->uvd_boot_level,
  1220. sizeof(u8), pi->sram_end);
  1221. if (ret)
  1222. return ret;
  1223. kv_send_msg_to_smc_with_parameter(rdev,
  1224. PPSMC_MSG_UVDDPM_SetEnabledMask,
  1225. mask);
  1226. }
  1227. return kv_enable_uvd_dpm(rdev, !gate);
  1228. }
  1229. static u8 kv_get_vce_boot_level(struct radeon_device *rdev, u32 evclk)
  1230. {
  1231. u8 i;
  1232. struct radeon_vce_clock_voltage_dependency_table *table =
  1233. &rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table;
  1234. for (i = 0; i < table->count; i++) {
  1235. if (table->entries[i].evclk >= evclk)
  1236. break;
  1237. }
  1238. return i;
  1239. }
  1240. static int kv_update_vce_dpm(struct radeon_device *rdev,
  1241. struct radeon_ps *radeon_new_state,
  1242. struct radeon_ps *radeon_current_state)
  1243. {
  1244. struct kv_power_info *pi = kv_get_pi(rdev);
  1245. struct radeon_vce_clock_voltage_dependency_table *table =
  1246. &rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table;
  1247. int ret;
  1248. if (radeon_new_state->evclk > 0 && radeon_current_state->evclk == 0) {
  1249. kv_dpm_powergate_vce(rdev, false);
  1250. /* turn the clocks on when encoding */
  1251. cik_update_cg(rdev, RADEON_CG_BLOCK_VCE, false);
  1252. if (pi->caps_stable_p_state)
  1253. pi->vce_boot_level = table->count - 1;
  1254. else
  1255. pi->vce_boot_level = kv_get_vce_boot_level(rdev, radeon_new_state->evclk);
  1256. ret = kv_copy_bytes_to_smc(rdev,
  1257. pi->dpm_table_start +
  1258. offsetof(SMU7_Fusion_DpmTable, VceBootLevel),
  1259. (u8 *)&pi->vce_boot_level,
  1260. sizeof(u8),
  1261. pi->sram_end);
  1262. if (ret)
  1263. return ret;
  1264. if (pi->caps_stable_p_state)
  1265. kv_send_msg_to_smc_with_parameter(rdev,
  1266. PPSMC_MSG_VCEDPM_SetEnabledMask,
  1267. (1 << pi->vce_boot_level));
  1268. kv_enable_vce_dpm(rdev, true);
  1269. } else if (radeon_new_state->evclk == 0 && radeon_current_state->evclk > 0) {
  1270. kv_enable_vce_dpm(rdev, false);
  1271. /* turn the clocks off when not encoding */
  1272. cik_update_cg(rdev, RADEON_CG_BLOCK_VCE, true);
  1273. kv_dpm_powergate_vce(rdev, true);
  1274. }
  1275. return 0;
  1276. }
  1277. static int kv_update_samu_dpm(struct radeon_device *rdev, bool gate)
  1278. {
  1279. struct kv_power_info *pi = kv_get_pi(rdev);
  1280. struct radeon_clock_voltage_dependency_table *table =
  1281. &rdev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table;
  1282. int ret;
  1283. if (!gate) {
  1284. if (pi->caps_stable_p_state)
  1285. pi->samu_boot_level = table->count - 1;
  1286. else
  1287. pi->samu_boot_level = 0;
  1288. ret = kv_copy_bytes_to_smc(rdev,
  1289. pi->dpm_table_start +
  1290. offsetof(SMU7_Fusion_DpmTable, SamuBootLevel),
  1291. (u8 *)&pi->samu_boot_level,
  1292. sizeof(u8),
  1293. pi->sram_end);
  1294. if (ret)
  1295. return ret;
  1296. if (pi->caps_stable_p_state)
  1297. kv_send_msg_to_smc_with_parameter(rdev,
  1298. PPSMC_MSG_SAMUDPM_SetEnabledMask,
  1299. (1 << pi->samu_boot_level));
  1300. }
  1301. return kv_enable_samu_dpm(rdev, !gate);
  1302. }
  1303. static u8 kv_get_acp_boot_level(struct radeon_device *rdev)
  1304. {
  1305. u8 i;
  1306. struct radeon_clock_voltage_dependency_table *table =
  1307. &rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table;
  1308. for (i = 0; i < table->count; i++) {
  1309. if (table->entries[i].clk >= 0) /* XXX */
  1310. break;
  1311. }
  1312. if (i >= table->count)
  1313. i = table->count - 1;
  1314. return i;
  1315. }
  1316. static void kv_update_acp_boot_level(struct radeon_device *rdev)
  1317. {
  1318. struct kv_power_info *pi = kv_get_pi(rdev);
  1319. u8 acp_boot_level;
  1320. if (!pi->caps_stable_p_state) {
  1321. acp_boot_level = kv_get_acp_boot_level(rdev);
  1322. if (acp_boot_level != pi->acp_boot_level) {
  1323. pi->acp_boot_level = acp_boot_level;
  1324. kv_send_msg_to_smc_with_parameter(rdev,
  1325. PPSMC_MSG_ACPDPM_SetEnabledMask,
  1326. (1 << pi->acp_boot_level));
  1327. }
  1328. }
  1329. }
  1330. static int kv_update_acp_dpm(struct radeon_device *rdev, bool gate)
  1331. {
  1332. struct kv_power_info *pi = kv_get_pi(rdev);
  1333. struct radeon_clock_voltage_dependency_table *table =
  1334. &rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table;
  1335. int ret;
  1336. if (!gate) {
  1337. if (pi->caps_stable_p_state)
  1338. pi->acp_boot_level = table->count - 1;
  1339. else
  1340. pi->acp_boot_level = kv_get_acp_boot_level(rdev);
  1341. ret = kv_copy_bytes_to_smc(rdev,
  1342. pi->dpm_table_start +
  1343. offsetof(SMU7_Fusion_DpmTable, AcpBootLevel),
  1344. (u8 *)&pi->acp_boot_level,
  1345. sizeof(u8),
  1346. pi->sram_end);
  1347. if (ret)
  1348. return ret;
  1349. if (pi->caps_stable_p_state)
  1350. kv_send_msg_to_smc_with_parameter(rdev,
  1351. PPSMC_MSG_ACPDPM_SetEnabledMask,
  1352. (1 << pi->acp_boot_level));
  1353. }
  1354. return kv_enable_acp_dpm(rdev, !gate);
  1355. }
  1356. void kv_dpm_powergate_uvd(struct radeon_device *rdev, bool gate)
  1357. {
  1358. struct kv_power_info *pi = kv_get_pi(rdev);
  1359. if (pi->uvd_power_gated == gate)
  1360. return;
  1361. pi->uvd_power_gated = gate;
  1362. if (gate) {
  1363. if (pi->caps_uvd_pg) {
  1364. uvd_v1_0_stop(rdev);
  1365. cik_update_cg(rdev, RADEON_CG_BLOCK_UVD, false);
  1366. }
  1367. kv_update_uvd_dpm(rdev, gate);
  1368. if (pi->caps_uvd_pg)
  1369. kv_notify_message_to_smu(rdev, PPSMC_MSG_UVDPowerOFF);
  1370. } else {
  1371. if (pi->caps_uvd_pg) {
  1372. kv_notify_message_to_smu(rdev, PPSMC_MSG_UVDPowerON);
  1373. uvd_v4_2_resume(rdev);
  1374. uvd_v1_0_start(rdev);
  1375. cik_update_cg(rdev, RADEON_CG_BLOCK_UVD, true);
  1376. }
  1377. kv_update_uvd_dpm(rdev, gate);
  1378. }
  1379. }
  1380. static void kv_dpm_powergate_vce(struct radeon_device *rdev, bool gate)
  1381. {
  1382. struct kv_power_info *pi = kv_get_pi(rdev);
  1383. if (pi->vce_power_gated == gate)
  1384. return;
  1385. pi->vce_power_gated = gate;
  1386. if (gate) {
  1387. if (pi->caps_vce_pg) {
  1388. /* XXX do we need a vce_v1_0_stop() ? */
  1389. kv_notify_message_to_smu(rdev, PPSMC_MSG_VCEPowerOFF);
  1390. }
  1391. } else {
  1392. if (pi->caps_vce_pg) {
  1393. kv_notify_message_to_smu(rdev, PPSMC_MSG_VCEPowerON);
  1394. vce_v2_0_resume(rdev);
  1395. vce_v1_0_start(rdev);
  1396. }
  1397. }
  1398. }
  1399. static void kv_dpm_powergate_samu(struct radeon_device *rdev, bool gate)
  1400. {
  1401. struct kv_power_info *pi = kv_get_pi(rdev);
  1402. if (pi->samu_power_gated == gate)
  1403. return;
  1404. pi->samu_power_gated = gate;
  1405. if (gate) {
  1406. kv_update_samu_dpm(rdev, true);
  1407. if (pi->caps_samu_pg)
  1408. kv_notify_message_to_smu(rdev, PPSMC_MSG_SAMPowerOFF);
  1409. } else {
  1410. if (pi->caps_samu_pg)
  1411. kv_notify_message_to_smu(rdev, PPSMC_MSG_SAMPowerON);
  1412. kv_update_samu_dpm(rdev, false);
  1413. }
  1414. }
  1415. static void kv_dpm_powergate_acp(struct radeon_device *rdev, bool gate)
  1416. {
  1417. struct kv_power_info *pi = kv_get_pi(rdev);
  1418. if (pi->acp_power_gated == gate)
  1419. return;
  1420. if (rdev->family == CHIP_KABINI || rdev->family == CHIP_MULLINS)
  1421. return;
  1422. pi->acp_power_gated = gate;
  1423. if (gate) {
  1424. kv_update_acp_dpm(rdev, true);
  1425. if (pi->caps_acp_pg)
  1426. kv_notify_message_to_smu(rdev, PPSMC_MSG_ACPPowerOFF);
  1427. } else {
  1428. if (pi->caps_acp_pg)
  1429. kv_notify_message_to_smu(rdev, PPSMC_MSG_ACPPowerON);
  1430. kv_update_acp_dpm(rdev, false);
  1431. }
  1432. }
  1433. static void kv_set_valid_clock_range(struct radeon_device *rdev,
  1434. struct radeon_ps *new_rps)
  1435. {
  1436. struct kv_ps *new_ps = kv_get_ps(new_rps);
  1437. struct kv_power_info *pi = kv_get_pi(rdev);
  1438. u32 i;
  1439. struct radeon_clock_voltage_dependency_table *table =
  1440. &rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
  1441. if (table && table->count) {
  1442. for (i = 0; i < pi->graphics_dpm_level_count; i++) {
  1443. if ((table->entries[i].clk >= new_ps->levels[0].sclk) ||
  1444. (i == (pi->graphics_dpm_level_count - 1))) {
  1445. pi->lowest_valid = i;
  1446. break;
  1447. }
  1448. }
  1449. for (i = pi->graphics_dpm_level_count - 1; i > 0; i--) {
  1450. if (table->entries[i].clk <= new_ps->levels[new_ps->num_levels - 1].sclk)
  1451. break;
  1452. }
  1453. pi->highest_valid = i;
  1454. if (pi->lowest_valid > pi->highest_valid) {
  1455. if ((new_ps->levels[0].sclk - table->entries[pi->highest_valid].clk) >
  1456. (table->entries[pi->lowest_valid].clk - new_ps->levels[new_ps->num_levels - 1].sclk))
  1457. pi->highest_valid = pi->lowest_valid;
  1458. else
  1459. pi->lowest_valid = pi->highest_valid;
  1460. }
  1461. } else {
  1462. struct sumo_sclk_voltage_mapping_table *table =
  1463. &pi->sys_info.sclk_voltage_mapping_table;
  1464. for (i = 0; i < (int)pi->graphics_dpm_level_count; i++) {
  1465. if (table->entries[i].sclk_frequency >= new_ps->levels[0].sclk ||
  1466. i == (int)(pi->graphics_dpm_level_count - 1)) {
  1467. pi->lowest_valid = i;
  1468. break;
  1469. }
  1470. }
  1471. for (i = pi->graphics_dpm_level_count - 1; i > 0; i--) {
  1472. if (table->entries[i].sclk_frequency <=
  1473. new_ps->levels[new_ps->num_levels - 1].sclk)
  1474. break;
  1475. }
  1476. pi->highest_valid = i;
  1477. if (pi->lowest_valid > pi->highest_valid) {
  1478. if ((new_ps->levels[0].sclk -
  1479. table->entries[pi->highest_valid].sclk_frequency) >
  1480. (table->entries[pi->lowest_valid].sclk_frequency -
  1481. new_ps->levels[new_ps->num_levels -1].sclk))
  1482. pi->highest_valid = pi->lowest_valid;
  1483. else
  1484. pi->lowest_valid = pi->highest_valid;
  1485. }
  1486. }
  1487. }
  1488. static int kv_update_dfs_bypass_settings(struct radeon_device *rdev,
  1489. struct radeon_ps *new_rps)
  1490. {
  1491. struct kv_ps *new_ps = kv_get_ps(new_rps);
  1492. struct kv_power_info *pi = kv_get_pi(rdev);
  1493. int ret = 0;
  1494. u8 clk_bypass_cntl;
  1495. if (pi->caps_enable_dfs_bypass) {
  1496. clk_bypass_cntl = new_ps->need_dfs_bypass ?
  1497. pi->graphics_level[pi->graphics_boot_level].ClkBypassCntl : 0;
  1498. ret = kv_copy_bytes_to_smc(rdev,
  1499. (pi->dpm_table_start +
  1500. offsetof(SMU7_Fusion_DpmTable, GraphicsLevel) +
  1501. (pi->graphics_boot_level * sizeof(SMU7_Fusion_GraphicsLevel)) +
  1502. offsetof(SMU7_Fusion_GraphicsLevel, ClkBypassCntl)),
  1503. &clk_bypass_cntl,
  1504. sizeof(u8), pi->sram_end);
  1505. }
  1506. return ret;
  1507. }
  1508. static int kv_enable_nb_dpm(struct radeon_device *rdev,
  1509. bool enable)
  1510. {
  1511. struct kv_power_info *pi = kv_get_pi(rdev);
  1512. int ret = 0;
  1513. if (enable) {
  1514. if (pi->enable_nb_dpm && !pi->nb_dpm_enabled) {
  1515. ret = kv_notify_message_to_smu(rdev, PPSMC_MSG_NBDPM_Enable);
  1516. if (ret == 0)
  1517. pi->nb_dpm_enabled = true;
  1518. }
  1519. } else {
  1520. if (pi->enable_nb_dpm && pi->nb_dpm_enabled) {
  1521. ret = kv_notify_message_to_smu(rdev, PPSMC_MSG_NBDPM_Disable);
  1522. if (ret == 0)
  1523. pi->nb_dpm_enabled = false;
  1524. }
  1525. }
  1526. return ret;
  1527. }
  1528. int kv_dpm_force_performance_level(struct radeon_device *rdev,
  1529. enum radeon_dpm_forced_level level)
  1530. {
  1531. int ret;
  1532. if (level == RADEON_DPM_FORCED_LEVEL_HIGH) {
  1533. ret = kv_force_dpm_highest(rdev);
  1534. if (ret)
  1535. return ret;
  1536. } else if (level == RADEON_DPM_FORCED_LEVEL_LOW) {
  1537. ret = kv_force_dpm_lowest(rdev);
  1538. if (ret)
  1539. return ret;
  1540. } else if (level == RADEON_DPM_FORCED_LEVEL_AUTO) {
  1541. ret = kv_unforce_levels(rdev);
  1542. if (ret)
  1543. return ret;
  1544. }
  1545. rdev->pm.dpm.forced_level = level;
  1546. return 0;
  1547. }
  1548. int kv_dpm_pre_set_power_state(struct radeon_device *rdev)
  1549. {
  1550. struct kv_power_info *pi = kv_get_pi(rdev);
  1551. struct radeon_ps requested_ps = *rdev->pm.dpm.requested_ps;
  1552. struct radeon_ps *new_ps = &requested_ps;
  1553. kv_update_requested_ps(rdev, new_ps);
  1554. kv_apply_state_adjust_rules(rdev,
  1555. &pi->requested_rps,
  1556. &pi->current_rps);
  1557. return 0;
  1558. }
  1559. int kv_dpm_set_power_state(struct radeon_device *rdev)
  1560. {
  1561. struct kv_power_info *pi = kv_get_pi(rdev);
  1562. struct radeon_ps *new_ps = &pi->requested_rps;
  1563. struct radeon_ps *old_ps = &pi->current_rps;
  1564. int ret;
  1565. if (pi->bapm_enable) {
  1566. ret = kv_smc_bapm_enable(rdev, rdev->pm.dpm.ac_power);
  1567. if (ret) {
  1568. DRM_ERROR("kv_smc_bapm_enable failed\n");
  1569. return ret;
  1570. }
  1571. }
  1572. if (rdev->family == CHIP_KABINI || rdev->family == CHIP_MULLINS) {
  1573. if (pi->enable_dpm) {
  1574. kv_set_valid_clock_range(rdev, new_ps);
  1575. kv_update_dfs_bypass_settings(rdev, new_ps);
  1576. ret = kv_calculate_ds_divider(rdev);
  1577. if (ret) {
  1578. DRM_ERROR("kv_calculate_ds_divider failed\n");
  1579. return ret;
  1580. }
  1581. kv_calculate_nbps_level_settings(rdev);
  1582. kv_calculate_dpm_settings(rdev);
  1583. kv_force_lowest_valid(rdev);
  1584. kv_enable_new_levels(rdev);
  1585. kv_upload_dpm_settings(rdev);
  1586. kv_program_nbps_index_settings(rdev, new_ps);
  1587. kv_unforce_levels(rdev);
  1588. kv_set_enabled_levels(rdev);
  1589. kv_force_lowest_valid(rdev);
  1590. kv_unforce_levels(rdev);
  1591. ret = kv_update_vce_dpm(rdev, new_ps, old_ps);
  1592. if (ret) {
  1593. DRM_ERROR("kv_update_vce_dpm failed\n");
  1594. return ret;
  1595. }
  1596. kv_update_sclk_t(rdev);
  1597. if (rdev->family == CHIP_MULLINS)
  1598. kv_enable_nb_dpm(rdev, true);
  1599. }
  1600. } else {
  1601. if (pi->enable_dpm) {
  1602. kv_set_valid_clock_range(rdev, new_ps);
  1603. kv_update_dfs_bypass_settings(rdev, new_ps);
  1604. ret = kv_calculate_ds_divider(rdev);
  1605. if (ret) {
  1606. DRM_ERROR("kv_calculate_ds_divider failed\n");
  1607. return ret;
  1608. }
  1609. kv_calculate_nbps_level_settings(rdev);
  1610. kv_calculate_dpm_settings(rdev);
  1611. kv_freeze_sclk_dpm(rdev, true);
  1612. kv_upload_dpm_settings(rdev);
  1613. kv_program_nbps_index_settings(rdev, new_ps);
  1614. kv_freeze_sclk_dpm(rdev, false);
  1615. kv_set_enabled_levels(rdev);
  1616. ret = kv_update_vce_dpm(rdev, new_ps, old_ps);
  1617. if (ret) {
  1618. DRM_ERROR("kv_update_vce_dpm failed\n");
  1619. return ret;
  1620. }
  1621. kv_update_acp_boot_level(rdev);
  1622. kv_update_sclk_t(rdev);
  1623. kv_enable_nb_dpm(rdev, true);
  1624. }
  1625. }
  1626. return 0;
  1627. }
  1628. void kv_dpm_post_set_power_state(struct radeon_device *rdev)
  1629. {
  1630. struct kv_power_info *pi = kv_get_pi(rdev);
  1631. struct radeon_ps *new_ps = &pi->requested_rps;
  1632. kv_update_current_ps(rdev, new_ps);
  1633. }
  1634. void kv_dpm_setup_asic(struct radeon_device *rdev)
  1635. {
  1636. sumo_take_smu_control(rdev, true);
  1637. kv_init_powergate_state(rdev);
  1638. kv_init_sclk_t(rdev);
  1639. }
  1640. #if 0
  1641. void kv_dpm_reset_asic(struct radeon_device *rdev)
  1642. {
  1643. struct kv_power_info *pi = kv_get_pi(rdev);
  1644. if (rdev->family == CHIP_KABINI || rdev->family == CHIP_MULLINS) {
  1645. kv_force_lowest_valid(rdev);
  1646. kv_init_graphics_levels(rdev);
  1647. kv_program_bootup_state(rdev);
  1648. kv_upload_dpm_settings(rdev);
  1649. kv_force_lowest_valid(rdev);
  1650. kv_unforce_levels(rdev);
  1651. } else {
  1652. kv_init_graphics_levels(rdev);
  1653. kv_program_bootup_state(rdev);
  1654. kv_freeze_sclk_dpm(rdev, true);
  1655. kv_upload_dpm_settings(rdev);
  1656. kv_freeze_sclk_dpm(rdev, false);
  1657. kv_set_enabled_level(rdev, pi->graphics_boot_level);
  1658. }
  1659. }
  1660. #endif
  1661. //XXX use sumo_dpm_display_configuration_changed
  1662. static void kv_construct_max_power_limits_table(struct radeon_device *rdev,
  1663. struct radeon_clock_and_voltage_limits *table)
  1664. {
  1665. struct kv_power_info *pi = kv_get_pi(rdev);
  1666. if (pi->sys_info.sclk_voltage_mapping_table.num_max_dpm_entries > 0) {
  1667. int idx = pi->sys_info.sclk_voltage_mapping_table.num_max_dpm_entries - 1;
  1668. table->sclk =
  1669. pi->sys_info.sclk_voltage_mapping_table.entries[idx].sclk_frequency;
  1670. table->vddc =
  1671. kv_convert_2bit_index_to_voltage(rdev,
  1672. pi->sys_info.sclk_voltage_mapping_table.entries[idx].vid_2bit);
  1673. }
  1674. table->mclk = pi->sys_info.nbp_memory_clock[0];
  1675. }
  1676. static void kv_patch_voltage_values(struct radeon_device *rdev)
  1677. {
  1678. int i;
  1679. struct radeon_uvd_clock_voltage_dependency_table *uvd_table =
  1680. &rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table;
  1681. struct radeon_vce_clock_voltage_dependency_table *vce_table =
  1682. &rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table;
  1683. struct radeon_clock_voltage_dependency_table *samu_table =
  1684. &rdev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table;
  1685. struct radeon_clock_voltage_dependency_table *acp_table =
  1686. &rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table;
  1687. if (uvd_table->count) {
  1688. for (i = 0; i < uvd_table->count; i++)
  1689. uvd_table->entries[i].v =
  1690. kv_convert_8bit_index_to_voltage(rdev,
  1691. uvd_table->entries[i].v);
  1692. }
  1693. if (vce_table->count) {
  1694. for (i = 0; i < vce_table->count; i++)
  1695. vce_table->entries[i].v =
  1696. kv_convert_8bit_index_to_voltage(rdev,
  1697. vce_table->entries[i].v);
  1698. }
  1699. if (samu_table->count) {
  1700. for (i = 0; i < samu_table->count; i++)
  1701. samu_table->entries[i].v =
  1702. kv_convert_8bit_index_to_voltage(rdev,
  1703. samu_table->entries[i].v);
  1704. }
  1705. if (acp_table->count) {
  1706. for (i = 0; i < acp_table->count; i++)
  1707. acp_table->entries[i].v =
  1708. kv_convert_8bit_index_to_voltage(rdev,
  1709. acp_table->entries[i].v);
  1710. }
  1711. }
  1712. static void kv_construct_boot_state(struct radeon_device *rdev)
  1713. {
  1714. struct kv_power_info *pi = kv_get_pi(rdev);
  1715. pi->boot_pl.sclk = pi->sys_info.bootup_sclk;
  1716. pi->boot_pl.vddc_index = pi->sys_info.bootup_nb_voltage_index;
  1717. pi->boot_pl.ds_divider_index = 0;
  1718. pi->boot_pl.ss_divider_index = 0;
  1719. pi->boot_pl.allow_gnb_slow = 1;
  1720. pi->boot_pl.force_nbp_state = 0;
  1721. pi->boot_pl.display_wm = 0;
  1722. pi->boot_pl.vce_wm = 0;
  1723. }
  1724. static int kv_force_dpm_highest(struct radeon_device *rdev)
  1725. {
  1726. int ret;
  1727. u32 enable_mask, i;
  1728. ret = kv_dpm_get_enable_mask(rdev, &enable_mask);
  1729. if (ret)
  1730. return ret;
  1731. for (i = SMU7_MAX_LEVELS_GRAPHICS - 1; i > 0; i--) {
  1732. if (enable_mask & (1 << i))
  1733. break;
  1734. }
  1735. if (rdev->family == CHIP_KABINI || rdev->family == CHIP_MULLINS)
  1736. return kv_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_DPM_ForceState, i);
  1737. else
  1738. return kv_set_enabled_level(rdev, i);
  1739. }
  1740. static int kv_force_dpm_lowest(struct radeon_device *rdev)
  1741. {
  1742. int ret;
  1743. u32 enable_mask, i;
  1744. ret = kv_dpm_get_enable_mask(rdev, &enable_mask);
  1745. if (ret)
  1746. return ret;
  1747. for (i = 0; i < SMU7_MAX_LEVELS_GRAPHICS; i++) {
  1748. if (enable_mask & (1 << i))
  1749. break;
  1750. }
  1751. if (rdev->family == CHIP_KABINI || rdev->family == CHIP_MULLINS)
  1752. return kv_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_DPM_ForceState, i);
  1753. else
  1754. return kv_set_enabled_level(rdev, i);
  1755. }
  1756. static u8 kv_get_sleep_divider_id_from_clock(struct radeon_device *rdev,
  1757. u32 sclk, u32 min_sclk_in_sr)
  1758. {
  1759. struct kv_power_info *pi = kv_get_pi(rdev);
  1760. u32 i;
  1761. u32 temp;
  1762. u32 min = (min_sclk_in_sr > KV_MINIMUM_ENGINE_CLOCK) ?
  1763. min_sclk_in_sr : KV_MINIMUM_ENGINE_CLOCK;
  1764. if (sclk < min)
  1765. return 0;
  1766. if (!pi->caps_sclk_ds)
  1767. return 0;
  1768. for (i = KV_MAX_DEEPSLEEP_DIVIDER_ID; i > 0; i--) {
  1769. temp = sclk / sumo_get_sleep_divider_from_id(i);
  1770. if (temp >= min)
  1771. break;
  1772. }
  1773. return (u8)i;
  1774. }
  1775. static int kv_get_high_voltage_limit(struct radeon_device *rdev, int *limit)
  1776. {
  1777. struct kv_power_info *pi = kv_get_pi(rdev);
  1778. struct radeon_clock_voltage_dependency_table *table =
  1779. &rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
  1780. int i;
  1781. if (table && table->count) {
  1782. for (i = table->count - 1; i >= 0; i--) {
  1783. if (pi->high_voltage_t &&
  1784. (kv_convert_8bit_index_to_voltage(rdev, table->entries[i].v) <=
  1785. pi->high_voltage_t)) {
  1786. *limit = i;
  1787. return 0;
  1788. }
  1789. }
  1790. } else {
  1791. struct sumo_sclk_voltage_mapping_table *table =
  1792. &pi->sys_info.sclk_voltage_mapping_table;
  1793. for (i = table->num_max_dpm_entries - 1; i >= 0; i--) {
  1794. if (pi->high_voltage_t &&
  1795. (kv_convert_2bit_index_to_voltage(rdev, table->entries[i].vid_2bit) <=
  1796. pi->high_voltage_t)) {
  1797. *limit = i;
  1798. return 0;
  1799. }
  1800. }
  1801. }
  1802. *limit = 0;
  1803. return 0;
  1804. }
  1805. static void kv_apply_state_adjust_rules(struct radeon_device *rdev,
  1806. struct radeon_ps *new_rps,
  1807. struct radeon_ps *old_rps)
  1808. {
  1809. struct kv_ps *ps = kv_get_ps(new_rps);
  1810. struct kv_power_info *pi = kv_get_pi(rdev);
  1811. u32 min_sclk = 10000; /* ??? */
  1812. u32 sclk, mclk = 0;
  1813. int i, limit;
  1814. bool force_high;
  1815. struct radeon_clock_voltage_dependency_table *table =
  1816. &rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
  1817. u32 stable_p_state_sclk = 0;
  1818. struct radeon_clock_and_voltage_limits *max_limits =
  1819. &rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac;
  1820. if (new_rps->vce_active) {
  1821. new_rps->evclk = rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].evclk;
  1822. new_rps->ecclk = rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].ecclk;
  1823. } else {
  1824. new_rps->evclk = 0;
  1825. new_rps->ecclk = 0;
  1826. }
  1827. mclk = max_limits->mclk;
  1828. sclk = min_sclk;
  1829. if (pi->caps_stable_p_state) {
  1830. stable_p_state_sclk = (max_limits->sclk * 75) / 100;
  1831. for (i = table->count - 1; i >= 0; i++) {
  1832. if (stable_p_state_sclk >= table->entries[i].clk) {
  1833. stable_p_state_sclk = table->entries[i].clk;
  1834. break;
  1835. }
  1836. }
  1837. if (i > 0)
  1838. stable_p_state_sclk = table->entries[0].clk;
  1839. sclk = stable_p_state_sclk;
  1840. }
  1841. if (new_rps->vce_active) {
  1842. if (sclk < rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].sclk)
  1843. sclk = rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].sclk;
  1844. }
  1845. ps->need_dfs_bypass = true;
  1846. for (i = 0; i < ps->num_levels; i++) {
  1847. if (ps->levels[i].sclk < sclk)
  1848. ps->levels[i].sclk = sclk;
  1849. }
  1850. if (table && table->count) {
  1851. for (i = 0; i < ps->num_levels; i++) {
  1852. if (pi->high_voltage_t &&
  1853. (pi->high_voltage_t <
  1854. kv_convert_8bit_index_to_voltage(rdev, ps->levels[i].vddc_index))) {
  1855. kv_get_high_voltage_limit(rdev, &limit);
  1856. ps->levels[i].sclk = table->entries[limit].clk;
  1857. }
  1858. }
  1859. } else {
  1860. struct sumo_sclk_voltage_mapping_table *table =
  1861. &pi->sys_info.sclk_voltage_mapping_table;
  1862. for (i = 0; i < ps->num_levels; i++) {
  1863. if (pi->high_voltage_t &&
  1864. (pi->high_voltage_t <
  1865. kv_convert_8bit_index_to_voltage(rdev, ps->levels[i].vddc_index))) {
  1866. kv_get_high_voltage_limit(rdev, &limit);
  1867. ps->levels[i].sclk = table->entries[limit].sclk_frequency;
  1868. }
  1869. }
  1870. }
  1871. if (pi->caps_stable_p_state) {
  1872. for (i = 0; i < ps->num_levels; i++) {
  1873. ps->levels[i].sclk = stable_p_state_sclk;
  1874. }
  1875. }
  1876. pi->video_start = new_rps->dclk || new_rps->vclk ||
  1877. new_rps->evclk || new_rps->ecclk;
  1878. if ((new_rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) ==
  1879. ATOM_PPLIB_CLASSIFICATION_UI_BATTERY)
  1880. pi->battery_state = true;
  1881. else
  1882. pi->battery_state = false;
  1883. if (rdev->family == CHIP_KABINI || rdev->family == CHIP_MULLINS) {
  1884. ps->dpm0_pg_nb_ps_lo = 0x1;
  1885. ps->dpm0_pg_nb_ps_hi = 0x0;
  1886. ps->dpmx_nb_ps_lo = 0x1;
  1887. ps->dpmx_nb_ps_hi = 0x0;
  1888. } else {
  1889. ps->dpm0_pg_nb_ps_lo = 0x3;
  1890. ps->dpm0_pg_nb_ps_hi = 0x0;
  1891. ps->dpmx_nb_ps_lo = 0x3;
  1892. ps->dpmx_nb_ps_hi = 0x0;
  1893. if (pi->sys_info.nb_dpm_enable) {
  1894. force_high = (mclk >= pi->sys_info.nbp_memory_clock[3]) ||
  1895. pi->video_start || (rdev->pm.dpm.new_active_crtc_count >= 3) ||
  1896. pi->disable_nb_ps3_in_battery;
  1897. ps->dpm0_pg_nb_ps_lo = force_high ? 0x2 : 0x3;
  1898. ps->dpm0_pg_nb_ps_hi = 0x2;
  1899. ps->dpmx_nb_ps_lo = force_high ? 0x2 : 0x3;
  1900. ps->dpmx_nb_ps_hi = 0x2;
  1901. }
  1902. }
  1903. }
  1904. static void kv_dpm_power_level_enabled_for_throttle(struct radeon_device *rdev,
  1905. u32 index, bool enable)
  1906. {
  1907. struct kv_power_info *pi = kv_get_pi(rdev);
  1908. pi->graphics_level[index].EnabledForThrottle = enable ? 1 : 0;
  1909. }
  1910. static int kv_calculate_ds_divider(struct radeon_device *rdev)
  1911. {
  1912. struct kv_power_info *pi = kv_get_pi(rdev);
  1913. u32 sclk_in_sr = 10000; /* ??? */
  1914. u32 i;
  1915. if (pi->lowest_valid > pi->highest_valid)
  1916. return -EINVAL;
  1917. for (i = pi->lowest_valid; i <= pi->highest_valid; i++) {
  1918. pi->graphics_level[i].DeepSleepDivId =
  1919. kv_get_sleep_divider_id_from_clock(rdev,
  1920. be32_to_cpu(pi->graphics_level[i].SclkFrequency),
  1921. sclk_in_sr);
  1922. }
  1923. return 0;
  1924. }
  1925. static int kv_calculate_nbps_level_settings(struct radeon_device *rdev)
  1926. {
  1927. struct kv_power_info *pi = kv_get_pi(rdev);
  1928. u32 i;
  1929. bool force_high;
  1930. struct radeon_clock_and_voltage_limits *max_limits =
  1931. &rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac;
  1932. u32 mclk = max_limits->mclk;
  1933. if (pi->lowest_valid > pi->highest_valid)
  1934. return -EINVAL;
  1935. if (rdev->family == CHIP_KABINI || rdev->family == CHIP_MULLINS) {
  1936. for (i = pi->lowest_valid; i <= pi->highest_valid; i++) {
  1937. pi->graphics_level[i].GnbSlow = 1;
  1938. pi->graphics_level[i].ForceNbPs1 = 0;
  1939. pi->graphics_level[i].UpH = 0;
  1940. }
  1941. if (!pi->sys_info.nb_dpm_enable)
  1942. return 0;
  1943. force_high = ((mclk >= pi->sys_info.nbp_memory_clock[3]) ||
  1944. (rdev->pm.dpm.new_active_crtc_count >= 3) || pi->video_start);
  1945. if (force_high) {
  1946. for (i = pi->lowest_valid; i <= pi->highest_valid; i++)
  1947. pi->graphics_level[i].GnbSlow = 0;
  1948. } else {
  1949. if (pi->battery_state)
  1950. pi->graphics_level[0].ForceNbPs1 = 1;
  1951. pi->graphics_level[1].GnbSlow = 0;
  1952. pi->graphics_level[2].GnbSlow = 0;
  1953. pi->graphics_level[3].GnbSlow = 0;
  1954. pi->graphics_level[4].GnbSlow = 0;
  1955. }
  1956. } else {
  1957. for (i = pi->lowest_valid; i <= pi->highest_valid; i++) {
  1958. pi->graphics_level[i].GnbSlow = 1;
  1959. pi->graphics_level[i].ForceNbPs1 = 0;
  1960. pi->graphics_level[i].UpH = 0;
  1961. }
  1962. if (pi->sys_info.nb_dpm_enable && pi->battery_state) {
  1963. pi->graphics_level[pi->lowest_valid].UpH = 0x28;
  1964. pi->graphics_level[pi->lowest_valid].GnbSlow = 0;
  1965. if (pi->lowest_valid != pi->highest_valid)
  1966. pi->graphics_level[pi->lowest_valid].ForceNbPs1 = 1;
  1967. }
  1968. }
  1969. return 0;
  1970. }
  1971. static int kv_calculate_dpm_settings(struct radeon_device *rdev)
  1972. {
  1973. struct kv_power_info *pi = kv_get_pi(rdev);
  1974. u32 i;
  1975. if (pi->lowest_valid > pi->highest_valid)
  1976. return -EINVAL;
  1977. for (i = pi->lowest_valid; i <= pi->highest_valid; i++)
  1978. pi->graphics_level[i].DisplayWatermark = (i == pi->highest_valid) ? 1 : 0;
  1979. return 0;
  1980. }
  1981. static void kv_init_graphics_levels(struct radeon_device *rdev)
  1982. {
  1983. struct kv_power_info *pi = kv_get_pi(rdev);
  1984. u32 i;
  1985. struct radeon_clock_voltage_dependency_table *table =
  1986. &rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
  1987. if (table && table->count) {
  1988. u32 vid_2bit;
  1989. pi->graphics_dpm_level_count = 0;
  1990. for (i = 0; i < table->count; i++) {
  1991. if (pi->high_voltage_t &&
  1992. (pi->high_voltage_t <
  1993. kv_convert_8bit_index_to_voltage(rdev, table->entries[i].v)))
  1994. break;
  1995. kv_set_divider_value(rdev, i, table->entries[i].clk);
  1996. vid_2bit = kv_convert_vid7_to_vid2(rdev,
  1997. &pi->sys_info.vid_mapping_table,
  1998. table->entries[i].v);
  1999. kv_set_vid(rdev, i, vid_2bit);
  2000. kv_set_at(rdev, i, pi->at[i]);
  2001. kv_dpm_power_level_enabled_for_throttle(rdev, i, true);
  2002. pi->graphics_dpm_level_count++;
  2003. }
  2004. } else {
  2005. struct sumo_sclk_voltage_mapping_table *table =
  2006. &pi->sys_info.sclk_voltage_mapping_table;
  2007. pi->graphics_dpm_level_count = 0;
  2008. for (i = 0; i < table->num_max_dpm_entries; i++) {
  2009. if (pi->high_voltage_t &&
  2010. pi->high_voltage_t <
  2011. kv_convert_2bit_index_to_voltage(rdev, table->entries[i].vid_2bit))
  2012. break;
  2013. kv_set_divider_value(rdev, i, table->entries[i].sclk_frequency);
  2014. kv_set_vid(rdev, i, table->entries[i].vid_2bit);
  2015. kv_set_at(rdev, i, pi->at[i]);
  2016. kv_dpm_power_level_enabled_for_throttle(rdev, i, true);
  2017. pi->graphics_dpm_level_count++;
  2018. }
  2019. }
  2020. for (i = 0; i < SMU7_MAX_LEVELS_GRAPHICS; i++)
  2021. kv_dpm_power_level_enable(rdev, i, false);
  2022. }
  2023. static void kv_enable_new_levels(struct radeon_device *rdev)
  2024. {
  2025. struct kv_power_info *pi = kv_get_pi(rdev);
  2026. u32 i;
  2027. for (i = 0; i < SMU7_MAX_LEVELS_GRAPHICS; i++) {
  2028. if (i >= pi->lowest_valid && i <= pi->highest_valid)
  2029. kv_dpm_power_level_enable(rdev, i, true);
  2030. }
  2031. }
  2032. static int kv_set_enabled_level(struct radeon_device *rdev, u32 level)
  2033. {
  2034. u32 new_mask = (1 << level);
  2035. return kv_send_msg_to_smc_with_parameter(rdev,
  2036. PPSMC_MSG_SCLKDPM_SetEnabledMask,
  2037. new_mask);
  2038. }
  2039. static int kv_set_enabled_levels(struct radeon_device *rdev)
  2040. {
  2041. struct kv_power_info *pi = kv_get_pi(rdev);
  2042. u32 i, new_mask = 0;
  2043. for (i = pi->lowest_valid; i <= pi->highest_valid; i++)
  2044. new_mask |= (1 << i);
  2045. return kv_send_msg_to_smc_with_parameter(rdev,
  2046. PPSMC_MSG_SCLKDPM_SetEnabledMask,
  2047. new_mask);
  2048. }
  2049. static void kv_program_nbps_index_settings(struct radeon_device *rdev,
  2050. struct radeon_ps *new_rps)
  2051. {
  2052. struct kv_ps *new_ps = kv_get_ps(new_rps);
  2053. struct kv_power_info *pi = kv_get_pi(rdev);
  2054. u32 nbdpmconfig1;
  2055. if (rdev->family == CHIP_KABINI || rdev->family == CHIP_MULLINS)
  2056. return;
  2057. if (pi->sys_info.nb_dpm_enable) {
  2058. nbdpmconfig1 = RREG32_SMC(NB_DPM_CONFIG_1);
  2059. nbdpmconfig1 &= ~(Dpm0PgNbPsLo_MASK | Dpm0PgNbPsHi_MASK |
  2060. DpmXNbPsLo_MASK | DpmXNbPsHi_MASK);
  2061. nbdpmconfig1 |= (Dpm0PgNbPsLo(new_ps->dpm0_pg_nb_ps_lo) |
  2062. Dpm0PgNbPsHi(new_ps->dpm0_pg_nb_ps_hi) |
  2063. DpmXNbPsLo(new_ps->dpmx_nb_ps_lo) |
  2064. DpmXNbPsHi(new_ps->dpmx_nb_ps_hi));
  2065. WREG32_SMC(NB_DPM_CONFIG_1, nbdpmconfig1);
  2066. }
  2067. }
  2068. static int kv_set_thermal_temperature_range(struct radeon_device *rdev,
  2069. int min_temp, int max_temp)
  2070. {
  2071. int low_temp = 0 * 1000;
  2072. int high_temp = 255 * 1000;
  2073. u32 tmp;
  2074. if (low_temp < min_temp)
  2075. low_temp = min_temp;
  2076. if (high_temp > max_temp)
  2077. high_temp = max_temp;
  2078. if (high_temp < low_temp) {
  2079. DRM_ERROR("invalid thermal range: %d - %d\n", low_temp, high_temp);
  2080. return -EINVAL;
  2081. }
  2082. tmp = RREG32_SMC(CG_THERMAL_INT_CTRL);
  2083. tmp &= ~(DIG_THERM_INTH_MASK | DIG_THERM_INTL_MASK);
  2084. tmp |= (DIG_THERM_INTH(49 + (high_temp / 1000)) |
  2085. DIG_THERM_INTL(49 + (low_temp / 1000)));
  2086. WREG32_SMC(CG_THERMAL_INT_CTRL, tmp);
  2087. rdev->pm.dpm.thermal.min_temp = low_temp;
  2088. rdev->pm.dpm.thermal.max_temp = high_temp;
  2089. return 0;
  2090. }
  2091. union igp_info {
  2092. struct _ATOM_INTEGRATED_SYSTEM_INFO info;
  2093. struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
  2094. struct _ATOM_INTEGRATED_SYSTEM_INFO_V5 info_5;
  2095. struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 info_6;
  2096. struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_7 info_7;
  2097. struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_8 info_8;
  2098. };
  2099. static int kv_parse_sys_info_table(struct radeon_device *rdev)
  2100. {
  2101. struct kv_power_info *pi = kv_get_pi(rdev);
  2102. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2103. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  2104. union igp_info *igp_info;
  2105. u8 frev, crev;
  2106. u16 data_offset;
  2107. int i;
  2108. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  2109. &frev, &crev, &data_offset)) {
  2110. igp_info = (union igp_info *)(mode_info->atom_context->bios +
  2111. data_offset);
  2112. if (crev != 8) {
  2113. DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
  2114. return -EINVAL;
  2115. }
  2116. pi->sys_info.bootup_sclk = le32_to_cpu(igp_info->info_8.ulBootUpEngineClock);
  2117. pi->sys_info.bootup_uma_clk = le32_to_cpu(igp_info->info_8.ulBootUpUMAClock);
  2118. pi->sys_info.bootup_nb_voltage_index =
  2119. le16_to_cpu(igp_info->info_8.usBootUpNBVoltage);
  2120. if (igp_info->info_8.ucHtcTmpLmt == 0)
  2121. pi->sys_info.htc_tmp_lmt = 203;
  2122. else
  2123. pi->sys_info.htc_tmp_lmt = igp_info->info_8.ucHtcTmpLmt;
  2124. if (igp_info->info_8.ucHtcHystLmt == 0)
  2125. pi->sys_info.htc_hyst_lmt = 5;
  2126. else
  2127. pi->sys_info.htc_hyst_lmt = igp_info->info_8.ucHtcHystLmt;
  2128. if (pi->sys_info.htc_tmp_lmt <= pi->sys_info.htc_hyst_lmt) {
  2129. DRM_ERROR("The htcTmpLmt should be larger than htcHystLmt.\n");
  2130. }
  2131. if (le32_to_cpu(igp_info->info_8.ulSystemConfig) & (1 << 3))
  2132. pi->sys_info.nb_dpm_enable = true;
  2133. else
  2134. pi->sys_info.nb_dpm_enable = false;
  2135. for (i = 0; i < KV_NUM_NBPSTATES; i++) {
  2136. pi->sys_info.nbp_memory_clock[i] =
  2137. le32_to_cpu(igp_info->info_8.ulNbpStateMemclkFreq[i]);
  2138. pi->sys_info.nbp_n_clock[i] =
  2139. le32_to_cpu(igp_info->info_8.ulNbpStateNClkFreq[i]);
  2140. }
  2141. if (le32_to_cpu(igp_info->info_8.ulGPUCapInfo) &
  2142. SYS_INFO_GPUCAPS__ENABEL_DFS_BYPASS)
  2143. pi->caps_enable_dfs_bypass = true;
  2144. sumo_construct_sclk_voltage_mapping_table(rdev,
  2145. &pi->sys_info.sclk_voltage_mapping_table,
  2146. igp_info->info_8.sAvail_SCLK);
  2147. sumo_construct_vid_mapping_table(rdev,
  2148. &pi->sys_info.vid_mapping_table,
  2149. igp_info->info_8.sAvail_SCLK);
  2150. kv_construct_max_power_limits_table(rdev,
  2151. &rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac);
  2152. }
  2153. return 0;
  2154. }
  2155. union power_info {
  2156. struct _ATOM_POWERPLAY_INFO info;
  2157. struct _ATOM_POWERPLAY_INFO_V2 info_2;
  2158. struct _ATOM_POWERPLAY_INFO_V3 info_3;
  2159. struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
  2160. struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
  2161. struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
  2162. };
  2163. union pplib_clock_info {
  2164. struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
  2165. struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
  2166. struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
  2167. struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
  2168. };
  2169. union pplib_power_state {
  2170. struct _ATOM_PPLIB_STATE v1;
  2171. struct _ATOM_PPLIB_STATE_V2 v2;
  2172. };
  2173. static void kv_patch_boot_state(struct radeon_device *rdev,
  2174. struct kv_ps *ps)
  2175. {
  2176. struct kv_power_info *pi = kv_get_pi(rdev);
  2177. ps->num_levels = 1;
  2178. ps->levels[0] = pi->boot_pl;
  2179. }
  2180. static void kv_parse_pplib_non_clock_info(struct radeon_device *rdev,
  2181. struct radeon_ps *rps,
  2182. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info,
  2183. u8 table_rev)
  2184. {
  2185. struct kv_ps *ps = kv_get_ps(rps);
  2186. rps->caps = le32_to_cpu(non_clock_info->ulCapsAndSettings);
  2187. rps->class = le16_to_cpu(non_clock_info->usClassification);
  2188. rps->class2 = le16_to_cpu(non_clock_info->usClassification2);
  2189. if (ATOM_PPLIB_NONCLOCKINFO_VER1 < table_rev) {
  2190. rps->vclk = le32_to_cpu(non_clock_info->ulVCLK);
  2191. rps->dclk = le32_to_cpu(non_clock_info->ulDCLK);
  2192. } else {
  2193. rps->vclk = 0;
  2194. rps->dclk = 0;
  2195. }
  2196. if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT) {
  2197. rdev->pm.dpm.boot_ps = rps;
  2198. kv_patch_boot_state(rdev, ps);
  2199. }
  2200. if (rps->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE)
  2201. rdev->pm.dpm.uvd_ps = rps;
  2202. }
  2203. static void kv_parse_pplib_clock_info(struct radeon_device *rdev,
  2204. struct radeon_ps *rps, int index,
  2205. union pplib_clock_info *clock_info)
  2206. {
  2207. struct kv_power_info *pi = kv_get_pi(rdev);
  2208. struct kv_ps *ps = kv_get_ps(rps);
  2209. struct kv_pl *pl = &ps->levels[index];
  2210. u32 sclk;
  2211. sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
  2212. sclk |= clock_info->sumo.ucEngineClockHigh << 16;
  2213. pl->sclk = sclk;
  2214. pl->vddc_index = clock_info->sumo.vddcIndex;
  2215. ps->num_levels = index + 1;
  2216. if (pi->caps_sclk_ds) {
  2217. pl->ds_divider_index = 5;
  2218. pl->ss_divider_index = 5;
  2219. }
  2220. }
  2221. static int kv_parse_power_table(struct radeon_device *rdev)
  2222. {
  2223. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2224. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
  2225. union pplib_power_state *power_state;
  2226. int i, j, k, non_clock_array_index, clock_array_index;
  2227. union pplib_clock_info *clock_info;
  2228. struct _StateArray *state_array;
  2229. struct _ClockInfoArray *clock_info_array;
  2230. struct _NonClockInfoArray *non_clock_info_array;
  2231. union power_info *power_info;
  2232. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  2233. u16 data_offset;
  2234. u8 frev, crev;
  2235. u8 *power_state_offset;
  2236. struct kv_ps *ps;
  2237. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  2238. &frev, &crev, &data_offset))
  2239. return -EINVAL;
  2240. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  2241. state_array = (struct _StateArray *)
  2242. (mode_info->atom_context->bios + data_offset +
  2243. le16_to_cpu(power_info->pplib.usStateArrayOffset));
  2244. clock_info_array = (struct _ClockInfoArray *)
  2245. (mode_info->atom_context->bios + data_offset +
  2246. le16_to_cpu(power_info->pplib.usClockInfoArrayOffset));
  2247. non_clock_info_array = (struct _NonClockInfoArray *)
  2248. (mode_info->atom_context->bios + data_offset +
  2249. le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset));
  2250. rdev->pm.dpm.ps = kzalloc(sizeof(struct radeon_ps) *
  2251. state_array->ucNumEntries, GFP_KERNEL);
  2252. if (!rdev->pm.dpm.ps)
  2253. return -ENOMEM;
  2254. power_state_offset = (u8 *)state_array->states;
  2255. for (i = 0; i < state_array->ucNumEntries; i++) {
  2256. u8 *idx;
  2257. power_state = (union pplib_power_state *)power_state_offset;
  2258. non_clock_array_index = power_state->v2.nonClockInfoIndex;
  2259. non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
  2260. &non_clock_info_array->nonClockInfo[non_clock_array_index];
  2261. if (!rdev->pm.power_state[i].clock_info)
  2262. return -EINVAL;
  2263. ps = kzalloc(sizeof(struct kv_ps), GFP_KERNEL);
  2264. if (ps == NULL) {
  2265. kfree(rdev->pm.dpm.ps);
  2266. return -ENOMEM;
  2267. }
  2268. rdev->pm.dpm.ps[i].ps_priv = ps;
  2269. k = 0;
  2270. idx = (u8 *)&power_state->v2.clockInfoIndex[0];
  2271. for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
  2272. clock_array_index = idx[j];
  2273. if (clock_array_index >= clock_info_array->ucNumEntries)
  2274. continue;
  2275. if (k >= SUMO_MAX_HARDWARE_POWERLEVELS)
  2276. break;
  2277. clock_info = (union pplib_clock_info *)
  2278. ((u8 *)&clock_info_array->clockInfo[0] +
  2279. (clock_array_index * clock_info_array->ucEntrySize));
  2280. kv_parse_pplib_clock_info(rdev,
  2281. &rdev->pm.dpm.ps[i], k,
  2282. clock_info);
  2283. k++;
  2284. }
  2285. kv_parse_pplib_non_clock_info(rdev, &rdev->pm.dpm.ps[i],
  2286. non_clock_info,
  2287. non_clock_info_array->ucEntrySize);
  2288. power_state_offset += 2 + power_state->v2.ucNumDPMLevels;
  2289. }
  2290. rdev->pm.dpm.num_ps = state_array->ucNumEntries;
  2291. /* fill in the vce power states */
  2292. for (i = 0; i < RADEON_MAX_VCE_LEVELS; i++) {
  2293. u32 sclk;
  2294. clock_array_index = rdev->pm.dpm.vce_states[i].clk_idx;
  2295. clock_info = (union pplib_clock_info *)
  2296. &clock_info_array->clockInfo[clock_array_index * clock_info_array->ucEntrySize];
  2297. sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
  2298. sclk |= clock_info->sumo.ucEngineClockHigh << 16;
  2299. rdev->pm.dpm.vce_states[i].sclk = sclk;
  2300. rdev->pm.dpm.vce_states[i].mclk = 0;
  2301. }
  2302. return 0;
  2303. }
  2304. int kv_dpm_init(struct radeon_device *rdev)
  2305. {
  2306. struct kv_power_info *pi;
  2307. int ret, i;
  2308. pi = kzalloc(sizeof(struct kv_power_info), GFP_KERNEL);
  2309. if (pi == NULL)
  2310. return -ENOMEM;
  2311. rdev->pm.dpm.priv = pi;
  2312. ret = r600_get_platform_caps(rdev);
  2313. if (ret)
  2314. return ret;
  2315. ret = r600_parse_extended_power_table(rdev);
  2316. if (ret)
  2317. return ret;
  2318. for (i = 0; i < SUMO_MAX_HARDWARE_POWERLEVELS; i++)
  2319. pi->at[i] = TRINITY_AT_DFLT;
  2320. pi->sram_end = SMC_RAM_END;
  2321. /* Enabling nb dpm on an asrock system prevents dpm from working */
  2322. if (rdev->pdev->subsystem_vendor == 0x1849)
  2323. pi->enable_nb_dpm = false;
  2324. else
  2325. pi->enable_nb_dpm = true;
  2326. pi->caps_power_containment = true;
  2327. pi->caps_cac = true;
  2328. pi->enable_didt = false;
  2329. if (pi->enable_didt) {
  2330. pi->caps_sq_ramping = true;
  2331. pi->caps_db_ramping = true;
  2332. pi->caps_td_ramping = true;
  2333. pi->caps_tcp_ramping = true;
  2334. }
  2335. pi->caps_sclk_ds = true;
  2336. pi->enable_auto_thermal_throttling = true;
  2337. pi->disable_nb_ps3_in_battery = false;
  2338. if (radeon_bapm == -1) {
  2339. /* only enable bapm on KB, ML by default */
  2340. if (rdev->family == CHIP_KABINI || rdev->family == CHIP_MULLINS)
  2341. pi->bapm_enable = true;
  2342. else
  2343. pi->bapm_enable = false;
  2344. } else if (radeon_bapm == 0) {
  2345. pi->bapm_enable = false;
  2346. } else {
  2347. pi->bapm_enable = true;
  2348. }
  2349. pi->voltage_drop_t = 0;
  2350. pi->caps_sclk_throttle_low_notification = false;
  2351. pi->caps_fps = false; /* true? */
  2352. pi->caps_uvd_pg = true;
  2353. pi->caps_uvd_dpm = true;
  2354. pi->caps_vce_pg = false; /* XXX true */
  2355. pi->caps_samu_pg = false;
  2356. pi->caps_acp_pg = false;
  2357. pi->caps_stable_p_state = false;
  2358. ret = kv_parse_sys_info_table(rdev);
  2359. if (ret)
  2360. return ret;
  2361. kv_patch_voltage_values(rdev);
  2362. kv_construct_boot_state(rdev);
  2363. ret = kv_parse_power_table(rdev);
  2364. if (ret)
  2365. return ret;
  2366. pi->enable_dpm = true;
  2367. return 0;
  2368. }
  2369. void kv_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev,
  2370. struct seq_file *m)
  2371. {
  2372. struct kv_power_info *pi = kv_get_pi(rdev);
  2373. u32 current_index =
  2374. (RREG32_SMC(TARGET_AND_CURRENT_PROFILE_INDEX) & CURR_SCLK_INDEX_MASK) >>
  2375. CURR_SCLK_INDEX_SHIFT;
  2376. u32 sclk, tmp;
  2377. u16 vddc;
  2378. if (current_index >= SMU__NUM_SCLK_DPM_STATE) {
  2379. seq_printf(m, "invalid dpm profile %d\n", current_index);
  2380. } else {
  2381. sclk = be32_to_cpu(pi->graphics_level[current_index].SclkFrequency);
  2382. tmp = (RREG32_SMC(SMU_VOLTAGE_STATUS) & SMU_VOLTAGE_CURRENT_LEVEL_MASK) >>
  2383. SMU_VOLTAGE_CURRENT_LEVEL_SHIFT;
  2384. vddc = kv_convert_8bit_index_to_voltage(rdev, (u16)tmp);
  2385. seq_printf(m, "uvd %sabled\n", pi->uvd_power_gated ? "dis" : "en");
  2386. seq_printf(m, "vce %sabled\n", pi->vce_power_gated ? "dis" : "en");
  2387. seq_printf(m, "power level %d sclk: %u vddc: %u\n",
  2388. current_index, sclk, vddc);
  2389. }
  2390. }
  2391. u32 kv_dpm_get_current_sclk(struct radeon_device *rdev)
  2392. {
  2393. struct kv_power_info *pi = kv_get_pi(rdev);
  2394. u32 current_index =
  2395. (RREG32_SMC(TARGET_AND_CURRENT_PROFILE_INDEX) & CURR_SCLK_INDEX_MASK) >>
  2396. CURR_SCLK_INDEX_SHIFT;
  2397. u32 sclk;
  2398. if (current_index >= SMU__NUM_SCLK_DPM_STATE) {
  2399. return 0;
  2400. } else {
  2401. sclk = be32_to_cpu(pi->graphics_level[current_index].SclkFrequency);
  2402. return sclk;
  2403. }
  2404. }
  2405. u32 kv_dpm_get_current_mclk(struct radeon_device *rdev)
  2406. {
  2407. struct kv_power_info *pi = kv_get_pi(rdev);
  2408. return pi->sys_info.bootup_uma_clk;
  2409. }
  2410. void kv_dpm_print_power_state(struct radeon_device *rdev,
  2411. struct radeon_ps *rps)
  2412. {
  2413. int i;
  2414. struct kv_ps *ps = kv_get_ps(rps);
  2415. r600_dpm_print_class_info(rps->class, rps->class2);
  2416. r600_dpm_print_cap_info(rps->caps);
  2417. printk("\tuvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
  2418. for (i = 0; i < ps->num_levels; i++) {
  2419. struct kv_pl *pl = &ps->levels[i];
  2420. printk("\t\tpower level %d sclk: %u vddc: %u\n",
  2421. i, pl->sclk,
  2422. kv_convert_8bit_index_to_voltage(rdev, pl->vddc_index));
  2423. }
  2424. r600_dpm_print_ps_status(rdev, rps);
  2425. }
  2426. void kv_dpm_fini(struct radeon_device *rdev)
  2427. {
  2428. int i;
  2429. for (i = 0; i < rdev->pm.dpm.num_ps; i++) {
  2430. kfree(rdev->pm.dpm.ps[i].ps_priv);
  2431. }
  2432. kfree(rdev->pm.dpm.ps);
  2433. kfree(rdev->pm.dpm.priv);
  2434. r600_free_extended_power_table(rdev);
  2435. }
  2436. void kv_dpm_display_configuration_changed(struct radeon_device *rdev)
  2437. {
  2438. }
  2439. u32 kv_dpm_get_sclk(struct radeon_device *rdev, bool low)
  2440. {
  2441. struct kv_power_info *pi = kv_get_pi(rdev);
  2442. struct kv_ps *requested_state = kv_get_ps(&pi->requested_rps);
  2443. if (low)
  2444. return requested_state->levels[0].sclk;
  2445. else
  2446. return requested_state->levels[requested_state->num_levels - 1].sclk;
  2447. }
  2448. u32 kv_dpm_get_mclk(struct radeon_device *rdev, bool low)
  2449. {
  2450. struct kv_power_info *pi = kv_get_pi(rdev);
  2451. return pi->sys_info.bootup_uma_clk;
  2452. }