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 48e5868a31SEgbert Eich static const u32 hpd_ibx[] = { 49e5868a31SEgbert Eich [HPD_CRT] = SDE_CRT_HOTPLUG, 50e5868a31SEgbert Eich [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG, 51e5868a31SEgbert Eich [HPD_PORT_B] = SDE_PORTB_HOTPLUG, 52e5868a31SEgbert Eich [HPD_PORT_C] = SDE_PORTC_HOTPLUG, 53e5868a31SEgbert Eich [HPD_PORT_D] = SDE_PORTD_HOTPLUG 54e5868a31SEgbert Eich }; 55e5868a31SEgbert Eich 56e5868a31SEgbert Eich static const u32 hpd_cpt[] = { 57e5868a31SEgbert Eich [HPD_CRT] = SDE_CRT_HOTPLUG_CPT, 5873c352a2SDaniel Vetter [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT, 59e5868a31SEgbert Eich [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT, 60e5868a31SEgbert Eich [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT, 61e5868a31SEgbert Eich [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT 62e5868a31SEgbert Eich }; 63e5868a31SEgbert Eich 64e5868a31SEgbert Eich static const u32 hpd_mask_i915[] = { 65e5868a31SEgbert Eich [HPD_CRT] = CRT_HOTPLUG_INT_EN, 66e5868a31SEgbert Eich [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN, 67e5868a31SEgbert Eich [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN, 68e5868a31SEgbert Eich [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN, 69e5868a31SEgbert Eich [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN, 70e5868a31SEgbert Eich [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN 71e5868a31SEgbert Eich }; 72e5868a31SEgbert Eich 73704cfb87SDaniel Vetter static const u32 hpd_status_g4x[] = { 74e5868a31SEgbert Eich [HPD_CRT] = CRT_HOTPLUG_INT_STATUS, 75e5868a31SEgbert Eich [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X, 76e5868a31SEgbert Eich [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X, 77e5868a31SEgbert Eich [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS, 78e5868a31SEgbert Eich [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS, 79e5868a31SEgbert Eich [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS 80e5868a31SEgbert Eich }; 81e5868a31SEgbert Eich 82e5868a31SEgbert Eich static const u32 hpd_status_i915[] = { /* i915 and valleyview are the same */ 83e5868a31SEgbert Eich [HPD_CRT] = CRT_HOTPLUG_INT_STATUS, 84e5868a31SEgbert Eich [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915, 85e5868a31SEgbert Eich [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915, 86e5868a31SEgbert Eich [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS, 87e5868a31SEgbert Eich [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS, 88e5868a31SEgbert Eich [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS 89e5868a31SEgbert Eich }; 90e5868a31SEgbert Eich 915c502442SPaulo Zanoni /* IIR can theoretically queue up two events. Be paranoid. */ 92f86f3fb0SPaulo Zanoni #define GEN8_IRQ_RESET_NDX(type, which) do { \ 935c502442SPaulo Zanoni I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \ 945c502442SPaulo Zanoni POSTING_READ(GEN8_##type##_IMR(which)); \ 955c502442SPaulo Zanoni I915_WRITE(GEN8_##type##_IER(which), 0); \ 965c502442SPaulo Zanoni I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \ 975c502442SPaulo Zanoni POSTING_READ(GEN8_##type##_IIR(which)); \ 985c502442SPaulo Zanoni I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \ 995c502442SPaulo Zanoni POSTING_READ(GEN8_##type##_IIR(which)); \ 1005c502442SPaulo Zanoni } while (0) 1015c502442SPaulo Zanoni 102f86f3fb0SPaulo Zanoni #define GEN5_IRQ_RESET(type) do { \ 103a9d356a6SPaulo Zanoni I915_WRITE(type##IMR, 0xffffffff); \ 1045c502442SPaulo Zanoni POSTING_READ(type##IMR); \ 105a9d356a6SPaulo Zanoni I915_WRITE(type##IER, 0); \ 1065c502442SPaulo Zanoni I915_WRITE(type##IIR, 0xffffffff); \ 1075c502442SPaulo Zanoni POSTING_READ(type##IIR); \ 1085c502442SPaulo Zanoni I915_WRITE(type##IIR, 0xffffffff); \ 1095c502442SPaulo Zanoni POSTING_READ(type##IIR); \ 110a9d356a6SPaulo Zanoni } while (0) 111a9d356a6SPaulo Zanoni 112337ba017SPaulo Zanoni /* 113337ba017SPaulo Zanoni * We should clear IMR at preinstall/uninstall, and just check at postinstall. 114337ba017SPaulo Zanoni */ 115337ba017SPaulo Zanoni #define GEN5_ASSERT_IIR_IS_ZERO(reg) do { \ 116337ba017SPaulo Zanoni u32 val = I915_READ(reg); \ 117337ba017SPaulo Zanoni if (val) { \ 118337ba017SPaulo Zanoni WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n", \ 119337ba017SPaulo Zanoni (reg), val); \ 120337ba017SPaulo Zanoni I915_WRITE((reg), 0xffffffff); \ 121337ba017SPaulo Zanoni POSTING_READ(reg); \ 122337ba017SPaulo Zanoni I915_WRITE((reg), 0xffffffff); \ 123337ba017SPaulo Zanoni POSTING_READ(reg); \ 124337ba017SPaulo Zanoni } \ 125337ba017SPaulo Zanoni } while (0) 126337ba017SPaulo Zanoni 12735079899SPaulo Zanoni #define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \ 128337ba017SPaulo Zanoni GEN5_ASSERT_IIR_IS_ZERO(GEN8_##type##_IIR(which)); \ 12935079899SPaulo Zanoni I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \ 1307d1bd539SVille Syrjälä I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \ 1317d1bd539SVille Syrjälä POSTING_READ(GEN8_##type##_IMR(which)); \ 13235079899SPaulo Zanoni } while (0) 13335079899SPaulo Zanoni 13435079899SPaulo Zanoni #define GEN5_IRQ_INIT(type, imr_val, ier_val) do { \ 135337ba017SPaulo Zanoni GEN5_ASSERT_IIR_IS_ZERO(type##IIR); \ 13635079899SPaulo Zanoni I915_WRITE(type##IER, (ier_val)); \ 1377d1bd539SVille Syrjälä I915_WRITE(type##IMR, (imr_val)); \ 1387d1bd539SVille Syrjälä POSTING_READ(type##IMR); \ 13935079899SPaulo Zanoni } while (0) 14035079899SPaulo Zanoni 141c9a9a268SImre Deak static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir); 142c9a9a268SImre Deak 143036a4a7dSZhenyu Wang /* For display hotplug interrupt */ 14447339cd9SDaniel Vetter void 1452d1013ddSJani Nikula ironlake_enable_display_irq(struct drm_i915_private *dev_priv, u32 mask) 146036a4a7dSZhenyu Wang { 1474bc9d430SDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 1484bc9d430SDaniel Vetter 1499df7575fSJesse Barnes if (WARN_ON(!intel_irqs_enabled(dev_priv))) 150c67a470bSPaulo Zanoni return; 151c67a470bSPaulo Zanoni 1521ec14ad3SChris Wilson if ((dev_priv->irq_mask & mask) != 0) { 1531ec14ad3SChris Wilson dev_priv->irq_mask &= ~mask; 1541ec14ad3SChris Wilson I915_WRITE(DEIMR, dev_priv->irq_mask); 1553143a2bfSChris Wilson POSTING_READ(DEIMR); 156036a4a7dSZhenyu Wang } 157036a4a7dSZhenyu Wang } 158036a4a7dSZhenyu Wang 15947339cd9SDaniel Vetter void 1602d1013ddSJani Nikula ironlake_disable_display_irq(struct drm_i915_private *dev_priv, u32 mask) 161036a4a7dSZhenyu Wang { 1624bc9d430SDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 1634bc9d430SDaniel Vetter 16406ffc778SPaulo Zanoni if (WARN_ON(!intel_irqs_enabled(dev_priv))) 165c67a470bSPaulo Zanoni return; 166c67a470bSPaulo Zanoni 1671ec14ad3SChris Wilson if ((dev_priv->irq_mask & mask) != mask) { 1681ec14ad3SChris Wilson dev_priv->irq_mask |= mask; 1691ec14ad3SChris Wilson I915_WRITE(DEIMR, dev_priv->irq_mask); 1703143a2bfSChris Wilson POSTING_READ(DEIMR); 171036a4a7dSZhenyu Wang } 172036a4a7dSZhenyu Wang } 173036a4a7dSZhenyu Wang 17443eaea13SPaulo Zanoni /** 17543eaea13SPaulo Zanoni * ilk_update_gt_irq - update GTIMR 17643eaea13SPaulo Zanoni * @dev_priv: driver private 17743eaea13SPaulo Zanoni * @interrupt_mask: mask of interrupt bits to update 17843eaea13SPaulo Zanoni * @enabled_irq_mask: mask of interrupt bits to enable 17943eaea13SPaulo Zanoni */ 18043eaea13SPaulo Zanoni static void ilk_update_gt_irq(struct drm_i915_private *dev_priv, 18143eaea13SPaulo Zanoni uint32_t interrupt_mask, 18243eaea13SPaulo Zanoni uint32_t enabled_irq_mask) 18343eaea13SPaulo Zanoni { 18443eaea13SPaulo Zanoni assert_spin_locked(&dev_priv->irq_lock); 18543eaea13SPaulo Zanoni 1869df7575fSJesse Barnes if (WARN_ON(!intel_irqs_enabled(dev_priv))) 187c67a470bSPaulo Zanoni return; 188c67a470bSPaulo Zanoni 18943eaea13SPaulo Zanoni dev_priv->gt_irq_mask &= ~interrupt_mask; 19043eaea13SPaulo Zanoni dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask); 19143eaea13SPaulo Zanoni I915_WRITE(GTIMR, dev_priv->gt_irq_mask); 19243eaea13SPaulo Zanoni POSTING_READ(GTIMR); 19343eaea13SPaulo Zanoni } 19443eaea13SPaulo Zanoni 195480c8033SDaniel Vetter void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask) 19643eaea13SPaulo Zanoni { 19743eaea13SPaulo Zanoni ilk_update_gt_irq(dev_priv, mask, mask); 19843eaea13SPaulo Zanoni } 19943eaea13SPaulo Zanoni 200480c8033SDaniel Vetter void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask) 20143eaea13SPaulo Zanoni { 20243eaea13SPaulo Zanoni ilk_update_gt_irq(dev_priv, mask, 0); 20343eaea13SPaulo Zanoni } 20443eaea13SPaulo Zanoni 205b900b949SImre Deak static u32 gen6_pm_iir(struct drm_i915_private *dev_priv) 206b900b949SImre Deak { 207b900b949SImre Deak return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR; 208b900b949SImre Deak } 209b900b949SImre Deak 210a72fbc3aSImre Deak static u32 gen6_pm_imr(struct drm_i915_private *dev_priv) 211a72fbc3aSImre Deak { 212a72fbc3aSImre Deak return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IMR(2) : GEN6_PMIMR; 213a72fbc3aSImre Deak } 214a72fbc3aSImre Deak 215b900b949SImre Deak static u32 gen6_pm_ier(struct drm_i915_private *dev_priv) 216b900b949SImre Deak { 217b900b949SImre Deak return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IER(2) : GEN6_PMIER; 218b900b949SImre Deak } 219b900b949SImre Deak 220edbfdb45SPaulo Zanoni /** 221edbfdb45SPaulo Zanoni * snb_update_pm_irq - update GEN6_PMIMR 222edbfdb45SPaulo Zanoni * @dev_priv: driver private 223edbfdb45SPaulo Zanoni * @interrupt_mask: mask of interrupt bits to update 224edbfdb45SPaulo Zanoni * @enabled_irq_mask: mask of interrupt bits to enable 225edbfdb45SPaulo Zanoni */ 226edbfdb45SPaulo Zanoni static void snb_update_pm_irq(struct drm_i915_private *dev_priv, 227edbfdb45SPaulo Zanoni uint32_t interrupt_mask, 228edbfdb45SPaulo Zanoni uint32_t enabled_irq_mask) 229edbfdb45SPaulo Zanoni { 230605cd25bSPaulo Zanoni uint32_t new_val; 231edbfdb45SPaulo Zanoni 232edbfdb45SPaulo Zanoni assert_spin_locked(&dev_priv->irq_lock); 233edbfdb45SPaulo Zanoni 2349df7575fSJesse Barnes if (WARN_ON(!intel_irqs_enabled(dev_priv))) 235c67a470bSPaulo Zanoni return; 236c67a470bSPaulo Zanoni 237605cd25bSPaulo Zanoni new_val = dev_priv->pm_irq_mask; 238f52ecbcfSPaulo Zanoni new_val &= ~interrupt_mask; 239f52ecbcfSPaulo Zanoni new_val |= (~enabled_irq_mask & interrupt_mask); 240f52ecbcfSPaulo Zanoni 241605cd25bSPaulo Zanoni if (new_val != dev_priv->pm_irq_mask) { 242605cd25bSPaulo Zanoni dev_priv->pm_irq_mask = new_val; 243a72fbc3aSImre Deak I915_WRITE(gen6_pm_imr(dev_priv), dev_priv->pm_irq_mask); 244a72fbc3aSImre Deak POSTING_READ(gen6_pm_imr(dev_priv)); 245edbfdb45SPaulo Zanoni } 246f52ecbcfSPaulo Zanoni } 247edbfdb45SPaulo Zanoni 248480c8033SDaniel Vetter void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask) 249edbfdb45SPaulo Zanoni { 250edbfdb45SPaulo Zanoni snb_update_pm_irq(dev_priv, mask, mask); 251edbfdb45SPaulo Zanoni } 252edbfdb45SPaulo Zanoni 253480c8033SDaniel Vetter void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask) 254edbfdb45SPaulo Zanoni { 255edbfdb45SPaulo Zanoni snb_update_pm_irq(dev_priv, mask, 0); 256edbfdb45SPaulo Zanoni } 257edbfdb45SPaulo Zanoni 258b900b949SImre Deak void gen6_enable_rps_interrupts(struct drm_device *dev) 259b900b949SImre Deak { 260b900b949SImre Deak struct drm_i915_private *dev_priv = dev->dev_private; 261b900b949SImre Deak 262b900b949SImre Deak spin_lock_irq(&dev_priv->irq_lock); 263b900b949SImre Deak WARN_ON(dev_priv->rps.pm_iir); 264b900b949SImre Deak gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events); 265b900b949SImre Deak I915_WRITE(gen6_pm_iir(dev_priv), dev_priv->pm_rps_events); 266b900b949SImre Deak spin_unlock_irq(&dev_priv->irq_lock); 267b900b949SImre Deak } 268b900b949SImre Deak 269b900b949SImre Deak void gen6_disable_rps_interrupts(struct drm_device *dev) 270b900b949SImre Deak { 271b900b949SImre Deak struct drm_i915_private *dev_priv = dev->dev_private; 272b900b949SImre Deak 273b900b949SImre Deak I915_WRITE(GEN6_PMINTRMSK, INTEL_INFO(dev_priv)->gen >= 8 ? 274b900b949SImre Deak ~GEN8_PMINTR_REDIRECT_TO_NON_DISP : ~0); 275b900b949SImre Deak I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) & 276b900b949SImre Deak ~dev_priv->pm_rps_events); 277b900b949SImre Deak /* Complete PM interrupt masking here doesn't race with the rps work 278b900b949SImre Deak * item again unmasking PM interrupts because that is using a different 279b900b949SImre Deak * register (PMIMR) to mask PM interrupts. The only risk is in leaving 280b900b949SImre Deak * stale bits in PMIIR and PMIMR which gen6_enable_rps will clean up. */ 281b900b949SImre Deak 282b900b949SImre Deak spin_lock_irq(&dev_priv->irq_lock); 283b900b949SImre Deak dev_priv->rps.pm_iir = 0; 284b900b949SImre Deak spin_unlock_irq(&dev_priv->irq_lock); 285b900b949SImre Deak 286b900b949SImre Deak I915_WRITE(gen6_pm_iir(dev_priv), dev_priv->pm_rps_events); 287b900b949SImre Deak } 288b900b949SImre Deak 2890961021aSBen Widawsky /** 290fee884edSDaniel Vetter * ibx_display_interrupt_update - update SDEIMR 291fee884edSDaniel Vetter * @dev_priv: driver private 292fee884edSDaniel Vetter * @interrupt_mask: mask of interrupt bits to update 293fee884edSDaniel Vetter * @enabled_irq_mask: mask of interrupt bits to enable 294fee884edSDaniel Vetter */ 29547339cd9SDaniel Vetter void ibx_display_interrupt_update(struct drm_i915_private *dev_priv, 296fee884edSDaniel Vetter uint32_t interrupt_mask, 297fee884edSDaniel Vetter uint32_t enabled_irq_mask) 298fee884edSDaniel Vetter { 299fee884edSDaniel Vetter uint32_t sdeimr = I915_READ(SDEIMR); 300fee884edSDaniel Vetter sdeimr &= ~interrupt_mask; 301fee884edSDaniel Vetter sdeimr |= (~enabled_irq_mask & interrupt_mask); 302fee884edSDaniel Vetter 303fee884edSDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 304fee884edSDaniel Vetter 3059df7575fSJesse Barnes if (WARN_ON(!intel_irqs_enabled(dev_priv))) 306c67a470bSPaulo Zanoni return; 307c67a470bSPaulo Zanoni 308fee884edSDaniel Vetter I915_WRITE(SDEIMR, sdeimr); 309fee884edSDaniel Vetter POSTING_READ(SDEIMR); 310fee884edSDaniel Vetter } 3118664281bSPaulo Zanoni 312b5ea642aSDaniel Vetter static void 313755e9019SImre Deak __i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 314755e9019SImre Deak u32 enable_mask, u32 status_mask) 3157c463586SKeith Packard { 3169db4a9c7SJesse Barnes u32 reg = PIPESTAT(pipe); 317755e9019SImre Deak u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK; 3187c463586SKeith Packard 319b79480baSDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 320d518ce50SDaniel Vetter WARN_ON(!intel_irqs_enabled(dev_priv)); 321b79480baSDaniel Vetter 32204feced9SVille Syrjälä if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK || 32304feced9SVille Syrjälä status_mask & ~PIPESTAT_INT_STATUS_MASK, 32404feced9SVille Syrjälä "pipe %c: enable_mask=0x%x, status_mask=0x%x\n", 32504feced9SVille Syrjälä pipe_name(pipe), enable_mask, status_mask)) 326755e9019SImre Deak return; 327755e9019SImre Deak 328755e9019SImre Deak if ((pipestat & enable_mask) == enable_mask) 32946c06a30SVille Syrjälä return; 33046c06a30SVille Syrjälä 33191d181ddSImre Deak dev_priv->pipestat_irq_mask[pipe] |= status_mask; 33291d181ddSImre Deak 3337c463586SKeith Packard /* Enable the interrupt, clear any pending status */ 334755e9019SImre Deak pipestat |= enable_mask | status_mask; 33546c06a30SVille Syrjälä I915_WRITE(reg, pipestat); 3363143a2bfSChris Wilson POSTING_READ(reg); 3377c463586SKeith Packard } 3387c463586SKeith Packard 339b5ea642aSDaniel Vetter static void 340755e9019SImre Deak __i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 341755e9019SImre Deak u32 enable_mask, u32 status_mask) 3427c463586SKeith Packard { 3439db4a9c7SJesse Barnes u32 reg = PIPESTAT(pipe); 344755e9019SImre Deak u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK; 3457c463586SKeith Packard 346b79480baSDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 347d518ce50SDaniel Vetter WARN_ON(!intel_irqs_enabled(dev_priv)); 348b79480baSDaniel Vetter 34904feced9SVille Syrjälä if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK || 35004feced9SVille Syrjälä status_mask & ~PIPESTAT_INT_STATUS_MASK, 35104feced9SVille Syrjälä "pipe %c: enable_mask=0x%x, status_mask=0x%x\n", 35204feced9SVille Syrjälä pipe_name(pipe), enable_mask, status_mask)) 35346c06a30SVille Syrjälä return; 35446c06a30SVille Syrjälä 355755e9019SImre Deak if ((pipestat & enable_mask) == 0) 356755e9019SImre Deak return; 357755e9019SImre Deak 35891d181ddSImre Deak dev_priv->pipestat_irq_mask[pipe] &= ~status_mask; 35991d181ddSImre Deak 360755e9019SImre Deak pipestat &= ~enable_mask; 36146c06a30SVille Syrjälä I915_WRITE(reg, pipestat); 3623143a2bfSChris Wilson POSTING_READ(reg); 3637c463586SKeith Packard } 3647c463586SKeith Packard 36510c59c51SImre Deak static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask) 36610c59c51SImre Deak { 36710c59c51SImre Deak u32 enable_mask = status_mask << 16; 36810c59c51SImre Deak 36910c59c51SImre Deak /* 370724a6905SVille Syrjälä * On pipe A we don't support the PSR interrupt yet, 371724a6905SVille Syrjälä * on pipe B and C the same bit MBZ. 37210c59c51SImre Deak */ 37310c59c51SImre Deak if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV)) 37410c59c51SImre Deak return 0; 375724a6905SVille Syrjälä /* 376724a6905SVille Syrjälä * On pipe B and C we don't support the PSR interrupt yet, on pipe 377724a6905SVille Syrjälä * A the same bit is for perf counters which we don't use either. 378724a6905SVille Syrjälä */ 379724a6905SVille Syrjälä if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV)) 380724a6905SVille Syrjälä return 0; 38110c59c51SImre Deak 38210c59c51SImre Deak enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS | 38310c59c51SImre Deak SPRITE0_FLIP_DONE_INT_EN_VLV | 38410c59c51SImre Deak SPRITE1_FLIP_DONE_INT_EN_VLV); 38510c59c51SImre Deak if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV) 38610c59c51SImre Deak enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV; 38710c59c51SImre Deak if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV) 38810c59c51SImre Deak enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV; 38910c59c51SImre Deak 39010c59c51SImre Deak return enable_mask; 39110c59c51SImre Deak } 39210c59c51SImre Deak 393755e9019SImre Deak void 394755e9019SImre Deak i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 395755e9019SImre Deak u32 status_mask) 396755e9019SImre Deak { 397755e9019SImre Deak u32 enable_mask; 398755e9019SImre Deak 39910c59c51SImre Deak if (IS_VALLEYVIEW(dev_priv->dev)) 40010c59c51SImre Deak enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev, 40110c59c51SImre Deak status_mask); 40210c59c51SImre Deak else 403755e9019SImre Deak enable_mask = status_mask << 16; 404755e9019SImre Deak __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask); 405755e9019SImre Deak } 406755e9019SImre Deak 407755e9019SImre Deak void 408755e9019SImre Deak i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 409755e9019SImre Deak u32 status_mask) 410755e9019SImre Deak { 411755e9019SImre Deak u32 enable_mask; 412755e9019SImre Deak 41310c59c51SImre Deak if (IS_VALLEYVIEW(dev_priv->dev)) 41410c59c51SImre Deak enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev, 41510c59c51SImre Deak status_mask); 41610c59c51SImre Deak else 417755e9019SImre Deak enable_mask = status_mask << 16; 418755e9019SImre Deak __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask); 419755e9019SImre Deak } 420755e9019SImre Deak 421c0e09200SDave Airlie /** 422f49e38ddSJani Nikula * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion 42301c66889SZhao Yakui */ 424f49e38ddSJani Nikula static void i915_enable_asle_pipestat(struct drm_device *dev) 42501c66889SZhao Yakui { 4262d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 4271ec14ad3SChris Wilson 428f49e38ddSJani Nikula if (!dev_priv->opregion.asle || !IS_MOBILE(dev)) 429f49e38ddSJani Nikula return; 430f49e38ddSJani Nikula 43113321786SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 43201c66889SZhao Yakui 433755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS); 434a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen >= 4) 4353b6c42e8SDaniel Vetter i915_enable_pipestat(dev_priv, PIPE_A, 436755e9019SImre Deak PIPE_LEGACY_BLC_EVENT_STATUS); 4371ec14ad3SChris Wilson 43813321786SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 43901c66889SZhao Yakui } 44001c66889SZhao Yakui 44101c66889SZhao Yakui /** 4420a3e67a4SJesse Barnes * i915_pipe_enabled - check if a pipe is enabled 4430a3e67a4SJesse Barnes * @dev: DRM device 4440a3e67a4SJesse Barnes * @pipe: pipe to check 4450a3e67a4SJesse Barnes * 4460a3e67a4SJesse Barnes * Reading certain registers when the pipe is disabled can hang the chip. 4470a3e67a4SJesse Barnes * Use this routine to make sure the PLL is running and the pipe is active 4480a3e67a4SJesse Barnes * before reading such registers if unsure. 4490a3e67a4SJesse Barnes */ 4500a3e67a4SJesse Barnes static int 4510a3e67a4SJesse Barnes i915_pipe_enabled(struct drm_device *dev, int pipe) 4520a3e67a4SJesse Barnes { 4532d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 454702e7a56SPaulo Zanoni 455a01025afSDaniel Vetter if (drm_core_check_feature(dev, DRIVER_MODESET)) { 456a01025afSDaniel Vetter /* Locking is horribly broken here, but whatever. */ 457a01025afSDaniel Vetter struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 458a01025afSDaniel Vetter struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 45971f8ba6bSPaulo Zanoni 460a01025afSDaniel Vetter return intel_crtc->active; 461a01025afSDaniel Vetter } else { 462a01025afSDaniel Vetter return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE; 463a01025afSDaniel Vetter } 4640a3e67a4SJesse Barnes } 4650a3e67a4SJesse Barnes 466f75f3746SVille Syrjälä /* 467f75f3746SVille Syrjälä * This timing diagram depicts the video signal in and 468f75f3746SVille Syrjälä * around the vertical blanking period. 469f75f3746SVille Syrjälä * 470f75f3746SVille Syrjälä * Assumptions about the fictitious mode used in this example: 471f75f3746SVille Syrjälä * vblank_start >= 3 472f75f3746SVille Syrjälä * vsync_start = vblank_start + 1 473f75f3746SVille Syrjälä * vsync_end = vblank_start + 2 474f75f3746SVille Syrjälä * vtotal = vblank_start + 3 475f75f3746SVille Syrjälä * 476f75f3746SVille Syrjälä * start of vblank: 477f75f3746SVille Syrjälä * latch double buffered registers 478f75f3746SVille Syrjälä * increment frame counter (ctg+) 479f75f3746SVille Syrjälä * generate start of vblank interrupt (gen4+) 480f75f3746SVille Syrjälä * | 481f75f3746SVille Syrjälä * | frame start: 482f75f3746SVille Syrjälä * | generate frame start interrupt (aka. vblank interrupt) (gmch) 483f75f3746SVille Syrjälä * | may be shifted forward 1-3 extra lines via PIPECONF 484f75f3746SVille Syrjälä * | | 485f75f3746SVille Syrjälä * | | start of vsync: 486f75f3746SVille Syrjälä * | | generate vsync interrupt 487f75f3746SVille Syrjälä * | | | 488f75f3746SVille Syrjälä * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx 489f75f3746SVille Syrjälä * . \hs/ . \hs/ \hs/ \hs/ . \hs/ 490f75f3746SVille Syrjälä * ----va---> <-----------------vb--------------------> <--------va------------- 491f75f3746SVille Syrjälä * | | <----vs-----> | 492f75f3746SVille Syrjälä * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2) 493f75f3746SVille Syrjälä * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+) 494f75f3746SVille Syrjälä * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi) 495f75f3746SVille Syrjälä * | | | 496f75f3746SVille Syrjälä * last visible pixel first visible pixel 497f75f3746SVille Syrjälä * | increment frame counter (gen3/4) 498f75f3746SVille Syrjälä * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4) 499f75f3746SVille Syrjälä * 500f75f3746SVille Syrjälä * x = horizontal active 501f75f3746SVille Syrjälä * _ = horizontal blanking 502f75f3746SVille Syrjälä * hs = horizontal sync 503f75f3746SVille Syrjälä * va = vertical active 504f75f3746SVille Syrjälä * vb = vertical blanking 505f75f3746SVille Syrjälä * vs = vertical sync 506f75f3746SVille Syrjälä * vbs = vblank_start (number) 507f75f3746SVille Syrjälä * 508f75f3746SVille Syrjälä * Summary: 509f75f3746SVille Syrjälä * - most events happen at the start of horizontal sync 510f75f3746SVille Syrjälä * - frame start happens at the start of horizontal blank, 1-4 lines 511f75f3746SVille Syrjälä * (depending on PIPECONF settings) after the start of vblank 512f75f3746SVille Syrjälä * - gen3/4 pixel and frame counter are synchronized with the start 513f75f3746SVille Syrjälä * of horizontal active on the first line of vertical active 514f75f3746SVille Syrjälä */ 515f75f3746SVille Syrjälä 5164cdb83ecSVille Syrjälä static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe) 5174cdb83ecSVille Syrjälä { 5184cdb83ecSVille Syrjälä /* Gen2 doesn't have a hardware frame counter */ 5194cdb83ecSVille Syrjälä return 0; 5204cdb83ecSVille Syrjälä } 5214cdb83ecSVille Syrjälä 52242f52ef8SKeith Packard /* Called from drm generic code, passed a 'crtc', which 52342f52ef8SKeith Packard * we use as a pipe index 52442f52ef8SKeith Packard */ 525f71d4af4SJesse Barnes static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe) 5260a3e67a4SJesse Barnes { 5272d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 5280a3e67a4SJesse Barnes unsigned long high_frame; 5290a3e67a4SJesse Barnes unsigned long low_frame; 5300b2a8e09SVille Syrjälä u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal; 5310a3e67a4SJesse Barnes 5320a3e67a4SJesse Barnes if (!i915_pipe_enabled(dev, pipe)) { 53344d98a61SZhao Yakui DRM_DEBUG_DRIVER("trying to get vblank count for disabled " 5349db4a9c7SJesse Barnes "pipe %c\n", pipe_name(pipe)); 5350a3e67a4SJesse Barnes return 0; 5360a3e67a4SJesse Barnes } 5370a3e67a4SJesse Barnes 538391f75e2SVille Syrjälä if (drm_core_check_feature(dev, DRIVER_MODESET)) { 539391f75e2SVille Syrjälä struct intel_crtc *intel_crtc = 540391f75e2SVille Syrjälä to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); 541391f75e2SVille Syrjälä const struct drm_display_mode *mode = 542391f75e2SVille Syrjälä &intel_crtc->config.adjusted_mode; 543391f75e2SVille Syrjälä 5440b2a8e09SVille Syrjälä htotal = mode->crtc_htotal; 5450b2a8e09SVille Syrjälä hsync_start = mode->crtc_hsync_start; 5460b2a8e09SVille Syrjälä vbl_start = mode->crtc_vblank_start; 5470b2a8e09SVille Syrjälä if (mode->flags & DRM_MODE_FLAG_INTERLACE) 5480b2a8e09SVille Syrjälä vbl_start = DIV_ROUND_UP(vbl_start, 2); 549391f75e2SVille Syrjälä } else { 550a2d213ddSDaniel Vetter enum transcoder cpu_transcoder = (enum transcoder) pipe; 551391f75e2SVille Syrjälä 552391f75e2SVille Syrjälä htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1; 5530b2a8e09SVille Syrjälä hsync_start = (I915_READ(HSYNC(cpu_transcoder)) & 0x1fff) + 1; 554391f75e2SVille Syrjälä vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1; 5550b2a8e09SVille Syrjälä if ((I915_READ(PIPECONF(cpu_transcoder)) & 5560b2a8e09SVille Syrjälä PIPECONF_INTERLACE_MASK) != PIPECONF_PROGRESSIVE) 5570b2a8e09SVille Syrjälä vbl_start = DIV_ROUND_UP(vbl_start, 2); 558391f75e2SVille Syrjälä } 559391f75e2SVille Syrjälä 5600b2a8e09SVille Syrjälä /* Convert to pixel count */ 5610b2a8e09SVille Syrjälä vbl_start *= htotal; 5620b2a8e09SVille Syrjälä 5630b2a8e09SVille Syrjälä /* Start of vblank event occurs at start of hsync */ 5640b2a8e09SVille Syrjälä vbl_start -= htotal - hsync_start; 5650b2a8e09SVille Syrjälä 5669db4a9c7SJesse Barnes high_frame = PIPEFRAME(pipe); 5679db4a9c7SJesse Barnes low_frame = PIPEFRAMEPIXEL(pipe); 5685eddb70bSChris Wilson 5690a3e67a4SJesse Barnes /* 5700a3e67a4SJesse Barnes * High & low register fields aren't synchronized, so make sure 5710a3e67a4SJesse Barnes * we get a low value that's stable across two reads of the high 5720a3e67a4SJesse Barnes * register. 5730a3e67a4SJesse Barnes */ 5740a3e67a4SJesse Barnes do { 5755eddb70bSChris Wilson high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; 576391f75e2SVille Syrjälä low = I915_READ(low_frame); 5775eddb70bSChris Wilson high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; 5780a3e67a4SJesse Barnes } while (high1 != high2); 5790a3e67a4SJesse Barnes 5805eddb70bSChris Wilson high1 >>= PIPE_FRAME_HIGH_SHIFT; 581391f75e2SVille Syrjälä pixel = low & PIPE_PIXEL_MASK; 5825eddb70bSChris Wilson low >>= PIPE_FRAME_LOW_SHIFT; 583391f75e2SVille Syrjälä 584391f75e2SVille Syrjälä /* 585391f75e2SVille Syrjälä * The frame counter increments at beginning of active. 586391f75e2SVille Syrjälä * Cook up a vblank counter by also checking the pixel 587391f75e2SVille Syrjälä * counter against vblank start. 588391f75e2SVille Syrjälä */ 589edc08d0aSVille Syrjälä return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff; 5900a3e67a4SJesse Barnes } 5910a3e67a4SJesse Barnes 592f71d4af4SJesse Barnes static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe) 5939880b7a5SJesse Barnes { 5942d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 5959db4a9c7SJesse Barnes int reg = PIPE_FRMCOUNT_GM45(pipe); 5969880b7a5SJesse Barnes 5979880b7a5SJesse Barnes if (!i915_pipe_enabled(dev, pipe)) { 59844d98a61SZhao Yakui DRM_DEBUG_DRIVER("trying to get vblank count for disabled " 5999db4a9c7SJesse Barnes "pipe %c\n", pipe_name(pipe)); 6009880b7a5SJesse Barnes return 0; 6019880b7a5SJesse Barnes } 6029880b7a5SJesse Barnes 6039880b7a5SJesse Barnes return I915_READ(reg); 6049880b7a5SJesse Barnes } 6059880b7a5SJesse Barnes 606ad3543edSMario Kleiner /* raw reads, only for fast reads of display block, no need for forcewake etc. */ 607ad3543edSMario Kleiner #define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__)) 608ad3543edSMario Kleiner 609a225f079SVille Syrjälä static int __intel_get_crtc_scanline(struct intel_crtc *crtc) 610a225f079SVille Syrjälä { 611a225f079SVille Syrjälä struct drm_device *dev = crtc->base.dev; 612a225f079SVille Syrjälä struct drm_i915_private *dev_priv = dev->dev_private; 613a225f079SVille Syrjälä const struct drm_display_mode *mode = &crtc->config.adjusted_mode; 614a225f079SVille Syrjälä enum pipe pipe = crtc->pipe; 61580715b2fSVille Syrjälä int position, vtotal; 616a225f079SVille Syrjälä 61780715b2fSVille Syrjälä vtotal = mode->crtc_vtotal; 618a225f079SVille Syrjälä if (mode->flags & DRM_MODE_FLAG_INTERLACE) 619a225f079SVille Syrjälä vtotal /= 2; 620a225f079SVille Syrjälä 621a225f079SVille Syrjälä if (IS_GEN2(dev)) 622a225f079SVille Syrjälä position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2; 623a225f079SVille Syrjälä else 624a225f079SVille Syrjälä position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3; 625a225f079SVille Syrjälä 626a225f079SVille Syrjälä /* 62780715b2fSVille Syrjälä * See update_scanline_offset() for the details on the 62880715b2fSVille Syrjälä * scanline_offset adjustment. 629a225f079SVille Syrjälä */ 63080715b2fSVille Syrjälä return (position + crtc->scanline_offset) % vtotal; 631a225f079SVille Syrjälä } 632a225f079SVille Syrjälä 633f71d4af4SJesse Barnes static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe, 634abca9e45SVille Syrjälä unsigned int flags, int *vpos, int *hpos, 635abca9e45SVille Syrjälä ktime_t *stime, ktime_t *etime) 6360af7e4dfSMario Kleiner { 637c2baf4b7SVille Syrjälä struct drm_i915_private *dev_priv = dev->dev_private; 638c2baf4b7SVille Syrjälä struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 639c2baf4b7SVille Syrjälä struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 640c2baf4b7SVille Syrjälä const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode; 6413aa18df8SVille Syrjälä int position; 64278e8fc6bSVille Syrjälä int vbl_start, vbl_end, hsync_start, htotal, vtotal; 6430af7e4dfSMario Kleiner bool in_vbl = true; 6440af7e4dfSMario Kleiner int ret = 0; 645ad3543edSMario Kleiner unsigned long irqflags; 6460af7e4dfSMario Kleiner 647c2baf4b7SVille Syrjälä if (!intel_crtc->active) { 6480af7e4dfSMario Kleiner DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled " 6499db4a9c7SJesse Barnes "pipe %c\n", pipe_name(pipe)); 6500af7e4dfSMario Kleiner return 0; 6510af7e4dfSMario Kleiner } 6520af7e4dfSMario Kleiner 653c2baf4b7SVille Syrjälä htotal = mode->crtc_htotal; 65478e8fc6bSVille Syrjälä hsync_start = mode->crtc_hsync_start; 655c2baf4b7SVille Syrjälä vtotal = mode->crtc_vtotal; 656c2baf4b7SVille Syrjälä vbl_start = mode->crtc_vblank_start; 657c2baf4b7SVille Syrjälä vbl_end = mode->crtc_vblank_end; 6580af7e4dfSMario Kleiner 659d31faf65SVille Syrjälä if (mode->flags & DRM_MODE_FLAG_INTERLACE) { 660d31faf65SVille Syrjälä vbl_start = DIV_ROUND_UP(vbl_start, 2); 661d31faf65SVille Syrjälä vbl_end /= 2; 662d31faf65SVille Syrjälä vtotal /= 2; 663d31faf65SVille Syrjälä } 664d31faf65SVille Syrjälä 665c2baf4b7SVille Syrjälä ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE; 666c2baf4b7SVille Syrjälä 667ad3543edSMario Kleiner /* 668ad3543edSMario Kleiner * Lock uncore.lock, as we will do multiple timing critical raw 669ad3543edSMario Kleiner * register reads, potentially with preemption disabled, so the 670ad3543edSMario Kleiner * following code must not block on uncore.lock. 671ad3543edSMario Kleiner */ 672ad3543edSMario Kleiner spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); 673ad3543edSMario Kleiner 674ad3543edSMario Kleiner /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */ 675ad3543edSMario Kleiner 676ad3543edSMario Kleiner /* Get optional system timestamp before query. */ 677ad3543edSMario Kleiner if (stime) 678ad3543edSMario Kleiner *stime = ktime_get(); 679ad3543edSMario Kleiner 6807c06b08aSVille Syrjälä if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { 6810af7e4dfSMario Kleiner /* No obvious pixelcount register. Only query vertical 6820af7e4dfSMario Kleiner * scanout position from Display scan line register. 6830af7e4dfSMario Kleiner */ 684a225f079SVille Syrjälä position = __intel_get_crtc_scanline(intel_crtc); 6850af7e4dfSMario Kleiner } else { 6860af7e4dfSMario Kleiner /* Have access to pixelcount since start of frame. 6870af7e4dfSMario Kleiner * We can split this into vertical and horizontal 6880af7e4dfSMario Kleiner * scanout position. 6890af7e4dfSMario Kleiner */ 690ad3543edSMario Kleiner position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT; 6910af7e4dfSMario Kleiner 6923aa18df8SVille Syrjälä /* convert to pixel counts */ 6933aa18df8SVille Syrjälä vbl_start *= htotal; 6943aa18df8SVille Syrjälä vbl_end *= htotal; 6953aa18df8SVille Syrjälä vtotal *= htotal; 69678e8fc6bSVille Syrjälä 69778e8fc6bSVille Syrjälä /* 6987e78f1cbSVille Syrjälä * In interlaced modes, the pixel counter counts all pixels, 6997e78f1cbSVille Syrjälä * so one field will have htotal more pixels. In order to avoid 7007e78f1cbSVille Syrjälä * the reported position from jumping backwards when the pixel 7017e78f1cbSVille Syrjälä * counter is beyond the length of the shorter field, just 7027e78f1cbSVille Syrjälä * clamp the position the length of the shorter field. This 7037e78f1cbSVille Syrjälä * matches how the scanline counter based position works since 7047e78f1cbSVille Syrjälä * the scanline counter doesn't count the two half lines. 7057e78f1cbSVille Syrjälä */ 7067e78f1cbSVille Syrjälä if (position >= vtotal) 7077e78f1cbSVille Syrjälä position = vtotal - 1; 7087e78f1cbSVille Syrjälä 7097e78f1cbSVille Syrjälä /* 71078e8fc6bSVille Syrjälä * Start of vblank interrupt is triggered at start of hsync, 71178e8fc6bSVille Syrjälä * just prior to the first active line of vblank. However we 71278e8fc6bSVille Syrjälä * consider lines to start at the leading edge of horizontal 71378e8fc6bSVille Syrjälä * active. So, should we get here before we've crossed into 71478e8fc6bSVille Syrjälä * the horizontal active of the first line in vblank, we would 71578e8fc6bSVille Syrjälä * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that, 71678e8fc6bSVille Syrjälä * always add htotal-hsync_start to the current pixel position. 71778e8fc6bSVille Syrjälä */ 71878e8fc6bSVille Syrjälä position = (position + htotal - hsync_start) % vtotal; 7193aa18df8SVille Syrjälä } 7203aa18df8SVille Syrjälä 721ad3543edSMario Kleiner /* Get optional system timestamp after query. */ 722ad3543edSMario Kleiner if (etime) 723ad3543edSMario Kleiner *etime = ktime_get(); 724ad3543edSMario Kleiner 725ad3543edSMario Kleiner /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */ 726ad3543edSMario Kleiner 727ad3543edSMario Kleiner spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); 728ad3543edSMario Kleiner 7293aa18df8SVille Syrjälä in_vbl = position >= vbl_start && position < vbl_end; 7303aa18df8SVille Syrjälä 7313aa18df8SVille Syrjälä /* 7323aa18df8SVille Syrjälä * While in vblank, position will be negative 7333aa18df8SVille Syrjälä * counting up towards 0 at vbl_end. And outside 7343aa18df8SVille Syrjälä * vblank, position will be positive counting 7353aa18df8SVille Syrjälä * up since vbl_end. 7363aa18df8SVille Syrjälä */ 7373aa18df8SVille Syrjälä if (position >= vbl_start) 7383aa18df8SVille Syrjälä position -= vbl_end; 7393aa18df8SVille Syrjälä else 7403aa18df8SVille Syrjälä position += vtotal - vbl_end; 7413aa18df8SVille Syrjälä 7427c06b08aSVille Syrjälä if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { 7433aa18df8SVille Syrjälä *vpos = position; 7443aa18df8SVille Syrjälä *hpos = 0; 7453aa18df8SVille Syrjälä } else { 7460af7e4dfSMario Kleiner *vpos = position / htotal; 7470af7e4dfSMario Kleiner *hpos = position - (*vpos * htotal); 7480af7e4dfSMario Kleiner } 7490af7e4dfSMario Kleiner 7500af7e4dfSMario Kleiner /* In vblank? */ 7510af7e4dfSMario Kleiner if (in_vbl) 7523d3cbd84SDaniel Vetter ret |= DRM_SCANOUTPOS_IN_VBLANK; 7530af7e4dfSMario Kleiner 7540af7e4dfSMario Kleiner return ret; 7550af7e4dfSMario Kleiner } 7560af7e4dfSMario Kleiner 757a225f079SVille Syrjälä int intel_get_crtc_scanline(struct intel_crtc *crtc) 758a225f079SVille Syrjälä { 759a225f079SVille Syrjälä struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; 760a225f079SVille Syrjälä unsigned long irqflags; 761a225f079SVille Syrjälä int position; 762a225f079SVille Syrjälä 763a225f079SVille Syrjälä spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); 764a225f079SVille Syrjälä position = __intel_get_crtc_scanline(crtc); 765a225f079SVille Syrjälä spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); 766a225f079SVille Syrjälä 767a225f079SVille Syrjälä return position; 768a225f079SVille Syrjälä } 769a225f079SVille Syrjälä 770f71d4af4SJesse Barnes static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe, 7710af7e4dfSMario Kleiner int *max_error, 7720af7e4dfSMario Kleiner struct timeval *vblank_time, 7730af7e4dfSMario Kleiner unsigned flags) 7740af7e4dfSMario Kleiner { 7754041b853SChris Wilson struct drm_crtc *crtc; 7760af7e4dfSMario Kleiner 7777eb552aeSBen Widawsky if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) { 7784041b853SChris Wilson DRM_ERROR("Invalid crtc %d\n", pipe); 7790af7e4dfSMario Kleiner return -EINVAL; 7800af7e4dfSMario Kleiner } 7810af7e4dfSMario Kleiner 7820af7e4dfSMario Kleiner /* Get drm_crtc to timestamp: */ 7834041b853SChris Wilson crtc = intel_get_crtc_for_pipe(dev, pipe); 7844041b853SChris Wilson if (crtc == NULL) { 7854041b853SChris Wilson DRM_ERROR("Invalid crtc %d\n", pipe); 7864041b853SChris Wilson return -EINVAL; 7874041b853SChris Wilson } 7884041b853SChris Wilson 7894041b853SChris Wilson if (!crtc->enabled) { 7904041b853SChris Wilson DRM_DEBUG_KMS("crtc %d is disabled\n", pipe); 7914041b853SChris Wilson return -EBUSY; 7924041b853SChris Wilson } 7930af7e4dfSMario Kleiner 7940af7e4dfSMario Kleiner /* Helper routine in DRM core does all the work: */ 7954041b853SChris Wilson return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error, 7964041b853SChris Wilson vblank_time, flags, 7977da903efSVille Syrjälä crtc, 7987da903efSVille Syrjälä &to_intel_crtc(crtc)->config.adjusted_mode); 7990af7e4dfSMario Kleiner } 8000af7e4dfSMario Kleiner 80167c347ffSJani Nikula static bool intel_hpd_irq_event(struct drm_device *dev, 80267c347ffSJani Nikula struct drm_connector *connector) 803321a1b30SEgbert Eich { 804321a1b30SEgbert Eich enum drm_connector_status old_status; 805321a1b30SEgbert Eich 806321a1b30SEgbert Eich WARN_ON(!mutex_is_locked(&dev->mode_config.mutex)); 807321a1b30SEgbert Eich old_status = connector->status; 808321a1b30SEgbert Eich 809321a1b30SEgbert Eich connector->status = connector->funcs->detect(connector, false); 81067c347ffSJani Nikula if (old_status == connector->status) 81167c347ffSJani Nikula return false; 81267c347ffSJani Nikula 81367c347ffSJani Nikula DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n", 814321a1b30SEgbert Eich connector->base.id, 815c23cc417SJani Nikula connector->name, 81667c347ffSJani Nikula drm_get_connector_status_name(old_status), 81767c347ffSJani Nikula drm_get_connector_status_name(connector->status)); 81867c347ffSJani Nikula 81967c347ffSJani Nikula return true; 820321a1b30SEgbert Eich } 821321a1b30SEgbert Eich 82213cf5504SDave Airlie static void i915_digport_work_func(struct work_struct *work) 82313cf5504SDave Airlie { 82413cf5504SDave Airlie struct drm_i915_private *dev_priv = 82513cf5504SDave Airlie container_of(work, struct drm_i915_private, dig_port_work); 82613cf5504SDave Airlie u32 long_port_mask, short_port_mask; 82713cf5504SDave Airlie struct intel_digital_port *intel_dig_port; 82813cf5504SDave Airlie int i, ret; 82913cf5504SDave Airlie u32 old_bits = 0; 83013cf5504SDave Airlie 8314cb21832SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 83213cf5504SDave Airlie long_port_mask = dev_priv->long_hpd_port_mask; 83313cf5504SDave Airlie dev_priv->long_hpd_port_mask = 0; 83413cf5504SDave Airlie short_port_mask = dev_priv->short_hpd_port_mask; 83513cf5504SDave Airlie dev_priv->short_hpd_port_mask = 0; 8364cb21832SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 83713cf5504SDave Airlie 83813cf5504SDave Airlie for (i = 0; i < I915_MAX_PORTS; i++) { 83913cf5504SDave Airlie bool valid = false; 84013cf5504SDave Airlie bool long_hpd = false; 84113cf5504SDave Airlie intel_dig_port = dev_priv->hpd_irq_port[i]; 84213cf5504SDave Airlie if (!intel_dig_port || !intel_dig_port->hpd_pulse) 84313cf5504SDave Airlie continue; 84413cf5504SDave Airlie 84513cf5504SDave Airlie if (long_port_mask & (1 << i)) { 84613cf5504SDave Airlie valid = true; 84713cf5504SDave Airlie long_hpd = true; 84813cf5504SDave Airlie } else if (short_port_mask & (1 << i)) 84913cf5504SDave Airlie valid = true; 85013cf5504SDave Airlie 85113cf5504SDave Airlie if (valid) { 85213cf5504SDave Airlie ret = intel_dig_port->hpd_pulse(intel_dig_port, long_hpd); 85313cf5504SDave Airlie if (ret == true) { 85413cf5504SDave Airlie /* if we get true fallback to old school hpd */ 85513cf5504SDave Airlie old_bits |= (1 << intel_dig_port->base.hpd_pin); 85613cf5504SDave Airlie } 85713cf5504SDave Airlie } 85813cf5504SDave Airlie } 85913cf5504SDave Airlie 86013cf5504SDave Airlie if (old_bits) { 8614cb21832SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 86213cf5504SDave Airlie dev_priv->hpd_event_bits |= old_bits; 8634cb21832SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 86413cf5504SDave Airlie schedule_work(&dev_priv->hotplug_work); 86513cf5504SDave Airlie } 86613cf5504SDave Airlie } 86713cf5504SDave Airlie 8685ca58282SJesse Barnes /* 8695ca58282SJesse Barnes * Handle hotplug events outside the interrupt handler proper. 8705ca58282SJesse Barnes */ 871ac4c16c5SEgbert Eich #define I915_REENABLE_HOTPLUG_DELAY (2*60*1000) 872ac4c16c5SEgbert Eich 8735ca58282SJesse Barnes static void i915_hotplug_work_func(struct work_struct *work) 8745ca58282SJesse Barnes { 8752d1013ddSJani Nikula struct drm_i915_private *dev_priv = 8762d1013ddSJani Nikula container_of(work, struct drm_i915_private, hotplug_work); 8775ca58282SJesse Barnes struct drm_device *dev = dev_priv->dev; 878c31c4ba3SKeith Packard struct drm_mode_config *mode_config = &dev->mode_config; 879cd569aedSEgbert Eich struct intel_connector *intel_connector; 880cd569aedSEgbert Eich struct intel_encoder *intel_encoder; 881cd569aedSEgbert Eich struct drm_connector *connector; 882cd569aedSEgbert Eich bool hpd_disabled = false; 883321a1b30SEgbert Eich bool changed = false; 884142e2398SEgbert Eich u32 hpd_event_bits; 8855ca58282SJesse Barnes 886a65e34c7SKeith Packard mutex_lock(&mode_config->mutex); 887e67189abSJesse Barnes DRM_DEBUG_KMS("running encoder hotplug functions\n"); 888e67189abSJesse Barnes 8894cb21832SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 890142e2398SEgbert Eich 891142e2398SEgbert Eich hpd_event_bits = dev_priv->hpd_event_bits; 892142e2398SEgbert Eich dev_priv->hpd_event_bits = 0; 893cd569aedSEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 894cd569aedSEgbert Eich intel_connector = to_intel_connector(connector); 89536cd7444SDave Airlie if (!intel_connector->encoder) 89636cd7444SDave Airlie continue; 897cd569aedSEgbert Eich intel_encoder = intel_connector->encoder; 898cd569aedSEgbert Eich if (intel_encoder->hpd_pin > HPD_NONE && 899cd569aedSEgbert Eich dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED && 900cd569aedSEgbert Eich connector->polled == DRM_CONNECTOR_POLL_HPD) { 901cd569aedSEgbert Eich DRM_INFO("HPD interrupt storm detected on connector %s: " 902cd569aedSEgbert Eich "switching from hotplug detection to polling\n", 903c23cc417SJani Nikula connector->name); 904cd569aedSEgbert Eich dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED; 905cd569aedSEgbert Eich connector->polled = DRM_CONNECTOR_POLL_CONNECT 906cd569aedSEgbert Eich | DRM_CONNECTOR_POLL_DISCONNECT; 907cd569aedSEgbert Eich hpd_disabled = true; 908cd569aedSEgbert Eich } 909142e2398SEgbert Eich if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) { 910142e2398SEgbert Eich DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n", 911c23cc417SJani Nikula connector->name, intel_encoder->hpd_pin); 912142e2398SEgbert Eich } 913cd569aedSEgbert Eich } 914cd569aedSEgbert Eich /* if there were no outputs to poll, poll was disabled, 915cd569aedSEgbert Eich * therefore make sure it's enabled when disabling HPD on 916cd569aedSEgbert Eich * some connectors */ 917ac4c16c5SEgbert Eich if (hpd_disabled) { 918cd569aedSEgbert Eich drm_kms_helper_poll_enable(dev); 9196323751dSImre Deak mod_delayed_work(system_wq, &dev_priv->hotplug_reenable_work, 9206323751dSImre Deak msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY)); 921ac4c16c5SEgbert Eich } 922cd569aedSEgbert Eich 9234cb21832SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 924cd569aedSEgbert Eich 925321a1b30SEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 926321a1b30SEgbert Eich intel_connector = to_intel_connector(connector); 92736cd7444SDave Airlie if (!intel_connector->encoder) 92836cd7444SDave Airlie continue; 929321a1b30SEgbert Eich intel_encoder = intel_connector->encoder; 930321a1b30SEgbert Eich if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) { 931cd569aedSEgbert Eich if (intel_encoder->hot_plug) 932cd569aedSEgbert Eich intel_encoder->hot_plug(intel_encoder); 933321a1b30SEgbert Eich if (intel_hpd_irq_event(dev, connector)) 934321a1b30SEgbert Eich changed = true; 935321a1b30SEgbert Eich } 936321a1b30SEgbert Eich } 93740ee3381SKeith Packard mutex_unlock(&mode_config->mutex); 93840ee3381SKeith Packard 939321a1b30SEgbert Eich if (changed) 940321a1b30SEgbert Eich drm_kms_helper_hotplug_event(dev); 9415ca58282SJesse Barnes } 9425ca58282SJesse Barnes 943d0ecd7e2SDaniel Vetter static void ironlake_rps_change_irq_handler(struct drm_device *dev) 944f97108d1SJesse Barnes { 9452d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 946b5b72e89SMatthew Garrett u32 busy_up, busy_down, max_avg, min_avg; 9479270388eSDaniel Vetter u8 new_delay; 9489270388eSDaniel Vetter 949d0ecd7e2SDaniel Vetter spin_lock(&mchdev_lock); 950f97108d1SJesse Barnes 95173edd18fSDaniel Vetter I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS)); 95273edd18fSDaniel Vetter 95320e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay; 9549270388eSDaniel Vetter 9557648fa99SJesse Barnes I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG); 956b5b72e89SMatthew Garrett busy_up = I915_READ(RCPREVBSYTUPAVG); 957b5b72e89SMatthew Garrett busy_down = I915_READ(RCPREVBSYTDNAVG); 958f97108d1SJesse Barnes max_avg = I915_READ(RCBMAXAVG); 959f97108d1SJesse Barnes min_avg = I915_READ(RCBMINAVG); 960f97108d1SJesse Barnes 961f97108d1SJesse Barnes /* Handle RCS change request from hw */ 962b5b72e89SMatthew Garrett if (busy_up > max_avg) { 96320e4d407SDaniel Vetter if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay) 96420e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay - 1; 96520e4d407SDaniel Vetter if (new_delay < dev_priv->ips.max_delay) 96620e4d407SDaniel Vetter new_delay = dev_priv->ips.max_delay; 967b5b72e89SMatthew Garrett } else if (busy_down < min_avg) { 96820e4d407SDaniel Vetter if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay) 96920e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay + 1; 97020e4d407SDaniel Vetter if (new_delay > dev_priv->ips.min_delay) 97120e4d407SDaniel Vetter new_delay = dev_priv->ips.min_delay; 972f97108d1SJesse Barnes } 973f97108d1SJesse Barnes 9747648fa99SJesse Barnes if (ironlake_set_drps(dev, new_delay)) 97520e4d407SDaniel Vetter dev_priv->ips.cur_delay = new_delay; 976f97108d1SJesse Barnes 977d0ecd7e2SDaniel Vetter spin_unlock(&mchdev_lock); 9789270388eSDaniel Vetter 979f97108d1SJesse Barnes return; 980f97108d1SJesse Barnes } 981f97108d1SJesse Barnes 982549f7365SChris Wilson static void notify_ring(struct drm_device *dev, 983a4872ba6SOscar Mateo struct intel_engine_cs *ring) 984549f7365SChris Wilson { 98593b0a4e0SOscar Mateo if (!intel_ring_initialized(ring)) 986475553deSChris Wilson return; 987475553deSChris Wilson 988814e9b57SChris Wilson trace_i915_gem_request_complete(ring); 9899862e600SChris Wilson 990549f7365SChris Wilson wake_up_all(&ring->irq_queue); 991549f7365SChris Wilson } 992549f7365SChris Wilson 99331685c25SDeepak S static u32 vlv_c0_residency(struct drm_i915_private *dev_priv, 994bf225f20SChris Wilson struct intel_rps_ei *rps_ei) 99531685c25SDeepak S { 99631685c25SDeepak S u32 cz_ts, cz_freq_khz; 99731685c25SDeepak S u32 render_count, media_count; 99831685c25SDeepak S u32 elapsed_render, elapsed_media, elapsed_time; 99931685c25SDeepak S u32 residency = 0; 100031685c25SDeepak S 100131685c25SDeepak S cz_ts = vlv_punit_read(dev_priv, PUNIT_REG_CZ_TIMESTAMP); 100231685c25SDeepak S cz_freq_khz = DIV_ROUND_CLOSEST(dev_priv->mem_freq * 1000, 4); 100331685c25SDeepak S 100431685c25SDeepak S render_count = I915_READ(VLV_RENDER_C0_COUNT_REG); 100531685c25SDeepak S media_count = I915_READ(VLV_MEDIA_C0_COUNT_REG); 100631685c25SDeepak S 1007bf225f20SChris Wilson if (rps_ei->cz_clock == 0) { 1008bf225f20SChris Wilson rps_ei->cz_clock = cz_ts; 1009bf225f20SChris Wilson rps_ei->render_c0 = render_count; 1010bf225f20SChris Wilson rps_ei->media_c0 = media_count; 101131685c25SDeepak S 101231685c25SDeepak S return dev_priv->rps.cur_freq; 101331685c25SDeepak S } 101431685c25SDeepak S 1015bf225f20SChris Wilson elapsed_time = cz_ts - rps_ei->cz_clock; 1016bf225f20SChris Wilson rps_ei->cz_clock = cz_ts; 101731685c25SDeepak S 1018bf225f20SChris Wilson elapsed_render = render_count - rps_ei->render_c0; 1019bf225f20SChris Wilson rps_ei->render_c0 = render_count; 102031685c25SDeepak S 1021bf225f20SChris Wilson elapsed_media = media_count - rps_ei->media_c0; 1022bf225f20SChris Wilson rps_ei->media_c0 = media_count; 102331685c25SDeepak S 102431685c25SDeepak S /* Convert all the counters into common unit of milli sec */ 102531685c25SDeepak S elapsed_time /= VLV_CZ_CLOCK_TO_MILLI_SEC; 102631685c25SDeepak S elapsed_render /= cz_freq_khz; 102731685c25SDeepak S elapsed_media /= cz_freq_khz; 102831685c25SDeepak S 102931685c25SDeepak S /* 103031685c25SDeepak S * Calculate overall C0 residency percentage 103131685c25SDeepak S * only if elapsed time is non zero 103231685c25SDeepak S */ 103331685c25SDeepak S if (elapsed_time) { 103431685c25SDeepak S residency = 103531685c25SDeepak S ((max(elapsed_render, elapsed_media) * 100) 103631685c25SDeepak S / elapsed_time); 103731685c25SDeepak S } 103831685c25SDeepak S 103931685c25SDeepak S return residency; 104031685c25SDeepak S } 104131685c25SDeepak S 104231685c25SDeepak S /** 104331685c25SDeepak S * vlv_calc_delay_from_C0_counters - Increase/Decrease freq based on GPU 104431685c25SDeepak S * busy-ness calculated from C0 counters of render & media power wells 104531685c25SDeepak S * @dev_priv: DRM device private 104631685c25SDeepak S * 104731685c25SDeepak S */ 10484fa79042SDamien Lespiau static int vlv_calc_delay_from_C0_counters(struct drm_i915_private *dev_priv) 104931685c25SDeepak S { 105031685c25SDeepak S u32 residency_C0_up = 0, residency_C0_down = 0; 10514fa79042SDamien Lespiau int new_delay, adj; 105231685c25SDeepak S 105331685c25SDeepak S dev_priv->rps.ei_interrupt_count++; 105431685c25SDeepak S 105531685c25SDeepak S WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); 105631685c25SDeepak S 105731685c25SDeepak S 1058bf225f20SChris Wilson if (dev_priv->rps.up_ei.cz_clock == 0) { 1059bf225f20SChris Wilson vlv_c0_residency(dev_priv, &dev_priv->rps.up_ei); 1060bf225f20SChris Wilson vlv_c0_residency(dev_priv, &dev_priv->rps.down_ei); 106131685c25SDeepak S return dev_priv->rps.cur_freq; 106231685c25SDeepak S } 106331685c25SDeepak S 106431685c25SDeepak S 106531685c25SDeepak S /* 106631685c25SDeepak S * To down throttle, C0 residency should be less than down threshold 106731685c25SDeepak S * for continous EI intervals. So calculate down EI counters 106831685c25SDeepak S * once in VLV_INT_COUNT_FOR_DOWN_EI 106931685c25SDeepak S */ 107031685c25SDeepak S if (dev_priv->rps.ei_interrupt_count == VLV_INT_COUNT_FOR_DOWN_EI) { 107131685c25SDeepak S 107231685c25SDeepak S dev_priv->rps.ei_interrupt_count = 0; 107331685c25SDeepak S 107431685c25SDeepak S residency_C0_down = vlv_c0_residency(dev_priv, 1075bf225f20SChris Wilson &dev_priv->rps.down_ei); 107631685c25SDeepak S } else { 107731685c25SDeepak S residency_C0_up = vlv_c0_residency(dev_priv, 1078bf225f20SChris Wilson &dev_priv->rps.up_ei); 107931685c25SDeepak S } 108031685c25SDeepak S 108131685c25SDeepak S new_delay = dev_priv->rps.cur_freq; 108231685c25SDeepak S 108331685c25SDeepak S adj = dev_priv->rps.last_adj; 108431685c25SDeepak S /* C0 residency is greater than UP threshold. Increase Frequency */ 108531685c25SDeepak S if (residency_C0_up >= VLV_RP_UP_EI_THRESHOLD) { 108631685c25SDeepak S if (adj > 0) 108731685c25SDeepak S adj *= 2; 108831685c25SDeepak S else 108931685c25SDeepak S adj = 1; 109031685c25SDeepak S 109131685c25SDeepak S if (dev_priv->rps.cur_freq < dev_priv->rps.max_freq_softlimit) 109231685c25SDeepak S new_delay = dev_priv->rps.cur_freq + adj; 109331685c25SDeepak S 109431685c25SDeepak S /* 109531685c25SDeepak S * For better performance, jump directly 109631685c25SDeepak S * to RPe if we're below it. 109731685c25SDeepak S */ 109831685c25SDeepak S if (new_delay < dev_priv->rps.efficient_freq) 109931685c25SDeepak S new_delay = dev_priv->rps.efficient_freq; 110031685c25SDeepak S 110131685c25SDeepak S } else if (!dev_priv->rps.ei_interrupt_count && 110231685c25SDeepak S (residency_C0_down < VLV_RP_DOWN_EI_THRESHOLD)) { 110331685c25SDeepak S if (adj < 0) 110431685c25SDeepak S adj *= 2; 110531685c25SDeepak S else 110631685c25SDeepak S adj = -1; 110731685c25SDeepak S /* 110831685c25SDeepak S * This means, C0 residency is less than down threshold over 110931685c25SDeepak S * a period of VLV_INT_COUNT_FOR_DOWN_EI. So, reduce the freq 111031685c25SDeepak S */ 111131685c25SDeepak S if (dev_priv->rps.cur_freq > dev_priv->rps.min_freq_softlimit) 111231685c25SDeepak S new_delay = dev_priv->rps.cur_freq + adj; 111331685c25SDeepak S } 111431685c25SDeepak S 111531685c25SDeepak S return new_delay; 111631685c25SDeepak S } 111731685c25SDeepak S 11184912d041SBen Widawsky static void gen6_pm_rps_work(struct work_struct *work) 11193b8d8d91SJesse Barnes { 11202d1013ddSJani Nikula struct drm_i915_private *dev_priv = 11212d1013ddSJani Nikula container_of(work, struct drm_i915_private, rps.work); 1122edbfdb45SPaulo Zanoni u32 pm_iir; 1123dd75fdc8SChris Wilson int new_delay, adj; 11243b8d8d91SJesse Barnes 112559cdb63dSDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 1126c6a828d3SDaniel Vetter pm_iir = dev_priv->rps.pm_iir; 1127c6a828d3SDaniel Vetter dev_priv->rps.pm_iir = 0; 1128a72fbc3aSImre Deak /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */ 1129480c8033SDaniel Vetter gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events); 113059cdb63dSDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 11314912d041SBen Widawsky 113260611c13SPaulo Zanoni /* Make sure we didn't queue anything we're not going to process. */ 1133a6706b45SDeepak S WARN_ON(pm_iir & ~dev_priv->pm_rps_events); 113460611c13SPaulo Zanoni 1135a6706b45SDeepak S if ((pm_iir & dev_priv->pm_rps_events) == 0) 11363b8d8d91SJesse Barnes return; 11373b8d8d91SJesse Barnes 11384fc688ceSJesse Barnes mutex_lock(&dev_priv->rps.hw_lock); 11397b9e0ae6SChris Wilson 1140dd75fdc8SChris Wilson adj = dev_priv->rps.last_adj; 11417425034aSVille Syrjälä if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) { 1142dd75fdc8SChris Wilson if (adj > 0) 1143dd75fdc8SChris Wilson adj *= 2; 114413a5660cSDeepak S else { 114513a5660cSDeepak S /* CHV needs even encode values */ 114613a5660cSDeepak S adj = IS_CHERRYVIEW(dev_priv->dev) ? 2 : 1; 114713a5660cSDeepak S } 1148b39fb297SBen Widawsky new_delay = dev_priv->rps.cur_freq + adj; 11497425034aSVille Syrjälä 11507425034aSVille Syrjälä /* 11517425034aSVille Syrjälä * For better performance, jump directly 11527425034aSVille Syrjälä * to RPe if we're below it. 11537425034aSVille Syrjälä */ 1154b39fb297SBen Widawsky if (new_delay < dev_priv->rps.efficient_freq) 1155b39fb297SBen Widawsky new_delay = dev_priv->rps.efficient_freq; 1156dd75fdc8SChris Wilson } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) { 1157b39fb297SBen Widawsky if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq) 1158b39fb297SBen Widawsky new_delay = dev_priv->rps.efficient_freq; 1159dd75fdc8SChris Wilson else 1160b39fb297SBen Widawsky new_delay = dev_priv->rps.min_freq_softlimit; 1161dd75fdc8SChris Wilson adj = 0; 116231685c25SDeepak S } else if (pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) { 116331685c25SDeepak S new_delay = vlv_calc_delay_from_C0_counters(dev_priv); 1164dd75fdc8SChris Wilson } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) { 1165dd75fdc8SChris Wilson if (adj < 0) 1166dd75fdc8SChris Wilson adj *= 2; 116713a5660cSDeepak S else { 116813a5660cSDeepak S /* CHV needs even encode values */ 116913a5660cSDeepak S adj = IS_CHERRYVIEW(dev_priv->dev) ? -2 : -1; 117013a5660cSDeepak S } 1171b39fb297SBen Widawsky new_delay = dev_priv->rps.cur_freq + adj; 1172dd75fdc8SChris Wilson } else { /* unknown event */ 1173b39fb297SBen Widawsky new_delay = dev_priv->rps.cur_freq; 1174dd75fdc8SChris Wilson } 11753b8d8d91SJesse Barnes 117679249636SBen Widawsky /* sysfs frequency interfaces may have snuck in while servicing the 117779249636SBen Widawsky * interrupt 117879249636SBen Widawsky */ 11791272e7b8SVille Syrjälä new_delay = clamp_t(int, new_delay, 1180b39fb297SBen Widawsky dev_priv->rps.min_freq_softlimit, 1181b39fb297SBen Widawsky dev_priv->rps.max_freq_softlimit); 118227544369SDeepak S 1183b39fb297SBen Widawsky dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_freq; 1184dd75fdc8SChris Wilson 11850a073b84SJesse Barnes if (IS_VALLEYVIEW(dev_priv->dev)) 11860a073b84SJesse Barnes valleyview_set_rps(dev_priv->dev, new_delay); 11870a073b84SJesse Barnes else 11884912d041SBen Widawsky gen6_set_rps(dev_priv->dev, new_delay); 11893b8d8d91SJesse Barnes 11904fc688ceSJesse Barnes mutex_unlock(&dev_priv->rps.hw_lock); 11913b8d8d91SJesse Barnes } 11923b8d8d91SJesse Barnes 1193e3689190SBen Widawsky 1194e3689190SBen Widawsky /** 1195e3689190SBen Widawsky * ivybridge_parity_work - Workqueue called when a parity error interrupt 1196e3689190SBen Widawsky * occurred. 1197e3689190SBen Widawsky * @work: workqueue struct 1198e3689190SBen Widawsky * 1199e3689190SBen Widawsky * Doesn't actually do anything except notify userspace. As a consequence of 1200e3689190SBen Widawsky * this event, userspace should try to remap the bad rows since statistically 1201e3689190SBen Widawsky * it is likely the same row is more likely to go bad again. 1202e3689190SBen Widawsky */ 1203e3689190SBen Widawsky static void ivybridge_parity_work(struct work_struct *work) 1204e3689190SBen Widawsky { 12052d1013ddSJani Nikula struct drm_i915_private *dev_priv = 12062d1013ddSJani Nikula container_of(work, struct drm_i915_private, l3_parity.error_work); 1207e3689190SBen Widawsky u32 error_status, row, bank, subbank; 120835a85ac6SBen Widawsky char *parity_event[6]; 1209e3689190SBen Widawsky uint32_t misccpctl; 121035a85ac6SBen Widawsky uint8_t slice = 0; 1211e3689190SBen Widawsky 1212e3689190SBen Widawsky /* We must turn off DOP level clock gating to access the L3 registers. 1213e3689190SBen Widawsky * In order to prevent a get/put style interface, acquire struct mutex 1214e3689190SBen Widawsky * any time we access those registers. 1215e3689190SBen Widawsky */ 1216e3689190SBen Widawsky mutex_lock(&dev_priv->dev->struct_mutex); 1217e3689190SBen Widawsky 121835a85ac6SBen Widawsky /* If we've screwed up tracking, just let the interrupt fire again */ 121935a85ac6SBen Widawsky if (WARN_ON(!dev_priv->l3_parity.which_slice)) 122035a85ac6SBen Widawsky goto out; 122135a85ac6SBen Widawsky 1222e3689190SBen Widawsky misccpctl = I915_READ(GEN7_MISCCPCTL); 1223e3689190SBen Widawsky I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); 1224e3689190SBen Widawsky POSTING_READ(GEN7_MISCCPCTL); 1225e3689190SBen Widawsky 122635a85ac6SBen Widawsky while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) { 122735a85ac6SBen Widawsky u32 reg; 122835a85ac6SBen Widawsky 122935a85ac6SBen Widawsky slice--; 123035a85ac6SBen Widawsky if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev))) 123135a85ac6SBen Widawsky break; 123235a85ac6SBen Widawsky 123335a85ac6SBen Widawsky dev_priv->l3_parity.which_slice &= ~(1<<slice); 123435a85ac6SBen Widawsky 123535a85ac6SBen Widawsky reg = GEN7_L3CDERRST1 + (slice * 0x200); 123635a85ac6SBen Widawsky 123735a85ac6SBen Widawsky error_status = I915_READ(reg); 1238e3689190SBen Widawsky row = GEN7_PARITY_ERROR_ROW(error_status); 1239e3689190SBen Widawsky bank = GEN7_PARITY_ERROR_BANK(error_status); 1240e3689190SBen Widawsky subbank = GEN7_PARITY_ERROR_SUBBANK(error_status); 1241e3689190SBen Widawsky 124235a85ac6SBen Widawsky I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE); 124335a85ac6SBen Widawsky POSTING_READ(reg); 1244e3689190SBen Widawsky 1245cce723edSBen Widawsky parity_event[0] = I915_L3_PARITY_UEVENT "=1"; 1246e3689190SBen Widawsky parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row); 1247e3689190SBen Widawsky parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank); 1248e3689190SBen Widawsky parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank); 124935a85ac6SBen Widawsky parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice); 125035a85ac6SBen Widawsky parity_event[5] = NULL; 1251e3689190SBen Widawsky 12525bdebb18SDave Airlie kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj, 1253e3689190SBen Widawsky KOBJ_CHANGE, parity_event); 1254e3689190SBen Widawsky 125535a85ac6SBen Widawsky DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n", 125635a85ac6SBen Widawsky slice, row, bank, subbank); 1257e3689190SBen Widawsky 125835a85ac6SBen Widawsky kfree(parity_event[4]); 1259e3689190SBen Widawsky kfree(parity_event[3]); 1260e3689190SBen Widawsky kfree(parity_event[2]); 1261e3689190SBen Widawsky kfree(parity_event[1]); 1262e3689190SBen Widawsky } 1263e3689190SBen Widawsky 126435a85ac6SBen Widawsky I915_WRITE(GEN7_MISCCPCTL, misccpctl); 126535a85ac6SBen Widawsky 126635a85ac6SBen Widawsky out: 126735a85ac6SBen Widawsky WARN_ON(dev_priv->l3_parity.which_slice); 12684cb21832SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 1269480c8033SDaniel Vetter gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev)); 12704cb21832SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 127135a85ac6SBen Widawsky 127235a85ac6SBen Widawsky mutex_unlock(&dev_priv->dev->struct_mutex); 127335a85ac6SBen Widawsky } 127435a85ac6SBen Widawsky 127535a85ac6SBen Widawsky static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir) 1276e3689190SBen Widawsky { 12772d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 1278e3689190SBen Widawsky 1279040d2baaSBen Widawsky if (!HAS_L3_DPF(dev)) 1280e3689190SBen Widawsky return; 1281e3689190SBen Widawsky 1282d0ecd7e2SDaniel Vetter spin_lock(&dev_priv->irq_lock); 1283480c8033SDaniel Vetter gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev)); 1284d0ecd7e2SDaniel Vetter spin_unlock(&dev_priv->irq_lock); 1285e3689190SBen Widawsky 128635a85ac6SBen Widawsky iir &= GT_PARITY_ERROR(dev); 128735a85ac6SBen Widawsky if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1) 128835a85ac6SBen Widawsky dev_priv->l3_parity.which_slice |= 1 << 1; 128935a85ac6SBen Widawsky 129035a85ac6SBen Widawsky if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT) 129135a85ac6SBen Widawsky dev_priv->l3_parity.which_slice |= 1 << 0; 129235a85ac6SBen Widawsky 1293a4da4fa4SDaniel Vetter queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work); 1294e3689190SBen Widawsky } 1295e3689190SBen Widawsky 1296f1af8fc1SPaulo Zanoni static void ilk_gt_irq_handler(struct drm_device *dev, 1297f1af8fc1SPaulo Zanoni struct drm_i915_private *dev_priv, 1298f1af8fc1SPaulo Zanoni u32 gt_iir) 1299f1af8fc1SPaulo Zanoni { 1300f1af8fc1SPaulo Zanoni if (gt_iir & 1301f1af8fc1SPaulo Zanoni (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT)) 1302f1af8fc1SPaulo Zanoni notify_ring(dev, &dev_priv->ring[RCS]); 1303f1af8fc1SPaulo Zanoni if (gt_iir & ILK_BSD_USER_INTERRUPT) 1304f1af8fc1SPaulo Zanoni notify_ring(dev, &dev_priv->ring[VCS]); 1305f1af8fc1SPaulo Zanoni } 1306f1af8fc1SPaulo Zanoni 1307e7b4c6b1SDaniel Vetter static void snb_gt_irq_handler(struct drm_device *dev, 1308e7b4c6b1SDaniel Vetter struct drm_i915_private *dev_priv, 1309e7b4c6b1SDaniel Vetter u32 gt_iir) 1310e7b4c6b1SDaniel Vetter { 1311e7b4c6b1SDaniel Vetter 1312cc609d5dSBen Widawsky if (gt_iir & 1313cc609d5dSBen Widawsky (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT)) 1314e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[RCS]); 1315cc609d5dSBen Widawsky if (gt_iir & GT_BSD_USER_INTERRUPT) 1316e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[VCS]); 1317cc609d5dSBen Widawsky if (gt_iir & GT_BLT_USER_INTERRUPT) 1318e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[BCS]); 1319e7b4c6b1SDaniel Vetter 1320cc609d5dSBen Widawsky if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT | 1321cc609d5dSBen Widawsky GT_BSD_CS_ERROR_INTERRUPT | 1322cc609d5dSBen Widawsky GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) { 132358174462SMika Kuoppala i915_handle_error(dev, false, "GT error interrupt 0x%08x", 132458174462SMika Kuoppala gt_iir); 1325e7b4c6b1SDaniel Vetter } 1326e3689190SBen Widawsky 132735a85ac6SBen Widawsky if (gt_iir & GT_PARITY_ERROR(dev)) 132835a85ac6SBen Widawsky ivybridge_parity_error_irq_handler(dev, gt_iir); 1329e7b4c6b1SDaniel Vetter } 1330e7b4c6b1SDaniel Vetter 1331abd58f01SBen Widawsky static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev, 1332abd58f01SBen Widawsky struct drm_i915_private *dev_priv, 1333abd58f01SBen Widawsky u32 master_ctl) 1334abd58f01SBen Widawsky { 1335e981e7b1SThomas Daniel struct intel_engine_cs *ring; 1336abd58f01SBen Widawsky u32 rcs, bcs, vcs; 1337abd58f01SBen Widawsky uint32_t tmp = 0; 1338abd58f01SBen Widawsky irqreturn_t ret = IRQ_NONE; 1339abd58f01SBen Widawsky 1340abd58f01SBen Widawsky if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) { 1341abd58f01SBen Widawsky tmp = I915_READ(GEN8_GT_IIR(0)); 1342abd58f01SBen Widawsky if (tmp) { 134338cc46d7SOscar Mateo I915_WRITE(GEN8_GT_IIR(0), tmp); 1344abd58f01SBen Widawsky ret = IRQ_HANDLED; 1345e981e7b1SThomas Daniel 1346abd58f01SBen Widawsky rcs = tmp >> GEN8_RCS_IRQ_SHIFT; 1347e981e7b1SThomas Daniel ring = &dev_priv->ring[RCS]; 1348abd58f01SBen Widawsky if (rcs & GT_RENDER_USER_INTERRUPT) 1349e981e7b1SThomas Daniel notify_ring(dev, ring); 1350e981e7b1SThomas Daniel if (rcs & GT_CONTEXT_SWITCH_INTERRUPT) 1351e981e7b1SThomas Daniel intel_execlists_handle_ctx_events(ring); 1352e981e7b1SThomas Daniel 1353e981e7b1SThomas Daniel bcs = tmp >> GEN8_BCS_IRQ_SHIFT; 1354e981e7b1SThomas Daniel ring = &dev_priv->ring[BCS]; 1355abd58f01SBen Widawsky if (bcs & GT_RENDER_USER_INTERRUPT) 1356e981e7b1SThomas Daniel notify_ring(dev, ring); 1357e981e7b1SThomas Daniel if (bcs & GT_CONTEXT_SWITCH_INTERRUPT) 1358e981e7b1SThomas Daniel intel_execlists_handle_ctx_events(ring); 1359abd58f01SBen Widawsky } else 1360abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (GT0)!\n"); 1361abd58f01SBen Widawsky } 1362abd58f01SBen Widawsky 136385f9b5f9SZhao Yakui if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) { 1364abd58f01SBen Widawsky tmp = I915_READ(GEN8_GT_IIR(1)); 1365abd58f01SBen Widawsky if (tmp) { 136638cc46d7SOscar Mateo I915_WRITE(GEN8_GT_IIR(1), tmp); 1367abd58f01SBen Widawsky ret = IRQ_HANDLED; 1368e981e7b1SThomas Daniel 1369abd58f01SBen Widawsky vcs = tmp >> GEN8_VCS1_IRQ_SHIFT; 1370e981e7b1SThomas Daniel ring = &dev_priv->ring[VCS]; 1371abd58f01SBen Widawsky if (vcs & GT_RENDER_USER_INTERRUPT) 1372e981e7b1SThomas Daniel notify_ring(dev, ring); 137373d477f6SOscar Mateo if (vcs & GT_CONTEXT_SWITCH_INTERRUPT) 1374e981e7b1SThomas Daniel intel_execlists_handle_ctx_events(ring); 1375e981e7b1SThomas Daniel 137685f9b5f9SZhao Yakui vcs = tmp >> GEN8_VCS2_IRQ_SHIFT; 1377e981e7b1SThomas Daniel ring = &dev_priv->ring[VCS2]; 137885f9b5f9SZhao Yakui if (vcs & GT_RENDER_USER_INTERRUPT) 1379e981e7b1SThomas Daniel notify_ring(dev, ring); 138073d477f6SOscar Mateo if (vcs & GT_CONTEXT_SWITCH_INTERRUPT) 1381e981e7b1SThomas Daniel intel_execlists_handle_ctx_events(ring); 1382abd58f01SBen Widawsky } else 1383abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (GT1)!\n"); 1384abd58f01SBen Widawsky } 1385abd58f01SBen Widawsky 13860961021aSBen Widawsky if (master_ctl & GEN8_GT_PM_IRQ) { 13870961021aSBen Widawsky tmp = I915_READ(GEN8_GT_IIR(2)); 13880961021aSBen Widawsky if (tmp & dev_priv->pm_rps_events) { 13890961021aSBen Widawsky I915_WRITE(GEN8_GT_IIR(2), 13900961021aSBen Widawsky tmp & dev_priv->pm_rps_events); 139138cc46d7SOscar Mateo ret = IRQ_HANDLED; 1392c9a9a268SImre Deak gen6_rps_irq_handler(dev_priv, tmp); 13930961021aSBen Widawsky } else 13940961021aSBen Widawsky DRM_ERROR("The master control interrupt lied (PM)!\n"); 13950961021aSBen Widawsky } 13960961021aSBen Widawsky 1397abd58f01SBen Widawsky if (master_ctl & GEN8_GT_VECS_IRQ) { 1398abd58f01SBen Widawsky tmp = I915_READ(GEN8_GT_IIR(3)); 1399abd58f01SBen Widawsky if (tmp) { 140038cc46d7SOscar Mateo I915_WRITE(GEN8_GT_IIR(3), tmp); 1401abd58f01SBen Widawsky ret = IRQ_HANDLED; 1402e981e7b1SThomas Daniel 1403abd58f01SBen Widawsky vcs = tmp >> GEN8_VECS_IRQ_SHIFT; 1404e981e7b1SThomas Daniel ring = &dev_priv->ring[VECS]; 1405abd58f01SBen Widawsky if (vcs & GT_RENDER_USER_INTERRUPT) 1406e981e7b1SThomas Daniel notify_ring(dev, ring); 140773d477f6SOscar Mateo if (vcs & GT_CONTEXT_SWITCH_INTERRUPT) 1408e981e7b1SThomas Daniel intel_execlists_handle_ctx_events(ring); 1409abd58f01SBen Widawsky } else 1410abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (GT3)!\n"); 1411abd58f01SBen Widawsky } 1412abd58f01SBen Widawsky 1413abd58f01SBen Widawsky return ret; 1414abd58f01SBen Widawsky } 1415abd58f01SBen Widawsky 1416b543fb04SEgbert Eich #define HPD_STORM_DETECT_PERIOD 1000 1417b543fb04SEgbert Eich #define HPD_STORM_THRESHOLD 5 1418b543fb04SEgbert Eich 141907c338ceSJani Nikula static int pch_port_to_hotplug_shift(enum port port) 142013cf5504SDave Airlie { 142113cf5504SDave Airlie switch (port) { 142213cf5504SDave Airlie case PORT_A: 142313cf5504SDave Airlie case PORT_E: 142413cf5504SDave Airlie default: 142513cf5504SDave Airlie return -1; 142613cf5504SDave Airlie case PORT_B: 142713cf5504SDave Airlie return 0; 142813cf5504SDave Airlie case PORT_C: 142913cf5504SDave Airlie return 8; 143013cf5504SDave Airlie case PORT_D: 143113cf5504SDave Airlie return 16; 143213cf5504SDave Airlie } 143313cf5504SDave Airlie } 143413cf5504SDave Airlie 143507c338ceSJani Nikula static int i915_port_to_hotplug_shift(enum port port) 143613cf5504SDave Airlie { 143713cf5504SDave Airlie switch (port) { 143813cf5504SDave Airlie case PORT_A: 143913cf5504SDave Airlie case PORT_E: 144013cf5504SDave Airlie default: 144113cf5504SDave Airlie return -1; 144213cf5504SDave Airlie case PORT_B: 144313cf5504SDave Airlie return 17; 144413cf5504SDave Airlie case PORT_C: 144513cf5504SDave Airlie return 19; 144613cf5504SDave Airlie case PORT_D: 144713cf5504SDave Airlie return 21; 144813cf5504SDave Airlie } 144913cf5504SDave Airlie } 145013cf5504SDave Airlie 145113cf5504SDave Airlie static inline enum port get_port_from_pin(enum hpd_pin pin) 145213cf5504SDave Airlie { 145313cf5504SDave Airlie switch (pin) { 145413cf5504SDave Airlie case HPD_PORT_B: 145513cf5504SDave Airlie return PORT_B; 145613cf5504SDave Airlie case HPD_PORT_C: 145713cf5504SDave Airlie return PORT_C; 145813cf5504SDave Airlie case HPD_PORT_D: 145913cf5504SDave Airlie return PORT_D; 146013cf5504SDave Airlie default: 146113cf5504SDave Airlie return PORT_A; /* no hpd */ 146213cf5504SDave Airlie } 146313cf5504SDave Airlie } 146413cf5504SDave Airlie 146510a504deSDaniel Vetter static inline void intel_hpd_irq_handler(struct drm_device *dev, 1466b543fb04SEgbert Eich u32 hotplug_trigger, 146713cf5504SDave Airlie u32 dig_hotplug_reg, 1468b543fb04SEgbert Eich const u32 *hpd) 1469b543fb04SEgbert Eich { 14702d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 1471b543fb04SEgbert Eich int i; 147213cf5504SDave Airlie enum port port; 147310a504deSDaniel Vetter bool storm_detected = false; 147413cf5504SDave Airlie bool queue_dig = false, queue_hp = false; 147513cf5504SDave Airlie u32 dig_shift; 147613cf5504SDave Airlie u32 dig_port_mask = 0; 1477b543fb04SEgbert Eich 147891d131d2SDaniel Vetter if (!hotplug_trigger) 147991d131d2SDaniel Vetter return; 148091d131d2SDaniel Vetter 148113cf5504SDave Airlie DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x\n", 148213cf5504SDave Airlie hotplug_trigger, dig_hotplug_reg); 1483cc9bd499SImre Deak 1484b5ea2d56SDaniel Vetter spin_lock(&dev_priv->irq_lock); 1485b543fb04SEgbert Eich for (i = 1; i < HPD_NUM_PINS; i++) { 148613cf5504SDave Airlie if (!(hpd[i] & hotplug_trigger)) 148713cf5504SDave Airlie continue; 1488821450c6SEgbert Eich 148913cf5504SDave Airlie port = get_port_from_pin(i); 149013cf5504SDave Airlie if (port && dev_priv->hpd_irq_port[port]) { 149113cf5504SDave Airlie bool long_hpd; 149213cf5504SDave Airlie 149307c338ceSJani Nikula if (HAS_PCH_SPLIT(dev)) { 149407c338ceSJani Nikula dig_shift = pch_port_to_hotplug_shift(port); 149513cf5504SDave Airlie long_hpd = (dig_hotplug_reg >> dig_shift) & PORTB_HOTPLUG_LONG_DETECT; 149607c338ceSJani Nikula } else { 149707c338ceSJani Nikula dig_shift = i915_port_to_hotplug_shift(port); 149807c338ceSJani Nikula long_hpd = (hotplug_trigger >> dig_shift) & PORTB_HOTPLUG_LONG_DETECT; 149913cf5504SDave Airlie } 150013cf5504SDave Airlie 150126fbb774SVille Syrjälä DRM_DEBUG_DRIVER("digital hpd port %c - %s\n", 150226fbb774SVille Syrjälä port_name(port), 150326fbb774SVille Syrjälä long_hpd ? "long" : "short"); 150413cf5504SDave Airlie /* for long HPD pulses we want to have the digital queue happen, 150513cf5504SDave Airlie but we still want HPD storm detection to function. */ 150613cf5504SDave Airlie if (long_hpd) { 150713cf5504SDave Airlie dev_priv->long_hpd_port_mask |= (1 << port); 150813cf5504SDave Airlie dig_port_mask |= hpd[i]; 150913cf5504SDave Airlie } else { 151013cf5504SDave Airlie /* for short HPD just trigger the digital queue */ 151113cf5504SDave Airlie dev_priv->short_hpd_port_mask |= (1 << port); 151213cf5504SDave Airlie hotplug_trigger &= ~hpd[i]; 151313cf5504SDave Airlie } 151413cf5504SDave Airlie queue_dig = true; 151513cf5504SDave Airlie } 151613cf5504SDave Airlie } 151713cf5504SDave Airlie 151813cf5504SDave Airlie for (i = 1; i < HPD_NUM_PINS; i++) { 15193ff04a16SDaniel Vetter if (hpd[i] & hotplug_trigger && 15203ff04a16SDaniel Vetter dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED) { 15213ff04a16SDaniel Vetter /* 15223ff04a16SDaniel Vetter * On GMCH platforms the interrupt mask bits only 15233ff04a16SDaniel Vetter * prevent irq generation, not the setting of the 15243ff04a16SDaniel Vetter * hotplug bits itself. So only WARN about unexpected 15253ff04a16SDaniel Vetter * interrupts on saner platforms. 15263ff04a16SDaniel Vetter */ 15273ff04a16SDaniel Vetter WARN_ONCE(INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev), 1528cba1c073SChris Wilson "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n", 1529cba1c073SChris Wilson hotplug_trigger, i, hpd[i]); 1530b8f102e8SEgbert Eich 15313ff04a16SDaniel Vetter continue; 15323ff04a16SDaniel Vetter } 15333ff04a16SDaniel Vetter 1534b543fb04SEgbert Eich if (!(hpd[i] & hotplug_trigger) || 1535b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED) 1536b543fb04SEgbert Eich continue; 1537b543fb04SEgbert Eich 153813cf5504SDave Airlie if (!(dig_port_mask & hpd[i])) { 1539bc5ead8cSJani Nikula dev_priv->hpd_event_bits |= (1 << i); 154013cf5504SDave Airlie queue_hp = true; 154113cf5504SDave Airlie } 154213cf5504SDave Airlie 1543b543fb04SEgbert Eich if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies, 1544b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_last_jiffies 1545b543fb04SEgbert Eich + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) { 1546b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies; 1547b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt = 0; 1548b8f102e8SEgbert Eich DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i); 1549b543fb04SEgbert Eich } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) { 1550b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED; 1551142e2398SEgbert Eich dev_priv->hpd_event_bits &= ~(1 << i); 1552b543fb04SEgbert Eich DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i); 155310a504deSDaniel Vetter storm_detected = true; 1554b543fb04SEgbert Eich } else { 1555b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt++; 1556b8f102e8SEgbert Eich DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i, 1557b8f102e8SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt); 1558b543fb04SEgbert Eich } 1559b543fb04SEgbert Eich } 1560b543fb04SEgbert Eich 156110a504deSDaniel Vetter if (storm_detected) 156210a504deSDaniel Vetter dev_priv->display.hpd_irq_setup(dev); 1563b5ea2d56SDaniel Vetter spin_unlock(&dev_priv->irq_lock); 15645876fa0dSDaniel Vetter 1565645416f5SDaniel Vetter /* 1566645416f5SDaniel Vetter * Our hotplug handler can grab modeset locks (by calling down into the 1567645416f5SDaniel Vetter * fb helpers). Hence it must not be run on our own dev-priv->wq work 1568645416f5SDaniel Vetter * queue for otherwise the flush_work in the pageflip code will 1569645416f5SDaniel Vetter * deadlock. 1570645416f5SDaniel Vetter */ 157113cf5504SDave Airlie if (queue_dig) 15720e32b39cSDave Airlie queue_work(dev_priv->dp_wq, &dev_priv->dig_port_work); 157313cf5504SDave Airlie if (queue_hp) 1574645416f5SDaniel Vetter schedule_work(&dev_priv->hotplug_work); 1575b543fb04SEgbert Eich } 1576b543fb04SEgbert Eich 1577515ac2bbSDaniel Vetter static void gmbus_irq_handler(struct drm_device *dev) 1578515ac2bbSDaniel Vetter { 15792d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 158028c70f16SDaniel Vetter 158128c70f16SDaniel Vetter wake_up_all(&dev_priv->gmbus_wait_queue); 1582515ac2bbSDaniel Vetter } 1583515ac2bbSDaniel Vetter 1584ce99c256SDaniel Vetter static void dp_aux_irq_handler(struct drm_device *dev) 1585ce99c256SDaniel Vetter { 15862d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 15879ee32feaSDaniel Vetter 15889ee32feaSDaniel Vetter wake_up_all(&dev_priv->gmbus_wait_queue); 1589ce99c256SDaniel Vetter } 1590ce99c256SDaniel Vetter 15918bf1e9f1SShuang He #if defined(CONFIG_DEBUG_FS) 1592277de95eSDaniel Vetter static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe, 1593eba94eb9SDaniel Vetter uint32_t crc0, uint32_t crc1, 1594eba94eb9SDaniel Vetter uint32_t crc2, uint32_t crc3, 15958bc5e955SDaniel Vetter uint32_t crc4) 15968bf1e9f1SShuang He { 15978bf1e9f1SShuang He struct drm_i915_private *dev_priv = dev->dev_private; 15988bf1e9f1SShuang He struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe]; 15998bf1e9f1SShuang He struct intel_pipe_crc_entry *entry; 1600ac2300d4SDamien Lespiau int head, tail; 1601b2c88f5bSDamien Lespiau 1602d538bbdfSDamien Lespiau spin_lock(&pipe_crc->lock); 1603d538bbdfSDamien Lespiau 16040c912c79SDamien Lespiau if (!pipe_crc->entries) { 1605d538bbdfSDamien Lespiau spin_unlock(&pipe_crc->lock); 16060c912c79SDamien Lespiau DRM_ERROR("spurious interrupt\n"); 16070c912c79SDamien Lespiau return; 16080c912c79SDamien Lespiau } 16090c912c79SDamien Lespiau 1610d538bbdfSDamien Lespiau head = pipe_crc->head; 1611d538bbdfSDamien Lespiau tail = pipe_crc->tail; 1612b2c88f5bSDamien Lespiau 1613b2c88f5bSDamien Lespiau if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) { 1614d538bbdfSDamien Lespiau spin_unlock(&pipe_crc->lock); 1615b2c88f5bSDamien Lespiau DRM_ERROR("CRC buffer overflowing\n"); 1616b2c88f5bSDamien Lespiau return; 1617b2c88f5bSDamien Lespiau } 1618b2c88f5bSDamien Lespiau 1619b2c88f5bSDamien Lespiau entry = &pipe_crc->entries[head]; 16208bf1e9f1SShuang He 16218bc5e955SDaniel Vetter entry->frame = dev->driver->get_vblank_counter(dev, pipe); 1622eba94eb9SDaniel Vetter entry->crc[0] = crc0; 1623eba94eb9SDaniel Vetter entry->crc[1] = crc1; 1624eba94eb9SDaniel Vetter entry->crc[2] = crc2; 1625eba94eb9SDaniel Vetter entry->crc[3] = crc3; 1626eba94eb9SDaniel Vetter entry->crc[4] = crc4; 1627b2c88f5bSDamien Lespiau 1628b2c88f5bSDamien Lespiau head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1); 1629d538bbdfSDamien Lespiau pipe_crc->head = head; 1630d538bbdfSDamien Lespiau 1631d538bbdfSDamien Lespiau spin_unlock(&pipe_crc->lock); 163207144428SDamien Lespiau 163307144428SDamien Lespiau wake_up_interruptible(&pipe_crc->wq); 16348bf1e9f1SShuang He } 1635277de95eSDaniel Vetter #else 1636277de95eSDaniel Vetter static inline void 1637277de95eSDaniel Vetter display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe, 1638277de95eSDaniel Vetter uint32_t crc0, uint32_t crc1, 1639277de95eSDaniel Vetter uint32_t crc2, uint32_t crc3, 1640277de95eSDaniel Vetter uint32_t crc4) {} 1641277de95eSDaniel Vetter #endif 1642eba94eb9SDaniel Vetter 1643277de95eSDaniel Vetter 1644277de95eSDaniel Vetter static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe) 16455a69b89fSDaniel Vetter { 16465a69b89fSDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 16475a69b89fSDaniel Vetter 1648277de95eSDaniel Vetter display_pipe_crc_irq_handler(dev, pipe, 16495a69b89fSDaniel Vetter I915_READ(PIPE_CRC_RES_1_IVB(pipe)), 16505a69b89fSDaniel Vetter 0, 0, 0, 0); 16515a69b89fSDaniel Vetter } 16525a69b89fSDaniel Vetter 1653277de95eSDaniel Vetter static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe) 1654eba94eb9SDaniel Vetter { 1655eba94eb9SDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 1656eba94eb9SDaniel Vetter 1657277de95eSDaniel Vetter display_pipe_crc_irq_handler(dev, pipe, 1658eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_1_IVB(pipe)), 1659eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_2_IVB(pipe)), 1660eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_3_IVB(pipe)), 1661eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_4_IVB(pipe)), 16628bc5e955SDaniel Vetter I915_READ(PIPE_CRC_RES_5_IVB(pipe))); 1663eba94eb9SDaniel Vetter } 16645b3a856bSDaniel Vetter 1665277de95eSDaniel Vetter static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe) 16665b3a856bSDaniel Vetter { 16675b3a856bSDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 16680b5c5ed0SDaniel Vetter uint32_t res1, res2; 16690b5c5ed0SDaniel Vetter 16700b5c5ed0SDaniel Vetter if (INTEL_INFO(dev)->gen >= 3) 16710b5c5ed0SDaniel Vetter res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe)); 16720b5c5ed0SDaniel Vetter else 16730b5c5ed0SDaniel Vetter res1 = 0; 16740b5c5ed0SDaniel Vetter 16750b5c5ed0SDaniel Vetter if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) 16760b5c5ed0SDaniel Vetter res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe)); 16770b5c5ed0SDaniel Vetter else 16780b5c5ed0SDaniel Vetter res2 = 0; 16795b3a856bSDaniel Vetter 1680277de95eSDaniel Vetter display_pipe_crc_irq_handler(dev, pipe, 16810b5c5ed0SDaniel Vetter I915_READ(PIPE_CRC_RES_RED(pipe)), 16820b5c5ed0SDaniel Vetter I915_READ(PIPE_CRC_RES_GREEN(pipe)), 16830b5c5ed0SDaniel Vetter I915_READ(PIPE_CRC_RES_BLUE(pipe)), 16840b5c5ed0SDaniel Vetter res1, res2); 16855b3a856bSDaniel Vetter } 16868bf1e9f1SShuang He 16871403c0d4SPaulo Zanoni /* The RPS events need forcewake, so we add them to a work queue and mask their 16881403c0d4SPaulo Zanoni * IMR bits until the work is done. Other interrupts can be processed without 16891403c0d4SPaulo Zanoni * the work queue. */ 16901403c0d4SPaulo Zanoni static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir) 1691baf02a1fSBen Widawsky { 1692132f3f17SImre Deak /* TODO: RPS on GEN9 is not supported yet. */ 1693132f3f17SImre Deak if (WARN_ONCE(INTEL_INFO(dev_priv)->gen == 9, 1694132f3f17SImre Deak "GEN9: unexpected RPS IRQ\n")) 1695132f3f17SImre Deak return; 1696132f3f17SImre Deak 1697a6706b45SDeepak S if (pm_iir & dev_priv->pm_rps_events) { 169859cdb63dSDaniel Vetter spin_lock(&dev_priv->irq_lock); 1699a6706b45SDeepak S dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events; 1700480c8033SDaniel Vetter gen6_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events); 170159cdb63dSDaniel Vetter spin_unlock(&dev_priv->irq_lock); 17022adbee62SDaniel Vetter 17032adbee62SDaniel Vetter queue_work(dev_priv->wq, &dev_priv->rps.work); 170441a05a3aSDaniel Vetter } 1705baf02a1fSBen Widawsky 1706c9a9a268SImre Deak if (INTEL_INFO(dev_priv)->gen >= 8) 1707c9a9a268SImre Deak return; 1708c9a9a268SImre Deak 17091403c0d4SPaulo Zanoni if (HAS_VEBOX(dev_priv->dev)) { 171012638c57SBen Widawsky if (pm_iir & PM_VEBOX_USER_INTERRUPT) 171112638c57SBen Widawsky notify_ring(dev_priv->dev, &dev_priv->ring[VECS]); 171212638c57SBen Widawsky 171312638c57SBen Widawsky if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) { 171458174462SMika Kuoppala i915_handle_error(dev_priv->dev, false, 171558174462SMika Kuoppala "VEBOX CS error interrupt 0x%08x", 171658174462SMika Kuoppala pm_iir); 171712638c57SBen Widawsky } 171812638c57SBen Widawsky } 17191403c0d4SPaulo Zanoni } 1720baf02a1fSBen Widawsky 17218d7849dbSVille Syrjälä static bool intel_pipe_handle_vblank(struct drm_device *dev, enum pipe pipe) 17228d7849dbSVille Syrjälä { 17238d7849dbSVille Syrjälä if (!drm_handle_vblank(dev, pipe)) 17248d7849dbSVille Syrjälä return false; 17258d7849dbSVille Syrjälä 17268d7849dbSVille Syrjälä return true; 17278d7849dbSVille Syrjälä } 17288d7849dbSVille Syrjälä 1729c1874ed7SImre Deak static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir) 17307e231dbeSJesse Barnes { 1731c1874ed7SImre Deak struct drm_i915_private *dev_priv = dev->dev_private; 173291d181ddSImre Deak u32 pipe_stats[I915_MAX_PIPES] = { }; 17337e231dbeSJesse Barnes int pipe; 17347e231dbeSJesse Barnes 173558ead0d7SImre Deak spin_lock(&dev_priv->irq_lock); 1736055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 173791d181ddSImre Deak int reg; 1738bbb5eebfSDaniel Vetter u32 mask, iir_bit = 0; 173991d181ddSImre Deak 1740bbb5eebfSDaniel Vetter /* 1741bbb5eebfSDaniel Vetter * PIPESTAT bits get signalled even when the interrupt is 1742bbb5eebfSDaniel Vetter * disabled with the mask bits, and some of the status bits do 1743bbb5eebfSDaniel Vetter * not generate interrupts at all (like the underrun bit). Hence 1744bbb5eebfSDaniel Vetter * we need to be careful that we only handle what we want to 1745bbb5eebfSDaniel Vetter * handle. 1746bbb5eebfSDaniel Vetter */ 17470f239f4cSDaniel Vetter 17480f239f4cSDaniel Vetter /* fifo underruns are filterered in the underrun handler. */ 17490f239f4cSDaniel Vetter mask = PIPE_FIFO_UNDERRUN_STATUS; 1750bbb5eebfSDaniel Vetter 1751bbb5eebfSDaniel Vetter switch (pipe) { 1752bbb5eebfSDaniel Vetter case PIPE_A: 1753bbb5eebfSDaniel Vetter iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT; 1754bbb5eebfSDaniel Vetter break; 1755bbb5eebfSDaniel Vetter case PIPE_B: 1756bbb5eebfSDaniel Vetter iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT; 1757bbb5eebfSDaniel Vetter break; 17583278f67fSVille Syrjälä case PIPE_C: 17593278f67fSVille Syrjälä iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT; 17603278f67fSVille Syrjälä break; 1761bbb5eebfSDaniel Vetter } 1762bbb5eebfSDaniel Vetter if (iir & iir_bit) 1763bbb5eebfSDaniel Vetter mask |= dev_priv->pipestat_irq_mask[pipe]; 1764bbb5eebfSDaniel Vetter 1765bbb5eebfSDaniel Vetter if (!mask) 176691d181ddSImre Deak continue; 176791d181ddSImre Deak 176891d181ddSImre Deak reg = PIPESTAT(pipe); 1769bbb5eebfSDaniel Vetter mask |= PIPESTAT_INT_ENABLE_MASK; 1770bbb5eebfSDaniel Vetter pipe_stats[pipe] = I915_READ(reg) & mask; 17717e231dbeSJesse Barnes 17727e231dbeSJesse Barnes /* 17737e231dbeSJesse Barnes * Clear the PIPE*STAT regs before the IIR 17747e231dbeSJesse Barnes */ 177591d181ddSImre Deak if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS | 177691d181ddSImre Deak PIPESTAT_INT_STATUS_MASK)) 17777e231dbeSJesse Barnes I915_WRITE(reg, pipe_stats[pipe]); 17787e231dbeSJesse Barnes } 177958ead0d7SImre Deak spin_unlock(&dev_priv->irq_lock); 17807e231dbeSJesse Barnes 1781055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 1782d6bbafa1SChris Wilson if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS && 1783d6bbafa1SChris Wilson intel_pipe_handle_vblank(dev, pipe)) 1784d6bbafa1SChris Wilson intel_check_page_flip(dev, pipe); 178531acc7f5SJesse Barnes 1786579a9b0eSImre Deak if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) { 178731acc7f5SJesse Barnes intel_prepare_page_flip(dev, pipe); 178831acc7f5SJesse Barnes intel_finish_page_flip(dev, pipe); 178931acc7f5SJesse Barnes } 17904356d586SDaniel Vetter 17914356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 1792277de95eSDaniel Vetter i9xx_pipe_crc_irq_handler(dev, pipe); 17932d9d2b0bSVille Syrjälä 17941f7247c0SDaniel Vetter if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 17951f7247c0SDaniel Vetter intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 179631acc7f5SJesse Barnes } 179731acc7f5SJesse Barnes 1798c1874ed7SImre Deak if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 1799c1874ed7SImre Deak gmbus_irq_handler(dev); 1800c1874ed7SImre Deak } 1801c1874ed7SImre Deak 180216c6c56bSVille Syrjälä static void i9xx_hpd_irq_handler(struct drm_device *dev) 180316c6c56bSVille Syrjälä { 180416c6c56bSVille Syrjälä struct drm_i915_private *dev_priv = dev->dev_private; 180516c6c56bSVille Syrjälä u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); 180616c6c56bSVille Syrjälä 18073ff60f89SOscar Mateo if (hotplug_status) { 18083ff60f89SOscar Mateo I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); 18093ff60f89SOscar Mateo /* 18103ff60f89SOscar Mateo * Make sure hotplug status is cleared before we clear IIR, or else we 18113ff60f89SOscar Mateo * may miss hotplug events. 18123ff60f89SOscar Mateo */ 18133ff60f89SOscar Mateo POSTING_READ(PORT_HOTPLUG_STAT); 18143ff60f89SOscar Mateo 181516c6c56bSVille Syrjälä if (IS_G4X(dev)) { 181616c6c56bSVille Syrjälä u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X; 181716c6c56bSVille Syrjälä 181813cf5504SDave Airlie intel_hpd_irq_handler(dev, hotplug_trigger, 0, hpd_status_g4x); 181916c6c56bSVille Syrjälä } else { 182016c6c56bSVille Syrjälä u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915; 182116c6c56bSVille Syrjälä 182213cf5504SDave Airlie intel_hpd_irq_handler(dev, hotplug_trigger, 0, hpd_status_i915); 182316c6c56bSVille Syrjälä } 182416c6c56bSVille Syrjälä 182516c6c56bSVille Syrjälä if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) && 182616c6c56bSVille Syrjälä hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X) 182716c6c56bSVille Syrjälä dp_aux_irq_handler(dev); 18283ff60f89SOscar Mateo } 182916c6c56bSVille Syrjälä } 183016c6c56bSVille Syrjälä 1831c1874ed7SImre Deak static irqreturn_t valleyview_irq_handler(int irq, void *arg) 1832c1874ed7SImre Deak { 183345a83f84SDaniel Vetter struct drm_device *dev = arg; 18342d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 1835c1874ed7SImre Deak u32 iir, gt_iir, pm_iir; 1836c1874ed7SImre Deak irqreturn_t ret = IRQ_NONE; 1837c1874ed7SImre Deak 1838c1874ed7SImre Deak while (true) { 18393ff60f89SOscar Mateo /* Find, clear, then process each source of interrupt */ 18403ff60f89SOscar Mateo 1841c1874ed7SImre Deak gt_iir = I915_READ(GTIIR); 18423ff60f89SOscar Mateo if (gt_iir) 18433ff60f89SOscar Mateo I915_WRITE(GTIIR, gt_iir); 18443ff60f89SOscar Mateo 1845c1874ed7SImre Deak pm_iir = I915_READ(GEN6_PMIIR); 18463ff60f89SOscar Mateo if (pm_iir) 18473ff60f89SOscar Mateo I915_WRITE(GEN6_PMIIR, pm_iir); 18483ff60f89SOscar Mateo 18493ff60f89SOscar Mateo iir = I915_READ(VLV_IIR); 18503ff60f89SOscar Mateo if (iir) { 18513ff60f89SOscar Mateo /* Consume port before clearing IIR or we'll miss events */ 18523ff60f89SOscar Mateo if (iir & I915_DISPLAY_PORT_INTERRUPT) 18533ff60f89SOscar Mateo i9xx_hpd_irq_handler(dev); 18543ff60f89SOscar Mateo I915_WRITE(VLV_IIR, iir); 18553ff60f89SOscar Mateo } 1856c1874ed7SImre Deak 1857c1874ed7SImre Deak if (gt_iir == 0 && pm_iir == 0 && iir == 0) 1858c1874ed7SImre Deak goto out; 1859c1874ed7SImre Deak 1860c1874ed7SImre Deak ret = IRQ_HANDLED; 1861c1874ed7SImre Deak 18623ff60f89SOscar Mateo if (gt_iir) 1863c1874ed7SImre Deak snb_gt_irq_handler(dev, dev_priv, gt_iir); 186460611c13SPaulo Zanoni if (pm_iir) 1865d0ecd7e2SDaniel Vetter gen6_rps_irq_handler(dev_priv, pm_iir); 18663ff60f89SOscar Mateo /* Call regardless, as some status bits might not be 18673ff60f89SOscar Mateo * signalled in iir */ 18683ff60f89SOscar Mateo valleyview_pipestat_irq_handler(dev, iir); 18697e231dbeSJesse Barnes } 18707e231dbeSJesse Barnes 18717e231dbeSJesse Barnes out: 18727e231dbeSJesse Barnes return ret; 18737e231dbeSJesse Barnes } 18747e231dbeSJesse Barnes 187543f328d7SVille Syrjälä static irqreturn_t cherryview_irq_handler(int irq, void *arg) 187643f328d7SVille Syrjälä { 187745a83f84SDaniel Vetter struct drm_device *dev = arg; 187843f328d7SVille Syrjälä struct drm_i915_private *dev_priv = dev->dev_private; 187943f328d7SVille Syrjälä u32 master_ctl, iir; 188043f328d7SVille Syrjälä irqreturn_t ret = IRQ_NONE; 188143f328d7SVille Syrjälä 18828e5fd599SVille Syrjälä for (;;) { 18838e5fd599SVille Syrjälä master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL; 18843278f67fSVille Syrjälä iir = I915_READ(VLV_IIR); 18853278f67fSVille Syrjälä 18863278f67fSVille Syrjälä if (master_ctl == 0 && iir == 0) 18878e5fd599SVille Syrjälä break; 188843f328d7SVille Syrjälä 188927b6c122SOscar Mateo ret = IRQ_HANDLED; 189027b6c122SOscar Mateo 189143f328d7SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, 0); 189243f328d7SVille Syrjälä 189327b6c122SOscar Mateo /* Find, clear, then process each source of interrupt */ 189427b6c122SOscar Mateo 189527b6c122SOscar Mateo if (iir) { 189627b6c122SOscar Mateo /* Consume port before clearing IIR or we'll miss events */ 189727b6c122SOscar Mateo if (iir & I915_DISPLAY_PORT_INTERRUPT) 189827b6c122SOscar Mateo i9xx_hpd_irq_handler(dev); 189927b6c122SOscar Mateo I915_WRITE(VLV_IIR, iir); 190027b6c122SOscar Mateo } 190127b6c122SOscar Mateo 19023278f67fSVille Syrjälä gen8_gt_irq_handler(dev, dev_priv, master_ctl); 190343f328d7SVille Syrjälä 190427b6c122SOscar Mateo /* Call regardless, as some status bits might not be 190527b6c122SOscar Mateo * signalled in iir */ 19063278f67fSVille Syrjälä valleyview_pipestat_irq_handler(dev, iir); 190743f328d7SVille Syrjälä 190843f328d7SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL); 190943f328d7SVille Syrjälä POSTING_READ(GEN8_MASTER_IRQ); 19108e5fd599SVille Syrjälä } 19113278f67fSVille Syrjälä 191243f328d7SVille Syrjälä return ret; 191343f328d7SVille Syrjälä } 191443f328d7SVille Syrjälä 191523e81d69SAdam Jackson static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir) 1916776ad806SJesse Barnes { 19172d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 19189db4a9c7SJesse Barnes int pipe; 1919b543fb04SEgbert Eich u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK; 192013cf5504SDave Airlie u32 dig_hotplug_reg; 1921776ad806SJesse Barnes 192213cf5504SDave Airlie dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG); 192313cf5504SDave Airlie I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg); 192413cf5504SDave Airlie 192513cf5504SDave Airlie intel_hpd_irq_handler(dev, hotplug_trigger, dig_hotplug_reg, hpd_ibx); 192691d131d2SDaniel Vetter 1927cfc33bf7SVille Syrjälä if (pch_iir & SDE_AUDIO_POWER_MASK) { 1928cfc33bf7SVille Syrjälä int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >> 1929776ad806SJesse Barnes SDE_AUDIO_POWER_SHIFT); 1930cfc33bf7SVille Syrjälä DRM_DEBUG_DRIVER("PCH audio power change on port %d\n", 1931cfc33bf7SVille Syrjälä port_name(port)); 1932cfc33bf7SVille Syrjälä } 1933776ad806SJesse Barnes 1934ce99c256SDaniel Vetter if (pch_iir & SDE_AUX_MASK) 1935ce99c256SDaniel Vetter dp_aux_irq_handler(dev); 1936ce99c256SDaniel Vetter 1937776ad806SJesse Barnes if (pch_iir & SDE_GMBUS) 1938515ac2bbSDaniel Vetter gmbus_irq_handler(dev); 1939776ad806SJesse Barnes 1940776ad806SJesse Barnes if (pch_iir & SDE_AUDIO_HDCP_MASK) 1941776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n"); 1942776ad806SJesse Barnes 1943776ad806SJesse Barnes if (pch_iir & SDE_AUDIO_TRANS_MASK) 1944776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n"); 1945776ad806SJesse Barnes 1946776ad806SJesse Barnes if (pch_iir & SDE_POISON) 1947776ad806SJesse Barnes DRM_ERROR("PCH poison interrupt\n"); 1948776ad806SJesse Barnes 19499db4a9c7SJesse Barnes if (pch_iir & SDE_FDI_MASK) 1950055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 19519db4a9c7SJesse Barnes DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", 19529db4a9c7SJesse Barnes pipe_name(pipe), 19539db4a9c7SJesse Barnes I915_READ(FDI_RX_IIR(pipe))); 1954776ad806SJesse Barnes 1955776ad806SJesse Barnes if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE)) 1956776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n"); 1957776ad806SJesse Barnes 1958776ad806SJesse Barnes if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR)) 1959776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n"); 1960776ad806SJesse Barnes 1961776ad806SJesse Barnes if (pch_iir & SDE_TRANSA_FIFO_UNDER) 19621f7247c0SDaniel Vetter intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A); 19638664281bSPaulo Zanoni 19648664281bSPaulo Zanoni if (pch_iir & SDE_TRANSB_FIFO_UNDER) 19651f7247c0SDaniel Vetter intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B); 19668664281bSPaulo Zanoni } 19678664281bSPaulo Zanoni 19688664281bSPaulo Zanoni static void ivb_err_int_handler(struct drm_device *dev) 19698664281bSPaulo Zanoni { 19708664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 19718664281bSPaulo Zanoni u32 err_int = I915_READ(GEN7_ERR_INT); 19725a69b89fSDaniel Vetter enum pipe pipe; 19738664281bSPaulo Zanoni 1974de032bf4SPaulo Zanoni if (err_int & ERR_INT_POISON) 1975de032bf4SPaulo Zanoni DRM_ERROR("Poison interrupt\n"); 1976de032bf4SPaulo Zanoni 1977055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 19781f7247c0SDaniel Vetter if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) 19791f7247c0SDaniel Vetter intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 19808664281bSPaulo Zanoni 19815a69b89fSDaniel Vetter if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) { 19825a69b89fSDaniel Vetter if (IS_IVYBRIDGE(dev)) 1983277de95eSDaniel Vetter ivb_pipe_crc_irq_handler(dev, pipe); 19845a69b89fSDaniel Vetter else 1985277de95eSDaniel Vetter hsw_pipe_crc_irq_handler(dev, pipe); 19865a69b89fSDaniel Vetter } 19875a69b89fSDaniel Vetter } 19888bf1e9f1SShuang He 19898664281bSPaulo Zanoni I915_WRITE(GEN7_ERR_INT, err_int); 19908664281bSPaulo Zanoni } 19918664281bSPaulo Zanoni 19928664281bSPaulo Zanoni static void cpt_serr_int_handler(struct drm_device *dev) 19938664281bSPaulo Zanoni { 19948664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 19958664281bSPaulo Zanoni u32 serr_int = I915_READ(SERR_INT); 19968664281bSPaulo Zanoni 1997de032bf4SPaulo Zanoni if (serr_int & SERR_INT_POISON) 1998de032bf4SPaulo Zanoni DRM_ERROR("PCH poison interrupt\n"); 1999de032bf4SPaulo Zanoni 20008664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN) 20011f7247c0SDaniel Vetter intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A); 20028664281bSPaulo Zanoni 20038664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN) 20041f7247c0SDaniel Vetter intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B); 20058664281bSPaulo Zanoni 20068664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN) 20071f7247c0SDaniel Vetter intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_C); 20088664281bSPaulo Zanoni 20098664281bSPaulo Zanoni I915_WRITE(SERR_INT, serr_int); 2010776ad806SJesse Barnes } 2011776ad806SJesse Barnes 201223e81d69SAdam Jackson static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir) 201323e81d69SAdam Jackson { 20142d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 201523e81d69SAdam Jackson int pipe; 2016b543fb04SEgbert Eich u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT; 201713cf5504SDave Airlie u32 dig_hotplug_reg; 201823e81d69SAdam Jackson 201913cf5504SDave Airlie dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG); 202013cf5504SDave Airlie I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg); 202113cf5504SDave Airlie 202213cf5504SDave Airlie intel_hpd_irq_handler(dev, hotplug_trigger, dig_hotplug_reg, hpd_cpt); 202391d131d2SDaniel Vetter 2024cfc33bf7SVille Syrjälä if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) { 2025cfc33bf7SVille Syrjälä int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >> 202623e81d69SAdam Jackson SDE_AUDIO_POWER_SHIFT_CPT); 2027cfc33bf7SVille Syrjälä DRM_DEBUG_DRIVER("PCH audio power change on port %c\n", 2028cfc33bf7SVille Syrjälä port_name(port)); 2029cfc33bf7SVille Syrjälä } 203023e81d69SAdam Jackson 203123e81d69SAdam Jackson if (pch_iir & SDE_AUX_MASK_CPT) 2032ce99c256SDaniel Vetter dp_aux_irq_handler(dev); 203323e81d69SAdam Jackson 203423e81d69SAdam Jackson if (pch_iir & SDE_GMBUS_CPT) 2035515ac2bbSDaniel Vetter gmbus_irq_handler(dev); 203623e81d69SAdam Jackson 203723e81d69SAdam Jackson if (pch_iir & SDE_AUDIO_CP_REQ_CPT) 203823e81d69SAdam Jackson DRM_DEBUG_DRIVER("Audio CP request interrupt\n"); 203923e81d69SAdam Jackson 204023e81d69SAdam Jackson if (pch_iir & SDE_AUDIO_CP_CHG_CPT) 204123e81d69SAdam Jackson DRM_DEBUG_DRIVER("Audio CP change interrupt\n"); 204223e81d69SAdam Jackson 204323e81d69SAdam Jackson if (pch_iir & SDE_FDI_MASK_CPT) 2044055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 204523e81d69SAdam Jackson DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", 204623e81d69SAdam Jackson pipe_name(pipe), 204723e81d69SAdam Jackson I915_READ(FDI_RX_IIR(pipe))); 20488664281bSPaulo Zanoni 20498664281bSPaulo Zanoni if (pch_iir & SDE_ERROR_CPT) 20508664281bSPaulo Zanoni cpt_serr_int_handler(dev); 205123e81d69SAdam Jackson } 205223e81d69SAdam Jackson 2053c008bc6eSPaulo Zanoni static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir) 2054c008bc6eSPaulo Zanoni { 2055c008bc6eSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 205640da17c2SDaniel Vetter enum pipe pipe; 2057c008bc6eSPaulo Zanoni 2058c008bc6eSPaulo Zanoni if (de_iir & DE_AUX_CHANNEL_A) 2059c008bc6eSPaulo Zanoni dp_aux_irq_handler(dev); 2060c008bc6eSPaulo Zanoni 2061c008bc6eSPaulo Zanoni if (de_iir & DE_GSE) 2062c008bc6eSPaulo Zanoni intel_opregion_asle_intr(dev); 2063c008bc6eSPaulo Zanoni 2064c008bc6eSPaulo Zanoni if (de_iir & DE_POISON) 2065c008bc6eSPaulo Zanoni DRM_ERROR("Poison interrupt\n"); 2066c008bc6eSPaulo Zanoni 2067055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 2068d6bbafa1SChris Wilson if (de_iir & DE_PIPE_VBLANK(pipe) && 2069d6bbafa1SChris Wilson intel_pipe_handle_vblank(dev, pipe)) 2070d6bbafa1SChris Wilson intel_check_page_flip(dev, pipe); 2071c008bc6eSPaulo Zanoni 207240da17c2SDaniel Vetter if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe)) 20731f7247c0SDaniel Vetter intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 2074c008bc6eSPaulo Zanoni 207540da17c2SDaniel Vetter if (de_iir & DE_PIPE_CRC_DONE(pipe)) 207640da17c2SDaniel Vetter i9xx_pipe_crc_irq_handler(dev, pipe); 20775b3a856bSDaniel Vetter 207840da17c2SDaniel Vetter /* plane/pipes map 1:1 on ilk+ */ 207940da17c2SDaniel Vetter if (de_iir & DE_PLANE_FLIP_DONE(pipe)) { 208040da17c2SDaniel Vetter intel_prepare_page_flip(dev, pipe); 208140da17c2SDaniel Vetter intel_finish_page_flip_plane(dev, pipe); 2082c008bc6eSPaulo Zanoni } 2083c008bc6eSPaulo Zanoni } 2084c008bc6eSPaulo Zanoni 2085c008bc6eSPaulo Zanoni /* check event from PCH */ 2086c008bc6eSPaulo Zanoni if (de_iir & DE_PCH_EVENT) { 2087c008bc6eSPaulo Zanoni u32 pch_iir = I915_READ(SDEIIR); 2088c008bc6eSPaulo Zanoni 2089c008bc6eSPaulo Zanoni if (HAS_PCH_CPT(dev)) 2090c008bc6eSPaulo Zanoni cpt_irq_handler(dev, pch_iir); 2091c008bc6eSPaulo Zanoni else 2092c008bc6eSPaulo Zanoni ibx_irq_handler(dev, pch_iir); 2093c008bc6eSPaulo Zanoni 2094c008bc6eSPaulo Zanoni /* should clear PCH hotplug event before clear CPU irq */ 2095c008bc6eSPaulo Zanoni I915_WRITE(SDEIIR, pch_iir); 2096c008bc6eSPaulo Zanoni } 2097c008bc6eSPaulo Zanoni 2098c008bc6eSPaulo Zanoni if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT) 2099c008bc6eSPaulo Zanoni ironlake_rps_change_irq_handler(dev); 2100c008bc6eSPaulo Zanoni } 2101c008bc6eSPaulo Zanoni 21029719fb98SPaulo Zanoni static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir) 21039719fb98SPaulo Zanoni { 21049719fb98SPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 210507d27e20SDamien Lespiau enum pipe pipe; 21069719fb98SPaulo Zanoni 21079719fb98SPaulo Zanoni if (de_iir & DE_ERR_INT_IVB) 21089719fb98SPaulo Zanoni ivb_err_int_handler(dev); 21099719fb98SPaulo Zanoni 21109719fb98SPaulo Zanoni if (de_iir & DE_AUX_CHANNEL_A_IVB) 21119719fb98SPaulo Zanoni dp_aux_irq_handler(dev); 21129719fb98SPaulo Zanoni 21139719fb98SPaulo Zanoni if (de_iir & DE_GSE_IVB) 21149719fb98SPaulo Zanoni intel_opregion_asle_intr(dev); 21159719fb98SPaulo Zanoni 2116055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 2117d6bbafa1SChris Wilson if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)) && 2118d6bbafa1SChris Wilson intel_pipe_handle_vblank(dev, pipe)) 2119d6bbafa1SChris Wilson intel_check_page_flip(dev, pipe); 212040da17c2SDaniel Vetter 212140da17c2SDaniel Vetter /* plane/pipes map 1:1 on ilk+ */ 212207d27e20SDamien Lespiau if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) { 212307d27e20SDamien Lespiau intel_prepare_page_flip(dev, pipe); 212407d27e20SDamien Lespiau intel_finish_page_flip_plane(dev, pipe); 21259719fb98SPaulo Zanoni } 21269719fb98SPaulo Zanoni } 21279719fb98SPaulo Zanoni 21289719fb98SPaulo Zanoni /* check event from PCH */ 21299719fb98SPaulo Zanoni if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) { 21309719fb98SPaulo Zanoni u32 pch_iir = I915_READ(SDEIIR); 21319719fb98SPaulo Zanoni 21329719fb98SPaulo Zanoni cpt_irq_handler(dev, pch_iir); 21339719fb98SPaulo Zanoni 21349719fb98SPaulo Zanoni /* clear PCH hotplug event before clear CPU irq */ 21359719fb98SPaulo Zanoni I915_WRITE(SDEIIR, pch_iir); 21369719fb98SPaulo Zanoni } 21379719fb98SPaulo Zanoni } 21389719fb98SPaulo Zanoni 213972c90f62SOscar Mateo /* 214072c90f62SOscar Mateo * To handle irqs with the minimum potential races with fresh interrupts, we: 214172c90f62SOscar Mateo * 1 - Disable Master Interrupt Control. 214272c90f62SOscar Mateo * 2 - Find the source(s) of the interrupt. 214372c90f62SOscar Mateo * 3 - Clear the Interrupt Identity bits (IIR). 214472c90f62SOscar Mateo * 4 - Process the interrupt(s) that had bits set in the IIRs. 214572c90f62SOscar Mateo * 5 - Re-enable Master Interrupt Control. 214672c90f62SOscar Mateo */ 2147f1af8fc1SPaulo Zanoni static irqreturn_t ironlake_irq_handler(int irq, void *arg) 2148b1f14ad0SJesse Barnes { 214945a83f84SDaniel Vetter struct drm_device *dev = arg; 21502d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 2151f1af8fc1SPaulo Zanoni u32 de_iir, gt_iir, de_ier, sde_ier = 0; 21520e43406bSChris Wilson irqreturn_t ret = IRQ_NONE; 2153b1f14ad0SJesse Barnes 21548664281bSPaulo Zanoni /* We get interrupts on unclaimed registers, so check for this before we 21558664281bSPaulo Zanoni * do any I915_{READ,WRITE}. */ 2156907b28c5SChris Wilson intel_uncore_check_errors(dev); 21578664281bSPaulo Zanoni 2158b1f14ad0SJesse Barnes /* disable master interrupt before clearing iir */ 2159b1f14ad0SJesse Barnes de_ier = I915_READ(DEIER); 2160b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL); 216123a78516SPaulo Zanoni POSTING_READ(DEIER); 21620e43406bSChris Wilson 216344498aeaSPaulo Zanoni /* Disable south interrupts. We'll only write to SDEIIR once, so further 216444498aeaSPaulo Zanoni * interrupts will will be stored on its back queue, and then we'll be 216544498aeaSPaulo Zanoni * able to process them after we restore SDEIER (as soon as we restore 216644498aeaSPaulo Zanoni * it, we'll get an interrupt if SDEIIR still has something to process 216744498aeaSPaulo Zanoni * due to its back queue). */ 2168ab5c608bSBen Widawsky if (!HAS_PCH_NOP(dev)) { 216944498aeaSPaulo Zanoni sde_ier = I915_READ(SDEIER); 217044498aeaSPaulo Zanoni I915_WRITE(SDEIER, 0); 217144498aeaSPaulo Zanoni POSTING_READ(SDEIER); 2172ab5c608bSBen Widawsky } 217344498aeaSPaulo Zanoni 217472c90f62SOscar Mateo /* Find, clear, then process each source of interrupt */ 217572c90f62SOscar Mateo 21760e43406bSChris Wilson gt_iir = I915_READ(GTIIR); 21770e43406bSChris Wilson if (gt_iir) { 217872c90f62SOscar Mateo I915_WRITE(GTIIR, gt_iir); 217972c90f62SOscar Mateo ret = IRQ_HANDLED; 2180d8fc8a47SPaulo Zanoni if (INTEL_INFO(dev)->gen >= 6) 21810e43406bSChris Wilson snb_gt_irq_handler(dev, dev_priv, gt_iir); 2182d8fc8a47SPaulo Zanoni else 2183d8fc8a47SPaulo Zanoni ilk_gt_irq_handler(dev, dev_priv, gt_iir); 21840e43406bSChris Wilson } 2185b1f14ad0SJesse Barnes 2186b1f14ad0SJesse Barnes de_iir = I915_READ(DEIIR); 21870e43406bSChris Wilson if (de_iir) { 218872c90f62SOscar Mateo I915_WRITE(DEIIR, de_iir); 218972c90f62SOscar Mateo ret = IRQ_HANDLED; 2190f1af8fc1SPaulo Zanoni if (INTEL_INFO(dev)->gen >= 7) 21919719fb98SPaulo Zanoni ivb_display_irq_handler(dev, de_iir); 2192f1af8fc1SPaulo Zanoni else 2193f1af8fc1SPaulo Zanoni ilk_display_irq_handler(dev, de_iir); 21940e43406bSChris Wilson } 21950e43406bSChris Wilson 2196f1af8fc1SPaulo Zanoni if (INTEL_INFO(dev)->gen >= 6) { 2197f1af8fc1SPaulo Zanoni u32 pm_iir = I915_READ(GEN6_PMIIR); 21980e43406bSChris Wilson if (pm_iir) { 2199b1f14ad0SJesse Barnes I915_WRITE(GEN6_PMIIR, pm_iir); 22000e43406bSChris Wilson ret = IRQ_HANDLED; 220172c90f62SOscar Mateo gen6_rps_irq_handler(dev_priv, pm_iir); 22020e43406bSChris Wilson } 2203f1af8fc1SPaulo Zanoni } 2204b1f14ad0SJesse Barnes 2205b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier); 2206b1f14ad0SJesse Barnes POSTING_READ(DEIER); 2207ab5c608bSBen Widawsky if (!HAS_PCH_NOP(dev)) { 220844498aeaSPaulo Zanoni I915_WRITE(SDEIER, sde_ier); 220944498aeaSPaulo Zanoni POSTING_READ(SDEIER); 2210ab5c608bSBen Widawsky } 2211b1f14ad0SJesse Barnes 2212b1f14ad0SJesse Barnes return ret; 2213b1f14ad0SJesse Barnes } 2214b1f14ad0SJesse Barnes 2215abd58f01SBen Widawsky static irqreturn_t gen8_irq_handler(int irq, void *arg) 2216abd58f01SBen Widawsky { 2217abd58f01SBen Widawsky struct drm_device *dev = arg; 2218abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 2219abd58f01SBen Widawsky u32 master_ctl; 2220abd58f01SBen Widawsky irqreturn_t ret = IRQ_NONE; 2221abd58f01SBen Widawsky uint32_t tmp = 0; 2222c42664ccSDaniel Vetter enum pipe pipe; 222388e04703SJesse Barnes u32 aux_mask = GEN8_AUX_CHANNEL_A; 222488e04703SJesse Barnes 222588e04703SJesse Barnes if (IS_GEN9(dev)) 222688e04703SJesse Barnes aux_mask |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C | 222788e04703SJesse Barnes GEN9_AUX_CHANNEL_D; 2228abd58f01SBen Widawsky 2229abd58f01SBen Widawsky master_ctl = I915_READ(GEN8_MASTER_IRQ); 2230abd58f01SBen Widawsky master_ctl &= ~GEN8_MASTER_IRQ_CONTROL; 2231abd58f01SBen Widawsky if (!master_ctl) 2232abd58f01SBen Widawsky return IRQ_NONE; 2233abd58f01SBen Widawsky 2234abd58f01SBen Widawsky I915_WRITE(GEN8_MASTER_IRQ, 0); 2235abd58f01SBen Widawsky POSTING_READ(GEN8_MASTER_IRQ); 2236abd58f01SBen Widawsky 223738cc46d7SOscar Mateo /* Find, clear, then process each source of interrupt */ 223838cc46d7SOscar Mateo 2239abd58f01SBen Widawsky ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl); 2240abd58f01SBen Widawsky 2241abd58f01SBen Widawsky if (master_ctl & GEN8_DE_MISC_IRQ) { 2242abd58f01SBen Widawsky tmp = I915_READ(GEN8_DE_MISC_IIR); 2243abd58f01SBen Widawsky if (tmp) { 2244abd58f01SBen Widawsky I915_WRITE(GEN8_DE_MISC_IIR, tmp); 2245abd58f01SBen Widawsky ret = IRQ_HANDLED; 224638cc46d7SOscar Mateo if (tmp & GEN8_DE_MISC_GSE) 224738cc46d7SOscar Mateo intel_opregion_asle_intr(dev); 224838cc46d7SOscar Mateo else 224938cc46d7SOscar Mateo DRM_ERROR("Unexpected DE Misc interrupt\n"); 2250abd58f01SBen Widawsky } 225138cc46d7SOscar Mateo else 225238cc46d7SOscar Mateo DRM_ERROR("The master control interrupt lied (DE MISC)!\n"); 2253abd58f01SBen Widawsky } 2254abd58f01SBen Widawsky 22556d766f02SDaniel Vetter if (master_ctl & GEN8_DE_PORT_IRQ) { 22566d766f02SDaniel Vetter tmp = I915_READ(GEN8_DE_PORT_IIR); 22576d766f02SDaniel Vetter if (tmp) { 22586d766f02SDaniel Vetter I915_WRITE(GEN8_DE_PORT_IIR, tmp); 22596d766f02SDaniel Vetter ret = IRQ_HANDLED; 226088e04703SJesse Barnes 226188e04703SJesse Barnes if (tmp & aux_mask) 226238cc46d7SOscar Mateo dp_aux_irq_handler(dev); 226338cc46d7SOscar Mateo else 226438cc46d7SOscar Mateo DRM_ERROR("Unexpected DE Port interrupt\n"); 22656d766f02SDaniel Vetter } 226638cc46d7SOscar Mateo else 226738cc46d7SOscar Mateo DRM_ERROR("The master control interrupt lied (DE PORT)!\n"); 22686d766f02SDaniel Vetter } 22696d766f02SDaniel Vetter 2270055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 2271770de83dSDamien Lespiau uint32_t pipe_iir, flip_done = 0, fault_errors = 0; 2272abd58f01SBen Widawsky 2273c42664ccSDaniel Vetter if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe))) 2274c42664ccSDaniel Vetter continue; 2275c42664ccSDaniel Vetter 2276abd58f01SBen Widawsky pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe)); 227738cc46d7SOscar Mateo if (pipe_iir) { 227838cc46d7SOscar Mateo ret = IRQ_HANDLED; 227938cc46d7SOscar Mateo I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir); 2280770de83dSDamien Lespiau 2281d6bbafa1SChris Wilson if (pipe_iir & GEN8_PIPE_VBLANK && 2282d6bbafa1SChris Wilson intel_pipe_handle_vblank(dev, pipe)) 2283d6bbafa1SChris Wilson intel_check_page_flip(dev, pipe); 2284abd58f01SBen Widawsky 2285770de83dSDamien Lespiau if (IS_GEN9(dev)) 2286770de83dSDamien Lespiau flip_done = pipe_iir & GEN9_PIPE_PLANE1_FLIP_DONE; 2287770de83dSDamien Lespiau else 2288770de83dSDamien Lespiau flip_done = pipe_iir & GEN8_PIPE_PRIMARY_FLIP_DONE; 2289770de83dSDamien Lespiau 2290770de83dSDamien Lespiau if (flip_done) { 2291abd58f01SBen Widawsky intel_prepare_page_flip(dev, pipe); 2292abd58f01SBen Widawsky intel_finish_page_flip_plane(dev, pipe); 2293abd58f01SBen Widawsky } 2294abd58f01SBen Widawsky 22950fbe7870SDaniel Vetter if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE) 22960fbe7870SDaniel Vetter hsw_pipe_crc_irq_handler(dev, pipe); 22970fbe7870SDaniel Vetter 22981f7247c0SDaniel Vetter if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN) 22991f7247c0SDaniel Vetter intel_cpu_fifo_underrun_irq_handler(dev_priv, 23001f7247c0SDaniel Vetter pipe); 230138d83c96SDaniel Vetter 2302770de83dSDamien Lespiau 2303770de83dSDamien Lespiau if (IS_GEN9(dev)) 2304770de83dSDamien Lespiau fault_errors = pipe_iir & GEN9_DE_PIPE_IRQ_FAULT_ERRORS; 2305770de83dSDamien Lespiau else 2306770de83dSDamien Lespiau fault_errors = pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS; 2307770de83dSDamien Lespiau 2308770de83dSDamien Lespiau if (fault_errors) 230930100f2bSDaniel Vetter DRM_ERROR("Fault errors on pipe %c\n: 0x%08x", 231030100f2bSDaniel Vetter pipe_name(pipe), 231130100f2bSDaniel Vetter pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS); 2312c42664ccSDaniel Vetter } else 2313abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (DE PIPE)!\n"); 2314abd58f01SBen Widawsky } 2315abd58f01SBen Widawsky 231692d03a80SDaniel Vetter if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) { 231792d03a80SDaniel Vetter /* 231892d03a80SDaniel Vetter * FIXME(BDW): Assume for now that the new interrupt handling 231992d03a80SDaniel Vetter * scheme also closed the SDE interrupt handling race we've seen 232092d03a80SDaniel Vetter * on older pch-split platforms. But this needs testing. 232192d03a80SDaniel Vetter */ 232292d03a80SDaniel Vetter u32 pch_iir = I915_READ(SDEIIR); 232392d03a80SDaniel Vetter if (pch_iir) { 232492d03a80SDaniel Vetter I915_WRITE(SDEIIR, pch_iir); 232592d03a80SDaniel Vetter ret = IRQ_HANDLED; 232638cc46d7SOscar Mateo cpt_irq_handler(dev, pch_iir); 232738cc46d7SOscar Mateo } else 232838cc46d7SOscar Mateo DRM_ERROR("The master control interrupt lied (SDE)!\n"); 232938cc46d7SOscar Mateo 233092d03a80SDaniel Vetter } 233192d03a80SDaniel Vetter 2332abd58f01SBen Widawsky I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); 2333abd58f01SBen Widawsky POSTING_READ(GEN8_MASTER_IRQ); 2334abd58f01SBen Widawsky 2335abd58f01SBen Widawsky return ret; 2336abd58f01SBen Widawsky } 2337abd58f01SBen Widawsky 233817e1df07SDaniel Vetter static void i915_error_wake_up(struct drm_i915_private *dev_priv, 233917e1df07SDaniel Vetter bool reset_completed) 234017e1df07SDaniel Vetter { 2341a4872ba6SOscar Mateo struct intel_engine_cs *ring; 234217e1df07SDaniel Vetter int i; 234317e1df07SDaniel Vetter 234417e1df07SDaniel Vetter /* 234517e1df07SDaniel Vetter * Notify all waiters for GPU completion events that reset state has 234617e1df07SDaniel Vetter * been changed, and that they need to restart their wait after 234717e1df07SDaniel Vetter * checking for potential errors (and bail out to drop locks if there is 234817e1df07SDaniel Vetter * a gpu reset pending so that i915_error_work_func can acquire them). 234917e1df07SDaniel Vetter */ 235017e1df07SDaniel Vetter 235117e1df07SDaniel Vetter /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */ 235217e1df07SDaniel Vetter for_each_ring(ring, dev_priv, i) 235317e1df07SDaniel Vetter wake_up_all(&ring->irq_queue); 235417e1df07SDaniel Vetter 235517e1df07SDaniel Vetter /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */ 235617e1df07SDaniel Vetter wake_up_all(&dev_priv->pending_flip_queue); 235717e1df07SDaniel Vetter 235817e1df07SDaniel Vetter /* 235917e1df07SDaniel Vetter * Signal tasks blocked in i915_gem_wait_for_error that the pending 236017e1df07SDaniel Vetter * reset state is cleared. 236117e1df07SDaniel Vetter */ 236217e1df07SDaniel Vetter if (reset_completed) 236317e1df07SDaniel Vetter wake_up_all(&dev_priv->gpu_error.reset_queue); 236417e1df07SDaniel Vetter } 236517e1df07SDaniel Vetter 23668a905236SJesse Barnes /** 23678a905236SJesse Barnes * i915_error_work_func - do process context error handling work 23688a905236SJesse Barnes * @work: work struct 23698a905236SJesse Barnes * 23708a905236SJesse Barnes * Fire an error uevent so userspace can see that a hang or error 23718a905236SJesse Barnes * was detected. 23728a905236SJesse Barnes */ 23738a905236SJesse Barnes static void i915_error_work_func(struct work_struct *work) 23748a905236SJesse Barnes { 23751f83fee0SDaniel Vetter struct i915_gpu_error *error = container_of(work, struct i915_gpu_error, 23761f83fee0SDaniel Vetter work); 23772d1013ddSJani Nikula struct drm_i915_private *dev_priv = 23782d1013ddSJani Nikula container_of(error, struct drm_i915_private, gpu_error); 23798a905236SJesse Barnes struct drm_device *dev = dev_priv->dev; 2380cce723edSBen Widawsky char *error_event[] = { I915_ERROR_UEVENT "=1", NULL }; 2381cce723edSBen Widawsky char *reset_event[] = { I915_RESET_UEVENT "=1", NULL }; 2382cce723edSBen Widawsky char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL }; 238317e1df07SDaniel Vetter int ret; 23848a905236SJesse Barnes 23855bdebb18SDave Airlie kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event); 23868a905236SJesse Barnes 23877db0ba24SDaniel Vetter /* 23887db0ba24SDaniel Vetter * Note that there's only one work item which does gpu resets, so we 23897db0ba24SDaniel Vetter * need not worry about concurrent gpu resets potentially incrementing 23907db0ba24SDaniel Vetter * error->reset_counter twice. We only need to take care of another 23917db0ba24SDaniel Vetter * racing irq/hangcheck declaring the gpu dead for a second time. A 23927db0ba24SDaniel Vetter * quick check for that is good enough: schedule_work ensures the 23937db0ba24SDaniel Vetter * correct ordering between hang detection and this work item, and since 23947db0ba24SDaniel Vetter * the reset in-progress bit is only ever set by code outside of this 23957db0ba24SDaniel Vetter * work we don't need to worry about any other races. 23967db0ba24SDaniel Vetter */ 23977db0ba24SDaniel Vetter if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) { 239844d98a61SZhao Yakui DRM_DEBUG_DRIVER("resetting chip\n"); 23995bdebb18SDave Airlie kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, 24007db0ba24SDaniel Vetter reset_event); 24011f83fee0SDaniel Vetter 240217e1df07SDaniel Vetter /* 2403f454c694SImre Deak * In most cases it's guaranteed that we get here with an RPM 2404f454c694SImre Deak * reference held, for example because there is a pending GPU 2405f454c694SImre Deak * request that won't finish until the reset is done. This 2406f454c694SImre Deak * isn't the case at least when we get here by doing a 2407f454c694SImre Deak * simulated reset via debugs, so get an RPM reference. 2408f454c694SImre Deak */ 2409f454c694SImre Deak intel_runtime_pm_get(dev_priv); 2410f454c694SImre Deak /* 241117e1df07SDaniel Vetter * All state reset _must_ be completed before we update the 241217e1df07SDaniel Vetter * reset counter, for otherwise waiters might miss the reset 241317e1df07SDaniel Vetter * pending state and not properly drop locks, resulting in 241417e1df07SDaniel Vetter * deadlocks with the reset work. 241517e1df07SDaniel Vetter */ 2416f69061beSDaniel Vetter ret = i915_reset(dev); 2417f69061beSDaniel Vetter 241817e1df07SDaniel Vetter intel_display_handle_reset(dev); 241917e1df07SDaniel Vetter 2420f454c694SImre Deak intel_runtime_pm_put(dev_priv); 2421f454c694SImre Deak 2422f69061beSDaniel Vetter if (ret == 0) { 2423f69061beSDaniel Vetter /* 2424f69061beSDaniel Vetter * After all the gem state is reset, increment the reset 2425f69061beSDaniel Vetter * counter and wake up everyone waiting for the reset to 2426f69061beSDaniel Vetter * complete. 2427f69061beSDaniel Vetter * 2428f69061beSDaniel Vetter * Since unlock operations are a one-sided barrier only, 2429f69061beSDaniel Vetter * we need to insert a barrier here to order any seqno 2430f69061beSDaniel Vetter * updates before 2431f69061beSDaniel Vetter * the counter increment. 2432f69061beSDaniel Vetter */ 24334e857c58SPeter Zijlstra smp_mb__before_atomic(); 2434f69061beSDaniel Vetter atomic_inc(&dev_priv->gpu_error.reset_counter); 2435f69061beSDaniel Vetter 24365bdebb18SDave Airlie kobject_uevent_env(&dev->primary->kdev->kobj, 2437f69061beSDaniel Vetter KOBJ_CHANGE, reset_done_event); 24381f83fee0SDaniel Vetter } else { 24392ac0f450SMika Kuoppala atomic_set_mask(I915_WEDGED, &error->reset_counter); 2440f316a42cSBen Gamari } 24411f83fee0SDaniel Vetter 244217e1df07SDaniel Vetter /* 244317e1df07SDaniel Vetter * Note: The wake_up also serves as a memory barrier so that 244417e1df07SDaniel Vetter * waiters see the update value of the reset counter atomic_t. 244517e1df07SDaniel Vetter */ 244617e1df07SDaniel Vetter i915_error_wake_up(dev_priv, true); 2447f316a42cSBen Gamari } 24488a905236SJesse Barnes } 24498a905236SJesse Barnes 245035aed2e6SChris Wilson static void i915_report_and_clear_eir(struct drm_device *dev) 2451c0e09200SDave Airlie { 24528a905236SJesse Barnes struct drm_i915_private *dev_priv = dev->dev_private; 2453bd9854f9SBen Widawsky uint32_t instdone[I915_NUM_INSTDONE_REG]; 245463eeaf38SJesse Barnes u32 eir = I915_READ(EIR); 2455050ee91fSBen Widawsky int pipe, i; 245663eeaf38SJesse Barnes 245735aed2e6SChris Wilson if (!eir) 245835aed2e6SChris Wilson return; 245963eeaf38SJesse Barnes 2460a70491ccSJoe Perches pr_err("render error detected, EIR: 0x%08x\n", eir); 24618a905236SJesse Barnes 2462bd9854f9SBen Widawsky i915_get_extra_instdone(dev, instdone); 2463bd9854f9SBen Widawsky 24648a905236SJesse Barnes if (IS_G4X(dev)) { 24658a905236SJesse Barnes if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) { 24668a905236SJesse Barnes u32 ipeir = I915_READ(IPEIR_I965); 24678a905236SJesse Barnes 2468a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); 2469a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); 2470050ee91fSBen Widawsky for (i = 0; i < ARRAY_SIZE(instdone); i++) 2471050ee91fSBen Widawsky pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]); 2472a70491ccSJoe Perches pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); 2473a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); 24748a905236SJesse Barnes I915_WRITE(IPEIR_I965, ipeir); 24753143a2bfSChris Wilson POSTING_READ(IPEIR_I965); 24768a905236SJesse Barnes } 24778a905236SJesse Barnes if (eir & GM45_ERROR_PAGE_TABLE) { 24788a905236SJesse Barnes u32 pgtbl_err = I915_READ(PGTBL_ER); 2479a70491ccSJoe Perches pr_err("page table error\n"); 2480a70491ccSJoe Perches pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); 24818a905236SJesse Barnes I915_WRITE(PGTBL_ER, pgtbl_err); 24823143a2bfSChris Wilson POSTING_READ(PGTBL_ER); 24838a905236SJesse Barnes } 24848a905236SJesse Barnes } 24858a905236SJesse Barnes 2486a6c45cf0SChris Wilson if (!IS_GEN2(dev)) { 248763eeaf38SJesse Barnes if (eir & I915_ERROR_PAGE_TABLE) { 248863eeaf38SJesse Barnes u32 pgtbl_err = I915_READ(PGTBL_ER); 2489a70491ccSJoe Perches pr_err("page table error\n"); 2490a70491ccSJoe Perches pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); 249163eeaf38SJesse Barnes I915_WRITE(PGTBL_ER, pgtbl_err); 24923143a2bfSChris Wilson POSTING_READ(PGTBL_ER); 249363eeaf38SJesse Barnes } 24948a905236SJesse Barnes } 24958a905236SJesse Barnes 249663eeaf38SJesse Barnes if (eir & I915_ERROR_MEMORY_REFRESH) { 2497a70491ccSJoe Perches pr_err("memory refresh error:\n"); 2498055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 2499a70491ccSJoe Perches pr_err("pipe %c stat: 0x%08x\n", 25009db4a9c7SJesse Barnes pipe_name(pipe), I915_READ(PIPESTAT(pipe))); 250163eeaf38SJesse Barnes /* pipestat has already been acked */ 250263eeaf38SJesse Barnes } 250363eeaf38SJesse Barnes if (eir & I915_ERROR_INSTRUCTION) { 2504a70491ccSJoe Perches pr_err("instruction error\n"); 2505a70491ccSJoe Perches pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM)); 2506050ee91fSBen Widawsky for (i = 0; i < ARRAY_SIZE(instdone); i++) 2507050ee91fSBen Widawsky pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]); 2508a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen < 4) { 250963eeaf38SJesse Barnes u32 ipeir = I915_READ(IPEIR); 251063eeaf38SJesse Barnes 2511a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR)); 2512a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR)); 2513a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD)); 251463eeaf38SJesse Barnes I915_WRITE(IPEIR, ipeir); 25153143a2bfSChris Wilson POSTING_READ(IPEIR); 251663eeaf38SJesse Barnes } else { 251763eeaf38SJesse Barnes u32 ipeir = I915_READ(IPEIR_I965); 251863eeaf38SJesse Barnes 2519a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); 2520a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); 2521a70491ccSJoe Perches pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); 2522a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); 252363eeaf38SJesse Barnes I915_WRITE(IPEIR_I965, ipeir); 25243143a2bfSChris Wilson POSTING_READ(IPEIR_I965); 252563eeaf38SJesse Barnes } 252663eeaf38SJesse Barnes } 252763eeaf38SJesse Barnes 252863eeaf38SJesse Barnes I915_WRITE(EIR, eir); 25293143a2bfSChris Wilson POSTING_READ(EIR); 253063eeaf38SJesse Barnes eir = I915_READ(EIR); 253163eeaf38SJesse Barnes if (eir) { 253263eeaf38SJesse Barnes /* 253363eeaf38SJesse Barnes * some errors might have become stuck, 253463eeaf38SJesse Barnes * mask them. 253563eeaf38SJesse Barnes */ 253663eeaf38SJesse Barnes DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir); 253763eeaf38SJesse Barnes I915_WRITE(EMR, I915_READ(EMR) | eir); 253863eeaf38SJesse Barnes I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 253963eeaf38SJesse Barnes } 254035aed2e6SChris Wilson } 254135aed2e6SChris Wilson 254235aed2e6SChris Wilson /** 254335aed2e6SChris Wilson * i915_handle_error - handle an error interrupt 254435aed2e6SChris Wilson * @dev: drm device 254535aed2e6SChris Wilson * 254635aed2e6SChris Wilson * Do some basic checking of regsiter state at error interrupt time and 254735aed2e6SChris Wilson * dump it to the syslog. Also call i915_capture_error_state() to make 254835aed2e6SChris Wilson * sure we get a record and make it available in debugfs. Fire a uevent 254935aed2e6SChris Wilson * so userspace knows something bad happened (should trigger collection 255035aed2e6SChris Wilson * of a ring dump etc.). 255135aed2e6SChris Wilson */ 255258174462SMika Kuoppala void i915_handle_error(struct drm_device *dev, bool wedged, 255358174462SMika Kuoppala const char *fmt, ...) 255435aed2e6SChris Wilson { 255535aed2e6SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 255658174462SMika Kuoppala va_list args; 255758174462SMika Kuoppala char error_msg[80]; 255835aed2e6SChris Wilson 255958174462SMika Kuoppala va_start(args, fmt); 256058174462SMika Kuoppala vscnprintf(error_msg, sizeof(error_msg), fmt, args); 256158174462SMika Kuoppala va_end(args); 256258174462SMika Kuoppala 256358174462SMika Kuoppala i915_capture_error_state(dev, wedged, error_msg); 256435aed2e6SChris Wilson i915_report_and_clear_eir(dev); 25658a905236SJesse Barnes 2566ba1234d1SBen Gamari if (wedged) { 2567f69061beSDaniel Vetter atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG, 2568f69061beSDaniel Vetter &dev_priv->gpu_error.reset_counter); 2569ba1234d1SBen Gamari 257011ed50ecSBen Gamari /* 257117e1df07SDaniel Vetter * Wakeup waiting processes so that the reset work function 257217e1df07SDaniel Vetter * i915_error_work_func doesn't deadlock trying to grab various 257317e1df07SDaniel Vetter * locks. By bumping the reset counter first, the woken 257417e1df07SDaniel Vetter * processes will see a reset in progress and back off, 257517e1df07SDaniel Vetter * releasing their locks and then wait for the reset completion. 257617e1df07SDaniel Vetter * We must do this for _all_ gpu waiters that might hold locks 257717e1df07SDaniel Vetter * that the reset work needs to acquire. 257817e1df07SDaniel Vetter * 257917e1df07SDaniel Vetter * Note: The wake_up serves as the required memory barrier to 258017e1df07SDaniel Vetter * ensure that the waiters see the updated value of the reset 258117e1df07SDaniel Vetter * counter atomic_t. 258211ed50ecSBen Gamari */ 258317e1df07SDaniel Vetter i915_error_wake_up(dev_priv, false); 258411ed50ecSBen Gamari } 258511ed50ecSBen Gamari 2586122f46baSDaniel Vetter /* 2587122f46baSDaniel Vetter * Our reset work can grab modeset locks (since it needs to reset the 2588122f46baSDaniel Vetter * state of outstanding pagelips). Hence it must not be run on our own 2589122f46baSDaniel Vetter * dev-priv->wq work queue for otherwise the flush_work in the pageflip 2590122f46baSDaniel Vetter * code will deadlock. 2591122f46baSDaniel Vetter */ 2592122f46baSDaniel Vetter schedule_work(&dev_priv->gpu_error.work); 25938a905236SJesse Barnes } 25948a905236SJesse Barnes 259542f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 259642f52ef8SKeith Packard * we use as a pipe index 259742f52ef8SKeith Packard */ 2598f71d4af4SJesse Barnes static int i915_enable_vblank(struct drm_device *dev, int pipe) 25990a3e67a4SJesse Barnes { 26002d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 2601e9d21d7fSKeith Packard unsigned long irqflags; 260271e0ffa5SJesse Barnes 26035eddb70bSChris Wilson if (!i915_pipe_enabled(dev, pipe)) 260471e0ffa5SJesse Barnes return -EINVAL; 26050a3e67a4SJesse Barnes 26061ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2607f796cf8fSJesse Barnes if (INTEL_INFO(dev)->gen >= 4) 26087c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 2609755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 26100a3e67a4SJesse Barnes else 26117c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 2612755e9019SImre Deak PIPE_VBLANK_INTERRUPT_STATUS); 26131ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 26148692d00eSChris Wilson 26150a3e67a4SJesse Barnes return 0; 26160a3e67a4SJesse Barnes } 26170a3e67a4SJesse Barnes 2618f71d4af4SJesse Barnes static int ironlake_enable_vblank(struct drm_device *dev, int pipe) 2619f796cf8fSJesse Barnes { 26202d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 2621f796cf8fSJesse Barnes unsigned long irqflags; 2622b518421fSPaulo Zanoni uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) : 262340da17c2SDaniel Vetter DE_PIPE_VBLANK(pipe); 2624f796cf8fSJesse Barnes 2625f796cf8fSJesse Barnes if (!i915_pipe_enabled(dev, pipe)) 2626f796cf8fSJesse Barnes return -EINVAL; 2627f796cf8fSJesse Barnes 2628f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2629b518421fSPaulo Zanoni ironlake_enable_display_irq(dev_priv, bit); 2630b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2631b1f14ad0SJesse Barnes 2632b1f14ad0SJesse Barnes return 0; 2633b1f14ad0SJesse Barnes } 2634b1f14ad0SJesse Barnes 26357e231dbeSJesse Barnes static int valleyview_enable_vblank(struct drm_device *dev, int pipe) 26367e231dbeSJesse Barnes { 26372d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 26387e231dbeSJesse Barnes unsigned long irqflags; 26397e231dbeSJesse Barnes 26407e231dbeSJesse Barnes if (!i915_pipe_enabled(dev, pipe)) 26417e231dbeSJesse Barnes return -EINVAL; 26427e231dbeSJesse Barnes 26437e231dbeSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 264431acc7f5SJesse Barnes i915_enable_pipestat(dev_priv, pipe, 2645755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 26467e231dbeSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 26477e231dbeSJesse Barnes 26487e231dbeSJesse Barnes return 0; 26497e231dbeSJesse Barnes } 26507e231dbeSJesse Barnes 2651abd58f01SBen Widawsky static int gen8_enable_vblank(struct drm_device *dev, int pipe) 2652abd58f01SBen Widawsky { 2653abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 2654abd58f01SBen Widawsky unsigned long irqflags; 2655abd58f01SBen Widawsky 2656abd58f01SBen Widawsky if (!i915_pipe_enabled(dev, pipe)) 2657abd58f01SBen Widawsky return -EINVAL; 2658abd58f01SBen Widawsky 2659abd58f01SBen Widawsky spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 26607167d7c6SDaniel Vetter dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK; 26617167d7c6SDaniel Vetter I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]); 2662abd58f01SBen Widawsky POSTING_READ(GEN8_DE_PIPE_IMR(pipe)); 2663abd58f01SBen Widawsky spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2664abd58f01SBen Widawsky return 0; 2665abd58f01SBen Widawsky } 2666abd58f01SBen Widawsky 266742f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 266842f52ef8SKeith Packard * we use as a pipe index 266942f52ef8SKeith Packard */ 2670f71d4af4SJesse Barnes static void i915_disable_vblank(struct drm_device *dev, int pipe) 26710a3e67a4SJesse Barnes { 26722d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 2673e9d21d7fSKeith Packard unsigned long irqflags; 26740a3e67a4SJesse Barnes 26751ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 26767c463586SKeith Packard i915_disable_pipestat(dev_priv, pipe, 2677755e9019SImre Deak PIPE_VBLANK_INTERRUPT_STATUS | 2678755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 26791ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 26800a3e67a4SJesse Barnes } 26810a3e67a4SJesse Barnes 2682f71d4af4SJesse Barnes static void ironlake_disable_vblank(struct drm_device *dev, int pipe) 2683f796cf8fSJesse Barnes { 26842d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 2685f796cf8fSJesse Barnes unsigned long irqflags; 2686b518421fSPaulo Zanoni uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) : 268740da17c2SDaniel Vetter DE_PIPE_VBLANK(pipe); 2688f796cf8fSJesse Barnes 2689f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2690b518421fSPaulo Zanoni ironlake_disable_display_irq(dev_priv, bit); 2691b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2692b1f14ad0SJesse Barnes } 2693b1f14ad0SJesse Barnes 26947e231dbeSJesse Barnes static void valleyview_disable_vblank(struct drm_device *dev, int pipe) 26957e231dbeSJesse Barnes { 26962d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 26977e231dbeSJesse Barnes unsigned long irqflags; 26987e231dbeSJesse Barnes 26997e231dbeSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 270031acc7f5SJesse Barnes i915_disable_pipestat(dev_priv, pipe, 2701755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 27027e231dbeSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 27037e231dbeSJesse Barnes } 27047e231dbeSJesse Barnes 2705abd58f01SBen Widawsky static void gen8_disable_vblank(struct drm_device *dev, int pipe) 2706abd58f01SBen Widawsky { 2707abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 2708abd58f01SBen Widawsky unsigned long irqflags; 2709abd58f01SBen Widawsky 2710abd58f01SBen Widawsky if (!i915_pipe_enabled(dev, pipe)) 2711abd58f01SBen Widawsky return; 2712abd58f01SBen Widawsky 2713abd58f01SBen Widawsky spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 27147167d7c6SDaniel Vetter dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK; 27157167d7c6SDaniel Vetter I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]); 2716abd58f01SBen Widawsky POSTING_READ(GEN8_DE_PIPE_IMR(pipe)); 2717abd58f01SBen Widawsky spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2718abd58f01SBen Widawsky } 2719abd58f01SBen Widawsky 2720893eead0SChris Wilson static u32 2721a4872ba6SOscar Mateo ring_last_seqno(struct intel_engine_cs *ring) 2722852835f3SZou Nan hai { 2723893eead0SChris Wilson return list_entry(ring->request_list.prev, 2724893eead0SChris Wilson struct drm_i915_gem_request, list)->seqno; 2725893eead0SChris Wilson } 2726893eead0SChris Wilson 27279107e9d2SChris Wilson static bool 2728a4872ba6SOscar Mateo ring_idle(struct intel_engine_cs *ring, u32 seqno) 2729893eead0SChris Wilson { 27309107e9d2SChris Wilson return (list_empty(&ring->request_list) || 27319107e9d2SChris Wilson i915_seqno_passed(seqno, ring_last_seqno(ring))); 2732f65d9421SBen Gamari } 2733f65d9421SBen Gamari 2734a028c4b0SDaniel Vetter static bool 2735a028c4b0SDaniel Vetter ipehr_is_semaphore_wait(struct drm_device *dev, u32 ipehr) 2736a028c4b0SDaniel Vetter { 2737a028c4b0SDaniel Vetter if (INTEL_INFO(dev)->gen >= 8) { 2738a6cdb93aSRodrigo Vivi return (ipehr >> 23) == 0x1c; 2739a028c4b0SDaniel Vetter } else { 2740a028c4b0SDaniel Vetter ipehr &= ~MI_SEMAPHORE_SYNC_MASK; 2741a028c4b0SDaniel Vetter return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | 2742a028c4b0SDaniel Vetter MI_SEMAPHORE_REGISTER); 2743a028c4b0SDaniel Vetter } 2744a028c4b0SDaniel Vetter } 2745a028c4b0SDaniel Vetter 2746a4872ba6SOscar Mateo static struct intel_engine_cs * 2747a6cdb93aSRodrigo Vivi semaphore_wait_to_signaller_ring(struct intel_engine_cs *ring, u32 ipehr, u64 offset) 2748921d42eaSDaniel Vetter { 2749921d42eaSDaniel Vetter struct drm_i915_private *dev_priv = ring->dev->dev_private; 2750a4872ba6SOscar Mateo struct intel_engine_cs *signaller; 2751921d42eaSDaniel Vetter int i; 2752921d42eaSDaniel Vetter 2753921d42eaSDaniel Vetter if (INTEL_INFO(dev_priv->dev)->gen >= 8) { 2754a6cdb93aSRodrigo Vivi for_each_ring(signaller, dev_priv, i) { 2755a6cdb93aSRodrigo Vivi if (ring == signaller) 2756a6cdb93aSRodrigo Vivi continue; 2757a6cdb93aSRodrigo Vivi 2758a6cdb93aSRodrigo Vivi if (offset == signaller->semaphore.signal_ggtt[ring->id]) 2759a6cdb93aSRodrigo Vivi return signaller; 2760a6cdb93aSRodrigo Vivi } 2761921d42eaSDaniel Vetter } else { 2762921d42eaSDaniel Vetter u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK; 2763921d42eaSDaniel Vetter 2764921d42eaSDaniel Vetter for_each_ring(signaller, dev_priv, i) { 2765921d42eaSDaniel Vetter if(ring == signaller) 2766921d42eaSDaniel Vetter continue; 2767921d42eaSDaniel Vetter 2768ebc348b2SBen Widawsky if (sync_bits == signaller->semaphore.mbox.wait[ring->id]) 2769921d42eaSDaniel Vetter return signaller; 2770921d42eaSDaniel Vetter } 2771921d42eaSDaniel Vetter } 2772921d42eaSDaniel Vetter 2773a6cdb93aSRodrigo Vivi DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x, offset 0x%016llx\n", 2774a6cdb93aSRodrigo Vivi ring->id, ipehr, offset); 2775921d42eaSDaniel Vetter 2776921d42eaSDaniel Vetter return NULL; 2777921d42eaSDaniel Vetter } 2778921d42eaSDaniel Vetter 2779a4872ba6SOscar Mateo static struct intel_engine_cs * 2780a4872ba6SOscar Mateo semaphore_waits_for(struct intel_engine_cs *ring, u32 *seqno) 2781a24a11e6SChris Wilson { 2782a24a11e6SChris Wilson struct drm_i915_private *dev_priv = ring->dev->dev_private; 278388fe429dSDaniel Vetter u32 cmd, ipehr, head; 2784a6cdb93aSRodrigo Vivi u64 offset = 0; 2785a6cdb93aSRodrigo Vivi int i, backwards; 2786a24a11e6SChris Wilson 2787a24a11e6SChris Wilson ipehr = I915_READ(RING_IPEHR(ring->mmio_base)); 2788a028c4b0SDaniel Vetter if (!ipehr_is_semaphore_wait(ring->dev, ipehr)) 27896274f212SChris Wilson return NULL; 2790a24a11e6SChris Wilson 279188fe429dSDaniel Vetter /* 279288fe429dSDaniel Vetter * HEAD is likely pointing to the dword after the actual command, 279388fe429dSDaniel Vetter * so scan backwards until we find the MBOX. But limit it to just 3 2794a6cdb93aSRodrigo Vivi * or 4 dwords depending on the semaphore wait command size. 2795a6cdb93aSRodrigo Vivi * Note that we don't care about ACTHD here since that might 279688fe429dSDaniel Vetter * point at at batch, and semaphores are always emitted into the 279788fe429dSDaniel Vetter * ringbuffer itself. 2798a24a11e6SChris Wilson */ 279988fe429dSDaniel Vetter head = I915_READ_HEAD(ring) & HEAD_ADDR; 2800a6cdb93aSRodrigo Vivi backwards = (INTEL_INFO(ring->dev)->gen >= 8) ? 5 : 4; 280188fe429dSDaniel Vetter 2802a6cdb93aSRodrigo Vivi for (i = backwards; i; --i) { 280388fe429dSDaniel Vetter /* 280488fe429dSDaniel Vetter * Be paranoid and presume the hw has gone off into the wild - 280588fe429dSDaniel Vetter * our ring is smaller than what the hardware (and hence 280688fe429dSDaniel Vetter * HEAD_ADDR) allows. Also handles wrap-around. 280788fe429dSDaniel Vetter */ 2808ee1b1e5eSOscar Mateo head &= ring->buffer->size - 1; 280988fe429dSDaniel Vetter 281088fe429dSDaniel Vetter /* This here seems to blow up */ 2811ee1b1e5eSOscar Mateo cmd = ioread32(ring->buffer->virtual_start + head); 2812a24a11e6SChris Wilson if (cmd == ipehr) 2813a24a11e6SChris Wilson break; 2814a24a11e6SChris Wilson 281588fe429dSDaniel Vetter head -= 4; 281688fe429dSDaniel Vetter } 2817a24a11e6SChris Wilson 281888fe429dSDaniel Vetter if (!i) 281988fe429dSDaniel Vetter return NULL; 282088fe429dSDaniel Vetter 2821ee1b1e5eSOscar Mateo *seqno = ioread32(ring->buffer->virtual_start + head + 4) + 1; 2822a6cdb93aSRodrigo Vivi if (INTEL_INFO(ring->dev)->gen >= 8) { 2823a6cdb93aSRodrigo Vivi offset = ioread32(ring->buffer->virtual_start + head + 12); 2824a6cdb93aSRodrigo Vivi offset <<= 32; 2825a6cdb93aSRodrigo Vivi offset = ioread32(ring->buffer->virtual_start + head + 8); 2826a6cdb93aSRodrigo Vivi } 2827a6cdb93aSRodrigo Vivi return semaphore_wait_to_signaller_ring(ring, ipehr, offset); 2828a24a11e6SChris Wilson } 2829a24a11e6SChris Wilson 2830a4872ba6SOscar Mateo static int semaphore_passed(struct intel_engine_cs *ring) 28316274f212SChris Wilson { 28326274f212SChris Wilson struct drm_i915_private *dev_priv = ring->dev->dev_private; 2833a4872ba6SOscar Mateo struct intel_engine_cs *signaller; 2834a0d036b0SChris Wilson u32 seqno; 28356274f212SChris Wilson 28364be17381SChris Wilson ring->hangcheck.deadlock++; 28376274f212SChris Wilson 28386274f212SChris Wilson signaller = semaphore_waits_for(ring, &seqno); 28394be17381SChris Wilson if (signaller == NULL) 28404be17381SChris Wilson return -1; 28414be17381SChris Wilson 28424be17381SChris Wilson /* Prevent pathological recursion due to driver bugs */ 28434be17381SChris Wilson if (signaller->hangcheck.deadlock >= I915_NUM_RINGS) 28446274f212SChris Wilson return -1; 28456274f212SChris Wilson 28464be17381SChris Wilson if (i915_seqno_passed(signaller->get_seqno(signaller, false), seqno)) 28474be17381SChris Wilson return 1; 28484be17381SChris Wilson 2849a0d036b0SChris Wilson /* cursory check for an unkickable deadlock */ 2850a0d036b0SChris Wilson if (I915_READ_CTL(signaller) & RING_WAIT_SEMAPHORE && 2851a0d036b0SChris Wilson semaphore_passed(signaller) < 0) 28524be17381SChris Wilson return -1; 28534be17381SChris Wilson 28544be17381SChris Wilson return 0; 28556274f212SChris Wilson } 28566274f212SChris Wilson 28576274f212SChris Wilson static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv) 28586274f212SChris Wilson { 2859a4872ba6SOscar Mateo struct intel_engine_cs *ring; 28606274f212SChris Wilson int i; 28616274f212SChris Wilson 28626274f212SChris Wilson for_each_ring(ring, dev_priv, i) 28634be17381SChris Wilson ring->hangcheck.deadlock = 0; 28646274f212SChris Wilson } 28656274f212SChris Wilson 2866ad8beaeaSMika Kuoppala static enum intel_ring_hangcheck_action 2867a4872ba6SOscar Mateo ring_stuck(struct intel_engine_cs *ring, u64 acthd) 28681ec14ad3SChris Wilson { 28691ec14ad3SChris Wilson struct drm_device *dev = ring->dev; 28701ec14ad3SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 28719107e9d2SChris Wilson u32 tmp; 28729107e9d2SChris Wilson 2873f260fe7bSMika Kuoppala if (acthd != ring->hangcheck.acthd) { 2874f260fe7bSMika Kuoppala if (acthd > ring->hangcheck.max_acthd) { 2875f260fe7bSMika Kuoppala ring->hangcheck.max_acthd = acthd; 2876f2f4d82fSJani Nikula return HANGCHECK_ACTIVE; 2877f260fe7bSMika Kuoppala } 2878f260fe7bSMika Kuoppala 2879f260fe7bSMika Kuoppala return HANGCHECK_ACTIVE_LOOP; 2880f260fe7bSMika Kuoppala } 28816274f212SChris Wilson 28829107e9d2SChris Wilson if (IS_GEN2(dev)) 2883f2f4d82fSJani Nikula return HANGCHECK_HUNG; 28849107e9d2SChris Wilson 28859107e9d2SChris Wilson /* Is the chip hanging on a WAIT_FOR_EVENT? 28869107e9d2SChris Wilson * If so we can simply poke the RB_WAIT bit 28879107e9d2SChris Wilson * and break the hang. This should work on 28889107e9d2SChris Wilson * all but the second generation chipsets. 28899107e9d2SChris Wilson */ 28909107e9d2SChris Wilson tmp = I915_READ_CTL(ring); 28911ec14ad3SChris Wilson if (tmp & RING_WAIT) { 289258174462SMika Kuoppala i915_handle_error(dev, false, 289358174462SMika Kuoppala "Kicking stuck wait on %s", 28941ec14ad3SChris Wilson ring->name); 28951ec14ad3SChris Wilson I915_WRITE_CTL(ring, tmp); 2896f2f4d82fSJani Nikula return HANGCHECK_KICK; 28971ec14ad3SChris Wilson } 2898a24a11e6SChris Wilson 28996274f212SChris Wilson if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) { 29006274f212SChris Wilson switch (semaphore_passed(ring)) { 29016274f212SChris Wilson default: 2902f2f4d82fSJani Nikula return HANGCHECK_HUNG; 29036274f212SChris Wilson case 1: 290458174462SMika Kuoppala i915_handle_error(dev, false, 290558174462SMika Kuoppala "Kicking stuck semaphore on %s", 2906a24a11e6SChris Wilson ring->name); 2907a24a11e6SChris Wilson I915_WRITE_CTL(ring, tmp); 2908f2f4d82fSJani Nikula return HANGCHECK_KICK; 29096274f212SChris Wilson case 0: 2910f2f4d82fSJani Nikula return HANGCHECK_WAIT; 29116274f212SChris Wilson } 29129107e9d2SChris Wilson } 29139107e9d2SChris Wilson 2914f2f4d82fSJani Nikula return HANGCHECK_HUNG; 2915a24a11e6SChris Wilson } 2916d1e61e7fSChris Wilson 2917f65d9421SBen Gamari /** 2918f65d9421SBen Gamari * This is called when the chip hasn't reported back with completed 291905407ff8SMika Kuoppala * batchbuffers in a long time. We keep track per ring seqno progress and 292005407ff8SMika Kuoppala * if there are no progress, hangcheck score for that ring is increased. 292105407ff8SMika Kuoppala * Further, acthd is inspected to see if the ring is stuck. On stuck case 292205407ff8SMika Kuoppala * we kick the ring. If we see no progress on three subsequent calls 292305407ff8SMika Kuoppala * we assume chip is wedged and try to fix it by resetting the chip. 2924f65d9421SBen Gamari */ 2925a658b5d2SDamien Lespiau static void i915_hangcheck_elapsed(unsigned long data) 2926f65d9421SBen Gamari { 2927f65d9421SBen Gamari struct drm_device *dev = (struct drm_device *)data; 29282d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 2929a4872ba6SOscar Mateo struct intel_engine_cs *ring; 2930b4519513SChris Wilson int i; 293105407ff8SMika Kuoppala int busy_count = 0, rings_hung = 0; 29329107e9d2SChris Wilson bool stuck[I915_NUM_RINGS] = { 0 }; 29339107e9d2SChris Wilson #define BUSY 1 29349107e9d2SChris Wilson #define KICK 5 29359107e9d2SChris Wilson #define HUNG 20 2936893eead0SChris Wilson 2937d330a953SJani Nikula if (!i915.enable_hangcheck) 29383e0dc6b0SBen Widawsky return; 29393e0dc6b0SBen Widawsky 2940b4519513SChris Wilson for_each_ring(ring, dev_priv, i) { 294150877445SChris Wilson u64 acthd; 294250877445SChris Wilson u32 seqno; 29439107e9d2SChris Wilson bool busy = true; 2944b4519513SChris Wilson 29456274f212SChris Wilson semaphore_clear_deadlocks(dev_priv); 29466274f212SChris Wilson 294705407ff8SMika Kuoppala seqno = ring->get_seqno(ring, false); 294805407ff8SMika Kuoppala acthd = intel_ring_get_active_head(ring); 294905407ff8SMika Kuoppala 295005407ff8SMika Kuoppala if (ring->hangcheck.seqno == seqno) { 29519107e9d2SChris Wilson if (ring_idle(ring, seqno)) { 2952da661464SMika Kuoppala ring->hangcheck.action = HANGCHECK_IDLE; 2953da661464SMika Kuoppala 29549107e9d2SChris Wilson if (waitqueue_active(&ring->irq_queue)) { 29559107e9d2SChris Wilson /* Issue a wake-up to catch stuck h/w. */ 2956094f9a54SChris Wilson if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) { 2957f4adcd24SDaniel Vetter if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring))) 29589107e9d2SChris Wilson DRM_ERROR("Hangcheck timer elapsed... %s idle\n", 29599107e9d2SChris Wilson ring->name); 2960f4adcd24SDaniel Vetter else 2961f4adcd24SDaniel Vetter DRM_INFO("Fake missed irq on %s\n", 2962f4adcd24SDaniel Vetter ring->name); 29639107e9d2SChris Wilson wake_up_all(&ring->irq_queue); 2964094f9a54SChris Wilson } 2965094f9a54SChris Wilson /* Safeguard against driver failure */ 2966094f9a54SChris Wilson ring->hangcheck.score += BUSY; 29679107e9d2SChris Wilson } else 29689107e9d2SChris Wilson busy = false; 296905407ff8SMika Kuoppala } else { 29706274f212SChris Wilson /* We always increment the hangcheck score 29716274f212SChris Wilson * if the ring is busy and still processing 29726274f212SChris Wilson * the same request, so that no single request 29736274f212SChris Wilson * can run indefinitely (such as a chain of 29746274f212SChris Wilson * batches). The only time we do not increment 29756274f212SChris Wilson * the hangcheck score on this ring, if this 29766274f212SChris Wilson * ring is in a legitimate wait for another 29776274f212SChris Wilson * ring. In that case the waiting ring is a 29786274f212SChris Wilson * victim and we want to be sure we catch the 29796274f212SChris Wilson * right culprit. Then every time we do kick 29806274f212SChris Wilson * the ring, add a small increment to the 29816274f212SChris Wilson * score so that we can catch a batch that is 29826274f212SChris Wilson * being repeatedly kicked and so responsible 29836274f212SChris Wilson * for stalling the machine. 29849107e9d2SChris Wilson */ 2985ad8beaeaSMika Kuoppala ring->hangcheck.action = ring_stuck(ring, 2986ad8beaeaSMika Kuoppala acthd); 2987ad8beaeaSMika Kuoppala 2988ad8beaeaSMika Kuoppala switch (ring->hangcheck.action) { 2989da661464SMika Kuoppala case HANGCHECK_IDLE: 2990f2f4d82fSJani Nikula case HANGCHECK_WAIT: 2991f2f4d82fSJani Nikula case HANGCHECK_ACTIVE: 2992f260fe7bSMika Kuoppala break; 2993f260fe7bSMika Kuoppala case HANGCHECK_ACTIVE_LOOP: 2994ea04cb31SJani Nikula ring->hangcheck.score += BUSY; 29956274f212SChris Wilson break; 2996f2f4d82fSJani Nikula case HANGCHECK_KICK: 2997ea04cb31SJani Nikula ring->hangcheck.score += KICK; 29986274f212SChris Wilson break; 2999f2f4d82fSJani Nikula case HANGCHECK_HUNG: 3000ea04cb31SJani Nikula ring->hangcheck.score += HUNG; 30016274f212SChris Wilson stuck[i] = true; 30026274f212SChris Wilson break; 30036274f212SChris Wilson } 300405407ff8SMika Kuoppala } 30059107e9d2SChris Wilson } else { 3006da661464SMika Kuoppala ring->hangcheck.action = HANGCHECK_ACTIVE; 3007da661464SMika Kuoppala 30089107e9d2SChris Wilson /* Gradually reduce the count so that we catch DoS 30099107e9d2SChris Wilson * attempts across multiple batches. 30109107e9d2SChris Wilson */ 30119107e9d2SChris Wilson if (ring->hangcheck.score > 0) 30129107e9d2SChris Wilson ring->hangcheck.score--; 3013f260fe7bSMika Kuoppala 3014f260fe7bSMika Kuoppala ring->hangcheck.acthd = ring->hangcheck.max_acthd = 0; 3015cbb465e7SChris Wilson } 3016f65d9421SBen Gamari 301705407ff8SMika Kuoppala ring->hangcheck.seqno = seqno; 301805407ff8SMika Kuoppala ring->hangcheck.acthd = acthd; 30199107e9d2SChris Wilson busy_count += busy; 302005407ff8SMika Kuoppala } 302105407ff8SMika Kuoppala 302205407ff8SMika Kuoppala for_each_ring(ring, dev_priv, i) { 3023b6b0fac0SMika Kuoppala if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) { 3024b8d88d1dSDaniel Vetter DRM_INFO("%s on %s\n", 302505407ff8SMika Kuoppala stuck[i] ? "stuck" : "no progress", 3026a43adf07SChris Wilson ring->name); 3027a43adf07SChris Wilson rings_hung++; 302805407ff8SMika Kuoppala } 302905407ff8SMika Kuoppala } 303005407ff8SMika Kuoppala 303105407ff8SMika Kuoppala if (rings_hung) 303258174462SMika Kuoppala return i915_handle_error(dev, true, "Ring hung"); 303305407ff8SMika Kuoppala 303405407ff8SMika Kuoppala if (busy_count) 303505407ff8SMika Kuoppala /* Reset timer case chip hangs without another request 303605407ff8SMika Kuoppala * being added */ 303710cd45b6SMika Kuoppala i915_queue_hangcheck(dev); 303810cd45b6SMika Kuoppala } 303910cd45b6SMika Kuoppala 304010cd45b6SMika Kuoppala void i915_queue_hangcheck(struct drm_device *dev) 304110cd45b6SMika Kuoppala { 304210cd45b6SMika Kuoppala struct drm_i915_private *dev_priv = dev->dev_private; 3043*672e7b7cSChris Wilson struct timer_list *timer = &dev_priv->gpu_error.hangcheck_timer; 3044*672e7b7cSChris Wilson 3045d330a953SJani Nikula if (!i915.enable_hangcheck) 304610cd45b6SMika Kuoppala return; 304710cd45b6SMika Kuoppala 3048*672e7b7cSChris Wilson /* Don't continually defer the hangcheck, but make sure it is active */ 3049*672e7b7cSChris Wilson if (!timer_pending(timer)) 3050*672e7b7cSChris Wilson timer->expires = round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES); 3051*672e7b7cSChris Wilson mod_timer(timer, timer->expires); 3052f65d9421SBen Gamari } 3053f65d9421SBen Gamari 30541c69eb42SPaulo Zanoni static void ibx_irq_reset(struct drm_device *dev) 305591738a95SPaulo Zanoni { 305691738a95SPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 305791738a95SPaulo Zanoni 305891738a95SPaulo Zanoni if (HAS_PCH_NOP(dev)) 305991738a95SPaulo Zanoni return; 306091738a95SPaulo Zanoni 3061f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(SDE); 3062105b122eSPaulo Zanoni 3063105b122eSPaulo Zanoni if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev)) 3064105b122eSPaulo Zanoni I915_WRITE(SERR_INT, 0xffffffff); 3065622364b6SPaulo Zanoni } 3066105b122eSPaulo Zanoni 306791738a95SPaulo Zanoni /* 3068622364b6SPaulo Zanoni * SDEIER is also touched by the interrupt handler to work around missed PCH 3069622364b6SPaulo Zanoni * interrupts. Hence we can't update it after the interrupt handler is enabled - 3070622364b6SPaulo Zanoni * instead we unconditionally enable all PCH interrupt sources here, but then 3071622364b6SPaulo Zanoni * only unmask them as needed with SDEIMR. 3072622364b6SPaulo Zanoni * 3073622364b6SPaulo Zanoni * This function needs to be called before interrupts are enabled. 307491738a95SPaulo Zanoni */ 3075622364b6SPaulo Zanoni static void ibx_irq_pre_postinstall(struct drm_device *dev) 3076622364b6SPaulo Zanoni { 3077622364b6SPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 3078622364b6SPaulo Zanoni 3079622364b6SPaulo Zanoni if (HAS_PCH_NOP(dev)) 3080622364b6SPaulo Zanoni return; 3081622364b6SPaulo Zanoni 3082622364b6SPaulo Zanoni WARN_ON(I915_READ(SDEIER) != 0); 308391738a95SPaulo Zanoni I915_WRITE(SDEIER, 0xffffffff); 308491738a95SPaulo Zanoni POSTING_READ(SDEIER); 308591738a95SPaulo Zanoni } 308691738a95SPaulo Zanoni 30877c4d664eSPaulo Zanoni static void gen5_gt_irq_reset(struct drm_device *dev) 3088d18ea1b5SDaniel Vetter { 3089d18ea1b5SDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 3090d18ea1b5SDaniel Vetter 3091f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(GT); 3092a9d356a6SPaulo Zanoni if (INTEL_INFO(dev)->gen >= 6) 3093f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(GEN6_PM); 3094d18ea1b5SDaniel Vetter } 3095d18ea1b5SDaniel Vetter 3096c0e09200SDave Airlie /* drm_dma.h hooks 3097c0e09200SDave Airlie */ 3098be30b29fSPaulo Zanoni static void ironlake_irq_reset(struct drm_device *dev) 3099036a4a7dSZhenyu Wang { 31002d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3101036a4a7dSZhenyu Wang 31020c841212SPaulo Zanoni I915_WRITE(HWSTAM, 0xffffffff); 3103bdfcdb63SDaniel Vetter 3104f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(DE); 3105c6d954c1SPaulo Zanoni if (IS_GEN7(dev)) 3106c6d954c1SPaulo Zanoni I915_WRITE(GEN7_ERR_INT, 0xffffffff); 3107036a4a7dSZhenyu Wang 31087c4d664eSPaulo Zanoni gen5_gt_irq_reset(dev); 3109c650156aSZhenyu Wang 31101c69eb42SPaulo Zanoni ibx_irq_reset(dev); 31117d99163dSBen Widawsky } 31127d99163dSBen Widawsky 311370591a41SVille Syrjälä static void vlv_display_irq_reset(struct drm_i915_private *dev_priv) 311470591a41SVille Syrjälä { 311570591a41SVille Syrjälä enum pipe pipe; 311670591a41SVille Syrjälä 311770591a41SVille Syrjälä I915_WRITE(PORT_HOTPLUG_EN, 0); 311870591a41SVille Syrjälä I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 311970591a41SVille Syrjälä 312070591a41SVille Syrjälä for_each_pipe(dev_priv, pipe) 312170591a41SVille Syrjälä I915_WRITE(PIPESTAT(pipe), 0xffff); 312270591a41SVille Syrjälä 312370591a41SVille Syrjälä GEN5_IRQ_RESET(VLV_); 312470591a41SVille Syrjälä } 312570591a41SVille Syrjälä 31267e231dbeSJesse Barnes static void valleyview_irq_preinstall(struct drm_device *dev) 31277e231dbeSJesse Barnes { 31282d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 31297e231dbeSJesse Barnes 31307e231dbeSJesse Barnes /* VLV magic */ 31317e231dbeSJesse Barnes I915_WRITE(VLV_IMR, 0); 31327e231dbeSJesse Barnes I915_WRITE(RING_IMR(RENDER_RING_BASE), 0); 31337e231dbeSJesse Barnes I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0); 31347e231dbeSJesse Barnes I915_WRITE(RING_IMR(BLT_RING_BASE), 0); 31357e231dbeSJesse Barnes 31367c4d664eSPaulo Zanoni gen5_gt_irq_reset(dev); 31377e231dbeSJesse Barnes 31387c4cde39SVille Syrjälä I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK); 31397e231dbeSJesse Barnes 314070591a41SVille Syrjälä vlv_display_irq_reset(dev_priv); 31417e231dbeSJesse Barnes } 31427e231dbeSJesse Barnes 3143d6e3cca3SDaniel Vetter static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv) 3144d6e3cca3SDaniel Vetter { 3145d6e3cca3SDaniel Vetter GEN8_IRQ_RESET_NDX(GT, 0); 3146d6e3cca3SDaniel Vetter GEN8_IRQ_RESET_NDX(GT, 1); 3147d6e3cca3SDaniel Vetter GEN8_IRQ_RESET_NDX(GT, 2); 3148d6e3cca3SDaniel Vetter GEN8_IRQ_RESET_NDX(GT, 3); 3149d6e3cca3SDaniel Vetter } 3150d6e3cca3SDaniel Vetter 3151823f6b38SPaulo Zanoni static void gen8_irq_reset(struct drm_device *dev) 3152abd58f01SBen Widawsky { 3153abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 3154abd58f01SBen Widawsky int pipe; 3155abd58f01SBen Widawsky 3156abd58f01SBen Widawsky I915_WRITE(GEN8_MASTER_IRQ, 0); 3157abd58f01SBen Widawsky POSTING_READ(GEN8_MASTER_IRQ); 3158abd58f01SBen Widawsky 3159d6e3cca3SDaniel Vetter gen8_gt_irq_reset(dev_priv); 3160abd58f01SBen Widawsky 3161055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 3162f458ebbcSDaniel Vetter if (intel_display_power_is_enabled(dev_priv, 3163813bde43SPaulo Zanoni POWER_DOMAIN_PIPE(pipe))) 3164f86f3fb0SPaulo Zanoni GEN8_IRQ_RESET_NDX(DE_PIPE, pipe); 3165abd58f01SBen Widawsky 3166f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(GEN8_DE_PORT_); 3167f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(GEN8_DE_MISC_); 3168f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(GEN8_PCU_); 3169abd58f01SBen Widawsky 31701c69eb42SPaulo Zanoni ibx_irq_reset(dev); 3171abd58f01SBen Widawsky } 3172abd58f01SBen Widawsky 3173d49bdb0eSPaulo Zanoni void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv) 3174d49bdb0eSPaulo Zanoni { 31751180e206SPaulo Zanoni uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN; 3176d49bdb0eSPaulo Zanoni 317713321786SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 3178d49bdb0eSPaulo Zanoni GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_B, dev_priv->de_irq_mask[PIPE_B], 31791180e206SPaulo Zanoni ~dev_priv->de_irq_mask[PIPE_B] | extra_ier); 3180d49bdb0eSPaulo Zanoni GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_C, dev_priv->de_irq_mask[PIPE_C], 31811180e206SPaulo Zanoni ~dev_priv->de_irq_mask[PIPE_C] | extra_ier); 318213321786SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 3183d49bdb0eSPaulo Zanoni } 3184d49bdb0eSPaulo Zanoni 318543f328d7SVille Syrjälä static void cherryview_irq_preinstall(struct drm_device *dev) 318643f328d7SVille Syrjälä { 318743f328d7SVille Syrjälä struct drm_i915_private *dev_priv = dev->dev_private; 318843f328d7SVille Syrjälä 318943f328d7SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, 0); 319043f328d7SVille Syrjälä POSTING_READ(GEN8_MASTER_IRQ); 319143f328d7SVille Syrjälä 3192d6e3cca3SDaniel Vetter gen8_gt_irq_reset(dev_priv); 319343f328d7SVille Syrjälä 319443f328d7SVille Syrjälä GEN5_IRQ_RESET(GEN8_PCU_); 319543f328d7SVille Syrjälä 319643f328d7SVille Syrjälä I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV); 319743f328d7SVille Syrjälä 319870591a41SVille Syrjälä vlv_display_irq_reset(dev_priv); 319943f328d7SVille Syrjälä } 320043f328d7SVille Syrjälä 320182a28bcfSDaniel Vetter static void ibx_hpd_irq_setup(struct drm_device *dev) 320282a28bcfSDaniel Vetter { 32032d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 320482a28bcfSDaniel Vetter struct intel_encoder *intel_encoder; 3205fee884edSDaniel Vetter u32 hotplug_irqs, hotplug, enabled_irqs = 0; 320682a28bcfSDaniel Vetter 320782a28bcfSDaniel Vetter if (HAS_PCH_IBX(dev)) { 3208fee884edSDaniel Vetter hotplug_irqs = SDE_HOTPLUG_MASK; 3209b2784e15SDamien Lespiau for_each_intel_encoder(dev, intel_encoder) 3210cd569aedSEgbert Eich if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) 3211fee884edSDaniel Vetter enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin]; 321282a28bcfSDaniel Vetter } else { 3213fee884edSDaniel Vetter hotplug_irqs = SDE_HOTPLUG_MASK_CPT; 3214b2784e15SDamien Lespiau for_each_intel_encoder(dev, intel_encoder) 3215cd569aedSEgbert Eich if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) 3216fee884edSDaniel Vetter enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin]; 321782a28bcfSDaniel Vetter } 321882a28bcfSDaniel Vetter 3219fee884edSDaniel Vetter ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); 322082a28bcfSDaniel Vetter 32217fe0b973SKeith Packard /* 32227fe0b973SKeith Packard * Enable digital hotplug on the PCH, and configure the DP short pulse 32237fe0b973SKeith Packard * duration to 2ms (which is the minimum in the Display Port spec) 32247fe0b973SKeith Packard * 32257fe0b973SKeith Packard * This register is the same on all known PCH chips. 32267fe0b973SKeith Packard */ 32277fe0b973SKeith Packard hotplug = I915_READ(PCH_PORT_HOTPLUG); 32287fe0b973SKeith Packard hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK); 32297fe0b973SKeith Packard hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms; 32307fe0b973SKeith Packard hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms; 32317fe0b973SKeith Packard hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms; 32327fe0b973SKeith Packard I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 32337fe0b973SKeith Packard } 32347fe0b973SKeith Packard 3235d46da437SPaulo Zanoni static void ibx_irq_postinstall(struct drm_device *dev) 3236d46da437SPaulo Zanoni { 32372d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 323882a28bcfSDaniel Vetter u32 mask; 3239d46da437SPaulo Zanoni 3240692a04cfSDaniel Vetter if (HAS_PCH_NOP(dev)) 3241692a04cfSDaniel Vetter return; 3242692a04cfSDaniel Vetter 3243105b122eSPaulo Zanoni if (HAS_PCH_IBX(dev)) 32445c673b60SDaniel Vetter mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON; 3245105b122eSPaulo Zanoni else 32465c673b60SDaniel Vetter mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT; 32478664281bSPaulo Zanoni 3248337ba017SPaulo Zanoni GEN5_ASSERT_IIR_IS_ZERO(SDEIIR); 3249d46da437SPaulo Zanoni I915_WRITE(SDEIMR, ~mask); 3250d46da437SPaulo Zanoni } 3251d46da437SPaulo Zanoni 32520a9a8c91SDaniel Vetter static void gen5_gt_irq_postinstall(struct drm_device *dev) 32530a9a8c91SDaniel Vetter { 32540a9a8c91SDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 32550a9a8c91SDaniel Vetter u32 pm_irqs, gt_irqs; 32560a9a8c91SDaniel Vetter 32570a9a8c91SDaniel Vetter pm_irqs = gt_irqs = 0; 32580a9a8c91SDaniel Vetter 32590a9a8c91SDaniel Vetter dev_priv->gt_irq_mask = ~0; 3260040d2baaSBen Widawsky if (HAS_L3_DPF(dev)) { 32610a9a8c91SDaniel Vetter /* L3 parity interrupt is always unmasked. */ 326235a85ac6SBen Widawsky dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev); 326335a85ac6SBen Widawsky gt_irqs |= GT_PARITY_ERROR(dev); 32640a9a8c91SDaniel Vetter } 32650a9a8c91SDaniel Vetter 32660a9a8c91SDaniel Vetter gt_irqs |= GT_RENDER_USER_INTERRUPT; 32670a9a8c91SDaniel Vetter if (IS_GEN5(dev)) { 32680a9a8c91SDaniel Vetter gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT | 32690a9a8c91SDaniel Vetter ILK_BSD_USER_INTERRUPT; 32700a9a8c91SDaniel Vetter } else { 32710a9a8c91SDaniel Vetter gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT; 32720a9a8c91SDaniel Vetter } 32730a9a8c91SDaniel Vetter 327435079899SPaulo Zanoni GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs); 32750a9a8c91SDaniel Vetter 32760a9a8c91SDaniel Vetter if (INTEL_INFO(dev)->gen >= 6) { 3277a6706b45SDeepak S pm_irqs |= dev_priv->pm_rps_events; 32780a9a8c91SDaniel Vetter 32790a9a8c91SDaniel Vetter if (HAS_VEBOX(dev)) 32800a9a8c91SDaniel Vetter pm_irqs |= PM_VEBOX_USER_INTERRUPT; 32810a9a8c91SDaniel Vetter 3282605cd25bSPaulo Zanoni dev_priv->pm_irq_mask = 0xffffffff; 328335079899SPaulo Zanoni GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs); 32840a9a8c91SDaniel Vetter } 32850a9a8c91SDaniel Vetter } 32860a9a8c91SDaniel Vetter 3287f71d4af4SJesse Barnes static int ironlake_irq_postinstall(struct drm_device *dev) 3288036a4a7dSZhenyu Wang { 32892d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 32908e76f8dcSPaulo Zanoni u32 display_mask, extra_mask; 32918e76f8dcSPaulo Zanoni 32928e76f8dcSPaulo Zanoni if (INTEL_INFO(dev)->gen >= 7) { 32938e76f8dcSPaulo Zanoni display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | 32948e76f8dcSPaulo Zanoni DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB | 32958e76f8dcSPaulo Zanoni DE_PLANEB_FLIP_DONE_IVB | 32965c673b60SDaniel Vetter DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB); 32978e76f8dcSPaulo Zanoni extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB | 32985c673b60SDaniel Vetter DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB); 32998e76f8dcSPaulo Zanoni } else { 33008e76f8dcSPaulo Zanoni display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | 3301ce99c256SDaniel Vetter DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE | 33025b3a856bSDaniel Vetter DE_AUX_CHANNEL_A | 33035b3a856bSDaniel Vetter DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE | 33045b3a856bSDaniel Vetter DE_POISON); 33055c673b60SDaniel Vetter extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT | 33065c673b60SDaniel Vetter DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN; 33078e76f8dcSPaulo Zanoni } 3308036a4a7dSZhenyu Wang 33091ec14ad3SChris Wilson dev_priv->irq_mask = ~display_mask; 3310036a4a7dSZhenyu Wang 33110c841212SPaulo Zanoni I915_WRITE(HWSTAM, 0xeffe); 33120c841212SPaulo Zanoni 3313622364b6SPaulo Zanoni ibx_irq_pre_postinstall(dev); 3314622364b6SPaulo Zanoni 331535079899SPaulo Zanoni GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask); 3316036a4a7dSZhenyu Wang 33170a9a8c91SDaniel Vetter gen5_gt_irq_postinstall(dev); 3318036a4a7dSZhenyu Wang 3319d46da437SPaulo Zanoni ibx_irq_postinstall(dev); 33207fe0b973SKeith Packard 3321f97108d1SJesse Barnes if (IS_IRONLAKE_M(dev)) { 33226005ce42SDaniel Vetter /* Enable PCU event interrupts 33236005ce42SDaniel Vetter * 33246005ce42SDaniel Vetter * spinlocking not required here for correctness since interrupt 33254bc9d430SDaniel Vetter * setup is guaranteed to run in single-threaded context. But we 33264bc9d430SDaniel Vetter * need it to make the assert_spin_locked happy. */ 3327d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 3328f97108d1SJesse Barnes ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT); 3329d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 3330f97108d1SJesse Barnes } 3331f97108d1SJesse Barnes 3332036a4a7dSZhenyu Wang return 0; 3333036a4a7dSZhenyu Wang } 3334036a4a7dSZhenyu Wang 3335f8b79e58SImre Deak static void valleyview_display_irqs_install(struct drm_i915_private *dev_priv) 3336f8b79e58SImre Deak { 3337f8b79e58SImre Deak u32 pipestat_mask; 3338f8b79e58SImre Deak u32 iir_mask; 3339120dda4fSVille Syrjälä enum pipe pipe; 3340f8b79e58SImre Deak 3341f8b79e58SImre Deak pipestat_mask = PIPESTAT_INT_STATUS_MASK | 3342f8b79e58SImre Deak PIPE_FIFO_UNDERRUN_STATUS; 3343f8b79e58SImre Deak 3344120dda4fSVille Syrjälä for_each_pipe(dev_priv, pipe) 3345120dda4fSVille Syrjälä I915_WRITE(PIPESTAT(pipe), pipestat_mask); 3346f8b79e58SImre Deak POSTING_READ(PIPESTAT(PIPE_A)); 3347f8b79e58SImre Deak 3348f8b79e58SImre Deak pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV | 3349f8b79e58SImre Deak PIPE_CRC_DONE_INTERRUPT_STATUS; 3350f8b79e58SImre Deak 3351120dda4fSVille Syrjälä i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS); 3352120dda4fSVille Syrjälä for_each_pipe(dev_priv, pipe) 3353120dda4fSVille Syrjälä i915_enable_pipestat(dev_priv, pipe, pipestat_mask); 3354f8b79e58SImre Deak 3355f8b79e58SImre Deak iir_mask = I915_DISPLAY_PORT_INTERRUPT | 3356f8b79e58SImre Deak I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3357f8b79e58SImre Deak I915_DISPLAY_PIPE_B_EVENT_INTERRUPT; 3358120dda4fSVille Syrjälä if (IS_CHERRYVIEW(dev_priv)) 3359120dda4fSVille Syrjälä iir_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT; 3360f8b79e58SImre Deak dev_priv->irq_mask &= ~iir_mask; 3361f8b79e58SImre Deak 3362f8b79e58SImre Deak I915_WRITE(VLV_IIR, iir_mask); 3363f8b79e58SImre Deak I915_WRITE(VLV_IIR, iir_mask); 3364f8b79e58SImre Deak I915_WRITE(VLV_IER, ~dev_priv->irq_mask); 336576e41860SVille Syrjälä I915_WRITE(VLV_IMR, dev_priv->irq_mask); 336676e41860SVille Syrjälä POSTING_READ(VLV_IMR); 3367f8b79e58SImre Deak } 3368f8b79e58SImre Deak 3369f8b79e58SImre Deak static void valleyview_display_irqs_uninstall(struct drm_i915_private *dev_priv) 3370f8b79e58SImre Deak { 3371f8b79e58SImre Deak u32 pipestat_mask; 3372f8b79e58SImre Deak u32 iir_mask; 3373120dda4fSVille Syrjälä enum pipe pipe; 3374f8b79e58SImre Deak 3375f8b79e58SImre Deak iir_mask = I915_DISPLAY_PORT_INTERRUPT | 3376f8b79e58SImre Deak I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 33776c7fba04SImre Deak I915_DISPLAY_PIPE_B_EVENT_INTERRUPT; 3378120dda4fSVille Syrjälä if (IS_CHERRYVIEW(dev_priv)) 3379120dda4fSVille Syrjälä iir_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT; 3380f8b79e58SImre Deak 3381f8b79e58SImre Deak dev_priv->irq_mask |= iir_mask; 3382f8b79e58SImre Deak I915_WRITE(VLV_IMR, dev_priv->irq_mask); 338376e41860SVille Syrjälä I915_WRITE(VLV_IER, ~dev_priv->irq_mask); 3384f8b79e58SImre Deak I915_WRITE(VLV_IIR, iir_mask); 3385f8b79e58SImre Deak I915_WRITE(VLV_IIR, iir_mask); 3386f8b79e58SImre Deak POSTING_READ(VLV_IIR); 3387f8b79e58SImre Deak 3388f8b79e58SImre Deak pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV | 3389f8b79e58SImre Deak PIPE_CRC_DONE_INTERRUPT_STATUS; 3390f8b79e58SImre Deak 3391120dda4fSVille Syrjälä i915_disable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS); 3392120dda4fSVille Syrjälä for_each_pipe(dev_priv, pipe) 3393120dda4fSVille Syrjälä i915_disable_pipestat(dev_priv, pipe, pipestat_mask); 3394f8b79e58SImre Deak 3395f8b79e58SImre Deak pipestat_mask = PIPESTAT_INT_STATUS_MASK | 3396f8b79e58SImre Deak PIPE_FIFO_UNDERRUN_STATUS; 3397120dda4fSVille Syrjälä 3398120dda4fSVille Syrjälä for_each_pipe(dev_priv, pipe) 3399120dda4fSVille Syrjälä I915_WRITE(PIPESTAT(pipe), pipestat_mask); 3400f8b79e58SImre Deak POSTING_READ(PIPESTAT(PIPE_A)); 3401f8b79e58SImre Deak } 3402f8b79e58SImre Deak 3403f8b79e58SImre Deak void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv) 3404f8b79e58SImre Deak { 3405f8b79e58SImre Deak assert_spin_locked(&dev_priv->irq_lock); 3406f8b79e58SImre Deak 3407f8b79e58SImre Deak if (dev_priv->display_irqs_enabled) 3408f8b79e58SImre Deak return; 3409f8b79e58SImre Deak 3410f8b79e58SImre Deak dev_priv->display_irqs_enabled = true; 3411f8b79e58SImre Deak 3412950eabafSImre Deak if (intel_irqs_enabled(dev_priv)) 3413f8b79e58SImre Deak valleyview_display_irqs_install(dev_priv); 3414f8b79e58SImre Deak } 3415f8b79e58SImre Deak 3416f8b79e58SImre Deak void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv) 3417f8b79e58SImre Deak { 3418f8b79e58SImre Deak assert_spin_locked(&dev_priv->irq_lock); 3419f8b79e58SImre Deak 3420f8b79e58SImre Deak if (!dev_priv->display_irqs_enabled) 3421f8b79e58SImre Deak return; 3422f8b79e58SImre Deak 3423f8b79e58SImre Deak dev_priv->display_irqs_enabled = false; 3424f8b79e58SImre Deak 3425950eabafSImre Deak if (intel_irqs_enabled(dev_priv)) 3426f8b79e58SImre Deak valleyview_display_irqs_uninstall(dev_priv); 3427f8b79e58SImre Deak } 3428f8b79e58SImre Deak 34290e6c9a9eSVille Syrjälä static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv) 34307e231dbeSJesse Barnes { 3431f8b79e58SImre Deak dev_priv->irq_mask = ~0; 34327e231dbeSJesse Barnes 343320afbda2SDaniel Vetter I915_WRITE(PORT_HOTPLUG_EN, 0); 343420afbda2SDaniel Vetter POSTING_READ(PORT_HOTPLUG_EN); 343520afbda2SDaniel Vetter 34367e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 343776e41860SVille Syrjälä I915_WRITE(VLV_IIR, 0xffffffff); 343876e41860SVille Syrjälä I915_WRITE(VLV_IER, ~dev_priv->irq_mask); 343976e41860SVille Syrjälä I915_WRITE(VLV_IMR, dev_priv->irq_mask); 344076e41860SVille Syrjälä POSTING_READ(VLV_IMR); 34417e231dbeSJesse Barnes 3442b79480baSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3443b79480baSDaniel Vetter * just to make the assert_spin_locked check happy. */ 3444d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 3445f8b79e58SImre Deak if (dev_priv->display_irqs_enabled) 3446f8b79e58SImre Deak valleyview_display_irqs_install(dev_priv); 3447d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 34480e6c9a9eSVille Syrjälä } 34490e6c9a9eSVille Syrjälä 34500e6c9a9eSVille Syrjälä static int valleyview_irq_postinstall(struct drm_device *dev) 34510e6c9a9eSVille Syrjälä { 34520e6c9a9eSVille Syrjälä struct drm_i915_private *dev_priv = dev->dev_private; 34530e6c9a9eSVille Syrjälä 34540e6c9a9eSVille Syrjälä vlv_display_irq_postinstall(dev_priv); 34557e231dbeSJesse Barnes 34560a9a8c91SDaniel Vetter gen5_gt_irq_postinstall(dev); 34577e231dbeSJesse Barnes 34587e231dbeSJesse Barnes /* ack & enable invalid PTE error interrupts */ 34597e231dbeSJesse Barnes #if 0 /* FIXME: add support to irq handler for checking these bits */ 34607e231dbeSJesse Barnes I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK); 34617e231dbeSJesse Barnes I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK); 34627e231dbeSJesse Barnes #endif 34637e231dbeSJesse Barnes 34647e231dbeSJesse Barnes I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE); 346520afbda2SDaniel Vetter 346620afbda2SDaniel Vetter return 0; 346720afbda2SDaniel Vetter } 346820afbda2SDaniel Vetter 3469abd58f01SBen Widawsky static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv) 3470abd58f01SBen Widawsky { 3471abd58f01SBen Widawsky /* These are interrupts we'll toggle with the ring mask register */ 3472abd58f01SBen Widawsky uint32_t gt_interrupts[] = { 3473abd58f01SBen Widawsky GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT | 347473d477f6SOscar Mateo GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT | 3475abd58f01SBen Widawsky GT_RENDER_L3_PARITY_ERROR_INTERRUPT | 347673d477f6SOscar Mateo GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT | 347773d477f6SOscar Mateo GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT, 3478abd58f01SBen Widawsky GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT | 347973d477f6SOscar Mateo GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT | 348073d477f6SOscar Mateo GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT | 348173d477f6SOscar Mateo GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT, 3482abd58f01SBen Widawsky 0, 348373d477f6SOscar Mateo GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT | 348473d477f6SOscar Mateo GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT 3485abd58f01SBen Widawsky }; 3486abd58f01SBen Widawsky 34870961021aSBen Widawsky dev_priv->pm_irq_mask = 0xffffffff; 34889a2d2d87SDeepak S GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]); 34899a2d2d87SDeepak S GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]); 34909a2d2d87SDeepak S GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_irq_mask, dev_priv->pm_rps_events); 34919a2d2d87SDeepak S GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]); 3492abd58f01SBen Widawsky } 3493abd58f01SBen Widawsky 3494abd58f01SBen Widawsky static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv) 3495abd58f01SBen Widawsky { 3496770de83dSDamien Lespiau uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE; 3497770de83dSDamien Lespiau uint32_t de_pipe_enables; 3498abd58f01SBen Widawsky int pipe; 349988e04703SJesse Barnes u32 aux_en = GEN8_AUX_CHANNEL_A; 3500770de83dSDamien Lespiau 350188e04703SJesse Barnes if (IS_GEN9(dev_priv)) { 3502770de83dSDamien Lespiau de_pipe_masked |= GEN9_PIPE_PLANE1_FLIP_DONE | 3503770de83dSDamien Lespiau GEN9_DE_PIPE_IRQ_FAULT_ERRORS; 350488e04703SJesse Barnes aux_en |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C | 350588e04703SJesse Barnes GEN9_AUX_CHANNEL_D; 350688e04703SJesse Barnes } else 3507770de83dSDamien Lespiau de_pipe_masked |= GEN8_PIPE_PRIMARY_FLIP_DONE | 3508770de83dSDamien Lespiau GEN8_DE_PIPE_IRQ_FAULT_ERRORS; 3509770de83dSDamien Lespiau 3510770de83dSDamien Lespiau de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK | 3511770de83dSDamien Lespiau GEN8_PIPE_FIFO_UNDERRUN; 3512770de83dSDamien Lespiau 351313b3a0a7SDaniel Vetter dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked; 351413b3a0a7SDaniel Vetter dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked; 351513b3a0a7SDaniel Vetter dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked; 3516abd58f01SBen Widawsky 3517055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 3518f458ebbcSDaniel Vetter if (intel_display_power_is_enabled(dev_priv, 3519813bde43SPaulo Zanoni POWER_DOMAIN_PIPE(pipe))) 3520813bde43SPaulo Zanoni GEN8_IRQ_INIT_NDX(DE_PIPE, pipe, 3521813bde43SPaulo Zanoni dev_priv->de_irq_mask[pipe], 352235079899SPaulo Zanoni de_pipe_enables); 3523abd58f01SBen Widawsky 352488e04703SJesse Barnes GEN5_IRQ_INIT(GEN8_DE_PORT_, ~aux_en, aux_en); 3525abd58f01SBen Widawsky } 3526abd58f01SBen Widawsky 3527abd58f01SBen Widawsky static int gen8_irq_postinstall(struct drm_device *dev) 3528abd58f01SBen Widawsky { 3529abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 3530abd58f01SBen Widawsky 3531622364b6SPaulo Zanoni ibx_irq_pre_postinstall(dev); 3532622364b6SPaulo Zanoni 3533abd58f01SBen Widawsky gen8_gt_irq_postinstall(dev_priv); 3534abd58f01SBen Widawsky gen8_de_irq_postinstall(dev_priv); 3535abd58f01SBen Widawsky 3536abd58f01SBen Widawsky ibx_irq_postinstall(dev); 3537abd58f01SBen Widawsky 3538abd58f01SBen Widawsky I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL); 3539abd58f01SBen Widawsky POSTING_READ(GEN8_MASTER_IRQ); 3540abd58f01SBen Widawsky 3541abd58f01SBen Widawsky return 0; 3542abd58f01SBen Widawsky } 3543abd58f01SBen Widawsky 354443f328d7SVille Syrjälä static int cherryview_irq_postinstall(struct drm_device *dev) 354543f328d7SVille Syrjälä { 354643f328d7SVille Syrjälä struct drm_i915_private *dev_priv = dev->dev_private; 354743f328d7SVille Syrjälä 3548c2b66797SVille Syrjälä vlv_display_irq_postinstall(dev_priv); 354943f328d7SVille Syrjälä 355043f328d7SVille Syrjälä gen8_gt_irq_postinstall(dev_priv); 355143f328d7SVille Syrjälä 355243f328d7SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, MASTER_INTERRUPT_ENABLE); 355343f328d7SVille Syrjälä POSTING_READ(GEN8_MASTER_IRQ); 355443f328d7SVille Syrjälä 355543f328d7SVille Syrjälä return 0; 355643f328d7SVille Syrjälä } 355743f328d7SVille Syrjälä 3558abd58f01SBen Widawsky static void gen8_irq_uninstall(struct drm_device *dev) 3559abd58f01SBen Widawsky { 3560abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 3561abd58f01SBen Widawsky 3562abd58f01SBen Widawsky if (!dev_priv) 3563abd58f01SBen Widawsky return; 3564abd58f01SBen Widawsky 3565823f6b38SPaulo Zanoni gen8_irq_reset(dev); 3566abd58f01SBen Widawsky } 3567abd58f01SBen Widawsky 35688ea0be4fSVille Syrjälä static void vlv_display_irq_uninstall(struct drm_i915_private *dev_priv) 35698ea0be4fSVille Syrjälä { 35708ea0be4fSVille Syrjälä /* Interrupt setup is already guaranteed to be single-threaded, this is 35718ea0be4fSVille Syrjälä * just to make the assert_spin_locked check happy. */ 35728ea0be4fSVille Syrjälä spin_lock_irq(&dev_priv->irq_lock); 35738ea0be4fSVille Syrjälä if (dev_priv->display_irqs_enabled) 35748ea0be4fSVille Syrjälä valleyview_display_irqs_uninstall(dev_priv); 35758ea0be4fSVille Syrjälä spin_unlock_irq(&dev_priv->irq_lock); 35768ea0be4fSVille Syrjälä 35778ea0be4fSVille Syrjälä vlv_display_irq_reset(dev_priv); 35788ea0be4fSVille Syrjälä 35798ea0be4fSVille Syrjälä dev_priv->irq_mask = 0; 35808ea0be4fSVille Syrjälä } 35818ea0be4fSVille Syrjälä 35827e231dbeSJesse Barnes static void valleyview_irq_uninstall(struct drm_device *dev) 35837e231dbeSJesse Barnes { 35842d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 35857e231dbeSJesse Barnes 35867e231dbeSJesse Barnes if (!dev_priv) 35877e231dbeSJesse Barnes return; 35887e231dbeSJesse Barnes 3589843d0e7dSImre Deak I915_WRITE(VLV_MASTER_IER, 0); 3590843d0e7dSImre Deak 3591893fce8eSVille Syrjälä gen5_gt_irq_reset(dev); 3592893fce8eSVille Syrjälä 35937e231dbeSJesse Barnes I915_WRITE(HWSTAM, 0xffffffff); 3594f8b79e58SImre Deak 35958ea0be4fSVille Syrjälä vlv_display_irq_uninstall(dev_priv); 35967e231dbeSJesse Barnes } 35977e231dbeSJesse Barnes 359843f328d7SVille Syrjälä static void cherryview_irq_uninstall(struct drm_device *dev) 359943f328d7SVille Syrjälä { 360043f328d7SVille Syrjälä struct drm_i915_private *dev_priv = dev->dev_private; 360143f328d7SVille Syrjälä 360243f328d7SVille Syrjälä if (!dev_priv) 360343f328d7SVille Syrjälä return; 360443f328d7SVille Syrjälä 360543f328d7SVille Syrjälä I915_WRITE(GEN8_MASTER_IRQ, 0); 360643f328d7SVille Syrjälä POSTING_READ(GEN8_MASTER_IRQ); 360743f328d7SVille Syrjälä 3608a2c30fbaSVille Syrjälä gen8_gt_irq_reset(dev_priv); 360943f328d7SVille Syrjälä 3610a2c30fbaSVille Syrjälä GEN5_IRQ_RESET(GEN8_PCU_); 361143f328d7SVille Syrjälä 3612c2b66797SVille Syrjälä vlv_display_irq_uninstall(dev_priv); 361343f328d7SVille Syrjälä } 361443f328d7SVille Syrjälä 3615f71d4af4SJesse Barnes static void ironlake_irq_uninstall(struct drm_device *dev) 3616036a4a7dSZhenyu Wang { 36172d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 36184697995bSJesse Barnes 36194697995bSJesse Barnes if (!dev_priv) 36204697995bSJesse Barnes return; 36214697995bSJesse Barnes 3622be30b29fSPaulo Zanoni ironlake_irq_reset(dev); 3623036a4a7dSZhenyu Wang } 3624036a4a7dSZhenyu Wang 3625c2798b19SChris Wilson static void i8xx_irq_preinstall(struct drm_device * dev) 3626c2798b19SChris Wilson { 36272d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3628c2798b19SChris Wilson int pipe; 3629c2798b19SChris Wilson 3630055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 3631c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3632c2798b19SChris Wilson I915_WRITE16(IMR, 0xffff); 3633c2798b19SChris Wilson I915_WRITE16(IER, 0x0); 3634c2798b19SChris Wilson POSTING_READ16(IER); 3635c2798b19SChris Wilson } 3636c2798b19SChris Wilson 3637c2798b19SChris Wilson static int i8xx_irq_postinstall(struct drm_device *dev) 3638c2798b19SChris Wilson { 36392d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3640c2798b19SChris Wilson 3641c2798b19SChris Wilson I915_WRITE16(EMR, 3642c2798b19SChris Wilson ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH)); 3643c2798b19SChris Wilson 3644c2798b19SChris Wilson /* Unmask the interrupts that we always want on. */ 3645c2798b19SChris Wilson dev_priv->irq_mask = 3646c2798b19SChris Wilson ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3647c2798b19SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3648c2798b19SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 3649c2798b19SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | 3650c2798b19SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 3651c2798b19SChris Wilson I915_WRITE16(IMR, dev_priv->irq_mask); 3652c2798b19SChris Wilson 3653c2798b19SChris Wilson I915_WRITE16(IER, 3654c2798b19SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3655c2798b19SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3656c2798b19SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT | 3657c2798b19SChris Wilson I915_USER_INTERRUPT); 3658c2798b19SChris Wilson POSTING_READ16(IER); 3659c2798b19SChris Wilson 3660379ef82dSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3661379ef82dSDaniel Vetter * just to make the assert_spin_locked check happy. */ 3662d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 3663755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 3664755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 3665d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 3666379ef82dSDaniel Vetter 3667c2798b19SChris Wilson return 0; 3668c2798b19SChris Wilson } 3669c2798b19SChris Wilson 367090a72f87SVille Syrjälä /* 367190a72f87SVille Syrjälä * Returns true when a page flip has completed. 367290a72f87SVille Syrjälä */ 367390a72f87SVille Syrjälä static bool i8xx_handle_vblank(struct drm_device *dev, 36741f1c2e24SVille Syrjälä int plane, int pipe, u32 iir) 367590a72f87SVille Syrjälä { 36762d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 36771f1c2e24SVille Syrjälä u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane); 367890a72f87SVille Syrjälä 36798d7849dbSVille Syrjälä if (!intel_pipe_handle_vblank(dev, pipe)) 368090a72f87SVille Syrjälä return false; 368190a72f87SVille Syrjälä 368290a72f87SVille Syrjälä if ((iir & flip_pending) == 0) 3683d6bbafa1SChris Wilson goto check_page_flip; 368490a72f87SVille Syrjälä 36851f1c2e24SVille Syrjälä intel_prepare_page_flip(dev, plane); 368690a72f87SVille Syrjälä 368790a72f87SVille Syrjälä /* We detect FlipDone by looking for the change in PendingFlip from '1' 368890a72f87SVille Syrjälä * to '0' on the following vblank, i.e. IIR has the Pendingflip 368990a72f87SVille Syrjälä * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence 369090a72f87SVille Syrjälä * the flip is completed (no longer pending). Since this doesn't raise 369190a72f87SVille Syrjälä * an interrupt per se, we watch for the change at vblank. 369290a72f87SVille Syrjälä */ 369390a72f87SVille Syrjälä if (I915_READ16(ISR) & flip_pending) 3694d6bbafa1SChris Wilson goto check_page_flip; 369590a72f87SVille Syrjälä 369690a72f87SVille Syrjälä intel_finish_page_flip(dev, pipe); 369790a72f87SVille Syrjälä return true; 3698d6bbafa1SChris Wilson 3699d6bbafa1SChris Wilson check_page_flip: 3700d6bbafa1SChris Wilson intel_check_page_flip(dev, pipe); 3701d6bbafa1SChris Wilson return false; 370290a72f87SVille Syrjälä } 370390a72f87SVille Syrjälä 3704ff1f525eSDaniel Vetter static irqreturn_t i8xx_irq_handler(int irq, void *arg) 3705c2798b19SChris Wilson { 370645a83f84SDaniel Vetter struct drm_device *dev = arg; 37072d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3708c2798b19SChris Wilson u16 iir, new_iir; 3709c2798b19SChris Wilson u32 pipe_stats[2]; 3710c2798b19SChris Wilson int pipe; 3711c2798b19SChris Wilson u16 flip_mask = 3712c2798b19SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 3713c2798b19SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 3714c2798b19SChris Wilson 3715c2798b19SChris Wilson iir = I915_READ16(IIR); 3716c2798b19SChris Wilson if (iir == 0) 3717c2798b19SChris Wilson return IRQ_NONE; 3718c2798b19SChris Wilson 3719c2798b19SChris Wilson while (iir & ~flip_mask) { 3720c2798b19SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 3721c2798b19SChris Wilson * have been cleared after the pipestat interrupt was received. 3722c2798b19SChris Wilson * It doesn't set the bit in iir again, but it still produces 3723c2798b19SChris Wilson * interrupts (for non-MSI). 3724c2798b19SChris Wilson */ 3725222c7f51SDaniel Vetter spin_lock(&dev_priv->irq_lock); 3726c2798b19SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 372758174462SMika Kuoppala i915_handle_error(dev, false, 372858174462SMika Kuoppala "Command parser error, iir 0x%08x", 372958174462SMika Kuoppala iir); 3730c2798b19SChris Wilson 3731055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 3732c2798b19SChris Wilson int reg = PIPESTAT(pipe); 3733c2798b19SChris Wilson pipe_stats[pipe] = I915_READ(reg); 3734c2798b19SChris Wilson 3735c2798b19SChris Wilson /* 3736c2798b19SChris Wilson * Clear the PIPE*STAT regs before the IIR 3737c2798b19SChris Wilson */ 37382d9d2b0bSVille Syrjälä if (pipe_stats[pipe] & 0x8000ffff) 3739c2798b19SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 3740c2798b19SChris Wilson } 3741222c7f51SDaniel Vetter spin_unlock(&dev_priv->irq_lock); 3742c2798b19SChris Wilson 3743c2798b19SChris Wilson I915_WRITE16(IIR, iir & ~flip_mask); 3744c2798b19SChris Wilson new_iir = I915_READ16(IIR); /* Flush posted writes */ 3745c2798b19SChris Wilson 3746d05c617eSDaniel Vetter i915_update_dri1_breadcrumb(dev); 3747c2798b19SChris Wilson 3748c2798b19SChris Wilson if (iir & I915_USER_INTERRUPT) 3749c2798b19SChris Wilson notify_ring(dev, &dev_priv->ring[RCS]); 3750c2798b19SChris Wilson 3751055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 37521f1c2e24SVille Syrjälä int plane = pipe; 37533a77c4c4SDaniel Vetter if (HAS_FBC(dev)) 37541f1c2e24SVille Syrjälä plane = !plane; 37551f1c2e24SVille Syrjälä 37564356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS && 37571f1c2e24SVille Syrjälä i8xx_handle_vblank(dev, plane, pipe, iir)) 37581f1c2e24SVille Syrjälä flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane); 3759c2798b19SChris Wilson 37604356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 3761277de95eSDaniel Vetter i9xx_pipe_crc_irq_handler(dev, pipe); 37622d9d2b0bSVille Syrjälä 37631f7247c0SDaniel Vetter if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 37641f7247c0SDaniel Vetter intel_cpu_fifo_underrun_irq_handler(dev_priv, 37651f7247c0SDaniel Vetter pipe); 37664356d586SDaniel Vetter } 3767c2798b19SChris Wilson 3768c2798b19SChris Wilson iir = new_iir; 3769c2798b19SChris Wilson } 3770c2798b19SChris Wilson 3771c2798b19SChris Wilson return IRQ_HANDLED; 3772c2798b19SChris Wilson } 3773c2798b19SChris Wilson 3774c2798b19SChris Wilson static void i8xx_irq_uninstall(struct drm_device * dev) 3775c2798b19SChris Wilson { 37762d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3777c2798b19SChris Wilson int pipe; 3778c2798b19SChris Wilson 3779055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 3780c2798b19SChris Wilson /* Clear enable bits; then clear status bits */ 3781c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3782c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe))); 3783c2798b19SChris Wilson } 3784c2798b19SChris Wilson I915_WRITE16(IMR, 0xffff); 3785c2798b19SChris Wilson I915_WRITE16(IER, 0x0); 3786c2798b19SChris Wilson I915_WRITE16(IIR, I915_READ16(IIR)); 3787c2798b19SChris Wilson } 3788c2798b19SChris Wilson 3789a266c7d5SChris Wilson static void i915_irq_preinstall(struct drm_device * dev) 3790a266c7d5SChris Wilson { 37912d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3792a266c7d5SChris Wilson int pipe; 3793a266c7d5SChris Wilson 3794a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 3795a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 3796a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3797a266c7d5SChris Wilson } 3798a266c7d5SChris Wilson 379900d98ebdSChris Wilson I915_WRITE16(HWSTAM, 0xeffe); 3800055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 3801a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3802a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 3803a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 3804a266c7d5SChris Wilson POSTING_READ(IER); 3805a266c7d5SChris Wilson } 3806a266c7d5SChris Wilson 3807a266c7d5SChris Wilson static int i915_irq_postinstall(struct drm_device *dev) 3808a266c7d5SChris Wilson { 38092d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 381038bde180SChris Wilson u32 enable_mask; 3811a266c7d5SChris Wilson 381238bde180SChris Wilson I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH)); 381338bde180SChris Wilson 381438bde180SChris Wilson /* Unmask the interrupts that we always want on. */ 381538bde180SChris Wilson dev_priv->irq_mask = 381638bde180SChris Wilson ~(I915_ASLE_INTERRUPT | 381738bde180SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 381838bde180SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 381938bde180SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 382038bde180SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | 382138bde180SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 382238bde180SChris Wilson 382338bde180SChris Wilson enable_mask = 382438bde180SChris Wilson I915_ASLE_INTERRUPT | 382538bde180SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 382638bde180SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 382738bde180SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT | 382838bde180SChris Wilson I915_USER_INTERRUPT; 382938bde180SChris Wilson 3830a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 383120afbda2SDaniel Vetter I915_WRITE(PORT_HOTPLUG_EN, 0); 383220afbda2SDaniel Vetter POSTING_READ(PORT_HOTPLUG_EN); 383320afbda2SDaniel Vetter 3834a266c7d5SChris Wilson /* Enable in IER... */ 3835a266c7d5SChris Wilson enable_mask |= I915_DISPLAY_PORT_INTERRUPT; 3836a266c7d5SChris Wilson /* and unmask in IMR */ 3837a266c7d5SChris Wilson dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT; 3838a266c7d5SChris Wilson } 3839a266c7d5SChris Wilson 3840a266c7d5SChris Wilson I915_WRITE(IMR, dev_priv->irq_mask); 3841a266c7d5SChris Wilson I915_WRITE(IER, enable_mask); 3842a266c7d5SChris Wilson POSTING_READ(IER); 3843a266c7d5SChris Wilson 3844f49e38ddSJani Nikula i915_enable_asle_pipestat(dev); 384520afbda2SDaniel Vetter 3846379ef82dSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3847379ef82dSDaniel Vetter * just to make the assert_spin_locked check happy. */ 3848d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 3849755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 3850755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 3851d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 3852379ef82dSDaniel Vetter 385320afbda2SDaniel Vetter return 0; 385420afbda2SDaniel Vetter } 385520afbda2SDaniel Vetter 385690a72f87SVille Syrjälä /* 385790a72f87SVille Syrjälä * Returns true when a page flip has completed. 385890a72f87SVille Syrjälä */ 385990a72f87SVille Syrjälä static bool i915_handle_vblank(struct drm_device *dev, 386090a72f87SVille Syrjälä int plane, int pipe, u32 iir) 386190a72f87SVille Syrjälä { 38622d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 386390a72f87SVille Syrjälä u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane); 386490a72f87SVille Syrjälä 38658d7849dbSVille Syrjälä if (!intel_pipe_handle_vblank(dev, pipe)) 386690a72f87SVille Syrjälä return false; 386790a72f87SVille Syrjälä 386890a72f87SVille Syrjälä if ((iir & flip_pending) == 0) 3869d6bbafa1SChris Wilson goto check_page_flip; 387090a72f87SVille Syrjälä 387190a72f87SVille Syrjälä intel_prepare_page_flip(dev, plane); 387290a72f87SVille Syrjälä 387390a72f87SVille Syrjälä /* We detect FlipDone by looking for the change in PendingFlip from '1' 387490a72f87SVille Syrjälä * to '0' on the following vblank, i.e. IIR has the Pendingflip 387590a72f87SVille Syrjälä * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence 387690a72f87SVille Syrjälä * the flip is completed (no longer pending). Since this doesn't raise 387790a72f87SVille Syrjälä * an interrupt per se, we watch for the change at vblank. 387890a72f87SVille Syrjälä */ 387990a72f87SVille Syrjälä if (I915_READ(ISR) & flip_pending) 3880d6bbafa1SChris Wilson goto check_page_flip; 388190a72f87SVille Syrjälä 388290a72f87SVille Syrjälä intel_finish_page_flip(dev, pipe); 388390a72f87SVille Syrjälä return true; 3884d6bbafa1SChris Wilson 3885d6bbafa1SChris Wilson check_page_flip: 3886d6bbafa1SChris Wilson intel_check_page_flip(dev, pipe); 3887d6bbafa1SChris Wilson return false; 388890a72f87SVille Syrjälä } 388990a72f87SVille Syrjälä 3890ff1f525eSDaniel Vetter static irqreturn_t i915_irq_handler(int irq, void *arg) 3891a266c7d5SChris Wilson { 389245a83f84SDaniel Vetter struct drm_device *dev = arg; 38932d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 38948291ee90SChris Wilson u32 iir, new_iir, pipe_stats[I915_MAX_PIPES]; 389538bde180SChris Wilson u32 flip_mask = 389638bde180SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 389738bde180SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 389838bde180SChris Wilson int pipe, ret = IRQ_NONE; 3899a266c7d5SChris Wilson 3900a266c7d5SChris Wilson iir = I915_READ(IIR); 390138bde180SChris Wilson do { 390238bde180SChris Wilson bool irq_received = (iir & ~flip_mask) != 0; 39038291ee90SChris Wilson bool blc_event = false; 3904a266c7d5SChris Wilson 3905a266c7d5SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 3906a266c7d5SChris Wilson * have been cleared after the pipestat interrupt was received. 3907a266c7d5SChris Wilson * It doesn't set the bit in iir again, but it still produces 3908a266c7d5SChris Wilson * interrupts (for non-MSI). 3909a266c7d5SChris Wilson */ 3910222c7f51SDaniel Vetter spin_lock(&dev_priv->irq_lock); 3911a266c7d5SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 391258174462SMika Kuoppala i915_handle_error(dev, false, 391358174462SMika Kuoppala "Command parser error, iir 0x%08x", 391458174462SMika Kuoppala iir); 3915a266c7d5SChris Wilson 3916055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 3917a266c7d5SChris Wilson int reg = PIPESTAT(pipe); 3918a266c7d5SChris Wilson pipe_stats[pipe] = I915_READ(reg); 3919a266c7d5SChris Wilson 392038bde180SChris Wilson /* Clear the PIPE*STAT regs before the IIR */ 3921a266c7d5SChris Wilson if (pipe_stats[pipe] & 0x8000ffff) { 3922a266c7d5SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 392338bde180SChris Wilson irq_received = true; 3924a266c7d5SChris Wilson } 3925a266c7d5SChris Wilson } 3926222c7f51SDaniel Vetter spin_unlock(&dev_priv->irq_lock); 3927a266c7d5SChris Wilson 3928a266c7d5SChris Wilson if (!irq_received) 3929a266c7d5SChris Wilson break; 3930a266c7d5SChris Wilson 3931a266c7d5SChris Wilson /* Consume port. Then clear IIR or we'll miss events */ 393216c6c56bSVille Syrjälä if (I915_HAS_HOTPLUG(dev) && 393316c6c56bSVille Syrjälä iir & I915_DISPLAY_PORT_INTERRUPT) 393416c6c56bSVille Syrjälä i9xx_hpd_irq_handler(dev); 3935a266c7d5SChris Wilson 393638bde180SChris Wilson I915_WRITE(IIR, iir & ~flip_mask); 3937a266c7d5SChris Wilson new_iir = I915_READ(IIR); /* Flush posted writes */ 3938a266c7d5SChris Wilson 3939a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 3940a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[RCS]); 3941a266c7d5SChris Wilson 3942055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 394338bde180SChris Wilson int plane = pipe; 39443a77c4c4SDaniel Vetter if (HAS_FBC(dev)) 394538bde180SChris Wilson plane = !plane; 39465e2032d4SVille Syrjälä 394790a72f87SVille Syrjälä if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS && 394890a72f87SVille Syrjälä i915_handle_vblank(dev, plane, pipe, iir)) 394990a72f87SVille Syrjälä flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane); 3950a266c7d5SChris Wilson 3951a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 3952a266c7d5SChris Wilson blc_event = true; 39534356d586SDaniel Vetter 39544356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 3955277de95eSDaniel Vetter i9xx_pipe_crc_irq_handler(dev, pipe); 39562d9d2b0bSVille Syrjälä 39571f7247c0SDaniel Vetter if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 39581f7247c0SDaniel Vetter intel_cpu_fifo_underrun_irq_handler(dev_priv, 39591f7247c0SDaniel Vetter pipe); 3960a266c7d5SChris Wilson } 3961a266c7d5SChris Wilson 3962a266c7d5SChris Wilson if (blc_event || (iir & I915_ASLE_INTERRUPT)) 3963a266c7d5SChris Wilson intel_opregion_asle_intr(dev); 3964a266c7d5SChris Wilson 3965a266c7d5SChris Wilson /* With MSI, interrupts are only generated when iir 3966a266c7d5SChris Wilson * transitions from zero to nonzero. If another bit got 3967a266c7d5SChris Wilson * set while we were handling the existing iir bits, then 3968a266c7d5SChris Wilson * we would never get another interrupt. 3969a266c7d5SChris Wilson * 3970a266c7d5SChris Wilson * This is fine on non-MSI as well, as if we hit this path 3971a266c7d5SChris Wilson * we avoid exiting the interrupt handler only to generate 3972a266c7d5SChris Wilson * another one. 3973a266c7d5SChris Wilson * 3974a266c7d5SChris Wilson * Note that for MSI this could cause a stray interrupt report 3975a266c7d5SChris Wilson * if an interrupt landed in the time between writing IIR and 3976a266c7d5SChris Wilson * the posting read. This should be rare enough to never 3977a266c7d5SChris Wilson * trigger the 99% of 100,000 interrupts test for disabling 3978a266c7d5SChris Wilson * stray interrupts. 3979a266c7d5SChris Wilson */ 398038bde180SChris Wilson ret = IRQ_HANDLED; 3981a266c7d5SChris Wilson iir = new_iir; 398238bde180SChris Wilson } while (iir & ~flip_mask); 3983a266c7d5SChris Wilson 3984d05c617eSDaniel Vetter i915_update_dri1_breadcrumb(dev); 39858291ee90SChris Wilson 3986a266c7d5SChris Wilson return ret; 3987a266c7d5SChris Wilson } 3988a266c7d5SChris Wilson 3989a266c7d5SChris Wilson static void i915_irq_uninstall(struct drm_device * dev) 3990a266c7d5SChris Wilson { 39912d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3992a266c7d5SChris Wilson int pipe; 3993a266c7d5SChris Wilson 3994a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 3995a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 3996a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3997a266c7d5SChris Wilson } 3998a266c7d5SChris Wilson 399900d98ebdSChris Wilson I915_WRITE16(HWSTAM, 0xffff); 4000055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 400155b39755SChris Wilson /* Clear enable bits; then clear status bits */ 4002a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 400355b39755SChris Wilson I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe))); 400455b39755SChris Wilson } 4005a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 4006a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 4007a266c7d5SChris Wilson 4008a266c7d5SChris Wilson I915_WRITE(IIR, I915_READ(IIR)); 4009a266c7d5SChris Wilson } 4010a266c7d5SChris Wilson 4011a266c7d5SChris Wilson static void i965_irq_preinstall(struct drm_device * dev) 4012a266c7d5SChris Wilson { 40132d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 4014a266c7d5SChris Wilson int pipe; 4015a266c7d5SChris Wilson 4016a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 4017a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 4018a266c7d5SChris Wilson 4019a266c7d5SChris Wilson I915_WRITE(HWSTAM, 0xeffe); 4020055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 4021a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 4022a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 4023a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 4024a266c7d5SChris Wilson POSTING_READ(IER); 4025a266c7d5SChris Wilson } 4026a266c7d5SChris Wilson 4027a266c7d5SChris Wilson static int i965_irq_postinstall(struct drm_device *dev) 4028a266c7d5SChris Wilson { 40292d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 4030bbba0a97SChris Wilson u32 enable_mask; 4031a266c7d5SChris Wilson u32 error_mask; 4032a266c7d5SChris Wilson 4033a266c7d5SChris Wilson /* Unmask the interrupts that we always want on. */ 4034bbba0a97SChris Wilson dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT | 4035adca4730SChris Wilson I915_DISPLAY_PORT_INTERRUPT | 4036bbba0a97SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 4037bbba0a97SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 4038bbba0a97SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 4039bbba0a97SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | 4040bbba0a97SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 4041bbba0a97SChris Wilson 4042bbba0a97SChris Wilson enable_mask = ~dev_priv->irq_mask; 404321ad8330SVille Syrjälä enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 404421ad8330SVille Syrjälä I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT); 4045bbba0a97SChris Wilson enable_mask |= I915_USER_INTERRUPT; 4046bbba0a97SChris Wilson 4047bbba0a97SChris Wilson if (IS_G4X(dev)) 4048bbba0a97SChris Wilson enable_mask |= I915_BSD_USER_INTERRUPT; 4049a266c7d5SChris Wilson 4050b79480baSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 4051b79480baSDaniel Vetter * just to make the assert_spin_locked check happy. */ 4052d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 4053755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS); 4054755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 4055755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 4056d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 4057a266c7d5SChris Wilson 4058a266c7d5SChris Wilson /* 4059a266c7d5SChris Wilson * Enable some error detection, note the instruction error mask 4060a266c7d5SChris Wilson * bit is reserved, so we leave it masked. 4061a266c7d5SChris Wilson */ 4062a266c7d5SChris Wilson if (IS_G4X(dev)) { 4063a266c7d5SChris Wilson error_mask = ~(GM45_ERROR_PAGE_TABLE | 4064a266c7d5SChris Wilson GM45_ERROR_MEM_PRIV | 4065a266c7d5SChris Wilson GM45_ERROR_CP_PRIV | 4066a266c7d5SChris Wilson I915_ERROR_MEMORY_REFRESH); 4067a266c7d5SChris Wilson } else { 4068a266c7d5SChris Wilson error_mask = ~(I915_ERROR_PAGE_TABLE | 4069a266c7d5SChris Wilson I915_ERROR_MEMORY_REFRESH); 4070a266c7d5SChris Wilson } 4071a266c7d5SChris Wilson I915_WRITE(EMR, error_mask); 4072a266c7d5SChris Wilson 4073a266c7d5SChris Wilson I915_WRITE(IMR, dev_priv->irq_mask); 4074a266c7d5SChris Wilson I915_WRITE(IER, enable_mask); 4075a266c7d5SChris Wilson POSTING_READ(IER); 4076a266c7d5SChris Wilson 407720afbda2SDaniel Vetter I915_WRITE(PORT_HOTPLUG_EN, 0); 407820afbda2SDaniel Vetter POSTING_READ(PORT_HOTPLUG_EN); 407920afbda2SDaniel Vetter 4080f49e38ddSJani Nikula i915_enable_asle_pipestat(dev); 408120afbda2SDaniel Vetter 408220afbda2SDaniel Vetter return 0; 408320afbda2SDaniel Vetter } 408420afbda2SDaniel Vetter 4085bac56d5bSEgbert Eich static void i915_hpd_irq_setup(struct drm_device *dev) 408620afbda2SDaniel Vetter { 40872d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 4088cd569aedSEgbert Eich struct intel_encoder *intel_encoder; 408920afbda2SDaniel Vetter u32 hotplug_en; 409020afbda2SDaniel Vetter 4091b5ea2d56SDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 4092b5ea2d56SDaniel Vetter 4093bac56d5bSEgbert Eich if (I915_HAS_HOTPLUG(dev)) { 4094bac56d5bSEgbert Eich hotplug_en = I915_READ(PORT_HOTPLUG_EN); 4095bac56d5bSEgbert Eich hotplug_en &= ~HOTPLUG_INT_EN_MASK; 4096adca4730SChris Wilson /* Note HDMI and DP share hotplug bits */ 4097e5868a31SEgbert Eich /* enable bits are the same for all generations */ 4098b2784e15SDamien Lespiau for_each_intel_encoder(dev, intel_encoder) 4099cd569aedSEgbert Eich if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) 4100cd569aedSEgbert Eich hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin]; 4101a266c7d5SChris Wilson /* Programming the CRT detection parameters tends 4102a266c7d5SChris Wilson to generate a spurious hotplug event about three 4103a266c7d5SChris Wilson seconds later. So just do it once. 4104a266c7d5SChris Wilson */ 4105a266c7d5SChris Wilson if (IS_G4X(dev)) 4106a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64; 410785fc95baSDaniel Vetter hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK; 4108a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; 4109a266c7d5SChris Wilson 4110a266c7d5SChris Wilson /* Ignore TV since it's buggy */ 4111a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, hotplug_en); 4112a266c7d5SChris Wilson } 4113bac56d5bSEgbert Eich } 4114a266c7d5SChris Wilson 4115ff1f525eSDaniel Vetter static irqreturn_t i965_irq_handler(int irq, void *arg) 4116a266c7d5SChris Wilson { 411745a83f84SDaniel Vetter struct drm_device *dev = arg; 41182d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 4119a266c7d5SChris Wilson u32 iir, new_iir; 4120a266c7d5SChris Wilson u32 pipe_stats[I915_MAX_PIPES]; 4121a266c7d5SChris Wilson int ret = IRQ_NONE, pipe; 412221ad8330SVille Syrjälä u32 flip_mask = 412321ad8330SVille Syrjälä I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 412421ad8330SVille Syrjälä I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 4125a266c7d5SChris Wilson 4126a266c7d5SChris Wilson iir = I915_READ(IIR); 4127a266c7d5SChris Wilson 4128a266c7d5SChris Wilson for (;;) { 4129501e01d7SVille Syrjälä bool irq_received = (iir & ~flip_mask) != 0; 41302c8ba29fSChris Wilson bool blc_event = false; 41312c8ba29fSChris Wilson 4132a266c7d5SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 4133a266c7d5SChris Wilson * have been cleared after the pipestat interrupt was received. 4134a266c7d5SChris Wilson * It doesn't set the bit in iir again, but it still produces 4135a266c7d5SChris Wilson * interrupts (for non-MSI). 4136a266c7d5SChris Wilson */ 4137222c7f51SDaniel Vetter spin_lock(&dev_priv->irq_lock); 4138a266c7d5SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 413958174462SMika Kuoppala i915_handle_error(dev, false, 414058174462SMika Kuoppala "Command parser error, iir 0x%08x", 414158174462SMika Kuoppala iir); 4142a266c7d5SChris Wilson 4143055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 4144a266c7d5SChris Wilson int reg = PIPESTAT(pipe); 4145a266c7d5SChris Wilson pipe_stats[pipe] = I915_READ(reg); 4146a266c7d5SChris Wilson 4147a266c7d5SChris Wilson /* 4148a266c7d5SChris Wilson * Clear the PIPE*STAT regs before the IIR 4149a266c7d5SChris Wilson */ 4150a266c7d5SChris Wilson if (pipe_stats[pipe] & 0x8000ffff) { 4151a266c7d5SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 4152501e01d7SVille Syrjälä irq_received = true; 4153a266c7d5SChris Wilson } 4154a266c7d5SChris Wilson } 4155222c7f51SDaniel Vetter spin_unlock(&dev_priv->irq_lock); 4156a266c7d5SChris Wilson 4157a266c7d5SChris Wilson if (!irq_received) 4158a266c7d5SChris Wilson break; 4159a266c7d5SChris Wilson 4160a266c7d5SChris Wilson ret = IRQ_HANDLED; 4161a266c7d5SChris Wilson 4162a266c7d5SChris Wilson /* Consume port. Then clear IIR or we'll miss events */ 416316c6c56bSVille Syrjälä if (iir & I915_DISPLAY_PORT_INTERRUPT) 416416c6c56bSVille Syrjälä i9xx_hpd_irq_handler(dev); 4165a266c7d5SChris Wilson 416621ad8330SVille Syrjälä I915_WRITE(IIR, iir & ~flip_mask); 4167a266c7d5SChris Wilson new_iir = I915_READ(IIR); /* Flush posted writes */ 4168a266c7d5SChris Wilson 4169a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 4170a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[RCS]); 4171a266c7d5SChris Wilson if (iir & I915_BSD_USER_INTERRUPT) 4172a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[VCS]); 4173a266c7d5SChris Wilson 4174055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) { 41752c8ba29fSChris Wilson if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS && 417690a72f87SVille Syrjälä i915_handle_vblank(dev, pipe, pipe, iir)) 417790a72f87SVille Syrjälä flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe); 4178a266c7d5SChris Wilson 4179a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 4180a266c7d5SChris Wilson blc_event = true; 41814356d586SDaniel Vetter 41824356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 4183277de95eSDaniel Vetter i9xx_pipe_crc_irq_handler(dev, pipe); 4184a266c7d5SChris Wilson 41851f7247c0SDaniel Vetter if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 41861f7247c0SDaniel Vetter intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 41872d9d2b0bSVille Syrjälä } 4188a266c7d5SChris Wilson 4189a266c7d5SChris Wilson if (blc_event || (iir & I915_ASLE_INTERRUPT)) 4190a266c7d5SChris Wilson intel_opregion_asle_intr(dev); 4191a266c7d5SChris Wilson 4192515ac2bbSDaniel Vetter if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 4193515ac2bbSDaniel Vetter gmbus_irq_handler(dev); 4194515ac2bbSDaniel Vetter 4195a266c7d5SChris Wilson /* With MSI, interrupts are only generated when iir 4196a266c7d5SChris Wilson * transitions from zero to nonzero. If another bit got 4197a266c7d5SChris Wilson * set while we were handling the existing iir bits, then 4198a266c7d5SChris Wilson * we would never get another interrupt. 4199a266c7d5SChris Wilson * 4200a266c7d5SChris Wilson * This is fine on non-MSI as well, as if we hit this path 4201a266c7d5SChris Wilson * we avoid exiting the interrupt handler only to generate 4202a266c7d5SChris Wilson * another one. 4203a266c7d5SChris Wilson * 4204a266c7d5SChris Wilson * Note that for MSI this could cause a stray interrupt report 4205a266c7d5SChris Wilson * if an interrupt landed in the time between writing IIR and 4206a266c7d5SChris Wilson * the posting read. This should be rare enough to never 4207a266c7d5SChris Wilson * trigger the 99% of 100,000 interrupts test for disabling 4208a266c7d5SChris Wilson * stray interrupts. 4209a266c7d5SChris Wilson */ 4210a266c7d5SChris Wilson iir = new_iir; 4211a266c7d5SChris Wilson } 4212a266c7d5SChris Wilson 4213d05c617eSDaniel Vetter i915_update_dri1_breadcrumb(dev); 42142c8ba29fSChris Wilson 4215a266c7d5SChris Wilson return ret; 4216a266c7d5SChris Wilson } 4217a266c7d5SChris Wilson 4218a266c7d5SChris Wilson static void i965_irq_uninstall(struct drm_device * dev) 4219a266c7d5SChris Wilson { 42202d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 4221a266c7d5SChris Wilson int pipe; 4222a266c7d5SChris Wilson 4223a266c7d5SChris Wilson if (!dev_priv) 4224a266c7d5SChris Wilson return; 4225a266c7d5SChris Wilson 4226a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 4227a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 4228a266c7d5SChris Wilson 4229a266c7d5SChris Wilson I915_WRITE(HWSTAM, 0xffffffff); 4230055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 4231a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 4232a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 4233a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 4234a266c7d5SChris Wilson 4235055e393fSDamien Lespiau for_each_pipe(dev_priv, pipe) 4236a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 4237a266c7d5SChris Wilson I915_READ(PIPESTAT(pipe)) & 0x8000ffff); 4238a266c7d5SChris Wilson I915_WRITE(IIR, I915_READ(IIR)); 4239a266c7d5SChris Wilson } 4240a266c7d5SChris Wilson 42414cb21832SDaniel Vetter static void intel_hpd_irq_reenable_work(struct work_struct *work) 4242ac4c16c5SEgbert Eich { 42436323751dSImre Deak struct drm_i915_private *dev_priv = 42446323751dSImre Deak container_of(work, typeof(*dev_priv), 42456323751dSImre Deak hotplug_reenable_work.work); 4246ac4c16c5SEgbert Eich struct drm_device *dev = dev_priv->dev; 4247ac4c16c5SEgbert Eich struct drm_mode_config *mode_config = &dev->mode_config; 4248ac4c16c5SEgbert Eich int i; 4249ac4c16c5SEgbert Eich 42506323751dSImre Deak intel_runtime_pm_get(dev_priv); 42516323751dSImre Deak 42524cb21832SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 4253ac4c16c5SEgbert Eich for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) { 4254ac4c16c5SEgbert Eich struct drm_connector *connector; 4255ac4c16c5SEgbert Eich 4256ac4c16c5SEgbert Eich if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED) 4257ac4c16c5SEgbert Eich continue; 4258ac4c16c5SEgbert Eich 4259ac4c16c5SEgbert Eich dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED; 4260ac4c16c5SEgbert Eich 4261ac4c16c5SEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 4262ac4c16c5SEgbert Eich struct intel_connector *intel_connector = to_intel_connector(connector); 4263ac4c16c5SEgbert Eich 4264ac4c16c5SEgbert Eich if (intel_connector->encoder->hpd_pin == i) { 4265ac4c16c5SEgbert Eich if (connector->polled != intel_connector->polled) 4266ac4c16c5SEgbert Eich DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n", 4267c23cc417SJani Nikula connector->name); 4268ac4c16c5SEgbert Eich connector->polled = intel_connector->polled; 4269ac4c16c5SEgbert Eich if (!connector->polled) 4270ac4c16c5SEgbert Eich connector->polled = DRM_CONNECTOR_POLL_HPD; 4271ac4c16c5SEgbert Eich } 4272ac4c16c5SEgbert Eich } 4273ac4c16c5SEgbert Eich } 4274ac4c16c5SEgbert Eich if (dev_priv->display.hpd_irq_setup) 4275ac4c16c5SEgbert Eich dev_priv->display.hpd_irq_setup(dev); 42764cb21832SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 42776323751dSImre Deak 42786323751dSImre Deak intel_runtime_pm_put(dev_priv); 4279ac4c16c5SEgbert Eich } 4280ac4c16c5SEgbert Eich 4281fca52a55SDaniel Vetter /** 4282fca52a55SDaniel Vetter * intel_irq_init - initializes irq support 4283fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4284fca52a55SDaniel Vetter * 4285fca52a55SDaniel Vetter * This function initializes all the irq support including work items, timers 4286fca52a55SDaniel Vetter * and all the vtables. It does not setup the interrupt itself though. 4287fca52a55SDaniel Vetter */ 4288b963291cSDaniel Vetter void intel_irq_init(struct drm_i915_private *dev_priv) 4289f71d4af4SJesse Barnes { 4290b963291cSDaniel Vetter struct drm_device *dev = dev_priv->dev; 42918b2e326dSChris Wilson 42928b2e326dSChris Wilson INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func); 429313cf5504SDave Airlie INIT_WORK(&dev_priv->dig_port_work, i915_digport_work_func); 429499584db3SDaniel Vetter INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func); 4295c6a828d3SDaniel Vetter INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work); 4296a4da4fa4SDaniel Vetter INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work); 42978b2e326dSChris Wilson 4298a6706b45SDeepak S /* Let's track the enabled rps events */ 4299b963291cSDaniel Vetter if (IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) 43006c65a587SVille Syrjälä /* WaGsvRC0ResidencyMethod:vlv */ 430131685c25SDeepak S dev_priv->pm_rps_events = GEN6_PM_RP_UP_EI_EXPIRED; 430231685c25SDeepak S else 4303a6706b45SDeepak S dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS; 4304a6706b45SDeepak S 430599584db3SDaniel Vetter setup_timer(&dev_priv->gpu_error.hangcheck_timer, 430699584db3SDaniel Vetter i915_hangcheck_elapsed, 430761bac78eSDaniel Vetter (unsigned long) dev); 43086323751dSImre Deak INIT_DELAYED_WORK(&dev_priv->hotplug_reenable_work, 43094cb21832SDaniel Vetter intel_hpd_irq_reenable_work); 431061bac78eSDaniel Vetter 431197a19a24STomas Janousek pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE); 43129ee32feaSDaniel Vetter 4313b963291cSDaniel Vetter if (IS_GEN2(dev_priv)) { 43144cdb83ecSVille Syrjälä dev->max_vblank_count = 0; 43154cdb83ecSVille Syrjälä dev->driver->get_vblank_counter = i8xx_get_vblank_counter; 4316b963291cSDaniel Vetter } else if (IS_G4X(dev_priv) || INTEL_INFO(dev_priv)->gen >= 5) { 4317f71d4af4SJesse Barnes dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */ 4318f71d4af4SJesse Barnes dev->driver->get_vblank_counter = gm45_get_vblank_counter; 4319391f75e2SVille Syrjälä } else { 4320391f75e2SVille Syrjälä dev->driver->get_vblank_counter = i915_get_vblank_counter; 4321391f75e2SVille Syrjälä dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ 4322f71d4af4SJesse Barnes } 4323f71d4af4SJesse Barnes 432421da2700SVille Syrjälä /* 432521da2700SVille Syrjälä * Opt out of the vblank disable timer on everything except gen2. 432621da2700SVille Syrjälä * Gen2 doesn't have a hardware frame counter and so depends on 432721da2700SVille Syrjälä * vblank interrupts to produce sane vblank seuquence numbers. 432821da2700SVille Syrjälä */ 4329b963291cSDaniel Vetter if (!IS_GEN2(dev_priv)) 433021da2700SVille Syrjälä dev->vblank_disable_immediate = true; 433121da2700SVille Syrjälä 4332c2baf4b7SVille Syrjälä if (drm_core_check_feature(dev, DRIVER_MODESET)) { 4333f71d4af4SJesse Barnes dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp; 4334f71d4af4SJesse Barnes dev->driver->get_scanout_position = i915_get_crtc_scanoutpos; 4335c2baf4b7SVille Syrjälä } 4336f71d4af4SJesse Barnes 4337b963291cSDaniel Vetter if (IS_CHERRYVIEW(dev_priv)) { 433843f328d7SVille Syrjälä dev->driver->irq_handler = cherryview_irq_handler; 433943f328d7SVille Syrjälä dev->driver->irq_preinstall = cherryview_irq_preinstall; 434043f328d7SVille Syrjälä dev->driver->irq_postinstall = cherryview_irq_postinstall; 434143f328d7SVille Syrjälä dev->driver->irq_uninstall = cherryview_irq_uninstall; 434243f328d7SVille Syrjälä dev->driver->enable_vblank = valleyview_enable_vblank; 434343f328d7SVille Syrjälä dev->driver->disable_vblank = valleyview_disable_vblank; 434443f328d7SVille Syrjälä dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 4345b963291cSDaniel Vetter } else if (IS_VALLEYVIEW(dev_priv)) { 43467e231dbeSJesse Barnes dev->driver->irq_handler = valleyview_irq_handler; 43477e231dbeSJesse Barnes dev->driver->irq_preinstall = valleyview_irq_preinstall; 43487e231dbeSJesse Barnes dev->driver->irq_postinstall = valleyview_irq_postinstall; 43497e231dbeSJesse Barnes dev->driver->irq_uninstall = valleyview_irq_uninstall; 43507e231dbeSJesse Barnes dev->driver->enable_vblank = valleyview_enable_vblank; 43517e231dbeSJesse Barnes dev->driver->disable_vblank = valleyview_disable_vblank; 4352fa00abe0SEgbert Eich dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 4353b963291cSDaniel Vetter } else if (INTEL_INFO(dev_priv)->gen >= 8) { 4354abd58f01SBen Widawsky dev->driver->irq_handler = gen8_irq_handler; 4355723761b8SDaniel Vetter dev->driver->irq_preinstall = gen8_irq_reset; 4356abd58f01SBen Widawsky dev->driver->irq_postinstall = gen8_irq_postinstall; 4357abd58f01SBen Widawsky dev->driver->irq_uninstall = gen8_irq_uninstall; 4358abd58f01SBen Widawsky dev->driver->enable_vblank = gen8_enable_vblank; 4359abd58f01SBen Widawsky dev->driver->disable_vblank = gen8_disable_vblank; 4360abd58f01SBen Widawsky dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup; 4361f71d4af4SJesse Barnes } else if (HAS_PCH_SPLIT(dev)) { 4362f71d4af4SJesse Barnes dev->driver->irq_handler = ironlake_irq_handler; 4363723761b8SDaniel Vetter dev->driver->irq_preinstall = ironlake_irq_reset; 4364f71d4af4SJesse Barnes dev->driver->irq_postinstall = ironlake_irq_postinstall; 4365f71d4af4SJesse Barnes dev->driver->irq_uninstall = ironlake_irq_uninstall; 4366f71d4af4SJesse Barnes dev->driver->enable_vblank = ironlake_enable_vblank; 4367f71d4af4SJesse Barnes dev->driver->disable_vblank = ironlake_disable_vblank; 436882a28bcfSDaniel Vetter dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup; 4369f71d4af4SJesse Barnes } else { 4370b963291cSDaniel Vetter if (INTEL_INFO(dev_priv)->gen == 2) { 4371c2798b19SChris Wilson dev->driver->irq_preinstall = i8xx_irq_preinstall; 4372c2798b19SChris Wilson dev->driver->irq_postinstall = i8xx_irq_postinstall; 4373c2798b19SChris Wilson dev->driver->irq_handler = i8xx_irq_handler; 4374c2798b19SChris Wilson dev->driver->irq_uninstall = i8xx_irq_uninstall; 4375b963291cSDaniel Vetter } else if (INTEL_INFO(dev_priv)->gen == 3) { 4376a266c7d5SChris Wilson dev->driver->irq_preinstall = i915_irq_preinstall; 4377a266c7d5SChris Wilson dev->driver->irq_postinstall = i915_irq_postinstall; 4378a266c7d5SChris Wilson dev->driver->irq_uninstall = i915_irq_uninstall; 4379a266c7d5SChris Wilson dev->driver->irq_handler = i915_irq_handler; 438020afbda2SDaniel Vetter dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 4381c2798b19SChris Wilson } else { 4382a266c7d5SChris Wilson dev->driver->irq_preinstall = i965_irq_preinstall; 4383a266c7d5SChris Wilson dev->driver->irq_postinstall = i965_irq_postinstall; 4384a266c7d5SChris Wilson dev->driver->irq_uninstall = i965_irq_uninstall; 4385a266c7d5SChris Wilson dev->driver->irq_handler = i965_irq_handler; 4386bac56d5bSEgbert Eich dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 4387c2798b19SChris Wilson } 4388f71d4af4SJesse Barnes dev->driver->enable_vblank = i915_enable_vblank; 4389f71d4af4SJesse Barnes dev->driver->disable_vblank = i915_disable_vblank; 4390f71d4af4SJesse Barnes } 4391f71d4af4SJesse Barnes } 439220afbda2SDaniel Vetter 4393fca52a55SDaniel Vetter /** 4394fca52a55SDaniel Vetter * intel_hpd_init - initializes and enables hpd support 4395fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4396fca52a55SDaniel Vetter * 4397fca52a55SDaniel Vetter * This function enables the hotplug support. It requires that interrupts have 4398fca52a55SDaniel Vetter * already been enabled with intel_irq_init_hw(). From this point on hotplug and 4399fca52a55SDaniel Vetter * poll request can run concurrently to other code, so locking rules must be 4400fca52a55SDaniel Vetter * obeyed. 4401fca52a55SDaniel Vetter * 4402fca52a55SDaniel Vetter * This is a separate step from interrupt enabling to simplify the locking rules 4403fca52a55SDaniel Vetter * in the driver load and resume code. 4404fca52a55SDaniel Vetter */ 4405b963291cSDaniel Vetter void intel_hpd_init(struct drm_i915_private *dev_priv) 440620afbda2SDaniel Vetter { 4407b963291cSDaniel Vetter struct drm_device *dev = dev_priv->dev; 4408821450c6SEgbert Eich struct drm_mode_config *mode_config = &dev->mode_config; 4409821450c6SEgbert Eich struct drm_connector *connector; 4410821450c6SEgbert Eich int i; 441120afbda2SDaniel Vetter 4412821450c6SEgbert Eich for (i = 1; i < HPD_NUM_PINS; i++) { 4413821450c6SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt = 0; 4414821450c6SEgbert Eich dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED; 4415821450c6SEgbert Eich } 4416821450c6SEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 4417821450c6SEgbert Eich struct intel_connector *intel_connector = to_intel_connector(connector); 4418821450c6SEgbert Eich connector->polled = intel_connector->polled; 44190e32b39cSDave Airlie if (connector->encoder && !connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE) 44200e32b39cSDave Airlie connector->polled = DRM_CONNECTOR_POLL_HPD; 44210e32b39cSDave Airlie if (intel_connector->mst_port) 4422821450c6SEgbert Eich connector->polled = DRM_CONNECTOR_POLL_HPD; 4423821450c6SEgbert Eich } 4424b5ea2d56SDaniel Vetter 4425b5ea2d56SDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 4426b5ea2d56SDaniel Vetter * just to make the assert_spin_locked checks happy. */ 4427d6207435SDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 442820afbda2SDaniel Vetter if (dev_priv->display.hpd_irq_setup) 442920afbda2SDaniel Vetter dev_priv->display.hpd_irq_setup(dev); 4430d6207435SDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 443120afbda2SDaniel Vetter } 4432c67a470bSPaulo Zanoni 4433fca52a55SDaniel Vetter /** 4434fca52a55SDaniel Vetter * intel_irq_install - enables the hardware interrupt 4435fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4436fca52a55SDaniel Vetter * 4437fca52a55SDaniel Vetter * This function enables the hardware interrupt handling, but leaves the hotplug 4438fca52a55SDaniel Vetter * handling still disabled. It is called after intel_irq_init(). 4439fca52a55SDaniel Vetter * 4440fca52a55SDaniel Vetter * In the driver load and resume code we need working interrupts in a few places 4441fca52a55SDaniel Vetter * but don't want to deal with the hassle of concurrent probe and hotplug 4442fca52a55SDaniel Vetter * workers. Hence the split into this two-stage approach. 4443fca52a55SDaniel Vetter */ 44442aeb7d3aSDaniel Vetter int intel_irq_install(struct drm_i915_private *dev_priv) 44452aeb7d3aSDaniel Vetter { 44462aeb7d3aSDaniel Vetter /* 44472aeb7d3aSDaniel Vetter * We enable some interrupt sources in our postinstall hooks, so mark 44482aeb7d3aSDaniel Vetter * interrupts as enabled _before_ actually enabling them to avoid 44492aeb7d3aSDaniel Vetter * special cases in our ordering checks. 44502aeb7d3aSDaniel Vetter */ 44512aeb7d3aSDaniel Vetter dev_priv->pm.irqs_enabled = true; 44522aeb7d3aSDaniel Vetter 44532aeb7d3aSDaniel Vetter return drm_irq_install(dev_priv->dev, dev_priv->dev->pdev->irq); 44542aeb7d3aSDaniel Vetter } 44552aeb7d3aSDaniel Vetter 4456fca52a55SDaniel Vetter /** 4457fca52a55SDaniel Vetter * intel_irq_uninstall - finilizes all irq handling 4458fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4459fca52a55SDaniel Vetter * 4460fca52a55SDaniel Vetter * This stops interrupt and hotplug handling and unregisters and frees all 4461fca52a55SDaniel Vetter * resources acquired in the init functions. 4462fca52a55SDaniel Vetter */ 44632aeb7d3aSDaniel Vetter void intel_irq_uninstall(struct drm_i915_private *dev_priv) 44642aeb7d3aSDaniel Vetter { 44652aeb7d3aSDaniel Vetter drm_irq_uninstall(dev_priv->dev); 44662aeb7d3aSDaniel Vetter intel_hpd_cancel_work(dev_priv); 44672aeb7d3aSDaniel Vetter dev_priv->pm.irqs_enabled = false; 44682aeb7d3aSDaniel Vetter } 44692aeb7d3aSDaniel Vetter 4470fca52a55SDaniel Vetter /** 4471fca52a55SDaniel Vetter * intel_runtime_pm_disable_interrupts - runtime interrupt disabling 4472fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4473fca52a55SDaniel Vetter * 4474fca52a55SDaniel Vetter * This function is used to disable interrupts at runtime, both in the runtime 4475fca52a55SDaniel Vetter * pm and the system suspend/resume code. 4476fca52a55SDaniel Vetter */ 4477b963291cSDaniel Vetter void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv) 4478c67a470bSPaulo Zanoni { 4479b963291cSDaniel Vetter dev_priv->dev->driver->irq_uninstall(dev_priv->dev); 44802aeb7d3aSDaniel Vetter dev_priv->pm.irqs_enabled = false; 4481c67a470bSPaulo Zanoni } 4482c67a470bSPaulo Zanoni 4483fca52a55SDaniel Vetter /** 4484fca52a55SDaniel Vetter * intel_runtime_pm_enable_interrupts - runtime interrupt enabling 4485fca52a55SDaniel Vetter * @dev_priv: i915 device instance 4486fca52a55SDaniel Vetter * 4487fca52a55SDaniel Vetter * This function is used to enable interrupts at runtime, both in the runtime 4488fca52a55SDaniel Vetter * pm and the system suspend/resume code. 4489fca52a55SDaniel Vetter */ 4490b963291cSDaniel Vetter void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv) 4491c67a470bSPaulo Zanoni { 44922aeb7d3aSDaniel Vetter dev_priv->pm.irqs_enabled = true; 4493b963291cSDaniel Vetter dev_priv->dev->driver->irq_preinstall(dev_priv->dev); 4494b963291cSDaniel Vetter dev_priv->dev->driver->irq_postinstall(dev_priv->dev); 4495c67a470bSPaulo Zanoni } 4496