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 415*cd6a8513SChris 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 426*cd6a8513SChris 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 443*cd6a8513SChris 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; 225158676af6SLucas De Marchi } else if (HAS_PCH_MCC(dev_priv)) { 22528ef7e340SMatt Roper ddi_hotplug_trigger = pch_iir & SDE_DDI_MASK_TGP; 22538ef7e340SMatt Roper tc_hotplug_trigger = 0; 2254d09ad3e7SMatt Roper pins = hpd_icp; 22558ef7e340SMatt Roper } else { 22568ef7e340SMatt Roper ddi_hotplug_trigger = pch_iir & SDE_DDI_MASK_ICP; 22578ef7e340SMatt Roper tc_hotplug_trigger = pch_iir & SDE_TC_MASK_ICP; 225858676af6SLucas De Marchi tc_port_hotplug_long_detect = icp_tc_port_hotplug_long_detect; 225958676af6SLucas De Marchi pins = hpd_icp; 22608ef7e340SMatt Roper } 22618ef7e340SMatt Roper 226231604222SAnusha Srivatsa if (ddi_hotplug_trigger) { 226331604222SAnusha Srivatsa u32 dig_hotplug_reg; 226431604222SAnusha Srivatsa 226531604222SAnusha Srivatsa dig_hotplug_reg = I915_READ(SHOTPLUG_CTL_DDI); 226631604222SAnusha Srivatsa I915_WRITE(SHOTPLUG_CTL_DDI, dig_hotplug_reg); 226731604222SAnusha Srivatsa 226831604222SAnusha Srivatsa intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, 226931604222SAnusha Srivatsa ddi_hotplug_trigger, 2270c6f7acb8SMatt Roper dig_hotplug_reg, pins, 227131604222SAnusha Srivatsa icp_ddi_port_hotplug_long_detect); 227231604222SAnusha Srivatsa } 227331604222SAnusha Srivatsa 227431604222SAnusha Srivatsa if (tc_hotplug_trigger) { 227531604222SAnusha Srivatsa u32 dig_hotplug_reg; 227631604222SAnusha Srivatsa 227731604222SAnusha Srivatsa dig_hotplug_reg = I915_READ(SHOTPLUG_CTL_TC); 227831604222SAnusha Srivatsa I915_WRITE(SHOTPLUG_CTL_TC, dig_hotplug_reg); 227931604222SAnusha Srivatsa 228031604222SAnusha Srivatsa intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, 228131604222SAnusha Srivatsa tc_hotplug_trigger, 2282c6f7acb8SMatt Roper dig_hotplug_reg, pins, 228358676af6SLucas De Marchi tc_port_hotplug_long_detect); 228452dfdba0SLucas De Marchi } 228552dfdba0SLucas De Marchi 228652dfdba0SLucas De Marchi if (pin_mask) 228752dfdba0SLucas De Marchi intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 228852dfdba0SLucas De Marchi 228952dfdba0SLucas De Marchi if (pch_iir & SDE_GMBUS_ICP) 229052dfdba0SLucas De Marchi gmbus_irq_handler(dev_priv); 229152dfdba0SLucas De Marchi } 229252dfdba0SLucas De Marchi 229391d14251STvrtko Ursulin static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir) 22946dbf30ceSVille Syrjälä { 22956dbf30ceSVille Syrjälä u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT & 22966dbf30ceSVille Syrjälä ~SDE_PORTE_HOTPLUG_SPT; 22976dbf30ceSVille Syrjälä u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT; 22986dbf30ceSVille Syrjälä u32 pin_mask = 0, long_mask = 0; 22996dbf30ceSVille Syrjälä 23006dbf30ceSVille Syrjälä if (hotplug_trigger) { 23016dbf30ceSVille Syrjälä u32 dig_hotplug_reg; 23026dbf30ceSVille Syrjälä 23036dbf30ceSVille Syrjälä dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG); 23046dbf30ceSVille Syrjälä I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg); 23056dbf30ceSVille Syrjälä 2306cf53902fSRodrigo Vivi intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, 2307cf53902fSRodrigo Vivi hotplug_trigger, dig_hotplug_reg, hpd_spt, 230874c0b395SVille Syrjälä spt_port_hotplug_long_detect); 23096dbf30ceSVille Syrjälä } 23106dbf30ceSVille Syrjälä 23116dbf30ceSVille Syrjälä if (hotplug2_trigger) { 23126dbf30ceSVille Syrjälä u32 dig_hotplug_reg; 23136dbf30ceSVille Syrjälä 23146dbf30ceSVille Syrjälä dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2); 23156dbf30ceSVille Syrjälä I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg); 23166dbf30ceSVille Syrjälä 2317cf53902fSRodrigo Vivi intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, 2318cf53902fSRodrigo Vivi hotplug2_trigger, dig_hotplug_reg, hpd_spt, 23196dbf30ceSVille Syrjälä spt_port_hotplug2_long_detect); 23206dbf30ceSVille Syrjälä } 23216dbf30ceSVille Syrjälä 23226dbf30ceSVille Syrjälä if (pin_mask) 232391d14251STvrtko Ursulin intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 23246dbf30ceSVille Syrjälä 23256dbf30ceSVille Syrjälä if (pch_iir & SDE_GMBUS_CPT) 232691d14251STvrtko Ursulin gmbus_irq_handler(dev_priv); 23276dbf30ceSVille Syrjälä } 23286dbf30ceSVille Syrjälä 232991d14251STvrtko Ursulin static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv, 233091d14251STvrtko Ursulin u32 hotplug_trigger, 233140e56410SVille Syrjälä const u32 hpd[HPD_NUM_PINS]) 2332c008bc6eSPaulo Zanoni { 2333e4ce95aaSVille Syrjälä u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0; 2334e4ce95aaSVille Syrjälä 2335e4ce95aaSVille Syrjälä dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL); 2336e4ce95aaSVille Syrjälä I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg); 2337e4ce95aaSVille Syrjälä 2338cf53902fSRodrigo Vivi intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger, 233940e56410SVille Syrjälä dig_hotplug_reg, hpd, 2340e4ce95aaSVille Syrjälä ilk_port_hotplug_long_detect); 234140e56410SVille Syrjälä 234291d14251STvrtko Ursulin intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 2343e4ce95aaSVille Syrjälä } 2344c008bc6eSPaulo Zanoni 234591d14251STvrtko Ursulin static void ilk_display_irq_handler(struct drm_i915_private *dev_priv, 234691d14251STvrtko Ursulin u32 de_iir) 234740e56410SVille Syrjälä { 234840e56410SVille Syrjälä enum pipe pipe; 234940e56410SVille Syrjälä u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG; 235040e56410SVille Syrjälä 235140e56410SVille Syrjälä if (hotplug_trigger) 235291d14251STvrtko Ursulin ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk); 235340e56410SVille Syrjälä 2354c008bc6eSPaulo Zanoni if (de_iir & DE_AUX_CHANNEL_A) 235591d14251STvrtko Ursulin dp_aux_irq_handler(dev_priv); 2356c008bc6eSPaulo Zanoni 2357c008bc6eSPaulo Zanoni if (de_iir & DE_GSE) 235891d14251STvrtko Ursulin intel_opregion_asle_intr(dev_priv); 2359c008bc6eSPaulo Zanoni 2360c008bc6eSPaulo Zanoni if (de_iir & DE_POISON) 2361c008bc6eSPaulo Zanoni DRM_ERROR("Poison interrupt\n"); 2362c008bc6eSPaulo Zanoni 2363055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 2364fd3a4024SDaniel Vetter if (de_iir & DE_PIPE_VBLANK(pipe)) 2365fd3a4024SDaniel Vetter drm_handle_vblank(&dev_priv->drm, pipe); 2366c008bc6eSPaulo Zanoni 236740da17c2SDaniel Vetter if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe)) 23681f7247c0SDaniel Vetter intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 2369c008bc6eSPaulo Zanoni 237040da17c2SDaniel Vetter if (de_iir & DE_PIPE_CRC_DONE(pipe)) 237191d14251STvrtko Ursulin i9xx_pipe_crc_irq_handler(dev_priv, pipe); 2372c008bc6eSPaulo Zanoni } 2373c008bc6eSPaulo Zanoni 2374c008bc6eSPaulo Zanoni /* check event from PCH */ 2375c008bc6eSPaulo Zanoni if (de_iir & DE_PCH_EVENT) { 2376c008bc6eSPaulo Zanoni u32 pch_iir = I915_READ(SDEIIR); 2377c008bc6eSPaulo Zanoni 237891d14251STvrtko Ursulin if (HAS_PCH_CPT(dev_priv)) 237991d14251STvrtko Ursulin cpt_irq_handler(dev_priv, pch_iir); 2380c008bc6eSPaulo Zanoni else 238191d14251STvrtko Ursulin ibx_irq_handler(dev_priv, pch_iir); 2382c008bc6eSPaulo Zanoni 2383c008bc6eSPaulo Zanoni /* should clear PCH hotplug event before clear CPU irq */ 2384c008bc6eSPaulo Zanoni I915_WRITE(SDEIIR, pch_iir); 2385c008bc6eSPaulo Zanoni } 2386c008bc6eSPaulo Zanoni 2387cf819effSLucas De Marchi if (IS_GEN(dev_priv, 5) && de_iir & DE_PCU_EVENT) 238891d14251STvrtko Ursulin ironlake_rps_change_irq_handler(dev_priv); 2389c008bc6eSPaulo Zanoni } 2390c008bc6eSPaulo Zanoni 239191d14251STvrtko Ursulin static void ivb_display_irq_handler(struct drm_i915_private *dev_priv, 239291d14251STvrtko Ursulin u32 de_iir) 23939719fb98SPaulo Zanoni { 239407d27e20SDamien Lespiau enum pipe pipe; 239523bb4cb5SVille Syrjälä u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB; 239623bb4cb5SVille Syrjälä 239740e56410SVille Syrjälä if (hotplug_trigger) 239891d14251STvrtko Ursulin ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb); 23999719fb98SPaulo Zanoni 24009719fb98SPaulo Zanoni if (de_iir & DE_ERR_INT_IVB) 240191d14251STvrtko Ursulin ivb_err_int_handler(dev_priv); 24029719fb98SPaulo Zanoni 240354fd3149SDhinakaran Pandiyan if (de_iir & DE_EDP_PSR_INT_HSW) { 240454fd3149SDhinakaran Pandiyan u32 psr_iir = I915_READ(EDP_PSR_IIR); 240554fd3149SDhinakaran Pandiyan 240654fd3149SDhinakaran Pandiyan intel_psr_irq_handler(dev_priv, psr_iir); 240754fd3149SDhinakaran Pandiyan I915_WRITE(EDP_PSR_IIR, psr_iir); 240854fd3149SDhinakaran Pandiyan } 2409fc340442SDaniel Vetter 24109719fb98SPaulo Zanoni if (de_iir & DE_AUX_CHANNEL_A_IVB) 241191d14251STvrtko Ursulin dp_aux_irq_handler(dev_priv); 24129719fb98SPaulo Zanoni 24139719fb98SPaulo Zanoni if (de_iir & DE_GSE_IVB) 241491d14251STvrtko Ursulin intel_opregion_asle_intr(dev_priv); 24159719fb98SPaulo Zanoni 2416055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 2417fd3a4024SDaniel Vetter if (de_iir & (DE_PIPE_VBLANK_IVB(pipe))) 2418fd3a4024SDaniel Vetter drm_handle_vblank(&dev_priv->drm, pipe); 24199719fb98SPaulo Zanoni } 24209719fb98SPaulo Zanoni 24219719fb98SPaulo Zanoni /* check event from PCH */ 242291d14251STvrtko Ursulin if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) { 24239719fb98SPaulo Zanoni u32 pch_iir = I915_READ(SDEIIR); 24249719fb98SPaulo Zanoni 242591d14251STvrtko Ursulin cpt_irq_handler(dev_priv, pch_iir); 24269719fb98SPaulo Zanoni 24279719fb98SPaulo Zanoni /* clear PCH hotplug event before clear CPU irq */ 24289719fb98SPaulo Zanoni I915_WRITE(SDEIIR, pch_iir); 24299719fb98SPaulo Zanoni } 24309719fb98SPaulo Zanoni } 24319719fb98SPaulo Zanoni 243272c90f62SOscar Mateo /* 243372c90f62SOscar Mateo * To handle irqs with the minimum potential races with fresh interrupts, we: 243472c90f62SOscar Mateo * 1 - Disable Master Interrupt Control. 243572c90f62SOscar Mateo * 2 - Find the source(s) of the interrupt. 243672c90f62SOscar Mateo * 3 - Clear the Interrupt Identity bits (IIR). 243772c90f62SOscar Mateo * 4 - Process the interrupt(s) that had bits set in the IIRs. 243872c90f62SOscar Mateo * 5 - Re-enable Master Interrupt Control. 243972c90f62SOscar Mateo */ 2440f1af8fc1SPaulo Zanoni static irqreturn_t ironlake_irq_handler(int irq, void *arg) 2441b1f14ad0SJesse Barnes { 2442b318b824SVille Syrjälä struct drm_i915_private *dev_priv = arg; 2443f1af8fc1SPaulo Zanoni u32 de_iir, gt_iir, de_ier, sde_ier = 0; 24440e43406bSChris Wilson irqreturn_t ret = IRQ_NONE; 2445b1f14ad0SJesse Barnes 24462dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 24472dd2a883SImre Deak return IRQ_NONE; 24482dd2a883SImre Deak 24491f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 24509102650fSDaniele Ceraolo Spurio disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 24511f814dacSImre Deak 2452b1f14ad0SJesse Barnes /* disable master interrupt before clearing iir */ 2453b1f14ad0SJesse Barnes de_ier = I915_READ(DEIER); 2454b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL); 24550e43406bSChris Wilson 245644498aeaSPaulo Zanoni /* Disable south interrupts. We'll only write to SDEIIR once, so further 245744498aeaSPaulo Zanoni * interrupts will will be stored on its back queue, and then we'll be 245844498aeaSPaulo Zanoni * able to process them after we restore SDEIER (as soon as we restore 245944498aeaSPaulo Zanoni * it, we'll get an interrupt if SDEIIR still has something to process 246044498aeaSPaulo Zanoni * due to its back queue). */ 246191d14251STvrtko Ursulin if (!HAS_PCH_NOP(dev_priv)) { 246244498aeaSPaulo Zanoni sde_ier = I915_READ(SDEIER); 246344498aeaSPaulo Zanoni I915_WRITE(SDEIER, 0); 2464ab5c608bSBen Widawsky } 246544498aeaSPaulo Zanoni 246672c90f62SOscar Mateo /* Find, clear, then process each source of interrupt */ 246772c90f62SOscar Mateo 24680e43406bSChris Wilson gt_iir = I915_READ(GTIIR); 24690e43406bSChris Wilson if (gt_iir) { 247072c90f62SOscar Mateo I915_WRITE(GTIIR, gt_iir); 247172c90f62SOscar Mateo ret = IRQ_HANDLED; 247291d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 6) 2473cf1c97dcSAndi Shyti gen6_gt_irq_handler(&dev_priv->gt, gt_iir); 2474d8fc8a47SPaulo Zanoni else 2475cf1c97dcSAndi Shyti gen5_gt_irq_handler(&dev_priv->gt, gt_iir); 24760e43406bSChris Wilson } 2477b1f14ad0SJesse Barnes 2478b1f14ad0SJesse Barnes de_iir = I915_READ(DEIIR); 24790e43406bSChris Wilson if (de_iir) { 248072c90f62SOscar Mateo I915_WRITE(DEIIR, de_iir); 248172c90f62SOscar Mateo ret = IRQ_HANDLED; 248291d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 7) 248391d14251STvrtko Ursulin ivb_display_irq_handler(dev_priv, de_iir); 2484f1af8fc1SPaulo Zanoni else 248591d14251STvrtko Ursulin ilk_display_irq_handler(dev_priv, de_iir); 24860e43406bSChris Wilson } 24870e43406bSChris Wilson 248891d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 6) { 2489f1af8fc1SPaulo Zanoni u32 pm_iir = I915_READ(GEN6_PMIIR); 24900e43406bSChris Wilson if (pm_iir) { 2491b1f14ad0SJesse Barnes I915_WRITE(GEN6_PMIIR, pm_iir); 24920e43406bSChris Wilson ret = IRQ_HANDLED; 249372c90f62SOscar Mateo gen6_rps_irq_handler(dev_priv, pm_iir); 24940e43406bSChris Wilson } 2495f1af8fc1SPaulo Zanoni } 2496b1f14ad0SJesse Barnes 2497b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier); 249874093f3eSChris Wilson if (!HAS_PCH_NOP(dev_priv)) 249944498aeaSPaulo Zanoni I915_WRITE(SDEIER, sde_ier); 2500b1f14ad0SJesse Barnes 25011f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 25029102650fSDaniele Ceraolo Spurio enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 25031f814dacSImre Deak 2504b1f14ad0SJesse Barnes return ret; 2505b1f14ad0SJesse Barnes } 2506b1f14ad0SJesse Barnes 250791d14251STvrtko Ursulin static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv, 250891d14251STvrtko Ursulin u32 hotplug_trigger, 250940e56410SVille Syrjälä const u32 hpd[HPD_NUM_PINS]) 2510d04a492dSShashank Sharma { 2511cebd87a0SVille Syrjälä u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0; 2512d04a492dSShashank Sharma 2513a52bb15bSVille Syrjälä dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG); 2514a52bb15bSVille Syrjälä I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg); 2515d04a492dSShashank Sharma 2516cf53902fSRodrigo Vivi intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger, 251740e56410SVille Syrjälä dig_hotplug_reg, hpd, 2518cebd87a0SVille Syrjälä bxt_port_hotplug_long_detect); 251940e56410SVille Syrjälä 252091d14251STvrtko Ursulin intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 2521d04a492dSShashank Sharma } 2522d04a492dSShashank Sharma 2523121e758eSDhinakaran Pandiyan static void gen11_hpd_irq_handler(struct drm_i915_private *dev_priv, u32 iir) 2524121e758eSDhinakaran Pandiyan { 2525121e758eSDhinakaran Pandiyan u32 pin_mask = 0, long_mask = 0; 2526b796b971SDhinakaran Pandiyan u32 trigger_tc = iir & GEN11_DE_TC_HOTPLUG_MASK; 2527b796b971SDhinakaran Pandiyan u32 trigger_tbt = iir & GEN11_DE_TBT_HOTPLUG_MASK; 252848ef15d3SJosé Roberto de Souza long_pulse_detect_func long_pulse_detect; 252948ef15d3SJosé Roberto de Souza const u32 *hpd; 253048ef15d3SJosé Roberto de Souza 253148ef15d3SJosé Roberto de Souza if (INTEL_GEN(dev_priv) >= 12) { 253248ef15d3SJosé Roberto de Souza long_pulse_detect = gen12_port_hotplug_long_detect; 253348ef15d3SJosé Roberto de Souza hpd = hpd_gen12; 253448ef15d3SJosé Roberto de Souza } else { 253548ef15d3SJosé Roberto de Souza long_pulse_detect = gen11_port_hotplug_long_detect; 253648ef15d3SJosé Roberto de Souza hpd = hpd_gen11; 253748ef15d3SJosé Roberto de Souza } 2538121e758eSDhinakaran Pandiyan 2539121e758eSDhinakaran Pandiyan if (trigger_tc) { 2540b796b971SDhinakaran Pandiyan u32 dig_hotplug_reg; 2541b796b971SDhinakaran Pandiyan 2542121e758eSDhinakaran Pandiyan dig_hotplug_reg = I915_READ(GEN11_TC_HOTPLUG_CTL); 2543121e758eSDhinakaran Pandiyan I915_WRITE(GEN11_TC_HOTPLUG_CTL, dig_hotplug_reg); 2544121e758eSDhinakaran Pandiyan 2545121e758eSDhinakaran Pandiyan intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, trigger_tc, 254648ef15d3SJosé Roberto de Souza dig_hotplug_reg, hpd, long_pulse_detect); 2547121e758eSDhinakaran Pandiyan } 2548b796b971SDhinakaran Pandiyan 2549b796b971SDhinakaran Pandiyan if (trigger_tbt) { 2550b796b971SDhinakaran Pandiyan u32 dig_hotplug_reg; 2551b796b971SDhinakaran Pandiyan 2552b796b971SDhinakaran Pandiyan dig_hotplug_reg = I915_READ(GEN11_TBT_HOTPLUG_CTL); 2553b796b971SDhinakaran Pandiyan I915_WRITE(GEN11_TBT_HOTPLUG_CTL, dig_hotplug_reg); 2554b796b971SDhinakaran Pandiyan 2555b796b971SDhinakaran Pandiyan intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, trigger_tbt, 255648ef15d3SJosé Roberto de Souza dig_hotplug_reg, hpd, long_pulse_detect); 2557b796b971SDhinakaran Pandiyan } 2558b796b971SDhinakaran Pandiyan 2559b796b971SDhinakaran Pandiyan if (pin_mask) 2560b796b971SDhinakaran Pandiyan intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 2561b796b971SDhinakaran Pandiyan else 2562b796b971SDhinakaran Pandiyan DRM_ERROR("Unexpected DE HPD interrupt 0x%08x\n", iir); 2563121e758eSDhinakaran Pandiyan } 2564121e758eSDhinakaran Pandiyan 25659d17210fSLucas De Marchi static u32 gen8_de_port_aux_mask(struct drm_i915_private *dev_priv) 25669d17210fSLucas De Marchi { 256755523360SLucas De Marchi u32 mask; 25689d17210fSLucas De Marchi 256955523360SLucas De Marchi if (INTEL_GEN(dev_priv) >= 12) 257055523360SLucas De Marchi /* TODO: Add AUX entries for USBC */ 257155523360SLucas De Marchi return TGL_DE_PORT_AUX_DDIA | 257255523360SLucas De Marchi TGL_DE_PORT_AUX_DDIB | 257355523360SLucas De Marchi TGL_DE_PORT_AUX_DDIC; 257455523360SLucas De Marchi 257555523360SLucas De Marchi mask = GEN8_AUX_CHANNEL_A; 25769d17210fSLucas De Marchi if (INTEL_GEN(dev_priv) >= 9) 25779d17210fSLucas De Marchi mask |= GEN9_AUX_CHANNEL_B | 25789d17210fSLucas De Marchi GEN9_AUX_CHANNEL_C | 25799d17210fSLucas De Marchi GEN9_AUX_CHANNEL_D; 25809d17210fSLucas De Marchi 258155523360SLucas De Marchi if (IS_CNL_WITH_PORT_F(dev_priv) || IS_GEN(dev_priv, 11)) 25829d17210fSLucas De Marchi mask |= CNL_AUX_CHANNEL_F; 25839d17210fSLucas De Marchi 258455523360SLucas De Marchi if (IS_GEN(dev_priv, 11)) 258555523360SLucas De Marchi mask |= ICL_AUX_CHANNEL_E; 25869d17210fSLucas De Marchi 25879d17210fSLucas De Marchi return mask; 25889d17210fSLucas De Marchi } 25899d17210fSLucas De Marchi 25905270130dSVille Syrjälä static u32 gen8_de_pipe_fault_mask(struct drm_i915_private *dev_priv) 25915270130dSVille Syrjälä { 25925270130dSVille Syrjälä if (INTEL_GEN(dev_priv) >= 9) 25935270130dSVille Syrjälä return GEN9_DE_PIPE_IRQ_FAULT_ERRORS; 25945270130dSVille Syrjälä else 25955270130dSVille Syrjälä return GEN8_DE_PIPE_IRQ_FAULT_ERRORS; 25965270130dSVille Syrjälä } 25975270130dSVille Syrjälä 259846c63d24SJosé Roberto de Souza static void 259946c63d24SJosé Roberto de Souza gen8_de_misc_irq_handler(struct drm_i915_private *dev_priv, u32 iir) 2600abd58f01SBen Widawsky { 2601e04f7eceSVille Syrjälä bool found = false; 2602e04f7eceSVille Syrjälä 2603e04f7eceSVille Syrjälä if (iir & GEN8_DE_MISC_GSE) { 260491d14251STvrtko Ursulin intel_opregion_asle_intr(dev_priv); 2605e04f7eceSVille Syrjälä found = true; 2606e04f7eceSVille Syrjälä } 2607e04f7eceSVille Syrjälä 2608e04f7eceSVille Syrjälä if (iir & GEN8_DE_EDP_PSR) { 26098241cfbeSJosé Roberto de Souza u32 psr_iir; 26108241cfbeSJosé Roberto de Souza i915_reg_t iir_reg; 26118241cfbeSJosé Roberto de Souza 26128241cfbeSJosé Roberto de Souza if (INTEL_GEN(dev_priv) >= 12) 26138241cfbeSJosé Roberto de Souza iir_reg = TRANS_PSR_IIR(dev_priv->psr.transcoder); 26148241cfbeSJosé Roberto de Souza else 26158241cfbeSJosé Roberto de Souza iir_reg = EDP_PSR_IIR; 26168241cfbeSJosé Roberto de Souza 26178241cfbeSJosé Roberto de Souza psr_iir = I915_READ(iir_reg); 26188241cfbeSJosé Roberto de Souza I915_WRITE(iir_reg, psr_iir); 26198241cfbeSJosé Roberto de Souza 26208241cfbeSJosé Roberto de Souza if (psr_iir) 26218241cfbeSJosé Roberto de Souza found = true; 262254fd3149SDhinakaran Pandiyan 262354fd3149SDhinakaran Pandiyan intel_psr_irq_handler(dev_priv, psr_iir); 2624e04f7eceSVille Syrjälä } 2625e04f7eceSVille Syrjälä 2626e04f7eceSVille Syrjälä if (!found) 262738cc46d7SOscar Mateo DRM_ERROR("Unexpected DE Misc interrupt\n"); 2628abd58f01SBen Widawsky } 262946c63d24SJosé Roberto de Souza 263046c63d24SJosé Roberto de Souza static irqreturn_t 263146c63d24SJosé Roberto de Souza gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl) 263246c63d24SJosé Roberto de Souza { 263346c63d24SJosé Roberto de Souza irqreturn_t ret = IRQ_NONE; 263446c63d24SJosé Roberto de Souza u32 iir; 263546c63d24SJosé Roberto de Souza enum pipe pipe; 263646c63d24SJosé Roberto de Souza 263746c63d24SJosé Roberto de Souza if (master_ctl & GEN8_DE_MISC_IRQ) { 263846c63d24SJosé Roberto de Souza iir = I915_READ(GEN8_DE_MISC_IIR); 263946c63d24SJosé Roberto de Souza if (iir) { 264046c63d24SJosé Roberto de Souza I915_WRITE(GEN8_DE_MISC_IIR, iir); 264146c63d24SJosé Roberto de Souza ret = IRQ_HANDLED; 264246c63d24SJosé Roberto de Souza gen8_de_misc_irq_handler(dev_priv, iir); 264346c63d24SJosé Roberto de Souza } else { 264438cc46d7SOscar Mateo DRM_ERROR("The master control interrupt lied (DE MISC)!\n"); 2645abd58f01SBen Widawsky } 264646c63d24SJosé Roberto de Souza } 2647abd58f01SBen Widawsky 2648121e758eSDhinakaran Pandiyan if (INTEL_GEN(dev_priv) >= 11 && (master_ctl & GEN11_DE_HPD_IRQ)) { 2649121e758eSDhinakaran Pandiyan iir = I915_READ(GEN11_DE_HPD_IIR); 2650121e758eSDhinakaran Pandiyan if (iir) { 2651121e758eSDhinakaran Pandiyan I915_WRITE(GEN11_DE_HPD_IIR, iir); 2652121e758eSDhinakaran Pandiyan ret = IRQ_HANDLED; 2653121e758eSDhinakaran Pandiyan gen11_hpd_irq_handler(dev_priv, iir); 2654121e758eSDhinakaran Pandiyan } else { 2655121e758eSDhinakaran Pandiyan DRM_ERROR("The master control interrupt lied, (DE HPD)!\n"); 2656121e758eSDhinakaran Pandiyan } 2657121e758eSDhinakaran Pandiyan } 2658121e758eSDhinakaran Pandiyan 26596d766f02SDaniel Vetter if (master_ctl & GEN8_DE_PORT_IRQ) { 2660e32192e1STvrtko Ursulin iir = I915_READ(GEN8_DE_PORT_IIR); 2661e32192e1STvrtko Ursulin if (iir) { 2662e32192e1STvrtko Ursulin u32 tmp_mask; 2663d04a492dSShashank Sharma bool found = false; 2664cebd87a0SVille Syrjälä 2665e32192e1STvrtko Ursulin I915_WRITE(GEN8_DE_PORT_IIR, iir); 26666d766f02SDaniel Vetter ret = IRQ_HANDLED; 266788e04703SJesse Barnes 26689d17210fSLucas De Marchi if (iir & gen8_de_port_aux_mask(dev_priv)) { 266991d14251STvrtko Ursulin dp_aux_irq_handler(dev_priv); 2670d04a492dSShashank Sharma found = true; 2671d04a492dSShashank Sharma } 2672d04a492dSShashank Sharma 2673cc3f90f0SAnder Conselvan de Oliveira if (IS_GEN9_LP(dev_priv)) { 2674e32192e1STvrtko Ursulin tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK; 2675e32192e1STvrtko Ursulin if (tmp_mask) { 267691d14251STvrtko Ursulin bxt_hpd_irq_handler(dev_priv, tmp_mask, 267791d14251STvrtko Ursulin hpd_bxt); 2678d04a492dSShashank Sharma found = true; 2679d04a492dSShashank Sharma } 2680e32192e1STvrtko Ursulin } else if (IS_BROADWELL(dev_priv)) { 2681e32192e1STvrtko Ursulin tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG; 2682e32192e1STvrtko Ursulin if (tmp_mask) { 268391d14251STvrtko Ursulin ilk_hpd_irq_handler(dev_priv, 268491d14251STvrtko Ursulin tmp_mask, hpd_bdw); 2685e32192e1STvrtko Ursulin found = true; 2686e32192e1STvrtko Ursulin } 2687e32192e1STvrtko Ursulin } 2688d04a492dSShashank Sharma 2689cc3f90f0SAnder Conselvan de Oliveira if (IS_GEN9_LP(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) { 269091d14251STvrtko Ursulin gmbus_irq_handler(dev_priv); 26919e63743eSShashank Sharma found = true; 26929e63743eSShashank Sharma } 26939e63743eSShashank Sharma 2694d04a492dSShashank Sharma if (!found) 269538cc46d7SOscar Mateo DRM_ERROR("Unexpected DE Port interrupt\n"); 26966d766f02SDaniel Vetter } 269738cc46d7SOscar Mateo else 269838cc46d7SOscar Mateo DRM_ERROR("The master control interrupt lied (DE PORT)!\n"); 26996d766f02SDaniel Vetter } 27006d766f02SDaniel Vetter 2701055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 2702fd3a4024SDaniel Vetter u32 fault_errors; 2703abd58f01SBen Widawsky 2704c42664ccSDaniel Vetter if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe))) 2705c42664ccSDaniel Vetter continue; 2706c42664ccSDaniel Vetter 2707e32192e1STvrtko Ursulin iir = I915_READ(GEN8_DE_PIPE_IIR(pipe)); 2708e32192e1STvrtko Ursulin if (!iir) { 2709e32192e1STvrtko Ursulin DRM_ERROR("The master control interrupt lied (DE PIPE)!\n"); 2710e32192e1STvrtko Ursulin continue; 2711e32192e1STvrtko Ursulin } 2712770de83dSDamien Lespiau 2713e32192e1STvrtko Ursulin ret = IRQ_HANDLED; 2714e32192e1STvrtko Ursulin I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir); 2715e32192e1STvrtko Ursulin 2716fd3a4024SDaniel Vetter if (iir & GEN8_PIPE_VBLANK) 2717fd3a4024SDaniel Vetter drm_handle_vblank(&dev_priv->drm, pipe); 2718abd58f01SBen Widawsky 2719e32192e1STvrtko Ursulin if (iir & GEN8_PIPE_CDCLK_CRC_DONE) 272091d14251STvrtko Ursulin hsw_pipe_crc_irq_handler(dev_priv, pipe); 27210fbe7870SDaniel Vetter 2722e32192e1STvrtko Ursulin if (iir & GEN8_PIPE_FIFO_UNDERRUN) 2723e32192e1STvrtko Ursulin intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 272438d83c96SDaniel Vetter 27255270130dSVille Syrjälä fault_errors = iir & gen8_de_pipe_fault_mask(dev_priv); 2726770de83dSDamien Lespiau if (fault_errors) 27271353ec38STvrtko Ursulin DRM_ERROR("Fault errors on pipe %c: 0x%08x\n", 272830100f2bSDaniel Vetter pipe_name(pipe), 2729e32192e1STvrtko Ursulin fault_errors); 2730abd58f01SBen Widawsky } 2731abd58f01SBen Widawsky 273291d14251STvrtko Ursulin if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) && 2733266ea3d9SShashank Sharma master_ctl & GEN8_DE_PCH_IRQ) { 273492d03a80SDaniel Vetter /* 273592d03a80SDaniel Vetter * FIXME(BDW): Assume for now that the new interrupt handling 273692d03a80SDaniel Vetter * scheme also closed the SDE interrupt handling race we've seen 273792d03a80SDaniel Vetter * on older pch-split platforms. But this needs testing. 273892d03a80SDaniel Vetter */ 2739e32192e1STvrtko Ursulin iir = I915_READ(SDEIIR); 2740e32192e1STvrtko Ursulin if (iir) { 2741e32192e1STvrtko Ursulin I915_WRITE(SDEIIR, iir); 274292d03a80SDaniel Vetter ret = IRQ_HANDLED; 27436dbf30ceSVille Syrjälä 274458676af6SLucas De Marchi if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP) 274558676af6SLucas De Marchi icp_irq_handler(dev_priv, iir); 2746c6c30b91SRodrigo Vivi else if (INTEL_PCH_TYPE(dev_priv) >= PCH_SPT) 274791d14251STvrtko Ursulin spt_irq_handler(dev_priv, iir); 27486dbf30ceSVille Syrjälä else 274991d14251STvrtko Ursulin cpt_irq_handler(dev_priv, iir); 27502dfb0b81SJani Nikula } else { 27512dfb0b81SJani Nikula /* 27522dfb0b81SJani Nikula * Like on previous PCH there seems to be something 27532dfb0b81SJani Nikula * fishy going on with forwarding PCH interrupts. 27542dfb0b81SJani Nikula */ 27552dfb0b81SJani Nikula DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n"); 27562dfb0b81SJani Nikula } 275792d03a80SDaniel Vetter } 275892d03a80SDaniel Vetter 2759f11a0f46STvrtko Ursulin return ret; 2760f11a0f46STvrtko Ursulin } 2761f11a0f46STvrtko Ursulin 27624376b9c9SMika Kuoppala static inline u32 gen8_master_intr_disable(void __iomem * const regs) 27634376b9c9SMika Kuoppala { 27644376b9c9SMika Kuoppala raw_reg_write(regs, GEN8_MASTER_IRQ, 0); 27654376b9c9SMika Kuoppala 27664376b9c9SMika Kuoppala /* 27674376b9c9SMika Kuoppala * Now with master disabled, get a sample of level indications 27684376b9c9SMika Kuoppala * for this interrupt. Indications will be cleared on related acks. 27694376b9c9SMika Kuoppala * New indications can and will light up during processing, 27704376b9c9SMika Kuoppala * and will generate new interrupt after enabling master. 27714376b9c9SMika Kuoppala */ 27724376b9c9SMika Kuoppala return raw_reg_read(regs, GEN8_MASTER_IRQ); 27734376b9c9SMika Kuoppala } 27744376b9c9SMika Kuoppala 27754376b9c9SMika Kuoppala static inline void gen8_master_intr_enable(void __iomem * const regs) 27764376b9c9SMika Kuoppala { 27774376b9c9SMika Kuoppala raw_reg_write(regs, GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); 27784376b9c9SMika Kuoppala } 27794376b9c9SMika Kuoppala 2780f11a0f46STvrtko Ursulin static irqreturn_t gen8_irq_handler(int irq, void *arg) 2781f11a0f46STvrtko Ursulin { 2782b318b824SVille Syrjälä struct drm_i915_private *dev_priv = arg; 278325286aacSDaniele Ceraolo Spurio void __iomem * const regs = dev_priv->uncore.regs; 2784f11a0f46STvrtko Ursulin u32 master_ctl; 2785f0fd96f5SChris Wilson u32 gt_iir[4]; 2786f11a0f46STvrtko Ursulin 2787f11a0f46STvrtko Ursulin if (!intel_irqs_enabled(dev_priv)) 2788f11a0f46STvrtko Ursulin return IRQ_NONE; 2789f11a0f46STvrtko Ursulin 27904376b9c9SMika Kuoppala master_ctl = gen8_master_intr_disable(regs); 27914376b9c9SMika Kuoppala if (!master_ctl) { 27924376b9c9SMika Kuoppala gen8_master_intr_enable(regs); 2793f11a0f46STvrtko Ursulin return IRQ_NONE; 27944376b9c9SMika Kuoppala } 2795f11a0f46STvrtko Ursulin 2796f11a0f46STvrtko Ursulin /* Find, clear, then process each source of interrupt */ 2797cf1c97dcSAndi Shyti gen8_gt_irq_ack(&dev_priv->gt, master_ctl, gt_iir); 2798f0fd96f5SChris Wilson 2799f0fd96f5SChris Wilson /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 2800f0fd96f5SChris Wilson if (master_ctl & ~GEN8_GT_IRQS) { 28019102650fSDaniele Ceraolo Spurio disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 280255ef72f2SChris Wilson gen8_de_irq_handler(dev_priv, master_ctl); 28039102650fSDaniele Ceraolo Spurio enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 2804f0fd96f5SChris Wilson } 2805f11a0f46STvrtko Ursulin 28064376b9c9SMika Kuoppala gen8_master_intr_enable(regs); 2807abd58f01SBen Widawsky 2808cf1c97dcSAndi Shyti gen8_gt_irq_handler(&dev_priv->gt, master_ctl, gt_iir); 28091f814dacSImre Deak 281055ef72f2SChris Wilson return IRQ_HANDLED; 2811abd58f01SBen Widawsky } 2812abd58f01SBen Widawsky 281351951ae7SMika Kuoppala static u32 28149b77011eSTvrtko Ursulin gen11_gu_misc_irq_ack(struct intel_gt *gt, const u32 master_ctl) 2815df0d28c1SDhinakaran Pandiyan { 28169b77011eSTvrtko Ursulin void __iomem * const regs = gt->uncore->regs; 28177a909383SChris Wilson u32 iir; 2818df0d28c1SDhinakaran Pandiyan 2819df0d28c1SDhinakaran Pandiyan if (!(master_ctl & GEN11_GU_MISC_IRQ)) 28207a909383SChris Wilson return 0; 2821df0d28c1SDhinakaran Pandiyan 28227a909383SChris Wilson iir = raw_reg_read(regs, GEN11_GU_MISC_IIR); 28237a909383SChris Wilson if (likely(iir)) 28247a909383SChris Wilson raw_reg_write(regs, GEN11_GU_MISC_IIR, iir); 28257a909383SChris Wilson 28267a909383SChris Wilson return iir; 2827df0d28c1SDhinakaran Pandiyan } 2828df0d28c1SDhinakaran Pandiyan 2829df0d28c1SDhinakaran Pandiyan static void 28309b77011eSTvrtko Ursulin gen11_gu_misc_irq_handler(struct intel_gt *gt, const u32 iir) 2831df0d28c1SDhinakaran Pandiyan { 2832df0d28c1SDhinakaran Pandiyan if (iir & GEN11_GU_MISC_GSE) 28339b77011eSTvrtko Ursulin intel_opregion_asle_intr(gt->i915); 2834df0d28c1SDhinakaran Pandiyan } 2835df0d28c1SDhinakaran Pandiyan 283681067b71SMika Kuoppala static inline u32 gen11_master_intr_disable(void __iomem * const regs) 283781067b71SMika Kuoppala { 283881067b71SMika Kuoppala raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, 0); 283981067b71SMika Kuoppala 284081067b71SMika Kuoppala /* 284181067b71SMika Kuoppala * Now with master disabled, get a sample of level indications 284281067b71SMika Kuoppala * for this interrupt. Indications will be cleared on related acks. 284381067b71SMika Kuoppala * New indications can and will light up during processing, 284481067b71SMika Kuoppala * and will generate new interrupt after enabling master. 284581067b71SMika Kuoppala */ 284681067b71SMika Kuoppala return raw_reg_read(regs, GEN11_GFX_MSTR_IRQ); 284781067b71SMika Kuoppala } 284881067b71SMika Kuoppala 284981067b71SMika Kuoppala static inline void gen11_master_intr_enable(void __iomem * const regs) 285081067b71SMika Kuoppala { 285181067b71SMika Kuoppala raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, GEN11_MASTER_IRQ); 285281067b71SMika Kuoppala } 285381067b71SMika Kuoppala 285451951ae7SMika Kuoppala static irqreturn_t gen11_irq_handler(int irq, void *arg) 285551951ae7SMika Kuoppala { 2856b318b824SVille Syrjälä struct drm_i915_private * const i915 = arg; 285725286aacSDaniele Ceraolo Spurio void __iomem * const regs = i915->uncore.regs; 28589b77011eSTvrtko Ursulin struct intel_gt *gt = &i915->gt; 285951951ae7SMika Kuoppala u32 master_ctl; 2860df0d28c1SDhinakaran Pandiyan u32 gu_misc_iir; 286151951ae7SMika Kuoppala 286251951ae7SMika Kuoppala if (!intel_irqs_enabled(i915)) 286351951ae7SMika Kuoppala return IRQ_NONE; 286451951ae7SMika Kuoppala 286581067b71SMika Kuoppala master_ctl = gen11_master_intr_disable(regs); 286681067b71SMika Kuoppala if (!master_ctl) { 286781067b71SMika Kuoppala gen11_master_intr_enable(regs); 286851951ae7SMika Kuoppala return IRQ_NONE; 286981067b71SMika Kuoppala } 287051951ae7SMika Kuoppala 287151951ae7SMika Kuoppala /* Find, clear, then process each source of interrupt. */ 28729b77011eSTvrtko Ursulin gen11_gt_irq_handler(gt, master_ctl); 287351951ae7SMika Kuoppala 287451951ae7SMika Kuoppala /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 287551951ae7SMika Kuoppala if (master_ctl & GEN11_DISPLAY_IRQ) { 287651951ae7SMika Kuoppala const u32 disp_ctl = raw_reg_read(regs, GEN11_DISPLAY_INT_CTL); 287751951ae7SMika Kuoppala 28789102650fSDaniele Ceraolo Spurio disable_rpm_wakeref_asserts(&i915->runtime_pm); 287951951ae7SMika Kuoppala /* 288051951ae7SMika Kuoppala * GEN11_DISPLAY_INT_CTL has same format as GEN8_MASTER_IRQ 288151951ae7SMika Kuoppala * for the display related bits. 288251951ae7SMika Kuoppala */ 288351951ae7SMika Kuoppala gen8_de_irq_handler(i915, disp_ctl); 28849102650fSDaniele Ceraolo Spurio enable_rpm_wakeref_asserts(&i915->runtime_pm); 288551951ae7SMika Kuoppala } 288651951ae7SMika Kuoppala 28879b77011eSTvrtko Ursulin gu_misc_iir = gen11_gu_misc_irq_ack(gt, master_ctl); 2888df0d28c1SDhinakaran Pandiyan 288981067b71SMika Kuoppala gen11_master_intr_enable(regs); 289051951ae7SMika Kuoppala 28919b77011eSTvrtko Ursulin gen11_gu_misc_irq_handler(gt, gu_misc_iir); 2892df0d28c1SDhinakaran Pandiyan 289351951ae7SMika Kuoppala return IRQ_HANDLED; 289451951ae7SMika Kuoppala } 289551951ae7SMika Kuoppala 289642f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 289742f52ef8SKeith Packard * we use as a pipe index 289842f52ef8SKeith Packard */ 289908fa8fd0SVille Syrjälä int i8xx_enable_vblank(struct drm_crtc *crtc) 29000a3e67a4SJesse Barnes { 290108fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 290208fa8fd0SVille Syrjälä enum pipe pipe = to_intel_crtc(crtc)->pipe; 2903e9d21d7fSKeith Packard unsigned long irqflags; 290471e0ffa5SJesse Barnes 29051ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 290686e83e35SChris Wilson i915_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS); 290786e83e35SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 290886e83e35SChris Wilson 290986e83e35SChris Wilson return 0; 291086e83e35SChris Wilson } 291186e83e35SChris Wilson 29127d423af9SVille Syrjälä int i915gm_enable_vblank(struct drm_crtc *crtc) 2913d938da6bSVille Syrjälä { 291408fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 2915d938da6bSVille Syrjälä 29167d423af9SVille Syrjälä /* 29177d423af9SVille Syrjälä * Vblank interrupts fail to wake the device up from C2+. 29187d423af9SVille Syrjälä * Disabling render clock gating during C-states avoids 29197d423af9SVille Syrjälä * the problem. There is a small power cost so we do this 29207d423af9SVille Syrjälä * only when vblank interrupts are actually enabled. 29217d423af9SVille Syrjälä */ 29227d423af9SVille Syrjälä if (dev_priv->vblank_enabled++ == 0) 29237d423af9SVille Syrjälä I915_WRITE(SCPD0, _MASKED_BIT_ENABLE(CSTATE_RENDER_CLOCK_GATE_DISABLE)); 2924d938da6bSVille Syrjälä 292508fa8fd0SVille Syrjälä return i8xx_enable_vblank(crtc); 2926d938da6bSVille Syrjälä } 2927d938da6bSVille Syrjälä 292808fa8fd0SVille Syrjälä int i965_enable_vblank(struct drm_crtc *crtc) 292986e83e35SChris Wilson { 293008fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 293108fa8fd0SVille Syrjälä enum pipe pipe = to_intel_crtc(crtc)->pipe; 293286e83e35SChris Wilson unsigned long irqflags; 293386e83e35SChris Wilson 293486e83e35SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 29357c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 2936755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 29371ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 29388692d00eSChris Wilson 29390a3e67a4SJesse Barnes return 0; 29400a3e67a4SJesse Barnes } 29410a3e67a4SJesse Barnes 294208fa8fd0SVille Syrjälä int ilk_enable_vblank(struct drm_crtc *crtc) 2943f796cf8fSJesse Barnes { 294408fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 294508fa8fd0SVille Syrjälä enum pipe pipe = to_intel_crtc(crtc)->pipe; 2946f796cf8fSJesse Barnes unsigned long irqflags; 2947a9c287c9SJani Nikula u32 bit = INTEL_GEN(dev_priv) >= 7 ? 294886e83e35SChris Wilson DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe); 2949f796cf8fSJesse Barnes 2950f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2951fbdedaeaSVille Syrjälä ilk_enable_display_irq(dev_priv, bit); 2952b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2953b1f14ad0SJesse Barnes 29542e8bf223SDhinakaran Pandiyan /* Even though there is no DMC, frame counter can get stuck when 29552e8bf223SDhinakaran Pandiyan * PSR is active as no frames are generated. 29562e8bf223SDhinakaran Pandiyan */ 29572e8bf223SDhinakaran Pandiyan if (HAS_PSR(dev_priv)) 295808fa8fd0SVille Syrjälä drm_crtc_vblank_restore(crtc); 29592e8bf223SDhinakaran Pandiyan 2960b1f14ad0SJesse Barnes return 0; 2961b1f14ad0SJesse Barnes } 2962b1f14ad0SJesse Barnes 296308fa8fd0SVille Syrjälä int bdw_enable_vblank(struct drm_crtc *crtc) 2964abd58f01SBen Widawsky { 296508fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 296608fa8fd0SVille Syrjälä enum pipe pipe = to_intel_crtc(crtc)->pipe; 2967abd58f01SBen Widawsky unsigned long irqflags; 2968abd58f01SBen Widawsky 2969abd58f01SBen Widawsky spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2970013d3752SVille Syrjälä bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK); 2971abd58f01SBen Widawsky spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2972013d3752SVille Syrjälä 29732e8bf223SDhinakaran Pandiyan /* Even if there is no DMC, frame counter can get stuck when 29742e8bf223SDhinakaran Pandiyan * PSR is active as no frames are generated, so check only for PSR. 29752e8bf223SDhinakaran Pandiyan */ 29762e8bf223SDhinakaran Pandiyan if (HAS_PSR(dev_priv)) 297708fa8fd0SVille Syrjälä drm_crtc_vblank_restore(crtc); 29782e8bf223SDhinakaran Pandiyan 2979abd58f01SBen Widawsky return 0; 2980abd58f01SBen Widawsky } 2981abd58f01SBen Widawsky 298242f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 298342f52ef8SKeith Packard * we use as a pipe index 298442f52ef8SKeith Packard */ 298508fa8fd0SVille Syrjälä void i8xx_disable_vblank(struct drm_crtc *crtc) 298686e83e35SChris Wilson { 298708fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 298808fa8fd0SVille Syrjälä enum pipe pipe = to_intel_crtc(crtc)->pipe; 298986e83e35SChris Wilson unsigned long irqflags; 299086e83e35SChris Wilson 299186e83e35SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 299286e83e35SChris Wilson i915_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS); 299386e83e35SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 299486e83e35SChris Wilson } 299586e83e35SChris Wilson 29967d423af9SVille Syrjälä void i915gm_disable_vblank(struct drm_crtc *crtc) 2997d938da6bSVille Syrjälä { 299808fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 2999d938da6bSVille Syrjälä 300008fa8fd0SVille Syrjälä i8xx_disable_vblank(crtc); 3001d938da6bSVille Syrjälä 30027d423af9SVille Syrjälä if (--dev_priv->vblank_enabled == 0) 30037d423af9SVille Syrjälä I915_WRITE(SCPD0, _MASKED_BIT_DISABLE(CSTATE_RENDER_CLOCK_GATE_DISABLE)); 3004d938da6bSVille Syrjälä } 3005d938da6bSVille Syrjälä 300608fa8fd0SVille Syrjälä void i965_disable_vblank(struct drm_crtc *crtc) 30070a3e67a4SJesse Barnes { 300808fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 300908fa8fd0SVille Syrjälä enum pipe pipe = to_intel_crtc(crtc)->pipe; 3010e9d21d7fSKeith Packard unsigned long irqflags; 30110a3e67a4SJesse Barnes 30121ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 30137c463586SKeith Packard i915_disable_pipestat(dev_priv, pipe, 3014755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 30151ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 30160a3e67a4SJesse Barnes } 30170a3e67a4SJesse Barnes 301808fa8fd0SVille Syrjälä void ilk_disable_vblank(struct drm_crtc *crtc) 3019f796cf8fSJesse Barnes { 302008fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 302108fa8fd0SVille Syrjälä enum pipe pipe = to_intel_crtc(crtc)->pipe; 3022f796cf8fSJesse Barnes unsigned long irqflags; 3023a9c287c9SJani Nikula u32 bit = INTEL_GEN(dev_priv) >= 7 ? 302486e83e35SChris Wilson DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe); 3025f796cf8fSJesse Barnes 3026f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3027fbdedaeaSVille Syrjälä ilk_disable_display_irq(dev_priv, bit); 3028b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3029b1f14ad0SJesse Barnes } 3030b1f14ad0SJesse Barnes 303108fa8fd0SVille Syrjälä void bdw_disable_vblank(struct drm_crtc *crtc) 3032abd58f01SBen Widawsky { 303308fa8fd0SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->dev); 303408fa8fd0SVille Syrjälä enum pipe pipe = to_intel_crtc(crtc)->pipe; 3035abd58f01SBen Widawsky unsigned long irqflags; 3036abd58f01SBen Widawsky 3037abd58f01SBen Widawsky spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3038013d3752SVille Syrjälä bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK); 3039abd58f01SBen Widawsky spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3040abd58f01SBen Widawsky } 3041abd58f01SBen Widawsky 3042b243f530STvrtko Ursulin static void ibx_irq_reset(struct drm_i915_private *dev_priv) 304391738a95SPaulo Zanoni { 3044b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 3045b16b2a2fSPaulo Zanoni 30466e266956STvrtko Ursulin if (HAS_PCH_NOP(dev_priv)) 304791738a95SPaulo Zanoni return; 304891738a95SPaulo Zanoni 3049b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, SDE); 3050105b122eSPaulo Zanoni 30516e266956STvrtko Ursulin if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv)) 3052105b122eSPaulo Zanoni I915_WRITE(SERR_INT, 0xffffffff); 3053622364b6SPaulo Zanoni } 3054105b122eSPaulo Zanoni 305591738a95SPaulo Zanoni /* 3056622364b6SPaulo Zanoni * SDEIER is also touched by the interrupt handler to work around missed PCH 3057622364b6SPaulo Zanoni * interrupts. Hence we can't update it after the interrupt handler is enabled - 3058622364b6SPaulo Zanoni * instead we unconditionally enable all PCH interrupt sources here, but then 3059622364b6SPaulo Zanoni * only unmask them as needed with SDEIMR. 3060622364b6SPaulo Zanoni * 3061622364b6SPaulo Zanoni * This function needs to be called before interrupts are enabled. 306291738a95SPaulo Zanoni */ 3063b318b824SVille Syrjälä static void ibx_irq_pre_postinstall(struct drm_i915_private *dev_priv) 3064622364b6SPaulo Zanoni { 30656e266956STvrtko Ursulin if (HAS_PCH_NOP(dev_priv)) 3066622364b6SPaulo Zanoni return; 3067622364b6SPaulo Zanoni 3068622364b6SPaulo Zanoni WARN_ON(I915_READ(SDEIER) != 0); 306991738a95SPaulo Zanoni I915_WRITE(SDEIER, 0xffffffff); 307091738a95SPaulo Zanoni POSTING_READ(SDEIER); 307191738a95SPaulo Zanoni } 307291738a95SPaulo Zanoni 307370591a41SVille Syrjälä static void vlv_display_irq_reset(struct drm_i915_private *dev_priv) 307470591a41SVille Syrjälä { 3075b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 3076b16b2a2fSPaulo Zanoni 307771b8b41dSVille Syrjälä if (IS_CHERRYVIEW(dev_priv)) 3078f0818984STvrtko Ursulin intel_uncore_write(uncore, DPINVGTT, DPINVGTT_STATUS_MASK_CHV); 307971b8b41dSVille Syrjälä else 3080f0818984STvrtko Ursulin intel_uncore_write(uncore, DPINVGTT, DPINVGTT_STATUS_MASK); 308171b8b41dSVille Syrjälä 3082ad22d106SVille Syrjälä i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0); 3083f0818984STvrtko Ursulin intel_uncore_write(uncore, PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 308470591a41SVille Syrjälä 308544d9241eSVille Syrjälä i9xx_pipestat_irq_reset(dev_priv); 308670591a41SVille Syrjälä 3087b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, VLV_); 30888bd099a7SChris Wilson dev_priv->irq_mask = ~0u; 308970591a41SVille Syrjälä } 309070591a41SVille Syrjälä 30918bb61306SVille Syrjälä static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv) 30928bb61306SVille Syrjälä { 3093b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 3094b16b2a2fSPaulo Zanoni 30958bb61306SVille Syrjälä u32 pipestat_mask; 30969ab981f2SVille Syrjälä u32 enable_mask; 30978bb61306SVille Syrjälä enum pipe pipe; 30988bb61306SVille Syrjälä 3099842ebf7aSVille Syrjälä pipestat_mask = PIPE_CRC_DONE_INTERRUPT_STATUS; 31008bb61306SVille Syrjälä 31018bb61306SVille Syrjälä i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS); 31028bb61306SVille Syrjälä for_each_pipe(dev_priv, pipe) 31038bb61306SVille Syrjälä i915_enable_pipestat(dev_priv, pipe, pipestat_mask); 31048bb61306SVille Syrjälä 31059ab981f2SVille Syrjälä enable_mask = I915_DISPLAY_PORT_INTERRUPT | 31068bb61306SVille Syrjälä I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3107ebf5f921SVille Syrjälä I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3108ebf5f921SVille Syrjälä I915_LPE_PIPE_A_INTERRUPT | 3109ebf5f921SVille Syrjälä I915_LPE_PIPE_B_INTERRUPT; 3110ebf5f921SVille Syrjälä 31118bb61306SVille Syrjälä if (IS_CHERRYVIEW(dev_priv)) 3112ebf5f921SVille Syrjälä enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT | 3113ebf5f921SVille Syrjälä I915_LPE_PIPE_C_INTERRUPT; 31146b7eafc1SVille Syrjälä 31158bd099a7SChris Wilson WARN_ON(dev_priv->irq_mask != ~0u); 31166b7eafc1SVille Syrjälä 31179ab981f2SVille Syrjälä dev_priv->irq_mask = ~enable_mask; 31188bb61306SVille Syrjälä 3119b16b2a2fSPaulo Zanoni GEN3_IRQ_INIT(uncore, VLV_, dev_priv->irq_mask, enable_mask); 31208bb61306SVille Syrjälä } 31218bb61306SVille Syrjälä 31228bb61306SVille Syrjälä /* drm_dma.h hooks 31238bb61306SVille Syrjälä */ 3124b318b824SVille Syrjälä static void ironlake_irq_reset(struct drm_i915_private *dev_priv) 31258bb61306SVille Syrjälä { 3126b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 31278bb61306SVille Syrjälä 3128b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, DE); 3129cf819effSLucas De Marchi if (IS_GEN(dev_priv, 7)) 3130f0818984STvrtko Ursulin intel_uncore_write(uncore, GEN7_ERR_INT, 0xffffffff); 31318bb61306SVille Syrjälä 3132fc340442SDaniel Vetter if (IS_HASWELL(dev_priv)) { 3133f0818984STvrtko Ursulin intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff); 3134f0818984STvrtko Ursulin intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff); 3135fc340442SDaniel Vetter } 3136fc340442SDaniel Vetter 3137cf1c97dcSAndi Shyti gen5_gt_irq_reset(&dev_priv->gt); 31388bb61306SVille Syrjälä 3139b243f530STvrtko Ursulin ibx_irq_reset(dev_priv); 31408bb61306SVille Syrjälä } 31418bb61306SVille Syrjälä 3142b318b824SVille Syrjälä static void valleyview_irq_reset(struct drm_i915_private *dev_priv) 31437e231dbeSJesse Barnes { 314434c7b8a7SVille Syrjälä I915_WRITE(VLV_MASTER_IER, 0); 314534c7b8a7SVille Syrjälä POSTING_READ(VLV_MASTER_IER); 314634c7b8a7SVille Syrjälä 3147cf1c97dcSAndi Shyti gen5_gt_irq_reset(&dev_priv->gt); 31487e231dbeSJesse Barnes 3149ad22d106SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 31509918271eSVille Syrjälä if (dev_priv->display_irqs_enabled) 315170591a41SVille Syrjälä vlv_display_irq_reset(dev_priv); 3152ad22d106SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 31537e231dbeSJesse Barnes } 31547e231dbeSJesse Barnes 3155b318b824SVille Syrjälä static void gen8_irq_reset(struct drm_i915_private *dev_priv) 3156abd58f01SBen Widawsky { 3157b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 3158d048a268SVille Syrjälä enum pipe pipe; 3159abd58f01SBen Widawsky 316025286aacSDaniele Ceraolo Spurio gen8_master_intr_disable(dev_priv->uncore.regs); 3161abd58f01SBen Widawsky 3162cf1c97dcSAndi Shyti gen8_gt_irq_reset(&dev_priv->gt); 3163abd58f01SBen Widawsky 3164f0818984STvrtko Ursulin intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff); 3165f0818984STvrtko Ursulin intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff); 3166e04f7eceSVille Syrjälä 3167055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 3168f458ebbcSDaniel Vetter if (intel_display_power_is_enabled(dev_priv, 3169813bde43SPaulo Zanoni POWER_DOMAIN_PIPE(pipe))) 3170b16b2a2fSPaulo Zanoni GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe); 3171abd58f01SBen Widawsky 3172b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN8_DE_PORT_); 3173b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN8_DE_MISC_); 3174b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN8_PCU_); 3175abd58f01SBen Widawsky 31766e266956STvrtko Ursulin if (HAS_PCH_SPLIT(dev_priv)) 3177b243f530STvrtko Ursulin ibx_irq_reset(dev_priv); 3178abd58f01SBen Widawsky } 3179abd58f01SBen Widawsky 3180b318b824SVille Syrjälä static void gen11_irq_reset(struct drm_i915_private *dev_priv) 318151951ae7SMika Kuoppala { 3182b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 3183d048a268SVille Syrjälä enum pipe pipe; 318451951ae7SMika Kuoppala 318525286aacSDaniele Ceraolo Spurio gen11_master_intr_disable(dev_priv->uncore.regs); 318651951ae7SMika Kuoppala 31879b77011eSTvrtko Ursulin gen11_gt_irq_reset(&dev_priv->gt); 318851951ae7SMika Kuoppala 3189f0818984STvrtko Ursulin intel_uncore_write(uncore, GEN11_DISPLAY_INT_CTL, 0); 319051951ae7SMika Kuoppala 31918241cfbeSJosé Roberto de Souza if (INTEL_GEN(dev_priv) >= 12) { 31928241cfbeSJosé Roberto de Souza enum transcoder trans; 31938241cfbeSJosé Roberto de Souza 31948241cfbeSJosé Roberto de Souza for (trans = TRANSCODER_A; trans <= TRANSCODER_D; trans++) { 31958241cfbeSJosé Roberto de Souza enum intel_display_power_domain domain; 31968241cfbeSJosé Roberto de Souza 31978241cfbeSJosé Roberto de Souza domain = POWER_DOMAIN_TRANSCODER(trans); 31988241cfbeSJosé Roberto de Souza if (!intel_display_power_is_enabled(dev_priv, domain)) 31998241cfbeSJosé Roberto de Souza continue; 32008241cfbeSJosé Roberto de Souza 32018241cfbeSJosé Roberto de Souza intel_uncore_write(uncore, TRANS_PSR_IMR(trans), 0xffffffff); 32028241cfbeSJosé Roberto de Souza intel_uncore_write(uncore, TRANS_PSR_IIR(trans), 0xffffffff); 32038241cfbeSJosé Roberto de Souza } 32048241cfbeSJosé Roberto de Souza } else { 3205f0818984STvrtko Ursulin intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff); 3206f0818984STvrtko Ursulin intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff); 32078241cfbeSJosé Roberto de Souza } 320862819dfdSJosé Roberto de Souza 320951951ae7SMika Kuoppala for_each_pipe(dev_priv, pipe) 321051951ae7SMika Kuoppala if (intel_display_power_is_enabled(dev_priv, 321151951ae7SMika Kuoppala POWER_DOMAIN_PIPE(pipe))) 3212b16b2a2fSPaulo Zanoni GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe); 321351951ae7SMika Kuoppala 3214b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN8_DE_PORT_); 3215b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN8_DE_MISC_); 3216b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN11_DE_HPD_); 3217b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN11_GU_MISC_); 3218b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN8_PCU_); 321931604222SAnusha Srivatsa 322029b43ae2SRodrigo Vivi if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP) 3221b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, SDE); 322251951ae7SMika Kuoppala } 322351951ae7SMika Kuoppala 32244c6c03beSDamien Lespiau void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv, 3225001bd2cbSImre Deak u8 pipe_mask) 3226d49bdb0eSPaulo Zanoni { 3227b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 3228b16b2a2fSPaulo Zanoni 3229a9c287c9SJani Nikula u32 extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN; 32306831f3e3SVille Syrjälä enum pipe pipe; 3231d49bdb0eSPaulo Zanoni 323213321786SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 32339dfe2e3aSImre Deak 32349dfe2e3aSImre Deak if (!intel_irqs_enabled(dev_priv)) { 32359dfe2e3aSImre Deak spin_unlock_irq(&dev_priv->irq_lock); 32369dfe2e3aSImre Deak return; 32379dfe2e3aSImre Deak } 32389dfe2e3aSImre Deak 32396831f3e3SVille Syrjälä for_each_pipe_masked(dev_priv, pipe, pipe_mask) 3240b16b2a2fSPaulo Zanoni GEN8_IRQ_INIT_NDX(uncore, DE_PIPE, pipe, 32416831f3e3SVille Syrjälä dev_priv->de_irq_mask[pipe], 32426831f3e3SVille Syrjälä ~dev_priv->de_irq_mask[pipe] | extra_ier); 32439dfe2e3aSImre Deak 324413321786SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 3245d49bdb0eSPaulo Zanoni } 3246d49bdb0eSPaulo Zanoni 3247aae8ba84SVille Syrjälä void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv, 3248001bd2cbSImre Deak u8 pipe_mask) 3249aae8ba84SVille Syrjälä { 3250b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 32516831f3e3SVille Syrjälä enum pipe pipe; 32526831f3e3SVille Syrjälä 3253aae8ba84SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 32549dfe2e3aSImre Deak 32559dfe2e3aSImre Deak if (!intel_irqs_enabled(dev_priv)) { 32569dfe2e3aSImre Deak spin_unlock_irq(&dev_priv->irq_lock); 32579dfe2e3aSImre Deak return; 32589dfe2e3aSImre Deak } 32599dfe2e3aSImre Deak 32606831f3e3SVille Syrjälä for_each_pipe_masked(dev_priv, pipe, pipe_mask) 3261b16b2a2fSPaulo Zanoni GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe); 32629dfe2e3aSImre Deak 3263aae8ba84SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 3264aae8ba84SVille Syrjälä 3265aae8ba84SVille Syrjälä /* make sure we're done processing display irqs */ 3266315ca4c4SVille Syrjälä intel_synchronize_irq(dev_priv); 3267aae8ba84SVille Syrjälä } 3268aae8ba84SVille Syrjälä 3269b318b824SVille Syrjälä static void cherryview_irq_reset(struct drm_i915_private *dev_priv) 327043f328d7SVille Syrjälä { 3271b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 327243f328d7SVille Syrjälä 327343f328d7SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, 0); 327443f328d7SVille Syrjälä POSTING_READ(GEN8_MASTER_IRQ); 327543f328d7SVille Syrjälä 3276cf1c97dcSAndi Shyti gen8_gt_irq_reset(&dev_priv->gt); 327743f328d7SVille Syrjälä 3278b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN8_PCU_); 327943f328d7SVille Syrjälä 3280ad22d106SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 32819918271eSVille Syrjälä if (dev_priv->display_irqs_enabled) 328270591a41SVille Syrjälä vlv_display_irq_reset(dev_priv); 3283ad22d106SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 328443f328d7SVille Syrjälä } 328543f328d7SVille Syrjälä 328691d14251STvrtko Ursulin static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv, 328787a02106SVille Syrjälä const u32 hpd[HPD_NUM_PINS]) 328887a02106SVille Syrjälä { 328987a02106SVille Syrjälä struct intel_encoder *encoder; 329087a02106SVille Syrjälä u32 enabled_irqs = 0; 329187a02106SVille Syrjälä 329291c8a326SChris Wilson for_each_intel_encoder(&dev_priv->drm, encoder) 329387a02106SVille Syrjälä if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED) 329487a02106SVille Syrjälä enabled_irqs |= hpd[encoder->hpd_pin]; 329587a02106SVille Syrjälä 329687a02106SVille Syrjälä return enabled_irqs; 329787a02106SVille Syrjälä } 329887a02106SVille Syrjälä 32991a56b1a2SImre Deak static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv) 33001a56b1a2SImre Deak { 33011a56b1a2SImre Deak u32 hotplug; 33021a56b1a2SImre Deak 33031a56b1a2SImre Deak /* 33041a56b1a2SImre Deak * Enable digital hotplug on the PCH, and configure the DP short pulse 33051a56b1a2SImre Deak * duration to 2ms (which is the minimum in the Display Port spec). 33061a56b1a2SImre Deak * The pulse duration bits are reserved on LPT+. 33071a56b1a2SImre Deak */ 33081a56b1a2SImre Deak hotplug = I915_READ(PCH_PORT_HOTPLUG); 33091a56b1a2SImre Deak hotplug &= ~(PORTB_PULSE_DURATION_MASK | 33101a56b1a2SImre Deak PORTC_PULSE_DURATION_MASK | 33111a56b1a2SImre Deak PORTD_PULSE_DURATION_MASK); 33121a56b1a2SImre Deak hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms; 33131a56b1a2SImre Deak hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms; 33141a56b1a2SImre Deak hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms; 33151a56b1a2SImre Deak /* 33161a56b1a2SImre Deak * When CPU and PCH are on the same package, port A 33171a56b1a2SImre Deak * HPD must be enabled in both north and south. 33181a56b1a2SImre Deak */ 33191a56b1a2SImre Deak if (HAS_PCH_LPT_LP(dev_priv)) 33201a56b1a2SImre Deak hotplug |= PORTA_HOTPLUG_ENABLE; 33211a56b1a2SImre Deak I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 33221a56b1a2SImre Deak } 33231a56b1a2SImre Deak 332491d14251STvrtko Ursulin static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv) 332582a28bcfSDaniel Vetter { 33261a56b1a2SImre Deak u32 hotplug_irqs, enabled_irqs; 332782a28bcfSDaniel Vetter 332891d14251STvrtko Ursulin if (HAS_PCH_IBX(dev_priv)) { 3329fee884edSDaniel Vetter hotplug_irqs = SDE_HOTPLUG_MASK; 333091d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx); 333182a28bcfSDaniel Vetter } else { 3332fee884edSDaniel Vetter hotplug_irqs = SDE_HOTPLUG_MASK_CPT; 333391d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt); 333482a28bcfSDaniel Vetter } 333582a28bcfSDaniel Vetter 3336fee884edSDaniel Vetter ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); 333782a28bcfSDaniel Vetter 33381a56b1a2SImre Deak ibx_hpd_detection_setup(dev_priv); 33396dbf30ceSVille Syrjälä } 334026951cafSXiong Zhang 334152dfdba0SLucas De Marchi static void icp_hpd_detection_setup(struct drm_i915_private *dev_priv, 334252dfdba0SLucas De Marchi u32 ddi_hotplug_enable_mask, 334352dfdba0SLucas De Marchi u32 tc_hotplug_enable_mask) 334431604222SAnusha Srivatsa { 334531604222SAnusha Srivatsa u32 hotplug; 334631604222SAnusha Srivatsa 334731604222SAnusha Srivatsa hotplug = I915_READ(SHOTPLUG_CTL_DDI); 334852dfdba0SLucas De Marchi hotplug |= ddi_hotplug_enable_mask; 334931604222SAnusha Srivatsa I915_WRITE(SHOTPLUG_CTL_DDI, hotplug); 335031604222SAnusha Srivatsa 33518ef7e340SMatt Roper if (tc_hotplug_enable_mask) { 335231604222SAnusha Srivatsa hotplug = I915_READ(SHOTPLUG_CTL_TC); 335352dfdba0SLucas De Marchi hotplug |= tc_hotplug_enable_mask; 335431604222SAnusha Srivatsa I915_WRITE(SHOTPLUG_CTL_TC, hotplug); 335531604222SAnusha Srivatsa } 33568ef7e340SMatt Roper } 335731604222SAnusha Srivatsa 335840e98130SLucas De Marchi static void icp_hpd_irq_setup(struct drm_i915_private *dev_priv, 335940e98130SLucas De Marchi u32 sde_ddi_mask, u32 sde_tc_mask, 336040e98130SLucas De Marchi u32 ddi_enable_mask, u32 tc_enable_mask, 336140e98130SLucas De Marchi const u32 *pins) 336231604222SAnusha Srivatsa { 336331604222SAnusha Srivatsa u32 hotplug_irqs, enabled_irqs; 336431604222SAnusha Srivatsa 336540e98130SLucas De Marchi hotplug_irqs = sde_ddi_mask | sde_tc_mask; 336640e98130SLucas De Marchi enabled_irqs = intel_hpd_enabled_irqs(dev_priv, pins); 336731604222SAnusha Srivatsa 336831604222SAnusha Srivatsa ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); 336931604222SAnusha Srivatsa 337040e98130SLucas De Marchi icp_hpd_detection_setup(dev_priv, ddi_enable_mask, tc_enable_mask); 337152dfdba0SLucas De Marchi } 337252dfdba0SLucas De Marchi 337340e98130SLucas De Marchi /* 337440e98130SLucas De Marchi * EHL doesn't need most of gen11_hpd_irq_setup, it's handling only the 337540e98130SLucas De Marchi * equivalent of SDE. 337640e98130SLucas De Marchi */ 33778ef7e340SMatt Roper static void mcc_hpd_irq_setup(struct drm_i915_private *dev_priv) 33788ef7e340SMatt Roper { 337940e98130SLucas De Marchi icp_hpd_irq_setup(dev_priv, 338040e98130SLucas De Marchi SDE_DDI_MASK_TGP, 0, 338140e98130SLucas De Marchi TGP_DDI_HPD_ENABLE_MASK, 0, 3382d09ad3e7SMatt Roper hpd_icp); 338331604222SAnusha Srivatsa } 338431604222SAnusha Srivatsa 3385121e758eSDhinakaran Pandiyan static void gen11_hpd_detection_setup(struct drm_i915_private *dev_priv) 3386121e758eSDhinakaran Pandiyan { 3387121e758eSDhinakaran Pandiyan u32 hotplug; 3388121e758eSDhinakaran Pandiyan 3389121e758eSDhinakaran Pandiyan hotplug = I915_READ(GEN11_TC_HOTPLUG_CTL); 3390121e758eSDhinakaran Pandiyan hotplug |= GEN11_HOTPLUG_CTL_ENABLE(PORT_TC1) | 3391121e758eSDhinakaran Pandiyan GEN11_HOTPLUG_CTL_ENABLE(PORT_TC2) | 3392121e758eSDhinakaran Pandiyan GEN11_HOTPLUG_CTL_ENABLE(PORT_TC3) | 3393121e758eSDhinakaran Pandiyan GEN11_HOTPLUG_CTL_ENABLE(PORT_TC4); 3394121e758eSDhinakaran Pandiyan I915_WRITE(GEN11_TC_HOTPLUG_CTL, hotplug); 3395b796b971SDhinakaran Pandiyan 3396b796b971SDhinakaran Pandiyan hotplug = I915_READ(GEN11_TBT_HOTPLUG_CTL); 3397b796b971SDhinakaran Pandiyan hotplug |= GEN11_HOTPLUG_CTL_ENABLE(PORT_TC1) | 3398b796b971SDhinakaran Pandiyan GEN11_HOTPLUG_CTL_ENABLE(PORT_TC2) | 3399b796b971SDhinakaran Pandiyan GEN11_HOTPLUG_CTL_ENABLE(PORT_TC3) | 3400b796b971SDhinakaran Pandiyan GEN11_HOTPLUG_CTL_ENABLE(PORT_TC4); 3401b796b971SDhinakaran Pandiyan I915_WRITE(GEN11_TBT_HOTPLUG_CTL, hotplug); 3402121e758eSDhinakaran Pandiyan } 3403121e758eSDhinakaran Pandiyan 3404121e758eSDhinakaran Pandiyan static void gen11_hpd_irq_setup(struct drm_i915_private *dev_priv) 3405121e758eSDhinakaran Pandiyan { 3406121e758eSDhinakaran Pandiyan u32 hotplug_irqs, enabled_irqs; 340748ef15d3SJosé Roberto de Souza const u32 *hpd; 3408121e758eSDhinakaran Pandiyan u32 val; 3409121e758eSDhinakaran Pandiyan 341048ef15d3SJosé Roberto de Souza hpd = INTEL_GEN(dev_priv) >= 12 ? hpd_gen12 : hpd_gen11; 341148ef15d3SJosé Roberto de Souza enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd); 3412b796b971SDhinakaran Pandiyan hotplug_irqs = GEN11_DE_TC_HOTPLUG_MASK | GEN11_DE_TBT_HOTPLUG_MASK; 3413121e758eSDhinakaran Pandiyan 3414121e758eSDhinakaran Pandiyan val = I915_READ(GEN11_DE_HPD_IMR); 3415121e758eSDhinakaran Pandiyan val &= ~hotplug_irqs; 3416121e758eSDhinakaran Pandiyan I915_WRITE(GEN11_DE_HPD_IMR, val); 3417121e758eSDhinakaran Pandiyan POSTING_READ(GEN11_DE_HPD_IMR); 3418121e758eSDhinakaran Pandiyan 3419121e758eSDhinakaran Pandiyan gen11_hpd_detection_setup(dev_priv); 342031604222SAnusha Srivatsa 342152dfdba0SLucas De Marchi if (INTEL_PCH_TYPE(dev_priv) >= PCH_TGP) 342240e98130SLucas De Marchi icp_hpd_irq_setup(dev_priv, SDE_DDI_MASK_TGP, SDE_TC_MASK_TGP, 342340e98130SLucas De Marchi TGP_DDI_HPD_ENABLE_MASK, 342440e98130SLucas De Marchi TGP_TC_HPD_ENABLE_MASK, hpd_tgp); 342552dfdba0SLucas De Marchi else if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP) 342640e98130SLucas De Marchi icp_hpd_irq_setup(dev_priv, SDE_DDI_MASK_ICP, SDE_TC_MASK_ICP, 342740e98130SLucas De Marchi ICP_DDI_HPD_ENABLE_MASK, 342840e98130SLucas De Marchi ICP_TC_HPD_ENABLE_MASK, hpd_icp); 3429121e758eSDhinakaran Pandiyan } 3430121e758eSDhinakaran Pandiyan 34312a57d9ccSImre Deak static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv) 34322a57d9ccSImre Deak { 34333b92e263SRodrigo Vivi u32 val, hotplug; 34343b92e263SRodrigo Vivi 34353b92e263SRodrigo Vivi /* Display WA #1179 WaHardHangonHotPlug: cnp */ 34363b92e263SRodrigo Vivi if (HAS_PCH_CNP(dev_priv)) { 34373b92e263SRodrigo Vivi val = I915_READ(SOUTH_CHICKEN1); 34383b92e263SRodrigo Vivi val &= ~CHASSIS_CLK_REQ_DURATION_MASK; 34393b92e263SRodrigo Vivi val |= CHASSIS_CLK_REQ_DURATION(0xf); 34403b92e263SRodrigo Vivi I915_WRITE(SOUTH_CHICKEN1, val); 34413b92e263SRodrigo Vivi } 34422a57d9ccSImre Deak 34432a57d9ccSImre Deak /* Enable digital hotplug on the PCH */ 34442a57d9ccSImre Deak hotplug = I915_READ(PCH_PORT_HOTPLUG); 34452a57d9ccSImre Deak hotplug |= PORTA_HOTPLUG_ENABLE | 34462a57d9ccSImre Deak PORTB_HOTPLUG_ENABLE | 34472a57d9ccSImre Deak PORTC_HOTPLUG_ENABLE | 34482a57d9ccSImre Deak PORTD_HOTPLUG_ENABLE; 34492a57d9ccSImre Deak I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 34502a57d9ccSImre Deak 34512a57d9ccSImre Deak hotplug = I915_READ(PCH_PORT_HOTPLUG2); 34522a57d9ccSImre Deak hotplug |= PORTE_HOTPLUG_ENABLE; 34532a57d9ccSImre Deak I915_WRITE(PCH_PORT_HOTPLUG2, hotplug); 34542a57d9ccSImre Deak } 34552a57d9ccSImre Deak 345691d14251STvrtko Ursulin static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv) 34576dbf30ceSVille Syrjälä { 34582a57d9ccSImre Deak u32 hotplug_irqs, enabled_irqs; 34596dbf30ceSVille Syrjälä 34606dbf30ceSVille Syrjälä hotplug_irqs = SDE_HOTPLUG_MASK_SPT; 346191d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt); 34626dbf30ceSVille Syrjälä 34636dbf30ceSVille Syrjälä ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); 34646dbf30ceSVille Syrjälä 34652a57d9ccSImre Deak spt_hpd_detection_setup(dev_priv); 346626951cafSXiong Zhang } 34677fe0b973SKeith Packard 34681a56b1a2SImre Deak static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv) 34691a56b1a2SImre Deak { 34701a56b1a2SImre Deak u32 hotplug; 34711a56b1a2SImre Deak 34721a56b1a2SImre Deak /* 34731a56b1a2SImre Deak * Enable digital hotplug on the CPU, and configure the DP short pulse 34741a56b1a2SImre Deak * duration to 2ms (which is the minimum in the Display Port spec) 34751a56b1a2SImre Deak * The pulse duration bits are reserved on HSW+. 34761a56b1a2SImre Deak */ 34771a56b1a2SImre Deak hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL); 34781a56b1a2SImre Deak hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK; 34791a56b1a2SImre Deak hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE | 34801a56b1a2SImre Deak DIGITAL_PORTA_PULSE_DURATION_2ms; 34811a56b1a2SImre Deak I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug); 34821a56b1a2SImre Deak } 34831a56b1a2SImre Deak 348491d14251STvrtko Ursulin static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv) 3485e4ce95aaSVille Syrjälä { 34861a56b1a2SImre Deak u32 hotplug_irqs, enabled_irqs; 3487e4ce95aaSVille Syrjälä 348891d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 8) { 34893a3b3c7dSVille Syrjälä hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG; 349091d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw); 34913a3b3c7dSVille Syrjälä 34923a3b3c7dSVille Syrjälä bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs); 349391d14251STvrtko Ursulin } else if (INTEL_GEN(dev_priv) >= 7) { 349423bb4cb5SVille Syrjälä hotplug_irqs = DE_DP_A_HOTPLUG_IVB; 349591d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb); 34963a3b3c7dSVille Syrjälä 34973a3b3c7dSVille Syrjälä ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs); 349823bb4cb5SVille Syrjälä } else { 3499e4ce95aaSVille Syrjälä hotplug_irqs = DE_DP_A_HOTPLUG; 350091d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk); 3501e4ce95aaSVille Syrjälä 3502e4ce95aaSVille Syrjälä ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs); 35033a3b3c7dSVille Syrjälä } 3504e4ce95aaSVille Syrjälä 35051a56b1a2SImre Deak ilk_hpd_detection_setup(dev_priv); 3506e4ce95aaSVille Syrjälä 350791d14251STvrtko Ursulin ibx_hpd_irq_setup(dev_priv); 3508e4ce95aaSVille Syrjälä } 3509e4ce95aaSVille Syrjälä 35102a57d9ccSImre Deak static void __bxt_hpd_detection_setup(struct drm_i915_private *dev_priv, 35112a57d9ccSImre Deak u32 enabled_irqs) 3512e0a20ad7SShashank Sharma { 35132a57d9ccSImre Deak u32 hotplug; 3514e0a20ad7SShashank Sharma 3515a52bb15bSVille Syrjälä hotplug = I915_READ(PCH_PORT_HOTPLUG); 35162a57d9ccSImre Deak hotplug |= PORTA_HOTPLUG_ENABLE | 35172a57d9ccSImre Deak PORTB_HOTPLUG_ENABLE | 35182a57d9ccSImre Deak PORTC_HOTPLUG_ENABLE; 3519d252bf68SShubhangi Shrivastava 3520d252bf68SShubhangi Shrivastava DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n", 3521d252bf68SShubhangi Shrivastava hotplug, enabled_irqs); 3522d252bf68SShubhangi Shrivastava hotplug &= ~BXT_DDI_HPD_INVERT_MASK; 3523d252bf68SShubhangi Shrivastava 3524d252bf68SShubhangi Shrivastava /* 3525d252bf68SShubhangi Shrivastava * For BXT invert bit has to be set based on AOB design 3526d252bf68SShubhangi Shrivastava * for HPD detection logic, update it based on VBT fields. 3527d252bf68SShubhangi Shrivastava */ 3528d252bf68SShubhangi Shrivastava if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) && 3529d252bf68SShubhangi Shrivastava intel_bios_is_port_hpd_inverted(dev_priv, PORT_A)) 3530d252bf68SShubhangi Shrivastava hotplug |= BXT_DDIA_HPD_INVERT; 3531d252bf68SShubhangi Shrivastava if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) && 3532d252bf68SShubhangi Shrivastava intel_bios_is_port_hpd_inverted(dev_priv, PORT_B)) 3533d252bf68SShubhangi Shrivastava hotplug |= BXT_DDIB_HPD_INVERT; 3534d252bf68SShubhangi Shrivastava if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) && 3535d252bf68SShubhangi Shrivastava intel_bios_is_port_hpd_inverted(dev_priv, PORT_C)) 3536d252bf68SShubhangi Shrivastava hotplug |= BXT_DDIC_HPD_INVERT; 3537d252bf68SShubhangi Shrivastava 3538a52bb15bSVille Syrjälä I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 3539e0a20ad7SShashank Sharma } 3540e0a20ad7SShashank Sharma 35412a57d9ccSImre Deak static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv) 35422a57d9ccSImre Deak { 35432a57d9ccSImre Deak __bxt_hpd_detection_setup(dev_priv, BXT_DE_PORT_HOTPLUG_MASK); 35442a57d9ccSImre Deak } 35452a57d9ccSImre Deak 35462a57d9ccSImre Deak static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv) 35472a57d9ccSImre Deak { 35482a57d9ccSImre Deak u32 hotplug_irqs, enabled_irqs; 35492a57d9ccSImre Deak 35502a57d9ccSImre Deak enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt); 35512a57d9ccSImre Deak hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK; 35522a57d9ccSImre Deak 35532a57d9ccSImre Deak bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs); 35542a57d9ccSImre Deak 35552a57d9ccSImre Deak __bxt_hpd_detection_setup(dev_priv, enabled_irqs); 35562a57d9ccSImre Deak } 35572a57d9ccSImre Deak 3558b318b824SVille Syrjälä static void ibx_irq_postinstall(struct drm_i915_private *dev_priv) 3559d46da437SPaulo Zanoni { 356082a28bcfSDaniel Vetter u32 mask; 3561d46da437SPaulo Zanoni 35626e266956STvrtko Ursulin if (HAS_PCH_NOP(dev_priv)) 3563692a04cfSDaniel Vetter return; 3564692a04cfSDaniel Vetter 35656e266956STvrtko Ursulin if (HAS_PCH_IBX(dev_priv)) 35665c673b60SDaniel Vetter mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON; 35674ebc6509SDhinakaran Pandiyan else if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv)) 35685c673b60SDaniel Vetter mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT; 35694ebc6509SDhinakaran Pandiyan else 35704ebc6509SDhinakaran Pandiyan mask = SDE_GMBUS_CPT; 35718664281bSPaulo Zanoni 357265f42cdcSPaulo Zanoni gen3_assert_iir_is_zero(&dev_priv->uncore, SDEIIR); 3573d46da437SPaulo Zanoni I915_WRITE(SDEIMR, ~mask); 35742a57d9ccSImre Deak 35752a57d9ccSImre Deak if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) || 35762a57d9ccSImre Deak HAS_PCH_LPT(dev_priv)) 35771a56b1a2SImre Deak ibx_hpd_detection_setup(dev_priv); 35782a57d9ccSImre Deak else 35792a57d9ccSImre Deak spt_hpd_detection_setup(dev_priv); 3580d46da437SPaulo Zanoni } 3581d46da437SPaulo Zanoni 3582b318b824SVille Syrjälä static void ironlake_irq_postinstall(struct drm_i915_private *dev_priv) 3583036a4a7dSZhenyu Wang { 3584b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 35858e76f8dcSPaulo Zanoni u32 display_mask, extra_mask; 35868e76f8dcSPaulo Zanoni 3587b243f530STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 7) { 35888e76f8dcSPaulo Zanoni display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | 3589842ebf7aSVille Syrjälä DE_PCH_EVENT_IVB | DE_AUX_CHANNEL_A_IVB); 35908e76f8dcSPaulo Zanoni extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB | 359123bb4cb5SVille Syrjälä DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB | 359223bb4cb5SVille Syrjälä DE_DP_A_HOTPLUG_IVB); 35938e76f8dcSPaulo Zanoni } else { 35948e76f8dcSPaulo Zanoni display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | 3595842ebf7aSVille Syrjälä DE_AUX_CHANNEL_A | DE_PIPEB_CRC_DONE | 3596842ebf7aSVille Syrjälä DE_PIPEA_CRC_DONE | DE_POISON); 3597e4ce95aaSVille Syrjälä extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT | 3598e4ce95aaSVille Syrjälä DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN | 3599e4ce95aaSVille Syrjälä DE_DP_A_HOTPLUG); 36008e76f8dcSPaulo Zanoni } 3601036a4a7dSZhenyu Wang 3602fc340442SDaniel Vetter if (IS_HASWELL(dev_priv)) { 3603b16b2a2fSPaulo Zanoni gen3_assert_iir_is_zero(uncore, EDP_PSR_IIR); 3604fc340442SDaniel Vetter display_mask |= DE_EDP_PSR_INT_HSW; 3605fc340442SDaniel Vetter } 3606fc340442SDaniel Vetter 36071ec14ad3SChris Wilson dev_priv->irq_mask = ~display_mask; 3608036a4a7dSZhenyu Wang 3609b318b824SVille Syrjälä ibx_irq_pre_postinstall(dev_priv); 3610622364b6SPaulo Zanoni 3611b16b2a2fSPaulo Zanoni GEN3_IRQ_INIT(uncore, DE, dev_priv->irq_mask, 3612b16b2a2fSPaulo Zanoni display_mask | extra_mask); 3613036a4a7dSZhenyu Wang 3614cf1c97dcSAndi Shyti gen5_gt_irq_postinstall(&dev_priv->gt); 3615036a4a7dSZhenyu Wang 36161a56b1a2SImre Deak ilk_hpd_detection_setup(dev_priv); 36171a56b1a2SImre Deak 3618b318b824SVille Syrjälä ibx_irq_postinstall(dev_priv); 36197fe0b973SKeith Packard 362050a0bc90STvrtko Ursulin if (IS_IRONLAKE_M(dev_priv)) { 36216005ce42SDaniel Vetter /* Enable PCU event interrupts 36226005ce42SDaniel Vetter * 36236005ce42SDaniel Vetter * spinlocking not required here for correctness since interrupt 36244bc9d430SDaniel Vetter * setup is guaranteed to run in single-threaded context. But we 36254bc9d430SDaniel Vetter * need it to make the assert_spin_locked happy. */ 3626d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 3627fbdedaeaSVille Syrjälä ilk_enable_display_irq(dev_priv, DE_PCU_EVENT); 3628d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 3629f97108d1SJesse Barnes } 3630036a4a7dSZhenyu Wang } 3631036a4a7dSZhenyu Wang 3632f8b79e58SImre Deak void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv) 3633f8b79e58SImre Deak { 363467520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 3635f8b79e58SImre Deak 3636f8b79e58SImre Deak if (dev_priv->display_irqs_enabled) 3637f8b79e58SImre Deak return; 3638f8b79e58SImre Deak 3639f8b79e58SImre Deak dev_priv->display_irqs_enabled = true; 3640f8b79e58SImre Deak 3641d6c69803SVille Syrjälä if (intel_irqs_enabled(dev_priv)) { 3642d6c69803SVille Syrjälä vlv_display_irq_reset(dev_priv); 3643ad22d106SVille Syrjälä vlv_display_irq_postinstall(dev_priv); 3644f8b79e58SImre Deak } 3645d6c69803SVille Syrjälä } 3646f8b79e58SImre Deak 3647f8b79e58SImre Deak void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv) 3648f8b79e58SImre Deak { 364967520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 3650f8b79e58SImre Deak 3651f8b79e58SImre Deak if (!dev_priv->display_irqs_enabled) 3652f8b79e58SImre Deak return; 3653f8b79e58SImre Deak 3654f8b79e58SImre Deak dev_priv->display_irqs_enabled = false; 3655f8b79e58SImre Deak 3656950eabafSImre Deak if (intel_irqs_enabled(dev_priv)) 3657ad22d106SVille Syrjälä vlv_display_irq_reset(dev_priv); 3658f8b79e58SImre Deak } 3659f8b79e58SImre Deak 36600e6c9a9eSVille Syrjälä 3661b318b824SVille Syrjälä static void valleyview_irq_postinstall(struct drm_i915_private *dev_priv) 36620e6c9a9eSVille Syrjälä { 3663cf1c97dcSAndi Shyti gen5_gt_irq_postinstall(&dev_priv->gt); 36647e231dbeSJesse Barnes 3665ad22d106SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 36669918271eSVille Syrjälä if (dev_priv->display_irqs_enabled) 3667ad22d106SVille Syrjälä vlv_display_irq_postinstall(dev_priv); 3668ad22d106SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 3669ad22d106SVille Syrjälä 36707e231dbeSJesse Barnes I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE); 367134c7b8a7SVille Syrjälä POSTING_READ(VLV_MASTER_IER); 367220afbda2SDaniel Vetter } 367320afbda2SDaniel Vetter 3674abd58f01SBen Widawsky static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv) 3675abd58f01SBen Widawsky { 3676b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 3677b16b2a2fSPaulo Zanoni 3678a9c287c9SJani Nikula u32 de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE; 3679a9c287c9SJani Nikula u32 de_pipe_enables; 36803a3b3c7dSVille Syrjälä u32 de_port_masked = GEN8_AUX_CHANNEL_A; 36813a3b3c7dSVille Syrjälä u32 de_port_enables; 3682df0d28c1SDhinakaran Pandiyan u32 de_misc_masked = GEN8_DE_EDP_PSR; 36833a3b3c7dSVille Syrjälä enum pipe pipe; 3684770de83dSDamien Lespiau 3685df0d28c1SDhinakaran Pandiyan if (INTEL_GEN(dev_priv) <= 10) 3686df0d28c1SDhinakaran Pandiyan de_misc_masked |= GEN8_DE_MISC_GSE; 3687df0d28c1SDhinakaran Pandiyan 3688bca2bf2aSPandiyan, Dhinakaran if (INTEL_GEN(dev_priv) >= 9) { 3689842ebf7aSVille Syrjälä de_pipe_masked |= GEN9_DE_PIPE_IRQ_FAULT_ERRORS; 36903a3b3c7dSVille Syrjälä de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C | 369188e04703SJesse Barnes GEN9_AUX_CHANNEL_D; 3692cc3f90f0SAnder Conselvan de Oliveira if (IS_GEN9_LP(dev_priv)) 36933a3b3c7dSVille Syrjälä de_port_masked |= BXT_DE_PORT_GMBUS; 36943a3b3c7dSVille Syrjälä } else { 3695842ebf7aSVille Syrjälä de_pipe_masked |= GEN8_DE_PIPE_IRQ_FAULT_ERRORS; 36963a3b3c7dSVille Syrjälä } 3697770de83dSDamien Lespiau 3698bb187e93SJames Ausmus if (INTEL_GEN(dev_priv) >= 11) 3699bb187e93SJames Ausmus de_port_masked |= ICL_AUX_CHANNEL_E; 3700bb187e93SJames Ausmus 37019bb635d9SDhinakaran Pandiyan if (IS_CNL_WITH_PORT_F(dev_priv) || INTEL_GEN(dev_priv) >= 11) 3702a324fcacSRodrigo Vivi de_port_masked |= CNL_AUX_CHANNEL_F; 3703a324fcacSRodrigo Vivi 3704770de83dSDamien Lespiau de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK | 3705770de83dSDamien Lespiau GEN8_PIPE_FIFO_UNDERRUN; 3706770de83dSDamien Lespiau 37073a3b3c7dSVille Syrjälä de_port_enables = de_port_masked; 3708cc3f90f0SAnder Conselvan de Oliveira if (IS_GEN9_LP(dev_priv)) 3709a52bb15bSVille Syrjälä de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK; 3710a52bb15bSVille Syrjälä else if (IS_BROADWELL(dev_priv)) 37113a3b3c7dSVille Syrjälä de_port_enables |= GEN8_PORT_DP_A_HOTPLUG; 37123a3b3c7dSVille Syrjälä 37138241cfbeSJosé Roberto de Souza if (INTEL_GEN(dev_priv) >= 12) { 37148241cfbeSJosé Roberto de Souza enum transcoder trans; 37158241cfbeSJosé Roberto de Souza 37168241cfbeSJosé Roberto de Souza for (trans = TRANSCODER_A; trans <= TRANSCODER_D; trans++) { 37178241cfbeSJosé Roberto de Souza enum intel_display_power_domain domain; 37188241cfbeSJosé Roberto de Souza 37198241cfbeSJosé Roberto de Souza domain = POWER_DOMAIN_TRANSCODER(trans); 37208241cfbeSJosé Roberto de Souza if (!intel_display_power_is_enabled(dev_priv, domain)) 37218241cfbeSJosé Roberto de Souza continue; 37228241cfbeSJosé Roberto de Souza 37238241cfbeSJosé Roberto de Souza gen3_assert_iir_is_zero(uncore, TRANS_PSR_IIR(trans)); 37248241cfbeSJosé Roberto de Souza } 37258241cfbeSJosé Roberto de Souza } else { 3726b16b2a2fSPaulo Zanoni gen3_assert_iir_is_zero(uncore, EDP_PSR_IIR); 37278241cfbeSJosé Roberto de Souza } 3728e04f7eceSVille Syrjälä 37290a195c02SMika Kahola for_each_pipe(dev_priv, pipe) { 37300a195c02SMika Kahola dev_priv->de_irq_mask[pipe] = ~de_pipe_masked; 3731abd58f01SBen Widawsky 3732f458ebbcSDaniel Vetter if (intel_display_power_is_enabled(dev_priv, 3733813bde43SPaulo Zanoni POWER_DOMAIN_PIPE(pipe))) 3734b16b2a2fSPaulo Zanoni GEN8_IRQ_INIT_NDX(uncore, DE_PIPE, pipe, 3735813bde43SPaulo Zanoni dev_priv->de_irq_mask[pipe], 373635079899SPaulo Zanoni de_pipe_enables); 37370a195c02SMika Kahola } 3738abd58f01SBen Widawsky 3739b16b2a2fSPaulo Zanoni GEN3_IRQ_INIT(uncore, GEN8_DE_PORT_, ~de_port_masked, de_port_enables); 3740b16b2a2fSPaulo Zanoni GEN3_IRQ_INIT(uncore, GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked); 37412a57d9ccSImre Deak 3742121e758eSDhinakaran Pandiyan if (INTEL_GEN(dev_priv) >= 11) { 3743121e758eSDhinakaran Pandiyan u32 de_hpd_masked = 0; 3744b796b971SDhinakaran Pandiyan u32 de_hpd_enables = GEN11_DE_TC_HOTPLUG_MASK | 3745b796b971SDhinakaran Pandiyan GEN11_DE_TBT_HOTPLUG_MASK; 3746121e758eSDhinakaran Pandiyan 3747b16b2a2fSPaulo Zanoni GEN3_IRQ_INIT(uncore, GEN11_DE_HPD_, ~de_hpd_masked, 3748b16b2a2fSPaulo Zanoni de_hpd_enables); 3749121e758eSDhinakaran Pandiyan gen11_hpd_detection_setup(dev_priv); 3750121e758eSDhinakaran Pandiyan } else if (IS_GEN9_LP(dev_priv)) { 37512a57d9ccSImre Deak bxt_hpd_detection_setup(dev_priv); 3752121e758eSDhinakaran Pandiyan } else if (IS_BROADWELL(dev_priv)) { 37531a56b1a2SImre Deak ilk_hpd_detection_setup(dev_priv); 3754abd58f01SBen Widawsky } 3755121e758eSDhinakaran Pandiyan } 3756abd58f01SBen Widawsky 3757b318b824SVille Syrjälä static void gen8_irq_postinstall(struct drm_i915_private *dev_priv) 3758abd58f01SBen Widawsky { 37596e266956STvrtko Ursulin if (HAS_PCH_SPLIT(dev_priv)) 3760b318b824SVille Syrjälä ibx_irq_pre_postinstall(dev_priv); 3761622364b6SPaulo Zanoni 3762cf1c97dcSAndi Shyti gen8_gt_irq_postinstall(&dev_priv->gt); 3763abd58f01SBen Widawsky gen8_de_irq_postinstall(dev_priv); 3764abd58f01SBen Widawsky 37656e266956STvrtko Ursulin if (HAS_PCH_SPLIT(dev_priv)) 3766b318b824SVille Syrjälä ibx_irq_postinstall(dev_priv); 3767abd58f01SBen Widawsky 376825286aacSDaniele Ceraolo Spurio gen8_master_intr_enable(dev_priv->uncore.regs); 3769abd58f01SBen Widawsky } 3770abd58f01SBen Widawsky 3771b318b824SVille Syrjälä static void icp_irq_postinstall(struct drm_i915_private *dev_priv) 377231604222SAnusha Srivatsa { 377331604222SAnusha Srivatsa u32 mask = SDE_GMBUS_ICP; 377431604222SAnusha Srivatsa 377531604222SAnusha Srivatsa WARN_ON(I915_READ(SDEIER) != 0); 377631604222SAnusha Srivatsa I915_WRITE(SDEIER, 0xffffffff); 377731604222SAnusha Srivatsa POSTING_READ(SDEIER); 377831604222SAnusha Srivatsa 377965f42cdcSPaulo Zanoni gen3_assert_iir_is_zero(&dev_priv->uncore, SDEIIR); 378031604222SAnusha Srivatsa I915_WRITE(SDEIMR, ~mask); 378131604222SAnusha Srivatsa 378252dfdba0SLucas De Marchi if (HAS_PCH_TGP(dev_priv)) 378352dfdba0SLucas De Marchi icp_hpd_detection_setup(dev_priv, TGP_DDI_HPD_ENABLE_MASK, 378452dfdba0SLucas De Marchi TGP_TC_HPD_ENABLE_MASK); 37858ef7e340SMatt Roper else if (HAS_PCH_MCC(dev_priv)) 37868ef7e340SMatt Roper icp_hpd_detection_setup(dev_priv, TGP_DDI_HPD_ENABLE_MASK, 0); 378752dfdba0SLucas De Marchi else 378852dfdba0SLucas De Marchi icp_hpd_detection_setup(dev_priv, ICP_DDI_HPD_ENABLE_MASK, 378952dfdba0SLucas De Marchi ICP_TC_HPD_ENABLE_MASK); 379031604222SAnusha Srivatsa } 379131604222SAnusha Srivatsa 3792b318b824SVille Syrjälä static void gen11_irq_postinstall(struct drm_i915_private *dev_priv) 379351951ae7SMika Kuoppala { 3794b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 3795df0d28c1SDhinakaran Pandiyan u32 gu_misc_masked = GEN11_GU_MISC_GSE; 379651951ae7SMika Kuoppala 379729b43ae2SRodrigo Vivi if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP) 3798b318b824SVille Syrjälä icp_irq_postinstall(dev_priv); 379931604222SAnusha Srivatsa 38009b77011eSTvrtko Ursulin gen11_gt_irq_postinstall(&dev_priv->gt); 380151951ae7SMika Kuoppala gen8_de_irq_postinstall(dev_priv); 380251951ae7SMika Kuoppala 3803b16b2a2fSPaulo Zanoni GEN3_IRQ_INIT(uncore, GEN11_GU_MISC_, ~gu_misc_masked, gu_misc_masked); 3804df0d28c1SDhinakaran Pandiyan 380551951ae7SMika Kuoppala I915_WRITE(GEN11_DISPLAY_INT_CTL, GEN11_DISPLAY_IRQ_ENABLE); 380651951ae7SMika Kuoppala 38079b77011eSTvrtko Ursulin gen11_master_intr_enable(uncore->regs); 3808c25f0c6aSDaniele Ceraolo Spurio POSTING_READ(GEN11_GFX_MSTR_IRQ); 380951951ae7SMika Kuoppala } 381051951ae7SMika Kuoppala 3811b318b824SVille Syrjälä static void cherryview_irq_postinstall(struct drm_i915_private *dev_priv) 381243f328d7SVille Syrjälä { 3813cf1c97dcSAndi Shyti gen8_gt_irq_postinstall(&dev_priv->gt); 381443f328d7SVille Syrjälä 3815ad22d106SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 38169918271eSVille Syrjälä if (dev_priv->display_irqs_enabled) 3817ad22d106SVille Syrjälä vlv_display_irq_postinstall(dev_priv); 3818ad22d106SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 3819ad22d106SVille Syrjälä 3820e5328c43SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); 382143f328d7SVille Syrjälä POSTING_READ(GEN8_MASTER_IRQ); 382243f328d7SVille Syrjälä } 382343f328d7SVille Syrjälä 3824b318b824SVille Syrjälä static void i8xx_irq_reset(struct drm_i915_private *dev_priv) 3825c2798b19SChris Wilson { 3826b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 3827c2798b19SChris Wilson 382844d9241eSVille Syrjälä i9xx_pipestat_irq_reset(dev_priv); 382944d9241eSVille Syrjälä 3830b16b2a2fSPaulo Zanoni GEN2_IRQ_RESET(uncore); 3831c2798b19SChris Wilson } 3832c2798b19SChris Wilson 3833b318b824SVille Syrjälä static void i8xx_irq_postinstall(struct drm_i915_private *dev_priv) 3834c2798b19SChris Wilson { 3835b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 3836e9e9848aSVille Syrjälä u16 enable_mask; 3837c2798b19SChris Wilson 38384f5fd91fSTvrtko Ursulin intel_uncore_write16(uncore, 38394f5fd91fSTvrtko Ursulin EMR, 38404f5fd91fSTvrtko Ursulin ~(I915_ERROR_PAGE_TABLE | 3841045cebd2SVille Syrjälä I915_ERROR_MEMORY_REFRESH)); 3842c2798b19SChris Wilson 3843c2798b19SChris Wilson /* Unmask the interrupts that we always want on. */ 3844c2798b19SChris Wilson dev_priv->irq_mask = 3845c2798b19SChris Wilson ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 384616659bc5SVille Syrjälä I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 384716659bc5SVille Syrjälä I915_MASTER_ERROR_INTERRUPT); 3848c2798b19SChris Wilson 3849e9e9848aSVille Syrjälä enable_mask = 3850c2798b19SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3851c2798b19SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 385216659bc5SVille Syrjälä I915_MASTER_ERROR_INTERRUPT | 3853e9e9848aSVille Syrjälä I915_USER_INTERRUPT; 3854e9e9848aSVille Syrjälä 3855b16b2a2fSPaulo Zanoni GEN2_IRQ_INIT(uncore, dev_priv->irq_mask, enable_mask); 3856c2798b19SChris Wilson 3857379ef82dSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3858379ef82dSDaniel Vetter * just to make the assert_spin_locked check happy. */ 3859d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 3860755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 3861755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 3862d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 3863c2798b19SChris Wilson } 3864c2798b19SChris Wilson 38654f5fd91fSTvrtko Ursulin static void i8xx_error_irq_ack(struct drm_i915_private *i915, 386678c357ddSVille Syrjälä u16 *eir, u16 *eir_stuck) 386778c357ddSVille Syrjälä { 38684f5fd91fSTvrtko Ursulin struct intel_uncore *uncore = &i915->uncore; 386978c357ddSVille Syrjälä u16 emr; 387078c357ddSVille Syrjälä 38714f5fd91fSTvrtko Ursulin *eir = intel_uncore_read16(uncore, EIR); 387278c357ddSVille Syrjälä 387378c357ddSVille Syrjälä if (*eir) 38744f5fd91fSTvrtko Ursulin intel_uncore_write16(uncore, EIR, *eir); 387578c357ddSVille Syrjälä 38764f5fd91fSTvrtko Ursulin *eir_stuck = intel_uncore_read16(uncore, EIR); 387778c357ddSVille Syrjälä if (*eir_stuck == 0) 387878c357ddSVille Syrjälä return; 387978c357ddSVille Syrjälä 388078c357ddSVille Syrjälä /* 388178c357ddSVille Syrjälä * Toggle all EMR bits to make sure we get an edge 388278c357ddSVille Syrjälä * in the ISR master error bit if we don't clear 388378c357ddSVille Syrjälä * all the EIR bits. Otherwise the edge triggered 388478c357ddSVille Syrjälä * IIR on i965/g4x wouldn't notice that an interrupt 388578c357ddSVille Syrjälä * is still pending. Also some EIR bits can't be 388678c357ddSVille Syrjälä * cleared except by handling the underlying error 388778c357ddSVille Syrjälä * (or by a GPU reset) so we mask any bit that 388878c357ddSVille Syrjälä * remains set. 388978c357ddSVille Syrjälä */ 38904f5fd91fSTvrtko Ursulin emr = intel_uncore_read16(uncore, EMR); 38914f5fd91fSTvrtko Ursulin intel_uncore_write16(uncore, EMR, 0xffff); 38924f5fd91fSTvrtko Ursulin intel_uncore_write16(uncore, EMR, emr | *eir_stuck); 389378c357ddSVille Syrjälä } 389478c357ddSVille Syrjälä 389578c357ddSVille Syrjälä static void i8xx_error_irq_handler(struct drm_i915_private *dev_priv, 389678c357ddSVille Syrjälä u16 eir, u16 eir_stuck) 389778c357ddSVille Syrjälä { 389878c357ddSVille Syrjälä DRM_DEBUG("Master Error: EIR 0x%04x\n", eir); 389978c357ddSVille Syrjälä 390078c357ddSVille Syrjälä if (eir_stuck) 390178c357ddSVille Syrjälä DRM_DEBUG_DRIVER("EIR stuck: 0x%04x, masked\n", eir_stuck); 390278c357ddSVille Syrjälä } 390378c357ddSVille Syrjälä 390478c357ddSVille Syrjälä static void i9xx_error_irq_ack(struct drm_i915_private *dev_priv, 390578c357ddSVille Syrjälä u32 *eir, u32 *eir_stuck) 390678c357ddSVille Syrjälä { 390778c357ddSVille Syrjälä u32 emr; 390878c357ddSVille Syrjälä 390978c357ddSVille Syrjälä *eir = I915_READ(EIR); 391078c357ddSVille Syrjälä 391178c357ddSVille Syrjälä I915_WRITE(EIR, *eir); 391278c357ddSVille Syrjälä 391378c357ddSVille Syrjälä *eir_stuck = I915_READ(EIR); 391478c357ddSVille Syrjälä if (*eir_stuck == 0) 391578c357ddSVille Syrjälä return; 391678c357ddSVille Syrjälä 391778c357ddSVille Syrjälä /* 391878c357ddSVille Syrjälä * Toggle all EMR bits to make sure we get an edge 391978c357ddSVille Syrjälä * in the ISR master error bit if we don't clear 392078c357ddSVille Syrjälä * all the EIR bits. Otherwise the edge triggered 392178c357ddSVille Syrjälä * IIR on i965/g4x wouldn't notice that an interrupt 392278c357ddSVille Syrjälä * is still pending. Also some EIR bits can't be 392378c357ddSVille Syrjälä * cleared except by handling the underlying error 392478c357ddSVille Syrjälä * (or by a GPU reset) so we mask any bit that 392578c357ddSVille Syrjälä * remains set. 392678c357ddSVille Syrjälä */ 392778c357ddSVille Syrjälä emr = I915_READ(EMR); 392878c357ddSVille Syrjälä I915_WRITE(EMR, 0xffffffff); 392978c357ddSVille Syrjälä I915_WRITE(EMR, emr | *eir_stuck); 393078c357ddSVille Syrjälä } 393178c357ddSVille Syrjälä 393278c357ddSVille Syrjälä static void i9xx_error_irq_handler(struct drm_i915_private *dev_priv, 393378c357ddSVille Syrjälä u32 eir, u32 eir_stuck) 393478c357ddSVille Syrjälä { 393578c357ddSVille Syrjälä DRM_DEBUG("Master Error, EIR 0x%08x\n", eir); 393678c357ddSVille Syrjälä 393778c357ddSVille Syrjälä if (eir_stuck) 393878c357ddSVille Syrjälä DRM_DEBUG_DRIVER("EIR stuck: 0x%08x, masked\n", eir_stuck); 393978c357ddSVille Syrjälä } 394078c357ddSVille Syrjälä 3941ff1f525eSDaniel Vetter static irqreturn_t i8xx_irq_handler(int irq, void *arg) 3942c2798b19SChris Wilson { 3943b318b824SVille Syrjälä struct drm_i915_private *dev_priv = arg; 3944af722d28SVille Syrjälä irqreturn_t ret = IRQ_NONE; 3945c2798b19SChris Wilson 39462dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 39472dd2a883SImre Deak return IRQ_NONE; 39482dd2a883SImre Deak 39491f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 39509102650fSDaniele Ceraolo Spurio disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 39511f814dacSImre Deak 3952af722d28SVille Syrjälä do { 3953af722d28SVille Syrjälä u32 pipe_stats[I915_MAX_PIPES] = {}; 395478c357ddSVille Syrjälä u16 eir = 0, eir_stuck = 0; 3955af722d28SVille Syrjälä u16 iir; 3956af722d28SVille Syrjälä 39574f5fd91fSTvrtko Ursulin iir = intel_uncore_read16(&dev_priv->uncore, GEN2_IIR); 3958c2798b19SChris Wilson if (iir == 0) 3959af722d28SVille Syrjälä break; 3960c2798b19SChris Wilson 3961af722d28SVille Syrjälä ret = IRQ_HANDLED; 3962c2798b19SChris Wilson 3963eb64343cSVille Syrjälä /* Call regardless, as some status bits might not be 3964eb64343cSVille Syrjälä * signalled in iir */ 3965eb64343cSVille Syrjälä i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats); 3966c2798b19SChris Wilson 396778c357ddSVille Syrjälä if (iir & I915_MASTER_ERROR_INTERRUPT) 396878c357ddSVille Syrjälä i8xx_error_irq_ack(dev_priv, &eir, &eir_stuck); 396978c357ddSVille Syrjälä 39704f5fd91fSTvrtko Ursulin intel_uncore_write16(&dev_priv->uncore, GEN2_IIR, iir); 3971c2798b19SChris Wilson 3972c2798b19SChris Wilson if (iir & I915_USER_INTERRUPT) 39738a68d464SChris Wilson intel_engine_breadcrumbs_irq(dev_priv->engine[RCS0]); 3974c2798b19SChris Wilson 397578c357ddSVille Syrjälä if (iir & I915_MASTER_ERROR_INTERRUPT) 397678c357ddSVille Syrjälä i8xx_error_irq_handler(dev_priv, eir, eir_stuck); 3977af722d28SVille Syrjälä 3978eb64343cSVille Syrjälä i8xx_pipestat_irq_handler(dev_priv, iir, pipe_stats); 3979af722d28SVille Syrjälä } while (0); 3980c2798b19SChris Wilson 39819102650fSDaniele Ceraolo Spurio enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 39821f814dacSImre Deak 39831f814dacSImre Deak return ret; 3984c2798b19SChris Wilson } 3985c2798b19SChris Wilson 3986b318b824SVille Syrjälä static void i915_irq_reset(struct drm_i915_private *dev_priv) 3987a266c7d5SChris Wilson { 3988b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 3989a266c7d5SChris Wilson 399056b857a5STvrtko Ursulin if (I915_HAS_HOTPLUG(dev_priv)) { 39910706f17cSEgbert Eich i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0); 3992a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3993a266c7d5SChris Wilson } 3994a266c7d5SChris Wilson 399544d9241eSVille Syrjälä i9xx_pipestat_irq_reset(dev_priv); 399644d9241eSVille Syrjälä 3997b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN2_); 3998a266c7d5SChris Wilson } 3999a266c7d5SChris Wilson 4000b318b824SVille Syrjälä static void i915_irq_postinstall(struct drm_i915_private *dev_priv) 4001a266c7d5SChris Wilson { 4002b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 400338bde180SChris Wilson u32 enable_mask; 4004a266c7d5SChris Wilson 4005045cebd2SVille Syrjälä I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | 4006045cebd2SVille Syrjälä I915_ERROR_MEMORY_REFRESH)); 400738bde180SChris Wilson 400838bde180SChris Wilson /* Unmask the interrupts that we always want on. */ 400938bde180SChris Wilson dev_priv->irq_mask = 401038bde180SChris Wilson ~(I915_ASLE_INTERRUPT | 401138bde180SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 401216659bc5SVille Syrjälä I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 401316659bc5SVille Syrjälä I915_MASTER_ERROR_INTERRUPT); 401438bde180SChris Wilson 401538bde180SChris Wilson enable_mask = 401638bde180SChris Wilson I915_ASLE_INTERRUPT | 401738bde180SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 401838bde180SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 401916659bc5SVille Syrjälä I915_MASTER_ERROR_INTERRUPT | 402038bde180SChris Wilson I915_USER_INTERRUPT; 402138bde180SChris Wilson 402256b857a5STvrtko Ursulin if (I915_HAS_HOTPLUG(dev_priv)) { 4023a266c7d5SChris Wilson /* Enable in IER... */ 4024a266c7d5SChris Wilson enable_mask |= I915_DISPLAY_PORT_INTERRUPT; 4025a266c7d5SChris Wilson /* and unmask in IMR */ 4026a266c7d5SChris Wilson dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT; 4027a266c7d5SChris Wilson } 4028a266c7d5SChris Wilson 4029b16b2a2fSPaulo Zanoni GEN3_IRQ_INIT(uncore, GEN2_, dev_priv->irq_mask, enable_mask); 4030a266c7d5SChris Wilson 4031379ef82dSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 4032379ef82dSDaniel Vetter * just to make the assert_spin_locked check happy. */ 4033d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 4034755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 4035755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 4036d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 4037379ef82dSDaniel Vetter 4038c30bb1fdSVille Syrjälä i915_enable_asle_pipestat(dev_priv); 403920afbda2SDaniel Vetter } 404020afbda2SDaniel Vetter 4041ff1f525eSDaniel Vetter static irqreturn_t i915_irq_handler(int irq, void *arg) 4042a266c7d5SChris Wilson { 4043b318b824SVille Syrjälä struct drm_i915_private *dev_priv = arg; 4044af722d28SVille Syrjälä irqreturn_t ret = IRQ_NONE; 4045a266c7d5SChris Wilson 40462dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 40472dd2a883SImre Deak return IRQ_NONE; 40482dd2a883SImre Deak 40491f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 40509102650fSDaniele Ceraolo Spurio disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 40511f814dacSImre Deak 405238bde180SChris Wilson do { 4053eb64343cSVille Syrjälä u32 pipe_stats[I915_MAX_PIPES] = {}; 405478c357ddSVille Syrjälä u32 eir = 0, eir_stuck = 0; 4055af722d28SVille Syrjälä u32 hotplug_status = 0; 4056af722d28SVille Syrjälä u32 iir; 4057a266c7d5SChris Wilson 40589d9523d8SPaulo Zanoni iir = I915_READ(GEN2_IIR); 4059af722d28SVille Syrjälä if (iir == 0) 4060af722d28SVille Syrjälä break; 4061af722d28SVille Syrjälä 4062af722d28SVille Syrjälä ret = IRQ_HANDLED; 4063af722d28SVille Syrjälä 4064af722d28SVille Syrjälä if (I915_HAS_HOTPLUG(dev_priv) && 4065af722d28SVille Syrjälä iir & I915_DISPLAY_PORT_INTERRUPT) 4066af722d28SVille Syrjälä hotplug_status = i9xx_hpd_irq_ack(dev_priv); 4067a266c7d5SChris Wilson 4068eb64343cSVille Syrjälä /* Call regardless, as some status bits might not be 4069eb64343cSVille Syrjälä * signalled in iir */ 4070eb64343cSVille Syrjälä i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats); 4071a266c7d5SChris Wilson 407278c357ddSVille Syrjälä if (iir & I915_MASTER_ERROR_INTERRUPT) 407378c357ddSVille Syrjälä i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck); 407478c357ddSVille Syrjälä 40759d9523d8SPaulo Zanoni I915_WRITE(GEN2_IIR, iir); 4076a266c7d5SChris Wilson 4077a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 40788a68d464SChris Wilson intel_engine_breadcrumbs_irq(dev_priv->engine[RCS0]); 4079a266c7d5SChris Wilson 408078c357ddSVille Syrjälä if (iir & I915_MASTER_ERROR_INTERRUPT) 408178c357ddSVille Syrjälä i9xx_error_irq_handler(dev_priv, eir, eir_stuck); 4082a266c7d5SChris Wilson 4083af722d28SVille Syrjälä if (hotplug_status) 4084af722d28SVille Syrjälä i9xx_hpd_irq_handler(dev_priv, hotplug_status); 4085af722d28SVille Syrjälä 4086af722d28SVille Syrjälä i915_pipestat_irq_handler(dev_priv, iir, pipe_stats); 4087af722d28SVille Syrjälä } while (0); 4088a266c7d5SChris Wilson 40899102650fSDaniele Ceraolo Spurio enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 40901f814dacSImre Deak 4091a266c7d5SChris Wilson return ret; 4092a266c7d5SChris Wilson } 4093a266c7d5SChris Wilson 4094b318b824SVille Syrjälä static void i965_irq_reset(struct drm_i915_private *dev_priv) 4095a266c7d5SChris Wilson { 4096b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 4097a266c7d5SChris Wilson 40980706f17cSEgbert Eich i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0); 4099a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 4100a266c7d5SChris Wilson 410144d9241eSVille Syrjälä i9xx_pipestat_irq_reset(dev_priv); 410244d9241eSVille Syrjälä 4103b16b2a2fSPaulo Zanoni GEN3_IRQ_RESET(uncore, GEN2_); 4104a266c7d5SChris Wilson } 4105a266c7d5SChris Wilson 4106b318b824SVille Syrjälä static void i965_irq_postinstall(struct drm_i915_private *dev_priv) 4107a266c7d5SChris Wilson { 4108b16b2a2fSPaulo Zanoni struct intel_uncore *uncore = &dev_priv->uncore; 4109bbba0a97SChris Wilson u32 enable_mask; 4110a266c7d5SChris Wilson u32 error_mask; 4111a266c7d5SChris Wilson 4112045cebd2SVille Syrjälä /* 4113045cebd2SVille Syrjälä * Enable some error detection, note the instruction error mask 4114045cebd2SVille Syrjälä * bit is reserved, so we leave it masked. 4115045cebd2SVille Syrjälä */ 4116045cebd2SVille Syrjälä if (IS_G4X(dev_priv)) { 4117045cebd2SVille Syrjälä error_mask = ~(GM45_ERROR_PAGE_TABLE | 4118045cebd2SVille Syrjälä GM45_ERROR_MEM_PRIV | 4119045cebd2SVille Syrjälä GM45_ERROR_CP_PRIV | 4120045cebd2SVille Syrjälä I915_ERROR_MEMORY_REFRESH); 4121045cebd2SVille Syrjälä } else { 4122045cebd2SVille Syrjälä error_mask = ~(I915_ERROR_PAGE_TABLE | 4123045cebd2SVille Syrjälä I915_ERROR_MEMORY_REFRESH); 4124045cebd2SVille Syrjälä } 4125045cebd2SVille Syrjälä I915_WRITE(EMR, error_mask); 4126045cebd2SVille Syrjälä 4127a266c7d5SChris Wilson /* Unmask the interrupts that we always want on. */ 4128c30bb1fdSVille Syrjälä dev_priv->irq_mask = 4129c30bb1fdSVille Syrjälä ~(I915_ASLE_INTERRUPT | 4130adca4730SChris Wilson I915_DISPLAY_PORT_INTERRUPT | 4131bbba0a97SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 4132bbba0a97SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 413378c357ddSVille Syrjälä I915_MASTER_ERROR_INTERRUPT); 4134bbba0a97SChris Wilson 4135c30bb1fdSVille Syrjälä enable_mask = 4136c30bb1fdSVille Syrjälä I915_ASLE_INTERRUPT | 4137c30bb1fdSVille Syrjälä I915_DISPLAY_PORT_INTERRUPT | 4138c30bb1fdSVille Syrjälä I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 4139c30bb1fdSVille Syrjälä I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 414078c357ddSVille Syrjälä I915_MASTER_ERROR_INTERRUPT | 4141c30bb1fdSVille Syrjälä I915_USER_INTERRUPT; 4142bbba0a97SChris Wilson 414391d14251STvrtko Ursulin if (IS_G4X(dev_priv)) 4144bbba0a97SChris Wilson enable_mask |= I915_BSD_USER_INTERRUPT; 4145a266c7d5SChris Wilson 4146b16b2a2fSPaulo Zanoni GEN3_IRQ_INIT(uncore, GEN2_, dev_priv->irq_mask, enable_mask); 4147c30bb1fdSVille Syrjälä 4148b79480baSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 4149b79480baSDaniel Vetter * just to make the assert_spin_locked check happy. */ 4150d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 4151755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS); 4152755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 4153755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 4154d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 4155a266c7d5SChris Wilson 415691d14251STvrtko Ursulin i915_enable_asle_pipestat(dev_priv); 415720afbda2SDaniel Vetter } 415820afbda2SDaniel Vetter 415991d14251STvrtko Ursulin static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv) 416020afbda2SDaniel Vetter { 416120afbda2SDaniel Vetter u32 hotplug_en; 416220afbda2SDaniel Vetter 416367520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 4164b5ea2d56SDaniel Vetter 4165adca4730SChris Wilson /* Note HDMI and DP share hotplug bits */ 4166e5868a31SEgbert Eich /* enable bits are the same for all generations */ 416791d14251STvrtko Ursulin hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915); 4168a266c7d5SChris Wilson /* Programming the CRT detection parameters tends 4169a266c7d5SChris Wilson to generate a spurious hotplug event about three 4170a266c7d5SChris Wilson seconds later. So just do it once. 4171a266c7d5SChris Wilson */ 417291d14251STvrtko Ursulin if (IS_G4X(dev_priv)) 4173a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64; 4174a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; 4175a266c7d5SChris Wilson 4176a266c7d5SChris Wilson /* Ignore TV since it's buggy */ 41770706f17cSEgbert Eich i915_hotplug_interrupt_update_locked(dev_priv, 4178f9e3dc78SJani Nikula HOTPLUG_INT_EN_MASK | 4179f9e3dc78SJani Nikula CRT_HOTPLUG_VOLTAGE_COMPARE_MASK | 4180f9e3dc78SJani Nikula CRT_HOTPLUG_ACTIVATION_PERIOD_64, 41810706f17cSEgbert Eich hotplug_en); 4182a266c7d5SChris Wilson } 4183a266c7d5SChris Wilson 4184ff1f525eSDaniel Vetter static irqreturn_t i965_irq_handler(int irq, void *arg) 4185a266c7d5SChris Wilson { 4186b318b824SVille Syrjälä struct drm_i915_private *dev_priv = arg; 4187af722d28SVille Syrjälä irqreturn_t ret = IRQ_NONE; 4188a266c7d5SChris Wilson 41892dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 41902dd2a883SImre Deak return IRQ_NONE; 41912dd2a883SImre Deak 41921f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 41939102650fSDaniele Ceraolo Spurio disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 41941f814dacSImre Deak 4195af722d28SVille Syrjälä do { 4196eb64343cSVille Syrjälä u32 pipe_stats[I915_MAX_PIPES] = {}; 419778c357ddSVille Syrjälä u32 eir = 0, eir_stuck = 0; 4198af722d28SVille Syrjälä u32 hotplug_status = 0; 4199af722d28SVille Syrjälä u32 iir; 42002c8ba29fSChris Wilson 42019d9523d8SPaulo Zanoni iir = I915_READ(GEN2_IIR); 4202af722d28SVille Syrjälä if (iir == 0) 4203af722d28SVille Syrjälä break; 4204af722d28SVille Syrjälä 4205af722d28SVille Syrjälä ret = IRQ_HANDLED; 4206af722d28SVille Syrjälä 4207af722d28SVille Syrjälä if (iir & I915_DISPLAY_PORT_INTERRUPT) 4208af722d28SVille Syrjälä hotplug_status = i9xx_hpd_irq_ack(dev_priv); 4209a266c7d5SChris Wilson 4210eb64343cSVille Syrjälä /* Call regardless, as some status bits might not be 4211eb64343cSVille Syrjälä * signalled in iir */ 4212eb64343cSVille Syrjälä i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats); 4213a266c7d5SChris Wilson 421478c357ddSVille Syrjälä if (iir & I915_MASTER_ERROR_INTERRUPT) 421578c357ddSVille Syrjälä i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck); 421678c357ddSVille Syrjälä 42179d9523d8SPaulo Zanoni I915_WRITE(GEN2_IIR, iir); 4218a266c7d5SChris Wilson 4219a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 42208a68d464SChris Wilson intel_engine_breadcrumbs_irq(dev_priv->engine[RCS0]); 4221af722d28SVille Syrjälä 4222a266c7d5SChris Wilson if (iir & I915_BSD_USER_INTERRUPT) 42238a68d464SChris Wilson intel_engine_breadcrumbs_irq(dev_priv->engine[VCS0]); 4224a266c7d5SChris Wilson 422578c357ddSVille Syrjälä if (iir & I915_MASTER_ERROR_INTERRUPT) 422678c357ddSVille Syrjälä i9xx_error_irq_handler(dev_priv, eir, eir_stuck); 4227515ac2bbSDaniel Vetter 4228af722d28SVille Syrjälä if (hotplug_status) 4229af722d28SVille Syrjälä i9xx_hpd_irq_handler(dev_priv, hotplug_status); 4230af722d28SVille Syrjälä 4231af722d28SVille Syrjälä i965_pipestat_irq_handler(dev_priv, iir, pipe_stats); 4232af722d28SVille Syrjälä } while (0); 4233a266c7d5SChris Wilson 42349102650fSDaniele Ceraolo Spurio enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 42351f814dacSImre Deak 4236a266c7d5SChris Wilson return ret; 4237a266c7d5SChris Wilson } 4238a266c7d5SChris Wilson 4239fca52a55SDaniel Vetter /** 4240fca52a55SDaniel Vetter * intel_irq_init - initializes irq support 4241fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4242fca52a55SDaniel Vetter * 4243fca52a55SDaniel Vetter * This function initializes all the irq support including work items, timers 4244fca52a55SDaniel Vetter * and all the vtables. It does not setup the interrupt itself though. 4245fca52a55SDaniel Vetter */ 4246b963291cSDaniel Vetter void intel_irq_init(struct drm_i915_private *dev_priv) 4247f71d4af4SJesse Barnes { 424891c8a326SChris Wilson struct drm_device *dev = &dev_priv->drm; 4249562d9baeSSagar Arun Kamble struct intel_rps *rps = &dev_priv->gt_pm.rps; 4250cefcff8fSJoonas Lahtinen int i; 42518b2e326dSChris Wilson 425277913b39SJani Nikula intel_hpd_init_work(dev_priv); 425377913b39SJani Nikula 4254562d9baeSSagar Arun Kamble INIT_WORK(&rps->work, gen6_pm_rps_work); 4255cefcff8fSJoonas Lahtinen 4256a4da4fa4SDaniel Vetter INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work); 4257cefcff8fSJoonas Lahtinen for (i = 0; i < MAX_L3_SLICES; ++i) 4258cefcff8fSJoonas Lahtinen dev_priv->l3_parity.remap_info[i] = NULL; 42598b2e326dSChris Wilson 4260633023a4SDaniele Ceraolo Spurio /* pre-gen11 the guc irqs bits are in the upper 16 bits of the pm reg */ 4261702668e6SDaniele Ceraolo Spurio if (HAS_GT_UC(dev_priv) && INTEL_GEN(dev_priv) < 11) 42622239e6dfSDaniele Ceraolo Spurio dev_priv->gt.pm_guc_events = GUC_INTR_GUC2HOST << 16; 426326705e20SSagar Arun Kamble 4264a6706b45SDeepak S /* Let's track the enabled rps events */ 4265666a4537SWayne Boyer if (IS_VALLEYVIEW(dev_priv)) 42666c65a587SVille Syrjälä /* WaGsvRC0ResidencyMethod:vlv */ 4267e0e8c7cbSChris Wilson dev_priv->pm_rps_events = GEN6_PM_RP_UP_EI_EXPIRED; 426831685c25SDeepak S else 42694668f695SChris Wilson dev_priv->pm_rps_events = (GEN6_PM_RP_UP_THRESHOLD | 42704668f695SChris Wilson GEN6_PM_RP_DOWN_THRESHOLD | 42714668f695SChris Wilson GEN6_PM_RP_DOWN_TIMEOUT); 4272a6706b45SDeepak S 4273917dc6b5SMika Kuoppala /* We share the register with other engine */ 4274917dc6b5SMika Kuoppala if (INTEL_GEN(dev_priv) > 9) 4275917dc6b5SMika Kuoppala GEM_WARN_ON(dev_priv->pm_rps_events & 0xffff0000); 4276917dc6b5SMika Kuoppala 4277562d9baeSSagar Arun Kamble rps->pm_intrmsk_mbz = 0; 42781800ad25SSagar Arun Kamble 42791800ad25SSagar Arun Kamble /* 4280acf2dc22SMika Kuoppala * SNB,IVB,HSW can while VLV,CHV may hard hang on looping batchbuffer 42811800ad25SSagar Arun Kamble * if GEN6_PM_UP_EI_EXPIRED is masked. 42821800ad25SSagar Arun Kamble * 42831800ad25SSagar Arun Kamble * TODO: verify if this can be reproduced on VLV,CHV. 42841800ad25SSagar Arun Kamble */ 4285bca2bf2aSPandiyan, Dhinakaran if (INTEL_GEN(dev_priv) <= 7) 4286562d9baeSSagar Arun Kamble rps->pm_intrmsk_mbz |= GEN6_PM_RP_UP_EI_EXPIRED; 42871800ad25SSagar Arun Kamble 4288bca2bf2aSPandiyan, Dhinakaran if (INTEL_GEN(dev_priv) >= 8) 4289562d9baeSSagar Arun Kamble rps->pm_intrmsk_mbz |= GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC; 42901800ad25SSagar Arun Kamble 429121da2700SVille Syrjälä dev->vblank_disable_immediate = true; 429221da2700SVille Syrjälä 4293262fd485SChris Wilson /* Most platforms treat the display irq block as an always-on 4294262fd485SChris Wilson * power domain. vlv/chv can disable it at runtime and need 4295262fd485SChris Wilson * special care to avoid writing any of the display block registers 4296262fd485SChris Wilson * outside of the power domain. We defer setting up the display irqs 4297262fd485SChris Wilson * in this case to the runtime pm. 4298262fd485SChris Wilson */ 4299262fd485SChris Wilson dev_priv->display_irqs_enabled = true; 4300262fd485SChris Wilson if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) 4301262fd485SChris Wilson dev_priv->display_irqs_enabled = false; 4302262fd485SChris Wilson 4303317eaa95SLyude dev_priv->hotplug.hpd_storm_threshold = HPD_STORM_DEFAULT_THRESHOLD; 43049a64c650SLyude Paul /* If we have MST support, we want to avoid doing short HPD IRQ storm 43059a64c650SLyude Paul * detection, as short HPD storms will occur as a natural part of 43069a64c650SLyude Paul * sideband messaging with MST. 43079a64c650SLyude Paul * On older platforms however, IRQ storms can occur with both long and 43089a64c650SLyude Paul * short pulses, as seen on some G4x systems. 43099a64c650SLyude Paul */ 43109a64c650SLyude Paul dev_priv->hotplug.hpd_short_storm_enabled = !HAS_DP_MST(dev_priv); 4311317eaa95SLyude 4312b318b824SVille Syrjälä if (HAS_GMCH(dev_priv)) { 4313b318b824SVille Syrjälä if (I915_HAS_HOTPLUG(dev_priv)) 431443f328d7SVille Syrjälä dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 4315b318b824SVille Syrjälä } else { 43168ef7e340SMatt Roper if (HAS_PCH_MCC(dev_priv)) 43178ef7e340SMatt Roper dev_priv->display.hpd_irq_setup = mcc_hpd_irq_setup; 43188ef7e340SMatt Roper else if (INTEL_GEN(dev_priv) >= 11) 4319121e758eSDhinakaran Pandiyan dev_priv->display.hpd_irq_setup = gen11_hpd_irq_setup; 4320b318b824SVille Syrjälä else if (IS_GEN9_LP(dev_priv)) 4321e0a20ad7SShashank Sharma dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup; 4322c6c30b91SRodrigo Vivi else if (INTEL_PCH_TYPE(dev_priv) >= PCH_SPT) 43236dbf30ceSVille Syrjälä dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup; 43246dbf30ceSVille Syrjälä else 43253a3b3c7dSVille Syrjälä dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup; 4326f71d4af4SJesse Barnes } 4327f71d4af4SJesse Barnes } 432820afbda2SDaniel Vetter 4329fca52a55SDaniel Vetter /** 4330cefcff8fSJoonas Lahtinen * intel_irq_fini - deinitializes IRQ support 4331cefcff8fSJoonas Lahtinen * @i915: i915 device instance 4332cefcff8fSJoonas Lahtinen * 4333cefcff8fSJoonas Lahtinen * This function deinitializes all the IRQ support. 4334cefcff8fSJoonas Lahtinen */ 4335cefcff8fSJoonas Lahtinen void intel_irq_fini(struct drm_i915_private *i915) 4336cefcff8fSJoonas Lahtinen { 4337cefcff8fSJoonas Lahtinen int i; 4338cefcff8fSJoonas Lahtinen 4339cefcff8fSJoonas Lahtinen for (i = 0; i < MAX_L3_SLICES; ++i) 4340cefcff8fSJoonas Lahtinen kfree(i915->l3_parity.remap_info[i]); 4341cefcff8fSJoonas Lahtinen } 4342cefcff8fSJoonas Lahtinen 4343b318b824SVille Syrjälä static irq_handler_t intel_irq_handler(struct drm_i915_private *dev_priv) 4344b318b824SVille Syrjälä { 4345b318b824SVille Syrjälä if (HAS_GMCH(dev_priv)) { 4346b318b824SVille Syrjälä if (IS_CHERRYVIEW(dev_priv)) 4347b318b824SVille Syrjälä return cherryview_irq_handler; 4348b318b824SVille Syrjälä else if (IS_VALLEYVIEW(dev_priv)) 4349b318b824SVille Syrjälä return valleyview_irq_handler; 4350b318b824SVille Syrjälä else if (IS_GEN(dev_priv, 4)) 4351b318b824SVille Syrjälä return i965_irq_handler; 4352b318b824SVille Syrjälä else if (IS_GEN(dev_priv, 3)) 4353b318b824SVille Syrjälä return i915_irq_handler; 4354b318b824SVille Syrjälä else 4355b318b824SVille Syrjälä return i8xx_irq_handler; 4356b318b824SVille Syrjälä } else { 4357b318b824SVille Syrjälä if (INTEL_GEN(dev_priv) >= 11) 4358b318b824SVille Syrjälä return gen11_irq_handler; 4359b318b824SVille Syrjälä else if (INTEL_GEN(dev_priv) >= 8) 4360b318b824SVille Syrjälä return gen8_irq_handler; 4361b318b824SVille Syrjälä else 4362b318b824SVille Syrjälä return ironlake_irq_handler; 4363b318b824SVille Syrjälä } 4364b318b824SVille Syrjälä } 4365b318b824SVille Syrjälä 4366b318b824SVille Syrjälä static void intel_irq_reset(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ä cherryview_irq_reset(dev_priv); 4371b318b824SVille Syrjälä else if (IS_VALLEYVIEW(dev_priv)) 4372b318b824SVille Syrjälä valleyview_irq_reset(dev_priv); 4373b318b824SVille Syrjälä else if (IS_GEN(dev_priv, 4)) 4374b318b824SVille Syrjälä i965_irq_reset(dev_priv); 4375b318b824SVille Syrjälä else if (IS_GEN(dev_priv, 3)) 4376b318b824SVille Syrjälä i915_irq_reset(dev_priv); 4377b318b824SVille Syrjälä else 4378b318b824SVille Syrjälä i8xx_irq_reset(dev_priv); 4379b318b824SVille Syrjälä } else { 4380b318b824SVille Syrjälä if (INTEL_GEN(dev_priv) >= 11) 4381b318b824SVille Syrjälä gen11_irq_reset(dev_priv); 4382b318b824SVille Syrjälä else if (INTEL_GEN(dev_priv) >= 8) 4383b318b824SVille Syrjälä gen8_irq_reset(dev_priv); 4384b318b824SVille Syrjälä else 4385b318b824SVille Syrjälä ironlake_irq_reset(dev_priv); 4386b318b824SVille Syrjälä } 4387b318b824SVille Syrjälä } 4388b318b824SVille Syrjälä 4389b318b824SVille Syrjälä static void intel_irq_postinstall(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_postinstall(dev_priv); 4394b318b824SVille Syrjälä else if (IS_VALLEYVIEW(dev_priv)) 4395b318b824SVille Syrjälä valleyview_irq_postinstall(dev_priv); 4396b318b824SVille Syrjälä else if (IS_GEN(dev_priv, 4)) 4397b318b824SVille Syrjälä i965_irq_postinstall(dev_priv); 4398b318b824SVille Syrjälä else if (IS_GEN(dev_priv, 3)) 4399b318b824SVille Syrjälä i915_irq_postinstall(dev_priv); 4400b318b824SVille Syrjälä else 4401b318b824SVille Syrjälä i8xx_irq_postinstall(dev_priv); 4402b318b824SVille Syrjälä } else { 4403b318b824SVille Syrjälä if (INTEL_GEN(dev_priv) >= 11) 4404b318b824SVille Syrjälä gen11_irq_postinstall(dev_priv); 4405b318b824SVille Syrjälä else if (INTEL_GEN(dev_priv) >= 8) 4406b318b824SVille Syrjälä gen8_irq_postinstall(dev_priv); 4407b318b824SVille Syrjälä else 4408b318b824SVille Syrjälä ironlake_irq_postinstall(dev_priv); 4409b318b824SVille Syrjälä } 4410b318b824SVille Syrjälä } 4411b318b824SVille Syrjälä 4412cefcff8fSJoonas Lahtinen /** 4413fca52a55SDaniel Vetter * intel_irq_install - enables the hardware interrupt 4414fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4415fca52a55SDaniel Vetter * 4416fca52a55SDaniel Vetter * This function enables the hardware interrupt handling, but leaves the hotplug 4417fca52a55SDaniel Vetter * handling still disabled. It is called after intel_irq_init(). 4418fca52a55SDaniel Vetter * 4419fca52a55SDaniel Vetter * In the driver load and resume code we need working interrupts in a few places 4420fca52a55SDaniel Vetter * but don't want to deal with the hassle of concurrent probe and hotplug 4421fca52a55SDaniel Vetter * workers. Hence the split into this two-stage approach. 4422fca52a55SDaniel Vetter */ 44232aeb7d3aSDaniel Vetter int intel_irq_install(struct drm_i915_private *dev_priv) 44242aeb7d3aSDaniel Vetter { 4425b318b824SVille Syrjälä int irq = dev_priv->drm.pdev->irq; 4426b318b824SVille Syrjälä int ret; 4427b318b824SVille Syrjälä 44282aeb7d3aSDaniel Vetter /* 44292aeb7d3aSDaniel Vetter * We enable some interrupt sources in our postinstall hooks, so mark 44302aeb7d3aSDaniel Vetter * interrupts as enabled _before_ actually enabling them to avoid 44312aeb7d3aSDaniel Vetter * special cases in our ordering checks. 44322aeb7d3aSDaniel Vetter */ 4433ad1443f0SSagar Arun Kamble dev_priv->runtime_pm.irqs_enabled = true; 44342aeb7d3aSDaniel Vetter 4435b318b824SVille Syrjälä dev_priv->drm.irq_enabled = true; 4436b318b824SVille Syrjälä 4437b318b824SVille Syrjälä intel_irq_reset(dev_priv); 4438b318b824SVille Syrjälä 4439b318b824SVille Syrjälä ret = request_irq(irq, intel_irq_handler(dev_priv), 4440b318b824SVille Syrjälä IRQF_SHARED, DRIVER_NAME, dev_priv); 4441b318b824SVille Syrjälä if (ret < 0) { 4442b318b824SVille Syrjälä dev_priv->drm.irq_enabled = false; 4443b318b824SVille Syrjälä return ret; 4444b318b824SVille Syrjälä } 4445b318b824SVille Syrjälä 4446b318b824SVille Syrjälä intel_irq_postinstall(dev_priv); 4447b318b824SVille Syrjälä 4448b318b824SVille Syrjälä return ret; 44492aeb7d3aSDaniel Vetter } 44502aeb7d3aSDaniel Vetter 4451fca52a55SDaniel Vetter /** 4452fca52a55SDaniel Vetter * intel_irq_uninstall - finilizes all irq handling 4453fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4454fca52a55SDaniel Vetter * 4455fca52a55SDaniel Vetter * This stops interrupt and hotplug handling and unregisters and frees all 4456fca52a55SDaniel Vetter * resources acquired in the init functions. 4457fca52a55SDaniel Vetter */ 44582aeb7d3aSDaniel Vetter void intel_irq_uninstall(struct drm_i915_private *dev_priv) 44592aeb7d3aSDaniel Vetter { 4460b318b824SVille Syrjälä int irq = dev_priv->drm.pdev->irq; 4461b318b824SVille Syrjälä 4462b318b824SVille Syrjälä /* 4463b318b824SVille Syrjälä * FIXME we can get called twice during driver load 4464b318b824SVille Syrjälä * error handling due to intel_modeset_cleanup() 4465b318b824SVille Syrjälä * calling us out of sequence. Would be nice if 4466b318b824SVille Syrjälä * it didn't do that... 4467b318b824SVille Syrjälä */ 4468b318b824SVille Syrjälä if (!dev_priv->drm.irq_enabled) 4469b318b824SVille Syrjälä return; 4470b318b824SVille Syrjälä 4471b318b824SVille Syrjälä dev_priv->drm.irq_enabled = false; 4472b318b824SVille Syrjälä 4473b318b824SVille Syrjälä intel_irq_reset(dev_priv); 4474b318b824SVille Syrjälä 4475b318b824SVille Syrjälä free_irq(irq, dev_priv); 4476b318b824SVille Syrjälä 44772aeb7d3aSDaniel Vetter intel_hpd_cancel_work(dev_priv); 4478ad1443f0SSagar Arun Kamble dev_priv->runtime_pm.irqs_enabled = false; 44792aeb7d3aSDaniel Vetter } 44802aeb7d3aSDaniel Vetter 4481fca52a55SDaniel Vetter /** 4482fca52a55SDaniel Vetter * intel_runtime_pm_disable_interrupts - runtime interrupt disabling 4483fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4484fca52a55SDaniel Vetter * 4485fca52a55SDaniel Vetter * This function is used to disable interrupts at runtime, both in the runtime 4486fca52a55SDaniel Vetter * pm and the system suspend/resume code. 4487fca52a55SDaniel Vetter */ 4488b963291cSDaniel Vetter void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv) 4489c67a470bSPaulo Zanoni { 4490b318b824SVille Syrjälä intel_irq_reset(dev_priv); 4491ad1443f0SSagar Arun Kamble dev_priv->runtime_pm.irqs_enabled = false; 4492315ca4c4SVille Syrjälä intel_synchronize_irq(dev_priv); 4493c67a470bSPaulo Zanoni } 4494c67a470bSPaulo Zanoni 4495fca52a55SDaniel Vetter /** 4496fca52a55SDaniel Vetter * intel_runtime_pm_enable_interrupts - runtime interrupt enabling 4497fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4498fca52a55SDaniel Vetter * 4499fca52a55SDaniel Vetter * This function is used to enable interrupts at runtime, both in the runtime 4500fca52a55SDaniel Vetter * pm and the system suspend/resume code. 4501fca52a55SDaniel Vetter */ 4502b963291cSDaniel Vetter void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv) 4503c67a470bSPaulo Zanoni { 4504ad1443f0SSagar Arun Kamble dev_priv->runtime_pm.irqs_enabled = true; 4505b318b824SVille Syrjälä intel_irq_reset(dev_priv); 4506b318b824SVille Syrjälä intel_irq_postinstall(dev_priv); 4507c67a470bSPaulo Zanoni } 4508d64575eeSJani Nikula 4509d64575eeSJani Nikula bool intel_irqs_enabled(struct drm_i915_private *dev_priv) 4510d64575eeSJani Nikula { 4511d64575eeSJani Nikula /* 4512d64575eeSJani Nikula * We only use drm_irq_uninstall() at unload and VT switch, so 4513d64575eeSJani Nikula * this is the only thing we need to check. 4514d64575eeSJani Nikula */ 4515d64575eeSJani Nikula return dev_priv->runtime_pm.irqs_enabled; 4516d64575eeSJani Nikula } 4517d64575eeSJani Nikula 4518d64575eeSJani Nikula void intel_synchronize_irq(struct drm_i915_private *i915) 4519d64575eeSJani Nikula { 4520d64575eeSJani Nikula synchronize_irq(i915->drm.pdev->irq); 4521d64575eeSJani Nikula } 4522