xref: /openbmc/linux/drivers/gpu/drm/i915/display/intel_fifo_underrun.c (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
1df0566a6SJani Nikula /*
2df0566a6SJani Nikula  * Copyright © 2014 Intel Corporation
3df0566a6SJani Nikula  *
4df0566a6SJani Nikula  * Permission is hereby granted, free of charge, to any person obtaining a
5df0566a6SJani Nikula  * copy of this software and associated documentation files (the "Software"),
6df0566a6SJani Nikula  * to deal in the Software without restriction, including without limitation
7df0566a6SJani Nikula  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8df0566a6SJani Nikula  * and/or sell copies of the Software, and to permit persons to whom the
9df0566a6SJani Nikula  * Software is furnished to do so, subject to the following conditions:
10df0566a6SJani Nikula  *
11df0566a6SJani Nikula  * The above copyright notice and this permission notice (including the next
12df0566a6SJani Nikula  * paragraph) shall be included in all copies or substantial portions of the
13df0566a6SJani Nikula  * Software.
14df0566a6SJani Nikula  *
15df0566a6SJani Nikula  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16df0566a6SJani Nikula  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17df0566a6SJani Nikula  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18df0566a6SJani Nikula  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19df0566a6SJani Nikula  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20df0566a6SJani Nikula  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21df0566a6SJani Nikula  * IN THE SOFTWARE.
22df0566a6SJani Nikula  *
23df0566a6SJani Nikula  * Authors:
24df0566a6SJani Nikula  *    Daniel Vetter <daniel.vetter@ffwll.ch>
25df0566a6SJani Nikula  *
26df0566a6SJani Nikula  */
27df0566a6SJani Nikula 
28df0566a6SJani Nikula #include "i915_drv.h"
297785ae0bSVille Syrjälä #include "i915_reg.h"
30fd2b94a5SJani Nikula #include "intel_de.h"
311d455f8dSJani Nikula #include "intel_display_irq.h"
32df0566a6SJani Nikula #include "intel_display_trace.h"
33df0566a6SJani Nikula #include "intel_display_types.h"
34*66560f33SVille Syrjälä #include "intel_fbc.h"
35df0566a6SJani Nikula #include "intel_fifo_underrun.h"
36df0566a6SJani Nikula #include "intel_pch_display.h"
37df0566a6SJani Nikula 
38df0566a6SJani Nikula /**
39df0566a6SJani Nikula  * DOC: fifo underrun handling
40df0566a6SJani Nikula  *
41df0566a6SJani Nikula  * The i915 driver checks for display fifo underruns using the interrupt signals
42df0566a6SJani Nikula  * provided by the hardware. This is enabled by default and fairly useful to
43df0566a6SJani Nikula  * debug display issues, especially watermark settings.
44df0566a6SJani Nikula  *
45df0566a6SJani Nikula  * If an underrun is detected this is logged into dmesg. To avoid flooding logs
46df0566a6SJani Nikula  * and occupying the cpu underrun interrupts are disabled after the first
47df0566a6SJani Nikula  * occurrence until the next modeset on a given pipe.
48df0566a6SJani Nikula  *
49df0566a6SJani Nikula  * Note that underrun detection on gmch platforms is a bit more ugly since there
50df0566a6SJani Nikula  * is no interrupt (despite that the signalling bit is in the PIPESTAT pipe
51df0566a6SJani Nikula  * interrupt register). Also on some other platforms underrun interrupts are
52df0566a6SJani Nikula  * shared, which means that if we detect an underrun we need to disable underrun
53df0566a6SJani Nikula  * reporting on all pipes.
54df0566a6SJani Nikula  *
55df0566a6SJani Nikula  * The code also supports underrun detection on the PCH transcoder.
56df0566a6SJani Nikula  */
57df0566a6SJani Nikula 
ivb_can_enable_err_int(struct drm_device * dev)58df0566a6SJani Nikula static bool ivb_can_enable_err_int(struct drm_device *dev)
59df0566a6SJani Nikula {
60df0566a6SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
61df0566a6SJani Nikula 	struct intel_crtc *crtc;
62df0566a6SJani Nikula 	enum pipe pipe;
63df0566a6SJani Nikula 
64df0566a6SJani Nikula 	lockdep_assert_held(&dev_priv->irq_lock);
657794b6deSJani Nikula 
66df0566a6SJani Nikula 	for_each_pipe(dev_priv, pipe) {
67df0566a6SJani Nikula 		crtc = intel_crtc_for_pipe(dev_priv, pipe);
68df0566a6SJani Nikula 
69df0566a6SJani Nikula 		if (crtc->cpu_fifo_underrun_disabled)
70df0566a6SJani Nikula 			return false;
71df0566a6SJani Nikula 	}
72df0566a6SJani Nikula 
73df0566a6SJani Nikula 	return true;
74df0566a6SJani Nikula }
75df0566a6SJani Nikula 
cpt_can_enable_serr_int(struct drm_device * dev)76df0566a6SJani Nikula static bool cpt_can_enable_serr_int(struct drm_device *dev)
77df0566a6SJani Nikula {
78df0566a6SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
79df0566a6SJani Nikula 	enum pipe pipe;
80df0566a6SJani Nikula 	struct intel_crtc *crtc;
81df0566a6SJani Nikula 
82df0566a6SJani Nikula 	lockdep_assert_held(&dev_priv->irq_lock);
837794b6deSJani Nikula 
84df0566a6SJani Nikula 	for_each_pipe(dev_priv, pipe) {
85df0566a6SJani Nikula 		crtc = intel_crtc_for_pipe(dev_priv, pipe);
86df0566a6SJani Nikula 
87df0566a6SJani Nikula 		if (crtc->pch_fifo_underrun_disabled)
88df0566a6SJani Nikula 			return false;
89df0566a6SJani Nikula 	}
90df0566a6SJani Nikula 
91df0566a6SJani Nikula 	return true;
92df0566a6SJani Nikula }
93df0566a6SJani Nikula 
i9xx_check_fifo_underruns(struct intel_crtc * crtc)94df0566a6SJani Nikula static void i9xx_check_fifo_underruns(struct intel_crtc *crtc)
95df0566a6SJani Nikula {
96df0566a6SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
97df0566a6SJani Nikula 	i915_reg_t reg = PIPESTAT(crtc->pipe);
98df0566a6SJani Nikula 	u32 enable_mask;
99df0566a6SJani Nikula 
100f639c497SJani Nikula 	lockdep_assert_held(&dev_priv->irq_lock);
101df0566a6SJani Nikula 
102df0566a6SJani Nikula 	if ((intel_de_read(dev_priv, reg) & PIPE_FIFO_UNDERRUN_STATUS) == 0)
103df0566a6SJani Nikula 		return;
104f639c497SJani Nikula 
105f639c497SJani Nikula 	enable_mask = i915_pipestat_enable_mask(dev_priv, crtc->pipe);
106df0566a6SJani Nikula 	intel_de_write(dev_priv, reg, enable_mask | PIPE_FIFO_UNDERRUN_STATUS);
107df0566a6SJani Nikula 	intel_de_posting_read(dev_priv, reg);
1085cc40a90SWambui Karuga 
109df0566a6SJani Nikula 	trace_intel_cpu_fifo_underrun(dev_priv, crtc->pipe);
110df0566a6SJani Nikula 	drm_err(&dev_priv->drm, "pipe %c underrun\n", pipe_name(crtc->pipe));
111df0566a6SJani Nikula }
112df0566a6SJani Nikula 
i9xx_set_fifo_underrun_reporting(struct drm_device * dev,enum pipe pipe,bool enable,bool old)113df0566a6SJani Nikula static void i9xx_set_fifo_underrun_reporting(struct drm_device *dev,
114df0566a6SJani Nikula 					     enum pipe pipe,
115df0566a6SJani Nikula 					     bool enable, bool old)
116df0566a6SJani Nikula {
117df0566a6SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
118df0566a6SJani Nikula 	i915_reg_t reg = PIPESTAT(pipe);
119df0566a6SJani Nikula 
120df0566a6SJani Nikula 	lockdep_assert_held(&dev_priv->irq_lock);
121df0566a6SJani Nikula 
122df0566a6SJani Nikula 	if (enable) {
123f639c497SJani Nikula 		u32 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
124f639c497SJani Nikula 
125f639c497SJani Nikula 		intel_de_write(dev_priv, reg,
126df0566a6SJani Nikula 			       enable_mask | PIPE_FIFO_UNDERRUN_STATUS);
127f639c497SJani Nikula 		intel_de_posting_read(dev_priv, reg);
1285cc40a90SWambui Karuga 	} else {
1295cc40a90SWambui Karuga 		if (old && intel_de_read(dev_priv, reg) & PIPE_FIFO_UNDERRUN_STATUS)
130df0566a6SJani Nikula 			drm_err(&dev_priv->drm, "pipe %c underrun\n",
131df0566a6SJani Nikula 				pipe_name(pipe));
132df0566a6SJani Nikula 	}
1339eae5e27SLucas De Marchi }
134df0566a6SJani Nikula 
ilk_set_fifo_underrun_reporting(struct drm_device * dev,enum pipe pipe,bool enable)135df0566a6SJani Nikula static void ilk_set_fifo_underrun_reporting(struct drm_device *dev,
136df0566a6SJani Nikula 					    enum pipe pipe, bool enable)
137df0566a6SJani Nikula {
138df0566a6SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
139df0566a6SJani Nikula 	u32 bit = (pipe == PIPE_A) ?
140df0566a6SJani Nikula 		DE_PIPEA_FIFO_UNDERRUN : DE_PIPEB_FIFO_UNDERRUN;
141df0566a6SJani Nikula 
142df0566a6SJani Nikula 	if (enable)
143df0566a6SJani Nikula 		ilk_enable_display_irq(dev_priv, bit);
144df0566a6SJani Nikula 	else
145df0566a6SJani Nikula 		ilk_disable_display_irq(dev_priv, bit);
14674bb98baSLucas De Marchi }
147df0566a6SJani Nikula 
ivb_check_fifo_underruns(struct intel_crtc * crtc)148df0566a6SJani Nikula static void ivb_check_fifo_underruns(struct intel_crtc *crtc)
149df0566a6SJani Nikula {
150f639c497SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
151df0566a6SJani Nikula 	enum pipe pipe = crtc->pipe;
152df0566a6SJani Nikula 	u32 err_int = intel_de_read(dev_priv, GEN7_ERR_INT);
153df0566a6SJani Nikula 
154df0566a6SJani Nikula 	lockdep_assert_held(&dev_priv->irq_lock);
155df0566a6SJani Nikula 
156df0566a6SJani Nikula 	if ((err_int & ERR_INT_FIFO_UNDERRUN(pipe)) == 0)
157f639c497SJani Nikula 		return;
158f639c497SJani Nikula 
159df0566a6SJani Nikula 	intel_de_write(dev_priv, GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
160df0566a6SJani Nikula 	intel_de_posting_read(dev_priv, GEN7_ERR_INT);
1615cc40a90SWambui Karuga 
162df0566a6SJani Nikula 	trace_intel_cpu_fifo_underrun(dev_priv, pipe);
163df0566a6SJani Nikula 	drm_err(&dev_priv->drm, "fifo underrun on pipe %c\n", pipe_name(pipe));
16474bb98baSLucas De Marchi }
16574bb98baSLucas De Marchi 
ivb_set_fifo_underrun_reporting(struct drm_device * dev,enum pipe pipe,bool enable,bool old)16674bb98baSLucas De Marchi static void ivb_set_fifo_underrun_reporting(struct drm_device *dev,
167df0566a6SJani Nikula 					    enum pipe pipe, bool enable,
168df0566a6SJani Nikula 					    bool old)
169df0566a6SJani Nikula {
170f639c497SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
171f639c497SJani Nikula 	if (enable) {
172df0566a6SJani Nikula 		intel_de_write(dev_priv, GEN7_ERR_INT,
173df0566a6SJani Nikula 			       ERR_INT_FIFO_UNDERRUN(pipe));
174df0566a6SJani Nikula 
175df0566a6SJani Nikula 		if (!ivb_can_enable_err_int(dev))
176df0566a6SJani Nikula 			return;
177df0566a6SJani Nikula 
178df0566a6SJani Nikula 		ilk_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
179df0566a6SJani Nikula 	} else {
180df0566a6SJani Nikula 		ilk_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
181f639c497SJani Nikula 
1825cc40a90SWambui Karuga 		if (old &&
1835cc40a90SWambui Karuga 		    intel_de_read(dev_priv, GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe)) {
184df0566a6SJani Nikula 			drm_err(&dev_priv->drm,
185df0566a6SJani Nikula 				"uncleared fifo underrun on pipe %c\n",
186df0566a6SJani Nikula 				pipe_name(pipe));
187df0566a6SJani Nikula 		}
188df0566a6SJani Nikula 	}
1898bcc0840SMatt Roper }
1908bcc0840SMatt Roper 
1918bcc0840SMatt Roper static u32
icl_pipe_status_underrun_mask(struct drm_i915_private * dev_priv)1928bcc0840SMatt Roper icl_pipe_status_underrun_mask(struct drm_i915_private *dev_priv)
1938bcc0840SMatt Roper {
1948bcc0840SMatt Roper 	u32 mask = PIPE_STATUS_UNDERRUN;
1958bcc0840SMatt Roper 
1968bcc0840SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 13)
1978bcc0840SMatt Roper 		mask |= PIPE_STATUS_SOFT_UNDERRUN_XELPD |
1988bcc0840SMatt Roper 			PIPE_STATUS_HARD_UNDERRUN_XELPD |
1998bcc0840SMatt Roper 			PIPE_STATUS_PORT_UNDERRUN_XELPD;
2008bcc0840SMatt Roper 
2018bcc0840SMatt Roper 	return mask;
20272588ffdSLucas De Marchi }
203df0566a6SJani Nikula 
bdw_set_fifo_underrun_reporting(struct drm_device * dev,enum pipe pipe,bool enable)204df0566a6SJani Nikula static void bdw_set_fifo_underrun_reporting(struct drm_device *dev,
205df0566a6SJani Nikula 					    enum pipe pipe, bool enable)
2068bcc0840SMatt Roper {
207df0566a6SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
2088bcc0840SMatt Roper 	u32 mask = gen8_de_pipe_underrun_mask(dev_priv);
2098bcc0840SMatt Roper 
2108bcc0840SMatt Roper 	if (enable) {
2118bcc0840SMatt Roper 		if (DISPLAY_VER(dev_priv) >= 11)
2128bcc0840SMatt Roper 			intel_de_write(dev_priv, ICL_PIPESTATUS(pipe),
2138bcc0840SMatt Roper 				       icl_pipe_status_underrun_mask(dev_priv));
2148bcc0840SMatt Roper 
2158bcc0840SMatt Roper 		bdw_enable_pipe_irq(dev_priv, pipe, mask);
2168bcc0840SMatt Roper 	} else {
217df0566a6SJani Nikula 		bdw_disable_pipe_irq(dev_priv, pipe, mask);
218df0566a6SJani Nikula 	}
219df0566a6SJani Nikula }
220df0566a6SJani Nikula 
ibx_set_fifo_underrun_reporting(struct drm_device * dev,enum pipe pch_transcoder,bool enable)221df0566a6SJani Nikula static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
222df0566a6SJani Nikula 					    enum pipe pch_transcoder,
223df0566a6SJani Nikula 					    bool enable)
224df0566a6SJani Nikula {
225df0566a6SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
226df0566a6SJani Nikula 	u32 bit = (pch_transcoder == PIPE_A) ?
227df0566a6SJani Nikula 		SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
228df0566a6SJani Nikula 
229df0566a6SJani Nikula 	if (enable)
230df0566a6SJani Nikula 		ibx_enable_display_interrupt(dev_priv, bit);
231df0566a6SJani Nikula 	else
232df0566a6SJani Nikula 		ibx_disable_display_interrupt(dev_priv, bit);
233df0566a6SJani Nikula }
234df0566a6SJani Nikula 
cpt_check_pch_fifo_underruns(struct intel_crtc * crtc)235df0566a6SJani Nikula static void cpt_check_pch_fifo_underruns(struct intel_crtc *crtc)
236df0566a6SJani Nikula {
237f639c497SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
238df0566a6SJani Nikula 	enum pipe pch_transcoder = crtc->pipe;
239df0566a6SJani Nikula 	u32 serr_int = intel_de_read(dev_priv, SERR_INT);
240df0566a6SJani Nikula 
241df0566a6SJani Nikula 	lockdep_assert_held(&dev_priv->irq_lock);
242df0566a6SJani Nikula 
243df0566a6SJani Nikula 	if ((serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) == 0)
244f639c497SJani Nikula 		return;
245f639c497SJani Nikula 
246f639c497SJani Nikula 	intel_de_write(dev_priv, SERR_INT,
247df0566a6SJani Nikula 		       SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
248df0566a6SJani Nikula 	intel_de_posting_read(dev_priv, SERR_INT);
2495cc40a90SWambui Karuga 
250df0566a6SJani Nikula 	trace_intel_pch_fifo_underrun(dev_priv, pch_transcoder);
251df0566a6SJani Nikula 	drm_err(&dev_priv->drm, "pch fifo underrun on pch transcoder %c\n",
252df0566a6SJani Nikula 		pipe_name(pch_transcoder));
253df0566a6SJani Nikula }
254df0566a6SJani Nikula 
cpt_set_fifo_underrun_reporting(struct drm_device * dev,enum pipe pch_transcoder,bool enable,bool old)255df0566a6SJani Nikula static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
256df0566a6SJani Nikula 					    enum pipe pch_transcoder,
257df0566a6SJani Nikula 					    bool enable, bool old)
258df0566a6SJani Nikula {
259df0566a6SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
260f639c497SJani Nikula 
261df0566a6SJani Nikula 	if (enable) {
262df0566a6SJani Nikula 		intel_de_write(dev_priv, SERR_INT,
263df0566a6SJani Nikula 			       SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
264df0566a6SJani Nikula 
265df0566a6SJani Nikula 		if (!cpt_can_enable_serr_int(dev))
266df0566a6SJani Nikula 			return;
267df0566a6SJani Nikula 
268df0566a6SJani Nikula 		ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
269df0566a6SJani Nikula 	} else {
270f639c497SJani Nikula 		ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
271df0566a6SJani Nikula 
2725cc40a90SWambui Karuga 		if (old && intel_de_read(dev_priv, SERR_INT) &
2735cc40a90SWambui Karuga 		    SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) {
274df0566a6SJani Nikula 			drm_err(&dev_priv->drm,
275df0566a6SJani Nikula 				"uncleared pch fifo underrun on pch transcoder %c\n",
276df0566a6SJani Nikula 				pipe_name(pch_transcoder));
277df0566a6SJani Nikula 		}
278df0566a6SJani Nikula 	}
279df0566a6SJani Nikula }
280df0566a6SJani Nikula 
__intel_set_cpu_fifo_underrun_reporting(struct drm_device * dev,enum pipe pipe,bool enable)281df0566a6SJani Nikula static bool __intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
282df0566a6SJani Nikula 						    enum pipe pipe, bool enable)
2837794b6deSJani Nikula {
284df0566a6SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
285df0566a6SJani Nikula 	struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
286df0566a6SJani Nikula 	bool old;
287df0566a6SJani Nikula 
288df0566a6SJani Nikula 	lockdep_assert_held(&dev_priv->irq_lock);
289df0566a6SJani Nikula 
290df0566a6SJani Nikula 	old = !crtc->cpu_fifo_underrun_disabled;
291df0566a6SJani Nikula 	crtc->cpu_fifo_underrun_disabled = !enable;
292df0566a6SJani Nikula 
293d47d29a6SMatt Roper 	if (HAS_GMCH(dev_priv))
2949eae5e27SLucas De Marchi 		i9xx_set_fifo_underrun_reporting(dev, pipe, enable, old);
29593e7e61eSLucas De Marchi 	else if (IS_IRONLAKE(dev_priv) || IS_SANDYBRIDGE(dev_priv))
29674bb98baSLucas De Marchi 		ilk_set_fifo_underrun_reporting(dev, pipe, enable);
297005e9537SMatt Roper 	else if (DISPLAY_VER(dev_priv) == 7)
29872588ffdSLucas De Marchi 		ivb_set_fifo_underrun_reporting(dev, pipe, enable, old);
299df0566a6SJani Nikula 	else if (DISPLAY_VER(dev_priv) >= 8)
300df0566a6SJani Nikula 		bdw_set_fifo_underrun_reporting(dev, pipe, enable);
301df0566a6SJani Nikula 
302df0566a6SJani Nikula 	return old;
303df0566a6SJani Nikula }
304df0566a6SJani Nikula 
305df0566a6SJani Nikula /**
306df0566a6SJani Nikula  * intel_set_cpu_fifo_underrun_reporting - set cpu fifo underrrun reporting state
307df0566a6SJani Nikula  * @dev_priv: i915 device instance
308df0566a6SJani Nikula  * @pipe: (CPU) pipe to set state for
309df0566a6SJani Nikula  * @enable: whether underruns should be reported or not
310df0566a6SJani Nikula  *
311df0566a6SJani Nikula  * This function sets the fifo underrun state for @pipe. It is used in the
312df0566a6SJani Nikula  * modeset code to avoid false positives since on many platforms underruns are
313df0566a6SJani Nikula  * expected when disabling or enabling the pipe.
314df0566a6SJani Nikula  *
315df0566a6SJani Nikula  * Notice that on some platforms disabling underrun reports for one pipe
316df0566a6SJani Nikula  * disables for all due to shared interrupts. Actual reporting is still per-pipe
317df0566a6SJani Nikula  * though.
318df0566a6SJani Nikula  *
319df0566a6SJani Nikula  * Returns the previous state of underrun reporting.
320df0566a6SJani Nikula  */
intel_set_cpu_fifo_underrun_reporting(struct drm_i915_private * dev_priv,enum pipe pipe,bool enable)321df0566a6SJani Nikula bool intel_set_cpu_fifo_underrun_reporting(struct drm_i915_private *dev_priv,
322df0566a6SJani Nikula 					   enum pipe pipe, bool enable)
323df0566a6SJani Nikula {
324df0566a6SJani Nikula 	unsigned long flags;
325df0566a6SJani Nikula 	bool ret;
326df0566a6SJani Nikula 
327df0566a6SJani Nikula 	spin_lock_irqsave(&dev_priv->irq_lock, flags);
328df0566a6SJani Nikula 	ret = __intel_set_cpu_fifo_underrun_reporting(&dev_priv->drm, pipe,
329df0566a6SJani Nikula 						      enable);
330df0566a6SJani Nikula 	spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
331df0566a6SJani Nikula 
332df0566a6SJani Nikula 	return ret;
333df0566a6SJani Nikula }
334df0566a6SJani Nikula 
335df0566a6SJani Nikula /**
336df0566a6SJani Nikula  * intel_set_pch_fifo_underrun_reporting - set PCH fifo underrun reporting state
337df0566a6SJani Nikula  * @dev_priv: i915 device instance
338df0566a6SJani Nikula  * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
339df0566a6SJani Nikula  * @enable: whether underruns should be reported or not
340df0566a6SJani Nikula  *
341df0566a6SJani Nikula  * This function makes us disable or enable PCH fifo underruns for a specific
342df0566a6SJani Nikula  * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
343df0566a6SJani Nikula  * underrun reporting for one transcoder may also disable all the other PCH
344df0566a6SJani Nikula  * error interruts for the other transcoders, due to the fact that there's just
345df0566a6SJani Nikula  * one interrupt mask/enable bit for all the transcoders.
346df0566a6SJani Nikula  *
347df0566a6SJani Nikula  * Returns the previous state of underrun reporting.
348df0566a6SJani Nikula  */
intel_set_pch_fifo_underrun_reporting(struct drm_i915_private * dev_priv,enum pipe pch_transcoder,bool enable)349df0566a6SJani Nikula bool intel_set_pch_fifo_underrun_reporting(struct drm_i915_private *dev_priv,
350df0566a6SJani Nikula 					   enum pipe pch_transcoder,
351df0566a6SJani Nikula 					   bool enable)
3527794b6deSJani Nikula {
353df0566a6SJani Nikula 	struct intel_crtc *crtc =
354df0566a6SJani Nikula 		intel_crtc_for_pipe(dev_priv, pch_transcoder);
355df0566a6SJani Nikula 	unsigned long flags;
356df0566a6SJani Nikula 	bool old;
357df0566a6SJani Nikula 
358df0566a6SJani Nikula 	/*
359df0566a6SJani Nikula 	 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
360df0566a6SJani Nikula 	 * has only one pch transcoder A that all pipes can use. To avoid racy
361df0566a6SJani Nikula 	 * pch transcoder -> pipe lookups from interrupt code simply store the
362df0566a6SJani Nikula 	 * underrun statistics in crtc A. Since we never expose this anywhere
363df0566a6SJani Nikula 	 * nor use it outside of the fifo underrun code here using the "wrong"
364df0566a6SJani Nikula 	 * crtc on LPT won't cause issues.
365df0566a6SJani Nikula 	 */
366df0566a6SJani Nikula 
367df0566a6SJani Nikula 	spin_lock_irqsave(&dev_priv->irq_lock, flags);
368df0566a6SJani Nikula 
369df0566a6SJani Nikula 	old = !crtc->pch_fifo_underrun_disabled;
370df0566a6SJani Nikula 	crtc->pch_fifo_underrun_disabled = !enable;
371df0566a6SJani Nikula 
372df0566a6SJani Nikula 	if (HAS_PCH_IBX(dev_priv))
373df0566a6SJani Nikula 		ibx_set_fifo_underrun_reporting(&dev_priv->drm,
374df0566a6SJani Nikula 						pch_transcoder,
375df0566a6SJani Nikula 						enable);
376df0566a6SJani Nikula 	else
377df0566a6SJani Nikula 		cpt_set_fifo_underrun_reporting(&dev_priv->drm,
378df0566a6SJani Nikula 						pch_transcoder,
379df0566a6SJani Nikula 						enable, old);
380df0566a6SJani Nikula 
381df0566a6SJani Nikula 	spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
382df0566a6SJani Nikula 	return old;
383df0566a6SJani Nikula }
384df0566a6SJani Nikula 
385df0566a6SJani Nikula /**
386df0566a6SJani Nikula  * intel_cpu_fifo_underrun_irq_handler - handle CPU fifo underrun interrupt
387df0566a6SJani Nikula  * @dev_priv: i915 device instance
388df0566a6SJani Nikula  * @pipe: (CPU) pipe to set state for
389df0566a6SJani Nikula  *
390df0566a6SJani Nikula  * This handles a CPU fifo underrun interrupt, generating an underrun warning
391df0566a6SJani Nikula  * into dmesg if underrun reporting is enabled and then disables the underrun
392df0566a6SJani Nikula  * interrupt to avoid an irq storm.
393df0566a6SJani Nikula  */
intel_cpu_fifo_underrun_irq_handler(struct drm_i915_private * dev_priv,enum pipe pipe)394df0566a6SJani Nikula void intel_cpu_fifo_underrun_irq_handler(struct drm_i915_private *dev_priv,
3957794b6deSJani Nikula 					 enum pipe pipe)
3968bcc0840SMatt Roper {
397df0566a6SJani Nikula 	struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
398df0566a6SJani Nikula 	u32 underruns = 0;
399df0566a6SJani Nikula 
400df0566a6SJani Nikula 	/* We may be called too early in init, thanks BIOS! */
401df0566a6SJani Nikula 	if (crtc == NULL)
402df0566a6SJani Nikula 		return;
403df0566a6SJani Nikula 
404df0566a6SJani Nikula 	/* GMCH can't disable fifo underruns, filter them. */
405df0566a6SJani Nikula 	if (HAS_GMCH(dev_priv) &&
406df0566a6SJani Nikula 	    crtc->cpu_fifo_underrun_disabled)
4078bcc0840SMatt Roper 		return;
4088bcc0840SMatt Roper 
4098bcc0840SMatt Roper 	/*
4108bcc0840SMatt Roper 	 * Starting with display version 11, the PIPE_STAT register records
4118bcc0840SMatt Roper 	 * whether an underrun has happened, and on XELPD+, it will also record
4128bcc0840SMatt Roper 	 * whether the underrun was soft/hard and whether it was triggered by
4138bcc0840SMatt Roper 	 * the downstream port logic.  We should clear these bits (which use
4148bcc0840SMatt Roper 	 * write-1-to-clear logic) too.
4158bcc0840SMatt Roper 	 *
4168bcc0840SMatt Roper 	 * Note that although the IIR gives us the same underrun and soft/hard
4178bcc0840SMatt Roper 	 * information, PIPE_STAT is the only place we can find out whether
4188bcc0840SMatt Roper 	 * the underrun was caused by the downstream port.
4198bcc0840SMatt Roper 	 */
4208bcc0840SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 11) {
4218bcc0840SMatt Roper 		underruns = intel_de_read(dev_priv, ICL_PIPESTATUS(pipe)) &
4228bcc0840SMatt Roper 			icl_pipe_status_underrun_mask(dev_priv);
4238bcc0840SMatt Roper 		intel_de_write(dev_priv, ICL_PIPESTATUS(pipe), underruns);
424df0566a6SJani Nikula 	}
425df0566a6SJani Nikula 
4268bcc0840SMatt Roper 	if (intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false)) {
4278bcc0840SMatt Roper 		trace_intel_cpu_fifo_underrun(dev_priv, pipe);
4288bcc0840SMatt Roper 
4298bcc0840SMatt Roper 		if (DISPLAY_VER(dev_priv) >= 11)
4308bcc0840SMatt Roper 			drm_err(&dev_priv->drm, "CPU pipe %c FIFO underrun: %s%s%s%s\n",
4318bcc0840SMatt Roper 				pipe_name(pipe),
4328bcc0840SMatt Roper 				underruns & PIPE_STATUS_SOFT_UNDERRUN_XELPD ? "soft," : "",
4338bcc0840SMatt Roper 				underruns & PIPE_STATUS_HARD_UNDERRUN_XELPD ? "hard," : "",
4348bcc0840SMatt Roper 				underruns & PIPE_STATUS_PORT_UNDERRUN_XELPD ? "port," : "",
4358bcc0840SMatt Roper 				underruns & PIPE_STATUS_UNDERRUN ? "transcoder," : "");
436df0566a6SJani Nikula 		else
437df0566a6SJani Nikula 			drm_err(&dev_priv->drm, "CPU pipe %c FIFO underrun\n", pipe_name(pipe));
43832024bb8SVille Syrjälä 	}
439df0566a6SJani Nikula 
440df0566a6SJani Nikula 	intel_fbc_handle_fifo_underrun_irq(dev_priv);
441df0566a6SJani Nikula }
442df0566a6SJani Nikula 
443df0566a6SJani Nikula /**
444df0566a6SJani Nikula  * intel_pch_fifo_underrun_irq_handler - handle PCH fifo underrun interrupt
445df0566a6SJani Nikula  * @dev_priv: i915 device instance
446df0566a6SJani Nikula  * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
447df0566a6SJani Nikula  *
448df0566a6SJani Nikula  * This handles a PCH fifo underrun interrupt, generating an underrun warning
449df0566a6SJani Nikula  * into dmesg if underrun reporting is enabled and then disables the underrun
450df0566a6SJani Nikula  * interrupt to avoid an irq storm.
451df0566a6SJani Nikula  */
intel_pch_fifo_underrun_irq_handler(struct drm_i915_private * dev_priv,enum pipe pch_transcoder)452df0566a6SJani Nikula void intel_pch_fifo_underrun_irq_handler(struct drm_i915_private *dev_priv,
453df0566a6SJani Nikula 					 enum pipe pch_transcoder)
454df0566a6SJani Nikula {
455df0566a6SJani Nikula 	if (intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder,
4565cc40a90SWambui Karuga 						  false)) {
457df0566a6SJani Nikula 		trace_intel_pch_fifo_underrun(dev_priv, pch_transcoder);
458df0566a6SJani Nikula 		drm_err(&dev_priv->drm, "PCH transcoder %c FIFO underrun\n",
459df0566a6SJani Nikula 			pipe_name(pch_transcoder));
460df0566a6SJani Nikula 	}
461df0566a6SJani Nikula }
462df0566a6SJani Nikula 
463df0566a6SJani Nikula /**
464df0566a6SJani Nikula  * intel_check_cpu_fifo_underruns - check for CPU fifo underruns immediately
465df0566a6SJani Nikula  * @dev_priv: i915 device instance
466df0566a6SJani Nikula  *
467df0566a6SJani Nikula  * Check for CPU fifo underruns immediately. Useful on IVB/HSW where the shared
468df0566a6SJani Nikula  * error interrupt may have been disabled, and so CPU fifo underruns won't
469df0566a6SJani Nikula  * necessarily raise an interrupt, and on GMCH platforms where underruns never
470df0566a6SJani Nikula  * raise an interrupt.
471df0566a6SJani Nikula  */
intel_check_cpu_fifo_underruns(struct drm_i915_private * dev_priv)472df0566a6SJani Nikula void intel_check_cpu_fifo_underruns(struct drm_i915_private *dev_priv)
473df0566a6SJani Nikula {
474df0566a6SJani Nikula 	struct intel_crtc *crtc;
475df0566a6SJani Nikula 
476df0566a6SJani Nikula 	spin_lock_irq(&dev_priv->irq_lock);
477df0566a6SJani Nikula 
478df0566a6SJani Nikula 	for_each_intel_crtc(&dev_priv->drm, crtc) {
479df0566a6SJani Nikula 		if (crtc->cpu_fifo_underrun_disabled)
480df0566a6SJani Nikula 			continue;
481df0566a6SJani Nikula 
48293e7e61eSLucas De Marchi 		if (HAS_GMCH(dev_priv))
48374bb98baSLucas De Marchi 			i9xx_check_fifo_underruns(crtc);
484df0566a6SJani Nikula 		else if (DISPLAY_VER(dev_priv) == 7)
485df0566a6SJani Nikula 			ivb_check_fifo_underruns(crtc);
486df0566a6SJani Nikula 	}
487df0566a6SJani Nikula 
488df0566a6SJani Nikula 	spin_unlock_irq(&dev_priv->irq_lock);
489df0566a6SJani Nikula }
490df0566a6SJani Nikula 
491df0566a6SJani Nikula /**
492df0566a6SJani Nikula  * intel_check_pch_fifo_underruns - check for PCH fifo underruns immediately
493df0566a6SJani Nikula  * @dev_priv: i915 device instance
494df0566a6SJani Nikula  *
495df0566a6SJani Nikula  * Check for PCH fifo underruns immediately. Useful on CPT/PPT where the shared
496df0566a6SJani Nikula  * error interrupt may have been disabled, and so PCH fifo underruns won't
497df0566a6SJani Nikula  * necessarily raise an interrupt.
498df0566a6SJani Nikula  */
intel_check_pch_fifo_underruns(struct drm_i915_private * dev_priv)499df0566a6SJani Nikula void intel_check_pch_fifo_underruns(struct drm_i915_private *dev_priv)
500df0566a6SJani Nikula {
501df0566a6SJani Nikula 	struct intel_crtc *crtc;
502df0566a6SJani Nikula 
503df0566a6SJani Nikula 	spin_lock_irq(&dev_priv->irq_lock);
504df0566a6SJani Nikula 
505df0566a6SJani Nikula 	for_each_intel_crtc(&dev_priv->drm, crtc) {
506df0566a6SJani Nikula 		if (crtc->pch_fifo_underrun_disabled)
507df0566a6SJani Nikula 			continue;
508df0566a6SJani Nikula 
509df0566a6SJani Nikula 		if (HAS_PCH_CPT(dev_priv))
510df0566a6SJani Nikula 			cpt_check_pch_fifo_underruns(crtc);
511df0566a6SJani Nikula 	}
512df0566a6SJani Nikula 
513*66560f33SVille Syrjälä 	spin_unlock_irq(&dev_priv->irq_lock);
514*66560f33SVille Syrjälä }
515*66560f33SVille Syrjälä 
intel_init_fifo_underrun_reporting(struct drm_i915_private * i915,struct intel_crtc * crtc,bool enable)516*66560f33SVille Syrjälä void intel_init_fifo_underrun_reporting(struct drm_i915_private *i915,
517*66560f33SVille Syrjälä 					struct intel_crtc *crtc,
518*66560f33SVille Syrjälä 					bool enable)
519*66560f33SVille Syrjälä {
520*66560f33SVille Syrjälä 	crtc->cpu_fifo_underrun_disabled = !enable;
521*66560f33SVille Syrjälä 
522*66560f33SVille Syrjälä 	/*
523*66560f33SVille Syrjälä 	 * We track the PCH trancoder underrun reporting state
524*66560f33SVille Syrjälä 	 * within the crtc. With crtc for pipe A housing the underrun
525*66560f33SVille Syrjälä 	 * reporting state for PCH transcoder A, crtc for pipe B housing
526*66560f33SVille Syrjälä 	 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
527*66560f33SVille Syrjälä 	 * and marking underrun reporting as disabled for the non-existing
528*66560f33SVille Syrjälä 	 * PCH transcoders B and C would prevent enabling the south
529*66560f33SVille Syrjälä 	 * error interrupt (see cpt_can_enable_serr_int()).
530*66560f33SVille Syrjälä 	 */
531*66560f33SVille Syrjälä 	if (intel_has_pch_trancoder(i915, crtc->pipe))
532 		crtc->pch_fifo_underrun_disabled = !enable;
533 }
534