intel_clock_gating.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. /*
  2. * Copyright © 2012 Intel Corporation
  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 (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eugeni Dodonov <eugeni.dodonov@intel.com>
  25. *
  26. */
  27. #include "display/i9xx_plane_regs.h"
  28. #include "display/intel_display.h"
  29. #include "gt/intel_engine_regs.h"
  30. #include "gt/intel_gt.h"
  31. #include "gt/intel_gt_mcr.h"
  32. #include "gt/intel_gt_regs.h"
  33. #include "i915_drv.h"
  34. #include "i915_reg.h"
  35. #include "intel_clock_gating.h"
  36. #include "intel_mchbar_regs.h"
  37. #include "vlv_sideband.h"
  38. struct drm_i915_clock_gating_funcs {
  39. void (*init_clock_gating)(struct drm_i915_private *i915);
  40. };
  41. static void gen9_init_clock_gating(struct drm_i915_private *i915)
  42. {
  43. if (HAS_LLC(i915)) {
  44. /*
  45. * WaCompressedResourceDisplayNewHashMode:skl,kbl
  46. * Display WA #0390: skl,kbl
  47. *
  48. * Must match Sampler, Pixel Back End, and Media. See
  49. * WaCompressedResourceSamplerPbeMediaNewHashMode.
  50. */
  51. intel_uncore_rmw(&i915->uncore, CHICKEN_PAR1_1, 0, SKL_DE_COMPRESSED_HASH_MODE);
  52. }
  53. /* See Bspec note for PSR2_CTL bit 31, Wa#828:skl,bxt,kbl,cfl */
  54. intel_uncore_rmw(&i915->uncore, CHICKEN_PAR1_1, 0, SKL_EDP_PSR_FIX_RDWRAP);
  55. /* WaEnableChickenDCPR:skl,bxt,kbl,glk,cfl */
  56. intel_uncore_rmw(&i915->uncore, GEN8_CHICKEN_DCPR_1, 0, MASK_WAKEMEM);
  57. /*
  58. * WaFbcWakeMemOn:skl,bxt,kbl,glk,cfl
  59. * Display WA #0859: skl,bxt,kbl,glk,cfl
  60. */
  61. intel_uncore_rmw(&i915->uncore, DISP_ARB_CTL, 0, DISP_FBC_MEMORY_WAKE);
  62. }
  63. static void bxt_init_clock_gating(struct drm_i915_private *i915)
  64. {
  65. gen9_init_clock_gating(i915);
  66. /* WaDisableSDEUnitClockGating:bxt */
  67. intel_uncore_rmw(&i915->uncore, GEN8_UCGCTL6, 0, GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
  68. /*
  69. * FIXME:
  70. * GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ applies on 3x6 GT SKUs only.
  71. */
  72. intel_uncore_rmw(&i915->uncore, GEN8_UCGCTL6, 0, GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ);
  73. /*
  74. * Wa: Backlight PWM may stop in the asserted state, causing backlight
  75. * to stay fully on.
  76. */
  77. intel_uncore_write(&i915->uncore, GEN9_CLKGATE_DIS_0,
  78. intel_uncore_read(&i915->uncore, GEN9_CLKGATE_DIS_0) |
  79. PWM1_GATING_DIS | PWM2_GATING_DIS);
  80. /*
  81. * Lower the display internal timeout.
  82. * This is needed to avoid any hard hangs when DSI port PLL
  83. * is off and a MMIO access is attempted by any privilege
  84. * application, using batch buffers or any other means.
  85. */
  86. intel_uncore_write(&i915->uncore, RM_TIMEOUT, MMIO_TIMEOUT_US(950));
  87. /*
  88. * WaFbcTurnOffFbcWatermark:bxt
  89. * Display WA #0562: bxt
  90. */
  91. intel_uncore_rmw(&i915->uncore, DISP_ARB_CTL, 0, DISP_FBC_WM_DIS);
  92. }
  93. static void glk_init_clock_gating(struct drm_i915_private *i915)
  94. {
  95. gen9_init_clock_gating(i915);
  96. /*
  97. * WaDisablePWMClockGating:glk
  98. * Backlight PWM may stop in the asserted state, causing backlight
  99. * to stay fully on.
  100. */
  101. intel_uncore_write(&i915->uncore, GEN9_CLKGATE_DIS_0,
  102. intel_uncore_read(&i915->uncore, GEN9_CLKGATE_DIS_0) |
  103. PWM1_GATING_DIS | PWM2_GATING_DIS);
  104. }
  105. static void ibx_init_clock_gating(struct drm_i915_private *i915)
  106. {
  107. /*
  108. * On Ibex Peak and Cougar Point, we need to disable clock
  109. * gating for the panel power sequencer or it will fail to
  110. * start up when no ports are active.
  111. */
  112. intel_uncore_write(&i915->uncore, SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE);
  113. }
  114. static void g4x_disable_trickle_feed(struct drm_i915_private *dev_priv)
  115. {
  116. enum pipe pipe;
  117. for_each_pipe(dev_priv, pipe) {
  118. intel_uncore_rmw(&dev_priv->uncore, DSPCNTR(dev_priv, pipe),
  119. 0, DISP_TRICKLE_FEED_DISABLE);
  120. intel_uncore_rmw(&dev_priv->uncore, DSPSURF(dev_priv, pipe),
  121. 0, 0);
  122. intel_uncore_posting_read(&dev_priv->uncore,
  123. DSPSURF(dev_priv, pipe));
  124. }
  125. }
  126. static void ilk_init_clock_gating(struct drm_i915_private *i915)
  127. {
  128. u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE;
  129. /*
  130. * Required for FBC
  131. * WaFbcDisableDpfcClockGating:ilk
  132. */
  133. dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE |
  134. ILK_DPFCUNIT_CLOCK_GATE_DISABLE |
  135. ILK_DPFDUNIT_CLOCK_GATE_ENABLE;
  136. intel_uncore_write(&i915->uncore, PCH_3DCGDIS0,
  137. MARIUNIT_CLOCK_GATE_DISABLE |
  138. SVSMUNIT_CLOCK_GATE_DISABLE);
  139. intel_uncore_write(&i915->uncore, PCH_3DCGDIS1,
  140. VFMUNIT_CLOCK_GATE_DISABLE);
  141. /*
  142. * According to the spec the following bits should be set in
  143. * order to enable memory self-refresh
  144. * The bit 22/21 of 0x42004
  145. * The bit 5 of 0x42020
  146. * The bit 15 of 0x45000
  147. */
  148. intel_uncore_write(&i915->uncore, ILK_DISPLAY_CHICKEN2,
  149. (intel_uncore_read(&i915->uncore, ILK_DISPLAY_CHICKEN2) |
  150. ILK_DPARB_GATE | ILK_VSDPFD_FULL));
  151. dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE;
  152. intel_uncore_write(&i915->uncore, DISP_ARB_CTL,
  153. (intel_uncore_read(&i915->uncore, DISP_ARB_CTL) |
  154. DISP_FBC_WM_DIS));
  155. /*
  156. * Based on the document from hardware guys the following bits
  157. * should be set unconditionally in order to enable FBC.
  158. * The bit 22 of 0x42000
  159. * The bit 22 of 0x42004
  160. * The bit 7,8,9 of 0x42020.
  161. */
  162. if (IS_IRONLAKE_M(i915)) {
  163. /* WaFbcAsynchFlipDisableFbcQueue:ilk */
  164. intel_uncore_rmw(&i915->uncore, ILK_DISPLAY_CHICKEN1, 0, ILK_FBCQ_DIS);
  165. intel_uncore_rmw(&i915->uncore, ILK_DISPLAY_CHICKEN2, 0, ILK_DPARB_GATE);
  166. }
  167. intel_uncore_write(&i915->uncore, ILK_DSPCLK_GATE_D, dspclk_gate);
  168. intel_uncore_rmw(&i915->uncore, ILK_DISPLAY_CHICKEN2, 0, ILK_ELPIN_409_SELECT);
  169. g4x_disable_trickle_feed(i915);
  170. ibx_init_clock_gating(i915);
  171. }
  172. static void cpt_init_clock_gating(struct drm_i915_private *i915)
  173. {
  174. enum pipe pipe;
  175. u32 val;
  176. /*
  177. * On Ibex Peak and Cougar Point, we need to disable clock
  178. * gating for the panel power sequencer or it will fail to
  179. * start up when no ports are active.
  180. */
  181. intel_uncore_write(&i915->uncore, SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE |
  182. PCH_DPLUNIT_CLOCK_GATE_DISABLE |
  183. PCH_CPUNIT_CLOCK_GATE_DISABLE);
  184. intel_uncore_rmw(&i915->uncore, SOUTH_CHICKEN2, 0, DPLS_EDP_PPS_FIX_DIS);
  185. /* The below fixes the weird display corruption, a few pixels shifted
  186. * downward, on (only) LVDS of some HP laptops with IVY.
  187. */
  188. for_each_pipe(i915, pipe) {
  189. val = intel_uncore_read(&i915->uncore, TRANS_CHICKEN2(pipe));
  190. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  191. val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED;
  192. if (i915->display.vbt.fdi_rx_polarity_inverted)
  193. val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED;
  194. val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER;
  195. val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH;
  196. intel_uncore_write(&i915->uncore, TRANS_CHICKEN2(pipe), val);
  197. }
  198. /* WADP0ClockGatingDisable */
  199. for_each_pipe(i915, pipe) {
  200. intel_uncore_write(&i915->uncore, TRANS_CHICKEN1(pipe),
  201. TRANS_CHICKEN1_DP0UNIT_GC_DISABLE);
  202. }
  203. }
  204. static void gen6_check_mch_setup(struct drm_i915_private *i915)
  205. {
  206. u32 tmp;
  207. tmp = intel_uncore_read(&i915->uncore, MCH_SSKPD);
  208. if (REG_FIELD_GET(SSKPD_WM0_MASK_SNB, tmp) != 12)
  209. drm_dbg_kms(&i915->drm,
  210. "Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n",
  211. tmp);
  212. }
  213. static void gen6_init_clock_gating(struct drm_i915_private *i915)
  214. {
  215. u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE;
  216. intel_uncore_write(&i915->uncore, ILK_DSPCLK_GATE_D, dspclk_gate);
  217. intel_uncore_rmw(&i915->uncore, ILK_DISPLAY_CHICKEN2, 0, ILK_ELPIN_409_SELECT);
  218. intel_uncore_write(&i915->uncore, GEN6_UCGCTL1,
  219. intel_uncore_read(&i915->uncore, GEN6_UCGCTL1) |
  220. GEN6_BLBUNIT_CLOCK_GATE_DISABLE |
  221. GEN6_CSUNIT_CLOCK_GATE_DISABLE);
  222. /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock
  223. * gating disable must be set. Failure to set it results in
  224. * flickering pixels due to Z write ordering failures after
  225. * some amount of runtime in the Mesa "fire" demo, and Unigine
  226. * Sanctuary and Tropics, and apparently anything else with
  227. * alpha test or pixel discard.
  228. *
  229. * According to the spec, bit 11 (RCCUNIT) must also be set,
  230. * but we didn't debug actual testcases to find it out.
  231. *
  232. * WaDisableRCCUnitClockGating:snb
  233. * WaDisableRCPBUnitClockGating:snb
  234. */
  235. intel_uncore_write(&i915->uncore, GEN6_UCGCTL2,
  236. GEN6_RCPBUNIT_CLOCK_GATE_DISABLE |
  237. GEN6_RCCUNIT_CLOCK_GATE_DISABLE);
  238. /*
  239. * According to the spec the following bits should be
  240. * set in order to enable memory self-refresh and fbc:
  241. * The bit21 and bit22 of 0x42000
  242. * The bit21 and bit22 of 0x42004
  243. * The bit5 and bit7 of 0x42020
  244. * The bit14 of 0x70180
  245. * The bit14 of 0x71180
  246. *
  247. * WaFbcAsynchFlipDisableFbcQueue:snb
  248. */
  249. intel_uncore_write(&i915->uncore, ILK_DISPLAY_CHICKEN1,
  250. intel_uncore_read(&i915->uncore, ILK_DISPLAY_CHICKEN1) |
  251. ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS);
  252. intel_uncore_write(&i915->uncore, ILK_DISPLAY_CHICKEN2,
  253. intel_uncore_read(&i915->uncore, ILK_DISPLAY_CHICKEN2) |
  254. ILK_DPARB_GATE | ILK_VSDPFD_FULL);
  255. intel_uncore_write(&i915->uncore, ILK_DSPCLK_GATE_D,
  256. intel_uncore_read(&i915->uncore, ILK_DSPCLK_GATE_D) |
  257. ILK_DPARBUNIT_CLOCK_GATE_ENABLE |
  258. ILK_DPFDUNIT_CLOCK_GATE_ENABLE);
  259. g4x_disable_trickle_feed(i915);
  260. cpt_init_clock_gating(i915);
  261. gen6_check_mch_setup(i915);
  262. }
  263. static void lpt_init_clock_gating(struct drm_i915_private *i915)
  264. {
  265. /*
  266. * TODO: this bit should only be enabled when really needed, then
  267. * disabled when not needed anymore in order to save power.
  268. */
  269. if (HAS_PCH_LPT_LP(i915))
  270. intel_uncore_rmw(&i915->uncore, SOUTH_DSPCLK_GATE_D,
  271. 0, PCH_LP_PARTITION_LEVEL_DISABLE);
  272. /* WADPOClockGatingDisable:hsw */
  273. intel_uncore_rmw(&i915->uncore, TRANS_CHICKEN1(PIPE_A),
  274. 0, TRANS_CHICKEN1_DP0UNIT_GC_DISABLE);
  275. }
  276. static void gen8_set_l3sqc_credits(struct drm_i915_private *i915,
  277. int general_prio_credits,
  278. int high_prio_credits)
  279. {
  280. u32 misccpctl;
  281. u32 val;
  282. /* WaTempDisableDOPClkGating:bdw */
  283. misccpctl = intel_uncore_rmw(&i915->uncore, GEN7_MISCCPCTL,
  284. GEN7_DOP_CLOCK_GATE_ENABLE, 0);
  285. val = intel_gt_mcr_read_any(to_gt(i915), GEN8_L3SQCREG1);
  286. val &= ~L3_PRIO_CREDITS_MASK;
  287. val |= L3_GENERAL_PRIO_CREDITS(general_prio_credits);
  288. val |= L3_HIGH_PRIO_CREDITS(high_prio_credits);
  289. intel_gt_mcr_multicast_write(to_gt(i915), GEN8_L3SQCREG1, val);
  290. /*
  291. * Wait at least 100 clocks before re-enabling clock gating.
  292. * See the definition of L3SQCREG1 in BSpec.
  293. */
  294. intel_gt_mcr_read_any(to_gt(i915), GEN8_L3SQCREG1);
  295. udelay(1);
  296. intel_uncore_write(&i915->uncore, GEN7_MISCCPCTL, misccpctl);
  297. }
  298. static void dg2_init_clock_gating(struct drm_i915_private *i915)
  299. {
  300. /* Wa_22010954014:dg2 */
  301. intel_uncore_rmw(&i915->uncore, XEHP_CLOCK_GATE_DIS, 0,
  302. SGSI_SIDECLK_DIS);
  303. }
  304. static void cnp_init_clock_gating(struct drm_i915_private *i915)
  305. {
  306. if (!HAS_PCH_CNP(i915))
  307. return;
  308. /* Display WA #1181 WaSouthDisplayDisablePWMCGEGating: cnp */
  309. intel_uncore_rmw(&i915->uncore, SOUTH_DSPCLK_GATE_D, 0, CNP_PWM_CGE_GATING_DISABLE);
  310. }
  311. static void cfl_init_clock_gating(struct drm_i915_private *i915)
  312. {
  313. cnp_init_clock_gating(i915);
  314. gen9_init_clock_gating(i915);
  315. /* WAC6entrylatency:cfl */
  316. intel_uncore_rmw(&i915->uncore, FBC_LLC_READ_CTRL, 0, FBC_LLC_FULLY_OPEN);
  317. /*
  318. * WaFbcTurnOffFbcWatermark:cfl
  319. * Display WA #0562: cfl
  320. */
  321. intel_uncore_rmw(&i915->uncore, DISP_ARB_CTL, 0, DISP_FBC_WM_DIS);
  322. }
  323. static void kbl_init_clock_gating(struct drm_i915_private *i915)
  324. {
  325. gen9_init_clock_gating(i915);
  326. /* WAC6entrylatency:kbl */
  327. intel_uncore_rmw(&i915->uncore, FBC_LLC_READ_CTRL, 0, FBC_LLC_FULLY_OPEN);
  328. /* WaDisableSDEUnitClockGating:kbl */
  329. if (IS_KABYLAKE(i915) && IS_GRAPHICS_STEP(i915, 0, STEP_C0))
  330. intel_uncore_rmw(&i915->uncore, GEN8_UCGCTL6,
  331. 0, GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
  332. /* WaDisableGamClockGating:kbl */
  333. if (IS_KABYLAKE(i915) && IS_GRAPHICS_STEP(i915, 0, STEP_C0))
  334. intel_uncore_rmw(&i915->uncore, GEN6_UCGCTL1,
  335. 0, GEN6_GAMUNIT_CLOCK_GATE_DISABLE);
  336. /*
  337. * WaFbcTurnOffFbcWatermark:kbl
  338. * Display WA #0562: kbl
  339. */
  340. intel_uncore_rmw(&i915->uncore, DISP_ARB_CTL, 0, DISP_FBC_WM_DIS);
  341. }
  342. static void skl_init_clock_gating(struct drm_i915_private *i915)
  343. {
  344. gen9_init_clock_gating(i915);
  345. /* WaDisableDopClockGating:skl */
  346. intel_uncore_rmw(&i915->uncore, GEN7_MISCCPCTL,
  347. GEN7_DOP_CLOCK_GATE_ENABLE, 0);
  348. /* WAC6entrylatency:skl */
  349. intel_uncore_rmw(&i915->uncore, FBC_LLC_READ_CTRL, 0, FBC_LLC_FULLY_OPEN);
  350. /*
  351. * WaFbcTurnOffFbcWatermark:skl
  352. * Display WA #0562: skl
  353. */
  354. intel_uncore_rmw(&i915->uncore, DISP_ARB_CTL, 0, DISP_FBC_WM_DIS);
  355. }
  356. static void bdw_init_clock_gating(struct drm_i915_private *i915)
  357. {
  358. enum pipe pipe;
  359. /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */
  360. intel_uncore_rmw(&i915->uncore, CHICKEN_PIPESL_1(PIPE_A), 0, HSW_FBCQ_DIS);
  361. /* WaSwitchSolVfFArbitrationPriority:bdw */
  362. intel_uncore_rmw(&i915->uncore, GAM_ECOCHK, 0, HSW_ECOCHK_ARB_PRIO_SOL);
  363. /* WaPsrDPAMaskVBlankInSRD:bdw */
  364. intel_uncore_rmw(&i915->uncore, CHICKEN_PAR1_1, 0, HSW_MASK_VBL_TO_PIPE_IN_SRD);
  365. for_each_pipe(i915, pipe) {
  366. /* WaPsrDPRSUnmaskVBlankInSRD:bdw */
  367. intel_uncore_rmw(&i915->uncore, CHICKEN_PIPESL_1(pipe),
  368. 0, BDW_UNMASK_VBL_TO_REGS_IN_SRD);
  369. }
  370. /* WaVSRefCountFullforceMissDisable:bdw */
  371. /* WaDSRefCountFullforceMissDisable:bdw */
  372. intel_uncore_rmw(&i915->uncore, GEN7_FF_THREAD_MODE,
  373. GEN8_FF_DS_REF_CNT_FFME | GEN7_FF_VS_REF_CNT_FFME, 0);
  374. intel_uncore_write(&i915->uncore, RING_PSMI_CTL(RENDER_RING_BASE),
  375. _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE));
  376. /* WaDisableSDEUnitClockGating:bdw */
  377. intel_uncore_rmw(&i915->uncore, GEN8_UCGCTL6, 0, GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
  378. /* WaProgramL3SqcReg1Default:bdw */
  379. gen8_set_l3sqc_credits(i915, 30, 2);
  380. /* WaKVMNotificationOnConfigChange:bdw */
  381. intel_uncore_rmw(&i915->uncore, CHICKEN_PAR2_1,
  382. 0, KVM_CONFIG_CHANGE_NOTIFICATION_SELECT);
  383. lpt_init_clock_gating(i915);
  384. /* WaDisableDopClockGating:bdw
  385. *
  386. * Also see the CHICKEN2 write in bdw_init_workarounds() to disable DOP
  387. * clock gating.
  388. */
  389. intel_uncore_rmw(&i915->uncore, GEN6_UCGCTL1, 0, GEN6_EU_TCUNIT_CLOCK_GATE_DISABLE);
  390. }
  391. static void hsw_init_clock_gating(struct drm_i915_private *i915)
  392. {
  393. enum pipe pipe;
  394. /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */
  395. intel_uncore_rmw(&i915->uncore, CHICKEN_PIPESL_1(PIPE_A), 0, HSW_FBCQ_DIS);
  396. /* WaPsrDPAMaskVBlankInSRD:hsw */
  397. intel_uncore_rmw(&i915->uncore, CHICKEN_PAR1_1, 0, HSW_MASK_VBL_TO_PIPE_IN_SRD);
  398. for_each_pipe(i915, pipe) {
  399. /* WaPsrDPRSUnmaskVBlankInSRD:hsw */
  400. intel_uncore_rmw(&i915->uncore, CHICKEN_PIPESL_1(pipe),
  401. 0, HSW_UNMASK_VBL_TO_REGS_IN_SRD);
  402. }
  403. /* This is required by WaCatErrorRejectionIssue:hsw */
  404. intel_uncore_rmw(&i915->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG,
  405. 0, GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB);
  406. /* WaSwitchSolVfFArbitrationPriority:hsw */
  407. intel_uncore_rmw(&i915->uncore, GAM_ECOCHK, 0, HSW_ECOCHK_ARB_PRIO_SOL);
  408. lpt_init_clock_gating(i915);
  409. }
  410. static void ivb_init_clock_gating(struct drm_i915_private *i915)
  411. {
  412. intel_uncore_write(&i915->uncore, ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE);
  413. /* WaFbcAsynchFlipDisableFbcQueue:ivb */
  414. intel_uncore_rmw(&i915->uncore, ILK_DISPLAY_CHICKEN1, 0, ILK_FBCQ_DIS);
  415. /* WaDisableBackToBackFlipFix:ivb */
  416. intel_uncore_write(&i915->uncore, IVB_CHICKEN3,
  417. CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE |
  418. CHICKEN3_DGMG_DONE_FIX_DISABLE);
  419. if (IS_IVB_GT1(i915))
  420. intel_uncore_write(&i915->uncore, GEN7_ROW_CHICKEN2,
  421. _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
  422. else {
  423. /* must write both registers */
  424. intel_uncore_write(&i915->uncore, GEN7_ROW_CHICKEN2,
  425. _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
  426. intel_uncore_write(&i915->uncore, GEN7_ROW_CHICKEN2_GT2,
  427. _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
  428. }
  429. /*
  430. * According to the spec, bit 13 (RCZUNIT) must be set on IVB.
  431. * This implements the WaDisableRCZUnitClockGating:ivb workaround.
  432. */
  433. intel_uncore_write(&i915->uncore, GEN6_UCGCTL2,
  434. GEN6_RCZUNIT_CLOCK_GATE_DISABLE);
  435. /* This is required by WaCatErrorRejectionIssue:ivb */
  436. intel_uncore_rmw(&i915->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG,
  437. 0, GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB);
  438. g4x_disable_trickle_feed(i915);
  439. intel_uncore_rmw(&i915->uncore, GEN6_MBCUNIT_SNPCR, GEN6_MBC_SNPCR_MASK,
  440. GEN6_MBC_SNPCR_MED);
  441. if (!HAS_PCH_NOP(i915))
  442. cpt_init_clock_gating(i915);
  443. gen6_check_mch_setup(i915);
  444. }
  445. static void vlv_init_clock_gating(struct drm_i915_private *i915)
  446. {
  447. /* WaDisableBackToBackFlipFix:vlv */
  448. intel_uncore_write(&i915->uncore, IVB_CHICKEN3,
  449. CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE |
  450. CHICKEN3_DGMG_DONE_FIX_DISABLE);
  451. /* WaDisableDopClockGating:vlv */
  452. intel_uncore_write(&i915->uncore, GEN7_ROW_CHICKEN2,
  453. _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
  454. /* This is required by WaCatErrorRejectionIssue:vlv */
  455. intel_uncore_rmw(&i915->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG,
  456. 0, GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB);
  457. /*
  458. * According to the spec, bit 13 (RCZUNIT) must be set on IVB.
  459. * This implements the WaDisableRCZUnitClockGating:vlv workaround.
  460. */
  461. intel_uncore_write(&i915->uncore, GEN6_UCGCTL2,
  462. GEN6_RCZUNIT_CLOCK_GATE_DISABLE);
  463. /* WaDisableL3Bank2xClockGate:vlv
  464. * Disabling L3 clock gating- MMIO 940c[25] = 1
  465. * Set bit 25, to disable L3_BANK_2x_CLK_GATING */
  466. intel_uncore_rmw(&i915->uncore, GEN7_UCGCTL4, 0, GEN7_L3BANK2X_CLOCK_GATE_DISABLE);
  467. /*
  468. * WaDisableVLVClockGating_VBIIssue:vlv
  469. * Disable clock gating on th GCFG unit to prevent a delay
  470. * in the reporting of vblank events.
  471. */
  472. intel_uncore_write(&i915->uncore, VLV_GUNIT_CLOCK_GATE, GCFG_DIS);
  473. }
  474. static void chv_init_clock_gating(struct drm_i915_private *i915)
  475. {
  476. /* WaVSRefCountFullforceMissDisable:chv */
  477. /* WaDSRefCountFullforceMissDisable:chv */
  478. intel_uncore_rmw(&i915->uncore, GEN7_FF_THREAD_MODE,
  479. GEN8_FF_DS_REF_CNT_FFME | GEN7_FF_VS_REF_CNT_FFME, 0);
  480. /* WaDisableSemaphoreAndSyncFlipWait:chv */
  481. intel_uncore_write(&i915->uncore, RING_PSMI_CTL(RENDER_RING_BASE),
  482. _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE));
  483. /* WaDisableCSUnitClockGating:chv */
  484. intel_uncore_rmw(&i915->uncore, GEN6_UCGCTL1, 0, GEN6_CSUNIT_CLOCK_GATE_DISABLE);
  485. /* WaDisableSDEUnitClockGating:chv */
  486. intel_uncore_rmw(&i915->uncore, GEN8_UCGCTL6, 0, GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
  487. /*
  488. * WaProgramL3SqcReg1Default:chv
  489. * See gfxspecs/Related Documents/Performance Guide/
  490. * LSQC Setting Recommendations.
  491. */
  492. gen8_set_l3sqc_credits(i915, 38, 2);
  493. }
  494. static void g4x_init_clock_gating(struct drm_i915_private *i915)
  495. {
  496. u32 dspclk_gate;
  497. intel_uncore_write(&i915->uncore, RENCLK_GATE_D1, 0);
  498. intel_uncore_write(&i915->uncore, RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE |
  499. GS_UNIT_CLOCK_GATE_DISABLE |
  500. CL_UNIT_CLOCK_GATE_DISABLE);
  501. intel_uncore_write(&i915->uncore, RAMCLK_GATE_D, 0);
  502. dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE |
  503. OVRUNIT_CLOCK_GATE_DISABLE |
  504. OVCUNIT_CLOCK_GATE_DISABLE;
  505. if (IS_GM45(i915))
  506. dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE;
  507. intel_uncore_write(&i915->uncore, DSPCLK_GATE_D(i915), dspclk_gate);
  508. g4x_disable_trickle_feed(i915);
  509. }
  510. static void i965gm_init_clock_gating(struct drm_i915_private *i915)
  511. {
  512. struct intel_uncore *uncore = &i915->uncore;
  513. intel_uncore_write(uncore, RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE);
  514. intel_uncore_write(uncore, RENCLK_GATE_D2, 0);
  515. intel_uncore_write(uncore, DSPCLK_GATE_D(i915), 0);
  516. intel_uncore_write(uncore, RAMCLK_GATE_D, 0);
  517. intel_uncore_write16(uncore, DEUC, 0);
  518. intel_uncore_write(uncore,
  519. MI_ARB_STATE,
  520. _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE));
  521. }
  522. static void i965g_init_clock_gating(struct drm_i915_private *i915)
  523. {
  524. intel_uncore_write(&i915->uncore, RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE |
  525. I965_RCC_CLOCK_GATE_DISABLE |
  526. I965_RCPB_CLOCK_GATE_DISABLE |
  527. I965_ISC_CLOCK_GATE_DISABLE |
  528. I965_FBC_CLOCK_GATE_DISABLE);
  529. intel_uncore_write(&i915->uncore, RENCLK_GATE_D2, 0);
  530. intel_uncore_write(&i915->uncore, MI_ARB_STATE,
  531. _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE));
  532. }
  533. static void gen3_init_clock_gating(struct drm_i915_private *i915)
  534. {
  535. u32 dstate = intel_uncore_read(&i915->uncore, D_STATE);
  536. dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING |
  537. DSTATE_DOT_CLOCK_GATING;
  538. intel_uncore_write(&i915->uncore, D_STATE, dstate);
  539. if (IS_PINEVIEW(i915))
  540. intel_uncore_write(&i915->uncore, ECOSKPD(RENDER_RING_BASE),
  541. _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY));
  542. /* IIR "flip pending" means done if this bit is set */
  543. intel_uncore_write(&i915->uncore, ECOSKPD(RENDER_RING_BASE),
  544. _MASKED_BIT_DISABLE(ECO_FLIP_DONE));
  545. /* interrupts should cause a wake up from C3 */
  546. intel_uncore_write(&i915->uncore, INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN));
  547. /* On GEN3 we really need to make sure the ARB C3 LP bit is set */
  548. intel_uncore_write(&i915->uncore, MI_ARB_STATE,
  549. _MASKED_BIT_ENABLE(MI_ARB_C3_LP_WRITE_ENABLE));
  550. intel_uncore_write(&i915->uncore, MI_ARB_STATE,
  551. _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE));
  552. }
  553. static void i85x_init_clock_gating(struct drm_i915_private *i915)
  554. {
  555. intel_uncore_write(&i915->uncore, RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE);
  556. /* interrupts should cause a wake up from C3 */
  557. intel_uncore_write(&i915->uncore, MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) |
  558. _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE));
  559. intel_uncore_write(&i915->uncore, MEM_MODE,
  560. _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE));
  561. /*
  562. * Have FBC ignore 3D activity since we use software
  563. * render tracking, and otherwise a pure 3D workload
  564. * (even if it just renders a single frame and then does
  565. * abosultely nothing) would not allow FBC to recompress
  566. * until a 2D blit occurs.
  567. */
  568. intel_uncore_write(&i915->uncore, SCPD0,
  569. _MASKED_BIT_ENABLE(SCPD_FBC_IGNORE_3D));
  570. }
  571. static void i830_init_clock_gating(struct drm_i915_private *i915)
  572. {
  573. intel_uncore_write(&i915->uncore, MEM_MODE,
  574. _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) |
  575. _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE));
  576. }
  577. void intel_clock_gating_init(struct drm_i915_private *i915)
  578. {
  579. i915->clock_gating_funcs->init_clock_gating(i915);
  580. }
  581. static void nop_init_clock_gating(struct drm_i915_private *i915)
  582. {
  583. drm_dbg_kms(&i915->drm,
  584. "No clock gating settings or workarounds applied.\n");
  585. }
  586. #define CG_FUNCS(platform) \
  587. static const struct drm_i915_clock_gating_funcs platform##_clock_gating_funcs = { \
  588. .init_clock_gating = platform##_init_clock_gating, \
  589. }
  590. CG_FUNCS(dg2);
  591. CG_FUNCS(cfl);
  592. CG_FUNCS(skl);
  593. CG_FUNCS(kbl);
  594. CG_FUNCS(bxt);
  595. CG_FUNCS(glk);
  596. CG_FUNCS(bdw);
  597. CG_FUNCS(chv);
  598. CG_FUNCS(hsw);
  599. CG_FUNCS(ivb);
  600. CG_FUNCS(vlv);
  601. CG_FUNCS(gen6);
  602. CG_FUNCS(ilk);
  603. CG_FUNCS(g4x);
  604. CG_FUNCS(i965gm);
  605. CG_FUNCS(i965g);
  606. CG_FUNCS(gen3);
  607. CG_FUNCS(i85x);
  608. CG_FUNCS(i830);
  609. CG_FUNCS(nop);
  610. #undef CG_FUNCS
  611. /**
  612. * intel_clock_gating_hooks_init - setup the clock gating hooks
  613. * @i915: device private
  614. *
  615. * Setup the hooks that configure which clocks of a given platform can be
  616. * gated and also apply various GT and display specific workarounds for these
  617. * platforms. Note that some GT specific workarounds are applied separately
  618. * when GPU contexts or batchbuffers start their execution.
  619. */
  620. void intel_clock_gating_hooks_init(struct drm_i915_private *i915)
  621. {
  622. if (IS_DG2(i915))
  623. i915->clock_gating_funcs = &dg2_clock_gating_funcs;
  624. else if (IS_COFFEELAKE(i915) || IS_COMETLAKE(i915))
  625. i915->clock_gating_funcs = &cfl_clock_gating_funcs;
  626. else if (IS_SKYLAKE(i915))
  627. i915->clock_gating_funcs = &skl_clock_gating_funcs;
  628. else if (IS_KABYLAKE(i915))
  629. i915->clock_gating_funcs = &kbl_clock_gating_funcs;
  630. else if (IS_BROXTON(i915))
  631. i915->clock_gating_funcs = &bxt_clock_gating_funcs;
  632. else if (IS_GEMINILAKE(i915))
  633. i915->clock_gating_funcs = &glk_clock_gating_funcs;
  634. else if (IS_BROADWELL(i915))
  635. i915->clock_gating_funcs = &bdw_clock_gating_funcs;
  636. else if (IS_CHERRYVIEW(i915))
  637. i915->clock_gating_funcs = &chv_clock_gating_funcs;
  638. else if (IS_HASWELL(i915))
  639. i915->clock_gating_funcs = &hsw_clock_gating_funcs;
  640. else if (IS_IVYBRIDGE(i915))
  641. i915->clock_gating_funcs = &ivb_clock_gating_funcs;
  642. else if (IS_VALLEYVIEW(i915))
  643. i915->clock_gating_funcs = &vlv_clock_gating_funcs;
  644. else if (GRAPHICS_VER(i915) == 6)
  645. i915->clock_gating_funcs = &gen6_clock_gating_funcs;
  646. else if (GRAPHICS_VER(i915) == 5)
  647. i915->clock_gating_funcs = &ilk_clock_gating_funcs;
  648. else if (IS_G4X(i915))
  649. i915->clock_gating_funcs = &g4x_clock_gating_funcs;
  650. else if (IS_I965GM(i915))
  651. i915->clock_gating_funcs = &i965gm_clock_gating_funcs;
  652. else if (IS_I965G(i915))
  653. i915->clock_gating_funcs = &i965g_clock_gating_funcs;
  654. else if (GRAPHICS_VER(i915) == 3)
  655. i915->clock_gating_funcs = &gen3_clock_gating_funcs;
  656. else if (IS_I85X(i915) || IS_I865G(i915))
  657. i915->clock_gating_funcs = &i85x_clock_gating_funcs;
  658. else if (GRAPHICS_VER(i915) == 2)
  659. i915->clock_gating_funcs = &i830_clock_gating_funcs;
  660. else
  661. i915->clock_gating_funcs = &nop_clock_gating_funcs;
  662. }