xref: /dflybsd-src/sys/dev/drm/i915/intel_fifo_underrun.c (revision 3f2dd94a569761201b5b0a18b2f697f97fe1b9dc)
12c9916cdSFrançois Tigeot /*
22c9916cdSFrançois Tigeot  * Copyright © 2014 Intel Corporation
32c9916cdSFrançois Tigeot  *
42c9916cdSFrançois Tigeot  * Permission is hereby granted, free of charge, to any person obtaining a
52c9916cdSFrançois Tigeot  * copy of this software and associated documentation files (the "Software"),
62c9916cdSFrançois Tigeot  * to deal in the Software without restriction, including without limitation
72c9916cdSFrançois Tigeot  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
82c9916cdSFrançois Tigeot  * and/or sell copies of the Software, and to permit persons to whom the
92c9916cdSFrançois Tigeot  * Software is furnished to do so, subject to the following conditions:
102c9916cdSFrançois Tigeot  *
112c9916cdSFrançois Tigeot  * The above copyright notice and this permission notice (including the next
122c9916cdSFrançois Tigeot  * paragraph) shall be included in all copies or substantial portions of the
132c9916cdSFrançois Tigeot  * Software.
142c9916cdSFrançois Tigeot  *
152c9916cdSFrançois Tigeot  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
162c9916cdSFrançois Tigeot  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
172c9916cdSFrançois Tigeot  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
182c9916cdSFrançois Tigeot  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
192c9916cdSFrançois Tigeot  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
202c9916cdSFrançois Tigeot  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
212c9916cdSFrançois Tigeot  * IN THE SOFTWARE.
222c9916cdSFrançois Tigeot  *
232c9916cdSFrançois Tigeot  * Authors:
242c9916cdSFrançois Tigeot  *    Daniel Vetter <daniel.vetter@ffwll.ch>
252c9916cdSFrançois Tigeot  *
262c9916cdSFrançois Tigeot  */
272c9916cdSFrançois Tigeot 
282c9916cdSFrançois Tigeot #include "i915_drv.h"
292c9916cdSFrançois Tigeot #include "intel_drv.h"
302c9916cdSFrançois Tigeot 
312c9916cdSFrançois Tigeot /**
322c9916cdSFrançois Tigeot  * DOC: fifo underrun handling
332c9916cdSFrançois Tigeot  *
342c9916cdSFrançois Tigeot  * The i915 driver checks for display fifo underruns using the interrupt signals
352c9916cdSFrançois Tigeot  * provided by the hardware. This is enabled by default and fairly useful to
362c9916cdSFrançois Tigeot  * debug display issues, especially watermark settings.
372c9916cdSFrançois Tigeot  *
382c9916cdSFrançois Tigeot  * If an underrun is detected this is logged into dmesg. To avoid flooding logs
392c9916cdSFrançois Tigeot  * and occupying the cpu underrun interrupts are disabled after the first
402c9916cdSFrançois Tigeot  * occurrence until the next modeset on a given pipe.
412c9916cdSFrançois Tigeot  *
422c9916cdSFrançois Tigeot  * Note that underrun detection on gmch platforms is a bit more ugly since there
432c9916cdSFrançois Tigeot  * is no interrupt (despite that the signalling bit is in the PIPESTAT pipe
442c9916cdSFrançois Tigeot  * interrupt register). Also on some other platforms underrun interrupts are
452c9916cdSFrançois Tigeot  * shared, which means that if we detect an underrun we need to disable underrun
462c9916cdSFrançois Tigeot  * reporting on all pipes.
472c9916cdSFrançois Tigeot  *
482c9916cdSFrançois Tigeot  * The code also supports underrun detection on the PCH transcoder.
492c9916cdSFrançois Tigeot  */
502c9916cdSFrançois Tigeot 
ivb_can_enable_err_int(struct drm_device * dev)512c9916cdSFrançois Tigeot static bool ivb_can_enable_err_int(struct drm_device *dev)
522c9916cdSFrançois Tigeot {
53bf017597SFrançois Tigeot 	struct drm_i915_private *dev_priv = to_i915(dev);
542c9916cdSFrançois Tigeot 	struct intel_crtc *crtc;
552c9916cdSFrançois Tigeot 	enum i915_pipe pipe;
562c9916cdSFrançois Tigeot 
57a85cb24fSFrançois Tigeot 	lockdep_assert_held(&dev_priv->irq_lock);
582c9916cdSFrançois Tigeot 
592c9916cdSFrançois Tigeot 	for_each_pipe(dev_priv, pipe) {
604be47400SFrançois Tigeot 		crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
612c9916cdSFrançois Tigeot 
622c9916cdSFrançois Tigeot 		if (crtc->cpu_fifo_underrun_disabled)
632c9916cdSFrançois Tigeot 			return false;
642c9916cdSFrançois Tigeot 	}
652c9916cdSFrançois Tigeot 
662c9916cdSFrançois Tigeot 	return true;
672c9916cdSFrançois Tigeot }
682c9916cdSFrançois Tigeot 
cpt_can_enable_serr_int(struct drm_device * dev)692c9916cdSFrançois Tigeot static bool cpt_can_enable_serr_int(struct drm_device *dev)
702c9916cdSFrançois Tigeot {
71bf017597SFrançois Tigeot 	struct drm_i915_private *dev_priv = to_i915(dev);
722c9916cdSFrançois Tigeot 	enum i915_pipe pipe;
732c9916cdSFrançois Tigeot 	struct intel_crtc *crtc;
742c9916cdSFrançois Tigeot 
75a85cb24fSFrançois Tigeot 	lockdep_assert_held(&dev_priv->irq_lock);
762c9916cdSFrançois Tigeot 
772c9916cdSFrançois Tigeot 	for_each_pipe(dev_priv, pipe) {
784be47400SFrançois Tigeot 		crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
792c9916cdSFrançois Tigeot 
802c9916cdSFrançois Tigeot 		if (crtc->pch_fifo_underrun_disabled)
812c9916cdSFrançois Tigeot 			return false;
822c9916cdSFrançois Tigeot 	}
832c9916cdSFrançois Tigeot 
842c9916cdSFrançois Tigeot 	return true;
852c9916cdSFrançois Tigeot }
862c9916cdSFrançois Tigeot 
i9xx_check_fifo_underruns(struct intel_crtc * crtc)87aee94f86SFrançois Tigeot static void i9xx_check_fifo_underruns(struct intel_crtc *crtc)
882c9916cdSFrançois Tigeot {
89aee94f86SFrançois Tigeot 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
90aee94f86SFrançois Tigeot 	i915_reg_t reg = PIPESTAT(crtc->pipe);
91*3f2dd94aSFrançois Tigeot 	u32 enable_mask;
922c9916cdSFrançois Tigeot 
93a85cb24fSFrançois Tigeot 	lockdep_assert_held(&dev_priv->irq_lock);
942c9916cdSFrançois Tigeot 
95*3f2dd94aSFrançois Tigeot 	if ((I915_READ(reg) & PIPE_FIFO_UNDERRUN_STATUS) == 0)
96aee94f86SFrançois Tigeot 		return;
972c9916cdSFrançois Tigeot 
98*3f2dd94aSFrançois Tigeot 	enable_mask = i915_pipestat_enable_mask(dev_priv, crtc->pipe);
99*3f2dd94aSFrançois Tigeot 	I915_WRITE(reg, enable_mask | PIPE_FIFO_UNDERRUN_STATUS);
1002c9916cdSFrançois Tigeot 	POSTING_READ(reg);
1012c9916cdSFrançois Tigeot 
102a85cb24fSFrançois Tigeot 	trace_intel_cpu_fifo_underrun(dev_priv, crtc->pipe);
1032c9916cdSFrançois Tigeot 	DRM_ERROR("pipe %c underrun\n", pipe_name(crtc->pipe));
1042c9916cdSFrançois Tigeot }
1052c9916cdSFrançois Tigeot 
i9xx_set_fifo_underrun_reporting(struct drm_device * dev,enum i915_pipe pipe,bool enable,bool old)1062c9916cdSFrançois Tigeot static void i9xx_set_fifo_underrun_reporting(struct drm_device *dev,
1072c9916cdSFrançois Tigeot 					     enum i915_pipe pipe,
1082c9916cdSFrançois Tigeot 					     bool enable, bool old)
1092c9916cdSFrançois Tigeot {
110bf017597SFrançois Tigeot 	struct drm_i915_private *dev_priv = to_i915(dev);
111aee94f86SFrançois Tigeot 	i915_reg_t reg = PIPESTAT(pipe);
1122c9916cdSFrançois Tigeot 
113a85cb24fSFrançois Tigeot 	lockdep_assert_held(&dev_priv->irq_lock);
1142c9916cdSFrançois Tigeot 
1152c9916cdSFrançois Tigeot 	if (enable) {
116*3f2dd94aSFrançois Tigeot 		u32 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
117*3f2dd94aSFrançois Tigeot 
118*3f2dd94aSFrançois Tigeot 		I915_WRITE(reg, enable_mask | PIPE_FIFO_UNDERRUN_STATUS);
1192c9916cdSFrançois Tigeot 		POSTING_READ(reg);
1202c9916cdSFrançois Tigeot 	} else {
121*3f2dd94aSFrançois Tigeot 		if (old && I915_READ(reg) & PIPE_FIFO_UNDERRUN_STATUS)
1222c9916cdSFrançois Tigeot 			DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
1232c9916cdSFrançois Tigeot 	}
1242c9916cdSFrançois Tigeot }
1252c9916cdSFrançois Tigeot 
ironlake_set_fifo_underrun_reporting(struct drm_device * dev,enum i915_pipe pipe,bool enable)1262c9916cdSFrançois Tigeot static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
1272c9916cdSFrançois Tigeot 						 enum i915_pipe pipe, bool enable)
1282c9916cdSFrançois Tigeot {
129bf017597SFrançois Tigeot 	struct drm_i915_private *dev_priv = to_i915(dev);
1302c9916cdSFrançois Tigeot 	uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
1312c9916cdSFrançois Tigeot 					  DE_PIPEB_FIFO_UNDERRUN;
1322c9916cdSFrançois Tigeot 
1332c9916cdSFrançois Tigeot 	if (enable)
134aee94f86SFrançois Tigeot 		ilk_enable_display_irq(dev_priv, bit);
1352c9916cdSFrançois Tigeot 	else
136aee94f86SFrançois Tigeot 		ilk_disable_display_irq(dev_priv, bit);
137aee94f86SFrançois Tigeot }
138aee94f86SFrançois Tigeot 
ivybridge_check_fifo_underruns(struct intel_crtc * crtc)139aee94f86SFrançois Tigeot static void ivybridge_check_fifo_underruns(struct intel_crtc *crtc)
140aee94f86SFrançois Tigeot {
141aee94f86SFrançois Tigeot 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
142aee94f86SFrançois Tigeot 	enum i915_pipe pipe = crtc->pipe;
143aee94f86SFrançois Tigeot 	uint32_t err_int = I915_READ(GEN7_ERR_INT);
144aee94f86SFrançois Tigeot 
145a85cb24fSFrançois Tigeot 	lockdep_assert_held(&dev_priv->irq_lock);
146aee94f86SFrançois Tigeot 
147aee94f86SFrançois Tigeot 	if ((err_int & ERR_INT_FIFO_UNDERRUN(pipe)) == 0)
148aee94f86SFrançois Tigeot 		return;
149aee94f86SFrançois Tigeot 
150aee94f86SFrançois Tigeot 	I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
151aee94f86SFrançois Tigeot 	POSTING_READ(GEN7_ERR_INT);
152aee94f86SFrançois Tigeot 
153a85cb24fSFrançois Tigeot 	trace_intel_cpu_fifo_underrun(dev_priv, pipe);
154aee94f86SFrançois Tigeot 	DRM_ERROR("fifo underrun on pipe %c\n", pipe_name(pipe));
1552c9916cdSFrançois Tigeot }
1562c9916cdSFrançois Tigeot 
ivybridge_set_fifo_underrun_reporting(struct drm_device * dev,enum i915_pipe pipe,bool enable,bool old)1572c9916cdSFrançois Tigeot static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
1582c9916cdSFrançois Tigeot 						  enum i915_pipe pipe,
1592c9916cdSFrançois Tigeot 						  bool enable, bool old)
1602c9916cdSFrançois Tigeot {
161bf017597SFrançois Tigeot 	struct drm_i915_private *dev_priv = to_i915(dev);
1622c9916cdSFrançois Tigeot 	if (enable) {
1632c9916cdSFrançois Tigeot 		I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
1642c9916cdSFrançois Tigeot 
1652c9916cdSFrançois Tigeot 		if (!ivb_can_enable_err_int(dev))
1662c9916cdSFrançois Tigeot 			return;
1672c9916cdSFrançois Tigeot 
168aee94f86SFrançois Tigeot 		ilk_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
1692c9916cdSFrançois Tigeot 	} else {
170aee94f86SFrançois Tigeot 		ilk_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
1712c9916cdSFrançois Tigeot 
1722c9916cdSFrançois Tigeot 		if (old &&
1732c9916cdSFrançois Tigeot 		    I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe)) {
1742c9916cdSFrançois Tigeot 			DRM_ERROR("uncleared fifo underrun on pipe %c\n",
1752c9916cdSFrançois Tigeot 				  pipe_name(pipe));
1762c9916cdSFrançois Tigeot 		}
1772c9916cdSFrançois Tigeot 	}
1782c9916cdSFrançois Tigeot }
1792c9916cdSFrançois Tigeot 
broadwell_set_fifo_underrun_reporting(struct drm_device * dev,enum i915_pipe pipe,bool enable)1802c9916cdSFrançois Tigeot static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev,
1812c9916cdSFrançois Tigeot 						  enum i915_pipe pipe, bool enable)
1822c9916cdSFrançois Tigeot {
183bf017597SFrançois Tigeot 	struct drm_i915_private *dev_priv = to_i915(dev);
1842c9916cdSFrançois Tigeot 
1852c9916cdSFrançois Tigeot 	if (enable)
186aee94f86SFrançois Tigeot 		bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_FIFO_UNDERRUN);
1872c9916cdSFrançois Tigeot 	else
188aee94f86SFrançois Tigeot 		bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_FIFO_UNDERRUN);
1892c9916cdSFrançois Tigeot }
1902c9916cdSFrançois Tigeot 
ibx_set_fifo_underrun_reporting(struct drm_device * dev,enum i915_pipe pch_transcoder,bool enable)1912c9916cdSFrançois Tigeot static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
192*3f2dd94aSFrançois Tigeot 					    enum i915_pipe pch_transcoder,
1932c9916cdSFrançois Tigeot 					    bool enable)
1942c9916cdSFrançois Tigeot {
195bf017597SFrançois Tigeot 	struct drm_i915_private *dev_priv = to_i915(dev);
196*3f2dd94aSFrançois Tigeot 	uint32_t bit = (pch_transcoder == PIPE_A) ?
1972c9916cdSFrançois Tigeot 		       SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
1982c9916cdSFrançois Tigeot 
1992c9916cdSFrançois Tigeot 	if (enable)
2002c9916cdSFrançois Tigeot 		ibx_enable_display_interrupt(dev_priv, bit);
2012c9916cdSFrançois Tigeot 	else
2022c9916cdSFrançois Tigeot 		ibx_disable_display_interrupt(dev_priv, bit);
2032c9916cdSFrançois Tigeot }
2042c9916cdSFrançois Tigeot 
cpt_check_pch_fifo_underruns(struct intel_crtc * crtc)205aee94f86SFrançois Tigeot static void cpt_check_pch_fifo_underruns(struct intel_crtc *crtc)
206aee94f86SFrançois Tigeot {
207aee94f86SFrançois Tigeot 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
208*3f2dd94aSFrançois Tigeot 	enum i915_pipe pch_transcoder = crtc->pipe;
209aee94f86SFrançois Tigeot 	uint32_t serr_int = I915_READ(SERR_INT);
210aee94f86SFrançois Tigeot 
211a85cb24fSFrançois Tigeot 	lockdep_assert_held(&dev_priv->irq_lock);
212aee94f86SFrançois Tigeot 
213aee94f86SFrançois Tigeot 	if ((serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) == 0)
214aee94f86SFrançois Tigeot 		return;
215aee94f86SFrançois Tigeot 
216aee94f86SFrançois Tigeot 	I915_WRITE(SERR_INT, SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
217aee94f86SFrançois Tigeot 	POSTING_READ(SERR_INT);
218aee94f86SFrançois Tigeot 
219a85cb24fSFrançois Tigeot 	trace_intel_pch_fifo_underrun(dev_priv, pch_transcoder);
220*3f2dd94aSFrançois Tigeot 	DRM_ERROR("pch fifo underrun on pch transcoder %c\n",
221*3f2dd94aSFrançois Tigeot 		  pipe_name(pch_transcoder));
222aee94f86SFrançois Tigeot }
223aee94f86SFrançois Tigeot 
cpt_set_fifo_underrun_reporting(struct drm_device * dev,enum i915_pipe pch_transcoder,bool enable,bool old)2242c9916cdSFrançois Tigeot static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
225*3f2dd94aSFrançois Tigeot 					    enum i915_pipe pch_transcoder,
2262c9916cdSFrançois Tigeot 					    bool enable, bool old)
2272c9916cdSFrançois Tigeot {
228bf017597SFrançois Tigeot 	struct drm_i915_private *dev_priv = to_i915(dev);
2292c9916cdSFrançois Tigeot 
2302c9916cdSFrançois Tigeot 	if (enable) {
2312c9916cdSFrançois Tigeot 		I915_WRITE(SERR_INT,
2322c9916cdSFrançois Tigeot 			   SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
2332c9916cdSFrançois Tigeot 
2342c9916cdSFrançois Tigeot 		if (!cpt_can_enable_serr_int(dev))
2352c9916cdSFrançois Tigeot 			return;
2362c9916cdSFrançois Tigeot 
2372c9916cdSFrançois Tigeot 		ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
2382c9916cdSFrançois Tigeot 	} else {
2392c9916cdSFrançois Tigeot 		ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
2402c9916cdSFrançois Tigeot 
2412c9916cdSFrançois Tigeot 		if (old && I915_READ(SERR_INT) &
2422c9916cdSFrançois Tigeot 		    SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) {
243*3f2dd94aSFrançois Tigeot 			DRM_ERROR("uncleared pch fifo underrun on pch transcoder %c\n",
244*3f2dd94aSFrançois Tigeot 				  pipe_name(pch_transcoder));
2452c9916cdSFrançois Tigeot 		}
2462c9916cdSFrançois Tigeot 	}
2472c9916cdSFrançois Tigeot }
2482c9916cdSFrançois Tigeot 
__intel_set_cpu_fifo_underrun_reporting(struct drm_device * dev,enum i915_pipe pipe,bool enable)2492c9916cdSFrançois Tigeot static bool __intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
2502c9916cdSFrançois Tigeot 						    enum i915_pipe pipe, bool enable)
2512c9916cdSFrançois Tigeot {
252bf017597SFrançois Tigeot 	struct drm_i915_private *dev_priv = to_i915(dev);
2534be47400SFrançois Tigeot 	struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
2542c9916cdSFrançois Tigeot 	bool old;
2552c9916cdSFrançois Tigeot 
256a85cb24fSFrançois Tigeot 	lockdep_assert_held(&dev_priv->irq_lock);
2572c9916cdSFrançois Tigeot 
2584be47400SFrançois Tigeot 	old = !crtc->cpu_fifo_underrun_disabled;
2594be47400SFrançois Tigeot 	crtc->cpu_fifo_underrun_disabled = !enable;
2602c9916cdSFrançois Tigeot 
2611e12ee3bSFrançois Tigeot 	if (HAS_GMCH_DISPLAY(dev_priv))
2622c9916cdSFrançois Tigeot 		i9xx_set_fifo_underrun_reporting(dev, pipe, enable, old);
2631e12ee3bSFrançois Tigeot 	else if (IS_GEN5(dev_priv) || IS_GEN6(dev_priv))
2642c9916cdSFrançois Tigeot 		ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
2651e12ee3bSFrançois Tigeot 	else if (IS_GEN7(dev_priv))
2662c9916cdSFrançois Tigeot 		ivybridge_set_fifo_underrun_reporting(dev, pipe, enable, old);
267*3f2dd94aSFrançois Tigeot 	else if (INTEL_GEN(dev_priv) >= 8)
2682c9916cdSFrançois Tigeot 		broadwell_set_fifo_underrun_reporting(dev, pipe, enable);
2692c9916cdSFrançois Tigeot 
2702c9916cdSFrançois Tigeot 	return old;
2712c9916cdSFrançois Tigeot }
2722c9916cdSFrançois Tigeot 
2732c9916cdSFrançois Tigeot /**
2742c9916cdSFrançois Tigeot  * intel_set_cpu_fifo_underrun_reporting - set cpu fifo underrrun reporting state
2752c9916cdSFrançois Tigeot  * @dev_priv: i915 device instance
2762c9916cdSFrançois Tigeot  * @pipe: (CPU) pipe to set state for
2772c9916cdSFrançois Tigeot  * @enable: whether underruns should be reported or not
2782c9916cdSFrançois Tigeot  *
2792c9916cdSFrançois Tigeot  * This function sets the fifo underrun state for @pipe. It is used in the
2802c9916cdSFrançois Tigeot  * modeset code to avoid false positives since on many platforms underruns are
2812c9916cdSFrançois Tigeot  * expected when disabling or enabling the pipe.
2822c9916cdSFrançois Tigeot  *
2832c9916cdSFrançois Tigeot  * Notice that on some platforms disabling underrun reports for one pipe
2842c9916cdSFrançois Tigeot  * disables for all due to shared interrupts. Actual reporting is still per-pipe
2852c9916cdSFrançois Tigeot  * though.
2862c9916cdSFrançois Tigeot  *
2872c9916cdSFrançois Tigeot  * Returns the previous state of underrun reporting.
2882c9916cdSFrançois Tigeot  */
intel_set_cpu_fifo_underrun_reporting(struct drm_i915_private * dev_priv,enum i915_pipe pipe,bool enable)2892c9916cdSFrançois Tigeot bool intel_set_cpu_fifo_underrun_reporting(struct drm_i915_private *dev_priv,
2902c9916cdSFrançois Tigeot 					   enum i915_pipe pipe, bool enable)
2912c9916cdSFrançois Tigeot {
2925e269720SFrançois Tigeot 	unsigned long flags;
2932c9916cdSFrançois Tigeot 	bool ret;
2942c9916cdSFrançois Tigeot 
2955e269720SFrançois Tigeot 	spin_lock_irqsave(&dev_priv->irq_lock, flags);
296303bf270SFrançois Tigeot 	ret = __intel_set_cpu_fifo_underrun_reporting(&dev_priv->drm, pipe,
2972c9916cdSFrançois Tigeot 						      enable);
2985e269720SFrançois Tigeot 	spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
2992c9916cdSFrançois Tigeot 
3002c9916cdSFrançois Tigeot 	return ret;
3012c9916cdSFrançois Tigeot }
3022c9916cdSFrançois Tigeot 
3032c9916cdSFrançois Tigeot /**
3042c9916cdSFrançois Tigeot  * intel_set_pch_fifo_underrun_reporting - set PCH fifo underrun reporting state
3052c9916cdSFrançois Tigeot  * @dev_priv: i915 device instance
3062c9916cdSFrançois Tigeot  * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
3072c9916cdSFrançois Tigeot  * @enable: whether underruns should be reported or not
3082c9916cdSFrançois Tigeot  *
3092c9916cdSFrançois Tigeot  * This function makes us disable or enable PCH fifo underruns for a specific
3102c9916cdSFrançois Tigeot  * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
3112c9916cdSFrançois Tigeot  * underrun reporting for one transcoder may also disable all the other PCH
3122c9916cdSFrançois Tigeot  * error interruts for the other transcoders, due to the fact that there's just
3132c9916cdSFrançois Tigeot  * one interrupt mask/enable bit for all the transcoders.
3142c9916cdSFrançois Tigeot  *
3152c9916cdSFrançois Tigeot  * Returns the previous state of underrun reporting.
3162c9916cdSFrançois Tigeot  */
intel_set_pch_fifo_underrun_reporting(struct drm_i915_private * dev_priv,enum i915_pipe pch_transcoder,bool enable)3172c9916cdSFrançois Tigeot bool intel_set_pch_fifo_underrun_reporting(struct drm_i915_private *dev_priv,
318*3f2dd94aSFrançois Tigeot 					   enum i915_pipe pch_transcoder,
3192c9916cdSFrançois Tigeot 					   bool enable)
3202c9916cdSFrançois Tigeot {
3214be47400SFrançois Tigeot 	struct intel_crtc *crtc =
322*3f2dd94aSFrançois Tigeot 		intel_get_crtc_for_pipe(dev_priv, pch_transcoder);
3235e269720SFrançois Tigeot 	unsigned long flags;
3242c9916cdSFrançois Tigeot 	bool old;
3252c9916cdSFrançois Tigeot 
3262c9916cdSFrançois Tigeot 	/*
3272c9916cdSFrançois Tigeot 	 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
3282c9916cdSFrançois Tigeot 	 * has only one pch transcoder A that all pipes can use. To avoid racy
3292c9916cdSFrançois Tigeot 	 * pch transcoder -> pipe lookups from interrupt code simply store the
3302c9916cdSFrançois Tigeot 	 * underrun statistics in crtc A. Since we never expose this anywhere
3312c9916cdSFrançois Tigeot 	 * nor use it outside of the fifo underrun code here using the "wrong"
3322c9916cdSFrançois Tigeot 	 * crtc on LPT won't cause issues.
3332c9916cdSFrançois Tigeot 	 */
3342c9916cdSFrançois Tigeot 
3355e269720SFrançois Tigeot 	spin_lock_irqsave(&dev_priv->irq_lock, flags);
3362c9916cdSFrançois Tigeot 
3374be47400SFrançois Tigeot 	old = !crtc->pch_fifo_underrun_disabled;
3384be47400SFrançois Tigeot 	crtc->pch_fifo_underrun_disabled = !enable;
3392c9916cdSFrançois Tigeot 
3408621f407SFrançois Tigeot 	if (HAS_PCH_IBX(dev_priv))
341303bf270SFrançois Tigeot 		ibx_set_fifo_underrun_reporting(&dev_priv->drm,
342303bf270SFrançois Tigeot 						pch_transcoder,
3432c9916cdSFrançois Tigeot 						enable);
3442c9916cdSFrançois Tigeot 	else
345303bf270SFrançois Tigeot 		cpt_set_fifo_underrun_reporting(&dev_priv->drm,
346303bf270SFrançois Tigeot 						pch_transcoder,
3472c9916cdSFrançois Tigeot 						enable, old);
3482c9916cdSFrançois Tigeot 
3495e269720SFrançois Tigeot 	spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
3502c9916cdSFrançois Tigeot 	return old;
3512c9916cdSFrançois Tigeot }
3522c9916cdSFrançois Tigeot 
3532c9916cdSFrançois Tigeot /**
3542c9916cdSFrançois Tigeot  * intel_cpu_fifo_underrun_irq_handler - handle CPU fifo underrun interrupt
3552c9916cdSFrançois Tigeot  * @dev_priv: i915 device instance
3562c9916cdSFrançois Tigeot  * @pipe: (CPU) pipe to set state for
3572c9916cdSFrançois Tigeot  *
3582c9916cdSFrançois Tigeot  * This handles a CPU fifo underrun interrupt, generating an underrun warning
3592c9916cdSFrançois Tigeot  * into dmesg if underrun reporting is enabled and then disables the underrun
3602c9916cdSFrançois Tigeot  * interrupt to avoid an irq storm.
3612c9916cdSFrançois Tigeot  */
intel_cpu_fifo_underrun_irq_handler(struct drm_i915_private * dev_priv,enum i915_pipe pipe)3622c9916cdSFrançois Tigeot void intel_cpu_fifo_underrun_irq_handler(struct drm_i915_private *dev_priv,
3632c9916cdSFrançois Tigeot 					 enum i915_pipe pipe)
3642c9916cdSFrançois Tigeot {
3654be47400SFrançois Tigeot 	struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
3662c9916cdSFrançois Tigeot 
3672c9916cdSFrançois Tigeot 	/* We may be called too early in init, thanks BIOS! */
3682c9916cdSFrançois Tigeot 	if (crtc == NULL)
3692c9916cdSFrançois Tigeot 		return;
3702c9916cdSFrançois Tigeot 
3712c9916cdSFrançois Tigeot 	/* GMCH can't disable fifo underruns, filter them. */
3728621f407SFrançois Tigeot 	if (HAS_GMCH_DISPLAY(dev_priv) &&
3734be47400SFrançois Tigeot 	    crtc->cpu_fifo_underrun_disabled)
3742c9916cdSFrançois Tigeot 		return;
3752c9916cdSFrançois Tigeot 
376a85cb24fSFrançois Tigeot 	if (intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false)) {
377a85cb24fSFrançois Tigeot 		trace_intel_cpu_fifo_underrun(dev_priv, pipe);
3782c9916cdSFrançois Tigeot 		DRM_ERROR("CPU pipe %c FIFO underrun\n",
3792c9916cdSFrançois Tigeot 			  pipe_name(pipe));
380a85cb24fSFrançois Tigeot 	}
3811e12ee3bSFrançois Tigeot 
3821e12ee3bSFrançois Tigeot 	intel_fbc_handle_fifo_underrun_irq(dev_priv);
3832c9916cdSFrançois Tigeot }
3842c9916cdSFrançois Tigeot 
3852c9916cdSFrançois Tigeot /**
3862c9916cdSFrançois Tigeot  * intel_pch_fifo_underrun_irq_handler - handle PCH fifo underrun interrupt
3872c9916cdSFrançois Tigeot  * @dev_priv: i915 device instance
3882c9916cdSFrançois Tigeot  * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
3892c9916cdSFrançois Tigeot  *
3902c9916cdSFrançois Tigeot  * This handles a PCH fifo underrun interrupt, generating an underrun warning
3912c9916cdSFrançois Tigeot  * into dmesg if underrun reporting is enabled and then disables the underrun
3922c9916cdSFrançois Tigeot  * interrupt to avoid an irq storm.
3932c9916cdSFrançois Tigeot  */
intel_pch_fifo_underrun_irq_handler(struct drm_i915_private * dev_priv,enum i915_pipe pch_transcoder)3942c9916cdSFrançois Tigeot void intel_pch_fifo_underrun_irq_handler(struct drm_i915_private *dev_priv,
395*3f2dd94aSFrançois Tigeot 					 enum i915_pipe pch_transcoder)
3962c9916cdSFrançois Tigeot {
3972c9916cdSFrançois Tigeot 	if (intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder,
398a85cb24fSFrançois Tigeot 						  false)) {
399a85cb24fSFrançois Tigeot 		trace_intel_pch_fifo_underrun(dev_priv, pch_transcoder);
400*3f2dd94aSFrançois Tigeot 		DRM_ERROR("PCH transcoder %c FIFO underrun\n",
401*3f2dd94aSFrançois Tigeot 			  pipe_name(pch_transcoder));
4022c9916cdSFrançois Tigeot 	}
403a85cb24fSFrançois Tigeot }
404aee94f86SFrançois Tigeot 
405aee94f86SFrançois Tigeot /**
406aee94f86SFrançois Tigeot  * intel_check_cpu_fifo_underruns - check for CPU fifo underruns immediately
407aee94f86SFrançois Tigeot  * @dev_priv: i915 device instance
408aee94f86SFrançois Tigeot  *
409aee94f86SFrançois Tigeot  * Check for CPU fifo underruns immediately. Useful on IVB/HSW where the shared
410aee94f86SFrançois Tigeot  * error interrupt may have been disabled, and so CPU fifo underruns won't
411aee94f86SFrançois Tigeot  * necessarily raise an interrupt, and on GMCH platforms where underruns never
412aee94f86SFrançois Tigeot  * raise an interrupt.
413aee94f86SFrançois Tigeot  */
intel_check_cpu_fifo_underruns(struct drm_i915_private * dev_priv)414aee94f86SFrançois Tigeot void intel_check_cpu_fifo_underruns(struct drm_i915_private *dev_priv)
415aee94f86SFrançois Tigeot {
416aee94f86SFrançois Tigeot 	struct intel_crtc *crtc;
417aee94f86SFrançois Tigeot 
418aee94f86SFrançois Tigeot 	spin_lock_irq(&dev_priv->irq_lock);
419aee94f86SFrançois Tigeot 
420303bf270SFrançois Tigeot 	for_each_intel_crtc(&dev_priv->drm, crtc) {
421aee94f86SFrançois Tigeot 		if (crtc->cpu_fifo_underrun_disabled)
422aee94f86SFrançois Tigeot 			continue;
423aee94f86SFrançois Tigeot 
424aee94f86SFrançois Tigeot 		if (HAS_GMCH_DISPLAY(dev_priv))
425aee94f86SFrançois Tigeot 			i9xx_check_fifo_underruns(crtc);
426aee94f86SFrançois Tigeot 		else if (IS_GEN7(dev_priv))
427aee94f86SFrançois Tigeot 			ivybridge_check_fifo_underruns(crtc);
428aee94f86SFrançois Tigeot 	}
429aee94f86SFrançois Tigeot 
430aee94f86SFrançois Tigeot 	spin_unlock_irq(&dev_priv->irq_lock);
431aee94f86SFrançois Tigeot }
432aee94f86SFrançois Tigeot 
433aee94f86SFrançois Tigeot /**
434aee94f86SFrançois Tigeot  * intel_check_pch_fifo_underruns - check for PCH fifo underruns immediately
435aee94f86SFrançois Tigeot  * @dev_priv: i915 device instance
436aee94f86SFrançois Tigeot  *
437aee94f86SFrançois Tigeot  * Check for PCH fifo underruns immediately. Useful on CPT/PPT where the shared
438aee94f86SFrançois Tigeot  * error interrupt may have been disabled, and so PCH fifo underruns won't
439aee94f86SFrançois Tigeot  * necessarily raise an interrupt.
440aee94f86SFrançois Tigeot  */
intel_check_pch_fifo_underruns(struct drm_i915_private * dev_priv)441aee94f86SFrançois Tigeot void intel_check_pch_fifo_underruns(struct drm_i915_private *dev_priv)
442aee94f86SFrançois Tigeot {
443aee94f86SFrançois Tigeot 	struct intel_crtc *crtc;
444aee94f86SFrançois Tigeot 
445aee94f86SFrançois Tigeot 	spin_lock_irq(&dev_priv->irq_lock);
446aee94f86SFrançois Tigeot 
447303bf270SFrançois Tigeot 	for_each_intel_crtc(&dev_priv->drm, crtc) {
448aee94f86SFrançois Tigeot 		if (crtc->pch_fifo_underrun_disabled)
449aee94f86SFrançois Tigeot 			continue;
450aee94f86SFrançois Tigeot 
451aee94f86SFrançois Tigeot 		if (HAS_PCH_CPT(dev_priv))
452aee94f86SFrançois Tigeot 			cpt_check_pch_fifo_underruns(crtc);
453aee94f86SFrançois Tigeot 	}
454aee94f86SFrançois Tigeot 
455aee94f86SFrançois Tigeot 	spin_unlock_irq(&dev_priv->irq_lock);
456aee94f86SFrançois Tigeot }
457