1 /* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
4 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31 #include <linux/circ_buf.h>
32 #include <linux/slab.h>
33 #include <linux/sysrq.h>
35 #include <drm/drm_drv.h>
37 #include "display/intel_de.h"
38 #include "display/intel_display_types.h"
39 #include "display/intel_fifo_underrun.h"
40 #include "display/intel_hotplug.h"
41 #include "display/intel_lpe_audio.h"
42 #include "display/intel_psr.h"
44 #include "gt/intel_breadcrumbs.h"
45 #include "gt/intel_gt.h"
46 #include "gt/intel_gt_irq.h"
47 #include "gt/intel_gt_pm_irq.h"
48 #include "gt/intel_rps.h"
52 #include "i915_trace.h"
56 * DOC: interrupt handling
58 * These functions provide the basic support for enabling and disabling the
59 * interrupt handling support. There's a lot more functionality in i915_irq.c
60 * and related files, but that will be described in separate chapters.
64 * Interrupt statistic for PMU. Increments the counter only if the
65 * interrupt originated from the the GPU so interrupts from a device which
66 * shares the interrupt line are not accounted.
68 static inline void pmu_irq_stats(struct drm_i915_private *i915,
71 if (unlikely(res != IRQ_HANDLED))
75 * A clever compiler translates that into INC. A not so clever one
76 * should at least prevent store tearing.
78 WRITE_ONCE(i915->pmu.irq_count, i915->pmu.irq_count + 1);
81 typedef bool (*long_pulse_detect_func)(enum hpd_pin pin, u32 val);
82 typedef u32 (*hotplug_enables_func)(struct drm_i915_private *i915,
85 static const u32 hpd_ilk[HPD_NUM_PINS] = {
86 [HPD_PORT_A] = DE_DP_A_HOTPLUG,
89 static const u32 hpd_ivb[HPD_NUM_PINS] = {
90 [HPD_PORT_A] = DE_DP_A_HOTPLUG_IVB,
93 static const u32 hpd_bdw[HPD_NUM_PINS] = {
94 [HPD_PORT_A] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_A),
97 static const u32 hpd_ibx[HPD_NUM_PINS] = {
98 [HPD_CRT] = SDE_CRT_HOTPLUG,
99 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
100 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
101 [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
102 [HPD_PORT_D] = SDE_PORTD_HOTPLUG,
105 static const u32 hpd_cpt[HPD_NUM_PINS] = {
106 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
107 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
108 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
109 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
110 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT,
113 static const u32 hpd_spt[HPD_NUM_PINS] = {
114 [HPD_PORT_A] = SDE_PORTA_HOTPLUG_SPT,
115 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
116 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
117 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT,
118 [HPD_PORT_E] = SDE_PORTE_HOTPLUG_SPT,
121 static const u32 hpd_mask_i915[HPD_NUM_PINS] = {
122 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
123 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
124 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
125 [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
126 [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
127 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN,
130 static const u32 hpd_status_g4x[HPD_NUM_PINS] = {
131 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
132 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
133 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
134 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
135 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
136 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS,
139 static const u32 hpd_status_i915[HPD_NUM_PINS] = {
140 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
141 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
142 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
143 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
144 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
145 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS,
148 static const u32 hpd_bxt[HPD_NUM_PINS] = {
149 [HPD_PORT_A] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_A),
150 [HPD_PORT_B] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_B),
151 [HPD_PORT_C] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_C),
154 static const u32 hpd_gen11[HPD_NUM_PINS] = {
155 [HPD_PORT_TC1] = GEN11_TC_HOTPLUG(HPD_PORT_TC1) | GEN11_TBT_HOTPLUG(HPD_PORT_TC1),
156 [HPD_PORT_TC2] = GEN11_TC_HOTPLUG(HPD_PORT_TC2) | GEN11_TBT_HOTPLUG(HPD_PORT_TC2),
157 [HPD_PORT_TC3] = GEN11_TC_HOTPLUG(HPD_PORT_TC3) | GEN11_TBT_HOTPLUG(HPD_PORT_TC3),
158 [HPD_PORT_TC4] = GEN11_TC_HOTPLUG(HPD_PORT_TC4) | GEN11_TBT_HOTPLUG(HPD_PORT_TC4),
159 [HPD_PORT_TC5] = GEN11_TC_HOTPLUG(HPD_PORT_TC5) | GEN11_TBT_HOTPLUG(HPD_PORT_TC5),
160 [HPD_PORT_TC6] = GEN11_TC_HOTPLUG(HPD_PORT_TC6) | GEN11_TBT_HOTPLUG(HPD_PORT_TC6),
163 static const u32 hpd_icp[HPD_NUM_PINS] = {
164 [HPD_PORT_A] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_A),
165 [HPD_PORT_B] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_B),
166 [HPD_PORT_C] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_C),
167 [HPD_PORT_TC1] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC1),
168 [HPD_PORT_TC2] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC2),
169 [HPD_PORT_TC3] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC3),
170 [HPD_PORT_TC4] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC4),
171 [HPD_PORT_TC5] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC5),
172 [HPD_PORT_TC6] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC6),
175 static const u32 hpd_sde_dg1[HPD_NUM_PINS] = {
176 [HPD_PORT_A] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_A),
177 [HPD_PORT_B] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_B),
178 [HPD_PORT_C] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_C),
179 [HPD_PORT_D] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_D),
182 static void intel_hpd_init_pins(struct drm_i915_private *dev_priv)
184 struct i915_hotplug *hpd = &dev_priv->hotplug;
186 if (HAS_GMCH(dev_priv)) {
187 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
188 IS_CHERRYVIEW(dev_priv))
189 hpd->hpd = hpd_status_g4x;
191 hpd->hpd = hpd_status_i915;
195 if (DISPLAY_VER(dev_priv) >= 11)
196 hpd->hpd = hpd_gen11;
197 else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
199 else if (DISPLAY_VER(dev_priv) >= 8)
201 else if (DISPLAY_VER(dev_priv) >= 7)
206 if ((INTEL_PCH_TYPE(dev_priv) < PCH_DG1) &&
207 (!HAS_PCH_SPLIT(dev_priv) || HAS_PCH_NOP(dev_priv)))
210 if (INTEL_PCH_TYPE(dev_priv) >= PCH_DG1)
211 hpd->pch_hpd = hpd_sde_dg1;
212 else if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
213 hpd->pch_hpd = hpd_icp;
214 else if (HAS_PCH_CNP(dev_priv) || HAS_PCH_SPT(dev_priv))
215 hpd->pch_hpd = hpd_spt;
216 else if (HAS_PCH_LPT(dev_priv) || HAS_PCH_CPT(dev_priv))
217 hpd->pch_hpd = hpd_cpt;
218 else if (HAS_PCH_IBX(dev_priv))
219 hpd->pch_hpd = hpd_ibx;
221 MISSING_CASE(INTEL_PCH_TYPE(dev_priv));
225 intel_handle_vblank(struct drm_i915_private *dev_priv, enum pipe pipe)
227 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
229 drm_crtc_handle_vblank(&crtc->base);
232 void gen3_irq_reset(struct intel_uncore *uncore, i915_reg_t imr,
233 i915_reg_t iir, i915_reg_t ier)
235 intel_uncore_write(uncore, imr, 0xffffffff);
236 intel_uncore_posting_read(uncore, imr);
238 intel_uncore_write(uncore, ier, 0);
240 /* IIR can theoretically queue up two events. Be paranoid. */
241 intel_uncore_write(uncore, iir, 0xffffffff);
242 intel_uncore_posting_read(uncore, iir);
243 intel_uncore_write(uncore, iir, 0xffffffff);
244 intel_uncore_posting_read(uncore, iir);
247 void gen2_irq_reset(struct intel_uncore *uncore)
249 intel_uncore_write16(uncore, GEN2_IMR, 0xffff);
250 intel_uncore_posting_read16(uncore, GEN2_IMR);
252 intel_uncore_write16(uncore, GEN2_IER, 0);
254 /* IIR can theoretically queue up two events. Be paranoid. */
255 intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
256 intel_uncore_posting_read16(uncore, GEN2_IIR);
257 intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
258 intel_uncore_posting_read16(uncore, GEN2_IIR);
262 * We should clear IMR at preinstall/uninstall, and just check at postinstall.
264 static void gen3_assert_iir_is_zero(struct intel_uncore *uncore, i915_reg_t reg)
266 u32 val = intel_uncore_read(uncore, reg);
271 drm_WARN(&uncore->i915->drm, 1,
272 "Interrupt register 0x%x is not zero: 0x%08x\n",
273 i915_mmio_reg_offset(reg), val);
274 intel_uncore_write(uncore, reg, 0xffffffff);
275 intel_uncore_posting_read(uncore, reg);
276 intel_uncore_write(uncore, reg, 0xffffffff);
277 intel_uncore_posting_read(uncore, reg);
280 static void gen2_assert_iir_is_zero(struct intel_uncore *uncore)
282 u16 val = intel_uncore_read16(uncore, GEN2_IIR);
287 drm_WARN(&uncore->i915->drm, 1,
288 "Interrupt register 0x%x is not zero: 0x%08x\n",
289 i915_mmio_reg_offset(GEN2_IIR), val);
290 intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
291 intel_uncore_posting_read16(uncore, GEN2_IIR);
292 intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
293 intel_uncore_posting_read16(uncore, GEN2_IIR);
296 void gen3_irq_init(struct intel_uncore *uncore,
297 i915_reg_t imr, u32 imr_val,
298 i915_reg_t ier, u32 ier_val,
301 gen3_assert_iir_is_zero(uncore, iir);
303 intel_uncore_write(uncore, ier, ier_val);
304 intel_uncore_write(uncore, imr, imr_val);
305 intel_uncore_posting_read(uncore, imr);
308 void gen2_irq_init(struct intel_uncore *uncore,
309 u32 imr_val, u32 ier_val)
311 gen2_assert_iir_is_zero(uncore);
313 intel_uncore_write16(uncore, GEN2_IER, ier_val);
314 intel_uncore_write16(uncore, GEN2_IMR, imr_val);
315 intel_uncore_posting_read16(uncore, GEN2_IMR);
318 /* For display hotplug interrupt */
320 i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv,
326 lockdep_assert_held(&dev_priv->irq_lock);
327 drm_WARN_ON(&dev_priv->drm, bits & ~mask);
329 val = intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_EN);
332 intel_uncore_write(&dev_priv->uncore, PORT_HOTPLUG_EN, val);
336 * i915_hotplug_interrupt_update - update hotplug interrupt enable
337 * @dev_priv: driver private
338 * @mask: bits to update
339 * @bits: bits to enable
340 * NOTE: the HPD enable bits are modified both inside and outside
341 * of an interrupt context. To avoid that read-modify-write cycles
342 * interfer, these bits are protected by a spinlock. Since this
343 * function is usually not called from a context where the lock is
344 * held already, this function acquires the lock itself. A non-locking
345 * version is also available.
347 void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
351 spin_lock_irq(&dev_priv->irq_lock);
352 i915_hotplug_interrupt_update_locked(dev_priv, mask, bits);
353 spin_unlock_irq(&dev_priv->irq_lock);
357 * ilk_update_display_irq - update DEIMR
358 * @dev_priv: driver private
359 * @interrupt_mask: mask of interrupt bits to update
360 * @enabled_irq_mask: mask of interrupt bits to enable
362 static void ilk_update_display_irq(struct drm_i915_private *dev_priv,
363 u32 interrupt_mask, u32 enabled_irq_mask)
367 lockdep_assert_held(&dev_priv->irq_lock);
368 drm_WARN_ON(&dev_priv->drm, enabled_irq_mask & ~interrupt_mask);
370 new_val = dev_priv->irq_mask;
371 new_val &= ~interrupt_mask;
372 new_val |= (~enabled_irq_mask & interrupt_mask);
374 if (new_val != dev_priv->irq_mask &&
375 !drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv))) {
376 dev_priv->irq_mask = new_val;
377 intel_uncore_write(&dev_priv->uncore, DEIMR, dev_priv->irq_mask);
378 intel_uncore_posting_read(&dev_priv->uncore, DEIMR);
382 void ilk_enable_display_irq(struct drm_i915_private *i915, u32 bits)
384 ilk_update_display_irq(i915, bits, bits);
387 void ilk_disable_display_irq(struct drm_i915_private *i915, u32 bits)
389 ilk_update_display_irq(i915, bits, 0);
393 * bdw_update_port_irq - update DE port interrupt
394 * @dev_priv: driver private
395 * @interrupt_mask: mask of interrupt bits to update
396 * @enabled_irq_mask: mask of interrupt bits to enable
398 static void bdw_update_port_irq(struct drm_i915_private *dev_priv,
400 u32 enabled_irq_mask)
405 lockdep_assert_held(&dev_priv->irq_lock);
407 drm_WARN_ON(&dev_priv->drm, enabled_irq_mask & ~interrupt_mask);
409 if (drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv)))
412 old_val = intel_uncore_read(&dev_priv->uncore, GEN8_DE_PORT_IMR);
415 new_val &= ~interrupt_mask;
416 new_val |= (~enabled_irq_mask & interrupt_mask);
418 if (new_val != old_val) {
419 intel_uncore_write(&dev_priv->uncore, GEN8_DE_PORT_IMR, new_val);
420 intel_uncore_posting_read(&dev_priv->uncore, GEN8_DE_PORT_IMR);
425 * bdw_update_pipe_irq - update DE pipe interrupt
426 * @dev_priv: driver private
427 * @pipe: pipe whose interrupt to update
428 * @interrupt_mask: mask of interrupt bits to update
429 * @enabled_irq_mask: mask of interrupt bits to enable
431 static void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
432 enum pipe pipe, u32 interrupt_mask,
433 u32 enabled_irq_mask)
437 lockdep_assert_held(&dev_priv->irq_lock);
439 drm_WARN_ON(&dev_priv->drm, enabled_irq_mask & ~interrupt_mask);
441 if (drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv)))
444 new_val = dev_priv->de_irq_mask[pipe];
445 new_val &= ~interrupt_mask;
446 new_val |= (~enabled_irq_mask & interrupt_mask);
448 if (new_val != dev_priv->de_irq_mask[pipe]) {
449 dev_priv->de_irq_mask[pipe] = new_val;
450 intel_uncore_write(&dev_priv->uncore, GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
451 intel_uncore_posting_read(&dev_priv->uncore, GEN8_DE_PIPE_IMR(pipe));
455 void bdw_enable_pipe_irq(struct drm_i915_private *i915,
456 enum pipe pipe, u32 bits)
458 bdw_update_pipe_irq(i915, pipe, bits, bits);
461 void bdw_disable_pipe_irq(struct drm_i915_private *i915,
462 enum pipe pipe, u32 bits)
464 bdw_update_pipe_irq(i915, pipe, bits, 0);
468 * ibx_display_interrupt_update - update SDEIMR
469 * @dev_priv: driver private
470 * @interrupt_mask: mask of interrupt bits to update
471 * @enabled_irq_mask: mask of interrupt bits to enable
473 static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
475 u32 enabled_irq_mask)
477 u32 sdeimr = intel_uncore_read(&dev_priv->uncore, SDEIMR);
478 sdeimr &= ~interrupt_mask;
479 sdeimr |= (~enabled_irq_mask & interrupt_mask);
481 drm_WARN_ON(&dev_priv->drm, enabled_irq_mask & ~interrupt_mask);
483 lockdep_assert_held(&dev_priv->irq_lock);
485 if (drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv)))
488 intel_uncore_write(&dev_priv->uncore, SDEIMR, sdeimr);
489 intel_uncore_posting_read(&dev_priv->uncore, SDEIMR);
492 void ibx_enable_display_interrupt(struct drm_i915_private *i915, u32 bits)
494 ibx_display_interrupt_update(i915, bits, bits);
497 void ibx_disable_display_interrupt(struct drm_i915_private *i915, u32 bits)
499 ibx_display_interrupt_update(i915, bits, 0);
502 u32 i915_pipestat_enable_mask(struct drm_i915_private *dev_priv,
505 u32 status_mask = dev_priv->pipestat_irq_mask[pipe];
506 u32 enable_mask = status_mask << 16;
508 lockdep_assert_held(&dev_priv->irq_lock);
510 if (DISPLAY_VER(dev_priv) < 5)
514 * On pipe A we don't support the PSR interrupt yet,
515 * on pipe B and C the same bit MBZ.
517 if (drm_WARN_ON_ONCE(&dev_priv->drm,
518 status_mask & PIPE_A_PSR_STATUS_VLV))
521 * On pipe B and C we don't support the PSR interrupt yet, on pipe
522 * A the same bit is for perf counters which we don't use either.
524 if (drm_WARN_ON_ONCE(&dev_priv->drm,
525 status_mask & PIPE_B_PSR_STATUS_VLV))
528 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
529 SPRITE0_FLIP_DONE_INT_EN_VLV |
530 SPRITE1_FLIP_DONE_INT_EN_VLV);
531 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
532 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
533 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
534 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
537 drm_WARN_ONCE(&dev_priv->drm,
538 enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
539 status_mask & ~PIPESTAT_INT_STATUS_MASK,
540 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
541 pipe_name(pipe), enable_mask, status_mask);
546 void i915_enable_pipestat(struct drm_i915_private *dev_priv,
547 enum pipe pipe, u32 status_mask)
549 i915_reg_t reg = PIPESTAT(pipe);
552 drm_WARN_ONCE(&dev_priv->drm, status_mask & ~PIPESTAT_INT_STATUS_MASK,
553 "pipe %c: status_mask=0x%x\n",
554 pipe_name(pipe), status_mask);
556 lockdep_assert_held(&dev_priv->irq_lock);
557 drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv));
559 if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == status_mask)
562 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
563 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
565 intel_uncore_write(&dev_priv->uncore, reg, enable_mask | status_mask);
566 intel_uncore_posting_read(&dev_priv->uncore, reg);
569 void i915_disable_pipestat(struct drm_i915_private *dev_priv,
570 enum pipe pipe, u32 status_mask)
572 i915_reg_t reg = PIPESTAT(pipe);
575 drm_WARN_ONCE(&dev_priv->drm, status_mask & ~PIPESTAT_INT_STATUS_MASK,
576 "pipe %c: status_mask=0x%x\n",
577 pipe_name(pipe), status_mask);
579 lockdep_assert_held(&dev_priv->irq_lock);
580 drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv));
582 if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == 0)
585 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
586 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
588 intel_uncore_write(&dev_priv->uncore, reg, enable_mask | status_mask);
589 intel_uncore_posting_read(&dev_priv->uncore, reg);
592 static bool i915_has_asle(struct drm_i915_private *dev_priv)
594 if (!dev_priv->opregion.asle)
597 return IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
601 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
602 * @dev_priv: i915 device private
604 static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv)
606 if (!i915_has_asle(dev_priv))
609 spin_lock_irq(&dev_priv->irq_lock);
611 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
612 if (DISPLAY_VER(dev_priv) >= 4)
613 i915_enable_pipestat(dev_priv, PIPE_A,
614 PIPE_LEGACY_BLC_EVENT_STATUS);
616 spin_unlock_irq(&dev_priv->irq_lock);
620 * This timing diagram depicts the video signal in and
621 * around the vertical blanking period.
623 * Assumptions about the fictitious mode used in this example:
625 * vsync_start = vblank_start + 1
626 * vsync_end = vblank_start + 2
627 * vtotal = vblank_start + 3
630 * latch double buffered registers
631 * increment frame counter (ctg+)
632 * generate start of vblank interrupt (gen4+)
635 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
636 * | may be shifted forward 1-3 extra lines via PIPECONF
638 * | | start of vsync:
639 * | | generate vsync interrupt
641 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
642 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
643 * ----va---> <-----------------vb--------------------> <--------va-------------
644 * | | <----vs-----> |
645 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
646 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
647 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
649 * last visible pixel first visible pixel
650 * | increment frame counter (gen3/4)
651 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
653 * x = horizontal active
654 * _ = horizontal blanking
655 * hs = horizontal sync
656 * va = vertical active
657 * vb = vertical blanking
659 * vbs = vblank_start (number)
662 * - most events happen at the start of horizontal sync
663 * - frame start happens at the start of horizontal blank, 1-4 lines
664 * (depending on PIPECONF settings) after the start of vblank
665 * - gen3/4 pixel and frame counter are synchronized with the start
666 * of horizontal active on the first line of vertical active
669 /* Called from drm generic code, passed a 'crtc', which
670 * we use as a pipe index
672 u32 i915_get_vblank_counter(struct drm_crtc *crtc)
674 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
675 struct drm_vblank_crtc *vblank = &dev_priv->drm.vblank[drm_crtc_index(crtc)];
676 const struct drm_display_mode *mode = &vblank->hwmode;
677 enum pipe pipe = to_intel_crtc(crtc)->pipe;
678 i915_reg_t high_frame, low_frame;
679 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
680 unsigned long irqflags;
683 * On i965gm TV output the frame counter only works up to
684 * the point when we enable the TV encoder. After that the
685 * frame counter ceases to work and reads zero. We need a
686 * vblank wait before enabling the TV encoder and so we
687 * have to enable vblank interrupts while the frame counter
688 * is still in a working state. However the core vblank code
689 * does not like us returning non-zero frame counter values
690 * when we've told it that we don't have a working frame
691 * counter. Thus we must stop non-zero values leaking out.
693 if (!vblank->max_vblank_count)
696 htotal = mode->crtc_htotal;
697 hsync_start = mode->crtc_hsync_start;
698 vbl_start = mode->crtc_vblank_start;
699 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
700 vbl_start = DIV_ROUND_UP(vbl_start, 2);
702 /* Convert to pixel count */
705 /* Start of vblank event occurs at start of hsync */
706 vbl_start -= htotal - hsync_start;
708 high_frame = PIPEFRAME(pipe);
709 low_frame = PIPEFRAMEPIXEL(pipe);
711 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
714 * High & low register fields aren't synchronized, so make sure
715 * we get a low value that's stable across two reads of the high
719 high1 = intel_de_read_fw(dev_priv, high_frame) & PIPE_FRAME_HIGH_MASK;
720 low = intel_de_read_fw(dev_priv, low_frame);
721 high2 = intel_de_read_fw(dev_priv, high_frame) & PIPE_FRAME_HIGH_MASK;
722 } while (high1 != high2);
724 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
726 high1 >>= PIPE_FRAME_HIGH_SHIFT;
727 pixel = low & PIPE_PIXEL_MASK;
728 low >>= PIPE_FRAME_LOW_SHIFT;
731 * The frame counter increments at beginning of active.
732 * Cook up a vblank counter by also checking the pixel
733 * counter against vblank start.
735 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
738 u32 g4x_get_vblank_counter(struct drm_crtc *crtc)
740 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
741 struct drm_vblank_crtc *vblank = &dev_priv->drm.vblank[drm_crtc_index(crtc)];
742 enum pipe pipe = to_intel_crtc(crtc)->pipe;
744 if (!vblank->max_vblank_count)
747 return intel_uncore_read(&dev_priv->uncore, PIPE_FRMCOUNT_G4X(pipe));
750 static u32 intel_crtc_scanlines_since_frame_timestamp(struct intel_crtc *crtc)
752 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
753 struct drm_vblank_crtc *vblank =
754 &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
755 const struct drm_display_mode *mode = &vblank->hwmode;
756 u32 htotal = mode->crtc_htotal;
757 u32 clock = mode->crtc_clock;
758 u32 scan_prev_time, scan_curr_time, scan_post_time;
761 * To avoid the race condition where we might cross into the
762 * next vblank just between the PIPE_FRMTMSTMP and TIMESTAMP_CTR
763 * reads. We make sure we read PIPE_FRMTMSTMP and TIMESTAMP_CTR
764 * during the same frame.
768 * This field provides read back of the display
769 * pipe frame time stamp. The time stamp value
770 * is sampled at every start of vertical blank.
772 scan_prev_time = intel_de_read_fw(dev_priv,
773 PIPE_FRMTMSTMP(crtc->pipe));
776 * The TIMESTAMP_CTR register has the current
779 scan_curr_time = intel_de_read_fw(dev_priv, IVB_TIMESTAMP_CTR);
781 scan_post_time = intel_de_read_fw(dev_priv,
782 PIPE_FRMTMSTMP(crtc->pipe));
783 } while (scan_post_time != scan_prev_time);
785 return div_u64(mul_u32_u32(scan_curr_time - scan_prev_time,
786 clock), 1000 * htotal);
790 * On certain encoders on certain platforms, pipe
791 * scanline register will not work to get the scanline,
792 * since the timings are driven from the PORT or issues
793 * with scanline register updates.
794 * This function will use Framestamp and current
795 * timestamp registers to calculate the scanline.
797 static u32 __intel_get_crtc_scanline_from_timestamp(struct intel_crtc *crtc)
799 struct drm_vblank_crtc *vblank =
800 &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
801 const struct drm_display_mode *mode = &vblank->hwmode;
802 u32 vblank_start = mode->crtc_vblank_start;
803 u32 vtotal = mode->crtc_vtotal;
806 scanline = intel_crtc_scanlines_since_frame_timestamp(crtc);
807 scanline = min(scanline, vtotal - 1);
808 scanline = (scanline + vblank_start) % vtotal;
814 * intel_de_read_fw(), only for fast reads of display block, no need for
817 static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
819 struct drm_device *dev = crtc->base.dev;
820 struct drm_i915_private *dev_priv = to_i915(dev);
821 const struct drm_display_mode *mode;
822 struct drm_vblank_crtc *vblank;
823 enum pipe pipe = crtc->pipe;
824 int position, vtotal;
829 vblank = &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
830 mode = &vblank->hwmode;
832 if (crtc->mode_flags & I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP)
833 return __intel_get_crtc_scanline_from_timestamp(crtc);
835 vtotal = mode->crtc_vtotal;
836 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
839 if (DISPLAY_VER(dev_priv) == 2)
840 position = intel_de_read_fw(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
842 position = intel_de_read_fw(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
845 * On HSW, the DSL reg (0x70000) appears to return 0 if we
846 * read it just before the start of vblank. So try it again
847 * so we don't accidentally end up spanning a vblank frame
848 * increment, causing the pipe_update_end() code to squak at us.
850 * The nature of this problem means we can't simply check the ISR
851 * bit and return the vblank start value; nor can we use the scanline
852 * debug register in the transcoder as it appears to have the same
853 * problem. We may need to extend this to include other platforms,
854 * but so far testing only shows the problem on HSW.
856 if (HAS_DDI(dev_priv) && !position) {
859 for (i = 0; i < 100; i++) {
861 temp = intel_de_read_fw(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
862 if (temp != position) {
870 * See update_scanline_offset() for the details on the
871 * scanline_offset adjustment.
873 return (position + crtc->scanline_offset) % vtotal;
876 static bool i915_get_crtc_scanoutpos(struct drm_crtc *_crtc,
878 int *vpos, int *hpos,
879 ktime_t *stime, ktime_t *etime,
880 const struct drm_display_mode *mode)
882 struct drm_device *dev = _crtc->dev;
883 struct drm_i915_private *dev_priv = to_i915(dev);
884 struct intel_crtc *crtc = to_intel_crtc(_crtc);
885 enum pipe pipe = crtc->pipe;
887 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
888 unsigned long irqflags;
889 bool use_scanline_counter = DISPLAY_VER(dev_priv) >= 5 ||
890 IS_G4X(dev_priv) || DISPLAY_VER(dev_priv) == 2 ||
891 crtc->mode_flags & I915_MODE_FLAG_USE_SCANLINE_COUNTER;
893 if (drm_WARN_ON(&dev_priv->drm, !mode->crtc_clock)) {
894 drm_dbg(&dev_priv->drm,
895 "trying to get scanoutpos for disabled "
896 "pipe %c\n", pipe_name(pipe));
900 htotal = mode->crtc_htotal;
901 hsync_start = mode->crtc_hsync_start;
902 vtotal = mode->crtc_vtotal;
903 vbl_start = mode->crtc_vblank_start;
904 vbl_end = mode->crtc_vblank_end;
906 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
907 vbl_start = DIV_ROUND_UP(vbl_start, 2);
913 * Lock uncore.lock, as we will do multiple timing critical raw
914 * register reads, potentially with preemption disabled, so the
915 * following code must not block on uncore.lock.
917 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
919 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
921 /* Get optional system timestamp before query. */
923 *stime = ktime_get();
925 if (crtc->mode_flags & I915_MODE_FLAG_VRR) {
926 int scanlines = intel_crtc_scanlines_since_frame_timestamp(crtc);
928 position = __intel_get_crtc_scanline(crtc);
931 * Already exiting vblank? If so, shift our position
932 * so it looks like we're already apporaching the full
933 * vblank end. This should make the generated timestamp
934 * more or less match when the active portion will start.
936 if (position >= vbl_start && scanlines < position)
937 position = min(crtc->vmax_vblank_start + scanlines, vtotal - 1);
938 } else if (use_scanline_counter) {
939 /* No obvious pixelcount register. Only query vertical
940 * scanout position from Display scan line register.
942 position = __intel_get_crtc_scanline(crtc);
944 /* Have access to pixelcount since start of frame.
945 * We can split this into vertical and horizontal
948 position = (intel_de_read_fw(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
950 /* convert to pixel counts */
956 * In interlaced modes, the pixel counter counts all pixels,
957 * so one field will have htotal more pixels. In order to avoid
958 * the reported position from jumping backwards when the pixel
959 * counter is beyond the length of the shorter field, just
960 * clamp the position the length of the shorter field. This
961 * matches how the scanline counter based position works since
962 * the scanline counter doesn't count the two half lines.
964 if (position >= vtotal)
965 position = vtotal - 1;
968 * Start of vblank interrupt is triggered at start of hsync,
969 * just prior to the first active line of vblank. However we
970 * consider lines to start at the leading edge of horizontal
971 * active. So, should we get here before we've crossed into
972 * the horizontal active of the first line in vblank, we would
973 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
974 * always add htotal-hsync_start to the current pixel position.
976 position = (position + htotal - hsync_start) % vtotal;
979 /* Get optional system timestamp after query. */
981 *etime = ktime_get();
983 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
985 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
988 * While in vblank, position will be negative
989 * counting up towards 0 at vbl_end. And outside
990 * vblank, position will be positive counting
993 if (position >= vbl_start)
996 position += vtotal - vbl_end;
998 if (use_scanline_counter) {
1002 *vpos = position / htotal;
1003 *hpos = position - (*vpos * htotal);
1009 bool intel_crtc_get_vblank_timestamp(struct drm_crtc *crtc, int *max_error,
1010 ktime_t *vblank_time, bool in_vblank_irq)
1012 return drm_crtc_vblank_helper_get_vblank_timestamp_internal(
1013 crtc, max_error, vblank_time, in_vblank_irq,
1014 i915_get_crtc_scanoutpos);
1017 int intel_get_crtc_scanline(struct intel_crtc *crtc)
1019 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1020 unsigned long irqflags;
1023 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1024 position = __intel_get_crtc_scanline(crtc);
1025 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1031 * ivb_parity_work - Workqueue called when a parity error interrupt
1033 * @work: workqueue struct
1035 * Doesn't actually do anything except notify userspace. As a consequence of
1036 * this event, userspace should try to remap the bad rows since statistically
1037 * it is likely the same row is more likely to go bad again.
1039 static void ivb_parity_work(struct work_struct *work)
1041 struct drm_i915_private *dev_priv =
1042 container_of(work, typeof(*dev_priv), l3_parity.error_work);
1043 struct intel_gt *gt = &dev_priv->gt;
1044 u32 error_status, row, bank, subbank;
1045 char *parity_event[6];
1049 /* We must turn off DOP level clock gating to access the L3 registers.
1050 * In order to prevent a get/put style interface, acquire struct mutex
1051 * any time we access those registers.
1053 mutex_lock(&dev_priv->drm.struct_mutex);
1055 /* If we've screwed up tracking, just let the interrupt fire again */
1056 if (drm_WARN_ON(&dev_priv->drm, !dev_priv->l3_parity.which_slice))
1059 misccpctl = intel_uncore_read(&dev_priv->uncore, GEN7_MISCCPCTL);
1060 intel_uncore_write(&dev_priv->uncore, GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1061 intel_uncore_posting_read(&dev_priv->uncore, GEN7_MISCCPCTL);
1063 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1067 if (drm_WARN_ON_ONCE(&dev_priv->drm,
1068 slice >= NUM_L3_SLICES(dev_priv)))
1071 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1073 reg = GEN7_L3CDERRST1(slice);
1075 error_status = intel_uncore_read(&dev_priv->uncore, reg);
1076 row = GEN7_PARITY_ERROR_ROW(error_status);
1077 bank = GEN7_PARITY_ERROR_BANK(error_status);
1078 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1080 intel_uncore_write(&dev_priv->uncore, reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1081 intel_uncore_posting_read(&dev_priv->uncore, reg);
1083 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1084 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1085 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1086 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1087 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1088 parity_event[5] = NULL;
1090 kobject_uevent_env(&dev_priv->drm.primary->kdev->kobj,
1091 KOBJ_CHANGE, parity_event);
1093 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1094 slice, row, bank, subbank);
1096 kfree(parity_event[4]);
1097 kfree(parity_event[3]);
1098 kfree(parity_event[2]);
1099 kfree(parity_event[1]);
1102 intel_uncore_write(&dev_priv->uncore, GEN7_MISCCPCTL, misccpctl);
1105 drm_WARN_ON(&dev_priv->drm, dev_priv->l3_parity.which_slice);
1106 spin_lock_irq(>->irq_lock);
1107 gen5_gt_enable_irq(gt, GT_PARITY_ERROR(dev_priv));
1108 spin_unlock_irq(>->irq_lock);
1110 mutex_unlock(&dev_priv->drm.struct_mutex);
1113 static bool gen11_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
1122 return val & GEN11_HOTPLUG_CTL_LONG_DETECT(pin);
1128 static bool bxt_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
1132 return val & PORTA_HOTPLUG_LONG_DETECT;
1134 return val & PORTB_HOTPLUG_LONG_DETECT;
1136 return val & PORTC_HOTPLUG_LONG_DETECT;
1142 static bool icp_ddi_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
1149 return val & SHOTPLUG_CTL_DDI_HPD_LONG_DETECT(pin);
1155 static bool icp_tc_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
1164 return val & ICP_TC_HPD_LONG_DETECT(pin);
1170 static bool spt_port_hotplug2_long_detect(enum hpd_pin pin, u32 val)
1174 return val & PORTE_HOTPLUG_LONG_DETECT;
1180 static bool spt_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
1184 return val & PORTA_HOTPLUG_LONG_DETECT;
1186 return val & PORTB_HOTPLUG_LONG_DETECT;
1188 return val & PORTC_HOTPLUG_LONG_DETECT;
1190 return val & PORTD_HOTPLUG_LONG_DETECT;
1196 static bool ilk_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
1200 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
1206 static bool pch_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
1210 return val & PORTB_HOTPLUG_LONG_DETECT;
1212 return val & PORTC_HOTPLUG_LONG_DETECT;
1214 return val & PORTD_HOTPLUG_LONG_DETECT;
1220 static bool i9xx_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
1224 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
1226 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
1228 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
1235 * Get a bit mask of pins that have triggered, and which ones may be long.
1236 * This can be called multiple times with the same masks to accumulate
1237 * hotplug detection results from several registers.
1239 * Note that the caller is expected to zero out the masks initially.
1241 static void intel_get_hpd_pins(struct drm_i915_private *dev_priv,
1242 u32 *pin_mask, u32 *long_mask,
1243 u32 hotplug_trigger, u32 dig_hotplug_reg,
1244 const u32 hpd[HPD_NUM_PINS],
1245 bool long_pulse_detect(enum hpd_pin pin, u32 val))
1249 BUILD_BUG_ON(BITS_PER_TYPE(*pin_mask) < HPD_NUM_PINS);
1251 for_each_hpd_pin(pin) {
1252 if ((hpd[pin] & hotplug_trigger) == 0)
1255 *pin_mask |= BIT(pin);
1257 if (long_pulse_detect(pin, dig_hotplug_reg))
1258 *long_mask |= BIT(pin);
1261 drm_dbg(&dev_priv->drm,
1262 "hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x, long 0x%08x\n",
1263 hotplug_trigger, dig_hotplug_reg, *pin_mask, *long_mask);
1267 static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
1268 const u32 hpd[HPD_NUM_PINS])
1270 struct intel_encoder *encoder;
1271 u32 enabled_irqs = 0;
1273 for_each_intel_encoder(&dev_priv->drm, encoder)
1274 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
1275 enabled_irqs |= hpd[encoder->hpd_pin];
1277 return enabled_irqs;
1280 static u32 intel_hpd_hotplug_irqs(struct drm_i915_private *dev_priv,
1281 const u32 hpd[HPD_NUM_PINS])
1283 struct intel_encoder *encoder;
1284 u32 hotplug_irqs = 0;
1286 for_each_intel_encoder(&dev_priv->drm, encoder)
1287 hotplug_irqs |= hpd[encoder->hpd_pin];
1289 return hotplug_irqs;
1292 static u32 intel_hpd_hotplug_enables(struct drm_i915_private *i915,
1293 hotplug_enables_func hotplug_enables)
1295 struct intel_encoder *encoder;
1298 for_each_intel_encoder(&i915->drm, encoder)
1299 hotplug |= hotplug_enables(i915, encoder->hpd_pin);
1304 static void gmbus_irq_handler(struct drm_i915_private *dev_priv)
1306 wake_up_all(&dev_priv->gmbus_wait_queue);
1309 static void dp_aux_irq_handler(struct drm_i915_private *dev_priv)
1311 wake_up_all(&dev_priv->gmbus_wait_queue);
1314 #if defined(CONFIG_DEBUG_FS)
1315 static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1321 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
1322 struct intel_pipe_crc *pipe_crc = &crtc->pipe_crc;
1323 u32 crcs[5] = { crc0, crc1, crc2, crc3, crc4 };
1325 trace_intel_pipe_crc(crtc, crcs);
1327 spin_lock(&pipe_crc->lock);
1329 * For some not yet identified reason, the first CRC is
1330 * bonkers. So let's just wait for the next vblank and read
1331 * out the buggy result.
1333 * On GEN8+ sometimes the second CRC is bonkers as well, so
1334 * don't trust that one either.
1336 if (pipe_crc->skipped <= 0 ||
1337 (DISPLAY_VER(dev_priv) >= 8 && pipe_crc->skipped == 1)) {
1338 pipe_crc->skipped++;
1339 spin_unlock(&pipe_crc->lock);
1342 spin_unlock(&pipe_crc->lock);
1344 drm_crtc_add_crc_entry(&crtc->base, true,
1345 drm_crtc_accurate_vblank_count(&crtc->base),
1350 display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1357 static void flip_done_handler(struct drm_i915_private *i915,
1360 struct intel_crtc *crtc = intel_get_crtc_for_pipe(i915, pipe);
1361 struct drm_crtc_state *crtc_state = crtc->base.state;
1362 struct drm_pending_vblank_event *e = crtc_state->event;
1363 struct drm_device *dev = &i915->drm;
1364 unsigned long irqflags;
1366 spin_lock_irqsave(&dev->event_lock, irqflags);
1368 crtc_state->event = NULL;
1370 drm_crtc_send_vblank_event(&crtc->base, e);
1372 spin_unlock_irqrestore(&dev->event_lock, irqflags);
1375 static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1378 display_pipe_crc_irq_handler(dev_priv, pipe,
1379 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_1_IVB(pipe)),
1383 static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1386 display_pipe_crc_irq_handler(dev_priv, pipe,
1387 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_1_IVB(pipe)),
1388 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_2_IVB(pipe)),
1389 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_3_IVB(pipe)),
1390 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_4_IVB(pipe)),
1391 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_5_IVB(pipe)));
1394 static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1399 if (DISPLAY_VER(dev_priv) >= 3)
1400 res1 = intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_RES1_I915(pipe));
1404 if (DISPLAY_VER(dev_priv) >= 5 || IS_G4X(dev_priv))
1405 res2 = intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_RES2_G4X(pipe));
1409 display_pipe_crc_irq_handler(dev_priv, pipe,
1410 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_RED(pipe)),
1411 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_GREEN(pipe)),
1412 intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_BLUE(pipe)),
1416 static void i9xx_pipestat_irq_reset(struct drm_i915_private *dev_priv)
1420 for_each_pipe(dev_priv, pipe) {
1421 intel_uncore_write(&dev_priv->uncore, PIPESTAT(pipe),
1422 PIPESTAT_INT_STATUS_MASK |
1423 PIPE_FIFO_UNDERRUN_STATUS);
1425 dev_priv->pipestat_irq_mask[pipe] = 0;
1429 static void i9xx_pipestat_irq_ack(struct drm_i915_private *dev_priv,
1430 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1434 spin_lock(&dev_priv->irq_lock);
1436 if (!dev_priv->display_irqs_enabled) {
1437 spin_unlock(&dev_priv->irq_lock);
1441 for_each_pipe(dev_priv, pipe) {
1443 u32 status_mask, enable_mask, iir_bit = 0;
1446 * PIPESTAT bits get signalled even when the interrupt is
1447 * disabled with the mask bits, and some of the status bits do
1448 * not generate interrupts at all (like the underrun bit). Hence
1449 * we need to be careful that we only handle what we want to
1453 /* fifo underruns are filterered in the underrun handler. */
1454 status_mask = PIPE_FIFO_UNDERRUN_STATUS;
1459 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1462 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1465 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1469 status_mask |= dev_priv->pipestat_irq_mask[pipe];
1474 reg = PIPESTAT(pipe);
1475 pipe_stats[pipe] = intel_uncore_read(&dev_priv->uncore, reg) & status_mask;
1476 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
1479 * Clear the PIPE*STAT regs before the IIR
1481 * Toggle the enable bits to make sure we get an
1482 * edge in the ISR pipe event bit if we don't clear
1483 * all the enabled status bits. Otherwise the edge
1484 * triggered IIR on i965/g4x wouldn't notice that
1485 * an interrupt is still pending.
1487 if (pipe_stats[pipe]) {
1488 intel_uncore_write(&dev_priv->uncore, reg, pipe_stats[pipe]);
1489 intel_uncore_write(&dev_priv->uncore, reg, enable_mask);
1492 spin_unlock(&dev_priv->irq_lock);
1495 static void i8xx_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1496 u16 iir, u32 pipe_stats[I915_MAX_PIPES])
1500 for_each_pipe(dev_priv, pipe) {
1501 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1502 intel_handle_vblank(dev_priv, pipe);
1504 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1505 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1507 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1508 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1512 static void i915_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1513 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1515 bool blc_event = false;
1518 for_each_pipe(dev_priv, pipe) {
1519 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1520 intel_handle_vblank(dev_priv, pipe);
1522 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1525 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1526 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1528 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1529 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1532 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1533 intel_opregion_asle_intr(dev_priv);
1536 static void i965_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1537 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1539 bool blc_event = false;
1542 for_each_pipe(dev_priv, pipe) {
1543 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1544 intel_handle_vblank(dev_priv, pipe);
1546 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1549 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1550 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1552 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1553 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1556 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1557 intel_opregion_asle_intr(dev_priv);
1559 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1560 gmbus_irq_handler(dev_priv);
1563 static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1564 u32 pipe_stats[I915_MAX_PIPES])
1568 for_each_pipe(dev_priv, pipe) {
1569 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1570 intel_handle_vblank(dev_priv, pipe);
1572 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV)
1573 flip_done_handler(dev_priv, pipe);
1575 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1576 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1578 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1579 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1582 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1583 gmbus_irq_handler(dev_priv);
1586 static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
1588 u32 hotplug_status = 0, hotplug_status_mask;
1591 if (IS_G4X(dev_priv) ||
1592 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
1593 hotplug_status_mask = HOTPLUG_INT_STATUS_G4X |
1594 DP_AUX_CHANNEL_MASK_INT_STATUS_G4X;
1596 hotplug_status_mask = HOTPLUG_INT_STATUS_I915;
1599 * We absolutely have to clear all the pending interrupt
1600 * bits in PORT_HOTPLUG_STAT. Otherwise the ISR port
1601 * interrupt bit won't have an edge, and the i965/g4x
1602 * edge triggered IIR will not notice that an interrupt
1603 * is still pending. We can't use PORT_HOTPLUG_EN to
1604 * guarantee the edge as the act of toggling the enable
1605 * bits can itself generate a new hotplug interrupt :(
1607 for (i = 0; i < 10; i++) {
1608 u32 tmp = intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT) & hotplug_status_mask;
1611 return hotplug_status;
1613 hotplug_status |= tmp;
1614 intel_uncore_write(&dev_priv->uncore, PORT_HOTPLUG_STAT, hotplug_status);
1617 drm_WARN_ONCE(&dev_priv->drm, 1,
1618 "PORT_HOTPLUG_STAT did not clear (0x%08x)\n",
1619 intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT));
1621 return hotplug_status;
1624 static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv,
1627 u32 pin_mask = 0, long_mask = 0;
1628 u32 hotplug_trigger;
1630 if (IS_G4X(dev_priv) ||
1631 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
1632 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
1634 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
1636 if (hotplug_trigger) {
1637 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1638 hotplug_trigger, hotplug_trigger,
1639 dev_priv->hotplug.hpd,
1640 i9xx_port_hotplug_long_detect);
1642 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
1645 if ((IS_G4X(dev_priv) ||
1646 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
1647 hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
1648 dp_aux_irq_handler(dev_priv);
1651 static irqreturn_t valleyview_irq_handler(int irq, void *arg)
1653 struct drm_i915_private *dev_priv = arg;
1654 irqreturn_t ret = IRQ_NONE;
1656 if (!intel_irqs_enabled(dev_priv))
1659 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1660 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
1663 u32 iir, gt_iir, pm_iir;
1664 u32 pipe_stats[I915_MAX_PIPES] = {};
1665 u32 hotplug_status = 0;
1668 gt_iir = intel_uncore_read(&dev_priv->uncore, GTIIR);
1669 pm_iir = intel_uncore_read(&dev_priv->uncore, GEN6_PMIIR);
1670 iir = intel_uncore_read(&dev_priv->uncore, VLV_IIR);
1672 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1678 * Theory on interrupt generation, based on empirical evidence:
1680 * x = ((VLV_IIR & VLV_IER) ||
1681 * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) &&
1682 * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE)));
1684 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
1685 * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to
1686 * guarantee the CPU interrupt will be raised again even if we
1687 * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR
1688 * bits this time around.
1690 intel_uncore_write(&dev_priv->uncore, VLV_MASTER_IER, 0);
1691 ier = intel_uncore_read(&dev_priv->uncore, VLV_IER);
1692 intel_uncore_write(&dev_priv->uncore, VLV_IER, 0);
1695 intel_uncore_write(&dev_priv->uncore, GTIIR, gt_iir);
1697 intel_uncore_write(&dev_priv->uncore, GEN6_PMIIR, pm_iir);
1699 if (iir & I915_DISPLAY_PORT_INTERRUPT)
1700 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
1702 /* Call regardless, as some status bits might not be
1703 * signalled in iir */
1704 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
1706 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
1707 I915_LPE_PIPE_B_INTERRUPT))
1708 intel_lpe_audio_irq_handler(dev_priv);
1711 * VLV_IIR is single buffered, and reflects the level
1712 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
1715 intel_uncore_write(&dev_priv->uncore, VLV_IIR, iir);
1717 intel_uncore_write(&dev_priv->uncore, VLV_IER, ier);
1718 intel_uncore_write(&dev_priv->uncore, VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
1721 gen6_gt_irq_handler(&dev_priv->gt, gt_iir);
1723 gen6_rps_irq_handler(&dev_priv->gt.rps, pm_iir);
1726 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
1728 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
1731 pmu_irq_stats(dev_priv, ret);
1733 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
1738 static irqreturn_t cherryview_irq_handler(int irq, void *arg)
1740 struct drm_i915_private *dev_priv = arg;
1741 irqreturn_t ret = IRQ_NONE;
1743 if (!intel_irqs_enabled(dev_priv))
1746 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1747 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
1750 u32 master_ctl, iir;
1751 u32 pipe_stats[I915_MAX_PIPES] = {};
1752 u32 hotplug_status = 0;
1755 master_ctl = intel_uncore_read(&dev_priv->uncore, GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
1756 iir = intel_uncore_read(&dev_priv->uncore, VLV_IIR);
1758 if (master_ctl == 0 && iir == 0)
1764 * Theory on interrupt generation, based on empirical evidence:
1766 * x = ((VLV_IIR & VLV_IER) ||
1767 * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) &&
1768 * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL)));
1770 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
1771 * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to
1772 * guarantee the CPU interrupt will be raised again even if we
1773 * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL
1774 * bits this time around.
1776 intel_uncore_write(&dev_priv->uncore, GEN8_MASTER_IRQ, 0);
1777 ier = intel_uncore_read(&dev_priv->uncore, VLV_IER);
1778 intel_uncore_write(&dev_priv->uncore, VLV_IER, 0);
1780 gen8_gt_irq_handler(&dev_priv->gt, master_ctl);
1782 if (iir & I915_DISPLAY_PORT_INTERRUPT)
1783 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
1785 /* Call regardless, as some status bits might not be
1786 * signalled in iir */
1787 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
1789 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
1790 I915_LPE_PIPE_B_INTERRUPT |
1791 I915_LPE_PIPE_C_INTERRUPT))
1792 intel_lpe_audio_irq_handler(dev_priv);
1795 * VLV_IIR is single buffered, and reflects the level
1796 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
1799 intel_uncore_write(&dev_priv->uncore, VLV_IIR, iir);
1801 intel_uncore_write(&dev_priv->uncore, VLV_IER, ier);
1802 intel_uncore_write(&dev_priv->uncore, GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
1805 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
1807 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
1810 pmu_irq_stats(dev_priv, ret);
1812 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
1817 static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv,
1818 u32 hotplug_trigger)
1820 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
1823 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
1824 * unless we touch the hotplug register, even if hotplug_trigger is
1825 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
1828 dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
1829 if (!hotplug_trigger) {
1830 u32 mask = PORTA_HOTPLUG_STATUS_MASK |
1831 PORTD_HOTPLUG_STATUS_MASK |
1832 PORTC_HOTPLUG_STATUS_MASK |
1833 PORTB_HOTPLUG_STATUS_MASK;
1834 dig_hotplug_reg &= ~mask;
1837 intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, dig_hotplug_reg);
1838 if (!hotplug_trigger)
1841 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1842 hotplug_trigger, dig_hotplug_reg,
1843 dev_priv->hotplug.pch_hpd,
1844 pch_port_hotplug_long_detect);
1846 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
1849 static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
1852 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
1854 ibx_hpd_irq_handler(dev_priv, hotplug_trigger);
1856 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1857 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1858 SDE_AUDIO_POWER_SHIFT);
1859 drm_dbg(&dev_priv->drm, "PCH audio power change on port %d\n",
1863 if (pch_iir & SDE_AUX_MASK)
1864 dp_aux_irq_handler(dev_priv);
1866 if (pch_iir & SDE_GMBUS)
1867 gmbus_irq_handler(dev_priv);
1869 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1870 drm_dbg(&dev_priv->drm, "PCH HDCP audio interrupt\n");
1872 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1873 drm_dbg(&dev_priv->drm, "PCH transcoder audio interrupt\n");
1875 if (pch_iir & SDE_POISON)
1876 drm_err(&dev_priv->drm, "PCH poison interrupt\n");
1878 if (pch_iir & SDE_FDI_MASK) {
1879 for_each_pipe(dev_priv, pipe)
1880 drm_dbg(&dev_priv->drm, " pipe %c FDI IIR: 0x%08x\n",
1882 intel_uncore_read(&dev_priv->uncore, FDI_RX_IIR(pipe)));
1885 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1886 drm_dbg(&dev_priv->drm, "PCH transcoder CRC done interrupt\n");
1888 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1889 drm_dbg(&dev_priv->drm,
1890 "PCH transcoder CRC error interrupt\n");
1892 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
1893 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A);
1895 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1896 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B);
1899 static void ivb_err_int_handler(struct drm_i915_private *dev_priv)
1901 u32 err_int = intel_uncore_read(&dev_priv->uncore, GEN7_ERR_INT);
1904 if (err_int & ERR_INT_POISON)
1905 drm_err(&dev_priv->drm, "Poison interrupt\n");
1907 for_each_pipe(dev_priv, pipe) {
1908 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
1909 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1911 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
1912 if (IS_IVYBRIDGE(dev_priv))
1913 ivb_pipe_crc_irq_handler(dev_priv, pipe);
1915 hsw_pipe_crc_irq_handler(dev_priv, pipe);
1919 intel_uncore_write(&dev_priv->uncore, GEN7_ERR_INT, err_int);
1922 static void cpt_serr_int_handler(struct drm_i915_private *dev_priv)
1924 u32 serr_int = intel_uncore_read(&dev_priv->uncore, SERR_INT);
1927 if (serr_int & SERR_INT_POISON)
1928 drm_err(&dev_priv->drm, "PCH poison interrupt\n");
1930 for_each_pipe(dev_priv, pipe)
1931 if (serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pipe))
1932 intel_pch_fifo_underrun_irq_handler(dev_priv, pipe);
1934 intel_uncore_write(&dev_priv->uncore, SERR_INT, serr_int);
1937 static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
1940 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
1942 ibx_hpd_irq_handler(dev_priv, hotplug_trigger);
1944 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1945 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1946 SDE_AUDIO_POWER_SHIFT_CPT);
1947 drm_dbg(&dev_priv->drm, "PCH audio power change on port %c\n",
1951 if (pch_iir & SDE_AUX_MASK_CPT)
1952 dp_aux_irq_handler(dev_priv);
1954 if (pch_iir & SDE_GMBUS_CPT)
1955 gmbus_irq_handler(dev_priv);
1957 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1958 drm_dbg(&dev_priv->drm, "Audio CP request interrupt\n");
1960 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1961 drm_dbg(&dev_priv->drm, "Audio CP change interrupt\n");
1963 if (pch_iir & SDE_FDI_MASK_CPT) {
1964 for_each_pipe(dev_priv, pipe)
1965 drm_dbg(&dev_priv->drm, " pipe %c FDI IIR: 0x%08x\n",
1967 intel_uncore_read(&dev_priv->uncore, FDI_RX_IIR(pipe)));
1970 if (pch_iir & SDE_ERROR_CPT)
1971 cpt_serr_int_handler(dev_priv);
1974 static void icp_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
1976 u32 ddi_hotplug_trigger = pch_iir & SDE_DDI_HOTPLUG_MASK_ICP;
1977 u32 tc_hotplug_trigger = pch_iir & SDE_TC_HOTPLUG_MASK_ICP;
1978 u32 pin_mask = 0, long_mask = 0;
1980 if (ddi_hotplug_trigger) {
1981 u32 dig_hotplug_reg;
1983 dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, SHOTPLUG_CTL_DDI);
1984 intel_uncore_write(&dev_priv->uncore, SHOTPLUG_CTL_DDI, dig_hotplug_reg);
1986 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1987 ddi_hotplug_trigger, dig_hotplug_reg,
1988 dev_priv->hotplug.pch_hpd,
1989 icp_ddi_port_hotplug_long_detect);
1992 if (tc_hotplug_trigger) {
1993 u32 dig_hotplug_reg;
1995 dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, SHOTPLUG_CTL_TC);
1996 intel_uncore_write(&dev_priv->uncore, SHOTPLUG_CTL_TC, dig_hotplug_reg);
1998 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1999 tc_hotplug_trigger, dig_hotplug_reg,
2000 dev_priv->hotplug.pch_hpd,
2001 icp_tc_port_hotplug_long_detect);
2005 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
2007 if (pch_iir & SDE_GMBUS_ICP)
2008 gmbus_irq_handler(dev_priv);
2011 static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
2013 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
2014 ~SDE_PORTE_HOTPLUG_SPT;
2015 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
2016 u32 pin_mask = 0, long_mask = 0;
2018 if (hotplug_trigger) {
2019 u32 dig_hotplug_reg;
2021 dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
2022 intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, dig_hotplug_reg);
2024 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2025 hotplug_trigger, dig_hotplug_reg,
2026 dev_priv->hotplug.pch_hpd,
2027 spt_port_hotplug_long_detect);
2030 if (hotplug2_trigger) {
2031 u32 dig_hotplug_reg;
2033 dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG2);
2034 intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG2, dig_hotplug_reg);
2036 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2037 hotplug2_trigger, dig_hotplug_reg,
2038 dev_priv->hotplug.pch_hpd,
2039 spt_port_hotplug2_long_detect);
2043 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
2045 if (pch_iir & SDE_GMBUS_CPT)
2046 gmbus_irq_handler(dev_priv);
2049 static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv,
2050 u32 hotplug_trigger)
2052 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2054 dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, DIGITAL_PORT_HOTPLUG_CNTRL);
2055 intel_uncore_write(&dev_priv->uncore, DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
2057 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2058 hotplug_trigger, dig_hotplug_reg,
2059 dev_priv->hotplug.hpd,
2060 ilk_port_hotplug_long_detect);
2062 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
2065 static void ilk_display_irq_handler(struct drm_i915_private *dev_priv,
2069 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
2071 if (hotplug_trigger)
2072 ilk_hpd_irq_handler(dev_priv, hotplug_trigger);
2074 if (de_iir & DE_AUX_CHANNEL_A)
2075 dp_aux_irq_handler(dev_priv);
2077 if (de_iir & DE_GSE)
2078 intel_opregion_asle_intr(dev_priv);
2080 if (de_iir & DE_POISON)
2081 drm_err(&dev_priv->drm, "Poison interrupt\n");
2083 for_each_pipe(dev_priv, pipe) {
2084 if (de_iir & DE_PIPE_VBLANK(pipe))
2085 intel_handle_vblank(dev_priv, pipe);
2087 if (de_iir & DE_PLANE_FLIP_DONE(pipe))
2088 flip_done_handler(dev_priv, pipe);
2090 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
2091 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2093 if (de_iir & DE_PIPE_CRC_DONE(pipe))
2094 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
2097 /* check event from PCH */
2098 if (de_iir & DE_PCH_EVENT) {
2099 u32 pch_iir = intel_uncore_read(&dev_priv->uncore, SDEIIR);
2101 if (HAS_PCH_CPT(dev_priv))
2102 cpt_irq_handler(dev_priv, pch_iir);
2104 ibx_irq_handler(dev_priv, pch_iir);
2106 /* should clear PCH hotplug event before clear CPU irq */
2107 intel_uncore_write(&dev_priv->uncore, SDEIIR, pch_iir);
2110 if (DISPLAY_VER(dev_priv) == 5 && de_iir & DE_PCU_EVENT)
2111 gen5_rps_irq_handler(&dev_priv->gt.rps);
2114 static void ivb_display_irq_handler(struct drm_i915_private *dev_priv,
2118 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
2120 if (hotplug_trigger)
2121 ilk_hpd_irq_handler(dev_priv, hotplug_trigger);
2123 if (de_iir & DE_ERR_INT_IVB)
2124 ivb_err_int_handler(dev_priv);
2126 if (de_iir & DE_AUX_CHANNEL_A_IVB)
2127 dp_aux_irq_handler(dev_priv);
2129 if (de_iir & DE_GSE_IVB)
2130 intel_opregion_asle_intr(dev_priv);
2132 for_each_pipe(dev_priv, pipe) {
2133 if (de_iir & DE_PIPE_VBLANK_IVB(pipe))
2134 intel_handle_vblank(dev_priv, pipe);
2136 if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe))
2137 flip_done_handler(dev_priv, pipe);
2140 /* check event from PCH */
2141 if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) {
2142 u32 pch_iir = intel_uncore_read(&dev_priv->uncore, SDEIIR);
2144 cpt_irq_handler(dev_priv, pch_iir);
2146 /* clear PCH hotplug event before clear CPU irq */
2147 intel_uncore_write(&dev_priv->uncore, SDEIIR, pch_iir);
2152 * To handle irqs with the minimum potential races with fresh interrupts, we:
2153 * 1 - Disable Master Interrupt Control.
2154 * 2 - Find the source(s) of the interrupt.
2155 * 3 - Clear the Interrupt Identity bits (IIR).
2156 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2157 * 5 - Re-enable Master Interrupt Control.
2159 static irqreturn_t ilk_irq_handler(int irq, void *arg)
2161 struct drm_i915_private *i915 = arg;
2162 void __iomem * const regs = i915->uncore.regs;
2163 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
2164 irqreturn_t ret = IRQ_NONE;
2166 if (unlikely(!intel_irqs_enabled(i915)))
2169 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2170 disable_rpm_wakeref_asserts(&i915->runtime_pm);
2172 /* disable master interrupt before clearing iir */
2173 de_ier = raw_reg_read(regs, DEIER);
2174 raw_reg_write(regs, DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
2176 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2177 * interrupts will will be stored on its back queue, and then we'll be
2178 * able to process them after we restore SDEIER (as soon as we restore
2179 * it, we'll get an interrupt if SDEIIR still has something to process
2180 * due to its back queue). */
2181 if (!HAS_PCH_NOP(i915)) {
2182 sde_ier = raw_reg_read(regs, SDEIER);
2183 raw_reg_write(regs, SDEIER, 0);
2186 /* Find, clear, then process each source of interrupt */
2188 gt_iir = raw_reg_read(regs, GTIIR);
2190 raw_reg_write(regs, GTIIR, gt_iir);
2191 if (GRAPHICS_VER(i915) >= 6)
2192 gen6_gt_irq_handler(&i915->gt, gt_iir);
2194 gen5_gt_irq_handler(&i915->gt, gt_iir);
2198 de_iir = raw_reg_read(regs, DEIIR);
2200 raw_reg_write(regs, DEIIR, de_iir);
2201 if (DISPLAY_VER(i915) >= 7)
2202 ivb_display_irq_handler(i915, de_iir);
2204 ilk_display_irq_handler(i915, de_iir);
2208 if (GRAPHICS_VER(i915) >= 6) {
2209 u32 pm_iir = raw_reg_read(regs, GEN6_PMIIR);
2211 raw_reg_write(regs, GEN6_PMIIR, pm_iir);
2212 gen6_rps_irq_handler(&i915->gt.rps, pm_iir);
2217 raw_reg_write(regs, DEIER, de_ier);
2219 raw_reg_write(regs, SDEIER, sde_ier);
2221 pmu_irq_stats(i915, ret);
2223 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2224 enable_rpm_wakeref_asserts(&i915->runtime_pm);
2229 static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv,
2230 u32 hotplug_trigger)
2232 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2234 dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
2235 intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, dig_hotplug_reg);
2237 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2238 hotplug_trigger, dig_hotplug_reg,
2239 dev_priv->hotplug.hpd,
2240 bxt_port_hotplug_long_detect);
2242 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
2245 static void gen11_hpd_irq_handler(struct drm_i915_private *dev_priv, u32 iir)
2247 u32 pin_mask = 0, long_mask = 0;
2248 u32 trigger_tc = iir & GEN11_DE_TC_HOTPLUG_MASK;
2249 u32 trigger_tbt = iir & GEN11_DE_TBT_HOTPLUG_MASK;
2252 u32 dig_hotplug_reg;
2254 dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, GEN11_TC_HOTPLUG_CTL);
2255 intel_uncore_write(&dev_priv->uncore, GEN11_TC_HOTPLUG_CTL, dig_hotplug_reg);
2257 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2258 trigger_tc, dig_hotplug_reg,
2259 dev_priv->hotplug.hpd,
2260 gen11_port_hotplug_long_detect);
2264 u32 dig_hotplug_reg;
2266 dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, GEN11_TBT_HOTPLUG_CTL);
2267 intel_uncore_write(&dev_priv->uncore, GEN11_TBT_HOTPLUG_CTL, dig_hotplug_reg);
2269 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2270 trigger_tbt, dig_hotplug_reg,
2271 dev_priv->hotplug.hpd,
2272 gen11_port_hotplug_long_detect);
2276 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
2278 drm_err(&dev_priv->drm,
2279 "Unexpected DE HPD interrupt 0x%08x\n", iir);
2282 static u32 gen8_de_port_aux_mask(struct drm_i915_private *dev_priv)
2286 if (DISPLAY_VER(dev_priv) >= 13)
2287 return TGL_DE_PORT_AUX_DDIA |
2288 TGL_DE_PORT_AUX_DDIB |
2289 TGL_DE_PORT_AUX_DDIC |
2290 XELPD_DE_PORT_AUX_DDID |
2291 XELPD_DE_PORT_AUX_DDIE |
2292 TGL_DE_PORT_AUX_USBC1 |
2293 TGL_DE_PORT_AUX_USBC2 |
2294 TGL_DE_PORT_AUX_USBC3 |
2295 TGL_DE_PORT_AUX_USBC4;
2296 else if (DISPLAY_VER(dev_priv) >= 12)
2297 return TGL_DE_PORT_AUX_DDIA |
2298 TGL_DE_PORT_AUX_DDIB |
2299 TGL_DE_PORT_AUX_DDIC |
2300 TGL_DE_PORT_AUX_USBC1 |
2301 TGL_DE_PORT_AUX_USBC2 |
2302 TGL_DE_PORT_AUX_USBC3 |
2303 TGL_DE_PORT_AUX_USBC4 |
2304 TGL_DE_PORT_AUX_USBC5 |
2305 TGL_DE_PORT_AUX_USBC6;
2308 mask = GEN8_AUX_CHANNEL_A;
2309 if (DISPLAY_VER(dev_priv) >= 9)
2310 mask |= GEN9_AUX_CHANNEL_B |
2311 GEN9_AUX_CHANNEL_C |
2314 if (DISPLAY_VER(dev_priv) == 11) {
2315 mask |= ICL_AUX_CHANNEL_F;
2316 mask |= ICL_AUX_CHANNEL_E;
2322 static u32 gen8_de_pipe_fault_mask(struct drm_i915_private *dev_priv)
2324 if (DISPLAY_VER(dev_priv) >= 13 || HAS_D12_PLANE_MINIMIZATION(dev_priv))
2325 return RKL_DE_PIPE_IRQ_FAULT_ERRORS;
2326 else if (DISPLAY_VER(dev_priv) >= 11)
2327 return GEN11_DE_PIPE_IRQ_FAULT_ERRORS;
2328 else if (DISPLAY_VER(dev_priv) >= 9)
2329 return GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2331 return GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2335 gen8_de_misc_irq_handler(struct drm_i915_private *dev_priv, u32 iir)
2339 if (iir & GEN8_DE_MISC_GSE) {
2340 intel_opregion_asle_intr(dev_priv);
2344 if (iir & GEN8_DE_EDP_PSR) {
2345 struct intel_encoder *encoder;
2349 for_each_intel_encoder_with_psr(&dev_priv->drm, encoder) {
2350 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2352 if (DISPLAY_VER(dev_priv) >= 12)
2353 iir_reg = TRANS_PSR_IIR(intel_dp->psr.transcoder);
2355 iir_reg = EDP_PSR_IIR;
2357 psr_iir = intel_uncore_read(&dev_priv->uncore, iir_reg);
2358 intel_uncore_write(&dev_priv->uncore, iir_reg, psr_iir);
2363 intel_psr_irq_handler(intel_dp, psr_iir);
2365 /* prior GEN12 only have one EDP PSR */
2366 if (DISPLAY_VER(dev_priv) < 12)
2372 drm_err(&dev_priv->drm, "Unexpected DE Misc interrupt\n");
2375 static void gen11_dsi_te_interrupt_handler(struct drm_i915_private *dev_priv,
2378 enum pipe pipe = INVALID_PIPE;
2379 enum transcoder dsi_trans;
2384 * Incase of dual link, TE comes from DSI_1
2385 * this is to check if dual link is enabled
2387 val = intel_uncore_read(&dev_priv->uncore, TRANS_DDI_FUNC_CTL2(TRANSCODER_DSI_0));
2388 val &= PORT_SYNC_MODE_ENABLE;
2391 * if dual link is enabled, then read DSI_0
2392 * transcoder registers
2394 port = ((te_trigger & DSI1_TE && val) || (te_trigger & DSI0_TE)) ?
2396 dsi_trans = (port == PORT_A) ? TRANSCODER_DSI_0 : TRANSCODER_DSI_1;
2398 /* Check if DSI configured in command mode */
2399 val = intel_uncore_read(&dev_priv->uncore, DSI_TRANS_FUNC_CONF(dsi_trans));
2400 val = val & OP_MODE_MASK;
2402 if (val != CMD_MODE_NO_GATE && val != CMD_MODE_TE_GATE) {
2403 drm_err(&dev_priv->drm, "DSI trancoder not configured in command mode\n");
2407 /* Get PIPE for handling VBLANK event */
2408 val = intel_uncore_read(&dev_priv->uncore, TRANS_DDI_FUNC_CTL(dsi_trans));
2409 switch (val & TRANS_DDI_EDP_INPUT_MASK) {
2410 case TRANS_DDI_EDP_INPUT_A_ON:
2413 case TRANS_DDI_EDP_INPUT_B_ONOFF:
2416 case TRANS_DDI_EDP_INPUT_C_ONOFF:
2420 drm_err(&dev_priv->drm, "Invalid PIPE\n");
2424 intel_handle_vblank(dev_priv, pipe);
2426 /* clear TE in dsi IIR */
2427 port = (te_trigger & DSI1_TE) ? PORT_B : PORT_A;
2428 tmp = intel_uncore_read(&dev_priv->uncore, DSI_INTR_IDENT_REG(port));
2429 intel_uncore_write(&dev_priv->uncore, DSI_INTR_IDENT_REG(port), tmp);
2432 static u32 gen8_de_pipe_flip_done_mask(struct drm_i915_private *i915)
2434 if (DISPLAY_VER(i915) >= 9)
2435 return GEN9_PIPE_PLANE1_FLIP_DONE;
2437 return GEN8_PIPE_PRIMARY_FLIP_DONE;
2440 u32 gen8_de_pipe_underrun_mask(struct drm_i915_private *dev_priv)
2442 u32 mask = GEN8_PIPE_FIFO_UNDERRUN;
2444 if (DISPLAY_VER(dev_priv) >= 13)
2445 mask |= XELPD_PIPE_SOFT_UNDERRUN |
2446 XELPD_PIPE_HARD_UNDERRUN;
2452 gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl)
2454 irqreturn_t ret = IRQ_NONE;
2458 drm_WARN_ON_ONCE(&dev_priv->drm, !HAS_DISPLAY(dev_priv));
2460 if (master_ctl & GEN8_DE_MISC_IRQ) {
2461 iir = intel_uncore_read(&dev_priv->uncore, GEN8_DE_MISC_IIR);
2463 intel_uncore_write(&dev_priv->uncore, GEN8_DE_MISC_IIR, iir);
2465 gen8_de_misc_irq_handler(dev_priv, iir);
2467 drm_err(&dev_priv->drm,
2468 "The master control interrupt lied (DE MISC)!\n");
2472 if (DISPLAY_VER(dev_priv) >= 11 && (master_ctl & GEN11_DE_HPD_IRQ)) {
2473 iir = intel_uncore_read(&dev_priv->uncore, GEN11_DE_HPD_IIR);
2475 intel_uncore_write(&dev_priv->uncore, GEN11_DE_HPD_IIR, iir);
2477 gen11_hpd_irq_handler(dev_priv, iir);
2479 drm_err(&dev_priv->drm,
2480 "The master control interrupt lied, (DE HPD)!\n");
2484 if (master_ctl & GEN8_DE_PORT_IRQ) {
2485 iir = intel_uncore_read(&dev_priv->uncore, GEN8_DE_PORT_IIR);
2489 intel_uncore_write(&dev_priv->uncore, GEN8_DE_PORT_IIR, iir);
2492 if (iir & gen8_de_port_aux_mask(dev_priv)) {
2493 dp_aux_irq_handler(dev_priv);
2497 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
2498 u32 hotplug_trigger = iir & BXT_DE_PORT_HOTPLUG_MASK;
2500 if (hotplug_trigger) {
2501 bxt_hpd_irq_handler(dev_priv, hotplug_trigger);
2504 } else if (IS_BROADWELL(dev_priv)) {
2505 u32 hotplug_trigger = iir & BDW_DE_PORT_HOTPLUG_MASK;
2507 if (hotplug_trigger) {
2508 ilk_hpd_irq_handler(dev_priv, hotplug_trigger);
2513 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
2514 (iir & BXT_DE_PORT_GMBUS)) {
2515 gmbus_irq_handler(dev_priv);
2519 if (DISPLAY_VER(dev_priv) >= 11) {
2520 u32 te_trigger = iir & (DSI0_TE | DSI1_TE);
2523 gen11_dsi_te_interrupt_handler(dev_priv, te_trigger);
2529 drm_err(&dev_priv->drm,
2530 "Unexpected DE Port interrupt\n");
2533 drm_err(&dev_priv->drm,
2534 "The master control interrupt lied (DE PORT)!\n");
2537 for_each_pipe(dev_priv, pipe) {
2540 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2543 iir = intel_uncore_read(&dev_priv->uncore, GEN8_DE_PIPE_IIR(pipe));
2545 drm_err(&dev_priv->drm,
2546 "The master control interrupt lied (DE PIPE)!\n");
2551 intel_uncore_write(&dev_priv->uncore, GEN8_DE_PIPE_IIR(pipe), iir);
2553 if (iir & GEN8_PIPE_VBLANK)
2554 intel_handle_vblank(dev_priv, pipe);
2556 if (iir & gen8_de_pipe_flip_done_mask(dev_priv))
2557 flip_done_handler(dev_priv, pipe);
2559 if (iir & GEN8_PIPE_CDCLK_CRC_DONE)
2560 hsw_pipe_crc_irq_handler(dev_priv, pipe);
2562 if (iir & gen8_de_pipe_underrun_mask(dev_priv))
2563 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2565 fault_errors = iir & gen8_de_pipe_fault_mask(dev_priv);
2567 drm_err(&dev_priv->drm,
2568 "Fault errors on pipe %c: 0x%08x\n",
2573 if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) &&
2574 master_ctl & GEN8_DE_PCH_IRQ) {
2576 * FIXME(BDW): Assume for now that the new interrupt handling
2577 * scheme also closed the SDE interrupt handling race we've seen
2578 * on older pch-split platforms. But this needs testing.
2580 iir = intel_uncore_read(&dev_priv->uncore, SDEIIR);
2582 intel_uncore_write(&dev_priv->uncore, SDEIIR, iir);
2585 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
2586 icp_irq_handler(dev_priv, iir);
2587 else if (INTEL_PCH_TYPE(dev_priv) >= PCH_SPT)
2588 spt_irq_handler(dev_priv, iir);
2590 cpt_irq_handler(dev_priv, iir);
2593 * Like on previous PCH there seems to be something
2594 * fishy going on with forwarding PCH interrupts.
2596 drm_dbg(&dev_priv->drm,
2597 "The master control interrupt lied (SDE)!\n");
2604 static inline u32 gen8_master_intr_disable(void __iomem * const regs)
2606 raw_reg_write(regs, GEN8_MASTER_IRQ, 0);
2609 * Now with master disabled, get a sample of level indications
2610 * for this interrupt. Indications will be cleared on related acks.
2611 * New indications can and will light up during processing,
2612 * and will generate new interrupt after enabling master.
2614 return raw_reg_read(regs, GEN8_MASTER_IRQ);
2617 static inline void gen8_master_intr_enable(void __iomem * const regs)
2619 raw_reg_write(regs, GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2622 static irqreturn_t gen8_irq_handler(int irq, void *arg)
2624 struct drm_i915_private *dev_priv = arg;
2625 void __iomem * const regs = dev_priv->uncore.regs;
2628 if (!intel_irqs_enabled(dev_priv))
2631 master_ctl = gen8_master_intr_disable(regs);
2633 gen8_master_intr_enable(regs);
2637 /* Find, queue (onto bottom-halves), then clear each source */
2638 gen8_gt_irq_handler(&dev_priv->gt, master_ctl);
2640 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2641 if (master_ctl & ~GEN8_GT_IRQS) {
2642 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
2643 gen8_de_irq_handler(dev_priv, master_ctl);
2644 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
2647 gen8_master_intr_enable(regs);
2649 pmu_irq_stats(dev_priv, IRQ_HANDLED);
2655 gen11_gu_misc_irq_ack(struct intel_gt *gt, const u32 master_ctl)
2657 void __iomem * const regs = gt->uncore->regs;
2660 if (!(master_ctl & GEN11_GU_MISC_IRQ))
2663 iir = raw_reg_read(regs, GEN11_GU_MISC_IIR);
2665 raw_reg_write(regs, GEN11_GU_MISC_IIR, iir);
2671 gen11_gu_misc_irq_handler(struct intel_gt *gt, const u32 iir)
2673 if (iir & GEN11_GU_MISC_GSE)
2674 intel_opregion_asle_intr(gt->i915);
2677 static inline u32 gen11_master_intr_disable(void __iomem * const regs)
2679 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, 0);
2682 * Now with master disabled, get a sample of level indications
2683 * for this interrupt. Indications will be cleared on related acks.
2684 * New indications can and will light up during processing,
2685 * and will generate new interrupt after enabling master.
2687 return raw_reg_read(regs, GEN11_GFX_MSTR_IRQ);
2690 static inline void gen11_master_intr_enable(void __iomem * const regs)
2692 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, GEN11_MASTER_IRQ);
2696 gen11_display_irq_handler(struct drm_i915_private *i915)
2698 void __iomem * const regs = i915->uncore.regs;
2699 const u32 disp_ctl = raw_reg_read(regs, GEN11_DISPLAY_INT_CTL);
2701 disable_rpm_wakeref_asserts(&i915->runtime_pm);
2703 * GEN11_DISPLAY_INT_CTL has same format as GEN8_MASTER_IRQ
2704 * for the display related bits.
2706 raw_reg_write(regs, GEN11_DISPLAY_INT_CTL, 0x0);
2707 gen8_de_irq_handler(i915, disp_ctl);
2708 raw_reg_write(regs, GEN11_DISPLAY_INT_CTL,
2709 GEN11_DISPLAY_IRQ_ENABLE);
2711 enable_rpm_wakeref_asserts(&i915->runtime_pm);
2714 static irqreturn_t gen11_irq_handler(int irq, void *arg)
2716 struct drm_i915_private *i915 = arg;
2717 void __iomem * const regs = i915->uncore.regs;
2718 struct intel_gt *gt = &i915->gt;
2722 if (!intel_irqs_enabled(i915))
2725 master_ctl = gen11_master_intr_disable(regs);
2727 gen11_master_intr_enable(regs);
2731 /* Find, queue (onto bottom-halves), then clear each source */
2732 gen11_gt_irq_handler(gt, master_ctl);
2734 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2735 if (master_ctl & GEN11_DISPLAY_IRQ)
2736 gen11_display_irq_handler(i915);
2738 gu_misc_iir = gen11_gu_misc_irq_ack(gt, master_ctl);
2740 gen11_master_intr_enable(regs);
2742 gen11_gu_misc_irq_handler(gt, gu_misc_iir);
2744 pmu_irq_stats(i915, IRQ_HANDLED);
2749 static inline u32 dg1_master_intr_disable(void __iomem * const regs)
2753 /* First disable interrupts */
2754 raw_reg_write(regs, DG1_MSTR_TILE_INTR, 0);
2756 /* Get the indication levels and ack the master unit */
2757 val = raw_reg_read(regs, DG1_MSTR_TILE_INTR);
2761 raw_reg_write(regs, DG1_MSTR_TILE_INTR, val);
2766 static inline void dg1_master_intr_enable(void __iomem * const regs)
2768 raw_reg_write(regs, DG1_MSTR_TILE_INTR, DG1_MSTR_IRQ);
2771 static irqreturn_t dg1_irq_handler(int irq, void *arg)
2773 struct drm_i915_private * const i915 = arg;
2774 struct intel_gt *gt = &i915->gt;
2775 void __iomem * const regs = i915->uncore.regs;
2776 u32 master_tile_ctl, master_ctl;
2779 if (!intel_irqs_enabled(i915))
2782 master_tile_ctl = dg1_master_intr_disable(regs);
2783 if (!master_tile_ctl) {
2784 dg1_master_intr_enable(regs);
2788 /* FIXME: we only support tile 0 for now. */
2789 if (master_tile_ctl & DG1_MSTR_TILE(0)) {
2790 master_ctl = raw_reg_read(regs, GEN11_GFX_MSTR_IRQ);
2791 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, master_ctl);
2793 DRM_ERROR("Tile not supported: 0x%08x\n", master_tile_ctl);
2794 dg1_master_intr_enable(regs);
2798 gen11_gt_irq_handler(gt, master_ctl);
2800 if (master_ctl & GEN11_DISPLAY_IRQ)
2801 gen11_display_irq_handler(i915);
2803 gu_misc_iir = gen11_gu_misc_irq_ack(gt, master_ctl);
2805 dg1_master_intr_enable(regs);
2807 gen11_gu_misc_irq_handler(gt, gu_misc_iir);
2809 pmu_irq_stats(i915, IRQ_HANDLED);
2814 /* Called from drm generic code, passed 'crtc' which
2815 * we use as a pipe index
2817 int i8xx_enable_vblank(struct drm_crtc *crtc)
2819 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2820 enum pipe pipe = to_intel_crtc(crtc)->pipe;
2821 unsigned long irqflags;
2823 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2824 i915_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
2825 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2830 int i915gm_enable_vblank(struct drm_crtc *crtc)
2832 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2835 * Vblank interrupts fail to wake the device up from C2+.
2836 * Disabling render clock gating during C-states avoids
2837 * the problem. There is a small power cost so we do this
2838 * only when vblank interrupts are actually enabled.
2840 if (dev_priv->vblank_enabled++ == 0)
2841 intel_uncore_write(&dev_priv->uncore, SCPD0, _MASKED_BIT_ENABLE(CSTATE_RENDER_CLOCK_GATE_DISABLE));
2843 return i8xx_enable_vblank(crtc);
2846 int i965_enable_vblank(struct drm_crtc *crtc)
2848 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2849 enum pipe pipe = to_intel_crtc(crtc)->pipe;
2850 unsigned long irqflags;
2852 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2853 i915_enable_pipestat(dev_priv, pipe,
2854 PIPE_START_VBLANK_INTERRUPT_STATUS);
2855 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2860 int ilk_enable_vblank(struct drm_crtc *crtc)
2862 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2863 enum pipe pipe = to_intel_crtc(crtc)->pipe;
2864 unsigned long irqflags;
2865 u32 bit = DISPLAY_VER(dev_priv) >= 7 ?
2866 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
2868 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2869 ilk_enable_display_irq(dev_priv, bit);
2870 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2872 /* Even though there is no DMC, frame counter can get stuck when
2873 * PSR is active as no frames are generated.
2875 if (HAS_PSR(dev_priv))
2876 drm_crtc_vblank_restore(crtc);
2881 static bool gen11_dsi_configure_te(struct intel_crtc *intel_crtc,
2884 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
2888 if (!(intel_crtc->mode_flags &
2889 (I915_MODE_FLAG_DSI_USE_TE1 | I915_MODE_FLAG_DSI_USE_TE0)))
2892 /* for dual link cases we consider TE from slave */
2893 if (intel_crtc->mode_flags & I915_MODE_FLAG_DSI_USE_TE1)
2898 tmp = intel_uncore_read(&dev_priv->uncore, DSI_INTR_MASK_REG(port));
2900 tmp &= ~DSI_TE_EVENT;
2902 tmp |= DSI_TE_EVENT;
2904 intel_uncore_write(&dev_priv->uncore, DSI_INTR_MASK_REG(port), tmp);
2906 tmp = intel_uncore_read(&dev_priv->uncore, DSI_INTR_IDENT_REG(port));
2907 intel_uncore_write(&dev_priv->uncore, DSI_INTR_IDENT_REG(port), tmp);
2912 int bdw_enable_vblank(struct drm_crtc *_crtc)
2914 struct intel_crtc *crtc = to_intel_crtc(_crtc);
2915 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2916 enum pipe pipe = crtc->pipe;
2917 unsigned long irqflags;
2919 if (gen11_dsi_configure_te(crtc, true))
2922 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2923 bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
2924 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2926 /* Even if there is no DMC, frame counter can get stuck when
2927 * PSR is active as no frames are generated, so check only for PSR.
2929 if (HAS_PSR(dev_priv))
2930 drm_crtc_vblank_restore(&crtc->base);
2935 /* Called from drm generic code, passed 'crtc' which
2936 * we use as a pipe index
2938 void i8xx_disable_vblank(struct drm_crtc *crtc)
2940 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2941 enum pipe pipe = to_intel_crtc(crtc)->pipe;
2942 unsigned long irqflags;
2944 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2945 i915_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
2946 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2949 void i915gm_disable_vblank(struct drm_crtc *crtc)
2951 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2953 i8xx_disable_vblank(crtc);
2955 if (--dev_priv->vblank_enabled == 0)
2956 intel_uncore_write(&dev_priv->uncore, SCPD0, _MASKED_BIT_DISABLE(CSTATE_RENDER_CLOCK_GATE_DISABLE));
2959 void i965_disable_vblank(struct drm_crtc *crtc)
2961 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2962 enum pipe pipe = to_intel_crtc(crtc)->pipe;
2963 unsigned long irqflags;
2965 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2966 i915_disable_pipestat(dev_priv, pipe,
2967 PIPE_START_VBLANK_INTERRUPT_STATUS);
2968 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2971 void ilk_disable_vblank(struct drm_crtc *crtc)
2973 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2974 enum pipe pipe = to_intel_crtc(crtc)->pipe;
2975 unsigned long irqflags;
2976 u32 bit = DISPLAY_VER(dev_priv) >= 7 ?
2977 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
2979 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2980 ilk_disable_display_irq(dev_priv, bit);
2981 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2984 void bdw_disable_vblank(struct drm_crtc *_crtc)
2986 struct intel_crtc *crtc = to_intel_crtc(_crtc);
2987 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2988 enum pipe pipe = crtc->pipe;
2989 unsigned long irqflags;
2991 if (gen11_dsi_configure_te(crtc, false))
2994 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2995 bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
2996 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2999 static void ibx_irq_reset(struct drm_i915_private *dev_priv)
3001 struct intel_uncore *uncore = &dev_priv->uncore;
3003 if (HAS_PCH_NOP(dev_priv))
3006 GEN3_IRQ_RESET(uncore, SDE);
3008 if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
3009 intel_uncore_write(&dev_priv->uncore, SERR_INT, 0xffffffff);
3012 static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3014 struct intel_uncore *uncore = &dev_priv->uncore;
3016 if (IS_CHERRYVIEW(dev_priv))
3017 intel_uncore_write(uncore, DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3019 intel_uncore_write(uncore, DPINVGTT, DPINVGTT_STATUS_MASK);
3021 i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0);
3022 intel_uncore_write(uncore, PORT_HOTPLUG_STAT, intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT));
3024 i9xx_pipestat_irq_reset(dev_priv);
3026 GEN3_IRQ_RESET(uncore, VLV_);
3027 dev_priv->irq_mask = ~0u;
3030 static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
3032 struct intel_uncore *uncore = &dev_priv->uncore;
3038 pipestat_mask = PIPE_CRC_DONE_INTERRUPT_STATUS;
3040 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3041 for_each_pipe(dev_priv, pipe)
3042 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
3044 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3045 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3046 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3047 I915_LPE_PIPE_A_INTERRUPT |
3048 I915_LPE_PIPE_B_INTERRUPT;
3050 if (IS_CHERRYVIEW(dev_priv))
3051 enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT |
3052 I915_LPE_PIPE_C_INTERRUPT;
3054 drm_WARN_ON(&dev_priv->drm, dev_priv->irq_mask != ~0u);
3056 dev_priv->irq_mask = ~enable_mask;
3058 GEN3_IRQ_INIT(uncore, VLV_, dev_priv->irq_mask, enable_mask);
3063 static void ilk_irq_reset(struct drm_i915_private *dev_priv)
3065 struct intel_uncore *uncore = &dev_priv->uncore;
3067 GEN3_IRQ_RESET(uncore, DE);
3068 dev_priv->irq_mask = ~0u;
3070 if (GRAPHICS_VER(dev_priv) == 7)
3071 intel_uncore_write(uncore, GEN7_ERR_INT, 0xffffffff);
3073 if (IS_HASWELL(dev_priv)) {
3074 intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff);
3075 intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff);
3078 gen5_gt_irq_reset(&dev_priv->gt);
3080 ibx_irq_reset(dev_priv);
3083 static void valleyview_irq_reset(struct drm_i915_private *dev_priv)
3085 intel_uncore_write(&dev_priv->uncore, VLV_MASTER_IER, 0);
3086 intel_uncore_posting_read(&dev_priv->uncore, VLV_MASTER_IER);
3088 gen5_gt_irq_reset(&dev_priv->gt);
3090 spin_lock_irq(&dev_priv->irq_lock);
3091 if (dev_priv->display_irqs_enabled)
3092 vlv_display_irq_reset(dev_priv);
3093 spin_unlock_irq(&dev_priv->irq_lock);
3096 static void gen8_display_irq_reset(struct drm_i915_private *dev_priv)
3098 struct intel_uncore *uncore = &dev_priv->uncore;
3101 if (!HAS_DISPLAY(dev_priv))
3104 intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff);
3105 intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff);
3107 for_each_pipe(dev_priv, pipe)
3108 if (intel_display_power_is_enabled(dev_priv,
3109 POWER_DOMAIN_PIPE(pipe)))
3110 GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe);
3112 GEN3_IRQ_RESET(uncore, GEN8_DE_PORT_);
3113 GEN3_IRQ_RESET(uncore, GEN8_DE_MISC_);
3116 static void gen8_irq_reset(struct drm_i915_private *dev_priv)
3118 struct intel_uncore *uncore = &dev_priv->uncore;
3120 gen8_master_intr_disable(dev_priv->uncore.regs);
3122 gen8_gt_irq_reset(&dev_priv->gt);
3123 gen8_display_irq_reset(dev_priv);
3124 GEN3_IRQ_RESET(uncore, GEN8_PCU_);
3126 if (HAS_PCH_SPLIT(dev_priv))
3127 ibx_irq_reset(dev_priv);
3131 static void gen11_display_irq_reset(struct drm_i915_private *dev_priv)
3133 struct intel_uncore *uncore = &dev_priv->uncore;
3135 u32 trans_mask = BIT(TRANSCODER_A) | BIT(TRANSCODER_B) |
3136 BIT(TRANSCODER_C) | BIT(TRANSCODER_D);
3138 if (!HAS_DISPLAY(dev_priv))
3141 intel_uncore_write(uncore, GEN11_DISPLAY_INT_CTL, 0);
3143 if (DISPLAY_VER(dev_priv) >= 12) {
3144 enum transcoder trans;
3146 for_each_cpu_transcoder_masked(dev_priv, trans, trans_mask) {
3147 enum intel_display_power_domain domain;
3149 domain = POWER_DOMAIN_TRANSCODER(trans);
3150 if (!intel_display_power_is_enabled(dev_priv, domain))
3153 intel_uncore_write(uncore, TRANS_PSR_IMR(trans), 0xffffffff);
3154 intel_uncore_write(uncore, TRANS_PSR_IIR(trans), 0xffffffff);
3157 intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff);
3158 intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff);
3161 for_each_pipe(dev_priv, pipe)
3162 if (intel_display_power_is_enabled(dev_priv,
3163 POWER_DOMAIN_PIPE(pipe)))
3164 GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe);
3166 GEN3_IRQ_RESET(uncore, GEN8_DE_PORT_);
3167 GEN3_IRQ_RESET(uncore, GEN8_DE_MISC_);
3168 GEN3_IRQ_RESET(uncore, GEN11_DE_HPD_);
3170 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
3171 GEN3_IRQ_RESET(uncore, SDE);
3174 static void gen11_irq_reset(struct drm_i915_private *dev_priv)
3176 struct intel_uncore *uncore = &dev_priv->uncore;
3178 gen11_master_intr_disable(dev_priv->uncore.regs);
3180 gen11_gt_irq_reset(&dev_priv->gt);
3181 gen11_display_irq_reset(dev_priv);
3183 GEN3_IRQ_RESET(uncore, GEN11_GU_MISC_);
3184 GEN3_IRQ_RESET(uncore, GEN8_PCU_);
3187 static void dg1_irq_reset(struct drm_i915_private *dev_priv)
3189 struct intel_uncore *uncore = &dev_priv->uncore;
3191 dg1_master_intr_disable(dev_priv->uncore.regs);
3193 gen11_gt_irq_reset(&dev_priv->gt);
3194 gen11_display_irq_reset(dev_priv);
3196 GEN3_IRQ_RESET(uncore, GEN11_GU_MISC_);
3197 GEN3_IRQ_RESET(uncore, GEN8_PCU_);
3200 void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
3203 struct intel_uncore *uncore = &dev_priv->uncore;
3204 u32 extra_ier = GEN8_PIPE_VBLANK |
3205 gen8_de_pipe_underrun_mask(dev_priv) |
3206 gen8_de_pipe_flip_done_mask(dev_priv);
3209 spin_lock_irq(&dev_priv->irq_lock);
3211 if (!intel_irqs_enabled(dev_priv)) {
3212 spin_unlock_irq(&dev_priv->irq_lock);
3216 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3217 GEN8_IRQ_INIT_NDX(uncore, DE_PIPE, pipe,
3218 dev_priv->de_irq_mask[pipe],
3219 ~dev_priv->de_irq_mask[pipe] | extra_ier);
3221 spin_unlock_irq(&dev_priv->irq_lock);
3224 void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv,
3227 struct intel_uncore *uncore = &dev_priv->uncore;
3230 spin_lock_irq(&dev_priv->irq_lock);
3232 if (!intel_irqs_enabled(dev_priv)) {
3233 spin_unlock_irq(&dev_priv->irq_lock);
3237 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3238 GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe);
3240 spin_unlock_irq(&dev_priv->irq_lock);
3242 /* make sure we're done processing display irqs */
3243 intel_synchronize_irq(dev_priv);
3246 static void cherryview_irq_reset(struct drm_i915_private *dev_priv)
3248 struct intel_uncore *uncore = &dev_priv->uncore;
3250 intel_uncore_write(&dev_priv->uncore, GEN8_MASTER_IRQ, 0);
3251 intel_uncore_posting_read(&dev_priv->uncore, GEN8_MASTER_IRQ);
3253 gen8_gt_irq_reset(&dev_priv->gt);
3255 GEN3_IRQ_RESET(uncore, GEN8_PCU_);
3257 spin_lock_irq(&dev_priv->irq_lock);
3258 if (dev_priv->display_irqs_enabled)
3259 vlv_display_irq_reset(dev_priv);
3260 spin_unlock_irq(&dev_priv->irq_lock);
3263 static u32 ibx_hotplug_enables(struct drm_i915_private *i915,
3269 * When CPU and PCH are on the same package, port A
3270 * HPD must be enabled in both north and south.
3272 return HAS_PCH_LPT_LP(i915) ?
3273 PORTA_HOTPLUG_ENABLE : 0;
3275 return PORTB_HOTPLUG_ENABLE |
3276 PORTB_PULSE_DURATION_2ms;
3278 return PORTC_HOTPLUG_ENABLE |
3279 PORTC_PULSE_DURATION_2ms;
3281 return PORTD_HOTPLUG_ENABLE |
3282 PORTD_PULSE_DURATION_2ms;
3288 static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv)
3293 * Enable digital hotplug on the PCH, and configure the DP short pulse
3294 * duration to 2ms (which is the minimum in the Display Port spec).
3295 * The pulse duration bits are reserved on LPT+.
3297 hotplug = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
3298 hotplug &= ~(PORTA_HOTPLUG_ENABLE |
3299 PORTB_HOTPLUG_ENABLE |
3300 PORTC_HOTPLUG_ENABLE |
3301 PORTD_HOTPLUG_ENABLE |
3302 PORTB_PULSE_DURATION_MASK |
3303 PORTC_PULSE_DURATION_MASK |
3304 PORTD_PULSE_DURATION_MASK);
3305 hotplug |= intel_hpd_hotplug_enables(dev_priv, ibx_hotplug_enables);
3306 intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, hotplug);
3309 static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
3311 u32 hotplug_irqs, enabled_irqs;
3313 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->hotplug.pch_hpd);
3314 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->hotplug.pch_hpd);
3316 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3318 ibx_hpd_detection_setup(dev_priv);
3321 static u32 icp_ddi_hotplug_enables(struct drm_i915_private *i915,
3329 return SHOTPLUG_CTL_DDI_HPD_ENABLE(pin);
3335 static u32 icp_tc_hotplug_enables(struct drm_i915_private *i915,
3345 return ICP_TC_HPD_ENABLE(pin);
3351 static void icp_ddi_hpd_detection_setup(struct drm_i915_private *dev_priv)
3355 hotplug = intel_uncore_read(&dev_priv->uncore, SHOTPLUG_CTL_DDI);
3356 hotplug &= ~(SHOTPLUG_CTL_DDI_HPD_ENABLE(HPD_PORT_A) |
3357 SHOTPLUG_CTL_DDI_HPD_ENABLE(HPD_PORT_B) |
3358 SHOTPLUG_CTL_DDI_HPD_ENABLE(HPD_PORT_C) |
3359 SHOTPLUG_CTL_DDI_HPD_ENABLE(HPD_PORT_D));
3360 hotplug |= intel_hpd_hotplug_enables(dev_priv, icp_ddi_hotplug_enables);
3361 intel_uncore_write(&dev_priv->uncore, SHOTPLUG_CTL_DDI, hotplug);
3364 static void icp_tc_hpd_detection_setup(struct drm_i915_private *dev_priv)
3368 hotplug = intel_uncore_read(&dev_priv->uncore, SHOTPLUG_CTL_TC);
3369 hotplug &= ~(ICP_TC_HPD_ENABLE(HPD_PORT_TC1) |
3370 ICP_TC_HPD_ENABLE(HPD_PORT_TC2) |
3371 ICP_TC_HPD_ENABLE(HPD_PORT_TC3) |
3372 ICP_TC_HPD_ENABLE(HPD_PORT_TC4) |
3373 ICP_TC_HPD_ENABLE(HPD_PORT_TC5) |
3374 ICP_TC_HPD_ENABLE(HPD_PORT_TC6));
3375 hotplug |= intel_hpd_hotplug_enables(dev_priv, icp_tc_hotplug_enables);
3376 intel_uncore_write(&dev_priv->uncore, SHOTPLUG_CTL_TC, hotplug);
3379 static void icp_hpd_irq_setup(struct drm_i915_private *dev_priv)
3381 u32 hotplug_irqs, enabled_irqs;
3383 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->hotplug.pch_hpd);
3384 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->hotplug.pch_hpd);
3386 if (INTEL_PCH_TYPE(dev_priv) <= PCH_TGP)
3387 intel_uncore_write(&dev_priv->uncore, SHPD_FILTER_CNT, SHPD_FILTER_CNT_500_ADJ);
3389 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3391 icp_ddi_hpd_detection_setup(dev_priv);
3392 icp_tc_hpd_detection_setup(dev_priv);
3395 static u32 gen11_hotplug_enables(struct drm_i915_private *i915,
3405 return GEN11_HOTPLUG_CTL_ENABLE(pin);
3411 static void dg1_hpd_irq_setup(struct drm_i915_private *dev_priv)
3415 val = intel_uncore_read(&dev_priv->uncore, SOUTH_CHICKEN1);
3416 val |= (INVERT_DDIA_HPD |
3420 intel_uncore_write(&dev_priv->uncore, SOUTH_CHICKEN1, val);
3422 icp_hpd_irq_setup(dev_priv);
3425 static void gen11_tc_hpd_detection_setup(struct drm_i915_private *dev_priv)
3429 hotplug = intel_uncore_read(&dev_priv->uncore, GEN11_TC_HOTPLUG_CTL);
3430 hotplug &= ~(GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC1) |
3431 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC2) |
3432 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC3) |
3433 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC4) |
3434 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC5) |
3435 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC6));
3436 hotplug |= intel_hpd_hotplug_enables(dev_priv, gen11_hotplug_enables);
3437 intel_uncore_write(&dev_priv->uncore, GEN11_TC_HOTPLUG_CTL, hotplug);
3440 static void gen11_tbt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3444 hotplug = intel_uncore_read(&dev_priv->uncore, GEN11_TBT_HOTPLUG_CTL);
3445 hotplug &= ~(GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC1) |
3446 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC2) |
3447 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC3) |
3448 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC4) |
3449 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC5) |
3450 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC6));
3451 hotplug |= intel_hpd_hotplug_enables(dev_priv, gen11_hotplug_enables);
3452 intel_uncore_write(&dev_priv->uncore, GEN11_TBT_HOTPLUG_CTL, hotplug);
3455 static void gen11_hpd_irq_setup(struct drm_i915_private *dev_priv)
3457 u32 hotplug_irqs, enabled_irqs;
3460 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->hotplug.hpd);
3461 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->hotplug.hpd);
3463 val = intel_uncore_read(&dev_priv->uncore, GEN11_DE_HPD_IMR);
3464 val &= ~hotplug_irqs;
3465 val |= ~enabled_irqs & hotplug_irqs;
3466 intel_uncore_write(&dev_priv->uncore, GEN11_DE_HPD_IMR, val);
3467 intel_uncore_posting_read(&dev_priv->uncore, GEN11_DE_HPD_IMR);
3469 gen11_tc_hpd_detection_setup(dev_priv);
3470 gen11_tbt_hpd_detection_setup(dev_priv);
3472 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
3473 icp_hpd_irq_setup(dev_priv);
3476 static u32 spt_hotplug_enables(struct drm_i915_private *i915,
3481 return PORTA_HOTPLUG_ENABLE;
3483 return PORTB_HOTPLUG_ENABLE;
3485 return PORTC_HOTPLUG_ENABLE;
3487 return PORTD_HOTPLUG_ENABLE;
3493 static u32 spt_hotplug2_enables(struct drm_i915_private *i915,
3498 return PORTE_HOTPLUG_ENABLE;
3504 static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3508 /* Display WA #1179 WaHardHangonHotPlug: cnp */
3509 if (HAS_PCH_CNP(dev_priv)) {
3510 val = intel_uncore_read(&dev_priv->uncore, SOUTH_CHICKEN1);
3511 val &= ~CHASSIS_CLK_REQ_DURATION_MASK;
3512 val |= CHASSIS_CLK_REQ_DURATION(0xf);
3513 intel_uncore_write(&dev_priv->uncore, SOUTH_CHICKEN1, val);
3516 /* Enable digital hotplug on the PCH */
3517 hotplug = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
3518 hotplug &= ~(PORTA_HOTPLUG_ENABLE |
3519 PORTB_HOTPLUG_ENABLE |
3520 PORTC_HOTPLUG_ENABLE |
3521 PORTD_HOTPLUG_ENABLE);
3522 hotplug |= intel_hpd_hotplug_enables(dev_priv, spt_hotplug_enables);
3523 intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, hotplug);
3525 hotplug = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG2);
3526 hotplug &= ~PORTE_HOTPLUG_ENABLE;
3527 hotplug |= intel_hpd_hotplug_enables(dev_priv, spt_hotplug2_enables);
3528 intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG2, hotplug);
3531 static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
3533 u32 hotplug_irqs, enabled_irqs;
3535 if (INTEL_PCH_TYPE(dev_priv) >= PCH_CNP)
3536 intel_uncore_write(&dev_priv->uncore, SHPD_FILTER_CNT, SHPD_FILTER_CNT_500_ADJ);
3538 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->hotplug.pch_hpd);
3539 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->hotplug.pch_hpd);
3541 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3543 spt_hpd_detection_setup(dev_priv);
3546 static u32 ilk_hotplug_enables(struct drm_i915_private *i915,
3551 return DIGITAL_PORTA_HOTPLUG_ENABLE |
3552 DIGITAL_PORTA_PULSE_DURATION_2ms;
3558 static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv)
3563 * Enable digital hotplug on the CPU, and configure the DP short pulse
3564 * duration to 2ms (which is the minimum in the Display Port spec)
3565 * The pulse duration bits are reserved on HSW+.
3567 hotplug = intel_uncore_read(&dev_priv->uncore, DIGITAL_PORT_HOTPLUG_CNTRL);
3568 hotplug &= ~(DIGITAL_PORTA_HOTPLUG_ENABLE |
3569 DIGITAL_PORTA_PULSE_DURATION_MASK);
3570 hotplug |= intel_hpd_hotplug_enables(dev_priv, ilk_hotplug_enables);
3571 intel_uncore_write(&dev_priv->uncore, DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
3574 static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
3576 u32 hotplug_irqs, enabled_irqs;
3578 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->hotplug.hpd);
3579 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->hotplug.hpd);
3581 if (DISPLAY_VER(dev_priv) >= 8)
3582 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
3584 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3586 ilk_hpd_detection_setup(dev_priv);
3588 ibx_hpd_irq_setup(dev_priv);
3591 static u32 bxt_hotplug_enables(struct drm_i915_private *i915,
3598 hotplug = PORTA_HOTPLUG_ENABLE;
3599 if (intel_bios_is_port_hpd_inverted(i915, PORT_A))
3600 hotplug |= BXT_DDIA_HPD_INVERT;
3603 hotplug = PORTB_HOTPLUG_ENABLE;
3604 if (intel_bios_is_port_hpd_inverted(i915, PORT_B))
3605 hotplug |= BXT_DDIB_HPD_INVERT;
3608 hotplug = PORTC_HOTPLUG_ENABLE;
3609 if (intel_bios_is_port_hpd_inverted(i915, PORT_C))
3610 hotplug |= BXT_DDIC_HPD_INVERT;
3617 static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3621 hotplug = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
3622 hotplug &= ~(PORTA_HOTPLUG_ENABLE |
3623 PORTB_HOTPLUG_ENABLE |
3624 PORTC_HOTPLUG_ENABLE |
3625 BXT_DDIA_HPD_INVERT |
3626 BXT_DDIB_HPD_INVERT |
3627 BXT_DDIC_HPD_INVERT);
3628 hotplug |= intel_hpd_hotplug_enables(dev_priv, bxt_hotplug_enables);
3629 intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, hotplug);
3632 static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
3634 u32 hotplug_irqs, enabled_irqs;
3636 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->hotplug.hpd);
3637 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->hotplug.hpd);
3639 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
3641 bxt_hpd_detection_setup(dev_priv);
3645 * SDEIER is also touched by the interrupt handler to work around missed PCH
3646 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3647 * instead we unconditionally enable all PCH interrupt sources here, but then
3648 * only unmask them as needed with SDEIMR.
3650 * Note that we currently do this after installing the interrupt handler,
3651 * but before we enable the master interrupt. That should be sufficient
3652 * to avoid races with the irq handler, assuming we have MSI. Shared legacy
3653 * interrupts could still race.
3655 static void ibx_irq_postinstall(struct drm_i915_private *dev_priv)
3657 struct intel_uncore *uncore = &dev_priv->uncore;
3660 if (HAS_PCH_NOP(dev_priv))
3663 if (HAS_PCH_IBX(dev_priv))
3664 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
3665 else if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
3666 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
3668 mask = SDE_GMBUS_CPT;
3670 GEN3_IRQ_INIT(uncore, SDE, ~mask, 0xffffffff);
3673 static void ilk_irq_postinstall(struct drm_i915_private *dev_priv)
3675 struct intel_uncore *uncore = &dev_priv->uncore;
3676 u32 display_mask, extra_mask;
3678 if (GRAPHICS_VER(dev_priv) >= 7) {
3679 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
3680 DE_PCH_EVENT_IVB | DE_AUX_CHANNEL_A_IVB);
3681 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
3682 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
3683 DE_PLANE_FLIP_DONE_IVB(PLANE_C) |
3684 DE_PLANE_FLIP_DONE_IVB(PLANE_B) |
3685 DE_PLANE_FLIP_DONE_IVB(PLANE_A) |
3686 DE_DP_A_HOTPLUG_IVB);
3688 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
3689 DE_AUX_CHANNEL_A | DE_PIPEB_CRC_DONE |
3690 DE_PIPEA_CRC_DONE | DE_POISON);
3691 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK |
3692 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
3693 DE_PLANE_FLIP_DONE(PLANE_A) |
3694 DE_PLANE_FLIP_DONE(PLANE_B) |
3698 if (IS_HASWELL(dev_priv)) {
3699 gen3_assert_iir_is_zero(uncore, EDP_PSR_IIR);
3700 display_mask |= DE_EDP_PSR_INT_HSW;
3703 if (IS_IRONLAKE_M(dev_priv))
3704 extra_mask |= DE_PCU_EVENT;
3706 dev_priv->irq_mask = ~display_mask;
3708 ibx_irq_postinstall(dev_priv);
3710 gen5_gt_irq_postinstall(&dev_priv->gt);
3712 GEN3_IRQ_INIT(uncore, DE, dev_priv->irq_mask,
3713 display_mask | extra_mask);
3716 void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3718 lockdep_assert_held(&dev_priv->irq_lock);
3720 if (dev_priv->display_irqs_enabled)
3723 dev_priv->display_irqs_enabled = true;
3725 if (intel_irqs_enabled(dev_priv)) {
3726 vlv_display_irq_reset(dev_priv);
3727 vlv_display_irq_postinstall(dev_priv);
3731 void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3733 lockdep_assert_held(&dev_priv->irq_lock);
3735 if (!dev_priv->display_irqs_enabled)
3738 dev_priv->display_irqs_enabled = false;
3740 if (intel_irqs_enabled(dev_priv))
3741 vlv_display_irq_reset(dev_priv);
3745 static void valleyview_irq_postinstall(struct drm_i915_private *dev_priv)
3747 gen5_gt_irq_postinstall(&dev_priv->gt);
3749 spin_lock_irq(&dev_priv->irq_lock);
3750 if (dev_priv->display_irqs_enabled)
3751 vlv_display_irq_postinstall(dev_priv);
3752 spin_unlock_irq(&dev_priv->irq_lock);
3754 intel_uncore_write(&dev_priv->uncore, VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
3755 intel_uncore_posting_read(&dev_priv->uncore, VLV_MASTER_IER);
3758 static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3760 struct intel_uncore *uncore = &dev_priv->uncore;
3762 u32 de_pipe_masked = gen8_de_pipe_fault_mask(dev_priv) |
3763 GEN8_PIPE_CDCLK_CRC_DONE;
3764 u32 de_pipe_enables;
3765 u32 de_port_masked = gen8_de_port_aux_mask(dev_priv);
3766 u32 de_port_enables;
3767 u32 de_misc_masked = GEN8_DE_EDP_PSR;
3768 u32 trans_mask = BIT(TRANSCODER_A) | BIT(TRANSCODER_B) |
3769 BIT(TRANSCODER_C) | BIT(TRANSCODER_D);
3772 if (!HAS_DISPLAY(dev_priv))
3775 if (DISPLAY_VER(dev_priv) <= 10)
3776 de_misc_masked |= GEN8_DE_MISC_GSE;
3778 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
3779 de_port_masked |= BXT_DE_PORT_GMBUS;
3781 if (DISPLAY_VER(dev_priv) >= 11) {
3784 if (intel_bios_is_dsi_present(dev_priv, &port))
3785 de_port_masked |= DSI0_TE | DSI1_TE;
3788 de_pipe_enables = de_pipe_masked |
3790 gen8_de_pipe_underrun_mask(dev_priv) |
3791 gen8_de_pipe_flip_done_mask(dev_priv);
3793 de_port_enables = de_port_masked;
3794 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
3795 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
3796 else if (IS_BROADWELL(dev_priv))
3797 de_port_enables |= BDW_DE_PORT_HOTPLUG_MASK;
3799 if (DISPLAY_VER(dev_priv) >= 12) {
3800 enum transcoder trans;
3802 for_each_cpu_transcoder_masked(dev_priv, trans, trans_mask) {
3803 enum intel_display_power_domain domain;
3805 domain = POWER_DOMAIN_TRANSCODER(trans);
3806 if (!intel_display_power_is_enabled(dev_priv, domain))
3809 gen3_assert_iir_is_zero(uncore, TRANS_PSR_IIR(trans));
3812 gen3_assert_iir_is_zero(uncore, EDP_PSR_IIR);
3815 for_each_pipe(dev_priv, pipe) {
3816 dev_priv->de_irq_mask[pipe] = ~de_pipe_masked;
3818 if (intel_display_power_is_enabled(dev_priv,
3819 POWER_DOMAIN_PIPE(pipe)))
3820 GEN8_IRQ_INIT_NDX(uncore, DE_PIPE, pipe,
3821 dev_priv->de_irq_mask[pipe],
3825 GEN3_IRQ_INIT(uncore, GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
3826 GEN3_IRQ_INIT(uncore, GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked);
3828 if (DISPLAY_VER(dev_priv) >= 11) {
3829 u32 de_hpd_masked = 0;
3830 u32 de_hpd_enables = GEN11_DE_TC_HOTPLUG_MASK |
3831 GEN11_DE_TBT_HOTPLUG_MASK;
3833 GEN3_IRQ_INIT(uncore, GEN11_DE_HPD_, ~de_hpd_masked,
3838 static void icp_irq_postinstall(struct drm_i915_private *dev_priv)
3840 struct intel_uncore *uncore = &dev_priv->uncore;
3841 u32 mask = SDE_GMBUS_ICP;
3843 GEN3_IRQ_INIT(uncore, SDE, ~mask, 0xffffffff);
3846 static void gen8_irq_postinstall(struct drm_i915_private *dev_priv)
3848 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
3849 icp_irq_postinstall(dev_priv);
3850 else if (HAS_PCH_SPLIT(dev_priv))
3851 ibx_irq_postinstall(dev_priv);
3853 gen8_gt_irq_postinstall(&dev_priv->gt);
3854 gen8_de_irq_postinstall(dev_priv);
3856 gen8_master_intr_enable(dev_priv->uncore.regs);
3859 static void gen11_de_irq_postinstall(struct drm_i915_private *dev_priv)
3861 if (!HAS_DISPLAY(dev_priv))
3864 gen8_de_irq_postinstall(dev_priv);
3866 intel_uncore_write(&dev_priv->uncore, GEN11_DISPLAY_INT_CTL,
3867 GEN11_DISPLAY_IRQ_ENABLE);
3870 static void gen11_irq_postinstall(struct drm_i915_private *dev_priv)
3872 struct intel_uncore *uncore = &dev_priv->uncore;
3873 u32 gu_misc_masked = GEN11_GU_MISC_GSE;
3875 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
3876 icp_irq_postinstall(dev_priv);
3878 gen11_gt_irq_postinstall(&dev_priv->gt);
3879 gen11_de_irq_postinstall(dev_priv);
3881 GEN3_IRQ_INIT(uncore, GEN11_GU_MISC_, ~gu_misc_masked, gu_misc_masked);
3883 gen11_master_intr_enable(uncore->regs);
3884 intel_uncore_posting_read(&dev_priv->uncore, GEN11_GFX_MSTR_IRQ);
3887 static void dg1_irq_postinstall(struct drm_i915_private *dev_priv)
3889 struct intel_uncore *uncore = &dev_priv->uncore;
3890 u32 gu_misc_masked = GEN11_GU_MISC_GSE;
3892 gen11_gt_irq_postinstall(&dev_priv->gt);
3894 GEN3_IRQ_INIT(uncore, GEN11_GU_MISC_, ~gu_misc_masked, gu_misc_masked);
3896 if (HAS_DISPLAY(dev_priv)) {
3897 icp_irq_postinstall(dev_priv);
3898 gen8_de_irq_postinstall(dev_priv);
3899 intel_uncore_write(&dev_priv->uncore, GEN11_DISPLAY_INT_CTL,
3900 GEN11_DISPLAY_IRQ_ENABLE);
3903 dg1_master_intr_enable(dev_priv->uncore.regs);
3904 intel_uncore_posting_read(&dev_priv->uncore, DG1_MSTR_TILE_INTR);
3907 static void cherryview_irq_postinstall(struct drm_i915_private *dev_priv)
3909 gen8_gt_irq_postinstall(&dev_priv->gt);
3911 spin_lock_irq(&dev_priv->irq_lock);
3912 if (dev_priv->display_irqs_enabled)
3913 vlv_display_irq_postinstall(dev_priv);
3914 spin_unlock_irq(&dev_priv->irq_lock);
3916 intel_uncore_write(&dev_priv->uncore, GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
3917 intel_uncore_posting_read(&dev_priv->uncore, GEN8_MASTER_IRQ);
3920 static void i8xx_irq_reset(struct drm_i915_private *dev_priv)
3922 struct intel_uncore *uncore = &dev_priv->uncore;
3924 i9xx_pipestat_irq_reset(dev_priv);
3926 GEN2_IRQ_RESET(uncore);
3927 dev_priv->irq_mask = ~0u;
3930 static void i8xx_irq_postinstall(struct drm_i915_private *dev_priv)
3932 struct intel_uncore *uncore = &dev_priv->uncore;
3935 intel_uncore_write16(uncore,
3937 ~(I915_ERROR_PAGE_TABLE |
3938 I915_ERROR_MEMORY_REFRESH));
3940 /* Unmask the interrupts that we always want on. */
3941 dev_priv->irq_mask =
3942 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3943 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3944 I915_MASTER_ERROR_INTERRUPT);
3947 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3948 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3949 I915_MASTER_ERROR_INTERRUPT |
3950 I915_USER_INTERRUPT;
3952 GEN2_IRQ_INIT(uncore, dev_priv->irq_mask, enable_mask);
3954 /* Interrupt setup is already guaranteed to be single-threaded, this is
3955 * just to make the assert_spin_locked check happy. */
3956 spin_lock_irq(&dev_priv->irq_lock);
3957 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3958 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
3959 spin_unlock_irq(&dev_priv->irq_lock);
3962 static void i8xx_error_irq_ack(struct drm_i915_private *i915,
3963 u16 *eir, u16 *eir_stuck)
3965 struct intel_uncore *uncore = &i915->uncore;
3968 *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_DEBUG("Master Error: EIR 0x%04x\n", eir);
3998 drm_dbg(&dev_priv->drm, "EIR stuck: 0x%04x, masked\n",
4002 static void i9xx_error_irq_ack(struct drm_i915_private *dev_priv,
4003 u32 *eir, u32 *eir_stuck)
4007 *eir = intel_uncore_read(&dev_priv->uncore, EIR);
4009 intel_uncore_write(&dev_priv->uncore, EIR, *eir);
4011 *eir_stuck = intel_uncore_read(&dev_priv->uncore, EIR);
4012 if (*eir_stuck == 0)
4016 * Toggle all EMR bits to make sure we get an edge
4017 * in the ISR master error bit if we don't clear
4018 * all the EIR bits. Otherwise the edge triggered
4019 * IIR on i965/g4x wouldn't notice that an interrupt
4020 * is still pending. Also some EIR bits can't be
4021 * cleared except by handling the underlying error
4022 * (or by a GPU reset) so we mask any bit that
4025 emr = intel_uncore_read(&dev_priv->uncore, EMR);
4026 intel_uncore_write(&dev_priv->uncore, EMR, 0xffffffff);
4027 intel_uncore_write(&dev_priv->uncore, EMR, emr | *eir_stuck);
4030 static void i9xx_error_irq_handler(struct drm_i915_private *dev_priv,
4031 u32 eir, u32 eir_stuck)
4033 DRM_DEBUG("Master Error, EIR 0x%08x\n", eir);
4036 drm_dbg(&dev_priv->drm, "EIR stuck: 0x%08x, masked\n",
4040 static irqreturn_t i8xx_irq_handler(int irq, void *arg)
4042 struct drm_i915_private *dev_priv = arg;
4043 irqreturn_t ret = IRQ_NONE;
4045 if (!intel_irqs_enabled(dev_priv))
4048 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4049 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
4052 u32 pipe_stats[I915_MAX_PIPES] = {};
4053 u16 eir = 0, eir_stuck = 0;
4056 iir = intel_uncore_read16(&dev_priv->uncore, GEN2_IIR);
4062 /* Call regardless, as some status bits might not be
4063 * signalled in iir */
4064 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
4066 if (iir & I915_MASTER_ERROR_INTERRUPT)
4067 i8xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
4069 intel_uncore_write16(&dev_priv->uncore, GEN2_IIR, iir);
4071 if (iir & I915_USER_INTERRUPT)
4072 intel_engine_cs_irq(dev_priv->gt.engine[RCS0], iir);
4074 if (iir & I915_MASTER_ERROR_INTERRUPT)
4075 i8xx_error_irq_handler(dev_priv, eir, eir_stuck);
4077 i8xx_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4080 pmu_irq_stats(dev_priv, ret);
4082 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
4087 static void i915_irq_reset(struct drm_i915_private *dev_priv)
4089 struct intel_uncore *uncore = &dev_priv->uncore;
4091 if (I915_HAS_HOTPLUG(dev_priv)) {
4092 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
4093 intel_uncore_write(&dev_priv->uncore, PORT_HOTPLUG_STAT, intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT));
4096 i9xx_pipestat_irq_reset(dev_priv);
4098 GEN3_IRQ_RESET(uncore, GEN2_);
4099 dev_priv->irq_mask = ~0u;
4102 static void i915_irq_postinstall(struct drm_i915_private *dev_priv)
4104 struct intel_uncore *uncore = &dev_priv->uncore;
4107 intel_uncore_write(&dev_priv->uncore, EMR, ~(I915_ERROR_PAGE_TABLE |
4108 I915_ERROR_MEMORY_REFRESH));
4110 /* Unmask the interrupts that we always want on. */
4111 dev_priv->irq_mask =
4112 ~(I915_ASLE_INTERRUPT |
4113 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4114 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4115 I915_MASTER_ERROR_INTERRUPT);
4118 I915_ASLE_INTERRUPT |
4119 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4120 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4121 I915_MASTER_ERROR_INTERRUPT |
4122 I915_USER_INTERRUPT;
4124 if (I915_HAS_HOTPLUG(dev_priv)) {
4125 /* Enable in IER... */
4126 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
4127 /* and unmask in IMR */
4128 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
4131 GEN3_IRQ_INIT(uncore, GEN2_, dev_priv->irq_mask, enable_mask);
4133 /* Interrupt setup is already guaranteed to be single-threaded, this is
4134 * just to make the assert_spin_locked check happy. */
4135 spin_lock_irq(&dev_priv->irq_lock);
4136 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4137 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
4138 spin_unlock_irq(&dev_priv->irq_lock);
4140 i915_enable_asle_pipestat(dev_priv);
4143 static irqreturn_t i915_irq_handler(int irq, void *arg)
4145 struct drm_i915_private *dev_priv = arg;
4146 irqreturn_t ret = IRQ_NONE;
4148 if (!intel_irqs_enabled(dev_priv))
4151 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4152 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
4155 u32 pipe_stats[I915_MAX_PIPES] = {};
4156 u32 eir = 0, eir_stuck = 0;
4157 u32 hotplug_status = 0;
4160 iir = intel_uncore_read(&dev_priv->uncore, GEN2_IIR);
4166 if (I915_HAS_HOTPLUG(dev_priv) &&
4167 iir & I915_DISPLAY_PORT_INTERRUPT)
4168 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
4170 /* Call regardless, as some status bits might not be
4171 * signalled in iir */
4172 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
4174 if (iir & I915_MASTER_ERROR_INTERRUPT)
4175 i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
4177 intel_uncore_write(&dev_priv->uncore, GEN2_IIR, iir);
4179 if (iir & I915_USER_INTERRUPT)
4180 intel_engine_cs_irq(dev_priv->gt.engine[RCS0], iir);
4182 if (iir & I915_MASTER_ERROR_INTERRUPT)
4183 i9xx_error_irq_handler(dev_priv, eir, eir_stuck);
4186 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
4188 i915_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4191 pmu_irq_stats(dev_priv, ret);
4193 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
4198 static void i965_irq_reset(struct drm_i915_private *dev_priv)
4200 struct intel_uncore *uncore = &dev_priv->uncore;
4202 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
4203 intel_uncore_write(&dev_priv->uncore, PORT_HOTPLUG_STAT, intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT));
4205 i9xx_pipestat_irq_reset(dev_priv);
4207 GEN3_IRQ_RESET(uncore, GEN2_);
4208 dev_priv->irq_mask = ~0u;
4211 static void i965_irq_postinstall(struct drm_i915_private *dev_priv)
4213 struct intel_uncore *uncore = &dev_priv->uncore;
4218 * Enable some error detection, note the instruction error mask
4219 * bit is reserved, so we leave it masked.
4221 if (IS_G4X(dev_priv)) {
4222 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4223 GM45_ERROR_MEM_PRIV |
4224 GM45_ERROR_CP_PRIV |
4225 I915_ERROR_MEMORY_REFRESH);
4227 error_mask = ~(I915_ERROR_PAGE_TABLE |
4228 I915_ERROR_MEMORY_REFRESH);
4230 intel_uncore_write(&dev_priv->uncore, EMR, error_mask);
4232 /* Unmask the interrupts that we always want on. */
4233 dev_priv->irq_mask =
4234 ~(I915_ASLE_INTERRUPT |
4235 I915_DISPLAY_PORT_INTERRUPT |
4236 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4237 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4238 I915_MASTER_ERROR_INTERRUPT);
4241 I915_ASLE_INTERRUPT |
4242 I915_DISPLAY_PORT_INTERRUPT |
4243 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4244 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4245 I915_MASTER_ERROR_INTERRUPT |
4246 I915_USER_INTERRUPT;
4248 if (IS_G4X(dev_priv))
4249 enable_mask |= I915_BSD_USER_INTERRUPT;
4251 GEN3_IRQ_INIT(uncore, GEN2_, dev_priv->irq_mask, enable_mask);
4253 /* Interrupt setup is already guaranteed to be single-threaded, this is
4254 * just to make the assert_spin_locked check happy. */
4255 spin_lock_irq(&dev_priv->irq_lock);
4256 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4257 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4258 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
4259 spin_unlock_irq(&dev_priv->irq_lock);
4261 i915_enable_asle_pipestat(dev_priv);
4264 static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
4268 lockdep_assert_held(&dev_priv->irq_lock);
4270 /* Note HDMI and DP share hotplug bits */
4271 /* enable bits are the same for all generations */
4272 hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
4273 /* Programming the CRT detection parameters tends
4274 to generate a spurious hotplug event about three
4275 seconds later. So just do it once.
4277 if (IS_G4X(dev_priv))
4278 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
4279 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
4281 /* Ignore TV since it's buggy */
4282 i915_hotplug_interrupt_update_locked(dev_priv,
4283 HOTPLUG_INT_EN_MASK |
4284 CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
4285 CRT_HOTPLUG_ACTIVATION_PERIOD_64,
4289 static irqreturn_t i965_irq_handler(int irq, void *arg)
4291 struct drm_i915_private *dev_priv = arg;
4292 irqreturn_t ret = IRQ_NONE;
4294 if (!intel_irqs_enabled(dev_priv))
4297 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4298 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
4301 u32 pipe_stats[I915_MAX_PIPES] = {};
4302 u32 eir = 0, eir_stuck = 0;
4303 u32 hotplug_status = 0;
4306 iir = intel_uncore_read(&dev_priv->uncore, GEN2_IIR);
4312 if (iir & I915_DISPLAY_PORT_INTERRUPT)
4313 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
4315 /* Call regardless, as some status bits might not be
4316 * signalled in iir */
4317 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
4319 if (iir & I915_MASTER_ERROR_INTERRUPT)
4320 i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
4322 intel_uncore_write(&dev_priv->uncore, GEN2_IIR, iir);
4324 if (iir & I915_USER_INTERRUPT)
4325 intel_engine_cs_irq(dev_priv->gt.engine[RCS0],
4328 if (iir & I915_BSD_USER_INTERRUPT)
4329 intel_engine_cs_irq(dev_priv->gt.engine[VCS0],
4332 if (iir & I915_MASTER_ERROR_INTERRUPT)
4333 i9xx_error_irq_handler(dev_priv, eir, eir_stuck);
4336 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
4338 i965_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4341 pmu_irq_stats(dev_priv, IRQ_HANDLED);
4343 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
4348 #define HPD_FUNCS(platform) \
4349 static const struct intel_hotplug_funcs platform##_hpd_funcs = { \
4350 .hpd_irq_setup = platform##_hpd_irq_setup, \
4363 * intel_irq_init - initializes irq support
4364 * @dev_priv: i915 device instance
4366 * This function initializes all the irq support including work items, timers
4367 * and all the vtables. It does not setup the interrupt itself though.
4369 void intel_irq_init(struct drm_i915_private *dev_priv)
4371 struct drm_device *dev = &dev_priv->drm;
4374 INIT_WORK(&dev_priv->l3_parity.error_work, ivb_parity_work);
4375 for (i = 0; i < MAX_L3_SLICES; ++i)
4376 dev_priv->l3_parity.remap_info[i] = NULL;
4378 /* pre-gen11 the guc irqs bits are in the upper 16 bits of the pm reg */
4379 if (HAS_GT_UC(dev_priv) && GRAPHICS_VER(dev_priv) < 11)
4380 dev_priv->gt.pm_guc_events = GUC_INTR_GUC2HOST << 16;
4382 if (!HAS_DISPLAY(dev_priv))
4385 intel_hpd_init_pins(dev_priv);
4387 intel_hpd_init_work(dev_priv);
4389 dev->vblank_disable_immediate = true;
4391 /* Most platforms treat the display irq block as an always-on
4392 * power domain. vlv/chv can disable it at runtime and need
4393 * special care to avoid writing any of the display block registers
4394 * outside of the power domain. We defer setting up the display irqs
4395 * in this case to the runtime pm.
4397 dev_priv->display_irqs_enabled = true;
4398 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4399 dev_priv->display_irqs_enabled = false;
4401 dev_priv->hotplug.hpd_storm_threshold = HPD_STORM_DEFAULT_THRESHOLD;
4402 /* If we have MST support, we want to avoid doing short HPD IRQ storm
4403 * detection, as short HPD storms will occur as a natural part of
4404 * sideband messaging with MST.
4405 * On older platforms however, IRQ storms can occur with both long and
4406 * short pulses, as seen on some G4x systems.
4408 dev_priv->hotplug.hpd_short_storm_enabled = !HAS_DP_MST(dev_priv);
4410 if (HAS_GMCH(dev_priv)) {
4411 if (I915_HAS_HOTPLUG(dev_priv))
4412 dev_priv->hotplug_funcs = &i915_hpd_funcs;
4414 if (HAS_PCH_DG1(dev_priv))
4415 dev_priv->hotplug_funcs = &dg1_hpd_funcs;
4416 else if (DISPLAY_VER(dev_priv) >= 11)
4417 dev_priv->hotplug_funcs = &gen11_hpd_funcs;
4418 else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
4419 dev_priv->hotplug_funcs = &bxt_hpd_funcs;
4420 else if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
4421 dev_priv->hotplug_funcs = &icp_hpd_funcs;
4422 else if (INTEL_PCH_TYPE(dev_priv) >= PCH_SPT)
4423 dev_priv->hotplug_funcs = &spt_hpd_funcs;
4425 dev_priv->hotplug_funcs = &ilk_hpd_funcs;
4430 * intel_irq_fini - deinitializes IRQ support
4431 * @i915: i915 device instance
4433 * This function deinitializes all the IRQ support.
4435 void intel_irq_fini(struct drm_i915_private *i915)
4439 for (i = 0; i < MAX_L3_SLICES; ++i)
4440 kfree(i915->l3_parity.remap_info[i]);
4443 static irq_handler_t intel_irq_handler(struct drm_i915_private *dev_priv)
4445 if (HAS_GMCH(dev_priv)) {
4446 if (IS_CHERRYVIEW(dev_priv))
4447 return cherryview_irq_handler;
4448 else if (IS_VALLEYVIEW(dev_priv))
4449 return valleyview_irq_handler;
4450 else if (GRAPHICS_VER(dev_priv) == 4)
4451 return i965_irq_handler;
4452 else if (GRAPHICS_VER(dev_priv) == 3)
4453 return i915_irq_handler;
4455 return i8xx_irq_handler;
4457 if (GRAPHICS_VER_FULL(dev_priv) >= IP_VER(12, 10))
4458 return dg1_irq_handler;
4459 else if (GRAPHICS_VER(dev_priv) >= 11)
4460 return gen11_irq_handler;
4461 else if (GRAPHICS_VER(dev_priv) >= 8)
4462 return gen8_irq_handler;
4464 return ilk_irq_handler;
4468 static void intel_irq_reset(struct drm_i915_private *dev_priv)
4470 if (HAS_GMCH(dev_priv)) {
4471 if (IS_CHERRYVIEW(dev_priv))
4472 cherryview_irq_reset(dev_priv);
4473 else if (IS_VALLEYVIEW(dev_priv))
4474 valleyview_irq_reset(dev_priv);
4475 else if (GRAPHICS_VER(dev_priv) == 4)
4476 i965_irq_reset(dev_priv);
4477 else if (GRAPHICS_VER(dev_priv) == 3)
4478 i915_irq_reset(dev_priv);
4480 i8xx_irq_reset(dev_priv);
4482 if (GRAPHICS_VER_FULL(dev_priv) >= IP_VER(12, 10))
4483 dg1_irq_reset(dev_priv);
4484 else if (GRAPHICS_VER(dev_priv) >= 11)
4485 gen11_irq_reset(dev_priv);
4486 else if (GRAPHICS_VER(dev_priv) >= 8)
4487 gen8_irq_reset(dev_priv);
4489 ilk_irq_reset(dev_priv);
4493 static void intel_irq_postinstall(struct drm_i915_private *dev_priv)
4495 if (HAS_GMCH(dev_priv)) {
4496 if (IS_CHERRYVIEW(dev_priv))
4497 cherryview_irq_postinstall(dev_priv);
4498 else if (IS_VALLEYVIEW(dev_priv))
4499 valleyview_irq_postinstall(dev_priv);
4500 else if (GRAPHICS_VER(dev_priv) == 4)
4501 i965_irq_postinstall(dev_priv);
4502 else if (GRAPHICS_VER(dev_priv) == 3)
4503 i915_irq_postinstall(dev_priv);
4505 i8xx_irq_postinstall(dev_priv);
4507 if (GRAPHICS_VER_FULL(dev_priv) >= IP_VER(12, 10))
4508 dg1_irq_postinstall(dev_priv);
4509 else if (GRAPHICS_VER(dev_priv) >= 11)
4510 gen11_irq_postinstall(dev_priv);
4511 else if (GRAPHICS_VER(dev_priv) >= 8)
4512 gen8_irq_postinstall(dev_priv);
4514 ilk_irq_postinstall(dev_priv);
4519 * intel_irq_install - enables the hardware interrupt
4520 * @dev_priv: i915 device instance
4522 * This function enables the hardware interrupt handling, but leaves the hotplug
4523 * handling still disabled. It is called after intel_irq_init().
4525 * In the driver load and resume code we need working interrupts in a few places
4526 * but don't want to deal with the hassle of concurrent probe and hotplug
4527 * workers. Hence the split into this two-stage approach.
4529 int intel_irq_install(struct drm_i915_private *dev_priv)
4531 int irq = to_pci_dev(dev_priv->drm.dev)->irq;
4535 * We enable some interrupt sources in our postinstall hooks, so mark
4536 * interrupts as enabled _before_ actually enabling them to avoid
4537 * special cases in our ordering checks.
4539 dev_priv->runtime_pm.irqs_enabled = true;
4541 dev_priv->irq_enabled = true;
4543 intel_irq_reset(dev_priv);
4545 ret = request_irq(irq, intel_irq_handler(dev_priv),
4546 IRQF_SHARED, DRIVER_NAME, dev_priv);
4548 dev_priv->irq_enabled = false;
4552 intel_irq_postinstall(dev_priv);
4558 * intel_irq_uninstall - finilizes all irq handling
4559 * @dev_priv: i915 device instance
4561 * This stops interrupt and hotplug handling and unregisters and frees all
4562 * resources acquired in the init functions.
4564 void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4566 int irq = to_pci_dev(dev_priv->drm.dev)->irq;
4569 * FIXME we can get called twice during driver probe
4570 * error handling as well as during driver remove due to
4571 * intel_modeset_driver_remove() calling us out of sequence.
4572 * Would be nice if it didn't do that...
4574 if (!dev_priv->irq_enabled)
4577 dev_priv->irq_enabled = false;
4579 intel_irq_reset(dev_priv);
4581 free_irq(irq, dev_priv);
4583 intel_hpd_cancel_work(dev_priv);
4584 dev_priv->runtime_pm.irqs_enabled = false;
4588 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4589 * @dev_priv: i915 device instance
4591 * This function is used to disable interrupts at runtime, both in the runtime
4592 * pm and the system suspend/resume code.
4594 void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
4596 intel_irq_reset(dev_priv);
4597 dev_priv->runtime_pm.irqs_enabled = false;
4598 intel_synchronize_irq(dev_priv);
4602 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4603 * @dev_priv: i915 device instance
4605 * This function is used to enable interrupts at runtime, both in the runtime
4606 * pm and the system suspend/resume code.
4608 void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
4610 dev_priv->runtime_pm.irqs_enabled = true;
4611 intel_irq_reset(dev_priv);
4612 intel_irq_postinstall(dev_priv);
4615 bool intel_irqs_enabled(struct drm_i915_private *dev_priv)
4617 return dev_priv->runtime_pm.irqs_enabled;
4620 void intel_synchronize_irq(struct drm_i915_private *i915)
4622 synchronize_irq(to_pci_dev(i915->drm.dev)->irq);
4625 void intel_synchronize_hardirq(struct drm_i915_private *i915)
4627 synchronize_hardirq(to_pci_dev(i915->drm.dev)->irq);