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 53404feced9SVille Syrjälä if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK || 53504feced9SVille Syrjälä status_mask & ~PIPESTAT_INT_STATUS_MASK, 53604feced9SVille Syrjälä "pipe %c: enable_mask=0x%x, status_mask=0x%x\n", 53704feced9SVille 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 56004feced9SVille Syrjälä if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK || 56104feced9SVille Syrjälä status_mask & ~PIPESTAT_INT_STATUS_MASK, 56204feced9SVille Syrjälä "pipe %c: enable_mask=0x%x, status_mask=0x%x\n", 56304feced9SVille 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 135085f9b5f9SZhao Yakui if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_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]); 135785f9b5f9SZhao Yakui vcs = tmp >> GEN8_VCS2_IRQ_SHIFT; 135885f9b5f9SZhao Yakui if (vcs & GT_RENDER_USER_INTERRUPT) 135985f9b5f9SZhao Yakui notify_ring(dev, &dev_priv->ring[VCS2]); 1360abd58f01SBen Widawsky I915_WRITE(GEN8_GT_IIR(1), tmp); 1361abd58f01SBen Widawsky } else 1362abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (GT1)!\n"); 1363abd58f01SBen Widawsky } 1364abd58f01SBen Widawsky 1365abd58f01SBen Widawsky if (master_ctl & GEN8_GT_VECS_IRQ) { 1366abd58f01SBen Widawsky tmp = I915_READ(GEN8_GT_IIR(3)); 1367abd58f01SBen Widawsky if (tmp) { 1368abd58f01SBen Widawsky ret = IRQ_HANDLED; 1369abd58f01SBen Widawsky vcs = tmp >> GEN8_VECS_IRQ_SHIFT; 1370abd58f01SBen Widawsky if (vcs & GT_RENDER_USER_INTERRUPT) 1371abd58f01SBen Widawsky notify_ring(dev, &dev_priv->ring[VECS]); 1372abd58f01SBen Widawsky I915_WRITE(GEN8_GT_IIR(3), tmp); 1373abd58f01SBen Widawsky } else 1374abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (GT3)!\n"); 1375abd58f01SBen Widawsky } 1376abd58f01SBen Widawsky 1377abd58f01SBen Widawsky return ret; 1378abd58f01SBen Widawsky } 1379abd58f01SBen Widawsky 1380b543fb04SEgbert Eich #define HPD_STORM_DETECT_PERIOD 1000 1381b543fb04SEgbert Eich #define HPD_STORM_THRESHOLD 5 1382b543fb04SEgbert Eich 138310a504deSDaniel Vetter static inline void intel_hpd_irq_handler(struct drm_device *dev, 1384b543fb04SEgbert Eich u32 hotplug_trigger, 1385b543fb04SEgbert Eich const u32 *hpd) 1386b543fb04SEgbert Eich { 13872d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 1388b543fb04SEgbert Eich int i; 138910a504deSDaniel Vetter bool storm_detected = false; 1390b543fb04SEgbert Eich 139191d131d2SDaniel Vetter if (!hotplug_trigger) 139291d131d2SDaniel Vetter return; 139391d131d2SDaniel Vetter 1394cc9bd499SImre Deak DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n", 1395cc9bd499SImre Deak hotplug_trigger); 1396cc9bd499SImre Deak 1397b5ea2d56SDaniel Vetter spin_lock(&dev_priv->irq_lock); 1398b543fb04SEgbert Eich for (i = 1; i < HPD_NUM_PINS; i++) { 1399821450c6SEgbert Eich 14003ff04a16SDaniel Vetter if (hpd[i] & hotplug_trigger && 14013ff04a16SDaniel Vetter dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED) { 14023ff04a16SDaniel Vetter /* 14033ff04a16SDaniel Vetter * On GMCH platforms the interrupt mask bits only 14043ff04a16SDaniel Vetter * prevent irq generation, not the setting of the 14053ff04a16SDaniel Vetter * hotplug bits itself. So only WARN about unexpected 14063ff04a16SDaniel Vetter * interrupts on saner platforms. 14073ff04a16SDaniel Vetter */ 14083ff04a16SDaniel Vetter WARN_ONCE(INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev), 1409cba1c073SChris Wilson "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n", 1410cba1c073SChris Wilson hotplug_trigger, i, hpd[i]); 1411b8f102e8SEgbert Eich 14123ff04a16SDaniel Vetter continue; 14133ff04a16SDaniel Vetter } 14143ff04a16SDaniel Vetter 1415b543fb04SEgbert Eich if (!(hpd[i] & hotplug_trigger) || 1416b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED) 1417b543fb04SEgbert Eich continue; 1418b543fb04SEgbert Eich 1419bc5ead8cSJani Nikula dev_priv->hpd_event_bits |= (1 << i); 1420b543fb04SEgbert Eich if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies, 1421b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_last_jiffies 1422b543fb04SEgbert Eich + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) { 1423b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies; 1424b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt = 0; 1425b8f102e8SEgbert Eich DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i); 1426b543fb04SEgbert Eich } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) { 1427b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED; 1428142e2398SEgbert Eich dev_priv->hpd_event_bits &= ~(1 << i); 1429b543fb04SEgbert Eich DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i); 143010a504deSDaniel Vetter storm_detected = true; 1431b543fb04SEgbert Eich } else { 1432b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt++; 1433b8f102e8SEgbert Eich DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i, 1434b8f102e8SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt); 1435b543fb04SEgbert Eich } 1436b543fb04SEgbert Eich } 1437b543fb04SEgbert Eich 143810a504deSDaniel Vetter if (storm_detected) 143910a504deSDaniel Vetter dev_priv->display.hpd_irq_setup(dev); 1440b5ea2d56SDaniel Vetter spin_unlock(&dev_priv->irq_lock); 14415876fa0dSDaniel Vetter 1442645416f5SDaniel Vetter /* 1443645416f5SDaniel Vetter * Our hotplug handler can grab modeset locks (by calling down into the 1444645416f5SDaniel Vetter * fb helpers). Hence it must not be run on our own dev-priv->wq work 1445645416f5SDaniel Vetter * queue for otherwise the flush_work in the pageflip code will 1446645416f5SDaniel Vetter * deadlock. 1447645416f5SDaniel Vetter */ 1448645416f5SDaniel Vetter schedule_work(&dev_priv->hotplug_work); 1449b543fb04SEgbert Eich } 1450b543fb04SEgbert Eich 1451515ac2bbSDaniel Vetter static void gmbus_irq_handler(struct drm_device *dev) 1452515ac2bbSDaniel Vetter { 14532d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 145428c70f16SDaniel Vetter 145528c70f16SDaniel Vetter wake_up_all(&dev_priv->gmbus_wait_queue); 1456515ac2bbSDaniel Vetter } 1457515ac2bbSDaniel Vetter 1458ce99c256SDaniel Vetter static void dp_aux_irq_handler(struct drm_device *dev) 1459ce99c256SDaniel Vetter { 14602d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 14619ee32feaSDaniel Vetter 14629ee32feaSDaniel Vetter wake_up_all(&dev_priv->gmbus_wait_queue); 1463ce99c256SDaniel Vetter } 1464ce99c256SDaniel Vetter 14658bf1e9f1SShuang He #if defined(CONFIG_DEBUG_FS) 1466277de95eSDaniel Vetter static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe, 1467eba94eb9SDaniel Vetter uint32_t crc0, uint32_t crc1, 1468eba94eb9SDaniel Vetter uint32_t crc2, uint32_t crc3, 14698bc5e955SDaniel Vetter uint32_t crc4) 14708bf1e9f1SShuang He { 14718bf1e9f1SShuang He struct drm_i915_private *dev_priv = dev->dev_private; 14728bf1e9f1SShuang He struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe]; 14738bf1e9f1SShuang He struct intel_pipe_crc_entry *entry; 1474ac2300d4SDamien Lespiau int head, tail; 1475b2c88f5bSDamien Lespiau 1476d538bbdfSDamien Lespiau spin_lock(&pipe_crc->lock); 1477d538bbdfSDamien Lespiau 14780c912c79SDamien Lespiau if (!pipe_crc->entries) { 1479d538bbdfSDamien Lespiau spin_unlock(&pipe_crc->lock); 14800c912c79SDamien Lespiau DRM_ERROR("spurious interrupt\n"); 14810c912c79SDamien Lespiau return; 14820c912c79SDamien Lespiau } 14830c912c79SDamien Lespiau 1484d538bbdfSDamien Lespiau head = pipe_crc->head; 1485d538bbdfSDamien Lespiau tail = pipe_crc->tail; 1486b2c88f5bSDamien Lespiau 1487b2c88f5bSDamien Lespiau if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) { 1488d538bbdfSDamien Lespiau spin_unlock(&pipe_crc->lock); 1489b2c88f5bSDamien Lespiau DRM_ERROR("CRC buffer overflowing\n"); 1490b2c88f5bSDamien Lespiau return; 1491b2c88f5bSDamien Lespiau } 1492b2c88f5bSDamien Lespiau 1493b2c88f5bSDamien Lespiau entry = &pipe_crc->entries[head]; 14948bf1e9f1SShuang He 14958bc5e955SDaniel Vetter entry->frame = dev->driver->get_vblank_counter(dev, pipe); 1496eba94eb9SDaniel Vetter entry->crc[0] = crc0; 1497eba94eb9SDaniel Vetter entry->crc[1] = crc1; 1498eba94eb9SDaniel Vetter entry->crc[2] = crc2; 1499eba94eb9SDaniel Vetter entry->crc[3] = crc3; 1500eba94eb9SDaniel Vetter entry->crc[4] = crc4; 1501b2c88f5bSDamien Lespiau 1502b2c88f5bSDamien Lespiau head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1); 1503d538bbdfSDamien Lespiau pipe_crc->head = head; 1504d538bbdfSDamien Lespiau 1505d538bbdfSDamien Lespiau spin_unlock(&pipe_crc->lock); 150607144428SDamien Lespiau 150707144428SDamien Lespiau wake_up_interruptible(&pipe_crc->wq); 15088bf1e9f1SShuang He } 1509277de95eSDaniel Vetter #else 1510277de95eSDaniel Vetter static inline void 1511277de95eSDaniel Vetter display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe, 1512277de95eSDaniel Vetter uint32_t crc0, uint32_t crc1, 1513277de95eSDaniel Vetter uint32_t crc2, uint32_t crc3, 1514277de95eSDaniel Vetter uint32_t crc4) {} 1515277de95eSDaniel Vetter #endif 1516eba94eb9SDaniel Vetter 1517277de95eSDaniel Vetter 1518277de95eSDaniel Vetter static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe) 15195a69b89fSDaniel Vetter { 15205a69b89fSDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 15215a69b89fSDaniel Vetter 1522277de95eSDaniel Vetter display_pipe_crc_irq_handler(dev, pipe, 15235a69b89fSDaniel Vetter I915_READ(PIPE_CRC_RES_1_IVB(pipe)), 15245a69b89fSDaniel Vetter 0, 0, 0, 0); 15255a69b89fSDaniel Vetter } 15265a69b89fSDaniel Vetter 1527277de95eSDaniel Vetter static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe) 1528eba94eb9SDaniel Vetter { 1529eba94eb9SDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 1530eba94eb9SDaniel Vetter 1531277de95eSDaniel Vetter display_pipe_crc_irq_handler(dev, pipe, 1532eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_1_IVB(pipe)), 1533eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_2_IVB(pipe)), 1534eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_3_IVB(pipe)), 1535eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_4_IVB(pipe)), 15368bc5e955SDaniel Vetter I915_READ(PIPE_CRC_RES_5_IVB(pipe))); 1537eba94eb9SDaniel Vetter } 15385b3a856bSDaniel Vetter 1539277de95eSDaniel Vetter static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe) 15405b3a856bSDaniel Vetter { 15415b3a856bSDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 15420b5c5ed0SDaniel Vetter uint32_t res1, res2; 15430b5c5ed0SDaniel Vetter 15440b5c5ed0SDaniel Vetter if (INTEL_INFO(dev)->gen >= 3) 15450b5c5ed0SDaniel Vetter res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe)); 15460b5c5ed0SDaniel Vetter else 15470b5c5ed0SDaniel Vetter res1 = 0; 15480b5c5ed0SDaniel Vetter 15490b5c5ed0SDaniel Vetter if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) 15500b5c5ed0SDaniel Vetter res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe)); 15510b5c5ed0SDaniel Vetter else 15520b5c5ed0SDaniel Vetter res2 = 0; 15535b3a856bSDaniel Vetter 1554277de95eSDaniel Vetter display_pipe_crc_irq_handler(dev, pipe, 15550b5c5ed0SDaniel Vetter I915_READ(PIPE_CRC_RES_RED(pipe)), 15560b5c5ed0SDaniel Vetter I915_READ(PIPE_CRC_RES_GREEN(pipe)), 15570b5c5ed0SDaniel Vetter I915_READ(PIPE_CRC_RES_BLUE(pipe)), 15580b5c5ed0SDaniel Vetter res1, res2); 15595b3a856bSDaniel Vetter } 15608bf1e9f1SShuang He 15611403c0d4SPaulo Zanoni /* The RPS events need forcewake, so we add them to a work queue and mask their 15621403c0d4SPaulo Zanoni * IMR bits until the work is done. Other interrupts can be processed without 15631403c0d4SPaulo Zanoni * the work queue. */ 15641403c0d4SPaulo Zanoni static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir) 1565baf02a1fSBen Widawsky { 1566a6706b45SDeepak S if (pm_iir & dev_priv->pm_rps_events) { 156759cdb63dSDaniel Vetter spin_lock(&dev_priv->irq_lock); 1568a6706b45SDeepak S dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events; 1569a6706b45SDeepak S snb_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events); 157059cdb63dSDaniel Vetter spin_unlock(&dev_priv->irq_lock); 15712adbee62SDaniel Vetter 15722adbee62SDaniel Vetter queue_work(dev_priv->wq, &dev_priv->rps.work); 157341a05a3aSDaniel Vetter } 1574baf02a1fSBen Widawsky 15751403c0d4SPaulo Zanoni if (HAS_VEBOX(dev_priv->dev)) { 157612638c57SBen Widawsky if (pm_iir & PM_VEBOX_USER_INTERRUPT) 157712638c57SBen Widawsky notify_ring(dev_priv->dev, &dev_priv->ring[VECS]); 157812638c57SBen Widawsky 157912638c57SBen Widawsky if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) { 158058174462SMika Kuoppala i915_handle_error(dev_priv->dev, false, 158158174462SMika Kuoppala "VEBOX CS error interrupt 0x%08x", 158258174462SMika Kuoppala pm_iir); 158312638c57SBen Widawsky } 158412638c57SBen Widawsky } 15851403c0d4SPaulo Zanoni } 1586baf02a1fSBen Widawsky 1587c1874ed7SImre Deak static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir) 15887e231dbeSJesse Barnes { 1589c1874ed7SImre Deak struct drm_i915_private *dev_priv = dev->dev_private; 159091d181ddSImre Deak u32 pipe_stats[I915_MAX_PIPES] = { }; 15917e231dbeSJesse Barnes int pipe; 15927e231dbeSJesse Barnes 159358ead0d7SImre Deak spin_lock(&dev_priv->irq_lock); 15947e231dbeSJesse Barnes for_each_pipe(pipe) { 159591d181ddSImre Deak int reg; 1596bbb5eebfSDaniel Vetter u32 mask, iir_bit = 0; 159791d181ddSImre Deak 1598bbb5eebfSDaniel Vetter /* 1599bbb5eebfSDaniel Vetter * PIPESTAT bits get signalled even when the interrupt is 1600bbb5eebfSDaniel Vetter * disabled with the mask bits, and some of the status bits do 1601bbb5eebfSDaniel Vetter * not generate interrupts at all (like the underrun bit). Hence 1602bbb5eebfSDaniel Vetter * we need to be careful that we only handle what we want to 1603bbb5eebfSDaniel Vetter * handle. 1604bbb5eebfSDaniel Vetter */ 1605bbb5eebfSDaniel Vetter mask = 0; 1606bbb5eebfSDaniel Vetter if (__cpu_fifo_underrun_reporting_enabled(dev, pipe)) 1607bbb5eebfSDaniel Vetter mask |= PIPE_FIFO_UNDERRUN_STATUS; 1608bbb5eebfSDaniel Vetter 1609bbb5eebfSDaniel Vetter switch (pipe) { 1610bbb5eebfSDaniel Vetter case PIPE_A: 1611bbb5eebfSDaniel Vetter iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT; 1612bbb5eebfSDaniel Vetter break; 1613bbb5eebfSDaniel Vetter case PIPE_B: 1614bbb5eebfSDaniel Vetter iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT; 1615bbb5eebfSDaniel Vetter break; 1616bbb5eebfSDaniel Vetter } 1617bbb5eebfSDaniel Vetter if (iir & iir_bit) 1618bbb5eebfSDaniel Vetter mask |= dev_priv->pipestat_irq_mask[pipe]; 1619bbb5eebfSDaniel Vetter 1620bbb5eebfSDaniel Vetter if (!mask) 162191d181ddSImre Deak continue; 162291d181ddSImre Deak 162391d181ddSImre Deak reg = PIPESTAT(pipe); 1624bbb5eebfSDaniel Vetter mask |= PIPESTAT_INT_ENABLE_MASK; 1625bbb5eebfSDaniel Vetter pipe_stats[pipe] = I915_READ(reg) & mask; 16267e231dbeSJesse Barnes 16277e231dbeSJesse Barnes /* 16287e231dbeSJesse Barnes * Clear the PIPE*STAT regs before the IIR 16297e231dbeSJesse Barnes */ 163091d181ddSImre Deak if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS | 163191d181ddSImre Deak PIPESTAT_INT_STATUS_MASK)) 16327e231dbeSJesse Barnes I915_WRITE(reg, pipe_stats[pipe]); 16337e231dbeSJesse Barnes } 163458ead0d7SImre Deak spin_unlock(&dev_priv->irq_lock); 16357e231dbeSJesse Barnes 163631acc7f5SJesse Barnes for_each_pipe(pipe) { 16377b5562d4SJesse Barnes if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS) 163831acc7f5SJesse Barnes drm_handle_vblank(dev, pipe); 163931acc7f5SJesse Barnes 1640579a9b0eSImre Deak if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) { 164131acc7f5SJesse Barnes intel_prepare_page_flip(dev, pipe); 164231acc7f5SJesse Barnes intel_finish_page_flip(dev, pipe); 164331acc7f5SJesse Barnes } 16444356d586SDaniel Vetter 16454356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 1646277de95eSDaniel Vetter i9xx_pipe_crc_irq_handler(dev, pipe); 16472d9d2b0bSVille Syrjälä 16482d9d2b0bSVille Syrjälä if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS && 16492d9d2b0bSVille Syrjälä intel_set_cpu_fifo_underrun_reporting(dev, pipe, false)) 1650fc2c807bSVille Syrjälä DRM_ERROR("pipe %c underrun\n", pipe_name(pipe)); 165131acc7f5SJesse Barnes } 165231acc7f5SJesse Barnes 1653c1874ed7SImre Deak if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 1654c1874ed7SImre Deak gmbus_irq_handler(dev); 1655c1874ed7SImre Deak } 1656c1874ed7SImre Deak 165716c6c56bSVille Syrjälä static void i9xx_hpd_irq_handler(struct drm_device *dev) 165816c6c56bSVille Syrjälä { 165916c6c56bSVille Syrjälä struct drm_i915_private *dev_priv = dev->dev_private; 166016c6c56bSVille Syrjälä u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); 166116c6c56bSVille Syrjälä 166216c6c56bSVille Syrjälä if (IS_G4X(dev)) { 166316c6c56bSVille Syrjälä u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X; 166416c6c56bSVille Syrjälä 166516c6c56bSVille Syrjälä intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_g4x); 166616c6c56bSVille Syrjälä } else { 166716c6c56bSVille Syrjälä u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915; 166816c6c56bSVille Syrjälä 166916c6c56bSVille Syrjälä intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915); 167016c6c56bSVille Syrjälä } 167116c6c56bSVille Syrjälä 167216c6c56bSVille Syrjälä if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) && 167316c6c56bSVille Syrjälä hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X) 167416c6c56bSVille Syrjälä dp_aux_irq_handler(dev); 167516c6c56bSVille Syrjälä 167616c6c56bSVille Syrjälä I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); 167716c6c56bSVille Syrjälä /* 167816c6c56bSVille Syrjälä * Make sure hotplug status is cleared before we clear IIR, or else we 167916c6c56bSVille Syrjälä * may miss hotplug events. 168016c6c56bSVille Syrjälä */ 168116c6c56bSVille Syrjälä POSTING_READ(PORT_HOTPLUG_STAT); 168216c6c56bSVille Syrjälä } 168316c6c56bSVille Syrjälä 1684c1874ed7SImre Deak static irqreturn_t valleyview_irq_handler(int irq, void *arg) 1685c1874ed7SImre Deak { 1686c1874ed7SImre Deak struct drm_device *dev = (struct drm_device *) arg; 16872d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 1688c1874ed7SImre Deak u32 iir, gt_iir, pm_iir; 1689c1874ed7SImre Deak irqreturn_t ret = IRQ_NONE; 1690c1874ed7SImre Deak 1691c1874ed7SImre Deak while (true) { 1692c1874ed7SImre Deak iir = I915_READ(VLV_IIR); 1693c1874ed7SImre Deak gt_iir = I915_READ(GTIIR); 1694c1874ed7SImre Deak pm_iir = I915_READ(GEN6_PMIIR); 1695c1874ed7SImre Deak 1696c1874ed7SImre Deak if (gt_iir == 0 && pm_iir == 0 && iir == 0) 1697c1874ed7SImre Deak goto out; 1698c1874ed7SImre Deak 1699c1874ed7SImre Deak ret = IRQ_HANDLED; 1700c1874ed7SImre Deak 1701c1874ed7SImre Deak snb_gt_irq_handler(dev, dev_priv, gt_iir); 1702c1874ed7SImre Deak 1703c1874ed7SImre Deak valleyview_pipestat_irq_handler(dev, iir); 1704c1874ed7SImre Deak 17057e231dbeSJesse Barnes /* Consume port. Then clear IIR or we'll miss events */ 170616c6c56bSVille Syrjälä if (iir & I915_DISPLAY_PORT_INTERRUPT) 170716c6c56bSVille Syrjälä i9xx_hpd_irq_handler(dev); 17087e231dbeSJesse Barnes 170960611c13SPaulo Zanoni if (pm_iir) 1710d0ecd7e2SDaniel Vetter gen6_rps_irq_handler(dev_priv, pm_iir); 17117e231dbeSJesse Barnes 17127e231dbeSJesse Barnes I915_WRITE(GTIIR, gt_iir); 17137e231dbeSJesse Barnes I915_WRITE(GEN6_PMIIR, pm_iir); 17147e231dbeSJesse Barnes I915_WRITE(VLV_IIR, iir); 17157e231dbeSJesse Barnes } 17167e231dbeSJesse Barnes 17177e231dbeSJesse Barnes out: 17187e231dbeSJesse Barnes return ret; 17197e231dbeSJesse Barnes } 17207e231dbeSJesse Barnes 172123e81d69SAdam Jackson static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir) 1722776ad806SJesse Barnes { 17232d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 17249db4a9c7SJesse Barnes int pipe; 1725b543fb04SEgbert Eich u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK; 1726776ad806SJesse Barnes 172710a504deSDaniel Vetter intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx); 172891d131d2SDaniel Vetter 1729cfc33bf7SVille Syrjälä if (pch_iir & SDE_AUDIO_POWER_MASK) { 1730cfc33bf7SVille Syrjälä int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >> 1731776ad806SJesse Barnes SDE_AUDIO_POWER_SHIFT); 1732cfc33bf7SVille Syrjälä DRM_DEBUG_DRIVER("PCH audio power change on port %d\n", 1733cfc33bf7SVille Syrjälä port_name(port)); 1734cfc33bf7SVille Syrjälä } 1735776ad806SJesse Barnes 1736ce99c256SDaniel Vetter if (pch_iir & SDE_AUX_MASK) 1737ce99c256SDaniel Vetter dp_aux_irq_handler(dev); 1738ce99c256SDaniel Vetter 1739776ad806SJesse Barnes if (pch_iir & SDE_GMBUS) 1740515ac2bbSDaniel Vetter gmbus_irq_handler(dev); 1741776ad806SJesse Barnes 1742776ad806SJesse Barnes if (pch_iir & SDE_AUDIO_HDCP_MASK) 1743776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n"); 1744776ad806SJesse Barnes 1745776ad806SJesse Barnes if (pch_iir & SDE_AUDIO_TRANS_MASK) 1746776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n"); 1747776ad806SJesse Barnes 1748776ad806SJesse Barnes if (pch_iir & SDE_POISON) 1749776ad806SJesse Barnes DRM_ERROR("PCH poison interrupt\n"); 1750776ad806SJesse Barnes 17519db4a9c7SJesse Barnes if (pch_iir & SDE_FDI_MASK) 17529db4a9c7SJesse Barnes for_each_pipe(pipe) 17539db4a9c7SJesse Barnes DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", 17549db4a9c7SJesse Barnes pipe_name(pipe), 17559db4a9c7SJesse Barnes I915_READ(FDI_RX_IIR(pipe))); 1756776ad806SJesse Barnes 1757776ad806SJesse Barnes if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE)) 1758776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n"); 1759776ad806SJesse Barnes 1760776ad806SJesse Barnes if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR)) 1761776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n"); 1762776ad806SJesse Barnes 1763776ad806SJesse Barnes if (pch_iir & SDE_TRANSA_FIFO_UNDER) 17648664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, 17658664281bSPaulo Zanoni false)) 1766fc2c807bSVille Syrjälä DRM_ERROR("PCH transcoder A FIFO underrun\n"); 17678664281bSPaulo Zanoni 17688664281bSPaulo Zanoni if (pch_iir & SDE_TRANSB_FIFO_UNDER) 17698664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B, 17708664281bSPaulo Zanoni false)) 1771fc2c807bSVille Syrjälä DRM_ERROR("PCH transcoder B FIFO underrun\n"); 17728664281bSPaulo Zanoni } 17738664281bSPaulo Zanoni 17748664281bSPaulo Zanoni static void ivb_err_int_handler(struct drm_device *dev) 17758664281bSPaulo Zanoni { 17768664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 17778664281bSPaulo Zanoni u32 err_int = I915_READ(GEN7_ERR_INT); 17785a69b89fSDaniel Vetter enum pipe pipe; 17798664281bSPaulo Zanoni 1780de032bf4SPaulo Zanoni if (err_int & ERR_INT_POISON) 1781de032bf4SPaulo Zanoni DRM_ERROR("Poison interrupt\n"); 1782de032bf4SPaulo Zanoni 17835a69b89fSDaniel Vetter for_each_pipe(pipe) { 17845a69b89fSDaniel Vetter if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) { 17855a69b89fSDaniel Vetter if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, 17865a69b89fSDaniel Vetter false)) 1787fc2c807bSVille Syrjälä DRM_ERROR("Pipe %c FIFO underrun\n", 17885a69b89fSDaniel Vetter pipe_name(pipe)); 17895a69b89fSDaniel Vetter } 17908664281bSPaulo Zanoni 17915a69b89fSDaniel Vetter if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) { 17925a69b89fSDaniel Vetter if (IS_IVYBRIDGE(dev)) 1793277de95eSDaniel Vetter ivb_pipe_crc_irq_handler(dev, pipe); 17945a69b89fSDaniel Vetter else 1795277de95eSDaniel Vetter hsw_pipe_crc_irq_handler(dev, pipe); 17965a69b89fSDaniel Vetter } 17975a69b89fSDaniel Vetter } 17988bf1e9f1SShuang He 17998664281bSPaulo Zanoni I915_WRITE(GEN7_ERR_INT, err_int); 18008664281bSPaulo Zanoni } 18018664281bSPaulo Zanoni 18028664281bSPaulo Zanoni static void cpt_serr_int_handler(struct drm_device *dev) 18038664281bSPaulo Zanoni { 18048664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 18058664281bSPaulo Zanoni u32 serr_int = I915_READ(SERR_INT); 18068664281bSPaulo Zanoni 1807de032bf4SPaulo Zanoni if (serr_int & SERR_INT_POISON) 1808de032bf4SPaulo Zanoni DRM_ERROR("PCH poison interrupt\n"); 1809de032bf4SPaulo Zanoni 18108664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN) 18118664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, 18128664281bSPaulo Zanoni false)) 1813fc2c807bSVille Syrjälä DRM_ERROR("PCH transcoder A FIFO underrun\n"); 18148664281bSPaulo Zanoni 18158664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN) 18168664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B, 18178664281bSPaulo Zanoni false)) 1818fc2c807bSVille Syrjälä DRM_ERROR("PCH transcoder B FIFO underrun\n"); 18198664281bSPaulo Zanoni 18208664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN) 18218664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C, 18228664281bSPaulo Zanoni false)) 1823fc2c807bSVille Syrjälä DRM_ERROR("PCH transcoder C FIFO underrun\n"); 18248664281bSPaulo Zanoni 18258664281bSPaulo Zanoni I915_WRITE(SERR_INT, serr_int); 1826776ad806SJesse Barnes } 1827776ad806SJesse Barnes 182823e81d69SAdam Jackson static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir) 182923e81d69SAdam Jackson { 18302d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 183123e81d69SAdam Jackson int pipe; 1832b543fb04SEgbert Eich u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT; 183323e81d69SAdam Jackson 183410a504deSDaniel Vetter intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt); 183591d131d2SDaniel Vetter 1836cfc33bf7SVille Syrjälä if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) { 1837cfc33bf7SVille Syrjälä int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >> 183823e81d69SAdam Jackson SDE_AUDIO_POWER_SHIFT_CPT); 1839cfc33bf7SVille Syrjälä DRM_DEBUG_DRIVER("PCH audio power change on port %c\n", 1840cfc33bf7SVille Syrjälä port_name(port)); 1841cfc33bf7SVille Syrjälä } 184223e81d69SAdam Jackson 184323e81d69SAdam Jackson if (pch_iir & SDE_AUX_MASK_CPT) 1844ce99c256SDaniel Vetter dp_aux_irq_handler(dev); 184523e81d69SAdam Jackson 184623e81d69SAdam Jackson if (pch_iir & SDE_GMBUS_CPT) 1847515ac2bbSDaniel Vetter gmbus_irq_handler(dev); 184823e81d69SAdam Jackson 184923e81d69SAdam Jackson if (pch_iir & SDE_AUDIO_CP_REQ_CPT) 185023e81d69SAdam Jackson DRM_DEBUG_DRIVER("Audio CP request interrupt\n"); 185123e81d69SAdam Jackson 185223e81d69SAdam Jackson if (pch_iir & SDE_AUDIO_CP_CHG_CPT) 185323e81d69SAdam Jackson DRM_DEBUG_DRIVER("Audio CP change interrupt\n"); 185423e81d69SAdam Jackson 185523e81d69SAdam Jackson if (pch_iir & SDE_FDI_MASK_CPT) 185623e81d69SAdam Jackson for_each_pipe(pipe) 185723e81d69SAdam Jackson DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", 185823e81d69SAdam Jackson pipe_name(pipe), 185923e81d69SAdam Jackson I915_READ(FDI_RX_IIR(pipe))); 18608664281bSPaulo Zanoni 18618664281bSPaulo Zanoni if (pch_iir & SDE_ERROR_CPT) 18628664281bSPaulo Zanoni cpt_serr_int_handler(dev); 186323e81d69SAdam Jackson } 186423e81d69SAdam Jackson 1865c008bc6eSPaulo Zanoni static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir) 1866c008bc6eSPaulo Zanoni { 1867c008bc6eSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 186840da17c2SDaniel Vetter enum pipe pipe; 1869c008bc6eSPaulo Zanoni 1870c008bc6eSPaulo Zanoni if (de_iir & DE_AUX_CHANNEL_A) 1871c008bc6eSPaulo Zanoni dp_aux_irq_handler(dev); 1872c008bc6eSPaulo Zanoni 1873c008bc6eSPaulo Zanoni if (de_iir & DE_GSE) 1874c008bc6eSPaulo Zanoni intel_opregion_asle_intr(dev); 1875c008bc6eSPaulo Zanoni 1876c008bc6eSPaulo Zanoni if (de_iir & DE_POISON) 1877c008bc6eSPaulo Zanoni DRM_ERROR("Poison interrupt\n"); 1878c008bc6eSPaulo Zanoni 187940da17c2SDaniel Vetter for_each_pipe(pipe) { 188040da17c2SDaniel Vetter if (de_iir & DE_PIPE_VBLANK(pipe)) 188140da17c2SDaniel Vetter drm_handle_vblank(dev, pipe); 1882c008bc6eSPaulo Zanoni 188340da17c2SDaniel Vetter if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe)) 188440da17c2SDaniel Vetter if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, false)) 1885fc2c807bSVille Syrjälä DRM_ERROR("Pipe %c FIFO underrun\n", 188640da17c2SDaniel Vetter pipe_name(pipe)); 1887c008bc6eSPaulo Zanoni 188840da17c2SDaniel Vetter if (de_iir & DE_PIPE_CRC_DONE(pipe)) 188940da17c2SDaniel Vetter i9xx_pipe_crc_irq_handler(dev, pipe); 18905b3a856bSDaniel Vetter 189140da17c2SDaniel Vetter /* plane/pipes map 1:1 on ilk+ */ 189240da17c2SDaniel Vetter if (de_iir & DE_PLANE_FLIP_DONE(pipe)) { 189340da17c2SDaniel Vetter intel_prepare_page_flip(dev, pipe); 189440da17c2SDaniel Vetter intel_finish_page_flip_plane(dev, pipe); 1895c008bc6eSPaulo Zanoni } 1896c008bc6eSPaulo Zanoni } 1897c008bc6eSPaulo Zanoni 1898c008bc6eSPaulo Zanoni /* check event from PCH */ 1899c008bc6eSPaulo Zanoni if (de_iir & DE_PCH_EVENT) { 1900c008bc6eSPaulo Zanoni u32 pch_iir = I915_READ(SDEIIR); 1901c008bc6eSPaulo Zanoni 1902c008bc6eSPaulo Zanoni if (HAS_PCH_CPT(dev)) 1903c008bc6eSPaulo Zanoni cpt_irq_handler(dev, pch_iir); 1904c008bc6eSPaulo Zanoni else 1905c008bc6eSPaulo Zanoni ibx_irq_handler(dev, pch_iir); 1906c008bc6eSPaulo Zanoni 1907c008bc6eSPaulo Zanoni /* should clear PCH hotplug event before clear CPU irq */ 1908c008bc6eSPaulo Zanoni I915_WRITE(SDEIIR, pch_iir); 1909c008bc6eSPaulo Zanoni } 1910c008bc6eSPaulo Zanoni 1911c008bc6eSPaulo Zanoni if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT) 1912c008bc6eSPaulo Zanoni ironlake_rps_change_irq_handler(dev); 1913c008bc6eSPaulo Zanoni } 1914c008bc6eSPaulo Zanoni 19159719fb98SPaulo Zanoni static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir) 19169719fb98SPaulo Zanoni { 19179719fb98SPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 191807d27e20SDamien Lespiau enum pipe pipe; 19199719fb98SPaulo Zanoni 19209719fb98SPaulo Zanoni if (de_iir & DE_ERR_INT_IVB) 19219719fb98SPaulo Zanoni ivb_err_int_handler(dev); 19229719fb98SPaulo Zanoni 19239719fb98SPaulo Zanoni if (de_iir & DE_AUX_CHANNEL_A_IVB) 19249719fb98SPaulo Zanoni dp_aux_irq_handler(dev); 19259719fb98SPaulo Zanoni 19269719fb98SPaulo Zanoni if (de_iir & DE_GSE_IVB) 19279719fb98SPaulo Zanoni intel_opregion_asle_intr(dev); 19289719fb98SPaulo Zanoni 192907d27e20SDamien Lespiau for_each_pipe(pipe) { 193007d27e20SDamien Lespiau if (de_iir & (DE_PIPE_VBLANK_IVB(pipe))) 193107d27e20SDamien Lespiau drm_handle_vblank(dev, pipe); 193240da17c2SDaniel Vetter 193340da17c2SDaniel Vetter /* plane/pipes map 1:1 on ilk+ */ 193407d27e20SDamien Lespiau if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) { 193507d27e20SDamien Lespiau intel_prepare_page_flip(dev, pipe); 193607d27e20SDamien Lespiau intel_finish_page_flip_plane(dev, pipe); 19379719fb98SPaulo Zanoni } 19389719fb98SPaulo Zanoni } 19399719fb98SPaulo Zanoni 19409719fb98SPaulo Zanoni /* check event from PCH */ 19419719fb98SPaulo Zanoni if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) { 19429719fb98SPaulo Zanoni u32 pch_iir = I915_READ(SDEIIR); 19439719fb98SPaulo Zanoni 19449719fb98SPaulo Zanoni cpt_irq_handler(dev, pch_iir); 19459719fb98SPaulo Zanoni 19469719fb98SPaulo Zanoni /* clear PCH hotplug event before clear CPU irq */ 19479719fb98SPaulo Zanoni I915_WRITE(SDEIIR, pch_iir); 19489719fb98SPaulo Zanoni } 19499719fb98SPaulo Zanoni } 19509719fb98SPaulo Zanoni 1951f1af8fc1SPaulo Zanoni static irqreturn_t ironlake_irq_handler(int irq, void *arg) 1952b1f14ad0SJesse Barnes { 1953b1f14ad0SJesse Barnes struct drm_device *dev = (struct drm_device *) arg; 19542d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 1955f1af8fc1SPaulo Zanoni u32 de_iir, gt_iir, de_ier, sde_ier = 0; 19560e43406bSChris Wilson irqreturn_t ret = IRQ_NONE; 1957b1f14ad0SJesse Barnes 19588664281bSPaulo Zanoni /* We get interrupts on unclaimed registers, so check for this before we 19598664281bSPaulo Zanoni * do any I915_{READ,WRITE}. */ 1960907b28c5SChris Wilson intel_uncore_check_errors(dev); 19618664281bSPaulo Zanoni 1962b1f14ad0SJesse Barnes /* disable master interrupt before clearing iir */ 1963b1f14ad0SJesse Barnes de_ier = I915_READ(DEIER); 1964b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL); 196523a78516SPaulo Zanoni POSTING_READ(DEIER); 19660e43406bSChris Wilson 196744498aeaSPaulo Zanoni /* Disable south interrupts. We'll only write to SDEIIR once, so further 196844498aeaSPaulo Zanoni * interrupts will will be stored on its back queue, and then we'll be 196944498aeaSPaulo Zanoni * able to process them after we restore SDEIER (as soon as we restore 197044498aeaSPaulo Zanoni * it, we'll get an interrupt if SDEIIR still has something to process 197144498aeaSPaulo Zanoni * due to its back queue). */ 1972ab5c608bSBen Widawsky if (!HAS_PCH_NOP(dev)) { 197344498aeaSPaulo Zanoni sde_ier = I915_READ(SDEIER); 197444498aeaSPaulo Zanoni I915_WRITE(SDEIER, 0); 197544498aeaSPaulo Zanoni POSTING_READ(SDEIER); 1976ab5c608bSBen Widawsky } 197744498aeaSPaulo Zanoni 19780e43406bSChris Wilson gt_iir = I915_READ(GTIIR); 19790e43406bSChris Wilson if (gt_iir) { 1980d8fc8a47SPaulo Zanoni if (INTEL_INFO(dev)->gen >= 6) 19810e43406bSChris Wilson snb_gt_irq_handler(dev, dev_priv, gt_iir); 1982d8fc8a47SPaulo Zanoni else 1983d8fc8a47SPaulo Zanoni ilk_gt_irq_handler(dev, dev_priv, gt_iir); 19840e43406bSChris Wilson I915_WRITE(GTIIR, gt_iir); 19850e43406bSChris Wilson ret = IRQ_HANDLED; 19860e43406bSChris Wilson } 1987b1f14ad0SJesse Barnes 1988b1f14ad0SJesse Barnes de_iir = I915_READ(DEIIR); 19890e43406bSChris Wilson if (de_iir) { 1990f1af8fc1SPaulo Zanoni if (INTEL_INFO(dev)->gen >= 7) 19919719fb98SPaulo Zanoni ivb_display_irq_handler(dev, de_iir); 1992f1af8fc1SPaulo Zanoni else 1993f1af8fc1SPaulo Zanoni ilk_display_irq_handler(dev, de_iir); 19940e43406bSChris Wilson I915_WRITE(DEIIR, de_iir); 19950e43406bSChris Wilson ret = IRQ_HANDLED; 19960e43406bSChris Wilson } 19970e43406bSChris Wilson 1998f1af8fc1SPaulo Zanoni if (INTEL_INFO(dev)->gen >= 6) { 1999f1af8fc1SPaulo Zanoni u32 pm_iir = I915_READ(GEN6_PMIIR); 20000e43406bSChris Wilson if (pm_iir) { 2001d0ecd7e2SDaniel Vetter gen6_rps_irq_handler(dev_priv, pm_iir); 2002b1f14ad0SJesse Barnes I915_WRITE(GEN6_PMIIR, pm_iir); 20030e43406bSChris Wilson ret = IRQ_HANDLED; 20040e43406bSChris Wilson } 2005f1af8fc1SPaulo Zanoni } 2006b1f14ad0SJesse Barnes 2007b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier); 2008b1f14ad0SJesse Barnes POSTING_READ(DEIER); 2009ab5c608bSBen Widawsky if (!HAS_PCH_NOP(dev)) { 201044498aeaSPaulo Zanoni I915_WRITE(SDEIER, sde_ier); 201144498aeaSPaulo Zanoni POSTING_READ(SDEIER); 2012ab5c608bSBen Widawsky } 2013b1f14ad0SJesse Barnes 2014b1f14ad0SJesse Barnes return ret; 2015b1f14ad0SJesse Barnes } 2016b1f14ad0SJesse Barnes 2017abd58f01SBen Widawsky static irqreturn_t gen8_irq_handler(int irq, void *arg) 2018abd58f01SBen Widawsky { 2019abd58f01SBen Widawsky struct drm_device *dev = arg; 2020abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 2021abd58f01SBen Widawsky u32 master_ctl; 2022abd58f01SBen Widawsky irqreturn_t ret = IRQ_NONE; 2023abd58f01SBen Widawsky uint32_t tmp = 0; 2024c42664ccSDaniel Vetter enum pipe pipe; 2025abd58f01SBen Widawsky 2026abd58f01SBen Widawsky master_ctl = I915_READ(GEN8_MASTER_IRQ); 2027abd58f01SBen Widawsky master_ctl &= ~GEN8_MASTER_IRQ_CONTROL; 2028abd58f01SBen Widawsky if (!master_ctl) 2029abd58f01SBen Widawsky return IRQ_NONE; 2030abd58f01SBen Widawsky 2031abd58f01SBen Widawsky I915_WRITE(GEN8_MASTER_IRQ, 0); 2032abd58f01SBen Widawsky POSTING_READ(GEN8_MASTER_IRQ); 2033abd58f01SBen Widawsky 2034abd58f01SBen Widawsky ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl); 2035abd58f01SBen Widawsky 2036abd58f01SBen Widawsky if (master_ctl & GEN8_DE_MISC_IRQ) { 2037abd58f01SBen Widawsky tmp = I915_READ(GEN8_DE_MISC_IIR); 2038abd58f01SBen Widawsky if (tmp & GEN8_DE_MISC_GSE) 2039abd58f01SBen Widawsky intel_opregion_asle_intr(dev); 2040abd58f01SBen Widawsky else if (tmp) 2041abd58f01SBen Widawsky DRM_ERROR("Unexpected DE Misc interrupt\n"); 2042abd58f01SBen Widawsky else 2043abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (DE MISC)!\n"); 2044abd58f01SBen Widawsky 2045abd58f01SBen Widawsky if (tmp) { 2046abd58f01SBen Widawsky I915_WRITE(GEN8_DE_MISC_IIR, tmp); 2047abd58f01SBen Widawsky ret = IRQ_HANDLED; 2048abd58f01SBen Widawsky } 2049abd58f01SBen Widawsky } 2050abd58f01SBen Widawsky 20516d766f02SDaniel Vetter if (master_ctl & GEN8_DE_PORT_IRQ) { 20526d766f02SDaniel Vetter tmp = I915_READ(GEN8_DE_PORT_IIR); 20536d766f02SDaniel Vetter if (tmp & GEN8_AUX_CHANNEL_A) 20546d766f02SDaniel Vetter dp_aux_irq_handler(dev); 20556d766f02SDaniel Vetter else if (tmp) 20566d766f02SDaniel Vetter DRM_ERROR("Unexpected DE Port interrupt\n"); 20576d766f02SDaniel Vetter else 20586d766f02SDaniel Vetter DRM_ERROR("The master control interrupt lied (DE PORT)!\n"); 20596d766f02SDaniel Vetter 20606d766f02SDaniel Vetter if (tmp) { 20616d766f02SDaniel Vetter I915_WRITE(GEN8_DE_PORT_IIR, tmp); 20626d766f02SDaniel Vetter ret = IRQ_HANDLED; 20636d766f02SDaniel Vetter } 20646d766f02SDaniel Vetter } 20656d766f02SDaniel Vetter 2066abd58f01SBen Widawsky for_each_pipe(pipe) { 2067abd58f01SBen Widawsky uint32_t pipe_iir; 2068abd58f01SBen Widawsky 2069c42664ccSDaniel Vetter if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe))) 2070c42664ccSDaniel Vetter continue; 2071c42664ccSDaniel Vetter 2072abd58f01SBen Widawsky pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe)); 2073abd58f01SBen Widawsky if (pipe_iir & GEN8_PIPE_VBLANK) 2074abd58f01SBen Widawsky drm_handle_vblank(dev, pipe); 2075abd58f01SBen Widawsky 2076d0e1f1cbSDamien Lespiau if (pipe_iir & GEN8_PIPE_PRIMARY_FLIP_DONE) { 2077abd58f01SBen Widawsky intel_prepare_page_flip(dev, pipe); 2078abd58f01SBen Widawsky intel_finish_page_flip_plane(dev, pipe); 2079abd58f01SBen Widawsky } 2080abd58f01SBen Widawsky 20810fbe7870SDaniel Vetter if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE) 20820fbe7870SDaniel Vetter hsw_pipe_crc_irq_handler(dev, pipe); 20830fbe7870SDaniel Vetter 208438d83c96SDaniel Vetter if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN) { 208538d83c96SDaniel Vetter if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, 208638d83c96SDaniel Vetter false)) 2087fc2c807bSVille Syrjälä DRM_ERROR("Pipe %c FIFO underrun\n", 208838d83c96SDaniel Vetter pipe_name(pipe)); 208938d83c96SDaniel Vetter } 209038d83c96SDaniel Vetter 209130100f2bSDaniel Vetter if (pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS) { 209230100f2bSDaniel Vetter DRM_ERROR("Fault errors on pipe %c\n: 0x%08x", 209330100f2bSDaniel Vetter pipe_name(pipe), 209430100f2bSDaniel Vetter pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS); 209530100f2bSDaniel Vetter } 2096abd58f01SBen Widawsky 2097abd58f01SBen Widawsky if (pipe_iir) { 2098abd58f01SBen Widawsky ret = IRQ_HANDLED; 2099abd58f01SBen Widawsky I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir); 2100c42664ccSDaniel Vetter } else 2101abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (DE PIPE)!\n"); 2102abd58f01SBen Widawsky } 2103abd58f01SBen Widawsky 210492d03a80SDaniel Vetter if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) { 210592d03a80SDaniel Vetter /* 210692d03a80SDaniel Vetter * FIXME(BDW): Assume for now that the new interrupt handling 210792d03a80SDaniel Vetter * scheme also closed the SDE interrupt handling race we've seen 210892d03a80SDaniel Vetter * on older pch-split platforms. But this needs testing. 210992d03a80SDaniel Vetter */ 211092d03a80SDaniel Vetter u32 pch_iir = I915_READ(SDEIIR); 211192d03a80SDaniel Vetter 211292d03a80SDaniel Vetter cpt_irq_handler(dev, pch_iir); 211392d03a80SDaniel Vetter 211492d03a80SDaniel Vetter if (pch_iir) { 211592d03a80SDaniel Vetter I915_WRITE(SDEIIR, pch_iir); 211692d03a80SDaniel Vetter ret = IRQ_HANDLED; 211792d03a80SDaniel Vetter } 211892d03a80SDaniel Vetter } 211992d03a80SDaniel Vetter 2120abd58f01SBen Widawsky I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); 2121abd58f01SBen Widawsky POSTING_READ(GEN8_MASTER_IRQ); 2122abd58f01SBen Widawsky 2123abd58f01SBen Widawsky return ret; 2124abd58f01SBen Widawsky } 2125abd58f01SBen Widawsky 212617e1df07SDaniel Vetter static void i915_error_wake_up(struct drm_i915_private *dev_priv, 212717e1df07SDaniel Vetter bool reset_completed) 212817e1df07SDaniel Vetter { 212917e1df07SDaniel Vetter struct intel_ring_buffer *ring; 213017e1df07SDaniel Vetter int i; 213117e1df07SDaniel Vetter 213217e1df07SDaniel Vetter /* 213317e1df07SDaniel Vetter * Notify all waiters for GPU completion events that reset state has 213417e1df07SDaniel Vetter * been changed, and that they need to restart their wait after 213517e1df07SDaniel Vetter * checking for potential errors (and bail out to drop locks if there is 213617e1df07SDaniel Vetter * a gpu reset pending so that i915_error_work_func can acquire them). 213717e1df07SDaniel Vetter */ 213817e1df07SDaniel Vetter 213917e1df07SDaniel Vetter /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */ 214017e1df07SDaniel Vetter for_each_ring(ring, dev_priv, i) 214117e1df07SDaniel Vetter wake_up_all(&ring->irq_queue); 214217e1df07SDaniel Vetter 214317e1df07SDaniel Vetter /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */ 214417e1df07SDaniel Vetter wake_up_all(&dev_priv->pending_flip_queue); 214517e1df07SDaniel Vetter 214617e1df07SDaniel Vetter /* 214717e1df07SDaniel Vetter * Signal tasks blocked in i915_gem_wait_for_error that the pending 214817e1df07SDaniel Vetter * reset state is cleared. 214917e1df07SDaniel Vetter */ 215017e1df07SDaniel Vetter if (reset_completed) 215117e1df07SDaniel Vetter wake_up_all(&dev_priv->gpu_error.reset_queue); 215217e1df07SDaniel Vetter } 215317e1df07SDaniel Vetter 21548a905236SJesse Barnes /** 21558a905236SJesse Barnes * i915_error_work_func - do process context error handling work 21568a905236SJesse Barnes * @work: work struct 21578a905236SJesse Barnes * 21588a905236SJesse Barnes * Fire an error uevent so userspace can see that a hang or error 21598a905236SJesse Barnes * was detected. 21608a905236SJesse Barnes */ 21618a905236SJesse Barnes static void i915_error_work_func(struct work_struct *work) 21628a905236SJesse Barnes { 21631f83fee0SDaniel Vetter struct i915_gpu_error *error = container_of(work, struct i915_gpu_error, 21641f83fee0SDaniel Vetter work); 21652d1013ddSJani Nikula struct drm_i915_private *dev_priv = 21662d1013ddSJani Nikula container_of(error, struct drm_i915_private, gpu_error); 21678a905236SJesse Barnes struct drm_device *dev = dev_priv->dev; 2168cce723edSBen Widawsky char *error_event[] = { I915_ERROR_UEVENT "=1", NULL }; 2169cce723edSBen Widawsky char *reset_event[] = { I915_RESET_UEVENT "=1", NULL }; 2170cce723edSBen Widawsky char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL }; 217117e1df07SDaniel Vetter int ret; 21728a905236SJesse Barnes 21735bdebb18SDave Airlie kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event); 21748a905236SJesse Barnes 21757db0ba24SDaniel Vetter /* 21767db0ba24SDaniel Vetter * Note that there's only one work item which does gpu resets, so we 21777db0ba24SDaniel Vetter * need not worry about concurrent gpu resets potentially incrementing 21787db0ba24SDaniel Vetter * error->reset_counter twice. We only need to take care of another 21797db0ba24SDaniel Vetter * racing irq/hangcheck declaring the gpu dead for a second time. A 21807db0ba24SDaniel Vetter * quick check for that is good enough: schedule_work ensures the 21817db0ba24SDaniel Vetter * correct ordering between hang detection and this work item, and since 21827db0ba24SDaniel Vetter * the reset in-progress bit is only ever set by code outside of this 21837db0ba24SDaniel Vetter * work we don't need to worry about any other races. 21847db0ba24SDaniel Vetter */ 21857db0ba24SDaniel Vetter if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) { 218644d98a61SZhao Yakui DRM_DEBUG_DRIVER("resetting chip\n"); 21875bdebb18SDave Airlie kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, 21887db0ba24SDaniel Vetter reset_event); 21891f83fee0SDaniel Vetter 219017e1df07SDaniel Vetter /* 219117e1df07SDaniel Vetter * All state reset _must_ be completed before we update the 219217e1df07SDaniel Vetter * reset counter, for otherwise waiters might miss the reset 219317e1df07SDaniel Vetter * pending state and not properly drop locks, resulting in 219417e1df07SDaniel Vetter * deadlocks with the reset work. 219517e1df07SDaniel Vetter */ 2196f69061beSDaniel Vetter ret = i915_reset(dev); 2197f69061beSDaniel Vetter 219817e1df07SDaniel Vetter intel_display_handle_reset(dev); 219917e1df07SDaniel Vetter 2200f69061beSDaniel Vetter if (ret == 0) { 2201f69061beSDaniel Vetter /* 2202f69061beSDaniel Vetter * After all the gem state is reset, increment the reset 2203f69061beSDaniel Vetter * counter and wake up everyone waiting for the reset to 2204f69061beSDaniel Vetter * complete. 2205f69061beSDaniel Vetter * 2206f69061beSDaniel Vetter * Since unlock operations are a one-sided barrier only, 2207f69061beSDaniel Vetter * we need to insert a barrier here to order any seqno 2208f69061beSDaniel Vetter * updates before 2209f69061beSDaniel Vetter * the counter increment. 2210f69061beSDaniel Vetter */ 2211f69061beSDaniel Vetter smp_mb__before_atomic_inc(); 2212f69061beSDaniel Vetter atomic_inc(&dev_priv->gpu_error.reset_counter); 2213f69061beSDaniel Vetter 22145bdebb18SDave Airlie kobject_uevent_env(&dev->primary->kdev->kobj, 2215f69061beSDaniel Vetter KOBJ_CHANGE, reset_done_event); 22161f83fee0SDaniel Vetter } else { 22172ac0f450SMika Kuoppala atomic_set_mask(I915_WEDGED, &error->reset_counter); 2218f316a42cSBen Gamari } 22191f83fee0SDaniel Vetter 222017e1df07SDaniel Vetter /* 222117e1df07SDaniel Vetter * Note: The wake_up also serves as a memory barrier so that 222217e1df07SDaniel Vetter * waiters see the update value of the reset counter atomic_t. 222317e1df07SDaniel Vetter */ 222417e1df07SDaniel Vetter i915_error_wake_up(dev_priv, true); 2225f316a42cSBen Gamari } 22268a905236SJesse Barnes } 22278a905236SJesse Barnes 222835aed2e6SChris Wilson static void i915_report_and_clear_eir(struct drm_device *dev) 2229c0e09200SDave Airlie { 22308a905236SJesse Barnes struct drm_i915_private *dev_priv = dev->dev_private; 2231bd9854f9SBen Widawsky uint32_t instdone[I915_NUM_INSTDONE_REG]; 223263eeaf38SJesse Barnes u32 eir = I915_READ(EIR); 2233050ee91fSBen Widawsky int pipe, i; 223463eeaf38SJesse Barnes 223535aed2e6SChris Wilson if (!eir) 223635aed2e6SChris Wilson return; 223763eeaf38SJesse Barnes 2238a70491ccSJoe Perches pr_err("render error detected, EIR: 0x%08x\n", eir); 22398a905236SJesse Barnes 2240bd9854f9SBen Widawsky i915_get_extra_instdone(dev, instdone); 2241bd9854f9SBen Widawsky 22428a905236SJesse Barnes if (IS_G4X(dev)) { 22438a905236SJesse Barnes if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) { 22448a905236SJesse Barnes u32 ipeir = I915_READ(IPEIR_I965); 22458a905236SJesse Barnes 2246a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); 2247a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); 2248050ee91fSBen Widawsky for (i = 0; i < ARRAY_SIZE(instdone); i++) 2249050ee91fSBen Widawsky pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]); 2250a70491ccSJoe Perches pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); 2251a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); 22528a905236SJesse Barnes I915_WRITE(IPEIR_I965, ipeir); 22533143a2bfSChris Wilson POSTING_READ(IPEIR_I965); 22548a905236SJesse Barnes } 22558a905236SJesse Barnes if (eir & GM45_ERROR_PAGE_TABLE) { 22568a905236SJesse Barnes u32 pgtbl_err = I915_READ(PGTBL_ER); 2257a70491ccSJoe Perches pr_err("page table error\n"); 2258a70491ccSJoe Perches pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); 22598a905236SJesse Barnes I915_WRITE(PGTBL_ER, pgtbl_err); 22603143a2bfSChris Wilson POSTING_READ(PGTBL_ER); 22618a905236SJesse Barnes } 22628a905236SJesse Barnes } 22638a905236SJesse Barnes 2264a6c45cf0SChris Wilson if (!IS_GEN2(dev)) { 226563eeaf38SJesse Barnes if (eir & I915_ERROR_PAGE_TABLE) { 226663eeaf38SJesse Barnes u32 pgtbl_err = I915_READ(PGTBL_ER); 2267a70491ccSJoe Perches pr_err("page table error\n"); 2268a70491ccSJoe Perches pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); 226963eeaf38SJesse Barnes I915_WRITE(PGTBL_ER, pgtbl_err); 22703143a2bfSChris Wilson POSTING_READ(PGTBL_ER); 227163eeaf38SJesse Barnes } 22728a905236SJesse Barnes } 22738a905236SJesse Barnes 227463eeaf38SJesse Barnes if (eir & I915_ERROR_MEMORY_REFRESH) { 2275a70491ccSJoe Perches pr_err("memory refresh error:\n"); 22769db4a9c7SJesse Barnes for_each_pipe(pipe) 2277a70491ccSJoe Perches pr_err("pipe %c stat: 0x%08x\n", 22789db4a9c7SJesse Barnes pipe_name(pipe), I915_READ(PIPESTAT(pipe))); 227963eeaf38SJesse Barnes /* pipestat has already been acked */ 228063eeaf38SJesse Barnes } 228163eeaf38SJesse Barnes if (eir & I915_ERROR_INSTRUCTION) { 2282a70491ccSJoe Perches pr_err("instruction error\n"); 2283a70491ccSJoe Perches pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM)); 2284050ee91fSBen Widawsky for (i = 0; i < ARRAY_SIZE(instdone); i++) 2285050ee91fSBen Widawsky pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]); 2286a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen < 4) { 228763eeaf38SJesse Barnes u32 ipeir = I915_READ(IPEIR); 228863eeaf38SJesse Barnes 2289a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR)); 2290a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR)); 2291a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD)); 229263eeaf38SJesse Barnes I915_WRITE(IPEIR, ipeir); 22933143a2bfSChris Wilson POSTING_READ(IPEIR); 229463eeaf38SJesse Barnes } else { 229563eeaf38SJesse Barnes u32 ipeir = I915_READ(IPEIR_I965); 229663eeaf38SJesse Barnes 2297a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); 2298a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); 2299a70491ccSJoe Perches pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); 2300a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); 230163eeaf38SJesse Barnes I915_WRITE(IPEIR_I965, ipeir); 23023143a2bfSChris Wilson POSTING_READ(IPEIR_I965); 230363eeaf38SJesse Barnes } 230463eeaf38SJesse Barnes } 230563eeaf38SJesse Barnes 230663eeaf38SJesse Barnes I915_WRITE(EIR, eir); 23073143a2bfSChris Wilson POSTING_READ(EIR); 230863eeaf38SJesse Barnes eir = I915_READ(EIR); 230963eeaf38SJesse Barnes if (eir) { 231063eeaf38SJesse Barnes /* 231163eeaf38SJesse Barnes * some errors might have become stuck, 231263eeaf38SJesse Barnes * mask them. 231363eeaf38SJesse Barnes */ 231463eeaf38SJesse Barnes DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir); 231563eeaf38SJesse Barnes I915_WRITE(EMR, I915_READ(EMR) | eir); 231663eeaf38SJesse Barnes I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 231763eeaf38SJesse Barnes } 231835aed2e6SChris Wilson } 231935aed2e6SChris Wilson 232035aed2e6SChris Wilson /** 232135aed2e6SChris Wilson * i915_handle_error - handle an error interrupt 232235aed2e6SChris Wilson * @dev: drm device 232335aed2e6SChris Wilson * 232435aed2e6SChris Wilson * Do some basic checking of regsiter state at error interrupt time and 232535aed2e6SChris Wilson * dump it to the syslog. Also call i915_capture_error_state() to make 232635aed2e6SChris Wilson * sure we get a record and make it available in debugfs. Fire a uevent 232735aed2e6SChris Wilson * so userspace knows something bad happened (should trigger collection 232835aed2e6SChris Wilson * of a ring dump etc.). 232935aed2e6SChris Wilson */ 233058174462SMika Kuoppala void i915_handle_error(struct drm_device *dev, bool wedged, 233158174462SMika Kuoppala const char *fmt, ...) 233235aed2e6SChris Wilson { 233335aed2e6SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 233458174462SMika Kuoppala va_list args; 233558174462SMika Kuoppala char error_msg[80]; 233635aed2e6SChris Wilson 233758174462SMika Kuoppala va_start(args, fmt); 233858174462SMika Kuoppala vscnprintf(error_msg, sizeof(error_msg), fmt, args); 233958174462SMika Kuoppala va_end(args); 234058174462SMika Kuoppala 234158174462SMika Kuoppala i915_capture_error_state(dev, wedged, error_msg); 234235aed2e6SChris Wilson i915_report_and_clear_eir(dev); 23438a905236SJesse Barnes 2344ba1234d1SBen Gamari if (wedged) { 2345f69061beSDaniel Vetter atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG, 2346f69061beSDaniel Vetter &dev_priv->gpu_error.reset_counter); 2347ba1234d1SBen Gamari 234811ed50ecSBen Gamari /* 234917e1df07SDaniel Vetter * Wakeup waiting processes so that the reset work function 235017e1df07SDaniel Vetter * i915_error_work_func doesn't deadlock trying to grab various 235117e1df07SDaniel Vetter * locks. By bumping the reset counter first, the woken 235217e1df07SDaniel Vetter * processes will see a reset in progress and back off, 235317e1df07SDaniel Vetter * releasing their locks and then wait for the reset completion. 235417e1df07SDaniel Vetter * We must do this for _all_ gpu waiters that might hold locks 235517e1df07SDaniel Vetter * that the reset work needs to acquire. 235617e1df07SDaniel Vetter * 235717e1df07SDaniel Vetter * Note: The wake_up serves as the required memory barrier to 235817e1df07SDaniel Vetter * ensure that the waiters see the updated value of the reset 235917e1df07SDaniel Vetter * counter atomic_t. 236011ed50ecSBen Gamari */ 236117e1df07SDaniel Vetter i915_error_wake_up(dev_priv, false); 236211ed50ecSBen Gamari } 236311ed50ecSBen Gamari 2364122f46baSDaniel Vetter /* 2365122f46baSDaniel Vetter * Our reset work can grab modeset locks (since it needs to reset the 2366122f46baSDaniel Vetter * state of outstanding pagelips). Hence it must not be run on our own 2367122f46baSDaniel Vetter * dev-priv->wq work queue for otherwise the flush_work in the pageflip 2368122f46baSDaniel Vetter * code will deadlock. 2369122f46baSDaniel Vetter */ 2370122f46baSDaniel Vetter schedule_work(&dev_priv->gpu_error.work); 23718a905236SJesse Barnes } 23728a905236SJesse Barnes 237321ad8330SVille Syrjälä static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe) 23744e5359cdSSimon Farnsworth { 23752d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 23764e5359cdSSimon Farnsworth struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 23774e5359cdSSimon Farnsworth struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 237805394f39SChris Wilson struct drm_i915_gem_object *obj; 23794e5359cdSSimon Farnsworth struct intel_unpin_work *work; 23804e5359cdSSimon Farnsworth unsigned long flags; 23814e5359cdSSimon Farnsworth bool stall_detected; 23824e5359cdSSimon Farnsworth 23834e5359cdSSimon Farnsworth /* Ignore early vblank irqs */ 23844e5359cdSSimon Farnsworth if (intel_crtc == NULL) 23854e5359cdSSimon Farnsworth return; 23864e5359cdSSimon Farnsworth 23874e5359cdSSimon Farnsworth spin_lock_irqsave(&dev->event_lock, flags); 23884e5359cdSSimon Farnsworth work = intel_crtc->unpin_work; 23894e5359cdSSimon Farnsworth 2390e7d841caSChris Wilson if (work == NULL || 2391e7d841caSChris Wilson atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE || 2392e7d841caSChris Wilson !work->enable_stall_check) { 23934e5359cdSSimon Farnsworth /* Either the pending flip IRQ arrived, or we're too early. Don't check */ 23944e5359cdSSimon Farnsworth spin_unlock_irqrestore(&dev->event_lock, flags); 23954e5359cdSSimon Farnsworth return; 23964e5359cdSSimon Farnsworth } 23974e5359cdSSimon Farnsworth 23984e5359cdSSimon Farnsworth /* Potential stall - if we see that the flip has happened, assume a missed interrupt */ 239905394f39SChris Wilson obj = work->pending_flip_obj; 2400a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen >= 4) { 24019db4a9c7SJesse Barnes int dspsurf = DSPSURF(intel_crtc->plane); 2402446f2545SArmin Reese stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) == 2403f343c5f6SBen Widawsky i915_gem_obj_ggtt_offset(obj); 24044e5359cdSSimon Farnsworth } else { 24059db4a9c7SJesse Barnes int dspaddr = DSPADDR(intel_crtc->plane); 2406f343c5f6SBen Widawsky stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) + 2407f4510a27SMatt Roper crtc->y * crtc->primary->fb->pitches[0] + 2408f4510a27SMatt Roper crtc->x * crtc->primary->fb->bits_per_pixel/8); 24094e5359cdSSimon Farnsworth } 24104e5359cdSSimon Farnsworth 24114e5359cdSSimon Farnsworth spin_unlock_irqrestore(&dev->event_lock, flags); 24124e5359cdSSimon Farnsworth 24134e5359cdSSimon Farnsworth if (stall_detected) { 24144e5359cdSSimon Farnsworth DRM_DEBUG_DRIVER("Pageflip stall detected\n"); 24154e5359cdSSimon Farnsworth intel_prepare_page_flip(dev, intel_crtc->plane); 24164e5359cdSSimon Farnsworth } 24174e5359cdSSimon Farnsworth } 24184e5359cdSSimon Farnsworth 241942f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 242042f52ef8SKeith Packard * we use as a pipe index 242142f52ef8SKeith Packard */ 2422f71d4af4SJesse Barnes static int i915_enable_vblank(struct drm_device *dev, int pipe) 24230a3e67a4SJesse Barnes { 24242d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 2425e9d21d7fSKeith Packard unsigned long irqflags; 242671e0ffa5SJesse Barnes 24275eddb70bSChris Wilson if (!i915_pipe_enabled(dev, pipe)) 242871e0ffa5SJesse Barnes return -EINVAL; 24290a3e67a4SJesse Barnes 24301ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2431f796cf8fSJesse Barnes if (INTEL_INFO(dev)->gen >= 4) 24327c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 2433755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 24340a3e67a4SJesse Barnes else 24357c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 2436755e9019SImre Deak PIPE_VBLANK_INTERRUPT_STATUS); 24378692d00eSChris Wilson 24388692d00eSChris Wilson /* maintain vblank delivery even in deep C-states */ 24393d13ef2eSDamien Lespiau if (INTEL_INFO(dev)->gen == 3) 24406b26c86dSDaniel Vetter I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS)); 24411ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 24428692d00eSChris Wilson 24430a3e67a4SJesse Barnes return 0; 24440a3e67a4SJesse Barnes } 24450a3e67a4SJesse Barnes 2446f71d4af4SJesse Barnes static int ironlake_enable_vblank(struct drm_device *dev, int pipe) 2447f796cf8fSJesse Barnes { 24482d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 2449f796cf8fSJesse Barnes unsigned long irqflags; 2450b518421fSPaulo Zanoni uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) : 245140da17c2SDaniel Vetter DE_PIPE_VBLANK(pipe); 2452f796cf8fSJesse Barnes 2453f796cf8fSJesse Barnes if (!i915_pipe_enabled(dev, pipe)) 2454f796cf8fSJesse Barnes return -EINVAL; 2455f796cf8fSJesse Barnes 2456f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2457b518421fSPaulo Zanoni ironlake_enable_display_irq(dev_priv, bit); 2458b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2459b1f14ad0SJesse Barnes 2460b1f14ad0SJesse Barnes return 0; 2461b1f14ad0SJesse Barnes } 2462b1f14ad0SJesse Barnes 24637e231dbeSJesse Barnes static int valleyview_enable_vblank(struct drm_device *dev, int pipe) 24647e231dbeSJesse Barnes { 24652d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 24667e231dbeSJesse Barnes unsigned long irqflags; 24677e231dbeSJesse Barnes 24687e231dbeSJesse Barnes if (!i915_pipe_enabled(dev, pipe)) 24697e231dbeSJesse Barnes return -EINVAL; 24707e231dbeSJesse Barnes 24717e231dbeSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 247231acc7f5SJesse Barnes i915_enable_pipestat(dev_priv, pipe, 2473755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 24747e231dbeSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 24757e231dbeSJesse Barnes 24767e231dbeSJesse Barnes return 0; 24777e231dbeSJesse Barnes } 24787e231dbeSJesse Barnes 2479abd58f01SBen Widawsky static int gen8_enable_vblank(struct drm_device *dev, int pipe) 2480abd58f01SBen Widawsky { 2481abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 2482abd58f01SBen Widawsky unsigned long irqflags; 2483abd58f01SBen Widawsky 2484abd58f01SBen Widawsky if (!i915_pipe_enabled(dev, pipe)) 2485abd58f01SBen Widawsky return -EINVAL; 2486abd58f01SBen Widawsky 2487abd58f01SBen Widawsky spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 24887167d7c6SDaniel Vetter dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK; 24897167d7c6SDaniel Vetter I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]); 2490abd58f01SBen Widawsky POSTING_READ(GEN8_DE_PIPE_IMR(pipe)); 2491abd58f01SBen Widawsky spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2492abd58f01SBen Widawsky return 0; 2493abd58f01SBen Widawsky } 2494abd58f01SBen Widawsky 249542f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 249642f52ef8SKeith Packard * we use as a pipe index 249742f52ef8SKeith Packard */ 2498f71d4af4SJesse Barnes static void i915_disable_vblank(struct drm_device *dev, int pipe) 24990a3e67a4SJesse Barnes { 25002d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 2501e9d21d7fSKeith Packard unsigned long irqflags; 25020a3e67a4SJesse Barnes 25031ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 25043d13ef2eSDamien Lespiau if (INTEL_INFO(dev)->gen == 3) 25056b26c86dSDaniel Vetter I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS)); 25068692d00eSChris Wilson 25077c463586SKeith Packard i915_disable_pipestat(dev_priv, pipe, 2508755e9019SImre Deak PIPE_VBLANK_INTERRUPT_STATUS | 2509755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 25101ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 25110a3e67a4SJesse Barnes } 25120a3e67a4SJesse Barnes 2513f71d4af4SJesse Barnes static void ironlake_disable_vblank(struct drm_device *dev, int pipe) 2514f796cf8fSJesse Barnes { 25152d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 2516f796cf8fSJesse Barnes unsigned long irqflags; 2517b518421fSPaulo Zanoni uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) : 251840da17c2SDaniel Vetter DE_PIPE_VBLANK(pipe); 2519f796cf8fSJesse Barnes 2520f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2521b518421fSPaulo Zanoni ironlake_disable_display_irq(dev_priv, bit); 2522b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2523b1f14ad0SJesse Barnes } 2524b1f14ad0SJesse Barnes 25257e231dbeSJesse Barnes static void valleyview_disable_vblank(struct drm_device *dev, int pipe) 25267e231dbeSJesse Barnes { 25272d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 25287e231dbeSJesse Barnes unsigned long irqflags; 25297e231dbeSJesse Barnes 25307e231dbeSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 253131acc7f5SJesse Barnes i915_disable_pipestat(dev_priv, pipe, 2532755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 25337e231dbeSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 25347e231dbeSJesse Barnes } 25357e231dbeSJesse Barnes 2536abd58f01SBen Widawsky static void gen8_disable_vblank(struct drm_device *dev, int pipe) 2537abd58f01SBen Widawsky { 2538abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 2539abd58f01SBen Widawsky unsigned long irqflags; 2540abd58f01SBen Widawsky 2541abd58f01SBen Widawsky if (!i915_pipe_enabled(dev, pipe)) 2542abd58f01SBen Widawsky return; 2543abd58f01SBen Widawsky 2544abd58f01SBen Widawsky spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 25457167d7c6SDaniel Vetter dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK; 25467167d7c6SDaniel Vetter I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]); 2547abd58f01SBen Widawsky POSTING_READ(GEN8_DE_PIPE_IMR(pipe)); 2548abd58f01SBen Widawsky spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2549abd58f01SBen Widawsky } 2550abd58f01SBen Widawsky 2551893eead0SChris Wilson static u32 2552893eead0SChris Wilson ring_last_seqno(struct intel_ring_buffer *ring) 2553852835f3SZou Nan hai { 2554893eead0SChris Wilson return list_entry(ring->request_list.prev, 2555893eead0SChris Wilson struct drm_i915_gem_request, list)->seqno; 2556893eead0SChris Wilson } 2557893eead0SChris Wilson 25589107e9d2SChris Wilson static bool 25599107e9d2SChris Wilson ring_idle(struct intel_ring_buffer *ring, u32 seqno) 2560893eead0SChris Wilson { 25619107e9d2SChris Wilson return (list_empty(&ring->request_list) || 25629107e9d2SChris Wilson i915_seqno_passed(seqno, ring_last_seqno(ring))); 2563f65d9421SBen Gamari } 2564f65d9421SBen Gamari 2565a028c4b0SDaniel Vetter static bool 2566a028c4b0SDaniel Vetter ipehr_is_semaphore_wait(struct drm_device *dev, u32 ipehr) 2567a028c4b0SDaniel Vetter { 2568a028c4b0SDaniel Vetter if (INTEL_INFO(dev)->gen >= 8) { 2569a028c4b0SDaniel Vetter /* 2570a028c4b0SDaniel Vetter * FIXME: gen8 semaphore support - currently we don't emit 2571a028c4b0SDaniel Vetter * semaphores on bdw anyway, but this needs to be addressed when 2572a028c4b0SDaniel Vetter * we merge that code. 2573a028c4b0SDaniel Vetter */ 2574a028c4b0SDaniel Vetter return false; 2575a028c4b0SDaniel Vetter } else { 2576a028c4b0SDaniel Vetter ipehr &= ~MI_SEMAPHORE_SYNC_MASK; 2577a028c4b0SDaniel Vetter return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | 2578a028c4b0SDaniel Vetter MI_SEMAPHORE_REGISTER); 2579a028c4b0SDaniel Vetter } 2580a028c4b0SDaniel Vetter } 2581a028c4b0SDaniel Vetter 25826274f212SChris Wilson static struct intel_ring_buffer * 2583921d42eaSDaniel Vetter semaphore_wait_to_signaller_ring(struct intel_ring_buffer *ring, u32 ipehr) 2584921d42eaSDaniel Vetter { 2585921d42eaSDaniel Vetter struct drm_i915_private *dev_priv = ring->dev->dev_private; 2586921d42eaSDaniel Vetter struct intel_ring_buffer *signaller; 2587921d42eaSDaniel Vetter int i; 2588921d42eaSDaniel Vetter 2589921d42eaSDaniel Vetter if (INTEL_INFO(dev_priv->dev)->gen >= 8) { 2590921d42eaSDaniel Vetter /* 2591921d42eaSDaniel Vetter * FIXME: gen8 semaphore support - currently we don't emit 2592921d42eaSDaniel Vetter * semaphores on bdw anyway, but this needs to be addressed when 2593921d42eaSDaniel Vetter * we merge that code. 2594921d42eaSDaniel Vetter */ 2595921d42eaSDaniel Vetter return NULL; 2596921d42eaSDaniel Vetter } else { 2597921d42eaSDaniel Vetter u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK; 2598921d42eaSDaniel Vetter 2599921d42eaSDaniel Vetter for_each_ring(signaller, dev_priv, i) { 2600921d42eaSDaniel Vetter if(ring == signaller) 2601921d42eaSDaniel Vetter continue; 2602921d42eaSDaniel Vetter 2603921d42eaSDaniel Vetter if (sync_bits == 2604921d42eaSDaniel Vetter signaller->semaphore_register[ring->id]) 2605921d42eaSDaniel Vetter return signaller; 2606921d42eaSDaniel Vetter } 2607921d42eaSDaniel Vetter } 2608921d42eaSDaniel Vetter 2609921d42eaSDaniel Vetter DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x\n", 2610921d42eaSDaniel Vetter ring->id, ipehr); 2611921d42eaSDaniel Vetter 2612921d42eaSDaniel Vetter return NULL; 2613921d42eaSDaniel Vetter } 2614921d42eaSDaniel Vetter 26156274f212SChris Wilson static struct intel_ring_buffer * 26166274f212SChris Wilson semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno) 2617a24a11e6SChris Wilson { 2618a24a11e6SChris Wilson struct drm_i915_private *dev_priv = ring->dev->dev_private; 261988fe429dSDaniel Vetter u32 cmd, ipehr, head; 262088fe429dSDaniel Vetter int i; 2621a24a11e6SChris Wilson 2622a24a11e6SChris Wilson ipehr = I915_READ(RING_IPEHR(ring->mmio_base)); 2623a028c4b0SDaniel Vetter if (!ipehr_is_semaphore_wait(ring->dev, ipehr)) 26246274f212SChris Wilson return NULL; 2625a24a11e6SChris Wilson 262688fe429dSDaniel Vetter /* 262788fe429dSDaniel Vetter * HEAD is likely pointing to the dword after the actual command, 262888fe429dSDaniel Vetter * so scan backwards until we find the MBOX. But limit it to just 3 262988fe429dSDaniel Vetter * dwords. Note that we don't care about ACTHD here since that might 263088fe429dSDaniel Vetter * point at at batch, and semaphores are always emitted into the 263188fe429dSDaniel Vetter * ringbuffer itself. 2632a24a11e6SChris Wilson */ 263388fe429dSDaniel Vetter head = I915_READ_HEAD(ring) & HEAD_ADDR; 263488fe429dSDaniel Vetter 263588fe429dSDaniel Vetter for (i = 4; i; --i) { 263688fe429dSDaniel Vetter /* 263788fe429dSDaniel Vetter * Be paranoid and presume the hw has gone off into the wild - 263888fe429dSDaniel Vetter * our ring is smaller than what the hardware (and hence 263988fe429dSDaniel Vetter * HEAD_ADDR) allows. Also handles wrap-around. 264088fe429dSDaniel Vetter */ 264188fe429dSDaniel Vetter head &= ring->size - 1; 264288fe429dSDaniel Vetter 264388fe429dSDaniel Vetter /* This here seems to blow up */ 264488fe429dSDaniel Vetter cmd = ioread32(ring->virtual_start + head); 2645a24a11e6SChris Wilson if (cmd == ipehr) 2646a24a11e6SChris Wilson break; 2647a24a11e6SChris Wilson 264888fe429dSDaniel Vetter head -= 4; 264988fe429dSDaniel Vetter } 2650a24a11e6SChris Wilson 265188fe429dSDaniel Vetter if (!i) 265288fe429dSDaniel Vetter return NULL; 265388fe429dSDaniel Vetter 265488fe429dSDaniel Vetter *seqno = ioread32(ring->virtual_start + head + 4) + 1; 2655921d42eaSDaniel Vetter return semaphore_wait_to_signaller_ring(ring, ipehr); 2656a24a11e6SChris Wilson } 2657a24a11e6SChris Wilson 26586274f212SChris Wilson static int semaphore_passed(struct intel_ring_buffer *ring) 26596274f212SChris Wilson { 26606274f212SChris Wilson struct drm_i915_private *dev_priv = ring->dev->dev_private; 26616274f212SChris Wilson struct intel_ring_buffer *signaller; 26626274f212SChris Wilson u32 seqno, ctl; 26636274f212SChris Wilson 26646274f212SChris Wilson ring->hangcheck.deadlock = true; 26656274f212SChris Wilson 26666274f212SChris Wilson signaller = semaphore_waits_for(ring, &seqno); 26676274f212SChris Wilson if (signaller == NULL || signaller->hangcheck.deadlock) 26686274f212SChris Wilson return -1; 26696274f212SChris Wilson 26706274f212SChris Wilson /* cursory check for an unkickable deadlock */ 26716274f212SChris Wilson ctl = I915_READ_CTL(signaller); 26726274f212SChris Wilson if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0) 26736274f212SChris Wilson return -1; 26746274f212SChris Wilson 26756274f212SChris Wilson return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno); 26766274f212SChris Wilson } 26776274f212SChris Wilson 26786274f212SChris Wilson static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv) 26796274f212SChris Wilson { 26806274f212SChris Wilson struct intel_ring_buffer *ring; 26816274f212SChris Wilson int i; 26826274f212SChris Wilson 26836274f212SChris Wilson for_each_ring(ring, dev_priv, i) 26846274f212SChris Wilson ring->hangcheck.deadlock = false; 26856274f212SChris Wilson } 26866274f212SChris Wilson 2687ad8beaeaSMika Kuoppala static enum intel_ring_hangcheck_action 268850877445SChris Wilson ring_stuck(struct intel_ring_buffer *ring, u64 acthd) 26891ec14ad3SChris Wilson { 26901ec14ad3SChris Wilson struct drm_device *dev = ring->dev; 26911ec14ad3SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 26929107e9d2SChris Wilson u32 tmp; 26939107e9d2SChris Wilson 26946274f212SChris Wilson if (ring->hangcheck.acthd != acthd) 2695f2f4d82fSJani Nikula return HANGCHECK_ACTIVE; 26966274f212SChris Wilson 26979107e9d2SChris Wilson if (IS_GEN2(dev)) 2698f2f4d82fSJani Nikula return HANGCHECK_HUNG; 26999107e9d2SChris Wilson 27009107e9d2SChris Wilson /* Is the chip hanging on a WAIT_FOR_EVENT? 27019107e9d2SChris Wilson * If so we can simply poke the RB_WAIT bit 27029107e9d2SChris Wilson * and break the hang. This should work on 27039107e9d2SChris Wilson * all but the second generation chipsets. 27049107e9d2SChris Wilson */ 27059107e9d2SChris Wilson tmp = I915_READ_CTL(ring); 27061ec14ad3SChris Wilson if (tmp & RING_WAIT) { 270758174462SMika Kuoppala i915_handle_error(dev, false, 270858174462SMika Kuoppala "Kicking stuck wait on %s", 27091ec14ad3SChris Wilson ring->name); 27101ec14ad3SChris Wilson I915_WRITE_CTL(ring, tmp); 2711f2f4d82fSJani Nikula return HANGCHECK_KICK; 27121ec14ad3SChris Wilson } 2713a24a11e6SChris Wilson 27146274f212SChris Wilson if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) { 27156274f212SChris Wilson switch (semaphore_passed(ring)) { 27166274f212SChris Wilson default: 2717f2f4d82fSJani Nikula return HANGCHECK_HUNG; 27186274f212SChris Wilson case 1: 271958174462SMika Kuoppala i915_handle_error(dev, false, 272058174462SMika Kuoppala "Kicking stuck semaphore on %s", 2721a24a11e6SChris Wilson ring->name); 2722a24a11e6SChris Wilson I915_WRITE_CTL(ring, tmp); 2723f2f4d82fSJani Nikula return HANGCHECK_KICK; 27246274f212SChris Wilson case 0: 2725f2f4d82fSJani Nikula return HANGCHECK_WAIT; 27266274f212SChris Wilson } 27279107e9d2SChris Wilson } 27289107e9d2SChris Wilson 2729f2f4d82fSJani Nikula return HANGCHECK_HUNG; 2730a24a11e6SChris Wilson } 2731d1e61e7fSChris Wilson 2732f65d9421SBen Gamari /** 2733f65d9421SBen Gamari * This is called when the chip hasn't reported back with completed 273405407ff8SMika Kuoppala * batchbuffers in a long time. We keep track per ring seqno progress and 273505407ff8SMika Kuoppala * if there are no progress, hangcheck score for that ring is increased. 273605407ff8SMika Kuoppala * Further, acthd is inspected to see if the ring is stuck. On stuck case 273705407ff8SMika Kuoppala * we kick the ring. If we see no progress on three subsequent calls 273805407ff8SMika Kuoppala * we assume chip is wedged and try to fix it by resetting the chip. 2739f65d9421SBen Gamari */ 2740a658b5d2SDamien Lespiau static void i915_hangcheck_elapsed(unsigned long data) 2741f65d9421SBen Gamari { 2742f65d9421SBen Gamari struct drm_device *dev = (struct drm_device *)data; 27432d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 2744b4519513SChris Wilson struct intel_ring_buffer *ring; 2745b4519513SChris Wilson int i; 274605407ff8SMika Kuoppala int busy_count = 0, rings_hung = 0; 27479107e9d2SChris Wilson bool stuck[I915_NUM_RINGS] = { 0 }; 27489107e9d2SChris Wilson #define BUSY 1 27499107e9d2SChris Wilson #define KICK 5 27509107e9d2SChris Wilson #define HUNG 20 2751893eead0SChris Wilson 2752d330a953SJani Nikula if (!i915.enable_hangcheck) 27533e0dc6b0SBen Widawsky return; 27543e0dc6b0SBen Widawsky 2755b4519513SChris Wilson for_each_ring(ring, dev_priv, i) { 275650877445SChris Wilson u64 acthd; 275750877445SChris Wilson u32 seqno; 27589107e9d2SChris Wilson bool busy = true; 2759b4519513SChris Wilson 27606274f212SChris Wilson semaphore_clear_deadlocks(dev_priv); 27616274f212SChris Wilson 276205407ff8SMika Kuoppala seqno = ring->get_seqno(ring, false); 276305407ff8SMika Kuoppala acthd = intel_ring_get_active_head(ring); 276405407ff8SMika Kuoppala 276505407ff8SMika Kuoppala if (ring->hangcheck.seqno == seqno) { 27669107e9d2SChris Wilson if (ring_idle(ring, seqno)) { 2767da661464SMika Kuoppala ring->hangcheck.action = HANGCHECK_IDLE; 2768da661464SMika Kuoppala 27699107e9d2SChris Wilson if (waitqueue_active(&ring->irq_queue)) { 27709107e9d2SChris Wilson /* Issue a wake-up to catch stuck h/w. */ 2771094f9a54SChris Wilson if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) { 2772f4adcd24SDaniel Vetter if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring))) 27739107e9d2SChris Wilson DRM_ERROR("Hangcheck timer elapsed... %s idle\n", 27749107e9d2SChris Wilson ring->name); 2775f4adcd24SDaniel Vetter else 2776f4adcd24SDaniel Vetter DRM_INFO("Fake missed irq on %s\n", 2777f4adcd24SDaniel Vetter ring->name); 27789107e9d2SChris Wilson wake_up_all(&ring->irq_queue); 2779094f9a54SChris Wilson } 2780094f9a54SChris Wilson /* Safeguard against driver failure */ 2781094f9a54SChris Wilson ring->hangcheck.score += BUSY; 27829107e9d2SChris Wilson } else 27839107e9d2SChris Wilson busy = false; 278405407ff8SMika Kuoppala } else { 27856274f212SChris Wilson /* We always increment the hangcheck score 27866274f212SChris Wilson * if the ring is busy and still processing 27876274f212SChris Wilson * the same request, so that no single request 27886274f212SChris Wilson * can run indefinitely (such as a chain of 27896274f212SChris Wilson * batches). The only time we do not increment 27906274f212SChris Wilson * the hangcheck score on this ring, if this 27916274f212SChris Wilson * ring is in a legitimate wait for another 27926274f212SChris Wilson * ring. In that case the waiting ring is a 27936274f212SChris Wilson * victim and we want to be sure we catch the 27946274f212SChris Wilson * right culprit. Then every time we do kick 27956274f212SChris Wilson * the ring, add a small increment to the 27966274f212SChris Wilson * score so that we can catch a batch that is 27976274f212SChris Wilson * being repeatedly kicked and so responsible 27986274f212SChris Wilson * for stalling the machine. 27999107e9d2SChris Wilson */ 2800ad8beaeaSMika Kuoppala ring->hangcheck.action = ring_stuck(ring, 2801ad8beaeaSMika Kuoppala acthd); 2802ad8beaeaSMika Kuoppala 2803ad8beaeaSMika Kuoppala switch (ring->hangcheck.action) { 2804da661464SMika Kuoppala case HANGCHECK_IDLE: 2805f2f4d82fSJani Nikula case HANGCHECK_WAIT: 28066274f212SChris Wilson break; 2807f2f4d82fSJani Nikula case HANGCHECK_ACTIVE: 2808ea04cb31SJani Nikula ring->hangcheck.score += BUSY; 28096274f212SChris Wilson break; 2810f2f4d82fSJani Nikula case HANGCHECK_KICK: 2811ea04cb31SJani Nikula ring->hangcheck.score += KICK; 28126274f212SChris Wilson break; 2813f2f4d82fSJani Nikula case HANGCHECK_HUNG: 2814ea04cb31SJani Nikula ring->hangcheck.score += HUNG; 28156274f212SChris Wilson stuck[i] = true; 28166274f212SChris Wilson break; 28176274f212SChris Wilson } 281805407ff8SMika Kuoppala } 28199107e9d2SChris Wilson } else { 2820da661464SMika Kuoppala ring->hangcheck.action = HANGCHECK_ACTIVE; 2821da661464SMika Kuoppala 28229107e9d2SChris Wilson /* Gradually reduce the count so that we catch DoS 28239107e9d2SChris Wilson * attempts across multiple batches. 28249107e9d2SChris Wilson */ 28259107e9d2SChris Wilson if (ring->hangcheck.score > 0) 28269107e9d2SChris Wilson ring->hangcheck.score--; 2827cbb465e7SChris Wilson } 2828f65d9421SBen Gamari 282905407ff8SMika Kuoppala ring->hangcheck.seqno = seqno; 283005407ff8SMika Kuoppala ring->hangcheck.acthd = acthd; 28319107e9d2SChris Wilson busy_count += busy; 283205407ff8SMika Kuoppala } 283305407ff8SMika Kuoppala 283405407ff8SMika Kuoppala for_each_ring(ring, dev_priv, i) { 2835b6b0fac0SMika Kuoppala if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) { 2836b8d88d1dSDaniel Vetter DRM_INFO("%s on %s\n", 283705407ff8SMika Kuoppala stuck[i] ? "stuck" : "no progress", 2838a43adf07SChris Wilson ring->name); 2839a43adf07SChris Wilson rings_hung++; 284005407ff8SMika Kuoppala } 284105407ff8SMika Kuoppala } 284205407ff8SMika Kuoppala 284305407ff8SMika Kuoppala if (rings_hung) 284458174462SMika Kuoppala return i915_handle_error(dev, true, "Ring hung"); 284505407ff8SMika Kuoppala 284605407ff8SMika Kuoppala if (busy_count) 284705407ff8SMika Kuoppala /* Reset timer case chip hangs without another request 284805407ff8SMika Kuoppala * being added */ 284910cd45b6SMika Kuoppala i915_queue_hangcheck(dev); 285010cd45b6SMika Kuoppala } 285110cd45b6SMika Kuoppala 285210cd45b6SMika Kuoppala void i915_queue_hangcheck(struct drm_device *dev) 285310cd45b6SMika Kuoppala { 285410cd45b6SMika Kuoppala struct drm_i915_private *dev_priv = dev->dev_private; 2855d330a953SJani Nikula if (!i915.enable_hangcheck) 285610cd45b6SMika Kuoppala return; 285710cd45b6SMika Kuoppala 285899584db3SDaniel Vetter mod_timer(&dev_priv->gpu_error.hangcheck_timer, 285910cd45b6SMika Kuoppala round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES)); 2860f65d9421SBen Gamari } 2861f65d9421SBen Gamari 28621c69eb42SPaulo Zanoni static void ibx_irq_reset(struct drm_device *dev) 286391738a95SPaulo Zanoni { 286491738a95SPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 286591738a95SPaulo Zanoni 286691738a95SPaulo Zanoni if (HAS_PCH_NOP(dev)) 286791738a95SPaulo Zanoni return; 286891738a95SPaulo Zanoni 2869f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(SDE); 2870105b122eSPaulo Zanoni 2871105b122eSPaulo Zanoni if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev)) 2872105b122eSPaulo Zanoni I915_WRITE(SERR_INT, 0xffffffff); 2873622364b6SPaulo Zanoni } 2874105b122eSPaulo Zanoni 287591738a95SPaulo Zanoni /* 2876622364b6SPaulo Zanoni * SDEIER is also touched by the interrupt handler to work around missed PCH 2877622364b6SPaulo Zanoni * interrupts. Hence we can't update it after the interrupt handler is enabled - 2878622364b6SPaulo Zanoni * instead we unconditionally enable all PCH interrupt sources here, but then 2879622364b6SPaulo Zanoni * only unmask them as needed with SDEIMR. 2880622364b6SPaulo Zanoni * 2881622364b6SPaulo Zanoni * This function needs to be called before interrupts are enabled. 288291738a95SPaulo Zanoni */ 2883622364b6SPaulo Zanoni static void ibx_irq_pre_postinstall(struct drm_device *dev) 2884622364b6SPaulo Zanoni { 2885622364b6SPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 2886622364b6SPaulo Zanoni 2887622364b6SPaulo Zanoni if (HAS_PCH_NOP(dev)) 2888622364b6SPaulo Zanoni return; 2889622364b6SPaulo Zanoni 2890622364b6SPaulo Zanoni WARN_ON(I915_READ(SDEIER) != 0); 289191738a95SPaulo Zanoni I915_WRITE(SDEIER, 0xffffffff); 289291738a95SPaulo Zanoni POSTING_READ(SDEIER); 289391738a95SPaulo Zanoni } 289491738a95SPaulo Zanoni 28957c4d664eSPaulo Zanoni static void gen5_gt_irq_reset(struct drm_device *dev) 2896d18ea1b5SDaniel Vetter { 2897d18ea1b5SDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 2898d18ea1b5SDaniel Vetter 2899f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(GT); 2900a9d356a6SPaulo Zanoni if (INTEL_INFO(dev)->gen >= 6) 2901f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(GEN6_PM); 2902d18ea1b5SDaniel Vetter } 2903d18ea1b5SDaniel Vetter 2904c0e09200SDave Airlie /* drm_dma.h hooks 2905c0e09200SDave Airlie */ 2906be30b29fSPaulo Zanoni static void ironlake_irq_reset(struct drm_device *dev) 2907036a4a7dSZhenyu Wang { 29082d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 2909036a4a7dSZhenyu Wang 29100c841212SPaulo Zanoni I915_WRITE(HWSTAM, 0xffffffff); 2911bdfcdb63SDaniel Vetter 2912f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(DE); 2913c6d954c1SPaulo Zanoni if (IS_GEN7(dev)) 2914c6d954c1SPaulo Zanoni I915_WRITE(GEN7_ERR_INT, 0xffffffff); 2915036a4a7dSZhenyu Wang 29167c4d664eSPaulo Zanoni gen5_gt_irq_reset(dev); 2917c650156aSZhenyu Wang 29181c69eb42SPaulo Zanoni ibx_irq_reset(dev); 29197d99163dSBen Widawsky } 29207d99163dSBen Widawsky 2921be30b29fSPaulo Zanoni static void ironlake_irq_preinstall(struct drm_device *dev) 2922be30b29fSPaulo Zanoni { 2923be30b29fSPaulo Zanoni ironlake_irq_reset(dev); 29247d99163dSBen Widawsky } 29257d99163dSBen Widawsky 29267e231dbeSJesse Barnes static void valleyview_irq_preinstall(struct drm_device *dev) 29277e231dbeSJesse Barnes { 29282d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 29297e231dbeSJesse Barnes int pipe; 29307e231dbeSJesse Barnes 29317e231dbeSJesse Barnes /* VLV magic */ 29327e231dbeSJesse Barnes I915_WRITE(VLV_IMR, 0); 29337e231dbeSJesse Barnes I915_WRITE(RING_IMR(RENDER_RING_BASE), 0); 29347e231dbeSJesse Barnes I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0); 29357e231dbeSJesse Barnes I915_WRITE(RING_IMR(BLT_RING_BASE), 0); 29367e231dbeSJesse Barnes 29377e231dbeSJesse Barnes /* and GT */ 29387e231dbeSJesse Barnes I915_WRITE(GTIIR, I915_READ(GTIIR)); 29397e231dbeSJesse Barnes I915_WRITE(GTIIR, I915_READ(GTIIR)); 2940d18ea1b5SDaniel Vetter 29417c4d664eSPaulo Zanoni gen5_gt_irq_reset(dev); 29427e231dbeSJesse Barnes 29437e231dbeSJesse Barnes I915_WRITE(DPINVGTT, 0xff); 29447e231dbeSJesse Barnes 29457e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_EN, 0); 29467e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 29477e231dbeSJesse Barnes for_each_pipe(pipe) 29487e231dbeSJesse Barnes I915_WRITE(PIPESTAT(pipe), 0xffff); 29497e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 29507e231dbeSJesse Barnes I915_WRITE(VLV_IMR, 0xffffffff); 29517e231dbeSJesse Barnes I915_WRITE(VLV_IER, 0x0); 29527e231dbeSJesse Barnes POSTING_READ(VLV_IER); 29537e231dbeSJesse Barnes } 29547e231dbeSJesse Barnes 2955823f6b38SPaulo Zanoni static void gen8_irq_reset(struct drm_device *dev) 2956abd58f01SBen Widawsky { 2957abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 2958abd58f01SBen Widawsky int pipe; 2959abd58f01SBen Widawsky 2960abd58f01SBen Widawsky I915_WRITE(GEN8_MASTER_IRQ, 0); 2961abd58f01SBen Widawsky POSTING_READ(GEN8_MASTER_IRQ); 2962abd58f01SBen Widawsky 2963f86f3fb0SPaulo Zanoni GEN8_IRQ_RESET_NDX(GT, 0); 2964f86f3fb0SPaulo Zanoni GEN8_IRQ_RESET_NDX(GT, 1); 2965f86f3fb0SPaulo Zanoni GEN8_IRQ_RESET_NDX(GT, 2); 2966f86f3fb0SPaulo Zanoni GEN8_IRQ_RESET_NDX(GT, 3); 2967abd58f01SBen Widawsky 2968823f6b38SPaulo Zanoni for_each_pipe(pipe) 2969f86f3fb0SPaulo Zanoni GEN8_IRQ_RESET_NDX(DE_PIPE, pipe); 2970abd58f01SBen Widawsky 2971f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(GEN8_DE_PORT_); 2972f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(GEN8_DE_MISC_); 2973f86f3fb0SPaulo Zanoni GEN5_IRQ_RESET(GEN8_PCU_); 2974abd58f01SBen Widawsky 29751c69eb42SPaulo Zanoni ibx_irq_reset(dev); 2976abd58f01SBen Widawsky } 2977abd58f01SBen Widawsky 2978823f6b38SPaulo Zanoni static void gen8_irq_preinstall(struct drm_device *dev) 2979823f6b38SPaulo Zanoni { 2980823f6b38SPaulo Zanoni gen8_irq_reset(dev); 2981abd58f01SBen Widawsky } 2982abd58f01SBen Widawsky 298382a28bcfSDaniel Vetter static void ibx_hpd_irq_setup(struct drm_device *dev) 298482a28bcfSDaniel Vetter { 29852d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 298682a28bcfSDaniel Vetter struct drm_mode_config *mode_config = &dev->mode_config; 298782a28bcfSDaniel Vetter struct intel_encoder *intel_encoder; 2988fee884edSDaniel Vetter u32 hotplug_irqs, hotplug, enabled_irqs = 0; 298982a28bcfSDaniel Vetter 299082a28bcfSDaniel Vetter if (HAS_PCH_IBX(dev)) { 2991fee884edSDaniel Vetter hotplug_irqs = SDE_HOTPLUG_MASK; 299282a28bcfSDaniel Vetter list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head) 2993cd569aedSEgbert Eich if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) 2994fee884edSDaniel Vetter enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin]; 299582a28bcfSDaniel Vetter } else { 2996fee884edSDaniel Vetter hotplug_irqs = SDE_HOTPLUG_MASK_CPT; 299782a28bcfSDaniel Vetter list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head) 2998cd569aedSEgbert Eich if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) 2999fee884edSDaniel Vetter enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin]; 300082a28bcfSDaniel Vetter } 300182a28bcfSDaniel Vetter 3002fee884edSDaniel Vetter ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); 300382a28bcfSDaniel Vetter 30047fe0b973SKeith Packard /* 30057fe0b973SKeith Packard * Enable digital hotplug on the PCH, and configure the DP short pulse 30067fe0b973SKeith Packard * duration to 2ms (which is the minimum in the Display Port spec) 30077fe0b973SKeith Packard * 30087fe0b973SKeith Packard * This register is the same on all known PCH chips. 30097fe0b973SKeith Packard */ 30107fe0b973SKeith Packard hotplug = I915_READ(PCH_PORT_HOTPLUG); 30117fe0b973SKeith Packard hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK); 30127fe0b973SKeith Packard hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms; 30137fe0b973SKeith Packard hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms; 30147fe0b973SKeith Packard hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms; 30157fe0b973SKeith Packard I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 30167fe0b973SKeith Packard } 30177fe0b973SKeith Packard 3018d46da437SPaulo Zanoni static void ibx_irq_postinstall(struct drm_device *dev) 3019d46da437SPaulo Zanoni { 30202d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 302182a28bcfSDaniel Vetter u32 mask; 3022d46da437SPaulo Zanoni 3023692a04cfSDaniel Vetter if (HAS_PCH_NOP(dev)) 3024692a04cfSDaniel Vetter return; 3025692a04cfSDaniel Vetter 3026105b122eSPaulo Zanoni if (HAS_PCH_IBX(dev)) 30275c673b60SDaniel Vetter mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON; 3028105b122eSPaulo Zanoni else 30295c673b60SDaniel Vetter mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT; 30308664281bSPaulo Zanoni 3031337ba017SPaulo Zanoni GEN5_ASSERT_IIR_IS_ZERO(SDEIIR); 3032d46da437SPaulo Zanoni I915_WRITE(SDEIMR, ~mask); 3033d46da437SPaulo Zanoni } 3034d46da437SPaulo Zanoni 30350a9a8c91SDaniel Vetter static void gen5_gt_irq_postinstall(struct drm_device *dev) 30360a9a8c91SDaniel Vetter { 30370a9a8c91SDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 30380a9a8c91SDaniel Vetter u32 pm_irqs, gt_irqs; 30390a9a8c91SDaniel Vetter 30400a9a8c91SDaniel Vetter pm_irqs = gt_irqs = 0; 30410a9a8c91SDaniel Vetter 30420a9a8c91SDaniel Vetter dev_priv->gt_irq_mask = ~0; 3043040d2baaSBen Widawsky if (HAS_L3_DPF(dev)) { 30440a9a8c91SDaniel Vetter /* L3 parity interrupt is always unmasked. */ 304535a85ac6SBen Widawsky dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev); 304635a85ac6SBen Widawsky gt_irqs |= GT_PARITY_ERROR(dev); 30470a9a8c91SDaniel Vetter } 30480a9a8c91SDaniel Vetter 30490a9a8c91SDaniel Vetter gt_irqs |= GT_RENDER_USER_INTERRUPT; 30500a9a8c91SDaniel Vetter if (IS_GEN5(dev)) { 30510a9a8c91SDaniel Vetter gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT | 30520a9a8c91SDaniel Vetter ILK_BSD_USER_INTERRUPT; 30530a9a8c91SDaniel Vetter } else { 30540a9a8c91SDaniel Vetter gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT; 30550a9a8c91SDaniel Vetter } 30560a9a8c91SDaniel Vetter 305735079899SPaulo Zanoni GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs); 30580a9a8c91SDaniel Vetter 30590a9a8c91SDaniel Vetter if (INTEL_INFO(dev)->gen >= 6) { 3060a6706b45SDeepak S pm_irqs |= dev_priv->pm_rps_events; 30610a9a8c91SDaniel Vetter 30620a9a8c91SDaniel Vetter if (HAS_VEBOX(dev)) 30630a9a8c91SDaniel Vetter pm_irqs |= PM_VEBOX_USER_INTERRUPT; 30640a9a8c91SDaniel Vetter 3065605cd25bSPaulo Zanoni dev_priv->pm_irq_mask = 0xffffffff; 306635079899SPaulo Zanoni GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs); 30670a9a8c91SDaniel Vetter } 30680a9a8c91SDaniel Vetter } 30690a9a8c91SDaniel Vetter 3070f71d4af4SJesse Barnes static int ironlake_irq_postinstall(struct drm_device *dev) 3071036a4a7dSZhenyu Wang { 30724bc9d430SDaniel Vetter unsigned long irqflags; 30732d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 30748e76f8dcSPaulo Zanoni u32 display_mask, extra_mask; 30758e76f8dcSPaulo Zanoni 30768e76f8dcSPaulo Zanoni if (INTEL_INFO(dev)->gen >= 7) { 30778e76f8dcSPaulo Zanoni display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | 30788e76f8dcSPaulo Zanoni DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB | 30798e76f8dcSPaulo Zanoni DE_PLANEB_FLIP_DONE_IVB | 30805c673b60SDaniel Vetter DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB); 30818e76f8dcSPaulo Zanoni extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB | 30825c673b60SDaniel Vetter DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB); 30838e76f8dcSPaulo Zanoni } else { 30848e76f8dcSPaulo Zanoni display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | 3085ce99c256SDaniel Vetter DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE | 30865b3a856bSDaniel Vetter DE_AUX_CHANNEL_A | 30875b3a856bSDaniel Vetter DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE | 30885b3a856bSDaniel Vetter DE_POISON); 30895c673b60SDaniel Vetter extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT | 30905c673b60SDaniel Vetter DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN; 30918e76f8dcSPaulo Zanoni } 3092036a4a7dSZhenyu Wang 30931ec14ad3SChris Wilson dev_priv->irq_mask = ~display_mask; 3094036a4a7dSZhenyu Wang 30950c841212SPaulo Zanoni I915_WRITE(HWSTAM, 0xeffe); 30960c841212SPaulo Zanoni 3097622364b6SPaulo Zanoni ibx_irq_pre_postinstall(dev); 3098622364b6SPaulo Zanoni 309935079899SPaulo Zanoni GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask); 3100036a4a7dSZhenyu Wang 31010a9a8c91SDaniel Vetter gen5_gt_irq_postinstall(dev); 3102036a4a7dSZhenyu Wang 3103d46da437SPaulo Zanoni ibx_irq_postinstall(dev); 31047fe0b973SKeith Packard 3105f97108d1SJesse Barnes if (IS_IRONLAKE_M(dev)) { 31066005ce42SDaniel Vetter /* Enable PCU event interrupts 31076005ce42SDaniel Vetter * 31086005ce42SDaniel Vetter * spinlocking not required here for correctness since interrupt 31094bc9d430SDaniel Vetter * setup is guaranteed to run in single-threaded context. But we 31104bc9d430SDaniel Vetter * need it to make the assert_spin_locked happy. */ 31114bc9d430SDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3112f97108d1SJesse Barnes ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT); 31134bc9d430SDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3114f97108d1SJesse Barnes } 3115f97108d1SJesse Barnes 3116036a4a7dSZhenyu Wang return 0; 3117036a4a7dSZhenyu Wang } 3118036a4a7dSZhenyu Wang 3119f8b79e58SImre Deak static void valleyview_display_irqs_install(struct drm_i915_private *dev_priv) 3120f8b79e58SImre Deak { 3121f8b79e58SImre Deak u32 pipestat_mask; 3122f8b79e58SImre Deak u32 iir_mask; 3123f8b79e58SImre Deak 3124f8b79e58SImre Deak pipestat_mask = PIPESTAT_INT_STATUS_MASK | 3125f8b79e58SImre Deak PIPE_FIFO_UNDERRUN_STATUS; 3126f8b79e58SImre Deak 3127f8b79e58SImre Deak I915_WRITE(PIPESTAT(PIPE_A), pipestat_mask); 3128f8b79e58SImre Deak I915_WRITE(PIPESTAT(PIPE_B), pipestat_mask); 3129f8b79e58SImre Deak POSTING_READ(PIPESTAT(PIPE_A)); 3130f8b79e58SImre Deak 3131f8b79e58SImre Deak pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV | 3132f8b79e58SImre Deak PIPE_CRC_DONE_INTERRUPT_STATUS; 3133f8b79e58SImre Deak 3134f8b79e58SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, pipestat_mask | 3135f8b79e58SImre Deak PIPE_GMBUS_INTERRUPT_STATUS); 3136f8b79e58SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, pipestat_mask); 3137f8b79e58SImre Deak 3138f8b79e58SImre Deak iir_mask = I915_DISPLAY_PORT_INTERRUPT | 3139f8b79e58SImre Deak I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3140f8b79e58SImre Deak I915_DISPLAY_PIPE_B_EVENT_INTERRUPT; 3141f8b79e58SImre Deak dev_priv->irq_mask &= ~iir_mask; 3142f8b79e58SImre Deak 3143f8b79e58SImre Deak I915_WRITE(VLV_IIR, iir_mask); 3144f8b79e58SImre Deak I915_WRITE(VLV_IIR, iir_mask); 3145f8b79e58SImre Deak I915_WRITE(VLV_IMR, dev_priv->irq_mask); 3146f8b79e58SImre Deak I915_WRITE(VLV_IER, ~dev_priv->irq_mask); 3147f8b79e58SImre Deak POSTING_READ(VLV_IER); 3148f8b79e58SImre Deak } 3149f8b79e58SImre Deak 3150f8b79e58SImre Deak static void valleyview_display_irqs_uninstall(struct drm_i915_private *dev_priv) 3151f8b79e58SImre Deak { 3152f8b79e58SImre Deak u32 pipestat_mask; 3153f8b79e58SImre Deak u32 iir_mask; 3154f8b79e58SImre Deak 3155f8b79e58SImre Deak iir_mask = I915_DISPLAY_PORT_INTERRUPT | 3156f8b79e58SImre Deak I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 31576c7fba04SImre Deak I915_DISPLAY_PIPE_B_EVENT_INTERRUPT; 3158f8b79e58SImre Deak 3159f8b79e58SImre Deak dev_priv->irq_mask |= iir_mask; 3160f8b79e58SImre Deak I915_WRITE(VLV_IER, ~dev_priv->irq_mask); 3161f8b79e58SImre Deak I915_WRITE(VLV_IMR, dev_priv->irq_mask); 3162f8b79e58SImre Deak I915_WRITE(VLV_IIR, iir_mask); 3163f8b79e58SImre Deak I915_WRITE(VLV_IIR, iir_mask); 3164f8b79e58SImre Deak POSTING_READ(VLV_IIR); 3165f8b79e58SImre Deak 3166f8b79e58SImre Deak pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV | 3167f8b79e58SImre Deak PIPE_CRC_DONE_INTERRUPT_STATUS; 3168f8b79e58SImre Deak 3169f8b79e58SImre Deak i915_disable_pipestat(dev_priv, PIPE_A, pipestat_mask | 3170f8b79e58SImre Deak PIPE_GMBUS_INTERRUPT_STATUS); 3171f8b79e58SImre Deak i915_disable_pipestat(dev_priv, PIPE_B, pipestat_mask); 3172f8b79e58SImre Deak 3173f8b79e58SImre Deak pipestat_mask = PIPESTAT_INT_STATUS_MASK | 3174f8b79e58SImre Deak PIPE_FIFO_UNDERRUN_STATUS; 3175f8b79e58SImre Deak I915_WRITE(PIPESTAT(PIPE_A), pipestat_mask); 3176f8b79e58SImre Deak I915_WRITE(PIPESTAT(PIPE_B), pipestat_mask); 3177f8b79e58SImre Deak POSTING_READ(PIPESTAT(PIPE_A)); 3178f8b79e58SImre Deak } 3179f8b79e58SImre Deak 3180f8b79e58SImre Deak void valleyview_enable_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 = true; 3188f8b79e58SImre Deak 3189f8b79e58SImre Deak if (dev_priv->dev->irq_enabled) 3190f8b79e58SImre Deak valleyview_display_irqs_install(dev_priv); 3191f8b79e58SImre Deak } 3192f8b79e58SImre Deak 3193f8b79e58SImre Deak void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv) 3194f8b79e58SImre Deak { 3195f8b79e58SImre Deak assert_spin_locked(&dev_priv->irq_lock); 3196f8b79e58SImre Deak 3197f8b79e58SImre Deak if (!dev_priv->display_irqs_enabled) 3198f8b79e58SImre Deak return; 3199f8b79e58SImre Deak 3200f8b79e58SImre Deak dev_priv->display_irqs_enabled = false; 3201f8b79e58SImre Deak 3202f8b79e58SImre Deak if (dev_priv->dev->irq_enabled) 3203f8b79e58SImre Deak valleyview_display_irqs_uninstall(dev_priv); 3204f8b79e58SImre Deak } 3205f8b79e58SImre Deak 32067e231dbeSJesse Barnes static int valleyview_irq_postinstall(struct drm_device *dev) 32077e231dbeSJesse Barnes { 32082d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3209b79480baSDaniel Vetter unsigned long irqflags; 32107e231dbeSJesse Barnes 3211f8b79e58SImre Deak dev_priv->irq_mask = ~0; 32127e231dbeSJesse Barnes 321320afbda2SDaniel Vetter I915_WRITE(PORT_HOTPLUG_EN, 0); 321420afbda2SDaniel Vetter POSTING_READ(PORT_HOTPLUG_EN); 321520afbda2SDaniel Vetter 32167e231dbeSJesse Barnes I915_WRITE(VLV_IMR, dev_priv->irq_mask); 3217f8b79e58SImre Deak I915_WRITE(VLV_IER, ~dev_priv->irq_mask); 32187e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 32197e231dbeSJesse Barnes POSTING_READ(VLV_IER); 32207e231dbeSJesse Barnes 3221b79480baSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3222b79480baSDaniel Vetter * just to make the assert_spin_locked check happy. */ 3223b79480baSDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3224f8b79e58SImre Deak if (dev_priv->display_irqs_enabled) 3225f8b79e58SImre Deak valleyview_display_irqs_install(dev_priv); 3226b79480baSDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 322731acc7f5SJesse Barnes 32287e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 32297e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 32307e231dbeSJesse Barnes 32310a9a8c91SDaniel Vetter gen5_gt_irq_postinstall(dev); 32327e231dbeSJesse Barnes 32337e231dbeSJesse Barnes /* ack & enable invalid PTE error interrupts */ 32347e231dbeSJesse Barnes #if 0 /* FIXME: add support to irq handler for checking these bits */ 32357e231dbeSJesse Barnes I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK); 32367e231dbeSJesse Barnes I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK); 32377e231dbeSJesse Barnes #endif 32387e231dbeSJesse Barnes 32397e231dbeSJesse Barnes I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE); 324020afbda2SDaniel Vetter 324120afbda2SDaniel Vetter return 0; 324220afbda2SDaniel Vetter } 324320afbda2SDaniel Vetter 3244abd58f01SBen Widawsky static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv) 3245abd58f01SBen Widawsky { 3246abd58f01SBen Widawsky int i; 3247abd58f01SBen Widawsky 3248abd58f01SBen Widawsky /* These are interrupts we'll toggle with the ring mask register */ 3249abd58f01SBen Widawsky uint32_t gt_interrupts[] = { 3250abd58f01SBen Widawsky GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT | 3251abd58f01SBen Widawsky GT_RENDER_L3_PARITY_ERROR_INTERRUPT | 3252abd58f01SBen Widawsky GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT, 3253abd58f01SBen Widawsky GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT | 3254abd58f01SBen Widawsky GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT, 3255abd58f01SBen Widawsky 0, 3256abd58f01SBen Widawsky GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT 3257abd58f01SBen Widawsky }; 3258abd58f01SBen Widawsky 3259337ba017SPaulo Zanoni for (i = 0; i < ARRAY_SIZE(gt_interrupts); i++) 326035079899SPaulo Zanoni GEN8_IRQ_INIT_NDX(GT, i, ~gt_interrupts[i], gt_interrupts[i]); 3261abd58f01SBen Widawsky } 3262abd58f01SBen Widawsky 3263abd58f01SBen Widawsky static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv) 3264abd58f01SBen Widawsky { 3265abd58f01SBen Widawsky struct drm_device *dev = dev_priv->dev; 3266d0e1f1cbSDamien Lespiau uint32_t de_pipe_masked = GEN8_PIPE_PRIMARY_FLIP_DONE | 32670fbe7870SDaniel Vetter GEN8_PIPE_CDCLK_CRC_DONE | 326830100f2bSDaniel Vetter GEN8_DE_PIPE_IRQ_FAULT_ERRORS; 32695c673b60SDaniel Vetter uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK | 32705c673b60SDaniel Vetter GEN8_PIPE_FIFO_UNDERRUN; 3271abd58f01SBen Widawsky int pipe; 327213b3a0a7SDaniel Vetter dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked; 327313b3a0a7SDaniel Vetter dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked; 327413b3a0a7SDaniel Vetter dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked; 3275abd58f01SBen Widawsky 3276337ba017SPaulo Zanoni for_each_pipe(pipe) 327735079899SPaulo Zanoni GEN8_IRQ_INIT_NDX(DE_PIPE, pipe, dev_priv->de_irq_mask[pipe], 327835079899SPaulo Zanoni de_pipe_enables); 3279abd58f01SBen Widawsky 328035079899SPaulo Zanoni GEN5_IRQ_INIT(GEN8_DE_PORT_, ~GEN8_AUX_CHANNEL_A, GEN8_AUX_CHANNEL_A); 3281abd58f01SBen Widawsky } 3282abd58f01SBen Widawsky 3283abd58f01SBen Widawsky static int gen8_irq_postinstall(struct drm_device *dev) 3284abd58f01SBen Widawsky { 3285abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 3286abd58f01SBen Widawsky 3287622364b6SPaulo Zanoni ibx_irq_pre_postinstall(dev); 3288622364b6SPaulo Zanoni 3289abd58f01SBen Widawsky gen8_gt_irq_postinstall(dev_priv); 3290abd58f01SBen Widawsky gen8_de_irq_postinstall(dev_priv); 3291abd58f01SBen Widawsky 3292abd58f01SBen Widawsky ibx_irq_postinstall(dev); 3293abd58f01SBen Widawsky 3294abd58f01SBen Widawsky I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL); 3295abd58f01SBen Widawsky POSTING_READ(GEN8_MASTER_IRQ); 3296abd58f01SBen Widawsky 3297abd58f01SBen Widawsky return 0; 3298abd58f01SBen Widawsky } 3299abd58f01SBen Widawsky 3300abd58f01SBen Widawsky static void gen8_irq_uninstall(struct drm_device *dev) 3301abd58f01SBen Widawsky { 3302abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 3303abd58f01SBen Widawsky 3304abd58f01SBen Widawsky if (!dev_priv) 3305abd58f01SBen Widawsky return; 3306abd58f01SBen Widawsky 3307d4eb6b10SPaulo Zanoni intel_hpd_irq_uninstall(dev_priv); 3308abd58f01SBen Widawsky 3309823f6b38SPaulo Zanoni gen8_irq_reset(dev); 3310abd58f01SBen Widawsky } 3311abd58f01SBen Widawsky 33127e231dbeSJesse Barnes static void valleyview_irq_uninstall(struct drm_device *dev) 33137e231dbeSJesse Barnes { 33142d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3315f8b79e58SImre Deak unsigned long irqflags; 33167e231dbeSJesse Barnes int pipe; 33177e231dbeSJesse Barnes 33187e231dbeSJesse Barnes if (!dev_priv) 33197e231dbeSJesse Barnes return; 33207e231dbeSJesse Barnes 3321*843d0e7dSImre Deak I915_WRITE(VLV_MASTER_IER, 0); 3322*843d0e7dSImre Deak 33233ca1ccedSVille Syrjälä intel_hpd_irq_uninstall(dev_priv); 3324ac4c16c5SEgbert Eich 33257e231dbeSJesse Barnes for_each_pipe(pipe) 33267e231dbeSJesse Barnes I915_WRITE(PIPESTAT(pipe), 0xffff); 33277e231dbeSJesse Barnes 33287e231dbeSJesse Barnes I915_WRITE(HWSTAM, 0xffffffff); 33297e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_EN, 0); 33307e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3331f8b79e58SImre Deak 3332f8b79e58SImre Deak spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3333f8b79e58SImre Deak if (dev_priv->display_irqs_enabled) 3334f8b79e58SImre Deak valleyview_display_irqs_uninstall(dev_priv); 3335f8b79e58SImre Deak spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3336f8b79e58SImre Deak 3337f8b79e58SImre Deak dev_priv->irq_mask = 0; 3338f8b79e58SImre Deak 33397e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 33407e231dbeSJesse Barnes I915_WRITE(VLV_IMR, 0xffffffff); 33417e231dbeSJesse Barnes I915_WRITE(VLV_IER, 0x0); 33427e231dbeSJesse Barnes POSTING_READ(VLV_IER); 33437e231dbeSJesse Barnes } 33447e231dbeSJesse Barnes 3345f71d4af4SJesse Barnes static void ironlake_irq_uninstall(struct drm_device *dev) 3346036a4a7dSZhenyu Wang { 33472d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 33484697995bSJesse Barnes 33494697995bSJesse Barnes if (!dev_priv) 33504697995bSJesse Barnes return; 33514697995bSJesse Barnes 33523ca1ccedSVille Syrjälä intel_hpd_irq_uninstall(dev_priv); 3353ac4c16c5SEgbert Eich 3354be30b29fSPaulo Zanoni ironlake_irq_reset(dev); 3355036a4a7dSZhenyu Wang } 3356036a4a7dSZhenyu Wang 3357c2798b19SChris Wilson static void i8xx_irq_preinstall(struct drm_device * dev) 3358c2798b19SChris Wilson { 33592d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3360c2798b19SChris Wilson int pipe; 3361c2798b19SChris Wilson 3362c2798b19SChris Wilson for_each_pipe(pipe) 3363c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3364c2798b19SChris Wilson I915_WRITE16(IMR, 0xffff); 3365c2798b19SChris Wilson I915_WRITE16(IER, 0x0); 3366c2798b19SChris Wilson POSTING_READ16(IER); 3367c2798b19SChris Wilson } 3368c2798b19SChris Wilson 3369c2798b19SChris Wilson static int i8xx_irq_postinstall(struct drm_device *dev) 3370c2798b19SChris Wilson { 33712d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3372379ef82dSDaniel Vetter unsigned long irqflags; 3373c2798b19SChris Wilson 3374c2798b19SChris Wilson I915_WRITE16(EMR, 3375c2798b19SChris Wilson ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH)); 3376c2798b19SChris Wilson 3377c2798b19SChris Wilson /* Unmask the interrupts that we always want on. */ 3378c2798b19SChris Wilson dev_priv->irq_mask = 3379c2798b19SChris Wilson ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3380c2798b19SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3381c2798b19SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 3382c2798b19SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | 3383c2798b19SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 3384c2798b19SChris Wilson I915_WRITE16(IMR, dev_priv->irq_mask); 3385c2798b19SChris Wilson 3386c2798b19SChris Wilson I915_WRITE16(IER, 3387c2798b19SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3388c2798b19SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3389c2798b19SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT | 3390c2798b19SChris Wilson I915_USER_INTERRUPT); 3391c2798b19SChris Wilson POSTING_READ16(IER); 3392c2798b19SChris Wilson 3393379ef82dSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3394379ef82dSDaniel Vetter * just to make the assert_spin_locked check happy. */ 3395379ef82dSDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3396755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 3397755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 3398379ef82dSDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3399379ef82dSDaniel Vetter 3400c2798b19SChris Wilson return 0; 3401c2798b19SChris Wilson } 3402c2798b19SChris Wilson 340390a72f87SVille Syrjälä /* 340490a72f87SVille Syrjälä * Returns true when a page flip has completed. 340590a72f87SVille Syrjälä */ 340690a72f87SVille Syrjälä static bool i8xx_handle_vblank(struct drm_device *dev, 34071f1c2e24SVille Syrjälä int plane, int pipe, u32 iir) 340890a72f87SVille Syrjälä { 34092d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 34101f1c2e24SVille Syrjälä u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane); 341190a72f87SVille Syrjälä 341290a72f87SVille Syrjälä if (!drm_handle_vblank(dev, pipe)) 341390a72f87SVille Syrjälä return false; 341490a72f87SVille Syrjälä 341590a72f87SVille Syrjälä if ((iir & flip_pending) == 0) 341690a72f87SVille Syrjälä return false; 341790a72f87SVille Syrjälä 34181f1c2e24SVille Syrjälä intel_prepare_page_flip(dev, plane); 341990a72f87SVille Syrjälä 342090a72f87SVille Syrjälä /* We detect FlipDone by looking for the change in PendingFlip from '1' 342190a72f87SVille Syrjälä * to '0' on the following vblank, i.e. IIR has the Pendingflip 342290a72f87SVille Syrjälä * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence 342390a72f87SVille Syrjälä * the flip is completed (no longer pending). Since this doesn't raise 342490a72f87SVille Syrjälä * an interrupt per se, we watch for the change at vblank. 342590a72f87SVille Syrjälä */ 342690a72f87SVille Syrjälä if (I915_READ16(ISR) & flip_pending) 342790a72f87SVille Syrjälä return false; 342890a72f87SVille Syrjälä 342990a72f87SVille Syrjälä intel_finish_page_flip(dev, pipe); 343090a72f87SVille Syrjälä 343190a72f87SVille Syrjälä return true; 343290a72f87SVille Syrjälä } 343390a72f87SVille Syrjälä 3434ff1f525eSDaniel Vetter static irqreturn_t i8xx_irq_handler(int irq, void *arg) 3435c2798b19SChris Wilson { 3436c2798b19SChris Wilson struct drm_device *dev = (struct drm_device *) arg; 34372d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3438c2798b19SChris Wilson u16 iir, new_iir; 3439c2798b19SChris Wilson u32 pipe_stats[2]; 3440c2798b19SChris Wilson unsigned long irqflags; 3441c2798b19SChris Wilson int pipe; 3442c2798b19SChris Wilson u16 flip_mask = 3443c2798b19SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 3444c2798b19SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 3445c2798b19SChris Wilson 3446c2798b19SChris Wilson iir = I915_READ16(IIR); 3447c2798b19SChris Wilson if (iir == 0) 3448c2798b19SChris Wilson return IRQ_NONE; 3449c2798b19SChris Wilson 3450c2798b19SChris Wilson while (iir & ~flip_mask) { 3451c2798b19SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 3452c2798b19SChris Wilson * have been cleared after the pipestat interrupt was received. 3453c2798b19SChris Wilson * It doesn't set the bit in iir again, but it still produces 3454c2798b19SChris Wilson * interrupts (for non-MSI). 3455c2798b19SChris Wilson */ 3456c2798b19SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3457c2798b19SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 345858174462SMika Kuoppala i915_handle_error(dev, false, 345958174462SMika Kuoppala "Command parser error, iir 0x%08x", 346058174462SMika Kuoppala iir); 3461c2798b19SChris Wilson 3462c2798b19SChris Wilson for_each_pipe(pipe) { 3463c2798b19SChris Wilson int reg = PIPESTAT(pipe); 3464c2798b19SChris Wilson pipe_stats[pipe] = I915_READ(reg); 3465c2798b19SChris Wilson 3466c2798b19SChris Wilson /* 3467c2798b19SChris Wilson * Clear the PIPE*STAT regs before the IIR 3468c2798b19SChris Wilson */ 34692d9d2b0bSVille Syrjälä if (pipe_stats[pipe] & 0x8000ffff) 3470c2798b19SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 3471c2798b19SChris Wilson } 3472c2798b19SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3473c2798b19SChris Wilson 3474c2798b19SChris Wilson I915_WRITE16(IIR, iir & ~flip_mask); 3475c2798b19SChris Wilson new_iir = I915_READ16(IIR); /* Flush posted writes */ 3476c2798b19SChris Wilson 3477d05c617eSDaniel Vetter i915_update_dri1_breadcrumb(dev); 3478c2798b19SChris Wilson 3479c2798b19SChris Wilson if (iir & I915_USER_INTERRUPT) 3480c2798b19SChris Wilson notify_ring(dev, &dev_priv->ring[RCS]); 3481c2798b19SChris Wilson 34824356d586SDaniel Vetter for_each_pipe(pipe) { 34831f1c2e24SVille Syrjälä int plane = pipe; 34843a77c4c4SDaniel Vetter if (HAS_FBC(dev)) 34851f1c2e24SVille Syrjälä plane = !plane; 34861f1c2e24SVille Syrjälä 34874356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS && 34881f1c2e24SVille Syrjälä i8xx_handle_vblank(dev, plane, pipe, iir)) 34891f1c2e24SVille Syrjälä flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane); 3490c2798b19SChris Wilson 34914356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 3492277de95eSDaniel Vetter i9xx_pipe_crc_irq_handler(dev, pipe); 34932d9d2b0bSVille Syrjälä 34942d9d2b0bSVille Syrjälä if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS && 34952d9d2b0bSVille Syrjälä intel_set_cpu_fifo_underrun_reporting(dev, pipe, false)) 3496fc2c807bSVille Syrjälä DRM_ERROR("pipe %c underrun\n", pipe_name(pipe)); 34974356d586SDaniel Vetter } 3498c2798b19SChris Wilson 3499c2798b19SChris Wilson iir = new_iir; 3500c2798b19SChris Wilson } 3501c2798b19SChris Wilson 3502c2798b19SChris Wilson return IRQ_HANDLED; 3503c2798b19SChris Wilson } 3504c2798b19SChris Wilson 3505c2798b19SChris Wilson static void i8xx_irq_uninstall(struct drm_device * dev) 3506c2798b19SChris Wilson { 35072d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3508c2798b19SChris Wilson int pipe; 3509c2798b19SChris Wilson 3510c2798b19SChris Wilson for_each_pipe(pipe) { 3511c2798b19SChris Wilson /* Clear enable bits; then clear status bits */ 3512c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3513c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe))); 3514c2798b19SChris Wilson } 3515c2798b19SChris Wilson I915_WRITE16(IMR, 0xffff); 3516c2798b19SChris Wilson I915_WRITE16(IER, 0x0); 3517c2798b19SChris Wilson I915_WRITE16(IIR, I915_READ16(IIR)); 3518c2798b19SChris Wilson } 3519c2798b19SChris Wilson 3520a266c7d5SChris Wilson static void i915_irq_preinstall(struct drm_device * dev) 3521a266c7d5SChris Wilson { 35222d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3523a266c7d5SChris Wilson int pipe; 3524a266c7d5SChris Wilson 3525a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 3526a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 3527a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3528a266c7d5SChris Wilson } 3529a266c7d5SChris Wilson 353000d98ebdSChris Wilson I915_WRITE16(HWSTAM, 0xeffe); 3531a266c7d5SChris Wilson for_each_pipe(pipe) 3532a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3533a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 3534a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 3535a266c7d5SChris Wilson POSTING_READ(IER); 3536a266c7d5SChris Wilson } 3537a266c7d5SChris Wilson 3538a266c7d5SChris Wilson static int i915_irq_postinstall(struct drm_device *dev) 3539a266c7d5SChris Wilson { 35402d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 354138bde180SChris Wilson u32 enable_mask; 3542379ef82dSDaniel Vetter unsigned long irqflags; 3543a266c7d5SChris Wilson 354438bde180SChris Wilson I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH)); 354538bde180SChris Wilson 354638bde180SChris Wilson /* Unmask the interrupts that we always want on. */ 354738bde180SChris Wilson dev_priv->irq_mask = 354838bde180SChris Wilson ~(I915_ASLE_INTERRUPT | 354938bde180SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 355038bde180SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 355138bde180SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 355238bde180SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | 355338bde180SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 355438bde180SChris Wilson 355538bde180SChris Wilson enable_mask = 355638bde180SChris Wilson I915_ASLE_INTERRUPT | 355738bde180SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 355838bde180SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 355938bde180SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT | 356038bde180SChris Wilson I915_USER_INTERRUPT; 356138bde180SChris Wilson 3562a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 356320afbda2SDaniel Vetter I915_WRITE(PORT_HOTPLUG_EN, 0); 356420afbda2SDaniel Vetter POSTING_READ(PORT_HOTPLUG_EN); 356520afbda2SDaniel Vetter 3566a266c7d5SChris Wilson /* Enable in IER... */ 3567a266c7d5SChris Wilson enable_mask |= I915_DISPLAY_PORT_INTERRUPT; 3568a266c7d5SChris Wilson /* and unmask in IMR */ 3569a266c7d5SChris Wilson dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT; 3570a266c7d5SChris Wilson } 3571a266c7d5SChris Wilson 3572a266c7d5SChris Wilson I915_WRITE(IMR, dev_priv->irq_mask); 3573a266c7d5SChris Wilson I915_WRITE(IER, enable_mask); 3574a266c7d5SChris Wilson POSTING_READ(IER); 3575a266c7d5SChris Wilson 3576f49e38ddSJani Nikula i915_enable_asle_pipestat(dev); 357720afbda2SDaniel Vetter 3578379ef82dSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3579379ef82dSDaniel Vetter * just to make the assert_spin_locked check happy. */ 3580379ef82dSDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3581755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 3582755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 3583379ef82dSDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3584379ef82dSDaniel Vetter 358520afbda2SDaniel Vetter return 0; 358620afbda2SDaniel Vetter } 358720afbda2SDaniel Vetter 358890a72f87SVille Syrjälä /* 358990a72f87SVille Syrjälä * Returns true when a page flip has completed. 359090a72f87SVille Syrjälä */ 359190a72f87SVille Syrjälä static bool i915_handle_vblank(struct drm_device *dev, 359290a72f87SVille Syrjälä int plane, int pipe, u32 iir) 359390a72f87SVille Syrjälä { 35942d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 359590a72f87SVille Syrjälä u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane); 359690a72f87SVille Syrjälä 359790a72f87SVille Syrjälä if (!drm_handle_vblank(dev, pipe)) 359890a72f87SVille Syrjälä return false; 359990a72f87SVille Syrjälä 360090a72f87SVille Syrjälä if ((iir & flip_pending) == 0) 360190a72f87SVille Syrjälä return false; 360290a72f87SVille Syrjälä 360390a72f87SVille Syrjälä intel_prepare_page_flip(dev, plane); 360490a72f87SVille Syrjälä 360590a72f87SVille Syrjälä /* We detect FlipDone by looking for the change in PendingFlip from '1' 360690a72f87SVille Syrjälä * to '0' on the following vblank, i.e. IIR has the Pendingflip 360790a72f87SVille Syrjälä * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence 360890a72f87SVille Syrjälä * the flip is completed (no longer pending). Since this doesn't raise 360990a72f87SVille Syrjälä * an interrupt per se, we watch for the change at vblank. 361090a72f87SVille Syrjälä */ 361190a72f87SVille Syrjälä if (I915_READ(ISR) & flip_pending) 361290a72f87SVille Syrjälä return false; 361390a72f87SVille Syrjälä 361490a72f87SVille Syrjälä intel_finish_page_flip(dev, pipe); 361590a72f87SVille Syrjälä 361690a72f87SVille Syrjälä return true; 361790a72f87SVille Syrjälä } 361890a72f87SVille Syrjälä 3619ff1f525eSDaniel Vetter static irqreturn_t i915_irq_handler(int irq, void *arg) 3620a266c7d5SChris Wilson { 3621a266c7d5SChris Wilson struct drm_device *dev = (struct drm_device *) arg; 36222d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 36238291ee90SChris Wilson u32 iir, new_iir, pipe_stats[I915_MAX_PIPES]; 3624a266c7d5SChris Wilson unsigned long irqflags; 362538bde180SChris Wilson u32 flip_mask = 362638bde180SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 362738bde180SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 362838bde180SChris Wilson int pipe, ret = IRQ_NONE; 3629a266c7d5SChris Wilson 3630a266c7d5SChris Wilson iir = I915_READ(IIR); 363138bde180SChris Wilson do { 363238bde180SChris Wilson bool irq_received = (iir & ~flip_mask) != 0; 36338291ee90SChris Wilson bool blc_event = false; 3634a266c7d5SChris Wilson 3635a266c7d5SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 3636a266c7d5SChris Wilson * have been cleared after the pipestat interrupt was received. 3637a266c7d5SChris Wilson * It doesn't set the bit in iir again, but it still produces 3638a266c7d5SChris Wilson * interrupts (for non-MSI). 3639a266c7d5SChris Wilson */ 3640a266c7d5SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3641a266c7d5SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 364258174462SMika Kuoppala i915_handle_error(dev, false, 364358174462SMika Kuoppala "Command parser error, iir 0x%08x", 364458174462SMika Kuoppala iir); 3645a266c7d5SChris Wilson 3646a266c7d5SChris Wilson for_each_pipe(pipe) { 3647a266c7d5SChris Wilson int reg = PIPESTAT(pipe); 3648a266c7d5SChris Wilson pipe_stats[pipe] = I915_READ(reg); 3649a266c7d5SChris Wilson 365038bde180SChris Wilson /* Clear the PIPE*STAT regs before the IIR */ 3651a266c7d5SChris Wilson if (pipe_stats[pipe] & 0x8000ffff) { 3652a266c7d5SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 365338bde180SChris Wilson irq_received = true; 3654a266c7d5SChris Wilson } 3655a266c7d5SChris Wilson } 3656a266c7d5SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3657a266c7d5SChris Wilson 3658a266c7d5SChris Wilson if (!irq_received) 3659a266c7d5SChris Wilson break; 3660a266c7d5SChris Wilson 3661a266c7d5SChris Wilson /* Consume port. Then clear IIR or we'll miss events */ 366216c6c56bSVille Syrjälä if (I915_HAS_HOTPLUG(dev) && 366316c6c56bSVille Syrjälä iir & I915_DISPLAY_PORT_INTERRUPT) 366416c6c56bSVille Syrjälä i9xx_hpd_irq_handler(dev); 3665a266c7d5SChris Wilson 366638bde180SChris Wilson I915_WRITE(IIR, iir & ~flip_mask); 3667a266c7d5SChris Wilson new_iir = I915_READ(IIR); /* Flush posted writes */ 3668a266c7d5SChris Wilson 3669a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 3670a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[RCS]); 3671a266c7d5SChris Wilson 3672a266c7d5SChris Wilson for_each_pipe(pipe) { 367338bde180SChris Wilson int plane = pipe; 36743a77c4c4SDaniel Vetter if (HAS_FBC(dev)) 367538bde180SChris Wilson plane = !plane; 36765e2032d4SVille Syrjälä 367790a72f87SVille Syrjälä if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS && 367890a72f87SVille Syrjälä i915_handle_vblank(dev, plane, pipe, iir)) 367990a72f87SVille Syrjälä flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane); 3680a266c7d5SChris Wilson 3681a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 3682a266c7d5SChris Wilson blc_event = true; 36834356d586SDaniel Vetter 36844356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 3685277de95eSDaniel Vetter i9xx_pipe_crc_irq_handler(dev, pipe); 36862d9d2b0bSVille Syrjälä 36872d9d2b0bSVille Syrjälä if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS && 36882d9d2b0bSVille Syrjälä intel_set_cpu_fifo_underrun_reporting(dev, pipe, false)) 3689fc2c807bSVille Syrjälä DRM_ERROR("pipe %c underrun\n", pipe_name(pipe)); 3690a266c7d5SChris Wilson } 3691a266c7d5SChris Wilson 3692a266c7d5SChris Wilson if (blc_event || (iir & I915_ASLE_INTERRUPT)) 3693a266c7d5SChris Wilson intel_opregion_asle_intr(dev); 3694a266c7d5SChris Wilson 3695a266c7d5SChris Wilson /* With MSI, interrupts are only generated when iir 3696a266c7d5SChris Wilson * transitions from zero to nonzero. If another bit got 3697a266c7d5SChris Wilson * set while we were handling the existing iir bits, then 3698a266c7d5SChris Wilson * we would never get another interrupt. 3699a266c7d5SChris Wilson * 3700a266c7d5SChris Wilson * This is fine on non-MSI as well, as if we hit this path 3701a266c7d5SChris Wilson * we avoid exiting the interrupt handler only to generate 3702a266c7d5SChris Wilson * another one. 3703a266c7d5SChris Wilson * 3704a266c7d5SChris Wilson * Note that for MSI this could cause a stray interrupt report 3705a266c7d5SChris Wilson * if an interrupt landed in the time between writing IIR and 3706a266c7d5SChris Wilson * the posting read. This should be rare enough to never 3707a266c7d5SChris Wilson * trigger the 99% of 100,000 interrupts test for disabling 3708a266c7d5SChris Wilson * stray interrupts. 3709a266c7d5SChris Wilson */ 371038bde180SChris Wilson ret = IRQ_HANDLED; 3711a266c7d5SChris Wilson iir = new_iir; 371238bde180SChris Wilson } while (iir & ~flip_mask); 3713a266c7d5SChris Wilson 3714d05c617eSDaniel Vetter i915_update_dri1_breadcrumb(dev); 37158291ee90SChris Wilson 3716a266c7d5SChris Wilson return ret; 3717a266c7d5SChris Wilson } 3718a266c7d5SChris Wilson 3719a266c7d5SChris Wilson static void i915_irq_uninstall(struct drm_device * dev) 3720a266c7d5SChris Wilson { 37212d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3722a266c7d5SChris Wilson int pipe; 3723a266c7d5SChris Wilson 37243ca1ccedSVille Syrjälä intel_hpd_irq_uninstall(dev_priv); 3725ac4c16c5SEgbert Eich 3726a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 3727a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 3728a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3729a266c7d5SChris Wilson } 3730a266c7d5SChris Wilson 373100d98ebdSChris Wilson I915_WRITE16(HWSTAM, 0xffff); 373255b39755SChris Wilson for_each_pipe(pipe) { 373355b39755SChris Wilson /* Clear enable bits; then clear status bits */ 3734a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 373555b39755SChris Wilson I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe))); 373655b39755SChris Wilson } 3737a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 3738a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 3739a266c7d5SChris Wilson 3740a266c7d5SChris Wilson I915_WRITE(IIR, I915_READ(IIR)); 3741a266c7d5SChris Wilson } 3742a266c7d5SChris Wilson 3743a266c7d5SChris Wilson static void i965_irq_preinstall(struct drm_device * dev) 3744a266c7d5SChris Wilson { 37452d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3746a266c7d5SChris Wilson int pipe; 3747a266c7d5SChris Wilson 3748a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 3749a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3750a266c7d5SChris Wilson 3751a266c7d5SChris Wilson I915_WRITE(HWSTAM, 0xeffe); 3752a266c7d5SChris Wilson for_each_pipe(pipe) 3753a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3754a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 3755a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 3756a266c7d5SChris Wilson POSTING_READ(IER); 3757a266c7d5SChris Wilson } 3758a266c7d5SChris Wilson 3759a266c7d5SChris Wilson static int i965_irq_postinstall(struct drm_device *dev) 3760a266c7d5SChris Wilson { 37612d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3762bbba0a97SChris Wilson u32 enable_mask; 3763a266c7d5SChris Wilson u32 error_mask; 3764b79480baSDaniel Vetter unsigned long irqflags; 3765a266c7d5SChris Wilson 3766a266c7d5SChris Wilson /* Unmask the interrupts that we always want on. */ 3767bbba0a97SChris Wilson dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT | 3768adca4730SChris Wilson I915_DISPLAY_PORT_INTERRUPT | 3769bbba0a97SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3770bbba0a97SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3771bbba0a97SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 3772bbba0a97SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | 3773bbba0a97SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 3774bbba0a97SChris Wilson 3775bbba0a97SChris Wilson enable_mask = ~dev_priv->irq_mask; 377621ad8330SVille Syrjälä enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 377721ad8330SVille Syrjälä I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT); 3778bbba0a97SChris Wilson enable_mask |= I915_USER_INTERRUPT; 3779bbba0a97SChris Wilson 3780bbba0a97SChris Wilson if (IS_G4X(dev)) 3781bbba0a97SChris Wilson enable_mask |= I915_BSD_USER_INTERRUPT; 3782a266c7d5SChris Wilson 3783b79480baSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3784b79480baSDaniel Vetter * just to make the assert_spin_locked check happy. */ 3785b79480baSDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3786755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS); 3787755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 3788755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 3789b79480baSDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3790a266c7d5SChris Wilson 3791a266c7d5SChris Wilson /* 3792a266c7d5SChris Wilson * Enable some error detection, note the instruction error mask 3793a266c7d5SChris Wilson * bit is reserved, so we leave it masked. 3794a266c7d5SChris Wilson */ 3795a266c7d5SChris Wilson if (IS_G4X(dev)) { 3796a266c7d5SChris Wilson error_mask = ~(GM45_ERROR_PAGE_TABLE | 3797a266c7d5SChris Wilson GM45_ERROR_MEM_PRIV | 3798a266c7d5SChris Wilson GM45_ERROR_CP_PRIV | 3799a266c7d5SChris Wilson I915_ERROR_MEMORY_REFRESH); 3800a266c7d5SChris Wilson } else { 3801a266c7d5SChris Wilson error_mask = ~(I915_ERROR_PAGE_TABLE | 3802a266c7d5SChris Wilson I915_ERROR_MEMORY_REFRESH); 3803a266c7d5SChris Wilson } 3804a266c7d5SChris Wilson I915_WRITE(EMR, error_mask); 3805a266c7d5SChris Wilson 3806a266c7d5SChris Wilson I915_WRITE(IMR, dev_priv->irq_mask); 3807a266c7d5SChris Wilson I915_WRITE(IER, enable_mask); 3808a266c7d5SChris Wilson POSTING_READ(IER); 3809a266c7d5SChris Wilson 381020afbda2SDaniel Vetter I915_WRITE(PORT_HOTPLUG_EN, 0); 381120afbda2SDaniel Vetter POSTING_READ(PORT_HOTPLUG_EN); 381220afbda2SDaniel Vetter 3813f49e38ddSJani Nikula i915_enable_asle_pipestat(dev); 381420afbda2SDaniel Vetter 381520afbda2SDaniel Vetter return 0; 381620afbda2SDaniel Vetter } 381720afbda2SDaniel Vetter 3818bac56d5bSEgbert Eich static void i915_hpd_irq_setup(struct drm_device *dev) 381920afbda2SDaniel Vetter { 38202d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3821e5868a31SEgbert Eich struct drm_mode_config *mode_config = &dev->mode_config; 3822cd569aedSEgbert Eich struct intel_encoder *intel_encoder; 382320afbda2SDaniel Vetter u32 hotplug_en; 382420afbda2SDaniel Vetter 3825b5ea2d56SDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 3826b5ea2d56SDaniel Vetter 3827bac56d5bSEgbert Eich if (I915_HAS_HOTPLUG(dev)) { 3828bac56d5bSEgbert Eich hotplug_en = I915_READ(PORT_HOTPLUG_EN); 3829bac56d5bSEgbert Eich hotplug_en &= ~HOTPLUG_INT_EN_MASK; 3830adca4730SChris Wilson /* Note HDMI and DP share hotplug bits */ 3831e5868a31SEgbert Eich /* enable bits are the same for all generations */ 3832cd569aedSEgbert Eich list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head) 3833cd569aedSEgbert Eich if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) 3834cd569aedSEgbert Eich hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin]; 3835a266c7d5SChris Wilson /* Programming the CRT detection parameters tends 3836a266c7d5SChris Wilson to generate a spurious hotplug event about three 3837a266c7d5SChris Wilson seconds later. So just do it once. 3838a266c7d5SChris Wilson */ 3839a266c7d5SChris Wilson if (IS_G4X(dev)) 3840a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64; 384185fc95baSDaniel Vetter hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK; 3842a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; 3843a266c7d5SChris Wilson 3844a266c7d5SChris Wilson /* Ignore TV since it's buggy */ 3845a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, hotplug_en); 3846a266c7d5SChris Wilson } 3847bac56d5bSEgbert Eich } 3848a266c7d5SChris Wilson 3849ff1f525eSDaniel Vetter static irqreturn_t i965_irq_handler(int irq, void *arg) 3850a266c7d5SChris Wilson { 3851a266c7d5SChris Wilson struct drm_device *dev = (struct drm_device *) arg; 38522d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3853a266c7d5SChris Wilson u32 iir, new_iir; 3854a266c7d5SChris Wilson u32 pipe_stats[I915_MAX_PIPES]; 3855a266c7d5SChris Wilson unsigned long irqflags; 3856a266c7d5SChris Wilson int ret = IRQ_NONE, pipe; 385721ad8330SVille Syrjälä u32 flip_mask = 385821ad8330SVille Syrjälä I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 385921ad8330SVille Syrjälä I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 3860a266c7d5SChris Wilson 3861a266c7d5SChris Wilson iir = I915_READ(IIR); 3862a266c7d5SChris Wilson 3863a266c7d5SChris Wilson for (;;) { 3864501e01d7SVille Syrjälä bool irq_received = (iir & ~flip_mask) != 0; 38652c8ba29fSChris Wilson bool blc_event = false; 38662c8ba29fSChris Wilson 3867a266c7d5SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 3868a266c7d5SChris Wilson * have been cleared after the pipestat interrupt was received. 3869a266c7d5SChris Wilson * It doesn't set the bit in iir again, but it still produces 3870a266c7d5SChris Wilson * interrupts (for non-MSI). 3871a266c7d5SChris Wilson */ 3872a266c7d5SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3873a266c7d5SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 387458174462SMika Kuoppala i915_handle_error(dev, false, 387558174462SMika Kuoppala "Command parser error, iir 0x%08x", 387658174462SMika Kuoppala iir); 3877a266c7d5SChris Wilson 3878a266c7d5SChris Wilson for_each_pipe(pipe) { 3879a266c7d5SChris Wilson int reg = PIPESTAT(pipe); 3880a266c7d5SChris Wilson pipe_stats[pipe] = I915_READ(reg); 3881a266c7d5SChris Wilson 3882a266c7d5SChris Wilson /* 3883a266c7d5SChris Wilson * Clear the PIPE*STAT regs before the IIR 3884a266c7d5SChris Wilson */ 3885a266c7d5SChris Wilson if (pipe_stats[pipe] & 0x8000ffff) { 3886a266c7d5SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 3887501e01d7SVille Syrjälä irq_received = true; 3888a266c7d5SChris Wilson } 3889a266c7d5SChris Wilson } 3890a266c7d5SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3891a266c7d5SChris Wilson 3892a266c7d5SChris Wilson if (!irq_received) 3893a266c7d5SChris Wilson break; 3894a266c7d5SChris Wilson 3895a266c7d5SChris Wilson ret = IRQ_HANDLED; 3896a266c7d5SChris Wilson 3897a266c7d5SChris Wilson /* Consume port. Then clear IIR or we'll miss events */ 389816c6c56bSVille Syrjälä if (iir & I915_DISPLAY_PORT_INTERRUPT) 389916c6c56bSVille Syrjälä i9xx_hpd_irq_handler(dev); 3900a266c7d5SChris Wilson 390121ad8330SVille Syrjälä I915_WRITE(IIR, iir & ~flip_mask); 3902a266c7d5SChris Wilson new_iir = I915_READ(IIR); /* Flush posted writes */ 3903a266c7d5SChris Wilson 3904a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 3905a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[RCS]); 3906a266c7d5SChris Wilson if (iir & I915_BSD_USER_INTERRUPT) 3907a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[VCS]); 3908a266c7d5SChris Wilson 3909a266c7d5SChris Wilson for_each_pipe(pipe) { 39102c8ba29fSChris Wilson if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS && 391190a72f87SVille Syrjälä i915_handle_vblank(dev, pipe, pipe, iir)) 391290a72f87SVille Syrjälä flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe); 3913a266c7d5SChris Wilson 3914a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 3915a266c7d5SChris Wilson blc_event = true; 39164356d586SDaniel Vetter 39174356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 3918277de95eSDaniel Vetter i9xx_pipe_crc_irq_handler(dev, pipe); 3919a266c7d5SChris Wilson 39202d9d2b0bSVille Syrjälä if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS && 39212d9d2b0bSVille Syrjälä intel_set_cpu_fifo_underrun_reporting(dev, pipe, false)) 3922fc2c807bSVille Syrjälä DRM_ERROR("pipe %c underrun\n", pipe_name(pipe)); 39232d9d2b0bSVille Syrjälä } 3924a266c7d5SChris Wilson 3925a266c7d5SChris Wilson if (blc_event || (iir & I915_ASLE_INTERRUPT)) 3926a266c7d5SChris Wilson intel_opregion_asle_intr(dev); 3927a266c7d5SChris Wilson 3928515ac2bbSDaniel Vetter if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 3929515ac2bbSDaniel Vetter gmbus_irq_handler(dev); 3930515ac2bbSDaniel Vetter 3931a266c7d5SChris Wilson /* With MSI, interrupts are only generated when iir 3932a266c7d5SChris Wilson * transitions from zero to nonzero. If another bit got 3933a266c7d5SChris Wilson * set while we were handling the existing iir bits, then 3934a266c7d5SChris Wilson * we would never get another interrupt. 3935a266c7d5SChris Wilson * 3936a266c7d5SChris Wilson * This is fine on non-MSI as well, as if we hit this path 3937a266c7d5SChris Wilson * we avoid exiting the interrupt handler only to generate 3938a266c7d5SChris Wilson * another one. 3939a266c7d5SChris Wilson * 3940a266c7d5SChris Wilson * Note that for MSI this could cause a stray interrupt report 3941a266c7d5SChris Wilson * if an interrupt landed in the time between writing IIR and 3942a266c7d5SChris Wilson * the posting read. This should be rare enough to never 3943a266c7d5SChris Wilson * trigger the 99% of 100,000 interrupts test for disabling 3944a266c7d5SChris Wilson * stray interrupts. 3945a266c7d5SChris Wilson */ 3946a266c7d5SChris Wilson iir = new_iir; 3947a266c7d5SChris Wilson } 3948a266c7d5SChris Wilson 3949d05c617eSDaniel Vetter i915_update_dri1_breadcrumb(dev); 39502c8ba29fSChris Wilson 3951a266c7d5SChris Wilson return ret; 3952a266c7d5SChris Wilson } 3953a266c7d5SChris Wilson 3954a266c7d5SChris Wilson static void i965_irq_uninstall(struct drm_device * dev) 3955a266c7d5SChris Wilson { 39562d1013ddSJani Nikula struct drm_i915_private *dev_priv = dev->dev_private; 3957a266c7d5SChris Wilson int pipe; 3958a266c7d5SChris Wilson 3959a266c7d5SChris Wilson if (!dev_priv) 3960a266c7d5SChris Wilson return; 3961a266c7d5SChris Wilson 39623ca1ccedSVille Syrjälä intel_hpd_irq_uninstall(dev_priv); 3963ac4c16c5SEgbert Eich 3964a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 3965a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3966a266c7d5SChris Wilson 3967a266c7d5SChris Wilson I915_WRITE(HWSTAM, 0xffffffff); 3968a266c7d5SChris Wilson for_each_pipe(pipe) 3969a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3970a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 3971a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 3972a266c7d5SChris Wilson 3973a266c7d5SChris Wilson for_each_pipe(pipe) 3974a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 3975a266c7d5SChris Wilson I915_READ(PIPESTAT(pipe)) & 0x8000ffff); 3976a266c7d5SChris Wilson I915_WRITE(IIR, I915_READ(IIR)); 3977a266c7d5SChris Wilson } 3978a266c7d5SChris Wilson 39793ca1ccedSVille Syrjälä static void intel_hpd_irq_reenable(unsigned long data) 3980ac4c16c5SEgbert Eich { 39812d1013ddSJani Nikula struct drm_i915_private *dev_priv = (struct drm_i915_private *)data; 3982ac4c16c5SEgbert Eich struct drm_device *dev = dev_priv->dev; 3983ac4c16c5SEgbert Eich struct drm_mode_config *mode_config = &dev->mode_config; 3984ac4c16c5SEgbert Eich unsigned long irqflags; 3985ac4c16c5SEgbert Eich int i; 3986ac4c16c5SEgbert Eich 3987ac4c16c5SEgbert Eich spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3988ac4c16c5SEgbert Eich for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) { 3989ac4c16c5SEgbert Eich struct drm_connector *connector; 3990ac4c16c5SEgbert Eich 3991ac4c16c5SEgbert Eich if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED) 3992ac4c16c5SEgbert Eich continue; 3993ac4c16c5SEgbert Eich 3994ac4c16c5SEgbert Eich dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED; 3995ac4c16c5SEgbert Eich 3996ac4c16c5SEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 3997ac4c16c5SEgbert Eich struct intel_connector *intel_connector = to_intel_connector(connector); 3998ac4c16c5SEgbert Eich 3999ac4c16c5SEgbert Eich if (intel_connector->encoder->hpd_pin == i) { 4000ac4c16c5SEgbert Eich if (connector->polled != intel_connector->polled) 4001ac4c16c5SEgbert Eich DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n", 4002ac4c16c5SEgbert Eich drm_get_connector_name(connector)); 4003ac4c16c5SEgbert Eich connector->polled = intel_connector->polled; 4004ac4c16c5SEgbert Eich if (!connector->polled) 4005ac4c16c5SEgbert Eich connector->polled = DRM_CONNECTOR_POLL_HPD; 4006ac4c16c5SEgbert Eich } 4007ac4c16c5SEgbert Eich } 4008ac4c16c5SEgbert Eich } 4009ac4c16c5SEgbert Eich if (dev_priv->display.hpd_irq_setup) 4010ac4c16c5SEgbert Eich dev_priv->display.hpd_irq_setup(dev); 4011ac4c16c5SEgbert Eich spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 4012ac4c16c5SEgbert Eich } 4013ac4c16c5SEgbert Eich 4014f71d4af4SJesse Barnes void intel_irq_init(struct drm_device *dev) 4015f71d4af4SJesse Barnes { 40168b2e326dSChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 40178b2e326dSChris Wilson 40188b2e326dSChris Wilson INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func); 401999584db3SDaniel Vetter INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func); 4020c6a828d3SDaniel Vetter INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work); 4021a4da4fa4SDaniel Vetter INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work); 40228b2e326dSChris Wilson 4023a6706b45SDeepak S /* Let's track the enabled rps events */ 4024a6706b45SDeepak S dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS; 4025a6706b45SDeepak S 402699584db3SDaniel Vetter setup_timer(&dev_priv->gpu_error.hangcheck_timer, 402799584db3SDaniel Vetter i915_hangcheck_elapsed, 402861bac78eSDaniel Vetter (unsigned long) dev); 40293ca1ccedSVille Syrjälä setup_timer(&dev_priv->hotplug_reenable_timer, intel_hpd_irq_reenable, 4030ac4c16c5SEgbert Eich (unsigned long) dev_priv); 403161bac78eSDaniel Vetter 403297a19a24STomas Janousek pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE); 40339ee32feaSDaniel Vetter 40344cdb83ecSVille Syrjälä if (IS_GEN2(dev)) { 40354cdb83ecSVille Syrjälä dev->max_vblank_count = 0; 40364cdb83ecSVille Syrjälä dev->driver->get_vblank_counter = i8xx_get_vblank_counter; 40374cdb83ecSVille Syrjälä } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { 4038f71d4af4SJesse Barnes dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */ 4039f71d4af4SJesse Barnes dev->driver->get_vblank_counter = gm45_get_vblank_counter; 4040391f75e2SVille Syrjälä } else { 4041391f75e2SVille Syrjälä dev->driver->get_vblank_counter = i915_get_vblank_counter; 4042391f75e2SVille Syrjälä dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ 4043f71d4af4SJesse Barnes } 4044f71d4af4SJesse Barnes 4045c2baf4b7SVille Syrjälä if (drm_core_check_feature(dev, DRIVER_MODESET)) { 4046f71d4af4SJesse Barnes dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp; 4047f71d4af4SJesse Barnes dev->driver->get_scanout_position = i915_get_crtc_scanoutpos; 4048c2baf4b7SVille Syrjälä } 4049f71d4af4SJesse Barnes 40507e231dbeSJesse Barnes if (IS_VALLEYVIEW(dev)) { 40517e231dbeSJesse Barnes dev->driver->irq_handler = valleyview_irq_handler; 40527e231dbeSJesse Barnes dev->driver->irq_preinstall = valleyview_irq_preinstall; 40537e231dbeSJesse Barnes dev->driver->irq_postinstall = valleyview_irq_postinstall; 40547e231dbeSJesse Barnes dev->driver->irq_uninstall = valleyview_irq_uninstall; 40557e231dbeSJesse Barnes dev->driver->enable_vblank = valleyview_enable_vblank; 40567e231dbeSJesse Barnes dev->driver->disable_vblank = valleyview_disable_vblank; 4057fa00abe0SEgbert Eich dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 4058abd58f01SBen Widawsky } else if (IS_GEN8(dev)) { 4059abd58f01SBen Widawsky dev->driver->irq_handler = gen8_irq_handler; 4060abd58f01SBen Widawsky dev->driver->irq_preinstall = gen8_irq_preinstall; 4061abd58f01SBen Widawsky dev->driver->irq_postinstall = gen8_irq_postinstall; 4062abd58f01SBen Widawsky dev->driver->irq_uninstall = gen8_irq_uninstall; 4063abd58f01SBen Widawsky dev->driver->enable_vblank = gen8_enable_vblank; 4064abd58f01SBen Widawsky dev->driver->disable_vblank = gen8_disable_vblank; 4065abd58f01SBen Widawsky dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup; 4066f71d4af4SJesse Barnes } else if (HAS_PCH_SPLIT(dev)) { 4067f71d4af4SJesse Barnes dev->driver->irq_handler = ironlake_irq_handler; 4068f71d4af4SJesse Barnes dev->driver->irq_preinstall = ironlake_irq_preinstall; 4069f71d4af4SJesse Barnes dev->driver->irq_postinstall = ironlake_irq_postinstall; 4070f71d4af4SJesse Barnes dev->driver->irq_uninstall = ironlake_irq_uninstall; 4071f71d4af4SJesse Barnes dev->driver->enable_vblank = ironlake_enable_vblank; 4072f71d4af4SJesse Barnes dev->driver->disable_vblank = ironlake_disable_vblank; 407382a28bcfSDaniel Vetter dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup; 4074f71d4af4SJesse Barnes } else { 4075c2798b19SChris Wilson if (INTEL_INFO(dev)->gen == 2) { 4076c2798b19SChris Wilson dev->driver->irq_preinstall = i8xx_irq_preinstall; 4077c2798b19SChris Wilson dev->driver->irq_postinstall = i8xx_irq_postinstall; 4078c2798b19SChris Wilson dev->driver->irq_handler = i8xx_irq_handler; 4079c2798b19SChris Wilson dev->driver->irq_uninstall = i8xx_irq_uninstall; 4080a266c7d5SChris Wilson } else if (INTEL_INFO(dev)->gen == 3) { 4081a266c7d5SChris Wilson dev->driver->irq_preinstall = i915_irq_preinstall; 4082a266c7d5SChris Wilson dev->driver->irq_postinstall = i915_irq_postinstall; 4083a266c7d5SChris Wilson dev->driver->irq_uninstall = i915_irq_uninstall; 4084a266c7d5SChris Wilson dev->driver->irq_handler = i915_irq_handler; 408520afbda2SDaniel Vetter dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 4086c2798b19SChris Wilson } else { 4087a266c7d5SChris Wilson dev->driver->irq_preinstall = i965_irq_preinstall; 4088a266c7d5SChris Wilson dev->driver->irq_postinstall = i965_irq_postinstall; 4089a266c7d5SChris Wilson dev->driver->irq_uninstall = i965_irq_uninstall; 4090a266c7d5SChris Wilson dev->driver->irq_handler = i965_irq_handler; 4091bac56d5bSEgbert Eich dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 4092c2798b19SChris Wilson } 4093f71d4af4SJesse Barnes dev->driver->enable_vblank = i915_enable_vblank; 4094f71d4af4SJesse Barnes dev->driver->disable_vblank = i915_disable_vblank; 4095f71d4af4SJesse Barnes } 4096f71d4af4SJesse Barnes } 409720afbda2SDaniel Vetter 409820afbda2SDaniel Vetter void intel_hpd_init(struct drm_device *dev) 409920afbda2SDaniel Vetter { 410020afbda2SDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 4101821450c6SEgbert Eich struct drm_mode_config *mode_config = &dev->mode_config; 4102821450c6SEgbert Eich struct drm_connector *connector; 4103b5ea2d56SDaniel Vetter unsigned long irqflags; 4104821450c6SEgbert Eich int i; 410520afbda2SDaniel Vetter 4106821450c6SEgbert Eich for (i = 1; i < HPD_NUM_PINS; i++) { 4107821450c6SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt = 0; 4108821450c6SEgbert Eich dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED; 4109821450c6SEgbert Eich } 4110821450c6SEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 4111821450c6SEgbert Eich struct intel_connector *intel_connector = to_intel_connector(connector); 4112821450c6SEgbert Eich connector->polled = intel_connector->polled; 4113821450c6SEgbert Eich if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE) 4114821450c6SEgbert Eich connector->polled = DRM_CONNECTOR_POLL_HPD; 4115821450c6SEgbert Eich } 4116b5ea2d56SDaniel Vetter 4117b5ea2d56SDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 4118b5ea2d56SDaniel Vetter * just to make the assert_spin_locked checks happy. */ 4119b5ea2d56SDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 412020afbda2SDaniel Vetter if (dev_priv->display.hpd_irq_setup) 412120afbda2SDaniel Vetter dev_priv->display.hpd_irq_setup(dev); 4122b5ea2d56SDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 412320afbda2SDaniel Vetter } 4124c67a470bSPaulo Zanoni 41255d584b2eSPaulo Zanoni /* Disable interrupts so we can allow runtime PM. */ 4126730488b2SPaulo Zanoni void intel_runtime_pm_disable_interrupts(struct drm_device *dev) 4127c67a470bSPaulo Zanoni { 4128c67a470bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 4129c67a470bSPaulo Zanoni 4130730488b2SPaulo Zanoni dev->driver->irq_uninstall(dev); 41315d584b2eSPaulo Zanoni dev_priv->pm.irqs_disabled = true; 4132c67a470bSPaulo Zanoni } 4133c67a470bSPaulo Zanoni 41345d584b2eSPaulo Zanoni /* Restore interrupts so we can recover from runtime PM. */ 4135730488b2SPaulo Zanoni void intel_runtime_pm_restore_interrupts(struct drm_device *dev) 4136c67a470bSPaulo Zanoni { 4137c67a470bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 4138c67a470bSPaulo Zanoni 41395d584b2eSPaulo Zanoni dev_priv->pm.irqs_disabled = false; 4140730488b2SPaulo Zanoni dev->driver->irq_preinstall(dev); 4141730488b2SPaulo Zanoni dev->driver->irq_postinstall(dev); 4142c67a470bSPaulo Zanoni } 4143