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
30 #include "intel_display_trace.h"
31 #include "intel_display_types.h"
32 #include "intel_fbc.h"
33 #include "intel_fifo_underrun.h"
34 #include "intel_pch_display.h"
37 * DOC: fifo underrun handling
39 * The i915 driver checks for display fifo underruns using the interrupt signals
40 * provided by the hardware. This is enabled by default and fairly useful to
41 * debug display issues, especially watermark settings.
43 * If an underrun is detected this is logged into dmesg. To avoid flooding logs
44 * and occupying the cpu underrun interrupts are disabled after the first
45 * occurrence until the next modeset on a given pipe.
47 * Note that underrun detection on gmch platforms is a bit more ugly since there
48 * is no interrupt (despite that the signalling bit is in the PIPESTAT pipe
49 * interrupt register). Also on some other platforms underrun interrupts are
50 * shared, which means that if we detect an underrun we need to disable underrun
51 * reporting on all pipes.
53 * The code also supports underrun detection on the PCH transcoder.
56 static bool ivb_can_enable_err_int(struct drm_device *dev)
58 struct drm_i915_private *dev_priv = to_i915(dev);
59 struct intel_crtc *crtc;
62 lockdep_assert_held(&dev_priv->irq_lock);
64 for_each_pipe(dev_priv, pipe) {
65 crtc = intel_crtc_for_pipe(dev_priv, pipe);
67 if (crtc->cpu_fifo_underrun_disabled)
74 static bool cpt_can_enable_serr_int(struct drm_device *dev)
76 struct drm_i915_private *dev_priv = to_i915(dev);
78 struct intel_crtc *crtc;
80 lockdep_assert_held(&dev_priv->irq_lock);
82 for_each_pipe(dev_priv, pipe) {
83 crtc = intel_crtc_for_pipe(dev_priv, pipe);
85 if (crtc->pch_fifo_underrun_disabled)
92 static void i9xx_check_fifo_underruns(struct intel_crtc *crtc)
94 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
95 i915_reg_t reg = PIPESTAT(crtc->pipe);
98 lockdep_assert_held(&dev_priv->irq_lock);
100 if ((intel_de_read(dev_priv, reg) & PIPE_FIFO_UNDERRUN_STATUS) == 0)
103 enable_mask = i915_pipestat_enable_mask(dev_priv, crtc->pipe);
104 intel_de_write(dev_priv, reg, enable_mask | PIPE_FIFO_UNDERRUN_STATUS);
105 intel_de_posting_read(dev_priv, reg);
107 trace_intel_cpu_fifo_underrun(dev_priv, crtc->pipe);
108 drm_err(&dev_priv->drm, "pipe %c underrun\n", pipe_name(crtc->pipe));
111 static void i9xx_set_fifo_underrun_reporting(struct drm_device *dev,
113 bool enable, bool old)
115 struct drm_i915_private *dev_priv = to_i915(dev);
116 i915_reg_t reg = PIPESTAT(pipe);
118 lockdep_assert_held(&dev_priv->irq_lock);
121 u32 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
123 intel_de_write(dev_priv, reg,
124 enable_mask | PIPE_FIFO_UNDERRUN_STATUS);
125 intel_de_posting_read(dev_priv, reg);
127 if (old && intel_de_read(dev_priv, reg) & PIPE_FIFO_UNDERRUN_STATUS)
128 drm_err(&dev_priv->drm, "pipe %c underrun\n",
133 static void ilk_set_fifo_underrun_reporting(struct drm_device *dev,
134 enum pipe pipe, bool enable)
136 struct drm_i915_private *dev_priv = to_i915(dev);
137 u32 bit = (pipe == PIPE_A) ?
138 DE_PIPEA_FIFO_UNDERRUN : DE_PIPEB_FIFO_UNDERRUN;
141 ilk_enable_display_irq(dev_priv, bit);
143 ilk_disable_display_irq(dev_priv, bit);
146 static void ivb_check_fifo_underruns(struct intel_crtc *crtc)
148 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
149 enum pipe pipe = crtc->pipe;
150 u32 err_int = intel_de_read(dev_priv, GEN7_ERR_INT);
152 lockdep_assert_held(&dev_priv->irq_lock);
154 if ((err_int & ERR_INT_FIFO_UNDERRUN(pipe)) == 0)
157 intel_de_write(dev_priv, GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
158 intel_de_posting_read(dev_priv, GEN7_ERR_INT);
160 trace_intel_cpu_fifo_underrun(dev_priv, pipe);
161 drm_err(&dev_priv->drm, "fifo underrun on pipe %c\n", pipe_name(pipe));
164 static void ivb_set_fifo_underrun_reporting(struct drm_device *dev,
165 enum pipe pipe, bool enable,
168 struct drm_i915_private *dev_priv = to_i915(dev);
170 intel_de_write(dev_priv, GEN7_ERR_INT,
171 ERR_INT_FIFO_UNDERRUN(pipe));
173 if (!ivb_can_enable_err_int(dev))
176 ilk_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
178 ilk_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
181 intel_de_read(dev_priv, GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe)) {
182 drm_err(&dev_priv->drm,
183 "uncleared fifo underrun on pipe %c\n",
190 icl_pipe_status_underrun_mask(struct drm_i915_private *dev_priv)
192 u32 mask = PIPE_STATUS_UNDERRUN;
194 if (DISPLAY_VER(dev_priv) >= 13)
195 mask |= PIPE_STATUS_SOFT_UNDERRUN_XELPD |
196 PIPE_STATUS_HARD_UNDERRUN_XELPD |
197 PIPE_STATUS_PORT_UNDERRUN_XELPD;
202 static void bdw_set_fifo_underrun_reporting(struct drm_device *dev,
203 enum pipe pipe, bool enable)
205 struct drm_i915_private *dev_priv = to_i915(dev);
206 u32 mask = gen8_de_pipe_underrun_mask(dev_priv);
209 if (DISPLAY_VER(dev_priv) >= 11)
210 intel_de_write(dev_priv, ICL_PIPESTATUS(pipe),
211 icl_pipe_status_underrun_mask(dev_priv));
213 bdw_enable_pipe_irq(dev_priv, pipe, mask);
215 bdw_disable_pipe_irq(dev_priv, pipe, mask);
219 static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
220 enum pipe pch_transcoder,
223 struct drm_i915_private *dev_priv = to_i915(dev);
224 u32 bit = (pch_transcoder == PIPE_A) ?
225 SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
228 ibx_enable_display_interrupt(dev_priv, bit);
230 ibx_disable_display_interrupt(dev_priv, bit);
233 static void cpt_check_pch_fifo_underruns(struct intel_crtc *crtc)
235 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
236 enum pipe pch_transcoder = crtc->pipe;
237 u32 serr_int = intel_de_read(dev_priv, SERR_INT);
239 lockdep_assert_held(&dev_priv->irq_lock);
241 if ((serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) == 0)
244 intel_de_write(dev_priv, SERR_INT,
245 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
246 intel_de_posting_read(dev_priv, SERR_INT);
248 trace_intel_pch_fifo_underrun(dev_priv, pch_transcoder);
249 drm_err(&dev_priv->drm, "pch fifo underrun on pch transcoder %c\n",
250 pipe_name(pch_transcoder));
253 static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
254 enum pipe pch_transcoder,
255 bool enable, bool old)
257 struct drm_i915_private *dev_priv = to_i915(dev);
260 intel_de_write(dev_priv, SERR_INT,
261 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
263 if (!cpt_can_enable_serr_int(dev))
266 ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
268 ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
270 if (old && intel_de_read(dev_priv, SERR_INT) &
271 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) {
272 drm_err(&dev_priv->drm,
273 "uncleared pch fifo underrun on pch transcoder %c\n",
274 pipe_name(pch_transcoder));
279 static bool __intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
280 enum pipe pipe, bool enable)
282 struct drm_i915_private *dev_priv = to_i915(dev);
283 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
286 lockdep_assert_held(&dev_priv->irq_lock);
288 old = !crtc->cpu_fifo_underrun_disabled;
289 crtc->cpu_fifo_underrun_disabled = !enable;
291 if (HAS_GMCH(dev_priv))
292 i9xx_set_fifo_underrun_reporting(dev, pipe, enable, old);
293 else if (IS_IRONLAKE(dev_priv) || IS_SANDYBRIDGE(dev_priv))
294 ilk_set_fifo_underrun_reporting(dev, pipe, enable);
295 else if (DISPLAY_VER(dev_priv) == 7)
296 ivb_set_fifo_underrun_reporting(dev, pipe, enable, old);
297 else if (DISPLAY_VER(dev_priv) >= 8)
298 bdw_set_fifo_underrun_reporting(dev, pipe, enable);
304 * intel_set_cpu_fifo_underrun_reporting - set cpu fifo underrrun reporting state
305 * @dev_priv: i915 device instance
306 * @pipe: (CPU) pipe to set state for
307 * @enable: whether underruns should be reported or not
309 * This function sets the fifo underrun state for @pipe. It is used in the
310 * modeset code to avoid false positives since on many platforms underruns are
311 * expected when disabling or enabling the pipe.
313 * Notice that on some platforms disabling underrun reports for one pipe
314 * disables for all due to shared interrupts. Actual reporting is still per-pipe
317 * Returns the previous state of underrun reporting.
319 bool intel_set_cpu_fifo_underrun_reporting(struct drm_i915_private *dev_priv,
320 enum pipe pipe, bool enable)
325 spin_lock_irqsave(&dev_priv->irq_lock, flags);
326 ret = __intel_set_cpu_fifo_underrun_reporting(&dev_priv->drm, pipe,
328 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
334 * intel_set_pch_fifo_underrun_reporting - set PCH fifo underrun reporting state
335 * @dev_priv: i915 device instance
336 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
337 * @enable: whether underruns should be reported or not
339 * This function makes us disable or enable PCH fifo underruns for a specific
340 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
341 * underrun reporting for one transcoder may also disable all the other PCH
342 * error interruts for the other transcoders, due to the fact that there's just
343 * one interrupt mask/enable bit for all the transcoders.
345 * Returns the previous state of underrun reporting.
347 bool intel_set_pch_fifo_underrun_reporting(struct drm_i915_private *dev_priv,
348 enum pipe pch_transcoder,
351 struct intel_crtc *crtc =
352 intel_crtc_for_pipe(dev_priv, pch_transcoder);
357 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
358 * has only one pch transcoder A that all pipes can use. To avoid racy
359 * pch transcoder -> pipe lookups from interrupt code simply store the
360 * underrun statistics in crtc A. Since we never expose this anywhere
361 * nor use it outside of the fifo underrun code here using the "wrong"
362 * crtc on LPT won't cause issues.
365 spin_lock_irqsave(&dev_priv->irq_lock, flags);
367 old = !crtc->pch_fifo_underrun_disabled;
368 crtc->pch_fifo_underrun_disabled = !enable;
370 if (HAS_PCH_IBX(dev_priv))
371 ibx_set_fifo_underrun_reporting(&dev_priv->drm,
375 cpt_set_fifo_underrun_reporting(&dev_priv->drm,
379 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
384 * intel_cpu_fifo_underrun_irq_handler - handle CPU fifo underrun interrupt
385 * @dev_priv: i915 device instance
386 * @pipe: (CPU) pipe to set state for
388 * This handles a CPU fifo underrun interrupt, generating an underrun warning
389 * into dmesg if underrun reporting is enabled and then disables the underrun
390 * interrupt to avoid an irq storm.
392 void intel_cpu_fifo_underrun_irq_handler(struct drm_i915_private *dev_priv,
395 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
398 /* We may be called too early in init, thanks BIOS! */
402 /* GMCH can't disable fifo underruns, filter them. */
403 if (HAS_GMCH(dev_priv) &&
404 crtc->cpu_fifo_underrun_disabled)
408 * Starting with display version 11, the PIPE_STAT register records
409 * whether an underrun has happened, and on XELPD+, it will also record
410 * whether the underrun was soft/hard and whether it was triggered by
411 * the downstream port logic. We should clear these bits (which use
412 * write-1-to-clear logic) too.
414 * Note that although the IIR gives us the same underrun and soft/hard
415 * information, PIPE_STAT is the only place we can find out whether
416 * the underrun was caused by the downstream port.
418 if (DISPLAY_VER(dev_priv) >= 11) {
419 underruns = intel_de_read(dev_priv, ICL_PIPESTATUS(pipe)) &
420 icl_pipe_status_underrun_mask(dev_priv);
421 intel_de_write(dev_priv, ICL_PIPESTATUS(pipe), underruns);
424 if (intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false)) {
425 trace_intel_cpu_fifo_underrun(dev_priv, pipe);
427 if (DISPLAY_VER(dev_priv) >= 11)
428 drm_err(&dev_priv->drm, "CPU pipe %c FIFO underrun: %s%s%s%s\n",
430 underruns & PIPE_STATUS_SOFT_UNDERRUN_XELPD ? "soft," : "",
431 underruns & PIPE_STATUS_HARD_UNDERRUN_XELPD ? "hard," : "",
432 underruns & PIPE_STATUS_PORT_UNDERRUN_XELPD ? "port," : "",
433 underruns & PIPE_STATUS_UNDERRUN ? "transcoder," : "");
435 drm_err(&dev_priv->drm, "CPU pipe %c FIFO underrun\n", pipe_name(pipe));
438 intel_fbc_handle_fifo_underrun_irq(dev_priv);
442 * intel_pch_fifo_underrun_irq_handler - handle PCH fifo underrun interrupt
443 * @dev_priv: i915 device instance
444 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
446 * This handles a PCH fifo underrun interrupt, generating an underrun warning
447 * into dmesg if underrun reporting is enabled and then disables the underrun
448 * interrupt to avoid an irq storm.
450 void intel_pch_fifo_underrun_irq_handler(struct drm_i915_private *dev_priv,
451 enum pipe pch_transcoder)
453 if (intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder,
455 trace_intel_pch_fifo_underrun(dev_priv, pch_transcoder);
456 drm_err(&dev_priv->drm, "PCH transcoder %c FIFO underrun\n",
457 pipe_name(pch_transcoder));
462 * intel_check_cpu_fifo_underruns - check for CPU fifo underruns immediately
463 * @dev_priv: i915 device instance
465 * Check for CPU fifo underruns immediately. Useful on IVB/HSW where the shared
466 * error interrupt may have been disabled, and so CPU fifo underruns won't
467 * necessarily raise an interrupt, and on GMCH platforms where underruns never
468 * raise an interrupt.
470 void intel_check_cpu_fifo_underruns(struct drm_i915_private *dev_priv)
472 struct intel_crtc *crtc;
474 spin_lock_irq(&dev_priv->irq_lock);
476 for_each_intel_crtc(&dev_priv->drm, crtc) {
477 if (crtc->cpu_fifo_underrun_disabled)
480 if (HAS_GMCH(dev_priv))
481 i9xx_check_fifo_underruns(crtc);
482 else if (DISPLAY_VER(dev_priv) == 7)
483 ivb_check_fifo_underruns(crtc);
486 spin_unlock_irq(&dev_priv->irq_lock);
490 * intel_check_pch_fifo_underruns - check for PCH fifo underruns immediately
491 * @dev_priv: i915 device instance
493 * Check for PCH fifo underruns immediately. Useful on CPT/PPT where the shared
494 * error interrupt may have been disabled, and so PCH fifo underruns won't
495 * necessarily raise an interrupt.
497 void intel_check_pch_fifo_underruns(struct drm_i915_private *dev_priv)
499 struct intel_crtc *crtc;
501 spin_lock_irq(&dev_priv->irq_lock);
503 for_each_intel_crtc(&dev_priv->drm, crtc) {
504 if (crtc->pch_fifo_underrun_disabled)
507 if (HAS_PCH_CPT(dev_priv))
508 cpt_check_pch_fifo_underruns(crtc);
511 spin_unlock_irq(&dev_priv->irq_lock);
514 void intel_init_fifo_underrun_reporting(struct drm_i915_private *i915,
515 struct intel_crtc *crtc,
518 crtc->cpu_fifo_underrun_disabled = !enable;
521 * We track the PCH trancoder underrun reporting state
522 * within the crtc. With crtc for pipe A housing the underrun
523 * reporting state for PCH transcoder A, crtc for pipe B housing
524 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
525 * and marking underrun reporting as disabled for the non-existing
526 * PCH transcoders B and C would prevent enabling the south
527 * error interrupt (see cpt_can_enable_serr_int()).
529 if (intel_has_pch_trancoder(i915, crtc->pipe))
530 crtc->pch_fifo_underrun_disabled = !enable;