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/slab.h>
32 #include <linux/sysrq.h>
34 #include <drm/drm_drv.h>
36 #include "display/icl_dsi_regs.h"
37 #include "display/intel_de.h"
38 #include "display/intel_display_trace.h"
39 #include "display/intel_display_types.h"
40 #include "display/intel_fdi_regs.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"
45 #include "display/intel_psr_regs.h"
47 #include "gt/intel_breadcrumbs.h"
48 #include "gt/intel_gt.h"
49 #include "gt/intel_gt_irq.h"
50 #include "gt/intel_gt_pm_irq.h"
51 #include "gt/intel_gt_regs.h"
52 #include "gt/intel_rps.h"
54 #include "i915_driver.h"
60 * DOC: interrupt handling
62 * These functions provide the basic support for enabling and disabling the
63 * interrupt handling support. There's a lot more functionality in i915_irq.c
64 * and related files, but that will be described in separate chapters.
68 * Interrupt statistic for PMU. Increments the counter only if the
69 * interrupt originated from the GPU so interrupts from a device which
70 * shares the interrupt line are not accounted.
72 static inline void pmu_irq_stats(struct drm_i915_private *i915,
75 if (unlikely(res != IRQ_HANDLED))
79 * A clever compiler translates that into INC. A not so clever one
80 * should at least prevent store tearing.
82 WRITE_ONCE(i915->pmu.irq_count, i915->pmu.irq_count + 1);
85 typedef bool (*long_pulse_detect_func)(enum hpd_pin pin, u32 val);
86 typedef u32 (*hotplug_enables_func)(struct intel_encoder *encoder);
87 typedef u32 (*hotplug_mask_func)(enum hpd_pin pin);
89 static const u32 hpd_ilk[HPD_NUM_PINS] = {
90 [HPD_PORT_A] = DE_DP_A_HOTPLUG,
93 static const u32 hpd_ivb[HPD_NUM_PINS] = {
94 [HPD_PORT_A] = DE_DP_A_HOTPLUG_IVB,
97 static const u32 hpd_bdw[HPD_NUM_PINS] = {
98 [HPD_PORT_A] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_A),
101 static const u32 hpd_ibx[HPD_NUM_PINS] = {
102 [HPD_CRT] = SDE_CRT_HOTPLUG,
103 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
104 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
105 [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
106 [HPD_PORT_D] = SDE_PORTD_HOTPLUG,
109 static const u32 hpd_cpt[HPD_NUM_PINS] = {
110 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
111 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
112 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
113 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
114 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT,
117 static const u32 hpd_spt[HPD_NUM_PINS] = {
118 [HPD_PORT_A] = SDE_PORTA_HOTPLUG_SPT,
119 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
120 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
121 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT,
122 [HPD_PORT_E] = SDE_PORTE_HOTPLUG_SPT,
125 static const u32 hpd_mask_i915[HPD_NUM_PINS] = {
126 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
127 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
128 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
129 [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
130 [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
131 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN,
134 static const u32 hpd_status_g4x[HPD_NUM_PINS] = {
135 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
136 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
137 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
138 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
139 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
140 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS,
143 static const u32 hpd_status_i915[HPD_NUM_PINS] = {
144 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
145 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
146 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
147 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
148 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
149 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS,
152 static const u32 hpd_bxt[HPD_NUM_PINS] = {
153 [HPD_PORT_A] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_A),
154 [HPD_PORT_B] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_B),
155 [HPD_PORT_C] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_C),
158 static const u32 hpd_gen11[HPD_NUM_PINS] = {
159 [HPD_PORT_TC1] = GEN11_TC_HOTPLUG(HPD_PORT_TC1) | GEN11_TBT_HOTPLUG(HPD_PORT_TC1),
160 [HPD_PORT_TC2] = GEN11_TC_HOTPLUG(HPD_PORT_TC2) | GEN11_TBT_HOTPLUG(HPD_PORT_TC2),
161 [HPD_PORT_TC3] = GEN11_TC_HOTPLUG(HPD_PORT_TC3) | GEN11_TBT_HOTPLUG(HPD_PORT_TC3),
162 [HPD_PORT_TC4] = GEN11_TC_HOTPLUG(HPD_PORT_TC4) | GEN11_TBT_HOTPLUG(HPD_PORT_TC4),
163 [HPD_PORT_TC5] = GEN11_TC_HOTPLUG(HPD_PORT_TC5) | GEN11_TBT_HOTPLUG(HPD_PORT_TC5),
164 [HPD_PORT_TC6] = GEN11_TC_HOTPLUG(HPD_PORT_TC6) | GEN11_TBT_HOTPLUG(HPD_PORT_TC6),
167 static const u32 hpd_xelpdp[HPD_NUM_PINS] = {
168 [HPD_PORT_TC1] = XELPDP_TBT_HOTPLUG(HPD_PORT_TC1) | XELPDP_DP_ALT_HOTPLUG(HPD_PORT_TC1),
169 [HPD_PORT_TC2] = XELPDP_TBT_HOTPLUG(HPD_PORT_TC2) | XELPDP_DP_ALT_HOTPLUG(HPD_PORT_TC2),
170 [HPD_PORT_TC3] = XELPDP_TBT_HOTPLUG(HPD_PORT_TC3) | XELPDP_DP_ALT_HOTPLUG(HPD_PORT_TC3),
171 [HPD_PORT_TC4] = XELPDP_TBT_HOTPLUG(HPD_PORT_TC4) | XELPDP_DP_ALT_HOTPLUG(HPD_PORT_TC4),
174 static const u32 hpd_icp[HPD_NUM_PINS] = {
175 [HPD_PORT_A] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_A),
176 [HPD_PORT_B] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_B),
177 [HPD_PORT_C] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_C),
178 [HPD_PORT_TC1] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC1),
179 [HPD_PORT_TC2] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC2),
180 [HPD_PORT_TC3] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC3),
181 [HPD_PORT_TC4] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC4),
182 [HPD_PORT_TC5] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC5),
183 [HPD_PORT_TC6] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC6),
186 static const u32 hpd_sde_dg1[HPD_NUM_PINS] = {
187 [HPD_PORT_A] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_A),
188 [HPD_PORT_B] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_B),
189 [HPD_PORT_C] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_C),
190 [HPD_PORT_D] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_D),
191 [HPD_PORT_TC1] = SDE_TC_HOTPLUG_DG2(HPD_PORT_TC1),
194 static const u32 hpd_mtp[HPD_NUM_PINS] = {
195 [HPD_PORT_A] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_A),
196 [HPD_PORT_B] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_B),
197 [HPD_PORT_TC1] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC1),
198 [HPD_PORT_TC2] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC2),
199 [HPD_PORT_TC3] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC3),
200 [HPD_PORT_TC4] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC4),
203 static void intel_hpd_init_pins(struct drm_i915_private *dev_priv)
205 struct intel_hotplug *hpd = &dev_priv->display.hotplug;
207 if (HAS_GMCH(dev_priv)) {
208 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
209 IS_CHERRYVIEW(dev_priv))
210 hpd->hpd = hpd_status_g4x;
212 hpd->hpd = hpd_status_i915;
216 if (DISPLAY_VER(dev_priv) >= 14)
217 hpd->hpd = hpd_xelpdp;
218 else if (DISPLAY_VER(dev_priv) >= 11)
219 hpd->hpd = hpd_gen11;
220 else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
222 else if (DISPLAY_VER(dev_priv) == 9)
223 hpd->hpd = NULL; /* no north HPD on SKL */
224 else if (DISPLAY_VER(dev_priv) >= 8)
226 else if (DISPLAY_VER(dev_priv) >= 7)
231 if ((INTEL_PCH_TYPE(dev_priv) < PCH_DG1) &&
232 (!HAS_PCH_SPLIT(dev_priv) || HAS_PCH_NOP(dev_priv)))
235 if (INTEL_PCH_TYPE(dev_priv) >= PCH_DG1)
236 hpd->pch_hpd = hpd_sde_dg1;
237 else if (INTEL_PCH_TYPE(dev_priv) >= PCH_MTP)
238 hpd->pch_hpd = hpd_mtp;
239 else if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
240 hpd->pch_hpd = hpd_icp;
241 else if (HAS_PCH_CNP(dev_priv) || HAS_PCH_SPT(dev_priv))
242 hpd->pch_hpd = hpd_spt;
243 else if (HAS_PCH_LPT(dev_priv) || HAS_PCH_CPT(dev_priv))
244 hpd->pch_hpd = hpd_cpt;
245 else if (HAS_PCH_IBX(dev_priv))
246 hpd->pch_hpd = hpd_ibx;
248 MISSING_CASE(INTEL_PCH_TYPE(dev_priv));
252 intel_handle_vblank(struct drm_i915_private *dev_priv, enum pipe pipe)
254 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
256 drm_crtc_handle_vblank(&crtc->base);
259 void gen3_irq_reset(struct intel_uncore *uncore, i915_reg_t imr,
260 i915_reg_t iir, i915_reg_t ier)
262 intel_uncore_write(uncore, imr, 0xffffffff);
263 intel_uncore_posting_read(uncore, imr);
265 intel_uncore_write(uncore, ier, 0);
267 /* IIR can theoretically queue up two events. Be paranoid. */
268 intel_uncore_write(uncore, iir, 0xffffffff);
269 intel_uncore_posting_read(uncore, iir);
270 intel_uncore_write(uncore, iir, 0xffffffff);
271 intel_uncore_posting_read(uncore, iir);
274 static void gen2_irq_reset(struct intel_uncore *uncore)
276 intel_uncore_write16(uncore, GEN2_IMR, 0xffff);
277 intel_uncore_posting_read16(uncore, GEN2_IMR);
279 intel_uncore_write16(uncore, GEN2_IER, 0);
281 /* IIR can theoretically queue up two events. Be paranoid. */
282 intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
283 intel_uncore_posting_read16(uncore, GEN2_IIR);
284 intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
285 intel_uncore_posting_read16(uncore, GEN2_IIR);
289 * We should clear IMR at preinstall/uninstall, and just check at postinstall.
291 static void gen3_assert_iir_is_zero(struct intel_uncore *uncore, i915_reg_t reg)
293 u32 val = intel_uncore_read(uncore, reg);
298 drm_WARN(&uncore->i915->drm, 1,
299 "Interrupt register 0x%x is not zero: 0x%08x\n",
300 i915_mmio_reg_offset(reg), val);
301 intel_uncore_write(uncore, reg, 0xffffffff);
302 intel_uncore_posting_read(uncore, reg);
303 intel_uncore_write(uncore, reg, 0xffffffff);
304 intel_uncore_posting_read(uncore, reg);
307 static void gen2_assert_iir_is_zero(struct intel_uncore *uncore)
309 u16 val = intel_uncore_read16(uncore, GEN2_IIR);
314 drm_WARN(&uncore->i915->drm, 1,
315 "Interrupt register 0x%x is not zero: 0x%08x\n",
316 i915_mmio_reg_offset(GEN2_IIR), val);
317 intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
318 intel_uncore_posting_read16(uncore, GEN2_IIR);
319 intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
320 intel_uncore_posting_read16(uncore, GEN2_IIR);
323 void gen3_irq_init(struct intel_uncore *uncore,
324 i915_reg_t imr, u32 imr_val,
325 i915_reg_t ier, u32 ier_val,
328 gen3_assert_iir_is_zero(uncore, iir);
330 intel_uncore_write(uncore, ier, ier_val);
331 intel_uncore_write(uncore, imr, imr_val);
332 intel_uncore_posting_read(uncore, imr);
335 static void gen2_irq_init(struct intel_uncore *uncore,
336 u32 imr_val, u32 ier_val)
338 gen2_assert_iir_is_zero(uncore);
340 intel_uncore_write16(uncore, GEN2_IER, ier_val);
341 intel_uncore_write16(uncore, GEN2_IMR, imr_val);
342 intel_uncore_posting_read16(uncore, GEN2_IMR);
345 /* For display hotplug interrupt */
347 i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv,
351 lockdep_assert_held(&dev_priv->irq_lock);
352 drm_WARN_ON(&dev_priv->drm, bits & ~mask);
354 intel_uncore_rmw(&dev_priv->uncore, PORT_HOTPLUG_EN, mask, bits);
358 * i915_hotplug_interrupt_update - update hotplug interrupt enable
359 * @dev_priv: driver private
360 * @mask: bits to update
361 * @bits: bits to enable
362 * NOTE: the HPD enable bits are modified both inside and outside
363 * of an interrupt context. To avoid that read-modify-write cycles
364 * interfer, these bits are protected by a spinlock. Since this
365 * function is usually not called from a context where the lock is
366 * held already, this function acquires the lock itself. A non-locking
367 * version is also available.
369 void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
373 spin_lock_irq(&dev_priv->irq_lock);
374 i915_hotplug_interrupt_update_locked(dev_priv, mask, bits);
375 spin_unlock_irq(&dev_priv->irq_lock);
379 * ilk_update_display_irq - update DEIMR
380 * @dev_priv: driver private
381 * @interrupt_mask: mask of interrupt bits to update
382 * @enabled_irq_mask: mask of interrupt bits to enable
384 static void ilk_update_display_irq(struct drm_i915_private *dev_priv,
385 u32 interrupt_mask, u32 enabled_irq_mask)
389 lockdep_assert_held(&dev_priv->irq_lock);
390 drm_WARN_ON(&dev_priv->drm, enabled_irq_mask & ~interrupt_mask);
392 new_val = dev_priv->irq_mask;
393 new_val &= ~interrupt_mask;
394 new_val |= (~enabled_irq_mask & interrupt_mask);
396 if (new_val != dev_priv->irq_mask &&
397 !drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv))) {
398 dev_priv->irq_mask = new_val;
399 intel_uncore_write(&dev_priv->uncore, DEIMR, dev_priv->irq_mask);
400 intel_uncore_posting_read(&dev_priv->uncore, DEIMR);
404 void ilk_enable_display_irq(struct drm_i915_private *i915, u32 bits)
406 ilk_update_display_irq(i915, bits, bits);
409 void ilk_disable_display_irq(struct drm_i915_private *i915, u32 bits)
411 ilk_update_display_irq(i915, bits, 0);
415 * bdw_update_port_irq - update DE port interrupt
416 * @dev_priv: driver private
417 * @interrupt_mask: mask of interrupt bits to update
418 * @enabled_irq_mask: mask of interrupt bits to enable
420 static void bdw_update_port_irq(struct drm_i915_private *dev_priv,
422 u32 enabled_irq_mask)
427 lockdep_assert_held(&dev_priv->irq_lock);
429 drm_WARN_ON(&dev_priv->drm, enabled_irq_mask & ~interrupt_mask);
431 if (drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv)))
434 old_val = intel_uncore_read(&dev_priv->uncore, GEN8_DE_PORT_IMR);
437 new_val &= ~interrupt_mask;
438 new_val |= (~enabled_irq_mask & interrupt_mask);
440 if (new_val != old_val) {
441 intel_uncore_write(&dev_priv->uncore, GEN8_DE_PORT_IMR, new_val);
442 intel_uncore_posting_read(&dev_priv->uncore, GEN8_DE_PORT_IMR);
447 * bdw_update_pipe_irq - update DE pipe interrupt
448 * @dev_priv: driver private
449 * @pipe: pipe whose interrupt to update
450 * @interrupt_mask: mask of interrupt bits to update
451 * @enabled_irq_mask: mask of interrupt bits to enable
453 static void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
454 enum pipe pipe, u32 interrupt_mask,
455 u32 enabled_irq_mask)
459 lockdep_assert_held(&dev_priv->irq_lock);
461 drm_WARN_ON(&dev_priv->drm, enabled_irq_mask & ~interrupt_mask);
463 if (drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv)))
466 new_val = dev_priv->de_irq_mask[pipe];
467 new_val &= ~interrupt_mask;
468 new_val |= (~enabled_irq_mask & interrupt_mask);
470 if (new_val != dev_priv->de_irq_mask[pipe]) {
471 dev_priv->de_irq_mask[pipe] = new_val;
472 intel_uncore_write(&dev_priv->uncore, GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
473 intel_uncore_posting_read(&dev_priv->uncore, GEN8_DE_PIPE_IMR(pipe));
477 void bdw_enable_pipe_irq(struct drm_i915_private *i915,
478 enum pipe pipe, u32 bits)
480 bdw_update_pipe_irq(i915, pipe, bits, bits);
483 void bdw_disable_pipe_irq(struct drm_i915_private *i915,
484 enum pipe pipe, u32 bits)
486 bdw_update_pipe_irq(i915, pipe, bits, 0);
490 * ibx_display_interrupt_update - update SDEIMR
491 * @dev_priv: driver private
492 * @interrupt_mask: mask of interrupt bits to update
493 * @enabled_irq_mask: mask of interrupt bits to enable
495 static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
497 u32 enabled_irq_mask)
499 u32 sdeimr = intel_uncore_read(&dev_priv->uncore, SDEIMR);
500 sdeimr &= ~interrupt_mask;
501 sdeimr |= (~enabled_irq_mask & interrupt_mask);
503 drm_WARN_ON(&dev_priv->drm, enabled_irq_mask & ~interrupt_mask);
505 lockdep_assert_held(&dev_priv->irq_lock);
507 if (drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv)))
510 intel_uncore_write(&dev_priv->uncore, SDEIMR, sdeimr);
511 intel_uncore_posting_read(&dev_priv->uncore, SDEIMR);
514 void ibx_enable_display_interrupt(struct drm_i915_private *i915, u32 bits)
516 ibx_display_interrupt_update(i915, bits, bits);
519 void ibx_disable_display_interrupt(struct drm_i915_private *i915, u32 bits)
521 ibx_display_interrupt_update(i915, bits, 0);
524 u32 i915_pipestat_enable_mask(struct drm_i915_private *dev_priv,
527 u32 status_mask = dev_priv->pipestat_irq_mask[pipe];
528 u32 enable_mask = status_mask << 16;
530 lockdep_assert_held(&dev_priv->irq_lock);
532 if (DISPLAY_VER(dev_priv) < 5)
536 * On pipe A we don't support the PSR interrupt yet,
537 * on pipe B and C the same bit MBZ.
539 if (drm_WARN_ON_ONCE(&dev_priv->drm,
540 status_mask & PIPE_A_PSR_STATUS_VLV))
543 * On pipe B and C we don't support the PSR interrupt yet, on pipe
544 * A the same bit is for perf counters which we don't use either.
546 if (drm_WARN_ON_ONCE(&dev_priv->drm,
547 status_mask & PIPE_B_PSR_STATUS_VLV))
550 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
551 SPRITE0_FLIP_DONE_INT_EN_VLV |
552 SPRITE1_FLIP_DONE_INT_EN_VLV);
553 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
554 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
555 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
556 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
559 drm_WARN_ONCE(&dev_priv->drm,
560 enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
561 status_mask & ~PIPESTAT_INT_STATUS_MASK,
562 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
563 pipe_name(pipe), enable_mask, status_mask);
568 void i915_enable_pipestat(struct drm_i915_private *dev_priv,
569 enum pipe pipe, u32 status_mask)
571 i915_reg_t reg = PIPESTAT(pipe);
574 drm_WARN_ONCE(&dev_priv->drm, status_mask & ~PIPESTAT_INT_STATUS_MASK,
575 "pipe %c: status_mask=0x%x\n",
576 pipe_name(pipe), status_mask);
578 lockdep_assert_held(&dev_priv->irq_lock);
579 drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv));
581 if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == status_mask)
584 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
585 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
587 intel_uncore_write(&dev_priv->uncore, reg, enable_mask | status_mask);
588 intel_uncore_posting_read(&dev_priv->uncore, reg);
591 void i915_disable_pipestat(struct drm_i915_private *dev_priv,
592 enum pipe pipe, u32 status_mask)
594 i915_reg_t reg = PIPESTAT(pipe);
597 drm_WARN_ONCE(&dev_priv->drm, status_mask & ~PIPESTAT_INT_STATUS_MASK,
598 "pipe %c: status_mask=0x%x\n",
599 pipe_name(pipe), status_mask);
601 lockdep_assert_held(&dev_priv->irq_lock);
602 drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv));
604 if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == 0)
607 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
608 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
610 intel_uncore_write(&dev_priv->uncore, reg, enable_mask | status_mask);
611 intel_uncore_posting_read(&dev_priv->uncore, reg);
614 static bool i915_has_asle(struct drm_i915_private *dev_priv)
616 if (!dev_priv->display.opregion.asle)
619 return IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
623 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
624 * @dev_priv: i915 device private
626 static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv)
628 if (!i915_has_asle(dev_priv))
631 spin_lock_irq(&dev_priv->irq_lock);
633 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
634 if (DISPLAY_VER(dev_priv) >= 4)
635 i915_enable_pipestat(dev_priv, PIPE_A,
636 PIPE_LEGACY_BLC_EVENT_STATUS);
638 spin_unlock_irq(&dev_priv->irq_lock);
642 * ivb_parity_work - Workqueue called when a parity error interrupt
644 * @work: workqueue struct
646 * Doesn't actually do anything except notify userspace. As a consequence of
647 * this event, userspace should try to remap the bad rows since statistically
648 * it is likely the same row is more likely to go bad again.
650 static void ivb_parity_work(struct work_struct *work)
652 struct drm_i915_private *dev_priv =
653 container_of(work, typeof(*dev_priv), l3_parity.error_work);
654 struct intel_gt *gt = to_gt(dev_priv);
655 u32 error_status, row, bank, subbank;
656 char *parity_event[6];
660 /* We must turn off DOP level clock gating to access the L3 registers.
661 * In order to prevent a get/put style interface, acquire struct mutex
662 * any time we access those registers.
664 mutex_lock(&dev_priv->drm.struct_mutex);
666 /* If we've screwed up tracking, just let the interrupt fire again */
667 if (drm_WARN_ON(&dev_priv->drm, !dev_priv->l3_parity.which_slice))
670 misccpctl = intel_uncore_rmw(&dev_priv->uncore, GEN7_MISCCPCTL,
671 GEN7_DOP_CLOCK_GATE_ENABLE, 0);
672 intel_uncore_posting_read(&dev_priv->uncore, GEN7_MISCCPCTL);
674 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
678 if (drm_WARN_ON_ONCE(&dev_priv->drm,
679 slice >= NUM_L3_SLICES(dev_priv)))
682 dev_priv->l3_parity.which_slice &= ~(1<<slice);
684 reg = GEN7_L3CDERRST1(slice);
686 error_status = intel_uncore_read(&dev_priv->uncore, reg);
687 row = GEN7_PARITY_ERROR_ROW(error_status);
688 bank = GEN7_PARITY_ERROR_BANK(error_status);
689 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
691 intel_uncore_write(&dev_priv->uncore, reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
692 intel_uncore_posting_read(&dev_priv->uncore, reg);
694 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
695 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
696 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
697 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
698 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
699 parity_event[5] = NULL;
701 kobject_uevent_env(&dev_priv->drm.primary->kdev->kobj,
702 KOBJ_CHANGE, parity_event);
704 drm_dbg(&dev_priv->drm,
705 "Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
706 slice, row, bank, subbank);
708 kfree(parity_event[4]);
709 kfree(parity_event[3]);
710 kfree(parity_event[2]);
711 kfree(parity_event[1]);
714 intel_uncore_write(&dev_priv->uncore, GEN7_MISCCPCTL, misccpctl);
717 drm_WARN_ON(&dev_priv->drm, dev_priv->l3_parity.which_slice);
718 spin_lock_irq(gt->irq_lock);
719 gen5_gt_enable_irq(gt, GT_PARITY_ERROR(dev_priv));
720 spin_unlock_irq(gt->irq_lock);
722 mutex_unlock(&dev_priv->drm.struct_mutex);
725 static bool gen11_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
734 return val & GEN11_HOTPLUG_CTL_LONG_DETECT(pin);
740 static bool bxt_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
744 return val & PORTA_HOTPLUG_LONG_DETECT;
746 return val & PORTB_HOTPLUG_LONG_DETECT;
748 return val & PORTC_HOTPLUG_LONG_DETECT;
754 static bool icp_ddi_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
761 return val & SHOTPLUG_CTL_DDI_HPD_LONG_DETECT(pin);
767 static bool icp_tc_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
776 return val & ICP_TC_HPD_LONG_DETECT(pin);
782 static bool spt_port_hotplug2_long_detect(enum hpd_pin pin, u32 val)
786 return val & PORTE_HOTPLUG_LONG_DETECT;
792 static bool spt_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
796 return val & PORTA_HOTPLUG_LONG_DETECT;
798 return val & PORTB_HOTPLUG_LONG_DETECT;
800 return val & PORTC_HOTPLUG_LONG_DETECT;
802 return val & PORTD_HOTPLUG_LONG_DETECT;
808 static bool ilk_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
812 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
818 static bool pch_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
822 return val & PORTB_HOTPLUG_LONG_DETECT;
824 return val & PORTC_HOTPLUG_LONG_DETECT;
826 return val & PORTD_HOTPLUG_LONG_DETECT;
832 static bool i9xx_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
836 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
838 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
840 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
847 * Get a bit mask of pins that have triggered, and which ones may be long.
848 * This can be called multiple times with the same masks to accumulate
849 * hotplug detection results from several registers.
851 * Note that the caller is expected to zero out the masks initially.
853 static void intel_get_hpd_pins(struct drm_i915_private *dev_priv,
854 u32 *pin_mask, u32 *long_mask,
855 u32 hotplug_trigger, u32 dig_hotplug_reg,
856 const u32 hpd[HPD_NUM_PINS],
857 bool long_pulse_detect(enum hpd_pin pin, u32 val))
861 BUILD_BUG_ON(BITS_PER_TYPE(*pin_mask) < HPD_NUM_PINS);
863 for_each_hpd_pin(pin) {
864 if ((hpd[pin] & hotplug_trigger) == 0)
867 *pin_mask |= BIT(pin);
869 if (long_pulse_detect(pin, dig_hotplug_reg))
870 *long_mask |= BIT(pin);
873 drm_dbg(&dev_priv->drm,
874 "hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x, long 0x%08x\n",
875 hotplug_trigger, dig_hotplug_reg, *pin_mask, *long_mask);
879 static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
880 const u32 hpd[HPD_NUM_PINS])
882 struct intel_encoder *encoder;
883 u32 enabled_irqs = 0;
885 for_each_intel_encoder(&dev_priv->drm, encoder)
886 if (dev_priv->display.hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
887 enabled_irqs |= hpd[encoder->hpd_pin];
892 static u32 intel_hpd_hotplug_irqs(struct drm_i915_private *dev_priv,
893 const u32 hpd[HPD_NUM_PINS])
895 struct intel_encoder *encoder;
896 u32 hotplug_irqs = 0;
898 for_each_intel_encoder(&dev_priv->drm, encoder)
899 hotplug_irqs |= hpd[encoder->hpd_pin];
904 static u32 intel_hpd_hotplug_mask(struct drm_i915_private *i915,
905 hotplug_mask_func hotplug_mask)
910 for_each_hpd_pin(pin)
911 hotplug |= hotplug_mask(pin);
916 static u32 intel_hpd_hotplug_enables(struct drm_i915_private *i915,
917 hotplug_enables_func hotplug_enables)
919 struct intel_encoder *encoder;
922 for_each_intel_encoder(&i915->drm, encoder)
923 hotplug |= hotplug_enables(encoder);
928 static void gmbus_irq_handler(struct drm_i915_private *dev_priv)
930 wake_up_all(&dev_priv->display.gmbus.wait_queue);
933 static void dp_aux_irq_handler(struct drm_i915_private *dev_priv)
935 wake_up_all(&dev_priv->display.gmbus.wait_queue);
938 #if defined(CONFIG_DEBUG_FS)
939 static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
945 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
946 struct intel_pipe_crc *pipe_crc = &crtc->pipe_crc;
947 u32 crcs[5] = { crc0, crc1, crc2, crc3, crc4 };
949 trace_intel_pipe_crc(crtc, crcs);
951 spin_lock(&pipe_crc->lock);
953 * For some not yet identified reason, the first CRC is
954 * bonkers. So let's just wait for the next vblank and read
955 * out the buggy result.
957 * On GEN8+ sometimes the second CRC is bonkers as well, so
958 * don't trust that one either.
960 if (pipe_crc->skipped <= 0 ||
961 (DISPLAY_VER(dev_priv) >= 8 && pipe_crc->skipped == 1)) {
963 spin_unlock(&pipe_crc->lock);
966 spin_unlock(&pipe_crc->lock);
968 drm_crtc_add_crc_entry(&crtc->base, true,
969 drm_crtc_accurate_vblank_count(&crtc->base),
974 display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
981 static void flip_done_handler(struct drm_i915_private *i915,
984 struct intel_crtc *crtc = intel_crtc_for_pipe(i915, pipe);
985 struct drm_crtc_state *crtc_state = crtc->base.state;
986 struct drm_pending_vblank_event *e = crtc_state->event;
987 struct drm_device *dev = &i915->drm;
988 unsigned long irqflags;
990 spin_lock_irqsave(&dev->event_lock, irqflags);
992 crtc_state->event = NULL;
994 drm_crtc_send_vblank_event(&crtc->base, e);
996 spin_unlock_irqrestore(&dev->event_lock, irqflags);
999 static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1002 display_pipe_crc_irq_handler(dev_priv, pipe,
1003 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_1_IVB(pipe)),
1007 static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1010 display_pipe_crc_irq_handler(dev_priv, pipe,
1011 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_1_IVB(pipe)),
1012 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_2_IVB(pipe)),
1013 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_3_IVB(pipe)),
1014 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_4_IVB(pipe)),
1015 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_5_IVB(pipe)));
1018 static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1023 if (DISPLAY_VER(dev_priv) >= 3)
1024 res1 = intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_RES1_I915(pipe));
1028 if (DISPLAY_VER(dev_priv) >= 5 || IS_G4X(dev_priv))
1029 res2 = intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_RES2_G4X(pipe));
1033 display_pipe_crc_irq_handler(dev_priv, pipe,
1034 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_RED(pipe)),
1035 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_GREEN(pipe)),
1036 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_BLUE(pipe)),
1040 static void i9xx_pipestat_irq_reset(struct drm_i915_private *dev_priv)
1044 for_each_pipe(dev_priv, pipe) {
1045 intel_uncore_write(&dev_priv->uncore, PIPESTAT(pipe),
1046 PIPESTAT_INT_STATUS_MASK |
1047 PIPE_FIFO_UNDERRUN_STATUS);
1049 dev_priv->pipestat_irq_mask[pipe] = 0;
1053 static void i9xx_pipestat_irq_ack(struct drm_i915_private *dev_priv,
1054 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1058 spin_lock(&dev_priv->irq_lock);
1060 if (!dev_priv->display_irqs_enabled) {
1061 spin_unlock(&dev_priv->irq_lock);
1065 for_each_pipe(dev_priv, pipe) {
1067 u32 status_mask, enable_mask, iir_bit = 0;
1070 * PIPESTAT bits get signalled even when the interrupt is
1071 * disabled with the mask bits, and some of the status bits do
1072 * not generate interrupts at all (like the underrun bit). Hence
1073 * we need to be careful that we only handle what we want to
1077 /* fifo underruns are filterered in the underrun handler. */
1078 status_mask = PIPE_FIFO_UNDERRUN_STATUS;
1083 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1086 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1089 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1093 status_mask |= dev_priv->pipestat_irq_mask[pipe];
1098 reg = PIPESTAT(pipe);
1099 pipe_stats[pipe] = intel_uncore_read(&dev_priv->uncore, reg) & status_mask;
1100 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
1103 * Clear the PIPE*STAT regs before the IIR
1105 * Toggle the enable bits to make sure we get an
1106 * edge in the ISR pipe event bit if we don't clear
1107 * all the enabled status bits. Otherwise the edge
1108 * triggered IIR on i965/g4x wouldn't notice that
1109 * an interrupt is still pending.
1111 if (pipe_stats[pipe]) {
1112 intel_uncore_write(&dev_priv->uncore, reg, pipe_stats[pipe]);
1113 intel_uncore_write(&dev_priv->uncore, reg, enable_mask);
1116 spin_unlock(&dev_priv->irq_lock);
1119 static void i8xx_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1120 u16 iir, u32 pipe_stats[I915_MAX_PIPES])
1124 for_each_pipe(dev_priv, pipe) {
1125 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1126 intel_handle_vblank(dev_priv, pipe);
1128 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1129 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1131 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1132 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1136 static void i915_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1137 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1139 bool blc_event = false;
1142 for_each_pipe(dev_priv, pipe) {
1143 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1144 intel_handle_vblank(dev_priv, pipe);
1146 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1149 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1150 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1152 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1153 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1156 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1157 intel_opregion_asle_intr(dev_priv);
1160 static void i965_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1161 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1163 bool blc_event = false;
1166 for_each_pipe(dev_priv, pipe) {
1167 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1168 intel_handle_vblank(dev_priv, pipe);
1170 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1173 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1174 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1176 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1177 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1180 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1181 intel_opregion_asle_intr(dev_priv);
1183 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1184 gmbus_irq_handler(dev_priv);
1187 static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1188 u32 pipe_stats[I915_MAX_PIPES])
1192 for_each_pipe(dev_priv, pipe) {
1193 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1194 intel_handle_vblank(dev_priv, pipe);
1196 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV)
1197 flip_done_handler(dev_priv, pipe);
1199 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1200 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1202 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1203 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1206 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1207 gmbus_irq_handler(dev_priv);
1210 static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
1212 u32 hotplug_status = 0, hotplug_status_mask;
1215 if (IS_G4X(dev_priv) ||
1216 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
1217 hotplug_status_mask = HOTPLUG_INT_STATUS_G4X |
1218 DP_AUX_CHANNEL_MASK_INT_STATUS_G4X;
1220 hotplug_status_mask = HOTPLUG_INT_STATUS_I915;
1223 * We absolutely have to clear all the pending interrupt
1224 * bits in PORT_HOTPLUG_STAT. Otherwise the ISR port
1225 * interrupt bit won't have an edge, and the i965/g4x
1226 * edge triggered IIR will not notice that an interrupt
1227 * is still pending. We can't use PORT_HOTPLUG_EN to
1228 * guarantee the edge as the act of toggling the enable
1229 * bits can itself generate a new hotplug interrupt :(
1231 for (i = 0; i < 10; i++) {
1232 u32 tmp = intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT) & hotplug_status_mask;
1235 return hotplug_status;
1237 hotplug_status |= tmp;
1238 intel_uncore_write(&dev_priv->uncore, PORT_HOTPLUG_STAT, hotplug_status);
1241 drm_WARN_ONCE(&dev_priv->drm, 1,
1242 "PORT_HOTPLUG_STAT did not clear (0x%08x)\n",
1243 intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT));
1245 return hotplug_status;
1248 static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv,
1251 u32 pin_mask = 0, long_mask = 0;
1252 u32 hotplug_trigger;
1254 if (IS_G4X(dev_priv) ||
1255 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
1256 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
1258 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
1260 if (hotplug_trigger) {
1261 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1262 hotplug_trigger, hotplug_trigger,
1263 dev_priv->display.hotplug.hpd,
1264 i9xx_port_hotplug_long_detect);
1266 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
1269 if ((IS_G4X(dev_priv) ||
1270 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
1271 hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
1272 dp_aux_irq_handler(dev_priv);
1275 static irqreturn_t valleyview_irq_handler(int irq, void *arg)
1277 struct drm_i915_private *dev_priv = arg;
1278 irqreturn_t ret = IRQ_NONE;
1280 if (!intel_irqs_enabled(dev_priv))
1283 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1284 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
1287 u32 iir, gt_iir, pm_iir;
1288 u32 pipe_stats[I915_MAX_PIPES] = {};
1289 u32 hotplug_status = 0;
1292 gt_iir = intel_uncore_read(&dev_priv->uncore, GTIIR);
1293 pm_iir = intel_uncore_read(&dev_priv->uncore, GEN6_PMIIR);
1294 iir = intel_uncore_read(&dev_priv->uncore, VLV_IIR);
1296 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1302 * Theory on interrupt generation, based on empirical evidence:
1304 * x = ((VLV_IIR & VLV_IER) ||
1305 * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) &&
1306 * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE)));
1308 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
1309 * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to
1310 * guarantee the CPU interrupt will be raised again even if we
1311 * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR
1312 * bits this time around.
1314 intel_uncore_write(&dev_priv->uncore, VLV_MASTER_IER, 0);
1315 ier = intel_uncore_rmw(&dev_priv->uncore, VLV_IER, ~0, 0);
1318 intel_uncore_write(&dev_priv->uncore, GTIIR, gt_iir);
1320 intel_uncore_write(&dev_priv->uncore, GEN6_PMIIR, pm_iir);
1322 if (iir & I915_DISPLAY_PORT_INTERRUPT)
1323 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
1325 /* Call regardless, as some status bits might not be
1326 * signalled in iir */
1327 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
1329 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
1330 I915_LPE_PIPE_B_INTERRUPT))
1331 intel_lpe_audio_irq_handler(dev_priv);
1334 * VLV_IIR is single buffered, and reflects the level
1335 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
1338 intel_uncore_write(&dev_priv->uncore, VLV_IIR, iir);
1340 intel_uncore_write(&dev_priv->uncore, VLV_IER, ier);
1341 intel_uncore_write(&dev_priv->uncore, VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
1344 gen6_gt_irq_handler(to_gt(dev_priv), gt_iir);
1346 gen6_rps_irq_handler(&to_gt(dev_priv)->rps, pm_iir);
1349 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
1351 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
1354 pmu_irq_stats(dev_priv, ret);
1356 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
1361 static irqreturn_t cherryview_irq_handler(int irq, void *arg)
1363 struct drm_i915_private *dev_priv = arg;
1364 irqreturn_t ret = IRQ_NONE;
1366 if (!intel_irqs_enabled(dev_priv))
1369 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1370 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
1373 u32 master_ctl, iir;
1374 u32 pipe_stats[I915_MAX_PIPES] = {};
1375 u32 hotplug_status = 0;
1378 master_ctl = intel_uncore_read(&dev_priv->uncore, GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
1379 iir = intel_uncore_read(&dev_priv->uncore, VLV_IIR);
1381 if (master_ctl == 0 && iir == 0)
1387 * Theory on interrupt generation, based on empirical evidence:
1389 * x = ((VLV_IIR & VLV_IER) ||
1390 * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) &&
1391 * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL)));
1393 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
1394 * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to
1395 * guarantee the CPU interrupt will be raised again even if we
1396 * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL
1397 * bits this time around.
1399 intel_uncore_write(&dev_priv->uncore, GEN8_MASTER_IRQ, 0);
1400 ier = intel_uncore_rmw(&dev_priv->uncore, VLV_IER, ~0, 0);
1402 gen8_gt_irq_handler(to_gt(dev_priv), master_ctl);
1404 if (iir & I915_DISPLAY_PORT_INTERRUPT)
1405 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
1407 /* Call regardless, as some status bits might not be
1408 * signalled in iir */
1409 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
1411 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
1412 I915_LPE_PIPE_B_INTERRUPT |
1413 I915_LPE_PIPE_C_INTERRUPT))
1414 intel_lpe_audio_irq_handler(dev_priv);
1417 * VLV_IIR is single buffered, and reflects the level
1418 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
1421 intel_uncore_write(&dev_priv->uncore, VLV_IIR, iir);
1423 intel_uncore_write(&dev_priv->uncore, VLV_IER, ier);
1424 intel_uncore_write(&dev_priv->uncore, GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
1427 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
1429 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
1432 pmu_irq_stats(dev_priv, ret);
1434 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
1439 static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv,
1440 u32 hotplug_trigger)
1442 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
1445 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
1446 * unless we touch the hotplug register, even if hotplug_trigger is
1447 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
1450 dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
1451 if (!hotplug_trigger) {
1452 u32 mask = PORTA_HOTPLUG_STATUS_MASK |
1453 PORTD_HOTPLUG_STATUS_MASK |
1454 PORTC_HOTPLUG_STATUS_MASK |
1455 PORTB_HOTPLUG_STATUS_MASK;
1456 dig_hotplug_reg &= ~mask;
1459 intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, dig_hotplug_reg);
1460 if (!hotplug_trigger)
1463 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1464 hotplug_trigger, dig_hotplug_reg,
1465 dev_priv->display.hotplug.pch_hpd,
1466 pch_port_hotplug_long_detect);
1468 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
1471 static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
1474 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
1476 ibx_hpd_irq_handler(dev_priv, hotplug_trigger);
1478 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1479 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1480 SDE_AUDIO_POWER_SHIFT);
1481 drm_dbg(&dev_priv->drm, "PCH audio power change on port %d\n",
1485 if (pch_iir & SDE_AUX_MASK)
1486 dp_aux_irq_handler(dev_priv);
1488 if (pch_iir & SDE_GMBUS)
1489 gmbus_irq_handler(dev_priv);
1491 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1492 drm_dbg(&dev_priv->drm, "PCH HDCP audio interrupt\n");
1494 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1495 drm_dbg(&dev_priv->drm, "PCH transcoder audio interrupt\n");
1497 if (pch_iir & SDE_POISON)
1498 drm_err(&dev_priv->drm, "PCH poison interrupt\n");
1500 if (pch_iir & SDE_FDI_MASK) {
1501 for_each_pipe(dev_priv, pipe)
1502 drm_dbg(&dev_priv->drm, " pipe %c FDI IIR: 0x%08x\n",
1504 intel_uncore_read(&dev_priv->uncore, FDI_RX_IIR(pipe)));
1507 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1508 drm_dbg(&dev_priv->drm, "PCH transcoder CRC done interrupt\n");
1510 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1511 drm_dbg(&dev_priv->drm,
1512 "PCH transcoder CRC error interrupt\n");
1514 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
1515 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A);
1517 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1518 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B);
1521 static void ivb_err_int_handler(struct drm_i915_private *dev_priv)
1523 u32 err_int = intel_uncore_read(&dev_priv->uncore, GEN7_ERR_INT);
1526 if (err_int & ERR_INT_POISON)
1527 drm_err(&dev_priv->drm, "Poison interrupt\n");
1529 for_each_pipe(dev_priv, pipe) {
1530 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
1531 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1533 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
1534 if (IS_IVYBRIDGE(dev_priv))
1535 ivb_pipe_crc_irq_handler(dev_priv, pipe);
1537 hsw_pipe_crc_irq_handler(dev_priv, pipe);
1541 intel_uncore_write(&dev_priv->uncore, GEN7_ERR_INT, err_int);
1544 static void cpt_serr_int_handler(struct drm_i915_private *dev_priv)
1546 u32 serr_int = intel_uncore_read(&dev_priv->uncore, SERR_INT);
1549 if (serr_int & SERR_INT_POISON)
1550 drm_err(&dev_priv->drm, "PCH poison interrupt\n");
1552 for_each_pipe(dev_priv, pipe)
1553 if (serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pipe))
1554 intel_pch_fifo_underrun_irq_handler(dev_priv, pipe);
1556 intel_uncore_write(&dev_priv->uncore, SERR_INT, serr_int);
1559 static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
1562 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
1564 ibx_hpd_irq_handler(dev_priv, hotplug_trigger);
1566 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1567 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1568 SDE_AUDIO_POWER_SHIFT_CPT);
1569 drm_dbg(&dev_priv->drm, "PCH audio power change on port %c\n",
1573 if (pch_iir & SDE_AUX_MASK_CPT)
1574 dp_aux_irq_handler(dev_priv);
1576 if (pch_iir & SDE_GMBUS_CPT)
1577 gmbus_irq_handler(dev_priv);
1579 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1580 drm_dbg(&dev_priv->drm, "Audio CP request interrupt\n");
1582 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1583 drm_dbg(&dev_priv->drm, "Audio CP change interrupt\n");
1585 if (pch_iir & SDE_FDI_MASK_CPT) {
1586 for_each_pipe(dev_priv, pipe)
1587 drm_dbg(&dev_priv->drm, " pipe %c FDI IIR: 0x%08x\n",
1589 intel_uncore_read(&dev_priv->uncore, FDI_RX_IIR(pipe)));
1592 if (pch_iir & SDE_ERROR_CPT)
1593 cpt_serr_int_handler(dev_priv);
1596 static void xelpdp_pica_irq_handler(struct drm_i915_private *i915, u32 iir)
1599 u32 hotplug_trigger = iir & (XELPDP_DP_ALT_HOTPLUG_MASK | XELPDP_TBT_HOTPLUG_MASK);
1600 u32 trigger_aux = iir & XELPDP_AUX_TC_MASK;
1601 u32 pin_mask = 0, long_mask = 0;
1603 for (pin = HPD_PORT_TC1; pin <= HPD_PORT_TC4; pin++) {
1606 if (!(i915->display.hotplug.hpd[pin] & hotplug_trigger))
1609 pin_mask |= BIT(pin);
1611 val = intel_de_read(i915, XELPDP_PORT_HOTPLUG_CTL(pin));
1612 intel_de_write(i915, XELPDP_PORT_HOTPLUG_CTL(pin), val);
1614 if (val & (XELPDP_DP_ALT_HPD_LONG_DETECT | XELPDP_TBT_HPD_LONG_DETECT))
1615 long_mask |= BIT(pin);
1620 "pica hotplug event received, stat 0x%08x, pins 0x%08x, long 0x%08x\n",
1621 hotplug_trigger, pin_mask, long_mask);
1623 intel_hpd_irq_handler(i915, pin_mask, long_mask);
1627 dp_aux_irq_handler(i915);
1629 if (!pin_mask && !trigger_aux)
1631 "Unexpected DE HPD/AUX interrupt 0x%08x\n", iir);
1634 static void icp_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
1636 u32 ddi_hotplug_trigger = pch_iir & SDE_DDI_HOTPLUG_MASK_ICP;
1637 u32 tc_hotplug_trigger = pch_iir & SDE_TC_HOTPLUG_MASK_ICP;
1638 u32 pin_mask = 0, long_mask = 0;
1640 if (ddi_hotplug_trigger) {
1641 u32 dig_hotplug_reg;
1643 /* Locking due to DSI native GPIO sequences */
1644 spin_lock(&dev_priv->irq_lock);
1645 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, SHOTPLUG_CTL_DDI, 0, 0);
1646 spin_unlock(&dev_priv->irq_lock);
1648 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1649 ddi_hotplug_trigger, dig_hotplug_reg,
1650 dev_priv->display.hotplug.pch_hpd,
1651 icp_ddi_port_hotplug_long_detect);
1654 if (tc_hotplug_trigger) {
1655 u32 dig_hotplug_reg;
1657 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, SHOTPLUG_CTL_TC, 0, 0);
1659 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1660 tc_hotplug_trigger, dig_hotplug_reg,
1661 dev_priv->display.hotplug.pch_hpd,
1662 icp_tc_port_hotplug_long_detect);
1666 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
1668 if (pch_iir & SDE_GMBUS_ICP)
1669 gmbus_irq_handler(dev_priv);
1672 static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
1674 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
1675 ~SDE_PORTE_HOTPLUG_SPT;
1676 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
1677 u32 pin_mask = 0, long_mask = 0;
1679 if (hotplug_trigger) {
1680 u32 dig_hotplug_reg;
1682 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG, 0, 0);
1684 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1685 hotplug_trigger, dig_hotplug_reg,
1686 dev_priv->display.hotplug.pch_hpd,
1687 spt_port_hotplug_long_detect);
1690 if (hotplug2_trigger) {
1691 u32 dig_hotplug_reg;
1693 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG2, 0, 0);
1695 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1696 hotplug2_trigger, dig_hotplug_reg,
1697 dev_priv->display.hotplug.pch_hpd,
1698 spt_port_hotplug2_long_detect);
1702 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
1704 if (pch_iir & SDE_GMBUS_CPT)
1705 gmbus_irq_handler(dev_priv);
1708 static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv,
1709 u32 hotplug_trigger)
1711 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
1713 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, DIGITAL_PORT_HOTPLUG_CNTRL, 0, 0);
1715 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1716 hotplug_trigger, dig_hotplug_reg,
1717 dev_priv->display.hotplug.hpd,
1718 ilk_port_hotplug_long_detect);
1720 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
1723 static void ilk_display_irq_handler(struct drm_i915_private *dev_priv,
1727 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
1729 if (hotplug_trigger)
1730 ilk_hpd_irq_handler(dev_priv, hotplug_trigger);
1732 if (de_iir & DE_AUX_CHANNEL_A)
1733 dp_aux_irq_handler(dev_priv);
1735 if (de_iir & DE_GSE)
1736 intel_opregion_asle_intr(dev_priv);
1738 if (de_iir & DE_POISON)
1739 drm_err(&dev_priv->drm, "Poison interrupt\n");
1741 for_each_pipe(dev_priv, pipe) {
1742 if (de_iir & DE_PIPE_VBLANK(pipe))
1743 intel_handle_vblank(dev_priv, pipe);
1745 if (de_iir & DE_PLANE_FLIP_DONE(pipe))
1746 flip_done_handler(dev_priv, pipe);
1748 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
1749 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1751 if (de_iir & DE_PIPE_CRC_DONE(pipe))
1752 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1755 /* check event from PCH */
1756 if (de_iir & DE_PCH_EVENT) {
1757 u32 pch_iir = intel_uncore_read(&dev_priv->uncore, SDEIIR);
1759 if (HAS_PCH_CPT(dev_priv))
1760 cpt_irq_handler(dev_priv, pch_iir);
1762 ibx_irq_handler(dev_priv, pch_iir);
1764 /* should clear PCH hotplug event before clear CPU irq */
1765 intel_uncore_write(&dev_priv->uncore, SDEIIR, pch_iir);
1768 if (DISPLAY_VER(dev_priv) == 5 && de_iir & DE_PCU_EVENT)
1769 gen5_rps_irq_handler(&to_gt(dev_priv)->rps);
1772 static void ivb_display_irq_handler(struct drm_i915_private *dev_priv,
1776 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
1778 if (hotplug_trigger)
1779 ilk_hpd_irq_handler(dev_priv, hotplug_trigger);
1781 if (de_iir & DE_ERR_INT_IVB)
1782 ivb_err_int_handler(dev_priv);
1784 if (de_iir & DE_AUX_CHANNEL_A_IVB)
1785 dp_aux_irq_handler(dev_priv);
1787 if (de_iir & DE_GSE_IVB)
1788 intel_opregion_asle_intr(dev_priv);
1790 for_each_pipe(dev_priv, pipe) {
1791 if (de_iir & DE_PIPE_VBLANK_IVB(pipe))
1792 intel_handle_vblank(dev_priv, pipe);
1794 if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe))
1795 flip_done_handler(dev_priv, pipe);
1798 /* check event from PCH */
1799 if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) {
1800 u32 pch_iir = intel_uncore_read(&dev_priv->uncore, SDEIIR);
1802 cpt_irq_handler(dev_priv, pch_iir);
1804 /* clear PCH hotplug event before clear CPU irq */
1805 intel_uncore_write(&dev_priv->uncore, SDEIIR, pch_iir);
1810 * To handle irqs with the minimum potential races with fresh interrupts, we:
1811 * 1 - Disable Master Interrupt Control.
1812 * 2 - Find the source(s) of the interrupt.
1813 * 3 - Clear the Interrupt Identity bits (IIR).
1814 * 4 - Process the interrupt(s) that had bits set in the IIRs.
1815 * 5 - Re-enable Master Interrupt Control.
1817 static irqreturn_t ilk_irq_handler(int irq, void *arg)
1819 struct drm_i915_private *i915 = arg;
1820 void __iomem * const regs = i915->uncore.regs;
1821 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
1822 irqreturn_t ret = IRQ_NONE;
1824 if (unlikely(!intel_irqs_enabled(i915)))
1827 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1828 disable_rpm_wakeref_asserts(&i915->runtime_pm);
1830 /* disable master interrupt before clearing iir */
1831 de_ier = raw_reg_read(regs, DEIER);
1832 raw_reg_write(regs, DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
1834 /* Disable south interrupts. We'll only write to SDEIIR once, so further
1835 * interrupts will will be stored on its back queue, and then we'll be
1836 * able to process them after we restore SDEIER (as soon as we restore
1837 * it, we'll get an interrupt if SDEIIR still has something to process
1838 * due to its back queue). */
1839 if (!HAS_PCH_NOP(i915)) {
1840 sde_ier = raw_reg_read(regs, SDEIER);
1841 raw_reg_write(regs, SDEIER, 0);
1844 /* Find, clear, then process each source of interrupt */
1846 gt_iir = raw_reg_read(regs, GTIIR);
1848 raw_reg_write(regs, GTIIR, gt_iir);
1849 if (GRAPHICS_VER(i915) >= 6)
1850 gen6_gt_irq_handler(to_gt(i915), gt_iir);
1852 gen5_gt_irq_handler(to_gt(i915), gt_iir);
1856 de_iir = raw_reg_read(regs, DEIIR);
1858 raw_reg_write(regs, DEIIR, de_iir);
1859 if (DISPLAY_VER(i915) >= 7)
1860 ivb_display_irq_handler(i915, de_iir);
1862 ilk_display_irq_handler(i915, de_iir);
1866 if (GRAPHICS_VER(i915) >= 6) {
1867 u32 pm_iir = raw_reg_read(regs, GEN6_PMIIR);
1869 raw_reg_write(regs, GEN6_PMIIR, pm_iir);
1870 gen6_rps_irq_handler(&to_gt(i915)->rps, pm_iir);
1875 raw_reg_write(regs, DEIER, de_ier);
1877 raw_reg_write(regs, SDEIER, sde_ier);
1879 pmu_irq_stats(i915, ret);
1881 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1882 enable_rpm_wakeref_asserts(&i915->runtime_pm);
1887 static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv,
1888 u32 hotplug_trigger)
1890 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
1892 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG, 0, 0);
1894 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1895 hotplug_trigger, dig_hotplug_reg,
1896 dev_priv->display.hotplug.hpd,
1897 bxt_port_hotplug_long_detect);
1899 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
1902 static void gen11_hpd_irq_handler(struct drm_i915_private *dev_priv, u32 iir)
1904 u32 pin_mask = 0, long_mask = 0;
1905 u32 trigger_tc = iir & GEN11_DE_TC_HOTPLUG_MASK;
1906 u32 trigger_tbt = iir & GEN11_DE_TBT_HOTPLUG_MASK;
1909 u32 dig_hotplug_reg;
1911 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, GEN11_TC_HOTPLUG_CTL, 0, 0);
1913 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1914 trigger_tc, dig_hotplug_reg,
1915 dev_priv->display.hotplug.hpd,
1916 gen11_port_hotplug_long_detect);
1920 u32 dig_hotplug_reg;
1922 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, GEN11_TBT_HOTPLUG_CTL, 0, 0);
1924 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1925 trigger_tbt, dig_hotplug_reg,
1926 dev_priv->display.hotplug.hpd,
1927 gen11_port_hotplug_long_detect);
1931 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
1933 drm_err(&dev_priv->drm,
1934 "Unexpected DE HPD interrupt 0x%08x\n", iir);
1937 static u32 gen8_de_port_aux_mask(struct drm_i915_private *dev_priv)
1941 if (DISPLAY_VER(dev_priv) >= 14)
1942 return TGL_DE_PORT_AUX_DDIA |
1943 TGL_DE_PORT_AUX_DDIB;
1944 else if (DISPLAY_VER(dev_priv) >= 13)
1945 return TGL_DE_PORT_AUX_DDIA |
1946 TGL_DE_PORT_AUX_DDIB |
1947 TGL_DE_PORT_AUX_DDIC |
1948 XELPD_DE_PORT_AUX_DDID |
1949 XELPD_DE_PORT_AUX_DDIE |
1950 TGL_DE_PORT_AUX_USBC1 |
1951 TGL_DE_PORT_AUX_USBC2 |
1952 TGL_DE_PORT_AUX_USBC3 |
1953 TGL_DE_PORT_AUX_USBC4;
1954 else if (DISPLAY_VER(dev_priv) >= 12)
1955 return TGL_DE_PORT_AUX_DDIA |
1956 TGL_DE_PORT_AUX_DDIB |
1957 TGL_DE_PORT_AUX_DDIC |
1958 TGL_DE_PORT_AUX_USBC1 |
1959 TGL_DE_PORT_AUX_USBC2 |
1960 TGL_DE_PORT_AUX_USBC3 |
1961 TGL_DE_PORT_AUX_USBC4 |
1962 TGL_DE_PORT_AUX_USBC5 |
1963 TGL_DE_PORT_AUX_USBC6;
1966 mask = GEN8_AUX_CHANNEL_A;
1967 if (DISPLAY_VER(dev_priv) >= 9)
1968 mask |= GEN9_AUX_CHANNEL_B |
1969 GEN9_AUX_CHANNEL_C |
1972 if (DISPLAY_VER(dev_priv) == 11) {
1973 mask |= ICL_AUX_CHANNEL_F;
1974 mask |= ICL_AUX_CHANNEL_E;
1980 static u32 gen8_de_pipe_fault_mask(struct drm_i915_private *dev_priv)
1982 if (DISPLAY_VER(dev_priv) >= 13 || HAS_D12_PLANE_MINIMIZATION(dev_priv))
1983 return RKL_DE_PIPE_IRQ_FAULT_ERRORS;
1984 else if (DISPLAY_VER(dev_priv) >= 11)
1985 return GEN11_DE_PIPE_IRQ_FAULT_ERRORS;
1986 else if (DISPLAY_VER(dev_priv) >= 9)
1987 return GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
1989 return GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
1993 gen8_de_misc_irq_handler(struct drm_i915_private *dev_priv, u32 iir)
1997 if (iir & GEN8_DE_MISC_GSE) {
1998 intel_opregion_asle_intr(dev_priv);
2002 if (iir & GEN8_DE_EDP_PSR) {
2003 struct intel_encoder *encoder;
2007 for_each_intel_encoder_with_psr(&dev_priv->drm, encoder) {
2008 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2010 if (DISPLAY_VER(dev_priv) >= 12)
2011 iir_reg = TRANS_PSR_IIR(intel_dp->psr.transcoder);
2013 iir_reg = EDP_PSR_IIR;
2015 psr_iir = intel_uncore_rmw(&dev_priv->uncore, iir_reg, 0, 0);
2020 intel_psr_irq_handler(intel_dp, psr_iir);
2022 /* prior GEN12 only have one EDP PSR */
2023 if (DISPLAY_VER(dev_priv) < 12)
2029 drm_err(&dev_priv->drm, "Unexpected DE Misc interrupt\n");
2032 static void gen11_dsi_te_interrupt_handler(struct drm_i915_private *dev_priv,
2035 enum pipe pipe = INVALID_PIPE;
2036 enum transcoder dsi_trans;
2041 * Incase of dual link, TE comes from DSI_1
2042 * this is to check if dual link is enabled
2044 val = intel_uncore_read(&dev_priv->uncore, TRANS_DDI_FUNC_CTL2(TRANSCODER_DSI_0));
2045 val &= PORT_SYNC_MODE_ENABLE;
2048 * if dual link is enabled, then read DSI_0
2049 * transcoder registers
2051 port = ((te_trigger & DSI1_TE && val) || (te_trigger & DSI0_TE)) ?
2053 dsi_trans = (port == PORT_A) ? TRANSCODER_DSI_0 : TRANSCODER_DSI_1;
2055 /* Check if DSI configured in command mode */
2056 val = intel_uncore_read(&dev_priv->uncore, DSI_TRANS_FUNC_CONF(dsi_trans));
2057 val = val & OP_MODE_MASK;
2059 if (val != CMD_MODE_NO_GATE && val != CMD_MODE_TE_GATE) {
2060 drm_err(&dev_priv->drm, "DSI trancoder not configured in command mode\n");
2064 /* Get PIPE for handling VBLANK event */
2065 val = intel_uncore_read(&dev_priv->uncore, TRANS_DDI_FUNC_CTL(dsi_trans));
2066 switch (val & TRANS_DDI_EDP_INPUT_MASK) {
2067 case TRANS_DDI_EDP_INPUT_A_ON:
2070 case TRANS_DDI_EDP_INPUT_B_ONOFF:
2073 case TRANS_DDI_EDP_INPUT_C_ONOFF:
2077 drm_err(&dev_priv->drm, "Invalid PIPE\n");
2081 intel_handle_vblank(dev_priv, pipe);
2083 /* clear TE in dsi IIR */
2084 port = (te_trigger & DSI1_TE) ? PORT_B : PORT_A;
2085 tmp = intel_uncore_rmw(&dev_priv->uncore, DSI_INTR_IDENT_REG(port), 0, 0);
2088 static u32 gen8_de_pipe_flip_done_mask(struct drm_i915_private *i915)
2090 if (DISPLAY_VER(i915) >= 9)
2091 return GEN9_PIPE_PLANE1_FLIP_DONE;
2093 return GEN8_PIPE_PRIMARY_FLIP_DONE;
2096 u32 gen8_de_pipe_underrun_mask(struct drm_i915_private *dev_priv)
2098 u32 mask = GEN8_PIPE_FIFO_UNDERRUN;
2100 if (DISPLAY_VER(dev_priv) >= 13)
2101 mask |= XELPD_PIPE_SOFT_UNDERRUN |
2102 XELPD_PIPE_HARD_UNDERRUN;
2107 static void gen8_read_and_ack_pch_irqs(struct drm_i915_private *i915, u32 *pch_iir, u32 *pica_iir)
2112 *pch_iir = intel_de_read(i915, SDEIIR);
2117 * PICA IER must be disabled/re-enabled around clearing PICA IIR and
2118 * SDEIIR, to avoid losing PICA IRQs and to ensure that such IRQs set
2119 * their flags both in the PICA and SDE IIR.
2121 if (*pch_iir & SDE_PICAINTERRUPT) {
2122 drm_WARN_ON(&i915->drm, INTEL_PCH_TYPE(i915) < PCH_MTP);
2124 pica_ier = intel_de_rmw(i915, PICAINTERRUPT_IER, ~0, 0);
2125 *pica_iir = intel_de_read(i915, PICAINTERRUPT_IIR);
2126 intel_de_write(i915, PICAINTERRUPT_IIR, *pica_iir);
2129 intel_de_write(i915, SDEIIR, *pch_iir);
2132 intel_de_write(i915, PICAINTERRUPT_IER, pica_ier);
2136 gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl)
2138 irqreturn_t ret = IRQ_NONE;
2142 drm_WARN_ON_ONCE(&dev_priv->drm, !HAS_DISPLAY(dev_priv));
2144 if (master_ctl & GEN8_DE_MISC_IRQ) {
2145 iir = intel_uncore_read(&dev_priv->uncore, GEN8_DE_MISC_IIR);
2147 intel_uncore_write(&dev_priv->uncore, GEN8_DE_MISC_IIR, iir);
2149 gen8_de_misc_irq_handler(dev_priv, iir);
2151 drm_err_ratelimited(&dev_priv->drm,
2152 "The master control interrupt lied (DE MISC)!\n");
2156 if (DISPLAY_VER(dev_priv) >= 11 && (master_ctl & GEN11_DE_HPD_IRQ)) {
2157 iir = intel_uncore_read(&dev_priv->uncore, GEN11_DE_HPD_IIR);
2159 intel_uncore_write(&dev_priv->uncore, GEN11_DE_HPD_IIR, iir);
2161 gen11_hpd_irq_handler(dev_priv, iir);
2163 drm_err_ratelimited(&dev_priv->drm,
2164 "The master control interrupt lied, (DE HPD)!\n");
2168 if (master_ctl & GEN8_DE_PORT_IRQ) {
2169 iir = intel_uncore_read(&dev_priv->uncore, GEN8_DE_PORT_IIR);
2173 intel_uncore_write(&dev_priv->uncore, GEN8_DE_PORT_IIR, iir);
2176 if (iir & gen8_de_port_aux_mask(dev_priv)) {
2177 dp_aux_irq_handler(dev_priv);
2181 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
2182 u32 hotplug_trigger = iir & BXT_DE_PORT_HOTPLUG_MASK;
2184 if (hotplug_trigger) {
2185 bxt_hpd_irq_handler(dev_priv, hotplug_trigger);
2188 } else if (IS_BROADWELL(dev_priv)) {
2189 u32 hotplug_trigger = iir & BDW_DE_PORT_HOTPLUG_MASK;
2191 if (hotplug_trigger) {
2192 ilk_hpd_irq_handler(dev_priv, hotplug_trigger);
2197 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
2198 (iir & BXT_DE_PORT_GMBUS)) {
2199 gmbus_irq_handler(dev_priv);
2203 if (DISPLAY_VER(dev_priv) >= 11) {
2204 u32 te_trigger = iir & (DSI0_TE | DSI1_TE);
2207 gen11_dsi_te_interrupt_handler(dev_priv, te_trigger);
2213 drm_err_ratelimited(&dev_priv->drm,
2214 "Unexpected DE Port interrupt\n");
2217 drm_err_ratelimited(&dev_priv->drm,
2218 "The master control interrupt lied (DE PORT)!\n");
2221 for_each_pipe(dev_priv, pipe) {
2224 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2227 iir = intel_uncore_read(&dev_priv->uncore, GEN8_DE_PIPE_IIR(pipe));
2229 drm_err_ratelimited(&dev_priv->drm,
2230 "The master control interrupt lied (DE PIPE)!\n");
2235 intel_uncore_write(&dev_priv->uncore, GEN8_DE_PIPE_IIR(pipe), iir);
2237 if (iir & GEN8_PIPE_VBLANK)
2238 intel_handle_vblank(dev_priv, pipe);
2240 if (iir & gen8_de_pipe_flip_done_mask(dev_priv))
2241 flip_done_handler(dev_priv, pipe);
2243 if (iir & GEN8_PIPE_CDCLK_CRC_DONE)
2244 hsw_pipe_crc_irq_handler(dev_priv, pipe);
2246 if (iir & gen8_de_pipe_underrun_mask(dev_priv))
2247 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2249 fault_errors = iir & gen8_de_pipe_fault_mask(dev_priv);
2251 drm_err_ratelimited(&dev_priv->drm,
2252 "Fault errors on pipe %c: 0x%08x\n",
2257 if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) &&
2258 master_ctl & GEN8_DE_PCH_IRQ) {
2262 * FIXME(BDW): Assume for now that the new interrupt handling
2263 * scheme also closed the SDE interrupt handling race we've seen
2264 * on older pch-split platforms. But this needs testing.
2266 gen8_read_and_ack_pch_irqs(dev_priv, &iir, &pica_iir);
2271 xelpdp_pica_irq_handler(dev_priv, pica_iir);
2273 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
2274 icp_irq_handler(dev_priv, iir);
2275 else if (INTEL_PCH_TYPE(dev_priv) >= PCH_SPT)
2276 spt_irq_handler(dev_priv, iir);
2278 cpt_irq_handler(dev_priv, iir);
2281 * Like on previous PCH there seems to be something
2282 * fishy going on with forwarding PCH interrupts.
2284 drm_dbg(&dev_priv->drm,
2285 "The master control interrupt lied (SDE)!\n");
2292 static inline u32 gen8_master_intr_disable(void __iomem * const regs)
2294 raw_reg_write(regs, GEN8_MASTER_IRQ, 0);
2297 * Now with master disabled, get a sample of level indications
2298 * for this interrupt. Indications will be cleared on related acks.
2299 * New indications can and will light up during processing,
2300 * and will generate new interrupt after enabling master.
2302 return raw_reg_read(regs, GEN8_MASTER_IRQ);
2305 static inline void gen8_master_intr_enable(void __iomem * const regs)
2307 raw_reg_write(regs, GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2310 static irqreturn_t gen8_irq_handler(int irq, void *arg)
2312 struct drm_i915_private *dev_priv = arg;
2313 void __iomem * const regs = dev_priv->uncore.regs;
2316 if (!intel_irqs_enabled(dev_priv))
2319 master_ctl = gen8_master_intr_disable(regs);
2321 gen8_master_intr_enable(regs);
2325 /* Find, queue (onto bottom-halves), then clear each source */
2326 gen8_gt_irq_handler(to_gt(dev_priv), master_ctl);
2328 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2329 if (master_ctl & ~GEN8_GT_IRQS) {
2330 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
2331 gen8_de_irq_handler(dev_priv, master_ctl);
2332 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
2335 gen8_master_intr_enable(regs);
2337 pmu_irq_stats(dev_priv, IRQ_HANDLED);
2343 gen11_gu_misc_irq_ack(struct drm_i915_private *i915, const u32 master_ctl)
2345 void __iomem * const regs = i915->uncore.regs;
2348 if (!(master_ctl & GEN11_GU_MISC_IRQ))
2351 iir = raw_reg_read(regs, GEN11_GU_MISC_IIR);
2353 raw_reg_write(regs, GEN11_GU_MISC_IIR, iir);
2359 gen11_gu_misc_irq_handler(struct drm_i915_private *i915, const u32 iir)
2361 if (iir & GEN11_GU_MISC_GSE)
2362 intel_opregion_asle_intr(i915);
2365 static inline u32 gen11_master_intr_disable(void __iomem * const regs)
2367 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, 0);
2370 * Now with master disabled, get a sample of level indications
2371 * for this interrupt. Indications will be cleared on related acks.
2372 * New indications can and will light up during processing,
2373 * and will generate new interrupt after enabling master.
2375 return raw_reg_read(regs, GEN11_GFX_MSTR_IRQ);
2378 static inline void gen11_master_intr_enable(void __iomem * const regs)
2380 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, GEN11_MASTER_IRQ);
2384 gen11_display_irq_handler(struct drm_i915_private *i915)
2386 void __iomem * const regs = i915->uncore.regs;
2387 const u32 disp_ctl = raw_reg_read(regs, GEN11_DISPLAY_INT_CTL);
2389 disable_rpm_wakeref_asserts(&i915->runtime_pm);
2391 * GEN11_DISPLAY_INT_CTL has same format as GEN8_MASTER_IRQ
2392 * for the display related bits.
2394 raw_reg_write(regs, GEN11_DISPLAY_INT_CTL, 0x0);
2395 gen8_de_irq_handler(i915, disp_ctl);
2396 raw_reg_write(regs, GEN11_DISPLAY_INT_CTL,
2397 GEN11_DISPLAY_IRQ_ENABLE);
2399 enable_rpm_wakeref_asserts(&i915->runtime_pm);
2402 static irqreturn_t gen11_irq_handler(int irq, void *arg)
2404 struct drm_i915_private *i915 = arg;
2405 void __iomem * const regs = i915->uncore.regs;
2406 struct intel_gt *gt = to_gt(i915);
2410 if (!intel_irqs_enabled(i915))
2413 master_ctl = gen11_master_intr_disable(regs);
2415 gen11_master_intr_enable(regs);
2419 /* Find, queue (onto bottom-halves), then clear each source */
2420 gen11_gt_irq_handler(gt, master_ctl);
2422 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2423 if (master_ctl & GEN11_DISPLAY_IRQ)
2424 gen11_display_irq_handler(i915);
2426 gu_misc_iir = gen11_gu_misc_irq_ack(i915, master_ctl);
2428 gen11_master_intr_enable(regs);
2430 gen11_gu_misc_irq_handler(i915, gu_misc_iir);
2432 pmu_irq_stats(i915, IRQ_HANDLED);
2437 static inline u32 dg1_master_intr_disable(void __iomem * const regs)
2441 /* First disable interrupts */
2442 raw_reg_write(regs, DG1_MSTR_TILE_INTR, 0);
2444 /* Get the indication levels and ack the master unit */
2445 val = raw_reg_read(regs, DG1_MSTR_TILE_INTR);
2449 raw_reg_write(regs, DG1_MSTR_TILE_INTR, val);
2454 static inline void dg1_master_intr_enable(void __iomem * const regs)
2456 raw_reg_write(regs, DG1_MSTR_TILE_INTR, DG1_MSTR_IRQ);
2459 static irqreturn_t dg1_irq_handler(int irq, void *arg)
2461 struct drm_i915_private * const i915 = arg;
2462 struct intel_gt *gt = to_gt(i915);
2463 void __iomem * const regs = gt->uncore->regs;
2464 u32 master_tile_ctl, master_ctl;
2467 if (!intel_irqs_enabled(i915))
2470 master_tile_ctl = dg1_master_intr_disable(regs);
2471 if (!master_tile_ctl) {
2472 dg1_master_intr_enable(regs);
2476 /* FIXME: we only support tile 0 for now. */
2477 if (master_tile_ctl & DG1_MSTR_TILE(0)) {
2478 master_ctl = raw_reg_read(regs, GEN11_GFX_MSTR_IRQ);
2479 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, master_ctl);
2481 drm_err(&i915->drm, "Tile not supported: 0x%08x\n",
2483 dg1_master_intr_enable(regs);
2487 gen11_gt_irq_handler(gt, master_ctl);
2489 if (master_ctl & GEN11_DISPLAY_IRQ)
2490 gen11_display_irq_handler(i915);
2492 gu_misc_iir = gen11_gu_misc_irq_ack(i915, master_ctl);
2494 dg1_master_intr_enable(regs);
2496 gen11_gu_misc_irq_handler(i915, gu_misc_iir);
2498 pmu_irq_stats(i915, IRQ_HANDLED);
2503 /* Called from drm generic code, passed 'crtc' which
2504 * we use as a pipe index
2506 int i8xx_enable_vblank(struct drm_crtc *crtc)
2508 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2509 enum pipe pipe = to_intel_crtc(crtc)->pipe;
2510 unsigned long irqflags;
2512 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2513 i915_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
2514 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2519 int i915gm_enable_vblank(struct drm_crtc *crtc)
2521 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2524 * Vblank interrupts fail to wake the device up from C2+.
2525 * Disabling render clock gating during C-states avoids
2526 * the problem. There is a small power cost so we do this
2527 * only when vblank interrupts are actually enabled.
2529 if (dev_priv->vblank_enabled++ == 0)
2530 intel_uncore_write(&dev_priv->uncore, SCPD0, _MASKED_BIT_ENABLE(CSTATE_RENDER_CLOCK_GATE_DISABLE));
2532 return i8xx_enable_vblank(crtc);
2535 int i965_enable_vblank(struct drm_crtc *crtc)
2537 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2538 enum pipe pipe = to_intel_crtc(crtc)->pipe;
2539 unsigned long irqflags;
2541 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2542 i915_enable_pipestat(dev_priv, pipe,
2543 PIPE_START_VBLANK_INTERRUPT_STATUS);
2544 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2549 int ilk_enable_vblank(struct drm_crtc *crtc)
2551 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2552 enum pipe pipe = to_intel_crtc(crtc)->pipe;
2553 unsigned long irqflags;
2554 u32 bit = DISPLAY_VER(dev_priv) >= 7 ?
2555 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
2557 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2558 ilk_enable_display_irq(dev_priv, bit);
2559 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2561 /* Even though there is no DMC, frame counter can get stuck when
2562 * PSR is active as no frames are generated.
2564 if (HAS_PSR(dev_priv))
2565 drm_crtc_vblank_restore(crtc);
2570 static bool gen11_dsi_configure_te(struct intel_crtc *intel_crtc,
2573 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
2576 if (!(intel_crtc->mode_flags &
2577 (I915_MODE_FLAG_DSI_USE_TE1 | I915_MODE_FLAG_DSI_USE_TE0)))
2580 /* for dual link cases we consider TE from slave */
2581 if (intel_crtc->mode_flags & I915_MODE_FLAG_DSI_USE_TE1)
2586 intel_uncore_rmw(&dev_priv->uncore, DSI_INTR_MASK_REG(port), DSI_TE_EVENT,
2587 enable ? 0 : DSI_TE_EVENT);
2589 intel_uncore_rmw(&dev_priv->uncore, DSI_INTR_IDENT_REG(port), 0, 0);
2594 int bdw_enable_vblank(struct drm_crtc *_crtc)
2596 struct intel_crtc *crtc = to_intel_crtc(_crtc);
2597 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2598 enum pipe pipe = crtc->pipe;
2599 unsigned long irqflags;
2601 if (gen11_dsi_configure_te(crtc, true))
2604 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2605 bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
2606 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2608 /* Even if there is no DMC, frame counter can get stuck when
2609 * PSR is active as no frames are generated, so check only for PSR.
2611 if (HAS_PSR(dev_priv))
2612 drm_crtc_vblank_restore(&crtc->base);
2617 /* Called from drm generic code, passed 'crtc' which
2618 * we use as a pipe index
2620 void i8xx_disable_vblank(struct drm_crtc *crtc)
2622 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2623 enum pipe pipe = to_intel_crtc(crtc)->pipe;
2624 unsigned long irqflags;
2626 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2627 i915_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
2628 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2631 void i915gm_disable_vblank(struct drm_crtc *crtc)
2633 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2635 i8xx_disable_vblank(crtc);
2637 if (--dev_priv->vblank_enabled == 0)
2638 intel_uncore_write(&dev_priv->uncore, SCPD0, _MASKED_BIT_DISABLE(CSTATE_RENDER_CLOCK_GATE_DISABLE));
2641 void i965_disable_vblank(struct drm_crtc *crtc)
2643 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2644 enum pipe pipe = to_intel_crtc(crtc)->pipe;
2645 unsigned long irqflags;
2647 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2648 i915_disable_pipestat(dev_priv, pipe,
2649 PIPE_START_VBLANK_INTERRUPT_STATUS);
2650 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2653 void ilk_disable_vblank(struct drm_crtc *crtc)
2655 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2656 enum pipe pipe = to_intel_crtc(crtc)->pipe;
2657 unsigned long irqflags;
2658 u32 bit = DISPLAY_VER(dev_priv) >= 7 ?
2659 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
2661 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2662 ilk_disable_display_irq(dev_priv, bit);
2663 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2666 void bdw_disable_vblank(struct drm_crtc *_crtc)
2668 struct intel_crtc *crtc = to_intel_crtc(_crtc);
2669 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2670 enum pipe pipe = crtc->pipe;
2671 unsigned long irqflags;
2673 if (gen11_dsi_configure_te(crtc, false))
2676 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2677 bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
2678 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2681 static void ibx_irq_reset(struct drm_i915_private *dev_priv)
2683 struct intel_uncore *uncore = &dev_priv->uncore;
2685 if (HAS_PCH_NOP(dev_priv))
2688 GEN3_IRQ_RESET(uncore, SDE);
2690 if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
2691 intel_uncore_write(&dev_priv->uncore, SERR_INT, 0xffffffff);
2694 static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
2696 struct intel_uncore *uncore = &dev_priv->uncore;
2698 if (IS_CHERRYVIEW(dev_priv))
2699 intel_uncore_write(uncore, DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
2701 intel_uncore_write(uncore, DPINVGTT, DPINVGTT_STATUS_MASK_VLV);
2703 i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0);
2704 intel_uncore_rmw(uncore, PORT_HOTPLUG_STAT, 0, 0);
2706 i9xx_pipestat_irq_reset(dev_priv);
2708 GEN3_IRQ_RESET(uncore, VLV_);
2709 dev_priv->irq_mask = ~0u;
2712 static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
2714 struct intel_uncore *uncore = &dev_priv->uncore;
2720 pipestat_mask = PIPE_CRC_DONE_INTERRUPT_STATUS;
2722 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
2723 for_each_pipe(dev_priv, pipe)
2724 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
2726 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
2727 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2728 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2729 I915_LPE_PIPE_A_INTERRUPT |
2730 I915_LPE_PIPE_B_INTERRUPT;
2732 if (IS_CHERRYVIEW(dev_priv))
2733 enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT |
2734 I915_LPE_PIPE_C_INTERRUPT;
2736 drm_WARN_ON(&dev_priv->drm, dev_priv->irq_mask != ~0u);
2738 dev_priv->irq_mask = ~enable_mask;
2740 GEN3_IRQ_INIT(uncore, VLV_, dev_priv->irq_mask, enable_mask);
2745 static void ilk_irq_reset(struct drm_i915_private *dev_priv)
2747 struct intel_uncore *uncore = &dev_priv->uncore;
2749 GEN3_IRQ_RESET(uncore, DE);
2750 dev_priv->irq_mask = ~0u;
2752 if (GRAPHICS_VER(dev_priv) == 7)
2753 intel_uncore_write(uncore, GEN7_ERR_INT, 0xffffffff);
2755 if (IS_HASWELL(dev_priv)) {
2756 intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff);
2757 intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff);
2760 gen5_gt_irq_reset(to_gt(dev_priv));
2762 ibx_irq_reset(dev_priv);
2765 static void valleyview_irq_reset(struct drm_i915_private *dev_priv)
2767 intel_uncore_write(&dev_priv->uncore, VLV_MASTER_IER, 0);
2768 intel_uncore_posting_read(&dev_priv->uncore, VLV_MASTER_IER);
2770 gen5_gt_irq_reset(to_gt(dev_priv));
2772 spin_lock_irq(&dev_priv->irq_lock);
2773 if (dev_priv->display_irqs_enabled)
2774 vlv_display_irq_reset(dev_priv);
2775 spin_unlock_irq(&dev_priv->irq_lock);
2778 static void gen8_display_irq_reset(struct drm_i915_private *dev_priv)
2780 struct intel_uncore *uncore = &dev_priv->uncore;
2783 if (!HAS_DISPLAY(dev_priv))
2786 intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff);
2787 intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff);
2789 for_each_pipe(dev_priv, pipe)
2790 if (intel_display_power_is_enabled(dev_priv,
2791 POWER_DOMAIN_PIPE(pipe)))
2792 GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe);
2794 GEN3_IRQ_RESET(uncore, GEN8_DE_PORT_);
2795 GEN3_IRQ_RESET(uncore, GEN8_DE_MISC_);
2798 static void gen8_irq_reset(struct drm_i915_private *dev_priv)
2800 struct intel_uncore *uncore = &dev_priv->uncore;
2802 gen8_master_intr_disable(uncore->regs);
2804 gen8_gt_irq_reset(to_gt(dev_priv));
2805 gen8_display_irq_reset(dev_priv);
2806 GEN3_IRQ_RESET(uncore, GEN8_PCU_);
2808 if (HAS_PCH_SPLIT(dev_priv))
2809 ibx_irq_reset(dev_priv);
2813 static void gen11_display_irq_reset(struct drm_i915_private *dev_priv)
2815 struct intel_uncore *uncore = &dev_priv->uncore;
2817 u32 trans_mask = BIT(TRANSCODER_A) | BIT(TRANSCODER_B) |
2818 BIT(TRANSCODER_C) | BIT(TRANSCODER_D);
2820 if (!HAS_DISPLAY(dev_priv))
2823 intel_uncore_write(uncore, GEN11_DISPLAY_INT_CTL, 0);
2825 if (DISPLAY_VER(dev_priv) >= 12) {
2826 enum transcoder trans;
2828 for_each_cpu_transcoder_masked(dev_priv, trans, trans_mask) {
2829 enum intel_display_power_domain domain;
2831 domain = POWER_DOMAIN_TRANSCODER(trans);
2832 if (!intel_display_power_is_enabled(dev_priv, domain))
2835 intel_uncore_write(uncore, TRANS_PSR_IMR(trans), 0xffffffff);
2836 intel_uncore_write(uncore, TRANS_PSR_IIR(trans), 0xffffffff);
2839 intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff);
2840 intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff);
2843 for_each_pipe(dev_priv, pipe)
2844 if (intel_display_power_is_enabled(dev_priv,
2845 POWER_DOMAIN_PIPE(pipe)))
2846 GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe);
2848 GEN3_IRQ_RESET(uncore, GEN8_DE_PORT_);
2849 GEN3_IRQ_RESET(uncore, GEN8_DE_MISC_);
2851 if (DISPLAY_VER(dev_priv) >= 14)
2852 GEN3_IRQ_RESET(uncore, PICAINTERRUPT_);
2854 GEN3_IRQ_RESET(uncore, GEN11_DE_HPD_);
2856 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
2857 GEN3_IRQ_RESET(uncore, SDE);
2860 static void gen11_irq_reset(struct drm_i915_private *dev_priv)
2862 struct intel_gt *gt = to_gt(dev_priv);
2863 struct intel_uncore *uncore = gt->uncore;
2865 gen11_master_intr_disable(dev_priv->uncore.regs);
2867 gen11_gt_irq_reset(gt);
2868 gen11_display_irq_reset(dev_priv);
2870 GEN3_IRQ_RESET(uncore, GEN11_GU_MISC_);
2871 GEN3_IRQ_RESET(uncore, GEN8_PCU_);
2874 static void dg1_irq_reset(struct drm_i915_private *dev_priv)
2876 struct intel_gt *gt = to_gt(dev_priv);
2877 struct intel_uncore *uncore = gt->uncore;
2879 dg1_master_intr_disable(dev_priv->uncore.regs);
2881 gen11_gt_irq_reset(gt);
2882 gen11_display_irq_reset(dev_priv);
2884 GEN3_IRQ_RESET(uncore, GEN11_GU_MISC_);
2885 GEN3_IRQ_RESET(uncore, GEN8_PCU_);
2888 void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
2891 struct intel_uncore *uncore = &dev_priv->uncore;
2892 u32 extra_ier = GEN8_PIPE_VBLANK |
2893 gen8_de_pipe_underrun_mask(dev_priv) |
2894 gen8_de_pipe_flip_done_mask(dev_priv);
2897 spin_lock_irq(&dev_priv->irq_lock);
2899 if (!intel_irqs_enabled(dev_priv)) {
2900 spin_unlock_irq(&dev_priv->irq_lock);
2904 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
2905 GEN8_IRQ_INIT_NDX(uncore, DE_PIPE, pipe,
2906 dev_priv->de_irq_mask[pipe],
2907 ~dev_priv->de_irq_mask[pipe] | extra_ier);
2909 spin_unlock_irq(&dev_priv->irq_lock);
2912 void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv,
2915 struct intel_uncore *uncore = &dev_priv->uncore;
2918 spin_lock_irq(&dev_priv->irq_lock);
2920 if (!intel_irqs_enabled(dev_priv)) {
2921 spin_unlock_irq(&dev_priv->irq_lock);
2925 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
2926 GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe);
2928 spin_unlock_irq(&dev_priv->irq_lock);
2930 /* make sure we're done processing display irqs */
2931 intel_synchronize_irq(dev_priv);
2934 static void cherryview_irq_reset(struct drm_i915_private *dev_priv)
2936 struct intel_uncore *uncore = &dev_priv->uncore;
2938 intel_uncore_write(uncore, GEN8_MASTER_IRQ, 0);
2939 intel_uncore_posting_read(&dev_priv->uncore, GEN8_MASTER_IRQ);
2941 gen8_gt_irq_reset(to_gt(dev_priv));
2943 GEN3_IRQ_RESET(uncore, GEN8_PCU_);
2945 spin_lock_irq(&dev_priv->irq_lock);
2946 if (dev_priv->display_irqs_enabled)
2947 vlv_display_irq_reset(dev_priv);
2948 spin_unlock_irq(&dev_priv->irq_lock);
2951 static u32 ibx_hotplug_mask(enum hpd_pin hpd_pin)
2955 return PORTA_HOTPLUG_ENABLE;
2957 return PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_MASK;
2959 return PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_MASK;
2961 return PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_MASK;
2967 static u32 ibx_hotplug_enables(struct intel_encoder *encoder)
2969 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
2971 switch (encoder->hpd_pin) {
2974 * When CPU and PCH are on the same package, port A
2975 * HPD must be enabled in both north and south.
2977 return HAS_PCH_LPT_LP(i915) ?
2978 PORTA_HOTPLUG_ENABLE : 0;
2980 return PORTB_HOTPLUG_ENABLE |
2981 PORTB_PULSE_DURATION_2ms;
2983 return PORTC_HOTPLUG_ENABLE |
2984 PORTC_PULSE_DURATION_2ms;
2986 return PORTD_HOTPLUG_ENABLE |
2987 PORTD_PULSE_DURATION_2ms;
2993 static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv)
2996 * Enable digital hotplug on the PCH, and configure the DP short pulse
2997 * duration to 2ms (which is the minimum in the Display Port spec).
2998 * The pulse duration bits are reserved on LPT+.
3000 intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG,
3001 intel_hpd_hotplug_mask(dev_priv, ibx_hotplug_mask),
3002 intel_hpd_hotplug_enables(dev_priv, ibx_hotplug_enables));
3005 static void ibx_hpd_enable_detection(struct intel_encoder *encoder)
3007 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3009 intel_uncore_rmw(&i915->uncore, PCH_PORT_HOTPLUG,
3010 ibx_hotplug_mask(encoder->hpd_pin),
3011 ibx_hotplug_enables(encoder));
3014 static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
3016 u32 hotplug_irqs, enabled_irqs;
3018 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
3019 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
3021 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3023 ibx_hpd_detection_setup(dev_priv);
3026 static u32 icp_ddi_hotplug_mask(enum hpd_pin hpd_pin)
3033 return SHOTPLUG_CTL_DDI_HPD_ENABLE(hpd_pin);
3039 static u32 icp_ddi_hotplug_enables(struct intel_encoder *encoder)
3041 return icp_ddi_hotplug_mask(encoder->hpd_pin);
3044 static u32 icp_tc_hotplug_mask(enum hpd_pin hpd_pin)
3053 return ICP_TC_HPD_ENABLE(hpd_pin);
3059 static u32 icp_tc_hotplug_enables(struct intel_encoder *encoder)
3061 return icp_tc_hotplug_mask(encoder->hpd_pin);
3064 static void icp_ddi_hpd_detection_setup(struct drm_i915_private *dev_priv)
3066 intel_uncore_rmw(&dev_priv->uncore, SHOTPLUG_CTL_DDI,
3067 intel_hpd_hotplug_mask(dev_priv, icp_ddi_hotplug_mask),
3068 intel_hpd_hotplug_enables(dev_priv, icp_ddi_hotplug_enables));
3071 static void icp_ddi_hpd_enable_detection(struct intel_encoder *encoder)
3073 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3075 intel_uncore_rmw(&i915->uncore, SHOTPLUG_CTL_DDI,
3076 icp_ddi_hotplug_mask(encoder->hpd_pin),
3077 icp_ddi_hotplug_enables(encoder));
3080 static void icp_tc_hpd_detection_setup(struct drm_i915_private *dev_priv)
3082 intel_uncore_rmw(&dev_priv->uncore, SHOTPLUG_CTL_TC,
3083 intel_hpd_hotplug_mask(dev_priv, icp_tc_hotplug_mask),
3084 intel_hpd_hotplug_enables(dev_priv, icp_tc_hotplug_enables));
3087 static void icp_tc_hpd_enable_detection(struct intel_encoder *encoder)
3089 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3091 intel_uncore_rmw(&i915->uncore, SHOTPLUG_CTL_TC,
3092 icp_tc_hotplug_mask(encoder->hpd_pin),
3093 icp_tc_hotplug_enables(encoder));
3096 static void icp_hpd_enable_detection(struct intel_encoder *encoder)
3098 icp_ddi_hpd_enable_detection(encoder);
3099 icp_tc_hpd_enable_detection(encoder);
3102 static void icp_hpd_irq_setup(struct drm_i915_private *dev_priv)
3104 u32 hotplug_irqs, enabled_irqs;
3106 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
3107 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
3109 if (INTEL_PCH_TYPE(dev_priv) <= PCH_TGP)
3110 intel_uncore_write(&dev_priv->uncore, SHPD_FILTER_CNT, SHPD_FILTER_CNT_500_ADJ);
3112 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3114 icp_ddi_hpd_detection_setup(dev_priv);
3115 icp_tc_hpd_detection_setup(dev_priv);
3118 static u32 gen11_hotplug_mask(enum hpd_pin hpd_pin)
3127 return GEN11_HOTPLUG_CTL_ENABLE(hpd_pin);
3133 static u32 gen11_hotplug_enables(struct intel_encoder *encoder)
3135 return gen11_hotplug_mask(encoder->hpd_pin);
3138 static void dg1_hpd_invert(struct drm_i915_private *i915)
3140 u32 val = (INVERT_DDIA_HPD |
3144 intel_uncore_rmw(&i915->uncore, SOUTH_CHICKEN1, 0, val);
3147 static void dg1_hpd_enable_detection(struct intel_encoder *encoder)
3149 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3151 dg1_hpd_invert(i915);
3152 icp_hpd_enable_detection(encoder);
3155 static void dg1_hpd_irq_setup(struct drm_i915_private *dev_priv)
3157 dg1_hpd_invert(dev_priv);
3158 icp_hpd_irq_setup(dev_priv);
3161 static void gen11_tc_hpd_detection_setup(struct drm_i915_private *dev_priv)
3163 intel_uncore_rmw(&dev_priv->uncore, GEN11_TC_HOTPLUG_CTL,
3164 intel_hpd_hotplug_mask(dev_priv, gen11_hotplug_mask),
3165 intel_hpd_hotplug_enables(dev_priv, gen11_hotplug_enables));
3168 static void gen11_tc_hpd_enable_detection(struct intel_encoder *encoder)
3170 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3172 intel_uncore_rmw(&i915->uncore, GEN11_TC_HOTPLUG_CTL,
3173 gen11_hotplug_mask(encoder->hpd_pin),
3174 gen11_hotplug_enables(encoder));
3177 static void gen11_tbt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3179 intel_uncore_rmw(&dev_priv->uncore, GEN11_TBT_HOTPLUG_CTL,
3180 intel_hpd_hotplug_mask(dev_priv, gen11_hotplug_mask),
3181 intel_hpd_hotplug_enables(dev_priv, gen11_hotplug_enables));
3184 static void gen11_tbt_hpd_enable_detection(struct intel_encoder *encoder)
3186 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3188 intel_uncore_rmw(&i915->uncore, GEN11_TBT_HOTPLUG_CTL,
3189 gen11_hotplug_mask(encoder->hpd_pin),
3190 gen11_hotplug_enables(encoder));
3193 static void gen11_hpd_enable_detection(struct intel_encoder *encoder)
3195 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3197 gen11_tc_hpd_enable_detection(encoder);
3198 gen11_tbt_hpd_enable_detection(encoder);
3200 if (INTEL_PCH_TYPE(i915) >= PCH_ICP)
3201 icp_hpd_enable_detection(encoder);
3204 static void gen11_hpd_irq_setup(struct drm_i915_private *dev_priv)
3206 u32 hotplug_irqs, enabled_irqs;
3208 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.hpd);
3209 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.hpd);
3211 intel_uncore_rmw(&dev_priv->uncore, GEN11_DE_HPD_IMR, hotplug_irqs,
3212 ~enabled_irqs & hotplug_irqs);
3213 intel_uncore_posting_read(&dev_priv->uncore, GEN11_DE_HPD_IMR);
3215 gen11_tc_hpd_detection_setup(dev_priv);
3216 gen11_tbt_hpd_detection_setup(dev_priv);
3218 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
3219 icp_hpd_irq_setup(dev_priv);
3222 static u32 mtp_ddi_hotplug_mask(enum hpd_pin hpd_pin)
3227 return SHOTPLUG_CTL_DDI_HPD_ENABLE(hpd_pin);
3233 static u32 mtp_ddi_hotplug_enables(struct intel_encoder *encoder)
3235 return mtp_ddi_hotplug_mask(encoder->hpd_pin);
3238 static u32 mtp_tc_hotplug_mask(enum hpd_pin hpd_pin)
3245 return ICP_TC_HPD_ENABLE(hpd_pin);
3251 static u32 mtp_tc_hotplug_enables(struct intel_encoder *encoder)
3253 return mtp_tc_hotplug_mask(encoder->hpd_pin);
3256 static void mtp_ddi_hpd_detection_setup(struct drm_i915_private *i915)
3258 intel_de_rmw(i915, SHOTPLUG_CTL_DDI,
3259 intel_hpd_hotplug_mask(i915, mtp_ddi_hotplug_mask),
3260 intel_hpd_hotplug_enables(i915, mtp_ddi_hotplug_enables));
3263 static void mtp_ddi_hpd_enable_detection(struct intel_encoder *encoder)
3265 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3267 intel_de_rmw(i915, SHOTPLUG_CTL_DDI,
3268 mtp_ddi_hotplug_mask(encoder->hpd_pin),
3269 mtp_ddi_hotplug_enables(encoder));
3272 static void mtp_tc_hpd_detection_setup(struct drm_i915_private *i915)
3274 intel_de_rmw(i915, SHOTPLUG_CTL_TC,
3275 intel_hpd_hotplug_mask(i915, mtp_tc_hotplug_mask),
3276 intel_hpd_hotplug_enables(i915, mtp_tc_hotplug_enables));
3279 static void mtp_tc_hpd_enable_detection(struct intel_encoder *encoder)
3281 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3283 intel_de_rmw(i915, SHOTPLUG_CTL_DDI,
3284 mtp_tc_hotplug_mask(encoder->hpd_pin),
3285 mtp_tc_hotplug_enables(encoder));
3288 static void mtp_hpd_invert(struct drm_i915_private *i915)
3290 u32 val = (INVERT_DDIA_HPD |
3297 INVERT_DDID_HPD_MTP |
3299 intel_de_rmw(i915, SOUTH_CHICKEN1, 0, val);
3302 static void mtp_hpd_enable_detection(struct intel_encoder *encoder)
3304 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3306 mtp_hpd_invert(i915);
3307 mtp_ddi_hpd_enable_detection(encoder);
3308 mtp_tc_hpd_enable_detection(encoder);
3311 static void mtp_hpd_irq_setup(struct drm_i915_private *i915)
3313 u32 hotplug_irqs, enabled_irqs;
3315 enabled_irqs = intel_hpd_enabled_irqs(i915, i915->display.hotplug.pch_hpd);
3316 hotplug_irqs = intel_hpd_hotplug_irqs(i915, i915->display.hotplug.pch_hpd);
3318 intel_de_write(i915, SHPD_FILTER_CNT, SHPD_FILTER_CNT_500_ADJ);
3320 mtp_hpd_invert(i915);
3321 ibx_display_interrupt_update(i915, hotplug_irqs, enabled_irqs);
3323 mtp_ddi_hpd_detection_setup(i915);
3324 mtp_tc_hpd_detection_setup(i915);
3327 static bool is_xelpdp_pica_hpd_pin(enum hpd_pin hpd_pin)
3329 return hpd_pin >= HPD_PORT_TC1 && hpd_pin <= HPD_PORT_TC4;
3332 static void _xelpdp_pica_hpd_detection_setup(struct drm_i915_private *i915,
3333 enum hpd_pin hpd_pin, bool enable)
3335 u32 mask = XELPDP_TBT_HOTPLUG_ENABLE |
3336 XELPDP_DP_ALT_HOTPLUG_ENABLE;
3338 if (!is_xelpdp_pica_hpd_pin(hpd_pin))
3341 intel_de_rmw(i915, XELPDP_PORT_HOTPLUG_CTL(hpd_pin),
3342 mask, enable ? mask : 0);
3345 static void xelpdp_pica_hpd_enable_detection(struct intel_encoder *encoder)
3347 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3349 _xelpdp_pica_hpd_detection_setup(i915, encoder->hpd_pin, true);
3352 static void xelpdp_pica_hpd_detection_setup(struct drm_i915_private *i915)
3354 struct intel_encoder *encoder;
3355 u32 available_pins = 0;
3358 BUILD_BUG_ON(BITS_PER_TYPE(available_pins) < HPD_NUM_PINS);
3360 for_each_intel_encoder(&i915->drm, encoder)
3361 available_pins |= BIT(encoder->hpd_pin);
3363 for_each_hpd_pin(pin)
3364 _xelpdp_pica_hpd_detection_setup(i915, pin, available_pins & BIT(pin));
3367 static void xelpdp_hpd_enable_detection(struct intel_encoder *encoder)
3369 xelpdp_pica_hpd_enable_detection(encoder);
3370 mtp_hpd_enable_detection(encoder);
3373 static void xelpdp_hpd_irq_setup(struct drm_i915_private *i915)
3375 u32 hotplug_irqs, enabled_irqs;
3377 enabled_irqs = intel_hpd_enabled_irqs(i915, i915->display.hotplug.hpd);
3378 hotplug_irqs = intel_hpd_hotplug_irqs(i915, i915->display.hotplug.hpd);
3380 intel_de_rmw(i915, PICAINTERRUPT_IMR, hotplug_irqs,
3381 ~enabled_irqs & hotplug_irqs);
3382 intel_uncore_posting_read(&i915->uncore, PICAINTERRUPT_IMR);
3384 xelpdp_pica_hpd_detection_setup(i915);
3386 if (INTEL_PCH_TYPE(i915) >= PCH_MTP)
3387 mtp_hpd_irq_setup(i915);
3390 static u32 spt_hotplug_mask(enum hpd_pin hpd_pin)
3394 return PORTA_HOTPLUG_ENABLE;
3396 return PORTB_HOTPLUG_ENABLE;
3398 return PORTC_HOTPLUG_ENABLE;
3400 return PORTD_HOTPLUG_ENABLE;
3406 static u32 spt_hotplug_enables(struct intel_encoder *encoder)
3408 return spt_hotplug_mask(encoder->hpd_pin);
3411 static u32 spt_hotplug2_mask(enum hpd_pin hpd_pin)
3415 return PORTE_HOTPLUG_ENABLE;
3421 static u32 spt_hotplug2_enables(struct intel_encoder *encoder)
3423 return spt_hotplug2_mask(encoder->hpd_pin);
3426 static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3428 /* Display WA #1179 WaHardHangonHotPlug: cnp */
3429 if (HAS_PCH_CNP(dev_priv)) {
3430 intel_uncore_rmw(&dev_priv->uncore, SOUTH_CHICKEN1, CHASSIS_CLK_REQ_DURATION_MASK,
3431 CHASSIS_CLK_REQ_DURATION(0xf));
3434 /* Enable digital hotplug on the PCH */
3435 intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG,
3436 intel_hpd_hotplug_mask(dev_priv, spt_hotplug_mask),
3437 intel_hpd_hotplug_enables(dev_priv, spt_hotplug_enables));
3439 intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG2,
3440 intel_hpd_hotplug_mask(dev_priv, spt_hotplug2_mask),
3441 intel_hpd_hotplug_enables(dev_priv, spt_hotplug2_enables));
3444 static void spt_hpd_enable_detection(struct intel_encoder *encoder)
3446 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3448 /* Display WA #1179 WaHardHangonHotPlug: cnp */
3449 if (HAS_PCH_CNP(i915)) {
3450 intel_uncore_rmw(&i915->uncore, SOUTH_CHICKEN1,
3451 CHASSIS_CLK_REQ_DURATION_MASK,
3452 CHASSIS_CLK_REQ_DURATION(0xf));
3455 intel_uncore_rmw(&i915->uncore, PCH_PORT_HOTPLUG,
3456 spt_hotplug_mask(encoder->hpd_pin),
3457 spt_hotplug_enables(encoder));
3459 intel_uncore_rmw(&i915->uncore, PCH_PORT_HOTPLUG2,
3460 spt_hotplug2_mask(encoder->hpd_pin),
3461 spt_hotplug2_enables(encoder));
3464 static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
3466 u32 hotplug_irqs, enabled_irqs;
3468 if (INTEL_PCH_TYPE(dev_priv) >= PCH_CNP)
3469 intel_uncore_write(&dev_priv->uncore, SHPD_FILTER_CNT, SHPD_FILTER_CNT_500_ADJ);
3471 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
3472 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
3474 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3476 spt_hpd_detection_setup(dev_priv);
3479 static u32 ilk_hotplug_mask(enum hpd_pin hpd_pin)
3483 return DIGITAL_PORTA_HOTPLUG_ENABLE |
3484 DIGITAL_PORTA_PULSE_DURATION_MASK;
3490 static u32 ilk_hotplug_enables(struct intel_encoder *encoder)
3492 switch (encoder->hpd_pin) {
3494 return DIGITAL_PORTA_HOTPLUG_ENABLE |
3495 DIGITAL_PORTA_PULSE_DURATION_2ms;
3501 static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv)
3504 * Enable digital hotplug on the CPU, and configure the DP short pulse
3505 * duration to 2ms (which is the minimum in the Display Port spec)
3506 * The pulse duration bits are reserved on HSW+.
3508 intel_uncore_rmw(&dev_priv->uncore, DIGITAL_PORT_HOTPLUG_CNTRL,
3509 intel_hpd_hotplug_mask(dev_priv, ilk_hotplug_mask),
3510 intel_hpd_hotplug_enables(dev_priv, ilk_hotplug_enables));
3513 static void ilk_hpd_enable_detection(struct intel_encoder *encoder)
3515 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3517 intel_uncore_rmw(&i915->uncore, DIGITAL_PORT_HOTPLUG_CNTRL,
3518 ilk_hotplug_mask(encoder->hpd_pin),
3519 ilk_hotplug_enables(encoder));
3521 ibx_hpd_enable_detection(encoder);
3524 static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
3526 u32 hotplug_irqs, enabled_irqs;
3528 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.hpd);
3529 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.hpd);
3531 if (DISPLAY_VER(dev_priv) >= 8)
3532 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
3534 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3536 ilk_hpd_detection_setup(dev_priv);
3538 ibx_hpd_irq_setup(dev_priv);
3541 static u32 bxt_hotplug_mask(enum hpd_pin hpd_pin)
3545 return PORTA_HOTPLUG_ENABLE | BXT_DDIA_HPD_INVERT;
3547 return PORTB_HOTPLUG_ENABLE | BXT_DDIB_HPD_INVERT;
3549 return PORTC_HOTPLUG_ENABLE | BXT_DDIC_HPD_INVERT;
3555 static u32 bxt_hotplug_enables(struct intel_encoder *encoder)
3559 switch (encoder->hpd_pin) {
3561 hotplug = PORTA_HOTPLUG_ENABLE;
3562 if (intel_bios_encoder_hpd_invert(encoder->devdata))
3563 hotplug |= BXT_DDIA_HPD_INVERT;
3566 hotplug = PORTB_HOTPLUG_ENABLE;
3567 if (intel_bios_encoder_hpd_invert(encoder->devdata))
3568 hotplug |= BXT_DDIB_HPD_INVERT;
3571 hotplug = PORTC_HOTPLUG_ENABLE;
3572 if (intel_bios_encoder_hpd_invert(encoder->devdata))
3573 hotplug |= BXT_DDIC_HPD_INVERT;
3580 static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3582 intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG,
3583 intel_hpd_hotplug_mask(dev_priv, bxt_hotplug_mask),
3584 intel_hpd_hotplug_enables(dev_priv, bxt_hotplug_enables));
3587 static void bxt_hpd_enable_detection(struct intel_encoder *encoder)
3589 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3591 intel_uncore_rmw(&i915->uncore, PCH_PORT_HOTPLUG,
3592 bxt_hotplug_mask(encoder->hpd_pin),
3593 bxt_hotplug_enables(encoder));
3596 static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
3598 u32 hotplug_irqs, enabled_irqs;
3600 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.hpd);
3601 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.hpd);
3603 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
3605 bxt_hpd_detection_setup(dev_priv);
3609 * SDEIER is also touched by the interrupt handler to work around missed PCH
3610 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3611 * instead we unconditionally enable all PCH interrupt sources here, but then
3612 * only unmask them as needed with SDEIMR.
3614 * Note that we currently do this after installing the interrupt handler,
3615 * but before we enable the master interrupt. That should be sufficient
3616 * to avoid races with the irq handler, assuming we have MSI. Shared legacy
3617 * interrupts could still race.
3619 static void ibx_irq_postinstall(struct drm_i915_private *dev_priv)
3621 struct intel_uncore *uncore = &dev_priv->uncore;
3624 if (HAS_PCH_NOP(dev_priv))
3627 if (HAS_PCH_IBX(dev_priv))
3628 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
3629 else if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
3630 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
3632 mask = SDE_GMBUS_CPT;
3634 GEN3_IRQ_INIT(uncore, SDE, ~mask, 0xffffffff);
3637 static void ilk_irq_postinstall(struct drm_i915_private *dev_priv)
3639 struct intel_uncore *uncore = &dev_priv->uncore;
3640 u32 display_mask, extra_mask;
3642 if (GRAPHICS_VER(dev_priv) >= 7) {
3643 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
3644 DE_PCH_EVENT_IVB | DE_AUX_CHANNEL_A_IVB);
3645 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
3646 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
3647 DE_PLANE_FLIP_DONE_IVB(PLANE_C) |
3648 DE_PLANE_FLIP_DONE_IVB(PLANE_B) |
3649 DE_PLANE_FLIP_DONE_IVB(PLANE_A) |
3650 DE_DP_A_HOTPLUG_IVB);
3652 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
3653 DE_AUX_CHANNEL_A | DE_PIPEB_CRC_DONE |
3654 DE_PIPEA_CRC_DONE | DE_POISON);
3655 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK |
3656 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
3657 DE_PLANE_FLIP_DONE(PLANE_A) |
3658 DE_PLANE_FLIP_DONE(PLANE_B) |
3662 if (IS_HASWELL(dev_priv)) {
3663 gen3_assert_iir_is_zero(uncore, EDP_PSR_IIR);
3664 display_mask |= DE_EDP_PSR_INT_HSW;
3667 if (IS_IRONLAKE_M(dev_priv))
3668 extra_mask |= DE_PCU_EVENT;
3670 dev_priv->irq_mask = ~display_mask;
3672 ibx_irq_postinstall(dev_priv);
3674 gen5_gt_irq_postinstall(to_gt(dev_priv));
3676 GEN3_IRQ_INIT(uncore, DE, dev_priv->irq_mask,
3677 display_mask | extra_mask);
3680 void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3682 lockdep_assert_held(&dev_priv->irq_lock);
3684 if (dev_priv->display_irqs_enabled)
3687 dev_priv->display_irqs_enabled = true;
3689 if (intel_irqs_enabled(dev_priv)) {
3690 vlv_display_irq_reset(dev_priv);
3691 vlv_display_irq_postinstall(dev_priv);
3695 void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3697 lockdep_assert_held(&dev_priv->irq_lock);
3699 if (!dev_priv->display_irqs_enabled)
3702 dev_priv->display_irqs_enabled = false;
3704 if (intel_irqs_enabled(dev_priv))
3705 vlv_display_irq_reset(dev_priv);
3709 static void valleyview_irq_postinstall(struct drm_i915_private *dev_priv)
3711 gen5_gt_irq_postinstall(to_gt(dev_priv));
3713 spin_lock_irq(&dev_priv->irq_lock);
3714 if (dev_priv->display_irqs_enabled)
3715 vlv_display_irq_postinstall(dev_priv);
3716 spin_unlock_irq(&dev_priv->irq_lock);
3718 intel_uncore_write(&dev_priv->uncore, VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
3719 intel_uncore_posting_read(&dev_priv->uncore, VLV_MASTER_IER);
3722 static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3724 struct intel_uncore *uncore = &dev_priv->uncore;
3726 u32 de_pipe_masked = gen8_de_pipe_fault_mask(dev_priv) |
3727 GEN8_PIPE_CDCLK_CRC_DONE;
3728 u32 de_pipe_enables;
3729 u32 de_port_masked = gen8_de_port_aux_mask(dev_priv);
3730 u32 de_port_enables;
3731 u32 de_misc_masked = GEN8_DE_EDP_PSR;
3732 u32 trans_mask = BIT(TRANSCODER_A) | BIT(TRANSCODER_B) |
3733 BIT(TRANSCODER_C) | BIT(TRANSCODER_D);
3736 if (!HAS_DISPLAY(dev_priv))
3739 if (DISPLAY_VER(dev_priv) <= 10)
3740 de_misc_masked |= GEN8_DE_MISC_GSE;
3742 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
3743 de_port_masked |= BXT_DE_PORT_GMBUS;
3745 if (DISPLAY_VER(dev_priv) >= 11) {
3748 if (intel_bios_is_dsi_present(dev_priv, &port))
3749 de_port_masked |= DSI0_TE | DSI1_TE;
3752 de_pipe_enables = de_pipe_masked |
3754 gen8_de_pipe_underrun_mask(dev_priv) |
3755 gen8_de_pipe_flip_done_mask(dev_priv);
3757 de_port_enables = de_port_masked;
3758 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
3759 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
3760 else if (IS_BROADWELL(dev_priv))
3761 de_port_enables |= BDW_DE_PORT_HOTPLUG_MASK;
3763 if (DISPLAY_VER(dev_priv) >= 12) {
3764 enum transcoder trans;
3766 for_each_cpu_transcoder_masked(dev_priv, trans, trans_mask) {
3767 enum intel_display_power_domain domain;
3769 domain = POWER_DOMAIN_TRANSCODER(trans);
3770 if (!intel_display_power_is_enabled(dev_priv, domain))
3773 gen3_assert_iir_is_zero(uncore, TRANS_PSR_IIR(trans));
3776 gen3_assert_iir_is_zero(uncore, EDP_PSR_IIR);
3779 for_each_pipe(dev_priv, pipe) {
3780 dev_priv->de_irq_mask[pipe] = ~de_pipe_masked;
3782 if (intel_display_power_is_enabled(dev_priv,
3783 POWER_DOMAIN_PIPE(pipe)))
3784 GEN8_IRQ_INIT_NDX(uncore, DE_PIPE, pipe,
3785 dev_priv->de_irq_mask[pipe],
3789 GEN3_IRQ_INIT(uncore, GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
3790 GEN3_IRQ_INIT(uncore, GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked);
3792 if (IS_DISPLAY_VER(dev_priv, 11, 13)) {
3793 u32 de_hpd_masked = 0;
3794 u32 de_hpd_enables = GEN11_DE_TC_HOTPLUG_MASK |
3795 GEN11_DE_TBT_HOTPLUG_MASK;
3797 GEN3_IRQ_INIT(uncore, GEN11_DE_HPD_, ~de_hpd_masked,
3802 static void mtp_irq_postinstall(struct drm_i915_private *i915)
3804 struct intel_uncore *uncore = &i915->uncore;
3805 u32 sde_mask = SDE_GMBUS_ICP | SDE_PICAINTERRUPT;
3806 u32 de_hpd_mask = XELPDP_AUX_TC_MASK;
3807 u32 de_hpd_enables = de_hpd_mask | XELPDP_DP_ALT_HOTPLUG_MASK |
3808 XELPDP_TBT_HOTPLUG_MASK;
3810 GEN3_IRQ_INIT(uncore, PICAINTERRUPT_, ~de_hpd_mask,
3813 GEN3_IRQ_INIT(uncore, SDE, ~sde_mask, 0xffffffff);
3816 static void icp_irq_postinstall(struct drm_i915_private *dev_priv)
3818 struct intel_uncore *uncore = &dev_priv->uncore;
3819 u32 mask = SDE_GMBUS_ICP;
3821 GEN3_IRQ_INIT(uncore, SDE, ~mask, 0xffffffff);
3824 static void gen8_irq_postinstall(struct drm_i915_private *dev_priv)
3826 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
3827 icp_irq_postinstall(dev_priv);
3828 else if (HAS_PCH_SPLIT(dev_priv))
3829 ibx_irq_postinstall(dev_priv);
3831 gen8_gt_irq_postinstall(to_gt(dev_priv));
3832 gen8_de_irq_postinstall(dev_priv);
3834 gen8_master_intr_enable(dev_priv->uncore.regs);
3837 static void gen11_de_irq_postinstall(struct drm_i915_private *dev_priv)
3839 if (!HAS_DISPLAY(dev_priv))
3842 gen8_de_irq_postinstall(dev_priv);
3844 intel_uncore_write(&dev_priv->uncore, GEN11_DISPLAY_INT_CTL,
3845 GEN11_DISPLAY_IRQ_ENABLE);
3848 static void gen11_irq_postinstall(struct drm_i915_private *dev_priv)
3850 struct intel_gt *gt = to_gt(dev_priv);
3851 struct intel_uncore *uncore = gt->uncore;
3852 u32 gu_misc_masked = GEN11_GU_MISC_GSE;
3854 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
3855 icp_irq_postinstall(dev_priv);
3857 gen11_gt_irq_postinstall(gt);
3858 gen11_de_irq_postinstall(dev_priv);
3860 GEN3_IRQ_INIT(uncore, GEN11_GU_MISC_, ~gu_misc_masked, gu_misc_masked);
3862 gen11_master_intr_enable(uncore->regs);
3863 intel_uncore_posting_read(&dev_priv->uncore, GEN11_GFX_MSTR_IRQ);
3866 static void dg1_irq_postinstall(struct drm_i915_private *dev_priv)
3868 struct intel_gt *gt = to_gt(dev_priv);
3869 struct intel_uncore *uncore = gt->uncore;
3870 u32 gu_misc_masked = GEN11_GU_MISC_GSE;
3872 gen11_gt_irq_postinstall(gt);
3874 GEN3_IRQ_INIT(uncore, GEN11_GU_MISC_, ~gu_misc_masked, gu_misc_masked);
3876 if (HAS_DISPLAY(dev_priv)) {
3877 if (DISPLAY_VER(dev_priv) >= 14)
3878 mtp_irq_postinstall(dev_priv);
3880 icp_irq_postinstall(dev_priv);
3882 gen8_de_irq_postinstall(dev_priv);
3883 intel_uncore_write(&dev_priv->uncore, GEN11_DISPLAY_INT_CTL,
3884 GEN11_DISPLAY_IRQ_ENABLE);
3887 dg1_master_intr_enable(uncore->regs);
3888 intel_uncore_posting_read(uncore, DG1_MSTR_TILE_INTR);
3891 static void cherryview_irq_postinstall(struct drm_i915_private *dev_priv)
3893 gen8_gt_irq_postinstall(to_gt(dev_priv));
3895 spin_lock_irq(&dev_priv->irq_lock);
3896 if (dev_priv->display_irqs_enabled)
3897 vlv_display_irq_postinstall(dev_priv);
3898 spin_unlock_irq(&dev_priv->irq_lock);
3900 intel_uncore_write(&dev_priv->uncore, GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
3901 intel_uncore_posting_read(&dev_priv->uncore, GEN8_MASTER_IRQ);
3904 static void i8xx_irq_reset(struct drm_i915_private *dev_priv)
3906 struct intel_uncore *uncore = &dev_priv->uncore;
3908 i9xx_pipestat_irq_reset(dev_priv);
3910 gen2_irq_reset(uncore);
3911 dev_priv->irq_mask = ~0u;
3914 static u32 i9xx_error_mask(struct drm_i915_private *i915)
3917 * On gen2/3 FBC generates (seemingly spurious)
3918 * display INVALID_GTT/INVALID_GTT_PTE table errors.
3920 * Also gen3 bspec has this to say:
3921 * "DISPA_INVALID_GTT_PTE
3922 " [DevNapa] : Reserved. This bit does not reflect the page
3923 " table error for the display plane A."
3925 * Unfortunately we can't mask off individual PGTBL_ER bits,
3926 * so we just have to mask off all page table errors via EMR.
3929 return ~I915_ERROR_MEMORY_REFRESH;
3931 return ~(I915_ERROR_PAGE_TABLE |
3932 I915_ERROR_MEMORY_REFRESH);
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, EMR, i9xx_error_mask(dev_priv));
3942 /* Unmask the interrupts that we always want on. */
3943 dev_priv->irq_mask =
3944 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3945 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3946 I915_MASTER_ERROR_INTERRUPT);
3949 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3950 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3951 I915_MASTER_ERROR_INTERRUPT |
3952 I915_USER_INTERRUPT;
3954 gen2_irq_init(uncore, dev_priv->irq_mask, enable_mask);
3956 /* Interrupt setup is already guaranteed to be single-threaded, this is
3957 * just to make the assert_spin_locked check happy. */
3958 spin_lock_irq(&dev_priv->irq_lock);
3959 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3960 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
3961 spin_unlock_irq(&dev_priv->irq_lock);
3964 static void i8xx_error_irq_ack(struct drm_i915_private *i915,
3965 u16 *eir, u16 *eir_stuck)
3967 struct intel_uncore *uncore = &i915->uncore;
3970 *eir = intel_uncore_read16(uncore, EIR);
3971 intel_uncore_write16(uncore, EIR, *eir);
3973 *eir_stuck = intel_uncore_read16(uncore, EIR);
3974 if (*eir_stuck == 0)
3978 * Toggle all EMR bits to make sure we get an edge
3979 * in the ISR master error bit if we don't clear
3980 * all the EIR bits. Otherwise the edge triggered
3981 * IIR on i965/g4x wouldn't notice that an interrupt
3982 * is still pending. Also some EIR bits can't be
3983 * cleared except by handling the underlying error
3984 * (or by a GPU reset) so we mask any bit that
3987 emr = intel_uncore_read16(uncore, EMR);
3988 intel_uncore_write16(uncore, EMR, 0xffff);
3989 intel_uncore_write16(uncore, EMR, emr | *eir_stuck);
3992 static void i8xx_error_irq_handler(struct drm_i915_private *dev_priv,
3993 u16 eir, u16 eir_stuck)
3995 drm_dbg(&dev_priv->drm, "Master Error: EIR 0x%04x\n", eir);
3998 drm_dbg(&dev_priv->drm, "EIR stuck: 0x%04x, masked\n",
4001 drm_dbg(&dev_priv->drm, "PGTBL_ER: 0x%08x\n",
4002 intel_uncore_read(&dev_priv->uncore, PGTBL_ER));
4005 static void i9xx_error_irq_ack(struct drm_i915_private *dev_priv,
4006 u32 *eir, u32 *eir_stuck)
4010 *eir = intel_uncore_read(&dev_priv->uncore, EIR);
4011 intel_uncore_write(&dev_priv->uncore, EIR, *eir);
4013 *eir_stuck = intel_uncore_read(&dev_priv->uncore, EIR);
4014 if (*eir_stuck == 0)
4018 * Toggle all EMR bits to make sure we get an edge
4019 * in the ISR master error bit if we don't clear
4020 * all the EIR bits. Otherwise the edge triggered
4021 * IIR on i965/g4x wouldn't notice that an interrupt
4022 * is still pending. Also some EIR bits can't be
4023 * cleared except by handling the underlying error
4024 * (or by a GPU reset) so we mask any bit that
4027 emr = intel_uncore_read(&dev_priv->uncore, EMR);
4028 intel_uncore_write(&dev_priv->uncore, EMR, 0xffffffff);
4029 intel_uncore_write(&dev_priv->uncore, EMR, emr | *eir_stuck);
4032 static void i9xx_error_irq_handler(struct drm_i915_private *dev_priv,
4033 u32 eir, u32 eir_stuck)
4035 drm_dbg(&dev_priv->drm, "Master Error, EIR 0x%08x\n", eir);
4038 drm_dbg(&dev_priv->drm, "EIR stuck: 0x%08x, masked\n",
4041 drm_dbg(&dev_priv->drm, "PGTBL_ER: 0x%08x\n",
4042 intel_uncore_read(&dev_priv->uncore, PGTBL_ER));
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_rmw(&dev_priv->uncore, PORT_HOTPLUG_STAT, 0, 0);
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(uncore, EMR, i9xx_error_mask(dev_priv));
4114 /* Unmask the interrupts that we always want on. */
4115 dev_priv->irq_mask =
4116 ~(I915_ASLE_INTERRUPT |
4117 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4118 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4119 I915_MASTER_ERROR_INTERRUPT);
4122 I915_ASLE_INTERRUPT |
4123 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4124 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4125 I915_MASTER_ERROR_INTERRUPT |
4126 I915_USER_INTERRUPT;
4128 if (I915_HAS_HOTPLUG(dev_priv)) {
4129 /* Enable in IER... */
4130 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
4131 /* and unmask in IMR */
4132 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
4135 GEN3_IRQ_INIT(uncore, GEN2_, dev_priv->irq_mask, enable_mask);
4137 /* Interrupt setup is already guaranteed to be single-threaded, this is
4138 * just to make the assert_spin_locked check happy. */
4139 spin_lock_irq(&dev_priv->irq_lock);
4140 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4141 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
4142 spin_unlock_irq(&dev_priv->irq_lock);
4144 i915_enable_asle_pipestat(dev_priv);
4147 static irqreturn_t i915_irq_handler(int irq, void *arg)
4149 struct drm_i915_private *dev_priv = arg;
4150 irqreturn_t ret = IRQ_NONE;
4152 if (!intel_irqs_enabled(dev_priv))
4155 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4156 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
4159 u32 pipe_stats[I915_MAX_PIPES] = {};
4160 u32 eir = 0, eir_stuck = 0;
4161 u32 hotplug_status = 0;
4164 iir = intel_uncore_read(&dev_priv->uncore, GEN2_IIR);
4170 if (I915_HAS_HOTPLUG(dev_priv) &&
4171 iir & I915_DISPLAY_PORT_INTERRUPT)
4172 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
4174 /* Call regardless, as some status bits might not be
4175 * signalled in iir */
4176 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
4178 if (iir & I915_MASTER_ERROR_INTERRUPT)
4179 i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
4181 intel_uncore_write(&dev_priv->uncore, GEN2_IIR, iir);
4183 if (iir & I915_USER_INTERRUPT)
4184 intel_engine_cs_irq(to_gt(dev_priv)->engine[RCS0], iir);
4186 if (iir & I915_MASTER_ERROR_INTERRUPT)
4187 i9xx_error_irq_handler(dev_priv, eir, eir_stuck);
4190 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
4192 i915_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4195 pmu_irq_stats(dev_priv, ret);
4197 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
4202 static void i965_irq_reset(struct drm_i915_private *dev_priv)
4204 struct intel_uncore *uncore = &dev_priv->uncore;
4206 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
4207 intel_uncore_rmw(uncore, PORT_HOTPLUG_STAT, 0, 0);
4209 i9xx_pipestat_irq_reset(dev_priv);
4211 GEN3_IRQ_RESET(uncore, GEN2_);
4212 dev_priv->irq_mask = ~0u;
4215 static u32 i965_error_mask(struct drm_i915_private *i915)
4218 * Enable some error detection, note the instruction error mask
4219 * bit is reserved, so we leave it masked.
4221 * i965 FBC no longer generates spurious GTT errors,
4222 * so we can always enable the page table errors.
4225 return ~(GM45_ERROR_PAGE_TABLE |
4226 GM45_ERROR_MEM_PRIV |
4227 GM45_ERROR_CP_PRIV |
4228 I915_ERROR_MEMORY_REFRESH);
4230 return ~(I915_ERROR_PAGE_TABLE |
4231 I915_ERROR_MEMORY_REFRESH);
4234 static void i965_irq_postinstall(struct drm_i915_private *dev_priv)
4236 struct intel_uncore *uncore = &dev_priv->uncore;
4239 intel_uncore_write(uncore, EMR, i965_error_mask(dev_priv));
4241 /* Unmask the interrupts that we always want on. */
4242 dev_priv->irq_mask =
4243 ~(I915_ASLE_INTERRUPT |
4244 I915_DISPLAY_PORT_INTERRUPT |
4245 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4246 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4247 I915_MASTER_ERROR_INTERRUPT);
4250 I915_ASLE_INTERRUPT |
4251 I915_DISPLAY_PORT_INTERRUPT |
4252 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4253 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4254 I915_MASTER_ERROR_INTERRUPT |
4255 I915_USER_INTERRUPT;
4257 if (IS_G4X(dev_priv))
4258 enable_mask |= I915_BSD_USER_INTERRUPT;
4260 GEN3_IRQ_INIT(uncore, GEN2_, dev_priv->irq_mask, enable_mask);
4262 /* Interrupt setup is already guaranteed to be single-threaded, this is
4263 * just to make the assert_spin_locked check happy. */
4264 spin_lock_irq(&dev_priv->irq_lock);
4265 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4266 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4267 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
4268 spin_unlock_irq(&dev_priv->irq_lock);
4270 i915_enable_asle_pipestat(dev_priv);
4273 static void i915_hpd_enable_detection(struct intel_encoder *encoder)
4275 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
4276 u32 hotplug_en = hpd_mask_i915[encoder->hpd_pin];
4278 /* HPD sense and interrupt enable are one and the same */
4279 i915_hotplug_interrupt_update(i915, hotplug_en, hotplug_en);
4282 static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
4286 lockdep_assert_held(&dev_priv->irq_lock);
4288 /* Note HDMI and DP share hotplug bits */
4289 /* enable bits are the same for all generations */
4290 hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
4291 /* Programming the CRT detection parameters tends
4292 to generate a spurious hotplug event about three
4293 seconds later. So just do it once.
4295 if (IS_G4X(dev_priv))
4296 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
4297 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
4299 /* Ignore TV since it's buggy */
4300 i915_hotplug_interrupt_update_locked(dev_priv,
4301 HOTPLUG_INT_EN_MASK |
4302 CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
4303 CRT_HOTPLUG_ACTIVATION_PERIOD_64,
4307 static irqreturn_t i965_irq_handler(int irq, void *arg)
4309 struct drm_i915_private *dev_priv = arg;
4310 irqreturn_t ret = IRQ_NONE;
4312 if (!intel_irqs_enabled(dev_priv))
4315 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4316 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
4319 u32 pipe_stats[I915_MAX_PIPES] = {};
4320 u32 eir = 0, eir_stuck = 0;
4321 u32 hotplug_status = 0;
4324 iir = intel_uncore_read(&dev_priv->uncore, GEN2_IIR);
4330 if (iir & I915_DISPLAY_PORT_INTERRUPT)
4331 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
4333 /* Call regardless, as some status bits might not be
4334 * signalled in iir */
4335 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
4337 if (iir & I915_MASTER_ERROR_INTERRUPT)
4338 i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
4340 intel_uncore_write(&dev_priv->uncore, GEN2_IIR, iir);
4342 if (iir & I915_USER_INTERRUPT)
4343 intel_engine_cs_irq(to_gt(dev_priv)->engine[RCS0],
4346 if (iir & I915_BSD_USER_INTERRUPT)
4347 intel_engine_cs_irq(to_gt(dev_priv)->engine[VCS0],
4350 if (iir & I915_MASTER_ERROR_INTERRUPT)
4351 i9xx_error_irq_handler(dev_priv, eir, eir_stuck);
4354 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
4356 i965_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4359 pmu_irq_stats(dev_priv, IRQ_HANDLED);
4361 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
4366 struct intel_hotplug_funcs {
4367 /* Enable HPD sense and interrupts for all present encoders */
4368 void (*hpd_irq_setup)(struct drm_i915_private *i915);
4369 /* Enable HPD sense for a single encoder */
4370 void (*hpd_enable_detection)(struct intel_encoder *encoder);
4373 #define HPD_FUNCS(platform) \
4374 static const struct intel_hotplug_funcs platform##_hpd_funcs = { \
4375 .hpd_irq_setup = platform##_hpd_irq_setup, \
4376 .hpd_enable_detection = platform##_hpd_enable_detection, \
4389 void intel_hpd_enable_detection(struct intel_encoder *encoder)
4391 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
4393 if (i915->display.funcs.hotplug)
4394 i915->display.funcs.hotplug->hpd_enable_detection(encoder);
4397 void intel_hpd_irq_setup(struct drm_i915_private *i915)
4399 if (i915->display_irqs_enabled && i915->display.funcs.hotplug)
4400 i915->display.funcs.hotplug->hpd_irq_setup(i915);
4404 * intel_irq_init - initializes irq support
4405 * @dev_priv: i915 device instance
4407 * This function initializes all the irq support including work items, timers
4408 * and all the vtables. It does not setup the interrupt itself though.
4410 void intel_irq_init(struct drm_i915_private *dev_priv)
4414 INIT_WORK(&dev_priv->l3_parity.error_work, ivb_parity_work);
4415 for (i = 0; i < MAX_L3_SLICES; ++i)
4416 dev_priv->l3_parity.remap_info[i] = NULL;
4418 /* pre-gen11 the guc irqs bits are in the upper 16 bits of the pm reg */
4419 if (HAS_GT_UC(dev_priv) && GRAPHICS_VER(dev_priv) < 11)
4420 to_gt(dev_priv)->pm_guc_events = GUC_INTR_GUC2HOST << 16;
4422 if (!HAS_DISPLAY(dev_priv))
4425 intel_hpd_init_pins(dev_priv);
4427 intel_hpd_init_early(dev_priv);
4429 dev_priv->drm.vblank_disable_immediate = true;
4431 /* Most platforms treat the display irq block as an always-on
4432 * power domain. vlv/chv can disable it at runtime and need
4433 * special care to avoid writing any of the display block registers
4434 * outside of the power domain. We defer setting up the display irqs
4435 * in this case to the runtime pm.
4437 dev_priv->display_irqs_enabled = true;
4438 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4439 dev_priv->display_irqs_enabled = false;
4441 if (HAS_GMCH(dev_priv)) {
4442 if (I915_HAS_HOTPLUG(dev_priv))
4443 dev_priv->display.funcs.hotplug = &i915_hpd_funcs;
4445 if (HAS_PCH_DG2(dev_priv))
4446 dev_priv->display.funcs.hotplug = &icp_hpd_funcs;
4447 else if (HAS_PCH_DG1(dev_priv))
4448 dev_priv->display.funcs.hotplug = &dg1_hpd_funcs;
4449 else if (DISPLAY_VER(dev_priv) >= 14)
4450 dev_priv->display.funcs.hotplug = &xelpdp_hpd_funcs;
4451 else if (DISPLAY_VER(dev_priv) >= 11)
4452 dev_priv->display.funcs.hotplug = &gen11_hpd_funcs;
4453 else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
4454 dev_priv->display.funcs.hotplug = &bxt_hpd_funcs;
4455 else if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
4456 dev_priv->display.funcs.hotplug = &icp_hpd_funcs;
4457 else if (INTEL_PCH_TYPE(dev_priv) >= PCH_SPT)
4458 dev_priv->display.funcs.hotplug = &spt_hpd_funcs;
4460 dev_priv->display.funcs.hotplug = &ilk_hpd_funcs;
4465 * intel_irq_fini - deinitializes IRQ support
4466 * @i915: i915 device instance
4468 * This function deinitializes all the IRQ support.
4470 void intel_irq_fini(struct drm_i915_private *i915)
4474 for (i = 0; i < MAX_L3_SLICES; ++i)
4475 kfree(i915->l3_parity.remap_info[i]);
4478 static irq_handler_t intel_irq_handler(struct drm_i915_private *dev_priv)
4480 if (HAS_GMCH(dev_priv)) {
4481 if (IS_CHERRYVIEW(dev_priv))
4482 return cherryview_irq_handler;
4483 else if (IS_VALLEYVIEW(dev_priv))
4484 return valleyview_irq_handler;
4485 else if (GRAPHICS_VER(dev_priv) == 4)
4486 return i965_irq_handler;
4487 else if (GRAPHICS_VER(dev_priv) == 3)
4488 return i915_irq_handler;
4490 return i8xx_irq_handler;
4492 if (GRAPHICS_VER_FULL(dev_priv) >= IP_VER(12, 10))
4493 return dg1_irq_handler;
4494 else if (GRAPHICS_VER(dev_priv) >= 11)
4495 return gen11_irq_handler;
4496 else if (GRAPHICS_VER(dev_priv) >= 8)
4497 return gen8_irq_handler;
4499 return ilk_irq_handler;
4503 static void intel_irq_reset(struct drm_i915_private *dev_priv)
4505 if (HAS_GMCH(dev_priv)) {
4506 if (IS_CHERRYVIEW(dev_priv))
4507 cherryview_irq_reset(dev_priv);
4508 else if (IS_VALLEYVIEW(dev_priv))
4509 valleyview_irq_reset(dev_priv);
4510 else if (GRAPHICS_VER(dev_priv) == 4)
4511 i965_irq_reset(dev_priv);
4512 else if (GRAPHICS_VER(dev_priv) == 3)
4513 i915_irq_reset(dev_priv);
4515 i8xx_irq_reset(dev_priv);
4517 if (GRAPHICS_VER_FULL(dev_priv) >= IP_VER(12, 10))
4518 dg1_irq_reset(dev_priv);
4519 else if (GRAPHICS_VER(dev_priv) >= 11)
4520 gen11_irq_reset(dev_priv);
4521 else if (GRAPHICS_VER(dev_priv) >= 8)
4522 gen8_irq_reset(dev_priv);
4524 ilk_irq_reset(dev_priv);
4528 static void intel_irq_postinstall(struct drm_i915_private *dev_priv)
4530 if (HAS_GMCH(dev_priv)) {
4531 if (IS_CHERRYVIEW(dev_priv))
4532 cherryview_irq_postinstall(dev_priv);
4533 else if (IS_VALLEYVIEW(dev_priv))
4534 valleyview_irq_postinstall(dev_priv);
4535 else if (GRAPHICS_VER(dev_priv) == 4)
4536 i965_irq_postinstall(dev_priv);
4537 else if (GRAPHICS_VER(dev_priv) == 3)
4538 i915_irq_postinstall(dev_priv);
4540 i8xx_irq_postinstall(dev_priv);
4542 if (GRAPHICS_VER_FULL(dev_priv) >= IP_VER(12, 10))
4543 dg1_irq_postinstall(dev_priv);
4544 else if (GRAPHICS_VER(dev_priv) >= 11)
4545 gen11_irq_postinstall(dev_priv);
4546 else if (GRAPHICS_VER(dev_priv) >= 8)
4547 gen8_irq_postinstall(dev_priv);
4549 ilk_irq_postinstall(dev_priv);
4554 * intel_irq_install - enables the hardware interrupt
4555 * @dev_priv: i915 device instance
4557 * This function enables the hardware interrupt handling, but leaves the hotplug
4558 * handling still disabled. It is called after intel_irq_init().
4560 * In the driver load and resume code we need working interrupts in a few places
4561 * but don't want to deal with the hassle of concurrent probe and hotplug
4562 * workers. Hence the split into this two-stage approach.
4564 int intel_irq_install(struct drm_i915_private *dev_priv)
4566 int irq = to_pci_dev(dev_priv->drm.dev)->irq;
4570 * We enable some interrupt sources in our postinstall hooks, so mark
4571 * interrupts as enabled _before_ actually enabling them to avoid
4572 * special cases in our ordering checks.
4574 dev_priv->runtime_pm.irqs_enabled = true;
4576 dev_priv->irq_enabled = true;
4578 intel_irq_reset(dev_priv);
4580 ret = request_irq(irq, intel_irq_handler(dev_priv),
4581 IRQF_SHARED, DRIVER_NAME, dev_priv);
4583 dev_priv->irq_enabled = false;
4587 intel_irq_postinstall(dev_priv);
4593 * intel_irq_uninstall - finilizes all irq handling
4594 * @dev_priv: i915 device instance
4596 * This stops interrupt and hotplug handling and unregisters and frees all
4597 * resources acquired in the init functions.
4599 void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4601 int irq = to_pci_dev(dev_priv->drm.dev)->irq;
4604 * FIXME we can get called twice during driver probe
4605 * error handling as well as during driver remove due to
4606 * intel_display_driver_remove() calling us out of sequence.
4607 * Would be nice if it didn't do that...
4609 if (!dev_priv->irq_enabled)
4612 dev_priv->irq_enabled = false;
4614 intel_irq_reset(dev_priv);
4616 free_irq(irq, dev_priv);
4618 intel_hpd_cancel_work(dev_priv);
4619 dev_priv->runtime_pm.irqs_enabled = false;
4623 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4624 * @dev_priv: i915 device instance
4626 * This function is used to disable interrupts at runtime, both in the runtime
4627 * pm and the system suspend/resume code.
4629 void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
4631 intel_irq_reset(dev_priv);
4632 dev_priv->runtime_pm.irqs_enabled = false;
4633 intel_synchronize_irq(dev_priv);
4637 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4638 * @dev_priv: i915 device instance
4640 * This function is used to enable interrupts at runtime, both in the runtime
4641 * pm and the system suspend/resume code.
4643 void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
4645 dev_priv->runtime_pm.irqs_enabled = true;
4646 intel_irq_reset(dev_priv);
4647 intel_irq_postinstall(dev_priv);
4650 bool intel_irqs_enabled(struct drm_i915_private *dev_priv)
4652 return dev_priv->runtime_pm.irqs_enabled;
4655 void intel_synchronize_irq(struct drm_i915_private *i915)
4657 synchronize_irq(to_pci_dev(i915->drm.dev)->irq);
4660 void intel_synchronize_hardirq(struct drm_i915_private *i915)
4662 synchronize_hardirq(to_pci_dev(i915->drm.dev)->irq);