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 31b2c88f5bSDamien Lespiau #include <linux/circ_buf.h> 3255367a27SJani Nikula #include <linux/slab.h> 3355367a27SJani Nikula #include <linux/sysrq.h> 3455367a27SJani Nikula 35fcd70cd3SDaniel Vetter #include <drm/drm_drv.h> 3655367a27SJani Nikula #include <drm/drm_irq.h> 37760285e7SDavid Howells #include <drm/i915_drm.h> 3855367a27SJani Nikula 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 452239e6dfSDaniele Ceraolo Spurio #include "gt/intel_gt.h" 46cf1c97dcSAndi Shyti #include "gt/intel_gt_irq.h" 47d762043fSAndi Shyti #include "gt/intel_gt_pm_irq.h" 482239e6dfSDaniele Ceraolo Spurio 49c0e09200SDave Airlie #include "i915_drv.h" 50440e2b3dSJani Nikula #include "i915_irq.h" 511c5d22f7SChris Wilson #include "i915_trace.h" 52d13616dbSJani Nikula #include "intel_pm.h" 53c0e09200SDave Airlie 54fca52a55SDaniel Vetter /** 55fca52a55SDaniel Vetter * DOC: interrupt handling 56fca52a55SDaniel Vetter * 57fca52a55SDaniel Vetter * These functions provide the basic support for enabling and disabling the 58fca52a55SDaniel Vetter * interrupt handling support. There's a lot more functionality in i915_irq.c 59fca52a55SDaniel Vetter * and related files, but that will be described in separate chapters. 60fca52a55SDaniel Vetter */ 61fca52a55SDaniel Vetter 6248ef15d3SJosé Roberto de Souza typedef bool (*long_pulse_detect_func)(enum hpd_pin pin, u32 val); 6348ef15d3SJosé Roberto de Souza 64e4ce95aaSVille Syrjälä static const u32 hpd_ilk[HPD_NUM_PINS] = { 65e4ce95aaSVille Syrjälä [HPD_PORT_A] = DE_DP_A_HOTPLUG, 66e4ce95aaSVille Syrjälä }; 67e4ce95aaSVille Syrjälä 6823bb4cb5SVille Syrjälä static const u32 hpd_ivb[HPD_NUM_PINS] = { 6923bb4cb5SVille Syrjälä [HPD_PORT_A] = DE_DP_A_HOTPLUG_IVB, 7023bb4cb5SVille Syrjälä }; 7123bb4cb5SVille Syrjälä 723a3b3c7dSVille Syrjälä static const u32 hpd_bdw[HPD_NUM_PINS] = { 733a3b3c7dSVille Syrjälä [HPD_PORT_A] = GEN8_PORT_DP_A_HOTPLUG, 743a3b3c7dSVille Syrjälä }; 753a3b3c7dSVille Syrjälä 767c7e10dbSVille Syrjälä static const u32 hpd_ibx[HPD_NUM_PINS] = { 77e5868a31SEgbert Eich [HPD_CRT] = SDE_CRT_HOTPLUG, 78e5868a31SEgbert Eich [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG, 79e5868a31SEgbert Eich [HPD_PORT_B] = SDE_PORTB_HOTPLUG, 80e5868a31SEgbert Eich [HPD_PORT_C] = SDE_PORTC_HOTPLUG, 81e5868a31SEgbert Eich [HPD_PORT_D] = SDE_PORTD_HOTPLUG 82e5868a31SEgbert Eich }; 83e5868a31SEgbert Eich 847c7e10dbSVille Syrjälä static const u32 hpd_cpt[HPD_NUM_PINS] = { 85e5868a31SEgbert Eich [HPD_CRT] = SDE_CRT_HOTPLUG_CPT, 8673c352a2SDaniel Vetter [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT, 87e5868a31SEgbert Eich [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT, 88e5868a31SEgbert Eich [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT, 89e5868a31SEgbert Eich [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT 90e5868a31SEgbert Eich }; 91e5868a31SEgbert Eich 9226951cafSXiong Zhang static const u32 hpd_spt[HPD_NUM_PINS] = { 9374c0b395SVille Syrjälä [HPD_PORT_A] = SDE_PORTA_HOTPLUG_SPT, 9426951cafSXiong Zhang [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT, 9526951cafSXiong Zhang [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT, 9626951cafSXiong Zhang [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT, 9726951cafSXiong Zhang [HPD_PORT_E] = SDE_PORTE_HOTPLUG_SPT 9826951cafSXiong Zhang }; 9926951cafSXiong Zhang 1007c7e10dbSVille Syrjälä static const u32 hpd_mask_i915[HPD_NUM_PINS] = { 101e5868a31SEgbert Eich [HPD_CRT] = CRT_HOTPLUG_INT_EN, 102e5868a31SEgbert Eich [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN, 103e5868a31SEgbert Eich [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN, 104e5868a31SEgbert Eich [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN, 105e5868a31SEgbert Eich [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN, 106e5868a31SEgbert Eich [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN 107e5868a31SEgbert Eich }; 108e5868a31SEgbert Eich 1097c7e10dbSVille Syrjälä static const u32 hpd_status_g4x[HPD_NUM_PINS] = { 110e5868a31SEgbert Eich [HPD_CRT] = CRT_HOTPLUG_INT_STATUS, 111e5868a31SEgbert Eich [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X, 112e5868a31SEgbert Eich [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X, 113e5868a31SEgbert Eich [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS, 114e5868a31SEgbert Eich [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS, 115e5868a31SEgbert Eich [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS 116e5868a31SEgbert Eich }; 117e5868a31SEgbert Eich 1184bca26d0SVille Syrjälä static const u32 hpd_status_i915[HPD_NUM_PINS] = { 119e5868a31SEgbert Eich [HPD_CRT] = CRT_HOTPLUG_INT_STATUS, 120e5868a31SEgbert Eich [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915, 121e5868a31SEgbert Eich [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915, 122e5868a31SEgbert Eich [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS, 123e5868a31SEgbert Eich [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS, 124e5868a31SEgbert Eich [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS 125e5868a31SEgbert Eich }; 126e5868a31SEgbert Eich 127e0a20ad7SShashank Sharma /* BXT hpd list */ 128e0a20ad7SShashank Sharma static const u32 hpd_bxt[HPD_NUM_PINS] = { 1297f3561beSSonika Jindal [HPD_PORT_A] = BXT_DE_PORT_HP_DDIA, 130e0a20ad7SShashank Sharma [HPD_PORT_B] = BXT_DE_PORT_HP_DDIB, 131e0a20ad7SShashank Sharma [HPD_PORT_C] = BXT_DE_PORT_HP_DDIC 132e0a20ad7SShashank Sharma }; 133e0a20ad7SShashank Sharma 134b796b971SDhinakaran Pandiyan static const u32 hpd_gen11[HPD_NUM_PINS] = { 135b796b971SDhinakaran Pandiyan [HPD_PORT_C] = GEN11_TC1_HOTPLUG | GEN11_TBT1_HOTPLUG, 136b796b971SDhinakaran Pandiyan [HPD_PORT_D] = GEN11_TC2_HOTPLUG | GEN11_TBT2_HOTPLUG, 137b796b971SDhinakaran Pandiyan [HPD_PORT_E] = GEN11_TC3_HOTPLUG | GEN11_TBT3_HOTPLUG, 138b796b971SDhinakaran Pandiyan [HPD_PORT_F] = GEN11_TC4_HOTPLUG | GEN11_TBT4_HOTPLUG 139121e758eSDhinakaran Pandiyan }; 140121e758eSDhinakaran Pandiyan 14148ef15d3SJosé Roberto de Souza static const u32 hpd_gen12[HPD_NUM_PINS] = { 14248ef15d3SJosé Roberto de Souza [HPD_PORT_D] = GEN11_TC1_HOTPLUG | GEN11_TBT1_HOTPLUG, 14348ef15d3SJosé Roberto de Souza [HPD_PORT_E] = GEN11_TC2_HOTPLUG | GEN11_TBT2_HOTPLUG, 14448ef15d3SJosé Roberto de Souza [HPD_PORT_F] = GEN11_TC3_HOTPLUG | GEN11_TBT3_HOTPLUG, 14548ef15d3SJosé Roberto de Souza [HPD_PORT_G] = GEN11_TC4_HOTPLUG | GEN11_TBT4_HOTPLUG, 14648ef15d3SJosé Roberto de Souza [HPD_PORT_H] = GEN12_TC5_HOTPLUG | GEN12_TBT5_HOTPLUG, 14748ef15d3SJosé Roberto de Souza [HPD_PORT_I] = GEN12_TC6_HOTPLUG | GEN12_TBT6_HOTPLUG 14848ef15d3SJosé Roberto de Souza }; 14948ef15d3SJosé Roberto de Souza 15031604222SAnusha Srivatsa static const u32 hpd_icp[HPD_NUM_PINS] = { 151b32821c0SLucas De Marchi [HPD_PORT_A] = SDE_DDI_HOTPLUG_ICP(PORT_A), 152b32821c0SLucas De Marchi [HPD_PORT_B] = SDE_DDI_HOTPLUG_ICP(PORT_B), 153b32821c0SLucas De Marchi [HPD_PORT_C] = SDE_TC_HOTPLUG_ICP(PORT_TC1), 154b32821c0SLucas De Marchi [HPD_PORT_D] = SDE_TC_HOTPLUG_ICP(PORT_TC2), 155b32821c0SLucas De Marchi [HPD_PORT_E] = SDE_TC_HOTPLUG_ICP(PORT_TC3), 156b32821c0SLucas De Marchi [HPD_PORT_F] = SDE_TC_HOTPLUG_ICP(PORT_TC4), 15731604222SAnusha Srivatsa }; 15831604222SAnusha Srivatsa 15952dfdba0SLucas De Marchi static const u32 hpd_tgp[HPD_NUM_PINS] = { 160b32821c0SLucas De Marchi [HPD_PORT_A] = SDE_DDI_HOTPLUG_ICP(PORT_A), 161b32821c0SLucas De Marchi [HPD_PORT_B] = SDE_DDI_HOTPLUG_ICP(PORT_B), 162b32821c0SLucas De Marchi [HPD_PORT_C] = SDE_DDI_HOTPLUG_ICP(PORT_C), 163b32821c0SLucas De Marchi [HPD_PORT_D] = SDE_TC_HOTPLUG_ICP(PORT_TC1), 164b32821c0SLucas De Marchi [HPD_PORT_E] = SDE_TC_HOTPLUG_ICP(PORT_TC2), 165b32821c0SLucas De Marchi [HPD_PORT_F] = SDE_TC_HOTPLUG_ICP(PORT_TC3), 166b32821c0SLucas De Marchi [HPD_PORT_G] = SDE_TC_HOTPLUG_ICP(PORT_TC4), 167b32821c0SLucas De Marchi [HPD_PORT_H] = SDE_TC_HOTPLUG_ICP(PORT_TC5), 168b32821c0SLucas De Marchi [HPD_PORT_I] = SDE_TC_HOTPLUG_ICP(PORT_TC6), 16952dfdba0SLucas De Marchi }; 17052dfdba0SLucas De Marchi 171cf1c97dcSAndi Shyti void gen3_irq_reset(struct intel_uncore *uncore, i915_reg_t imr, 17268eb49b1SPaulo Zanoni i915_reg_t iir, i915_reg_t ier) 17368eb49b1SPaulo Zanoni { 17465f42cdcSPaulo Zanoni intel_uncore_write(uncore, imr, 0xffffffff); 17565f42cdcSPaulo Zanoni intel_uncore_posting_read(uncore, imr); 17668eb49b1SPaulo Zanoni 17765f42cdcSPaulo Zanoni intel_uncore_write(uncore, ier, 0); 17868eb49b1SPaulo Zanoni 1795c502442SPaulo Zanoni /* IIR can theoretically queue up two events. Be paranoid. */ 18065f42cdcSPaulo Zanoni intel_uncore_write(uncore, iir, 0xffffffff); 18165f42cdcSPaulo Zanoni intel_uncore_posting_read(uncore, iir); 18265f42cdcSPaulo Zanoni intel_uncore_write(uncore, iir, 0xffffffff); 18365f42cdcSPaulo Zanoni intel_uncore_posting_read(uncore, iir); 18468eb49b1SPaulo Zanoni } 1855c502442SPaulo Zanoni 186cf1c97dcSAndi Shyti void gen2_irq_reset(struct intel_uncore *uncore) 18768eb49b1SPaulo Zanoni { 18865f42cdcSPaulo Zanoni intel_uncore_write16(uncore, GEN2_IMR, 0xffff); 18965f42cdcSPaulo Zanoni intel_uncore_posting_read16(uncore, GEN2_IMR); 190a9d356a6SPaulo Zanoni 19165f42cdcSPaulo Zanoni intel_uncore_write16(uncore, GEN2_IER, 0); 19268eb49b1SPaulo Zanoni 19368eb49b1SPaulo Zanoni /* IIR can theoretically queue up two events. Be paranoid. */ 19465f42cdcSPaulo Zanoni intel_uncore_write16(uncore, GEN2_IIR, 0xffff); 19565f42cdcSPaulo Zanoni intel_uncore_posting_read16(uncore, GEN2_IIR); 19665f42cdcSPaulo Zanoni intel_uncore_write16(uncore, GEN2_IIR, 0xffff); 19765f42cdcSPaulo Zanoni intel_uncore_posting_read16(uncore, GEN2_IIR); 19868eb49b1SPaulo Zanoni } 19968eb49b1SPaulo Zanoni 200337ba017SPaulo Zanoni /* 201337ba017SPaulo Zanoni * We should clear IMR at preinstall/uninstall, and just check at postinstall. 202337ba017SPaulo Zanoni */ 20365f42cdcSPaulo Zanoni static void gen3_assert_iir_is_zero(struct intel_uncore *uncore, i915_reg_t reg) 204b51a2842SVille Syrjälä { 20565f42cdcSPaulo Zanoni u32 val = intel_uncore_read(uncore, reg); 206b51a2842SVille Syrjälä 207b51a2842SVille Syrjälä if (val == 0) 208b51a2842SVille Syrjälä return; 209b51a2842SVille Syrjälä 210b51a2842SVille Syrjälä WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n", 211f0f59a00SVille Syrjälä i915_mmio_reg_offset(reg), val); 21265f42cdcSPaulo Zanoni intel_uncore_write(uncore, reg, 0xffffffff); 21365f42cdcSPaulo Zanoni intel_uncore_posting_read(uncore, reg); 21465f42cdcSPaulo Zanoni intel_uncore_write(uncore, reg, 0xffffffff); 21565f42cdcSPaulo Zanoni intel_uncore_posting_read(uncore, reg); 216b51a2842SVille Syrjälä } 217337ba017SPaulo Zanoni 21865f42cdcSPaulo Zanoni static void gen2_assert_iir_is_zero(struct intel_uncore *uncore) 219e9e9848aSVille Syrjälä { 22065f42cdcSPaulo Zanoni u16 val = intel_uncore_read16(uncore, GEN2_IIR); 221e9e9848aSVille Syrjälä 222e9e9848aSVille Syrjälä if (val == 0) 223e9e9848aSVille Syrjälä return; 224e9e9848aSVille Syrjälä 225e9e9848aSVille Syrjälä WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n", 2269d9523d8SPaulo Zanoni i915_mmio_reg_offset(GEN2_IIR), val); 22765f42cdcSPaulo Zanoni intel_uncore_write16(uncore, GEN2_IIR, 0xffff); 22865f42cdcSPaulo Zanoni intel_uncore_posting_read16(uncore, GEN2_IIR); 22965f42cdcSPaulo Zanoni intel_uncore_write16(uncore, GEN2_IIR, 0xffff); 23065f42cdcSPaulo Zanoni intel_uncore_posting_read16(uncore, GEN2_IIR); 231e9e9848aSVille Syrjälä } 232e9e9848aSVille Syrjälä 233cf1c97dcSAndi Shyti void gen3_irq_init(struct intel_uncore *uncore, 23468eb49b1SPaulo Zanoni i915_reg_t imr, u32 imr_val, 23568eb49b1SPaulo Zanoni i915_reg_t ier, u32 ier_val, 23668eb49b1SPaulo Zanoni i915_reg_t iir) 23768eb49b1SPaulo Zanoni { 23865f42cdcSPaulo Zanoni gen3_assert_iir_is_zero(uncore, iir); 23935079899SPaulo Zanoni 24065f42cdcSPaulo Zanoni intel_uncore_write(uncore, ier, ier_val); 24165f42cdcSPaulo Zanoni intel_uncore_write(uncore, imr, imr_val); 24265f42cdcSPaulo Zanoni intel_uncore_posting_read(uncore, imr); 24368eb49b1SPaulo Zanoni } 24435079899SPaulo Zanoni 245cf1c97dcSAndi Shyti void gen2_irq_init(struct intel_uncore *uncore, 2462918c3caSPaulo Zanoni u32 imr_val, u32 ier_val) 24768eb49b1SPaulo Zanoni { 24865f42cdcSPaulo Zanoni gen2_assert_iir_is_zero(uncore); 24968eb49b1SPaulo Zanoni 25065f42cdcSPaulo Zanoni intel_uncore_write16(uncore, GEN2_IER, ier_val); 25165f42cdcSPaulo Zanoni intel_uncore_write16(uncore, GEN2_IMR, imr_val); 25265f42cdcSPaulo Zanoni intel_uncore_posting_read16(uncore, GEN2_IMR); 25368eb49b1SPaulo Zanoni } 25468eb49b1SPaulo Zanoni 2550706f17cSEgbert Eich /* For display hotplug interrupt */ 2560706f17cSEgbert Eich static inline void 2570706f17cSEgbert Eich i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv, 258a9c287c9SJani Nikula u32 mask, 259a9c287c9SJani Nikula u32 bits) 2600706f17cSEgbert Eich { 261a9c287c9SJani Nikula u32 val; 2620706f17cSEgbert Eich 26367520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 2640706f17cSEgbert Eich WARN_ON(bits & ~mask); 2650706f17cSEgbert Eich 2660706f17cSEgbert Eich val = I915_READ(PORT_HOTPLUG_EN); 2670706f17cSEgbert Eich val &= ~mask; 2680706f17cSEgbert Eich val |= bits; 2690706f17cSEgbert Eich I915_WRITE(PORT_HOTPLUG_EN, val); 2700706f17cSEgbert Eich } 2710706f17cSEgbert Eich 2720706f17cSEgbert Eich /** 2730706f17cSEgbert Eich * i915_hotplug_interrupt_update - update hotplug interrupt enable 2740706f17cSEgbert Eich * @dev_priv: driver private 2750706f17cSEgbert Eich * @mask: bits to update 2760706f17cSEgbert Eich * @bits: bits to enable 2770706f17cSEgbert Eich * NOTE: the HPD enable bits are modified both inside and outside 2780706f17cSEgbert Eich * of an interrupt context. To avoid that read-modify-write cycles 2790706f17cSEgbert Eich * interfer, these bits are protected by a spinlock. Since this 2800706f17cSEgbert Eich * function is usually not called from a context where the lock is 2810706f17cSEgbert Eich * held already, this function acquires the lock itself. A non-locking 2820706f17cSEgbert Eich * version is also available. 2830706f17cSEgbert Eich */ 2840706f17cSEgbert Eich void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv, 285a9c287c9SJani Nikula u32 mask, 286a9c287c9SJani Nikula u32 bits) 2870706f17cSEgbert Eich { 2880706f17cSEgbert Eich spin_lock_irq(&dev_priv->irq_lock); 2890706f17cSEgbert Eich i915_hotplug_interrupt_update_locked(dev_priv, mask, bits); 2900706f17cSEgbert Eich spin_unlock_irq(&dev_priv->irq_lock); 2910706f17cSEgbert Eich } 2920706f17cSEgbert Eich 293d9dc34f1SVille Syrjälä /** 294d9dc34f1SVille Syrjälä * ilk_update_display_irq - update DEIMR 295d9dc34f1SVille Syrjälä * @dev_priv: driver private 296d9dc34f1SVille Syrjälä * @interrupt_mask: mask of interrupt bits to update 297d9dc34f1SVille Syrjälä * @enabled_irq_mask: mask of interrupt bits to enable 298d9dc34f1SVille Syrjälä */ 299fbdedaeaSVille Syrjälä void ilk_update_display_irq(struct drm_i915_private *dev_priv, 300a9c287c9SJani Nikula u32 interrupt_mask, 301a9c287c9SJani Nikula u32 enabled_irq_mask) 302036a4a7dSZhenyu Wang { 303a9c287c9SJani Nikula u32 new_val; 304d9dc34f1SVille Syrjälä 30567520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 3064bc9d430SDaniel Vetter 307d9dc34f1SVille Syrjälä WARN_ON(enabled_irq_mask & ~interrupt_mask); 308d9dc34f1SVille Syrjälä 3099df7575fSJesse Barnes if (WARN_ON(!intel_irqs_enabled(dev_priv))) 310c67a470bSPaulo Zanoni return; 311c67a470bSPaulo Zanoni 312d9dc34f1SVille Syrjälä new_val = dev_priv->irq_mask; 313d9dc34f1SVille Syrjälä new_val &= ~interrupt_mask; 314d9dc34f1SVille Syrjälä new_val |= (~enabled_irq_mask & interrupt_mask); 315d9dc34f1SVille Syrjälä 316d9dc34f1SVille Syrjälä if (new_val != dev_priv->irq_mask) { 317d9dc34f1SVille Syrjälä dev_priv->irq_mask = new_val; 3181ec14ad3SChris Wilson I915_WRITE(DEIMR, dev_priv->irq_mask); 3193143a2bfSChris Wilson POSTING_READ(DEIMR); 320036a4a7dSZhenyu Wang } 321036a4a7dSZhenyu Wang } 322036a4a7dSZhenyu Wang 323f0f59a00SVille Syrjälä static i915_reg_t gen6_pm_iir(struct drm_i915_private *dev_priv) 324b900b949SImre Deak { 325d02b98b8SOscar Mateo WARN_ON_ONCE(INTEL_GEN(dev_priv) >= 11); 326d02b98b8SOscar Mateo 327bca2bf2aSPandiyan, Dhinakaran return INTEL_GEN(dev_priv) >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR; 328b900b949SImre Deak } 329b900b949SImre Deak 330d02b98b8SOscar Mateo void gen11_reset_rps_interrupts(struct drm_i915_private *dev_priv) 331d02b98b8SOscar Mateo { 332d762043fSAndi Shyti struct intel_gt *gt = &dev_priv->gt; 333d02b98b8SOscar Mateo 334d762043fSAndi Shyti spin_lock_irq(>->irq_lock); 335d762043fSAndi Shyti 336cf1c97dcSAndi Shyti while (gen11_gt_reset_one_iir(gt, 0, GEN11_GTPM)) 33796606f3bSOscar Mateo ; 338d02b98b8SOscar Mateo 339d02b98b8SOscar Mateo dev_priv->gt_pm.rps.pm_iir = 0; 340d02b98b8SOscar Mateo 341d762043fSAndi Shyti spin_unlock_irq(>->irq_lock); 342d02b98b8SOscar Mateo } 343d02b98b8SOscar Mateo 344dc97997aSChris Wilson void gen6_reset_rps_interrupts(struct drm_i915_private *dev_priv) 3453cc134e3SImre Deak { 346d762043fSAndi Shyti struct intel_gt *gt = &dev_priv->gt; 347d762043fSAndi Shyti 348d762043fSAndi Shyti spin_lock_irq(>->irq_lock); 349d762043fSAndi Shyti gen6_gt_pm_reset_iir(gt, GEN6_PM_RPS_EVENTS); 350562d9baeSSagar Arun Kamble dev_priv->gt_pm.rps.pm_iir = 0; 351d762043fSAndi Shyti spin_unlock_irq(>->irq_lock); 3523cc134e3SImre Deak } 3533cc134e3SImre Deak 35491d14251STvrtko Ursulin void gen6_enable_rps_interrupts(struct drm_i915_private *dev_priv) 355b900b949SImre Deak { 35658820574STvrtko Ursulin struct intel_gt *gt = &dev_priv->gt; 357562d9baeSSagar Arun Kamble struct intel_rps *rps = &dev_priv->gt_pm.rps; 358562d9baeSSagar Arun Kamble 359562d9baeSSagar Arun Kamble if (READ_ONCE(rps->interrupts_enabled)) 360f2a91d1aSChris Wilson return; 361f2a91d1aSChris Wilson 362d762043fSAndi Shyti spin_lock_irq(>->irq_lock); 363562d9baeSSagar Arun Kamble WARN_ON_ONCE(rps->pm_iir); 36496606f3bSOscar Mateo 365d02b98b8SOscar Mateo if (INTEL_GEN(dev_priv) >= 11) 366cf1c97dcSAndi Shyti WARN_ON_ONCE(gen11_gt_reset_one_iir(gt, 0, GEN11_GTPM)); 367d02b98b8SOscar Mateo else 368c33d247dSChris Wilson WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events); 36996606f3bSOscar Mateo 370562d9baeSSagar Arun Kamble rps->interrupts_enabled = true; 371d762043fSAndi Shyti gen6_gt_pm_enable_irq(gt, dev_priv->pm_rps_events); 37278e68d36SImre Deak 373d762043fSAndi Shyti spin_unlock_irq(>->irq_lock); 374b900b949SImre Deak } 375b900b949SImre Deak 376d64575eeSJani Nikula u32 gen6_sanitize_rps_pm_mask(const struct drm_i915_private *i915, u32 mask) 377d64575eeSJani Nikula { 378d64575eeSJani Nikula return mask & ~i915->gt_pm.rps.pm_intrmsk_mbz; 379d64575eeSJani Nikula } 380d64575eeSJani Nikula 38191d14251STvrtko Ursulin void gen6_disable_rps_interrupts(struct drm_i915_private *dev_priv) 382b900b949SImre Deak { 383562d9baeSSagar Arun Kamble struct intel_rps *rps = &dev_priv->gt_pm.rps; 384d762043fSAndi Shyti struct intel_gt *gt = &dev_priv->gt; 385562d9baeSSagar Arun Kamble 386562d9baeSSagar Arun Kamble if (!READ_ONCE(rps->interrupts_enabled)) 387f2a91d1aSChris Wilson return; 388f2a91d1aSChris Wilson 389d762043fSAndi Shyti spin_lock_irq(>->irq_lock); 390562d9baeSSagar Arun Kamble rps->interrupts_enabled = false; 3919939fba2SImre Deak 392b20e3cfeSDave Gordon I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0u)); 3939939fba2SImre Deak 394d762043fSAndi Shyti gen6_gt_pm_disable_irq(gt, GEN6_PM_RPS_EVENTS); 39558072ccbSImre Deak 396d762043fSAndi Shyti spin_unlock_irq(>->irq_lock); 397315ca4c4SVille Syrjälä intel_synchronize_irq(dev_priv); 398c33d247dSChris Wilson 399c33d247dSChris Wilson /* Now that we will not be generating any more work, flush any 4003814fd77SOscar Mateo * outstanding tasks. As we are called on the RPS idle path, 401c33d247dSChris Wilson * we will reset the GPU to minimum frequencies, so the current 402c33d247dSChris Wilson * state of the worker can be discarded. 403c33d247dSChris Wilson */ 404562d9baeSSagar Arun Kamble cancel_work_sync(&rps->work); 405d02b98b8SOscar Mateo if (INTEL_GEN(dev_priv) >= 11) 406d02b98b8SOscar Mateo gen11_reset_rps_interrupts(dev_priv); 407d02b98b8SOscar Mateo else 408c33d247dSChris Wilson gen6_reset_rps_interrupts(dev_priv); 409b900b949SImre Deak } 410b900b949SImre Deak 4119cbd51c2SDaniele Ceraolo Spurio void gen9_reset_guc_interrupts(struct intel_guc *guc) 41226705e20SSagar Arun Kamble { 4132239e6dfSDaniele Ceraolo Spurio struct intel_gt *gt = guc_to_gt(guc); 4149cbd51c2SDaniele Ceraolo Spurio 415cd6a8513SChris Wilson assert_rpm_wakelock_held(gt->uncore->rpm); 4161be333d3SSagar Arun Kamble 417d762043fSAndi Shyti spin_lock_irq(>->irq_lock); 418d762043fSAndi Shyti gen6_gt_pm_reset_iir(gt, gt->pm_guc_events); 419d762043fSAndi Shyti spin_unlock_irq(>->irq_lock); 42026705e20SSagar Arun Kamble } 42126705e20SSagar Arun Kamble 4229cbd51c2SDaniele Ceraolo Spurio void gen9_enable_guc_interrupts(struct intel_guc *guc) 42326705e20SSagar Arun Kamble { 4242239e6dfSDaniele Ceraolo Spurio struct intel_gt *gt = guc_to_gt(guc); 4259cbd51c2SDaniele Ceraolo Spurio 426cd6a8513SChris Wilson assert_rpm_wakelock_held(gt->uncore->rpm); 4271be333d3SSagar Arun Kamble 428d762043fSAndi Shyti spin_lock_irq(>->irq_lock); 4299cbd51c2SDaniele Ceraolo Spurio if (!guc->interrupts.enabled) { 430d762043fSAndi Shyti WARN_ON_ONCE(intel_uncore_read(gt->uncore, 431d762043fSAndi Shyti gen6_pm_iir(gt->i915)) & 4322239e6dfSDaniele Ceraolo Spurio gt->pm_guc_events); 4339cbd51c2SDaniele Ceraolo Spurio guc->interrupts.enabled = true; 434d762043fSAndi Shyti gen6_gt_pm_enable_irq(gt, gt->pm_guc_events); 43526705e20SSagar Arun Kamble } 436d762043fSAndi Shyti spin_unlock_irq(>->irq_lock); 43726705e20SSagar Arun Kamble } 43826705e20SSagar Arun Kamble 4399cbd51c2SDaniele Ceraolo Spurio void gen9_disable_guc_interrupts(struct intel_guc *guc) 44026705e20SSagar Arun Kamble { 4412239e6dfSDaniele Ceraolo Spurio struct intel_gt *gt = guc_to_gt(guc); 4429cbd51c2SDaniele Ceraolo Spurio 443cd6a8513SChris Wilson assert_rpm_wakelock_held(gt->uncore->rpm); 4441be333d3SSagar Arun Kamble 445d762043fSAndi Shyti spin_lock_irq(>->irq_lock); 4469cbd51c2SDaniele Ceraolo Spurio guc->interrupts.enabled = false; 44726705e20SSagar Arun Kamble 448d762043fSAndi Shyti gen6_gt_pm_disable_irq(gt, gt->pm_guc_events); 44926705e20SSagar Arun Kamble 450d762043fSAndi Shyti spin_unlock_irq(>->irq_lock); 451d762043fSAndi Shyti intel_synchronize_irq(gt->i915); 45226705e20SSagar Arun Kamble 4539cbd51c2SDaniele Ceraolo Spurio gen9_reset_guc_interrupts(guc); 45426705e20SSagar Arun Kamble } 45526705e20SSagar Arun Kamble 4569cbd51c2SDaniele Ceraolo Spurio void gen11_reset_guc_interrupts(struct intel_guc *guc) 45754c52a84SOscar Mateo { 4582239e6dfSDaniele Ceraolo Spurio struct intel_gt *gt = guc_to_gt(guc); 4599cbd51c2SDaniele Ceraolo Spurio 460d762043fSAndi Shyti spin_lock_irq(>->irq_lock); 461cf1c97dcSAndi Shyti gen11_gt_reset_one_iir(gt, 0, GEN11_GUC); 462d762043fSAndi Shyti spin_unlock_irq(>->irq_lock); 46354c52a84SOscar Mateo } 46454c52a84SOscar Mateo 4659cbd51c2SDaniele Ceraolo Spurio void gen11_enable_guc_interrupts(struct intel_guc *guc) 46654c52a84SOscar Mateo { 4672239e6dfSDaniele Ceraolo Spurio struct intel_gt *gt = guc_to_gt(guc); 4689cbd51c2SDaniele Ceraolo Spurio 469d762043fSAndi Shyti spin_lock_irq(>->irq_lock); 4709cbd51c2SDaniele Ceraolo Spurio if (!guc->interrupts.enabled) { 471633023a4SDaniele Ceraolo Spurio u32 events = REG_FIELD_PREP(ENGINE1_MASK, GUC_INTR_GUC2HOST); 47254c52a84SOscar Mateo 473cf1c97dcSAndi Shyti WARN_ON_ONCE(gen11_gt_reset_one_iir(gt, 0, GEN11_GUC)); 4742239e6dfSDaniele Ceraolo Spurio intel_uncore_write(gt->uncore, GEN11_GUC_SG_INTR_ENABLE, events); 4752239e6dfSDaniele Ceraolo Spurio intel_uncore_write(gt->uncore, GEN11_GUC_SG_INTR_MASK, ~events); 4769cbd51c2SDaniele Ceraolo Spurio guc->interrupts.enabled = true; 47754c52a84SOscar Mateo } 478d762043fSAndi Shyti spin_unlock_irq(>->irq_lock); 47954c52a84SOscar Mateo } 48054c52a84SOscar Mateo 4819cbd51c2SDaniele Ceraolo Spurio void gen11_disable_guc_interrupts(struct intel_guc *guc) 48254c52a84SOscar Mateo { 4832239e6dfSDaniele Ceraolo Spurio struct intel_gt *gt = guc_to_gt(guc); 4849cbd51c2SDaniele Ceraolo Spurio 485d762043fSAndi Shyti spin_lock_irq(>->irq_lock); 4869cbd51c2SDaniele Ceraolo Spurio guc->interrupts.enabled = false; 48754c52a84SOscar Mateo 4882239e6dfSDaniele Ceraolo Spurio intel_uncore_write(gt->uncore, GEN11_GUC_SG_INTR_MASK, ~0); 4892239e6dfSDaniele Ceraolo Spurio intel_uncore_write(gt->uncore, GEN11_GUC_SG_INTR_ENABLE, 0); 49054c52a84SOscar Mateo 491d762043fSAndi Shyti spin_unlock_irq(>->irq_lock); 492d762043fSAndi Shyti intel_synchronize_irq(gt->i915); 49354c52a84SOscar Mateo 4949cbd51c2SDaniele Ceraolo Spurio gen11_reset_guc_interrupts(guc); 49554c52a84SOscar Mateo } 49654c52a84SOscar Mateo 4970961021aSBen Widawsky /** 4983a3b3c7dSVille Syrjälä * bdw_update_port_irq - update DE port interrupt 4993a3b3c7dSVille Syrjälä * @dev_priv: driver private 5003a3b3c7dSVille Syrjälä * @interrupt_mask: mask of interrupt bits to update 5013a3b3c7dSVille Syrjälä * @enabled_irq_mask: mask of interrupt bits to enable 5023a3b3c7dSVille Syrjälä */ 5033a3b3c7dSVille Syrjälä static void bdw_update_port_irq(struct drm_i915_private *dev_priv, 504a9c287c9SJani Nikula u32 interrupt_mask, 505a9c287c9SJani Nikula u32 enabled_irq_mask) 5063a3b3c7dSVille Syrjälä { 507a9c287c9SJani Nikula u32 new_val; 508a9c287c9SJani Nikula u32 old_val; 5093a3b3c7dSVille Syrjälä 51067520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 5113a3b3c7dSVille Syrjälä 5123a3b3c7dSVille Syrjälä WARN_ON(enabled_irq_mask & ~interrupt_mask); 5133a3b3c7dSVille Syrjälä 5143a3b3c7dSVille Syrjälä if (WARN_ON(!intel_irqs_enabled(dev_priv))) 5153a3b3c7dSVille Syrjälä return; 5163a3b3c7dSVille Syrjälä 5173a3b3c7dSVille Syrjälä old_val = I915_READ(GEN8_DE_PORT_IMR); 5183a3b3c7dSVille Syrjälä 5193a3b3c7dSVille Syrjälä new_val = old_val; 5203a3b3c7dSVille Syrjälä new_val &= ~interrupt_mask; 5213a3b3c7dSVille Syrjälä new_val |= (~enabled_irq_mask & interrupt_mask); 5223a3b3c7dSVille Syrjälä 5233a3b3c7dSVille Syrjälä if (new_val != old_val) { 5243a3b3c7dSVille Syrjälä I915_WRITE(GEN8_DE_PORT_IMR, new_val); 5253a3b3c7dSVille Syrjälä POSTING_READ(GEN8_DE_PORT_IMR); 5263a3b3c7dSVille Syrjälä } 5273a3b3c7dSVille Syrjälä } 5283a3b3c7dSVille Syrjälä 5293a3b3c7dSVille Syrjälä /** 530013d3752SVille Syrjälä * bdw_update_pipe_irq - update DE pipe interrupt 531013d3752SVille Syrjälä * @dev_priv: driver private 532013d3752SVille Syrjälä * @pipe: pipe whose interrupt to update 533013d3752SVille Syrjälä * @interrupt_mask: mask of interrupt bits to update 534013d3752SVille Syrjälä * @enabled_irq_mask: mask of interrupt bits to enable 535013d3752SVille Syrjälä */ 536013d3752SVille Syrjälä void bdw_update_pipe_irq(struct drm_i915_private *dev_priv, 537013d3752SVille Syrjälä enum pipe pipe, 538a9c287c9SJani Nikula u32 interrupt_mask, 539a9c287c9SJani Nikula u32 enabled_irq_mask) 540013d3752SVille Syrjälä { 541a9c287c9SJani Nikula u32 new_val; 542013d3752SVille Syrjälä 54367520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 544013d3752SVille Syrjälä 545013d3752SVille Syrjälä WARN_ON(enabled_irq_mask & ~interrupt_mask); 546013d3752SVille Syrjälä 547013d3752SVille Syrjälä if (WARN_ON(!intel_irqs_enabled(dev_priv))) 548013d3752SVille Syrjälä return; 549013d3752SVille Syrjälä 550013d3752SVille Syrjälä new_val = dev_priv->de_irq_mask[pipe]; 551013d3752SVille Syrjälä new_val &= ~interrupt_mask; 552013d3752SVille Syrjälä new_val |= (~enabled_irq_mask & interrupt_mask); 553013d3752SVille Syrjälä 554013d3752SVille Syrjälä if (new_val != dev_priv->de_irq_mask[pipe]) { 555013d3752SVille Syrjälä dev_priv->de_irq_mask[pipe] = new_val; 556013d3752SVille Syrjälä I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]); 557013d3752SVille Syrjälä POSTING_READ(GEN8_DE_PIPE_IMR(pipe)); 558013d3752SVille Syrjälä } 559013d3752SVille Syrjälä } 560013d3752SVille Syrjälä 561013d3752SVille Syrjälä /** 562fee884edSDaniel Vetter * ibx_display_interrupt_update - update SDEIMR 563fee884edSDaniel Vetter * @dev_priv: driver private 564fee884edSDaniel Vetter * @interrupt_mask: mask of interrupt bits to update 565fee884edSDaniel Vetter * @enabled_irq_mask: mask of interrupt bits to enable 566fee884edSDaniel Vetter */ 56747339cd9SDaniel Vetter void ibx_display_interrupt_update(struct drm_i915_private *dev_priv, 568a9c287c9SJani Nikula u32 interrupt_mask, 569a9c287c9SJani Nikula u32 enabled_irq_mask) 570fee884edSDaniel Vetter { 571a9c287c9SJani Nikula u32 sdeimr = I915_READ(SDEIMR); 572fee884edSDaniel Vetter sdeimr &= ~interrupt_mask; 573fee884edSDaniel Vetter sdeimr |= (~enabled_irq_mask & interrupt_mask); 574fee884edSDaniel Vetter 57515a17aaeSDaniel Vetter WARN_ON(enabled_irq_mask & ~interrupt_mask); 57615a17aaeSDaniel Vetter 57767520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 578fee884edSDaniel Vetter 5799df7575fSJesse Barnes if (WARN_ON(!intel_irqs_enabled(dev_priv))) 580c67a470bSPaulo Zanoni return; 581c67a470bSPaulo Zanoni 582fee884edSDaniel Vetter I915_WRITE(SDEIMR, sdeimr); 583fee884edSDaniel Vetter POSTING_READ(SDEIMR); 584fee884edSDaniel Vetter } 5858664281bSPaulo Zanoni 5866b12ca56SVille Syrjälä u32 i915_pipestat_enable_mask(struct drm_i915_private *dev_priv, 5876b12ca56SVille Syrjälä enum pipe pipe) 5887c463586SKeith Packard { 5896b12ca56SVille Syrjälä u32 status_mask = dev_priv->pipestat_irq_mask[pipe]; 59010c59c51SImre Deak u32 enable_mask = status_mask << 16; 59110c59c51SImre Deak 5926b12ca56SVille Syrjälä lockdep_assert_held(&dev_priv->irq_lock); 5936b12ca56SVille Syrjälä 5946b12ca56SVille Syrjälä if (INTEL_GEN(dev_priv) < 5) 5956b12ca56SVille Syrjälä goto out; 5966b12ca56SVille Syrjälä 59710c59c51SImre Deak /* 598724a6905SVille Syrjälä * On pipe A we don't support the PSR interrupt yet, 599724a6905SVille Syrjälä * on pipe B and C the same bit MBZ. 60010c59c51SImre Deak */ 60110c59c51SImre Deak if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV)) 60210c59c51SImre Deak return 0; 603724a6905SVille Syrjälä /* 604724a6905SVille Syrjälä * On pipe B and C we don't support the PSR interrupt yet, on pipe 605724a6905SVille Syrjälä * A the same bit is for perf counters which we don't use either. 606724a6905SVille Syrjälä */ 607724a6905SVille Syrjälä if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV)) 608724a6905SVille Syrjälä return 0; 60910c59c51SImre Deak 61010c59c51SImre Deak enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS | 61110c59c51SImre Deak SPRITE0_FLIP_DONE_INT_EN_VLV | 61210c59c51SImre Deak SPRITE1_FLIP_DONE_INT_EN_VLV); 61310c59c51SImre Deak if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV) 61410c59c51SImre Deak enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV; 61510c59c51SImre Deak if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV) 61610c59c51SImre Deak enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV; 61710c59c51SImre Deak 6186b12ca56SVille Syrjälä out: 6196b12ca56SVille Syrjälä WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK || 6206b12ca56SVille Syrjälä status_mask & ~PIPESTAT_INT_STATUS_MASK, 6216b12ca56SVille Syrjälä "pipe %c: enable_mask=0x%x, status_mask=0x%x\n", 6226b12ca56SVille Syrjälä pipe_name(pipe), enable_mask, status_mask); 6236b12ca56SVille Syrjälä 62410c59c51SImre Deak return enable_mask; 62510c59c51SImre Deak } 62610c59c51SImre Deak 6276b12ca56SVille Syrjälä void i915_enable_pipestat(struct drm_i915_private *dev_priv, 6286b12ca56SVille Syrjälä enum pipe pipe, u32 status_mask) 629755e9019SImre Deak { 6306b12ca56SVille Syrjälä i915_reg_t reg = PIPESTAT(pipe); 631755e9019SImre Deak u32 enable_mask; 632755e9019SImre Deak 6336b12ca56SVille Syrjälä WARN_ONCE(status_mask & ~PIPESTAT_INT_STATUS_MASK, 6346b12ca56SVille Syrjälä "pipe %c: status_mask=0x%x\n", 6356b12ca56SVille Syrjälä pipe_name(pipe), status_mask); 6366b12ca56SVille Syrjälä 6376b12ca56SVille Syrjälä lockdep_assert_held(&dev_priv->irq_lock); 6386b12ca56SVille Syrjälä WARN_ON(!intel_irqs_enabled(dev_priv)); 6396b12ca56SVille Syrjälä 6406b12ca56SVille Syrjälä if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == status_mask) 6416b12ca56SVille Syrjälä return; 6426b12ca56SVille Syrjälä 6436b12ca56SVille Syrjälä dev_priv->pipestat_irq_mask[pipe] |= status_mask; 6446b12ca56SVille Syrjälä enable_mask = i915_pipestat_enable_mask(dev_priv, pipe); 6456b12ca56SVille Syrjälä 6466b12ca56SVille Syrjälä I915_WRITE(reg, enable_mask | status_mask); 6476b12ca56SVille Syrjälä POSTING_READ(reg); 648755e9019SImre Deak } 649755e9019SImre Deak 6506b12ca56SVille Syrjälä void i915_disable_pipestat(struct drm_i915_private *dev_priv, 6516b12ca56SVille Syrjälä enum pipe pipe, u32 status_mask) 652755e9019SImre Deak { 6536b12ca56SVille Syrjälä i915_reg_t reg = PIPESTAT(pipe); 654755e9019SImre Deak u32 enable_mask; 655755e9019SImre Deak 6566b12ca56SVille Syrjälä WARN_ONCE(status_mask & ~PIPESTAT_INT_STATUS_MASK, 6576b12ca56SVille Syrjälä "pipe %c: status_mask=0x%x\n", 6586b12ca56SVille Syrjälä pipe_name(pipe), status_mask); 6596b12ca56SVille Syrjälä 6606b12ca56SVille Syrjälä lockdep_assert_held(&dev_priv->irq_lock); 6616b12ca56SVille Syrjälä WARN_ON(!intel_irqs_enabled(dev_priv)); 6626b12ca56SVille Syrjälä 6636b12ca56SVille Syrjälä if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == 0) 6646b12ca56SVille Syrjälä return; 6656b12ca56SVille Syrjälä 6666b12ca56SVille Syrjälä dev_priv->pipestat_irq_mask[pipe] &= ~status_mask; 6676b12ca56SVille Syrjälä enable_mask = i915_pipestat_enable_mask(dev_priv, pipe); 6686b12ca56SVille Syrjälä 6696b12ca56SVille Syrjälä I915_WRITE(reg, enable_mask | status_mask); 6706b12ca56SVille Syrjälä POSTING_READ(reg); 671755e9019SImre Deak } 672755e9019SImre Deak 673f3e30485SVille Syrjälä static bool i915_has_asle(struct drm_i915_private *dev_priv) 674f3e30485SVille Syrjälä { 675f3e30485SVille Syrjälä if (!dev_priv->opregion.asle) 676f3e30485SVille Syrjälä return false; 677f3e30485SVille Syrjälä 678f3e30485SVille Syrjälä return IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv); 679f3e30485SVille Syrjälä } 680f3e30485SVille Syrjälä 681c0e09200SDave Airlie /** 682f49e38ddSJani Nikula * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion 68314bb2c11STvrtko Ursulin * @dev_priv: i915 device private 68401c66889SZhao Yakui */ 68591d14251STvrtko Ursulin static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv) 68601c66889SZhao Yakui { 687f3e30485SVille Syrjälä if (!i915_has_asle(dev_priv)) 688f49e38ddSJani Nikula return; 689f49e38ddSJani Nikula 69013321786SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 69101c66889SZhao Yakui 692755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS); 69391d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 4) 6943b6c42e8SDaniel Vetter i915_enable_pipestat(dev_priv, PIPE_A, 695755e9019SImre Deak PIPE_LEGACY_BLC_EVENT_STATUS); 6961ec14ad3SChris Wilson 69713321786SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 69801c66889SZhao Yakui } 69901c66889SZhao Yakui 700f75f3746SVille Syrjälä /* 701f75f3746SVille Syrjälä * This timing diagram depicts the video signal in and 702f75f3746SVille Syrjälä * around the vertical blanking period. 703f75f3746SVille Syrjälä * 704f75f3746SVille Syrjälä * Assumptions about the fictitious mode used in this example: 705f75f3746SVille Syrjälä * vblank_start >= 3 706f75f3746SVille Syrjälä * vsync_start = vblank_start + 1 707f75f3746SVille Syrjälä * vsync_end = vblank_start + 2 708f75f3746SVille Syrjälä * vtotal = vblank_start + 3 709f75f3746SVille Syrjälä * 710f75f3746SVille Syrjälä * start of vblank: 711f75f3746SVille Syrjälä * latch double buffered registers 712f75f3746SVille Syrjälä * increment frame counter (ctg+) 713f75f3746SVille Syrjälä * generate start of vblank interrupt (gen4+) 714f75f3746SVille Syrjälä * | 715f75f3746SVille Syrjälä * | frame start: 716f75f3746SVille Syrjälä * | generate frame start interrupt (aka. vblank interrupt) (gmch) 717f75f3746SVille Syrjälä * | may be shifted forward 1-3 extra lines via PIPECONF 718f75f3746SVille Syrjälä * | | 719f75f3746SVille Syrjälä * | | start of vsync: 720f75f3746SVille Syrjälä * | | generate vsync interrupt 721f75f3746SVille Syrjälä * | | | 722f75f3746SVille Syrjälä * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx 723f75f3746SVille Syrjälä * . \hs/ . \hs/ \hs/ \hs/ . \hs/ 724f75f3746SVille Syrjälä * ----va---> <-----------------vb--------------------> <--------va------------- 725f75f3746SVille Syrjälä * | | <----vs-----> | 726f75f3746SVille Syrjälä * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2) 727f75f3746SVille Syrjälä * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+) 728f75f3746SVille Syrjälä * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi) 729f75f3746SVille Syrjälä * | | | 730f75f3746SVille Syrjälä * last visible pixel first visible pixel 731f75f3746SVille Syrjälä * | increment frame counter (gen3/4) 732f75f3746SVille Syrjälä * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4) 733f75f3746SVille Syrjälä * 734f75f3746SVille Syrjälä * x = horizontal active 735f75f3746SVille Syrjälä * _ = horizontal blanking 736f75f3746SVille Syrjälä * hs = horizontal sync 737f75f3746SVille Syrjälä * va = vertical active 738f75f3746SVille Syrjälä * vb = vertical blanking 739f75f3746SVille Syrjälä * vs = vertical sync 740f75f3746SVille Syrjälä * vbs = vblank_start (number) 741f75f3746SVille Syrjälä * 742f75f3746SVille Syrjälä * Summary: 743f75f3746SVille Syrjälä * - most events happen at the start of horizontal sync 744f75f3746SVille Syrjälä * - frame start happens at the start of horizontal blank, 1-4 lines 745f75f3746SVille Syrjälä * (depending on PIPECONF settings) after the start of vblank 746f75f3746SVille Syrjälä * - gen3/4 pixel and frame counter are synchronized with the start 747f75f3746SVille Syrjälä * of horizontal active on the first line of vertical active 748f75f3746SVille Syrjälä */ 749f75f3746SVille Syrjälä 75042f52ef8SKeith Packard /* Called from drm generic code, passed a 'crtc', which 75142f52ef8SKeith Packard * we use as a pipe index 75242f52ef8SKeith Packard */ 75308fa8fd0SVille Syrjälä u32 i915_get_vblank_counter(struct drm_crtc *crtc) 7540a3e67a4SJesse Barnes { 75508fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 75608fa8fd0SVille Syrjälä struct drm_vblank_crtc *vblank = &dev_priv->drm.vblank[drm_crtc_index(crtc)]; 75732db0b65SVille Syrjälä const struct drm_display_mode *mode = &vblank->hwmode; 75808fa8fd0SVille Syrjälä enum pipe pipe = to_intel_crtc(crtc)->pipe; 759f0f59a00SVille Syrjälä i915_reg_t high_frame, low_frame; 7600b2a8e09SVille Syrjälä u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal; 761694e409dSVille Syrjälä unsigned long irqflags; 762391f75e2SVille Syrjälä 76332db0b65SVille Syrjälä /* 76432db0b65SVille Syrjälä * On i965gm TV output the frame counter only works up to 76532db0b65SVille Syrjälä * the point when we enable the TV encoder. After that the 76632db0b65SVille Syrjälä * frame counter ceases to work and reads zero. We need a 76732db0b65SVille Syrjälä * vblank wait before enabling the TV encoder and so we 76832db0b65SVille Syrjälä * have to enable vblank interrupts while the frame counter 76932db0b65SVille Syrjälä * is still in a working state. However the core vblank code 77032db0b65SVille Syrjälä * does not like us returning non-zero frame counter values 77132db0b65SVille Syrjälä * when we've told it that we don't have a working frame 77232db0b65SVille Syrjälä * counter. Thus we must stop non-zero values leaking out. 77332db0b65SVille Syrjälä */ 77432db0b65SVille Syrjälä if (!vblank->max_vblank_count) 77532db0b65SVille Syrjälä return 0; 77632db0b65SVille Syrjälä 7770b2a8e09SVille Syrjälä htotal = mode->crtc_htotal; 7780b2a8e09SVille Syrjälä hsync_start = mode->crtc_hsync_start; 7790b2a8e09SVille Syrjälä vbl_start = mode->crtc_vblank_start; 7800b2a8e09SVille Syrjälä if (mode->flags & DRM_MODE_FLAG_INTERLACE) 7810b2a8e09SVille Syrjälä vbl_start = DIV_ROUND_UP(vbl_start, 2); 782391f75e2SVille Syrjälä 7830b2a8e09SVille Syrjälä /* Convert to pixel count */ 7840b2a8e09SVille Syrjälä vbl_start *= htotal; 7850b2a8e09SVille Syrjälä 7860b2a8e09SVille Syrjälä /* Start of vblank event occurs at start of hsync */ 7870b2a8e09SVille Syrjälä vbl_start -= htotal - hsync_start; 7880b2a8e09SVille Syrjälä 7899db4a9c7SJesse Barnes high_frame = PIPEFRAME(pipe); 7909db4a9c7SJesse Barnes low_frame = PIPEFRAMEPIXEL(pipe); 7915eddb70bSChris Wilson 792694e409dSVille Syrjälä spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); 793694e409dSVille Syrjälä 7940a3e67a4SJesse Barnes /* 7950a3e67a4SJesse Barnes * High & low register fields aren't synchronized, so make sure 7960a3e67a4SJesse Barnes * we get a low value that's stable across two reads of the high 7970a3e67a4SJesse Barnes * register. 7980a3e67a4SJesse Barnes */ 7990a3e67a4SJesse Barnes do { 800694e409dSVille Syrjälä high1 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK; 801694e409dSVille Syrjälä low = I915_READ_FW(low_frame); 802694e409dSVille Syrjälä high2 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK; 8030a3e67a4SJesse Barnes } while (high1 != high2); 8040a3e67a4SJesse Barnes 805694e409dSVille Syrjälä spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); 806694e409dSVille Syrjälä 8075eddb70bSChris Wilson high1 >>= PIPE_FRAME_HIGH_SHIFT; 808391f75e2SVille Syrjälä pixel = low & PIPE_PIXEL_MASK; 8095eddb70bSChris Wilson low >>= PIPE_FRAME_LOW_SHIFT; 810391f75e2SVille Syrjälä 811391f75e2SVille Syrjälä /* 812391f75e2SVille Syrjälä * The frame counter increments at beginning of active. 813391f75e2SVille Syrjälä * Cook up a vblank counter by also checking the pixel 814391f75e2SVille Syrjälä * counter against vblank start. 815391f75e2SVille Syrjälä */ 816edc08d0aSVille Syrjälä return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff; 8170a3e67a4SJesse Barnes } 8180a3e67a4SJesse Barnes 81908fa8fd0SVille Syrjälä u32 g4x_get_vblank_counter(struct drm_crtc *crtc) 8209880b7a5SJesse Barnes { 82108fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 82208fa8fd0SVille Syrjälä enum pipe pipe = to_intel_crtc(crtc)->pipe; 8239880b7a5SJesse Barnes 824649636efSVille Syrjälä return I915_READ(PIPE_FRMCOUNT_G4X(pipe)); 8259880b7a5SJesse Barnes } 8269880b7a5SJesse Barnes 827aec0246fSUma Shankar /* 828aec0246fSUma Shankar * On certain encoders on certain platforms, pipe 829aec0246fSUma Shankar * scanline register will not work to get the scanline, 830aec0246fSUma Shankar * since the timings are driven from the PORT or issues 831aec0246fSUma Shankar * with scanline register updates. 832aec0246fSUma Shankar * This function will use Framestamp and current 833aec0246fSUma Shankar * timestamp registers to calculate the scanline. 834aec0246fSUma Shankar */ 835aec0246fSUma Shankar static u32 __intel_get_crtc_scanline_from_timestamp(struct intel_crtc *crtc) 836aec0246fSUma Shankar { 837aec0246fSUma Shankar struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 838aec0246fSUma Shankar struct drm_vblank_crtc *vblank = 839aec0246fSUma Shankar &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)]; 840aec0246fSUma Shankar const struct drm_display_mode *mode = &vblank->hwmode; 841aec0246fSUma Shankar u32 vblank_start = mode->crtc_vblank_start; 842aec0246fSUma Shankar u32 vtotal = mode->crtc_vtotal; 843aec0246fSUma Shankar u32 htotal = mode->crtc_htotal; 844aec0246fSUma Shankar u32 clock = mode->crtc_clock; 845aec0246fSUma Shankar u32 scanline, scan_prev_time, scan_curr_time, scan_post_time; 846aec0246fSUma Shankar 847aec0246fSUma Shankar /* 848aec0246fSUma Shankar * To avoid the race condition where we might cross into the 849aec0246fSUma Shankar * next vblank just between the PIPE_FRMTMSTMP and TIMESTAMP_CTR 850aec0246fSUma Shankar * reads. We make sure we read PIPE_FRMTMSTMP and TIMESTAMP_CTR 851aec0246fSUma Shankar * during the same frame. 852aec0246fSUma Shankar */ 853aec0246fSUma Shankar do { 854aec0246fSUma Shankar /* 855aec0246fSUma Shankar * This field provides read back of the display 856aec0246fSUma Shankar * pipe frame time stamp. The time stamp value 857aec0246fSUma Shankar * is sampled at every start of vertical blank. 858aec0246fSUma Shankar */ 859aec0246fSUma Shankar scan_prev_time = I915_READ_FW(PIPE_FRMTMSTMP(crtc->pipe)); 860aec0246fSUma Shankar 861aec0246fSUma Shankar /* 862aec0246fSUma Shankar * The TIMESTAMP_CTR register has the current 863aec0246fSUma Shankar * time stamp value. 864aec0246fSUma Shankar */ 865aec0246fSUma Shankar scan_curr_time = I915_READ_FW(IVB_TIMESTAMP_CTR); 866aec0246fSUma Shankar 867aec0246fSUma Shankar scan_post_time = I915_READ_FW(PIPE_FRMTMSTMP(crtc->pipe)); 868aec0246fSUma Shankar } while (scan_post_time != scan_prev_time); 869aec0246fSUma Shankar 870aec0246fSUma Shankar scanline = div_u64(mul_u32_u32(scan_curr_time - scan_prev_time, 871aec0246fSUma Shankar clock), 1000 * htotal); 872aec0246fSUma Shankar scanline = min(scanline, vtotal - 1); 873aec0246fSUma Shankar scanline = (scanline + vblank_start) % vtotal; 874aec0246fSUma Shankar 875aec0246fSUma Shankar return scanline; 876aec0246fSUma Shankar } 877aec0246fSUma Shankar 87875aa3f63SVille Syrjälä /* I915_READ_FW, only for fast reads of display block, no need for forcewake etc. */ 879a225f079SVille Syrjälä static int __intel_get_crtc_scanline(struct intel_crtc *crtc) 880a225f079SVille Syrjälä { 881a225f079SVille Syrjälä struct drm_device *dev = crtc->base.dev; 882fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 8835caa0feaSDaniel Vetter const struct drm_display_mode *mode; 8845caa0feaSDaniel Vetter struct drm_vblank_crtc *vblank; 885a225f079SVille Syrjälä enum pipe pipe = crtc->pipe; 88680715b2fSVille Syrjälä int position, vtotal; 887a225f079SVille Syrjälä 88872259536SVille Syrjälä if (!crtc->active) 88972259536SVille Syrjälä return -1; 89072259536SVille Syrjälä 8915caa0feaSDaniel Vetter vblank = &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)]; 8925caa0feaSDaniel Vetter mode = &vblank->hwmode; 8935caa0feaSDaniel Vetter 894aec0246fSUma Shankar if (mode->private_flags & I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP) 895aec0246fSUma Shankar return __intel_get_crtc_scanline_from_timestamp(crtc); 896aec0246fSUma Shankar 89780715b2fSVille Syrjälä vtotal = mode->crtc_vtotal; 898a225f079SVille Syrjälä if (mode->flags & DRM_MODE_FLAG_INTERLACE) 899a225f079SVille Syrjälä vtotal /= 2; 900a225f079SVille Syrjälä 901cf819effSLucas De Marchi if (IS_GEN(dev_priv, 2)) 90275aa3f63SVille Syrjälä position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2; 903a225f079SVille Syrjälä else 90475aa3f63SVille Syrjälä position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3; 905a225f079SVille Syrjälä 906a225f079SVille Syrjälä /* 90741b578fbSJesse Barnes * On HSW, the DSL reg (0x70000) appears to return 0 if we 90841b578fbSJesse Barnes * read it just before the start of vblank. So try it again 90941b578fbSJesse Barnes * so we don't accidentally end up spanning a vblank frame 91041b578fbSJesse Barnes * increment, causing the pipe_update_end() code to squak at us. 91141b578fbSJesse Barnes * 91241b578fbSJesse Barnes * The nature of this problem means we can't simply check the ISR 91341b578fbSJesse Barnes * bit and return the vblank start value; nor can we use the scanline 91441b578fbSJesse Barnes * debug register in the transcoder as it appears to have the same 91541b578fbSJesse Barnes * problem. We may need to extend this to include other platforms, 91641b578fbSJesse Barnes * but so far testing only shows the problem on HSW. 91741b578fbSJesse Barnes */ 91891d14251STvrtko Ursulin if (HAS_DDI(dev_priv) && !position) { 91941b578fbSJesse Barnes int i, temp; 92041b578fbSJesse Barnes 92141b578fbSJesse Barnes for (i = 0; i < 100; i++) { 92241b578fbSJesse Barnes udelay(1); 923707bdd3fSVille Syrjälä temp = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3; 92441b578fbSJesse Barnes if (temp != position) { 92541b578fbSJesse Barnes position = temp; 92641b578fbSJesse Barnes break; 92741b578fbSJesse Barnes } 92841b578fbSJesse Barnes } 92941b578fbSJesse Barnes } 93041b578fbSJesse Barnes 93141b578fbSJesse Barnes /* 93280715b2fSVille Syrjälä * See update_scanline_offset() for the details on the 93380715b2fSVille Syrjälä * scanline_offset adjustment. 934a225f079SVille Syrjälä */ 93580715b2fSVille Syrjälä return (position + crtc->scanline_offset) % vtotal; 936a225f079SVille Syrjälä } 937a225f079SVille Syrjälä 938e8edae54SVille Syrjälä bool i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int index, 9391bf6ad62SDaniel Vetter bool in_vblank_irq, int *vpos, int *hpos, 9403bb403bfSVille Syrjälä ktime_t *stime, ktime_t *etime, 9413bb403bfSVille Syrjälä const struct drm_display_mode *mode) 9420af7e4dfSMario Kleiner { 943fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 944e8edae54SVille Syrjälä struct intel_crtc *crtc = to_intel_crtc(drm_crtc_from_index(dev, index)); 945e8edae54SVille Syrjälä enum pipe pipe = crtc->pipe; 9463aa18df8SVille Syrjälä int position; 94778e8fc6bSVille Syrjälä int vbl_start, vbl_end, hsync_start, htotal, vtotal; 948ad3543edSMario Kleiner unsigned long irqflags; 9498a920e24SVille Syrjälä bool use_scanline_counter = INTEL_GEN(dev_priv) >= 5 || 9508a920e24SVille Syrjälä IS_G4X(dev_priv) || IS_GEN(dev_priv, 2) || 9518a920e24SVille Syrjälä mode->private_flags & I915_MODE_FLAG_USE_SCANLINE_COUNTER; 9520af7e4dfSMario Kleiner 953fc467a22SMaarten Lankhorst if (WARN_ON(!mode->crtc_clock)) { 9540af7e4dfSMario Kleiner DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled " 9559db4a9c7SJesse Barnes "pipe %c\n", pipe_name(pipe)); 9561bf6ad62SDaniel Vetter return false; 9570af7e4dfSMario Kleiner } 9580af7e4dfSMario Kleiner 959c2baf4b7SVille Syrjälä htotal = mode->crtc_htotal; 96078e8fc6bSVille Syrjälä hsync_start = mode->crtc_hsync_start; 961c2baf4b7SVille Syrjälä vtotal = mode->crtc_vtotal; 962c2baf4b7SVille Syrjälä vbl_start = mode->crtc_vblank_start; 963c2baf4b7SVille Syrjälä vbl_end = mode->crtc_vblank_end; 9640af7e4dfSMario Kleiner 965d31faf65SVille Syrjälä if (mode->flags & DRM_MODE_FLAG_INTERLACE) { 966d31faf65SVille Syrjälä vbl_start = DIV_ROUND_UP(vbl_start, 2); 967d31faf65SVille Syrjälä vbl_end /= 2; 968d31faf65SVille Syrjälä vtotal /= 2; 969d31faf65SVille Syrjälä } 970d31faf65SVille Syrjälä 971ad3543edSMario Kleiner /* 972ad3543edSMario Kleiner * Lock uncore.lock, as we will do multiple timing critical raw 973ad3543edSMario Kleiner * register reads, potentially with preemption disabled, so the 974ad3543edSMario Kleiner * following code must not block on uncore.lock. 975ad3543edSMario Kleiner */ 976ad3543edSMario Kleiner spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); 977ad3543edSMario Kleiner 978ad3543edSMario Kleiner /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */ 979ad3543edSMario Kleiner 980ad3543edSMario Kleiner /* Get optional system timestamp before query. */ 981ad3543edSMario Kleiner if (stime) 982ad3543edSMario Kleiner *stime = ktime_get(); 983ad3543edSMario Kleiner 9848a920e24SVille Syrjälä if (use_scanline_counter) { 9850af7e4dfSMario Kleiner /* No obvious pixelcount register. Only query vertical 9860af7e4dfSMario Kleiner * scanout position from Display scan line register. 9870af7e4dfSMario Kleiner */ 988e8edae54SVille Syrjälä position = __intel_get_crtc_scanline(crtc); 9890af7e4dfSMario Kleiner } else { 9900af7e4dfSMario Kleiner /* Have access to pixelcount since start of frame. 9910af7e4dfSMario Kleiner * We can split this into vertical and horizontal 9920af7e4dfSMario Kleiner * scanout position. 9930af7e4dfSMario Kleiner */ 99475aa3f63SVille Syrjälä position = (I915_READ_FW(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT; 9950af7e4dfSMario Kleiner 9963aa18df8SVille Syrjälä /* convert to pixel counts */ 9973aa18df8SVille Syrjälä vbl_start *= htotal; 9983aa18df8SVille Syrjälä vbl_end *= htotal; 9993aa18df8SVille Syrjälä vtotal *= htotal; 100078e8fc6bSVille Syrjälä 100178e8fc6bSVille Syrjälä /* 10027e78f1cbSVille Syrjälä * In interlaced modes, the pixel counter counts all pixels, 10037e78f1cbSVille Syrjälä * so one field will have htotal more pixels. In order to avoid 10047e78f1cbSVille Syrjälä * the reported position from jumping backwards when the pixel 10057e78f1cbSVille Syrjälä * counter is beyond the length of the shorter field, just 10067e78f1cbSVille Syrjälä * clamp the position the length of the shorter field. This 10077e78f1cbSVille Syrjälä * matches how the scanline counter based position works since 10087e78f1cbSVille Syrjälä * the scanline counter doesn't count the two half lines. 10097e78f1cbSVille Syrjälä */ 10107e78f1cbSVille Syrjälä if (position >= vtotal) 10117e78f1cbSVille Syrjälä position = vtotal - 1; 10127e78f1cbSVille Syrjälä 10137e78f1cbSVille Syrjälä /* 101478e8fc6bSVille Syrjälä * Start of vblank interrupt is triggered at start of hsync, 101578e8fc6bSVille Syrjälä * just prior to the first active line of vblank. However we 101678e8fc6bSVille Syrjälä * consider lines to start at the leading edge of horizontal 101778e8fc6bSVille Syrjälä * active. So, should we get here before we've crossed into 101878e8fc6bSVille Syrjälä * the horizontal active of the first line in vblank, we would 101978e8fc6bSVille Syrjälä * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that, 102078e8fc6bSVille Syrjälä * always add htotal-hsync_start to the current pixel position. 102178e8fc6bSVille Syrjälä */ 102278e8fc6bSVille Syrjälä position = (position + htotal - hsync_start) % vtotal; 10233aa18df8SVille Syrjälä } 10243aa18df8SVille Syrjälä 1025ad3543edSMario Kleiner /* Get optional system timestamp after query. */ 1026ad3543edSMario Kleiner if (etime) 1027ad3543edSMario Kleiner *etime = ktime_get(); 1028ad3543edSMario Kleiner 1029ad3543edSMario Kleiner /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */ 1030ad3543edSMario Kleiner 1031ad3543edSMario Kleiner spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); 1032ad3543edSMario Kleiner 10333aa18df8SVille Syrjälä /* 10343aa18df8SVille Syrjälä * While in vblank, position will be negative 10353aa18df8SVille Syrjälä * counting up towards 0 at vbl_end. And outside 10363aa18df8SVille Syrjälä * vblank, position will be positive counting 10373aa18df8SVille Syrjälä * up since vbl_end. 10383aa18df8SVille Syrjälä */ 10393aa18df8SVille Syrjälä if (position >= vbl_start) 10403aa18df8SVille Syrjälä position -= vbl_end; 10413aa18df8SVille Syrjälä else 10423aa18df8SVille Syrjälä position += vtotal - vbl_end; 10433aa18df8SVille Syrjälä 10448a920e24SVille Syrjälä if (use_scanline_counter) { 10453aa18df8SVille Syrjälä *vpos = position; 10463aa18df8SVille Syrjälä *hpos = 0; 10473aa18df8SVille Syrjälä } else { 10480af7e4dfSMario Kleiner *vpos = position / htotal; 10490af7e4dfSMario Kleiner *hpos = position - (*vpos * htotal); 10500af7e4dfSMario Kleiner } 10510af7e4dfSMario Kleiner 10521bf6ad62SDaniel Vetter return true; 10530af7e4dfSMario Kleiner } 10540af7e4dfSMario Kleiner 1055a225f079SVille Syrjälä int intel_get_crtc_scanline(struct intel_crtc *crtc) 1056a225f079SVille Syrjälä { 1057fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1058a225f079SVille Syrjälä unsigned long irqflags; 1059a225f079SVille Syrjälä int position; 1060a225f079SVille Syrjälä 1061a225f079SVille Syrjälä spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); 1062a225f079SVille Syrjälä position = __intel_get_crtc_scanline(crtc); 1063a225f079SVille Syrjälä spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); 1064a225f079SVille Syrjälä 1065a225f079SVille Syrjälä return position; 1066a225f079SVille Syrjälä } 1067a225f079SVille Syrjälä 106891d14251STvrtko Ursulin static void ironlake_rps_change_irq_handler(struct drm_i915_private *dev_priv) 1069f97108d1SJesse Barnes { 10704f5fd91fSTvrtko Ursulin struct intel_uncore *uncore = &dev_priv->uncore; 1071b5b72e89SMatthew Garrett u32 busy_up, busy_down, max_avg, min_avg; 10729270388eSDaniel Vetter u8 new_delay; 10739270388eSDaniel Vetter 1074d0ecd7e2SDaniel Vetter spin_lock(&mchdev_lock); 1075f97108d1SJesse Barnes 10764f5fd91fSTvrtko Ursulin intel_uncore_write16(uncore, 10774f5fd91fSTvrtko Ursulin MEMINTRSTS, 10784f5fd91fSTvrtko Ursulin intel_uncore_read(uncore, MEMINTRSTS)); 107973edd18fSDaniel Vetter 108020e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay; 10819270388eSDaniel Vetter 10824f5fd91fSTvrtko Ursulin intel_uncore_write16(uncore, MEMINTRSTS, MEMINT_EVAL_CHG); 10834f5fd91fSTvrtko Ursulin busy_up = intel_uncore_read(uncore, RCPREVBSYTUPAVG); 10844f5fd91fSTvrtko Ursulin busy_down = intel_uncore_read(uncore, RCPREVBSYTDNAVG); 10854f5fd91fSTvrtko Ursulin max_avg = intel_uncore_read(uncore, RCBMAXAVG); 10864f5fd91fSTvrtko Ursulin min_avg = intel_uncore_read(uncore, RCBMINAVG); 1087f97108d1SJesse Barnes 1088f97108d1SJesse Barnes /* Handle RCS change request from hw */ 1089b5b72e89SMatthew Garrett if (busy_up > max_avg) { 109020e4d407SDaniel Vetter if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay) 109120e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay - 1; 109220e4d407SDaniel Vetter if (new_delay < dev_priv->ips.max_delay) 109320e4d407SDaniel Vetter new_delay = dev_priv->ips.max_delay; 1094b5b72e89SMatthew Garrett } else if (busy_down < min_avg) { 109520e4d407SDaniel Vetter if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay) 109620e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay + 1; 109720e4d407SDaniel Vetter if (new_delay > dev_priv->ips.min_delay) 109820e4d407SDaniel Vetter new_delay = dev_priv->ips.min_delay; 1099f97108d1SJesse Barnes } 1100f97108d1SJesse Barnes 110191d14251STvrtko Ursulin if (ironlake_set_drps(dev_priv, new_delay)) 110220e4d407SDaniel Vetter dev_priv->ips.cur_delay = new_delay; 1103f97108d1SJesse Barnes 1104d0ecd7e2SDaniel Vetter spin_unlock(&mchdev_lock); 11059270388eSDaniel Vetter 1106f97108d1SJesse Barnes return; 1107f97108d1SJesse Barnes } 1108f97108d1SJesse Barnes 110943cf3bf0SChris Wilson static void vlv_c0_read(struct drm_i915_private *dev_priv, 111043cf3bf0SChris Wilson struct intel_rps_ei *ei) 111131685c25SDeepak S { 1112679cb6c1SMika Kuoppala ei->ktime = ktime_get_raw(); 111343cf3bf0SChris Wilson ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT); 111443cf3bf0SChris Wilson ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT); 111531685c25SDeepak S } 111631685c25SDeepak S 111743cf3bf0SChris Wilson void gen6_rps_reset_ei(struct drm_i915_private *dev_priv) 111843cf3bf0SChris Wilson { 1119562d9baeSSagar Arun Kamble memset(&dev_priv->gt_pm.rps.ei, 0, sizeof(dev_priv->gt_pm.rps.ei)); 112043cf3bf0SChris Wilson } 112143cf3bf0SChris Wilson 112243cf3bf0SChris Wilson static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir) 112343cf3bf0SChris Wilson { 1124562d9baeSSagar Arun Kamble struct intel_rps *rps = &dev_priv->gt_pm.rps; 1125562d9baeSSagar Arun Kamble const struct intel_rps_ei *prev = &rps->ei; 112643cf3bf0SChris Wilson struct intel_rps_ei now; 112743cf3bf0SChris Wilson u32 events = 0; 112843cf3bf0SChris Wilson 1129e0e8c7cbSChris Wilson if ((pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) == 0) 113043cf3bf0SChris Wilson return 0; 113143cf3bf0SChris Wilson 113243cf3bf0SChris Wilson vlv_c0_read(dev_priv, &now); 113331685c25SDeepak S 1134679cb6c1SMika Kuoppala if (prev->ktime) { 1135e0e8c7cbSChris Wilson u64 time, c0; 1136569884e3SChris Wilson u32 render, media; 1137e0e8c7cbSChris Wilson 1138679cb6c1SMika Kuoppala time = ktime_us_delta(now.ktime, prev->ktime); 11398f68d591SChris Wilson 1140e0e8c7cbSChris Wilson time *= dev_priv->czclk_freq; 1141e0e8c7cbSChris Wilson 1142e0e8c7cbSChris Wilson /* Workload can be split between render + media, 1143e0e8c7cbSChris Wilson * e.g. SwapBuffers being blitted in X after being rendered in 1144e0e8c7cbSChris Wilson * mesa. To account for this we need to combine both engines 1145e0e8c7cbSChris Wilson * into our activity counter. 1146e0e8c7cbSChris Wilson */ 1147569884e3SChris Wilson render = now.render_c0 - prev->render_c0; 1148569884e3SChris Wilson media = now.media_c0 - prev->media_c0; 1149569884e3SChris Wilson c0 = max(render, media); 11506b7f6aa7SMika Kuoppala c0 *= 1000 * 100 << 8; /* to usecs and scale to threshold% */ 1151e0e8c7cbSChris Wilson 115260548c55SChris Wilson if (c0 > time * rps->power.up_threshold) 1153e0e8c7cbSChris Wilson events = GEN6_PM_RP_UP_THRESHOLD; 115460548c55SChris Wilson else if (c0 < time * rps->power.down_threshold) 1155e0e8c7cbSChris Wilson events = GEN6_PM_RP_DOWN_THRESHOLD; 115631685c25SDeepak S } 115731685c25SDeepak S 1158562d9baeSSagar Arun Kamble rps->ei = now; 115943cf3bf0SChris Wilson return events; 116031685c25SDeepak S } 116131685c25SDeepak S 11624912d041SBen Widawsky static void gen6_pm_rps_work(struct work_struct *work) 11633b8d8d91SJesse Barnes { 11642d1013ddSJani Nikula struct drm_i915_private *dev_priv = 1165562d9baeSSagar Arun Kamble container_of(work, struct drm_i915_private, gt_pm.rps.work); 1166d762043fSAndi Shyti struct intel_gt *gt = &dev_priv->gt; 1167562d9baeSSagar Arun Kamble struct intel_rps *rps = &dev_priv->gt_pm.rps; 11687c0a16adSChris Wilson bool client_boost = false; 11698d3afd7dSChris Wilson int new_delay, adj, min, max; 11707c0a16adSChris Wilson u32 pm_iir = 0; 11713b8d8d91SJesse Barnes 1172d762043fSAndi Shyti spin_lock_irq(>->irq_lock); 1173562d9baeSSagar Arun Kamble if (rps->interrupts_enabled) { 1174562d9baeSSagar Arun Kamble pm_iir = fetch_and_zero(&rps->pm_iir); 1175562d9baeSSagar Arun Kamble client_boost = atomic_read(&rps->num_waiters); 1176d4d70aa5SImre Deak } 1177d762043fSAndi Shyti spin_unlock_irq(>->irq_lock); 11784912d041SBen Widawsky 117960611c13SPaulo Zanoni /* Make sure we didn't queue anything we're not going to process. */ 1180a6706b45SDeepak S WARN_ON(pm_iir & ~dev_priv->pm_rps_events); 11818d3afd7dSChris Wilson if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost) 11827c0a16adSChris Wilson goto out; 11833b8d8d91SJesse Barnes 1184ebb5eb7dSChris Wilson mutex_lock(&rps->lock); 11857b9e0ae6SChris Wilson 118643cf3bf0SChris Wilson pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir); 118743cf3bf0SChris Wilson 1188562d9baeSSagar Arun Kamble adj = rps->last_adj; 1189562d9baeSSagar Arun Kamble new_delay = rps->cur_freq; 1190562d9baeSSagar Arun Kamble min = rps->min_freq_softlimit; 1191562d9baeSSagar Arun Kamble max = rps->max_freq_softlimit; 11927b92c1bdSChris Wilson if (client_boost) 1193562d9baeSSagar Arun Kamble max = rps->max_freq; 1194562d9baeSSagar Arun Kamble if (client_boost && new_delay < rps->boost_freq) { 1195562d9baeSSagar Arun Kamble new_delay = rps->boost_freq; 11968d3afd7dSChris Wilson adj = 0; 11978d3afd7dSChris Wilson } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) { 1198dd75fdc8SChris Wilson if (adj > 0) 1199dd75fdc8SChris Wilson adj *= 2; 1200edcf284bSChris Wilson else /* CHV needs even encode values */ 1201edcf284bSChris Wilson adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1; 12027e79a683SSagar Arun Kamble 1203562d9baeSSagar Arun Kamble if (new_delay >= rps->max_freq_softlimit) 12047e79a683SSagar Arun Kamble adj = 0; 12057b92c1bdSChris Wilson } else if (client_boost) { 1206f5a4c67dSChris Wilson adj = 0; 1207dd75fdc8SChris Wilson } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) { 1208562d9baeSSagar Arun Kamble if (rps->cur_freq > rps->efficient_freq) 1209562d9baeSSagar Arun Kamble new_delay = rps->efficient_freq; 1210562d9baeSSagar Arun Kamble else if (rps->cur_freq > rps->min_freq_softlimit) 1211562d9baeSSagar Arun Kamble new_delay = rps->min_freq_softlimit; 1212dd75fdc8SChris Wilson adj = 0; 1213dd75fdc8SChris Wilson } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) { 1214dd75fdc8SChris Wilson if (adj < 0) 1215dd75fdc8SChris Wilson adj *= 2; 1216edcf284bSChris Wilson else /* CHV needs even encode values */ 1217edcf284bSChris Wilson adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1; 12187e79a683SSagar Arun Kamble 1219562d9baeSSagar Arun Kamble if (new_delay <= rps->min_freq_softlimit) 12207e79a683SSagar Arun Kamble adj = 0; 1221dd75fdc8SChris Wilson } else { /* unknown event */ 1222edcf284bSChris Wilson adj = 0; 1223dd75fdc8SChris Wilson } 12243b8d8d91SJesse Barnes 1225562d9baeSSagar Arun Kamble rps->last_adj = adj; 1226edcf284bSChris Wilson 12272a8862d2SChris Wilson /* 12282a8862d2SChris Wilson * Limit deboosting and boosting to keep ourselves at the extremes 12292a8862d2SChris Wilson * when in the respective power modes (i.e. slowly decrease frequencies 12302a8862d2SChris Wilson * while in the HIGH_POWER zone and slowly increase frequencies while 12312a8862d2SChris Wilson * in the LOW_POWER zone). On idle, we will hit the timeout and drop 12322a8862d2SChris Wilson * to the next level quickly, and conversely if busy we expect to 12332a8862d2SChris Wilson * hit a waitboost and rapidly switch into max power. 12342a8862d2SChris Wilson */ 12352a8862d2SChris Wilson if ((adj < 0 && rps->power.mode == HIGH_POWER) || 12362a8862d2SChris Wilson (adj > 0 && rps->power.mode == LOW_POWER)) 12372a8862d2SChris Wilson rps->last_adj = 0; 12382a8862d2SChris Wilson 123979249636SBen Widawsky /* sysfs frequency interfaces may have snuck in while servicing the 124079249636SBen Widawsky * interrupt 124179249636SBen Widawsky */ 1242edcf284bSChris Wilson new_delay += adj; 12438d3afd7dSChris Wilson new_delay = clamp_t(int, new_delay, min, max); 124427544369SDeepak S 12459fcee2f7SChris Wilson if (intel_set_rps(dev_priv, new_delay)) { 12469fcee2f7SChris Wilson DRM_DEBUG_DRIVER("Failed to set new GPU frequency\n"); 1247562d9baeSSagar Arun Kamble rps->last_adj = 0; 12489fcee2f7SChris Wilson } 12493b8d8d91SJesse Barnes 1250ebb5eb7dSChris Wilson mutex_unlock(&rps->lock); 12517c0a16adSChris Wilson 12527c0a16adSChris Wilson out: 12537c0a16adSChris Wilson /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */ 1254d762043fSAndi Shyti spin_lock_irq(>->irq_lock); 1255562d9baeSSagar Arun Kamble if (rps->interrupts_enabled) 1256d762043fSAndi Shyti gen6_gt_pm_unmask_irq(gt, dev_priv->pm_rps_events); 1257d762043fSAndi Shyti spin_unlock_irq(>->irq_lock); 12583b8d8d91SJesse Barnes } 12593b8d8d91SJesse Barnes 1260e3689190SBen Widawsky 1261e3689190SBen Widawsky /** 1262e3689190SBen Widawsky * ivybridge_parity_work - Workqueue called when a parity error interrupt 1263e3689190SBen Widawsky * occurred. 1264e3689190SBen Widawsky * @work: workqueue struct 1265e3689190SBen Widawsky * 1266e3689190SBen Widawsky * Doesn't actually do anything except notify userspace. As a consequence of 1267e3689190SBen Widawsky * this event, userspace should try to remap the bad rows since statistically 1268e3689190SBen Widawsky * it is likely the same row is more likely to go bad again. 1269e3689190SBen Widawsky */ 1270e3689190SBen Widawsky static void ivybridge_parity_work(struct work_struct *work) 1271e3689190SBen Widawsky { 12722d1013ddSJani Nikula struct drm_i915_private *dev_priv = 1273cefcff8fSJoonas Lahtinen container_of(work, typeof(*dev_priv), l3_parity.error_work); 1274cf1c97dcSAndi Shyti struct intel_gt *gt = &dev_priv->gt; 1275e3689190SBen Widawsky u32 error_status, row, bank, subbank; 127635a85ac6SBen Widawsky char *parity_event[6]; 1277a9c287c9SJani Nikula u32 misccpctl; 1278a9c287c9SJani Nikula u8 slice = 0; 1279e3689190SBen Widawsky 1280e3689190SBen Widawsky /* We must turn off DOP level clock gating to access the L3 registers. 1281e3689190SBen Widawsky * In order to prevent a get/put style interface, acquire struct mutex 1282e3689190SBen Widawsky * any time we access those registers. 1283e3689190SBen Widawsky */ 128491c8a326SChris Wilson mutex_lock(&dev_priv->drm.struct_mutex); 1285e3689190SBen Widawsky 128635a85ac6SBen Widawsky /* If we've screwed up tracking, just let the interrupt fire again */ 128735a85ac6SBen Widawsky if (WARN_ON(!dev_priv->l3_parity.which_slice)) 128835a85ac6SBen Widawsky goto out; 128935a85ac6SBen Widawsky 1290e3689190SBen Widawsky misccpctl = I915_READ(GEN7_MISCCPCTL); 1291e3689190SBen Widawsky I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); 1292e3689190SBen Widawsky POSTING_READ(GEN7_MISCCPCTL); 1293e3689190SBen Widawsky 129435a85ac6SBen Widawsky while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) { 1295f0f59a00SVille Syrjälä i915_reg_t reg; 129635a85ac6SBen Widawsky 129735a85ac6SBen Widawsky slice--; 12982d1fe073SJoonas Lahtinen if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv))) 129935a85ac6SBen Widawsky break; 130035a85ac6SBen Widawsky 130135a85ac6SBen Widawsky dev_priv->l3_parity.which_slice &= ~(1<<slice); 130235a85ac6SBen Widawsky 13036fa1c5f1SVille Syrjälä reg = GEN7_L3CDERRST1(slice); 130435a85ac6SBen Widawsky 130535a85ac6SBen Widawsky error_status = I915_READ(reg); 1306e3689190SBen Widawsky row = GEN7_PARITY_ERROR_ROW(error_status); 1307e3689190SBen Widawsky bank = GEN7_PARITY_ERROR_BANK(error_status); 1308e3689190SBen Widawsky subbank = GEN7_PARITY_ERROR_SUBBANK(error_status); 1309e3689190SBen Widawsky 131035a85ac6SBen Widawsky I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE); 131135a85ac6SBen Widawsky POSTING_READ(reg); 1312e3689190SBen Widawsky 1313cce723edSBen Widawsky parity_event[0] = I915_L3_PARITY_UEVENT "=1"; 1314e3689190SBen Widawsky parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row); 1315e3689190SBen Widawsky parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank); 1316e3689190SBen Widawsky parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank); 131735a85ac6SBen Widawsky parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice); 131835a85ac6SBen Widawsky parity_event[5] = NULL; 1319e3689190SBen Widawsky 132091c8a326SChris Wilson kobject_uevent_env(&dev_priv->drm.primary->kdev->kobj, 1321e3689190SBen Widawsky KOBJ_CHANGE, parity_event); 1322e3689190SBen Widawsky 132335a85ac6SBen Widawsky DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n", 132435a85ac6SBen Widawsky slice, row, bank, subbank); 1325e3689190SBen Widawsky 132635a85ac6SBen Widawsky kfree(parity_event[4]); 1327e3689190SBen Widawsky kfree(parity_event[3]); 1328e3689190SBen Widawsky kfree(parity_event[2]); 1329e3689190SBen Widawsky kfree(parity_event[1]); 1330e3689190SBen Widawsky } 1331e3689190SBen Widawsky 133235a85ac6SBen Widawsky I915_WRITE(GEN7_MISCCPCTL, misccpctl); 133335a85ac6SBen Widawsky 133435a85ac6SBen Widawsky out: 133535a85ac6SBen Widawsky WARN_ON(dev_priv->l3_parity.which_slice); 1336cf1c97dcSAndi Shyti spin_lock_irq(>->irq_lock); 1337cf1c97dcSAndi Shyti gen5_gt_enable_irq(gt, GT_PARITY_ERROR(dev_priv)); 1338cf1c97dcSAndi Shyti spin_unlock_irq(>->irq_lock); 133935a85ac6SBen Widawsky 134091c8a326SChris Wilson mutex_unlock(&dev_priv->drm.struct_mutex); 134135a85ac6SBen Widawsky } 134235a85ac6SBen Widawsky 1343af92058fSVille Syrjälä static bool gen11_port_hotplug_long_detect(enum hpd_pin pin, u32 val) 1344121e758eSDhinakaran Pandiyan { 1345af92058fSVille Syrjälä switch (pin) { 1346af92058fSVille Syrjälä case HPD_PORT_C: 1347121e758eSDhinakaran Pandiyan return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC1); 1348af92058fSVille Syrjälä case HPD_PORT_D: 1349121e758eSDhinakaran Pandiyan return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC2); 1350af92058fSVille Syrjälä case HPD_PORT_E: 1351121e758eSDhinakaran Pandiyan return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC3); 1352af92058fSVille Syrjälä case HPD_PORT_F: 1353121e758eSDhinakaran Pandiyan return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC4); 1354121e758eSDhinakaran Pandiyan default: 1355121e758eSDhinakaran Pandiyan return false; 1356121e758eSDhinakaran Pandiyan } 1357121e758eSDhinakaran Pandiyan } 1358121e758eSDhinakaran Pandiyan 135948ef15d3SJosé Roberto de Souza static bool gen12_port_hotplug_long_detect(enum hpd_pin pin, u32 val) 136048ef15d3SJosé Roberto de Souza { 136148ef15d3SJosé Roberto de Souza switch (pin) { 136248ef15d3SJosé Roberto de Souza case HPD_PORT_D: 136348ef15d3SJosé Roberto de Souza return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC1); 136448ef15d3SJosé Roberto de Souza case HPD_PORT_E: 136548ef15d3SJosé Roberto de Souza return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC2); 136648ef15d3SJosé Roberto de Souza case HPD_PORT_F: 136748ef15d3SJosé Roberto de Souza return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC3); 136848ef15d3SJosé Roberto de Souza case HPD_PORT_G: 136948ef15d3SJosé Roberto de Souza return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC4); 137048ef15d3SJosé Roberto de Souza case HPD_PORT_H: 137148ef15d3SJosé Roberto de Souza return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC5); 137248ef15d3SJosé Roberto de Souza case HPD_PORT_I: 137348ef15d3SJosé Roberto de Souza return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC6); 137448ef15d3SJosé Roberto de Souza default: 137548ef15d3SJosé Roberto de Souza return false; 137648ef15d3SJosé Roberto de Souza } 137748ef15d3SJosé Roberto de Souza } 137848ef15d3SJosé Roberto de Souza 1379af92058fSVille Syrjälä static bool bxt_port_hotplug_long_detect(enum hpd_pin pin, u32 val) 138063c88d22SImre Deak { 1381af92058fSVille Syrjälä switch (pin) { 1382af92058fSVille Syrjälä case HPD_PORT_A: 1383195baa06SVille Syrjälä return val & PORTA_HOTPLUG_LONG_DETECT; 1384af92058fSVille Syrjälä case HPD_PORT_B: 138563c88d22SImre Deak return val & PORTB_HOTPLUG_LONG_DETECT; 1386af92058fSVille Syrjälä case HPD_PORT_C: 138763c88d22SImre Deak return val & PORTC_HOTPLUG_LONG_DETECT; 138863c88d22SImre Deak default: 138963c88d22SImre Deak return false; 139063c88d22SImre Deak } 139163c88d22SImre Deak } 139263c88d22SImre Deak 1393af92058fSVille Syrjälä static bool icp_ddi_port_hotplug_long_detect(enum hpd_pin pin, u32 val) 139431604222SAnusha Srivatsa { 1395af92058fSVille Syrjälä switch (pin) { 1396af92058fSVille Syrjälä case HPD_PORT_A: 1397ed3126faSLucas De Marchi return val & SHOTPLUG_CTL_DDI_HPD_LONG_DETECT(PORT_A); 1398af92058fSVille Syrjälä case HPD_PORT_B: 1399ed3126faSLucas De Marchi return val & SHOTPLUG_CTL_DDI_HPD_LONG_DETECT(PORT_B); 14008ef7e340SMatt Roper case HPD_PORT_C: 1401ed3126faSLucas De Marchi return val & SHOTPLUG_CTL_DDI_HPD_LONG_DETECT(PORT_C); 140231604222SAnusha Srivatsa default: 140331604222SAnusha Srivatsa return false; 140431604222SAnusha Srivatsa } 140531604222SAnusha Srivatsa } 140631604222SAnusha Srivatsa 1407af92058fSVille Syrjälä static bool icp_tc_port_hotplug_long_detect(enum hpd_pin pin, u32 val) 140831604222SAnusha Srivatsa { 1409af92058fSVille Syrjälä switch (pin) { 1410af92058fSVille Syrjälä case HPD_PORT_C: 141131604222SAnusha Srivatsa return val & ICP_TC_HPD_LONG_DETECT(PORT_TC1); 1412af92058fSVille Syrjälä case HPD_PORT_D: 141331604222SAnusha Srivatsa return val & ICP_TC_HPD_LONG_DETECT(PORT_TC2); 1414af92058fSVille Syrjälä case HPD_PORT_E: 141531604222SAnusha Srivatsa return val & ICP_TC_HPD_LONG_DETECT(PORT_TC3); 1416af92058fSVille Syrjälä case HPD_PORT_F: 141731604222SAnusha Srivatsa return val & ICP_TC_HPD_LONG_DETECT(PORT_TC4); 141831604222SAnusha Srivatsa default: 141931604222SAnusha Srivatsa return false; 142031604222SAnusha Srivatsa } 142131604222SAnusha Srivatsa } 142231604222SAnusha Srivatsa 142352dfdba0SLucas De Marchi static bool tgp_tc_port_hotplug_long_detect(enum hpd_pin pin, u32 val) 142452dfdba0SLucas De Marchi { 142552dfdba0SLucas De Marchi switch (pin) { 142652dfdba0SLucas De Marchi case HPD_PORT_D: 142752dfdba0SLucas De Marchi return val & ICP_TC_HPD_LONG_DETECT(PORT_TC1); 142852dfdba0SLucas De Marchi case HPD_PORT_E: 142952dfdba0SLucas De Marchi return val & ICP_TC_HPD_LONG_DETECT(PORT_TC2); 143052dfdba0SLucas De Marchi case HPD_PORT_F: 143152dfdba0SLucas De Marchi return val & ICP_TC_HPD_LONG_DETECT(PORT_TC3); 143252dfdba0SLucas De Marchi case HPD_PORT_G: 143352dfdba0SLucas De Marchi return val & ICP_TC_HPD_LONG_DETECT(PORT_TC4); 143452dfdba0SLucas De Marchi case HPD_PORT_H: 143552dfdba0SLucas De Marchi return val & ICP_TC_HPD_LONG_DETECT(PORT_TC5); 143652dfdba0SLucas De Marchi case HPD_PORT_I: 143752dfdba0SLucas De Marchi return val & ICP_TC_HPD_LONG_DETECT(PORT_TC6); 143852dfdba0SLucas De Marchi default: 143952dfdba0SLucas De Marchi return false; 144052dfdba0SLucas De Marchi } 144152dfdba0SLucas De Marchi } 144252dfdba0SLucas De Marchi 1443af92058fSVille Syrjälä static bool spt_port_hotplug2_long_detect(enum hpd_pin pin, u32 val) 14446dbf30ceSVille Syrjälä { 1445af92058fSVille Syrjälä switch (pin) { 1446af92058fSVille Syrjälä case HPD_PORT_E: 14476dbf30ceSVille Syrjälä return val & PORTE_HOTPLUG_LONG_DETECT; 14486dbf30ceSVille Syrjälä default: 14496dbf30ceSVille Syrjälä return false; 14506dbf30ceSVille Syrjälä } 14516dbf30ceSVille Syrjälä } 14526dbf30ceSVille Syrjälä 1453af92058fSVille Syrjälä static bool spt_port_hotplug_long_detect(enum hpd_pin pin, u32 val) 145474c0b395SVille Syrjälä { 1455af92058fSVille Syrjälä switch (pin) { 1456af92058fSVille Syrjälä case HPD_PORT_A: 145774c0b395SVille Syrjälä return val & PORTA_HOTPLUG_LONG_DETECT; 1458af92058fSVille Syrjälä case HPD_PORT_B: 145974c0b395SVille Syrjälä return val & PORTB_HOTPLUG_LONG_DETECT; 1460af92058fSVille Syrjälä case HPD_PORT_C: 146174c0b395SVille Syrjälä return val & PORTC_HOTPLUG_LONG_DETECT; 1462af92058fSVille Syrjälä case HPD_PORT_D: 146374c0b395SVille Syrjälä return val & PORTD_HOTPLUG_LONG_DETECT; 146474c0b395SVille Syrjälä default: 146574c0b395SVille Syrjälä return false; 146674c0b395SVille Syrjälä } 146774c0b395SVille Syrjälä } 146874c0b395SVille Syrjälä 1469af92058fSVille Syrjälä static bool ilk_port_hotplug_long_detect(enum hpd_pin pin, u32 val) 1470e4ce95aaSVille Syrjälä { 1471af92058fSVille Syrjälä switch (pin) { 1472af92058fSVille Syrjälä case HPD_PORT_A: 1473e4ce95aaSVille Syrjälä return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT; 1474e4ce95aaSVille Syrjälä default: 1475e4ce95aaSVille Syrjälä return false; 1476e4ce95aaSVille Syrjälä } 1477e4ce95aaSVille Syrjälä } 1478e4ce95aaSVille Syrjälä 1479af92058fSVille Syrjälä static bool pch_port_hotplug_long_detect(enum hpd_pin pin, u32 val) 148013cf5504SDave Airlie { 1481af92058fSVille Syrjälä switch (pin) { 1482af92058fSVille Syrjälä case HPD_PORT_B: 1483676574dfSJani Nikula return val & PORTB_HOTPLUG_LONG_DETECT; 1484af92058fSVille Syrjälä case HPD_PORT_C: 1485676574dfSJani Nikula return val & PORTC_HOTPLUG_LONG_DETECT; 1486af92058fSVille Syrjälä case HPD_PORT_D: 1487676574dfSJani Nikula return val & PORTD_HOTPLUG_LONG_DETECT; 1488676574dfSJani Nikula default: 1489676574dfSJani Nikula return false; 149013cf5504SDave Airlie } 149113cf5504SDave Airlie } 149213cf5504SDave Airlie 1493af92058fSVille Syrjälä static bool i9xx_port_hotplug_long_detect(enum hpd_pin pin, u32 val) 149413cf5504SDave Airlie { 1495af92058fSVille Syrjälä switch (pin) { 1496af92058fSVille Syrjälä case HPD_PORT_B: 1497676574dfSJani Nikula return val & PORTB_HOTPLUG_INT_LONG_PULSE; 1498af92058fSVille Syrjälä case HPD_PORT_C: 1499676574dfSJani Nikula return val & PORTC_HOTPLUG_INT_LONG_PULSE; 1500af92058fSVille Syrjälä case HPD_PORT_D: 1501676574dfSJani Nikula return val & PORTD_HOTPLUG_INT_LONG_PULSE; 1502676574dfSJani Nikula default: 1503676574dfSJani Nikula return false; 150413cf5504SDave Airlie } 150513cf5504SDave Airlie } 150613cf5504SDave Airlie 150742db67d6SVille Syrjälä /* 150842db67d6SVille Syrjälä * Get a bit mask of pins that have triggered, and which ones may be long. 150942db67d6SVille Syrjälä * This can be called multiple times with the same masks to accumulate 151042db67d6SVille Syrjälä * hotplug detection results from several registers. 151142db67d6SVille Syrjälä * 151242db67d6SVille Syrjälä * Note that the caller is expected to zero out the masks initially. 151342db67d6SVille Syrjälä */ 1514cf53902fSRodrigo Vivi static void intel_get_hpd_pins(struct drm_i915_private *dev_priv, 1515cf53902fSRodrigo Vivi u32 *pin_mask, u32 *long_mask, 15168c841e57SJani Nikula u32 hotplug_trigger, u32 dig_hotplug_reg, 1517fd63e2a9SImre Deak const u32 hpd[HPD_NUM_PINS], 1518af92058fSVille Syrjälä bool long_pulse_detect(enum hpd_pin pin, u32 val)) 1519676574dfSJani Nikula { 1520e9be2850SVille Syrjälä enum hpd_pin pin; 1521676574dfSJani Nikula 152252dfdba0SLucas De Marchi BUILD_BUG_ON(BITS_PER_TYPE(*pin_mask) < HPD_NUM_PINS); 152352dfdba0SLucas De Marchi 1524e9be2850SVille Syrjälä for_each_hpd_pin(pin) { 1525e9be2850SVille Syrjälä if ((hpd[pin] & hotplug_trigger) == 0) 15268c841e57SJani Nikula continue; 15278c841e57SJani Nikula 1528e9be2850SVille Syrjälä *pin_mask |= BIT(pin); 1529676574dfSJani Nikula 1530af92058fSVille Syrjälä if (long_pulse_detect(pin, dig_hotplug_reg)) 1531e9be2850SVille Syrjälä *long_mask |= BIT(pin); 1532676574dfSJani Nikula } 1533676574dfSJani Nikula 1534f88f0478SVille Syrjälä DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x, long 0x%08x\n", 1535f88f0478SVille Syrjälä hotplug_trigger, dig_hotplug_reg, *pin_mask, *long_mask); 1536676574dfSJani Nikula 1537676574dfSJani Nikula } 1538676574dfSJani Nikula 153991d14251STvrtko Ursulin static void gmbus_irq_handler(struct drm_i915_private *dev_priv) 1540515ac2bbSDaniel Vetter { 154128c70f16SDaniel Vetter wake_up_all(&dev_priv->gmbus_wait_queue); 1542515ac2bbSDaniel Vetter } 1543515ac2bbSDaniel Vetter 154491d14251STvrtko Ursulin static void dp_aux_irq_handler(struct drm_i915_private *dev_priv) 1545ce99c256SDaniel Vetter { 15469ee32feaSDaniel Vetter wake_up_all(&dev_priv->gmbus_wait_queue); 1547ce99c256SDaniel Vetter } 1548ce99c256SDaniel Vetter 15498bf1e9f1SShuang He #if defined(CONFIG_DEBUG_FS) 155091d14251STvrtko Ursulin static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, 155191d14251STvrtko Ursulin enum pipe pipe, 1552a9c287c9SJani Nikula u32 crc0, u32 crc1, 1553a9c287c9SJani Nikula u32 crc2, u32 crc3, 1554a9c287c9SJani Nikula u32 crc4) 15558bf1e9f1SShuang He { 15568bf1e9f1SShuang He struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe]; 15578c6b709dSTomeu Vizoso struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); 15585cee6c45SVille Syrjälä u32 crcs[5] = { crc0, crc1, crc2, crc3, crc4 }; 15595cee6c45SVille Syrjälä 15605cee6c45SVille Syrjälä trace_intel_pipe_crc(crtc, crcs); 1561b2c88f5bSDamien Lespiau 1562d538bbdfSDamien Lespiau spin_lock(&pipe_crc->lock); 15638c6b709dSTomeu Vizoso /* 15648c6b709dSTomeu Vizoso * For some not yet identified reason, the first CRC is 15658c6b709dSTomeu Vizoso * bonkers. So let's just wait for the next vblank and read 15668c6b709dSTomeu Vizoso * out the buggy result. 15678c6b709dSTomeu Vizoso * 1568163e8aecSRodrigo Vivi * On GEN8+ sometimes the second CRC is bonkers as well, so 15698c6b709dSTomeu Vizoso * don't trust that one either. 15708c6b709dSTomeu Vizoso */ 1571033b7a23SMaarten Lankhorst if (pipe_crc->skipped <= 0 || 1572163e8aecSRodrigo Vivi (INTEL_GEN(dev_priv) >= 8 && pipe_crc->skipped == 1)) { 15738c6b709dSTomeu Vizoso pipe_crc->skipped++; 15748c6b709dSTomeu Vizoso spin_unlock(&pipe_crc->lock); 15758c6b709dSTomeu Vizoso return; 15768c6b709dSTomeu Vizoso } 15778c6b709dSTomeu Vizoso spin_unlock(&pipe_crc->lock); 15786cc42152SMaarten Lankhorst 1579246ee524STomeu Vizoso drm_crtc_add_crc_entry(&crtc->base, true, 1580ca814b25SDaniel Vetter drm_crtc_accurate_vblank_count(&crtc->base), 1581246ee524STomeu Vizoso crcs); 15828c6b709dSTomeu Vizoso } 1583277de95eSDaniel Vetter #else 1584277de95eSDaniel Vetter static inline void 158591d14251STvrtko Ursulin display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, 158691d14251STvrtko Ursulin enum pipe pipe, 1587a9c287c9SJani Nikula u32 crc0, u32 crc1, 1588a9c287c9SJani Nikula u32 crc2, u32 crc3, 1589a9c287c9SJani Nikula u32 crc4) {} 1590277de95eSDaniel Vetter #endif 1591eba94eb9SDaniel Vetter 1592277de95eSDaniel Vetter 159391d14251STvrtko Ursulin static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, 159491d14251STvrtko Ursulin enum pipe pipe) 15955a69b89fSDaniel Vetter { 159691d14251STvrtko Ursulin display_pipe_crc_irq_handler(dev_priv, pipe, 15975a69b89fSDaniel Vetter I915_READ(PIPE_CRC_RES_1_IVB(pipe)), 15985a69b89fSDaniel Vetter 0, 0, 0, 0); 15995a69b89fSDaniel Vetter } 16005a69b89fSDaniel Vetter 160191d14251STvrtko Ursulin static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, 160291d14251STvrtko Ursulin enum pipe pipe) 1603eba94eb9SDaniel Vetter { 160491d14251STvrtko Ursulin display_pipe_crc_irq_handler(dev_priv, pipe, 1605eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_1_IVB(pipe)), 1606eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_2_IVB(pipe)), 1607eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_3_IVB(pipe)), 1608eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_4_IVB(pipe)), 16098bc5e955SDaniel Vetter I915_READ(PIPE_CRC_RES_5_IVB(pipe))); 1610eba94eb9SDaniel Vetter } 16115b3a856bSDaniel Vetter 161291d14251STvrtko Ursulin static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, 161391d14251STvrtko Ursulin enum pipe pipe) 16145b3a856bSDaniel Vetter { 1615a9c287c9SJani Nikula u32 res1, res2; 16160b5c5ed0SDaniel Vetter 161791d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 3) 16180b5c5ed0SDaniel Vetter res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe)); 16190b5c5ed0SDaniel Vetter else 16200b5c5ed0SDaniel Vetter res1 = 0; 16210b5c5ed0SDaniel Vetter 162291d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) 16230b5c5ed0SDaniel Vetter res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe)); 16240b5c5ed0SDaniel Vetter else 16250b5c5ed0SDaniel Vetter res2 = 0; 16265b3a856bSDaniel Vetter 162791d14251STvrtko Ursulin display_pipe_crc_irq_handler(dev_priv, pipe, 16280b5c5ed0SDaniel Vetter I915_READ(PIPE_CRC_RES_RED(pipe)), 16290b5c5ed0SDaniel Vetter I915_READ(PIPE_CRC_RES_GREEN(pipe)), 16300b5c5ed0SDaniel Vetter I915_READ(PIPE_CRC_RES_BLUE(pipe)), 16310b5c5ed0SDaniel Vetter res1, res2); 16325b3a856bSDaniel Vetter } 16338bf1e9f1SShuang He 16341403c0d4SPaulo Zanoni /* The RPS events need forcewake, so we add them to a work queue and mask their 16351403c0d4SPaulo Zanoni * IMR bits until the work is done. Other interrupts can be processed without 16361403c0d4SPaulo Zanoni * the work queue. */ 1637cf1c97dcSAndi Shyti void gen11_rps_irq_handler(struct intel_gt *gt, u32 pm_iir) 1638a087bafeSMika Kuoppala { 163958820574STvrtko Ursulin struct drm_i915_private *i915 = gt->i915; 1640a087bafeSMika Kuoppala struct intel_rps *rps = &i915->gt_pm.rps; 1641a087bafeSMika Kuoppala const u32 events = i915->pm_rps_events & pm_iir; 1642a087bafeSMika Kuoppala 1643d762043fSAndi Shyti lockdep_assert_held(>->irq_lock); 1644a087bafeSMika Kuoppala 1645a087bafeSMika Kuoppala if (unlikely(!events)) 1646a087bafeSMika Kuoppala return; 1647a087bafeSMika Kuoppala 1648d762043fSAndi Shyti gen6_gt_pm_mask_irq(gt, events); 1649a087bafeSMika Kuoppala 1650a087bafeSMika Kuoppala if (!rps->interrupts_enabled) 1651a087bafeSMika Kuoppala return; 1652a087bafeSMika Kuoppala 1653a087bafeSMika Kuoppala rps->pm_iir |= events; 1654a087bafeSMika Kuoppala schedule_work(&rps->work); 1655a087bafeSMika Kuoppala } 1656a087bafeSMika Kuoppala 1657cf1c97dcSAndi Shyti void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir) 1658baf02a1fSBen Widawsky { 1659562d9baeSSagar Arun Kamble struct intel_rps *rps = &dev_priv->gt_pm.rps; 1660d762043fSAndi Shyti struct intel_gt *gt = &dev_priv->gt; 1661562d9baeSSagar Arun Kamble 1662a6706b45SDeepak S if (pm_iir & dev_priv->pm_rps_events) { 1663d762043fSAndi Shyti spin_lock(>->irq_lock); 1664d762043fSAndi Shyti gen6_gt_pm_mask_irq(gt, pm_iir & dev_priv->pm_rps_events); 1665562d9baeSSagar Arun Kamble if (rps->interrupts_enabled) { 1666562d9baeSSagar Arun Kamble rps->pm_iir |= pm_iir & dev_priv->pm_rps_events; 1667562d9baeSSagar Arun Kamble schedule_work(&rps->work); 166841a05a3aSDaniel Vetter } 1669d762043fSAndi Shyti spin_unlock(>->irq_lock); 1670d4d70aa5SImre Deak } 1671baf02a1fSBen Widawsky 1672bca2bf2aSPandiyan, Dhinakaran if (INTEL_GEN(dev_priv) >= 8) 1673c9a9a268SImre Deak return; 1674c9a9a268SImre Deak 167512638c57SBen Widawsky if (pm_iir & PM_VEBOX_USER_INTERRUPT) 16768a68d464SChris Wilson intel_engine_breadcrumbs_irq(dev_priv->engine[VECS0]); 167712638c57SBen Widawsky 1678aaecdf61SDaniel Vetter if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) 1679aaecdf61SDaniel Vetter DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir); 168012638c57SBen Widawsky } 1681baf02a1fSBen Widawsky 168244d9241eSVille Syrjälä static void i9xx_pipestat_irq_reset(struct drm_i915_private *dev_priv) 168344d9241eSVille Syrjälä { 168444d9241eSVille Syrjälä enum pipe pipe; 168544d9241eSVille Syrjälä 168644d9241eSVille Syrjälä for_each_pipe(dev_priv, pipe) { 168744d9241eSVille Syrjälä I915_WRITE(PIPESTAT(pipe), 168844d9241eSVille Syrjälä PIPESTAT_INT_STATUS_MASK | 168944d9241eSVille Syrjälä PIPE_FIFO_UNDERRUN_STATUS); 169044d9241eSVille Syrjälä 169144d9241eSVille Syrjälä dev_priv->pipestat_irq_mask[pipe] = 0; 169244d9241eSVille Syrjälä } 169344d9241eSVille Syrjälä } 169444d9241eSVille Syrjälä 1695eb64343cSVille Syrjälä static void i9xx_pipestat_irq_ack(struct drm_i915_private *dev_priv, 169691d14251STvrtko Ursulin u32 iir, u32 pipe_stats[I915_MAX_PIPES]) 16977e231dbeSJesse Barnes { 1698d048a268SVille Syrjälä enum pipe pipe; 16997e231dbeSJesse Barnes 170058ead0d7SImre Deak spin_lock(&dev_priv->irq_lock); 17011ca993d2SVille Syrjälä 17021ca993d2SVille Syrjälä if (!dev_priv->display_irqs_enabled) { 17031ca993d2SVille Syrjälä spin_unlock(&dev_priv->irq_lock); 17041ca993d2SVille Syrjälä return; 17051ca993d2SVille Syrjälä } 17061ca993d2SVille Syrjälä 1707055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 1708f0f59a00SVille Syrjälä i915_reg_t reg; 17096b12ca56SVille Syrjälä u32 status_mask, enable_mask, iir_bit = 0; 171091d181ddSImre Deak 1711bbb5eebfSDaniel Vetter /* 1712bbb5eebfSDaniel Vetter * PIPESTAT bits get signalled even when the interrupt is 1713bbb5eebfSDaniel Vetter * disabled with the mask bits, and some of the status bits do 1714bbb5eebfSDaniel Vetter * not generate interrupts at all (like the underrun bit). Hence 1715bbb5eebfSDaniel Vetter * we need to be careful that we only handle what we want to 1716bbb5eebfSDaniel Vetter * handle. 1717bbb5eebfSDaniel Vetter */ 17180f239f4cSDaniel Vetter 17190f239f4cSDaniel Vetter /* fifo underruns are filterered in the underrun handler. */ 17206b12ca56SVille Syrjälä status_mask = PIPE_FIFO_UNDERRUN_STATUS; 1721bbb5eebfSDaniel Vetter 1722bbb5eebfSDaniel Vetter switch (pipe) { 1723d048a268SVille Syrjälä default: 1724bbb5eebfSDaniel Vetter case PIPE_A: 1725bbb5eebfSDaniel Vetter iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT; 1726bbb5eebfSDaniel Vetter break; 1727bbb5eebfSDaniel Vetter case PIPE_B: 1728bbb5eebfSDaniel Vetter iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT; 1729bbb5eebfSDaniel Vetter break; 17303278f67fSVille Syrjälä case PIPE_C: 17313278f67fSVille Syrjälä iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT; 17323278f67fSVille Syrjälä break; 1733bbb5eebfSDaniel Vetter } 1734bbb5eebfSDaniel Vetter if (iir & iir_bit) 17356b12ca56SVille Syrjälä status_mask |= dev_priv->pipestat_irq_mask[pipe]; 1736bbb5eebfSDaniel Vetter 17376b12ca56SVille Syrjälä if (!status_mask) 173891d181ddSImre Deak continue; 173991d181ddSImre Deak 174091d181ddSImre Deak reg = PIPESTAT(pipe); 17416b12ca56SVille Syrjälä pipe_stats[pipe] = I915_READ(reg) & status_mask; 17426b12ca56SVille Syrjälä enable_mask = i915_pipestat_enable_mask(dev_priv, pipe); 17437e231dbeSJesse Barnes 17447e231dbeSJesse Barnes /* 17457e231dbeSJesse Barnes * Clear the PIPE*STAT regs before the IIR 1746132c27c9SVille Syrjälä * 1747132c27c9SVille Syrjälä * Toggle the enable bits to make sure we get an 1748132c27c9SVille Syrjälä * edge in the ISR pipe event bit if we don't clear 1749132c27c9SVille Syrjälä * all the enabled status bits. Otherwise the edge 1750132c27c9SVille Syrjälä * triggered IIR on i965/g4x wouldn't notice that 1751132c27c9SVille Syrjälä * an interrupt is still pending. 17527e231dbeSJesse Barnes */ 1753132c27c9SVille Syrjälä if (pipe_stats[pipe]) { 1754132c27c9SVille Syrjälä I915_WRITE(reg, pipe_stats[pipe]); 1755132c27c9SVille Syrjälä I915_WRITE(reg, enable_mask); 1756132c27c9SVille Syrjälä } 17577e231dbeSJesse Barnes } 175858ead0d7SImre Deak spin_unlock(&dev_priv->irq_lock); 17592ecb8ca4SVille Syrjälä } 17602ecb8ca4SVille Syrjälä 1761eb64343cSVille Syrjälä static void i8xx_pipestat_irq_handler(struct drm_i915_private *dev_priv, 1762eb64343cSVille Syrjälä u16 iir, u32 pipe_stats[I915_MAX_PIPES]) 1763eb64343cSVille Syrjälä { 1764eb64343cSVille Syrjälä enum pipe pipe; 1765eb64343cSVille Syrjälä 1766eb64343cSVille Syrjälä for_each_pipe(dev_priv, pipe) { 1767eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS) 1768eb64343cSVille Syrjälä drm_handle_vblank(&dev_priv->drm, pipe); 1769eb64343cSVille Syrjälä 1770eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 1771eb64343cSVille Syrjälä i9xx_pipe_crc_irq_handler(dev_priv, pipe); 1772eb64343cSVille Syrjälä 1773eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 1774eb64343cSVille Syrjälä intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 1775eb64343cSVille Syrjälä } 1776eb64343cSVille Syrjälä } 1777eb64343cSVille Syrjälä 1778eb64343cSVille Syrjälä static void i915_pipestat_irq_handler(struct drm_i915_private *dev_priv, 1779eb64343cSVille Syrjälä u32 iir, u32 pipe_stats[I915_MAX_PIPES]) 1780eb64343cSVille Syrjälä { 1781eb64343cSVille Syrjälä bool blc_event = false; 1782eb64343cSVille Syrjälä enum pipe pipe; 1783eb64343cSVille Syrjälä 1784eb64343cSVille Syrjälä for_each_pipe(dev_priv, pipe) { 1785eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS) 1786eb64343cSVille Syrjälä drm_handle_vblank(&dev_priv->drm, pipe); 1787eb64343cSVille Syrjälä 1788eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 1789eb64343cSVille Syrjälä blc_event = true; 1790eb64343cSVille Syrjälä 1791eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 1792eb64343cSVille Syrjälä i9xx_pipe_crc_irq_handler(dev_priv, pipe); 1793eb64343cSVille Syrjälä 1794eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 1795eb64343cSVille Syrjälä intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 1796eb64343cSVille Syrjälä } 1797eb64343cSVille Syrjälä 1798eb64343cSVille Syrjälä if (blc_event || (iir & I915_ASLE_INTERRUPT)) 1799eb64343cSVille Syrjälä intel_opregion_asle_intr(dev_priv); 1800eb64343cSVille Syrjälä } 1801eb64343cSVille Syrjälä 1802eb64343cSVille Syrjälä static void i965_pipestat_irq_handler(struct drm_i915_private *dev_priv, 1803eb64343cSVille Syrjälä u32 iir, u32 pipe_stats[I915_MAX_PIPES]) 1804eb64343cSVille Syrjälä { 1805eb64343cSVille Syrjälä bool blc_event = false; 1806eb64343cSVille Syrjälä enum pipe pipe; 1807eb64343cSVille Syrjälä 1808eb64343cSVille Syrjälä for_each_pipe(dev_priv, pipe) { 1809eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS) 1810eb64343cSVille Syrjälä drm_handle_vblank(&dev_priv->drm, pipe); 1811eb64343cSVille Syrjälä 1812eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 1813eb64343cSVille Syrjälä blc_event = true; 1814eb64343cSVille Syrjälä 1815eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 1816eb64343cSVille Syrjälä i9xx_pipe_crc_irq_handler(dev_priv, pipe); 1817eb64343cSVille Syrjälä 1818eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 1819eb64343cSVille Syrjälä intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 1820eb64343cSVille Syrjälä } 1821eb64343cSVille Syrjälä 1822eb64343cSVille Syrjälä if (blc_event || (iir & I915_ASLE_INTERRUPT)) 1823eb64343cSVille Syrjälä intel_opregion_asle_intr(dev_priv); 1824eb64343cSVille Syrjälä 1825eb64343cSVille Syrjälä if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 1826eb64343cSVille Syrjälä gmbus_irq_handler(dev_priv); 1827eb64343cSVille Syrjälä } 1828eb64343cSVille Syrjälä 182991d14251STvrtko Ursulin static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv, 18302ecb8ca4SVille Syrjälä u32 pipe_stats[I915_MAX_PIPES]) 18312ecb8ca4SVille Syrjälä { 18322ecb8ca4SVille Syrjälä enum pipe pipe; 18337e231dbeSJesse Barnes 1834055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 1835fd3a4024SDaniel Vetter if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS) 1836fd3a4024SDaniel Vetter drm_handle_vblank(&dev_priv->drm, pipe); 18374356d586SDaniel Vetter 18384356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 183991d14251STvrtko Ursulin i9xx_pipe_crc_irq_handler(dev_priv, pipe); 18402d9d2b0bSVille Syrjälä 18411f7247c0SDaniel Vetter if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 18421f7247c0SDaniel Vetter intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 184331acc7f5SJesse Barnes } 184431acc7f5SJesse Barnes 1845c1874ed7SImre Deak if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 184691d14251STvrtko Ursulin gmbus_irq_handler(dev_priv); 1847c1874ed7SImre Deak } 1848c1874ed7SImre Deak 18491ae3c34cSVille Syrjälä static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv) 185016c6c56bSVille Syrjälä { 18510ba7c51aSVille Syrjälä u32 hotplug_status = 0, hotplug_status_mask; 18520ba7c51aSVille Syrjälä int i; 185316c6c56bSVille Syrjälä 18540ba7c51aSVille Syrjälä if (IS_G4X(dev_priv) || 18550ba7c51aSVille Syrjälä IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) 18560ba7c51aSVille Syrjälä hotplug_status_mask = HOTPLUG_INT_STATUS_G4X | 18570ba7c51aSVille Syrjälä DP_AUX_CHANNEL_MASK_INT_STATUS_G4X; 18580ba7c51aSVille Syrjälä else 18590ba7c51aSVille Syrjälä hotplug_status_mask = HOTPLUG_INT_STATUS_I915; 18600ba7c51aSVille Syrjälä 18610ba7c51aSVille Syrjälä /* 18620ba7c51aSVille Syrjälä * We absolutely have to clear all the pending interrupt 18630ba7c51aSVille Syrjälä * bits in PORT_HOTPLUG_STAT. Otherwise the ISR port 18640ba7c51aSVille Syrjälä * interrupt bit won't have an edge, and the i965/g4x 18650ba7c51aSVille Syrjälä * edge triggered IIR will not notice that an interrupt 18660ba7c51aSVille Syrjälä * is still pending. We can't use PORT_HOTPLUG_EN to 18670ba7c51aSVille Syrjälä * guarantee the edge as the act of toggling the enable 18680ba7c51aSVille Syrjälä * bits can itself generate a new hotplug interrupt :( 18690ba7c51aSVille Syrjälä */ 18700ba7c51aSVille Syrjälä for (i = 0; i < 10; i++) { 18710ba7c51aSVille Syrjälä u32 tmp = I915_READ(PORT_HOTPLUG_STAT) & hotplug_status_mask; 18720ba7c51aSVille Syrjälä 18730ba7c51aSVille Syrjälä if (tmp == 0) 18740ba7c51aSVille Syrjälä return hotplug_status; 18750ba7c51aSVille Syrjälä 18760ba7c51aSVille Syrjälä hotplug_status |= tmp; 18773ff60f89SOscar Mateo I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); 18780ba7c51aSVille Syrjälä } 18790ba7c51aSVille Syrjälä 18800ba7c51aSVille Syrjälä WARN_ONCE(1, 18810ba7c51aSVille Syrjälä "PORT_HOTPLUG_STAT did not clear (0x%08x)\n", 18820ba7c51aSVille Syrjälä I915_READ(PORT_HOTPLUG_STAT)); 18831ae3c34cSVille Syrjälä 18841ae3c34cSVille Syrjälä return hotplug_status; 18851ae3c34cSVille Syrjälä } 18861ae3c34cSVille Syrjälä 188791d14251STvrtko Ursulin static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv, 18881ae3c34cSVille Syrjälä u32 hotplug_status) 18891ae3c34cSVille Syrjälä { 18901ae3c34cSVille Syrjälä u32 pin_mask = 0, long_mask = 0; 18913ff60f89SOscar Mateo 189291d14251STvrtko Ursulin if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || 189391d14251STvrtko Ursulin IS_CHERRYVIEW(dev_priv)) { 189416c6c56bSVille Syrjälä u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X; 189516c6c56bSVille Syrjälä 189658f2cf24SVille Syrjälä if (hotplug_trigger) { 1897cf53902fSRodrigo Vivi intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, 1898cf53902fSRodrigo Vivi hotplug_trigger, hotplug_trigger, 1899cf53902fSRodrigo Vivi hpd_status_g4x, 1900fd63e2a9SImre Deak i9xx_port_hotplug_long_detect); 190158f2cf24SVille Syrjälä 190291d14251STvrtko Ursulin intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 190358f2cf24SVille Syrjälä } 1904369712e8SJani Nikula 1905369712e8SJani Nikula if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X) 190691d14251STvrtko Ursulin dp_aux_irq_handler(dev_priv); 190716c6c56bSVille Syrjälä } else { 190816c6c56bSVille Syrjälä u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915; 190916c6c56bSVille Syrjälä 191058f2cf24SVille Syrjälä if (hotplug_trigger) { 1911cf53902fSRodrigo Vivi intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, 1912cf53902fSRodrigo Vivi hotplug_trigger, hotplug_trigger, 1913cf53902fSRodrigo Vivi hpd_status_i915, 1914fd63e2a9SImre Deak i9xx_port_hotplug_long_detect); 191591d14251STvrtko Ursulin intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 191616c6c56bSVille Syrjälä } 19173ff60f89SOscar Mateo } 191858f2cf24SVille Syrjälä } 191916c6c56bSVille Syrjälä 1920c1874ed7SImre Deak static irqreturn_t valleyview_irq_handler(int irq, void *arg) 1921c1874ed7SImre Deak { 1922b318b824SVille Syrjälä struct drm_i915_private *dev_priv = arg; 1923c1874ed7SImre Deak irqreturn_t ret = IRQ_NONE; 1924c1874ed7SImre Deak 19252dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 19262dd2a883SImre Deak return IRQ_NONE; 19272dd2a883SImre Deak 19281f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 19299102650fSDaniele Ceraolo Spurio disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 19301f814dacSImre Deak 19311e1cace9SVille Syrjälä do { 19326e814800SVille Syrjälä u32 iir, gt_iir, pm_iir; 19332ecb8ca4SVille Syrjälä u32 pipe_stats[I915_MAX_PIPES] = {}; 19341ae3c34cSVille Syrjälä u32 hotplug_status = 0; 1935a5e485a9SVille Syrjälä u32 ier = 0; 19363ff60f89SOscar Mateo 1937c1874ed7SImre Deak gt_iir = I915_READ(GTIIR); 1938c1874ed7SImre Deak pm_iir = I915_READ(GEN6_PMIIR); 19393ff60f89SOscar Mateo iir = I915_READ(VLV_IIR); 1940c1874ed7SImre Deak 1941c1874ed7SImre Deak if (gt_iir == 0 && pm_iir == 0 && iir == 0) 19421e1cace9SVille Syrjälä break; 1943c1874ed7SImre Deak 1944c1874ed7SImre Deak ret = IRQ_HANDLED; 1945c1874ed7SImre Deak 1946a5e485a9SVille Syrjälä /* 1947a5e485a9SVille Syrjälä * Theory on interrupt generation, based on empirical evidence: 1948a5e485a9SVille Syrjälä * 1949a5e485a9SVille Syrjälä * x = ((VLV_IIR & VLV_IER) || 1950a5e485a9SVille Syrjälä * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) && 1951a5e485a9SVille Syrjälä * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE))); 1952a5e485a9SVille Syrjälä * 1953a5e485a9SVille Syrjälä * A CPU interrupt will only be raised when 'x' has a 0->1 edge. 1954a5e485a9SVille Syrjälä * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to 1955a5e485a9SVille Syrjälä * guarantee the CPU interrupt will be raised again even if we 1956a5e485a9SVille Syrjälä * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR 1957a5e485a9SVille Syrjälä * bits this time around. 1958a5e485a9SVille Syrjälä */ 19594a0a0202SVille Syrjälä I915_WRITE(VLV_MASTER_IER, 0); 1960a5e485a9SVille Syrjälä ier = I915_READ(VLV_IER); 1961a5e485a9SVille Syrjälä I915_WRITE(VLV_IER, 0); 19624a0a0202SVille Syrjälä 19634a0a0202SVille Syrjälä if (gt_iir) 19644a0a0202SVille Syrjälä I915_WRITE(GTIIR, gt_iir); 19654a0a0202SVille Syrjälä if (pm_iir) 19664a0a0202SVille Syrjälä I915_WRITE(GEN6_PMIIR, pm_iir); 19674a0a0202SVille Syrjälä 19687ce4d1f2SVille Syrjälä if (iir & I915_DISPLAY_PORT_INTERRUPT) 19691ae3c34cSVille Syrjälä hotplug_status = i9xx_hpd_irq_ack(dev_priv); 19707ce4d1f2SVille Syrjälä 19713ff60f89SOscar Mateo /* Call regardless, as some status bits might not be 19723ff60f89SOscar Mateo * signalled in iir */ 1973eb64343cSVille Syrjälä i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats); 19747ce4d1f2SVille Syrjälä 1975eef57324SJerome Anand if (iir & (I915_LPE_PIPE_A_INTERRUPT | 1976eef57324SJerome Anand I915_LPE_PIPE_B_INTERRUPT)) 1977eef57324SJerome Anand intel_lpe_audio_irq_handler(dev_priv); 1978eef57324SJerome Anand 19797ce4d1f2SVille Syrjälä /* 19807ce4d1f2SVille Syrjälä * VLV_IIR is single buffered, and reflects the level 19817ce4d1f2SVille Syrjälä * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last. 19827ce4d1f2SVille Syrjälä */ 19837ce4d1f2SVille Syrjälä if (iir) 19847ce4d1f2SVille Syrjälä I915_WRITE(VLV_IIR, iir); 19854a0a0202SVille Syrjälä 1986a5e485a9SVille Syrjälä I915_WRITE(VLV_IER, ier); 19874a0a0202SVille Syrjälä I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE); 19881ae3c34cSVille Syrjälä 198952894874SVille Syrjälä if (gt_iir) 1990cf1c97dcSAndi Shyti gen6_gt_irq_handler(&dev_priv->gt, gt_iir); 199152894874SVille Syrjälä if (pm_iir) 199252894874SVille Syrjälä gen6_rps_irq_handler(dev_priv, pm_iir); 199352894874SVille Syrjälä 19941ae3c34cSVille Syrjälä if (hotplug_status) 199591d14251STvrtko Ursulin i9xx_hpd_irq_handler(dev_priv, hotplug_status); 19962ecb8ca4SVille Syrjälä 199791d14251STvrtko Ursulin valleyview_pipestat_irq_handler(dev_priv, pipe_stats); 19981e1cace9SVille Syrjälä } while (0); 19997e231dbeSJesse Barnes 20009102650fSDaniele Ceraolo Spurio enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 20011f814dacSImre Deak 20027e231dbeSJesse Barnes return ret; 20037e231dbeSJesse Barnes } 20047e231dbeSJesse Barnes 200543f328d7SVille Syrjälä static irqreturn_t cherryview_irq_handler(int irq, void *arg) 200643f328d7SVille Syrjälä { 2007b318b824SVille Syrjälä struct drm_i915_private *dev_priv = arg; 200843f328d7SVille Syrjälä irqreturn_t ret = IRQ_NONE; 200943f328d7SVille Syrjälä 20102dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 20112dd2a883SImre Deak return IRQ_NONE; 20122dd2a883SImre Deak 20131f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 20149102650fSDaniele Ceraolo Spurio disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 20151f814dacSImre Deak 2016579de73bSChris Wilson do { 20176e814800SVille Syrjälä u32 master_ctl, iir; 20182ecb8ca4SVille Syrjälä u32 pipe_stats[I915_MAX_PIPES] = {}; 20191ae3c34cSVille Syrjälä u32 hotplug_status = 0; 2020f0fd96f5SChris Wilson u32 gt_iir[4]; 2021a5e485a9SVille Syrjälä u32 ier = 0; 2022a5e485a9SVille Syrjälä 20238e5fd599SVille Syrjälä master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL; 20243278f67fSVille Syrjälä iir = I915_READ(VLV_IIR); 20253278f67fSVille Syrjälä 20263278f67fSVille Syrjälä if (master_ctl == 0 && iir == 0) 20278e5fd599SVille Syrjälä break; 202843f328d7SVille Syrjälä 202927b6c122SOscar Mateo ret = IRQ_HANDLED; 203027b6c122SOscar Mateo 2031a5e485a9SVille Syrjälä /* 2032a5e485a9SVille Syrjälä * Theory on interrupt generation, based on empirical evidence: 2033a5e485a9SVille Syrjälä * 2034a5e485a9SVille Syrjälä * x = ((VLV_IIR & VLV_IER) || 2035a5e485a9SVille Syrjälä * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) && 2036a5e485a9SVille Syrjälä * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL))); 2037a5e485a9SVille Syrjälä * 2038a5e485a9SVille Syrjälä * A CPU interrupt will only be raised when 'x' has a 0->1 edge. 2039a5e485a9SVille Syrjälä * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to 2040a5e485a9SVille Syrjälä * guarantee the CPU interrupt will be raised again even if we 2041a5e485a9SVille Syrjälä * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL 2042a5e485a9SVille Syrjälä * bits this time around. 2043a5e485a9SVille Syrjälä */ 204443f328d7SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, 0); 2045a5e485a9SVille Syrjälä ier = I915_READ(VLV_IER); 2046a5e485a9SVille Syrjälä I915_WRITE(VLV_IER, 0); 204743f328d7SVille Syrjälä 2048cf1c97dcSAndi Shyti gen8_gt_irq_ack(&dev_priv->gt, master_ctl, gt_iir); 204927b6c122SOscar Mateo 205027b6c122SOscar Mateo if (iir & I915_DISPLAY_PORT_INTERRUPT) 20511ae3c34cSVille Syrjälä hotplug_status = i9xx_hpd_irq_ack(dev_priv); 205243f328d7SVille Syrjälä 205327b6c122SOscar Mateo /* Call regardless, as some status bits might not be 205427b6c122SOscar Mateo * signalled in iir */ 2055eb64343cSVille Syrjälä i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats); 205643f328d7SVille Syrjälä 2057eef57324SJerome Anand if (iir & (I915_LPE_PIPE_A_INTERRUPT | 2058eef57324SJerome Anand I915_LPE_PIPE_B_INTERRUPT | 2059eef57324SJerome Anand I915_LPE_PIPE_C_INTERRUPT)) 2060eef57324SJerome Anand intel_lpe_audio_irq_handler(dev_priv); 2061eef57324SJerome Anand 20627ce4d1f2SVille Syrjälä /* 20637ce4d1f2SVille Syrjälä * VLV_IIR is single buffered, and reflects the level 20647ce4d1f2SVille Syrjälä * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last. 20657ce4d1f2SVille Syrjälä */ 20667ce4d1f2SVille Syrjälä if (iir) 20677ce4d1f2SVille Syrjälä I915_WRITE(VLV_IIR, iir); 20687ce4d1f2SVille Syrjälä 2069a5e485a9SVille Syrjälä I915_WRITE(VLV_IER, ier); 2070e5328c43SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); 20711ae3c34cSVille Syrjälä 2072cf1c97dcSAndi Shyti gen8_gt_irq_handler(&dev_priv->gt, master_ctl, gt_iir); 2073e30e251aSVille Syrjälä 20741ae3c34cSVille Syrjälä if (hotplug_status) 207591d14251STvrtko Ursulin i9xx_hpd_irq_handler(dev_priv, hotplug_status); 20762ecb8ca4SVille Syrjälä 207791d14251STvrtko Ursulin valleyview_pipestat_irq_handler(dev_priv, pipe_stats); 2078579de73bSChris Wilson } while (0); 20793278f67fSVille Syrjälä 20809102650fSDaniele Ceraolo Spurio enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 20811f814dacSImre Deak 208243f328d7SVille Syrjälä return ret; 208343f328d7SVille Syrjälä } 208443f328d7SVille Syrjälä 208591d14251STvrtko Ursulin static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv, 208691d14251STvrtko Ursulin u32 hotplug_trigger, 208740e56410SVille Syrjälä const u32 hpd[HPD_NUM_PINS]) 2088776ad806SJesse Barnes { 208942db67d6SVille Syrjälä u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0; 2090776ad806SJesse Barnes 20916a39d7c9SJani Nikula /* 20926a39d7c9SJani Nikula * Somehow the PCH doesn't seem to really ack the interrupt to the CPU 20936a39d7c9SJani Nikula * unless we touch the hotplug register, even if hotplug_trigger is 20946a39d7c9SJani Nikula * zero. Not acking leads to "The master control interrupt lied (SDE)!" 20956a39d7c9SJani Nikula * errors. 20966a39d7c9SJani Nikula */ 209713cf5504SDave Airlie dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG); 20986a39d7c9SJani Nikula if (!hotplug_trigger) { 20996a39d7c9SJani Nikula u32 mask = PORTA_HOTPLUG_STATUS_MASK | 21006a39d7c9SJani Nikula PORTD_HOTPLUG_STATUS_MASK | 21016a39d7c9SJani Nikula PORTC_HOTPLUG_STATUS_MASK | 21026a39d7c9SJani Nikula PORTB_HOTPLUG_STATUS_MASK; 21036a39d7c9SJani Nikula dig_hotplug_reg &= ~mask; 21046a39d7c9SJani Nikula } 21056a39d7c9SJani Nikula 210613cf5504SDave Airlie I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg); 21076a39d7c9SJani Nikula if (!hotplug_trigger) 21086a39d7c9SJani Nikula return; 210913cf5504SDave Airlie 2110cf53902fSRodrigo Vivi intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger, 211140e56410SVille Syrjälä dig_hotplug_reg, hpd, 2112fd63e2a9SImre Deak pch_port_hotplug_long_detect); 211340e56410SVille Syrjälä 211491d14251STvrtko Ursulin intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 2115aaf5ec2eSSonika Jindal } 211691d131d2SDaniel Vetter 211791d14251STvrtko Ursulin static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir) 211840e56410SVille Syrjälä { 2119d048a268SVille Syrjälä enum pipe pipe; 212040e56410SVille Syrjälä u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK; 212140e56410SVille Syrjälä 212291d14251STvrtko Ursulin ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ibx); 212340e56410SVille Syrjälä 2124cfc33bf7SVille Syrjälä if (pch_iir & SDE_AUDIO_POWER_MASK) { 2125cfc33bf7SVille Syrjälä int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >> 2126776ad806SJesse Barnes SDE_AUDIO_POWER_SHIFT); 2127cfc33bf7SVille Syrjälä DRM_DEBUG_DRIVER("PCH audio power change on port %d\n", 2128cfc33bf7SVille Syrjälä port_name(port)); 2129cfc33bf7SVille Syrjälä } 2130776ad806SJesse Barnes 2131ce99c256SDaniel Vetter if (pch_iir & SDE_AUX_MASK) 213291d14251STvrtko Ursulin dp_aux_irq_handler(dev_priv); 2133ce99c256SDaniel Vetter 2134776ad806SJesse Barnes if (pch_iir & SDE_GMBUS) 213591d14251STvrtko Ursulin gmbus_irq_handler(dev_priv); 2136776ad806SJesse Barnes 2137776ad806SJesse Barnes if (pch_iir & SDE_AUDIO_HDCP_MASK) 2138776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n"); 2139776ad806SJesse Barnes 2140776ad806SJesse Barnes if (pch_iir & SDE_AUDIO_TRANS_MASK) 2141776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n"); 2142776ad806SJesse Barnes 2143776ad806SJesse Barnes if (pch_iir & SDE_POISON) 2144776ad806SJesse Barnes DRM_ERROR("PCH poison interrupt\n"); 2145776ad806SJesse Barnes 21469db4a9c7SJesse Barnes if (pch_iir & SDE_FDI_MASK) 2147055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 21489db4a9c7SJesse Barnes DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", 21499db4a9c7SJesse Barnes pipe_name(pipe), 21509db4a9c7SJesse Barnes I915_READ(FDI_RX_IIR(pipe))); 2151776ad806SJesse Barnes 2152776ad806SJesse Barnes if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE)) 2153776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n"); 2154776ad806SJesse Barnes 2155776ad806SJesse Barnes if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR)) 2156776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n"); 2157776ad806SJesse Barnes 2158776ad806SJesse Barnes if (pch_iir & SDE_TRANSA_FIFO_UNDER) 2159a2196033SMatthias Kaehlcke intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A); 21608664281bSPaulo Zanoni 21618664281bSPaulo Zanoni if (pch_iir & SDE_TRANSB_FIFO_UNDER) 2162a2196033SMatthias Kaehlcke intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B); 21638664281bSPaulo Zanoni } 21648664281bSPaulo Zanoni 216591d14251STvrtko Ursulin static void ivb_err_int_handler(struct drm_i915_private *dev_priv) 21668664281bSPaulo Zanoni { 21678664281bSPaulo Zanoni u32 err_int = I915_READ(GEN7_ERR_INT); 21685a69b89fSDaniel Vetter enum pipe pipe; 21698664281bSPaulo Zanoni 2170de032bf4SPaulo Zanoni if (err_int & ERR_INT_POISON) 2171de032bf4SPaulo Zanoni DRM_ERROR("Poison interrupt\n"); 2172de032bf4SPaulo Zanoni 2173055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 21741f7247c0SDaniel Vetter if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) 21751f7247c0SDaniel Vetter intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 21768664281bSPaulo Zanoni 21775a69b89fSDaniel Vetter if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) { 217891d14251STvrtko Ursulin if (IS_IVYBRIDGE(dev_priv)) 217991d14251STvrtko Ursulin ivb_pipe_crc_irq_handler(dev_priv, pipe); 21805a69b89fSDaniel Vetter else 218191d14251STvrtko Ursulin hsw_pipe_crc_irq_handler(dev_priv, pipe); 21825a69b89fSDaniel Vetter } 21835a69b89fSDaniel Vetter } 21848bf1e9f1SShuang He 21858664281bSPaulo Zanoni I915_WRITE(GEN7_ERR_INT, err_int); 21868664281bSPaulo Zanoni } 21878664281bSPaulo Zanoni 218891d14251STvrtko Ursulin static void cpt_serr_int_handler(struct drm_i915_private *dev_priv) 21898664281bSPaulo Zanoni { 21908664281bSPaulo Zanoni u32 serr_int = I915_READ(SERR_INT); 219145c1cd87SMika Kahola enum pipe pipe; 21928664281bSPaulo Zanoni 2193de032bf4SPaulo Zanoni if (serr_int & SERR_INT_POISON) 2194de032bf4SPaulo Zanoni DRM_ERROR("PCH poison interrupt\n"); 2195de032bf4SPaulo Zanoni 219645c1cd87SMika Kahola for_each_pipe(dev_priv, pipe) 219745c1cd87SMika Kahola if (serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pipe)) 219845c1cd87SMika Kahola intel_pch_fifo_underrun_irq_handler(dev_priv, pipe); 21998664281bSPaulo Zanoni 22008664281bSPaulo Zanoni I915_WRITE(SERR_INT, serr_int); 2201776ad806SJesse Barnes } 2202776ad806SJesse Barnes 220391d14251STvrtko Ursulin static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir) 220423e81d69SAdam Jackson { 2205d048a268SVille Syrjälä enum pipe pipe; 22066dbf30ceSVille Syrjälä u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT; 2207aaf5ec2eSSonika Jindal 220891d14251STvrtko Ursulin ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_cpt); 220991d131d2SDaniel Vetter 2210cfc33bf7SVille Syrjälä if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) { 2211cfc33bf7SVille Syrjälä int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >> 221223e81d69SAdam Jackson SDE_AUDIO_POWER_SHIFT_CPT); 2213cfc33bf7SVille Syrjälä DRM_DEBUG_DRIVER("PCH audio power change on port %c\n", 2214cfc33bf7SVille Syrjälä port_name(port)); 2215cfc33bf7SVille Syrjälä } 221623e81d69SAdam Jackson 221723e81d69SAdam Jackson if (pch_iir & SDE_AUX_MASK_CPT) 221891d14251STvrtko Ursulin dp_aux_irq_handler(dev_priv); 221923e81d69SAdam Jackson 222023e81d69SAdam Jackson if (pch_iir & SDE_GMBUS_CPT) 222191d14251STvrtko Ursulin gmbus_irq_handler(dev_priv); 222223e81d69SAdam Jackson 222323e81d69SAdam Jackson if (pch_iir & SDE_AUDIO_CP_REQ_CPT) 222423e81d69SAdam Jackson DRM_DEBUG_DRIVER("Audio CP request interrupt\n"); 222523e81d69SAdam Jackson 222623e81d69SAdam Jackson if (pch_iir & SDE_AUDIO_CP_CHG_CPT) 222723e81d69SAdam Jackson DRM_DEBUG_DRIVER("Audio CP change interrupt\n"); 222823e81d69SAdam Jackson 222923e81d69SAdam Jackson if (pch_iir & SDE_FDI_MASK_CPT) 2230055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 223123e81d69SAdam Jackson DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", 223223e81d69SAdam Jackson pipe_name(pipe), 223323e81d69SAdam Jackson I915_READ(FDI_RX_IIR(pipe))); 22348664281bSPaulo Zanoni 22358664281bSPaulo Zanoni if (pch_iir & SDE_ERROR_CPT) 223691d14251STvrtko Ursulin cpt_serr_int_handler(dev_priv); 223723e81d69SAdam Jackson } 223823e81d69SAdam Jackson 223958676af6SLucas De Marchi static void icp_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir) 224031604222SAnusha Srivatsa { 224158676af6SLucas De Marchi u32 ddi_hotplug_trigger, tc_hotplug_trigger; 224231604222SAnusha Srivatsa u32 pin_mask = 0, long_mask = 0; 224358676af6SLucas De Marchi bool (*tc_port_hotplug_long_detect)(enum hpd_pin pin, u32 val); 224458676af6SLucas De Marchi const u32 *pins; 224531604222SAnusha Srivatsa 224658676af6SLucas De Marchi if (HAS_PCH_TGP(dev_priv)) { 224758676af6SLucas De Marchi ddi_hotplug_trigger = pch_iir & SDE_DDI_MASK_TGP; 224858676af6SLucas De Marchi tc_hotplug_trigger = pch_iir & SDE_TC_MASK_TGP; 224958676af6SLucas De Marchi tc_port_hotplug_long_detect = tgp_tc_port_hotplug_long_detect; 225058676af6SLucas De Marchi pins = hpd_tgp; 2251*943682e3SMatt Roper } else if (HAS_PCH_JSP(dev_priv)) { 2252*943682e3SMatt Roper ddi_hotplug_trigger = pch_iir & SDE_DDI_MASK_TGP; 2253*943682e3SMatt Roper tc_hotplug_trigger = 0; 2254*943682e3SMatt Roper pins = hpd_tgp; 225558676af6SLucas De Marchi } else if (HAS_PCH_MCC(dev_priv)) { 225653448aedSVivek Kasireddy ddi_hotplug_trigger = pch_iir & SDE_DDI_MASK_ICP; 225753448aedSVivek Kasireddy tc_hotplug_trigger = pch_iir & SDE_TC_HOTPLUG_ICP(PORT_TC1); 2258fcb9bba4SMatt Roper tc_port_hotplug_long_detect = icp_tc_port_hotplug_long_detect; 2259d09ad3e7SMatt Roper pins = hpd_icp; 22608ef7e340SMatt Roper } else { 2261*943682e3SMatt Roper WARN(!HAS_PCH_ICP(dev_priv), 2262*943682e3SMatt Roper "Unrecognized PCH type 0x%x\n", INTEL_PCH_TYPE(dev_priv)); 2263*943682e3SMatt Roper 22648ef7e340SMatt Roper ddi_hotplug_trigger = pch_iir & SDE_DDI_MASK_ICP; 22658ef7e340SMatt Roper tc_hotplug_trigger = pch_iir & SDE_TC_MASK_ICP; 226658676af6SLucas De Marchi tc_port_hotplug_long_detect = icp_tc_port_hotplug_long_detect; 226758676af6SLucas De Marchi pins = hpd_icp; 22688ef7e340SMatt Roper } 22698ef7e340SMatt Roper 227031604222SAnusha Srivatsa if (ddi_hotplug_trigger) { 227131604222SAnusha Srivatsa u32 dig_hotplug_reg; 227231604222SAnusha Srivatsa 227331604222SAnusha Srivatsa dig_hotplug_reg = I915_READ(SHOTPLUG_CTL_DDI); 227431604222SAnusha Srivatsa I915_WRITE(SHOTPLUG_CTL_DDI, dig_hotplug_reg); 227531604222SAnusha Srivatsa 227631604222SAnusha Srivatsa intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, 227731604222SAnusha Srivatsa ddi_hotplug_trigger, 2278c6f7acb8SMatt Roper dig_hotplug_reg, pins, 227931604222SAnusha Srivatsa icp_ddi_port_hotplug_long_detect); 228031604222SAnusha Srivatsa } 228131604222SAnusha Srivatsa 228231604222SAnusha Srivatsa if (tc_hotplug_trigger) { 228331604222SAnusha Srivatsa u32 dig_hotplug_reg; 228431604222SAnusha Srivatsa 228531604222SAnusha Srivatsa dig_hotplug_reg = I915_READ(SHOTPLUG_CTL_TC); 228631604222SAnusha Srivatsa I915_WRITE(SHOTPLUG_CTL_TC, dig_hotplug_reg); 228731604222SAnusha Srivatsa 228831604222SAnusha Srivatsa intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, 228931604222SAnusha Srivatsa tc_hotplug_trigger, 2290c6f7acb8SMatt Roper dig_hotplug_reg, pins, 229158676af6SLucas De Marchi tc_port_hotplug_long_detect); 229252dfdba0SLucas De Marchi } 229352dfdba0SLucas De Marchi 229452dfdba0SLucas De Marchi if (pin_mask) 229552dfdba0SLucas De Marchi intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 229652dfdba0SLucas De Marchi 229752dfdba0SLucas De Marchi if (pch_iir & SDE_GMBUS_ICP) 229852dfdba0SLucas De Marchi gmbus_irq_handler(dev_priv); 229952dfdba0SLucas De Marchi } 230052dfdba0SLucas De Marchi 230191d14251STvrtko Ursulin static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir) 23026dbf30ceSVille Syrjälä { 23036dbf30ceSVille Syrjälä u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT & 23046dbf30ceSVille Syrjälä ~SDE_PORTE_HOTPLUG_SPT; 23056dbf30ceSVille Syrjälä u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT; 23066dbf30ceSVille Syrjälä u32 pin_mask = 0, long_mask = 0; 23076dbf30ceSVille Syrjälä 23086dbf30ceSVille Syrjälä if (hotplug_trigger) { 23096dbf30ceSVille Syrjälä u32 dig_hotplug_reg; 23106dbf30ceSVille Syrjälä 23116dbf30ceSVille Syrjälä dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG); 23126dbf30ceSVille Syrjälä I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg); 23136dbf30ceSVille Syrjälä 2314cf53902fSRodrigo Vivi intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, 2315cf53902fSRodrigo Vivi hotplug_trigger, dig_hotplug_reg, hpd_spt, 231674c0b395SVille Syrjälä spt_port_hotplug_long_detect); 23176dbf30ceSVille Syrjälä } 23186dbf30ceSVille Syrjälä 23196dbf30ceSVille Syrjälä if (hotplug2_trigger) { 23206dbf30ceSVille Syrjälä u32 dig_hotplug_reg; 23216dbf30ceSVille Syrjälä 23226dbf30ceSVille Syrjälä dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2); 23236dbf30ceSVille Syrjälä I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg); 23246dbf30ceSVille Syrjälä 2325cf53902fSRodrigo Vivi intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, 2326cf53902fSRodrigo Vivi hotplug2_trigger, dig_hotplug_reg, hpd_spt, 23276dbf30ceSVille Syrjälä spt_port_hotplug2_long_detect); 23286dbf30ceSVille Syrjälä } 23296dbf30ceSVille Syrjälä 23306dbf30ceSVille Syrjälä if (pin_mask) 233191d14251STvrtko Ursulin intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 23326dbf30ceSVille Syrjälä 23336dbf30ceSVille Syrjälä if (pch_iir & SDE_GMBUS_CPT) 233491d14251STvrtko Ursulin gmbus_irq_handler(dev_priv); 23356dbf30ceSVille Syrjälä } 23366dbf30ceSVille Syrjälä 233791d14251STvrtko Ursulin static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv, 233891d14251STvrtko Ursulin u32 hotplug_trigger, 233940e56410SVille Syrjälä const u32 hpd[HPD_NUM_PINS]) 2340c008bc6eSPaulo Zanoni { 2341e4ce95aaSVille Syrjälä u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0; 2342e4ce95aaSVille Syrjälä 2343e4ce95aaSVille Syrjälä dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL); 2344e4ce95aaSVille Syrjälä I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg); 2345e4ce95aaSVille Syrjälä 2346cf53902fSRodrigo Vivi intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger, 234740e56410SVille Syrjälä dig_hotplug_reg, hpd, 2348e4ce95aaSVille Syrjälä ilk_port_hotplug_long_detect); 234940e56410SVille Syrjälä 235091d14251STvrtko Ursulin intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 2351e4ce95aaSVille Syrjälä } 2352c008bc6eSPaulo Zanoni 235391d14251STvrtko Ursulin static void ilk_display_irq_handler(struct drm_i915_private *dev_priv, 235491d14251STvrtko Ursulin u32 de_iir) 235540e56410SVille Syrjälä { 235640e56410SVille Syrjälä enum pipe pipe; 235740e56410SVille Syrjälä u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG; 235840e56410SVille Syrjälä 235940e56410SVille Syrjälä if (hotplug_trigger) 236091d14251STvrtko Ursulin ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk); 236140e56410SVille Syrjälä 2362c008bc6eSPaulo Zanoni if (de_iir & DE_AUX_CHANNEL_A) 236391d14251STvrtko Ursulin dp_aux_irq_handler(dev_priv); 2364c008bc6eSPaulo Zanoni 2365c008bc6eSPaulo Zanoni if (de_iir & DE_GSE) 236691d14251STvrtko Ursulin intel_opregion_asle_intr(dev_priv); 2367c008bc6eSPaulo Zanoni 2368c008bc6eSPaulo Zanoni if (de_iir & DE_POISON) 2369c008bc6eSPaulo Zanoni DRM_ERROR("Poison interrupt\n"); 2370c008bc6eSPaulo Zanoni 2371055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 2372fd3a4024SDaniel Vetter if (de_iir & DE_PIPE_VBLANK(pipe)) 2373fd3a4024SDaniel Vetter drm_handle_vblank(&dev_priv->drm, pipe); 2374c008bc6eSPaulo Zanoni 237540da17c2SDaniel Vetter if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe)) 23761f7247c0SDaniel Vetter intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 2377c008bc6eSPaulo Zanoni 237840da17c2SDaniel Vetter if (de_iir & DE_PIPE_CRC_DONE(pipe)) 237991d14251STvrtko Ursulin i9xx_pipe_crc_irq_handler(dev_priv, pipe); 2380c008bc6eSPaulo Zanoni } 2381c008bc6eSPaulo Zanoni 2382c008bc6eSPaulo Zanoni /* check event from PCH */ 2383c008bc6eSPaulo Zanoni if (de_iir & DE_PCH_EVENT) { 2384c008bc6eSPaulo Zanoni u32 pch_iir = I915_READ(SDEIIR); 2385c008bc6eSPaulo Zanoni 238691d14251STvrtko Ursulin if (HAS_PCH_CPT(dev_priv)) 238791d14251STvrtko Ursulin cpt_irq_handler(dev_priv, pch_iir); 2388c008bc6eSPaulo Zanoni else 238991d14251STvrtko Ursulin ibx_irq_handler(dev_priv, pch_iir); 2390c008bc6eSPaulo Zanoni 2391c008bc6eSPaulo Zanoni /* should clear PCH hotplug event before clear CPU irq */ 2392c008bc6eSPaulo Zanoni I915_WRITE(SDEIIR, pch_iir); 2393c008bc6eSPaulo Zanoni } 2394c008bc6eSPaulo Zanoni 2395cf819effSLucas De Marchi if (IS_GEN(dev_priv, 5) && de_iir & DE_PCU_EVENT) 239691d14251STvrtko Ursulin ironlake_rps_change_irq_handler(dev_priv); 2397c008bc6eSPaulo Zanoni } 2398c008bc6eSPaulo Zanoni 239991d14251STvrtko Ursulin static void ivb_display_irq_handler(struct drm_i915_private *dev_priv, 240091d14251STvrtko Ursulin u32 de_iir) 24019719fb98SPaulo Zanoni { 240207d27e20SDamien Lespiau enum pipe pipe; 240323bb4cb5SVille Syrjälä u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB; 240423bb4cb5SVille Syrjälä 240540e56410SVille Syrjälä if (hotplug_trigger) 240691d14251STvrtko Ursulin ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb); 24079719fb98SPaulo Zanoni 24089719fb98SPaulo Zanoni if (de_iir & DE_ERR_INT_IVB) 240991d14251STvrtko Ursulin ivb_err_int_handler(dev_priv); 24109719fb98SPaulo Zanoni 241154fd3149SDhinakaran Pandiyan if (de_iir & DE_EDP_PSR_INT_HSW) { 241254fd3149SDhinakaran Pandiyan u32 psr_iir = I915_READ(EDP_PSR_IIR); 241354fd3149SDhinakaran Pandiyan 241454fd3149SDhinakaran Pandiyan intel_psr_irq_handler(dev_priv, psr_iir); 241554fd3149SDhinakaran Pandiyan I915_WRITE(EDP_PSR_IIR, psr_iir); 241654fd3149SDhinakaran Pandiyan } 2417fc340442SDaniel Vetter 24189719fb98SPaulo Zanoni if (de_iir & DE_AUX_CHANNEL_A_IVB) 241991d14251STvrtko Ursulin dp_aux_irq_handler(dev_priv); 24209719fb98SPaulo Zanoni 24219719fb98SPaulo Zanoni if (de_iir & DE_GSE_IVB) 242291d14251STvrtko Ursulin intel_opregion_asle_intr(dev_priv); 24239719fb98SPaulo Zanoni 2424055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 2425fd3a4024SDaniel Vetter if (de_iir & (DE_PIPE_VBLANK_IVB(pipe))) 2426fd3a4024SDaniel Vetter drm_handle_vblank(&dev_priv->drm, pipe); 24279719fb98SPaulo Zanoni } 24289719fb98SPaulo Zanoni 24299719fb98SPaulo Zanoni /* check event from PCH */ 243091d14251STvrtko Ursulin if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) { 24319719fb98SPaulo Zanoni u32 pch_iir = I915_READ(SDEIIR); 24329719fb98SPaulo Zanoni 243391d14251STvrtko Ursulin cpt_irq_handler(dev_priv, pch_iir); 24349719fb98SPaulo Zanoni 24359719fb98SPaulo Zanoni /* clear PCH hotplug event before clear CPU irq */ 24369719fb98SPaulo Zanoni I915_WRITE(SDEIIR, pch_iir); 24379719fb98SPaulo Zanoni } 24389719fb98SPaulo Zanoni } 24399719fb98SPaulo Zanoni 244072c90f62SOscar Mateo /* 244172c90f62SOscar Mateo * To handle irqs with the minimum potential races with fresh interrupts, we: 244272c90f62SOscar Mateo * 1 - Disable Master Interrupt Control. 244372c90f62SOscar Mateo * 2 - Find the source(s) of the interrupt. 244472c90f62SOscar Mateo * 3 - Clear the Interrupt Identity bits (IIR). 244572c90f62SOscar Mateo * 4 - Process the interrupt(s) that had bits set in the IIRs. 244672c90f62SOscar Mateo * 5 - Re-enable Master Interrupt Control. 244772c90f62SOscar Mateo */ 2448f1af8fc1SPaulo Zanoni static irqreturn_t ironlake_irq_handler(int irq, void *arg) 2449b1f14ad0SJesse Barnes { 2450b318b824SVille Syrjälä struct drm_i915_private *dev_priv = arg; 2451f1af8fc1SPaulo Zanoni u32 de_iir, gt_iir, de_ier, sde_ier = 0; 24520e43406bSChris Wilson irqreturn_t ret = IRQ_NONE; 2453b1f14ad0SJesse Barnes 24542dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 24552dd2a883SImre Deak return IRQ_NONE; 24562dd2a883SImre Deak 24571f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 24589102650fSDaniele Ceraolo Spurio disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 24591f814dacSImre Deak 2460b1f14ad0SJesse Barnes /* disable master interrupt before clearing iir */ 2461b1f14ad0SJesse Barnes de_ier = I915_READ(DEIER); 2462b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL); 24630e43406bSChris Wilson 246444498aeaSPaulo Zanoni /* Disable south interrupts. We'll only write to SDEIIR once, so further 246544498aeaSPaulo Zanoni * interrupts will will be stored on its back queue, and then we'll be 246644498aeaSPaulo Zanoni * able to process them after we restore SDEIER (as soon as we restore 246744498aeaSPaulo Zanoni * it, we'll get an interrupt if SDEIIR still has something to process 246844498aeaSPaulo Zanoni * due to its back queue). */ 246991d14251STvrtko Ursulin if (!HAS_PCH_NOP(dev_priv)) { 247044498aeaSPaulo Zanoni sde_ier = I915_READ(SDEIER); 247144498aeaSPaulo Zanoni I915_WRITE(SDEIER, 0); 2472ab5c608bSBen Widawsky } 247344498aeaSPaulo Zanoni 247472c90f62SOscar Mateo /* Find, clear, then process each source of interrupt */ 247572c90f62SOscar Mateo 24760e43406bSChris Wilson gt_iir = I915_READ(GTIIR); 24770e43406bSChris Wilson if (gt_iir) { 247872c90f62SOscar Mateo I915_WRITE(GTIIR, gt_iir); 247972c90f62SOscar Mateo ret = IRQ_HANDLED; 248091d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 6) 2481cf1c97dcSAndi Shyti gen6_gt_irq_handler(&dev_priv->gt, gt_iir); 2482d8fc8a47SPaulo Zanoni else 2483cf1c97dcSAndi Shyti gen5_gt_irq_handler(&dev_priv->gt, gt_iir); 24840e43406bSChris Wilson } 2485b1f14ad0SJesse Barnes 2486b1f14ad0SJesse Barnes de_iir = I915_READ(DEIIR); 24870e43406bSChris Wilson if (de_iir) { 248872c90f62SOscar Mateo I915_WRITE(DEIIR, de_iir); 248972c90f62SOscar Mateo ret = IRQ_HANDLED; 249091d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 7) 249191d14251STvrtko Ursulin ivb_display_irq_handler(dev_priv, de_iir); 2492f1af8fc1SPaulo Zanoni else 249391d14251STvrtko Ursulin ilk_display_irq_handler(dev_priv, de_iir); 24940e43406bSChris Wilson } 24950e43406bSChris Wilson 249691d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 6) { 2497f1af8fc1SPaulo Zanoni u32 pm_iir = I915_READ(GEN6_PMIIR); 24980e43406bSChris Wilson if (pm_iir) { 2499b1f14ad0SJesse Barnes I915_WRITE(GEN6_PMIIR, pm_iir); 25000e43406bSChris Wilson ret = IRQ_HANDLED; 250172c90f62SOscar Mateo gen6_rps_irq_handler(dev_priv, pm_iir); 25020e43406bSChris Wilson } 2503f1af8fc1SPaulo Zanoni } 2504b1f14ad0SJesse Barnes 2505b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier); 250674093f3eSChris Wilson if (!HAS_PCH_NOP(dev_priv)) 250744498aeaSPaulo Zanoni I915_WRITE(SDEIER, sde_ier); 2508b1f14ad0SJesse Barnes 25091f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 25109102650fSDaniele Ceraolo Spurio enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 25111f814dacSImre Deak 2512b1f14ad0SJesse Barnes return ret; 2513b1f14ad0SJesse Barnes } 2514b1f14ad0SJesse Barnes 251591d14251STvrtko Ursulin static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv, 251691d14251STvrtko Ursulin u32 hotplug_trigger, 251740e56410SVille Syrjälä const u32 hpd[HPD_NUM_PINS]) 2518d04a492dSShashank Sharma { 2519cebd87a0SVille Syrjälä u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0; 2520d04a492dSShashank Sharma 2521a52bb15bSVille Syrjälä dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG); 2522a52bb15bSVille Syrjälä I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg); 2523d04a492dSShashank Sharma 2524cf53902fSRodrigo Vivi intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger, 252540e56410SVille Syrjälä dig_hotplug_reg, hpd, 2526cebd87a0SVille Syrjälä bxt_port_hotplug_long_detect); 252740e56410SVille Syrjälä 252891d14251STvrtko Ursulin intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 2529d04a492dSShashank Sharma } 2530d04a492dSShashank Sharma 2531121e758eSDhinakaran Pandiyan static void gen11_hpd_irq_handler(struct drm_i915_private *dev_priv, u32 iir) 2532121e758eSDhinakaran Pandiyan { 2533121e758eSDhinakaran Pandiyan u32 pin_mask = 0, long_mask = 0; 2534b796b971SDhinakaran Pandiyan u32 trigger_tc = iir & GEN11_DE_TC_HOTPLUG_MASK; 2535b796b971SDhinakaran Pandiyan u32 trigger_tbt = iir & GEN11_DE_TBT_HOTPLUG_MASK; 253648ef15d3SJosé Roberto de Souza long_pulse_detect_func long_pulse_detect; 253748ef15d3SJosé Roberto de Souza const u32 *hpd; 253848ef15d3SJosé Roberto de Souza 253948ef15d3SJosé Roberto de Souza if (INTEL_GEN(dev_priv) >= 12) { 254048ef15d3SJosé Roberto de Souza long_pulse_detect = gen12_port_hotplug_long_detect; 254148ef15d3SJosé Roberto de Souza hpd = hpd_gen12; 254248ef15d3SJosé Roberto de Souza } else { 254348ef15d3SJosé Roberto de Souza long_pulse_detect = gen11_port_hotplug_long_detect; 254448ef15d3SJosé Roberto de Souza hpd = hpd_gen11; 254548ef15d3SJosé Roberto de Souza } 2546121e758eSDhinakaran Pandiyan 2547121e758eSDhinakaran Pandiyan if (trigger_tc) { 2548b796b971SDhinakaran Pandiyan u32 dig_hotplug_reg; 2549b796b971SDhinakaran Pandiyan 2550121e758eSDhinakaran Pandiyan dig_hotplug_reg = I915_READ(GEN11_TC_HOTPLUG_CTL); 2551121e758eSDhinakaran Pandiyan I915_WRITE(GEN11_TC_HOTPLUG_CTL, dig_hotplug_reg); 2552121e758eSDhinakaran Pandiyan 2553121e758eSDhinakaran Pandiyan intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, trigger_tc, 255448ef15d3SJosé Roberto de Souza dig_hotplug_reg, hpd, long_pulse_detect); 2555121e758eSDhinakaran Pandiyan } 2556b796b971SDhinakaran Pandiyan 2557b796b971SDhinakaran Pandiyan if (trigger_tbt) { 2558b796b971SDhinakaran Pandiyan u32 dig_hotplug_reg; 2559b796b971SDhinakaran Pandiyan 2560b796b971SDhinakaran Pandiyan dig_hotplug_reg = I915_READ(GEN11_TBT_HOTPLUG_CTL); 2561b796b971SDhinakaran Pandiyan I915_WRITE(GEN11_TBT_HOTPLUG_CTL, dig_hotplug_reg); 2562b796b971SDhinakaran Pandiyan 2563b796b971SDhinakaran Pandiyan intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, trigger_tbt, 256448ef15d3SJosé Roberto de Souza dig_hotplug_reg, hpd, long_pulse_detect); 2565b796b971SDhinakaran Pandiyan } 2566b796b971SDhinakaran Pandiyan 2567b796b971SDhinakaran Pandiyan if (pin_mask) 2568b796b971SDhinakaran Pandiyan intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 2569b796b971SDhinakaran Pandiyan else 2570b796b971SDhinakaran Pandiyan DRM_ERROR("Unexpected DE HPD interrupt 0x%08x\n", iir); 2571121e758eSDhinakaran Pandiyan } 2572121e758eSDhinakaran Pandiyan 25739d17210fSLucas De Marchi static u32 gen8_de_port_aux_mask(struct drm_i915_private *dev_priv) 25749d17210fSLucas De Marchi { 257555523360SLucas De Marchi u32 mask; 25769d17210fSLucas De Marchi 257755523360SLucas De Marchi if (INTEL_GEN(dev_priv) >= 12) 257855523360SLucas De Marchi /* TODO: Add AUX entries for USBC */ 257955523360SLucas De Marchi return TGL_DE_PORT_AUX_DDIA | 258055523360SLucas De Marchi TGL_DE_PORT_AUX_DDIB | 258155523360SLucas De Marchi TGL_DE_PORT_AUX_DDIC; 258255523360SLucas De Marchi 258355523360SLucas De Marchi mask = GEN8_AUX_CHANNEL_A; 25849d17210fSLucas De Marchi if (INTEL_GEN(dev_priv) >= 9) 25859d17210fSLucas De Marchi mask |= GEN9_AUX_CHANNEL_B | 25869d17210fSLucas De Marchi GEN9_AUX_CHANNEL_C | 25879d17210fSLucas De Marchi GEN9_AUX_CHANNEL_D; 25889d17210fSLucas De Marchi 258955523360SLucas De Marchi if (IS_CNL_WITH_PORT_F(dev_priv) || IS_GEN(dev_priv, 11)) 25909d17210fSLucas De Marchi mask |= CNL_AUX_CHANNEL_F; 25919d17210fSLucas De Marchi 259255523360SLucas De Marchi if (IS_GEN(dev_priv, 11)) 259355523360SLucas De Marchi mask |= ICL_AUX_CHANNEL_E; 25949d17210fSLucas De Marchi 25959d17210fSLucas De Marchi return mask; 25969d17210fSLucas De Marchi } 25979d17210fSLucas De Marchi 25985270130dSVille Syrjälä static u32 gen8_de_pipe_fault_mask(struct drm_i915_private *dev_priv) 25995270130dSVille Syrjälä { 26005270130dSVille Syrjälä if (INTEL_GEN(dev_priv) >= 9) 26015270130dSVille Syrjälä return GEN9_DE_PIPE_IRQ_FAULT_ERRORS; 26025270130dSVille Syrjälä else 26035270130dSVille Syrjälä return GEN8_DE_PIPE_IRQ_FAULT_ERRORS; 26045270130dSVille Syrjälä } 26055270130dSVille Syrjälä 260646c63d24SJosé Roberto de Souza static void 260746c63d24SJosé Roberto de Souza gen8_de_misc_irq_handler(struct drm_i915_private *dev_priv, u32 iir) 2608abd58f01SBen Widawsky { 2609e04f7eceSVille Syrjälä bool found = false; 2610e04f7eceSVille Syrjälä 2611e04f7eceSVille Syrjälä if (iir & GEN8_DE_MISC_GSE) { 261291d14251STvrtko Ursulin intel_opregion_asle_intr(dev_priv); 2613e04f7eceSVille Syrjälä found = true; 2614e04f7eceSVille Syrjälä } 2615e04f7eceSVille Syrjälä 2616e04f7eceSVille Syrjälä if (iir & GEN8_DE_EDP_PSR) { 26178241cfbeSJosé Roberto de Souza u32 psr_iir; 26188241cfbeSJosé Roberto de Souza i915_reg_t iir_reg; 26198241cfbeSJosé Roberto de Souza 26208241cfbeSJosé Roberto de Souza if (INTEL_GEN(dev_priv) >= 12) 26218241cfbeSJosé Roberto de Souza iir_reg = TRANS_PSR_IIR(dev_priv->psr.transcoder); 26228241cfbeSJosé Roberto de Souza else 26238241cfbeSJosé Roberto de Souza iir_reg = EDP_PSR_IIR; 26248241cfbeSJosé Roberto de Souza 26258241cfbeSJosé Roberto de Souza psr_iir = I915_READ(iir_reg); 26268241cfbeSJosé Roberto de Souza I915_WRITE(iir_reg, psr_iir); 26278241cfbeSJosé Roberto de Souza 26288241cfbeSJosé Roberto de Souza if (psr_iir) 26298241cfbeSJosé Roberto de Souza found = true; 263054fd3149SDhinakaran Pandiyan 263154fd3149SDhinakaran Pandiyan intel_psr_irq_handler(dev_priv, psr_iir); 2632e04f7eceSVille Syrjälä } 2633e04f7eceSVille Syrjälä 2634e04f7eceSVille Syrjälä if (!found) 263538cc46d7SOscar Mateo DRM_ERROR("Unexpected DE Misc interrupt\n"); 2636abd58f01SBen Widawsky } 263746c63d24SJosé Roberto de Souza 263846c63d24SJosé Roberto de Souza static irqreturn_t 263946c63d24SJosé Roberto de Souza gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl) 264046c63d24SJosé Roberto de Souza { 264146c63d24SJosé Roberto de Souza irqreturn_t ret = IRQ_NONE; 264246c63d24SJosé Roberto de Souza u32 iir; 264346c63d24SJosé Roberto de Souza enum pipe pipe; 264446c63d24SJosé Roberto de Souza 264546c63d24SJosé Roberto de Souza if (master_ctl & GEN8_DE_MISC_IRQ) { 264646c63d24SJosé Roberto de Souza iir = I915_READ(GEN8_DE_MISC_IIR); 264746c63d24SJosé Roberto de Souza if (iir) { 264846c63d24SJosé Roberto de Souza I915_WRITE(GEN8_DE_MISC_IIR, iir); 264946c63d24SJosé Roberto de Souza ret = IRQ_HANDLED; 265046c63d24SJosé Roberto de Souza gen8_de_misc_irq_handler(dev_priv, iir); 265146c63d24SJosé Roberto de Souza } else { 265238cc46d7SOscar Mateo DRM_ERROR("The master control interrupt lied (DE MISC)!\n"); 2653abd58f01SBen Widawsky } 265446c63d24SJosé Roberto de Souza } 2655abd58f01SBen Widawsky 2656121e758eSDhinakaran Pandiyan if (INTEL_GEN(dev_priv) >= 11 && (master_ctl & GEN11_DE_HPD_IRQ)) { 2657121e758eSDhinakaran Pandiyan iir = I915_READ(GEN11_DE_HPD_IIR); 2658121e758eSDhinakaran Pandiyan if (iir) { 2659121e758eSDhinakaran Pandiyan I915_WRITE(GEN11_DE_HPD_IIR, iir); 2660121e758eSDhinakaran Pandiyan ret = IRQ_HANDLED; 2661121e758eSDhinakaran Pandiyan gen11_hpd_irq_handler(dev_priv, iir); 2662121e758eSDhinakaran Pandiyan } else { 2663121e758eSDhinakaran Pandiyan DRM_ERROR("The master control interrupt lied, (DE HPD)!\n"); 2664121e758eSDhinakaran Pandiyan } 2665121e758eSDhinakaran Pandiyan } 2666121e758eSDhinakaran Pandiyan 26676d766f02SDaniel Vetter if (master_ctl & GEN8_DE_PORT_IRQ) { 2668e32192e1STvrtko Ursulin iir = I915_READ(GEN8_DE_PORT_IIR); 2669e32192e1STvrtko Ursulin if (iir) { 2670e32192e1STvrtko Ursulin u32 tmp_mask; 2671d04a492dSShashank Sharma bool found = false; 2672cebd87a0SVille Syrjälä 2673e32192e1STvrtko Ursulin I915_WRITE(GEN8_DE_PORT_IIR, iir); 26746d766f02SDaniel Vetter ret = IRQ_HANDLED; 267588e04703SJesse Barnes 26769d17210fSLucas De Marchi if (iir & gen8_de_port_aux_mask(dev_priv)) { 267791d14251STvrtko Ursulin dp_aux_irq_handler(dev_priv); 2678d04a492dSShashank Sharma found = true; 2679d04a492dSShashank Sharma } 2680d04a492dSShashank Sharma 2681cc3f90f0SAnder Conselvan de Oliveira if (IS_GEN9_LP(dev_priv)) { 2682e32192e1STvrtko Ursulin tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK; 2683e32192e1STvrtko Ursulin if (tmp_mask) { 268491d14251STvrtko Ursulin bxt_hpd_irq_handler(dev_priv, tmp_mask, 268591d14251STvrtko Ursulin hpd_bxt); 2686d04a492dSShashank Sharma found = true; 2687d04a492dSShashank Sharma } 2688e32192e1STvrtko Ursulin } else if (IS_BROADWELL(dev_priv)) { 2689e32192e1STvrtko Ursulin tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG; 2690e32192e1STvrtko Ursulin if (tmp_mask) { 269191d14251STvrtko Ursulin ilk_hpd_irq_handler(dev_priv, 269291d14251STvrtko Ursulin tmp_mask, hpd_bdw); 2693e32192e1STvrtko Ursulin found = true; 2694e32192e1STvrtko Ursulin } 2695e32192e1STvrtko Ursulin } 2696d04a492dSShashank Sharma 2697cc3f90f0SAnder Conselvan de Oliveira if (IS_GEN9_LP(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) { 269891d14251STvrtko Ursulin gmbus_irq_handler(dev_priv); 26999e63743eSShashank Sharma found = true; 27009e63743eSShashank Sharma } 27019e63743eSShashank Sharma 2702d04a492dSShashank Sharma if (!found) 270338cc46d7SOscar Mateo DRM_ERROR("Unexpected DE Port interrupt\n"); 27046d766f02SDaniel Vetter } 270538cc46d7SOscar Mateo else 270638cc46d7SOscar Mateo DRM_ERROR("The master control interrupt lied (DE PORT)!\n"); 27076d766f02SDaniel Vetter } 27086d766f02SDaniel Vetter 2709055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 2710fd3a4024SDaniel Vetter u32 fault_errors; 2711abd58f01SBen Widawsky 2712c42664ccSDaniel Vetter if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe))) 2713c42664ccSDaniel Vetter continue; 2714c42664ccSDaniel Vetter 2715e32192e1STvrtko Ursulin iir = I915_READ(GEN8_DE_PIPE_IIR(pipe)); 2716e32192e1STvrtko Ursulin if (!iir) { 2717e32192e1STvrtko Ursulin DRM_ERROR("The master control interrupt lied (DE PIPE)!\n"); 2718e32192e1STvrtko Ursulin continue; 2719e32192e1STvrtko Ursulin } 2720770de83dSDamien Lespiau 2721e32192e1STvrtko Ursulin ret = IRQ_HANDLED; 2722e32192e1STvrtko Ursulin I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir); 2723e32192e1STvrtko Ursulin 2724fd3a4024SDaniel Vetter if (iir & GEN8_PIPE_VBLANK) 2725fd3a4024SDaniel Vetter drm_handle_vblank(&dev_priv->drm, pipe); 2726abd58f01SBen Widawsky 2727e32192e1STvrtko Ursulin if (iir & GEN8_PIPE_CDCLK_CRC_DONE) 272891d14251STvrtko Ursulin hsw_pipe_crc_irq_handler(dev_priv, pipe); 27290fbe7870SDaniel Vetter 2730e32192e1STvrtko Ursulin if (iir & GEN8_PIPE_FIFO_UNDERRUN) 2731e32192e1STvrtko Ursulin intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 273238d83c96SDaniel Vetter 27335270130dSVille Syrjälä fault_errors = iir & gen8_de_pipe_fault_mask(dev_priv); 2734770de83dSDamien Lespiau if (fault_errors) 27351353ec38STvrtko Ursulin DRM_ERROR("Fault errors on pipe %c: 0x%08x\n", 273630100f2bSDaniel Vetter pipe_name(pipe), 2737e32192e1STvrtko Ursulin fault_errors); 2738abd58f01SBen Widawsky } 2739abd58f01SBen Widawsky 274091d14251STvrtko Ursulin if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) && 2741266ea3d9SShashank Sharma master_ctl & GEN8_DE_PCH_IRQ) { 274292d03a80SDaniel Vetter /* 274392d03a80SDaniel Vetter * FIXME(BDW): Assume for now that the new interrupt handling 274492d03a80SDaniel Vetter * scheme also closed the SDE interrupt handling race we've seen 274592d03a80SDaniel Vetter * on older pch-split platforms. But this needs testing. 274692d03a80SDaniel Vetter */ 2747e32192e1STvrtko Ursulin iir = I915_READ(SDEIIR); 2748e32192e1STvrtko Ursulin if (iir) { 2749e32192e1STvrtko Ursulin I915_WRITE(SDEIIR, iir); 275092d03a80SDaniel Vetter ret = IRQ_HANDLED; 27516dbf30ceSVille Syrjälä 275258676af6SLucas De Marchi if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP) 275358676af6SLucas De Marchi icp_irq_handler(dev_priv, iir); 2754c6c30b91SRodrigo Vivi else if (INTEL_PCH_TYPE(dev_priv) >= PCH_SPT) 275591d14251STvrtko Ursulin spt_irq_handler(dev_priv, iir); 27566dbf30ceSVille Syrjälä else 275791d14251STvrtko Ursulin cpt_irq_handler(dev_priv, iir); 27582dfb0b81SJani Nikula } else { 27592dfb0b81SJani Nikula /* 27602dfb0b81SJani Nikula * Like on previous PCH there seems to be something 27612dfb0b81SJani Nikula * fishy going on with forwarding PCH interrupts. 27622dfb0b81SJani Nikula */ 27632dfb0b81SJani Nikula DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n"); 27642dfb0b81SJani Nikula } 276592d03a80SDaniel Vetter } 276692d03a80SDaniel Vetter 2767f11a0f46STvrtko Ursulin return ret; 2768f11a0f46STvrtko Ursulin } 2769f11a0f46STvrtko Ursulin 27704376b9c9SMika Kuoppala static inline u32 gen8_master_intr_disable(void __iomem * const regs) 27714376b9c9SMika Kuoppala { 27724376b9c9SMika Kuoppala raw_reg_write(regs, GEN8_MASTER_IRQ, 0); 27734376b9c9SMika Kuoppala 27744376b9c9SMika Kuoppala /* 27754376b9c9SMika Kuoppala * Now with master disabled, get a sample of level indications 27764376b9c9SMika Kuoppala * for this interrupt. Indications will be cleared on related acks. 27774376b9c9SMika Kuoppala * New indications can and will light up during processing, 27784376b9c9SMika Kuoppala * and will generate new interrupt after enabling master. 27794376b9c9SMika Kuoppala */ 27804376b9c9SMika Kuoppala return raw_reg_read(regs, GEN8_MASTER_IRQ); 27814376b9c9SMika Kuoppala } 27824376b9c9SMika Kuoppala 27834376b9c9SMika Kuoppala static inline void gen8_master_intr_enable(void __iomem * const regs) 27844376b9c9SMika Kuoppala { 27854376b9c9SMika Kuoppala raw_reg_write(regs, GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); 27864376b9c9SMika Kuoppala } 27874376b9c9SMika Kuoppala 2788f11a0f46STvrtko Ursulin static irqreturn_t gen8_irq_handler(int irq, void *arg) 2789f11a0f46STvrtko Ursulin { 2790b318b824SVille Syrjälä struct drm_i915_private *dev_priv = arg; 279125286aacSDaniele Ceraolo Spurio void __iomem * const regs = dev_priv->uncore.regs; 2792f11a0f46STvrtko Ursulin u32 master_ctl; 2793f0fd96f5SChris Wilson u32 gt_iir[4]; 2794f11a0f46STvrtko Ursulin 2795f11a0f46STvrtko Ursulin if (!intel_irqs_enabled(dev_priv)) 2796f11a0f46STvrtko Ursulin return IRQ_NONE; 2797f11a0f46STvrtko Ursulin 27984376b9c9SMika Kuoppala master_ctl = gen8_master_intr_disable(regs); 27994376b9c9SMika Kuoppala if (!master_ctl) { 28004376b9c9SMika Kuoppala gen8_master_intr_enable(regs); 2801f11a0f46STvrtko Ursulin return IRQ_NONE; 28024376b9c9SMika Kuoppala } 2803f11a0f46STvrtko Ursulin 2804f11a0f46STvrtko Ursulin /* Find, clear, then process each source of interrupt */ 2805cf1c97dcSAndi Shyti gen8_gt_irq_ack(&dev_priv->gt, master_ctl, gt_iir); 2806f0fd96f5SChris Wilson 2807f0fd96f5SChris Wilson /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 2808f0fd96f5SChris Wilson if (master_ctl & ~GEN8_GT_IRQS) { 28099102650fSDaniele Ceraolo Spurio disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 281055ef72f2SChris Wilson gen8_de_irq_handler(dev_priv, master_ctl); 28119102650fSDaniele Ceraolo Spurio enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 2812f0fd96f5SChris Wilson } 2813f11a0f46STvrtko Ursulin 28144376b9c9SMika Kuoppala gen8_master_intr_enable(regs); 2815abd58f01SBen Widawsky 2816cf1c97dcSAndi Shyti gen8_gt_irq_handler(&dev_priv->gt, master_ctl, gt_iir); 28171f814dacSImre Deak 281855ef72f2SChris Wilson return IRQ_HANDLED; 2819abd58f01SBen Widawsky } 2820abd58f01SBen Widawsky 282151951ae7SMika Kuoppala static u32 28229b77011eSTvrtko Ursulin gen11_gu_misc_irq_ack(struct intel_gt *gt, const u32 master_ctl) 2823df0d28c1SDhinakaran Pandiyan { 28249b77011eSTvrtko Ursulin void __iomem * const regs = gt->uncore->regs; 28257a909383SChris Wilson u32 iir; 2826df0d28c1SDhinakaran Pandiyan 2827df0d28c1SDhinakaran Pandiyan if (!(master_ctl & GEN11_GU_MISC_IRQ)) 28287a909383SChris Wilson return 0; 2829df0d28c1SDhinakaran Pandiyan 28307a909383SChris Wilson iir = raw_reg_read(regs, GEN11_GU_MISC_IIR); 28317a909383SChris Wilson if (likely(iir)) 28327a909383SChris Wilson raw_reg_write(regs, GEN11_GU_MISC_IIR, iir); 28337a909383SChris Wilson 28347a909383SChris Wilson return iir; 2835df0d28c1SDhinakaran Pandiyan } 2836df0d28c1SDhinakaran Pandiyan 2837df0d28c1SDhinakaran Pandiyan static void 28389b77011eSTvrtko Ursulin gen11_gu_misc_irq_handler(struct intel_gt *gt, const u32 iir) 2839df0d28c1SDhinakaran Pandiyan { 2840df0d28c1SDhinakaran Pandiyan if (iir & GEN11_GU_MISC_GSE) 28419b77011eSTvrtko Ursulin intel_opregion_asle_intr(gt->i915); 2842df0d28c1SDhinakaran Pandiyan } 2843df0d28c1SDhinakaran Pandiyan 284481067b71SMika Kuoppala static inline u32 gen11_master_intr_disable(void __iomem * const regs) 284581067b71SMika Kuoppala { 284681067b71SMika Kuoppala raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, 0); 284781067b71SMika Kuoppala 284881067b71SMika Kuoppala /* 284981067b71SMika Kuoppala * Now with master disabled, get a sample of level indications 285081067b71SMika Kuoppala * for this interrupt. Indications will be cleared on related acks. 285181067b71SMika Kuoppala * New indications can and will light up during processing, 285281067b71SMika Kuoppala * and will generate new interrupt after enabling master. 285381067b71SMika Kuoppala */ 285481067b71SMika Kuoppala return raw_reg_read(regs, GEN11_GFX_MSTR_IRQ); 285581067b71SMika Kuoppala } 285681067b71SMika Kuoppala 285781067b71SMika Kuoppala static inline void gen11_master_intr_enable(void __iomem * const regs) 285881067b71SMika Kuoppala { 285981067b71SMika Kuoppala raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, GEN11_MASTER_IRQ); 286081067b71SMika Kuoppala } 286181067b71SMika Kuoppala 286251951ae7SMika Kuoppala static irqreturn_t gen11_irq_handler(int irq, void *arg) 286351951ae7SMika Kuoppala { 2864b318b824SVille Syrjälä struct drm_i915_private * const i915 = arg; 286525286aacSDaniele Ceraolo Spurio void __iomem * const regs = i915->uncore.regs; 28669b77011eSTvrtko Ursulin struct intel_gt *gt = &i915->gt; 286751951ae7SMika Kuoppala u32 master_ctl; 2868df0d28c1SDhinakaran Pandiyan u32 gu_misc_iir; 286951951ae7SMika Kuoppala 287051951ae7SMika Kuoppala if (!intel_irqs_enabled(i915)) 287151951ae7SMika Kuoppala return IRQ_NONE; 287251951ae7SMika Kuoppala 287381067b71SMika Kuoppala master_ctl = gen11_master_intr_disable(regs); 287481067b71SMika Kuoppala if (!master_ctl) { 287581067b71SMika Kuoppala gen11_master_intr_enable(regs); 287651951ae7SMika Kuoppala return IRQ_NONE; 287781067b71SMika Kuoppala } 287851951ae7SMika Kuoppala 287951951ae7SMika Kuoppala /* Find, clear, then process each source of interrupt. */ 28809b77011eSTvrtko Ursulin gen11_gt_irq_handler(gt, master_ctl); 288151951ae7SMika Kuoppala 288251951ae7SMika Kuoppala /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 288351951ae7SMika Kuoppala if (master_ctl & GEN11_DISPLAY_IRQ) { 288451951ae7SMika Kuoppala const u32 disp_ctl = raw_reg_read(regs, GEN11_DISPLAY_INT_CTL); 288551951ae7SMika Kuoppala 28869102650fSDaniele Ceraolo Spurio disable_rpm_wakeref_asserts(&i915->runtime_pm); 288751951ae7SMika Kuoppala /* 288851951ae7SMika Kuoppala * GEN11_DISPLAY_INT_CTL has same format as GEN8_MASTER_IRQ 288951951ae7SMika Kuoppala * for the display related bits. 289051951ae7SMika Kuoppala */ 289151951ae7SMika Kuoppala gen8_de_irq_handler(i915, disp_ctl); 28929102650fSDaniele Ceraolo Spurio enable_rpm_wakeref_asserts(&i915->runtime_pm); 289351951ae7SMika Kuoppala } 289451951ae7SMika Kuoppala 28959b77011eSTvrtko Ursulin gu_misc_iir = gen11_gu_misc_irq_ack(gt, master_ctl); 2896df0d28c1SDhinakaran Pandiyan 289781067b71SMika Kuoppala gen11_master_intr_enable(regs); 289851951ae7SMika Kuoppala 28999b77011eSTvrtko Ursulin gen11_gu_misc_irq_handler(gt, gu_misc_iir); 2900df0d28c1SDhinakaran Pandiyan 290151951ae7SMika Kuoppala return IRQ_HANDLED; 290251951ae7SMika Kuoppala } 290351951ae7SMika Kuoppala 290442f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 290542f52ef8SKeith Packard * we use as a pipe index 290642f52ef8SKeith Packard */ 290708fa8fd0SVille Syrjälä int i8xx_enable_vblank(struct drm_crtc *crtc) 29080a3e67a4SJesse Barnes { 290908fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 291008fa8fd0SVille Syrjälä enum pipe pipe = to_intel_crtc(crtc)->pipe; 2911e9d21d7fSKeith Packard unsigned long irqflags; 291271e0ffa5SJesse Barnes 29131ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 291486e83e35SChris Wilson i915_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS); 291586e83e35SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 291686e83e35SChris Wilson 291786e83e35SChris Wilson return 0; 291886e83e35SChris Wilson } 291986e83e35SChris Wilson 29207d423af9SVille Syrjälä int i915gm_enable_vblank(struct drm_crtc *crtc) 2921d938da6bSVille Syrjälä { 292208fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 2923d938da6bSVille Syrjälä 29247d423af9SVille Syrjälä /* 29257d423af9SVille Syrjälä * Vblank interrupts fail to wake the device up from C2+. 29267d423af9SVille Syrjälä * Disabling render clock gating during C-states avoids 29277d423af9SVille Syrjälä * the problem. There is a small power cost so we do this 29287d423af9SVille Syrjälä * only when vblank interrupts are actually enabled. 29297d423af9SVille Syrjälä */ 29307d423af9SVille Syrjälä if (dev_priv->vblank_enabled++ == 0) 29317d423af9SVille Syrjälä I915_WRITE(SCPD0, _MASKED_BIT_ENABLE(CSTATE_RENDER_CLOCK_GATE_DISABLE)); 2932d938da6bSVille Syrjälä 293308fa8fd0SVille Syrjälä return i8xx_enable_vblank(crtc); 2934d938da6bSVille Syrjälä } 2935d938da6bSVille Syrjälä 293608fa8fd0SVille Syrjälä int i965_enable_vblank(struct drm_crtc *crtc) 293786e83e35SChris Wilson { 293808fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 293908fa8fd0SVille Syrjälä enum pipe pipe = to_intel_crtc(crtc)->pipe; 294086e83e35SChris Wilson unsigned long irqflags; 294186e83e35SChris Wilson 294286e83e35SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 29437c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 2944755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 29451ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 29468692d00eSChris Wilson 29470a3e67a4SJesse Barnes return 0; 29480a3e67a4SJesse Barnes } 29490a3e67a4SJesse Barnes 295008fa8fd0SVille Syrjälä int ilk_enable_vblank(struct drm_crtc *crtc) 2951f796cf8fSJesse Barnes { 295208fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 295308fa8fd0SVille Syrjälä enum pipe pipe = to_intel_crtc(crtc)->pipe; 2954f796cf8fSJesse Barnes unsigned long irqflags; 2955a9c287c9SJani Nikula u32 bit = INTEL_GEN(dev_priv) >= 7 ? 295686e83e35SChris Wilson DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe); 2957f796cf8fSJesse Barnes 2958f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2959fbdedaeaSVille Syrjälä ilk_enable_display_irq(dev_priv, bit); 2960b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2961b1f14ad0SJesse Barnes 29622e8bf223SDhinakaran Pandiyan /* Even though there is no DMC, frame counter can get stuck when 29632e8bf223SDhinakaran Pandiyan * PSR is active as no frames are generated. 29642e8bf223SDhinakaran Pandiyan */ 29652e8bf223SDhinakaran Pandiyan if (HAS_PSR(dev_priv)) 296608fa8fd0SVille Syrjälä drm_crtc_vblank_restore(crtc); 29672e8bf223SDhinakaran Pandiyan 2968b1f14ad0SJesse Barnes return 0; 2969b1f14ad0SJesse Barnes } 2970b1f14ad0SJesse Barnes 297108fa8fd0SVille Syrjälä int bdw_enable_vblank(struct drm_crtc *crtc) 2972abd58f01SBen Widawsky { 297308fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 297408fa8fd0SVille Syrjälä enum pipe pipe = to_intel_crtc(crtc)->pipe; 2975abd58f01SBen Widawsky unsigned long irqflags; 2976abd58f01SBen Widawsky 2977abd58f01SBen Widawsky spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2978013d3752SVille Syrjälä bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK); 2979abd58f01SBen Widawsky spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2980013d3752SVille Syrjälä 29812e8bf223SDhinakaran Pandiyan /* Even if there is no DMC, frame counter can get stuck when 29822e8bf223SDhinakaran Pandiyan * PSR is active as no frames are generated, so check only for PSR. 29832e8bf223SDhinakaran Pandiyan */ 29842e8bf223SDhinakaran Pandiyan if (HAS_PSR(dev_priv)) 298508fa8fd0SVille Syrjälä drm_crtc_vblank_restore(crtc); 29862e8bf223SDhinakaran Pandiyan 2987abd58f01SBen Widawsky return 0; 2988abd58f01SBen Widawsky } 2989abd58f01SBen Widawsky 299042f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 299142f52ef8SKeith Packard * we use as a pipe index 299242f52ef8SKeith Packard */ 299308fa8fd0SVille Syrjälä void i8xx_disable_vblank(struct drm_crtc *crtc) 299486e83e35SChris Wilson { 299508fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 299608fa8fd0SVille Syrjälä enum pipe pipe = to_intel_crtc(crtc)->pipe; 299786e83e35SChris Wilson unsigned long irqflags; 299886e83e35SChris Wilson 299986e83e35SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 300086e83e35SChris Wilson i915_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS); 300186e83e35SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 300286e83e35SChris Wilson } 300386e83e35SChris Wilson 30047d423af9SVille Syrjälä void i915gm_disable_vblank(struct drm_crtc *crtc) 3005d938da6bSVille Syrjälä { 300608fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 3007d938da6bSVille Syrjälä 300808fa8fd0SVille Syrjälä i8xx_disable_vblank(crtc); 3009d938da6bSVille Syrjälä 30107d423af9SVille Syrjälä if (--dev_priv->vblank_enabled == 0) 30117d423af9SVille Syrjälä I915_WRITE(SCPD0, _MASKED_BIT_DISABLE(CSTATE_RENDER_CLOCK_GATE_DISABLE)); 3012d938da6bSVille Syrjälä } 3013d938da6bSVille Syrjälä 301408fa8fd0SVille Syrjälä void i965_disable_vblank(struct drm_crtc *crtc) 30150a3e67a4SJesse Barnes { 301608fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 301708fa8fd0SVille Syrjälä enum pipe pipe = to_intel_crtc(crtc)->pipe; 3018e9d21d7fSKeith Packard unsigned long irqflags; 30190a3e67a4SJesse Barnes 30201ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 30217c463586SKeith Packard i915_disable_pipestat(dev_priv, pipe, 3022755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 30231ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 30240a3e67a4SJesse Barnes } 30250a3e67a4SJesse Barnes 302608fa8fd0SVille Syrjälä void ilk_disable_vblank(struct drm_crtc *crtc) 3027f796cf8fSJesse Barnes { 302808fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 302908fa8fd0SVille Syrjälä enum pipe pipe = to_intel_crtc(crtc)->pipe; 3030f796cf8fSJesse Barnes unsigned long irqflags; 3031a9c287c9SJani Nikula u32 bit = INTEL_GEN(dev_priv) >= 7 ? 303286e83e35SChris Wilson DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe); 3033f796cf8fSJesse Barnes 3034f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3035fbdedaeaSVille Syrjälä ilk_disable_display_irq(dev_priv, bit); 3036b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3037b1f14ad0SJesse Barnes } 3038b1f14ad0SJesse Barnes 303908fa8fd0SVille Syrjälä void bdw_disable_vblank(struct drm_crtc *crtc) 3040abd58f01SBen Widawsky { 304108fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 304208fa8fd0SVille Syrjälä enum pipe pipe = to_intel_crtc(crtc)->pipe; 3043abd58f01SBen Widawsky unsigned long irqflags; 3044abd58f01SBen Widawsky 3045abd58f01SBen Widawsky spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3046013d3752SVille Syrjälä bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK); 3047abd58f01SBen Widawsky spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3048abd58f01SBen Widawsky } 3049abd58f01SBen Widawsky 3050b243f530STvrtko Ursulin static void ibx_irq_reset(struct drm_i915_private *dev_priv) 305191738a95SPaulo Zanoni { 3052b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 3053b16b2a2fSPaulo Zanoni 30546e266956STvrtko Ursulin if (HAS_PCH_NOP(dev_priv)) 305591738a95SPaulo Zanoni return; 305691738a95SPaulo Zanoni 3057b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, SDE); 3058105b122eSPaulo Zanoni 30596e266956STvrtko Ursulin if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv)) 3060105b122eSPaulo Zanoni I915_WRITE(SERR_INT, 0xffffffff); 3061622364b6SPaulo Zanoni } 3062105b122eSPaulo Zanoni 306391738a95SPaulo Zanoni /* 3064622364b6SPaulo Zanoni * SDEIER is also touched by the interrupt handler to work around missed PCH 3065622364b6SPaulo Zanoni * interrupts. Hence we can't update it after the interrupt handler is enabled - 3066622364b6SPaulo Zanoni * instead we unconditionally enable all PCH interrupt sources here, but then 3067622364b6SPaulo Zanoni * only unmask them as needed with SDEIMR. 3068622364b6SPaulo Zanoni * 3069622364b6SPaulo Zanoni * This function needs to be called before interrupts are enabled. 307091738a95SPaulo Zanoni */ 3071b318b824SVille Syrjälä static void ibx_irq_pre_postinstall(struct drm_i915_private *dev_priv) 3072622364b6SPaulo Zanoni { 30736e266956STvrtko Ursulin if (HAS_PCH_NOP(dev_priv)) 3074622364b6SPaulo Zanoni return; 3075622364b6SPaulo Zanoni 3076622364b6SPaulo Zanoni WARN_ON(I915_READ(SDEIER) != 0); 307791738a95SPaulo Zanoni I915_WRITE(SDEIER, 0xffffffff); 307891738a95SPaulo Zanoni POSTING_READ(SDEIER); 307991738a95SPaulo Zanoni } 308091738a95SPaulo Zanoni 308170591a41SVille Syrjälä static void vlv_display_irq_reset(struct drm_i915_private *dev_priv) 308270591a41SVille Syrjälä { 3083b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 3084b16b2a2fSPaulo Zanoni 308571b8b41dSVille Syrjälä if (IS_CHERRYVIEW(dev_priv)) 3086f0818984STvrtko Ursulin intel_uncore_write(uncore, DPINVGTT, DPINVGTT_STATUS_MASK_CHV); 308771b8b41dSVille Syrjälä else 3088f0818984STvrtko Ursulin intel_uncore_write(uncore, DPINVGTT, DPINVGTT_STATUS_MASK); 308971b8b41dSVille Syrjälä 3090ad22d106SVille Syrjälä i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0); 3091f0818984STvrtko Ursulin intel_uncore_write(uncore, PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 309270591a41SVille Syrjälä 309344d9241eSVille Syrjälä i9xx_pipestat_irq_reset(dev_priv); 309470591a41SVille Syrjälä 3095b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, VLV_); 30968bd099a7SChris Wilson dev_priv->irq_mask = ~0u; 309770591a41SVille Syrjälä } 309870591a41SVille Syrjälä 30998bb61306SVille Syrjälä static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv) 31008bb61306SVille Syrjälä { 3101b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 3102b16b2a2fSPaulo Zanoni 31038bb61306SVille Syrjälä u32 pipestat_mask; 31049ab981f2SVille Syrjälä u32 enable_mask; 31058bb61306SVille Syrjälä enum pipe pipe; 31068bb61306SVille Syrjälä 3107842ebf7aSVille Syrjälä pipestat_mask = PIPE_CRC_DONE_INTERRUPT_STATUS; 31088bb61306SVille Syrjälä 31098bb61306SVille Syrjälä i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS); 31108bb61306SVille Syrjälä for_each_pipe(dev_priv, pipe) 31118bb61306SVille Syrjälä i915_enable_pipestat(dev_priv, pipe, pipestat_mask); 31128bb61306SVille Syrjälä 31139ab981f2SVille Syrjälä enable_mask = I915_DISPLAY_PORT_INTERRUPT | 31148bb61306SVille Syrjälä I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3115ebf5f921SVille Syrjälä I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3116ebf5f921SVille Syrjälä I915_LPE_PIPE_A_INTERRUPT | 3117ebf5f921SVille Syrjälä I915_LPE_PIPE_B_INTERRUPT; 3118ebf5f921SVille Syrjälä 31198bb61306SVille Syrjälä if (IS_CHERRYVIEW(dev_priv)) 3120ebf5f921SVille Syrjälä enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT | 3121ebf5f921SVille Syrjälä I915_LPE_PIPE_C_INTERRUPT; 31226b7eafc1SVille Syrjälä 31238bd099a7SChris Wilson WARN_ON(dev_priv->irq_mask != ~0u); 31246b7eafc1SVille Syrjälä 31259ab981f2SVille Syrjälä dev_priv->irq_mask = ~enable_mask; 31268bb61306SVille Syrjälä 3127b16b2a2fSPaulo Zanoni GEN3_IRQ_INIT(uncore, VLV_, dev_priv->irq_mask, enable_mask); 31288bb61306SVille Syrjälä } 31298bb61306SVille Syrjälä 31308bb61306SVille Syrjälä /* drm_dma.h hooks 31318bb61306SVille Syrjälä */ 3132b318b824SVille Syrjälä static void ironlake_irq_reset(struct drm_i915_private *dev_priv) 31338bb61306SVille Syrjälä { 3134b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 31358bb61306SVille Syrjälä 3136b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, DE); 3137cf819effSLucas De Marchi if (IS_GEN(dev_priv, 7)) 3138f0818984STvrtko Ursulin intel_uncore_write(uncore, GEN7_ERR_INT, 0xffffffff); 31398bb61306SVille Syrjälä 3140fc340442SDaniel Vetter if (IS_HASWELL(dev_priv)) { 3141f0818984STvrtko Ursulin intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff); 3142f0818984STvrtko Ursulin intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff); 3143fc340442SDaniel Vetter } 3144fc340442SDaniel Vetter 3145cf1c97dcSAndi Shyti gen5_gt_irq_reset(&dev_priv->gt); 31468bb61306SVille Syrjälä 3147b243f530STvrtko Ursulin ibx_irq_reset(dev_priv); 31488bb61306SVille Syrjälä } 31498bb61306SVille Syrjälä 3150b318b824SVille Syrjälä static void valleyview_irq_reset(struct drm_i915_private *dev_priv) 31517e231dbeSJesse Barnes { 315234c7b8a7SVille Syrjälä I915_WRITE(VLV_MASTER_IER, 0); 315334c7b8a7SVille Syrjälä POSTING_READ(VLV_MASTER_IER); 315434c7b8a7SVille Syrjälä 3155cf1c97dcSAndi Shyti gen5_gt_irq_reset(&dev_priv->gt); 31567e231dbeSJesse Barnes 3157ad22d106SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 31589918271eSVille Syrjälä if (dev_priv->display_irqs_enabled) 315970591a41SVille Syrjälä vlv_display_irq_reset(dev_priv); 3160ad22d106SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 31617e231dbeSJesse Barnes } 31627e231dbeSJesse Barnes 3163b318b824SVille Syrjälä static void gen8_irq_reset(struct drm_i915_private *dev_priv) 3164abd58f01SBen Widawsky { 3165b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 3166d048a268SVille Syrjälä enum pipe pipe; 3167abd58f01SBen Widawsky 316825286aacSDaniele Ceraolo Spurio gen8_master_intr_disable(dev_priv->uncore.regs); 3169abd58f01SBen Widawsky 3170cf1c97dcSAndi Shyti gen8_gt_irq_reset(&dev_priv->gt); 3171abd58f01SBen Widawsky 3172f0818984STvrtko Ursulin intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff); 3173f0818984STvrtko Ursulin intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff); 3174e04f7eceSVille Syrjälä 3175055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 3176f458ebbcSDaniel Vetter if (intel_display_power_is_enabled(dev_priv, 3177813bde43SPaulo Zanoni POWER_DOMAIN_PIPE(pipe))) 3178b16b2a2fSPaulo Zanoni GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe); 3179abd58f01SBen Widawsky 3180b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN8_DE_PORT_); 3181b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN8_DE_MISC_); 3182b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN8_PCU_); 3183abd58f01SBen Widawsky 31846e266956STvrtko Ursulin if (HAS_PCH_SPLIT(dev_priv)) 3185b243f530STvrtko Ursulin ibx_irq_reset(dev_priv); 3186abd58f01SBen Widawsky } 3187abd58f01SBen Widawsky 3188b318b824SVille Syrjälä static void gen11_irq_reset(struct drm_i915_private *dev_priv) 318951951ae7SMika Kuoppala { 3190b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 3191d048a268SVille Syrjälä enum pipe pipe; 319251951ae7SMika Kuoppala 319325286aacSDaniele Ceraolo Spurio gen11_master_intr_disable(dev_priv->uncore.regs); 319451951ae7SMika Kuoppala 31959b77011eSTvrtko Ursulin gen11_gt_irq_reset(&dev_priv->gt); 319651951ae7SMika Kuoppala 3197f0818984STvrtko Ursulin intel_uncore_write(uncore, GEN11_DISPLAY_INT_CTL, 0); 319851951ae7SMika Kuoppala 31998241cfbeSJosé Roberto de Souza if (INTEL_GEN(dev_priv) >= 12) { 32008241cfbeSJosé Roberto de Souza enum transcoder trans; 32018241cfbeSJosé Roberto de Souza 32028241cfbeSJosé Roberto de Souza for (trans = TRANSCODER_A; trans <= TRANSCODER_D; trans++) { 32038241cfbeSJosé Roberto de Souza enum intel_display_power_domain domain; 32048241cfbeSJosé Roberto de Souza 32058241cfbeSJosé Roberto de Souza domain = POWER_DOMAIN_TRANSCODER(trans); 32068241cfbeSJosé Roberto de Souza if (!intel_display_power_is_enabled(dev_priv, domain)) 32078241cfbeSJosé Roberto de Souza continue; 32088241cfbeSJosé Roberto de Souza 32098241cfbeSJosé Roberto de Souza intel_uncore_write(uncore, TRANS_PSR_IMR(trans), 0xffffffff); 32108241cfbeSJosé Roberto de Souza intel_uncore_write(uncore, TRANS_PSR_IIR(trans), 0xffffffff); 32118241cfbeSJosé Roberto de Souza } 32128241cfbeSJosé Roberto de Souza } else { 3213f0818984STvrtko Ursulin intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff); 3214f0818984STvrtko Ursulin intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff); 32158241cfbeSJosé Roberto de Souza } 321662819dfdSJosé Roberto de Souza 321751951ae7SMika Kuoppala for_each_pipe(dev_priv, pipe) 321851951ae7SMika Kuoppala if (intel_display_power_is_enabled(dev_priv, 321951951ae7SMika Kuoppala POWER_DOMAIN_PIPE(pipe))) 3220b16b2a2fSPaulo Zanoni GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe); 322151951ae7SMika Kuoppala 3222b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN8_DE_PORT_); 3223b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN8_DE_MISC_); 3224b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN11_DE_HPD_); 3225b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN11_GU_MISC_); 3226b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN8_PCU_); 322731604222SAnusha Srivatsa 322829b43ae2SRodrigo Vivi if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP) 3229b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, SDE); 323051951ae7SMika Kuoppala } 323151951ae7SMika Kuoppala 32324c6c03beSDamien Lespiau void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv, 3233001bd2cbSImre Deak u8 pipe_mask) 3234d49bdb0eSPaulo Zanoni { 3235b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 3236b16b2a2fSPaulo Zanoni 3237a9c287c9SJani Nikula u32 extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN; 32386831f3e3SVille Syrjälä enum pipe pipe; 3239d49bdb0eSPaulo Zanoni 324013321786SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 32419dfe2e3aSImre Deak 32429dfe2e3aSImre Deak if (!intel_irqs_enabled(dev_priv)) { 32439dfe2e3aSImre Deak spin_unlock_irq(&dev_priv->irq_lock); 32449dfe2e3aSImre Deak return; 32459dfe2e3aSImre Deak } 32469dfe2e3aSImre Deak 32476831f3e3SVille Syrjälä for_each_pipe_masked(dev_priv, pipe, pipe_mask) 3248b16b2a2fSPaulo Zanoni GEN8_IRQ_INIT_NDX(uncore, DE_PIPE, pipe, 32496831f3e3SVille Syrjälä dev_priv->de_irq_mask[pipe], 32506831f3e3SVille Syrjälä ~dev_priv->de_irq_mask[pipe] | extra_ier); 32519dfe2e3aSImre Deak 325213321786SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 3253d49bdb0eSPaulo Zanoni } 3254d49bdb0eSPaulo Zanoni 3255aae8ba84SVille Syrjälä void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv, 3256001bd2cbSImre Deak u8 pipe_mask) 3257aae8ba84SVille Syrjälä { 3258b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 32596831f3e3SVille Syrjälä enum pipe pipe; 32606831f3e3SVille Syrjälä 3261aae8ba84SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 32629dfe2e3aSImre Deak 32639dfe2e3aSImre Deak if (!intel_irqs_enabled(dev_priv)) { 32649dfe2e3aSImre Deak spin_unlock_irq(&dev_priv->irq_lock); 32659dfe2e3aSImre Deak return; 32669dfe2e3aSImre Deak } 32679dfe2e3aSImre Deak 32686831f3e3SVille Syrjälä for_each_pipe_masked(dev_priv, pipe, pipe_mask) 3269b16b2a2fSPaulo Zanoni GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe); 32709dfe2e3aSImre Deak 3271aae8ba84SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 3272aae8ba84SVille Syrjälä 3273aae8ba84SVille Syrjälä /* make sure we're done processing display irqs */ 3274315ca4c4SVille Syrjälä intel_synchronize_irq(dev_priv); 3275aae8ba84SVille Syrjälä } 3276aae8ba84SVille Syrjälä 3277b318b824SVille Syrjälä static void cherryview_irq_reset(struct drm_i915_private *dev_priv) 327843f328d7SVille Syrjälä { 3279b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 328043f328d7SVille Syrjälä 328143f328d7SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, 0); 328243f328d7SVille Syrjälä POSTING_READ(GEN8_MASTER_IRQ); 328343f328d7SVille Syrjälä 3284cf1c97dcSAndi Shyti gen8_gt_irq_reset(&dev_priv->gt); 328543f328d7SVille Syrjälä 3286b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN8_PCU_); 328743f328d7SVille Syrjälä 3288ad22d106SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 32899918271eSVille Syrjälä if (dev_priv->display_irqs_enabled) 329070591a41SVille Syrjälä vlv_display_irq_reset(dev_priv); 3291ad22d106SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 329243f328d7SVille Syrjälä } 329343f328d7SVille Syrjälä 329491d14251STvrtko Ursulin static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv, 329587a02106SVille Syrjälä const u32 hpd[HPD_NUM_PINS]) 329687a02106SVille Syrjälä { 329787a02106SVille Syrjälä struct intel_encoder *encoder; 329887a02106SVille Syrjälä u32 enabled_irqs = 0; 329987a02106SVille Syrjälä 330091c8a326SChris Wilson for_each_intel_encoder(&dev_priv->drm, encoder) 330187a02106SVille Syrjälä if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED) 330287a02106SVille Syrjälä enabled_irqs |= hpd[encoder->hpd_pin]; 330387a02106SVille Syrjälä 330487a02106SVille Syrjälä return enabled_irqs; 330587a02106SVille Syrjälä } 330687a02106SVille Syrjälä 33071a56b1a2SImre Deak static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv) 33081a56b1a2SImre Deak { 33091a56b1a2SImre Deak u32 hotplug; 33101a56b1a2SImre Deak 33111a56b1a2SImre Deak /* 33121a56b1a2SImre Deak * Enable digital hotplug on the PCH, and configure the DP short pulse 33131a56b1a2SImre Deak * duration to 2ms (which is the minimum in the Display Port spec). 33141a56b1a2SImre Deak * The pulse duration bits are reserved on LPT+. 33151a56b1a2SImre Deak */ 33161a56b1a2SImre Deak hotplug = I915_READ(PCH_PORT_HOTPLUG); 33171a56b1a2SImre Deak hotplug &= ~(PORTB_PULSE_DURATION_MASK | 33181a56b1a2SImre Deak PORTC_PULSE_DURATION_MASK | 33191a56b1a2SImre Deak PORTD_PULSE_DURATION_MASK); 33201a56b1a2SImre Deak hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms; 33211a56b1a2SImre Deak hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms; 33221a56b1a2SImre Deak hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms; 33231a56b1a2SImre Deak /* 33241a56b1a2SImre Deak * When CPU and PCH are on the same package, port A 33251a56b1a2SImre Deak * HPD must be enabled in both north and south. 33261a56b1a2SImre Deak */ 33271a56b1a2SImre Deak if (HAS_PCH_LPT_LP(dev_priv)) 33281a56b1a2SImre Deak hotplug |= PORTA_HOTPLUG_ENABLE; 33291a56b1a2SImre Deak I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 33301a56b1a2SImre Deak } 33311a56b1a2SImre Deak 333291d14251STvrtko Ursulin static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv) 333382a28bcfSDaniel Vetter { 33341a56b1a2SImre Deak u32 hotplug_irqs, enabled_irqs; 333582a28bcfSDaniel Vetter 333691d14251STvrtko Ursulin if (HAS_PCH_IBX(dev_priv)) { 3337fee884edSDaniel Vetter hotplug_irqs = SDE_HOTPLUG_MASK; 333891d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx); 333982a28bcfSDaniel Vetter } else { 3340fee884edSDaniel Vetter hotplug_irqs = SDE_HOTPLUG_MASK_CPT; 334191d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt); 334282a28bcfSDaniel Vetter } 334382a28bcfSDaniel Vetter 3344fee884edSDaniel Vetter ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); 334582a28bcfSDaniel Vetter 33461a56b1a2SImre Deak ibx_hpd_detection_setup(dev_priv); 33476dbf30ceSVille Syrjälä } 334826951cafSXiong Zhang 334952dfdba0SLucas De Marchi static void icp_hpd_detection_setup(struct drm_i915_private *dev_priv, 335052dfdba0SLucas De Marchi u32 ddi_hotplug_enable_mask, 335152dfdba0SLucas De Marchi u32 tc_hotplug_enable_mask) 335231604222SAnusha Srivatsa { 335331604222SAnusha Srivatsa u32 hotplug; 335431604222SAnusha Srivatsa 335531604222SAnusha Srivatsa hotplug = I915_READ(SHOTPLUG_CTL_DDI); 335652dfdba0SLucas De Marchi hotplug |= ddi_hotplug_enable_mask; 335731604222SAnusha Srivatsa I915_WRITE(SHOTPLUG_CTL_DDI, hotplug); 335831604222SAnusha Srivatsa 33598ef7e340SMatt Roper if (tc_hotplug_enable_mask) { 336031604222SAnusha Srivatsa hotplug = I915_READ(SHOTPLUG_CTL_TC); 336152dfdba0SLucas De Marchi hotplug |= tc_hotplug_enable_mask; 336231604222SAnusha Srivatsa I915_WRITE(SHOTPLUG_CTL_TC, hotplug); 336331604222SAnusha Srivatsa } 33648ef7e340SMatt Roper } 336531604222SAnusha Srivatsa 336640e98130SLucas De Marchi static void icp_hpd_irq_setup(struct drm_i915_private *dev_priv, 336740e98130SLucas De Marchi u32 sde_ddi_mask, u32 sde_tc_mask, 336840e98130SLucas De Marchi u32 ddi_enable_mask, u32 tc_enable_mask, 336940e98130SLucas De Marchi const u32 *pins) 337031604222SAnusha Srivatsa { 337131604222SAnusha Srivatsa u32 hotplug_irqs, enabled_irqs; 337231604222SAnusha Srivatsa 337340e98130SLucas De Marchi hotplug_irqs = sde_ddi_mask | sde_tc_mask; 337440e98130SLucas De Marchi enabled_irqs = intel_hpd_enabled_irqs(dev_priv, pins); 337531604222SAnusha Srivatsa 337631604222SAnusha Srivatsa ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); 337731604222SAnusha Srivatsa 337840e98130SLucas De Marchi icp_hpd_detection_setup(dev_priv, ddi_enable_mask, tc_enable_mask); 337952dfdba0SLucas De Marchi } 338052dfdba0SLucas De Marchi 338140e98130SLucas De Marchi /* 338240e98130SLucas De Marchi * EHL doesn't need most of gen11_hpd_irq_setup, it's handling only the 338340e98130SLucas De Marchi * equivalent of SDE. 338440e98130SLucas De Marchi */ 33858ef7e340SMatt Roper static void mcc_hpd_irq_setup(struct drm_i915_private *dev_priv) 33868ef7e340SMatt Roper { 338740e98130SLucas De Marchi icp_hpd_irq_setup(dev_priv, 338853448aedSVivek Kasireddy SDE_DDI_MASK_ICP, SDE_TC_HOTPLUG_ICP(PORT_TC1), 338953448aedSVivek Kasireddy ICP_DDI_HPD_ENABLE_MASK, ICP_TC_HPD_ENABLE(PORT_TC1), 3390d09ad3e7SMatt Roper hpd_icp); 339131604222SAnusha Srivatsa } 339231604222SAnusha Srivatsa 3393*943682e3SMatt Roper /* 3394*943682e3SMatt Roper * JSP behaves exactly the same as MCC above except that port C is mapped to 3395*943682e3SMatt Roper * the DDI-C pins instead of the TC1 pins. This means we should follow TGP's 3396*943682e3SMatt Roper * masks & tables rather than ICP's masks & tables. 3397*943682e3SMatt Roper */ 3398*943682e3SMatt Roper static void jsp_hpd_irq_setup(struct drm_i915_private *dev_priv) 3399*943682e3SMatt Roper { 3400*943682e3SMatt Roper icp_hpd_irq_setup(dev_priv, 3401*943682e3SMatt Roper SDE_DDI_MASK_TGP, 0, 3402*943682e3SMatt Roper TGP_DDI_HPD_ENABLE_MASK, 0, 3403*943682e3SMatt Roper hpd_tgp); 3404*943682e3SMatt Roper } 3405*943682e3SMatt Roper 3406121e758eSDhinakaran Pandiyan static void gen11_hpd_detection_setup(struct drm_i915_private *dev_priv) 3407121e758eSDhinakaran Pandiyan { 3408121e758eSDhinakaran Pandiyan u32 hotplug; 3409121e758eSDhinakaran Pandiyan 3410121e758eSDhinakaran Pandiyan hotplug = I915_READ(GEN11_TC_HOTPLUG_CTL); 3411121e758eSDhinakaran Pandiyan hotplug |= GEN11_HOTPLUG_CTL_ENABLE(PORT_TC1) | 3412121e758eSDhinakaran Pandiyan GEN11_HOTPLUG_CTL_ENABLE(PORT_TC2) | 3413121e758eSDhinakaran Pandiyan GEN11_HOTPLUG_CTL_ENABLE(PORT_TC3) | 3414121e758eSDhinakaran Pandiyan GEN11_HOTPLUG_CTL_ENABLE(PORT_TC4); 3415121e758eSDhinakaran Pandiyan I915_WRITE(GEN11_TC_HOTPLUG_CTL, hotplug); 3416b796b971SDhinakaran Pandiyan 3417b796b971SDhinakaran Pandiyan hotplug = I915_READ(GEN11_TBT_HOTPLUG_CTL); 3418b796b971SDhinakaran Pandiyan hotplug |= GEN11_HOTPLUG_CTL_ENABLE(PORT_TC1) | 3419b796b971SDhinakaran Pandiyan GEN11_HOTPLUG_CTL_ENABLE(PORT_TC2) | 3420b796b971SDhinakaran Pandiyan GEN11_HOTPLUG_CTL_ENABLE(PORT_TC3) | 3421b796b971SDhinakaran Pandiyan GEN11_HOTPLUG_CTL_ENABLE(PORT_TC4); 3422b796b971SDhinakaran Pandiyan I915_WRITE(GEN11_TBT_HOTPLUG_CTL, hotplug); 3423121e758eSDhinakaran Pandiyan } 3424121e758eSDhinakaran Pandiyan 3425121e758eSDhinakaran Pandiyan static void gen11_hpd_irq_setup(struct drm_i915_private *dev_priv) 3426121e758eSDhinakaran Pandiyan { 3427121e758eSDhinakaran Pandiyan u32 hotplug_irqs, enabled_irqs; 342848ef15d3SJosé Roberto de Souza const u32 *hpd; 3429121e758eSDhinakaran Pandiyan u32 val; 3430121e758eSDhinakaran Pandiyan 343148ef15d3SJosé Roberto de Souza hpd = INTEL_GEN(dev_priv) >= 12 ? hpd_gen12 : hpd_gen11; 343248ef15d3SJosé Roberto de Souza enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd); 3433b796b971SDhinakaran Pandiyan hotplug_irqs = GEN11_DE_TC_HOTPLUG_MASK | GEN11_DE_TBT_HOTPLUG_MASK; 3434121e758eSDhinakaran Pandiyan 3435121e758eSDhinakaran Pandiyan val = I915_READ(GEN11_DE_HPD_IMR); 3436121e758eSDhinakaran Pandiyan val &= ~hotplug_irqs; 3437121e758eSDhinakaran Pandiyan I915_WRITE(GEN11_DE_HPD_IMR, val); 3438121e758eSDhinakaran Pandiyan POSTING_READ(GEN11_DE_HPD_IMR); 3439121e758eSDhinakaran Pandiyan 3440121e758eSDhinakaran Pandiyan gen11_hpd_detection_setup(dev_priv); 344131604222SAnusha Srivatsa 344252dfdba0SLucas De Marchi if (INTEL_PCH_TYPE(dev_priv) >= PCH_TGP) 344340e98130SLucas De Marchi icp_hpd_irq_setup(dev_priv, SDE_DDI_MASK_TGP, SDE_TC_MASK_TGP, 344440e98130SLucas De Marchi TGP_DDI_HPD_ENABLE_MASK, 344540e98130SLucas De Marchi TGP_TC_HPD_ENABLE_MASK, hpd_tgp); 344652dfdba0SLucas De Marchi else if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP) 344740e98130SLucas De Marchi icp_hpd_irq_setup(dev_priv, SDE_DDI_MASK_ICP, SDE_TC_MASK_ICP, 344840e98130SLucas De Marchi ICP_DDI_HPD_ENABLE_MASK, 344940e98130SLucas De Marchi ICP_TC_HPD_ENABLE_MASK, hpd_icp); 3450121e758eSDhinakaran Pandiyan } 3451121e758eSDhinakaran Pandiyan 34522a57d9ccSImre Deak static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv) 34532a57d9ccSImre Deak { 34543b92e263SRodrigo Vivi u32 val, hotplug; 34553b92e263SRodrigo Vivi 34563b92e263SRodrigo Vivi /* Display WA #1179 WaHardHangonHotPlug: cnp */ 34573b92e263SRodrigo Vivi if (HAS_PCH_CNP(dev_priv)) { 34583b92e263SRodrigo Vivi val = I915_READ(SOUTH_CHICKEN1); 34593b92e263SRodrigo Vivi val &= ~CHASSIS_CLK_REQ_DURATION_MASK; 34603b92e263SRodrigo Vivi val |= CHASSIS_CLK_REQ_DURATION(0xf); 34613b92e263SRodrigo Vivi I915_WRITE(SOUTH_CHICKEN1, val); 34623b92e263SRodrigo Vivi } 34632a57d9ccSImre Deak 34642a57d9ccSImre Deak /* Enable digital hotplug on the PCH */ 34652a57d9ccSImre Deak hotplug = I915_READ(PCH_PORT_HOTPLUG); 34662a57d9ccSImre Deak hotplug |= PORTA_HOTPLUG_ENABLE | 34672a57d9ccSImre Deak PORTB_HOTPLUG_ENABLE | 34682a57d9ccSImre Deak PORTC_HOTPLUG_ENABLE | 34692a57d9ccSImre Deak PORTD_HOTPLUG_ENABLE; 34702a57d9ccSImre Deak I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 34712a57d9ccSImre Deak 34722a57d9ccSImre Deak hotplug = I915_READ(PCH_PORT_HOTPLUG2); 34732a57d9ccSImre Deak hotplug |= PORTE_HOTPLUG_ENABLE; 34742a57d9ccSImre Deak I915_WRITE(PCH_PORT_HOTPLUG2, hotplug); 34752a57d9ccSImre Deak } 34762a57d9ccSImre Deak 347791d14251STvrtko Ursulin static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv) 34786dbf30ceSVille Syrjälä { 34792a57d9ccSImre Deak u32 hotplug_irqs, enabled_irqs; 34806dbf30ceSVille Syrjälä 34816dbf30ceSVille Syrjälä hotplug_irqs = SDE_HOTPLUG_MASK_SPT; 348291d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt); 34836dbf30ceSVille Syrjälä 34846dbf30ceSVille Syrjälä ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); 34856dbf30ceSVille Syrjälä 34862a57d9ccSImre Deak spt_hpd_detection_setup(dev_priv); 348726951cafSXiong Zhang } 34887fe0b973SKeith Packard 34891a56b1a2SImre Deak static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv) 34901a56b1a2SImre Deak { 34911a56b1a2SImre Deak u32 hotplug; 34921a56b1a2SImre Deak 34931a56b1a2SImre Deak /* 34941a56b1a2SImre Deak * Enable digital hotplug on the CPU, and configure the DP short pulse 34951a56b1a2SImre Deak * duration to 2ms (which is the minimum in the Display Port spec) 34961a56b1a2SImre Deak * The pulse duration bits are reserved on HSW+. 34971a56b1a2SImre Deak */ 34981a56b1a2SImre Deak hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL); 34991a56b1a2SImre Deak hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK; 35001a56b1a2SImre Deak hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE | 35011a56b1a2SImre Deak DIGITAL_PORTA_PULSE_DURATION_2ms; 35021a56b1a2SImre Deak I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug); 35031a56b1a2SImre Deak } 35041a56b1a2SImre Deak 350591d14251STvrtko Ursulin static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv) 3506e4ce95aaSVille Syrjälä { 35071a56b1a2SImre Deak u32 hotplug_irqs, enabled_irqs; 3508e4ce95aaSVille Syrjälä 350991d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 8) { 35103a3b3c7dSVille Syrjälä hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG; 351191d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw); 35123a3b3c7dSVille Syrjälä 35133a3b3c7dSVille Syrjälä bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs); 351491d14251STvrtko Ursulin } else if (INTEL_GEN(dev_priv) >= 7) { 351523bb4cb5SVille Syrjälä hotplug_irqs = DE_DP_A_HOTPLUG_IVB; 351691d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb); 35173a3b3c7dSVille Syrjälä 35183a3b3c7dSVille Syrjälä ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs); 351923bb4cb5SVille Syrjälä } else { 3520e4ce95aaSVille Syrjälä hotplug_irqs = DE_DP_A_HOTPLUG; 352191d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk); 3522e4ce95aaSVille Syrjälä 3523e4ce95aaSVille Syrjälä ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs); 35243a3b3c7dSVille Syrjälä } 3525e4ce95aaSVille Syrjälä 35261a56b1a2SImre Deak ilk_hpd_detection_setup(dev_priv); 3527e4ce95aaSVille Syrjälä 352891d14251STvrtko Ursulin ibx_hpd_irq_setup(dev_priv); 3529e4ce95aaSVille Syrjälä } 3530e4ce95aaSVille Syrjälä 35312a57d9ccSImre Deak static void __bxt_hpd_detection_setup(struct drm_i915_private *dev_priv, 35322a57d9ccSImre Deak u32 enabled_irqs) 3533e0a20ad7SShashank Sharma { 35342a57d9ccSImre Deak u32 hotplug; 3535e0a20ad7SShashank Sharma 3536a52bb15bSVille Syrjälä hotplug = I915_READ(PCH_PORT_HOTPLUG); 35372a57d9ccSImre Deak hotplug |= PORTA_HOTPLUG_ENABLE | 35382a57d9ccSImre Deak PORTB_HOTPLUG_ENABLE | 35392a57d9ccSImre Deak PORTC_HOTPLUG_ENABLE; 3540d252bf68SShubhangi Shrivastava 3541d252bf68SShubhangi Shrivastava DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n", 3542d252bf68SShubhangi Shrivastava hotplug, enabled_irqs); 3543d252bf68SShubhangi Shrivastava hotplug &= ~BXT_DDI_HPD_INVERT_MASK; 3544d252bf68SShubhangi Shrivastava 3545d252bf68SShubhangi Shrivastava /* 3546d252bf68SShubhangi Shrivastava * For BXT invert bit has to be set based on AOB design 3547d252bf68SShubhangi Shrivastava * for HPD detection logic, update it based on VBT fields. 3548d252bf68SShubhangi Shrivastava */ 3549d252bf68SShubhangi Shrivastava if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) && 3550d252bf68SShubhangi Shrivastava intel_bios_is_port_hpd_inverted(dev_priv, PORT_A)) 3551d252bf68SShubhangi Shrivastava hotplug |= BXT_DDIA_HPD_INVERT; 3552d252bf68SShubhangi Shrivastava if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) && 3553d252bf68SShubhangi Shrivastava intel_bios_is_port_hpd_inverted(dev_priv, PORT_B)) 3554d252bf68SShubhangi Shrivastava hotplug |= BXT_DDIB_HPD_INVERT; 3555d252bf68SShubhangi Shrivastava if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) && 3556d252bf68SShubhangi Shrivastava intel_bios_is_port_hpd_inverted(dev_priv, PORT_C)) 3557d252bf68SShubhangi Shrivastava hotplug |= BXT_DDIC_HPD_INVERT; 3558d252bf68SShubhangi Shrivastava 3559a52bb15bSVille Syrjälä I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 3560e0a20ad7SShashank Sharma } 3561e0a20ad7SShashank Sharma 35622a57d9ccSImre Deak static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv) 35632a57d9ccSImre Deak { 35642a57d9ccSImre Deak __bxt_hpd_detection_setup(dev_priv, BXT_DE_PORT_HOTPLUG_MASK); 35652a57d9ccSImre Deak } 35662a57d9ccSImre Deak 35672a57d9ccSImre Deak static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv) 35682a57d9ccSImre Deak { 35692a57d9ccSImre Deak u32 hotplug_irqs, enabled_irqs; 35702a57d9ccSImre Deak 35712a57d9ccSImre Deak enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt); 35722a57d9ccSImre Deak hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK; 35732a57d9ccSImre Deak 35742a57d9ccSImre Deak bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs); 35752a57d9ccSImre Deak 35762a57d9ccSImre Deak __bxt_hpd_detection_setup(dev_priv, enabled_irqs); 35772a57d9ccSImre Deak } 35782a57d9ccSImre Deak 3579b318b824SVille Syrjälä static void ibx_irq_postinstall(struct drm_i915_private *dev_priv) 3580d46da437SPaulo Zanoni { 358182a28bcfSDaniel Vetter u32 mask; 3582d46da437SPaulo Zanoni 35836e266956STvrtko Ursulin if (HAS_PCH_NOP(dev_priv)) 3584692a04cfSDaniel Vetter return; 3585692a04cfSDaniel Vetter 35866e266956STvrtko Ursulin if (HAS_PCH_IBX(dev_priv)) 35875c673b60SDaniel Vetter mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON; 35884ebc6509SDhinakaran Pandiyan else if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv)) 35895c673b60SDaniel Vetter mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT; 35904ebc6509SDhinakaran Pandiyan else 35914ebc6509SDhinakaran Pandiyan mask = SDE_GMBUS_CPT; 35928664281bSPaulo Zanoni 359365f42cdcSPaulo Zanoni gen3_assert_iir_is_zero(&dev_priv->uncore, SDEIIR); 3594d46da437SPaulo Zanoni I915_WRITE(SDEIMR, ~mask); 35952a57d9ccSImre Deak 35962a57d9ccSImre Deak if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) || 35972a57d9ccSImre Deak HAS_PCH_LPT(dev_priv)) 35981a56b1a2SImre Deak ibx_hpd_detection_setup(dev_priv); 35992a57d9ccSImre Deak else 36002a57d9ccSImre Deak spt_hpd_detection_setup(dev_priv); 3601d46da437SPaulo Zanoni } 3602d46da437SPaulo Zanoni 3603b318b824SVille Syrjälä static void ironlake_irq_postinstall(struct drm_i915_private *dev_priv) 3604036a4a7dSZhenyu Wang { 3605b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 36068e76f8dcSPaulo Zanoni u32 display_mask, extra_mask; 36078e76f8dcSPaulo Zanoni 3608b243f530STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 7) { 36098e76f8dcSPaulo Zanoni display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | 3610842ebf7aSVille Syrjälä DE_PCH_EVENT_IVB | DE_AUX_CHANNEL_A_IVB); 36118e76f8dcSPaulo Zanoni extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB | 361223bb4cb5SVille Syrjälä DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB | 361323bb4cb5SVille Syrjälä DE_DP_A_HOTPLUG_IVB); 36148e76f8dcSPaulo Zanoni } else { 36158e76f8dcSPaulo Zanoni display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | 3616842ebf7aSVille Syrjälä DE_AUX_CHANNEL_A | DE_PIPEB_CRC_DONE | 3617842ebf7aSVille Syrjälä DE_PIPEA_CRC_DONE | DE_POISON); 3618e4ce95aaSVille Syrjälä extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT | 3619e4ce95aaSVille Syrjälä DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN | 3620e4ce95aaSVille Syrjälä DE_DP_A_HOTPLUG); 36218e76f8dcSPaulo Zanoni } 3622036a4a7dSZhenyu Wang 3623fc340442SDaniel Vetter if (IS_HASWELL(dev_priv)) { 3624b16b2a2fSPaulo Zanoni gen3_assert_iir_is_zero(uncore, EDP_PSR_IIR); 3625fc340442SDaniel Vetter display_mask |= DE_EDP_PSR_INT_HSW; 3626fc340442SDaniel Vetter } 3627fc340442SDaniel Vetter 36281ec14ad3SChris Wilson dev_priv->irq_mask = ~display_mask; 3629036a4a7dSZhenyu Wang 3630b318b824SVille Syrjälä ibx_irq_pre_postinstall(dev_priv); 3631622364b6SPaulo Zanoni 3632b16b2a2fSPaulo Zanoni GEN3_IRQ_INIT(uncore, DE, dev_priv->irq_mask, 3633b16b2a2fSPaulo Zanoni display_mask | extra_mask); 3634036a4a7dSZhenyu Wang 3635cf1c97dcSAndi Shyti gen5_gt_irq_postinstall(&dev_priv->gt); 3636036a4a7dSZhenyu Wang 36371a56b1a2SImre Deak ilk_hpd_detection_setup(dev_priv); 36381a56b1a2SImre Deak 3639b318b824SVille Syrjälä ibx_irq_postinstall(dev_priv); 36407fe0b973SKeith Packard 364150a0bc90STvrtko Ursulin if (IS_IRONLAKE_M(dev_priv)) { 36426005ce42SDaniel Vetter /* Enable PCU event interrupts 36436005ce42SDaniel Vetter * 36446005ce42SDaniel Vetter * spinlocking not required here for correctness since interrupt 36454bc9d430SDaniel Vetter * setup is guaranteed to run in single-threaded context. But we 36464bc9d430SDaniel Vetter * need it to make the assert_spin_locked happy. */ 3647d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 3648fbdedaeaSVille Syrjälä ilk_enable_display_irq(dev_priv, DE_PCU_EVENT); 3649d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 3650f97108d1SJesse Barnes } 3651036a4a7dSZhenyu Wang } 3652036a4a7dSZhenyu Wang 3653f8b79e58SImre Deak void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv) 3654f8b79e58SImre Deak { 365567520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 3656f8b79e58SImre Deak 3657f8b79e58SImre Deak if (dev_priv->display_irqs_enabled) 3658f8b79e58SImre Deak return; 3659f8b79e58SImre Deak 3660f8b79e58SImre Deak dev_priv->display_irqs_enabled = true; 3661f8b79e58SImre Deak 3662d6c69803SVille Syrjälä if (intel_irqs_enabled(dev_priv)) { 3663d6c69803SVille Syrjälä vlv_display_irq_reset(dev_priv); 3664ad22d106SVille Syrjälä vlv_display_irq_postinstall(dev_priv); 3665f8b79e58SImre Deak } 3666d6c69803SVille Syrjälä } 3667f8b79e58SImre Deak 3668f8b79e58SImre Deak void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv) 3669f8b79e58SImre Deak { 367067520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 3671f8b79e58SImre Deak 3672f8b79e58SImre Deak if (!dev_priv->display_irqs_enabled) 3673f8b79e58SImre Deak return; 3674f8b79e58SImre Deak 3675f8b79e58SImre Deak dev_priv->display_irqs_enabled = false; 3676f8b79e58SImre Deak 3677950eabafSImre Deak if (intel_irqs_enabled(dev_priv)) 3678ad22d106SVille Syrjälä vlv_display_irq_reset(dev_priv); 3679f8b79e58SImre Deak } 3680f8b79e58SImre Deak 36810e6c9a9eSVille Syrjälä 3682b318b824SVille Syrjälä static void valleyview_irq_postinstall(struct drm_i915_private *dev_priv) 36830e6c9a9eSVille Syrjälä { 3684cf1c97dcSAndi Shyti gen5_gt_irq_postinstall(&dev_priv->gt); 36857e231dbeSJesse Barnes 3686ad22d106SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 36879918271eSVille Syrjälä if (dev_priv->display_irqs_enabled) 3688ad22d106SVille Syrjälä vlv_display_irq_postinstall(dev_priv); 3689ad22d106SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 3690ad22d106SVille Syrjälä 36917e231dbeSJesse Barnes I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE); 369234c7b8a7SVille Syrjälä POSTING_READ(VLV_MASTER_IER); 369320afbda2SDaniel Vetter } 369420afbda2SDaniel Vetter 3695abd58f01SBen Widawsky static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv) 3696abd58f01SBen Widawsky { 3697b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 3698b16b2a2fSPaulo Zanoni 3699a9c287c9SJani Nikula u32 de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE; 3700a9c287c9SJani Nikula u32 de_pipe_enables; 37013a3b3c7dSVille Syrjälä u32 de_port_masked = GEN8_AUX_CHANNEL_A; 37023a3b3c7dSVille Syrjälä u32 de_port_enables; 3703df0d28c1SDhinakaran Pandiyan u32 de_misc_masked = GEN8_DE_EDP_PSR; 37043a3b3c7dSVille Syrjälä enum pipe pipe; 3705770de83dSDamien Lespiau 3706df0d28c1SDhinakaran Pandiyan if (INTEL_GEN(dev_priv) <= 10) 3707df0d28c1SDhinakaran Pandiyan de_misc_masked |= GEN8_DE_MISC_GSE; 3708df0d28c1SDhinakaran Pandiyan 3709bca2bf2aSPandiyan, Dhinakaran if (INTEL_GEN(dev_priv) >= 9) { 3710842ebf7aSVille Syrjälä de_pipe_masked |= GEN9_DE_PIPE_IRQ_FAULT_ERRORS; 37113a3b3c7dSVille Syrjälä de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C | 371288e04703SJesse Barnes GEN9_AUX_CHANNEL_D; 3713cc3f90f0SAnder Conselvan de Oliveira if (IS_GEN9_LP(dev_priv)) 37143a3b3c7dSVille Syrjälä de_port_masked |= BXT_DE_PORT_GMBUS; 37153a3b3c7dSVille Syrjälä } else { 3716842ebf7aSVille Syrjälä de_pipe_masked |= GEN8_DE_PIPE_IRQ_FAULT_ERRORS; 37173a3b3c7dSVille Syrjälä } 3718770de83dSDamien Lespiau 3719bb187e93SJames Ausmus if (INTEL_GEN(dev_priv) >= 11) 3720bb187e93SJames Ausmus de_port_masked |= ICL_AUX_CHANNEL_E; 3721bb187e93SJames Ausmus 37229bb635d9SDhinakaran Pandiyan if (IS_CNL_WITH_PORT_F(dev_priv) || INTEL_GEN(dev_priv) >= 11) 3723a324fcacSRodrigo Vivi de_port_masked |= CNL_AUX_CHANNEL_F; 3724a324fcacSRodrigo Vivi 3725770de83dSDamien Lespiau de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK | 3726770de83dSDamien Lespiau GEN8_PIPE_FIFO_UNDERRUN; 3727770de83dSDamien Lespiau 37283a3b3c7dSVille Syrjälä de_port_enables = de_port_masked; 3729cc3f90f0SAnder Conselvan de Oliveira if (IS_GEN9_LP(dev_priv)) 3730a52bb15bSVille Syrjälä de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK; 3731a52bb15bSVille Syrjälä else if (IS_BROADWELL(dev_priv)) 37323a3b3c7dSVille Syrjälä de_port_enables |= GEN8_PORT_DP_A_HOTPLUG; 37333a3b3c7dSVille Syrjälä 37348241cfbeSJosé Roberto de Souza if (INTEL_GEN(dev_priv) >= 12) { 37358241cfbeSJosé Roberto de Souza enum transcoder trans; 37368241cfbeSJosé Roberto de Souza 37378241cfbeSJosé Roberto de Souza for (trans = TRANSCODER_A; trans <= TRANSCODER_D; trans++) { 37388241cfbeSJosé Roberto de Souza enum intel_display_power_domain domain; 37398241cfbeSJosé Roberto de Souza 37408241cfbeSJosé Roberto de Souza domain = POWER_DOMAIN_TRANSCODER(trans); 37418241cfbeSJosé Roberto de Souza if (!intel_display_power_is_enabled(dev_priv, domain)) 37428241cfbeSJosé Roberto de Souza continue; 37438241cfbeSJosé Roberto de Souza 37448241cfbeSJosé Roberto de Souza gen3_assert_iir_is_zero(uncore, TRANS_PSR_IIR(trans)); 37458241cfbeSJosé Roberto de Souza } 37468241cfbeSJosé Roberto de Souza } else { 3747b16b2a2fSPaulo Zanoni gen3_assert_iir_is_zero(uncore, EDP_PSR_IIR); 37488241cfbeSJosé Roberto de Souza } 3749e04f7eceSVille Syrjälä 37500a195c02SMika Kahola for_each_pipe(dev_priv, pipe) { 37510a195c02SMika Kahola dev_priv->de_irq_mask[pipe] = ~de_pipe_masked; 3752abd58f01SBen Widawsky 3753f458ebbcSDaniel Vetter if (intel_display_power_is_enabled(dev_priv, 3754813bde43SPaulo Zanoni POWER_DOMAIN_PIPE(pipe))) 3755b16b2a2fSPaulo Zanoni GEN8_IRQ_INIT_NDX(uncore, DE_PIPE, pipe, 3756813bde43SPaulo Zanoni dev_priv->de_irq_mask[pipe], 375735079899SPaulo Zanoni de_pipe_enables); 37580a195c02SMika Kahola } 3759abd58f01SBen Widawsky 3760b16b2a2fSPaulo Zanoni GEN3_IRQ_INIT(uncore, GEN8_DE_PORT_, ~de_port_masked, de_port_enables); 3761b16b2a2fSPaulo Zanoni GEN3_IRQ_INIT(uncore, GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked); 37622a57d9ccSImre Deak 3763121e758eSDhinakaran Pandiyan if (INTEL_GEN(dev_priv) >= 11) { 3764121e758eSDhinakaran Pandiyan u32 de_hpd_masked = 0; 3765b796b971SDhinakaran Pandiyan u32 de_hpd_enables = GEN11_DE_TC_HOTPLUG_MASK | 3766b796b971SDhinakaran Pandiyan GEN11_DE_TBT_HOTPLUG_MASK; 3767121e758eSDhinakaran Pandiyan 3768b16b2a2fSPaulo Zanoni GEN3_IRQ_INIT(uncore, GEN11_DE_HPD_, ~de_hpd_masked, 3769b16b2a2fSPaulo Zanoni de_hpd_enables); 3770121e758eSDhinakaran Pandiyan gen11_hpd_detection_setup(dev_priv); 3771121e758eSDhinakaran Pandiyan } else if (IS_GEN9_LP(dev_priv)) { 37722a57d9ccSImre Deak bxt_hpd_detection_setup(dev_priv); 3773121e758eSDhinakaran Pandiyan } else if (IS_BROADWELL(dev_priv)) { 37741a56b1a2SImre Deak ilk_hpd_detection_setup(dev_priv); 3775abd58f01SBen Widawsky } 3776121e758eSDhinakaran Pandiyan } 3777abd58f01SBen Widawsky 3778b318b824SVille Syrjälä static void gen8_irq_postinstall(struct drm_i915_private *dev_priv) 3779abd58f01SBen Widawsky { 37806e266956STvrtko Ursulin if (HAS_PCH_SPLIT(dev_priv)) 3781b318b824SVille Syrjälä ibx_irq_pre_postinstall(dev_priv); 3782622364b6SPaulo Zanoni 3783cf1c97dcSAndi Shyti gen8_gt_irq_postinstall(&dev_priv->gt); 3784abd58f01SBen Widawsky gen8_de_irq_postinstall(dev_priv); 3785abd58f01SBen Widawsky 37866e266956STvrtko Ursulin if (HAS_PCH_SPLIT(dev_priv)) 3787b318b824SVille Syrjälä ibx_irq_postinstall(dev_priv); 3788abd58f01SBen Widawsky 378925286aacSDaniele Ceraolo Spurio gen8_master_intr_enable(dev_priv->uncore.regs); 3790abd58f01SBen Widawsky } 3791abd58f01SBen Widawsky 3792b318b824SVille Syrjälä static void icp_irq_postinstall(struct drm_i915_private *dev_priv) 379331604222SAnusha Srivatsa { 379431604222SAnusha Srivatsa u32 mask = SDE_GMBUS_ICP; 379531604222SAnusha Srivatsa 379631604222SAnusha Srivatsa WARN_ON(I915_READ(SDEIER) != 0); 379731604222SAnusha Srivatsa I915_WRITE(SDEIER, 0xffffffff); 379831604222SAnusha Srivatsa POSTING_READ(SDEIER); 379931604222SAnusha Srivatsa 380065f42cdcSPaulo Zanoni gen3_assert_iir_is_zero(&dev_priv->uncore, SDEIIR); 380131604222SAnusha Srivatsa I915_WRITE(SDEIMR, ~mask); 380231604222SAnusha Srivatsa 380352dfdba0SLucas De Marchi if (HAS_PCH_TGP(dev_priv)) 380452dfdba0SLucas De Marchi icp_hpd_detection_setup(dev_priv, TGP_DDI_HPD_ENABLE_MASK, 380552dfdba0SLucas De Marchi TGP_TC_HPD_ENABLE_MASK); 38068ef7e340SMatt Roper else if (HAS_PCH_MCC(dev_priv)) 38078ef7e340SMatt Roper icp_hpd_detection_setup(dev_priv, TGP_DDI_HPD_ENABLE_MASK, 0); 380852dfdba0SLucas De Marchi else 380952dfdba0SLucas De Marchi icp_hpd_detection_setup(dev_priv, ICP_DDI_HPD_ENABLE_MASK, 381052dfdba0SLucas De Marchi ICP_TC_HPD_ENABLE_MASK); 381131604222SAnusha Srivatsa } 381231604222SAnusha Srivatsa 3813b318b824SVille Syrjälä static void gen11_irq_postinstall(struct drm_i915_private *dev_priv) 381451951ae7SMika Kuoppala { 3815b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 3816df0d28c1SDhinakaran Pandiyan u32 gu_misc_masked = GEN11_GU_MISC_GSE; 381751951ae7SMika Kuoppala 381829b43ae2SRodrigo Vivi if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP) 3819b318b824SVille Syrjälä icp_irq_postinstall(dev_priv); 382031604222SAnusha Srivatsa 38219b77011eSTvrtko Ursulin gen11_gt_irq_postinstall(&dev_priv->gt); 382251951ae7SMika Kuoppala gen8_de_irq_postinstall(dev_priv); 382351951ae7SMika Kuoppala 3824b16b2a2fSPaulo Zanoni GEN3_IRQ_INIT(uncore, GEN11_GU_MISC_, ~gu_misc_masked, gu_misc_masked); 3825df0d28c1SDhinakaran Pandiyan 382651951ae7SMika Kuoppala I915_WRITE(GEN11_DISPLAY_INT_CTL, GEN11_DISPLAY_IRQ_ENABLE); 382751951ae7SMika Kuoppala 38289b77011eSTvrtko Ursulin gen11_master_intr_enable(uncore->regs); 3829c25f0c6aSDaniele Ceraolo Spurio POSTING_READ(GEN11_GFX_MSTR_IRQ); 383051951ae7SMika Kuoppala } 383151951ae7SMika Kuoppala 3832b318b824SVille Syrjälä static void cherryview_irq_postinstall(struct drm_i915_private *dev_priv) 383343f328d7SVille Syrjälä { 3834cf1c97dcSAndi Shyti gen8_gt_irq_postinstall(&dev_priv->gt); 383543f328d7SVille Syrjälä 3836ad22d106SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 38379918271eSVille Syrjälä if (dev_priv->display_irqs_enabled) 3838ad22d106SVille Syrjälä vlv_display_irq_postinstall(dev_priv); 3839ad22d106SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 3840ad22d106SVille Syrjälä 3841e5328c43SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); 384243f328d7SVille Syrjälä POSTING_READ(GEN8_MASTER_IRQ); 384343f328d7SVille Syrjälä } 384443f328d7SVille Syrjälä 3845b318b824SVille Syrjälä static void i8xx_irq_reset(struct drm_i915_private *dev_priv) 3846c2798b19SChris Wilson { 3847b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 3848c2798b19SChris Wilson 384944d9241eSVille Syrjälä i9xx_pipestat_irq_reset(dev_priv); 385044d9241eSVille Syrjälä 3851b16b2a2fSPaulo Zanoni GEN2_IRQ_RESET(uncore); 3852c2798b19SChris Wilson } 3853c2798b19SChris Wilson 3854b318b824SVille Syrjälä static void i8xx_irq_postinstall(struct drm_i915_private *dev_priv) 3855c2798b19SChris Wilson { 3856b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 3857e9e9848aSVille Syrjälä u16 enable_mask; 3858c2798b19SChris Wilson 38594f5fd91fSTvrtko Ursulin intel_uncore_write16(uncore, 38604f5fd91fSTvrtko Ursulin EMR, 38614f5fd91fSTvrtko Ursulin ~(I915_ERROR_PAGE_TABLE | 3862045cebd2SVille Syrjälä I915_ERROR_MEMORY_REFRESH)); 3863c2798b19SChris Wilson 3864c2798b19SChris Wilson /* Unmask the interrupts that we always want on. */ 3865c2798b19SChris Wilson dev_priv->irq_mask = 3866c2798b19SChris Wilson ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 386716659bc5SVille Syrjälä I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 386816659bc5SVille Syrjälä I915_MASTER_ERROR_INTERRUPT); 3869c2798b19SChris Wilson 3870e9e9848aSVille Syrjälä enable_mask = 3871c2798b19SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3872c2798b19SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 387316659bc5SVille Syrjälä I915_MASTER_ERROR_INTERRUPT | 3874e9e9848aSVille Syrjälä I915_USER_INTERRUPT; 3875e9e9848aSVille Syrjälä 3876b16b2a2fSPaulo Zanoni GEN2_IRQ_INIT(uncore, dev_priv->irq_mask, enable_mask); 3877c2798b19SChris Wilson 3878379ef82dSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3879379ef82dSDaniel Vetter * just to make the assert_spin_locked check happy. */ 3880d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 3881755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 3882755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 3883d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 3884c2798b19SChris Wilson } 3885c2798b19SChris Wilson 38864f5fd91fSTvrtko Ursulin static void i8xx_error_irq_ack(struct drm_i915_private *i915, 388778c357ddSVille Syrjälä u16 *eir, u16 *eir_stuck) 388878c357ddSVille Syrjälä { 38894f5fd91fSTvrtko Ursulin struct intel_uncore *uncore = &i915->uncore; 389078c357ddSVille Syrjälä u16 emr; 389178c357ddSVille Syrjälä 38924f5fd91fSTvrtko Ursulin *eir = intel_uncore_read16(uncore, EIR); 389378c357ddSVille Syrjälä 389478c357ddSVille Syrjälä if (*eir) 38954f5fd91fSTvrtko Ursulin intel_uncore_write16(uncore, EIR, *eir); 389678c357ddSVille Syrjälä 38974f5fd91fSTvrtko Ursulin *eir_stuck = intel_uncore_read16(uncore, EIR); 389878c357ddSVille Syrjälä if (*eir_stuck == 0) 389978c357ddSVille Syrjälä return; 390078c357ddSVille Syrjälä 390178c357ddSVille Syrjälä /* 390278c357ddSVille Syrjälä * Toggle all EMR bits to make sure we get an edge 390378c357ddSVille Syrjälä * in the ISR master error bit if we don't clear 390478c357ddSVille Syrjälä * all the EIR bits. Otherwise the edge triggered 390578c357ddSVille Syrjälä * IIR on i965/g4x wouldn't notice that an interrupt 390678c357ddSVille Syrjälä * is still pending. Also some EIR bits can't be 390778c357ddSVille Syrjälä * cleared except by handling the underlying error 390878c357ddSVille Syrjälä * (or by a GPU reset) so we mask any bit that 390978c357ddSVille Syrjälä * remains set. 391078c357ddSVille Syrjälä */ 39114f5fd91fSTvrtko Ursulin emr = intel_uncore_read16(uncore, EMR); 39124f5fd91fSTvrtko Ursulin intel_uncore_write16(uncore, EMR, 0xffff); 39134f5fd91fSTvrtko Ursulin intel_uncore_write16(uncore, EMR, emr | *eir_stuck); 391478c357ddSVille Syrjälä } 391578c357ddSVille Syrjälä 391678c357ddSVille Syrjälä static void i8xx_error_irq_handler(struct drm_i915_private *dev_priv, 391778c357ddSVille Syrjälä u16 eir, u16 eir_stuck) 391878c357ddSVille Syrjälä { 391978c357ddSVille Syrjälä DRM_DEBUG("Master Error: EIR 0x%04x\n", eir); 392078c357ddSVille Syrjälä 392178c357ddSVille Syrjälä if (eir_stuck) 392278c357ddSVille Syrjälä DRM_DEBUG_DRIVER("EIR stuck: 0x%04x, masked\n", eir_stuck); 392378c357ddSVille Syrjälä } 392478c357ddSVille Syrjälä 392578c357ddSVille Syrjälä static void i9xx_error_irq_ack(struct drm_i915_private *dev_priv, 392678c357ddSVille Syrjälä u32 *eir, u32 *eir_stuck) 392778c357ddSVille Syrjälä { 392878c357ddSVille Syrjälä u32 emr; 392978c357ddSVille Syrjälä 393078c357ddSVille Syrjälä *eir = I915_READ(EIR); 393178c357ddSVille Syrjälä 393278c357ddSVille Syrjälä I915_WRITE(EIR, *eir); 393378c357ddSVille Syrjälä 393478c357ddSVille Syrjälä *eir_stuck = I915_READ(EIR); 393578c357ddSVille Syrjälä if (*eir_stuck == 0) 393678c357ddSVille Syrjälä return; 393778c357ddSVille Syrjälä 393878c357ddSVille Syrjälä /* 393978c357ddSVille Syrjälä * Toggle all EMR bits to make sure we get an edge 394078c357ddSVille Syrjälä * in the ISR master error bit if we don't clear 394178c357ddSVille Syrjälä * all the EIR bits. Otherwise the edge triggered 394278c357ddSVille Syrjälä * IIR on i965/g4x wouldn't notice that an interrupt 394378c357ddSVille Syrjälä * is still pending. Also some EIR bits can't be 394478c357ddSVille Syrjälä * cleared except by handling the underlying error 394578c357ddSVille Syrjälä * (or by a GPU reset) so we mask any bit that 394678c357ddSVille Syrjälä * remains set. 394778c357ddSVille Syrjälä */ 394878c357ddSVille Syrjälä emr = I915_READ(EMR); 394978c357ddSVille Syrjälä I915_WRITE(EMR, 0xffffffff); 395078c357ddSVille Syrjälä I915_WRITE(EMR, emr | *eir_stuck); 395178c357ddSVille Syrjälä } 395278c357ddSVille Syrjälä 395378c357ddSVille Syrjälä static void i9xx_error_irq_handler(struct drm_i915_private *dev_priv, 395478c357ddSVille Syrjälä u32 eir, u32 eir_stuck) 395578c357ddSVille Syrjälä { 395678c357ddSVille Syrjälä DRM_DEBUG("Master Error, EIR 0x%08x\n", eir); 395778c357ddSVille Syrjälä 395878c357ddSVille Syrjälä if (eir_stuck) 395978c357ddSVille Syrjälä DRM_DEBUG_DRIVER("EIR stuck: 0x%08x, masked\n", eir_stuck); 396078c357ddSVille Syrjälä } 396178c357ddSVille Syrjälä 3962ff1f525eSDaniel Vetter static irqreturn_t i8xx_irq_handler(int irq, void *arg) 3963c2798b19SChris Wilson { 3964b318b824SVille Syrjälä struct drm_i915_private *dev_priv = arg; 3965af722d28SVille Syrjälä irqreturn_t ret = IRQ_NONE; 3966c2798b19SChris Wilson 39672dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 39682dd2a883SImre Deak return IRQ_NONE; 39692dd2a883SImre Deak 39701f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 39719102650fSDaniele Ceraolo Spurio disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 39721f814dacSImre Deak 3973af722d28SVille Syrjälä do { 3974af722d28SVille Syrjälä u32 pipe_stats[I915_MAX_PIPES] = {}; 397578c357ddSVille Syrjälä u16 eir = 0, eir_stuck = 0; 3976af722d28SVille Syrjälä u16 iir; 3977af722d28SVille Syrjälä 39784f5fd91fSTvrtko Ursulin iir = intel_uncore_read16(&dev_priv->uncore, GEN2_IIR); 3979c2798b19SChris Wilson if (iir == 0) 3980af722d28SVille Syrjälä break; 3981c2798b19SChris Wilson 3982af722d28SVille Syrjälä ret = IRQ_HANDLED; 3983c2798b19SChris Wilson 3984eb64343cSVille Syrjälä /* Call regardless, as some status bits might not be 3985eb64343cSVille Syrjälä * signalled in iir */ 3986eb64343cSVille Syrjälä i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats); 3987c2798b19SChris Wilson 398878c357ddSVille Syrjälä if (iir & I915_MASTER_ERROR_INTERRUPT) 398978c357ddSVille Syrjälä i8xx_error_irq_ack(dev_priv, &eir, &eir_stuck); 399078c357ddSVille Syrjälä 39914f5fd91fSTvrtko Ursulin intel_uncore_write16(&dev_priv->uncore, GEN2_IIR, iir); 3992c2798b19SChris Wilson 3993c2798b19SChris Wilson if (iir & I915_USER_INTERRUPT) 39948a68d464SChris Wilson intel_engine_breadcrumbs_irq(dev_priv->engine[RCS0]); 3995c2798b19SChris Wilson 399678c357ddSVille Syrjälä if (iir & I915_MASTER_ERROR_INTERRUPT) 399778c357ddSVille Syrjälä i8xx_error_irq_handler(dev_priv, eir, eir_stuck); 3998af722d28SVille Syrjälä 3999eb64343cSVille Syrjälä i8xx_pipestat_irq_handler(dev_priv, iir, pipe_stats); 4000af722d28SVille Syrjälä } while (0); 4001c2798b19SChris Wilson 40029102650fSDaniele Ceraolo Spurio enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 40031f814dacSImre Deak 40041f814dacSImre Deak return ret; 4005c2798b19SChris Wilson } 4006c2798b19SChris Wilson 4007b318b824SVille Syrjälä static void i915_irq_reset(struct drm_i915_private *dev_priv) 4008a266c7d5SChris Wilson { 4009b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 4010a266c7d5SChris Wilson 401156b857a5STvrtko Ursulin if (I915_HAS_HOTPLUG(dev_priv)) { 40120706f17cSEgbert Eich i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0); 4013a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 4014a266c7d5SChris Wilson } 4015a266c7d5SChris Wilson 401644d9241eSVille Syrjälä i9xx_pipestat_irq_reset(dev_priv); 401744d9241eSVille Syrjälä 4018b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN2_); 4019a266c7d5SChris Wilson } 4020a266c7d5SChris Wilson 4021b318b824SVille Syrjälä static void i915_irq_postinstall(struct drm_i915_private *dev_priv) 4022a266c7d5SChris Wilson { 4023b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 402438bde180SChris Wilson u32 enable_mask; 4025a266c7d5SChris Wilson 4026045cebd2SVille Syrjälä I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | 4027045cebd2SVille Syrjälä I915_ERROR_MEMORY_REFRESH)); 402838bde180SChris Wilson 402938bde180SChris Wilson /* Unmask the interrupts that we always want on. */ 403038bde180SChris Wilson dev_priv->irq_mask = 403138bde180SChris Wilson ~(I915_ASLE_INTERRUPT | 403238bde180SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 403316659bc5SVille Syrjälä I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 403416659bc5SVille Syrjälä I915_MASTER_ERROR_INTERRUPT); 403538bde180SChris Wilson 403638bde180SChris Wilson enable_mask = 403738bde180SChris Wilson I915_ASLE_INTERRUPT | 403838bde180SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 403938bde180SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 404016659bc5SVille Syrjälä I915_MASTER_ERROR_INTERRUPT | 404138bde180SChris Wilson I915_USER_INTERRUPT; 404238bde180SChris Wilson 404356b857a5STvrtko Ursulin if (I915_HAS_HOTPLUG(dev_priv)) { 4044a266c7d5SChris Wilson /* Enable in IER... */ 4045a266c7d5SChris Wilson enable_mask |= I915_DISPLAY_PORT_INTERRUPT; 4046a266c7d5SChris Wilson /* and unmask in IMR */ 4047a266c7d5SChris Wilson dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT; 4048a266c7d5SChris Wilson } 4049a266c7d5SChris Wilson 4050b16b2a2fSPaulo Zanoni GEN3_IRQ_INIT(uncore, GEN2_, dev_priv->irq_mask, enable_mask); 4051a266c7d5SChris Wilson 4052379ef82dSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 4053379ef82dSDaniel Vetter * just to make the assert_spin_locked check happy. */ 4054d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 4055755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 4056755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 4057d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 4058379ef82dSDaniel Vetter 4059c30bb1fdSVille Syrjälä i915_enable_asle_pipestat(dev_priv); 406020afbda2SDaniel Vetter } 406120afbda2SDaniel Vetter 4062ff1f525eSDaniel Vetter static irqreturn_t i915_irq_handler(int irq, void *arg) 4063a266c7d5SChris Wilson { 4064b318b824SVille Syrjälä struct drm_i915_private *dev_priv = arg; 4065af722d28SVille Syrjälä irqreturn_t ret = IRQ_NONE; 4066a266c7d5SChris Wilson 40672dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 40682dd2a883SImre Deak return IRQ_NONE; 40692dd2a883SImre Deak 40701f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 40719102650fSDaniele Ceraolo Spurio disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 40721f814dacSImre Deak 407338bde180SChris Wilson do { 4074eb64343cSVille Syrjälä u32 pipe_stats[I915_MAX_PIPES] = {}; 407578c357ddSVille Syrjälä u32 eir = 0, eir_stuck = 0; 4076af722d28SVille Syrjälä u32 hotplug_status = 0; 4077af722d28SVille Syrjälä u32 iir; 4078a266c7d5SChris Wilson 40799d9523d8SPaulo Zanoni iir = I915_READ(GEN2_IIR); 4080af722d28SVille Syrjälä if (iir == 0) 4081af722d28SVille Syrjälä break; 4082af722d28SVille Syrjälä 4083af722d28SVille Syrjälä ret = IRQ_HANDLED; 4084af722d28SVille Syrjälä 4085af722d28SVille Syrjälä if (I915_HAS_HOTPLUG(dev_priv) && 4086af722d28SVille Syrjälä iir & I915_DISPLAY_PORT_INTERRUPT) 4087af722d28SVille Syrjälä hotplug_status = i9xx_hpd_irq_ack(dev_priv); 4088a266c7d5SChris Wilson 4089eb64343cSVille Syrjälä /* Call regardless, as some status bits might not be 4090eb64343cSVille Syrjälä * signalled in iir */ 4091eb64343cSVille Syrjälä i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats); 4092a266c7d5SChris Wilson 409378c357ddSVille Syrjälä if (iir & I915_MASTER_ERROR_INTERRUPT) 409478c357ddSVille Syrjälä i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck); 409578c357ddSVille Syrjälä 40969d9523d8SPaulo Zanoni I915_WRITE(GEN2_IIR, iir); 4097a266c7d5SChris Wilson 4098a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 40998a68d464SChris Wilson intel_engine_breadcrumbs_irq(dev_priv->engine[RCS0]); 4100a266c7d5SChris Wilson 410178c357ddSVille Syrjälä if (iir & I915_MASTER_ERROR_INTERRUPT) 410278c357ddSVille Syrjälä i9xx_error_irq_handler(dev_priv, eir, eir_stuck); 4103a266c7d5SChris Wilson 4104af722d28SVille Syrjälä if (hotplug_status) 4105af722d28SVille Syrjälä i9xx_hpd_irq_handler(dev_priv, hotplug_status); 4106af722d28SVille Syrjälä 4107af722d28SVille Syrjälä i915_pipestat_irq_handler(dev_priv, iir, pipe_stats); 4108af722d28SVille Syrjälä } while (0); 4109a266c7d5SChris Wilson 41109102650fSDaniele Ceraolo Spurio enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 41111f814dacSImre Deak 4112a266c7d5SChris Wilson return ret; 4113a266c7d5SChris Wilson } 4114a266c7d5SChris Wilson 4115b318b824SVille Syrjälä static void i965_irq_reset(struct drm_i915_private *dev_priv) 4116a266c7d5SChris Wilson { 4117b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 4118a266c7d5SChris Wilson 41190706f17cSEgbert Eich i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0); 4120a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 4121a266c7d5SChris Wilson 412244d9241eSVille Syrjälä i9xx_pipestat_irq_reset(dev_priv); 412344d9241eSVille Syrjälä 4124b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN2_); 4125a266c7d5SChris Wilson } 4126a266c7d5SChris Wilson 4127b318b824SVille Syrjälä static void i965_irq_postinstall(struct drm_i915_private *dev_priv) 4128a266c7d5SChris Wilson { 4129b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 4130bbba0a97SChris Wilson u32 enable_mask; 4131a266c7d5SChris Wilson u32 error_mask; 4132a266c7d5SChris Wilson 4133045cebd2SVille Syrjälä /* 4134045cebd2SVille Syrjälä * Enable some error detection, note the instruction error mask 4135045cebd2SVille Syrjälä * bit is reserved, so we leave it masked. 4136045cebd2SVille Syrjälä */ 4137045cebd2SVille Syrjälä if (IS_G4X(dev_priv)) { 4138045cebd2SVille Syrjälä error_mask = ~(GM45_ERROR_PAGE_TABLE | 4139045cebd2SVille Syrjälä GM45_ERROR_MEM_PRIV | 4140045cebd2SVille Syrjälä GM45_ERROR_CP_PRIV | 4141045cebd2SVille Syrjälä I915_ERROR_MEMORY_REFRESH); 4142045cebd2SVille Syrjälä } else { 4143045cebd2SVille Syrjälä error_mask = ~(I915_ERROR_PAGE_TABLE | 4144045cebd2SVille Syrjälä I915_ERROR_MEMORY_REFRESH); 4145045cebd2SVille Syrjälä } 4146045cebd2SVille Syrjälä I915_WRITE(EMR, error_mask); 4147045cebd2SVille Syrjälä 4148a266c7d5SChris Wilson /* Unmask the interrupts that we always want on. */ 4149c30bb1fdSVille Syrjälä dev_priv->irq_mask = 4150c30bb1fdSVille Syrjälä ~(I915_ASLE_INTERRUPT | 4151adca4730SChris Wilson I915_DISPLAY_PORT_INTERRUPT | 4152bbba0a97SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 4153bbba0a97SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 415478c357ddSVille Syrjälä I915_MASTER_ERROR_INTERRUPT); 4155bbba0a97SChris Wilson 4156c30bb1fdSVille Syrjälä enable_mask = 4157c30bb1fdSVille Syrjälä I915_ASLE_INTERRUPT | 4158c30bb1fdSVille Syrjälä I915_DISPLAY_PORT_INTERRUPT | 4159c30bb1fdSVille Syrjälä I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 4160c30bb1fdSVille Syrjälä I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 416178c357ddSVille Syrjälä I915_MASTER_ERROR_INTERRUPT | 4162c30bb1fdSVille Syrjälä I915_USER_INTERRUPT; 4163bbba0a97SChris Wilson 416491d14251STvrtko Ursulin if (IS_G4X(dev_priv)) 4165bbba0a97SChris Wilson enable_mask |= I915_BSD_USER_INTERRUPT; 4166a266c7d5SChris Wilson 4167b16b2a2fSPaulo Zanoni GEN3_IRQ_INIT(uncore, GEN2_, dev_priv->irq_mask, enable_mask); 4168c30bb1fdSVille Syrjälä 4169b79480baSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 4170b79480baSDaniel Vetter * just to make the assert_spin_locked check happy. */ 4171d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 4172755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS); 4173755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 4174755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 4175d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 4176a266c7d5SChris Wilson 417791d14251STvrtko Ursulin i915_enable_asle_pipestat(dev_priv); 417820afbda2SDaniel Vetter } 417920afbda2SDaniel Vetter 418091d14251STvrtko Ursulin static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv) 418120afbda2SDaniel Vetter { 418220afbda2SDaniel Vetter u32 hotplug_en; 418320afbda2SDaniel Vetter 418467520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 4185b5ea2d56SDaniel Vetter 4186adca4730SChris Wilson /* Note HDMI and DP share hotplug bits */ 4187e5868a31SEgbert Eich /* enable bits are the same for all generations */ 418891d14251STvrtko Ursulin hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915); 4189a266c7d5SChris Wilson /* Programming the CRT detection parameters tends 4190a266c7d5SChris Wilson to generate a spurious hotplug event about three 4191a266c7d5SChris Wilson seconds later. So just do it once. 4192a266c7d5SChris Wilson */ 419391d14251STvrtko Ursulin if (IS_G4X(dev_priv)) 4194a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64; 4195a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; 4196a266c7d5SChris Wilson 4197a266c7d5SChris Wilson /* Ignore TV since it's buggy */ 41980706f17cSEgbert Eich i915_hotplug_interrupt_update_locked(dev_priv, 4199f9e3dc78SJani Nikula HOTPLUG_INT_EN_MASK | 4200f9e3dc78SJani Nikula CRT_HOTPLUG_VOLTAGE_COMPARE_MASK | 4201f9e3dc78SJani Nikula CRT_HOTPLUG_ACTIVATION_PERIOD_64, 42020706f17cSEgbert Eich hotplug_en); 4203a266c7d5SChris Wilson } 4204a266c7d5SChris Wilson 4205ff1f525eSDaniel Vetter static irqreturn_t i965_irq_handler(int irq, void *arg) 4206a266c7d5SChris Wilson { 4207b318b824SVille Syrjälä struct drm_i915_private *dev_priv = arg; 4208af722d28SVille Syrjälä irqreturn_t ret = IRQ_NONE; 4209a266c7d5SChris Wilson 42102dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 42112dd2a883SImre Deak return IRQ_NONE; 42122dd2a883SImre Deak 42131f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 42149102650fSDaniele Ceraolo Spurio disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 42151f814dacSImre Deak 4216af722d28SVille Syrjälä do { 4217eb64343cSVille Syrjälä u32 pipe_stats[I915_MAX_PIPES] = {}; 421878c357ddSVille Syrjälä u32 eir = 0, eir_stuck = 0; 4219af722d28SVille Syrjälä u32 hotplug_status = 0; 4220af722d28SVille Syrjälä u32 iir; 42212c8ba29fSChris Wilson 42229d9523d8SPaulo Zanoni iir = I915_READ(GEN2_IIR); 4223af722d28SVille Syrjälä if (iir == 0) 4224af722d28SVille Syrjälä break; 4225af722d28SVille Syrjälä 4226af722d28SVille Syrjälä ret = IRQ_HANDLED; 4227af722d28SVille Syrjälä 4228af722d28SVille Syrjälä if (iir & I915_DISPLAY_PORT_INTERRUPT) 4229af722d28SVille Syrjälä hotplug_status = i9xx_hpd_irq_ack(dev_priv); 4230a266c7d5SChris Wilson 4231eb64343cSVille Syrjälä /* Call regardless, as some status bits might not be 4232eb64343cSVille Syrjälä * signalled in iir */ 4233eb64343cSVille Syrjälä i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats); 4234a266c7d5SChris Wilson 423578c357ddSVille Syrjälä if (iir & I915_MASTER_ERROR_INTERRUPT) 423678c357ddSVille Syrjälä i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck); 423778c357ddSVille Syrjälä 42389d9523d8SPaulo Zanoni I915_WRITE(GEN2_IIR, iir); 4239a266c7d5SChris Wilson 4240a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 42418a68d464SChris Wilson intel_engine_breadcrumbs_irq(dev_priv->engine[RCS0]); 4242af722d28SVille Syrjälä 4243a266c7d5SChris Wilson if (iir & I915_BSD_USER_INTERRUPT) 42448a68d464SChris Wilson intel_engine_breadcrumbs_irq(dev_priv->engine[VCS0]); 4245a266c7d5SChris Wilson 424678c357ddSVille Syrjälä if (iir & I915_MASTER_ERROR_INTERRUPT) 424778c357ddSVille Syrjälä i9xx_error_irq_handler(dev_priv, eir, eir_stuck); 4248515ac2bbSDaniel Vetter 4249af722d28SVille Syrjälä if (hotplug_status) 4250af722d28SVille Syrjälä i9xx_hpd_irq_handler(dev_priv, hotplug_status); 4251af722d28SVille Syrjälä 4252af722d28SVille Syrjälä i965_pipestat_irq_handler(dev_priv, iir, pipe_stats); 4253af722d28SVille Syrjälä } while (0); 4254a266c7d5SChris Wilson 42559102650fSDaniele Ceraolo Spurio enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 42561f814dacSImre Deak 4257a266c7d5SChris Wilson return ret; 4258a266c7d5SChris Wilson } 4259a266c7d5SChris Wilson 4260fca52a55SDaniel Vetter /** 4261fca52a55SDaniel Vetter * intel_irq_init - initializes irq support 4262fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4263fca52a55SDaniel Vetter * 4264fca52a55SDaniel Vetter * This function initializes all the irq support including work items, timers 4265fca52a55SDaniel Vetter * and all the vtables. It does not setup the interrupt itself though. 4266fca52a55SDaniel Vetter */ 4267b963291cSDaniel Vetter void intel_irq_init(struct drm_i915_private *dev_priv) 4268f71d4af4SJesse Barnes { 426991c8a326SChris Wilson struct drm_device *dev = &dev_priv->drm; 4270562d9baeSSagar Arun Kamble struct intel_rps *rps = &dev_priv->gt_pm.rps; 4271cefcff8fSJoonas Lahtinen int i; 42728b2e326dSChris Wilson 427377913b39SJani Nikula intel_hpd_init_work(dev_priv); 427477913b39SJani Nikula 4275562d9baeSSagar Arun Kamble INIT_WORK(&rps->work, gen6_pm_rps_work); 4276cefcff8fSJoonas Lahtinen 4277a4da4fa4SDaniel Vetter INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work); 4278cefcff8fSJoonas Lahtinen for (i = 0; i < MAX_L3_SLICES; ++i) 4279cefcff8fSJoonas Lahtinen dev_priv->l3_parity.remap_info[i] = NULL; 42808b2e326dSChris Wilson 4281633023a4SDaniele Ceraolo Spurio /* pre-gen11 the guc irqs bits are in the upper 16 bits of the pm reg */ 4282702668e6SDaniele Ceraolo Spurio if (HAS_GT_UC(dev_priv) && INTEL_GEN(dev_priv) < 11) 42832239e6dfSDaniele Ceraolo Spurio dev_priv->gt.pm_guc_events = GUC_INTR_GUC2HOST << 16; 428426705e20SSagar Arun Kamble 4285a6706b45SDeepak S /* Let's track the enabled rps events */ 4286666a4537SWayne Boyer if (IS_VALLEYVIEW(dev_priv)) 42876c65a587SVille Syrjälä /* WaGsvRC0ResidencyMethod:vlv */ 4288e0e8c7cbSChris Wilson dev_priv->pm_rps_events = GEN6_PM_RP_UP_EI_EXPIRED; 428931685c25SDeepak S else 42904668f695SChris Wilson dev_priv->pm_rps_events = (GEN6_PM_RP_UP_THRESHOLD | 42914668f695SChris Wilson GEN6_PM_RP_DOWN_THRESHOLD | 42924668f695SChris Wilson GEN6_PM_RP_DOWN_TIMEOUT); 4293a6706b45SDeepak S 4294917dc6b5SMika Kuoppala /* We share the register with other engine */ 4295917dc6b5SMika Kuoppala if (INTEL_GEN(dev_priv) > 9) 4296917dc6b5SMika Kuoppala GEM_WARN_ON(dev_priv->pm_rps_events & 0xffff0000); 4297917dc6b5SMika Kuoppala 4298562d9baeSSagar Arun Kamble rps->pm_intrmsk_mbz = 0; 42991800ad25SSagar Arun Kamble 43001800ad25SSagar Arun Kamble /* 4301acf2dc22SMika Kuoppala * SNB,IVB,HSW can while VLV,CHV may hard hang on looping batchbuffer 43021800ad25SSagar Arun Kamble * if GEN6_PM_UP_EI_EXPIRED is masked. 43031800ad25SSagar Arun Kamble * 43041800ad25SSagar Arun Kamble * TODO: verify if this can be reproduced on VLV,CHV. 43051800ad25SSagar Arun Kamble */ 4306bca2bf2aSPandiyan, Dhinakaran if (INTEL_GEN(dev_priv) <= 7) 4307562d9baeSSagar Arun Kamble rps->pm_intrmsk_mbz |= GEN6_PM_RP_UP_EI_EXPIRED; 43081800ad25SSagar Arun Kamble 4309bca2bf2aSPandiyan, Dhinakaran if (INTEL_GEN(dev_priv) >= 8) 4310562d9baeSSagar Arun Kamble rps->pm_intrmsk_mbz |= GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC; 43111800ad25SSagar Arun Kamble 431221da2700SVille Syrjälä dev->vblank_disable_immediate = true; 431321da2700SVille Syrjälä 4314262fd485SChris Wilson /* Most platforms treat the display irq block as an always-on 4315262fd485SChris Wilson * power domain. vlv/chv can disable it at runtime and need 4316262fd485SChris Wilson * special care to avoid writing any of the display block registers 4317262fd485SChris Wilson * outside of the power domain. We defer setting up the display irqs 4318262fd485SChris Wilson * in this case to the runtime pm. 4319262fd485SChris Wilson */ 4320262fd485SChris Wilson dev_priv->display_irqs_enabled = true; 4321262fd485SChris Wilson if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) 4322262fd485SChris Wilson dev_priv->display_irqs_enabled = false; 4323262fd485SChris Wilson 4324317eaa95SLyude dev_priv->hotplug.hpd_storm_threshold = HPD_STORM_DEFAULT_THRESHOLD; 43259a64c650SLyude Paul /* If we have MST support, we want to avoid doing short HPD IRQ storm 43269a64c650SLyude Paul * detection, as short HPD storms will occur as a natural part of 43279a64c650SLyude Paul * sideband messaging with MST. 43289a64c650SLyude Paul * On older platforms however, IRQ storms can occur with both long and 43299a64c650SLyude Paul * short pulses, as seen on some G4x systems. 43309a64c650SLyude Paul */ 43319a64c650SLyude Paul dev_priv->hotplug.hpd_short_storm_enabled = !HAS_DP_MST(dev_priv); 4332317eaa95SLyude 4333b318b824SVille Syrjälä if (HAS_GMCH(dev_priv)) { 4334b318b824SVille Syrjälä if (I915_HAS_HOTPLUG(dev_priv)) 433543f328d7SVille Syrjälä dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 4336b318b824SVille Syrjälä } else { 4337*943682e3SMatt Roper if (HAS_PCH_JSP(dev_priv)) 4338*943682e3SMatt Roper dev_priv->display.hpd_irq_setup = jsp_hpd_irq_setup; 4339*943682e3SMatt Roper else if (HAS_PCH_MCC(dev_priv)) 43408ef7e340SMatt Roper dev_priv->display.hpd_irq_setup = mcc_hpd_irq_setup; 43418ef7e340SMatt Roper else if (INTEL_GEN(dev_priv) >= 11) 4342121e758eSDhinakaran Pandiyan dev_priv->display.hpd_irq_setup = gen11_hpd_irq_setup; 4343b318b824SVille Syrjälä else if (IS_GEN9_LP(dev_priv)) 4344e0a20ad7SShashank Sharma dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup; 4345c6c30b91SRodrigo Vivi else if (INTEL_PCH_TYPE(dev_priv) >= PCH_SPT) 43466dbf30ceSVille Syrjälä dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup; 43476dbf30ceSVille Syrjälä else 43483a3b3c7dSVille Syrjälä dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup; 4349f71d4af4SJesse Barnes } 4350f71d4af4SJesse Barnes } 435120afbda2SDaniel Vetter 4352fca52a55SDaniel Vetter /** 4353cefcff8fSJoonas Lahtinen * intel_irq_fini - deinitializes IRQ support 4354cefcff8fSJoonas Lahtinen * @i915: i915 device instance 4355cefcff8fSJoonas Lahtinen * 4356cefcff8fSJoonas Lahtinen * This function deinitializes all the IRQ support. 4357cefcff8fSJoonas Lahtinen */ 4358cefcff8fSJoonas Lahtinen void intel_irq_fini(struct drm_i915_private *i915) 4359cefcff8fSJoonas Lahtinen { 4360cefcff8fSJoonas Lahtinen int i; 4361cefcff8fSJoonas Lahtinen 4362cefcff8fSJoonas Lahtinen for (i = 0; i < MAX_L3_SLICES; ++i) 4363cefcff8fSJoonas Lahtinen kfree(i915->l3_parity.remap_info[i]); 4364cefcff8fSJoonas Lahtinen } 4365cefcff8fSJoonas Lahtinen 4366b318b824SVille Syrjälä static irq_handler_t intel_irq_handler(struct drm_i915_private *dev_priv) 4367b318b824SVille Syrjälä { 4368b318b824SVille Syrjälä if (HAS_GMCH(dev_priv)) { 4369b318b824SVille Syrjälä if (IS_CHERRYVIEW(dev_priv)) 4370b318b824SVille Syrjälä return cherryview_irq_handler; 4371b318b824SVille Syrjälä else if (IS_VALLEYVIEW(dev_priv)) 4372b318b824SVille Syrjälä return valleyview_irq_handler; 4373b318b824SVille Syrjälä else if (IS_GEN(dev_priv, 4)) 4374b318b824SVille Syrjälä return i965_irq_handler; 4375b318b824SVille Syrjälä else if (IS_GEN(dev_priv, 3)) 4376b318b824SVille Syrjälä return i915_irq_handler; 4377b318b824SVille Syrjälä else 4378b318b824SVille Syrjälä return i8xx_irq_handler; 4379b318b824SVille Syrjälä } else { 4380b318b824SVille Syrjälä if (INTEL_GEN(dev_priv) >= 11) 4381b318b824SVille Syrjälä return gen11_irq_handler; 4382b318b824SVille Syrjälä else if (INTEL_GEN(dev_priv) >= 8) 4383b318b824SVille Syrjälä return gen8_irq_handler; 4384b318b824SVille Syrjälä else 4385b318b824SVille Syrjälä return ironlake_irq_handler; 4386b318b824SVille Syrjälä } 4387b318b824SVille Syrjälä } 4388b318b824SVille Syrjälä 4389b318b824SVille Syrjälä static void intel_irq_reset(struct drm_i915_private *dev_priv) 4390b318b824SVille Syrjälä { 4391b318b824SVille Syrjälä if (HAS_GMCH(dev_priv)) { 4392b318b824SVille Syrjälä if (IS_CHERRYVIEW(dev_priv)) 4393b318b824SVille Syrjälä cherryview_irq_reset(dev_priv); 4394b318b824SVille Syrjälä else if (IS_VALLEYVIEW(dev_priv)) 4395b318b824SVille Syrjälä valleyview_irq_reset(dev_priv); 4396b318b824SVille Syrjälä else if (IS_GEN(dev_priv, 4)) 4397b318b824SVille Syrjälä i965_irq_reset(dev_priv); 4398b318b824SVille Syrjälä else if (IS_GEN(dev_priv, 3)) 4399b318b824SVille Syrjälä i915_irq_reset(dev_priv); 4400b318b824SVille Syrjälä else 4401b318b824SVille Syrjälä i8xx_irq_reset(dev_priv); 4402b318b824SVille Syrjälä } else { 4403b318b824SVille Syrjälä if (INTEL_GEN(dev_priv) >= 11) 4404b318b824SVille Syrjälä gen11_irq_reset(dev_priv); 4405b318b824SVille Syrjälä else if (INTEL_GEN(dev_priv) >= 8) 4406b318b824SVille Syrjälä gen8_irq_reset(dev_priv); 4407b318b824SVille Syrjälä else 4408b318b824SVille Syrjälä ironlake_irq_reset(dev_priv); 4409b318b824SVille Syrjälä } 4410b318b824SVille Syrjälä } 4411b318b824SVille Syrjälä 4412b318b824SVille Syrjälä static void intel_irq_postinstall(struct drm_i915_private *dev_priv) 4413b318b824SVille Syrjälä { 4414b318b824SVille Syrjälä if (HAS_GMCH(dev_priv)) { 4415b318b824SVille Syrjälä if (IS_CHERRYVIEW(dev_priv)) 4416b318b824SVille Syrjälä cherryview_irq_postinstall(dev_priv); 4417b318b824SVille Syrjälä else if (IS_VALLEYVIEW(dev_priv)) 4418b318b824SVille Syrjälä valleyview_irq_postinstall(dev_priv); 4419b318b824SVille Syrjälä else if (IS_GEN(dev_priv, 4)) 4420b318b824SVille Syrjälä i965_irq_postinstall(dev_priv); 4421b318b824SVille Syrjälä else if (IS_GEN(dev_priv, 3)) 4422b318b824SVille Syrjälä i915_irq_postinstall(dev_priv); 4423b318b824SVille Syrjälä else 4424b318b824SVille Syrjälä i8xx_irq_postinstall(dev_priv); 4425b318b824SVille Syrjälä } else { 4426b318b824SVille Syrjälä if (INTEL_GEN(dev_priv) >= 11) 4427b318b824SVille Syrjälä gen11_irq_postinstall(dev_priv); 4428b318b824SVille Syrjälä else if (INTEL_GEN(dev_priv) >= 8) 4429b318b824SVille Syrjälä gen8_irq_postinstall(dev_priv); 4430b318b824SVille Syrjälä else 4431b318b824SVille Syrjälä ironlake_irq_postinstall(dev_priv); 4432b318b824SVille Syrjälä } 4433b318b824SVille Syrjälä } 4434b318b824SVille Syrjälä 4435cefcff8fSJoonas Lahtinen /** 4436fca52a55SDaniel Vetter * intel_irq_install - enables the hardware interrupt 4437fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4438fca52a55SDaniel Vetter * 4439fca52a55SDaniel Vetter * This function enables the hardware interrupt handling, but leaves the hotplug 4440fca52a55SDaniel Vetter * handling still disabled. It is called after intel_irq_init(). 4441fca52a55SDaniel Vetter * 4442fca52a55SDaniel Vetter * In the driver load and resume code we need working interrupts in a few places 4443fca52a55SDaniel Vetter * but don't want to deal with the hassle of concurrent probe and hotplug 4444fca52a55SDaniel Vetter * workers. Hence the split into this two-stage approach. 4445fca52a55SDaniel Vetter */ 44462aeb7d3aSDaniel Vetter int intel_irq_install(struct drm_i915_private *dev_priv) 44472aeb7d3aSDaniel Vetter { 4448b318b824SVille Syrjälä int irq = dev_priv->drm.pdev->irq; 4449b318b824SVille Syrjälä int ret; 4450b318b824SVille Syrjälä 44512aeb7d3aSDaniel Vetter /* 44522aeb7d3aSDaniel Vetter * We enable some interrupt sources in our postinstall hooks, so mark 44532aeb7d3aSDaniel Vetter * interrupts as enabled _before_ actually enabling them to avoid 44542aeb7d3aSDaniel Vetter * special cases in our ordering checks. 44552aeb7d3aSDaniel Vetter */ 4456ad1443f0SSagar Arun Kamble dev_priv->runtime_pm.irqs_enabled = true; 44572aeb7d3aSDaniel Vetter 4458b318b824SVille Syrjälä dev_priv->drm.irq_enabled = true; 4459b318b824SVille Syrjälä 4460b318b824SVille Syrjälä intel_irq_reset(dev_priv); 4461b318b824SVille Syrjälä 4462b318b824SVille Syrjälä ret = request_irq(irq, intel_irq_handler(dev_priv), 4463b318b824SVille Syrjälä IRQF_SHARED, DRIVER_NAME, dev_priv); 4464b318b824SVille Syrjälä if (ret < 0) { 4465b318b824SVille Syrjälä dev_priv->drm.irq_enabled = false; 4466b318b824SVille Syrjälä return ret; 4467b318b824SVille Syrjälä } 4468b318b824SVille Syrjälä 4469b318b824SVille Syrjälä intel_irq_postinstall(dev_priv); 4470b318b824SVille Syrjälä 4471b318b824SVille Syrjälä return ret; 44722aeb7d3aSDaniel Vetter } 44732aeb7d3aSDaniel Vetter 4474fca52a55SDaniel Vetter /** 4475fca52a55SDaniel Vetter * intel_irq_uninstall - finilizes all irq handling 4476fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4477fca52a55SDaniel Vetter * 4478fca52a55SDaniel Vetter * This stops interrupt and hotplug handling and unregisters and frees all 4479fca52a55SDaniel Vetter * resources acquired in the init functions. 4480fca52a55SDaniel Vetter */ 44812aeb7d3aSDaniel Vetter void intel_irq_uninstall(struct drm_i915_private *dev_priv) 44822aeb7d3aSDaniel Vetter { 4483b318b824SVille Syrjälä int irq = dev_priv->drm.pdev->irq; 4484b318b824SVille Syrjälä 4485b318b824SVille Syrjälä /* 4486b318b824SVille Syrjälä * FIXME we can get called twice during driver load 4487b318b824SVille Syrjälä * error handling due to intel_modeset_cleanup() 4488b318b824SVille Syrjälä * calling us out of sequence. Would be nice if 4489b318b824SVille Syrjälä * it didn't do that... 4490b318b824SVille Syrjälä */ 4491b318b824SVille Syrjälä if (!dev_priv->drm.irq_enabled) 4492b318b824SVille Syrjälä return; 4493b318b824SVille Syrjälä 4494b318b824SVille Syrjälä dev_priv->drm.irq_enabled = false; 4495b318b824SVille Syrjälä 4496b318b824SVille Syrjälä intel_irq_reset(dev_priv); 4497b318b824SVille Syrjälä 4498b318b824SVille Syrjälä free_irq(irq, dev_priv); 4499b318b824SVille Syrjälä 45002aeb7d3aSDaniel Vetter intel_hpd_cancel_work(dev_priv); 4501ad1443f0SSagar Arun Kamble dev_priv->runtime_pm.irqs_enabled = false; 45022aeb7d3aSDaniel Vetter } 45032aeb7d3aSDaniel Vetter 4504fca52a55SDaniel Vetter /** 4505fca52a55SDaniel Vetter * intel_runtime_pm_disable_interrupts - runtime interrupt disabling 4506fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4507fca52a55SDaniel Vetter * 4508fca52a55SDaniel Vetter * This function is used to disable interrupts at runtime, both in the runtime 4509fca52a55SDaniel Vetter * pm and the system suspend/resume code. 4510fca52a55SDaniel Vetter */ 4511b963291cSDaniel Vetter void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv) 4512c67a470bSPaulo Zanoni { 4513b318b824SVille Syrjälä intel_irq_reset(dev_priv); 4514ad1443f0SSagar Arun Kamble dev_priv->runtime_pm.irqs_enabled = false; 4515315ca4c4SVille Syrjälä intel_synchronize_irq(dev_priv); 4516c67a470bSPaulo Zanoni } 4517c67a470bSPaulo Zanoni 4518fca52a55SDaniel Vetter /** 4519fca52a55SDaniel Vetter * intel_runtime_pm_enable_interrupts - runtime interrupt enabling 4520fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4521fca52a55SDaniel Vetter * 4522fca52a55SDaniel Vetter * This function is used to enable interrupts at runtime, both in the runtime 4523fca52a55SDaniel Vetter * pm and the system suspend/resume code. 4524fca52a55SDaniel Vetter */ 4525b963291cSDaniel Vetter void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv) 4526c67a470bSPaulo Zanoni { 4527ad1443f0SSagar Arun Kamble dev_priv->runtime_pm.irqs_enabled = true; 4528b318b824SVille Syrjälä intel_irq_reset(dev_priv); 4529b318b824SVille Syrjälä intel_irq_postinstall(dev_priv); 4530c67a470bSPaulo Zanoni } 4531d64575eeSJani Nikula 4532d64575eeSJani Nikula bool intel_irqs_enabled(struct drm_i915_private *dev_priv) 4533d64575eeSJani Nikula { 4534d64575eeSJani Nikula /* 4535d64575eeSJani Nikula * We only use drm_irq_uninstall() at unload and VT switch, so 4536d64575eeSJani Nikula * this is the only thing we need to check. 4537d64575eeSJani Nikula */ 4538d64575eeSJani Nikula return dev_priv->runtime_pm.irqs_enabled; 4539d64575eeSJani Nikula } 4540d64575eeSJani Nikula 4541d64575eeSJani Nikula void intel_synchronize_irq(struct drm_i915_private *i915) 4542d64575eeSJani Nikula { 4543d64575eeSJani Nikula synchronize_irq(i915->drm.pdev->irq); 4544d64575eeSJani Nikula } 4545