trinity_dpm.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104
  1. /*
  2. * Copyright 2012 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 "radeon_asic.h"
  26. #include "trinityd.h"
  27. #include "r600_dpm.h"
  28. #include "trinity_dpm.h"
  29. #include <linux/seq_file.h>
  30. #define TRINITY_MAX_DEEPSLEEP_DIVIDER_ID 5
  31. #define TRINITY_MINIMUM_ENGINE_CLOCK 800
  32. #define SCLK_MIN_DIV_INTV_SHIFT 12
  33. #define TRINITY_DISPCLK_BYPASS_THRESHOLD 10000
  34. #ifndef TRINITY_MGCG_SEQUENCE
  35. #define TRINITY_MGCG_SEQUENCE 100
  36. static const u32 trinity_mgcg_shls_default[] =
  37. {
  38. /* Register, Value, Mask */
  39. 0x0000802c, 0xc0000000, 0xffffffff,
  40. 0x00003fc4, 0xc0000000, 0xffffffff,
  41. 0x00005448, 0x00000100, 0xffffffff,
  42. 0x000055e4, 0x00000100, 0xffffffff,
  43. 0x0000160c, 0x00000100, 0xffffffff,
  44. 0x00008984, 0x06000100, 0xffffffff,
  45. 0x0000c164, 0x00000100, 0xffffffff,
  46. 0x00008a18, 0x00000100, 0xffffffff,
  47. 0x0000897c, 0x06000100, 0xffffffff,
  48. 0x00008b28, 0x00000100, 0xffffffff,
  49. 0x00009144, 0x00800200, 0xffffffff,
  50. 0x00009a60, 0x00000100, 0xffffffff,
  51. 0x00009868, 0x00000100, 0xffffffff,
  52. 0x00008d58, 0x00000100, 0xffffffff,
  53. 0x00009510, 0x00000100, 0xffffffff,
  54. 0x0000949c, 0x00000100, 0xffffffff,
  55. 0x00009654, 0x00000100, 0xffffffff,
  56. 0x00009030, 0x00000100, 0xffffffff,
  57. 0x00009034, 0x00000100, 0xffffffff,
  58. 0x00009038, 0x00000100, 0xffffffff,
  59. 0x0000903c, 0x00000100, 0xffffffff,
  60. 0x00009040, 0x00000100, 0xffffffff,
  61. 0x0000a200, 0x00000100, 0xffffffff,
  62. 0x0000a204, 0x00000100, 0xffffffff,
  63. 0x0000a208, 0x00000100, 0xffffffff,
  64. 0x0000a20c, 0x00000100, 0xffffffff,
  65. 0x00009744, 0x00000100, 0xffffffff,
  66. 0x00003f80, 0x00000100, 0xffffffff,
  67. 0x0000a210, 0x00000100, 0xffffffff,
  68. 0x0000a214, 0x00000100, 0xffffffff,
  69. 0x000004d8, 0x00000100, 0xffffffff,
  70. 0x00009664, 0x00000100, 0xffffffff,
  71. 0x00009698, 0x00000100, 0xffffffff,
  72. 0x000004d4, 0x00000200, 0xffffffff,
  73. 0x000004d0, 0x00000000, 0xffffffff,
  74. 0x000030cc, 0x00000104, 0xffffffff,
  75. 0x0000d0c0, 0x00000100, 0xffffffff,
  76. 0x0000d8c0, 0x00000100, 0xffffffff,
  77. 0x0000951c, 0x00010000, 0xffffffff,
  78. 0x00009160, 0x00030002, 0xffffffff,
  79. 0x00009164, 0x00050004, 0xffffffff,
  80. 0x00009168, 0x00070006, 0xffffffff,
  81. 0x00009178, 0x00070000, 0xffffffff,
  82. 0x0000917c, 0x00030002, 0xffffffff,
  83. 0x00009180, 0x00050004, 0xffffffff,
  84. 0x0000918c, 0x00010006, 0xffffffff,
  85. 0x00009190, 0x00090008, 0xffffffff,
  86. 0x00009194, 0x00070000, 0xffffffff,
  87. 0x00009198, 0x00030002, 0xffffffff,
  88. 0x0000919c, 0x00050004, 0xffffffff,
  89. 0x000091a8, 0x00010006, 0xffffffff,
  90. 0x000091ac, 0x00090008, 0xffffffff,
  91. 0x000091b0, 0x00070000, 0xffffffff,
  92. 0x000091b4, 0x00030002, 0xffffffff,
  93. 0x000091b8, 0x00050004, 0xffffffff,
  94. 0x000091c4, 0x00010006, 0xffffffff,
  95. 0x000091c8, 0x00090008, 0xffffffff,
  96. 0x000091cc, 0x00070000, 0xffffffff,
  97. 0x000091d0, 0x00030002, 0xffffffff,
  98. 0x000091d4, 0x00050004, 0xffffffff,
  99. 0x000091e0, 0x00010006, 0xffffffff,
  100. 0x000091e4, 0x00090008, 0xffffffff,
  101. 0x000091e8, 0x00000000, 0xffffffff,
  102. 0x000091ec, 0x00070000, 0xffffffff,
  103. 0x000091f0, 0x00030002, 0xffffffff,
  104. 0x000091f4, 0x00050004, 0xffffffff,
  105. 0x00009200, 0x00010006, 0xffffffff,
  106. 0x00009204, 0x00090008, 0xffffffff,
  107. 0x00009208, 0x00070000, 0xffffffff,
  108. 0x0000920c, 0x00030002, 0xffffffff,
  109. 0x00009210, 0x00050004, 0xffffffff,
  110. 0x0000921c, 0x00010006, 0xffffffff,
  111. 0x00009220, 0x00090008, 0xffffffff,
  112. 0x00009294, 0x00000000, 0xffffffff
  113. };
  114. static const u32 trinity_mgcg_shls_enable[] =
  115. {
  116. /* Register, Value, Mask */
  117. 0x0000802c, 0xc0000000, 0xffffffff,
  118. 0x000008f8, 0x00000000, 0xffffffff,
  119. 0x000008fc, 0x00000000, 0x000133FF,
  120. 0x000008f8, 0x00000001, 0xffffffff,
  121. 0x000008fc, 0x00000000, 0xE00B03FC,
  122. 0x00009150, 0x96944200, 0xffffffff
  123. };
  124. static const u32 trinity_mgcg_shls_disable[] =
  125. {
  126. /* Register, Value, Mask */
  127. 0x0000802c, 0xc0000000, 0xffffffff,
  128. 0x00009150, 0x00600000, 0xffffffff,
  129. 0x000008f8, 0x00000000, 0xffffffff,
  130. 0x000008fc, 0xffffffff, 0x000133FF,
  131. 0x000008f8, 0x00000001, 0xffffffff,
  132. 0x000008fc, 0xffffffff, 0xE00B03FC
  133. };
  134. #endif
  135. #ifndef TRINITY_SYSLS_SEQUENCE
  136. #define TRINITY_SYSLS_SEQUENCE 100
  137. static const u32 trinity_sysls_default[] =
  138. {
  139. /* Register, Value, Mask */
  140. 0x000055e8, 0x00000000, 0xffffffff,
  141. 0x0000d0bc, 0x00000000, 0xffffffff,
  142. 0x0000d8bc, 0x00000000, 0xffffffff,
  143. 0x000015c0, 0x000c1401, 0xffffffff,
  144. 0x0000264c, 0x000c0400, 0xffffffff,
  145. 0x00002648, 0x000c0400, 0xffffffff,
  146. 0x00002650, 0x000c0400, 0xffffffff,
  147. 0x000020b8, 0x000c0400, 0xffffffff,
  148. 0x000020bc, 0x000c0400, 0xffffffff,
  149. 0x000020c0, 0x000c0c80, 0xffffffff,
  150. 0x0000f4a0, 0x000000c0, 0xffffffff,
  151. 0x0000f4a4, 0x00680fff, 0xffffffff,
  152. 0x00002f50, 0x00000404, 0xffffffff,
  153. 0x000004c8, 0x00000001, 0xffffffff,
  154. 0x0000641c, 0x00000000, 0xffffffff,
  155. 0x00000c7c, 0x00000000, 0xffffffff,
  156. 0x00006dfc, 0x00000000, 0xffffffff
  157. };
  158. static const u32 trinity_sysls_disable[] =
  159. {
  160. /* Register, Value, Mask */
  161. 0x0000d0c0, 0x00000000, 0xffffffff,
  162. 0x0000d8c0, 0x00000000, 0xffffffff,
  163. 0x000055e8, 0x00000000, 0xffffffff,
  164. 0x0000d0bc, 0x00000000, 0xffffffff,
  165. 0x0000d8bc, 0x00000000, 0xffffffff,
  166. 0x000015c0, 0x00041401, 0xffffffff,
  167. 0x0000264c, 0x00040400, 0xffffffff,
  168. 0x00002648, 0x00040400, 0xffffffff,
  169. 0x00002650, 0x00040400, 0xffffffff,
  170. 0x000020b8, 0x00040400, 0xffffffff,
  171. 0x000020bc, 0x00040400, 0xffffffff,
  172. 0x000020c0, 0x00040c80, 0xffffffff,
  173. 0x0000f4a0, 0x000000c0, 0xffffffff,
  174. 0x0000f4a4, 0x00680000, 0xffffffff,
  175. 0x00002f50, 0x00000404, 0xffffffff,
  176. 0x000004c8, 0x00000001, 0xffffffff,
  177. 0x0000641c, 0x00007ffd, 0xffffffff,
  178. 0x00000c7c, 0x0000ff00, 0xffffffff,
  179. 0x00006dfc, 0x0000007f, 0xffffffff
  180. };
  181. static const u32 trinity_sysls_enable[] =
  182. {
  183. /* Register, Value, Mask */
  184. 0x000055e8, 0x00000001, 0xffffffff,
  185. 0x0000d0bc, 0x00000100, 0xffffffff,
  186. 0x0000d8bc, 0x00000100, 0xffffffff,
  187. 0x000015c0, 0x000c1401, 0xffffffff,
  188. 0x0000264c, 0x000c0400, 0xffffffff,
  189. 0x00002648, 0x000c0400, 0xffffffff,
  190. 0x00002650, 0x000c0400, 0xffffffff,
  191. 0x000020b8, 0x000c0400, 0xffffffff,
  192. 0x000020bc, 0x000c0400, 0xffffffff,
  193. 0x000020c0, 0x000c0c80, 0xffffffff,
  194. 0x0000f4a0, 0x000000c0, 0xffffffff,
  195. 0x0000f4a4, 0x00680fff, 0xffffffff,
  196. 0x00002f50, 0x00000903, 0xffffffff,
  197. 0x000004c8, 0x00000000, 0xffffffff,
  198. 0x0000641c, 0x00000000, 0xffffffff,
  199. 0x00000c7c, 0x00000000, 0xffffffff,
  200. 0x00006dfc, 0x00000000, 0xffffffff
  201. };
  202. #endif
  203. static const u32 trinity_override_mgpg_sequences[] =
  204. {
  205. /* Register, Value */
  206. 0x00000200, 0xE030032C,
  207. 0x00000204, 0x00000FFF,
  208. 0x00000200, 0xE0300058,
  209. 0x00000204, 0x00030301,
  210. 0x00000200, 0xE0300054,
  211. 0x00000204, 0x500010FF,
  212. 0x00000200, 0xE0300074,
  213. 0x00000204, 0x00030301,
  214. 0x00000200, 0xE0300070,
  215. 0x00000204, 0x500010FF,
  216. 0x00000200, 0xE0300090,
  217. 0x00000204, 0x00030301,
  218. 0x00000200, 0xE030008C,
  219. 0x00000204, 0x500010FF,
  220. 0x00000200, 0xE03000AC,
  221. 0x00000204, 0x00030301,
  222. 0x00000200, 0xE03000A8,
  223. 0x00000204, 0x500010FF,
  224. 0x00000200, 0xE03000C8,
  225. 0x00000204, 0x00030301,
  226. 0x00000200, 0xE03000C4,
  227. 0x00000204, 0x500010FF,
  228. 0x00000200, 0xE03000E4,
  229. 0x00000204, 0x00030301,
  230. 0x00000200, 0xE03000E0,
  231. 0x00000204, 0x500010FF,
  232. 0x00000200, 0xE0300100,
  233. 0x00000204, 0x00030301,
  234. 0x00000200, 0xE03000FC,
  235. 0x00000204, 0x500010FF,
  236. 0x00000200, 0xE0300058,
  237. 0x00000204, 0x00030303,
  238. 0x00000200, 0xE0300054,
  239. 0x00000204, 0x600010FF,
  240. 0x00000200, 0xE0300074,
  241. 0x00000204, 0x00030303,
  242. 0x00000200, 0xE0300070,
  243. 0x00000204, 0x600010FF,
  244. 0x00000200, 0xE0300090,
  245. 0x00000204, 0x00030303,
  246. 0x00000200, 0xE030008C,
  247. 0x00000204, 0x600010FF,
  248. 0x00000200, 0xE03000AC,
  249. 0x00000204, 0x00030303,
  250. 0x00000200, 0xE03000A8,
  251. 0x00000204, 0x600010FF,
  252. 0x00000200, 0xE03000C8,
  253. 0x00000204, 0x00030303,
  254. 0x00000200, 0xE03000C4,
  255. 0x00000204, 0x600010FF,
  256. 0x00000200, 0xE03000E4,
  257. 0x00000204, 0x00030303,
  258. 0x00000200, 0xE03000E0,
  259. 0x00000204, 0x600010FF,
  260. 0x00000200, 0xE0300100,
  261. 0x00000204, 0x00030303,
  262. 0x00000200, 0xE03000FC,
  263. 0x00000204, 0x600010FF,
  264. 0x00000200, 0xE0300058,
  265. 0x00000204, 0x00030303,
  266. 0x00000200, 0xE0300054,
  267. 0x00000204, 0x700010FF,
  268. 0x00000200, 0xE0300074,
  269. 0x00000204, 0x00030303,
  270. 0x00000200, 0xE0300070,
  271. 0x00000204, 0x700010FF,
  272. 0x00000200, 0xE0300090,
  273. 0x00000204, 0x00030303,
  274. 0x00000200, 0xE030008C,
  275. 0x00000204, 0x700010FF,
  276. 0x00000200, 0xE03000AC,
  277. 0x00000204, 0x00030303,
  278. 0x00000200, 0xE03000A8,
  279. 0x00000204, 0x700010FF,
  280. 0x00000200, 0xE03000C8,
  281. 0x00000204, 0x00030303,
  282. 0x00000200, 0xE03000C4,
  283. 0x00000204, 0x700010FF,
  284. 0x00000200, 0xE03000E4,
  285. 0x00000204, 0x00030303,
  286. 0x00000200, 0xE03000E0,
  287. 0x00000204, 0x700010FF,
  288. 0x00000200, 0xE0300100,
  289. 0x00000204, 0x00030303,
  290. 0x00000200, 0xE03000FC,
  291. 0x00000204, 0x700010FF,
  292. 0x00000200, 0xE0300058,
  293. 0x00000204, 0x00010303,
  294. 0x00000200, 0xE0300054,
  295. 0x00000204, 0x800010FF,
  296. 0x00000200, 0xE0300074,
  297. 0x00000204, 0x00010303,
  298. 0x00000200, 0xE0300070,
  299. 0x00000204, 0x800010FF,
  300. 0x00000200, 0xE0300090,
  301. 0x00000204, 0x00010303,
  302. 0x00000200, 0xE030008C,
  303. 0x00000204, 0x800010FF,
  304. 0x00000200, 0xE03000AC,
  305. 0x00000204, 0x00010303,
  306. 0x00000200, 0xE03000A8,
  307. 0x00000204, 0x800010FF,
  308. 0x00000200, 0xE03000C4,
  309. 0x00000204, 0x800010FF,
  310. 0x00000200, 0xE03000C8,
  311. 0x00000204, 0x00010303,
  312. 0x00000200, 0xE03000E4,
  313. 0x00000204, 0x00010303,
  314. 0x00000200, 0xE03000E0,
  315. 0x00000204, 0x800010FF,
  316. 0x00000200, 0xE0300100,
  317. 0x00000204, 0x00010303,
  318. 0x00000200, 0xE03000FC,
  319. 0x00000204, 0x800010FF,
  320. 0x00000200, 0x0001f198,
  321. 0x00000204, 0x0003ffff,
  322. 0x00000200, 0x0001f19C,
  323. 0x00000204, 0x3fffffff,
  324. 0x00000200, 0xE030032C,
  325. 0x00000204, 0x00000000,
  326. };
  327. extern void vce_v1_0_enable_mgcg(struct radeon_device *rdev, bool enable);
  328. static void trinity_program_clk_gating_hw_sequence(struct radeon_device *rdev,
  329. const u32 *seq, u32 count);
  330. static void trinity_override_dynamic_mg_powergating(struct radeon_device *rdev);
  331. static void trinity_apply_state_adjust_rules(struct radeon_device *rdev,
  332. struct radeon_ps *new_rps,
  333. struct radeon_ps *old_rps);
  334. static struct trinity_ps *trinity_get_ps(struct radeon_ps *rps)
  335. {
  336. struct trinity_ps *ps = rps->ps_priv;
  337. return ps;
  338. }
  339. static struct trinity_power_info *trinity_get_pi(struct radeon_device *rdev)
  340. {
  341. struct trinity_power_info *pi = rdev->pm.dpm.priv;
  342. return pi;
  343. }
  344. static void trinity_gfx_powergating_initialize(struct radeon_device *rdev)
  345. {
  346. struct trinity_power_info *pi = trinity_get_pi(rdev);
  347. u32 p, u;
  348. u32 value;
  349. struct atom_clock_dividers dividers;
  350. u32 xclk = radeon_get_xclk(rdev);
  351. u32 sssd = 1;
  352. int ret;
  353. u32 hw_rev = (RREG32(HW_REV) & ATI_REV_ID_MASK) >> ATI_REV_ID_SHIFT;
  354. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  355. 25000, false, &dividers);
  356. if (ret)
  357. return;
  358. value = RREG32_SMC(GFX_POWER_GATING_CNTL);
  359. value &= ~(SSSD_MASK | PDS_DIV_MASK);
  360. if (sssd)
  361. value |= SSSD(1);
  362. value |= PDS_DIV(dividers.post_div);
  363. WREG32_SMC(GFX_POWER_GATING_CNTL, value);
  364. r600_calculate_u_and_p(500, xclk, 16, &p, &u);
  365. WREG32(CG_PG_CTRL, SP(p) | SU(u));
  366. WREG32_P(CG_GIPOTS, CG_GIPOT(p), ~CG_GIPOT_MASK);
  367. /* XXX double check hw_rev */
  368. if (pi->override_dynamic_mgpg && (hw_rev == 0))
  369. trinity_override_dynamic_mg_powergating(rdev);
  370. }
  371. #define CGCG_CGTT_LOCAL0_MASK 0xFFFF33FF
  372. #define CGCG_CGTT_LOCAL1_MASK 0xFFFB0FFE
  373. #define CGTS_SM_CTRL_REG_DISABLE 0x00600000
  374. #define CGTS_SM_CTRL_REG_ENABLE 0x96944200
  375. static void trinity_mg_clockgating_enable(struct radeon_device *rdev,
  376. bool enable)
  377. {
  378. u32 local0;
  379. u32 local1;
  380. if (enable) {
  381. local0 = RREG32_CG(CG_CGTT_LOCAL_0);
  382. local1 = RREG32_CG(CG_CGTT_LOCAL_1);
  383. WREG32_CG(CG_CGTT_LOCAL_0,
  384. (0x00380000 & CGCG_CGTT_LOCAL0_MASK) | (local0 & ~CGCG_CGTT_LOCAL0_MASK) );
  385. WREG32_CG(CG_CGTT_LOCAL_1,
  386. (0x0E000000 & CGCG_CGTT_LOCAL1_MASK) | (local1 & ~CGCG_CGTT_LOCAL1_MASK) );
  387. WREG32(CGTS_SM_CTRL_REG, CGTS_SM_CTRL_REG_ENABLE);
  388. } else {
  389. WREG32(CGTS_SM_CTRL_REG, CGTS_SM_CTRL_REG_DISABLE);
  390. local0 = RREG32_CG(CG_CGTT_LOCAL_0);
  391. local1 = RREG32_CG(CG_CGTT_LOCAL_1);
  392. WREG32_CG(CG_CGTT_LOCAL_0,
  393. CGCG_CGTT_LOCAL0_MASK | (local0 & ~CGCG_CGTT_LOCAL0_MASK) );
  394. WREG32_CG(CG_CGTT_LOCAL_1,
  395. CGCG_CGTT_LOCAL1_MASK | (local1 & ~CGCG_CGTT_LOCAL1_MASK) );
  396. }
  397. }
  398. static void trinity_mg_clockgating_initialize(struct radeon_device *rdev)
  399. {
  400. u32 count;
  401. const u32 *seq = NULL;
  402. seq = &trinity_mgcg_shls_default[0];
  403. count = sizeof(trinity_mgcg_shls_default) / (3 * sizeof(u32));
  404. trinity_program_clk_gating_hw_sequence(rdev, seq, count);
  405. }
  406. static void trinity_gfx_clockgating_enable(struct radeon_device *rdev,
  407. bool enable)
  408. {
  409. if (enable) {
  410. WREG32_P(SCLK_PWRMGT_CNTL, DYN_GFX_CLK_OFF_EN, ~DYN_GFX_CLK_OFF_EN);
  411. } else {
  412. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~DYN_GFX_CLK_OFF_EN);
  413. WREG32_P(SCLK_PWRMGT_CNTL, GFX_CLK_FORCE_ON, ~GFX_CLK_FORCE_ON);
  414. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~GFX_CLK_FORCE_ON);
  415. RREG32(GB_ADDR_CONFIG);
  416. }
  417. }
  418. static void trinity_program_clk_gating_hw_sequence(struct radeon_device *rdev,
  419. const u32 *seq, u32 count)
  420. {
  421. u32 i, length = count * 3;
  422. for (i = 0; i < length; i += 3)
  423. WREG32_P(seq[i], seq[i+1], ~seq[i+2]);
  424. }
  425. static void trinity_program_override_mgpg_sequences(struct radeon_device *rdev,
  426. const u32 *seq, u32 count)
  427. {
  428. u32 i, length = count * 2;
  429. for (i = 0; i < length; i += 2)
  430. WREG32(seq[i], seq[i+1]);
  431. }
  432. static void trinity_override_dynamic_mg_powergating(struct radeon_device *rdev)
  433. {
  434. u32 count;
  435. const u32 *seq = NULL;
  436. seq = &trinity_override_mgpg_sequences[0];
  437. count = sizeof(trinity_override_mgpg_sequences) / (2 * sizeof(u32));
  438. trinity_program_override_mgpg_sequences(rdev, seq, count);
  439. }
  440. static void trinity_ls_clockgating_enable(struct radeon_device *rdev,
  441. bool enable)
  442. {
  443. u32 count;
  444. const u32 *seq = NULL;
  445. if (enable) {
  446. seq = &trinity_sysls_enable[0];
  447. count = sizeof(trinity_sysls_enable) / (3 * sizeof(u32));
  448. } else {
  449. seq = &trinity_sysls_disable[0];
  450. count = sizeof(trinity_sysls_disable) / (3 * sizeof(u32));
  451. }
  452. trinity_program_clk_gating_hw_sequence(rdev, seq, count);
  453. }
  454. static void trinity_gfx_powergating_enable(struct radeon_device *rdev,
  455. bool enable)
  456. {
  457. if (enable) {
  458. if (RREG32_SMC(CC_SMU_TST_EFUSE1_MISC) & RB_BACKEND_DISABLE_MASK)
  459. WREG32_SMC(SMU_SCRATCH_A, (RREG32_SMC(SMU_SCRATCH_A) | 0x01));
  460. WREG32_P(SCLK_PWRMGT_CNTL, DYN_PWR_DOWN_EN, ~DYN_PWR_DOWN_EN);
  461. } else {
  462. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~DYN_PWR_DOWN_EN);
  463. RREG32(GB_ADDR_CONFIG);
  464. }
  465. }
  466. static void trinity_gfx_dynamic_mgpg_enable(struct radeon_device *rdev,
  467. bool enable)
  468. {
  469. u32 value;
  470. if (enable) {
  471. value = RREG32_SMC(PM_I_CNTL_1);
  472. value &= ~DS_PG_CNTL_MASK;
  473. value |= DS_PG_CNTL(1);
  474. WREG32_SMC(PM_I_CNTL_1, value);
  475. value = RREG32_SMC(SMU_S_PG_CNTL);
  476. value &= ~DS_PG_EN_MASK;
  477. value |= DS_PG_EN(1);
  478. WREG32_SMC(SMU_S_PG_CNTL, value);
  479. } else {
  480. value = RREG32_SMC(SMU_S_PG_CNTL);
  481. value &= ~DS_PG_EN_MASK;
  482. WREG32_SMC(SMU_S_PG_CNTL, value);
  483. value = RREG32_SMC(PM_I_CNTL_1);
  484. value &= ~DS_PG_CNTL_MASK;
  485. WREG32_SMC(PM_I_CNTL_1, value);
  486. }
  487. trinity_gfx_dynamic_mgpg_config(rdev);
  488. }
  489. static void trinity_enable_clock_power_gating(struct radeon_device *rdev)
  490. {
  491. struct trinity_power_info *pi = trinity_get_pi(rdev);
  492. if (pi->enable_gfx_clock_gating)
  493. sumo_gfx_clockgating_initialize(rdev);
  494. if (pi->enable_mg_clock_gating)
  495. trinity_mg_clockgating_initialize(rdev);
  496. if (pi->enable_gfx_power_gating)
  497. trinity_gfx_powergating_initialize(rdev);
  498. if (pi->enable_mg_clock_gating) {
  499. trinity_ls_clockgating_enable(rdev, true);
  500. trinity_mg_clockgating_enable(rdev, true);
  501. }
  502. if (pi->enable_gfx_clock_gating)
  503. trinity_gfx_clockgating_enable(rdev, true);
  504. if (pi->enable_gfx_dynamic_mgpg)
  505. trinity_gfx_dynamic_mgpg_enable(rdev, true);
  506. if (pi->enable_gfx_power_gating)
  507. trinity_gfx_powergating_enable(rdev, true);
  508. }
  509. static void trinity_disable_clock_power_gating(struct radeon_device *rdev)
  510. {
  511. struct trinity_power_info *pi = trinity_get_pi(rdev);
  512. if (pi->enable_gfx_power_gating)
  513. trinity_gfx_powergating_enable(rdev, false);
  514. if (pi->enable_gfx_dynamic_mgpg)
  515. trinity_gfx_dynamic_mgpg_enable(rdev, false);
  516. if (pi->enable_gfx_clock_gating)
  517. trinity_gfx_clockgating_enable(rdev, false);
  518. if (pi->enable_mg_clock_gating) {
  519. trinity_mg_clockgating_enable(rdev, false);
  520. trinity_ls_clockgating_enable(rdev, false);
  521. }
  522. }
  523. static void trinity_set_divider_value(struct radeon_device *rdev,
  524. u32 index, u32 sclk)
  525. {
  526. struct atom_clock_dividers dividers;
  527. int ret;
  528. u32 value;
  529. u32 ix = index * TRINITY_SIZEOF_DPM_STATE_TABLE;
  530. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  531. sclk, false, &dividers);
  532. if (ret)
  533. return;
  534. value = RREG32_SMC(SMU_SCLK_DPM_STATE_0_CNTL_0 + ix);
  535. value &= ~CLK_DIVIDER_MASK;
  536. value |= CLK_DIVIDER(dividers.post_div);
  537. WREG32_SMC(SMU_SCLK_DPM_STATE_0_CNTL_0 + ix, value);
  538. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  539. sclk/2, false, &dividers);
  540. if (ret)
  541. return;
  542. value = RREG32_SMC(SMU_SCLK_DPM_STATE_0_PG_CNTL + ix);
  543. value &= ~PD_SCLK_DIVIDER_MASK;
  544. value |= PD_SCLK_DIVIDER(dividers.post_div);
  545. WREG32_SMC(SMU_SCLK_DPM_STATE_0_PG_CNTL + ix, value);
  546. }
  547. static void trinity_set_ds_dividers(struct radeon_device *rdev,
  548. u32 index, u32 divider)
  549. {
  550. u32 value;
  551. u32 ix = index * TRINITY_SIZEOF_DPM_STATE_TABLE;
  552. value = RREG32_SMC(SMU_SCLK_DPM_STATE_0_CNTL_1 + ix);
  553. value &= ~DS_DIV_MASK;
  554. value |= DS_DIV(divider);
  555. WREG32_SMC(SMU_SCLK_DPM_STATE_0_CNTL_1 + ix, value);
  556. }
  557. static void trinity_set_ss_dividers(struct radeon_device *rdev,
  558. u32 index, u32 divider)
  559. {
  560. u32 value;
  561. u32 ix = index * TRINITY_SIZEOF_DPM_STATE_TABLE;
  562. value = RREG32_SMC(SMU_SCLK_DPM_STATE_0_CNTL_1 + ix);
  563. value &= ~DS_SH_DIV_MASK;
  564. value |= DS_SH_DIV(divider);
  565. WREG32_SMC(SMU_SCLK_DPM_STATE_0_CNTL_1 + ix, value);
  566. }
  567. static void trinity_set_vid(struct radeon_device *rdev, u32 index, u32 vid)
  568. {
  569. struct trinity_power_info *pi = trinity_get_pi(rdev);
  570. u32 vid_7bit = sumo_convert_vid2_to_vid7(rdev, &pi->sys_info.vid_mapping_table, vid);
  571. u32 value;
  572. u32 ix = index * TRINITY_SIZEOF_DPM_STATE_TABLE;
  573. value = RREG32_SMC(SMU_SCLK_DPM_STATE_0_CNTL_0 + ix);
  574. value &= ~VID_MASK;
  575. value |= VID(vid_7bit);
  576. WREG32_SMC(SMU_SCLK_DPM_STATE_0_CNTL_0 + ix, value);
  577. value = RREG32_SMC(SMU_SCLK_DPM_STATE_0_CNTL_0 + ix);
  578. value &= ~LVRT_MASK;
  579. value |= LVRT(0);
  580. WREG32_SMC(SMU_SCLK_DPM_STATE_0_CNTL_0 + ix, value);
  581. }
  582. static void trinity_set_allos_gnb_slow(struct radeon_device *rdev,
  583. u32 index, u32 gnb_slow)
  584. {
  585. u32 value;
  586. u32 ix = index * TRINITY_SIZEOF_DPM_STATE_TABLE;
  587. value = RREG32_SMC(SMU_SCLK_DPM_STATE_0_CNTL_3 + ix);
  588. value &= ~GNB_SLOW_MASK;
  589. value |= GNB_SLOW(gnb_slow);
  590. WREG32_SMC(SMU_SCLK_DPM_STATE_0_CNTL_3 + ix, value);
  591. }
  592. static void trinity_set_force_nbp_state(struct radeon_device *rdev,
  593. u32 index, u32 force_nbp_state)
  594. {
  595. u32 value;
  596. u32 ix = index * TRINITY_SIZEOF_DPM_STATE_TABLE;
  597. value = RREG32_SMC(SMU_SCLK_DPM_STATE_0_CNTL_3 + ix);
  598. value &= ~FORCE_NBPS1_MASK;
  599. value |= FORCE_NBPS1(force_nbp_state);
  600. WREG32_SMC(SMU_SCLK_DPM_STATE_0_CNTL_3 + ix, value);
  601. }
  602. static void trinity_set_display_wm(struct radeon_device *rdev,
  603. u32 index, u32 wm)
  604. {
  605. u32 value;
  606. u32 ix = index * TRINITY_SIZEOF_DPM_STATE_TABLE;
  607. value = RREG32_SMC(SMU_SCLK_DPM_STATE_0_CNTL_1 + ix);
  608. value &= ~DISPLAY_WM_MASK;
  609. value |= DISPLAY_WM(wm);
  610. WREG32_SMC(SMU_SCLK_DPM_STATE_0_CNTL_1 + ix, value);
  611. }
  612. static void trinity_set_vce_wm(struct radeon_device *rdev,
  613. u32 index, u32 wm)
  614. {
  615. u32 value;
  616. u32 ix = index * TRINITY_SIZEOF_DPM_STATE_TABLE;
  617. value = RREG32_SMC(SMU_SCLK_DPM_STATE_0_CNTL_1 + ix);
  618. value &= ~VCE_WM_MASK;
  619. value |= VCE_WM(wm);
  620. WREG32_SMC(SMU_SCLK_DPM_STATE_0_CNTL_1 + ix, value);
  621. }
  622. static void trinity_set_at(struct radeon_device *rdev,
  623. u32 index, u32 at)
  624. {
  625. u32 value;
  626. u32 ix = index * TRINITY_SIZEOF_DPM_STATE_TABLE;
  627. value = RREG32_SMC(SMU_SCLK_DPM_STATE_0_AT + ix);
  628. value &= ~AT_MASK;
  629. value |= AT(at);
  630. WREG32_SMC(SMU_SCLK_DPM_STATE_0_AT + ix, value);
  631. }
  632. static void trinity_program_power_level(struct radeon_device *rdev,
  633. struct trinity_pl *pl, u32 index)
  634. {
  635. struct trinity_power_info *pi = trinity_get_pi(rdev);
  636. if (index >= SUMO_MAX_HARDWARE_POWERLEVELS)
  637. return;
  638. trinity_set_divider_value(rdev, index, pl->sclk);
  639. trinity_set_vid(rdev, index, pl->vddc_index);
  640. trinity_set_ss_dividers(rdev, index, pl->ss_divider_index);
  641. trinity_set_ds_dividers(rdev, index, pl->ds_divider_index);
  642. trinity_set_allos_gnb_slow(rdev, index, pl->allow_gnb_slow);
  643. trinity_set_force_nbp_state(rdev, index, pl->force_nbp_state);
  644. trinity_set_display_wm(rdev, index, pl->display_wm);
  645. trinity_set_vce_wm(rdev, index, pl->vce_wm);
  646. trinity_set_at(rdev, index, pi->at[index]);
  647. }
  648. static void trinity_power_level_enable_disable(struct radeon_device *rdev,
  649. u32 index, bool enable)
  650. {
  651. u32 value;
  652. u32 ix = index * TRINITY_SIZEOF_DPM_STATE_TABLE;
  653. value = RREG32_SMC(SMU_SCLK_DPM_STATE_0_CNTL_0 + ix);
  654. value &= ~STATE_VALID_MASK;
  655. if (enable)
  656. value |= STATE_VALID(1);
  657. WREG32_SMC(SMU_SCLK_DPM_STATE_0_CNTL_0 + ix, value);
  658. }
  659. static bool trinity_dpm_enabled(struct radeon_device *rdev)
  660. {
  661. if (RREG32_SMC(SMU_SCLK_DPM_CNTL) & SCLK_DPM_EN(1))
  662. return true;
  663. else
  664. return false;
  665. }
  666. static void trinity_start_dpm(struct radeon_device *rdev)
  667. {
  668. u32 value = RREG32_SMC(SMU_SCLK_DPM_CNTL);
  669. value &= ~(SCLK_DPM_EN_MASK | SCLK_DPM_BOOT_STATE_MASK | VOLTAGE_CHG_EN_MASK);
  670. value |= SCLK_DPM_EN(1) | SCLK_DPM_BOOT_STATE(0) | VOLTAGE_CHG_EN(1);
  671. WREG32_SMC(SMU_SCLK_DPM_CNTL, value);
  672. WREG32_P(GENERAL_PWRMGT, GLOBAL_PWRMGT_EN, ~GLOBAL_PWRMGT_EN);
  673. WREG32_P(CG_CG_VOLTAGE_CNTL, 0, ~EN);
  674. trinity_dpm_config(rdev, true);
  675. }
  676. static void trinity_wait_for_dpm_enabled(struct radeon_device *rdev)
  677. {
  678. int i;
  679. for (i = 0; i < rdev->usec_timeout; i++) {
  680. if (RREG32(SCLK_PWRMGT_CNTL) & DYNAMIC_PM_EN)
  681. break;
  682. udelay(1);
  683. }
  684. for (i = 0; i < rdev->usec_timeout; i++) {
  685. if ((RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & TARGET_STATE_MASK) == 0)
  686. break;
  687. udelay(1);
  688. }
  689. for (i = 0; i < rdev->usec_timeout; i++) {
  690. if ((RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_STATE_MASK) == 0)
  691. break;
  692. udelay(1);
  693. }
  694. }
  695. static void trinity_stop_dpm(struct radeon_device *rdev)
  696. {
  697. u32 sclk_dpm_cntl;
  698. WREG32_P(CG_CG_VOLTAGE_CNTL, EN, ~EN);
  699. sclk_dpm_cntl = RREG32_SMC(SMU_SCLK_DPM_CNTL);
  700. sclk_dpm_cntl &= ~(SCLK_DPM_EN_MASK | VOLTAGE_CHG_EN_MASK);
  701. WREG32_SMC(SMU_SCLK_DPM_CNTL, sclk_dpm_cntl);
  702. trinity_dpm_config(rdev, false);
  703. }
  704. static void trinity_start_am(struct radeon_device *rdev)
  705. {
  706. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~(RESET_SCLK_CNT | RESET_BUSY_CNT));
  707. }
  708. static void trinity_reset_am(struct radeon_device *rdev)
  709. {
  710. WREG32_P(SCLK_PWRMGT_CNTL, RESET_SCLK_CNT | RESET_BUSY_CNT,
  711. ~(RESET_SCLK_CNT | RESET_BUSY_CNT));
  712. }
  713. static void trinity_wait_for_level_0(struct radeon_device *rdev)
  714. {
  715. int i;
  716. for (i = 0; i < rdev->usec_timeout; i++) {
  717. if ((RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_STATE_MASK) == 0)
  718. break;
  719. udelay(1);
  720. }
  721. }
  722. static void trinity_enable_power_level_0(struct radeon_device *rdev)
  723. {
  724. trinity_power_level_enable_disable(rdev, 0, true);
  725. }
  726. static void trinity_force_level_0(struct radeon_device *rdev)
  727. {
  728. trinity_dpm_force_state(rdev, 0);
  729. }
  730. static void trinity_unforce_levels(struct radeon_device *rdev)
  731. {
  732. trinity_dpm_no_forced_level(rdev);
  733. }
  734. static void trinity_program_power_levels_0_to_n(struct radeon_device *rdev,
  735. struct radeon_ps *new_rps,
  736. struct radeon_ps *old_rps)
  737. {
  738. struct trinity_ps *new_ps = trinity_get_ps(new_rps);
  739. struct trinity_ps *old_ps = trinity_get_ps(old_rps);
  740. u32 i;
  741. u32 n_current_state_levels = (old_ps == NULL) ? 1 : old_ps->num_levels;
  742. for (i = 0; i < new_ps->num_levels; i++) {
  743. trinity_program_power_level(rdev, &new_ps->levels[i], i);
  744. trinity_power_level_enable_disable(rdev, i, true);
  745. }
  746. for (i = new_ps->num_levels; i < n_current_state_levels; i++)
  747. trinity_power_level_enable_disable(rdev, i, false);
  748. }
  749. static void trinity_program_bootup_state(struct radeon_device *rdev)
  750. {
  751. struct trinity_power_info *pi = trinity_get_pi(rdev);
  752. u32 i;
  753. trinity_program_power_level(rdev, &pi->boot_pl, 0);
  754. trinity_power_level_enable_disable(rdev, 0, true);
  755. for (i = 1; i < 8; i++)
  756. trinity_power_level_enable_disable(rdev, i, false);
  757. }
  758. static void trinity_setup_uvd_clock_table(struct radeon_device *rdev,
  759. struct radeon_ps *rps)
  760. {
  761. struct trinity_ps *ps = trinity_get_ps(rps);
  762. u32 uvdstates = (ps->vclk_low_divider |
  763. ps->vclk_high_divider << 8 |
  764. ps->dclk_low_divider << 16 |
  765. ps->dclk_high_divider << 24);
  766. WREG32_SMC(SMU_UVD_DPM_STATES, uvdstates);
  767. }
  768. static void trinity_setup_uvd_dpm_interval(struct radeon_device *rdev,
  769. u32 interval)
  770. {
  771. u32 p, u;
  772. u32 tp = RREG32_SMC(PM_TP);
  773. u32 val;
  774. u32 xclk = radeon_get_xclk(rdev);
  775. r600_calculate_u_and_p(interval, xclk, 16, &p, &u);
  776. val = (p + tp - 1) / tp;
  777. WREG32_SMC(SMU_UVD_DPM_CNTL, val);
  778. }
  779. static bool trinity_uvd_clocks_zero(struct radeon_ps *rps)
  780. {
  781. if ((rps->vclk == 0) && (rps->dclk == 0))
  782. return true;
  783. else
  784. return false;
  785. }
  786. static bool trinity_uvd_clocks_equal(struct radeon_ps *rps1,
  787. struct radeon_ps *rps2)
  788. {
  789. struct trinity_ps *ps1 = trinity_get_ps(rps1);
  790. struct trinity_ps *ps2 = trinity_get_ps(rps2);
  791. if ((rps1->vclk == rps2->vclk) &&
  792. (rps1->dclk == rps2->dclk) &&
  793. (ps1->vclk_low_divider == ps2->vclk_low_divider) &&
  794. (ps1->vclk_high_divider == ps2->vclk_high_divider) &&
  795. (ps1->dclk_low_divider == ps2->dclk_low_divider) &&
  796. (ps1->dclk_high_divider == ps2->dclk_high_divider))
  797. return true;
  798. else
  799. return false;
  800. }
  801. static void trinity_setup_uvd_clocks(struct radeon_device *rdev,
  802. struct radeon_ps *new_rps,
  803. struct radeon_ps *old_rps)
  804. {
  805. struct trinity_power_info *pi = trinity_get_pi(rdev);
  806. if (pi->enable_gfx_power_gating) {
  807. trinity_gfx_powergating_enable(rdev, false);
  808. }
  809. if (pi->uvd_dpm) {
  810. if (trinity_uvd_clocks_zero(new_rps) &&
  811. !trinity_uvd_clocks_zero(old_rps)) {
  812. trinity_setup_uvd_dpm_interval(rdev, 0);
  813. } else if (!trinity_uvd_clocks_zero(new_rps)) {
  814. trinity_setup_uvd_clock_table(rdev, new_rps);
  815. if (trinity_uvd_clocks_zero(old_rps)) {
  816. u32 tmp = RREG32(CG_MISC_REG);
  817. tmp &= 0xfffffffd;
  818. WREG32(CG_MISC_REG, tmp);
  819. radeon_set_uvd_clocks(rdev, new_rps->vclk, new_rps->dclk);
  820. trinity_setup_uvd_dpm_interval(rdev, 3000);
  821. }
  822. }
  823. trinity_uvd_dpm_config(rdev);
  824. } else {
  825. if (trinity_uvd_clocks_zero(new_rps) ||
  826. trinity_uvd_clocks_equal(new_rps, old_rps))
  827. return;
  828. radeon_set_uvd_clocks(rdev, new_rps->vclk, new_rps->dclk);
  829. }
  830. if (pi->enable_gfx_power_gating) {
  831. trinity_gfx_powergating_enable(rdev, true);
  832. }
  833. }
  834. static void trinity_set_uvd_clock_before_set_eng_clock(struct radeon_device *rdev,
  835. struct radeon_ps *new_rps,
  836. struct radeon_ps *old_rps)
  837. {
  838. struct trinity_ps *new_ps = trinity_get_ps(new_rps);
  839. struct trinity_ps *current_ps = trinity_get_ps(new_rps);
  840. if (new_ps->levels[new_ps->num_levels - 1].sclk >=
  841. current_ps->levels[current_ps->num_levels - 1].sclk)
  842. return;
  843. trinity_setup_uvd_clocks(rdev, new_rps, old_rps);
  844. }
  845. static void trinity_set_uvd_clock_after_set_eng_clock(struct radeon_device *rdev,
  846. struct radeon_ps *new_rps,
  847. struct radeon_ps *old_rps)
  848. {
  849. struct trinity_ps *new_ps = trinity_get_ps(new_rps);
  850. struct trinity_ps *current_ps = trinity_get_ps(old_rps);
  851. if (new_ps->levels[new_ps->num_levels - 1].sclk <
  852. current_ps->levels[current_ps->num_levels - 1].sclk)
  853. return;
  854. trinity_setup_uvd_clocks(rdev, new_rps, old_rps);
  855. }
  856. static void trinity_set_vce_clock(struct radeon_device *rdev,
  857. struct radeon_ps *new_rps,
  858. struct radeon_ps *old_rps)
  859. {
  860. if ((old_rps->evclk != new_rps->evclk) ||
  861. (old_rps->ecclk != new_rps->ecclk)) {
  862. /* turn the clocks on when encoding, off otherwise */
  863. if (new_rps->evclk || new_rps->ecclk)
  864. vce_v1_0_enable_mgcg(rdev, false);
  865. else
  866. vce_v1_0_enable_mgcg(rdev, true);
  867. radeon_set_vce_clocks(rdev, new_rps->evclk, new_rps->ecclk);
  868. }
  869. }
  870. static void trinity_program_ttt(struct radeon_device *rdev)
  871. {
  872. struct trinity_power_info *pi = trinity_get_pi(rdev);
  873. u32 value = RREG32_SMC(SMU_SCLK_DPM_TTT);
  874. value &= ~(HT_MASK | LT_MASK);
  875. value |= HT((pi->thermal_auto_throttling + 49) * 8);
  876. value |= LT((pi->thermal_auto_throttling + 49 - pi->sys_info.htc_hyst_lmt) * 8);
  877. WREG32_SMC(SMU_SCLK_DPM_TTT, value);
  878. }
  879. static void trinity_enable_att(struct radeon_device *rdev)
  880. {
  881. u32 value = RREG32_SMC(SMU_SCLK_DPM_TT_CNTL);
  882. value &= ~SCLK_TT_EN_MASK;
  883. value |= SCLK_TT_EN(1);
  884. WREG32_SMC(SMU_SCLK_DPM_TT_CNTL, value);
  885. }
  886. static void trinity_program_sclk_dpm(struct radeon_device *rdev)
  887. {
  888. u32 p, u;
  889. u32 tp = RREG32_SMC(PM_TP);
  890. u32 ni;
  891. u32 xclk = radeon_get_xclk(rdev);
  892. u32 value;
  893. r600_calculate_u_and_p(400, xclk, 16, &p, &u);
  894. ni = (p + tp - 1) / tp;
  895. value = RREG32_SMC(PM_I_CNTL_1);
  896. value &= ~SCLK_DPM_MASK;
  897. value |= SCLK_DPM(ni);
  898. WREG32_SMC(PM_I_CNTL_1, value);
  899. }
  900. static int trinity_set_thermal_temperature_range(struct radeon_device *rdev,
  901. int min_temp, int max_temp)
  902. {
  903. int low_temp = 0 * 1000;
  904. int high_temp = 255 * 1000;
  905. if (low_temp < min_temp)
  906. low_temp = min_temp;
  907. if (high_temp > max_temp)
  908. high_temp = max_temp;
  909. if (high_temp < low_temp) {
  910. DRM_ERROR("invalid thermal range: %d - %d\n", low_temp, high_temp);
  911. return -EINVAL;
  912. }
  913. WREG32_P(CG_THERMAL_INT_CTRL, DIG_THERM_INTH(49 + (high_temp / 1000)), ~DIG_THERM_INTH_MASK);
  914. WREG32_P(CG_THERMAL_INT_CTRL, DIG_THERM_INTL(49 + (low_temp / 1000)), ~DIG_THERM_INTL_MASK);
  915. rdev->pm.dpm.thermal.min_temp = low_temp;
  916. rdev->pm.dpm.thermal.max_temp = high_temp;
  917. return 0;
  918. }
  919. static void trinity_update_current_ps(struct radeon_device *rdev,
  920. struct radeon_ps *rps)
  921. {
  922. struct trinity_ps *new_ps = trinity_get_ps(rps);
  923. struct trinity_power_info *pi = trinity_get_pi(rdev);
  924. pi->current_rps = *rps;
  925. pi->current_ps = *new_ps;
  926. pi->current_rps.ps_priv = &pi->current_ps;
  927. }
  928. static void trinity_update_requested_ps(struct radeon_device *rdev,
  929. struct radeon_ps *rps)
  930. {
  931. struct trinity_ps *new_ps = trinity_get_ps(rps);
  932. struct trinity_power_info *pi = trinity_get_pi(rdev);
  933. pi->requested_rps = *rps;
  934. pi->requested_ps = *new_ps;
  935. pi->requested_rps.ps_priv = &pi->requested_ps;
  936. }
  937. void trinity_dpm_enable_bapm(struct radeon_device *rdev, bool enable)
  938. {
  939. struct trinity_power_info *pi = trinity_get_pi(rdev);
  940. if (pi->enable_bapm) {
  941. trinity_acquire_mutex(rdev);
  942. trinity_dpm_bapm_enable(rdev, enable);
  943. trinity_release_mutex(rdev);
  944. }
  945. }
  946. int trinity_dpm_enable(struct radeon_device *rdev)
  947. {
  948. struct trinity_power_info *pi = trinity_get_pi(rdev);
  949. trinity_acquire_mutex(rdev);
  950. if (trinity_dpm_enabled(rdev)) {
  951. trinity_release_mutex(rdev);
  952. return -EINVAL;
  953. }
  954. trinity_program_bootup_state(rdev);
  955. sumo_program_vc(rdev, 0x00C00033);
  956. trinity_start_am(rdev);
  957. if (pi->enable_auto_thermal_throttling) {
  958. trinity_program_ttt(rdev);
  959. trinity_enable_att(rdev);
  960. }
  961. trinity_program_sclk_dpm(rdev);
  962. trinity_start_dpm(rdev);
  963. trinity_wait_for_dpm_enabled(rdev);
  964. trinity_dpm_bapm_enable(rdev, false);
  965. trinity_release_mutex(rdev);
  966. trinity_update_current_ps(rdev, rdev->pm.dpm.boot_ps);
  967. return 0;
  968. }
  969. int trinity_dpm_late_enable(struct radeon_device *rdev)
  970. {
  971. int ret;
  972. trinity_acquire_mutex(rdev);
  973. trinity_enable_clock_power_gating(rdev);
  974. if (rdev->irq.installed &&
  975. r600_is_internal_thermal_sensor(rdev->pm.int_thermal_type)) {
  976. ret = trinity_set_thermal_temperature_range(rdev, R600_TEMP_RANGE_MIN, R600_TEMP_RANGE_MAX);
  977. if (ret) {
  978. trinity_release_mutex(rdev);
  979. return ret;
  980. }
  981. rdev->irq.dpm_thermal = true;
  982. radeon_irq_set(rdev);
  983. }
  984. trinity_release_mutex(rdev);
  985. return 0;
  986. }
  987. void trinity_dpm_disable(struct radeon_device *rdev)
  988. {
  989. trinity_acquire_mutex(rdev);
  990. if (!trinity_dpm_enabled(rdev)) {
  991. trinity_release_mutex(rdev);
  992. return;
  993. }
  994. trinity_dpm_bapm_enable(rdev, false);
  995. trinity_disable_clock_power_gating(rdev);
  996. sumo_clear_vc(rdev);
  997. trinity_wait_for_level_0(rdev);
  998. trinity_stop_dpm(rdev);
  999. trinity_reset_am(rdev);
  1000. trinity_release_mutex(rdev);
  1001. if (rdev->irq.installed &&
  1002. r600_is_internal_thermal_sensor(rdev->pm.int_thermal_type)) {
  1003. rdev->irq.dpm_thermal = false;
  1004. radeon_irq_set(rdev);
  1005. }
  1006. trinity_update_current_ps(rdev, rdev->pm.dpm.boot_ps);
  1007. }
  1008. static void trinity_get_min_sclk_divider(struct radeon_device *rdev)
  1009. {
  1010. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1011. pi->min_sclk_did =
  1012. (RREG32_SMC(CC_SMU_MISC_FUSES) & MinSClkDid_MASK) >> MinSClkDid_SHIFT;
  1013. }
  1014. static void trinity_setup_nbp_sim(struct radeon_device *rdev,
  1015. struct radeon_ps *rps)
  1016. {
  1017. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1018. struct trinity_ps *new_ps = trinity_get_ps(rps);
  1019. u32 nbpsconfig;
  1020. if (pi->sys_info.nb_dpm_enable) {
  1021. nbpsconfig = RREG32_SMC(NB_PSTATE_CONFIG);
  1022. nbpsconfig &= ~(Dpm0PgNbPsLo_MASK | Dpm0PgNbPsHi_MASK | DpmXNbPsLo_MASK | DpmXNbPsHi_MASK);
  1023. nbpsconfig |= (Dpm0PgNbPsLo(new_ps->Dpm0PgNbPsLo) |
  1024. Dpm0PgNbPsHi(new_ps->Dpm0PgNbPsHi) |
  1025. DpmXNbPsLo(new_ps->DpmXNbPsLo) |
  1026. DpmXNbPsHi(new_ps->DpmXNbPsHi));
  1027. WREG32_SMC(NB_PSTATE_CONFIG, nbpsconfig);
  1028. }
  1029. }
  1030. int trinity_dpm_force_performance_level(struct radeon_device *rdev,
  1031. enum radeon_dpm_forced_level level)
  1032. {
  1033. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1034. struct radeon_ps *rps = &pi->current_rps;
  1035. struct trinity_ps *ps = trinity_get_ps(rps);
  1036. int i, ret;
  1037. if (ps->num_levels <= 1)
  1038. return 0;
  1039. if (level == RADEON_DPM_FORCED_LEVEL_HIGH) {
  1040. /* not supported by the hw */
  1041. return -EINVAL;
  1042. } else if (level == RADEON_DPM_FORCED_LEVEL_LOW) {
  1043. ret = trinity_dpm_n_levels_disabled(rdev, ps->num_levels - 1);
  1044. if (ret)
  1045. return ret;
  1046. } else {
  1047. for (i = 0; i < ps->num_levels; i++) {
  1048. ret = trinity_dpm_n_levels_disabled(rdev, 0);
  1049. if (ret)
  1050. return ret;
  1051. }
  1052. }
  1053. rdev->pm.dpm.forced_level = level;
  1054. return 0;
  1055. }
  1056. int trinity_dpm_pre_set_power_state(struct radeon_device *rdev)
  1057. {
  1058. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1059. struct radeon_ps requested_ps = *rdev->pm.dpm.requested_ps;
  1060. struct radeon_ps *new_ps = &requested_ps;
  1061. trinity_update_requested_ps(rdev, new_ps);
  1062. trinity_apply_state_adjust_rules(rdev,
  1063. &pi->requested_rps,
  1064. &pi->current_rps);
  1065. return 0;
  1066. }
  1067. int trinity_dpm_set_power_state(struct radeon_device *rdev)
  1068. {
  1069. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1070. struct radeon_ps *new_ps = &pi->requested_rps;
  1071. struct radeon_ps *old_ps = &pi->current_rps;
  1072. trinity_acquire_mutex(rdev);
  1073. if (pi->enable_dpm) {
  1074. if (pi->enable_bapm)
  1075. trinity_dpm_bapm_enable(rdev, rdev->pm.dpm.ac_power);
  1076. trinity_set_uvd_clock_before_set_eng_clock(rdev, new_ps, old_ps);
  1077. trinity_enable_power_level_0(rdev);
  1078. trinity_force_level_0(rdev);
  1079. trinity_wait_for_level_0(rdev);
  1080. trinity_setup_nbp_sim(rdev, new_ps);
  1081. trinity_program_power_levels_0_to_n(rdev, new_ps, old_ps);
  1082. trinity_force_level_0(rdev);
  1083. trinity_unforce_levels(rdev);
  1084. trinity_set_uvd_clock_after_set_eng_clock(rdev, new_ps, old_ps);
  1085. trinity_set_vce_clock(rdev, new_ps, old_ps);
  1086. }
  1087. trinity_release_mutex(rdev);
  1088. return 0;
  1089. }
  1090. void trinity_dpm_post_set_power_state(struct radeon_device *rdev)
  1091. {
  1092. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1093. struct radeon_ps *new_ps = &pi->requested_rps;
  1094. trinity_update_current_ps(rdev, new_ps);
  1095. }
  1096. void trinity_dpm_setup_asic(struct radeon_device *rdev)
  1097. {
  1098. trinity_acquire_mutex(rdev);
  1099. sumo_program_sstp(rdev);
  1100. sumo_take_smu_control(rdev, true);
  1101. trinity_get_min_sclk_divider(rdev);
  1102. trinity_release_mutex(rdev);
  1103. }
  1104. #if 0
  1105. void trinity_dpm_reset_asic(struct radeon_device *rdev)
  1106. {
  1107. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1108. trinity_acquire_mutex(rdev);
  1109. if (pi->enable_dpm) {
  1110. trinity_enable_power_level_0(rdev);
  1111. trinity_force_level_0(rdev);
  1112. trinity_wait_for_level_0(rdev);
  1113. trinity_program_bootup_state(rdev);
  1114. trinity_force_level_0(rdev);
  1115. trinity_unforce_levels(rdev);
  1116. }
  1117. trinity_release_mutex(rdev);
  1118. }
  1119. #endif
  1120. static u16 trinity_convert_voltage_index_to_value(struct radeon_device *rdev,
  1121. u32 vid_2bit)
  1122. {
  1123. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1124. u32 vid_7bit = sumo_convert_vid2_to_vid7(rdev, &pi->sys_info.vid_mapping_table, vid_2bit);
  1125. u32 svi_mode = (RREG32_SMC(PM_CONFIG) & SVI_Mode) ? 1 : 0;
  1126. u32 step = (svi_mode == 0) ? 1250 : 625;
  1127. u32 delta = vid_7bit * step + 50;
  1128. if (delta > 155000)
  1129. return 0;
  1130. return (155000 - delta) / 100;
  1131. }
  1132. static void trinity_patch_boot_state(struct radeon_device *rdev,
  1133. struct trinity_ps *ps)
  1134. {
  1135. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1136. ps->num_levels = 1;
  1137. ps->nbps_flags = 0;
  1138. ps->bapm_flags = 0;
  1139. ps->levels[0] = pi->boot_pl;
  1140. }
  1141. static u8 trinity_calculate_vce_wm(struct radeon_device *rdev, u32 sclk)
  1142. {
  1143. if (sclk < 20000)
  1144. return 1;
  1145. return 0;
  1146. }
  1147. static void trinity_construct_boot_state(struct radeon_device *rdev)
  1148. {
  1149. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1150. pi->boot_pl.sclk = pi->sys_info.bootup_sclk;
  1151. pi->boot_pl.vddc_index = pi->sys_info.bootup_nb_voltage_index;
  1152. pi->boot_pl.ds_divider_index = 0;
  1153. pi->boot_pl.ss_divider_index = 0;
  1154. pi->boot_pl.allow_gnb_slow = 1;
  1155. pi->boot_pl.force_nbp_state = 0;
  1156. pi->boot_pl.display_wm = 0;
  1157. pi->boot_pl.vce_wm = 0;
  1158. pi->current_ps.num_levels = 1;
  1159. pi->current_ps.levels[0] = pi->boot_pl;
  1160. }
  1161. static u8 trinity_get_sleep_divider_id_from_clock(struct radeon_device *rdev,
  1162. u32 sclk, u32 min_sclk_in_sr)
  1163. {
  1164. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1165. u32 i;
  1166. u32 temp;
  1167. u32 min = (min_sclk_in_sr > TRINITY_MINIMUM_ENGINE_CLOCK) ?
  1168. min_sclk_in_sr : TRINITY_MINIMUM_ENGINE_CLOCK;
  1169. if (sclk < min)
  1170. return 0;
  1171. if (!pi->enable_sclk_ds)
  1172. return 0;
  1173. for (i = TRINITY_MAX_DEEPSLEEP_DIVIDER_ID; ; i--) {
  1174. temp = sclk / sumo_get_sleep_divider_from_id(i);
  1175. if (temp >= min || i == 0)
  1176. break;
  1177. }
  1178. return (u8)i;
  1179. }
  1180. static u32 trinity_get_valid_engine_clock(struct radeon_device *rdev,
  1181. u32 lower_limit)
  1182. {
  1183. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1184. u32 i;
  1185. for (i = 0; i < pi->sys_info.sclk_voltage_mapping_table.num_max_dpm_entries; i++) {
  1186. if (pi->sys_info.sclk_voltage_mapping_table.entries[i].sclk_frequency >= lower_limit)
  1187. return pi->sys_info.sclk_voltage_mapping_table.entries[i].sclk_frequency;
  1188. }
  1189. if (i == pi->sys_info.sclk_voltage_mapping_table.num_max_dpm_entries)
  1190. DRM_ERROR("engine clock out of range!");
  1191. return 0;
  1192. }
  1193. static void trinity_patch_thermal_state(struct radeon_device *rdev,
  1194. struct trinity_ps *ps,
  1195. struct trinity_ps *current_ps)
  1196. {
  1197. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1198. u32 sclk_in_sr = pi->sys_info.min_sclk; /* ??? */
  1199. u32 current_vddc;
  1200. u32 current_sclk;
  1201. u32 current_index = 0;
  1202. if (current_ps) {
  1203. current_vddc = current_ps->levels[current_index].vddc_index;
  1204. current_sclk = current_ps->levels[current_index].sclk;
  1205. } else {
  1206. current_vddc = pi->boot_pl.vddc_index;
  1207. current_sclk = pi->boot_pl.sclk;
  1208. }
  1209. ps->levels[0].vddc_index = current_vddc;
  1210. if (ps->levels[0].sclk > current_sclk)
  1211. ps->levels[0].sclk = current_sclk;
  1212. ps->levels[0].ds_divider_index =
  1213. trinity_get_sleep_divider_id_from_clock(rdev, ps->levels[0].sclk, sclk_in_sr);
  1214. ps->levels[0].ss_divider_index = ps->levels[0].ds_divider_index;
  1215. ps->levels[0].allow_gnb_slow = 1;
  1216. ps->levels[0].force_nbp_state = 0;
  1217. ps->levels[0].display_wm = 0;
  1218. ps->levels[0].vce_wm =
  1219. trinity_calculate_vce_wm(rdev, ps->levels[0].sclk);
  1220. }
  1221. static u8 trinity_calculate_display_wm(struct radeon_device *rdev,
  1222. struct trinity_ps *ps, u32 index)
  1223. {
  1224. if (ps == NULL || ps->num_levels <= 1)
  1225. return 0;
  1226. else if (ps->num_levels == 2) {
  1227. if (index == 0)
  1228. return 0;
  1229. else
  1230. return 1;
  1231. } else {
  1232. if (index == 0)
  1233. return 0;
  1234. else if (ps->levels[index].sclk < 30000)
  1235. return 0;
  1236. else
  1237. return 1;
  1238. }
  1239. }
  1240. static u32 trinity_get_uvd_clock_index(struct radeon_device *rdev,
  1241. struct radeon_ps *rps)
  1242. {
  1243. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1244. u32 i = 0;
  1245. for (i = 0; i < 4; i++) {
  1246. if ((rps->vclk == pi->sys_info.uvd_clock_table_entries[i].vclk) &&
  1247. (rps->dclk == pi->sys_info.uvd_clock_table_entries[i].dclk))
  1248. break;
  1249. }
  1250. if (i >= 4) {
  1251. DRM_ERROR("UVD clock index not found!\n");
  1252. i = 3;
  1253. }
  1254. return i;
  1255. }
  1256. static void trinity_adjust_uvd_state(struct radeon_device *rdev,
  1257. struct radeon_ps *rps)
  1258. {
  1259. struct trinity_ps *ps = trinity_get_ps(rps);
  1260. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1261. u32 high_index = 0;
  1262. u32 low_index = 0;
  1263. if (pi->uvd_dpm && r600_is_uvd_state(rps->class, rps->class2)) {
  1264. high_index = trinity_get_uvd_clock_index(rdev, rps);
  1265. switch(high_index) {
  1266. case 3:
  1267. case 2:
  1268. low_index = 1;
  1269. break;
  1270. case 1:
  1271. case 0:
  1272. default:
  1273. low_index = 0;
  1274. break;
  1275. }
  1276. ps->vclk_low_divider =
  1277. pi->sys_info.uvd_clock_table_entries[high_index].vclk_did;
  1278. ps->dclk_low_divider =
  1279. pi->sys_info.uvd_clock_table_entries[high_index].dclk_did;
  1280. ps->vclk_high_divider =
  1281. pi->sys_info.uvd_clock_table_entries[low_index].vclk_did;
  1282. ps->dclk_high_divider =
  1283. pi->sys_info.uvd_clock_table_entries[low_index].dclk_did;
  1284. }
  1285. }
  1286. static int trinity_get_vce_clock_voltage(struct radeon_device *rdev,
  1287. u32 evclk, u32 ecclk, u16 *voltage)
  1288. {
  1289. u32 i;
  1290. int ret = -EINVAL;
  1291. struct radeon_vce_clock_voltage_dependency_table *table =
  1292. &rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table;
  1293. if (((evclk == 0) && (ecclk == 0)) ||
  1294. (table && (table->count == 0))) {
  1295. *voltage = 0;
  1296. return 0;
  1297. }
  1298. for (i = 0; i < table->count; i++) {
  1299. if ((evclk <= table->entries[i].evclk) &&
  1300. (ecclk <= table->entries[i].ecclk)) {
  1301. *voltage = table->entries[i].v;
  1302. ret = 0;
  1303. break;
  1304. }
  1305. }
  1306. /* if no match return the highest voltage */
  1307. if (ret)
  1308. *voltage = table->entries[table->count - 1].v;
  1309. return ret;
  1310. }
  1311. static void trinity_apply_state_adjust_rules(struct radeon_device *rdev,
  1312. struct radeon_ps *new_rps,
  1313. struct radeon_ps *old_rps)
  1314. {
  1315. struct trinity_ps *ps = trinity_get_ps(new_rps);
  1316. struct trinity_ps *current_ps = trinity_get_ps(old_rps);
  1317. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1318. u32 min_voltage = 0; /* ??? */
  1319. u32 min_sclk = pi->sys_info.min_sclk; /* XXX check against disp reqs */
  1320. u32 sclk_in_sr = pi->sys_info.min_sclk; /* ??? */
  1321. u32 i;
  1322. u16 min_vce_voltage;
  1323. bool force_high;
  1324. u32 num_active_displays = rdev->pm.dpm.new_active_crtc_count;
  1325. if (new_rps->class & ATOM_PPLIB_CLASSIFICATION_THERMAL)
  1326. return trinity_patch_thermal_state(rdev, ps, current_ps);
  1327. trinity_adjust_uvd_state(rdev, new_rps);
  1328. if (new_rps->vce_active) {
  1329. new_rps->evclk = rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].evclk;
  1330. new_rps->ecclk = rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].ecclk;
  1331. } else {
  1332. new_rps->evclk = 0;
  1333. new_rps->ecclk = 0;
  1334. }
  1335. for (i = 0; i < ps->num_levels; i++) {
  1336. if (ps->levels[i].vddc_index < min_voltage)
  1337. ps->levels[i].vddc_index = min_voltage;
  1338. if (ps->levels[i].sclk < min_sclk)
  1339. ps->levels[i].sclk =
  1340. trinity_get_valid_engine_clock(rdev, min_sclk);
  1341. /* patch in vce limits */
  1342. if (new_rps->vce_active) {
  1343. /* sclk */
  1344. if (ps->levels[i].sclk < rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].sclk)
  1345. ps->levels[i].sclk = rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].sclk;
  1346. /* vddc */
  1347. trinity_get_vce_clock_voltage(rdev, new_rps->evclk, new_rps->ecclk, &min_vce_voltage);
  1348. if (ps->levels[i].vddc_index < min_vce_voltage)
  1349. ps->levels[i].vddc_index = min_vce_voltage;
  1350. }
  1351. ps->levels[i].ds_divider_index =
  1352. sumo_get_sleep_divider_id_from_clock(rdev, ps->levels[i].sclk, sclk_in_sr);
  1353. ps->levels[i].ss_divider_index = ps->levels[i].ds_divider_index;
  1354. ps->levels[i].allow_gnb_slow = 1;
  1355. ps->levels[i].force_nbp_state = 0;
  1356. ps->levels[i].display_wm =
  1357. trinity_calculate_display_wm(rdev, ps, i);
  1358. ps->levels[i].vce_wm =
  1359. trinity_calculate_vce_wm(rdev, ps->levels[0].sclk);
  1360. }
  1361. if ((new_rps->class & (ATOM_PPLIB_CLASSIFICATION_HDSTATE | ATOM_PPLIB_CLASSIFICATION_SDSTATE)) ||
  1362. ((new_rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) == ATOM_PPLIB_CLASSIFICATION_UI_BATTERY))
  1363. ps->bapm_flags |= TRINITY_POWERSTATE_FLAGS_BAPM_DISABLE;
  1364. if (pi->sys_info.nb_dpm_enable) {
  1365. ps->Dpm0PgNbPsLo = 0x1;
  1366. ps->Dpm0PgNbPsHi = 0x0;
  1367. ps->DpmXNbPsLo = 0x2;
  1368. ps->DpmXNbPsHi = 0x1;
  1369. if ((new_rps->class & (ATOM_PPLIB_CLASSIFICATION_HDSTATE | ATOM_PPLIB_CLASSIFICATION_SDSTATE)) ||
  1370. ((new_rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) == ATOM_PPLIB_CLASSIFICATION_UI_BATTERY)) {
  1371. force_high = ((new_rps->class & ATOM_PPLIB_CLASSIFICATION_HDSTATE) ||
  1372. ((new_rps->class & ATOM_PPLIB_CLASSIFICATION_SDSTATE) &&
  1373. (pi->sys_info.uma_channel_number == 1)));
  1374. force_high = (num_active_displays >= 3) || force_high;
  1375. ps->Dpm0PgNbPsLo = force_high ? 0x2 : 0x3;
  1376. ps->Dpm0PgNbPsHi = 0x1;
  1377. ps->DpmXNbPsLo = force_high ? 0x2 : 0x3;
  1378. ps->DpmXNbPsHi = 0x2;
  1379. ps->levels[ps->num_levels - 1].allow_gnb_slow = 0;
  1380. }
  1381. }
  1382. }
  1383. static void trinity_cleanup_asic(struct radeon_device *rdev)
  1384. {
  1385. sumo_take_smu_control(rdev, false);
  1386. }
  1387. #if 0
  1388. static void trinity_pre_display_configuration_change(struct radeon_device *rdev)
  1389. {
  1390. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1391. if (pi->voltage_drop_in_dce)
  1392. trinity_dce_enable_voltage_adjustment(rdev, false);
  1393. }
  1394. #endif
  1395. static void trinity_add_dccac_value(struct radeon_device *rdev)
  1396. {
  1397. u32 gpu_cac_avrg_cntl_window_size;
  1398. u32 num_active_displays = rdev->pm.dpm.new_active_crtc_count;
  1399. u64 disp_clk = rdev->clock.default_dispclk / 100;
  1400. u32 dc_cac_value;
  1401. gpu_cac_avrg_cntl_window_size =
  1402. (RREG32_SMC(GPU_CAC_AVRG_CNTL) & WINDOW_SIZE_MASK) >> WINDOW_SIZE_SHIFT;
  1403. dc_cac_value = (u32)((14213 * disp_clk * disp_clk * (u64)num_active_displays) >>
  1404. (32 - gpu_cac_avrg_cntl_window_size));
  1405. WREG32_SMC(DC_CAC_VALUE, dc_cac_value);
  1406. }
  1407. void trinity_dpm_display_configuration_changed(struct radeon_device *rdev)
  1408. {
  1409. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1410. if (pi->voltage_drop_in_dce)
  1411. trinity_dce_enable_voltage_adjustment(rdev, true);
  1412. trinity_add_dccac_value(rdev);
  1413. }
  1414. union power_info {
  1415. struct _ATOM_POWERPLAY_INFO info;
  1416. struct _ATOM_POWERPLAY_INFO_V2 info_2;
  1417. struct _ATOM_POWERPLAY_INFO_V3 info_3;
  1418. struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
  1419. struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
  1420. struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
  1421. };
  1422. union pplib_clock_info {
  1423. struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
  1424. struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
  1425. struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
  1426. struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
  1427. };
  1428. union pplib_power_state {
  1429. struct _ATOM_PPLIB_STATE v1;
  1430. struct _ATOM_PPLIB_STATE_V2 v2;
  1431. };
  1432. static void trinity_parse_pplib_non_clock_info(struct radeon_device *rdev,
  1433. struct radeon_ps *rps,
  1434. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info,
  1435. u8 table_rev)
  1436. {
  1437. struct trinity_ps *ps = trinity_get_ps(rps);
  1438. rps->caps = le32_to_cpu(non_clock_info->ulCapsAndSettings);
  1439. rps->class = le16_to_cpu(non_clock_info->usClassification);
  1440. rps->class2 = le16_to_cpu(non_clock_info->usClassification2);
  1441. if (ATOM_PPLIB_NONCLOCKINFO_VER1 < table_rev) {
  1442. rps->vclk = le32_to_cpu(non_clock_info->ulVCLK);
  1443. rps->dclk = le32_to_cpu(non_clock_info->ulDCLK);
  1444. } else {
  1445. rps->vclk = 0;
  1446. rps->dclk = 0;
  1447. }
  1448. if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT) {
  1449. rdev->pm.dpm.boot_ps = rps;
  1450. trinity_patch_boot_state(rdev, ps);
  1451. }
  1452. if (rps->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE)
  1453. rdev->pm.dpm.uvd_ps = rps;
  1454. }
  1455. static void trinity_parse_pplib_clock_info(struct radeon_device *rdev,
  1456. struct radeon_ps *rps, int index,
  1457. union pplib_clock_info *clock_info)
  1458. {
  1459. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1460. struct trinity_ps *ps = trinity_get_ps(rps);
  1461. struct trinity_pl *pl = &ps->levels[index];
  1462. u32 sclk;
  1463. sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
  1464. sclk |= clock_info->sumo.ucEngineClockHigh << 16;
  1465. pl->sclk = sclk;
  1466. pl->vddc_index = clock_info->sumo.vddcIndex;
  1467. ps->num_levels = index + 1;
  1468. if (pi->enable_sclk_ds) {
  1469. pl->ds_divider_index = 5;
  1470. pl->ss_divider_index = 5;
  1471. }
  1472. }
  1473. static int trinity_parse_power_table(struct radeon_device *rdev)
  1474. {
  1475. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1476. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
  1477. union pplib_power_state *power_state;
  1478. int i, j, k, non_clock_array_index, clock_array_index;
  1479. union pplib_clock_info *clock_info;
  1480. struct _StateArray *state_array;
  1481. struct _ClockInfoArray *clock_info_array;
  1482. struct _NonClockInfoArray *non_clock_info_array;
  1483. union power_info *power_info;
  1484. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  1485. u16 data_offset;
  1486. u8 frev, crev;
  1487. u8 *power_state_offset;
  1488. struct sumo_ps *ps;
  1489. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  1490. &frev, &crev, &data_offset))
  1491. return -EINVAL;
  1492. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  1493. state_array = (struct _StateArray *)
  1494. (mode_info->atom_context->bios + data_offset +
  1495. le16_to_cpu(power_info->pplib.usStateArrayOffset));
  1496. clock_info_array = (struct _ClockInfoArray *)
  1497. (mode_info->atom_context->bios + data_offset +
  1498. le16_to_cpu(power_info->pplib.usClockInfoArrayOffset));
  1499. non_clock_info_array = (struct _NonClockInfoArray *)
  1500. (mode_info->atom_context->bios + data_offset +
  1501. le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset));
  1502. rdev->pm.dpm.ps = kzalloc(sizeof(struct radeon_ps) *
  1503. state_array->ucNumEntries, GFP_KERNEL);
  1504. if (!rdev->pm.dpm.ps)
  1505. return -ENOMEM;
  1506. power_state_offset = (u8 *)state_array->states;
  1507. for (i = 0; i < state_array->ucNumEntries; i++) {
  1508. u8 *idx;
  1509. power_state = (union pplib_power_state *)power_state_offset;
  1510. non_clock_array_index = power_state->v2.nonClockInfoIndex;
  1511. non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
  1512. &non_clock_info_array->nonClockInfo[non_clock_array_index];
  1513. if (!rdev->pm.power_state[i].clock_info)
  1514. return -EINVAL;
  1515. ps = kzalloc(sizeof(struct sumo_ps), GFP_KERNEL);
  1516. if (ps == NULL) {
  1517. kfree(rdev->pm.dpm.ps);
  1518. return -ENOMEM;
  1519. }
  1520. rdev->pm.dpm.ps[i].ps_priv = ps;
  1521. k = 0;
  1522. idx = (u8 *)&power_state->v2.clockInfoIndex[0];
  1523. for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
  1524. clock_array_index = idx[j];
  1525. if (clock_array_index >= clock_info_array->ucNumEntries)
  1526. continue;
  1527. if (k >= SUMO_MAX_HARDWARE_POWERLEVELS)
  1528. break;
  1529. clock_info = (union pplib_clock_info *)
  1530. ((u8 *)&clock_info_array->clockInfo[0] +
  1531. (clock_array_index * clock_info_array->ucEntrySize));
  1532. trinity_parse_pplib_clock_info(rdev,
  1533. &rdev->pm.dpm.ps[i], k,
  1534. clock_info);
  1535. k++;
  1536. }
  1537. trinity_parse_pplib_non_clock_info(rdev, &rdev->pm.dpm.ps[i],
  1538. non_clock_info,
  1539. non_clock_info_array->ucEntrySize);
  1540. power_state_offset += 2 + power_state->v2.ucNumDPMLevels;
  1541. }
  1542. rdev->pm.dpm.num_ps = state_array->ucNumEntries;
  1543. /* fill in the vce power states */
  1544. for (i = 0; i < RADEON_MAX_VCE_LEVELS; i++) {
  1545. u32 sclk;
  1546. clock_array_index = rdev->pm.dpm.vce_states[i].clk_idx;
  1547. clock_info = (union pplib_clock_info *)
  1548. &clock_info_array->clockInfo[clock_array_index * clock_info_array->ucEntrySize];
  1549. sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
  1550. sclk |= clock_info->sumo.ucEngineClockHigh << 16;
  1551. rdev->pm.dpm.vce_states[i].sclk = sclk;
  1552. rdev->pm.dpm.vce_states[i].mclk = 0;
  1553. }
  1554. return 0;
  1555. }
  1556. union igp_info {
  1557. struct _ATOM_INTEGRATED_SYSTEM_INFO info;
  1558. struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
  1559. struct _ATOM_INTEGRATED_SYSTEM_INFO_V5 info_5;
  1560. struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 info_6;
  1561. struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_7 info_7;
  1562. };
  1563. static u32 trinity_convert_did_to_freq(struct radeon_device *rdev, u8 did)
  1564. {
  1565. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1566. u32 divider;
  1567. if (did >= 8 && did <= 0x3f)
  1568. divider = did * 25;
  1569. else if (did > 0x3f && did <= 0x5f)
  1570. divider = (did - 64) * 50 + 1600;
  1571. else if (did > 0x5f && did <= 0x7e)
  1572. divider = (did - 96) * 100 + 3200;
  1573. else if (did == 0x7f)
  1574. divider = 128 * 100;
  1575. else
  1576. return 10000;
  1577. return ((pi->sys_info.dentist_vco_freq * 100) + (divider - 1)) / divider;
  1578. }
  1579. static int trinity_parse_sys_info_table(struct radeon_device *rdev)
  1580. {
  1581. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1582. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1583. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  1584. union igp_info *igp_info;
  1585. u8 frev, crev;
  1586. u16 data_offset;
  1587. int i;
  1588. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1589. &frev, &crev, &data_offset)) {
  1590. igp_info = (union igp_info *)(mode_info->atom_context->bios +
  1591. data_offset);
  1592. if (crev != 7) {
  1593. DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
  1594. return -EINVAL;
  1595. }
  1596. pi->sys_info.bootup_sclk = le32_to_cpu(igp_info->info_7.ulBootUpEngineClock);
  1597. pi->sys_info.min_sclk = le32_to_cpu(igp_info->info_7.ulMinEngineClock);
  1598. pi->sys_info.bootup_uma_clk = le32_to_cpu(igp_info->info_7.ulBootUpUMAClock);
  1599. pi->sys_info.dentist_vco_freq = le32_to_cpu(igp_info->info_7.ulDentistVCOFreq);
  1600. pi->sys_info.bootup_nb_voltage_index =
  1601. le16_to_cpu(igp_info->info_7.usBootUpNBVoltage);
  1602. if (igp_info->info_7.ucHtcTmpLmt == 0)
  1603. pi->sys_info.htc_tmp_lmt = 203;
  1604. else
  1605. pi->sys_info.htc_tmp_lmt = igp_info->info_7.ucHtcTmpLmt;
  1606. if (igp_info->info_7.ucHtcHystLmt == 0)
  1607. pi->sys_info.htc_hyst_lmt = 5;
  1608. else
  1609. pi->sys_info.htc_hyst_lmt = igp_info->info_7.ucHtcHystLmt;
  1610. if (pi->sys_info.htc_tmp_lmt <= pi->sys_info.htc_hyst_lmt) {
  1611. DRM_ERROR("The htcTmpLmt should be larger than htcHystLmt.\n");
  1612. }
  1613. if (pi->enable_nbps_policy)
  1614. pi->sys_info.nb_dpm_enable = igp_info->info_7.ucNBDPMEnable;
  1615. else
  1616. pi->sys_info.nb_dpm_enable = 0;
  1617. for (i = 0; i < TRINITY_NUM_NBPSTATES; i++) {
  1618. pi->sys_info.nbp_mclk[i] = le32_to_cpu(igp_info->info_7.ulNbpStateMemclkFreq[i]);
  1619. pi->sys_info.nbp_nclk[i] = le32_to_cpu(igp_info->info_7.ulNbpStateNClkFreq[i]);
  1620. }
  1621. pi->sys_info.nbp_voltage_index[0] = le16_to_cpu(igp_info->info_7.usNBP0Voltage);
  1622. pi->sys_info.nbp_voltage_index[1] = le16_to_cpu(igp_info->info_7.usNBP1Voltage);
  1623. pi->sys_info.nbp_voltage_index[2] = le16_to_cpu(igp_info->info_7.usNBP2Voltage);
  1624. pi->sys_info.nbp_voltage_index[3] = le16_to_cpu(igp_info->info_7.usNBP3Voltage);
  1625. if (!pi->sys_info.nb_dpm_enable) {
  1626. for (i = 1; i < TRINITY_NUM_NBPSTATES; i++) {
  1627. pi->sys_info.nbp_mclk[i] = pi->sys_info.nbp_mclk[0];
  1628. pi->sys_info.nbp_nclk[i] = pi->sys_info.nbp_nclk[0];
  1629. pi->sys_info.nbp_voltage_index[i] = pi->sys_info.nbp_voltage_index[0];
  1630. }
  1631. }
  1632. pi->sys_info.uma_channel_number = igp_info->info_7.ucUMAChannelNumber;
  1633. sumo_construct_sclk_voltage_mapping_table(rdev,
  1634. &pi->sys_info.sclk_voltage_mapping_table,
  1635. igp_info->info_7.sAvail_SCLK);
  1636. sumo_construct_vid_mapping_table(rdev, &pi->sys_info.vid_mapping_table,
  1637. igp_info->info_7.sAvail_SCLK);
  1638. pi->sys_info.uvd_clock_table_entries[0].vclk_did =
  1639. igp_info->info_7.ucDPMState0VclkFid;
  1640. pi->sys_info.uvd_clock_table_entries[1].vclk_did =
  1641. igp_info->info_7.ucDPMState1VclkFid;
  1642. pi->sys_info.uvd_clock_table_entries[2].vclk_did =
  1643. igp_info->info_7.ucDPMState2VclkFid;
  1644. pi->sys_info.uvd_clock_table_entries[3].vclk_did =
  1645. igp_info->info_7.ucDPMState3VclkFid;
  1646. pi->sys_info.uvd_clock_table_entries[0].dclk_did =
  1647. igp_info->info_7.ucDPMState0DclkFid;
  1648. pi->sys_info.uvd_clock_table_entries[1].dclk_did =
  1649. igp_info->info_7.ucDPMState1DclkFid;
  1650. pi->sys_info.uvd_clock_table_entries[2].dclk_did =
  1651. igp_info->info_7.ucDPMState2DclkFid;
  1652. pi->sys_info.uvd_clock_table_entries[3].dclk_did =
  1653. igp_info->info_7.ucDPMState3DclkFid;
  1654. for (i = 0; i < 4; i++) {
  1655. pi->sys_info.uvd_clock_table_entries[i].vclk =
  1656. trinity_convert_did_to_freq(rdev,
  1657. pi->sys_info.uvd_clock_table_entries[i].vclk_did);
  1658. pi->sys_info.uvd_clock_table_entries[i].dclk =
  1659. trinity_convert_did_to_freq(rdev,
  1660. pi->sys_info.uvd_clock_table_entries[i].dclk_did);
  1661. }
  1662. }
  1663. return 0;
  1664. }
  1665. int trinity_dpm_init(struct radeon_device *rdev)
  1666. {
  1667. struct trinity_power_info *pi;
  1668. int ret, i;
  1669. pi = kzalloc(sizeof(struct trinity_power_info), GFP_KERNEL);
  1670. if (pi == NULL)
  1671. return -ENOMEM;
  1672. rdev->pm.dpm.priv = pi;
  1673. for (i = 0; i < SUMO_MAX_HARDWARE_POWERLEVELS; i++)
  1674. pi->at[i] = TRINITY_AT_DFLT;
  1675. if (radeon_bapm == -1) {
  1676. /* There are stability issues reported on with
  1677. * bapm enabled when switching between AC and battery
  1678. * power. At the same time, some MSI boards hang
  1679. * if it's not enabled and dpm is enabled. Just enable
  1680. * it for MSI boards right now.
  1681. */
  1682. if (rdev->pdev->subsystem_vendor == 0x1462)
  1683. pi->enable_bapm = true;
  1684. else
  1685. pi->enable_bapm = false;
  1686. } else if (radeon_bapm == 0) {
  1687. pi->enable_bapm = false;
  1688. } else {
  1689. pi->enable_bapm = true;
  1690. }
  1691. pi->enable_nbps_policy = true;
  1692. pi->enable_sclk_ds = true;
  1693. pi->enable_gfx_power_gating = true;
  1694. pi->enable_gfx_clock_gating = true;
  1695. pi->enable_mg_clock_gating = false;
  1696. pi->enable_gfx_dynamic_mgpg = false;
  1697. pi->override_dynamic_mgpg = false;
  1698. pi->enable_auto_thermal_throttling = true;
  1699. pi->voltage_drop_in_dce = false; /* need to restructure dpm/modeset interaction */
  1700. pi->uvd_dpm = true; /* ??? */
  1701. ret = trinity_parse_sys_info_table(rdev);
  1702. if (ret)
  1703. return ret;
  1704. trinity_construct_boot_state(rdev);
  1705. ret = r600_get_platform_caps(rdev);
  1706. if (ret)
  1707. return ret;
  1708. ret = r600_parse_extended_power_table(rdev);
  1709. if (ret)
  1710. return ret;
  1711. ret = trinity_parse_power_table(rdev);
  1712. if (ret)
  1713. return ret;
  1714. pi->thermal_auto_throttling = pi->sys_info.htc_tmp_lmt;
  1715. pi->enable_dpm = true;
  1716. return 0;
  1717. }
  1718. void trinity_dpm_print_power_state(struct radeon_device *rdev,
  1719. struct radeon_ps *rps)
  1720. {
  1721. int i;
  1722. struct trinity_ps *ps = trinity_get_ps(rps);
  1723. r600_dpm_print_class_info(rps->class, rps->class2);
  1724. r600_dpm_print_cap_info(rps->caps);
  1725. printk("\tuvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
  1726. for (i = 0; i < ps->num_levels; i++) {
  1727. struct trinity_pl *pl = &ps->levels[i];
  1728. printk("\t\tpower level %d sclk: %u vddc: %u\n",
  1729. i, pl->sclk,
  1730. trinity_convert_voltage_index_to_value(rdev, pl->vddc_index));
  1731. }
  1732. r600_dpm_print_ps_status(rdev, rps);
  1733. }
  1734. void trinity_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev,
  1735. struct seq_file *m)
  1736. {
  1737. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1738. struct radeon_ps *rps = &pi->current_rps;
  1739. struct trinity_ps *ps = trinity_get_ps(rps);
  1740. struct trinity_pl *pl;
  1741. u32 current_index =
  1742. (RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_STATE_MASK) >>
  1743. CURRENT_STATE_SHIFT;
  1744. if (current_index >= ps->num_levels) {
  1745. seq_printf(m, "invalid dpm profile %d\n", current_index);
  1746. } else {
  1747. pl = &ps->levels[current_index];
  1748. seq_printf(m, "uvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
  1749. seq_printf(m, "power level %d sclk: %u vddc: %u\n",
  1750. current_index, pl->sclk,
  1751. trinity_convert_voltage_index_to_value(rdev, pl->vddc_index));
  1752. }
  1753. }
  1754. u32 trinity_dpm_get_current_sclk(struct radeon_device *rdev)
  1755. {
  1756. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1757. struct radeon_ps *rps = &pi->current_rps;
  1758. struct trinity_ps *ps = trinity_get_ps(rps);
  1759. struct trinity_pl *pl;
  1760. u32 current_index =
  1761. (RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_STATE_MASK) >>
  1762. CURRENT_STATE_SHIFT;
  1763. if (current_index >= ps->num_levels) {
  1764. return 0;
  1765. } else {
  1766. pl = &ps->levels[current_index];
  1767. return pl->sclk;
  1768. }
  1769. }
  1770. u32 trinity_dpm_get_current_mclk(struct radeon_device *rdev)
  1771. {
  1772. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1773. return pi->sys_info.bootup_uma_clk;
  1774. }
  1775. void trinity_dpm_fini(struct radeon_device *rdev)
  1776. {
  1777. int i;
  1778. trinity_cleanup_asic(rdev); /* ??? */
  1779. for (i = 0; i < rdev->pm.dpm.num_ps; i++) {
  1780. kfree(rdev->pm.dpm.ps[i].ps_priv);
  1781. }
  1782. kfree(rdev->pm.dpm.ps);
  1783. kfree(rdev->pm.dpm.priv);
  1784. r600_free_extended_power_table(rdev);
  1785. }
  1786. u32 trinity_dpm_get_sclk(struct radeon_device *rdev, bool low)
  1787. {
  1788. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1789. struct trinity_ps *requested_state = trinity_get_ps(&pi->requested_rps);
  1790. if (low)
  1791. return requested_state->levels[0].sclk;
  1792. else
  1793. return requested_state->levels[requested_state->num_levels - 1].sclk;
  1794. }
  1795. u32 trinity_dpm_get_mclk(struct radeon_device *rdev, bool low)
  1796. {
  1797. struct trinity_power_info *pi = trinity_get_pi(rdev);
  1798. return pi->sys_info.bootup_uma_clk;
  1799. }