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