intel_clock_gating.c 26 KB

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