intel_fifo_underrun.c 14 KB

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