intel_fifo_underrun.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /*
  2. * Copyright © 2014 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. * Daniel Vetter <daniel.vetter@ffwll.ch>
  25. *
  26. */
  27. #include "i915_drv.h"
  28. #include "intel_drv.h"
  29. /**
  30. * DOC: fifo underrun handling
  31. *
  32. * The i915 driver checks for display fifo underruns using the interrupt signals
  33. * provided by the hardware. This is enabled by default and fairly useful to
  34. * debug display issues, especially watermark settings.
  35. *
  36. * If an underrun is detected this is logged into dmesg. To avoid flooding logs
  37. * and occupying the cpu underrun interrupts are disabled after the first
  38. * occurrence until the next modeset on a given pipe.
  39. *
  40. * Note that underrun detection on gmch platforms is a bit more ugly since there
  41. * is no interrupt (despite that the signalling bit is in the PIPESTAT pipe
  42. * interrupt register). Also on some other platforms underrun interrupts are
  43. * shared, which means that if we detect an underrun we need to disable underrun
  44. * reporting on all pipes.
  45. *
  46. * The code also supports underrun detection on the PCH transcoder.
  47. */
  48. static bool ivb_can_enable_err_int(struct drm_device *dev)
  49. {
  50. struct drm_i915_private *dev_priv = to_i915(dev);
  51. struct intel_crtc *crtc;
  52. enum pipe pipe;
  53. assert_spin_locked(&dev_priv->irq_lock);
  54. for_each_pipe(dev_priv, pipe) {
  55. crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
  56. if (crtc->cpu_fifo_underrun_disabled)
  57. return false;
  58. }
  59. return true;
  60. }
  61. static bool cpt_can_enable_serr_int(struct drm_device *dev)
  62. {
  63. struct drm_i915_private *dev_priv = to_i915(dev);
  64. enum pipe pipe;
  65. struct intel_crtc *crtc;
  66. assert_spin_locked(&dev_priv->irq_lock);
  67. for_each_pipe(dev_priv, pipe) {
  68. crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
  69. if (crtc->pch_fifo_underrun_disabled)
  70. return false;
  71. }
  72. return true;
  73. }
  74. static void i9xx_check_fifo_underruns(struct intel_crtc *crtc)
  75. {
  76. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  77. i915_reg_t reg = PIPESTAT(crtc->pipe);
  78. u32 pipestat = I915_READ(reg) & 0xffff0000;
  79. assert_spin_locked(&dev_priv->irq_lock);
  80. if ((pipestat & PIPE_FIFO_UNDERRUN_STATUS) == 0)
  81. return;
  82. I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS);
  83. POSTING_READ(reg);
  84. DRM_ERROR("pipe %c underrun\n", pipe_name(crtc->pipe));
  85. }
  86. static void i9xx_set_fifo_underrun_reporting(struct drm_device *dev,
  87. enum pipe pipe,
  88. bool enable, bool old)
  89. {
  90. struct drm_i915_private *dev_priv = to_i915(dev);
  91. i915_reg_t reg = PIPESTAT(pipe);
  92. u32 pipestat = I915_READ(reg) & 0xffff0000;
  93. assert_spin_locked(&dev_priv->irq_lock);
  94. if (enable) {
  95. I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS);
  96. POSTING_READ(reg);
  97. } else {
  98. if (old && pipestat & PIPE_FIFO_UNDERRUN_STATUS)
  99. DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
  100. }
  101. }
  102. static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
  103. enum pipe pipe, bool enable)
  104. {
  105. struct drm_i915_private *dev_priv = to_i915(dev);
  106. uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
  107. DE_PIPEB_FIFO_UNDERRUN;
  108. if (enable)
  109. ilk_enable_display_irq(dev_priv, bit);
  110. else
  111. ilk_disable_display_irq(dev_priv, bit);
  112. }
  113. static void ivybridge_check_fifo_underruns(struct intel_crtc *crtc)
  114. {
  115. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  116. enum pipe pipe = crtc->pipe;
  117. uint32_t err_int = I915_READ(GEN7_ERR_INT);
  118. assert_spin_locked(&dev_priv->irq_lock);
  119. if ((err_int & ERR_INT_FIFO_UNDERRUN(pipe)) == 0)
  120. return;
  121. I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
  122. POSTING_READ(GEN7_ERR_INT);
  123. DRM_ERROR("fifo underrun on pipe %c\n", pipe_name(pipe));
  124. }
  125. static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
  126. enum pipe pipe,
  127. bool enable, bool old)
  128. {
  129. struct drm_i915_private *dev_priv = to_i915(dev);
  130. if (enable) {
  131. I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
  132. if (!ivb_can_enable_err_int(dev))
  133. return;
  134. ilk_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
  135. } else {
  136. ilk_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
  137. if (old &&
  138. I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe)) {
  139. DRM_ERROR("uncleared fifo underrun on pipe %c\n",
  140. pipe_name(pipe));
  141. }
  142. }
  143. }
  144. static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev,
  145. enum pipe pipe, bool enable)
  146. {
  147. struct drm_i915_private *dev_priv = to_i915(dev);
  148. if (enable)
  149. bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_FIFO_UNDERRUN);
  150. else
  151. bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_FIFO_UNDERRUN);
  152. }
  153. static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
  154. enum transcoder pch_transcoder,
  155. bool enable)
  156. {
  157. struct drm_i915_private *dev_priv = to_i915(dev);
  158. uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
  159. SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
  160. if (enable)
  161. ibx_enable_display_interrupt(dev_priv, bit);
  162. else
  163. ibx_disable_display_interrupt(dev_priv, bit);
  164. }
  165. static void cpt_check_pch_fifo_underruns(struct intel_crtc *crtc)
  166. {
  167. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  168. enum transcoder pch_transcoder = (enum transcoder) crtc->pipe;
  169. uint32_t serr_int = I915_READ(SERR_INT);
  170. assert_spin_locked(&dev_priv->irq_lock);
  171. if ((serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) == 0)
  172. return;
  173. I915_WRITE(SERR_INT, SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
  174. POSTING_READ(SERR_INT);
  175. DRM_ERROR("pch fifo underrun on pch transcoder %s\n",
  176. transcoder_name(pch_transcoder));
  177. }
  178. static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
  179. enum transcoder pch_transcoder,
  180. bool enable, bool old)
  181. {
  182. struct drm_i915_private *dev_priv = to_i915(dev);
  183. if (enable) {
  184. I915_WRITE(SERR_INT,
  185. SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
  186. if (!cpt_can_enable_serr_int(dev))
  187. return;
  188. ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
  189. } else {
  190. ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
  191. if (old && I915_READ(SERR_INT) &
  192. SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) {
  193. DRM_ERROR("uncleared pch fifo underrun on pch transcoder %s\n",
  194. transcoder_name(pch_transcoder));
  195. }
  196. }
  197. }
  198. static bool __intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
  199. enum pipe pipe, bool enable)
  200. {
  201. struct drm_i915_private *dev_priv = to_i915(dev);
  202. struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
  203. bool old;
  204. assert_spin_locked(&dev_priv->irq_lock);
  205. old = !crtc->cpu_fifo_underrun_disabled;
  206. crtc->cpu_fifo_underrun_disabled = !enable;
  207. if (HAS_GMCH_DISPLAY(dev_priv))
  208. i9xx_set_fifo_underrun_reporting(dev, pipe, enable, old);
  209. else if (IS_GEN5(dev_priv) || IS_GEN6(dev_priv))
  210. ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
  211. else if (IS_GEN7(dev_priv))
  212. ivybridge_set_fifo_underrun_reporting(dev, pipe, enable, old);
  213. else if (IS_GEN8(dev_priv) || IS_GEN9(dev_priv))
  214. broadwell_set_fifo_underrun_reporting(dev, pipe, enable);
  215. return old;
  216. }
  217. /**
  218. * intel_set_cpu_fifo_underrun_reporting - set cpu fifo underrrun reporting state
  219. * @dev_priv: i915 device instance
  220. * @pipe: (CPU) pipe to set state for
  221. * @enable: whether underruns should be reported or not
  222. *
  223. * This function sets the fifo underrun state for @pipe. It is used in the
  224. * modeset code to avoid false positives since on many platforms underruns are
  225. * expected when disabling or enabling the pipe.
  226. *
  227. * Notice that on some platforms disabling underrun reports for one pipe
  228. * disables for all due to shared interrupts. Actual reporting is still per-pipe
  229. * though.
  230. *
  231. * Returns the previous state of underrun reporting.
  232. */
  233. bool intel_set_cpu_fifo_underrun_reporting(struct drm_i915_private *dev_priv,
  234. enum pipe pipe, bool enable)
  235. {
  236. unsigned long flags;
  237. bool ret;
  238. spin_lock_irqsave(&dev_priv->irq_lock, flags);
  239. ret = __intel_set_cpu_fifo_underrun_reporting(&dev_priv->drm, pipe,
  240. enable);
  241. spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
  242. return ret;
  243. }
  244. /**
  245. * intel_set_pch_fifo_underrun_reporting - set PCH fifo underrun reporting state
  246. * @dev_priv: i915 device instance
  247. * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
  248. * @enable: whether underruns should be reported or not
  249. *
  250. * This function makes us disable or enable PCH fifo underruns for a specific
  251. * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
  252. * underrun reporting for one transcoder may also disable all the other PCH
  253. * error interruts for the other transcoders, due to the fact that there's just
  254. * one interrupt mask/enable bit for all the transcoders.
  255. *
  256. * Returns the previous state of underrun reporting.
  257. */
  258. bool intel_set_pch_fifo_underrun_reporting(struct drm_i915_private *dev_priv,
  259. enum transcoder pch_transcoder,
  260. bool enable)
  261. {
  262. struct intel_crtc *crtc =
  263. intel_get_crtc_for_pipe(dev_priv, (enum pipe) pch_transcoder);
  264. unsigned long flags;
  265. bool old;
  266. /*
  267. * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
  268. * has only one pch transcoder A that all pipes can use. To avoid racy
  269. * pch transcoder -> pipe lookups from interrupt code simply store the
  270. * underrun statistics in crtc A. Since we never expose this anywhere
  271. * nor use it outside of the fifo underrun code here using the "wrong"
  272. * crtc on LPT won't cause issues.
  273. */
  274. spin_lock_irqsave(&dev_priv->irq_lock, flags);
  275. old = !crtc->pch_fifo_underrun_disabled;
  276. crtc->pch_fifo_underrun_disabled = !enable;
  277. if (HAS_PCH_IBX(dev_priv))
  278. ibx_set_fifo_underrun_reporting(&dev_priv->drm,
  279. pch_transcoder,
  280. enable);
  281. else
  282. cpt_set_fifo_underrun_reporting(&dev_priv->drm,
  283. pch_transcoder,
  284. enable, old);
  285. spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
  286. return old;
  287. }
  288. /**
  289. * intel_cpu_fifo_underrun_irq_handler - handle CPU fifo underrun interrupt
  290. * @dev_priv: i915 device instance
  291. * @pipe: (CPU) pipe to set state for
  292. *
  293. * This handles a CPU fifo underrun interrupt, generating an underrun warning
  294. * into dmesg if underrun reporting is enabled and then disables the underrun
  295. * interrupt to avoid an irq storm.
  296. */
  297. void intel_cpu_fifo_underrun_irq_handler(struct drm_i915_private *dev_priv,
  298. enum pipe pipe)
  299. {
  300. struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
  301. /* We may be called too early in init, thanks BIOS! */
  302. if (crtc == NULL)
  303. return;
  304. /* GMCH can't disable fifo underruns, filter them. */
  305. if (HAS_GMCH_DISPLAY(dev_priv) &&
  306. crtc->cpu_fifo_underrun_disabled)
  307. return;
  308. if (intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false))
  309. DRM_ERROR("CPU pipe %c FIFO underrun\n",
  310. pipe_name(pipe));
  311. intel_fbc_handle_fifo_underrun_irq(dev_priv);
  312. }
  313. /**
  314. * intel_pch_fifo_underrun_irq_handler - handle PCH fifo underrun interrupt
  315. * @dev_priv: i915 device instance
  316. * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
  317. *
  318. * This handles a PCH fifo underrun interrupt, generating an underrun warning
  319. * into dmesg if underrun reporting is enabled and then disables the underrun
  320. * interrupt to avoid an irq storm.
  321. */
  322. void intel_pch_fifo_underrun_irq_handler(struct drm_i915_private *dev_priv,
  323. enum transcoder pch_transcoder)
  324. {
  325. if (intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder,
  326. false))
  327. DRM_ERROR("PCH transcoder %s FIFO underrun\n",
  328. transcoder_name(pch_transcoder));
  329. }
  330. /**
  331. * intel_check_cpu_fifo_underruns - check for CPU fifo underruns immediately
  332. * @dev_priv: i915 device instance
  333. *
  334. * Check for CPU fifo underruns immediately. Useful on IVB/HSW where the shared
  335. * error interrupt may have been disabled, and so CPU fifo underruns won't
  336. * necessarily raise an interrupt, and on GMCH platforms where underruns never
  337. * raise an interrupt.
  338. */
  339. void intel_check_cpu_fifo_underruns(struct drm_i915_private *dev_priv)
  340. {
  341. struct intel_crtc *crtc;
  342. spin_lock_irq(&dev_priv->irq_lock);
  343. for_each_intel_crtc(&dev_priv->drm, crtc) {
  344. if (crtc->cpu_fifo_underrun_disabled)
  345. continue;
  346. if (HAS_GMCH_DISPLAY(dev_priv))
  347. i9xx_check_fifo_underruns(crtc);
  348. else if (IS_GEN7(dev_priv))
  349. ivybridge_check_fifo_underruns(crtc);
  350. }
  351. spin_unlock_irq(&dev_priv->irq_lock);
  352. }
  353. /**
  354. * intel_check_pch_fifo_underruns - check for PCH fifo underruns immediately
  355. * @dev_priv: i915 device instance
  356. *
  357. * Check for PCH fifo underruns immediately. Useful on CPT/PPT where the shared
  358. * error interrupt may have been disabled, and so PCH fifo underruns won't
  359. * necessarily raise an interrupt.
  360. */
  361. void intel_check_pch_fifo_underruns(struct drm_i915_private *dev_priv)
  362. {
  363. struct intel_crtc *crtc;
  364. spin_lock_irq(&dev_priv->irq_lock);
  365. for_each_intel_crtc(&dev_priv->drm, crtc) {
  366. if (crtc->pch_fifo_underrun_disabled)
  367. continue;
  368. if (HAS_PCH_CPT(dev_priv))
  369. cpt_check_pch_fifo_underruns(crtc);
  370. }
  371. spin_unlock_irq(&dev_priv->irq_lock);
  372. }