2 * Copyright © 2014 Intel Corporation
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:
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
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
24 * Daniel Vetter <daniel.vetter@ffwll.ch>
29 #include "i915_trace.h"
31 #include "intel_display_types.h"
32 #include "intel_fbc.h"
33 #include "intel_fifo_underrun.h"
36 * DOC: fifo underrun handling
38 * The i915 driver checks for display fifo underruns using the interrupt signals
39 * provided by the hardware. This is enabled by default and fairly useful to
40 * debug display issues, especially watermark settings.
42 * If an underrun is detected this is logged into dmesg. To avoid flooding logs
43 * and occupying the cpu underrun interrupts are disabled after the first
44 * occurrence until the next modeset on a given pipe.
46 * Note that underrun detection on gmch platforms is a bit more ugly since there
47 * is no interrupt (despite that the signalling bit is in the PIPESTAT pipe
48 * interrupt register). Also on some other platforms underrun interrupts are
49 * shared, which means that if we detect an underrun we need to disable underrun
50 * reporting on all pipes.
52 * The code also supports underrun detection on the PCH transcoder.
55 static bool ivb_can_enable_err_int(struct drm_device *dev)
57 struct drm_i915_private *dev_priv = to_i915(dev);
58 struct intel_crtc *crtc;
61 lockdep_assert_held(&dev_priv->irq_lock);
63 for_each_pipe(dev_priv, pipe) {
64 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
66 if (crtc->cpu_fifo_underrun_disabled)
73 static bool cpt_can_enable_serr_int(struct drm_device *dev)
75 struct drm_i915_private *dev_priv = to_i915(dev);
77 struct intel_crtc *crtc;
79 lockdep_assert_held(&dev_priv->irq_lock);
81 for_each_pipe(dev_priv, pipe) {
82 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
84 if (crtc->pch_fifo_underrun_disabled)
91 static void i9xx_check_fifo_underruns(struct intel_crtc *crtc)
93 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
94 i915_reg_t reg = PIPESTAT(crtc->pipe);
97 lockdep_assert_held(&dev_priv->irq_lock);
99 if ((intel_de_read(dev_priv, reg) & PIPE_FIFO_UNDERRUN_STATUS) == 0)
102 enable_mask = i915_pipestat_enable_mask(dev_priv, crtc->pipe);
103 intel_de_write(dev_priv, reg, enable_mask | PIPE_FIFO_UNDERRUN_STATUS);
104 intel_de_posting_read(dev_priv, reg);
106 trace_intel_cpu_fifo_underrun(dev_priv, crtc->pipe);
107 drm_err(&dev_priv->drm, "pipe %c underrun\n", pipe_name(crtc->pipe));
110 static void i9xx_set_fifo_underrun_reporting(struct drm_device *dev,
112 bool enable, bool old)
114 struct drm_i915_private *dev_priv = to_i915(dev);
115 i915_reg_t reg = PIPESTAT(pipe);
117 lockdep_assert_held(&dev_priv->irq_lock);
120 u32 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
122 intel_de_write(dev_priv, reg,
123 enable_mask | PIPE_FIFO_UNDERRUN_STATUS);
124 intel_de_posting_read(dev_priv, reg);
126 if (old && intel_de_read(dev_priv, reg) & PIPE_FIFO_UNDERRUN_STATUS)
127 drm_err(&dev_priv->drm, "pipe %c underrun\n",
132 static void ilk_set_fifo_underrun_reporting(struct drm_device *dev,
133 enum pipe pipe, bool enable)
135 struct drm_i915_private *dev_priv = to_i915(dev);
136 u32 bit = (pipe == PIPE_A) ?
137 DE_PIPEA_FIFO_UNDERRUN : DE_PIPEB_FIFO_UNDERRUN;
140 ilk_enable_display_irq(dev_priv, bit);
142 ilk_disable_display_irq(dev_priv, bit);
145 static void ivb_check_fifo_underruns(struct intel_crtc *crtc)
147 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
148 enum pipe pipe = crtc->pipe;
149 u32 err_int = intel_de_read(dev_priv, GEN7_ERR_INT);
151 lockdep_assert_held(&dev_priv->irq_lock);
153 if ((err_int & ERR_INT_FIFO_UNDERRUN(pipe)) == 0)
156 intel_de_write(dev_priv, GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
157 intel_de_posting_read(dev_priv, GEN7_ERR_INT);
159 trace_intel_cpu_fifo_underrun(dev_priv, pipe);
160 drm_err(&dev_priv->drm, "fifo underrun on pipe %c\n", pipe_name(pipe));
163 static void ivb_set_fifo_underrun_reporting(struct drm_device *dev,
164 enum pipe pipe, bool enable,
167 struct drm_i915_private *dev_priv = to_i915(dev);
169 intel_de_write(dev_priv, GEN7_ERR_INT,
170 ERR_INT_FIFO_UNDERRUN(pipe));
172 if (!ivb_can_enable_err_int(dev))
175 ilk_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
177 ilk_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
180 intel_de_read(dev_priv, GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe)) {
181 drm_err(&dev_priv->drm,
182 "uncleared fifo underrun on pipe %c\n",
189 icl_pipe_status_underrun_mask(struct drm_i915_private *dev_priv)
191 u32 mask = PIPE_STATUS_UNDERRUN;
193 if (DISPLAY_VER(dev_priv) >= 13)
194 mask |= PIPE_STATUS_SOFT_UNDERRUN_XELPD |
195 PIPE_STATUS_HARD_UNDERRUN_XELPD |
196 PIPE_STATUS_PORT_UNDERRUN_XELPD;
201 static void bdw_set_fifo_underrun_reporting(struct drm_device *dev,
202 enum pipe pipe, bool enable)
204 struct drm_i915_private *dev_priv = to_i915(dev);
205 u32 mask = gen8_de_pipe_underrun_mask(dev_priv);
208 if (DISPLAY_VER(dev_priv) >= 11)
209 intel_de_write(dev_priv, ICL_PIPESTATUS(pipe),
210 icl_pipe_status_underrun_mask(dev_priv));
212 bdw_enable_pipe_irq(dev_priv, pipe, mask);
214 bdw_disable_pipe_irq(dev_priv, pipe, mask);
218 static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
219 enum pipe pch_transcoder,
222 struct drm_i915_private *dev_priv = to_i915(dev);
223 u32 bit = (pch_transcoder == PIPE_A) ?
224 SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
227 ibx_enable_display_interrupt(dev_priv, bit);
229 ibx_disable_display_interrupt(dev_priv, bit);
232 static void cpt_check_pch_fifo_underruns(struct intel_crtc *crtc)
234 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
235 enum pipe pch_transcoder = crtc->pipe;
236 u32 serr_int = intel_de_read(dev_priv, SERR_INT);
238 lockdep_assert_held(&dev_priv->irq_lock);
240 if ((serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) == 0)
243 intel_de_write(dev_priv, SERR_INT,
244 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
245 intel_de_posting_read(dev_priv, SERR_INT);
247 trace_intel_pch_fifo_underrun(dev_priv, pch_transcoder);
248 drm_err(&dev_priv->drm, "pch fifo underrun on pch transcoder %c\n",
249 pipe_name(pch_transcoder));
252 static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
253 enum pipe pch_transcoder,
254 bool enable, bool old)
256 struct drm_i915_private *dev_priv = to_i915(dev);
259 intel_de_write(dev_priv, SERR_INT,
260 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
262 if (!cpt_can_enable_serr_int(dev))
265 ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
267 ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
269 if (old && intel_de_read(dev_priv, SERR_INT) &
270 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) {
271 drm_err(&dev_priv->drm,
272 "uncleared pch fifo underrun on pch transcoder %c\n",
273 pipe_name(pch_transcoder));
278 static bool __intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
279 enum pipe pipe, bool enable)
281 struct drm_i915_private *dev_priv = to_i915(dev);
282 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
285 lockdep_assert_held(&dev_priv->irq_lock);
287 old = !crtc->cpu_fifo_underrun_disabled;
288 crtc->cpu_fifo_underrun_disabled = !enable;
290 if (HAS_GMCH(dev_priv))
291 i9xx_set_fifo_underrun_reporting(dev, pipe, enable, old);
292 else if (IS_IRONLAKE(dev_priv) || IS_SANDYBRIDGE(dev_priv))
293 ilk_set_fifo_underrun_reporting(dev, pipe, enable);
294 else if (DISPLAY_VER(dev_priv) == 7)
295 ivb_set_fifo_underrun_reporting(dev, pipe, enable, old);
296 else if (DISPLAY_VER(dev_priv) >= 8)
297 bdw_set_fifo_underrun_reporting(dev, pipe, enable);
303 * intel_set_cpu_fifo_underrun_reporting - set cpu fifo underrrun reporting state
304 * @dev_priv: i915 device instance
305 * @pipe: (CPU) pipe to set state for
306 * @enable: whether underruns should be reported or not
308 * This function sets the fifo underrun state for @pipe. It is used in the
309 * modeset code to avoid false positives since on many platforms underruns are
310 * expected when disabling or enabling the pipe.
312 * Notice that on some platforms disabling underrun reports for one pipe
313 * disables for all due to shared interrupts. Actual reporting is still per-pipe
316 * Returns the previous state of underrun reporting.
318 bool intel_set_cpu_fifo_underrun_reporting(struct drm_i915_private *dev_priv,
319 enum pipe pipe, bool enable)
324 spin_lock_irqsave(&dev_priv->irq_lock, flags);
325 ret = __intel_set_cpu_fifo_underrun_reporting(&dev_priv->drm, pipe,
327 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
333 * intel_set_pch_fifo_underrun_reporting - set PCH fifo underrun reporting state
334 * @dev_priv: i915 device instance
335 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
336 * @enable: whether underruns should be reported or not
338 * This function makes us disable or enable PCH fifo underruns for a specific
339 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
340 * underrun reporting for one transcoder may also disable all the other PCH
341 * error interruts for the other transcoders, due to the fact that there's just
342 * one interrupt mask/enable bit for all the transcoders.
344 * Returns the previous state of underrun reporting.
346 bool intel_set_pch_fifo_underrun_reporting(struct drm_i915_private *dev_priv,
347 enum pipe pch_transcoder,
350 struct intel_crtc *crtc =
351 intel_get_crtc_for_pipe(dev_priv, pch_transcoder);
356 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
357 * has only one pch transcoder A that all pipes can use. To avoid racy
358 * pch transcoder -> pipe lookups from interrupt code simply store the
359 * underrun statistics in crtc A. Since we never expose this anywhere
360 * nor use it outside of the fifo underrun code here using the "wrong"
361 * crtc on LPT won't cause issues.
364 spin_lock_irqsave(&dev_priv->irq_lock, flags);
366 old = !crtc->pch_fifo_underrun_disabled;
367 crtc->pch_fifo_underrun_disabled = !enable;
369 if (HAS_PCH_IBX(dev_priv))
370 ibx_set_fifo_underrun_reporting(&dev_priv->drm,
374 cpt_set_fifo_underrun_reporting(&dev_priv->drm,
378 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
383 * intel_cpu_fifo_underrun_irq_handler - handle CPU fifo underrun interrupt
384 * @dev_priv: i915 device instance
385 * @pipe: (CPU) pipe to set state for
387 * This handles a CPU fifo underrun interrupt, generating an underrun warning
388 * into dmesg if underrun reporting is enabled and then disables the underrun
389 * interrupt to avoid an irq storm.
391 void intel_cpu_fifo_underrun_irq_handler(struct drm_i915_private *dev_priv,
394 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
397 /* We may be called too early in init, thanks BIOS! */
401 /* GMCH can't disable fifo underruns, filter them. */
402 if (HAS_GMCH(dev_priv) &&
403 crtc->cpu_fifo_underrun_disabled)
407 * Starting with display version 11, the PIPE_STAT register records
408 * whether an underrun has happened, and on XELPD+, it will also record
409 * whether the underrun was soft/hard and whether it was triggered by
410 * the downstream port logic. We should clear these bits (which use
411 * write-1-to-clear logic) too.
413 * Note that although the IIR gives us the same underrun and soft/hard
414 * information, PIPE_STAT is the only place we can find out whether
415 * the underrun was caused by the downstream port.
417 if (DISPLAY_VER(dev_priv) >= 11) {
418 underruns = intel_de_read(dev_priv, ICL_PIPESTATUS(pipe)) &
419 icl_pipe_status_underrun_mask(dev_priv);
420 intel_de_write(dev_priv, ICL_PIPESTATUS(pipe), underruns);
423 if (intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false)) {
424 trace_intel_cpu_fifo_underrun(dev_priv, pipe);
426 if (DISPLAY_VER(dev_priv) >= 11)
427 drm_err(&dev_priv->drm, "CPU pipe %c FIFO underrun: %s%s%s%s\n",
429 underruns & PIPE_STATUS_SOFT_UNDERRUN_XELPD ? "soft," : "",
430 underruns & PIPE_STATUS_HARD_UNDERRUN_XELPD ? "hard," : "",
431 underruns & PIPE_STATUS_PORT_UNDERRUN_XELPD ? "port," : "",
432 underruns & PIPE_STATUS_UNDERRUN ? "transcoder," : "");
434 drm_err(&dev_priv->drm, "CPU pipe %c FIFO underrun\n", pipe_name(pipe));
437 intel_fbc_handle_fifo_underrun_irq(dev_priv);
441 * intel_pch_fifo_underrun_irq_handler - handle PCH fifo underrun interrupt
442 * @dev_priv: i915 device instance
443 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
445 * This handles a PCH fifo underrun interrupt, generating an underrun warning
446 * into dmesg if underrun reporting is enabled and then disables the underrun
447 * interrupt to avoid an irq storm.
449 void intel_pch_fifo_underrun_irq_handler(struct drm_i915_private *dev_priv,
450 enum pipe pch_transcoder)
452 if (intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder,
454 trace_intel_pch_fifo_underrun(dev_priv, pch_transcoder);
455 drm_err(&dev_priv->drm, "PCH transcoder %c FIFO underrun\n",
456 pipe_name(pch_transcoder));
461 * intel_check_cpu_fifo_underruns - check for CPU fifo underruns immediately
462 * @dev_priv: i915 device instance
464 * Check for CPU fifo underruns immediately. Useful on IVB/HSW where the shared
465 * error interrupt may have been disabled, and so CPU fifo underruns won't
466 * necessarily raise an interrupt, and on GMCH platforms where underruns never
467 * raise an interrupt.
469 void intel_check_cpu_fifo_underruns(struct drm_i915_private *dev_priv)
471 struct intel_crtc *crtc;
473 spin_lock_irq(&dev_priv->irq_lock);
475 for_each_intel_crtc(&dev_priv->drm, crtc) {
476 if (crtc->cpu_fifo_underrun_disabled)
479 if (HAS_GMCH(dev_priv))
480 i9xx_check_fifo_underruns(crtc);
481 else if (DISPLAY_VER(dev_priv) == 7)
482 ivb_check_fifo_underruns(crtc);
485 spin_unlock_irq(&dev_priv->irq_lock);
489 * intel_check_pch_fifo_underruns - check for PCH fifo underruns immediately
490 * @dev_priv: i915 device instance
492 * Check for PCH fifo underruns immediately. Useful on CPT/PPT where the shared
493 * error interrupt may have been disabled, and so PCH fifo underruns won't
494 * necessarily raise an interrupt.
496 void intel_check_pch_fifo_underruns(struct drm_i915_private *dev_priv)
498 struct intel_crtc *crtc;
500 spin_lock_irq(&dev_priv->irq_lock);
502 for_each_intel_crtc(&dev_priv->drm, crtc) {
503 if (crtc->pch_fifo_underrun_disabled)
506 if (HAS_PCH_CPT(dev_priv))
507 cpt_check_pch_fifo_underruns(crtc);
510 spin_unlock_irq(&dev_priv->irq_lock);