blob: af906c7db5c337164773197ad93d86429b12442c [file] [log] [blame]
Daniel Vetter47339cd2014-09-30 10:56:46 +02001/*
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
28#include "i915_drv.h"
29#include "intel_drv.h"
30
Daniel Vetteref073882014-09-30 10:56:50 +020031/**
32 * DOC: fifo underrun handling
33 *
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.
37 *
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.
41 *
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.
47 *
48 * The code also supports underrun detection on the PCH transcoder.
49 */
50
Daniel Vetter47339cd2014-09-30 10:56:46 +020051static bool ivb_can_enable_err_int(struct drm_device *dev)
52{
53 struct drm_i915_private *dev_priv = dev->dev_private;
54 struct intel_crtc *crtc;
55 enum pipe pipe;
56
57 assert_spin_locked(&dev_priv->irq_lock);
58
59 for_each_pipe(dev_priv, pipe) {
60 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
61
62 if (crtc->cpu_fifo_underrun_disabled)
63 return false;
64 }
65
66 return true;
67}
68
69static bool cpt_can_enable_serr_int(struct drm_device *dev)
70{
71 struct drm_i915_private *dev_priv = dev->dev_private;
72 enum pipe pipe;
73 struct intel_crtc *crtc;
74
75 assert_spin_locked(&dev_priv->irq_lock);
76
77 for_each_pipe(dev_priv, pipe) {
78 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
79
80 if (crtc->pch_fifo_underrun_disabled)
81 return false;
82 }
83
84 return true;
85}
86
Ville Syrjäläaca7b682015-10-30 19:22:21 +020087static void i9xx_check_fifo_underruns(struct intel_crtc *crtc)
Daniel Vetter47339cd2014-09-30 10:56:46 +020088{
Ville Syrjäläaca7b682015-10-30 19:22:21 +020089 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
90 u32 reg = PIPESTAT(crtc->pipe);
91 u32 pipestat = I915_READ(reg) & 0xffff0000;
Daniel Vetter47339cd2014-09-30 10:56:46 +020092
Ville Syrjäläaca7b682015-10-30 19:22:21 +020093 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetter47339cd2014-09-30 10:56:46 +020094
Ville Syrjäläaca7b682015-10-30 19:22:21 +020095 if ((pipestat & PIPE_FIFO_UNDERRUN_STATUS) == 0)
96 return;
Daniel Vetter47339cd2014-09-30 10:56:46 +020097
Ville Syrjäläaca7b682015-10-30 19:22:21 +020098 I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS);
99 POSTING_READ(reg);
Daniel Vetter47339cd2014-09-30 10:56:46 +0200100
Ville Syrjäläaca7b682015-10-30 19:22:21 +0200101 DRM_ERROR("pipe %c underrun\n", pipe_name(crtc->pipe));
Daniel Vetter47339cd2014-09-30 10:56:46 +0200102}
103
104static void i9xx_set_fifo_underrun_reporting(struct drm_device *dev,
105 enum pipe pipe,
106 bool enable, bool old)
107{
108 struct drm_i915_private *dev_priv = dev->dev_private;
109 u32 reg = PIPESTAT(pipe);
110 u32 pipestat = I915_READ(reg) & 0xffff0000;
111
112 assert_spin_locked(&dev_priv->irq_lock);
113
114 if (enable) {
115 I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS);
116 POSTING_READ(reg);
117 } else {
118 if (old && pipestat & PIPE_FIFO_UNDERRUN_STATUS)
119 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
120 }
121}
122
123static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
124 enum pipe pipe, bool enable)
125{
126 struct drm_i915_private *dev_priv = dev->dev_private;
127 uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
128 DE_PIPEB_FIFO_UNDERRUN;
129
130 if (enable)
131 ironlake_enable_display_irq(dev_priv, bit);
132 else
133 ironlake_disable_display_irq(dev_priv, bit);
134}
135
Ville Syrjäläaca7b682015-10-30 19:22:21 +0200136static void ivybridge_check_fifo_underruns(struct intel_crtc *crtc)
137{
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);
141
142 assert_spin_locked(&dev_priv->irq_lock);
143
144 if ((err_int & ERR_INT_FIFO_UNDERRUN(pipe)) == 0)
145 return;
146
147 I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
148 POSTING_READ(GEN7_ERR_INT);
149
150 DRM_ERROR("fifo underrun on pipe %c\n", pipe_name(pipe));
151}
152
Daniel Vetter47339cd2014-09-30 10:56:46 +0200153static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
154 enum pipe pipe,
155 bool enable, bool old)
156{
157 struct drm_i915_private *dev_priv = dev->dev_private;
158 if (enable) {
159 I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
160
161 if (!ivb_can_enable_err_int(dev))
162 return;
163
164 ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
165 } else {
166 ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
167
168 if (old &&
169 I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe)) {
170 DRM_ERROR("uncleared fifo underrun on pipe %c\n",
171 pipe_name(pipe));
172 }
173 }
174}
175
176static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev,
177 enum pipe pipe, bool enable)
178{
179 struct drm_i915_private *dev_priv = dev->dev_private;
180
181 assert_spin_locked(&dev_priv->irq_lock);
182
183 if (enable)
184 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_FIFO_UNDERRUN;
185 else
186 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_FIFO_UNDERRUN;
187 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
188 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
189}
190
191static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
192 enum transcoder pch_transcoder,
193 bool enable)
194{
195 struct drm_i915_private *dev_priv = dev->dev_private;
196 uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
197 SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
198
199 if (enable)
200 ibx_enable_display_interrupt(dev_priv, bit);
201 else
202 ibx_disable_display_interrupt(dev_priv, bit);
203}
204
Ville Syrjäläaca7b682015-10-30 19:22:21 +0200205static void cpt_check_pch_fifo_underruns(struct intel_crtc *crtc)
206{
207 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
208 enum transcoder pch_transcoder = (enum transcoder) crtc->pipe;
209 uint32_t serr_int = I915_READ(SERR_INT);
210
211 assert_spin_locked(&dev_priv->irq_lock);
212
213 if ((serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) == 0)
214 return;
215
216 I915_WRITE(SERR_INT, SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
217 POSTING_READ(SERR_INT);
218
219 DRM_ERROR("pch fifo underrun on pch transcoder %c\n",
220 transcoder_name(pch_transcoder));
221}
222
Daniel Vetter47339cd2014-09-30 10:56:46 +0200223static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
224 enum transcoder pch_transcoder,
225 bool enable, bool old)
226{
227 struct drm_i915_private *dev_priv = dev->dev_private;
228
229 if (enable) {
230 I915_WRITE(SERR_INT,
231 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
232
233 if (!cpt_can_enable_serr_int(dev))
234 return;
235
236 ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
237 } else {
238 ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
239
240 if (old && I915_READ(SERR_INT) &
241 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) {
242 DRM_ERROR("uncleared pch fifo underrun on pch transcoder %c\n",
243 transcoder_name(pch_transcoder));
244 }
245 }
246}
247
Daniel Vetter47339cd2014-09-30 10:56:46 +0200248static bool __intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
249 enum pipe pipe, bool enable)
250{
251 struct drm_i915_private *dev_priv = dev->dev_private;
252 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
253 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
254 bool old;
255
256 assert_spin_locked(&dev_priv->irq_lock);
257
258 old = !intel_crtc->cpu_fifo_underrun_disabled;
259 intel_crtc->cpu_fifo_underrun_disabled = !enable;
260
261 if (HAS_GMCH_DISPLAY(dev))
262 i9xx_set_fifo_underrun_reporting(dev, pipe, enable, old);
263 else if (IS_GEN5(dev) || IS_GEN6(dev))
264 ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
265 else if (IS_GEN7(dev))
266 ivybridge_set_fifo_underrun_reporting(dev, pipe, enable, old);
267 else if (IS_GEN8(dev) || IS_GEN9(dev))
268 broadwell_set_fifo_underrun_reporting(dev, pipe, enable);
269
270 return old;
271}
272
Daniel Vetteref073882014-09-30 10:56:50 +0200273/**
274 * intel_set_cpu_fifo_underrun_reporting - set cpu fifo underrrun reporting state
275 * @dev_priv: i915 device instance
276 * @pipe: (CPU) pipe to set state for
277 * @enable: whether underruns should be reported or not
278 *
279 * This function sets the fifo underrun state for @pipe. It is used in the
280 * modeset code to avoid false positives since on many platforms underruns are
281 * expected when disabling or enabling the pipe.
282 *
283 * Notice that on some platforms disabling underrun reports for one pipe
284 * disables for all due to shared interrupts. Actual reporting is still per-pipe
285 * though.
286 *
287 * Returns the previous state of underrun reporting.
288 */
Daniel Vettera72e4c92014-09-30 10:56:47 +0200289bool intel_set_cpu_fifo_underrun_reporting(struct drm_i915_private *dev_priv,
Daniel Vetter47339cd2014-09-30 10:56:46 +0200290 enum pipe pipe, bool enable)
291{
Daniel Vetter47339cd2014-09-30 10:56:46 +0200292 unsigned long flags;
293 bool ret;
294
295 spin_lock_irqsave(&dev_priv->irq_lock, flags);
Daniel Vettera72e4c92014-09-30 10:56:47 +0200296 ret = __intel_set_cpu_fifo_underrun_reporting(dev_priv->dev, pipe,
297 enable);
Daniel Vetter47339cd2014-09-30 10:56:46 +0200298 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
299
300 return ret;
301}
302
Daniel Vetter47339cd2014-09-30 10:56:46 +0200303/**
Daniel Vetteref073882014-09-30 10:56:50 +0200304 * intel_set_pch_fifo_underrun_reporting - set PCH fifo underrun reporting state
305 * @dev_priv: i915 device instance
Daniel Vetter47339cd2014-09-30 10:56:46 +0200306 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
Daniel Vetteref073882014-09-30 10:56:50 +0200307 * @enable: whether underruns should be reported or not
Daniel Vetter47339cd2014-09-30 10:56:46 +0200308 *
309 * This function makes us disable or enable PCH fifo underruns for a specific
310 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
311 * underrun reporting for one transcoder may also disable all the other PCH
312 * error interruts for the other transcoders, due to the fact that there's just
313 * one interrupt mask/enable bit for all the transcoders.
314 *
315 * Returns the previous state of underrun reporting.
316 */
Daniel Vettera72e4c92014-09-30 10:56:47 +0200317bool intel_set_pch_fifo_underrun_reporting(struct drm_i915_private *dev_priv,
Daniel Vetter47339cd2014-09-30 10:56:46 +0200318 enum transcoder pch_transcoder,
319 bool enable)
320{
Daniel Vetter47339cd2014-09-30 10:56:46 +0200321 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder];
322 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
323 unsigned long flags;
324 bool old;
325
326 /*
327 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
328 * has only one pch transcoder A that all pipes can use. To avoid racy
329 * pch transcoder -> pipe lookups from interrupt code simply store the
330 * underrun statistics in crtc A. Since we never expose this anywhere
331 * nor use it outside of the fifo underrun code here using the "wrong"
332 * crtc on LPT won't cause issues.
333 */
334
335 spin_lock_irqsave(&dev_priv->irq_lock, flags);
336
337 old = !intel_crtc->pch_fifo_underrun_disabled;
338 intel_crtc->pch_fifo_underrun_disabled = !enable;
339
Daniel Vettera72e4c92014-09-30 10:56:47 +0200340 if (HAS_PCH_IBX(dev_priv->dev))
341 ibx_set_fifo_underrun_reporting(dev_priv->dev, pch_transcoder,
342 enable);
Daniel Vetter47339cd2014-09-30 10:56:46 +0200343 else
Daniel Vettera72e4c92014-09-30 10:56:47 +0200344 cpt_set_fifo_underrun_reporting(dev_priv->dev, pch_transcoder,
345 enable, old);
Daniel Vetter47339cd2014-09-30 10:56:46 +0200346
347 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
348 return old;
349}
Daniel Vetter1f7247c2014-09-30 10:56:48 +0200350
Daniel Vetteref073882014-09-30 10:56:50 +0200351/**
Kumar Amit Mehtacea3bf82015-01-26 17:47:32 +0100352 * intel_cpu_fifo_underrun_irq_handler - handle CPU fifo underrun interrupt
Daniel Vetteref073882014-09-30 10:56:50 +0200353 * @dev_priv: i915 device instance
354 * @pipe: (CPU) pipe to set state for
355 *
356 * This handles a CPU fifo underrun interrupt, generating an underrun warning
357 * into dmesg if underrun reporting is enabled and then disables the underrun
358 * interrupt to avoid an irq storm.
359 */
Daniel Vetter1f7247c2014-09-30 10:56:48 +0200360void intel_cpu_fifo_underrun_irq_handler(struct drm_i915_private *dev_priv,
361 enum pipe pipe)
362{
Chris Wilson54fc7c12015-02-26 15:53:02 +0000363 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
364
365 /* We may be called too early in init, thanks BIOS! */
366 if (crtc == NULL)
367 return;
368
Daniel Vetter0f239f42014-09-30 10:56:49 +0200369 /* GMCH can't disable fifo underruns, filter them. */
370 if (HAS_GMCH_DISPLAY(dev_priv->dev) &&
Chris Wilson54fc7c12015-02-26 15:53:02 +0000371 to_intel_crtc(crtc)->cpu_fifo_underrun_disabled)
Daniel Vetter0f239f42014-09-30 10:56:49 +0200372 return;
373
Daniel Vetter1f7247c2014-09-30 10:56:48 +0200374 if (intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false))
375 DRM_ERROR("CPU pipe %c FIFO underrun\n",
376 pipe_name(pipe));
377}
378
Daniel Vetteref073882014-09-30 10:56:50 +0200379/**
380 * intel_pch_fifo_underrun_irq_handler - handle PCH fifo underrun interrupt
381 * @dev_priv: i915 device instance
382 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
383 *
384 * This handles a PCH fifo underrun interrupt, generating an underrun warning
385 * into dmesg if underrun reporting is enabled and then disables the underrun
386 * interrupt to avoid an irq storm.
387 */
Daniel Vetter1f7247c2014-09-30 10:56:48 +0200388void intel_pch_fifo_underrun_irq_handler(struct drm_i915_private *dev_priv,
389 enum transcoder pch_transcoder)
390{
391 if (intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder,
392 false))
393 DRM_ERROR("PCH transcoder %c FIFO underrun\n",
394 transcoder_name(pch_transcoder));
395}
Ville Syrjäläaca7b682015-10-30 19:22:21 +0200396
397/**
398 * intel_check_cpu_fifo_underruns - check for CPU fifo underruns immediately
399 * @dev_priv: i915 device instance
400 *
401 * Check for CPU fifo underruns immediately. Useful on IVB/HSW where the shared
402 * error interrupt may have been disabled, and so CPU fifo underruns won't
403 * necessarily raise an interrupt, and on GMCH platforms where underruns never
404 * raise an interrupt.
405 */
406void intel_check_cpu_fifo_underruns(struct drm_i915_private *dev_priv)
407{
408 struct intel_crtc *crtc;
409
410 spin_lock_irq(&dev_priv->irq_lock);
411
412 for_each_intel_crtc(dev_priv->dev, crtc) {
413 if (crtc->cpu_fifo_underrun_disabled)
414 continue;
415
416 if (HAS_GMCH_DISPLAY(dev_priv))
417 i9xx_check_fifo_underruns(crtc);
418 else if (IS_GEN7(dev_priv))
419 ivybridge_check_fifo_underruns(crtc);
420 }
421
422 spin_unlock_irq(&dev_priv->irq_lock);
423}
424
425/**
426 * intel_check_pch_fifo_underruns - check for PCH fifo underruns immediately
427 * @dev_priv: i915 device instance
428 *
429 * Check for PCH fifo underruns immediately. Useful on CPT/PPT where the shared
430 * error interrupt may have been disabled, and so PCH fifo underruns won't
431 * necessarily raise an interrupt.
432 */
433void intel_check_pch_fifo_underruns(struct drm_i915_private *dev_priv)
434{
435 struct intel_crtc *crtc;
436
437 spin_lock_irq(&dev_priv->irq_lock);
438
439 for_each_intel_crtc(dev_priv->dev, crtc) {
440 if (crtc->pch_fifo_underrun_disabled)
441 continue;
442
443 if (HAS_PCH_CPT(dev_priv))
444 cpt_check_pch_fifo_underruns(crtc);
445 }
446
447 spin_unlock_irq(&dev_priv->irq_lock);
448}