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 129f86f3fb0SPaulo Zanoni #define GEN5_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 139337ba017SPaulo Zanoni /* 140337ba017SPaulo Zanoni * We should clear IMR at preinstall/uninstall, and just check at postinstall. 141337ba017SPaulo Zanoni */ 142f0f59a00SVille Syrjälä static void gen5_assert_iir_is_zero(struct drm_i915_private *dev_priv, 143f0f59a00SVille Syrjälä i915_reg_t reg) 144b51a2842SVille Syrjälä { 145b51a2842SVille Syrjälä u32 val = I915_READ(reg); 146b51a2842SVille Syrjälä 147b51a2842SVille Syrjälä if (val == 0) 148b51a2842SVille Syrjälä return; 149b51a2842SVille Syrjälä 150b51a2842SVille Syrjälä WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n", 151f0f59a00SVille Syrjälä i915_mmio_reg_offset(reg), val); 152b51a2842SVille Syrjälä I915_WRITE(reg, 0xffffffff); 153b51a2842SVille Syrjälä POSTING_READ(reg); 154b51a2842SVille Syrjälä I915_WRITE(reg, 0xffffffff); 155b51a2842SVille Syrjälä POSTING_READ(reg); 156b51a2842SVille Syrjälä } 157337ba017SPaulo Zanoni 15835079899SPaulo Zanoni #define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \ 159b51a2842SVille Syrjälä gen5_assert_iir_is_zero(dev_priv, GEN8_##type##_IIR(which)); \ 16035079899SPaulo Zanoni I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \ 1617d1bd539SVille Syrjälä I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \ 1627d1bd539SVille Syrjälä POSTING_READ(GEN8_##type##_IMR(which)); \ 16335079899SPaulo Zanoni } while (0) 16435079899SPaulo Zanoni 16535079899SPaulo Zanoni #define GEN5_IRQ_INIT(type, imr_val, ier_val) do { \ 166b51a2842SVille Syrjälä gen5_assert_iir_is_zero(dev_priv, type##IIR); \ 16735079899SPaulo Zanoni I915_WRITE(type##IER, (ier_val)); \ 1687d1bd539SVille Syrjälä I915_WRITE(type##IMR, (imr_val)); \ 1697d1bd539SVille Syrjälä POSTING_READ(type##IMR); \ 17035079899SPaulo Zanoni } while (0) 17135079899SPaulo Zanoni 172c9a9a268SImre Deak static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir); 173c9a9a268SImre Deak 1740706f17cSEgbert Eich /* For display hotplug interrupt */ 1750706f17cSEgbert Eich static inline void 1760706f17cSEgbert Eich i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv, 1770706f17cSEgbert Eich uint32_t mask, 1780706f17cSEgbert Eich uint32_t bits) 1790706f17cSEgbert Eich { 1800706f17cSEgbert Eich uint32_t val; 1810706f17cSEgbert Eich 1820706f17cSEgbert Eich assert_spin_locked(&dev_priv->irq_lock); 1830706f17cSEgbert Eich WARN_ON(bits & ~mask); 1840706f17cSEgbert Eich 1850706f17cSEgbert Eich val = I915_READ(PORT_HOTPLUG_EN); 1860706f17cSEgbert Eich val &= ~mask; 1870706f17cSEgbert Eich val |= bits; 1880706f17cSEgbert Eich I915_WRITE(PORT_HOTPLUG_EN, val); 1890706f17cSEgbert Eich } 1900706f17cSEgbert Eich 1910706f17cSEgbert Eich /** 1920706f17cSEgbert Eich * i915_hotplug_interrupt_update - update hotplug interrupt enable 1930706f17cSEgbert Eich * @dev_priv: driver private 1940706f17cSEgbert Eich * @mask: bits to update 1950706f17cSEgbert Eich * @bits: bits to enable 1960706f17cSEgbert Eich * NOTE: the HPD enable bits are modified both inside and outside 1970706f17cSEgbert Eich * of an interrupt context. To avoid that read-modify-write cycles 1980706f17cSEgbert Eich * interfer, these bits are protected by a spinlock. Since this 1990706f17cSEgbert Eich * function is usually not called from a context where the lock is 2000706f17cSEgbert Eich * held already, this function acquires the lock itself. A non-locking 2010706f17cSEgbert Eich * version is also available. 2020706f17cSEgbert Eich */ 2030706f17cSEgbert Eich void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv, 2040706f17cSEgbert Eich uint32_t mask, 2050706f17cSEgbert Eich uint32_t bits) 2060706f17cSEgbert Eich { 2070706f17cSEgbert Eich spin_lock_irq(&dev_priv->irq_lock); 2080706f17cSEgbert Eich i915_hotplug_interrupt_update_locked(dev_priv, mask, bits); 2090706f17cSEgbert Eich spin_unlock_irq(&dev_priv->irq_lock); 2100706f17cSEgbert Eich } 2110706f17cSEgbert Eich 212d9dc34f1SVille Syrjälä /** 213d9dc34f1SVille Syrjälä * ilk_update_display_irq - update DEIMR 214d9dc34f1SVille Syrjälä * @dev_priv: driver private 215d9dc34f1SVille Syrjälä * @interrupt_mask: mask of interrupt bits to update 216d9dc34f1SVille Syrjälä * @enabled_irq_mask: mask of interrupt bits to enable 217d9dc34f1SVille Syrjälä */ 218fbdedaeaSVille Syrjälä void ilk_update_display_irq(struct drm_i915_private *dev_priv, 219d9dc34f1SVille Syrjälä uint32_t interrupt_mask, 220d9dc34f1SVille Syrjälä uint32_t enabled_irq_mask) 221036a4a7dSZhenyu Wang { 222d9dc34f1SVille Syrjälä uint32_t new_val; 223d9dc34f1SVille Syrjälä 2244bc9d430SDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 2254bc9d430SDaniel Vetter 226d9dc34f1SVille Syrjälä WARN_ON(enabled_irq_mask & ~interrupt_mask); 227d9dc34f1SVille Syrjälä 2289df7575fSJesse Barnes if (WARN_ON(!intel_irqs_enabled(dev_priv))) 229c67a470bSPaulo Zanoni return; 230c67a470bSPaulo Zanoni 231d9dc34f1SVille Syrjälä new_val = dev_priv->irq_mask; 232d9dc34f1SVille Syrjälä new_val &= ~interrupt_mask; 233d9dc34f1SVille Syrjälä new_val |= (~enabled_irq_mask & interrupt_mask); 234d9dc34f1SVille Syrjälä 235d9dc34f1SVille Syrjälä if (new_val != dev_priv->irq_mask) { 236d9dc34f1SVille Syrjälä dev_priv->irq_mask = new_val; 2371ec14ad3SChris Wilson I915_WRITE(DEIMR, dev_priv->irq_mask); 2383143a2bfSChris Wilson POSTING_READ(DEIMR); 239036a4a7dSZhenyu Wang } 240036a4a7dSZhenyu Wang } 241036a4a7dSZhenyu Wang 24243eaea13SPaulo Zanoni /** 24343eaea13SPaulo Zanoni * ilk_update_gt_irq - update GTIMR 24443eaea13SPaulo Zanoni * @dev_priv: driver private 24543eaea13SPaulo Zanoni * @interrupt_mask: mask of interrupt bits to update 24643eaea13SPaulo Zanoni * @enabled_irq_mask: mask of interrupt bits to enable 24743eaea13SPaulo Zanoni */ 24843eaea13SPaulo Zanoni static void ilk_update_gt_irq(struct drm_i915_private *dev_priv, 24943eaea13SPaulo Zanoni uint32_t interrupt_mask, 25043eaea13SPaulo Zanoni uint32_t enabled_irq_mask) 25143eaea13SPaulo Zanoni { 25243eaea13SPaulo Zanoni assert_spin_locked(&dev_priv->irq_lock); 25343eaea13SPaulo Zanoni 25415a17aaeSDaniel Vetter WARN_ON(enabled_irq_mask & ~interrupt_mask); 25515a17aaeSDaniel Vetter 2569df7575fSJesse Barnes if (WARN_ON(!intel_irqs_enabled(dev_priv))) 257c67a470bSPaulo Zanoni return; 258c67a470bSPaulo Zanoni 25943eaea13SPaulo Zanoni dev_priv->gt_irq_mask &= ~interrupt_mask; 26043eaea13SPaulo Zanoni dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask); 26143eaea13SPaulo Zanoni I915_WRITE(GTIMR, dev_priv->gt_irq_mask); 26243eaea13SPaulo Zanoni } 26343eaea13SPaulo Zanoni 264480c8033SDaniel Vetter void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask) 26543eaea13SPaulo Zanoni { 26643eaea13SPaulo Zanoni ilk_update_gt_irq(dev_priv, mask, mask); 26731bb59ccSChris Wilson POSTING_READ_FW(GTIMR); 26843eaea13SPaulo Zanoni } 26943eaea13SPaulo Zanoni 270480c8033SDaniel Vetter void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask) 27143eaea13SPaulo Zanoni { 27243eaea13SPaulo Zanoni ilk_update_gt_irq(dev_priv, mask, 0); 27343eaea13SPaulo Zanoni } 27443eaea13SPaulo Zanoni 275f0f59a00SVille Syrjälä static i915_reg_t gen6_pm_iir(struct drm_i915_private *dev_priv) 276b900b949SImre Deak { 277b900b949SImre Deak return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR; 278b900b949SImre Deak } 279b900b949SImre Deak 280f0f59a00SVille Syrjälä static i915_reg_t gen6_pm_imr(struct drm_i915_private *dev_priv) 281a72fbc3aSImre Deak { 282a72fbc3aSImre Deak return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IMR(2) : GEN6_PMIMR; 283a72fbc3aSImre Deak } 284a72fbc3aSImre Deak 285f0f59a00SVille Syrjälä static i915_reg_t gen6_pm_ier(struct drm_i915_private *dev_priv) 286b900b949SImre Deak { 287b900b949SImre Deak return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IER(2) : GEN6_PMIER; 288b900b949SImre Deak } 289b900b949SImre Deak 290edbfdb45SPaulo Zanoni /** 291edbfdb45SPaulo Zanoni * snb_update_pm_irq - update GEN6_PMIMR 292edbfdb45SPaulo Zanoni * @dev_priv: driver private 293edbfdb45SPaulo Zanoni * @interrupt_mask: mask of interrupt bits to update 294edbfdb45SPaulo Zanoni * @enabled_irq_mask: mask of interrupt bits to enable 295edbfdb45SPaulo Zanoni */ 296edbfdb45SPaulo Zanoni static void snb_update_pm_irq(struct drm_i915_private *dev_priv, 297edbfdb45SPaulo Zanoni uint32_t interrupt_mask, 298edbfdb45SPaulo Zanoni uint32_t enabled_irq_mask) 299edbfdb45SPaulo Zanoni { 300605cd25bSPaulo Zanoni uint32_t new_val; 301edbfdb45SPaulo Zanoni 30215a17aaeSDaniel Vetter WARN_ON(enabled_irq_mask & ~interrupt_mask); 30315a17aaeSDaniel Vetter 304edbfdb45SPaulo Zanoni assert_spin_locked(&dev_priv->irq_lock); 305edbfdb45SPaulo Zanoni 306605cd25bSPaulo Zanoni new_val = dev_priv->pm_irq_mask; 307f52ecbcfSPaulo Zanoni new_val &= ~interrupt_mask; 308f52ecbcfSPaulo Zanoni new_val |= (~enabled_irq_mask & interrupt_mask); 309f52ecbcfSPaulo Zanoni 310605cd25bSPaulo Zanoni if (new_val != dev_priv->pm_irq_mask) { 311605cd25bSPaulo Zanoni dev_priv->pm_irq_mask = new_val; 312a72fbc3aSImre Deak I915_WRITE(gen6_pm_imr(dev_priv), dev_priv->pm_irq_mask); 313a72fbc3aSImre Deak POSTING_READ(gen6_pm_imr(dev_priv)); 314edbfdb45SPaulo Zanoni } 315f52ecbcfSPaulo Zanoni } 316edbfdb45SPaulo Zanoni 317480c8033SDaniel Vetter void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask) 318edbfdb45SPaulo Zanoni { 3199939fba2SImre Deak if (WARN_ON(!intel_irqs_enabled(dev_priv))) 3209939fba2SImre Deak return; 3219939fba2SImre Deak 322edbfdb45SPaulo Zanoni snb_update_pm_irq(dev_priv, mask, mask); 323edbfdb45SPaulo Zanoni } 324edbfdb45SPaulo Zanoni 3259939fba2SImre Deak static void __gen6_disable_pm_irq(struct drm_i915_private *dev_priv, 3269939fba2SImre Deak uint32_t mask) 3279939fba2SImre Deak { 3289939fba2SImre Deak snb_update_pm_irq(dev_priv, mask, 0); 3299939fba2SImre Deak } 3309939fba2SImre Deak 331480c8033SDaniel Vetter void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask) 332edbfdb45SPaulo Zanoni { 3339939fba2SImre Deak if (WARN_ON(!intel_irqs_enabled(dev_priv))) 3349939fba2SImre Deak return; 3359939fba2SImre Deak 3369939fba2SImre Deak __gen6_disable_pm_irq(dev_priv, mask); 337edbfdb45SPaulo Zanoni } 338edbfdb45SPaulo Zanoni 339dc97997aSChris Wilson void gen6_reset_rps_interrupts(struct drm_i915_private *dev_priv) 3403cc134e3SImre Deak { 341f0f59a00SVille Syrjälä i915_reg_t reg = gen6_pm_iir(dev_priv); 3423cc134e3SImre Deak 3433cc134e3SImre Deak spin_lock_irq(&dev_priv->irq_lock); 3443cc134e3SImre Deak I915_WRITE(reg, dev_priv->pm_rps_events); 3453cc134e3SImre Deak I915_WRITE(reg, dev_priv->pm_rps_events); 3463cc134e3SImre Deak POSTING_READ(reg); 347096fad9eSImre Deak dev_priv->rps.pm_iir = 0; 3483cc134e3SImre Deak spin_unlock_irq(&dev_priv->irq_lock); 3493cc134e3SImre Deak } 3503cc134e3SImre Deak 35191d14251STvrtko Ursulin void gen6_enable_rps_interrupts(struct drm_i915_private *dev_priv) 352b900b949SImre Deak { 353b900b949SImre Deak spin_lock_irq(&dev_priv->irq_lock); 354c33d247dSChris Wilson WARN_ON_ONCE(dev_priv->rps.pm_iir); 355c33d247dSChris Wilson WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events); 356d4d70aa5SImre Deak dev_priv->rps.interrupts_enabled = true; 35778e68d36SImre Deak I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) | 35878e68d36SImre Deak dev_priv->pm_rps_events); 359b900b949SImre Deak gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events); 36078e68d36SImre Deak 361b900b949SImre Deak spin_unlock_irq(&dev_priv->irq_lock); 362b900b949SImre Deak } 363b900b949SImre Deak 36459d02a1fSImre Deak u32 gen6_sanitize_rps_pm_mask(struct drm_i915_private *dev_priv, u32 mask) 36559d02a1fSImre Deak { 3661800ad25SSagar Arun Kamble return (mask & ~dev_priv->rps.pm_intr_keep); 36759d02a1fSImre Deak } 36859d02a1fSImre Deak 36991d14251STvrtko Ursulin void gen6_disable_rps_interrupts(struct drm_i915_private *dev_priv) 370b900b949SImre Deak { 371d4d70aa5SImre Deak spin_lock_irq(&dev_priv->irq_lock); 372d4d70aa5SImre Deak dev_priv->rps.interrupts_enabled = false; 3739939fba2SImre Deak 37459d02a1fSImre Deak I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0)); 3759939fba2SImre Deak 3769939fba2SImre Deak __gen6_disable_pm_irq(dev_priv, dev_priv->pm_rps_events); 377b900b949SImre Deak I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) & 378b900b949SImre Deak ~dev_priv->pm_rps_events); 37958072ccbSImre Deak 38058072ccbSImre Deak spin_unlock_irq(&dev_priv->irq_lock); 38191c8a326SChris Wilson synchronize_irq(dev_priv->drm.irq); 382c33d247dSChris Wilson 383c33d247dSChris Wilson /* Now that we will not be generating any more work, flush any 384c33d247dSChris Wilson * outsanding tasks. As we are called on the RPS idle path, 385c33d247dSChris Wilson * we will reset the GPU to minimum frequencies, so the current 386c33d247dSChris Wilson * state of the worker can be discarded. 387c33d247dSChris Wilson */ 388c33d247dSChris Wilson cancel_work_sync(&dev_priv->rps.work); 389c33d247dSChris Wilson gen6_reset_rps_interrupts(dev_priv); 390b900b949SImre Deak } 391b900b949SImre Deak 3920961021aSBen Widawsky /** 3933a3b3c7dSVille Syrjälä * bdw_update_port_irq - update DE port interrupt 3943a3b3c7dSVille Syrjälä * @dev_priv: driver private 3953a3b3c7dSVille Syrjälä * @interrupt_mask: mask of interrupt bits to update 3963a3b3c7dSVille Syrjälä * @enabled_irq_mask: mask of interrupt bits to enable 3973a3b3c7dSVille Syrjälä */ 3983a3b3c7dSVille Syrjälä static void bdw_update_port_irq(struct drm_i915_private *dev_priv, 3993a3b3c7dSVille Syrjälä uint32_t interrupt_mask, 4003a3b3c7dSVille Syrjälä uint32_t enabled_irq_mask) 4013a3b3c7dSVille Syrjälä { 4023a3b3c7dSVille Syrjälä uint32_t new_val; 4033a3b3c7dSVille Syrjälä uint32_t old_val; 4043a3b3c7dSVille Syrjälä 4053a3b3c7dSVille Syrjälä assert_spin_locked(&dev_priv->irq_lock); 4063a3b3c7dSVille Syrjälä 4073a3b3c7dSVille Syrjälä WARN_ON(enabled_irq_mask & ~interrupt_mask); 4083a3b3c7dSVille Syrjälä 4093a3b3c7dSVille Syrjälä if (WARN_ON(!intel_irqs_enabled(dev_priv))) 4103a3b3c7dSVille Syrjälä return; 4113a3b3c7dSVille Syrjälä 4123a3b3c7dSVille Syrjälä old_val = I915_READ(GEN8_DE_PORT_IMR); 4133a3b3c7dSVille Syrjälä 4143a3b3c7dSVille Syrjälä new_val = old_val; 4153a3b3c7dSVille Syrjälä new_val &= ~interrupt_mask; 4163a3b3c7dSVille Syrjälä new_val |= (~enabled_irq_mask & interrupt_mask); 4173a3b3c7dSVille Syrjälä 4183a3b3c7dSVille Syrjälä if (new_val != old_val) { 4193a3b3c7dSVille Syrjälä I915_WRITE(GEN8_DE_PORT_IMR, new_val); 4203a3b3c7dSVille Syrjälä POSTING_READ(GEN8_DE_PORT_IMR); 4213a3b3c7dSVille Syrjälä } 4223a3b3c7dSVille Syrjälä } 4233a3b3c7dSVille Syrjälä 4243a3b3c7dSVille Syrjälä /** 425013d3752SVille Syrjälä * bdw_update_pipe_irq - update DE pipe interrupt 426013d3752SVille Syrjälä * @dev_priv: driver private 427013d3752SVille Syrjälä * @pipe: pipe whose interrupt to update 428013d3752SVille Syrjälä * @interrupt_mask: mask of interrupt bits to update 429013d3752SVille Syrjälä * @enabled_irq_mask: mask of interrupt bits to enable 430013d3752SVille Syrjälä */ 431013d3752SVille Syrjälä void bdw_update_pipe_irq(struct drm_i915_private *dev_priv, 432013d3752SVille Syrjälä enum pipe pipe, 433013d3752SVille Syrjälä uint32_t interrupt_mask, 434013d3752SVille Syrjälä uint32_t enabled_irq_mask) 435013d3752SVille Syrjälä { 436013d3752SVille Syrjälä uint32_t new_val; 437013d3752SVille Syrjälä 438013d3752SVille Syrjälä assert_spin_locked(&dev_priv->irq_lock); 439013d3752SVille Syrjälä 440013d3752SVille Syrjälä WARN_ON(enabled_irq_mask & ~interrupt_mask); 441013d3752SVille Syrjälä 442013d3752SVille Syrjälä if (WARN_ON(!intel_irqs_enabled(dev_priv))) 443013d3752SVille Syrjälä return; 444013d3752SVille Syrjälä 445013d3752SVille Syrjälä new_val = dev_priv->de_irq_mask[pipe]; 446013d3752SVille Syrjälä new_val &= ~interrupt_mask; 447013d3752SVille Syrjälä new_val |= (~enabled_irq_mask & interrupt_mask); 448013d3752SVille Syrjälä 449013d3752SVille Syrjälä if (new_val != dev_priv->de_irq_mask[pipe]) { 450013d3752SVille Syrjälä dev_priv->de_irq_mask[pipe] = new_val; 451013d3752SVille Syrjälä I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]); 452013d3752SVille Syrjälä POSTING_READ(GEN8_DE_PIPE_IMR(pipe)); 453013d3752SVille Syrjälä } 454013d3752SVille Syrjälä } 455013d3752SVille Syrjälä 456013d3752SVille Syrjälä /** 457fee884edSDaniel Vetter * ibx_display_interrupt_update - update SDEIMR 458fee884edSDaniel Vetter * @dev_priv: driver private 459fee884edSDaniel Vetter * @interrupt_mask: mask of interrupt bits to update 460fee884edSDaniel Vetter * @enabled_irq_mask: mask of interrupt bits to enable 461fee884edSDaniel Vetter */ 46247339cd9SDaniel Vetter void ibx_display_interrupt_update(struct drm_i915_private *dev_priv, 463fee884edSDaniel Vetter uint32_t interrupt_mask, 464fee884edSDaniel Vetter uint32_t enabled_irq_mask) 465fee884edSDaniel Vetter { 466fee884edSDaniel Vetter uint32_t sdeimr = I915_READ(SDEIMR); 467fee884edSDaniel Vetter sdeimr &= ~interrupt_mask; 468fee884edSDaniel Vetter sdeimr |= (~enabled_irq_mask & interrupt_mask); 469fee884edSDaniel Vetter 47015a17aaeSDaniel Vetter WARN_ON(enabled_irq_mask & ~interrupt_mask); 47115a17aaeSDaniel Vetter 472fee884edSDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 473fee884edSDaniel Vetter 4749df7575fSJesse Barnes if (WARN_ON(!intel_irqs_enabled(dev_priv))) 475c67a470bSPaulo Zanoni return; 476c67a470bSPaulo Zanoni 477fee884edSDaniel Vetter I915_WRITE(SDEIMR, sdeimr); 478fee884edSDaniel Vetter POSTING_READ(SDEIMR); 479fee884edSDaniel Vetter } 4808664281bSPaulo Zanoni 481b5ea642aSDaniel Vetter static void 482755e9019SImre Deak __i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 483755e9019SImre Deak u32 enable_mask, u32 status_mask) 4847c463586SKeith Packard { 485f0f59a00SVille Syrjälä i915_reg_t reg = PIPESTAT(pipe); 486755e9019SImre Deak u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK; 4877c463586SKeith Packard 488b79480baSDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 489d518ce50SDaniel Vetter WARN_ON(!intel_irqs_enabled(dev_priv)); 490b79480baSDaniel Vetter 49104feced9SVille Syrjälä if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK || 49204feced9SVille Syrjälä status_mask & ~PIPESTAT_INT_STATUS_MASK, 49304feced9SVille Syrjälä "pipe %c: enable_mask=0x%x, status_mask=0x%x\n", 49404feced9SVille Syrjälä pipe_name(pipe), enable_mask, status_mask)) 495755e9019SImre Deak return; 496755e9019SImre Deak 497755e9019SImre Deak if ((pipestat & enable_mask) == enable_mask) 49846c06a30SVille Syrjälä return; 49946c06a30SVille Syrjälä 50091d181ddSImre Deak dev_priv->pipestat_irq_mask[pipe] |= status_mask; 50191d181ddSImre Deak 5027c463586SKeith Packard /* Enable the interrupt, clear any pending status */ 503755e9019SImre Deak pipestat |= enable_mask | status_mask; 50446c06a30SVille Syrjälä I915_WRITE(reg, pipestat); 5053143a2bfSChris Wilson POSTING_READ(reg); 5067c463586SKeith Packard } 5077c463586SKeith Packard 508b5ea642aSDaniel Vetter static void 509755e9019SImre Deak __i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 510755e9019SImre Deak u32 enable_mask, u32 status_mask) 5117c463586SKeith Packard { 512f0f59a00SVille Syrjälä i915_reg_t reg = PIPESTAT(pipe); 513755e9019SImre Deak u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK; 5147c463586SKeith Packard 515b79480baSDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 516d518ce50SDaniel Vetter WARN_ON(!intel_irqs_enabled(dev_priv)); 517b79480baSDaniel Vetter 51804feced9SVille Syrjälä if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK || 51904feced9SVille Syrjälä status_mask & ~PIPESTAT_INT_STATUS_MASK, 52004feced9SVille Syrjälä "pipe %c: enable_mask=0x%x, status_mask=0x%x\n", 52104feced9SVille Syrjälä pipe_name(pipe), enable_mask, status_mask)) 52246c06a30SVille Syrjälä return; 52346c06a30SVille Syrjälä 524755e9019SImre Deak if ((pipestat & enable_mask) == 0) 525755e9019SImre Deak return; 526755e9019SImre Deak 52791d181ddSImre Deak dev_priv->pipestat_irq_mask[pipe] &= ~status_mask; 52891d181ddSImre Deak 529755e9019SImre Deak pipestat &= ~enable_mask; 53046c06a30SVille Syrjälä I915_WRITE(reg, pipestat); 5313143a2bfSChris Wilson POSTING_READ(reg); 5327c463586SKeith Packard } 5337c463586SKeith Packard 53410c59c51SImre Deak static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask) 53510c59c51SImre Deak { 53610c59c51SImre Deak u32 enable_mask = status_mask << 16; 53710c59c51SImre Deak 53810c59c51SImre Deak /* 539724a6905SVille Syrjälä * On pipe A we don't support the PSR interrupt yet, 540724a6905SVille Syrjälä * on pipe B and C the same bit MBZ. 54110c59c51SImre Deak */ 54210c59c51SImre Deak if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV)) 54310c59c51SImre Deak return 0; 544724a6905SVille Syrjälä /* 545724a6905SVille Syrjälä * On pipe B and C we don't support the PSR interrupt yet, on pipe 546724a6905SVille Syrjälä * A the same bit is for perf counters which we don't use either. 547724a6905SVille Syrjälä */ 548724a6905SVille Syrjälä if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV)) 549724a6905SVille Syrjälä return 0; 55010c59c51SImre Deak 55110c59c51SImre Deak enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS | 55210c59c51SImre Deak SPRITE0_FLIP_DONE_INT_EN_VLV | 55310c59c51SImre Deak SPRITE1_FLIP_DONE_INT_EN_VLV); 55410c59c51SImre Deak if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV) 55510c59c51SImre Deak enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV; 55610c59c51SImre Deak if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV) 55710c59c51SImre Deak enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV; 55810c59c51SImre Deak 55910c59c51SImre Deak return enable_mask; 56010c59c51SImre Deak } 56110c59c51SImre Deak 562755e9019SImre Deak void 563755e9019SImre Deak i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 564755e9019SImre Deak u32 status_mask) 565755e9019SImre Deak { 566755e9019SImre Deak u32 enable_mask; 567755e9019SImre Deak 568666a4537SWayne Boyer if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) 56991c8a326SChris Wilson enable_mask = vlv_get_pipestat_enable_mask(&dev_priv->drm, 57010c59c51SImre Deak status_mask); 57110c59c51SImre Deak else 572755e9019SImre Deak enable_mask = status_mask << 16; 573755e9019SImre Deak __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask); 574755e9019SImre Deak } 575755e9019SImre Deak 576755e9019SImre Deak void 577755e9019SImre Deak i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 578755e9019SImre Deak u32 status_mask) 579755e9019SImre Deak { 580755e9019SImre Deak u32 enable_mask; 581755e9019SImre Deak 582666a4537SWayne Boyer if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) 58391c8a326SChris Wilson enable_mask = vlv_get_pipestat_enable_mask(&dev_priv->drm, 58410c59c51SImre Deak status_mask); 58510c59c51SImre Deak else 586755e9019SImre Deak enable_mask = status_mask << 16; 587755e9019SImre Deak __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask); 588755e9019SImre Deak } 589755e9019SImre Deak 590c0e09200SDave Airlie /** 591f49e38ddSJani Nikula * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion 59214bb2c11STvrtko Ursulin * @dev_priv: i915 device private 59301c66889SZhao Yakui */ 59491d14251STvrtko Ursulin static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv) 59501c66889SZhao Yakui { 59691d14251STvrtko Ursulin if (!dev_priv->opregion.asle || !IS_MOBILE(dev_priv)) 597f49e38ddSJani Nikula return; 598f49e38ddSJani Nikula 59913321786SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 60001c66889SZhao Yakui 601755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS); 60291d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 4) 6033b6c42e8SDaniel Vetter i915_enable_pipestat(dev_priv, PIPE_A, 604755e9019SImre Deak PIPE_LEGACY_BLC_EVENT_STATUS); 6051ec14ad3SChris Wilson 60613321786SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 60701c66889SZhao Yakui } 60801c66889SZhao Yakui 609f75f3746SVille Syrjälä /* 610f75f3746SVille Syrjälä * This timing diagram depicts the video signal in and 611f75f3746SVille Syrjälä * around the vertical blanking period. 612f75f3746SVille Syrjälä * 613f75f3746SVille Syrjälä * Assumptions about the fictitious mode used in this example: 614f75f3746SVille Syrjälä * vblank_start >= 3 615f75f3746SVille Syrjälä * vsync_start = vblank_start + 1 616f75f3746SVille Syrjälä * vsync_end = vblank_start + 2 617f75f3746SVille Syrjälä * vtotal = vblank_start + 3 618f75f3746SVille Syrjälä * 619f75f3746SVille Syrjälä * start of vblank: 620f75f3746SVille Syrjälä * latch double buffered registers 621f75f3746SVille Syrjälä * increment frame counter (ctg+) 622f75f3746SVille Syrjälä * generate start of vblank interrupt (gen4+) 623f75f3746SVille Syrjälä * | 624f75f3746SVille Syrjälä * | frame start: 625f75f3746SVille Syrjälä * | generate frame start interrupt (aka. vblank interrupt) (gmch) 626f75f3746SVille Syrjälä * | may be shifted forward 1-3 extra lines via PIPECONF 627f75f3746SVille Syrjälä * | | 628f75f3746SVille Syrjälä * | | start of vsync: 629f75f3746SVille Syrjälä * | | generate vsync interrupt 630f75f3746SVille Syrjälä * | | | 631f75f3746SVille Syrjälä * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx 632f75f3746SVille Syrjälä * . \hs/ . \hs/ \hs/ \hs/ . \hs/ 633f75f3746SVille Syrjälä * ----va---> <-----------------vb--------------------> <--------va------------- 634f75f3746SVille Syrjälä * | | <----vs-----> | 635f75f3746SVille Syrjälä * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2) 636f75f3746SVille Syrjälä * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+) 637f75f3746SVille Syrjälä * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi) 638f75f3746SVille Syrjälä * | | | 639f75f3746SVille Syrjälä * last visible pixel first visible pixel 640f75f3746SVille Syrjälä * | increment frame counter (gen3/4) 641f75f3746SVille Syrjälä * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4) 642f75f3746SVille Syrjälä * 643f75f3746SVille Syrjälä * x = horizontal active 644f75f3746SVille Syrjälä * _ = horizontal blanking 645f75f3746SVille Syrjälä * hs = horizontal sync 646f75f3746SVille Syrjälä * va = vertical active 647f75f3746SVille Syrjälä * vb = vertical blanking 648f75f3746SVille Syrjälä * vs = vertical sync 649f75f3746SVille Syrjälä * vbs = vblank_start (number) 650f75f3746SVille Syrjälä * 651f75f3746SVille Syrjälä * Summary: 652f75f3746SVille Syrjälä * - most events happen at the start of horizontal sync 653f75f3746SVille Syrjälä * - frame start happens at the start of horizontal blank, 1-4 lines 654f75f3746SVille Syrjälä * (depending on PIPECONF settings) after the start of vblank 655f75f3746SVille Syrjälä * - gen3/4 pixel and frame counter are synchronized with the start 656f75f3746SVille Syrjälä * of horizontal active on the first line of vertical active 657f75f3746SVille Syrjälä */ 658f75f3746SVille Syrjälä 65942f52ef8SKeith Packard /* Called from drm generic code, passed a 'crtc', which 66042f52ef8SKeith Packard * we use as a pipe index 66142f52ef8SKeith Packard */ 66288e72717SThierry Reding static u32 i915_get_vblank_counter(struct drm_device *dev, unsigned int pipe) 6630a3e67a4SJesse Barnes { 664fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 665f0f59a00SVille Syrjälä i915_reg_t high_frame, low_frame; 6660b2a8e09SVille Syrjälä u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal; 667391f75e2SVille Syrjälä struct intel_crtc *intel_crtc = 668391f75e2SVille Syrjälä to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); 669fc467a22SMaarten Lankhorst const struct drm_display_mode *mode = &intel_crtc->base.hwmode; 670391f75e2SVille Syrjälä 6710b2a8e09SVille Syrjälä htotal = mode->crtc_htotal; 6720b2a8e09SVille Syrjälä hsync_start = mode->crtc_hsync_start; 6730b2a8e09SVille Syrjälä vbl_start = mode->crtc_vblank_start; 6740b2a8e09SVille Syrjälä if (mode->flags & DRM_MODE_FLAG_INTERLACE) 6750b2a8e09SVille Syrjälä vbl_start = DIV_ROUND_UP(vbl_start, 2); 676391f75e2SVille Syrjälä 6770b2a8e09SVille Syrjälä /* Convert to pixel count */ 6780b2a8e09SVille Syrjälä vbl_start *= htotal; 6790b2a8e09SVille Syrjälä 6800b2a8e09SVille Syrjälä /* Start of vblank event occurs at start of hsync */ 6810b2a8e09SVille Syrjälä vbl_start -= htotal - hsync_start; 6820b2a8e09SVille Syrjälä 6839db4a9c7SJesse Barnes high_frame = PIPEFRAME(pipe); 6849db4a9c7SJesse Barnes low_frame = PIPEFRAMEPIXEL(pipe); 6855eddb70bSChris Wilson 6860a3e67a4SJesse Barnes /* 6870a3e67a4SJesse Barnes * High & low register fields aren't synchronized, so make sure 6880a3e67a4SJesse Barnes * we get a low value that's stable across two reads of the high 6890a3e67a4SJesse Barnes * register. 6900a3e67a4SJesse Barnes */ 6910a3e67a4SJesse Barnes do { 6925eddb70bSChris Wilson high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; 693391f75e2SVille Syrjälä low = I915_READ(low_frame); 6945eddb70bSChris Wilson high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; 6950a3e67a4SJesse Barnes } while (high1 != high2); 6960a3e67a4SJesse Barnes 6975eddb70bSChris Wilson high1 >>= PIPE_FRAME_HIGH_SHIFT; 698391f75e2SVille Syrjälä pixel = low & PIPE_PIXEL_MASK; 6995eddb70bSChris Wilson low >>= PIPE_FRAME_LOW_SHIFT; 700391f75e2SVille Syrjälä 701391f75e2SVille Syrjälä /* 702391f75e2SVille Syrjälä * The frame counter increments at beginning of active. 703391f75e2SVille Syrjälä * Cook up a vblank counter by also checking the pixel 704391f75e2SVille Syrjälä * counter against vblank start. 705391f75e2SVille Syrjälä */ 706edc08d0aSVille Syrjälä return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff; 7070a3e67a4SJesse Barnes } 7080a3e67a4SJesse Barnes 709974e59baSDave Airlie static u32 g4x_get_vblank_counter(struct drm_device *dev, unsigned int pipe) 7109880b7a5SJesse Barnes { 711fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 7129880b7a5SJesse Barnes 713649636efSVille Syrjälä return I915_READ(PIPE_FRMCOUNT_G4X(pipe)); 7149880b7a5SJesse Barnes } 7159880b7a5SJesse Barnes 71675aa3f63SVille Syrjälä /* I915_READ_FW, only for fast reads of display block, no need for forcewake etc. */ 717a225f079SVille Syrjälä static int __intel_get_crtc_scanline(struct intel_crtc *crtc) 718a225f079SVille Syrjälä { 719a225f079SVille Syrjälä struct drm_device *dev = crtc->base.dev; 720fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 721fc467a22SMaarten Lankhorst const struct drm_display_mode *mode = &crtc->base.hwmode; 722a225f079SVille Syrjälä enum pipe pipe = crtc->pipe; 72380715b2fSVille Syrjälä int position, vtotal; 724a225f079SVille Syrjälä 72580715b2fSVille Syrjälä vtotal = mode->crtc_vtotal; 726a225f079SVille Syrjälä if (mode->flags & DRM_MODE_FLAG_INTERLACE) 727a225f079SVille Syrjälä vtotal /= 2; 728a225f079SVille Syrjälä 72991d14251STvrtko Ursulin if (IS_GEN2(dev_priv)) 73075aa3f63SVille Syrjälä position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2; 731a225f079SVille Syrjälä else 73275aa3f63SVille Syrjälä position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3; 733a225f079SVille Syrjälä 734a225f079SVille Syrjälä /* 73541b578fbSJesse Barnes * On HSW, the DSL reg (0x70000) appears to return 0 if we 73641b578fbSJesse Barnes * read it just before the start of vblank. So try it again 73741b578fbSJesse Barnes * so we don't accidentally end up spanning a vblank frame 73841b578fbSJesse Barnes * increment, causing the pipe_update_end() code to squak at us. 73941b578fbSJesse Barnes * 74041b578fbSJesse Barnes * The nature of this problem means we can't simply check the ISR 74141b578fbSJesse Barnes * bit and return the vblank start value; nor can we use the scanline 74241b578fbSJesse Barnes * debug register in the transcoder as it appears to have the same 74341b578fbSJesse Barnes * problem. We may need to extend this to include other platforms, 74441b578fbSJesse Barnes * but so far testing only shows the problem on HSW. 74541b578fbSJesse Barnes */ 74691d14251STvrtko Ursulin if (HAS_DDI(dev_priv) && !position) { 74741b578fbSJesse Barnes int i, temp; 74841b578fbSJesse Barnes 74941b578fbSJesse Barnes for (i = 0; i < 100; i++) { 75041b578fbSJesse Barnes udelay(1); 75141b578fbSJesse Barnes temp = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & 75241b578fbSJesse Barnes DSL_LINEMASK_GEN3; 75341b578fbSJesse Barnes if (temp != position) { 75441b578fbSJesse Barnes position = temp; 75541b578fbSJesse Barnes break; 75641b578fbSJesse Barnes } 75741b578fbSJesse Barnes } 75841b578fbSJesse Barnes } 75941b578fbSJesse Barnes 76041b578fbSJesse Barnes /* 76180715b2fSVille Syrjälä * See update_scanline_offset() for the details on the 76280715b2fSVille Syrjälä * scanline_offset adjustment. 763a225f079SVille Syrjälä */ 76480715b2fSVille Syrjälä return (position + crtc->scanline_offset) % vtotal; 765a225f079SVille Syrjälä } 766a225f079SVille Syrjälä 76788e72717SThierry Reding static int i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe, 768abca9e45SVille Syrjälä unsigned int flags, int *vpos, int *hpos, 7693bb403bfSVille Syrjälä ktime_t *stime, ktime_t *etime, 7703bb403bfSVille Syrjälä const struct drm_display_mode *mode) 7710af7e4dfSMario Kleiner { 772fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 773c2baf4b7SVille Syrjälä struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 774c2baf4b7SVille Syrjälä struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 7753aa18df8SVille Syrjälä int position; 77678e8fc6bSVille Syrjälä int vbl_start, vbl_end, hsync_start, htotal, vtotal; 7770af7e4dfSMario Kleiner bool in_vbl = true; 7780af7e4dfSMario Kleiner int ret = 0; 779ad3543edSMario Kleiner unsigned long irqflags; 7800af7e4dfSMario Kleiner 781fc467a22SMaarten Lankhorst if (WARN_ON(!mode->crtc_clock)) { 7820af7e4dfSMario Kleiner DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled " 7839db4a9c7SJesse Barnes "pipe %c\n", pipe_name(pipe)); 7840af7e4dfSMario Kleiner return 0; 7850af7e4dfSMario Kleiner } 7860af7e4dfSMario Kleiner 787c2baf4b7SVille Syrjälä htotal = mode->crtc_htotal; 78878e8fc6bSVille Syrjälä hsync_start = mode->crtc_hsync_start; 789c2baf4b7SVille Syrjälä vtotal = mode->crtc_vtotal; 790c2baf4b7SVille Syrjälä vbl_start = mode->crtc_vblank_start; 791c2baf4b7SVille Syrjälä vbl_end = mode->crtc_vblank_end; 7920af7e4dfSMario Kleiner 793d31faf65SVille Syrjälä if (mode->flags & DRM_MODE_FLAG_INTERLACE) { 794d31faf65SVille Syrjälä vbl_start = DIV_ROUND_UP(vbl_start, 2); 795d31faf65SVille Syrjälä vbl_end /= 2; 796d31faf65SVille Syrjälä vtotal /= 2; 797d31faf65SVille Syrjälä } 798d31faf65SVille Syrjälä 799c2baf4b7SVille Syrjälä ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE; 800c2baf4b7SVille Syrjälä 801ad3543edSMario Kleiner /* 802ad3543edSMario Kleiner * Lock uncore.lock, as we will do multiple timing critical raw 803ad3543edSMario Kleiner * register reads, potentially with preemption disabled, so the 804ad3543edSMario Kleiner * following code must not block on uncore.lock. 805ad3543edSMario Kleiner */ 806ad3543edSMario Kleiner spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); 807ad3543edSMario Kleiner 808ad3543edSMario Kleiner /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */ 809ad3543edSMario Kleiner 810ad3543edSMario Kleiner /* Get optional system timestamp before query. */ 811ad3543edSMario Kleiner if (stime) 812ad3543edSMario Kleiner *stime = ktime_get(); 813ad3543edSMario Kleiner 81491d14251STvrtko Ursulin if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) { 8150af7e4dfSMario Kleiner /* No obvious pixelcount register. Only query vertical 8160af7e4dfSMario Kleiner * scanout position from Display scan line register. 8170af7e4dfSMario Kleiner */ 818a225f079SVille Syrjälä position = __intel_get_crtc_scanline(intel_crtc); 8190af7e4dfSMario Kleiner } else { 8200af7e4dfSMario Kleiner /* Have access to pixelcount since start of frame. 8210af7e4dfSMario Kleiner * We can split this into vertical and horizontal 8220af7e4dfSMario Kleiner * scanout position. 8230af7e4dfSMario Kleiner */ 82475aa3f63SVille Syrjälä position = (I915_READ_FW(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT; 8250af7e4dfSMario Kleiner 8263aa18df8SVille Syrjälä /* convert to pixel counts */ 8273aa18df8SVille Syrjälä vbl_start *= htotal; 8283aa18df8SVille Syrjälä vbl_end *= htotal; 8293aa18df8SVille Syrjälä vtotal *= htotal; 83078e8fc6bSVille Syrjälä 83178e8fc6bSVille Syrjälä /* 8327e78f1cbSVille Syrjälä * In interlaced modes, the pixel counter counts all pixels, 8337e78f1cbSVille Syrjälä * so one field will have htotal more pixels. In order to avoid 8347e78f1cbSVille Syrjälä * the reported position from jumping backwards when the pixel 8357e78f1cbSVille Syrjälä * counter is beyond the length of the shorter field, just 8367e78f1cbSVille Syrjälä * clamp the position the length of the shorter field. This 8377e78f1cbSVille Syrjälä * matches how the scanline counter based position works since 8387e78f1cbSVille Syrjälä * the scanline counter doesn't count the two half lines. 8397e78f1cbSVille Syrjälä */ 8407e78f1cbSVille Syrjälä if (position >= vtotal) 8417e78f1cbSVille Syrjälä position = vtotal - 1; 8427e78f1cbSVille Syrjälä 8437e78f1cbSVille Syrjälä /* 84478e8fc6bSVille Syrjälä * Start of vblank interrupt is triggered at start of hsync, 84578e8fc6bSVille Syrjälä * just prior to the first active line of vblank. However we 84678e8fc6bSVille Syrjälä * consider lines to start at the leading edge of horizontal 84778e8fc6bSVille Syrjälä * active. So, should we get here before we've crossed into 84878e8fc6bSVille Syrjälä * the horizontal active of the first line in vblank, we would 84978e8fc6bSVille Syrjälä * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that, 85078e8fc6bSVille Syrjälä * always add htotal-hsync_start to the current pixel position. 85178e8fc6bSVille Syrjälä */ 85278e8fc6bSVille Syrjälä position = (position + htotal - hsync_start) % vtotal; 8533aa18df8SVille Syrjälä } 8543aa18df8SVille Syrjälä 855ad3543edSMario Kleiner /* Get optional system timestamp after query. */ 856ad3543edSMario Kleiner if (etime) 857ad3543edSMario Kleiner *etime = ktime_get(); 858ad3543edSMario Kleiner 859ad3543edSMario Kleiner /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */ 860ad3543edSMario Kleiner 861ad3543edSMario Kleiner spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); 862ad3543edSMario Kleiner 8633aa18df8SVille Syrjälä in_vbl = position >= vbl_start && position < vbl_end; 8643aa18df8SVille Syrjälä 8653aa18df8SVille Syrjälä /* 8663aa18df8SVille Syrjälä * While in vblank, position will be negative 8673aa18df8SVille Syrjälä * counting up towards 0 at vbl_end. And outside 8683aa18df8SVille Syrjälä * vblank, position will be positive counting 8693aa18df8SVille Syrjälä * up since vbl_end. 8703aa18df8SVille Syrjälä */ 8713aa18df8SVille Syrjälä if (position >= vbl_start) 8723aa18df8SVille Syrjälä position -= vbl_end; 8733aa18df8SVille Syrjälä else 8743aa18df8SVille Syrjälä position += vtotal - vbl_end; 8753aa18df8SVille Syrjälä 87691d14251STvrtko Ursulin if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) { 8773aa18df8SVille Syrjälä *vpos = position; 8783aa18df8SVille Syrjälä *hpos = 0; 8793aa18df8SVille Syrjälä } else { 8800af7e4dfSMario Kleiner *vpos = position / htotal; 8810af7e4dfSMario Kleiner *hpos = position - (*vpos * htotal); 8820af7e4dfSMario Kleiner } 8830af7e4dfSMario Kleiner 8840af7e4dfSMario Kleiner /* In vblank? */ 8850af7e4dfSMario Kleiner if (in_vbl) 8863d3cbd84SDaniel Vetter ret |= DRM_SCANOUTPOS_IN_VBLANK; 8870af7e4dfSMario Kleiner 8880af7e4dfSMario Kleiner return ret; 8890af7e4dfSMario Kleiner } 8900af7e4dfSMario Kleiner 891a225f079SVille Syrjälä int intel_get_crtc_scanline(struct intel_crtc *crtc) 892a225f079SVille Syrjälä { 893fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 894a225f079SVille Syrjälä unsigned long irqflags; 895a225f079SVille Syrjälä int position; 896a225f079SVille Syrjälä 897a225f079SVille Syrjälä spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); 898a225f079SVille Syrjälä position = __intel_get_crtc_scanline(crtc); 899a225f079SVille Syrjälä spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); 900a225f079SVille Syrjälä 901a225f079SVille Syrjälä return position; 902a225f079SVille Syrjälä } 903a225f079SVille Syrjälä 90488e72717SThierry Reding static int i915_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe, 9050af7e4dfSMario Kleiner int *max_error, 9060af7e4dfSMario Kleiner struct timeval *vblank_time, 9070af7e4dfSMario Kleiner unsigned flags) 9080af7e4dfSMario Kleiner { 9094041b853SChris Wilson struct drm_crtc *crtc; 9100af7e4dfSMario Kleiner 91188e72717SThierry Reding if (pipe >= INTEL_INFO(dev)->num_pipes) { 91288e72717SThierry Reding DRM_ERROR("Invalid crtc %u\n", pipe); 9130af7e4dfSMario Kleiner return -EINVAL; 9140af7e4dfSMario Kleiner } 9150af7e4dfSMario Kleiner 9160af7e4dfSMario Kleiner /* Get drm_crtc to timestamp: */ 9174041b853SChris Wilson crtc = intel_get_crtc_for_pipe(dev, pipe); 9184041b853SChris Wilson if (crtc == NULL) { 91988e72717SThierry Reding DRM_ERROR("Invalid crtc %u\n", pipe); 9204041b853SChris Wilson return -EINVAL; 9214041b853SChris Wilson } 9224041b853SChris Wilson 923fc467a22SMaarten Lankhorst if (!crtc->hwmode.crtc_clock) { 92488e72717SThierry Reding DRM_DEBUG_KMS("crtc %u is disabled\n", pipe); 9254041b853SChris Wilson return -EBUSY; 9264041b853SChris Wilson } 9270af7e4dfSMario Kleiner 9280af7e4dfSMario Kleiner /* Helper routine in DRM core does all the work: */ 9294041b853SChris Wilson return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error, 9304041b853SChris Wilson vblank_time, flags, 931fc467a22SMaarten Lankhorst &crtc->hwmode); 9320af7e4dfSMario Kleiner } 9330af7e4dfSMario Kleiner 93491d14251STvrtko Ursulin static void ironlake_rps_change_irq_handler(struct drm_i915_private *dev_priv) 935f97108d1SJesse Barnes { 936b5b72e89SMatthew Garrett u32 busy_up, busy_down, max_avg, min_avg; 9379270388eSDaniel Vetter u8 new_delay; 9389270388eSDaniel Vetter 939d0ecd7e2SDaniel Vetter spin_lock(&mchdev_lock); 940f97108d1SJesse Barnes 94173edd18fSDaniel Vetter I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS)); 94273edd18fSDaniel Vetter 94320e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay; 9449270388eSDaniel Vetter 9457648fa99SJesse Barnes I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG); 946b5b72e89SMatthew Garrett busy_up = I915_READ(RCPREVBSYTUPAVG); 947b5b72e89SMatthew Garrett busy_down = I915_READ(RCPREVBSYTDNAVG); 948f97108d1SJesse Barnes max_avg = I915_READ(RCBMAXAVG); 949f97108d1SJesse Barnes min_avg = I915_READ(RCBMINAVG); 950f97108d1SJesse Barnes 951f97108d1SJesse Barnes /* Handle RCS change request from hw */ 952b5b72e89SMatthew Garrett if (busy_up > max_avg) { 95320e4d407SDaniel Vetter if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay) 95420e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay - 1; 95520e4d407SDaniel Vetter if (new_delay < dev_priv->ips.max_delay) 95620e4d407SDaniel Vetter new_delay = dev_priv->ips.max_delay; 957b5b72e89SMatthew Garrett } else if (busy_down < min_avg) { 95820e4d407SDaniel Vetter if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay) 95920e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay + 1; 96020e4d407SDaniel Vetter if (new_delay > dev_priv->ips.min_delay) 96120e4d407SDaniel Vetter new_delay = dev_priv->ips.min_delay; 962f97108d1SJesse Barnes } 963f97108d1SJesse Barnes 96491d14251STvrtko Ursulin if (ironlake_set_drps(dev_priv, new_delay)) 96520e4d407SDaniel Vetter dev_priv->ips.cur_delay = new_delay; 966f97108d1SJesse Barnes 967d0ecd7e2SDaniel Vetter spin_unlock(&mchdev_lock); 9689270388eSDaniel Vetter 969f97108d1SJesse Barnes return; 970f97108d1SJesse Barnes } 971f97108d1SJesse Barnes 9720bc40be8STvrtko Ursulin static void notify_ring(struct intel_engine_cs *engine) 973549f7365SChris Wilson { 974aca34b6eSChris Wilson smp_store_mb(engine->breadcrumbs.irq_posted, true); 97583348ba8SChris Wilson if (intel_engine_wakeup(engine)) 9760bc40be8STvrtko Ursulin trace_i915_gem_request_notify(engine); 977549f7365SChris Wilson } 978549f7365SChris Wilson 97943cf3bf0SChris Wilson static void vlv_c0_read(struct drm_i915_private *dev_priv, 98043cf3bf0SChris Wilson struct intel_rps_ei *ei) 98131685c25SDeepak S { 98243cf3bf0SChris Wilson ei->cz_clock = vlv_punit_read(dev_priv, PUNIT_REG_CZ_TIMESTAMP); 98343cf3bf0SChris Wilson ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT); 98443cf3bf0SChris Wilson ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT); 98531685c25SDeepak S } 98631685c25SDeepak S 98743cf3bf0SChris Wilson static bool vlv_c0_above(struct drm_i915_private *dev_priv, 98843cf3bf0SChris Wilson const struct intel_rps_ei *old, 98943cf3bf0SChris Wilson const struct intel_rps_ei *now, 99043cf3bf0SChris Wilson int threshold) 99131685c25SDeepak S { 99243cf3bf0SChris Wilson u64 time, c0; 9937bad74d5SVille Syrjälä unsigned int mul = 100; 99431685c25SDeepak S 99543cf3bf0SChris Wilson if (old->cz_clock == 0) 99643cf3bf0SChris Wilson return false; 99731685c25SDeepak S 9987bad74d5SVille Syrjälä if (I915_READ(VLV_COUNTER_CONTROL) & VLV_COUNT_RANGE_HIGH) 9997bad74d5SVille Syrjälä mul <<= 8; 10007bad74d5SVille Syrjälä 100143cf3bf0SChris Wilson time = now->cz_clock - old->cz_clock; 10027bad74d5SVille Syrjälä time *= threshold * dev_priv->czclk_freq; 100331685c25SDeepak S 100443cf3bf0SChris Wilson /* Workload can be split between render + media, e.g. SwapBuffers 100543cf3bf0SChris Wilson * being blitted in X after being rendered in mesa. To account for 100643cf3bf0SChris Wilson * this we need to combine both engines into our activity counter. 100743cf3bf0SChris Wilson */ 100843cf3bf0SChris Wilson c0 = now->render_c0 - old->render_c0; 100943cf3bf0SChris Wilson c0 += now->media_c0 - old->media_c0; 10107bad74d5SVille Syrjälä c0 *= mul * VLV_CZ_CLOCK_TO_MILLI_SEC; 101131685c25SDeepak S 101243cf3bf0SChris Wilson return c0 >= time; 101331685c25SDeepak S } 101431685c25SDeepak S 101543cf3bf0SChris Wilson void gen6_rps_reset_ei(struct drm_i915_private *dev_priv) 101643cf3bf0SChris Wilson { 101743cf3bf0SChris Wilson vlv_c0_read(dev_priv, &dev_priv->rps.down_ei); 101843cf3bf0SChris Wilson dev_priv->rps.up_ei = dev_priv->rps.down_ei; 101943cf3bf0SChris Wilson } 102043cf3bf0SChris Wilson 102143cf3bf0SChris Wilson static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir) 102243cf3bf0SChris Wilson { 102343cf3bf0SChris Wilson struct intel_rps_ei now; 102443cf3bf0SChris Wilson u32 events = 0; 102543cf3bf0SChris Wilson 10266f4b12f8SChris Wilson if ((pm_iir & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED)) == 0) 102743cf3bf0SChris Wilson return 0; 102843cf3bf0SChris Wilson 102943cf3bf0SChris Wilson vlv_c0_read(dev_priv, &now); 103043cf3bf0SChris Wilson if (now.cz_clock == 0) 103143cf3bf0SChris Wilson return 0; 103231685c25SDeepak S 103343cf3bf0SChris Wilson if (pm_iir & GEN6_PM_RP_DOWN_EI_EXPIRED) { 103443cf3bf0SChris Wilson if (!vlv_c0_above(dev_priv, 103543cf3bf0SChris Wilson &dev_priv->rps.down_ei, &now, 10368fb55197SChris Wilson dev_priv->rps.down_threshold)) 103743cf3bf0SChris Wilson events |= GEN6_PM_RP_DOWN_THRESHOLD; 103843cf3bf0SChris Wilson dev_priv->rps.down_ei = now; 103931685c25SDeepak S } 104031685c25SDeepak S 104143cf3bf0SChris Wilson if (pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) { 104243cf3bf0SChris Wilson if (vlv_c0_above(dev_priv, 104343cf3bf0SChris Wilson &dev_priv->rps.up_ei, &now, 10448fb55197SChris Wilson dev_priv->rps.up_threshold)) 104543cf3bf0SChris Wilson events |= GEN6_PM_RP_UP_THRESHOLD; 104643cf3bf0SChris Wilson dev_priv->rps.up_ei = now; 104743cf3bf0SChris Wilson } 104843cf3bf0SChris Wilson 104943cf3bf0SChris Wilson return events; 105031685c25SDeepak S } 105131685c25SDeepak S 1052f5a4c67dSChris Wilson static bool any_waiters(struct drm_i915_private *dev_priv) 1053f5a4c67dSChris Wilson { 1054e2f80391STvrtko Ursulin struct intel_engine_cs *engine; 1055f5a4c67dSChris Wilson 1056b4ac5afcSDave Gordon for_each_engine(engine, dev_priv) 1057688e6c72SChris Wilson if (intel_engine_has_waiter(engine)) 1058f5a4c67dSChris Wilson return true; 1059f5a4c67dSChris Wilson 1060f5a4c67dSChris Wilson return false; 1061f5a4c67dSChris Wilson } 1062f5a4c67dSChris Wilson 10634912d041SBen Widawsky static void gen6_pm_rps_work(struct work_struct *work) 10643b8d8d91SJesse Barnes { 10652d1013ddSJani Nikula struct drm_i915_private *dev_priv = 10662d1013ddSJani Nikula container_of(work, struct drm_i915_private, rps.work); 10678d3afd7dSChris Wilson bool client_boost; 10688d3afd7dSChris Wilson int new_delay, adj, min, max; 1069edbfdb45SPaulo Zanoni u32 pm_iir; 10703b8d8d91SJesse Barnes 107159cdb63dSDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 1072d4d70aa5SImre Deak /* Speed up work cancelation during disabling rps interrupts. */ 1073d4d70aa5SImre Deak if (!dev_priv->rps.interrupts_enabled) { 1074d4d70aa5SImre Deak spin_unlock_irq(&dev_priv->irq_lock); 1075d4d70aa5SImre Deak return; 1076d4d70aa5SImre Deak } 10771f814dacSImre Deak 1078c6a828d3SDaniel Vetter pm_iir = dev_priv->rps.pm_iir; 1079c6a828d3SDaniel Vetter dev_priv->rps.pm_iir = 0; 1080a72fbc3aSImre Deak /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */ 1081480c8033SDaniel Vetter gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events); 10828d3afd7dSChris Wilson client_boost = dev_priv->rps.client_boost; 10838d3afd7dSChris Wilson dev_priv->rps.client_boost = false; 108459cdb63dSDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 10854912d041SBen Widawsky 108660611c13SPaulo Zanoni /* Make sure we didn't queue anything we're not going to process. */ 1087a6706b45SDeepak S WARN_ON(pm_iir & ~dev_priv->pm_rps_events); 108860611c13SPaulo Zanoni 10898d3afd7dSChris Wilson if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost) 1090c33d247dSChris Wilson return; 10913b8d8d91SJesse Barnes 10924fc688ceSJesse Barnes mutex_lock(&dev_priv->rps.hw_lock); 10937b9e0ae6SChris Wilson 109443cf3bf0SChris Wilson pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir); 109543cf3bf0SChris Wilson 1096dd75fdc8SChris Wilson adj = dev_priv->rps.last_adj; 1097edcf284bSChris Wilson new_delay = dev_priv->rps.cur_freq; 10988d3afd7dSChris Wilson min = dev_priv->rps.min_freq_softlimit; 10998d3afd7dSChris Wilson max = dev_priv->rps.max_freq_softlimit; 110029ecd78dSChris Wilson if (client_boost || any_waiters(dev_priv)) 110129ecd78dSChris Wilson max = dev_priv->rps.max_freq; 110229ecd78dSChris Wilson if (client_boost && new_delay < dev_priv->rps.boost_freq) { 110329ecd78dSChris Wilson new_delay = dev_priv->rps.boost_freq; 11048d3afd7dSChris Wilson adj = 0; 11058d3afd7dSChris Wilson } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) { 1106dd75fdc8SChris Wilson if (adj > 0) 1107dd75fdc8SChris Wilson adj *= 2; 1108edcf284bSChris Wilson else /* CHV needs even encode values */ 1109edcf284bSChris Wilson adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1; 11107425034aSVille Syrjälä /* 11117425034aSVille Syrjälä * For better performance, jump directly 11127425034aSVille Syrjälä * to RPe if we're below it. 11137425034aSVille Syrjälä */ 1114edcf284bSChris Wilson if (new_delay < dev_priv->rps.efficient_freq - adj) { 1115b39fb297SBen Widawsky new_delay = dev_priv->rps.efficient_freq; 1116edcf284bSChris Wilson adj = 0; 1117edcf284bSChris Wilson } 111829ecd78dSChris Wilson } else if (client_boost || any_waiters(dev_priv)) { 1119f5a4c67dSChris Wilson adj = 0; 1120dd75fdc8SChris Wilson } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) { 1121b39fb297SBen Widawsky if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq) 1122b39fb297SBen Widawsky new_delay = dev_priv->rps.efficient_freq; 1123dd75fdc8SChris Wilson else 1124b39fb297SBen Widawsky new_delay = dev_priv->rps.min_freq_softlimit; 1125dd75fdc8SChris Wilson adj = 0; 1126dd75fdc8SChris Wilson } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) { 1127dd75fdc8SChris Wilson if (adj < 0) 1128dd75fdc8SChris Wilson adj *= 2; 1129edcf284bSChris Wilson else /* CHV needs even encode values */ 1130edcf284bSChris Wilson adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1; 1131dd75fdc8SChris Wilson } else { /* unknown event */ 1132edcf284bSChris Wilson adj = 0; 1133dd75fdc8SChris Wilson } 11343b8d8d91SJesse Barnes 1135edcf284bSChris Wilson dev_priv->rps.last_adj = adj; 1136edcf284bSChris Wilson 113779249636SBen Widawsky /* sysfs frequency interfaces may have snuck in while servicing the 113879249636SBen Widawsky * interrupt 113979249636SBen Widawsky */ 1140edcf284bSChris Wilson new_delay += adj; 11418d3afd7dSChris Wilson new_delay = clamp_t(int, new_delay, min, max); 114227544369SDeepak S 1143dc97997aSChris Wilson intel_set_rps(dev_priv, new_delay); 11443b8d8d91SJesse Barnes 11454fc688ceSJesse Barnes mutex_unlock(&dev_priv->rps.hw_lock); 11463b8d8d91SJesse Barnes } 11473b8d8d91SJesse Barnes 1148e3689190SBen Widawsky 1149e3689190SBen Widawsky /** 1150e3689190SBen Widawsky * ivybridge_parity_work - Workqueue called when a parity error interrupt 1151e3689190SBen Widawsky * occurred. 1152e3689190SBen Widawsky * @work: workqueue struct 1153e3689190SBen Widawsky * 1154e3689190SBen Widawsky * Doesn't actually do anything except notify userspace. As a consequence of 1155e3689190SBen Widawsky * this event, userspace should try to remap the bad rows since statistically 1156e3689190SBen Widawsky * it is likely the same row is more likely to go bad again. 1157e3689190SBen Widawsky */ 1158e3689190SBen Widawsky static void ivybridge_parity_work(struct work_struct *work) 1159e3689190SBen Widawsky { 11602d1013ddSJani Nikula struct drm_i915_private *dev_priv = 11612d1013ddSJani Nikula container_of(work, struct drm_i915_private, l3_parity.error_work); 1162e3689190SBen Widawsky u32 error_status, row, bank, subbank; 116335a85ac6SBen Widawsky char *parity_event[6]; 1164e3689190SBen Widawsky uint32_t misccpctl; 116535a85ac6SBen Widawsky uint8_t slice = 0; 1166e3689190SBen Widawsky 1167e3689190SBen Widawsky /* We must turn off DOP level clock gating to access the L3 registers. 1168e3689190SBen Widawsky * In order to prevent a get/put style interface, acquire struct mutex 1169e3689190SBen Widawsky * any time we access those registers. 1170e3689190SBen Widawsky */ 117191c8a326SChris Wilson mutex_lock(&dev_priv->drm.struct_mutex); 1172e3689190SBen Widawsky 117335a85ac6SBen Widawsky /* If we've screwed up tracking, just let the interrupt fire again */ 117435a85ac6SBen Widawsky if (WARN_ON(!dev_priv->l3_parity.which_slice)) 117535a85ac6SBen Widawsky goto out; 117635a85ac6SBen Widawsky 1177e3689190SBen Widawsky misccpctl = I915_READ(GEN7_MISCCPCTL); 1178e3689190SBen Widawsky I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); 1179e3689190SBen Widawsky POSTING_READ(GEN7_MISCCPCTL); 1180e3689190SBen Widawsky 118135a85ac6SBen Widawsky while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) { 1182f0f59a00SVille Syrjälä i915_reg_t reg; 118335a85ac6SBen Widawsky 118435a85ac6SBen Widawsky slice--; 11852d1fe073SJoonas Lahtinen if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv))) 118635a85ac6SBen Widawsky break; 118735a85ac6SBen Widawsky 118835a85ac6SBen Widawsky dev_priv->l3_parity.which_slice &= ~(1<<slice); 118935a85ac6SBen Widawsky 11906fa1c5f1SVille Syrjälä reg = GEN7_L3CDERRST1(slice); 119135a85ac6SBen Widawsky 119235a85ac6SBen Widawsky error_status = I915_READ(reg); 1193e3689190SBen Widawsky row = GEN7_PARITY_ERROR_ROW(error_status); 1194e3689190SBen Widawsky bank = GEN7_PARITY_ERROR_BANK(error_status); 1195e3689190SBen Widawsky subbank = GEN7_PARITY_ERROR_SUBBANK(error_status); 1196e3689190SBen Widawsky 119735a85ac6SBen Widawsky I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE); 119835a85ac6SBen Widawsky POSTING_READ(reg); 1199e3689190SBen Widawsky 1200cce723edSBen Widawsky parity_event[0] = I915_L3_PARITY_UEVENT "=1"; 1201e3689190SBen Widawsky parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row); 1202e3689190SBen Widawsky parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank); 1203e3689190SBen Widawsky parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank); 120435a85ac6SBen Widawsky parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice); 120535a85ac6SBen Widawsky parity_event[5] = NULL; 1206e3689190SBen Widawsky 120791c8a326SChris Wilson kobject_uevent_env(&dev_priv->drm.primary->kdev->kobj, 1208e3689190SBen Widawsky KOBJ_CHANGE, parity_event); 1209e3689190SBen Widawsky 121035a85ac6SBen Widawsky DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n", 121135a85ac6SBen Widawsky slice, row, bank, subbank); 1212e3689190SBen Widawsky 121335a85ac6SBen Widawsky kfree(parity_event[4]); 1214e3689190SBen Widawsky kfree(parity_event[3]); 1215e3689190SBen Widawsky kfree(parity_event[2]); 1216e3689190SBen Widawsky kfree(parity_event[1]); 1217e3689190SBen Widawsky } 1218e3689190SBen Widawsky 121935a85ac6SBen Widawsky I915_WRITE(GEN7_MISCCPCTL, misccpctl); 122035a85ac6SBen Widawsky 122135a85ac6SBen Widawsky out: 122235a85ac6SBen Widawsky WARN_ON(dev_priv->l3_parity.which_slice); 12234cb21832SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 12242d1fe073SJoonas Lahtinen gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv)); 12254cb21832SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 122635a85ac6SBen Widawsky 122791c8a326SChris Wilson mutex_unlock(&dev_priv->drm.struct_mutex); 122835a85ac6SBen Widawsky } 122935a85ac6SBen Widawsky 1230261e40b8SVille Syrjälä static void ivybridge_parity_error_irq_handler(struct drm_i915_private *dev_priv, 1231261e40b8SVille Syrjälä u32 iir) 1232e3689190SBen Widawsky { 1233261e40b8SVille Syrjälä if (!HAS_L3_DPF(dev_priv)) 1234e3689190SBen Widawsky return; 1235e3689190SBen Widawsky 1236d0ecd7e2SDaniel Vetter spin_lock(&dev_priv->irq_lock); 1237261e40b8SVille Syrjälä gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv)); 1238d0ecd7e2SDaniel Vetter spin_unlock(&dev_priv->irq_lock); 1239e3689190SBen Widawsky 1240261e40b8SVille Syrjälä iir &= GT_PARITY_ERROR(dev_priv); 124135a85ac6SBen Widawsky if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1) 124235a85ac6SBen Widawsky dev_priv->l3_parity.which_slice |= 1 << 1; 124335a85ac6SBen Widawsky 124435a85ac6SBen Widawsky if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT) 124535a85ac6SBen Widawsky dev_priv->l3_parity.which_slice |= 1 << 0; 124635a85ac6SBen Widawsky 1247a4da4fa4SDaniel Vetter queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work); 1248e3689190SBen Widawsky } 1249e3689190SBen Widawsky 1250261e40b8SVille Syrjälä static void ilk_gt_irq_handler(struct drm_i915_private *dev_priv, 1251f1af8fc1SPaulo Zanoni u32 gt_iir) 1252f1af8fc1SPaulo Zanoni { 1253f8973c21SChris Wilson if (gt_iir & GT_RENDER_USER_INTERRUPT) 12544a570db5STvrtko Ursulin notify_ring(&dev_priv->engine[RCS]); 1255f1af8fc1SPaulo Zanoni if (gt_iir & ILK_BSD_USER_INTERRUPT) 12564a570db5STvrtko Ursulin notify_ring(&dev_priv->engine[VCS]); 1257f1af8fc1SPaulo Zanoni } 1258f1af8fc1SPaulo Zanoni 1259261e40b8SVille Syrjälä static void snb_gt_irq_handler(struct drm_i915_private *dev_priv, 1260e7b4c6b1SDaniel Vetter u32 gt_iir) 1261e7b4c6b1SDaniel Vetter { 1262f8973c21SChris Wilson if (gt_iir & GT_RENDER_USER_INTERRUPT) 12634a570db5STvrtko Ursulin notify_ring(&dev_priv->engine[RCS]); 1264cc609d5dSBen Widawsky if (gt_iir & GT_BSD_USER_INTERRUPT) 12654a570db5STvrtko Ursulin notify_ring(&dev_priv->engine[VCS]); 1266cc609d5dSBen Widawsky if (gt_iir & GT_BLT_USER_INTERRUPT) 12674a570db5STvrtko Ursulin notify_ring(&dev_priv->engine[BCS]); 1268e7b4c6b1SDaniel Vetter 1269cc609d5dSBen Widawsky if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT | 1270cc609d5dSBen Widawsky GT_BSD_CS_ERROR_INTERRUPT | 1271aaecdf61SDaniel Vetter GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) 1272aaecdf61SDaniel Vetter DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir); 1273e3689190SBen Widawsky 1274261e40b8SVille Syrjälä if (gt_iir & GT_PARITY_ERROR(dev_priv)) 1275261e40b8SVille Syrjälä ivybridge_parity_error_irq_handler(dev_priv, gt_iir); 1276e7b4c6b1SDaniel Vetter } 1277e7b4c6b1SDaniel Vetter 1278fbcc1a0cSNick Hoath static __always_inline void 12790bc40be8STvrtko Ursulin gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir, int test_shift) 1280fbcc1a0cSNick Hoath { 1281fbcc1a0cSNick Hoath if (iir & (GT_RENDER_USER_INTERRUPT << test_shift)) 12820bc40be8STvrtko Ursulin notify_ring(engine); 1283fbcc1a0cSNick Hoath if (iir & (GT_CONTEXT_SWITCH_INTERRUPT << test_shift)) 128427af5eeaSTvrtko Ursulin tasklet_schedule(&engine->irq_tasklet); 1285fbcc1a0cSNick Hoath } 1286fbcc1a0cSNick Hoath 1287e30e251aSVille Syrjälä static irqreturn_t gen8_gt_irq_ack(struct drm_i915_private *dev_priv, 1288e30e251aSVille Syrjälä u32 master_ctl, 1289e30e251aSVille Syrjälä u32 gt_iir[4]) 1290abd58f01SBen Widawsky { 1291abd58f01SBen Widawsky irqreturn_t ret = IRQ_NONE; 1292abd58f01SBen Widawsky 1293abd58f01SBen Widawsky if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) { 1294e30e251aSVille Syrjälä gt_iir[0] = I915_READ_FW(GEN8_GT_IIR(0)); 1295e30e251aSVille Syrjälä if (gt_iir[0]) { 1296e30e251aSVille Syrjälä I915_WRITE_FW(GEN8_GT_IIR(0), gt_iir[0]); 1297abd58f01SBen Widawsky ret = IRQ_HANDLED; 1298abd58f01SBen Widawsky } else 1299abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (GT0)!\n"); 1300abd58f01SBen Widawsky } 1301abd58f01SBen Widawsky 130285f9b5f9SZhao Yakui if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) { 1303e30e251aSVille Syrjälä gt_iir[1] = I915_READ_FW(GEN8_GT_IIR(1)); 1304e30e251aSVille Syrjälä if (gt_iir[1]) { 1305e30e251aSVille Syrjälä I915_WRITE_FW(GEN8_GT_IIR(1), gt_iir[1]); 1306abd58f01SBen Widawsky ret = IRQ_HANDLED; 1307abd58f01SBen Widawsky } else 1308abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (GT1)!\n"); 1309abd58f01SBen Widawsky } 1310abd58f01SBen Widawsky 131174cdb337SChris Wilson if (master_ctl & GEN8_GT_VECS_IRQ) { 1312e30e251aSVille Syrjälä gt_iir[3] = I915_READ_FW(GEN8_GT_IIR(3)); 1313e30e251aSVille Syrjälä if (gt_iir[3]) { 1314e30e251aSVille Syrjälä I915_WRITE_FW(GEN8_GT_IIR(3), gt_iir[3]); 131574cdb337SChris Wilson ret = IRQ_HANDLED; 131674cdb337SChris Wilson } else 131774cdb337SChris Wilson DRM_ERROR("The master control interrupt lied (GT3)!\n"); 131874cdb337SChris Wilson } 131974cdb337SChris Wilson 13200961021aSBen Widawsky if (master_ctl & GEN8_GT_PM_IRQ) { 1321e30e251aSVille Syrjälä gt_iir[2] = I915_READ_FW(GEN8_GT_IIR(2)); 1322e30e251aSVille Syrjälä if (gt_iir[2] & dev_priv->pm_rps_events) { 1323cb0d205eSChris Wilson I915_WRITE_FW(GEN8_GT_IIR(2), 1324e30e251aSVille Syrjälä gt_iir[2] & dev_priv->pm_rps_events); 132538cc46d7SOscar Mateo ret = IRQ_HANDLED; 13260961021aSBen Widawsky } else 13270961021aSBen Widawsky DRM_ERROR("The master control interrupt lied (PM)!\n"); 13280961021aSBen Widawsky } 13290961021aSBen Widawsky 1330abd58f01SBen Widawsky return ret; 1331abd58f01SBen Widawsky } 1332abd58f01SBen Widawsky 1333e30e251aSVille Syrjälä static void gen8_gt_irq_handler(struct drm_i915_private *dev_priv, 1334e30e251aSVille Syrjälä u32 gt_iir[4]) 1335e30e251aSVille Syrjälä { 1336e30e251aSVille Syrjälä if (gt_iir[0]) { 1337e30e251aSVille Syrjälä gen8_cs_irq_handler(&dev_priv->engine[RCS], 1338e30e251aSVille Syrjälä gt_iir[0], GEN8_RCS_IRQ_SHIFT); 1339e30e251aSVille Syrjälä gen8_cs_irq_handler(&dev_priv->engine[BCS], 1340e30e251aSVille Syrjälä gt_iir[0], GEN8_BCS_IRQ_SHIFT); 1341e30e251aSVille Syrjälä } 1342e30e251aSVille Syrjälä 1343e30e251aSVille Syrjälä if (gt_iir[1]) { 1344e30e251aSVille Syrjälä gen8_cs_irq_handler(&dev_priv->engine[VCS], 1345e30e251aSVille Syrjälä gt_iir[1], GEN8_VCS1_IRQ_SHIFT); 1346e30e251aSVille Syrjälä gen8_cs_irq_handler(&dev_priv->engine[VCS2], 1347e30e251aSVille Syrjälä gt_iir[1], GEN8_VCS2_IRQ_SHIFT); 1348e30e251aSVille Syrjälä } 1349e30e251aSVille Syrjälä 1350e30e251aSVille Syrjälä if (gt_iir[3]) 1351e30e251aSVille Syrjälä gen8_cs_irq_handler(&dev_priv->engine[VECS], 1352e30e251aSVille Syrjälä gt_iir[3], GEN8_VECS_IRQ_SHIFT); 1353e30e251aSVille Syrjälä 1354e30e251aSVille Syrjälä if (gt_iir[2] & dev_priv->pm_rps_events) 1355e30e251aSVille Syrjälä gen6_rps_irq_handler(dev_priv, gt_iir[2]); 1356e30e251aSVille Syrjälä } 1357e30e251aSVille Syrjälä 135863c88d22SImre Deak static bool bxt_port_hotplug_long_detect(enum port port, u32 val) 135963c88d22SImre Deak { 136063c88d22SImre Deak switch (port) { 136163c88d22SImre Deak case PORT_A: 1362195baa06SVille Syrjälä return val & PORTA_HOTPLUG_LONG_DETECT; 136363c88d22SImre Deak case PORT_B: 136463c88d22SImre Deak return val & PORTB_HOTPLUG_LONG_DETECT; 136563c88d22SImre Deak case PORT_C: 136663c88d22SImre Deak return val & PORTC_HOTPLUG_LONG_DETECT; 136763c88d22SImre Deak default: 136863c88d22SImre Deak return false; 136963c88d22SImre Deak } 137063c88d22SImre Deak } 137163c88d22SImre Deak 13726dbf30ceSVille Syrjälä static bool spt_port_hotplug2_long_detect(enum port port, u32 val) 13736dbf30ceSVille Syrjälä { 13746dbf30ceSVille Syrjälä switch (port) { 13756dbf30ceSVille Syrjälä case PORT_E: 13766dbf30ceSVille Syrjälä return val & PORTE_HOTPLUG_LONG_DETECT; 13776dbf30ceSVille Syrjälä default: 13786dbf30ceSVille Syrjälä return false; 13796dbf30ceSVille Syrjälä } 13806dbf30ceSVille Syrjälä } 13816dbf30ceSVille Syrjälä 138274c0b395SVille Syrjälä static bool spt_port_hotplug_long_detect(enum port port, u32 val) 138374c0b395SVille Syrjälä { 138474c0b395SVille Syrjälä switch (port) { 138574c0b395SVille Syrjälä case PORT_A: 138674c0b395SVille Syrjälä return val & PORTA_HOTPLUG_LONG_DETECT; 138774c0b395SVille Syrjälä case PORT_B: 138874c0b395SVille Syrjälä return val & PORTB_HOTPLUG_LONG_DETECT; 138974c0b395SVille Syrjälä case PORT_C: 139074c0b395SVille Syrjälä return val & PORTC_HOTPLUG_LONG_DETECT; 139174c0b395SVille Syrjälä case PORT_D: 139274c0b395SVille Syrjälä return val & PORTD_HOTPLUG_LONG_DETECT; 139374c0b395SVille Syrjälä default: 139474c0b395SVille Syrjälä return false; 139574c0b395SVille Syrjälä } 139674c0b395SVille Syrjälä } 139774c0b395SVille Syrjälä 1398e4ce95aaSVille Syrjälä static bool ilk_port_hotplug_long_detect(enum port port, u32 val) 1399e4ce95aaSVille Syrjälä { 1400e4ce95aaSVille Syrjälä switch (port) { 1401e4ce95aaSVille Syrjälä case PORT_A: 1402e4ce95aaSVille Syrjälä return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT; 1403e4ce95aaSVille Syrjälä default: 1404e4ce95aaSVille Syrjälä return false; 1405e4ce95aaSVille Syrjälä } 1406e4ce95aaSVille Syrjälä } 1407e4ce95aaSVille Syrjälä 1408676574dfSJani Nikula static bool pch_port_hotplug_long_detect(enum port port, u32 val) 140913cf5504SDave Airlie { 141013cf5504SDave Airlie switch (port) { 141113cf5504SDave Airlie case PORT_B: 1412676574dfSJani Nikula return val & PORTB_HOTPLUG_LONG_DETECT; 141313cf5504SDave Airlie case PORT_C: 1414676574dfSJani Nikula return val & PORTC_HOTPLUG_LONG_DETECT; 141513cf5504SDave Airlie case PORT_D: 1416676574dfSJani Nikula return val & PORTD_HOTPLUG_LONG_DETECT; 1417676574dfSJani Nikula default: 1418676574dfSJani Nikula return false; 141913cf5504SDave Airlie } 142013cf5504SDave Airlie } 142113cf5504SDave Airlie 1422676574dfSJani Nikula static bool i9xx_port_hotplug_long_detect(enum port port, u32 val) 142313cf5504SDave Airlie { 142413cf5504SDave Airlie switch (port) { 142513cf5504SDave Airlie case PORT_B: 1426676574dfSJani Nikula return val & PORTB_HOTPLUG_INT_LONG_PULSE; 142713cf5504SDave Airlie case PORT_C: 1428676574dfSJani Nikula return val & PORTC_HOTPLUG_INT_LONG_PULSE; 142913cf5504SDave Airlie case PORT_D: 1430676574dfSJani Nikula return val & PORTD_HOTPLUG_INT_LONG_PULSE; 1431676574dfSJani Nikula default: 1432676574dfSJani Nikula return false; 143313cf5504SDave Airlie } 143413cf5504SDave Airlie } 143513cf5504SDave Airlie 143642db67d6SVille Syrjälä /* 143742db67d6SVille Syrjälä * Get a bit mask of pins that have triggered, and which ones may be long. 143842db67d6SVille Syrjälä * This can be called multiple times with the same masks to accumulate 143942db67d6SVille Syrjälä * hotplug detection results from several registers. 144042db67d6SVille Syrjälä * 144142db67d6SVille Syrjälä * Note that the caller is expected to zero out the masks initially. 144242db67d6SVille Syrjälä */ 1443fd63e2a9SImre Deak static void intel_get_hpd_pins(u32 *pin_mask, u32 *long_mask, 14448c841e57SJani Nikula u32 hotplug_trigger, u32 dig_hotplug_reg, 1445fd63e2a9SImre Deak const u32 hpd[HPD_NUM_PINS], 1446fd63e2a9SImre Deak bool long_pulse_detect(enum port port, u32 val)) 1447676574dfSJani Nikula { 14488c841e57SJani Nikula enum port port; 1449676574dfSJani Nikula int i; 1450676574dfSJani Nikula 1451676574dfSJani Nikula for_each_hpd_pin(i) { 14528c841e57SJani Nikula if ((hpd[i] & hotplug_trigger) == 0) 14538c841e57SJani Nikula continue; 14548c841e57SJani Nikula 1455676574dfSJani Nikula *pin_mask |= BIT(i); 1456676574dfSJani Nikula 1457cc24fcdcSImre Deak if (!intel_hpd_pin_to_port(i, &port)) 1458cc24fcdcSImre Deak continue; 1459cc24fcdcSImre Deak 1460fd63e2a9SImre Deak if (long_pulse_detect(port, dig_hotplug_reg)) 1461676574dfSJani Nikula *long_mask |= BIT(i); 1462676574dfSJani Nikula } 1463676574dfSJani Nikula 1464676574dfSJani Nikula DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x\n", 1465676574dfSJani Nikula hotplug_trigger, dig_hotplug_reg, *pin_mask); 1466676574dfSJani Nikula 1467676574dfSJani Nikula } 1468676574dfSJani Nikula 146991d14251STvrtko Ursulin static void gmbus_irq_handler(struct drm_i915_private *dev_priv) 1470515ac2bbSDaniel Vetter { 147128c70f16SDaniel Vetter wake_up_all(&dev_priv->gmbus_wait_queue); 1472515ac2bbSDaniel Vetter } 1473515ac2bbSDaniel Vetter 147491d14251STvrtko Ursulin static void dp_aux_irq_handler(struct drm_i915_private *dev_priv) 1475ce99c256SDaniel Vetter { 14769ee32feaSDaniel Vetter wake_up_all(&dev_priv->gmbus_wait_queue); 1477ce99c256SDaniel Vetter } 1478ce99c256SDaniel Vetter 14798bf1e9f1SShuang He #if defined(CONFIG_DEBUG_FS) 148091d14251STvrtko Ursulin static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, 148191d14251STvrtko Ursulin enum pipe pipe, 1482eba94eb9SDaniel Vetter uint32_t crc0, uint32_t crc1, 1483eba94eb9SDaniel Vetter uint32_t crc2, uint32_t crc3, 14848bc5e955SDaniel Vetter uint32_t crc4) 14858bf1e9f1SShuang He { 14868bf1e9f1SShuang He struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe]; 14878bf1e9f1SShuang He struct intel_pipe_crc_entry *entry; 1488ac2300d4SDamien Lespiau int head, tail; 1489b2c88f5bSDamien Lespiau 1490d538bbdfSDamien Lespiau spin_lock(&pipe_crc->lock); 1491d538bbdfSDamien Lespiau 14920c912c79SDamien Lespiau if (!pipe_crc->entries) { 1493d538bbdfSDamien Lespiau spin_unlock(&pipe_crc->lock); 149434273620SDaniel Vetter DRM_DEBUG_KMS("spurious interrupt\n"); 14950c912c79SDamien Lespiau return; 14960c912c79SDamien Lespiau } 14970c912c79SDamien Lespiau 1498d538bbdfSDamien Lespiau head = pipe_crc->head; 1499d538bbdfSDamien Lespiau tail = pipe_crc->tail; 1500b2c88f5bSDamien Lespiau 1501b2c88f5bSDamien Lespiau if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) { 1502d538bbdfSDamien Lespiau spin_unlock(&pipe_crc->lock); 1503b2c88f5bSDamien Lespiau DRM_ERROR("CRC buffer overflowing\n"); 1504b2c88f5bSDamien Lespiau return; 1505b2c88f5bSDamien Lespiau } 1506b2c88f5bSDamien Lespiau 1507b2c88f5bSDamien Lespiau entry = &pipe_crc->entries[head]; 15088bf1e9f1SShuang He 150991c8a326SChris Wilson entry->frame = dev_priv->drm.driver->get_vblank_counter(&dev_priv->drm, 151091d14251STvrtko Ursulin pipe); 1511eba94eb9SDaniel Vetter entry->crc[0] = crc0; 1512eba94eb9SDaniel Vetter entry->crc[1] = crc1; 1513eba94eb9SDaniel Vetter entry->crc[2] = crc2; 1514eba94eb9SDaniel Vetter entry->crc[3] = crc3; 1515eba94eb9SDaniel Vetter entry->crc[4] = crc4; 1516b2c88f5bSDamien Lespiau 1517b2c88f5bSDamien Lespiau head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1); 1518d538bbdfSDamien Lespiau pipe_crc->head = head; 1519d538bbdfSDamien Lespiau 1520d538bbdfSDamien Lespiau spin_unlock(&pipe_crc->lock); 152107144428SDamien Lespiau 152207144428SDamien Lespiau wake_up_interruptible(&pipe_crc->wq); 15238bf1e9f1SShuang He } 1524277de95eSDaniel Vetter #else 1525277de95eSDaniel Vetter static inline void 152691d14251STvrtko Ursulin display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, 152791d14251STvrtko Ursulin enum pipe pipe, 1528277de95eSDaniel Vetter uint32_t crc0, uint32_t crc1, 1529277de95eSDaniel Vetter uint32_t crc2, uint32_t crc3, 1530277de95eSDaniel Vetter uint32_t crc4) {} 1531277de95eSDaniel Vetter #endif 1532eba94eb9SDaniel Vetter 1533277de95eSDaniel Vetter 153491d14251STvrtko Ursulin static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, 153591d14251STvrtko Ursulin enum pipe pipe) 15365a69b89fSDaniel Vetter { 153791d14251STvrtko Ursulin display_pipe_crc_irq_handler(dev_priv, pipe, 15385a69b89fSDaniel Vetter I915_READ(PIPE_CRC_RES_1_IVB(pipe)), 15395a69b89fSDaniel Vetter 0, 0, 0, 0); 15405a69b89fSDaniel Vetter } 15415a69b89fSDaniel Vetter 154291d14251STvrtko Ursulin static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, 154391d14251STvrtko Ursulin enum pipe pipe) 1544eba94eb9SDaniel Vetter { 154591d14251STvrtko Ursulin display_pipe_crc_irq_handler(dev_priv, pipe, 1546eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_1_IVB(pipe)), 1547eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_2_IVB(pipe)), 1548eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_3_IVB(pipe)), 1549eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_4_IVB(pipe)), 15508bc5e955SDaniel Vetter I915_READ(PIPE_CRC_RES_5_IVB(pipe))); 1551eba94eb9SDaniel Vetter } 15525b3a856bSDaniel Vetter 155391d14251STvrtko Ursulin static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, 155491d14251STvrtko Ursulin enum pipe pipe) 15555b3a856bSDaniel Vetter { 15560b5c5ed0SDaniel Vetter uint32_t res1, res2; 15570b5c5ed0SDaniel Vetter 155891d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 3) 15590b5c5ed0SDaniel Vetter res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe)); 15600b5c5ed0SDaniel Vetter else 15610b5c5ed0SDaniel Vetter res1 = 0; 15620b5c5ed0SDaniel Vetter 156391d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) 15640b5c5ed0SDaniel Vetter res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe)); 15650b5c5ed0SDaniel Vetter else 15660b5c5ed0SDaniel Vetter res2 = 0; 15675b3a856bSDaniel Vetter 156891d14251STvrtko Ursulin display_pipe_crc_irq_handler(dev_priv, pipe, 15690b5c5ed0SDaniel Vetter I915_READ(PIPE_CRC_RES_RED(pipe)), 15700b5c5ed0SDaniel Vetter I915_READ(PIPE_CRC_RES_GREEN(pipe)), 15710b5c5ed0SDaniel Vetter I915_READ(PIPE_CRC_RES_BLUE(pipe)), 15720b5c5ed0SDaniel Vetter res1, res2); 15735b3a856bSDaniel Vetter } 15748bf1e9f1SShuang He 15751403c0d4SPaulo Zanoni /* The RPS events need forcewake, so we add them to a work queue and mask their 15761403c0d4SPaulo Zanoni * IMR bits until the work is done. Other interrupts can be processed without 15771403c0d4SPaulo Zanoni * the work queue. */ 15781403c0d4SPaulo Zanoni static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir) 1579baf02a1fSBen Widawsky { 1580a6706b45SDeepak S if (pm_iir & dev_priv->pm_rps_events) { 158159cdb63dSDaniel Vetter spin_lock(&dev_priv->irq_lock); 1582480c8033SDaniel Vetter gen6_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events); 1583d4d70aa5SImre Deak if (dev_priv->rps.interrupts_enabled) { 1584d4d70aa5SImre Deak dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events; 1585c33d247dSChris Wilson schedule_work(&dev_priv->rps.work); 158641a05a3aSDaniel Vetter } 1587d4d70aa5SImre Deak spin_unlock(&dev_priv->irq_lock); 1588d4d70aa5SImre Deak } 1589baf02a1fSBen Widawsky 1590c9a9a268SImre Deak if (INTEL_INFO(dev_priv)->gen >= 8) 1591c9a9a268SImre Deak return; 1592c9a9a268SImre Deak 15932d1fe073SJoonas Lahtinen if (HAS_VEBOX(dev_priv)) { 159412638c57SBen Widawsky if (pm_iir & PM_VEBOX_USER_INTERRUPT) 15954a570db5STvrtko Ursulin notify_ring(&dev_priv->engine[VECS]); 159612638c57SBen Widawsky 1597aaecdf61SDaniel Vetter if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) 1598aaecdf61SDaniel Vetter DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir); 159912638c57SBen Widawsky } 16001403c0d4SPaulo Zanoni } 1601baf02a1fSBen Widawsky 16025a21b665SDaniel Vetter static bool intel_pipe_handle_vblank(struct drm_i915_private *dev_priv, 160391d14251STvrtko Ursulin enum pipe pipe) 16048d7849dbSVille Syrjälä { 16055a21b665SDaniel Vetter bool ret; 16065a21b665SDaniel Vetter 160791c8a326SChris Wilson ret = drm_handle_vblank(&dev_priv->drm, pipe); 16085a21b665SDaniel Vetter if (ret) 160951cbaf01SMaarten Lankhorst intel_finish_page_flip_mmio(dev_priv, pipe); 16105a21b665SDaniel Vetter 16115a21b665SDaniel Vetter return ret; 16128d7849dbSVille Syrjälä } 16138d7849dbSVille Syrjälä 161491d14251STvrtko Ursulin static void valleyview_pipestat_irq_ack(struct drm_i915_private *dev_priv, 161591d14251STvrtko Ursulin u32 iir, u32 pipe_stats[I915_MAX_PIPES]) 16167e231dbeSJesse Barnes { 16177e231dbeSJesse Barnes int pipe; 16187e231dbeSJesse Barnes 161958ead0d7SImre Deak spin_lock(&dev_priv->irq_lock); 16201ca993d2SVille Syrjälä 16211ca993d2SVille Syrjälä if (!dev_priv->display_irqs_enabled) { 16221ca993d2SVille Syrjälä spin_unlock(&dev_priv->irq_lock); 16231ca993d2SVille Syrjälä return; 16241ca993d2SVille Syrjälä } 16251ca993d2SVille Syrjälä 1626055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 1627f0f59a00SVille Syrjälä i915_reg_t reg; 1628bbb5eebfSDaniel Vetter u32 mask, iir_bit = 0; 162991d181ddSImre Deak 1630bbb5eebfSDaniel Vetter /* 1631bbb5eebfSDaniel Vetter * PIPESTAT bits get signalled even when the interrupt is 1632bbb5eebfSDaniel Vetter * disabled with the mask bits, and some of the status bits do 1633bbb5eebfSDaniel Vetter * not generate interrupts at all (like the underrun bit). Hence 1634bbb5eebfSDaniel Vetter * we need to be careful that we only handle what we want to 1635bbb5eebfSDaniel Vetter * handle. 1636bbb5eebfSDaniel Vetter */ 16370f239f4cSDaniel Vetter 16380f239f4cSDaniel Vetter /* fifo underruns are filterered in the underrun handler. */ 16390f239f4cSDaniel Vetter mask = PIPE_FIFO_UNDERRUN_STATUS; 1640bbb5eebfSDaniel Vetter 1641bbb5eebfSDaniel Vetter switch (pipe) { 1642bbb5eebfSDaniel Vetter case PIPE_A: 1643bbb5eebfSDaniel Vetter iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT; 1644bbb5eebfSDaniel Vetter break; 1645bbb5eebfSDaniel Vetter case PIPE_B: 1646bbb5eebfSDaniel Vetter iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT; 1647bbb5eebfSDaniel Vetter break; 16483278f67fSVille Syrjälä case PIPE_C: 16493278f67fSVille Syrjälä iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT; 16503278f67fSVille Syrjälä break; 1651bbb5eebfSDaniel Vetter } 1652bbb5eebfSDaniel Vetter if (iir & iir_bit) 1653bbb5eebfSDaniel Vetter mask |= dev_priv->pipestat_irq_mask[pipe]; 1654bbb5eebfSDaniel Vetter 1655bbb5eebfSDaniel Vetter if (!mask) 165691d181ddSImre Deak continue; 165791d181ddSImre Deak 165891d181ddSImre Deak reg = PIPESTAT(pipe); 1659bbb5eebfSDaniel Vetter mask |= PIPESTAT_INT_ENABLE_MASK; 1660bbb5eebfSDaniel Vetter pipe_stats[pipe] = I915_READ(reg) & mask; 16617e231dbeSJesse Barnes 16627e231dbeSJesse Barnes /* 16637e231dbeSJesse Barnes * Clear the PIPE*STAT regs before the IIR 16647e231dbeSJesse Barnes */ 166591d181ddSImre Deak if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS | 166691d181ddSImre Deak PIPESTAT_INT_STATUS_MASK)) 16677e231dbeSJesse Barnes I915_WRITE(reg, pipe_stats[pipe]); 16687e231dbeSJesse Barnes } 166958ead0d7SImre Deak spin_unlock(&dev_priv->irq_lock); 16702ecb8ca4SVille Syrjälä } 16712ecb8ca4SVille Syrjälä 167291d14251STvrtko Ursulin static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv, 16732ecb8ca4SVille Syrjälä u32 pipe_stats[I915_MAX_PIPES]) 16742ecb8ca4SVille Syrjälä { 16752ecb8ca4SVille Syrjälä enum pipe pipe; 16767e231dbeSJesse Barnes 1677055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 16785a21b665SDaniel Vetter if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS && 16795a21b665SDaniel Vetter intel_pipe_handle_vblank(dev_priv, pipe)) 16805a21b665SDaniel Vetter intel_check_page_flip(dev_priv, pipe); 168131acc7f5SJesse Barnes 16825251f04eSMaarten Lankhorst if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) 168351cbaf01SMaarten Lankhorst intel_finish_page_flip_cs(dev_priv, pipe); 16844356d586SDaniel Vetter 16854356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 168691d14251STvrtko Ursulin i9xx_pipe_crc_irq_handler(dev_priv, pipe); 16872d9d2b0bSVille Syrjälä 16881f7247c0SDaniel Vetter if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 16891f7247c0SDaniel Vetter intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 169031acc7f5SJesse Barnes } 169131acc7f5SJesse Barnes 1692c1874ed7SImre Deak if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 169391d14251STvrtko Ursulin gmbus_irq_handler(dev_priv); 1694c1874ed7SImre Deak } 1695c1874ed7SImre Deak 16961ae3c34cSVille Syrjälä static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv) 169716c6c56bSVille Syrjälä { 169816c6c56bSVille Syrjälä u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); 169916c6c56bSVille Syrjälä 17001ae3c34cSVille Syrjälä if (hotplug_status) 17013ff60f89SOscar Mateo I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); 17021ae3c34cSVille Syrjälä 17031ae3c34cSVille Syrjälä return hotplug_status; 17041ae3c34cSVille Syrjälä } 17051ae3c34cSVille Syrjälä 170691d14251STvrtko Ursulin static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv, 17071ae3c34cSVille Syrjälä u32 hotplug_status) 17081ae3c34cSVille Syrjälä { 17091ae3c34cSVille Syrjälä u32 pin_mask = 0, long_mask = 0; 17103ff60f89SOscar Mateo 171191d14251STvrtko Ursulin if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || 171291d14251STvrtko Ursulin IS_CHERRYVIEW(dev_priv)) { 171316c6c56bSVille Syrjälä u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X; 171416c6c56bSVille Syrjälä 171558f2cf24SVille Syrjälä if (hotplug_trigger) { 1716fd63e2a9SImre Deak intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger, 1717fd63e2a9SImre Deak hotplug_trigger, hpd_status_g4x, 1718fd63e2a9SImre Deak i9xx_port_hotplug_long_detect); 171958f2cf24SVille Syrjälä 172091d14251STvrtko Ursulin intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 172158f2cf24SVille Syrjälä } 1722369712e8SJani Nikula 1723369712e8SJani Nikula if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X) 172491d14251STvrtko Ursulin dp_aux_irq_handler(dev_priv); 172516c6c56bSVille Syrjälä } else { 172616c6c56bSVille Syrjälä u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915; 172716c6c56bSVille Syrjälä 172858f2cf24SVille Syrjälä if (hotplug_trigger) { 1729fd63e2a9SImre Deak intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger, 17304e3d1e26SVille Syrjälä hotplug_trigger, hpd_status_i915, 1731fd63e2a9SImre Deak i9xx_port_hotplug_long_detect); 173291d14251STvrtko Ursulin intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 173316c6c56bSVille Syrjälä } 17343ff60f89SOscar Mateo } 173558f2cf24SVille Syrjälä } 173616c6c56bSVille Syrjälä 1737c1874ed7SImre Deak static irqreturn_t valleyview_irq_handler(int irq, void *arg) 1738c1874ed7SImre Deak { 173945a83f84SDaniel Vetter struct drm_device *dev = arg; 1740fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 1741c1874ed7SImre Deak irqreturn_t ret = IRQ_NONE; 1742c1874ed7SImre Deak 17432dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 17442dd2a883SImre Deak return IRQ_NONE; 17452dd2a883SImre Deak 17461f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 17471f814dacSImre Deak disable_rpm_wakeref_asserts(dev_priv); 17481f814dacSImre Deak 17491e1cace9SVille Syrjälä do { 17506e814800SVille Syrjälä u32 iir, gt_iir, pm_iir; 17512ecb8ca4SVille Syrjälä u32 pipe_stats[I915_MAX_PIPES] = {}; 17521ae3c34cSVille Syrjälä u32 hotplug_status = 0; 1753a5e485a9SVille Syrjälä u32 ier = 0; 17543ff60f89SOscar Mateo 1755c1874ed7SImre Deak gt_iir = I915_READ(GTIIR); 1756c1874ed7SImre Deak pm_iir = I915_READ(GEN6_PMIIR); 17573ff60f89SOscar Mateo iir = I915_READ(VLV_IIR); 1758c1874ed7SImre Deak 1759c1874ed7SImre Deak if (gt_iir == 0 && pm_iir == 0 && iir == 0) 17601e1cace9SVille Syrjälä break; 1761c1874ed7SImre Deak 1762c1874ed7SImre Deak ret = IRQ_HANDLED; 1763c1874ed7SImre Deak 1764a5e485a9SVille Syrjälä /* 1765a5e485a9SVille Syrjälä * Theory on interrupt generation, based on empirical evidence: 1766a5e485a9SVille Syrjälä * 1767a5e485a9SVille Syrjälä * x = ((VLV_IIR & VLV_IER) || 1768a5e485a9SVille Syrjälä * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) && 1769a5e485a9SVille Syrjälä * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE))); 1770a5e485a9SVille Syrjälä * 1771a5e485a9SVille Syrjälä * A CPU interrupt will only be raised when 'x' has a 0->1 edge. 1772a5e485a9SVille Syrjälä * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to 1773a5e485a9SVille Syrjälä * guarantee the CPU interrupt will be raised again even if we 1774a5e485a9SVille Syrjälä * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR 1775a5e485a9SVille Syrjälä * bits this time around. 1776a5e485a9SVille Syrjälä */ 17774a0a0202SVille Syrjälä I915_WRITE(VLV_MASTER_IER, 0); 1778a5e485a9SVille Syrjälä ier = I915_READ(VLV_IER); 1779a5e485a9SVille Syrjälä I915_WRITE(VLV_IER, 0); 17804a0a0202SVille Syrjälä 17814a0a0202SVille Syrjälä if (gt_iir) 17824a0a0202SVille Syrjälä I915_WRITE(GTIIR, gt_iir); 17834a0a0202SVille Syrjälä if (pm_iir) 17844a0a0202SVille Syrjälä I915_WRITE(GEN6_PMIIR, pm_iir); 17854a0a0202SVille Syrjälä 17867ce4d1f2SVille Syrjälä if (iir & I915_DISPLAY_PORT_INTERRUPT) 17871ae3c34cSVille Syrjälä hotplug_status = i9xx_hpd_irq_ack(dev_priv); 17887ce4d1f2SVille Syrjälä 17893ff60f89SOscar Mateo /* Call regardless, as some status bits might not be 17903ff60f89SOscar Mateo * signalled in iir */ 179191d14251STvrtko Ursulin valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats); 17927ce4d1f2SVille Syrjälä 17937ce4d1f2SVille Syrjälä /* 17947ce4d1f2SVille Syrjälä * VLV_IIR is single buffered, and reflects the level 17957ce4d1f2SVille Syrjälä * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last. 17967ce4d1f2SVille Syrjälä */ 17977ce4d1f2SVille Syrjälä if (iir) 17987ce4d1f2SVille Syrjälä I915_WRITE(VLV_IIR, iir); 17994a0a0202SVille Syrjälä 1800a5e485a9SVille Syrjälä I915_WRITE(VLV_IER, ier); 18014a0a0202SVille Syrjälä I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE); 18024a0a0202SVille Syrjälä POSTING_READ(VLV_MASTER_IER); 18031ae3c34cSVille Syrjälä 180452894874SVille Syrjälä if (gt_iir) 1805261e40b8SVille Syrjälä snb_gt_irq_handler(dev_priv, gt_iir); 180652894874SVille Syrjälä if (pm_iir) 180752894874SVille Syrjälä gen6_rps_irq_handler(dev_priv, pm_iir); 180852894874SVille Syrjälä 18091ae3c34cSVille Syrjälä if (hotplug_status) 181091d14251STvrtko Ursulin i9xx_hpd_irq_handler(dev_priv, hotplug_status); 18112ecb8ca4SVille Syrjälä 181291d14251STvrtko Ursulin valleyview_pipestat_irq_handler(dev_priv, pipe_stats); 18131e1cace9SVille Syrjälä } while (0); 18147e231dbeSJesse Barnes 18151f814dacSImre Deak enable_rpm_wakeref_asserts(dev_priv); 18161f814dacSImre Deak 18177e231dbeSJesse Barnes return ret; 18187e231dbeSJesse Barnes } 18197e231dbeSJesse Barnes 182043f328d7SVille Syrjälä static irqreturn_t cherryview_irq_handler(int irq, void *arg) 182143f328d7SVille Syrjälä { 182245a83f84SDaniel Vetter struct drm_device *dev = arg; 1823fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 182443f328d7SVille Syrjälä irqreturn_t ret = IRQ_NONE; 182543f328d7SVille Syrjälä 18262dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 18272dd2a883SImre Deak return IRQ_NONE; 18282dd2a883SImre Deak 18291f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 18301f814dacSImre Deak disable_rpm_wakeref_asserts(dev_priv); 18311f814dacSImre Deak 1832579de73bSChris Wilson do { 18336e814800SVille Syrjälä u32 master_ctl, iir; 1834e30e251aSVille Syrjälä u32 gt_iir[4] = {}; 18352ecb8ca4SVille Syrjälä u32 pipe_stats[I915_MAX_PIPES] = {}; 18361ae3c34cSVille Syrjälä u32 hotplug_status = 0; 1837a5e485a9SVille Syrjälä u32 ier = 0; 1838a5e485a9SVille Syrjälä 18398e5fd599SVille Syrjälä master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL; 18403278f67fSVille Syrjälä iir = I915_READ(VLV_IIR); 18413278f67fSVille Syrjälä 18423278f67fSVille Syrjälä if (master_ctl == 0 && iir == 0) 18438e5fd599SVille Syrjälä break; 184443f328d7SVille Syrjälä 184527b6c122SOscar Mateo ret = IRQ_HANDLED; 184627b6c122SOscar Mateo 1847a5e485a9SVille Syrjälä /* 1848a5e485a9SVille Syrjälä * Theory on interrupt generation, based on empirical evidence: 1849a5e485a9SVille Syrjälä * 1850a5e485a9SVille Syrjälä * x = ((VLV_IIR & VLV_IER) || 1851a5e485a9SVille Syrjälä * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) && 1852a5e485a9SVille Syrjälä * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL))); 1853a5e485a9SVille Syrjälä * 1854a5e485a9SVille Syrjälä * A CPU interrupt will only be raised when 'x' has a 0->1 edge. 1855a5e485a9SVille Syrjälä * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to 1856a5e485a9SVille Syrjälä * guarantee the CPU interrupt will be raised again even if we 1857a5e485a9SVille Syrjälä * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL 1858a5e485a9SVille Syrjälä * bits this time around. 1859a5e485a9SVille Syrjälä */ 186043f328d7SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, 0); 1861a5e485a9SVille Syrjälä ier = I915_READ(VLV_IER); 1862a5e485a9SVille Syrjälä I915_WRITE(VLV_IER, 0); 186343f328d7SVille Syrjälä 1864e30e251aSVille Syrjälä gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir); 186527b6c122SOscar Mateo 186627b6c122SOscar Mateo if (iir & I915_DISPLAY_PORT_INTERRUPT) 18671ae3c34cSVille Syrjälä hotplug_status = i9xx_hpd_irq_ack(dev_priv); 186843f328d7SVille Syrjälä 186927b6c122SOscar Mateo /* Call regardless, as some status bits might not be 187027b6c122SOscar Mateo * signalled in iir */ 187191d14251STvrtko Ursulin valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats); 187243f328d7SVille Syrjälä 18737ce4d1f2SVille Syrjälä /* 18747ce4d1f2SVille Syrjälä * VLV_IIR is single buffered, and reflects the level 18757ce4d1f2SVille Syrjälä * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last. 18767ce4d1f2SVille Syrjälä */ 18777ce4d1f2SVille Syrjälä if (iir) 18787ce4d1f2SVille Syrjälä I915_WRITE(VLV_IIR, iir); 18797ce4d1f2SVille Syrjälä 1880a5e485a9SVille Syrjälä I915_WRITE(VLV_IER, ier); 1881e5328c43SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); 188243f328d7SVille Syrjälä POSTING_READ(GEN8_MASTER_IRQ); 18831ae3c34cSVille Syrjälä 1884e30e251aSVille Syrjälä gen8_gt_irq_handler(dev_priv, gt_iir); 1885e30e251aSVille Syrjälä 18861ae3c34cSVille Syrjälä if (hotplug_status) 188791d14251STvrtko Ursulin i9xx_hpd_irq_handler(dev_priv, hotplug_status); 18882ecb8ca4SVille Syrjälä 188991d14251STvrtko Ursulin valleyview_pipestat_irq_handler(dev_priv, pipe_stats); 1890579de73bSChris Wilson } while (0); 18913278f67fSVille Syrjälä 18921f814dacSImre Deak enable_rpm_wakeref_asserts(dev_priv); 18931f814dacSImre Deak 189443f328d7SVille Syrjälä return ret; 189543f328d7SVille Syrjälä } 189643f328d7SVille Syrjälä 189791d14251STvrtko Ursulin static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv, 189891d14251STvrtko Ursulin u32 hotplug_trigger, 189940e56410SVille Syrjälä const u32 hpd[HPD_NUM_PINS]) 1900776ad806SJesse Barnes { 190142db67d6SVille Syrjälä u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0; 1902776ad806SJesse Barnes 19036a39d7c9SJani Nikula /* 19046a39d7c9SJani Nikula * Somehow the PCH doesn't seem to really ack the interrupt to the CPU 19056a39d7c9SJani Nikula * unless we touch the hotplug register, even if hotplug_trigger is 19066a39d7c9SJani Nikula * zero. Not acking leads to "The master control interrupt lied (SDE)!" 19076a39d7c9SJani Nikula * errors. 19086a39d7c9SJani Nikula */ 190913cf5504SDave Airlie dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG); 19106a39d7c9SJani Nikula if (!hotplug_trigger) { 19116a39d7c9SJani Nikula u32 mask = PORTA_HOTPLUG_STATUS_MASK | 19126a39d7c9SJani Nikula PORTD_HOTPLUG_STATUS_MASK | 19136a39d7c9SJani Nikula PORTC_HOTPLUG_STATUS_MASK | 19146a39d7c9SJani Nikula PORTB_HOTPLUG_STATUS_MASK; 19156a39d7c9SJani Nikula dig_hotplug_reg &= ~mask; 19166a39d7c9SJani Nikula } 19176a39d7c9SJani Nikula 191813cf5504SDave Airlie I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg); 19196a39d7c9SJani Nikula if (!hotplug_trigger) 19206a39d7c9SJani Nikula return; 192113cf5504SDave Airlie 1922fd63e2a9SImre Deak intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger, 192340e56410SVille Syrjälä dig_hotplug_reg, hpd, 1924fd63e2a9SImre Deak pch_port_hotplug_long_detect); 192540e56410SVille Syrjälä 192691d14251STvrtko Ursulin intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 1927aaf5ec2eSSonika Jindal } 192891d131d2SDaniel Vetter 192991d14251STvrtko Ursulin static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir) 193040e56410SVille Syrjälä { 193140e56410SVille Syrjälä int pipe; 193240e56410SVille Syrjälä u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK; 193340e56410SVille Syrjälä 193491d14251STvrtko Ursulin ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ibx); 193540e56410SVille Syrjälä 1936cfc33bf7SVille Syrjälä if (pch_iir & SDE_AUDIO_POWER_MASK) { 1937cfc33bf7SVille Syrjälä int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >> 1938776ad806SJesse Barnes SDE_AUDIO_POWER_SHIFT); 1939cfc33bf7SVille Syrjälä DRM_DEBUG_DRIVER("PCH audio power change on port %d\n", 1940cfc33bf7SVille Syrjälä port_name(port)); 1941cfc33bf7SVille Syrjälä } 1942776ad806SJesse Barnes 1943ce99c256SDaniel Vetter if (pch_iir & SDE_AUX_MASK) 194491d14251STvrtko Ursulin dp_aux_irq_handler(dev_priv); 1945ce99c256SDaniel Vetter 1946776ad806SJesse Barnes if (pch_iir & SDE_GMBUS) 194791d14251STvrtko Ursulin gmbus_irq_handler(dev_priv); 1948776ad806SJesse Barnes 1949776ad806SJesse Barnes if (pch_iir & SDE_AUDIO_HDCP_MASK) 1950776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n"); 1951776ad806SJesse Barnes 1952776ad806SJesse Barnes if (pch_iir & SDE_AUDIO_TRANS_MASK) 1953776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n"); 1954776ad806SJesse Barnes 1955776ad806SJesse Barnes if (pch_iir & SDE_POISON) 1956776ad806SJesse Barnes DRM_ERROR("PCH poison interrupt\n"); 1957776ad806SJesse Barnes 19589db4a9c7SJesse Barnes if (pch_iir & SDE_FDI_MASK) 1959055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 19609db4a9c7SJesse Barnes DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", 19619db4a9c7SJesse Barnes pipe_name(pipe), 19629db4a9c7SJesse Barnes I915_READ(FDI_RX_IIR(pipe))); 1963776ad806SJesse Barnes 1964776ad806SJesse Barnes if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE)) 1965776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n"); 1966776ad806SJesse Barnes 1967776ad806SJesse Barnes if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR)) 1968776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n"); 1969776ad806SJesse Barnes 1970776ad806SJesse Barnes if (pch_iir & SDE_TRANSA_FIFO_UNDER) 19711f7247c0SDaniel Vetter intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A); 19728664281bSPaulo Zanoni 19738664281bSPaulo Zanoni if (pch_iir & SDE_TRANSB_FIFO_UNDER) 19741f7247c0SDaniel Vetter intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B); 19758664281bSPaulo Zanoni } 19768664281bSPaulo Zanoni 197791d14251STvrtko Ursulin static void ivb_err_int_handler(struct drm_i915_private *dev_priv) 19788664281bSPaulo Zanoni { 19798664281bSPaulo Zanoni u32 err_int = I915_READ(GEN7_ERR_INT); 19805a69b89fSDaniel Vetter enum pipe pipe; 19818664281bSPaulo Zanoni 1982de032bf4SPaulo Zanoni if (err_int & ERR_INT_POISON) 1983de032bf4SPaulo Zanoni DRM_ERROR("Poison interrupt\n"); 1984de032bf4SPaulo Zanoni 1985055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 19861f7247c0SDaniel Vetter if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) 19871f7247c0SDaniel Vetter intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 19888664281bSPaulo Zanoni 19895a69b89fSDaniel Vetter if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) { 199091d14251STvrtko Ursulin if (IS_IVYBRIDGE(dev_priv)) 199191d14251STvrtko Ursulin ivb_pipe_crc_irq_handler(dev_priv, pipe); 19925a69b89fSDaniel Vetter else 199391d14251STvrtko Ursulin hsw_pipe_crc_irq_handler(dev_priv, pipe); 19945a69b89fSDaniel Vetter } 19955a69b89fSDaniel Vetter } 19968bf1e9f1SShuang He 19978664281bSPaulo Zanoni I915_WRITE(GEN7_ERR_INT, err_int); 19988664281bSPaulo Zanoni } 19998664281bSPaulo Zanoni 200091d14251STvrtko Ursulin static void cpt_serr_int_handler(struct drm_i915_private *dev_priv) 20018664281bSPaulo Zanoni { 20028664281bSPaulo Zanoni u32 serr_int = I915_READ(SERR_INT); 20038664281bSPaulo Zanoni 2004de032bf4SPaulo Zanoni if (serr_int & SERR_INT_POISON) 2005de032bf4SPaulo Zanoni DRM_ERROR("PCH poison interrupt\n"); 2006de032bf4SPaulo Zanoni 20078664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN) 20081f7247c0SDaniel Vetter intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A); 20098664281bSPaulo Zanoni 20108664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN) 20111f7247c0SDaniel Vetter intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B); 20128664281bSPaulo Zanoni 20138664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN) 20141f7247c0SDaniel Vetter intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_C); 20158664281bSPaulo Zanoni 20168664281bSPaulo Zanoni I915_WRITE(SERR_INT, serr_int); 2017776ad806SJesse Barnes } 2018776ad806SJesse Barnes 201991d14251STvrtko Ursulin static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir) 202023e81d69SAdam Jackson { 202123e81d69SAdam Jackson int pipe; 20226dbf30ceSVille Syrjälä u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT; 2023aaf5ec2eSSonika Jindal 202491d14251STvrtko Ursulin ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_cpt); 202591d131d2SDaniel Vetter 2026cfc33bf7SVille Syrjälä if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) { 2027cfc33bf7SVille Syrjälä int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >> 202823e81d69SAdam Jackson SDE_AUDIO_POWER_SHIFT_CPT); 2029cfc33bf7SVille Syrjälä DRM_DEBUG_DRIVER("PCH audio power change on port %c\n", 2030cfc33bf7SVille Syrjälä port_name(port)); 2031cfc33bf7SVille Syrjälä } 203223e81d69SAdam Jackson 203323e81d69SAdam Jackson if (pch_iir & SDE_AUX_MASK_CPT) 203491d14251STvrtko Ursulin dp_aux_irq_handler(dev_priv); 203523e81d69SAdam Jackson 203623e81d69SAdam Jackson if (pch_iir & SDE_GMBUS_CPT) 203791d14251STvrtko Ursulin gmbus_irq_handler(dev_priv); 203823e81d69SAdam Jackson 203923e81d69SAdam Jackson if (pch_iir & SDE_AUDIO_CP_REQ_CPT) 204023e81d69SAdam Jackson DRM_DEBUG_DRIVER("Audio CP request interrupt\n"); 204123e81d69SAdam Jackson 204223e81d69SAdam Jackson if (pch_iir & SDE_AUDIO_CP_CHG_CPT) 204323e81d69SAdam Jackson DRM_DEBUG_DRIVER("Audio CP change interrupt\n"); 204423e81d69SAdam Jackson 204523e81d69SAdam Jackson if (pch_iir & SDE_FDI_MASK_CPT) 2046055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 204723e81d69SAdam Jackson DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", 204823e81d69SAdam Jackson pipe_name(pipe), 204923e81d69SAdam Jackson I915_READ(FDI_RX_IIR(pipe))); 20508664281bSPaulo Zanoni 20518664281bSPaulo Zanoni if (pch_iir & SDE_ERROR_CPT) 205291d14251STvrtko Ursulin cpt_serr_int_handler(dev_priv); 205323e81d69SAdam Jackson } 205423e81d69SAdam Jackson 205591d14251STvrtko Ursulin static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir) 20566dbf30ceSVille Syrjälä { 20576dbf30ceSVille Syrjälä u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT & 20586dbf30ceSVille Syrjälä ~SDE_PORTE_HOTPLUG_SPT; 20596dbf30ceSVille Syrjälä u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT; 20606dbf30ceSVille Syrjälä u32 pin_mask = 0, long_mask = 0; 20616dbf30ceSVille Syrjälä 20626dbf30ceSVille Syrjälä if (hotplug_trigger) { 20636dbf30ceSVille Syrjälä u32 dig_hotplug_reg; 20646dbf30ceSVille Syrjälä 20656dbf30ceSVille Syrjälä dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG); 20666dbf30ceSVille Syrjälä I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg); 20676dbf30ceSVille Syrjälä 20686dbf30ceSVille Syrjälä intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger, 20696dbf30ceSVille Syrjälä dig_hotplug_reg, hpd_spt, 207074c0b395SVille Syrjälä spt_port_hotplug_long_detect); 20716dbf30ceSVille Syrjälä } 20726dbf30ceSVille Syrjälä 20736dbf30ceSVille Syrjälä if (hotplug2_trigger) { 20746dbf30ceSVille Syrjälä u32 dig_hotplug_reg; 20756dbf30ceSVille Syrjälä 20766dbf30ceSVille Syrjälä dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2); 20776dbf30ceSVille Syrjälä I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg); 20786dbf30ceSVille Syrjälä 20796dbf30ceSVille Syrjälä intel_get_hpd_pins(&pin_mask, &long_mask, hotplug2_trigger, 20806dbf30ceSVille Syrjälä dig_hotplug_reg, hpd_spt, 20816dbf30ceSVille Syrjälä spt_port_hotplug2_long_detect); 20826dbf30ceSVille Syrjälä } 20836dbf30ceSVille Syrjälä 20846dbf30ceSVille Syrjälä if (pin_mask) 208591d14251STvrtko Ursulin intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 20866dbf30ceSVille Syrjälä 20876dbf30ceSVille Syrjälä if (pch_iir & SDE_GMBUS_CPT) 208891d14251STvrtko Ursulin gmbus_irq_handler(dev_priv); 20896dbf30ceSVille Syrjälä } 20906dbf30ceSVille Syrjälä 209191d14251STvrtko Ursulin static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv, 209291d14251STvrtko Ursulin u32 hotplug_trigger, 209340e56410SVille Syrjälä const u32 hpd[HPD_NUM_PINS]) 2094c008bc6eSPaulo Zanoni { 2095e4ce95aaSVille Syrjälä u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0; 2096e4ce95aaSVille Syrjälä 2097e4ce95aaSVille Syrjälä dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL); 2098e4ce95aaSVille Syrjälä I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg); 2099e4ce95aaSVille Syrjälä 2100e4ce95aaSVille Syrjälä intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger, 210140e56410SVille Syrjälä dig_hotplug_reg, hpd, 2102e4ce95aaSVille Syrjälä ilk_port_hotplug_long_detect); 210340e56410SVille Syrjälä 210491d14251STvrtko Ursulin intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 2105e4ce95aaSVille Syrjälä } 2106c008bc6eSPaulo Zanoni 210791d14251STvrtko Ursulin static void ilk_display_irq_handler(struct drm_i915_private *dev_priv, 210891d14251STvrtko Ursulin u32 de_iir) 210940e56410SVille Syrjälä { 211040e56410SVille Syrjälä enum pipe pipe; 211140e56410SVille Syrjälä u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG; 211240e56410SVille Syrjälä 211340e56410SVille Syrjälä if (hotplug_trigger) 211491d14251STvrtko Ursulin ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk); 211540e56410SVille Syrjälä 2116c008bc6eSPaulo Zanoni if (de_iir & DE_AUX_CHANNEL_A) 211791d14251STvrtko Ursulin dp_aux_irq_handler(dev_priv); 2118c008bc6eSPaulo Zanoni 2119c008bc6eSPaulo Zanoni if (de_iir & DE_GSE) 212091d14251STvrtko Ursulin intel_opregion_asle_intr(dev_priv); 2121c008bc6eSPaulo Zanoni 2122c008bc6eSPaulo Zanoni if (de_iir & DE_POISON) 2123c008bc6eSPaulo Zanoni DRM_ERROR("Poison interrupt\n"); 2124c008bc6eSPaulo Zanoni 2125055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 21265a21b665SDaniel Vetter if (de_iir & DE_PIPE_VBLANK(pipe) && 21275a21b665SDaniel Vetter intel_pipe_handle_vblank(dev_priv, pipe)) 21285a21b665SDaniel Vetter intel_check_page_flip(dev_priv, pipe); 2129c008bc6eSPaulo Zanoni 213040da17c2SDaniel Vetter if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe)) 21311f7247c0SDaniel Vetter intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 2132c008bc6eSPaulo Zanoni 213340da17c2SDaniel Vetter if (de_iir & DE_PIPE_CRC_DONE(pipe)) 213491d14251STvrtko Ursulin i9xx_pipe_crc_irq_handler(dev_priv, pipe); 21355b3a856bSDaniel Vetter 213640da17c2SDaniel Vetter /* plane/pipes map 1:1 on ilk+ */ 21375251f04eSMaarten Lankhorst if (de_iir & DE_PLANE_FLIP_DONE(pipe)) 213851cbaf01SMaarten Lankhorst intel_finish_page_flip_cs(dev_priv, pipe); 2139c008bc6eSPaulo Zanoni } 2140c008bc6eSPaulo Zanoni 2141c008bc6eSPaulo Zanoni /* check event from PCH */ 2142c008bc6eSPaulo Zanoni if (de_iir & DE_PCH_EVENT) { 2143c008bc6eSPaulo Zanoni u32 pch_iir = I915_READ(SDEIIR); 2144c008bc6eSPaulo Zanoni 214591d14251STvrtko Ursulin if (HAS_PCH_CPT(dev_priv)) 214691d14251STvrtko Ursulin cpt_irq_handler(dev_priv, pch_iir); 2147c008bc6eSPaulo Zanoni else 214891d14251STvrtko Ursulin ibx_irq_handler(dev_priv, pch_iir); 2149c008bc6eSPaulo Zanoni 2150c008bc6eSPaulo Zanoni /* should clear PCH hotplug event before clear CPU irq */ 2151c008bc6eSPaulo Zanoni I915_WRITE(SDEIIR, pch_iir); 2152c008bc6eSPaulo Zanoni } 2153c008bc6eSPaulo Zanoni 215491d14251STvrtko Ursulin if (IS_GEN5(dev_priv) && de_iir & DE_PCU_EVENT) 215591d14251STvrtko Ursulin ironlake_rps_change_irq_handler(dev_priv); 2156c008bc6eSPaulo Zanoni } 2157c008bc6eSPaulo Zanoni 215891d14251STvrtko Ursulin static void ivb_display_irq_handler(struct drm_i915_private *dev_priv, 215991d14251STvrtko Ursulin u32 de_iir) 21609719fb98SPaulo Zanoni { 216107d27e20SDamien Lespiau enum pipe pipe; 216223bb4cb5SVille Syrjälä u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB; 216323bb4cb5SVille Syrjälä 216440e56410SVille Syrjälä if (hotplug_trigger) 216591d14251STvrtko Ursulin ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb); 21669719fb98SPaulo Zanoni 21679719fb98SPaulo Zanoni if (de_iir & DE_ERR_INT_IVB) 216891d14251STvrtko Ursulin ivb_err_int_handler(dev_priv); 21699719fb98SPaulo Zanoni 21709719fb98SPaulo Zanoni if (de_iir & DE_AUX_CHANNEL_A_IVB) 217191d14251STvrtko Ursulin dp_aux_irq_handler(dev_priv); 21729719fb98SPaulo Zanoni 21739719fb98SPaulo Zanoni if (de_iir & DE_GSE_IVB) 217491d14251STvrtko Ursulin intel_opregion_asle_intr(dev_priv); 21759719fb98SPaulo Zanoni 2176055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 21775a21b665SDaniel Vetter if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)) && 21785a21b665SDaniel Vetter intel_pipe_handle_vblank(dev_priv, pipe)) 21795a21b665SDaniel Vetter intel_check_page_flip(dev_priv, pipe); 218040da17c2SDaniel Vetter 218140da17c2SDaniel Vetter /* plane/pipes map 1:1 on ilk+ */ 21825251f04eSMaarten Lankhorst if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) 218351cbaf01SMaarten Lankhorst intel_finish_page_flip_cs(dev_priv, pipe); 21849719fb98SPaulo Zanoni } 21859719fb98SPaulo Zanoni 21869719fb98SPaulo Zanoni /* check event from PCH */ 218791d14251STvrtko Ursulin if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) { 21889719fb98SPaulo Zanoni u32 pch_iir = I915_READ(SDEIIR); 21899719fb98SPaulo Zanoni 219091d14251STvrtko Ursulin cpt_irq_handler(dev_priv, pch_iir); 21919719fb98SPaulo Zanoni 21929719fb98SPaulo Zanoni /* clear PCH hotplug event before clear CPU irq */ 21939719fb98SPaulo Zanoni I915_WRITE(SDEIIR, pch_iir); 21949719fb98SPaulo Zanoni } 21959719fb98SPaulo Zanoni } 21969719fb98SPaulo Zanoni 219772c90f62SOscar Mateo /* 219872c90f62SOscar Mateo * To handle irqs with the minimum potential races with fresh interrupts, we: 219972c90f62SOscar Mateo * 1 - Disable Master Interrupt Control. 220072c90f62SOscar Mateo * 2 - Find the source(s) of the interrupt. 220172c90f62SOscar Mateo * 3 - Clear the Interrupt Identity bits (IIR). 220272c90f62SOscar Mateo * 4 - Process the interrupt(s) that had bits set in the IIRs. 220372c90f62SOscar Mateo * 5 - Re-enable Master Interrupt Control. 220472c90f62SOscar Mateo */ 2205f1af8fc1SPaulo Zanoni static irqreturn_t ironlake_irq_handler(int irq, void *arg) 2206b1f14ad0SJesse Barnes { 220745a83f84SDaniel Vetter struct drm_device *dev = arg; 2208fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 2209f1af8fc1SPaulo Zanoni u32 de_iir, gt_iir, de_ier, sde_ier = 0; 22100e43406bSChris Wilson irqreturn_t ret = IRQ_NONE; 2211b1f14ad0SJesse Barnes 22122dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 22132dd2a883SImre Deak return IRQ_NONE; 22142dd2a883SImre Deak 22151f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 22161f814dacSImre Deak disable_rpm_wakeref_asserts(dev_priv); 22171f814dacSImre Deak 2218b1f14ad0SJesse Barnes /* disable master interrupt before clearing iir */ 2219b1f14ad0SJesse Barnes de_ier = I915_READ(DEIER); 2220b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL); 222123a78516SPaulo Zanoni POSTING_READ(DEIER); 22220e43406bSChris Wilson 222344498aeaSPaulo Zanoni /* Disable south interrupts. We'll only write to SDEIIR once, so further 222444498aeaSPaulo Zanoni * interrupts will will be stored on its back queue, and then we'll be 222544498aeaSPaulo Zanoni * able to process them after we restore SDEIER (as soon as we restore 222644498aeaSPaulo Zanoni * it, we'll get an interrupt if SDEIIR still has something to process 222744498aeaSPaulo Zanoni * due to its back queue). */ 222891d14251STvrtko Ursulin if (!HAS_PCH_NOP(dev_priv)) { 222944498aeaSPaulo Zanoni sde_ier = I915_READ(SDEIER); 223044498aeaSPaulo Zanoni I915_WRITE(SDEIER, 0); 223144498aeaSPaulo Zanoni POSTING_READ(SDEIER); 2232ab5c608bSBen Widawsky } 223344498aeaSPaulo Zanoni 223472c90f62SOscar Mateo /* Find, clear, then process each source of interrupt */ 223572c90f62SOscar Mateo 22360e43406bSChris Wilson gt_iir = I915_READ(GTIIR); 22370e43406bSChris Wilson if (gt_iir) { 223872c90f62SOscar Mateo I915_WRITE(GTIIR, gt_iir); 223972c90f62SOscar Mateo ret = IRQ_HANDLED; 224091d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 6) 2241261e40b8SVille Syrjälä snb_gt_irq_handler(dev_priv, gt_iir); 2242d8fc8a47SPaulo Zanoni else 2243261e40b8SVille Syrjälä ilk_gt_irq_handler(dev_priv, gt_iir); 22440e43406bSChris Wilson } 2245b1f14ad0SJesse Barnes 2246b1f14ad0SJesse Barnes de_iir = I915_READ(DEIIR); 22470e43406bSChris Wilson if (de_iir) { 224872c90f62SOscar Mateo I915_WRITE(DEIIR, de_iir); 224972c90f62SOscar Mateo ret = IRQ_HANDLED; 225091d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 7) 225191d14251STvrtko Ursulin ivb_display_irq_handler(dev_priv, de_iir); 2252f1af8fc1SPaulo Zanoni else 225391d14251STvrtko Ursulin ilk_display_irq_handler(dev_priv, de_iir); 22540e43406bSChris Wilson } 22550e43406bSChris Wilson 225691d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 6) { 2257f1af8fc1SPaulo Zanoni u32 pm_iir = I915_READ(GEN6_PMIIR); 22580e43406bSChris Wilson if (pm_iir) { 2259b1f14ad0SJesse Barnes I915_WRITE(GEN6_PMIIR, pm_iir); 22600e43406bSChris Wilson ret = IRQ_HANDLED; 226172c90f62SOscar Mateo gen6_rps_irq_handler(dev_priv, pm_iir); 22620e43406bSChris Wilson } 2263f1af8fc1SPaulo Zanoni } 2264b1f14ad0SJesse Barnes 2265b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier); 2266b1f14ad0SJesse Barnes POSTING_READ(DEIER); 226791d14251STvrtko Ursulin if (!HAS_PCH_NOP(dev_priv)) { 226844498aeaSPaulo Zanoni I915_WRITE(SDEIER, sde_ier); 226944498aeaSPaulo Zanoni POSTING_READ(SDEIER); 2270ab5c608bSBen Widawsky } 2271b1f14ad0SJesse Barnes 22721f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 22731f814dacSImre Deak enable_rpm_wakeref_asserts(dev_priv); 22741f814dacSImre Deak 2275b1f14ad0SJesse Barnes return ret; 2276b1f14ad0SJesse Barnes } 2277b1f14ad0SJesse Barnes 227891d14251STvrtko Ursulin static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv, 227991d14251STvrtko Ursulin u32 hotplug_trigger, 228040e56410SVille Syrjälä const u32 hpd[HPD_NUM_PINS]) 2281d04a492dSShashank Sharma { 2282cebd87a0SVille Syrjälä u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0; 2283d04a492dSShashank Sharma 2284a52bb15bSVille Syrjälä dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG); 2285a52bb15bSVille Syrjälä I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg); 2286d04a492dSShashank Sharma 2287cebd87a0SVille Syrjälä intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger, 228840e56410SVille Syrjälä dig_hotplug_reg, hpd, 2289cebd87a0SVille Syrjälä bxt_port_hotplug_long_detect); 229040e56410SVille Syrjälä 229191d14251STvrtko Ursulin intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 2292d04a492dSShashank Sharma } 2293d04a492dSShashank Sharma 2294f11a0f46STvrtko Ursulin static irqreturn_t 2295f11a0f46STvrtko Ursulin gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl) 2296abd58f01SBen Widawsky { 2297abd58f01SBen Widawsky irqreturn_t ret = IRQ_NONE; 2298f11a0f46STvrtko Ursulin u32 iir; 2299c42664ccSDaniel Vetter enum pipe pipe; 230088e04703SJesse Barnes 2301abd58f01SBen Widawsky if (master_ctl & GEN8_DE_MISC_IRQ) { 2302e32192e1STvrtko Ursulin iir = I915_READ(GEN8_DE_MISC_IIR); 2303e32192e1STvrtko Ursulin if (iir) { 2304e32192e1STvrtko Ursulin I915_WRITE(GEN8_DE_MISC_IIR, iir); 2305abd58f01SBen Widawsky ret = IRQ_HANDLED; 2306e32192e1STvrtko Ursulin if (iir & GEN8_DE_MISC_GSE) 230791d14251STvrtko Ursulin intel_opregion_asle_intr(dev_priv); 230838cc46d7SOscar Mateo else 230938cc46d7SOscar Mateo DRM_ERROR("Unexpected DE Misc interrupt\n"); 2310abd58f01SBen Widawsky } 231138cc46d7SOscar Mateo else 231238cc46d7SOscar Mateo DRM_ERROR("The master control interrupt lied (DE MISC)!\n"); 2313abd58f01SBen Widawsky } 2314abd58f01SBen Widawsky 23156d766f02SDaniel Vetter if (master_ctl & GEN8_DE_PORT_IRQ) { 2316e32192e1STvrtko Ursulin iir = I915_READ(GEN8_DE_PORT_IIR); 2317e32192e1STvrtko Ursulin if (iir) { 2318e32192e1STvrtko Ursulin u32 tmp_mask; 2319d04a492dSShashank Sharma bool found = false; 2320cebd87a0SVille Syrjälä 2321e32192e1STvrtko Ursulin I915_WRITE(GEN8_DE_PORT_IIR, iir); 23226d766f02SDaniel Vetter ret = IRQ_HANDLED; 232388e04703SJesse Barnes 2324e32192e1STvrtko Ursulin tmp_mask = GEN8_AUX_CHANNEL_A; 2325e32192e1STvrtko Ursulin if (INTEL_INFO(dev_priv)->gen >= 9) 2326e32192e1STvrtko Ursulin tmp_mask |= GEN9_AUX_CHANNEL_B | 2327e32192e1STvrtko Ursulin GEN9_AUX_CHANNEL_C | 2328e32192e1STvrtko Ursulin GEN9_AUX_CHANNEL_D; 2329e32192e1STvrtko Ursulin 2330e32192e1STvrtko Ursulin if (iir & tmp_mask) { 233191d14251STvrtko Ursulin dp_aux_irq_handler(dev_priv); 2332d04a492dSShashank Sharma found = true; 2333d04a492dSShashank Sharma } 2334d04a492dSShashank Sharma 2335e32192e1STvrtko Ursulin if (IS_BROXTON(dev_priv)) { 2336e32192e1STvrtko Ursulin tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK; 2337e32192e1STvrtko Ursulin if (tmp_mask) { 233891d14251STvrtko Ursulin bxt_hpd_irq_handler(dev_priv, tmp_mask, 233991d14251STvrtko Ursulin hpd_bxt); 2340d04a492dSShashank Sharma found = true; 2341d04a492dSShashank Sharma } 2342e32192e1STvrtko Ursulin } else if (IS_BROADWELL(dev_priv)) { 2343e32192e1STvrtko Ursulin tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG; 2344e32192e1STvrtko Ursulin if (tmp_mask) { 234591d14251STvrtko Ursulin ilk_hpd_irq_handler(dev_priv, 234691d14251STvrtko Ursulin tmp_mask, hpd_bdw); 2347e32192e1STvrtko Ursulin found = true; 2348e32192e1STvrtko Ursulin } 2349e32192e1STvrtko Ursulin } 2350d04a492dSShashank Sharma 235191d14251STvrtko Ursulin if (IS_BROXTON(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) { 235291d14251STvrtko Ursulin gmbus_irq_handler(dev_priv); 23539e63743eSShashank Sharma found = true; 23549e63743eSShashank Sharma } 23559e63743eSShashank Sharma 2356d04a492dSShashank Sharma if (!found) 235738cc46d7SOscar Mateo DRM_ERROR("Unexpected DE Port interrupt\n"); 23586d766f02SDaniel Vetter } 235938cc46d7SOscar Mateo else 236038cc46d7SOscar Mateo DRM_ERROR("The master control interrupt lied (DE PORT)!\n"); 23616d766f02SDaniel Vetter } 23626d766f02SDaniel Vetter 2363055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 2364e32192e1STvrtko Ursulin u32 flip_done, fault_errors; 2365abd58f01SBen Widawsky 2366c42664ccSDaniel Vetter if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe))) 2367c42664ccSDaniel Vetter continue; 2368c42664ccSDaniel Vetter 2369e32192e1STvrtko Ursulin iir = I915_READ(GEN8_DE_PIPE_IIR(pipe)); 2370e32192e1STvrtko Ursulin if (!iir) { 2371e32192e1STvrtko Ursulin DRM_ERROR("The master control interrupt lied (DE PIPE)!\n"); 2372e32192e1STvrtko Ursulin continue; 2373e32192e1STvrtko Ursulin } 2374770de83dSDamien Lespiau 2375e32192e1STvrtko Ursulin ret = IRQ_HANDLED; 2376e32192e1STvrtko Ursulin I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir); 2377e32192e1STvrtko Ursulin 23785a21b665SDaniel Vetter if (iir & GEN8_PIPE_VBLANK && 23795a21b665SDaniel Vetter intel_pipe_handle_vblank(dev_priv, pipe)) 23805a21b665SDaniel Vetter intel_check_page_flip(dev_priv, pipe); 2381abd58f01SBen Widawsky 2382e32192e1STvrtko Ursulin flip_done = iir; 2383b4834a50SRodrigo Vivi if (INTEL_INFO(dev_priv)->gen >= 9) 2384e32192e1STvrtko Ursulin flip_done &= GEN9_PIPE_PLANE1_FLIP_DONE; 2385770de83dSDamien Lespiau else 2386e32192e1STvrtko Ursulin flip_done &= GEN8_PIPE_PRIMARY_FLIP_DONE; 2387770de83dSDamien Lespiau 23885251f04eSMaarten Lankhorst if (flip_done) 238951cbaf01SMaarten Lankhorst intel_finish_page_flip_cs(dev_priv, pipe); 2390abd58f01SBen Widawsky 2391e32192e1STvrtko Ursulin if (iir & GEN8_PIPE_CDCLK_CRC_DONE) 239291d14251STvrtko Ursulin hsw_pipe_crc_irq_handler(dev_priv, pipe); 23930fbe7870SDaniel Vetter 2394e32192e1STvrtko Ursulin if (iir & GEN8_PIPE_FIFO_UNDERRUN) 2395e32192e1STvrtko Ursulin intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 239638d83c96SDaniel Vetter 2397e32192e1STvrtko Ursulin fault_errors = iir; 2398b4834a50SRodrigo Vivi if (INTEL_INFO(dev_priv)->gen >= 9) 2399e32192e1STvrtko Ursulin fault_errors &= GEN9_DE_PIPE_IRQ_FAULT_ERRORS; 2400770de83dSDamien Lespiau else 2401e32192e1STvrtko Ursulin fault_errors &= GEN8_DE_PIPE_IRQ_FAULT_ERRORS; 2402770de83dSDamien Lespiau 2403770de83dSDamien Lespiau if (fault_errors) 240430100f2bSDaniel Vetter DRM_ERROR("Fault errors on pipe %c\n: 0x%08x", 240530100f2bSDaniel Vetter pipe_name(pipe), 2406e32192e1STvrtko Ursulin fault_errors); 2407abd58f01SBen Widawsky } 2408abd58f01SBen Widawsky 240991d14251STvrtko Ursulin if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) && 2410266ea3d9SShashank Sharma master_ctl & GEN8_DE_PCH_IRQ) { 241192d03a80SDaniel Vetter /* 241292d03a80SDaniel Vetter * FIXME(BDW): Assume for now that the new interrupt handling 241392d03a80SDaniel Vetter * scheme also closed the SDE interrupt handling race we've seen 241492d03a80SDaniel Vetter * on older pch-split platforms. But this needs testing. 241592d03a80SDaniel Vetter */ 2416e32192e1STvrtko Ursulin iir = I915_READ(SDEIIR); 2417e32192e1STvrtko Ursulin if (iir) { 2418e32192e1STvrtko Ursulin I915_WRITE(SDEIIR, iir); 241992d03a80SDaniel Vetter ret = IRQ_HANDLED; 24206dbf30ceSVille Syrjälä 242122dea0beSRodrigo Vivi if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv)) 242291d14251STvrtko Ursulin spt_irq_handler(dev_priv, iir); 24236dbf30ceSVille Syrjälä else 242491d14251STvrtko Ursulin cpt_irq_handler(dev_priv, iir); 24252dfb0b81SJani Nikula } else { 24262dfb0b81SJani Nikula /* 24272dfb0b81SJani Nikula * Like on previous PCH there seems to be something 24282dfb0b81SJani Nikula * fishy going on with forwarding PCH interrupts. 24292dfb0b81SJani Nikula */ 24302dfb0b81SJani Nikula DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n"); 24312dfb0b81SJani Nikula } 243292d03a80SDaniel Vetter } 243392d03a80SDaniel Vetter 2434f11a0f46STvrtko Ursulin return ret; 2435f11a0f46STvrtko Ursulin } 2436f11a0f46STvrtko Ursulin 2437f11a0f46STvrtko Ursulin static irqreturn_t gen8_irq_handler(int irq, void *arg) 2438f11a0f46STvrtko Ursulin { 2439f11a0f46STvrtko Ursulin struct drm_device *dev = arg; 2440fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 2441f11a0f46STvrtko Ursulin u32 master_ctl; 2442e30e251aSVille Syrjälä u32 gt_iir[4] = {}; 2443f11a0f46STvrtko Ursulin irqreturn_t ret; 2444f11a0f46STvrtko Ursulin 2445f11a0f46STvrtko Ursulin if (!intel_irqs_enabled(dev_priv)) 2446f11a0f46STvrtko Ursulin return IRQ_NONE; 2447f11a0f46STvrtko Ursulin 2448f11a0f46STvrtko Ursulin master_ctl = I915_READ_FW(GEN8_MASTER_IRQ); 2449f11a0f46STvrtko Ursulin master_ctl &= ~GEN8_MASTER_IRQ_CONTROL; 2450f11a0f46STvrtko Ursulin if (!master_ctl) 2451f11a0f46STvrtko Ursulin return IRQ_NONE; 2452f11a0f46STvrtko Ursulin 2453f11a0f46STvrtko Ursulin I915_WRITE_FW(GEN8_MASTER_IRQ, 0); 2454f11a0f46STvrtko Ursulin 2455f11a0f46STvrtko Ursulin /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 2456f11a0f46STvrtko Ursulin disable_rpm_wakeref_asserts(dev_priv); 2457f11a0f46STvrtko Ursulin 2458f11a0f46STvrtko Ursulin /* Find, clear, then process each source of interrupt */ 2459e30e251aSVille Syrjälä ret = gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir); 2460e30e251aSVille Syrjälä gen8_gt_irq_handler(dev_priv, gt_iir); 2461f11a0f46STvrtko Ursulin ret |= gen8_de_irq_handler(dev_priv, master_ctl); 2462f11a0f46STvrtko Ursulin 2463cb0d205eSChris Wilson I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); 2464cb0d205eSChris Wilson POSTING_READ_FW(GEN8_MASTER_IRQ); 2465abd58f01SBen Widawsky 24661f814dacSImre Deak enable_rpm_wakeref_asserts(dev_priv); 24671f814dacSImre Deak 2468abd58f01SBen Widawsky return ret; 2469abd58f01SBen Widawsky } 2470abd58f01SBen Widawsky 24711f15b76fSChris Wilson static void i915_error_wake_up(struct drm_i915_private *dev_priv) 247217e1df07SDaniel Vetter { 247317e1df07SDaniel Vetter /* 247417e1df07SDaniel Vetter * Notify all waiters for GPU completion events that reset state has 247517e1df07SDaniel Vetter * been changed, and that they need to restart their wait after 247617e1df07SDaniel Vetter * checking for potential errors (and bail out to drop locks if there is 247717e1df07SDaniel Vetter * a gpu reset pending so that i915_error_work_func can acquire them). 247817e1df07SDaniel Vetter */ 247917e1df07SDaniel Vetter 248017e1df07SDaniel Vetter /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */ 24811f15b76fSChris Wilson wake_up_all(&dev_priv->gpu_error.wait_queue); 248217e1df07SDaniel Vetter 248317e1df07SDaniel Vetter /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */ 248417e1df07SDaniel Vetter wake_up_all(&dev_priv->pending_flip_queue); 248517e1df07SDaniel Vetter } 248617e1df07SDaniel Vetter 24878a905236SJesse Barnes /** 2488b8d24a06SMika Kuoppala * i915_reset_and_wakeup - do process context error handling work 248914bb2c11STvrtko Ursulin * @dev_priv: i915 device private 24908a905236SJesse Barnes * 24918a905236SJesse Barnes * Fire an error uevent so userspace can see that a hang or error 24928a905236SJesse Barnes * was detected. 24938a905236SJesse Barnes */ 2494c033666aSChris Wilson static void i915_reset_and_wakeup(struct drm_i915_private *dev_priv) 24958a905236SJesse Barnes { 249691c8a326SChris Wilson struct kobject *kobj = &dev_priv->drm.primary->kdev->kobj; 2497cce723edSBen Widawsky char *error_event[] = { I915_ERROR_UEVENT "=1", NULL }; 2498cce723edSBen Widawsky char *reset_event[] = { I915_RESET_UEVENT "=1", NULL }; 2499cce723edSBen Widawsky char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL }; 25008a905236SJesse Barnes 2501c033666aSChris Wilson kobject_uevent_env(kobj, KOBJ_CHANGE, error_event); 25028a905236SJesse Barnes 250344d98a61SZhao Yakui DRM_DEBUG_DRIVER("resetting chip\n"); 2504c033666aSChris Wilson kobject_uevent_env(kobj, KOBJ_CHANGE, reset_event); 25051f83fee0SDaniel Vetter 250617e1df07SDaniel Vetter /* 2507f454c694SImre Deak * In most cases it's guaranteed that we get here with an RPM 2508f454c694SImre Deak * reference held, for example because there is a pending GPU 2509f454c694SImre Deak * request that won't finish until the reset is done. This 2510f454c694SImre Deak * isn't the case at least when we get here by doing a 2511f454c694SImre Deak * simulated reset via debugs, so get an RPM reference. 2512f454c694SImre Deak */ 2513f454c694SImre Deak intel_runtime_pm_get(dev_priv); 2514c033666aSChris Wilson intel_prepare_reset(dev_priv); 25157514747dSVille Syrjälä 2516780f262aSChris Wilson do { 2517f454c694SImre Deak /* 251817e1df07SDaniel Vetter * All state reset _must_ be completed before we update the 251917e1df07SDaniel Vetter * reset counter, for otherwise waiters might miss the reset 252017e1df07SDaniel Vetter * pending state and not properly drop locks, resulting in 252117e1df07SDaniel Vetter * deadlocks with the reset work. 252217e1df07SDaniel Vetter */ 2523780f262aSChris Wilson if (mutex_trylock(&dev_priv->drm.struct_mutex)) { 2524780f262aSChris Wilson i915_reset(dev_priv); 2525221fe799SChris Wilson mutex_unlock(&dev_priv->drm.struct_mutex); 2526780f262aSChris Wilson } 2527780f262aSChris Wilson 2528780f262aSChris Wilson /* We need to wait for anyone holding the lock to wakeup */ 2529780f262aSChris Wilson } while (wait_on_bit_timeout(&dev_priv->gpu_error.flags, 2530780f262aSChris Wilson I915_RESET_IN_PROGRESS, 2531780f262aSChris Wilson TASK_UNINTERRUPTIBLE, 2532780f262aSChris Wilson HZ)); 2533f69061beSDaniel Vetter 2534c033666aSChris Wilson intel_finish_reset(dev_priv); 2535f454c694SImre Deak intel_runtime_pm_put(dev_priv); 2536f454c694SImre Deak 2537780f262aSChris Wilson if (!test_bit(I915_WEDGED, &dev_priv->gpu_error.flags)) 2538c033666aSChris Wilson kobject_uevent_env(kobj, 2539f69061beSDaniel Vetter KOBJ_CHANGE, reset_done_event); 25401f83fee0SDaniel Vetter 254117e1df07SDaniel Vetter /* 254217e1df07SDaniel Vetter * Note: The wake_up also serves as a memory barrier so that 25438af29b0cSChris Wilson * waiters see the updated value of the dev_priv->gpu_error. 254417e1df07SDaniel Vetter */ 25451f15b76fSChris Wilson wake_up_all(&dev_priv->gpu_error.reset_queue); 2546f316a42cSBen Gamari } 25478a905236SJesse Barnes 2548c033666aSChris Wilson static void i915_report_and_clear_eir(struct drm_i915_private *dev_priv) 2549c0e09200SDave Airlie { 2550bd9854f9SBen Widawsky uint32_t instdone[I915_NUM_INSTDONE_REG]; 255163eeaf38SJesse Barnes u32 eir = I915_READ(EIR); 2552050ee91fSBen Widawsky int pipe, i; 255363eeaf38SJesse Barnes 255435aed2e6SChris Wilson if (!eir) 255535aed2e6SChris Wilson return; 255663eeaf38SJesse Barnes 2557a70491ccSJoe Perches pr_err("render error detected, EIR: 0x%08x\n", eir); 25588a905236SJesse Barnes 2559c033666aSChris Wilson i915_get_extra_instdone(dev_priv, instdone); 2560bd9854f9SBen Widawsky 2561c033666aSChris Wilson if (IS_G4X(dev_priv)) { 25628a905236SJesse Barnes if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) { 25638a905236SJesse Barnes u32 ipeir = I915_READ(IPEIR_I965); 25648a905236SJesse Barnes 2565a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); 2566a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); 2567050ee91fSBen Widawsky for (i = 0; i < ARRAY_SIZE(instdone); i++) 2568050ee91fSBen Widawsky pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]); 2569a70491ccSJoe Perches pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); 2570a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); 25718a905236SJesse Barnes I915_WRITE(IPEIR_I965, ipeir); 25723143a2bfSChris Wilson POSTING_READ(IPEIR_I965); 25738a905236SJesse Barnes } 25748a905236SJesse Barnes if (eir & GM45_ERROR_PAGE_TABLE) { 25758a905236SJesse Barnes u32 pgtbl_err = I915_READ(PGTBL_ER); 2576a70491ccSJoe Perches pr_err("page table error\n"); 2577a70491ccSJoe Perches pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); 25788a905236SJesse Barnes I915_WRITE(PGTBL_ER, pgtbl_err); 25793143a2bfSChris Wilson POSTING_READ(PGTBL_ER); 25808a905236SJesse Barnes } 25818a905236SJesse Barnes } 25828a905236SJesse Barnes 2583c033666aSChris Wilson if (!IS_GEN2(dev_priv)) { 258463eeaf38SJesse Barnes if (eir & I915_ERROR_PAGE_TABLE) { 258563eeaf38SJesse Barnes u32 pgtbl_err = I915_READ(PGTBL_ER); 2586a70491ccSJoe Perches pr_err("page table error\n"); 2587a70491ccSJoe Perches pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); 258863eeaf38SJesse Barnes I915_WRITE(PGTBL_ER, pgtbl_err); 25893143a2bfSChris Wilson POSTING_READ(PGTBL_ER); 259063eeaf38SJesse Barnes } 25918a905236SJesse Barnes } 25928a905236SJesse Barnes 259363eeaf38SJesse Barnes if (eir & I915_ERROR_MEMORY_REFRESH) { 2594a70491ccSJoe Perches pr_err("memory refresh error:\n"); 2595055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 2596a70491ccSJoe Perches pr_err("pipe %c stat: 0x%08x\n", 25979db4a9c7SJesse Barnes pipe_name(pipe), I915_READ(PIPESTAT(pipe))); 259863eeaf38SJesse Barnes /* pipestat has already been acked */ 259963eeaf38SJesse Barnes } 260063eeaf38SJesse Barnes if (eir & I915_ERROR_INSTRUCTION) { 2601a70491ccSJoe Perches pr_err("instruction error\n"); 2602a70491ccSJoe Perches pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM)); 2603050ee91fSBen Widawsky for (i = 0; i < ARRAY_SIZE(instdone); i++) 2604050ee91fSBen Widawsky pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]); 2605c033666aSChris Wilson if (INTEL_GEN(dev_priv) < 4) { 260663eeaf38SJesse Barnes u32 ipeir = I915_READ(IPEIR); 260763eeaf38SJesse Barnes 2608a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR)); 2609a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR)); 2610a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD)); 261163eeaf38SJesse Barnes I915_WRITE(IPEIR, ipeir); 26123143a2bfSChris Wilson POSTING_READ(IPEIR); 261363eeaf38SJesse Barnes } else { 261463eeaf38SJesse Barnes u32 ipeir = I915_READ(IPEIR_I965); 261563eeaf38SJesse Barnes 2616a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); 2617a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); 2618a70491ccSJoe Perches pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); 2619a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); 262063eeaf38SJesse Barnes I915_WRITE(IPEIR_I965, ipeir); 26213143a2bfSChris Wilson POSTING_READ(IPEIR_I965); 262263eeaf38SJesse Barnes } 262363eeaf38SJesse Barnes } 262463eeaf38SJesse Barnes 262563eeaf38SJesse Barnes I915_WRITE(EIR, eir); 26263143a2bfSChris Wilson POSTING_READ(EIR); 262763eeaf38SJesse Barnes eir = I915_READ(EIR); 262863eeaf38SJesse Barnes if (eir) { 262963eeaf38SJesse Barnes /* 263063eeaf38SJesse Barnes * some errors might have become stuck, 263163eeaf38SJesse Barnes * mask them. 263263eeaf38SJesse Barnes */ 263363eeaf38SJesse Barnes DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir); 263463eeaf38SJesse Barnes I915_WRITE(EMR, I915_READ(EMR) | eir); 263563eeaf38SJesse Barnes I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 263663eeaf38SJesse Barnes } 263735aed2e6SChris Wilson } 263835aed2e6SChris Wilson 263935aed2e6SChris Wilson /** 2640b8d24a06SMika Kuoppala * i915_handle_error - handle a gpu error 264114bb2c11STvrtko Ursulin * @dev_priv: i915 device private 264214b730fcSarun.siluvery@linux.intel.com * @engine_mask: mask representing engines that are hung 2643aafd8581SJavier Martinez Canillas * Do some basic checking of register state at error time and 264435aed2e6SChris Wilson * dump it to the syslog. Also call i915_capture_error_state() to make 264535aed2e6SChris Wilson * sure we get a record and make it available in debugfs. Fire a uevent 264635aed2e6SChris Wilson * so userspace knows something bad happened (should trigger collection 264735aed2e6SChris Wilson * of a ring dump etc.). 264814bb2c11STvrtko Ursulin * @fmt: Error message format string 264935aed2e6SChris Wilson */ 2650c033666aSChris Wilson void i915_handle_error(struct drm_i915_private *dev_priv, 2651c033666aSChris Wilson u32 engine_mask, 265258174462SMika Kuoppala const char *fmt, ...) 265335aed2e6SChris Wilson { 265458174462SMika Kuoppala va_list args; 265558174462SMika Kuoppala char error_msg[80]; 265635aed2e6SChris Wilson 265758174462SMika Kuoppala va_start(args, fmt); 265858174462SMika Kuoppala vscnprintf(error_msg, sizeof(error_msg), fmt, args); 265958174462SMika Kuoppala va_end(args); 266058174462SMika Kuoppala 2661c033666aSChris Wilson i915_capture_error_state(dev_priv, engine_mask, error_msg); 2662c033666aSChris Wilson i915_report_and_clear_eir(dev_priv); 26638a905236SJesse Barnes 26648af29b0cSChris Wilson if (!engine_mask) 26658af29b0cSChris Wilson return; 26668af29b0cSChris Wilson 26678af29b0cSChris Wilson if (test_and_set_bit(I915_RESET_IN_PROGRESS, 26688af29b0cSChris Wilson &dev_priv->gpu_error.flags)) 26698af29b0cSChris Wilson return; 2670ba1234d1SBen Gamari 267111ed50ecSBen Gamari /* 2672b8d24a06SMika Kuoppala * Wakeup waiting processes so that the reset function 2673b8d24a06SMika Kuoppala * i915_reset_and_wakeup doesn't deadlock trying to grab 2674b8d24a06SMika Kuoppala * various locks. By bumping the reset counter first, the woken 267517e1df07SDaniel Vetter * processes will see a reset in progress and back off, 267617e1df07SDaniel Vetter * releasing their locks and then wait for the reset completion. 267717e1df07SDaniel Vetter * We must do this for _all_ gpu waiters that might hold locks 267817e1df07SDaniel Vetter * that the reset work needs to acquire. 267917e1df07SDaniel Vetter * 26808af29b0cSChris Wilson * Note: The wake_up also provides a memory barrier to ensure that the 26818af29b0cSChris Wilson * waiters see the updated value of the reset flags. 268211ed50ecSBen Gamari */ 26831f15b76fSChris Wilson i915_error_wake_up(dev_priv); 268411ed50ecSBen Gamari 2685c033666aSChris Wilson i915_reset_and_wakeup(dev_priv); 26868a905236SJesse Barnes } 26878a905236SJesse Barnes 268842f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 268942f52ef8SKeith Packard * we use as a pipe index 269042f52ef8SKeith Packard */ 269188e72717SThierry Reding static int i915_enable_vblank(struct drm_device *dev, unsigned int pipe) 26920a3e67a4SJesse Barnes { 2693fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 2694e9d21d7fSKeith Packard unsigned long irqflags; 269571e0ffa5SJesse Barnes 26961ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2697f796cf8fSJesse Barnes if (INTEL_INFO(dev)->gen >= 4) 26987c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 2699755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 27000a3e67a4SJesse Barnes else 27017c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 2702755e9019SImre Deak PIPE_VBLANK_INTERRUPT_STATUS); 27031ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 27048692d00eSChris Wilson 27050a3e67a4SJesse Barnes return 0; 27060a3e67a4SJesse Barnes } 27070a3e67a4SJesse Barnes 270888e72717SThierry Reding static int ironlake_enable_vblank(struct drm_device *dev, unsigned int pipe) 2709f796cf8fSJesse Barnes { 2710fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 2711f796cf8fSJesse Barnes unsigned long irqflags; 2712b518421fSPaulo Zanoni uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) : 271340da17c2SDaniel Vetter DE_PIPE_VBLANK(pipe); 2714f796cf8fSJesse Barnes 2715f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2716fbdedaeaSVille Syrjälä ilk_enable_display_irq(dev_priv, bit); 2717b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2718b1f14ad0SJesse Barnes 2719b1f14ad0SJesse Barnes return 0; 2720b1f14ad0SJesse Barnes } 2721b1f14ad0SJesse Barnes 272288e72717SThierry Reding static int valleyview_enable_vblank(struct drm_device *dev, unsigned int pipe) 27237e231dbeSJesse Barnes { 2724fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 27257e231dbeSJesse Barnes unsigned long irqflags; 27267e231dbeSJesse Barnes 27277e231dbeSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 272831acc7f5SJesse Barnes i915_enable_pipestat(dev_priv, pipe, 2729755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 27307e231dbeSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 27317e231dbeSJesse Barnes 27327e231dbeSJesse Barnes return 0; 27337e231dbeSJesse Barnes } 27347e231dbeSJesse Barnes 273588e72717SThierry Reding static int gen8_enable_vblank(struct drm_device *dev, unsigned int pipe) 2736abd58f01SBen Widawsky { 2737fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 2738abd58f01SBen Widawsky unsigned long irqflags; 2739abd58f01SBen Widawsky 2740abd58f01SBen Widawsky spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2741013d3752SVille Syrjälä bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK); 2742abd58f01SBen Widawsky spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2743013d3752SVille Syrjälä 2744abd58f01SBen Widawsky return 0; 2745abd58f01SBen Widawsky } 2746abd58f01SBen Widawsky 274742f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 274842f52ef8SKeith Packard * we use as a pipe index 274942f52ef8SKeith Packard */ 275088e72717SThierry Reding static void i915_disable_vblank(struct drm_device *dev, unsigned int pipe) 27510a3e67a4SJesse Barnes { 2752fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 2753e9d21d7fSKeith Packard unsigned long irqflags; 27540a3e67a4SJesse Barnes 27551ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 27567c463586SKeith Packard i915_disable_pipestat(dev_priv, pipe, 2757755e9019SImre Deak PIPE_VBLANK_INTERRUPT_STATUS | 2758755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 27591ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 27600a3e67a4SJesse Barnes } 27610a3e67a4SJesse Barnes 276288e72717SThierry Reding static void ironlake_disable_vblank(struct drm_device *dev, unsigned int pipe) 2763f796cf8fSJesse Barnes { 2764fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 2765f796cf8fSJesse Barnes unsigned long irqflags; 2766b518421fSPaulo Zanoni uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) : 276740da17c2SDaniel Vetter DE_PIPE_VBLANK(pipe); 2768f796cf8fSJesse Barnes 2769f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2770fbdedaeaSVille Syrjälä ilk_disable_display_irq(dev_priv, bit); 2771b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2772b1f14ad0SJesse Barnes } 2773b1f14ad0SJesse Barnes 277488e72717SThierry Reding static void valleyview_disable_vblank(struct drm_device *dev, unsigned int pipe) 27757e231dbeSJesse Barnes { 2776fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 27777e231dbeSJesse Barnes unsigned long irqflags; 27787e231dbeSJesse Barnes 27797e231dbeSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 278031acc7f5SJesse Barnes i915_disable_pipestat(dev_priv, pipe, 2781755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 27827e231dbeSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 27837e231dbeSJesse Barnes } 27847e231dbeSJesse Barnes 278588e72717SThierry Reding static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe) 2786abd58f01SBen Widawsky { 2787fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 2788abd58f01SBen Widawsky unsigned long irqflags; 2789abd58f01SBen Widawsky 2790abd58f01SBen Widawsky spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2791013d3752SVille Syrjälä bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK); 2792abd58f01SBen Widawsky spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2793abd58f01SBen Widawsky } 2794abd58f01SBen Widawsky 27959107e9d2SChris Wilson static bool 279631bb59ccSChris Wilson ipehr_is_semaphore_wait(struct intel_engine_cs *engine, u32 ipehr) 2797a028c4b0SDaniel Vetter { 279831bb59ccSChris Wilson if (INTEL_GEN(engine->i915) >= 8) { 2799a6cdb93aSRodrigo Vivi return (ipehr >> 23) == 0x1c; 2800a028c4b0SDaniel Vetter } else { 2801a028c4b0SDaniel Vetter ipehr &= ~MI_SEMAPHORE_SYNC_MASK; 2802a028c4b0SDaniel Vetter return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | 2803a028c4b0SDaniel Vetter MI_SEMAPHORE_REGISTER); 2804a028c4b0SDaniel Vetter } 2805a028c4b0SDaniel Vetter } 2806a028c4b0SDaniel Vetter 2807a4872ba6SOscar Mateo static struct intel_engine_cs * 28080bc40be8STvrtko Ursulin semaphore_wait_to_signaller_ring(struct intel_engine_cs *engine, u32 ipehr, 28090bc40be8STvrtko Ursulin u64 offset) 2810921d42eaSDaniel Vetter { 2811c033666aSChris Wilson struct drm_i915_private *dev_priv = engine->i915; 2812a4872ba6SOscar Mateo struct intel_engine_cs *signaller; 2813921d42eaSDaniel Vetter 2814c033666aSChris Wilson if (INTEL_GEN(dev_priv) >= 8) { 2815b4ac5afcSDave Gordon for_each_engine(signaller, dev_priv) { 28160bc40be8STvrtko Ursulin if (engine == signaller) 2817a6cdb93aSRodrigo Vivi continue; 2818a6cdb93aSRodrigo Vivi 28190bc40be8STvrtko Ursulin if (offset == signaller->semaphore.signal_ggtt[engine->id]) 2820a6cdb93aSRodrigo Vivi return signaller; 2821a6cdb93aSRodrigo Vivi } 2822921d42eaSDaniel Vetter } else { 2823921d42eaSDaniel Vetter u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK; 2824921d42eaSDaniel Vetter 2825b4ac5afcSDave Gordon for_each_engine(signaller, dev_priv) { 28260bc40be8STvrtko Ursulin if(engine == signaller) 2827921d42eaSDaniel Vetter continue; 2828921d42eaSDaniel Vetter 28290bc40be8STvrtko Ursulin if (sync_bits == signaller->semaphore.mbox.wait[engine->id]) 2830921d42eaSDaniel Vetter return signaller; 2831921d42eaSDaniel Vetter } 2832921d42eaSDaniel Vetter } 2833921d42eaSDaniel Vetter 2834*80b5bdbdSChris Wilson DRM_DEBUG_DRIVER("No signaller ring found for ring %i, ipehr 0x%08x, offset 0x%016llx\n", 28350bc40be8STvrtko Ursulin engine->id, ipehr, offset); 2836921d42eaSDaniel Vetter 2837*80b5bdbdSChris Wilson return ERR_PTR(-ENODEV); 2838921d42eaSDaniel Vetter } 2839921d42eaSDaniel Vetter 2840a4872ba6SOscar Mateo static struct intel_engine_cs * 28410bc40be8STvrtko Ursulin semaphore_waits_for(struct intel_engine_cs *engine, u32 *seqno) 2842a24a11e6SChris Wilson { 2843c033666aSChris Wilson struct drm_i915_private *dev_priv = engine->i915; 2844406ea8d2SChris Wilson void __iomem *vaddr; 284588fe429dSDaniel Vetter u32 cmd, ipehr, head; 2846a6cdb93aSRodrigo Vivi u64 offset = 0; 2847a6cdb93aSRodrigo Vivi int i, backwards; 2848a24a11e6SChris Wilson 2849381e8ae3STomas Elf /* 2850381e8ae3STomas Elf * This function does not support execlist mode - any attempt to 2851381e8ae3STomas Elf * proceed further into this function will result in a kernel panic 2852381e8ae3STomas Elf * when dereferencing ring->buffer, which is not set up in execlist 2853381e8ae3STomas Elf * mode. 2854381e8ae3STomas Elf * 2855381e8ae3STomas Elf * The correct way of doing it would be to derive the currently 2856381e8ae3STomas Elf * executing ring buffer from the current context, which is derived 2857381e8ae3STomas Elf * from the currently running request. Unfortunately, to get the 2858381e8ae3STomas Elf * current request we would have to grab the struct_mutex before doing 2859381e8ae3STomas Elf * anything else, which would be ill-advised since some other thread 2860381e8ae3STomas Elf * might have grabbed it already and managed to hang itself, causing 2861381e8ae3STomas Elf * the hang checker to deadlock. 2862381e8ae3STomas Elf * 2863381e8ae3STomas Elf * Therefore, this function does not support execlist mode in its 2864381e8ae3STomas Elf * current form. Just return NULL and move on. 2865381e8ae3STomas Elf */ 28660bc40be8STvrtko Ursulin if (engine->buffer == NULL) 2867381e8ae3STomas Elf return NULL; 2868381e8ae3STomas Elf 28690bc40be8STvrtko Ursulin ipehr = I915_READ(RING_IPEHR(engine->mmio_base)); 287031bb59ccSChris Wilson if (!ipehr_is_semaphore_wait(engine, ipehr)) 28716274f212SChris Wilson return NULL; 2872a24a11e6SChris Wilson 287388fe429dSDaniel Vetter /* 287488fe429dSDaniel Vetter * HEAD is likely pointing to the dword after the actual command, 287588fe429dSDaniel Vetter * so scan backwards until we find the MBOX. But limit it to just 3 2876a6cdb93aSRodrigo Vivi * or 4 dwords depending on the semaphore wait command size. 2877a6cdb93aSRodrigo Vivi * Note that we don't care about ACTHD here since that might 287888fe429dSDaniel Vetter * point at at batch, and semaphores are always emitted into the 287988fe429dSDaniel Vetter * ringbuffer itself. 2880a24a11e6SChris Wilson */ 28810bc40be8STvrtko Ursulin head = I915_READ_HEAD(engine) & HEAD_ADDR; 2882c033666aSChris Wilson backwards = (INTEL_GEN(dev_priv) >= 8) ? 5 : 4; 2883f2f0ed71SChris Wilson vaddr = (void __iomem *)engine->buffer->vaddr; 288488fe429dSDaniel Vetter 2885a6cdb93aSRodrigo Vivi for (i = backwards; i; --i) { 288688fe429dSDaniel Vetter /* 288788fe429dSDaniel Vetter * Be paranoid and presume the hw has gone off into the wild - 288888fe429dSDaniel Vetter * our ring is smaller than what the hardware (and hence 288988fe429dSDaniel Vetter * HEAD_ADDR) allows. Also handles wrap-around. 289088fe429dSDaniel Vetter */ 28910bc40be8STvrtko Ursulin head &= engine->buffer->size - 1; 289288fe429dSDaniel Vetter 289388fe429dSDaniel Vetter /* This here seems to blow up */ 2894406ea8d2SChris Wilson cmd = ioread32(vaddr + head); 2895a24a11e6SChris Wilson if (cmd == ipehr) 2896a24a11e6SChris Wilson break; 2897a24a11e6SChris Wilson 289888fe429dSDaniel Vetter head -= 4; 289988fe429dSDaniel Vetter } 2900a24a11e6SChris Wilson 290188fe429dSDaniel Vetter if (!i) 290288fe429dSDaniel Vetter return NULL; 290388fe429dSDaniel Vetter 2904406ea8d2SChris Wilson *seqno = ioread32(vaddr + head + 4) + 1; 2905c033666aSChris Wilson if (INTEL_GEN(dev_priv) >= 8) { 2906406ea8d2SChris Wilson offset = ioread32(vaddr + head + 12); 2907a6cdb93aSRodrigo Vivi offset <<= 32; 2908406ea8d2SChris Wilson offset |= ioread32(vaddr + head + 8); 2909a6cdb93aSRodrigo Vivi } 29100bc40be8STvrtko Ursulin return semaphore_wait_to_signaller_ring(engine, ipehr, offset); 2911a24a11e6SChris Wilson } 2912a24a11e6SChris Wilson 29130bc40be8STvrtko Ursulin static int semaphore_passed(struct intel_engine_cs *engine) 29146274f212SChris Wilson { 2915c033666aSChris Wilson struct drm_i915_private *dev_priv = engine->i915; 2916a4872ba6SOscar Mateo struct intel_engine_cs *signaller; 2917a0d036b0SChris Wilson u32 seqno; 29186274f212SChris Wilson 29190bc40be8STvrtko Ursulin engine->hangcheck.deadlock++; 29206274f212SChris Wilson 29210bc40be8STvrtko Ursulin signaller = semaphore_waits_for(engine, &seqno); 29224be17381SChris Wilson if (signaller == NULL) 29234be17381SChris Wilson return -1; 29244be17381SChris Wilson 2925*80b5bdbdSChris Wilson if (IS_ERR(signaller)) 2926*80b5bdbdSChris Wilson return 0; 2927*80b5bdbdSChris Wilson 29284be17381SChris Wilson /* Prevent pathological recursion due to driver bugs */ 2929666796daSTvrtko Ursulin if (signaller->hangcheck.deadlock >= I915_NUM_ENGINES) 29306274f212SChris Wilson return -1; 29316274f212SChris Wilson 29321b7744e7SChris Wilson if (i915_seqno_passed(intel_engine_get_seqno(signaller), seqno)) 29334be17381SChris Wilson return 1; 29344be17381SChris Wilson 2935a0d036b0SChris Wilson /* cursory check for an unkickable deadlock */ 2936a0d036b0SChris Wilson if (I915_READ_CTL(signaller) & RING_WAIT_SEMAPHORE && 2937a0d036b0SChris Wilson semaphore_passed(signaller) < 0) 29384be17381SChris Wilson return -1; 29394be17381SChris Wilson 29404be17381SChris Wilson return 0; 29416274f212SChris Wilson } 29426274f212SChris Wilson 29436274f212SChris Wilson static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv) 29446274f212SChris Wilson { 2945e2f80391STvrtko Ursulin struct intel_engine_cs *engine; 29466274f212SChris Wilson 2947b4ac5afcSDave Gordon for_each_engine(engine, dev_priv) 2948e2f80391STvrtko Ursulin engine->hangcheck.deadlock = 0; 29496274f212SChris Wilson } 29506274f212SChris Wilson 29510bc40be8STvrtko Ursulin static bool subunits_stuck(struct intel_engine_cs *engine) 29521ec14ad3SChris Wilson { 295361642ff0SMika Kuoppala u32 instdone[I915_NUM_INSTDONE_REG]; 295461642ff0SMika Kuoppala bool stuck; 295561642ff0SMika Kuoppala int i; 29569107e9d2SChris Wilson 29570bc40be8STvrtko Ursulin if (engine->id != RCS) 295861642ff0SMika Kuoppala return true; 295961642ff0SMika Kuoppala 2960c033666aSChris Wilson i915_get_extra_instdone(engine->i915, instdone); 296161642ff0SMika Kuoppala 296261642ff0SMika Kuoppala /* There might be unstable subunit states even when 296361642ff0SMika Kuoppala * actual head is not moving. Filter out the unstable ones by 296461642ff0SMika Kuoppala * accumulating the undone -> done transitions and only 296561642ff0SMika Kuoppala * consider those as progress. 296661642ff0SMika Kuoppala */ 296761642ff0SMika Kuoppala stuck = true; 296861642ff0SMika Kuoppala for (i = 0; i < I915_NUM_INSTDONE_REG; i++) { 29690bc40be8STvrtko Ursulin const u32 tmp = instdone[i] | engine->hangcheck.instdone[i]; 297061642ff0SMika Kuoppala 29710bc40be8STvrtko Ursulin if (tmp != engine->hangcheck.instdone[i]) 297261642ff0SMika Kuoppala stuck = false; 297361642ff0SMika Kuoppala 29740bc40be8STvrtko Ursulin engine->hangcheck.instdone[i] |= tmp; 297561642ff0SMika Kuoppala } 297661642ff0SMika Kuoppala 297761642ff0SMika Kuoppala return stuck; 297861642ff0SMika Kuoppala } 297961642ff0SMika Kuoppala 29807e37f889SChris Wilson static enum intel_engine_hangcheck_action 29810bc40be8STvrtko Ursulin head_stuck(struct intel_engine_cs *engine, u64 acthd) 298261642ff0SMika Kuoppala { 29830bc40be8STvrtko Ursulin if (acthd != engine->hangcheck.acthd) { 298461642ff0SMika Kuoppala 298561642ff0SMika Kuoppala /* Clear subunit states on head movement */ 29860bc40be8STvrtko Ursulin memset(engine->hangcheck.instdone, 0, 29870bc40be8STvrtko Ursulin sizeof(engine->hangcheck.instdone)); 298861642ff0SMika Kuoppala 2989f2f4d82fSJani Nikula return HANGCHECK_ACTIVE; 2990f260fe7bSMika Kuoppala } 2991f260fe7bSMika Kuoppala 29920bc40be8STvrtko Ursulin if (!subunits_stuck(engine)) 299361642ff0SMika Kuoppala return HANGCHECK_ACTIVE; 299461642ff0SMika Kuoppala 299561642ff0SMika Kuoppala return HANGCHECK_HUNG; 299661642ff0SMika Kuoppala } 299761642ff0SMika Kuoppala 29987e37f889SChris Wilson static enum intel_engine_hangcheck_action 29997e37f889SChris Wilson engine_stuck(struct intel_engine_cs *engine, u64 acthd) 300061642ff0SMika Kuoppala { 3001c033666aSChris Wilson struct drm_i915_private *dev_priv = engine->i915; 30027e37f889SChris Wilson enum intel_engine_hangcheck_action ha; 300361642ff0SMika Kuoppala u32 tmp; 300461642ff0SMika Kuoppala 30050bc40be8STvrtko Ursulin ha = head_stuck(engine, acthd); 300661642ff0SMika Kuoppala if (ha != HANGCHECK_HUNG) 300761642ff0SMika Kuoppala return ha; 300861642ff0SMika Kuoppala 3009c033666aSChris Wilson if (IS_GEN2(dev_priv)) 3010f2f4d82fSJani Nikula return HANGCHECK_HUNG; 30119107e9d2SChris Wilson 30129107e9d2SChris Wilson /* Is the chip hanging on a WAIT_FOR_EVENT? 30139107e9d2SChris Wilson * If so we can simply poke the RB_WAIT bit 30149107e9d2SChris Wilson * and break the hang. This should work on 30159107e9d2SChris Wilson * all but the second generation chipsets. 30169107e9d2SChris Wilson */ 30170bc40be8STvrtko Ursulin tmp = I915_READ_CTL(engine); 30181ec14ad3SChris Wilson if (tmp & RING_WAIT) { 3019c033666aSChris Wilson i915_handle_error(dev_priv, 0, 302058174462SMika Kuoppala "Kicking stuck wait on %s", 30210bc40be8STvrtko Ursulin engine->name); 30220bc40be8STvrtko Ursulin I915_WRITE_CTL(engine, tmp); 3023f2f4d82fSJani Nikula return HANGCHECK_KICK; 30241ec14ad3SChris Wilson } 3025a24a11e6SChris Wilson 3026c033666aSChris Wilson if (INTEL_GEN(dev_priv) >= 6 && tmp & RING_WAIT_SEMAPHORE) { 30270bc40be8STvrtko Ursulin switch (semaphore_passed(engine)) { 30286274f212SChris Wilson default: 3029f2f4d82fSJani Nikula return HANGCHECK_HUNG; 30306274f212SChris Wilson case 1: 3031c033666aSChris Wilson i915_handle_error(dev_priv, 0, 303258174462SMika Kuoppala "Kicking stuck semaphore on %s", 30330bc40be8STvrtko Ursulin engine->name); 30340bc40be8STvrtko Ursulin I915_WRITE_CTL(engine, tmp); 3035f2f4d82fSJani Nikula return HANGCHECK_KICK; 30366274f212SChris Wilson case 0: 3037f2f4d82fSJani Nikula return HANGCHECK_WAIT; 30386274f212SChris Wilson } 30399107e9d2SChris Wilson } 30409107e9d2SChris Wilson 3041f2f4d82fSJani Nikula return HANGCHECK_HUNG; 3042a24a11e6SChris Wilson } 3043d1e61e7fSChris Wilson 3044737b1506SChris Wilson /* 3045f65d9421SBen Gamari * This is called when the chip hasn't reported back with completed 304605407ff8SMika Kuoppala * batchbuffers in a long time. We keep track per ring seqno progress and 304705407ff8SMika Kuoppala * if there are no progress, hangcheck score for that ring is increased. 304805407ff8SMika Kuoppala * Further, acthd is inspected to see if the ring is stuck. On stuck case 304905407ff8SMika Kuoppala * we kick the ring. If we see no progress on three subsequent calls 305005407ff8SMika Kuoppala * we assume chip is wedged and try to fix it by resetting the chip. 3051f65d9421SBen Gamari */ 3052737b1506SChris Wilson static void i915_hangcheck_elapsed(struct work_struct *work) 3053f65d9421SBen Gamari { 3054737b1506SChris Wilson struct drm_i915_private *dev_priv = 3055737b1506SChris Wilson container_of(work, typeof(*dev_priv), 3056737b1506SChris Wilson gpu_error.hangcheck_work.work); 3057e2f80391STvrtko Ursulin struct intel_engine_cs *engine; 30582b284288SChris Wilson unsigned int hung = 0, stuck = 0; 30592b284288SChris Wilson int busy_count = 0; 30609107e9d2SChris Wilson #define BUSY 1 30619107e9d2SChris Wilson #define KICK 5 30629107e9d2SChris Wilson #define HUNG 20 306324a65e62SMika Kuoppala #define ACTIVE_DECAY 15 3064893eead0SChris Wilson 3065d330a953SJani Nikula if (!i915.enable_hangcheck) 30663e0dc6b0SBen Widawsky return; 30673e0dc6b0SBen Widawsky 3068b1379d49SChris Wilson if (!READ_ONCE(dev_priv->gt.awake)) 306967d97da3SChris Wilson return; 30701f814dacSImre Deak 307175714940SMika Kuoppala /* As enabling the GPU requires fairly extensive mmio access, 307275714940SMika Kuoppala * periodically arm the mmio checker to see if we are triggering 307375714940SMika Kuoppala * any invalid access. 307475714940SMika Kuoppala */ 307575714940SMika Kuoppala intel_uncore_arm_unclaimed_mmio_detection(dev_priv); 307675714940SMika Kuoppala 30772b284288SChris Wilson for_each_engine(engine, dev_priv) { 3078688e6c72SChris Wilson bool busy = intel_engine_has_waiter(engine); 307950877445SChris Wilson u64 acthd; 308050877445SChris Wilson u32 seqno; 308134730fedSChris Wilson u32 submit; 3082b4519513SChris Wilson 30836274f212SChris Wilson semaphore_clear_deadlocks(dev_priv); 30846274f212SChris Wilson 3085c04e0f3bSChris Wilson /* We don't strictly need an irq-barrier here, as we are not 3086c04e0f3bSChris Wilson * serving an interrupt request, be paranoid in case the 3087c04e0f3bSChris Wilson * barrier has side-effects (such as preventing a broken 3088c04e0f3bSChris Wilson * cacheline snoop) and so be sure that we can see the seqno 3089c04e0f3bSChris Wilson * advance. If the seqno should stick, due to a stale 3090c04e0f3bSChris Wilson * cacheline, we would erroneously declare the GPU hung. 3091c04e0f3bSChris Wilson */ 3092c04e0f3bSChris Wilson if (engine->irq_seqno_barrier) 3093c04e0f3bSChris Wilson engine->irq_seqno_barrier(engine); 3094c04e0f3bSChris Wilson 30957e37f889SChris Wilson acthd = intel_engine_get_active_head(engine); 30961b7744e7SChris Wilson seqno = intel_engine_get_seqno(engine); 309734730fedSChris Wilson submit = READ_ONCE(engine->last_submitted_seqno); 309805407ff8SMika Kuoppala 3099e2f80391STvrtko Ursulin if (engine->hangcheck.seqno == seqno) { 310034730fedSChris Wilson if (i915_seqno_passed(seqno, submit)) { 3101e2f80391STvrtko Ursulin engine->hangcheck.action = HANGCHECK_IDLE; 310205535726SChris Wilson if (busy) { 3103094f9a54SChris Wilson /* Safeguard against driver failure */ 3104e2f80391STvrtko Ursulin engine->hangcheck.score += BUSY; 310505535726SChris Wilson } 310605407ff8SMika Kuoppala } else { 31076274f212SChris Wilson /* We always increment the hangcheck score 31089930ca1aSChris Wilson * if the engine is busy and still processing 31096274f212SChris Wilson * the same request, so that no single request 31106274f212SChris Wilson * can run indefinitely (such as a chain of 31116274f212SChris Wilson * batches). The only time we do not increment 31126274f212SChris Wilson * the hangcheck score on this ring, if this 31139930ca1aSChris Wilson * engine is in a legitimate wait for another 31149930ca1aSChris Wilson * engine. In that case the waiting engine is a 31156274f212SChris Wilson * victim and we want to be sure we catch the 31166274f212SChris Wilson * right culprit. Then every time we do kick 31176274f212SChris Wilson * the ring, add a small increment to the 31186274f212SChris Wilson * score so that we can catch a batch that is 31196274f212SChris Wilson * being repeatedly kicked and so responsible 31206274f212SChris Wilson * for stalling the machine. 31219107e9d2SChris Wilson */ 31227e37f889SChris Wilson engine->hangcheck.action = 31237e37f889SChris Wilson engine_stuck(engine, acthd); 3124ad8beaeaSMika Kuoppala 3125e2f80391STvrtko Ursulin switch (engine->hangcheck.action) { 3126da661464SMika Kuoppala case HANGCHECK_IDLE: 3127f2f4d82fSJani Nikula case HANGCHECK_WAIT: 3128f260fe7bSMika Kuoppala break; 312924a65e62SMika Kuoppala case HANGCHECK_ACTIVE: 3130e2f80391STvrtko Ursulin engine->hangcheck.score += BUSY; 31316274f212SChris Wilson break; 3132f2f4d82fSJani Nikula case HANGCHECK_KICK: 3133e2f80391STvrtko Ursulin engine->hangcheck.score += KICK; 31346274f212SChris Wilson break; 3135f2f4d82fSJani Nikula case HANGCHECK_HUNG: 3136e2f80391STvrtko Ursulin engine->hangcheck.score += HUNG; 31376274f212SChris Wilson break; 31386274f212SChris Wilson } 313905407ff8SMika Kuoppala } 31402b284288SChris Wilson 31412b284288SChris Wilson if (engine->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) { 31422b284288SChris Wilson hung |= intel_engine_flag(engine); 31432b284288SChris Wilson if (engine->hangcheck.action != HANGCHECK_HUNG) 31442b284288SChris Wilson stuck |= intel_engine_flag(engine); 31452b284288SChris Wilson } 31469107e9d2SChris Wilson } else { 3147e2f80391STvrtko Ursulin engine->hangcheck.action = HANGCHECK_ACTIVE; 3148da661464SMika Kuoppala 31499107e9d2SChris Wilson /* Gradually reduce the count so that we catch DoS 31509107e9d2SChris Wilson * attempts across multiple batches. 31519107e9d2SChris Wilson */ 3152e2f80391STvrtko Ursulin if (engine->hangcheck.score > 0) 3153e2f80391STvrtko Ursulin engine->hangcheck.score -= ACTIVE_DECAY; 3154e2f80391STvrtko Ursulin if (engine->hangcheck.score < 0) 3155e2f80391STvrtko Ursulin engine->hangcheck.score = 0; 3156f260fe7bSMika Kuoppala 315761642ff0SMika Kuoppala /* Clear head and subunit states on seqno movement */ 315812471ba8SChris Wilson acthd = 0; 315961642ff0SMika Kuoppala 3160e2f80391STvrtko Ursulin memset(engine->hangcheck.instdone, 0, 3161e2f80391STvrtko Ursulin sizeof(engine->hangcheck.instdone)); 3162cbb465e7SChris Wilson } 3163f65d9421SBen Gamari 3164e2f80391STvrtko Ursulin engine->hangcheck.seqno = seqno; 3165e2f80391STvrtko Ursulin engine->hangcheck.acthd = acthd; 31669107e9d2SChris Wilson busy_count += busy; 316705407ff8SMika Kuoppala } 316805407ff8SMika Kuoppala 31692b284288SChris Wilson if (hung) { 31702b284288SChris Wilson char msg[80]; 3171bafb0fceSChris Wilson unsigned int tmp; 31722b284288SChris Wilson int len; 317305407ff8SMika Kuoppala 31742b284288SChris Wilson /* If some rings hung but others were still busy, only 31752b284288SChris Wilson * blame the hanging rings in the synopsis. 31762b284288SChris Wilson */ 31772b284288SChris Wilson if (stuck != hung) 31782b284288SChris Wilson hung &= ~stuck; 31792b284288SChris Wilson len = scnprintf(msg, sizeof(msg), 31802b284288SChris Wilson "%s on ", stuck == hung ? "No progress" : "Hang"); 3181bafb0fceSChris Wilson for_each_engine_masked(engine, dev_priv, hung, tmp) 31822b284288SChris Wilson len += scnprintf(msg + len, sizeof(msg) - len, 31832b284288SChris Wilson "%s, ", engine->name); 31842b284288SChris Wilson msg[len-2] = '\0'; 31852b284288SChris Wilson 31862b284288SChris Wilson return i915_handle_error(dev_priv, hung, msg); 31872b284288SChris Wilson } 318805407ff8SMika Kuoppala 318905535726SChris Wilson /* Reset timer in case GPU hangs without another request being added */ 319005407ff8SMika Kuoppala if (busy_count) 3191c033666aSChris Wilson i915_queue_hangcheck(dev_priv); 319210cd45b6SMika Kuoppala } 319310cd45b6SMika Kuoppala 31941c69eb42SPaulo Zanoni static void ibx_irq_reset(struct drm_device *dev) 319591738a95SPaulo Zanoni { 3196fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 319791738a95SPaulo Zanoni 319891738a95SPaulo Zanoni if (HAS_PCH_NOP(dev)) 319991738a95SPaulo Zanoni return; 320091738a95SPaulo Zanoni 3201f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(SDE); 3202105b122eSPaulo Zanoni 3203105b122eSPaulo Zanoni if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev)) 3204105b122eSPaulo Zanoni I915_WRITE(SERR_INT, 0xffffffff); 3205622364b6SPaulo Zanoni } 3206105b122eSPaulo Zanoni 320791738a95SPaulo Zanoni /* 3208622364b6SPaulo Zanoni * SDEIER is also touched by the interrupt handler to work around missed PCH 3209622364b6SPaulo Zanoni * interrupts. Hence we can't update it after the interrupt handler is enabled - 3210622364b6SPaulo Zanoni * instead we unconditionally enable all PCH interrupt sources here, but then 3211622364b6SPaulo Zanoni * only unmask them as needed with SDEIMR. 3212622364b6SPaulo Zanoni * 3213622364b6SPaulo Zanoni * This function needs to be called before interrupts are enabled. 321491738a95SPaulo Zanoni */ 3215622364b6SPaulo Zanoni static void ibx_irq_pre_postinstall(struct drm_device *dev) 3216622364b6SPaulo Zanoni { 3217fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 3218622364b6SPaulo Zanoni 3219622364b6SPaulo Zanoni if (HAS_PCH_NOP(dev)) 3220622364b6SPaulo Zanoni return; 3221622364b6SPaulo Zanoni 3222622364b6SPaulo Zanoni WARN_ON(I915_READ(SDEIER) != 0); 322391738a95SPaulo Zanoni I915_WRITE(SDEIER, 0xffffffff); 322491738a95SPaulo Zanoni POSTING_READ(SDEIER); 322591738a95SPaulo Zanoni } 322691738a95SPaulo Zanoni 32277c4d664eSPaulo Zanoni static void gen5_gt_irq_reset(struct drm_device *dev) 3228d18ea1b5SDaniel Vetter { 3229fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 3230d18ea1b5SDaniel Vetter 3231f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(GT); 3232a9d356a6SPaulo Zanoni if (INTEL_INFO(dev)->gen >= 6) 3233f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(GEN6_PM); 3234d18ea1b5SDaniel Vetter } 3235d18ea1b5SDaniel Vetter 323670591a41SVille Syrjälä static void vlv_display_irq_reset(struct drm_i915_private *dev_priv) 323770591a41SVille Syrjälä { 323870591a41SVille Syrjälä enum pipe pipe; 323970591a41SVille Syrjälä 324071b8b41dSVille Syrjälä if (IS_CHERRYVIEW(dev_priv)) 324171b8b41dSVille Syrjälä I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV); 324271b8b41dSVille Syrjälä else 324371b8b41dSVille Syrjälä I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK); 324471b8b41dSVille Syrjälä 3245ad22d106SVille Syrjälä i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0); 324670591a41SVille Syrjälä I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 324770591a41SVille Syrjälä 3248ad22d106SVille Syrjälä for_each_pipe(dev_priv, pipe) { 3249ad22d106SVille Syrjälä I915_WRITE(PIPESTAT(pipe), 3250ad22d106SVille Syrjälä PIPE_FIFO_UNDERRUN_STATUS | 3251ad22d106SVille Syrjälä PIPESTAT_INT_STATUS_MASK); 3252ad22d106SVille Syrjälä dev_priv->pipestat_irq_mask[pipe] = 0; 3253ad22d106SVille Syrjälä } 325470591a41SVille Syrjälä 325570591a41SVille Syrjälä GEN5_IRQ_RESET(VLV_); 3256ad22d106SVille Syrjälä dev_priv->irq_mask = ~0; 325770591a41SVille Syrjälä } 325870591a41SVille Syrjälä 32598bb61306SVille Syrjälä static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv) 32608bb61306SVille Syrjälä { 32618bb61306SVille Syrjälä u32 pipestat_mask; 32629ab981f2SVille Syrjälä u32 enable_mask; 32638bb61306SVille Syrjälä enum pipe pipe; 32648bb61306SVille Syrjälä 32658bb61306SVille Syrjälä pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV | 32668bb61306SVille Syrjälä PIPE_CRC_DONE_INTERRUPT_STATUS; 32678bb61306SVille Syrjälä 32688bb61306SVille Syrjälä i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS); 32698bb61306SVille Syrjälä for_each_pipe(dev_priv, pipe) 32708bb61306SVille Syrjälä i915_enable_pipestat(dev_priv, pipe, pipestat_mask); 32718bb61306SVille Syrjälä 32729ab981f2SVille Syrjälä enable_mask = I915_DISPLAY_PORT_INTERRUPT | 32738bb61306SVille Syrjälä I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 32748bb61306SVille Syrjälä I915_DISPLAY_PIPE_B_EVENT_INTERRUPT; 32758bb61306SVille Syrjälä if (IS_CHERRYVIEW(dev_priv)) 32769ab981f2SVille Syrjälä enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT; 32776b7eafc1SVille Syrjälä 32786b7eafc1SVille Syrjälä WARN_ON(dev_priv->irq_mask != ~0); 32796b7eafc1SVille Syrjälä 32809ab981f2SVille Syrjälä dev_priv->irq_mask = ~enable_mask; 32818bb61306SVille Syrjälä 32829ab981f2SVille Syrjälä GEN5_IRQ_INIT(VLV_, dev_priv->irq_mask, enable_mask); 32838bb61306SVille Syrjälä } 32848bb61306SVille Syrjälä 32858bb61306SVille Syrjälä /* drm_dma.h hooks 32868bb61306SVille Syrjälä */ 32878bb61306SVille Syrjälä static void ironlake_irq_reset(struct drm_device *dev) 32888bb61306SVille Syrjälä { 3289fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 32908bb61306SVille Syrjälä 32918bb61306SVille Syrjälä I915_WRITE(HWSTAM, 0xffffffff); 32928bb61306SVille Syrjälä 32938bb61306SVille Syrjälä GEN5_IRQ_RESET(DE); 32948bb61306SVille Syrjälä if (IS_GEN7(dev)) 32958bb61306SVille Syrjälä I915_WRITE(GEN7_ERR_INT, 0xffffffff); 32968bb61306SVille Syrjälä 32978bb61306SVille Syrjälä gen5_gt_irq_reset(dev); 32988bb61306SVille Syrjälä 32998bb61306SVille Syrjälä ibx_irq_reset(dev); 33008bb61306SVille Syrjälä } 33018bb61306SVille Syrjälä 33027e231dbeSJesse Barnes static void valleyview_irq_preinstall(struct drm_device *dev) 33037e231dbeSJesse Barnes { 3304fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 33057e231dbeSJesse Barnes 330634c7b8a7SVille Syrjälä I915_WRITE(VLV_MASTER_IER, 0); 330734c7b8a7SVille Syrjälä POSTING_READ(VLV_MASTER_IER); 330834c7b8a7SVille Syrjälä 33097c4d664eSPaulo Zanoni gen5_gt_irq_reset(dev); 33107e231dbeSJesse Barnes 3311ad22d106SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 33129918271eSVille Syrjälä if (dev_priv->display_irqs_enabled) 331370591a41SVille Syrjälä vlv_display_irq_reset(dev_priv); 3314ad22d106SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 33157e231dbeSJesse Barnes } 33167e231dbeSJesse Barnes 3317d6e3cca3SDaniel Vetter static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv) 3318d6e3cca3SDaniel Vetter { 3319d6e3cca3SDaniel Vetter GEN8_IRQ_RESET_NDX(GT, 0); 3320d6e3cca3SDaniel Vetter GEN8_IRQ_RESET_NDX(GT, 1); 3321d6e3cca3SDaniel Vetter GEN8_IRQ_RESET_NDX(GT, 2); 3322d6e3cca3SDaniel Vetter GEN8_IRQ_RESET_NDX(GT, 3); 3323d6e3cca3SDaniel Vetter } 3324d6e3cca3SDaniel Vetter 3325823f6b38SPaulo Zanoni static void gen8_irq_reset(struct drm_device *dev) 3326abd58f01SBen Widawsky { 3327fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 3328abd58f01SBen Widawsky int pipe; 3329abd58f01SBen Widawsky 3330abd58f01SBen Widawsky I915_WRITE(GEN8_MASTER_IRQ, 0); 3331abd58f01SBen Widawsky POSTING_READ(GEN8_MASTER_IRQ); 3332abd58f01SBen Widawsky 3333d6e3cca3SDaniel Vetter gen8_gt_irq_reset(dev_priv); 3334abd58f01SBen Widawsky 3335055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 3336f458ebbcSDaniel Vetter if (intel_display_power_is_enabled(dev_priv, 3337813bde43SPaulo Zanoni POWER_DOMAIN_PIPE(pipe))) 3338f86f3fb0SPaulo Zanoni GEN8_IRQ_RESET_NDX(DE_PIPE, pipe); 3339abd58f01SBen Widawsky 3340f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(GEN8_DE_PORT_); 3341f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(GEN8_DE_MISC_); 3342f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(GEN8_PCU_); 3343abd58f01SBen Widawsky 3344266ea3d9SShashank Sharma if (HAS_PCH_SPLIT(dev)) 33451c69eb42SPaulo Zanoni ibx_irq_reset(dev); 3346abd58f01SBen Widawsky } 3347abd58f01SBen Widawsky 33484c6c03beSDamien Lespiau void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv, 33494c6c03beSDamien Lespiau unsigned int pipe_mask) 3350d49bdb0eSPaulo Zanoni { 33511180e206SPaulo Zanoni uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN; 33526831f3e3SVille Syrjälä enum pipe pipe; 3353d49bdb0eSPaulo Zanoni 335413321786SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 33556831f3e3SVille Syrjälä for_each_pipe_masked(dev_priv, pipe, pipe_mask) 33566831f3e3SVille Syrjälä GEN8_IRQ_INIT_NDX(DE_PIPE, pipe, 33576831f3e3SVille Syrjälä dev_priv->de_irq_mask[pipe], 33586831f3e3SVille Syrjälä ~dev_priv->de_irq_mask[pipe] | extra_ier); 335913321786SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 3360d49bdb0eSPaulo Zanoni } 3361d49bdb0eSPaulo Zanoni 3362aae8ba84SVille Syrjälä void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv, 3363aae8ba84SVille Syrjälä unsigned int pipe_mask) 3364aae8ba84SVille Syrjälä { 33656831f3e3SVille Syrjälä enum pipe pipe; 33666831f3e3SVille Syrjälä 3367aae8ba84SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 33686831f3e3SVille Syrjälä for_each_pipe_masked(dev_priv, pipe, pipe_mask) 33696831f3e3SVille Syrjälä GEN8_IRQ_RESET_NDX(DE_PIPE, pipe); 3370aae8ba84SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 3371aae8ba84SVille Syrjälä 3372aae8ba84SVille Syrjälä /* make sure we're done processing display irqs */ 337391c8a326SChris Wilson synchronize_irq(dev_priv->drm.irq); 3374aae8ba84SVille Syrjälä } 3375aae8ba84SVille Syrjälä 337643f328d7SVille Syrjälä static void cherryview_irq_preinstall(struct drm_device *dev) 337743f328d7SVille Syrjälä { 3378fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 337943f328d7SVille Syrjälä 338043f328d7SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, 0); 338143f328d7SVille Syrjälä POSTING_READ(GEN8_MASTER_IRQ); 338243f328d7SVille Syrjälä 3383d6e3cca3SDaniel Vetter gen8_gt_irq_reset(dev_priv); 338443f328d7SVille Syrjälä 338543f328d7SVille Syrjälä GEN5_IRQ_RESET(GEN8_PCU_); 338643f328d7SVille Syrjälä 3387ad22d106SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 33889918271eSVille Syrjälä if (dev_priv->display_irqs_enabled) 338970591a41SVille Syrjälä vlv_display_irq_reset(dev_priv); 3390ad22d106SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 339143f328d7SVille Syrjälä } 339243f328d7SVille Syrjälä 339391d14251STvrtko Ursulin static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv, 339487a02106SVille Syrjälä const u32 hpd[HPD_NUM_PINS]) 339587a02106SVille Syrjälä { 339687a02106SVille Syrjälä struct intel_encoder *encoder; 339787a02106SVille Syrjälä u32 enabled_irqs = 0; 339887a02106SVille Syrjälä 339991c8a326SChris Wilson for_each_intel_encoder(&dev_priv->drm, encoder) 340087a02106SVille Syrjälä if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED) 340187a02106SVille Syrjälä enabled_irqs |= hpd[encoder->hpd_pin]; 340287a02106SVille Syrjälä 340387a02106SVille Syrjälä return enabled_irqs; 340487a02106SVille Syrjälä } 340587a02106SVille Syrjälä 340691d14251STvrtko Ursulin static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv) 340782a28bcfSDaniel Vetter { 340887a02106SVille Syrjälä u32 hotplug_irqs, hotplug, enabled_irqs; 340982a28bcfSDaniel Vetter 341091d14251STvrtko Ursulin if (HAS_PCH_IBX(dev_priv)) { 3411fee884edSDaniel Vetter hotplug_irqs = SDE_HOTPLUG_MASK; 341291d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx); 341382a28bcfSDaniel Vetter } else { 3414fee884edSDaniel Vetter hotplug_irqs = SDE_HOTPLUG_MASK_CPT; 341591d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt); 341682a28bcfSDaniel Vetter } 341782a28bcfSDaniel Vetter 3418fee884edSDaniel Vetter ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); 341982a28bcfSDaniel Vetter 34207fe0b973SKeith Packard /* 34217fe0b973SKeith Packard * Enable digital hotplug on the PCH, and configure the DP short pulse 34226dbf30ceSVille Syrjälä * duration to 2ms (which is the minimum in the Display Port spec). 34236dbf30ceSVille Syrjälä * The pulse duration bits are reserved on LPT+. 34247fe0b973SKeith Packard */ 34257fe0b973SKeith Packard hotplug = I915_READ(PCH_PORT_HOTPLUG); 34267fe0b973SKeith Packard hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK); 34277fe0b973SKeith Packard hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms; 34287fe0b973SKeith Packard hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms; 34297fe0b973SKeith Packard hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms; 34300b2eb33eSVille Syrjälä /* 34310b2eb33eSVille Syrjälä * When CPU and PCH are on the same package, port A 34320b2eb33eSVille Syrjälä * HPD must be enabled in both north and south. 34330b2eb33eSVille Syrjälä */ 343491d14251STvrtko Ursulin if (HAS_PCH_LPT_LP(dev_priv)) 34350b2eb33eSVille Syrjälä hotplug |= PORTA_HOTPLUG_ENABLE; 34367fe0b973SKeith Packard I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 34376dbf30ceSVille Syrjälä } 343826951cafSXiong Zhang 343991d14251STvrtko Ursulin static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv) 34406dbf30ceSVille Syrjälä { 34416dbf30ceSVille Syrjälä u32 hotplug_irqs, hotplug, enabled_irqs; 34426dbf30ceSVille Syrjälä 34436dbf30ceSVille Syrjälä hotplug_irqs = SDE_HOTPLUG_MASK_SPT; 344491d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt); 34456dbf30ceSVille Syrjälä 34466dbf30ceSVille Syrjälä ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); 34476dbf30ceSVille Syrjälä 34486dbf30ceSVille Syrjälä /* Enable digital hotplug on the PCH */ 34496dbf30ceSVille Syrjälä hotplug = I915_READ(PCH_PORT_HOTPLUG); 34506dbf30ceSVille Syrjälä hotplug |= PORTD_HOTPLUG_ENABLE | PORTC_HOTPLUG_ENABLE | 345174c0b395SVille Syrjälä PORTB_HOTPLUG_ENABLE | PORTA_HOTPLUG_ENABLE; 34526dbf30ceSVille Syrjälä I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 34536dbf30ceSVille Syrjälä 345426951cafSXiong Zhang hotplug = I915_READ(PCH_PORT_HOTPLUG2); 345526951cafSXiong Zhang hotplug |= PORTE_HOTPLUG_ENABLE; 345626951cafSXiong Zhang I915_WRITE(PCH_PORT_HOTPLUG2, hotplug); 345726951cafSXiong Zhang } 34587fe0b973SKeith Packard 345991d14251STvrtko Ursulin static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv) 3460e4ce95aaSVille Syrjälä { 3461e4ce95aaSVille Syrjälä u32 hotplug_irqs, hotplug, enabled_irqs; 3462e4ce95aaSVille Syrjälä 346391d14251STvrtko Ursulin if (INTEL_GEN(dev_priv) >= 8) { 34643a3b3c7dSVille Syrjälä hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG; 346591d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw); 34663a3b3c7dSVille Syrjälä 34673a3b3c7dSVille Syrjälä bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs); 346891d14251STvrtko Ursulin } else if (INTEL_GEN(dev_priv) >= 7) { 346923bb4cb5SVille Syrjälä hotplug_irqs = DE_DP_A_HOTPLUG_IVB; 347091d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb); 34713a3b3c7dSVille Syrjälä 34723a3b3c7dSVille Syrjälä ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs); 347323bb4cb5SVille Syrjälä } else { 3474e4ce95aaSVille Syrjälä hotplug_irqs = DE_DP_A_HOTPLUG; 347591d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk); 3476e4ce95aaSVille Syrjälä 3477e4ce95aaSVille Syrjälä ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs); 34783a3b3c7dSVille Syrjälä } 3479e4ce95aaSVille Syrjälä 3480e4ce95aaSVille Syrjälä /* 3481e4ce95aaSVille Syrjälä * Enable digital hotplug on the CPU, and configure the DP short pulse 3482e4ce95aaSVille Syrjälä * duration to 2ms (which is the minimum in the Display Port spec) 348323bb4cb5SVille Syrjälä * The pulse duration bits are reserved on HSW+. 3484e4ce95aaSVille Syrjälä */ 3485e4ce95aaSVille Syrjälä hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL); 3486e4ce95aaSVille Syrjälä hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK; 3487e4ce95aaSVille Syrjälä hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE | DIGITAL_PORTA_PULSE_DURATION_2ms; 3488e4ce95aaSVille Syrjälä I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug); 3489e4ce95aaSVille Syrjälä 349091d14251STvrtko Ursulin ibx_hpd_irq_setup(dev_priv); 3491e4ce95aaSVille Syrjälä } 3492e4ce95aaSVille Syrjälä 349391d14251STvrtko Ursulin static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv) 3494e0a20ad7SShashank Sharma { 3495a52bb15bSVille Syrjälä u32 hotplug_irqs, hotplug, enabled_irqs; 3496e0a20ad7SShashank Sharma 349791d14251STvrtko Ursulin enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt); 3498a52bb15bSVille Syrjälä hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK; 3499e0a20ad7SShashank Sharma 3500a52bb15bSVille Syrjälä bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs); 3501e0a20ad7SShashank Sharma 3502a52bb15bSVille Syrjälä hotplug = I915_READ(PCH_PORT_HOTPLUG); 3503a52bb15bSVille Syrjälä hotplug |= PORTC_HOTPLUG_ENABLE | PORTB_HOTPLUG_ENABLE | 3504a52bb15bSVille Syrjälä PORTA_HOTPLUG_ENABLE; 3505d252bf68SShubhangi Shrivastava 3506d252bf68SShubhangi Shrivastava DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n", 3507d252bf68SShubhangi Shrivastava hotplug, enabled_irqs); 3508d252bf68SShubhangi Shrivastava hotplug &= ~BXT_DDI_HPD_INVERT_MASK; 3509d252bf68SShubhangi Shrivastava 3510d252bf68SShubhangi Shrivastava /* 3511d252bf68SShubhangi Shrivastava * For BXT invert bit has to be set based on AOB design 3512d252bf68SShubhangi Shrivastava * for HPD detection logic, update it based on VBT fields. 3513d252bf68SShubhangi Shrivastava */ 3514d252bf68SShubhangi Shrivastava 3515d252bf68SShubhangi Shrivastava if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) && 3516d252bf68SShubhangi Shrivastava intel_bios_is_port_hpd_inverted(dev_priv, PORT_A)) 3517d252bf68SShubhangi Shrivastava hotplug |= BXT_DDIA_HPD_INVERT; 3518d252bf68SShubhangi Shrivastava if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) && 3519d252bf68SShubhangi Shrivastava intel_bios_is_port_hpd_inverted(dev_priv, PORT_B)) 3520d252bf68SShubhangi Shrivastava hotplug |= BXT_DDIB_HPD_INVERT; 3521d252bf68SShubhangi Shrivastava if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) && 3522d252bf68SShubhangi Shrivastava intel_bios_is_port_hpd_inverted(dev_priv, PORT_C)) 3523d252bf68SShubhangi Shrivastava hotplug |= BXT_DDIC_HPD_INVERT; 3524d252bf68SShubhangi Shrivastava 3525a52bb15bSVille Syrjälä I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 3526e0a20ad7SShashank Sharma } 3527e0a20ad7SShashank Sharma 3528d46da437SPaulo Zanoni static void ibx_irq_postinstall(struct drm_device *dev) 3529d46da437SPaulo Zanoni { 3530fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 353182a28bcfSDaniel Vetter u32 mask; 3532d46da437SPaulo Zanoni 3533692a04cfSDaniel Vetter if (HAS_PCH_NOP(dev)) 3534692a04cfSDaniel Vetter return; 3535692a04cfSDaniel Vetter 3536105b122eSPaulo Zanoni if (HAS_PCH_IBX(dev)) 35375c673b60SDaniel Vetter mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON; 3538105b122eSPaulo Zanoni else 35395c673b60SDaniel Vetter mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT; 35408664281bSPaulo Zanoni 3541b51a2842SVille Syrjälä gen5_assert_iir_is_zero(dev_priv, SDEIIR); 3542d46da437SPaulo Zanoni I915_WRITE(SDEIMR, ~mask); 3543d46da437SPaulo Zanoni } 3544d46da437SPaulo Zanoni 35450a9a8c91SDaniel Vetter static void gen5_gt_irq_postinstall(struct drm_device *dev) 35460a9a8c91SDaniel Vetter { 3547fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 35480a9a8c91SDaniel Vetter u32 pm_irqs, gt_irqs; 35490a9a8c91SDaniel Vetter 35500a9a8c91SDaniel Vetter pm_irqs = gt_irqs = 0; 35510a9a8c91SDaniel Vetter 35520a9a8c91SDaniel Vetter dev_priv->gt_irq_mask = ~0; 3553040d2baaSBen Widawsky if (HAS_L3_DPF(dev)) { 35540a9a8c91SDaniel Vetter /* L3 parity interrupt is always unmasked. */ 355535a85ac6SBen Widawsky dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev); 355635a85ac6SBen Widawsky gt_irqs |= GT_PARITY_ERROR(dev); 35570a9a8c91SDaniel Vetter } 35580a9a8c91SDaniel Vetter 35590a9a8c91SDaniel Vetter gt_irqs |= GT_RENDER_USER_INTERRUPT; 35600a9a8c91SDaniel Vetter if (IS_GEN5(dev)) { 3561f8973c21SChris Wilson gt_irqs |= ILK_BSD_USER_INTERRUPT; 35620a9a8c91SDaniel Vetter } else { 35630a9a8c91SDaniel Vetter gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT; 35640a9a8c91SDaniel Vetter } 35650a9a8c91SDaniel Vetter 356635079899SPaulo Zanoni GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs); 35670a9a8c91SDaniel Vetter 35680a9a8c91SDaniel Vetter if (INTEL_INFO(dev)->gen >= 6) { 356978e68d36SImre Deak /* 357078e68d36SImre Deak * RPS interrupts will get enabled/disabled on demand when RPS 357178e68d36SImre Deak * itself is enabled/disabled. 357278e68d36SImre Deak */ 35730a9a8c91SDaniel Vetter if (HAS_VEBOX(dev)) 35740a9a8c91SDaniel Vetter pm_irqs |= PM_VEBOX_USER_INTERRUPT; 35750a9a8c91SDaniel Vetter 3576605cd25bSPaulo Zanoni dev_priv->pm_irq_mask = 0xffffffff; 357735079899SPaulo Zanoni GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs); 35780a9a8c91SDaniel Vetter } 35790a9a8c91SDaniel Vetter } 35800a9a8c91SDaniel Vetter 3581f71d4af4SJesse Barnes static int ironlake_irq_postinstall(struct drm_device *dev) 3582036a4a7dSZhenyu Wang { 3583fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 35848e76f8dcSPaulo Zanoni u32 display_mask, extra_mask; 35858e76f8dcSPaulo Zanoni 35868e76f8dcSPaulo Zanoni if (INTEL_INFO(dev)->gen >= 7) { 35878e76f8dcSPaulo Zanoni display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | 35888e76f8dcSPaulo Zanoni DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB | 35898e76f8dcSPaulo Zanoni DE_PLANEB_FLIP_DONE_IVB | 35905c673b60SDaniel Vetter DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB); 35918e76f8dcSPaulo Zanoni extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB | 359223bb4cb5SVille Syrjälä DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB | 359323bb4cb5SVille Syrjälä DE_DP_A_HOTPLUG_IVB); 35948e76f8dcSPaulo Zanoni } else { 35958e76f8dcSPaulo Zanoni display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | 3596ce99c256SDaniel Vetter DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE | 35975b3a856bSDaniel Vetter DE_AUX_CHANNEL_A | 35985b3a856bSDaniel Vetter DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE | 35995b3a856bSDaniel Vetter DE_POISON); 3600e4ce95aaSVille Syrjälä extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT | 3601e4ce95aaSVille Syrjälä DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN | 3602e4ce95aaSVille Syrjälä DE_DP_A_HOTPLUG); 36038e76f8dcSPaulo Zanoni } 3604036a4a7dSZhenyu Wang 36051ec14ad3SChris Wilson dev_priv->irq_mask = ~display_mask; 3606036a4a7dSZhenyu Wang 36070c841212SPaulo Zanoni I915_WRITE(HWSTAM, 0xeffe); 36080c841212SPaulo Zanoni 3609622364b6SPaulo Zanoni ibx_irq_pre_postinstall(dev); 3610622364b6SPaulo Zanoni 361135079899SPaulo Zanoni GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask); 3612036a4a7dSZhenyu Wang 36130a9a8c91SDaniel Vetter gen5_gt_irq_postinstall(dev); 3614036a4a7dSZhenyu Wang 3615d46da437SPaulo Zanoni ibx_irq_postinstall(dev); 36167fe0b973SKeith Packard 3617f97108d1SJesse Barnes if (IS_IRONLAKE_M(dev)) { 36186005ce42SDaniel Vetter /* Enable PCU event interrupts 36196005ce42SDaniel Vetter * 36206005ce42SDaniel Vetter * spinlocking not required here for correctness since interrupt 36214bc9d430SDaniel Vetter * setup is guaranteed to run in single-threaded context. But we 36224bc9d430SDaniel Vetter * need it to make the assert_spin_locked happy. */ 3623d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 3624fbdedaeaSVille Syrjälä ilk_enable_display_irq(dev_priv, DE_PCU_EVENT); 3625d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 3626f97108d1SJesse Barnes } 3627f97108d1SJesse Barnes 3628036a4a7dSZhenyu Wang return 0; 3629036a4a7dSZhenyu Wang } 3630036a4a7dSZhenyu Wang 3631f8b79e58SImre Deak void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv) 3632f8b79e58SImre Deak { 3633f8b79e58SImre Deak assert_spin_locked(&dev_priv->irq_lock); 3634f8b79e58SImre Deak 3635f8b79e58SImre Deak if (dev_priv->display_irqs_enabled) 3636f8b79e58SImre Deak return; 3637f8b79e58SImre Deak 3638f8b79e58SImre Deak dev_priv->display_irqs_enabled = true; 3639f8b79e58SImre Deak 3640d6c69803SVille Syrjälä if (intel_irqs_enabled(dev_priv)) { 3641d6c69803SVille Syrjälä vlv_display_irq_reset(dev_priv); 3642ad22d106SVille Syrjälä vlv_display_irq_postinstall(dev_priv); 3643f8b79e58SImre Deak } 3644d6c69803SVille Syrjälä } 3645f8b79e58SImre Deak 3646f8b79e58SImre Deak void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv) 3647f8b79e58SImre Deak { 3648f8b79e58SImre Deak assert_spin_locked(&dev_priv->irq_lock); 3649f8b79e58SImre Deak 3650f8b79e58SImre Deak if (!dev_priv->display_irqs_enabled) 3651f8b79e58SImre Deak return; 3652f8b79e58SImre Deak 3653f8b79e58SImre Deak dev_priv->display_irqs_enabled = false; 3654f8b79e58SImre Deak 3655950eabafSImre Deak if (intel_irqs_enabled(dev_priv)) 3656ad22d106SVille Syrjälä vlv_display_irq_reset(dev_priv); 3657f8b79e58SImre Deak } 3658f8b79e58SImre Deak 36590e6c9a9eSVille Syrjälä 36600e6c9a9eSVille Syrjälä static int valleyview_irq_postinstall(struct drm_device *dev) 36610e6c9a9eSVille Syrjälä { 3662fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 36630e6c9a9eSVille Syrjälä 36640a9a8c91SDaniel Vetter gen5_gt_irq_postinstall(dev); 36657e231dbeSJesse Barnes 3666ad22d106SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 36679918271eSVille Syrjälä if (dev_priv->display_irqs_enabled) 3668ad22d106SVille Syrjälä vlv_display_irq_postinstall(dev_priv); 3669ad22d106SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 3670ad22d106SVille Syrjälä 36717e231dbeSJesse Barnes I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE); 367234c7b8a7SVille Syrjälä POSTING_READ(VLV_MASTER_IER); 367320afbda2SDaniel Vetter 367420afbda2SDaniel Vetter return 0; 367520afbda2SDaniel Vetter } 367620afbda2SDaniel Vetter 3677abd58f01SBen Widawsky static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv) 3678abd58f01SBen Widawsky { 3679abd58f01SBen Widawsky /* These are interrupts we'll toggle with the ring mask register */ 3680abd58f01SBen Widawsky uint32_t gt_interrupts[] = { 3681abd58f01SBen Widawsky GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT | 368273d477f6SOscar Mateo GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT | 368373d477f6SOscar Mateo GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT | 368473d477f6SOscar Mateo GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT, 3685abd58f01SBen Widawsky GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT | 368673d477f6SOscar Mateo GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT | 368773d477f6SOscar Mateo GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT | 368873d477f6SOscar Mateo GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT, 3689abd58f01SBen Widawsky 0, 369073d477f6SOscar Mateo GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT | 369173d477f6SOscar Mateo GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT 3692abd58f01SBen Widawsky }; 3693abd58f01SBen Widawsky 369498735739STvrtko Ursulin if (HAS_L3_DPF(dev_priv)) 369598735739STvrtko Ursulin gt_interrupts[0] |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT; 369698735739STvrtko Ursulin 36970961021aSBen Widawsky dev_priv->pm_irq_mask = 0xffffffff; 36989a2d2d87SDeepak S GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]); 36999a2d2d87SDeepak S GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]); 370078e68d36SImre Deak /* 370178e68d36SImre Deak * RPS interrupts will get enabled/disabled on demand when RPS itself 370278e68d36SImre Deak * is enabled/disabled. 370378e68d36SImre Deak */ 370478e68d36SImre Deak GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_irq_mask, 0); 37059a2d2d87SDeepak S GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]); 3706abd58f01SBen Widawsky } 3707abd58f01SBen Widawsky 3708abd58f01SBen Widawsky static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv) 3709abd58f01SBen Widawsky { 3710770de83dSDamien Lespiau uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE; 3711770de83dSDamien Lespiau uint32_t de_pipe_enables; 37123a3b3c7dSVille Syrjälä u32 de_port_masked = GEN8_AUX_CHANNEL_A; 37133a3b3c7dSVille Syrjälä u32 de_port_enables; 371411825b0dSVille Syrjälä u32 de_misc_masked = GEN8_DE_MISC_GSE; 37153a3b3c7dSVille Syrjälä enum pipe pipe; 3716770de83dSDamien Lespiau 3717b4834a50SRodrigo Vivi if (INTEL_INFO(dev_priv)->gen >= 9) { 3718770de83dSDamien Lespiau de_pipe_masked |= GEN9_PIPE_PLANE1_FLIP_DONE | 3719770de83dSDamien Lespiau GEN9_DE_PIPE_IRQ_FAULT_ERRORS; 37203a3b3c7dSVille Syrjälä de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C | 372188e04703SJesse Barnes GEN9_AUX_CHANNEL_D; 37229e63743eSShashank Sharma if (IS_BROXTON(dev_priv)) 37233a3b3c7dSVille Syrjälä de_port_masked |= BXT_DE_PORT_GMBUS; 37243a3b3c7dSVille Syrjälä } else { 3725770de83dSDamien Lespiau de_pipe_masked |= GEN8_PIPE_PRIMARY_FLIP_DONE | 3726770de83dSDamien Lespiau GEN8_DE_PIPE_IRQ_FAULT_ERRORS; 37273a3b3c7dSVille Syrjälä } 3728770de83dSDamien Lespiau 3729770de83dSDamien Lespiau de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK | 3730770de83dSDamien Lespiau GEN8_PIPE_FIFO_UNDERRUN; 3731770de83dSDamien Lespiau 37323a3b3c7dSVille Syrjälä de_port_enables = de_port_masked; 3733a52bb15bSVille Syrjälä if (IS_BROXTON(dev_priv)) 3734a52bb15bSVille Syrjälä de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK; 3735a52bb15bSVille Syrjälä else if (IS_BROADWELL(dev_priv)) 37363a3b3c7dSVille Syrjälä de_port_enables |= GEN8_PORT_DP_A_HOTPLUG; 37373a3b3c7dSVille Syrjälä 373813b3a0a7SDaniel Vetter dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked; 373913b3a0a7SDaniel Vetter dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked; 374013b3a0a7SDaniel Vetter dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked; 3741abd58f01SBen Widawsky 3742055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 3743f458ebbcSDaniel Vetter if (intel_display_power_is_enabled(dev_priv, 3744813bde43SPaulo Zanoni POWER_DOMAIN_PIPE(pipe))) 3745813bde43SPaulo Zanoni GEN8_IRQ_INIT_NDX(DE_PIPE, pipe, 3746813bde43SPaulo Zanoni dev_priv->de_irq_mask[pipe], 374735079899SPaulo Zanoni de_pipe_enables); 3748abd58f01SBen Widawsky 37493a3b3c7dSVille Syrjälä GEN5_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables); 375011825b0dSVille Syrjälä GEN5_IRQ_INIT(GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked); 3751abd58f01SBen Widawsky } 3752abd58f01SBen Widawsky 3753abd58f01SBen Widawsky static int gen8_irq_postinstall(struct drm_device *dev) 3754abd58f01SBen Widawsky { 3755fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 3756abd58f01SBen Widawsky 3757266ea3d9SShashank Sharma if (HAS_PCH_SPLIT(dev)) 3758622364b6SPaulo Zanoni ibx_irq_pre_postinstall(dev); 3759622364b6SPaulo Zanoni 3760abd58f01SBen Widawsky gen8_gt_irq_postinstall(dev_priv); 3761abd58f01SBen Widawsky gen8_de_irq_postinstall(dev_priv); 3762abd58f01SBen Widawsky 3763266ea3d9SShashank Sharma if (HAS_PCH_SPLIT(dev)) 3764abd58f01SBen Widawsky ibx_irq_postinstall(dev); 3765abd58f01SBen Widawsky 3766e5328c43SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); 3767abd58f01SBen Widawsky POSTING_READ(GEN8_MASTER_IRQ); 3768abd58f01SBen Widawsky 3769abd58f01SBen Widawsky return 0; 3770abd58f01SBen Widawsky } 3771abd58f01SBen Widawsky 377243f328d7SVille Syrjälä static int cherryview_irq_postinstall(struct drm_device *dev) 377343f328d7SVille Syrjälä { 3774fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 377543f328d7SVille Syrjälä 377643f328d7SVille Syrjälä gen8_gt_irq_postinstall(dev_priv); 377743f328d7SVille Syrjälä 3778ad22d106SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 37799918271eSVille Syrjälä if (dev_priv->display_irqs_enabled) 3780ad22d106SVille Syrjälä vlv_display_irq_postinstall(dev_priv); 3781ad22d106SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 3782ad22d106SVille Syrjälä 3783e5328c43SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); 378443f328d7SVille Syrjälä POSTING_READ(GEN8_MASTER_IRQ); 378543f328d7SVille Syrjälä 378643f328d7SVille Syrjälä return 0; 378743f328d7SVille Syrjälä } 378843f328d7SVille Syrjälä 3789abd58f01SBen Widawsky static void gen8_irq_uninstall(struct drm_device *dev) 3790abd58f01SBen Widawsky { 3791fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 3792abd58f01SBen Widawsky 3793abd58f01SBen Widawsky if (!dev_priv) 3794abd58f01SBen Widawsky return; 3795abd58f01SBen Widawsky 3796823f6b38SPaulo Zanoni gen8_irq_reset(dev); 3797abd58f01SBen Widawsky } 3798abd58f01SBen Widawsky 37997e231dbeSJesse Barnes static void valleyview_irq_uninstall(struct drm_device *dev) 38007e231dbeSJesse Barnes { 3801fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 38027e231dbeSJesse Barnes 38037e231dbeSJesse Barnes if (!dev_priv) 38047e231dbeSJesse Barnes return; 38057e231dbeSJesse Barnes 3806843d0e7dSImre Deak I915_WRITE(VLV_MASTER_IER, 0); 380734c7b8a7SVille Syrjälä POSTING_READ(VLV_MASTER_IER); 3808843d0e7dSImre Deak 3809893fce8eSVille Syrjälä gen5_gt_irq_reset(dev); 3810893fce8eSVille Syrjälä 38117e231dbeSJesse Barnes I915_WRITE(HWSTAM, 0xffffffff); 3812f8b79e58SImre Deak 3813ad22d106SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 38149918271eSVille Syrjälä if (dev_priv->display_irqs_enabled) 3815ad22d106SVille Syrjälä vlv_display_irq_reset(dev_priv); 3816ad22d106SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 38177e231dbeSJesse Barnes } 38187e231dbeSJesse Barnes 381943f328d7SVille Syrjälä static void cherryview_irq_uninstall(struct drm_device *dev) 382043f328d7SVille Syrjälä { 3821fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 382243f328d7SVille Syrjälä 382343f328d7SVille Syrjälä if (!dev_priv) 382443f328d7SVille Syrjälä return; 382543f328d7SVille Syrjälä 382643f328d7SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, 0); 382743f328d7SVille Syrjälä POSTING_READ(GEN8_MASTER_IRQ); 382843f328d7SVille Syrjälä 3829a2c30fbaSVille Syrjälä gen8_gt_irq_reset(dev_priv); 383043f328d7SVille Syrjälä 3831a2c30fbaSVille Syrjälä GEN5_IRQ_RESET(GEN8_PCU_); 383243f328d7SVille Syrjälä 3833ad22d106SVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 38349918271eSVille Syrjälä if (dev_priv->display_irqs_enabled) 3835ad22d106SVille Syrjälä vlv_display_irq_reset(dev_priv); 3836ad22d106SVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 383743f328d7SVille Syrjälä } 383843f328d7SVille Syrjälä 3839f71d4af4SJesse Barnes static void ironlake_irq_uninstall(struct drm_device *dev) 3840036a4a7dSZhenyu Wang { 3841fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 38424697995bSJesse Barnes 38434697995bSJesse Barnes if (!dev_priv) 38444697995bSJesse Barnes return; 38454697995bSJesse Barnes 3846be30b29fSPaulo Zanoni ironlake_irq_reset(dev); 3847036a4a7dSZhenyu Wang } 3848036a4a7dSZhenyu Wang 3849c2798b19SChris Wilson static void i8xx_irq_preinstall(struct drm_device * dev) 3850c2798b19SChris Wilson { 3851fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 3852c2798b19SChris Wilson int pipe; 3853c2798b19SChris Wilson 3854055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 3855c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3856c2798b19SChris Wilson I915_WRITE16(IMR, 0xffff); 3857c2798b19SChris Wilson I915_WRITE16(IER, 0x0); 3858c2798b19SChris Wilson POSTING_READ16(IER); 3859c2798b19SChris Wilson } 3860c2798b19SChris Wilson 3861c2798b19SChris Wilson static int i8xx_irq_postinstall(struct drm_device *dev) 3862c2798b19SChris Wilson { 3863fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 3864c2798b19SChris Wilson 3865c2798b19SChris Wilson I915_WRITE16(EMR, 3866c2798b19SChris Wilson ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH)); 3867c2798b19SChris Wilson 3868c2798b19SChris Wilson /* Unmask the interrupts that we always want on. */ 3869c2798b19SChris Wilson dev_priv->irq_mask = 3870c2798b19SChris Wilson ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3871c2798b19SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3872c2798b19SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 387337ef01abSDaniel Vetter I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT); 3874c2798b19SChris Wilson I915_WRITE16(IMR, dev_priv->irq_mask); 3875c2798b19SChris Wilson 3876c2798b19SChris Wilson I915_WRITE16(IER, 3877c2798b19SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3878c2798b19SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3879c2798b19SChris Wilson I915_USER_INTERRUPT); 3880c2798b19SChris Wilson POSTING_READ16(IER); 3881c2798b19SChris Wilson 3882379ef82dSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3883379ef82dSDaniel Vetter * just to make the assert_spin_locked check happy. */ 3884d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 3885755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 3886755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 3887d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 3888379ef82dSDaniel Vetter 3889c2798b19SChris Wilson return 0; 3890c2798b19SChris Wilson } 3891c2798b19SChris Wilson 38925a21b665SDaniel Vetter /* 38935a21b665SDaniel Vetter * Returns true when a page flip has completed. 38945a21b665SDaniel Vetter */ 38955a21b665SDaniel Vetter static bool i8xx_handle_vblank(struct drm_i915_private *dev_priv, 38965a21b665SDaniel Vetter int plane, int pipe, u32 iir) 38975a21b665SDaniel Vetter { 38985a21b665SDaniel Vetter u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane); 38995a21b665SDaniel Vetter 39005a21b665SDaniel Vetter if (!intel_pipe_handle_vblank(dev_priv, pipe)) 39015a21b665SDaniel Vetter return false; 39025a21b665SDaniel Vetter 39035a21b665SDaniel Vetter if ((iir & flip_pending) == 0) 39045a21b665SDaniel Vetter goto check_page_flip; 39055a21b665SDaniel Vetter 39065a21b665SDaniel Vetter /* We detect FlipDone by looking for the change in PendingFlip from '1' 39075a21b665SDaniel Vetter * to '0' on the following vblank, i.e. IIR has the Pendingflip 39085a21b665SDaniel Vetter * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence 39095a21b665SDaniel Vetter * the flip is completed (no longer pending). Since this doesn't raise 39105a21b665SDaniel Vetter * an interrupt per se, we watch for the change at vblank. 39115a21b665SDaniel Vetter */ 39125a21b665SDaniel Vetter if (I915_READ16(ISR) & flip_pending) 39135a21b665SDaniel Vetter goto check_page_flip; 39145a21b665SDaniel Vetter 39155a21b665SDaniel Vetter intel_finish_page_flip_cs(dev_priv, pipe); 39165a21b665SDaniel Vetter return true; 39175a21b665SDaniel Vetter 39185a21b665SDaniel Vetter check_page_flip: 39195a21b665SDaniel Vetter intel_check_page_flip(dev_priv, pipe); 39205a21b665SDaniel Vetter return false; 39215a21b665SDaniel Vetter } 39225a21b665SDaniel Vetter 3923ff1f525eSDaniel Vetter static irqreturn_t i8xx_irq_handler(int irq, void *arg) 3924c2798b19SChris Wilson { 392545a83f84SDaniel Vetter struct drm_device *dev = arg; 3926fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 3927c2798b19SChris Wilson u16 iir, new_iir; 3928c2798b19SChris Wilson u32 pipe_stats[2]; 3929c2798b19SChris Wilson int pipe; 3930c2798b19SChris Wilson u16 flip_mask = 3931c2798b19SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 3932c2798b19SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 39331f814dacSImre Deak irqreturn_t ret; 3934c2798b19SChris Wilson 39352dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 39362dd2a883SImre Deak return IRQ_NONE; 39372dd2a883SImre Deak 39381f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 39391f814dacSImre Deak disable_rpm_wakeref_asserts(dev_priv); 39401f814dacSImre Deak 39411f814dacSImre Deak ret = IRQ_NONE; 3942c2798b19SChris Wilson iir = I915_READ16(IIR); 3943c2798b19SChris Wilson if (iir == 0) 39441f814dacSImre Deak goto out; 3945c2798b19SChris Wilson 3946c2798b19SChris Wilson while (iir & ~flip_mask) { 3947c2798b19SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 3948c2798b19SChris Wilson * have been cleared after the pipestat interrupt was received. 3949c2798b19SChris Wilson * It doesn't set the bit in iir again, but it still produces 3950c2798b19SChris Wilson * interrupts (for non-MSI). 3951c2798b19SChris Wilson */ 3952222c7f51SDaniel Vetter spin_lock(&dev_priv->irq_lock); 3953c2798b19SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 3954aaecdf61SDaniel Vetter DRM_DEBUG("Command parser error, iir 0x%08x\n", iir); 3955c2798b19SChris Wilson 3956055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 3957f0f59a00SVille Syrjälä i915_reg_t reg = PIPESTAT(pipe); 3958c2798b19SChris Wilson pipe_stats[pipe] = I915_READ(reg); 3959c2798b19SChris Wilson 3960c2798b19SChris Wilson /* 3961c2798b19SChris Wilson * Clear the PIPE*STAT regs before the IIR 3962c2798b19SChris Wilson */ 39632d9d2b0bSVille Syrjälä if (pipe_stats[pipe] & 0x8000ffff) 3964c2798b19SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 3965c2798b19SChris Wilson } 3966222c7f51SDaniel Vetter spin_unlock(&dev_priv->irq_lock); 3967c2798b19SChris Wilson 3968c2798b19SChris Wilson I915_WRITE16(IIR, iir & ~flip_mask); 3969c2798b19SChris Wilson new_iir = I915_READ16(IIR); /* Flush posted writes */ 3970c2798b19SChris Wilson 3971c2798b19SChris Wilson if (iir & I915_USER_INTERRUPT) 39724a570db5STvrtko Ursulin notify_ring(&dev_priv->engine[RCS]); 3973c2798b19SChris Wilson 3974055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 39755a21b665SDaniel Vetter int plane = pipe; 39765a21b665SDaniel Vetter if (HAS_FBC(dev_priv)) 39775a21b665SDaniel Vetter plane = !plane; 39785a21b665SDaniel Vetter 39795a21b665SDaniel Vetter if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS && 39805a21b665SDaniel Vetter i8xx_handle_vblank(dev_priv, plane, pipe, iir)) 39815a21b665SDaniel Vetter flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane); 3982c2798b19SChris Wilson 39834356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 398491d14251STvrtko Ursulin i9xx_pipe_crc_irq_handler(dev_priv, pipe); 39852d9d2b0bSVille Syrjälä 39861f7247c0SDaniel Vetter if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 39871f7247c0SDaniel Vetter intel_cpu_fifo_underrun_irq_handler(dev_priv, 39881f7247c0SDaniel Vetter pipe); 39894356d586SDaniel Vetter } 3990c2798b19SChris Wilson 3991c2798b19SChris Wilson iir = new_iir; 3992c2798b19SChris Wilson } 39931f814dacSImre Deak ret = IRQ_HANDLED; 3994c2798b19SChris Wilson 39951f814dacSImre Deak out: 39961f814dacSImre Deak enable_rpm_wakeref_asserts(dev_priv); 39971f814dacSImre Deak 39981f814dacSImre Deak return ret; 3999c2798b19SChris Wilson } 4000c2798b19SChris Wilson 4001c2798b19SChris Wilson static void i8xx_irq_uninstall(struct drm_device * dev) 4002c2798b19SChris Wilson { 4003fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 4004c2798b19SChris Wilson int pipe; 4005c2798b19SChris Wilson 4006055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 4007c2798b19SChris Wilson /* Clear enable bits; then clear status bits */ 4008c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 4009c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe))); 4010c2798b19SChris Wilson } 4011c2798b19SChris Wilson I915_WRITE16(IMR, 0xffff); 4012c2798b19SChris Wilson I915_WRITE16(IER, 0x0); 4013c2798b19SChris Wilson I915_WRITE16(IIR, I915_READ16(IIR)); 4014c2798b19SChris Wilson } 4015c2798b19SChris Wilson 4016a266c7d5SChris Wilson static void i915_irq_preinstall(struct drm_device * dev) 4017a266c7d5SChris Wilson { 4018fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 4019a266c7d5SChris Wilson int pipe; 4020a266c7d5SChris Wilson 4021a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 40220706f17cSEgbert Eich i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0); 4023a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 4024a266c7d5SChris Wilson } 4025a266c7d5SChris Wilson 402600d98ebdSChris Wilson I915_WRITE16(HWSTAM, 0xeffe); 4027055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 4028a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 4029a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 4030a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 4031a266c7d5SChris Wilson POSTING_READ(IER); 4032a266c7d5SChris Wilson } 4033a266c7d5SChris Wilson 4034a266c7d5SChris Wilson static int i915_irq_postinstall(struct drm_device *dev) 4035a266c7d5SChris Wilson { 4036fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 403738bde180SChris Wilson u32 enable_mask; 4038a266c7d5SChris Wilson 403938bde180SChris Wilson I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH)); 404038bde180SChris Wilson 404138bde180SChris Wilson /* Unmask the interrupts that we always want on. */ 404238bde180SChris Wilson dev_priv->irq_mask = 404338bde180SChris Wilson ~(I915_ASLE_INTERRUPT | 404438bde180SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 404538bde180SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 404638bde180SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 404737ef01abSDaniel Vetter I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT); 404838bde180SChris Wilson 404938bde180SChris Wilson enable_mask = 405038bde180SChris Wilson I915_ASLE_INTERRUPT | 405138bde180SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 405238bde180SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 405338bde180SChris Wilson I915_USER_INTERRUPT; 405438bde180SChris Wilson 4055a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 40560706f17cSEgbert Eich i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0); 405720afbda2SDaniel Vetter POSTING_READ(PORT_HOTPLUG_EN); 405820afbda2SDaniel Vetter 4059a266c7d5SChris Wilson /* Enable in IER... */ 4060a266c7d5SChris Wilson enable_mask |= I915_DISPLAY_PORT_INTERRUPT; 4061a266c7d5SChris Wilson /* and unmask in IMR */ 4062a266c7d5SChris Wilson dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT; 4063a266c7d5SChris Wilson } 4064a266c7d5SChris Wilson 4065a266c7d5SChris Wilson I915_WRITE(IMR, dev_priv->irq_mask); 4066a266c7d5SChris Wilson I915_WRITE(IER, enable_mask); 4067a266c7d5SChris Wilson POSTING_READ(IER); 4068a266c7d5SChris Wilson 406991d14251STvrtko Ursulin i915_enable_asle_pipestat(dev_priv); 407020afbda2SDaniel Vetter 4071379ef82dSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 4072379ef82dSDaniel Vetter * just to make the assert_spin_locked check happy. */ 4073d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 4074755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 4075755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 4076d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 4077379ef82dSDaniel Vetter 407820afbda2SDaniel Vetter return 0; 407920afbda2SDaniel Vetter } 408020afbda2SDaniel Vetter 40815a21b665SDaniel Vetter /* 40825a21b665SDaniel Vetter * Returns true when a page flip has completed. 40835a21b665SDaniel Vetter */ 40845a21b665SDaniel Vetter static bool i915_handle_vblank(struct drm_i915_private *dev_priv, 40855a21b665SDaniel Vetter int plane, int pipe, u32 iir) 40865a21b665SDaniel Vetter { 40875a21b665SDaniel Vetter u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane); 40885a21b665SDaniel Vetter 40895a21b665SDaniel Vetter if (!intel_pipe_handle_vblank(dev_priv, pipe)) 40905a21b665SDaniel Vetter return false; 40915a21b665SDaniel Vetter 40925a21b665SDaniel Vetter if ((iir & flip_pending) == 0) 40935a21b665SDaniel Vetter goto check_page_flip; 40945a21b665SDaniel Vetter 40955a21b665SDaniel Vetter /* We detect FlipDone by looking for the change in PendingFlip from '1' 40965a21b665SDaniel Vetter * to '0' on the following vblank, i.e. IIR has the Pendingflip 40975a21b665SDaniel Vetter * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence 40985a21b665SDaniel Vetter * the flip is completed (no longer pending). Since this doesn't raise 40995a21b665SDaniel Vetter * an interrupt per se, we watch for the change at vblank. 41005a21b665SDaniel Vetter */ 41015a21b665SDaniel Vetter if (I915_READ(ISR) & flip_pending) 41025a21b665SDaniel Vetter goto check_page_flip; 41035a21b665SDaniel Vetter 41045a21b665SDaniel Vetter intel_finish_page_flip_cs(dev_priv, pipe); 41055a21b665SDaniel Vetter return true; 41065a21b665SDaniel Vetter 41075a21b665SDaniel Vetter check_page_flip: 41085a21b665SDaniel Vetter intel_check_page_flip(dev_priv, pipe); 41095a21b665SDaniel Vetter return false; 41105a21b665SDaniel Vetter } 41115a21b665SDaniel Vetter 4112ff1f525eSDaniel Vetter static irqreturn_t i915_irq_handler(int irq, void *arg) 4113a266c7d5SChris Wilson { 411445a83f84SDaniel Vetter struct drm_device *dev = arg; 4115fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 41168291ee90SChris Wilson u32 iir, new_iir, pipe_stats[I915_MAX_PIPES]; 411738bde180SChris Wilson u32 flip_mask = 411838bde180SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 411938bde180SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 412038bde180SChris Wilson int pipe, ret = IRQ_NONE; 4121a266c7d5SChris Wilson 41222dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 41232dd2a883SImre Deak return IRQ_NONE; 41242dd2a883SImre Deak 41251f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 41261f814dacSImre Deak disable_rpm_wakeref_asserts(dev_priv); 41271f814dacSImre Deak 4128a266c7d5SChris Wilson iir = I915_READ(IIR); 412938bde180SChris Wilson do { 413038bde180SChris Wilson bool irq_received = (iir & ~flip_mask) != 0; 41318291ee90SChris Wilson bool blc_event = false; 4132a266c7d5SChris Wilson 4133a266c7d5SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 4134a266c7d5SChris Wilson * have been cleared after the pipestat interrupt was received. 4135a266c7d5SChris Wilson * It doesn't set the bit in iir again, but it still produces 4136a266c7d5SChris Wilson * interrupts (for non-MSI). 4137a266c7d5SChris Wilson */ 4138222c7f51SDaniel Vetter spin_lock(&dev_priv->irq_lock); 4139a266c7d5SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 4140aaecdf61SDaniel Vetter DRM_DEBUG("Command parser error, iir 0x%08x\n", iir); 4141a266c7d5SChris Wilson 4142055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 4143f0f59a00SVille Syrjälä i915_reg_t reg = PIPESTAT(pipe); 4144a266c7d5SChris Wilson pipe_stats[pipe] = I915_READ(reg); 4145a266c7d5SChris Wilson 414638bde180SChris Wilson /* Clear the PIPE*STAT regs before the IIR */ 4147a266c7d5SChris Wilson if (pipe_stats[pipe] & 0x8000ffff) { 4148a266c7d5SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 414938bde180SChris Wilson irq_received = true; 4150a266c7d5SChris Wilson } 4151a266c7d5SChris Wilson } 4152222c7f51SDaniel Vetter spin_unlock(&dev_priv->irq_lock); 4153a266c7d5SChris Wilson 4154a266c7d5SChris Wilson if (!irq_received) 4155a266c7d5SChris Wilson break; 4156a266c7d5SChris Wilson 4157a266c7d5SChris Wilson /* Consume port. Then clear IIR or we'll miss events */ 415891d14251STvrtko Ursulin if (I915_HAS_HOTPLUG(dev_priv) && 41591ae3c34cSVille Syrjälä iir & I915_DISPLAY_PORT_INTERRUPT) { 41601ae3c34cSVille Syrjälä u32 hotplug_status = i9xx_hpd_irq_ack(dev_priv); 41611ae3c34cSVille Syrjälä if (hotplug_status) 416291d14251STvrtko Ursulin i9xx_hpd_irq_handler(dev_priv, hotplug_status); 41631ae3c34cSVille Syrjälä } 4164a266c7d5SChris Wilson 416538bde180SChris Wilson I915_WRITE(IIR, iir & ~flip_mask); 4166a266c7d5SChris Wilson new_iir = I915_READ(IIR); /* Flush posted writes */ 4167a266c7d5SChris Wilson 4168a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 41694a570db5STvrtko Ursulin notify_ring(&dev_priv->engine[RCS]); 4170a266c7d5SChris Wilson 4171055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 41725a21b665SDaniel Vetter int plane = pipe; 41735a21b665SDaniel Vetter if (HAS_FBC(dev_priv)) 41745a21b665SDaniel Vetter plane = !plane; 41755a21b665SDaniel Vetter 41765a21b665SDaniel Vetter if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS && 41775a21b665SDaniel Vetter i915_handle_vblank(dev_priv, plane, pipe, iir)) 41785a21b665SDaniel Vetter flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane); 4179a266c7d5SChris Wilson 4180a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 4181a266c7d5SChris Wilson blc_event = true; 41824356d586SDaniel Vetter 41834356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 418491d14251STvrtko Ursulin i9xx_pipe_crc_irq_handler(dev_priv, pipe); 41852d9d2b0bSVille Syrjälä 41861f7247c0SDaniel Vetter if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 41871f7247c0SDaniel Vetter intel_cpu_fifo_underrun_irq_handler(dev_priv, 41881f7247c0SDaniel Vetter pipe); 4189a266c7d5SChris Wilson } 4190a266c7d5SChris Wilson 4191a266c7d5SChris Wilson if (blc_event || (iir & I915_ASLE_INTERRUPT)) 419291d14251STvrtko Ursulin intel_opregion_asle_intr(dev_priv); 4193a266c7d5SChris Wilson 4194a266c7d5SChris Wilson /* With MSI, interrupts are only generated when iir 4195a266c7d5SChris Wilson * transitions from zero to nonzero. If another bit got 4196a266c7d5SChris Wilson * set while we were handling the existing iir bits, then 4197a266c7d5SChris Wilson * we would never get another interrupt. 4198a266c7d5SChris Wilson * 4199a266c7d5SChris Wilson * This is fine on non-MSI as well, as if we hit this path 4200a266c7d5SChris Wilson * we avoid exiting the interrupt handler only to generate 4201a266c7d5SChris Wilson * another one. 4202a266c7d5SChris Wilson * 4203a266c7d5SChris Wilson * Note that for MSI this could cause a stray interrupt report 4204a266c7d5SChris Wilson * if an interrupt landed in the time between writing IIR and 4205a266c7d5SChris Wilson * the posting read. This should be rare enough to never 4206a266c7d5SChris Wilson * trigger the 99% of 100,000 interrupts test for disabling 4207a266c7d5SChris Wilson * stray interrupts. 4208a266c7d5SChris Wilson */ 420938bde180SChris Wilson ret = IRQ_HANDLED; 4210a266c7d5SChris Wilson iir = new_iir; 421138bde180SChris Wilson } while (iir & ~flip_mask); 4212a266c7d5SChris Wilson 42131f814dacSImre Deak enable_rpm_wakeref_asserts(dev_priv); 42141f814dacSImre Deak 4215a266c7d5SChris Wilson return ret; 4216a266c7d5SChris Wilson } 4217a266c7d5SChris Wilson 4218a266c7d5SChris Wilson static void i915_irq_uninstall(struct drm_device * dev) 4219a266c7d5SChris Wilson { 4220fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 4221a266c7d5SChris Wilson int pipe; 4222a266c7d5SChris Wilson 4223a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 42240706f17cSEgbert Eich i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0); 4225a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 4226a266c7d5SChris Wilson } 4227a266c7d5SChris Wilson 422800d98ebdSChris Wilson I915_WRITE16(HWSTAM, 0xffff); 4229055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 423055b39755SChris Wilson /* Clear enable bits; then clear status bits */ 4231a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 423255b39755SChris Wilson I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe))); 423355b39755SChris Wilson } 4234a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 4235a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 4236a266c7d5SChris Wilson 4237a266c7d5SChris Wilson I915_WRITE(IIR, I915_READ(IIR)); 4238a266c7d5SChris Wilson } 4239a266c7d5SChris Wilson 4240a266c7d5SChris Wilson static void i965_irq_preinstall(struct drm_device * dev) 4241a266c7d5SChris Wilson { 4242fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 4243a266c7d5SChris Wilson int pipe; 4244a266c7d5SChris Wilson 42450706f17cSEgbert Eich i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0); 4246a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 4247a266c7d5SChris Wilson 4248a266c7d5SChris Wilson I915_WRITE(HWSTAM, 0xeffe); 4249055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 4250a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 4251a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 4252a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 4253a266c7d5SChris Wilson POSTING_READ(IER); 4254a266c7d5SChris Wilson } 4255a266c7d5SChris Wilson 4256a266c7d5SChris Wilson static int i965_irq_postinstall(struct drm_device *dev) 4257a266c7d5SChris Wilson { 4258fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 4259bbba0a97SChris Wilson u32 enable_mask; 4260a266c7d5SChris Wilson u32 error_mask; 4261a266c7d5SChris Wilson 4262a266c7d5SChris Wilson /* Unmask the interrupts that we always want on. */ 4263bbba0a97SChris Wilson dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT | 4264adca4730SChris Wilson I915_DISPLAY_PORT_INTERRUPT | 4265bbba0a97SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 4266bbba0a97SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 4267bbba0a97SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 4268bbba0a97SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | 4269bbba0a97SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 4270bbba0a97SChris Wilson 4271bbba0a97SChris Wilson enable_mask = ~dev_priv->irq_mask; 427221ad8330SVille Syrjälä enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 427321ad8330SVille Syrjälä I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT); 4274bbba0a97SChris Wilson enable_mask |= I915_USER_INTERRUPT; 4275bbba0a97SChris Wilson 427691d14251STvrtko Ursulin if (IS_G4X(dev_priv)) 4277bbba0a97SChris Wilson enable_mask |= I915_BSD_USER_INTERRUPT; 4278a266c7d5SChris Wilson 4279b79480baSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 4280b79480baSDaniel Vetter * just to make the assert_spin_locked check happy. */ 4281d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 4282755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS); 4283755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 4284755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 4285d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 4286a266c7d5SChris Wilson 4287a266c7d5SChris Wilson /* 4288a266c7d5SChris Wilson * Enable some error detection, note the instruction error mask 4289a266c7d5SChris Wilson * bit is reserved, so we leave it masked. 4290a266c7d5SChris Wilson */ 429191d14251STvrtko Ursulin if (IS_G4X(dev_priv)) { 4292a266c7d5SChris Wilson error_mask = ~(GM45_ERROR_PAGE_TABLE | 4293a266c7d5SChris Wilson GM45_ERROR_MEM_PRIV | 4294a266c7d5SChris Wilson GM45_ERROR_CP_PRIV | 4295a266c7d5SChris Wilson I915_ERROR_MEMORY_REFRESH); 4296a266c7d5SChris Wilson } else { 4297a266c7d5SChris Wilson error_mask = ~(I915_ERROR_PAGE_TABLE | 4298a266c7d5SChris Wilson I915_ERROR_MEMORY_REFRESH); 4299a266c7d5SChris Wilson } 4300a266c7d5SChris Wilson I915_WRITE(EMR, error_mask); 4301a266c7d5SChris Wilson 4302a266c7d5SChris Wilson I915_WRITE(IMR, dev_priv->irq_mask); 4303a266c7d5SChris Wilson I915_WRITE(IER, enable_mask); 4304a266c7d5SChris Wilson POSTING_READ(IER); 4305a266c7d5SChris Wilson 43060706f17cSEgbert Eich i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0); 430720afbda2SDaniel Vetter POSTING_READ(PORT_HOTPLUG_EN); 430820afbda2SDaniel Vetter 430991d14251STvrtko Ursulin i915_enable_asle_pipestat(dev_priv); 431020afbda2SDaniel Vetter 431120afbda2SDaniel Vetter return 0; 431220afbda2SDaniel Vetter } 431320afbda2SDaniel Vetter 431491d14251STvrtko Ursulin static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv) 431520afbda2SDaniel Vetter { 431620afbda2SDaniel Vetter u32 hotplug_en; 431720afbda2SDaniel Vetter 4318b5ea2d56SDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 4319b5ea2d56SDaniel Vetter 4320adca4730SChris Wilson /* Note HDMI and DP share hotplug bits */ 4321e5868a31SEgbert Eich /* enable bits are the same for all generations */ 432291d14251STvrtko Ursulin hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915); 4323a266c7d5SChris Wilson /* Programming the CRT detection parameters tends 4324a266c7d5SChris Wilson to generate a spurious hotplug event about three 4325a266c7d5SChris Wilson seconds later. So just do it once. 4326a266c7d5SChris Wilson */ 432791d14251STvrtko Ursulin if (IS_G4X(dev_priv)) 4328a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64; 4329a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; 4330a266c7d5SChris Wilson 4331a266c7d5SChris Wilson /* Ignore TV since it's buggy */ 43320706f17cSEgbert Eich i915_hotplug_interrupt_update_locked(dev_priv, 4333f9e3dc78SJani Nikula HOTPLUG_INT_EN_MASK | 4334f9e3dc78SJani Nikula CRT_HOTPLUG_VOLTAGE_COMPARE_MASK | 4335f9e3dc78SJani Nikula CRT_HOTPLUG_ACTIVATION_PERIOD_64, 43360706f17cSEgbert Eich hotplug_en); 4337a266c7d5SChris Wilson } 4338a266c7d5SChris Wilson 4339ff1f525eSDaniel Vetter static irqreturn_t i965_irq_handler(int irq, void *arg) 4340a266c7d5SChris Wilson { 434145a83f84SDaniel Vetter struct drm_device *dev = arg; 4342fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 4343a266c7d5SChris Wilson u32 iir, new_iir; 4344a266c7d5SChris Wilson u32 pipe_stats[I915_MAX_PIPES]; 4345a266c7d5SChris Wilson int ret = IRQ_NONE, pipe; 434621ad8330SVille Syrjälä u32 flip_mask = 434721ad8330SVille Syrjälä I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 434821ad8330SVille Syrjälä I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 4349a266c7d5SChris Wilson 43502dd2a883SImre Deak if (!intel_irqs_enabled(dev_priv)) 43512dd2a883SImre Deak return IRQ_NONE; 43522dd2a883SImre Deak 43531f814dacSImre Deak /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 43541f814dacSImre Deak disable_rpm_wakeref_asserts(dev_priv); 43551f814dacSImre Deak 4356a266c7d5SChris Wilson iir = I915_READ(IIR); 4357a266c7d5SChris Wilson 4358a266c7d5SChris Wilson for (;;) { 4359501e01d7SVille Syrjälä bool irq_received = (iir & ~flip_mask) != 0; 43602c8ba29fSChris Wilson bool blc_event = false; 43612c8ba29fSChris Wilson 4362a266c7d5SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 4363a266c7d5SChris Wilson * have been cleared after the pipestat interrupt was received. 4364a266c7d5SChris Wilson * It doesn't set the bit in iir again, but it still produces 4365a266c7d5SChris Wilson * interrupts (for non-MSI). 4366a266c7d5SChris Wilson */ 4367222c7f51SDaniel Vetter spin_lock(&dev_priv->irq_lock); 4368a266c7d5SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 4369aaecdf61SDaniel Vetter DRM_DEBUG("Command parser error, iir 0x%08x\n", iir); 4370a266c7d5SChris Wilson 4371055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 4372f0f59a00SVille Syrjälä i915_reg_t reg = PIPESTAT(pipe); 4373a266c7d5SChris Wilson pipe_stats[pipe] = I915_READ(reg); 4374a266c7d5SChris Wilson 4375a266c7d5SChris Wilson /* 4376a266c7d5SChris Wilson * Clear the PIPE*STAT regs before the IIR 4377a266c7d5SChris Wilson */ 4378a266c7d5SChris Wilson if (pipe_stats[pipe] & 0x8000ffff) { 4379a266c7d5SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 4380501e01d7SVille Syrjälä irq_received = true; 4381a266c7d5SChris Wilson } 4382a266c7d5SChris Wilson } 4383222c7f51SDaniel Vetter spin_unlock(&dev_priv->irq_lock); 4384a266c7d5SChris Wilson 4385a266c7d5SChris Wilson if (!irq_received) 4386a266c7d5SChris Wilson break; 4387a266c7d5SChris Wilson 4388a266c7d5SChris Wilson ret = IRQ_HANDLED; 4389a266c7d5SChris Wilson 4390a266c7d5SChris Wilson /* Consume port. Then clear IIR or we'll miss events */ 43911ae3c34cSVille Syrjälä if (iir & I915_DISPLAY_PORT_INTERRUPT) { 43921ae3c34cSVille Syrjälä u32 hotplug_status = i9xx_hpd_irq_ack(dev_priv); 43931ae3c34cSVille Syrjälä if (hotplug_status) 439491d14251STvrtko Ursulin i9xx_hpd_irq_handler(dev_priv, hotplug_status); 43951ae3c34cSVille Syrjälä } 4396a266c7d5SChris Wilson 439721ad8330SVille Syrjälä I915_WRITE(IIR, iir & ~flip_mask); 4398a266c7d5SChris Wilson new_iir = I915_READ(IIR); /* Flush posted writes */ 4399a266c7d5SChris Wilson 4400a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 44014a570db5STvrtko Ursulin notify_ring(&dev_priv->engine[RCS]); 4402a266c7d5SChris Wilson if (iir & I915_BSD_USER_INTERRUPT) 44034a570db5STvrtko Ursulin notify_ring(&dev_priv->engine[VCS]); 4404a266c7d5SChris Wilson 4405055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 44065a21b665SDaniel Vetter if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS && 44075a21b665SDaniel Vetter i915_handle_vblank(dev_priv, pipe, pipe, iir)) 44085a21b665SDaniel Vetter flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe); 4409a266c7d5SChris Wilson 4410a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 4411a266c7d5SChris Wilson blc_event = true; 44124356d586SDaniel Vetter 44134356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 441491d14251STvrtko Ursulin i9xx_pipe_crc_irq_handler(dev_priv, pipe); 4415a266c7d5SChris Wilson 44161f7247c0SDaniel Vetter if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 44171f7247c0SDaniel Vetter intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 44182d9d2b0bSVille Syrjälä } 4419a266c7d5SChris Wilson 4420a266c7d5SChris Wilson if (blc_event || (iir & I915_ASLE_INTERRUPT)) 442191d14251STvrtko Ursulin intel_opregion_asle_intr(dev_priv); 4422a266c7d5SChris Wilson 4423515ac2bbSDaniel Vetter if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 442491d14251STvrtko Ursulin gmbus_irq_handler(dev_priv); 4425515ac2bbSDaniel Vetter 4426a266c7d5SChris Wilson /* With MSI, interrupts are only generated when iir 4427a266c7d5SChris Wilson * transitions from zero to nonzero. If another bit got 4428a266c7d5SChris Wilson * set while we were handling the existing iir bits, then 4429a266c7d5SChris Wilson * we would never get another interrupt. 4430a266c7d5SChris Wilson * 4431a266c7d5SChris Wilson * This is fine on non-MSI as well, as if we hit this path 4432a266c7d5SChris Wilson * we avoid exiting the interrupt handler only to generate 4433a266c7d5SChris Wilson * another one. 4434a266c7d5SChris Wilson * 4435a266c7d5SChris Wilson * Note that for MSI this could cause a stray interrupt report 4436a266c7d5SChris Wilson * if an interrupt landed in the time between writing IIR and 4437a266c7d5SChris Wilson * the posting read. This should be rare enough to never 4438a266c7d5SChris Wilson * trigger the 99% of 100,000 interrupts test for disabling 4439a266c7d5SChris Wilson * stray interrupts. 4440a266c7d5SChris Wilson */ 4441a266c7d5SChris Wilson iir = new_iir; 4442a266c7d5SChris Wilson } 4443a266c7d5SChris Wilson 44441f814dacSImre Deak enable_rpm_wakeref_asserts(dev_priv); 44451f814dacSImre Deak 4446a266c7d5SChris Wilson return ret; 4447a266c7d5SChris Wilson } 4448a266c7d5SChris Wilson 4449a266c7d5SChris Wilson static void i965_irq_uninstall(struct drm_device * dev) 4450a266c7d5SChris Wilson { 4451fac5e23eSChris Wilson struct drm_i915_private *dev_priv = to_i915(dev); 4452a266c7d5SChris Wilson int pipe; 4453a266c7d5SChris Wilson 4454a266c7d5SChris Wilson if (!dev_priv) 4455a266c7d5SChris Wilson return; 4456a266c7d5SChris Wilson 44570706f17cSEgbert Eich i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0); 4458a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 4459a266c7d5SChris Wilson 4460a266c7d5SChris Wilson I915_WRITE(HWSTAM, 0xffffffff); 4461055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 4462a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 4463a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 4464a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 4465a266c7d5SChris Wilson 4466055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 4467a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 4468a266c7d5SChris Wilson I915_READ(PIPESTAT(pipe)) & 0x8000ffff); 4469a266c7d5SChris Wilson I915_WRITE(IIR, I915_READ(IIR)); 4470a266c7d5SChris Wilson } 4471a266c7d5SChris Wilson 4472fca52a55SDaniel Vetter /** 4473fca52a55SDaniel Vetter * intel_irq_init - initializes irq support 4474fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4475fca52a55SDaniel Vetter * 4476fca52a55SDaniel Vetter * This function initializes all the irq support including work items, timers 4477fca52a55SDaniel Vetter * and all the vtables. It does not setup the interrupt itself though. 4478fca52a55SDaniel Vetter */ 4479b963291cSDaniel Vetter void intel_irq_init(struct drm_i915_private *dev_priv) 4480f71d4af4SJesse Barnes { 448191c8a326SChris Wilson struct drm_device *dev = &dev_priv->drm; 44828b2e326dSChris Wilson 448377913b39SJani Nikula intel_hpd_init_work(dev_priv); 448477913b39SJani Nikula 4485c6a828d3SDaniel Vetter INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work); 4486a4da4fa4SDaniel Vetter INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work); 44878b2e326dSChris Wilson 4488a6706b45SDeepak S /* Let's track the enabled rps events */ 4489666a4537SWayne Boyer if (IS_VALLEYVIEW(dev_priv)) 44906c65a587SVille Syrjälä /* WaGsvRC0ResidencyMethod:vlv */ 44916f4b12f8SChris Wilson dev_priv->pm_rps_events = GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED; 449231685c25SDeepak S else 4493a6706b45SDeepak S dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS; 4494a6706b45SDeepak S 44951800ad25SSagar Arun Kamble dev_priv->rps.pm_intr_keep = 0; 44961800ad25SSagar Arun Kamble 44971800ad25SSagar Arun Kamble /* 44981800ad25SSagar Arun Kamble * SNB,IVB can while VLV,CHV may hard hang on looping batchbuffer 44991800ad25SSagar Arun Kamble * if GEN6_PM_UP_EI_EXPIRED is masked. 45001800ad25SSagar Arun Kamble * 45011800ad25SSagar Arun Kamble * TODO: verify if this can be reproduced on VLV,CHV. 45021800ad25SSagar Arun Kamble */ 45031800ad25SSagar Arun Kamble if (INTEL_INFO(dev_priv)->gen <= 7 && !IS_HASWELL(dev_priv)) 45041800ad25SSagar Arun Kamble dev_priv->rps.pm_intr_keep |= GEN6_PM_RP_UP_EI_EXPIRED; 45051800ad25SSagar Arun Kamble 45061800ad25SSagar Arun Kamble if (INTEL_INFO(dev_priv)->gen >= 8) 45071800ad25SSagar Arun Kamble dev_priv->rps.pm_intr_keep |= GEN8_PMINTR_REDIRECT_TO_NON_DISP; 45081800ad25SSagar Arun Kamble 4509737b1506SChris Wilson INIT_DELAYED_WORK(&dev_priv->gpu_error.hangcheck_work, 4510737b1506SChris Wilson i915_hangcheck_elapsed); 451161bac78eSDaniel Vetter 4512b963291cSDaniel Vetter if (IS_GEN2(dev_priv)) { 45134194c088SRodrigo Vivi /* Gen2 doesn't have a hardware frame counter */ 45144cdb83ecSVille Syrjälä dev->max_vblank_count = 0; 45154194c088SRodrigo Vivi dev->driver->get_vblank_counter = drm_vblank_no_hw_counter; 4516b963291cSDaniel Vetter } else if (IS_G4X(dev_priv) || INTEL_INFO(dev_priv)->gen >= 5) { 4517f71d4af4SJesse Barnes dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */ 4518fd8f507cSVille Syrjälä dev->driver->get_vblank_counter = g4x_get_vblank_counter; 4519391f75e2SVille Syrjälä } else { 4520391f75e2SVille Syrjälä dev->driver->get_vblank_counter = i915_get_vblank_counter; 4521391f75e2SVille Syrjälä dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ 4522f71d4af4SJesse Barnes } 4523f71d4af4SJesse Barnes 452421da2700SVille Syrjälä /* 452521da2700SVille Syrjälä * Opt out of the vblank disable timer on everything except gen2. 452621da2700SVille Syrjälä * Gen2 doesn't have a hardware frame counter and so depends on 452721da2700SVille Syrjälä * vblank interrupts to produce sane vblank seuquence numbers. 452821da2700SVille Syrjälä */ 4529b963291cSDaniel Vetter if (!IS_GEN2(dev_priv)) 453021da2700SVille Syrjälä dev->vblank_disable_immediate = true; 453121da2700SVille Syrjälä 4532f71d4af4SJesse Barnes dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp; 4533f71d4af4SJesse Barnes dev->driver->get_scanout_position = i915_get_crtc_scanoutpos; 4534f71d4af4SJesse Barnes 4535b963291cSDaniel Vetter if (IS_CHERRYVIEW(dev_priv)) { 453643f328d7SVille Syrjälä dev->driver->irq_handler = cherryview_irq_handler; 453743f328d7SVille Syrjälä dev->driver->irq_preinstall = cherryview_irq_preinstall; 453843f328d7SVille Syrjälä dev->driver->irq_postinstall = cherryview_irq_postinstall; 453943f328d7SVille Syrjälä dev->driver->irq_uninstall = cherryview_irq_uninstall; 454043f328d7SVille Syrjälä dev->driver->enable_vblank = valleyview_enable_vblank; 454143f328d7SVille Syrjälä dev->driver->disable_vblank = valleyview_disable_vblank; 454243f328d7SVille Syrjälä dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 4543b963291cSDaniel Vetter } else if (IS_VALLEYVIEW(dev_priv)) { 45447e231dbeSJesse Barnes dev->driver->irq_handler = valleyview_irq_handler; 45457e231dbeSJesse Barnes dev->driver->irq_preinstall = valleyview_irq_preinstall; 45467e231dbeSJesse Barnes dev->driver->irq_postinstall = valleyview_irq_postinstall; 45477e231dbeSJesse Barnes dev->driver->irq_uninstall = valleyview_irq_uninstall; 45487e231dbeSJesse Barnes dev->driver->enable_vblank = valleyview_enable_vblank; 45497e231dbeSJesse Barnes dev->driver->disable_vblank = valleyview_disable_vblank; 4550fa00abe0SEgbert Eich dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 4551b963291cSDaniel Vetter } else if (INTEL_INFO(dev_priv)->gen >= 8) { 4552abd58f01SBen Widawsky dev->driver->irq_handler = gen8_irq_handler; 4553723761b8SDaniel Vetter dev->driver->irq_preinstall = gen8_irq_reset; 4554abd58f01SBen Widawsky dev->driver->irq_postinstall = gen8_irq_postinstall; 4555abd58f01SBen Widawsky dev->driver->irq_uninstall = gen8_irq_uninstall; 4556abd58f01SBen Widawsky dev->driver->enable_vblank = gen8_enable_vblank; 4557abd58f01SBen Widawsky dev->driver->disable_vblank = gen8_disable_vblank; 45586dbf30ceSVille Syrjälä if (IS_BROXTON(dev)) 4559e0a20ad7SShashank Sharma dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup; 456022dea0beSRodrigo Vivi else if (HAS_PCH_SPT(dev) || HAS_PCH_KBP(dev)) 45616dbf30ceSVille Syrjälä dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup; 45626dbf30ceSVille Syrjälä else 45633a3b3c7dSVille Syrjälä dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup; 4564f71d4af4SJesse Barnes } else if (HAS_PCH_SPLIT(dev)) { 4565f71d4af4SJesse Barnes dev->driver->irq_handler = ironlake_irq_handler; 4566723761b8SDaniel Vetter dev->driver->irq_preinstall = ironlake_irq_reset; 4567f71d4af4SJesse Barnes dev->driver->irq_postinstall = ironlake_irq_postinstall; 4568f71d4af4SJesse Barnes dev->driver->irq_uninstall = ironlake_irq_uninstall; 4569f71d4af4SJesse Barnes dev->driver->enable_vblank = ironlake_enable_vblank; 4570f71d4af4SJesse Barnes dev->driver->disable_vblank = ironlake_disable_vblank; 4571e4ce95aaSVille Syrjälä dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup; 4572f71d4af4SJesse Barnes } else { 45737e22dbbbSTvrtko Ursulin if (IS_GEN2(dev_priv)) { 4574c2798b19SChris Wilson dev->driver->irq_preinstall = i8xx_irq_preinstall; 4575c2798b19SChris Wilson dev->driver->irq_postinstall = i8xx_irq_postinstall; 4576c2798b19SChris Wilson dev->driver->irq_handler = i8xx_irq_handler; 4577c2798b19SChris Wilson dev->driver->irq_uninstall = i8xx_irq_uninstall; 45787e22dbbbSTvrtko Ursulin } else if (IS_GEN3(dev_priv)) { 4579a266c7d5SChris Wilson dev->driver->irq_preinstall = i915_irq_preinstall; 4580a266c7d5SChris Wilson dev->driver->irq_postinstall = i915_irq_postinstall; 4581a266c7d5SChris Wilson dev->driver->irq_uninstall = i915_irq_uninstall; 4582a266c7d5SChris Wilson dev->driver->irq_handler = i915_irq_handler; 4583c2798b19SChris Wilson } else { 4584a266c7d5SChris Wilson dev->driver->irq_preinstall = i965_irq_preinstall; 4585a266c7d5SChris Wilson dev->driver->irq_postinstall = i965_irq_postinstall; 4586a266c7d5SChris Wilson dev->driver->irq_uninstall = i965_irq_uninstall; 4587a266c7d5SChris Wilson dev->driver->irq_handler = i965_irq_handler; 4588c2798b19SChris Wilson } 4589778eb334SVille Syrjälä if (I915_HAS_HOTPLUG(dev_priv)) 4590778eb334SVille Syrjälä dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 4591f71d4af4SJesse Barnes dev->driver->enable_vblank = i915_enable_vblank; 4592f71d4af4SJesse Barnes dev->driver->disable_vblank = i915_disable_vblank; 4593f71d4af4SJesse Barnes } 4594f71d4af4SJesse Barnes } 459520afbda2SDaniel Vetter 4596fca52a55SDaniel Vetter /** 4597fca52a55SDaniel Vetter * intel_irq_install - enables the hardware interrupt 4598fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4599fca52a55SDaniel Vetter * 4600fca52a55SDaniel Vetter * This function enables the hardware interrupt handling, but leaves the hotplug 4601fca52a55SDaniel Vetter * handling still disabled. It is called after intel_irq_init(). 4602fca52a55SDaniel Vetter * 4603fca52a55SDaniel Vetter * In the driver load and resume code we need working interrupts in a few places 4604fca52a55SDaniel Vetter * but don't want to deal with the hassle of concurrent probe and hotplug 4605fca52a55SDaniel Vetter * workers. Hence the split into this two-stage approach. 4606fca52a55SDaniel Vetter */ 46072aeb7d3aSDaniel Vetter int intel_irq_install(struct drm_i915_private *dev_priv) 46082aeb7d3aSDaniel Vetter { 46092aeb7d3aSDaniel Vetter /* 46102aeb7d3aSDaniel Vetter * We enable some interrupt sources in our postinstall hooks, so mark 46112aeb7d3aSDaniel Vetter * interrupts as enabled _before_ actually enabling them to avoid 46122aeb7d3aSDaniel Vetter * special cases in our ordering checks. 46132aeb7d3aSDaniel Vetter */ 46142aeb7d3aSDaniel Vetter dev_priv->pm.irqs_enabled = true; 46152aeb7d3aSDaniel Vetter 461691c8a326SChris Wilson return drm_irq_install(&dev_priv->drm, dev_priv->drm.pdev->irq); 46172aeb7d3aSDaniel Vetter } 46182aeb7d3aSDaniel Vetter 4619fca52a55SDaniel Vetter /** 4620fca52a55SDaniel Vetter * intel_irq_uninstall - finilizes all irq handling 4621fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4622fca52a55SDaniel Vetter * 4623fca52a55SDaniel Vetter * This stops interrupt and hotplug handling and unregisters and frees all 4624fca52a55SDaniel Vetter * resources acquired in the init functions. 4625fca52a55SDaniel Vetter */ 46262aeb7d3aSDaniel Vetter void intel_irq_uninstall(struct drm_i915_private *dev_priv) 46272aeb7d3aSDaniel Vetter { 462891c8a326SChris Wilson drm_irq_uninstall(&dev_priv->drm); 46292aeb7d3aSDaniel Vetter intel_hpd_cancel_work(dev_priv); 46302aeb7d3aSDaniel Vetter dev_priv->pm.irqs_enabled = false; 46312aeb7d3aSDaniel Vetter } 46322aeb7d3aSDaniel Vetter 4633fca52a55SDaniel Vetter /** 4634fca52a55SDaniel Vetter * intel_runtime_pm_disable_interrupts - runtime interrupt disabling 4635fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4636fca52a55SDaniel Vetter * 4637fca52a55SDaniel Vetter * This function is used to disable interrupts at runtime, both in the runtime 4638fca52a55SDaniel Vetter * pm and the system suspend/resume code. 4639fca52a55SDaniel Vetter */ 4640b963291cSDaniel Vetter void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv) 4641c67a470bSPaulo Zanoni { 464291c8a326SChris Wilson dev_priv->drm.driver->irq_uninstall(&dev_priv->drm); 46432aeb7d3aSDaniel Vetter dev_priv->pm.irqs_enabled = false; 464491c8a326SChris Wilson synchronize_irq(dev_priv->drm.irq); 4645c67a470bSPaulo Zanoni } 4646c67a470bSPaulo Zanoni 4647fca52a55SDaniel Vetter /** 4648fca52a55SDaniel Vetter * intel_runtime_pm_enable_interrupts - runtime interrupt enabling 4649fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4650fca52a55SDaniel Vetter * 4651fca52a55SDaniel Vetter * This function is used to enable interrupts at runtime, both in the runtime 4652fca52a55SDaniel Vetter * pm and the system suspend/resume code. 4653fca52a55SDaniel Vetter */ 4654b963291cSDaniel Vetter void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv) 4655c67a470bSPaulo Zanoni { 46562aeb7d3aSDaniel Vetter dev_priv->pm.irqs_enabled = true; 465791c8a326SChris Wilson dev_priv->drm.driver->irq_preinstall(&dev_priv->drm); 465891c8a326SChris Wilson dev_priv->drm.driver->irq_postinstall(&dev_priv->drm); 4659c67a470bSPaulo Zanoni } 4660