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 40e5868a31SEgbert Eich static const u32 hpd_ibx[] = { 41e5868a31SEgbert Eich [HPD_CRT] = SDE_CRT_HOTPLUG, 42e5868a31SEgbert Eich [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG, 43e5868a31SEgbert Eich [HPD_PORT_B] = SDE_PORTB_HOTPLUG, 44e5868a31SEgbert Eich [HPD_PORT_C] = SDE_PORTC_HOTPLUG, 45e5868a31SEgbert Eich [HPD_PORT_D] = SDE_PORTD_HOTPLUG 46e5868a31SEgbert Eich }; 47e5868a31SEgbert Eich 48e5868a31SEgbert Eich static const u32 hpd_cpt[] = { 49e5868a31SEgbert Eich [HPD_CRT] = SDE_CRT_HOTPLUG_CPT, 5073c352a2SDaniel Vetter [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT, 51e5868a31SEgbert Eich [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT, 52e5868a31SEgbert Eich [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT, 53e5868a31SEgbert Eich [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT 54e5868a31SEgbert Eich }; 55e5868a31SEgbert Eich 56e5868a31SEgbert Eich static const u32 hpd_mask_i915[] = { 57e5868a31SEgbert Eich [HPD_CRT] = CRT_HOTPLUG_INT_EN, 58e5868a31SEgbert Eich [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN, 59e5868a31SEgbert Eich [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN, 60e5868a31SEgbert Eich [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN, 61e5868a31SEgbert Eich [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN, 62e5868a31SEgbert Eich [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN 63e5868a31SEgbert Eich }; 64e5868a31SEgbert Eich 65704cfb87SDaniel Vetter static const u32 hpd_status_g4x[] = { 66e5868a31SEgbert Eich [HPD_CRT] = CRT_HOTPLUG_INT_STATUS, 67e5868a31SEgbert Eich [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X, 68e5868a31SEgbert Eich [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X, 69e5868a31SEgbert Eich [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS, 70e5868a31SEgbert Eich [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS, 71e5868a31SEgbert Eich [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS 72e5868a31SEgbert Eich }; 73e5868a31SEgbert Eich 74e5868a31SEgbert Eich static const u32 hpd_status_i915[] = { /* i915 and valleyview are the same */ 75e5868a31SEgbert Eich [HPD_CRT] = CRT_HOTPLUG_INT_STATUS, 76e5868a31SEgbert Eich [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915, 77e5868a31SEgbert Eich [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915, 78e5868a31SEgbert Eich [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS, 79e5868a31SEgbert Eich [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS, 80e5868a31SEgbert Eich [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS 81e5868a31SEgbert Eich }; 82e5868a31SEgbert Eich 835c502442SPaulo Zanoni /* IIR can theoretically queue up two events. Be paranoid. */ 84f86f3fb0SPaulo Zanoni #define GEN8_IRQ_RESET_NDX(type, which) do { \ 855c502442SPaulo Zanoni I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \ 865c502442SPaulo Zanoni POSTING_READ(GEN8_##type##_IMR(which)); \ 875c502442SPaulo Zanoni I915_WRITE(GEN8_##type##_IER(which), 0); \ 885c502442SPaulo Zanoni I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \ 895c502442SPaulo Zanoni POSTING_READ(GEN8_##type##_IIR(which)); \ 905c502442SPaulo Zanoni I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \ 915c502442SPaulo Zanoni POSTING_READ(GEN8_##type##_IIR(which)); \ 925c502442SPaulo Zanoni } while (0) 935c502442SPaulo Zanoni 94f86f3fb0SPaulo Zanoni #define GEN5_IRQ_RESET(type) do { \ 95a9d356a6SPaulo Zanoni I915_WRITE(type##IMR, 0xffffffff); \ 965c502442SPaulo Zanoni POSTING_READ(type##IMR); \ 97a9d356a6SPaulo Zanoni I915_WRITE(type##IER, 0); \ 985c502442SPaulo Zanoni I915_WRITE(type##IIR, 0xffffffff); \ 995c502442SPaulo Zanoni POSTING_READ(type##IIR); \ 1005c502442SPaulo Zanoni I915_WRITE(type##IIR, 0xffffffff); \ 1015c502442SPaulo Zanoni POSTING_READ(type##IIR); \ 102a9d356a6SPaulo Zanoni } while (0) 103a9d356a6SPaulo Zanoni 104337ba017SPaulo Zanoni /* 105337ba017SPaulo Zanoni * We should clear IMR at preinstall/uninstall, and just check at postinstall. 106337ba017SPaulo Zanoni */ 107337ba017SPaulo Zanoni #define GEN5_ASSERT_IIR_IS_ZERO(reg) do { \ 108337ba017SPaulo Zanoni u32 val = I915_READ(reg); \ 109337ba017SPaulo Zanoni if (val) { \ 110337ba017SPaulo Zanoni WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n", \ 111337ba017SPaulo Zanoni (reg), val); \ 112337ba017SPaulo Zanoni I915_WRITE((reg), 0xffffffff); \ 113337ba017SPaulo Zanoni POSTING_READ(reg); \ 114337ba017SPaulo Zanoni I915_WRITE((reg), 0xffffffff); \ 115337ba017SPaulo Zanoni POSTING_READ(reg); \ 116337ba017SPaulo Zanoni } \ 117337ba017SPaulo Zanoni } while (0) 118337ba017SPaulo Zanoni 11935079899SPaulo Zanoni #define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \ 120337ba017SPaulo Zanoni GEN5_ASSERT_IIR_IS_ZERO(GEN8_##type##_IIR(which)); \ 12135079899SPaulo Zanoni I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \ 12235079899SPaulo Zanoni I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \ 12335079899SPaulo Zanoni POSTING_READ(GEN8_##type##_IER(which)); \ 12435079899SPaulo Zanoni } while (0) 12535079899SPaulo Zanoni 12635079899SPaulo Zanoni #define GEN5_IRQ_INIT(type, imr_val, ier_val) do { \ 127337ba017SPaulo Zanoni GEN5_ASSERT_IIR_IS_ZERO(type##IIR); \ 12835079899SPaulo Zanoni I915_WRITE(type##IMR, (imr_val)); \ 12935079899SPaulo Zanoni I915_WRITE(type##IER, (ier_val)); \ 13035079899SPaulo Zanoni POSTING_READ(type##IER); \ 13135079899SPaulo Zanoni } while (0) 13235079899SPaulo Zanoni 133036a4a7dSZhenyu Wang /* For display hotplug interrupt */ 134995b6762SChris Wilson static void 1352d1013ddSJani Nikula ironlake_enable_display_irq(struct drm_i915_private *dev_priv, u32 mask) 136036a4a7dSZhenyu Wang { 1374bc9d430SDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 1384bc9d430SDaniel Vetter 139730488b2SPaulo Zanoni if (WARN_ON(dev_priv->pm.irqs_disabled)) 140c67a470bSPaulo Zanoni return; 141c67a470bSPaulo Zanoni 1421ec14ad3SChris Wilson if ((dev_priv->irq_mask & mask) != 0) { 1431ec14ad3SChris Wilson dev_priv->irq_mask &= ~mask; 1441ec14ad3SChris Wilson I915_WRITE(DEIMR, dev_priv->irq_mask); 1453143a2bfSChris Wilson POSTING_READ(DEIMR); 146036a4a7dSZhenyu Wang } 147036a4a7dSZhenyu Wang } 148036a4a7dSZhenyu Wang 1490ff9800aSPaulo Zanoni static void 1502d1013ddSJani Nikula ironlake_disable_display_irq(struct drm_i915_private *dev_priv, u32 mask) 151036a4a7dSZhenyu Wang { 1524bc9d430SDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 1534bc9d430SDaniel Vetter 154730488b2SPaulo Zanoni if (WARN_ON(dev_priv->pm.irqs_disabled)) 155c67a470bSPaulo Zanoni return; 156c67a470bSPaulo Zanoni 1571ec14ad3SChris Wilson if ((dev_priv->irq_mask & mask) != mask) { 1581ec14ad3SChris Wilson dev_priv->irq_mask |= mask; 1591ec14ad3SChris Wilson I915_WRITE(DEIMR, dev_priv->irq_mask); 1603143a2bfSChris Wilson POSTING_READ(DEIMR); 161036a4a7dSZhenyu Wang } 162036a4a7dSZhenyu Wang } 163036a4a7dSZhenyu Wang 16443eaea13SPaulo Zanoni /** 16543eaea13SPaulo Zanoni * ilk_update_gt_irq - update GTIMR 16643eaea13SPaulo Zanoni * @dev_priv: driver private 16743eaea13SPaulo Zanoni * @interrupt_mask: mask of interrupt bits to update 16843eaea13SPaulo Zanoni * @enabled_irq_mask: mask of interrupt bits to enable 16943eaea13SPaulo Zanoni */ 17043eaea13SPaulo Zanoni static void ilk_update_gt_irq(struct drm_i915_private *dev_priv, 17143eaea13SPaulo Zanoni uint32_t interrupt_mask, 17243eaea13SPaulo Zanoni uint32_t enabled_irq_mask) 17343eaea13SPaulo Zanoni { 17443eaea13SPaulo Zanoni assert_spin_locked(&dev_priv->irq_lock); 17543eaea13SPaulo Zanoni 176730488b2SPaulo Zanoni if (WARN_ON(dev_priv->pm.irqs_disabled)) 177c67a470bSPaulo Zanoni return; 178c67a470bSPaulo Zanoni 17943eaea13SPaulo Zanoni dev_priv->gt_irq_mask &= ~interrupt_mask; 18043eaea13SPaulo Zanoni dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask); 18143eaea13SPaulo Zanoni I915_WRITE(GTIMR, dev_priv->gt_irq_mask); 18243eaea13SPaulo Zanoni POSTING_READ(GTIMR); 18343eaea13SPaulo Zanoni } 18443eaea13SPaulo Zanoni 18543eaea13SPaulo Zanoni void ilk_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask) 18643eaea13SPaulo Zanoni { 18743eaea13SPaulo Zanoni ilk_update_gt_irq(dev_priv, mask, mask); 18843eaea13SPaulo Zanoni } 18943eaea13SPaulo Zanoni 19043eaea13SPaulo Zanoni void ilk_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask) 19143eaea13SPaulo Zanoni { 19243eaea13SPaulo Zanoni ilk_update_gt_irq(dev_priv, mask, 0); 19343eaea13SPaulo Zanoni } 19443eaea13SPaulo Zanoni 195edbfdb45SPaulo Zanoni /** 196edbfdb45SPaulo Zanoni * snb_update_pm_irq - update GEN6_PMIMR 197edbfdb45SPaulo Zanoni * @dev_priv: driver private 198edbfdb45SPaulo Zanoni * @interrupt_mask: mask of interrupt bits to update 199edbfdb45SPaulo Zanoni * @enabled_irq_mask: mask of interrupt bits to enable 200edbfdb45SPaulo Zanoni */ 201edbfdb45SPaulo Zanoni static void snb_update_pm_irq(struct drm_i915_private *dev_priv, 202edbfdb45SPaulo Zanoni uint32_t interrupt_mask, 203edbfdb45SPaulo Zanoni uint32_t enabled_irq_mask) 204edbfdb45SPaulo Zanoni { 205605cd25bSPaulo Zanoni uint32_t new_val; 206edbfdb45SPaulo Zanoni 207edbfdb45SPaulo Zanoni assert_spin_locked(&dev_priv->irq_lock); 208edbfdb45SPaulo Zanoni 209730488b2SPaulo Zanoni if (WARN_ON(dev_priv->pm.irqs_disabled)) 210c67a470bSPaulo Zanoni return; 211c67a470bSPaulo Zanoni 212605cd25bSPaulo Zanoni new_val = dev_priv->pm_irq_mask; 213f52ecbcfSPaulo Zanoni new_val &= ~interrupt_mask; 214f52ecbcfSPaulo Zanoni new_val |= (~enabled_irq_mask & interrupt_mask); 215f52ecbcfSPaulo Zanoni 216605cd25bSPaulo Zanoni if (new_val != dev_priv->pm_irq_mask) { 217605cd25bSPaulo Zanoni dev_priv->pm_irq_mask = new_val; 218605cd25bSPaulo Zanoni I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask); 219edbfdb45SPaulo Zanoni POSTING_READ(GEN6_PMIMR); 220edbfdb45SPaulo Zanoni } 221f52ecbcfSPaulo Zanoni } 222edbfdb45SPaulo Zanoni 223edbfdb45SPaulo Zanoni void snb_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask) 224edbfdb45SPaulo Zanoni { 225edbfdb45SPaulo Zanoni snb_update_pm_irq(dev_priv, mask, mask); 226edbfdb45SPaulo Zanoni } 227edbfdb45SPaulo Zanoni 228edbfdb45SPaulo Zanoni void snb_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask) 229edbfdb45SPaulo Zanoni { 230edbfdb45SPaulo Zanoni snb_update_pm_irq(dev_priv, mask, 0); 231edbfdb45SPaulo Zanoni } 232edbfdb45SPaulo Zanoni 2338664281bSPaulo Zanoni static bool ivb_can_enable_err_int(struct drm_device *dev) 2348664281bSPaulo Zanoni { 2358664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 2368664281bSPaulo Zanoni struct intel_crtc *crtc; 2378664281bSPaulo Zanoni enum pipe pipe; 2388664281bSPaulo Zanoni 2394bc9d430SDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 2404bc9d430SDaniel Vetter 2418664281bSPaulo Zanoni for_each_pipe(pipe) { 2428664281bSPaulo Zanoni crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); 2438664281bSPaulo Zanoni 2448664281bSPaulo Zanoni if (crtc->cpu_fifo_underrun_disabled) 2458664281bSPaulo Zanoni return false; 2468664281bSPaulo Zanoni } 2478664281bSPaulo Zanoni 2488664281bSPaulo Zanoni return true; 2498664281bSPaulo Zanoni } 2508664281bSPaulo Zanoni 2518664281bSPaulo Zanoni static bool cpt_can_enable_serr_int(struct drm_device *dev) 2528664281bSPaulo Zanoni { 2538664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 2548664281bSPaulo Zanoni enum pipe pipe; 2558664281bSPaulo Zanoni struct intel_crtc *crtc; 2568664281bSPaulo Zanoni 257fee884edSDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 258fee884edSDaniel Vetter 2598664281bSPaulo Zanoni for_each_pipe(pipe) { 2608664281bSPaulo Zanoni crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); 2618664281bSPaulo Zanoni 2628664281bSPaulo Zanoni if (crtc->pch_fifo_underrun_disabled) 2638664281bSPaulo Zanoni return false; 2648664281bSPaulo Zanoni } 2658664281bSPaulo Zanoni 2668664281bSPaulo Zanoni return true; 2678664281bSPaulo Zanoni } 2688664281bSPaulo Zanoni 2692d9d2b0bSVille Syrjälä static void i9xx_clear_fifo_underrun(struct drm_device *dev, enum pipe pipe) 2702d9d2b0bSVille Syrjälä { 2712d9d2b0bSVille Syrjälä struct drm_i915_private *dev_priv = dev->dev_private; 2722d9d2b0bSVille Syrjälä u32 reg = PIPESTAT(pipe); 2732d9d2b0bSVille Syrjälä u32 pipestat = I915_READ(reg) & 0x7fff0000; 2742d9d2b0bSVille Syrjälä 2752d9d2b0bSVille Syrjälä assert_spin_locked(&dev_priv->irq_lock); 2762d9d2b0bSVille Syrjälä 2772d9d2b0bSVille Syrjälä I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS); 2782d9d2b0bSVille Syrjälä POSTING_READ(reg); 2792d9d2b0bSVille Syrjälä } 2802d9d2b0bSVille Syrjälä 2818664281bSPaulo Zanoni static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev, 2828664281bSPaulo Zanoni enum pipe pipe, bool enable) 2838664281bSPaulo Zanoni { 2848664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 2858664281bSPaulo Zanoni uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN : 2868664281bSPaulo Zanoni DE_PIPEB_FIFO_UNDERRUN; 2878664281bSPaulo Zanoni 2888664281bSPaulo Zanoni if (enable) 2898664281bSPaulo Zanoni ironlake_enable_display_irq(dev_priv, bit); 2908664281bSPaulo Zanoni else 2918664281bSPaulo Zanoni ironlake_disable_display_irq(dev_priv, bit); 2928664281bSPaulo Zanoni } 2938664281bSPaulo Zanoni 2948664281bSPaulo Zanoni static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev, 2957336df65SDaniel Vetter enum pipe pipe, bool enable) 2968664281bSPaulo Zanoni { 2978664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 2988664281bSPaulo Zanoni if (enable) { 2997336df65SDaniel Vetter I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe)); 3007336df65SDaniel Vetter 3018664281bSPaulo Zanoni if (!ivb_can_enable_err_int(dev)) 3028664281bSPaulo Zanoni return; 3038664281bSPaulo Zanoni 3048664281bSPaulo Zanoni ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB); 3058664281bSPaulo Zanoni } else { 3067336df65SDaniel Vetter bool was_enabled = !(I915_READ(DEIMR) & DE_ERR_INT_IVB); 3077336df65SDaniel Vetter 3087336df65SDaniel Vetter /* Change the state _after_ we've read out the current one. */ 3098664281bSPaulo Zanoni ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB); 3107336df65SDaniel Vetter 3117336df65SDaniel Vetter if (!was_enabled && 3127336df65SDaniel Vetter (I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe))) { 3137336df65SDaniel Vetter DRM_DEBUG_KMS("uncleared fifo underrun on pipe %c\n", 3147336df65SDaniel Vetter pipe_name(pipe)); 3157336df65SDaniel Vetter } 3168664281bSPaulo Zanoni } 3178664281bSPaulo Zanoni } 3188664281bSPaulo Zanoni 31938d83c96SDaniel Vetter static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev, 32038d83c96SDaniel Vetter enum pipe pipe, bool enable) 32138d83c96SDaniel Vetter { 32238d83c96SDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 32338d83c96SDaniel Vetter 32438d83c96SDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 32538d83c96SDaniel Vetter 32638d83c96SDaniel Vetter if (enable) 32738d83c96SDaniel Vetter dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_FIFO_UNDERRUN; 32838d83c96SDaniel Vetter else 32938d83c96SDaniel Vetter dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_FIFO_UNDERRUN; 33038d83c96SDaniel Vetter I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]); 33138d83c96SDaniel Vetter POSTING_READ(GEN8_DE_PIPE_IMR(pipe)); 33238d83c96SDaniel Vetter } 33338d83c96SDaniel Vetter 334fee884edSDaniel Vetter /** 335fee884edSDaniel Vetter * ibx_display_interrupt_update - update SDEIMR 336fee884edSDaniel Vetter * @dev_priv: driver private 337fee884edSDaniel Vetter * @interrupt_mask: mask of interrupt bits to update 338fee884edSDaniel Vetter * @enabled_irq_mask: mask of interrupt bits to enable 339fee884edSDaniel Vetter */ 340fee884edSDaniel Vetter static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv, 341fee884edSDaniel Vetter uint32_t interrupt_mask, 342fee884edSDaniel Vetter uint32_t enabled_irq_mask) 343fee884edSDaniel Vetter { 344fee884edSDaniel Vetter uint32_t sdeimr = I915_READ(SDEIMR); 345fee884edSDaniel Vetter sdeimr &= ~interrupt_mask; 346fee884edSDaniel Vetter sdeimr |= (~enabled_irq_mask & interrupt_mask); 347fee884edSDaniel Vetter 348fee884edSDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 349fee884edSDaniel Vetter 350730488b2SPaulo Zanoni if (WARN_ON(dev_priv->pm.irqs_disabled)) 351c67a470bSPaulo Zanoni return; 352c67a470bSPaulo Zanoni 353fee884edSDaniel Vetter I915_WRITE(SDEIMR, sdeimr); 354fee884edSDaniel Vetter POSTING_READ(SDEIMR); 355fee884edSDaniel Vetter } 356fee884edSDaniel Vetter #define ibx_enable_display_interrupt(dev_priv, bits) \ 357fee884edSDaniel Vetter ibx_display_interrupt_update((dev_priv), (bits), (bits)) 358fee884edSDaniel Vetter #define ibx_disable_display_interrupt(dev_priv, bits) \ 359fee884edSDaniel Vetter ibx_display_interrupt_update((dev_priv), (bits), 0) 360fee884edSDaniel Vetter 361de28075dSDaniel Vetter static void ibx_set_fifo_underrun_reporting(struct drm_device *dev, 362de28075dSDaniel Vetter enum transcoder pch_transcoder, 3638664281bSPaulo Zanoni bool enable) 3648664281bSPaulo Zanoni { 3658664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 366de28075dSDaniel Vetter uint32_t bit = (pch_transcoder == TRANSCODER_A) ? 367de28075dSDaniel Vetter SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER; 3688664281bSPaulo Zanoni 3698664281bSPaulo Zanoni if (enable) 370fee884edSDaniel Vetter ibx_enable_display_interrupt(dev_priv, bit); 3718664281bSPaulo Zanoni else 372fee884edSDaniel Vetter ibx_disable_display_interrupt(dev_priv, bit); 3738664281bSPaulo Zanoni } 3748664281bSPaulo Zanoni 3758664281bSPaulo Zanoni static void cpt_set_fifo_underrun_reporting(struct drm_device *dev, 3768664281bSPaulo Zanoni enum transcoder pch_transcoder, 3778664281bSPaulo Zanoni bool enable) 3788664281bSPaulo Zanoni { 3798664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 3808664281bSPaulo Zanoni 3818664281bSPaulo Zanoni if (enable) { 3821dd246fbSDaniel Vetter I915_WRITE(SERR_INT, 3831dd246fbSDaniel Vetter SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)); 3841dd246fbSDaniel Vetter 3858664281bSPaulo Zanoni if (!cpt_can_enable_serr_int(dev)) 3868664281bSPaulo Zanoni return; 3878664281bSPaulo Zanoni 388fee884edSDaniel Vetter ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT); 3898664281bSPaulo Zanoni } else { 3901dd246fbSDaniel Vetter uint32_t tmp = I915_READ(SERR_INT); 3911dd246fbSDaniel Vetter bool was_enabled = !(I915_READ(SDEIMR) & SDE_ERROR_CPT); 3921dd246fbSDaniel Vetter 3931dd246fbSDaniel Vetter /* Change the state _after_ we've read out the current one. */ 394fee884edSDaniel Vetter ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT); 3951dd246fbSDaniel Vetter 3961dd246fbSDaniel Vetter if (!was_enabled && 3971dd246fbSDaniel Vetter (tmp & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder))) { 3981dd246fbSDaniel Vetter DRM_DEBUG_KMS("uncleared pch fifo underrun on pch transcoder %c\n", 3991dd246fbSDaniel Vetter transcoder_name(pch_transcoder)); 4001dd246fbSDaniel Vetter } 4018664281bSPaulo Zanoni } 4028664281bSPaulo Zanoni } 4038664281bSPaulo Zanoni 4048664281bSPaulo Zanoni /** 4058664281bSPaulo Zanoni * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages 4068664281bSPaulo Zanoni * @dev: drm device 4078664281bSPaulo Zanoni * @pipe: pipe 4088664281bSPaulo Zanoni * @enable: true if we want to report FIFO underrun errors, false otherwise 4098664281bSPaulo Zanoni * 4108664281bSPaulo Zanoni * This function makes us disable or enable CPU fifo underruns for a specific 4118664281bSPaulo Zanoni * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun 4128664281bSPaulo Zanoni * reporting for one pipe may also disable all the other CPU error interruts for 4138664281bSPaulo Zanoni * the other pipes, due to the fact that there's just one interrupt mask/enable 4148664281bSPaulo Zanoni * bit for all the pipes. 4158664281bSPaulo Zanoni * 4168664281bSPaulo Zanoni * Returns the previous state of underrun reporting. 4178664281bSPaulo Zanoni */ 418f88d42f1SImre Deak bool __intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev, 4198664281bSPaulo Zanoni enum pipe pipe, bool enable) 4208664281bSPaulo Zanoni { 4218664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 4228664281bSPaulo Zanoni struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 4238664281bSPaulo Zanoni struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 4248664281bSPaulo Zanoni bool ret; 4258664281bSPaulo Zanoni 42677961eb9SImre Deak assert_spin_locked(&dev_priv->irq_lock); 42777961eb9SImre Deak 4288664281bSPaulo Zanoni ret = !intel_crtc->cpu_fifo_underrun_disabled; 4298664281bSPaulo Zanoni 4308664281bSPaulo Zanoni if (enable == ret) 4318664281bSPaulo Zanoni goto done; 4328664281bSPaulo Zanoni 4338664281bSPaulo Zanoni intel_crtc->cpu_fifo_underrun_disabled = !enable; 4348664281bSPaulo Zanoni 4352d9d2b0bSVille Syrjälä if (enable && (INTEL_INFO(dev)->gen < 5 || IS_VALLEYVIEW(dev))) 4362d9d2b0bSVille Syrjälä i9xx_clear_fifo_underrun(dev, pipe); 4372d9d2b0bSVille Syrjälä else if (IS_GEN5(dev) || IS_GEN6(dev)) 4388664281bSPaulo Zanoni ironlake_set_fifo_underrun_reporting(dev, pipe, enable); 4398664281bSPaulo Zanoni else if (IS_GEN7(dev)) 4407336df65SDaniel Vetter ivybridge_set_fifo_underrun_reporting(dev, pipe, enable); 44138d83c96SDaniel Vetter else if (IS_GEN8(dev)) 44238d83c96SDaniel Vetter broadwell_set_fifo_underrun_reporting(dev, pipe, enable); 4438664281bSPaulo Zanoni 4448664281bSPaulo Zanoni done: 445f88d42f1SImre Deak return ret; 446f88d42f1SImre Deak } 447f88d42f1SImre Deak 448f88d42f1SImre Deak bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev, 449f88d42f1SImre Deak enum pipe pipe, bool enable) 450f88d42f1SImre Deak { 451f88d42f1SImre Deak struct drm_i915_private *dev_priv = dev->dev_private; 452f88d42f1SImre Deak unsigned long flags; 453f88d42f1SImre Deak bool ret; 454f88d42f1SImre Deak 455f88d42f1SImre Deak spin_lock_irqsave(&dev_priv->irq_lock, flags); 456f88d42f1SImre Deak ret = __intel_set_cpu_fifo_underrun_reporting(dev, pipe, enable); 4578664281bSPaulo Zanoni spin_unlock_irqrestore(&dev_priv->irq_lock, flags); 458f88d42f1SImre Deak 4598664281bSPaulo Zanoni return ret; 4608664281bSPaulo Zanoni } 4618664281bSPaulo Zanoni 46291d181ddSImre Deak static bool __cpu_fifo_underrun_reporting_enabled(struct drm_device *dev, 46391d181ddSImre Deak enum pipe pipe) 46491d181ddSImre Deak { 46591d181ddSImre Deak struct drm_i915_private *dev_priv = dev->dev_private; 46691d181ddSImre Deak struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 46791d181ddSImre Deak struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 46891d181ddSImre Deak 46991d181ddSImre Deak return !intel_crtc->cpu_fifo_underrun_disabled; 47091d181ddSImre Deak } 47191d181ddSImre Deak 4728664281bSPaulo Zanoni /** 4738664281bSPaulo Zanoni * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages 4748664281bSPaulo Zanoni * @dev: drm device 4758664281bSPaulo Zanoni * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older) 4768664281bSPaulo Zanoni * @enable: true if we want to report FIFO underrun errors, false otherwise 4778664281bSPaulo Zanoni * 4788664281bSPaulo Zanoni * This function makes us disable or enable PCH fifo underruns for a specific 4798664281bSPaulo Zanoni * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO 4808664281bSPaulo Zanoni * underrun reporting for one transcoder may also disable all the other PCH 4818664281bSPaulo Zanoni * error interruts for the other transcoders, due to the fact that there's just 4828664281bSPaulo Zanoni * one interrupt mask/enable bit for all the transcoders. 4838664281bSPaulo Zanoni * 4848664281bSPaulo Zanoni * Returns the previous state of underrun reporting. 4858664281bSPaulo Zanoni */ 4868664281bSPaulo Zanoni bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev, 4878664281bSPaulo Zanoni enum transcoder pch_transcoder, 4888664281bSPaulo Zanoni bool enable) 4898664281bSPaulo Zanoni { 4908664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 491de28075dSDaniel Vetter struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder]; 492de28075dSDaniel Vetter struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 4938664281bSPaulo Zanoni unsigned long flags; 4948664281bSPaulo Zanoni bool ret; 4958664281bSPaulo Zanoni 496de28075dSDaniel Vetter /* 497de28075dSDaniel Vetter * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT 498de28075dSDaniel Vetter * has only one pch transcoder A that all pipes can use. To avoid racy 499de28075dSDaniel Vetter * pch transcoder -> pipe lookups from interrupt code simply store the 500de28075dSDaniel Vetter * underrun statistics in crtc A. Since we never expose this anywhere 501de28075dSDaniel Vetter * nor use it outside of the fifo underrun code here using the "wrong" 502de28075dSDaniel Vetter * crtc on LPT won't cause issues. 503de28075dSDaniel Vetter */ 5048664281bSPaulo Zanoni 5058664281bSPaulo Zanoni spin_lock_irqsave(&dev_priv->irq_lock, flags); 5068664281bSPaulo Zanoni 5078664281bSPaulo Zanoni ret = !intel_crtc->pch_fifo_underrun_disabled; 5088664281bSPaulo Zanoni 5098664281bSPaulo Zanoni if (enable == ret) 5108664281bSPaulo Zanoni goto done; 5118664281bSPaulo Zanoni 5128664281bSPaulo Zanoni intel_crtc->pch_fifo_underrun_disabled = !enable; 5138664281bSPaulo Zanoni 5148664281bSPaulo Zanoni if (HAS_PCH_IBX(dev)) 515de28075dSDaniel Vetter ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable); 5168664281bSPaulo Zanoni else 5178664281bSPaulo Zanoni cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable); 5188664281bSPaulo Zanoni 5198664281bSPaulo Zanoni done: 5208664281bSPaulo Zanoni spin_unlock_irqrestore(&dev_priv->irq_lock, flags); 5218664281bSPaulo Zanoni return ret; 5228664281bSPaulo Zanoni } 5238664281bSPaulo Zanoni 5248664281bSPaulo Zanoni 525b5ea642aSDaniel Vetter static void 526755e9019SImre Deak __i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 527755e9019SImre Deak u32 enable_mask, u32 status_mask) 5287c463586SKeith Packard { 5299db4a9c7SJesse Barnes u32 reg = PIPESTAT(pipe); 530755e9019SImre Deak u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK; 5317c463586SKeith Packard 532b79480baSDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 533b79480baSDaniel Vetter 534*04feced9SVille Syrjälä if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK || 535*04feced9SVille Syrjälä status_mask & ~PIPESTAT_INT_STATUS_MASK, 536*04feced9SVille Syrjälä "pipe %c: enable_mask=0x%x, status_mask=0x%x\n", 537*04feced9SVille Syrjälä pipe_name(pipe), enable_mask, status_mask)) 538755e9019SImre Deak return; 539755e9019SImre Deak 540755e9019SImre Deak if ((pipestat & enable_mask) == enable_mask) 54146c06a30SVille Syrjälä return; 54246c06a30SVille Syrjälä 54391d181ddSImre Deak dev_priv->pipestat_irq_mask[pipe] |= status_mask; 54491d181ddSImre Deak 5457c463586SKeith Packard /* Enable the interrupt, clear any pending status */ 546755e9019SImre Deak pipestat |= enable_mask | status_mask; 54746c06a30SVille Syrjälä I915_WRITE(reg, pipestat); 5483143a2bfSChris Wilson POSTING_READ(reg); 5497c463586SKeith Packard } 5507c463586SKeith Packard 551b5ea642aSDaniel Vetter static void 552755e9019SImre Deak __i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 553755e9019SImre Deak u32 enable_mask, u32 status_mask) 5547c463586SKeith Packard { 5559db4a9c7SJesse Barnes u32 reg = PIPESTAT(pipe); 556755e9019SImre Deak u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK; 5577c463586SKeith Packard 558b79480baSDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 559b79480baSDaniel Vetter 560*04feced9SVille Syrjälä if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK || 561*04feced9SVille Syrjälä status_mask & ~PIPESTAT_INT_STATUS_MASK, 562*04feced9SVille Syrjälä "pipe %c: enable_mask=0x%x, status_mask=0x%x\n", 563*04feced9SVille Syrjälä pipe_name(pipe), enable_mask, status_mask)) 56446c06a30SVille Syrjälä return; 56546c06a30SVille Syrjälä 566755e9019SImre Deak if ((pipestat & enable_mask) == 0) 567755e9019SImre Deak return; 568755e9019SImre Deak 56991d181ddSImre Deak dev_priv->pipestat_irq_mask[pipe] &= ~status_mask; 57091d181ddSImre Deak 571755e9019SImre Deak pipestat &= ~enable_mask; 57246c06a30SVille Syrjälä I915_WRITE(reg, pipestat); 5733143a2bfSChris Wilson POSTING_READ(reg); 5747c463586SKeith Packard } 5757c463586SKeith Packard 57610c59c51SImre Deak static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask) 57710c59c51SImre Deak { 57810c59c51SImre Deak u32 enable_mask = status_mask << 16; 57910c59c51SImre Deak 58010c59c51SImre Deak /* 58110c59c51SImre Deak * On pipe A we don't support the PSR interrupt yet, on pipe B the 58210c59c51SImre Deak * same bit MBZ. 58310c59c51SImre Deak */ 58410c59c51SImre Deak if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV)) 58510c59c51SImre Deak return 0; 58610c59c51SImre Deak 58710c59c51SImre Deak enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS | 58810c59c51SImre Deak SPRITE0_FLIP_DONE_INT_EN_VLV | 58910c59c51SImre Deak SPRITE1_FLIP_DONE_INT_EN_VLV); 59010c59c51SImre Deak if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV) 59110c59c51SImre Deak enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV; 59210c59c51SImre Deak if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV) 59310c59c51SImre Deak enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV; 59410c59c51SImre Deak 59510c59c51SImre Deak return enable_mask; 59610c59c51SImre Deak } 59710c59c51SImre Deak 598755e9019SImre Deak void 599755e9019SImre Deak i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 600755e9019SImre Deak u32 status_mask) 601755e9019SImre Deak { 602755e9019SImre Deak u32 enable_mask; 603755e9019SImre Deak 60410c59c51SImre Deak if (IS_VALLEYVIEW(dev_priv->dev)) 60510c59c51SImre Deak enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev, 60610c59c51SImre Deak status_mask); 60710c59c51SImre Deak else 608755e9019SImre Deak enable_mask = status_mask << 16; 609755e9019SImre Deak __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask); 610755e9019SImre Deak } 611755e9019SImre Deak 612755e9019SImre Deak void 613755e9019SImre Deak i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 614755e9019SImre Deak u32 status_mask) 615755e9019SImre Deak { 616755e9019SImre Deak u32 enable_mask; 617755e9019SImre Deak 61810c59c51SImre Deak if (IS_VALLEYVIEW(dev_priv->dev)) 61910c59c51SImre Deak enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev, 62010c59c51SImre Deak status_mask); 62110c59c51SImre Deak else 622755e9019SImre Deak enable_mask = status_mask << 16; 623755e9019SImre Deak __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask); 624755e9019SImre Deak } 625755e9019SImre Deak 626c0e09200SDave Airlie /** 627f49e38ddSJani Nikula * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion 62801c66889SZhao Yakui */ 629f49e38ddSJani Nikula static void i915_enable_asle_pipestat(struct drm_device *dev) 63001c66889SZhao Yakui { 6312d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 6321ec14ad3SChris Wilson unsigned long irqflags; 6331ec14ad3SChris Wilson 634f49e38ddSJani Nikula if (!dev_priv->opregion.asle || !IS_MOBILE(dev)) 635f49e38ddSJani Nikula return; 636f49e38ddSJani Nikula 6371ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 63801c66889SZhao Yakui 639755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS); 640a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen >= 4) 6413b6c42e8SDaniel Vetter i915_enable_pipestat(dev_priv, PIPE_A, 642755e9019SImre Deak PIPE_LEGACY_BLC_EVENT_STATUS); 6431ec14ad3SChris Wilson 6441ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 64501c66889SZhao Yakui } 64601c66889SZhao Yakui 64701c66889SZhao Yakui /** 6480a3e67a4SJesse Barnes * i915_pipe_enabled - check if a pipe is enabled 6490a3e67a4SJesse Barnes * @dev: DRM device 6500a3e67a4SJesse Barnes * @pipe: pipe to check 6510a3e67a4SJesse Barnes * 6520a3e67a4SJesse Barnes * Reading certain registers when the pipe is disabled can hang the chip. 6530a3e67a4SJesse Barnes * Use this routine to make sure the PLL is running and the pipe is active 6540a3e67a4SJesse Barnes * before reading such registers if unsure. 6550a3e67a4SJesse Barnes */ 6560a3e67a4SJesse Barnes static int 6570a3e67a4SJesse Barnes i915_pipe_enabled(struct drm_device *dev, int pipe) 6580a3e67a4SJesse Barnes { 6592d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 660702e7a56SPaulo Zanoni 661a01025afSDaniel Vetter if (drm_core_check_feature(dev, DRIVER_MODESET)) { 662a01025afSDaniel Vetter /* Locking is horribly broken here, but whatever. */ 663a01025afSDaniel Vetter struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 664a01025afSDaniel Vetter struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 66571f8ba6bSPaulo Zanoni 666a01025afSDaniel Vetter return intel_crtc->active; 667a01025afSDaniel Vetter } else { 668a01025afSDaniel Vetter return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE; 669a01025afSDaniel Vetter } 6700a3e67a4SJesse Barnes } 6710a3e67a4SJesse Barnes 6724cdb83ecSVille Syrjälä static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe) 6734cdb83ecSVille Syrjälä { 6744cdb83ecSVille Syrjälä /* Gen2 doesn't have a hardware frame counter */ 6754cdb83ecSVille Syrjälä return 0; 6764cdb83ecSVille Syrjälä } 6774cdb83ecSVille Syrjälä 67842f52ef8SKeith Packard /* Called from drm generic code, passed a 'crtc', which 67942f52ef8SKeith Packard * we use as a pipe index 68042f52ef8SKeith Packard */ 681f71d4af4SJesse Barnes static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe) 6820a3e67a4SJesse Barnes { 6832d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 6840a3e67a4SJesse Barnes unsigned long high_frame; 6850a3e67a4SJesse Barnes unsigned long low_frame; 686391f75e2SVille Syrjälä u32 high1, high2, low, pixel, vbl_start; 6870a3e67a4SJesse Barnes 6880a3e67a4SJesse Barnes if (!i915_pipe_enabled(dev, pipe)) { 68944d98a61SZhao Yakui DRM_DEBUG_DRIVER("trying to get vblank count for disabled " 6909db4a9c7SJesse Barnes "pipe %c\n", pipe_name(pipe)); 6910a3e67a4SJesse Barnes return 0; 6920a3e67a4SJesse Barnes } 6930a3e67a4SJesse Barnes 694391f75e2SVille Syrjälä if (drm_core_check_feature(dev, DRIVER_MODESET)) { 695391f75e2SVille Syrjälä struct intel_crtc *intel_crtc = 696391f75e2SVille Syrjälä to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); 697391f75e2SVille Syrjälä const struct drm_display_mode *mode = 698391f75e2SVille Syrjälä &intel_crtc->config.adjusted_mode; 699391f75e2SVille Syrjälä 700391f75e2SVille Syrjälä vbl_start = mode->crtc_vblank_start * mode->crtc_htotal; 701391f75e2SVille Syrjälä } else { 702a2d213ddSDaniel Vetter enum transcoder cpu_transcoder = (enum transcoder) pipe; 703391f75e2SVille Syrjälä u32 htotal; 704391f75e2SVille Syrjälä 705391f75e2SVille Syrjälä htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1; 706391f75e2SVille Syrjälä vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1; 707391f75e2SVille Syrjälä 708391f75e2SVille Syrjälä vbl_start *= htotal; 709391f75e2SVille Syrjälä } 710391f75e2SVille Syrjälä 7119db4a9c7SJesse Barnes high_frame = PIPEFRAME(pipe); 7129db4a9c7SJesse Barnes low_frame = PIPEFRAMEPIXEL(pipe); 7135eddb70bSChris Wilson 7140a3e67a4SJesse Barnes /* 7150a3e67a4SJesse Barnes * High & low register fields aren't synchronized, so make sure 7160a3e67a4SJesse Barnes * we get a low value that's stable across two reads of the high 7170a3e67a4SJesse Barnes * register. 7180a3e67a4SJesse Barnes */ 7190a3e67a4SJesse Barnes do { 7205eddb70bSChris Wilson high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; 721391f75e2SVille Syrjälä low = I915_READ(low_frame); 7225eddb70bSChris Wilson high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; 7230a3e67a4SJesse Barnes } while (high1 != high2); 7240a3e67a4SJesse Barnes 7255eddb70bSChris Wilson high1 >>= PIPE_FRAME_HIGH_SHIFT; 726391f75e2SVille Syrjälä pixel = low & PIPE_PIXEL_MASK; 7275eddb70bSChris Wilson low >>= PIPE_FRAME_LOW_SHIFT; 728391f75e2SVille Syrjälä 729391f75e2SVille Syrjälä /* 730391f75e2SVille Syrjälä * The frame counter increments at beginning of active. 731391f75e2SVille Syrjälä * Cook up a vblank counter by also checking the pixel 732391f75e2SVille Syrjälä * counter against vblank start. 733391f75e2SVille Syrjälä */ 734edc08d0aSVille Syrjälä return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff; 7350a3e67a4SJesse Barnes } 7360a3e67a4SJesse Barnes 737f71d4af4SJesse Barnes static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe) 7389880b7a5SJesse Barnes { 7392d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 7409db4a9c7SJesse Barnes int reg = PIPE_FRMCOUNT_GM45(pipe); 7419880b7a5SJesse Barnes 7429880b7a5SJesse Barnes if (!i915_pipe_enabled(dev, pipe)) { 74344d98a61SZhao Yakui DRM_DEBUG_DRIVER("trying to get vblank count for disabled " 7449db4a9c7SJesse Barnes "pipe %c\n", pipe_name(pipe)); 7459880b7a5SJesse Barnes return 0; 7469880b7a5SJesse Barnes } 7479880b7a5SJesse Barnes 7489880b7a5SJesse Barnes return I915_READ(reg); 7499880b7a5SJesse Barnes } 7509880b7a5SJesse Barnes 751ad3543edSMario Kleiner /* raw reads, only for fast reads of display block, no need for forcewake etc. */ 752ad3543edSMario Kleiner #define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__)) 753ad3543edSMario Kleiner 754095163baSVille Syrjälä static bool ilk_pipe_in_vblank_locked(struct drm_device *dev, enum pipe pipe) 75554ddcbd2SVille Syrjälä { 75654ddcbd2SVille Syrjälä struct drm_i915_private *dev_priv = dev->dev_private; 75754ddcbd2SVille Syrjälä uint32_t status; 75824302624SVille Syrjälä int reg; 75954ddcbd2SVille Syrjälä 76024302624SVille Syrjälä if (INTEL_INFO(dev)->gen >= 8) { 76124302624SVille Syrjälä status = GEN8_PIPE_VBLANK; 76224302624SVille Syrjälä reg = GEN8_DE_PIPE_ISR(pipe); 76324302624SVille Syrjälä } else if (INTEL_INFO(dev)->gen >= 7) { 76424302624SVille Syrjälä status = DE_PIPE_VBLANK_IVB(pipe); 76524302624SVille Syrjälä reg = DEISR; 76654ddcbd2SVille Syrjälä } else { 76724302624SVille Syrjälä status = DE_PIPE_VBLANK(pipe); 76824302624SVille Syrjälä reg = DEISR; 76954ddcbd2SVille Syrjälä } 770ad3543edSMario Kleiner 77124302624SVille Syrjälä return __raw_i915_read32(dev_priv, reg) & status; 77254ddcbd2SVille Syrjälä } 77354ddcbd2SVille Syrjälä 774f71d4af4SJesse Barnes static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe, 775abca9e45SVille Syrjälä unsigned int flags, int *vpos, int *hpos, 776abca9e45SVille Syrjälä ktime_t *stime, ktime_t *etime) 7770af7e4dfSMario Kleiner { 778c2baf4b7SVille Syrjälä struct drm_i915_private *dev_priv = dev->dev_private; 779c2baf4b7SVille Syrjälä struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 780c2baf4b7SVille Syrjälä struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 781c2baf4b7SVille Syrjälä const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode; 7823aa18df8SVille Syrjälä int position; 7830af7e4dfSMario Kleiner int vbl_start, vbl_end, htotal, vtotal; 7840af7e4dfSMario Kleiner bool in_vbl = true; 7850af7e4dfSMario Kleiner int ret = 0; 786ad3543edSMario Kleiner unsigned long irqflags; 7870af7e4dfSMario Kleiner 788c2baf4b7SVille Syrjälä if (!intel_crtc->active) { 7890af7e4dfSMario Kleiner DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled " 7909db4a9c7SJesse Barnes "pipe %c\n", pipe_name(pipe)); 7910af7e4dfSMario Kleiner return 0; 7920af7e4dfSMario Kleiner } 7930af7e4dfSMario Kleiner 794c2baf4b7SVille Syrjälä htotal = mode->crtc_htotal; 795c2baf4b7SVille Syrjälä vtotal = mode->crtc_vtotal; 796c2baf4b7SVille Syrjälä vbl_start = mode->crtc_vblank_start; 797c2baf4b7SVille Syrjälä vbl_end = mode->crtc_vblank_end; 7980af7e4dfSMario Kleiner 799d31faf65SVille Syrjälä if (mode->flags & DRM_MODE_FLAG_INTERLACE) { 800d31faf65SVille Syrjälä vbl_start = DIV_ROUND_UP(vbl_start, 2); 801d31faf65SVille Syrjälä vbl_end /= 2; 802d31faf65SVille Syrjälä vtotal /= 2; 803d31faf65SVille Syrjälä } 804d31faf65SVille Syrjälä 805c2baf4b7SVille Syrjälä ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE; 806c2baf4b7SVille Syrjälä 807ad3543edSMario Kleiner /* 808ad3543edSMario Kleiner * Lock uncore.lock, as we will do multiple timing critical raw 809ad3543edSMario Kleiner * register reads, potentially with preemption disabled, so the 810ad3543edSMario Kleiner * following code must not block on uncore.lock. 811ad3543edSMario Kleiner */ 812ad3543edSMario Kleiner spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); 813ad3543edSMario Kleiner 814ad3543edSMario Kleiner /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */ 815ad3543edSMario Kleiner 816ad3543edSMario Kleiner /* Get optional system timestamp before query. */ 817ad3543edSMario Kleiner if (stime) 818ad3543edSMario Kleiner *stime = ktime_get(); 819ad3543edSMario Kleiner 8207c06b08aSVille Syrjälä if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { 8210af7e4dfSMario Kleiner /* No obvious pixelcount register. Only query vertical 8220af7e4dfSMario Kleiner * scanout position from Display scan line register. 8230af7e4dfSMario Kleiner */ 8247c06b08aSVille Syrjälä if (IS_GEN2(dev)) 825ad3543edSMario Kleiner position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2; 8267c06b08aSVille Syrjälä else 827ad3543edSMario Kleiner position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3; 82854ddcbd2SVille Syrjälä 829fcb81823SVille Syrjälä if (HAS_DDI(dev)) { 830fcb81823SVille Syrjälä /* 831fcb81823SVille Syrjälä * On HSW HDMI outputs there seems to be a 2 line 832fcb81823SVille Syrjälä * difference, whereas eDP has the normal 1 line 833fcb81823SVille Syrjälä * difference that earlier platforms have. External 834fcb81823SVille Syrjälä * DP is unknown. For now just check for the 2 line 835fcb81823SVille Syrjälä * difference case on all output types on HSW+. 836fcb81823SVille Syrjälä * 837fcb81823SVille Syrjälä * This might misinterpret the scanline counter being 838fcb81823SVille Syrjälä * one line too far along on eDP, but that's less 839fcb81823SVille Syrjälä * dangerous than the alternative since that would lead 840fcb81823SVille Syrjälä * the vblank timestamp code astray when it sees a 841fcb81823SVille Syrjälä * scanline count before vblank_start during a vblank 842fcb81823SVille Syrjälä * interrupt. 843fcb81823SVille Syrjälä */ 844fcb81823SVille Syrjälä in_vbl = ilk_pipe_in_vblank_locked(dev, pipe); 845fcb81823SVille Syrjälä if ((in_vbl && (position == vbl_start - 2 || 846fcb81823SVille Syrjälä position == vbl_start - 1)) || 847fcb81823SVille Syrjälä (!in_vbl && (position == vbl_end - 2 || 848fcb81823SVille Syrjälä position == vbl_end - 1))) 849fcb81823SVille Syrjälä position = (position + 2) % vtotal; 850fcb81823SVille Syrjälä } else if (HAS_PCH_SPLIT(dev)) { 85154ddcbd2SVille Syrjälä /* 85254ddcbd2SVille Syrjälä * The scanline counter increments at the leading edge 85354ddcbd2SVille Syrjälä * of hsync, ie. it completely misses the active portion 85454ddcbd2SVille Syrjälä * of the line. Fix up the counter at both edges of vblank 85554ddcbd2SVille Syrjälä * to get a more accurate picture whether we're in vblank 85654ddcbd2SVille Syrjälä * or not. 85754ddcbd2SVille Syrjälä */ 858095163baSVille Syrjälä in_vbl = ilk_pipe_in_vblank_locked(dev, pipe); 85954ddcbd2SVille Syrjälä if ((in_vbl && position == vbl_start - 1) || 86054ddcbd2SVille Syrjälä (!in_vbl && position == vbl_end - 1)) 86154ddcbd2SVille Syrjälä position = (position + 1) % vtotal; 8620af7e4dfSMario Kleiner } else { 863095163baSVille Syrjälä /* 864095163baSVille Syrjälä * ISR vblank status bits don't work the way we'd want 865095163baSVille Syrjälä * them to work on non-PCH platforms (for 866095163baSVille Syrjälä * ilk_pipe_in_vblank_locked()), and there doesn't 867095163baSVille Syrjälä * appear any other way to determine if we're currently 868095163baSVille Syrjälä * in vblank. 869095163baSVille Syrjälä * 870095163baSVille Syrjälä * Instead let's assume that we're already in vblank if 871095163baSVille Syrjälä * we got called from the vblank interrupt and the 872095163baSVille Syrjälä * scanline counter value indicates that we're on the 873095163baSVille Syrjälä * line just prior to vblank start. This should result 874095163baSVille Syrjälä * in the correct answer, unless the vblank interrupt 875095163baSVille Syrjälä * delivery really got delayed for almost exactly one 876095163baSVille Syrjälä * full frame/field. 877095163baSVille Syrjälä */ 878095163baSVille Syrjälä if (flags & DRM_CALLED_FROM_VBLIRQ && 879095163baSVille Syrjälä position == vbl_start - 1) { 880095163baSVille Syrjälä position = (position + 1) % vtotal; 881095163baSVille Syrjälä 882095163baSVille Syrjälä /* Signal this correction as "applied". */ 883095163baSVille Syrjälä ret |= 0x8; 884095163baSVille Syrjälä } 885095163baSVille Syrjälä } 886095163baSVille Syrjälä } else { 8870af7e4dfSMario Kleiner /* Have access to pixelcount since start of frame. 8880af7e4dfSMario Kleiner * We can split this into vertical and horizontal 8890af7e4dfSMario Kleiner * scanout position. 8900af7e4dfSMario Kleiner */ 891ad3543edSMario Kleiner position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT; 8920af7e4dfSMario Kleiner 8933aa18df8SVille Syrjälä /* convert to pixel counts */ 8943aa18df8SVille Syrjälä vbl_start *= htotal; 8953aa18df8SVille Syrjälä vbl_end *= htotal; 8963aa18df8SVille Syrjälä vtotal *= htotal; 8973aa18df8SVille Syrjälä } 8983aa18df8SVille Syrjälä 899ad3543edSMario Kleiner /* Get optional system timestamp after query. */ 900ad3543edSMario Kleiner if (etime) 901ad3543edSMario Kleiner *etime = ktime_get(); 902ad3543edSMario Kleiner 903ad3543edSMario Kleiner /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */ 904ad3543edSMario Kleiner 905ad3543edSMario Kleiner spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); 906ad3543edSMario Kleiner 9073aa18df8SVille Syrjälä in_vbl = position >= vbl_start && position < vbl_end; 9083aa18df8SVille Syrjälä 9093aa18df8SVille Syrjälä /* 9103aa18df8SVille Syrjälä * While in vblank, position will be negative 9113aa18df8SVille Syrjälä * counting up towards 0 at vbl_end. And outside 9123aa18df8SVille Syrjälä * vblank, position will be positive counting 9133aa18df8SVille Syrjälä * up since vbl_end. 9143aa18df8SVille Syrjälä */ 9153aa18df8SVille Syrjälä if (position >= vbl_start) 9163aa18df8SVille Syrjälä position -= vbl_end; 9173aa18df8SVille Syrjälä else 9183aa18df8SVille Syrjälä position += vtotal - vbl_end; 9193aa18df8SVille Syrjälä 9207c06b08aSVille Syrjälä if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { 9213aa18df8SVille Syrjälä *vpos = position; 9223aa18df8SVille Syrjälä *hpos = 0; 9233aa18df8SVille Syrjälä } else { 9240af7e4dfSMario Kleiner *vpos = position / htotal; 9250af7e4dfSMario Kleiner *hpos = position - (*vpos * htotal); 9260af7e4dfSMario Kleiner } 9270af7e4dfSMario Kleiner 9280af7e4dfSMario Kleiner /* In vblank? */ 9290af7e4dfSMario Kleiner if (in_vbl) 9300af7e4dfSMario Kleiner ret |= DRM_SCANOUTPOS_INVBL; 9310af7e4dfSMario Kleiner 9320af7e4dfSMario Kleiner return ret; 9330af7e4dfSMario Kleiner } 9340af7e4dfSMario Kleiner 935f71d4af4SJesse Barnes static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe, 9360af7e4dfSMario Kleiner int *max_error, 9370af7e4dfSMario Kleiner struct timeval *vblank_time, 9380af7e4dfSMario Kleiner unsigned flags) 9390af7e4dfSMario Kleiner { 9404041b853SChris Wilson struct drm_crtc *crtc; 9410af7e4dfSMario Kleiner 9427eb552aeSBen Widawsky if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) { 9434041b853SChris Wilson DRM_ERROR("Invalid crtc %d\n", pipe); 9440af7e4dfSMario Kleiner return -EINVAL; 9450af7e4dfSMario Kleiner } 9460af7e4dfSMario Kleiner 9470af7e4dfSMario Kleiner /* Get drm_crtc to timestamp: */ 9484041b853SChris Wilson crtc = intel_get_crtc_for_pipe(dev, pipe); 9494041b853SChris Wilson if (crtc == NULL) { 9504041b853SChris Wilson DRM_ERROR("Invalid crtc %d\n", pipe); 9514041b853SChris Wilson return -EINVAL; 9524041b853SChris Wilson } 9534041b853SChris Wilson 9544041b853SChris Wilson if (!crtc->enabled) { 9554041b853SChris Wilson DRM_DEBUG_KMS("crtc %d is disabled\n", pipe); 9564041b853SChris Wilson return -EBUSY; 9574041b853SChris Wilson } 9580af7e4dfSMario Kleiner 9590af7e4dfSMario Kleiner /* Helper routine in DRM core does all the work: */ 9604041b853SChris Wilson return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error, 9614041b853SChris Wilson vblank_time, flags, 9627da903efSVille Syrjälä crtc, 9637da903efSVille Syrjälä &to_intel_crtc(crtc)->config.adjusted_mode); 9640af7e4dfSMario Kleiner } 9650af7e4dfSMario Kleiner 96667c347ffSJani Nikula static bool intel_hpd_irq_event(struct drm_device *dev, 96767c347ffSJani Nikula struct drm_connector *connector) 968321a1b30SEgbert Eich { 969321a1b30SEgbert Eich enum drm_connector_status old_status; 970321a1b30SEgbert Eich 971321a1b30SEgbert Eich WARN_ON(!mutex_is_locked(&dev->mode_config.mutex)); 972321a1b30SEgbert Eich old_status = connector->status; 973321a1b30SEgbert Eich 974321a1b30SEgbert Eich connector->status = connector->funcs->detect(connector, false); 97567c347ffSJani Nikula if (old_status == connector->status) 97667c347ffSJani Nikula return false; 97767c347ffSJani Nikula 97867c347ffSJani Nikula DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n", 979321a1b30SEgbert Eich connector->base.id, 980321a1b30SEgbert Eich drm_get_connector_name(connector), 98167c347ffSJani Nikula drm_get_connector_status_name(old_status), 98267c347ffSJani Nikula drm_get_connector_status_name(connector->status)); 98367c347ffSJani Nikula 98467c347ffSJani Nikula return true; 985321a1b30SEgbert Eich } 986321a1b30SEgbert Eich 9875ca58282SJesse Barnes /* 9885ca58282SJesse Barnes * Handle hotplug events outside the interrupt handler proper. 9895ca58282SJesse Barnes */ 990ac4c16c5SEgbert Eich #define I915_REENABLE_HOTPLUG_DELAY (2*60*1000) 991ac4c16c5SEgbert Eich 9925ca58282SJesse Barnes static void i915_hotplug_work_func(struct work_struct *work) 9935ca58282SJesse Barnes { 9942d1013ddSJani Nikula struct drm_i915_private *dev_priv = 9952d1013ddSJani Nikula container_of(work, struct drm_i915_private, hotplug_work); 9965ca58282SJesse Barnes struct drm_device *dev = dev_priv->dev; 997c31c4ba3SKeith Packard struct drm_mode_config *mode_config = &dev->mode_config; 998cd569aedSEgbert Eich struct intel_connector *intel_connector; 999cd569aedSEgbert Eich struct intel_encoder *intel_encoder; 1000cd569aedSEgbert Eich struct drm_connector *connector; 1001cd569aedSEgbert Eich unsigned long irqflags; 1002cd569aedSEgbert Eich bool hpd_disabled = false; 1003321a1b30SEgbert Eich bool changed = false; 1004142e2398SEgbert Eich u32 hpd_event_bits; 10055ca58282SJesse Barnes 100652d7ecedSDaniel Vetter /* HPD irq before everything is fully set up. */ 100752d7ecedSDaniel Vetter if (!dev_priv->enable_hotplug_processing) 100852d7ecedSDaniel Vetter return; 100952d7ecedSDaniel Vetter 1010a65e34c7SKeith Packard mutex_lock(&mode_config->mutex); 1011e67189abSJesse Barnes DRM_DEBUG_KMS("running encoder hotplug functions\n"); 1012e67189abSJesse Barnes 1013cd569aedSEgbert Eich spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 1014142e2398SEgbert Eich 1015142e2398SEgbert Eich hpd_event_bits = dev_priv->hpd_event_bits; 1016142e2398SEgbert Eich dev_priv->hpd_event_bits = 0; 1017cd569aedSEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 1018cd569aedSEgbert Eich intel_connector = to_intel_connector(connector); 1019cd569aedSEgbert Eich intel_encoder = intel_connector->encoder; 1020cd569aedSEgbert Eich if (intel_encoder->hpd_pin > HPD_NONE && 1021cd569aedSEgbert Eich dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED && 1022cd569aedSEgbert Eich connector->polled == DRM_CONNECTOR_POLL_HPD) { 1023cd569aedSEgbert Eich DRM_INFO("HPD interrupt storm detected on connector %s: " 1024cd569aedSEgbert Eich "switching from hotplug detection to polling\n", 1025cd569aedSEgbert Eich drm_get_connector_name(connector)); 1026cd569aedSEgbert Eich dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED; 1027cd569aedSEgbert Eich connector->polled = DRM_CONNECTOR_POLL_CONNECT 1028cd569aedSEgbert Eich | DRM_CONNECTOR_POLL_DISCONNECT; 1029cd569aedSEgbert Eich hpd_disabled = true; 1030cd569aedSEgbert Eich } 1031142e2398SEgbert Eich if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) { 1032142e2398SEgbert Eich DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n", 1033142e2398SEgbert Eich drm_get_connector_name(connector), intel_encoder->hpd_pin); 1034142e2398SEgbert Eich } 1035cd569aedSEgbert Eich } 1036cd569aedSEgbert Eich /* if there were no outputs to poll, poll was disabled, 1037cd569aedSEgbert Eich * therefore make sure it's enabled when disabling HPD on 1038cd569aedSEgbert Eich * some connectors */ 1039ac4c16c5SEgbert Eich if (hpd_disabled) { 1040cd569aedSEgbert Eich drm_kms_helper_poll_enable(dev); 1041ac4c16c5SEgbert Eich mod_timer(&dev_priv->hotplug_reenable_timer, 1042ac4c16c5SEgbert Eich jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY)); 1043ac4c16c5SEgbert Eich } 1044cd569aedSEgbert Eich 1045cd569aedSEgbert Eich spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 1046cd569aedSEgbert Eich 1047321a1b30SEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 1048321a1b30SEgbert Eich intel_connector = to_intel_connector(connector); 1049321a1b30SEgbert Eich intel_encoder = intel_connector->encoder; 1050321a1b30SEgbert Eich if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) { 1051cd569aedSEgbert Eich if (intel_encoder->hot_plug) 1052cd569aedSEgbert Eich intel_encoder->hot_plug(intel_encoder); 1053321a1b30SEgbert Eich if (intel_hpd_irq_event(dev, connector)) 1054321a1b30SEgbert Eich changed = true; 1055321a1b30SEgbert Eich } 1056321a1b30SEgbert Eich } 105740ee3381SKeith Packard mutex_unlock(&mode_config->mutex); 105840ee3381SKeith Packard 1059321a1b30SEgbert Eich if (changed) 1060321a1b30SEgbert Eich drm_kms_helper_hotplug_event(dev); 10615ca58282SJesse Barnes } 10625ca58282SJesse Barnes 10633ca1ccedSVille Syrjälä static void intel_hpd_irq_uninstall(struct drm_i915_private *dev_priv) 10643ca1ccedSVille Syrjälä { 10653ca1ccedSVille Syrjälä del_timer_sync(&dev_priv->hotplug_reenable_timer); 10663ca1ccedSVille Syrjälä } 10673ca1ccedSVille Syrjälä 1068d0ecd7e2SDaniel Vetter static void ironlake_rps_change_irq_handler(struct drm_device *dev) 1069f97108d1SJesse Barnes { 10702d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 1071b5b72e89SMatthew Garrett u32 busy_up, busy_down, max_avg, min_avg; 10729270388eSDaniel Vetter u8 new_delay; 10739270388eSDaniel Vetter 1074d0ecd7e2SDaniel Vetter spin_lock(&mchdev_lock); 1075f97108d1SJesse Barnes 107673edd18fSDaniel Vetter I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS)); 107773edd18fSDaniel Vetter 107820e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay; 10799270388eSDaniel Vetter 10807648fa99SJesse Barnes I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG); 1081b5b72e89SMatthew Garrett busy_up = I915_READ(RCPREVBSYTUPAVG); 1082b5b72e89SMatthew Garrett busy_down = I915_READ(RCPREVBSYTDNAVG); 1083f97108d1SJesse Barnes max_avg = I915_READ(RCBMAXAVG); 1084f97108d1SJesse Barnes min_avg = I915_READ(RCBMINAVG); 1085f97108d1SJesse Barnes 1086f97108d1SJesse Barnes /* Handle RCS change request from hw */ 1087b5b72e89SMatthew Garrett if (busy_up > max_avg) { 108820e4d407SDaniel Vetter if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay) 108920e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay - 1; 109020e4d407SDaniel Vetter if (new_delay < dev_priv->ips.max_delay) 109120e4d407SDaniel Vetter new_delay = dev_priv->ips.max_delay; 1092b5b72e89SMatthew Garrett } else if (busy_down < min_avg) { 109320e4d407SDaniel Vetter if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay) 109420e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay + 1; 109520e4d407SDaniel Vetter if (new_delay > dev_priv->ips.min_delay) 109620e4d407SDaniel Vetter new_delay = dev_priv->ips.min_delay; 1097f97108d1SJesse Barnes } 1098f97108d1SJesse Barnes 10997648fa99SJesse Barnes if (ironlake_set_drps(dev, new_delay)) 110020e4d407SDaniel Vetter dev_priv->ips.cur_delay = new_delay; 1101f97108d1SJesse Barnes 1102d0ecd7e2SDaniel Vetter spin_unlock(&mchdev_lock); 11039270388eSDaniel Vetter 1104f97108d1SJesse Barnes return; 1105f97108d1SJesse Barnes } 1106f97108d1SJesse Barnes 1107549f7365SChris Wilson static void notify_ring(struct drm_device *dev, 1108549f7365SChris Wilson struct intel_ring_buffer *ring) 1109549f7365SChris Wilson { 1110475553deSChris Wilson if (ring->obj == NULL) 1111475553deSChris Wilson return; 1112475553deSChris Wilson 1113814e9b57SChris Wilson trace_i915_gem_request_complete(ring); 11149862e600SChris Wilson 1115549f7365SChris Wilson wake_up_all(&ring->irq_queue); 111610cd45b6SMika Kuoppala i915_queue_hangcheck(dev); 1117549f7365SChris Wilson } 1118549f7365SChris Wilson 11194912d041SBen Widawsky static void gen6_pm_rps_work(struct work_struct *work) 11203b8d8d91SJesse Barnes { 11212d1013ddSJani Nikula struct drm_i915_private *dev_priv = 11222d1013ddSJani Nikula container_of(work, struct drm_i915_private, rps.work); 1123edbfdb45SPaulo Zanoni u32 pm_iir; 1124dd75fdc8SChris Wilson int new_delay, adj; 11253b8d8d91SJesse Barnes 112659cdb63dSDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 1127c6a828d3SDaniel Vetter pm_iir = dev_priv->rps.pm_iir; 1128c6a828d3SDaniel Vetter dev_priv->rps.pm_iir = 0; 11294848405cSBen Widawsky /* Make sure not to corrupt PMIMR state used by ringbuffer code */ 1130a6706b45SDeepak S snb_enable_pm_irq(dev_priv, dev_priv->pm_rps_events); 113159cdb63dSDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 11324912d041SBen Widawsky 113360611c13SPaulo Zanoni /* Make sure we didn't queue anything we're not going to process. */ 1134a6706b45SDeepak S WARN_ON(pm_iir & ~dev_priv->pm_rps_events); 113560611c13SPaulo Zanoni 1136a6706b45SDeepak S if ((pm_iir & dev_priv->pm_rps_events) == 0) 11373b8d8d91SJesse Barnes return; 11383b8d8d91SJesse Barnes 11394fc688ceSJesse Barnes mutex_lock(&dev_priv->rps.hw_lock); 11407b9e0ae6SChris Wilson 1141dd75fdc8SChris Wilson adj = dev_priv->rps.last_adj; 11427425034aSVille Syrjälä if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) { 1143dd75fdc8SChris Wilson if (adj > 0) 1144dd75fdc8SChris Wilson adj *= 2; 1145dd75fdc8SChris Wilson else 1146dd75fdc8SChris Wilson adj = 1; 1147b39fb297SBen Widawsky new_delay = dev_priv->rps.cur_freq + adj; 11487425034aSVille Syrjälä 11497425034aSVille Syrjälä /* 11507425034aSVille Syrjälä * For better performance, jump directly 11517425034aSVille Syrjälä * to RPe if we're below it. 11527425034aSVille Syrjälä */ 1153b39fb297SBen Widawsky if (new_delay < dev_priv->rps.efficient_freq) 1154b39fb297SBen Widawsky new_delay = dev_priv->rps.efficient_freq; 1155dd75fdc8SChris Wilson } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) { 1156b39fb297SBen Widawsky if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq) 1157b39fb297SBen Widawsky new_delay = dev_priv->rps.efficient_freq; 1158dd75fdc8SChris Wilson else 1159b39fb297SBen Widawsky new_delay = dev_priv->rps.min_freq_softlimit; 1160dd75fdc8SChris Wilson adj = 0; 1161dd75fdc8SChris Wilson } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) { 1162dd75fdc8SChris Wilson if (adj < 0) 1163dd75fdc8SChris Wilson adj *= 2; 1164dd75fdc8SChris Wilson else 1165dd75fdc8SChris Wilson adj = -1; 1166b39fb297SBen Widawsky new_delay = dev_priv->rps.cur_freq + adj; 1167dd75fdc8SChris Wilson } else { /* unknown event */ 1168b39fb297SBen Widawsky new_delay = dev_priv->rps.cur_freq; 1169dd75fdc8SChris Wilson } 11703b8d8d91SJesse Barnes 117179249636SBen Widawsky /* sysfs frequency interfaces may have snuck in while servicing the 117279249636SBen Widawsky * interrupt 117379249636SBen Widawsky */ 11741272e7b8SVille Syrjälä new_delay = clamp_t(int, new_delay, 1175b39fb297SBen Widawsky dev_priv->rps.min_freq_softlimit, 1176b39fb297SBen Widawsky dev_priv->rps.max_freq_softlimit); 117727544369SDeepak S 1178b39fb297SBen Widawsky dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_freq; 1179dd75fdc8SChris Wilson 11800a073b84SJesse Barnes if (IS_VALLEYVIEW(dev_priv->dev)) 11810a073b84SJesse Barnes valleyview_set_rps(dev_priv->dev, new_delay); 11820a073b84SJesse Barnes else 11834912d041SBen Widawsky gen6_set_rps(dev_priv->dev, new_delay); 11843b8d8d91SJesse Barnes 11854fc688ceSJesse Barnes mutex_unlock(&dev_priv->rps.hw_lock); 11863b8d8d91SJesse Barnes } 11873b8d8d91SJesse Barnes 1188e3689190SBen Widawsky 1189e3689190SBen Widawsky /** 1190e3689190SBen Widawsky * ivybridge_parity_work - Workqueue called when a parity error interrupt 1191e3689190SBen Widawsky * occurred. 1192e3689190SBen Widawsky * @work: workqueue struct 1193e3689190SBen Widawsky * 1194e3689190SBen Widawsky * Doesn't actually do anything except notify userspace. As a consequence of 1195e3689190SBen Widawsky * this event, userspace should try to remap the bad rows since statistically 1196e3689190SBen Widawsky * it is likely the same row is more likely to go bad again. 1197e3689190SBen Widawsky */ 1198e3689190SBen Widawsky static void ivybridge_parity_work(struct work_struct *work) 1199e3689190SBen Widawsky { 12002d1013ddSJani Nikula struct drm_i915_private *dev_priv = 12012d1013ddSJani Nikula container_of(work, struct drm_i915_private, l3_parity.error_work); 1202e3689190SBen Widawsky u32 error_status, row, bank, subbank; 120335a85ac6SBen Widawsky char *parity_event[6]; 1204e3689190SBen Widawsky uint32_t misccpctl; 1205e3689190SBen Widawsky unsigned long flags; 120635a85ac6SBen Widawsky uint8_t slice = 0; 1207e3689190SBen Widawsky 1208e3689190SBen Widawsky /* We must turn off DOP level clock gating to access the L3 registers. 1209e3689190SBen Widawsky * In order to prevent a get/put style interface, acquire struct mutex 1210e3689190SBen Widawsky * any time we access those registers. 1211e3689190SBen Widawsky */ 1212e3689190SBen Widawsky mutex_lock(&dev_priv->dev->struct_mutex); 1213e3689190SBen Widawsky 121435a85ac6SBen Widawsky /* If we've screwed up tracking, just let the interrupt fire again */ 121535a85ac6SBen Widawsky if (WARN_ON(!dev_priv->l3_parity.which_slice)) 121635a85ac6SBen Widawsky goto out; 121735a85ac6SBen Widawsky 1218e3689190SBen Widawsky misccpctl = I915_READ(GEN7_MISCCPCTL); 1219e3689190SBen Widawsky I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); 1220e3689190SBen Widawsky POSTING_READ(GEN7_MISCCPCTL); 1221e3689190SBen Widawsky 122235a85ac6SBen Widawsky while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) { 122335a85ac6SBen Widawsky u32 reg; 122435a85ac6SBen Widawsky 122535a85ac6SBen Widawsky slice--; 122635a85ac6SBen Widawsky if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev))) 122735a85ac6SBen Widawsky break; 122835a85ac6SBen Widawsky 122935a85ac6SBen Widawsky dev_priv->l3_parity.which_slice &= ~(1<<slice); 123035a85ac6SBen Widawsky 123135a85ac6SBen Widawsky reg = GEN7_L3CDERRST1 + (slice * 0x200); 123235a85ac6SBen Widawsky 123335a85ac6SBen Widawsky error_status = I915_READ(reg); 1234e3689190SBen Widawsky row = GEN7_PARITY_ERROR_ROW(error_status); 1235e3689190SBen Widawsky bank = GEN7_PARITY_ERROR_BANK(error_status); 1236e3689190SBen Widawsky subbank = GEN7_PARITY_ERROR_SUBBANK(error_status); 1237e3689190SBen Widawsky 123835a85ac6SBen Widawsky I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE); 123935a85ac6SBen Widawsky POSTING_READ(reg); 1240e3689190SBen Widawsky 1241cce723edSBen Widawsky parity_event[0] = I915_L3_PARITY_UEVENT "=1"; 1242e3689190SBen Widawsky parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row); 1243e3689190SBen Widawsky parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank); 1244e3689190SBen Widawsky parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank); 124535a85ac6SBen Widawsky parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice); 124635a85ac6SBen Widawsky parity_event[5] = NULL; 1247e3689190SBen Widawsky 12485bdebb18SDave Airlie kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj, 1249e3689190SBen Widawsky KOBJ_CHANGE, parity_event); 1250e3689190SBen Widawsky 125135a85ac6SBen Widawsky DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n", 125235a85ac6SBen Widawsky slice, row, bank, subbank); 1253e3689190SBen Widawsky 125435a85ac6SBen Widawsky kfree(parity_event[4]); 1255e3689190SBen Widawsky kfree(parity_event[3]); 1256e3689190SBen Widawsky kfree(parity_event[2]); 1257e3689190SBen Widawsky kfree(parity_event[1]); 1258e3689190SBen Widawsky } 1259e3689190SBen Widawsky 126035a85ac6SBen Widawsky I915_WRITE(GEN7_MISCCPCTL, misccpctl); 126135a85ac6SBen Widawsky 126235a85ac6SBen Widawsky out: 126335a85ac6SBen Widawsky WARN_ON(dev_priv->l3_parity.which_slice); 126435a85ac6SBen Widawsky spin_lock_irqsave(&dev_priv->irq_lock, flags); 126535a85ac6SBen Widawsky ilk_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev)); 126635a85ac6SBen Widawsky spin_unlock_irqrestore(&dev_priv->irq_lock, flags); 126735a85ac6SBen Widawsky 126835a85ac6SBen Widawsky mutex_unlock(&dev_priv->dev->struct_mutex); 126935a85ac6SBen Widawsky } 127035a85ac6SBen Widawsky 127135a85ac6SBen Widawsky static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir) 1272e3689190SBen Widawsky { 12732d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 1274e3689190SBen Widawsky 1275040d2baaSBen Widawsky if (!HAS_L3_DPF(dev)) 1276e3689190SBen Widawsky return; 1277e3689190SBen Widawsky 1278d0ecd7e2SDaniel Vetter spin_lock(&dev_priv->irq_lock); 127935a85ac6SBen Widawsky ilk_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev)); 1280d0ecd7e2SDaniel Vetter spin_unlock(&dev_priv->irq_lock); 1281e3689190SBen Widawsky 128235a85ac6SBen Widawsky iir &= GT_PARITY_ERROR(dev); 128335a85ac6SBen Widawsky if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1) 128435a85ac6SBen Widawsky dev_priv->l3_parity.which_slice |= 1 << 1; 128535a85ac6SBen Widawsky 128635a85ac6SBen Widawsky if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT) 128735a85ac6SBen Widawsky dev_priv->l3_parity.which_slice |= 1 << 0; 128835a85ac6SBen Widawsky 1289a4da4fa4SDaniel Vetter queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work); 1290e3689190SBen Widawsky } 1291e3689190SBen Widawsky 1292f1af8fc1SPaulo Zanoni static void ilk_gt_irq_handler(struct drm_device *dev, 1293f1af8fc1SPaulo Zanoni struct drm_i915_private *dev_priv, 1294f1af8fc1SPaulo Zanoni u32 gt_iir) 1295f1af8fc1SPaulo Zanoni { 1296f1af8fc1SPaulo Zanoni if (gt_iir & 1297f1af8fc1SPaulo Zanoni (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT)) 1298f1af8fc1SPaulo Zanoni notify_ring(dev, &dev_priv->ring[RCS]); 1299f1af8fc1SPaulo Zanoni if (gt_iir & ILK_BSD_USER_INTERRUPT) 1300f1af8fc1SPaulo Zanoni notify_ring(dev, &dev_priv->ring[VCS]); 1301f1af8fc1SPaulo Zanoni } 1302f1af8fc1SPaulo Zanoni 1303e7b4c6b1SDaniel Vetter static void snb_gt_irq_handler(struct drm_device *dev, 1304e7b4c6b1SDaniel Vetter struct drm_i915_private *dev_priv, 1305e7b4c6b1SDaniel Vetter u32 gt_iir) 1306e7b4c6b1SDaniel Vetter { 1307e7b4c6b1SDaniel Vetter 1308cc609d5dSBen Widawsky if (gt_iir & 1309cc609d5dSBen Widawsky (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT)) 1310e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[RCS]); 1311cc609d5dSBen Widawsky if (gt_iir & GT_BSD_USER_INTERRUPT) 1312e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[VCS]); 1313cc609d5dSBen Widawsky if (gt_iir & GT_BLT_USER_INTERRUPT) 1314e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[BCS]); 1315e7b4c6b1SDaniel Vetter 1316cc609d5dSBen Widawsky if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT | 1317cc609d5dSBen Widawsky GT_BSD_CS_ERROR_INTERRUPT | 1318cc609d5dSBen Widawsky GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) { 131958174462SMika Kuoppala i915_handle_error(dev, false, "GT error interrupt 0x%08x", 132058174462SMika Kuoppala gt_iir); 1321e7b4c6b1SDaniel Vetter } 1322e3689190SBen Widawsky 132335a85ac6SBen Widawsky if (gt_iir & GT_PARITY_ERROR(dev)) 132435a85ac6SBen Widawsky ivybridge_parity_error_irq_handler(dev, gt_iir); 1325e7b4c6b1SDaniel Vetter } 1326e7b4c6b1SDaniel Vetter 1327abd58f01SBen Widawsky static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev, 1328abd58f01SBen Widawsky struct drm_i915_private *dev_priv, 1329abd58f01SBen Widawsky u32 master_ctl) 1330abd58f01SBen Widawsky { 1331abd58f01SBen Widawsky u32 rcs, bcs, vcs; 1332abd58f01SBen Widawsky uint32_t tmp = 0; 1333abd58f01SBen Widawsky irqreturn_t ret = IRQ_NONE; 1334abd58f01SBen Widawsky 1335abd58f01SBen Widawsky if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) { 1336abd58f01SBen Widawsky tmp = I915_READ(GEN8_GT_IIR(0)); 1337abd58f01SBen Widawsky if (tmp) { 1338abd58f01SBen Widawsky ret = IRQ_HANDLED; 1339abd58f01SBen Widawsky rcs = tmp >> GEN8_RCS_IRQ_SHIFT; 1340abd58f01SBen Widawsky bcs = tmp >> GEN8_BCS_IRQ_SHIFT; 1341abd58f01SBen Widawsky if (rcs & GT_RENDER_USER_INTERRUPT) 1342abd58f01SBen Widawsky notify_ring(dev, &dev_priv->ring[RCS]); 1343abd58f01SBen Widawsky if (bcs & GT_RENDER_USER_INTERRUPT) 1344abd58f01SBen Widawsky notify_ring(dev, &dev_priv->ring[BCS]); 1345abd58f01SBen Widawsky I915_WRITE(GEN8_GT_IIR(0), tmp); 1346abd58f01SBen Widawsky } else 1347abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (GT0)!\n"); 1348abd58f01SBen Widawsky } 1349abd58f01SBen Widawsky 1350abd58f01SBen Widawsky if (master_ctl & GEN8_GT_VCS1_IRQ) { 1351abd58f01SBen Widawsky tmp = I915_READ(GEN8_GT_IIR(1)); 1352abd58f01SBen Widawsky if (tmp) { 1353abd58f01SBen Widawsky ret = IRQ_HANDLED; 1354abd58f01SBen Widawsky vcs = tmp >> GEN8_VCS1_IRQ_SHIFT; 1355abd58f01SBen Widawsky if (vcs & GT_RENDER_USER_INTERRUPT) 1356abd58f01SBen Widawsky notify_ring(dev, &dev_priv->ring[VCS]); 1357abd58f01SBen Widawsky I915_WRITE(GEN8_GT_IIR(1), tmp); 1358abd58f01SBen Widawsky } else 1359abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (GT1)!\n"); 1360abd58f01SBen Widawsky } 1361abd58f01SBen Widawsky 1362abd58f01SBen Widawsky if (master_ctl & GEN8_GT_VECS_IRQ) { 1363abd58f01SBen Widawsky tmp = I915_READ(GEN8_GT_IIR(3)); 1364abd58f01SBen Widawsky if (tmp) { 1365abd58f01SBen Widawsky ret = IRQ_HANDLED; 1366abd58f01SBen Widawsky vcs = tmp >> GEN8_VECS_IRQ_SHIFT; 1367abd58f01SBen Widawsky if (vcs & GT_RENDER_USER_INTERRUPT) 1368abd58f01SBen Widawsky notify_ring(dev, &dev_priv->ring[VECS]); 1369abd58f01SBen Widawsky I915_WRITE(GEN8_GT_IIR(3), tmp); 1370abd58f01SBen Widawsky } else 1371abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (GT3)!\n"); 1372abd58f01SBen Widawsky } 1373abd58f01SBen Widawsky 1374abd58f01SBen Widawsky return ret; 1375abd58f01SBen Widawsky } 1376abd58f01SBen Widawsky 1377b543fb04SEgbert Eich #define HPD_STORM_DETECT_PERIOD 1000 1378b543fb04SEgbert Eich #define HPD_STORM_THRESHOLD 5 1379b543fb04SEgbert Eich 138010a504deSDaniel Vetter static inline void intel_hpd_irq_handler(struct drm_device *dev, 1381b543fb04SEgbert Eich u32 hotplug_trigger, 1382b543fb04SEgbert Eich const u32 *hpd) 1383b543fb04SEgbert Eich { 13842d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 1385b543fb04SEgbert Eich int i; 138610a504deSDaniel Vetter bool storm_detected = false; 1387b543fb04SEgbert Eich 138891d131d2SDaniel Vetter if (!hotplug_trigger) 138991d131d2SDaniel Vetter return; 139091d131d2SDaniel Vetter 1391cc9bd499SImre Deak DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n", 1392cc9bd499SImre Deak hotplug_trigger); 1393cc9bd499SImre Deak 1394b5ea2d56SDaniel Vetter spin_lock(&dev_priv->irq_lock); 1395b543fb04SEgbert Eich for (i = 1; i < HPD_NUM_PINS; i++) { 1396821450c6SEgbert Eich 13973432087eSChris Wilson WARN_ONCE(hpd[i] & hotplug_trigger && 13988b5565b8SChris Wilson dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED, 1399cba1c073SChris Wilson "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n", 1400cba1c073SChris Wilson hotplug_trigger, i, hpd[i]); 1401b8f102e8SEgbert Eich 1402b543fb04SEgbert Eich if (!(hpd[i] & hotplug_trigger) || 1403b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED) 1404b543fb04SEgbert Eich continue; 1405b543fb04SEgbert Eich 1406bc5ead8cSJani Nikula dev_priv->hpd_event_bits |= (1 << i); 1407b543fb04SEgbert Eich if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies, 1408b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_last_jiffies 1409b543fb04SEgbert Eich + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) { 1410b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies; 1411b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt = 0; 1412b8f102e8SEgbert Eich DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i); 1413b543fb04SEgbert Eich } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) { 1414b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED; 1415142e2398SEgbert Eich dev_priv->hpd_event_bits &= ~(1 << i); 1416b543fb04SEgbert Eich DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i); 141710a504deSDaniel Vetter storm_detected = true; 1418b543fb04SEgbert Eich } else { 1419b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt++; 1420b8f102e8SEgbert Eich DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i, 1421b8f102e8SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt); 1422b543fb04SEgbert Eich } 1423b543fb04SEgbert Eich } 1424b543fb04SEgbert Eich 142510a504deSDaniel Vetter if (storm_detected) 142610a504deSDaniel Vetter dev_priv->display.hpd_irq_setup(dev); 1427b5ea2d56SDaniel Vetter spin_unlock(&dev_priv->irq_lock); 14285876fa0dSDaniel Vetter 1429645416f5SDaniel Vetter /* 1430645416f5SDaniel Vetter * Our hotplug handler can grab modeset locks (by calling down into the 1431645416f5SDaniel Vetter * fb helpers). Hence it must not be run on our own dev-priv->wq work 1432645416f5SDaniel Vetter * queue for otherwise the flush_work in the pageflip code will 1433645416f5SDaniel Vetter * deadlock. 1434645416f5SDaniel Vetter */ 1435645416f5SDaniel Vetter schedule_work(&dev_priv->hotplug_work); 1436b543fb04SEgbert Eich } 1437b543fb04SEgbert Eich 1438515ac2bbSDaniel Vetter static void gmbus_irq_handler(struct drm_device *dev) 1439515ac2bbSDaniel Vetter { 14402d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 144128c70f16SDaniel Vetter 144228c70f16SDaniel Vetter wake_up_all(&dev_priv->gmbus_wait_queue); 1443515ac2bbSDaniel Vetter } 1444515ac2bbSDaniel Vetter 1445ce99c256SDaniel Vetter static void dp_aux_irq_handler(struct drm_device *dev) 1446ce99c256SDaniel Vetter { 14472d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 14489ee32feaSDaniel Vetter 14499ee32feaSDaniel Vetter wake_up_all(&dev_priv->gmbus_wait_queue); 1450ce99c256SDaniel Vetter } 1451ce99c256SDaniel Vetter 14528bf1e9f1SShuang He #if defined(CONFIG_DEBUG_FS) 1453277de95eSDaniel Vetter static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe, 1454eba94eb9SDaniel Vetter uint32_t crc0, uint32_t crc1, 1455eba94eb9SDaniel Vetter uint32_t crc2, uint32_t crc3, 14568bc5e955SDaniel Vetter uint32_t crc4) 14578bf1e9f1SShuang He { 14588bf1e9f1SShuang He struct drm_i915_private *dev_priv = dev->dev_private; 14598bf1e9f1SShuang He struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe]; 14608bf1e9f1SShuang He struct intel_pipe_crc_entry *entry; 1461ac2300d4SDamien Lespiau int head, tail; 1462b2c88f5bSDamien Lespiau 1463d538bbdfSDamien Lespiau spin_lock(&pipe_crc->lock); 1464d538bbdfSDamien Lespiau 14650c912c79SDamien Lespiau if (!pipe_crc->entries) { 1466d538bbdfSDamien Lespiau spin_unlock(&pipe_crc->lock); 14670c912c79SDamien Lespiau DRM_ERROR("spurious interrupt\n"); 14680c912c79SDamien Lespiau return; 14690c912c79SDamien Lespiau } 14700c912c79SDamien Lespiau 1471d538bbdfSDamien Lespiau head = pipe_crc->head; 1472d538bbdfSDamien Lespiau tail = pipe_crc->tail; 1473b2c88f5bSDamien Lespiau 1474b2c88f5bSDamien Lespiau if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) { 1475d538bbdfSDamien Lespiau spin_unlock(&pipe_crc->lock); 1476b2c88f5bSDamien Lespiau DRM_ERROR("CRC buffer overflowing\n"); 1477b2c88f5bSDamien Lespiau return; 1478b2c88f5bSDamien Lespiau } 1479b2c88f5bSDamien Lespiau 1480b2c88f5bSDamien Lespiau entry = &pipe_crc->entries[head]; 14818bf1e9f1SShuang He 14828bc5e955SDaniel Vetter entry->frame = dev->driver->get_vblank_counter(dev, pipe); 1483eba94eb9SDaniel Vetter entry->crc[0] = crc0; 1484eba94eb9SDaniel Vetter entry->crc[1] = crc1; 1485eba94eb9SDaniel Vetter entry->crc[2] = crc2; 1486eba94eb9SDaniel Vetter entry->crc[3] = crc3; 1487eba94eb9SDaniel Vetter entry->crc[4] = crc4; 1488b2c88f5bSDamien Lespiau 1489b2c88f5bSDamien Lespiau head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1); 1490d538bbdfSDamien Lespiau pipe_crc->head = head; 1491d538bbdfSDamien Lespiau 1492d538bbdfSDamien Lespiau spin_unlock(&pipe_crc->lock); 149307144428SDamien Lespiau 149407144428SDamien Lespiau wake_up_interruptible(&pipe_crc->wq); 14958bf1e9f1SShuang He } 1496277de95eSDaniel Vetter #else 1497277de95eSDaniel Vetter static inline void 1498277de95eSDaniel Vetter display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe, 1499277de95eSDaniel Vetter uint32_t crc0, uint32_t crc1, 1500277de95eSDaniel Vetter uint32_t crc2, uint32_t crc3, 1501277de95eSDaniel Vetter uint32_t crc4) {} 1502277de95eSDaniel Vetter #endif 1503eba94eb9SDaniel Vetter 1504277de95eSDaniel Vetter 1505277de95eSDaniel Vetter static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe) 15065a69b89fSDaniel Vetter { 15075a69b89fSDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 15085a69b89fSDaniel Vetter 1509277de95eSDaniel Vetter display_pipe_crc_irq_handler(dev, pipe, 15105a69b89fSDaniel Vetter I915_READ(PIPE_CRC_RES_1_IVB(pipe)), 15115a69b89fSDaniel Vetter 0, 0, 0, 0); 15125a69b89fSDaniel Vetter } 15135a69b89fSDaniel Vetter 1514277de95eSDaniel Vetter static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe) 1515eba94eb9SDaniel Vetter { 1516eba94eb9SDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 1517eba94eb9SDaniel Vetter 1518277de95eSDaniel Vetter display_pipe_crc_irq_handler(dev, pipe, 1519eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_1_IVB(pipe)), 1520eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_2_IVB(pipe)), 1521eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_3_IVB(pipe)), 1522eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_4_IVB(pipe)), 15238bc5e955SDaniel Vetter I915_READ(PIPE_CRC_RES_5_IVB(pipe))); 1524eba94eb9SDaniel Vetter } 15255b3a856bSDaniel Vetter 1526277de95eSDaniel Vetter static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe) 15275b3a856bSDaniel Vetter { 15285b3a856bSDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 15290b5c5ed0SDaniel Vetter uint32_t res1, res2; 15300b5c5ed0SDaniel Vetter 15310b5c5ed0SDaniel Vetter if (INTEL_INFO(dev)->gen >= 3) 15320b5c5ed0SDaniel Vetter res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe)); 15330b5c5ed0SDaniel Vetter else 15340b5c5ed0SDaniel Vetter res1 = 0; 15350b5c5ed0SDaniel Vetter 15360b5c5ed0SDaniel Vetter if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) 15370b5c5ed0SDaniel Vetter res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe)); 15380b5c5ed0SDaniel Vetter else 15390b5c5ed0SDaniel Vetter res2 = 0; 15405b3a856bSDaniel Vetter 1541277de95eSDaniel Vetter display_pipe_crc_irq_handler(dev, pipe, 15420b5c5ed0SDaniel Vetter I915_READ(PIPE_CRC_RES_RED(pipe)), 15430b5c5ed0SDaniel Vetter I915_READ(PIPE_CRC_RES_GREEN(pipe)), 15440b5c5ed0SDaniel Vetter I915_READ(PIPE_CRC_RES_BLUE(pipe)), 15450b5c5ed0SDaniel Vetter res1, res2); 15465b3a856bSDaniel Vetter } 15478bf1e9f1SShuang He 15481403c0d4SPaulo Zanoni /* The RPS events need forcewake, so we add them to a work queue and mask their 15491403c0d4SPaulo Zanoni * IMR bits until the work is done. Other interrupts can be processed without 15501403c0d4SPaulo Zanoni * the work queue. */ 15511403c0d4SPaulo Zanoni static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir) 1552baf02a1fSBen Widawsky { 1553a6706b45SDeepak S if (pm_iir & dev_priv->pm_rps_events) { 155459cdb63dSDaniel Vetter spin_lock(&dev_priv->irq_lock); 1555a6706b45SDeepak S dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events; 1556a6706b45SDeepak S snb_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events); 155759cdb63dSDaniel Vetter spin_unlock(&dev_priv->irq_lock); 15582adbee62SDaniel Vetter 15592adbee62SDaniel Vetter queue_work(dev_priv->wq, &dev_priv->rps.work); 156041a05a3aSDaniel Vetter } 1561baf02a1fSBen Widawsky 15621403c0d4SPaulo Zanoni if (HAS_VEBOX(dev_priv->dev)) { 156312638c57SBen Widawsky if (pm_iir & PM_VEBOX_USER_INTERRUPT) 156412638c57SBen Widawsky notify_ring(dev_priv->dev, &dev_priv->ring[VECS]); 156512638c57SBen Widawsky 156612638c57SBen Widawsky if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) { 156758174462SMika Kuoppala i915_handle_error(dev_priv->dev, false, 156858174462SMika Kuoppala "VEBOX CS error interrupt 0x%08x", 156958174462SMika Kuoppala pm_iir); 157012638c57SBen Widawsky } 157112638c57SBen Widawsky } 15721403c0d4SPaulo Zanoni } 1573baf02a1fSBen Widawsky 1574c1874ed7SImre Deak static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir) 15757e231dbeSJesse Barnes { 1576c1874ed7SImre Deak struct drm_i915_private *dev_priv = dev->dev_private; 157791d181ddSImre Deak u32 pipe_stats[I915_MAX_PIPES] = { }; 15787e231dbeSJesse Barnes int pipe; 15797e231dbeSJesse Barnes 158058ead0d7SImre Deak spin_lock(&dev_priv->irq_lock); 15817e231dbeSJesse Barnes for_each_pipe(pipe) { 158291d181ddSImre Deak int reg; 1583bbb5eebfSDaniel Vetter u32 mask, iir_bit = 0; 158491d181ddSImre Deak 1585bbb5eebfSDaniel Vetter /* 1586bbb5eebfSDaniel Vetter * PIPESTAT bits get signalled even when the interrupt is 1587bbb5eebfSDaniel Vetter * disabled with the mask bits, and some of the status bits do 1588bbb5eebfSDaniel Vetter * not generate interrupts at all (like the underrun bit). Hence 1589bbb5eebfSDaniel Vetter * we need to be careful that we only handle what we want to 1590bbb5eebfSDaniel Vetter * handle. 1591bbb5eebfSDaniel Vetter */ 1592bbb5eebfSDaniel Vetter mask = 0; 1593bbb5eebfSDaniel Vetter if (__cpu_fifo_underrun_reporting_enabled(dev, pipe)) 1594bbb5eebfSDaniel Vetter mask |= PIPE_FIFO_UNDERRUN_STATUS; 1595bbb5eebfSDaniel Vetter 1596bbb5eebfSDaniel Vetter switch (pipe) { 1597bbb5eebfSDaniel Vetter case PIPE_A: 1598bbb5eebfSDaniel Vetter iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT; 1599bbb5eebfSDaniel Vetter break; 1600bbb5eebfSDaniel Vetter case PIPE_B: 1601bbb5eebfSDaniel Vetter iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT; 1602bbb5eebfSDaniel Vetter break; 1603bbb5eebfSDaniel Vetter } 1604bbb5eebfSDaniel Vetter if (iir & iir_bit) 1605bbb5eebfSDaniel Vetter mask |= dev_priv->pipestat_irq_mask[pipe]; 1606bbb5eebfSDaniel Vetter 1607bbb5eebfSDaniel Vetter if (!mask) 160891d181ddSImre Deak continue; 160991d181ddSImre Deak 161091d181ddSImre Deak reg = PIPESTAT(pipe); 1611bbb5eebfSDaniel Vetter mask |= PIPESTAT_INT_ENABLE_MASK; 1612bbb5eebfSDaniel Vetter pipe_stats[pipe] = I915_READ(reg) & mask; 16137e231dbeSJesse Barnes 16147e231dbeSJesse Barnes /* 16157e231dbeSJesse Barnes * Clear the PIPE*STAT regs before the IIR 16167e231dbeSJesse Barnes */ 161791d181ddSImre Deak if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS | 161891d181ddSImre Deak PIPESTAT_INT_STATUS_MASK)) 16197e231dbeSJesse Barnes I915_WRITE(reg, pipe_stats[pipe]); 16207e231dbeSJesse Barnes } 162158ead0d7SImre Deak spin_unlock(&dev_priv->irq_lock); 16227e231dbeSJesse Barnes 162331acc7f5SJesse Barnes for_each_pipe(pipe) { 16247b5562d4SJesse Barnes if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS) 162531acc7f5SJesse Barnes drm_handle_vblank(dev, pipe); 162631acc7f5SJesse Barnes 1627579a9b0eSImre Deak if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) { 162831acc7f5SJesse Barnes intel_prepare_page_flip(dev, pipe); 162931acc7f5SJesse Barnes intel_finish_page_flip(dev, pipe); 163031acc7f5SJesse Barnes } 16314356d586SDaniel Vetter 16324356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 1633277de95eSDaniel Vetter i9xx_pipe_crc_irq_handler(dev, pipe); 16342d9d2b0bSVille Syrjälä 16352d9d2b0bSVille Syrjälä if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS && 16362d9d2b0bSVille Syrjälä intel_set_cpu_fifo_underrun_reporting(dev, pipe, false)) 1637fc2c807bSVille Syrjälä DRM_ERROR("pipe %c underrun\n", pipe_name(pipe)); 163831acc7f5SJesse Barnes } 163931acc7f5SJesse Barnes 1640c1874ed7SImre Deak if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 1641c1874ed7SImre Deak gmbus_irq_handler(dev); 1642c1874ed7SImre Deak } 1643c1874ed7SImre Deak 164416c6c56bSVille Syrjälä static void i9xx_hpd_irq_handler(struct drm_device *dev) 164516c6c56bSVille Syrjälä { 164616c6c56bSVille Syrjälä struct drm_i915_private *dev_priv = dev->dev_private; 164716c6c56bSVille Syrjälä u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); 164816c6c56bSVille Syrjälä 164916c6c56bSVille Syrjälä if (IS_G4X(dev)) { 165016c6c56bSVille Syrjälä u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X; 165116c6c56bSVille Syrjälä 165216c6c56bSVille Syrjälä intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_g4x); 165316c6c56bSVille Syrjälä } else { 165416c6c56bSVille Syrjälä u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915; 165516c6c56bSVille Syrjälä 165616c6c56bSVille Syrjälä intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915); 165716c6c56bSVille Syrjälä } 165816c6c56bSVille Syrjälä 165916c6c56bSVille Syrjälä if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) && 166016c6c56bSVille Syrjälä hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X) 166116c6c56bSVille Syrjälä dp_aux_irq_handler(dev); 166216c6c56bSVille Syrjälä 166316c6c56bSVille Syrjälä I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); 166416c6c56bSVille Syrjälä /* 166516c6c56bSVille Syrjälä * Make sure hotplug status is cleared before we clear IIR, or else we 166616c6c56bSVille Syrjälä * may miss hotplug events. 166716c6c56bSVille Syrjälä */ 166816c6c56bSVille Syrjälä POSTING_READ(PORT_HOTPLUG_STAT); 166916c6c56bSVille Syrjälä } 167016c6c56bSVille Syrjälä 1671c1874ed7SImre Deak static irqreturn_t valleyview_irq_handler(int irq, void *arg) 1672c1874ed7SImre Deak { 1673c1874ed7SImre Deak struct drm_device *dev = (struct drm_device *) arg; 16742d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 1675c1874ed7SImre Deak u32 iir, gt_iir, pm_iir; 1676c1874ed7SImre Deak irqreturn_t ret = IRQ_NONE; 1677c1874ed7SImre Deak 1678c1874ed7SImre Deak while (true) { 1679c1874ed7SImre Deak iir = I915_READ(VLV_IIR); 1680c1874ed7SImre Deak gt_iir = I915_READ(GTIIR); 1681c1874ed7SImre Deak pm_iir = I915_READ(GEN6_PMIIR); 1682c1874ed7SImre Deak 1683c1874ed7SImre Deak if (gt_iir == 0 && pm_iir == 0 && iir == 0) 1684c1874ed7SImre Deak goto out; 1685c1874ed7SImre Deak 1686c1874ed7SImre Deak ret = IRQ_HANDLED; 1687c1874ed7SImre Deak 1688c1874ed7SImre Deak snb_gt_irq_handler(dev, dev_priv, gt_iir); 1689c1874ed7SImre Deak 1690c1874ed7SImre Deak valleyview_pipestat_irq_handler(dev, iir); 1691c1874ed7SImre Deak 16927e231dbeSJesse Barnes /* Consume port. Then clear IIR or we'll miss events */ 169316c6c56bSVille Syrjälä if (iir & I915_DISPLAY_PORT_INTERRUPT) 169416c6c56bSVille Syrjälä i9xx_hpd_irq_handler(dev); 16957e231dbeSJesse Barnes 169660611c13SPaulo Zanoni if (pm_iir) 1697d0ecd7e2SDaniel Vetter gen6_rps_irq_handler(dev_priv, pm_iir); 16987e231dbeSJesse Barnes 16997e231dbeSJesse Barnes I915_WRITE(GTIIR, gt_iir); 17007e231dbeSJesse Barnes I915_WRITE(GEN6_PMIIR, pm_iir); 17017e231dbeSJesse Barnes I915_WRITE(VLV_IIR, iir); 17027e231dbeSJesse Barnes } 17037e231dbeSJesse Barnes 17047e231dbeSJesse Barnes out: 17057e231dbeSJesse Barnes return ret; 17067e231dbeSJesse Barnes } 17077e231dbeSJesse Barnes 170823e81d69SAdam Jackson static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir) 1709776ad806SJesse Barnes { 17102d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 17119db4a9c7SJesse Barnes int pipe; 1712b543fb04SEgbert Eich u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK; 1713776ad806SJesse Barnes 171410a504deSDaniel Vetter intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx); 171591d131d2SDaniel Vetter 1716cfc33bf7SVille Syrjälä if (pch_iir & SDE_AUDIO_POWER_MASK) { 1717cfc33bf7SVille Syrjälä int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >> 1718776ad806SJesse Barnes SDE_AUDIO_POWER_SHIFT); 1719cfc33bf7SVille Syrjälä DRM_DEBUG_DRIVER("PCH audio power change on port %d\n", 1720cfc33bf7SVille Syrjälä port_name(port)); 1721cfc33bf7SVille Syrjälä } 1722776ad806SJesse Barnes 1723ce99c256SDaniel Vetter if (pch_iir & SDE_AUX_MASK) 1724ce99c256SDaniel Vetter dp_aux_irq_handler(dev); 1725ce99c256SDaniel Vetter 1726776ad806SJesse Barnes if (pch_iir & SDE_GMBUS) 1727515ac2bbSDaniel Vetter gmbus_irq_handler(dev); 1728776ad806SJesse Barnes 1729776ad806SJesse Barnes if (pch_iir & SDE_AUDIO_HDCP_MASK) 1730776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n"); 1731776ad806SJesse Barnes 1732776ad806SJesse Barnes if (pch_iir & SDE_AUDIO_TRANS_MASK) 1733776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n"); 1734776ad806SJesse Barnes 1735776ad806SJesse Barnes if (pch_iir & SDE_POISON) 1736776ad806SJesse Barnes DRM_ERROR("PCH poison interrupt\n"); 1737776ad806SJesse Barnes 17389db4a9c7SJesse Barnes if (pch_iir & SDE_FDI_MASK) 17399db4a9c7SJesse Barnes for_each_pipe(pipe) 17409db4a9c7SJesse Barnes DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", 17419db4a9c7SJesse Barnes pipe_name(pipe), 17429db4a9c7SJesse Barnes I915_READ(FDI_RX_IIR(pipe))); 1743776ad806SJesse Barnes 1744776ad806SJesse Barnes if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE)) 1745776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n"); 1746776ad806SJesse Barnes 1747776ad806SJesse Barnes if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR)) 1748776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n"); 1749776ad806SJesse Barnes 1750776ad806SJesse Barnes if (pch_iir & SDE_TRANSA_FIFO_UNDER) 17518664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, 17528664281bSPaulo Zanoni false)) 1753fc2c807bSVille Syrjälä DRM_ERROR("PCH transcoder A FIFO underrun\n"); 17548664281bSPaulo Zanoni 17558664281bSPaulo Zanoni if (pch_iir & SDE_TRANSB_FIFO_UNDER) 17568664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B, 17578664281bSPaulo Zanoni false)) 1758fc2c807bSVille Syrjälä DRM_ERROR("PCH transcoder B FIFO underrun\n"); 17598664281bSPaulo Zanoni } 17608664281bSPaulo Zanoni 17618664281bSPaulo Zanoni static void ivb_err_int_handler(struct drm_device *dev) 17628664281bSPaulo Zanoni { 17638664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 17648664281bSPaulo Zanoni u32 err_int = I915_READ(GEN7_ERR_INT); 17655a69b89fSDaniel Vetter enum pipe pipe; 17668664281bSPaulo Zanoni 1767de032bf4SPaulo Zanoni if (err_int & ERR_INT_POISON) 1768de032bf4SPaulo Zanoni DRM_ERROR("Poison interrupt\n"); 1769de032bf4SPaulo Zanoni 17705a69b89fSDaniel Vetter for_each_pipe(pipe) { 17715a69b89fSDaniel Vetter if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) { 17725a69b89fSDaniel Vetter if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, 17735a69b89fSDaniel Vetter false)) 1774fc2c807bSVille Syrjälä DRM_ERROR("Pipe %c FIFO underrun\n", 17755a69b89fSDaniel Vetter pipe_name(pipe)); 17765a69b89fSDaniel Vetter } 17778664281bSPaulo Zanoni 17785a69b89fSDaniel Vetter if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) { 17795a69b89fSDaniel Vetter if (IS_IVYBRIDGE(dev)) 1780277de95eSDaniel Vetter ivb_pipe_crc_irq_handler(dev, pipe); 17815a69b89fSDaniel Vetter else 1782277de95eSDaniel Vetter hsw_pipe_crc_irq_handler(dev, pipe); 17835a69b89fSDaniel Vetter } 17845a69b89fSDaniel Vetter } 17858bf1e9f1SShuang He 17868664281bSPaulo Zanoni I915_WRITE(GEN7_ERR_INT, err_int); 17878664281bSPaulo Zanoni } 17888664281bSPaulo Zanoni 17898664281bSPaulo Zanoni static void cpt_serr_int_handler(struct drm_device *dev) 17908664281bSPaulo Zanoni { 17918664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 17928664281bSPaulo Zanoni u32 serr_int = I915_READ(SERR_INT); 17938664281bSPaulo Zanoni 1794de032bf4SPaulo Zanoni if (serr_int & SERR_INT_POISON) 1795de032bf4SPaulo Zanoni DRM_ERROR("PCH poison interrupt\n"); 1796de032bf4SPaulo Zanoni 17978664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN) 17988664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, 17998664281bSPaulo Zanoni false)) 1800fc2c807bSVille Syrjälä DRM_ERROR("PCH transcoder A FIFO underrun\n"); 18018664281bSPaulo Zanoni 18028664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN) 18038664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B, 18048664281bSPaulo Zanoni false)) 1805fc2c807bSVille Syrjälä DRM_ERROR("PCH transcoder B FIFO underrun\n"); 18068664281bSPaulo Zanoni 18078664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN) 18088664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C, 18098664281bSPaulo Zanoni false)) 1810fc2c807bSVille Syrjälä DRM_ERROR("PCH transcoder C FIFO underrun\n"); 18118664281bSPaulo Zanoni 18128664281bSPaulo Zanoni I915_WRITE(SERR_INT, serr_int); 1813776ad806SJesse Barnes } 1814776ad806SJesse Barnes 181523e81d69SAdam Jackson static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir) 181623e81d69SAdam Jackson { 18172d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 181823e81d69SAdam Jackson int pipe; 1819b543fb04SEgbert Eich u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT; 182023e81d69SAdam Jackson 182110a504deSDaniel Vetter intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt); 182291d131d2SDaniel Vetter 1823cfc33bf7SVille Syrjälä if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) { 1824cfc33bf7SVille Syrjälä int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >> 182523e81d69SAdam Jackson SDE_AUDIO_POWER_SHIFT_CPT); 1826cfc33bf7SVille Syrjälä DRM_DEBUG_DRIVER("PCH audio power change on port %c\n", 1827cfc33bf7SVille Syrjälä port_name(port)); 1828cfc33bf7SVille Syrjälä } 182923e81d69SAdam Jackson 183023e81d69SAdam Jackson if (pch_iir & SDE_AUX_MASK_CPT) 1831ce99c256SDaniel Vetter dp_aux_irq_handler(dev); 183223e81d69SAdam Jackson 183323e81d69SAdam Jackson if (pch_iir & SDE_GMBUS_CPT) 1834515ac2bbSDaniel Vetter gmbus_irq_handler(dev); 183523e81d69SAdam Jackson 183623e81d69SAdam Jackson if (pch_iir & SDE_AUDIO_CP_REQ_CPT) 183723e81d69SAdam Jackson DRM_DEBUG_DRIVER("Audio CP request interrupt\n"); 183823e81d69SAdam Jackson 183923e81d69SAdam Jackson if (pch_iir & SDE_AUDIO_CP_CHG_CPT) 184023e81d69SAdam Jackson DRM_DEBUG_DRIVER("Audio CP change interrupt\n"); 184123e81d69SAdam Jackson 184223e81d69SAdam Jackson if (pch_iir & SDE_FDI_MASK_CPT) 184323e81d69SAdam Jackson for_each_pipe(pipe) 184423e81d69SAdam Jackson DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", 184523e81d69SAdam Jackson pipe_name(pipe), 184623e81d69SAdam Jackson I915_READ(FDI_RX_IIR(pipe))); 18478664281bSPaulo Zanoni 18488664281bSPaulo Zanoni if (pch_iir & SDE_ERROR_CPT) 18498664281bSPaulo Zanoni cpt_serr_int_handler(dev); 185023e81d69SAdam Jackson } 185123e81d69SAdam Jackson 1852c008bc6eSPaulo Zanoni static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir) 1853c008bc6eSPaulo Zanoni { 1854c008bc6eSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 185540da17c2SDaniel Vetter enum pipe pipe; 1856c008bc6eSPaulo Zanoni 1857c008bc6eSPaulo Zanoni if (de_iir & DE_AUX_CHANNEL_A) 1858c008bc6eSPaulo Zanoni dp_aux_irq_handler(dev); 1859c008bc6eSPaulo Zanoni 1860c008bc6eSPaulo Zanoni if (de_iir & DE_GSE) 1861c008bc6eSPaulo Zanoni intel_opregion_asle_intr(dev); 1862c008bc6eSPaulo Zanoni 1863c008bc6eSPaulo Zanoni if (de_iir & DE_POISON) 1864c008bc6eSPaulo Zanoni DRM_ERROR("Poison interrupt\n"); 1865c008bc6eSPaulo Zanoni 186640da17c2SDaniel Vetter for_each_pipe(pipe) { 186740da17c2SDaniel Vetter if (de_iir & DE_PIPE_VBLANK(pipe)) 186840da17c2SDaniel Vetter drm_handle_vblank(dev, pipe); 1869c008bc6eSPaulo Zanoni 187040da17c2SDaniel Vetter if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe)) 187140da17c2SDaniel Vetter if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, false)) 1872fc2c807bSVille Syrjälä DRM_ERROR("Pipe %c FIFO underrun\n", 187340da17c2SDaniel Vetter pipe_name(pipe)); 1874c008bc6eSPaulo Zanoni 187540da17c2SDaniel Vetter if (de_iir & DE_PIPE_CRC_DONE(pipe)) 187640da17c2SDaniel Vetter i9xx_pipe_crc_irq_handler(dev, pipe); 18775b3a856bSDaniel Vetter 187840da17c2SDaniel Vetter /* plane/pipes map 1:1 on ilk+ */ 187940da17c2SDaniel Vetter if (de_iir & DE_PLANE_FLIP_DONE(pipe)) { 188040da17c2SDaniel Vetter intel_prepare_page_flip(dev, pipe); 188140da17c2SDaniel Vetter intel_finish_page_flip_plane(dev, pipe); 1882c008bc6eSPaulo Zanoni } 1883c008bc6eSPaulo Zanoni } 1884c008bc6eSPaulo Zanoni 1885c008bc6eSPaulo Zanoni /* check event from PCH */ 1886c008bc6eSPaulo Zanoni if (de_iir & DE_PCH_EVENT) { 1887c008bc6eSPaulo Zanoni u32 pch_iir = I915_READ(SDEIIR); 1888c008bc6eSPaulo Zanoni 1889c008bc6eSPaulo Zanoni if (HAS_PCH_CPT(dev)) 1890c008bc6eSPaulo Zanoni cpt_irq_handler(dev, pch_iir); 1891c008bc6eSPaulo Zanoni else 1892c008bc6eSPaulo Zanoni ibx_irq_handler(dev, pch_iir); 1893c008bc6eSPaulo Zanoni 1894c008bc6eSPaulo Zanoni /* should clear PCH hotplug event before clear CPU irq */ 1895c008bc6eSPaulo Zanoni I915_WRITE(SDEIIR, pch_iir); 1896c008bc6eSPaulo Zanoni } 1897c008bc6eSPaulo Zanoni 1898c008bc6eSPaulo Zanoni if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT) 1899c008bc6eSPaulo Zanoni ironlake_rps_change_irq_handler(dev); 1900c008bc6eSPaulo Zanoni } 1901c008bc6eSPaulo Zanoni 19029719fb98SPaulo Zanoni static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir) 19039719fb98SPaulo Zanoni { 19049719fb98SPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 190507d27e20SDamien Lespiau enum pipe pipe; 19069719fb98SPaulo Zanoni 19079719fb98SPaulo Zanoni if (de_iir & DE_ERR_INT_IVB) 19089719fb98SPaulo Zanoni ivb_err_int_handler(dev); 19099719fb98SPaulo Zanoni 19109719fb98SPaulo Zanoni if (de_iir & DE_AUX_CHANNEL_A_IVB) 19119719fb98SPaulo Zanoni dp_aux_irq_handler(dev); 19129719fb98SPaulo Zanoni 19139719fb98SPaulo Zanoni if (de_iir & DE_GSE_IVB) 19149719fb98SPaulo Zanoni intel_opregion_asle_intr(dev); 19159719fb98SPaulo Zanoni 191607d27e20SDamien Lespiau for_each_pipe(pipe) { 191707d27e20SDamien Lespiau if (de_iir & (DE_PIPE_VBLANK_IVB(pipe))) 191807d27e20SDamien Lespiau drm_handle_vblank(dev, pipe); 191940da17c2SDaniel Vetter 192040da17c2SDaniel Vetter /* plane/pipes map 1:1 on ilk+ */ 192107d27e20SDamien Lespiau if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) { 192207d27e20SDamien Lespiau intel_prepare_page_flip(dev, pipe); 192307d27e20SDamien Lespiau intel_finish_page_flip_plane(dev, pipe); 19249719fb98SPaulo Zanoni } 19259719fb98SPaulo Zanoni } 19269719fb98SPaulo Zanoni 19279719fb98SPaulo Zanoni /* check event from PCH */ 19289719fb98SPaulo Zanoni if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) { 19299719fb98SPaulo Zanoni u32 pch_iir = I915_READ(SDEIIR); 19309719fb98SPaulo Zanoni 19319719fb98SPaulo Zanoni cpt_irq_handler(dev, pch_iir); 19329719fb98SPaulo Zanoni 19339719fb98SPaulo Zanoni /* clear PCH hotplug event before clear CPU irq */ 19349719fb98SPaulo Zanoni I915_WRITE(SDEIIR, pch_iir); 19359719fb98SPaulo Zanoni } 19369719fb98SPaulo Zanoni } 19379719fb98SPaulo Zanoni 1938f1af8fc1SPaulo Zanoni static irqreturn_t ironlake_irq_handler(int irq, void *arg) 1939b1f14ad0SJesse Barnes { 1940b1f14ad0SJesse Barnes struct drm_device *dev = (struct drm_device *) arg; 19412d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 1942f1af8fc1SPaulo Zanoni u32 de_iir, gt_iir, de_ier, sde_ier = 0; 19430e43406bSChris Wilson irqreturn_t ret = IRQ_NONE; 1944b1f14ad0SJesse Barnes 19458664281bSPaulo Zanoni /* We get interrupts on unclaimed registers, so check for this before we 19468664281bSPaulo Zanoni * do any I915_{READ,WRITE}. */ 1947907b28c5SChris Wilson intel_uncore_check_errors(dev); 19488664281bSPaulo Zanoni 1949b1f14ad0SJesse Barnes /* disable master interrupt before clearing iir */ 1950b1f14ad0SJesse Barnes de_ier = I915_READ(DEIER); 1951b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL); 195223a78516SPaulo Zanoni POSTING_READ(DEIER); 19530e43406bSChris Wilson 195444498aeaSPaulo Zanoni /* Disable south interrupts. We'll only write to SDEIIR once, so further 195544498aeaSPaulo Zanoni * interrupts will will be stored on its back queue, and then we'll be 195644498aeaSPaulo Zanoni * able to process them after we restore SDEIER (as soon as we restore 195744498aeaSPaulo Zanoni * it, we'll get an interrupt if SDEIIR still has something to process 195844498aeaSPaulo Zanoni * due to its back queue). */ 1959ab5c608bSBen Widawsky if (!HAS_PCH_NOP(dev)) { 196044498aeaSPaulo Zanoni sde_ier = I915_READ(SDEIER); 196144498aeaSPaulo Zanoni I915_WRITE(SDEIER, 0); 196244498aeaSPaulo Zanoni POSTING_READ(SDEIER); 1963ab5c608bSBen Widawsky } 196444498aeaSPaulo Zanoni 19650e43406bSChris Wilson gt_iir = I915_READ(GTIIR); 19660e43406bSChris Wilson if (gt_iir) { 1967d8fc8a47SPaulo Zanoni if (INTEL_INFO(dev)->gen >= 6) 19680e43406bSChris Wilson snb_gt_irq_handler(dev, dev_priv, gt_iir); 1969d8fc8a47SPaulo Zanoni else 1970d8fc8a47SPaulo Zanoni ilk_gt_irq_handler(dev, dev_priv, gt_iir); 19710e43406bSChris Wilson I915_WRITE(GTIIR, gt_iir); 19720e43406bSChris Wilson ret = IRQ_HANDLED; 19730e43406bSChris Wilson } 1974b1f14ad0SJesse Barnes 1975b1f14ad0SJesse Barnes de_iir = I915_READ(DEIIR); 19760e43406bSChris Wilson if (de_iir) { 1977f1af8fc1SPaulo Zanoni if (INTEL_INFO(dev)->gen >= 7) 19789719fb98SPaulo Zanoni ivb_display_irq_handler(dev, de_iir); 1979f1af8fc1SPaulo Zanoni else 1980f1af8fc1SPaulo Zanoni ilk_display_irq_handler(dev, de_iir); 19810e43406bSChris Wilson I915_WRITE(DEIIR, de_iir); 19820e43406bSChris Wilson ret = IRQ_HANDLED; 19830e43406bSChris Wilson } 19840e43406bSChris Wilson 1985f1af8fc1SPaulo Zanoni if (INTEL_INFO(dev)->gen >= 6) { 1986f1af8fc1SPaulo Zanoni u32 pm_iir = I915_READ(GEN6_PMIIR); 19870e43406bSChris Wilson if (pm_iir) { 1988d0ecd7e2SDaniel Vetter gen6_rps_irq_handler(dev_priv, pm_iir); 1989b1f14ad0SJesse Barnes I915_WRITE(GEN6_PMIIR, pm_iir); 19900e43406bSChris Wilson ret = IRQ_HANDLED; 19910e43406bSChris Wilson } 1992f1af8fc1SPaulo Zanoni } 1993b1f14ad0SJesse Barnes 1994b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier); 1995b1f14ad0SJesse Barnes POSTING_READ(DEIER); 1996ab5c608bSBen Widawsky if (!HAS_PCH_NOP(dev)) { 199744498aeaSPaulo Zanoni I915_WRITE(SDEIER, sde_ier); 199844498aeaSPaulo Zanoni POSTING_READ(SDEIER); 1999ab5c608bSBen Widawsky } 2000b1f14ad0SJesse Barnes 2001b1f14ad0SJesse Barnes return ret; 2002b1f14ad0SJesse Barnes } 2003b1f14ad0SJesse Barnes 2004abd58f01SBen Widawsky static irqreturn_t gen8_irq_handler(int irq, void *arg) 2005abd58f01SBen Widawsky { 2006abd58f01SBen Widawsky struct drm_device *dev = arg; 2007abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 2008abd58f01SBen Widawsky u32 master_ctl; 2009abd58f01SBen Widawsky irqreturn_t ret = IRQ_NONE; 2010abd58f01SBen Widawsky uint32_t tmp = 0; 2011c42664ccSDaniel Vetter enum pipe pipe; 2012abd58f01SBen Widawsky 2013abd58f01SBen Widawsky master_ctl = I915_READ(GEN8_MASTER_IRQ); 2014abd58f01SBen Widawsky master_ctl &= ~GEN8_MASTER_IRQ_CONTROL; 2015abd58f01SBen Widawsky if (!master_ctl) 2016abd58f01SBen Widawsky return IRQ_NONE; 2017abd58f01SBen Widawsky 2018abd58f01SBen Widawsky I915_WRITE(GEN8_MASTER_IRQ, 0); 2019abd58f01SBen Widawsky POSTING_READ(GEN8_MASTER_IRQ); 2020abd58f01SBen Widawsky 2021abd58f01SBen Widawsky ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl); 2022abd58f01SBen Widawsky 2023abd58f01SBen Widawsky if (master_ctl & GEN8_DE_MISC_IRQ) { 2024abd58f01SBen Widawsky tmp = I915_READ(GEN8_DE_MISC_IIR); 2025abd58f01SBen Widawsky if (tmp & GEN8_DE_MISC_GSE) 2026abd58f01SBen Widawsky intel_opregion_asle_intr(dev); 2027abd58f01SBen Widawsky else if (tmp) 2028abd58f01SBen Widawsky DRM_ERROR("Unexpected DE Misc interrupt\n"); 2029abd58f01SBen Widawsky else 2030abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (DE MISC)!\n"); 2031abd58f01SBen Widawsky 2032abd58f01SBen Widawsky if (tmp) { 2033abd58f01SBen Widawsky I915_WRITE(GEN8_DE_MISC_IIR, tmp); 2034abd58f01SBen Widawsky ret = IRQ_HANDLED; 2035abd58f01SBen Widawsky } 2036abd58f01SBen Widawsky } 2037abd58f01SBen Widawsky 20386d766f02SDaniel Vetter if (master_ctl & GEN8_DE_PORT_IRQ) { 20396d766f02SDaniel Vetter tmp = I915_READ(GEN8_DE_PORT_IIR); 20406d766f02SDaniel Vetter if (tmp & GEN8_AUX_CHANNEL_A) 20416d766f02SDaniel Vetter dp_aux_irq_handler(dev); 20426d766f02SDaniel Vetter else if (tmp) 20436d766f02SDaniel Vetter DRM_ERROR("Unexpected DE Port interrupt\n"); 20446d766f02SDaniel Vetter else 20456d766f02SDaniel Vetter DRM_ERROR("The master control interrupt lied (DE PORT)!\n"); 20466d766f02SDaniel Vetter 20476d766f02SDaniel Vetter if (tmp) { 20486d766f02SDaniel Vetter I915_WRITE(GEN8_DE_PORT_IIR, tmp); 20496d766f02SDaniel Vetter ret = IRQ_HANDLED; 20506d766f02SDaniel Vetter } 20516d766f02SDaniel Vetter } 20526d766f02SDaniel Vetter 2053abd58f01SBen Widawsky for_each_pipe(pipe) { 2054abd58f01SBen Widawsky uint32_t pipe_iir; 2055abd58f01SBen Widawsky 2056c42664ccSDaniel Vetter if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe))) 2057c42664ccSDaniel Vetter continue; 2058c42664ccSDaniel Vetter 2059abd58f01SBen Widawsky pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe)); 2060abd58f01SBen Widawsky if (pipe_iir & GEN8_PIPE_VBLANK) 2061abd58f01SBen Widawsky drm_handle_vblank(dev, pipe); 2062abd58f01SBen Widawsky 2063abd58f01SBen Widawsky if (pipe_iir & GEN8_PIPE_FLIP_DONE) { 2064abd58f01SBen Widawsky intel_prepare_page_flip(dev, pipe); 2065abd58f01SBen Widawsky intel_finish_page_flip_plane(dev, pipe); 2066abd58f01SBen Widawsky } 2067abd58f01SBen Widawsky 20680fbe7870SDaniel Vetter if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE) 20690fbe7870SDaniel Vetter hsw_pipe_crc_irq_handler(dev, pipe); 20700fbe7870SDaniel Vetter 207138d83c96SDaniel Vetter if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN) { 207238d83c96SDaniel Vetter if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, 207338d83c96SDaniel Vetter false)) 2074fc2c807bSVille Syrjälä DRM_ERROR("Pipe %c FIFO underrun\n", 207538d83c96SDaniel Vetter pipe_name(pipe)); 207638d83c96SDaniel Vetter } 207738d83c96SDaniel Vetter 207830100f2bSDaniel Vetter if (pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS) { 207930100f2bSDaniel Vetter DRM_ERROR("Fault errors on pipe %c\n: 0x%08x", 208030100f2bSDaniel Vetter pipe_name(pipe), 208130100f2bSDaniel Vetter pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS); 208230100f2bSDaniel Vetter } 2083abd58f01SBen Widawsky 2084abd58f01SBen Widawsky if (pipe_iir) { 2085abd58f01SBen Widawsky ret = IRQ_HANDLED; 2086abd58f01SBen Widawsky I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir); 2087c42664ccSDaniel Vetter } else 2088abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (DE PIPE)!\n"); 2089abd58f01SBen Widawsky } 2090abd58f01SBen Widawsky 209192d03a80SDaniel Vetter if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) { 209292d03a80SDaniel Vetter /* 209392d03a80SDaniel Vetter * FIXME(BDW): Assume for now that the new interrupt handling 209492d03a80SDaniel Vetter * scheme also closed the SDE interrupt handling race we've seen 209592d03a80SDaniel Vetter * on older pch-split platforms. But this needs testing. 209692d03a80SDaniel Vetter */ 209792d03a80SDaniel Vetter u32 pch_iir = I915_READ(SDEIIR); 209892d03a80SDaniel Vetter 209992d03a80SDaniel Vetter cpt_irq_handler(dev, pch_iir); 210092d03a80SDaniel Vetter 210192d03a80SDaniel Vetter if (pch_iir) { 210292d03a80SDaniel Vetter I915_WRITE(SDEIIR, pch_iir); 210392d03a80SDaniel Vetter ret = IRQ_HANDLED; 210492d03a80SDaniel Vetter } 210592d03a80SDaniel Vetter } 210692d03a80SDaniel Vetter 2107abd58f01SBen Widawsky I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); 2108abd58f01SBen Widawsky POSTING_READ(GEN8_MASTER_IRQ); 2109abd58f01SBen Widawsky 2110abd58f01SBen Widawsky return ret; 2111abd58f01SBen Widawsky } 2112abd58f01SBen Widawsky 211317e1df07SDaniel Vetter static void i915_error_wake_up(struct drm_i915_private *dev_priv, 211417e1df07SDaniel Vetter bool reset_completed) 211517e1df07SDaniel Vetter { 211617e1df07SDaniel Vetter struct intel_ring_buffer *ring; 211717e1df07SDaniel Vetter int i; 211817e1df07SDaniel Vetter 211917e1df07SDaniel Vetter /* 212017e1df07SDaniel Vetter * Notify all waiters for GPU completion events that reset state has 212117e1df07SDaniel Vetter * been changed, and that they need to restart their wait after 212217e1df07SDaniel Vetter * checking for potential errors (and bail out to drop locks if there is 212317e1df07SDaniel Vetter * a gpu reset pending so that i915_error_work_func can acquire them). 212417e1df07SDaniel Vetter */ 212517e1df07SDaniel Vetter 212617e1df07SDaniel Vetter /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */ 212717e1df07SDaniel Vetter for_each_ring(ring, dev_priv, i) 212817e1df07SDaniel Vetter wake_up_all(&ring->irq_queue); 212917e1df07SDaniel Vetter 213017e1df07SDaniel Vetter /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */ 213117e1df07SDaniel Vetter wake_up_all(&dev_priv->pending_flip_queue); 213217e1df07SDaniel Vetter 213317e1df07SDaniel Vetter /* 213417e1df07SDaniel Vetter * Signal tasks blocked in i915_gem_wait_for_error that the pending 213517e1df07SDaniel Vetter * reset state is cleared. 213617e1df07SDaniel Vetter */ 213717e1df07SDaniel Vetter if (reset_completed) 213817e1df07SDaniel Vetter wake_up_all(&dev_priv->gpu_error.reset_queue); 213917e1df07SDaniel Vetter } 214017e1df07SDaniel Vetter 21418a905236SJesse Barnes /** 21428a905236SJesse Barnes * i915_error_work_func - do process context error handling work 21438a905236SJesse Barnes * @work: work struct 21448a905236SJesse Barnes * 21458a905236SJesse Barnes * Fire an error uevent so userspace can see that a hang or error 21468a905236SJesse Barnes * was detected. 21478a905236SJesse Barnes */ 21488a905236SJesse Barnes static void i915_error_work_func(struct work_struct *work) 21498a905236SJesse Barnes { 21501f83fee0SDaniel Vetter struct i915_gpu_error *error = container_of(work, struct i915_gpu_error, 21511f83fee0SDaniel Vetter work); 21522d1013ddSJani Nikula struct drm_i915_private *dev_priv = 21532d1013ddSJani Nikula container_of(error, struct drm_i915_private, gpu_error); 21548a905236SJesse Barnes struct drm_device *dev = dev_priv->dev; 2155cce723edSBen Widawsky char *error_event[] = { I915_ERROR_UEVENT "=1", NULL }; 2156cce723edSBen Widawsky char *reset_event[] = { I915_RESET_UEVENT "=1", NULL }; 2157cce723edSBen Widawsky char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL }; 215817e1df07SDaniel Vetter int ret; 21598a905236SJesse Barnes 21605bdebb18SDave Airlie kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event); 21618a905236SJesse Barnes 21627db0ba24SDaniel Vetter /* 21637db0ba24SDaniel Vetter * Note that there's only one work item which does gpu resets, so we 21647db0ba24SDaniel Vetter * need not worry about concurrent gpu resets potentially incrementing 21657db0ba24SDaniel Vetter * error->reset_counter twice. We only need to take care of another 21667db0ba24SDaniel Vetter * racing irq/hangcheck declaring the gpu dead for a second time. A 21677db0ba24SDaniel Vetter * quick check for that is good enough: schedule_work ensures the 21687db0ba24SDaniel Vetter * correct ordering between hang detection and this work item, and since 21697db0ba24SDaniel Vetter * the reset in-progress bit is only ever set by code outside of this 21707db0ba24SDaniel Vetter * work we don't need to worry about any other races. 21717db0ba24SDaniel Vetter */ 21727db0ba24SDaniel Vetter if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) { 217344d98a61SZhao Yakui DRM_DEBUG_DRIVER("resetting chip\n"); 21745bdebb18SDave Airlie kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, 21757db0ba24SDaniel Vetter reset_event); 21761f83fee0SDaniel Vetter 217717e1df07SDaniel Vetter /* 217817e1df07SDaniel Vetter * All state reset _must_ be completed before we update the 217917e1df07SDaniel Vetter * reset counter, for otherwise waiters might miss the reset 218017e1df07SDaniel Vetter * pending state and not properly drop locks, resulting in 218117e1df07SDaniel Vetter * deadlocks with the reset work. 218217e1df07SDaniel Vetter */ 2183f69061beSDaniel Vetter ret = i915_reset(dev); 2184f69061beSDaniel Vetter 218517e1df07SDaniel Vetter intel_display_handle_reset(dev); 218617e1df07SDaniel Vetter 2187f69061beSDaniel Vetter if (ret == 0) { 2188f69061beSDaniel Vetter /* 2189f69061beSDaniel Vetter * After all the gem state is reset, increment the reset 2190f69061beSDaniel Vetter * counter and wake up everyone waiting for the reset to 2191f69061beSDaniel Vetter * complete. 2192f69061beSDaniel Vetter * 2193f69061beSDaniel Vetter * Since unlock operations are a one-sided barrier only, 2194f69061beSDaniel Vetter * we need to insert a barrier here to order any seqno 2195f69061beSDaniel Vetter * updates before 2196f69061beSDaniel Vetter * the counter increment. 2197f69061beSDaniel Vetter */ 2198f69061beSDaniel Vetter smp_mb__before_atomic_inc(); 2199f69061beSDaniel Vetter atomic_inc(&dev_priv->gpu_error.reset_counter); 2200f69061beSDaniel Vetter 22015bdebb18SDave Airlie kobject_uevent_env(&dev->primary->kdev->kobj, 2202f69061beSDaniel Vetter KOBJ_CHANGE, reset_done_event); 22031f83fee0SDaniel Vetter } else { 22042ac0f450SMika Kuoppala atomic_set_mask(I915_WEDGED, &error->reset_counter); 2205f316a42cSBen Gamari } 22061f83fee0SDaniel Vetter 220717e1df07SDaniel Vetter /* 220817e1df07SDaniel Vetter * Note: The wake_up also serves as a memory barrier so that 220917e1df07SDaniel Vetter * waiters see the update value of the reset counter atomic_t. 221017e1df07SDaniel Vetter */ 221117e1df07SDaniel Vetter i915_error_wake_up(dev_priv, true); 2212f316a42cSBen Gamari } 22138a905236SJesse Barnes } 22148a905236SJesse Barnes 221535aed2e6SChris Wilson static void i915_report_and_clear_eir(struct drm_device *dev) 2216c0e09200SDave Airlie { 22178a905236SJesse Barnes struct drm_i915_private *dev_priv = dev->dev_private; 2218bd9854f9SBen Widawsky uint32_t instdone[I915_NUM_INSTDONE_REG]; 221963eeaf38SJesse Barnes u32 eir = I915_READ(EIR); 2220050ee91fSBen Widawsky int pipe, i; 222163eeaf38SJesse Barnes 222235aed2e6SChris Wilson if (!eir) 222335aed2e6SChris Wilson return; 222463eeaf38SJesse Barnes 2225a70491ccSJoe Perches pr_err("render error detected, EIR: 0x%08x\n", eir); 22268a905236SJesse Barnes 2227bd9854f9SBen Widawsky i915_get_extra_instdone(dev, instdone); 2228bd9854f9SBen Widawsky 22298a905236SJesse Barnes if (IS_G4X(dev)) { 22308a905236SJesse Barnes if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) { 22318a905236SJesse Barnes u32 ipeir = I915_READ(IPEIR_I965); 22328a905236SJesse Barnes 2233a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); 2234a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); 2235050ee91fSBen Widawsky for (i = 0; i < ARRAY_SIZE(instdone); i++) 2236050ee91fSBen Widawsky pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]); 2237a70491ccSJoe Perches pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); 2238a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); 22398a905236SJesse Barnes I915_WRITE(IPEIR_I965, ipeir); 22403143a2bfSChris Wilson POSTING_READ(IPEIR_I965); 22418a905236SJesse Barnes } 22428a905236SJesse Barnes if (eir & GM45_ERROR_PAGE_TABLE) { 22438a905236SJesse Barnes u32 pgtbl_err = I915_READ(PGTBL_ER); 2244a70491ccSJoe Perches pr_err("page table error\n"); 2245a70491ccSJoe Perches pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); 22468a905236SJesse Barnes I915_WRITE(PGTBL_ER, pgtbl_err); 22473143a2bfSChris Wilson POSTING_READ(PGTBL_ER); 22488a905236SJesse Barnes } 22498a905236SJesse Barnes } 22508a905236SJesse Barnes 2251a6c45cf0SChris Wilson if (!IS_GEN2(dev)) { 225263eeaf38SJesse Barnes if (eir & I915_ERROR_PAGE_TABLE) { 225363eeaf38SJesse Barnes u32 pgtbl_err = I915_READ(PGTBL_ER); 2254a70491ccSJoe Perches pr_err("page table error\n"); 2255a70491ccSJoe Perches pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); 225663eeaf38SJesse Barnes I915_WRITE(PGTBL_ER, pgtbl_err); 22573143a2bfSChris Wilson POSTING_READ(PGTBL_ER); 225863eeaf38SJesse Barnes } 22598a905236SJesse Barnes } 22608a905236SJesse Barnes 226163eeaf38SJesse Barnes if (eir & I915_ERROR_MEMORY_REFRESH) { 2262a70491ccSJoe Perches pr_err("memory refresh error:\n"); 22639db4a9c7SJesse Barnes for_each_pipe(pipe) 2264a70491ccSJoe Perches pr_err("pipe %c stat: 0x%08x\n", 22659db4a9c7SJesse Barnes pipe_name(pipe), I915_READ(PIPESTAT(pipe))); 226663eeaf38SJesse Barnes /* pipestat has already been acked */ 226763eeaf38SJesse Barnes } 226863eeaf38SJesse Barnes if (eir & I915_ERROR_INSTRUCTION) { 2269a70491ccSJoe Perches pr_err("instruction error\n"); 2270a70491ccSJoe Perches pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM)); 2271050ee91fSBen Widawsky for (i = 0; i < ARRAY_SIZE(instdone); i++) 2272050ee91fSBen Widawsky pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]); 2273a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen < 4) { 227463eeaf38SJesse Barnes u32 ipeir = I915_READ(IPEIR); 227563eeaf38SJesse Barnes 2276a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR)); 2277a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR)); 2278a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD)); 227963eeaf38SJesse Barnes I915_WRITE(IPEIR, ipeir); 22803143a2bfSChris Wilson POSTING_READ(IPEIR); 228163eeaf38SJesse Barnes } else { 228263eeaf38SJesse Barnes u32 ipeir = I915_READ(IPEIR_I965); 228363eeaf38SJesse Barnes 2284a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); 2285a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); 2286a70491ccSJoe Perches pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); 2287a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); 228863eeaf38SJesse Barnes I915_WRITE(IPEIR_I965, ipeir); 22893143a2bfSChris Wilson POSTING_READ(IPEIR_I965); 229063eeaf38SJesse Barnes } 229163eeaf38SJesse Barnes } 229263eeaf38SJesse Barnes 229363eeaf38SJesse Barnes I915_WRITE(EIR, eir); 22943143a2bfSChris Wilson POSTING_READ(EIR); 229563eeaf38SJesse Barnes eir = I915_READ(EIR); 229663eeaf38SJesse Barnes if (eir) { 229763eeaf38SJesse Barnes /* 229863eeaf38SJesse Barnes * some errors might have become stuck, 229963eeaf38SJesse Barnes * mask them. 230063eeaf38SJesse Barnes */ 230163eeaf38SJesse Barnes DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir); 230263eeaf38SJesse Barnes I915_WRITE(EMR, I915_READ(EMR) | eir); 230363eeaf38SJesse Barnes I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 230463eeaf38SJesse Barnes } 230535aed2e6SChris Wilson } 230635aed2e6SChris Wilson 230735aed2e6SChris Wilson /** 230835aed2e6SChris Wilson * i915_handle_error - handle an error interrupt 230935aed2e6SChris Wilson * @dev: drm device 231035aed2e6SChris Wilson * 231135aed2e6SChris Wilson * Do some basic checking of regsiter state at error interrupt time and 231235aed2e6SChris Wilson * dump it to the syslog. Also call i915_capture_error_state() to make 231335aed2e6SChris Wilson * sure we get a record and make it available in debugfs. Fire a uevent 231435aed2e6SChris Wilson * so userspace knows something bad happened (should trigger collection 231535aed2e6SChris Wilson * of a ring dump etc.). 231635aed2e6SChris Wilson */ 231758174462SMika Kuoppala void i915_handle_error(struct drm_device *dev, bool wedged, 231858174462SMika Kuoppala const char *fmt, ...) 231935aed2e6SChris Wilson { 232035aed2e6SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 232158174462SMika Kuoppala va_list args; 232258174462SMika Kuoppala char error_msg[80]; 232335aed2e6SChris Wilson 232458174462SMika Kuoppala va_start(args, fmt); 232558174462SMika Kuoppala vscnprintf(error_msg, sizeof(error_msg), fmt, args); 232658174462SMika Kuoppala va_end(args); 232758174462SMika Kuoppala 232858174462SMika Kuoppala i915_capture_error_state(dev, wedged, error_msg); 232935aed2e6SChris Wilson i915_report_and_clear_eir(dev); 23308a905236SJesse Barnes 2331ba1234d1SBen Gamari if (wedged) { 2332f69061beSDaniel Vetter atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG, 2333f69061beSDaniel Vetter &dev_priv->gpu_error.reset_counter); 2334ba1234d1SBen Gamari 233511ed50ecSBen Gamari /* 233617e1df07SDaniel Vetter * Wakeup waiting processes so that the reset work function 233717e1df07SDaniel Vetter * i915_error_work_func doesn't deadlock trying to grab various 233817e1df07SDaniel Vetter * locks. By bumping the reset counter first, the woken 233917e1df07SDaniel Vetter * processes will see a reset in progress and back off, 234017e1df07SDaniel Vetter * releasing their locks and then wait for the reset completion. 234117e1df07SDaniel Vetter * We must do this for _all_ gpu waiters that might hold locks 234217e1df07SDaniel Vetter * that the reset work needs to acquire. 234317e1df07SDaniel Vetter * 234417e1df07SDaniel Vetter * Note: The wake_up serves as the required memory barrier to 234517e1df07SDaniel Vetter * ensure that the waiters see the updated value of the reset 234617e1df07SDaniel Vetter * counter atomic_t. 234711ed50ecSBen Gamari */ 234817e1df07SDaniel Vetter i915_error_wake_up(dev_priv, false); 234911ed50ecSBen Gamari } 235011ed50ecSBen Gamari 2351122f46baSDaniel Vetter /* 2352122f46baSDaniel Vetter * Our reset work can grab modeset locks (since it needs to reset the 2353122f46baSDaniel Vetter * state of outstanding pagelips). Hence it must not be run on our own 2354122f46baSDaniel Vetter * dev-priv->wq work queue for otherwise the flush_work in the pageflip 2355122f46baSDaniel Vetter * code will deadlock. 2356122f46baSDaniel Vetter */ 2357122f46baSDaniel Vetter schedule_work(&dev_priv->gpu_error.work); 23588a905236SJesse Barnes } 23598a905236SJesse Barnes 236021ad8330SVille Syrjälä static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe) 23614e5359cdSSimon Farnsworth { 23622d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 23634e5359cdSSimon Farnsworth struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 23644e5359cdSSimon Farnsworth struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 236505394f39SChris Wilson struct drm_i915_gem_object *obj; 23664e5359cdSSimon Farnsworth struct intel_unpin_work *work; 23674e5359cdSSimon Farnsworth unsigned long flags; 23684e5359cdSSimon Farnsworth bool stall_detected; 23694e5359cdSSimon Farnsworth 23704e5359cdSSimon Farnsworth /* Ignore early vblank irqs */ 23714e5359cdSSimon Farnsworth if (intel_crtc == NULL) 23724e5359cdSSimon Farnsworth return; 23734e5359cdSSimon Farnsworth 23744e5359cdSSimon Farnsworth spin_lock_irqsave(&dev->event_lock, flags); 23754e5359cdSSimon Farnsworth work = intel_crtc->unpin_work; 23764e5359cdSSimon Farnsworth 2377e7d841caSChris Wilson if (work == NULL || 2378e7d841caSChris Wilson atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE || 2379e7d841caSChris Wilson !work->enable_stall_check) { 23804e5359cdSSimon Farnsworth /* Either the pending flip IRQ arrived, or we're too early. Don't check */ 23814e5359cdSSimon Farnsworth spin_unlock_irqrestore(&dev->event_lock, flags); 23824e5359cdSSimon Farnsworth return; 23834e5359cdSSimon Farnsworth } 23844e5359cdSSimon Farnsworth 23854e5359cdSSimon Farnsworth /* Potential stall - if we see that the flip has happened, assume a missed interrupt */ 238605394f39SChris Wilson obj = work->pending_flip_obj; 2387a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen >= 4) { 23889db4a9c7SJesse Barnes int dspsurf = DSPSURF(intel_crtc->plane); 2389446f2545SArmin Reese stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) == 2390f343c5f6SBen Widawsky i915_gem_obj_ggtt_offset(obj); 23914e5359cdSSimon Farnsworth } else { 23929db4a9c7SJesse Barnes int dspaddr = DSPADDR(intel_crtc->plane); 2393f343c5f6SBen Widawsky stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) + 239401f2c773SVille Syrjälä crtc->y * crtc->fb->pitches[0] + 23954e5359cdSSimon Farnsworth crtc->x * crtc->fb->bits_per_pixel/8); 23964e5359cdSSimon Farnsworth } 23974e5359cdSSimon Farnsworth 23984e5359cdSSimon Farnsworth spin_unlock_irqrestore(&dev->event_lock, flags); 23994e5359cdSSimon Farnsworth 24004e5359cdSSimon Farnsworth if (stall_detected) { 24014e5359cdSSimon Farnsworth DRM_DEBUG_DRIVER("Pageflip stall detected\n"); 24024e5359cdSSimon Farnsworth intel_prepare_page_flip(dev, intel_crtc->plane); 24034e5359cdSSimon Farnsworth } 24044e5359cdSSimon Farnsworth } 24054e5359cdSSimon Farnsworth 240642f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 240742f52ef8SKeith Packard * we use as a pipe index 240842f52ef8SKeith Packard */ 2409f71d4af4SJesse Barnes static int i915_enable_vblank(struct drm_device *dev, int pipe) 24100a3e67a4SJesse Barnes { 24112d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 2412e9d21d7fSKeith Packard unsigned long irqflags; 241371e0ffa5SJesse Barnes 24145eddb70bSChris Wilson if (!i915_pipe_enabled(dev, pipe)) 241571e0ffa5SJesse Barnes return -EINVAL; 24160a3e67a4SJesse Barnes 24171ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2418f796cf8fSJesse Barnes if (INTEL_INFO(dev)->gen >= 4) 24197c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 2420755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 24210a3e67a4SJesse Barnes else 24227c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 2423755e9019SImre Deak PIPE_VBLANK_INTERRUPT_STATUS); 24248692d00eSChris Wilson 24258692d00eSChris Wilson /* maintain vblank delivery even in deep C-states */ 24263d13ef2eSDamien Lespiau if (INTEL_INFO(dev)->gen == 3) 24276b26c86dSDaniel Vetter I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS)); 24281ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 24298692d00eSChris Wilson 24300a3e67a4SJesse Barnes return 0; 24310a3e67a4SJesse Barnes } 24320a3e67a4SJesse Barnes 2433f71d4af4SJesse Barnes static int ironlake_enable_vblank(struct drm_device *dev, int pipe) 2434f796cf8fSJesse Barnes { 24352d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 2436f796cf8fSJesse Barnes unsigned long irqflags; 2437b518421fSPaulo Zanoni uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) : 243840da17c2SDaniel Vetter DE_PIPE_VBLANK(pipe); 2439f796cf8fSJesse Barnes 2440f796cf8fSJesse Barnes if (!i915_pipe_enabled(dev, pipe)) 2441f796cf8fSJesse Barnes return -EINVAL; 2442f796cf8fSJesse Barnes 2443f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2444b518421fSPaulo Zanoni ironlake_enable_display_irq(dev_priv, bit); 2445b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2446b1f14ad0SJesse Barnes 2447b1f14ad0SJesse Barnes return 0; 2448b1f14ad0SJesse Barnes } 2449b1f14ad0SJesse Barnes 24507e231dbeSJesse Barnes static int valleyview_enable_vblank(struct drm_device *dev, int pipe) 24517e231dbeSJesse Barnes { 24522d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 24537e231dbeSJesse Barnes unsigned long irqflags; 24547e231dbeSJesse Barnes 24557e231dbeSJesse Barnes if (!i915_pipe_enabled(dev, pipe)) 24567e231dbeSJesse Barnes return -EINVAL; 24577e231dbeSJesse Barnes 24587e231dbeSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 245931acc7f5SJesse Barnes i915_enable_pipestat(dev_priv, pipe, 2460755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 24617e231dbeSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 24627e231dbeSJesse Barnes 24637e231dbeSJesse Barnes return 0; 24647e231dbeSJesse Barnes } 24657e231dbeSJesse Barnes 2466abd58f01SBen Widawsky static int gen8_enable_vblank(struct drm_device *dev, int pipe) 2467abd58f01SBen Widawsky { 2468abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 2469abd58f01SBen Widawsky unsigned long irqflags; 2470abd58f01SBen Widawsky 2471abd58f01SBen Widawsky if (!i915_pipe_enabled(dev, pipe)) 2472abd58f01SBen Widawsky return -EINVAL; 2473abd58f01SBen Widawsky 2474abd58f01SBen Widawsky spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 24757167d7c6SDaniel Vetter dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK; 24767167d7c6SDaniel Vetter I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]); 2477abd58f01SBen Widawsky POSTING_READ(GEN8_DE_PIPE_IMR(pipe)); 2478abd58f01SBen Widawsky spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2479abd58f01SBen Widawsky return 0; 2480abd58f01SBen Widawsky } 2481abd58f01SBen Widawsky 248242f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 248342f52ef8SKeith Packard * we use as a pipe index 248442f52ef8SKeith Packard */ 2485f71d4af4SJesse Barnes static void i915_disable_vblank(struct drm_device *dev, int pipe) 24860a3e67a4SJesse Barnes { 24872d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 2488e9d21d7fSKeith Packard unsigned long irqflags; 24890a3e67a4SJesse Barnes 24901ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 24913d13ef2eSDamien Lespiau if (INTEL_INFO(dev)->gen == 3) 24926b26c86dSDaniel Vetter I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS)); 24938692d00eSChris Wilson 24947c463586SKeith Packard i915_disable_pipestat(dev_priv, pipe, 2495755e9019SImre Deak PIPE_VBLANK_INTERRUPT_STATUS | 2496755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 24971ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 24980a3e67a4SJesse Barnes } 24990a3e67a4SJesse Barnes 2500f71d4af4SJesse Barnes static void ironlake_disable_vblank(struct drm_device *dev, int pipe) 2501f796cf8fSJesse Barnes { 25022d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 2503f796cf8fSJesse Barnes unsigned long irqflags; 2504b518421fSPaulo Zanoni uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) : 250540da17c2SDaniel Vetter DE_PIPE_VBLANK(pipe); 2506f796cf8fSJesse Barnes 2507f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2508b518421fSPaulo Zanoni ironlake_disable_display_irq(dev_priv, bit); 2509b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2510b1f14ad0SJesse Barnes } 2511b1f14ad0SJesse Barnes 25127e231dbeSJesse Barnes static void valleyview_disable_vblank(struct drm_device *dev, int pipe) 25137e231dbeSJesse Barnes { 25142d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 25157e231dbeSJesse Barnes unsigned long irqflags; 25167e231dbeSJesse Barnes 25177e231dbeSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 251831acc7f5SJesse Barnes i915_disable_pipestat(dev_priv, pipe, 2519755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 25207e231dbeSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 25217e231dbeSJesse Barnes } 25227e231dbeSJesse Barnes 2523abd58f01SBen Widawsky static void gen8_disable_vblank(struct drm_device *dev, int pipe) 2524abd58f01SBen Widawsky { 2525abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 2526abd58f01SBen Widawsky unsigned long irqflags; 2527abd58f01SBen Widawsky 2528abd58f01SBen Widawsky if (!i915_pipe_enabled(dev, pipe)) 2529abd58f01SBen Widawsky return; 2530abd58f01SBen Widawsky 2531abd58f01SBen Widawsky spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 25327167d7c6SDaniel Vetter dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK; 25337167d7c6SDaniel Vetter I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]); 2534abd58f01SBen Widawsky POSTING_READ(GEN8_DE_PIPE_IMR(pipe)); 2535abd58f01SBen Widawsky spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2536abd58f01SBen Widawsky } 2537abd58f01SBen Widawsky 2538893eead0SChris Wilson static u32 2539893eead0SChris Wilson ring_last_seqno(struct intel_ring_buffer *ring) 2540852835f3SZou Nan hai { 2541893eead0SChris Wilson return list_entry(ring->request_list.prev, 2542893eead0SChris Wilson struct drm_i915_gem_request, list)->seqno; 2543893eead0SChris Wilson } 2544893eead0SChris Wilson 25459107e9d2SChris Wilson static bool 25469107e9d2SChris Wilson ring_idle(struct intel_ring_buffer *ring, u32 seqno) 2547893eead0SChris Wilson { 25489107e9d2SChris Wilson return (list_empty(&ring->request_list) || 25499107e9d2SChris Wilson i915_seqno_passed(seqno, ring_last_seqno(ring))); 2550f65d9421SBen Gamari } 2551f65d9421SBen Gamari 2552a028c4b0SDaniel Vetter static bool 2553a028c4b0SDaniel Vetter ipehr_is_semaphore_wait(struct drm_device *dev, u32 ipehr) 2554a028c4b0SDaniel Vetter { 2555a028c4b0SDaniel Vetter if (INTEL_INFO(dev)->gen >= 8) { 2556a028c4b0SDaniel Vetter /* 2557a028c4b0SDaniel Vetter * FIXME: gen8 semaphore support - currently we don't emit 2558a028c4b0SDaniel Vetter * semaphores on bdw anyway, but this needs to be addressed when 2559a028c4b0SDaniel Vetter * we merge that code. 2560a028c4b0SDaniel Vetter */ 2561a028c4b0SDaniel Vetter return false; 2562a028c4b0SDaniel Vetter } else { 2563a028c4b0SDaniel Vetter ipehr &= ~MI_SEMAPHORE_SYNC_MASK; 2564a028c4b0SDaniel Vetter return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | 2565a028c4b0SDaniel Vetter MI_SEMAPHORE_REGISTER); 2566a028c4b0SDaniel Vetter } 2567a028c4b0SDaniel Vetter } 2568a028c4b0SDaniel Vetter 25696274f212SChris Wilson static struct intel_ring_buffer * 2570921d42eaSDaniel Vetter semaphore_wait_to_signaller_ring(struct intel_ring_buffer *ring, u32 ipehr) 2571921d42eaSDaniel Vetter { 2572921d42eaSDaniel Vetter struct drm_i915_private *dev_priv = ring->dev->dev_private; 2573921d42eaSDaniel Vetter struct intel_ring_buffer *signaller; 2574921d42eaSDaniel Vetter int i; 2575921d42eaSDaniel Vetter 2576921d42eaSDaniel Vetter if (INTEL_INFO(dev_priv->dev)->gen >= 8) { 2577921d42eaSDaniel Vetter /* 2578921d42eaSDaniel Vetter * FIXME: gen8 semaphore support - currently we don't emit 2579921d42eaSDaniel Vetter * semaphores on bdw anyway, but this needs to be addressed when 2580921d42eaSDaniel Vetter * we merge that code. 2581921d42eaSDaniel Vetter */ 2582921d42eaSDaniel Vetter return NULL; 2583921d42eaSDaniel Vetter } else { 2584921d42eaSDaniel Vetter u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK; 2585921d42eaSDaniel Vetter 2586921d42eaSDaniel Vetter for_each_ring(signaller, dev_priv, i) { 2587921d42eaSDaniel Vetter if(ring == signaller) 2588921d42eaSDaniel Vetter continue; 2589921d42eaSDaniel Vetter 2590921d42eaSDaniel Vetter if (sync_bits == 2591921d42eaSDaniel Vetter signaller->semaphore_register[ring->id]) 2592921d42eaSDaniel Vetter return signaller; 2593921d42eaSDaniel Vetter } 2594921d42eaSDaniel Vetter } 2595921d42eaSDaniel Vetter 2596921d42eaSDaniel Vetter DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x\n", 2597921d42eaSDaniel Vetter ring->id, ipehr); 2598921d42eaSDaniel Vetter 2599921d42eaSDaniel Vetter return NULL; 2600921d42eaSDaniel Vetter } 2601921d42eaSDaniel Vetter 2602921d42eaSDaniel Vetter static struct intel_ring_buffer * 26036274f212SChris Wilson semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno) 2604a24a11e6SChris Wilson { 2605a24a11e6SChris Wilson struct drm_i915_private *dev_priv = ring->dev->dev_private; 260688fe429dSDaniel Vetter u32 cmd, ipehr, head; 260788fe429dSDaniel Vetter int i; 2608a24a11e6SChris Wilson 2609a24a11e6SChris Wilson ipehr = I915_READ(RING_IPEHR(ring->mmio_base)); 2610a028c4b0SDaniel Vetter if (!ipehr_is_semaphore_wait(ring->dev, ipehr)) 26116274f212SChris Wilson return NULL; 2612a24a11e6SChris Wilson 261388fe429dSDaniel Vetter /* 261488fe429dSDaniel Vetter * HEAD is likely pointing to the dword after the actual command, 261588fe429dSDaniel Vetter * so scan backwards until we find the MBOX. But limit it to just 3 261688fe429dSDaniel Vetter * dwords. Note that we don't care about ACTHD here since that might 261788fe429dSDaniel Vetter * point at at batch, and semaphores are always emitted into the 261888fe429dSDaniel Vetter * ringbuffer itself. 2619a24a11e6SChris Wilson */ 262088fe429dSDaniel Vetter head = I915_READ_HEAD(ring) & HEAD_ADDR; 262188fe429dSDaniel Vetter 262288fe429dSDaniel Vetter for (i = 4; i; --i) { 262388fe429dSDaniel Vetter /* 262488fe429dSDaniel Vetter * Be paranoid and presume the hw has gone off into the wild - 262588fe429dSDaniel Vetter * our ring is smaller than what the hardware (and hence 262688fe429dSDaniel Vetter * HEAD_ADDR) allows. Also handles wrap-around. 262788fe429dSDaniel Vetter */ 262888fe429dSDaniel Vetter head &= ring->size - 1; 262988fe429dSDaniel Vetter 263088fe429dSDaniel Vetter /* This here seems to blow up */ 263188fe429dSDaniel Vetter cmd = ioread32(ring->virtual_start + head); 2632a24a11e6SChris Wilson if (cmd == ipehr) 2633a24a11e6SChris Wilson break; 2634a24a11e6SChris Wilson 263588fe429dSDaniel Vetter head -= 4; 263688fe429dSDaniel Vetter } 2637a24a11e6SChris Wilson 263888fe429dSDaniel Vetter if (!i) 263988fe429dSDaniel Vetter return NULL; 264088fe429dSDaniel Vetter 264188fe429dSDaniel Vetter *seqno = ioread32(ring->virtual_start + head + 4) + 1; 2642921d42eaSDaniel Vetter return semaphore_wait_to_signaller_ring(ring, ipehr); 2643a24a11e6SChris Wilson } 2644a24a11e6SChris Wilson 26456274f212SChris Wilson static int semaphore_passed(struct intel_ring_buffer *ring) 26466274f212SChris Wilson { 26476274f212SChris Wilson struct drm_i915_private *dev_priv = ring->dev->dev_private; 26486274f212SChris Wilson struct intel_ring_buffer *signaller; 26496274f212SChris Wilson u32 seqno, ctl; 26506274f212SChris Wilson 26516274f212SChris Wilson ring->hangcheck.deadlock = true; 26526274f212SChris Wilson 26536274f212SChris Wilson signaller = semaphore_waits_for(ring, &seqno); 26546274f212SChris Wilson if (signaller == NULL || signaller->hangcheck.deadlock) 26556274f212SChris Wilson return -1; 26566274f212SChris Wilson 26576274f212SChris Wilson /* cursory check for an unkickable deadlock */ 26586274f212SChris Wilson ctl = I915_READ_CTL(signaller); 26596274f212SChris Wilson if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0) 26606274f212SChris Wilson return -1; 26616274f212SChris Wilson 26626274f212SChris Wilson return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno); 26636274f212SChris Wilson } 26646274f212SChris Wilson 26656274f212SChris Wilson static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv) 26666274f212SChris Wilson { 26676274f212SChris Wilson struct intel_ring_buffer *ring; 26686274f212SChris Wilson int i; 26696274f212SChris Wilson 26706274f212SChris Wilson for_each_ring(ring, dev_priv, i) 26716274f212SChris Wilson ring->hangcheck.deadlock = false; 26726274f212SChris Wilson } 26736274f212SChris Wilson 2674ad8beaeaSMika Kuoppala static enum intel_ring_hangcheck_action 267550877445SChris Wilson ring_stuck(struct intel_ring_buffer *ring, u64 acthd) 26761ec14ad3SChris Wilson { 26771ec14ad3SChris Wilson struct drm_device *dev = ring->dev; 26781ec14ad3SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 26799107e9d2SChris Wilson u32 tmp; 26809107e9d2SChris Wilson 26816274f212SChris Wilson if (ring->hangcheck.acthd != acthd) 2682f2f4d82fSJani Nikula return HANGCHECK_ACTIVE; 26836274f212SChris Wilson 26849107e9d2SChris Wilson if (IS_GEN2(dev)) 2685f2f4d82fSJani Nikula return HANGCHECK_HUNG; 26869107e9d2SChris Wilson 26879107e9d2SChris Wilson /* Is the chip hanging on a WAIT_FOR_EVENT? 26889107e9d2SChris Wilson * If so we can simply poke the RB_WAIT bit 26899107e9d2SChris Wilson * and break the hang. This should work on 26909107e9d2SChris Wilson * all but the second generation chipsets. 26919107e9d2SChris Wilson */ 26929107e9d2SChris Wilson tmp = I915_READ_CTL(ring); 26931ec14ad3SChris Wilson if (tmp & RING_WAIT) { 269458174462SMika Kuoppala i915_handle_error(dev, false, 269558174462SMika Kuoppala "Kicking stuck wait on %s", 26961ec14ad3SChris Wilson ring->name); 26971ec14ad3SChris Wilson I915_WRITE_CTL(ring, tmp); 2698f2f4d82fSJani Nikula return HANGCHECK_KICK; 26991ec14ad3SChris Wilson } 2700a24a11e6SChris Wilson 27016274f212SChris Wilson if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) { 27026274f212SChris Wilson switch (semaphore_passed(ring)) { 27036274f212SChris Wilson default: 2704f2f4d82fSJani Nikula return HANGCHECK_HUNG; 27056274f212SChris Wilson case 1: 270658174462SMika Kuoppala i915_handle_error(dev, false, 270758174462SMika Kuoppala "Kicking stuck semaphore on %s", 2708a24a11e6SChris Wilson ring->name); 2709a24a11e6SChris Wilson I915_WRITE_CTL(ring, tmp); 2710f2f4d82fSJani Nikula return HANGCHECK_KICK; 27116274f212SChris Wilson case 0: 2712f2f4d82fSJani Nikula return HANGCHECK_WAIT; 27136274f212SChris Wilson } 27149107e9d2SChris Wilson } 27159107e9d2SChris Wilson 2716f2f4d82fSJani Nikula return HANGCHECK_HUNG; 2717a24a11e6SChris Wilson } 2718d1e61e7fSChris Wilson 2719f65d9421SBen Gamari /** 2720f65d9421SBen Gamari * This is called when the chip hasn't reported back with completed 272105407ff8SMika Kuoppala * batchbuffers in a long time. We keep track per ring seqno progress and 272205407ff8SMika Kuoppala * if there are no progress, hangcheck score for that ring is increased. 272305407ff8SMika Kuoppala * Further, acthd is inspected to see if the ring is stuck. On stuck case 272405407ff8SMika Kuoppala * we kick the ring. If we see no progress on three subsequent calls 272505407ff8SMika Kuoppala * we assume chip is wedged and try to fix it by resetting the chip. 2726f65d9421SBen Gamari */ 2727a658b5d2SDamien Lespiau static void i915_hangcheck_elapsed(unsigned long data) 2728f65d9421SBen Gamari { 2729f65d9421SBen Gamari struct drm_device *dev = (struct drm_device *)data; 27302d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 2731b4519513SChris Wilson struct intel_ring_buffer *ring; 2732b4519513SChris Wilson int i; 273305407ff8SMika Kuoppala int busy_count = 0, rings_hung = 0; 27349107e9d2SChris Wilson bool stuck[I915_NUM_RINGS] = { 0 }; 27359107e9d2SChris Wilson #define BUSY 1 27369107e9d2SChris Wilson #define KICK 5 27379107e9d2SChris Wilson #define HUNG 20 2738893eead0SChris Wilson 2739d330a953SJani Nikula if (!i915.enable_hangcheck) 27403e0dc6b0SBen Widawsky return; 27413e0dc6b0SBen Widawsky 2742b4519513SChris Wilson for_each_ring(ring, dev_priv, i) { 274350877445SChris Wilson u64 acthd; 274450877445SChris Wilson u32 seqno; 27459107e9d2SChris Wilson bool busy = true; 2746b4519513SChris Wilson 27476274f212SChris Wilson semaphore_clear_deadlocks(dev_priv); 27486274f212SChris Wilson 274905407ff8SMika Kuoppala seqno = ring->get_seqno(ring, false); 275005407ff8SMika Kuoppala acthd = intel_ring_get_active_head(ring); 275105407ff8SMika Kuoppala 275205407ff8SMika Kuoppala if (ring->hangcheck.seqno == seqno) { 27539107e9d2SChris Wilson if (ring_idle(ring, seqno)) { 2754da661464SMika Kuoppala ring->hangcheck.action = HANGCHECK_IDLE; 2755da661464SMika Kuoppala 27569107e9d2SChris Wilson if (waitqueue_active(&ring->irq_queue)) { 27579107e9d2SChris Wilson /* Issue a wake-up to catch stuck h/w. */ 2758094f9a54SChris Wilson if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) { 2759f4adcd24SDaniel Vetter if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring))) 27609107e9d2SChris Wilson DRM_ERROR("Hangcheck timer elapsed... %s idle\n", 27619107e9d2SChris Wilson ring->name); 2762f4adcd24SDaniel Vetter else 2763f4adcd24SDaniel Vetter DRM_INFO("Fake missed irq on %s\n", 2764f4adcd24SDaniel Vetter ring->name); 27659107e9d2SChris Wilson wake_up_all(&ring->irq_queue); 2766094f9a54SChris Wilson } 2767094f9a54SChris Wilson /* Safeguard against driver failure */ 2768094f9a54SChris Wilson ring->hangcheck.score += BUSY; 27699107e9d2SChris Wilson } else 27709107e9d2SChris Wilson busy = false; 277105407ff8SMika Kuoppala } else { 27726274f212SChris Wilson /* We always increment the hangcheck score 27736274f212SChris Wilson * if the ring is busy and still processing 27746274f212SChris Wilson * the same request, so that no single request 27756274f212SChris Wilson * can run indefinitely (such as a chain of 27766274f212SChris Wilson * batches). The only time we do not increment 27776274f212SChris Wilson * the hangcheck score on this ring, if this 27786274f212SChris Wilson * ring is in a legitimate wait for another 27796274f212SChris Wilson * ring. In that case the waiting ring is a 27806274f212SChris Wilson * victim and we want to be sure we catch the 27816274f212SChris Wilson * right culprit. Then every time we do kick 27826274f212SChris Wilson * the ring, add a small increment to the 27836274f212SChris Wilson * score so that we can catch a batch that is 27846274f212SChris Wilson * being repeatedly kicked and so responsible 27856274f212SChris Wilson * for stalling the machine. 27869107e9d2SChris Wilson */ 2787ad8beaeaSMika Kuoppala ring->hangcheck.action = ring_stuck(ring, 2788ad8beaeaSMika Kuoppala acthd); 2789ad8beaeaSMika Kuoppala 2790ad8beaeaSMika Kuoppala switch (ring->hangcheck.action) { 2791da661464SMika Kuoppala case HANGCHECK_IDLE: 2792f2f4d82fSJani Nikula case HANGCHECK_WAIT: 27936274f212SChris Wilson break; 2794f2f4d82fSJani Nikula case HANGCHECK_ACTIVE: 2795ea04cb31SJani Nikula ring->hangcheck.score += BUSY; 27966274f212SChris Wilson break; 2797f2f4d82fSJani Nikula case HANGCHECK_KICK: 2798ea04cb31SJani Nikula ring->hangcheck.score += KICK; 27996274f212SChris Wilson break; 2800f2f4d82fSJani Nikula case HANGCHECK_HUNG: 2801ea04cb31SJani Nikula ring->hangcheck.score += HUNG; 28026274f212SChris Wilson stuck[i] = true; 28036274f212SChris Wilson break; 28046274f212SChris Wilson } 280505407ff8SMika Kuoppala } 28069107e9d2SChris Wilson } else { 2807da661464SMika Kuoppala ring->hangcheck.action = HANGCHECK_ACTIVE; 2808da661464SMika Kuoppala 28099107e9d2SChris Wilson /* Gradually reduce the count so that we catch DoS 28109107e9d2SChris Wilson * attempts across multiple batches. 28119107e9d2SChris Wilson */ 28129107e9d2SChris Wilson if (ring->hangcheck.score > 0) 28139107e9d2SChris Wilson ring->hangcheck.score--; 2814cbb465e7SChris Wilson } 2815f65d9421SBen Gamari 281605407ff8SMika Kuoppala ring->hangcheck.seqno = seqno; 281705407ff8SMika Kuoppala ring->hangcheck.acthd = acthd; 28189107e9d2SChris Wilson busy_count += busy; 281905407ff8SMika Kuoppala } 282005407ff8SMika Kuoppala 282105407ff8SMika Kuoppala for_each_ring(ring, dev_priv, i) { 2822b6b0fac0SMika Kuoppala if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) { 2823b8d88d1dSDaniel Vetter DRM_INFO("%s on %s\n", 282405407ff8SMika Kuoppala stuck[i] ? "stuck" : "no progress", 2825a43adf07SChris Wilson ring->name); 2826a43adf07SChris Wilson rings_hung++; 282705407ff8SMika Kuoppala } 282805407ff8SMika Kuoppala } 282905407ff8SMika Kuoppala 283005407ff8SMika Kuoppala if (rings_hung) 283158174462SMika Kuoppala return i915_handle_error(dev, true, "Ring hung"); 283205407ff8SMika Kuoppala 283305407ff8SMika Kuoppala if (busy_count) 283405407ff8SMika Kuoppala /* Reset timer case chip hangs without another request 283505407ff8SMika Kuoppala * being added */ 283610cd45b6SMika Kuoppala i915_queue_hangcheck(dev); 283710cd45b6SMika Kuoppala } 283810cd45b6SMika Kuoppala 283910cd45b6SMika Kuoppala void i915_queue_hangcheck(struct drm_device *dev) 284010cd45b6SMika Kuoppala { 284110cd45b6SMika Kuoppala struct drm_i915_private *dev_priv = dev->dev_private; 2842d330a953SJani Nikula if (!i915.enable_hangcheck) 284310cd45b6SMika Kuoppala return; 284410cd45b6SMika Kuoppala 284599584db3SDaniel Vetter mod_timer(&dev_priv->gpu_error.hangcheck_timer, 284610cd45b6SMika Kuoppala round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES)); 2847f65d9421SBen Gamari } 2848f65d9421SBen Gamari 28491c69eb42SPaulo Zanoni static void ibx_irq_reset(struct drm_device *dev) 285091738a95SPaulo Zanoni { 285191738a95SPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 285291738a95SPaulo Zanoni 285391738a95SPaulo Zanoni if (HAS_PCH_NOP(dev)) 285491738a95SPaulo Zanoni return; 285591738a95SPaulo Zanoni 2856f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(SDE); 2857105b122eSPaulo Zanoni 2858105b122eSPaulo Zanoni if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev)) 2859105b122eSPaulo Zanoni I915_WRITE(SERR_INT, 0xffffffff); 2860622364b6SPaulo Zanoni } 2861105b122eSPaulo Zanoni 286291738a95SPaulo Zanoni /* 2863622364b6SPaulo Zanoni * SDEIER is also touched by the interrupt handler to work around missed PCH 2864622364b6SPaulo Zanoni * interrupts. Hence we can't update it after the interrupt handler is enabled - 2865622364b6SPaulo Zanoni * instead we unconditionally enable all PCH interrupt sources here, but then 2866622364b6SPaulo Zanoni * only unmask them as needed with SDEIMR. 2867622364b6SPaulo Zanoni * 2868622364b6SPaulo Zanoni * This function needs to be called before interrupts are enabled. 286991738a95SPaulo Zanoni */ 2870622364b6SPaulo Zanoni static void ibx_irq_pre_postinstall(struct drm_device *dev) 2871622364b6SPaulo Zanoni { 2872622364b6SPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 2873622364b6SPaulo Zanoni 2874622364b6SPaulo Zanoni if (HAS_PCH_NOP(dev)) 2875622364b6SPaulo Zanoni return; 2876622364b6SPaulo Zanoni 2877622364b6SPaulo Zanoni WARN_ON(I915_READ(SDEIER) != 0); 287891738a95SPaulo Zanoni I915_WRITE(SDEIER, 0xffffffff); 287991738a95SPaulo Zanoni POSTING_READ(SDEIER); 288091738a95SPaulo Zanoni } 288191738a95SPaulo Zanoni 28827c4d664eSPaulo Zanoni static void gen5_gt_irq_reset(struct drm_device *dev) 2883d18ea1b5SDaniel Vetter { 2884d18ea1b5SDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 2885d18ea1b5SDaniel Vetter 2886f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(GT); 2887a9d356a6SPaulo Zanoni if (INTEL_INFO(dev)->gen >= 6) 2888f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(GEN6_PM); 2889d18ea1b5SDaniel Vetter } 2890d18ea1b5SDaniel Vetter 2891c0e09200SDave Airlie /* drm_dma.h hooks 2892c0e09200SDave Airlie */ 2893be30b29fSPaulo Zanoni static void ironlake_irq_reset(struct drm_device *dev) 2894036a4a7dSZhenyu Wang { 28952d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 2896036a4a7dSZhenyu Wang 28970c841212SPaulo Zanoni I915_WRITE(HWSTAM, 0xffffffff); 28980c841212SPaulo Zanoni 2899f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(DE); 2900c6d954c1SPaulo Zanoni if (IS_GEN7(dev)) 2901c6d954c1SPaulo Zanoni I915_WRITE(GEN7_ERR_INT, 0xffffffff); 2902c6d954c1SPaulo Zanoni 29037c4d664eSPaulo Zanoni gen5_gt_irq_reset(dev); 2904c650156aSZhenyu Wang 29051c69eb42SPaulo Zanoni ibx_irq_reset(dev); 29067d99163dSBen Widawsky } 29077d99163dSBen Widawsky 2908be30b29fSPaulo Zanoni static void ironlake_irq_preinstall(struct drm_device *dev) 2909be30b29fSPaulo Zanoni { 2910be30b29fSPaulo Zanoni ironlake_irq_reset(dev); 2911be30b29fSPaulo Zanoni } 2912be30b29fSPaulo Zanoni 29137e231dbeSJesse Barnes static void valleyview_irq_preinstall(struct drm_device *dev) 29147e231dbeSJesse Barnes { 29152d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 29167e231dbeSJesse Barnes int pipe; 29177e231dbeSJesse Barnes 29187e231dbeSJesse Barnes /* VLV magic */ 29197e231dbeSJesse Barnes I915_WRITE(VLV_IMR, 0); 29207e231dbeSJesse Barnes I915_WRITE(RING_IMR(RENDER_RING_BASE), 0); 29217e231dbeSJesse Barnes I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0); 29227e231dbeSJesse Barnes I915_WRITE(RING_IMR(BLT_RING_BASE), 0); 29237e231dbeSJesse Barnes 29247e231dbeSJesse Barnes /* and GT */ 29257e231dbeSJesse Barnes I915_WRITE(GTIIR, I915_READ(GTIIR)); 29267e231dbeSJesse Barnes I915_WRITE(GTIIR, I915_READ(GTIIR)); 2927d18ea1b5SDaniel Vetter 29287c4d664eSPaulo Zanoni gen5_gt_irq_reset(dev); 29297e231dbeSJesse Barnes 29307e231dbeSJesse Barnes I915_WRITE(DPINVGTT, 0xff); 29317e231dbeSJesse Barnes 29327e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_EN, 0); 29337e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 29347e231dbeSJesse Barnes for_each_pipe(pipe) 29357e231dbeSJesse Barnes I915_WRITE(PIPESTAT(pipe), 0xffff); 29367e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 29377e231dbeSJesse Barnes I915_WRITE(VLV_IMR, 0xffffffff); 29387e231dbeSJesse Barnes I915_WRITE(VLV_IER, 0x0); 29397e231dbeSJesse Barnes POSTING_READ(VLV_IER); 29407e231dbeSJesse Barnes } 29417e231dbeSJesse Barnes 2942823f6b38SPaulo Zanoni static void gen8_irq_reset(struct drm_device *dev) 2943abd58f01SBen Widawsky { 2944abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 2945abd58f01SBen Widawsky int pipe; 2946abd58f01SBen Widawsky 2947abd58f01SBen Widawsky I915_WRITE(GEN8_MASTER_IRQ, 0); 2948abd58f01SBen Widawsky POSTING_READ(GEN8_MASTER_IRQ); 2949abd58f01SBen Widawsky 2950f86f3fb0SPaulo Zanoni GEN8_IRQ_RESET_NDX(GT, 0); 2951f86f3fb0SPaulo Zanoni GEN8_IRQ_RESET_NDX(GT, 1); 2952f86f3fb0SPaulo Zanoni GEN8_IRQ_RESET_NDX(GT, 2); 2953f86f3fb0SPaulo Zanoni GEN8_IRQ_RESET_NDX(GT, 3); 2954abd58f01SBen Widawsky 2955823f6b38SPaulo Zanoni for_each_pipe(pipe) 2956f86f3fb0SPaulo Zanoni GEN8_IRQ_RESET_NDX(DE_PIPE, pipe); 2957abd58f01SBen Widawsky 2958f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(GEN8_DE_PORT_); 2959f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(GEN8_DE_MISC_); 2960f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(GEN8_PCU_); 296109f2344dSJesse Barnes 29621c69eb42SPaulo Zanoni ibx_irq_reset(dev); 2963abd58f01SBen Widawsky } 2964abd58f01SBen Widawsky 2965823f6b38SPaulo Zanoni static void gen8_irq_preinstall(struct drm_device *dev) 2966823f6b38SPaulo Zanoni { 2967823f6b38SPaulo Zanoni gen8_irq_reset(dev); 2968823f6b38SPaulo Zanoni } 2969823f6b38SPaulo Zanoni 297082a28bcfSDaniel Vetter static void ibx_hpd_irq_setup(struct drm_device *dev) 297182a28bcfSDaniel Vetter { 29722d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 297382a28bcfSDaniel Vetter struct drm_mode_config *mode_config = &dev->mode_config; 297482a28bcfSDaniel Vetter struct intel_encoder *intel_encoder; 2975fee884edSDaniel Vetter u32 hotplug_irqs, hotplug, enabled_irqs = 0; 297682a28bcfSDaniel Vetter 297782a28bcfSDaniel Vetter if (HAS_PCH_IBX(dev)) { 2978fee884edSDaniel Vetter hotplug_irqs = SDE_HOTPLUG_MASK; 297982a28bcfSDaniel Vetter list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head) 2980cd569aedSEgbert Eich if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) 2981fee884edSDaniel Vetter enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin]; 298282a28bcfSDaniel Vetter } else { 2983fee884edSDaniel Vetter hotplug_irqs = SDE_HOTPLUG_MASK_CPT; 298482a28bcfSDaniel Vetter list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head) 2985cd569aedSEgbert Eich if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) 2986fee884edSDaniel Vetter enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin]; 298782a28bcfSDaniel Vetter } 298882a28bcfSDaniel Vetter 2989fee884edSDaniel Vetter ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); 299082a28bcfSDaniel Vetter 29917fe0b973SKeith Packard /* 29927fe0b973SKeith Packard * Enable digital hotplug on the PCH, and configure the DP short pulse 29937fe0b973SKeith Packard * duration to 2ms (which is the minimum in the Display Port spec) 29947fe0b973SKeith Packard * 29957fe0b973SKeith Packard * This register is the same on all known PCH chips. 29967fe0b973SKeith Packard */ 29977fe0b973SKeith Packard hotplug = I915_READ(PCH_PORT_HOTPLUG); 29987fe0b973SKeith Packard hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK); 29997fe0b973SKeith Packard hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms; 30007fe0b973SKeith Packard hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms; 30017fe0b973SKeith Packard hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms; 30027fe0b973SKeith Packard I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 30037fe0b973SKeith Packard } 30047fe0b973SKeith Packard 3005d46da437SPaulo Zanoni static void ibx_irq_postinstall(struct drm_device *dev) 3006d46da437SPaulo Zanoni { 30072d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 300882a28bcfSDaniel Vetter u32 mask; 3009d46da437SPaulo Zanoni 3010692a04cfSDaniel Vetter if (HAS_PCH_NOP(dev)) 3011692a04cfSDaniel Vetter return; 3012692a04cfSDaniel Vetter 3013105b122eSPaulo Zanoni if (HAS_PCH_IBX(dev)) 30145c673b60SDaniel Vetter mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON; 3015105b122eSPaulo Zanoni else 30165c673b60SDaniel Vetter mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT; 30178664281bSPaulo Zanoni 3018337ba017SPaulo Zanoni GEN5_ASSERT_IIR_IS_ZERO(SDEIIR); 3019d46da437SPaulo Zanoni I915_WRITE(SDEIMR, ~mask); 3020d46da437SPaulo Zanoni } 3021d46da437SPaulo Zanoni 30220a9a8c91SDaniel Vetter static void gen5_gt_irq_postinstall(struct drm_device *dev) 30230a9a8c91SDaniel Vetter { 30240a9a8c91SDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 30250a9a8c91SDaniel Vetter u32 pm_irqs, gt_irqs; 30260a9a8c91SDaniel Vetter 30270a9a8c91SDaniel Vetter pm_irqs = gt_irqs = 0; 30280a9a8c91SDaniel Vetter 30290a9a8c91SDaniel Vetter dev_priv->gt_irq_mask = ~0; 3030040d2baaSBen Widawsky if (HAS_L3_DPF(dev)) { 30310a9a8c91SDaniel Vetter /* L3 parity interrupt is always unmasked. */ 303235a85ac6SBen Widawsky dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev); 303335a85ac6SBen Widawsky gt_irqs |= GT_PARITY_ERROR(dev); 30340a9a8c91SDaniel Vetter } 30350a9a8c91SDaniel Vetter 30360a9a8c91SDaniel Vetter gt_irqs |= GT_RENDER_USER_INTERRUPT; 30370a9a8c91SDaniel Vetter if (IS_GEN5(dev)) { 30380a9a8c91SDaniel Vetter gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT | 30390a9a8c91SDaniel Vetter ILK_BSD_USER_INTERRUPT; 30400a9a8c91SDaniel Vetter } else { 30410a9a8c91SDaniel Vetter gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT; 30420a9a8c91SDaniel Vetter } 30430a9a8c91SDaniel Vetter 304435079899SPaulo Zanoni GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs); 30450a9a8c91SDaniel Vetter 30460a9a8c91SDaniel Vetter if (INTEL_INFO(dev)->gen >= 6) { 3047a6706b45SDeepak S pm_irqs |= dev_priv->pm_rps_events; 30480a9a8c91SDaniel Vetter 30490a9a8c91SDaniel Vetter if (HAS_VEBOX(dev)) 30500a9a8c91SDaniel Vetter pm_irqs |= PM_VEBOX_USER_INTERRUPT; 30510a9a8c91SDaniel Vetter 3052605cd25bSPaulo Zanoni dev_priv->pm_irq_mask = 0xffffffff; 305335079899SPaulo Zanoni GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs); 30540a9a8c91SDaniel Vetter } 30550a9a8c91SDaniel Vetter } 30560a9a8c91SDaniel Vetter 3057f71d4af4SJesse Barnes static int ironlake_irq_postinstall(struct drm_device *dev) 3058036a4a7dSZhenyu Wang { 30594bc9d430SDaniel Vetter unsigned long irqflags; 30602d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 30618e76f8dcSPaulo Zanoni u32 display_mask, extra_mask; 30628e76f8dcSPaulo Zanoni 30638e76f8dcSPaulo Zanoni if (INTEL_INFO(dev)->gen >= 7) { 30648e76f8dcSPaulo Zanoni display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | 30658e76f8dcSPaulo Zanoni DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB | 30668e76f8dcSPaulo Zanoni DE_PLANEB_FLIP_DONE_IVB | 30675c673b60SDaniel Vetter DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB); 30688e76f8dcSPaulo Zanoni extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB | 30695c673b60SDaniel Vetter DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB); 30708e76f8dcSPaulo Zanoni } else { 30718e76f8dcSPaulo Zanoni display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | 3072ce99c256SDaniel Vetter DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE | 30735b3a856bSDaniel Vetter DE_AUX_CHANNEL_A | 30745b3a856bSDaniel Vetter DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE | 30755b3a856bSDaniel Vetter DE_POISON); 30765c673b60SDaniel Vetter extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT | 30775c673b60SDaniel Vetter DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN; 30788e76f8dcSPaulo Zanoni } 3079036a4a7dSZhenyu Wang 30801ec14ad3SChris Wilson dev_priv->irq_mask = ~display_mask; 3081036a4a7dSZhenyu Wang 30820c841212SPaulo Zanoni I915_WRITE(HWSTAM, 0xeffe); 30830c841212SPaulo Zanoni 3084622364b6SPaulo Zanoni ibx_irq_pre_postinstall(dev); 3085622364b6SPaulo Zanoni 308635079899SPaulo Zanoni GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask); 3087036a4a7dSZhenyu Wang 30880a9a8c91SDaniel Vetter gen5_gt_irq_postinstall(dev); 3089036a4a7dSZhenyu Wang 3090d46da437SPaulo Zanoni ibx_irq_postinstall(dev); 30917fe0b973SKeith Packard 3092f97108d1SJesse Barnes if (IS_IRONLAKE_M(dev)) { 30936005ce42SDaniel Vetter /* Enable PCU event interrupts 30946005ce42SDaniel Vetter * 30956005ce42SDaniel Vetter * spinlocking not required here for correctness since interrupt 30964bc9d430SDaniel Vetter * setup is guaranteed to run in single-threaded context. But we 30974bc9d430SDaniel Vetter * need it to make the assert_spin_locked happy. */ 30984bc9d430SDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3099f97108d1SJesse Barnes ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT); 31004bc9d430SDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3101f97108d1SJesse Barnes } 3102f97108d1SJesse Barnes 3103036a4a7dSZhenyu Wang return 0; 3104036a4a7dSZhenyu Wang } 3105036a4a7dSZhenyu Wang 3106f8b79e58SImre Deak static void valleyview_display_irqs_install(struct drm_i915_private *dev_priv) 3107f8b79e58SImre Deak { 3108f8b79e58SImre Deak u32 pipestat_mask; 3109f8b79e58SImre Deak u32 iir_mask; 3110f8b79e58SImre Deak 3111f8b79e58SImre Deak pipestat_mask = PIPESTAT_INT_STATUS_MASK | 3112f8b79e58SImre Deak PIPE_FIFO_UNDERRUN_STATUS; 3113f8b79e58SImre Deak 3114f8b79e58SImre Deak I915_WRITE(PIPESTAT(PIPE_A), pipestat_mask); 3115f8b79e58SImre Deak I915_WRITE(PIPESTAT(PIPE_B), pipestat_mask); 3116f8b79e58SImre Deak POSTING_READ(PIPESTAT(PIPE_A)); 3117f8b79e58SImre Deak 3118f8b79e58SImre Deak pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV | 3119f8b79e58SImre Deak PIPE_CRC_DONE_INTERRUPT_STATUS; 3120f8b79e58SImre Deak 3121f8b79e58SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, pipestat_mask | 3122f8b79e58SImre Deak PIPE_GMBUS_INTERRUPT_STATUS); 3123f8b79e58SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, pipestat_mask); 3124f8b79e58SImre Deak 3125f8b79e58SImre Deak iir_mask = I915_DISPLAY_PORT_INTERRUPT | 3126f8b79e58SImre Deak I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3127f8b79e58SImre Deak I915_DISPLAY_PIPE_B_EVENT_INTERRUPT; 3128f8b79e58SImre Deak dev_priv->irq_mask &= ~iir_mask; 3129f8b79e58SImre Deak 3130f8b79e58SImre Deak I915_WRITE(VLV_IIR, iir_mask); 3131f8b79e58SImre Deak I915_WRITE(VLV_IIR, iir_mask); 3132f8b79e58SImre Deak I915_WRITE(VLV_IMR, dev_priv->irq_mask); 3133f8b79e58SImre Deak I915_WRITE(VLV_IER, ~dev_priv->irq_mask); 3134f8b79e58SImre Deak POSTING_READ(VLV_IER); 3135f8b79e58SImre Deak } 3136f8b79e58SImre Deak 3137f8b79e58SImre Deak static void valleyview_display_irqs_uninstall(struct drm_i915_private *dev_priv) 3138f8b79e58SImre Deak { 3139f8b79e58SImre Deak u32 pipestat_mask; 3140f8b79e58SImre Deak u32 iir_mask; 3141f8b79e58SImre Deak 3142f8b79e58SImre Deak iir_mask = I915_DISPLAY_PORT_INTERRUPT | 3143f8b79e58SImre Deak I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 31446c7fba04SImre Deak I915_DISPLAY_PIPE_B_EVENT_INTERRUPT; 3145f8b79e58SImre Deak 3146f8b79e58SImre Deak dev_priv->irq_mask |= iir_mask; 3147f8b79e58SImre Deak I915_WRITE(VLV_IER, ~dev_priv->irq_mask); 3148f8b79e58SImre Deak I915_WRITE(VLV_IMR, dev_priv->irq_mask); 3149f8b79e58SImre Deak I915_WRITE(VLV_IIR, iir_mask); 3150f8b79e58SImre Deak I915_WRITE(VLV_IIR, iir_mask); 3151f8b79e58SImre Deak POSTING_READ(VLV_IIR); 3152f8b79e58SImre Deak 3153f8b79e58SImre Deak pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV | 3154f8b79e58SImre Deak PIPE_CRC_DONE_INTERRUPT_STATUS; 3155f8b79e58SImre Deak 3156f8b79e58SImre Deak i915_disable_pipestat(dev_priv, PIPE_A, pipestat_mask | 3157f8b79e58SImre Deak PIPE_GMBUS_INTERRUPT_STATUS); 3158f8b79e58SImre Deak i915_disable_pipestat(dev_priv, PIPE_B, pipestat_mask); 3159f8b79e58SImre Deak 3160f8b79e58SImre Deak pipestat_mask = PIPESTAT_INT_STATUS_MASK | 3161f8b79e58SImre Deak PIPE_FIFO_UNDERRUN_STATUS; 3162f8b79e58SImre Deak I915_WRITE(PIPESTAT(PIPE_A), pipestat_mask); 3163f8b79e58SImre Deak I915_WRITE(PIPESTAT(PIPE_B), pipestat_mask); 3164f8b79e58SImre Deak POSTING_READ(PIPESTAT(PIPE_A)); 3165f8b79e58SImre Deak } 3166f8b79e58SImre Deak 3167f8b79e58SImre Deak void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv) 3168f8b79e58SImre Deak { 3169f8b79e58SImre Deak assert_spin_locked(&dev_priv->irq_lock); 3170f8b79e58SImre Deak 3171f8b79e58SImre Deak if (dev_priv->display_irqs_enabled) 3172f8b79e58SImre Deak return; 3173f8b79e58SImre Deak 3174f8b79e58SImre Deak dev_priv->display_irqs_enabled = true; 3175f8b79e58SImre Deak 3176f8b79e58SImre Deak if (dev_priv->dev->irq_enabled) 3177f8b79e58SImre Deak valleyview_display_irqs_install(dev_priv); 3178f8b79e58SImre Deak } 3179f8b79e58SImre Deak 3180f8b79e58SImre Deak void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv) 3181f8b79e58SImre Deak { 3182f8b79e58SImre Deak assert_spin_locked(&dev_priv->irq_lock); 3183f8b79e58SImre Deak 3184f8b79e58SImre Deak if (!dev_priv->display_irqs_enabled) 3185f8b79e58SImre Deak return; 3186f8b79e58SImre Deak 3187f8b79e58SImre Deak dev_priv->display_irqs_enabled = false; 3188f8b79e58SImre Deak 3189f8b79e58SImre Deak if (dev_priv->dev->irq_enabled) 3190f8b79e58SImre Deak valleyview_display_irqs_uninstall(dev_priv); 3191f8b79e58SImre Deak } 3192f8b79e58SImre Deak 31937e231dbeSJesse Barnes static int valleyview_irq_postinstall(struct drm_device *dev) 31947e231dbeSJesse Barnes { 31952d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3196b79480baSDaniel Vetter unsigned long irqflags; 31977e231dbeSJesse Barnes 3198f8b79e58SImre Deak dev_priv->irq_mask = ~0; 31997e231dbeSJesse Barnes 320020afbda2SDaniel Vetter I915_WRITE(PORT_HOTPLUG_EN, 0); 320120afbda2SDaniel Vetter POSTING_READ(PORT_HOTPLUG_EN); 320220afbda2SDaniel Vetter 32037e231dbeSJesse Barnes I915_WRITE(VLV_IMR, dev_priv->irq_mask); 3204f8b79e58SImre Deak I915_WRITE(VLV_IER, ~dev_priv->irq_mask); 32057e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 32067e231dbeSJesse Barnes POSTING_READ(VLV_IER); 32077e231dbeSJesse Barnes 3208b79480baSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3209b79480baSDaniel Vetter * just to make the assert_spin_locked check happy. */ 3210b79480baSDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3211f8b79e58SImre Deak if (dev_priv->display_irqs_enabled) 3212f8b79e58SImre Deak valleyview_display_irqs_install(dev_priv); 3213b79480baSDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 321431acc7f5SJesse Barnes 32157e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 32167e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 32177e231dbeSJesse Barnes 32180a9a8c91SDaniel Vetter gen5_gt_irq_postinstall(dev); 32197e231dbeSJesse Barnes 32207e231dbeSJesse Barnes /* ack & enable invalid PTE error interrupts */ 32217e231dbeSJesse Barnes #if 0 /* FIXME: add support to irq handler for checking these bits */ 32227e231dbeSJesse Barnes I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK); 32237e231dbeSJesse Barnes I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK); 32247e231dbeSJesse Barnes #endif 32257e231dbeSJesse Barnes 32267e231dbeSJesse Barnes I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE); 322720afbda2SDaniel Vetter 322820afbda2SDaniel Vetter return 0; 322920afbda2SDaniel Vetter } 323020afbda2SDaniel Vetter 3231abd58f01SBen Widawsky static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv) 3232abd58f01SBen Widawsky { 3233abd58f01SBen Widawsky int i; 3234abd58f01SBen Widawsky 3235abd58f01SBen Widawsky /* These are interrupts we'll toggle with the ring mask register */ 3236abd58f01SBen Widawsky uint32_t gt_interrupts[] = { 3237abd58f01SBen Widawsky GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT | 3238abd58f01SBen Widawsky GT_RENDER_L3_PARITY_ERROR_INTERRUPT | 3239abd58f01SBen Widawsky GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT, 3240abd58f01SBen Widawsky GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT | 3241abd58f01SBen Widawsky GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT, 3242abd58f01SBen Widawsky 0, 3243abd58f01SBen Widawsky GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT 3244abd58f01SBen Widawsky }; 3245abd58f01SBen Widawsky 3246337ba017SPaulo Zanoni for (i = 0; i < ARRAY_SIZE(gt_interrupts); i++) 324735079899SPaulo Zanoni GEN8_IRQ_INIT_NDX(GT, i, ~gt_interrupts[i], gt_interrupts[i]); 3248abd58f01SBen Widawsky } 3249abd58f01SBen Widawsky 3250abd58f01SBen Widawsky static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv) 3251abd58f01SBen Widawsky { 3252abd58f01SBen Widawsky struct drm_device *dev = dev_priv->dev; 325313b3a0a7SDaniel Vetter uint32_t de_pipe_masked = GEN8_PIPE_FLIP_DONE | 32540fbe7870SDaniel Vetter GEN8_PIPE_CDCLK_CRC_DONE | 325530100f2bSDaniel Vetter GEN8_DE_PIPE_IRQ_FAULT_ERRORS; 32565c673b60SDaniel Vetter uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK | 32575c673b60SDaniel Vetter GEN8_PIPE_FIFO_UNDERRUN; 3258abd58f01SBen Widawsky int pipe; 325913b3a0a7SDaniel Vetter dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked; 326013b3a0a7SDaniel Vetter dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked; 326113b3a0a7SDaniel Vetter dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked; 3262abd58f01SBen Widawsky 3263337ba017SPaulo Zanoni for_each_pipe(pipe) 326435079899SPaulo Zanoni GEN8_IRQ_INIT_NDX(DE_PIPE, pipe, dev_priv->de_irq_mask[pipe], 326535079899SPaulo Zanoni de_pipe_enables); 3266abd58f01SBen Widawsky 326735079899SPaulo Zanoni GEN5_IRQ_INIT(GEN8_DE_PORT_, ~GEN8_AUX_CHANNEL_A, GEN8_AUX_CHANNEL_A); 3268abd58f01SBen Widawsky } 3269abd58f01SBen Widawsky 3270abd58f01SBen Widawsky static int gen8_irq_postinstall(struct drm_device *dev) 3271abd58f01SBen Widawsky { 3272abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 3273abd58f01SBen Widawsky 3274622364b6SPaulo Zanoni ibx_irq_pre_postinstall(dev); 3275622364b6SPaulo Zanoni 3276abd58f01SBen Widawsky gen8_gt_irq_postinstall(dev_priv); 3277abd58f01SBen Widawsky gen8_de_irq_postinstall(dev_priv); 3278abd58f01SBen Widawsky 3279abd58f01SBen Widawsky ibx_irq_postinstall(dev); 3280abd58f01SBen Widawsky 3281abd58f01SBen Widawsky I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL); 3282abd58f01SBen Widawsky POSTING_READ(GEN8_MASTER_IRQ); 3283abd58f01SBen Widawsky 3284abd58f01SBen Widawsky return 0; 3285abd58f01SBen Widawsky } 3286abd58f01SBen Widawsky 3287abd58f01SBen Widawsky static void gen8_irq_uninstall(struct drm_device *dev) 3288abd58f01SBen Widawsky { 3289abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 3290abd58f01SBen Widawsky 3291abd58f01SBen Widawsky if (!dev_priv) 3292abd58f01SBen Widawsky return; 3293abd58f01SBen Widawsky 3294d4eb6b10SPaulo Zanoni intel_hpd_irq_uninstall(dev_priv); 3295d4eb6b10SPaulo Zanoni 3296823f6b38SPaulo Zanoni gen8_irq_reset(dev); 3297abd58f01SBen Widawsky } 3298abd58f01SBen Widawsky 32997e231dbeSJesse Barnes static void valleyview_irq_uninstall(struct drm_device *dev) 33007e231dbeSJesse Barnes { 33012d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3302f8b79e58SImre Deak unsigned long irqflags; 33037e231dbeSJesse Barnes int pipe; 33047e231dbeSJesse Barnes 33057e231dbeSJesse Barnes if (!dev_priv) 33067e231dbeSJesse Barnes return; 33077e231dbeSJesse Barnes 33083ca1ccedSVille Syrjälä intel_hpd_irq_uninstall(dev_priv); 3309ac4c16c5SEgbert Eich 33107e231dbeSJesse Barnes for_each_pipe(pipe) 33117e231dbeSJesse Barnes I915_WRITE(PIPESTAT(pipe), 0xffff); 33127e231dbeSJesse Barnes 33137e231dbeSJesse Barnes I915_WRITE(HWSTAM, 0xffffffff); 33147e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_EN, 0); 33157e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3316f8b79e58SImre Deak 3317f8b79e58SImre Deak spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3318f8b79e58SImre Deak if (dev_priv->display_irqs_enabled) 3319f8b79e58SImre Deak valleyview_display_irqs_uninstall(dev_priv); 3320f8b79e58SImre Deak spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3321f8b79e58SImre Deak 3322f8b79e58SImre Deak dev_priv->irq_mask = 0; 3323f8b79e58SImre Deak 33247e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 33257e231dbeSJesse Barnes I915_WRITE(VLV_IMR, 0xffffffff); 33267e231dbeSJesse Barnes I915_WRITE(VLV_IER, 0x0); 33277e231dbeSJesse Barnes POSTING_READ(VLV_IER); 33287e231dbeSJesse Barnes } 33297e231dbeSJesse Barnes 3330f71d4af4SJesse Barnes static void ironlake_irq_uninstall(struct drm_device *dev) 3331036a4a7dSZhenyu Wang { 33322d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 33334697995bSJesse Barnes 33344697995bSJesse Barnes if (!dev_priv) 33354697995bSJesse Barnes return; 33364697995bSJesse Barnes 33373ca1ccedSVille Syrjälä intel_hpd_irq_uninstall(dev_priv); 3338ac4c16c5SEgbert Eich 3339be30b29fSPaulo Zanoni ironlake_irq_reset(dev); 3340036a4a7dSZhenyu Wang } 3341036a4a7dSZhenyu Wang 3342c2798b19SChris Wilson static void i8xx_irq_preinstall(struct drm_device * dev) 3343c2798b19SChris Wilson { 33442d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3345c2798b19SChris Wilson int pipe; 3346c2798b19SChris Wilson 3347c2798b19SChris Wilson for_each_pipe(pipe) 3348c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3349c2798b19SChris Wilson I915_WRITE16(IMR, 0xffff); 3350c2798b19SChris Wilson I915_WRITE16(IER, 0x0); 3351c2798b19SChris Wilson POSTING_READ16(IER); 3352c2798b19SChris Wilson } 3353c2798b19SChris Wilson 3354c2798b19SChris Wilson static int i8xx_irq_postinstall(struct drm_device *dev) 3355c2798b19SChris Wilson { 33562d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3357379ef82dSDaniel Vetter unsigned long irqflags; 3358c2798b19SChris Wilson 3359c2798b19SChris Wilson I915_WRITE16(EMR, 3360c2798b19SChris Wilson ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH)); 3361c2798b19SChris Wilson 3362c2798b19SChris Wilson /* Unmask the interrupts that we always want on. */ 3363c2798b19SChris Wilson dev_priv->irq_mask = 3364c2798b19SChris Wilson ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3365c2798b19SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3366c2798b19SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 3367c2798b19SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | 3368c2798b19SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 3369c2798b19SChris Wilson I915_WRITE16(IMR, dev_priv->irq_mask); 3370c2798b19SChris Wilson 3371c2798b19SChris Wilson I915_WRITE16(IER, 3372c2798b19SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3373c2798b19SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3374c2798b19SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT | 3375c2798b19SChris Wilson I915_USER_INTERRUPT); 3376c2798b19SChris Wilson POSTING_READ16(IER); 3377c2798b19SChris Wilson 3378379ef82dSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3379379ef82dSDaniel Vetter * just to make the assert_spin_locked check happy. */ 3380379ef82dSDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3381755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 3382755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 3383379ef82dSDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3384379ef82dSDaniel Vetter 3385c2798b19SChris Wilson return 0; 3386c2798b19SChris Wilson } 3387c2798b19SChris Wilson 338890a72f87SVille Syrjälä /* 338990a72f87SVille Syrjälä * Returns true when a page flip has completed. 339090a72f87SVille Syrjälä */ 339190a72f87SVille Syrjälä static bool i8xx_handle_vblank(struct drm_device *dev, 33921f1c2e24SVille Syrjälä int plane, int pipe, u32 iir) 339390a72f87SVille Syrjälä { 33942d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 33951f1c2e24SVille Syrjälä u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane); 339690a72f87SVille Syrjälä 339790a72f87SVille Syrjälä if (!drm_handle_vblank(dev, pipe)) 339890a72f87SVille Syrjälä return false; 339990a72f87SVille Syrjälä 340090a72f87SVille Syrjälä if ((iir & flip_pending) == 0) 340190a72f87SVille Syrjälä return false; 340290a72f87SVille Syrjälä 34031f1c2e24SVille Syrjälä intel_prepare_page_flip(dev, plane); 340490a72f87SVille Syrjälä 340590a72f87SVille Syrjälä /* We detect FlipDone by looking for the change in PendingFlip from '1' 340690a72f87SVille Syrjälä * to '0' on the following vblank, i.e. IIR has the Pendingflip 340790a72f87SVille Syrjälä * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence 340890a72f87SVille Syrjälä * the flip is completed (no longer pending). Since this doesn't raise 340990a72f87SVille Syrjälä * an interrupt per se, we watch for the change at vblank. 341090a72f87SVille Syrjälä */ 341190a72f87SVille Syrjälä if (I915_READ16(ISR) & flip_pending) 341290a72f87SVille Syrjälä return false; 341390a72f87SVille Syrjälä 341490a72f87SVille Syrjälä intel_finish_page_flip(dev, pipe); 341590a72f87SVille Syrjälä 341690a72f87SVille Syrjälä return true; 341790a72f87SVille Syrjälä } 341890a72f87SVille Syrjälä 3419ff1f525eSDaniel Vetter static irqreturn_t i8xx_irq_handler(int irq, void *arg) 3420c2798b19SChris Wilson { 3421c2798b19SChris Wilson struct drm_device *dev = (struct drm_device *) arg; 34222d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3423c2798b19SChris Wilson u16 iir, new_iir; 3424c2798b19SChris Wilson u32 pipe_stats[2]; 3425c2798b19SChris Wilson unsigned long irqflags; 3426c2798b19SChris Wilson int pipe; 3427c2798b19SChris Wilson u16 flip_mask = 3428c2798b19SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 3429c2798b19SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 3430c2798b19SChris Wilson 3431c2798b19SChris Wilson iir = I915_READ16(IIR); 3432c2798b19SChris Wilson if (iir == 0) 3433c2798b19SChris Wilson return IRQ_NONE; 3434c2798b19SChris Wilson 3435c2798b19SChris Wilson while (iir & ~flip_mask) { 3436c2798b19SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 3437c2798b19SChris Wilson * have been cleared after the pipestat interrupt was received. 3438c2798b19SChris Wilson * It doesn't set the bit in iir again, but it still produces 3439c2798b19SChris Wilson * interrupts (for non-MSI). 3440c2798b19SChris Wilson */ 3441c2798b19SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3442c2798b19SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 344358174462SMika Kuoppala i915_handle_error(dev, false, 344458174462SMika Kuoppala "Command parser error, iir 0x%08x", 344558174462SMika Kuoppala iir); 3446c2798b19SChris Wilson 3447c2798b19SChris Wilson for_each_pipe(pipe) { 3448c2798b19SChris Wilson int reg = PIPESTAT(pipe); 3449c2798b19SChris Wilson pipe_stats[pipe] = I915_READ(reg); 3450c2798b19SChris Wilson 3451c2798b19SChris Wilson /* 3452c2798b19SChris Wilson * Clear the PIPE*STAT regs before the IIR 3453c2798b19SChris Wilson */ 34542d9d2b0bSVille Syrjälä if (pipe_stats[pipe] & 0x8000ffff) 3455c2798b19SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 3456c2798b19SChris Wilson } 3457c2798b19SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3458c2798b19SChris Wilson 3459c2798b19SChris Wilson I915_WRITE16(IIR, iir & ~flip_mask); 3460c2798b19SChris Wilson new_iir = I915_READ16(IIR); /* Flush posted writes */ 3461c2798b19SChris Wilson 3462d05c617eSDaniel Vetter i915_update_dri1_breadcrumb(dev); 3463c2798b19SChris Wilson 3464c2798b19SChris Wilson if (iir & I915_USER_INTERRUPT) 3465c2798b19SChris Wilson notify_ring(dev, &dev_priv->ring[RCS]); 3466c2798b19SChris Wilson 34674356d586SDaniel Vetter for_each_pipe(pipe) { 34681f1c2e24SVille Syrjälä int plane = pipe; 34693a77c4c4SDaniel Vetter if (HAS_FBC(dev)) 34701f1c2e24SVille Syrjälä plane = !plane; 34711f1c2e24SVille Syrjälä 34724356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS && 34731f1c2e24SVille Syrjälä i8xx_handle_vblank(dev, plane, pipe, iir)) 34741f1c2e24SVille Syrjälä flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane); 3475c2798b19SChris Wilson 34764356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 3477277de95eSDaniel Vetter i9xx_pipe_crc_irq_handler(dev, pipe); 34782d9d2b0bSVille Syrjälä 34792d9d2b0bSVille Syrjälä if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS && 34802d9d2b0bSVille Syrjälä intel_set_cpu_fifo_underrun_reporting(dev, pipe, false)) 3481fc2c807bSVille Syrjälä DRM_ERROR("pipe %c underrun\n", pipe_name(pipe)); 34824356d586SDaniel Vetter } 3483c2798b19SChris Wilson 3484c2798b19SChris Wilson iir = new_iir; 3485c2798b19SChris Wilson } 3486c2798b19SChris Wilson 3487c2798b19SChris Wilson return IRQ_HANDLED; 3488c2798b19SChris Wilson } 3489c2798b19SChris Wilson 3490c2798b19SChris Wilson static void i8xx_irq_uninstall(struct drm_device * dev) 3491c2798b19SChris Wilson { 34922d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3493c2798b19SChris Wilson int pipe; 3494c2798b19SChris Wilson 3495c2798b19SChris Wilson for_each_pipe(pipe) { 3496c2798b19SChris Wilson /* Clear enable bits; then clear status bits */ 3497c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3498c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe))); 3499c2798b19SChris Wilson } 3500c2798b19SChris Wilson I915_WRITE16(IMR, 0xffff); 3501c2798b19SChris Wilson I915_WRITE16(IER, 0x0); 3502c2798b19SChris Wilson I915_WRITE16(IIR, I915_READ16(IIR)); 3503c2798b19SChris Wilson } 3504c2798b19SChris Wilson 3505a266c7d5SChris Wilson static void i915_irq_preinstall(struct drm_device * dev) 3506a266c7d5SChris Wilson { 35072d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3508a266c7d5SChris Wilson int pipe; 3509a266c7d5SChris Wilson 3510a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 3511a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 3512a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3513a266c7d5SChris Wilson } 3514a266c7d5SChris Wilson 351500d98ebdSChris Wilson I915_WRITE16(HWSTAM, 0xeffe); 3516a266c7d5SChris Wilson for_each_pipe(pipe) 3517a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3518a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 3519a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 3520a266c7d5SChris Wilson POSTING_READ(IER); 3521a266c7d5SChris Wilson } 3522a266c7d5SChris Wilson 3523a266c7d5SChris Wilson static int i915_irq_postinstall(struct drm_device *dev) 3524a266c7d5SChris Wilson { 35252d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 352638bde180SChris Wilson u32 enable_mask; 3527379ef82dSDaniel Vetter unsigned long irqflags; 3528a266c7d5SChris Wilson 352938bde180SChris Wilson I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH)); 353038bde180SChris Wilson 353138bde180SChris Wilson /* Unmask the interrupts that we always want on. */ 353238bde180SChris Wilson dev_priv->irq_mask = 353338bde180SChris Wilson ~(I915_ASLE_INTERRUPT | 353438bde180SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 353538bde180SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 353638bde180SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 353738bde180SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | 353838bde180SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 353938bde180SChris Wilson 354038bde180SChris Wilson enable_mask = 354138bde180SChris Wilson I915_ASLE_INTERRUPT | 354238bde180SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 354338bde180SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 354438bde180SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT | 354538bde180SChris Wilson I915_USER_INTERRUPT; 354638bde180SChris Wilson 3547a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 354820afbda2SDaniel Vetter I915_WRITE(PORT_HOTPLUG_EN, 0); 354920afbda2SDaniel Vetter POSTING_READ(PORT_HOTPLUG_EN); 355020afbda2SDaniel Vetter 3551a266c7d5SChris Wilson /* Enable in IER... */ 3552a266c7d5SChris Wilson enable_mask |= I915_DISPLAY_PORT_INTERRUPT; 3553a266c7d5SChris Wilson /* and unmask in IMR */ 3554a266c7d5SChris Wilson dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT; 3555a266c7d5SChris Wilson } 3556a266c7d5SChris Wilson 3557a266c7d5SChris Wilson I915_WRITE(IMR, dev_priv->irq_mask); 3558a266c7d5SChris Wilson I915_WRITE(IER, enable_mask); 3559a266c7d5SChris Wilson POSTING_READ(IER); 3560a266c7d5SChris Wilson 3561f49e38ddSJani Nikula i915_enable_asle_pipestat(dev); 356220afbda2SDaniel Vetter 3563379ef82dSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3564379ef82dSDaniel Vetter * just to make the assert_spin_locked check happy. */ 3565379ef82dSDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3566755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 3567755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 3568379ef82dSDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3569379ef82dSDaniel Vetter 357020afbda2SDaniel Vetter return 0; 357120afbda2SDaniel Vetter } 357220afbda2SDaniel Vetter 357390a72f87SVille Syrjälä /* 357490a72f87SVille Syrjälä * Returns true when a page flip has completed. 357590a72f87SVille Syrjälä */ 357690a72f87SVille Syrjälä static bool i915_handle_vblank(struct drm_device *dev, 357790a72f87SVille Syrjälä int plane, int pipe, u32 iir) 357890a72f87SVille Syrjälä { 35792d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 358090a72f87SVille Syrjälä u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane); 358190a72f87SVille Syrjälä 358290a72f87SVille Syrjälä if (!drm_handle_vblank(dev, pipe)) 358390a72f87SVille Syrjälä return false; 358490a72f87SVille Syrjälä 358590a72f87SVille Syrjälä if ((iir & flip_pending) == 0) 358690a72f87SVille Syrjälä return false; 358790a72f87SVille Syrjälä 358890a72f87SVille Syrjälä intel_prepare_page_flip(dev, plane); 358990a72f87SVille Syrjälä 359090a72f87SVille Syrjälä /* We detect FlipDone by looking for the change in PendingFlip from '1' 359190a72f87SVille Syrjälä * to '0' on the following vblank, i.e. IIR has the Pendingflip 359290a72f87SVille Syrjälä * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence 359390a72f87SVille Syrjälä * the flip is completed (no longer pending). Since this doesn't raise 359490a72f87SVille Syrjälä * an interrupt per se, we watch for the change at vblank. 359590a72f87SVille Syrjälä */ 359690a72f87SVille Syrjälä if (I915_READ(ISR) & flip_pending) 359790a72f87SVille Syrjälä return false; 359890a72f87SVille Syrjälä 359990a72f87SVille Syrjälä intel_finish_page_flip(dev, pipe); 360090a72f87SVille Syrjälä 360190a72f87SVille Syrjälä return true; 360290a72f87SVille Syrjälä } 360390a72f87SVille Syrjälä 3604ff1f525eSDaniel Vetter static irqreturn_t i915_irq_handler(int irq, void *arg) 3605a266c7d5SChris Wilson { 3606a266c7d5SChris Wilson struct drm_device *dev = (struct drm_device *) arg; 36072d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 36088291ee90SChris Wilson u32 iir, new_iir, pipe_stats[I915_MAX_PIPES]; 3609a266c7d5SChris Wilson unsigned long irqflags; 361038bde180SChris Wilson u32 flip_mask = 361138bde180SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 361238bde180SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 361338bde180SChris Wilson int pipe, ret = IRQ_NONE; 3614a266c7d5SChris Wilson 3615a266c7d5SChris Wilson iir = I915_READ(IIR); 361638bde180SChris Wilson do { 361738bde180SChris Wilson bool irq_received = (iir & ~flip_mask) != 0; 36188291ee90SChris Wilson bool blc_event = false; 3619a266c7d5SChris Wilson 3620a266c7d5SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 3621a266c7d5SChris Wilson * have been cleared after the pipestat interrupt was received. 3622a266c7d5SChris Wilson * It doesn't set the bit in iir again, but it still produces 3623a266c7d5SChris Wilson * interrupts (for non-MSI). 3624a266c7d5SChris Wilson */ 3625a266c7d5SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3626a266c7d5SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 362758174462SMika Kuoppala i915_handle_error(dev, false, 362858174462SMika Kuoppala "Command parser error, iir 0x%08x", 362958174462SMika Kuoppala iir); 3630a266c7d5SChris Wilson 3631a266c7d5SChris Wilson for_each_pipe(pipe) { 3632a266c7d5SChris Wilson int reg = PIPESTAT(pipe); 3633a266c7d5SChris Wilson pipe_stats[pipe] = I915_READ(reg); 3634a266c7d5SChris Wilson 363538bde180SChris Wilson /* Clear the PIPE*STAT regs before the IIR */ 3636a266c7d5SChris Wilson if (pipe_stats[pipe] & 0x8000ffff) { 3637a266c7d5SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 363838bde180SChris Wilson irq_received = true; 3639a266c7d5SChris Wilson } 3640a266c7d5SChris Wilson } 3641a266c7d5SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3642a266c7d5SChris Wilson 3643a266c7d5SChris Wilson if (!irq_received) 3644a266c7d5SChris Wilson break; 3645a266c7d5SChris Wilson 3646a266c7d5SChris Wilson /* Consume port. Then clear IIR or we'll miss events */ 364716c6c56bSVille Syrjälä if (I915_HAS_HOTPLUG(dev) && 364816c6c56bSVille Syrjälä iir & I915_DISPLAY_PORT_INTERRUPT) 364916c6c56bSVille Syrjälä i9xx_hpd_irq_handler(dev); 3650a266c7d5SChris Wilson 365138bde180SChris Wilson I915_WRITE(IIR, iir & ~flip_mask); 3652a266c7d5SChris Wilson new_iir = I915_READ(IIR); /* Flush posted writes */ 3653a266c7d5SChris Wilson 3654a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 3655a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[RCS]); 3656a266c7d5SChris Wilson 3657a266c7d5SChris Wilson for_each_pipe(pipe) { 365838bde180SChris Wilson int plane = pipe; 36593a77c4c4SDaniel Vetter if (HAS_FBC(dev)) 366038bde180SChris Wilson plane = !plane; 36615e2032d4SVille Syrjälä 366290a72f87SVille Syrjälä if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS && 366390a72f87SVille Syrjälä i915_handle_vblank(dev, plane, pipe, iir)) 366490a72f87SVille Syrjälä flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane); 3665a266c7d5SChris Wilson 3666a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 3667a266c7d5SChris Wilson blc_event = true; 36684356d586SDaniel Vetter 36694356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 3670277de95eSDaniel Vetter i9xx_pipe_crc_irq_handler(dev, pipe); 36712d9d2b0bSVille Syrjälä 36722d9d2b0bSVille Syrjälä if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS && 36732d9d2b0bSVille Syrjälä intel_set_cpu_fifo_underrun_reporting(dev, pipe, false)) 3674fc2c807bSVille Syrjälä DRM_ERROR("pipe %c underrun\n", pipe_name(pipe)); 3675a266c7d5SChris Wilson } 3676a266c7d5SChris Wilson 3677a266c7d5SChris Wilson if (blc_event || (iir & I915_ASLE_INTERRUPT)) 3678a266c7d5SChris Wilson intel_opregion_asle_intr(dev); 3679a266c7d5SChris Wilson 3680a266c7d5SChris Wilson /* With MSI, interrupts are only generated when iir 3681a266c7d5SChris Wilson * transitions from zero to nonzero. If another bit got 3682a266c7d5SChris Wilson * set while we were handling the existing iir bits, then 3683a266c7d5SChris Wilson * we would never get another interrupt. 3684a266c7d5SChris Wilson * 3685a266c7d5SChris Wilson * This is fine on non-MSI as well, as if we hit this path 3686a266c7d5SChris Wilson * we avoid exiting the interrupt handler only to generate 3687a266c7d5SChris Wilson * another one. 3688a266c7d5SChris Wilson * 3689a266c7d5SChris Wilson * Note that for MSI this could cause a stray interrupt report 3690a266c7d5SChris Wilson * if an interrupt landed in the time between writing IIR and 3691a266c7d5SChris Wilson * the posting read. This should be rare enough to never 3692a266c7d5SChris Wilson * trigger the 99% of 100,000 interrupts test for disabling 3693a266c7d5SChris Wilson * stray interrupts. 3694a266c7d5SChris Wilson */ 369538bde180SChris Wilson ret = IRQ_HANDLED; 3696a266c7d5SChris Wilson iir = new_iir; 369738bde180SChris Wilson } while (iir & ~flip_mask); 3698a266c7d5SChris Wilson 3699d05c617eSDaniel Vetter i915_update_dri1_breadcrumb(dev); 37008291ee90SChris Wilson 3701a266c7d5SChris Wilson return ret; 3702a266c7d5SChris Wilson } 3703a266c7d5SChris Wilson 3704a266c7d5SChris Wilson static void i915_irq_uninstall(struct drm_device * dev) 3705a266c7d5SChris Wilson { 37062d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3707a266c7d5SChris Wilson int pipe; 3708a266c7d5SChris Wilson 37093ca1ccedSVille Syrjälä intel_hpd_irq_uninstall(dev_priv); 3710ac4c16c5SEgbert Eich 3711a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 3712a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 3713a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3714a266c7d5SChris Wilson } 3715a266c7d5SChris Wilson 371600d98ebdSChris Wilson I915_WRITE16(HWSTAM, 0xffff); 371755b39755SChris Wilson for_each_pipe(pipe) { 371855b39755SChris Wilson /* Clear enable bits; then clear status bits */ 3719a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 372055b39755SChris Wilson I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe))); 372155b39755SChris Wilson } 3722a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 3723a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 3724a266c7d5SChris Wilson 3725a266c7d5SChris Wilson I915_WRITE(IIR, I915_READ(IIR)); 3726a266c7d5SChris Wilson } 3727a266c7d5SChris Wilson 3728a266c7d5SChris Wilson static void i965_irq_preinstall(struct drm_device * dev) 3729a266c7d5SChris Wilson { 37302d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3731a266c7d5SChris Wilson int pipe; 3732a266c7d5SChris Wilson 3733a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 3734a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3735a266c7d5SChris Wilson 3736a266c7d5SChris Wilson I915_WRITE(HWSTAM, 0xeffe); 3737a266c7d5SChris Wilson for_each_pipe(pipe) 3738a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3739a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 3740a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 3741a266c7d5SChris Wilson POSTING_READ(IER); 3742a266c7d5SChris Wilson } 3743a266c7d5SChris Wilson 3744a266c7d5SChris Wilson static int i965_irq_postinstall(struct drm_device *dev) 3745a266c7d5SChris Wilson { 37462d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3747bbba0a97SChris Wilson u32 enable_mask; 3748a266c7d5SChris Wilson u32 error_mask; 3749b79480baSDaniel Vetter unsigned long irqflags; 3750a266c7d5SChris Wilson 3751a266c7d5SChris Wilson /* Unmask the interrupts that we always want on. */ 3752bbba0a97SChris Wilson dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT | 3753adca4730SChris Wilson I915_DISPLAY_PORT_INTERRUPT | 3754bbba0a97SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3755bbba0a97SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3756bbba0a97SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 3757bbba0a97SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | 3758bbba0a97SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 3759bbba0a97SChris Wilson 3760bbba0a97SChris Wilson enable_mask = ~dev_priv->irq_mask; 376121ad8330SVille Syrjälä enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 376221ad8330SVille Syrjälä I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT); 3763bbba0a97SChris Wilson enable_mask |= I915_USER_INTERRUPT; 3764bbba0a97SChris Wilson 3765bbba0a97SChris Wilson if (IS_G4X(dev)) 3766bbba0a97SChris Wilson enable_mask |= I915_BSD_USER_INTERRUPT; 3767a266c7d5SChris Wilson 3768b79480baSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3769b79480baSDaniel Vetter * just to make the assert_spin_locked check happy. */ 3770b79480baSDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3771755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS); 3772755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 3773755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 3774b79480baSDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3775a266c7d5SChris Wilson 3776a266c7d5SChris Wilson /* 3777a266c7d5SChris Wilson * Enable some error detection, note the instruction error mask 3778a266c7d5SChris Wilson * bit is reserved, so we leave it masked. 3779a266c7d5SChris Wilson */ 3780a266c7d5SChris Wilson if (IS_G4X(dev)) { 3781a266c7d5SChris Wilson error_mask = ~(GM45_ERROR_PAGE_TABLE | 3782a266c7d5SChris Wilson GM45_ERROR_MEM_PRIV | 3783a266c7d5SChris Wilson GM45_ERROR_CP_PRIV | 3784a266c7d5SChris Wilson I915_ERROR_MEMORY_REFRESH); 3785a266c7d5SChris Wilson } else { 3786a266c7d5SChris Wilson error_mask = ~(I915_ERROR_PAGE_TABLE | 3787a266c7d5SChris Wilson I915_ERROR_MEMORY_REFRESH); 3788a266c7d5SChris Wilson } 3789a266c7d5SChris Wilson I915_WRITE(EMR, error_mask); 3790a266c7d5SChris Wilson 3791a266c7d5SChris Wilson I915_WRITE(IMR, dev_priv->irq_mask); 3792a266c7d5SChris Wilson I915_WRITE(IER, enable_mask); 3793a266c7d5SChris Wilson POSTING_READ(IER); 3794a266c7d5SChris Wilson 379520afbda2SDaniel Vetter I915_WRITE(PORT_HOTPLUG_EN, 0); 379620afbda2SDaniel Vetter POSTING_READ(PORT_HOTPLUG_EN); 379720afbda2SDaniel Vetter 3798f49e38ddSJani Nikula i915_enable_asle_pipestat(dev); 379920afbda2SDaniel Vetter 380020afbda2SDaniel Vetter return 0; 380120afbda2SDaniel Vetter } 380220afbda2SDaniel Vetter 3803bac56d5bSEgbert Eich static void i915_hpd_irq_setup(struct drm_device *dev) 380420afbda2SDaniel Vetter { 38052d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3806e5868a31SEgbert Eich struct drm_mode_config *mode_config = &dev->mode_config; 3807cd569aedSEgbert Eich struct intel_encoder *intel_encoder; 380820afbda2SDaniel Vetter u32 hotplug_en; 380920afbda2SDaniel Vetter 3810b5ea2d56SDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 3811b5ea2d56SDaniel Vetter 3812bac56d5bSEgbert Eich if (I915_HAS_HOTPLUG(dev)) { 3813bac56d5bSEgbert Eich hotplug_en = I915_READ(PORT_HOTPLUG_EN); 3814bac56d5bSEgbert Eich hotplug_en &= ~HOTPLUG_INT_EN_MASK; 3815adca4730SChris Wilson /* Note HDMI and DP share hotplug bits */ 3816e5868a31SEgbert Eich /* enable bits are the same for all generations */ 3817cd569aedSEgbert Eich list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head) 3818cd569aedSEgbert Eich if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) 3819cd569aedSEgbert Eich hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin]; 3820a266c7d5SChris Wilson /* Programming the CRT detection parameters tends 3821a266c7d5SChris Wilson to generate a spurious hotplug event about three 3822a266c7d5SChris Wilson seconds later. So just do it once. 3823a266c7d5SChris Wilson */ 3824a266c7d5SChris Wilson if (IS_G4X(dev)) 3825a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64; 382685fc95baSDaniel Vetter hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK; 3827a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; 3828a266c7d5SChris Wilson 3829a266c7d5SChris Wilson /* Ignore TV since it's buggy */ 3830a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, hotplug_en); 3831a266c7d5SChris Wilson } 3832bac56d5bSEgbert Eich } 3833a266c7d5SChris Wilson 3834ff1f525eSDaniel Vetter static irqreturn_t i965_irq_handler(int irq, void *arg) 3835a266c7d5SChris Wilson { 3836a266c7d5SChris Wilson struct drm_device *dev = (struct drm_device *) arg; 38372d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3838a266c7d5SChris Wilson u32 iir, new_iir; 3839a266c7d5SChris Wilson u32 pipe_stats[I915_MAX_PIPES]; 3840a266c7d5SChris Wilson unsigned long irqflags; 3841a266c7d5SChris Wilson int ret = IRQ_NONE, pipe; 384221ad8330SVille Syrjälä u32 flip_mask = 384321ad8330SVille Syrjälä I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 384421ad8330SVille Syrjälä I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 3845a266c7d5SChris Wilson 3846a266c7d5SChris Wilson iir = I915_READ(IIR); 3847a266c7d5SChris Wilson 3848a266c7d5SChris Wilson for (;;) { 3849501e01d7SVille Syrjälä bool irq_received = (iir & ~flip_mask) != 0; 38502c8ba29fSChris Wilson bool blc_event = false; 38512c8ba29fSChris Wilson 3852a266c7d5SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 3853a266c7d5SChris Wilson * have been cleared after the pipestat interrupt was received. 3854a266c7d5SChris Wilson * It doesn't set the bit in iir again, but it still produces 3855a266c7d5SChris Wilson * interrupts (for non-MSI). 3856a266c7d5SChris Wilson */ 3857a266c7d5SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3858a266c7d5SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 385958174462SMika Kuoppala i915_handle_error(dev, false, 386058174462SMika Kuoppala "Command parser error, iir 0x%08x", 386158174462SMika Kuoppala iir); 3862a266c7d5SChris Wilson 3863a266c7d5SChris Wilson for_each_pipe(pipe) { 3864a266c7d5SChris Wilson int reg = PIPESTAT(pipe); 3865a266c7d5SChris Wilson pipe_stats[pipe] = I915_READ(reg); 3866a266c7d5SChris Wilson 3867a266c7d5SChris Wilson /* 3868a266c7d5SChris Wilson * Clear the PIPE*STAT regs before the IIR 3869a266c7d5SChris Wilson */ 3870a266c7d5SChris Wilson if (pipe_stats[pipe] & 0x8000ffff) { 3871a266c7d5SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 3872501e01d7SVille Syrjälä irq_received = true; 3873a266c7d5SChris Wilson } 3874a266c7d5SChris Wilson } 3875a266c7d5SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3876a266c7d5SChris Wilson 3877a266c7d5SChris Wilson if (!irq_received) 3878a266c7d5SChris Wilson break; 3879a266c7d5SChris Wilson 3880a266c7d5SChris Wilson ret = IRQ_HANDLED; 3881a266c7d5SChris Wilson 3882a266c7d5SChris Wilson /* Consume port. Then clear IIR or we'll miss events */ 388316c6c56bSVille Syrjälä if (iir & I915_DISPLAY_PORT_INTERRUPT) 388416c6c56bSVille Syrjälä i9xx_hpd_irq_handler(dev); 3885a266c7d5SChris Wilson 388621ad8330SVille Syrjälä I915_WRITE(IIR, iir & ~flip_mask); 3887a266c7d5SChris Wilson new_iir = I915_READ(IIR); /* Flush posted writes */ 3888a266c7d5SChris Wilson 3889a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 3890a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[RCS]); 3891a266c7d5SChris Wilson if (iir & I915_BSD_USER_INTERRUPT) 3892a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[VCS]); 3893a266c7d5SChris Wilson 3894a266c7d5SChris Wilson for_each_pipe(pipe) { 38952c8ba29fSChris Wilson if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS && 389690a72f87SVille Syrjälä i915_handle_vblank(dev, pipe, pipe, iir)) 389790a72f87SVille Syrjälä flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe); 3898a266c7d5SChris Wilson 3899a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 3900a266c7d5SChris Wilson blc_event = true; 39014356d586SDaniel Vetter 39024356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 3903277de95eSDaniel Vetter i9xx_pipe_crc_irq_handler(dev, pipe); 3904a266c7d5SChris Wilson 39052d9d2b0bSVille Syrjälä if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS && 39062d9d2b0bSVille Syrjälä intel_set_cpu_fifo_underrun_reporting(dev, pipe, false)) 3907fc2c807bSVille Syrjälä DRM_ERROR("pipe %c underrun\n", pipe_name(pipe)); 39082d9d2b0bSVille Syrjälä } 3909a266c7d5SChris Wilson 3910a266c7d5SChris Wilson if (blc_event || (iir & I915_ASLE_INTERRUPT)) 3911a266c7d5SChris Wilson intel_opregion_asle_intr(dev); 3912a266c7d5SChris Wilson 3913515ac2bbSDaniel Vetter if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 3914515ac2bbSDaniel Vetter gmbus_irq_handler(dev); 3915515ac2bbSDaniel Vetter 3916a266c7d5SChris Wilson /* With MSI, interrupts are only generated when iir 3917a266c7d5SChris Wilson * transitions from zero to nonzero. If another bit got 3918a266c7d5SChris Wilson * set while we were handling the existing iir bits, then 3919a266c7d5SChris Wilson * we would never get another interrupt. 3920a266c7d5SChris Wilson * 3921a266c7d5SChris Wilson * This is fine on non-MSI as well, as if we hit this path 3922a266c7d5SChris Wilson * we avoid exiting the interrupt handler only to generate 3923a266c7d5SChris Wilson * another one. 3924a266c7d5SChris Wilson * 3925a266c7d5SChris Wilson * Note that for MSI this could cause a stray interrupt report 3926a266c7d5SChris Wilson * if an interrupt landed in the time between writing IIR and 3927a266c7d5SChris Wilson * the posting read. This should be rare enough to never 3928a266c7d5SChris Wilson * trigger the 99% of 100,000 interrupts test for disabling 3929a266c7d5SChris Wilson * stray interrupts. 3930a266c7d5SChris Wilson */ 3931a266c7d5SChris Wilson iir = new_iir; 3932a266c7d5SChris Wilson } 3933a266c7d5SChris Wilson 3934d05c617eSDaniel Vetter i915_update_dri1_breadcrumb(dev); 39352c8ba29fSChris Wilson 3936a266c7d5SChris Wilson return ret; 3937a266c7d5SChris Wilson } 3938a266c7d5SChris Wilson 3939a266c7d5SChris Wilson static void i965_irq_uninstall(struct drm_device * dev) 3940a266c7d5SChris Wilson { 39412d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3942a266c7d5SChris Wilson int pipe; 3943a266c7d5SChris Wilson 3944a266c7d5SChris Wilson if (!dev_priv) 3945a266c7d5SChris Wilson return; 3946a266c7d5SChris Wilson 39473ca1ccedSVille Syrjälä intel_hpd_irq_uninstall(dev_priv); 3948ac4c16c5SEgbert Eich 3949a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 3950a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3951a266c7d5SChris Wilson 3952a266c7d5SChris Wilson I915_WRITE(HWSTAM, 0xffffffff); 3953a266c7d5SChris Wilson for_each_pipe(pipe) 3954a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3955a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 3956a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 3957a266c7d5SChris Wilson 3958a266c7d5SChris Wilson for_each_pipe(pipe) 3959a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 3960a266c7d5SChris Wilson I915_READ(PIPESTAT(pipe)) & 0x8000ffff); 3961a266c7d5SChris Wilson I915_WRITE(IIR, I915_READ(IIR)); 3962a266c7d5SChris Wilson } 3963a266c7d5SChris Wilson 39643ca1ccedSVille Syrjälä static void intel_hpd_irq_reenable(unsigned long data) 3965ac4c16c5SEgbert Eich { 39662d1013ddSJani Nikula struct drm_i915_private *dev_priv = (struct drm_i915_private *)data; 3967ac4c16c5SEgbert Eich struct drm_device *dev = dev_priv->dev; 3968ac4c16c5SEgbert Eich struct drm_mode_config *mode_config = &dev->mode_config; 3969ac4c16c5SEgbert Eich unsigned long irqflags; 3970ac4c16c5SEgbert Eich int i; 3971ac4c16c5SEgbert Eich 3972ac4c16c5SEgbert Eich spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3973ac4c16c5SEgbert Eich for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) { 3974ac4c16c5SEgbert Eich struct drm_connector *connector; 3975ac4c16c5SEgbert Eich 3976ac4c16c5SEgbert Eich if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED) 3977ac4c16c5SEgbert Eich continue; 3978ac4c16c5SEgbert Eich 3979ac4c16c5SEgbert Eich dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED; 3980ac4c16c5SEgbert Eich 3981ac4c16c5SEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 3982ac4c16c5SEgbert Eich struct intel_connector *intel_connector = to_intel_connector(connector); 3983ac4c16c5SEgbert Eich 3984ac4c16c5SEgbert Eich if (intel_connector->encoder->hpd_pin == i) { 3985ac4c16c5SEgbert Eich if (connector->polled != intel_connector->polled) 3986ac4c16c5SEgbert Eich DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n", 3987ac4c16c5SEgbert Eich drm_get_connector_name(connector)); 3988ac4c16c5SEgbert Eich connector->polled = intel_connector->polled; 3989ac4c16c5SEgbert Eich if (!connector->polled) 3990ac4c16c5SEgbert Eich connector->polled = DRM_CONNECTOR_POLL_HPD; 3991ac4c16c5SEgbert Eich } 3992ac4c16c5SEgbert Eich } 3993ac4c16c5SEgbert Eich } 3994ac4c16c5SEgbert Eich if (dev_priv->display.hpd_irq_setup) 3995ac4c16c5SEgbert Eich dev_priv->display.hpd_irq_setup(dev); 3996ac4c16c5SEgbert Eich spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3997ac4c16c5SEgbert Eich } 3998ac4c16c5SEgbert Eich 3999f71d4af4SJesse Barnes void intel_irq_init(struct drm_device *dev) 4000f71d4af4SJesse Barnes { 40018b2e326dSChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 40028b2e326dSChris Wilson 40038b2e326dSChris Wilson INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func); 400499584db3SDaniel Vetter INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func); 4005c6a828d3SDaniel Vetter INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work); 4006a4da4fa4SDaniel Vetter INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work); 40078b2e326dSChris Wilson 4008a6706b45SDeepak S /* Let's track the enabled rps events */ 4009a6706b45SDeepak S dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS; 4010a6706b45SDeepak S 401199584db3SDaniel Vetter setup_timer(&dev_priv->gpu_error.hangcheck_timer, 401299584db3SDaniel Vetter i915_hangcheck_elapsed, 401361bac78eSDaniel Vetter (unsigned long) dev); 40143ca1ccedSVille Syrjälä setup_timer(&dev_priv->hotplug_reenable_timer, intel_hpd_irq_reenable, 4015ac4c16c5SEgbert Eich (unsigned long) dev_priv); 401661bac78eSDaniel Vetter 401797a19a24STomas Janousek pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE); 40189ee32feaSDaniel Vetter 40194cdb83ecSVille Syrjälä if (IS_GEN2(dev)) { 40204cdb83ecSVille Syrjälä dev->max_vblank_count = 0; 40214cdb83ecSVille Syrjälä dev->driver->get_vblank_counter = i8xx_get_vblank_counter; 40224cdb83ecSVille Syrjälä } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { 4023f71d4af4SJesse Barnes dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */ 4024f71d4af4SJesse Barnes dev->driver->get_vblank_counter = gm45_get_vblank_counter; 4025391f75e2SVille Syrjälä } else { 4026391f75e2SVille Syrjälä dev->driver->get_vblank_counter = i915_get_vblank_counter; 4027391f75e2SVille Syrjälä dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ 4028f71d4af4SJesse Barnes } 4029f71d4af4SJesse Barnes 4030c2baf4b7SVille Syrjälä if (drm_core_check_feature(dev, DRIVER_MODESET)) { 4031f71d4af4SJesse Barnes dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp; 4032f71d4af4SJesse Barnes dev->driver->get_scanout_position = i915_get_crtc_scanoutpos; 4033c2baf4b7SVille Syrjälä } 4034f71d4af4SJesse Barnes 40357e231dbeSJesse Barnes if (IS_VALLEYVIEW(dev)) { 40367e231dbeSJesse Barnes dev->driver->irq_handler = valleyview_irq_handler; 40377e231dbeSJesse Barnes dev->driver->irq_preinstall = valleyview_irq_preinstall; 40387e231dbeSJesse Barnes dev->driver->irq_postinstall = valleyview_irq_postinstall; 40397e231dbeSJesse Barnes dev->driver->irq_uninstall = valleyview_irq_uninstall; 40407e231dbeSJesse Barnes dev->driver->enable_vblank = valleyview_enable_vblank; 40417e231dbeSJesse Barnes dev->driver->disable_vblank = valleyview_disable_vblank; 4042fa00abe0SEgbert Eich dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 4043abd58f01SBen Widawsky } else if (IS_GEN8(dev)) { 4044abd58f01SBen Widawsky dev->driver->irq_handler = gen8_irq_handler; 4045abd58f01SBen Widawsky dev->driver->irq_preinstall = gen8_irq_preinstall; 4046abd58f01SBen Widawsky dev->driver->irq_postinstall = gen8_irq_postinstall; 4047abd58f01SBen Widawsky dev->driver->irq_uninstall = gen8_irq_uninstall; 4048abd58f01SBen Widawsky dev->driver->enable_vblank = gen8_enable_vblank; 4049abd58f01SBen Widawsky dev->driver->disable_vblank = gen8_disable_vblank; 4050abd58f01SBen Widawsky dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup; 4051f71d4af4SJesse Barnes } else if (HAS_PCH_SPLIT(dev)) { 4052f71d4af4SJesse Barnes dev->driver->irq_handler = ironlake_irq_handler; 4053f71d4af4SJesse Barnes dev->driver->irq_preinstall = ironlake_irq_preinstall; 4054f71d4af4SJesse Barnes dev->driver->irq_postinstall = ironlake_irq_postinstall; 4055f71d4af4SJesse Barnes dev->driver->irq_uninstall = ironlake_irq_uninstall; 4056f71d4af4SJesse Barnes dev->driver->enable_vblank = ironlake_enable_vblank; 4057f71d4af4SJesse Barnes dev->driver->disable_vblank = ironlake_disable_vblank; 405882a28bcfSDaniel Vetter dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup; 4059f71d4af4SJesse Barnes } else { 4060c2798b19SChris Wilson if (INTEL_INFO(dev)->gen == 2) { 4061c2798b19SChris Wilson dev->driver->irq_preinstall = i8xx_irq_preinstall; 4062c2798b19SChris Wilson dev->driver->irq_postinstall = i8xx_irq_postinstall; 4063c2798b19SChris Wilson dev->driver->irq_handler = i8xx_irq_handler; 4064c2798b19SChris Wilson dev->driver->irq_uninstall = i8xx_irq_uninstall; 4065a266c7d5SChris Wilson } else if (INTEL_INFO(dev)->gen == 3) { 4066a266c7d5SChris Wilson dev->driver->irq_preinstall = i915_irq_preinstall; 4067a266c7d5SChris Wilson dev->driver->irq_postinstall = i915_irq_postinstall; 4068a266c7d5SChris Wilson dev->driver->irq_uninstall = i915_irq_uninstall; 4069a266c7d5SChris Wilson dev->driver->irq_handler = i915_irq_handler; 407020afbda2SDaniel Vetter dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 4071c2798b19SChris Wilson } else { 4072a266c7d5SChris Wilson dev->driver->irq_preinstall = i965_irq_preinstall; 4073a266c7d5SChris Wilson dev->driver->irq_postinstall = i965_irq_postinstall; 4074a266c7d5SChris Wilson dev->driver->irq_uninstall = i965_irq_uninstall; 4075a266c7d5SChris Wilson dev->driver->irq_handler = i965_irq_handler; 4076bac56d5bSEgbert Eich dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 4077c2798b19SChris Wilson } 4078f71d4af4SJesse Barnes dev->driver->enable_vblank = i915_enable_vblank; 4079f71d4af4SJesse Barnes dev->driver->disable_vblank = i915_disable_vblank; 4080f71d4af4SJesse Barnes } 4081f71d4af4SJesse Barnes } 408220afbda2SDaniel Vetter 408320afbda2SDaniel Vetter void intel_hpd_init(struct drm_device *dev) 408420afbda2SDaniel Vetter { 408520afbda2SDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 4086821450c6SEgbert Eich struct drm_mode_config *mode_config = &dev->mode_config; 4087821450c6SEgbert Eich struct drm_connector *connector; 4088b5ea2d56SDaniel Vetter unsigned long irqflags; 4089821450c6SEgbert Eich int i; 409020afbda2SDaniel Vetter 4091821450c6SEgbert Eich for (i = 1; i < HPD_NUM_PINS; i++) { 4092821450c6SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt = 0; 4093821450c6SEgbert Eich dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED; 4094821450c6SEgbert Eich } 4095821450c6SEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 4096821450c6SEgbert Eich struct intel_connector *intel_connector = to_intel_connector(connector); 4097821450c6SEgbert Eich connector->polled = intel_connector->polled; 4098821450c6SEgbert Eich if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE) 4099821450c6SEgbert Eich connector->polled = DRM_CONNECTOR_POLL_HPD; 4100821450c6SEgbert Eich } 4101b5ea2d56SDaniel Vetter 4102b5ea2d56SDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 4103b5ea2d56SDaniel Vetter * just to make the assert_spin_locked checks happy. */ 4104b5ea2d56SDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 410520afbda2SDaniel Vetter if (dev_priv->display.hpd_irq_setup) 410620afbda2SDaniel Vetter dev_priv->display.hpd_irq_setup(dev); 4107b5ea2d56SDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 410820afbda2SDaniel Vetter } 4109c67a470bSPaulo Zanoni 41105d584b2eSPaulo Zanoni /* Disable interrupts so we can allow runtime PM. */ 4111730488b2SPaulo Zanoni void intel_runtime_pm_disable_interrupts(struct drm_device *dev) 4112c67a470bSPaulo Zanoni { 4113c67a470bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 4114c67a470bSPaulo Zanoni 4115730488b2SPaulo Zanoni dev->driver->irq_uninstall(dev); 41165d584b2eSPaulo Zanoni dev_priv->pm.irqs_disabled = true; 4117c67a470bSPaulo Zanoni } 4118c67a470bSPaulo Zanoni 41195d584b2eSPaulo Zanoni /* Restore interrupts so we can recover from runtime PM. */ 4120730488b2SPaulo Zanoni void intel_runtime_pm_restore_interrupts(struct drm_device *dev) 4121c67a470bSPaulo Zanoni { 4122c67a470bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 4123c67a470bSPaulo Zanoni 41245d584b2eSPaulo Zanoni dev_priv->pm.irqs_disabled = false; 4125730488b2SPaulo Zanoni dev->driver->irq_preinstall(dev); 4126730488b2SPaulo Zanoni dev->driver->irq_postinstall(dev); 4127c67a470bSPaulo Zanoni } 4128