xref: /openbmc/linux/drivers/gpu/drm/i915/i915_irq.c (revision 839259b8afbb78bcd6d0b698e82cd4578a505ba4)
1c0e09200SDave Airlie /* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
2c0e09200SDave Airlie  */
3c0e09200SDave Airlie /*
4c0e09200SDave Airlie  * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
5c0e09200SDave Airlie  * All Rights Reserved.
6c0e09200SDave Airlie  *
7c0e09200SDave Airlie  * Permission is hereby granted, free of charge, to any person obtaining a
8c0e09200SDave Airlie  * copy of this software and associated documentation files (the
9c0e09200SDave Airlie  * "Software"), to deal in the Software without restriction, including
10c0e09200SDave Airlie  * without limitation the rights to use, copy, modify, merge, publish,
11c0e09200SDave Airlie  * distribute, sub license, and/or sell copies of the Software, and to
12c0e09200SDave Airlie  * permit persons to whom the Software is furnished to do so, subject to
13c0e09200SDave Airlie  * the following conditions:
14c0e09200SDave Airlie  *
15c0e09200SDave Airlie  * The above copyright notice and this permission notice (including the
16c0e09200SDave Airlie  * next paragraph) shall be included in all copies or substantial portions
17c0e09200SDave Airlie  * of the Software.
18c0e09200SDave Airlie  *
19c0e09200SDave Airlie  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20c0e09200SDave Airlie  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21c0e09200SDave Airlie  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22c0e09200SDave Airlie  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23c0e09200SDave Airlie  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24c0e09200SDave Airlie  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25c0e09200SDave Airlie  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26c0e09200SDave Airlie  *
27c0e09200SDave Airlie  */
28c0e09200SDave Airlie 
29a70491ccSJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30a70491ccSJoe Perches 
3155367a27SJani Nikula #include <linux/slab.h>
3255367a27SJani Nikula #include <linux/sysrq.h>
3355367a27SJani Nikula 
34fcd70cd3SDaniel Vetter #include <drm/drm_drv.h>
3555367a27SJani Nikula 
363c0deb14SJani Nikula #include "display/icl_dsi_regs.h"
377785ae0bSVille Syrjälä #include "display/intel_de.h"
38fd2b94a5SJani Nikula #include "display/intel_display_trace.h"
391d455f8dSJani Nikula #include "display/intel_display_types.h"
40df0566a6SJani Nikula #include "display/intel_fifo_underrun.h"
41df0566a6SJani Nikula #include "display/intel_hotplug.h"
42df0566a6SJani Nikula #include "display/intel_lpe_audio.h"
43df0566a6SJani Nikula #include "display/intel_psr.h"
44df0566a6SJani Nikula 
45b3786b29SChris Wilson #include "gt/intel_breadcrumbs.h"
462239e6dfSDaniele Ceraolo Spurio #include "gt/intel_gt.h"
47cf1c97dcSAndi Shyti #include "gt/intel_gt_irq.h"
48d762043fSAndi Shyti #include "gt/intel_gt_pm_irq.h"
490d6419e9SMatt Roper #include "gt/intel_gt_regs.h"
503e7abf81SAndi Shyti #include "gt/intel_rps.h"
512239e6dfSDaniele Ceraolo Spurio 
5224524e3fSJani Nikula #include "i915_driver.h"
53c0e09200SDave Airlie #include "i915_drv.h"
54440e2b3dSJani Nikula #include "i915_irq.h"
55d13616dbSJani Nikula #include "intel_pm.h"
56c0e09200SDave Airlie 
57fca52a55SDaniel Vetter /**
58fca52a55SDaniel Vetter  * DOC: interrupt handling
59fca52a55SDaniel Vetter  *
60fca52a55SDaniel Vetter  * These functions provide the basic support for enabling and disabling the
61fca52a55SDaniel Vetter  * interrupt handling support. There's a lot more functionality in i915_irq.c
62fca52a55SDaniel Vetter  * and related files, but that will be described in separate chapters.
63fca52a55SDaniel Vetter  */
64fca52a55SDaniel Vetter 
659c6508b9SThomas Gleixner /*
669c6508b9SThomas Gleixner  * Interrupt statistic for PMU. Increments the counter only if the
6778f48aa6SBo Liu  * interrupt originated from the GPU so interrupts from a device which
689c6508b9SThomas Gleixner  * shares the interrupt line are not accounted.
699c6508b9SThomas Gleixner  */
709c6508b9SThomas Gleixner static inline void pmu_irq_stats(struct drm_i915_private *i915,
719c6508b9SThomas Gleixner 				 irqreturn_t res)
729c6508b9SThomas Gleixner {
739c6508b9SThomas Gleixner 	if (unlikely(res != IRQ_HANDLED))
749c6508b9SThomas Gleixner 		return;
759c6508b9SThomas Gleixner 
769c6508b9SThomas Gleixner 	/*
779c6508b9SThomas Gleixner 	 * A clever compiler translates that into INC. A not so clever one
789c6508b9SThomas Gleixner 	 * should at least prevent store tearing.
799c6508b9SThomas Gleixner 	 */
809c6508b9SThomas Gleixner 	WRITE_ONCE(i915->pmu.irq_count, i915->pmu.irq_count + 1);
819c6508b9SThomas Gleixner }
829c6508b9SThomas Gleixner 
8348ef15d3SJosé Roberto de Souza typedef bool (*long_pulse_detect_func)(enum hpd_pin pin, u32 val);
84dfefe7bcSVille Syrjälä typedef u32 (*hotplug_enables_func)(struct intel_encoder *encoder);
8548ef15d3SJosé Roberto de Souza 
86e4ce95aaSVille Syrjälä static const u32 hpd_ilk[HPD_NUM_PINS] = {
87e4ce95aaSVille Syrjälä 	[HPD_PORT_A] = DE_DP_A_HOTPLUG,
88e4ce95aaSVille Syrjälä };
89e4ce95aaSVille Syrjälä 
9023bb4cb5SVille Syrjälä static const u32 hpd_ivb[HPD_NUM_PINS] = {
9123bb4cb5SVille Syrjälä 	[HPD_PORT_A] = DE_DP_A_HOTPLUG_IVB,
9223bb4cb5SVille Syrjälä };
9323bb4cb5SVille Syrjälä 
943a3b3c7dSVille Syrjälä static const u32 hpd_bdw[HPD_NUM_PINS] = {
95e5abaab3SVille Syrjälä 	[HPD_PORT_A] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_A),
963a3b3c7dSVille Syrjälä };
973a3b3c7dSVille Syrjälä 
987c7e10dbSVille Syrjälä static const u32 hpd_ibx[HPD_NUM_PINS] = {
99e5868a31SEgbert Eich 	[HPD_CRT] = SDE_CRT_HOTPLUG,
100e5868a31SEgbert Eich 	[HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
101e5868a31SEgbert Eich 	[HPD_PORT_B] = SDE_PORTB_HOTPLUG,
102e5868a31SEgbert Eich 	[HPD_PORT_C] = SDE_PORTC_HOTPLUG,
1037203d49cSVille Syrjälä 	[HPD_PORT_D] = SDE_PORTD_HOTPLUG,
104e5868a31SEgbert Eich };
105e5868a31SEgbert Eich 
1067c7e10dbSVille Syrjälä static const u32 hpd_cpt[HPD_NUM_PINS] = {
107e5868a31SEgbert Eich 	[HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
10873c352a2SDaniel Vetter 	[HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
109e5868a31SEgbert Eich 	[HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
110e5868a31SEgbert Eich 	[HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
1117203d49cSVille Syrjälä 	[HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT,
112e5868a31SEgbert Eich };
113e5868a31SEgbert Eich 
11426951cafSXiong Zhang static const u32 hpd_spt[HPD_NUM_PINS] = {
11574c0b395SVille Syrjälä 	[HPD_PORT_A] = SDE_PORTA_HOTPLUG_SPT,
11626951cafSXiong Zhang 	[HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
11726951cafSXiong Zhang 	[HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
11826951cafSXiong Zhang 	[HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT,
1197203d49cSVille Syrjälä 	[HPD_PORT_E] = SDE_PORTE_HOTPLUG_SPT,
12026951cafSXiong Zhang };
12126951cafSXiong Zhang 
1227c7e10dbSVille Syrjälä static const u32 hpd_mask_i915[HPD_NUM_PINS] = {
123e5868a31SEgbert Eich 	[HPD_CRT] = CRT_HOTPLUG_INT_EN,
124e5868a31SEgbert Eich 	[HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
125e5868a31SEgbert Eich 	[HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
126e5868a31SEgbert Eich 	[HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
127e5868a31SEgbert Eich 	[HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
1287203d49cSVille Syrjälä 	[HPD_PORT_D] = PORTD_HOTPLUG_INT_EN,
129e5868a31SEgbert Eich };
130e5868a31SEgbert Eich 
1317c7e10dbSVille Syrjälä static const u32 hpd_status_g4x[HPD_NUM_PINS] = {
132e5868a31SEgbert Eich 	[HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
133e5868a31SEgbert Eich 	[HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
134e5868a31SEgbert Eich 	[HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
135e5868a31SEgbert Eich 	[HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
136e5868a31SEgbert Eich 	[HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
1377203d49cSVille Syrjälä 	[HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS,
138e5868a31SEgbert Eich };
139e5868a31SEgbert Eich 
1404bca26d0SVille Syrjälä static const u32 hpd_status_i915[HPD_NUM_PINS] = {
141e5868a31SEgbert Eich 	[HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
142e5868a31SEgbert Eich 	[HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
143e5868a31SEgbert Eich 	[HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
144e5868a31SEgbert Eich 	[HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
145e5868a31SEgbert Eich 	[HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
1467203d49cSVille Syrjälä 	[HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS,
147e5868a31SEgbert Eich };
148e5868a31SEgbert Eich 
149e0a20ad7SShashank Sharma static const u32 hpd_bxt[HPD_NUM_PINS] = {
150e5abaab3SVille Syrjälä 	[HPD_PORT_A] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_A),
151e5abaab3SVille Syrjälä 	[HPD_PORT_B] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_B),
152e5abaab3SVille Syrjälä 	[HPD_PORT_C] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_C),
153e0a20ad7SShashank Sharma };
154e0a20ad7SShashank Sharma 
155b796b971SDhinakaran Pandiyan static const u32 hpd_gen11[HPD_NUM_PINS] = {
1565b76e860SVille Syrjälä 	[HPD_PORT_TC1] = GEN11_TC_HOTPLUG(HPD_PORT_TC1) | GEN11_TBT_HOTPLUG(HPD_PORT_TC1),
1575b76e860SVille Syrjälä 	[HPD_PORT_TC2] = GEN11_TC_HOTPLUG(HPD_PORT_TC2) | GEN11_TBT_HOTPLUG(HPD_PORT_TC2),
1585b76e860SVille Syrjälä 	[HPD_PORT_TC3] = GEN11_TC_HOTPLUG(HPD_PORT_TC3) | GEN11_TBT_HOTPLUG(HPD_PORT_TC3),
1595b76e860SVille Syrjälä 	[HPD_PORT_TC4] = GEN11_TC_HOTPLUG(HPD_PORT_TC4) | GEN11_TBT_HOTPLUG(HPD_PORT_TC4),
1605b76e860SVille Syrjälä 	[HPD_PORT_TC5] = GEN11_TC_HOTPLUG(HPD_PORT_TC5) | GEN11_TBT_HOTPLUG(HPD_PORT_TC5),
1615b76e860SVille Syrjälä 	[HPD_PORT_TC6] = GEN11_TC_HOTPLUG(HPD_PORT_TC6) | GEN11_TBT_HOTPLUG(HPD_PORT_TC6),
16248ef15d3SJosé Roberto de Souza };
16348ef15d3SJosé Roberto de Souza 
16431604222SAnusha Srivatsa static const u32 hpd_icp[HPD_NUM_PINS] = {
1655f371a81SVille Syrjälä 	[HPD_PORT_A] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_A),
1665f371a81SVille Syrjälä 	[HPD_PORT_B] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_B),
1675f371a81SVille Syrjälä 	[HPD_PORT_C] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_C),
16897011359SVille Syrjälä 	[HPD_PORT_TC1] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC1),
16997011359SVille Syrjälä 	[HPD_PORT_TC2] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC2),
17097011359SVille Syrjälä 	[HPD_PORT_TC3] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC3),
17197011359SVille Syrjälä 	[HPD_PORT_TC4] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC4),
17297011359SVille Syrjälä 	[HPD_PORT_TC5] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC5),
17397011359SVille Syrjälä 	[HPD_PORT_TC6] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC6),
17452dfdba0SLucas De Marchi };
17552dfdba0SLucas De Marchi 
176229f31e2SLucas De Marchi static const u32 hpd_sde_dg1[HPD_NUM_PINS] = {
1775f371a81SVille Syrjälä 	[HPD_PORT_A] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_A),
1785f371a81SVille Syrjälä 	[HPD_PORT_B] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_B),
1795f371a81SVille Syrjälä 	[HPD_PORT_C] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_C),
1805f371a81SVille Syrjälä 	[HPD_PORT_D] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_D),
1812f8a6699SMatt Roper 	[HPD_PORT_TC1] = SDE_TC_HOTPLUG_DG2(HPD_PORT_TC1),
182229f31e2SLucas De Marchi };
183229f31e2SLucas De Marchi 
1840398993bSVille Syrjälä static void intel_hpd_init_pins(struct drm_i915_private *dev_priv)
1850398993bSVille Syrjälä {
1865a4dd6f0SJani Nikula 	struct intel_hotplug *hpd = &dev_priv->display.hotplug;
1870398993bSVille Syrjälä 
1880398993bSVille Syrjälä 	if (HAS_GMCH(dev_priv)) {
1890398993bSVille Syrjälä 		if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
1900398993bSVille Syrjälä 		    IS_CHERRYVIEW(dev_priv))
1910398993bSVille Syrjälä 			hpd->hpd = hpd_status_g4x;
1920398993bSVille Syrjälä 		else
1930398993bSVille Syrjälä 			hpd->hpd = hpd_status_i915;
1940398993bSVille Syrjälä 		return;
1950398993bSVille Syrjälä 	}
1960398993bSVille Syrjälä 
197373abf1aSMatt Roper 	if (DISPLAY_VER(dev_priv) >= 11)
1980398993bSVille Syrjälä 		hpd->hpd = hpd_gen11;
19970bfb307SMatt Roper 	else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
2000398993bSVille Syrjälä 		hpd->hpd = hpd_bxt;
201373abf1aSMatt Roper 	else if (DISPLAY_VER(dev_priv) >= 8)
2020398993bSVille Syrjälä 		hpd->hpd = hpd_bdw;
203373abf1aSMatt Roper 	else if (DISPLAY_VER(dev_priv) >= 7)
2040398993bSVille Syrjälä 		hpd->hpd = hpd_ivb;
2050398993bSVille Syrjälä 	else
2060398993bSVille Syrjälä 		hpd->hpd = hpd_ilk;
2070398993bSVille Syrjälä 
208229f31e2SLucas De Marchi 	if ((INTEL_PCH_TYPE(dev_priv) < PCH_DG1) &&
209229f31e2SLucas De Marchi 	    (!HAS_PCH_SPLIT(dev_priv) || HAS_PCH_NOP(dev_priv)))
2100398993bSVille Syrjälä 		return;
2110398993bSVille Syrjälä 
2123176fb66SMatt Roper 	if (INTEL_PCH_TYPE(dev_priv) >= PCH_DG1)
213229f31e2SLucas De Marchi 		hpd->pch_hpd = hpd_sde_dg1;
214fa58c9e4SAnusha Srivatsa 	else if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
2150398993bSVille Syrjälä 		hpd->pch_hpd = hpd_icp;
2160398993bSVille Syrjälä 	else if (HAS_PCH_CNP(dev_priv) || HAS_PCH_SPT(dev_priv))
2170398993bSVille Syrjälä 		hpd->pch_hpd = hpd_spt;
2180398993bSVille Syrjälä 	else if (HAS_PCH_LPT(dev_priv) || HAS_PCH_CPT(dev_priv))
2190398993bSVille Syrjälä 		hpd->pch_hpd = hpd_cpt;
2200398993bSVille Syrjälä 	else if (HAS_PCH_IBX(dev_priv))
2210398993bSVille Syrjälä 		hpd->pch_hpd = hpd_ibx;
2220398993bSVille Syrjälä 	else
2230398993bSVille Syrjälä 		MISSING_CASE(INTEL_PCH_TYPE(dev_priv));
2240398993bSVille Syrjälä }
2250398993bSVille Syrjälä 
226aca9310aSAnshuman Gupta static void
227aca9310aSAnshuman Gupta intel_handle_vblank(struct drm_i915_private *dev_priv, enum pipe pipe)
228aca9310aSAnshuman Gupta {
2297794b6deSJani Nikula 	struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
230aca9310aSAnshuman Gupta 
231aca9310aSAnshuman Gupta 	drm_crtc_handle_vblank(&crtc->base);
232aca9310aSAnshuman Gupta }
233aca9310aSAnshuman Gupta 
234cf1c97dcSAndi Shyti void gen3_irq_reset(struct intel_uncore *uncore, i915_reg_t imr,
23568eb49b1SPaulo Zanoni 		    i915_reg_t iir, i915_reg_t ier)
23668eb49b1SPaulo Zanoni {
23765f42cdcSPaulo Zanoni 	intel_uncore_write(uncore, imr, 0xffffffff);
23865f42cdcSPaulo Zanoni 	intel_uncore_posting_read(uncore, imr);
23968eb49b1SPaulo Zanoni 
24065f42cdcSPaulo Zanoni 	intel_uncore_write(uncore, ier, 0);
24168eb49b1SPaulo Zanoni 
2425c502442SPaulo Zanoni 	/* IIR can theoretically queue up two events. Be paranoid. */
24365f42cdcSPaulo Zanoni 	intel_uncore_write(uncore, iir, 0xffffffff);
24465f42cdcSPaulo Zanoni 	intel_uncore_posting_read(uncore, iir);
24565f42cdcSPaulo Zanoni 	intel_uncore_write(uncore, iir, 0xffffffff);
24665f42cdcSPaulo Zanoni 	intel_uncore_posting_read(uncore, iir);
24768eb49b1SPaulo Zanoni }
2485c502442SPaulo Zanoni 
249ad7632ffSJani Nikula static void gen2_irq_reset(struct intel_uncore *uncore)
25068eb49b1SPaulo Zanoni {
25165f42cdcSPaulo Zanoni 	intel_uncore_write16(uncore, GEN2_IMR, 0xffff);
25265f42cdcSPaulo Zanoni 	intel_uncore_posting_read16(uncore, GEN2_IMR);
253a9d356a6SPaulo Zanoni 
25465f42cdcSPaulo Zanoni 	intel_uncore_write16(uncore, GEN2_IER, 0);
25568eb49b1SPaulo Zanoni 
25668eb49b1SPaulo Zanoni 	/* IIR can theoretically queue up two events. Be paranoid. */
25765f42cdcSPaulo Zanoni 	intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
25865f42cdcSPaulo Zanoni 	intel_uncore_posting_read16(uncore, GEN2_IIR);
25965f42cdcSPaulo Zanoni 	intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
26065f42cdcSPaulo Zanoni 	intel_uncore_posting_read16(uncore, GEN2_IIR);
26168eb49b1SPaulo Zanoni }
26268eb49b1SPaulo Zanoni 
263337ba017SPaulo Zanoni /*
264337ba017SPaulo Zanoni  * We should clear IMR at preinstall/uninstall, and just check at postinstall.
265337ba017SPaulo Zanoni  */
26665f42cdcSPaulo Zanoni static void gen3_assert_iir_is_zero(struct intel_uncore *uncore, i915_reg_t reg)
267b51a2842SVille Syrjälä {
26865f42cdcSPaulo Zanoni 	u32 val = intel_uncore_read(uncore, reg);
269b51a2842SVille Syrjälä 
270b51a2842SVille Syrjälä 	if (val == 0)
271b51a2842SVille Syrjälä 		return;
272b51a2842SVille Syrjälä 
273a9f236d1SPankaj Bharadiya 	drm_WARN(&uncore->i915->drm, 1,
274a9f236d1SPankaj Bharadiya 		 "Interrupt register 0x%x is not zero: 0x%08x\n",
275f0f59a00SVille Syrjälä 		 i915_mmio_reg_offset(reg), val);
27665f42cdcSPaulo Zanoni 	intel_uncore_write(uncore, reg, 0xffffffff);
27765f42cdcSPaulo Zanoni 	intel_uncore_posting_read(uncore, reg);
27865f42cdcSPaulo Zanoni 	intel_uncore_write(uncore, reg, 0xffffffff);
27965f42cdcSPaulo Zanoni 	intel_uncore_posting_read(uncore, reg);
280b51a2842SVille Syrjälä }
281337ba017SPaulo Zanoni 
28265f42cdcSPaulo Zanoni static void gen2_assert_iir_is_zero(struct intel_uncore *uncore)
283e9e9848aSVille Syrjälä {
28465f42cdcSPaulo Zanoni 	u16 val = intel_uncore_read16(uncore, GEN2_IIR);
285e9e9848aSVille Syrjälä 
286e9e9848aSVille Syrjälä 	if (val == 0)
287e9e9848aSVille Syrjälä 		return;
288e9e9848aSVille Syrjälä 
289a9f236d1SPankaj Bharadiya 	drm_WARN(&uncore->i915->drm, 1,
290a9f236d1SPankaj Bharadiya 		 "Interrupt register 0x%x is not zero: 0x%08x\n",
2919d9523d8SPaulo Zanoni 		 i915_mmio_reg_offset(GEN2_IIR), val);
29265f42cdcSPaulo Zanoni 	intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
29365f42cdcSPaulo Zanoni 	intel_uncore_posting_read16(uncore, GEN2_IIR);
29465f42cdcSPaulo Zanoni 	intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
29565f42cdcSPaulo Zanoni 	intel_uncore_posting_read16(uncore, GEN2_IIR);
296e9e9848aSVille Syrjälä }
297e9e9848aSVille Syrjälä 
298cf1c97dcSAndi Shyti void gen3_irq_init(struct intel_uncore *uncore,
29968eb49b1SPaulo Zanoni 		   i915_reg_t imr, u32 imr_val,
30068eb49b1SPaulo Zanoni 		   i915_reg_t ier, u32 ier_val,
30168eb49b1SPaulo Zanoni 		   i915_reg_t iir)
30268eb49b1SPaulo Zanoni {
30365f42cdcSPaulo Zanoni 	gen3_assert_iir_is_zero(uncore, iir);
30435079899SPaulo Zanoni 
30565f42cdcSPaulo Zanoni 	intel_uncore_write(uncore, ier, ier_val);
30665f42cdcSPaulo Zanoni 	intel_uncore_write(uncore, imr, imr_val);
30765f42cdcSPaulo Zanoni 	intel_uncore_posting_read(uncore, imr);
30868eb49b1SPaulo Zanoni }
30935079899SPaulo Zanoni 
310ad7632ffSJani Nikula static void gen2_irq_init(struct intel_uncore *uncore,
3112918c3caSPaulo Zanoni 			  u32 imr_val, u32 ier_val)
31268eb49b1SPaulo Zanoni {
31365f42cdcSPaulo Zanoni 	gen2_assert_iir_is_zero(uncore);
31468eb49b1SPaulo Zanoni 
31565f42cdcSPaulo Zanoni 	intel_uncore_write16(uncore, GEN2_IER, ier_val);
31665f42cdcSPaulo Zanoni 	intel_uncore_write16(uncore, GEN2_IMR, imr_val);
31765f42cdcSPaulo Zanoni 	intel_uncore_posting_read16(uncore, GEN2_IMR);
31868eb49b1SPaulo Zanoni }
31968eb49b1SPaulo Zanoni 
3200706f17cSEgbert Eich /* For display hotplug interrupt */
3210706f17cSEgbert Eich static inline void
3220706f17cSEgbert Eich i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv,
323a9c287c9SJani Nikula 				     u32 mask,
324a9c287c9SJani Nikula 				     u32 bits)
3250706f17cSEgbert Eich {
32667520415SChris Wilson 	lockdep_assert_held(&dev_priv->irq_lock);
32748a1b8d4SPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm, bits & ~mask);
3280706f17cSEgbert Eich 
3298cee664dSAndrzej Hajda 	intel_uncore_rmw(&dev_priv->uncore, PORT_HOTPLUG_EN, mask, bits);
3300706f17cSEgbert Eich }
3310706f17cSEgbert Eich 
3320706f17cSEgbert Eich /**
3330706f17cSEgbert Eich  * i915_hotplug_interrupt_update - update hotplug interrupt enable
3340706f17cSEgbert Eich  * @dev_priv: driver private
3350706f17cSEgbert Eich  * @mask: bits to update
3360706f17cSEgbert Eich  * @bits: bits to enable
3370706f17cSEgbert Eich  * NOTE: the HPD enable bits are modified both inside and outside
3380706f17cSEgbert Eich  * of an interrupt context. To avoid that read-modify-write cycles
3390706f17cSEgbert Eich  * interfer, these bits are protected by a spinlock. Since this
3400706f17cSEgbert Eich  * function is usually not called from a context where the lock is
3410706f17cSEgbert Eich  * held already, this function acquires the lock itself. A non-locking
3420706f17cSEgbert Eich  * version is also available.
3430706f17cSEgbert Eich  */
3440706f17cSEgbert Eich void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
345a9c287c9SJani Nikula 				   u32 mask,
346a9c287c9SJani Nikula 				   u32 bits)
3470706f17cSEgbert Eich {
3480706f17cSEgbert Eich 	spin_lock_irq(&dev_priv->irq_lock);
3490706f17cSEgbert Eich 	i915_hotplug_interrupt_update_locked(dev_priv, mask, bits);
3500706f17cSEgbert Eich 	spin_unlock_irq(&dev_priv->irq_lock);
3510706f17cSEgbert Eich }
3520706f17cSEgbert Eich 
353d9dc34f1SVille Syrjälä /**
354d9dc34f1SVille Syrjälä  * ilk_update_display_irq - update DEIMR
355d9dc34f1SVille Syrjälä  * @dev_priv: driver private
356d9dc34f1SVille Syrjälä  * @interrupt_mask: mask of interrupt bits to update
357d9dc34f1SVille Syrjälä  * @enabled_irq_mask: mask of interrupt bits to enable
358d9dc34f1SVille Syrjälä  */
3599e6dcf33SJani Nikula static void ilk_update_display_irq(struct drm_i915_private *dev_priv,
3609e6dcf33SJani Nikula 				   u32 interrupt_mask, u32 enabled_irq_mask)
361036a4a7dSZhenyu Wang {
362a9c287c9SJani Nikula 	u32 new_val;
363d9dc34f1SVille Syrjälä 
36467520415SChris Wilson 	lockdep_assert_held(&dev_priv->irq_lock);
36548a1b8d4SPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm, enabled_irq_mask & ~interrupt_mask);
366d9dc34f1SVille Syrjälä 
367d9dc34f1SVille Syrjälä 	new_val = dev_priv->irq_mask;
368d9dc34f1SVille Syrjälä 	new_val &= ~interrupt_mask;
369d9dc34f1SVille Syrjälä 	new_val |= (~enabled_irq_mask & interrupt_mask);
370d9dc34f1SVille Syrjälä 
371e44adb5dSChris Wilson 	if (new_val != dev_priv->irq_mask &&
372e44adb5dSChris Wilson 	    !drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv))) {
373d9dc34f1SVille Syrjälä 		dev_priv->irq_mask = new_val;
3742939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, DEIMR, dev_priv->irq_mask);
3752939eb06SJani Nikula 		intel_uncore_posting_read(&dev_priv->uncore, DEIMR);
376036a4a7dSZhenyu Wang 	}
377036a4a7dSZhenyu Wang }
378036a4a7dSZhenyu Wang 
3799e6dcf33SJani Nikula void ilk_enable_display_irq(struct drm_i915_private *i915, u32 bits)
3809e6dcf33SJani Nikula {
3819e6dcf33SJani Nikula 	ilk_update_display_irq(i915, bits, bits);
3829e6dcf33SJani Nikula }
3839e6dcf33SJani Nikula 
3849e6dcf33SJani Nikula void ilk_disable_display_irq(struct drm_i915_private *i915, u32 bits)
3859e6dcf33SJani Nikula {
3869e6dcf33SJani Nikula 	ilk_update_display_irq(i915, bits, 0);
3879e6dcf33SJani Nikula }
3889e6dcf33SJani Nikula 
3890961021aSBen Widawsky /**
3903a3b3c7dSVille Syrjälä  * bdw_update_port_irq - update DE port interrupt
3913a3b3c7dSVille Syrjälä  * @dev_priv: driver private
3923a3b3c7dSVille Syrjälä  * @interrupt_mask: mask of interrupt bits to update
3933a3b3c7dSVille Syrjälä  * @enabled_irq_mask: mask of interrupt bits to enable
3943a3b3c7dSVille Syrjälä  */
3953a3b3c7dSVille Syrjälä static void bdw_update_port_irq(struct drm_i915_private *dev_priv,
396a9c287c9SJani Nikula 				u32 interrupt_mask,
397a9c287c9SJani Nikula 				u32 enabled_irq_mask)
3983a3b3c7dSVille Syrjälä {
399a9c287c9SJani Nikula 	u32 new_val;
400a9c287c9SJani Nikula 	u32 old_val;
4013a3b3c7dSVille Syrjälä 
40267520415SChris Wilson 	lockdep_assert_held(&dev_priv->irq_lock);
4033a3b3c7dSVille Syrjälä 
40448a1b8d4SPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm, enabled_irq_mask & ~interrupt_mask);
4053a3b3c7dSVille Syrjälä 
40648a1b8d4SPankaj Bharadiya 	if (drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv)))
4073a3b3c7dSVille Syrjälä 		return;
4083a3b3c7dSVille Syrjälä 
4092939eb06SJani Nikula 	old_val = intel_uncore_read(&dev_priv->uncore, GEN8_DE_PORT_IMR);
4103a3b3c7dSVille Syrjälä 
4113a3b3c7dSVille Syrjälä 	new_val = old_val;
4123a3b3c7dSVille Syrjälä 	new_val &= ~interrupt_mask;
4133a3b3c7dSVille Syrjälä 	new_val |= (~enabled_irq_mask & interrupt_mask);
4143a3b3c7dSVille Syrjälä 
4153a3b3c7dSVille Syrjälä 	if (new_val != old_val) {
4162939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, GEN8_DE_PORT_IMR, new_val);
4172939eb06SJani Nikula 		intel_uncore_posting_read(&dev_priv->uncore, GEN8_DE_PORT_IMR);
4183a3b3c7dSVille Syrjälä 	}
4193a3b3c7dSVille Syrjälä }
4203a3b3c7dSVille Syrjälä 
4213a3b3c7dSVille Syrjälä /**
422013d3752SVille Syrjälä  * bdw_update_pipe_irq - update DE pipe interrupt
423013d3752SVille Syrjälä  * @dev_priv: driver private
424013d3752SVille Syrjälä  * @pipe: pipe whose interrupt to update
425013d3752SVille Syrjälä  * @interrupt_mask: mask of interrupt bits to update
426013d3752SVille Syrjälä  * @enabled_irq_mask: mask of interrupt bits to enable
427013d3752SVille Syrjälä  */
4289e6dcf33SJani Nikula static void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
4299e6dcf33SJani Nikula 				enum pipe pipe, u32 interrupt_mask,
430a9c287c9SJani Nikula 				u32 enabled_irq_mask)
431013d3752SVille Syrjälä {
432a9c287c9SJani Nikula 	u32 new_val;
433013d3752SVille Syrjälä 
43467520415SChris Wilson 	lockdep_assert_held(&dev_priv->irq_lock);
435013d3752SVille Syrjälä 
43648a1b8d4SPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm, enabled_irq_mask & ~interrupt_mask);
437013d3752SVille Syrjälä 
43848a1b8d4SPankaj Bharadiya 	if (drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv)))
439013d3752SVille Syrjälä 		return;
440013d3752SVille Syrjälä 
441013d3752SVille Syrjälä 	new_val = dev_priv->de_irq_mask[pipe];
442013d3752SVille Syrjälä 	new_val &= ~interrupt_mask;
443013d3752SVille Syrjälä 	new_val |= (~enabled_irq_mask & interrupt_mask);
444013d3752SVille Syrjälä 
445013d3752SVille Syrjälä 	if (new_val != dev_priv->de_irq_mask[pipe]) {
446013d3752SVille Syrjälä 		dev_priv->de_irq_mask[pipe] = new_val;
4472939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
4482939eb06SJani Nikula 		intel_uncore_posting_read(&dev_priv->uncore, GEN8_DE_PIPE_IMR(pipe));
449013d3752SVille Syrjälä 	}
450013d3752SVille Syrjälä }
451013d3752SVille Syrjälä 
4529e6dcf33SJani Nikula void bdw_enable_pipe_irq(struct drm_i915_private *i915,
4539e6dcf33SJani Nikula 			 enum pipe pipe, u32 bits)
4549e6dcf33SJani Nikula {
4559e6dcf33SJani Nikula 	bdw_update_pipe_irq(i915, pipe, bits, bits);
4569e6dcf33SJani Nikula }
4579e6dcf33SJani Nikula 
4589e6dcf33SJani Nikula void bdw_disable_pipe_irq(struct drm_i915_private *i915,
4599e6dcf33SJani Nikula 			  enum pipe pipe, u32 bits)
4609e6dcf33SJani Nikula {
4619e6dcf33SJani Nikula 	bdw_update_pipe_irq(i915, pipe, bits, 0);
4629e6dcf33SJani Nikula }
4639e6dcf33SJani Nikula 
464013d3752SVille Syrjälä /**
465fee884edSDaniel Vetter  * ibx_display_interrupt_update - update SDEIMR
466fee884edSDaniel Vetter  * @dev_priv: driver private
467fee884edSDaniel Vetter  * @interrupt_mask: mask of interrupt bits to update
468fee884edSDaniel Vetter  * @enabled_irq_mask: mask of interrupt bits to enable
469fee884edSDaniel Vetter  */
4709e6dcf33SJani Nikula static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
471a9c287c9SJani Nikula 					 u32 interrupt_mask,
472a9c287c9SJani Nikula 					 u32 enabled_irq_mask)
473fee884edSDaniel Vetter {
4742939eb06SJani Nikula 	u32 sdeimr = intel_uncore_read(&dev_priv->uncore, SDEIMR);
475fee884edSDaniel Vetter 	sdeimr &= ~interrupt_mask;
476fee884edSDaniel Vetter 	sdeimr |= (~enabled_irq_mask & interrupt_mask);
477fee884edSDaniel Vetter 
47848a1b8d4SPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm, enabled_irq_mask & ~interrupt_mask);
47915a17aaeSDaniel Vetter 
48067520415SChris Wilson 	lockdep_assert_held(&dev_priv->irq_lock);
481fee884edSDaniel Vetter 
48248a1b8d4SPankaj Bharadiya 	if (drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv)))
483c67a470bSPaulo Zanoni 		return;
484c67a470bSPaulo Zanoni 
4852939eb06SJani Nikula 	intel_uncore_write(&dev_priv->uncore, SDEIMR, sdeimr);
4862939eb06SJani Nikula 	intel_uncore_posting_read(&dev_priv->uncore, SDEIMR);
487fee884edSDaniel Vetter }
4888664281bSPaulo Zanoni 
4899e6dcf33SJani Nikula void ibx_enable_display_interrupt(struct drm_i915_private *i915, u32 bits)
4909e6dcf33SJani Nikula {
4919e6dcf33SJani Nikula 	ibx_display_interrupt_update(i915, bits, bits);
4929e6dcf33SJani Nikula }
4939e6dcf33SJani Nikula 
4949e6dcf33SJani Nikula void ibx_disable_display_interrupt(struct drm_i915_private *i915, u32 bits)
4959e6dcf33SJani Nikula {
4969e6dcf33SJani Nikula 	ibx_display_interrupt_update(i915, bits, 0);
4979e6dcf33SJani Nikula }
4989e6dcf33SJani Nikula 
4996b12ca56SVille Syrjälä u32 i915_pipestat_enable_mask(struct drm_i915_private *dev_priv,
5006b12ca56SVille Syrjälä 			      enum pipe pipe)
5017c463586SKeith Packard {
5026b12ca56SVille Syrjälä 	u32 status_mask = dev_priv->pipestat_irq_mask[pipe];
50310c59c51SImre Deak 	u32 enable_mask = status_mask << 16;
50410c59c51SImre Deak 
5056b12ca56SVille Syrjälä 	lockdep_assert_held(&dev_priv->irq_lock);
5066b12ca56SVille Syrjälä 
507373abf1aSMatt Roper 	if (DISPLAY_VER(dev_priv) < 5)
5086b12ca56SVille Syrjälä 		goto out;
5096b12ca56SVille Syrjälä 
51010c59c51SImre Deak 	/*
511724a6905SVille Syrjälä 	 * On pipe A we don't support the PSR interrupt yet,
512724a6905SVille Syrjälä 	 * on pipe B and C the same bit MBZ.
51310c59c51SImre Deak 	 */
51448a1b8d4SPankaj Bharadiya 	if (drm_WARN_ON_ONCE(&dev_priv->drm,
51548a1b8d4SPankaj Bharadiya 			     status_mask & PIPE_A_PSR_STATUS_VLV))
51610c59c51SImre Deak 		return 0;
517724a6905SVille Syrjälä 	/*
518724a6905SVille Syrjälä 	 * On pipe B and C we don't support the PSR interrupt yet, on pipe
519724a6905SVille Syrjälä 	 * A the same bit is for perf counters which we don't use either.
520724a6905SVille Syrjälä 	 */
52148a1b8d4SPankaj Bharadiya 	if (drm_WARN_ON_ONCE(&dev_priv->drm,
52248a1b8d4SPankaj Bharadiya 			     status_mask & PIPE_B_PSR_STATUS_VLV))
523724a6905SVille Syrjälä 		return 0;
52410c59c51SImre Deak 
52510c59c51SImre Deak 	enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
52610c59c51SImre Deak 			 SPRITE0_FLIP_DONE_INT_EN_VLV |
52710c59c51SImre Deak 			 SPRITE1_FLIP_DONE_INT_EN_VLV);
52810c59c51SImre Deak 	if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
52910c59c51SImre Deak 		enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
53010c59c51SImre Deak 	if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
53110c59c51SImre Deak 		enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
53210c59c51SImre Deak 
5336b12ca56SVille Syrjälä out:
53448a1b8d4SPankaj Bharadiya 	drm_WARN_ONCE(&dev_priv->drm,
53548a1b8d4SPankaj Bharadiya 		      enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
5366b12ca56SVille Syrjälä 		      status_mask & ~PIPESTAT_INT_STATUS_MASK,
5376b12ca56SVille Syrjälä 		      "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
5386b12ca56SVille Syrjälä 		      pipe_name(pipe), enable_mask, status_mask);
5396b12ca56SVille Syrjälä 
54010c59c51SImre Deak 	return enable_mask;
54110c59c51SImre Deak }
54210c59c51SImre Deak 
5436b12ca56SVille Syrjälä void i915_enable_pipestat(struct drm_i915_private *dev_priv,
5446b12ca56SVille Syrjälä 			  enum pipe pipe, u32 status_mask)
545755e9019SImre Deak {
5466b12ca56SVille Syrjälä 	i915_reg_t reg = PIPESTAT(pipe);
547755e9019SImre Deak 	u32 enable_mask;
548755e9019SImre Deak 
54948a1b8d4SPankaj Bharadiya 	drm_WARN_ONCE(&dev_priv->drm, status_mask & ~PIPESTAT_INT_STATUS_MASK,
5506b12ca56SVille Syrjälä 		      "pipe %c: status_mask=0x%x\n",
5516b12ca56SVille Syrjälä 		      pipe_name(pipe), status_mask);
5526b12ca56SVille Syrjälä 
5536b12ca56SVille Syrjälä 	lockdep_assert_held(&dev_priv->irq_lock);
55448a1b8d4SPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv));
5556b12ca56SVille Syrjälä 
5566b12ca56SVille Syrjälä 	if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == status_mask)
5576b12ca56SVille Syrjälä 		return;
5586b12ca56SVille Syrjälä 
5596b12ca56SVille Syrjälä 	dev_priv->pipestat_irq_mask[pipe] |= status_mask;
5606b12ca56SVille Syrjälä 	enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
5616b12ca56SVille Syrjälä 
5622939eb06SJani Nikula 	intel_uncore_write(&dev_priv->uncore, reg, enable_mask | status_mask);
5632939eb06SJani Nikula 	intel_uncore_posting_read(&dev_priv->uncore, reg);
564755e9019SImre Deak }
565755e9019SImre Deak 
5666b12ca56SVille Syrjälä void i915_disable_pipestat(struct drm_i915_private *dev_priv,
5676b12ca56SVille Syrjälä 			   enum pipe pipe, u32 status_mask)
568755e9019SImre Deak {
5696b12ca56SVille Syrjälä 	i915_reg_t reg = PIPESTAT(pipe);
570755e9019SImre Deak 	u32 enable_mask;
571755e9019SImre Deak 
57248a1b8d4SPankaj Bharadiya 	drm_WARN_ONCE(&dev_priv->drm, status_mask & ~PIPESTAT_INT_STATUS_MASK,
5736b12ca56SVille Syrjälä 		      "pipe %c: status_mask=0x%x\n",
5746b12ca56SVille Syrjälä 		      pipe_name(pipe), status_mask);
5756b12ca56SVille Syrjälä 
5766b12ca56SVille Syrjälä 	lockdep_assert_held(&dev_priv->irq_lock);
57748a1b8d4SPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv));
5786b12ca56SVille Syrjälä 
5796b12ca56SVille Syrjälä 	if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == 0)
5806b12ca56SVille Syrjälä 		return;
5816b12ca56SVille Syrjälä 
5826b12ca56SVille Syrjälä 	dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
5836b12ca56SVille Syrjälä 	enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
5846b12ca56SVille Syrjälä 
5852939eb06SJani Nikula 	intel_uncore_write(&dev_priv->uncore, reg, enable_mask | status_mask);
5862939eb06SJani Nikula 	intel_uncore_posting_read(&dev_priv->uncore, reg);
587755e9019SImre Deak }
588755e9019SImre Deak 
589f3e30485SVille Syrjälä static bool i915_has_asle(struct drm_i915_private *dev_priv)
590f3e30485SVille Syrjälä {
5917249dfcbSJani Nikula 	if (!dev_priv->display.opregion.asle)
592f3e30485SVille Syrjälä 		return false;
593f3e30485SVille Syrjälä 
594f3e30485SVille Syrjälä 	return IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
595f3e30485SVille Syrjälä }
596f3e30485SVille Syrjälä 
597c0e09200SDave Airlie /**
598f49e38ddSJani Nikula  * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
59914bb2c11STvrtko Ursulin  * @dev_priv: i915 device private
60001c66889SZhao Yakui  */
60191d14251STvrtko Ursulin static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv)
60201c66889SZhao Yakui {
603f3e30485SVille Syrjälä 	if (!i915_has_asle(dev_priv))
604f49e38ddSJani Nikula 		return;
605f49e38ddSJani Nikula 
60613321786SDaniel Vetter 	spin_lock_irq(&dev_priv->irq_lock);
60701c66889SZhao Yakui 
608755e9019SImre Deak 	i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
609373abf1aSMatt Roper 	if (DISPLAY_VER(dev_priv) >= 4)
6103b6c42e8SDaniel Vetter 		i915_enable_pipestat(dev_priv, PIPE_A,
611755e9019SImre Deak 				     PIPE_LEGACY_BLC_EVENT_STATUS);
6121ec14ad3SChris Wilson 
61313321786SDaniel Vetter 	spin_unlock_irq(&dev_priv->irq_lock);
61401c66889SZhao Yakui }
61501c66889SZhao Yakui 
616e3689190SBen Widawsky /**
61774bb98baSLucas De Marchi  * ivb_parity_work - Workqueue called when a parity error interrupt
618e3689190SBen Widawsky  * occurred.
619e3689190SBen Widawsky  * @work: workqueue struct
620e3689190SBen Widawsky  *
621e3689190SBen Widawsky  * Doesn't actually do anything except notify userspace. As a consequence of
622e3689190SBen Widawsky  * this event, userspace should try to remap the bad rows since statistically
623e3689190SBen Widawsky  * it is likely the same row is more likely to go bad again.
624e3689190SBen Widawsky  */
62574bb98baSLucas De Marchi static void ivb_parity_work(struct work_struct *work)
626e3689190SBen Widawsky {
6272d1013ddSJani Nikula 	struct drm_i915_private *dev_priv =
628cefcff8fSJoonas Lahtinen 		container_of(work, typeof(*dev_priv), l3_parity.error_work);
6292cbc876dSMichał Winiarski 	struct intel_gt *gt = to_gt(dev_priv);
630e3689190SBen Widawsky 	u32 error_status, row, bank, subbank;
63135a85ac6SBen Widawsky 	char *parity_event[6];
632a9c287c9SJani Nikula 	u32 misccpctl;
633a9c287c9SJani Nikula 	u8 slice = 0;
634e3689190SBen Widawsky 
635e3689190SBen Widawsky 	/* We must turn off DOP level clock gating to access the L3 registers.
636e3689190SBen Widawsky 	 * In order to prevent a get/put style interface, acquire struct mutex
637e3689190SBen Widawsky 	 * any time we access those registers.
638e3689190SBen Widawsky 	 */
63991c8a326SChris Wilson 	mutex_lock(&dev_priv->drm.struct_mutex);
640e3689190SBen Widawsky 
64135a85ac6SBen Widawsky 	/* If we've screwed up tracking, just let the interrupt fire again */
64248a1b8d4SPankaj Bharadiya 	if (drm_WARN_ON(&dev_priv->drm, !dev_priv->l3_parity.which_slice))
64335a85ac6SBen Widawsky 		goto out;
64435a85ac6SBen Widawsky 
645f7435467SAndrzej Hajda 	misccpctl = intel_uncore_rmw(&dev_priv->uncore, GEN7_MISCCPCTL,
646f7435467SAndrzej Hajda 				     GEN7_DOP_CLOCK_GATE_ENABLE, 0);
6472939eb06SJani Nikula 	intel_uncore_posting_read(&dev_priv->uncore, GEN7_MISCCPCTL);
648e3689190SBen Widawsky 
64935a85ac6SBen Widawsky 	while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
650f0f59a00SVille Syrjälä 		i915_reg_t reg;
65135a85ac6SBen Widawsky 
65235a85ac6SBen Widawsky 		slice--;
65348a1b8d4SPankaj Bharadiya 		if (drm_WARN_ON_ONCE(&dev_priv->drm,
65448a1b8d4SPankaj Bharadiya 				     slice >= NUM_L3_SLICES(dev_priv)))
65535a85ac6SBen Widawsky 			break;
65635a85ac6SBen Widawsky 
65735a85ac6SBen Widawsky 		dev_priv->l3_parity.which_slice &= ~(1<<slice);
65835a85ac6SBen Widawsky 
6596fa1c5f1SVille Syrjälä 		reg = GEN7_L3CDERRST1(slice);
66035a85ac6SBen Widawsky 
6612939eb06SJani Nikula 		error_status = intel_uncore_read(&dev_priv->uncore, reg);
662e3689190SBen Widawsky 		row = GEN7_PARITY_ERROR_ROW(error_status);
663e3689190SBen Widawsky 		bank = GEN7_PARITY_ERROR_BANK(error_status);
664e3689190SBen Widawsky 		subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
665e3689190SBen Widawsky 
6662939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
6672939eb06SJani Nikula 		intel_uncore_posting_read(&dev_priv->uncore, reg);
668e3689190SBen Widawsky 
669cce723edSBen Widawsky 		parity_event[0] = I915_L3_PARITY_UEVENT "=1";
670e3689190SBen Widawsky 		parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
671e3689190SBen Widawsky 		parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
672e3689190SBen Widawsky 		parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
67335a85ac6SBen Widawsky 		parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
67435a85ac6SBen Widawsky 		parity_event[5] = NULL;
675e3689190SBen Widawsky 
67691c8a326SChris Wilson 		kobject_uevent_env(&dev_priv->drm.primary->kdev->kobj,
677e3689190SBen Widawsky 				   KOBJ_CHANGE, parity_event);
678e3689190SBen Widawsky 
679a10234fdSTvrtko Ursulin 		drm_dbg(&dev_priv->drm,
680a10234fdSTvrtko Ursulin 			"Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
68135a85ac6SBen Widawsky 			slice, row, bank, subbank);
682e3689190SBen Widawsky 
68335a85ac6SBen Widawsky 		kfree(parity_event[4]);
684e3689190SBen Widawsky 		kfree(parity_event[3]);
685e3689190SBen Widawsky 		kfree(parity_event[2]);
686e3689190SBen Widawsky 		kfree(parity_event[1]);
687e3689190SBen Widawsky 	}
688e3689190SBen Widawsky 
6892939eb06SJani Nikula 	intel_uncore_write(&dev_priv->uncore, GEN7_MISCCPCTL, misccpctl);
69035a85ac6SBen Widawsky 
69135a85ac6SBen Widawsky out:
69248a1b8d4SPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm, dev_priv->l3_parity.which_slice);
69303d2c54dSMatt Roper 	spin_lock_irq(gt->irq_lock);
694cf1c97dcSAndi Shyti 	gen5_gt_enable_irq(gt, GT_PARITY_ERROR(dev_priv));
69503d2c54dSMatt Roper 	spin_unlock_irq(gt->irq_lock);
69635a85ac6SBen Widawsky 
69791c8a326SChris Wilson 	mutex_unlock(&dev_priv->drm.struct_mutex);
69835a85ac6SBen Widawsky }
69935a85ac6SBen Widawsky 
700af92058fSVille Syrjälä static bool gen11_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
701121e758eSDhinakaran Pandiyan {
702af92058fSVille Syrjälä 	switch (pin) {
703da51e4baSVille Syrjälä 	case HPD_PORT_TC1:
704da51e4baSVille Syrjälä 	case HPD_PORT_TC2:
705da51e4baSVille Syrjälä 	case HPD_PORT_TC3:
706da51e4baSVille Syrjälä 	case HPD_PORT_TC4:
707da51e4baSVille Syrjälä 	case HPD_PORT_TC5:
708da51e4baSVille Syrjälä 	case HPD_PORT_TC6:
7094294fa5fSVille Syrjälä 		return val & GEN11_HOTPLUG_CTL_LONG_DETECT(pin);
71048ef15d3SJosé Roberto de Souza 	default:
71148ef15d3SJosé Roberto de Souza 		return false;
71248ef15d3SJosé Roberto de Souza 	}
71348ef15d3SJosé Roberto de Souza }
71448ef15d3SJosé Roberto de Souza 
715af92058fSVille Syrjälä static bool bxt_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
71663c88d22SImre Deak {
717af92058fSVille Syrjälä 	switch (pin) {
718af92058fSVille Syrjälä 	case HPD_PORT_A:
719195baa06SVille Syrjälä 		return val & PORTA_HOTPLUG_LONG_DETECT;
720af92058fSVille Syrjälä 	case HPD_PORT_B:
72163c88d22SImre Deak 		return val & PORTB_HOTPLUG_LONG_DETECT;
722af92058fSVille Syrjälä 	case HPD_PORT_C:
72363c88d22SImre Deak 		return val & PORTC_HOTPLUG_LONG_DETECT;
72463c88d22SImre Deak 	default:
72563c88d22SImre Deak 		return false;
72663c88d22SImre Deak 	}
72763c88d22SImre Deak }
72863c88d22SImre Deak 
729af92058fSVille Syrjälä static bool icp_ddi_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
73031604222SAnusha Srivatsa {
731af92058fSVille Syrjälä 	switch (pin) {
732af92058fSVille Syrjälä 	case HPD_PORT_A:
733af92058fSVille Syrjälä 	case HPD_PORT_B:
7348ef7e340SMatt Roper 	case HPD_PORT_C:
735229f31e2SLucas De Marchi 	case HPD_PORT_D:
7364294fa5fSVille Syrjälä 		return val & SHOTPLUG_CTL_DDI_HPD_LONG_DETECT(pin);
73731604222SAnusha Srivatsa 	default:
73831604222SAnusha Srivatsa 		return false;
73931604222SAnusha Srivatsa 	}
74031604222SAnusha Srivatsa }
74131604222SAnusha Srivatsa 
742af92058fSVille Syrjälä static bool icp_tc_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
74331604222SAnusha Srivatsa {
744af92058fSVille Syrjälä 	switch (pin) {
745da51e4baSVille Syrjälä 	case HPD_PORT_TC1:
746da51e4baSVille Syrjälä 	case HPD_PORT_TC2:
747da51e4baSVille Syrjälä 	case HPD_PORT_TC3:
748da51e4baSVille Syrjälä 	case HPD_PORT_TC4:
749da51e4baSVille Syrjälä 	case HPD_PORT_TC5:
750da51e4baSVille Syrjälä 	case HPD_PORT_TC6:
7514294fa5fSVille Syrjälä 		return val & ICP_TC_HPD_LONG_DETECT(pin);
75252dfdba0SLucas De Marchi 	default:
75352dfdba0SLucas De Marchi 		return false;
75452dfdba0SLucas De Marchi 	}
75552dfdba0SLucas De Marchi }
75652dfdba0SLucas De Marchi 
757af92058fSVille Syrjälä static bool spt_port_hotplug2_long_detect(enum hpd_pin pin, u32 val)
7586dbf30ceSVille Syrjälä {
759af92058fSVille Syrjälä 	switch (pin) {
760af92058fSVille Syrjälä 	case HPD_PORT_E:
7616dbf30ceSVille Syrjälä 		return val & PORTE_HOTPLUG_LONG_DETECT;
7626dbf30ceSVille Syrjälä 	default:
7636dbf30ceSVille Syrjälä 		return false;
7646dbf30ceSVille Syrjälä 	}
7656dbf30ceSVille Syrjälä }
7666dbf30ceSVille Syrjälä 
767af92058fSVille Syrjälä static bool spt_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
76874c0b395SVille Syrjälä {
769af92058fSVille Syrjälä 	switch (pin) {
770af92058fSVille Syrjälä 	case HPD_PORT_A:
77174c0b395SVille Syrjälä 		return val & PORTA_HOTPLUG_LONG_DETECT;
772af92058fSVille Syrjälä 	case HPD_PORT_B:
77374c0b395SVille Syrjälä 		return val & PORTB_HOTPLUG_LONG_DETECT;
774af92058fSVille Syrjälä 	case HPD_PORT_C:
77574c0b395SVille Syrjälä 		return val & PORTC_HOTPLUG_LONG_DETECT;
776af92058fSVille Syrjälä 	case HPD_PORT_D:
77774c0b395SVille Syrjälä 		return val & PORTD_HOTPLUG_LONG_DETECT;
77874c0b395SVille Syrjälä 	default:
77974c0b395SVille Syrjälä 		return false;
78074c0b395SVille Syrjälä 	}
78174c0b395SVille Syrjälä }
78274c0b395SVille Syrjälä 
783af92058fSVille Syrjälä static bool ilk_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
784e4ce95aaSVille Syrjälä {
785af92058fSVille Syrjälä 	switch (pin) {
786af92058fSVille Syrjälä 	case HPD_PORT_A:
787e4ce95aaSVille Syrjälä 		return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
788e4ce95aaSVille Syrjälä 	default:
789e4ce95aaSVille Syrjälä 		return false;
790e4ce95aaSVille Syrjälä 	}
791e4ce95aaSVille Syrjälä }
792e4ce95aaSVille Syrjälä 
793af92058fSVille Syrjälä static bool pch_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
79413cf5504SDave Airlie {
795af92058fSVille Syrjälä 	switch (pin) {
796af92058fSVille Syrjälä 	case HPD_PORT_B:
797676574dfSJani Nikula 		return val & PORTB_HOTPLUG_LONG_DETECT;
798af92058fSVille Syrjälä 	case HPD_PORT_C:
799676574dfSJani Nikula 		return val & PORTC_HOTPLUG_LONG_DETECT;
800af92058fSVille Syrjälä 	case HPD_PORT_D:
801676574dfSJani Nikula 		return val & PORTD_HOTPLUG_LONG_DETECT;
802676574dfSJani Nikula 	default:
803676574dfSJani Nikula 		return false;
80413cf5504SDave Airlie 	}
80513cf5504SDave Airlie }
80613cf5504SDave Airlie 
807af92058fSVille Syrjälä static bool i9xx_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
80813cf5504SDave Airlie {
809af92058fSVille Syrjälä 	switch (pin) {
810af92058fSVille Syrjälä 	case HPD_PORT_B:
811676574dfSJani Nikula 		return val & PORTB_HOTPLUG_INT_LONG_PULSE;
812af92058fSVille Syrjälä 	case HPD_PORT_C:
813676574dfSJani Nikula 		return val & PORTC_HOTPLUG_INT_LONG_PULSE;
814af92058fSVille Syrjälä 	case HPD_PORT_D:
815676574dfSJani Nikula 		return val & PORTD_HOTPLUG_INT_LONG_PULSE;
816676574dfSJani Nikula 	default:
817676574dfSJani Nikula 		return false;
81813cf5504SDave Airlie 	}
81913cf5504SDave Airlie }
82013cf5504SDave Airlie 
82142db67d6SVille Syrjälä /*
82242db67d6SVille Syrjälä  * Get a bit mask of pins that have triggered, and which ones may be long.
82342db67d6SVille Syrjälä  * This can be called multiple times with the same masks to accumulate
82442db67d6SVille Syrjälä  * hotplug detection results from several registers.
82542db67d6SVille Syrjälä  *
82642db67d6SVille Syrjälä  * Note that the caller is expected to zero out the masks initially.
82742db67d6SVille Syrjälä  */
828cf53902fSRodrigo Vivi static void intel_get_hpd_pins(struct drm_i915_private *dev_priv,
829cf53902fSRodrigo Vivi 			       u32 *pin_mask, u32 *long_mask,
8308c841e57SJani Nikula 			       u32 hotplug_trigger, u32 dig_hotplug_reg,
831fd63e2a9SImre Deak 			       const u32 hpd[HPD_NUM_PINS],
832af92058fSVille Syrjälä 			       bool long_pulse_detect(enum hpd_pin pin, u32 val))
833676574dfSJani Nikula {
834e9be2850SVille Syrjälä 	enum hpd_pin pin;
835676574dfSJani Nikula 
83652dfdba0SLucas De Marchi 	BUILD_BUG_ON(BITS_PER_TYPE(*pin_mask) < HPD_NUM_PINS);
83752dfdba0SLucas De Marchi 
838e9be2850SVille Syrjälä 	for_each_hpd_pin(pin) {
839e9be2850SVille Syrjälä 		if ((hpd[pin] & hotplug_trigger) == 0)
8408c841e57SJani Nikula 			continue;
8418c841e57SJani Nikula 
842e9be2850SVille Syrjälä 		*pin_mask |= BIT(pin);
843676574dfSJani Nikula 
844af92058fSVille Syrjälä 		if (long_pulse_detect(pin, dig_hotplug_reg))
845e9be2850SVille Syrjälä 			*long_mask |= BIT(pin);
846676574dfSJani Nikula 	}
847676574dfSJani Nikula 
84800376ccfSWambui Karuga 	drm_dbg(&dev_priv->drm,
84900376ccfSWambui Karuga 		"hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x, long 0x%08x\n",
850f88f0478SVille Syrjälä 		hotplug_trigger, dig_hotplug_reg, *pin_mask, *long_mask);
851676574dfSJani Nikula 
852676574dfSJani Nikula }
853676574dfSJani Nikula 
854a0e066b8SVille Syrjälä static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
855a0e066b8SVille Syrjälä 				  const u32 hpd[HPD_NUM_PINS])
856a0e066b8SVille Syrjälä {
857a0e066b8SVille Syrjälä 	struct intel_encoder *encoder;
858a0e066b8SVille Syrjälä 	u32 enabled_irqs = 0;
859a0e066b8SVille Syrjälä 
860a0e066b8SVille Syrjälä 	for_each_intel_encoder(&dev_priv->drm, encoder)
8615a4dd6f0SJani Nikula 		if (dev_priv->display.hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
862a0e066b8SVille Syrjälä 			enabled_irqs |= hpd[encoder->hpd_pin];
863a0e066b8SVille Syrjälä 
864a0e066b8SVille Syrjälä 	return enabled_irqs;
865a0e066b8SVille Syrjälä }
866a0e066b8SVille Syrjälä 
867a0e066b8SVille Syrjälä static u32 intel_hpd_hotplug_irqs(struct drm_i915_private *dev_priv,
868a0e066b8SVille Syrjälä 				  const u32 hpd[HPD_NUM_PINS])
869a0e066b8SVille Syrjälä {
870a0e066b8SVille Syrjälä 	struct intel_encoder *encoder;
871a0e066b8SVille Syrjälä 	u32 hotplug_irqs = 0;
872a0e066b8SVille Syrjälä 
873a0e066b8SVille Syrjälä 	for_each_intel_encoder(&dev_priv->drm, encoder)
874a0e066b8SVille Syrjälä 		hotplug_irqs |= hpd[encoder->hpd_pin];
875a0e066b8SVille Syrjälä 
876a0e066b8SVille Syrjälä 	return hotplug_irqs;
877a0e066b8SVille Syrjälä }
878a0e066b8SVille Syrjälä 
8792ea63927SVille Syrjälä static u32 intel_hpd_hotplug_enables(struct drm_i915_private *i915,
8802ea63927SVille Syrjälä 				     hotplug_enables_func hotplug_enables)
8812ea63927SVille Syrjälä {
8822ea63927SVille Syrjälä 	struct intel_encoder *encoder;
8832ea63927SVille Syrjälä 	u32 hotplug = 0;
8842ea63927SVille Syrjälä 
8852ea63927SVille Syrjälä 	for_each_intel_encoder(&i915->drm, encoder)
886dfefe7bcSVille Syrjälä 		hotplug |= hotplug_enables(encoder);
8872ea63927SVille Syrjälä 
8882ea63927SVille Syrjälä 	return hotplug;
8892ea63927SVille Syrjälä }
8902ea63927SVille Syrjälä 
89191d14251STvrtko Ursulin static void gmbus_irq_handler(struct drm_i915_private *dev_priv)
892515ac2bbSDaniel Vetter {
893203eb5a9SJani Nikula 	wake_up_all(&dev_priv->display.gmbus.wait_queue);
894515ac2bbSDaniel Vetter }
895515ac2bbSDaniel Vetter 
89691d14251STvrtko Ursulin static void dp_aux_irq_handler(struct drm_i915_private *dev_priv)
897ce99c256SDaniel Vetter {
898203eb5a9SJani Nikula 	wake_up_all(&dev_priv->display.gmbus.wait_queue);
899ce99c256SDaniel Vetter }
900ce99c256SDaniel Vetter 
9018bf1e9f1SShuang He #if defined(CONFIG_DEBUG_FS)
90291d14251STvrtko Ursulin static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
90391d14251STvrtko Ursulin 					 enum pipe pipe,
904a9c287c9SJani Nikula 					 u32 crc0, u32 crc1,
905a9c287c9SJani Nikula 					 u32 crc2, u32 crc3,
906a9c287c9SJani Nikula 					 u32 crc4)
9078bf1e9f1SShuang He {
9087794b6deSJani Nikula 	struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
90900535527SJani Nikula 	struct intel_pipe_crc *pipe_crc = &crtc->pipe_crc;
9105cee6c45SVille Syrjälä 	u32 crcs[5] = { crc0, crc1, crc2, crc3, crc4 };
9115cee6c45SVille Syrjälä 
9125cee6c45SVille Syrjälä 	trace_intel_pipe_crc(crtc, crcs);
913b2c88f5bSDamien Lespiau 
914d538bbdfSDamien Lespiau 	spin_lock(&pipe_crc->lock);
9158c6b709dSTomeu Vizoso 	/*
9168c6b709dSTomeu Vizoso 	 * For some not yet identified reason, the first CRC is
9178c6b709dSTomeu Vizoso 	 * bonkers. So let's just wait for the next vblank and read
9188c6b709dSTomeu Vizoso 	 * out the buggy result.
9198c6b709dSTomeu Vizoso 	 *
920163e8aecSRodrigo Vivi 	 * On GEN8+ sometimes the second CRC is bonkers as well, so
9218c6b709dSTomeu Vizoso 	 * don't trust that one either.
9228c6b709dSTomeu Vizoso 	 */
923033b7a23SMaarten Lankhorst 	if (pipe_crc->skipped <= 0 ||
924373abf1aSMatt Roper 	    (DISPLAY_VER(dev_priv) >= 8 && pipe_crc->skipped == 1)) {
9258c6b709dSTomeu Vizoso 		pipe_crc->skipped++;
9268c6b709dSTomeu Vizoso 		spin_unlock(&pipe_crc->lock);
9278c6b709dSTomeu Vizoso 		return;
9288c6b709dSTomeu Vizoso 	}
9298c6b709dSTomeu Vizoso 	spin_unlock(&pipe_crc->lock);
9306cc42152SMaarten Lankhorst 
931246ee524STomeu Vizoso 	drm_crtc_add_crc_entry(&crtc->base, true,
932ca814b25SDaniel Vetter 				drm_crtc_accurate_vblank_count(&crtc->base),
933246ee524STomeu Vizoso 				crcs);
9348c6b709dSTomeu Vizoso }
935277de95eSDaniel Vetter #else
936277de95eSDaniel Vetter static inline void
93791d14251STvrtko Ursulin display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
93891d14251STvrtko Ursulin 			     enum pipe pipe,
939a9c287c9SJani Nikula 			     u32 crc0, u32 crc1,
940a9c287c9SJani Nikula 			     u32 crc2, u32 crc3,
941a9c287c9SJani Nikula 			     u32 crc4) {}
942277de95eSDaniel Vetter #endif
943eba94eb9SDaniel Vetter 
9441288f9b0SKarthik B S static void flip_done_handler(struct drm_i915_private *i915,
9451288f9b0SKarthik B S 			      enum pipe pipe)
9461288f9b0SKarthik B S {
9477794b6deSJani Nikula 	struct intel_crtc *crtc = intel_crtc_for_pipe(i915, pipe);
9481288f9b0SKarthik B S 	struct drm_crtc_state *crtc_state = crtc->base.state;
9491288f9b0SKarthik B S 	struct drm_pending_vblank_event *e = crtc_state->event;
9501288f9b0SKarthik B S 	struct drm_device *dev = &i915->drm;
9511288f9b0SKarthik B S 	unsigned long irqflags;
9521288f9b0SKarthik B S 
9531288f9b0SKarthik B S 	spin_lock_irqsave(&dev->event_lock, irqflags);
9541288f9b0SKarthik B S 
9551288f9b0SKarthik B S 	crtc_state->event = NULL;
9561288f9b0SKarthik B S 
9571288f9b0SKarthik B S 	drm_crtc_send_vblank_event(&crtc->base, e);
9581288f9b0SKarthik B S 
9591288f9b0SKarthik B S 	spin_unlock_irqrestore(&dev->event_lock, irqflags);
9601288f9b0SKarthik B S }
961277de95eSDaniel Vetter 
96291d14251STvrtko Ursulin static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
96391d14251STvrtko Ursulin 				     enum pipe pipe)
9645a69b89fSDaniel Vetter {
96591d14251STvrtko Ursulin 	display_pipe_crc_irq_handler(dev_priv, pipe,
9662939eb06SJani Nikula 				     intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_1_IVB(pipe)),
9675a69b89fSDaniel Vetter 				     0, 0, 0, 0);
9685a69b89fSDaniel Vetter }
9695a69b89fSDaniel Vetter 
97091d14251STvrtko Ursulin static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
97191d14251STvrtko Ursulin 				     enum pipe pipe)
972eba94eb9SDaniel Vetter {
97391d14251STvrtko Ursulin 	display_pipe_crc_irq_handler(dev_priv, pipe,
9742939eb06SJani Nikula 				     intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_1_IVB(pipe)),
9752939eb06SJani Nikula 				     intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_2_IVB(pipe)),
9762939eb06SJani Nikula 				     intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_3_IVB(pipe)),
9772939eb06SJani Nikula 				     intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_4_IVB(pipe)),
9782939eb06SJani Nikula 				     intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_5_IVB(pipe)));
979eba94eb9SDaniel Vetter }
9805b3a856bSDaniel Vetter 
98191d14251STvrtko Ursulin static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
98291d14251STvrtko Ursulin 				      enum pipe pipe)
9835b3a856bSDaniel Vetter {
984a9c287c9SJani Nikula 	u32 res1, res2;
9850b5c5ed0SDaniel Vetter 
986373abf1aSMatt Roper 	if (DISPLAY_VER(dev_priv) >= 3)
9872939eb06SJani Nikula 		res1 = intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_RES1_I915(pipe));
9880b5c5ed0SDaniel Vetter 	else
9890b5c5ed0SDaniel Vetter 		res1 = 0;
9900b5c5ed0SDaniel Vetter 
991373abf1aSMatt Roper 	if (DISPLAY_VER(dev_priv) >= 5 || IS_G4X(dev_priv))
9922939eb06SJani Nikula 		res2 = intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_RES2_G4X(pipe));
9930b5c5ed0SDaniel Vetter 	else
9940b5c5ed0SDaniel Vetter 		res2 = 0;
9955b3a856bSDaniel Vetter 
99691d14251STvrtko Ursulin 	display_pipe_crc_irq_handler(dev_priv, pipe,
9972939eb06SJani Nikula 				     intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_RED(pipe)),
9982939eb06SJani Nikula 				     intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_GREEN(pipe)),
9992939eb06SJani Nikula 				     intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_BLUE(pipe)),
10000b5c5ed0SDaniel Vetter 				     res1, res2);
10015b3a856bSDaniel Vetter }
10028bf1e9f1SShuang He 
100344d9241eSVille Syrjälä static void i9xx_pipestat_irq_reset(struct drm_i915_private *dev_priv)
100444d9241eSVille Syrjälä {
100544d9241eSVille Syrjälä 	enum pipe pipe;
100644d9241eSVille Syrjälä 
100744d9241eSVille Syrjälä 	for_each_pipe(dev_priv, pipe) {
10082939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, PIPESTAT(pipe),
100944d9241eSVille Syrjälä 			   PIPESTAT_INT_STATUS_MASK |
101044d9241eSVille Syrjälä 			   PIPE_FIFO_UNDERRUN_STATUS);
101144d9241eSVille Syrjälä 
101244d9241eSVille Syrjälä 		dev_priv->pipestat_irq_mask[pipe] = 0;
101344d9241eSVille Syrjälä 	}
101444d9241eSVille Syrjälä }
101544d9241eSVille Syrjälä 
1016eb64343cSVille Syrjälä static void i9xx_pipestat_irq_ack(struct drm_i915_private *dev_priv,
101791d14251STvrtko Ursulin 				  u32 iir, u32 pipe_stats[I915_MAX_PIPES])
10187e231dbeSJesse Barnes {
1019d048a268SVille Syrjälä 	enum pipe pipe;
10207e231dbeSJesse Barnes 
102158ead0d7SImre Deak 	spin_lock(&dev_priv->irq_lock);
10221ca993d2SVille Syrjälä 
10231ca993d2SVille Syrjälä 	if (!dev_priv->display_irqs_enabled) {
10241ca993d2SVille Syrjälä 		spin_unlock(&dev_priv->irq_lock);
10251ca993d2SVille Syrjälä 		return;
10261ca993d2SVille Syrjälä 	}
10271ca993d2SVille Syrjälä 
1028055e393fSDamien Lespiau 	for_each_pipe(dev_priv, pipe) {
1029f0f59a00SVille Syrjälä 		i915_reg_t reg;
10306b12ca56SVille Syrjälä 		u32 status_mask, enable_mask, iir_bit = 0;
103191d181ddSImre Deak 
1032bbb5eebfSDaniel Vetter 		/*
1033bbb5eebfSDaniel Vetter 		 * PIPESTAT bits get signalled even when the interrupt is
1034bbb5eebfSDaniel Vetter 		 * disabled with the mask bits, and some of the status bits do
1035bbb5eebfSDaniel Vetter 		 * not generate interrupts at all (like the underrun bit). Hence
1036bbb5eebfSDaniel Vetter 		 * we need to be careful that we only handle what we want to
1037bbb5eebfSDaniel Vetter 		 * handle.
1038bbb5eebfSDaniel Vetter 		 */
10390f239f4cSDaniel Vetter 
10400f239f4cSDaniel Vetter 		/* fifo underruns are filterered in the underrun handler. */
10416b12ca56SVille Syrjälä 		status_mask = PIPE_FIFO_UNDERRUN_STATUS;
1042bbb5eebfSDaniel Vetter 
1043bbb5eebfSDaniel Vetter 		switch (pipe) {
1044d048a268SVille Syrjälä 		default:
1045bbb5eebfSDaniel Vetter 		case PIPE_A:
1046bbb5eebfSDaniel Vetter 			iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1047bbb5eebfSDaniel Vetter 			break;
1048bbb5eebfSDaniel Vetter 		case PIPE_B:
1049bbb5eebfSDaniel Vetter 			iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1050bbb5eebfSDaniel Vetter 			break;
10513278f67fSVille Syrjälä 		case PIPE_C:
10523278f67fSVille Syrjälä 			iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
10533278f67fSVille Syrjälä 			break;
1054bbb5eebfSDaniel Vetter 		}
1055bbb5eebfSDaniel Vetter 		if (iir & iir_bit)
10566b12ca56SVille Syrjälä 			status_mask |= dev_priv->pipestat_irq_mask[pipe];
1057bbb5eebfSDaniel Vetter 
10586b12ca56SVille Syrjälä 		if (!status_mask)
105991d181ddSImre Deak 			continue;
106091d181ddSImre Deak 
106191d181ddSImre Deak 		reg = PIPESTAT(pipe);
10622939eb06SJani Nikula 		pipe_stats[pipe] = intel_uncore_read(&dev_priv->uncore, reg) & status_mask;
10636b12ca56SVille Syrjälä 		enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
10647e231dbeSJesse Barnes 
10657e231dbeSJesse Barnes 		/*
10667e231dbeSJesse Barnes 		 * Clear the PIPE*STAT regs before the IIR
1067132c27c9SVille Syrjälä 		 *
1068132c27c9SVille Syrjälä 		 * Toggle the enable bits to make sure we get an
1069132c27c9SVille Syrjälä 		 * edge in the ISR pipe event bit if we don't clear
1070132c27c9SVille Syrjälä 		 * all the enabled status bits. Otherwise the edge
1071132c27c9SVille Syrjälä 		 * triggered IIR on i965/g4x wouldn't notice that
1072132c27c9SVille Syrjälä 		 * an interrupt is still pending.
10737e231dbeSJesse Barnes 		 */
1074132c27c9SVille Syrjälä 		if (pipe_stats[pipe]) {
10752939eb06SJani Nikula 			intel_uncore_write(&dev_priv->uncore, reg, pipe_stats[pipe]);
10762939eb06SJani Nikula 			intel_uncore_write(&dev_priv->uncore, reg, enable_mask);
1077132c27c9SVille Syrjälä 		}
10787e231dbeSJesse Barnes 	}
107958ead0d7SImre Deak 	spin_unlock(&dev_priv->irq_lock);
10802ecb8ca4SVille Syrjälä }
10812ecb8ca4SVille Syrjälä 
1082eb64343cSVille Syrjälä static void i8xx_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1083eb64343cSVille Syrjälä 				      u16 iir, u32 pipe_stats[I915_MAX_PIPES])
1084eb64343cSVille Syrjälä {
1085eb64343cSVille Syrjälä 	enum pipe pipe;
1086eb64343cSVille Syrjälä 
1087eb64343cSVille Syrjälä 	for_each_pipe(dev_priv, pipe) {
1088eb64343cSVille Syrjälä 		if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1089aca9310aSAnshuman Gupta 			intel_handle_vblank(dev_priv, pipe);
1090eb64343cSVille Syrjälä 
1091eb64343cSVille Syrjälä 		if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1092eb64343cSVille Syrjälä 			i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1093eb64343cSVille Syrjälä 
1094eb64343cSVille Syrjälä 		if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1095eb64343cSVille Syrjälä 			intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1096eb64343cSVille Syrjälä 	}
1097eb64343cSVille Syrjälä }
1098eb64343cSVille Syrjälä 
1099eb64343cSVille Syrjälä static void i915_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1100eb64343cSVille Syrjälä 				      u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1101eb64343cSVille Syrjälä {
1102eb64343cSVille Syrjälä 	bool blc_event = false;
1103eb64343cSVille Syrjälä 	enum pipe pipe;
1104eb64343cSVille Syrjälä 
1105eb64343cSVille Syrjälä 	for_each_pipe(dev_priv, pipe) {
1106eb64343cSVille Syrjälä 		if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1107aca9310aSAnshuman Gupta 			intel_handle_vblank(dev_priv, pipe);
1108eb64343cSVille Syrjälä 
1109eb64343cSVille Syrjälä 		if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1110eb64343cSVille Syrjälä 			blc_event = true;
1111eb64343cSVille Syrjälä 
1112eb64343cSVille Syrjälä 		if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1113eb64343cSVille Syrjälä 			i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1114eb64343cSVille Syrjälä 
1115eb64343cSVille Syrjälä 		if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1116eb64343cSVille Syrjälä 			intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1117eb64343cSVille Syrjälä 	}
1118eb64343cSVille Syrjälä 
1119eb64343cSVille Syrjälä 	if (blc_event || (iir & I915_ASLE_INTERRUPT))
1120eb64343cSVille Syrjälä 		intel_opregion_asle_intr(dev_priv);
1121eb64343cSVille Syrjälä }
1122eb64343cSVille Syrjälä 
1123eb64343cSVille Syrjälä static void i965_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1124eb64343cSVille Syrjälä 				      u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1125eb64343cSVille Syrjälä {
1126eb64343cSVille Syrjälä 	bool blc_event = false;
1127eb64343cSVille Syrjälä 	enum pipe pipe;
1128eb64343cSVille Syrjälä 
1129eb64343cSVille Syrjälä 	for_each_pipe(dev_priv, pipe) {
1130eb64343cSVille Syrjälä 		if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1131aca9310aSAnshuman Gupta 			intel_handle_vblank(dev_priv, pipe);
1132eb64343cSVille Syrjälä 
1133eb64343cSVille Syrjälä 		if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1134eb64343cSVille Syrjälä 			blc_event = true;
1135eb64343cSVille Syrjälä 
1136eb64343cSVille Syrjälä 		if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1137eb64343cSVille Syrjälä 			i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1138eb64343cSVille Syrjälä 
1139eb64343cSVille Syrjälä 		if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1140eb64343cSVille Syrjälä 			intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1141eb64343cSVille Syrjälä 	}
1142eb64343cSVille Syrjälä 
1143eb64343cSVille Syrjälä 	if (blc_event || (iir & I915_ASLE_INTERRUPT))
1144eb64343cSVille Syrjälä 		intel_opregion_asle_intr(dev_priv);
1145eb64343cSVille Syrjälä 
1146eb64343cSVille Syrjälä 	if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1147eb64343cSVille Syrjälä 		gmbus_irq_handler(dev_priv);
1148eb64343cSVille Syrjälä }
1149eb64343cSVille Syrjälä 
115091d14251STvrtko Ursulin static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv,
11512ecb8ca4SVille Syrjälä 					    u32 pipe_stats[I915_MAX_PIPES])
11522ecb8ca4SVille Syrjälä {
11532ecb8ca4SVille Syrjälä 	enum pipe pipe;
11547e231dbeSJesse Barnes 
1155055e393fSDamien Lespiau 	for_each_pipe(dev_priv, pipe) {
1156fd3a4024SDaniel Vetter 		if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1157aca9310aSAnshuman Gupta 			intel_handle_vblank(dev_priv, pipe);
11584356d586SDaniel Vetter 
11596ede6b06SVille Syrjälä 		if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV)
11606ede6b06SVille Syrjälä 			flip_done_handler(dev_priv, pipe);
11616ede6b06SVille Syrjälä 
11624356d586SDaniel Vetter 		if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
116391d14251STvrtko Ursulin 			i9xx_pipe_crc_irq_handler(dev_priv, pipe);
11642d9d2b0bSVille Syrjälä 
11651f7247c0SDaniel Vetter 		if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
11661f7247c0SDaniel Vetter 			intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
116731acc7f5SJesse Barnes 	}
116831acc7f5SJesse Barnes 
1169c1874ed7SImre Deak 	if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
117091d14251STvrtko Ursulin 		gmbus_irq_handler(dev_priv);
1171c1874ed7SImre Deak }
1172c1874ed7SImre Deak 
11731ae3c34cSVille Syrjälä static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
117416c6c56bSVille Syrjälä {
11750ba7c51aSVille Syrjälä 	u32 hotplug_status = 0, hotplug_status_mask;
11760ba7c51aSVille Syrjälä 	int i;
117716c6c56bSVille Syrjälä 
11780ba7c51aSVille Syrjälä 	if (IS_G4X(dev_priv) ||
11790ba7c51aSVille Syrjälä 	    IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11800ba7c51aSVille Syrjälä 		hotplug_status_mask = HOTPLUG_INT_STATUS_G4X |
11810ba7c51aSVille Syrjälä 			DP_AUX_CHANNEL_MASK_INT_STATUS_G4X;
11820ba7c51aSVille Syrjälä 	else
11830ba7c51aSVille Syrjälä 		hotplug_status_mask = HOTPLUG_INT_STATUS_I915;
11840ba7c51aSVille Syrjälä 
11850ba7c51aSVille Syrjälä 	/*
11860ba7c51aSVille Syrjälä 	 * We absolutely have to clear all the pending interrupt
11870ba7c51aSVille Syrjälä 	 * bits in PORT_HOTPLUG_STAT. Otherwise the ISR port
11880ba7c51aSVille Syrjälä 	 * interrupt bit won't have an edge, and the i965/g4x
11890ba7c51aSVille Syrjälä 	 * edge triggered IIR will not notice that an interrupt
11900ba7c51aSVille Syrjälä 	 * is still pending. We can't use PORT_HOTPLUG_EN to
11910ba7c51aSVille Syrjälä 	 * guarantee the edge as the act of toggling the enable
11920ba7c51aSVille Syrjälä 	 * bits can itself generate a new hotplug interrupt :(
11930ba7c51aSVille Syrjälä 	 */
11940ba7c51aSVille Syrjälä 	for (i = 0; i < 10; i++) {
11952939eb06SJani Nikula 		u32 tmp = intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT) & hotplug_status_mask;
11960ba7c51aSVille Syrjälä 
11970ba7c51aSVille Syrjälä 		if (tmp == 0)
11980ba7c51aSVille Syrjälä 			return hotplug_status;
11990ba7c51aSVille Syrjälä 
12000ba7c51aSVille Syrjälä 		hotplug_status |= tmp;
12012939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, PORT_HOTPLUG_STAT, hotplug_status);
12020ba7c51aSVille Syrjälä 	}
12030ba7c51aSVille Syrjälä 
120448a1b8d4SPankaj Bharadiya 	drm_WARN_ONCE(&dev_priv->drm, 1,
12050ba7c51aSVille Syrjälä 		      "PORT_HOTPLUG_STAT did not clear (0x%08x)\n",
12062939eb06SJani Nikula 		      intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT));
12071ae3c34cSVille Syrjälä 
12081ae3c34cSVille Syrjälä 	return hotplug_status;
12091ae3c34cSVille Syrjälä }
12101ae3c34cSVille Syrjälä 
121191d14251STvrtko Ursulin static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv,
12121ae3c34cSVille Syrjälä 				 u32 hotplug_status)
12131ae3c34cSVille Syrjälä {
12141ae3c34cSVille Syrjälä 	u32 pin_mask = 0, long_mask = 0;
12150398993bSVille Syrjälä 	u32 hotplug_trigger;
12163ff60f89SOscar Mateo 
12170398993bSVille Syrjälä 	if (IS_G4X(dev_priv) ||
12180398993bSVille Syrjälä 	    IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
12190398993bSVille Syrjälä 		hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
12200398993bSVille Syrjälä 	else
12210398993bSVille Syrjälä 		hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
122216c6c56bSVille Syrjälä 
122358f2cf24SVille Syrjälä 	if (hotplug_trigger) {
1224cf53902fSRodrigo Vivi 		intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1225cf53902fSRodrigo Vivi 				   hotplug_trigger, hotplug_trigger,
12265a4dd6f0SJani Nikula 				   dev_priv->display.hotplug.hpd,
1227fd63e2a9SImre Deak 				   i9xx_port_hotplug_long_detect);
122858f2cf24SVille Syrjälä 
122991d14251STvrtko Ursulin 		intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
123058f2cf24SVille Syrjälä 	}
1231369712e8SJani Nikula 
12320398993bSVille Syrjälä 	if ((IS_G4X(dev_priv) ||
12330398993bSVille Syrjälä 	     IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
12340398993bSVille Syrjälä 	    hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
123591d14251STvrtko Ursulin 		dp_aux_irq_handler(dev_priv);
123658f2cf24SVille Syrjälä }
123716c6c56bSVille Syrjälä 
1238c1874ed7SImre Deak static irqreturn_t valleyview_irq_handler(int irq, void *arg)
1239c1874ed7SImre Deak {
1240b318b824SVille Syrjälä 	struct drm_i915_private *dev_priv = arg;
1241c1874ed7SImre Deak 	irqreturn_t ret = IRQ_NONE;
1242c1874ed7SImre Deak 
12432dd2a883SImre Deak 	if (!intel_irqs_enabled(dev_priv))
12442dd2a883SImre Deak 		return IRQ_NONE;
12452dd2a883SImre Deak 
12461f814dacSImre Deak 	/* IRQs are synced during runtime_suspend, we don't require a wakeref */
12479102650fSDaniele Ceraolo Spurio 	disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
12481f814dacSImre Deak 
12491e1cace9SVille Syrjälä 	do {
12506e814800SVille Syrjälä 		u32 iir, gt_iir, pm_iir;
12512ecb8ca4SVille Syrjälä 		u32 pipe_stats[I915_MAX_PIPES] = {};
12521ae3c34cSVille Syrjälä 		u32 hotplug_status = 0;
1253a5e485a9SVille Syrjälä 		u32 ier = 0;
12543ff60f89SOscar Mateo 
12552939eb06SJani Nikula 		gt_iir = intel_uncore_read(&dev_priv->uncore, GTIIR);
12562939eb06SJani Nikula 		pm_iir = intel_uncore_read(&dev_priv->uncore, GEN6_PMIIR);
12572939eb06SJani Nikula 		iir = intel_uncore_read(&dev_priv->uncore, VLV_IIR);
1258c1874ed7SImre Deak 
1259c1874ed7SImre Deak 		if (gt_iir == 0 && pm_iir == 0 && iir == 0)
12601e1cace9SVille Syrjälä 			break;
1261c1874ed7SImre Deak 
1262c1874ed7SImre Deak 		ret = IRQ_HANDLED;
1263c1874ed7SImre Deak 
1264a5e485a9SVille Syrjälä 		/*
1265a5e485a9SVille Syrjälä 		 * Theory on interrupt generation, based on empirical evidence:
1266a5e485a9SVille Syrjälä 		 *
1267a5e485a9SVille Syrjälä 		 * x = ((VLV_IIR & VLV_IER) ||
1268a5e485a9SVille Syrjälä 		 *      (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) &&
1269a5e485a9SVille Syrjälä 		 *       (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE)));
1270a5e485a9SVille Syrjälä 		 *
1271a5e485a9SVille Syrjälä 		 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
1272a5e485a9SVille Syrjälä 		 * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to
1273a5e485a9SVille Syrjälä 		 * guarantee the CPU interrupt will be raised again even if we
1274a5e485a9SVille Syrjälä 		 * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR
1275a5e485a9SVille Syrjälä 		 * bits this time around.
1276a5e485a9SVille Syrjälä 		 */
12772939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, VLV_MASTER_IER, 0);
12788cee664dSAndrzej Hajda 		ier = intel_uncore_rmw(&dev_priv->uncore, VLV_IER, ~0, 0);
12794a0a0202SVille Syrjälä 
12804a0a0202SVille Syrjälä 		if (gt_iir)
12812939eb06SJani Nikula 			intel_uncore_write(&dev_priv->uncore, GTIIR, gt_iir);
12824a0a0202SVille Syrjälä 		if (pm_iir)
12832939eb06SJani Nikula 			intel_uncore_write(&dev_priv->uncore, GEN6_PMIIR, pm_iir);
12844a0a0202SVille Syrjälä 
12857ce4d1f2SVille Syrjälä 		if (iir & I915_DISPLAY_PORT_INTERRUPT)
12861ae3c34cSVille Syrjälä 			hotplug_status = i9xx_hpd_irq_ack(dev_priv);
12877ce4d1f2SVille Syrjälä 
12883ff60f89SOscar Mateo 		/* Call regardless, as some status bits might not be
12893ff60f89SOscar Mateo 		 * signalled in iir */
1290eb64343cSVille Syrjälä 		i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
12917ce4d1f2SVille Syrjälä 
1292eef57324SJerome Anand 		if (iir & (I915_LPE_PIPE_A_INTERRUPT |
1293eef57324SJerome Anand 			   I915_LPE_PIPE_B_INTERRUPT))
1294eef57324SJerome Anand 			intel_lpe_audio_irq_handler(dev_priv);
1295eef57324SJerome Anand 
12967ce4d1f2SVille Syrjälä 		/*
12977ce4d1f2SVille Syrjälä 		 * VLV_IIR is single buffered, and reflects the level
12987ce4d1f2SVille Syrjälä 		 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
12997ce4d1f2SVille Syrjälä 		 */
13007ce4d1f2SVille Syrjälä 		if (iir)
13012939eb06SJani Nikula 			intel_uncore_write(&dev_priv->uncore, VLV_IIR, iir);
13024a0a0202SVille Syrjälä 
13032939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, VLV_IER, ier);
13042939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
13051ae3c34cSVille Syrjälä 
130652894874SVille Syrjälä 		if (gt_iir)
13072cbc876dSMichał Winiarski 			gen6_gt_irq_handler(to_gt(dev_priv), gt_iir);
130852894874SVille Syrjälä 		if (pm_iir)
13092cbc876dSMichał Winiarski 			gen6_rps_irq_handler(&to_gt(dev_priv)->rps, pm_iir);
131052894874SVille Syrjälä 
13111ae3c34cSVille Syrjälä 		if (hotplug_status)
131291d14251STvrtko Ursulin 			i9xx_hpd_irq_handler(dev_priv, hotplug_status);
13132ecb8ca4SVille Syrjälä 
131491d14251STvrtko Ursulin 		valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
13151e1cace9SVille Syrjälä 	} while (0);
13167e231dbeSJesse Barnes 
13179c6508b9SThomas Gleixner 	pmu_irq_stats(dev_priv, ret);
13189c6508b9SThomas Gleixner 
13199102650fSDaniele Ceraolo Spurio 	enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
13201f814dacSImre Deak 
13217e231dbeSJesse Barnes 	return ret;
13227e231dbeSJesse Barnes }
13237e231dbeSJesse Barnes 
132443f328d7SVille Syrjälä static irqreturn_t cherryview_irq_handler(int irq, void *arg)
132543f328d7SVille Syrjälä {
1326b318b824SVille Syrjälä 	struct drm_i915_private *dev_priv = arg;
132743f328d7SVille Syrjälä 	irqreturn_t ret = IRQ_NONE;
132843f328d7SVille Syrjälä 
13292dd2a883SImre Deak 	if (!intel_irqs_enabled(dev_priv))
13302dd2a883SImre Deak 		return IRQ_NONE;
13312dd2a883SImre Deak 
13321f814dacSImre Deak 	/* IRQs are synced during runtime_suspend, we don't require a wakeref */
13339102650fSDaniele Ceraolo Spurio 	disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
13341f814dacSImre Deak 
1335579de73bSChris Wilson 	do {
13366e814800SVille Syrjälä 		u32 master_ctl, iir;
13372ecb8ca4SVille Syrjälä 		u32 pipe_stats[I915_MAX_PIPES] = {};
13381ae3c34cSVille Syrjälä 		u32 hotplug_status = 0;
1339a5e485a9SVille Syrjälä 		u32 ier = 0;
1340a5e485a9SVille Syrjälä 
13412939eb06SJani Nikula 		master_ctl = intel_uncore_read(&dev_priv->uncore, GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
13422939eb06SJani Nikula 		iir = intel_uncore_read(&dev_priv->uncore, VLV_IIR);
13433278f67fSVille Syrjälä 
13443278f67fSVille Syrjälä 		if (master_ctl == 0 && iir == 0)
13458e5fd599SVille Syrjälä 			break;
134643f328d7SVille Syrjälä 
134727b6c122SOscar Mateo 		ret = IRQ_HANDLED;
134827b6c122SOscar Mateo 
1349a5e485a9SVille Syrjälä 		/*
1350a5e485a9SVille Syrjälä 		 * Theory on interrupt generation, based on empirical evidence:
1351a5e485a9SVille Syrjälä 		 *
1352a5e485a9SVille Syrjälä 		 * x = ((VLV_IIR & VLV_IER) ||
1353a5e485a9SVille Syrjälä 		 *      ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) &&
1354a5e485a9SVille Syrjälä 		 *       (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL)));
1355a5e485a9SVille Syrjälä 		 *
1356a5e485a9SVille Syrjälä 		 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
1357a5e485a9SVille Syrjälä 		 * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to
1358a5e485a9SVille Syrjälä 		 * guarantee the CPU interrupt will be raised again even if we
1359a5e485a9SVille Syrjälä 		 * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL
1360a5e485a9SVille Syrjälä 		 * bits this time around.
1361a5e485a9SVille Syrjälä 		 */
13622939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, GEN8_MASTER_IRQ, 0);
13638cee664dSAndrzej Hajda 		ier = intel_uncore_rmw(&dev_priv->uncore, VLV_IER, ~0, 0);
136443f328d7SVille Syrjälä 
13652cbc876dSMichał Winiarski 		gen8_gt_irq_handler(to_gt(dev_priv), master_ctl);
136627b6c122SOscar Mateo 
136727b6c122SOscar Mateo 		if (iir & I915_DISPLAY_PORT_INTERRUPT)
13681ae3c34cSVille Syrjälä 			hotplug_status = i9xx_hpd_irq_ack(dev_priv);
136943f328d7SVille Syrjälä 
137027b6c122SOscar Mateo 		/* Call regardless, as some status bits might not be
137127b6c122SOscar Mateo 		 * signalled in iir */
1372eb64343cSVille Syrjälä 		i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
137343f328d7SVille Syrjälä 
1374eef57324SJerome Anand 		if (iir & (I915_LPE_PIPE_A_INTERRUPT |
1375eef57324SJerome Anand 			   I915_LPE_PIPE_B_INTERRUPT |
1376eef57324SJerome Anand 			   I915_LPE_PIPE_C_INTERRUPT))
1377eef57324SJerome Anand 			intel_lpe_audio_irq_handler(dev_priv);
1378eef57324SJerome Anand 
13797ce4d1f2SVille Syrjälä 		/*
13807ce4d1f2SVille Syrjälä 		 * VLV_IIR is single buffered, and reflects the level
13817ce4d1f2SVille Syrjälä 		 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
13827ce4d1f2SVille Syrjälä 		 */
13837ce4d1f2SVille Syrjälä 		if (iir)
13842939eb06SJani Nikula 			intel_uncore_write(&dev_priv->uncore, VLV_IIR, iir);
13857ce4d1f2SVille Syrjälä 
13862939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, VLV_IER, ier);
13872939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
13881ae3c34cSVille Syrjälä 
13891ae3c34cSVille Syrjälä 		if (hotplug_status)
139091d14251STvrtko Ursulin 			i9xx_hpd_irq_handler(dev_priv, hotplug_status);
13912ecb8ca4SVille Syrjälä 
139291d14251STvrtko Ursulin 		valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
1393579de73bSChris Wilson 	} while (0);
13943278f67fSVille Syrjälä 
13959c6508b9SThomas Gleixner 	pmu_irq_stats(dev_priv, ret);
13969c6508b9SThomas Gleixner 
13979102650fSDaniele Ceraolo Spurio 	enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
13981f814dacSImre Deak 
139943f328d7SVille Syrjälä 	return ret;
140043f328d7SVille Syrjälä }
140143f328d7SVille Syrjälä 
140291d14251STvrtko Ursulin static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv,
14030398993bSVille Syrjälä 				u32 hotplug_trigger)
1404776ad806SJesse Barnes {
140542db67d6SVille Syrjälä 	u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
1406776ad806SJesse Barnes 
14076a39d7c9SJani Nikula 	/*
14086a39d7c9SJani Nikula 	 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
14096a39d7c9SJani Nikula 	 * unless we touch the hotplug register, even if hotplug_trigger is
14106a39d7c9SJani Nikula 	 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
14116a39d7c9SJani Nikula 	 * errors.
14126a39d7c9SJani Nikula 	 */
14132939eb06SJani Nikula 	dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
14146a39d7c9SJani Nikula 	if (!hotplug_trigger) {
14156a39d7c9SJani Nikula 		u32 mask = PORTA_HOTPLUG_STATUS_MASK |
14166a39d7c9SJani Nikula 			PORTD_HOTPLUG_STATUS_MASK |
14176a39d7c9SJani Nikula 			PORTC_HOTPLUG_STATUS_MASK |
14186a39d7c9SJani Nikula 			PORTB_HOTPLUG_STATUS_MASK;
14196a39d7c9SJani Nikula 		dig_hotplug_reg &= ~mask;
14206a39d7c9SJani Nikula 	}
14216a39d7c9SJani Nikula 
14222939eb06SJani Nikula 	intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, dig_hotplug_reg);
14236a39d7c9SJani Nikula 	if (!hotplug_trigger)
14246a39d7c9SJani Nikula 		return;
142513cf5504SDave Airlie 
14260398993bSVille Syrjälä 	intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
14270398993bSVille Syrjälä 			   hotplug_trigger, dig_hotplug_reg,
14285a4dd6f0SJani Nikula 			   dev_priv->display.hotplug.pch_hpd,
1429fd63e2a9SImre Deak 			   pch_port_hotplug_long_detect);
143040e56410SVille Syrjälä 
143191d14251STvrtko Ursulin 	intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
1432aaf5ec2eSSonika Jindal }
143391d131d2SDaniel Vetter 
143491d14251STvrtko Ursulin static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
143540e56410SVille Syrjälä {
1436d048a268SVille Syrjälä 	enum pipe pipe;
143740e56410SVille Syrjälä 	u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
143840e56410SVille Syrjälä 
14390398993bSVille Syrjälä 	ibx_hpd_irq_handler(dev_priv, hotplug_trigger);
144040e56410SVille Syrjälä 
1441cfc33bf7SVille Syrjälä 	if (pch_iir & SDE_AUDIO_POWER_MASK) {
1442cfc33bf7SVille Syrjälä 		int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1443776ad806SJesse Barnes 			       SDE_AUDIO_POWER_SHIFT);
144400376ccfSWambui Karuga 		drm_dbg(&dev_priv->drm, "PCH audio power change on port %d\n",
1445cfc33bf7SVille Syrjälä 			port_name(port));
1446cfc33bf7SVille Syrjälä 	}
1447776ad806SJesse Barnes 
1448ce99c256SDaniel Vetter 	if (pch_iir & SDE_AUX_MASK)
144991d14251STvrtko Ursulin 		dp_aux_irq_handler(dev_priv);
1450ce99c256SDaniel Vetter 
1451776ad806SJesse Barnes 	if (pch_iir & SDE_GMBUS)
145291d14251STvrtko Ursulin 		gmbus_irq_handler(dev_priv);
1453776ad806SJesse Barnes 
1454776ad806SJesse Barnes 	if (pch_iir & SDE_AUDIO_HDCP_MASK)
145500376ccfSWambui Karuga 		drm_dbg(&dev_priv->drm, "PCH HDCP audio interrupt\n");
1456776ad806SJesse Barnes 
1457776ad806SJesse Barnes 	if (pch_iir & SDE_AUDIO_TRANS_MASK)
145800376ccfSWambui Karuga 		drm_dbg(&dev_priv->drm, "PCH transcoder audio interrupt\n");
1459776ad806SJesse Barnes 
1460776ad806SJesse Barnes 	if (pch_iir & SDE_POISON)
146100376ccfSWambui Karuga 		drm_err(&dev_priv->drm, "PCH poison interrupt\n");
1462776ad806SJesse Barnes 
1463b8b65ccdSAnshuman Gupta 	if (pch_iir & SDE_FDI_MASK) {
1464055e393fSDamien Lespiau 		for_each_pipe(dev_priv, pipe)
146500376ccfSWambui Karuga 			drm_dbg(&dev_priv->drm, "  pipe %c FDI IIR: 0x%08x\n",
14669db4a9c7SJesse Barnes 				pipe_name(pipe),
14672939eb06SJani Nikula 				intel_uncore_read(&dev_priv->uncore, FDI_RX_IIR(pipe)));
1468b8b65ccdSAnshuman Gupta 	}
1469776ad806SJesse Barnes 
1470776ad806SJesse Barnes 	if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
147100376ccfSWambui Karuga 		drm_dbg(&dev_priv->drm, "PCH transcoder CRC done interrupt\n");
1472776ad806SJesse Barnes 
1473776ad806SJesse Barnes 	if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
147400376ccfSWambui Karuga 		drm_dbg(&dev_priv->drm,
147500376ccfSWambui Karuga 			"PCH transcoder CRC error interrupt\n");
1476776ad806SJesse Barnes 
1477776ad806SJesse Barnes 	if (pch_iir & SDE_TRANSA_FIFO_UNDER)
1478a2196033SMatthias Kaehlcke 		intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A);
14798664281bSPaulo Zanoni 
14808664281bSPaulo Zanoni 	if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1481a2196033SMatthias Kaehlcke 		intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B);
14828664281bSPaulo Zanoni }
14838664281bSPaulo Zanoni 
148491d14251STvrtko Ursulin static void ivb_err_int_handler(struct drm_i915_private *dev_priv)
14858664281bSPaulo Zanoni {
14862939eb06SJani Nikula 	u32 err_int = intel_uncore_read(&dev_priv->uncore, GEN7_ERR_INT);
14875a69b89fSDaniel Vetter 	enum pipe pipe;
14888664281bSPaulo Zanoni 
1489de032bf4SPaulo Zanoni 	if (err_int & ERR_INT_POISON)
149000376ccfSWambui Karuga 		drm_err(&dev_priv->drm, "Poison interrupt\n");
1491de032bf4SPaulo Zanoni 
1492055e393fSDamien Lespiau 	for_each_pipe(dev_priv, pipe) {
14931f7247c0SDaniel Vetter 		if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
14941f7247c0SDaniel Vetter 			intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
14958664281bSPaulo Zanoni 
14965a69b89fSDaniel Vetter 		if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
149791d14251STvrtko Ursulin 			if (IS_IVYBRIDGE(dev_priv))
149891d14251STvrtko Ursulin 				ivb_pipe_crc_irq_handler(dev_priv, pipe);
14995a69b89fSDaniel Vetter 			else
150091d14251STvrtko Ursulin 				hsw_pipe_crc_irq_handler(dev_priv, pipe);
15015a69b89fSDaniel Vetter 		}
15025a69b89fSDaniel Vetter 	}
15038bf1e9f1SShuang He 
15042939eb06SJani Nikula 	intel_uncore_write(&dev_priv->uncore, GEN7_ERR_INT, err_int);
15058664281bSPaulo Zanoni }
15068664281bSPaulo Zanoni 
150791d14251STvrtko Ursulin static void cpt_serr_int_handler(struct drm_i915_private *dev_priv)
15088664281bSPaulo Zanoni {
15092939eb06SJani Nikula 	u32 serr_int = intel_uncore_read(&dev_priv->uncore, SERR_INT);
151045c1cd87SMika Kahola 	enum pipe pipe;
15118664281bSPaulo Zanoni 
1512de032bf4SPaulo Zanoni 	if (serr_int & SERR_INT_POISON)
151300376ccfSWambui Karuga 		drm_err(&dev_priv->drm, "PCH poison interrupt\n");
1514de032bf4SPaulo Zanoni 
151545c1cd87SMika Kahola 	for_each_pipe(dev_priv, pipe)
151645c1cd87SMika Kahola 		if (serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pipe))
151745c1cd87SMika Kahola 			intel_pch_fifo_underrun_irq_handler(dev_priv, pipe);
15188664281bSPaulo Zanoni 
15192939eb06SJani Nikula 	intel_uncore_write(&dev_priv->uncore, SERR_INT, serr_int);
1520776ad806SJesse Barnes }
1521776ad806SJesse Barnes 
152291d14251STvrtko Ursulin static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
152323e81d69SAdam Jackson {
1524d048a268SVille Syrjälä 	enum pipe pipe;
15256dbf30ceSVille Syrjälä 	u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
1526aaf5ec2eSSonika Jindal 
15270398993bSVille Syrjälä 	ibx_hpd_irq_handler(dev_priv, hotplug_trigger);
152891d131d2SDaniel Vetter 
1529cfc33bf7SVille Syrjälä 	if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1530cfc33bf7SVille Syrjälä 		int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
153123e81d69SAdam Jackson 			       SDE_AUDIO_POWER_SHIFT_CPT);
153200376ccfSWambui Karuga 		drm_dbg(&dev_priv->drm, "PCH audio power change on port %c\n",
1533cfc33bf7SVille Syrjälä 			port_name(port));
1534cfc33bf7SVille Syrjälä 	}
153523e81d69SAdam Jackson 
153623e81d69SAdam Jackson 	if (pch_iir & SDE_AUX_MASK_CPT)
153791d14251STvrtko Ursulin 		dp_aux_irq_handler(dev_priv);
153823e81d69SAdam Jackson 
153923e81d69SAdam Jackson 	if (pch_iir & SDE_GMBUS_CPT)
154091d14251STvrtko Ursulin 		gmbus_irq_handler(dev_priv);
154123e81d69SAdam Jackson 
154223e81d69SAdam Jackson 	if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
154300376ccfSWambui Karuga 		drm_dbg(&dev_priv->drm, "Audio CP request interrupt\n");
154423e81d69SAdam Jackson 
154523e81d69SAdam Jackson 	if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
154600376ccfSWambui Karuga 		drm_dbg(&dev_priv->drm, "Audio CP change interrupt\n");
154723e81d69SAdam Jackson 
1548b8b65ccdSAnshuman Gupta 	if (pch_iir & SDE_FDI_MASK_CPT) {
1549055e393fSDamien Lespiau 		for_each_pipe(dev_priv, pipe)
155000376ccfSWambui Karuga 			drm_dbg(&dev_priv->drm, "  pipe %c FDI IIR: 0x%08x\n",
155123e81d69SAdam Jackson 				pipe_name(pipe),
15522939eb06SJani Nikula 				intel_uncore_read(&dev_priv->uncore, FDI_RX_IIR(pipe)));
1553b8b65ccdSAnshuman Gupta 	}
15548664281bSPaulo Zanoni 
15558664281bSPaulo Zanoni 	if (pch_iir & SDE_ERROR_CPT)
155691d14251STvrtko Ursulin 		cpt_serr_int_handler(dev_priv);
155723e81d69SAdam Jackson }
155823e81d69SAdam Jackson 
155958676af6SLucas De Marchi static void icp_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
156031604222SAnusha Srivatsa {
1561e76ab2cfSVille Syrjälä 	u32 ddi_hotplug_trigger = pch_iir & SDE_DDI_HOTPLUG_MASK_ICP;
1562e76ab2cfSVille Syrjälä 	u32 tc_hotplug_trigger = pch_iir & SDE_TC_HOTPLUG_MASK_ICP;
156331604222SAnusha Srivatsa 	u32 pin_mask = 0, long_mask = 0;
156431604222SAnusha Srivatsa 
156531604222SAnusha Srivatsa 	if (ddi_hotplug_trigger) {
156631604222SAnusha Srivatsa 		u32 dig_hotplug_reg;
156731604222SAnusha Srivatsa 
1568f087cfe6SJani Nikula 		/* Locking due to DSI native GPIO sequences */
1569f087cfe6SJani Nikula 		spin_lock(&dev_priv->irq_lock);
15708cee664dSAndrzej Hajda 		dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, SHOTPLUG_CTL_DDI, 0, 0);
1571f087cfe6SJani Nikula 		spin_unlock(&dev_priv->irq_lock);
157231604222SAnusha Srivatsa 
157331604222SAnusha Srivatsa 		intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
15740398993bSVille Syrjälä 				   ddi_hotplug_trigger, dig_hotplug_reg,
15755a4dd6f0SJani Nikula 				   dev_priv->display.hotplug.pch_hpd,
157631604222SAnusha Srivatsa 				   icp_ddi_port_hotplug_long_detect);
157731604222SAnusha Srivatsa 	}
157831604222SAnusha Srivatsa 
157931604222SAnusha Srivatsa 	if (tc_hotplug_trigger) {
158031604222SAnusha Srivatsa 		u32 dig_hotplug_reg;
158131604222SAnusha Srivatsa 
15828cee664dSAndrzej Hajda 		dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, SHOTPLUG_CTL_TC, 0, 0);
158331604222SAnusha Srivatsa 
158431604222SAnusha Srivatsa 		intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
15850398993bSVille Syrjälä 				   tc_hotplug_trigger, dig_hotplug_reg,
15865a4dd6f0SJani Nikula 				   dev_priv->display.hotplug.pch_hpd,
1587da51e4baSVille Syrjälä 				   icp_tc_port_hotplug_long_detect);
158852dfdba0SLucas De Marchi 	}
158952dfdba0SLucas De Marchi 
159052dfdba0SLucas De Marchi 	if (pin_mask)
159152dfdba0SLucas De Marchi 		intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
159252dfdba0SLucas De Marchi 
159352dfdba0SLucas De Marchi 	if (pch_iir & SDE_GMBUS_ICP)
159452dfdba0SLucas De Marchi 		gmbus_irq_handler(dev_priv);
159552dfdba0SLucas De Marchi }
159652dfdba0SLucas De Marchi 
159791d14251STvrtko Ursulin static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
15986dbf30ceSVille Syrjälä {
15996dbf30ceSVille Syrjälä 	u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
16006dbf30ceSVille Syrjälä 		~SDE_PORTE_HOTPLUG_SPT;
16016dbf30ceSVille Syrjälä 	u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
16026dbf30ceSVille Syrjälä 	u32 pin_mask = 0, long_mask = 0;
16036dbf30ceSVille Syrjälä 
16046dbf30ceSVille Syrjälä 	if (hotplug_trigger) {
16056dbf30ceSVille Syrjälä 		u32 dig_hotplug_reg;
16066dbf30ceSVille Syrjälä 
16078cee664dSAndrzej Hajda 		dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG, 0, 0);
16086dbf30ceSVille Syrjälä 
1609cf53902fSRodrigo Vivi 		intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
16100398993bSVille Syrjälä 				   hotplug_trigger, dig_hotplug_reg,
16115a4dd6f0SJani Nikula 				   dev_priv->display.hotplug.pch_hpd,
161274c0b395SVille Syrjälä 				   spt_port_hotplug_long_detect);
16136dbf30ceSVille Syrjälä 	}
16146dbf30ceSVille Syrjälä 
16156dbf30ceSVille Syrjälä 	if (hotplug2_trigger) {
16166dbf30ceSVille Syrjälä 		u32 dig_hotplug_reg;
16176dbf30ceSVille Syrjälä 
16188cee664dSAndrzej Hajda 		dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG2, 0, 0);
16196dbf30ceSVille Syrjälä 
1620cf53902fSRodrigo Vivi 		intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
16210398993bSVille Syrjälä 				   hotplug2_trigger, dig_hotplug_reg,
16225a4dd6f0SJani Nikula 				   dev_priv->display.hotplug.pch_hpd,
16236dbf30ceSVille Syrjälä 				   spt_port_hotplug2_long_detect);
16246dbf30ceSVille Syrjälä 	}
16256dbf30ceSVille Syrjälä 
16266dbf30ceSVille Syrjälä 	if (pin_mask)
162791d14251STvrtko Ursulin 		intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
16286dbf30ceSVille Syrjälä 
16296dbf30ceSVille Syrjälä 	if (pch_iir & SDE_GMBUS_CPT)
163091d14251STvrtko Ursulin 		gmbus_irq_handler(dev_priv);
16316dbf30ceSVille Syrjälä }
16326dbf30ceSVille Syrjälä 
163391d14251STvrtko Ursulin static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv,
16340398993bSVille Syrjälä 				u32 hotplug_trigger)
1635c008bc6eSPaulo Zanoni {
1636e4ce95aaSVille Syrjälä 	u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
1637e4ce95aaSVille Syrjälä 
16388cee664dSAndrzej Hajda 	dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, DIGITAL_PORT_HOTPLUG_CNTRL, 0, 0);
1639e4ce95aaSVille Syrjälä 
16400398993bSVille Syrjälä 	intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
16410398993bSVille Syrjälä 			   hotplug_trigger, dig_hotplug_reg,
16425a4dd6f0SJani Nikula 			   dev_priv->display.hotplug.hpd,
1643e4ce95aaSVille Syrjälä 			   ilk_port_hotplug_long_detect);
164440e56410SVille Syrjälä 
164591d14251STvrtko Ursulin 	intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
1646e4ce95aaSVille Syrjälä }
1647c008bc6eSPaulo Zanoni 
164891d14251STvrtko Ursulin static void ilk_display_irq_handler(struct drm_i915_private *dev_priv,
164991d14251STvrtko Ursulin 				    u32 de_iir)
165040e56410SVille Syrjälä {
165140e56410SVille Syrjälä 	enum pipe pipe;
165240e56410SVille Syrjälä 	u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
165340e56410SVille Syrjälä 
165440e56410SVille Syrjälä 	if (hotplug_trigger)
16550398993bSVille Syrjälä 		ilk_hpd_irq_handler(dev_priv, hotplug_trigger);
165640e56410SVille Syrjälä 
1657c008bc6eSPaulo Zanoni 	if (de_iir & DE_AUX_CHANNEL_A)
165891d14251STvrtko Ursulin 		dp_aux_irq_handler(dev_priv);
1659c008bc6eSPaulo Zanoni 
1660c008bc6eSPaulo Zanoni 	if (de_iir & DE_GSE)
166191d14251STvrtko Ursulin 		intel_opregion_asle_intr(dev_priv);
1662c008bc6eSPaulo Zanoni 
1663c008bc6eSPaulo Zanoni 	if (de_iir & DE_POISON)
166400376ccfSWambui Karuga 		drm_err(&dev_priv->drm, "Poison interrupt\n");
1665c008bc6eSPaulo Zanoni 
1666055e393fSDamien Lespiau 	for_each_pipe(dev_priv, pipe) {
1667fd3a4024SDaniel Vetter 		if (de_iir & DE_PIPE_VBLANK(pipe))
1668aca9310aSAnshuman Gupta 			intel_handle_vblank(dev_priv, pipe);
1669c008bc6eSPaulo Zanoni 
16704bb18054SVille Syrjälä 		if (de_iir & DE_PLANE_FLIP_DONE(pipe))
16714bb18054SVille Syrjälä 			flip_done_handler(dev_priv, pipe);
16724bb18054SVille Syrjälä 
167340da17c2SDaniel Vetter 		if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
16741f7247c0SDaniel Vetter 			intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1675c008bc6eSPaulo Zanoni 
167640da17c2SDaniel Vetter 		if (de_iir & DE_PIPE_CRC_DONE(pipe))
167791d14251STvrtko Ursulin 			i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1678c008bc6eSPaulo Zanoni 	}
1679c008bc6eSPaulo Zanoni 
1680c008bc6eSPaulo Zanoni 	/* check event from PCH */
1681c008bc6eSPaulo Zanoni 	if (de_iir & DE_PCH_EVENT) {
16822939eb06SJani Nikula 		u32 pch_iir = intel_uncore_read(&dev_priv->uncore, SDEIIR);
1683c008bc6eSPaulo Zanoni 
168491d14251STvrtko Ursulin 		if (HAS_PCH_CPT(dev_priv))
168591d14251STvrtko Ursulin 			cpt_irq_handler(dev_priv, pch_iir);
1686c008bc6eSPaulo Zanoni 		else
168791d14251STvrtko Ursulin 			ibx_irq_handler(dev_priv, pch_iir);
1688c008bc6eSPaulo Zanoni 
1689c008bc6eSPaulo Zanoni 		/* should clear PCH hotplug event before clear CPU irq */
16902939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, SDEIIR, pch_iir);
1691c008bc6eSPaulo Zanoni 	}
1692c008bc6eSPaulo Zanoni 
169393e7e61eSLucas De Marchi 	if (DISPLAY_VER(dev_priv) == 5 && de_iir & DE_PCU_EVENT)
16942cbc876dSMichał Winiarski 		gen5_rps_irq_handler(&to_gt(dev_priv)->rps);
1695c008bc6eSPaulo Zanoni }
1696c008bc6eSPaulo Zanoni 
169791d14251STvrtko Ursulin static void ivb_display_irq_handler(struct drm_i915_private *dev_priv,
169891d14251STvrtko Ursulin 				    u32 de_iir)
16999719fb98SPaulo Zanoni {
170007d27e20SDamien Lespiau 	enum pipe pipe;
170123bb4cb5SVille Syrjälä 	u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
170223bb4cb5SVille Syrjälä 
170340e56410SVille Syrjälä 	if (hotplug_trigger)
17040398993bSVille Syrjälä 		ilk_hpd_irq_handler(dev_priv, hotplug_trigger);
17059719fb98SPaulo Zanoni 
17069719fb98SPaulo Zanoni 	if (de_iir & DE_ERR_INT_IVB)
170791d14251STvrtko Ursulin 		ivb_err_int_handler(dev_priv);
17089719fb98SPaulo Zanoni 
17099719fb98SPaulo Zanoni 	if (de_iir & DE_AUX_CHANNEL_A_IVB)
171091d14251STvrtko Ursulin 		dp_aux_irq_handler(dev_priv);
17119719fb98SPaulo Zanoni 
17129719fb98SPaulo Zanoni 	if (de_iir & DE_GSE_IVB)
171391d14251STvrtko Ursulin 		intel_opregion_asle_intr(dev_priv);
17149719fb98SPaulo Zanoni 
1715055e393fSDamien Lespiau 	for_each_pipe(dev_priv, pipe) {
171633ef04faSVille Syrjälä 		if (de_iir & DE_PIPE_VBLANK_IVB(pipe))
1717aca9310aSAnshuman Gupta 			intel_handle_vblank(dev_priv, pipe);
17182a636e24SVille Syrjälä 
17192a636e24SVille Syrjälä 		if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe))
17202a636e24SVille Syrjälä 			flip_done_handler(dev_priv, pipe);
17219719fb98SPaulo Zanoni 	}
17229719fb98SPaulo Zanoni 
17239719fb98SPaulo Zanoni 	/* check event from PCH */
172491d14251STvrtko Ursulin 	if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) {
17252939eb06SJani Nikula 		u32 pch_iir = intel_uncore_read(&dev_priv->uncore, SDEIIR);
17269719fb98SPaulo Zanoni 
172791d14251STvrtko Ursulin 		cpt_irq_handler(dev_priv, pch_iir);
17289719fb98SPaulo Zanoni 
17299719fb98SPaulo Zanoni 		/* clear PCH hotplug event before clear CPU irq */
17302939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, SDEIIR, pch_iir);
17319719fb98SPaulo Zanoni 	}
17329719fb98SPaulo Zanoni }
17339719fb98SPaulo Zanoni 
173472c90f62SOscar Mateo /*
173572c90f62SOscar Mateo  * To handle irqs with the minimum potential races with fresh interrupts, we:
173672c90f62SOscar Mateo  * 1 - Disable Master Interrupt Control.
173772c90f62SOscar Mateo  * 2 - Find the source(s) of the interrupt.
173872c90f62SOscar Mateo  * 3 - Clear the Interrupt Identity bits (IIR).
173972c90f62SOscar Mateo  * 4 - Process the interrupt(s) that had bits set in the IIRs.
174072c90f62SOscar Mateo  * 5 - Re-enable Master Interrupt Control.
174172c90f62SOscar Mateo  */
17429eae5e27SLucas De Marchi static irqreturn_t ilk_irq_handler(int irq, void *arg)
1743b1f14ad0SJesse Barnes {
1744c48a798aSChris Wilson 	struct drm_i915_private *i915 = arg;
1745c48a798aSChris Wilson 	void __iomem * const regs = i915->uncore.regs;
1746f1af8fc1SPaulo Zanoni 	u32 de_iir, gt_iir, de_ier, sde_ier = 0;
17470e43406bSChris Wilson 	irqreturn_t ret = IRQ_NONE;
1748b1f14ad0SJesse Barnes 
1749c48a798aSChris Wilson 	if (unlikely(!intel_irqs_enabled(i915)))
17502dd2a883SImre Deak 		return IRQ_NONE;
17512dd2a883SImre Deak 
17521f814dacSImre Deak 	/* IRQs are synced during runtime_suspend, we don't require a wakeref */
1753c48a798aSChris Wilson 	disable_rpm_wakeref_asserts(&i915->runtime_pm);
17541f814dacSImre Deak 
1755b1f14ad0SJesse Barnes 	/* disable master interrupt before clearing iir  */
1756c48a798aSChris Wilson 	de_ier = raw_reg_read(regs, DEIER);
1757c48a798aSChris Wilson 	raw_reg_write(regs, DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
17580e43406bSChris Wilson 
175944498aeaSPaulo Zanoni 	/* Disable south interrupts. We'll only write to SDEIIR once, so further
176044498aeaSPaulo Zanoni 	 * interrupts will will be stored on its back queue, and then we'll be
176144498aeaSPaulo Zanoni 	 * able to process them after we restore SDEIER (as soon as we restore
176244498aeaSPaulo Zanoni 	 * it, we'll get an interrupt if SDEIIR still has something to process
176344498aeaSPaulo Zanoni 	 * due to its back queue). */
1764c48a798aSChris Wilson 	if (!HAS_PCH_NOP(i915)) {
1765c48a798aSChris Wilson 		sde_ier = raw_reg_read(regs, SDEIER);
1766c48a798aSChris Wilson 		raw_reg_write(regs, SDEIER, 0);
1767ab5c608bSBen Widawsky 	}
176844498aeaSPaulo Zanoni 
176972c90f62SOscar Mateo 	/* Find, clear, then process each source of interrupt */
177072c90f62SOscar Mateo 
1771c48a798aSChris Wilson 	gt_iir = raw_reg_read(regs, GTIIR);
17720e43406bSChris Wilson 	if (gt_iir) {
1773c48a798aSChris Wilson 		raw_reg_write(regs, GTIIR, gt_iir);
1774651e7d48SLucas De Marchi 		if (GRAPHICS_VER(i915) >= 6)
17752cbc876dSMichał Winiarski 			gen6_gt_irq_handler(to_gt(i915), gt_iir);
1776d8fc8a47SPaulo Zanoni 		else
17772cbc876dSMichał Winiarski 			gen5_gt_irq_handler(to_gt(i915), gt_iir);
1778c48a798aSChris Wilson 		ret = IRQ_HANDLED;
17790e43406bSChris Wilson 	}
1780b1f14ad0SJesse Barnes 
1781c48a798aSChris Wilson 	de_iir = raw_reg_read(regs, DEIIR);
17820e43406bSChris Wilson 	if (de_iir) {
1783c48a798aSChris Wilson 		raw_reg_write(regs, DEIIR, de_iir);
1784373abf1aSMatt Roper 		if (DISPLAY_VER(i915) >= 7)
1785c48a798aSChris Wilson 			ivb_display_irq_handler(i915, de_iir);
1786f1af8fc1SPaulo Zanoni 		else
1787c48a798aSChris Wilson 			ilk_display_irq_handler(i915, de_iir);
17880e43406bSChris Wilson 		ret = IRQ_HANDLED;
1789c48a798aSChris Wilson 	}
1790c48a798aSChris Wilson 
1791651e7d48SLucas De Marchi 	if (GRAPHICS_VER(i915) >= 6) {
1792c48a798aSChris Wilson 		u32 pm_iir = raw_reg_read(regs, GEN6_PMIIR);
1793c48a798aSChris Wilson 		if (pm_iir) {
1794c48a798aSChris Wilson 			raw_reg_write(regs, GEN6_PMIIR, pm_iir);
17952cbc876dSMichał Winiarski 			gen6_rps_irq_handler(&to_gt(i915)->rps, pm_iir);
1796c48a798aSChris Wilson 			ret = IRQ_HANDLED;
17970e43406bSChris Wilson 		}
1798f1af8fc1SPaulo Zanoni 	}
1799b1f14ad0SJesse Barnes 
1800c48a798aSChris Wilson 	raw_reg_write(regs, DEIER, de_ier);
1801c48a798aSChris Wilson 	if (sde_ier)
1802c48a798aSChris Wilson 		raw_reg_write(regs, SDEIER, sde_ier);
1803b1f14ad0SJesse Barnes 
18049c6508b9SThomas Gleixner 	pmu_irq_stats(i915, ret);
18059c6508b9SThomas Gleixner 
18061f814dacSImre Deak 	/* IRQs are synced during runtime_suspend, we don't require a wakeref */
1807c48a798aSChris Wilson 	enable_rpm_wakeref_asserts(&i915->runtime_pm);
18081f814dacSImre Deak 
1809b1f14ad0SJesse Barnes 	return ret;
1810b1f14ad0SJesse Barnes }
1811b1f14ad0SJesse Barnes 
181291d14251STvrtko Ursulin static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv,
18130398993bSVille Syrjälä 				u32 hotplug_trigger)
1814d04a492dSShashank Sharma {
1815cebd87a0SVille Syrjälä 	u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
1816d04a492dSShashank Sharma 
18178cee664dSAndrzej Hajda 	dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG, 0, 0);
1818d04a492dSShashank Sharma 
18190398993bSVille Syrjälä 	intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
18200398993bSVille Syrjälä 			   hotplug_trigger, dig_hotplug_reg,
18215a4dd6f0SJani Nikula 			   dev_priv->display.hotplug.hpd,
1822cebd87a0SVille Syrjälä 			   bxt_port_hotplug_long_detect);
182340e56410SVille Syrjälä 
182491d14251STvrtko Ursulin 	intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
1825d04a492dSShashank Sharma }
1826d04a492dSShashank Sharma 
1827121e758eSDhinakaran Pandiyan static void gen11_hpd_irq_handler(struct drm_i915_private *dev_priv, u32 iir)
1828121e758eSDhinakaran Pandiyan {
1829121e758eSDhinakaran Pandiyan 	u32 pin_mask = 0, long_mask = 0;
1830b796b971SDhinakaran Pandiyan 	u32 trigger_tc = iir & GEN11_DE_TC_HOTPLUG_MASK;
1831b796b971SDhinakaran Pandiyan 	u32 trigger_tbt = iir & GEN11_DE_TBT_HOTPLUG_MASK;
1832121e758eSDhinakaran Pandiyan 
1833121e758eSDhinakaran Pandiyan 	if (trigger_tc) {
1834b796b971SDhinakaran Pandiyan 		u32 dig_hotplug_reg;
1835b796b971SDhinakaran Pandiyan 
18368cee664dSAndrzej Hajda 		dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, GEN11_TC_HOTPLUG_CTL, 0, 0);
1837121e758eSDhinakaran Pandiyan 
18380398993bSVille Syrjälä 		intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
18390398993bSVille Syrjälä 				   trigger_tc, dig_hotplug_reg,
18405a4dd6f0SJani Nikula 				   dev_priv->display.hotplug.hpd,
1841da51e4baSVille Syrjälä 				   gen11_port_hotplug_long_detect);
1842121e758eSDhinakaran Pandiyan 	}
1843b796b971SDhinakaran Pandiyan 
1844b796b971SDhinakaran Pandiyan 	if (trigger_tbt) {
1845b796b971SDhinakaran Pandiyan 		u32 dig_hotplug_reg;
1846b796b971SDhinakaran Pandiyan 
18478cee664dSAndrzej Hajda 		dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, GEN11_TBT_HOTPLUG_CTL, 0, 0);
1848b796b971SDhinakaran Pandiyan 
18490398993bSVille Syrjälä 		intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
18500398993bSVille Syrjälä 				   trigger_tbt, dig_hotplug_reg,
18515a4dd6f0SJani Nikula 				   dev_priv->display.hotplug.hpd,
1852da51e4baSVille Syrjälä 				   gen11_port_hotplug_long_detect);
1853b796b971SDhinakaran Pandiyan 	}
1854b796b971SDhinakaran Pandiyan 
1855b796b971SDhinakaran Pandiyan 	if (pin_mask)
1856b796b971SDhinakaran Pandiyan 		intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
1857b796b971SDhinakaran Pandiyan 	else
185800376ccfSWambui Karuga 		drm_err(&dev_priv->drm,
185900376ccfSWambui Karuga 			"Unexpected DE HPD interrupt 0x%08x\n", iir);
1860121e758eSDhinakaran Pandiyan }
1861121e758eSDhinakaran Pandiyan 
18629d17210fSLucas De Marchi static u32 gen8_de_port_aux_mask(struct drm_i915_private *dev_priv)
18639d17210fSLucas De Marchi {
186455523360SLucas De Marchi 	u32 mask;
18659d17210fSLucas De Marchi 
186620fe778fSMatt Roper 	if (DISPLAY_VER(dev_priv) >= 13)
186720fe778fSMatt Roper 		return TGL_DE_PORT_AUX_DDIA |
186820fe778fSMatt Roper 			TGL_DE_PORT_AUX_DDIB |
186920fe778fSMatt Roper 			TGL_DE_PORT_AUX_DDIC |
187020fe778fSMatt Roper 			XELPD_DE_PORT_AUX_DDID |
187120fe778fSMatt Roper 			XELPD_DE_PORT_AUX_DDIE |
187220fe778fSMatt Roper 			TGL_DE_PORT_AUX_USBC1 |
187320fe778fSMatt Roper 			TGL_DE_PORT_AUX_USBC2 |
187420fe778fSMatt Roper 			TGL_DE_PORT_AUX_USBC3 |
187520fe778fSMatt Roper 			TGL_DE_PORT_AUX_USBC4;
187620fe778fSMatt Roper 	else if (DISPLAY_VER(dev_priv) >= 12)
187755523360SLucas De Marchi 		return TGL_DE_PORT_AUX_DDIA |
187855523360SLucas De Marchi 			TGL_DE_PORT_AUX_DDIB |
1879e5df52dcSMatt Roper 			TGL_DE_PORT_AUX_DDIC |
1880e5df52dcSMatt Roper 			TGL_DE_PORT_AUX_USBC1 |
1881e5df52dcSMatt Roper 			TGL_DE_PORT_AUX_USBC2 |
1882e5df52dcSMatt Roper 			TGL_DE_PORT_AUX_USBC3 |
1883e5df52dcSMatt Roper 			TGL_DE_PORT_AUX_USBC4 |
1884e5df52dcSMatt Roper 			TGL_DE_PORT_AUX_USBC5 |
1885e5df52dcSMatt Roper 			TGL_DE_PORT_AUX_USBC6;
1886e5df52dcSMatt Roper 
188755523360SLucas De Marchi 
188855523360SLucas De Marchi 	mask = GEN8_AUX_CHANNEL_A;
1889373abf1aSMatt Roper 	if (DISPLAY_VER(dev_priv) >= 9)
18909d17210fSLucas De Marchi 		mask |= GEN9_AUX_CHANNEL_B |
18919d17210fSLucas De Marchi 			GEN9_AUX_CHANNEL_C |
18929d17210fSLucas De Marchi 			GEN9_AUX_CHANNEL_D;
18939d17210fSLucas De Marchi 
1894938a8a9aSLucas De Marchi 	if (DISPLAY_VER(dev_priv) == 11) {
1895938a8a9aSLucas De Marchi 		mask |= ICL_AUX_CHANNEL_F;
189655523360SLucas De Marchi 		mask |= ICL_AUX_CHANNEL_E;
1897938a8a9aSLucas De Marchi 	}
18989d17210fSLucas De Marchi 
18999d17210fSLucas De Marchi 	return mask;
19009d17210fSLucas De Marchi }
19019d17210fSLucas De Marchi 
19025270130dSVille Syrjälä static u32 gen8_de_pipe_fault_mask(struct drm_i915_private *dev_priv)
19035270130dSVille Syrjälä {
19041649a4ccSMatt Roper 	if (DISPLAY_VER(dev_priv) >= 13 || HAS_D12_PLANE_MINIMIZATION(dev_priv))
190599e2d8bcSMatt Roper 		return RKL_DE_PIPE_IRQ_FAULT_ERRORS;
1906373abf1aSMatt Roper 	else if (DISPLAY_VER(dev_priv) >= 11)
1907d506a65dSMatt Roper 		return GEN11_DE_PIPE_IRQ_FAULT_ERRORS;
1908373abf1aSMatt Roper 	else if (DISPLAY_VER(dev_priv) >= 9)
19095270130dSVille Syrjälä 		return GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
19105270130dSVille Syrjälä 	else
19115270130dSVille Syrjälä 		return GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
19125270130dSVille Syrjälä }
19135270130dSVille Syrjälä 
191446c63d24SJosé Roberto de Souza static void
191546c63d24SJosé Roberto de Souza gen8_de_misc_irq_handler(struct drm_i915_private *dev_priv, u32 iir)
1916abd58f01SBen Widawsky {
1917e04f7eceSVille Syrjälä 	bool found = false;
1918e04f7eceSVille Syrjälä 
1919e04f7eceSVille Syrjälä 	if (iir & GEN8_DE_MISC_GSE) {
192091d14251STvrtko Ursulin 		intel_opregion_asle_intr(dev_priv);
1921e04f7eceSVille Syrjälä 		found = true;
1922e04f7eceSVille Syrjälä 	}
1923e04f7eceSVille Syrjälä 
1924e04f7eceSVille Syrjälä 	if (iir & GEN8_DE_EDP_PSR) {
1925b64d6c51SGwan-gyeong Mun 		struct intel_encoder *encoder;
19268241cfbeSJosé Roberto de Souza 		u32 psr_iir;
19278241cfbeSJosé Roberto de Souza 		i915_reg_t iir_reg;
19288241cfbeSJosé Roberto de Souza 
1929a22af61dSJosé Roberto de Souza 		for_each_intel_encoder_with_psr(&dev_priv->drm, encoder) {
1930b64d6c51SGwan-gyeong Mun 			struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1931b64d6c51SGwan-gyeong Mun 
1932373abf1aSMatt Roper 			if (DISPLAY_VER(dev_priv) >= 12)
1933b64d6c51SGwan-gyeong Mun 				iir_reg = TRANS_PSR_IIR(intel_dp->psr.transcoder);
19348241cfbeSJosé Roberto de Souza 			else
19358241cfbeSJosé Roberto de Souza 				iir_reg = EDP_PSR_IIR;
19368241cfbeSJosé Roberto de Souza 
19378cee664dSAndrzej Hajda 			psr_iir = intel_uncore_rmw(&dev_priv->uncore, iir_reg, 0, 0);
19388241cfbeSJosé Roberto de Souza 
19398241cfbeSJosé Roberto de Souza 			if (psr_iir)
19408241cfbeSJosé Roberto de Souza 				found = true;
194154fd3149SDhinakaran Pandiyan 
1942b64d6c51SGwan-gyeong Mun 			intel_psr_irq_handler(intel_dp, psr_iir);
1943b64d6c51SGwan-gyeong Mun 
1944b64d6c51SGwan-gyeong Mun 			/* prior GEN12 only have one EDP PSR */
1945373abf1aSMatt Roper 			if (DISPLAY_VER(dev_priv) < 12)
1946b64d6c51SGwan-gyeong Mun 				break;
1947b64d6c51SGwan-gyeong Mun 		}
1948e04f7eceSVille Syrjälä 	}
1949e04f7eceSVille Syrjälä 
1950e04f7eceSVille Syrjälä 	if (!found)
195100376ccfSWambui Karuga 		drm_err(&dev_priv->drm, "Unexpected DE Misc interrupt\n");
1952abd58f01SBen Widawsky }
195346c63d24SJosé Roberto de Souza 
195400acb329SVandita Kulkarni static void gen11_dsi_te_interrupt_handler(struct drm_i915_private *dev_priv,
195500acb329SVandita Kulkarni 					   u32 te_trigger)
195600acb329SVandita Kulkarni {
195700acb329SVandita Kulkarni 	enum pipe pipe = INVALID_PIPE;
195800acb329SVandita Kulkarni 	enum transcoder dsi_trans;
195900acb329SVandita Kulkarni 	enum port port;
196000acb329SVandita Kulkarni 	u32 val, tmp;
196100acb329SVandita Kulkarni 
196200acb329SVandita Kulkarni 	/*
196300acb329SVandita Kulkarni 	 * Incase of dual link, TE comes from DSI_1
196400acb329SVandita Kulkarni 	 * this is to check if dual link is enabled
196500acb329SVandita Kulkarni 	 */
19662939eb06SJani Nikula 	val = intel_uncore_read(&dev_priv->uncore, TRANS_DDI_FUNC_CTL2(TRANSCODER_DSI_0));
196700acb329SVandita Kulkarni 	val &= PORT_SYNC_MODE_ENABLE;
196800acb329SVandita Kulkarni 
196900acb329SVandita Kulkarni 	/*
197000acb329SVandita Kulkarni 	 * if dual link is enabled, then read DSI_0
197100acb329SVandita Kulkarni 	 * transcoder registers
197200acb329SVandita Kulkarni 	 */
197300acb329SVandita Kulkarni 	port = ((te_trigger & DSI1_TE && val) || (te_trigger & DSI0_TE)) ?
197400acb329SVandita Kulkarni 						  PORT_A : PORT_B;
197500acb329SVandita Kulkarni 	dsi_trans = (port == PORT_A) ? TRANSCODER_DSI_0 : TRANSCODER_DSI_1;
197600acb329SVandita Kulkarni 
197700acb329SVandita Kulkarni 	/* Check if DSI configured in command mode */
19782939eb06SJani Nikula 	val = intel_uncore_read(&dev_priv->uncore, DSI_TRANS_FUNC_CONF(dsi_trans));
197900acb329SVandita Kulkarni 	val = val & OP_MODE_MASK;
198000acb329SVandita Kulkarni 
198100acb329SVandita Kulkarni 	if (val != CMD_MODE_NO_GATE && val != CMD_MODE_TE_GATE) {
198200acb329SVandita Kulkarni 		drm_err(&dev_priv->drm, "DSI trancoder not configured in command mode\n");
198300acb329SVandita Kulkarni 		return;
198400acb329SVandita Kulkarni 	}
198500acb329SVandita Kulkarni 
198600acb329SVandita Kulkarni 	/* Get PIPE for handling VBLANK event */
19872939eb06SJani Nikula 	val = intel_uncore_read(&dev_priv->uncore, TRANS_DDI_FUNC_CTL(dsi_trans));
198800acb329SVandita Kulkarni 	switch (val & TRANS_DDI_EDP_INPUT_MASK) {
198900acb329SVandita Kulkarni 	case TRANS_DDI_EDP_INPUT_A_ON:
199000acb329SVandita Kulkarni 		pipe = PIPE_A;
199100acb329SVandita Kulkarni 		break;
199200acb329SVandita Kulkarni 	case TRANS_DDI_EDP_INPUT_B_ONOFF:
199300acb329SVandita Kulkarni 		pipe = PIPE_B;
199400acb329SVandita Kulkarni 		break;
199500acb329SVandita Kulkarni 	case TRANS_DDI_EDP_INPUT_C_ONOFF:
199600acb329SVandita Kulkarni 		pipe = PIPE_C;
199700acb329SVandita Kulkarni 		break;
199800acb329SVandita Kulkarni 	default:
199900acb329SVandita Kulkarni 		drm_err(&dev_priv->drm, "Invalid PIPE\n");
200000acb329SVandita Kulkarni 		return;
200100acb329SVandita Kulkarni 	}
200200acb329SVandita Kulkarni 
200300acb329SVandita Kulkarni 	intel_handle_vblank(dev_priv, pipe);
200400acb329SVandita Kulkarni 
200500acb329SVandita Kulkarni 	/* clear TE in dsi IIR */
200600acb329SVandita Kulkarni 	port = (te_trigger & DSI1_TE) ? PORT_B : PORT_A;
20078cee664dSAndrzej Hajda 	tmp = intel_uncore_rmw(&dev_priv->uncore, DSI_INTR_IDENT_REG(port), 0, 0);
200800acb329SVandita Kulkarni }
200900acb329SVandita Kulkarni 
2010cda195f1SVille Syrjälä static u32 gen8_de_pipe_flip_done_mask(struct drm_i915_private *i915)
2011cda195f1SVille Syrjälä {
2012373abf1aSMatt Roper 	if (DISPLAY_VER(i915) >= 9)
2013cda195f1SVille Syrjälä 		return GEN9_PIPE_PLANE1_FLIP_DONE;
2014cda195f1SVille Syrjälä 	else
2015cda195f1SVille Syrjälä 		return GEN8_PIPE_PRIMARY_FLIP_DONE;
2016cda195f1SVille Syrjälä }
2017cda195f1SVille Syrjälä 
20188bcc0840SMatt Roper u32 gen8_de_pipe_underrun_mask(struct drm_i915_private *dev_priv)
20198bcc0840SMatt Roper {
20208bcc0840SMatt Roper 	u32 mask = GEN8_PIPE_FIFO_UNDERRUN;
20218bcc0840SMatt Roper 
20228bcc0840SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 13)
20238bcc0840SMatt Roper 		mask |= XELPD_PIPE_SOFT_UNDERRUN |
20248bcc0840SMatt Roper 			XELPD_PIPE_HARD_UNDERRUN;
20258bcc0840SMatt Roper 
20268bcc0840SMatt Roper 	return mask;
20278bcc0840SMatt Roper }
20288bcc0840SMatt Roper 
202946c63d24SJosé Roberto de Souza static irqreturn_t
203046c63d24SJosé Roberto de Souza gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl)
203146c63d24SJosé Roberto de Souza {
203246c63d24SJosé Roberto de Souza 	irqreturn_t ret = IRQ_NONE;
203346c63d24SJosé Roberto de Souza 	u32 iir;
203446c63d24SJosé Roberto de Souza 	enum pipe pipe;
203546c63d24SJosé Roberto de Souza 
2036a844cfbeSJosé Roberto de Souza 	drm_WARN_ON_ONCE(&dev_priv->drm, !HAS_DISPLAY(dev_priv));
2037a844cfbeSJosé Roberto de Souza 
203846c63d24SJosé Roberto de Souza 	if (master_ctl & GEN8_DE_MISC_IRQ) {
20392939eb06SJani Nikula 		iir = intel_uncore_read(&dev_priv->uncore, GEN8_DE_MISC_IIR);
204046c63d24SJosé Roberto de Souza 		if (iir) {
20412939eb06SJani Nikula 			intel_uncore_write(&dev_priv->uncore, GEN8_DE_MISC_IIR, iir);
204246c63d24SJosé Roberto de Souza 			ret = IRQ_HANDLED;
204346c63d24SJosé Roberto de Souza 			gen8_de_misc_irq_handler(dev_priv, iir);
204446c63d24SJosé Roberto de Souza 		} else {
20459a4cea62SLucas De Marchi 			drm_err_ratelimited(&dev_priv->drm,
204600376ccfSWambui Karuga 					    "The master control interrupt lied (DE MISC)!\n");
2047abd58f01SBen Widawsky 		}
204846c63d24SJosé Roberto de Souza 	}
2049abd58f01SBen Widawsky 
2050373abf1aSMatt Roper 	if (DISPLAY_VER(dev_priv) >= 11 && (master_ctl & GEN11_DE_HPD_IRQ)) {
20512939eb06SJani Nikula 		iir = intel_uncore_read(&dev_priv->uncore, GEN11_DE_HPD_IIR);
2052121e758eSDhinakaran Pandiyan 		if (iir) {
20532939eb06SJani Nikula 			intel_uncore_write(&dev_priv->uncore, GEN11_DE_HPD_IIR, iir);
2054121e758eSDhinakaran Pandiyan 			ret = IRQ_HANDLED;
2055121e758eSDhinakaran Pandiyan 			gen11_hpd_irq_handler(dev_priv, iir);
2056121e758eSDhinakaran Pandiyan 		} else {
20579a4cea62SLucas De Marchi 			drm_err_ratelimited(&dev_priv->drm,
205800376ccfSWambui Karuga 					    "The master control interrupt lied, (DE HPD)!\n");
2059121e758eSDhinakaran Pandiyan 		}
2060121e758eSDhinakaran Pandiyan 	}
2061121e758eSDhinakaran Pandiyan 
20626d766f02SDaniel Vetter 	if (master_ctl & GEN8_DE_PORT_IRQ) {
20632939eb06SJani Nikula 		iir = intel_uncore_read(&dev_priv->uncore, GEN8_DE_PORT_IIR);
2064e32192e1STvrtko Ursulin 		if (iir) {
2065d04a492dSShashank Sharma 			bool found = false;
2066cebd87a0SVille Syrjälä 
20672939eb06SJani Nikula 			intel_uncore_write(&dev_priv->uncore, GEN8_DE_PORT_IIR, iir);
20686d766f02SDaniel Vetter 			ret = IRQ_HANDLED;
206988e04703SJesse Barnes 
20709d17210fSLucas De Marchi 			if (iir & gen8_de_port_aux_mask(dev_priv)) {
207191d14251STvrtko Ursulin 				dp_aux_irq_handler(dev_priv);
2072d04a492dSShashank Sharma 				found = true;
2073d04a492dSShashank Sharma 			}
2074d04a492dSShashank Sharma 
207570bfb307SMatt Roper 			if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
20769a55a620SVille Syrjälä 				u32 hotplug_trigger = iir & BXT_DE_PORT_HOTPLUG_MASK;
20779a55a620SVille Syrjälä 
20789a55a620SVille Syrjälä 				if (hotplug_trigger) {
20799a55a620SVille Syrjälä 					bxt_hpd_irq_handler(dev_priv, hotplug_trigger);
2080d04a492dSShashank Sharma 					found = true;
2081d04a492dSShashank Sharma 				}
2082e32192e1STvrtko Ursulin 			} else if (IS_BROADWELL(dev_priv)) {
20839a55a620SVille Syrjälä 				u32 hotplug_trigger = iir & BDW_DE_PORT_HOTPLUG_MASK;
20849a55a620SVille Syrjälä 
20859a55a620SVille Syrjälä 				if (hotplug_trigger) {
20869a55a620SVille Syrjälä 					ilk_hpd_irq_handler(dev_priv, hotplug_trigger);
2087e32192e1STvrtko Ursulin 					found = true;
2088e32192e1STvrtko Ursulin 				}
2089e32192e1STvrtko Ursulin 			}
2090d04a492dSShashank Sharma 
209170bfb307SMatt Roper 			if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
209270bfb307SMatt Roper 			    (iir & BXT_DE_PORT_GMBUS)) {
209391d14251STvrtko Ursulin 				gmbus_irq_handler(dev_priv);
20949e63743eSShashank Sharma 				found = true;
20959e63743eSShashank Sharma 			}
20969e63743eSShashank Sharma 
2097373abf1aSMatt Roper 			if (DISPLAY_VER(dev_priv) >= 11) {
20989a55a620SVille Syrjälä 				u32 te_trigger = iir & (DSI0_TE | DSI1_TE);
20999a55a620SVille Syrjälä 
21009a55a620SVille Syrjälä 				if (te_trigger) {
21019a55a620SVille Syrjälä 					gen11_dsi_te_interrupt_handler(dev_priv, te_trigger);
210200acb329SVandita Kulkarni 					found = true;
210300acb329SVandita Kulkarni 				}
210400acb329SVandita Kulkarni 			}
210500acb329SVandita Kulkarni 
2106d04a492dSShashank Sharma 			if (!found)
21079a4cea62SLucas De Marchi 				drm_err_ratelimited(&dev_priv->drm,
210800376ccfSWambui Karuga 						    "Unexpected DE Port interrupt\n");
21096d766f02SDaniel Vetter 		}
211038cc46d7SOscar Mateo 		else
21119a4cea62SLucas De Marchi 			drm_err_ratelimited(&dev_priv->drm,
211200376ccfSWambui Karuga 					    "The master control interrupt lied (DE PORT)!\n");
21136d766f02SDaniel Vetter 	}
21146d766f02SDaniel Vetter 
2115055e393fSDamien Lespiau 	for_each_pipe(dev_priv, pipe) {
2116fd3a4024SDaniel Vetter 		u32 fault_errors;
2117abd58f01SBen Widawsky 
2118c42664ccSDaniel Vetter 		if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2119c42664ccSDaniel Vetter 			continue;
2120c42664ccSDaniel Vetter 
21212939eb06SJani Nikula 		iir = intel_uncore_read(&dev_priv->uncore, GEN8_DE_PIPE_IIR(pipe));
2122e32192e1STvrtko Ursulin 		if (!iir) {
21239a4cea62SLucas De Marchi 			drm_err_ratelimited(&dev_priv->drm,
212400376ccfSWambui Karuga 					    "The master control interrupt lied (DE PIPE)!\n");
2125e32192e1STvrtko Ursulin 			continue;
2126e32192e1STvrtko Ursulin 		}
2127770de83dSDamien Lespiau 
2128e32192e1STvrtko Ursulin 		ret = IRQ_HANDLED;
21292939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, GEN8_DE_PIPE_IIR(pipe), iir);
2130e32192e1STvrtko Ursulin 
2131fd3a4024SDaniel Vetter 		if (iir & GEN8_PIPE_VBLANK)
2132aca9310aSAnshuman Gupta 			intel_handle_vblank(dev_priv, pipe);
2133abd58f01SBen Widawsky 
2134cda195f1SVille Syrjälä 		if (iir & gen8_de_pipe_flip_done_mask(dev_priv))
21351288f9b0SKarthik B S 			flip_done_handler(dev_priv, pipe);
21361288f9b0SKarthik B S 
2137e32192e1STvrtko Ursulin 		if (iir & GEN8_PIPE_CDCLK_CRC_DONE)
213891d14251STvrtko Ursulin 			hsw_pipe_crc_irq_handler(dev_priv, pipe);
21390fbe7870SDaniel Vetter 
21408bcc0840SMatt Roper 		if (iir & gen8_de_pipe_underrun_mask(dev_priv))
2141e32192e1STvrtko Ursulin 			intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
214238d83c96SDaniel Vetter 
21435270130dSVille Syrjälä 		fault_errors = iir & gen8_de_pipe_fault_mask(dev_priv);
2144770de83dSDamien Lespiau 		if (fault_errors)
21459a4cea62SLucas De Marchi 			drm_err_ratelimited(&dev_priv->drm,
214600376ccfSWambui Karuga 					    "Fault errors on pipe %c: 0x%08x\n",
214730100f2bSDaniel Vetter 					    pipe_name(pipe),
2148e32192e1STvrtko Ursulin 					    fault_errors);
2149abd58f01SBen Widawsky 	}
2150abd58f01SBen Widawsky 
215191d14251STvrtko Ursulin 	if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) &&
2152266ea3d9SShashank Sharma 	    master_ctl & GEN8_DE_PCH_IRQ) {
215392d03a80SDaniel Vetter 		/*
215492d03a80SDaniel Vetter 		 * FIXME(BDW): Assume for now that the new interrupt handling
215592d03a80SDaniel Vetter 		 * scheme also closed the SDE interrupt handling race we've seen
215692d03a80SDaniel Vetter 		 * on older pch-split platforms. But this needs testing.
215792d03a80SDaniel Vetter 		 */
21582939eb06SJani Nikula 		iir = intel_uncore_read(&dev_priv->uncore, SDEIIR);
2159e32192e1STvrtko Ursulin 		if (iir) {
21602939eb06SJani Nikula 			intel_uncore_write(&dev_priv->uncore, SDEIIR, iir);
216192d03a80SDaniel Vetter 			ret = IRQ_HANDLED;
21626dbf30ceSVille Syrjälä 
216358676af6SLucas De Marchi 			if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
216458676af6SLucas De Marchi 				icp_irq_handler(dev_priv, iir);
2165c6c30b91SRodrigo Vivi 			else if (INTEL_PCH_TYPE(dev_priv) >= PCH_SPT)
216691d14251STvrtko Ursulin 				spt_irq_handler(dev_priv, iir);
21676dbf30ceSVille Syrjälä 			else
216891d14251STvrtko Ursulin 				cpt_irq_handler(dev_priv, iir);
21692dfb0b81SJani Nikula 		} else {
21702dfb0b81SJani Nikula 			/*
21712dfb0b81SJani Nikula 			 * Like on previous PCH there seems to be something
21722dfb0b81SJani Nikula 			 * fishy going on with forwarding PCH interrupts.
21732dfb0b81SJani Nikula 			 */
217400376ccfSWambui Karuga 			drm_dbg(&dev_priv->drm,
217500376ccfSWambui Karuga 				"The master control interrupt lied (SDE)!\n");
21762dfb0b81SJani Nikula 		}
217792d03a80SDaniel Vetter 	}
217892d03a80SDaniel Vetter 
2179f11a0f46STvrtko Ursulin 	return ret;
2180f11a0f46STvrtko Ursulin }
2181f11a0f46STvrtko Ursulin 
21824376b9c9SMika Kuoppala static inline u32 gen8_master_intr_disable(void __iomem * const regs)
21834376b9c9SMika Kuoppala {
21844376b9c9SMika Kuoppala 	raw_reg_write(regs, GEN8_MASTER_IRQ, 0);
21854376b9c9SMika Kuoppala 
21864376b9c9SMika Kuoppala 	/*
21874376b9c9SMika Kuoppala 	 * Now with master disabled, get a sample of level indications
21884376b9c9SMika Kuoppala 	 * for this interrupt. Indications will be cleared on related acks.
21894376b9c9SMika Kuoppala 	 * New indications can and will light up during processing,
21904376b9c9SMika Kuoppala 	 * and will generate new interrupt after enabling master.
21914376b9c9SMika Kuoppala 	 */
21924376b9c9SMika Kuoppala 	return raw_reg_read(regs, GEN8_MASTER_IRQ);
21934376b9c9SMika Kuoppala }
21944376b9c9SMika Kuoppala 
21954376b9c9SMika Kuoppala static inline void gen8_master_intr_enable(void __iomem * const regs)
21964376b9c9SMika Kuoppala {
21974376b9c9SMika Kuoppala 	raw_reg_write(regs, GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
21984376b9c9SMika Kuoppala }
21994376b9c9SMika Kuoppala 
2200f11a0f46STvrtko Ursulin static irqreturn_t gen8_irq_handler(int irq, void *arg)
2201f11a0f46STvrtko Ursulin {
2202b318b824SVille Syrjälä 	struct drm_i915_private *dev_priv = arg;
220325286aacSDaniele Ceraolo Spurio 	void __iomem * const regs = dev_priv->uncore.regs;
2204f11a0f46STvrtko Ursulin 	u32 master_ctl;
2205f11a0f46STvrtko Ursulin 
2206f11a0f46STvrtko Ursulin 	if (!intel_irqs_enabled(dev_priv))
2207f11a0f46STvrtko Ursulin 		return IRQ_NONE;
2208f11a0f46STvrtko Ursulin 
22094376b9c9SMika Kuoppala 	master_ctl = gen8_master_intr_disable(regs);
22104376b9c9SMika Kuoppala 	if (!master_ctl) {
22114376b9c9SMika Kuoppala 		gen8_master_intr_enable(regs);
2212f11a0f46STvrtko Ursulin 		return IRQ_NONE;
22134376b9c9SMika Kuoppala 	}
2214f11a0f46STvrtko Ursulin 
22156cc32f15SChris Wilson 	/* Find, queue (onto bottom-halves), then clear each source */
22162cbc876dSMichał Winiarski 	gen8_gt_irq_handler(to_gt(dev_priv), master_ctl);
2217f0fd96f5SChris Wilson 
2218f0fd96f5SChris Wilson 	/* IRQs are synced during runtime_suspend, we don't require a wakeref */
2219f0fd96f5SChris Wilson 	if (master_ctl & ~GEN8_GT_IRQS) {
22209102650fSDaniele Ceraolo Spurio 		disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
222155ef72f2SChris Wilson 		gen8_de_irq_handler(dev_priv, master_ctl);
22229102650fSDaniele Ceraolo Spurio 		enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
2223f0fd96f5SChris Wilson 	}
2224f11a0f46STvrtko Ursulin 
22254376b9c9SMika Kuoppala 	gen8_master_intr_enable(regs);
2226abd58f01SBen Widawsky 
22279c6508b9SThomas Gleixner 	pmu_irq_stats(dev_priv, IRQ_HANDLED);
22289c6508b9SThomas Gleixner 
222955ef72f2SChris Wilson 	return IRQ_HANDLED;
2230abd58f01SBen Widawsky }
2231abd58f01SBen Widawsky 
223251951ae7SMika Kuoppala static u32
2233ddcf980fSAnusha Srivatsa gen11_gu_misc_irq_ack(struct drm_i915_private *i915, const u32 master_ctl)
2234df0d28c1SDhinakaran Pandiyan {
2235ddcf980fSAnusha Srivatsa 	void __iomem * const regs = i915->uncore.regs;
22367a909383SChris Wilson 	u32 iir;
2237df0d28c1SDhinakaran Pandiyan 
2238df0d28c1SDhinakaran Pandiyan 	if (!(master_ctl & GEN11_GU_MISC_IRQ))
22397a909383SChris Wilson 		return 0;
2240df0d28c1SDhinakaran Pandiyan 
22417a909383SChris Wilson 	iir = raw_reg_read(regs, GEN11_GU_MISC_IIR);
22427a909383SChris Wilson 	if (likely(iir))
22437a909383SChris Wilson 		raw_reg_write(regs, GEN11_GU_MISC_IIR, iir);
22447a909383SChris Wilson 
22457a909383SChris Wilson 	return iir;
2246df0d28c1SDhinakaran Pandiyan }
2247df0d28c1SDhinakaran Pandiyan 
2248df0d28c1SDhinakaran Pandiyan static void
2249ddcf980fSAnusha Srivatsa gen11_gu_misc_irq_handler(struct drm_i915_private *i915, const u32 iir)
2250df0d28c1SDhinakaran Pandiyan {
2251df0d28c1SDhinakaran Pandiyan 	if (iir & GEN11_GU_MISC_GSE)
2252ddcf980fSAnusha Srivatsa 		intel_opregion_asle_intr(i915);
2253df0d28c1SDhinakaran Pandiyan }
2254df0d28c1SDhinakaran Pandiyan 
225581067b71SMika Kuoppala static inline u32 gen11_master_intr_disable(void __iomem * const regs)
225681067b71SMika Kuoppala {
225781067b71SMika Kuoppala 	raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, 0);
225881067b71SMika Kuoppala 
225981067b71SMika Kuoppala 	/*
226081067b71SMika Kuoppala 	 * Now with master disabled, get a sample of level indications
226181067b71SMika Kuoppala 	 * for this interrupt. Indications will be cleared on related acks.
226281067b71SMika Kuoppala 	 * New indications can and will light up during processing,
226381067b71SMika Kuoppala 	 * and will generate new interrupt after enabling master.
226481067b71SMika Kuoppala 	 */
226581067b71SMika Kuoppala 	return raw_reg_read(regs, GEN11_GFX_MSTR_IRQ);
226681067b71SMika Kuoppala }
226781067b71SMika Kuoppala 
226881067b71SMika Kuoppala static inline void gen11_master_intr_enable(void __iomem * const regs)
226981067b71SMika Kuoppala {
227081067b71SMika Kuoppala 	raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, GEN11_MASTER_IRQ);
227181067b71SMika Kuoppala }
227281067b71SMika Kuoppala 
2273a3265d85SMatt Roper static void
2274a3265d85SMatt Roper gen11_display_irq_handler(struct drm_i915_private *i915)
2275a3265d85SMatt Roper {
2276a3265d85SMatt Roper 	void __iomem * const regs = i915->uncore.regs;
2277a3265d85SMatt Roper 	const u32 disp_ctl = raw_reg_read(regs, GEN11_DISPLAY_INT_CTL);
2278a3265d85SMatt Roper 
2279a3265d85SMatt Roper 	disable_rpm_wakeref_asserts(&i915->runtime_pm);
2280a3265d85SMatt Roper 	/*
2281a3265d85SMatt Roper 	 * GEN11_DISPLAY_INT_CTL has same format as GEN8_MASTER_IRQ
2282a3265d85SMatt Roper 	 * for the display related bits.
2283a3265d85SMatt Roper 	 */
2284a3265d85SMatt Roper 	raw_reg_write(regs, GEN11_DISPLAY_INT_CTL, 0x0);
2285a3265d85SMatt Roper 	gen8_de_irq_handler(i915, disp_ctl);
2286a3265d85SMatt Roper 	raw_reg_write(regs, GEN11_DISPLAY_INT_CTL,
2287a3265d85SMatt Roper 		      GEN11_DISPLAY_IRQ_ENABLE);
2288a3265d85SMatt Roper 
2289a3265d85SMatt Roper 	enable_rpm_wakeref_asserts(&i915->runtime_pm);
2290a3265d85SMatt Roper }
2291a3265d85SMatt Roper 
229222e26af7SPaulo Zanoni static irqreturn_t gen11_irq_handler(int irq, void *arg)
229351951ae7SMika Kuoppala {
229422e26af7SPaulo Zanoni 	struct drm_i915_private *i915 = arg;
229525286aacSDaniele Ceraolo Spurio 	void __iomem * const regs = i915->uncore.regs;
22962cbc876dSMichał Winiarski 	struct intel_gt *gt = to_gt(i915);
229751951ae7SMika Kuoppala 	u32 master_ctl;
2298df0d28c1SDhinakaran Pandiyan 	u32 gu_misc_iir;
229951951ae7SMika Kuoppala 
230051951ae7SMika Kuoppala 	if (!intel_irqs_enabled(i915))
230151951ae7SMika Kuoppala 		return IRQ_NONE;
230251951ae7SMika Kuoppala 
230322e26af7SPaulo Zanoni 	master_ctl = gen11_master_intr_disable(regs);
230481067b71SMika Kuoppala 	if (!master_ctl) {
230522e26af7SPaulo Zanoni 		gen11_master_intr_enable(regs);
230651951ae7SMika Kuoppala 		return IRQ_NONE;
230781067b71SMika Kuoppala 	}
230851951ae7SMika Kuoppala 
23096cc32f15SChris Wilson 	/* Find, queue (onto bottom-halves), then clear each source */
23109b77011eSTvrtko Ursulin 	gen11_gt_irq_handler(gt, master_ctl);
231151951ae7SMika Kuoppala 
231251951ae7SMika Kuoppala 	/* IRQs are synced during runtime_suspend, we don't require a wakeref */
2313a3265d85SMatt Roper 	if (master_ctl & GEN11_DISPLAY_IRQ)
2314a3265d85SMatt Roper 		gen11_display_irq_handler(i915);
231551951ae7SMika Kuoppala 
2316ddcf980fSAnusha Srivatsa 	gu_misc_iir = gen11_gu_misc_irq_ack(i915, master_ctl);
2317df0d28c1SDhinakaran Pandiyan 
231822e26af7SPaulo Zanoni 	gen11_master_intr_enable(regs);
231951951ae7SMika Kuoppala 
2320ddcf980fSAnusha Srivatsa 	gen11_gu_misc_irq_handler(i915, gu_misc_iir);
2321df0d28c1SDhinakaran Pandiyan 
23229c6508b9SThomas Gleixner 	pmu_irq_stats(i915, IRQ_HANDLED);
23239c6508b9SThomas Gleixner 
232451951ae7SMika Kuoppala 	return IRQ_HANDLED;
232551951ae7SMika Kuoppala }
232651951ae7SMika Kuoppala 
232722e26af7SPaulo Zanoni static inline u32 dg1_master_intr_disable(void __iomem * const regs)
232897b492f5SLucas De Marchi {
232997b492f5SLucas De Marchi 	u32 val;
233097b492f5SLucas De Marchi 
233197b492f5SLucas De Marchi 	/* First disable interrupts */
233222e26af7SPaulo Zanoni 	raw_reg_write(regs, DG1_MSTR_TILE_INTR, 0);
233397b492f5SLucas De Marchi 
233497b492f5SLucas De Marchi 	/* Get the indication levels and ack the master unit */
233522e26af7SPaulo Zanoni 	val = raw_reg_read(regs, DG1_MSTR_TILE_INTR);
233697b492f5SLucas De Marchi 	if (unlikely(!val))
233797b492f5SLucas De Marchi 		return 0;
233897b492f5SLucas De Marchi 
233922e26af7SPaulo Zanoni 	raw_reg_write(regs, DG1_MSTR_TILE_INTR, val);
234097b492f5SLucas De Marchi 
234197b492f5SLucas De Marchi 	return val;
234297b492f5SLucas De Marchi }
234397b492f5SLucas De Marchi 
234497b492f5SLucas De Marchi static inline void dg1_master_intr_enable(void __iomem * const regs)
234597b492f5SLucas De Marchi {
234622e26af7SPaulo Zanoni 	raw_reg_write(regs, DG1_MSTR_TILE_INTR, DG1_MSTR_IRQ);
234797b492f5SLucas De Marchi }
234897b492f5SLucas De Marchi 
234997b492f5SLucas De Marchi static irqreturn_t dg1_irq_handler(int irq, void *arg)
235097b492f5SLucas De Marchi {
235122e26af7SPaulo Zanoni 	struct drm_i915_private * const i915 = arg;
23522cbc876dSMichał Winiarski 	struct intel_gt *gt = to_gt(i915);
2353fd4d7904SPaulo Zanoni 	void __iomem * const regs = gt->uncore->regs;
235422e26af7SPaulo Zanoni 	u32 master_tile_ctl, master_ctl;
235522e26af7SPaulo Zanoni 	u32 gu_misc_iir;
235622e26af7SPaulo Zanoni 
235722e26af7SPaulo Zanoni 	if (!intel_irqs_enabled(i915))
235822e26af7SPaulo Zanoni 		return IRQ_NONE;
235922e26af7SPaulo Zanoni 
236022e26af7SPaulo Zanoni 	master_tile_ctl = dg1_master_intr_disable(regs);
236122e26af7SPaulo Zanoni 	if (!master_tile_ctl) {
236222e26af7SPaulo Zanoni 		dg1_master_intr_enable(regs);
236322e26af7SPaulo Zanoni 		return IRQ_NONE;
236422e26af7SPaulo Zanoni 	}
236522e26af7SPaulo Zanoni 
236622e26af7SPaulo Zanoni 	/* FIXME: we only support tile 0 for now. */
236722e26af7SPaulo Zanoni 	if (master_tile_ctl & DG1_MSTR_TILE(0)) {
236822e26af7SPaulo Zanoni 		master_ctl = raw_reg_read(regs, GEN11_GFX_MSTR_IRQ);
236922e26af7SPaulo Zanoni 		raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, master_ctl);
237022e26af7SPaulo Zanoni 	} else {
2371a10234fdSTvrtko Ursulin 		drm_err(&i915->drm, "Tile not supported: 0x%08x\n",
2372a10234fdSTvrtko Ursulin 			master_tile_ctl);
237322e26af7SPaulo Zanoni 		dg1_master_intr_enable(regs);
237422e26af7SPaulo Zanoni 		return IRQ_NONE;
237522e26af7SPaulo Zanoni 	}
237622e26af7SPaulo Zanoni 
237722e26af7SPaulo Zanoni 	gen11_gt_irq_handler(gt, master_ctl);
237822e26af7SPaulo Zanoni 
237922e26af7SPaulo Zanoni 	if (master_ctl & GEN11_DISPLAY_IRQ)
238022e26af7SPaulo Zanoni 		gen11_display_irq_handler(i915);
238122e26af7SPaulo Zanoni 
2382ddcf980fSAnusha Srivatsa 	gu_misc_iir = gen11_gu_misc_irq_ack(i915, master_ctl);
238322e26af7SPaulo Zanoni 
238422e26af7SPaulo Zanoni 	dg1_master_intr_enable(regs);
238522e26af7SPaulo Zanoni 
2386ddcf980fSAnusha Srivatsa 	gen11_gu_misc_irq_handler(i915, gu_misc_iir);
238722e26af7SPaulo Zanoni 
238822e26af7SPaulo Zanoni 	pmu_irq_stats(i915, IRQ_HANDLED);
238922e26af7SPaulo Zanoni 
239022e26af7SPaulo Zanoni 	return IRQ_HANDLED;
239197b492f5SLucas De Marchi }
239297b492f5SLucas De Marchi 
239342f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which
239442f52ef8SKeith Packard  * we use as a pipe index
239542f52ef8SKeith Packard  */
239608fa8fd0SVille Syrjälä int i8xx_enable_vblank(struct drm_crtc *crtc)
23970a3e67a4SJesse Barnes {
239808fa8fd0SVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(crtc->dev);
239908fa8fd0SVille Syrjälä 	enum pipe pipe = to_intel_crtc(crtc)->pipe;
2400e9d21d7fSKeith Packard 	unsigned long irqflags;
240171e0ffa5SJesse Barnes 
24021ec14ad3SChris Wilson 	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
240386e83e35SChris Wilson 	i915_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
240486e83e35SChris Wilson 	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
240586e83e35SChris Wilson 
240686e83e35SChris Wilson 	return 0;
240786e83e35SChris Wilson }
240886e83e35SChris Wilson 
24097d423af9SVille Syrjälä int i915gm_enable_vblank(struct drm_crtc *crtc)
2410d938da6bSVille Syrjälä {
241108fa8fd0SVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2412d938da6bSVille Syrjälä 
24137d423af9SVille Syrjälä 	/*
24147d423af9SVille Syrjälä 	 * Vblank interrupts fail to wake the device up from C2+.
24157d423af9SVille Syrjälä 	 * Disabling render clock gating during C-states avoids
24167d423af9SVille Syrjälä 	 * the problem. There is a small power cost so we do this
24177d423af9SVille Syrjälä 	 * only when vblank interrupts are actually enabled.
24187d423af9SVille Syrjälä 	 */
24197d423af9SVille Syrjälä 	if (dev_priv->vblank_enabled++ == 0)
24202939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, SCPD0, _MASKED_BIT_ENABLE(CSTATE_RENDER_CLOCK_GATE_DISABLE));
2421d938da6bSVille Syrjälä 
242208fa8fd0SVille Syrjälä 	return i8xx_enable_vblank(crtc);
2423d938da6bSVille Syrjälä }
2424d938da6bSVille Syrjälä 
242508fa8fd0SVille Syrjälä int i965_enable_vblank(struct drm_crtc *crtc)
242686e83e35SChris Wilson {
242708fa8fd0SVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(crtc->dev);
242808fa8fd0SVille Syrjälä 	enum pipe pipe = to_intel_crtc(crtc)->pipe;
242986e83e35SChris Wilson 	unsigned long irqflags;
243086e83e35SChris Wilson 
243186e83e35SChris Wilson 	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
24327c463586SKeith Packard 	i915_enable_pipestat(dev_priv, pipe,
2433755e9019SImre Deak 			     PIPE_START_VBLANK_INTERRUPT_STATUS);
24341ec14ad3SChris Wilson 	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
24358692d00eSChris Wilson 
24360a3e67a4SJesse Barnes 	return 0;
24370a3e67a4SJesse Barnes }
24380a3e67a4SJesse Barnes 
243908fa8fd0SVille Syrjälä int ilk_enable_vblank(struct drm_crtc *crtc)
2440f796cf8fSJesse Barnes {
244108fa8fd0SVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(crtc->dev);
244208fa8fd0SVille Syrjälä 	enum pipe pipe = to_intel_crtc(crtc)->pipe;
2443f796cf8fSJesse Barnes 	unsigned long irqflags;
2444373abf1aSMatt Roper 	u32 bit = DISPLAY_VER(dev_priv) >= 7 ?
244586e83e35SChris Wilson 		DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
2446f796cf8fSJesse Barnes 
2447f796cf8fSJesse Barnes 	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2448fbdedaeaSVille Syrjälä 	ilk_enable_display_irq(dev_priv, bit);
2449b1f14ad0SJesse Barnes 	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2450b1f14ad0SJesse Barnes 
24512e8bf223SDhinakaran Pandiyan 	/* Even though there is no DMC, frame counter can get stuck when
24522e8bf223SDhinakaran Pandiyan 	 * PSR is active as no frames are generated.
24532e8bf223SDhinakaran Pandiyan 	 */
24542e8bf223SDhinakaran Pandiyan 	if (HAS_PSR(dev_priv))
245508fa8fd0SVille Syrjälä 		drm_crtc_vblank_restore(crtc);
24562e8bf223SDhinakaran Pandiyan 
2457b1f14ad0SJesse Barnes 	return 0;
2458b1f14ad0SJesse Barnes }
2459b1f14ad0SJesse Barnes 
24609c9e97c4SVandita Kulkarni static bool gen11_dsi_configure_te(struct intel_crtc *intel_crtc,
24619c9e97c4SVandita Kulkarni 				   bool enable)
24629c9e97c4SVandita Kulkarni {
24639c9e97c4SVandita Kulkarni 	struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
24649c9e97c4SVandita Kulkarni 	enum port port;
24659c9e97c4SVandita Kulkarni 
24669c9e97c4SVandita Kulkarni 	if (!(intel_crtc->mode_flags &
24679c9e97c4SVandita Kulkarni 	    (I915_MODE_FLAG_DSI_USE_TE1 | I915_MODE_FLAG_DSI_USE_TE0)))
24689c9e97c4SVandita Kulkarni 		return false;
24699c9e97c4SVandita Kulkarni 
24709c9e97c4SVandita Kulkarni 	/* for dual link cases we consider TE from slave */
24719c9e97c4SVandita Kulkarni 	if (intel_crtc->mode_flags & I915_MODE_FLAG_DSI_USE_TE1)
24729c9e97c4SVandita Kulkarni 		port = PORT_B;
24739c9e97c4SVandita Kulkarni 	else
24749c9e97c4SVandita Kulkarni 		port = PORT_A;
24759c9e97c4SVandita Kulkarni 
24768cee664dSAndrzej Hajda 	intel_uncore_rmw(&dev_priv->uncore, DSI_INTR_MASK_REG(port), DSI_TE_EVENT,
24778cee664dSAndrzej Hajda 			 enable ? 0 : DSI_TE_EVENT);
24789c9e97c4SVandita Kulkarni 
24798cee664dSAndrzej Hajda 	intel_uncore_rmw(&dev_priv->uncore, DSI_INTR_IDENT_REG(port), 0, 0);
24809c9e97c4SVandita Kulkarni 
24819c9e97c4SVandita Kulkarni 	return true;
24829c9e97c4SVandita Kulkarni }
24839c9e97c4SVandita Kulkarni 
2484f15f01a7SVille Syrjälä int bdw_enable_vblank(struct drm_crtc *_crtc)
2485abd58f01SBen Widawsky {
2486f15f01a7SVille Syrjälä 	struct intel_crtc *crtc = to_intel_crtc(_crtc);
2487f15f01a7SVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2488f15f01a7SVille Syrjälä 	enum pipe pipe = crtc->pipe;
2489abd58f01SBen Widawsky 	unsigned long irqflags;
2490abd58f01SBen Widawsky 
2491f15f01a7SVille Syrjälä 	if (gen11_dsi_configure_te(crtc, true))
24929c9e97c4SVandita Kulkarni 		return 0;
24939c9e97c4SVandita Kulkarni 
2494abd58f01SBen Widawsky 	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2495013d3752SVille Syrjälä 	bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
2496abd58f01SBen Widawsky 	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2497013d3752SVille Syrjälä 
24982e8bf223SDhinakaran Pandiyan 	/* Even if there is no DMC, frame counter can get stuck when
24992e8bf223SDhinakaran Pandiyan 	 * PSR is active as no frames are generated, so check only for PSR.
25002e8bf223SDhinakaran Pandiyan 	 */
25012e8bf223SDhinakaran Pandiyan 	if (HAS_PSR(dev_priv))
2502f15f01a7SVille Syrjälä 		drm_crtc_vblank_restore(&crtc->base);
25032e8bf223SDhinakaran Pandiyan 
2504abd58f01SBen Widawsky 	return 0;
2505abd58f01SBen Widawsky }
2506abd58f01SBen Widawsky 
250742f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which
250842f52ef8SKeith Packard  * we use as a pipe index
250942f52ef8SKeith Packard  */
251008fa8fd0SVille Syrjälä void i8xx_disable_vblank(struct drm_crtc *crtc)
251186e83e35SChris Wilson {
251208fa8fd0SVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(crtc->dev);
251308fa8fd0SVille Syrjälä 	enum pipe pipe = to_intel_crtc(crtc)->pipe;
251486e83e35SChris Wilson 	unsigned long irqflags;
251586e83e35SChris Wilson 
251686e83e35SChris Wilson 	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
251786e83e35SChris Wilson 	i915_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
251886e83e35SChris Wilson 	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
251986e83e35SChris Wilson }
252086e83e35SChris Wilson 
25217d423af9SVille Syrjälä void i915gm_disable_vblank(struct drm_crtc *crtc)
2522d938da6bSVille Syrjälä {
252308fa8fd0SVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2524d938da6bSVille Syrjälä 
252508fa8fd0SVille Syrjälä 	i8xx_disable_vblank(crtc);
2526d938da6bSVille Syrjälä 
25277d423af9SVille Syrjälä 	if (--dev_priv->vblank_enabled == 0)
25282939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, SCPD0, _MASKED_BIT_DISABLE(CSTATE_RENDER_CLOCK_GATE_DISABLE));
2529d938da6bSVille Syrjälä }
2530d938da6bSVille Syrjälä 
253108fa8fd0SVille Syrjälä void i965_disable_vblank(struct drm_crtc *crtc)
25320a3e67a4SJesse Barnes {
253308fa8fd0SVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(crtc->dev);
253408fa8fd0SVille Syrjälä 	enum pipe pipe = to_intel_crtc(crtc)->pipe;
2535e9d21d7fSKeith Packard 	unsigned long irqflags;
25360a3e67a4SJesse Barnes 
25371ec14ad3SChris Wilson 	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
25387c463586SKeith Packard 	i915_disable_pipestat(dev_priv, pipe,
2539755e9019SImre Deak 			      PIPE_START_VBLANK_INTERRUPT_STATUS);
25401ec14ad3SChris Wilson 	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
25410a3e67a4SJesse Barnes }
25420a3e67a4SJesse Barnes 
254308fa8fd0SVille Syrjälä void ilk_disable_vblank(struct drm_crtc *crtc)
2544f796cf8fSJesse Barnes {
254508fa8fd0SVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(crtc->dev);
254608fa8fd0SVille Syrjälä 	enum pipe pipe = to_intel_crtc(crtc)->pipe;
2547f796cf8fSJesse Barnes 	unsigned long irqflags;
2548373abf1aSMatt Roper 	u32 bit = DISPLAY_VER(dev_priv) >= 7 ?
254986e83e35SChris Wilson 		DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
2550f796cf8fSJesse Barnes 
2551f796cf8fSJesse Barnes 	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2552fbdedaeaSVille Syrjälä 	ilk_disable_display_irq(dev_priv, bit);
2553b1f14ad0SJesse Barnes 	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2554b1f14ad0SJesse Barnes }
2555b1f14ad0SJesse Barnes 
2556f15f01a7SVille Syrjälä void bdw_disable_vblank(struct drm_crtc *_crtc)
2557abd58f01SBen Widawsky {
2558f15f01a7SVille Syrjälä 	struct intel_crtc *crtc = to_intel_crtc(_crtc);
2559f15f01a7SVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2560f15f01a7SVille Syrjälä 	enum pipe pipe = crtc->pipe;
2561abd58f01SBen Widawsky 	unsigned long irqflags;
2562abd58f01SBen Widawsky 
2563f15f01a7SVille Syrjälä 	if (gen11_dsi_configure_te(crtc, false))
25649c9e97c4SVandita Kulkarni 		return;
25659c9e97c4SVandita Kulkarni 
2566abd58f01SBen Widawsky 	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2567013d3752SVille Syrjälä 	bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
2568abd58f01SBen Widawsky 	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2569abd58f01SBen Widawsky }
2570abd58f01SBen Widawsky 
2571b243f530STvrtko Ursulin static void ibx_irq_reset(struct drm_i915_private *dev_priv)
257291738a95SPaulo Zanoni {
2573b16b2a2fSPaulo Zanoni 	struct intel_uncore *uncore = &dev_priv->uncore;
2574b16b2a2fSPaulo Zanoni 
25756e266956STvrtko Ursulin 	if (HAS_PCH_NOP(dev_priv))
257691738a95SPaulo Zanoni 		return;
257791738a95SPaulo Zanoni 
2578b16b2a2fSPaulo Zanoni 	GEN3_IRQ_RESET(uncore, SDE);
2579105b122eSPaulo Zanoni 
25806e266956STvrtko Ursulin 	if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
25812939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, SERR_INT, 0xffffffff);
2582622364b6SPaulo Zanoni }
2583105b122eSPaulo Zanoni 
258470591a41SVille Syrjälä static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
258570591a41SVille Syrjälä {
2586b16b2a2fSPaulo Zanoni 	struct intel_uncore *uncore = &dev_priv->uncore;
2587b16b2a2fSPaulo Zanoni 
258871b8b41dSVille Syrjälä 	if (IS_CHERRYVIEW(dev_priv))
2589f0818984STvrtko Ursulin 		intel_uncore_write(uncore, DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
259071b8b41dSVille Syrjälä 	else
25917d938bc0SVille Syrjälä 		intel_uncore_write(uncore, DPINVGTT, DPINVGTT_STATUS_MASK_VLV);
259271b8b41dSVille Syrjälä 
2593ad22d106SVille Syrjälä 	i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0);
25948cee664dSAndrzej Hajda 	intel_uncore_rmw(uncore, PORT_HOTPLUG_STAT, 0, 0);
259570591a41SVille Syrjälä 
259644d9241eSVille Syrjälä 	i9xx_pipestat_irq_reset(dev_priv);
259770591a41SVille Syrjälä 
2598b16b2a2fSPaulo Zanoni 	GEN3_IRQ_RESET(uncore, VLV_);
25998bd099a7SChris Wilson 	dev_priv->irq_mask = ~0u;
260070591a41SVille Syrjälä }
260170591a41SVille Syrjälä 
26028bb61306SVille Syrjälä static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
26038bb61306SVille Syrjälä {
2604b16b2a2fSPaulo Zanoni 	struct intel_uncore *uncore = &dev_priv->uncore;
2605b16b2a2fSPaulo Zanoni 
26068bb61306SVille Syrjälä 	u32 pipestat_mask;
26079ab981f2SVille Syrjälä 	u32 enable_mask;
26088bb61306SVille Syrjälä 	enum pipe pipe;
26098bb61306SVille Syrjälä 
2610842ebf7aSVille Syrjälä 	pipestat_mask = PIPE_CRC_DONE_INTERRUPT_STATUS;
26118bb61306SVille Syrjälä 
26128bb61306SVille Syrjälä 	i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
26138bb61306SVille Syrjälä 	for_each_pipe(dev_priv, pipe)
26148bb61306SVille Syrjälä 		i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
26158bb61306SVille Syrjälä 
26169ab981f2SVille Syrjälä 	enable_mask = I915_DISPLAY_PORT_INTERRUPT |
26178bb61306SVille Syrjälä 		I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2618ebf5f921SVille Syrjälä 		I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2619ebf5f921SVille Syrjälä 		I915_LPE_PIPE_A_INTERRUPT |
2620ebf5f921SVille Syrjälä 		I915_LPE_PIPE_B_INTERRUPT;
2621ebf5f921SVille Syrjälä 
26228bb61306SVille Syrjälä 	if (IS_CHERRYVIEW(dev_priv))
2623ebf5f921SVille Syrjälä 		enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT |
2624ebf5f921SVille Syrjälä 			I915_LPE_PIPE_C_INTERRUPT;
26256b7eafc1SVille Syrjälä 
262648a1b8d4SPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm, dev_priv->irq_mask != ~0u);
26276b7eafc1SVille Syrjälä 
26289ab981f2SVille Syrjälä 	dev_priv->irq_mask = ~enable_mask;
26298bb61306SVille Syrjälä 
2630b16b2a2fSPaulo Zanoni 	GEN3_IRQ_INIT(uncore, VLV_, dev_priv->irq_mask, enable_mask);
26318bb61306SVille Syrjälä }
26328bb61306SVille Syrjälä 
26338bb61306SVille Syrjälä /* drm_dma.h hooks
26348bb61306SVille Syrjälä */
26359eae5e27SLucas De Marchi static void ilk_irq_reset(struct drm_i915_private *dev_priv)
26368bb61306SVille Syrjälä {
2637b16b2a2fSPaulo Zanoni 	struct intel_uncore *uncore = &dev_priv->uncore;
26388bb61306SVille Syrjälä 
2639b16b2a2fSPaulo Zanoni 	GEN3_IRQ_RESET(uncore, DE);
2640e44adb5dSChris Wilson 	dev_priv->irq_mask = ~0u;
2641e44adb5dSChris Wilson 
2642651e7d48SLucas De Marchi 	if (GRAPHICS_VER(dev_priv) == 7)
2643f0818984STvrtko Ursulin 		intel_uncore_write(uncore, GEN7_ERR_INT, 0xffffffff);
26448bb61306SVille Syrjälä 
2645fc340442SDaniel Vetter 	if (IS_HASWELL(dev_priv)) {
2646f0818984STvrtko Ursulin 		intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff);
2647f0818984STvrtko Ursulin 		intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff);
2648fc340442SDaniel Vetter 	}
2649fc340442SDaniel Vetter 
26502cbc876dSMichał Winiarski 	gen5_gt_irq_reset(to_gt(dev_priv));
26518bb61306SVille Syrjälä 
2652b243f530STvrtko Ursulin 	ibx_irq_reset(dev_priv);
26538bb61306SVille Syrjälä }
26548bb61306SVille Syrjälä 
2655b318b824SVille Syrjälä static void valleyview_irq_reset(struct drm_i915_private *dev_priv)
26567e231dbeSJesse Barnes {
26572939eb06SJani Nikula 	intel_uncore_write(&dev_priv->uncore, VLV_MASTER_IER, 0);
26582939eb06SJani Nikula 	intel_uncore_posting_read(&dev_priv->uncore, VLV_MASTER_IER);
265934c7b8a7SVille Syrjälä 
26602cbc876dSMichał Winiarski 	gen5_gt_irq_reset(to_gt(dev_priv));
26617e231dbeSJesse Barnes 
2662ad22d106SVille Syrjälä 	spin_lock_irq(&dev_priv->irq_lock);
26639918271eSVille Syrjälä 	if (dev_priv->display_irqs_enabled)
266470591a41SVille Syrjälä 		vlv_display_irq_reset(dev_priv);
2665ad22d106SVille Syrjälä 	spin_unlock_irq(&dev_priv->irq_lock);
26667e231dbeSJesse Barnes }
26677e231dbeSJesse Barnes 
2668a844cfbeSJosé Roberto de Souza static void gen8_display_irq_reset(struct drm_i915_private *dev_priv)
2669abd58f01SBen Widawsky {
2670b16b2a2fSPaulo Zanoni 	struct intel_uncore *uncore = &dev_priv->uncore;
2671d048a268SVille Syrjälä 	enum pipe pipe;
2672abd58f01SBen Widawsky 
2673a844cfbeSJosé Roberto de Souza 	if (!HAS_DISPLAY(dev_priv))
2674a844cfbeSJosé Roberto de Souza 		return;
2675abd58f01SBen Widawsky 
2676f0818984STvrtko Ursulin 	intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff);
2677f0818984STvrtko Ursulin 	intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff);
2678e04f7eceSVille Syrjälä 
2679055e393fSDamien Lespiau 	for_each_pipe(dev_priv, pipe)
2680f458ebbcSDaniel Vetter 		if (intel_display_power_is_enabled(dev_priv,
2681813bde43SPaulo Zanoni 						   POWER_DOMAIN_PIPE(pipe)))
2682b16b2a2fSPaulo Zanoni 			GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe);
2683abd58f01SBen Widawsky 
2684b16b2a2fSPaulo Zanoni 	GEN3_IRQ_RESET(uncore, GEN8_DE_PORT_);
2685b16b2a2fSPaulo Zanoni 	GEN3_IRQ_RESET(uncore, GEN8_DE_MISC_);
2686a844cfbeSJosé Roberto de Souza }
2687a844cfbeSJosé Roberto de Souza 
2688a844cfbeSJosé Roberto de Souza static void gen8_irq_reset(struct drm_i915_private *dev_priv)
2689a844cfbeSJosé Roberto de Souza {
2690a844cfbeSJosé Roberto de Souza 	struct intel_uncore *uncore = &dev_priv->uncore;
2691a844cfbeSJosé Roberto de Souza 
2692e58c2cacSAndrzej Hajda 	gen8_master_intr_disable(uncore->regs);
2693a844cfbeSJosé Roberto de Souza 
26942cbc876dSMichał Winiarski 	gen8_gt_irq_reset(to_gt(dev_priv));
2695a844cfbeSJosé Roberto de Souza 	gen8_display_irq_reset(dev_priv);
2696b16b2a2fSPaulo Zanoni 	GEN3_IRQ_RESET(uncore, GEN8_PCU_);
2697abd58f01SBen Widawsky 
26986e266956STvrtko Ursulin 	if (HAS_PCH_SPLIT(dev_priv))
2699b243f530STvrtko Ursulin 		ibx_irq_reset(dev_priv);
270059b7cb44STejas Upadhyay 
2701abd58f01SBen Widawsky }
2702abd58f01SBen Widawsky 
2703a3265d85SMatt Roper static void gen11_display_irq_reset(struct drm_i915_private *dev_priv)
270451951ae7SMika Kuoppala {
2705b16b2a2fSPaulo Zanoni 	struct intel_uncore *uncore = &dev_priv->uncore;
2706d048a268SVille Syrjälä 	enum pipe pipe;
2707562ddcb7SMatt Roper 	u32 trans_mask = BIT(TRANSCODER_A) | BIT(TRANSCODER_B) |
2708562ddcb7SMatt Roper 		BIT(TRANSCODER_C) | BIT(TRANSCODER_D);
270951951ae7SMika Kuoppala 
2710a844cfbeSJosé Roberto de Souza 	if (!HAS_DISPLAY(dev_priv))
2711a844cfbeSJosé Roberto de Souza 		return;
2712a844cfbeSJosé Roberto de Souza 
2713f0818984STvrtko Ursulin 	intel_uncore_write(uncore, GEN11_DISPLAY_INT_CTL, 0);
271451951ae7SMika Kuoppala 
2715373abf1aSMatt Roper 	if (DISPLAY_VER(dev_priv) >= 12) {
27168241cfbeSJosé Roberto de Souza 		enum transcoder trans;
27178241cfbeSJosé Roberto de Souza 
2718562ddcb7SMatt Roper 		for_each_cpu_transcoder_masked(dev_priv, trans, trans_mask) {
27198241cfbeSJosé Roberto de Souza 			enum intel_display_power_domain domain;
27208241cfbeSJosé Roberto de Souza 
27218241cfbeSJosé Roberto de Souza 			domain = POWER_DOMAIN_TRANSCODER(trans);
27228241cfbeSJosé Roberto de Souza 			if (!intel_display_power_is_enabled(dev_priv, domain))
27238241cfbeSJosé Roberto de Souza 				continue;
27248241cfbeSJosé Roberto de Souza 
27258241cfbeSJosé Roberto de Souza 			intel_uncore_write(uncore, TRANS_PSR_IMR(trans), 0xffffffff);
27268241cfbeSJosé Roberto de Souza 			intel_uncore_write(uncore, TRANS_PSR_IIR(trans), 0xffffffff);
27278241cfbeSJosé Roberto de Souza 		}
27288241cfbeSJosé Roberto de Souza 	} else {
2729f0818984STvrtko Ursulin 		intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff);
2730f0818984STvrtko Ursulin 		intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff);
27318241cfbeSJosé Roberto de Souza 	}
273262819dfdSJosé Roberto de Souza 
273351951ae7SMika Kuoppala 	for_each_pipe(dev_priv, pipe)
273451951ae7SMika Kuoppala 		if (intel_display_power_is_enabled(dev_priv,
273551951ae7SMika Kuoppala 						   POWER_DOMAIN_PIPE(pipe)))
2736b16b2a2fSPaulo Zanoni 			GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe);
273751951ae7SMika Kuoppala 
2738b16b2a2fSPaulo Zanoni 	GEN3_IRQ_RESET(uncore, GEN8_DE_PORT_);
2739b16b2a2fSPaulo Zanoni 	GEN3_IRQ_RESET(uncore, GEN8_DE_MISC_);
2740b16b2a2fSPaulo Zanoni 	GEN3_IRQ_RESET(uncore, GEN11_DE_HPD_);
274131604222SAnusha Srivatsa 
274229b43ae2SRodrigo Vivi 	if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
2743b16b2a2fSPaulo Zanoni 		GEN3_IRQ_RESET(uncore, SDE);
274451951ae7SMika Kuoppala }
274551951ae7SMika Kuoppala 
2746a3265d85SMatt Roper static void gen11_irq_reset(struct drm_i915_private *dev_priv)
2747a3265d85SMatt Roper {
27482cbc876dSMichał Winiarski 	struct intel_gt *gt = to_gt(dev_priv);
2749fd4d7904SPaulo Zanoni 	struct intel_uncore *uncore = gt->uncore;
2750a3265d85SMatt Roper 
2751a3265d85SMatt Roper 	gen11_master_intr_disable(dev_priv->uncore.regs);
2752a3265d85SMatt Roper 
2753fd4d7904SPaulo Zanoni 	gen11_gt_irq_reset(gt);
2754a3265d85SMatt Roper 	gen11_display_irq_reset(dev_priv);
2755a3265d85SMatt Roper 
2756a3265d85SMatt Roper 	GEN3_IRQ_RESET(uncore, GEN11_GU_MISC_);
2757a3265d85SMatt Roper 	GEN3_IRQ_RESET(uncore, GEN8_PCU_);
2758a3265d85SMatt Roper }
2759a3265d85SMatt Roper 
276022e26af7SPaulo Zanoni static void dg1_irq_reset(struct drm_i915_private *dev_priv)
276122e26af7SPaulo Zanoni {
27622cbc876dSMichał Winiarski 	struct intel_gt *gt = to_gt(dev_priv);
2763fd4d7904SPaulo Zanoni 	struct intel_uncore *uncore = gt->uncore;
276422e26af7SPaulo Zanoni 
276522e26af7SPaulo Zanoni 	dg1_master_intr_disable(dev_priv->uncore.regs);
276622e26af7SPaulo Zanoni 
2767fd4d7904SPaulo Zanoni 	gen11_gt_irq_reset(gt);
276822e26af7SPaulo Zanoni 	gen11_display_irq_reset(dev_priv);
276922e26af7SPaulo Zanoni 
277022e26af7SPaulo Zanoni 	GEN3_IRQ_RESET(uncore, GEN11_GU_MISC_);
277122e26af7SPaulo Zanoni 	GEN3_IRQ_RESET(uncore, GEN8_PCU_);
277222e26af7SPaulo Zanoni }
277322e26af7SPaulo Zanoni 
27744c6c03beSDamien Lespiau void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
2775001bd2cbSImre Deak 				     u8 pipe_mask)
2776d49bdb0eSPaulo Zanoni {
2777b16b2a2fSPaulo Zanoni 	struct intel_uncore *uncore = &dev_priv->uncore;
27788bcc0840SMatt Roper 	u32 extra_ier = GEN8_PIPE_VBLANK |
27798bcc0840SMatt Roper 		gen8_de_pipe_underrun_mask(dev_priv) |
2780cda195f1SVille Syrjälä 		gen8_de_pipe_flip_done_mask(dev_priv);
27816831f3e3SVille Syrjälä 	enum pipe pipe;
2782d49bdb0eSPaulo Zanoni 
278313321786SDaniel Vetter 	spin_lock_irq(&dev_priv->irq_lock);
27849dfe2e3aSImre Deak 
27859dfe2e3aSImre Deak 	if (!intel_irqs_enabled(dev_priv)) {
27869dfe2e3aSImre Deak 		spin_unlock_irq(&dev_priv->irq_lock);
27879dfe2e3aSImre Deak 		return;
27889dfe2e3aSImre Deak 	}
27899dfe2e3aSImre Deak 
27906831f3e3SVille Syrjälä 	for_each_pipe_masked(dev_priv, pipe, pipe_mask)
2791b16b2a2fSPaulo Zanoni 		GEN8_IRQ_INIT_NDX(uncore, DE_PIPE, pipe,
27926831f3e3SVille Syrjälä 				  dev_priv->de_irq_mask[pipe],
27936831f3e3SVille Syrjälä 				  ~dev_priv->de_irq_mask[pipe] | extra_ier);
27949dfe2e3aSImre Deak 
279513321786SDaniel Vetter 	spin_unlock_irq(&dev_priv->irq_lock);
2796d49bdb0eSPaulo Zanoni }
2797d49bdb0eSPaulo Zanoni 
2798aae8ba84SVille Syrjälä void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv,
2799001bd2cbSImre Deak 				     u8 pipe_mask)
2800aae8ba84SVille Syrjälä {
2801b16b2a2fSPaulo Zanoni 	struct intel_uncore *uncore = &dev_priv->uncore;
28026831f3e3SVille Syrjälä 	enum pipe pipe;
28036831f3e3SVille Syrjälä 
2804aae8ba84SVille Syrjälä 	spin_lock_irq(&dev_priv->irq_lock);
28059dfe2e3aSImre Deak 
28069dfe2e3aSImre Deak 	if (!intel_irqs_enabled(dev_priv)) {
28079dfe2e3aSImre Deak 		spin_unlock_irq(&dev_priv->irq_lock);
28089dfe2e3aSImre Deak 		return;
28099dfe2e3aSImre Deak 	}
28109dfe2e3aSImre Deak 
28116831f3e3SVille Syrjälä 	for_each_pipe_masked(dev_priv, pipe, pipe_mask)
2812b16b2a2fSPaulo Zanoni 		GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe);
28139dfe2e3aSImre Deak 
2814aae8ba84SVille Syrjälä 	spin_unlock_irq(&dev_priv->irq_lock);
2815aae8ba84SVille Syrjälä 
2816aae8ba84SVille Syrjälä 	/* make sure we're done processing display irqs */
2817315ca4c4SVille Syrjälä 	intel_synchronize_irq(dev_priv);
2818aae8ba84SVille Syrjälä }
2819aae8ba84SVille Syrjälä 
2820b318b824SVille Syrjälä static void cherryview_irq_reset(struct drm_i915_private *dev_priv)
282143f328d7SVille Syrjälä {
2822b16b2a2fSPaulo Zanoni 	struct intel_uncore *uncore = &dev_priv->uncore;
282343f328d7SVille Syrjälä 
2824e58c2cacSAndrzej Hajda 	intel_uncore_write(uncore, GEN8_MASTER_IRQ, 0);
28252939eb06SJani Nikula 	intel_uncore_posting_read(&dev_priv->uncore, GEN8_MASTER_IRQ);
282643f328d7SVille Syrjälä 
28272cbc876dSMichał Winiarski 	gen8_gt_irq_reset(to_gt(dev_priv));
282843f328d7SVille Syrjälä 
2829b16b2a2fSPaulo Zanoni 	GEN3_IRQ_RESET(uncore, GEN8_PCU_);
283043f328d7SVille Syrjälä 
2831ad22d106SVille Syrjälä 	spin_lock_irq(&dev_priv->irq_lock);
28329918271eSVille Syrjälä 	if (dev_priv->display_irqs_enabled)
283370591a41SVille Syrjälä 		vlv_display_irq_reset(dev_priv);
2834ad22d106SVille Syrjälä 	spin_unlock_irq(&dev_priv->irq_lock);
283543f328d7SVille Syrjälä }
283643f328d7SVille Syrjälä 
2837dfefe7bcSVille Syrjälä static u32 ibx_hotplug_enables(struct intel_encoder *encoder)
28382ea63927SVille Syrjälä {
2839dfefe7bcSVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
2840dfefe7bcSVille Syrjälä 
2841dfefe7bcSVille Syrjälä 	switch (encoder->hpd_pin) {
28422ea63927SVille Syrjälä 	case HPD_PORT_A:
28432ea63927SVille Syrjälä 		/*
28442ea63927SVille Syrjälä 		 * When CPU and PCH are on the same package, port A
28452ea63927SVille Syrjälä 		 * HPD must be enabled in both north and south.
28462ea63927SVille Syrjälä 		 */
28472ea63927SVille Syrjälä 		return HAS_PCH_LPT_LP(i915) ?
28482ea63927SVille Syrjälä 			PORTA_HOTPLUG_ENABLE : 0;
28492ea63927SVille Syrjälä 	case HPD_PORT_B:
28502ea63927SVille Syrjälä 		return PORTB_HOTPLUG_ENABLE |
28512ea63927SVille Syrjälä 			PORTB_PULSE_DURATION_2ms;
28522ea63927SVille Syrjälä 	case HPD_PORT_C:
28532ea63927SVille Syrjälä 		return PORTC_HOTPLUG_ENABLE |
28542ea63927SVille Syrjälä 			PORTC_PULSE_DURATION_2ms;
28552ea63927SVille Syrjälä 	case HPD_PORT_D:
28562ea63927SVille Syrjälä 		return PORTD_HOTPLUG_ENABLE |
28572ea63927SVille Syrjälä 			PORTD_PULSE_DURATION_2ms;
28582ea63927SVille Syrjälä 	default:
28592ea63927SVille Syrjälä 		return 0;
28602ea63927SVille Syrjälä 	}
28612ea63927SVille Syrjälä }
28622ea63927SVille Syrjälä 
28631a56b1a2SImre Deak static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv)
28641a56b1a2SImre Deak {
28651a56b1a2SImre Deak 	/*
28661a56b1a2SImre Deak 	 * Enable digital hotplug on the PCH, and configure the DP short pulse
28671a56b1a2SImre Deak 	 * duration to 2ms (which is the minimum in the Display Port spec).
28681a56b1a2SImre Deak 	 * The pulse duration bits are reserved on LPT+.
28691a56b1a2SImre Deak 	 */
28708cee664dSAndrzej Hajda 	intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG,
28718cee664dSAndrzej Hajda 			 PORTA_HOTPLUG_ENABLE |
28722ea63927SVille Syrjälä 			 PORTB_HOTPLUG_ENABLE |
28732ea63927SVille Syrjälä 			 PORTC_HOTPLUG_ENABLE |
28742ea63927SVille Syrjälä 			 PORTD_HOTPLUG_ENABLE |
28752ea63927SVille Syrjälä 			 PORTB_PULSE_DURATION_MASK |
28761a56b1a2SImre Deak 			 PORTC_PULSE_DURATION_MASK |
28778cee664dSAndrzej Hajda 			 PORTD_PULSE_DURATION_MASK,
28788cee664dSAndrzej Hajda 			 intel_hpd_hotplug_enables(dev_priv, ibx_hotplug_enables));
28791a56b1a2SImre Deak }
28801a56b1a2SImre Deak 
288191d14251STvrtko Ursulin static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
288282a28bcfSDaniel Vetter {
28831a56b1a2SImre Deak 	u32 hotplug_irqs, enabled_irqs;
288482a28bcfSDaniel Vetter 
28855a4dd6f0SJani Nikula 	enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
28865a4dd6f0SJani Nikula 	hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
288782a28bcfSDaniel Vetter 
2888fee884edSDaniel Vetter 	ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
288982a28bcfSDaniel Vetter 
28901a56b1a2SImre Deak 	ibx_hpd_detection_setup(dev_priv);
28916dbf30ceSVille Syrjälä }
289226951cafSXiong Zhang 
2893dfefe7bcSVille Syrjälä static u32 icp_ddi_hotplug_enables(struct intel_encoder *encoder)
28942ea63927SVille Syrjälä {
2895dfefe7bcSVille Syrjälä 	switch (encoder->hpd_pin) {
28962ea63927SVille Syrjälä 	case HPD_PORT_A:
28972ea63927SVille Syrjälä 	case HPD_PORT_B:
28982ea63927SVille Syrjälä 	case HPD_PORT_C:
28992ea63927SVille Syrjälä 	case HPD_PORT_D:
2900dfefe7bcSVille Syrjälä 		return SHOTPLUG_CTL_DDI_HPD_ENABLE(encoder->hpd_pin);
29012ea63927SVille Syrjälä 	default:
29022ea63927SVille Syrjälä 		return 0;
29032ea63927SVille Syrjälä 	}
29042ea63927SVille Syrjälä }
29052ea63927SVille Syrjälä 
2906dfefe7bcSVille Syrjälä static u32 icp_tc_hotplug_enables(struct intel_encoder *encoder)
29072ea63927SVille Syrjälä {
2908dfefe7bcSVille Syrjälä 	switch (encoder->hpd_pin) {
29092ea63927SVille Syrjälä 	case HPD_PORT_TC1:
29102ea63927SVille Syrjälä 	case HPD_PORT_TC2:
29112ea63927SVille Syrjälä 	case HPD_PORT_TC3:
29122ea63927SVille Syrjälä 	case HPD_PORT_TC4:
29132ea63927SVille Syrjälä 	case HPD_PORT_TC5:
29142ea63927SVille Syrjälä 	case HPD_PORT_TC6:
2915dfefe7bcSVille Syrjälä 		return ICP_TC_HPD_ENABLE(encoder->hpd_pin);
29162ea63927SVille Syrjälä 	default:
29172ea63927SVille Syrjälä 		return 0;
29182ea63927SVille Syrjälä 	}
29192ea63927SVille Syrjälä }
29202ea63927SVille Syrjälä 
29212ea63927SVille Syrjälä static void icp_ddi_hpd_detection_setup(struct drm_i915_private *dev_priv)
292231604222SAnusha Srivatsa {
29238cee664dSAndrzej Hajda 	intel_uncore_rmw(&dev_priv->uncore, SHOTPLUG_CTL_DDI,
29248cee664dSAndrzej Hajda 			 SHOTPLUG_CTL_DDI_HPD_ENABLE(HPD_PORT_A) |
29252ea63927SVille Syrjälä 			 SHOTPLUG_CTL_DDI_HPD_ENABLE(HPD_PORT_B) |
29262ea63927SVille Syrjälä 			 SHOTPLUG_CTL_DDI_HPD_ENABLE(HPD_PORT_C) |
29278cee664dSAndrzej Hajda 			 SHOTPLUG_CTL_DDI_HPD_ENABLE(HPD_PORT_D),
29288cee664dSAndrzej Hajda 			 intel_hpd_hotplug_enables(dev_priv, icp_ddi_hotplug_enables));
292931604222SAnusha Srivatsa }
2930815f4ef2SVille Syrjälä 
29312ea63927SVille Syrjälä static void icp_tc_hpd_detection_setup(struct drm_i915_private *dev_priv)
2932815f4ef2SVille Syrjälä {
29338cee664dSAndrzej Hajda 	intel_uncore_rmw(&dev_priv->uncore, SHOTPLUG_CTL_TC,
29348cee664dSAndrzej Hajda 			 ICP_TC_HPD_ENABLE(HPD_PORT_TC1) |
29352ea63927SVille Syrjälä 			 ICP_TC_HPD_ENABLE(HPD_PORT_TC2) |
29362ea63927SVille Syrjälä 			 ICP_TC_HPD_ENABLE(HPD_PORT_TC3) |
29372ea63927SVille Syrjälä 			 ICP_TC_HPD_ENABLE(HPD_PORT_TC4) |
29382ea63927SVille Syrjälä 			 ICP_TC_HPD_ENABLE(HPD_PORT_TC5) |
29398cee664dSAndrzej Hajda 			 ICP_TC_HPD_ENABLE(HPD_PORT_TC6),
29408cee664dSAndrzej Hajda 			 intel_hpd_hotplug_enables(dev_priv, icp_tc_hotplug_enables));
29418ef7e340SMatt Roper }
294231604222SAnusha Srivatsa 
29432ea63927SVille Syrjälä static void icp_hpd_irq_setup(struct drm_i915_private *dev_priv)
294431604222SAnusha Srivatsa {
294531604222SAnusha Srivatsa 	u32 hotplug_irqs, enabled_irqs;
294631604222SAnusha Srivatsa 
29475a4dd6f0SJani Nikula 	enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
29485a4dd6f0SJani Nikula 	hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
294931604222SAnusha Srivatsa 
2950f619e516SAnusha Srivatsa 	if (INTEL_PCH_TYPE(dev_priv) <= PCH_TGP)
29512939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, SHPD_FILTER_CNT, SHPD_FILTER_CNT_500_ADJ);
2952f49108d0SMatt Roper 
295331604222SAnusha Srivatsa 	ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
295431604222SAnusha Srivatsa 
29552ea63927SVille Syrjälä 	icp_ddi_hpd_detection_setup(dev_priv);
29562ea63927SVille Syrjälä 	icp_tc_hpd_detection_setup(dev_priv);
295752dfdba0SLucas De Marchi }
295852dfdba0SLucas De Marchi 
2959dfefe7bcSVille Syrjälä static u32 gen11_hotplug_enables(struct intel_encoder *encoder)
29608ef7e340SMatt Roper {
2961dfefe7bcSVille Syrjälä 	switch (encoder->hpd_pin) {
29622ea63927SVille Syrjälä 	case HPD_PORT_TC1:
29632ea63927SVille Syrjälä 	case HPD_PORT_TC2:
29642ea63927SVille Syrjälä 	case HPD_PORT_TC3:
29652ea63927SVille Syrjälä 	case HPD_PORT_TC4:
29662ea63927SVille Syrjälä 	case HPD_PORT_TC5:
29672ea63927SVille Syrjälä 	case HPD_PORT_TC6:
2968dfefe7bcSVille Syrjälä 		return GEN11_HOTPLUG_CTL_ENABLE(encoder->hpd_pin);
29692ea63927SVille Syrjälä 	default:
29702ea63927SVille Syrjälä 		return 0;
297131604222SAnusha Srivatsa 	}
2972943682e3SMatt Roper }
2973943682e3SMatt Roper 
297471690148SGustavo Sousa static void dg1_hpd_invert(struct drm_i915_private *i915)
2975229f31e2SLucas De Marchi {
297671690148SGustavo Sousa 	u32 val = (INVERT_DDIA_HPD |
2977b18c1eb9SClinton A Taylor 		   INVERT_DDIB_HPD |
2978b18c1eb9SClinton A Taylor 		   INVERT_DDIC_HPD |
2979b18c1eb9SClinton A Taylor 		   INVERT_DDID_HPD);
298071690148SGustavo Sousa 	intel_uncore_rmw(&i915->uncore, SOUTH_CHICKEN1, 0, val);
298171690148SGustavo Sousa }
2982b18c1eb9SClinton A Taylor 
298371690148SGustavo Sousa static void dg1_hpd_irq_setup(struct drm_i915_private *dev_priv)
298471690148SGustavo Sousa {
298571690148SGustavo Sousa 	dg1_hpd_invert(dev_priv);
29862ea63927SVille Syrjälä 	icp_hpd_irq_setup(dev_priv);
2987229f31e2SLucas De Marchi }
2988229f31e2SLucas De Marchi 
298952c7f5f1SVille Syrjälä static void gen11_tc_hpd_detection_setup(struct drm_i915_private *dev_priv)
2990121e758eSDhinakaran Pandiyan {
29918cee664dSAndrzej Hajda 	intel_uncore_rmw(&dev_priv->uncore, GEN11_TC_HOTPLUG_CTL,
29928cee664dSAndrzej Hajda 			 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC1) |
29935b76e860SVille Syrjälä 			 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC2) |
29945b76e860SVille Syrjälä 			 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC3) |
29955b76e860SVille Syrjälä 			 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC4) |
29965b76e860SVille Syrjälä 			 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC5) |
29978cee664dSAndrzej Hajda 			 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC6),
29988cee664dSAndrzej Hajda 			 intel_hpd_hotplug_enables(dev_priv, gen11_hotplug_enables));
299952c7f5f1SVille Syrjälä }
300052c7f5f1SVille Syrjälä 
300152c7f5f1SVille Syrjälä static void gen11_tbt_hpd_detection_setup(struct drm_i915_private *dev_priv)
300252c7f5f1SVille Syrjälä {
30038cee664dSAndrzej Hajda 	intel_uncore_rmw(&dev_priv->uncore, GEN11_TBT_HOTPLUG_CTL,
30048cee664dSAndrzej Hajda 			 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC1) |
30055b76e860SVille Syrjälä 			 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC2) |
30065b76e860SVille Syrjälä 			 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC3) |
30075b76e860SVille Syrjälä 			 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC4) |
30085b76e860SVille Syrjälä 			 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC5) |
30098cee664dSAndrzej Hajda 			 GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC6),
30108cee664dSAndrzej Hajda 			 intel_hpd_hotplug_enables(dev_priv, gen11_hotplug_enables));
3011121e758eSDhinakaran Pandiyan }
3012121e758eSDhinakaran Pandiyan 
3013121e758eSDhinakaran Pandiyan static void gen11_hpd_irq_setup(struct drm_i915_private *dev_priv)
3014121e758eSDhinakaran Pandiyan {
3015121e758eSDhinakaran Pandiyan 	u32 hotplug_irqs, enabled_irqs;
3016121e758eSDhinakaran Pandiyan 
30175a4dd6f0SJani Nikula 	enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.hpd);
30185a4dd6f0SJani Nikula 	hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.hpd);
3019121e758eSDhinakaran Pandiyan 
30208cee664dSAndrzej Hajda 	intel_uncore_rmw(&dev_priv->uncore, GEN11_DE_HPD_IMR, hotplug_irqs,
30218cee664dSAndrzej Hajda 			 ~enabled_irqs & hotplug_irqs);
30222939eb06SJani Nikula 	intel_uncore_posting_read(&dev_priv->uncore, GEN11_DE_HPD_IMR);
3023121e758eSDhinakaran Pandiyan 
302452c7f5f1SVille Syrjälä 	gen11_tc_hpd_detection_setup(dev_priv);
302552c7f5f1SVille Syrjälä 	gen11_tbt_hpd_detection_setup(dev_priv);
302631604222SAnusha Srivatsa 
30272ea63927SVille Syrjälä 	if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
30282ea63927SVille Syrjälä 		icp_hpd_irq_setup(dev_priv);
30292ea63927SVille Syrjälä }
30302ea63927SVille Syrjälä 
3031dfefe7bcSVille Syrjälä static u32 spt_hotplug_enables(struct intel_encoder *encoder)
30322ea63927SVille Syrjälä {
3033dfefe7bcSVille Syrjälä 	switch (encoder->hpd_pin) {
30342ea63927SVille Syrjälä 	case HPD_PORT_A:
30352ea63927SVille Syrjälä 		return PORTA_HOTPLUG_ENABLE;
30362ea63927SVille Syrjälä 	case HPD_PORT_B:
30372ea63927SVille Syrjälä 		return PORTB_HOTPLUG_ENABLE;
30382ea63927SVille Syrjälä 	case HPD_PORT_C:
30392ea63927SVille Syrjälä 		return PORTC_HOTPLUG_ENABLE;
30402ea63927SVille Syrjälä 	case HPD_PORT_D:
30412ea63927SVille Syrjälä 		return PORTD_HOTPLUG_ENABLE;
30422ea63927SVille Syrjälä 	default:
30432ea63927SVille Syrjälä 		return 0;
30442ea63927SVille Syrjälä 	}
30452ea63927SVille Syrjälä }
30462ea63927SVille Syrjälä 
3047dfefe7bcSVille Syrjälä static u32 spt_hotplug2_enables(struct intel_encoder *encoder)
30482ea63927SVille Syrjälä {
3049dfefe7bcSVille Syrjälä 	switch (encoder->hpd_pin) {
30502ea63927SVille Syrjälä 	case HPD_PORT_E:
30512ea63927SVille Syrjälä 		return PORTE_HOTPLUG_ENABLE;
30522ea63927SVille Syrjälä 	default:
30532ea63927SVille Syrjälä 		return 0;
30542ea63927SVille Syrjälä 	}
3055121e758eSDhinakaran Pandiyan }
3056121e758eSDhinakaran Pandiyan 
30572a57d9ccSImre Deak static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv)
30582a57d9ccSImre Deak {
30593b92e263SRodrigo Vivi 	/* Display WA #1179 WaHardHangonHotPlug: cnp */
30603b92e263SRodrigo Vivi 	if (HAS_PCH_CNP(dev_priv)) {
30618cee664dSAndrzej Hajda 		intel_uncore_rmw(&dev_priv->uncore, SOUTH_CHICKEN1, CHASSIS_CLK_REQ_DURATION_MASK,
30628cee664dSAndrzej Hajda 				 CHASSIS_CLK_REQ_DURATION(0xf));
30633b92e263SRodrigo Vivi 	}
30642a57d9ccSImre Deak 
30652a57d9ccSImre Deak 	/* Enable digital hotplug on the PCH */
30668cee664dSAndrzej Hajda 	intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG,
30678cee664dSAndrzej Hajda 			 PORTA_HOTPLUG_ENABLE |
30682a57d9ccSImre Deak 			 PORTB_HOTPLUG_ENABLE |
30692a57d9ccSImre Deak 			 PORTC_HOTPLUG_ENABLE |
30708cee664dSAndrzej Hajda 			 PORTD_HOTPLUG_ENABLE,
30718cee664dSAndrzej Hajda 			 intel_hpd_hotplug_enables(dev_priv, spt_hotplug_enables));
30722a57d9ccSImre Deak 
30738cee664dSAndrzej Hajda 	intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG2, PORTE_HOTPLUG_ENABLE,
30748cee664dSAndrzej Hajda 			 intel_hpd_hotplug_enables(dev_priv, spt_hotplug2_enables));
30752a57d9ccSImre Deak }
30762a57d9ccSImre Deak 
307791d14251STvrtko Ursulin static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
30786dbf30ceSVille Syrjälä {
30792a57d9ccSImre Deak 	u32 hotplug_irqs, enabled_irqs;
30806dbf30ceSVille Syrjälä 
3081f49108d0SMatt Roper 	if (INTEL_PCH_TYPE(dev_priv) >= PCH_CNP)
30822939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, SHPD_FILTER_CNT, SHPD_FILTER_CNT_500_ADJ);
3083f49108d0SMatt Roper 
30845a4dd6f0SJani Nikula 	enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
30855a4dd6f0SJani Nikula 	hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
30866dbf30ceSVille Syrjälä 
30876dbf30ceSVille Syrjälä 	ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
30886dbf30ceSVille Syrjälä 
30892a57d9ccSImre Deak 	spt_hpd_detection_setup(dev_priv);
309026951cafSXiong Zhang }
30917fe0b973SKeith Packard 
3092dfefe7bcSVille Syrjälä static u32 ilk_hotplug_enables(struct intel_encoder *encoder)
30932ea63927SVille Syrjälä {
3094dfefe7bcSVille Syrjälä 	switch (encoder->hpd_pin) {
30952ea63927SVille Syrjälä 	case HPD_PORT_A:
30962ea63927SVille Syrjälä 		return DIGITAL_PORTA_HOTPLUG_ENABLE |
30972ea63927SVille Syrjälä 			DIGITAL_PORTA_PULSE_DURATION_2ms;
30982ea63927SVille Syrjälä 	default:
30992ea63927SVille Syrjälä 		return 0;
31002ea63927SVille Syrjälä 	}
31012ea63927SVille Syrjälä }
31022ea63927SVille Syrjälä 
31031a56b1a2SImre Deak static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv)
31041a56b1a2SImre Deak {
31051a56b1a2SImre Deak 	/*
31061a56b1a2SImre Deak 	 * Enable digital hotplug on the CPU, and configure the DP short pulse
31071a56b1a2SImre Deak 	 * duration to 2ms (which is the minimum in the Display Port spec)
31081a56b1a2SImre Deak 	 * The pulse duration bits are reserved on HSW+.
31091a56b1a2SImre Deak 	 */
31108cee664dSAndrzej Hajda 	intel_uncore_rmw(&dev_priv->uncore, DIGITAL_PORT_HOTPLUG_CNTRL,
31118cee664dSAndrzej Hajda 			 DIGITAL_PORTA_HOTPLUG_ENABLE | DIGITAL_PORTA_PULSE_DURATION_MASK,
31128cee664dSAndrzej Hajda 			 intel_hpd_hotplug_enables(dev_priv, ilk_hotplug_enables));
31131a56b1a2SImre Deak }
31141a56b1a2SImre Deak 
311591d14251STvrtko Ursulin static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
3116e4ce95aaSVille Syrjälä {
31171a56b1a2SImre Deak 	u32 hotplug_irqs, enabled_irqs;
3118e4ce95aaSVille Syrjälä 
31195a4dd6f0SJani Nikula 	enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.hpd);
31205a4dd6f0SJani Nikula 	hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.hpd);
31213a3b3c7dSVille Syrjälä 
3122373abf1aSMatt Roper 	if (DISPLAY_VER(dev_priv) >= 8)
31233a3b3c7dSVille Syrjälä 		bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
31246d3144ebSVille Syrjälä 	else
31253a3b3c7dSVille Syrjälä 		ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3126e4ce95aaSVille Syrjälä 
31271a56b1a2SImre Deak 	ilk_hpd_detection_setup(dev_priv);
3128e4ce95aaSVille Syrjälä 
312991d14251STvrtko Ursulin 	ibx_hpd_irq_setup(dev_priv);
3130e4ce95aaSVille Syrjälä }
3131e4ce95aaSVille Syrjälä 
3132dfefe7bcSVille Syrjälä static u32 bxt_hotplug_enables(struct intel_encoder *encoder)
31332ea63927SVille Syrjälä {
31342ea63927SVille Syrjälä 	u32 hotplug;
31352ea63927SVille Syrjälä 
3136dfefe7bcSVille Syrjälä 	switch (encoder->hpd_pin) {
31372ea63927SVille Syrjälä 	case HPD_PORT_A:
31382ea63927SVille Syrjälä 		hotplug = PORTA_HOTPLUG_ENABLE;
31399151c85cSVille Syrjälä 		if (intel_bios_encoder_hpd_invert(encoder->devdata))
31402ea63927SVille Syrjälä 			hotplug |= BXT_DDIA_HPD_INVERT;
31412ea63927SVille Syrjälä 		return hotplug;
31422ea63927SVille Syrjälä 	case HPD_PORT_B:
31432ea63927SVille Syrjälä 		hotplug = PORTB_HOTPLUG_ENABLE;
31449151c85cSVille Syrjälä 		if (intel_bios_encoder_hpd_invert(encoder->devdata))
31452ea63927SVille Syrjälä 			hotplug |= BXT_DDIB_HPD_INVERT;
31462ea63927SVille Syrjälä 		return hotplug;
31472ea63927SVille Syrjälä 	case HPD_PORT_C:
31482ea63927SVille Syrjälä 		hotplug = PORTC_HOTPLUG_ENABLE;
31499151c85cSVille Syrjälä 		if (intel_bios_encoder_hpd_invert(encoder->devdata))
31502ea63927SVille Syrjälä 			hotplug |= BXT_DDIC_HPD_INVERT;
31512ea63927SVille Syrjälä 		return hotplug;
31522ea63927SVille Syrjälä 	default:
31532ea63927SVille Syrjälä 		return 0;
31542ea63927SVille Syrjälä 	}
31552ea63927SVille Syrjälä }
31562ea63927SVille Syrjälä 
31572ea63927SVille Syrjälä static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3158e0a20ad7SShashank Sharma {
31598cee664dSAndrzej Hajda 	intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG,
31608cee664dSAndrzej Hajda 			 PORTA_HOTPLUG_ENABLE |
31612a57d9ccSImre Deak 			 PORTB_HOTPLUG_ENABLE |
31622ea63927SVille Syrjälä 			 PORTC_HOTPLUG_ENABLE |
31638cee664dSAndrzej Hajda 			 BXT_DDI_HPD_INVERT_MASK,
31648cee664dSAndrzej Hajda 			 intel_hpd_hotplug_enables(dev_priv, bxt_hotplug_enables));
3165e0a20ad7SShashank Sharma }
3166e0a20ad7SShashank Sharma 
31672a57d9ccSImre Deak static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
31682a57d9ccSImre Deak {
31692a57d9ccSImre Deak 	u32 hotplug_irqs, enabled_irqs;
31702a57d9ccSImre Deak 
31715a4dd6f0SJani Nikula 	enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.hpd);
31725a4dd6f0SJani Nikula 	hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.hpd);
31732a57d9ccSImre Deak 
31742a57d9ccSImre Deak 	bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
31752a57d9ccSImre Deak 
31762ea63927SVille Syrjälä 	bxt_hpd_detection_setup(dev_priv);
31772a57d9ccSImre Deak }
31782a57d9ccSImre Deak 
3179a0a6d8cbSVille Syrjälä /*
3180a0a6d8cbSVille Syrjälä  * SDEIER is also touched by the interrupt handler to work around missed PCH
3181a0a6d8cbSVille Syrjälä  * interrupts. Hence we can't update it after the interrupt handler is enabled -
3182a0a6d8cbSVille Syrjälä  * instead we unconditionally enable all PCH interrupt sources here, but then
3183a0a6d8cbSVille Syrjälä  * only unmask them as needed with SDEIMR.
3184a0a6d8cbSVille Syrjälä  *
3185a0a6d8cbSVille Syrjälä  * Note that we currently do this after installing the interrupt handler,
3186a0a6d8cbSVille Syrjälä  * but before we enable the master interrupt. That should be sufficient
3187a0a6d8cbSVille Syrjälä  * to avoid races with the irq handler, assuming we have MSI. Shared legacy
3188a0a6d8cbSVille Syrjälä  * interrupts could still race.
3189a0a6d8cbSVille Syrjälä  */
3190b318b824SVille Syrjälä static void ibx_irq_postinstall(struct drm_i915_private *dev_priv)
3191d46da437SPaulo Zanoni {
3192a0a6d8cbSVille Syrjälä 	struct intel_uncore *uncore = &dev_priv->uncore;
319382a28bcfSDaniel Vetter 	u32 mask;
3194d46da437SPaulo Zanoni 
31956e266956STvrtko Ursulin 	if (HAS_PCH_NOP(dev_priv))
3196692a04cfSDaniel Vetter 		return;
3197692a04cfSDaniel Vetter 
31986e266956STvrtko Ursulin 	if (HAS_PCH_IBX(dev_priv))
31995c673b60SDaniel Vetter 		mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
32004ebc6509SDhinakaran Pandiyan 	else if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
32015c673b60SDaniel Vetter 		mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
32024ebc6509SDhinakaran Pandiyan 	else
32034ebc6509SDhinakaran Pandiyan 		mask = SDE_GMBUS_CPT;
32048664281bSPaulo Zanoni 
3205a0a6d8cbSVille Syrjälä 	GEN3_IRQ_INIT(uncore, SDE, ~mask, 0xffffffff);
3206d46da437SPaulo Zanoni }
3207d46da437SPaulo Zanoni 
32089eae5e27SLucas De Marchi static void ilk_irq_postinstall(struct drm_i915_private *dev_priv)
3209036a4a7dSZhenyu Wang {
3210b16b2a2fSPaulo Zanoni 	struct intel_uncore *uncore = &dev_priv->uncore;
32118e76f8dcSPaulo Zanoni 	u32 display_mask, extra_mask;
32128e76f8dcSPaulo Zanoni 
3213651e7d48SLucas De Marchi 	if (GRAPHICS_VER(dev_priv) >= 7) {
32148e76f8dcSPaulo Zanoni 		display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
3215842ebf7aSVille Syrjälä 				DE_PCH_EVENT_IVB | DE_AUX_CHANNEL_A_IVB);
32168e76f8dcSPaulo Zanoni 		extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
321723bb4cb5SVille Syrjälä 			      DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
32182a636e24SVille Syrjälä 			      DE_PLANE_FLIP_DONE_IVB(PLANE_C) |
32192a636e24SVille Syrjälä 			      DE_PLANE_FLIP_DONE_IVB(PLANE_B) |
32202a636e24SVille Syrjälä 			      DE_PLANE_FLIP_DONE_IVB(PLANE_A) |
322123bb4cb5SVille Syrjälä 			      DE_DP_A_HOTPLUG_IVB);
32228e76f8dcSPaulo Zanoni 	} else {
32238e76f8dcSPaulo Zanoni 		display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
3224842ebf7aSVille Syrjälä 				DE_AUX_CHANNEL_A | DE_PIPEB_CRC_DONE |
3225842ebf7aSVille Syrjälä 				DE_PIPEA_CRC_DONE | DE_POISON);
3226c6073d4cSVille Syrjälä 		extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK |
3227e4ce95aaSVille Syrjälä 			      DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
32284bb18054SVille Syrjälä 			      DE_PLANE_FLIP_DONE(PLANE_A) |
32294bb18054SVille Syrjälä 			      DE_PLANE_FLIP_DONE(PLANE_B) |
3230e4ce95aaSVille Syrjälä 			      DE_DP_A_HOTPLUG);
32318e76f8dcSPaulo Zanoni 	}
3232036a4a7dSZhenyu Wang 
3233fc340442SDaniel Vetter 	if (IS_HASWELL(dev_priv)) {
3234b16b2a2fSPaulo Zanoni 		gen3_assert_iir_is_zero(uncore, EDP_PSR_IIR);
3235fc340442SDaniel Vetter 		display_mask |= DE_EDP_PSR_INT_HSW;
3236fc340442SDaniel Vetter 	}
3237fc340442SDaniel Vetter 
3238c6073d4cSVille Syrjälä 	if (IS_IRONLAKE_M(dev_priv))
3239c6073d4cSVille Syrjälä 		extra_mask |= DE_PCU_EVENT;
3240c6073d4cSVille Syrjälä 
32411ec14ad3SChris Wilson 	dev_priv->irq_mask = ~display_mask;
3242036a4a7dSZhenyu Wang 
3243a0a6d8cbSVille Syrjälä 	ibx_irq_postinstall(dev_priv);
3244622364b6SPaulo Zanoni 
32452cbc876dSMichał Winiarski 	gen5_gt_irq_postinstall(to_gt(dev_priv));
3246a9922912SVille Syrjälä 
3247b16b2a2fSPaulo Zanoni 	GEN3_IRQ_INIT(uncore, DE, dev_priv->irq_mask,
3248b16b2a2fSPaulo Zanoni 		      display_mask | extra_mask);
3249036a4a7dSZhenyu Wang }
3250036a4a7dSZhenyu Wang 
3251f8b79e58SImre Deak void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3252f8b79e58SImre Deak {
325367520415SChris Wilson 	lockdep_assert_held(&dev_priv->irq_lock);
3254f8b79e58SImre Deak 
3255f8b79e58SImre Deak 	if (dev_priv->display_irqs_enabled)
3256f8b79e58SImre Deak 		return;
3257f8b79e58SImre Deak 
3258f8b79e58SImre Deak 	dev_priv->display_irqs_enabled = true;
3259f8b79e58SImre Deak 
3260d6c69803SVille Syrjälä 	if (intel_irqs_enabled(dev_priv)) {
3261d6c69803SVille Syrjälä 		vlv_display_irq_reset(dev_priv);
3262ad22d106SVille Syrjälä 		vlv_display_irq_postinstall(dev_priv);
3263f8b79e58SImre Deak 	}
3264d6c69803SVille Syrjälä }
3265f8b79e58SImre Deak 
3266f8b79e58SImre Deak void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3267f8b79e58SImre Deak {
326867520415SChris Wilson 	lockdep_assert_held(&dev_priv->irq_lock);
3269f8b79e58SImre Deak 
3270f8b79e58SImre Deak 	if (!dev_priv->display_irqs_enabled)
3271f8b79e58SImre Deak 		return;
3272f8b79e58SImre Deak 
3273f8b79e58SImre Deak 	dev_priv->display_irqs_enabled = false;
3274f8b79e58SImre Deak 
3275950eabafSImre Deak 	if (intel_irqs_enabled(dev_priv))
3276ad22d106SVille Syrjälä 		vlv_display_irq_reset(dev_priv);
3277f8b79e58SImre Deak }
3278f8b79e58SImre Deak 
32790e6c9a9eSVille Syrjälä 
3280b318b824SVille Syrjälä static void valleyview_irq_postinstall(struct drm_i915_private *dev_priv)
32810e6c9a9eSVille Syrjälä {
32822cbc876dSMichał Winiarski 	gen5_gt_irq_postinstall(to_gt(dev_priv));
32837e231dbeSJesse Barnes 
3284ad22d106SVille Syrjälä 	spin_lock_irq(&dev_priv->irq_lock);
32859918271eSVille Syrjälä 	if (dev_priv->display_irqs_enabled)
3286ad22d106SVille Syrjälä 		vlv_display_irq_postinstall(dev_priv);
3287ad22d106SVille Syrjälä 	spin_unlock_irq(&dev_priv->irq_lock);
3288ad22d106SVille Syrjälä 
32892939eb06SJani Nikula 	intel_uncore_write(&dev_priv->uncore, VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
32902939eb06SJani Nikula 	intel_uncore_posting_read(&dev_priv->uncore, VLV_MASTER_IER);
329120afbda2SDaniel Vetter }
329220afbda2SDaniel Vetter 
3293abd58f01SBen Widawsky static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3294abd58f01SBen Widawsky {
3295b16b2a2fSPaulo Zanoni 	struct intel_uncore *uncore = &dev_priv->uncore;
3296b16b2a2fSPaulo Zanoni 
3297869129eeSMatt Roper 	u32 de_pipe_masked = gen8_de_pipe_fault_mask(dev_priv) |
3298869129eeSMatt Roper 		GEN8_PIPE_CDCLK_CRC_DONE;
3299a9c287c9SJani Nikula 	u32 de_pipe_enables;
3300054318c7SImre Deak 	u32 de_port_masked = gen8_de_port_aux_mask(dev_priv);
33013a3b3c7dSVille Syrjälä 	u32 de_port_enables;
3302df0d28c1SDhinakaran Pandiyan 	u32 de_misc_masked = GEN8_DE_EDP_PSR;
3303562ddcb7SMatt Roper 	u32 trans_mask = BIT(TRANSCODER_A) | BIT(TRANSCODER_B) |
3304562ddcb7SMatt Roper 		BIT(TRANSCODER_C) | BIT(TRANSCODER_D);
33053a3b3c7dSVille Syrjälä 	enum pipe pipe;
3306770de83dSDamien Lespiau 
3307a844cfbeSJosé Roberto de Souza 	if (!HAS_DISPLAY(dev_priv))
3308a844cfbeSJosé Roberto de Souza 		return;
3309a844cfbeSJosé Roberto de Souza 
3310373abf1aSMatt Roper 	if (DISPLAY_VER(dev_priv) <= 10)
3311df0d28c1SDhinakaran Pandiyan 		de_misc_masked |= GEN8_DE_MISC_GSE;
3312df0d28c1SDhinakaran Pandiyan 
331370bfb307SMatt Roper 	if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
33143a3b3c7dSVille Syrjälä 		de_port_masked |= BXT_DE_PORT_GMBUS;
3315a324fcacSRodrigo Vivi 
3316373abf1aSMatt Roper 	if (DISPLAY_VER(dev_priv) >= 11) {
33179c9e97c4SVandita Kulkarni 		enum port port;
33189c9e97c4SVandita Kulkarni 
33199c9e97c4SVandita Kulkarni 		if (intel_bios_is_dsi_present(dev_priv, &port))
33209c9e97c4SVandita Kulkarni 			de_port_masked |= DSI0_TE | DSI1_TE;
33219c9e97c4SVandita Kulkarni 	}
33229c9e97c4SVandita Kulkarni 
3323cda195f1SVille Syrjälä 	de_pipe_enables = de_pipe_masked |
33248bcc0840SMatt Roper 		GEN8_PIPE_VBLANK |
33258bcc0840SMatt Roper 		gen8_de_pipe_underrun_mask(dev_priv) |
3326cda195f1SVille Syrjälä 		gen8_de_pipe_flip_done_mask(dev_priv);
33271288f9b0SKarthik B S 
33283a3b3c7dSVille Syrjälä 	de_port_enables = de_port_masked;
332970bfb307SMatt Roper 	if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
3330a52bb15bSVille Syrjälä 		de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
3331a52bb15bSVille Syrjälä 	else if (IS_BROADWELL(dev_priv))
3332e5abaab3SVille Syrjälä 		de_port_enables |= BDW_DE_PORT_HOTPLUG_MASK;
33333a3b3c7dSVille Syrjälä 
3334373abf1aSMatt Roper 	if (DISPLAY_VER(dev_priv) >= 12) {
33358241cfbeSJosé Roberto de Souza 		enum transcoder trans;
33368241cfbeSJosé Roberto de Souza 
3337562ddcb7SMatt Roper 		for_each_cpu_transcoder_masked(dev_priv, trans, trans_mask) {
33388241cfbeSJosé Roberto de Souza 			enum intel_display_power_domain domain;
33398241cfbeSJosé Roberto de Souza 
33408241cfbeSJosé Roberto de Souza 			domain = POWER_DOMAIN_TRANSCODER(trans);
33418241cfbeSJosé Roberto de Souza 			if (!intel_display_power_is_enabled(dev_priv, domain))
33428241cfbeSJosé Roberto de Souza 				continue;
33438241cfbeSJosé Roberto de Souza 
33448241cfbeSJosé Roberto de Souza 			gen3_assert_iir_is_zero(uncore, TRANS_PSR_IIR(trans));
33458241cfbeSJosé Roberto de Souza 		}
33468241cfbeSJosé Roberto de Souza 	} else {
3347b16b2a2fSPaulo Zanoni 		gen3_assert_iir_is_zero(uncore, EDP_PSR_IIR);
33488241cfbeSJosé Roberto de Souza 	}
3349e04f7eceSVille Syrjälä 
33500a195c02SMika Kahola 	for_each_pipe(dev_priv, pipe) {
33510a195c02SMika Kahola 		dev_priv->de_irq_mask[pipe] = ~de_pipe_masked;
3352abd58f01SBen Widawsky 
3353f458ebbcSDaniel Vetter 		if (intel_display_power_is_enabled(dev_priv,
3354813bde43SPaulo Zanoni 				POWER_DOMAIN_PIPE(pipe)))
3355b16b2a2fSPaulo Zanoni 			GEN8_IRQ_INIT_NDX(uncore, DE_PIPE, pipe,
3356813bde43SPaulo Zanoni 					  dev_priv->de_irq_mask[pipe],
335735079899SPaulo Zanoni 					  de_pipe_enables);
33580a195c02SMika Kahola 	}
3359abd58f01SBen Widawsky 
3360b16b2a2fSPaulo Zanoni 	GEN3_IRQ_INIT(uncore, GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
3361b16b2a2fSPaulo Zanoni 	GEN3_IRQ_INIT(uncore, GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked);
33622a57d9ccSImre Deak 
3363373abf1aSMatt Roper 	if (DISPLAY_VER(dev_priv) >= 11) {
3364121e758eSDhinakaran Pandiyan 		u32 de_hpd_masked = 0;
3365b796b971SDhinakaran Pandiyan 		u32 de_hpd_enables = GEN11_DE_TC_HOTPLUG_MASK |
3366b796b971SDhinakaran Pandiyan 				     GEN11_DE_TBT_HOTPLUG_MASK;
3367121e758eSDhinakaran Pandiyan 
3368b16b2a2fSPaulo Zanoni 		GEN3_IRQ_INIT(uncore, GEN11_DE_HPD_, ~de_hpd_masked,
3369b16b2a2fSPaulo Zanoni 			      de_hpd_enables);
3370abd58f01SBen Widawsky 	}
3371121e758eSDhinakaran Pandiyan }
3372abd58f01SBen Widawsky 
337359b7cb44STejas Upadhyay static void icp_irq_postinstall(struct drm_i915_private *dev_priv)
337459b7cb44STejas Upadhyay {
337559b7cb44STejas Upadhyay 	struct intel_uncore *uncore = &dev_priv->uncore;
337659b7cb44STejas Upadhyay 	u32 mask = SDE_GMBUS_ICP;
337759b7cb44STejas Upadhyay 
337859b7cb44STejas Upadhyay 	GEN3_IRQ_INIT(uncore, SDE, ~mask, 0xffffffff);
337959b7cb44STejas Upadhyay }
338059b7cb44STejas Upadhyay 
3381b318b824SVille Syrjälä static void gen8_irq_postinstall(struct drm_i915_private *dev_priv)
3382abd58f01SBen Widawsky {
338359b7cb44STejas Upadhyay 	if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
338459b7cb44STejas Upadhyay 		icp_irq_postinstall(dev_priv);
338559b7cb44STejas Upadhyay 	else if (HAS_PCH_SPLIT(dev_priv))
3386a0a6d8cbSVille Syrjälä 		ibx_irq_postinstall(dev_priv);
3387622364b6SPaulo Zanoni 
33882cbc876dSMichał Winiarski 	gen8_gt_irq_postinstall(to_gt(dev_priv));
3389abd58f01SBen Widawsky 	gen8_de_irq_postinstall(dev_priv);
3390abd58f01SBen Widawsky 
339125286aacSDaniele Ceraolo Spurio 	gen8_master_intr_enable(dev_priv->uncore.regs);
3392abd58f01SBen Widawsky }
3393abd58f01SBen Widawsky 
3394a844cfbeSJosé Roberto de Souza static void gen11_de_irq_postinstall(struct drm_i915_private *dev_priv)
3395a844cfbeSJosé Roberto de Souza {
3396a844cfbeSJosé Roberto de Souza 	if (!HAS_DISPLAY(dev_priv))
3397a844cfbeSJosé Roberto de Souza 		return;
3398a844cfbeSJosé Roberto de Souza 
3399a844cfbeSJosé Roberto de Souza 	gen8_de_irq_postinstall(dev_priv);
3400a844cfbeSJosé Roberto de Souza 
3401a844cfbeSJosé Roberto de Souza 	intel_uncore_write(&dev_priv->uncore, GEN11_DISPLAY_INT_CTL,
3402a844cfbeSJosé Roberto de Souza 			   GEN11_DISPLAY_IRQ_ENABLE);
3403a844cfbeSJosé Roberto de Souza }
340431604222SAnusha Srivatsa 
3405b318b824SVille Syrjälä static void gen11_irq_postinstall(struct drm_i915_private *dev_priv)
340651951ae7SMika Kuoppala {
34072cbc876dSMichał Winiarski 	struct intel_gt *gt = to_gt(dev_priv);
3408fd4d7904SPaulo Zanoni 	struct intel_uncore *uncore = gt->uncore;
3409df0d28c1SDhinakaran Pandiyan 	u32 gu_misc_masked = GEN11_GU_MISC_GSE;
341051951ae7SMika Kuoppala 
341129b43ae2SRodrigo Vivi 	if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
3412b318b824SVille Syrjälä 		icp_irq_postinstall(dev_priv);
341331604222SAnusha Srivatsa 
3414fd4d7904SPaulo Zanoni 	gen11_gt_irq_postinstall(gt);
3415a844cfbeSJosé Roberto de Souza 	gen11_de_irq_postinstall(dev_priv);
341651951ae7SMika Kuoppala 
3417b16b2a2fSPaulo Zanoni 	GEN3_IRQ_INIT(uncore, GEN11_GU_MISC_, ~gu_misc_masked, gu_misc_masked);
3418df0d28c1SDhinakaran Pandiyan 
34199b77011eSTvrtko Ursulin 	gen11_master_intr_enable(uncore->regs);
34202939eb06SJani Nikula 	intel_uncore_posting_read(&dev_priv->uncore, GEN11_GFX_MSTR_IRQ);
342151951ae7SMika Kuoppala }
342222e26af7SPaulo Zanoni 
342322e26af7SPaulo Zanoni static void dg1_irq_postinstall(struct drm_i915_private *dev_priv)
342422e26af7SPaulo Zanoni {
34252cbc876dSMichał Winiarski 	struct intel_gt *gt = to_gt(dev_priv);
3426fd4d7904SPaulo Zanoni 	struct intel_uncore *uncore = gt->uncore;
342722e26af7SPaulo Zanoni 	u32 gu_misc_masked = GEN11_GU_MISC_GSE;
342822e26af7SPaulo Zanoni 
3429fd4d7904SPaulo Zanoni 	gen11_gt_irq_postinstall(gt);
343022e26af7SPaulo Zanoni 
343122e26af7SPaulo Zanoni 	GEN3_IRQ_INIT(uncore, GEN11_GU_MISC_, ~gu_misc_masked, gu_misc_masked);
343222e26af7SPaulo Zanoni 
343322e26af7SPaulo Zanoni 	if (HAS_DISPLAY(dev_priv)) {
343422e26af7SPaulo Zanoni 		icp_irq_postinstall(dev_priv);
343522e26af7SPaulo Zanoni 		gen8_de_irq_postinstall(dev_priv);
343622e26af7SPaulo Zanoni 		intel_uncore_write(&dev_priv->uncore, GEN11_DISPLAY_INT_CTL,
343722e26af7SPaulo Zanoni 				   GEN11_DISPLAY_IRQ_ENABLE);
343822e26af7SPaulo Zanoni 	}
343922e26af7SPaulo Zanoni 
3440fd4d7904SPaulo Zanoni 	dg1_master_intr_enable(uncore->regs);
3441fd4d7904SPaulo Zanoni 	intel_uncore_posting_read(uncore, DG1_MSTR_TILE_INTR);
344297b492f5SLucas De Marchi }
344351951ae7SMika Kuoppala 
3444b318b824SVille Syrjälä static void cherryview_irq_postinstall(struct drm_i915_private *dev_priv)
344543f328d7SVille Syrjälä {
34462cbc876dSMichał Winiarski 	gen8_gt_irq_postinstall(to_gt(dev_priv));
344743f328d7SVille Syrjälä 
3448ad22d106SVille Syrjälä 	spin_lock_irq(&dev_priv->irq_lock);
34499918271eSVille Syrjälä 	if (dev_priv->display_irqs_enabled)
3450ad22d106SVille Syrjälä 		vlv_display_irq_postinstall(dev_priv);
3451ad22d106SVille Syrjälä 	spin_unlock_irq(&dev_priv->irq_lock);
3452ad22d106SVille Syrjälä 
34532939eb06SJani Nikula 	intel_uncore_write(&dev_priv->uncore, GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
34542939eb06SJani Nikula 	intel_uncore_posting_read(&dev_priv->uncore, GEN8_MASTER_IRQ);
345543f328d7SVille Syrjälä }
345643f328d7SVille Syrjälä 
3457b318b824SVille Syrjälä static void i8xx_irq_reset(struct drm_i915_private *dev_priv)
3458c2798b19SChris Wilson {
3459b16b2a2fSPaulo Zanoni 	struct intel_uncore *uncore = &dev_priv->uncore;
3460c2798b19SChris Wilson 
346144d9241eSVille Syrjälä 	i9xx_pipestat_irq_reset(dev_priv);
346244d9241eSVille Syrjälä 
3463ad7632ffSJani Nikula 	gen2_irq_reset(uncore);
3464e44adb5dSChris Wilson 	dev_priv->irq_mask = ~0u;
3465c2798b19SChris Wilson }
3466c2798b19SChris Wilson 
3467b318b824SVille Syrjälä static void i8xx_irq_postinstall(struct drm_i915_private *dev_priv)
3468c2798b19SChris Wilson {
3469b16b2a2fSPaulo Zanoni 	struct intel_uncore *uncore = &dev_priv->uncore;
3470e9e9848aSVille Syrjälä 	u16 enable_mask;
3471c2798b19SChris Wilson 
34724f5fd91fSTvrtko Ursulin 	intel_uncore_write16(uncore,
34734f5fd91fSTvrtko Ursulin 			     EMR,
34744f5fd91fSTvrtko Ursulin 			     ~(I915_ERROR_PAGE_TABLE |
3475045cebd2SVille Syrjälä 			       I915_ERROR_MEMORY_REFRESH));
3476c2798b19SChris Wilson 
3477c2798b19SChris Wilson 	/* Unmask the interrupts that we always want on. */
3478c2798b19SChris Wilson 	dev_priv->irq_mask =
3479c2798b19SChris Wilson 		~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
348016659bc5SVille Syrjälä 		  I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
348116659bc5SVille Syrjälä 		  I915_MASTER_ERROR_INTERRUPT);
3482c2798b19SChris Wilson 
3483e9e9848aSVille Syrjälä 	enable_mask =
3484c2798b19SChris Wilson 		I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3485c2798b19SChris Wilson 		I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
348616659bc5SVille Syrjälä 		I915_MASTER_ERROR_INTERRUPT |
3487e9e9848aSVille Syrjälä 		I915_USER_INTERRUPT;
3488e9e9848aSVille Syrjälä 
3489ad7632ffSJani Nikula 	gen2_irq_init(uncore, dev_priv->irq_mask, enable_mask);
3490c2798b19SChris Wilson 
3491379ef82dSDaniel Vetter 	/* Interrupt setup is already guaranteed to be single-threaded, this is
3492379ef82dSDaniel Vetter 	 * just to make the assert_spin_locked check happy. */
3493d6207435SDaniel Vetter 	spin_lock_irq(&dev_priv->irq_lock);
3494755e9019SImre Deak 	i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3495755e9019SImre Deak 	i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
3496d6207435SDaniel Vetter 	spin_unlock_irq(&dev_priv->irq_lock);
3497c2798b19SChris Wilson }
3498c2798b19SChris Wilson 
34994f5fd91fSTvrtko Ursulin static void i8xx_error_irq_ack(struct drm_i915_private *i915,
350078c357ddSVille Syrjälä 			       u16 *eir, u16 *eir_stuck)
350178c357ddSVille Syrjälä {
35024f5fd91fSTvrtko Ursulin 	struct intel_uncore *uncore = &i915->uncore;
350378c357ddSVille Syrjälä 	u16 emr;
350478c357ddSVille Syrjälä 
35054f5fd91fSTvrtko Ursulin 	*eir = intel_uncore_read16(uncore, EIR);
35064f5fd91fSTvrtko Ursulin 	intel_uncore_write16(uncore, EIR, *eir);
350778c357ddSVille Syrjälä 
35084f5fd91fSTvrtko Ursulin 	*eir_stuck = intel_uncore_read16(uncore, EIR);
350978c357ddSVille Syrjälä 	if (*eir_stuck == 0)
351078c357ddSVille Syrjälä 		return;
351178c357ddSVille Syrjälä 
351278c357ddSVille Syrjälä 	/*
351378c357ddSVille Syrjälä 	 * Toggle all EMR bits to make sure we get an edge
351478c357ddSVille Syrjälä 	 * in the ISR master error bit if we don't clear
351578c357ddSVille Syrjälä 	 * all the EIR bits. Otherwise the edge triggered
351678c357ddSVille Syrjälä 	 * IIR on i965/g4x wouldn't notice that an interrupt
351778c357ddSVille Syrjälä 	 * is still pending. Also some EIR bits can't be
351878c357ddSVille Syrjälä 	 * cleared except by handling the underlying error
351978c357ddSVille Syrjälä 	 * (or by a GPU reset) so we mask any bit that
352078c357ddSVille Syrjälä 	 * remains set.
352178c357ddSVille Syrjälä 	 */
35224f5fd91fSTvrtko Ursulin 	emr = intel_uncore_read16(uncore, EMR);
35234f5fd91fSTvrtko Ursulin 	intel_uncore_write16(uncore, EMR, 0xffff);
35244f5fd91fSTvrtko Ursulin 	intel_uncore_write16(uncore, EMR, emr | *eir_stuck);
352578c357ddSVille Syrjälä }
352678c357ddSVille Syrjälä 
352778c357ddSVille Syrjälä static void i8xx_error_irq_handler(struct drm_i915_private *dev_priv,
352878c357ddSVille Syrjälä 				   u16 eir, u16 eir_stuck)
352978c357ddSVille Syrjälä {
3530a10234fdSTvrtko Ursulin 	drm_dbg(&dev_priv->drm, "Master Error: EIR 0x%04x\n", eir);
353178c357ddSVille Syrjälä 
353278c357ddSVille Syrjälä 	if (eir_stuck)
353300376ccfSWambui Karuga 		drm_dbg(&dev_priv->drm, "EIR stuck: 0x%04x, masked\n",
353400376ccfSWambui Karuga 			eir_stuck);
353578c357ddSVille Syrjälä }
353678c357ddSVille Syrjälä 
353778c357ddSVille Syrjälä static void i9xx_error_irq_ack(struct drm_i915_private *dev_priv,
353878c357ddSVille Syrjälä 			       u32 *eir, u32 *eir_stuck)
353978c357ddSVille Syrjälä {
354078c357ddSVille Syrjälä 	u32 emr;
354178c357ddSVille Syrjälä 
3542*839259b8SVille Syrjälä 	*eir = intel_uncore_read(&dev_priv->uncore, EIR);
3543*839259b8SVille Syrjälä 	intel_uncore_write(&dev_priv->uncore, EIR, *eir);
354478c357ddSVille Syrjälä 
35452939eb06SJani Nikula 	*eir_stuck = intel_uncore_read(&dev_priv->uncore, EIR);
354678c357ddSVille Syrjälä 	if (*eir_stuck == 0)
354778c357ddSVille Syrjälä 		return;
354878c357ddSVille Syrjälä 
354978c357ddSVille Syrjälä 	/*
355078c357ddSVille Syrjälä 	 * Toggle all EMR bits to make sure we get an edge
355178c357ddSVille Syrjälä 	 * in the ISR master error bit if we don't clear
355278c357ddSVille Syrjälä 	 * all the EIR bits. Otherwise the edge triggered
355378c357ddSVille Syrjälä 	 * IIR on i965/g4x wouldn't notice that an interrupt
355478c357ddSVille Syrjälä 	 * is still pending. Also some EIR bits can't be
355578c357ddSVille Syrjälä 	 * cleared except by handling the underlying error
355678c357ddSVille Syrjälä 	 * (or by a GPU reset) so we mask any bit that
355778c357ddSVille Syrjälä 	 * remains set.
355878c357ddSVille Syrjälä 	 */
3559*839259b8SVille Syrjälä 	emr = intel_uncore_read(&dev_priv->uncore, EMR);
3560*839259b8SVille Syrjälä 	intel_uncore_write(&dev_priv->uncore, EMR, 0xffffffff);
35612939eb06SJani Nikula 	intel_uncore_write(&dev_priv->uncore, EMR, emr | *eir_stuck);
356278c357ddSVille Syrjälä }
356378c357ddSVille Syrjälä 
356478c357ddSVille Syrjälä static void i9xx_error_irq_handler(struct drm_i915_private *dev_priv,
356578c357ddSVille Syrjälä 				   u32 eir, u32 eir_stuck)
356678c357ddSVille Syrjälä {
3567a10234fdSTvrtko Ursulin 	drm_dbg(&dev_priv->drm, "Master Error, EIR 0x%08x\n", eir);
356878c357ddSVille Syrjälä 
356978c357ddSVille Syrjälä 	if (eir_stuck)
357000376ccfSWambui Karuga 		drm_dbg(&dev_priv->drm, "EIR stuck: 0x%08x, masked\n",
357100376ccfSWambui Karuga 			eir_stuck);
357278c357ddSVille Syrjälä }
357378c357ddSVille Syrjälä 
3574ff1f525eSDaniel Vetter static irqreturn_t i8xx_irq_handler(int irq, void *arg)
3575c2798b19SChris Wilson {
3576b318b824SVille Syrjälä 	struct drm_i915_private *dev_priv = arg;
3577af722d28SVille Syrjälä 	irqreturn_t ret = IRQ_NONE;
3578c2798b19SChris Wilson 
35792dd2a883SImre Deak 	if (!intel_irqs_enabled(dev_priv))
35802dd2a883SImre Deak 		return IRQ_NONE;
35812dd2a883SImre Deak 
35821f814dacSImre Deak 	/* IRQs are synced during runtime_suspend, we don't require a wakeref */
35839102650fSDaniele Ceraolo Spurio 	disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
35841f814dacSImre Deak 
3585af722d28SVille Syrjälä 	do {
3586af722d28SVille Syrjälä 		u32 pipe_stats[I915_MAX_PIPES] = {};
358778c357ddSVille Syrjälä 		u16 eir = 0, eir_stuck = 0;
3588af722d28SVille Syrjälä 		u16 iir;
3589af722d28SVille Syrjälä 
35904f5fd91fSTvrtko Ursulin 		iir = intel_uncore_read16(&dev_priv->uncore, GEN2_IIR);
3591c2798b19SChris Wilson 		if (iir == 0)
3592af722d28SVille Syrjälä 			break;
3593c2798b19SChris Wilson 
3594af722d28SVille Syrjälä 		ret = IRQ_HANDLED;
3595c2798b19SChris Wilson 
3596eb64343cSVille Syrjälä 		/* Call regardless, as some status bits might not be
3597eb64343cSVille Syrjälä 		 * signalled in iir */
3598eb64343cSVille Syrjälä 		i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
3599c2798b19SChris Wilson 
360078c357ddSVille Syrjälä 		if (iir & I915_MASTER_ERROR_INTERRUPT)
360178c357ddSVille Syrjälä 			i8xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
360278c357ddSVille Syrjälä 
36034f5fd91fSTvrtko Ursulin 		intel_uncore_write16(&dev_priv->uncore, GEN2_IIR, iir);
3604c2798b19SChris Wilson 
3605c2798b19SChris Wilson 		if (iir & I915_USER_INTERRUPT)
36062cbc876dSMichał Winiarski 			intel_engine_cs_irq(to_gt(dev_priv)->engine[RCS0], iir);
3607c2798b19SChris Wilson 
360878c357ddSVille Syrjälä 		if (iir & I915_MASTER_ERROR_INTERRUPT)
360978c357ddSVille Syrjälä 			i8xx_error_irq_handler(dev_priv, eir, eir_stuck);
3610af722d28SVille Syrjälä 
3611eb64343cSVille Syrjälä 		i8xx_pipestat_irq_handler(dev_priv, iir, pipe_stats);
3612af722d28SVille Syrjälä 	} while (0);
3613c2798b19SChris Wilson 
36149c6508b9SThomas Gleixner 	pmu_irq_stats(dev_priv, ret);
36159c6508b9SThomas Gleixner 
36169102650fSDaniele Ceraolo Spurio 	enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
36171f814dacSImre Deak 
36181f814dacSImre Deak 	return ret;
3619c2798b19SChris Wilson }
3620c2798b19SChris Wilson 
3621b318b824SVille Syrjälä static void i915_irq_reset(struct drm_i915_private *dev_priv)
3622a266c7d5SChris Wilson {
3623b16b2a2fSPaulo Zanoni 	struct intel_uncore *uncore = &dev_priv->uncore;
3624a266c7d5SChris Wilson 
362556b857a5STvrtko Ursulin 	if (I915_HAS_HOTPLUG(dev_priv)) {
36260706f17cSEgbert Eich 		i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
36278cee664dSAndrzej Hajda 		intel_uncore_rmw(&dev_priv->uncore, PORT_HOTPLUG_STAT, 0, 0);
3628a266c7d5SChris Wilson 	}
3629a266c7d5SChris Wilson 
363044d9241eSVille Syrjälä 	i9xx_pipestat_irq_reset(dev_priv);
363144d9241eSVille Syrjälä 
3632b16b2a2fSPaulo Zanoni 	GEN3_IRQ_RESET(uncore, GEN2_);
3633e44adb5dSChris Wilson 	dev_priv->irq_mask = ~0u;
3634a266c7d5SChris Wilson }
3635a266c7d5SChris Wilson 
3636b318b824SVille Syrjälä static void i915_irq_postinstall(struct drm_i915_private *dev_priv)
3637a266c7d5SChris Wilson {
3638b16b2a2fSPaulo Zanoni 	struct intel_uncore *uncore = &dev_priv->uncore;
363938bde180SChris Wilson 	u32 enable_mask;
3640a266c7d5SChris Wilson 
3641e58c2cacSAndrzej Hajda 	intel_uncore_write(uncore, EMR, ~(I915_ERROR_PAGE_TABLE |
3642045cebd2SVille Syrjälä 					  I915_ERROR_MEMORY_REFRESH));
364338bde180SChris Wilson 
364438bde180SChris Wilson 	/* Unmask the interrupts that we always want on. */
364538bde180SChris Wilson 	dev_priv->irq_mask =
364638bde180SChris Wilson 		~(I915_ASLE_INTERRUPT |
364738bde180SChris Wilson 		  I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
364816659bc5SVille Syrjälä 		  I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
364916659bc5SVille Syrjälä 		  I915_MASTER_ERROR_INTERRUPT);
365038bde180SChris Wilson 
365138bde180SChris Wilson 	enable_mask =
365238bde180SChris Wilson 		I915_ASLE_INTERRUPT |
365338bde180SChris Wilson 		I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
365438bde180SChris Wilson 		I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
365516659bc5SVille Syrjälä 		I915_MASTER_ERROR_INTERRUPT |
365638bde180SChris Wilson 		I915_USER_INTERRUPT;
365738bde180SChris Wilson 
365856b857a5STvrtko Ursulin 	if (I915_HAS_HOTPLUG(dev_priv)) {
3659a266c7d5SChris Wilson 		/* Enable in IER... */
3660a266c7d5SChris Wilson 		enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
3661a266c7d5SChris Wilson 		/* and unmask in IMR */
3662a266c7d5SChris Wilson 		dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
3663a266c7d5SChris Wilson 	}
3664a266c7d5SChris Wilson 
3665b16b2a2fSPaulo Zanoni 	GEN3_IRQ_INIT(uncore, GEN2_, dev_priv->irq_mask, enable_mask);
3666a266c7d5SChris Wilson 
3667379ef82dSDaniel Vetter 	/* Interrupt setup is already guaranteed to be single-threaded, this is
3668379ef82dSDaniel Vetter 	 * just to make the assert_spin_locked check happy. */
3669d6207435SDaniel Vetter 	spin_lock_irq(&dev_priv->irq_lock);
3670755e9019SImre Deak 	i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3671755e9019SImre Deak 	i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
3672d6207435SDaniel Vetter 	spin_unlock_irq(&dev_priv->irq_lock);
3673379ef82dSDaniel Vetter 
3674c30bb1fdSVille Syrjälä 	i915_enable_asle_pipestat(dev_priv);
367520afbda2SDaniel Vetter }
367620afbda2SDaniel Vetter 
3677ff1f525eSDaniel Vetter static irqreturn_t i915_irq_handler(int irq, void *arg)
3678a266c7d5SChris Wilson {
3679b318b824SVille Syrjälä 	struct drm_i915_private *dev_priv = arg;
3680af722d28SVille Syrjälä 	irqreturn_t ret = IRQ_NONE;
3681a266c7d5SChris Wilson 
36822dd2a883SImre Deak 	if (!intel_irqs_enabled(dev_priv))
36832dd2a883SImre Deak 		return IRQ_NONE;
36842dd2a883SImre Deak 
36851f814dacSImre Deak 	/* IRQs are synced during runtime_suspend, we don't require a wakeref */
36869102650fSDaniele Ceraolo Spurio 	disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
36871f814dacSImre Deak 
368838bde180SChris Wilson 	do {
3689eb64343cSVille Syrjälä 		u32 pipe_stats[I915_MAX_PIPES] = {};
369078c357ddSVille Syrjälä 		u32 eir = 0, eir_stuck = 0;
3691af722d28SVille Syrjälä 		u32 hotplug_status = 0;
3692af722d28SVille Syrjälä 		u32 iir;
3693a266c7d5SChris Wilson 
36942939eb06SJani Nikula 		iir = intel_uncore_read(&dev_priv->uncore, GEN2_IIR);
3695af722d28SVille Syrjälä 		if (iir == 0)
3696af722d28SVille Syrjälä 			break;
3697af722d28SVille Syrjälä 
3698af722d28SVille Syrjälä 		ret = IRQ_HANDLED;
3699af722d28SVille Syrjälä 
3700af722d28SVille Syrjälä 		if (I915_HAS_HOTPLUG(dev_priv) &&
3701af722d28SVille Syrjälä 		    iir & I915_DISPLAY_PORT_INTERRUPT)
3702af722d28SVille Syrjälä 			hotplug_status = i9xx_hpd_irq_ack(dev_priv);
3703a266c7d5SChris Wilson 
3704eb64343cSVille Syrjälä 		/* Call regardless, as some status bits might not be
3705eb64343cSVille Syrjälä 		 * signalled in iir */
3706eb64343cSVille Syrjälä 		i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
3707a266c7d5SChris Wilson 
370878c357ddSVille Syrjälä 		if (iir & I915_MASTER_ERROR_INTERRUPT)
370978c357ddSVille Syrjälä 			i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
371078c357ddSVille Syrjälä 
37112939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, GEN2_IIR, iir);
3712a266c7d5SChris Wilson 
3713a266c7d5SChris Wilson 		if (iir & I915_USER_INTERRUPT)
37142cbc876dSMichał Winiarski 			intel_engine_cs_irq(to_gt(dev_priv)->engine[RCS0], iir);
3715a266c7d5SChris Wilson 
371678c357ddSVille Syrjälä 		if (iir & I915_MASTER_ERROR_INTERRUPT)
371778c357ddSVille Syrjälä 			i9xx_error_irq_handler(dev_priv, eir, eir_stuck);
3718a266c7d5SChris Wilson 
3719af722d28SVille Syrjälä 		if (hotplug_status)
3720af722d28SVille Syrjälä 			i9xx_hpd_irq_handler(dev_priv, hotplug_status);
3721af722d28SVille Syrjälä 
3722af722d28SVille Syrjälä 		i915_pipestat_irq_handler(dev_priv, iir, pipe_stats);
3723af722d28SVille Syrjälä 	} while (0);
3724a266c7d5SChris Wilson 
37259c6508b9SThomas Gleixner 	pmu_irq_stats(dev_priv, ret);
37269c6508b9SThomas Gleixner 
37279102650fSDaniele Ceraolo Spurio 	enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
37281f814dacSImre Deak 
3729a266c7d5SChris Wilson 	return ret;
3730a266c7d5SChris Wilson }
3731a266c7d5SChris Wilson 
3732b318b824SVille Syrjälä static void i965_irq_reset(struct drm_i915_private *dev_priv)
3733a266c7d5SChris Wilson {
3734b16b2a2fSPaulo Zanoni 	struct intel_uncore *uncore = &dev_priv->uncore;
3735a266c7d5SChris Wilson 
37360706f17cSEgbert Eich 	i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
37378cee664dSAndrzej Hajda 	intel_uncore_rmw(uncore, PORT_HOTPLUG_STAT, 0, 0);
3738a266c7d5SChris Wilson 
373944d9241eSVille Syrjälä 	i9xx_pipestat_irq_reset(dev_priv);
374044d9241eSVille Syrjälä 
3741b16b2a2fSPaulo Zanoni 	GEN3_IRQ_RESET(uncore, GEN2_);
3742e44adb5dSChris Wilson 	dev_priv->irq_mask = ~0u;
3743a266c7d5SChris Wilson }
3744a266c7d5SChris Wilson 
3745b318b824SVille Syrjälä static void i965_irq_postinstall(struct drm_i915_private *dev_priv)
3746a266c7d5SChris Wilson {
3747b16b2a2fSPaulo Zanoni 	struct intel_uncore *uncore = &dev_priv->uncore;
3748bbba0a97SChris Wilson 	u32 enable_mask;
3749a266c7d5SChris Wilson 	u32 error_mask;
3750a266c7d5SChris Wilson 
3751045cebd2SVille Syrjälä 	/*
3752045cebd2SVille Syrjälä 	 * Enable some error detection, note the instruction error mask
3753045cebd2SVille Syrjälä 	 * bit is reserved, so we leave it masked.
3754045cebd2SVille Syrjälä 	 */
3755045cebd2SVille Syrjälä 	if (IS_G4X(dev_priv)) {
3756045cebd2SVille Syrjälä 		error_mask = ~(GM45_ERROR_PAGE_TABLE |
3757045cebd2SVille Syrjälä 			       GM45_ERROR_MEM_PRIV |
3758045cebd2SVille Syrjälä 			       GM45_ERROR_CP_PRIV |
3759045cebd2SVille Syrjälä 			       I915_ERROR_MEMORY_REFRESH);
3760045cebd2SVille Syrjälä 	} else {
3761045cebd2SVille Syrjälä 		error_mask = ~(I915_ERROR_PAGE_TABLE |
3762045cebd2SVille Syrjälä 			       I915_ERROR_MEMORY_REFRESH);
3763045cebd2SVille Syrjälä 	}
3764e58c2cacSAndrzej Hajda 	intel_uncore_write(uncore, EMR, error_mask);
3765045cebd2SVille Syrjälä 
3766a266c7d5SChris Wilson 	/* Unmask the interrupts that we always want on. */
3767c30bb1fdSVille Syrjälä 	dev_priv->irq_mask =
3768c30bb1fdSVille Syrjälä 		~(I915_ASLE_INTERRUPT |
3769adca4730SChris Wilson 		  I915_DISPLAY_PORT_INTERRUPT |
3770bbba0a97SChris Wilson 		  I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3771bbba0a97SChris Wilson 		  I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
377278c357ddSVille Syrjälä 		  I915_MASTER_ERROR_INTERRUPT);
3773bbba0a97SChris Wilson 
3774c30bb1fdSVille Syrjälä 	enable_mask =
3775c30bb1fdSVille Syrjälä 		I915_ASLE_INTERRUPT |
3776c30bb1fdSVille Syrjälä 		I915_DISPLAY_PORT_INTERRUPT |
3777c30bb1fdSVille Syrjälä 		I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3778c30bb1fdSVille Syrjälä 		I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
377978c357ddSVille Syrjälä 		I915_MASTER_ERROR_INTERRUPT |
3780c30bb1fdSVille Syrjälä 		I915_USER_INTERRUPT;
3781bbba0a97SChris Wilson 
378291d14251STvrtko Ursulin 	if (IS_G4X(dev_priv))
3783bbba0a97SChris Wilson 		enable_mask |= I915_BSD_USER_INTERRUPT;
3784a266c7d5SChris Wilson 
3785b16b2a2fSPaulo Zanoni 	GEN3_IRQ_INIT(uncore, GEN2_, dev_priv->irq_mask, enable_mask);
3786c30bb1fdSVille Syrjälä 
3787b79480baSDaniel Vetter 	/* Interrupt setup is already guaranteed to be single-threaded, this is
3788b79480baSDaniel Vetter 	 * just to make the assert_spin_locked check happy. */
3789d6207435SDaniel Vetter 	spin_lock_irq(&dev_priv->irq_lock);
3790755e9019SImre Deak 	i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3791755e9019SImre Deak 	i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3792755e9019SImre Deak 	i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
3793d6207435SDaniel Vetter 	spin_unlock_irq(&dev_priv->irq_lock);
3794a266c7d5SChris Wilson 
379591d14251STvrtko Ursulin 	i915_enable_asle_pipestat(dev_priv);
379620afbda2SDaniel Vetter }
379720afbda2SDaniel Vetter 
379891d14251STvrtko Ursulin static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
379920afbda2SDaniel Vetter {
380020afbda2SDaniel Vetter 	u32 hotplug_en;
380120afbda2SDaniel Vetter 
380267520415SChris Wilson 	lockdep_assert_held(&dev_priv->irq_lock);
3803b5ea2d56SDaniel Vetter 
3804adca4730SChris Wilson 	/* Note HDMI and DP share hotplug bits */
3805e5868a31SEgbert Eich 	/* enable bits are the same for all generations */
380691d14251STvrtko Ursulin 	hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
3807a266c7d5SChris Wilson 	/* Programming the CRT detection parameters tends
3808a266c7d5SChris Wilson 	   to generate a spurious hotplug event about three
3809a266c7d5SChris Wilson 	   seconds later.  So just do it once.
3810a266c7d5SChris Wilson 	*/
381191d14251STvrtko Ursulin 	if (IS_G4X(dev_priv))
3812a266c7d5SChris Wilson 		hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
3813a266c7d5SChris Wilson 	hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
3814a266c7d5SChris Wilson 
3815a266c7d5SChris Wilson 	/* Ignore TV since it's buggy */
38160706f17cSEgbert Eich 	i915_hotplug_interrupt_update_locked(dev_priv,
3817f9e3dc78SJani Nikula 					     HOTPLUG_INT_EN_MASK |
3818f9e3dc78SJani Nikula 					     CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
3819f9e3dc78SJani Nikula 					     CRT_HOTPLUG_ACTIVATION_PERIOD_64,
38200706f17cSEgbert Eich 					     hotplug_en);
3821a266c7d5SChris Wilson }
3822a266c7d5SChris Wilson 
3823ff1f525eSDaniel Vetter static irqreturn_t i965_irq_handler(int irq, void *arg)
3824a266c7d5SChris Wilson {
3825b318b824SVille Syrjälä 	struct drm_i915_private *dev_priv = arg;
3826af722d28SVille Syrjälä 	irqreturn_t ret = IRQ_NONE;
3827a266c7d5SChris Wilson 
38282dd2a883SImre Deak 	if (!intel_irqs_enabled(dev_priv))
38292dd2a883SImre Deak 		return IRQ_NONE;
38302dd2a883SImre Deak 
38311f814dacSImre Deak 	/* IRQs are synced during runtime_suspend, we don't require a wakeref */
38329102650fSDaniele Ceraolo Spurio 	disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
38331f814dacSImre Deak 
3834af722d28SVille Syrjälä 	do {
3835eb64343cSVille Syrjälä 		u32 pipe_stats[I915_MAX_PIPES] = {};
383678c357ddSVille Syrjälä 		u32 eir = 0, eir_stuck = 0;
3837af722d28SVille Syrjälä 		u32 hotplug_status = 0;
3838af722d28SVille Syrjälä 		u32 iir;
38392c8ba29fSChris Wilson 
38402939eb06SJani Nikula 		iir = intel_uncore_read(&dev_priv->uncore, GEN2_IIR);
3841af722d28SVille Syrjälä 		if (iir == 0)
3842af722d28SVille Syrjälä 			break;
3843af722d28SVille Syrjälä 
3844af722d28SVille Syrjälä 		ret = IRQ_HANDLED;
3845af722d28SVille Syrjälä 
3846af722d28SVille Syrjälä 		if (iir & I915_DISPLAY_PORT_INTERRUPT)
3847af722d28SVille Syrjälä 			hotplug_status = i9xx_hpd_irq_ack(dev_priv);
3848a266c7d5SChris Wilson 
3849eb64343cSVille Syrjälä 		/* Call regardless, as some status bits might not be
3850eb64343cSVille Syrjälä 		 * signalled in iir */
3851eb64343cSVille Syrjälä 		i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
3852a266c7d5SChris Wilson 
385378c357ddSVille Syrjälä 		if (iir & I915_MASTER_ERROR_INTERRUPT)
385478c357ddSVille Syrjälä 			i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
385578c357ddSVille Syrjälä 
38562939eb06SJani Nikula 		intel_uncore_write(&dev_priv->uncore, GEN2_IIR, iir);
3857a266c7d5SChris Wilson 
3858a266c7d5SChris Wilson 		if (iir & I915_USER_INTERRUPT)
38592cbc876dSMichał Winiarski 			intel_engine_cs_irq(to_gt(dev_priv)->engine[RCS0],
38600669a6e1SChris Wilson 					    iir);
3861af722d28SVille Syrjälä 
3862a266c7d5SChris Wilson 		if (iir & I915_BSD_USER_INTERRUPT)
38632cbc876dSMichał Winiarski 			intel_engine_cs_irq(to_gt(dev_priv)->engine[VCS0],
38640669a6e1SChris Wilson 					    iir >> 25);
3865a266c7d5SChris Wilson 
386678c357ddSVille Syrjälä 		if (iir & I915_MASTER_ERROR_INTERRUPT)
386778c357ddSVille Syrjälä 			i9xx_error_irq_handler(dev_priv, eir, eir_stuck);
3868515ac2bbSDaniel Vetter 
3869af722d28SVille Syrjälä 		if (hotplug_status)
3870af722d28SVille Syrjälä 			i9xx_hpd_irq_handler(dev_priv, hotplug_status);
3871af722d28SVille Syrjälä 
3872af722d28SVille Syrjälä 		i965_pipestat_irq_handler(dev_priv, iir, pipe_stats);
3873af722d28SVille Syrjälä 	} while (0);
3874a266c7d5SChris Wilson 
38759c6508b9SThomas Gleixner 	pmu_irq_stats(dev_priv, IRQ_HANDLED);
38769c6508b9SThomas Gleixner 
38779102650fSDaniele Ceraolo Spurio 	enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
38781f814dacSImre Deak 
3879a266c7d5SChris Wilson 	return ret;
3880a266c7d5SChris Wilson }
3881a266c7d5SChris Wilson 
38827e97596cSJani Nikula struct intel_hotplug_funcs {
38837e97596cSJani Nikula 	void (*hpd_irq_setup)(struct drm_i915_private *i915);
38847e97596cSJani Nikula };
38857e97596cSJani Nikula 
3886cd030c7cSDave Airlie #define HPD_FUNCS(platform)					 \
3887cd030c7cSDave Airlie static const struct intel_hotplug_funcs platform##_hpd_funcs = { \
3888cd030c7cSDave Airlie 	.hpd_irq_setup = platform##_hpd_irq_setup,		 \
3889cd030c7cSDave Airlie }
3890cd030c7cSDave Airlie 
3891cd030c7cSDave Airlie HPD_FUNCS(i915);
3892cd030c7cSDave Airlie HPD_FUNCS(dg1);
3893cd030c7cSDave Airlie HPD_FUNCS(gen11);
3894cd030c7cSDave Airlie HPD_FUNCS(bxt);
3895cd030c7cSDave Airlie HPD_FUNCS(icp);
3896cd030c7cSDave Airlie HPD_FUNCS(spt);
3897cd030c7cSDave Airlie HPD_FUNCS(ilk);
3898cd030c7cSDave Airlie #undef HPD_FUNCS
3899cd030c7cSDave Airlie 
39007e97596cSJani Nikula void intel_hpd_irq_setup(struct drm_i915_private *i915)
39017e97596cSJani Nikula {
39025a04eb5bSJani Nikula 	if (i915->display_irqs_enabled && i915->display.funcs.hotplug)
39035a04eb5bSJani Nikula 		i915->display.funcs.hotplug->hpd_irq_setup(i915);
39047e97596cSJani Nikula }
39057e97596cSJani Nikula 
3906fca52a55SDaniel Vetter /**
3907fca52a55SDaniel Vetter  * intel_irq_init - initializes irq support
3908fca52a55SDaniel Vetter  * @dev_priv: i915 device instance
3909fca52a55SDaniel Vetter  *
3910fca52a55SDaniel Vetter  * This function initializes all the irq support including work items, timers
3911fca52a55SDaniel Vetter  * and all the vtables. It does not setup the interrupt itself though.
3912fca52a55SDaniel Vetter  */
3913b963291cSDaniel Vetter void intel_irq_init(struct drm_i915_private *dev_priv)
3914f71d4af4SJesse Barnes {
3915cefcff8fSJoonas Lahtinen 	int i;
39168b2e326dSChris Wilson 
391774bb98baSLucas De Marchi 	INIT_WORK(&dev_priv->l3_parity.error_work, ivb_parity_work);
3918cefcff8fSJoonas Lahtinen 	for (i = 0; i < MAX_L3_SLICES; ++i)
3919cefcff8fSJoonas Lahtinen 		dev_priv->l3_parity.remap_info[i] = NULL;
39208b2e326dSChris Wilson 
3921633023a4SDaniele Ceraolo Spurio 	/* pre-gen11 the guc irqs bits are in the upper 16 bits of the pm reg */
3922651e7d48SLucas De Marchi 	if (HAS_GT_UC(dev_priv) && GRAPHICS_VER(dev_priv) < 11)
39232cbc876dSMichał Winiarski 		to_gt(dev_priv)->pm_guc_events = GUC_INTR_GUC2HOST << 16;
392426705e20SSagar Arun Kamble 
39259a450b68SLucas De Marchi 	if (!HAS_DISPLAY(dev_priv))
39269a450b68SLucas De Marchi 		return;
39279a450b68SLucas De Marchi 
392896bd87b7SLucas De Marchi 	intel_hpd_init_pins(dev_priv);
392996bd87b7SLucas De Marchi 
3930dd890d42SJani Nikula 	intel_hpd_init_early(dev_priv);
393196bd87b7SLucas De Marchi 
39323703060dSAndrzej Hajda 	dev_priv->drm.vblank_disable_immediate = true;
393321da2700SVille Syrjälä 
3934262fd485SChris Wilson 	/* Most platforms treat the display irq block as an always-on
3935262fd485SChris Wilson 	 * power domain. vlv/chv can disable it at runtime and need
3936262fd485SChris Wilson 	 * special care to avoid writing any of the display block registers
3937262fd485SChris Wilson 	 * outside of the power domain. We defer setting up the display irqs
3938262fd485SChris Wilson 	 * in this case to the runtime pm.
3939262fd485SChris Wilson 	 */
3940262fd485SChris Wilson 	dev_priv->display_irqs_enabled = true;
3941262fd485SChris Wilson 	if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
3942262fd485SChris Wilson 		dev_priv->display_irqs_enabled = false;
3943262fd485SChris Wilson 
39442ccf2e03SChris Wilson 	if (HAS_GMCH(dev_priv)) {
39452ccf2e03SChris Wilson 		if (I915_HAS_HOTPLUG(dev_priv))
39465a04eb5bSJani Nikula 			dev_priv->display.funcs.hotplug = &i915_hpd_funcs;
39472ccf2e03SChris Wilson 	} else {
39482f8a6699SMatt Roper 		if (HAS_PCH_DG2(dev_priv))
39495a04eb5bSJani Nikula 			dev_priv->display.funcs.hotplug = &icp_hpd_funcs;
39502f8a6699SMatt Roper 		else if (HAS_PCH_DG1(dev_priv))
39515a04eb5bSJani Nikula 			dev_priv->display.funcs.hotplug = &dg1_hpd_funcs;
3952373abf1aSMatt Roper 		else if (DISPLAY_VER(dev_priv) >= 11)
39535a04eb5bSJani Nikula 			dev_priv->display.funcs.hotplug = &gen11_hpd_funcs;
395470bfb307SMatt Roper 		else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
39555a04eb5bSJani Nikula 			dev_priv->display.funcs.hotplug = &bxt_hpd_funcs;
3956cec3295bSLyude Paul 		else if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
39575a04eb5bSJani Nikula 			dev_priv->display.funcs.hotplug = &icp_hpd_funcs;
3958c6c30b91SRodrigo Vivi 		else if (INTEL_PCH_TYPE(dev_priv) >= PCH_SPT)
39595a04eb5bSJani Nikula 			dev_priv->display.funcs.hotplug = &spt_hpd_funcs;
39606dbf30ceSVille Syrjälä 		else
39615a04eb5bSJani Nikula 			dev_priv->display.funcs.hotplug = &ilk_hpd_funcs;
3962f71d4af4SJesse Barnes 	}
39632ccf2e03SChris Wilson }
396420afbda2SDaniel Vetter 
3965fca52a55SDaniel Vetter /**
3966cefcff8fSJoonas Lahtinen  * intel_irq_fini - deinitializes IRQ support
3967cefcff8fSJoonas Lahtinen  * @i915: i915 device instance
3968cefcff8fSJoonas Lahtinen  *
3969cefcff8fSJoonas Lahtinen  * This function deinitializes all the IRQ support.
3970cefcff8fSJoonas Lahtinen  */
3971cefcff8fSJoonas Lahtinen void intel_irq_fini(struct drm_i915_private *i915)
3972cefcff8fSJoonas Lahtinen {
3973cefcff8fSJoonas Lahtinen 	int i;
3974cefcff8fSJoonas Lahtinen 
3975cefcff8fSJoonas Lahtinen 	for (i = 0; i < MAX_L3_SLICES; ++i)
3976cefcff8fSJoonas Lahtinen 		kfree(i915->l3_parity.remap_info[i]);
3977cefcff8fSJoonas Lahtinen }
3978cefcff8fSJoonas Lahtinen 
3979b318b824SVille Syrjälä static irq_handler_t intel_irq_handler(struct drm_i915_private *dev_priv)
3980b318b824SVille Syrjälä {
3981b318b824SVille Syrjälä 	if (HAS_GMCH(dev_priv)) {
3982b318b824SVille Syrjälä 		if (IS_CHERRYVIEW(dev_priv))
3983b318b824SVille Syrjälä 			return cherryview_irq_handler;
3984b318b824SVille Syrjälä 		else if (IS_VALLEYVIEW(dev_priv))
3985b318b824SVille Syrjälä 			return valleyview_irq_handler;
3986651e7d48SLucas De Marchi 		else if (GRAPHICS_VER(dev_priv) == 4)
3987b318b824SVille Syrjälä 			return i965_irq_handler;
3988651e7d48SLucas De Marchi 		else if (GRAPHICS_VER(dev_priv) == 3)
3989b318b824SVille Syrjälä 			return i915_irq_handler;
3990b318b824SVille Syrjälä 		else
3991b318b824SVille Syrjälä 			return i8xx_irq_handler;
3992b318b824SVille Syrjälä 	} else {
399322e26af7SPaulo Zanoni 		if (GRAPHICS_VER_FULL(dev_priv) >= IP_VER(12, 10))
399497b492f5SLucas De Marchi 			return dg1_irq_handler;
399522e26af7SPaulo Zanoni 		else if (GRAPHICS_VER(dev_priv) >= 11)
3996b318b824SVille Syrjälä 			return gen11_irq_handler;
3997651e7d48SLucas De Marchi 		else if (GRAPHICS_VER(dev_priv) >= 8)
3998b318b824SVille Syrjälä 			return gen8_irq_handler;
3999b318b824SVille Syrjälä 		else
40009eae5e27SLucas De Marchi 			return ilk_irq_handler;
4001b318b824SVille Syrjälä 	}
4002b318b824SVille Syrjälä }
4003b318b824SVille Syrjälä 
4004b318b824SVille Syrjälä static void intel_irq_reset(struct drm_i915_private *dev_priv)
4005b318b824SVille Syrjälä {
4006b318b824SVille Syrjälä 	if (HAS_GMCH(dev_priv)) {
4007b318b824SVille Syrjälä 		if (IS_CHERRYVIEW(dev_priv))
4008b318b824SVille Syrjälä 			cherryview_irq_reset(dev_priv);
4009b318b824SVille Syrjälä 		else if (IS_VALLEYVIEW(dev_priv))
4010b318b824SVille Syrjälä 			valleyview_irq_reset(dev_priv);
4011651e7d48SLucas De Marchi 		else if (GRAPHICS_VER(dev_priv) == 4)
4012b318b824SVille Syrjälä 			i965_irq_reset(dev_priv);
4013651e7d48SLucas De Marchi 		else if (GRAPHICS_VER(dev_priv) == 3)
4014b318b824SVille Syrjälä 			i915_irq_reset(dev_priv);
4015b318b824SVille Syrjälä 		else
4016b318b824SVille Syrjälä 			i8xx_irq_reset(dev_priv);
4017b318b824SVille Syrjälä 	} else {
401822e26af7SPaulo Zanoni 		if (GRAPHICS_VER_FULL(dev_priv) >= IP_VER(12, 10))
401922e26af7SPaulo Zanoni 			dg1_irq_reset(dev_priv);
402022e26af7SPaulo Zanoni 		else if (GRAPHICS_VER(dev_priv) >= 11)
4021b318b824SVille Syrjälä 			gen11_irq_reset(dev_priv);
4022651e7d48SLucas De Marchi 		else if (GRAPHICS_VER(dev_priv) >= 8)
4023b318b824SVille Syrjälä 			gen8_irq_reset(dev_priv);
4024b318b824SVille Syrjälä 		else
40259eae5e27SLucas De Marchi 			ilk_irq_reset(dev_priv);
4026b318b824SVille Syrjälä 	}
4027b318b824SVille Syrjälä }
4028b318b824SVille Syrjälä 
4029b318b824SVille Syrjälä static void intel_irq_postinstall(struct drm_i915_private *dev_priv)
4030b318b824SVille Syrjälä {
4031b318b824SVille Syrjälä 	if (HAS_GMCH(dev_priv)) {
4032b318b824SVille Syrjälä 		if (IS_CHERRYVIEW(dev_priv))
4033b318b824SVille Syrjälä 			cherryview_irq_postinstall(dev_priv);
4034b318b824SVille Syrjälä 		else if (IS_VALLEYVIEW(dev_priv))
4035b318b824SVille Syrjälä 			valleyview_irq_postinstall(dev_priv);
4036651e7d48SLucas De Marchi 		else if (GRAPHICS_VER(dev_priv) == 4)
4037b318b824SVille Syrjälä 			i965_irq_postinstall(dev_priv);
4038651e7d48SLucas De Marchi 		else if (GRAPHICS_VER(dev_priv) == 3)
4039b318b824SVille Syrjälä 			i915_irq_postinstall(dev_priv);
4040b318b824SVille Syrjälä 		else
4041b318b824SVille Syrjälä 			i8xx_irq_postinstall(dev_priv);
4042b318b824SVille Syrjälä 	} else {
404322e26af7SPaulo Zanoni 		if (GRAPHICS_VER_FULL(dev_priv) >= IP_VER(12, 10))
404422e26af7SPaulo Zanoni 			dg1_irq_postinstall(dev_priv);
404522e26af7SPaulo Zanoni 		else if (GRAPHICS_VER(dev_priv) >= 11)
4046b318b824SVille Syrjälä 			gen11_irq_postinstall(dev_priv);
4047651e7d48SLucas De Marchi 		else if (GRAPHICS_VER(dev_priv) >= 8)
4048b318b824SVille Syrjälä 			gen8_irq_postinstall(dev_priv);
4049b318b824SVille Syrjälä 		else
40509eae5e27SLucas De Marchi 			ilk_irq_postinstall(dev_priv);
4051b318b824SVille Syrjälä 	}
4052b318b824SVille Syrjälä }
4053b318b824SVille Syrjälä 
4054cefcff8fSJoonas Lahtinen /**
4055fca52a55SDaniel Vetter  * intel_irq_install - enables the hardware interrupt
4056fca52a55SDaniel Vetter  * @dev_priv: i915 device instance
4057fca52a55SDaniel Vetter  *
4058fca52a55SDaniel Vetter  * This function enables the hardware interrupt handling, but leaves the hotplug
4059fca52a55SDaniel Vetter  * handling still disabled. It is called after intel_irq_init().
4060fca52a55SDaniel Vetter  *
4061fca52a55SDaniel Vetter  * In the driver load and resume code we need working interrupts in a few places
4062fca52a55SDaniel Vetter  * but don't want to deal with the hassle of concurrent probe and hotplug
4063fca52a55SDaniel Vetter  * workers. Hence the split into this two-stage approach.
4064fca52a55SDaniel Vetter  */
40652aeb7d3aSDaniel Vetter int intel_irq_install(struct drm_i915_private *dev_priv)
40662aeb7d3aSDaniel Vetter {
40678ff5446aSThomas Zimmermann 	int irq = to_pci_dev(dev_priv->drm.dev)->irq;
4068b318b824SVille Syrjälä 	int ret;
4069b318b824SVille Syrjälä 
40702aeb7d3aSDaniel Vetter 	/*
40712aeb7d3aSDaniel Vetter 	 * We enable some interrupt sources in our postinstall hooks, so mark
40722aeb7d3aSDaniel Vetter 	 * interrupts as enabled _before_ actually enabling them to avoid
40732aeb7d3aSDaniel Vetter 	 * special cases in our ordering checks.
40742aeb7d3aSDaniel Vetter 	 */
4075ad1443f0SSagar Arun Kamble 	dev_priv->runtime_pm.irqs_enabled = true;
40762aeb7d3aSDaniel Vetter 
4077ac1723c1SThomas Zimmermann 	dev_priv->irq_enabled = true;
4078b318b824SVille Syrjälä 
4079b318b824SVille Syrjälä 	intel_irq_reset(dev_priv);
4080b318b824SVille Syrjälä 
4081b318b824SVille Syrjälä 	ret = request_irq(irq, intel_irq_handler(dev_priv),
4082b318b824SVille Syrjälä 			  IRQF_SHARED, DRIVER_NAME, dev_priv);
4083b318b824SVille Syrjälä 	if (ret < 0) {
4084ac1723c1SThomas Zimmermann 		dev_priv->irq_enabled = false;
4085b318b824SVille Syrjälä 		return ret;
4086b318b824SVille Syrjälä 	}
4087b318b824SVille Syrjälä 
4088b318b824SVille Syrjälä 	intel_irq_postinstall(dev_priv);
4089b318b824SVille Syrjälä 
4090b318b824SVille Syrjälä 	return ret;
40912aeb7d3aSDaniel Vetter }
40922aeb7d3aSDaniel Vetter 
4093fca52a55SDaniel Vetter /**
4094fca52a55SDaniel Vetter  * intel_irq_uninstall - finilizes all irq handling
4095fca52a55SDaniel Vetter  * @dev_priv: i915 device instance
4096fca52a55SDaniel Vetter  *
4097fca52a55SDaniel Vetter  * This stops interrupt and hotplug handling and unregisters and frees all
4098fca52a55SDaniel Vetter  * resources acquired in the init functions.
4099fca52a55SDaniel Vetter  */
41002aeb7d3aSDaniel Vetter void intel_irq_uninstall(struct drm_i915_private *dev_priv)
41012aeb7d3aSDaniel Vetter {
41028ff5446aSThomas Zimmermann 	int irq = to_pci_dev(dev_priv->drm.dev)->irq;
4103b318b824SVille Syrjälä 
4104b318b824SVille Syrjälä 	/*
4105789fa874SJanusz Krzysztofik 	 * FIXME we can get called twice during driver probe
4106789fa874SJanusz Krzysztofik 	 * error handling as well as during driver remove due to
4107789fa874SJanusz Krzysztofik 	 * intel_modeset_driver_remove() calling us out of sequence.
4108789fa874SJanusz Krzysztofik 	 * Would be nice if it didn't do that...
4109b318b824SVille Syrjälä 	 */
4110ac1723c1SThomas Zimmermann 	if (!dev_priv->irq_enabled)
4111b318b824SVille Syrjälä 		return;
4112b318b824SVille Syrjälä 
4113ac1723c1SThomas Zimmermann 	dev_priv->irq_enabled = false;
4114b318b824SVille Syrjälä 
4115b318b824SVille Syrjälä 	intel_irq_reset(dev_priv);
4116b318b824SVille Syrjälä 
4117b318b824SVille Syrjälä 	free_irq(irq, dev_priv);
4118b318b824SVille Syrjälä 
41192aeb7d3aSDaniel Vetter 	intel_hpd_cancel_work(dev_priv);
4120ad1443f0SSagar Arun Kamble 	dev_priv->runtime_pm.irqs_enabled = false;
41212aeb7d3aSDaniel Vetter }
41222aeb7d3aSDaniel Vetter 
4123fca52a55SDaniel Vetter /**
4124fca52a55SDaniel Vetter  * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4125fca52a55SDaniel Vetter  * @dev_priv: i915 device instance
4126fca52a55SDaniel Vetter  *
4127fca52a55SDaniel Vetter  * This function is used to disable interrupts at runtime, both in the runtime
4128fca52a55SDaniel Vetter  * pm and the system suspend/resume code.
4129fca52a55SDaniel Vetter  */
4130b963291cSDaniel Vetter void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
4131c67a470bSPaulo Zanoni {
4132b318b824SVille Syrjälä 	intel_irq_reset(dev_priv);
4133ad1443f0SSagar Arun Kamble 	dev_priv->runtime_pm.irqs_enabled = false;
4134315ca4c4SVille Syrjälä 	intel_synchronize_irq(dev_priv);
4135c67a470bSPaulo Zanoni }
4136c67a470bSPaulo Zanoni 
4137fca52a55SDaniel Vetter /**
4138fca52a55SDaniel Vetter  * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4139fca52a55SDaniel Vetter  * @dev_priv: i915 device instance
4140fca52a55SDaniel Vetter  *
4141fca52a55SDaniel Vetter  * This function is used to enable interrupts at runtime, both in the runtime
4142fca52a55SDaniel Vetter  * pm and the system suspend/resume code.
4143fca52a55SDaniel Vetter  */
4144b963291cSDaniel Vetter void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
4145c67a470bSPaulo Zanoni {
4146ad1443f0SSagar Arun Kamble 	dev_priv->runtime_pm.irqs_enabled = true;
4147b318b824SVille Syrjälä 	intel_irq_reset(dev_priv);
4148b318b824SVille Syrjälä 	intel_irq_postinstall(dev_priv);
4149c67a470bSPaulo Zanoni }
4150d64575eeSJani Nikula 
4151d64575eeSJani Nikula bool intel_irqs_enabled(struct drm_i915_private *dev_priv)
4152d64575eeSJani Nikula {
4153d64575eeSJani Nikula 	return dev_priv->runtime_pm.irqs_enabled;
4154d64575eeSJani Nikula }
4155d64575eeSJani Nikula 
4156d64575eeSJani Nikula void intel_synchronize_irq(struct drm_i915_private *i915)
4157d64575eeSJani Nikula {
41588ff5446aSThomas Zimmermann 	synchronize_irq(to_pci_dev(i915->drm.dev)->irq);
4159d64575eeSJani Nikula }
4160320ad343SThomas Zimmermann 
4161320ad343SThomas Zimmermann void intel_synchronize_hardirq(struct drm_i915_private *i915)
4162320ad343SThomas Zimmermann {
4163320ad343SThomas Zimmermann 	synchronize_hardirq(to_pci_dev(i915->drm.dev)->irq);
4164320ad343SThomas Zimmermann }
4165