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 "intel_drv.h"
32 * DOC: fifo underrun handling
34 * The i915 driver checks for display fifo underruns using the interrupt signals
35 * provided by the hardware. This is enabled by default and fairly useful to
36 * debug display issues, especially watermark settings.
38 * If an underrun is detected this is logged into dmesg. To avoid flooding logs
39 * and occupying the cpu underrun interrupts are disabled after the first
40 * occurrence until the next modeset on a given pipe.
42 * Note that underrun detection on gmch platforms is a bit more ugly since there
43 * is no interrupt (despite that the signalling bit is in the PIPESTAT pipe
44 * interrupt register). Also on some other platforms underrun interrupts are
45 * shared, which means that if we detect an underrun we need to disable underrun
46 * reporting on all pipes.
48 * The code also supports underrun detection on the PCH transcoder.
51 static bool ivb_can_enable_err_int(struct drm_device
*dev
)
53 struct drm_i915_private
*dev_priv
= to_i915(dev
);
54 struct intel_crtc
*crtc
;
57 assert_spin_locked(&dev_priv
->irq_lock
);
59 for_each_pipe(dev_priv
, pipe
) {
60 crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
62 if (crtc
->cpu_fifo_underrun_disabled
)
69 static bool cpt_can_enable_serr_int(struct drm_device
*dev
)
71 struct drm_i915_private
*dev_priv
= to_i915(dev
);
73 struct intel_crtc
*crtc
;
75 assert_spin_locked(&dev_priv
->irq_lock
);
77 for_each_pipe(dev_priv
, pipe
) {
78 crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
80 if (crtc
->pch_fifo_underrun_disabled
)
87 static void i9xx_check_fifo_underruns(struct intel_crtc
*crtc
)
89 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
90 i915_reg_t reg
= PIPESTAT(crtc
->pipe
);
91 u32 pipestat
= I915_READ(reg
) & 0xffff0000;
93 assert_spin_locked(&dev_priv
->irq_lock
);
95 if ((pipestat
& PIPE_FIFO_UNDERRUN_STATUS
) == 0)
98 I915_WRITE(reg
, pipestat
| PIPE_FIFO_UNDERRUN_STATUS
);
101 DRM_ERROR("pipe %c underrun\n", pipe_name(crtc
->pipe
));
104 static void i9xx_set_fifo_underrun_reporting(struct drm_device
*dev
,
106 bool enable
, bool old
)
108 struct drm_i915_private
*dev_priv
= to_i915(dev
);
109 i915_reg_t reg
= PIPESTAT(pipe
);
110 u32 pipestat
= I915_READ(reg
) & 0xffff0000;
112 assert_spin_locked(&dev_priv
->irq_lock
);
115 I915_WRITE(reg
, pipestat
| PIPE_FIFO_UNDERRUN_STATUS
);
118 if (old
&& pipestat
& PIPE_FIFO_UNDERRUN_STATUS
)
119 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe
));
123 static void ironlake_set_fifo_underrun_reporting(struct drm_device
*dev
,
124 enum pipe pipe
, bool enable
)
126 struct drm_i915_private
*dev_priv
= to_i915(dev
);
127 uint32_t bit
= (pipe
== PIPE_A
) ? DE_PIPEA_FIFO_UNDERRUN
:
128 DE_PIPEB_FIFO_UNDERRUN
;
131 ilk_enable_display_irq(dev_priv
, bit
);
133 ilk_disable_display_irq(dev_priv
, bit
);
136 static void ivybridge_check_fifo_underruns(struct intel_crtc
*crtc
)
138 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
139 enum pipe pipe
= crtc
->pipe
;
140 uint32_t err_int
= I915_READ(GEN7_ERR_INT
);
142 assert_spin_locked(&dev_priv
->irq_lock
);
144 if ((err_int
& ERR_INT_FIFO_UNDERRUN(pipe
)) == 0)
147 I915_WRITE(GEN7_ERR_INT
, ERR_INT_FIFO_UNDERRUN(pipe
));
148 POSTING_READ(GEN7_ERR_INT
);
150 DRM_ERROR("fifo underrun on pipe %c\n", pipe_name(pipe
));
153 static void ivybridge_set_fifo_underrun_reporting(struct drm_device
*dev
,
155 bool enable
, bool old
)
157 struct drm_i915_private
*dev_priv
= to_i915(dev
);
159 I915_WRITE(GEN7_ERR_INT
, ERR_INT_FIFO_UNDERRUN(pipe
));
161 if (!ivb_can_enable_err_int(dev
))
164 ilk_enable_display_irq(dev_priv
, DE_ERR_INT_IVB
);
166 ilk_disable_display_irq(dev_priv
, DE_ERR_INT_IVB
);
169 I915_READ(GEN7_ERR_INT
) & ERR_INT_FIFO_UNDERRUN(pipe
)) {
170 DRM_ERROR("uncleared fifo underrun on pipe %c\n",
176 static void broadwell_set_fifo_underrun_reporting(struct drm_device
*dev
,
177 enum pipe pipe
, bool enable
)
179 struct drm_i915_private
*dev_priv
= to_i915(dev
);
182 bdw_enable_pipe_irq(dev_priv
, pipe
, GEN8_PIPE_FIFO_UNDERRUN
);
184 bdw_disable_pipe_irq(dev_priv
, pipe
, GEN8_PIPE_FIFO_UNDERRUN
);
187 static void ibx_set_fifo_underrun_reporting(struct drm_device
*dev
,
188 enum transcoder pch_transcoder
,
191 struct drm_i915_private
*dev_priv
= to_i915(dev
);
192 uint32_t bit
= (pch_transcoder
== TRANSCODER_A
) ?
193 SDE_TRANSA_FIFO_UNDER
: SDE_TRANSB_FIFO_UNDER
;
196 ibx_enable_display_interrupt(dev_priv
, bit
);
198 ibx_disable_display_interrupt(dev_priv
, bit
);
201 static void cpt_check_pch_fifo_underruns(struct intel_crtc
*crtc
)
203 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
204 enum transcoder pch_transcoder
= (enum transcoder
) crtc
->pipe
;
205 uint32_t serr_int
= I915_READ(SERR_INT
);
207 assert_spin_locked(&dev_priv
->irq_lock
);
209 if ((serr_int
& SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder
)) == 0)
212 I915_WRITE(SERR_INT
, SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder
));
213 POSTING_READ(SERR_INT
);
215 DRM_ERROR("pch fifo underrun on pch transcoder %s\n",
216 transcoder_name(pch_transcoder
));
219 static void cpt_set_fifo_underrun_reporting(struct drm_device
*dev
,
220 enum transcoder pch_transcoder
,
221 bool enable
, bool old
)
223 struct drm_i915_private
*dev_priv
= to_i915(dev
);
227 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder
));
229 if (!cpt_can_enable_serr_int(dev
))
232 ibx_enable_display_interrupt(dev_priv
, SDE_ERROR_CPT
);
234 ibx_disable_display_interrupt(dev_priv
, SDE_ERROR_CPT
);
236 if (old
&& I915_READ(SERR_INT
) &
237 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder
)) {
238 DRM_ERROR("uncleared pch fifo underrun on pch transcoder %s\n",
239 transcoder_name(pch_transcoder
));
244 static bool __intel_set_cpu_fifo_underrun_reporting(struct drm_device
*dev
,
245 enum pipe pipe
, bool enable
)
247 struct drm_i915_private
*dev_priv
= to_i915(dev
);
248 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
251 assert_spin_locked(&dev_priv
->irq_lock
);
253 old
= !crtc
->cpu_fifo_underrun_disabled
;
254 crtc
->cpu_fifo_underrun_disabled
= !enable
;
256 if (HAS_GMCH_DISPLAY(dev_priv
))
257 i9xx_set_fifo_underrun_reporting(dev
, pipe
, enable
, old
);
258 else if (IS_GEN5(dev_priv
) || IS_GEN6(dev_priv
))
259 ironlake_set_fifo_underrun_reporting(dev
, pipe
, enable
);
260 else if (IS_GEN7(dev_priv
))
261 ivybridge_set_fifo_underrun_reporting(dev
, pipe
, enable
, old
);
262 else if (IS_GEN8(dev_priv
) || IS_GEN9(dev_priv
))
263 broadwell_set_fifo_underrun_reporting(dev
, pipe
, enable
);
269 * intel_set_cpu_fifo_underrun_reporting - set cpu fifo underrrun reporting state
270 * @dev_priv: i915 device instance
271 * @pipe: (CPU) pipe to set state for
272 * @enable: whether underruns should be reported or not
274 * This function sets the fifo underrun state for @pipe. It is used in the
275 * modeset code to avoid false positives since on many platforms underruns are
276 * expected when disabling or enabling the pipe.
278 * Notice that on some platforms disabling underrun reports for one pipe
279 * disables for all due to shared interrupts. Actual reporting is still per-pipe
282 * Returns the previous state of underrun reporting.
284 bool intel_set_cpu_fifo_underrun_reporting(struct drm_i915_private
*dev_priv
,
285 enum pipe pipe
, bool enable
)
290 spin_lock_irqsave(&dev_priv
->irq_lock
, flags
);
291 ret
= __intel_set_cpu_fifo_underrun_reporting(&dev_priv
->drm
, pipe
,
293 spin_unlock_irqrestore(&dev_priv
->irq_lock
, flags
);
299 * intel_set_pch_fifo_underrun_reporting - set PCH fifo underrun reporting state
300 * @dev_priv: i915 device instance
301 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
302 * @enable: whether underruns should be reported or not
304 * This function makes us disable or enable PCH fifo underruns for a specific
305 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
306 * underrun reporting for one transcoder may also disable all the other PCH
307 * error interruts for the other transcoders, due to the fact that there's just
308 * one interrupt mask/enable bit for all the transcoders.
310 * Returns the previous state of underrun reporting.
312 bool intel_set_pch_fifo_underrun_reporting(struct drm_i915_private
*dev_priv
,
313 enum transcoder pch_transcoder
,
316 struct intel_crtc
*crtc
=
317 intel_get_crtc_for_pipe(dev_priv
, (enum pipe
) pch_transcoder
);
322 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
323 * has only one pch transcoder A that all pipes can use. To avoid racy
324 * pch transcoder -> pipe lookups from interrupt code simply store the
325 * underrun statistics in crtc A. Since we never expose this anywhere
326 * nor use it outside of the fifo underrun code here using the "wrong"
327 * crtc on LPT won't cause issues.
330 spin_lock_irqsave(&dev_priv
->irq_lock
, flags
);
332 old
= !crtc
->pch_fifo_underrun_disabled
;
333 crtc
->pch_fifo_underrun_disabled
= !enable
;
335 if (HAS_PCH_IBX(dev_priv
))
336 ibx_set_fifo_underrun_reporting(&dev_priv
->drm
,
340 cpt_set_fifo_underrun_reporting(&dev_priv
->drm
,
344 spin_unlock_irqrestore(&dev_priv
->irq_lock
, flags
);
349 * intel_cpu_fifo_underrun_irq_handler - handle CPU fifo underrun interrupt
350 * @dev_priv: i915 device instance
351 * @pipe: (CPU) pipe to set state for
353 * This handles a CPU fifo underrun interrupt, generating an underrun warning
354 * into dmesg if underrun reporting is enabled and then disables the underrun
355 * interrupt to avoid an irq storm.
357 void intel_cpu_fifo_underrun_irq_handler(struct drm_i915_private
*dev_priv
,
360 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
362 /* We may be called too early in init, thanks BIOS! */
366 /* GMCH can't disable fifo underruns, filter them. */
367 if (HAS_GMCH_DISPLAY(dev_priv
) &&
368 crtc
->cpu_fifo_underrun_disabled
)
371 if (intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, false))
372 DRM_ERROR("CPU pipe %c FIFO underrun\n",
375 intel_fbc_handle_fifo_underrun_irq(dev_priv
);
379 * intel_pch_fifo_underrun_irq_handler - handle PCH fifo underrun interrupt
380 * @dev_priv: i915 device instance
381 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
383 * This handles a PCH fifo underrun interrupt, generating an underrun warning
384 * into dmesg if underrun reporting is enabled and then disables the underrun
385 * interrupt to avoid an irq storm.
387 void intel_pch_fifo_underrun_irq_handler(struct drm_i915_private
*dev_priv
,
388 enum transcoder pch_transcoder
)
390 if (intel_set_pch_fifo_underrun_reporting(dev_priv
, pch_transcoder
,
392 DRM_ERROR("PCH transcoder %s FIFO underrun\n",
393 transcoder_name(pch_transcoder
));
397 * intel_check_cpu_fifo_underruns - check for CPU fifo underruns immediately
398 * @dev_priv: i915 device instance
400 * Check for CPU fifo underruns immediately. Useful on IVB/HSW where the shared
401 * error interrupt may have been disabled, and so CPU fifo underruns won't
402 * necessarily raise an interrupt, and on GMCH platforms where underruns never
403 * raise an interrupt.
405 void intel_check_cpu_fifo_underruns(struct drm_i915_private
*dev_priv
)
407 struct intel_crtc
*crtc
;
409 spin_lock_irq(&dev_priv
->irq_lock
);
411 for_each_intel_crtc(&dev_priv
->drm
, crtc
) {
412 if (crtc
->cpu_fifo_underrun_disabled
)
415 if (HAS_GMCH_DISPLAY(dev_priv
))
416 i9xx_check_fifo_underruns(crtc
);
417 else if (IS_GEN7(dev_priv
))
418 ivybridge_check_fifo_underruns(crtc
);
421 spin_unlock_irq(&dev_priv
->irq_lock
);
425 * intel_check_pch_fifo_underruns - check for PCH fifo underruns immediately
426 * @dev_priv: i915 device instance
428 * Check for PCH fifo underruns immediately. Useful on CPT/PPT where the shared
429 * error interrupt may have been disabled, and so PCH fifo underruns won't
430 * necessarily raise an interrupt.
432 void intel_check_pch_fifo_underruns(struct drm_i915_private
*dev_priv
)
434 struct intel_crtc
*crtc
;
436 spin_lock_irq(&dev_priv
->irq_lock
);
438 for_each_intel_crtc(&dev_priv
->drm
, crtc
) {
439 if (crtc
->pch_fifo_underrun_disabled
)
442 if (HAS_PCH_CPT(dev_priv
))
443 cpt_check_pch_fifo_underruns(crtc
);
446 spin_unlock_irq(&dev_priv
->irq_lock
);