intel_fifo_underrun.c 13.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/*
 * Copyright © 2014 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 * Authors:
 *    Daniel Vetter <daniel.vetter@ffwll.ch>
 *
 */

#include "i915_drv.h"
#include "intel_drv.h"

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
/**
 * DOC: fifo underrun handling
 *
 * The i915 driver checks for display fifo underruns using the interrupt signals
 * provided by the hardware. This is enabled by default and fairly useful to
 * debug display issues, especially watermark settings.
 *
 * If an underrun is detected this is logged into dmesg. To avoid flooding logs
 * and occupying the cpu underrun interrupts are disabled after the first
 * occurrence until the next modeset on a given pipe.
 *
 * Note that underrun detection on gmch platforms is a bit more ugly since there
 * is no interrupt (despite that the signalling bit is in the PIPESTAT pipe
 * interrupt register). Also on some other platforms underrun interrupts are
 * shared, which means that if we detect an underrun we need to disable underrun
 * reporting on all pipes.
 *
 * The code also supports underrun detection on the PCH transcoder.
 */

51 52
static bool ivb_can_enable_err_int(struct drm_device *dev)
{
53
	struct drm_i915_private *dev_priv = to_i915(dev);
54 55 56
	struct intel_crtc *crtc;
	enum pipe pipe;

57
	lockdep_assert_held(&dev_priv->irq_lock);
58 59

	for_each_pipe(dev_priv, pipe) {
60
		crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
61 62 63 64 65 66 67 68 69 70

		if (crtc->cpu_fifo_underrun_disabled)
			return false;
	}

	return true;
}

static bool cpt_can_enable_serr_int(struct drm_device *dev)
{
71
	struct drm_i915_private *dev_priv = to_i915(dev);
72 73 74
	enum pipe pipe;
	struct intel_crtc *crtc;

75
	lockdep_assert_held(&dev_priv->irq_lock);
76 77

	for_each_pipe(dev_priv, pipe) {
78
		crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
79 80 81 82 83 84 85 86

		if (crtc->pch_fifo_underrun_disabled)
			return false;
	}

	return true;
}

87
static void i9xx_check_fifo_underruns(struct intel_crtc *crtc)
88
{
89
	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
90
	i915_reg_t reg = PIPESTAT(crtc->pipe);
91
	u32 pipestat = I915_READ(reg) & 0xffff0000;
92

93
	lockdep_assert_held(&dev_priv->irq_lock);
94

95 96
	if ((pipestat & PIPE_FIFO_UNDERRUN_STATUS) == 0)
		return;
97

98 99
	I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS);
	POSTING_READ(reg);
100

101
	DRM_ERROR("pipe %c underrun\n", pipe_name(crtc->pipe));
102 103 104 105 106 107
}

static void i9xx_set_fifo_underrun_reporting(struct drm_device *dev,
					     enum pipe pipe,
					     bool enable, bool old)
{
108
	struct drm_i915_private *dev_priv = to_i915(dev);
109
	i915_reg_t reg = PIPESTAT(pipe);
110 111
	u32 pipestat = I915_READ(reg) & 0xffff0000;

112
	lockdep_assert_held(&dev_priv->irq_lock);
113 114 115 116 117 118 119 120 121 122 123 124 125

	if (enable) {
		I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS);
		POSTING_READ(reg);
	} else {
		if (old && pipestat & PIPE_FIFO_UNDERRUN_STATUS)
			DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
	}
}

static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
						 enum pipe pipe, bool enable)
{
126
	struct drm_i915_private *dev_priv = to_i915(dev);
127 128 129 130
	uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
					  DE_PIPEB_FIFO_UNDERRUN;

	if (enable)
131
		ilk_enable_display_irq(dev_priv, bit);
132
	else
133
		ilk_disable_display_irq(dev_priv, bit);
134 135
}

136 137 138 139 140 141
static void ivybridge_check_fifo_underruns(struct intel_crtc *crtc)
{
	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
	enum pipe pipe = crtc->pipe;
	uint32_t err_int = I915_READ(GEN7_ERR_INT);

142
	lockdep_assert_held(&dev_priv->irq_lock);
143 144 145 146 147 148 149 150 151 152

	if ((err_int & ERR_INT_FIFO_UNDERRUN(pipe)) == 0)
		return;

	I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
	POSTING_READ(GEN7_ERR_INT);

	DRM_ERROR("fifo underrun on pipe %c\n", pipe_name(pipe));
}

153 154 155 156
static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
						  enum pipe pipe,
						  bool enable, bool old)
{
157
	struct drm_i915_private *dev_priv = to_i915(dev);
158 159 160 161 162 163
	if (enable) {
		I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));

		if (!ivb_can_enable_err_int(dev))
			return;

164
		ilk_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
165
	} else {
166
		ilk_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
167 168 169 170 171 172 173 174 175 176 177 178

		if (old &&
		    I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe)) {
			DRM_ERROR("uncleared fifo underrun on pipe %c\n",
				  pipe_name(pipe));
		}
	}
}

static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev,
						  enum pipe pipe, bool enable)
{
179
	struct drm_i915_private *dev_priv = to_i915(dev);
180 181

	if (enable)
182
		bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_FIFO_UNDERRUN);
183
	else
184
		bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_FIFO_UNDERRUN);
185 186 187 188 189 190
}

static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
					    enum transcoder pch_transcoder,
					    bool enable)
{
191
	struct drm_i915_private *dev_priv = to_i915(dev);
192 193 194 195 196 197 198 199 200
	uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
		       SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;

	if (enable)
		ibx_enable_display_interrupt(dev_priv, bit);
	else
		ibx_disable_display_interrupt(dev_priv, bit);
}

201 202 203 204 205 206
static void cpt_check_pch_fifo_underruns(struct intel_crtc *crtc)
{
	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
	enum transcoder pch_transcoder = (enum transcoder) crtc->pipe;
	uint32_t serr_int = I915_READ(SERR_INT);

207
	lockdep_assert_held(&dev_priv->irq_lock);
208 209 210 211 212 213 214

	if ((serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) == 0)
		return;

	I915_WRITE(SERR_INT, SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
	POSTING_READ(SERR_INT);

215
	DRM_ERROR("pch fifo underrun on pch transcoder %s\n",
216 217 218
		  transcoder_name(pch_transcoder));
}

219 220 221 222
static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
					    enum transcoder pch_transcoder,
					    bool enable, bool old)
{
223
	struct drm_i915_private *dev_priv = to_i915(dev);
224 225 226 227 228 229 230 231 232 233 234 235 236 237

	if (enable) {
		I915_WRITE(SERR_INT,
			   SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));

		if (!cpt_can_enable_serr_int(dev))
			return;

		ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
	} else {
		ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);

		if (old && I915_READ(SERR_INT) &
		    SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) {
238
			DRM_ERROR("uncleared pch fifo underrun on pch transcoder %s\n",
239 240 241 242 243 244 245 246
				  transcoder_name(pch_transcoder));
		}
	}
}

static bool __intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
						    enum pipe pipe, bool enable)
{
247
	struct drm_i915_private *dev_priv = to_i915(dev);
248
	struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
249 250
	bool old;

251
	lockdep_assert_held(&dev_priv->irq_lock);
252

253 254
	old = !crtc->cpu_fifo_underrun_disabled;
	crtc->cpu_fifo_underrun_disabled = !enable;
255

256
	if (HAS_GMCH_DISPLAY(dev_priv))
257
		i9xx_set_fifo_underrun_reporting(dev, pipe, enable, old);
258
	else if (IS_GEN5(dev_priv) || IS_GEN6(dev_priv))
259
		ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
260
	else if (IS_GEN7(dev_priv))
261
		ivybridge_set_fifo_underrun_reporting(dev, pipe, enable, old);
262
	else if (IS_GEN8(dev_priv) || IS_GEN9(dev_priv))
263 264 265 266 267
		broadwell_set_fifo_underrun_reporting(dev, pipe, enable);

	return old;
}

268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
/**
 * intel_set_cpu_fifo_underrun_reporting - set cpu fifo underrrun reporting state
 * @dev_priv: i915 device instance
 * @pipe: (CPU) pipe to set state for
 * @enable: whether underruns should be reported or not
 *
 * This function sets the fifo underrun state for @pipe. It is used in the
 * modeset code to avoid false positives since on many platforms underruns are
 * expected when disabling or enabling the pipe.
 *
 * Notice that on some platforms disabling underrun reports for one pipe
 * disables for all due to shared interrupts. Actual reporting is still per-pipe
 * though.
 *
 * Returns the previous state of underrun reporting.
 */
284
bool intel_set_cpu_fifo_underrun_reporting(struct drm_i915_private *dev_priv,
285 286 287 288 289 290
					   enum pipe pipe, bool enable)
{
	unsigned long flags;
	bool ret;

	spin_lock_irqsave(&dev_priv->irq_lock, flags);
291
	ret = __intel_set_cpu_fifo_underrun_reporting(&dev_priv->drm, pipe,
292
						      enable);
293 294 295 296 297 298
	spin_unlock_irqrestore(&dev_priv->irq_lock, flags);

	return ret;
}

/**
299 300
 * intel_set_pch_fifo_underrun_reporting - set PCH fifo underrun reporting state
 * @dev_priv: i915 device instance
301
 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
302
 * @enable: whether underruns should be reported or not
303 304 305 306 307 308 309 310 311
 *
 * This function makes us disable or enable PCH fifo underruns for a specific
 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
 * underrun reporting for one transcoder may also disable all the other PCH
 * error interruts for the other transcoders, due to the fact that there's just
 * one interrupt mask/enable bit for all the transcoders.
 *
 * Returns the previous state of underrun reporting.
 */
312
bool intel_set_pch_fifo_underrun_reporting(struct drm_i915_private *dev_priv,
313 314 315
					   enum transcoder pch_transcoder,
					   bool enable)
{
316 317
	struct intel_crtc *crtc =
		intel_get_crtc_for_pipe(dev_priv, (enum pipe) pch_transcoder);
318 319 320 321 322 323 324 325 326 327 328 329 330 331
	unsigned long flags;
	bool old;

	/*
	 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
	 * has only one pch transcoder A that all pipes can use. To avoid racy
	 * pch transcoder -> pipe lookups from interrupt code simply store the
	 * underrun statistics in crtc A. Since we never expose this anywhere
	 * nor use it outside of the fifo underrun code here using the "wrong"
	 * crtc on LPT won't cause issues.
	 */

	spin_lock_irqsave(&dev_priv->irq_lock, flags);

332 333
	old = !crtc->pch_fifo_underrun_disabled;
	crtc->pch_fifo_underrun_disabled = !enable;
334

335
	if (HAS_PCH_IBX(dev_priv))
336 337
		ibx_set_fifo_underrun_reporting(&dev_priv->drm,
						pch_transcoder,
338
						enable);
339
	else
340 341
		cpt_set_fifo_underrun_reporting(&dev_priv->drm,
						pch_transcoder,
342
						enable, old);
343 344 345 346

	spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
	return old;
}
347

348
/**
349
 * intel_cpu_fifo_underrun_irq_handler - handle CPU fifo underrun interrupt
350 351 352 353 354 355 356
 * @dev_priv: i915 device instance
 * @pipe: (CPU) pipe to set state for
 *
 * This handles a CPU fifo underrun interrupt, generating an underrun warning
 * into dmesg if underrun reporting is enabled and then disables the underrun
 * interrupt to avoid an irq storm.
 */
357 358 359
void intel_cpu_fifo_underrun_irq_handler(struct drm_i915_private *dev_priv,
					 enum pipe pipe)
{
360
	struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
361 362 363 364 365

	/* We may be called too early in init, thanks BIOS! */
	if (crtc == NULL)
		return;

366
	/* GMCH can't disable fifo underruns, filter them. */
367
	if (HAS_GMCH_DISPLAY(dev_priv) &&
368
	    crtc->cpu_fifo_underrun_disabled)
369 370
		return;

371 372 373
	if (intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false))
		DRM_ERROR("CPU pipe %c FIFO underrun\n",
			  pipe_name(pipe));
374 375

	intel_fbc_handle_fifo_underrun_irq(dev_priv);
376 377
}

378 379 380 381 382 383 384 385 386
/**
 * intel_pch_fifo_underrun_irq_handler - handle PCH fifo underrun interrupt
 * @dev_priv: i915 device instance
 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
 *
 * This handles a PCH fifo underrun interrupt, generating an underrun warning
 * into dmesg if underrun reporting is enabled and then disables the underrun
 * interrupt to avoid an irq storm.
 */
387 388 389 390 391
void intel_pch_fifo_underrun_irq_handler(struct drm_i915_private *dev_priv,
					 enum transcoder pch_transcoder)
{
	if (intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder,
						  false))
392
		DRM_ERROR("PCH transcoder %s FIFO underrun\n",
393 394
			  transcoder_name(pch_transcoder));
}
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410

/**
 * intel_check_cpu_fifo_underruns - check for CPU fifo underruns immediately
 * @dev_priv: i915 device instance
 *
 * Check for CPU fifo underruns immediately. Useful on IVB/HSW where the shared
 * error interrupt may have been disabled, and so CPU fifo underruns won't
 * necessarily raise an interrupt, and on GMCH platforms where underruns never
 * raise an interrupt.
 */
void intel_check_cpu_fifo_underruns(struct drm_i915_private *dev_priv)
{
	struct intel_crtc *crtc;

	spin_lock_irq(&dev_priv->irq_lock);

411
	for_each_intel_crtc(&dev_priv->drm, crtc) {
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
		if (crtc->cpu_fifo_underrun_disabled)
			continue;

		if (HAS_GMCH_DISPLAY(dev_priv))
			i9xx_check_fifo_underruns(crtc);
		else if (IS_GEN7(dev_priv))
			ivybridge_check_fifo_underruns(crtc);
	}

	spin_unlock_irq(&dev_priv->irq_lock);
}

/**
 * intel_check_pch_fifo_underruns - check for PCH fifo underruns immediately
 * @dev_priv: i915 device instance
 *
 * Check for PCH fifo underruns immediately. Useful on CPT/PPT where the shared
 * error interrupt may have been disabled, and so PCH fifo underruns won't
 * necessarily raise an interrupt.
 */
void intel_check_pch_fifo_underruns(struct drm_i915_private *dev_priv)
{
	struct intel_crtc *crtc;

	spin_lock_irq(&dev_priv->irq_lock);

438
	for_each_intel_crtc(&dev_priv->drm, crtc) {
439 440 441 442 443 444 445 446 447
		if (crtc->pch_fifo_underrun_disabled)
			continue;

		if (HAS_PCH_CPT(dev_priv))
			cpt_check_pch_fifo_underruns(crtc);
	}

	spin_unlock_irq(&dev_priv->irq_lock);
}