sumo_dpm.c 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945
  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 "sumod.h"
  27. #include "r600_dpm.h"
  28. #include "cypress_dpm.h"
  29. #include "sumo_dpm.h"
  30. #include <linux/seq_file.h>
  31. #define SUMO_MAX_DEEPSLEEP_DIVIDER_ID 5
  32. #define SUMO_MINIMUM_ENGINE_CLOCK 800
  33. #define BOOST_DPM_LEVEL 7
  34. static const u32 sumo_utc[SUMO_PM_NUMBER_OF_TC] =
  35. {
  36. SUMO_UTC_DFLT_00,
  37. SUMO_UTC_DFLT_01,
  38. SUMO_UTC_DFLT_02,
  39. SUMO_UTC_DFLT_03,
  40. SUMO_UTC_DFLT_04,
  41. SUMO_UTC_DFLT_05,
  42. SUMO_UTC_DFLT_06,
  43. SUMO_UTC_DFLT_07,
  44. SUMO_UTC_DFLT_08,
  45. SUMO_UTC_DFLT_09,
  46. SUMO_UTC_DFLT_10,
  47. SUMO_UTC_DFLT_11,
  48. SUMO_UTC_DFLT_12,
  49. SUMO_UTC_DFLT_13,
  50. SUMO_UTC_DFLT_14,
  51. };
  52. static const u32 sumo_dtc[SUMO_PM_NUMBER_OF_TC] =
  53. {
  54. SUMO_DTC_DFLT_00,
  55. SUMO_DTC_DFLT_01,
  56. SUMO_DTC_DFLT_02,
  57. SUMO_DTC_DFLT_03,
  58. SUMO_DTC_DFLT_04,
  59. SUMO_DTC_DFLT_05,
  60. SUMO_DTC_DFLT_06,
  61. SUMO_DTC_DFLT_07,
  62. SUMO_DTC_DFLT_08,
  63. SUMO_DTC_DFLT_09,
  64. SUMO_DTC_DFLT_10,
  65. SUMO_DTC_DFLT_11,
  66. SUMO_DTC_DFLT_12,
  67. SUMO_DTC_DFLT_13,
  68. SUMO_DTC_DFLT_14,
  69. };
  70. static struct sumo_ps *sumo_get_ps(struct radeon_ps *rps)
  71. {
  72. struct sumo_ps *ps = rps->ps_priv;
  73. return ps;
  74. }
  75. struct sumo_power_info *sumo_get_pi(struct radeon_device *rdev)
  76. {
  77. struct sumo_power_info *pi = rdev->pm.dpm.priv;
  78. return pi;
  79. }
  80. static void sumo_gfx_clockgating_enable(struct radeon_device *rdev, bool enable)
  81. {
  82. if (enable)
  83. WREG32_P(SCLK_PWRMGT_CNTL, DYN_GFX_CLK_OFF_EN, ~DYN_GFX_CLK_OFF_EN);
  84. else {
  85. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~DYN_GFX_CLK_OFF_EN);
  86. WREG32_P(SCLK_PWRMGT_CNTL, GFX_CLK_FORCE_ON, ~GFX_CLK_FORCE_ON);
  87. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~GFX_CLK_FORCE_ON);
  88. RREG32(GB_ADDR_CONFIG);
  89. }
  90. }
  91. #define CGCG_CGTT_LOCAL0_MASK 0xE5BFFFFF
  92. #define CGCG_CGTT_LOCAL1_MASK 0xEFFF07FF
  93. static void sumo_mg_clockgating_enable(struct radeon_device *rdev, bool enable)
  94. {
  95. u32 local0;
  96. u32 local1;
  97. local0 = RREG32(CG_CGTT_LOCAL_0);
  98. local1 = RREG32(CG_CGTT_LOCAL_1);
  99. if (enable) {
  100. WREG32(CG_CGTT_LOCAL_0, (0 & CGCG_CGTT_LOCAL0_MASK) | (local0 & ~CGCG_CGTT_LOCAL0_MASK) );
  101. WREG32(CG_CGTT_LOCAL_1, (0 & CGCG_CGTT_LOCAL1_MASK) | (local1 & ~CGCG_CGTT_LOCAL1_MASK) );
  102. } else {
  103. WREG32(CG_CGTT_LOCAL_0, (0xFFFFFFFF & CGCG_CGTT_LOCAL0_MASK) | (local0 & ~CGCG_CGTT_LOCAL0_MASK) );
  104. WREG32(CG_CGTT_LOCAL_1, (0xFFFFCFFF & CGCG_CGTT_LOCAL1_MASK) | (local1 & ~CGCG_CGTT_LOCAL1_MASK) );
  105. }
  106. }
  107. static void sumo_program_git(struct radeon_device *rdev)
  108. {
  109. u32 p, u;
  110. u32 xclk = radeon_get_xclk(rdev);
  111. r600_calculate_u_and_p(SUMO_GICST_DFLT,
  112. xclk, 16, &p, &u);
  113. WREG32_P(CG_GIT, CG_GICST(p), ~CG_GICST_MASK);
  114. }
  115. static void sumo_program_grsd(struct radeon_device *rdev)
  116. {
  117. u32 p, u;
  118. u32 xclk = radeon_get_xclk(rdev);
  119. u32 grs = 256 * 25 / 100;
  120. r600_calculate_u_and_p(1, xclk, 14, &p, &u);
  121. WREG32(CG_GCOOR, PHC(grs) | SDC(p) | SU(u));
  122. }
  123. void sumo_gfx_clockgating_initialize(struct radeon_device *rdev)
  124. {
  125. sumo_program_git(rdev);
  126. sumo_program_grsd(rdev);
  127. }
  128. static void sumo_gfx_powergating_initialize(struct radeon_device *rdev)
  129. {
  130. u32 rcu_pwr_gating_cntl;
  131. u32 p, u;
  132. u32 p_c, p_p, d_p;
  133. u32 r_t, i_t;
  134. u32 xclk = radeon_get_xclk(rdev);
  135. if (rdev->family == CHIP_PALM) {
  136. p_c = 4;
  137. d_p = 10;
  138. r_t = 10;
  139. i_t = 4;
  140. p_p = 50 + 1000/200 + 6 * 32;
  141. } else {
  142. p_c = 16;
  143. d_p = 50;
  144. r_t = 50;
  145. i_t = 50;
  146. p_p = 113;
  147. }
  148. WREG32(CG_SCRATCH2, 0x01B60A17);
  149. r600_calculate_u_and_p(SUMO_GFXPOWERGATINGT_DFLT,
  150. xclk, 16, &p, &u);
  151. WREG32_P(CG_PWR_GATING_CNTL, PGP(p) | PGU(u),
  152. ~(PGP_MASK | PGU_MASK));
  153. r600_calculate_u_and_p(SUMO_VOLTAGEDROPT_DFLT,
  154. xclk, 16, &p, &u);
  155. WREG32_P(CG_CG_VOLTAGE_CNTL, PGP(p) | PGU(u),
  156. ~(PGP_MASK | PGU_MASK));
  157. if (rdev->family == CHIP_PALM) {
  158. WREG32_RCU(RCU_PWR_GATING_SEQ0, 0x10103210);
  159. WREG32_RCU(RCU_PWR_GATING_SEQ1, 0x10101010);
  160. } else {
  161. WREG32_RCU(RCU_PWR_GATING_SEQ0, 0x76543210);
  162. WREG32_RCU(RCU_PWR_GATING_SEQ1, 0xFEDCBA98);
  163. }
  164. rcu_pwr_gating_cntl = RREG32_RCU(RCU_PWR_GATING_CNTL);
  165. rcu_pwr_gating_cntl &=
  166. ~(RSVD_MASK | PCV_MASK | PGS_MASK);
  167. rcu_pwr_gating_cntl |= PCV(p_c) | PGS(1) | PWR_GATING_EN;
  168. if (rdev->family == CHIP_PALM) {
  169. rcu_pwr_gating_cntl &= ~PCP_MASK;
  170. rcu_pwr_gating_cntl |= PCP(0x77);
  171. }
  172. WREG32_RCU(RCU_PWR_GATING_CNTL, rcu_pwr_gating_cntl);
  173. rcu_pwr_gating_cntl = RREG32_RCU(RCU_PWR_GATING_CNTL_2);
  174. rcu_pwr_gating_cntl &= ~(MPPU_MASK | MPPD_MASK);
  175. rcu_pwr_gating_cntl |= MPPU(p_p) | MPPD(50);
  176. WREG32_RCU(RCU_PWR_GATING_CNTL_2, rcu_pwr_gating_cntl);
  177. rcu_pwr_gating_cntl = RREG32_RCU(RCU_PWR_GATING_CNTL_3);
  178. rcu_pwr_gating_cntl &= ~(DPPU_MASK | DPPD_MASK);
  179. rcu_pwr_gating_cntl |= DPPU(d_p) | DPPD(50);
  180. WREG32_RCU(RCU_PWR_GATING_CNTL_3, rcu_pwr_gating_cntl);
  181. rcu_pwr_gating_cntl = RREG32_RCU(RCU_PWR_GATING_CNTL_4);
  182. rcu_pwr_gating_cntl &= ~(RT_MASK | IT_MASK);
  183. rcu_pwr_gating_cntl |= RT(r_t) | IT(i_t);
  184. WREG32_RCU(RCU_PWR_GATING_CNTL_4, rcu_pwr_gating_cntl);
  185. if (rdev->family == CHIP_PALM)
  186. WREG32_RCU(RCU_PWR_GATING_CNTL_5, 0xA02);
  187. sumo_smu_pg_init(rdev);
  188. rcu_pwr_gating_cntl = RREG32_RCU(RCU_PWR_GATING_CNTL);
  189. rcu_pwr_gating_cntl &=
  190. ~(RSVD_MASK | PCV_MASK | PGS_MASK);
  191. rcu_pwr_gating_cntl |= PCV(p_c) | PGS(4) | PWR_GATING_EN;
  192. if (rdev->family == CHIP_PALM) {
  193. rcu_pwr_gating_cntl &= ~PCP_MASK;
  194. rcu_pwr_gating_cntl |= PCP(0x77);
  195. }
  196. WREG32_RCU(RCU_PWR_GATING_CNTL, rcu_pwr_gating_cntl);
  197. if (rdev->family == CHIP_PALM) {
  198. rcu_pwr_gating_cntl = RREG32_RCU(RCU_PWR_GATING_CNTL_2);
  199. rcu_pwr_gating_cntl &= ~(MPPU_MASK | MPPD_MASK);
  200. rcu_pwr_gating_cntl |= MPPU(113) | MPPD(50);
  201. WREG32_RCU(RCU_PWR_GATING_CNTL_2, rcu_pwr_gating_cntl);
  202. rcu_pwr_gating_cntl = RREG32_RCU(RCU_PWR_GATING_CNTL_3);
  203. rcu_pwr_gating_cntl &= ~(DPPU_MASK | DPPD_MASK);
  204. rcu_pwr_gating_cntl |= DPPU(16) | DPPD(50);
  205. WREG32_RCU(RCU_PWR_GATING_CNTL_3, rcu_pwr_gating_cntl);
  206. }
  207. sumo_smu_pg_init(rdev);
  208. rcu_pwr_gating_cntl = RREG32_RCU(RCU_PWR_GATING_CNTL);
  209. rcu_pwr_gating_cntl &=
  210. ~(RSVD_MASK | PCV_MASK | PGS_MASK);
  211. rcu_pwr_gating_cntl |= PGS(5) | PWR_GATING_EN;
  212. if (rdev->family == CHIP_PALM) {
  213. rcu_pwr_gating_cntl |= PCV(4);
  214. rcu_pwr_gating_cntl &= ~PCP_MASK;
  215. rcu_pwr_gating_cntl |= PCP(0x77);
  216. } else
  217. rcu_pwr_gating_cntl |= PCV(11);
  218. WREG32_RCU(RCU_PWR_GATING_CNTL, rcu_pwr_gating_cntl);
  219. if (rdev->family == CHIP_PALM) {
  220. rcu_pwr_gating_cntl = RREG32_RCU(RCU_PWR_GATING_CNTL_2);
  221. rcu_pwr_gating_cntl &= ~(MPPU_MASK | MPPD_MASK);
  222. rcu_pwr_gating_cntl |= MPPU(113) | MPPD(50);
  223. WREG32_RCU(RCU_PWR_GATING_CNTL_2, rcu_pwr_gating_cntl);
  224. rcu_pwr_gating_cntl = RREG32_RCU(RCU_PWR_GATING_CNTL_3);
  225. rcu_pwr_gating_cntl &= ~(DPPU_MASK | DPPD_MASK);
  226. rcu_pwr_gating_cntl |= DPPU(22) | DPPD(50);
  227. WREG32_RCU(RCU_PWR_GATING_CNTL_3, rcu_pwr_gating_cntl);
  228. }
  229. sumo_smu_pg_init(rdev);
  230. }
  231. static void sumo_gfx_powergating_enable(struct radeon_device *rdev, bool enable)
  232. {
  233. if (enable)
  234. WREG32_P(CG_PWR_GATING_CNTL, DYN_PWR_DOWN_EN, ~DYN_PWR_DOWN_EN);
  235. else {
  236. WREG32_P(CG_PWR_GATING_CNTL, 0, ~DYN_PWR_DOWN_EN);
  237. RREG32(GB_ADDR_CONFIG);
  238. }
  239. }
  240. static int sumo_enable_clock_power_gating(struct radeon_device *rdev)
  241. {
  242. struct sumo_power_info *pi = sumo_get_pi(rdev);
  243. if (pi->enable_gfx_clock_gating)
  244. sumo_gfx_clockgating_initialize(rdev);
  245. if (pi->enable_gfx_power_gating)
  246. sumo_gfx_powergating_initialize(rdev);
  247. if (pi->enable_mg_clock_gating)
  248. sumo_mg_clockgating_enable(rdev, true);
  249. if (pi->enable_gfx_clock_gating)
  250. sumo_gfx_clockgating_enable(rdev, true);
  251. if (pi->enable_gfx_power_gating)
  252. sumo_gfx_powergating_enable(rdev, true);
  253. return 0;
  254. }
  255. static void sumo_disable_clock_power_gating(struct radeon_device *rdev)
  256. {
  257. struct sumo_power_info *pi = sumo_get_pi(rdev);
  258. if (pi->enable_gfx_clock_gating)
  259. sumo_gfx_clockgating_enable(rdev, false);
  260. if (pi->enable_gfx_power_gating)
  261. sumo_gfx_powergating_enable(rdev, false);
  262. if (pi->enable_mg_clock_gating)
  263. sumo_mg_clockgating_enable(rdev, false);
  264. }
  265. static void sumo_calculate_bsp(struct radeon_device *rdev,
  266. u32 high_clk)
  267. {
  268. struct sumo_power_info *pi = sumo_get_pi(rdev);
  269. u32 xclk = radeon_get_xclk(rdev);
  270. pi->pasi = 65535 * 100 / high_clk;
  271. pi->asi = 65535 * 100 / high_clk;
  272. r600_calculate_u_and_p(pi->asi,
  273. xclk, 16, &pi->bsp, &pi->bsu);
  274. r600_calculate_u_and_p(pi->pasi,
  275. xclk, 16, &pi->pbsp, &pi->pbsu);
  276. pi->dsp = BSP(pi->bsp) | BSU(pi->bsu);
  277. pi->psp = BSP(pi->pbsp) | BSU(pi->pbsu);
  278. }
  279. static void sumo_init_bsp(struct radeon_device *rdev)
  280. {
  281. struct sumo_power_info *pi = sumo_get_pi(rdev);
  282. WREG32(CG_BSP_0, pi->psp);
  283. }
  284. static void sumo_program_bsp(struct radeon_device *rdev,
  285. struct radeon_ps *rps)
  286. {
  287. struct sumo_power_info *pi = sumo_get_pi(rdev);
  288. struct sumo_ps *ps = sumo_get_ps(rps);
  289. u32 i;
  290. u32 highest_engine_clock = ps->levels[ps->num_levels - 1].sclk;
  291. if (ps->flags & SUMO_POWERSTATE_FLAGS_BOOST_STATE)
  292. highest_engine_clock = pi->boost_pl.sclk;
  293. sumo_calculate_bsp(rdev, highest_engine_clock);
  294. for (i = 0; i < ps->num_levels - 1; i++)
  295. WREG32(CG_BSP_0 + (i * 4), pi->dsp);
  296. WREG32(CG_BSP_0 + (i * 4), pi->psp);
  297. if (ps->flags & SUMO_POWERSTATE_FLAGS_BOOST_STATE)
  298. WREG32(CG_BSP_0 + (BOOST_DPM_LEVEL * 4), pi->psp);
  299. }
  300. static void sumo_write_at(struct radeon_device *rdev,
  301. u32 index, u32 value)
  302. {
  303. if (index == 0)
  304. WREG32(CG_AT_0, value);
  305. else if (index == 1)
  306. WREG32(CG_AT_1, value);
  307. else if (index == 2)
  308. WREG32(CG_AT_2, value);
  309. else if (index == 3)
  310. WREG32(CG_AT_3, value);
  311. else if (index == 4)
  312. WREG32(CG_AT_4, value);
  313. else if (index == 5)
  314. WREG32(CG_AT_5, value);
  315. else if (index == 6)
  316. WREG32(CG_AT_6, value);
  317. else if (index == 7)
  318. WREG32(CG_AT_7, value);
  319. }
  320. static void sumo_program_at(struct radeon_device *rdev,
  321. struct radeon_ps *rps)
  322. {
  323. struct sumo_power_info *pi = sumo_get_pi(rdev);
  324. struct sumo_ps *ps = sumo_get_ps(rps);
  325. u32 asi;
  326. u32 i;
  327. u32 m_a;
  328. u32 a_t;
  329. u32 r[SUMO_MAX_HARDWARE_POWERLEVELS];
  330. u32 l[SUMO_MAX_HARDWARE_POWERLEVELS];
  331. r[0] = SUMO_R_DFLT0;
  332. r[1] = SUMO_R_DFLT1;
  333. r[2] = SUMO_R_DFLT2;
  334. r[3] = SUMO_R_DFLT3;
  335. r[4] = SUMO_R_DFLT4;
  336. l[0] = SUMO_L_DFLT0;
  337. l[1] = SUMO_L_DFLT1;
  338. l[2] = SUMO_L_DFLT2;
  339. l[3] = SUMO_L_DFLT3;
  340. l[4] = SUMO_L_DFLT4;
  341. for (i = 0; i < ps->num_levels; i++) {
  342. asi = (i == ps->num_levels - 1) ? pi->pasi : pi->asi;
  343. m_a = asi * ps->levels[i].sclk / 100;
  344. a_t = CG_R(m_a * r[i] / 100) | CG_L(m_a * l[i] / 100);
  345. sumo_write_at(rdev, i, a_t);
  346. }
  347. if (ps->flags & SUMO_POWERSTATE_FLAGS_BOOST_STATE) {
  348. asi = pi->pasi;
  349. m_a = asi * pi->boost_pl.sclk / 100;
  350. a_t = CG_R(m_a * r[ps->num_levels - 1] / 100) |
  351. CG_L(m_a * l[ps->num_levels - 1] / 100);
  352. sumo_write_at(rdev, BOOST_DPM_LEVEL, a_t);
  353. }
  354. }
  355. static void sumo_program_tp(struct radeon_device *rdev)
  356. {
  357. int i;
  358. enum r600_td td = R600_TD_DFLT;
  359. for (i = 0; i < SUMO_PM_NUMBER_OF_TC; i++) {
  360. WREG32_P(CG_FFCT_0 + (i * 4), UTC_0(sumo_utc[i]), ~UTC_0_MASK);
  361. WREG32_P(CG_FFCT_0 + (i * 4), DTC_0(sumo_dtc[i]), ~DTC_0_MASK);
  362. }
  363. if (td == R600_TD_AUTO)
  364. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~FIR_FORCE_TREND_SEL);
  365. else
  366. WREG32_P(SCLK_PWRMGT_CNTL, FIR_FORCE_TREND_SEL, ~FIR_FORCE_TREND_SEL);
  367. if (td == R600_TD_UP)
  368. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~FIR_TREND_MODE);
  369. if (td == R600_TD_DOWN)
  370. WREG32_P(SCLK_PWRMGT_CNTL, FIR_TREND_MODE, ~FIR_TREND_MODE);
  371. }
  372. void sumo_program_vc(struct radeon_device *rdev, u32 vrc)
  373. {
  374. WREG32(CG_FTV, vrc);
  375. }
  376. void sumo_clear_vc(struct radeon_device *rdev)
  377. {
  378. WREG32(CG_FTV, 0);
  379. }
  380. void sumo_program_sstp(struct radeon_device *rdev)
  381. {
  382. u32 p, u;
  383. u32 xclk = radeon_get_xclk(rdev);
  384. r600_calculate_u_and_p(SUMO_SST_DFLT,
  385. xclk, 16, &p, &u);
  386. WREG32(CG_SSP, SSTU(u) | SST(p));
  387. }
  388. static void sumo_set_divider_value(struct radeon_device *rdev,
  389. u32 index, u32 divider)
  390. {
  391. u32 reg_index = index / 4;
  392. u32 field_index = index % 4;
  393. if (field_index == 0)
  394. WREG32_P(CG_SCLK_DPM_CTRL + (reg_index * 4),
  395. SCLK_FSTATE_0_DIV(divider), ~SCLK_FSTATE_0_DIV_MASK);
  396. else if (field_index == 1)
  397. WREG32_P(CG_SCLK_DPM_CTRL + (reg_index * 4),
  398. SCLK_FSTATE_1_DIV(divider), ~SCLK_FSTATE_1_DIV_MASK);
  399. else if (field_index == 2)
  400. WREG32_P(CG_SCLK_DPM_CTRL + (reg_index * 4),
  401. SCLK_FSTATE_2_DIV(divider), ~SCLK_FSTATE_2_DIV_MASK);
  402. else if (field_index == 3)
  403. WREG32_P(CG_SCLK_DPM_CTRL + (reg_index * 4),
  404. SCLK_FSTATE_3_DIV(divider), ~SCLK_FSTATE_3_DIV_MASK);
  405. }
  406. static void sumo_set_ds_dividers(struct radeon_device *rdev,
  407. u32 index, u32 divider)
  408. {
  409. struct sumo_power_info *pi = sumo_get_pi(rdev);
  410. if (pi->enable_sclk_ds) {
  411. u32 dpm_ctrl = RREG32(CG_SCLK_DPM_CTRL_6);
  412. dpm_ctrl &= ~(0x7 << (index * 3));
  413. dpm_ctrl |= (divider << (index * 3));
  414. WREG32(CG_SCLK_DPM_CTRL_6, dpm_ctrl);
  415. }
  416. }
  417. static void sumo_set_ss_dividers(struct radeon_device *rdev,
  418. u32 index, u32 divider)
  419. {
  420. struct sumo_power_info *pi = sumo_get_pi(rdev);
  421. if (pi->enable_sclk_ds) {
  422. u32 dpm_ctrl = RREG32(CG_SCLK_DPM_CTRL_11);
  423. dpm_ctrl &= ~(0x7 << (index * 3));
  424. dpm_ctrl |= (divider << (index * 3));
  425. WREG32(CG_SCLK_DPM_CTRL_11, dpm_ctrl);
  426. }
  427. }
  428. static void sumo_set_vid(struct radeon_device *rdev, u32 index, u32 vid)
  429. {
  430. u32 voltage_cntl = RREG32(CG_DPM_VOLTAGE_CNTL);
  431. voltage_cntl &= ~(DPM_STATE0_LEVEL_MASK << (index * 2));
  432. voltage_cntl |= (vid << (DPM_STATE0_LEVEL_SHIFT + index * 2));
  433. WREG32(CG_DPM_VOLTAGE_CNTL, voltage_cntl);
  434. }
  435. static void sumo_set_allos_gnb_slow(struct radeon_device *rdev, u32 index, u32 gnb_slow)
  436. {
  437. struct sumo_power_info *pi = sumo_get_pi(rdev);
  438. u32 temp = gnb_slow;
  439. u32 cg_sclk_dpm_ctrl_3;
  440. if (pi->driver_nbps_policy_disable)
  441. temp = 1;
  442. cg_sclk_dpm_ctrl_3 = RREG32(CG_SCLK_DPM_CTRL_3);
  443. cg_sclk_dpm_ctrl_3 &= ~(GNB_SLOW_FSTATE_0_MASK << index);
  444. cg_sclk_dpm_ctrl_3 |= (temp << (GNB_SLOW_FSTATE_0_SHIFT + index));
  445. WREG32(CG_SCLK_DPM_CTRL_3, cg_sclk_dpm_ctrl_3);
  446. }
  447. static void sumo_program_power_level(struct radeon_device *rdev,
  448. struct sumo_pl *pl, u32 index)
  449. {
  450. struct sumo_power_info *pi = sumo_get_pi(rdev);
  451. int ret;
  452. struct atom_clock_dividers dividers;
  453. u32 ds_en = RREG32(DEEP_SLEEP_CNTL) & ENABLE_DS;
  454. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  455. pl->sclk, false, &dividers);
  456. if (ret)
  457. return;
  458. sumo_set_divider_value(rdev, index, dividers.post_div);
  459. sumo_set_vid(rdev, index, pl->vddc_index);
  460. if (pl->ss_divider_index == 0 || pl->ds_divider_index == 0) {
  461. if (ds_en)
  462. WREG32_P(DEEP_SLEEP_CNTL, 0, ~ENABLE_DS);
  463. } else {
  464. sumo_set_ss_dividers(rdev, index, pl->ss_divider_index);
  465. sumo_set_ds_dividers(rdev, index, pl->ds_divider_index);
  466. if (!ds_en)
  467. WREG32_P(DEEP_SLEEP_CNTL, ENABLE_DS, ~ENABLE_DS);
  468. }
  469. sumo_set_allos_gnb_slow(rdev, index, pl->allow_gnb_slow);
  470. if (pi->enable_boost)
  471. sumo_set_tdp_limit(rdev, index, pl->sclk_dpm_tdp_limit);
  472. }
  473. static void sumo_power_level_enable(struct radeon_device *rdev, u32 index, bool enable)
  474. {
  475. u32 reg_index = index / 4;
  476. u32 field_index = index % 4;
  477. if (field_index == 0)
  478. WREG32_P(CG_SCLK_DPM_CTRL + (reg_index * 4),
  479. enable ? SCLK_FSTATE_0_VLD : 0, ~SCLK_FSTATE_0_VLD);
  480. else if (field_index == 1)
  481. WREG32_P(CG_SCLK_DPM_CTRL + (reg_index * 4),
  482. enable ? SCLK_FSTATE_1_VLD : 0, ~SCLK_FSTATE_1_VLD);
  483. else if (field_index == 2)
  484. WREG32_P(CG_SCLK_DPM_CTRL + (reg_index * 4),
  485. enable ? SCLK_FSTATE_2_VLD : 0, ~SCLK_FSTATE_2_VLD);
  486. else if (field_index == 3)
  487. WREG32_P(CG_SCLK_DPM_CTRL + (reg_index * 4),
  488. enable ? SCLK_FSTATE_3_VLD : 0, ~SCLK_FSTATE_3_VLD);
  489. }
  490. static bool sumo_dpm_enabled(struct radeon_device *rdev)
  491. {
  492. if (RREG32(CG_SCLK_DPM_CTRL_3) & DPM_SCLK_ENABLE)
  493. return true;
  494. else
  495. return false;
  496. }
  497. static void sumo_start_dpm(struct radeon_device *rdev)
  498. {
  499. WREG32_P(CG_SCLK_DPM_CTRL_3, DPM_SCLK_ENABLE, ~DPM_SCLK_ENABLE);
  500. }
  501. static void sumo_stop_dpm(struct radeon_device *rdev)
  502. {
  503. WREG32_P(CG_SCLK_DPM_CTRL_3, 0, ~DPM_SCLK_ENABLE);
  504. }
  505. static void sumo_set_forced_mode(struct radeon_device *rdev, bool enable)
  506. {
  507. if (enable)
  508. WREG32_P(CG_SCLK_DPM_CTRL_3, FORCE_SCLK_STATE_EN, ~FORCE_SCLK_STATE_EN);
  509. else
  510. WREG32_P(CG_SCLK_DPM_CTRL_3, 0, ~FORCE_SCLK_STATE_EN);
  511. }
  512. static void sumo_set_forced_mode_enabled(struct radeon_device *rdev)
  513. {
  514. int i;
  515. sumo_set_forced_mode(rdev, true);
  516. for (i = 0; i < rdev->usec_timeout; i++) {
  517. if (RREG32(CG_SCLK_STATUS) & SCLK_OVERCLK_DETECT)
  518. break;
  519. udelay(1);
  520. }
  521. }
  522. static void sumo_wait_for_level_0(struct radeon_device *rdev)
  523. {
  524. int i;
  525. for (i = 0; i < rdev->usec_timeout; i++) {
  526. if ((RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURR_SCLK_INDEX_MASK) == 0)
  527. break;
  528. udelay(1);
  529. }
  530. for (i = 0; i < rdev->usec_timeout; i++) {
  531. if ((RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURR_INDEX_MASK) == 0)
  532. break;
  533. udelay(1);
  534. }
  535. }
  536. static void sumo_set_forced_mode_disabled(struct radeon_device *rdev)
  537. {
  538. sumo_set_forced_mode(rdev, false);
  539. }
  540. static void sumo_enable_power_level_0(struct radeon_device *rdev)
  541. {
  542. sumo_power_level_enable(rdev, 0, true);
  543. }
  544. static void sumo_patch_boost_state(struct radeon_device *rdev,
  545. struct radeon_ps *rps)
  546. {
  547. struct sumo_power_info *pi = sumo_get_pi(rdev);
  548. struct sumo_ps *new_ps = sumo_get_ps(rps);
  549. if (new_ps->flags & SUMO_POWERSTATE_FLAGS_BOOST_STATE) {
  550. pi->boost_pl = new_ps->levels[new_ps->num_levels - 1];
  551. pi->boost_pl.sclk = pi->sys_info.boost_sclk;
  552. pi->boost_pl.vddc_index = pi->sys_info.boost_vid_2bit;
  553. pi->boost_pl.sclk_dpm_tdp_limit = pi->sys_info.sclk_dpm_tdp_limit_boost;
  554. }
  555. }
  556. static void sumo_pre_notify_alt_vddnb_change(struct radeon_device *rdev,
  557. struct radeon_ps *new_rps,
  558. struct radeon_ps *old_rps)
  559. {
  560. struct sumo_ps *new_ps = sumo_get_ps(new_rps);
  561. struct sumo_ps *old_ps = sumo_get_ps(old_rps);
  562. u32 nbps1_old = 0;
  563. u32 nbps1_new = 0;
  564. if (old_ps != NULL)
  565. nbps1_old = (old_ps->flags & SUMO_POWERSTATE_FLAGS_FORCE_NBPS1_STATE) ? 1 : 0;
  566. nbps1_new = (new_ps->flags & SUMO_POWERSTATE_FLAGS_FORCE_NBPS1_STATE) ? 1 : 0;
  567. if (nbps1_old == 1 && nbps1_new == 0)
  568. sumo_smu_notify_alt_vddnb_change(rdev, 0, 0);
  569. }
  570. static void sumo_post_notify_alt_vddnb_change(struct radeon_device *rdev,
  571. struct radeon_ps *new_rps,
  572. struct radeon_ps *old_rps)
  573. {
  574. struct sumo_ps *new_ps = sumo_get_ps(new_rps);
  575. struct sumo_ps *old_ps = sumo_get_ps(old_rps);
  576. u32 nbps1_old = 0;
  577. u32 nbps1_new = 0;
  578. if (old_ps != NULL)
  579. nbps1_old = (old_ps->flags & SUMO_POWERSTATE_FLAGS_FORCE_NBPS1_STATE)? 1 : 0;
  580. nbps1_new = (new_ps->flags & SUMO_POWERSTATE_FLAGS_FORCE_NBPS1_STATE)? 1 : 0;
  581. if (nbps1_old == 0 && nbps1_new == 1)
  582. sumo_smu_notify_alt_vddnb_change(rdev, 1, 1);
  583. }
  584. static void sumo_enable_boost(struct radeon_device *rdev,
  585. struct radeon_ps *rps,
  586. bool enable)
  587. {
  588. struct sumo_ps *new_ps = sumo_get_ps(rps);
  589. if (enable) {
  590. if (new_ps->flags & SUMO_POWERSTATE_FLAGS_BOOST_STATE)
  591. sumo_boost_state_enable(rdev, true);
  592. } else
  593. sumo_boost_state_enable(rdev, false);
  594. }
  595. static void sumo_set_forced_level(struct radeon_device *rdev, u32 index)
  596. {
  597. WREG32_P(CG_SCLK_DPM_CTRL_3, FORCE_SCLK_STATE(index), ~FORCE_SCLK_STATE_MASK);
  598. }
  599. static void sumo_set_forced_level_0(struct radeon_device *rdev)
  600. {
  601. sumo_set_forced_level(rdev, 0);
  602. }
  603. static void sumo_program_wl(struct radeon_device *rdev,
  604. struct radeon_ps *rps)
  605. {
  606. struct sumo_ps *new_ps = sumo_get_ps(rps);
  607. u32 dpm_ctrl4 = RREG32(CG_SCLK_DPM_CTRL_4);
  608. dpm_ctrl4 &= 0xFFFFFF00;
  609. dpm_ctrl4 |= (1 << (new_ps->num_levels - 1));
  610. if (new_ps->flags & SUMO_POWERSTATE_FLAGS_BOOST_STATE)
  611. dpm_ctrl4 |= (1 << BOOST_DPM_LEVEL);
  612. WREG32(CG_SCLK_DPM_CTRL_4, dpm_ctrl4);
  613. }
  614. static void sumo_program_power_levels_0_to_n(struct radeon_device *rdev,
  615. struct radeon_ps *new_rps,
  616. struct radeon_ps *old_rps)
  617. {
  618. struct sumo_power_info *pi = sumo_get_pi(rdev);
  619. struct sumo_ps *new_ps = sumo_get_ps(new_rps);
  620. struct sumo_ps *old_ps = sumo_get_ps(old_rps);
  621. u32 i;
  622. u32 n_current_state_levels = (old_ps == NULL) ? 1 : old_ps->num_levels;
  623. for (i = 0; i < new_ps->num_levels; i++) {
  624. sumo_program_power_level(rdev, &new_ps->levels[i], i);
  625. sumo_power_level_enable(rdev, i, true);
  626. }
  627. for (i = new_ps->num_levels; i < n_current_state_levels; i++)
  628. sumo_power_level_enable(rdev, i, false);
  629. if (new_ps->flags & SUMO_POWERSTATE_FLAGS_BOOST_STATE)
  630. sumo_program_power_level(rdev, &pi->boost_pl, BOOST_DPM_LEVEL);
  631. }
  632. static void sumo_enable_acpi_pm(struct radeon_device *rdev)
  633. {
  634. WREG32_P(GENERAL_PWRMGT, STATIC_PM_EN, ~STATIC_PM_EN);
  635. }
  636. static void sumo_program_power_level_enter_state(struct radeon_device *rdev)
  637. {
  638. WREG32_P(CG_SCLK_DPM_CTRL_5, SCLK_FSTATE_BOOTUP(0), ~SCLK_FSTATE_BOOTUP_MASK);
  639. }
  640. static void sumo_program_acpi_power_level(struct radeon_device *rdev)
  641. {
  642. struct sumo_power_info *pi = sumo_get_pi(rdev);
  643. struct atom_clock_dividers dividers;
  644. int ret;
  645. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  646. pi->acpi_pl.sclk,
  647. false, &dividers);
  648. if (ret)
  649. return;
  650. WREG32_P(CG_ACPI_CNTL, SCLK_ACPI_DIV(dividers.post_div), ~SCLK_ACPI_DIV_MASK);
  651. WREG32_P(CG_ACPI_VOLTAGE_CNTL, 0, ~ACPI_VOLTAGE_EN);
  652. }
  653. static void sumo_program_bootup_state(struct radeon_device *rdev)
  654. {
  655. struct sumo_power_info *pi = sumo_get_pi(rdev);
  656. u32 dpm_ctrl4 = RREG32(CG_SCLK_DPM_CTRL_4);
  657. u32 i;
  658. sumo_program_power_level(rdev, &pi->boot_pl, 0);
  659. dpm_ctrl4 &= 0xFFFFFF00;
  660. WREG32(CG_SCLK_DPM_CTRL_4, dpm_ctrl4);
  661. for (i = 1; i < 8; i++)
  662. sumo_power_level_enable(rdev, i, false);
  663. }
  664. static void sumo_setup_uvd_clocks(struct radeon_device *rdev,
  665. struct radeon_ps *new_rps,
  666. struct radeon_ps *old_rps)
  667. {
  668. struct sumo_power_info *pi = sumo_get_pi(rdev);
  669. if (pi->enable_gfx_power_gating) {
  670. sumo_gfx_powergating_enable(rdev, false);
  671. }
  672. radeon_set_uvd_clocks(rdev, new_rps->vclk, new_rps->dclk);
  673. if (pi->enable_gfx_power_gating) {
  674. if (!pi->disable_gfx_power_gating_in_uvd ||
  675. !r600_is_uvd_state(new_rps->class, new_rps->class2))
  676. sumo_gfx_powergating_enable(rdev, true);
  677. }
  678. }
  679. static void sumo_set_uvd_clock_before_set_eng_clock(struct radeon_device *rdev,
  680. struct radeon_ps *new_rps,
  681. struct radeon_ps *old_rps)
  682. {
  683. struct sumo_ps *new_ps = sumo_get_ps(new_rps);
  684. struct sumo_ps *current_ps = sumo_get_ps(old_rps);
  685. if ((new_rps->vclk == old_rps->vclk) &&
  686. (new_rps->dclk == old_rps->dclk))
  687. return;
  688. if (new_ps->levels[new_ps->num_levels - 1].sclk >=
  689. current_ps->levels[current_ps->num_levels - 1].sclk)
  690. return;
  691. sumo_setup_uvd_clocks(rdev, new_rps, old_rps);
  692. }
  693. static void sumo_set_uvd_clock_after_set_eng_clock(struct radeon_device *rdev,
  694. struct radeon_ps *new_rps,
  695. struct radeon_ps *old_rps)
  696. {
  697. struct sumo_ps *new_ps = sumo_get_ps(new_rps);
  698. struct sumo_ps *current_ps = sumo_get_ps(old_rps);
  699. if ((new_rps->vclk == old_rps->vclk) &&
  700. (new_rps->dclk == old_rps->dclk))
  701. return;
  702. if (new_ps->levels[new_ps->num_levels - 1].sclk <
  703. current_ps->levels[current_ps->num_levels - 1].sclk)
  704. return;
  705. sumo_setup_uvd_clocks(rdev, new_rps, old_rps);
  706. }
  707. void sumo_take_smu_control(struct radeon_device *rdev, bool enable)
  708. {
  709. /* This bit selects who handles display phy powergating.
  710. * Clear the bit to let atom handle it.
  711. * Set it to let the driver handle it.
  712. * For now we just let atom handle it.
  713. */
  714. #if 0
  715. u32 v = RREG32(DOUT_SCRATCH3);
  716. if (enable)
  717. v |= 0x4;
  718. else
  719. v &= 0xFFFFFFFB;
  720. WREG32(DOUT_SCRATCH3, v);
  721. #endif
  722. }
  723. static void sumo_enable_sclk_ds(struct radeon_device *rdev, bool enable)
  724. {
  725. if (enable) {
  726. u32 deep_sleep_cntl = RREG32(DEEP_SLEEP_CNTL);
  727. u32 deep_sleep_cntl2 = RREG32(DEEP_SLEEP_CNTL2);
  728. u32 t = 1;
  729. deep_sleep_cntl &= ~R_DIS;
  730. deep_sleep_cntl &= ~HS_MASK;
  731. deep_sleep_cntl |= HS(t > 4095 ? 4095 : t);
  732. deep_sleep_cntl2 |= LB_UFP_EN;
  733. deep_sleep_cntl2 &= INOUT_C_MASK;
  734. deep_sleep_cntl2 |= INOUT_C(0xf);
  735. WREG32(DEEP_SLEEP_CNTL2, deep_sleep_cntl2);
  736. WREG32(DEEP_SLEEP_CNTL, deep_sleep_cntl);
  737. } else
  738. WREG32_P(DEEP_SLEEP_CNTL, 0, ~ENABLE_DS);
  739. }
  740. static void sumo_program_bootup_at(struct radeon_device *rdev)
  741. {
  742. WREG32_P(CG_AT_0, CG_R(0xffff), ~CG_R_MASK);
  743. WREG32_P(CG_AT_0, CG_L(0), ~CG_L_MASK);
  744. }
  745. static void sumo_reset_am(struct radeon_device *rdev)
  746. {
  747. WREG32_P(SCLK_PWRMGT_CNTL, FIR_RESET, ~FIR_RESET);
  748. }
  749. static void sumo_start_am(struct radeon_device *rdev)
  750. {
  751. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~FIR_RESET);
  752. }
  753. static void sumo_program_ttp(struct radeon_device *rdev)
  754. {
  755. u32 xclk = radeon_get_xclk(rdev);
  756. u32 p, u;
  757. u32 cg_sclk_dpm_ctrl_5 = RREG32(CG_SCLK_DPM_CTRL_5);
  758. r600_calculate_u_and_p(1000,
  759. xclk, 16, &p, &u);
  760. cg_sclk_dpm_ctrl_5 &= ~(TT_TP_MASK | TT_TU_MASK);
  761. cg_sclk_dpm_ctrl_5 |= TT_TP(p) | TT_TU(u);
  762. WREG32(CG_SCLK_DPM_CTRL_5, cg_sclk_dpm_ctrl_5);
  763. }
  764. static void sumo_program_ttt(struct radeon_device *rdev)
  765. {
  766. u32 cg_sclk_dpm_ctrl_3 = RREG32(CG_SCLK_DPM_CTRL_3);
  767. struct sumo_power_info *pi = sumo_get_pi(rdev);
  768. cg_sclk_dpm_ctrl_3 &= ~(GNB_TT_MASK | GNB_THERMTHRO_MASK);
  769. cg_sclk_dpm_ctrl_3 |= GNB_TT(pi->thermal_auto_throttling + 49);
  770. WREG32(CG_SCLK_DPM_CTRL_3, cg_sclk_dpm_ctrl_3);
  771. }
  772. static void sumo_enable_voltage_scaling(struct radeon_device *rdev, bool enable)
  773. {
  774. if (enable) {
  775. WREG32_P(CG_DPM_VOLTAGE_CNTL, DPM_VOLTAGE_EN, ~DPM_VOLTAGE_EN);
  776. WREG32_P(CG_CG_VOLTAGE_CNTL, 0, ~CG_VOLTAGE_EN);
  777. } else {
  778. WREG32_P(CG_CG_VOLTAGE_CNTL, CG_VOLTAGE_EN, ~CG_VOLTAGE_EN);
  779. WREG32_P(CG_DPM_VOLTAGE_CNTL, 0, ~DPM_VOLTAGE_EN);
  780. }
  781. }
  782. static void sumo_override_cnb_thermal_events(struct radeon_device *rdev)
  783. {
  784. WREG32_P(CG_SCLK_DPM_CTRL_3, CNB_THERMTHRO_MASK_SCLK,
  785. ~CNB_THERMTHRO_MASK_SCLK);
  786. }
  787. static void sumo_program_dc_hto(struct radeon_device *rdev)
  788. {
  789. u32 cg_sclk_dpm_ctrl_4 = RREG32(CG_SCLK_DPM_CTRL_4);
  790. u32 p, u;
  791. u32 xclk = radeon_get_xclk(rdev);
  792. r600_calculate_u_and_p(100000,
  793. xclk, 14, &p, &u);
  794. cg_sclk_dpm_ctrl_4 &= ~(DC_HDC_MASK | DC_HU_MASK);
  795. cg_sclk_dpm_ctrl_4 |= DC_HDC(p) | DC_HU(u);
  796. WREG32(CG_SCLK_DPM_CTRL_4, cg_sclk_dpm_ctrl_4);
  797. }
  798. static void sumo_force_nbp_state(struct radeon_device *rdev,
  799. struct radeon_ps *rps)
  800. {
  801. struct sumo_power_info *pi = sumo_get_pi(rdev);
  802. struct sumo_ps *new_ps = sumo_get_ps(rps);
  803. if (!pi->driver_nbps_policy_disable) {
  804. if (new_ps->flags & SUMO_POWERSTATE_FLAGS_FORCE_NBPS1_STATE)
  805. WREG32_P(CG_SCLK_DPM_CTRL_3, FORCE_NB_PSTATE_1, ~FORCE_NB_PSTATE_1);
  806. else
  807. WREG32_P(CG_SCLK_DPM_CTRL_3, 0, ~FORCE_NB_PSTATE_1);
  808. }
  809. }
  810. u32 sumo_get_sleep_divider_from_id(u32 id)
  811. {
  812. return 1 << id;
  813. }
  814. u32 sumo_get_sleep_divider_id_from_clock(struct radeon_device *rdev,
  815. u32 sclk,
  816. u32 min_sclk_in_sr)
  817. {
  818. struct sumo_power_info *pi = sumo_get_pi(rdev);
  819. u32 i;
  820. u32 temp;
  821. u32 min = (min_sclk_in_sr > SUMO_MINIMUM_ENGINE_CLOCK) ?
  822. min_sclk_in_sr : SUMO_MINIMUM_ENGINE_CLOCK;
  823. if (sclk < min)
  824. return 0;
  825. if (!pi->enable_sclk_ds)
  826. return 0;
  827. for (i = SUMO_MAX_DEEPSLEEP_DIVIDER_ID; ; i--) {
  828. temp = sclk / sumo_get_sleep_divider_from_id(i);
  829. if (temp >= min || i == 0)
  830. break;
  831. }
  832. return i;
  833. }
  834. static u32 sumo_get_valid_engine_clock(struct radeon_device *rdev,
  835. u32 lower_limit)
  836. {
  837. struct sumo_power_info *pi = sumo_get_pi(rdev);
  838. u32 i;
  839. for (i = 0; i < pi->sys_info.sclk_voltage_mapping_table.num_max_dpm_entries; i++) {
  840. if (pi->sys_info.sclk_voltage_mapping_table.entries[i].sclk_frequency >= lower_limit)
  841. return pi->sys_info.sclk_voltage_mapping_table.entries[i].sclk_frequency;
  842. }
  843. return pi->sys_info.sclk_voltage_mapping_table.entries[pi->sys_info.sclk_voltage_mapping_table.num_max_dpm_entries - 1].sclk_frequency;
  844. }
  845. static void sumo_patch_thermal_state(struct radeon_device *rdev,
  846. struct sumo_ps *ps,
  847. struct sumo_ps *current_ps)
  848. {
  849. struct sumo_power_info *pi = sumo_get_pi(rdev);
  850. u32 sclk_in_sr = pi->sys_info.min_sclk; /* ??? */
  851. u32 current_vddc;
  852. u32 current_sclk;
  853. u32 current_index = 0;
  854. if (current_ps) {
  855. current_vddc = current_ps->levels[current_index].vddc_index;
  856. current_sclk = current_ps->levels[current_index].sclk;
  857. } else {
  858. current_vddc = pi->boot_pl.vddc_index;
  859. current_sclk = pi->boot_pl.sclk;
  860. }
  861. ps->levels[0].vddc_index = current_vddc;
  862. if (ps->levels[0].sclk > current_sclk)
  863. ps->levels[0].sclk = current_sclk;
  864. ps->levels[0].ss_divider_index =
  865. sumo_get_sleep_divider_id_from_clock(rdev, ps->levels[0].sclk, sclk_in_sr);
  866. ps->levels[0].ds_divider_index =
  867. sumo_get_sleep_divider_id_from_clock(rdev, ps->levels[0].sclk, SUMO_MINIMUM_ENGINE_CLOCK);
  868. if (ps->levels[0].ds_divider_index > ps->levels[0].ss_divider_index + 1)
  869. ps->levels[0].ds_divider_index = ps->levels[0].ss_divider_index + 1;
  870. if (ps->levels[0].ss_divider_index == ps->levels[0].ds_divider_index) {
  871. if (ps->levels[0].ss_divider_index > 1)
  872. ps->levels[0].ss_divider_index = ps->levels[0].ss_divider_index - 1;
  873. }
  874. if (ps->levels[0].ss_divider_index == 0)
  875. ps->levels[0].ds_divider_index = 0;
  876. if (ps->levels[0].ds_divider_index == 0)
  877. ps->levels[0].ss_divider_index = 0;
  878. }
  879. static void sumo_apply_state_adjust_rules(struct radeon_device *rdev,
  880. struct radeon_ps *new_rps,
  881. struct radeon_ps *old_rps)
  882. {
  883. struct sumo_ps *ps = sumo_get_ps(new_rps);
  884. struct sumo_ps *current_ps = sumo_get_ps(old_rps);
  885. struct sumo_power_info *pi = sumo_get_pi(rdev);
  886. u32 min_voltage = 0; /* ??? */
  887. u32 min_sclk = pi->sys_info.min_sclk; /* XXX check against disp reqs */
  888. u32 sclk_in_sr = pi->sys_info.min_sclk; /* ??? */
  889. u32 i;
  890. if (new_rps->class & ATOM_PPLIB_CLASSIFICATION_THERMAL)
  891. return sumo_patch_thermal_state(rdev, ps, current_ps);
  892. if (pi->enable_boost) {
  893. if (new_rps->class & ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE)
  894. ps->flags |= SUMO_POWERSTATE_FLAGS_BOOST_STATE;
  895. }
  896. if ((new_rps->class & ATOM_PPLIB_CLASSIFICATION_UI_BATTERY) ||
  897. (new_rps->class & ATOM_PPLIB_CLASSIFICATION_SDSTATE) ||
  898. (new_rps->class & ATOM_PPLIB_CLASSIFICATION_HDSTATE))
  899. ps->flags |= SUMO_POWERSTATE_FLAGS_FORCE_NBPS1_STATE;
  900. for (i = 0; i < ps->num_levels; i++) {
  901. if (ps->levels[i].vddc_index < min_voltage)
  902. ps->levels[i].vddc_index = min_voltage;
  903. if (ps->levels[i].sclk < min_sclk)
  904. ps->levels[i].sclk =
  905. sumo_get_valid_engine_clock(rdev, min_sclk);
  906. ps->levels[i].ss_divider_index =
  907. sumo_get_sleep_divider_id_from_clock(rdev, ps->levels[i].sclk, sclk_in_sr);
  908. ps->levels[i].ds_divider_index =
  909. sumo_get_sleep_divider_id_from_clock(rdev, ps->levels[i].sclk, SUMO_MINIMUM_ENGINE_CLOCK);
  910. if (ps->levels[i].ds_divider_index > ps->levels[i].ss_divider_index + 1)
  911. ps->levels[i].ds_divider_index = ps->levels[i].ss_divider_index + 1;
  912. if (ps->levels[i].ss_divider_index == ps->levels[i].ds_divider_index) {
  913. if (ps->levels[i].ss_divider_index > 1)
  914. ps->levels[i].ss_divider_index = ps->levels[i].ss_divider_index - 1;
  915. }
  916. if (ps->levels[i].ss_divider_index == 0)
  917. ps->levels[i].ds_divider_index = 0;
  918. if (ps->levels[i].ds_divider_index == 0)
  919. ps->levels[i].ss_divider_index = 0;
  920. if (ps->flags & SUMO_POWERSTATE_FLAGS_FORCE_NBPS1_STATE)
  921. ps->levels[i].allow_gnb_slow = 1;
  922. else if ((new_rps->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE) ||
  923. (new_rps->class2 & ATOM_PPLIB_CLASSIFICATION2_MVC))
  924. ps->levels[i].allow_gnb_slow = 0;
  925. else if (i == ps->num_levels - 1)
  926. ps->levels[i].allow_gnb_slow = 0;
  927. else
  928. ps->levels[i].allow_gnb_slow = 1;
  929. }
  930. }
  931. static void sumo_cleanup_asic(struct radeon_device *rdev)
  932. {
  933. sumo_take_smu_control(rdev, false);
  934. }
  935. static int sumo_set_thermal_temperature_range(struct radeon_device *rdev,
  936. int min_temp, int max_temp)
  937. {
  938. int low_temp = 0 * 1000;
  939. int high_temp = 255 * 1000;
  940. if (low_temp < min_temp)
  941. low_temp = min_temp;
  942. if (high_temp > max_temp)
  943. high_temp = max_temp;
  944. if (high_temp < low_temp) {
  945. DRM_ERROR("invalid thermal range: %d - %d\n", low_temp, high_temp);
  946. return -EINVAL;
  947. }
  948. WREG32_P(CG_THERMAL_INT, DIG_THERM_INTH(49 + (high_temp / 1000)), ~DIG_THERM_INTH_MASK);
  949. WREG32_P(CG_THERMAL_INT, DIG_THERM_INTL(49 + (low_temp / 1000)), ~DIG_THERM_INTL_MASK);
  950. rdev->pm.dpm.thermal.min_temp = low_temp;
  951. rdev->pm.dpm.thermal.max_temp = high_temp;
  952. return 0;
  953. }
  954. static void sumo_update_current_ps(struct radeon_device *rdev,
  955. struct radeon_ps *rps)
  956. {
  957. struct sumo_ps *new_ps = sumo_get_ps(rps);
  958. struct sumo_power_info *pi = sumo_get_pi(rdev);
  959. pi->current_rps = *rps;
  960. pi->current_ps = *new_ps;
  961. pi->current_rps.ps_priv = &pi->current_ps;
  962. }
  963. static void sumo_update_requested_ps(struct radeon_device *rdev,
  964. struct radeon_ps *rps)
  965. {
  966. struct sumo_ps *new_ps = sumo_get_ps(rps);
  967. struct sumo_power_info *pi = sumo_get_pi(rdev);
  968. pi->requested_rps = *rps;
  969. pi->requested_ps = *new_ps;
  970. pi->requested_rps.ps_priv = &pi->requested_ps;
  971. }
  972. int sumo_dpm_enable(struct radeon_device *rdev)
  973. {
  974. struct sumo_power_info *pi = sumo_get_pi(rdev);
  975. if (sumo_dpm_enabled(rdev))
  976. return -EINVAL;
  977. sumo_program_bootup_state(rdev);
  978. sumo_init_bsp(rdev);
  979. sumo_reset_am(rdev);
  980. sumo_program_tp(rdev);
  981. sumo_program_bootup_at(rdev);
  982. sumo_start_am(rdev);
  983. if (pi->enable_auto_thermal_throttling) {
  984. sumo_program_ttp(rdev);
  985. sumo_program_ttt(rdev);
  986. }
  987. sumo_program_dc_hto(rdev);
  988. sumo_program_power_level_enter_state(rdev);
  989. sumo_enable_voltage_scaling(rdev, true);
  990. sumo_program_sstp(rdev);
  991. sumo_program_vc(rdev, SUMO_VRC_DFLT);
  992. sumo_override_cnb_thermal_events(rdev);
  993. sumo_start_dpm(rdev);
  994. sumo_wait_for_level_0(rdev);
  995. if (pi->enable_sclk_ds)
  996. sumo_enable_sclk_ds(rdev, true);
  997. if (pi->enable_boost)
  998. sumo_enable_boost_timer(rdev);
  999. sumo_update_current_ps(rdev, rdev->pm.dpm.boot_ps);
  1000. return 0;
  1001. }
  1002. int sumo_dpm_late_enable(struct radeon_device *rdev)
  1003. {
  1004. int ret;
  1005. ret = sumo_enable_clock_power_gating(rdev);
  1006. if (ret)
  1007. return ret;
  1008. if (rdev->irq.installed &&
  1009. r600_is_internal_thermal_sensor(rdev->pm.int_thermal_type)) {
  1010. ret = sumo_set_thermal_temperature_range(rdev, R600_TEMP_RANGE_MIN, R600_TEMP_RANGE_MAX);
  1011. if (ret)
  1012. return ret;
  1013. rdev->irq.dpm_thermal = true;
  1014. radeon_irq_set(rdev);
  1015. }
  1016. return 0;
  1017. }
  1018. void sumo_dpm_disable(struct radeon_device *rdev)
  1019. {
  1020. struct sumo_power_info *pi = sumo_get_pi(rdev);
  1021. if (!sumo_dpm_enabled(rdev))
  1022. return;
  1023. sumo_disable_clock_power_gating(rdev);
  1024. if (pi->enable_sclk_ds)
  1025. sumo_enable_sclk_ds(rdev, false);
  1026. sumo_clear_vc(rdev);
  1027. sumo_wait_for_level_0(rdev);
  1028. sumo_stop_dpm(rdev);
  1029. sumo_enable_voltage_scaling(rdev, false);
  1030. if (rdev->irq.installed &&
  1031. r600_is_internal_thermal_sensor(rdev->pm.int_thermal_type)) {
  1032. rdev->irq.dpm_thermal = false;
  1033. radeon_irq_set(rdev);
  1034. }
  1035. sumo_update_current_ps(rdev, rdev->pm.dpm.boot_ps);
  1036. }
  1037. int sumo_dpm_pre_set_power_state(struct radeon_device *rdev)
  1038. {
  1039. struct sumo_power_info *pi = sumo_get_pi(rdev);
  1040. struct radeon_ps requested_ps = *rdev->pm.dpm.requested_ps;
  1041. struct radeon_ps *new_ps = &requested_ps;
  1042. sumo_update_requested_ps(rdev, new_ps);
  1043. if (pi->enable_dynamic_patch_ps)
  1044. sumo_apply_state_adjust_rules(rdev,
  1045. &pi->requested_rps,
  1046. &pi->current_rps);
  1047. return 0;
  1048. }
  1049. int sumo_dpm_set_power_state(struct radeon_device *rdev)
  1050. {
  1051. struct sumo_power_info *pi = sumo_get_pi(rdev);
  1052. struct radeon_ps *new_ps = &pi->requested_rps;
  1053. struct radeon_ps *old_ps = &pi->current_rps;
  1054. if (pi->enable_dpm)
  1055. sumo_set_uvd_clock_before_set_eng_clock(rdev, new_ps, old_ps);
  1056. if (pi->enable_boost) {
  1057. sumo_enable_boost(rdev, new_ps, false);
  1058. sumo_patch_boost_state(rdev, new_ps);
  1059. }
  1060. if (pi->enable_dpm) {
  1061. sumo_pre_notify_alt_vddnb_change(rdev, new_ps, old_ps);
  1062. sumo_enable_power_level_0(rdev);
  1063. sumo_set_forced_level_0(rdev);
  1064. sumo_set_forced_mode_enabled(rdev);
  1065. sumo_wait_for_level_0(rdev);
  1066. sumo_program_power_levels_0_to_n(rdev, new_ps, old_ps);
  1067. sumo_program_wl(rdev, new_ps);
  1068. sumo_program_bsp(rdev, new_ps);
  1069. sumo_program_at(rdev, new_ps);
  1070. sumo_force_nbp_state(rdev, new_ps);
  1071. sumo_set_forced_mode_disabled(rdev);
  1072. sumo_set_forced_mode_enabled(rdev);
  1073. sumo_set_forced_mode_disabled(rdev);
  1074. sumo_post_notify_alt_vddnb_change(rdev, new_ps, old_ps);
  1075. }
  1076. if (pi->enable_boost)
  1077. sumo_enable_boost(rdev, new_ps, true);
  1078. if (pi->enable_dpm)
  1079. sumo_set_uvd_clock_after_set_eng_clock(rdev, new_ps, old_ps);
  1080. return 0;
  1081. }
  1082. void sumo_dpm_post_set_power_state(struct radeon_device *rdev)
  1083. {
  1084. struct sumo_power_info *pi = sumo_get_pi(rdev);
  1085. struct radeon_ps *new_ps = &pi->requested_rps;
  1086. sumo_update_current_ps(rdev, new_ps);
  1087. }
  1088. #if 0
  1089. void sumo_dpm_reset_asic(struct radeon_device *rdev)
  1090. {
  1091. sumo_program_bootup_state(rdev);
  1092. sumo_enable_power_level_0(rdev);
  1093. sumo_set_forced_level_0(rdev);
  1094. sumo_set_forced_mode_enabled(rdev);
  1095. sumo_wait_for_level_0(rdev);
  1096. sumo_set_forced_mode_disabled(rdev);
  1097. sumo_set_forced_mode_enabled(rdev);
  1098. sumo_set_forced_mode_disabled(rdev);
  1099. }
  1100. #endif
  1101. void sumo_dpm_setup_asic(struct radeon_device *rdev)
  1102. {
  1103. struct sumo_power_info *pi = sumo_get_pi(rdev);
  1104. sumo_initialize_m3_arb(rdev);
  1105. pi->fw_version = sumo_get_running_fw_version(rdev);
  1106. DRM_INFO("Found smc ucode version: 0x%08x\n", pi->fw_version);
  1107. sumo_program_acpi_power_level(rdev);
  1108. sumo_enable_acpi_pm(rdev);
  1109. sumo_take_smu_control(rdev, true);
  1110. }
  1111. void sumo_dpm_display_configuration_changed(struct radeon_device *rdev)
  1112. {
  1113. }
  1114. union power_info {
  1115. struct _ATOM_POWERPLAY_INFO info;
  1116. struct _ATOM_POWERPLAY_INFO_V2 info_2;
  1117. struct _ATOM_POWERPLAY_INFO_V3 info_3;
  1118. struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
  1119. struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
  1120. struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
  1121. };
  1122. union pplib_clock_info {
  1123. struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
  1124. struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
  1125. struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
  1126. struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
  1127. };
  1128. union pplib_power_state {
  1129. struct _ATOM_PPLIB_STATE v1;
  1130. struct _ATOM_PPLIB_STATE_V2 v2;
  1131. };
  1132. static void sumo_patch_boot_state(struct radeon_device *rdev,
  1133. struct sumo_ps *ps)
  1134. {
  1135. struct sumo_power_info *pi = sumo_get_pi(rdev);
  1136. ps->num_levels = 1;
  1137. ps->flags = 0;
  1138. ps->levels[0] = pi->boot_pl;
  1139. }
  1140. static void sumo_parse_pplib_non_clock_info(struct radeon_device *rdev,
  1141. struct radeon_ps *rps,
  1142. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info,
  1143. u8 table_rev)
  1144. {
  1145. struct sumo_ps *ps = sumo_get_ps(rps);
  1146. rps->caps = le32_to_cpu(non_clock_info->ulCapsAndSettings);
  1147. rps->class = le16_to_cpu(non_clock_info->usClassification);
  1148. rps->class2 = le16_to_cpu(non_clock_info->usClassification2);
  1149. if (ATOM_PPLIB_NONCLOCKINFO_VER1 < table_rev) {
  1150. rps->vclk = le32_to_cpu(non_clock_info->ulVCLK);
  1151. rps->dclk = le32_to_cpu(non_clock_info->ulDCLK);
  1152. } else {
  1153. rps->vclk = 0;
  1154. rps->dclk = 0;
  1155. }
  1156. if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT) {
  1157. rdev->pm.dpm.boot_ps = rps;
  1158. sumo_patch_boot_state(rdev, ps);
  1159. }
  1160. if (rps->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE)
  1161. rdev->pm.dpm.uvd_ps = rps;
  1162. }
  1163. static void sumo_parse_pplib_clock_info(struct radeon_device *rdev,
  1164. struct radeon_ps *rps, int index,
  1165. union pplib_clock_info *clock_info)
  1166. {
  1167. struct sumo_power_info *pi = sumo_get_pi(rdev);
  1168. struct sumo_ps *ps = sumo_get_ps(rps);
  1169. struct sumo_pl *pl = &ps->levels[index];
  1170. u32 sclk;
  1171. sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
  1172. sclk |= clock_info->sumo.ucEngineClockHigh << 16;
  1173. pl->sclk = sclk;
  1174. pl->vddc_index = clock_info->sumo.vddcIndex;
  1175. pl->sclk_dpm_tdp_limit = clock_info->sumo.tdpLimit;
  1176. ps->num_levels = index + 1;
  1177. if (pi->enable_sclk_ds) {
  1178. pl->ds_divider_index = 5;
  1179. pl->ss_divider_index = 4;
  1180. }
  1181. }
  1182. static int sumo_parse_power_table(struct radeon_device *rdev)
  1183. {
  1184. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1185. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
  1186. union pplib_power_state *power_state;
  1187. int i, j, k, non_clock_array_index, clock_array_index;
  1188. union pplib_clock_info *clock_info;
  1189. struct _StateArray *state_array;
  1190. struct _ClockInfoArray *clock_info_array;
  1191. struct _NonClockInfoArray *non_clock_info_array;
  1192. union power_info *power_info;
  1193. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  1194. u16 data_offset;
  1195. u8 frev, crev;
  1196. u8 *power_state_offset;
  1197. struct sumo_ps *ps;
  1198. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  1199. &frev, &crev, &data_offset))
  1200. return -EINVAL;
  1201. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  1202. state_array = (struct _StateArray *)
  1203. (mode_info->atom_context->bios + data_offset +
  1204. le16_to_cpu(power_info->pplib.usStateArrayOffset));
  1205. clock_info_array = (struct _ClockInfoArray *)
  1206. (mode_info->atom_context->bios + data_offset +
  1207. le16_to_cpu(power_info->pplib.usClockInfoArrayOffset));
  1208. non_clock_info_array = (struct _NonClockInfoArray *)
  1209. (mode_info->atom_context->bios + data_offset +
  1210. le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset));
  1211. rdev->pm.dpm.ps = kzalloc(sizeof(struct radeon_ps) *
  1212. state_array->ucNumEntries, GFP_KERNEL);
  1213. if (!rdev->pm.dpm.ps)
  1214. return -ENOMEM;
  1215. power_state_offset = (u8 *)state_array->states;
  1216. for (i = 0; i < state_array->ucNumEntries; i++) {
  1217. u8 *idx;
  1218. power_state = (union pplib_power_state *)power_state_offset;
  1219. non_clock_array_index = power_state->v2.nonClockInfoIndex;
  1220. non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
  1221. &non_clock_info_array->nonClockInfo[non_clock_array_index];
  1222. if (!rdev->pm.power_state[i].clock_info)
  1223. return -EINVAL;
  1224. ps = kzalloc(sizeof(struct sumo_ps), GFP_KERNEL);
  1225. if (ps == NULL) {
  1226. kfree(rdev->pm.dpm.ps);
  1227. return -ENOMEM;
  1228. }
  1229. rdev->pm.dpm.ps[i].ps_priv = ps;
  1230. k = 0;
  1231. idx = (u8 *)&power_state->v2.clockInfoIndex[0];
  1232. for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
  1233. clock_array_index = idx[j];
  1234. if (k >= SUMO_MAX_HARDWARE_POWERLEVELS)
  1235. break;
  1236. clock_info = (union pplib_clock_info *)
  1237. ((u8 *)&clock_info_array->clockInfo[0] +
  1238. (clock_array_index * clock_info_array->ucEntrySize));
  1239. sumo_parse_pplib_clock_info(rdev,
  1240. &rdev->pm.dpm.ps[i], k,
  1241. clock_info);
  1242. k++;
  1243. }
  1244. sumo_parse_pplib_non_clock_info(rdev, &rdev->pm.dpm.ps[i],
  1245. non_clock_info,
  1246. non_clock_info_array->ucEntrySize);
  1247. power_state_offset += 2 + power_state->v2.ucNumDPMLevels;
  1248. }
  1249. rdev->pm.dpm.num_ps = state_array->ucNumEntries;
  1250. return 0;
  1251. }
  1252. u32 sumo_convert_vid2_to_vid7(struct radeon_device *rdev,
  1253. struct sumo_vid_mapping_table *vid_mapping_table,
  1254. u32 vid_2bit)
  1255. {
  1256. u32 i;
  1257. for (i = 0; i < vid_mapping_table->num_entries; i++) {
  1258. if (vid_mapping_table->entries[i].vid_2bit == vid_2bit)
  1259. return vid_mapping_table->entries[i].vid_7bit;
  1260. }
  1261. return vid_mapping_table->entries[vid_mapping_table->num_entries - 1].vid_7bit;
  1262. }
  1263. #if 0
  1264. u32 sumo_convert_vid7_to_vid2(struct radeon_device *rdev,
  1265. struct sumo_vid_mapping_table *vid_mapping_table,
  1266. u32 vid_7bit)
  1267. {
  1268. u32 i;
  1269. for (i = 0; i < vid_mapping_table->num_entries; i++) {
  1270. if (vid_mapping_table->entries[i].vid_7bit == vid_7bit)
  1271. return vid_mapping_table->entries[i].vid_2bit;
  1272. }
  1273. return vid_mapping_table->entries[vid_mapping_table->num_entries - 1].vid_2bit;
  1274. }
  1275. #endif
  1276. static u16 sumo_convert_voltage_index_to_value(struct radeon_device *rdev,
  1277. u32 vid_2bit)
  1278. {
  1279. struct sumo_power_info *pi = sumo_get_pi(rdev);
  1280. u32 vid_7bit = sumo_convert_vid2_to_vid7(rdev, &pi->sys_info.vid_mapping_table, vid_2bit);
  1281. if (vid_7bit > 0x7C)
  1282. return 0;
  1283. return (15500 - vid_7bit * 125 + 5) / 10;
  1284. }
  1285. static void sumo_construct_display_voltage_mapping_table(struct radeon_device *rdev,
  1286. struct sumo_disp_clock_voltage_mapping_table *disp_clk_voltage_mapping_table,
  1287. ATOM_CLK_VOLT_CAPABILITY *table)
  1288. {
  1289. u32 i;
  1290. for (i = 0; i < SUMO_MAX_NUMBER_VOLTAGES; i++) {
  1291. if (table[i].ulMaximumSupportedCLK == 0)
  1292. break;
  1293. disp_clk_voltage_mapping_table->display_clock_frequency[i] =
  1294. table[i].ulMaximumSupportedCLK;
  1295. }
  1296. disp_clk_voltage_mapping_table->num_max_voltage_levels = i;
  1297. if (disp_clk_voltage_mapping_table->num_max_voltage_levels == 0) {
  1298. disp_clk_voltage_mapping_table->display_clock_frequency[0] = 80000;
  1299. disp_clk_voltage_mapping_table->num_max_voltage_levels = 1;
  1300. }
  1301. }
  1302. void sumo_construct_sclk_voltage_mapping_table(struct radeon_device *rdev,
  1303. struct sumo_sclk_voltage_mapping_table *sclk_voltage_mapping_table,
  1304. ATOM_AVAILABLE_SCLK_LIST *table)
  1305. {
  1306. u32 i;
  1307. u32 n = 0;
  1308. u32 prev_sclk = 0;
  1309. for (i = 0; i < SUMO_MAX_HARDWARE_POWERLEVELS; i++) {
  1310. if (table[i].ulSupportedSCLK > prev_sclk) {
  1311. sclk_voltage_mapping_table->entries[n].sclk_frequency =
  1312. table[i].ulSupportedSCLK;
  1313. sclk_voltage_mapping_table->entries[n].vid_2bit =
  1314. table[i].usVoltageIndex;
  1315. prev_sclk = table[i].ulSupportedSCLK;
  1316. n++;
  1317. }
  1318. }
  1319. sclk_voltage_mapping_table->num_max_dpm_entries = n;
  1320. }
  1321. void sumo_construct_vid_mapping_table(struct radeon_device *rdev,
  1322. struct sumo_vid_mapping_table *vid_mapping_table,
  1323. ATOM_AVAILABLE_SCLK_LIST *table)
  1324. {
  1325. u32 i, j;
  1326. for (i = 0; i < SUMO_MAX_HARDWARE_POWERLEVELS; i++) {
  1327. if (table[i].ulSupportedSCLK != 0) {
  1328. vid_mapping_table->entries[table[i].usVoltageIndex].vid_7bit =
  1329. table[i].usVoltageID;
  1330. vid_mapping_table->entries[table[i].usVoltageIndex].vid_2bit =
  1331. table[i].usVoltageIndex;
  1332. }
  1333. }
  1334. for (i = 0; i < SUMO_MAX_NUMBER_VOLTAGES; i++) {
  1335. if (vid_mapping_table->entries[i].vid_7bit == 0) {
  1336. for (j = i + 1; j < SUMO_MAX_NUMBER_VOLTAGES; j++) {
  1337. if (vid_mapping_table->entries[j].vid_7bit != 0) {
  1338. vid_mapping_table->entries[i] =
  1339. vid_mapping_table->entries[j];
  1340. vid_mapping_table->entries[j].vid_7bit = 0;
  1341. break;
  1342. }
  1343. }
  1344. if (j == SUMO_MAX_NUMBER_VOLTAGES)
  1345. break;
  1346. }
  1347. }
  1348. vid_mapping_table->num_entries = i;
  1349. }
  1350. union igp_info {
  1351. struct _ATOM_INTEGRATED_SYSTEM_INFO info;
  1352. struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
  1353. struct _ATOM_INTEGRATED_SYSTEM_INFO_V5 info_5;
  1354. struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 info_6;
  1355. };
  1356. static int sumo_parse_sys_info_table(struct radeon_device *rdev)
  1357. {
  1358. struct sumo_power_info *pi = sumo_get_pi(rdev);
  1359. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1360. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  1361. union igp_info *igp_info;
  1362. u8 frev, crev;
  1363. u16 data_offset;
  1364. int i;
  1365. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1366. &frev, &crev, &data_offset)) {
  1367. igp_info = (union igp_info *)(mode_info->atom_context->bios +
  1368. data_offset);
  1369. if (crev != 6) {
  1370. DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
  1371. return -EINVAL;
  1372. }
  1373. pi->sys_info.bootup_sclk = le32_to_cpu(igp_info->info_6.ulBootUpEngineClock);
  1374. pi->sys_info.min_sclk = le32_to_cpu(igp_info->info_6.ulMinEngineClock);
  1375. pi->sys_info.bootup_uma_clk = le32_to_cpu(igp_info->info_6.ulBootUpUMAClock);
  1376. pi->sys_info.bootup_nb_voltage_index =
  1377. le16_to_cpu(igp_info->info_6.usBootUpNBVoltage);
  1378. if (igp_info->info_6.ucHtcTmpLmt == 0)
  1379. pi->sys_info.htc_tmp_lmt = 203;
  1380. else
  1381. pi->sys_info.htc_tmp_lmt = igp_info->info_6.ucHtcTmpLmt;
  1382. if (igp_info->info_6.ucHtcHystLmt == 0)
  1383. pi->sys_info.htc_hyst_lmt = 5;
  1384. else
  1385. pi->sys_info.htc_hyst_lmt = igp_info->info_6.ucHtcHystLmt;
  1386. if (pi->sys_info.htc_tmp_lmt <= pi->sys_info.htc_hyst_lmt) {
  1387. DRM_ERROR("The htcTmpLmt should be larger than htcHystLmt.\n");
  1388. }
  1389. for (i = 0; i < NUMBER_OF_M3ARB_PARAM_SETS; i++) {
  1390. pi->sys_info.csr_m3_arb_cntl_default[i] =
  1391. le32_to_cpu(igp_info->info_6.ulCSR_M3_ARB_CNTL_DEFAULT[i]);
  1392. pi->sys_info.csr_m3_arb_cntl_uvd[i] =
  1393. le32_to_cpu(igp_info->info_6.ulCSR_M3_ARB_CNTL_UVD[i]);
  1394. pi->sys_info.csr_m3_arb_cntl_fs3d[i] =
  1395. le32_to_cpu(igp_info->info_6.ulCSR_M3_ARB_CNTL_FS3D[i]);
  1396. }
  1397. pi->sys_info.sclk_dpm_boost_margin =
  1398. le32_to_cpu(igp_info->info_6.SclkDpmBoostMargin);
  1399. pi->sys_info.sclk_dpm_throttle_margin =
  1400. le32_to_cpu(igp_info->info_6.SclkDpmThrottleMargin);
  1401. pi->sys_info.sclk_dpm_tdp_limit_pg =
  1402. le16_to_cpu(igp_info->info_6.SclkDpmTdpLimitPG);
  1403. pi->sys_info.gnb_tdp_limit = le16_to_cpu(igp_info->info_6.GnbTdpLimit);
  1404. pi->sys_info.sclk_dpm_tdp_limit_boost =
  1405. le16_to_cpu(igp_info->info_6.SclkDpmTdpLimitBoost);
  1406. pi->sys_info.boost_sclk = le32_to_cpu(igp_info->info_6.ulBoostEngineCLock);
  1407. pi->sys_info.boost_vid_2bit = igp_info->info_6.ulBoostVid_2bit;
  1408. if (igp_info->info_6.EnableBoost)
  1409. pi->sys_info.enable_boost = true;
  1410. else
  1411. pi->sys_info.enable_boost = false;
  1412. sumo_construct_display_voltage_mapping_table(rdev,
  1413. &pi->sys_info.disp_clk_voltage_mapping_table,
  1414. igp_info->info_6.sDISPCLK_Voltage);
  1415. sumo_construct_sclk_voltage_mapping_table(rdev,
  1416. &pi->sys_info.sclk_voltage_mapping_table,
  1417. igp_info->info_6.sAvail_SCLK);
  1418. sumo_construct_vid_mapping_table(rdev, &pi->sys_info.vid_mapping_table,
  1419. igp_info->info_6.sAvail_SCLK);
  1420. }
  1421. return 0;
  1422. }
  1423. static void sumo_construct_boot_and_acpi_state(struct radeon_device *rdev)
  1424. {
  1425. struct sumo_power_info *pi = sumo_get_pi(rdev);
  1426. pi->boot_pl.sclk = pi->sys_info.bootup_sclk;
  1427. pi->boot_pl.vddc_index = pi->sys_info.bootup_nb_voltage_index;
  1428. pi->boot_pl.ds_divider_index = 0;
  1429. pi->boot_pl.ss_divider_index = 0;
  1430. pi->boot_pl.allow_gnb_slow = 1;
  1431. pi->acpi_pl = pi->boot_pl;
  1432. pi->current_ps.num_levels = 1;
  1433. pi->current_ps.levels[0] = pi->boot_pl;
  1434. }
  1435. int sumo_dpm_init(struct radeon_device *rdev)
  1436. {
  1437. struct sumo_power_info *pi;
  1438. u32 hw_rev = (RREG32(HW_REV) & ATI_REV_ID_MASK) >> ATI_REV_ID_SHIFT;
  1439. int ret;
  1440. pi = kzalloc(sizeof(struct sumo_power_info), GFP_KERNEL);
  1441. if (pi == NULL)
  1442. return -ENOMEM;
  1443. rdev->pm.dpm.priv = pi;
  1444. pi->driver_nbps_policy_disable = false;
  1445. if ((rdev->family == CHIP_PALM) && (hw_rev < 3))
  1446. pi->disable_gfx_power_gating_in_uvd = true;
  1447. else
  1448. pi->disable_gfx_power_gating_in_uvd = false;
  1449. pi->enable_alt_vddnb = true;
  1450. pi->enable_sclk_ds = true;
  1451. pi->enable_dynamic_m3_arbiter = false;
  1452. pi->enable_dynamic_patch_ps = true;
  1453. /* Some PALM chips don't seem to properly ungate gfx when UVD is in use;
  1454. * for now just disable gfx PG.
  1455. */
  1456. if (rdev->family == CHIP_PALM)
  1457. pi->enable_gfx_power_gating = false;
  1458. else
  1459. pi->enable_gfx_power_gating = true;
  1460. pi->enable_gfx_clock_gating = true;
  1461. pi->enable_mg_clock_gating = true;
  1462. pi->enable_auto_thermal_throttling = true;
  1463. ret = sumo_parse_sys_info_table(rdev);
  1464. if (ret)
  1465. return ret;
  1466. sumo_construct_boot_and_acpi_state(rdev);
  1467. ret = r600_get_platform_caps(rdev);
  1468. if (ret)
  1469. return ret;
  1470. ret = sumo_parse_power_table(rdev);
  1471. if (ret)
  1472. return ret;
  1473. pi->pasi = CYPRESS_HASI_DFLT;
  1474. pi->asi = RV770_ASI_DFLT;
  1475. pi->thermal_auto_throttling = pi->sys_info.htc_tmp_lmt;
  1476. pi->enable_boost = pi->sys_info.enable_boost;
  1477. pi->enable_dpm = true;
  1478. return 0;
  1479. }
  1480. void sumo_dpm_print_power_state(struct radeon_device *rdev,
  1481. struct radeon_ps *rps)
  1482. {
  1483. int i;
  1484. struct sumo_ps *ps = sumo_get_ps(rps);
  1485. r600_dpm_print_class_info(rps->class, rps->class2);
  1486. r600_dpm_print_cap_info(rps->caps);
  1487. printk("\tuvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
  1488. for (i = 0; i < ps->num_levels; i++) {
  1489. struct sumo_pl *pl = &ps->levels[i];
  1490. printk("\t\tpower level %d sclk: %u vddc: %u\n",
  1491. i, pl->sclk,
  1492. sumo_convert_voltage_index_to_value(rdev, pl->vddc_index));
  1493. }
  1494. r600_dpm_print_ps_status(rdev, rps);
  1495. }
  1496. void sumo_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev,
  1497. struct seq_file *m)
  1498. {
  1499. struct sumo_power_info *pi = sumo_get_pi(rdev);
  1500. struct radeon_ps *rps = &pi->current_rps;
  1501. struct sumo_ps *ps = sumo_get_ps(rps);
  1502. struct sumo_pl *pl;
  1503. u32 current_index =
  1504. (RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURR_INDEX_MASK) >>
  1505. CURR_INDEX_SHIFT;
  1506. if (current_index == BOOST_DPM_LEVEL) {
  1507. pl = &pi->boost_pl;
  1508. seq_printf(m, "uvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
  1509. seq_printf(m, "power level %d sclk: %u vddc: %u\n",
  1510. current_index, pl->sclk,
  1511. sumo_convert_voltage_index_to_value(rdev, pl->vddc_index));
  1512. } else if (current_index >= ps->num_levels) {
  1513. seq_printf(m, "invalid dpm profile %d\n", current_index);
  1514. } else {
  1515. pl = &ps->levels[current_index];
  1516. seq_printf(m, "uvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
  1517. seq_printf(m, "power level %d sclk: %u vddc: %u\n",
  1518. current_index, pl->sclk,
  1519. sumo_convert_voltage_index_to_value(rdev, pl->vddc_index));
  1520. }
  1521. }
  1522. u32 sumo_dpm_get_current_sclk(struct radeon_device *rdev)
  1523. {
  1524. struct sumo_power_info *pi = sumo_get_pi(rdev);
  1525. struct radeon_ps *rps = &pi->current_rps;
  1526. struct sumo_ps *ps = sumo_get_ps(rps);
  1527. struct sumo_pl *pl;
  1528. u32 current_index =
  1529. (RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURR_INDEX_MASK) >>
  1530. CURR_INDEX_SHIFT;
  1531. if (current_index == BOOST_DPM_LEVEL) {
  1532. pl = &pi->boost_pl;
  1533. return pl->sclk;
  1534. } else if (current_index >= ps->num_levels) {
  1535. return 0;
  1536. } else {
  1537. pl = &ps->levels[current_index];
  1538. return pl->sclk;
  1539. }
  1540. }
  1541. u32 sumo_dpm_get_current_mclk(struct radeon_device *rdev)
  1542. {
  1543. struct sumo_power_info *pi = sumo_get_pi(rdev);
  1544. return pi->sys_info.bootup_uma_clk;
  1545. }
  1546. void sumo_dpm_fini(struct radeon_device *rdev)
  1547. {
  1548. int i;
  1549. sumo_cleanup_asic(rdev); /* ??? */
  1550. for (i = 0; i < rdev->pm.dpm.num_ps; i++) {
  1551. kfree(rdev->pm.dpm.ps[i].ps_priv);
  1552. }
  1553. kfree(rdev->pm.dpm.ps);
  1554. kfree(rdev->pm.dpm.priv);
  1555. }
  1556. u32 sumo_dpm_get_sclk(struct radeon_device *rdev, bool low)
  1557. {
  1558. struct sumo_power_info *pi = sumo_get_pi(rdev);
  1559. struct sumo_ps *requested_state = sumo_get_ps(&pi->requested_rps);
  1560. if (low)
  1561. return requested_state->levels[0].sclk;
  1562. else
  1563. return requested_state->levels[requested_state->num_levels - 1].sclk;
  1564. }
  1565. u32 sumo_dpm_get_mclk(struct radeon_device *rdev, bool low)
  1566. {
  1567. struct sumo_power_info *pi = sumo_get_pi(rdev);
  1568. return pi->sys_info.bootup_uma_clk;
  1569. }
  1570. int sumo_dpm_force_performance_level(struct radeon_device *rdev,
  1571. enum radeon_dpm_forced_level level)
  1572. {
  1573. struct sumo_power_info *pi = sumo_get_pi(rdev);
  1574. struct radeon_ps *rps = &pi->current_rps;
  1575. struct sumo_ps *ps = sumo_get_ps(rps);
  1576. int i;
  1577. if (ps->num_levels <= 1)
  1578. return 0;
  1579. if (level == RADEON_DPM_FORCED_LEVEL_HIGH) {
  1580. if (pi->enable_boost)
  1581. sumo_enable_boost(rdev, rps, false);
  1582. sumo_power_level_enable(rdev, ps->num_levels - 1, true);
  1583. sumo_set_forced_level(rdev, ps->num_levels - 1);
  1584. sumo_set_forced_mode_enabled(rdev);
  1585. for (i = 0; i < ps->num_levels - 1; i++) {
  1586. sumo_power_level_enable(rdev, i, false);
  1587. }
  1588. sumo_set_forced_mode(rdev, false);
  1589. sumo_set_forced_mode_enabled(rdev);
  1590. sumo_set_forced_mode(rdev, false);
  1591. } else if (level == RADEON_DPM_FORCED_LEVEL_LOW) {
  1592. if (pi->enable_boost)
  1593. sumo_enable_boost(rdev, rps, false);
  1594. sumo_power_level_enable(rdev, 0, true);
  1595. sumo_set_forced_level(rdev, 0);
  1596. sumo_set_forced_mode_enabled(rdev);
  1597. for (i = 1; i < ps->num_levels; i++) {
  1598. sumo_power_level_enable(rdev, i, false);
  1599. }
  1600. sumo_set_forced_mode(rdev, false);
  1601. sumo_set_forced_mode_enabled(rdev);
  1602. sumo_set_forced_mode(rdev, false);
  1603. } else {
  1604. for (i = 0; i < ps->num_levels; i++) {
  1605. sumo_power_level_enable(rdev, i, true);
  1606. }
  1607. if (pi->enable_boost)
  1608. sumo_enable_boost(rdev, rps, true);
  1609. }
  1610. rdev->pm.dpm.forced_level = level;
  1611. return 0;
  1612. }