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 3163eeaf38SJesse Barnes #include <linux/sysrq.h> 325a0e3ad6STejun Heo #include <linux/slab.h> 33b2c88f5bSDamien Lespiau #include <linux/circ_buf.h> 34760285e7SDavid Howells #include <drm/drmP.h> 35760285e7SDavid Howells #include <drm/i915_drm.h> 36c0e09200SDave Airlie #include "i915_drv.h" 371c5d22f7SChris Wilson #include "i915_trace.h" 3879e53945SJesse Barnes #include "intel_drv.h" 39c0e09200SDave Airlie 40fca52a55SDaniel Vetter /** 41fca52a55SDaniel Vetter * DOC: interrupt handling 42fca52a55SDaniel Vetter * 43fca52a55SDaniel Vetter * These functions provide the basic support for enabling and disabling the 44fca52a55SDaniel Vetter * interrupt handling support. There's a lot more functionality in i915_irq.c 45fca52a55SDaniel Vetter * and related files, but that will be described in separate chapters. 46fca52a55SDaniel Vetter */ 47fca52a55SDaniel Vetter 48e4ce95aaSVille Syrjälä static const u32 hpd_ilk[HPD_NUM_PINS] = { 49e4ce95aaSVille Syrjälä [HPD_PORT_A] = DE_DP_A_HOTPLUG, 50e4ce95aaSVille Syrjälä }; 51e4ce95aaSVille Syrjälä 5223bb4cb5SVille Syrjälä static const u32 hpd_ivb[HPD_NUM_PINS] = { 5323bb4cb5SVille Syrjälä [HPD_PORT_A] = DE_DP_A_HOTPLUG_IVB, 5423bb4cb5SVille Syrjälä }; 5523bb4cb5SVille Syrjälä 563a3b3c7dSVille Syrjälä static const u32 hpd_bdw[HPD_NUM_PINS] = { 573a3b3c7dSVille Syrjälä [HPD_PORT_A] = GEN8_PORT_DP_A_HOTPLUG, 583a3b3c7dSVille Syrjälä }; 593a3b3c7dSVille Syrjälä 607c7e10dbSVille Syrjälä static const u32 hpd_ibx[HPD_NUM_PINS] = { 61e5868a31SEgbert Eich [HPD_CRT] = SDE_CRT_HOTPLUG, 62e5868a31SEgbert Eich [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG, 63e5868a31SEgbert Eich [HPD_PORT_B] = SDE_PORTB_HOTPLUG, 64e5868a31SEgbert Eich [HPD_PORT_C] = SDE_PORTC_HOTPLUG, 65e5868a31SEgbert Eich [HPD_PORT_D] = SDE_PORTD_HOTPLUG 66e5868a31SEgbert Eich }; 67e5868a31SEgbert Eich 687c7e10dbSVille Syrjälä static const u32 hpd_cpt[HPD_NUM_PINS] = { 69e5868a31SEgbert Eich [HPD_CRT] = SDE_CRT_HOTPLUG_CPT, 7073c352a2SDaniel Vetter [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT, 71e5868a31SEgbert Eich [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT, 72e5868a31SEgbert Eich [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT, 73e5868a31SEgbert Eich [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT 74e5868a31SEgbert Eich }; 75e5868a31SEgbert Eich 7626951cafSXiong Zhang static const u32 hpd_spt[HPD_NUM_PINS] = { 7774c0b395SVille Syrjälä [HPD_PORT_A] = SDE_PORTA_HOTPLUG_SPT, 7826951cafSXiong Zhang [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT, 7926951cafSXiong Zhang [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT, 8026951cafSXiong Zhang [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT, 8126951cafSXiong Zhang [HPD_PORT_E] = SDE_PORTE_HOTPLUG_SPT 8226951cafSXiong Zhang }; 8326951cafSXiong Zhang 847c7e10dbSVille Syrjälä static const u32 hpd_mask_i915[HPD_NUM_PINS] = { 85e5868a31SEgbert Eich [HPD_CRT] = CRT_HOTPLUG_INT_EN, 86e5868a31SEgbert Eich [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN, 87e5868a31SEgbert Eich [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN, 88e5868a31SEgbert Eich [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN, 89e5868a31SEgbert Eich [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN, 90e5868a31SEgbert Eich [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN 91e5868a31SEgbert Eich }; 92e5868a31SEgbert Eich 937c7e10dbSVille Syrjälä static const u32 hpd_status_g4x[HPD_NUM_PINS] = { 94e5868a31SEgbert Eich [HPD_CRT] = CRT_HOTPLUG_INT_STATUS, 95e5868a31SEgbert Eich [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X, 96e5868a31SEgbert Eich [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X, 97e5868a31SEgbert Eich [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS, 98e5868a31SEgbert Eich [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS, 99e5868a31SEgbert Eich [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS 100e5868a31SEgbert Eich }; 101e5868a31SEgbert Eich 1024bca26d0SVille Syrjälä static const u32 hpd_status_i915[HPD_NUM_PINS] = { 103e5868a31SEgbert Eich [HPD_CRT] = CRT_HOTPLUG_INT_STATUS, 104e5868a31SEgbert Eich [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915, 105e5868a31SEgbert Eich [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915, 106e5868a31SEgbert Eich [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS, 107e5868a31SEgbert Eich [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS, 108e5868a31SEgbert Eich [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS 109e5868a31SEgbert Eich }; 110e5868a31SEgbert Eich 111e0a20ad7SShashank Sharma /* BXT hpd list */ 112e0a20ad7SShashank Sharma static const u32 hpd_bxt[HPD_NUM_PINS] = { 1137f3561beSSonika Jindal [HPD_PORT_A] = BXT_DE_PORT_HP_DDIA, 114e0a20ad7SShashank Sharma [HPD_PORT_B] = BXT_DE_PORT_HP_DDIB, 115e0a20ad7SShashank Sharma [HPD_PORT_C] = BXT_DE_PORT_HP_DDIC 116e0a20ad7SShashank Sharma }; 117e0a20ad7SShashank Sharma 1185c502442SPaulo Zanoni /* IIR can theoretically queue up two events. Be paranoid. */ 119f86f3fb0SPaulo Zanoni #define GEN8_IRQ_RESET_NDX(type, which) do { \ 1205c502442SPaulo Zanoni I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \ 1215c502442SPaulo Zanoni POSTING_READ(GEN8_##type##_IMR(which)); \ 1225c502442SPaulo Zanoni I915_WRITE(GEN8_##type##_IER(which), 0); \ 1235c502442SPaulo Zanoni I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \ 1245c502442SPaulo Zanoni POSTING_READ(GEN8_##type##_IIR(which)); \ 1255c502442SPaulo Zanoni I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \ 1265c502442SPaulo Zanoni POSTING_READ(GEN8_##type##_IIR(which)); \ 1275c502442SPaulo Zanoni } while (0) 1285c502442SPaulo Zanoni 1293488d4ebSVille Syrjälä #define GEN3_IRQ_RESET(type) do { \ 130a9d356a6SPaulo Zanoni I915_WRITE(type##IMR, 0xffffffff); \ 1315c502442SPaulo Zanoni POSTING_READ(type##IMR); \ 132a9d356a6SPaulo Zanoni I915_WRITE(type##IER, 0); \ 1335c502442SPaulo Zanoni I915_WRITE(type##IIR, 0xffffffff); \ 1345c502442SPaulo Zanoni POSTING_READ(type##IIR); \ 1355c502442SPaulo Zanoni I915_WRITE(type##IIR, 0xffffffff); \ 1365c502442SPaulo Zanoni POSTING_READ(type##IIR); \ 137a9d356a6SPaulo Zanoni } while (0) 138a9d356a6SPaulo Zanoni 139e9e9848aSVille Syrjälä #define GEN2_IRQ_RESET(type) do { \ 140e9e9848aSVille Syrjälä I915_WRITE16(type##IMR, 0xffff); \ 141e9e9848aSVille Syrjälä POSTING_READ16(type##IMR); \ 142e9e9848aSVille Syrjälä I915_WRITE16(type##IER, 0); \ 143e9e9848aSVille Syrjälä I915_WRITE16(type##IIR, 0xffff); \ 144e9e9848aSVille Syrjälä POSTING_READ16(type##IIR); \ 145e9e9848aSVille Syrjälä I915_WRITE16(type##IIR, 0xffff); \ 146e9e9848aSVille Syrjälä POSTING_READ16(type##IIR); \ 147e9e9848aSVille Syrjälä } while (0) 148e9e9848aSVille Syrjälä 149337ba017SPaulo Zanoni /* 150337ba017SPaulo Zanoni * We should clear IMR at preinstall/uninstall, and just check at postinstall. 151337ba017SPaulo Zanoni */ 1523488d4ebSVille Syrjälä static void gen3_assert_iir_is_zero(struct drm_i915_private *dev_priv, 153f0f59a00SVille Syrjälä i915_reg_t reg) 154b51a2842SVille Syrjälä { 155b51a2842SVille Syrjälä u32 val = I915_READ(reg); 156b51a2842SVille Syrjälä 157b51a2842SVille Syrjälä if (val == 0) 158b51a2842SVille Syrjälä return; 159b51a2842SVille Syrjälä 160b51a2842SVille Syrjälä WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n", 161f0f59a00SVille Syrjälä i915_mmio_reg_offset(reg), val); 162b51a2842SVille Syrjälä I915_WRITE(reg, 0xffffffff); 163b51a2842SVille Syrjälä POSTING_READ(reg); 164b51a2842SVille Syrjälä I915_WRITE(reg, 0xffffffff); 165b51a2842SVille Syrjälä POSTING_READ(reg); 166b51a2842SVille Syrjälä } 167337ba017SPaulo Zanoni 168e9e9848aSVille Syrjälä static void gen2_assert_iir_is_zero(struct drm_i915_private *dev_priv, 169e9e9848aSVille Syrjälä i915_reg_t reg) 170e9e9848aSVille Syrjälä { 171e9e9848aSVille Syrjälä u16 val = I915_READ16(reg); 172e9e9848aSVille Syrjälä 173e9e9848aSVille Syrjälä if (val == 0) 174e9e9848aSVille Syrjälä return; 175e9e9848aSVille Syrjälä 176e9e9848aSVille Syrjälä WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n", 177e9e9848aSVille Syrjälä i915_mmio_reg_offset(reg), val); 178e9e9848aSVille Syrjälä I915_WRITE16(reg, 0xffff); 179e9e9848aSVille Syrjälä POSTING_READ16(reg); 180e9e9848aSVille Syrjälä I915_WRITE16(reg, 0xffff); 181e9e9848aSVille Syrjälä POSTING_READ16(reg); 182e9e9848aSVille Syrjälä } 183e9e9848aSVille Syrjälä 18435079899SPaulo Zanoni #define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \ 1853488d4ebSVille Syrjälä gen3_assert_iir_is_zero(dev_priv, GEN8_##type##_IIR(which)); \ 18635079899SPaulo Zanoni I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \ 1877d1bd539SVille Syrjälä I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \ 1887d1bd539SVille Syrjälä POSTING_READ(GEN8_##type##_IMR(which)); \ 18935079899SPaulo Zanoni } while (0) 19035079899SPaulo Zanoni 1913488d4ebSVille Syrjälä #define GEN3_IRQ_INIT(type, imr_val, ier_val) do { \ 1923488d4ebSVille Syrjälä gen3_assert_iir_is_zero(dev_priv, type##IIR); \ 19335079899SPaulo Zanoni I915_WRITE(type##IER, (ier_val)); \ 1947d1bd539SVille Syrjälä I915_WRITE(type##IMR, (imr_val)); \ 1957d1bd539SVille Syrjälä POSTING_READ(type##IMR); \ 19635079899SPaulo Zanoni } while (0) 19735079899SPaulo Zanoni 198e9e9848aSVille Syrjälä #define GEN2_IRQ_INIT(type, imr_val, ier_val) do { \ 199e9e9848aSVille Syrjälä gen2_assert_iir_is_zero(dev_priv, type##IIR); \ 200e9e9848aSVille Syrjälä I915_WRITE16(type##IER, (ier_val)); \ 201e9e9848aSVille Syrjälä I915_WRITE16(type##IMR, (imr_val)); \ 202e9e9848aSVille Syrjälä POSTING_READ16(type##IMR); \ 203e9e9848aSVille Syrjälä } while (0) 204e9e9848aSVille Syrjälä 205c9a9a268SImre Deak static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir); 20626705e20SSagar Arun Kamble static void gen9_guc_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir); 207c9a9a268SImre Deak 2080706f17cSEgbert Eich /* For display hotplug interrupt */ 2090706f17cSEgbert Eich static inline void 2100706f17cSEgbert Eich i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv, 2110706f17cSEgbert Eich uint32_t mask, 2120706f17cSEgbert Eich uint32_t bits) 2130706f17cSEgbert Eich { 2140706f17cSEgbert Eich uint32_t val; 2150706f17cSEgbert Eich 21667520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 2170706f17cSEgbert Eich WARN_ON(bits & ~mask); 2180706f17cSEgbert Eich 2190706f17cSEgbert Eich val = I915_READ(PORT_HOTPLUG_EN); 2200706f17cSEgbert Eich val &= ~mask; 2210706f17cSEgbert Eich val |= bits; 2220706f17cSEgbert Eich I915_WRITE(PORT_HOTPLUG_EN, val); 2230706f17cSEgbert Eich } 2240706f17cSEgbert Eich 2250706f17cSEgbert Eich /** 2260706f17cSEgbert Eich * i915_hotplug_interrupt_update - update hotplug interrupt enable 2270706f17cSEgbert Eich * @dev_priv: driver private 2280706f17cSEgbert Eich * @mask: bits to update 2290706f17cSEgbert Eich * @bits: bits to enable 2300706f17cSEgbert Eich * NOTE: the HPD enable bits are modified both inside and outside 2310706f17cSEgbert Eich * of an interrupt context. To avoid that read-modify-write cycles 2320706f17cSEgbert Eich * interfer, these bits are protected by a spinlock. Since this 2330706f17cSEgbert Eich * function is usually not called from a context where the lock is 2340706f17cSEgbert Eich * held already, this function acquires the lock itself. A non-locking 2350706f17cSEgbert Eich * version is also available. 2360706f17cSEgbert Eich */ 2370706f17cSEgbert Eich void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv, 2380706f17cSEgbert Eich uint32_t mask, 2390706f17cSEgbert Eich uint32_t bits) 2400706f17cSEgbert Eich { 2410706f17cSEgbert Eich spin_lock_irq(&dev_priv->irq_lock); 2420706f17cSEgbert Eich i915_hotplug_interrupt_update_locked(dev_priv, mask, bits); 2430706f17cSEgbert Eich spin_unlock_irq(&dev_priv->irq_lock); 2440706f17cSEgbert Eich } 2450706f17cSEgbert Eich 246d9dc34f1SVille Syrjälä /** 247d9dc34f1SVille Syrjälä * ilk_update_display_irq - update DEIMR 248d9dc34f1SVille Syrjälä * @dev_priv: driver private 249d9dc34f1SVille Syrjälä * @interrupt_mask: mask of interrupt bits to update 250d9dc34f1SVille Syrjälä * @enabled_irq_mask: mask of interrupt bits to enable 251d9dc34f1SVille Syrjälä */ 252fbdedaeaSVille Syrjälä void ilk_update_display_irq(struct drm_i915_private *dev_priv, 253d9dc34f1SVille Syrjälä uint32_t interrupt_mask, 254d9dc34f1SVille Syrjälä uint32_t enabled_irq_mask) 255036a4a7dSZhenyu Wang { 256d9dc34f1SVille Syrjälä uint32_t new_val; 257d9dc34f1SVille Syrjälä 25867520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 2594bc9d430SDaniel Vetter 260d9dc34f1SVille Syrjälä WARN_ON(enabled_irq_mask & ~interrupt_mask); 261d9dc34f1SVille Syrjälä 2629df7575fSJesse Barnes if (WARN_ON(!intel_irqs_enabled(dev_priv))) 263c67a470bSPaulo Zanoni return; 264c67a470bSPaulo Zanoni 265d9dc34f1SVille Syrjälä new_val = dev_priv->irq_mask; 266d9dc34f1SVille Syrjälä new_val &= ~interrupt_mask; 267d9dc34f1SVille Syrjälä new_val |= (~enabled_irq_mask & interrupt_mask); 268d9dc34f1SVille Syrjälä 269d9dc34f1SVille Syrjälä if (new_val != dev_priv->irq_mask) { 270d9dc34f1SVille Syrjälä dev_priv->irq_mask = new_val; 2711ec14ad3SChris Wilson I915_WRITE(DEIMR, dev_priv->irq_mask); 2723143a2bfSChris Wilson POSTING_READ(DEIMR); 273036a4a7dSZhenyu Wang } 274036a4a7dSZhenyu Wang } 275036a4a7dSZhenyu Wang 27643eaea13SPaulo Zanoni /** 27743eaea13SPaulo Zanoni * ilk_update_gt_irq - update GTIMR 27843eaea13SPaulo Zanoni * @dev_priv: driver private 27943eaea13SPaulo Zanoni * @interrupt_mask: mask of interrupt bits to update 28043eaea13SPaulo Zanoni * @enabled_irq_mask: mask of interrupt bits to enable 28143eaea13SPaulo Zanoni */ 28243eaea13SPaulo Zanoni static void ilk_update_gt_irq(struct drm_i915_private *dev_priv, 28343eaea13SPaulo Zanoni uint32_t interrupt_mask, 28443eaea13SPaulo Zanoni uint32_t enabled_irq_mask) 28543eaea13SPaulo Zanoni { 28667520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 28743eaea13SPaulo Zanoni 28815a17aaeSDaniel Vetter WARN_ON(enabled_irq_mask & ~interrupt_mask); 28915a17aaeSDaniel Vetter 2909df7575fSJesse Barnes if (WARN_ON(!intel_irqs_enabled(dev_priv))) 291c67a470bSPaulo Zanoni return; 292c67a470bSPaulo Zanoni 29343eaea13SPaulo Zanoni dev_priv->gt_irq_mask &= ~interrupt_mask; 29443eaea13SPaulo Zanoni dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask); 29543eaea13SPaulo Zanoni I915_WRITE(GTIMR, dev_priv->gt_irq_mask); 29643eaea13SPaulo Zanoni } 29743eaea13SPaulo Zanoni 298480c8033SDaniel Vetter void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask) 29943eaea13SPaulo Zanoni { 30043eaea13SPaulo Zanoni ilk_update_gt_irq(dev_priv, mask, mask); 30131bb59ccSChris Wilson POSTING_READ_FW(GTIMR); 30243eaea13SPaulo Zanoni } 30343eaea13SPaulo Zanoni 304480c8033SDaniel Vetter void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask) 30543eaea13SPaulo Zanoni { 30643eaea13SPaulo Zanoni ilk_update_gt_irq(dev_priv, mask, 0); 30743eaea13SPaulo Zanoni } 30843eaea13SPaulo Zanoni 309f0f59a00SVille Syrjälä static i915_reg_t gen6_pm_iir(struct drm_i915_private *dev_priv) 310b900b949SImre Deak { 311bca2bf2aSPandiyan, Dhinakaran return INTEL_GEN(dev_priv) >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR; 312b900b949SImre Deak } 313b900b949SImre Deak 314f0f59a00SVille Syrjälä static i915_reg_t gen6_pm_imr(struct drm_i915_private *dev_priv) 315a72fbc3aSImre Deak { 316bca2bf2aSPandiyan, Dhinakaran return INTEL_GEN(dev_priv) >= 8 ? GEN8_GT_IMR(2) : GEN6_PMIMR; 317a72fbc3aSImre Deak } 318a72fbc3aSImre Deak 319f0f59a00SVille Syrjälä static i915_reg_t gen6_pm_ier(struct drm_i915_private *dev_priv) 320b900b949SImre Deak { 321bca2bf2aSPandiyan, Dhinakaran return INTEL_GEN(dev_priv) >= 8 ? GEN8_GT_IER(2) : GEN6_PMIER; 322b900b949SImre Deak } 323b900b949SImre Deak 324edbfdb45SPaulo Zanoni /** 325edbfdb45SPaulo Zanoni * snb_update_pm_irq - update GEN6_PMIMR 326edbfdb45SPaulo Zanoni * @dev_priv: driver private 327edbfdb45SPaulo Zanoni * @interrupt_mask: mask of interrupt bits to update 328edbfdb45SPaulo Zanoni * @enabled_irq_mask: mask of interrupt bits to enable 329edbfdb45SPaulo Zanoni */ 330edbfdb45SPaulo Zanoni static void snb_update_pm_irq(struct drm_i915_private *dev_priv, 331edbfdb45SPaulo Zanoni uint32_t interrupt_mask, 332edbfdb45SPaulo Zanoni uint32_t enabled_irq_mask) 333edbfdb45SPaulo Zanoni { 334605cd25bSPaulo Zanoni uint32_t new_val; 335edbfdb45SPaulo Zanoni 33615a17aaeSDaniel Vetter WARN_ON(enabled_irq_mask & ~interrupt_mask); 33715a17aaeSDaniel Vetter 33867520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 339edbfdb45SPaulo Zanoni 340f4e9af4fSAkash Goel new_val = dev_priv->pm_imr; 341f52ecbcfSPaulo Zanoni new_val &= ~interrupt_mask; 342f52ecbcfSPaulo Zanoni new_val |= (~enabled_irq_mask & interrupt_mask); 343f52ecbcfSPaulo Zanoni 344f4e9af4fSAkash Goel if (new_val != dev_priv->pm_imr) { 345f4e9af4fSAkash Goel dev_priv->pm_imr = new_val; 346f4e9af4fSAkash Goel I915_WRITE(gen6_pm_imr(dev_priv), dev_priv->pm_imr); 347a72fbc3aSImre Deak POSTING_READ(gen6_pm_imr(dev_priv)); 348edbfdb45SPaulo Zanoni } 349f52ecbcfSPaulo Zanoni } 350edbfdb45SPaulo Zanoni 351f4e9af4fSAkash Goel void gen6_unmask_pm_irq(struct drm_i915_private *dev_priv, u32 mask) 352edbfdb45SPaulo Zanoni { 3539939fba2SImre Deak if (WARN_ON(!intel_irqs_enabled(dev_priv))) 3549939fba2SImre Deak return; 3559939fba2SImre Deak 356edbfdb45SPaulo Zanoni snb_update_pm_irq(dev_priv, mask, mask); 357edbfdb45SPaulo Zanoni } 358edbfdb45SPaulo Zanoni 359f4e9af4fSAkash Goel static void __gen6_mask_pm_irq(struct drm_i915_private *dev_priv, u32 mask) 3609939fba2SImre Deak { 3619939fba2SImre Deak snb_update_pm_irq(dev_priv, mask, 0); 3629939fba2SImre Deak } 3639939fba2SImre Deak 364f4e9af4fSAkash Goel void gen6_mask_pm_irq(struct drm_i915_private *dev_priv, u32 mask) 365edbfdb45SPaulo Zanoni { 3669939fba2SImre Deak if (WARN_ON(!intel_irqs_enabled(dev_priv))) 3679939fba2SImre Deak return; 3689939fba2SImre Deak 369f4e9af4fSAkash Goel __gen6_mask_pm_irq(dev_priv, mask); 370f4e9af4fSAkash Goel } 371f4e9af4fSAkash Goel 3723814fd77SOscar Mateo static void gen6_reset_pm_iir(struct drm_i915_private *dev_priv, u32 reset_mask) 373f4e9af4fSAkash Goel { 374f4e9af4fSAkash Goel i915_reg_t reg = gen6_pm_iir(dev_priv); 375f4e9af4fSAkash Goel 37667520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 377f4e9af4fSAkash Goel 378f4e9af4fSAkash Goel I915_WRITE(reg, reset_mask); 379f4e9af4fSAkash Goel I915_WRITE(reg, reset_mask); 380f4e9af4fSAkash Goel POSTING_READ(reg); 381f4e9af4fSAkash Goel } 382f4e9af4fSAkash Goel 3833814fd77SOscar Mateo static void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, u32 enable_mask) 384f4e9af4fSAkash Goel { 38567520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 386f4e9af4fSAkash Goel 387f4e9af4fSAkash Goel dev_priv->pm_ier |= enable_mask; 388f4e9af4fSAkash Goel I915_WRITE(gen6_pm_ier(dev_priv), dev_priv->pm_ier); 389f4e9af4fSAkash Goel gen6_unmask_pm_irq(dev_priv, enable_mask); 390f4e9af4fSAkash Goel /* unmask_pm_irq provides an implicit barrier (POSTING_READ) */ 391f4e9af4fSAkash Goel } 392f4e9af4fSAkash Goel 3933814fd77SOscar Mateo static void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, u32 disable_mask) 394f4e9af4fSAkash Goel { 39567520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 396f4e9af4fSAkash Goel 397f4e9af4fSAkash Goel dev_priv->pm_ier &= ~disable_mask; 398f4e9af4fSAkash Goel __gen6_mask_pm_irq(dev_priv, disable_mask); 399f4e9af4fSAkash Goel I915_WRITE(gen6_pm_ier(dev_priv), dev_priv->pm_ier); 400f4e9af4fSAkash Goel /* though a barrier is missing here, but don't really need a one */ 401edbfdb45SPaulo Zanoni } 402edbfdb45SPaulo Zanoni 403dc97997aSChris Wilson void gen6_reset_rps_interrupts(struct drm_i915_private *dev_priv) 4043cc134e3SImre Deak { 4053cc134e3SImre Deak spin_lock_irq(&dev_priv->irq_lock); 406f4e9af4fSAkash Goel gen6_reset_pm_iir(dev_priv, dev_priv->pm_rps_events); 407096fad9eSImre Deak dev_priv->rps.pm_iir = 0; 4083cc134e3SImre Deak spin_unlock_irq(&dev_priv->irq_lock); 4093cc134e3SImre Deak } 4103cc134e3SImre Deak 41191d14251STvrtko Ursulin void gen6_enable_rps_interrupts(struct drm_i915_private *dev_priv) 412b900b949SImre Deak { 413f2a91d1aSChris Wilson if (READ_ONCE(dev_priv->rps.interrupts_enabled)) 414f2a91d1aSChris Wilson return; 415f2a91d1aSChris Wilson 416b900b949SImre Deak spin_lock_irq(&dev_priv->irq_lock); 417c33d247dSChris Wilson WARN_ON_ONCE(dev_priv->rps.pm_iir); 418c33d247dSChris Wilson WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events); 419d4d70aa5SImre Deak dev_priv->rps.interrupts_enabled = true; 420b900b949SImre Deak gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events); 42178e68d36SImre Deak 422b900b949SImre Deak spin_unlock_irq(&dev_priv->irq_lock); 423b900b949SImre Deak } 424b900b949SImre Deak 42591d14251STvrtko Ursulin void gen6_disable_rps_interrupts(struct drm_i915_private *dev_priv) 426b900b949SImre Deak { 427f2a91d1aSChris Wilson if (!READ_ONCE(dev_priv->rps.interrupts_enabled)) 428f2a91d1aSChris Wilson return; 429f2a91d1aSChris Wilson 430d4d70aa5SImre Deak spin_lock_irq(&dev_priv->irq_lock); 431d4d70aa5SImre Deak dev_priv->rps.interrupts_enabled = false; 4329939fba2SImre Deak 433b20e3cfeSDave Gordon I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0u)); 4349939fba2SImre Deak 435f4e9af4fSAkash Goel gen6_disable_pm_irq(dev_priv, dev_priv->pm_rps_events); 43658072ccbSImre Deak 43758072ccbSImre Deak spin_unlock_irq(&dev_priv->irq_lock); 43891c8a326SChris Wilson synchronize_irq(dev_priv->drm.irq); 439c33d247dSChris Wilson 440c33d247dSChris Wilson /* Now that we will not be generating any more work, flush any 4413814fd77SOscar Mateo * outstanding tasks. As we are called on the RPS idle path, 442c33d247dSChris Wilson * we will reset the GPU to minimum frequencies, so the current 443c33d247dSChris Wilson * state of the worker can be discarded. 444c33d247dSChris Wilson */ 445c33d247dSChris Wilson cancel_work_sync(&dev_priv->rps.work); 446c33d247dSChris Wilson gen6_reset_rps_interrupts(dev_priv); 447b900b949SImre Deak } 448b900b949SImre Deak 44926705e20SSagar Arun Kamble void gen9_reset_guc_interrupts(struct drm_i915_private *dev_priv) 45026705e20SSagar Arun Kamble { 45126705e20SSagar Arun Kamble spin_lock_irq(&dev_priv->irq_lock); 45226705e20SSagar Arun Kamble gen6_reset_pm_iir(dev_priv, dev_priv->pm_guc_events); 45326705e20SSagar Arun Kamble spin_unlock_irq(&dev_priv->irq_lock); 45426705e20SSagar Arun Kamble } 45526705e20SSagar Arun Kamble 45626705e20SSagar Arun Kamble void gen9_enable_guc_interrupts(struct drm_i915_private *dev_priv) 45726705e20SSagar Arun Kamble { 45826705e20SSagar Arun Kamble spin_lock_irq(&dev_priv->irq_lock); 45926705e20SSagar Arun Kamble if (!dev_priv->guc.interrupts_enabled) { 46026705e20SSagar Arun Kamble WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) & 46126705e20SSagar Arun Kamble dev_priv->pm_guc_events); 46226705e20SSagar Arun Kamble dev_priv->guc.interrupts_enabled = true; 46326705e20SSagar Arun Kamble gen6_enable_pm_irq(dev_priv, dev_priv->pm_guc_events); 46426705e20SSagar Arun Kamble } 46526705e20SSagar Arun Kamble spin_unlock_irq(&dev_priv->irq_lock); 46626705e20SSagar Arun Kamble } 46726705e20SSagar Arun Kamble 46826705e20SSagar Arun Kamble void gen9_disable_guc_interrupts(struct drm_i915_private *dev_priv) 46926705e20SSagar Arun Kamble { 47026705e20SSagar Arun Kamble spin_lock_irq(&dev_priv->irq_lock); 47126705e20SSagar Arun Kamble dev_priv->guc.interrupts_enabled = false; 47226705e20SSagar Arun Kamble 47326705e20SSagar Arun Kamble gen6_disable_pm_irq(dev_priv, dev_priv->pm_guc_events); 47426705e20SSagar Arun Kamble 47526705e20SSagar Arun Kamble spin_unlock_irq(&dev_priv->irq_lock); 47626705e20SSagar Arun Kamble synchronize_irq(dev_priv->drm.irq); 47726705e20SSagar Arun Kamble 47826705e20SSagar Arun Kamble gen9_reset_guc_interrupts(dev_priv); 47926705e20SSagar Arun Kamble } 48026705e20SSagar Arun Kamble 4810961021aSBen Widawsky /** 4823a3b3c7dSVille Syrjälä * bdw_update_port_irq - update DE port interrupt 4833a3b3c7dSVille Syrjälä * @dev_priv: driver private 4843a3b3c7dSVille Syrjälä * @interrupt_mask: mask of interrupt bits to update 4853a3b3c7dSVille Syrjälä * @enabled_irq_mask: mask of interrupt bits to enable 4863a3b3c7dSVille Syrjälä */ 4873a3b3c7dSVille Syrjälä static void bdw_update_port_irq(struct drm_i915_private *dev_priv, 4883a3b3c7dSVille Syrjälä uint32_t interrupt_mask, 4893a3b3c7dSVille Syrjälä uint32_t enabled_irq_mask) 4903a3b3c7dSVille Syrjälä { 4913a3b3c7dSVille Syrjälä uint32_t new_val; 4923a3b3c7dSVille Syrjälä uint32_t old_val; 4933a3b3c7dSVille Syrjälä 49467520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 4953a3b3c7dSVille Syrjälä 4963a3b3c7dSVille Syrjälä WARN_ON(enabled_irq_mask & ~interrupt_mask); 4973a3b3c7dSVille Syrjälä 4983a3b3c7dSVille Syrjälä if (WARN_ON(!intel_irqs_enabled(dev_priv))) 4993a3b3c7dSVille Syrjälä return; 5003a3b3c7dSVille Syrjälä 5013a3b3c7dSVille Syrjälä old_val = I915_READ(GEN8_DE_PORT_IMR); 5023a3b3c7dSVille Syrjälä 5033a3b3c7dSVille Syrjälä new_val = old_val; 5043a3b3c7dSVille Syrjälä new_val &= ~interrupt_mask; 5053a3b3c7dSVille Syrjälä new_val |= (~enabled_irq_mask & interrupt_mask); 5063a3b3c7dSVille Syrjälä 5073a3b3c7dSVille Syrjälä if (new_val != old_val) { 5083a3b3c7dSVille Syrjälä I915_WRITE(GEN8_DE_PORT_IMR, new_val); 5093a3b3c7dSVille Syrjälä POSTING_READ(GEN8_DE_PORT_IMR); 5103a3b3c7dSVille Syrjälä } 5113a3b3c7dSVille Syrjälä } 5123a3b3c7dSVille Syrjälä 5133a3b3c7dSVille Syrjälä /** 514013d3752SVille Syrjälä * bdw_update_pipe_irq - update DE pipe interrupt 515013d3752SVille Syrjälä * @dev_priv: driver private 516013d3752SVille Syrjälä * @pipe: pipe whose interrupt to update 517013d3752SVille Syrjälä * @interrupt_mask: mask of interrupt bits to update 518013d3752SVille Syrjälä * @enabled_irq_mask: mask of interrupt bits to enable 519013d3752SVille Syrjälä */ 520013d3752SVille Syrjälä void bdw_update_pipe_irq(struct drm_i915_private *dev_priv, 521013d3752SVille Syrjälä enum pipe pipe, 522013d3752SVille Syrjälä uint32_t interrupt_mask, 523013d3752SVille Syrjälä uint32_t enabled_irq_mask) 524013d3752SVille Syrjälä { 525013d3752SVille Syrjälä uint32_t new_val; 526013d3752SVille Syrjälä 52767520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 528013d3752SVille Syrjälä 529013d3752SVille Syrjälä WARN_ON(enabled_irq_mask & ~interrupt_mask); 530013d3752SVille Syrjälä 531013d3752SVille Syrjälä if (WARN_ON(!intel_irqs_enabled(dev_priv))) 532013d3752SVille Syrjälä return; 533013d3752SVille Syrjälä 534013d3752SVille Syrjälä new_val = dev_priv->de_irq_mask[pipe]; 535013d3752SVille Syrjälä new_val &= ~interrupt_mask; 536013d3752SVille Syrjälä new_val |= (~enabled_irq_mask & interrupt_mask); 537013d3752SVille Syrjälä 538013d3752SVille Syrjälä if (new_val != dev_priv->de_irq_mask[pipe]) { 539013d3752SVille Syrjälä dev_priv->de_irq_mask[pipe] = new_val; 540013d3752SVille Syrjälä I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]); 541013d3752SVille Syrjälä POSTING_READ(GEN8_DE_PIPE_IMR(pipe)); 542013d3752SVille Syrjälä } 543013d3752SVille Syrjälä } 544013d3752SVille Syrjälä 545013d3752SVille Syrjälä /** 546fee884edSDaniel Vetter * ibx_display_interrupt_update - update SDEIMR 547fee884edSDaniel Vetter * @dev_priv: driver private 548fee884edSDaniel Vetter * @interrupt_mask: mask of interrupt bits to update 549fee884edSDaniel Vetter * @enabled_irq_mask: mask of interrupt bits to enable 550fee884edSDaniel Vetter */ 55147339cd9SDaniel Vetter void ibx_display_interrupt_update(struct drm_i915_private *dev_priv, 552fee884edSDaniel Vetter uint32_t interrupt_mask, 553fee884edSDaniel Vetter uint32_t enabled_irq_mask) 554fee884edSDaniel Vetter { 555fee884edSDaniel Vetter uint32_t sdeimr = I915_READ(SDEIMR); 556fee884edSDaniel Vetter sdeimr &= ~interrupt_mask; 557fee884edSDaniel Vetter sdeimr |= (~enabled_irq_mask & interrupt_mask); 558fee884edSDaniel Vetter 55915a17aaeSDaniel Vetter WARN_ON(enabled_irq_mask & ~interrupt_mask); 56015a17aaeSDaniel Vetter 56167520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 562fee884edSDaniel Vetter 5639df7575fSJesse Barnes if (WARN_ON(!intel_irqs_enabled(dev_priv))) 564c67a470bSPaulo Zanoni return; 565c67a470bSPaulo Zanoni 566fee884edSDaniel Vetter I915_WRITE(SDEIMR, sdeimr); 567fee884edSDaniel Vetter POSTING_READ(SDEIMR); 568fee884edSDaniel Vetter } 5698664281bSPaulo Zanoni 570b5ea642aSDaniel Vetter static void 571755e9019SImre Deak __i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 572755e9019SImre Deak u32 enable_mask, u32 status_mask) 5737c463586SKeith Packard { 574f0f59a00SVille Syrjälä i915_reg_t reg = PIPESTAT(pipe); 575755e9019SImre Deak u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK; 5767c463586SKeith Packard 57767520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 578d518ce50SDaniel Vetter WARN_ON(!intel_irqs_enabled(dev_priv)); 579b79480baSDaniel Vetter 58004feced9SVille Syrjälä if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK || 58104feced9SVille Syrjälä status_mask & ~PIPESTAT_INT_STATUS_MASK, 58204feced9SVille Syrjälä "pipe %c: enable_mask=0x%x, status_mask=0x%x\n", 58304feced9SVille Syrjälä pipe_name(pipe), enable_mask, status_mask)) 584755e9019SImre Deak return; 585755e9019SImre Deak 586755e9019SImre Deak if ((pipestat & enable_mask) == enable_mask) 58746c06a30SVille Syrjälä return; 58846c06a30SVille Syrjälä 58991d181ddSImre Deak dev_priv->pipestat_irq_mask[pipe] |= status_mask; 59091d181ddSImre Deak 5917c463586SKeith Packard /* Enable the interrupt, clear any pending status */ 592755e9019SImre Deak pipestat |= enable_mask | status_mask; 59346c06a30SVille Syrjälä I915_WRITE(reg, pipestat); 5943143a2bfSChris Wilson POSTING_READ(reg); 5957c463586SKeith Packard } 5967c463586SKeith Packard 597b5ea642aSDaniel Vetter static void 598755e9019SImre Deak __i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 599755e9019SImre Deak u32 enable_mask, u32 status_mask) 6007c463586SKeith Packard { 601f0f59a00SVille Syrjälä i915_reg_t reg = PIPESTAT(pipe); 602755e9019SImre Deak u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK; 6037c463586SKeith Packard 60467520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 605d518ce50SDaniel Vetter WARN_ON(!intel_irqs_enabled(dev_priv)); 606b79480baSDaniel Vetter 60704feced9SVille Syrjälä if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK || 60804feced9SVille Syrjälä status_mask & ~PIPESTAT_INT_STATUS_MASK, 60904feced9SVille Syrjälä "pipe %c: enable_mask=0x%x, status_mask=0x%x\n", 61004feced9SVille Syrjälä pipe_name(pipe), enable_mask, status_mask)) 61146c06a30SVille Syrjälä return; 61246c06a30SVille Syrjälä 613755e9019SImre Deak if ((pipestat & enable_mask) == 0) 614755e9019SImre Deak return; 615755e9019SImre Deak 61691d181ddSImre Deak dev_priv->pipestat_irq_mask[pipe] &= ~status_mask; 61791d181ddSImre Deak 618755e9019SImre Deak pipestat &= ~enable_mask; 61946c06a30SVille Syrjälä I915_WRITE(reg, pipestat); 6203143a2bfSChris Wilson POSTING_READ(reg); 6217c463586SKeith Packard } 6227c463586SKeith Packard 62310c59c51SImre Deak static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask) 62410c59c51SImre Deak { 62510c59c51SImre Deak u32 enable_mask = status_mask << 16; 62610c59c51SImre Deak 62710c59c51SImre Deak /* 628724a6905SVille Syrjälä * On pipe A we don't support the PSR interrupt yet, 629724a6905SVille Syrjälä * on pipe B and C the same bit MBZ. 63010c59c51SImre Deak */ 63110c59c51SImre Deak if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV)) 63210c59c51SImre Deak return 0; 633724a6905SVille Syrjälä /* 634724a6905SVille Syrjälä * On pipe B and C we don't support the PSR interrupt yet, on pipe 635724a6905SVille Syrjälä * A the same bit is for perf counters which we don't use either. 636724a6905SVille Syrjälä */ 637724a6905SVille Syrjälä if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV)) 638724a6905SVille Syrjälä return 0; 63910c59c51SImre Deak 64010c59c51SImre Deak enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS | 64110c59c51SImre Deak SPRITE0_FLIP_DONE_INT_EN_VLV | 64210c59c51SImre Deak SPRITE1_FLIP_DONE_INT_EN_VLV); 64310c59c51SImre Deak if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV) 64410c59c51SImre Deak enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV; 64510c59c51SImre Deak if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV) 64610c59c51SImre Deak enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV; 64710c59c51SImre Deak 64810c59c51SImre Deak return enable_mask; 64910c59c51SImre Deak } 65010c59c51SImre Deak 651755e9019SImre Deak void 652755e9019SImre Deak i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 653755e9019SImre Deak u32 status_mask) 654755e9019SImre Deak { 655755e9019SImre Deak u32 enable_mask; 656755e9019SImre Deak 657666a4537SWayne Boyer if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) 65891c8a326SChris Wilson enable_mask = vlv_get_pipestat_enable_mask(&dev_priv->drm, 65910c59c51SImre Deak status_mask); 66010c59c51SImre Deak else 661755e9019SImre Deak enable_mask = status_mask << 16; 662755e9019SImre Deak __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask); 663755e9019SImre Deak } 664755e9019SImre Deak 665755e9019SImre Deak void 666755e9019SImre Deak i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 667755e9019SImre Deak u32 status_mask) 668755e9019SImre Deak { 669755e9019SImre Deak u32 enable_mask; 670755e9019SImre Deak 671666a4537SWayne Boyer if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) 67291c8a326SChris Wilson enable_mask = vlv_get_pipestat_enable_mask(&dev_priv->drm, 67310c59c51SImre Deak status_mask); 67410c59c51SImre Deak else 675755e9019SImre Deak enable_mask = status_mask << 16; 676755e9019SImre Deak __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask); 677755e9019SImre Deak } 678755e9019SImre Deak 679c0e09200SDave Airlie /** 680f49e38ddSJani Nikula * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion 68114bb2c11STvrtko Ursulin * @dev_priv: i915 device private 68201c66889SZhao Yakui */ 68391d14251STvrtko Ursulin static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv) 68401c66889SZhao Yakui { 68591d14251STvrtko Ursulin if (!dev_priv->opregion.asle || !IS_MOBILE(dev_priv)) 686f49e38ddSJani Nikula return; 687f49e38ddSJani Nikula 68813321786SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 68901c66889SZhao Yakui 690755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS); 69191d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 4) 6923b6c42e8SDaniel Vetter i915_enable_pipestat(dev_priv, PIPE_A, 693755e9019SImre Deak PIPE_LEGACY_BLC_EVENT_STATUS); 6941ec14ad3SChris Wilson 69513321786SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 69601c66889SZhao Yakui } 69701c66889SZhao Yakui 698f75f3746SVille Syrjälä /* 699f75f3746SVille Syrjälä * This timing diagram depicts the video signal in and 700f75f3746SVille Syrjälä * around the vertical blanking period. 701f75f3746SVille Syrjälä * 702f75f3746SVille Syrjälä * Assumptions about the fictitious mode used in this example: 703f75f3746SVille Syrjälä * vblank_start >= 3 704f75f3746SVille Syrjälä * vsync_start = vblank_start + 1 705f75f3746SVille Syrjälä * vsync_end = vblank_start + 2 706f75f3746SVille Syrjälä * vtotal = vblank_start + 3 707f75f3746SVille Syrjälä * 708f75f3746SVille Syrjälä * start of vblank: 709f75f3746SVille Syrjälä * latch double buffered registers 710f75f3746SVille Syrjälä * increment frame counter (ctg+) 711f75f3746SVille Syrjälä * generate start of vblank interrupt (gen4+) 712f75f3746SVille Syrjälä * | 713f75f3746SVille Syrjälä * | frame start: 714f75f3746SVille Syrjälä * | generate frame start interrupt (aka. vblank interrupt) (gmch) 715f75f3746SVille Syrjälä * | may be shifted forward 1-3 extra lines via PIPECONF 716f75f3746SVille Syrjälä * | | 717f75f3746SVille Syrjälä * | | start of vsync: 718f75f3746SVille Syrjälä * | | generate vsync interrupt 719f75f3746SVille Syrjälä * | | | 720f75f3746SVille Syrjälä * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx 721f75f3746SVille Syrjälä * . \hs/ . \hs/ \hs/ \hs/ . \hs/ 722f75f3746SVille Syrjälä * ----va---> <-----------------vb--------------------> <--------va------------- 723f75f3746SVille Syrjälä * | | <----vs-----> | 724f75f3746SVille Syrjälä * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2) 725f75f3746SVille Syrjälä * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+) 726f75f3746SVille Syrjälä * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi) 727f75f3746SVille Syrjälä * | | | 728f75f3746SVille Syrjälä * last visible pixel first visible pixel 729f75f3746SVille Syrjälä * | increment frame counter (gen3/4) 730f75f3746SVille Syrjälä * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4) 731f75f3746SVille Syrjälä * 732f75f3746SVille Syrjälä * x = horizontal active 733f75f3746SVille Syrjälä * _ = horizontal blanking 734f75f3746SVille Syrjälä * hs = horizontal sync 735f75f3746SVille Syrjälä * va = vertical active 736f75f3746SVille Syrjälä * vb = vertical blanking 737f75f3746SVille Syrjälä * vs = vertical sync 738f75f3746SVille Syrjälä * vbs = vblank_start (number) 739f75f3746SVille Syrjälä * 740f75f3746SVille Syrjälä * Summary: 741f75f3746SVille Syrjälä * - most events happen at the start of horizontal sync 742f75f3746SVille Syrjälä * - frame start happens at the start of horizontal blank, 1-4 lines 743f75f3746SVille Syrjälä * (depending on PIPECONF settings) after the start of vblank 744f75f3746SVille Syrjälä * - gen3/4 pixel and frame counter are synchronized with the start 745f75f3746SVille Syrjälä * of horizontal active on the first line of vertical active 746f75f3746SVille Syrjälä */ 747f75f3746SVille Syrjälä 74842f52ef8SKeith Packard /* Called from drm generic code, passed a 'crtc', which 74942f52ef8SKeith Packard * we use as a pipe index 75042f52ef8SKeith Packard */ 75188e72717SThierry Reding static u32 i915_get_vblank_counter(struct drm_device *dev, unsigned int pipe) 7520a3e67a4SJesse Barnes { 753fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 754f0f59a00SVille Syrjälä i915_reg_t high_frame, low_frame; 7550b2a8e09SVille Syrjälä u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal; 7565caa0feaSDaniel Vetter const struct drm_display_mode *mode = &dev->vblank[pipe].hwmode; 757694e409dSVille Syrjälä unsigned long irqflags; 758391f75e2SVille Syrjälä 7590b2a8e09SVille Syrjälä htotal = mode->crtc_htotal; 7600b2a8e09SVille Syrjälä hsync_start = mode->crtc_hsync_start; 7610b2a8e09SVille Syrjälä vbl_start = mode->crtc_vblank_start; 7620b2a8e09SVille Syrjälä if (mode->flags & DRM_MODE_FLAG_INTERLACE) 7630b2a8e09SVille Syrjälä vbl_start = DIV_ROUND_UP(vbl_start, 2); 764391f75e2SVille Syrjälä 7650b2a8e09SVille Syrjälä /* Convert to pixel count */ 7660b2a8e09SVille Syrjälä vbl_start *= htotal; 7670b2a8e09SVille Syrjälä 7680b2a8e09SVille Syrjälä /* Start of vblank event occurs at start of hsync */ 7690b2a8e09SVille Syrjälä vbl_start -= htotal - hsync_start; 7700b2a8e09SVille Syrjälä 7719db4a9c7SJesse Barnes high_frame = PIPEFRAME(pipe); 7729db4a9c7SJesse Barnes low_frame = PIPEFRAMEPIXEL(pipe); 7735eddb70bSChris Wilson 774694e409dSVille Syrjälä spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); 775694e409dSVille Syrjälä 7760a3e67a4SJesse Barnes /* 7770a3e67a4SJesse Barnes * High & low register fields aren't synchronized, so make sure 7780a3e67a4SJesse Barnes * we get a low value that's stable across two reads of the high 7790a3e67a4SJesse Barnes * register. 7800a3e67a4SJesse Barnes */ 7810a3e67a4SJesse Barnes do { 782694e409dSVille Syrjälä high1 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK; 783694e409dSVille Syrjälä low = I915_READ_FW(low_frame); 784694e409dSVille Syrjälä high2 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK; 7850a3e67a4SJesse Barnes } while (high1 != high2); 7860a3e67a4SJesse Barnes 787694e409dSVille Syrjälä spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); 788694e409dSVille Syrjälä 7895eddb70bSChris Wilson high1 >>= PIPE_FRAME_HIGH_SHIFT; 790391f75e2SVille Syrjälä pixel = low & PIPE_PIXEL_MASK; 7915eddb70bSChris Wilson low >>= PIPE_FRAME_LOW_SHIFT; 792391f75e2SVille Syrjälä 793391f75e2SVille Syrjälä /* 794391f75e2SVille Syrjälä * The frame counter increments at beginning of active. 795391f75e2SVille Syrjälä * Cook up a vblank counter by also checking the pixel 796391f75e2SVille Syrjälä * counter against vblank start. 797391f75e2SVille Syrjälä */ 798edc08d0aSVille Syrjälä return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff; 7990a3e67a4SJesse Barnes } 8000a3e67a4SJesse Barnes 801974e59baSDave Airlie static u32 g4x_get_vblank_counter(struct drm_device *dev, unsigned int pipe) 8029880b7a5SJesse Barnes { 803fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 8049880b7a5SJesse Barnes 805649636efSVille Syrjälä return I915_READ(PIPE_FRMCOUNT_G4X(pipe)); 8069880b7a5SJesse Barnes } 8079880b7a5SJesse Barnes 80875aa3f63SVille Syrjälä /* I915_READ_FW, only for fast reads of display block, no need for forcewake etc. */ 809a225f079SVille Syrjälä static int __intel_get_crtc_scanline(struct intel_crtc *crtc) 810a225f079SVille Syrjälä { 811a225f079SVille Syrjälä struct drm_device *dev = crtc->base.dev; 812fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 8135caa0feaSDaniel Vetter const struct drm_display_mode *mode; 8145caa0feaSDaniel Vetter struct drm_vblank_crtc *vblank; 815a225f079SVille Syrjälä enum pipe pipe = crtc->pipe; 81680715b2fSVille Syrjälä int position, vtotal; 817a225f079SVille Syrjälä 81872259536SVille Syrjälä if (!crtc->active) 81972259536SVille Syrjälä return -1; 82072259536SVille Syrjälä 8215caa0feaSDaniel Vetter vblank = &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)]; 8225caa0feaSDaniel Vetter mode = &vblank->hwmode; 8235caa0feaSDaniel Vetter 82480715b2fSVille Syrjälä vtotal = mode->crtc_vtotal; 825a225f079SVille Syrjälä if (mode->flags & DRM_MODE_FLAG_INTERLACE) 826a225f079SVille Syrjälä vtotal /= 2; 827a225f079SVille Syrjälä 82891d14251STvrtko Ursulin if (IS_GEN2(dev_priv)) 82975aa3f63SVille Syrjälä position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2; 830a225f079SVille Syrjälä else 83175aa3f63SVille Syrjälä position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3; 832a225f079SVille Syrjälä 833a225f079SVille Syrjälä /* 83441b578fbSJesse Barnes * On HSW, the DSL reg (0x70000) appears to return 0 if we 83541b578fbSJesse Barnes * read it just before the start of vblank. So try it again 83641b578fbSJesse Barnes * so we don't accidentally end up spanning a vblank frame 83741b578fbSJesse Barnes * increment, causing the pipe_update_end() code to squak at us. 83841b578fbSJesse Barnes * 83941b578fbSJesse Barnes * The nature of this problem means we can't simply check the ISR 84041b578fbSJesse Barnes * bit and return the vblank start value; nor can we use the scanline 84141b578fbSJesse Barnes * debug register in the transcoder as it appears to have the same 84241b578fbSJesse Barnes * problem. We may need to extend this to include other platforms, 84341b578fbSJesse Barnes * but so far testing only shows the problem on HSW. 84441b578fbSJesse Barnes */ 84591d14251STvrtko Ursulin if (HAS_DDI(dev_priv) && !position) { 84641b578fbSJesse Barnes int i, temp; 84741b578fbSJesse Barnes 84841b578fbSJesse Barnes for (i = 0; i < 100; i++) { 84941b578fbSJesse Barnes udelay(1); 850707bdd3fSVille Syrjälä temp = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3; 85141b578fbSJesse Barnes if (temp != position) { 85241b578fbSJesse Barnes position = temp; 85341b578fbSJesse Barnes break; 85441b578fbSJesse Barnes } 85541b578fbSJesse Barnes } 85641b578fbSJesse Barnes } 85741b578fbSJesse Barnes 85841b578fbSJesse Barnes /* 85980715b2fSVille Syrjälä * See update_scanline_offset() for the details on the 86080715b2fSVille Syrjälä * scanline_offset adjustment. 861a225f079SVille Syrjälä */ 86280715b2fSVille Syrjälä return (position + crtc->scanline_offset) % vtotal; 863a225f079SVille Syrjälä } 864a225f079SVille Syrjälä 8651bf6ad62SDaniel Vetter static bool i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe, 8661bf6ad62SDaniel Vetter bool in_vblank_irq, int *vpos, int *hpos, 8673bb403bfSVille Syrjälä ktime_t *stime, ktime_t *etime, 8683bb403bfSVille Syrjälä const struct drm_display_mode *mode) 8690af7e4dfSMario Kleiner { 870fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 87198187836SVille Syrjälä struct intel_crtc *intel_crtc = intel_get_crtc_for_pipe(dev_priv, 87298187836SVille Syrjälä pipe); 8733aa18df8SVille Syrjälä int position; 87478e8fc6bSVille Syrjälä int vbl_start, vbl_end, hsync_start, htotal, vtotal; 875ad3543edSMario Kleiner unsigned long irqflags; 8760af7e4dfSMario Kleiner 877fc467a22SMaarten Lankhorst if (WARN_ON(!mode->crtc_clock)) { 8780af7e4dfSMario Kleiner DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled " 8799db4a9c7SJesse Barnes "pipe %c\n", pipe_name(pipe)); 8801bf6ad62SDaniel Vetter return false; 8810af7e4dfSMario Kleiner } 8820af7e4dfSMario Kleiner 883c2baf4b7SVille Syrjälä htotal = mode->crtc_htotal; 88478e8fc6bSVille Syrjälä hsync_start = mode->crtc_hsync_start; 885c2baf4b7SVille Syrjälä vtotal = mode->crtc_vtotal; 886c2baf4b7SVille Syrjälä vbl_start = mode->crtc_vblank_start; 887c2baf4b7SVille Syrjälä vbl_end = mode->crtc_vblank_end; 8880af7e4dfSMario Kleiner 889d31faf65SVille Syrjälä if (mode->flags & DRM_MODE_FLAG_INTERLACE) { 890d31faf65SVille Syrjälä vbl_start = DIV_ROUND_UP(vbl_start, 2); 891d31faf65SVille Syrjälä vbl_end /= 2; 892d31faf65SVille Syrjälä vtotal /= 2; 893d31faf65SVille Syrjälä } 894d31faf65SVille Syrjälä 895ad3543edSMario Kleiner /* 896ad3543edSMario Kleiner * Lock uncore.lock, as we will do multiple timing critical raw 897ad3543edSMario Kleiner * register reads, potentially with preemption disabled, so the 898ad3543edSMario Kleiner * following code must not block on uncore.lock. 899ad3543edSMario Kleiner */ 900ad3543edSMario Kleiner spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); 901ad3543edSMario Kleiner 902ad3543edSMario Kleiner /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */ 903ad3543edSMario Kleiner 904ad3543edSMario Kleiner /* Get optional system timestamp before query. */ 905ad3543edSMario Kleiner if (stime) 906ad3543edSMario Kleiner *stime = ktime_get(); 907ad3543edSMario Kleiner 90891d14251STvrtko Ursulin if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) { 9090af7e4dfSMario Kleiner /* No obvious pixelcount register. Only query vertical 9100af7e4dfSMario Kleiner * scanout position from Display scan line register. 9110af7e4dfSMario Kleiner */ 912a225f079SVille Syrjälä position = __intel_get_crtc_scanline(intel_crtc); 9130af7e4dfSMario Kleiner } else { 9140af7e4dfSMario Kleiner /* Have access to pixelcount since start of frame. 9150af7e4dfSMario Kleiner * We can split this into vertical and horizontal 9160af7e4dfSMario Kleiner * scanout position. 9170af7e4dfSMario Kleiner */ 91875aa3f63SVille Syrjälä position = (I915_READ_FW(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT; 9190af7e4dfSMario Kleiner 9203aa18df8SVille Syrjälä /* convert to pixel counts */ 9213aa18df8SVille Syrjälä vbl_start *= htotal; 9223aa18df8SVille Syrjälä vbl_end *= htotal; 9233aa18df8SVille Syrjälä vtotal *= htotal; 92478e8fc6bSVille Syrjälä 92578e8fc6bSVille Syrjälä /* 9267e78f1cbSVille Syrjälä * In interlaced modes, the pixel counter counts all pixels, 9277e78f1cbSVille Syrjälä * so one field will have htotal more pixels. In order to avoid 9287e78f1cbSVille Syrjälä * the reported position from jumping backwards when the pixel 9297e78f1cbSVille Syrjälä * counter is beyond the length of the shorter field, just 9307e78f1cbSVille Syrjälä * clamp the position the length of the shorter field. This 9317e78f1cbSVille Syrjälä * matches how the scanline counter based position works since 9327e78f1cbSVille Syrjälä * the scanline counter doesn't count the two half lines. 9337e78f1cbSVille Syrjälä */ 9347e78f1cbSVille Syrjälä if (position >= vtotal) 9357e78f1cbSVille Syrjälä position = vtotal - 1; 9367e78f1cbSVille Syrjälä 9377e78f1cbSVille Syrjälä /* 93878e8fc6bSVille Syrjälä * Start of vblank interrupt is triggered at start of hsync, 93978e8fc6bSVille Syrjälä * just prior to the first active line of vblank. However we 94078e8fc6bSVille Syrjälä * consider lines to start at the leading edge of horizontal 94178e8fc6bSVille Syrjälä * active. So, should we get here before we've crossed into 94278e8fc6bSVille Syrjälä * the horizontal active of the first line in vblank, we would 94378e8fc6bSVille Syrjälä * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that, 94478e8fc6bSVille Syrjälä * always add htotal-hsync_start to the current pixel position. 94578e8fc6bSVille Syrjälä */ 94678e8fc6bSVille Syrjälä position = (position + htotal - hsync_start) % vtotal; 9473aa18df8SVille Syrjälä } 9483aa18df8SVille Syrjälä 949ad3543edSMario Kleiner /* Get optional system timestamp after query. */ 950ad3543edSMario Kleiner if (etime) 951ad3543edSMario Kleiner *etime = ktime_get(); 952ad3543edSMario Kleiner 953ad3543edSMario Kleiner /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */ 954ad3543edSMario Kleiner 955ad3543edSMario Kleiner spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); 956ad3543edSMario Kleiner 9573aa18df8SVille Syrjälä /* 9583aa18df8SVille Syrjälä * While in vblank, position will be negative 9593aa18df8SVille Syrjälä * counting up towards 0 at vbl_end. And outside 9603aa18df8SVille Syrjälä * vblank, position will be positive counting 9613aa18df8SVille Syrjälä * up since vbl_end. 9623aa18df8SVille Syrjälä */ 9633aa18df8SVille Syrjälä if (position >= vbl_start) 9643aa18df8SVille Syrjälä position -= vbl_end; 9653aa18df8SVille Syrjälä else 9663aa18df8SVille Syrjälä position += vtotal - vbl_end; 9673aa18df8SVille Syrjälä 96891d14251STvrtko Ursulin if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) { 9693aa18df8SVille Syrjälä *vpos = position; 9703aa18df8SVille Syrjälä *hpos = 0; 9713aa18df8SVille Syrjälä } else { 9720af7e4dfSMario Kleiner *vpos = position / htotal; 9730af7e4dfSMario Kleiner *hpos = position - (*vpos * htotal); 9740af7e4dfSMario Kleiner } 9750af7e4dfSMario Kleiner 9761bf6ad62SDaniel Vetter return true; 9770af7e4dfSMario Kleiner } 9780af7e4dfSMario Kleiner 979a225f079SVille Syrjälä int intel_get_crtc_scanline(struct intel_crtc *crtc) 980a225f079SVille Syrjälä { 981fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 982a225f079SVille Syrjälä unsigned long irqflags; 983a225f079SVille Syrjälä int position; 984a225f079SVille Syrjälä 985a225f079SVille Syrjälä spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); 986a225f079SVille Syrjälä position = __intel_get_crtc_scanline(crtc); 987a225f079SVille Syrjälä spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); 988a225f079SVille Syrjälä 989a225f079SVille Syrjälä return position; 990a225f079SVille Syrjälä } 991a225f079SVille Syrjälä 99291d14251STvrtko Ursulin static void ironlake_rps_change_irq_handler(struct drm_i915_private *dev_priv) 993f97108d1SJesse Barnes { 994b5b72e89SMatthew Garrett u32 busy_up, busy_down, max_avg, min_avg; 9959270388eSDaniel Vetter u8 new_delay; 9969270388eSDaniel Vetter 997d0ecd7e2SDaniel Vetter spin_lock(&mchdev_lock); 998f97108d1SJesse Barnes 99973edd18fSDaniel Vetter I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS)); 100073edd18fSDaniel Vetter 100120e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay; 10029270388eSDaniel Vetter 10037648fa99SJesse Barnes I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG); 1004b5b72e89SMatthew Garrett busy_up = I915_READ(RCPREVBSYTUPAVG); 1005b5b72e89SMatthew Garrett busy_down = I915_READ(RCPREVBSYTDNAVG); 1006f97108d1SJesse Barnes max_avg = I915_READ(RCBMAXAVG); 1007f97108d1SJesse Barnes min_avg = I915_READ(RCBMINAVG); 1008f97108d1SJesse Barnes 1009f97108d1SJesse Barnes /* Handle RCS change request from hw */ 1010b5b72e89SMatthew Garrett if (busy_up > max_avg) { 101120e4d407SDaniel Vetter if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay) 101220e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay - 1; 101320e4d407SDaniel Vetter if (new_delay < dev_priv->ips.max_delay) 101420e4d407SDaniel Vetter new_delay = dev_priv->ips.max_delay; 1015b5b72e89SMatthew Garrett } else if (busy_down < min_avg) { 101620e4d407SDaniel Vetter if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay) 101720e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay + 1; 101820e4d407SDaniel Vetter if (new_delay > dev_priv->ips.min_delay) 101920e4d407SDaniel Vetter new_delay = dev_priv->ips.min_delay; 1020f97108d1SJesse Barnes } 1021f97108d1SJesse Barnes 102291d14251STvrtko Ursulin if (ironlake_set_drps(dev_priv, new_delay)) 102320e4d407SDaniel Vetter dev_priv->ips.cur_delay = new_delay; 1024f97108d1SJesse Barnes 1025d0ecd7e2SDaniel Vetter spin_unlock(&mchdev_lock); 10269270388eSDaniel Vetter 1027f97108d1SJesse Barnes return; 1028f97108d1SJesse Barnes } 1029f97108d1SJesse Barnes 10300bc40be8STvrtko Ursulin static void notify_ring(struct intel_engine_cs *engine) 1031549f7365SChris Wilson { 103256299fb7SChris Wilson struct drm_i915_gem_request *rq = NULL; 103356299fb7SChris Wilson struct intel_wait *wait; 1034dffabc8fSTvrtko Ursulin 10352246bea6SChris Wilson atomic_inc(&engine->irq_count); 1036538b257dSChris Wilson set_bit(ENGINE_IRQ_BREADCRUMB, &engine->irq_posted); 103756299fb7SChris Wilson 103861d3dc70SChris Wilson spin_lock(&engine->breadcrumbs.irq_lock); 103961d3dc70SChris Wilson wait = engine->breadcrumbs.irq_wait; 104056299fb7SChris Wilson if (wait) { 104156299fb7SChris Wilson /* We use a callback from the dma-fence to submit 104256299fb7SChris Wilson * requests after waiting on our own requests. To 104356299fb7SChris Wilson * ensure minimum delay in queuing the next request to 104456299fb7SChris Wilson * hardware, signal the fence now rather than wait for 104556299fb7SChris Wilson * the signaler to be woken up. We still wake up the 104656299fb7SChris Wilson * waiter in order to handle the irq-seqno coherency 104756299fb7SChris Wilson * issues (we may receive the interrupt before the 104856299fb7SChris Wilson * seqno is written, see __i915_request_irq_complete()) 104956299fb7SChris Wilson * and to handle coalescing of multiple seqno updates 105056299fb7SChris Wilson * and many waiters. 105156299fb7SChris Wilson */ 105256299fb7SChris Wilson if (i915_seqno_passed(intel_engine_get_seqno(engine), 1053db93991bSChris Wilson wait->seqno) && 1054db93991bSChris Wilson !test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, 1055db93991bSChris Wilson &wait->request->fence.flags)) 105624754d75SChris Wilson rq = i915_gem_request_get(wait->request); 105756299fb7SChris Wilson 105856299fb7SChris Wilson wake_up_process(wait->tsk); 105967b807a8SChris Wilson } else { 106067b807a8SChris Wilson __intel_engine_disarm_breadcrumbs(engine); 106156299fb7SChris Wilson } 106261d3dc70SChris Wilson spin_unlock(&engine->breadcrumbs.irq_lock); 106356299fb7SChris Wilson 106424754d75SChris Wilson if (rq) { 106556299fb7SChris Wilson dma_fence_signal(&rq->fence); 106624754d75SChris Wilson i915_gem_request_put(rq); 106724754d75SChris Wilson } 106856299fb7SChris Wilson 106956299fb7SChris Wilson trace_intel_engine_notify(engine, wait); 1070549f7365SChris Wilson } 1071549f7365SChris Wilson 107243cf3bf0SChris Wilson static void vlv_c0_read(struct drm_i915_private *dev_priv, 107343cf3bf0SChris Wilson struct intel_rps_ei *ei) 107431685c25SDeepak S { 1075679cb6c1SMika Kuoppala ei->ktime = ktime_get_raw(); 107643cf3bf0SChris Wilson ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT); 107743cf3bf0SChris Wilson ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT); 107831685c25SDeepak S } 107931685c25SDeepak S 108043cf3bf0SChris Wilson void gen6_rps_reset_ei(struct drm_i915_private *dev_priv) 108143cf3bf0SChris Wilson { 1082e0e8c7cbSChris Wilson memset(&dev_priv->rps.ei, 0, sizeof(dev_priv->rps.ei)); 108343cf3bf0SChris Wilson } 108443cf3bf0SChris Wilson 108543cf3bf0SChris Wilson static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir) 108643cf3bf0SChris Wilson { 1087e0e8c7cbSChris Wilson const struct intel_rps_ei *prev = &dev_priv->rps.ei; 108843cf3bf0SChris Wilson struct intel_rps_ei now; 108943cf3bf0SChris Wilson u32 events = 0; 109043cf3bf0SChris Wilson 1091e0e8c7cbSChris Wilson if ((pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) == 0) 109243cf3bf0SChris Wilson return 0; 109343cf3bf0SChris Wilson 109443cf3bf0SChris Wilson vlv_c0_read(dev_priv, &now); 109531685c25SDeepak S 1096679cb6c1SMika Kuoppala if (prev->ktime) { 1097e0e8c7cbSChris Wilson u64 time, c0; 1098569884e3SChris Wilson u32 render, media; 1099e0e8c7cbSChris Wilson 1100679cb6c1SMika Kuoppala time = ktime_us_delta(now.ktime, prev->ktime); 11018f68d591SChris Wilson 1102e0e8c7cbSChris Wilson time *= dev_priv->czclk_freq; 1103e0e8c7cbSChris Wilson 1104e0e8c7cbSChris Wilson /* Workload can be split between render + media, 1105e0e8c7cbSChris Wilson * e.g. SwapBuffers being blitted in X after being rendered in 1106e0e8c7cbSChris Wilson * mesa. To account for this we need to combine both engines 1107e0e8c7cbSChris Wilson * into our activity counter. 1108e0e8c7cbSChris Wilson */ 1109569884e3SChris Wilson render = now.render_c0 - prev->render_c0; 1110569884e3SChris Wilson media = now.media_c0 - prev->media_c0; 1111569884e3SChris Wilson c0 = max(render, media); 11126b7f6aa7SMika Kuoppala c0 *= 1000 * 100 << 8; /* to usecs and scale to threshold% */ 1113e0e8c7cbSChris Wilson 1114e0e8c7cbSChris Wilson if (c0 > time * dev_priv->rps.up_threshold) 1115e0e8c7cbSChris Wilson events = GEN6_PM_RP_UP_THRESHOLD; 1116e0e8c7cbSChris Wilson else if (c0 < time * dev_priv->rps.down_threshold) 1117e0e8c7cbSChris Wilson events = GEN6_PM_RP_DOWN_THRESHOLD; 111831685c25SDeepak S } 111931685c25SDeepak S 1120e0e8c7cbSChris Wilson dev_priv->rps.ei = now; 112143cf3bf0SChris Wilson return events; 112231685c25SDeepak S } 112331685c25SDeepak S 11244912d041SBen Widawsky static void gen6_pm_rps_work(struct work_struct *work) 11253b8d8d91SJesse Barnes { 11262d1013ddSJani Nikula struct drm_i915_private *dev_priv = 11272d1013ddSJani Nikula container_of(work, struct drm_i915_private, rps.work); 11287c0a16adSChris Wilson bool client_boost = false; 11298d3afd7dSChris Wilson int new_delay, adj, min, max; 11307c0a16adSChris Wilson u32 pm_iir = 0; 11313b8d8d91SJesse Barnes 113259cdb63dSDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 11337c0a16adSChris Wilson if (dev_priv->rps.interrupts_enabled) { 11347c0a16adSChris Wilson pm_iir = fetch_and_zero(&dev_priv->rps.pm_iir); 11357b92c1bdSChris Wilson client_boost = atomic_read(&dev_priv->rps.num_waiters); 1136d4d70aa5SImre Deak } 113759cdb63dSDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 11384912d041SBen Widawsky 113960611c13SPaulo Zanoni /* Make sure we didn't queue anything we're not going to process. */ 1140a6706b45SDeepak S WARN_ON(pm_iir & ~dev_priv->pm_rps_events); 11418d3afd7dSChris Wilson if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost) 11427c0a16adSChris Wilson goto out; 11433b8d8d91SJesse Barnes 11444fc688ceSJesse Barnes mutex_lock(&dev_priv->rps.hw_lock); 11457b9e0ae6SChris Wilson 114643cf3bf0SChris Wilson pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir); 114743cf3bf0SChris Wilson 1148dd75fdc8SChris Wilson adj = dev_priv->rps.last_adj; 1149edcf284bSChris Wilson new_delay = dev_priv->rps.cur_freq; 11508d3afd7dSChris Wilson min = dev_priv->rps.min_freq_softlimit; 11518d3afd7dSChris Wilson max = dev_priv->rps.max_freq_softlimit; 11527b92c1bdSChris Wilson if (client_boost) 115329ecd78dSChris Wilson max = dev_priv->rps.max_freq; 115429ecd78dSChris Wilson if (client_boost && new_delay < dev_priv->rps.boost_freq) { 115529ecd78dSChris Wilson new_delay = dev_priv->rps.boost_freq; 11568d3afd7dSChris Wilson adj = 0; 11578d3afd7dSChris Wilson } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) { 1158dd75fdc8SChris Wilson if (adj > 0) 1159dd75fdc8SChris Wilson adj *= 2; 1160edcf284bSChris Wilson else /* CHV needs even encode values */ 1161edcf284bSChris Wilson adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1; 11627e79a683SSagar Arun Kamble 11637e79a683SSagar Arun Kamble if (new_delay >= dev_priv->rps.max_freq_softlimit) 11647e79a683SSagar Arun Kamble adj = 0; 11657b92c1bdSChris Wilson } else if (client_boost) { 1166f5a4c67dSChris Wilson adj = 0; 1167dd75fdc8SChris Wilson } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) { 1168b39fb297SBen Widawsky if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq) 1169b39fb297SBen Widawsky new_delay = dev_priv->rps.efficient_freq; 117017136d54SChris Wilson else if (dev_priv->rps.cur_freq > dev_priv->rps.min_freq_softlimit) 1171b39fb297SBen Widawsky new_delay = dev_priv->rps.min_freq_softlimit; 1172dd75fdc8SChris Wilson adj = 0; 1173dd75fdc8SChris Wilson } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) { 1174dd75fdc8SChris Wilson if (adj < 0) 1175dd75fdc8SChris Wilson adj *= 2; 1176edcf284bSChris Wilson else /* CHV needs even encode values */ 1177edcf284bSChris Wilson adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1; 11787e79a683SSagar Arun Kamble 11797e79a683SSagar Arun Kamble if (new_delay <= dev_priv->rps.min_freq_softlimit) 11807e79a683SSagar Arun Kamble adj = 0; 1181dd75fdc8SChris Wilson } else { /* unknown event */ 1182edcf284bSChris Wilson adj = 0; 1183dd75fdc8SChris Wilson } 11843b8d8d91SJesse Barnes 1185edcf284bSChris Wilson dev_priv->rps.last_adj = adj; 1186edcf284bSChris Wilson 118779249636SBen Widawsky /* sysfs frequency interfaces may have snuck in while servicing the 118879249636SBen Widawsky * interrupt 118979249636SBen Widawsky */ 1190edcf284bSChris Wilson new_delay += adj; 11918d3afd7dSChris Wilson new_delay = clamp_t(int, new_delay, min, max); 119227544369SDeepak S 11939fcee2f7SChris Wilson if (intel_set_rps(dev_priv, new_delay)) { 11949fcee2f7SChris Wilson DRM_DEBUG_DRIVER("Failed to set new GPU frequency\n"); 11959fcee2f7SChris Wilson dev_priv->rps.last_adj = 0; 11969fcee2f7SChris Wilson } 11973b8d8d91SJesse Barnes 11984fc688ceSJesse Barnes mutex_unlock(&dev_priv->rps.hw_lock); 11997c0a16adSChris Wilson 12007c0a16adSChris Wilson out: 12017c0a16adSChris Wilson /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */ 12027c0a16adSChris Wilson spin_lock_irq(&dev_priv->irq_lock); 12037c0a16adSChris Wilson if (dev_priv->rps.interrupts_enabled) 12047c0a16adSChris Wilson gen6_unmask_pm_irq(dev_priv, dev_priv->pm_rps_events); 12057c0a16adSChris Wilson spin_unlock_irq(&dev_priv->irq_lock); 12063b8d8d91SJesse Barnes } 12073b8d8d91SJesse Barnes 1208e3689190SBen Widawsky 1209e3689190SBen Widawsky /** 1210e3689190SBen Widawsky * ivybridge_parity_work - Workqueue called when a parity error interrupt 1211e3689190SBen Widawsky * occurred. 1212e3689190SBen Widawsky * @work: workqueue struct 1213e3689190SBen Widawsky * 1214e3689190SBen Widawsky * Doesn't actually do anything except notify userspace. As a consequence of 1215e3689190SBen Widawsky * this event, userspace should try to remap the bad rows since statistically 1216e3689190SBen Widawsky * it is likely the same row is more likely to go bad again. 1217e3689190SBen Widawsky */ 1218e3689190SBen Widawsky static void ivybridge_parity_work(struct work_struct *work) 1219e3689190SBen Widawsky { 12202d1013ddSJani Nikula struct drm_i915_private *dev_priv = 1221cefcff8fSJoonas Lahtinen container_of(work, typeof(*dev_priv), l3_parity.error_work); 1222e3689190SBen Widawsky u32 error_status, row, bank, subbank; 122335a85ac6SBen Widawsky char *parity_event[6]; 1224e3689190SBen Widawsky uint32_t misccpctl; 122535a85ac6SBen Widawsky uint8_t slice = 0; 1226e3689190SBen Widawsky 1227e3689190SBen Widawsky /* We must turn off DOP level clock gating to access the L3 registers. 1228e3689190SBen Widawsky * In order to prevent a get/put style interface, acquire struct mutex 1229e3689190SBen Widawsky * any time we access those registers. 1230e3689190SBen Widawsky */ 123191c8a326SChris Wilson mutex_lock(&dev_priv->drm.struct_mutex); 1232e3689190SBen Widawsky 123335a85ac6SBen Widawsky /* If we've screwed up tracking, just let the interrupt fire again */ 123435a85ac6SBen Widawsky if (WARN_ON(!dev_priv->l3_parity.which_slice)) 123535a85ac6SBen Widawsky goto out; 123635a85ac6SBen Widawsky 1237e3689190SBen Widawsky misccpctl = I915_READ(GEN7_MISCCPCTL); 1238e3689190SBen Widawsky I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); 1239e3689190SBen Widawsky POSTING_READ(GEN7_MISCCPCTL); 1240e3689190SBen Widawsky 124135a85ac6SBen Widawsky while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) { 1242f0f59a00SVille Syrjälä i915_reg_t reg; 124335a85ac6SBen Widawsky 124435a85ac6SBen Widawsky slice--; 12452d1fe073SJoonas Lahtinen if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv))) 124635a85ac6SBen Widawsky break; 124735a85ac6SBen Widawsky 124835a85ac6SBen Widawsky dev_priv->l3_parity.which_slice &= ~(1<<slice); 124935a85ac6SBen Widawsky 12506fa1c5f1SVille Syrjälä reg = GEN7_L3CDERRST1(slice); 125135a85ac6SBen Widawsky 125235a85ac6SBen Widawsky error_status = I915_READ(reg); 1253e3689190SBen Widawsky row = GEN7_PARITY_ERROR_ROW(error_status); 1254e3689190SBen Widawsky bank = GEN7_PARITY_ERROR_BANK(error_status); 1255e3689190SBen Widawsky subbank = GEN7_PARITY_ERROR_SUBBANK(error_status); 1256e3689190SBen Widawsky 125735a85ac6SBen Widawsky I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE); 125835a85ac6SBen Widawsky POSTING_READ(reg); 1259e3689190SBen Widawsky 1260cce723edSBen Widawsky parity_event[0] = I915_L3_PARITY_UEVENT "=1"; 1261e3689190SBen Widawsky parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row); 1262e3689190SBen Widawsky parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank); 1263e3689190SBen Widawsky parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank); 126435a85ac6SBen Widawsky parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice); 126535a85ac6SBen Widawsky parity_event[5] = NULL; 1266e3689190SBen Widawsky 126791c8a326SChris Wilson kobject_uevent_env(&dev_priv->drm.primary->kdev->kobj, 1268e3689190SBen Widawsky KOBJ_CHANGE, parity_event); 1269e3689190SBen Widawsky 127035a85ac6SBen Widawsky DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n", 127135a85ac6SBen Widawsky slice, row, bank, subbank); 1272e3689190SBen Widawsky 127335a85ac6SBen Widawsky kfree(parity_event[4]); 1274e3689190SBen Widawsky kfree(parity_event[3]); 1275e3689190SBen Widawsky kfree(parity_event[2]); 1276e3689190SBen Widawsky kfree(parity_event[1]); 1277e3689190SBen Widawsky } 1278e3689190SBen Widawsky 127935a85ac6SBen Widawsky I915_WRITE(GEN7_MISCCPCTL, misccpctl); 128035a85ac6SBen Widawsky 128135a85ac6SBen Widawsky out: 128235a85ac6SBen Widawsky WARN_ON(dev_priv->l3_parity.which_slice); 12834cb21832SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 12842d1fe073SJoonas Lahtinen gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv)); 12854cb21832SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 128635a85ac6SBen Widawsky 128791c8a326SChris Wilson mutex_unlock(&dev_priv->drm.struct_mutex); 128835a85ac6SBen Widawsky } 128935a85ac6SBen Widawsky 1290261e40b8SVille Syrjälä static void ivybridge_parity_error_irq_handler(struct drm_i915_private *dev_priv, 1291261e40b8SVille Syrjälä u32 iir) 1292e3689190SBen Widawsky { 1293261e40b8SVille Syrjälä if (!HAS_L3_DPF(dev_priv)) 1294e3689190SBen Widawsky return; 1295e3689190SBen Widawsky 1296d0ecd7e2SDaniel Vetter spin_lock(&dev_priv->irq_lock); 1297261e40b8SVille Syrjälä gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv)); 1298d0ecd7e2SDaniel Vetter spin_unlock(&dev_priv->irq_lock); 1299e3689190SBen Widawsky 1300261e40b8SVille Syrjälä iir &= GT_PARITY_ERROR(dev_priv); 130135a85ac6SBen Widawsky if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1) 130235a85ac6SBen Widawsky dev_priv->l3_parity.which_slice |= 1 << 1; 130335a85ac6SBen Widawsky 130435a85ac6SBen Widawsky if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT) 130535a85ac6SBen Widawsky dev_priv->l3_parity.which_slice |= 1 << 0; 130635a85ac6SBen Widawsky 1307a4da4fa4SDaniel Vetter queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work); 1308e3689190SBen Widawsky } 1309e3689190SBen Widawsky 1310261e40b8SVille Syrjälä static void ilk_gt_irq_handler(struct drm_i915_private *dev_priv, 1311f1af8fc1SPaulo Zanoni u32 gt_iir) 1312f1af8fc1SPaulo Zanoni { 1313f8973c21SChris Wilson if (gt_iir & GT_RENDER_USER_INTERRUPT) 13143b3f1650SAkash Goel notify_ring(dev_priv->engine[RCS]); 1315f1af8fc1SPaulo Zanoni if (gt_iir & ILK_BSD_USER_INTERRUPT) 13163b3f1650SAkash Goel notify_ring(dev_priv->engine[VCS]); 1317f1af8fc1SPaulo Zanoni } 1318f1af8fc1SPaulo Zanoni 1319261e40b8SVille Syrjälä static void snb_gt_irq_handler(struct drm_i915_private *dev_priv, 1320e7b4c6b1SDaniel Vetter u32 gt_iir) 1321e7b4c6b1SDaniel Vetter { 1322f8973c21SChris Wilson if (gt_iir & GT_RENDER_USER_INTERRUPT) 13233b3f1650SAkash Goel notify_ring(dev_priv->engine[RCS]); 1324cc609d5dSBen Widawsky if (gt_iir & GT_BSD_USER_INTERRUPT) 13253b3f1650SAkash Goel notify_ring(dev_priv->engine[VCS]); 1326cc609d5dSBen Widawsky if (gt_iir & GT_BLT_USER_INTERRUPT) 13273b3f1650SAkash Goel notify_ring(dev_priv->engine[BCS]); 1328e7b4c6b1SDaniel Vetter 1329cc609d5dSBen Widawsky if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT | 1330cc609d5dSBen Widawsky GT_BSD_CS_ERROR_INTERRUPT | 1331aaecdf61SDaniel Vetter GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) 1332aaecdf61SDaniel Vetter DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir); 1333e3689190SBen Widawsky 1334261e40b8SVille Syrjälä if (gt_iir & GT_PARITY_ERROR(dev_priv)) 1335261e40b8SVille Syrjälä ivybridge_parity_error_irq_handler(dev_priv, gt_iir); 1336e7b4c6b1SDaniel Vetter } 1337e7b4c6b1SDaniel Vetter 13385d3d69d5SChris Wilson static void 13390bc40be8STvrtko Ursulin gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir, int test_shift) 1340fbcc1a0cSNick Hoath { 134131de7350SChris Wilson bool tasklet = false; 1342f747026cSChris Wilson 1343f747026cSChris Wilson if (iir & (GT_CONTEXT_SWITCH_INTERRUPT << test_shift)) { 1344a4b2b015SChris Wilson if (port_count(&engine->execlist_port[0])) { 1345955a4b89SChris Wilson __set_bit(ENGINE_IRQ_EXECLIST, &engine->irq_posted); 134631de7350SChris Wilson tasklet = true; 1347f747026cSChris Wilson } 1348a4b2b015SChris Wilson } 134931de7350SChris Wilson 135031de7350SChris Wilson if (iir & (GT_RENDER_USER_INTERRUPT << test_shift)) { 135131de7350SChris Wilson notify_ring(engine); 135231de7350SChris Wilson tasklet |= i915.enable_guc_submission; 135331de7350SChris Wilson } 135431de7350SChris Wilson 135531de7350SChris Wilson if (tasklet) 135631de7350SChris Wilson tasklet_hi_schedule(&engine->irq_tasklet); 1357fbcc1a0cSNick Hoath } 1358fbcc1a0cSNick Hoath 1359e30e251aSVille Syrjälä static irqreturn_t gen8_gt_irq_ack(struct drm_i915_private *dev_priv, 1360e30e251aSVille Syrjälä u32 master_ctl, 1361e30e251aSVille Syrjälä u32 gt_iir[4]) 1362abd58f01SBen Widawsky { 1363abd58f01SBen Widawsky irqreturn_t ret = IRQ_NONE; 1364abd58f01SBen Widawsky 1365abd58f01SBen Widawsky if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) { 1366e30e251aSVille Syrjälä gt_iir[0] = I915_READ_FW(GEN8_GT_IIR(0)); 1367e30e251aSVille Syrjälä if (gt_iir[0]) { 1368e30e251aSVille Syrjälä I915_WRITE_FW(GEN8_GT_IIR(0), gt_iir[0]); 1369abd58f01SBen Widawsky ret = IRQ_HANDLED; 1370abd58f01SBen Widawsky } else 1371abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (GT0)!\n"); 1372abd58f01SBen Widawsky } 1373abd58f01SBen Widawsky 137485f9b5f9SZhao Yakui if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) { 1375e30e251aSVille Syrjälä gt_iir[1] = I915_READ_FW(GEN8_GT_IIR(1)); 1376e30e251aSVille Syrjälä if (gt_iir[1]) { 1377e30e251aSVille Syrjälä I915_WRITE_FW(GEN8_GT_IIR(1), gt_iir[1]); 1378abd58f01SBen Widawsky ret = IRQ_HANDLED; 1379abd58f01SBen Widawsky } else 1380abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (GT1)!\n"); 1381abd58f01SBen Widawsky } 1382abd58f01SBen Widawsky 138374cdb337SChris Wilson if (master_ctl & GEN8_GT_VECS_IRQ) { 1384e30e251aSVille Syrjälä gt_iir[3] = I915_READ_FW(GEN8_GT_IIR(3)); 1385e30e251aSVille Syrjälä if (gt_iir[3]) { 1386e30e251aSVille Syrjälä I915_WRITE_FW(GEN8_GT_IIR(3), gt_iir[3]); 138774cdb337SChris Wilson ret = IRQ_HANDLED; 138874cdb337SChris Wilson } else 138974cdb337SChris Wilson DRM_ERROR("The master control interrupt lied (GT3)!\n"); 139074cdb337SChris Wilson } 139174cdb337SChris Wilson 139226705e20SSagar Arun Kamble if (master_ctl & (GEN8_GT_PM_IRQ | GEN8_GT_GUC_IRQ)) { 1393e30e251aSVille Syrjälä gt_iir[2] = I915_READ_FW(GEN8_GT_IIR(2)); 139426705e20SSagar Arun Kamble if (gt_iir[2] & (dev_priv->pm_rps_events | 139526705e20SSagar Arun Kamble dev_priv->pm_guc_events)) { 1396cb0d205eSChris Wilson I915_WRITE_FW(GEN8_GT_IIR(2), 139726705e20SSagar Arun Kamble gt_iir[2] & (dev_priv->pm_rps_events | 139826705e20SSagar Arun Kamble dev_priv->pm_guc_events)); 139938cc46d7SOscar Mateo ret = IRQ_HANDLED; 14000961021aSBen Widawsky } else 14010961021aSBen Widawsky DRM_ERROR("The master control interrupt lied (PM)!\n"); 14020961021aSBen Widawsky } 14030961021aSBen Widawsky 1404abd58f01SBen Widawsky return ret; 1405abd58f01SBen Widawsky } 1406abd58f01SBen Widawsky 1407e30e251aSVille Syrjälä static void gen8_gt_irq_handler(struct drm_i915_private *dev_priv, 1408e30e251aSVille Syrjälä u32 gt_iir[4]) 1409e30e251aSVille Syrjälä { 1410e30e251aSVille Syrjälä if (gt_iir[0]) { 14113b3f1650SAkash Goel gen8_cs_irq_handler(dev_priv->engine[RCS], 1412e30e251aSVille Syrjälä gt_iir[0], GEN8_RCS_IRQ_SHIFT); 14133b3f1650SAkash Goel gen8_cs_irq_handler(dev_priv->engine[BCS], 1414e30e251aSVille Syrjälä gt_iir[0], GEN8_BCS_IRQ_SHIFT); 1415e30e251aSVille Syrjälä } 1416e30e251aSVille Syrjälä 1417e30e251aSVille Syrjälä if (gt_iir[1]) { 14183b3f1650SAkash Goel gen8_cs_irq_handler(dev_priv->engine[VCS], 1419e30e251aSVille Syrjälä gt_iir[1], GEN8_VCS1_IRQ_SHIFT); 14203b3f1650SAkash Goel gen8_cs_irq_handler(dev_priv->engine[VCS2], 1421e30e251aSVille Syrjälä gt_iir[1], GEN8_VCS2_IRQ_SHIFT); 1422e30e251aSVille Syrjälä } 1423e30e251aSVille Syrjälä 1424e30e251aSVille Syrjälä if (gt_iir[3]) 14253b3f1650SAkash Goel gen8_cs_irq_handler(dev_priv->engine[VECS], 1426e30e251aSVille Syrjälä gt_iir[3], GEN8_VECS_IRQ_SHIFT); 1427e30e251aSVille Syrjälä 1428e30e251aSVille Syrjälä if (gt_iir[2] & dev_priv->pm_rps_events) 1429e30e251aSVille Syrjälä gen6_rps_irq_handler(dev_priv, gt_iir[2]); 143026705e20SSagar Arun Kamble 143126705e20SSagar Arun Kamble if (gt_iir[2] & dev_priv->pm_guc_events) 143226705e20SSagar Arun Kamble gen9_guc_irq_handler(dev_priv, gt_iir[2]); 1433e30e251aSVille Syrjälä } 1434e30e251aSVille Syrjälä 143563c88d22SImre Deak static bool bxt_port_hotplug_long_detect(enum port port, u32 val) 143663c88d22SImre Deak { 143763c88d22SImre Deak switch (port) { 143863c88d22SImre Deak case PORT_A: 1439195baa06SVille Syrjälä return val & PORTA_HOTPLUG_LONG_DETECT; 144063c88d22SImre Deak case PORT_B: 144163c88d22SImre Deak return val & PORTB_HOTPLUG_LONG_DETECT; 144263c88d22SImre Deak case PORT_C: 144363c88d22SImre Deak return val & PORTC_HOTPLUG_LONG_DETECT; 144463c88d22SImre Deak default: 144563c88d22SImre Deak return false; 144663c88d22SImre Deak } 144763c88d22SImre Deak } 144863c88d22SImre Deak 14496dbf30ceSVille Syrjälä static bool spt_port_hotplug2_long_detect(enum port port, u32 val) 14506dbf30ceSVille Syrjälä { 14516dbf30ceSVille Syrjälä switch (port) { 14526dbf30ceSVille Syrjälä case PORT_E: 14536dbf30ceSVille Syrjälä return val & PORTE_HOTPLUG_LONG_DETECT; 14546dbf30ceSVille Syrjälä default: 14556dbf30ceSVille Syrjälä return false; 14566dbf30ceSVille Syrjälä } 14576dbf30ceSVille Syrjälä } 14586dbf30ceSVille Syrjälä 145974c0b395SVille Syrjälä static bool spt_port_hotplug_long_detect(enum port port, u32 val) 146074c0b395SVille Syrjälä { 146174c0b395SVille Syrjälä switch (port) { 146274c0b395SVille Syrjälä case PORT_A: 146374c0b395SVille Syrjälä return val & PORTA_HOTPLUG_LONG_DETECT; 146474c0b395SVille Syrjälä case PORT_B: 146574c0b395SVille Syrjälä return val & PORTB_HOTPLUG_LONG_DETECT; 146674c0b395SVille Syrjälä case PORT_C: 146774c0b395SVille Syrjälä return val & PORTC_HOTPLUG_LONG_DETECT; 146874c0b395SVille Syrjälä case PORT_D: 146974c0b395SVille Syrjälä return val & PORTD_HOTPLUG_LONG_DETECT; 147074c0b395SVille Syrjälä default: 147174c0b395SVille Syrjälä return false; 147274c0b395SVille Syrjälä } 147374c0b395SVille Syrjälä } 147474c0b395SVille Syrjälä 1475e4ce95aaSVille Syrjälä static bool ilk_port_hotplug_long_detect(enum port port, u32 val) 1476e4ce95aaSVille Syrjälä { 1477e4ce95aaSVille Syrjälä switch (port) { 1478e4ce95aaSVille Syrjälä case PORT_A: 1479e4ce95aaSVille Syrjälä return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT; 1480e4ce95aaSVille Syrjälä default: 1481e4ce95aaSVille Syrjälä return false; 1482e4ce95aaSVille Syrjälä } 1483e4ce95aaSVille Syrjälä } 1484e4ce95aaSVille Syrjälä 1485676574dfSJani Nikula static bool pch_port_hotplug_long_detect(enum port port, u32 val) 148613cf5504SDave Airlie { 148713cf5504SDave Airlie switch (port) { 148813cf5504SDave Airlie case PORT_B: 1489676574dfSJani Nikula return val & PORTB_HOTPLUG_LONG_DETECT; 149013cf5504SDave Airlie case PORT_C: 1491676574dfSJani Nikula return val & PORTC_HOTPLUG_LONG_DETECT; 149213cf5504SDave Airlie case PORT_D: 1493676574dfSJani Nikula return val & PORTD_HOTPLUG_LONG_DETECT; 1494676574dfSJani Nikula default: 1495676574dfSJani Nikula return false; 149613cf5504SDave Airlie } 149713cf5504SDave Airlie } 149813cf5504SDave Airlie 1499676574dfSJani Nikula static bool i9xx_port_hotplug_long_detect(enum port port, u32 val) 150013cf5504SDave Airlie { 150113cf5504SDave Airlie switch (port) { 150213cf5504SDave Airlie case PORT_B: 1503676574dfSJani Nikula return val & PORTB_HOTPLUG_INT_LONG_PULSE; 150413cf5504SDave Airlie case PORT_C: 1505676574dfSJani Nikula return val & PORTC_HOTPLUG_INT_LONG_PULSE; 150613cf5504SDave Airlie case PORT_D: 1507676574dfSJani Nikula return val & PORTD_HOTPLUG_INT_LONG_PULSE; 1508676574dfSJani Nikula default: 1509676574dfSJani Nikula return false; 151013cf5504SDave Airlie } 151113cf5504SDave Airlie } 151213cf5504SDave Airlie 151342db67d6SVille Syrjälä /* 151442db67d6SVille Syrjälä * Get a bit mask of pins that have triggered, and which ones may be long. 151542db67d6SVille Syrjälä * This can be called multiple times with the same masks to accumulate 151642db67d6SVille Syrjälä * hotplug detection results from several registers. 151742db67d6SVille Syrjälä * 151842db67d6SVille Syrjälä * Note that the caller is expected to zero out the masks initially. 151942db67d6SVille Syrjälä */ 1520fd63e2a9SImre Deak static void intel_get_hpd_pins(u32 *pin_mask, u32 *long_mask, 15218c841e57SJani Nikula u32 hotplug_trigger, u32 dig_hotplug_reg, 1522fd63e2a9SImre Deak const u32 hpd[HPD_NUM_PINS], 1523fd63e2a9SImre Deak bool long_pulse_detect(enum port port, u32 val)) 1524676574dfSJani Nikula { 15258c841e57SJani Nikula enum port port; 1526676574dfSJani Nikula int i; 1527676574dfSJani Nikula 1528676574dfSJani Nikula for_each_hpd_pin(i) { 15298c841e57SJani Nikula if ((hpd[i] & hotplug_trigger) == 0) 15308c841e57SJani Nikula continue; 15318c841e57SJani Nikula 1532676574dfSJani Nikula *pin_mask |= BIT(i); 1533676574dfSJani Nikula 1534256cfddeSRodrigo Vivi port = intel_hpd_pin_to_port(i); 1535256cfddeSRodrigo Vivi if (port == PORT_NONE) 1536cc24fcdcSImre Deak continue; 1537cc24fcdcSImre Deak 1538fd63e2a9SImre Deak if (long_pulse_detect(port, dig_hotplug_reg)) 1539676574dfSJani Nikula *long_mask |= BIT(i); 1540676574dfSJani Nikula } 1541676574dfSJani Nikula 1542676574dfSJani Nikula DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x\n", 1543676574dfSJani Nikula hotplug_trigger, dig_hotplug_reg, *pin_mask); 1544676574dfSJani Nikula 1545676574dfSJani Nikula } 1546676574dfSJani Nikula 154791d14251STvrtko Ursulin static void gmbus_irq_handler(struct drm_i915_private *dev_priv) 1548515ac2bbSDaniel Vetter { 154928c70f16SDaniel Vetter wake_up_all(&dev_priv->gmbus_wait_queue); 1550515ac2bbSDaniel Vetter } 1551515ac2bbSDaniel Vetter 155291d14251STvrtko Ursulin static void dp_aux_irq_handler(struct drm_i915_private *dev_priv) 1553ce99c256SDaniel Vetter { 15549ee32feaSDaniel Vetter wake_up_all(&dev_priv->gmbus_wait_queue); 1555ce99c256SDaniel Vetter } 1556ce99c256SDaniel Vetter 15578bf1e9f1SShuang He #if defined(CONFIG_DEBUG_FS) 155891d14251STvrtko Ursulin static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, 155991d14251STvrtko Ursulin enum pipe pipe, 1560eba94eb9SDaniel Vetter uint32_t crc0, uint32_t crc1, 1561eba94eb9SDaniel Vetter uint32_t crc2, uint32_t crc3, 15628bc5e955SDaniel Vetter uint32_t crc4) 15638bf1e9f1SShuang He { 15648bf1e9f1SShuang He struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe]; 15658bf1e9f1SShuang He struct intel_pipe_crc_entry *entry; 15668c6b709dSTomeu Vizoso struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); 15678c6b709dSTomeu Vizoso struct drm_driver *driver = dev_priv->drm.driver; 15688c6b709dSTomeu Vizoso uint32_t crcs[5]; 1569ac2300d4SDamien Lespiau int head, tail; 1570b2c88f5bSDamien Lespiau 1571d538bbdfSDamien Lespiau spin_lock(&pipe_crc->lock); 15728c6b709dSTomeu Vizoso if (pipe_crc->source) { 15730c912c79SDamien Lespiau if (!pipe_crc->entries) { 1574d538bbdfSDamien Lespiau spin_unlock(&pipe_crc->lock); 157534273620SDaniel Vetter DRM_DEBUG_KMS("spurious interrupt\n"); 15760c912c79SDamien Lespiau return; 15770c912c79SDamien Lespiau } 15780c912c79SDamien Lespiau 1579d538bbdfSDamien Lespiau head = pipe_crc->head; 1580d538bbdfSDamien Lespiau tail = pipe_crc->tail; 1581b2c88f5bSDamien Lespiau 1582b2c88f5bSDamien Lespiau if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) { 1583d538bbdfSDamien Lespiau spin_unlock(&pipe_crc->lock); 1584b2c88f5bSDamien Lespiau DRM_ERROR("CRC buffer overflowing\n"); 1585b2c88f5bSDamien Lespiau return; 1586b2c88f5bSDamien Lespiau } 1587b2c88f5bSDamien Lespiau 1588b2c88f5bSDamien Lespiau entry = &pipe_crc->entries[head]; 15898bf1e9f1SShuang He 15908c6b709dSTomeu Vizoso entry->frame = driver->get_vblank_counter(&dev_priv->drm, pipe); 1591eba94eb9SDaniel Vetter entry->crc[0] = crc0; 1592eba94eb9SDaniel Vetter entry->crc[1] = crc1; 1593eba94eb9SDaniel Vetter entry->crc[2] = crc2; 1594eba94eb9SDaniel Vetter entry->crc[3] = crc3; 1595eba94eb9SDaniel Vetter entry->crc[4] = crc4; 1596b2c88f5bSDamien Lespiau 1597b2c88f5bSDamien Lespiau head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1); 1598d538bbdfSDamien Lespiau pipe_crc->head = head; 1599d538bbdfSDamien Lespiau 1600d538bbdfSDamien Lespiau spin_unlock(&pipe_crc->lock); 160107144428SDamien Lespiau 160207144428SDamien Lespiau wake_up_interruptible(&pipe_crc->wq); 16038c6b709dSTomeu Vizoso } else { 16048c6b709dSTomeu Vizoso /* 16058c6b709dSTomeu Vizoso * For some not yet identified reason, the first CRC is 16068c6b709dSTomeu Vizoso * bonkers. So let's just wait for the next vblank and read 16078c6b709dSTomeu Vizoso * out the buggy result. 16088c6b709dSTomeu Vizoso * 16098c6b709dSTomeu Vizoso * On CHV sometimes the second CRC is bonkers as well, so 16108c6b709dSTomeu Vizoso * don't trust that one either. 16118c6b709dSTomeu Vizoso */ 16128c6b709dSTomeu Vizoso if (pipe_crc->skipped == 0 || 16138c6b709dSTomeu Vizoso (IS_CHERRYVIEW(dev_priv) && pipe_crc->skipped == 1)) { 16148c6b709dSTomeu Vizoso pipe_crc->skipped++; 16158c6b709dSTomeu Vizoso spin_unlock(&pipe_crc->lock); 16168c6b709dSTomeu Vizoso return; 16178c6b709dSTomeu Vizoso } 16188c6b709dSTomeu Vizoso spin_unlock(&pipe_crc->lock); 16198c6b709dSTomeu Vizoso crcs[0] = crc0; 16208c6b709dSTomeu Vizoso crcs[1] = crc1; 16218c6b709dSTomeu Vizoso crcs[2] = crc2; 16228c6b709dSTomeu Vizoso crcs[3] = crc3; 16238c6b709dSTomeu Vizoso crcs[4] = crc4; 1624246ee524STomeu Vizoso drm_crtc_add_crc_entry(&crtc->base, true, 1625ca814b25SDaniel Vetter drm_crtc_accurate_vblank_count(&crtc->base), 1626246ee524STomeu Vizoso crcs); 16278c6b709dSTomeu Vizoso } 16288bf1e9f1SShuang He } 1629277de95eSDaniel Vetter #else 1630277de95eSDaniel Vetter static inline void 163191d14251STvrtko Ursulin display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, 163291d14251STvrtko Ursulin enum pipe pipe, 1633277de95eSDaniel Vetter uint32_t crc0, uint32_t crc1, 1634277de95eSDaniel Vetter uint32_t crc2, uint32_t crc3, 1635277de95eSDaniel Vetter uint32_t crc4) {} 1636277de95eSDaniel Vetter #endif 1637eba94eb9SDaniel Vetter 1638277de95eSDaniel Vetter 163991d14251STvrtko Ursulin static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, 164091d14251STvrtko Ursulin enum pipe pipe) 16415a69b89fSDaniel Vetter { 164291d14251STvrtko Ursulin display_pipe_crc_irq_handler(dev_priv, pipe, 16435a69b89fSDaniel Vetter I915_READ(PIPE_CRC_RES_1_IVB(pipe)), 16445a69b89fSDaniel Vetter 0, 0, 0, 0); 16455a69b89fSDaniel Vetter } 16465a69b89fSDaniel Vetter 164791d14251STvrtko Ursulin static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, 164891d14251STvrtko Ursulin enum pipe pipe) 1649eba94eb9SDaniel Vetter { 165091d14251STvrtko Ursulin display_pipe_crc_irq_handler(dev_priv, pipe, 1651eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_1_IVB(pipe)), 1652eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_2_IVB(pipe)), 1653eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_3_IVB(pipe)), 1654eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_4_IVB(pipe)), 16558bc5e955SDaniel Vetter I915_READ(PIPE_CRC_RES_5_IVB(pipe))); 1656eba94eb9SDaniel Vetter } 16575b3a856bSDaniel Vetter 165891d14251STvrtko Ursulin static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, 165991d14251STvrtko Ursulin enum pipe pipe) 16605b3a856bSDaniel Vetter { 16610b5c5ed0SDaniel Vetter uint32_t res1, res2; 16620b5c5ed0SDaniel Vetter 166391d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 3) 16640b5c5ed0SDaniel Vetter res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe)); 16650b5c5ed0SDaniel Vetter else 16660b5c5ed0SDaniel Vetter res1 = 0; 16670b5c5ed0SDaniel Vetter 166891d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) 16690b5c5ed0SDaniel Vetter res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe)); 16700b5c5ed0SDaniel Vetter else 16710b5c5ed0SDaniel Vetter res2 = 0; 16725b3a856bSDaniel Vetter 167391d14251STvrtko Ursulin display_pipe_crc_irq_handler(dev_priv, pipe, 16740b5c5ed0SDaniel Vetter I915_READ(PIPE_CRC_RES_RED(pipe)), 16750b5c5ed0SDaniel Vetter I915_READ(PIPE_CRC_RES_GREEN(pipe)), 16760b5c5ed0SDaniel Vetter I915_READ(PIPE_CRC_RES_BLUE(pipe)), 16770b5c5ed0SDaniel Vetter res1, res2); 16785b3a856bSDaniel Vetter } 16798bf1e9f1SShuang He 16801403c0d4SPaulo Zanoni /* The RPS events need forcewake, so we add them to a work queue and mask their 16811403c0d4SPaulo Zanoni * IMR bits until the work is done. Other interrupts can be processed without 16821403c0d4SPaulo Zanoni * the work queue. */ 16831403c0d4SPaulo Zanoni static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir) 1684baf02a1fSBen Widawsky { 1685a6706b45SDeepak S if (pm_iir & dev_priv->pm_rps_events) { 168659cdb63dSDaniel Vetter spin_lock(&dev_priv->irq_lock); 1687f4e9af4fSAkash Goel gen6_mask_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events); 1688d4d70aa5SImre Deak if (dev_priv->rps.interrupts_enabled) { 1689d4d70aa5SImre Deak dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events; 1690c33d247dSChris Wilson schedule_work(&dev_priv->rps.work); 169141a05a3aSDaniel Vetter } 1692d4d70aa5SImre Deak spin_unlock(&dev_priv->irq_lock); 1693d4d70aa5SImre Deak } 1694baf02a1fSBen Widawsky 1695bca2bf2aSPandiyan, Dhinakaran if (INTEL_GEN(dev_priv) >= 8) 1696c9a9a268SImre Deak return; 1697c9a9a268SImre Deak 16982d1fe073SJoonas Lahtinen if (HAS_VEBOX(dev_priv)) { 169912638c57SBen Widawsky if (pm_iir & PM_VEBOX_USER_INTERRUPT) 17003b3f1650SAkash Goel notify_ring(dev_priv->engine[VECS]); 170112638c57SBen Widawsky 1702aaecdf61SDaniel Vetter if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) 1703aaecdf61SDaniel Vetter DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir); 170412638c57SBen Widawsky } 17051403c0d4SPaulo Zanoni } 1706baf02a1fSBen Widawsky 170726705e20SSagar Arun Kamble static void gen9_guc_irq_handler(struct drm_i915_private *dev_priv, u32 gt_iir) 170826705e20SSagar Arun Kamble { 170926705e20SSagar Arun Kamble if (gt_iir & GEN9_GUC_TO_HOST_INT_EVENT) { 17104100b2abSSagar Arun Kamble /* Sample the log buffer flush related bits & clear them out now 17114100b2abSSagar Arun Kamble * itself from the message identity register to minimize the 17124100b2abSSagar Arun Kamble * probability of losing a flush interrupt, when there are back 17134100b2abSSagar Arun Kamble * to back flush interrupts. 17144100b2abSSagar Arun Kamble * There can be a new flush interrupt, for different log buffer 17154100b2abSSagar Arun Kamble * type (like for ISR), whilst Host is handling one (for DPC). 17164100b2abSSagar Arun Kamble * Since same bit is used in message register for ISR & DPC, it 17174100b2abSSagar Arun Kamble * could happen that GuC sets the bit for 2nd interrupt but Host 17184100b2abSSagar Arun Kamble * clears out the bit on handling the 1st interrupt. 17194100b2abSSagar Arun Kamble */ 17204100b2abSSagar Arun Kamble u32 msg, flush; 17214100b2abSSagar Arun Kamble 17224100b2abSSagar Arun Kamble msg = I915_READ(SOFT_SCRATCH(15)); 1723a80bc45fSArkadiusz Hiler flush = msg & (INTEL_GUC_RECV_MSG_CRASH_DUMP_POSTED | 1724a80bc45fSArkadiusz Hiler INTEL_GUC_RECV_MSG_FLUSH_LOG_BUFFER); 17254100b2abSSagar Arun Kamble if (flush) { 17264100b2abSSagar Arun Kamble /* Clear the message bits that are handled */ 17274100b2abSSagar Arun Kamble I915_WRITE(SOFT_SCRATCH(15), msg & ~flush); 17284100b2abSSagar Arun Kamble 17294100b2abSSagar Arun Kamble /* Handle flush interrupt in bottom half */ 1730e7465473SOscar Mateo queue_work(dev_priv->guc.log.runtime.flush_wq, 1731e7465473SOscar Mateo &dev_priv->guc.log.runtime.flush_work); 17325aa1ee4bSAkash Goel 17335aa1ee4bSAkash Goel dev_priv->guc.log.flush_interrupt_count++; 17344100b2abSSagar Arun Kamble } else { 17354100b2abSSagar Arun Kamble /* Not clearing of unhandled event bits won't result in 17364100b2abSSagar Arun Kamble * re-triggering of the interrupt. 17374100b2abSSagar Arun Kamble */ 17384100b2abSSagar Arun Kamble } 173926705e20SSagar Arun Kamble } 174026705e20SSagar Arun Kamble } 174126705e20SSagar Arun Kamble 174244d9241eSVille Syrjälä static void i9xx_pipestat_irq_reset(struct drm_i915_private *dev_priv) 174344d9241eSVille Syrjälä { 174444d9241eSVille Syrjälä enum pipe pipe; 174544d9241eSVille Syrjälä 174644d9241eSVille Syrjälä for_each_pipe(dev_priv, pipe) { 174744d9241eSVille Syrjälä I915_WRITE(PIPESTAT(pipe), 174844d9241eSVille Syrjälä PIPESTAT_INT_STATUS_MASK | 174944d9241eSVille Syrjälä PIPE_FIFO_UNDERRUN_STATUS); 175044d9241eSVille Syrjälä 175144d9241eSVille Syrjälä dev_priv->pipestat_irq_mask[pipe] = 0; 175244d9241eSVille Syrjälä } 175344d9241eSVille Syrjälä } 175444d9241eSVille Syrjälä 1755eb64343cSVille Syrjälä static void i9xx_pipestat_irq_ack(struct drm_i915_private *dev_priv, 175691d14251STvrtko Ursulin u32 iir, u32 pipe_stats[I915_MAX_PIPES]) 17577e231dbeSJesse Barnes { 17587e231dbeSJesse Barnes int pipe; 17597e231dbeSJesse Barnes 176058ead0d7SImre Deak spin_lock(&dev_priv->irq_lock); 17611ca993d2SVille Syrjälä 17621ca993d2SVille Syrjälä if (!dev_priv->display_irqs_enabled) { 17631ca993d2SVille Syrjälä spin_unlock(&dev_priv->irq_lock); 17641ca993d2SVille Syrjälä return; 17651ca993d2SVille Syrjälä } 17661ca993d2SVille Syrjälä 1767055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 1768f0f59a00SVille Syrjälä i915_reg_t reg; 1769bbb5eebfSDaniel Vetter u32 mask, iir_bit = 0; 177091d181ddSImre Deak 1771bbb5eebfSDaniel Vetter /* 1772bbb5eebfSDaniel Vetter * PIPESTAT bits get signalled even when the interrupt is 1773bbb5eebfSDaniel Vetter * disabled with the mask bits, and some of the status bits do 1774bbb5eebfSDaniel Vetter * not generate interrupts at all (like the underrun bit). Hence 1775bbb5eebfSDaniel Vetter * we need to be careful that we only handle what we want to 1776bbb5eebfSDaniel Vetter * handle. 1777bbb5eebfSDaniel Vetter */ 17780f239f4cSDaniel Vetter 17790f239f4cSDaniel Vetter /* fifo underruns are filterered in the underrun handler. */ 17800f239f4cSDaniel Vetter mask = PIPE_FIFO_UNDERRUN_STATUS; 1781bbb5eebfSDaniel Vetter 1782bbb5eebfSDaniel Vetter switch (pipe) { 1783bbb5eebfSDaniel Vetter case PIPE_A: 1784bbb5eebfSDaniel Vetter iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT; 1785bbb5eebfSDaniel Vetter break; 1786bbb5eebfSDaniel Vetter case PIPE_B: 1787bbb5eebfSDaniel Vetter iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT; 1788bbb5eebfSDaniel Vetter break; 17893278f67fSVille Syrjälä case PIPE_C: 17903278f67fSVille Syrjälä iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT; 17913278f67fSVille Syrjälä break; 1792bbb5eebfSDaniel Vetter } 1793bbb5eebfSDaniel Vetter if (iir & iir_bit) 1794bbb5eebfSDaniel Vetter mask |= dev_priv->pipestat_irq_mask[pipe]; 1795bbb5eebfSDaniel Vetter 1796bbb5eebfSDaniel Vetter if (!mask) 179791d181ddSImre Deak continue; 179891d181ddSImre Deak 179991d181ddSImre Deak reg = PIPESTAT(pipe); 1800bbb5eebfSDaniel Vetter mask |= PIPESTAT_INT_ENABLE_MASK; 1801bbb5eebfSDaniel Vetter pipe_stats[pipe] = I915_READ(reg) & mask; 18027e231dbeSJesse Barnes 18037e231dbeSJesse Barnes /* 18047e231dbeSJesse Barnes * Clear the PIPE*STAT regs before the IIR 18057e231dbeSJesse Barnes */ 180691d181ddSImre Deak if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS | 180791d181ddSImre Deak PIPESTAT_INT_STATUS_MASK)) 18087e231dbeSJesse Barnes I915_WRITE(reg, pipe_stats[pipe]); 18097e231dbeSJesse Barnes } 181058ead0d7SImre Deak spin_unlock(&dev_priv->irq_lock); 18112ecb8ca4SVille Syrjälä } 18122ecb8ca4SVille Syrjälä 1813eb64343cSVille Syrjälä static void i8xx_pipestat_irq_handler(struct drm_i915_private *dev_priv, 1814eb64343cSVille Syrjälä u16 iir, u32 pipe_stats[I915_MAX_PIPES]) 1815eb64343cSVille Syrjälä { 1816eb64343cSVille Syrjälä enum pipe pipe; 1817eb64343cSVille Syrjälä 1818eb64343cSVille Syrjälä for_each_pipe(dev_priv, pipe) { 1819eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS) 1820eb64343cSVille Syrjälä drm_handle_vblank(&dev_priv->drm, pipe); 1821eb64343cSVille Syrjälä 1822eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 1823eb64343cSVille Syrjälä i9xx_pipe_crc_irq_handler(dev_priv, pipe); 1824eb64343cSVille Syrjälä 1825eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 1826eb64343cSVille Syrjälä intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 1827eb64343cSVille Syrjälä } 1828eb64343cSVille Syrjälä } 1829eb64343cSVille Syrjälä 1830eb64343cSVille Syrjälä static void i915_pipestat_irq_handler(struct drm_i915_private *dev_priv, 1831eb64343cSVille Syrjälä u32 iir, u32 pipe_stats[I915_MAX_PIPES]) 1832eb64343cSVille Syrjälä { 1833eb64343cSVille Syrjälä bool blc_event = false; 1834eb64343cSVille Syrjälä enum pipe pipe; 1835eb64343cSVille Syrjälä 1836eb64343cSVille Syrjälä for_each_pipe(dev_priv, pipe) { 1837eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS) 1838eb64343cSVille Syrjälä drm_handle_vblank(&dev_priv->drm, pipe); 1839eb64343cSVille Syrjälä 1840eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 1841eb64343cSVille Syrjälä blc_event = true; 1842eb64343cSVille Syrjälä 1843eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 1844eb64343cSVille Syrjälä i9xx_pipe_crc_irq_handler(dev_priv, pipe); 1845eb64343cSVille Syrjälä 1846eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 1847eb64343cSVille Syrjälä intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 1848eb64343cSVille Syrjälä } 1849eb64343cSVille Syrjälä 1850eb64343cSVille Syrjälä if (blc_event || (iir & I915_ASLE_INTERRUPT)) 1851eb64343cSVille Syrjälä intel_opregion_asle_intr(dev_priv); 1852eb64343cSVille Syrjälä } 1853eb64343cSVille Syrjälä 1854eb64343cSVille Syrjälä static void i965_pipestat_irq_handler(struct drm_i915_private *dev_priv, 1855eb64343cSVille Syrjälä u32 iir, u32 pipe_stats[I915_MAX_PIPES]) 1856eb64343cSVille Syrjälä { 1857eb64343cSVille Syrjälä bool blc_event = false; 1858eb64343cSVille Syrjälä enum pipe pipe; 1859eb64343cSVille Syrjälä 1860eb64343cSVille Syrjälä for_each_pipe(dev_priv, pipe) { 1861eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS) 1862eb64343cSVille Syrjälä drm_handle_vblank(&dev_priv->drm, pipe); 1863eb64343cSVille Syrjälä 1864eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 1865eb64343cSVille Syrjälä blc_event = true; 1866eb64343cSVille Syrjälä 1867eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 1868eb64343cSVille Syrjälä i9xx_pipe_crc_irq_handler(dev_priv, pipe); 1869eb64343cSVille Syrjälä 1870eb64343cSVille Syrjälä if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 1871eb64343cSVille Syrjälä intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 1872eb64343cSVille Syrjälä } 1873eb64343cSVille Syrjälä 1874eb64343cSVille Syrjälä if (blc_event || (iir & I915_ASLE_INTERRUPT)) 1875eb64343cSVille Syrjälä intel_opregion_asle_intr(dev_priv); 1876eb64343cSVille Syrjälä 1877eb64343cSVille Syrjälä if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 1878eb64343cSVille Syrjälä gmbus_irq_handler(dev_priv); 1879eb64343cSVille Syrjälä } 1880eb64343cSVille Syrjälä 188191d14251STvrtko Ursulin static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv, 18822ecb8ca4SVille Syrjälä u32 pipe_stats[I915_MAX_PIPES]) 18832ecb8ca4SVille Syrjälä { 18842ecb8ca4SVille Syrjälä enum pipe pipe; 18857e231dbeSJesse Barnes 1886055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 1887fd3a4024SDaniel Vetter if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS) 1888fd3a4024SDaniel Vetter drm_handle_vblank(&dev_priv->drm, pipe); 18894356d586SDaniel Vetter 18904356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 189191d14251STvrtko Ursulin i9xx_pipe_crc_irq_handler(dev_priv, pipe); 18922d9d2b0bSVille Syrjälä 18931f7247c0SDaniel Vetter if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 18941f7247c0SDaniel Vetter intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 189531acc7f5SJesse Barnes } 189631acc7f5SJesse Barnes 1897c1874ed7SImre Deak if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 189891d14251STvrtko Ursulin gmbus_irq_handler(dev_priv); 1899c1874ed7SImre Deak } 1900c1874ed7SImre Deak 19011ae3c34cSVille Syrjälä static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv) 190216c6c56bSVille Syrjälä { 190316c6c56bSVille Syrjälä u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); 190416c6c56bSVille Syrjälä 19051ae3c34cSVille Syrjälä if (hotplug_status) 19063ff60f89SOscar Mateo I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); 19071ae3c34cSVille Syrjälä 19081ae3c34cSVille Syrjälä return hotplug_status; 19091ae3c34cSVille Syrjälä } 19101ae3c34cSVille Syrjälä 191191d14251STvrtko Ursulin static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv, 19121ae3c34cSVille Syrjälä u32 hotplug_status) 19131ae3c34cSVille Syrjälä { 19141ae3c34cSVille Syrjälä u32 pin_mask = 0, long_mask = 0; 19153ff60f89SOscar Mateo 191691d14251STvrtko Ursulin if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || 191791d14251STvrtko Ursulin IS_CHERRYVIEW(dev_priv)) { 191816c6c56bSVille Syrjälä u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X; 191916c6c56bSVille Syrjälä 192058f2cf24SVille Syrjälä if (hotplug_trigger) { 1921fd63e2a9SImre Deak intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger, 1922fd63e2a9SImre Deak hotplug_trigger, hpd_status_g4x, 1923fd63e2a9SImre Deak i9xx_port_hotplug_long_detect); 192458f2cf24SVille Syrjälä 192591d14251STvrtko Ursulin intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 192658f2cf24SVille Syrjälä } 1927369712e8SJani Nikula 1928369712e8SJani Nikula if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X) 192991d14251STvrtko Ursulin dp_aux_irq_handler(dev_priv); 193016c6c56bSVille Syrjälä } else { 193116c6c56bSVille Syrjälä u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915; 193216c6c56bSVille Syrjälä 193358f2cf24SVille Syrjälä if (hotplug_trigger) { 1934fd63e2a9SImre Deak intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger, 19354e3d1e26SVille Syrjälä hotplug_trigger, hpd_status_i915, 1936fd63e2a9SImre Deak i9xx_port_hotplug_long_detect); 193791d14251STvrtko Ursulin intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 193816c6c56bSVille Syrjälä } 19393ff60f89SOscar Mateo } 194058f2cf24SVille Syrjälä } 194116c6c56bSVille Syrjälä 1942c1874ed7SImre Deak static irqreturn_t valleyview_irq_handler(int irq, void *arg) 1943c1874ed7SImre Deak { 194445a83f84SDaniel Vetter struct drm_device *dev = arg; 1945fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 1946c1874ed7SImre Deak irqreturn_t ret = IRQ_NONE; 1947c1874ed7SImre Deak 19482dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 19492dd2a883SImre Deak return IRQ_NONE; 19502dd2a883SImre Deak 19511f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 19521f814dacSImre Deak disable_rpm_wakeref_asserts(dev_priv); 19531f814dacSImre Deak 19541e1cace9SVille Syrjälä do { 19556e814800SVille Syrjälä u32 iir, gt_iir, pm_iir; 19562ecb8ca4SVille Syrjälä u32 pipe_stats[I915_MAX_PIPES] = {}; 19571ae3c34cSVille Syrjälä u32 hotplug_status = 0; 1958a5e485a9SVille Syrjälä u32 ier = 0; 19593ff60f89SOscar Mateo 1960c1874ed7SImre Deak gt_iir = I915_READ(GTIIR); 1961c1874ed7SImre Deak pm_iir = I915_READ(GEN6_PMIIR); 19623ff60f89SOscar Mateo iir = I915_READ(VLV_IIR); 1963c1874ed7SImre Deak 1964c1874ed7SImre Deak if (gt_iir == 0 && pm_iir == 0 && iir == 0) 19651e1cace9SVille Syrjälä break; 1966c1874ed7SImre Deak 1967c1874ed7SImre Deak ret = IRQ_HANDLED; 1968c1874ed7SImre Deak 1969a5e485a9SVille Syrjälä /* 1970a5e485a9SVille Syrjälä * Theory on interrupt generation, based on empirical evidence: 1971a5e485a9SVille Syrjälä * 1972a5e485a9SVille Syrjälä * x = ((VLV_IIR & VLV_IER) || 1973a5e485a9SVille Syrjälä * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) && 1974a5e485a9SVille Syrjälä * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE))); 1975a5e485a9SVille Syrjälä * 1976a5e485a9SVille Syrjälä * A CPU interrupt will only be raised when 'x' has a 0->1 edge. 1977a5e485a9SVille Syrjälä * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to 1978a5e485a9SVille Syrjälä * guarantee the CPU interrupt will be raised again even if we 1979a5e485a9SVille Syrjälä * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR 1980a5e485a9SVille Syrjälä * bits this time around. 1981a5e485a9SVille Syrjälä */ 19824a0a0202SVille Syrjälä I915_WRITE(VLV_MASTER_IER, 0); 1983a5e485a9SVille Syrjälä ier = I915_READ(VLV_IER); 1984a5e485a9SVille Syrjälä I915_WRITE(VLV_IER, 0); 19854a0a0202SVille Syrjälä 19864a0a0202SVille Syrjälä if (gt_iir) 19874a0a0202SVille Syrjälä I915_WRITE(GTIIR, gt_iir); 19884a0a0202SVille Syrjälä if (pm_iir) 19894a0a0202SVille Syrjälä I915_WRITE(GEN6_PMIIR, pm_iir); 19904a0a0202SVille Syrjälä 19917ce4d1f2SVille Syrjälä if (iir & I915_DISPLAY_PORT_INTERRUPT) 19921ae3c34cSVille Syrjälä hotplug_status = i9xx_hpd_irq_ack(dev_priv); 19937ce4d1f2SVille Syrjälä 19943ff60f89SOscar Mateo /* Call regardless, as some status bits might not be 19953ff60f89SOscar Mateo * signalled in iir */ 1996eb64343cSVille Syrjälä i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats); 19977ce4d1f2SVille Syrjälä 1998eef57324SJerome Anand if (iir & (I915_LPE_PIPE_A_INTERRUPT | 1999eef57324SJerome Anand I915_LPE_PIPE_B_INTERRUPT)) 2000eef57324SJerome Anand intel_lpe_audio_irq_handler(dev_priv); 2001eef57324SJerome Anand 20027ce4d1f2SVille Syrjälä /* 20037ce4d1f2SVille Syrjälä * VLV_IIR is single buffered, and reflects the level 20047ce4d1f2SVille Syrjälä * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last. 20057ce4d1f2SVille Syrjälä */ 20067ce4d1f2SVille Syrjälä if (iir) 20077ce4d1f2SVille Syrjälä I915_WRITE(VLV_IIR, iir); 20084a0a0202SVille Syrjälä 2009a5e485a9SVille Syrjälä I915_WRITE(VLV_IER, ier); 20104a0a0202SVille Syrjälä I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE); 20114a0a0202SVille Syrjälä POSTING_READ(VLV_MASTER_IER); 20121ae3c34cSVille Syrjälä 201352894874SVille Syrjälä if (gt_iir) 2014261e40b8SVille Syrjälä snb_gt_irq_handler(dev_priv, gt_iir); 201552894874SVille Syrjälä if (pm_iir) 201652894874SVille Syrjälä gen6_rps_irq_handler(dev_priv, pm_iir); 201752894874SVille Syrjälä 20181ae3c34cSVille Syrjälä if (hotplug_status) 201991d14251STvrtko Ursulin i9xx_hpd_irq_handler(dev_priv, hotplug_status); 20202ecb8ca4SVille Syrjälä 202191d14251STvrtko Ursulin valleyview_pipestat_irq_handler(dev_priv, pipe_stats); 20221e1cace9SVille Syrjälä } while (0); 20237e231dbeSJesse Barnes 20241f814dacSImre Deak enable_rpm_wakeref_asserts(dev_priv); 20251f814dacSImre Deak 20267e231dbeSJesse Barnes return ret; 20277e231dbeSJesse Barnes } 20287e231dbeSJesse Barnes 202943f328d7SVille Syrjälä static irqreturn_t cherryview_irq_handler(int irq, void *arg) 203043f328d7SVille Syrjälä { 203145a83f84SDaniel Vetter struct drm_device *dev = arg; 2032fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 203343f328d7SVille Syrjälä irqreturn_t ret = IRQ_NONE; 203443f328d7SVille Syrjälä 20352dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 20362dd2a883SImre Deak return IRQ_NONE; 20372dd2a883SImre Deak 20381f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 20391f814dacSImre Deak disable_rpm_wakeref_asserts(dev_priv); 20401f814dacSImre Deak 2041579de73bSChris Wilson do { 20426e814800SVille Syrjälä u32 master_ctl, iir; 2043e30e251aSVille Syrjälä u32 gt_iir[4] = {}; 20442ecb8ca4SVille Syrjälä u32 pipe_stats[I915_MAX_PIPES] = {}; 20451ae3c34cSVille Syrjälä u32 hotplug_status = 0; 2046a5e485a9SVille Syrjälä u32 ier = 0; 2047a5e485a9SVille Syrjälä 20488e5fd599SVille Syrjälä master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL; 20493278f67fSVille Syrjälä iir = I915_READ(VLV_IIR); 20503278f67fSVille Syrjälä 20513278f67fSVille Syrjälä if (master_ctl == 0 && iir == 0) 20528e5fd599SVille Syrjälä break; 205343f328d7SVille Syrjälä 205427b6c122SOscar Mateo ret = IRQ_HANDLED; 205527b6c122SOscar Mateo 2056a5e485a9SVille Syrjälä /* 2057a5e485a9SVille Syrjälä * Theory on interrupt generation, based on empirical evidence: 2058a5e485a9SVille Syrjälä * 2059a5e485a9SVille Syrjälä * x = ((VLV_IIR & VLV_IER) || 2060a5e485a9SVille Syrjälä * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) && 2061a5e485a9SVille Syrjälä * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL))); 2062a5e485a9SVille Syrjälä * 2063a5e485a9SVille Syrjälä * A CPU interrupt will only be raised when 'x' has a 0->1 edge. 2064a5e485a9SVille Syrjälä * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to 2065a5e485a9SVille Syrjälä * guarantee the CPU interrupt will be raised again even if we 2066a5e485a9SVille Syrjälä * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL 2067a5e485a9SVille Syrjälä * bits this time around. 2068a5e485a9SVille Syrjälä */ 206943f328d7SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, 0); 2070a5e485a9SVille Syrjälä ier = I915_READ(VLV_IER); 2071a5e485a9SVille Syrjälä I915_WRITE(VLV_IER, 0); 207243f328d7SVille Syrjälä 2073e30e251aSVille Syrjälä gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir); 207427b6c122SOscar Mateo 207527b6c122SOscar Mateo if (iir & I915_DISPLAY_PORT_INTERRUPT) 20761ae3c34cSVille Syrjälä hotplug_status = i9xx_hpd_irq_ack(dev_priv); 207743f328d7SVille Syrjälä 207827b6c122SOscar Mateo /* Call regardless, as some status bits might not be 207927b6c122SOscar Mateo * signalled in iir */ 2080eb64343cSVille Syrjälä i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats); 208143f328d7SVille Syrjälä 2082eef57324SJerome Anand if (iir & (I915_LPE_PIPE_A_INTERRUPT | 2083eef57324SJerome Anand I915_LPE_PIPE_B_INTERRUPT | 2084eef57324SJerome Anand I915_LPE_PIPE_C_INTERRUPT)) 2085eef57324SJerome Anand intel_lpe_audio_irq_handler(dev_priv); 2086eef57324SJerome Anand 20877ce4d1f2SVille Syrjälä /* 20887ce4d1f2SVille Syrjälä * VLV_IIR is single buffered, and reflects the level 20897ce4d1f2SVille Syrjälä * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last. 20907ce4d1f2SVille Syrjälä */ 20917ce4d1f2SVille Syrjälä if (iir) 20927ce4d1f2SVille Syrjälä I915_WRITE(VLV_IIR, iir); 20937ce4d1f2SVille Syrjälä 2094a5e485a9SVille Syrjälä I915_WRITE(VLV_IER, ier); 2095e5328c43SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); 209643f328d7SVille Syrjälä POSTING_READ(GEN8_MASTER_IRQ); 20971ae3c34cSVille Syrjälä 2098e30e251aSVille Syrjälä gen8_gt_irq_handler(dev_priv, gt_iir); 2099e30e251aSVille Syrjälä 21001ae3c34cSVille Syrjälä if (hotplug_status) 210191d14251STvrtko Ursulin i9xx_hpd_irq_handler(dev_priv, hotplug_status); 21022ecb8ca4SVille Syrjälä 210391d14251STvrtko Ursulin valleyview_pipestat_irq_handler(dev_priv, pipe_stats); 2104579de73bSChris Wilson } while (0); 21053278f67fSVille Syrjälä 21061f814dacSImre Deak enable_rpm_wakeref_asserts(dev_priv); 21071f814dacSImre Deak 210843f328d7SVille Syrjälä return ret; 210943f328d7SVille Syrjälä } 211043f328d7SVille Syrjälä 211191d14251STvrtko Ursulin static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv, 211291d14251STvrtko Ursulin u32 hotplug_trigger, 211340e56410SVille Syrjälä const u32 hpd[HPD_NUM_PINS]) 2114776ad806SJesse Barnes { 211542db67d6SVille Syrjälä u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0; 2116776ad806SJesse Barnes 21176a39d7c9SJani Nikula /* 21186a39d7c9SJani Nikula * Somehow the PCH doesn't seem to really ack the interrupt to the CPU 21196a39d7c9SJani Nikula * unless we touch the hotplug register, even if hotplug_trigger is 21206a39d7c9SJani Nikula * zero. Not acking leads to "The master control interrupt lied (SDE)!" 21216a39d7c9SJani Nikula * errors. 21226a39d7c9SJani Nikula */ 212313cf5504SDave Airlie dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG); 21246a39d7c9SJani Nikula if (!hotplug_trigger) { 21256a39d7c9SJani Nikula u32 mask = PORTA_HOTPLUG_STATUS_MASK | 21266a39d7c9SJani Nikula PORTD_HOTPLUG_STATUS_MASK | 21276a39d7c9SJani Nikula PORTC_HOTPLUG_STATUS_MASK | 21286a39d7c9SJani Nikula PORTB_HOTPLUG_STATUS_MASK; 21296a39d7c9SJani Nikula dig_hotplug_reg &= ~mask; 21306a39d7c9SJani Nikula } 21316a39d7c9SJani Nikula 213213cf5504SDave Airlie I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg); 21336a39d7c9SJani Nikula if (!hotplug_trigger) 21346a39d7c9SJani Nikula return; 213513cf5504SDave Airlie 2136fd63e2a9SImre Deak intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger, 213740e56410SVille Syrjälä dig_hotplug_reg, hpd, 2138fd63e2a9SImre Deak pch_port_hotplug_long_detect); 213940e56410SVille Syrjälä 214091d14251STvrtko Ursulin intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 2141aaf5ec2eSSonika Jindal } 214291d131d2SDaniel Vetter 214391d14251STvrtko Ursulin static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir) 214440e56410SVille Syrjälä { 214540e56410SVille Syrjälä int pipe; 214640e56410SVille Syrjälä u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK; 214740e56410SVille Syrjälä 214891d14251STvrtko Ursulin ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ibx); 214940e56410SVille Syrjälä 2150cfc33bf7SVille Syrjälä if (pch_iir & SDE_AUDIO_POWER_MASK) { 2151cfc33bf7SVille Syrjälä int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >> 2152776ad806SJesse Barnes SDE_AUDIO_POWER_SHIFT); 2153cfc33bf7SVille Syrjälä DRM_DEBUG_DRIVER("PCH audio power change on port %d\n", 2154cfc33bf7SVille Syrjälä port_name(port)); 2155cfc33bf7SVille Syrjälä } 2156776ad806SJesse Barnes 2157ce99c256SDaniel Vetter if (pch_iir & SDE_AUX_MASK) 215891d14251STvrtko Ursulin dp_aux_irq_handler(dev_priv); 2159ce99c256SDaniel Vetter 2160776ad806SJesse Barnes if (pch_iir & SDE_GMBUS) 216191d14251STvrtko Ursulin gmbus_irq_handler(dev_priv); 2162776ad806SJesse Barnes 2163776ad806SJesse Barnes if (pch_iir & SDE_AUDIO_HDCP_MASK) 2164776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n"); 2165776ad806SJesse Barnes 2166776ad806SJesse Barnes if (pch_iir & SDE_AUDIO_TRANS_MASK) 2167776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n"); 2168776ad806SJesse Barnes 2169776ad806SJesse Barnes if (pch_iir & SDE_POISON) 2170776ad806SJesse Barnes DRM_ERROR("PCH poison interrupt\n"); 2171776ad806SJesse Barnes 21729db4a9c7SJesse Barnes if (pch_iir & SDE_FDI_MASK) 2173055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 21749db4a9c7SJesse Barnes DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", 21759db4a9c7SJesse Barnes pipe_name(pipe), 21769db4a9c7SJesse Barnes I915_READ(FDI_RX_IIR(pipe))); 2177776ad806SJesse Barnes 2178776ad806SJesse Barnes if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE)) 2179776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n"); 2180776ad806SJesse Barnes 2181776ad806SJesse Barnes if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR)) 2182776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n"); 2183776ad806SJesse Barnes 2184776ad806SJesse Barnes if (pch_iir & SDE_TRANSA_FIFO_UNDER) 2185a2196033SMatthias Kaehlcke intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A); 21868664281bSPaulo Zanoni 21878664281bSPaulo Zanoni if (pch_iir & SDE_TRANSB_FIFO_UNDER) 2188a2196033SMatthias Kaehlcke intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B); 21898664281bSPaulo Zanoni } 21908664281bSPaulo Zanoni 219191d14251STvrtko Ursulin static void ivb_err_int_handler(struct drm_i915_private *dev_priv) 21928664281bSPaulo Zanoni { 21938664281bSPaulo Zanoni u32 err_int = I915_READ(GEN7_ERR_INT); 21945a69b89fSDaniel Vetter enum pipe pipe; 21958664281bSPaulo Zanoni 2196de032bf4SPaulo Zanoni if (err_int & ERR_INT_POISON) 2197de032bf4SPaulo Zanoni DRM_ERROR("Poison interrupt\n"); 2198de032bf4SPaulo Zanoni 2199055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 22001f7247c0SDaniel Vetter if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) 22011f7247c0SDaniel Vetter intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 22028664281bSPaulo Zanoni 22035a69b89fSDaniel Vetter if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) { 220491d14251STvrtko Ursulin if (IS_IVYBRIDGE(dev_priv)) 220591d14251STvrtko Ursulin ivb_pipe_crc_irq_handler(dev_priv, pipe); 22065a69b89fSDaniel Vetter else 220791d14251STvrtko Ursulin hsw_pipe_crc_irq_handler(dev_priv, pipe); 22085a69b89fSDaniel Vetter } 22095a69b89fSDaniel Vetter } 22108bf1e9f1SShuang He 22118664281bSPaulo Zanoni I915_WRITE(GEN7_ERR_INT, err_int); 22128664281bSPaulo Zanoni } 22138664281bSPaulo Zanoni 221491d14251STvrtko Ursulin static void cpt_serr_int_handler(struct drm_i915_private *dev_priv) 22158664281bSPaulo Zanoni { 22168664281bSPaulo Zanoni u32 serr_int = I915_READ(SERR_INT); 22178664281bSPaulo Zanoni 2218de032bf4SPaulo Zanoni if (serr_int & SERR_INT_POISON) 2219de032bf4SPaulo Zanoni DRM_ERROR("PCH poison interrupt\n"); 2220de032bf4SPaulo Zanoni 22218664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN) 2222a2196033SMatthias Kaehlcke intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A); 22238664281bSPaulo Zanoni 22248664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN) 2225a2196033SMatthias Kaehlcke intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B); 22268664281bSPaulo Zanoni 22278664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN) 2228a2196033SMatthias Kaehlcke intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_C); 22298664281bSPaulo Zanoni 22308664281bSPaulo Zanoni I915_WRITE(SERR_INT, serr_int); 2231776ad806SJesse Barnes } 2232776ad806SJesse Barnes 223391d14251STvrtko Ursulin static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir) 223423e81d69SAdam Jackson { 223523e81d69SAdam Jackson int pipe; 22366dbf30ceSVille Syrjälä u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT; 2237aaf5ec2eSSonika Jindal 223891d14251STvrtko Ursulin ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_cpt); 223991d131d2SDaniel Vetter 2240cfc33bf7SVille Syrjälä if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) { 2241cfc33bf7SVille Syrjälä int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >> 224223e81d69SAdam Jackson SDE_AUDIO_POWER_SHIFT_CPT); 2243cfc33bf7SVille Syrjälä DRM_DEBUG_DRIVER("PCH audio power change on port %c\n", 2244cfc33bf7SVille Syrjälä port_name(port)); 2245cfc33bf7SVille Syrjälä } 224623e81d69SAdam Jackson 224723e81d69SAdam Jackson if (pch_iir & SDE_AUX_MASK_CPT) 224891d14251STvrtko Ursulin dp_aux_irq_handler(dev_priv); 224923e81d69SAdam Jackson 225023e81d69SAdam Jackson if (pch_iir & SDE_GMBUS_CPT) 225191d14251STvrtko Ursulin gmbus_irq_handler(dev_priv); 225223e81d69SAdam Jackson 225323e81d69SAdam Jackson if (pch_iir & SDE_AUDIO_CP_REQ_CPT) 225423e81d69SAdam Jackson DRM_DEBUG_DRIVER("Audio CP request interrupt\n"); 225523e81d69SAdam Jackson 225623e81d69SAdam Jackson if (pch_iir & SDE_AUDIO_CP_CHG_CPT) 225723e81d69SAdam Jackson DRM_DEBUG_DRIVER("Audio CP change interrupt\n"); 225823e81d69SAdam Jackson 225923e81d69SAdam Jackson if (pch_iir & SDE_FDI_MASK_CPT) 2260055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 226123e81d69SAdam Jackson DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", 226223e81d69SAdam Jackson pipe_name(pipe), 226323e81d69SAdam Jackson I915_READ(FDI_RX_IIR(pipe))); 22648664281bSPaulo Zanoni 22658664281bSPaulo Zanoni if (pch_iir & SDE_ERROR_CPT) 226691d14251STvrtko Ursulin cpt_serr_int_handler(dev_priv); 226723e81d69SAdam Jackson } 226823e81d69SAdam Jackson 226991d14251STvrtko Ursulin static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir) 22706dbf30ceSVille Syrjälä { 22716dbf30ceSVille Syrjälä u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT & 22726dbf30ceSVille Syrjälä ~SDE_PORTE_HOTPLUG_SPT; 22736dbf30ceSVille Syrjälä u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT; 22746dbf30ceSVille Syrjälä u32 pin_mask = 0, long_mask = 0; 22756dbf30ceSVille Syrjälä 22766dbf30ceSVille Syrjälä if (hotplug_trigger) { 22776dbf30ceSVille Syrjälä u32 dig_hotplug_reg; 22786dbf30ceSVille Syrjälä 22796dbf30ceSVille Syrjälä dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG); 22806dbf30ceSVille Syrjälä I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg); 22816dbf30ceSVille Syrjälä 22826dbf30ceSVille Syrjälä intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger, 22836dbf30ceSVille Syrjälä dig_hotplug_reg, hpd_spt, 228474c0b395SVille Syrjälä spt_port_hotplug_long_detect); 22856dbf30ceSVille Syrjälä } 22866dbf30ceSVille Syrjälä 22876dbf30ceSVille Syrjälä if (hotplug2_trigger) { 22886dbf30ceSVille Syrjälä u32 dig_hotplug_reg; 22896dbf30ceSVille Syrjälä 22906dbf30ceSVille Syrjälä dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2); 22916dbf30ceSVille Syrjälä I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg); 22926dbf30ceSVille Syrjälä 22936dbf30ceSVille Syrjälä intel_get_hpd_pins(&pin_mask, &long_mask, hotplug2_trigger, 22946dbf30ceSVille Syrjälä dig_hotplug_reg, hpd_spt, 22956dbf30ceSVille Syrjälä spt_port_hotplug2_long_detect); 22966dbf30ceSVille Syrjälä } 22976dbf30ceSVille Syrjälä 22986dbf30ceSVille Syrjälä if (pin_mask) 229991d14251STvrtko Ursulin intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 23006dbf30ceSVille Syrjälä 23016dbf30ceSVille Syrjälä if (pch_iir & SDE_GMBUS_CPT) 230291d14251STvrtko Ursulin gmbus_irq_handler(dev_priv); 23036dbf30ceSVille Syrjälä } 23046dbf30ceSVille Syrjälä 230591d14251STvrtko Ursulin static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv, 230691d14251STvrtko Ursulin u32 hotplug_trigger, 230740e56410SVille Syrjälä const u32 hpd[HPD_NUM_PINS]) 2308c008bc6eSPaulo Zanoni { 2309e4ce95aaSVille Syrjälä u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0; 2310e4ce95aaSVille Syrjälä 2311e4ce95aaSVille Syrjälä dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL); 2312e4ce95aaSVille Syrjälä I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg); 2313e4ce95aaSVille Syrjälä 2314e4ce95aaSVille Syrjälä intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger, 231540e56410SVille Syrjälä dig_hotplug_reg, hpd, 2316e4ce95aaSVille Syrjälä ilk_port_hotplug_long_detect); 231740e56410SVille Syrjälä 231891d14251STvrtko Ursulin intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 2319e4ce95aaSVille Syrjälä } 2320c008bc6eSPaulo Zanoni 232191d14251STvrtko Ursulin static void ilk_display_irq_handler(struct drm_i915_private *dev_priv, 232291d14251STvrtko Ursulin u32 de_iir) 232340e56410SVille Syrjälä { 232440e56410SVille Syrjälä enum pipe pipe; 232540e56410SVille Syrjälä u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG; 232640e56410SVille Syrjälä 232740e56410SVille Syrjälä if (hotplug_trigger) 232891d14251STvrtko Ursulin ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk); 232940e56410SVille Syrjälä 2330c008bc6eSPaulo Zanoni if (de_iir & DE_AUX_CHANNEL_A) 233191d14251STvrtko Ursulin dp_aux_irq_handler(dev_priv); 2332c008bc6eSPaulo Zanoni 2333c008bc6eSPaulo Zanoni if (de_iir & DE_GSE) 233491d14251STvrtko Ursulin intel_opregion_asle_intr(dev_priv); 2335c008bc6eSPaulo Zanoni 2336c008bc6eSPaulo Zanoni if (de_iir & DE_POISON) 2337c008bc6eSPaulo Zanoni DRM_ERROR("Poison interrupt\n"); 2338c008bc6eSPaulo Zanoni 2339055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 2340fd3a4024SDaniel Vetter if (de_iir & DE_PIPE_VBLANK(pipe)) 2341fd3a4024SDaniel Vetter drm_handle_vblank(&dev_priv->drm, pipe); 2342c008bc6eSPaulo Zanoni 234340da17c2SDaniel Vetter if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe)) 23441f7247c0SDaniel Vetter intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 2345c008bc6eSPaulo Zanoni 234640da17c2SDaniel Vetter if (de_iir & DE_PIPE_CRC_DONE(pipe)) 234791d14251STvrtko Ursulin i9xx_pipe_crc_irq_handler(dev_priv, pipe); 2348c008bc6eSPaulo Zanoni } 2349c008bc6eSPaulo Zanoni 2350c008bc6eSPaulo Zanoni /* check event from PCH */ 2351c008bc6eSPaulo Zanoni if (de_iir & DE_PCH_EVENT) { 2352c008bc6eSPaulo Zanoni u32 pch_iir = I915_READ(SDEIIR); 2353c008bc6eSPaulo Zanoni 235491d14251STvrtko Ursulin if (HAS_PCH_CPT(dev_priv)) 235591d14251STvrtko Ursulin cpt_irq_handler(dev_priv, pch_iir); 2356c008bc6eSPaulo Zanoni else 235791d14251STvrtko Ursulin ibx_irq_handler(dev_priv, pch_iir); 2358c008bc6eSPaulo Zanoni 2359c008bc6eSPaulo Zanoni /* should clear PCH hotplug event before clear CPU irq */ 2360c008bc6eSPaulo Zanoni I915_WRITE(SDEIIR, pch_iir); 2361c008bc6eSPaulo Zanoni } 2362c008bc6eSPaulo Zanoni 236391d14251STvrtko Ursulin if (IS_GEN5(dev_priv) && de_iir & DE_PCU_EVENT) 236491d14251STvrtko Ursulin ironlake_rps_change_irq_handler(dev_priv); 2365c008bc6eSPaulo Zanoni } 2366c008bc6eSPaulo Zanoni 236791d14251STvrtko Ursulin static void ivb_display_irq_handler(struct drm_i915_private *dev_priv, 236891d14251STvrtko Ursulin u32 de_iir) 23699719fb98SPaulo Zanoni { 237007d27e20SDamien Lespiau enum pipe pipe; 237123bb4cb5SVille Syrjälä u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB; 237223bb4cb5SVille Syrjälä 237340e56410SVille Syrjälä if (hotplug_trigger) 237491d14251STvrtko Ursulin ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb); 23759719fb98SPaulo Zanoni 23769719fb98SPaulo Zanoni if (de_iir & DE_ERR_INT_IVB) 237791d14251STvrtko Ursulin ivb_err_int_handler(dev_priv); 23789719fb98SPaulo Zanoni 23799719fb98SPaulo Zanoni if (de_iir & DE_AUX_CHANNEL_A_IVB) 238091d14251STvrtko Ursulin dp_aux_irq_handler(dev_priv); 23819719fb98SPaulo Zanoni 23829719fb98SPaulo Zanoni if (de_iir & DE_GSE_IVB) 238391d14251STvrtko Ursulin intel_opregion_asle_intr(dev_priv); 23849719fb98SPaulo Zanoni 2385055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 2386fd3a4024SDaniel Vetter if (de_iir & (DE_PIPE_VBLANK_IVB(pipe))) 2387fd3a4024SDaniel Vetter drm_handle_vblank(&dev_priv->drm, pipe); 23889719fb98SPaulo Zanoni } 23899719fb98SPaulo Zanoni 23909719fb98SPaulo Zanoni /* check event from PCH */ 239191d14251STvrtko Ursulin if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) { 23929719fb98SPaulo Zanoni u32 pch_iir = I915_READ(SDEIIR); 23939719fb98SPaulo Zanoni 239491d14251STvrtko Ursulin cpt_irq_handler(dev_priv, pch_iir); 23959719fb98SPaulo Zanoni 23969719fb98SPaulo Zanoni /* clear PCH hotplug event before clear CPU irq */ 23979719fb98SPaulo Zanoni I915_WRITE(SDEIIR, pch_iir); 23989719fb98SPaulo Zanoni } 23999719fb98SPaulo Zanoni } 24009719fb98SPaulo Zanoni 240172c90f62SOscar Mateo /* 240272c90f62SOscar Mateo * To handle irqs with the minimum potential races with fresh interrupts, we: 240372c90f62SOscar Mateo * 1 - Disable Master Interrupt Control. 240472c90f62SOscar Mateo * 2 - Find the source(s) of the interrupt. 240572c90f62SOscar Mateo * 3 - Clear the Interrupt Identity bits (IIR). 240672c90f62SOscar Mateo * 4 - Process the interrupt(s) that had bits set in the IIRs. 240772c90f62SOscar Mateo * 5 - Re-enable Master Interrupt Control. 240872c90f62SOscar Mateo */ 2409f1af8fc1SPaulo Zanoni static irqreturn_t ironlake_irq_handler(int irq, void *arg) 2410b1f14ad0SJesse Barnes { 241145a83f84SDaniel Vetter struct drm_device *dev = arg; 2412fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 2413f1af8fc1SPaulo Zanoni u32 de_iir, gt_iir, de_ier, sde_ier = 0; 24140e43406bSChris Wilson irqreturn_t ret = IRQ_NONE; 2415b1f14ad0SJesse Barnes 24162dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 24172dd2a883SImre Deak return IRQ_NONE; 24182dd2a883SImre Deak 24191f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 24201f814dacSImre Deak disable_rpm_wakeref_asserts(dev_priv); 24211f814dacSImre Deak 2422b1f14ad0SJesse Barnes /* disable master interrupt before clearing iir */ 2423b1f14ad0SJesse Barnes de_ier = I915_READ(DEIER); 2424b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL); 242523a78516SPaulo Zanoni POSTING_READ(DEIER); 24260e43406bSChris Wilson 242744498aeaSPaulo Zanoni /* Disable south interrupts. We'll only write to SDEIIR once, so further 242844498aeaSPaulo Zanoni * interrupts will will be stored on its back queue, and then we'll be 242944498aeaSPaulo Zanoni * able to process them after we restore SDEIER (as soon as we restore 243044498aeaSPaulo Zanoni * it, we'll get an interrupt if SDEIIR still has something to process 243144498aeaSPaulo Zanoni * due to its back queue). */ 243291d14251STvrtko Ursulin if (!HAS_PCH_NOP(dev_priv)) { 243344498aeaSPaulo Zanoni sde_ier = I915_READ(SDEIER); 243444498aeaSPaulo Zanoni I915_WRITE(SDEIER, 0); 243544498aeaSPaulo Zanoni POSTING_READ(SDEIER); 2436ab5c608bSBen Widawsky } 243744498aeaSPaulo Zanoni 243872c90f62SOscar Mateo /* Find, clear, then process each source of interrupt */ 243972c90f62SOscar Mateo 24400e43406bSChris Wilson gt_iir = I915_READ(GTIIR); 24410e43406bSChris Wilson if (gt_iir) { 244272c90f62SOscar Mateo I915_WRITE(GTIIR, gt_iir); 244372c90f62SOscar Mateo ret = IRQ_HANDLED; 244491d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 6) 2445261e40b8SVille Syrjälä snb_gt_irq_handler(dev_priv, gt_iir); 2446d8fc8a47SPaulo Zanoni else 2447261e40b8SVille Syrjälä ilk_gt_irq_handler(dev_priv, gt_iir); 24480e43406bSChris Wilson } 2449b1f14ad0SJesse Barnes 2450b1f14ad0SJesse Barnes de_iir = I915_READ(DEIIR); 24510e43406bSChris Wilson if (de_iir) { 245272c90f62SOscar Mateo I915_WRITE(DEIIR, de_iir); 245372c90f62SOscar Mateo ret = IRQ_HANDLED; 245491d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 7) 245591d14251STvrtko Ursulin ivb_display_irq_handler(dev_priv, de_iir); 2456f1af8fc1SPaulo Zanoni else 245791d14251STvrtko Ursulin ilk_display_irq_handler(dev_priv, de_iir); 24580e43406bSChris Wilson } 24590e43406bSChris Wilson 246091d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 6) { 2461f1af8fc1SPaulo Zanoni u32 pm_iir = I915_READ(GEN6_PMIIR); 24620e43406bSChris Wilson if (pm_iir) { 2463b1f14ad0SJesse Barnes I915_WRITE(GEN6_PMIIR, pm_iir); 24640e43406bSChris Wilson ret = IRQ_HANDLED; 246572c90f62SOscar Mateo gen6_rps_irq_handler(dev_priv, pm_iir); 24660e43406bSChris Wilson } 2467f1af8fc1SPaulo Zanoni } 2468b1f14ad0SJesse Barnes 2469b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier); 2470b1f14ad0SJesse Barnes POSTING_READ(DEIER); 247191d14251STvrtko Ursulin if (!HAS_PCH_NOP(dev_priv)) { 247244498aeaSPaulo Zanoni I915_WRITE(SDEIER, sde_ier); 247344498aeaSPaulo Zanoni POSTING_READ(SDEIER); 2474ab5c608bSBen Widawsky } 2475b1f14ad0SJesse Barnes 24761f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 24771f814dacSImre Deak enable_rpm_wakeref_asserts(dev_priv); 24781f814dacSImre Deak 2479b1f14ad0SJesse Barnes return ret; 2480b1f14ad0SJesse Barnes } 2481b1f14ad0SJesse Barnes 248291d14251STvrtko Ursulin static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv, 248391d14251STvrtko Ursulin u32 hotplug_trigger, 248440e56410SVille Syrjälä const u32 hpd[HPD_NUM_PINS]) 2485d04a492dSShashank Sharma { 2486cebd87a0SVille Syrjälä u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0; 2487d04a492dSShashank Sharma 2488a52bb15bSVille Syrjälä dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG); 2489a52bb15bSVille Syrjälä I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg); 2490d04a492dSShashank Sharma 2491cebd87a0SVille Syrjälä intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger, 249240e56410SVille Syrjälä dig_hotplug_reg, hpd, 2493cebd87a0SVille Syrjälä bxt_port_hotplug_long_detect); 249440e56410SVille Syrjälä 249591d14251STvrtko Ursulin intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 2496d04a492dSShashank Sharma } 2497d04a492dSShashank Sharma 2498f11a0f46STvrtko Ursulin static irqreturn_t 2499f11a0f46STvrtko Ursulin gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl) 2500abd58f01SBen Widawsky { 2501abd58f01SBen Widawsky irqreturn_t ret = IRQ_NONE; 2502f11a0f46STvrtko Ursulin u32 iir; 2503c42664ccSDaniel Vetter enum pipe pipe; 250488e04703SJesse Barnes 2505abd58f01SBen Widawsky if (master_ctl & GEN8_DE_MISC_IRQ) { 2506e32192e1STvrtko Ursulin iir = I915_READ(GEN8_DE_MISC_IIR); 2507e32192e1STvrtko Ursulin if (iir) { 2508e32192e1STvrtko Ursulin I915_WRITE(GEN8_DE_MISC_IIR, iir); 2509abd58f01SBen Widawsky ret = IRQ_HANDLED; 2510e32192e1STvrtko Ursulin if (iir & GEN8_DE_MISC_GSE) 251191d14251STvrtko Ursulin intel_opregion_asle_intr(dev_priv); 251238cc46d7SOscar Mateo else 251338cc46d7SOscar Mateo DRM_ERROR("Unexpected DE Misc interrupt\n"); 2514abd58f01SBen Widawsky } 251538cc46d7SOscar Mateo else 251638cc46d7SOscar Mateo DRM_ERROR("The master control interrupt lied (DE MISC)!\n"); 2517abd58f01SBen Widawsky } 2518abd58f01SBen Widawsky 25196d766f02SDaniel Vetter if (master_ctl & GEN8_DE_PORT_IRQ) { 2520e32192e1STvrtko Ursulin iir = I915_READ(GEN8_DE_PORT_IIR); 2521e32192e1STvrtko Ursulin if (iir) { 2522e32192e1STvrtko Ursulin u32 tmp_mask; 2523d04a492dSShashank Sharma bool found = false; 2524cebd87a0SVille Syrjälä 2525e32192e1STvrtko Ursulin I915_WRITE(GEN8_DE_PORT_IIR, iir); 25266d766f02SDaniel Vetter ret = IRQ_HANDLED; 252788e04703SJesse Barnes 2528e32192e1STvrtko Ursulin tmp_mask = GEN8_AUX_CHANNEL_A; 2529bca2bf2aSPandiyan, Dhinakaran if (INTEL_GEN(dev_priv) >= 9) 2530e32192e1STvrtko Ursulin tmp_mask |= GEN9_AUX_CHANNEL_B | 2531e32192e1STvrtko Ursulin GEN9_AUX_CHANNEL_C | 2532e32192e1STvrtko Ursulin GEN9_AUX_CHANNEL_D; 2533e32192e1STvrtko Ursulin 2534e32192e1STvrtko Ursulin if (iir & tmp_mask) { 253591d14251STvrtko Ursulin dp_aux_irq_handler(dev_priv); 2536d04a492dSShashank Sharma found = true; 2537d04a492dSShashank Sharma } 2538d04a492dSShashank Sharma 2539cc3f90f0SAnder Conselvan de Oliveira if (IS_GEN9_LP(dev_priv)) { 2540e32192e1STvrtko Ursulin tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK; 2541e32192e1STvrtko Ursulin if (tmp_mask) { 254291d14251STvrtko Ursulin bxt_hpd_irq_handler(dev_priv, tmp_mask, 254391d14251STvrtko Ursulin hpd_bxt); 2544d04a492dSShashank Sharma found = true; 2545d04a492dSShashank Sharma } 2546e32192e1STvrtko Ursulin } else if (IS_BROADWELL(dev_priv)) { 2547e32192e1STvrtko Ursulin tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG; 2548e32192e1STvrtko Ursulin if (tmp_mask) { 254991d14251STvrtko Ursulin ilk_hpd_irq_handler(dev_priv, 255091d14251STvrtko Ursulin tmp_mask, hpd_bdw); 2551e32192e1STvrtko Ursulin found = true; 2552e32192e1STvrtko Ursulin } 2553e32192e1STvrtko Ursulin } 2554d04a492dSShashank Sharma 2555cc3f90f0SAnder Conselvan de Oliveira if (IS_GEN9_LP(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) { 255691d14251STvrtko Ursulin gmbus_irq_handler(dev_priv); 25579e63743eSShashank Sharma found = true; 25589e63743eSShashank Sharma } 25599e63743eSShashank Sharma 2560d04a492dSShashank Sharma if (!found) 256138cc46d7SOscar Mateo DRM_ERROR("Unexpected DE Port interrupt\n"); 25626d766f02SDaniel Vetter } 256338cc46d7SOscar Mateo else 256438cc46d7SOscar Mateo DRM_ERROR("The master control interrupt lied (DE PORT)!\n"); 25656d766f02SDaniel Vetter } 25666d766f02SDaniel Vetter 2567055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 2568fd3a4024SDaniel Vetter u32 fault_errors; 2569abd58f01SBen Widawsky 2570c42664ccSDaniel Vetter if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe))) 2571c42664ccSDaniel Vetter continue; 2572c42664ccSDaniel Vetter 2573e32192e1STvrtko Ursulin iir = I915_READ(GEN8_DE_PIPE_IIR(pipe)); 2574e32192e1STvrtko Ursulin if (!iir) { 2575e32192e1STvrtko Ursulin DRM_ERROR("The master control interrupt lied (DE PIPE)!\n"); 2576e32192e1STvrtko Ursulin continue; 2577e32192e1STvrtko Ursulin } 2578770de83dSDamien Lespiau 2579e32192e1STvrtko Ursulin ret = IRQ_HANDLED; 2580e32192e1STvrtko Ursulin I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir); 2581e32192e1STvrtko Ursulin 2582fd3a4024SDaniel Vetter if (iir & GEN8_PIPE_VBLANK) 2583fd3a4024SDaniel Vetter drm_handle_vblank(&dev_priv->drm, pipe); 2584abd58f01SBen Widawsky 2585e32192e1STvrtko Ursulin if (iir & GEN8_PIPE_CDCLK_CRC_DONE) 258691d14251STvrtko Ursulin hsw_pipe_crc_irq_handler(dev_priv, pipe); 25870fbe7870SDaniel Vetter 2588e32192e1STvrtko Ursulin if (iir & GEN8_PIPE_FIFO_UNDERRUN) 2589e32192e1STvrtko Ursulin intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 259038d83c96SDaniel Vetter 2591e32192e1STvrtko Ursulin fault_errors = iir; 2592bca2bf2aSPandiyan, Dhinakaran if (INTEL_GEN(dev_priv) >= 9) 2593e32192e1STvrtko Ursulin fault_errors &= GEN9_DE_PIPE_IRQ_FAULT_ERRORS; 2594770de83dSDamien Lespiau else 2595e32192e1STvrtko Ursulin fault_errors &= GEN8_DE_PIPE_IRQ_FAULT_ERRORS; 2596770de83dSDamien Lespiau 2597770de83dSDamien Lespiau if (fault_errors) 25981353ec38STvrtko Ursulin DRM_ERROR("Fault errors on pipe %c: 0x%08x\n", 259930100f2bSDaniel Vetter pipe_name(pipe), 2600e32192e1STvrtko Ursulin fault_errors); 2601abd58f01SBen Widawsky } 2602abd58f01SBen Widawsky 260391d14251STvrtko Ursulin if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) && 2604266ea3d9SShashank Sharma master_ctl & GEN8_DE_PCH_IRQ) { 260592d03a80SDaniel Vetter /* 260692d03a80SDaniel Vetter * FIXME(BDW): Assume for now that the new interrupt handling 260792d03a80SDaniel Vetter * scheme also closed the SDE interrupt handling race we've seen 260892d03a80SDaniel Vetter * on older pch-split platforms. But this needs testing. 260992d03a80SDaniel Vetter */ 2610e32192e1STvrtko Ursulin iir = I915_READ(SDEIIR); 2611e32192e1STvrtko Ursulin if (iir) { 2612e32192e1STvrtko Ursulin I915_WRITE(SDEIIR, iir); 261392d03a80SDaniel Vetter ret = IRQ_HANDLED; 26146dbf30ceSVille Syrjälä 26157b22b8c4SRodrigo Vivi if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv) || 26167b22b8c4SRodrigo Vivi HAS_PCH_CNP(dev_priv)) 261791d14251STvrtko Ursulin spt_irq_handler(dev_priv, iir); 26186dbf30ceSVille Syrjälä else 261991d14251STvrtko Ursulin cpt_irq_handler(dev_priv, iir); 26202dfb0b81SJani Nikula } else { 26212dfb0b81SJani Nikula /* 26222dfb0b81SJani Nikula * Like on previous PCH there seems to be something 26232dfb0b81SJani Nikula * fishy going on with forwarding PCH interrupts. 26242dfb0b81SJani Nikula */ 26252dfb0b81SJani Nikula DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n"); 26262dfb0b81SJani Nikula } 262792d03a80SDaniel Vetter } 262892d03a80SDaniel Vetter 2629f11a0f46STvrtko Ursulin return ret; 2630f11a0f46STvrtko Ursulin } 2631f11a0f46STvrtko Ursulin 2632f11a0f46STvrtko Ursulin static irqreturn_t gen8_irq_handler(int irq, void *arg) 2633f11a0f46STvrtko Ursulin { 2634f11a0f46STvrtko Ursulin struct drm_device *dev = arg; 2635fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 2636f11a0f46STvrtko Ursulin u32 master_ctl; 2637e30e251aSVille Syrjälä u32 gt_iir[4] = {}; 2638f11a0f46STvrtko Ursulin irqreturn_t ret; 2639f11a0f46STvrtko Ursulin 2640f11a0f46STvrtko Ursulin if (!intel_irqs_enabled(dev_priv)) 2641f11a0f46STvrtko Ursulin return IRQ_NONE; 2642f11a0f46STvrtko Ursulin 2643f11a0f46STvrtko Ursulin master_ctl = I915_READ_FW(GEN8_MASTER_IRQ); 2644f11a0f46STvrtko Ursulin master_ctl &= ~GEN8_MASTER_IRQ_CONTROL; 2645f11a0f46STvrtko Ursulin if (!master_ctl) 2646f11a0f46STvrtko Ursulin return IRQ_NONE; 2647f11a0f46STvrtko Ursulin 2648f11a0f46STvrtko Ursulin I915_WRITE_FW(GEN8_MASTER_IRQ, 0); 2649f11a0f46STvrtko Ursulin 2650f11a0f46STvrtko Ursulin /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 2651f11a0f46STvrtko Ursulin disable_rpm_wakeref_asserts(dev_priv); 2652f11a0f46STvrtko Ursulin 2653f11a0f46STvrtko Ursulin /* Find, clear, then process each source of interrupt */ 2654e30e251aSVille Syrjälä ret = gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir); 2655e30e251aSVille Syrjälä gen8_gt_irq_handler(dev_priv, gt_iir); 2656f11a0f46STvrtko Ursulin ret |= gen8_de_irq_handler(dev_priv, master_ctl); 2657f11a0f46STvrtko Ursulin 2658cb0d205eSChris Wilson I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); 2659cb0d205eSChris Wilson POSTING_READ_FW(GEN8_MASTER_IRQ); 2660abd58f01SBen Widawsky 26611f814dacSImre Deak enable_rpm_wakeref_asserts(dev_priv); 26621f814dacSImre Deak 2663abd58f01SBen Widawsky return ret; 2664abd58f01SBen Widawsky } 2665abd58f01SBen Widawsky 266636703e79SChris Wilson struct wedge_me { 266736703e79SChris Wilson struct delayed_work work; 266836703e79SChris Wilson struct drm_i915_private *i915; 266936703e79SChris Wilson const char *name; 267036703e79SChris Wilson }; 267136703e79SChris Wilson 267236703e79SChris Wilson static void wedge_me(struct work_struct *work) 267336703e79SChris Wilson { 267436703e79SChris Wilson struct wedge_me *w = container_of(work, typeof(*w), work.work); 267536703e79SChris Wilson 267636703e79SChris Wilson dev_err(w->i915->drm.dev, 267736703e79SChris Wilson "%s timed out, cancelling all in-flight rendering.\n", 267836703e79SChris Wilson w->name); 267936703e79SChris Wilson i915_gem_set_wedged(w->i915); 268036703e79SChris Wilson } 268136703e79SChris Wilson 268236703e79SChris Wilson static void __init_wedge(struct wedge_me *w, 268336703e79SChris Wilson struct drm_i915_private *i915, 268436703e79SChris Wilson long timeout, 268536703e79SChris Wilson const char *name) 268636703e79SChris Wilson { 268736703e79SChris Wilson w->i915 = i915; 268836703e79SChris Wilson w->name = name; 268936703e79SChris Wilson 269036703e79SChris Wilson INIT_DELAYED_WORK_ONSTACK(&w->work, wedge_me); 269136703e79SChris Wilson schedule_delayed_work(&w->work, timeout); 269236703e79SChris Wilson } 269336703e79SChris Wilson 269436703e79SChris Wilson static void __fini_wedge(struct wedge_me *w) 269536703e79SChris Wilson { 269636703e79SChris Wilson cancel_delayed_work_sync(&w->work); 269736703e79SChris Wilson destroy_delayed_work_on_stack(&w->work); 269836703e79SChris Wilson w->i915 = NULL; 269936703e79SChris Wilson } 270036703e79SChris Wilson 270136703e79SChris Wilson #define i915_wedge_on_timeout(W, DEV, TIMEOUT) \ 270236703e79SChris Wilson for (__init_wedge((W), (DEV), (TIMEOUT), __func__); \ 270336703e79SChris Wilson (W)->i915; \ 270436703e79SChris Wilson __fini_wedge((W))) 270536703e79SChris Wilson 27068a905236SJesse Barnes /** 2707d5367307SChris Wilson * i915_reset_device - do process context error handling work 270814bb2c11STvrtko Ursulin * @dev_priv: i915 device private 27098a905236SJesse Barnes * 27108a905236SJesse Barnes * Fire an error uevent so userspace can see that a hang or error 27118a905236SJesse Barnes * was detected. 27128a905236SJesse Barnes */ 2713d5367307SChris Wilson static void i915_reset_device(struct drm_i915_private *dev_priv) 27148a905236SJesse Barnes { 271591c8a326SChris Wilson struct kobject *kobj = &dev_priv->drm.primary->kdev->kobj; 2716cce723edSBen Widawsky char *error_event[] = { I915_ERROR_UEVENT "=1", NULL }; 2717cce723edSBen Widawsky char *reset_event[] = { I915_RESET_UEVENT "=1", NULL }; 2718cce723edSBen Widawsky char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL }; 271936703e79SChris Wilson struct wedge_me w; 27208a905236SJesse Barnes 2721c033666aSChris Wilson kobject_uevent_env(kobj, KOBJ_CHANGE, error_event); 27228a905236SJesse Barnes 272344d98a61SZhao Yakui DRM_DEBUG_DRIVER("resetting chip\n"); 2724c033666aSChris Wilson kobject_uevent_env(kobj, KOBJ_CHANGE, reset_event); 27251f83fee0SDaniel Vetter 272636703e79SChris Wilson /* Use a watchdog to ensure that our reset completes */ 272736703e79SChris Wilson i915_wedge_on_timeout(&w, dev_priv, 5*HZ) { 2728c033666aSChris Wilson intel_prepare_reset(dev_priv); 27297514747dSVille Syrjälä 273036703e79SChris Wilson /* Signal that locked waiters should reset the GPU */ 27318c185ecaSChris Wilson set_bit(I915_RESET_HANDOFF, &dev_priv->gpu_error.flags); 27328c185ecaSChris Wilson wake_up_all(&dev_priv->gpu_error.wait_queue); 27338c185ecaSChris Wilson 273436703e79SChris Wilson /* Wait for anyone holding the lock to wakeup, without 273536703e79SChris Wilson * blocking indefinitely on struct_mutex. 273617e1df07SDaniel Vetter */ 273736703e79SChris Wilson do { 2738780f262aSChris Wilson if (mutex_trylock(&dev_priv->drm.struct_mutex)) { 2739535275d3SChris Wilson i915_reset(dev_priv, 0); 2740221fe799SChris Wilson mutex_unlock(&dev_priv->drm.struct_mutex); 2741780f262aSChris Wilson } 2742780f262aSChris Wilson } while (wait_on_bit_timeout(&dev_priv->gpu_error.flags, 27438c185ecaSChris Wilson I915_RESET_HANDOFF, 2744780f262aSChris Wilson TASK_UNINTERRUPTIBLE, 274536703e79SChris Wilson 1)); 2746f69061beSDaniel Vetter 2747c033666aSChris Wilson intel_finish_reset(dev_priv); 274836703e79SChris Wilson } 2749f454c694SImre Deak 2750780f262aSChris Wilson if (!test_bit(I915_WEDGED, &dev_priv->gpu_error.flags)) 2751c033666aSChris Wilson kobject_uevent_env(kobj, 2752f69061beSDaniel Vetter KOBJ_CHANGE, reset_done_event); 2753f316a42cSBen Gamari } 27548a905236SJesse Barnes 2755eaa14c24SChris Wilson static void i915_clear_error_registers(struct drm_i915_private *dev_priv) 2756c0e09200SDave Airlie { 2757eaa14c24SChris Wilson u32 eir; 275863eeaf38SJesse Barnes 2759eaa14c24SChris Wilson if (!IS_GEN2(dev_priv)) 2760eaa14c24SChris Wilson I915_WRITE(PGTBL_ER, I915_READ(PGTBL_ER)); 276163eeaf38SJesse Barnes 2762eaa14c24SChris Wilson if (INTEL_GEN(dev_priv) < 4) 2763eaa14c24SChris Wilson I915_WRITE(IPEIR, I915_READ(IPEIR)); 2764eaa14c24SChris Wilson else 2765eaa14c24SChris Wilson I915_WRITE(IPEIR_I965, I915_READ(IPEIR_I965)); 27668a905236SJesse Barnes 2767eaa14c24SChris Wilson I915_WRITE(EIR, I915_READ(EIR)); 276863eeaf38SJesse Barnes eir = I915_READ(EIR); 276963eeaf38SJesse Barnes if (eir) { 277063eeaf38SJesse Barnes /* 277163eeaf38SJesse Barnes * some errors might have become stuck, 277263eeaf38SJesse Barnes * mask them. 277363eeaf38SJesse Barnes */ 2774eaa14c24SChris Wilson DRM_DEBUG_DRIVER("EIR stuck: 0x%08x, masking\n", eir); 277563eeaf38SJesse Barnes I915_WRITE(EMR, I915_READ(EMR) | eir); 277663eeaf38SJesse Barnes I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 277763eeaf38SJesse Barnes } 277835aed2e6SChris Wilson } 277935aed2e6SChris Wilson 278035aed2e6SChris Wilson /** 2781b8d24a06SMika Kuoppala * i915_handle_error - handle a gpu error 278214bb2c11STvrtko Ursulin * @dev_priv: i915 device private 278314b730fcSarun.siluvery@linux.intel.com * @engine_mask: mask representing engines that are hung 278487c390b6SMichel Thierry * @fmt: Error message format string 278587c390b6SMichel Thierry * 2786aafd8581SJavier Martinez Canillas * Do some basic checking of register state at error time and 278735aed2e6SChris Wilson * dump it to the syslog. Also call i915_capture_error_state() to make 278835aed2e6SChris Wilson * sure we get a record and make it available in debugfs. Fire a uevent 278935aed2e6SChris Wilson * so userspace knows something bad happened (should trigger collection 279035aed2e6SChris Wilson * of a ring dump etc.). 279135aed2e6SChris Wilson */ 2792c033666aSChris Wilson void i915_handle_error(struct drm_i915_private *dev_priv, 2793c033666aSChris Wilson u32 engine_mask, 279458174462SMika Kuoppala const char *fmt, ...) 279535aed2e6SChris Wilson { 2796142bc7d9SMichel Thierry struct intel_engine_cs *engine; 2797142bc7d9SMichel Thierry unsigned int tmp; 279858174462SMika Kuoppala va_list args; 279958174462SMika Kuoppala char error_msg[80]; 280035aed2e6SChris Wilson 280158174462SMika Kuoppala va_start(args, fmt); 280258174462SMika Kuoppala vscnprintf(error_msg, sizeof(error_msg), fmt, args); 280358174462SMika Kuoppala va_end(args); 280458174462SMika Kuoppala 28051604a86dSChris Wilson /* 28061604a86dSChris Wilson * In most cases it's guaranteed that we get here with an RPM 28071604a86dSChris Wilson * reference held, for example because there is a pending GPU 28081604a86dSChris Wilson * request that won't finish until the reset is done. This 28091604a86dSChris Wilson * isn't the case at least when we get here by doing a 28101604a86dSChris Wilson * simulated reset via debugfs, so get an RPM reference. 28111604a86dSChris Wilson */ 28121604a86dSChris Wilson intel_runtime_pm_get(dev_priv); 28131604a86dSChris Wilson 2814c033666aSChris Wilson i915_capture_error_state(dev_priv, engine_mask, error_msg); 2815eaa14c24SChris Wilson i915_clear_error_registers(dev_priv); 28168a905236SJesse Barnes 2817142bc7d9SMichel Thierry /* 2818142bc7d9SMichel Thierry * Try engine reset when available. We fall back to full reset if 2819142bc7d9SMichel Thierry * single reset fails. 2820142bc7d9SMichel Thierry */ 2821142bc7d9SMichel Thierry if (intel_has_reset_engine(dev_priv)) { 2822142bc7d9SMichel Thierry for_each_engine_masked(engine, dev_priv, engine_mask, tmp) { 28239db529aaSDaniel Vetter BUILD_BUG_ON(I915_RESET_MODESET >= I915_RESET_ENGINE); 2824142bc7d9SMichel Thierry if (test_and_set_bit(I915_RESET_ENGINE + engine->id, 2825142bc7d9SMichel Thierry &dev_priv->gpu_error.flags)) 2826142bc7d9SMichel Thierry continue; 2827142bc7d9SMichel Thierry 2828535275d3SChris Wilson if (i915_reset_engine(engine, 0) == 0) 2829142bc7d9SMichel Thierry engine_mask &= ~intel_engine_flag(engine); 2830142bc7d9SMichel Thierry 2831142bc7d9SMichel Thierry clear_bit(I915_RESET_ENGINE + engine->id, 2832142bc7d9SMichel Thierry &dev_priv->gpu_error.flags); 2833142bc7d9SMichel Thierry wake_up_bit(&dev_priv->gpu_error.flags, 2834142bc7d9SMichel Thierry I915_RESET_ENGINE + engine->id); 2835142bc7d9SMichel Thierry } 2836142bc7d9SMichel Thierry } 2837142bc7d9SMichel Thierry 28388af29b0cSChris Wilson if (!engine_mask) 28391604a86dSChris Wilson goto out; 28408af29b0cSChris Wilson 2841142bc7d9SMichel Thierry /* Full reset needs the mutex, stop any other user trying to do so. */ 2842d5367307SChris Wilson if (test_and_set_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags)) { 2843d5367307SChris Wilson wait_event(dev_priv->gpu_error.reset_queue, 2844d5367307SChris Wilson !test_bit(I915_RESET_BACKOFF, 2845d5367307SChris Wilson &dev_priv->gpu_error.flags)); 28461604a86dSChris Wilson goto out; 2847d5367307SChris Wilson } 2848ba1234d1SBen Gamari 2849142bc7d9SMichel Thierry /* Prevent any other reset-engine attempt. */ 2850142bc7d9SMichel Thierry for_each_engine(engine, dev_priv, tmp) { 2851142bc7d9SMichel Thierry while (test_and_set_bit(I915_RESET_ENGINE + engine->id, 2852142bc7d9SMichel Thierry &dev_priv->gpu_error.flags)) 2853142bc7d9SMichel Thierry wait_on_bit(&dev_priv->gpu_error.flags, 2854142bc7d9SMichel Thierry I915_RESET_ENGINE + engine->id, 2855142bc7d9SMichel Thierry TASK_UNINTERRUPTIBLE); 2856142bc7d9SMichel Thierry } 2857142bc7d9SMichel Thierry 2858d5367307SChris Wilson i915_reset_device(dev_priv); 2859d5367307SChris Wilson 2860142bc7d9SMichel Thierry for_each_engine(engine, dev_priv, tmp) { 2861142bc7d9SMichel Thierry clear_bit(I915_RESET_ENGINE + engine->id, 2862142bc7d9SMichel Thierry &dev_priv->gpu_error.flags); 2863142bc7d9SMichel Thierry } 2864142bc7d9SMichel Thierry 2865d5367307SChris Wilson clear_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags); 2866d5367307SChris Wilson wake_up_all(&dev_priv->gpu_error.reset_queue); 28671604a86dSChris Wilson 28681604a86dSChris Wilson out: 28691604a86dSChris Wilson intel_runtime_pm_put(dev_priv); 28708a905236SJesse Barnes } 28718a905236SJesse Barnes 287242f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 287342f52ef8SKeith Packard * we use as a pipe index 287442f52ef8SKeith Packard */ 287586e83e35SChris Wilson static int i8xx_enable_vblank(struct drm_device *dev, unsigned int pipe) 28760a3e67a4SJesse Barnes { 2877fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 2878e9d21d7fSKeith Packard unsigned long irqflags; 287971e0ffa5SJesse Barnes 28801ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 288186e83e35SChris Wilson i915_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS); 288286e83e35SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 288386e83e35SChris Wilson 288486e83e35SChris Wilson return 0; 288586e83e35SChris Wilson } 288686e83e35SChris Wilson 288786e83e35SChris Wilson static int i965_enable_vblank(struct drm_device *dev, unsigned int pipe) 288886e83e35SChris Wilson { 288986e83e35SChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 289086e83e35SChris Wilson unsigned long irqflags; 289186e83e35SChris Wilson 289286e83e35SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 28937c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 2894755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 28951ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 28968692d00eSChris Wilson 28970a3e67a4SJesse Barnes return 0; 28980a3e67a4SJesse Barnes } 28990a3e67a4SJesse Barnes 290088e72717SThierry Reding static int ironlake_enable_vblank(struct drm_device *dev, unsigned int pipe) 2901f796cf8fSJesse Barnes { 2902fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 2903f796cf8fSJesse Barnes unsigned long irqflags; 290455b8f2a7STvrtko Ursulin uint32_t bit = INTEL_GEN(dev_priv) >= 7 ? 290586e83e35SChris Wilson DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe); 2906f796cf8fSJesse Barnes 2907f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2908fbdedaeaSVille Syrjälä ilk_enable_display_irq(dev_priv, bit); 2909b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2910b1f14ad0SJesse Barnes 2911b1f14ad0SJesse Barnes return 0; 2912b1f14ad0SJesse Barnes } 2913b1f14ad0SJesse Barnes 291488e72717SThierry Reding static int gen8_enable_vblank(struct drm_device *dev, unsigned int pipe) 2915abd58f01SBen Widawsky { 2916fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 2917abd58f01SBen Widawsky unsigned long irqflags; 2918abd58f01SBen Widawsky 2919abd58f01SBen Widawsky spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2920013d3752SVille Syrjälä bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK); 2921abd58f01SBen Widawsky spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2922013d3752SVille Syrjälä 2923abd58f01SBen Widawsky return 0; 2924abd58f01SBen Widawsky } 2925abd58f01SBen Widawsky 292642f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 292742f52ef8SKeith Packard * we use as a pipe index 292842f52ef8SKeith Packard */ 292986e83e35SChris Wilson static void i8xx_disable_vblank(struct drm_device *dev, unsigned int pipe) 293086e83e35SChris Wilson { 293186e83e35SChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 293286e83e35SChris Wilson unsigned long irqflags; 293386e83e35SChris Wilson 293486e83e35SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 293586e83e35SChris Wilson i915_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS); 293686e83e35SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 293786e83e35SChris Wilson } 293886e83e35SChris Wilson 293986e83e35SChris Wilson static void i965_disable_vblank(struct drm_device *dev, unsigned int pipe) 29400a3e67a4SJesse Barnes { 2941fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 2942e9d21d7fSKeith Packard unsigned long irqflags; 29430a3e67a4SJesse Barnes 29441ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 29457c463586SKeith Packard i915_disable_pipestat(dev_priv, pipe, 2946755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 29471ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 29480a3e67a4SJesse Barnes } 29490a3e67a4SJesse Barnes 295088e72717SThierry Reding static void ironlake_disable_vblank(struct drm_device *dev, unsigned int pipe) 2951f796cf8fSJesse Barnes { 2952fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 2953f796cf8fSJesse Barnes unsigned long irqflags; 295455b8f2a7STvrtko Ursulin uint32_t bit = INTEL_GEN(dev_priv) >= 7 ? 295586e83e35SChris Wilson DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe); 2956f796cf8fSJesse Barnes 2957f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2958fbdedaeaSVille Syrjälä ilk_disable_display_irq(dev_priv, bit); 2959b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2960b1f14ad0SJesse Barnes } 2961b1f14ad0SJesse Barnes 296288e72717SThierry Reding static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe) 2963abd58f01SBen Widawsky { 2964fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 2965abd58f01SBen Widawsky unsigned long irqflags; 2966abd58f01SBen Widawsky 2967abd58f01SBen Widawsky spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2968013d3752SVille Syrjälä bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK); 2969abd58f01SBen Widawsky spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2970abd58f01SBen Widawsky } 2971abd58f01SBen Widawsky 2972b243f530STvrtko Ursulin static void ibx_irq_reset(struct drm_i915_private *dev_priv) 297391738a95SPaulo Zanoni { 29746e266956STvrtko Ursulin if (HAS_PCH_NOP(dev_priv)) 297591738a95SPaulo Zanoni return; 297691738a95SPaulo Zanoni 29773488d4ebSVille Syrjälä GEN3_IRQ_RESET(SDE); 2978105b122eSPaulo Zanoni 29796e266956STvrtko Ursulin if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv)) 2980105b122eSPaulo Zanoni I915_WRITE(SERR_INT, 0xffffffff); 2981622364b6SPaulo Zanoni } 2982105b122eSPaulo Zanoni 298391738a95SPaulo Zanoni /* 2984622364b6SPaulo Zanoni * SDEIER is also touched by the interrupt handler to work around missed PCH 2985622364b6SPaulo Zanoni * interrupts. Hence we can't update it after the interrupt handler is enabled - 2986622364b6SPaulo Zanoni * instead we unconditionally enable all PCH interrupt sources here, but then 2987622364b6SPaulo Zanoni * only unmask them as needed with SDEIMR. 2988622364b6SPaulo Zanoni * 2989622364b6SPaulo Zanoni * This function needs to be called before interrupts are enabled. 299091738a95SPaulo Zanoni */ 2991622364b6SPaulo Zanoni static void ibx_irq_pre_postinstall(struct drm_device *dev) 2992622364b6SPaulo Zanoni { 2993fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 2994622364b6SPaulo Zanoni 29956e266956STvrtko Ursulin if (HAS_PCH_NOP(dev_priv)) 2996622364b6SPaulo Zanoni return; 2997622364b6SPaulo Zanoni 2998622364b6SPaulo Zanoni WARN_ON(I915_READ(SDEIER) != 0); 299991738a95SPaulo Zanoni I915_WRITE(SDEIER, 0xffffffff); 300091738a95SPaulo Zanoni POSTING_READ(SDEIER); 300191738a95SPaulo Zanoni } 300291738a95SPaulo Zanoni 3003b243f530STvrtko Ursulin static void gen5_gt_irq_reset(struct drm_i915_private *dev_priv) 3004d18ea1b5SDaniel Vetter { 30053488d4ebSVille Syrjälä GEN3_IRQ_RESET(GT); 3006b243f530STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 6) 30073488d4ebSVille Syrjälä GEN3_IRQ_RESET(GEN6_PM); 3008d18ea1b5SDaniel Vetter } 3009d18ea1b5SDaniel Vetter 301070591a41SVille Syrjälä static void vlv_display_irq_reset(struct drm_i915_private *dev_priv) 301170591a41SVille Syrjälä { 301271b8b41dSVille Syrjälä if (IS_CHERRYVIEW(dev_priv)) 301371b8b41dSVille Syrjälä I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV); 301471b8b41dSVille Syrjälä else 301571b8b41dSVille Syrjälä I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK); 301671b8b41dSVille Syrjälä 3017ad22d106SVille Syrjälä i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0); 301870591a41SVille Syrjälä I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 301970591a41SVille Syrjälä 302044d9241eSVille Syrjälä i9xx_pipestat_irq_reset(dev_priv); 302170591a41SVille Syrjälä 30223488d4ebSVille Syrjälä GEN3_IRQ_RESET(VLV_); 3023ad22d106SVille Syrjälä dev_priv->irq_mask = ~0; 302470591a41SVille Syrjälä } 302570591a41SVille Syrjälä 30268bb61306SVille Syrjälä static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv) 30278bb61306SVille Syrjälä { 30288bb61306SVille Syrjälä u32 pipestat_mask; 30299ab981f2SVille Syrjälä u32 enable_mask; 30308bb61306SVille Syrjälä enum pipe pipe; 30318bb61306SVille Syrjälä 3032842ebf7aSVille Syrjälä pipestat_mask = PIPE_CRC_DONE_INTERRUPT_STATUS; 30338bb61306SVille Syrjälä 30348bb61306SVille Syrjälä i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS); 30358bb61306SVille Syrjälä for_each_pipe(dev_priv, pipe) 30368bb61306SVille Syrjälä i915_enable_pipestat(dev_priv, pipe, pipestat_mask); 30378bb61306SVille Syrjälä 30389ab981f2SVille Syrjälä enable_mask = I915_DISPLAY_PORT_INTERRUPT | 30398bb61306SVille Syrjälä I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3040ebf5f921SVille Syrjälä I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3041ebf5f921SVille Syrjälä I915_LPE_PIPE_A_INTERRUPT | 3042ebf5f921SVille Syrjälä I915_LPE_PIPE_B_INTERRUPT; 3043ebf5f921SVille Syrjälä 30448bb61306SVille Syrjälä if (IS_CHERRYVIEW(dev_priv)) 3045ebf5f921SVille Syrjälä enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT | 3046ebf5f921SVille Syrjälä I915_LPE_PIPE_C_INTERRUPT; 30476b7eafc1SVille Syrjälä 30486b7eafc1SVille Syrjälä WARN_ON(dev_priv->irq_mask != ~0); 30496b7eafc1SVille Syrjälä 30509ab981f2SVille Syrjälä dev_priv->irq_mask = ~enable_mask; 30518bb61306SVille Syrjälä 30523488d4ebSVille Syrjälä GEN3_IRQ_INIT(VLV_, dev_priv->irq_mask, enable_mask); 30538bb61306SVille Syrjälä } 30548bb61306SVille Syrjälä 30558bb61306SVille Syrjälä /* drm_dma.h hooks 30568bb61306SVille Syrjälä */ 30578bb61306SVille Syrjälä static void ironlake_irq_reset(struct drm_device *dev) 30588bb61306SVille Syrjälä { 3059fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 30608bb61306SVille Syrjälä 3061d420a50cSVille Syrjälä if (IS_GEN5(dev_priv)) 30628bb61306SVille Syrjälä I915_WRITE(HWSTAM, 0xffffffff); 30638bb61306SVille Syrjälä 30643488d4ebSVille Syrjälä GEN3_IRQ_RESET(DE); 30655db94019STvrtko Ursulin if (IS_GEN7(dev_priv)) 30668bb61306SVille Syrjälä I915_WRITE(GEN7_ERR_INT, 0xffffffff); 30678bb61306SVille Syrjälä 3068b243f530STvrtko Ursulin gen5_gt_irq_reset(dev_priv); 30698bb61306SVille Syrjälä 3070b243f530STvrtko Ursulin ibx_irq_reset(dev_priv); 30718bb61306SVille Syrjälä } 30728bb61306SVille Syrjälä 3073*6bcdb1c8SVille Syrjälä static void valleyview_irq_reset(struct drm_device *dev) 30747e231dbeSJesse Barnes { 3075fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 30767e231dbeSJesse Barnes 307734c7b8a7SVille Syrjälä I915_WRITE(VLV_MASTER_IER, 0); 307834c7b8a7SVille Syrjälä POSTING_READ(VLV_MASTER_IER); 307934c7b8a7SVille Syrjälä 3080b243f530STvrtko Ursulin gen5_gt_irq_reset(dev_priv); 30817e231dbeSJesse Barnes 3082ad22d106SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 30839918271eSVille Syrjälä if (dev_priv->display_irqs_enabled) 308470591a41SVille Syrjälä vlv_display_irq_reset(dev_priv); 3085ad22d106SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 30867e231dbeSJesse Barnes } 30877e231dbeSJesse Barnes 3088d6e3cca3SDaniel Vetter static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv) 3089d6e3cca3SDaniel Vetter { 3090d6e3cca3SDaniel Vetter GEN8_IRQ_RESET_NDX(GT, 0); 3091d6e3cca3SDaniel Vetter GEN8_IRQ_RESET_NDX(GT, 1); 3092d6e3cca3SDaniel Vetter GEN8_IRQ_RESET_NDX(GT, 2); 3093d6e3cca3SDaniel Vetter GEN8_IRQ_RESET_NDX(GT, 3); 3094d6e3cca3SDaniel Vetter } 3095d6e3cca3SDaniel Vetter 3096823f6b38SPaulo Zanoni static void gen8_irq_reset(struct drm_device *dev) 3097abd58f01SBen Widawsky { 3098fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 3099abd58f01SBen Widawsky int pipe; 3100abd58f01SBen Widawsky 3101abd58f01SBen Widawsky I915_WRITE(GEN8_MASTER_IRQ, 0); 3102abd58f01SBen Widawsky POSTING_READ(GEN8_MASTER_IRQ); 3103abd58f01SBen Widawsky 3104d6e3cca3SDaniel Vetter gen8_gt_irq_reset(dev_priv); 3105abd58f01SBen Widawsky 3106055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 3107f458ebbcSDaniel Vetter if (intel_display_power_is_enabled(dev_priv, 3108813bde43SPaulo Zanoni POWER_DOMAIN_PIPE(pipe))) 3109f86f3fb0SPaulo Zanoni GEN8_IRQ_RESET_NDX(DE_PIPE, pipe); 3110abd58f01SBen Widawsky 31113488d4ebSVille Syrjälä GEN3_IRQ_RESET(GEN8_DE_PORT_); 31123488d4ebSVille Syrjälä GEN3_IRQ_RESET(GEN8_DE_MISC_); 31133488d4ebSVille Syrjälä GEN3_IRQ_RESET(GEN8_PCU_); 3114abd58f01SBen Widawsky 31156e266956STvrtko Ursulin if (HAS_PCH_SPLIT(dev_priv)) 3116b243f530STvrtko Ursulin ibx_irq_reset(dev_priv); 3117abd58f01SBen Widawsky } 3118abd58f01SBen Widawsky 31194c6c03beSDamien Lespiau void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv, 3120001bd2cbSImre Deak u8 pipe_mask) 3121d49bdb0eSPaulo Zanoni { 31221180e206SPaulo Zanoni uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN; 31236831f3e3SVille Syrjälä enum pipe pipe; 3124d49bdb0eSPaulo Zanoni 312513321786SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 31266831f3e3SVille Syrjälä for_each_pipe_masked(dev_priv, pipe, pipe_mask) 31276831f3e3SVille Syrjälä GEN8_IRQ_INIT_NDX(DE_PIPE, pipe, 31286831f3e3SVille Syrjälä dev_priv->de_irq_mask[pipe], 31296831f3e3SVille Syrjälä ~dev_priv->de_irq_mask[pipe] | extra_ier); 313013321786SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 3131d49bdb0eSPaulo Zanoni } 3132d49bdb0eSPaulo Zanoni 3133aae8ba84SVille Syrjälä void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv, 3134001bd2cbSImre Deak u8 pipe_mask) 3135aae8ba84SVille Syrjälä { 31366831f3e3SVille Syrjälä enum pipe pipe; 31376831f3e3SVille Syrjälä 3138aae8ba84SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 31396831f3e3SVille Syrjälä for_each_pipe_masked(dev_priv, pipe, pipe_mask) 31406831f3e3SVille Syrjälä GEN8_IRQ_RESET_NDX(DE_PIPE, pipe); 3141aae8ba84SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 3142aae8ba84SVille Syrjälä 3143aae8ba84SVille Syrjälä /* make sure we're done processing display irqs */ 314491c8a326SChris Wilson synchronize_irq(dev_priv->drm.irq); 3145aae8ba84SVille Syrjälä } 3146aae8ba84SVille Syrjälä 3147*6bcdb1c8SVille Syrjälä static void cherryview_irq_reset(struct drm_device *dev) 314843f328d7SVille Syrjälä { 3149fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 315043f328d7SVille Syrjälä 315143f328d7SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, 0); 315243f328d7SVille Syrjälä POSTING_READ(GEN8_MASTER_IRQ); 315343f328d7SVille Syrjälä 3154d6e3cca3SDaniel Vetter gen8_gt_irq_reset(dev_priv); 315543f328d7SVille Syrjälä 31563488d4ebSVille Syrjälä GEN3_IRQ_RESET(GEN8_PCU_); 315743f328d7SVille Syrjälä 3158ad22d106SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 31599918271eSVille Syrjälä if (dev_priv->display_irqs_enabled) 316070591a41SVille Syrjälä vlv_display_irq_reset(dev_priv); 3161ad22d106SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 316243f328d7SVille Syrjälä } 316343f328d7SVille Syrjälä 316491d14251STvrtko Ursulin static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv, 316587a02106SVille Syrjälä const u32 hpd[HPD_NUM_PINS]) 316687a02106SVille Syrjälä { 316787a02106SVille Syrjälä struct intel_encoder *encoder; 316887a02106SVille Syrjälä u32 enabled_irqs = 0; 316987a02106SVille Syrjälä 317091c8a326SChris Wilson for_each_intel_encoder(&dev_priv->drm, encoder) 317187a02106SVille Syrjälä if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED) 317287a02106SVille Syrjälä enabled_irqs |= hpd[encoder->hpd_pin]; 317387a02106SVille Syrjälä 317487a02106SVille Syrjälä return enabled_irqs; 317587a02106SVille Syrjälä } 317687a02106SVille Syrjälä 31771a56b1a2SImre Deak static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv) 31781a56b1a2SImre Deak { 31791a56b1a2SImre Deak u32 hotplug; 31801a56b1a2SImre Deak 31811a56b1a2SImre Deak /* 31821a56b1a2SImre Deak * Enable digital hotplug on the PCH, and configure the DP short pulse 31831a56b1a2SImre Deak * duration to 2ms (which is the minimum in the Display Port spec). 31841a56b1a2SImre Deak * The pulse duration bits are reserved on LPT+. 31851a56b1a2SImre Deak */ 31861a56b1a2SImre Deak hotplug = I915_READ(PCH_PORT_HOTPLUG); 31871a56b1a2SImre Deak hotplug &= ~(PORTB_PULSE_DURATION_MASK | 31881a56b1a2SImre Deak PORTC_PULSE_DURATION_MASK | 31891a56b1a2SImre Deak PORTD_PULSE_DURATION_MASK); 31901a56b1a2SImre Deak hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms; 31911a56b1a2SImre Deak hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms; 31921a56b1a2SImre Deak hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms; 31931a56b1a2SImre Deak /* 31941a56b1a2SImre Deak * When CPU and PCH are on the same package, port A 31951a56b1a2SImre Deak * HPD must be enabled in both north and south. 31961a56b1a2SImre Deak */ 31971a56b1a2SImre Deak if (HAS_PCH_LPT_LP(dev_priv)) 31981a56b1a2SImre Deak hotplug |= PORTA_HOTPLUG_ENABLE; 31991a56b1a2SImre Deak I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 32001a56b1a2SImre Deak } 32011a56b1a2SImre Deak 320291d14251STvrtko Ursulin static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv) 320382a28bcfSDaniel Vetter { 32041a56b1a2SImre Deak u32 hotplug_irqs, enabled_irqs; 320582a28bcfSDaniel Vetter 320691d14251STvrtko Ursulin if (HAS_PCH_IBX(dev_priv)) { 3207fee884edSDaniel Vetter hotplug_irqs = SDE_HOTPLUG_MASK; 320891d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx); 320982a28bcfSDaniel Vetter } else { 3210fee884edSDaniel Vetter hotplug_irqs = SDE_HOTPLUG_MASK_CPT; 321191d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt); 321282a28bcfSDaniel Vetter } 321382a28bcfSDaniel Vetter 3214fee884edSDaniel Vetter ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); 321582a28bcfSDaniel Vetter 32161a56b1a2SImre Deak ibx_hpd_detection_setup(dev_priv); 32176dbf30ceSVille Syrjälä } 321826951cafSXiong Zhang 32192a57d9ccSImre Deak static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv) 32202a57d9ccSImre Deak { 32212a57d9ccSImre Deak u32 hotplug; 32222a57d9ccSImre Deak 32232a57d9ccSImre Deak /* Enable digital hotplug on the PCH */ 32242a57d9ccSImre Deak hotplug = I915_READ(PCH_PORT_HOTPLUG); 32252a57d9ccSImre Deak hotplug |= PORTA_HOTPLUG_ENABLE | 32262a57d9ccSImre Deak PORTB_HOTPLUG_ENABLE | 32272a57d9ccSImre Deak PORTC_HOTPLUG_ENABLE | 32282a57d9ccSImre Deak PORTD_HOTPLUG_ENABLE; 32292a57d9ccSImre Deak I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 32302a57d9ccSImre Deak 32312a57d9ccSImre Deak hotplug = I915_READ(PCH_PORT_HOTPLUG2); 32322a57d9ccSImre Deak hotplug |= PORTE_HOTPLUG_ENABLE; 32332a57d9ccSImre Deak I915_WRITE(PCH_PORT_HOTPLUG2, hotplug); 32342a57d9ccSImre Deak } 32352a57d9ccSImre Deak 323691d14251STvrtko Ursulin static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv) 32376dbf30ceSVille Syrjälä { 32382a57d9ccSImre Deak u32 hotplug_irqs, enabled_irqs; 32396dbf30ceSVille Syrjälä 32406dbf30ceSVille Syrjälä hotplug_irqs = SDE_HOTPLUG_MASK_SPT; 324191d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt); 32426dbf30ceSVille Syrjälä 32436dbf30ceSVille Syrjälä ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); 32446dbf30ceSVille Syrjälä 32452a57d9ccSImre Deak spt_hpd_detection_setup(dev_priv); 324626951cafSXiong Zhang } 32477fe0b973SKeith Packard 32481a56b1a2SImre Deak static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv) 32491a56b1a2SImre Deak { 32501a56b1a2SImre Deak u32 hotplug; 32511a56b1a2SImre Deak 32521a56b1a2SImre Deak /* 32531a56b1a2SImre Deak * Enable digital hotplug on the CPU, and configure the DP short pulse 32541a56b1a2SImre Deak * duration to 2ms (which is the minimum in the Display Port spec) 32551a56b1a2SImre Deak * The pulse duration bits are reserved on HSW+. 32561a56b1a2SImre Deak */ 32571a56b1a2SImre Deak hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL); 32581a56b1a2SImre Deak hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK; 32591a56b1a2SImre Deak hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE | 32601a56b1a2SImre Deak DIGITAL_PORTA_PULSE_DURATION_2ms; 32611a56b1a2SImre Deak I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug); 32621a56b1a2SImre Deak } 32631a56b1a2SImre Deak 326491d14251STvrtko Ursulin static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv) 3265e4ce95aaSVille Syrjälä { 32661a56b1a2SImre Deak u32 hotplug_irqs, enabled_irqs; 3267e4ce95aaSVille Syrjälä 326891d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 8) { 32693a3b3c7dSVille Syrjälä hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG; 327091d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw); 32713a3b3c7dSVille Syrjälä 32723a3b3c7dSVille Syrjälä bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs); 327391d14251STvrtko Ursulin } else if (INTEL_GEN(dev_priv) >= 7) { 327423bb4cb5SVille Syrjälä hotplug_irqs = DE_DP_A_HOTPLUG_IVB; 327591d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb); 32763a3b3c7dSVille Syrjälä 32773a3b3c7dSVille Syrjälä ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs); 327823bb4cb5SVille Syrjälä } else { 3279e4ce95aaSVille Syrjälä hotplug_irqs = DE_DP_A_HOTPLUG; 328091d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk); 3281e4ce95aaSVille Syrjälä 3282e4ce95aaSVille Syrjälä ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs); 32833a3b3c7dSVille Syrjälä } 3284e4ce95aaSVille Syrjälä 32851a56b1a2SImre Deak ilk_hpd_detection_setup(dev_priv); 3286e4ce95aaSVille Syrjälä 328791d14251STvrtko Ursulin ibx_hpd_irq_setup(dev_priv); 3288e4ce95aaSVille Syrjälä } 3289e4ce95aaSVille Syrjälä 32902a57d9ccSImre Deak static void __bxt_hpd_detection_setup(struct drm_i915_private *dev_priv, 32912a57d9ccSImre Deak u32 enabled_irqs) 3292e0a20ad7SShashank Sharma { 32932a57d9ccSImre Deak u32 hotplug; 3294e0a20ad7SShashank Sharma 3295a52bb15bSVille Syrjälä hotplug = I915_READ(PCH_PORT_HOTPLUG); 32962a57d9ccSImre Deak hotplug |= PORTA_HOTPLUG_ENABLE | 32972a57d9ccSImre Deak PORTB_HOTPLUG_ENABLE | 32982a57d9ccSImre Deak PORTC_HOTPLUG_ENABLE; 3299d252bf68SShubhangi Shrivastava 3300d252bf68SShubhangi Shrivastava DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n", 3301d252bf68SShubhangi Shrivastava hotplug, enabled_irqs); 3302d252bf68SShubhangi Shrivastava hotplug &= ~BXT_DDI_HPD_INVERT_MASK; 3303d252bf68SShubhangi Shrivastava 3304d252bf68SShubhangi Shrivastava /* 3305d252bf68SShubhangi Shrivastava * For BXT invert bit has to be set based on AOB design 3306d252bf68SShubhangi Shrivastava * for HPD detection logic, update it based on VBT fields. 3307d252bf68SShubhangi Shrivastava */ 3308d252bf68SShubhangi Shrivastava if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) && 3309d252bf68SShubhangi Shrivastava intel_bios_is_port_hpd_inverted(dev_priv, PORT_A)) 3310d252bf68SShubhangi Shrivastava hotplug |= BXT_DDIA_HPD_INVERT; 3311d252bf68SShubhangi Shrivastava if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) && 3312d252bf68SShubhangi Shrivastava intel_bios_is_port_hpd_inverted(dev_priv, PORT_B)) 3313d252bf68SShubhangi Shrivastava hotplug |= BXT_DDIB_HPD_INVERT; 3314d252bf68SShubhangi Shrivastava if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) && 3315d252bf68SShubhangi Shrivastava intel_bios_is_port_hpd_inverted(dev_priv, PORT_C)) 3316d252bf68SShubhangi Shrivastava hotplug |= BXT_DDIC_HPD_INVERT; 3317d252bf68SShubhangi Shrivastava 3318a52bb15bSVille Syrjälä I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 3319e0a20ad7SShashank Sharma } 3320e0a20ad7SShashank Sharma 33212a57d9ccSImre Deak static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv) 33222a57d9ccSImre Deak { 33232a57d9ccSImre Deak __bxt_hpd_detection_setup(dev_priv, BXT_DE_PORT_HOTPLUG_MASK); 33242a57d9ccSImre Deak } 33252a57d9ccSImre Deak 33262a57d9ccSImre Deak static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv) 33272a57d9ccSImre Deak { 33282a57d9ccSImre Deak u32 hotplug_irqs, enabled_irqs; 33292a57d9ccSImre Deak 33302a57d9ccSImre Deak enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt); 33312a57d9ccSImre Deak hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK; 33322a57d9ccSImre Deak 33332a57d9ccSImre Deak bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs); 33342a57d9ccSImre Deak 33352a57d9ccSImre Deak __bxt_hpd_detection_setup(dev_priv, enabled_irqs); 33362a57d9ccSImre Deak } 33372a57d9ccSImre Deak 3338d46da437SPaulo Zanoni static void ibx_irq_postinstall(struct drm_device *dev) 3339d46da437SPaulo Zanoni { 3340fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 334182a28bcfSDaniel Vetter u32 mask; 3342d46da437SPaulo Zanoni 33436e266956STvrtko Ursulin if (HAS_PCH_NOP(dev_priv)) 3344692a04cfSDaniel Vetter return; 3345692a04cfSDaniel Vetter 33466e266956STvrtko Ursulin if (HAS_PCH_IBX(dev_priv)) 33475c673b60SDaniel Vetter mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON; 33484ebc6509SDhinakaran Pandiyan else if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv)) 33495c673b60SDaniel Vetter mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT; 33504ebc6509SDhinakaran Pandiyan else 33514ebc6509SDhinakaran Pandiyan mask = SDE_GMBUS_CPT; 33528664281bSPaulo Zanoni 33533488d4ebSVille Syrjälä gen3_assert_iir_is_zero(dev_priv, SDEIIR); 3354d46da437SPaulo Zanoni I915_WRITE(SDEIMR, ~mask); 33552a57d9ccSImre Deak 33562a57d9ccSImre Deak if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) || 33572a57d9ccSImre Deak HAS_PCH_LPT(dev_priv)) 33581a56b1a2SImre Deak ibx_hpd_detection_setup(dev_priv); 33592a57d9ccSImre Deak else 33602a57d9ccSImre Deak spt_hpd_detection_setup(dev_priv); 3361d46da437SPaulo Zanoni } 3362d46da437SPaulo Zanoni 33630a9a8c91SDaniel Vetter static void gen5_gt_irq_postinstall(struct drm_device *dev) 33640a9a8c91SDaniel Vetter { 3365fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 33660a9a8c91SDaniel Vetter u32 pm_irqs, gt_irqs; 33670a9a8c91SDaniel Vetter 33680a9a8c91SDaniel Vetter pm_irqs = gt_irqs = 0; 33690a9a8c91SDaniel Vetter 33700a9a8c91SDaniel Vetter dev_priv->gt_irq_mask = ~0; 33713c9192bcSTvrtko Ursulin if (HAS_L3_DPF(dev_priv)) { 33720a9a8c91SDaniel Vetter /* L3 parity interrupt is always unmasked. */ 3373772c2a51STvrtko Ursulin dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev_priv); 3374772c2a51STvrtko Ursulin gt_irqs |= GT_PARITY_ERROR(dev_priv); 33750a9a8c91SDaniel Vetter } 33760a9a8c91SDaniel Vetter 33770a9a8c91SDaniel Vetter gt_irqs |= GT_RENDER_USER_INTERRUPT; 33785db94019STvrtko Ursulin if (IS_GEN5(dev_priv)) { 3379f8973c21SChris Wilson gt_irqs |= ILK_BSD_USER_INTERRUPT; 33800a9a8c91SDaniel Vetter } else { 33810a9a8c91SDaniel Vetter gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT; 33820a9a8c91SDaniel Vetter } 33830a9a8c91SDaniel Vetter 33843488d4ebSVille Syrjälä GEN3_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs); 33850a9a8c91SDaniel Vetter 3386b243f530STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 6) { 338778e68d36SImre Deak /* 338878e68d36SImre Deak * RPS interrupts will get enabled/disabled on demand when RPS 338978e68d36SImre Deak * itself is enabled/disabled. 339078e68d36SImre Deak */ 3391f4e9af4fSAkash Goel if (HAS_VEBOX(dev_priv)) { 33920a9a8c91SDaniel Vetter pm_irqs |= PM_VEBOX_USER_INTERRUPT; 3393f4e9af4fSAkash Goel dev_priv->pm_ier |= PM_VEBOX_USER_INTERRUPT; 3394f4e9af4fSAkash Goel } 33950a9a8c91SDaniel Vetter 3396f4e9af4fSAkash Goel dev_priv->pm_imr = 0xffffffff; 33973488d4ebSVille Syrjälä GEN3_IRQ_INIT(GEN6_PM, dev_priv->pm_imr, pm_irqs); 33980a9a8c91SDaniel Vetter } 33990a9a8c91SDaniel Vetter } 34000a9a8c91SDaniel Vetter 3401f71d4af4SJesse Barnes static int ironlake_irq_postinstall(struct drm_device *dev) 3402036a4a7dSZhenyu Wang { 3403fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 34048e76f8dcSPaulo Zanoni u32 display_mask, extra_mask; 34058e76f8dcSPaulo Zanoni 3406b243f530STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 7) { 34078e76f8dcSPaulo Zanoni display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | 3408842ebf7aSVille Syrjälä DE_PCH_EVENT_IVB | DE_AUX_CHANNEL_A_IVB); 34098e76f8dcSPaulo Zanoni extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB | 341023bb4cb5SVille Syrjälä DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB | 341123bb4cb5SVille Syrjälä DE_DP_A_HOTPLUG_IVB); 34128e76f8dcSPaulo Zanoni } else { 34138e76f8dcSPaulo Zanoni display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | 3414842ebf7aSVille Syrjälä DE_AUX_CHANNEL_A | DE_PIPEB_CRC_DONE | 3415842ebf7aSVille Syrjälä DE_PIPEA_CRC_DONE | DE_POISON); 3416e4ce95aaSVille Syrjälä extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT | 3417e4ce95aaSVille Syrjälä DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN | 3418e4ce95aaSVille Syrjälä DE_DP_A_HOTPLUG); 34198e76f8dcSPaulo Zanoni } 3420036a4a7dSZhenyu Wang 34211ec14ad3SChris Wilson dev_priv->irq_mask = ~display_mask; 3422036a4a7dSZhenyu Wang 3423622364b6SPaulo Zanoni ibx_irq_pre_postinstall(dev); 3424622364b6SPaulo Zanoni 34253488d4ebSVille Syrjälä GEN3_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask); 3426036a4a7dSZhenyu Wang 34270a9a8c91SDaniel Vetter gen5_gt_irq_postinstall(dev); 3428036a4a7dSZhenyu Wang 34291a56b1a2SImre Deak ilk_hpd_detection_setup(dev_priv); 34301a56b1a2SImre Deak 3431d46da437SPaulo Zanoni ibx_irq_postinstall(dev); 34327fe0b973SKeith Packard 343350a0bc90STvrtko Ursulin if (IS_IRONLAKE_M(dev_priv)) { 34346005ce42SDaniel Vetter /* Enable PCU event interrupts 34356005ce42SDaniel Vetter * 34366005ce42SDaniel Vetter * spinlocking not required here for correctness since interrupt 34374bc9d430SDaniel Vetter * setup is guaranteed to run in single-threaded context. But we 34384bc9d430SDaniel Vetter * need it to make the assert_spin_locked happy. */ 3439d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 3440fbdedaeaSVille Syrjälä ilk_enable_display_irq(dev_priv, DE_PCU_EVENT); 3441d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 3442f97108d1SJesse Barnes } 3443f97108d1SJesse Barnes 3444036a4a7dSZhenyu Wang return 0; 3445036a4a7dSZhenyu Wang } 3446036a4a7dSZhenyu Wang 3447f8b79e58SImre Deak void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv) 3448f8b79e58SImre Deak { 344967520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 3450f8b79e58SImre Deak 3451f8b79e58SImre Deak if (dev_priv->display_irqs_enabled) 3452f8b79e58SImre Deak return; 3453f8b79e58SImre Deak 3454f8b79e58SImre Deak dev_priv->display_irqs_enabled = true; 3455f8b79e58SImre Deak 3456d6c69803SVille Syrjälä if (intel_irqs_enabled(dev_priv)) { 3457d6c69803SVille Syrjälä vlv_display_irq_reset(dev_priv); 3458ad22d106SVille Syrjälä vlv_display_irq_postinstall(dev_priv); 3459f8b79e58SImre Deak } 3460d6c69803SVille Syrjälä } 3461f8b79e58SImre Deak 3462f8b79e58SImre Deak void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv) 3463f8b79e58SImre Deak { 346467520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 3465f8b79e58SImre Deak 3466f8b79e58SImre Deak if (!dev_priv->display_irqs_enabled) 3467f8b79e58SImre Deak return; 3468f8b79e58SImre Deak 3469f8b79e58SImre Deak dev_priv->display_irqs_enabled = false; 3470f8b79e58SImre Deak 3471950eabafSImre Deak if (intel_irqs_enabled(dev_priv)) 3472ad22d106SVille Syrjälä vlv_display_irq_reset(dev_priv); 3473f8b79e58SImre Deak } 3474f8b79e58SImre Deak 34750e6c9a9eSVille Syrjälä 34760e6c9a9eSVille Syrjälä static int valleyview_irq_postinstall(struct drm_device *dev) 34770e6c9a9eSVille Syrjälä { 3478fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 34790e6c9a9eSVille Syrjälä 34800a9a8c91SDaniel Vetter gen5_gt_irq_postinstall(dev); 34817e231dbeSJesse Barnes 3482ad22d106SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 34839918271eSVille Syrjälä if (dev_priv->display_irqs_enabled) 3484ad22d106SVille Syrjälä vlv_display_irq_postinstall(dev_priv); 3485ad22d106SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 3486ad22d106SVille Syrjälä 34877e231dbeSJesse Barnes I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE); 348834c7b8a7SVille Syrjälä POSTING_READ(VLV_MASTER_IER); 348920afbda2SDaniel Vetter 349020afbda2SDaniel Vetter return 0; 349120afbda2SDaniel Vetter } 349220afbda2SDaniel Vetter 3493abd58f01SBen Widawsky static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv) 3494abd58f01SBen Widawsky { 3495abd58f01SBen Widawsky /* These are interrupts we'll toggle with the ring mask register */ 3496abd58f01SBen Widawsky uint32_t gt_interrupts[] = { 3497abd58f01SBen Widawsky GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT | 349873d477f6SOscar Mateo GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT | 349973d477f6SOscar Mateo GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT | 350073d477f6SOscar Mateo GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT, 3501abd58f01SBen Widawsky GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT | 350273d477f6SOscar Mateo GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT | 350373d477f6SOscar Mateo GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT | 350473d477f6SOscar Mateo GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT, 3505abd58f01SBen Widawsky 0, 350673d477f6SOscar Mateo GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT | 350773d477f6SOscar Mateo GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT 3508abd58f01SBen Widawsky }; 3509abd58f01SBen Widawsky 351098735739STvrtko Ursulin if (HAS_L3_DPF(dev_priv)) 351198735739STvrtko Ursulin gt_interrupts[0] |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT; 351298735739STvrtko Ursulin 3513f4e9af4fSAkash Goel dev_priv->pm_ier = 0x0; 3514f4e9af4fSAkash Goel dev_priv->pm_imr = ~dev_priv->pm_ier; 35159a2d2d87SDeepak S GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]); 35169a2d2d87SDeepak S GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]); 351778e68d36SImre Deak /* 351878e68d36SImre Deak * RPS interrupts will get enabled/disabled on demand when RPS itself 351926705e20SSagar Arun Kamble * is enabled/disabled. Same wil be the case for GuC interrupts. 352078e68d36SImre Deak */ 3521f4e9af4fSAkash Goel GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_imr, dev_priv->pm_ier); 35229a2d2d87SDeepak S GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]); 3523abd58f01SBen Widawsky } 3524abd58f01SBen Widawsky 3525abd58f01SBen Widawsky static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv) 3526abd58f01SBen Widawsky { 3527770de83dSDamien Lespiau uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE; 3528770de83dSDamien Lespiau uint32_t de_pipe_enables; 35293a3b3c7dSVille Syrjälä u32 de_port_masked = GEN8_AUX_CHANNEL_A; 35303a3b3c7dSVille Syrjälä u32 de_port_enables; 353111825b0dSVille Syrjälä u32 de_misc_masked = GEN8_DE_MISC_GSE; 35323a3b3c7dSVille Syrjälä enum pipe pipe; 3533770de83dSDamien Lespiau 3534bca2bf2aSPandiyan, Dhinakaran if (INTEL_GEN(dev_priv) >= 9) { 3535842ebf7aSVille Syrjälä de_pipe_masked |= GEN9_DE_PIPE_IRQ_FAULT_ERRORS; 35363a3b3c7dSVille Syrjälä de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C | 353788e04703SJesse Barnes GEN9_AUX_CHANNEL_D; 3538cc3f90f0SAnder Conselvan de Oliveira if (IS_GEN9_LP(dev_priv)) 35393a3b3c7dSVille Syrjälä de_port_masked |= BXT_DE_PORT_GMBUS; 35403a3b3c7dSVille Syrjälä } else { 3541842ebf7aSVille Syrjälä de_pipe_masked |= GEN8_DE_PIPE_IRQ_FAULT_ERRORS; 35423a3b3c7dSVille Syrjälä } 3543770de83dSDamien Lespiau 3544770de83dSDamien Lespiau de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK | 3545770de83dSDamien Lespiau GEN8_PIPE_FIFO_UNDERRUN; 3546770de83dSDamien Lespiau 35473a3b3c7dSVille Syrjälä de_port_enables = de_port_masked; 3548cc3f90f0SAnder Conselvan de Oliveira if (IS_GEN9_LP(dev_priv)) 3549a52bb15bSVille Syrjälä de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK; 3550a52bb15bSVille Syrjälä else if (IS_BROADWELL(dev_priv)) 35513a3b3c7dSVille Syrjälä de_port_enables |= GEN8_PORT_DP_A_HOTPLUG; 35523a3b3c7dSVille Syrjälä 355313b3a0a7SDaniel Vetter dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked; 355413b3a0a7SDaniel Vetter dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked; 355513b3a0a7SDaniel Vetter dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked; 3556abd58f01SBen Widawsky 3557055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 3558f458ebbcSDaniel Vetter if (intel_display_power_is_enabled(dev_priv, 3559813bde43SPaulo Zanoni POWER_DOMAIN_PIPE(pipe))) 3560813bde43SPaulo Zanoni GEN8_IRQ_INIT_NDX(DE_PIPE, pipe, 3561813bde43SPaulo Zanoni dev_priv->de_irq_mask[pipe], 356235079899SPaulo Zanoni de_pipe_enables); 3563abd58f01SBen Widawsky 35643488d4ebSVille Syrjälä GEN3_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables); 35653488d4ebSVille Syrjälä GEN3_IRQ_INIT(GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked); 35662a57d9ccSImre Deak 35672a57d9ccSImre Deak if (IS_GEN9_LP(dev_priv)) 35682a57d9ccSImre Deak bxt_hpd_detection_setup(dev_priv); 35691a56b1a2SImre Deak else if (IS_BROADWELL(dev_priv)) 35701a56b1a2SImre Deak ilk_hpd_detection_setup(dev_priv); 3571abd58f01SBen Widawsky } 3572abd58f01SBen Widawsky 3573abd58f01SBen Widawsky static int gen8_irq_postinstall(struct drm_device *dev) 3574abd58f01SBen Widawsky { 3575fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 3576abd58f01SBen Widawsky 35776e266956STvrtko Ursulin if (HAS_PCH_SPLIT(dev_priv)) 3578622364b6SPaulo Zanoni ibx_irq_pre_postinstall(dev); 3579622364b6SPaulo Zanoni 3580abd58f01SBen Widawsky gen8_gt_irq_postinstall(dev_priv); 3581abd58f01SBen Widawsky gen8_de_irq_postinstall(dev_priv); 3582abd58f01SBen Widawsky 35836e266956STvrtko Ursulin if (HAS_PCH_SPLIT(dev_priv)) 3584abd58f01SBen Widawsky ibx_irq_postinstall(dev); 3585abd58f01SBen Widawsky 3586e5328c43SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); 3587abd58f01SBen Widawsky POSTING_READ(GEN8_MASTER_IRQ); 3588abd58f01SBen Widawsky 3589abd58f01SBen Widawsky return 0; 3590abd58f01SBen Widawsky } 3591abd58f01SBen Widawsky 359243f328d7SVille Syrjälä static int cherryview_irq_postinstall(struct drm_device *dev) 359343f328d7SVille Syrjälä { 3594fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 359543f328d7SVille Syrjälä 359643f328d7SVille Syrjälä gen8_gt_irq_postinstall(dev_priv); 359743f328d7SVille Syrjälä 3598ad22d106SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 35999918271eSVille Syrjälä if (dev_priv->display_irqs_enabled) 3600ad22d106SVille Syrjälä vlv_display_irq_postinstall(dev_priv); 3601ad22d106SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 3602ad22d106SVille Syrjälä 3603e5328c43SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); 360443f328d7SVille Syrjälä POSTING_READ(GEN8_MASTER_IRQ); 360543f328d7SVille Syrjälä 360643f328d7SVille Syrjälä return 0; 360743f328d7SVille Syrjälä } 360843f328d7SVille Syrjälä 3609*6bcdb1c8SVille Syrjälä static void i8xx_irq_reset(struct drm_device *dev) 3610c2798b19SChris Wilson { 3611fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 3612c2798b19SChris Wilson 361344d9241eSVille Syrjälä i9xx_pipestat_irq_reset(dev_priv); 361444d9241eSVille Syrjälä 3615d420a50cSVille Syrjälä I915_WRITE16(HWSTAM, 0xffff); 3616d420a50cSVille Syrjälä 3617e9e9848aSVille Syrjälä GEN2_IRQ_RESET(); 3618c2798b19SChris Wilson } 3619c2798b19SChris Wilson 3620c2798b19SChris Wilson static int i8xx_irq_postinstall(struct drm_device *dev) 3621c2798b19SChris Wilson { 3622fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 3623e9e9848aSVille Syrjälä u16 enable_mask; 3624c2798b19SChris Wilson 3625045cebd2SVille Syrjälä I915_WRITE16(EMR, ~(I915_ERROR_PAGE_TABLE | 3626045cebd2SVille Syrjälä I915_ERROR_MEMORY_REFRESH)); 3627c2798b19SChris Wilson 3628c2798b19SChris Wilson /* Unmask the interrupts that we always want on. */ 3629c2798b19SChris Wilson dev_priv->irq_mask = 3630c2798b19SChris Wilson ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3631842ebf7aSVille Syrjälä I915_DISPLAY_PIPE_B_EVENT_INTERRUPT); 3632c2798b19SChris Wilson 3633e9e9848aSVille Syrjälä enable_mask = 3634c2798b19SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3635c2798b19SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3636e9e9848aSVille Syrjälä I915_USER_INTERRUPT; 3637e9e9848aSVille Syrjälä 3638e9e9848aSVille Syrjälä GEN2_IRQ_INIT(, dev_priv->irq_mask, enable_mask); 3639c2798b19SChris Wilson 3640379ef82dSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3641379ef82dSDaniel Vetter * just to make the assert_spin_locked check happy. */ 3642d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 3643755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 3644755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 3645d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 3646379ef82dSDaniel Vetter 3647c2798b19SChris Wilson return 0; 3648c2798b19SChris Wilson } 3649c2798b19SChris Wilson 3650ff1f525eSDaniel Vetter static irqreturn_t i8xx_irq_handler(int irq, void *arg) 3651c2798b19SChris Wilson { 365245a83f84SDaniel Vetter struct drm_device *dev = arg; 3653fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 3654af722d28SVille Syrjälä irqreturn_t ret = IRQ_NONE; 3655c2798b19SChris Wilson 36562dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 36572dd2a883SImre Deak return IRQ_NONE; 36582dd2a883SImre Deak 36591f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 36601f814dacSImre Deak disable_rpm_wakeref_asserts(dev_priv); 36611f814dacSImre Deak 3662af722d28SVille Syrjälä do { 3663af722d28SVille Syrjälä u32 pipe_stats[I915_MAX_PIPES] = {}; 3664af722d28SVille Syrjälä u16 iir; 3665af722d28SVille Syrjälä 3666c2798b19SChris Wilson iir = I915_READ16(IIR); 3667c2798b19SChris Wilson if (iir == 0) 3668af722d28SVille Syrjälä break; 3669c2798b19SChris Wilson 3670af722d28SVille Syrjälä ret = IRQ_HANDLED; 3671c2798b19SChris Wilson 3672eb64343cSVille Syrjälä /* Call regardless, as some status bits might not be 3673eb64343cSVille Syrjälä * signalled in iir */ 3674eb64343cSVille Syrjälä i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats); 3675c2798b19SChris Wilson 3676fd3a4024SDaniel Vetter I915_WRITE16(IIR, iir); 3677c2798b19SChris Wilson 3678c2798b19SChris Wilson if (iir & I915_USER_INTERRUPT) 36793b3f1650SAkash Goel notify_ring(dev_priv->engine[RCS]); 3680c2798b19SChris Wilson 3681af722d28SVille Syrjälä if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 3682af722d28SVille Syrjälä DRM_DEBUG("Command parser error, iir 0x%08x\n", iir); 3683af722d28SVille Syrjälä 3684eb64343cSVille Syrjälä i8xx_pipestat_irq_handler(dev_priv, iir, pipe_stats); 3685af722d28SVille Syrjälä } while (0); 3686c2798b19SChris Wilson 36871f814dacSImre Deak enable_rpm_wakeref_asserts(dev_priv); 36881f814dacSImre Deak 36891f814dacSImre Deak return ret; 3690c2798b19SChris Wilson } 3691c2798b19SChris Wilson 3692*6bcdb1c8SVille Syrjälä static void i915_irq_reset(struct drm_device *dev) 3693a266c7d5SChris Wilson { 3694fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 3695a266c7d5SChris Wilson 369656b857a5STvrtko Ursulin if (I915_HAS_HOTPLUG(dev_priv)) { 36970706f17cSEgbert Eich i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0); 3698a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3699a266c7d5SChris Wilson } 3700a266c7d5SChris Wilson 370144d9241eSVille Syrjälä i9xx_pipestat_irq_reset(dev_priv); 370244d9241eSVille Syrjälä 3703d420a50cSVille Syrjälä I915_WRITE(HWSTAM, 0xffffffff); 370444d9241eSVille Syrjälä 3705ba7eb789SVille Syrjälä GEN3_IRQ_RESET(); 3706a266c7d5SChris Wilson } 3707a266c7d5SChris Wilson 3708a266c7d5SChris Wilson static int i915_irq_postinstall(struct drm_device *dev) 3709a266c7d5SChris Wilson { 3710fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 371138bde180SChris Wilson u32 enable_mask; 3712a266c7d5SChris Wilson 3713045cebd2SVille Syrjälä I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | 3714045cebd2SVille Syrjälä I915_ERROR_MEMORY_REFRESH)); 371538bde180SChris Wilson 371638bde180SChris Wilson /* Unmask the interrupts that we always want on. */ 371738bde180SChris Wilson dev_priv->irq_mask = 371838bde180SChris Wilson ~(I915_ASLE_INTERRUPT | 371938bde180SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3720842ebf7aSVille Syrjälä I915_DISPLAY_PIPE_B_EVENT_INTERRUPT); 372138bde180SChris Wilson 372238bde180SChris Wilson enable_mask = 372338bde180SChris Wilson I915_ASLE_INTERRUPT | 372438bde180SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 372538bde180SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 372638bde180SChris Wilson I915_USER_INTERRUPT; 372738bde180SChris Wilson 372856b857a5STvrtko Ursulin if (I915_HAS_HOTPLUG(dev_priv)) { 3729a266c7d5SChris Wilson /* Enable in IER... */ 3730a266c7d5SChris Wilson enable_mask |= I915_DISPLAY_PORT_INTERRUPT; 3731a266c7d5SChris Wilson /* and unmask in IMR */ 3732a266c7d5SChris Wilson dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT; 3733a266c7d5SChris Wilson } 3734a266c7d5SChris Wilson 3735ba7eb789SVille Syrjälä GEN3_IRQ_INIT(, dev_priv->irq_mask, enable_mask); 3736a266c7d5SChris Wilson 3737379ef82dSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3738379ef82dSDaniel Vetter * just to make the assert_spin_locked check happy. */ 3739d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 3740755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 3741755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 3742d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 3743379ef82dSDaniel Vetter 3744c30bb1fdSVille Syrjälä i915_enable_asle_pipestat(dev_priv); 3745c30bb1fdSVille Syrjälä 374620afbda2SDaniel Vetter return 0; 374720afbda2SDaniel Vetter } 374820afbda2SDaniel Vetter 3749ff1f525eSDaniel Vetter static irqreturn_t i915_irq_handler(int irq, void *arg) 3750a266c7d5SChris Wilson { 375145a83f84SDaniel Vetter struct drm_device *dev = arg; 3752fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 3753af722d28SVille Syrjälä irqreturn_t ret = IRQ_NONE; 3754a266c7d5SChris Wilson 37552dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 37562dd2a883SImre Deak return IRQ_NONE; 37572dd2a883SImre Deak 37581f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 37591f814dacSImre Deak disable_rpm_wakeref_asserts(dev_priv); 37601f814dacSImre Deak 376138bde180SChris Wilson do { 3762eb64343cSVille Syrjälä u32 pipe_stats[I915_MAX_PIPES] = {}; 3763af722d28SVille Syrjälä u32 hotplug_status = 0; 3764af722d28SVille Syrjälä u32 iir; 3765a266c7d5SChris Wilson 3766af722d28SVille Syrjälä iir = I915_READ(IIR); 3767af722d28SVille Syrjälä if (iir == 0) 3768af722d28SVille Syrjälä break; 3769af722d28SVille Syrjälä 3770af722d28SVille Syrjälä ret = IRQ_HANDLED; 3771af722d28SVille Syrjälä 3772af722d28SVille Syrjälä if (I915_HAS_HOTPLUG(dev_priv) && 3773af722d28SVille Syrjälä iir & I915_DISPLAY_PORT_INTERRUPT) 3774af722d28SVille Syrjälä hotplug_status = i9xx_hpd_irq_ack(dev_priv); 3775a266c7d5SChris Wilson 3776eb64343cSVille Syrjälä /* Call regardless, as some status bits might not be 3777eb64343cSVille Syrjälä * signalled in iir */ 3778eb64343cSVille Syrjälä i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats); 3779a266c7d5SChris Wilson 3780fd3a4024SDaniel Vetter I915_WRITE(IIR, iir); 3781a266c7d5SChris Wilson 3782a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 37833b3f1650SAkash Goel notify_ring(dev_priv->engine[RCS]); 3784a266c7d5SChris Wilson 3785af722d28SVille Syrjälä if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 3786af722d28SVille Syrjälä DRM_DEBUG("Command parser error, iir 0x%08x\n", iir); 3787a266c7d5SChris Wilson 3788af722d28SVille Syrjälä if (hotplug_status) 3789af722d28SVille Syrjälä i9xx_hpd_irq_handler(dev_priv, hotplug_status); 3790af722d28SVille Syrjälä 3791af722d28SVille Syrjälä i915_pipestat_irq_handler(dev_priv, iir, pipe_stats); 3792af722d28SVille Syrjälä } while (0); 3793a266c7d5SChris Wilson 37941f814dacSImre Deak enable_rpm_wakeref_asserts(dev_priv); 37951f814dacSImre Deak 3796a266c7d5SChris Wilson return ret; 3797a266c7d5SChris Wilson } 3798a266c7d5SChris Wilson 3799*6bcdb1c8SVille Syrjälä static void i965_irq_reset(struct drm_device *dev) 3800a266c7d5SChris Wilson { 3801fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 3802a266c7d5SChris Wilson 38030706f17cSEgbert Eich i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0); 3804a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3805a266c7d5SChris Wilson 380644d9241eSVille Syrjälä i9xx_pipestat_irq_reset(dev_priv); 380744d9241eSVille Syrjälä 3808d420a50cSVille Syrjälä I915_WRITE(HWSTAM, 0xffffffff); 380944d9241eSVille Syrjälä 3810ba7eb789SVille Syrjälä GEN3_IRQ_RESET(); 3811a266c7d5SChris Wilson } 3812a266c7d5SChris Wilson 3813a266c7d5SChris Wilson static int i965_irq_postinstall(struct drm_device *dev) 3814a266c7d5SChris Wilson { 3815fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 3816bbba0a97SChris Wilson u32 enable_mask; 3817a266c7d5SChris Wilson u32 error_mask; 3818a266c7d5SChris Wilson 3819045cebd2SVille Syrjälä /* 3820045cebd2SVille Syrjälä * Enable some error detection, note the instruction error mask 3821045cebd2SVille Syrjälä * bit is reserved, so we leave it masked. 3822045cebd2SVille Syrjälä */ 3823045cebd2SVille Syrjälä if (IS_G4X(dev_priv)) { 3824045cebd2SVille Syrjälä error_mask = ~(GM45_ERROR_PAGE_TABLE | 3825045cebd2SVille Syrjälä GM45_ERROR_MEM_PRIV | 3826045cebd2SVille Syrjälä GM45_ERROR_CP_PRIV | 3827045cebd2SVille Syrjälä I915_ERROR_MEMORY_REFRESH); 3828045cebd2SVille Syrjälä } else { 3829045cebd2SVille Syrjälä error_mask = ~(I915_ERROR_PAGE_TABLE | 3830045cebd2SVille Syrjälä I915_ERROR_MEMORY_REFRESH); 3831045cebd2SVille Syrjälä } 3832045cebd2SVille Syrjälä I915_WRITE(EMR, error_mask); 3833045cebd2SVille Syrjälä 3834a266c7d5SChris Wilson /* Unmask the interrupts that we always want on. */ 3835c30bb1fdSVille Syrjälä dev_priv->irq_mask = 3836c30bb1fdSVille Syrjälä ~(I915_ASLE_INTERRUPT | 3837adca4730SChris Wilson I915_DISPLAY_PORT_INTERRUPT | 3838bbba0a97SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3839bbba0a97SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3840bbba0a97SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 3841bbba0a97SChris Wilson 3842c30bb1fdSVille Syrjälä enable_mask = 3843c30bb1fdSVille Syrjälä I915_ASLE_INTERRUPT | 3844c30bb1fdSVille Syrjälä I915_DISPLAY_PORT_INTERRUPT | 3845c30bb1fdSVille Syrjälä I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3846c30bb1fdSVille Syrjälä I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3847c30bb1fdSVille Syrjälä I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT | 3848c30bb1fdSVille Syrjälä I915_USER_INTERRUPT; 3849bbba0a97SChris Wilson 385091d14251STvrtko Ursulin if (IS_G4X(dev_priv)) 3851bbba0a97SChris Wilson enable_mask |= I915_BSD_USER_INTERRUPT; 3852a266c7d5SChris Wilson 3853c30bb1fdSVille Syrjälä GEN3_IRQ_INIT(, dev_priv->irq_mask, enable_mask); 3854c30bb1fdSVille Syrjälä 3855b79480baSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3856b79480baSDaniel Vetter * just to make the assert_spin_locked check happy. */ 3857d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 3858755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS); 3859755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 3860755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 3861d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 3862a266c7d5SChris Wilson 386391d14251STvrtko Ursulin i915_enable_asle_pipestat(dev_priv); 386420afbda2SDaniel Vetter 386520afbda2SDaniel Vetter return 0; 386620afbda2SDaniel Vetter } 386720afbda2SDaniel Vetter 386891d14251STvrtko Ursulin static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv) 386920afbda2SDaniel Vetter { 387020afbda2SDaniel Vetter u32 hotplug_en; 387120afbda2SDaniel Vetter 387267520415SChris Wilson lockdep_assert_held(&dev_priv->irq_lock); 3873b5ea2d56SDaniel Vetter 3874adca4730SChris Wilson /* Note HDMI and DP share hotplug bits */ 3875e5868a31SEgbert Eich /* enable bits are the same for all generations */ 387691d14251STvrtko Ursulin hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915); 3877a266c7d5SChris Wilson /* Programming the CRT detection parameters tends 3878a266c7d5SChris Wilson to generate a spurious hotplug event about three 3879a266c7d5SChris Wilson seconds later. So just do it once. 3880a266c7d5SChris Wilson */ 388191d14251STvrtko Ursulin if (IS_G4X(dev_priv)) 3882a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64; 3883a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; 3884a266c7d5SChris Wilson 3885a266c7d5SChris Wilson /* Ignore TV since it's buggy */ 38860706f17cSEgbert Eich i915_hotplug_interrupt_update_locked(dev_priv, 3887f9e3dc78SJani Nikula HOTPLUG_INT_EN_MASK | 3888f9e3dc78SJani Nikula CRT_HOTPLUG_VOLTAGE_COMPARE_MASK | 3889f9e3dc78SJani Nikula CRT_HOTPLUG_ACTIVATION_PERIOD_64, 38900706f17cSEgbert Eich hotplug_en); 3891a266c7d5SChris Wilson } 3892a266c7d5SChris Wilson 3893ff1f525eSDaniel Vetter static irqreturn_t i965_irq_handler(int irq, void *arg) 3894a266c7d5SChris Wilson { 389545a83f84SDaniel Vetter struct drm_device *dev = arg; 3896fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 3897af722d28SVille Syrjälä irqreturn_t ret = IRQ_NONE; 3898a266c7d5SChris Wilson 38992dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 39002dd2a883SImre Deak return IRQ_NONE; 39012dd2a883SImre Deak 39021f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 39031f814dacSImre Deak disable_rpm_wakeref_asserts(dev_priv); 39041f814dacSImre Deak 3905af722d28SVille Syrjälä do { 3906eb64343cSVille Syrjälä u32 pipe_stats[I915_MAX_PIPES] = {}; 3907af722d28SVille Syrjälä u32 hotplug_status = 0; 3908af722d28SVille Syrjälä u32 iir; 39092c8ba29fSChris Wilson 3910af722d28SVille Syrjälä iir = I915_READ(IIR); 3911af722d28SVille Syrjälä if (iir == 0) 3912af722d28SVille Syrjälä break; 3913af722d28SVille Syrjälä 3914af722d28SVille Syrjälä ret = IRQ_HANDLED; 3915af722d28SVille Syrjälä 3916af722d28SVille Syrjälä if (iir & I915_DISPLAY_PORT_INTERRUPT) 3917af722d28SVille Syrjälä hotplug_status = i9xx_hpd_irq_ack(dev_priv); 3918a266c7d5SChris Wilson 3919eb64343cSVille Syrjälä /* Call regardless, as some status bits might not be 3920eb64343cSVille Syrjälä * signalled in iir */ 3921eb64343cSVille Syrjälä i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats); 3922a266c7d5SChris Wilson 3923fd3a4024SDaniel Vetter I915_WRITE(IIR, iir); 3924a266c7d5SChris Wilson 3925a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 39263b3f1650SAkash Goel notify_ring(dev_priv->engine[RCS]); 3927af722d28SVille Syrjälä 3928a266c7d5SChris Wilson if (iir & I915_BSD_USER_INTERRUPT) 39293b3f1650SAkash Goel notify_ring(dev_priv->engine[VCS]); 3930a266c7d5SChris Wilson 3931af722d28SVille Syrjälä if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 3932af722d28SVille Syrjälä DRM_DEBUG("Command parser error, iir 0x%08x\n", iir); 3933515ac2bbSDaniel Vetter 3934af722d28SVille Syrjälä if (hotplug_status) 3935af722d28SVille Syrjälä i9xx_hpd_irq_handler(dev_priv, hotplug_status); 3936af722d28SVille Syrjälä 3937af722d28SVille Syrjälä i965_pipestat_irq_handler(dev_priv, iir, pipe_stats); 3938af722d28SVille Syrjälä } while (0); 3939a266c7d5SChris Wilson 39401f814dacSImre Deak enable_rpm_wakeref_asserts(dev_priv); 39411f814dacSImre Deak 3942a266c7d5SChris Wilson return ret; 3943a266c7d5SChris Wilson } 3944a266c7d5SChris Wilson 3945fca52a55SDaniel Vetter /** 3946fca52a55SDaniel Vetter * intel_irq_init - initializes irq support 3947fca52a55SDaniel Vetter * @dev_priv: i915 device instance 3948fca52a55SDaniel Vetter * 3949fca52a55SDaniel Vetter * This function initializes all the irq support including work items, timers 3950fca52a55SDaniel Vetter * and all the vtables. It does not setup the interrupt itself though. 3951fca52a55SDaniel Vetter */ 3952b963291cSDaniel Vetter void intel_irq_init(struct drm_i915_private *dev_priv) 3953f71d4af4SJesse Barnes { 395491c8a326SChris Wilson struct drm_device *dev = &dev_priv->drm; 3955cefcff8fSJoonas Lahtinen int i; 39568b2e326dSChris Wilson 395777913b39SJani Nikula intel_hpd_init_work(dev_priv); 395877913b39SJani Nikula 3959c6a828d3SDaniel Vetter INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work); 3960cefcff8fSJoonas Lahtinen 3961a4da4fa4SDaniel Vetter INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work); 3962cefcff8fSJoonas Lahtinen for (i = 0; i < MAX_L3_SLICES; ++i) 3963cefcff8fSJoonas Lahtinen dev_priv->l3_parity.remap_info[i] = NULL; 39648b2e326dSChris Wilson 39654805fe82STvrtko Ursulin if (HAS_GUC_SCHED(dev_priv)) 396626705e20SSagar Arun Kamble dev_priv->pm_guc_events = GEN9_GUC_TO_HOST_INT_EVENT; 396726705e20SSagar Arun Kamble 3968a6706b45SDeepak S /* Let's track the enabled rps events */ 3969666a4537SWayne Boyer if (IS_VALLEYVIEW(dev_priv)) 39706c65a587SVille Syrjälä /* WaGsvRC0ResidencyMethod:vlv */ 3971e0e8c7cbSChris Wilson dev_priv->pm_rps_events = GEN6_PM_RP_UP_EI_EXPIRED; 397231685c25SDeepak S else 3973a6706b45SDeepak S dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS; 3974a6706b45SDeepak S 39755dd04556SSagar Arun Kamble dev_priv->rps.pm_intrmsk_mbz = 0; 39761800ad25SSagar Arun Kamble 39771800ad25SSagar Arun Kamble /* 3978acf2dc22SMika Kuoppala * SNB,IVB,HSW can while VLV,CHV may hard hang on looping batchbuffer 39791800ad25SSagar Arun Kamble * if GEN6_PM_UP_EI_EXPIRED is masked. 39801800ad25SSagar Arun Kamble * 39811800ad25SSagar Arun Kamble * TODO: verify if this can be reproduced on VLV,CHV. 39821800ad25SSagar Arun Kamble */ 3983bca2bf2aSPandiyan, Dhinakaran if (INTEL_GEN(dev_priv) <= 7) 39845dd04556SSagar Arun Kamble dev_priv->rps.pm_intrmsk_mbz |= GEN6_PM_RP_UP_EI_EXPIRED; 39851800ad25SSagar Arun Kamble 3986bca2bf2aSPandiyan, Dhinakaran if (INTEL_GEN(dev_priv) >= 8) 3987655d49efSChris Wilson dev_priv->rps.pm_intrmsk_mbz |= GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC; 39881800ad25SSagar Arun Kamble 3989b963291cSDaniel Vetter if (IS_GEN2(dev_priv)) { 39904194c088SRodrigo Vivi /* Gen2 doesn't have a hardware frame counter */ 39914cdb83ecSVille Syrjälä dev->max_vblank_count = 0; 3992bca2bf2aSPandiyan, Dhinakaran } else if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) { 3993f71d4af4SJesse Barnes dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */ 3994fd8f507cSVille Syrjälä dev->driver->get_vblank_counter = g4x_get_vblank_counter; 3995391f75e2SVille Syrjälä } else { 3996391f75e2SVille Syrjälä dev->driver->get_vblank_counter = i915_get_vblank_counter; 3997391f75e2SVille Syrjälä dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ 3998f71d4af4SJesse Barnes } 3999f71d4af4SJesse Barnes 400021da2700SVille Syrjälä /* 400121da2700SVille Syrjälä * Opt out of the vblank disable timer on everything except gen2. 400221da2700SVille Syrjälä * Gen2 doesn't have a hardware frame counter and so depends on 400321da2700SVille Syrjälä * vblank interrupts to produce sane vblank seuquence numbers. 400421da2700SVille Syrjälä */ 4005b963291cSDaniel Vetter if (!IS_GEN2(dev_priv)) 400621da2700SVille Syrjälä dev->vblank_disable_immediate = true; 400721da2700SVille Syrjälä 4008262fd485SChris Wilson /* Most platforms treat the display irq block as an always-on 4009262fd485SChris Wilson * power domain. vlv/chv can disable it at runtime and need 4010262fd485SChris Wilson * special care to avoid writing any of the display block registers 4011262fd485SChris Wilson * outside of the power domain. We defer setting up the display irqs 4012262fd485SChris Wilson * in this case to the runtime pm. 4013262fd485SChris Wilson */ 4014262fd485SChris Wilson dev_priv->display_irqs_enabled = true; 4015262fd485SChris Wilson if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) 4016262fd485SChris Wilson dev_priv->display_irqs_enabled = false; 4017262fd485SChris Wilson 4018317eaa95SLyude dev_priv->hotplug.hpd_storm_threshold = HPD_STORM_DEFAULT_THRESHOLD; 4019317eaa95SLyude 40201bf6ad62SDaniel Vetter dev->driver->get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos; 4021f71d4af4SJesse Barnes dev->driver->get_scanout_position = i915_get_crtc_scanoutpos; 4022f71d4af4SJesse Barnes 4023b963291cSDaniel Vetter if (IS_CHERRYVIEW(dev_priv)) { 402443f328d7SVille Syrjälä dev->driver->irq_handler = cherryview_irq_handler; 4025*6bcdb1c8SVille Syrjälä dev->driver->irq_preinstall = cherryview_irq_reset; 402643f328d7SVille Syrjälä dev->driver->irq_postinstall = cherryview_irq_postinstall; 4027*6bcdb1c8SVille Syrjälä dev->driver->irq_uninstall = cherryview_irq_reset; 402886e83e35SChris Wilson dev->driver->enable_vblank = i965_enable_vblank; 402986e83e35SChris Wilson dev->driver->disable_vblank = i965_disable_vblank; 403043f328d7SVille Syrjälä dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 4031b963291cSDaniel Vetter } else if (IS_VALLEYVIEW(dev_priv)) { 40327e231dbeSJesse Barnes dev->driver->irq_handler = valleyview_irq_handler; 4033*6bcdb1c8SVille Syrjälä dev->driver->irq_preinstall = valleyview_irq_reset; 40347e231dbeSJesse Barnes dev->driver->irq_postinstall = valleyview_irq_postinstall; 4035*6bcdb1c8SVille Syrjälä dev->driver->irq_uninstall = valleyview_irq_reset; 403686e83e35SChris Wilson dev->driver->enable_vblank = i965_enable_vblank; 403786e83e35SChris Wilson dev->driver->disable_vblank = i965_disable_vblank; 4038fa00abe0SEgbert Eich dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 4039bca2bf2aSPandiyan, Dhinakaran } else if (INTEL_GEN(dev_priv) >= 8) { 4040abd58f01SBen Widawsky dev->driver->irq_handler = gen8_irq_handler; 4041723761b8SDaniel Vetter dev->driver->irq_preinstall = gen8_irq_reset; 4042abd58f01SBen Widawsky dev->driver->irq_postinstall = gen8_irq_postinstall; 4043*6bcdb1c8SVille Syrjälä dev->driver->irq_uninstall = gen8_irq_reset; 4044abd58f01SBen Widawsky dev->driver->enable_vblank = gen8_enable_vblank; 4045abd58f01SBen Widawsky dev->driver->disable_vblank = gen8_disable_vblank; 4046cc3f90f0SAnder Conselvan de Oliveira if (IS_GEN9_LP(dev_priv)) 4047e0a20ad7SShashank Sharma dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup; 40487b22b8c4SRodrigo Vivi else if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv) || 40497b22b8c4SRodrigo Vivi HAS_PCH_CNP(dev_priv)) 40506dbf30ceSVille Syrjälä dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup; 40516dbf30ceSVille Syrjälä else 40523a3b3c7dSVille Syrjälä dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup; 40536e266956STvrtko Ursulin } else if (HAS_PCH_SPLIT(dev_priv)) { 4054f71d4af4SJesse Barnes dev->driver->irq_handler = ironlake_irq_handler; 4055723761b8SDaniel Vetter dev->driver->irq_preinstall = ironlake_irq_reset; 4056f71d4af4SJesse Barnes dev->driver->irq_postinstall = ironlake_irq_postinstall; 4057*6bcdb1c8SVille Syrjälä dev->driver->irq_uninstall = ironlake_irq_reset; 4058f71d4af4SJesse Barnes dev->driver->enable_vblank = ironlake_enable_vblank; 4059f71d4af4SJesse Barnes dev->driver->disable_vblank = ironlake_disable_vblank; 4060e4ce95aaSVille Syrjälä dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup; 4061f71d4af4SJesse Barnes } else { 40627e22dbbbSTvrtko Ursulin if (IS_GEN2(dev_priv)) { 4063*6bcdb1c8SVille Syrjälä dev->driver->irq_preinstall = i8xx_irq_reset; 4064c2798b19SChris Wilson dev->driver->irq_postinstall = i8xx_irq_postinstall; 4065c2798b19SChris Wilson dev->driver->irq_handler = i8xx_irq_handler; 4066*6bcdb1c8SVille Syrjälä dev->driver->irq_uninstall = i8xx_irq_reset; 406786e83e35SChris Wilson dev->driver->enable_vblank = i8xx_enable_vblank; 406886e83e35SChris Wilson dev->driver->disable_vblank = i8xx_disable_vblank; 40697e22dbbbSTvrtko Ursulin } else if (IS_GEN3(dev_priv)) { 4070*6bcdb1c8SVille Syrjälä dev->driver->irq_preinstall = i915_irq_reset; 4071a266c7d5SChris Wilson dev->driver->irq_postinstall = i915_irq_postinstall; 4072*6bcdb1c8SVille Syrjälä dev->driver->irq_uninstall = i915_irq_reset; 4073a266c7d5SChris Wilson dev->driver->irq_handler = i915_irq_handler; 407486e83e35SChris Wilson dev->driver->enable_vblank = i8xx_enable_vblank; 407586e83e35SChris Wilson dev->driver->disable_vblank = i8xx_disable_vblank; 4076c2798b19SChris Wilson } else { 4077*6bcdb1c8SVille Syrjälä dev->driver->irq_preinstall = i965_irq_reset; 4078a266c7d5SChris Wilson dev->driver->irq_postinstall = i965_irq_postinstall; 4079*6bcdb1c8SVille Syrjälä dev->driver->irq_uninstall = i965_irq_reset; 4080a266c7d5SChris Wilson dev->driver->irq_handler = i965_irq_handler; 408186e83e35SChris Wilson dev->driver->enable_vblank = i965_enable_vblank; 408286e83e35SChris Wilson dev->driver->disable_vblank = i965_disable_vblank; 4083c2798b19SChris Wilson } 4084778eb334SVille Syrjälä if (I915_HAS_HOTPLUG(dev_priv)) 4085778eb334SVille Syrjälä dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 4086f71d4af4SJesse Barnes } 4087f71d4af4SJesse Barnes } 408820afbda2SDaniel Vetter 4089fca52a55SDaniel Vetter /** 4090cefcff8fSJoonas Lahtinen * intel_irq_fini - deinitializes IRQ support 4091cefcff8fSJoonas Lahtinen * @i915: i915 device instance 4092cefcff8fSJoonas Lahtinen * 4093cefcff8fSJoonas Lahtinen * This function deinitializes all the IRQ support. 4094cefcff8fSJoonas Lahtinen */ 4095cefcff8fSJoonas Lahtinen void intel_irq_fini(struct drm_i915_private *i915) 4096cefcff8fSJoonas Lahtinen { 4097cefcff8fSJoonas Lahtinen int i; 4098cefcff8fSJoonas Lahtinen 4099cefcff8fSJoonas Lahtinen for (i = 0; i < MAX_L3_SLICES; ++i) 4100cefcff8fSJoonas Lahtinen kfree(i915->l3_parity.remap_info[i]); 4101cefcff8fSJoonas Lahtinen } 4102cefcff8fSJoonas Lahtinen 4103cefcff8fSJoonas Lahtinen /** 4104fca52a55SDaniel Vetter * intel_irq_install - enables the hardware interrupt 4105fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4106fca52a55SDaniel Vetter * 4107fca52a55SDaniel Vetter * This function enables the hardware interrupt handling, but leaves the hotplug 4108fca52a55SDaniel Vetter * handling still disabled. It is called after intel_irq_init(). 4109fca52a55SDaniel Vetter * 4110fca52a55SDaniel Vetter * In the driver load and resume code we need working interrupts in a few places 4111fca52a55SDaniel Vetter * but don't want to deal with the hassle of concurrent probe and hotplug 4112fca52a55SDaniel Vetter * workers. Hence the split into this two-stage approach. 4113fca52a55SDaniel Vetter */ 41142aeb7d3aSDaniel Vetter int intel_irq_install(struct drm_i915_private *dev_priv) 41152aeb7d3aSDaniel Vetter { 41162aeb7d3aSDaniel Vetter /* 41172aeb7d3aSDaniel Vetter * We enable some interrupt sources in our postinstall hooks, so mark 41182aeb7d3aSDaniel Vetter * interrupts as enabled _before_ actually enabling them to avoid 41192aeb7d3aSDaniel Vetter * special cases in our ordering checks. 41202aeb7d3aSDaniel Vetter */ 41212aeb7d3aSDaniel Vetter dev_priv->pm.irqs_enabled = true; 41222aeb7d3aSDaniel Vetter 412391c8a326SChris Wilson return drm_irq_install(&dev_priv->drm, dev_priv->drm.pdev->irq); 41242aeb7d3aSDaniel Vetter } 41252aeb7d3aSDaniel Vetter 4126fca52a55SDaniel Vetter /** 4127fca52a55SDaniel Vetter * intel_irq_uninstall - finilizes all irq handling 4128fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4129fca52a55SDaniel Vetter * 4130fca52a55SDaniel Vetter * This stops interrupt and hotplug handling and unregisters and frees all 4131fca52a55SDaniel Vetter * resources acquired in the init functions. 4132fca52a55SDaniel Vetter */ 41332aeb7d3aSDaniel Vetter void intel_irq_uninstall(struct drm_i915_private *dev_priv) 41342aeb7d3aSDaniel Vetter { 413591c8a326SChris Wilson drm_irq_uninstall(&dev_priv->drm); 41362aeb7d3aSDaniel Vetter intel_hpd_cancel_work(dev_priv); 41372aeb7d3aSDaniel Vetter dev_priv->pm.irqs_enabled = false; 41382aeb7d3aSDaniel Vetter } 41392aeb7d3aSDaniel Vetter 4140fca52a55SDaniel Vetter /** 4141fca52a55SDaniel Vetter * intel_runtime_pm_disable_interrupts - runtime interrupt disabling 4142fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4143fca52a55SDaniel Vetter * 4144fca52a55SDaniel Vetter * This function is used to disable interrupts at runtime, both in the runtime 4145fca52a55SDaniel Vetter * pm and the system suspend/resume code. 4146fca52a55SDaniel Vetter */ 4147b963291cSDaniel Vetter void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv) 4148c67a470bSPaulo Zanoni { 414991c8a326SChris Wilson dev_priv->drm.driver->irq_uninstall(&dev_priv->drm); 41502aeb7d3aSDaniel Vetter dev_priv->pm.irqs_enabled = false; 415191c8a326SChris Wilson synchronize_irq(dev_priv->drm.irq); 4152c67a470bSPaulo Zanoni } 4153c67a470bSPaulo Zanoni 4154fca52a55SDaniel Vetter /** 4155fca52a55SDaniel Vetter * intel_runtime_pm_enable_interrupts - runtime interrupt enabling 4156fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4157fca52a55SDaniel Vetter * 4158fca52a55SDaniel Vetter * This function is used to enable interrupts at runtime, both in the runtime 4159fca52a55SDaniel Vetter * pm and the system suspend/resume code. 4160fca52a55SDaniel Vetter */ 4161b963291cSDaniel Vetter void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv) 4162c67a470bSPaulo Zanoni { 41632aeb7d3aSDaniel Vetter dev_priv->pm.irqs_enabled = true; 416491c8a326SChris Wilson dev_priv->drm.driver->irq_preinstall(&dev_priv->drm); 416591c8a326SChris Wilson dev_priv->drm.driver->irq_postinstall(&dev_priv->drm); 4166c67a470bSPaulo Zanoni } 4167