xref: /linux/drivers/gpu/drm/i915/display/intel_fifo_underrun.c (revision a4871e6201c46c8e1d04308265b4b4c5753c8209)
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 
28 #include "i915_drv.h"
29 #include "i915_reg.h"
30 #include "intel_de.h"
31 #include "intel_display_irq.h"
32 #include "intel_display_trace.h"
33 #include "intel_display_types.h"
34 #include "intel_fbc.h"
35 #include "intel_fifo_underrun.h"
36 #include "intel_pch_display.h"
37 
38 /**
39  * DOC: fifo underrun handling
40  *
41  * The i915 driver checks for display fifo underruns using the interrupt signals
42  * provided by the hardware. This is enabled by default and fairly useful to
43  * debug display issues, especially watermark settings.
44  *
45  * If an underrun is detected this is logged into dmesg. To avoid flooding logs
46  * and occupying the cpu underrun interrupts are disabled after the first
47  * occurrence until the next modeset on a given pipe.
48  *
49  * Note that underrun detection on gmch platforms is a bit more ugly since there
50  * is no interrupt (despite that the signalling bit is in the PIPESTAT pipe
51  * interrupt register). Also on some other platforms underrun interrupts are
52  * shared, which means that if we detect an underrun we need to disable underrun
53  * reporting on all pipes.
54  *
55  * The code also supports underrun detection on the PCH transcoder.
56  */
57 
58 static bool ivb_can_enable_err_int(struct intel_display *display)
59 {
60 	struct drm_i915_private *dev_priv = to_i915(display->drm);
61 	struct intel_crtc *crtc;
62 	enum pipe pipe;
63 
64 	lockdep_assert_held(&dev_priv->irq_lock);
65 
66 	for_each_pipe(display, pipe) {
67 		crtc = intel_crtc_for_pipe(display, pipe);
68 
69 		if (crtc->cpu_fifo_underrun_disabled)
70 			return false;
71 	}
72 
73 	return true;
74 }
75 
76 static bool cpt_can_enable_serr_int(struct intel_display *display)
77 {
78 	struct drm_i915_private *dev_priv = to_i915(display->drm);
79 	enum pipe pipe;
80 	struct intel_crtc *crtc;
81 
82 	lockdep_assert_held(&dev_priv->irq_lock);
83 
84 	for_each_pipe(display, pipe) {
85 		crtc = intel_crtc_for_pipe(display, pipe);
86 
87 		if (crtc->pch_fifo_underrun_disabled)
88 			return false;
89 	}
90 
91 	return true;
92 }
93 
94 static void i9xx_check_fifo_underruns(struct intel_crtc *crtc)
95 {
96 	struct intel_display *display = to_intel_display(crtc);
97 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
98 	i915_reg_t reg = PIPESTAT(display, crtc->pipe);
99 	u32 enable_mask;
100 
101 	lockdep_assert_held(&dev_priv->irq_lock);
102 
103 	if ((intel_de_read(display, reg) & PIPE_FIFO_UNDERRUN_STATUS) == 0)
104 		return;
105 
106 	enable_mask = i915_pipestat_enable_mask(display, crtc->pipe);
107 	intel_de_write(display, reg, enable_mask | PIPE_FIFO_UNDERRUN_STATUS);
108 	intel_de_posting_read(display, reg);
109 
110 	trace_intel_cpu_fifo_underrun(display, crtc->pipe);
111 	drm_err(display->drm, "pipe %c underrun\n", pipe_name(crtc->pipe));
112 }
113 
114 static void i9xx_set_fifo_underrun_reporting(struct intel_display *display,
115 					     enum pipe pipe,
116 					     bool enable, bool old)
117 {
118 	struct drm_i915_private *dev_priv = to_i915(display->drm);
119 	i915_reg_t reg = PIPESTAT(display, pipe);
120 
121 	lockdep_assert_held(&dev_priv->irq_lock);
122 
123 	if (enable) {
124 		u32 enable_mask = i915_pipestat_enable_mask(display, pipe);
125 
126 		intel_de_write(display, reg,
127 			       enable_mask | PIPE_FIFO_UNDERRUN_STATUS);
128 		intel_de_posting_read(display, reg);
129 	} else {
130 		if (old && intel_de_read(display, reg) & PIPE_FIFO_UNDERRUN_STATUS)
131 			drm_err(display->drm, "pipe %c underrun\n",
132 				pipe_name(pipe));
133 	}
134 }
135 
136 static void ilk_set_fifo_underrun_reporting(struct intel_display *display,
137 					    enum pipe pipe, bool enable)
138 {
139 	u32 bit = (pipe == PIPE_A) ?
140 		DE_PIPEA_FIFO_UNDERRUN : DE_PIPEB_FIFO_UNDERRUN;
141 
142 	if (enable)
143 		ilk_enable_display_irq(display, bit);
144 	else
145 		ilk_disable_display_irq(display, bit);
146 }
147 
148 static void ivb_check_fifo_underruns(struct intel_crtc *crtc)
149 {
150 	struct intel_display *display = to_intel_display(crtc);
151 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
152 	enum pipe pipe = crtc->pipe;
153 	u32 err_int = intel_de_read(display, GEN7_ERR_INT);
154 
155 	lockdep_assert_held(&dev_priv->irq_lock);
156 
157 	if ((err_int & ERR_INT_FIFO_UNDERRUN(pipe)) == 0)
158 		return;
159 
160 	intel_de_write(display, GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
161 	intel_de_posting_read(display, GEN7_ERR_INT);
162 
163 	trace_intel_cpu_fifo_underrun(display, pipe);
164 	drm_err(display->drm, "fifo underrun on pipe %c\n", pipe_name(pipe));
165 }
166 
167 static void ivb_set_fifo_underrun_reporting(struct intel_display *display,
168 					    enum pipe pipe, bool enable,
169 					    bool old)
170 {
171 	if (enable) {
172 		intel_de_write(display, GEN7_ERR_INT,
173 			       ERR_INT_FIFO_UNDERRUN(pipe));
174 
175 		if (!ivb_can_enable_err_int(display))
176 			return;
177 
178 		ilk_enable_display_irq(display, DE_ERR_INT_IVB);
179 	} else {
180 		ilk_disable_display_irq(display, DE_ERR_INT_IVB);
181 
182 		if (old &&
183 		    intel_de_read(display, GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe)) {
184 			drm_err(display->drm,
185 				"uncleared fifo underrun on pipe %c\n",
186 				pipe_name(pipe));
187 		}
188 	}
189 }
190 
191 static void bdw_set_fifo_underrun_reporting(struct intel_display *display,
192 					    enum pipe pipe, bool enable)
193 {
194 	if (enable)
195 		bdw_enable_pipe_irq(display, pipe, GEN8_PIPE_FIFO_UNDERRUN);
196 	else
197 		bdw_disable_pipe_irq(display, pipe, GEN8_PIPE_FIFO_UNDERRUN);
198 }
199 
200 static void ibx_set_fifo_underrun_reporting(struct intel_display *display,
201 					    enum pipe pch_transcoder,
202 					    bool enable)
203 {
204 	u32 bit = (pch_transcoder == PIPE_A) ?
205 		SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
206 
207 	if (enable)
208 		ibx_enable_display_interrupt(display, bit);
209 	else
210 		ibx_disable_display_interrupt(display, bit);
211 }
212 
213 static void cpt_check_pch_fifo_underruns(struct intel_crtc *crtc)
214 {
215 	struct intel_display *display = to_intel_display(crtc);
216 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
217 	enum pipe pch_transcoder = crtc->pipe;
218 	u32 serr_int = intel_de_read(display, SERR_INT);
219 
220 	lockdep_assert_held(&dev_priv->irq_lock);
221 
222 	if ((serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) == 0)
223 		return;
224 
225 	intel_de_write(display, SERR_INT,
226 		       SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
227 	intel_de_posting_read(display, SERR_INT);
228 
229 	trace_intel_pch_fifo_underrun(display, pch_transcoder);
230 	drm_err(display->drm, "pch fifo underrun on pch transcoder %c\n",
231 		pipe_name(pch_transcoder));
232 }
233 
234 static void cpt_set_fifo_underrun_reporting(struct intel_display *display,
235 					    enum pipe pch_transcoder,
236 					    bool enable, bool old)
237 {
238 	if (enable) {
239 		intel_de_write(display, SERR_INT,
240 			       SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
241 
242 		if (!cpt_can_enable_serr_int(display))
243 			return;
244 
245 		ibx_enable_display_interrupt(display, SDE_ERROR_CPT);
246 	} else {
247 		ibx_disable_display_interrupt(display, SDE_ERROR_CPT);
248 
249 		if (old && intel_de_read(display, SERR_INT) &
250 		    SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) {
251 			drm_err(display->drm,
252 				"uncleared pch fifo underrun on pch transcoder %c\n",
253 				pipe_name(pch_transcoder));
254 		}
255 	}
256 }
257 
258 static bool __intel_set_cpu_fifo_underrun_reporting(struct intel_display *display,
259 						    enum pipe pipe, bool enable)
260 {
261 	struct drm_i915_private *dev_priv = to_i915(display->drm);
262 	struct intel_crtc *crtc = intel_crtc_for_pipe(display, pipe);
263 	bool old;
264 
265 	lockdep_assert_held(&dev_priv->irq_lock);
266 
267 	old = !crtc->cpu_fifo_underrun_disabled;
268 	crtc->cpu_fifo_underrun_disabled = !enable;
269 
270 	if (HAS_GMCH(display))
271 		i9xx_set_fifo_underrun_reporting(display, pipe, enable, old);
272 	else if (display->platform.ironlake || display->platform.sandybridge)
273 		ilk_set_fifo_underrun_reporting(display, pipe, enable);
274 	else if (DISPLAY_VER(display) == 7)
275 		ivb_set_fifo_underrun_reporting(display, pipe, enable, old);
276 	else if (DISPLAY_VER(display) >= 8)
277 		bdw_set_fifo_underrun_reporting(display, pipe, enable);
278 
279 	return old;
280 }
281 
282 /**
283  * intel_set_cpu_fifo_underrun_reporting - set cpu fifo underrun reporting state
284  * @display: display device instance
285  * @pipe: (CPU) pipe to set state for
286  * @enable: whether underruns should be reported or not
287  *
288  * This function sets the fifo underrun state for @pipe. It is used in the
289  * modeset code to avoid false positives since on many platforms underruns are
290  * expected when disabling or enabling the pipe.
291  *
292  * Notice that on some platforms disabling underrun reports for one pipe
293  * disables for all due to shared interrupts. Actual reporting is still per-pipe
294  * though.
295  *
296  * Returns the previous state of underrun reporting.
297  */
298 bool intel_set_cpu_fifo_underrun_reporting(struct intel_display *display,
299 					   enum pipe pipe, bool enable)
300 {
301 	struct drm_i915_private *dev_priv = to_i915(display->drm);
302 	unsigned long flags;
303 	bool ret;
304 
305 	spin_lock_irqsave(&dev_priv->irq_lock, flags);
306 	ret = __intel_set_cpu_fifo_underrun_reporting(display, pipe, enable);
307 	spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
308 
309 	return ret;
310 }
311 
312 /**
313  * intel_set_pch_fifo_underrun_reporting - set PCH fifo underrun reporting state
314  * @display: display device instance
315  * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
316  * @enable: whether underruns should be reported or not
317  *
318  * This function makes us disable or enable PCH fifo underruns for a specific
319  * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
320  * underrun reporting for one transcoder may also disable all the other PCH
321  * error interruts for the other transcoders, due to the fact that there's just
322  * one interrupt mask/enable bit for all the transcoders.
323  *
324  * Returns the previous state of underrun reporting.
325  */
326 bool intel_set_pch_fifo_underrun_reporting(struct intel_display *display,
327 					   enum pipe pch_transcoder,
328 					   bool enable)
329 {
330 	struct drm_i915_private *dev_priv = to_i915(display->drm);
331 	struct intel_crtc *crtc = intel_crtc_for_pipe(display, pch_transcoder);
332 	unsigned long flags;
333 	bool old;
334 
335 	/*
336 	 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
337 	 * has only one pch transcoder A that all pipes can use. To avoid racy
338 	 * pch transcoder -> pipe lookups from interrupt code simply store the
339 	 * underrun statistics in crtc A. Since we never expose this anywhere
340 	 * nor use it outside of the fifo underrun code here using the "wrong"
341 	 * crtc on LPT won't cause issues.
342 	 */
343 
344 	spin_lock_irqsave(&dev_priv->irq_lock, flags);
345 
346 	old = !crtc->pch_fifo_underrun_disabled;
347 	crtc->pch_fifo_underrun_disabled = !enable;
348 
349 	if (HAS_PCH_IBX(dev_priv))
350 		ibx_set_fifo_underrun_reporting(display,
351 						pch_transcoder,
352 						enable);
353 	else
354 		cpt_set_fifo_underrun_reporting(display,
355 						pch_transcoder,
356 						enable, old);
357 
358 	spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
359 	return old;
360 }
361 
362 /**
363  * intel_cpu_fifo_underrun_irq_handler - handle CPU fifo underrun interrupt
364  * @display: display device instance
365  * @pipe: (CPU) pipe to set state for
366  *
367  * This handles a CPU fifo underrun interrupt, generating an underrun warning
368  * into dmesg if underrun reporting is enabled and then disables the underrun
369  * interrupt to avoid an irq storm.
370  */
371 void intel_cpu_fifo_underrun_irq_handler(struct intel_display *display,
372 					 enum pipe pipe)
373 {
374 	struct intel_crtc *crtc = intel_crtc_for_pipe(display, pipe);
375 
376 	/* We may be called too early in init, thanks BIOS! */
377 	if (crtc == NULL)
378 		return;
379 
380 	/* GMCH can't disable fifo underruns, filter them. */
381 	if (HAS_GMCH(display) &&
382 	    crtc->cpu_fifo_underrun_disabled)
383 		return;
384 
385 	if (intel_set_cpu_fifo_underrun_reporting(display, pipe, false)) {
386 		trace_intel_cpu_fifo_underrun(display, pipe);
387 
388 		drm_err(display->drm, "CPU pipe %c FIFO underrun\n", pipe_name(pipe));
389 	}
390 
391 	intel_fbc_handle_fifo_underrun_irq(display);
392 }
393 
394 /**
395  * intel_pch_fifo_underrun_irq_handler - handle PCH fifo underrun interrupt
396  * @display: display device instance
397  * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
398  *
399  * This handles a PCH fifo underrun interrupt, generating an underrun warning
400  * into dmesg if underrun reporting is enabled and then disables the underrun
401  * interrupt to avoid an irq storm.
402  */
403 void intel_pch_fifo_underrun_irq_handler(struct intel_display *display,
404 					 enum pipe pch_transcoder)
405 {
406 	if (intel_set_pch_fifo_underrun_reporting(display, pch_transcoder,
407 						  false)) {
408 		trace_intel_pch_fifo_underrun(display, pch_transcoder);
409 		drm_err(display->drm, "PCH transcoder %c FIFO underrun\n",
410 			pipe_name(pch_transcoder));
411 	}
412 }
413 
414 /**
415  * intel_check_cpu_fifo_underruns - check for CPU fifo underruns immediately
416  * @display: display device instance
417  *
418  * Check for CPU fifo underruns immediately. Useful on IVB/HSW where the shared
419  * error interrupt may have been disabled, and so CPU fifo underruns won't
420  * necessarily raise an interrupt, and on GMCH platforms where underruns never
421  * raise an interrupt.
422  */
423 void intel_check_cpu_fifo_underruns(struct intel_display *display)
424 {
425 	struct drm_i915_private *dev_priv = to_i915(display->drm);
426 	struct intel_crtc *crtc;
427 
428 	spin_lock_irq(&dev_priv->irq_lock);
429 
430 	for_each_intel_crtc(display->drm, crtc) {
431 		if (crtc->cpu_fifo_underrun_disabled)
432 			continue;
433 
434 		if (HAS_GMCH(display))
435 			i9xx_check_fifo_underruns(crtc);
436 		else if (DISPLAY_VER(display) == 7)
437 			ivb_check_fifo_underruns(crtc);
438 	}
439 
440 	spin_unlock_irq(&dev_priv->irq_lock);
441 }
442 
443 /**
444  * intel_check_pch_fifo_underruns - check for PCH fifo underruns immediately
445  * @display: display device instance
446  *
447  * Check for PCH fifo underruns immediately. Useful on CPT/PPT where the shared
448  * error interrupt may have been disabled, and so PCH fifo underruns won't
449  * necessarily raise an interrupt.
450  */
451 void intel_check_pch_fifo_underruns(struct intel_display *display)
452 {
453 	struct drm_i915_private *dev_priv = to_i915(display->drm);
454 	struct intel_crtc *crtc;
455 
456 	spin_lock_irq(&dev_priv->irq_lock);
457 
458 	for_each_intel_crtc(display->drm, crtc) {
459 		if (crtc->pch_fifo_underrun_disabled)
460 			continue;
461 
462 		if (HAS_PCH_CPT(dev_priv))
463 			cpt_check_pch_fifo_underruns(crtc);
464 	}
465 
466 	spin_unlock_irq(&dev_priv->irq_lock);
467 }
468 
469 void intel_init_fifo_underrun_reporting(struct intel_display *display,
470 					struct intel_crtc *crtc,
471 					bool enable)
472 {
473 	crtc->cpu_fifo_underrun_disabled = !enable;
474 
475 	/*
476 	 * We track the PCH trancoder underrun reporting state
477 	 * within the crtc. With crtc for pipe A housing the underrun
478 	 * reporting state for PCH transcoder A, crtc for pipe B housing
479 	 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
480 	 * and marking underrun reporting as disabled for the non-existing
481 	 * PCH transcoders B and C would prevent enabling the south
482 	 * error interrupt (see cpt_can_enable_serr_int()).
483 	 */
484 	if (intel_has_pch_trancoder(display, crtc->pipe))
485 		crtc->pch_fifo_underrun_disabled = !enable;
486 }
487