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/circ_buf.h>
32 #include <linux/slab.h>
33 #include <linux/sysrq.h>
35 #include <drm/drm_drv.h>
37 #include "display/icl_dsi_regs.h"
38 #include "display/intel_de.h"
39 #include "display/intel_display_trace.h"
40 #include "display/intel_display_types.h"
41 #include "display/intel_fifo_underrun.h"
42 #include "display/intel_hotplug.h"
43 #include "display/intel_lpe_audio.h"
44 #include "display/intel_psr.h"
46 #include "gt/intel_breadcrumbs.h"
47 #include "gt/intel_gt.h"
48 #include "gt/intel_gt_irq.h"
49 #include "gt/intel_gt_pm_irq.h"
50 #include "gt/intel_gt_regs.h"
51 #include "gt/intel_rps.h"
53 #include "i915_driver.h"
59 * DOC: interrupt handling
61 * These functions provide the basic support for enabling and disabling the
62 * interrupt handling support. There's a lot more functionality in i915_irq.c
63 * and related files, but that will be described in separate chapters.
67 * Interrupt statistic for PMU. Increments the counter only if the
68 * interrupt originated from the the GPU so interrupts from a device which
69 * shares the interrupt line are not accounted.
71 static inline void pmu_irq_stats(struct drm_i915_private *i915,
74 if (unlikely(res != IRQ_HANDLED))
78 * A clever compiler translates that into INC. A not so clever one
79 * should at least prevent store tearing.
81 WRITE_ONCE(i915->pmu.irq_count, i915->pmu.irq_count + 1);
84 typedef bool (*long_pulse_detect_func)(enum hpd_pin pin, u32 val);
85 typedef u32 (*hotplug_enables_func)(struct drm_i915_private *i915,
88 static const u32 hpd_ilk[HPD_NUM_PINS] = {
89 [HPD_PORT_A] = DE_DP_A_HOTPLUG,
92 static const u32 hpd_ivb[HPD_NUM_PINS] = {
93 [HPD_PORT_A] = DE_DP_A_HOTPLUG_IVB,
96 static const u32 hpd_bdw[HPD_NUM_PINS] = {
97 [HPD_PORT_A] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_A),
100 static const u32 hpd_ibx[HPD_NUM_PINS] = {
101 [HPD_CRT] = SDE_CRT_HOTPLUG,
102 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
103 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
104 [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
105 [HPD_PORT_D] = SDE_PORTD_HOTPLUG,
108 static const u32 hpd_cpt[HPD_NUM_PINS] = {
109 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
110 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
111 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
112 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
113 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT,
116 static const u32 hpd_spt[HPD_NUM_PINS] = {
117 [HPD_PORT_A] = SDE_PORTA_HOTPLUG_SPT,
118 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
119 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
120 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT,
121 [HPD_PORT_E] = SDE_PORTE_HOTPLUG_SPT,
124 static const u32 hpd_mask_i915[HPD_NUM_PINS] = {
125 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
126 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
127 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
128 [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
129 [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
130 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN,
133 static const u32 hpd_status_g4x[HPD_NUM_PINS] = {
134 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
135 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
136 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
137 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
138 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
139 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS,
142 static const u32 hpd_status_i915[HPD_NUM_PINS] = {
143 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
144 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
145 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
146 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
147 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
148 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS,
151 static const u32 hpd_bxt[HPD_NUM_PINS] = {
152 [HPD_PORT_A] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_A),
153 [HPD_PORT_B] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_B),
154 [HPD_PORT_C] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_C),
157 static const u32 hpd_gen11[HPD_NUM_PINS] = {
158 [HPD_PORT_TC1] = GEN11_TC_HOTPLUG(HPD_PORT_TC1) | GEN11_TBT_HOTPLUG(HPD_PORT_TC1),
159 [HPD_PORT_TC2] = GEN11_TC_HOTPLUG(HPD_PORT_TC2) | GEN11_TBT_HOTPLUG(HPD_PORT_TC2),
160 [HPD_PORT_TC3] = GEN11_TC_HOTPLUG(HPD_PORT_TC3) | GEN11_TBT_HOTPLUG(HPD_PORT_TC3),
161 [HPD_PORT_TC4] = GEN11_TC_HOTPLUG(HPD_PORT_TC4) | GEN11_TBT_HOTPLUG(HPD_PORT_TC4),
162 [HPD_PORT_TC5] = GEN11_TC_HOTPLUG(HPD_PORT_TC5) | GEN11_TBT_HOTPLUG(HPD_PORT_TC5),
163 [HPD_PORT_TC6] = GEN11_TC_HOTPLUG(HPD_PORT_TC6) | GEN11_TBT_HOTPLUG(HPD_PORT_TC6),
166 static const u32 hpd_icp[HPD_NUM_PINS] = {
167 [HPD_PORT_A] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_A),
168 [HPD_PORT_B] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_B),
169 [HPD_PORT_C] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_C),
170 [HPD_PORT_TC1] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC1),
171 [HPD_PORT_TC2] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC2),
172 [HPD_PORT_TC3] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC3),
173 [HPD_PORT_TC4] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC4),
174 [HPD_PORT_TC5] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC5),
175 [HPD_PORT_TC6] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC6),
178 static const u32 hpd_sde_dg1[HPD_NUM_PINS] = {
179 [HPD_PORT_A] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_A),
180 [HPD_PORT_B] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_B),
181 [HPD_PORT_C] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_C),
182 [HPD_PORT_D] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_D),
183 [HPD_PORT_TC1] = SDE_TC_HOTPLUG_DG2(HPD_PORT_TC1),
186 static void intel_hpd_init_pins(struct drm_i915_private *dev_priv)
188 struct i915_hotplug *hpd = &dev_priv->hotplug;
190 if (HAS_GMCH(dev_priv)) {
191 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
192 IS_CHERRYVIEW(dev_priv))
193 hpd->hpd = hpd_status_g4x;
195 hpd->hpd = hpd_status_i915;
199 if (DISPLAY_VER(dev_priv) >= 11)
200 hpd->hpd = hpd_gen11;
201 else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
203 else if (DISPLAY_VER(dev_priv) >= 8)
205 else if (DISPLAY_VER(dev_priv) >= 7)
210 if ((INTEL_PCH_TYPE(dev_priv) < PCH_DG1) &&
211 (!HAS_PCH_SPLIT(dev_priv) || HAS_PCH_NOP(dev_priv)))
214 if (INTEL_PCH_TYPE(dev_priv) >= PCH_DG1)
215 hpd->pch_hpd = hpd_sde_dg1;
216 else if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
217 hpd->pch_hpd = hpd_icp;
218 else if (HAS_PCH_CNP(dev_priv) || HAS_PCH_SPT(dev_priv))
219 hpd->pch_hpd = hpd_spt;
220 else if (HAS_PCH_LPT(dev_priv) || HAS_PCH_CPT(dev_priv))
221 hpd->pch_hpd = hpd_cpt;
222 else if (HAS_PCH_IBX(dev_priv))
223 hpd->pch_hpd = hpd_ibx;
225 MISSING_CASE(INTEL_PCH_TYPE(dev_priv));
229 intel_handle_vblank(struct drm_i915_private *dev_priv, enum pipe pipe)
231 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
233 drm_crtc_handle_vblank(&crtc->base);
236 void gen3_irq_reset(struct intel_uncore *uncore, i915_reg_t imr,
237 i915_reg_t iir, i915_reg_t ier)
239 intel_uncore_write(uncore, imr, 0xffffffff);
240 intel_uncore_posting_read(uncore, imr);
242 intel_uncore_write(uncore, ier, 0);
244 /* IIR can theoretically queue up two events. Be paranoid. */
245 intel_uncore_write(uncore, iir, 0xffffffff);
246 intel_uncore_posting_read(uncore, iir);
247 intel_uncore_write(uncore, iir, 0xffffffff);
248 intel_uncore_posting_read(uncore, iir);
251 void gen2_irq_reset(struct intel_uncore *uncore)
253 intel_uncore_write16(uncore, GEN2_IMR, 0xffff);
254 intel_uncore_posting_read16(uncore, GEN2_IMR);
256 intel_uncore_write16(uncore, GEN2_IER, 0);
258 /* IIR can theoretically queue up two events. Be paranoid. */
259 intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
260 intel_uncore_posting_read16(uncore, GEN2_IIR);
261 intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
262 intel_uncore_posting_read16(uncore, GEN2_IIR);
266 * We should clear IMR at preinstall/uninstall, and just check at postinstall.
268 static void gen3_assert_iir_is_zero(struct intel_uncore *uncore, i915_reg_t reg)
270 u32 val = intel_uncore_read(uncore, reg);
275 drm_WARN(&uncore->i915->drm, 1,
276 "Interrupt register 0x%x is not zero: 0x%08x\n",
277 i915_mmio_reg_offset(reg), val);
278 intel_uncore_write(uncore, reg, 0xffffffff);
279 intel_uncore_posting_read(uncore, reg);
280 intel_uncore_write(uncore, reg, 0xffffffff);
281 intel_uncore_posting_read(uncore, reg);
284 static void gen2_assert_iir_is_zero(struct intel_uncore *uncore)
286 u16 val = intel_uncore_read16(uncore, GEN2_IIR);
291 drm_WARN(&uncore->i915->drm, 1,
292 "Interrupt register 0x%x is not zero: 0x%08x\n",
293 i915_mmio_reg_offset(GEN2_IIR), val);
294 intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
295 intel_uncore_posting_read16(uncore, GEN2_IIR);
296 intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
297 intel_uncore_posting_read16(uncore, GEN2_IIR);
300 void gen3_irq_init(struct intel_uncore *uncore,
301 i915_reg_t imr, u32 imr_val,
302 i915_reg_t ier, u32 ier_val,
305 gen3_assert_iir_is_zero(uncore, iir);
307 intel_uncore_write(uncore, ier, ier_val);
308 intel_uncore_write(uncore, imr, imr_val);
309 intel_uncore_posting_read(uncore, imr);
312 void gen2_irq_init(struct intel_uncore *uncore,
313 u32 imr_val, u32 ier_val)
315 gen2_assert_iir_is_zero(uncore);
317 intel_uncore_write16(uncore, GEN2_IER, ier_val);
318 intel_uncore_write16(uncore, GEN2_IMR, imr_val);
319 intel_uncore_posting_read16(uncore, GEN2_IMR);
322 /* For display hotplug interrupt */
324 i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv,
330 lockdep_assert_held(&dev_priv->irq_lock);
331 drm_WARN_ON(&dev_priv->drm, bits & ~mask);
333 val = intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_EN);
336 intel_uncore_write(&dev_priv->uncore, PORT_HOTPLUG_EN, val);
340 * i915_hotplug_interrupt_update - update hotplug interrupt enable
341 * @dev_priv: driver private
342 * @mask: bits to update
343 * @bits: bits to enable
344 * NOTE: the HPD enable bits are modified both inside and outside
345 * of an interrupt context. To avoid that read-modify-write cycles
346 * interfer, these bits are protected by a spinlock. Since this
347 * function is usually not called from a context where the lock is
348 * held already, this function acquires the lock itself. A non-locking
349 * version is also available.
351 void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
355 spin_lock_irq(&dev_priv->irq_lock);
356 i915_hotplug_interrupt_update_locked(dev_priv, mask, bits);
357 spin_unlock_irq(&dev_priv->irq_lock);
361 * ilk_update_display_irq - update DEIMR
362 * @dev_priv: driver private
363 * @interrupt_mask: mask of interrupt bits to update
364 * @enabled_irq_mask: mask of interrupt bits to enable
366 static void ilk_update_display_irq(struct drm_i915_private *dev_priv,
367 u32 interrupt_mask, u32 enabled_irq_mask)
371 lockdep_assert_held(&dev_priv->irq_lock);
372 drm_WARN_ON(&dev_priv->drm, enabled_irq_mask & ~interrupt_mask);
374 new_val = dev_priv->irq_mask;
375 new_val &= ~interrupt_mask;
376 new_val |= (~enabled_irq_mask & interrupt_mask);
378 if (new_val != dev_priv->irq_mask &&
379 !drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv))) {
380 dev_priv->irq_mask = new_val;
381 intel_uncore_write(&dev_priv->uncore, DEIMR, dev_priv->irq_mask);
382 intel_uncore_posting_read(&dev_priv->uncore, DEIMR);
386 void ilk_enable_display_irq(struct drm_i915_private *i915, u32 bits)
388 ilk_update_display_irq(i915, bits, bits);
391 void ilk_disable_display_irq(struct drm_i915_private *i915, u32 bits)
393 ilk_update_display_irq(i915, bits, 0);
397 * bdw_update_port_irq - update DE port interrupt
398 * @dev_priv: driver private
399 * @interrupt_mask: mask of interrupt bits to update
400 * @enabled_irq_mask: mask of interrupt bits to enable
402 static void bdw_update_port_irq(struct drm_i915_private *dev_priv,
404 u32 enabled_irq_mask)
409 lockdep_assert_held(&dev_priv->irq_lock);
411 drm_WARN_ON(&dev_priv->drm, enabled_irq_mask & ~interrupt_mask);
413 if (drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv)))
416 old_val = intel_uncore_read(&dev_priv->uncore, GEN8_DE_PORT_IMR);
419 new_val &= ~interrupt_mask;
420 new_val |= (~enabled_irq_mask & interrupt_mask);
422 if (new_val != old_val) {
423 intel_uncore_write(&dev_priv->uncore, GEN8_DE_PORT_IMR, new_val);
424 intel_uncore_posting_read(&dev_priv->uncore, GEN8_DE_PORT_IMR);
429 * bdw_update_pipe_irq - update DE pipe interrupt
430 * @dev_priv: driver private
431 * @pipe: pipe whose interrupt to update
432 * @interrupt_mask: mask of interrupt bits to update
433 * @enabled_irq_mask: mask of interrupt bits to enable
435 static void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
436 enum pipe pipe, u32 interrupt_mask,
437 u32 enabled_irq_mask)
441 lockdep_assert_held(&dev_priv->irq_lock);
443 drm_WARN_ON(&dev_priv->drm, enabled_irq_mask & ~interrupt_mask);
445 if (drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv)))
448 new_val = dev_priv->de_irq_mask[pipe];
449 new_val &= ~interrupt_mask;
450 new_val |= (~enabled_irq_mask & interrupt_mask);
452 if (new_val != dev_priv->de_irq_mask[pipe]) {
453 dev_priv->de_irq_mask[pipe] = new_val;
454 intel_uncore_write(&dev_priv->uncore, GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
455 intel_uncore_posting_read(&dev_priv->uncore, GEN8_DE_PIPE_IMR(pipe));
459 void bdw_enable_pipe_irq(struct drm_i915_private *i915,
460 enum pipe pipe, u32 bits)
462 bdw_update_pipe_irq(i915, pipe, bits, bits);
465 void bdw_disable_pipe_irq(struct drm_i915_private *i915,
466 enum pipe pipe, u32 bits)
468 bdw_update_pipe_irq(i915, pipe, bits, 0);
472 * ibx_display_interrupt_update - update SDEIMR
473 * @dev_priv: driver private
474 * @interrupt_mask: mask of interrupt bits to update
475 * @enabled_irq_mask: mask of interrupt bits to enable
477 static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
479 u32 enabled_irq_mask)
481 u32 sdeimr = intel_uncore_read(&dev_priv->uncore, SDEIMR);
482 sdeimr &= ~interrupt_mask;
483 sdeimr |= (~enabled_irq_mask & interrupt_mask);
485 drm_WARN_ON(&dev_priv->drm, enabled_irq_mask & ~interrupt_mask);
487 lockdep_assert_held(&dev_priv->irq_lock);
489 if (drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv)))
492 intel_uncore_write(&dev_priv->uncore, SDEIMR, sdeimr);
493 intel_uncore_posting_read(&dev_priv->uncore, SDEIMR);
496 void ibx_enable_display_interrupt(struct drm_i915_private *i915, u32 bits)
498 ibx_display_interrupt_update(i915, bits, bits);
501 void ibx_disable_display_interrupt(struct drm_i915_private *i915, u32 bits)
503 ibx_display_interrupt_update(i915, bits, 0);
506 u32 i915_pipestat_enable_mask(struct drm_i915_private *dev_priv,
509 u32 status_mask = dev_priv->pipestat_irq_mask[pipe];
510 u32 enable_mask = status_mask << 16;
512 lockdep_assert_held(&dev_priv->irq_lock);
514 if (DISPLAY_VER(dev_priv) < 5)
518 * On pipe A we don't support the PSR interrupt yet,
519 * on pipe B and C the same bit MBZ.
521 if (drm_WARN_ON_ONCE(&dev_priv->drm,
522 status_mask & PIPE_A_PSR_STATUS_VLV))
525 * On pipe B and C we don't support the PSR interrupt yet, on pipe
526 * A the same bit is for perf counters which we don't use either.
528 if (drm_WARN_ON_ONCE(&dev_priv->drm,
529 status_mask & PIPE_B_PSR_STATUS_VLV))
532 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
533 SPRITE0_FLIP_DONE_INT_EN_VLV |
534 SPRITE1_FLIP_DONE_INT_EN_VLV);
535 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
536 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
537 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
538 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
541 drm_WARN_ONCE(&dev_priv->drm,
542 enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
543 status_mask & ~PIPESTAT_INT_STATUS_MASK,
544 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
545 pipe_name(pipe), enable_mask, status_mask);
550 void i915_enable_pipestat(struct drm_i915_private *dev_priv,
551 enum pipe pipe, u32 status_mask)
553 i915_reg_t reg = PIPESTAT(pipe);
556 drm_WARN_ONCE(&dev_priv->drm, status_mask & ~PIPESTAT_INT_STATUS_MASK,
557 "pipe %c: status_mask=0x%x\n",
558 pipe_name(pipe), status_mask);
560 lockdep_assert_held(&dev_priv->irq_lock);
561 drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv));
563 if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == status_mask)
566 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
567 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
569 intel_uncore_write(&dev_priv->uncore, reg, enable_mask | status_mask);
570 intel_uncore_posting_read(&dev_priv->uncore, reg);
573 void i915_disable_pipestat(struct drm_i915_private *dev_priv,
574 enum pipe pipe, u32 status_mask)
576 i915_reg_t reg = PIPESTAT(pipe);
579 drm_WARN_ONCE(&dev_priv->drm, status_mask & ~PIPESTAT_INT_STATUS_MASK,
580 "pipe %c: status_mask=0x%x\n",
581 pipe_name(pipe), status_mask);
583 lockdep_assert_held(&dev_priv->irq_lock);
584 drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv));
586 if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == 0)
589 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
590 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
592 intel_uncore_write(&dev_priv->uncore, reg, enable_mask | status_mask);
593 intel_uncore_posting_read(&dev_priv->uncore, reg);
596 static bool i915_has_asle(struct drm_i915_private *dev_priv)
598 if (!dev_priv->opregion.asle)
601 return IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
605 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
606 * @dev_priv: i915 device private
608 static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv)
610 if (!i915_has_asle(dev_priv))
613 spin_lock_irq(&dev_priv->irq_lock);
615 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
616 if (DISPLAY_VER(dev_priv) >= 4)
617 i915_enable_pipestat(dev_priv, PIPE_A,
618 PIPE_LEGACY_BLC_EVENT_STATUS);
620 spin_unlock_irq(&dev_priv->irq_lock);
624 * This timing diagram depicts the video signal in and
625 * around the vertical blanking period.
627 * Assumptions about the fictitious mode used in this example:
629 * vsync_start = vblank_start + 1
630 * vsync_end = vblank_start + 2
631 * vtotal = vblank_start + 3
634 * latch double buffered registers
635 * increment frame counter (ctg+)
636 * generate start of vblank interrupt (gen4+)
639 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
640 * | may be shifted forward 1-3 extra lines via PIPECONF
642 * | | start of vsync:
643 * | | generate vsync interrupt
645 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
646 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
647 * ----va---> <-----------------vb--------------------> <--------va-------------
648 * | | <----vs-----> |
649 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
650 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
651 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
653 * last visible pixel first visible pixel
654 * | increment frame counter (gen3/4)
655 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
657 * x = horizontal active
658 * _ = horizontal blanking
659 * hs = horizontal sync
660 * va = vertical active
661 * vb = vertical blanking
663 * vbs = vblank_start (number)
666 * - most events happen at the start of horizontal sync
667 * - frame start happens at the start of horizontal blank, 1-4 lines
668 * (depending on PIPECONF settings) after the start of vblank
669 * - gen3/4 pixel and frame counter are synchronized with the start
670 * of horizontal active on the first line of vertical active
673 /* Called from drm generic code, passed a 'crtc', which
674 * we use as a pipe index
676 u32 i915_get_vblank_counter(struct drm_crtc *crtc)
678 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
679 struct drm_vblank_crtc *vblank = &dev_priv->drm.vblank[drm_crtc_index(crtc)];
680 const struct drm_display_mode *mode = &vblank->hwmode;
681 enum pipe pipe = to_intel_crtc(crtc)->pipe;
682 i915_reg_t high_frame, low_frame;
683 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
684 unsigned long irqflags;
687 * On i965gm TV output the frame counter only works up to
688 * the point when we enable the TV encoder. After that the
689 * frame counter ceases to work and reads zero. We need a
690 * vblank wait before enabling the TV encoder and so we
691 * have to enable vblank interrupts while the frame counter
692 * is still in a working state. However the core vblank code
693 * does not like us returning non-zero frame counter values
694 * when we've told it that we don't have a working frame
695 * counter. Thus we must stop non-zero values leaking out.
697 if (!vblank->max_vblank_count)
700 htotal = mode->crtc_htotal;
701 hsync_start = mode->crtc_hsync_start;
702 vbl_start = mode->crtc_vblank_start;
703 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
704 vbl_start = DIV_ROUND_UP(vbl_start, 2);
706 /* Convert to pixel count */
709 /* Start of vblank event occurs at start of hsync */
710 vbl_start -= htotal - hsync_start;
712 high_frame = PIPEFRAME(pipe);
713 low_frame = PIPEFRAMEPIXEL(pipe);
715 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
718 * High & low register fields aren't synchronized, so make sure
719 * we get a low value that's stable across two reads of the high
723 high1 = intel_de_read_fw(dev_priv, high_frame) & PIPE_FRAME_HIGH_MASK;
724 low = intel_de_read_fw(dev_priv, low_frame);
725 high2 = intel_de_read_fw(dev_priv, high_frame) & PIPE_FRAME_HIGH_MASK;
726 } while (high1 != high2);
728 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
730 high1 >>= PIPE_FRAME_HIGH_SHIFT;
731 pixel = low & PIPE_PIXEL_MASK;
732 low >>= PIPE_FRAME_LOW_SHIFT;
735 * The frame counter increments at beginning of active.
736 * Cook up a vblank counter by also checking the pixel
737 * counter against vblank start.
739 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
742 u32 g4x_get_vblank_counter(struct drm_crtc *crtc)
744 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
745 struct drm_vblank_crtc *vblank = &dev_priv->drm.vblank[drm_crtc_index(crtc)];
746 enum pipe pipe = to_intel_crtc(crtc)->pipe;
748 if (!vblank->max_vblank_count)
751 return intel_uncore_read(&dev_priv->uncore, PIPE_FRMCOUNT_G4X(pipe));
754 static u32 intel_crtc_scanlines_since_frame_timestamp(struct intel_crtc *crtc)
756 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
757 struct drm_vblank_crtc *vblank =
758 &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
759 const struct drm_display_mode *mode = &vblank->hwmode;
760 u32 htotal = mode->crtc_htotal;
761 u32 clock = mode->crtc_clock;
762 u32 scan_prev_time, scan_curr_time, scan_post_time;
765 * To avoid the race condition where we might cross into the
766 * next vblank just between the PIPE_FRMTMSTMP and TIMESTAMP_CTR
767 * reads. We make sure we read PIPE_FRMTMSTMP and TIMESTAMP_CTR
768 * during the same frame.
772 * This field provides read back of the display
773 * pipe frame time stamp. The time stamp value
774 * is sampled at every start of vertical blank.
776 scan_prev_time = intel_de_read_fw(dev_priv,
777 PIPE_FRMTMSTMP(crtc->pipe));
780 * The TIMESTAMP_CTR register has the current
783 scan_curr_time = intel_de_read_fw(dev_priv, IVB_TIMESTAMP_CTR);
785 scan_post_time = intel_de_read_fw(dev_priv,
786 PIPE_FRMTMSTMP(crtc->pipe));
787 } while (scan_post_time != scan_prev_time);
789 return div_u64(mul_u32_u32(scan_curr_time - scan_prev_time,
790 clock), 1000 * htotal);
794 * On certain encoders on certain platforms, pipe
795 * scanline register will not work to get the scanline,
796 * since the timings are driven from the PORT or issues
797 * with scanline register updates.
798 * This function will use Framestamp and current
799 * timestamp registers to calculate the scanline.
801 static u32 __intel_get_crtc_scanline_from_timestamp(struct intel_crtc *crtc)
803 struct drm_vblank_crtc *vblank =
804 &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
805 const struct drm_display_mode *mode = &vblank->hwmode;
806 u32 vblank_start = mode->crtc_vblank_start;
807 u32 vtotal = mode->crtc_vtotal;
810 scanline = intel_crtc_scanlines_since_frame_timestamp(crtc);
811 scanline = min(scanline, vtotal - 1);
812 scanline = (scanline + vblank_start) % vtotal;
818 * intel_de_read_fw(), only for fast reads of display block, no need for
821 static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
823 struct drm_device *dev = crtc->base.dev;
824 struct drm_i915_private *dev_priv = to_i915(dev);
825 const struct drm_display_mode *mode;
826 struct drm_vblank_crtc *vblank;
827 enum pipe pipe = crtc->pipe;
828 int position, vtotal;
833 vblank = &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
834 mode = &vblank->hwmode;
836 if (crtc->mode_flags & I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP)
837 return __intel_get_crtc_scanline_from_timestamp(crtc);
839 vtotal = mode->crtc_vtotal;
840 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
843 position = intel_de_read_fw(dev_priv, PIPEDSL(pipe)) & PIPEDSL_LINE_MASK;
846 * On HSW, the DSL reg (0x70000) appears to return 0 if we
847 * read it just before the start of vblank. So try it again
848 * so we don't accidentally end up spanning a vblank frame
849 * increment, causing the pipe_update_end() code to squak at us.
851 * The nature of this problem means we can't simply check the ISR
852 * bit and return the vblank start value; nor can we use the scanline
853 * debug register in the transcoder as it appears to have the same
854 * problem. We may need to extend this to include other platforms,
855 * but so far testing only shows the problem on HSW.
857 if (HAS_DDI(dev_priv) && !position) {
860 for (i = 0; i < 100; i++) {
862 temp = intel_de_read_fw(dev_priv, PIPEDSL(pipe)) & PIPEDSL_LINE_MASK;
863 if (temp != position) {
871 * See update_scanline_offset() for the details on the
872 * scanline_offset adjustment.
874 return (position + crtc->scanline_offset) % vtotal;
877 static bool i915_get_crtc_scanoutpos(struct drm_crtc *_crtc,
879 int *vpos, int *hpos,
880 ktime_t *stime, ktime_t *etime,
881 const struct drm_display_mode *mode)
883 struct drm_device *dev = _crtc->dev;
884 struct drm_i915_private *dev_priv = to_i915(dev);
885 struct intel_crtc *crtc = to_intel_crtc(_crtc);
886 enum pipe pipe = crtc->pipe;
888 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
889 unsigned long irqflags;
890 bool use_scanline_counter = DISPLAY_VER(dev_priv) >= 5 ||
891 IS_G4X(dev_priv) || DISPLAY_VER(dev_priv) == 2 ||
892 crtc->mode_flags & I915_MODE_FLAG_USE_SCANLINE_COUNTER;
894 if (drm_WARN_ON(&dev_priv->drm, !mode->crtc_clock)) {
895 drm_dbg(&dev_priv->drm,
896 "trying to get scanoutpos for disabled "
897 "pipe %c\n", pipe_name(pipe));
901 htotal = mode->crtc_htotal;
902 hsync_start = mode->crtc_hsync_start;
903 vtotal = mode->crtc_vtotal;
904 vbl_start = mode->crtc_vblank_start;
905 vbl_end = mode->crtc_vblank_end;
907 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
908 vbl_start = DIV_ROUND_UP(vbl_start, 2);
914 * Lock uncore.lock, as we will do multiple timing critical raw
915 * register reads, potentially with preemption disabled, so the
916 * following code must not block on uncore.lock.
918 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
920 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
922 /* Get optional system timestamp before query. */
924 *stime = ktime_get();
926 if (crtc->mode_flags & I915_MODE_FLAG_VRR) {
927 int scanlines = intel_crtc_scanlines_since_frame_timestamp(crtc);
929 position = __intel_get_crtc_scanline(crtc);
932 * Already exiting vblank? If so, shift our position
933 * so it looks like we're already apporaching the full
934 * vblank end. This should make the generated timestamp
935 * more or less match when the active portion will start.
937 if (position >= vbl_start && scanlines < position)
938 position = min(crtc->vmax_vblank_start + scanlines, vtotal - 1);
939 } else if (use_scanline_counter) {
940 /* No obvious pixelcount register. Only query vertical
941 * scanout position from Display scan line register.
943 position = __intel_get_crtc_scanline(crtc);
945 /* Have access to pixelcount since start of frame.
946 * We can split this into vertical and horizontal
949 position = (intel_de_read_fw(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
951 /* convert to pixel counts */
957 * In interlaced modes, the pixel counter counts all pixels,
958 * so one field will have htotal more pixels. In order to avoid
959 * the reported position from jumping backwards when the pixel
960 * counter is beyond the length of the shorter field, just
961 * clamp the position the length of the shorter field. This
962 * matches how the scanline counter based position works since
963 * the scanline counter doesn't count the two half lines.
965 if (position >= vtotal)
966 position = vtotal - 1;
969 * Start of vblank interrupt is triggered at start of hsync,
970 * just prior to the first active line of vblank. However we
971 * consider lines to start at the leading edge of horizontal
972 * active. So, should we get here before we've crossed into
973 * the horizontal active of the first line in vblank, we would
974 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
975 * always add htotal-hsync_start to the current pixel position.
977 position = (position + htotal - hsync_start) % vtotal;
980 /* Get optional system timestamp after query. */
982 *etime = ktime_get();
984 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
986 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
989 * While in vblank, position will be negative
990 * counting up towards 0 at vbl_end. And outside
991 * vblank, position will be positive counting
994 if (position >= vbl_start)
997 position += vtotal - vbl_end;
999 if (use_scanline_counter) {
1003 *vpos = position / htotal;
1004 *hpos = position - (*vpos * htotal);
1010 bool intel_crtc_get_vblank_timestamp(struct drm_crtc *crtc, int *max_error,
1011 ktime_t *vblank_time, bool in_vblank_irq)
1013 return drm_crtc_vblank_helper_get_vblank_timestamp_internal(
1014 crtc, max_error, vblank_time, in_vblank_irq,
1015 i915_get_crtc_scanoutpos);
1018 int intel_get_crtc_scanline(struct intel_crtc *crtc)
1020 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1021 unsigned long irqflags;
1024 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1025 position = __intel_get_crtc_scanline(crtc);
1026 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1032 * ivb_parity_work - Workqueue called when a parity error interrupt
1034 * @work: workqueue struct
1036 * Doesn't actually do anything except notify userspace. As a consequence of
1037 * this event, userspace should try to remap the bad rows since statistically
1038 * it is likely the same row is more likely to go bad again.
1040 static void ivb_parity_work(struct work_struct *work)
1042 struct drm_i915_private *dev_priv =
1043 container_of(work, typeof(*dev_priv), l3_parity.error_work);
1044 struct intel_gt *gt = to_gt(dev_priv);
1045 u32 error_status, row, bank, subbank;
1046 char *parity_event[6];
1050 /* We must turn off DOP level clock gating to access the L3 registers.
1051 * In order to prevent a get/put style interface, acquire struct mutex
1052 * any time we access those registers.
1054 mutex_lock(&dev_priv->drm.struct_mutex);
1056 /* If we've screwed up tracking, just let the interrupt fire again */
1057 if (drm_WARN_ON(&dev_priv->drm, !dev_priv->l3_parity.which_slice))
1060 misccpctl = intel_uncore_read(&dev_priv->uncore, GEN7_MISCCPCTL);
1061 intel_uncore_write(&dev_priv->uncore, GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1062 intel_uncore_posting_read(&dev_priv->uncore, GEN7_MISCCPCTL);
1064 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1068 if (drm_WARN_ON_ONCE(&dev_priv->drm,
1069 slice >= NUM_L3_SLICES(dev_priv)))
1072 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1074 reg = GEN7_L3CDERRST1(slice);
1076 error_status = intel_uncore_read(&dev_priv->uncore, reg);
1077 row = GEN7_PARITY_ERROR_ROW(error_status);
1078 bank = GEN7_PARITY_ERROR_BANK(error_status);
1079 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1081 intel_uncore_write(&dev_priv->uncore, reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1082 intel_uncore_posting_read(&dev_priv->uncore, reg);
1084 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1085 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1086 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1087 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1088 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1089 parity_event[5] = NULL;
1091 kobject_uevent_env(&dev_priv->drm.primary->kdev->kobj,
1092 KOBJ_CHANGE, parity_event);
1094 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1095 slice, row, bank, subbank);
1097 kfree(parity_event[4]);
1098 kfree(parity_event[3]);
1099 kfree(parity_event[2]);
1100 kfree(parity_event[1]);
1103 intel_uncore_write(&dev_priv->uncore, GEN7_MISCCPCTL, misccpctl);
1106 drm_WARN_ON(&dev_priv->drm, dev_priv->l3_parity.which_slice);
1107 spin_lock_irq(>->irq_lock);
1108 gen5_gt_enable_irq(gt, GT_PARITY_ERROR(dev_priv));
1109 spin_unlock_irq(>->irq_lock);
1111 mutex_unlock(&dev_priv->drm.struct_mutex);
1114 static bool gen11_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
1123 return val & GEN11_HOTPLUG_CTL_LONG_DETECT(pin);
1129 static bool bxt_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
1133 return val & PORTA_HOTPLUG_LONG_DETECT;
1135 return val & PORTB_HOTPLUG_LONG_DETECT;
1137 return val & PORTC_HOTPLUG_LONG_DETECT;
1143 static bool icp_ddi_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
1150 return val & SHOTPLUG_CTL_DDI_HPD_LONG_DETECT(pin);
1156 static bool icp_tc_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
1165 return val & ICP_TC_HPD_LONG_DETECT(pin);
1171 static bool spt_port_hotplug2_long_detect(enum hpd_pin pin, u32 val)
1175 return val & PORTE_HOTPLUG_LONG_DETECT;
1181 static bool spt_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
1185 return val & PORTA_HOTPLUG_LONG_DETECT;
1187 return val & PORTB_HOTPLUG_LONG_DETECT;
1189 return val & PORTC_HOTPLUG_LONG_DETECT;
1191 return val & PORTD_HOTPLUG_LONG_DETECT;
1197 static bool ilk_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
1201 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
1207 static bool pch_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
1211 return val & PORTB_HOTPLUG_LONG_DETECT;
1213 return val & PORTC_HOTPLUG_LONG_DETECT;
1215 return val & PORTD_HOTPLUG_LONG_DETECT;
1221 static bool i9xx_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
1225 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
1227 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
1229 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
1236 * Get a bit mask of pins that have triggered, and which ones may be long.
1237 * This can be called multiple times with the same masks to accumulate
1238 * hotplug detection results from several registers.
1240 * Note that the caller is expected to zero out the masks initially.
1242 static void intel_get_hpd_pins(struct drm_i915_private *dev_priv,
1243 u32 *pin_mask, u32 *long_mask,
1244 u32 hotplug_trigger, u32 dig_hotplug_reg,
1245 const u32 hpd[HPD_NUM_PINS],
1246 bool long_pulse_detect(enum hpd_pin pin, u32 val))
1250 BUILD_BUG_ON(BITS_PER_TYPE(*pin_mask) < HPD_NUM_PINS);
1252 for_each_hpd_pin(pin) {
1253 if ((hpd[pin] & hotplug_trigger) == 0)
1256 *pin_mask |= BIT(pin);
1258 if (long_pulse_detect(pin, dig_hotplug_reg))
1259 *long_mask |= BIT(pin);
1262 drm_dbg(&dev_priv->drm,
1263 "hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x, long 0x%08x\n",
1264 hotplug_trigger, dig_hotplug_reg, *pin_mask, *long_mask);
1268 static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
1269 const u32 hpd[HPD_NUM_PINS])
1271 struct intel_encoder *encoder;
1272 u32 enabled_irqs = 0;
1274 for_each_intel_encoder(&dev_priv->drm, encoder)
1275 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
1276 enabled_irqs |= hpd[encoder->hpd_pin];
1278 return enabled_irqs;
1281 static u32 intel_hpd_hotplug_irqs(struct drm_i915_private *dev_priv,
1282 const u32 hpd[HPD_NUM_PINS])
1284 struct intel_encoder *encoder;
1285 u32 hotplug_irqs = 0;
1287 for_each_intel_encoder(&dev_priv->drm, encoder)
1288 hotplug_irqs |= hpd[encoder->hpd_pin];
1290 return hotplug_irqs;
1293 static u32 intel_hpd_hotplug_enables(struct drm_i915_private *i915,
1294 hotplug_enables_func hotplug_enables)
1296 struct intel_encoder *encoder;
1299 for_each_intel_encoder(&i915->drm, encoder)
1300 hotplug |= hotplug_enables(i915, encoder->hpd_pin);
1305 static void gmbus_irq_handler(struct drm_i915_private *dev_priv)
1307 wake_up_all(&dev_priv->gmbus_wait_queue);
1310 static void dp_aux_irq_handler(struct drm_i915_private *dev_priv)
1312 wake_up_all(&dev_priv->gmbus_wait_queue);
1315 #if defined(CONFIG_DEBUG_FS)
1316 static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1322 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
1323 struct intel_pipe_crc *pipe_crc = &crtc->pipe_crc;
1324 u32 crcs[5] = { crc0, crc1, crc2, crc3, crc4 };
1326 trace_intel_pipe_crc(crtc, crcs);
1328 spin_lock(&pipe_crc->lock);
1330 * For some not yet identified reason, the first CRC is
1331 * bonkers. So let's just wait for the next vblank and read
1332 * out the buggy result.
1334 * On GEN8+ sometimes the second CRC is bonkers as well, so
1335 * don't trust that one either.
1337 if (pipe_crc->skipped <= 0 ||
1338 (DISPLAY_VER(dev_priv) >= 8 && pipe_crc->skipped == 1)) {
1339 pipe_crc->skipped++;
1340 spin_unlock(&pipe_crc->lock);
1343 spin_unlock(&pipe_crc->lock);
1345 drm_crtc_add_crc_entry(&crtc->base, true,
1346 drm_crtc_accurate_vblank_count(&crtc->base),
1351 display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1358 static void flip_done_handler(struct drm_i915_private *i915,
1361 struct intel_crtc *crtc = intel_crtc_for_pipe(i915, pipe);
1362 struct drm_crtc_state *crtc_state = crtc->base.state;
1363 struct drm_pending_vblank_event *e = crtc_state->event;
1364 struct drm_device *dev = &i915->drm;
1365 unsigned long irqflags;
1367 spin_lock_irqsave(&dev->event_lock, irqflags);
1369 crtc_state->event = NULL;
1371 drm_crtc_send_vblank_event(&crtc->base, e);
1373 spin_unlock_irqrestore(&dev->event_lock, irqflags);
1376 static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1379 display_pipe_crc_irq_handler(dev_priv, pipe,
1380 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_1_IVB(pipe)),
1384 static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1387 display_pipe_crc_irq_handler(dev_priv, pipe,
1388 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_1_IVB(pipe)),
1389 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_2_IVB(pipe)),
1390 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_3_IVB(pipe)),
1391 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_4_IVB(pipe)),
1392 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_5_IVB(pipe)));
1395 static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1400 if (DISPLAY_VER(dev_priv) >= 3)
1401 res1 = intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_RES1_I915(pipe));
1405 if (DISPLAY_VER(dev_priv) >= 5 || IS_G4X(dev_priv))
1406 res2 = intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_RES2_G4X(pipe));
1410 display_pipe_crc_irq_handler(dev_priv, pipe,
1411 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_RED(pipe)),
1412 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_GREEN(pipe)),
1413 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_BLUE(pipe)),
1417 static void i9xx_pipestat_irq_reset(struct drm_i915_private *dev_priv)
1421 for_each_pipe(dev_priv, pipe) {
1422 intel_uncore_write(&dev_priv->uncore, PIPESTAT(pipe),
1423 PIPESTAT_INT_STATUS_MASK |
1424 PIPE_FIFO_UNDERRUN_STATUS);
1426 dev_priv->pipestat_irq_mask[pipe] = 0;
1430 static void i9xx_pipestat_irq_ack(struct drm_i915_private *dev_priv,
1431 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1435 spin_lock(&dev_priv->irq_lock);
1437 if (!dev_priv->display_irqs_enabled) {
1438 spin_unlock(&dev_priv->irq_lock);
1442 for_each_pipe(dev_priv, pipe) {
1444 u32 status_mask, enable_mask, iir_bit = 0;
1447 * PIPESTAT bits get signalled even when the interrupt is
1448 * disabled with the mask bits, and some of the status bits do
1449 * not generate interrupts at all (like the underrun bit). Hence
1450 * we need to be careful that we only handle what we want to
1454 /* fifo underruns are filterered in the underrun handler. */
1455 status_mask = PIPE_FIFO_UNDERRUN_STATUS;
1460 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1463 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1466 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1470 status_mask |= dev_priv->pipestat_irq_mask[pipe];
1475 reg = PIPESTAT(pipe);
1476 pipe_stats[pipe] = intel_uncore_read(&dev_priv->uncore, reg) & status_mask;
1477 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
1480 * Clear the PIPE*STAT regs before the IIR
1482 * Toggle the enable bits to make sure we get an
1483 * edge in the ISR pipe event bit if we don't clear
1484 * all the enabled status bits. Otherwise the edge
1485 * triggered IIR on i965/g4x wouldn't notice that
1486 * an interrupt is still pending.
1488 if (pipe_stats[pipe]) {
1489 intel_uncore_write(&dev_priv->uncore, reg, pipe_stats[pipe]);
1490 intel_uncore_write(&dev_priv->uncore, reg, enable_mask);
1493 spin_unlock(&dev_priv->irq_lock);
1496 static void i8xx_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1497 u16 iir, u32 pipe_stats[I915_MAX_PIPES])
1501 for_each_pipe(dev_priv, pipe) {
1502 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1503 intel_handle_vblank(dev_priv, pipe);
1505 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1506 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1508 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1509 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1513 static void i915_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1514 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1516 bool blc_event = false;
1519 for_each_pipe(dev_priv, pipe) {
1520 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1521 intel_handle_vblank(dev_priv, pipe);
1523 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1526 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1527 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1529 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1530 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1533 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1534 intel_opregion_asle_intr(dev_priv);
1537 static void i965_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1538 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1540 bool blc_event = false;
1543 for_each_pipe(dev_priv, pipe) {
1544 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1545 intel_handle_vblank(dev_priv, pipe);
1547 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1550 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1551 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1553 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1554 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1557 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1558 intel_opregion_asle_intr(dev_priv);
1560 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1561 gmbus_irq_handler(dev_priv);
1564 static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1565 u32 pipe_stats[I915_MAX_PIPES])
1569 for_each_pipe(dev_priv, pipe) {
1570 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1571 intel_handle_vblank(dev_priv, pipe);
1573 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV)
1574 flip_done_handler(dev_priv, pipe);
1576 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1577 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1579 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1580 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1583 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1584 gmbus_irq_handler(dev_priv);
1587 static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
1589 u32 hotplug_status = 0, hotplug_status_mask;
1592 if (IS_G4X(dev_priv) ||
1593 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
1594 hotplug_status_mask = HOTPLUG_INT_STATUS_G4X |
1595 DP_AUX_CHANNEL_MASK_INT_STATUS_G4X;
1597 hotplug_status_mask = HOTPLUG_INT_STATUS_I915;
1600 * We absolutely have to clear all the pending interrupt
1601 * bits in PORT_HOTPLUG_STAT. Otherwise the ISR port
1602 * interrupt bit won't have an edge, and the i965/g4x
1603 * edge triggered IIR will not notice that an interrupt
1604 * is still pending. We can't use PORT_HOTPLUG_EN to
1605 * guarantee the edge as the act of toggling the enable
1606 * bits can itself generate a new hotplug interrupt :(
1608 for (i = 0; i < 10; i++) {
1609 u32 tmp = intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT) & hotplug_status_mask;
1612 return hotplug_status;
1614 hotplug_status |= tmp;
1615 intel_uncore_write(&dev_priv->uncore, PORT_HOTPLUG_STAT, hotplug_status);
1618 drm_WARN_ONCE(&dev_priv->drm, 1,
1619 "PORT_HOTPLUG_STAT did not clear (0x%08x)\n",
1620 intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT));
1622 return hotplug_status;
1625 static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv,
1628 u32 pin_mask = 0, long_mask = 0;
1629 u32 hotplug_trigger;
1631 if (IS_G4X(dev_priv) ||
1632 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
1633 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
1635 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
1637 if (hotplug_trigger) {
1638 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1639 hotplug_trigger, hotplug_trigger,
1640 dev_priv->hotplug.hpd,
1641 i9xx_port_hotplug_long_detect);
1643 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
1646 if ((IS_G4X(dev_priv) ||
1647 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
1648 hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
1649 dp_aux_irq_handler(dev_priv);
1652 static irqreturn_t valleyview_irq_handler(int irq, void *arg)
1654 struct drm_i915_private *dev_priv = arg;
1655 irqreturn_t ret = IRQ_NONE;
1657 if (!intel_irqs_enabled(dev_priv))
1660 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1661 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
1664 u32 iir, gt_iir, pm_iir;
1665 u32 pipe_stats[I915_MAX_PIPES] = {};
1666 u32 hotplug_status = 0;
1669 gt_iir = intel_uncore_read(&dev_priv->uncore, GTIIR);
1670 pm_iir = intel_uncore_read(&dev_priv->uncore, GEN6_PMIIR);
1671 iir = intel_uncore_read(&dev_priv->uncore, VLV_IIR);
1673 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1679 * Theory on interrupt generation, based on empirical evidence:
1681 * x = ((VLV_IIR & VLV_IER) ||
1682 * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) &&
1683 * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE)));
1685 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
1686 * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to
1687 * guarantee the CPU interrupt will be raised again even if we
1688 * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR
1689 * bits this time around.
1691 intel_uncore_write(&dev_priv->uncore, VLV_MASTER_IER, 0);
1692 ier = intel_uncore_read(&dev_priv->uncore, VLV_IER);
1693 intel_uncore_write(&dev_priv->uncore, VLV_IER, 0);
1696 intel_uncore_write(&dev_priv->uncore, GTIIR, gt_iir);
1698 intel_uncore_write(&dev_priv->uncore, GEN6_PMIIR, pm_iir);
1700 if (iir & I915_DISPLAY_PORT_INTERRUPT)
1701 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
1703 /* Call regardless, as some status bits might not be
1704 * signalled in iir */
1705 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
1707 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
1708 I915_LPE_PIPE_B_INTERRUPT))
1709 intel_lpe_audio_irq_handler(dev_priv);
1712 * VLV_IIR is single buffered, and reflects the level
1713 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
1716 intel_uncore_write(&dev_priv->uncore, VLV_IIR, iir);
1718 intel_uncore_write(&dev_priv->uncore, VLV_IER, ier);
1719 intel_uncore_write(&dev_priv->uncore, VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
1722 gen6_gt_irq_handler(to_gt(dev_priv), gt_iir);
1724 gen6_rps_irq_handler(&to_gt(dev_priv)->rps, pm_iir);
1727 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
1729 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
1732 pmu_irq_stats(dev_priv, ret);
1734 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
1739 static irqreturn_t cherryview_irq_handler(int irq, void *arg)
1741 struct drm_i915_private *dev_priv = arg;
1742 irqreturn_t ret = IRQ_NONE;
1744 if (!intel_irqs_enabled(dev_priv))
1747 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1748 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
1751 u32 master_ctl, iir;
1752 u32 pipe_stats[I915_MAX_PIPES] = {};
1753 u32 hotplug_status = 0;
1756 master_ctl = intel_uncore_read(&dev_priv->uncore, GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
1757 iir = intel_uncore_read(&dev_priv->uncore, VLV_IIR);
1759 if (master_ctl == 0 && iir == 0)
1765 * Theory on interrupt generation, based on empirical evidence:
1767 * x = ((VLV_IIR & VLV_IER) ||
1768 * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) &&
1769 * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL)));
1771 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
1772 * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to
1773 * guarantee the CPU interrupt will be raised again even if we
1774 * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL
1775 * bits this time around.
1777 intel_uncore_write(&dev_priv->uncore, GEN8_MASTER_IRQ, 0);
1778 ier = intel_uncore_read(&dev_priv->uncore, VLV_IER);
1779 intel_uncore_write(&dev_priv->uncore, VLV_IER, 0);
1781 gen8_gt_irq_handler(to_gt(dev_priv), master_ctl);
1783 if (iir & I915_DISPLAY_PORT_INTERRUPT)
1784 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
1786 /* Call regardless, as some status bits might not be
1787 * signalled in iir */
1788 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
1790 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
1791 I915_LPE_PIPE_B_INTERRUPT |
1792 I915_LPE_PIPE_C_INTERRUPT))
1793 intel_lpe_audio_irq_handler(dev_priv);
1796 * VLV_IIR is single buffered, and reflects the level
1797 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
1800 intel_uncore_write(&dev_priv->uncore, VLV_IIR, iir);
1802 intel_uncore_write(&dev_priv->uncore, VLV_IER, ier);
1803 intel_uncore_write(&dev_priv->uncore, GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
1806 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
1808 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
1811 pmu_irq_stats(dev_priv, ret);
1813 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
1818 static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv,
1819 u32 hotplug_trigger)
1821 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
1824 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
1825 * unless we touch the hotplug register, even if hotplug_trigger is
1826 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
1829 dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
1830 if (!hotplug_trigger) {
1831 u32 mask = PORTA_HOTPLUG_STATUS_MASK |
1832 PORTD_HOTPLUG_STATUS_MASK |
1833 PORTC_HOTPLUG_STATUS_MASK |
1834 PORTB_HOTPLUG_STATUS_MASK;
1835 dig_hotplug_reg &= ~mask;
1838 intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, dig_hotplug_reg);
1839 if (!hotplug_trigger)
1842 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1843 hotplug_trigger, dig_hotplug_reg,
1844 dev_priv->hotplug.pch_hpd,
1845 pch_port_hotplug_long_detect);
1847 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
1850 static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
1853 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
1855 ibx_hpd_irq_handler(dev_priv, hotplug_trigger);
1857 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1858 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1859 SDE_AUDIO_POWER_SHIFT);
1860 drm_dbg(&dev_priv->drm, "PCH audio power change on port %d\n",
1864 if (pch_iir & SDE_AUX_MASK)
1865 dp_aux_irq_handler(dev_priv);
1867 if (pch_iir & SDE_GMBUS)
1868 gmbus_irq_handler(dev_priv);
1870 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1871 drm_dbg(&dev_priv->drm, "PCH HDCP audio interrupt\n");
1873 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1874 drm_dbg(&dev_priv->drm, "PCH transcoder audio interrupt\n");
1876 if (pch_iir & SDE_POISON)
1877 drm_err(&dev_priv->drm, "PCH poison interrupt\n");
1879 if (pch_iir & SDE_FDI_MASK) {
1880 for_each_pipe(dev_priv, pipe)
1881 drm_dbg(&dev_priv->drm, " pipe %c FDI IIR: 0x%08x\n",
1883 intel_uncore_read(&dev_priv->uncore, FDI_RX_IIR(pipe)));
1886 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1887 drm_dbg(&dev_priv->drm, "PCH transcoder CRC done interrupt\n");
1889 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1890 drm_dbg(&dev_priv->drm,
1891 "PCH transcoder CRC error interrupt\n");
1893 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
1894 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A);
1896 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1897 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B);
1900 static void ivb_err_int_handler(struct drm_i915_private *dev_priv)
1902 u32 err_int = intel_uncore_read(&dev_priv->uncore, GEN7_ERR_INT);
1905 if (err_int & ERR_INT_POISON)
1906 drm_err(&dev_priv->drm, "Poison interrupt\n");
1908 for_each_pipe(dev_priv, pipe) {
1909 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
1910 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1912 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
1913 if (IS_IVYBRIDGE(dev_priv))
1914 ivb_pipe_crc_irq_handler(dev_priv, pipe);
1916 hsw_pipe_crc_irq_handler(dev_priv, pipe);
1920 intel_uncore_write(&dev_priv->uncore, GEN7_ERR_INT, err_int);
1923 static void cpt_serr_int_handler(struct drm_i915_private *dev_priv)
1925 u32 serr_int = intel_uncore_read(&dev_priv->uncore, SERR_INT);
1928 if (serr_int & SERR_INT_POISON)
1929 drm_err(&dev_priv->drm, "PCH poison interrupt\n");
1931 for_each_pipe(dev_priv, pipe)
1932 if (serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pipe))
1933 intel_pch_fifo_underrun_irq_handler(dev_priv, pipe);
1935 intel_uncore_write(&dev_priv->uncore, SERR_INT, serr_int);
1938 static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
1941 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
1943 ibx_hpd_irq_handler(dev_priv, hotplug_trigger);
1945 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1946 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1947 SDE_AUDIO_POWER_SHIFT_CPT);
1948 drm_dbg(&dev_priv->drm, "PCH audio power change on port %c\n",
1952 if (pch_iir & SDE_AUX_MASK_CPT)
1953 dp_aux_irq_handler(dev_priv);
1955 if (pch_iir & SDE_GMBUS_CPT)
1956 gmbus_irq_handler(dev_priv);
1958 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1959 drm_dbg(&dev_priv->drm, "Audio CP request interrupt\n");
1961 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1962 drm_dbg(&dev_priv->drm, "Audio CP change interrupt\n");
1964 if (pch_iir & SDE_FDI_MASK_CPT) {
1965 for_each_pipe(dev_priv, pipe)
1966 drm_dbg(&dev_priv->drm, " pipe %c FDI IIR: 0x%08x\n",
1968 intel_uncore_read(&dev_priv->uncore, FDI_RX_IIR(pipe)));
1971 if (pch_iir & SDE_ERROR_CPT)
1972 cpt_serr_int_handler(dev_priv);
1975 static void icp_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
1977 u32 ddi_hotplug_trigger = pch_iir & SDE_DDI_HOTPLUG_MASK_ICP;
1978 u32 tc_hotplug_trigger = pch_iir & SDE_TC_HOTPLUG_MASK_ICP;
1979 u32 pin_mask = 0, long_mask = 0;
1981 if (ddi_hotplug_trigger) {
1982 u32 dig_hotplug_reg;
1984 dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, SHOTPLUG_CTL_DDI);
1985 intel_uncore_write(&dev_priv->uncore, SHOTPLUG_CTL_DDI, dig_hotplug_reg);
1987 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1988 ddi_hotplug_trigger, dig_hotplug_reg,
1989 dev_priv->hotplug.pch_hpd,
1990 icp_ddi_port_hotplug_long_detect);
1993 if (tc_hotplug_trigger) {
1994 u32 dig_hotplug_reg;
1996 dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, SHOTPLUG_CTL_TC);
1997 intel_uncore_write(&dev_priv->uncore, SHOTPLUG_CTL_TC, dig_hotplug_reg);
1999 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2000 tc_hotplug_trigger, dig_hotplug_reg,
2001 dev_priv->hotplug.pch_hpd,
2002 icp_tc_port_hotplug_long_detect);
2006 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
2008 if (pch_iir & SDE_GMBUS_ICP)
2009 gmbus_irq_handler(dev_priv);
2012 static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
2014 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
2015 ~SDE_PORTE_HOTPLUG_SPT;
2016 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
2017 u32 pin_mask = 0, long_mask = 0;
2019 if (hotplug_trigger) {
2020 u32 dig_hotplug_reg;
2022 dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
2023 intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, dig_hotplug_reg);
2025 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2026 hotplug_trigger, dig_hotplug_reg,
2027 dev_priv->hotplug.pch_hpd,
2028 spt_port_hotplug_long_detect);
2031 if (hotplug2_trigger) {
2032 u32 dig_hotplug_reg;
2034 dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG2);
2035 intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG2, dig_hotplug_reg);
2037 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2038 hotplug2_trigger, dig_hotplug_reg,
2039 dev_priv->hotplug.pch_hpd,
2040 spt_port_hotplug2_long_detect);
2044 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
2046 if (pch_iir & SDE_GMBUS_CPT)
2047 gmbus_irq_handler(dev_priv);
2050 static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv,
2051 u32 hotplug_trigger)
2053 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2055 dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, DIGITAL_PORT_HOTPLUG_CNTRL);
2056 intel_uncore_write(&dev_priv->uncore, DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
2058 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2059 hotplug_trigger, dig_hotplug_reg,
2060 dev_priv->hotplug.hpd,
2061 ilk_port_hotplug_long_detect);
2063 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
2066 static void ilk_display_irq_handler(struct drm_i915_private *dev_priv,
2070 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
2072 if (hotplug_trigger)
2073 ilk_hpd_irq_handler(dev_priv, hotplug_trigger);
2075 if (de_iir & DE_AUX_CHANNEL_A)
2076 dp_aux_irq_handler(dev_priv);
2078 if (de_iir & DE_GSE)
2079 intel_opregion_asle_intr(dev_priv);
2081 if (de_iir & DE_POISON)
2082 drm_err(&dev_priv->drm, "Poison interrupt\n");
2084 for_each_pipe(dev_priv, pipe) {
2085 if (de_iir & DE_PIPE_VBLANK(pipe))
2086 intel_handle_vblank(dev_priv, pipe);
2088 if (de_iir & DE_PLANE_FLIP_DONE(pipe))
2089 flip_done_handler(dev_priv, pipe);
2091 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
2092 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2094 if (de_iir & DE_PIPE_CRC_DONE(pipe))
2095 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
2098 /* check event from PCH */
2099 if (de_iir & DE_PCH_EVENT) {
2100 u32 pch_iir = intel_uncore_read(&dev_priv->uncore, SDEIIR);
2102 if (HAS_PCH_CPT(dev_priv))
2103 cpt_irq_handler(dev_priv, pch_iir);
2105 ibx_irq_handler(dev_priv, pch_iir);
2107 /* should clear PCH hotplug event before clear CPU irq */
2108 intel_uncore_write(&dev_priv->uncore, SDEIIR, pch_iir);
2111 if (DISPLAY_VER(dev_priv) == 5 && de_iir & DE_PCU_EVENT)
2112 gen5_rps_irq_handler(&to_gt(dev_priv)->rps);
2115 static void ivb_display_irq_handler(struct drm_i915_private *dev_priv,
2119 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
2121 if (hotplug_trigger)
2122 ilk_hpd_irq_handler(dev_priv, hotplug_trigger);
2124 if (de_iir & DE_ERR_INT_IVB)
2125 ivb_err_int_handler(dev_priv);
2127 if (de_iir & DE_AUX_CHANNEL_A_IVB)
2128 dp_aux_irq_handler(dev_priv);
2130 if (de_iir & DE_GSE_IVB)
2131 intel_opregion_asle_intr(dev_priv);
2133 for_each_pipe(dev_priv, pipe) {
2134 if (de_iir & DE_PIPE_VBLANK_IVB(pipe))
2135 intel_handle_vblank(dev_priv, pipe);
2137 if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe))
2138 flip_done_handler(dev_priv, pipe);
2141 /* check event from PCH */
2142 if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) {
2143 u32 pch_iir = intel_uncore_read(&dev_priv->uncore, SDEIIR);
2145 cpt_irq_handler(dev_priv, pch_iir);
2147 /* clear PCH hotplug event before clear CPU irq */
2148 intel_uncore_write(&dev_priv->uncore, SDEIIR, pch_iir);
2153 * To handle irqs with the minimum potential races with fresh interrupts, we:
2154 * 1 - Disable Master Interrupt Control.
2155 * 2 - Find the source(s) of the interrupt.
2156 * 3 - Clear the Interrupt Identity bits (IIR).
2157 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2158 * 5 - Re-enable Master Interrupt Control.
2160 static irqreturn_t ilk_irq_handler(int irq, void *arg)
2162 struct drm_i915_private *i915 = arg;
2163 void __iomem * const regs = i915->uncore.regs;
2164 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
2165 irqreturn_t ret = IRQ_NONE;
2167 if (unlikely(!intel_irqs_enabled(i915)))
2170 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2171 disable_rpm_wakeref_asserts(&i915->runtime_pm);
2173 /* disable master interrupt before clearing iir */
2174 de_ier = raw_reg_read(regs, DEIER);
2175 raw_reg_write(regs, DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
2177 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2178 * interrupts will will be stored on its back queue, and then we'll be
2179 * able to process them after we restore SDEIER (as soon as we restore
2180 * it, we'll get an interrupt if SDEIIR still has something to process
2181 * due to its back queue). */
2182 if (!HAS_PCH_NOP(i915)) {
2183 sde_ier = raw_reg_read(regs, SDEIER);
2184 raw_reg_write(regs, SDEIER, 0);
2187 /* Find, clear, then process each source of interrupt */
2189 gt_iir = raw_reg_read(regs, GTIIR);
2191 raw_reg_write(regs, GTIIR, gt_iir);
2192 if (GRAPHICS_VER(i915) >= 6)
2193 gen6_gt_irq_handler(to_gt(i915), gt_iir);
2195 gen5_gt_irq_handler(to_gt(i915), gt_iir);
2199 de_iir = raw_reg_read(regs, DEIIR);
2201 raw_reg_write(regs, DEIIR, de_iir);
2202 if (DISPLAY_VER(i915) >= 7)
2203 ivb_display_irq_handler(i915, de_iir);
2205 ilk_display_irq_handler(i915, de_iir);
2209 if (GRAPHICS_VER(i915) >= 6) {
2210 u32 pm_iir = raw_reg_read(regs, GEN6_PMIIR);
2212 raw_reg_write(regs, GEN6_PMIIR, pm_iir);
2213 gen6_rps_irq_handler(&to_gt(i915)->rps, pm_iir);
2218 raw_reg_write(regs, DEIER, de_ier);
2220 raw_reg_write(regs, SDEIER, sde_ier);
2222 pmu_irq_stats(i915, ret);
2224 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2225 enable_rpm_wakeref_asserts(&i915->runtime_pm);
2230 static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv,
2231 u32 hotplug_trigger)
2233 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2235 dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
2236 intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, dig_hotplug_reg);
2238 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2239 hotplug_trigger, dig_hotplug_reg,
2240 dev_priv->hotplug.hpd,
2241 bxt_port_hotplug_long_detect);
2243 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
2246 static void gen11_hpd_irq_handler(struct drm_i915_private *dev_priv, u32 iir)
2248 u32 pin_mask = 0, long_mask = 0;
2249 u32 trigger_tc = iir & GEN11_DE_TC_HOTPLUG_MASK;
2250 u32 trigger_tbt = iir & GEN11_DE_TBT_HOTPLUG_MASK;
2253 u32 dig_hotplug_reg;
2255 dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, GEN11_TC_HOTPLUG_CTL);
2256 intel_uncore_write(&dev_priv->uncore, GEN11_TC_HOTPLUG_CTL, dig_hotplug_reg);
2258 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2259 trigger_tc, dig_hotplug_reg,
2260 dev_priv->hotplug.hpd,
2261 gen11_port_hotplug_long_detect);
2265 u32 dig_hotplug_reg;
2267 dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, GEN11_TBT_HOTPLUG_CTL);
2268 intel_uncore_write(&dev_priv->uncore, GEN11_TBT_HOTPLUG_CTL, dig_hotplug_reg);
2270 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2271 trigger_tbt, dig_hotplug_reg,
2272 dev_priv->hotplug.hpd,
2273 gen11_port_hotplug_long_detect);
2277 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
2279 drm_err(&dev_priv->drm,
2280 "Unexpected DE HPD interrupt 0x%08x\n", iir);
2283 static u32 gen8_de_port_aux_mask(struct drm_i915_private *dev_priv)
2287 if (DISPLAY_VER(dev_priv) >= 13)
2288 return TGL_DE_PORT_AUX_DDIA |
2289 TGL_DE_PORT_AUX_DDIB |
2290 TGL_DE_PORT_AUX_DDIC |
2291 XELPD_DE_PORT_AUX_DDID |
2292 XELPD_DE_PORT_AUX_DDIE |
2293 TGL_DE_PORT_AUX_USBC1 |
2294 TGL_DE_PORT_AUX_USBC2 |
2295 TGL_DE_PORT_AUX_USBC3 |
2296 TGL_DE_PORT_AUX_USBC4;
2297 else if (DISPLAY_VER(dev_priv) >= 12)
2298 return TGL_DE_PORT_AUX_DDIA |
2299 TGL_DE_PORT_AUX_DDIB |
2300 TGL_DE_PORT_AUX_DDIC |
2301 TGL_DE_PORT_AUX_USBC1 |
2302 TGL_DE_PORT_AUX_USBC2 |
2303 TGL_DE_PORT_AUX_USBC3 |
2304 TGL_DE_PORT_AUX_USBC4 |
2305 TGL_DE_PORT_AUX_USBC5 |
2306 TGL_DE_PORT_AUX_USBC6;
2309 mask = GEN8_AUX_CHANNEL_A;
2310 if (DISPLAY_VER(dev_priv) >= 9)
2311 mask |= GEN9_AUX_CHANNEL_B |
2312 GEN9_AUX_CHANNEL_C |
2315 if (DISPLAY_VER(dev_priv) == 11) {
2316 mask |= ICL_AUX_CHANNEL_F;
2317 mask |= ICL_AUX_CHANNEL_E;
2323 static u32 gen8_de_pipe_fault_mask(struct drm_i915_private *dev_priv)
2325 if (DISPLAY_VER(dev_priv) >= 13 || HAS_D12_PLANE_MINIMIZATION(dev_priv))
2326 return RKL_DE_PIPE_IRQ_FAULT_ERRORS;
2327 else if (DISPLAY_VER(dev_priv) >= 11)
2328 return GEN11_DE_PIPE_IRQ_FAULT_ERRORS;
2329 else if (DISPLAY_VER(dev_priv) >= 9)
2330 return GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2332 return GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2336 gen8_de_misc_irq_handler(struct drm_i915_private *dev_priv, u32 iir)
2340 if (iir & GEN8_DE_MISC_GSE) {
2341 intel_opregion_asle_intr(dev_priv);
2345 if (iir & GEN8_DE_EDP_PSR) {
2346 struct intel_encoder *encoder;
2350 for_each_intel_encoder_with_psr(&dev_priv->drm, encoder) {
2351 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2353 if (DISPLAY_VER(dev_priv) >= 12)
2354 iir_reg = TRANS_PSR_IIR(intel_dp->psr.transcoder);
2356 iir_reg = EDP_PSR_IIR;
2358 psr_iir = intel_uncore_read(&dev_priv->uncore, iir_reg);
2359 intel_uncore_write(&dev_priv->uncore, iir_reg, psr_iir);
2364 intel_psr_irq_handler(intel_dp, psr_iir);
2366 /* prior GEN12 only have one EDP PSR */
2367 if (DISPLAY_VER(dev_priv) < 12)
2373 drm_err(&dev_priv->drm, "Unexpected DE Misc interrupt\n");
2376 static void gen11_dsi_te_interrupt_handler(struct drm_i915_private *dev_priv,
2379 enum pipe pipe = INVALID_PIPE;
2380 enum transcoder dsi_trans;
2385 * Incase of dual link, TE comes from DSI_1
2386 * this is to check if dual link is enabled
2388 val = intel_uncore_read(&dev_priv->uncore, TRANS_DDI_FUNC_CTL2(TRANSCODER_DSI_0));
2389 val &= PORT_SYNC_MODE_ENABLE;
2392 * if dual link is enabled, then read DSI_0
2393 * transcoder registers
2395 port = ((te_trigger & DSI1_TE && val) || (te_trigger & DSI0_TE)) ?
2397 dsi_trans = (port == PORT_A) ? TRANSCODER_DSI_0 : TRANSCODER_DSI_1;
2399 /* Check if DSI configured in command mode */
2400 val = intel_uncore_read(&dev_priv->uncore, DSI_TRANS_FUNC_CONF(dsi_trans));
2401 val = val & OP_MODE_MASK;
2403 if (val != CMD_MODE_NO_GATE && val != CMD_MODE_TE_GATE) {
2404 drm_err(&dev_priv->drm, "DSI trancoder not configured in command mode\n");
2408 /* Get PIPE for handling VBLANK event */
2409 val = intel_uncore_read(&dev_priv->uncore, TRANS_DDI_FUNC_CTL(dsi_trans));
2410 switch (val & TRANS_DDI_EDP_INPUT_MASK) {
2411 case TRANS_DDI_EDP_INPUT_A_ON:
2414 case TRANS_DDI_EDP_INPUT_B_ONOFF:
2417 case TRANS_DDI_EDP_INPUT_C_ONOFF:
2421 drm_err(&dev_priv->drm, "Invalid PIPE\n");
2425 intel_handle_vblank(dev_priv, pipe);
2427 /* clear TE in dsi IIR */
2428 port = (te_trigger & DSI1_TE) ? PORT_B : PORT_A;
2429 tmp = intel_uncore_read(&dev_priv->uncore, DSI_INTR_IDENT_REG(port));
2430 intel_uncore_write(&dev_priv->uncore, DSI_INTR_IDENT_REG(port), tmp);
2433 static u32 gen8_de_pipe_flip_done_mask(struct drm_i915_private *i915)
2435 if (DISPLAY_VER(i915) >= 9)
2436 return GEN9_PIPE_PLANE1_FLIP_DONE;
2438 return GEN8_PIPE_PRIMARY_FLIP_DONE;
2441 u32 gen8_de_pipe_underrun_mask(struct drm_i915_private *dev_priv)
2443 u32 mask = GEN8_PIPE_FIFO_UNDERRUN;
2445 if (DISPLAY_VER(dev_priv) >= 13)
2446 mask |= XELPD_PIPE_SOFT_UNDERRUN |
2447 XELPD_PIPE_HARD_UNDERRUN;
2453 gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl)
2455 irqreturn_t ret = IRQ_NONE;
2459 drm_WARN_ON_ONCE(&dev_priv->drm, !HAS_DISPLAY(dev_priv));
2461 if (master_ctl & GEN8_DE_MISC_IRQ) {
2462 iir = intel_uncore_read(&dev_priv->uncore, GEN8_DE_MISC_IIR);
2464 intel_uncore_write(&dev_priv->uncore, GEN8_DE_MISC_IIR, iir);
2466 gen8_de_misc_irq_handler(dev_priv, iir);
2468 drm_err(&dev_priv->drm,
2469 "The master control interrupt lied (DE MISC)!\n");
2473 if (DISPLAY_VER(dev_priv) >= 11 && (master_ctl & GEN11_DE_HPD_IRQ)) {
2474 iir = intel_uncore_read(&dev_priv->uncore, GEN11_DE_HPD_IIR);
2476 intel_uncore_write(&dev_priv->uncore, GEN11_DE_HPD_IIR, iir);
2478 gen11_hpd_irq_handler(dev_priv, iir);
2480 drm_err(&dev_priv->drm,
2481 "The master control interrupt lied, (DE HPD)!\n");
2485 if (master_ctl & GEN8_DE_PORT_IRQ) {
2486 iir = intel_uncore_read(&dev_priv->uncore, GEN8_DE_PORT_IIR);
2490 intel_uncore_write(&dev_priv->uncore, GEN8_DE_PORT_IIR, iir);
2493 if (iir & gen8_de_port_aux_mask(dev_priv)) {
2494 dp_aux_irq_handler(dev_priv);
2498 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
2499 u32 hotplug_trigger = iir & BXT_DE_PORT_HOTPLUG_MASK;
2501 if (hotplug_trigger) {
2502 bxt_hpd_irq_handler(dev_priv, hotplug_trigger);
2505 } else if (IS_BROADWELL(dev_priv)) {
2506 u32 hotplug_trigger = iir & BDW_DE_PORT_HOTPLUG_MASK;
2508 if (hotplug_trigger) {
2509 ilk_hpd_irq_handler(dev_priv, hotplug_trigger);
2514 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
2515 (iir & BXT_DE_PORT_GMBUS)) {
2516 gmbus_irq_handler(dev_priv);
2520 if (DISPLAY_VER(dev_priv) >= 11) {
2521 u32 te_trigger = iir & (DSI0_TE | DSI1_TE);
2524 gen11_dsi_te_interrupt_handler(dev_priv, te_trigger);
2530 drm_err(&dev_priv->drm,
2531 "Unexpected DE Port interrupt\n");
2534 drm_err(&dev_priv->drm,
2535 "The master control interrupt lied (DE PORT)!\n");
2538 for_each_pipe(dev_priv, pipe) {
2541 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2544 iir = intel_uncore_read(&dev_priv->uncore, GEN8_DE_PIPE_IIR(pipe));
2546 drm_err(&dev_priv->drm,
2547 "The master control interrupt lied (DE PIPE)!\n");
2552 intel_uncore_write(&dev_priv->uncore, GEN8_DE_PIPE_IIR(pipe), iir);
2554 if (iir & GEN8_PIPE_VBLANK)
2555 intel_handle_vblank(dev_priv, pipe);
2557 if (iir & gen8_de_pipe_flip_done_mask(dev_priv))
2558 flip_done_handler(dev_priv, pipe);
2560 if (iir & GEN8_PIPE_CDCLK_CRC_DONE)
2561 hsw_pipe_crc_irq_handler(dev_priv, pipe);
2563 if (iir & gen8_de_pipe_underrun_mask(dev_priv))
2564 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2566 fault_errors = iir & gen8_de_pipe_fault_mask(dev_priv);
2568 drm_err(&dev_priv->drm,
2569 "Fault errors on pipe %c: 0x%08x\n",
2574 if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) &&
2575 master_ctl & GEN8_DE_PCH_IRQ) {
2577 * FIXME(BDW): Assume for now that the new interrupt handling
2578 * scheme also closed the SDE interrupt handling race we've seen
2579 * on older pch-split platforms. But this needs testing.
2581 iir = intel_uncore_read(&dev_priv->uncore, SDEIIR);
2583 intel_uncore_write(&dev_priv->uncore, SDEIIR, iir);
2586 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
2587 icp_irq_handler(dev_priv, iir);
2588 else if (INTEL_PCH_TYPE(dev_priv) >= PCH_SPT)
2589 spt_irq_handler(dev_priv, iir);
2591 cpt_irq_handler(dev_priv, iir);
2594 * Like on previous PCH there seems to be something
2595 * fishy going on with forwarding PCH interrupts.
2597 drm_dbg(&dev_priv->drm,
2598 "The master control interrupt lied (SDE)!\n");
2605 static inline u32 gen8_master_intr_disable(void __iomem * const regs)
2607 raw_reg_write(regs, GEN8_MASTER_IRQ, 0);
2610 * Now with master disabled, get a sample of level indications
2611 * for this interrupt. Indications will be cleared on related acks.
2612 * New indications can and will light up during processing,
2613 * and will generate new interrupt after enabling master.
2615 return raw_reg_read(regs, GEN8_MASTER_IRQ);
2618 static inline void gen8_master_intr_enable(void __iomem * const regs)
2620 raw_reg_write(regs, GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2623 static irqreturn_t gen8_irq_handler(int irq, void *arg)
2625 struct drm_i915_private *dev_priv = arg;
2626 void __iomem * const regs = dev_priv->uncore.regs;
2629 if (!intel_irqs_enabled(dev_priv))
2632 master_ctl = gen8_master_intr_disable(regs);
2634 gen8_master_intr_enable(regs);
2638 /* Find, queue (onto bottom-halves), then clear each source */
2639 gen8_gt_irq_handler(to_gt(dev_priv), master_ctl);
2641 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2642 if (master_ctl & ~GEN8_GT_IRQS) {
2643 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
2644 gen8_de_irq_handler(dev_priv, master_ctl);
2645 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
2648 gen8_master_intr_enable(regs);
2650 pmu_irq_stats(dev_priv, IRQ_HANDLED);
2656 gen11_gu_misc_irq_ack(struct intel_gt *gt, const u32 master_ctl)
2658 void __iomem * const regs = gt->uncore->regs;
2661 if (!(master_ctl & GEN11_GU_MISC_IRQ))
2664 iir = raw_reg_read(regs, GEN11_GU_MISC_IIR);
2666 raw_reg_write(regs, GEN11_GU_MISC_IIR, iir);
2672 gen11_gu_misc_irq_handler(struct intel_gt *gt, const u32 iir)
2674 if (iir & GEN11_GU_MISC_GSE)
2675 intel_opregion_asle_intr(gt->i915);
2678 static inline u32 gen11_master_intr_disable(void __iomem * const regs)
2680 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, 0);
2683 * Now with master disabled, get a sample of level indications
2684 * for this interrupt. Indications will be cleared on related acks.
2685 * New indications can and will light up during processing,
2686 * and will generate new interrupt after enabling master.
2688 return raw_reg_read(regs, GEN11_GFX_MSTR_IRQ);
2691 static inline void gen11_master_intr_enable(void __iomem * const regs)
2693 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, GEN11_MASTER_IRQ);
2697 gen11_display_irq_handler(struct drm_i915_private *i915)
2699 void __iomem * const regs = i915->uncore.regs;
2700 const u32 disp_ctl = raw_reg_read(regs, GEN11_DISPLAY_INT_CTL);
2702 disable_rpm_wakeref_asserts(&i915->runtime_pm);
2704 * GEN11_DISPLAY_INT_CTL has same format as GEN8_MASTER_IRQ
2705 * for the display related bits.
2707 raw_reg_write(regs, GEN11_DISPLAY_INT_CTL, 0x0);
2708 gen8_de_irq_handler(i915, disp_ctl);
2709 raw_reg_write(regs, GEN11_DISPLAY_INT_CTL,
2710 GEN11_DISPLAY_IRQ_ENABLE);
2712 enable_rpm_wakeref_asserts(&i915->runtime_pm);
2715 static irqreturn_t gen11_irq_handler(int irq, void *arg)
2717 struct drm_i915_private *i915 = arg;
2718 void __iomem * const regs = i915->uncore.regs;
2719 struct intel_gt *gt = to_gt(i915);
2723 if (!intel_irqs_enabled(i915))
2726 master_ctl = gen11_master_intr_disable(regs);
2728 gen11_master_intr_enable(regs);
2732 /* Find, queue (onto bottom-halves), then clear each source */
2733 gen11_gt_irq_handler(gt, master_ctl);
2735 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2736 if (master_ctl & GEN11_DISPLAY_IRQ)
2737 gen11_display_irq_handler(i915);
2739 gu_misc_iir = gen11_gu_misc_irq_ack(gt, master_ctl);
2741 gen11_master_intr_enable(regs);
2743 gen11_gu_misc_irq_handler(gt, gu_misc_iir);
2745 pmu_irq_stats(i915, IRQ_HANDLED);
2750 static inline u32 dg1_master_intr_disable(void __iomem * const regs)
2754 /* First disable interrupts */
2755 raw_reg_write(regs, DG1_MSTR_TILE_INTR, 0);
2757 /* Get the indication levels and ack the master unit */
2758 val = raw_reg_read(regs, DG1_MSTR_TILE_INTR);
2762 raw_reg_write(regs, DG1_MSTR_TILE_INTR, val);
2767 static inline void dg1_master_intr_enable(void __iomem * const regs)
2769 raw_reg_write(regs, DG1_MSTR_TILE_INTR, DG1_MSTR_IRQ);
2772 static irqreturn_t dg1_irq_handler(int irq, void *arg)
2774 struct drm_i915_private * const i915 = arg;
2775 struct intel_gt *gt = to_gt(i915);
2776 void __iomem * const regs = gt->uncore->regs;
2777 u32 master_tile_ctl, master_ctl;
2780 if (!intel_irqs_enabled(i915))
2783 master_tile_ctl = dg1_master_intr_disable(regs);
2784 if (!master_tile_ctl) {
2785 dg1_master_intr_enable(regs);
2789 /* FIXME: we only support tile 0 for now. */
2790 if (master_tile_ctl & DG1_MSTR_TILE(0)) {
2791 master_ctl = raw_reg_read(regs, GEN11_GFX_MSTR_IRQ);
2792 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, master_ctl);
2794 DRM_ERROR("Tile not supported: 0x%08x\n", master_tile_ctl);
2795 dg1_master_intr_enable(regs);
2799 gen11_gt_irq_handler(gt, master_ctl);
2801 if (master_ctl & GEN11_DISPLAY_IRQ)
2802 gen11_display_irq_handler(i915);
2804 gu_misc_iir = gen11_gu_misc_irq_ack(gt, master_ctl);
2806 dg1_master_intr_enable(regs);
2808 gen11_gu_misc_irq_handler(gt, gu_misc_iir);
2810 pmu_irq_stats(i915, IRQ_HANDLED);
2815 /* Called from drm generic code, passed 'crtc' which
2816 * we use as a pipe index
2818 int i8xx_enable_vblank(struct drm_crtc *crtc)
2820 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2821 enum pipe pipe = to_intel_crtc(crtc)->pipe;
2822 unsigned long irqflags;
2824 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2825 i915_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
2826 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2831 int i915gm_enable_vblank(struct drm_crtc *crtc)
2833 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2836 * Vblank interrupts fail to wake the device up from C2+.
2837 * Disabling render clock gating during C-states avoids
2838 * the problem. There is a small power cost so we do this
2839 * only when vblank interrupts are actually enabled.
2841 if (dev_priv->vblank_enabled++ == 0)
2842 intel_uncore_write(&dev_priv->uncore, SCPD0, _MASKED_BIT_ENABLE(CSTATE_RENDER_CLOCK_GATE_DISABLE));
2844 return i8xx_enable_vblank(crtc);
2847 int i965_enable_vblank(struct drm_crtc *crtc)
2849 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2850 enum pipe pipe = to_intel_crtc(crtc)->pipe;
2851 unsigned long irqflags;
2853 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2854 i915_enable_pipestat(dev_priv, pipe,
2855 PIPE_START_VBLANK_INTERRUPT_STATUS);
2856 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2861 int ilk_enable_vblank(struct drm_crtc *crtc)
2863 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2864 enum pipe pipe = to_intel_crtc(crtc)->pipe;
2865 unsigned long irqflags;
2866 u32 bit = DISPLAY_VER(dev_priv) >= 7 ?
2867 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
2869 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2870 ilk_enable_display_irq(dev_priv, bit);
2871 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2873 /* Even though there is no DMC, frame counter can get stuck when
2874 * PSR is active as no frames are generated.
2876 if (HAS_PSR(dev_priv))
2877 drm_crtc_vblank_restore(crtc);
2882 static bool gen11_dsi_configure_te(struct intel_crtc *intel_crtc,
2885 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
2889 if (!(intel_crtc->mode_flags &
2890 (I915_MODE_FLAG_DSI_USE_TE1 | I915_MODE_FLAG_DSI_USE_TE0)))
2893 /* for dual link cases we consider TE from slave */
2894 if (intel_crtc->mode_flags & I915_MODE_FLAG_DSI_USE_TE1)
2899 tmp = intel_uncore_read(&dev_priv->uncore, DSI_INTR_MASK_REG(port));
2901 tmp &= ~DSI_TE_EVENT;
2903 tmp |= DSI_TE_EVENT;
2905 intel_uncore_write(&dev_priv->uncore, DSI_INTR_MASK_REG(port), tmp);
2907 tmp = intel_uncore_read(&dev_priv->uncore, DSI_INTR_IDENT_REG(port));
2908 intel_uncore_write(&dev_priv->uncore, DSI_INTR_IDENT_REG(port), tmp);
2913 int bdw_enable_vblank(struct drm_crtc *_crtc)
2915 struct intel_crtc *crtc = to_intel_crtc(_crtc);
2916 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2917 enum pipe pipe = crtc->pipe;
2918 unsigned long irqflags;
2920 if (gen11_dsi_configure_te(crtc, true))
2923 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2924 bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
2925 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2927 /* Even if there is no DMC, frame counter can get stuck when
2928 * PSR is active as no frames are generated, so check only for PSR.
2930 if (HAS_PSR(dev_priv))
2931 drm_crtc_vblank_restore(&crtc->base);
2936 /* Called from drm generic code, passed 'crtc' which
2937 * we use as a pipe index
2939 void i8xx_disable_vblank(struct drm_crtc *crtc)
2941 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2942 enum pipe pipe = to_intel_crtc(crtc)->pipe;
2943 unsigned long irqflags;
2945 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2946 i915_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
2947 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2950 void i915gm_disable_vblank(struct drm_crtc *crtc)
2952 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2954 i8xx_disable_vblank(crtc);
2956 if (--dev_priv->vblank_enabled == 0)
2957 intel_uncore_write(&dev_priv->uncore, SCPD0, _MASKED_BIT_DISABLE(CSTATE_RENDER_CLOCK_GATE_DISABLE));
2960 void i965_disable_vblank(struct drm_crtc *crtc)
2962 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2963 enum pipe pipe = to_intel_crtc(crtc)->pipe;
2964 unsigned long irqflags;
2966 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2967 i915_disable_pipestat(dev_priv, pipe,
2968 PIPE_START_VBLANK_INTERRUPT_STATUS);
2969 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2972 void ilk_disable_vblank(struct drm_crtc *crtc)
2974 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2975 enum pipe pipe = to_intel_crtc(crtc)->pipe;
2976 unsigned long irqflags;
2977 u32 bit = DISPLAY_VER(dev_priv) >= 7 ?
2978 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
2980 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2981 ilk_disable_display_irq(dev_priv, bit);
2982 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2985 void bdw_disable_vblank(struct drm_crtc *_crtc)
2987 struct intel_crtc *crtc = to_intel_crtc(_crtc);
2988 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2989 enum pipe pipe = crtc->pipe;
2990 unsigned long irqflags;
2992 if (gen11_dsi_configure_te(crtc, false))
2995 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2996 bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
2997 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3000 static void ibx_irq_reset(struct drm_i915_private *dev_priv)
3002 struct intel_uncore *uncore = &dev_priv->uncore;
3004 if (HAS_PCH_NOP(dev_priv))
3007 GEN3_IRQ_RESET(uncore, SDE);
3009 if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
3010 intel_uncore_write(&dev_priv->uncore, SERR_INT, 0xffffffff);
3013 static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3015 struct intel_uncore *uncore = &dev_priv->uncore;
3017 if (IS_CHERRYVIEW(dev_priv))
3018 intel_uncore_write(uncore, DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3020 intel_uncore_write(uncore, DPINVGTT, DPINVGTT_STATUS_MASK_VLV);
3022 i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0);
3023 intel_uncore_write(uncore, PORT_HOTPLUG_STAT, intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT));
3025 i9xx_pipestat_irq_reset(dev_priv);
3027 GEN3_IRQ_RESET(uncore, VLV_);
3028 dev_priv->irq_mask = ~0u;
3031 static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
3033 struct intel_uncore *uncore = &dev_priv->uncore;
3039 pipestat_mask = PIPE_CRC_DONE_INTERRUPT_STATUS;
3041 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3042 for_each_pipe(dev_priv, pipe)
3043 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
3045 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3046 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3047 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3048 I915_LPE_PIPE_A_INTERRUPT |
3049 I915_LPE_PIPE_B_INTERRUPT;
3051 if (IS_CHERRYVIEW(dev_priv))
3052 enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT |
3053 I915_LPE_PIPE_C_INTERRUPT;
3055 drm_WARN_ON(&dev_priv->drm, dev_priv->irq_mask != ~0u);
3057 dev_priv->irq_mask = ~enable_mask;
3059 GEN3_IRQ_INIT(uncore, VLV_, dev_priv->irq_mask, enable_mask);
3064 static void ilk_irq_reset(struct drm_i915_private *dev_priv)
3066 struct intel_uncore *uncore = &dev_priv->uncore;
3068 GEN3_IRQ_RESET(uncore, DE);
3069 dev_priv->irq_mask = ~0u;
3071 if (GRAPHICS_VER(dev_priv) == 7)
3072 intel_uncore_write(uncore, GEN7_ERR_INT, 0xffffffff);
3074 if (IS_HASWELL(dev_priv)) {
3075 intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff);
3076 intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff);
3079 gen5_gt_irq_reset(to_gt(dev_priv));
3081 ibx_irq_reset(dev_priv);
3084 static void valleyview_irq_reset(struct drm_i915_private *dev_priv)
3086 intel_uncore_write(&dev_priv->uncore, VLV_MASTER_IER, 0);
3087 intel_uncore_posting_read(&dev_priv->uncore, VLV_MASTER_IER);
3089 gen5_gt_irq_reset(to_gt(dev_priv));
3091 spin_lock_irq(&dev_priv->irq_lock);
3092 if (dev_priv->display_irqs_enabled)
3093 vlv_display_irq_reset(dev_priv);
3094 spin_unlock_irq(&dev_priv->irq_lock);
3097 static void gen8_display_irq_reset(struct drm_i915_private *dev_priv)
3099 struct intel_uncore *uncore = &dev_priv->uncore;
3102 if (!HAS_DISPLAY(dev_priv))
3105 intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff);
3106 intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff);
3108 for_each_pipe(dev_priv, pipe)
3109 if (intel_display_power_is_enabled(dev_priv,
3110 POWER_DOMAIN_PIPE(pipe)))
3111 GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe);
3113 GEN3_IRQ_RESET(uncore, GEN8_DE_PORT_);
3114 GEN3_IRQ_RESET(uncore, GEN8_DE_MISC_);
3117 static void gen8_irq_reset(struct drm_i915_private *dev_priv)
3119 struct intel_uncore *uncore = &dev_priv->uncore;
3121 gen8_master_intr_disable(dev_priv->uncore.regs);
3123 gen8_gt_irq_reset(to_gt(dev_priv));
3124 gen8_display_irq_reset(dev_priv);
3125 GEN3_IRQ_RESET(uncore, GEN8_PCU_);
3127 if (HAS_PCH_SPLIT(dev_priv))
3128 ibx_irq_reset(dev_priv);
3132 static void gen11_display_irq_reset(struct drm_i915_private *dev_priv)
3134 struct intel_uncore *uncore = &dev_priv->uncore;
3136 u32 trans_mask = BIT(TRANSCODER_A) | BIT(TRANSCODER_B) |
3137 BIT(TRANSCODER_C) | BIT(TRANSCODER_D);
3139 if (!HAS_DISPLAY(dev_priv))
3142 intel_uncore_write(uncore, GEN11_DISPLAY_INT_CTL, 0);
3144 if (DISPLAY_VER(dev_priv) >= 12) {
3145 enum transcoder trans;
3147 for_each_cpu_transcoder_masked(dev_priv, trans, trans_mask) {
3148 enum intel_display_power_domain domain;
3150 domain = POWER_DOMAIN_TRANSCODER(trans);
3151 if (!intel_display_power_is_enabled(dev_priv, domain))
3154 intel_uncore_write(uncore, TRANS_PSR_IMR(trans), 0xffffffff);
3155 intel_uncore_write(uncore, TRANS_PSR_IIR(trans), 0xffffffff);
3158 intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff);
3159 intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff);
3162 for_each_pipe(dev_priv, pipe)
3163 if (intel_display_power_is_enabled(dev_priv,
3164 POWER_DOMAIN_PIPE(pipe)))
3165 GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe);
3167 GEN3_IRQ_RESET(uncore, GEN8_DE_PORT_);
3168 GEN3_IRQ_RESET(uncore, GEN8_DE_MISC_);
3169 GEN3_IRQ_RESET(uncore, GEN11_DE_HPD_);
3171 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
3172 GEN3_IRQ_RESET(uncore, SDE);
3175 static void gen11_irq_reset(struct drm_i915_private *dev_priv)
3177 struct intel_gt *gt = to_gt(dev_priv);
3178 struct intel_uncore *uncore = gt->uncore;
3180 gen11_master_intr_disable(dev_priv->uncore.regs);
3182 gen11_gt_irq_reset(gt);
3183 gen11_display_irq_reset(dev_priv);
3185 GEN3_IRQ_RESET(uncore, GEN11_GU_MISC_);
3186 GEN3_IRQ_RESET(uncore, GEN8_PCU_);
3189 static void dg1_irq_reset(struct drm_i915_private *dev_priv)
3191 struct intel_gt *gt = to_gt(dev_priv);
3192 struct intel_uncore *uncore = gt->uncore;
3194 dg1_master_intr_disable(dev_priv->uncore.regs);
3196 gen11_gt_irq_reset(gt);
3197 gen11_display_irq_reset(dev_priv);
3199 GEN3_IRQ_RESET(uncore, GEN11_GU_MISC_);
3200 GEN3_IRQ_RESET(uncore, GEN8_PCU_);
3203 void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
3206 struct intel_uncore *uncore = &dev_priv->uncore;
3207 u32 extra_ier = GEN8_PIPE_VBLANK |
3208 gen8_de_pipe_underrun_mask(dev_priv) |
3209 gen8_de_pipe_flip_done_mask(dev_priv);
3212 spin_lock_irq(&dev_priv->irq_lock);
3214 if (!intel_irqs_enabled(dev_priv)) {
3215 spin_unlock_irq(&dev_priv->irq_lock);
3219 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3220 GEN8_IRQ_INIT_NDX(uncore, DE_PIPE, pipe,
3221 dev_priv->de_irq_mask[pipe],
3222 ~dev_priv->de_irq_mask[pipe] | extra_ier);
3224 spin_unlock_irq(&dev_priv->irq_lock);
3227 void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv,
3230 struct intel_uncore *uncore = &dev_priv->uncore;
3233 spin_lock_irq(&dev_priv->irq_lock);
3235 if (!intel_irqs_enabled(dev_priv)) {
3236 spin_unlock_irq(&dev_priv->irq_lock);
3240 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3241 GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe);
3243 spin_unlock_irq(&dev_priv->irq_lock);
3245 /* make sure we're done processing display irqs */
3246 intel_synchronize_irq(dev_priv);
3249 static void cherryview_irq_reset(struct drm_i915_private *dev_priv)
3251 struct intel_uncore *uncore = &dev_priv->uncore;
3253 intel_uncore_write(&dev_priv->uncore, GEN8_MASTER_IRQ, 0);
3254 intel_uncore_posting_read(&dev_priv->uncore, GEN8_MASTER_IRQ);
3256 gen8_gt_irq_reset(to_gt(dev_priv));
3258 GEN3_IRQ_RESET(uncore, GEN8_PCU_);
3260 spin_lock_irq(&dev_priv->irq_lock);
3261 if (dev_priv->display_irqs_enabled)
3262 vlv_display_irq_reset(dev_priv);
3263 spin_unlock_irq(&dev_priv->irq_lock);
3266 static u32 ibx_hotplug_enables(struct drm_i915_private *i915,
3272 * When CPU and PCH are on the same package, port A
3273 * HPD must be enabled in both north and south.
3275 return HAS_PCH_LPT_LP(i915) ?
3276 PORTA_HOTPLUG_ENABLE : 0;
3278 return PORTB_HOTPLUG_ENABLE |
3279 PORTB_PULSE_DURATION_2ms;
3281 return PORTC_HOTPLUG_ENABLE |
3282 PORTC_PULSE_DURATION_2ms;
3284 return PORTD_HOTPLUG_ENABLE |
3285 PORTD_PULSE_DURATION_2ms;
3291 static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv)
3296 * Enable digital hotplug on the PCH, and configure the DP short pulse
3297 * duration to 2ms (which is the minimum in the Display Port spec).
3298 * The pulse duration bits are reserved on LPT+.
3300 hotplug = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
3301 hotplug &= ~(PORTA_HOTPLUG_ENABLE |
3302 PORTB_HOTPLUG_ENABLE |
3303 PORTC_HOTPLUG_ENABLE |
3304 PORTD_HOTPLUG_ENABLE |
3305 PORTB_PULSE_DURATION_MASK |
3306 PORTC_PULSE_DURATION_MASK |
3307 PORTD_PULSE_DURATION_MASK);
3308 hotplug |= intel_hpd_hotplug_enables(dev_priv, ibx_hotplug_enables);
3309 intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, hotplug);
3312 static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
3314 u32 hotplug_irqs, enabled_irqs;
3316 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->hotplug.pch_hpd);
3317 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->hotplug.pch_hpd);
3319 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3321 ibx_hpd_detection_setup(dev_priv);
3324 static u32 icp_ddi_hotplug_enables(struct drm_i915_private *i915,
3332 return SHOTPLUG_CTL_DDI_HPD_ENABLE(pin);
3338 static u32 icp_tc_hotplug_enables(struct drm_i915_private *i915,
3348 return ICP_TC_HPD_ENABLE(pin);
3354 static void icp_ddi_hpd_detection_setup(struct drm_i915_private *dev_priv)
3358 hotplug = intel_uncore_read(&dev_priv->uncore, SHOTPLUG_CTL_DDI);
3359 hotplug &= ~(SHOTPLUG_CTL_DDI_HPD_ENABLE(HPD_PORT_A) |
3360 SHOTPLUG_CTL_DDI_HPD_ENABLE(HPD_PORT_B) |
3361 SHOTPLUG_CTL_DDI_HPD_ENABLE(HPD_PORT_C) |
3362 SHOTPLUG_CTL_DDI_HPD_ENABLE(HPD_PORT_D));
3363 hotplug |= intel_hpd_hotplug_enables(dev_priv, icp_ddi_hotplug_enables);
3364 intel_uncore_write(&dev_priv->uncore, SHOTPLUG_CTL_DDI, hotplug);
3367 static void icp_tc_hpd_detection_setup(struct drm_i915_private *dev_priv)
3371 hotplug = intel_uncore_read(&dev_priv->uncore, SHOTPLUG_CTL_TC);
3372 hotplug &= ~(ICP_TC_HPD_ENABLE(HPD_PORT_TC1) |
3373 ICP_TC_HPD_ENABLE(HPD_PORT_TC2) |
3374 ICP_TC_HPD_ENABLE(HPD_PORT_TC3) |
3375 ICP_TC_HPD_ENABLE(HPD_PORT_TC4) |
3376 ICP_TC_HPD_ENABLE(HPD_PORT_TC5) |
3377 ICP_TC_HPD_ENABLE(HPD_PORT_TC6));
3378 hotplug |= intel_hpd_hotplug_enables(dev_priv, icp_tc_hotplug_enables);
3379 intel_uncore_write(&dev_priv->uncore, SHOTPLUG_CTL_TC, hotplug);
3382 static void icp_hpd_irq_setup(struct drm_i915_private *dev_priv)
3384 u32 hotplug_irqs, enabled_irqs;
3386 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->hotplug.pch_hpd);
3387 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->hotplug.pch_hpd);
3389 if (INTEL_PCH_TYPE(dev_priv) <= PCH_TGP)
3390 intel_uncore_write(&dev_priv->uncore, SHPD_FILTER_CNT, SHPD_FILTER_CNT_500_ADJ);
3392 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3394 icp_ddi_hpd_detection_setup(dev_priv);
3395 icp_tc_hpd_detection_setup(dev_priv);
3398 static u32 gen11_hotplug_enables(struct drm_i915_private *i915,
3408 return GEN11_HOTPLUG_CTL_ENABLE(pin);
3414 static void dg1_hpd_irq_setup(struct drm_i915_private *dev_priv)
3418 val = intel_uncore_read(&dev_priv->uncore, SOUTH_CHICKEN1);
3419 val |= (INVERT_DDIA_HPD |
3423 intel_uncore_write(&dev_priv->uncore, SOUTH_CHICKEN1, val);
3425 icp_hpd_irq_setup(dev_priv);
3428 static void gen11_tc_hpd_detection_setup(struct drm_i915_private *dev_priv)
3432 hotplug = intel_uncore_read(&dev_priv->uncore, GEN11_TC_HOTPLUG_CTL);
3433 hotplug &= ~(GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC1) |
3434 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC2) |
3435 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC3) |
3436 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC4) |
3437 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC5) |
3438 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC6));
3439 hotplug |= intel_hpd_hotplug_enables(dev_priv, gen11_hotplug_enables);
3440 intel_uncore_write(&dev_priv->uncore, GEN11_TC_HOTPLUG_CTL, hotplug);
3443 static void gen11_tbt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3447 hotplug = intel_uncore_read(&dev_priv->uncore, GEN11_TBT_HOTPLUG_CTL);
3448 hotplug &= ~(GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC1) |
3449 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC2) |
3450 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC3) |
3451 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC4) |
3452 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC5) |
3453 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC6));
3454 hotplug |= intel_hpd_hotplug_enables(dev_priv, gen11_hotplug_enables);
3455 intel_uncore_write(&dev_priv->uncore, GEN11_TBT_HOTPLUG_CTL, hotplug);
3458 static void gen11_hpd_irq_setup(struct drm_i915_private *dev_priv)
3460 u32 hotplug_irqs, enabled_irqs;
3463 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->hotplug.hpd);
3464 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->hotplug.hpd);
3466 val = intel_uncore_read(&dev_priv->uncore, GEN11_DE_HPD_IMR);
3467 val &= ~hotplug_irqs;
3468 val |= ~enabled_irqs & hotplug_irqs;
3469 intel_uncore_write(&dev_priv->uncore, GEN11_DE_HPD_IMR, val);
3470 intel_uncore_posting_read(&dev_priv->uncore, GEN11_DE_HPD_IMR);
3472 gen11_tc_hpd_detection_setup(dev_priv);
3473 gen11_tbt_hpd_detection_setup(dev_priv);
3475 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
3476 icp_hpd_irq_setup(dev_priv);
3479 static u32 spt_hotplug_enables(struct drm_i915_private *i915,
3484 return PORTA_HOTPLUG_ENABLE;
3486 return PORTB_HOTPLUG_ENABLE;
3488 return PORTC_HOTPLUG_ENABLE;
3490 return PORTD_HOTPLUG_ENABLE;
3496 static u32 spt_hotplug2_enables(struct drm_i915_private *i915,
3501 return PORTE_HOTPLUG_ENABLE;
3507 static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3511 /* Display WA #1179 WaHardHangonHotPlug: cnp */
3512 if (HAS_PCH_CNP(dev_priv)) {
3513 val = intel_uncore_read(&dev_priv->uncore, SOUTH_CHICKEN1);
3514 val &= ~CHASSIS_CLK_REQ_DURATION_MASK;
3515 val |= CHASSIS_CLK_REQ_DURATION(0xf);
3516 intel_uncore_write(&dev_priv->uncore, SOUTH_CHICKEN1, val);
3519 /* Enable digital hotplug on the PCH */
3520 hotplug = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
3521 hotplug &= ~(PORTA_HOTPLUG_ENABLE |
3522 PORTB_HOTPLUG_ENABLE |
3523 PORTC_HOTPLUG_ENABLE |
3524 PORTD_HOTPLUG_ENABLE);
3525 hotplug |= intel_hpd_hotplug_enables(dev_priv, spt_hotplug_enables);
3526 intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, hotplug);
3528 hotplug = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG2);
3529 hotplug &= ~PORTE_HOTPLUG_ENABLE;
3530 hotplug |= intel_hpd_hotplug_enables(dev_priv, spt_hotplug2_enables);
3531 intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG2, hotplug);
3534 static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
3536 u32 hotplug_irqs, enabled_irqs;
3538 if (INTEL_PCH_TYPE(dev_priv) >= PCH_CNP)
3539 intel_uncore_write(&dev_priv->uncore, SHPD_FILTER_CNT, SHPD_FILTER_CNT_500_ADJ);
3541 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->hotplug.pch_hpd);
3542 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->hotplug.pch_hpd);
3544 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3546 spt_hpd_detection_setup(dev_priv);
3549 static u32 ilk_hotplug_enables(struct drm_i915_private *i915,
3554 return DIGITAL_PORTA_HOTPLUG_ENABLE |
3555 DIGITAL_PORTA_PULSE_DURATION_2ms;
3561 static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv)
3566 * Enable digital hotplug on the CPU, and configure the DP short pulse
3567 * duration to 2ms (which is the minimum in the Display Port spec)
3568 * The pulse duration bits are reserved on HSW+.
3570 hotplug = intel_uncore_read(&dev_priv->uncore, DIGITAL_PORT_HOTPLUG_CNTRL);
3571 hotplug &= ~(DIGITAL_PORTA_HOTPLUG_ENABLE |
3572 DIGITAL_PORTA_PULSE_DURATION_MASK);
3573 hotplug |= intel_hpd_hotplug_enables(dev_priv, ilk_hotplug_enables);
3574 intel_uncore_write(&dev_priv->uncore, DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
3577 static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
3579 u32 hotplug_irqs, enabled_irqs;
3581 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->hotplug.hpd);
3582 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->hotplug.hpd);
3584 if (DISPLAY_VER(dev_priv) >= 8)
3585 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
3587 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3589 ilk_hpd_detection_setup(dev_priv);
3591 ibx_hpd_irq_setup(dev_priv);
3594 static u32 bxt_hotplug_enables(struct drm_i915_private *i915,
3601 hotplug = PORTA_HOTPLUG_ENABLE;
3602 if (intel_bios_is_port_hpd_inverted(i915, PORT_A))
3603 hotplug |= BXT_DDIA_HPD_INVERT;
3606 hotplug = PORTB_HOTPLUG_ENABLE;
3607 if (intel_bios_is_port_hpd_inverted(i915, PORT_B))
3608 hotplug |= BXT_DDIB_HPD_INVERT;
3611 hotplug = PORTC_HOTPLUG_ENABLE;
3612 if (intel_bios_is_port_hpd_inverted(i915, PORT_C))
3613 hotplug |= BXT_DDIC_HPD_INVERT;
3620 static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3624 hotplug = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
3625 hotplug &= ~(PORTA_HOTPLUG_ENABLE |
3626 PORTB_HOTPLUG_ENABLE |
3627 PORTC_HOTPLUG_ENABLE |
3628 BXT_DDIA_HPD_INVERT |
3629 BXT_DDIB_HPD_INVERT |
3630 BXT_DDIC_HPD_INVERT);
3631 hotplug |= intel_hpd_hotplug_enables(dev_priv, bxt_hotplug_enables);
3632 intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, hotplug);
3635 static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
3637 u32 hotplug_irqs, enabled_irqs;
3639 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->hotplug.hpd);
3640 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->hotplug.hpd);
3642 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
3644 bxt_hpd_detection_setup(dev_priv);
3648 * SDEIER is also touched by the interrupt handler to work around missed PCH
3649 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3650 * instead we unconditionally enable all PCH interrupt sources here, but then
3651 * only unmask them as needed with SDEIMR.
3653 * Note that we currently do this after installing the interrupt handler,
3654 * but before we enable the master interrupt. That should be sufficient
3655 * to avoid races with the irq handler, assuming we have MSI. Shared legacy
3656 * interrupts could still race.
3658 static void ibx_irq_postinstall(struct drm_i915_private *dev_priv)
3660 struct intel_uncore *uncore = &dev_priv->uncore;
3663 if (HAS_PCH_NOP(dev_priv))
3666 if (HAS_PCH_IBX(dev_priv))
3667 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
3668 else if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
3669 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
3671 mask = SDE_GMBUS_CPT;
3673 GEN3_IRQ_INIT(uncore, SDE, ~mask, 0xffffffff);
3676 static void ilk_irq_postinstall(struct drm_i915_private *dev_priv)
3678 struct intel_uncore *uncore = &dev_priv->uncore;
3679 u32 display_mask, extra_mask;
3681 if (GRAPHICS_VER(dev_priv) >= 7) {
3682 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
3683 DE_PCH_EVENT_IVB | DE_AUX_CHANNEL_A_IVB);
3684 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
3685 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
3686 DE_PLANE_FLIP_DONE_IVB(PLANE_C) |
3687 DE_PLANE_FLIP_DONE_IVB(PLANE_B) |
3688 DE_PLANE_FLIP_DONE_IVB(PLANE_A) |
3689 DE_DP_A_HOTPLUG_IVB);
3691 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
3692 DE_AUX_CHANNEL_A | DE_PIPEB_CRC_DONE |
3693 DE_PIPEA_CRC_DONE | DE_POISON);
3694 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK |
3695 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
3696 DE_PLANE_FLIP_DONE(PLANE_A) |
3697 DE_PLANE_FLIP_DONE(PLANE_B) |
3701 if (IS_HASWELL(dev_priv)) {
3702 gen3_assert_iir_is_zero(uncore, EDP_PSR_IIR);
3703 display_mask |= DE_EDP_PSR_INT_HSW;
3706 if (IS_IRONLAKE_M(dev_priv))
3707 extra_mask |= DE_PCU_EVENT;
3709 dev_priv->irq_mask = ~display_mask;
3711 ibx_irq_postinstall(dev_priv);
3713 gen5_gt_irq_postinstall(to_gt(dev_priv));
3715 GEN3_IRQ_INIT(uncore, DE, dev_priv->irq_mask,
3716 display_mask | extra_mask);
3719 void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3721 lockdep_assert_held(&dev_priv->irq_lock);
3723 if (dev_priv->display_irqs_enabled)
3726 dev_priv->display_irqs_enabled = true;
3728 if (intel_irqs_enabled(dev_priv)) {
3729 vlv_display_irq_reset(dev_priv);
3730 vlv_display_irq_postinstall(dev_priv);
3734 void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3736 lockdep_assert_held(&dev_priv->irq_lock);
3738 if (!dev_priv->display_irqs_enabled)
3741 dev_priv->display_irqs_enabled = false;
3743 if (intel_irqs_enabled(dev_priv))
3744 vlv_display_irq_reset(dev_priv);
3748 static void valleyview_irq_postinstall(struct drm_i915_private *dev_priv)
3750 gen5_gt_irq_postinstall(to_gt(dev_priv));
3752 spin_lock_irq(&dev_priv->irq_lock);
3753 if (dev_priv->display_irqs_enabled)
3754 vlv_display_irq_postinstall(dev_priv);
3755 spin_unlock_irq(&dev_priv->irq_lock);
3757 intel_uncore_write(&dev_priv->uncore, VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
3758 intel_uncore_posting_read(&dev_priv->uncore, VLV_MASTER_IER);
3761 static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3763 struct intel_uncore *uncore = &dev_priv->uncore;
3765 u32 de_pipe_masked = gen8_de_pipe_fault_mask(dev_priv) |
3766 GEN8_PIPE_CDCLK_CRC_DONE;
3767 u32 de_pipe_enables;
3768 u32 de_port_masked = gen8_de_port_aux_mask(dev_priv);
3769 u32 de_port_enables;
3770 u32 de_misc_masked = GEN8_DE_EDP_PSR;
3771 u32 trans_mask = BIT(TRANSCODER_A) | BIT(TRANSCODER_B) |
3772 BIT(TRANSCODER_C) | BIT(TRANSCODER_D);
3775 if (!HAS_DISPLAY(dev_priv))
3778 if (DISPLAY_VER(dev_priv) <= 10)
3779 de_misc_masked |= GEN8_DE_MISC_GSE;
3781 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
3782 de_port_masked |= BXT_DE_PORT_GMBUS;
3784 if (DISPLAY_VER(dev_priv) >= 11) {
3787 if (intel_bios_is_dsi_present(dev_priv, &port))
3788 de_port_masked |= DSI0_TE | DSI1_TE;
3791 de_pipe_enables = de_pipe_masked |
3793 gen8_de_pipe_underrun_mask(dev_priv) |
3794 gen8_de_pipe_flip_done_mask(dev_priv);
3796 de_port_enables = de_port_masked;
3797 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
3798 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
3799 else if (IS_BROADWELL(dev_priv))
3800 de_port_enables |= BDW_DE_PORT_HOTPLUG_MASK;
3802 if (DISPLAY_VER(dev_priv) >= 12) {
3803 enum transcoder trans;
3805 for_each_cpu_transcoder_masked(dev_priv, trans, trans_mask) {
3806 enum intel_display_power_domain domain;
3808 domain = POWER_DOMAIN_TRANSCODER(trans);
3809 if (!intel_display_power_is_enabled(dev_priv, domain))
3812 gen3_assert_iir_is_zero(uncore, TRANS_PSR_IIR(trans));
3815 gen3_assert_iir_is_zero(uncore, EDP_PSR_IIR);
3818 for_each_pipe(dev_priv, pipe) {
3819 dev_priv->de_irq_mask[pipe] = ~de_pipe_masked;
3821 if (intel_display_power_is_enabled(dev_priv,
3822 POWER_DOMAIN_PIPE(pipe)))
3823 GEN8_IRQ_INIT_NDX(uncore, DE_PIPE, pipe,
3824 dev_priv->de_irq_mask[pipe],
3828 GEN3_IRQ_INIT(uncore, GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
3829 GEN3_IRQ_INIT(uncore, GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked);
3831 if (DISPLAY_VER(dev_priv) >= 11) {
3832 u32 de_hpd_masked = 0;
3833 u32 de_hpd_enables = GEN11_DE_TC_HOTPLUG_MASK |
3834 GEN11_DE_TBT_HOTPLUG_MASK;
3836 GEN3_IRQ_INIT(uncore, GEN11_DE_HPD_, ~de_hpd_masked,
3841 static void icp_irq_postinstall(struct drm_i915_private *dev_priv)
3843 struct intel_uncore *uncore = &dev_priv->uncore;
3844 u32 mask = SDE_GMBUS_ICP;
3846 GEN3_IRQ_INIT(uncore, SDE, ~mask, 0xffffffff);
3849 static void gen8_irq_postinstall(struct drm_i915_private *dev_priv)
3851 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
3852 icp_irq_postinstall(dev_priv);
3853 else if (HAS_PCH_SPLIT(dev_priv))
3854 ibx_irq_postinstall(dev_priv);
3856 gen8_gt_irq_postinstall(to_gt(dev_priv));
3857 gen8_de_irq_postinstall(dev_priv);
3859 gen8_master_intr_enable(dev_priv->uncore.regs);
3862 static void gen11_de_irq_postinstall(struct drm_i915_private *dev_priv)
3864 if (!HAS_DISPLAY(dev_priv))
3867 gen8_de_irq_postinstall(dev_priv);
3869 intel_uncore_write(&dev_priv->uncore, GEN11_DISPLAY_INT_CTL,
3870 GEN11_DISPLAY_IRQ_ENABLE);
3873 static void gen11_irq_postinstall(struct drm_i915_private *dev_priv)
3875 struct intel_gt *gt = to_gt(dev_priv);
3876 struct intel_uncore *uncore = gt->uncore;
3877 u32 gu_misc_masked = GEN11_GU_MISC_GSE;
3879 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
3880 icp_irq_postinstall(dev_priv);
3882 gen11_gt_irq_postinstall(gt);
3883 gen11_de_irq_postinstall(dev_priv);
3885 GEN3_IRQ_INIT(uncore, GEN11_GU_MISC_, ~gu_misc_masked, gu_misc_masked);
3887 gen11_master_intr_enable(uncore->regs);
3888 intel_uncore_posting_read(&dev_priv->uncore, GEN11_GFX_MSTR_IRQ);
3891 static void dg1_irq_postinstall(struct drm_i915_private *dev_priv)
3893 struct intel_gt *gt = to_gt(dev_priv);
3894 struct intel_uncore *uncore = gt->uncore;
3895 u32 gu_misc_masked = GEN11_GU_MISC_GSE;
3897 gen11_gt_irq_postinstall(gt);
3899 GEN3_IRQ_INIT(uncore, GEN11_GU_MISC_, ~gu_misc_masked, gu_misc_masked);
3901 if (HAS_DISPLAY(dev_priv)) {
3902 icp_irq_postinstall(dev_priv);
3903 gen8_de_irq_postinstall(dev_priv);
3904 intel_uncore_write(&dev_priv->uncore, GEN11_DISPLAY_INT_CTL,
3905 GEN11_DISPLAY_IRQ_ENABLE);
3908 dg1_master_intr_enable(uncore->regs);
3909 intel_uncore_posting_read(uncore, DG1_MSTR_TILE_INTR);
3912 static void cherryview_irq_postinstall(struct drm_i915_private *dev_priv)
3914 gen8_gt_irq_postinstall(to_gt(dev_priv));
3916 spin_lock_irq(&dev_priv->irq_lock);
3917 if (dev_priv->display_irqs_enabled)
3918 vlv_display_irq_postinstall(dev_priv);
3919 spin_unlock_irq(&dev_priv->irq_lock);
3921 intel_uncore_write(&dev_priv->uncore, GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
3922 intel_uncore_posting_read(&dev_priv->uncore, GEN8_MASTER_IRQ);
3925 static void i8xx_irq_reset(struct drm_i915_private *dev_priv)
3927 struct intel_uncore *uncore = &dev_priv->uncore;
3929 i9xx_pipestat_irq_reset(dev_priv);
3931 GEN2_IRQ_RESET(uncore);
3932 dev_priv->irq_mask = ~0u;
3935 static void i8xx_irq_postinstall(struct drm_i915_private *dev_priv)
3937 struct intel_uncore *uncore = &dev_priv->uncore;
3940 intel_uncore_write16(uncore,
3942 ~(I915_ERROR_PAGE_TABLE |
3943 I915_ERROR_MEMORY_REFRESH));
3945 /* Unmask the interrupts that we always want on. */
3946 dev_priv->irq_mask =
3947 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3948 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3949 I915_MASTER_ERROR_INTERRUPT);
3952 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3953 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3954 I915_MASTER_ERROR_INTERRUPT |
3955 I915_USER_INTERRUPT;
3957 GEN2_IRQ_INIT(uncore, dev_priv->irq_mask, enable_mask);
3959 /* Interrupt setup is already guaranteed to be single-threaded, this is
3960 * just to make the assert_spin_locked check happy. */
3961 spin_lock_irq(&dev_priv->irq_lock);
3962 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3963 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
3964 spin_unlock_irq(&dev_priv->irq_lock);
3967 static void i8xx_error_irq_ack(struct drm_i915_private *i915,
3968 u16 *eir, u16 *eir_stuck)
3970 struct intel_uncore *uncore = &i915->uncore;
3973 *eir = intel_uncore_read16(uncore, EIR);
3976 intel_uncore_write16(uncore, EIR, *eir);
3978 *eir_stuck = intel_uncore_read16(uncore, EIR);
3979 if (*eir_stuck == 0)
3983 * Toggle all EMR bits to make sure we get an edge
3984 * in the ISR master error bit if we don't clear
3985 * all the EIR bits. Otherwise the edge triggered
3986 * IIR on i965/g4x wouldn't notice that an interrupt
3987 * is still pending. Also some EIR bits can't be
3988 * cleared except by handling the underlying error
3989 * (or by a GPU reset) so we mask any bit that
3992 emr = intel_uncore_read16(uncore, EMR);
3993 intel_uncore_write16(uncore, EMR, 0xffff);
3994 intel_uncore_write16(uncore, EMR, emr | *eir_stuck);
3997 static void i8xx_error_irq_handler(struct drm_i915_private *dev_priv,
3998 u16 eir, u16 eir_stuck)
4000 DRM_DEBUG("Master Error: EIR 0x%04x\n", eir);
4003 drm_dbg(&dev_priv->drm, "EIR stuck: 0x%04x, masked\n",
4007 static void i9xx_error_irq_ack(struct drm_i915_private *dev_priv,
4008 u32 *eir, u32 *eir_stuck)
4012 *eir = intel_uncore_read(&dev_priv->uncore, EIR);
4014 intel_uncore_write(&dev_priv->uncore, EIR, *eir);
4016 *eir_stuck = intel_uncore_read(&dev_priv->uncore, EIR);
4017 if (*eir_stuck == 0)
4021 * Toggle all EMR bits to make sure we get an edge
4022 * in the ISR master error bit if we don't clear
4023 * all the EIR bits. Otherwise the edge triggered
4024 * IIR on i965/g4x wouldn't notice that an interrupt
4025 * is still pending. Also some EIR bits can't be
4026 * cleared except by handling the underlying error
4027 * (or by a GPU reset) so we mask any bit that
4030 emr = intel_uncore_read(&dev_priv->uncore, EMR);
4031 intel_uncore_write(&dev_priv->uncore, EMR, 0xffffffff);
4032 intel_uncore_write(&dev_priv->uncore, EMR, emr | *eir_stuck);
4035 static void i9xx_error_irq_handler(struct drm_i915_private *dev_priv,
4036 u32 eir, u32 eir_stuck)
4038 DRM_DEBUG("Master Error, EIR 0x%08x\n", eir);
4041 drm_dbg(&dev_priv->drm, "EIR stuck: 0x%08x, masked\n",
4045 static irqreturn_t i8xx_irq_handler(int irq, void *arg)
4047 struct drm_i915_private *dev_priv = arg;
4048 irqreturn_t ret = IRQ_NONE;
4050 if (!intel_irqs_enabled(dev_priv))
4053 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4054 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
4057 u32 pipe_stats[I915_MAX_PIPES] = {};
4058 u16 eir = 0, eir_stuck = 0;
4061 iir = intel_uncore_read16(&dev_priv->uncore, GEN2_IIR);
4067 /* Call regardless, as some status bits might not be
4068 * signalled in iir */
4069 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
4071 if (iir & I915_MASTER_ERROR_INTERRUPT)
4072 i8xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
4074 intel_uncore_write16(&dev_priv->uncore, GEN2_IIR, iir);
4076 if (iir & I915_USER_INTERRUPT)
4077 intel_engine_cs_irq(to_gt(dev_priv)->engine[RCS0], iir);
4079 if (iir & I915_MASTER_ERROR_INTERRUPT)
4080 i8xx_error_irq_handler(dev_priv, eir, eir_stuck);
4082 i8xx_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4085 pmu_irq_stats(dev_priv, ret);
4087 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
4092 static void i915_irq_reset(struct drm_i915_private *dev_priv)
4094 struct intel_uncore *uncore = &dev_priv->uncore;
4096 if (I915_HAS_HOTPLUG(dev_priv)) {
4097 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
4098 intel_uncore_write(&dev_priv->uncore, PORT_HOTPLUG_STAT, intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT));
4101 i9xx_pipestat_irq_reset(dev_priv);
4103 GEN3_IRQ_RESET(uncore, GEN2_);
4104 dev_priv->irq_mask = ~0u;
4107 static void i915_irq_postinstall(struct drm_i915_private *dev_priv)
4109 struct intel_uncore *uncore = &dev_priv->uncore;
4112 intel_uncore_write(&dev_priv->uncore, EMR, ~(I915_ERROR_PAGE_TABLE |
4113 I915_ERROR_MEMORY_REFRESH));
4115 /* Unmask the interrupts that we always want on. */
4116 dev_priv->irq_mask =
4117 ~(I915_ASLE_INTERRUPT |
4118 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4119 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4120 I915_MASTER_ERROR_INTERRUPT);
4123 I915_ASLE_INTERRUPT |
4124 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4125 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4126 I915_MASTER_ERROR_INTERRUPT |
4127 I915_USER_INTERRUPT;
4129 if (I915_HAS_HOTPLUG(dev_priv)) {
4130 /* Enable in IER... */
4131 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
4132 /* and unmask in IMR */
4133 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
4136 GEN3_IRQ_INIT(uncore, GEN2_, dev_priv->irq_mask, enable_mask);
4138 /* Interrupt setup is already guaranteed to be single-threaded, this is
4139 * just to make the assert_spin_locked check happy. */
4140 spin_lock_irq(&dev_priv->irq_lock);
4141 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4142 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
4143 spin_unlock_irq(&dev_priv->irq_lock);
4145 i915_enable_asle_pipestat(dev_priv);
4148 static irqreturn_t i915_irq_handler(int irq, void *arg)
4150 struct drm_i915_private *dev_priv = arg;
4151 irqreturn_t ret = IRQ_NONE;
4153 if (!intel_irqs_enabled(dev_priv))
4156 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4157 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
4160 u32 pipe_stats[I915_MAX_PIPES] = {};
4161 u32 eir = 0, eir_stuck = 0;
4162 u32 hotplug_status = 0;
4165 iir = intel_uncore_read(&dev_priv->uncore, GEN2_IIR);
4171 if (I915_HAS_HOTPLUG(dev_priv) &&
4172 iir & I915_DISPLAY_PORT_INTERRUPT)
4173 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
4175 /* Call regardless, as some status bits might not be
4176 * signalled in iir */
4177 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
4179 if (iir & I915_MASTER_ERROR_INTERRUPT)
4180 i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
4182 intel_uncore_write(&dev_priv->uncore, GEN2_IIR, iir);
4184 if (iir & I915_USER_INTERRUPT)
4185 intel_engine_cs_irq(to_gt(dev_priv)->engine[RCS0], iir);
4187 if (iir & I915_MASTER_ERROR_INTERRUPT)
4188 i9xx_error_irq_handler(dev_priv, eir, eir_stuck);
4191 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
4193 i915_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4196 pmu_irq_stats(dev_priv, ret);
4198 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
4203 static void i965_irq_reset(struct drm_i915_private *dev_priv)
4205 struct intel_uncore *uncore = &dev_priv->uncore;
4207 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
4208 intel_uncore_write(&dev_priv->uncore, PORT_HOTPLUG_STAT, intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT));
4210 i9xx_pipestat_irq_reset(dev_priv);
4212 GEN3_IRQ_RESET(uncore, GEN2_);
4213 dev_priv->irq_mask = ~0u;
4216 static void i965_irq_postinstall(struct drm_i915_private *dev_priv)
4218 struct intel_uncore *uncore = &dev_priv->uncore;
4223 * Enable some error detection, note the instruction error mask
4224 * bit is reserved, so we leave it masked.
4226 if (IS_G4X(dev_priv)) {
4227 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4228 GM45_ERROR_MEM_PRIV |
4229 GM45_ERROR_CP_PRIV |
4230 I915_ERROR_MEMORY_REFRESH);
4232 error_mask = ~(I915_ERROR_PAGE_TABLE |
4233 I915_ERROR_MEMORY_REFRESH);
4235 intel_uncore_write(&dev_priv->uncore, EMR, error_mask);
4237 /* Unmask the interrupts that we always want on. */
4238 dev_priv->irq_mask =
4239 ~(I915_ASLE_INTERRUPT |
4240 I915_DISPLAY_PORT_INTERRUPT |
4241 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4242 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4243 I915_MASTER_ERROR_INTERRUPT);
4246 I915_ASLE_INTERRUPT |
4247 I915_DISPLAY_PORT_INTERRUPT |
4248 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4249 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4250 I915_MASTER_ERROR_INTERRUPT |
4251 I915_USER_INTERRUPT;
4253 if (IS_G4X(dev_priv))
4254 enable_mask |= I915_BSD_USER_INTERRUPT;
4256 GEN3_IRQ_INIT(uncore, GEN2_, dev_priv->irq_mask, enable_mask);
4258 /* Interrupt setup is already guaranteed to be single-threaded, this is
4259 * just to make the assert_spin_locked check happy. */
4260 spin_lock_irq(&dev_priv->irq_lock);
4261 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4262 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4263 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
4264 spin_unlock_irq(&dev_priv->irq_lock);
4266 i915_enable_asle_pipestat(dev_priv);
4269 static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
4273 lockdep_assert_held(&dev_priv->irq_lock);
4275 /* Note HDMI and DP share hotplug bits */
4276 /* enable bits are the same for all generations */
4277 hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
4278 /* Programming the CRT detection parameters tends
4279 to generate a spurious hotplug event about three
4280 seconds later. So just do it once.
4282 if (IS_G4X(dev_priv))
4283 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
4284 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
4286 /* Ignore TV since it's buggy */
4287 i915_hotplug_interrupt_update_locked(dev_priv,
4288 HOTPLUG_INT_EN_MASK |
4289 CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
4290 CRT_HOTPLUG_ACTIVATION_PERIOD_64,
4294 static irqreturn_t i965_irq_handler(int irq, void *arg)
4296 struct drm_i915_private *dev_priv = arg;
4297 irqreturn_t ret = IRQ_NONE;
4299 if (!intel_irqs_enabled(dev_priv))
4302 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4303 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
4306 u32 pipe_stats[I915_MAX_PIPES] = {};
4307 u32 eir = 0, eir_stuck = 0;
4308 u32 hotplug_status = 0;
4311 iir = intel_uncore_read(&dev_priv->uncore, GEN2_IIR);
4317 if (iir & I915_DISPLAY_PORT_INTERRUPT)
4318 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
4320 /* Call regardless, as some status bits might not be
4321 * signalled in iir */
4322 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
4324 if (iir & I915_MASTER_ERROR_INTERRUPT)
4325 i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
4327 intel_uncore_write(&dev_priv->uncore, GEN2_IIR, iir);
4329 if (iir & I915_USER_INTERRUPT)
4330 intel_engine_cs_irq(to_gt(dev_priv)->engine[RCS0],
4333 if (iir & I915_BSD_USER_INTERRUPT)
4334 intel_engine_cs_irq(to_gt(dev_priv)->engine[VCS0],
4337 if (iir & I915_MASTER_ERROR_INTERRUPT)
4338 i9xx_error_irq_handler(dev_priv, eir, eir_stuck);
4341 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
4343 i965_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4346 pmu_irq_stats(dev_priv, IRQ_HANDLED);
4348 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
4353 struct intel_hotplug_funcs {
4354 void (*hpd_irq_setup)(struct drm_i915_private *i915);
4357 #define HPD_FUNCS(platform) \
4358 static const struct intel_hotplug_funcs platform##_hpd_funcs = { \
4359 .hpd_irq_setup = platform##_hpd_irq_setup, \
4371 void intel_hpd_irq_setup(struct drm_i915_private *i915)
4373 if (i915->display_irqs_enabled && i915->hotplug_funcs)
4374 i915->hotplug_funcs->hpd_irq_setup(i915);
4378 * intel_irq_init - initializes irq support
4379 * @dev_priv: i915 device instance
4381 * This function initializes all the irq support including work items, timers
4382 * and all the vtables. It does not setup the interrupt itself though.
4384 void intel_irq_init(struct drm_i915_private *dev_priv)
4386 struct drm_device *dev = &dev_priv->drm;
4389 INIT_WORK(&dev_priv->l3_parity.error_work, ivb_parity_work);
4390 for (i = 0; i < MAX_L3_SLICES; ++i)
4391 dev_priv->l3_parity.remap_info[i] = NULL;
4393 /* pre-gen11 the guc irqs bits are in the upper 16 bits of the pm reg */
4394 if (HAS_GT_UC(dev_priv) && GRAPHICS_VER(dev_priv) < 11)
4395 to_gt(dev_priv)->pm_guc_events = GUC_INTR_GUC2HOST << 16;
4397 if (!HAS_DISPLAY(dev_priv))
4400 intel_hpd_init_pins(dev_priv);
4402 intel_hpd_init_work(dev_priv);
4404 dev->vblank_disable_immediate = true;
4406 /* Most platforms treat the display irq block as an always-on
4407 * power domain. vlv/chv can disable it at runtime and need
4408 * special care to avoid writing any of the display block registers
4409 * outside of the power domain. We defer setting up the display irqs
4410 * in this case to the runtime pm.
4412 dev_priv->display_irqs_enabled = true;
4413 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4414 dev_priv->display_irqs_enabled = false;
4416 dev_priv->hotplug.hpd_storm_threshold = HPD_STORM_DEFAULT_THRESHOLD;
4417 /* If we have MST support, we want to avoid doing short HPD IRQ storm
4418 * detection, as short HPD storms will occur as a natural part of
4419 * sideband messaging with MST.
4420 * On older platforms however, IRQ storms can occur with both long and
4421 * short pulses, as seen on some G4x systems.
4423 dev_priv->hotplug.hpd_short_storm_enabled = !HAS_DP_MST(dev_priv);
4425 if (HAS_GMCH(dev_priv)) {
4426 if (I915_HAS_HOTPLUG(dev_priv))
4427 dev_priv->hotplug_funcs = &i915_hpd_funcs;
4429 if (HAS_PCH_DG2(dev_priv))
4430 dev_priv->hotplug_funcs = &icp_hpd_funcs;
4431 else if (HAS_PCH_DG1(dev_priv))
4432 dev_priv->hotplug_funcs = &dg1_hpd_funcs;
4433 else if (DISPLAY_VER(dev_priv) >= 11)
4434 dev_priv->hotplug_funcs = &gen11_hpd_funcs;
4435 else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
4436 dev_priv->hotplug_funcs = &bxt_hpd_funcs;
4437 else if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
4438 dev_priv->hotplug_funcs = &icp_hpd_funcs;
4439 else if (INTEL_PCH_TYPE(dev_priv) >= PCH_SPT)
4440 dev_priv->hotplug_funcs = &spt_hpd_funcs;
4442 dev_priv->hotplug_funcs = &ilk_hpd_funcs;
4447 * intel_irq_fini - deinitializes IRQ support
4448 * @i915: i915 device instance
4450 * This function deinitializes all the IRQ support.
4452 void intel_irq_fini(struct drm_i915_private *i915)
4456 for (i = 0; i < MAX_L3_SLICES; ++i)
4457 kfree(i915->l3_parity.remap_info[i]);
4460 static irq_handler_t intel_irq_handler(struct drm_i915_private *dev_priv)
4462 if (HAS_GMCH(dev_priv)) {
4463 if (IS_CHERRYVIEW(dev_priv))
4464 return cherryview_irq_handler;
4465 else if (IS_VALLEYVIEW(dev_priv))
4466 return valleyview_irq_handler;
4467 else if (GRAPHICS_VER(dev_priv) == 4)
4468 return i965_irq_handler;
4469 else if (GRAPHICS_VER(dev_priv) == 3)
4470 return i915_irq_handler;
4472 return i8xx_irq_handler;
4474 if (GRAPHICS_VER_FULL(dev_priv) >= IP_VER(12, 10))
4475 return dg1_irq_handler;
4476 else if (GRAPHICS_VER(dev_priv) >= 11)
4477 return gen11_irq_handler;
4478 else if (GRAPHICS_VER(dev_priv) >= 8)
4479 return gen8_irq_handler;
4481 return ilk_irq_handler;
4485 static void intel_irq_reset(struct drm_i915_private *dev_priv)
4487 if (HAS_GMCH(dev_priv)) {
4488 if (IS_CHERRYVIEW(dev_priv))
4489 cherryview_irq_reset(dev_priv);
4490 else if (IS_VALLEYVIEW(dev_priv))
4491 valleyview_irq_reset(dev_priv);
4492 else if (GRAPHICS_VER(dev_priv) == 4)
4493 i965_irq_reset(dev_priv);
4494 else if (GRAPHICS_VER(dev_priv) == 3)
4495 i915_irq_reset(dev_priv);
4497 i8xx_irq_reset(dev_priv);
4499 if (GRAPHICS_VER_FULL(dev_priv) >= IP_VER(12, 10))
4500 dg1_irq_reset(dev_priv);
4501 else if (GRAPHICS_VER(dev_priv) >= 11)
4502 gen11_irq_reset(dev_priv);
4503 else if (GRAPHICS_VER(dev_priv) >= 8)
4504 gen8_irq_reset(dev_priv);
4506 ilk_irq_reset(dev_priv);
4510 static void intel_irq_postinstall(struct drm_i915_private *dev_priv)
4512 if (HAS_GMCH(dev_priv)) {
4513 if (IS_CHERRYVIEW(dev_priv))
4514 cherryview_irq_postinstall(dev_priv);
4515 else if (IS_VALLEYVIEW(dev_priv))
4516 valleyview_irq_postinstall(dev_priv);
4517 else if (GRAPHICS_VER(dev_priv) == 4)
4518 i965_irq_postinstall(dev_priv);
4519 else if (GRAPHICS_VER(dev_priv) == 3)
4520 i915_irq_postinstall(dev_priv);
4522 i8xx_irq_postinstall(dev_priv);
4524 if (GRAPHICS_VER_FULL(dev_priv) >= IP_VER(12, 10))
4525 dg1_irq_postinstall(dev_priv);
4526 else if (GRAPHICS_VER(dev_priv) >= 11)
4527 gen11_irq_postinstall(dev_priv);
4528 else if (GRAPHICS_VER(dev_priv) >= 8)
4529 gen8_irq_postinstall(dev_priv);
4531 ilk_irq_postinstall(dev_priv);
4536 * intel_irq_install - enables the hardware interrupt
4537 * @dev_priv: i915 device instance
4539 * This function enables the hardware interrupt handling, but leaves the hotplug
4540 * handling still disabled. It is called after intel_irq_init().
4542 * In the driver load and resume code we need working interrupts in a few places
4543 * but don't want to deal with the hassle of concurrent probe and hotplug
4544 * workers. Hence the split into this two-stage approach.
4546 int intel_irq_install(struct drm_i915_private *dev_priv)
4548 int irq = to_pci_dev(dev_priv->drm.dev)->irq;
4552 * We enable some interrupt sources in our postinstall hooks, so mark
4553 * interrupts as enabled _before_ actually enabling them to avoid
4554 * special cases in our ordering checks.
4556 dev_priv->runtime_pm.irqs_enabled = true;
4558 dev_priv->irq_enabled = true;
4560 intel_irq_reset(dev_priv);
4562 ret = request_irq(irq, intel_irq_handler(dev_priv),
4563 IRQF_SHARED, DRIVER_NAME, dev_priv);
4565 dev_priv->irq_enabled = false;
4569 intel_irq_postinstall(dev_priv);
4575 * intel_irq_uninstall - finilizes all irq handling
4576 * @dev_priv: i915 device instance
4578 * This stops interrupt and hotplug handling and unregisters and frees all
4579 * resources acquired in the init functions.
4581 void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4583 int irq = to_pci_dev(dev_priv->drm.dev)->irq;
4586 * FIXME we can get called twice during driver probe
4587 * error handling as well as during driver remove due to
4588 * intel_modeset_driver_remove() calling us out of sequence.
4589 * Would be nice if it didn't do that...
4591 if (!dev_priv->irq_enabled)
4594 dev_priv->irq_enabled = false;
4596 intel_irq_reset(dev_priv);
4598 free_irq(irq, dev_priv);
4600 intel_hpd_cancel_work(dev_priv);
4601 dev_priv->runtime_pm.irqs_enabled = false;
4605 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4606 * @dev_priv: i915 device instance
4608 * This function is used to disable interrupts at runtime, both in the runtime
4609 * pm and the system suspend/resume code.
4611 void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
4613 intel_irq_reset(dev_priv);
4614 dev_priv->runtime_pm.irqs_enabled = false;
4615 intel_synchronize_irq(dev_priv);
4619 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4620 * @dev_priv: i915 device instance
4622 * This function is used to enable interrupts at runtime, both in the runtime
4623 * pm and the system suspend/resume code.
4625 void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
4627 dev_priv->runtime_pm.irqs_enabled = true;
4628 intel_irq_reset(dev_priv);
4629 intel_irq_postinstall(dev_priv);
4632 bool intel_irqs_enabled(struct drm_i915_private *dev_priv)
4634 return dev_priv->runtime_pm.irqs_enabled;
4637 void intel_synchronize_irq(struct drm_i915_private *i915)
4639 synchronize_irq(to_pci_dev(i915->drm.dev)->irq);
4642 void intel_synchronize_hardirq(struct drm_i915_private *i915)
4644 synchronize_hardirq(to_pci_dev(i915->drm.dev)->irq);