1 /* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
4 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31 #include <linux/sysrq.h>
32 #include <linux/slab.h>
33 #include <linux/circ_buf.h>
35 #include <drm/i915_drm.h>
37 #include "i915_trace.h"
38 #include "intel_drv.h"
41 * DOC: interrupt handling
43 * These functions provide the basic support for enabling and disabling the
44 * interrupt handling support. There's a lot more functionality in i915_irq.c
45 * and related files, but that will be described in separate chapters.
48 static const u32 hpd_ibx[] = {
49 [HPD_CRT] = SDE_CRT_HOTPLUG,
50 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
51 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
52 [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
53 [HPD_PORT_D] = SDE_PORTD_HOTPLUG
56 static const u32 hpd_cpt[] = {
57 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
58 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
59 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
60 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
61 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
64 static const u32 hpd_mask_i915[] = {
65 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
66 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
67 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
68 [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
69 [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
70 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
73 static const u32 hpd_status_g4x[] = {
74 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
75 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
76 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
77 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
78 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
79 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
82 static const u32 hpd_status_i915[] = { /* i915 and valleyview are the same */
83 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
84 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
85 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
86 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
87 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
88 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
91 /* IIR can theoretically queue up two events. Be paranoid. */
92 #define GEN8_IRQ_RESET_NDX(type, which) do { \
93 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
94 POSTING_READ(GEN8_##type##_IMR(which)); \
95 I915_WRITE(GEN8_##type##_IER(which), 0); \
96 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
97 POSTING_READ(GEN8_##type##_IIR(which)); \
98 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
99 POSTING_READ(GEN8_##type##_IIR(which)); \
102 #define GEN5_IRQ_RESET(type) do { \
103 I915_WRITE(type##IMR, 0xffffffff); \
104 POSTING_READ(type##IMR); \
105 I915_WRITE(type##IER, 0); \
106 I915_WRITE(type##IIR, 0xffffffff); \
107 POSTING_READ(type##IIR); \
108 I915_WRITE(type##IIR, 0xffffffff); \
109 POSTING_READ(type##IIR); \
113 * We should clear IMR at preinstall/uninstall, and just check at postinstall.
115 #define GEN5_ASSERT_IIR_IS_ZERO(reg) do { \
116 u32 val = I915_READ(reg); \
118 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n", \
120 I915_WRITE((reg), 0xffffffff); \
122 I915_WRITE((reg), 0xffffffff); \
127 #define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \
128 GEN5_ASSERT_IIR_IS_ZERO(GEN8_##type##_IIR(which)); \
129 I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \
130 I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \
131 POSTING_READ(GEN8_##type##_IMR(which)); \
134 #define GEN5_IRQ_INIT(type, imr_val, ier_val) do { \
135 GEN5_ASSERT_IIR_IS_ZERO(type##IIR); \
136 I915_WRITE(type##IER, (ier_val)); \
137 I915_WRITE(type##IMR, (imr_val)); \
138 POSTING_READ(type##IMR); \
141 static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir);
143 /* For display hotplug interrupt */
145 ironlake_enable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
147 assert_spin_locked(&dev_priv->irq_lock);
149 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
152 if ((dev_priv->irq_mask & mask) != 0) {
153 dev_priv->irq_mask &= ~mask;
154 I915_WRITE(DEIMR, dev_priv->irq_mask);
160 ironlake_disable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
162 assert_spin_locked(&dev_priv->irq_lock);
164 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
167 if ((dev_priv->irq_mask & mask) != mask) {
168 dev_priv->irq_mask |= mask;
169 I915_WRITE(DEIMR, dev_priv->irq_mask);
175 * ilk_update_gt_irq - update GTIMR
176 * @dev_priv: driver private
177 * @interrupt_mask: mask of interrupt bits to update
178 * @enabled_irq_mask: mask of interrupt bits to enable
180 static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
181 uint32_t interrupt_mask,
182 uint32_t enabled_irq_mask)
184 assert_spin_locked(&dev_priv->irq_lock);
186 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
189 dev_priv->gt_irq_mask &= ~interrupt_mask;
190 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
191 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
195 void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
197 ilk_update_gt_irq(dev_priv, mask, mask);
200 void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
202 ilk_update_gt_irq(dev_priv, mask, 0);
205 static u32 gen6_pm_iir(struct drm_i915_private *dev_priv)
207 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR;
210 static u32 gen6_pm_imr(struct drm_i915_private *dev_priv)
212 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IMR(2) : GEN6_PMIMR;
215 static u32 gen6_pm_ier(struct drm_i915_private *dev_priv)
217 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IER(2) : GEN6_PMIER;
221 * snb_update_pm_irq - update GEN6_PMIMR
222 * @dev_priv: driver private
223 * @interrupt_mask: mask of interrupt bits to update
224 * @enabled_irq_mask: mask of interrupt bits to enable
226 static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
227 uint32_t interrupt_mask,
228 uint32_t enabled_irq_mask)
232 assert_spin_locked(&dev_priv->irq_lock);
234 new_val = dev_priv->pm_irq_mask;
235 new_val &= ~interrupt_mask;
236 new_val |= (~enabled_irq_mask & interrupt_mask);
238 if (new_val != dev_priv->pm_irq_mask) {
239 dev_priv->pm_irq_mask = new_val;
240 I915_WRITE(gen6_pm_imr(dev_priv), dev_priv->pm_irq_mask);
241 POSTING_READ(gen6_pm_imr(dev_priv));
245 void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
247 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
250 snb_update_pm_irq(dev_priv, mask, mask);
253 static void __gen6_disable_pm_irq(struct drm_i915_private *dev_priv,
256 snb_update_pm_irq(dev_priv, mask, 0);
259 void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
261 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
264 __gen6_disable_pm_irq(dev_priv, mask);
267 void gen6_reset_rps_interrupts(struct drm_device *dev)
269 struct drm_i915_private *dev_priv = dev->dev_private;
270 uint32_t reg = gen6_pm_iir(dev_priv);
272 spin_lock_irq(&dev_priv->irq_lock);
273 I915_WRITE(reg, dev_priv->pm_rps_events);
274 I915_WRITE(reg, dev_priv->pm_rps_events);
276 spin_unlock_irq(&dev_priv->irq_lock);
279 void gen6_enable_rps_interrupts(struct drm_device *dev)
281 struct drm_i915_private *dev_priv = dev->dev_private;
283 spin_lock_irq(&dev_priv->irq_lock);
284 WARN_ON(dev_priv->rps.pm_iir);
285 WARN_ON(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events);
286 dev_priv->rps.interrupts_enabled = true;
287 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
288 spin_unlock_irq(&dev_priv->irq_lock);
291 void gen6_disable_rps_interrupts(struct drm_device *dev)
293 struct drm_i915_private *dev_priv = dev->dev_private;
295 spin_lock_irq(&dev_priv->irq_lock);
296 dev_priv->rps.interrupts_enabled = false;
297 spin_unlock_irq(&dev_priv->irq_lock);
299 cancel_work_sync(&dev_priv->rps.work);
301 spin_lock_irq(&dev_priv->irq_lock);
303 I915_WRITE(GEN6_PMINTRMSK, INTEL_INFO(dev_priv)->gen >= 8 ?
304 ~GEN8_PMINTR_REDIRECT_TO_NON_DISP : ~0);
306 __gen6_disable_pm_irq(dev_priv, dev_priv->pm_rps_events);
307 I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) &
308 ~dev_priv->pm_rps_events);
309 I915_WRITE(gen6_pm_iir(dev_priv), dev_priv->pm_rps_events);
310 I915_WRITE(gen6_pm_iir(dev_priv), dev_priv->pm_rps_events);
312 dev_priv->rps.pm_iir = 0;
314 spin_unlock_irq(&dev_priv->irq_lock);
318 * ibx_display_interrupt_update - update SDEIMR
319 * @dev_priv: driver private
320 * @interrupt_mask: mask of interrupt bits to update
321 * @enabled_irq_mask: mask of interrupt bits to enable
323 void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
324 uint32_t interrupt_mask,
325 uint32_t enabled_irq_mask)
327 uint32_t sdeimr = I915_READ(SDEIMR);
328 sdeimr &= ~interrupt_mask;
329 sdeimr |= (~enabled_irq_mask & interrupt_mask);
331 assert_spin_locked(&dev_priv->irq_lock);
333 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
336 I915_WRITE(SDEIMR, sdeimr);
337 POSTING_READ(SDEIMR);
341 __i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
342 u32 enable_mask, u32 status_mask)
344 u32 reg = PIPESTAT(pipe);
345 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
347 assert_spin_locked(&dev_priv->irq_lock);
348 WARN_ON(!intel_irqs_enabled(dev_priv));
350 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
351 status_mask & ~PIPESTAT_INT_STATUS_MASK,
352 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
353 pipe_name(pipe), enable_mask, status_mask))
356 if ((pipestat & enable_mask) == enable_mask)
359 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
361 /* Enable the interrupt, clear any pending status */
362 pipestat |= enable_mask | status_mask;
363 I915_WRITE(reg, pipestat);
368 __i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
369 u32 enable_mask, u32 status_mask)
371 u32 reg = PIPESTAT(pipe);
372 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
374 assert_spin_locked(&dev_priv->irq_lock);
375 WARN_ON(!intel_irqs_enabled(dev_priv));
377 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
378 status_mask & ~PIPESTAT_INT_STATUS_MASK,
379 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
380 pipe_name(pipe), enable_mask, status_mask))
383 if ((pipestat & enable_mask) == 0)
386 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
388 pipestat &= ~enable_mask;
389 I915_WRITE(reg, pipestat);
393 static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
395 u32 enable_mask = status_mask << 16;
398 * On pipe A we don't support the PSR interrupt yet,
399 * on pipe B and C the same bit MBZ.
401 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
404 * On pipe B and C we don't support the PSR interrupt yet, on pipe
405 * A the same bit is for perf counters which we don't use either.
407 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
410 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
411 SPRITE0_FLIP_DONE_INT_EN_VLV |
412 SPRITE1_FLIP_DONE_INT_EN_VLV);
413 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
414 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
415 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
416 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
422 i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
427 if (IS_VALLEYVIEW(dev_priv->dev))
428 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
431 enable_mask = status_mask << 16;
432 __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
436 i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
441 if (IS_VALLEYVIEW(dev_priv->dev))
442 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
445 enable_mask = status_mask << 16;
446 __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
450 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
452 static void i915_enable_asle_pipestat(struct drm_device *dev)
454 struct drm_i915_private *dev_priv = dev->dev_private;
456 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
459 spin_lock_irq(&dev_priv->irq_lock);
461 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
462 if (INTEL_INFO(dev)->gen >= 4)
463 i915_enable_pipestat(dev_priv, PIPE_A,
464 PIPE_LEGACY_BLC_EVENT_STATUS);
466 spin_unlock_irq(&dev_priv->irq_lock);
470 * i915_pipe_enabled - check if a pipe is enabled
472 * @pipe: pipe to check
474 * Reading certain registers when the pipe is disabled can hang the chip.
475 * Use this routine to make sure the PLL is running and the pipe is active
476 * before reading such registers if unsure.
479 i915_pipe_enabled(struct drm_device *dev, int pipe)
481 struct drm_i915_private *dev_priv = dev->dev_private;
483 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
484 /* Locking is horribly broken here, but whatever. */
485 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
486 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
488 return intel_crtc->active;
490 return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
495 * This timing diagram depicts the video signal in and
496 * around the vertical blanking period.
498 * Assumptions about the fictitious mode used in this example:
500 * vsync_start = vblank_start + 1
501 * vsync_end = vblank_start + 2
502 * vtotal = vblank_start + 3
505 * latch double buffered registers
506 * increment frame counter (ctg+)
507 * generate start of vblank interrupt (gen4+)
510 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
511 * | may be shifted forward 1-3 extra lines via PIPECONF
513 * | | start of vsync:
514 * | | generate vsync interrupt
516 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
517 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
518 * ----va---> <-----------------vb--------------------> <--------va-------------
519 * | | <----vs-----> |
520 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
521 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
522 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
524 * last visible pixel first visible pixel
525 * | increment frame counter (gen3/4)
526 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
528 * x = horizontal active
529 * _ = horizontal blanking
530 * hs = horizontal sync
531 * va = vertical active
532 * vb = vertical blanking
534 * vbs = vblank_start (number)
537 * - most events happen at the start of horizontal sync
538 * - frame start happens at the start of horizontal blank, 1-4 lines
539 * (depending on PIPECONF settings) after the start of vblank
540 * - gen3/4 pixel and frame counter are synchronized with the start
541 * of horizontal active on the first line of vertical active
544 static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
546 /* Gen2 doesn't have a hardware frame counter */
550 /* Called from drm generic code, passed a 'crtc', which
551 * we use as a pipe index
553 static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
555 struct drm_i915_private *dev_priv = dev->dev_private;
556 unsigned long high_frame;
557 unsigned long low_frame;
558 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
560 if (!i915_pipe_enabled(dev, pipe)) {
561 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
562 "pipe %c\n", pipe_name(pipe));
566 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
567 struct intel_crtc *intel_crtc =
568 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
569 const struct drm_display_mode *mode =
570 &intel_crtc->config.adjusted_mode;
572 htotal = mode->crtc_htotal;
573 hsync_start = mode->crtc_hsync_start;
574 vbl_start = mode->crtc_vblank_start;
575 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
576 vbl_start = DIV_ROUND_UP(vbl_start, 2);
578 enum transcoder cpu_transcoder = (enum transcoder) pipe;
580 htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1;
581 hsync_start = (I915_READ(HSYNC(cpu_transcoder)) & 0x1fff) + 1;
582 vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1;
583 if ((I915_READ(PIPECONF(cpu_transcoder)) &
584 PIPECONF_INTERLACE_MASK) != PIPECONF_PROGRESSIVE)
585 vbl_start = DIV_ROUND_UP(vbl_start, 2);
588 /* Convert to pixel count */
591 /* Start of vblank event occurs at start of hsync */
592 vbl_start -= htotal - hsync_start;
594 high_frame = PIPEFRAME(pipe);
595 low_frame = PIPEFRAMEPIXEL(pipe);
598 * High & low register fields aren't synchronized, so make sure
599 * we get a low value that's stable across two reads of the high
603 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
604 low = I915_READ(low_frame);
605 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
606 } while (high1 != high2);
608 high1 >>= PIPE_FRAME_HIGH_SHIFT;
609 pixel = low & PIPE_PIXEL_MASK;
610 low >>= PIPE_FRAME_LOW_SHIFT;
613 * The frame counter increments at beginning of active.
614 * Cook up a vblank counter by also checking the pixel
615 * counter against vblank start.
617 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
620 static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
622 struct drm_i915_private *dev_priv = dev->dev_private;
623 int reg = PIPE_FRMCOUNT_GM45(pipe);
625 if (!i915_pipe_enabled(dev, pipe)) {
626 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
627 "pipe %c\n", pipe_name(pipe));
631 return I915_READ(reg);
634 /* raw reads, only for fast reads of display block, no need for forcewake etc. */
635 #define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
637 static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
639 struct drm_device *dev = crtc->base.dev;
640 struct drm_i915_private *dev_priv = dev->dev_private;
641 const struct drm_display_mode *mode = &crtc->config.adjusted_mode;
642 enum pipe pipe = crtc->pipe;
643 int position, vtotal;
645 vtotal = mode->crtc_vtotal;
646 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
650 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
652 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
655 * See update_scanline_offset() for the details on the
656 * scanline_offset adjustment.
658 return (position + crtc->scanline_offset) % vtotal;
661 static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
662 unsigned int flags, int *vpos, int *hpos,
663 ktime_t *stime, ktime_t *etime)
665 struct drm_i915_private *dev_priv = dev->dev_private;
666 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
667 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
668 const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode;
670 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
673 unsigned long irqflags;
675 if (!intel_crtc->active) {
676 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
677 "pipe %c\n", pipe_name(pipe));
681 htotal = mode->crtc_htotal;
682 hsync_start = mode->crtc_hsync_start;
683 vtotal = mode->crtc_vtotal;
684 vbl_start = mode->crtc_vblank_start;
685 vbl_end = mode->crtc_vblank_end;
687 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
688 vbl_start = DIV_ROUND_UP(vbl_start, 2);
693 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
696 * Lock uncore.lock, as we will do multiple timing critical raw
697 * register reads, potentially with preemption disabled, so the
698 * following code must not block on uncore.lock.
700 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
702 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
704 /* Get optional system timestamp before query. */
706 *stime = ktime_get();
708 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
709 /* No obvious pixelcount register. Only query vertical
710 * scanout position from Display scan line register.
712 position = __intel_get_crtc_scanline(intel_crtc);
714 /* Have access to pixelcount since start of frame.
715 * We can split this into vertical and horizontal
718 position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
720 /* convert to pixel counts */
726 * In interlaced modes, the pixel counter counts all pixels,
727 * so one field will have htotal more pixels. In order to avoid
728 * the reported position from jumping backwards when the pixel
729 * counter is beyond the length of the shorter field, just
730 * clamp the position the length of the shorter field. This
731 * matches how the scanline counter based position works since
732 * the scanline counter doesn't count the two half lines.
734 if (position >= vtotal)
735 position = vtotal - 1;
738 * Start of vblank interrupt is triggered at start of hsync,
739 * just prior to the first active line of vblank. However we
740 * consider lines to start at the leading edge of horizontal
741 * active. So, should we get here before we've crossed into
742 * the horizontal active of the first line in vblank, we would
743 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
744 * always add htotal-hsync_start to the current pixel position.
746 position = (position + htotal - hsync_start) % vtotal;
749 /* Get optional system timestamp after query. */
751 *etime = ktime_get();
753 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
755 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
757 in_vbl = position >= vbl_start && position < vbl_end;
760 * While in vblank, position will be negative
761 * counting up towards 0 at vbl_end. And outside
762 * vblank, position will be positive counting
765 if (position >= vbl_start)
768 position += vtotal - vbl_end;
770 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
774 *vpos = position / htotal;
775 *hpos = position - (*vpos * htotal);
780 ret |= DRM_SCANOUTPOS_IN_VBLANK;
785 int intel_get_crtc_scanline(struct intel_crtc *crtc)
787 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
788 unsigned long irqflags;
791 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
792 position = __intel_get_crtc_scanline(crtc);
793 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
798 static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
800 struct timeval *vblank_time,
803 struct drm_crtc *crtc;
805 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
806 DRM_ERROR("Invalid crtc %d\n", pipe);
810 /* Get drm_crtc to timestamp: */
811 crtc = intel_get_crtc_for_pipe(dev, pipe);
813 DRM_ERROR("Invalid crtc %d\n", pipe);
817 if (!crtc->enabled) {
818 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
822 /* Helper routine in DRM core does all the work: */
823 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
826 &to_intel_crtc(crtc)->config.adjusted_mode);
829 static bool intel_hpd_irq_event(struct drm_device *dev,
830 struct drm_connector *connector)
832 enum drm_connector_status old_status;
834 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
835 old_status = connector->status;
837 connector->status = connector->funcs->detect(connector, false);
838 if (old_status == connector->status)
841 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
844 drm_get_connector_status_name(old_status),
845 drm_get_connector_status_name(connector->status));
850 static void i915_digport_work_func(struct work_struct *work)
852 struct drm_i915_private *dev_priv =
853 container_of(work, struct drm_i915_private, dig_port_work);
854 u32 long_port_mask, short_port_mask;
855 struct intel_digital_port *intel_dig_port;
859 spin_lock_irq(&dev_priv->irq_lock);
860 long_port_mask = dev_priv->long_hpd_port_mask;
861 dev_priv->long_hpd_port_mask = 0;
862 short_port_mask = dev_priv->short_hpd_port_mask;
863 dev_priv->short_hpd_port_mask = 0;
864 spin_unlock_irq(&dev_priv->irq_lock);
866 for (i = 0; i < I915_MAX_PORTS; i++) {
868 bool long_hpd = false;
869 intel_dig_port = dev_priv->hpd_irq_port[i];
870 if (!intel_dig_port || !intel_dig_port->hpd_pulse)
873 if (long_port_mask & (1 << i)) {
876 } else if (short_port_mask & (1 << i))
880 ret = intel_dig_port->hpd_pulse(intel_dig_port, long_hpd);
882 /* if we get true fallback to old school hpd */
883 old_bits |= (1 << intel_dig_port->base.hpd_pin);
889 spin_lock_irq(&dev_priv->irq_lock);
890 dev_priv->hpd_event_bits |= old_bits;
891 spin_unlock_irq(&dev_priv->irq_lock);
892 schedule_work(&dev_priv->hotplug_work);
897 * Handle hotplug events outside the interrupt handler proper.
899 #define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
901 static void i915_hotplug_work_func(struct work_struct *work)
903 struct drm_i915_private *dev_priv =
904 container_of(work, struct drm_i915_private, hotplug_work);
905 struct drm_device *dev = dev_priv->dev;
906 struct drm_mode_config *mode_config = &dev->mode_config;
907 struct intel_connector *intel_connector;
908 struct intel_encoder *intel_encoder;
909 struct drm_connector *connector;
910 bool hpd_disabled = false;
911 bool changed = false;
914 mutex_lock(&mode_config->mutex);
915 DRM_DEBUG_KMS("running encoder hotplug functions\n");
917 spin_lock_irq(&dev_priv->irq_lock);
919 hpd_event_bits = dev_priv->hpd_event_bits;
920 dev_priv->hpd_event_bits = 0;
921 list_for_each_entry(connector, &mode_config->connector_list, head) {
922 intel_connector = to_intel_connector(connector);
923 if (!intel_connector->encoder)
925 intel_encoder = intel_connector->encoder;
926 if (intel_encoder->hpd_pin > HPD_NONE &&
927 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
928 connector->polled == DRM_CONNECTOR_POLL_HPD) {
929 DRM_INFO("HPD interrupt storm detected on connector %s: "
930 "switching from hotplug detection to polling\n",
932 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
933 connector->polled = DRM_CONNECTOR_POLL_CONNECT
934 | DRM_CONNECTOR_POLL_DISCONNECT;
937 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
938 DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
939 connector->name, intel_encoder->hpd_pin);
942 /* if there were no outputs to poll, poll was disabled,
943 * therefore make sure it's enabled when disabling HPD on
946 drm_kms_helper_poll_enable(dev);
947 mod_delayed_work(system_wq, &dev_priv->hotplug_reenable_work,
948 msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
951 spin_unlock_irq(&dev_priv->irq_lock);
953 list_for_each_entry(connector, &mode_config->connector_list, head) {
954 intel_connector = to_intel_connector(connector);
955 if (!intel_connector->encoder)
957 intel_encoder = intel_connector->encoder;
958 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
959 if (intel_encoder->hot_plug)
960 intel_encoder->hot_plug(intel_encoder);
961 if (intel_hpd_irq_event(dev, connector))
965 mutex_unlock(&mode_config->mutex);
968 drm_kms_helper_hotplug_event(dev);
971 static void ironlake_rps_change_irq_handler(struct drm_device *dev)
973 struct drm_i915_private *dev_priv = dev->dev_private;
974 u32 busy_up, busy_down, max_avg, min_avg;
977 spin_lock(&mchdev_lock);
979 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
981 new_delay = dev_priv->ips.cur_delay;
983 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
984 busy_up = I915_READ(RCPREVBSYTUPAVG);
985 busy_down = I915_READ(RCPREVBSYTDNAVG);
986 max_avg = I915_READ(RCBMAXAVG);
987 min_avg = I915_READ(RCBMINAVG);
989 /* Handle RCS change request from hw */
990 if (busy_up > max_avg) {
991 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
992 new_delay = dev_priv->ips.cur_delay - 1;
993 if (new_delay < dev_priv->ips.max_delay)
994 new_delay = dev_priv->ips.max_delay;
995 } else if (busy_down < min_avg) {
996 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
997 new_delay = dev_priv->ips.cur_delay + 1;
998 if (new_delay > dev_priv->ips.min_delay)
999 new_delay = dev_priv->ips.min_delay;
1002 if (ironlake_set_drps(dev, new_delay))
1003 dev_priv->ips.cur_delay = new_delay;
1005 spin_unlock(&mchdev_lock);
1010 static void notify_ring(struct drm_device *dev,
1011 struct intel_engine_cs *ring)
1013 if (!intel_ring_initialized(ring))
1016 trace_i915_gem_request_complete(ring);
1018 wake_up_all(&ring->irq_queue);
1021 static u32 vlv_c0_residency(struct drm_i915_private *dev_priv,
1022 struct intel_rps_ei *rps_ei)
1024 u32 cz_ts, cz_freq_khz;
1025 u32 render_count, media_count;
1026 u32 elapsed_render, elapsed_media, elapsed_time;
1029 cz_ts = vlv_punit_read(dev_priv, PUNIT_REG_CZ_TIMESTAMP);
1030 cz_freq_khz = DIV_ROUND_CLOSEST(dev_priv->mem_freq * 1000, 4);
1032 render_count = I915_READ(VLV_RENDER_C0_COUNT_REG);
1033 media_count = I915_READ(VLV_MEDIA_C0_COUNT_REG);
1035 if (rps_ei->cz_clock == 0) {
1036 rps_ei->cz_clock = cz_ts;
1037 rps_ei->render_c0 = render_count;
1038 rps_ei->media_c0 = media_count;
1040 return dev_priv->rps.cur_freq;
1043 elapsed_time = cz_ts - rps_ei->cz_clock;
1044 rps_ei->cz_clock = cz_ts;
1046 elapsed_render = render_count - rps_ei->render_c0;
1047 rps_ei->render_c0 = render_count;
1049 elapsed_media = media_count - rps_ei->media_c0;
1050 rps_ei->media_c0 = media_count;
1052 /* Convert all the counters into common unit of milli sec */
1053 elapsed_time /= VLV_CZ_CLOCK_TO_MILLI_SEC;
1054 elapsed_render /= cz_freq_khz;
1055 elapsed_media /= cz_freq_khz;
1058 * Calculate overall C0 residency percentage
1059 * only if elapsed time is non zero
1063 ((max(elapsed_render, elapsed_media) * 100)
1071 * vlv_calc_delay_from_C0_counters - Increase/Decrease freq based on GPU
1072 * busy-ness calculated from C0 counters of render & media power wells
1073 * @dev_priv: DRM device private
1076 static int vlv_calc_delay_from_C0_counters(struct drm_i915_private *dev_priv)
1078 u32 residency_C0_up = 0, residency_C0_down = 0;
1081 dev_priv->rps.ei_interrupt_count++;
1083 WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
1086 if (dev_priv->rps.up_ei.cz_clock == 0) {
1087 vlv_c0_residency(dev_priv, &dev_priv->rps.up_ei);
1088 vlv_c0_residency(dev_priv, &dev_priv->rps.down_ei);
1089 return dev_priv->rps.cur_freq;
1094 * To down throttle, C0 residency should be less than down threshold
1095 * for continous EI intervals. So calculate down EI counters
1096 * once in VLV_INT_COUNT_FOR_DOWN_EI
1098 if (dev_priv->rps.ei_interrupt_count == VLV_INT_COUNT_FOR_DOWN_EI) {
1100 dev_priv->rps.ei_interrupt_count = 0;
1102 residency_C0_down = vlv_c0_residency(dev_priv,
1103 &dev_priv->rps.down_ei);
1105 residency_C0_up = vlv_c0_residency(dev_priv,
1106 &dev_priv->rps.up_ei);
1109 new_delay = dev_priv->rps.cur_freq;
1111 adj = dev_priv->rps.last_adj;
1112 /* C0 residency is greater than UP threshold. Increase Frequency */
1113 if (residency_C0_up >= VLV_RP_UP_EI_THRESHOLD) {
1119 if (dev_priv->rps.cur_freq < dev_priv->rps.max_freq_softlimit)
1120 new_delay = dev_priv->rps.cur_freq + adj;
1123 * For better performance, jump directly
1124 * to RPe if we're below it.
1126 if (new_delay < dev_priv->rps.efficient_freq)
1127 new_delay = dev_priv->rps.efficient_freq;
1129 } else if (!dev_priv->rps.ei_interrupt_count &&
1130 (residency_C0_down < VLV_RP_DOWN_EI_THRESHOLD)) {
1136 * This means, C0 residency is less than down threshold over
1137 * a period of VLV_INT_COUNT_FOR_DOWN_EI. So, reduce the freq
1139 if (dev_priv->rps.cur_freq > dev_priv->rps.min_freq_softlimit)
1140 new_delay = dev_priv->rps.cur_freq + adj;
1146 static void gen6_pm_rps_work(struct work_struct *work)
1148 struct drm_i915_private *dev_priv =
1149 container_of(work, struct drm_i915_private, rps.work);
1153 spin_lock_irq(&dev_priv->irq_lock);
1154 /* Speed up work cancelation during disabling rps interrupts. */
1155 if (!dev_priv->rps.interrupts_enabled) {
1156 spin_unlock_irq(&dev_priv->irq_lock);
1159 pm_iir = dev_priv->rps.pm_iir;
1160 dev_priv->rps.pm_iir = 0;
1161 /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
1162 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
1163 spin_unlock_irq(&dev_priv->irq_lock);
1165 /* Make sure we didn't queue anything we're not going to process. */
1166 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
1168 if ((pm_iir & dev_priv->pm_rps_events) == 0)
1171 mutex_lock(&dev_priv->rps.hw_lock);
1173 adj = dev_priv->rps.last_adj;
1174 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
1178 /* CHV needs even encode values */
1179 adj = IS_CHERRYVIEW(dev_priv->dev) ? 2 : 1;
1181 new_delay = dev_priv->rps.cur_freq + adj;
1184 * For better performance, jump directly
1185 * to RPe if we're below it.
1187 if (new_delay < dev_priv->rps.efficient_freq)
1188 new_delay = dev_priv->rps.efficient_freq;
1189 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
1190 if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
1191 new_delay = dev_priv->rps.efficient_freq;
1193 new_delay = dev_priv->rps.min_freq_softlimit;
1195 } else if (pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) {
1196 new_delay = vlv_calc_delay_from_C0_counters(dev_priv);
1197 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1201 /* CHV needs even encode values */
1202 adj = IS_CHERRYVIEW(dev_priv->dev) ? -2 : -1;
1204 new_delay = dev_priv->rps.cur_freq + adj;
1205 } else { /* unknown event */
1206 new_delay = dev_priv->rps.cur_freq;
1209 /* sysfs frequency interfaces may have snuck in while servicing the
1212 new_delay = clamp_t(int, new_delay,
1213 dev_priv->rps.min_freq_softlimit,
1214 dev_priv->rps.max_freq_softlimit);
1216 dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_freq;
1218 if (IS_VALLEYVIEW(dev_priv->dev))
1219 valleyview_set_rps(dev_priv->dev, new_delay);
1221 gen6_set_rps(dev_priv->dev, new_delay);
1223 mutex_unlock(&dev_priv->rps.hw_lock);
1228 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1230 * @work: workqueue struct
1232 * Doesn't actually do anything except notify userspace. As a consequence of
1233 * this event, userspace should try to remap the bad rows since statistically
1234 * it is likely the same row is more likely to go bad again.
1236 static void ivybridge_parity_work(struct work_struct *work)
1238 struct drm_i915_private *dev_priv =
1239 container_of(work, struct drm_i915_private, l3_parity.error_work);
1240 u32 error_status, row, bank, subbank;
1241 char *parity_event[6];
1245 /* We must turn off DOP level clock gating to access the L3 registers.
1246 * In order to prevent a get/put style interface, acquire struct mutex
1247 * any time we access those registers.
1249 mutex_lock(&dev_priv->dev->struct_mutex);
1251 /* If we've screwed up tracking, just let the interrupt fire again */
1252 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1255 misccpctl = I915_READ(GEN7_MISCCPCTL);
1256 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1257 POSTING_READ(GEN7_MISCCPCTL);
1259 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1263 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1266 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1268 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1270 error_status = I915_READ(reg);
1271 row = GEN7_PARITY_ERROR_ROW(error_status);
1272 bank = GEN7_PARITY_ERROR_BANK(error_status);
1273 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1275 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1278 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1279 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1280 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1281 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1282 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1283 parity_event[5] = NULL;
1285 kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
1286 KOBJ_CHANGE, parity_event);
1288 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1289 slice, row, bank, subbank);
1291 kfree(parity_event[4]);
1292 kfree(parity_event[3]);
1293 kfree(parity_event[2]);
1294 kfree(parity_event[1]);
1297 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1300 WARN_ON(dev_priv->l3_parity.which_slice);
1301 spin_lock_irq(&dev_priv->irq_lock);
1302 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
1303 spin_unlock_irq(&dev_priv->irq_lock);
1305 mutex_unlock(&dev_priv->dev->struct_mutex);
1308 static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
1310 struct drm_i915_private *dev_priv = dev->dev_private;
1312 if (!HAS_L3_DPF(dev))
1315 spin_lock(&dev_priv->irq_lock);
1316 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
1317 spin_unlock(&dev_priv->irq_lock);
1319 iir &= GT_PARITY_ERROR(dev);
1320 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1321 dev_priv->l3_parity.which_slice |= 1 << 1;
1323 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1324 dev_priv->l3_parity.which_slice |= 1 << 0;
1326 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
1329 static void ilk_gt_irq_handler(struct drm_device *dev,
1330 struct drm_i915_private *dev_priv,
1334 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1335 notify_ring(dev, &dev_priv->ring[RCS]);
1336 if (gt_iir & ILK_BSD_USER_INTERRUPT)
1337 notify_ring(dev, &dev_priv->ring[VCS]);
1340 static void snb_gt_irq_handler(struct drm_device *dev,
1341 struct drm_i915_private *dev_priv,
1346 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1347 notify_ring(dev, &dev_priv->ring[RCS]);
1348 if (gt_iir & GT_BSD_USER_INTERRUPT)
1349 notify_ring(dev, &dev_priv->ring[VCS]);
1350 if (gt_iir & GT_BLT_USER_INTERRUPT)
1351 notify_ring(dev, &dev_priv->ring[BCS]);
1353 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1354 GT_BSD_CS_ERROR_INTERRUPT |
1355 GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
1356 DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
1358 if (gt_iir & GT_PARITY_ERROR(dev))
1359 ivybridge_parity_error_irq_handler(dev, gt_iir);
1362 static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev,
1363 struct drm_i915_private *dev_priv,
1366 struct intel_engine_cs *ring;
1369 irqreturn_t ret = IRQ_NONE;
1371 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
1372 tmp = I915_READ(GEN8_GT_IIR(0));
1374 I915_WRITE(GEN8_GT_IIR(0), tmp);
1377 rcs = tmp >> GEN8_RCS_IRQ_SHIFT;
1378 ring = &dev_priv->ring[RCS];
1379 if (rcs & GT_RENDER_USER_INTERRUPT)
1380 notify_ring(dev, ring);
1381 if (rcs & GT_CONTEXT_SWITCH_INTERRUPT)
1382 intel_execlists_handle_ctx_events(ring);
1384 bcs = tmp >> GEN8_BCS_IRQ_SHIFT;
1385 ring = &dev_priv->ring[BCS];
1386 if (bcs & GT_RENDER_USER_INTERRUPT)
1387 notify_ring(dev, ring);
1388 if (bcs & GT_CONTEXT_SWITCH_INTERRUPT)
1389 intel_execlists_handle_ctx_events(ring);
1391 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1394 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
1395 tmp = I915_READ(GEN8_GT_IIR(1));
1397 I915_WRITE(GEN8_GT_IIR(1), tmp);
1400 vcs = tmp >> GEN8_VCS1_IRQ_SHIFT;
1401 ring = &dev_priv->ring[VCS];
1402 if (vcs & GT_RENDER_USER_INTERRUPT)
1403 notify_ring(dev, ring);
1404 if (vcs & GT_CONTEXT_SWITCH_INTERRUPT)
1405 intel_execlists_handle_ctx_events(ring);
1407 vcs = tmp >> GEN8_VCS2_IRQ_SHIFT;
1408 ring = &dev_priv->ring[VCS2];
1409 if (vcs & GT_RENDER_USER_INTERRUPT)
1410 notify_ring(dev, ring);
1411 if (vcs & GT_CONTEXT_SWITCH_INTERRUPT)
1412 intel_execlists_handle_ctx_events(ring);
1414 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1417 if (master_ctl & GEN8_GT_PM_IRQ) {
1418 tmp = I915_READ(GEN8_GT_IIR(2));
1419 if (tmp & dev_priv->pm_rps_events) {
1420 I915_WRITE(GEN8_GT_IIR(2),
1421 tmp & dev_priv->pm_rps_events);
1423 gen6_rps_irq_handler(dev_priv, tmp);
1425 DRM_ERROR("The master control interrupt lied (PM)!\n");
1428 if (master_ctl & GEN8_GT_VECS_IRQ) {
1429 tmp = I915_READ(GEN8_GT_IIR(3));
1431 I915_WRITE(GEN8_GT_IIR(3), tmp);
1434 vcs = tmp >> GEN8_VECS_IRQ_SHIFT;
1435 ring = &dev_priv->ring[VECS];
1436 if (vcs & GT_RENDER_USER_INTERRUPT)
1437 notify_ring(dev, ring);
1438 if (vcs & GT_CONTEXT_SWITCH_INTERRUPT)
1439 intel_execlists_handle_ctx_events(ring);
1441 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1447 #define HPD_STORM_DETECT_PERIOD 1000
1448 #define HPD_STORM_THRESHOLD 5
1450 static int pch_port_to_hotplug_shift(enum port port)
1466 static int i915_port_to_hotplug_shift(enum port port)
1482 static inline enum port get_port_from_pin(enum hpd_pin pin)
1492 return PORT_A; /* no hpd */
1496 static inline void intel_hpd_irq_handler(struct drm_device *dev,
1497 u32 hotplug_trigger,
1498 u32 dig_hotplug_reg,
1501 struct drm_i915_private *dev_priv = dev->dev_private;
1504 bool storm_detected = false;
1505 bool queue_dig = false, queue_hp = false;
1507 u32 dig_port_mask = 0;
1509 if (!hotplug_trigger)
1512 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x\n",
1513 hotplug_trigger, dig_hotplug_reg);
1515 spin_lock(&dev_priv->irq_lock);
1516 for (i = 1; i < HPD_NUM_PINS; i++) {
1517 if (!(hpd[i] & hotplug_trigger))
1520 port = get_port_from_pin(i);
1521 if (port && dev_priv->hpd_irq_port[port]) {
1524 if (HAS_PCH_SPLIT(dev)) {
1525 dig_shift = pch_port_to_hotplug_shift(port);
1526 long_hpd = (dig_hotplug_reg >> dig_shift) & PORTB_HOTPLUG_LONG_DETECT;
1528 dig_shift = i915_port_to_hotplug_shift(port);
1529 long_hpd = (hotplug_trigger >> dig_shift) & PORTB_HOTPLUG_LONG_DETECT;
1532 DRM_DEBUG_DRIVER("digital hpd port %c - %s\n",
1534 long_hpd ? "long" : "short");
1535 /* for long HPD pulses we want to have the digital queue happen,
1536 but we still want HPD storm detection to function. */
1538 dev_priv->long_hpd_port_mask |= (1 << port);
1539 dig_port_mask |= hpd[i];
1541 /* for short HPD just trigger the digital queue */
1542 dev_priv->short_hpd_port_mask |= (1 << port);
1543 hotplug_trigger &= ~hpd[i];
1549 for (i = 1; i < HPD_NUM_PINS; i++) {
1550 if (hpd[i] & hotplug_trigger &&
1551 dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED) {
1553 * On GMCH platforms the interrupt mask bits only
1554 * prevent irq generation, not the setting of the
1555 * hotplug bits itself. So only WARN about unexpected
1556 * interrupts on saner platforms.
1558 WARN_ONCE(INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev),
1559 "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n",
1560 hotplug_trigger, i, hpd[i]);
1565 if (!(hpd[i] & hotplug_trigger) ||
1566 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
1569 if (!(dig_port_mask & hpd[i])) {
1570 dev_priv->hpd_event_bits |= (1 << i);
1574 if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
1575 dev_priv->hpd_stats[i].hpd_last_jiffies
1576 + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
1577 dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
1578 dev_priv->hpd_stats[i].hpd_cnt = 0;
1579 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
1580 } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
1581 dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
1582 dev_priv->hpd_event_bits &= ~(1 << i);
1583 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
1584 storm_detected = true;
1586 dev_priv->hpd_stats[i].hpd_cnt++;
1587 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
1588 dev_priv->hpd_stats[i].hpd_cnt);
1593 dev_priv->display.hpd_irq_setup(dev);
1594 spin_unlock(&dev_priv->irq_lock);
1597 * Our hotplug handler can grab modeset locks (by calling down into the
1598 * fb helpers). Hence it must not be run on our own dev-priv->wq work
1599 * queue for otherwise the flush_work in the pageflip code will
1603 queue_work(dev_priv->dp_wq, &dev_priv->dig_port_work);
1605 schedule_work(&dev_priv->hotplug_work);
1608 static void gmbus_irq_handler(struct drm_device *dev)
1610 struct drm_i915_private *dev_priv = dev->dev_private;
1612 wake_up_all(&dev_priv->gmbus_wait_queue);
1615 static void dp_aux_irq_handler(struct drm_device *dev)
1617 struct drm_i915_private *dev_priv = dev->dev_private;
1619 wake_up_all(&dev_priv->gmbus_wait_queue);
1622 #if defined(CONFIG_DEBUG_FS)
1623 static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1624 uint32_t crc0, uint32_t crc1,
1625 uint32_t crc2, uint32_t crc3,
1628 struct drm_i915_private *dev_priv = dev->dev_private;
1629 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1630 struct intel_pipe_crc_entry *entry;
1633 spin_lock(&pipe_crc->lock);
1635 if (!pipe_crc->entries) {
1636 spin_unlock(&pipe_crc->lock);
1637 DRM_DEBUG_KMS("spurious interrupt\n");
1641 head = pipe_crc->head;
1642 tail = pipe_crc->tail;
1644 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
1645 spin_unlock(&pipe_crc->lock);
1646 DRM_ERROR("CRC buffer overflowing\n");
1650 entry = &pipe_crc->entries[head];
1652 entry->frame = dev->driver->get_vblank_counter(dev, pipe);
1653 entry->crc[0] = crc0;
1654 entry->crc[1] = crc1;
1655 entry->crc[2] = crc2;
1656 entry->crc[3] = crc3;
1657 entry->crc[4] = crc4;
1659 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
1660 pipe_crc->head = head;
1662 spin_unlock(&pipe_crc->lock);
1664 wake_up_interruptible(&pipe_crc->wq);
1668 display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1669 uint32_t crc0, uint32_t crc1,
1670 uint32_t crc2, uint32_t crc3,
1675 static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
1677 struct drm_i915_private *dev_priv = dev->dev_private;
1679 display_pipe_crc_irq_handler(dev, pipe,
1680 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1684 static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
1686 struct drm_i915_private *dev_priv = dev->dev_private;
1688 display_pipe_crc_irq_handler(dev, pipe,
1689 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1690 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1691 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1692 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1693 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
1696 static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
1698 struct drm_i915_private *dev_priv = dev->dev_private;
1699 uint32_t res1, res2;
1701 if (INTEL_INFO(dev)->gen >= 3)
1702 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1706 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
1707 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1711 display_pipe_crc_irq_handler(dev, pipe,
1712 I915_READ(PIPE_CRC_RES_RED(pipe)),
1713 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1714 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1718 /* The RPS events need forcewake, so we add them to a work queue and mask their
1719 * IMR bits until the work is done. Other interrupts can be processed without
1720 * the work queue. */
1721 static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
1723 /* TODO: RPS on GEN9+ is not supported yet. */
1724 if (WARN_ONCE(INTEL_INFO(dev_priv)->gen >= 9,
1725 "GEN9+: unexpected RPS IRQ\n"))
1728 if (pm_iir & dev_priv->pm_rps_events) {
1729 spin_lock(&dev_priv->irq_lock);
1730 gen6_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
1731 if (dev_priv->rps.interrupts_enabled) {
1732 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
1733 queue_work(dev_priv->wq, &dev_priv->rps.work);
1735 spin_unlock(&dev_priv->irq_lock);
1738 if (INTEL_INFO(dev_priv)->gen >= 8)
1741 if (HAS_VEBOX(dev_priv->dev)) {
1742 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
1743 notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
1745 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
1746 DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
1750 static bool intel_pipe_handle_vblank(struct drm_device *dev, enum pipe pipe)
1752 if (!drm_handle_vblank(dev, pipe))
1758 static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir)
1760 struct drm_i915_private *dev_priv = dev->dev_private;
1761 u32 pipe_stats[I915_MAX_PIPES] = { };
1764 spin_lock(&dev_priv->irq_lock);
1765 for_each_pipe(dev_priv, pipe) {
1767 u32 mask, iir_bit = 0;
1770 * PIPESTAT bits get signalled even when the interrupt is
1771 * disabled with the mask bits, and some of the status bits do
1772 * not generate interrupts at all (like the underrun bit). Hence
1773 * we need to be careful that we only handle what we want to
1777 /* fifo underruns are filterered in the underrun handler. */
1778 mask = PIPE_FIFO_UNDERRUN_STATUS;
1782 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1785 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1788 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1792 mask |= dev_priv->pipestat_irq_mask[pipe];
1797 reg = PIPESTAT(pipe);
1798 mask |= PIPESTAT_INT_ENABLE_MASK;
1799 pipe_stats[pipe] = I915_READ(reg) & mask;
1802 * Clear the PIPE*STAT regs before the IIR
1804 if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
1805 PIPESTAT_INT_STATUS_MASK))
1806 I915_WRITE(reg, pipe_stats[pipe]);
1808 spin_unlock(&dev_priv->irq_lock);
1810 for_each_pipe(dev_priv, pipe) {
1811 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
1812 intel_pipe_handle_vblank(dev, pipe))
1813 intel_check_page_flip(dev, pipe);
1815 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) {
1816 intel_prepare_page_flip(dev, pipe);
1817 intel_finish_page_flip(dev, pipe);
1820 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1821 i9xx_pipe_crc_irq_handler(dev, pipe);
1823 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1824 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1827 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1828 gmbus_irq_handler(dev);
1831 static void i9xx_hpd_irq_handler(struct drm_device *dev)
1833 struct drm_i915_private *dev_priv = dev->dev_private;
1834 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
1836 if (hotplug_status) {
1837 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1839 * Make sure hotplug status is cleared before we clear IIR, or else we
1840 * may miss hotplug events.
1842 POSTING_READ(PORT_HOTPLUG_STAT);
1845 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
1847 intel_hpd_irq_handler(dev, hotplug_trigger, 0, hpd_status_g4x);
1849 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
1851 intel_hpd_irq_handler(dev, hotplug_trigger, 0, hpd_status_i915);
1854 if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) &&
1855 hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
1856 dp_aux_irq_handler(dev);
1860 static irqreturn_t valleyview_irq_handler(int irq, void *arg)
1862 struct drm_device *dev = arg;
1863 struct drm_i915_private *dev_priv = dev->dev_private;
1864 u32 iir, gt_iir, pm_iir;
1865 irqreturn_t ret = IRQ_NONE;
1868 /* Find, clear, then process each source of interrupt */
1870 gt_iir = I915_READ(GTIIR);
1872 I915_WRITE(GTIIR, gt_iir);
1874 pm_iir = I915_READ(GEN6_PMIIR);
1876 I915_WRITE(GEN6_PMIIR, pm_iir);
1878 iir = I915_READ(VLV_IIR);
1880 /* Consume port before clearing IIR or we'll miss events */
1881 if (iir & I915_DISPLAY_PORT_INTERRUPT)
1882 i9xx_hpd_irq_handler(dev);
1883 I915_WRITE(VLV_IIR, iir);
1886 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1892 snb_gt_irq_handler(dev, dev_priv, gt_iir);
1894 gen6_rps_irq_handler(dev_priv, pm_iir);
1895 /* Call regardless, as some status bits might not be
1896 * signalled in iir */
1897 valleyview_pipestat_irq_handler(dev, iir);
1904 static irqreturn_t cherryview_irq_handler(int irq, void *arg)
1906 struct drm_device *dev = arg;
1907 struct drm_i915_private *dev_priv = dev->dev_private;
1908 u32 master_ctl, iir;
1909 irqreturn_t ret = IRQ_NONE;
1912 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
1913 iir = I915_READ(VLV_IIR);
1915 if (master_ctl == 0 && iir == 0)
1920 I915_WRITE(GEN8_MASTER_IRQ, 0);
1922 /* Find, clear, then process each source of interrupt */
1925 /* Consume port before clearing IIR or we'll miss events */
1926 if (iir & I915_DISPLAY_PORT_INTERRUPT)
1927 i9xx_hpd_irq_handler(dev);
1928 I915_WRITE(VLV_IIR, iir);
1931 gen8_gt_irq_handler(dev, dev_priv, master_ctl);
1933 /* Call regardless, as some status bits might not be
1934 * signalled in iir */
1935 valleyview_pipestat_irq_handler(dev, iir);
1937 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
1938 POSTING_READ(GEN8_MASTER_IRQ);
1944 static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
1946 struct drm_i915_private *dev_priv = dev->dev_private;
1948 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
1949 u32 dig_hotplug_reg;
1951 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
1952 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
1954 intel_hpd_irq_handler(dev, hotplug_trigger, dig_hotplug_reg, hpd_ibx);
1956 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1957 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1958 SDE_AUDIO_POWER_SHIFT);
1959 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
1963 if (pch_iir & SDE_AUX_MASK)
1964 dp_aux_irq_handler(dev);
1966 if (pch_iir & SDE_GMBUS)
1967 gmbus_irq_handler(dev);
1969 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1970 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1972 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1973 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1975 if (pch_iir & SDE_POISON)
1976 DRM_ERROR("PCH poison interrupt\n");
1978 if (pch_iir & SDE_FDI_MASK)
1979 for_each_pipe(dev_priv, pipe)
1980 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1982 I915_READ(FDI_RX_IIR(pipe)));
1984 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1985 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1987 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1988 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1990 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
1991 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
1993 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1994 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
1997 static void ivb_err_int_handler(struct drm_device *dev)
1999 struct drm_i915_private *dev_priv = dev->dev_private;
2000 u32 err_int = I915_READ(GEN7_ERR_INT);
2003 if (err_int & ERR_INT_POISON)
2004 DRM_ERROR("Poison interrupt\n");
2006 for_each_pipe(dev_priv, pipe) {
2007 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
2008 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2010 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
2011 if (IS_IVYBRIDGE(dev))
2012 ivb_pipe_crc_irq_handler(dev, pipe);
2014 hsw_pipe_crc_irq_handler(dev, pipe);
2018 I915_WRITE(GEN7_ERR_INT, err_int);
2021 static void cpt_serr_int_handler(struct drm_device *dev)
2023 struct drm_i915_private *dev_priv = dev->dev_private;
2024 u32 serr_int = I915_READ(SERR_INT);
2026 if (serr_int & SERR_INT_POISON)
2027 DRM_ERROR("PCH poison interrupt\n");
2029 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
2030 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
2032 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
2033 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
2035 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
2036 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_C);
2038 I915_WRITE(SERR_INT, serr_int);
2041 static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
2043 struct drm_i915_private *dev_priv = dev->dev_private;
2045 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
2046 u32 dig_hotplug_reg;
2048 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2049 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2051 intel_hpd_irq_handler(dev, hotplug_trigger, dig_hotplug_reg, hpd_cpt);
2053 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2054 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2055 SDE_AUDIO_POWER_SHIFT_CPT);
2056 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2060 if (pch_iir & SDE_AUX_MASK_CPT)
2061 dp_aux_irq_handler(dev);
2063 if (pch_iir & SDE_GMBUS_CPT)
2064 gmbus_irq_handler(dev);
2066 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2067 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2069 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2070 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2072 if (pch_iir & SDE_FDI_MASK_CPT)
2073 for_each_pipe(dev_priv, pipe)
2074 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2076 I915_READ(FDI_RX_IIR(pipe)));
2078 if (pch_iir & SDE_ERROR_CPT)
2079 cpt_serr_int_handler(dev);
2082 static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
2084 struct drm_i915_private *dev_priv = dev->dev_private;
2087 if (de_iir & DE_AUX_CHANNEL_A)
2088 dp_aux_irq_handler(dev);
2090 if (de_iir & DE_GSE)
2091 intel_opregion_asle_intr(dev);
2093 if (de_iir & DE_POISON)
2094 DRM_ERROR("Poison interrupt\n");
2096 for_each_pipe(dev_priv, pipe) {
2097 if (de_iir & DE_PIPE_VBLANK(pipe) &&
2098 intel_pipe_handle_vblank(dev, pipe))
2099 intel_check_page_flip(dev, pipe);
2101 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
2102 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2104 if (de_iir & DE_PIPE_CRC_DONE(pipe))
2105 i9xx_pipe_crc_irq_handler(dev, pipe);
2107 /* plane/pipes map 1:1 on ilk+ */
2108 if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
2109 intel_prepare_page_flip(dev, pipe);
2110 intel_finish_page_flip_plane(dev, pipe);
2114 /* check event from PCH */
2115 if (de_iir & DE_PCH_EVENT) {
2116 u32 pch_iir = I915_READ(SDEIIR);
2118 if (HAS_PCH_CPT(dev))
2119 cpt_irq_handler(dev, pch_iir);
2121 ibx_irq_handler(dev, pch_iir);
2123 /* should clear PCH hotplug event before clear CPU irq */
2124 I915_WRITE(SDEIIR, pch_iir);
2127 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
2128 ironlake_rps_change_irq_handler(dev);
2131 static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
2133 struct drm_i915_private *dev_priv = dev->dev_private;
2136 if (de_iir & DE_ERR_INT_IVB)
2137 ivb_err_int_handler(dev);
2139 if (de_iir & DE_AUX_CHANNEL_A_IVB)
2140 dp_aux_irq_handler(dev);
2142 if (de_iir & DE_GSE_IVB)
2143 intel_opregion_asle_intr(dev);
2145 for_each_pipe(dev_priv, pipe) {
2146 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)) &&
2147 intel_pipe_handle_vblank(dev, pipe))
2148 intel_check_page_flip(dev, pipe);
2150 /* plane/pipes map 1:1 on ilk+ */
2151 if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) {
2152 intel_prepare_page_flip(dev, pipe);
2153 intel_finish_page_flip_plane(dev, pipe);
2157 /* check event from PCH */
2158 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
2159 u32 pch_iir = I915_READ(SDEIIR);
2161 cpt_irq_handler(dev, pch_iir);
2163 /* clear PCH hotplug event before clear CPU irq */
2164 I915_WRITE(SDEIIR, pch_iir);
2169 * To handle irqs with the minimum potential races with fresh interrupts, we:
2170 * 1 - Disable Master Interrupt Control.
2171 * 2 - Find the source(s) of the interrupt.
2172 * 3 - Clear the Interrupt Identity bits (IIR).
2173 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2174 * 5 - Re-enable Master Interrupt Control.
2176 static irqreturn_t ironlake_irq_handler(int irq, void *arg)
2178 struct drm_device *dev = arg;
2179 struct drm_i915_private *dev_priv = dev->dev_private;
2180 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
2181 irqreturn_t ret = IRQ_NONE;
2183 /* We get interrupts on unclaimed registers, so check for this before we
2184 * do any I915_{READ,WRITE}. */
2185 intel_uncore_check_errors(dev);
2187 /* disable master interrupt before clearing iir */
2188 de_ier = I915_READ(DEIER);
2189 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
2190 POSTING_READ(DEIER);
2192 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2193 * interrupts will will be stored on its back queue, and then we'll be
2194 * able to process them after we restore SDEIER (as soon as we restore
2195 * it, we'll get an interrupt if SDEIIR still has something to process
2196 * due to its back queue). */
2197 if (!HAS_PCH_NOP(dev)) {
2198 sde_ier = I915_READ(SDEIER);
2199 I915_WRITE(SDEIER, 0);
2200 POSTING_READ(SDEIER);
2203 /* Find, clear, then process each source of interrupt */
2205 gt_iir = I915_READ(GTIIR);
2207 I915_WRITE(GTIIR, gt_iir);
2209 if (INTEL_INFO(dev)->gen >= 6)
2210 snb_gt_irq_handler(dev, dev_priv, gt_iir);
2212 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
2215 de_iir = I915_READ(DEIIR);
2217 I915_WRITE(DEIIR, de_iir);
2219 if (INTEL_INFO(dev)->gen >= 7)
2220 ivb_display_irq_handler(dev, de_iir);
2222 ilk_display_irq_handler(dev, de_iir);
2225 if (INTEL_INFO(dev)->gen >= 6) {
2226 u32 pm_iir = I915_READ(GEN6_PMIIR);
2228 I915_WRITE(GEN6_PMIIR, pm_iir);
2230 gen6_rps_irq_handler(dev_priv, pm_iir);
2234 I915_WRITE(DEIER, de_ier);
2235 POSTING_READ(DEIER);
2236 if (!HAS_PCH_NOP(dev)) {
2237 I915_WRITE(SDEIER, sde_ier);
2238 POSTING_READ(SDEIER);
2244 static irqreturn_t gen8_irq_handler(int irq, void *arg)
2246 struct drm_device *dev = arg;
2247 struct drm_i915_private *dev_priv = dev->dev_private;
2249 irqreturn_t ret = IRQ_NONE;
2252 u32 aux_mask = GEN8_AUX_CHANNEL_A;
2255 aux_mask |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
2258 master_ctl = I915_READ(GEN8_MASTER_IRQ);
2259 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2263 I915_WRITE(GEN8_MASTER_IRQ, 0);
2264 POSTING_READ(GEN8_MASTER_IRQ);
2266 /* Find, clear, then process each source of interrupt */
2268 ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl);
2270 if (master_ctl & GEN8_DE_MISC_IRQ) {
2271 tmp = I915_READ(GEN8_DE_MISC_IIR);
2273 I915_WRITE(GEN8_DE_MISC_IIR, tmp);
2275 if (tmp & GEN8_DE_MISC_GSE)
2276 intel_opregion_asle_intr(dev);
2278 DRM_ERROR("Unexpected DE Misc interrupt\n");
2281 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
2284 if (master_ctl & GEN8_DE_PORT_IRQ) {
2285 tmp = I915_READ(GEN8_DE_PORT_IIR);
2287 I915_WRITE(GEN8_DE_PORT_IIR, tmp);
2291 dp_aux_irq_handler(dev);
2293 DRM_ERROR("Unexpected DE Port interrupt\n");
2296 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
2299 for_each_pipe(dev_priv, pipe) {
2300 uint32_t pipe_iir, flip_done = 0, fault_errors = 0;
2302 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2305 pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2308 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
2310 if (pipe_iir & GEN8_PIPE_VBLANK &&
2311 intel_pipe_handle_vblank(dev, pipe))
2312 intel_check_page_flip(dev, pipe);
2315 flip_done = pipe_iir & GEN9_PIPE_PLANE1_FLIP_DONE;
2317 flip_done = pipe_iir & GEN8_PIPE_PRIMARY_FLIP_DONE;
2320 intel_prepare_page_flip(dev, pipe);
2321 intel_finish_page_flip_plane(dev, pipe);
2324 if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
2325 hsw_pipe_crc_irq_handler(dev, pipe);
2327 if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN)
2328 intel_cpu_fifo_underrun_irq_handler(dev_priv,
2333 fault_errors = pipe_iir & GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2335 fault_errors = pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2338 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
2340 pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
2342 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
2345 if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) {
2347 * FIXME(BDW): Assume for now that the new interrupt handling
2348 * scheme also closed the SDE interrupt handling race we've seen
2349 * on older pch-split platforms. But this needs testing.
2351 u32 pch_iir = I915_READ(SDEIIR);
2353 I915_WRITE(SDEIIR, pch_iir);
2355 cpt_irq_handler(dev, pch_iir);
2357 DRM_ERROR("The master control interrupt lied (SDE)!\n");
2361 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2362 POSTING_READ(GEN8_MASTER_IRQ);
2367 static void i915_error_wake_up(struct drm_i915_private *dev_priv,
2368 bool reset_completed)
2370 struct intel_engine_cs *ring;
2374 * Notify all waiters for GPU completion events that reset state has
2375 * been changed, and that they need to restart their wait after
2376 * checking for potential errors (and bail out to drop locks if there is
2377 * a gpu reset pending so that i915_error_work_func can acquire them).
2380 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
2381 for_each_ring(ring, dev_priv, i)
2382 wake_up_all(&ring->irq_queue);
2384 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
2385 wake_up_all(&dev_priv->pending_flip_queue);
2388 * Signal tasks blocked in i915_gem_wait_for_error that the pending
2389 * reset state is cleared.
2391 if (reset_completed)
2392 wake_up_all(&dev_priv->gpu_error.reset_queue);
2396 * i915_error_work_func - do process context error handling work
2397 * @work: work struct
2399 * Fire an error uevent so userspace can see that a hang or error
2402 static void i915_error_work_func(struct work_struct *work)
2404 struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
2406 struct drm_i915_private *dev_priv =
2407 container_of(error, struct drm_i915_private, gpu_error);
2408 struct drm_device *dev = dev_priv->dev;
2409 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2410 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2411 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
2414 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
2417 * Note that there's only one work item which does gpu resets, so we
2418 * need not worry about concurrent gpu resets potentially incrementing
2419 * error->reset_counter twice. We only need to take care of another
2420 * racing irq/hangcheck declaring the gpu dead for a second time. A
2421 * quick check for that is good enough: schedule_work ensures the
2422 * correct ordering between hang detection and this work item, and since
2423 * the reset in-progress bit is only ever set by code outside of this
2424 * work we don't need to worry about any other races.
2426 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
2427 DRM_DEBUG_DRIVER("resetting chip\n");
2428 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
2432 * In most cases it's guaranteed that we get here with an RPM
2433 * reference held, for example because there is a pending GPU
2434 * request that won't finish until the reset is done. This
2435 * isn't the case at least when we get here by doing a
2436 * simulated reset via debugs, so get an RPM reference.
2438 intel_runtime_pm_get(dev_priv);
2440 intel_prepare_reset(dev);
2443 * All state reset _must_ be completed before we update the
2444 * reset counter, for otherwise waiters might miss the reset
2445 * pending state and not properly drop locks, resulting in
2446 * deadlocks with the reset work.
2448 ret = i915_reset(dev);
2450 intel_finish_reset(dev);
2452 intel_runtime_pm_put(dev_priv);
2456 * After all the gem state is reset, increment the reset
2457 * counter and wake up everyone waiting for the reset to
2460 * Since unlock operations are a one-sided barrier only,
2461 * we need to insert a barrier here to order any seqno
2463 * the counter increment.
2465 smp_mb__before_atomic();
2466 atomic_inc(&dev_priv->gpu_error.reset_counter);
2468 kobject_uevent_env(&dev->primary->kdev->kobj,
2469 KOBJ_CHANGE, reset_done_event);
2471 atomic_set_mask(I915_WEDGED, &error->reset_counter);
2475 * Note: The wake_up also serves as a memory barrier so that
2476 * waiters see the update value of the reset counter atomic_t.
2478 i915_error_wake_up(dev_priv, true);
2482 static void i915_report_and_clear_eir(struct drm_device *dev)
2484 struct drm_i915_private *dev_priv = dev->dev_private;
2485 uint32_t instdone[I915_NUM_INSTDONE_REG];
2486 u32 eir = I915_READ(EIR);
2492 pr_err("render error detected, EIR: 0x%08x\n", eir);
2494 i915_get_extra_instdone(dev, instdone);
2497 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2498 u32 ipeir = I915_READ(IPEIR_I965);
2500 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2501 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
2502 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2503 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
2504 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
2505 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
2506 I915_WRITE(IPEIR_I965, ipeir);
2507 POSTING_READ(IPEIR_I965);
2509 if (eir & GM45_ERROR_PAGE_TABLE) {
2510 u32 pgtbl_err = I915_READ(PGTBL_ER);
2511 pr_err("page table error\n");
2512 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
2513 I915_WRITE(PGTBL_ER, pgtbl_err);
2514 POSTING_READ(PGTBL_ER);
2518 if (!IS_GEN2(dev)) {
2519 if (eir & I915_ERROR_PAGE_TABLE) {
2520 u32 pgtbl_err = I915_READ(PGTBL_ER);
2521 pr_err("page table error\n");
2522 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
2523 I915_WRITE(PGTBL_ER, pgtbl_err);
2524 POSTING_READ(PGTBL_ER);
2528 if (eir & I915_ERROR_MEMORY_REFRESH) {
2529 pr_err("memory refresh error:\n");
2530 for_each_pipe(dev_priv, pipe)
2531 pr_err("pipe %c stat: 0x%08x\n",
2532 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
2533 /* pipestat has already been acked */
2535 if (eir & I915_ERROR_INSTRUCTION) {
2536 pr_err("instruction error\n");
2537 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
2538 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2539 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
2540 if (INTEL_INFO(dev)->gen < 4) {
2541 u32 ipeir = I915_READ(IPEIR);
2543 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2544 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
2545 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
2546 I915_WRITE(IPEIR, ipeir);
2547 POSTING_READ(IPEIR);
2549 u32 ipeir = I915_READ(IPEIR_I965);
2551 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2552 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
2553 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
2554 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
2555 I915_WRITE(IPEIR_I965, ipeir);
2556 POSTING_READ(IPEIR_I965);
2560 I915_WRITE(EIR, eir);
2562 eir = I915_READ(EIR);
2565 * some errors might have become stuck,
2568 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2569 I915_WRITE(EMR, I915_READ(EMR) | eir);
2570 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2575 * i915_handle_error - handle an error interrupt
2578 * Do some basic checking of regsiter state at error interrupt time and
2579 * dump it to the syslog. Also call i915_capture_error_state() to make
2580 * sure we get a record and make it available in debugfs. Fire a uevent
2581 * so userspace knows something bad happened (should trigger collection
2582 * of a ring dump etc.).
2584 void i915_handle_error(struct drm_device *dev, bool wedged,
2585 const char *fmt, ...)
2587 struct drm_i915_private *dev_priv = dev->dev_private;
2591 va_start(args, fmt);
2592 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2595 i915_capture_error_state(dev, wedged, error_msg);
2596 i915_report_and_clear_eir(dev);
2599 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
2600 &dev_priv->gpu_error.reset_counter);
2603 * Wakeup waiting processes so that the reset work function
2604 * i915_error_work_func doesn't deadlock trying to grab various
2605 * locks. By bumping the reset counter first, the woken
2606 * processes will see a reset in progress and back off,
2607 * releasing their locks and then wait for the reset completion.
2608 * We must do this for _all_ gpu waiters that might hold locks
2609 * that the reset work needs to acquire.
2611 * Note: The wake_up serves as the required memory barrier to
2612 * ensure that the waiters see the updated value of the reset
2615 i915_error_wake_up(dev_priv, false);
2619 * Our reset work can grab modeset locks (since it needs to reset the
2620 * state of outstanding pagelips). Hence it must not be run on our own
2621 * dev-priv->wq work queue for otherwise the flush_work in the pageflip
2622 * code will deadlock.
2624 schedule_work(&dev_priv->gpu_error.work);
2627 /* Called from drm generic code, passed 'crtc' which
2628 * we use as a pipe index
2630 static int i915_enable_vblank(struct drm_device *dev, int pipe)
2632 struct drm_i915_private *dev_priv = dev->dev_private;
2633 unsigned long irqflags;
2635 if (!i915_pipe_enabled(dev, pipe))
2638 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2639 if (INTEL_INFO(dev)->gen >= 4)
2640 i915_enable_pipestat(dev_priv, pipe,
2641 PIPE_START_VBLANK_INTERRUPT_STATUS);
2643 i915_enable_pipestat(dev_priv, pipe,
2644 PIPE_VBLANK_INTERRUPT_STATUS);
2645 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2650 static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
2652 struct drm_i915_private *dev_priv = dev->dev_private;
2653 unsigned long irqflags;
2654 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
2655 DE_PIPE_VBLANK(pipe);
2657 if (!i915_pipe_enabled(dev, pipe))
2660 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2661 ironlake_enable_display_irq(dev_priv, bit);
2662 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2667 static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
2669 struct drm_i915_private *dev_priv = dev->dev_private;
2670 unsigned long irqflags;
2672 if (!i915_pipe_enabled(dev, pipe))
2675 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2676 i915_enable_pipestat(dev_priv, pipe,
2677 PIPE_START_VBLANK_INTERRUPT_STATUS);
2678 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2683 static int gen8_enable_vblank(struct drm_device *dev, int pipe)
2685 struct drm_i915_private *dev_priv = dev->dev_private;
2686 unsigned long irqflags;
2688 if (!i915_pipe_enabled(dev, pipe))
2691 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2692 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
2693 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2694 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
2695 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2699 /* Called from drm generic code, passed 'crtc' which
2700 * we use as a pipe index
2702 static void i915_disable_vblank(struct drm_device *dev, int pipe)
2704 struct drm_i915_private *dev_priv = dev->dev_private;
2705 unsigned long irqflags;
2707 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2708 i915_disable_pipestat(dev_priv, pipe,
2709 PIPE_VBLANK_INTERRUPT_STATUS |
2710 PIPE_START_VBLANK_INTERRUPT_STATUS);
2711 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2714 static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
2716 struct drm_i915_private *dev_priv = dev->dev_private;
2717 unsigned long irqflags;
2718 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
2719 DE_PIPE_VBLANK(pipe);
2721 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2722 ironlake_disable_display_irq(dev_priv, bit);
2723 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2726 static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
2728 struct drm_i915_private *dev_priv = dev->dev_private;
2729 unsigned long irqflags;
2731 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2732 i915_disable_pipestat(dev_priv, pipe,
2733 PIPE_START_VBLANK_INTERRUPT_STATUS);
2734 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2737 static void gen8_disable_vblank(struct drm_device *dev, int pipe)
2739 struct drm_i915_private *dev_priv = dev->dev_private;
2740 unsigned long irqflags;
2742 if (!i915_pipe_enabled(dev, pipe))
2745 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2746 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
2747 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2748 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
2749 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2753 ring_last_seqno(struct intel_engine_cs *ring)
2755 return list_entry(ring->request_list.prev,
2756 struct drm_i915_gem_request, list)->seqno;
2760 ring_idle(struct intel_engine_cs *ring, u32 seqno)
2762 return (list_empty(&ring->request_list) ||
2763 i915_seqno_passed(seqno, ring_last_seqno(ring)));
2767 ipehr_is_semaphore_wait(struct drm_device *dev, u32 ipehr)
2769 if (INTEL_INFO(dev)->gen >= 8) {
2770 return (ipehr >> 23) == 0x1c;
2772 ipehr &= ~MI_SEMAPHORE_SYNC_MASK;
2773 return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE |
2774 MI_SEMAPHORE_REGISTER);
2778 static struct intel_engine_cs *
2779 semaphore_wait_to_signaller_ring(struct intel_engine_cs *ring, u32 ipehr, u64 offset)
2781 struct drm_i915_private *dev_priv = ring->dev->dev_private;
2782 struct intel_engine_cs *signaller;
2785 if (INTEL_INFO(dev_priv->dev)->gen >= 8) {
2786 for_each_ring(signaller, dev_priv, i) {
2787 if (ring == signaller)
2790 if (offset == signaller->semaphore.signal_ggtt[ring->id])
2794 u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK;
2796 for_each_ring(signaller, dev_priv, i) {
2797 if(ring == signaller)
2800 if (sync_bits == signaller->semaphore.mbox.wait[ring->id])
2805 DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x, offset 0x%016llx\n",
2806 ring->id, ipehr, offset);
2811 static struct intel_engine_cs *
2812 semaphore_waits_for(struct intel_engine_cs *ring, u32 *seqno)
2814 struct drm_i915_private *dev_priv = ring->dev->dev_private;
2815 u32 cmd, ipehr, head;
2819 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
2820 if (!ipehr_is_semaphore_wait(ring->dev, ipehr))
2824 * HEAD is likely pointing to the dword after the actual command,
2825 * so scan backwards until we find the MBOX. But limit it to just 3
2826 * or 4 dwords depending on the semaphore wait command size.
2827 * Note that we don't care about ACTHD here since that might
2828 * point at at batch, and semaphores are always emitted into the
2829 * ringbuffer itself.
2831 head = I915_READ_HEAD(ring) & HEAD_ADDR;
2832 backwards = (INTEL_INFO(ring->dev)->gen >= 8) ? 5 : 4;
2834 for (i = backwards; i; --i) {
2836 * Be paranoid and presume the hw has gone off into the wild -
2837 * our ring is smaller than what the hardware (and hence
2838 * HEAD_ADDR) allows. Also handles wrap-around.
2840 head &= ring->buffer->size - 1;
2842 /* This here seems to blow up */
2843 cmd = ioread32(ring->buffer->virtual_start + head);
2853 *seqno = ioread32(ring->buffer->virtual_start + head + 4) + 1;
2854 if (INTEL_INFO(ring->dev)->gen >= 8) {
2855 offset = ioread32(ring->buffer->virtual_start + head + 12);
2857 offset = ioread32(ring->buffer->virtual_start + head + 8);
2859 return semaphore_wait_to_signaller_ring(ring, ipehr, offset);
2862 static int semaphore_passed(struct intel_engine_cs *ring)
2864 struct drm_i915_private *dev_priv = ring->dev->dev_private;
2865 struct intel_engine_cs *signaller;
2868 ring->hangcheck.deadlock++;
2870 signaller = semaphore_waits_for(ring, &seqno);
2871 if (signaller == NULL)
2874 /* Prevent pathological recursion due to driver bugs */
2875 if (signaller->hangcheck.deadlock >= I915_NUM_RINGS)
2878 if (i915_seqno_passed(signaller->get_seqno(signaller, false), seqno))
2881 /* cursory check for an unkickable deadlock */
2882 if (I915_READ_CTL(signaller) & RING_WAIT_SEMAPHORE &&
2883 semaphore_passed(signaller) < 0)
2889 static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2891 struct intel_engine_cs *ring;
2894 for_each_ring(ring, dev_priv, i)
2895 ring->hangcheck.deadlock = 0;
2898 static enum intel_ring_hangcheck_action
2899 ring_stuck(struct intel_engine_cs *ring, u64 acthd)
2901 struct drm_device *dev = ring->dev;
2902 struct drm_i915_private *dev_priv = dev->dev_private;
2905 if (acthd != ring->hangcheck.acthd) {
2906 if (acthd > ring->hangcheck.max_acthd) {
2907 ring->hangcheck.max_acthd = acthd;
2908 return HANGCHECK_ACTIVE;
2911 return HANGCHECK_ACTIVE_LOOP;
2915 return HANGCHECK_HUNG;
2917 /* Is the chip hanging on a WAIT_FOR_EVENT?
2918 * If so we can simply poke the RB_WAIT bit
2919 * and break the hang. This should work on
2920 * all but the second generation chipsets.
2922 tmp = I915_READ_CTL(ring);
2923 if (tmp & RING_WAIT) {
2924 i915_handle_error(dev, false,
2925 "Kicking stuck wait on %s",
2927 I915_WRITE_CTL(ring, tmp);
2928 return HANGCHECK_KICK;
2931 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
2932 switch (semaphore_passed(ring)) {
2934 return HANGCHECK_HUNG;
2936 i915_handle_error(dev, false,
2937 "Kicking stuck semaphore on %s",
2939 I915_WRITE_CTL(ring, tmp);
2940 return HANGCHECK_KICK;
2942 return HANGCHECK_WAIT;
2946 return HANGCHECK_HUNG;
2950 * This is called when the chip hasn't reported back with completed
2951 * batchbuffers in a long time. We keep track per ring seqno progress and
2952 * if there are no progress, hangcheck score for that ring is increased.
2953 * Further, acthd is inspected to see if the ring is stuck. On stuck case
2954 * we kick the ring. If we see no progress on three subsequent calls
2955 * we assume chip is wedged and try to fix it by resetting the chip.
2957 static void i915_hangcheck_elapsed(unsigned long data)
2959 struct drm_device *dev = (struct drm_device *)data;
2960 struct drm_i915_private *dev_priv = dev->dev_private;
2961 struct intel_engine_cs *ring;
2963 int busy_count = 0, rings_hung = 0;
2964 bool stuck[I915_NUM_RINGS] = { 0 };
2969 if (!i915.enable_hangcheck)
2972 for_each_ring(ring, dev_priv, i) {
2977 semaphore_clear_deadlocks(dev_priv);
2979 seqno = ring->get_seqno(ring, false);
2980 acthd = intel_ring_get_active_head(ring);
2982 if (ring->hangcheck.seqno == seqno) {
2983 if (ring_idle(ring, seqno)) {
2984 ring->hangcheck.action = HANGCHECK_IDLE;
2986 if (waitqueue_active(&ring->irq_queue)) {
2987 /* Issue a wake-up to catch stuck h/w. */
2988 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
2989 if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
2990 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
2993 DRM_INFO("Fake missed irq on %s\n",
2995 wake_up_all(&ring->irq_queue);
2997 /* Safeguard against driver failure */
2998 ring->hangcheck.score += BUSY;
3002 /* We always increment the hangcheck score
3003 * if the ring is busy and still processing
3004 * the same request, so that no single request
3005 * can run indefinitely (such as a chain of
3006 * batches). The only time we do not increment
3007 * the hangcheck score on this ring, if this
3008 * ring is in a legitimate wait for another
3009 * ring. In that case the waiting ring is a
3010 * victim and we want to be sure we catch the
3011 * right culprit. Then every time we do kick
3012 * the ring, add a small increment to the
3013 * score so that we can catch a batch that is
3014 * being repeatedly kicked and so responsible
3015 * for stalling the machine.
3017 ring->hangcheck.action = ring_stuck(ring,
3020 switch (ring->hangcheck.action) {
3021 case HANGCHECK_IDLE:
3022 case HANGCHECK_WAIT:
3023 case HANGCHECK_ACTIVE:
3025 case HANGCHECK_ACTIVE_LOOP:
3026 ring->hangcheck.score += BUSY;
3028 case HANGCHECK_KICK:
3029 ring->hangcheck.score += KICK;
3031 case HANGCHECK_HUNG:
3032 ring->hangcheck.score += HUNG;
3038 ring->hangcheck.action = HANGCHECK_ACTIVE;
3040 /* Gradually reduce the count so that we catch DoS
3041 * attempts across multiple batches.
3043 if (ring->hangcheck.score > 0)
3044 ring->hangcheck.score--;
3046 ring->hangcheck.acthd = ring->hangcheck.max_acthd = 0;
3049 ring->hangcheck.seqno = seqno;
3050 ring->hangcheck.acthd = acthd;
3054 for_each_ring(ring, dev_priv, i) {
3055 if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
3056 DRM_INFO("%s on %s\n",
3057 stuck[i] ? "stuck" : "no progress",
3064 return i915_handle_error(dev, true, "Ring hung");
3067 /* Reset timer case chip hangs without another request
3069 i915_queue_hangcheck(dev);
3072 void i915_queue_hangcheck(struct drm_device *dev)
3074 struct drm_i915_private *dev_priv = dev->dev_private;
3075 struct timer_list *timer = &dev_priv->gpu_error.hangcheck_timer;
3077 if (!i915.enable_hangcheck)
3080 /* Don't continually defer the hangcheck, but make sure it is active */
3081 if (timer_pending(timer))
3084 round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
3087 static void ibx_irq_reset(struct drm_device *dev)
3089 struct drm_i915_private *dev_priv = dev->dev_private;
3091 if (HAS_PCH_NOP(dev))
3094 GEN5_IRQ_RESET(SDE);
3096 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3097 I915_WRITE(SERR_INT, 0xffffffff);
3101 * SDEIER is also touched by the interrupt handler to work around missed PCH
3102 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3103 * instead we unconditionally enable all PCH interrupt sources here, but then
3104 * only unmask them as needed with SDEIMR.
3106 * This function needs to be called before interrupts are enabled.
3108 static void ibx_irq_pre_postinstall(struct drm_device *dev)
3110 struct drm_i915_private *dev_priv = dev->dev_private;
3112 if (HAS_PCH_NOP(dev))
3115 WARN_ON(I915_READ(SDEIER) != 0);
3116 I915_WRITE(SDEIER, 0xffffffff);
3117 POSTING_READ(SDEIER);
3120 static void gen5_gt_irq_reset(struct drm_device *dev)
3122 struct drm_i915_private *dev_priv = dev->dev_private;
3125 if (INTEL_INFO(dev)->gen >= 6)
3126 GEN5_IRQ_RESET(GEN6_PM);
3131 static void ironlake_irq_reset(struct drm_device *dev)
3133 struct drm_i915_private *dev_priv = dev->dev_private;
3135 I915_WRITE(HWSTAM, 0xffffffff);
3139 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
3141 gen5_gt_irq_reset(dev);
3146 static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3150 I915_WRITE(PORT_HOTPLUG_EN, 0);
3151 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3153 for_each_pipe(dev_priv, pipe)
3154 I915_WRITE(PIPESTAT(pipe), 0xffff);
3156 GEN5_IRQ_RESET(VLV_);
3159 static void valleyview_irq_preinstall(struct drm_device *dev)
3161 struct drm_i915_private *dev_priv = dev->dev_private;
3164 I915_WRITE(VLV_IMR, 0);
3165 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
3166 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
3167 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
3169 gen5_gt_irq_reset(dev);
3171 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3173 vlv_display_irq_reset(dev_priv);
3176 static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3178 GEN8_IRQ_RESET_NDX(GT, 0);
3179 GEN8_IRQ_RESET_NDX(GT, 1);
3180 GEN8_IRQ_RESET_NDX(GT, 2);
3181 GEN8_IRQ_RESET_NDX(GT, 3);
3184 static void gen8_irq_reset(struct drm_device *dev)
3186 struct drm_i915_private *dev_priv = dev->dev_private;
3189 I915_WRITE(GEN8_MASTER_IRQ, 0);
3190 POSTING_READ(GEN8_MASTER_IRQ);
3192 gen8_gt_irq_reset(dev_priv);
3194 for_each_pipe(dev_priv, pipe)
3195 if (intel_display_power_is_enabled(dev_priv,
3196 POWER_DOMAIN_PIPE(pipe)))
3197 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
3199 GEN5_IRQ_RESET(GEN8_DE_PORT_);
3200 GEN5_IRQ_RESET(GEN8_DE_MISC_);
3201 GEN5_IRQ_RESET(GEN8_PCU_);
3206 void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv)
3208 uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
3210 spin_lock_irq(&dev_priv->irq_lock);
3211 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_B, dev_priv->de_irq_mask[PIPE_B],
3212 ~dev_priv->de_irq_mask[PIPE_B] | extra_ier);
3213 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_C, dev_priv->de_irq_mask[PIPE_C],
3214 ~dev_priv->de_irq_mask[PIPE_C] | extra_ier);
3215 spin_unlock_irq(&dev_priv->irq_lock);
3218 static void cherryview_irq_preinstall(struct drm_device *dev)
3220 struct drm_i915_private *dev_priv = dev->dev_private;
3222 I915_WRITE(GEN8_MASTER_IRQ, 0);
3223 POSTING_READ(GEN8_MASTER_IRQ);
3225 gen8_gt_irq_reset(dev_priv);
3227 GEN5_IRQ_RESET(GEN8_PCU_);
3229 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3231 vlv_display_irq_reset(dev_priv);
3234 static void ibx_hpd_irq_setup(struct drm_device *dev)
3236 struct drm_i915_private *dev_priv = dev->dev_private;
3237 struct intel_encoder *intel_encoder;
3238 u32 hotplug_irqs, hotplug, enabled_irqs = 0;
3240 if (HAS_PCH_IBX(dev)) {
3241 hotplug_irqs = SDE_HOTPLUG_MASK;
3242 for_each_intel_encoder(dev, intel_encoder)
3243 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
3244 enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
3246 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
3247 for_each_intel_encoder(dev, intel_encoder)
3248 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
3249 enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
3252 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3255 * Enable digital hotplug on the PCH, and configure the DP short pulse
3256 * duration to 2ms (which is the minimum in the Display Port spec)
3258 * This register is the same on all known PCH chips.
3260 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3261 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
3262 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3263 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3264 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
3265 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3268 static void ibx_irq_postinstall(struct drm_device *dev)
3270 struct drm_i915_private *dev_priv = dev->dev_private;
3273 if (HAS_PCH_NOP(dev))
3276 if (HAS_PCH_IBX(dev))
3277 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
3279 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
3281 GEN5_ASSERT_IIR_IS_ZERO(SDEIIR);
3282 I915_WRITE(SDEIMR, ~mask);
3285 static void gen5_gt_irq_postinstall(struct drm_device *dev)
3287 struct drm_i915_private *dev_priv = dev->dev_private;
3288 u32 pm_irqs, gt_irqs;
3290 pm_irqs = gt_irqs = 0;
3292 dev_priv->gt_irq_mask = ~0;
3293 if (HAS_L3_DPF(dev)) {
3294 /* L3 parity interrupt is always unmasked. */
3295 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
3296 gt_irqs |= GT_PARITY_ERROR(dev);
3299 gt_irqs |= GT_RENDER_USER_INTERRUPT;
3301 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
3302 ILK_BSD_USER_INTERRUPT;
3304 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3307 GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
3309 if (INTEL_INFO(dev)->gen >= 6) {
3310 pm_irqs |= dev_priv->pm_rps_events;
3313 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
3315 dev_priv->pm_irq_mask = 0xffffffff;
3316 GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs);
3320 static int ironlake_irq_postinstall(struct drm_device *dev)
3322 struct drm_i915_private *dev_priv = dev->dev_private;
3323 u32 display_mask, extra_mask;
3325 if (INTEL_INFO(dev)->gen >= 7) {
3326 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
3327 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
3328 DE_PLANEB_FLIP_DONE_IVB |
3329 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
3330 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
3331 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB);
3333 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
3334 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
3336 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
3338 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3339 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN;
3342 dev_priv->irq_mask = ~display_mask;
3344 I915_WRITE(HWSTAM, 0xeffe);
3346 ibx_irq_pre_postinstall(dev);
3348 GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
3350 gen5_gt_irq_postinstall(dev);
3352 ibx_irq_postinstall(dev);
3354 if (IS_IRONLAKE_M(dev)) {
3355 /* Enable PCU event interrupts
3357 * spinlocking not required here for correctness since interrupt
3358 * setup is guaranteed to run in single-threaded context. But we
3359 * need it to make the assert_spin_locked happy. */
3360 spin_lock_irq(&dev_priv->irq_lock);
3361 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
3362 spin_unlock_irq(&dev_priv->irq_lock);
3368 static void valleyview_display_irqs_install(struct drm_i915_private *dev_priv)
3374 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3375 PIPE_FIFO_UNDERRUN_STATUS;
3377 for_each_pipe(dev_priv, pipe)
3378 I915_WRITE(PIPESTAT(pipe), pipestat_mask);
3379 POSTING_READ(PIPESTAT(PIPE_A));
3381 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3382 PIPE_CRC_DONE_INTERRUPT_STATUS;
3384 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3385 for_each_pipe(dev_priv, pipe)
3386 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
3388 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3389 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3390 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
3391 if (IS_CHERRYVIEW(dev_priv))
3392 iir_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
3393 dev_priv->irq_mask &= ~iir_mask;
3395 I915_WRITE(VLV_IIR, iir_mask);
3396 I915_WRITE(VLV_IIR, iir_mask);
3397 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3398 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3399 POSTING_READ(VLV_IMR);
3402 static void valleyview_display_irqs_uninstall(struct drm_i915_private *dev_priv)
3408 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3409 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3410 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
3411 if (IS_CHERRYVIEW(dev_priv))
3412 iir_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
3414 dev_priv->irq_mask |= iir_mask;
3415 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3416 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3417 I915_WRITE(VLV_IIR, iir_mask);
3418 I915_WRITE(VLV_IIR, iir_mask);
3419 POSTING_READ(VLV_IIR);
3421 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3422 PIPE_CRC_DONE_INTERRUPT_STATUS;
3424 i915_disable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3425 for_each_pipe(dev_priv, pipe)
3426 i915_disable_pipestat(dev_priv, pipe, pipestat_mask);
3428 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3429 PIPE_FIFO_UNDERRUN_STATUS;
3431 for_each_pipe(dev_priv, pipe)
3432 I915_WRITE(PIPESTAT(pipe), pipestat_mask);
3433 POSTING_READ(PIPESTAT(PIPE_A));
3436 void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3438 assert_spin_locked(&dev_priv->irq_lock);
3440 if (dev_priv->display_irqs_enabled)
3443 dev_priv->display_irqs_enabled = true;
3445 if (intel_irqs_enabled(dev_priv))
3446 valleyview_display_irqs_install(dev_priv);
3449 void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3451 assert_spin_locked(&dev_priv->irq_lock);
3453 if (!dev_priv->display_irqs_enabled)
3456 dev_priv->display_irqs_enabled = false;
3458 if (intel_irqs_enabled(dev_priv))
3459 valleyview_display_irqs_uninstall(dev_priv);
3462 static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
3464 dev_priv->irq_mask = ~0;
3466 I915_WRITE(PORT_HOTPLUG_EN, 0);
3467 POSTING_READ(PORT_HOTPLUG_EN);
3469 I915_WRITE(VLV_IIR, 0xffffffff);
3470 I915_WRITE(VLV_IIR, 0xffffffff);
3471 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3472 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3473 POSTING_READ(VLV_IMR);
3475 /* Interrupt setup is already guaranteed to be single-threaded, this is
3476 * just to make the assert_spin_locked check happy. */
3477 spin_lock_irq(&dev_priv->irq_lock);
3478 if (dev_priv->display_irqs_enabled)
3479 valleyview_display_irqs_install(dev_priv);
3480 spin_unlock_irq(&dev_priv->irq_lock);
3483 static int valleyview_irq_postinstall(struct drm_device *dev)
3485 struct drm_i915_private *dev_priv = dev->dev_private;
3487 vlv_display_irq_postinstall(dev_priv);
3489 gen5_gt_irq_postinstall(dev);
3491 /* ack & enable invalid PTE error interrupts */
3492 #if 0 /* FIXME: add support to irq handler for checking these bits */
3493 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3494 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
3497 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
3502 static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3504 /* These are interrupts we'll toggle with the ring mask register */
3505 uint32_t gt_interrupts[] = {
3506 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
3507 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
3508 GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
3509 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3510 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
3511 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3512 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3513 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3514 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
3516 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3517 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
3520 dev_priv->pm_irq_mask = 0xffffffff;
3521 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3522 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
3523 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_irq_mask, dev_priv->pm_rps_events);
3524 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
3527 static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3529 uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
3530 uint32_t de_pipe_enables;
3532 u32 aux_en = GEN8_AUX_CHANNEL_A;
3534 if (IS_GEN9(dev_priv)) {
3535 de_pipe_masked |= GEN9_PIPE_PLANE1_FLIP_DONE |
3536 GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
3537 aux_en |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
3540 de_pipe_masked |= GEN8_PIPE_PRIMARY_FLIP_DONE |
3541 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
3543 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3544 GEN8_PIPE_FIFO_UNDERRUN;
3546 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3547 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3548 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
3550 for_each_pipe(dev_priv, pipe)
3551 if (intel_display_power_is_enabled(dev_priv,
3552 POWER_DOMAIN_PIPE(pipe)))
3553 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3554 dev_priv->de_irq_mask[pipe],
3557 GEN5_IRQ_INIT(GEN8_DE_PORT_, ~aux_en, aux_en);
3560 static int gen8_irq_postinstall(struct drm_device *dev)
3562 struct drm_i915_private *dev_priv = dev->dev_private;
3564 ibx_irq_pre_postinstall(dev);
3566 gen8_gt_irq_postinstall(dev_priv);
3567 gen8_de_irq_postinstall(dev_priv);
3569 ibx_irq_postinstall(dev);
3571 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
3572 POSTING_READ(GEN8_MASTER_IRQ);
3577 static int cherryview_irq_postinstall(struct drm_device *dev)
3579 struct drm_i915_private *dev_priv = dev->dev_private;
3581 vlv_display_irq_postinstall(dev_priv);
3583 gen8_gt_irq_postinstall(dev_priv);
3585 I915_WRITE(GEN8_MASTER_IRQ, MASTER_INTERRUPT_ENABLE);
3586 POSTING_READ(GEN8_MASTER_IRQ);
3591 static void gen8_irq_uninstall(struct drm_device *dev)
3593 struct drm_i915_private *dev_priv = dev->dev_private;
3598 gen8_irq_reset(dev);
3601 static void vlv_display_irq_uninstall(struct drm_i915_private *dev_priv)
3603 /* Interrupt setup is already guaranteed to be single-threaded, this is
3604 * just to make the assert_spin_locked check happy. */
3605 spin_lock_irq(&dev_priv->irq_lock);
3606 if (dev_priv->display_irqs_enabled)
3607 valleyview_display_irqs_uninstall(dev_priv);
3608 spin_unlock_irq(&dev_priv->irq_lock);
3610 vlv_display_irq_reset(dev_priv);
3612 dev_priv->irq_mask = 0;
3615 static void valleyview_irq_uninstall(struct drm_device *dev)
3617 struct drm_i915_private *dev_priv = dev->dev_private;
3622 I915_WRITE(VLV_MASTER_IER, 0);
3624 gen5_gt_irq_reset(dev);
3626 I915_WRITE(HWSTAM, 0xffffffff);
3628 vlv_display_irq_uninstall(dev_priv);
3631 static void cherryview_irq_uninstall(struct drm_device *dev)
3633 struct drm_i915_private *dev_priv = dev->dev_private;
3638 I915_WRITE(GEN8_MASTER_IRQ, 0);
3639 POSTING_READ(GEN8_MASTER_IRQ);
3641 gen8_gt_irq_reset(dev_priv);
3643 GEN5_IRQ_RESET(GEN8_PCU_);
3645 vlv_display_irq_uninstall(dev_priv);
3648 static void ironlake_irq_uninstall(struct drm_device *dev)
3650 struct drm_i915_private *dev_priv = dev->dev_private;
3655 ironlake_irq_reset(dev);
3658 static void i8xx_irq_preinstall(struct drm_device * dev)
3660 struct drm_i915_private *dev_priv = dev->dev_private;
3663 for_each_pipe(dev_priv, pipe)
3664 I915_WRITE(PIPESTAT(pipe), 0);
3665 I915_WRITE16(IMR, 0xffff);
3666 I915_WRITE16(IER, 0x0);
3667 POSTING_READ16(IER);
3670 static int i8xx_irq_postinstall(struct drm_device *dev)
3672 struct drm_i915_private *dev_priv = dev->dev_private;
3675 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3677 /* Unmask the interrupts that we always want on. */
3678 dev_priv->irq_mask =
3679 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3680 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3681 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3682 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3683 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3684 I915_WRITE16(IMR, dev_priv->irq_mask);
3687 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3688 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3689 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3690 I915_USER_INTERRUPT);
3691 POSTING_READ16(IER);
3693 /* Interrupt setup is already guaranteed to be single-threaded, this is
3694 * just to make the assert_spin_locked check happy. */
3695 spin_lock_irq(&dev_priv->irq_lock);
3696 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3697 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
3698 spin_unlock_irq(&dev_priv->irq_lock);
3704 * Returns true when a page flip has completed.
3706 static bool i8xx_handle_vblank(struct drm_device *dev,
3707 int plane, int pipe, u32 iir)
3709 struct drm_i915_private *dev_priv = dev->dev_private;
3710 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
3712 if (!intel_pipe_handle_vblank(dev, pipe))
3715 if ((iir & flip_pending) == 0)
3716 goto check_page_flip;
3718 intel_prepare_page_flip(dev, plane);
3720 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3721 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3722 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3723 * the flip is completed (no longer pending). Since this doesn't raise
3724 * an interrupt per se, we watch for the change at vblank.
3726 if (I915_READ16(ISR) & flip_pending)
3727 goto check_page_flip;
3729 intel_finish_page_flip(dev, pipe);
3733 intel_check_page_flip(dev, pipe);
3737 static irqreturn_t i8xx_irq_handler(int irq, void *arg)
3739 struct drm_device *dev = arg;
3740 struct drm_i915_private *dev_priv = dev->dev_private;
3745 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3746 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
3748 iir = I915_READ16(IIR);
3752 while (iir & ~flip_mask) {
3753 /* Can't rely on pipestat interrupt bit in iir as it might
3754 * have been cleared after the pipestat interrupt was received.
3755 * It doesn't set the bit in iir again, but it still produces
3756 * interrupts (for non-MSI).
3758 spin_lock(&dev_priv->irq_lock);
3759 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3760 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
3762 for_each_pipe(dev_priv, pipe) {
3763 int reg = PIPESTAT(pipe);
3764 pipe_stats[pipe] = I915_READ(reg);
3767 * Clear the PIPE*STAT regs before the IIR
3769 if (pipe_stats[pipe] & 0x8000ffff)
3770 I915_WRITE(reg, pipe_stats[pipe]);
3772 spin_unlock(&dev_priv->irq_lock);
3774 I915_WRITE16(IIR, iir & ~flip_mask);
3775 new_iir = I915_READ16(IIR); /* Flush posted writes */
3777 if (iir & I915_USER_INTERRUPT)
3778 notify_ring(dev, &dev_priv->ring[RCS]);
3780 for_each_pipe(dev_priv, pipe) {
3785 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
3786 i8xx_handle_vblank(dev, plane, pipe, iir))
3787 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
3789 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
3790 i9xx_pipe_crc_irq_handler(dev, pipe);
3792 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3793 intel_cpu_fifo_underrun_irq_handler(dev_priv,
3803 static void i8xx_irq_uninstall(struct drm_device * dev)
3805 struct drm_i915_private *dev_priv = dev->dev_private;
3808 for_each_pipe(dev_priv, pipe) {
3809 /* Clear enable bits; then clear status bits */
3810 I915_WRITE(PIPESTAT(pipe), 0);
3811 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3813 I915_WRITE16(IMR, 0xffff);
3814 I915_WRITE16(IER, 0x0);
3815 I915_WRITE16(IIR, I915_READ16(IIR));
3818 static void i915_irq_preinstall(struct drm_device * dev)
3820 struct drm_i915_private *dev_priv = dev->dev_private;
3823 if (I915_HAS_HOTPLUG(dev)) {
3824 I915_WRITE(PORT_HOTPLUG_EN, 0);
3825 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3828 I915_WRITE16(HWSTAM, 0xeffe);
3829 for_each_pipe(dev_priv, pipe)
3830 I915_WRITE(PIPESTAT(pipe), 0);
3831 I915_WRITE(IMR, 0xffffffff);
3832 I915_WRITE(IER, 0x0);
3836 static int i915_irq_postinstall(struct drm_device *dev)
3838 struct drm_i915_private *dev_priv = dev->dev_private;
3841 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3843 /* Unmask the interrupts that we always want on. */
3844 dev_priv->irq_mask =
3845 ~(I915_ASLE_INTERRUPT |
3846 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3847 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3848 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3849 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3850 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3853 I915_ASLE_INTERRUPT |
3854 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3855 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3856 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3857 I915_USER_INTERRUPT;
3859 if (I915_HAS_HOTPLUG(dev)) {
3860 I915_WRITE(PORT_HOTPLUG_EN, 0);
3861 POSTING_READ(PORT_HOTPLUG_EN);
3863 /* Enable in IER... */
3864 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
3865 /* and unmask in IMR */
3866 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
3869 I915_WRITE(IMR, dev_priv->irq_mask);
3870 I915_WRITE(IER, enable_mask);
3873 i915_enable_asle_pipestat(dev);
3875 /* Interrupt setup is already guaranteed to be single-threaded, this is
3876 * just to make the assert_spin_locked check happy. */
3877 spin_lock_irq(&dev_priv->irq_lock);
3878 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3879 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
3880 spin_unlock_irq(&dev_priv->irq_lock);
3886 * Returns true when a page flip has completed.
3888 static bool i915_handle_vblank(struct drm_device *dev,
3889 int plane, int pipe, u32 iir)
3891 struct drm_i915_private *dev_priv = dev->dev_private;
3892 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
3894 if (!intel_pipe_handle_vblank(dev, pipe))
3897 if ((iir & flip_pending) == 0)
3898 goto check_page_flip;
3900 intel_prepare_page_flip(dev, plane);
3902 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3903 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3904 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3905 * the flip is completed (no longer pending). Since this doesn't raise
3906 * an interrupt per se, we watch for the change at vblank.
3908 if (I915_READ(ISR) & flip_pending)
3909 goto check_page_flip;
3911 intel_finish_page_flip(dev, pipe);
3915 intel_check_page_flip(dev, pipe);
3919 static irqreturn_t i915_irq_handler(int irq, void *arg)
3921 struct drm_device *dev = arg;
3922 struct drm_i915_private *dev_priv = dev->dev_private;
3923 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
3925 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3926 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
3927 int pipe, ret = IRQ_NONE;
3929 iir = I915_READ(IIR);
3931 bool irq_received = (iir & ~flip_mask) != 0;
3932 bool blc_event = false;
3934 /* Can't rely on pipestat interrupt bit in iir as it might
3935 * have been cleared after the pipestat interrupt was received.
3936 * It doesn't set the bit in iir again, but it still produces
3937 * interrupts (for non-MSI).
3939 spin_lock(&dev_priv->irq_lock);
3940 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3941 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
3943 for_each_pipe(dev_priv, pipe) {
3944 int reg = PIPESTAT(pipe);
3945 pipe_stats[pipe] = I915_READ(reg);
3947 /* Clear the PIPE*STAT regs before the IIR */
3948 if (pipe_stats[pipe] & 0x8000ffff) {
3949 I915_WRITE(reg, pipe_stats[pipe]);
3950 irq_received = true;
3953 spin_unlock(&dev_priv->irq_lock);
3958 /* Consume port. Then clear IIR or we'll miss events */
3959 if (I915_HAS_HOTPLUG(dev) &&
3960 iir & I915_DISPLAY_PORT_INTERRUPT)
3961 i9xx_hpd_irq_handler(dev);
3963 I915_WRITE(IIR, iir & ~flip_mask);
3964 new_iir = I915_READ(IIR); /* Flush posted writes */
3966 if (iir & I915_USER_INTERRUPT)
3967 notify_ring(dev, &dev_priv->ring[RCS]);
3969 for_each_pipe(dev_priv, pipe) {
3974 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
3975 i915_handle_vblank(dev, plane, pipe, iir))
3976 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
3978 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3981 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
3982 i9xx_pipe_crc_irq_handler(dev, pipe);
3984 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3985 intel_cpu_fifo_underrun_irq_handler(dev_priv,
3989 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3990 intel_opregion_asle_intr(dev);
3992 /* With MSI, interrupts are only generated when iir
3993 * transitions from zero to nonzero. If another bit got
3994 * set while we were handling the existing iir bits, then
3995 * we would never get another interrupt.
3997 * This is fine on non-MSI as well, as if we hit this path
3998 * we avoid exiting the interrupt handler only to generate
4001 * Note that for MSI this could cause a stray interrupt report
4002 * if an interrupt landed in the time between writing IIR and
4003 * the posting read. This should be rare enough to never
4004 * trigger the 99% of 100,000 interrupts test for disabling
4009 } while (iir & ~flip_mask);
4014 static void i915_irq_uninstall(struct drm_device * dev)
4016 struct drm_i915_private *dev_priv = dev->dev_private;
4019 if (I915_HAS_HOTPLUG(dev)) {
4020 I915_WRITE(PORT_HOTPLUG_EN, 0);
4021 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4024 I915_WRITE16(HWSTAM, 0xffff);
4025 for_each_pipe(dev_priv, pipe) {
4026 /* Clear enable bits; then clear status bits */
4027 I915_WRITE(PIPESTAT(pipe), 0);
4028 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4030 I915_WRITE(IMR, 0xffffffff);
4031 I915_WRITE(IER, 0x0);
4033 I915_WRITE(IIR, I915_READ(IIR));
4036 static void i965_irq_preinstall(struct drm_device * dev)
4038 struct drm_i915_private *dev_priv = dev->dev_private;
4041 I915_WRITE(PORT_HOTPLUG_EN, 0);
4042 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4044 I915_WRITE(HWSTAM, 0xeffe);
4045 for_each_pipe(dev_priv, pipe)
4046 I915_WRITE(PIPESTAT(pipe), 0);
4047 I915_WRITE(IMR, 0xffffffff);
4048 I915_WRITE(IER, 0x0);
4052 static int i965_irq_postinstall(struct drm_device *dev)
4054 struct drm_i915_private *dev_priv = dev->dev_private;
4058 /* Unmask the interrupts that we always want on. */
4059 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
4060 I915_DISPLAY_PORT_INTERRUPT |
4061 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4062 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4063 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4064 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
4065 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
4067 enable_mask = ~dev_priv->irq_mask;
4068 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4069 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
4070 enable_mask |= I915_USER_INTERRUPT;
4073 enable_mask |= I915_BSD_USER_INTERRUPT;
4075 /* Interrupt setup is already guaranteed to be single-threaded, this is
4076 * just to make the assert_spin_locked check happy. */
4077 spin_lock_irq(&dev_priv->irq_lock);
4078 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4079 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4080 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
4081 spin_unlock_irq(&dev_priv->irq_lock);
4084 * Enable some error detection, note the instruction error mask
4085 * bit is reserved, so we leave it masked.
4088 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4089 GM45_ERROR_MEM_PRIV |
4090 GM45_ERROR_CP_PRIV |
4091 I915_ERROR_MEMORY_REFRESH);
4093 error_mask = ~(I915_ERROR_PAGE_TABLE |
4094 I915_ERROR_MEMORY_REFRESH);
4096 I915_WRITE(EMR, error_mask);
4098 I915_WRITE(IMR, dev_priv->irq_mask);
4099 I915_WRITE(IER, enable_mask);
4102 I915_WRITE(PORT_HOTPLUG_EN, 0);
4103 POSTING_READ(PORT_HOTPLUG_EN);
4105 i915_enable_asle_pipestat(dev);
4110 static void i915_hpd_irq_setup(struct drm_device *dev)
4112 struct drm_i915_private *dev_priv = dev->dev_private;
4113 struct intel_encoder *intel_encoder;
4116 assert_spin_locked(&dev_priv->irq_lock);
4118 if (I915_HAS_HOTPLUG(dev)) {
4119 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
4120 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
4121 /* Note HDMI and DP share hotplug bits */
4122 /* enable bits are the same for all generations */
4123 for_each_intel_encoder(dev, intel_encoder)
4124 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
4125 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
4126 /* Programming the CRT detection parameters tends
4127 to generate a spurious hotplug event about three
4128 seconds later. So just do it once.
4131 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
4132 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
4133 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
4135 /* Ignore TV since it's buggy */
4136 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
4140 static irqreturn_t i965_irq_handler(int irq, void *arg)
4142 struct drm_device *dev = arg;
4143 struct drm_i915_private *dev_priv = dev->dev_private;
4145 u32 pipe_stats[I915_MAX_PIPES];
4146 int ret = IRQ_NONE, pipe;
4148 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4149 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
4151 iir = I915_READ(IIR);
4154 bool irq_received = (iir & ~flip_mask) != 0;
4155 bool blc_event = false;
4157 /* Can't rely on pipestat interrupt bit in iir as it might
4158 * have been cleared after the pipestat interrupt was received.
4159 * It doesn't set the bit in iir again, but it still produces
4160 * interrupts (for non-MSI).
4162 spin_lock(&dev_priv->irq_lock);
4163 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
4164 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
4166 for_each_pipe(dev_priv, pipe) {
4167 int reg = PIPESTAT(pipe);
4168 pipe_stats[pipe] = I915_READ(reg);
4171 * Clear the PIPE*STAT regs before the IIR
4173 if (pipe_stats[pipe] & 0x8000ffff) {
4174 I915_WRITE(reg, pipe_stats[pipe]);
4175 irq_received = true;
4178 spin_unlock(&dev_priv->irq_lock);
4185 /* Consume port. Then clear IIR or we'll miss events */
4186 if (iir & I915_DISPLAY_PORT_INTERRUPT)
4187 i9xx_hpd_irq_handler(dev);
4189 I915_WRITE(IIR, iir & ~flip_mask);
4190 new_iir = I915_READ(IIR); /* Flush posted writes */
4192 if (iir & I915_USER_INTERRUPT)
4193 notify_ring(dev, &dev_priv->ring[RCS]);
4194 if (iir & I915_BSD_USER_INTERRUPT)
4195 notify_ring(dev, &dev_priv->ring[VCS]);
4197 for_each_pipe(dev_priv, pipe) {
4198 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
4199 i915_handle_vblank(dev, pipe, pipe, iir))
4200 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
4202 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4205 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
4206 i9xx_pipe_crc_irq_handler(dev, pipe);
4208 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4209 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
4212 if (blc_event || (iir & I915_ASLE_INTERRUPT))
4213 intel_opregion_asle_intr(dev);
4215 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
4216 gmbus_irq_handler(dev);
4218 /* With MSI, interrupts are only generated when iir
4219 * transitions from zero to nonzero. If another bit got
4220 * set while we were handling the existing iir bits, then
4221 * we would never get another interrupt.
4223 * This is fine on non-MSI as well, as if we hit this path
4224 * we avoid exiting the interrupt handler only to generate
4227 * Note that for MSI this could cause a stray interrupt report
4228 * if an interrupt landed in the time between writing IIR and
4229 * the posting read. This should be rare enough to never
4230 * trigger the 99% of 100,000 interrupts test for disabling
4239 static void i965_irq_uninstall(struct drm_device * dev)
4241 struct drm_i915_private *dev_priv = dev->dev_private;
4247 I915_WRITE(PORT_HOTPLUG_EN, 0);
4248 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4250 I915_WRITE(HWSTAM, 0xffffffff);
4251 for_each_pipe(dev_priv, pipe)
4252 I915_WRITE(PIPESTAT(pipe), 0);
4253 I915_WRITE(IMR, 0xffffffff);
4254 I915_WRITE(IER, 0x0);
4256 for_each_pipe(dev_priv, pipe)
4257 I915_WRITE(PIPESTAT(pipe),
4258 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
4259 I915_WRITE(IIR, I915_READ(IIR));
4262 static void intel_hpd_irq_reenable_work(struct work_struct *work)
4264 struct drm_i915_private *dev_priv =
4265 container_of(work, typeof(*dev_priv),
4266 hotplug_reenable_work.work);
4267 struct drm_device *dev = dev_priv->dev;
4268 struct drm_mode_config *mode_config = &dev->mode_config;
4271 intel_runtime_pm_get(dev_priv);
4273 spin_lock_irq(&dev_priv->irq_lock);
4274 for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
4275 struct drm_connector *connector;
4277 if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
4280 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
4282 list_for_each_entry(connector, &mode_config->connector_list, head) {
4283 struct intel_connector *intel_connector = to_intel_connector(connector);
4285 if (intel_connector->encoder->hpd_pin == i) {
4286 if (connector->polled != intel_connector->polled)
4287 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
4289 connector->polled = intel_connector->polled;
4290 if (!connector->polled)
4291 connector->polled = DRM_CONNECTOR_POLL_HPD;
4295 if (dev_priv->display.hpd_irq_setup)
4296 dev_priv->display.hpd_irq_setup(dev);
4297 spin_unlock_irq(&dev_priv->irq_lock);
4299 intel_runtime_pm_put(dev_priv);
4303 * intel_irq_init - initializes irq support
4304 * @dev_priv: i915 device instance
4306 * This function initializes all the irq support including work items, timers
4307 * and all the vtables. It does not setup the interrupt itself though.
4309 void intel_irq_init(struct drm_i915_private *dev_priv)
4311 struct drm_device *dev = dev_priv->dev;
4313 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
4314 INIT_WORK(&dev_priv->dig_port_work, i915_digport_work_func);
4315 INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
4316 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
4317 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
4319 /* Let's track the enabled rps events */
4320 if (IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
4321 /* WaGsvRC0ResidencyMethod:vlv */
4322 dev_priv->pm_rps_events = GEN6_PM_RP_UP_EI_EXPIRED;
4324 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
4326 setup_timer(&dev_priv->gpu_error.hangcheck_timer,
4327 i915_hangcheck_elapsed,
4328 (unsigned long) dev);
4329 INIT_DELAYED_WORK(&dev_priv->hotplug_reenable_work,
4330 intel_hpd_irq_reenable_work);
4332 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
4334 if (IS_GEN2(dev_priv)) {
4335 dev->max_vblank_count = 0;
4336 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
4337 } else if (IS_G4X(dev_priv) || INTEL_INFO(dev_priv)->gen >= 5) {
4338 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
4339 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
4341 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4342 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
4346 * Opt out of the vblank disable timer on everything except gen2.
4347 * Gen2 doesn't have a hardware frame counter and so depends on
4348 * vblank interrupts to produce sane vblank seuquence numbers.
4350 if (!IS_GEN2(dev_priv))
4351 dev->vblank_disable_immediate = true;
4353 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
4354 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
4355 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
4358 if (IS_CHERRYVIEW(dev_priv)) {
4359 dev->driver->irq_handler = cherryview_irq_handler;
4360 dev->driver->irq_preinstall = cherryview_irq_preinstall;
4361 dev->driver->irq_postinstall = cherryview_irq_postinstall;
4362 dev->driver->irq_uninstall = cherryview_irq_uninstall;
4363 dev->driver->enable_vblank = valleyview_enable_vblank;
4364 dev->driver->disable_vblank = valleyview_disable_vblank;
4365 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
4366 } else if (IS_VALLEYVIEW(dev_priv)) {
4367 dev->driver->irq_handler = valleyview_irq_handler;
4368 dev->driver->irq_preinstall = valleyview_irq_preinstall;
4369 dev->driver->irq_postinstall = valleyview_irq_postinstall;
4370 dev->driver->irq_uninstall = valleyview_irq_uninstall;
4371 dev->driver->enable_vblank = valleyview_enable_vblank;
4372 dev->driver->disable_vblank = valleyview_disable_vblank;
4373 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
4374 } else if (INTEL_INFO(dev_priv)->gen >= 8) {
4375 dev->driver->irq_handler = gen8_irq_handler;
4376 dev->driver->irq_preinstall = gen8_irq_reset;
4377 dev->driver->irq_postinstall = gen8_irq_postinstall;
4378 dev->driver->irq_uninstall = gen8_irq_uninstall;
4379 dev->driver->enable_vblank = gen8_enable_vblank;
4380 dev->driver->disable_vblank = gen8_disable_vblank;
4381 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
4382 } else if (HAS_PCH_SPLIT(dev)) {
4383 dev->driver->irq_handler = ironlake_irq_handler;
4384 dev->driver->irq_preinstall = ironlake_irq_reset;
4385 dev->driver->irq_postinstall = ironlake_irq_postinstall;
4386 dev->driver->irq_uninstall = ironlake_irq_uninstall;
4387 dev->driver->enable_vblank = ironlake_enable_vblank;
4388 dev->driver->disable_vblank = ironlake_disable_vblank;
4389 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
4391 if (INTEL_INFO(dev_priv)->gen == 2) {
4392 dev->driver->irq_preinstall = i8xx_irq_preinstall;
4393 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4394 dev->driver->irq_handler = i8xx_irq_handler;
4395 dev->driver->irq_uninstall = i8xx_irq_uninstall;
4396 } else if (INTEL_INFO(dev_priv)->gen == 3) {
4397 dev->driver->irq_preinstall = i915_irq_preinstall;
4398 dev->driver->irq_postinstall = i915_irq_postinstall;
4399 dev->driver->irq_uninstall = i915_irq_uninstall;
4400 dev->driver->irq_handler = i915_irq_handler;
4401 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
4403 dev->driver->irq_preinstall = i965_irq_preinstall;
4404 dev->driver->irq_postinstall = i965_irq_postinstall;
4405 dev->driver->irq_uninstall = i965_irq_uninstall;
4406 dev->driver->irq_handler = i965_irq_handler;
4407 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
4409 dev->driver->enable_vblank = i915_enable_vblank;
4410 dev->driver->disable_vblank = i915_disable_vblank;
4415 * intel_hpd_init - initializes and enables hpd support
4416 * @dev_priv: i915 device instance
4418 * This function enables the hotplug support. It requires that interrupts have
4419 * already been enabled with intel_irq_init_hw(). From this point on hotplug and
4420 * poll request can run concurrently to other code, so locking rules must be
4423 * This is a separate step from interrupt enabling to simplify the locking rules
4424 * in the driver load and resume code.
4426 void intel_hpd_init(struct drm_i915_private *dev_priv)
4428 struct drm_device *dev = dev_priv->dev;
4429 struct drm_mode_config *mode_config = &dev->mode_config;
4430 struct drm_connector *connector;
4433 for (i = 1; i < HPD_NUM_PINS; i++) {
4434 dev_priv->hpd_stats[i].hpd_cnt = 0;
4435 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
4437 list_for_each_entry(connector, &mode_config->connector_list, head) {
4438 struct intel_connector *intel_connector = to_intel_connector(connector);
4439 connector->polled = intel_connector->polled;
4440 if (connector->encoder && !connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
4441 connector->polled = DRM_CONNECTOR_POLL_HPD;
4442 if (intel_connector->mst_port)
4443 connector->polled = DRM_CONNECTOR_POLL_HPD;
4446 /* Interrupt setup is already guaranteed to be single-threaded, this is
4447 * just to make the assert_spin_locked checks happy. */
4448 spin_lock_irq(&dev_priv->irq_lock);
4449 if (dev_priv->display.hpd_irq_setup)
4450 dev_priv->display.hpd_irq_setup(dev);
4451 spin_unlock_irq(&dev_priv->irq_lock);
4455 * intel_irq_install - enables the hardware interrupt
4456 * @dev_priv: i915 device instance
4458 * This function enables the hardware interrupt handling, but leaves the hotplug
4459 * handling still disabled. It is called after intel_irq_init().
4461 * In the driver load and resume code we need working interrupts in a few places
4462 * but don't want to deal with the hassle of concurrent probe and hotplug
4463 * workers. Hence the split into this two-stage approach.
4465 int intel_irq_install(struct drm_i915_private *dev_priv)
4468 * We enable some interrupt sources in our postinstall hooks, so mark
4469 * interrupts as enabled _before_ actually enabling them to avoid
4470 * special cases in our ordering checks.
4472 dev_priv->pm.irqs_enabled = true;
4474 return drm_irq_install(dev_priv->dev, dev_priv->dev->pdev->irq);
4478 * intel_irq_uninstall - finilizes all irq handling
4479 * @dev_priv: i915 device instance
4481 * This stops interrupt and hotplug handling and unregisters and frees all
4482 * resources acquired in the init functions.
4484 void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4486 drm_irq_uninstall(dev_priv->dev);
4487 intel_hpd_cancel_work(dev_priv);
4488 dev_priv->pm.irqs_enabled = false;
4492 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4493 * @dev_priv: i915 device instance
4495 * This function is used to disable interrupts at runtime, both in the runtime
4496 * pm and the system suspend/resume code.
4498 void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
4500 dev_priv->dev->driver->irq_uninstall(dev_priv->dev);
4501 dev_priv->pm.irqs_enabled = false;
4505 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4506 * @dev_priv: i915 device instance
4508 * This function is used to enable interrupts at runtime, both in the runtime
4509 * pm and the system suspend/resume code.
4511 void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
4513 dev_priv->pm.irqs_enabled = true;
4514 dev_priv->dev->driver->irq_preinstall(dev_priv->dev);
4515 dev_priv->dev->driver->irq_postinstall(dev_priv->dev);