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 83036a4a7dSZhenyu Wang /* For display hotplug interrupt */ 84995b6762SChris Wilson static void 85f2b115e6SAdam Jackson ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask) 86036a4a7dSZhenyu Wang { 874bc9d430SDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 884bc9d430SDaniel Vetter 89c67a470bSPaulo Zanoni if (dev_priv->pc8.irqs_disabled) { 90c67a470bSPaulo Zanoni WARN(1, "IRQs disabled\n"); 91c67a470bSPaulo Zanoni dev_priv->pc8.regsave.deimr &= ~mask; 92c67a470bSPaulo Zanoni return; 93c67a470bSPaulo Zanoni } 94c67a470bSPaulo Zanoni 951ec14ad3SChris Wilson if ((dev_priv->irq_mask & mask) != 0) { 961ec14ad3SChris Wilson dev_priv->irq_mask &= ~mask; 971ec14ad3SChris Wilson I915_WRITE(DEIMR, dev_priv->irq_mask); 983143a2bfSChris Wilson POSTING_READ(DEIMR); 99036a4a7dSZhenyu Wang } 100036a4a7dSZhenyu Wang } 101036a4a7dSZhenyu Wang 1020ff9800aSPaulo Zanoni static void 103f2b115e6SAdam Jackson ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask) 104036a4a7dSZhenyu Wang { 1054bc9d430SDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 1064bc9d430SDaniel Vetter 107c67a470bSPaulo Zanoni if (dev_priv->pc8.irqs_disabled) { 108c67a470bSPaulo Zanoni WARN(1, "IRQs disabled\n"); 109c67a470bSPaulo Zanoni dev_priv->pc8.regsave.deimr |= mask; 110c67a470bSPaulo Zanoni return; 111c67a470bSPaulo Zanoni } 112c67a470bSPaulo Zanoni 1131ec14ad3SChris Wilson if ((dev_priv->irq_mask & mask) != mask) { 1141ec14ad3SChris Wilson dev_priv->irq_mask |= mask; 1151ec14ad3SChris Wilson I915_WRITE(DEIMR, dev_priv->irq_mask); 1163143a2bfSChris Wilson POSTING_READ(DEIMR); 117036a4a7dSZhenyu Wang } 118036a4a7dSZhenyu Wang } 119036a4a7dSZhenyu Wang 12043eaea13SPaulo Zanoni /** 12143eaea13SPaulo Zanoni * ilk_update_gt_irq - update GTIMR 12243eaea13SPaulo Zanoni * @dev_priv: driver private 12343eaea13SPaulo Zanoni * @interrupt_mask: mask of interrupt bits to update 12443eaea13SPaulo Zanoni * @enabled_irq_mask: mask of interrupt bits to enable 12543eaea13SPaulo Zanoni */ 12643eaea13SPaulo Zanoni static void ilk_update_gt_irq(struct drm_i915_private *dev_priv, 12743eaea13SPaulo Zanoni uint32_t interrupt_mask, 12843eaea13SPaulo Zanoni uint32_t enabled_irq_mask) 12943eaea13SPaulo Zanoni { 13043eaea13SPaulo Zanoni assert_spin_locked(&dev_priv->irq_lock); 13143eaea13SPaulo Zanoni 132c67a470bSPaulo Zanoni if (dev_priv->pc8.irqs_disabled) { 133c67a470bSPaulo Zanoni WARN(1, "IRQs disabled\n"); 134c67a470bSPaulo Zanoni dev_priv->pc8.regsave.gtimr &= ~interrupt_mask; 135c67a470bSPaulo Zanoni dev_priv->pc8.regsave.gtimr |= (~enabled_irq_mask & 136c67a470bSPaulo Zanoni interrupt_mask); 137c67a470bSPaulo Zanoni return; 138c67a470bSPaulo Zanoni } 139c67a470bSPaulo Zanoni 14043eaea13SPaulo Zanoni dev_priv->gt_irq_mask &= ~interrupt_mask; 14143eaea13SPaulo Zanoni dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask); 14243eaea13SPaulo Zanoni I915_WRITE(GTIMR, dev_priv->gt_irq_mask); 14343eaea13SPaulo Zanoni POSTING_READ(GTIMR); 14443eaea13SPaulo Zanoni } 14543eaea13SPaulo Zanoni 14643eaea13SPaulo Zanoni void ilk_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask) 14743eaea13SPaulo Zanoni { 14843eaea13SPaulo Zanoni ilk_update_gt_irq(dev_priv, mask, mask); 14943eaea13SPaulo Zanoni } 15043eaea13SPaulo Zanoni 15143eaea13SPaulo Zanoni void ilk_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask) 15243eaea13SPaulo Zanoni { 15343eaea13SPaulo Zanoni ilk_update_gt_irq(dev_priv, mask, 0); 15443eaea13SPaulo Zanoni } 15543eaea13SPaulo Zanoni 156edbfdb45SPaulo Zanoni /** 157edbfdb45SPaulo Zanoni * snb_update_pm_irq - update GEN6_PMIMR 158edbfdb45SPaulo Zanoni * @dev_priv: driver private 159edbfdb45SPaulo Zanoni * @interrupt_mask: mask of interrupt bits to update 160edbfdb45SPaulo Zanoni * @enabled_irq_mask: mask of interrupt bits to enable 161edbfdb45SPaulo Zanoni */ 162edbfdb45SPaulo Zanoni static void snb_update_pm_irq(struct drm_i915_private *dev_priv, 163edbfdb45SPaulo Zanoni uint32_t interrupt_mask, 164edbfdb45SPaulo Zanoni uint32_t enabled_irq_mask) 165edbfdb45SPaulo Zanoni { 166605cd25bSPaulo Zanoni uint32_t new_val; 167edbfdb45SPaulo Zanoni 168edbfdb45SPaulo Zanoni assert_spin_locked(&dev_priv->irq_lock); 169edbfdb45SPaulo Zanoni 170c67a470bSPaulo Zanoni if (dev_priv->pc8.irqs_disabled) { 171c67a470bSPaulo Zanoni WARN(1, "IRQs disabled\n"); 172c67a470bSPaulo Zanoni dev_priv->pc8.regsave.gen6_pmimr &= ~interrupt_mask; 173c67a470bSPaulo Zanoni dev_priv->pc8.regsave.gen6_pmimr |= (~enabled_irq_mask & 174c67a470bSPaulo Zanoni interrupt_mask); 175c67a470bSPaulo Zanoni return; 176c67a470bSPaulo Zanoni } 177c67a470bSPaulo Zanoni 178605cd25bSPaulo Zanoni new_val = dev_priv->pm_irq_mask; 179f52ecbcfSPaulo Zanoni new_val &= ~interrupt_mask; 180f52ecbcfSPaulo Zanoni new_val |= (~enabled_irq_mask & interrupt_mask); 181f52ecbcfSPaulo Zanoni 182605cd25bSPaulo Zanoni if (new_val != dev_priv->pm_irq_mask) { 183605cd25bSPaulo Zanoni dev_priv->pm_irq_mask = new_val; 184605cd25bSPaulo Zanoni I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask); 185edbfdb45SPaulo Zanoni POSTING_READ(GEN6_PMIMR); 186edbfdb45SPaulo Zanoni } 187f52ecbcfSPaulo Zanoni } 188edbfdb45SPaulo Zanoni 189edbfdb45SPaulo Zanoni void snb_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask) 190edbfdb45SPaulo Zanoni { 191edbfdb45SPaulo Zanoni snb_update_pm_irq(dev_priv, mask, mask); 192edbfdb45SPaulo Zanoni } 193edbfdb45SPaulo Zanoni 194edbfdb45SPaulo Zanoni void snb_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask) 195edbfdb45SPaulo Zanoni { 196edbfdb45SPaulo Zanoni snb_update_pm_irq(dev_priv, mask, 0); 197edbfdb45SPaulo Zanoni } 198edbfdb45SPaulo Zanoni 1998664281bSPaulo Zanoni static bool ivb_can_enable_err_int(struct drm_device *dev) 2008664281bSPaulo Zanoni { 2018664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 2028664281bSPaulo Zanoni struct intel_crtc *crtc; 2038664281bSPaulo Zanoni enum pipe pipe; 2048664281bSPaulo Zanoni 2054bc9d430SDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 2064bc9d430SDaniel Vetter 2078664281bSPaulo Zanoni for_each_pipe(pipe) { 2088664281bSPaulo Zanoni crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); 2098664281bSPaulo Zanoni 2108664281bSPaulo Zanoni if (crtc->cpu_fifo_underrun_disabled) 2118664281bSPaulo Zanoni return false; 2128664281bSPaulo Zanoni } 2138664281bSPaulo Zanoni 2148664281bSPaulo Zanoni return true; 2158664281bSPaulo Zanoni } 2168664281bSPaulo Zanoni 2178664281bSPaulo Zanoni static bool cpt_can_enable_serr_int(struct drm_device *dev) 2188664281bSPaulo Zanoni { 2198664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 2208664281bSPaulo Zanoni enum pipe pipe; 2218664281bSPaulo Zanoni struct intel_crtc *crtc; 2228664281bSPaulo Zanoni 223fee884edSDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 224fee884edSDaniel Vetter 2258664281bSPaulo Zanoni for_each_pipe(pipe) { 2268664281bSPaulo Zanoni crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); 2278664281bSPaulo Zanoni 2288664281bSPaulo Zanoni if (crtc->pch_fifo_underrun_disabled) 2298664281bSPaulo Zanoni return false; 2308664281bSPaulo Zanoni } 2318664281bSPaulo Zanoni 2328664281bSPaulo Zanoni return true; 2338664281bSPaulo Zanoni } 2348664281bSPaulo Zanoni 2352d9d2b0bSVille Syrjälä static void i9xx_clear_fifo_underrun(struct drm_device *dev, enum pipe pipe) 2362d9d2b0bSVille Syrjälä { 2372d9d2b0bSVille Syrjälä struct drm_i915_private *dev_priv = dev->dev_private; 2382d9d2b0bSVille Syrjälä u32 reg = PIPESTAT(pipe); 2392d9d2b0bSVille Syrjälä u32 pipestat = I915_READ(reg) & 0x7fff0000; 2402d9d2b0bSVille Syrjälä 2412d9d2b0bSVille Syrjälä assert_spin_locked(&dev_priv->irq_lock); 2422d9d2b0bSVille Syrjälä 2432d9d2b0bSVille Syrjälä I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS); 2442d9d2b0bSVille Syrjälä POSTING_READ(reg); 2452d9d2b0bSVille Syrjälä } 2462d9d2b0bSVille Syrjälä 2478664281bSPaulo Zanoni static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev, 2488664281bSPaulo Zanoni enum pipe pipe, bool enable) 2498664281bSPaulo Zanoni { 2508664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 2518664281bSPaulo Zanoni uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN : 2528664281bSPaulo Zanoni DE_PIPEB_FIFO_UNDERRUN; 2538664281bSPaulo Zanoni 2548664281bSPaulo Zanoni if (enable) 2558664281bSPaulo Zanoni ironlake_enable_display_irq(dev_priv, bit); 2568664281bSPaulo Zanoni else 2578664281bSPaulo Zanoni ironlake_disable_display_irq(dev_priv, bit); 2588664281bSPaulo Zanoni } 2598664281bSPaulo Zanoni 2608664281bSPaulo Zanoni static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev, 2617336df65SDaniel Vetter enum pipe pipe, bool enable) 2628664281bSPaulo Zanoni { 2638664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 2648664281bSPaulo Zanoni if (enable) { 2657336df65SDaniel Vetter I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe)); 2667336df65SDaniel Vetter 2678664281bSPaulo Zanoni if (!ivb_can_enable_err_int(dev)) 2688664281bSPaulo Zanoni return; 2698664281bSPaulo Zanoni 2708664281bSPaulo Zanoni ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB); 2718664281bSPaulo Zanoni } else { 2727336df65SDaniel Vetter bool was_enabled = !(I915_READ(DEIMR) & DE_ERR_INT_IVB); 2737336df65SDaniel Vetter 2747336df65SDaniel Vetter /* Change the state _after_ we've read out the current one. */ 2758664281bSPaulo Zanoni ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB); 2767336df65SDaniel Vetter 2777336df65SDaniel Vetter if (!was_enabled && 2787336df65SDaniel Vetter (I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe))) { 2797336df65SDaniel Vetter DRM_DEBUG_KMS("uncleared fifo underrun on pipe %c\n", 2807336df65SDaniel Vetter pipe_name(pipe)); 2817336df65SDaniel Vetter } 2828664281bSPaulo Zanoni } 2838664281bSPaulo Zanoni } 2848664281bSPaulo Zanoni 28538d83c96SDaniel Vetter static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev, 28638d83c96SDaniel Vetter enum pipe pipe, bool enable) 28738d83c96SDaniel Vetter { 28838d83c96SDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 28938d83c96SDaniel Vetter 29038d83c96SDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 29138d83c96SDaniel Vetter 29238d83c96SDaniel Vetter if (enable) 29338d83c96SDaniel Vetter dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_FIFO_UNDERRUN; 29438d83c96SDaniel Vetter else 29538d83c96SDaniel Vetter dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_FIFO_UNDERRUN; 29638d83c96SDaniel Vetter I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]); 29738d83c96SDaniel Vetter POSTING_READ(GEN8_DE_PIPE_IMR(pipe)); 29838d83c96SDaniel Vetter } 29938d83c96SDaniel Vetter 300fee884edSDaniel Vetter /** 301fee884edSDaniel Vetter * ibx_display_interrupt_update - update SDEIMR 302fee884edSDaniel Vetter * @dev_priv: driver private 303fee884edSDaniel Vetter * @interrupt_mask: mask of interrupt bits to update 304fee884edSDaniel Vetter * @enabled_irq_mask: mask of interrupt bits to enable 305fee884edSDaniel Vetter */ 306fee884edSDaniel Vetter static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv, 307fee884edSDaniel Vetter uint32_t interrupt_mask, 308fee884edSDaniel Vetter uint32_t enabled_irq_mask) 309fee884edSDaniel Vetter { 310fee884edSDaniel Vetter uint32_t sdeimr = I915_READ(SDEIMR); 311fee884edSDaniel Vetter sdeimr &= ~interrupt_mask; 312fee884edSDaniel Vetter sdeimr |= (~enabled_irq_mask & interrupt_mask); 313fee884edSDaniel Vetter 314fee884edSDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 315fee884edSDaniel Vetter 316c67a470bSPaulo Zanoni if (dev_priv->pc8.irqs_disabled && 317c67a470bSPaulo Zanoni (interrupt_mask & SDE_HOTPLUG_MASK_CPT)) { 318c67a470bSPaulo Zanoni WARN(1, "IRQs disabled\n"); 319c67a470bSPaulo Zanoni dev_priv->pc8.regsave.sdeimr &= ~interrupt_mask; 320c67a470bSPaulo Zanoni dev_priv->pc8.regsave.sdeimr |= (~enabled_irq_mask & 321c67a470bSPaulo Zanoni interrupt_mask); 322c67a470bSPaulo Zanoni return; 323c67a470bSPaulo Zanoni } 324c67a470bSPaulo Zanoni 325fee884edSDaniel Vetter I915_WRITE(SDEIMR, sdeimr); 326fee884edSDaniel Vetter POSTING_READ(SDEIMR); 327fee884edSDaniel Vetter } 328fee884edSDaniel Vetter #define ibx_enable_display_interrupt(dev_priv, bits) \ 329fee884edSDaniel Vetter ibx_display_interrupt_update((dev_priv), (bits), (bits)) 330fee884edSDaniel Vetter #define ibx_disable_display_interrupt(dev_priv, bits) \ 331fee884edSDaniel Vetter ibx_display_interrupt_update((dev_priv), (bits), 0) 332fee884edSDaniel Vetter 333de28075dSDaniel Vetter static void ibx_set_fifo_underrun_reporting(struct drm_device *dev, 334de28075dSDaniel Vetter enum transcoder pch_transcoder, 3358664281bSPaulo Zanoni bool enable) 3368664281bSPaulo Zanoni { 3378664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 338de28075dSDaniel Vetter uint32_t bit = (pch_transcoder == TRANSCODER_A) ? 339de28075dSDaniel Vetter SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER; 3408664281bSPaulo Zanoni 3418664281bSPaulo Zanoni if (enable) 342fee884edSDaniel Vetter ibx_enable_display_interrupt(dev_priv, bit); 3438664281bSPaulo Zanoni else 344fee884edSDaniel Vetter ibx_disable_display_interrupt(dev_priv, bit); 3458664281bSPaulo Zanoni } 3468664281bSPaulo Zanoni 3478664281bSPaulo Zanoni static void cpt_set_fifo_underrun_reporting(struct drm_device *dev, 3488664281bSPaulo Zanoni enum transcoder pch_transcoder, 3498664281bSPaulo Zanoni bool enable) 3508664281bSPaulo Zanoni { 3518664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 3528664281bSPaulo Zanoni 3538664281bSPaulo Zanoni if (enable) { 3541dd246fbSDaniel Vetter I915_WRITE(SERR_INT, 3551dd246fbSDaniel Vetter SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)); 3561dd246fbSDaniel Vetter 3578664281bSPaulo Zanoni if (!cpt_can_enable_serr_int(dev)) 3588664281bSPaulo Zanoni return; 3598664281bSPaulo Zanoni 360fee884edSDaniel Vetter ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT); 3618664281bSPaulo Zanoni } else { 3621dd246fbSDaniel Vetter uint32_t tmp = I915_READ(SERR_INT); 3631dd246fbSDaniel Vetter bool was_enabled = !(I915_READ(SDEIMR) & SDE_ERROR_CPT); 3641dd246fbSDaniel Vetter 3651dd246fbSDaniel Vetter /* Change the state _after_ we've read out the current one. */ 366fee884edSDaniel Vetter ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT); 3671dd246fbSDaniel Vetter 3681dd246fbSDaniel Vetter if (!was_enabled && 3691dd246fbSDaniel Vetter (tmp & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder))) { 3701dd246fbSDaniel Vetter DRM_DEBUG_KMS("uncleared pch fifo underrun on pch transcoder %c\n", 3711dd246fbSDaniel Vetter transcoder_name(pch_transcoder)); 3721dd246fbSDaniel Vetter } 3738664281bSPaulo Zanoni } 3748664281bSPaulo Zanoni } 3758664281bSPaulo Zanoni 3768664281bSPaulo Zanoni /** 3778664281bSPaulo Zanoni * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages 3788664281bSPaulo Zanoni * @dev: drm device 3798664281bSPaulo Zanoni * @pipe: pipe 3808664281bSPaulo Zanoni * @enable: true if we want to report FIFO underrun errors, false otherwise 3818664281bSPaulo Zanoni * 3828664281bSPaulo Zanoni * This function makes us disable or enable CPU fifo underruns for a specific 3838664281bSPaulo Zanoni * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun 3848664281bSPaulo Zanoni * reporting for one pipe may also disable all the other CPU error interruts for 3858664281bSPaulo Zanoni * the other pipes, due to the fact that there's just one interrupt mask/enable 3868664281bSPaulo Zanoni * bit for all the pipes. 3878664281bSPaulo Zanoni * 3888664281bSPaulo Zanoni * Returns the previous state of underrun reporting. 3898664281bSPaulo Zanoni */ 3908664281bSPaulo Zanoni bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev, 3918664281bSPaulo Zanoni enum pipe pipe, bool enable) 3928664281bSPaulo Zanoni { 3938664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 3948664281bSPaulo Zanoni struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 3958664281bSPaulo Zanoni struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 3968664281bSPaulo Zanoni unsigned long flags; 3978664281bSPaulo Zanoni bool ret; 3988664281bSPaulo Zanoni 3998664281bSPaulo Zanoni spin_lock_irqsave(&dev_priv->irq_lock, flags); 4008664281bSPaulo Zanoni 4018664281bSPaulo Zanoni ret = !intel_crtc->cpu_fifo_underrun_disabled; 4028664281bSPaulo Zanoni 4038664281bSPaulo Zanoni if (enable == ret) 4048664281bSPaulo Zanoni goto done; 4058664281bSPaulo Zanoni 4068664281bSPaulo Zanoni intel_crtc->cpu_fifo_underrun_disabled = !enable; 4078664281bSPaulo Zanoni 4082d9d2b0bSVille Syrjälä if (enable && (INTEL_INFO(dev)->gen < 5 || IS_VALLEYVIEW(dev))) 4092d9d2b0bSVille Syrjälä i9xx_clear_fifo_underrun(dev, pipe); 4102d9d2b0bSVille Syrjälä else if (IS_GEN5(dev) || IS_GEN6(dev)) 4118664281bSPaulo Zanoni ironlake_set_fifo_underrun_reporting(dev, pipe, enable); 4128664281bSPaulo Zanoni else if (IS_GEN7(dev)) 4137336df65SDaniel Vetter ivybridge_set_fifo_underrun_reporting(dev, pipe, enable); 41438d83c96SDaniel Vetter else if (IS_GEN8(dev)) 41538d83c96SDaniel Vetter broadwell_set_fifo_underrun_reporting(dev, pipe, enable); 4168664281bSPaulo Zanoni 4178664281bSPaulo Zanoni done: 4188664281bSPaulo Zanoni spin_unlock_irqrestore(&dev_priv->irq_lock, flags); 4198664281bSPaulo Zanoni return ret; 4208664281bSPaulo Zanoni } 4218664281bSPaulo Zanoni 42291d181ddSImre Deak static bool __cpu_fifo_underrun_reporting_enabled(struct drm_device *dev, 42391d181ddSImre Deak enum pipe pipe) 42491d181ddSImre Deak { 42591d181ddSImre Deak struct drm_i915_private *dev_priv = dev->dev_private; 42691d181ddSImre Deak struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 42791d181ddSImre Deak struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 42891d181ddSImre Deak 42991d181ddSImre Deak return !intel_crtc->cpu_fifo_underrun_disabled; 43091d181ddSImre Deak } 43191d181ddSImre Deak 4328664281bSPaulo Zanoni /** 4338664281bSPaulo Zanoni * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages 4348664281bSPaulo Zanoni * @dev: drm device 4358664281bSPaulo Zanoni * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older) 4368664281bSPaulo Zanoni * @enable: true if we want to report FIFO underrun errors, false otherwise 4378664281bSPaulo Zanoni * 4388664281bSPaulo Zanoni * This function makes us disable or enable PCH fifo underruns for a specific 4398664281bSPaulo Zanoni * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO 4408664281bSPaulo Zanoni * underrun reporting for one transcoder may also disable all the other PCH 4418664281bSPaulo Zanoni * error interruts for the other transcoders, due to the fact that there's just 4428664281bSPaulo Zanoni * one interrupt mask/enable bit for all the transcoders. 4438664281bSPaulo Zanoni * 4448664281bSPaulo Zanoni * Returns the previous state of underrun reporting. 4458664281bSPaulo Zanoni */ 4468664281bSPaulo Zanoni bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev, 4478664281bSPaulo Zanoni enum transcoder pch_transcoder, 4488664281bSPaulo Zanoni bool enable) 4498664281bSPaulo Zanoni { 4508664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 451de28075dSDaniel Vetter struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder]; 452de28075dSDaniel Vetter struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 4538664281bSPaulo Zanoni unsigned long flags; 4548664281bSPaulo Zanoni bool ret; 4558664281bSPaulo Zanoni 456de28075dSDaniel Vetter /* 457de28075dSDaniel Vetter * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT 458de28075dSDaniel Vetter * has only one pch transcoder A that all pipes can use. To avoid racy 459de28075dSDaniel Vetter * pch transcoder -> pipe lookups from interrupt code simply store the 460de28075dSDaniel Vetter * underrun statistics in crtc A. Since we never expose this anywhere 461de28075dSDaniel Vetter * nor use it outside of the fifo underrun code here using the "wrong" 462de28075dSDaniel Vetter * crtc on LPT won't cause issues. 463de28075dSDaniel Vetter */ 4648664281bSPaulo Zanoni 4658664281bSPaulo Zanoni spin_lock_irqsave(&dev_priv->irq_lock, flags); 4668664281bSPaulo Zanoni 4678664281bSPaulo Zanoni ret = !intel_crtc->pch_fifo_underrun_disabled; 4688664281bSPaulo Zanoni 4698664281bSPaulo Zanoni if (enable == ret) 4708664281bSPaulo Zanoni goto done; 4718664281bSPaulo Zanoni 4728664281bSPaulo Zanoni intel_crtc->pch_fifo_underrun_disabled = !enable; 4738664281bSPaulo Zanoni 4748664281bSPaulo Zanoni if (HAS_PCH_IBX(dev)) 475de28075dSDaniel Vetter ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable); 4768664281bSPaulo Zanoni else 4778664281bSPaulo Zanoni cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable); 4788664281bSPaulo Zanoni 4798664281bSPaulo Zanoni done: 4808664281bSPaulo Zanoni spin_unlock_irqrestore(&dev_priv->irq_lock, flags); 4818664281bSPaulo Zanoni return ret; 4828664281bSPaulo Zanoni } 4838664281bSPaulo Zanoni 4848664281bSPaulo Zanoni 485b5ea642aSDaniel Vetter static void 486755e9019SImre Deak __i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 487755e9019SImre Deak u32 enable_mask, u32 status_mask) 4887c463586SKeith Packard { 4899db4a9c7SJesse Barnes u32 reg = PIPESTAT(pipe); 490755e9019SImre Deak u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK; 4917c463586SKeith Packard 492b79480baSDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 493b79480baSDaniel Vetter 494755e9019SImre Deak if (WARN_ON_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK || 495755e9019SImre Deak status_mask & ~PIPESTAT_INT_STATUS_MASK)) 496755e9019SImre Deak return; 497755e9019SImre Deak 498755e9019SImre Deak if ((pipestat & enable_mask) == enable_mask) 49946c06a30SVille Syrjälä return; 50046c06a30SVille Syrjälä 50191d181ddSImre Deak dev_priv->pipestat_irq_mask[pipe] |= status_mask; 50291d181ddSImre Deak 5037c463586SKeith Packard /* Enable the interrupt, clear any pending status */ 504755e9019SImre Deak pipestat |= enable_mask | status_mask; 50546c06a30SVille Syrjälä I915_WRITE(reg, pipestat); 5063143a2bfSChris Wilson POSTING_READ(reg); 5077c463586SKeith Packard } 5087c463586SKeith Packard 509b5ea642aSDaniel Vetter static void 510755e9019SImre Deak __i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 511755e9019SImre Deak u32 enable_mask, u32 status_mask) 5127c463586SKeith Packard { 5139db4a9c7SJesse Barnes u32 reg = PIPESTAT(pipe); 514755e9019SImre Deak u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK; 5157c463586SKeith Packard 516b79480baSDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 517b79480baSDaniel Vetter 518755e9019SImre Deak if (WARN_ON_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK || 519755e9019SImre Deak status_mask & ~PIPESTAT_INT_STATUS_MASK)) 52046c06a30SVille Syrjälä return; 52146c06a30SVille Syrjälä 522755e9019SImre Deak if ((pipestat & enable_mask) == 0) 523755e9019SImre Deak return; 524755e9019SImre Deak 52591d181ddSImre Deak dev_priv->pipestat_irq_mask[pipe] &= ~status_mask; 52691d181ddSImre Deak 527755e9019SImre Deak pipestat &= ~enable_mask; 52846c06a30SVille Syrjälä I915_WRITE(reg, pipestat); 5293143a2bfSChris Wilson POSTING_READ(reg); 5307c463586SKeith Packard } 5317c463586SKeith Packard 53210c59c51SImre Deak static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask) 53310c59c51SImre Deak { 53410c59c51SImre Deak u32 enable_mask = status_mask << 16; 53510c59c51SImre Deak 53610c59c51SImre Deak /* 53710c59c51SImre Deak * On pipe A we don't support the PSR interrupt yet, on pipe B the 53810c59c51SImre Deak * same bit MBZ. 53910c59c51SImre Deak */ 54010c59c51SImre Deak if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV)) 54110c59c51SImre Deak return 0; 54210c59c51SImre Deak 54310c59c51SImre Deak enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS | 54410c59c51SImre Deak SPRITE0_FLIP_DONE_INT_EN_VLV | 54510c59c51SImre Deak SPRITE1_FLIP_DONE_INT_EN_VLV); 54610c59c51SImre Deak if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV) 54710c59c51SImre Deak enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV; 54810c59c51SImre Deak if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV) 54910c59c51SImre Deak enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV; 55010c59c51SImre Deak 55110c59c51SImre Deak return enable_mask; 55210c59c51SImre Deak } 55310c59c51SImre Deak 554755e9019SImre Deak void 555755e9019SImre Deak i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 556755e9019SImre Deak u32 status_mask) 557755e9019SImre Deak { 558755e9019SImre Deak u32 enable_mask; 559755e9019SImre Deak 56010c59c51SImre Deak if (IS_VALLEYVIEW(dev_priv->dev)) 56110c59c51SImre Deak enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev, 56210c59c51SImre Deak status_mask); 56310c59c51SImre Deak else 564755e9019SImre Deak enable_mask = status_mask << 16; 565755e9019SImre Deak __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask); 566755e9019SImre Deak } 567755e9019SImre Deak 568755e9019SImre Deak void 569755e9019SImre Deak i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 570755e9019SImre Deak u32 status_mask) 571755e9019SImre Deak { 572755e9019SImre Deak u32 enable_mask; 573755e9019SImre Deak 57410c59c51SImre Deak if (IS_VALLEYVIEW(dev_priv->dev)) 57510c59c51SImre Deak enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev, 57610c59c51SImre Deak status_mask); 57710c59c51SImre Deak else 578755e9019SImre Deak enable_mask = status_mask << 16; 579755e9019SImre Deak __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask); 580755e9019SImre Deak } 581755e9019SImre Deak 582c0e09200SDave Airlie /** 583f49e38ddSJani Nikula * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion 58401c66889SZhao Yakui */ 585f49e38ddSJani Nikula static void i915_enable_asle_pipestat(struct drm_device *dev) 58601c66889SZhao Yakui { 5871ec14ad3SChris Wilson drm_i915_private_t *dev_priv = dev->dev_private; 5881ec14ad3SChris Wilson unsigned long irqflags; 5891ec14ad3SChris Wilson 590f49e38ddSJani Nikula if (!dev_priv->opregion.asle || !IS_MOBILE(dev)) 591f49e38ddSJani Nikula return; 592f49e38ddSJani Nikula 5931ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 59401c66889SZhao Yakui 595755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS); 596a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen >= 4) 5973b6c42e8SDaniel Vetter i915_enable_pipestat(dev_priv, PIPE_A, 598755e9019SImre Deak PIPE_LEGACY_BLC_EVENT_STATUS); 5991ec14ad3SChris Wilson 6001ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 60101c66889SZhao Yakui } 60201c66889SZhao Yakui 60301c66889SZhao Yakui /** 6040a3e67a4SJesse Barnes * i915_pipe_enabled - check if a pipe is enabled 6050a3e67a4SJesse Barnes * @dev: DRM device 6060a3e67a4SJesse Barnes * @pipe: pipe to check 6070a3e67a4SJesse Barnes * 6080a3e67a4SJesse Barnes * Reading certain registers when the pipe is disabled can hang the chip. 6090a3e67a4SJesse Barnes * Use this routine to make sure the PLL is running and the pipe is active 6100a3e67a4SJesse Barnes * before reading such registers if unsure. 6110a3e67a4SJesse Barnes */ 6120a3e67a4SJesse Barnes static int 6130a3e67a4SJesse Barnes i915_pipe_enabled(struct drm_device *dev, int pipe) 6140a3e67a4SJesse Barnes { 6150a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 616702e7a56SPaulo Zanoni 617a01025afSDaniel Vetter if (drm_core_check_feature(dev, DRIVER_MODESET)) { 618a01025afSDaniel Vetter /* Locking is horribly broken here, but whatever. */ 619a01025afSDaniel Vetter struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 620a01025afSDaniel Vetter struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 62171f8ba6bSPaulo Zanoni 622a01025afSDaniel Vetter return intel_crtc->active; 623a01025afSDaniel Vetter } else { 624a01025afSDaniel Vetter return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE; 625a01025afSDaniel Vetter } 6260a3e67a4SJesse Barnes } 6270a3e67a4SJesse Barnes 6284cdb83ecSVille Syrjälä static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe) 6294cdb83ecSVille Syrjälä { 6304cdb83ecSVille Syrjälä /* Gen2 doesn't have a hardware frame counter */ 6314cdb83ecSVille Syrjälä return 0; 6324cdb83ecSVille Syrjälä } 6334cdb83ecSVille Syrjälä 63442f52ef8SKeith Packard /* Called from drm generic code, passed a 'crtc', which 63542f52ef8SKeith Packard * we use as a pipe index 63642f52ef8SKeith Packard */ 637f71d4af4SJesse Barnes static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe) 6380a3e67a4SJesse Barnes { 6390a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 6400a3e67a4SJesse Barnes unsigned long high_frame; 6410a3e67a4SJesse Barnes unsigned long low_frame; 642391f75e2SVille Syrjälä u32 high1, high2, low, pixel, vbl_start; 6430a3e67a4SJesse Barnes 6440a3e67a4SJesse Barnes if (!i915_pipe_enabled(dev, pipe)) { 64544d98a61SZhao Yakui DRM_DEBUG_DRIVER("trying to get vblank count for disabled " 6469db4a9c7SJesse Barnes "pipe %c\n", pipe_name(pipe)); 6470a3e67a4SJesse Barnes return 0; 6480a3e67a4SJesse Barnes } 6490a3e67a4SJesse Barnes 650391f75e2SVille Syrjälä if (drm_core_check_feature(dev, DRIVER_MODESET)) { 651391f75e2SVille Syrjälä struct intel_crtc *intel_crtc = 652391f75e2SVille Syrjälä to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); 653391f75e2SVille Syrjälä const struct drm_display_mode *mode = 654391f75e2SVille Syrjälä &intel_crtc->config.adjusted_mode; 655391f75e2SVille Syrjälä 656391f75e2SVille Syrjälä vbl_start = mode->crtc_vblank_start * mode->crtc_htotal; 657391f75e2SVille Syrjälä } else { 658391f75e2SVille Syrjälä enum transcoder cpu_transcoder = 659391f75e2SVille Syrjälä intel_pipe_to_cpu_transcoder(dev_priv, pipe); 660391f75e2SVille Syrjälä u32 htotal; 661391f75e2SVille Syrjälä 662391f75e2SVille Syrjälä htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1; 663391f75e2SVille Syrjälä vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1; 664391f75e2SVille Syrjälä 665391f75e2SVille Syrjälä vbl_start *= htotal; 666391f75e2SVille Syrjälä } 667391f75e2SVille Syrjälä 6689db4a9c7SJesse Barnes high_frame = PIPEFRAME(pipe); 6699db4a9c7SJesse Barnes low_frame = PIPEFRAMEPIXEL(pipe); 6705eddb70bSChris Wilson 6710a3e67a4SJesse Barnes /* 6720a3e67a4SJesse Barnes * High & low register fields aren't synchronized, so make sure 6730a3e67a4SJesse Barnes * we get a low value that's stable across two reads of the high 6740a3e67a4SJesse Barnes * register. 6750a3e67a4SJesse Barnes */ 6760a3e67a4SJesse Barnes do { 6775eddb70bSChris Wilson high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; 678391f75e2SVille Syrjälä low = I915_READ(low_frame); 6795eddb70bSChris Wilson high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; 6800a3e67a4SJesse Barnes } while (high1 != high2); 6810a3e67a4SJesse Barnes 6825eddb70bSChris Wilson high1 >>= PIPE_FRAME_HIGH_SHIFT; 683391f75e2SVille Syrjälä pixel = low & PIPE_PIXEL_MASK; 6845eddb70bSChris Wilson low >>= PIPE_FRAME_LOW_SHIFT; 685391f75e2SVille Syrjälä 686391f75e2SVille Syrjälä /* 687391f75e2SVille Syrjälä * The frame counter increments at beginning of active. 688391f75e2SVille Syrjälä * Cook up a vblank counter by also checking the pixel 689391f75e2SVille Syrjälä * counter against vblank start. 690391f75e2SVille Syrjälä */ 691edc08d0aSVille Syrjälä return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff; 6920a3e67a4SJesse Barnes } 6930a3e67a4SJesse Barnes 694f71d4af4SJesse Barnes static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe) 6959880b7a5SJesse Barnes { 6969880b7a5SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 6979db4a9c7SJesse Barnes int reg = PIPE_FRMCOUNT_GM45(pipe); 6989880b7a5SJesse Barnes 6999880b7a5SJesse Barnes if (!i915_pipe_enabled(dev, pipe)) { 70044d98a61SZhao Yakui DRM_DEBUG_DRIVER("trying to get vblank count for disabled " 7019db4a9c7SJesse Barnes "pipe %c\n", pipe_name(pipe)); 7029880b7a5SJesse Barnes return 0; 7039880b7a5SJesse Barnes } 7049880b7a5SJesse Barnes 7059880b7a5SJesse Barnes return I915_READ(reg); 7069880b7a5SJesse Barnes } 7079880b7a5SJesse Barnes 708ad3543edSMario Kleiner /* raw reads, only for fast reads of display block, no need for forcewake etc. */ 709ad3543edSMario Kleiner #define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__)) 710ad3543edSMario Kleiner #define __raw_i915_read16(dev_priv__, reg__) readw((dev_priv__)->regs + (reg__)) 711ad3543edSMario Kleiner 712095163baSVille Syrjälä static bool ilk_pipe_in_vblank_locked(struct drm_device *dev, enum pipe pipe) 71354ddcbd2SVille Syrjälä { 71454ddcbd2SVille Syrjälä struct drm_i915_private *dev_priv = dev->dev_private; 71554ddcbd2SVille Syrjälä uint32_t status; 71654ddcbd2SVille Syrjälä 717095163baSVille Syrjälä if (INTEL_INFO(dev)->gen < 7) { 71854ddcbd2SVille Syrjälä status = pipe == PIPE_A ? 71954ddcbd2SVille Syrjälä DE_PIPEA_VBLANK : 72054ddcbd2SVille Syrjälä DE_PIPEB_VBLANK; 72154ddcbd2SVille Syrjälä } else { 72254ddcbd2SVille Syrjälä switch (pipe) { 72354ddcbd2SVille Syrjälä default: 72454ddcbd2SVille Syrjälä case PIPE_A: 72554ddcbd2SVille Syrjälä status = DE_PIPEA_VBLANK_IVB; 72654ddcbd2SVille Syrjälä break; 72754ddcbd2SVille Syrjälä case PIPE_B: 72854ddcbd2SVille Syrjälä status = DE_PIPEB_VBLANK_IVB; 72954ddcbd2SVille Syrjälä break; 73054ddcbd2SVille Syrjälä case PIPE_C: 73154ddcbd2SVille Syrjälä status = DE_PIPEC_VBLANK_IVB; 73254ddcbd2SVille Syrjälä break; 73354ddcbd2SVille Syrjälä } 73454ddcbd2SVille Syrjälä } 735ad3543edSMario Kleiner 736095163baSVille Syrjälä return __raw_i915_read32(dev_priv, DEISR) & status; 73754ddcbd2SVille Syrjälä } 73854ddcbd2SVille Syrjälä 739f71d4af4SJesse Barnes static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe, 740abca9e45SVille Syrjälä unsigned int flags, int *vpos, int *hpos, 741abca9e45SVille Syrjälä ktime_t *stime, ktime_t *etime) 7420af7e4dfSMario Kleiner { 743c2baf4b7SVille Syrjälä struct drm_i915_private *dev_priv = dev->dev_private; 744c2baf4b7SVille Syrjälä struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 745c2baf4b7SVille Syrjälä struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 746c2baf4b7SVille Syrjälä const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode; 7473aa18df8SVille Syrjälä int position; 7480af7e4dfSMario Kleiner int vbl_start, vbl_end, htotal, vtotal; 7490af7e4dfSMario Kleiner bool in_vbl = true; 7500af7e4dfSMario Kleiner int ret = 0; 751ad3543edSMario Kleiner unsigned long irqflags; 7520af7e4dfSMario Kleiner 753c2baf4b7SVille Syrjälä if (!intel_crtc->active) { 7540af7e4dfSMario Kleiner DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled " 7559db4a9c7SJesse Barnes "pipe %c\n", pipe_name(pipe)); 7560af7e4dfSMario Kleiner return 0; 7570af7e4dfSMario Kleiner } 7580af7e4dfSMario Kleiner 759c2baf4b7SVille Syrjälä htotal = mode->crtc_htotal; 760c2baf4b7SVille Syrjälä vtotal = mode->crtc_vtotal; 761c2baf4b7SVille Syrjälä vbl_start = mode->crtc_vblank_start; 762c2baf4b7SVille Syrjälä vbl_end = mode->crtc_vblank_end; 7630af7e4dfSMario Kleiner 764d31faf65SVille Syrjälä if (mode->flags & DRM_MODE_FLAG_INTERLACE) { 765d31faf65SVille Syrjälä vbl_start = DIV_ROUND_UP(vbl_start, 2); 766d31faf65SVille Syrjälä vbl_end /= 2; 767d31faf65SVille Syrjälä vtotal /= 2; 768d31faf65SVille Syrjälä } 769d31faf65SVille Syrjälä 770c2baf4b7SVille Syrjälä ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE; 771c2baf4b7SVille Syrjälä 772ad3543edSMario Kleiner /* 773ad3543edSMario Kleiner * Lock uncore.lock, as we will do multiple timing critical raw 774ad3543edSMario Kleiner * register reads, potentially with preemption disabled, so the 775ad3543edSMario Kleiner * following code must not block on uncore.lock. 776ad3543edSMario Kleiner */ 777ad3543edSMario Kleiner spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); 778ad3543edSMario Kleiner 779ad3543edSMario Kleiner /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */ 780ad3543edSMario Kleiner 781ad3543edSMario Kleiner /* Get optional system timestamp before query. */ 782ad3543edSMario Kleiner if (stime) 783ad3543edSMario Kleiner *stime = ktime_get(); 784ad3543edSMario Kleiner 7857c06b08aSVille Syrjälä if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { 7860af7e4dfSMario Kleiner /* No obvious pixelcount register. Only query vertical 7870af7e4dfSMario Kleiner * scanout position from Display scan line register. 7880af7e4dfSMario Kleiner */ 7897c06b08aSVille Syrjälä if (IS_GEN2(dev)) 790ad3543edSMario Kleiner position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2; 7917c06b08aSVille Syrjälä else 792ad3543edSMario Kleiner position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3; 79354ddcbd2SVille Syrjälä 794095163baSVille Syrjälä if (HAS_PCH_SPLIT(dev)) { 79554ddcbd2SVille Syrjälä /* 79654ddcbd2SVille Syrjälä * The scanline counter increments at the leading edge 79754ddcbd2SVille Syrjälä * of hsync, ie. it completely misses the active portion 79854ddcbd2SVille Syrjälä * of the line. Fix up the counter at both edges of vblank 79954ddcbd2SVille Syrjälä * to get a more accurate picture whether we're in vblank 80054ddcbd2SVille Syrjälä * or not. 80154ddcbd2SVille Syrjälä */ 802095163baSVille Syrjälä in_vbl = ilk_pipe_in_vblank_locked(dev, pipe); 80354ddcbd2SVille Syrjälä if ((in_vbl && position == vbl_start - 1) || 80454ddcbd2SVille Syrjälä (!in_vbl && position == vbl_end - 1)) 80554ddcbd2SVille Syrjälä position = (position + 1) % vtotal; 8060af7e4dfSMario Kleiner } else { 807095163baSVille Syrjälä /* 808095163baSVille Syrjälä * ISR vblank status bits don't work the way we'd want 809095163baSVille Syrjälä * them to work on non-PCH platforms (for 810095163baSVille Syrjälä * ilk_pipe_in_vblank_locked()), and there doesn't 811095163baSVille Syrjälä * appear any other way to determine if we're currently 812095163baSVille Syrjälä * in vblank. 813095163baSVille Syrjälä * 814095163baSVille Syrjälä * Instead let's assume that we're already in vblank if 815095163baSVille Syrjälä * we got called from the vblank interrupt and the 816095163baSVille Syrjälä * scanline counter value indicates that we're on the 817095163baSVille Syrjälä * line just prior to vblank start. This should result 818095163baSVille Syrjälä * in the correct answer, unless the vblank interrupt 819095163baSVille Syrjälä * delivery really got delayed for almost exactly one 820095163baSVille Syrjälä * full frame/field. 821095163baSVille Syrjälä */ 822095163baSVille Syrjälä if (flags & DRM_CALLED_FROM_VBLIRQ && 823095163baSVille Syrjälä position == vbl_start - 1) { 824095163baSVille Syrjälä position = (position + 1) % vtotal; 825095163baSVille Syrjälä 826095163baSVille Syrjälä /* Signal this correction as "applied". */ 827095163baSVille Syrjälä ret |= 0x8; 828095163baSVille Syrjälä } 829095163baSVille Syrjälä } 830095163baSVille Syrjälä } else { 8310af7e4dfSMario Kleiner /* Have access to pixelcount since start of frame. 8320af7e4dfSMario Kleiner * We can split this into vertical and horizontal 8330af7e4dfSMario Kleiner * scanout position. 8340af7e4dfSMario Kleiner */ 835ad3543edSMario Kleiner position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT; 8360af7e4dfSMario Kleiner 8373aa18df8SVille Syrjälä /* convert to pixel counts */ 8383aa18df8SVille Syrjälä vbl_start *= htotal; 8393aa18df8SVille Syrjälä vbl_end *= htotal; 8403aa18df8SVille Syrjälä vtotal *= htotal; 8413aa18df8SVille Syrjälä } 8423aa18df8SVille Syrjälä 843ad3543edSMario Kleiner /* Get optional system timestamp after query. */ 844ad3543edSMario Kleiner if (etime) 845ad3543edSMario Kleiner *etime = ktime_get(); 846ad3543edSMario Kleiner 847ad3543edSMario Kleiner /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */ 848ad3543edSMario Kleiner 849ad3543edSMario Kleiner spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); 850ad3543edSMario Kleiner 8513aa18df8SVille Syrjälä in_vbl = position >= vbl_start && position < vbl_end; 8523aa18df8SVille Syrjälä 8533aa18df8SVille Syrjälä /* 8543aa18df8SVille Syrjälä * While in vblank, position will be negative 8553aa18df8SVille Syrjälä * counting up towards 0 at vbl_end. And outside 8563aa18df8SVille Syrjälä * vblank, position will be positive counting 8573aa18df8SVille Syrjälä * up since vbl_end. 8583aa18df8SVille Syrjälä */ 8593aa18df8SVille Syrjälä if (position >= vbl_start) 8603aa18df8SVille Syrjälä position -= vbl_end; 8613aa18df8SVille Syrjälä else 8623aa18df8SVille Syrjälä position += vtotal - vbl_end; 8633aa18df8SVille Syrjälä 8647c06b08aSVille Syrjälä if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { 8653aa18df8SVille Syrjälä *vpos = position; 8663aa18df8SVille Syrjälä *hpos = 0; 8673aa18df8SVille Syrjälä } else { 8680af7e4dfSMario Kleiner *vpos = position / htotal; 8690af7e4dfSMario Kleiner *hpos = position - (*vpos * htotal); 8700af7e4dfSMario Kleiner } 8710af7e4dfSMario Kleiner 8720af7e4dfSMario Kleiner /* In vblank? */ 8730af7e4dfSMario Kleiner if (in_vbl) 8740af7e4dfSMario Kleiner ret |= DRM_SCANOUTPOS_INVBL; 8750af7e4dfSMario Kleiner 8760af7e4dfSMario Kleiner return ret; 8770af7e4dfSMario Kleiner } 8780af7e4dfSMario Kleiner 879f71d4af4SJesse Barnes static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe, 8800af7e4dfSMario Kleiner int *max_error, 8810af7e4dfSMario Kleiner struct timeval *vblank_time, 8820af7e4dfSMario Kleiner unsigned flags) 8830af7e4dfSMario Kleiner { 8844041b853SChris Wilson struct drm_crtc *crtc; 8850af7e4dfSMario Kleiner 8867eb552aeSBen Widawsky if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) { 8874041b853SChris Wilson DRM_ERROR("Invalid crtc %d\n", pipe); 8880af7e4dfSMario Kleiner return -EINVAL; 8890af7e4dfSMario Kleiner } 8900af7e4dfSMario Kleiner 8910af7e4dfSMario Kleiner /* Get drm_crtc to timestamp: */ 8924041b853SChris Wilson crtc = intel_get_crtc_for_pipe(dev, pipe); 8934041b853SChris Wilson if (crtc == NULL) { 8944041b853SChris Wilson DRM_ERROR("Invalid crtc %d\n", pipe); 8954041b853SChris Wilson return -EINVAL; 8964041b853SChris Wilson } 8974041b853SChris Wilson 8984041b853SChris Wilson if (!crtc->enabled) { 8994041b853SChris Wilson DRM_DEBUG_KMS("crtc %d is disabled\n", pipe); 9004041b853SChris Wilson return -EBUSY; 9014041b853SChris Wilson } 9020af7e4dfSMario Kleiner 9030af7e4dfSMario Kleiner /* Helper routine in DRM core does all the work: */ 9044041b853SChris Wilson return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error, 9054041b853SChris Wilson vblank_time, flags, 9067da903efSVille Syrjälä crtc, 9077da903efSVille Syrjälä &to_intel_crtc(crtc)->config.adjusted_mode); 9080af7e4dfSMario Kleiner } 9090af7e4dfSMario Kleiner 91067c347ffSJani Nikula static bool intel_hpd_irq_event(struct drm_device *dev, 91167c347ffSJani Nikula struct drm_connector *connector) 912321a1b30SEgbert Eich { 913321a1b30SEgbert Eich enum drm_connector_status old_status; 914321a1b30SEgbert Eich 915321a1b30SEgbert Eich WARN_ON(!mutex_is_locked(&dev->mode_config.mutex)); 916321a1b30SEgbert Eich old_status = connector->status; 917321a1b30SEgbert Eich 918321a1b30SEgbert Eich connector->status = connector->funcs->detect(connector, false); 91967c347ffSJani Nikula if (old_status == connector->status) 92067c347ffSJani Nikula return false; 92167c347ffSJani Nikula 92267c347ffSJani Nikula DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n", 923321a1b30SEgbert Eich connector->base.id, 924321a1b30SEgbert Eich drm_get_connector_name(connector), 92567c347ffSJani Nikula drm_get_connector_status_name(old_status), 92667c347ffSJani Nikula drm_get_connector_status_name(connector->status)); 92767c347ffSJani Nikula 92867c347ffSJani Nikula return true; 929321a1b30SEgbert Eich } 930321a1b30SEgbert Eich 9315ca58282SJesse Barnes /* 9325ca58282SJesse Barnes * Handle hotplug events outside the interrupt handler proper. 9335ca58282SJesse Barnes */ 934ac4c16c5SEgbert Eich #define I915_REENABLE_HOTPLUG_DELAY (2*60*1000) 935ac4c16c5SEgbert Eich 9365ca58282SJesse Barnes static void i915_hotplug_work_func(struct work_struct *work) 9375ca58282SJesse Barnes { 9385ca58282SJesse Barnes drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, 9395ca58282SJesse Barnes hotplug_work); 9405ca58282SJesse Barnes struct drm_device *dev = dev_priv->dev; 941c31c4ba3SKeith Packard struct drm_mode_config *mode_config = &dev->mode_config; 942cd569aedSEgbert Eich struct intel_connector *intel_connector; 943cd569aedSEgbert Eich struct intel_encoder *intel_encoder; 944cd569aedSEgbert Eich struct drm_connector *connector; 945cd569aedSEgbert Eich unsigned long irqflags; 946cd569aedSEgbert Eich bool hpd_disabled = false; 947321a1b30SEgbert Eich bool changed = false; 948142e2398SEgbert Eich u32 hpd_event_bits; 9495ca58282SJesse Barnes 95052d7ecedSDaniel Vetter /* HPD irq before everything is fully set up. */ 95152d7ecedSDaniel Vetter if (!dev_priv->enable_hotplug_processing) 95252d7ecedSDaniel Vetter return; 95352d7ecedSDaniel Vetter 954a65e34c7SKeith Packard mutex_lock(&mode_config->mutex); 955e67189abSJesse Barnes DRM_DEBUG_KMS("running encoder hotplug functions\n"); 956e67189abSJesse Barnes 957cd569aedSEgbert Eich spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 958142e2398SEgbert Eich 959142e2398SEgbert Eich hpd_event_bits = dev_priv->hpd_event_bits; 960142e2398SEgbert Eich dev_priv->hpd_event_bits = 0; 961cd569aedSEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 962cd569aedSEgbert Eich intel_connector = to_intel_connector(connector); 963cd569aedSEgbert Eich intel_encoder = intel_connector->encoder; 964cd569aedSEgbert Eich if (intel_encoder->hpd_pin > HPD_NONE && 965cd569aedSEgbert Eich dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED && 966cd569aedSEgbert Eich connector->polled == DRM_CONNECTOR_POLL_HPD) { 967cd569aedSEgbert Eich DRM_INFO("HPD interrupt storm detected on connector %s: " 968cd569aedSEgbert Eich "switching from hotplug detection to polling\n", 969cd569aedSEgbert Eich drm_get_connector_name(connector)); 970cd569aedSEgbert Eich dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED; 971cd569aedSEgbert Eich connector->polled = DRM_CONNECTOR_POLL_CONNECT 972cd569aedSEgbert Eich | DRM_CONNECTOR_POLL_DISCONNECT; 973cd569aedSEgbert Eich hpd_disabled = true; 974cd569aedSEgbert Eich } 975142e2398SEgbert Eich if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) { 976142e2398SEgbert Eich DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n", 977142e2398SEgbert Eich drm_get_connector_name(connector), intel_encoder->hpd_pin); 978142e2398SEgbert Eich } 979cd569aedSEgbert Eich } 980cd569aedSEgbert Eich /* if there were no outputs to poll, poll was disabled, 981cd569aedSEgbert Eich * therefore make sure it's enabled when disabling HPD on 982cd569aedSEgbert Eich * some connectors */ 983ac4c16c5SEgbert Eich if (hpd_disabled) { 984cd569aedSEgbert Eich drm_kms_helper_poll_enable(dev); 985ac4c16c5SEgbert Eich mod_timer(&dev_priv->hotplug_reenable_timer, 986ac4c16c5SEgbert Eich jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY)); 987ac4c16c5SEgbert Eich } 988cd569aedSEgbert Eich 989cd569aedSEgbert Eich spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 990cd569aedSEgbert Eich 991321a1b30SEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 992321a1b30SEgbert Eich intel_connector = to_intel_connector(connector); 993321a1b30SEgbert Eich intel_encoder = intel_connector->encoder; 994321a1b30SEgbert Eich if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) { 995cd569aedSEgbert Eich if (intel_encoder->hot_plug) 996cd569aedSEgbert Eich intel_encoder->hot_plug(intel_encoder); 997321a1b30SEgbert Eich if (intel_hpd_irq_event(dev, connector)) 998321a1b30SEgbert Eich changed = true; 999321a1b30SEgbert Eich } 1000321a1b30SEgbert Eich } 100140ee3381SKeith Packard mutex_unlock(&mode_config->mutex); 100240ee3381SKeith Packard 1003321a1b30SEgbert Eich if (changed) 1004321a1b30SEgbert Eich drm_kms_helper_hotplug_event(dev); 10055ca58282SJesse Barnes } 10065ca58282SJesse Barnes 10073ca1ccedSVille Syrjälä static void intel_hpd_irq_uninstall(struct drm_i915_private *dev_priv) 10083ca1ccedSVille Syrjälä { 10093ca1ccedSVille Syrjälä del_timer_sync(&dev_priv->hotplug_reenable_timer); 10103ca1ccedSVille Syrjälä } 10113ca1ccedSVille Syrjälä 1012d0ecd7e2SDaniel Vetter static void ironlake_rps_change_irq_handler(struct drm_device *dev) 1013f97108d1SJesse Barnes { 1014f97108d1SJesse Barnes drm_i915_private_t *dev_priv = dev->dev_private; 1015b5b72e89SMatthew Garrett u32 busy_up, busy_down, max_avg, min_avg; 10169270388eSDaniel Vetter u8 new_delay; 10179270388eSDaniel Vetter 1018d0ecd7e2SDaniel Vetter spin_lock(&mchdev_lock); 1019f97108d1SJesse Barnes 102073edd18fSDaniel Vetter I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS)); 102173edd18fSDaniel Vetter 102220e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay; 10239270388eSDaniel Vetter 10247648fa99SJesse Barnes I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG); 1025b5b72e89SMatthew Garrett busy_up = I915_READ(RCPREVBSYTUPAVG); 1026b5b72e89SMatthew Garrett busy_down = I915_READ(RCPREVBSYTDNAVG); 1027f97108d1SJesse Barnes max_avg = I915_READ(RCBMAXAVG); 1028f97108d1SJesse Barnes min_avg = I915_READ(RCBMINAVG); 1029f97108d1SJesse Barnes 1030f97108d1SJesse Barnes /* Handle RCS change request from hw */ 1031b5b72e89SMatthew Garrett if (busy_up > max_avg) { 103220e4d407SDaniel Vetter if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay) 103320e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay - 1; 103420e4d407SDaniel Vetter if (new_delay < dev_priv->ips.max_delay) 103520e4d407SDaniel Vetter new_delay = dev_priv->ips.max_delay; 1036b5b72e89SMatthew Garrett } else if (busy_down < min_avg) { 103720e4d407SDaniel Vetter if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay) 103820e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay + 1; 103920e4d407SDaniel Vetter if (new_delay > dev_priv->ips.min_delay) 104020e4d407SDaniel Vetter new_delay = dev_priv->ips.min_delay; 1041f97108d1SJesse Barnes } 1042f97108d1SJesse Barnes 10437648fa99SJesse Barnes if (ironlake_set_drps(dev, new_delay)) 104420e4d407SDaniel Vetter dev_priv->ips.cur_delay = new_delay; 1045f97108d1SJesse Barnes 1046d0ecd7e2SDaniel Vetter spin_unlock(&mchdev_lock); 10479270388eSDaniel Vetter 1048f97108d1SJesse Barnes return; 1049f97108d1SJesse Barnes } 1050f97108d1SJesse Barnes 1051549f7365SChris Wilson static void notify_ring(struct drm_device *dev, 1052549f7365SChris Wilson struct intel_ring_buffer *ring) 1053549f7365SChris Wilson { 1054475553deSChris Wilson if (ring->obj == NULL) 1055475553deSChris Wilson return; 1056475553deSChris Wilson 1057814e9b57SChris Wilson trace_i915_gem_request_complete(ring); 10589862e600SChris Wilson 1059549f7365SChris Wilson wake_up_all(&ring->irq_queue); 106010cd45b6SMika Kuoppala i915_queue_hangcheck(dev); 1061549f7365SChris Wilson } 1062549f7365SChris Wilson 106376c3552fSDeepak S void gen6_set_pm_mask(struct drm_i915_private *dev_priv, 106427544369SDeepak S u32 pm_iir, int new_delay) 106527544369SDeepak S { 106627544369SDeepak S if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) { 106727544369SDeepak S if (new_delay >= dev_priv->rps.max_delay) { 106827544369SDeepak S /* Mask UP THRESHOLD Interrupts */ 106927544369SDeepak S I915_WRITE(GEN6_PMINTRMSK, 107027544369SDeepak S I915_READ(GEN6_PMINTRMSK) | 107127544369SDeepak S GEN6_PM_RP_UP_THRESHOLD); 107227544369SDeepak S dev_priv->rps.rp_up_masked = true; 107327544369SDeepak S } 107427544369SDeepak S if (dev_priv->rps.rp_down_masked) { 107527544369SDeepak S /* UnMask DOWN THRESHOLD Interrupts */ 107627544369SDeepak S I915_WRITE(GEN6_PMINTRMSK, 107727544369SDeepak S I915_READ(GEN6_PMINTRMSK) & 107827544369SDeepak S ~GEN6_PM_RP_DOWN_THRESHOLD); 107927544369SDeepak S dev_priv->rps.rp_down_masked = false; 108027544369SDeepak S } 108127544369SDeepak S } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) { 108227544369SDeepak S if (new_delay <= dev_priv->rps.min_delay) { 108327544369SDeepak S /* Mask DOWN THRESHOLD Interrupts */ 108427544369SDeepak S I915_WRITE(GEN6_PMINTRMSK, 108527544369SDeepak S I915_READ(GEN6_PMINTRMSK) | 108627544369SDeepak S GEN6_PM_RP_DOWN_THRESHOLD); 108727544369SDeepak S dev_priv->rps.rp_down_masked = true; 108827544369SDeepak S } 108927544369SDeepak S 109027544369SDeepak S if (dev_priv->rps.rp_up_masked) { 109127544369SDeepak S /* UnMask UP THRESHOLD Interrupts */ 109227544369SDeepak S I915_WRITE(GEN6_PMINTRMSK, 109327544369SDeepak S I915_READ(GEN6_PMINTRMSK) & 109427544369SDeepak S ~GEN6_PM_RP_UP_THRESHOLD); 109527544369SDeepak S dev_priv->rps.rp_up_masked = false; 109627544369SDeepak S } 109727544369SDeepak S } 109827544369SDeepak S } 109927544369SDeepak S 11004912d041SBen Widawsky static void gen6_pm_rps_work(struct work_struct *work) 11013b8d8d91SJesse Barnes { 11024912d041SBen Widawsky drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, 1103c6a828d3SDaniel Vetter rps.work); 1104edbfdb45SPaulo Zanoni u32 pm_iir; 1105dd75fdc8SChris Wilson int new_delay, adj; 11063b8d8d91SJesse Barnes 110759cdb63dSDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 1108c6a828d3SDaniel Vetter pm_iir = dev_priv->rps.pm_iir; 1109c6a828d3SDaniel Vetter dev_priv->rps.pm_iir = 0; 11104848405cSBen Widawsky /* Make sure not to corrupt PMIMR state used by ringbuffer code */ 1111edbfdb45SPaulo Zanoni snb_enable_pm_irq(dev_priv, GEN6_PM_RPS_EVENTS); 111259cdb63dSDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 11134912d041SBen Widawsky 111460611c13SPaulo Zanoni /* Make sure we didn't queue anything we're not going to process. */ 111560611c13SPaulo Zanoni WARN_ON(pm_iir & ~GEN6_PM_RPS_EVENTS); 111660611c13SPaulo Zanoni 11174848405cSBen Widawsky if ((pm_iir & GEN6_PM_RPS_EVENTS) == 0) 11183b8d8d91SJesse Barnes return; 11193b8d8d91SJesse Barnes 11204fc688ceSJesse Barnes mutex_lock(&dev_priv->rps.hw_lock); 11217b9e0ae6SChris Wilson 1122dd75fdc8SChris Wilson adj = dev_priv->rps.last_adj; 11237425034aSVille Syrjälä if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) { 1124dd75fdc8SChris Wilson if (adj > 0) 1125dd75fdc8SChris Wilson adj *= 2; 1126dd75fdc8SChris Wilson else 1127dd75fdc8SChris Wilson adj = 1; 1128dd75fdc8SChris Wilson new_delay = dev_priv->rps.cur_delay + adj; 11297425034aSVille Syrjälä 11307425034aSVille Syrjälä /* 11317425034aSVille Syrjälä * For better performance, jump directly 11327425034aSVille Syrjälä * to RPe if we're below it. 11337425034aSVille Syrjälä */ 1134dd75fdc8SChris Wilson if (new_delay < dev_priv->rps.rpe_delay) 11357425034aSVille Syrjälä new_delay = dev_priv->rps.rpe_delay; 1136dd75fdc8SChris Wilson } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) { 1137dd75fdc8SChris Wilson if (dev_priv->rps.cur_delay > dev_priv->rps.rpe_delay) 1138dd75fdc8SChris Wilson new_delay = dev_priv->rps.rpe_delay; 1139dd75fdc8SChris Wilson else 1140dd75fdc8SChris Wilson new_delay = dev_priv->rps.min_delay; 1141dd75fdc8SChris Wilson adj = 0; 1142dd75fdc8SChris Wilson } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) { 1143dd75fdc8SChris Wilson if (adj < 0) 1144dd75fdc8SChris Wilson adj *= 2; 1145dd75fdc8SChris Wilson else 1146dd75fdc8SChris Wilson adj = -1; 1147dd75fdc8SChris Wilson new_delay = dev_priv->rps.cur_delay + adj; 1148dd75fdc8SChris Wilson } else { /* unknown event */ 1149dd75fdc8SChris Wilson new_delay = dev_priv->rps.cur_delay; 1150dd75fdc8SChris Wilson } 11513b8d8d91SJesse Barnes 115279249636SBen Widawsky /* sysfs frequency interfaces may have snuck in while servicing the 115379249636SBen Widawsky * interrupt 115479249636SBen Widawsky */ 11551272e7b8SVille Syrjälä new_delay = clamp_t(int, new_delay, 11561272e7b8SVille Syrjälä dev_priv->rps.min_delay, dev_priv->rps.max_delay); 115727544369SDeepak S 115827544369SDeepak S gen6_set_pm_mask(dev_priv, pm_iir, new_delay); 1159dd75fdc8SChris Wilson dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_delay; 1160dd75fdc8SChris Wilson 11610a073b84SJesse Barnes if (IS_VALLEYVIEW(dev_priv->dev)) 11620a073b84SJesse Barnes valleyview_set_rps(dev_priv->dev, new_delay); 11630a073b84SJesse Barnes else 11644912d041SBen Widawsky gen6_set_rps(dev_priv->dev, new_delay); 11653b8d8d91SJesse Barnes 11664fc688ceSJesse Barnes mutex_unlock(&dev_priv->rps.hw_lock); 11673b8d8d91SJesse Barnes } 11683b8d8d91SJesse Barnes 1169e3689190SBen Widawsky 1170e3689190SBen Widawsky /** 1171e3689190SBen Widawsky * ivybridge_parity_work - Workqueue called when a parity error interrupt 1172e3689190SBen Widawsky * occurred. 1173e3689190SBen Widawsky * @work: workqueue struct 1174e3689190SBen Widawsky * 1175e3689190SBen Widawsky * Doesn't actually do anything except notify userspace. As a consequence of 1176e3689190SBen Widawsky * this event, userspace should try to remap the bad rows since statistically 1177e3689190SBen Widawsky * it is likely the same row is more likely to go bad again. 1178e3689190SBen Widawsky */ 1179e3689190SBen Widawsky static void ivybridge_parity_work(struct work_struct *work) 1180e3689190SBen Widawsky { 1181e3689190SBen Widawsky drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, 1182a4da4fa4SDaniel Vetter l3_parity.error_work); 1183e3689190SBen Widawsky u32 error_status, row, bank, subbank; 118435a85ac6SBen Widawsky char *parity_event[6]; 1185e3689190SBen Widawsky uint32_t misccpctl; 1186e3689190SBen Widawsky unsigned long flags; 118735a85ac6SBen Widawsky uint8_t slice = 0; 1188e3689190SBen Widawsky 1189e3689190SBen Widawsky /* We must turn off DOP level clock gating to access the L3 registers. 1190e3689190SBen Widawsky * In order to prevent a get/put style interface, acquire struct mutex 1191e3689190SBen Widawsky * any time we access those registers. 1192e3689190SBen Widawsky */ 1193e3689190SBen Widawsky mutex_lock(&dev_priv->dev->struct_mutex); 1194e3689190SBen Widawsky 119535a85ac6SBen Widawsky /* If we've screwed up tracking, just let the interrupt fire again */ 119635a85ac6SBen Widawsky if (WARN_ON(!dev_priv->l3_parity.which_slice)) 119735a85ac6SBen Widawsky goto out; 119835a85ac6SBen Widawsky 1199e3689190SBen Widawsky misccpctl = I915_READ(GEN7_MISCCPCTL); 1200e3689190SBen Widawsky I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); 1201e3689190SBen Widawsky POSTING_READ(GEN7_MISCCPCTL); 1202e3689190SBen Widawsky 120335a85ac6SBen Widawsky while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) { 120435a85ac6SBen Widawsky u32 reg; 120535a85ac6SBen Widawsky 120635a85ac6SBen Widawsky slice--; 120735a85ac6SBen Widawsky if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev))) 120835a85ac6SBen Widawsky break; 120935a85ac6SBen Widawsky 121035a85ac6SBen Widawsky dev_priv->l3_parity.which_slice &= ~(1<<slice); 121135a85ac6SBen Widawsky 121235a85ac6SBen Widawsky reg = GEN7_L3CDERRST1 + (slice * 0x200); 121335a85ac6SBen Widawsky 121435a85ac6SBen Widawsky error_status = I915_READ(reg); 1215e3689190SBen Widawsky row = GEN7_PARITY_ERROR_ROW(error_status); 1216e3689190SBen Widawsky bank = GEN7_PARITY_ERROR_BANK(error_status); 1217e3689190SBen Widawsky subbank = GEN7_PARITY_ERROR_SUBBANK(error_status); 1218e3689190SBen Widawsky 121935a85ac6SBen Widawsky I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE); 122035a85ac6SBen Widawsky POSTING_READ(reg); 1221e3689190SBen Widawsky 1222cce723edSBen Widawsky parity_event[0] = I915_L3_PARITY_UEVENT "=1"; 1223e3689190SBen Widawsky parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row); 1224e3689190SBen Widawsky parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank); 1225e3689190SBen Widawsky parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank); 122635a85ac6SBen Widawsky parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice); 122735a85ac6SBen Widawsky parity_event[5] = NULL; 1228e3689190SBen Widawsky 12295bdebb18SDave Airlie kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj, 1230e3689190SBen Widawsky KOBJ_CHANGE, parity_event); 1231e3689190SBen Widawsky 123235a85ac6SBen Widawsky DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n", 123335a85ac6SBen Widawsky slice, row, bank, subbank); 1234e3689190SBen Widawsky 123535a85ac6SBen Widawsky kfree(parity_event[4]); 1236e3689190SBen Widawsky kfree(parity_event[3]); 1237e3689190SBen Widawsky kfree(parity_event[2]); 1238e3689190SBen Widawsky kfree(parity_event[1]); 1239e3689190SBen Widawsky } 1240e3689190SBen Widawsky 124135a85ac6SBen Widawsky I915_WRITE(GEN7_MISCCPCTL, misccpctl); 124235a85ac6SBen Widawsky 124335a85ac6SBen Widawsky out: 124435a85ac6SBen Widawsky WARN_ON(dev_priv->l3_parity.which_slice); 124535a85ac6SBen Widawsky spin_lock_irqsave(&dev_priv->irq_lock, flags); 124635a85ac6SBen Widawsky ilk_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev)); 124735a85ac6SBen Widawsky spin_unlock_irqrestore(&dev_priv->irq_lock, flags); 124835a85ac6SBen Widawsky 124935a85ac6SBen Widawsky mutex_unlock(&dev_priv->dev->struct_mutex); 125035a85ac6SBen Widawsky } 125135a85ac6SBen Widawsky 125235a85ac6SBen Widawsky static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir) 1253e3689190SBen Widawsky { 1254e3689190SBen Widawsky drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1255e3689190SBen Widawsky 1256040d2baaSBen Widawsky if (!HAS_L3_DPF(dev)) 1257e3689190SBen Widawsky return; 1258e3689190SBen Widawsky 1259d0ecd7e2SDaniel Vetter spin_lock(&dev_priv->irq_lock); 126035a85ac6SBen Widawsky ilk_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev)); 1261d0ecd7e2SDaniel Vetter spin_unlock(&dev_priv->irq_lock); 1262e3689190SBen Widawsky 126335a85ac6SBen Widawsky iir &= GT_PARITY_ERROR(dev); 126435a85ac6SBen Widawsky if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1) 126535a85ac6SBen Widawsky dev_priv->l3_parity.which_slice |= 1 << 1; 126635a85ac6SBen Widawsky 126735a85ac6SBen Widawsky if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT) 126835a85ac6SBen Widawsky dev_priv->l3_parity.which_slice |= 1 << 0; 126935a85ac6SBen Widawsky 1270a4da4fa4SDaniel Vetter queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work); 1271e3689190SBen Widawsky } 1272e3689190SBen Widawsky 1273f1af8fc1SPaulo Zanoni static void ilk_gt_irq_handler(struct drm_device *dev, 1274f1af8fc1SPaulo Zanoni struct drm_i915_private *dev_priv, 1275f1af8fc1SPaulo Zanoni u32 gt_iir) 1276f1af8fc1SPaulo Zanoni { 1277f1af8fc1SPaulo Zanoni if (gt_iir & 1278f1af8fc1SPaulo Zanoni (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT)) 1279f1af8fc1SPaulo Zanoni notify_ring(dev, &dev_priv->ring[RCS]); 1280f1af8fc1SPaulo Zanoni if (gt_iir & ILK_BSD_USER_INTERRUPT) 1281f1af8fc1SPaulo Zanoni notify_ring(dev, &dev_priv->ring[VCS]); 1282f1af8fc1SPaulo Zanoni } 1283f1af8fc1SPaulo Zanoni 1284e7b4c6b1SDaniel Vetter static void snb_gt_irq_handler(struct drm_device *dev, 1285e7b4c6b1SDaniel Vetter struct drm_i915_private *dev_priv, 1286e7b4c6b1SDaniel Vetter u32 gt_iir) 1287e7b4c6b1SDaniel Vetter { 1288e7b4c6b1SDaniel Vetter 1289cc609d5dSBen Widawsky if (gt_iir & 1290cc609d5dSBen Widawsky (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT)) 1291e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[RCS]); 1292cc609d5dSBen Widawsky if (gt_iir & GT_BSD_USER_INTERRUPT) 1293e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[VCS]); 1294cc609d5dSBen Widawsky if (gt_iir & GT_BLT_USER_INTERRUPT) 1295e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[BCS]); 1296e7b4c6b1SDaniel Vetter 1297cc609d5dSBen Widawsky if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT | 1298cc609d5dSBen Widawsky GT_BSD_CS_ERROR_INTERRUPT | 1299cc609d5dSBen Widawsky GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) { 1300*58174462SMika Kuoppala i915_handle_error(dev, false, "GT error interrupt 0x%08x", 1301*58174462SMika Kuoppala gt_iir); 1302e7b4c6b1SDaniel Vetter } 1303e3689190SBen Widawsky 130435a85ac6SBen Widawsky if (gt_iir & GT_PARITY_ERROR(dev)) 130535a85ac6SBen Widawsky ivybridge_parity_error_irq_handler(dev, gt_iir); 1306e7b4c6b1SDaniel Vetter } 1307e7b4c6b1SDaniel Vetter 1308abd58f01SBen Widawsky static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev, 1309abd58f01SBen Widawsky struct drm_i915_private *dev_priv, 1310abd58f01SBen Widawsky u32 master_ctl) 1311abd58f01SBen Widawsky { 1312abd58f01SBen Widawsky u32 rcs, bcs, vcs; 1313abd58f01SBen Widawsky uint32_t tmp = 0; 1314abd58f01SBen Widawsky irqreturn_t ret = IRQ_NONE; 1315abd58f01SBen Widawsky 1316abd58f01SBen Widawsky if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) { 1317abd58f01SBen Widawsky tmp = I915_READ(GEN8_GT_IIR(0)); 1318abd58f01SBen Widawsky if (tmp) { 1319abd58f01SBen Widawsky ret = IRQ_HANDLED; 1320abd58f01SBen Widawsky rcs = tmp >> GEN8_RCS_IRQ_SHIFT; 1321abd58f01SBen Widawsky bcs = tmp >> GEN8_BCS_IRQ_SHIFT; 1322abd58f01SBen Widawsky if (rcs & GT_RENDER_USER_INTERRUPT) 1323abd58f01SBen Widawsky notify_ring(dev, &dev_priv->ring[RCS]); 1324abd58f01SBen Widawsky if (bcs & GT_RENDER_USER_INTERRUPT) 1325abd58f01SBen Widawsky notify_ring(dev, &dev_priv->ring[BCS]); 1326abd58f01SBen Widawsky I915_WRITE(GEN8_GT_IIR(0), tmp); 1327abd58f01SBen Widawsky } else 1328abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (GT0)!\n"); 1329abd58f01SBen Widawsky } 1330abd58f01SBen Widawsky 1331abd58f01SBen Widawsky if (master_ctl & GEN8_GT_VCS1_IRQ) { 1332abd58f01SBen Widawsky tmp = I915_READ(GEN8_GT_IIR(1)); 1333abd58f01SBen Widawsky if (tmp) { 1334abd58f01SBen Widawsky ret = IRQ_HANDLED; 1335abd58f01SBen Widawsky vcs = tmp >> GEN8_VCS1_IRQ_SHIFT; 1336abd58f01SBen Widawsky if (vcs & GT_RENDER_USER_INTERRUPT) 1337abd58f01SBen Widawsky notify_ring(dev, &dev_priv->ring[VCS]); 1338abd58f01SBen Widawsky I915_WRITE(GEN8_GT_IIR(1), tmp); 1339abd58f01SBen Widawsky } else 1340abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (GT1)!\n"); 1341abd58f01SBen Widawsky } 1342abd58f01SBen Widawsky 1343abd58f01SBen Widawsky if (master_ctl & GEN8_GT_VECS_IRQ) { 1344abd58f01SBen Widawsky tmp = I915_READ(GEN8_GT_IIR(3)); 1345abd58f01SBen Widawsky if (tmp) { 1346abd58f01SBen Widawsky ret = IRQ_HANDLED; 1347abd58f01SBen Widawsky vcs = tmp >> GEN8_VECS_IRQ_SHIFT; 1348abd58f01SBen Widawsky if (vcs & GT_RENDER_USER_INTERRUPT) 1349abd58f01SBen Widawsky notify_ring(dev, &dev_priv->ring[VECS]); 1350abd58f01SBen Widawsky I915_WRITE(GEN8_GT_IIR(3), tmp); 1351abd58f01SBen Widawsky } else 1352abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (GT3)!\n"); 1353abd58f01SBen Widawsky } 1354abd58f01SBen Widawsky 1355abd58f01SBen Widawsky return ret; 1356abd58f01SBen Widawsky } 1357abd58f01SBen Widawsky 1358b543fb04SEgbert Eich #define HPD_STORM_DETECT_PERIOD 1000 1359b543fb04SEgbert Eich #define HPD_STORM_THRESHOLD 5 1360b543fb04SEgbert Eich 136110a504deSDaniel Vetter static inline void intel_hpd_irq_handler(struct drm_device *dev, 1362b543fb04SEgbert Eich u32 hotplug_trigger, 1363b543fb04SEgbert Eich const u32 *hpd) 1364b543fb04SEgbert Eich { 1365b543fb04SEgbert Eich drm_i915_private_t *dev_priv = dev->dev_private; 1366b543fb04SEgbert Eich int i; 136710a504deSDaniel Vetter bool storm_detected = false; 1368b543fb04SEgbert Eich 136991d131d2SDaniel Vetter if (!hotplug_trigger) 137091d131d2SDaniel Vetter return; 137191d131d2SDaniel Vetter 1372cc9bd499SImre Deak DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n", 1373cc9bd499SImre Deak hotplug_trigger); 1374cc9bd499SImre Deak 1375b5ea2d56SDaniel Vetter spin_lock(&dev_priv->irq_lock); 1376b543fb04SEgbert Eich for (i = 1; i < HPD_NUM_PINS; i++) { 1377821450c6SEgbert Eich 13783432087eSChris Wilson WARN_ONCE(hpd[i] & hotplug_trigger && 13798b5565b8SChris Wilson dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED, 1380cba1c073SChris Wilson "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n", 1381cba1c073SChris Wilson hotplug_trigger, i, hpd[i]); 1382b8f102e8SEgbert Eich 1383b543fb04SEgbert Eich if (!(hpd[i] & hotplug_trigger) || 1384b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED) 1385b543fb04SEgbert Eich continue; 1386b543fb04SEgbert Eich 1387bc5ead8cSJani Nikula dev_priv->hpd_event_bits |= (1 << i); 1388b543fb04SEgbert Eich if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies, 1389b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_last_jiffies 1390b543fb04SEgbert Eich + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) { 1391b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies; 1392b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt = 0; 1393b8f102e8SEgbert Eich DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i); 1394b543fb04SEgbert Eich } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) { 1395b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED; 1396142e2398SEgbert Eich dev_priv->hpd_event_bits &= ~(1 << i); 1397b543fb04SEgbert Eich DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i); 139810a504deSDaniel Vetter storm_detected = true; 1399b543fb04SEgbert Eich } else { 1400b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt++; 1401b8f102e8SEgbert Eich DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i, 1402b8f102e8SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt); 1403b543fb04SEgbert Eich } 1404b543fb04SEgbert Eich } 1405b543fb04SEgbert Eich 140610a504deSDaniel Vetter if (storm_detected) 140710a504deSDaniel Vetter dev_priv->display.hpd_irq_setup(dev); 1408b5ea2d56SDaniel Vetter spin_unlock(&dev_priv->irq_lock); 14095876fa0dSDaniel Vetter 1410645416f5SDaniel Vetter /* 1411645416f5SDaniel Vetter * Our hotplug handler can grab modeset locks (by calling down into the 1412645416f5SDaniel Vetter * fb helpers). Hence it must not be run on our own dev-priv->wq work 1413645416f5SDaniel Vetter * queue for otherwise the flush_work in the pageflip code will 1414645416f5SDaniel Vetter * deadlock. 1415645416f5SDaniel Vetter */ 1416645416f5SDaniel Vetter schedule_work(&dev_priv->hotplug_work); 1417b543fb04SEgbert Eich } 1418b543fb04SEgbert Eich 1419515ac2bbSDaniel Vetter static void gmbus_irq_handler(struct drm_device *dev) 1420515ac2bbSDaniel Vetter { 142128c70f16SDaniel Vetter struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private; 142228c70f16SDaniel Vetter 142328c70f16SDaniel Vetter wake_up_all(&dev_priv->gmbus_wait_queue); 1424515ac2bbSDaniel Vetter } 1425515ac2bbSDaniel Vetter 1426ce99c256SDaniel Vetter static void dp_aux_irq_handler(struct drm_device *dev) 1427ce99c256SDaniel Vetter { 14289ee32feaSDaniel Vetter struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private; 14299ee32feaSDaniel Vetter 14309ee32feaSDaniel Vetter wake_up_all(&dev_priv->gmbus_wait_queue); 1431ce99c256SDaniel Vetter } 1432ce99c256SDaniel Vetter 14338bf1e9f1SShuang He #if defined(CONFIG_DEBUG_FS) 1434277de95eSDaniel Vetter static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe, 1435eba94eb9SDaniel Vetter uint32_t crc0, uint32_t crc1, 1436eba94eb9SDaniel Vetter uint32_t crc2, uint32_t crc3, 14378bc5e955SDaniel Vetter uint32_t crc4) 14388bf1e9f1SShuang He { 14398bf1e9f1SShuang He struct drm_i915_private *dev_priv = dev->dev_private; 14408bf1e9f1SShuang He struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe]; 14418bf1e9f1SShuang He struct intel_pipe_crc_entry *entry; 1442ac2300d4SDamien Lespiau int head, tail; 1443b2c88f5bSDamien Lespiau 1444d538bbdfSDamien Lespiau spin_lock(&pipe_crc->lock); 1445d538bbdfSDamien Lespiau 14460c912c79SDamien Lespiau if (!pipe_crc->entries) { 1447d538bbdfSDamien Lespiau spin_unlock(&pipe_crc->lock); 14480c912c79SDamien Lespiau DRM_ERROR("spurious interrupt\n"); 14490c912c79SDamien Lespiau return; 14500c912c79SDamien Lespiau } 14510c912c79SDamien Lespiau 1452d538bbdfSDamien Lespiau head = pipe_crc->head; 1453d538bbdfSDamien Lespiau tail = pipe_crc->tail; 1454b2c88f5bSDamien Lespiau 1455b2c88f5bSDamien Lespiau if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) { 1456d538bbdfSDamien Lespiau spin_unlock(&pipe_crc->lock); 1457b2c88f5bSDamien Lespiau DRM_ERROR("CRC buffer overflowing\n"); 1458b2c88f5bSDamien Lespiau return; 1459b2c88f5bSDamien Lespiau } 1460b2c88f5bSDamien Lespiau 1461b2c88f5bSDamien Lespiau entry = &pipe_crc->entries[head]; 14628bf1e9f1SShuang He 14638bc5e955SDaniel Vetter entry->frame = dev->driver->get_vblank_counter(dev, pipe); 1464eba94eb9SDaniel Vetter entry->crc[0] = crc0; 1465eba94eb9SDaniel Vetter entry->crc[1] = crc1; 1466eba94eb9SDaniel Vetter entry->crc[2] = crc2; 1467eba94eb9SDaniel Vetter entry->crc[3] = crc3; 1468eba94eb9SDaniel Vetter entry->crc[4] = crc4; 1469b2c88f5bSDamien Lespiau 1470b2c88f5bSDamien Lespiau head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1); 1471d538bbdfSDamien Lespiau pipe_crc->head = head; 1472d538bbdfSDamien Lespiau 1473d538bbdfSDamien Lespiau spin_unlock(&pipe_crc->lock); 147407144428SDamien Lespiau 147507144428SDamien Lespiau wake_up_interruptible(&pipe_crc->wq); 14768bf1e9f1SShuang He } 1477277de95eSDaniel Vetter #else 1478277de95eSDaniel Vetter static inline void 1479277de95eSDaniel Vetter display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe, 1480277de95eSDaniel Vetter uint32_t crc0, uint32_t crc1, 1481277de95eSDaniel Vetter uint32_t crc2, uint32_t crc3, 1482277de95eSDaniel Vetter uint32_t crc4) {} 1483277de95eSDaniel Vetter #endif 1484eba94eb9SDaniel Vetter 1485277de95eSDaniel Vetter 1486277de95eSDaniel Vetter static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe) 14875a69b89fSDaniel Vetter { 14885a69b89fSDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 14895a69b89fSDaniel Vetter 1490277de95eSDaniel Vetter display_pipe_crc_irq_handler(dev, pipe, 14915a69b89fSDaniel Vetter I915_READ(PIPE_CRC_RES_1_IVB(pipe)), 14925a69b89fSDaniel Vetter 0, 0, 0, 0); 14935a69b89fSDaniel Vetter } 14945a69b89fSDaniel Vetter 1495277de95eSDaniel Vetter static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe) 1496eba94eb9SDaniel Vetter { 1497eba94eb9SDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 1498eba94eb9SDaniel Vetter 1499277de95eSDaniel Vetter display_pipe_crc_irq_handler(dev, pipe, 1500eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_1_IVB(pipe)), 1501eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_2_IVB(pipe)), 1502eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_3_IVB(pipe)), 1503eba94eb9SDaniel Vetter I915_READ(PIPE_CRC_RES_4_IVB(pipe)), 15048bc5e955SDaniel Vetter I915_READ(PIPE_CRC_RES_5_IVB(pipe))); 1505eba94eb9SDaniel Vetter } 15065b3a856bSDaniel Vetter 1507277de95eSDaniel Vetter static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe) 15085b3a856bSDaniel Vetter { 15095b3a856bSDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 15100b5c5ed0SDaniel Vetter uint32_t res1, res2; 15110b5c5ed0SDaniel Vetter 15120b5c5ed0SDaniel Vetter if (INTEL_INFO(dev)->gen >= 3) 15130b5c5ed0SDaniel Vetter res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe)); 15140b5c5ed0SDaniel Vetter else 15150b5c5ed0SDaniel Vetter res1 = 0; 15160b5c5ed0SDaniel Vetter 15170b5c5ed0SDaniel Vetter if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) 15180b5c5ed0SDaniel Vetter res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe)); 15190b5c5ed0SDaniel Vetter else 15200b5c5ed0SDaniel Vetter res2 = 0; 15215b3a856bSDaniel Vetter 1522277de95eSDaniel Vetter display_pipe_crc_irq_handler(dev, pipe, 15230b5c5ed0SDaniel Vetter I915_READ(PIPE_CRC_RES_RED(pipe)), 15240b5c5ed0SDaniel Vetter I915_READ(PIPE_CRC_RES_GREEN(pipe)), 15250b5c5ed0SDaniel Vetter I915_READ(PIPE_CRC_RES_BLUE(pipe)), 15260b5c5ed0SDaniel Vetter res1, res2); 15275b3a856bSDaniel Vetter } 15288bf1e9f1SShuang He 15291403c0d4SPaulo Zanoni /* The RPS events need forcewake, so we add them to a work queue and mask their 15301403c0d4SPaulo Zanoni * IMR bits until the work is done. Other interrupts can be processed without 15311403c0d4SPaulo Zanoni * the work queue. */ 15321403c0d4SPaulo Zanoni static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir) 1533baf02a1fSBen Widawsky { 153441a05a3aSDaniel Vetter if (pm_iir & GEN6_PM_RPS_EVENTS) { 153559cdb63dSDaniel Vetter spin_lock(&dev_priv->irq_lock); 15364848405cSBen Widawsky dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS; 15374d3b3d5fSPaulo Zanoni snb_disable_pm_irq(dev_priv, pm_iir & GEN6_PM_RPS_EVENTS); 153859cdb63dSDaniel Vetter spin_unlock(&dev_priv->irq_lock); 15392adbee62SDaniel Vetter 15402adbee62SDaniel Vetter queue_work(dev_priv->wq, &dev_priv->rps.work); 154141a05a3aSDaniel Vetter } 1542baf02a1fSBen Widawsky 15431403c0d4SPaulo Zanoni if (HAS_VEBOX(dev_priv->dev)) { 154412638c57SBen Widawsky if (pm_iir & PM_VEBOX_USER_INTERRUPT) 154512638c57SBen Widawsky notify_ring(dev_priv->dev, &dev_priv->ring[VECS]); 154612638c57SBen Widawsky 154712638c57SBen Widawsky if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) { 1548*58174462SMika Kuoppala i915_handle_error(dev_priv->dev, false, 1549*58174462SMika Kuoppala "VEBOX CS error interrupt 0x%08x", 1550*58174462SMika Kuoppala pm_iir); 155112638c57SBen Widawsky } 155212638c57SBen Widawsky } 15531403c0d4SPaulo Zanoni } 1554baf02a1fSBen Widawsky 1555c1874ed7SImre Deak static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir) 15567e231dbeSJesse Barnes { 1557c1874ed7SImre Deak struct drm_i915_private *dev_priv = dev->dev_private; 155891d181ddSImre Deak u32 pipe_stats[I915_MAX_PIPES] = { }; 15597e231dbeSJesse Barnes int pipe; 15607e231dbeSJesse Barnes 156158ead0d7SImre Deak spin_lock(&dev_priv->irq_lock); 15627e231dbeSJesse Barnes for_each_pipe(pipe) { 156391d181ddSImre Deak int reg; 1564bbb5eebfSDaniel Vetter u32 mask, iir_bit = 0; 156591d181ddSImre Deak 1566bbb5eebfSDaniel Vetter /* 1567bbb5eebfSDaniel Vetter * PIPESTAT bits get signalled even when the interrupt is 1568bbb5eebfSDaniel Vetter * disabled with the mask bits, and some of the status bits do 1569bbb5eebfSDaniel Vetter * not generate interrupts at all (like the underrun bit). Hence 1570bbb5eebfSDaniel Vetter * we need to be careful that we only handle what we want to 1571bbb5eebfSDaniel Vetter * handle. 1572bbb5eebfSDaniel Vetter */ 1573bbb5eebfSDaniel Vetter mask = 0; 1574bbb5eebfSDaniel Vetter if (__cpu_fifo_underrun_reporting_enabled(dev, pipe)) 1575bbb5eebfSDaniel Vetter mask |= PIPE_FIFO_UNDERRUN_STATUS; 1576bbb5eebfSDaniel Vetter 1577bbb5eebfSDaniel Vetter switch (pipe) { 1578bbb5eebfSDaniel Vetter case PIPE_A: 1579bbb5eebfSDaniel Vetter iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT; 1580bbb5eebfSDaniel Vetter break; 1581bbb5eebfSDaniel Vetter case PIPE_B: 1582bbb5eebfSDaniel Vetter iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT; 1583bbb5eebfSDaniel Vetter break; 1584bbb5eebfSDaniel Vetter } 1585bbb5eebfSDaniel Vetter if (iir & iir_bit) 1586bbb5eebfSDaniel Vetter mask |= dev_priv->pipestat_irq_mask[pipe]; 1587bbb5eebfSDaniel Vetter 1588bbb5eebfSDaniel Vetter if (!mask) 158991d181ddSImre Deak continue; 159091d181ddSImre Deak 159191d181ddSImre Deak reg = PIPESTAT(pipe); 1592bbb5eebfSDaniel Vetter mask |= PIPESTAT_INT_ENABLE_MASK; 1593bbb5eebfSDaniel Vetter pipe_stats[pipe] = I915_READ(reg) & mask; 15947e231dbeSJesse Barnes 15957e231dbeSJesse Barnes /* 15967e231dbeSJesse Barnes * Clear the PIPE*STAT regs before the IIR 15977e231dbeSJesse Barnes */ 159891d181ddSImre Deak if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS | 159991d181ddSImre Deak PIPESTAT_INT_STATUS_MASK)) 16007e231dbeSJesse Barnes I915_WRITE(reg, pipe_stats[pipe]); 16017e231dbeSJesse Barnes } 160258ead0d7SImre Deak spin_unlock(&dev_priv->irq_lock); 16037e231dbeSJesse Barnes 160431acc7f5SJesse Barnes for_each_pipe(pipe) { 16057b5562d4SJesse Barnes if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS) 160631acc7f5SJesse Barnes drm_handle_vblank(dev, pipe); 160731acc7f5SJesse Barnes 1608579a9b0eSImre Deak if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) { 160931acc7f5SJesse Barnes intel_prepare_page_flip(dev, pipe); 161031acc7f5SJesse Barnes intel_finish_page_flip(dev, pipe); 161131acc7f5SJesse Barnes } 16124356d586SDaniel Vetter 16134356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 1614277de95eSDaniel Vetter i9xx_pipe_crc_irq_handler(dev, pipe); 16152d9d2b0bSVille Syrjälä 16162d9d2b0bSVille Syrjälä if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS && 16172d9d2b0bSVille Syrjälä intel_set_cpu_fifo_underrun_reporting(dev, pipe, false)) 1618fc2c807bSVille Syrjälä DRM_ERROR("pipe %c underrun\n", pipe_name(pipe)); 161931acc7f5SJesse Barnes } 162031acc7f5SJesse Barnes 1621c1874ed7SImre Deak if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 1622c1874ed7SImre Deak gmbus_irq_handler(dev); 1623c1874ed7SImre Deak } 1624c1874ed7SImre Deak 1625c1874ed7SImre Deak static irqreturn_t valleyview_irq_handler(int irq, void *arg) 1626c1874ed7SImre Deak { 1627c1874ed7SImre Deak struct drm_device *dev = (struct drm_device *) arg; 1628c1874ed7SImre Deak drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1629c1874ed7SImre Deak u32 iir, gt_iir, pm_iir; 1630c1874ed7SImre Deak irqreturn_t ret = IRQ_NONE; 1631c1874ed7SImre Deak 1632c1874ed7SImre Deak while (true) { 1633c1874ed7SImre Deak iir = I915_READ(VLV_IIR); 1634c1874ed7SImre Deak gt_iir = I915_READ(GTIIR); 1635c1874ed7SImre Deak pm_iir = I915_READ(GEN6_PMIIR); 1636c1874ed7SImre Deak 1637c1874ed7SImre Deak if (gt_iir == 0 && pm_iir == 0 && iir == 0) 1638c1874ed7SImre Deak goto out; 1639c1874ed7SImre Deak 1640c1874ed7SImre Deak ret = IRQ_HANDLED; 1641c1874ed7SImre Deak 1642c1874ed7SImre Deak snb_gt_irq_handler(dev, dev_priv, gt_iir); 1643c1874ed7SImre Deak 1644c1874ed7SImre Deak valleyview_pipestat_irq_handler(dev, iir); 1645c1874ed7SImre Deak 16467e231dbeSJesse Barnes /* Consume port. Then clear IIR or we'll miss events */ 16477e231dbeSJesse Barnes if (iir & I915_DISPLAY_PORT_INTERRUPT) { 16487e231dbeSJesse Barnes u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); 1649b543fb04SEgbert Eich u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915; 16507e231dbeSJesse Barnes 165110a504deSDaniel Vetter intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915); 165291d131d2SDaniel Vetter 16534aeebd74SDaniel Vetter if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X) 16544aeebd74SDaniel Vetter dp_aux_irq_handler(dev); 16554aeebd74SDaniel Vetter 16567e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); 16577e231dbeSJesse Barnes I915_READ(PORT_HOTPLUG_STAT); 16587e231dbeSJesse Barnes } 16597e231dbeSJesse Barnes 16607e231dbeSJesse Barnes 166160611c13SPaulo Zanoni if (pm_iir) 1662d0ecd7e2SDaniel Vetter gen6_rps_irq_handler(dev_priv, pm_iir); 16637e231dbeSJesse Barnes 16647e231dbeSJesse Barnes I915_WRITE(GTIIR, gt_iir); 16657e231dbeSJesse Barnes I915_WRITE(GEN6_PMIIR, pm_iir); 16667e231dbeSJesse Barnes I915_WRITE(VLV_IIR, iir); 16677e231dbeSJesse Barnes } 16687e231dbeSJesse Barnes 16697e231dbeSJesse Barnes out: 16707e231dbeSJesse Barnes return ret; 16717e231dbeSJesse Barnes } 16727e231dbeSJesse Barnes 167323e81d69SAdam Jackson static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir) 1674776ad806SJesse Barnes { 1675776ad806SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 16769db4a9c7SJesse Barnes int pipe; 1677b543fb04SEgbert Eich u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK; 1678776ad806SJesse Barnes 167910a504deSDaniel Vetter intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx); 168091d131d2SDaniel Vetter 1681cfc33bf7SVille Syrjälä if (pch_iir & SDE_AUDIO_POWER_MASK) { 1682cfc33bf7SVille Syrjälä int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >> 1683776ad806SJesse Barnes SDE_AUDIO_POWER_SHIFT); 1684cfc33bf7SVille Syrjälä DRM_DEBUG_DRIVER("PCH audio power change on port %d\n", 1685cfc33bf7SVille Syrjälä port_name(port)); 1686cfc33bf7SVille Syrjälä } 1687776ad806SJesse Barnes 1688ce99c256SDaniel Vetter if (pch_iir & SDE_AUX_MASK) 1689ce99c256SDaniel Vetter dp_aux_irq_handler(dev); 1690ce99c256SDaniel Vetter 1691776ad806SJesse Barnes if (pch_iir & SDE_GMBUS) 1692515ac2bbSDaniel Vetter gmbus_irq_handler(dev); 1693776ad806SJesse Barnes 1694776ad806SJesse Barnes if (pch_iir & SDE_AUDIO_HDCP_MASK) 1695776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n"); 1696776ad806SJesse Barnes 1697776ad806SJesse Barnes if (pch_iir & SDE_AUDIO_TRANS_MASK) 1698776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n"); 1699776ad806SJesse Barnes 1700776ad806SJesse Barnes if (pch_iir & SDE_POISON) 1701776ad806SJesse Barnes DRM_ERROR("PCH poison interrupt\n"); 1702776ad806SJesse Barnes 17039db4a9c7SJesse Barnes if (pch_iir & SDE_FDI_MASK) 17049db4a9c7SJesse Barnes for_each_pipe(pipe) 17059db4a9c7SJesse Barnes DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", 17069db4a9c7SJesse Barnes pipe_name(pipe), 17079db4a9c7SJesse Barnes I915_READ(FDI_RX_IIR(pipe))); 1708776ad806SJesse Barnes 1709776ad806SJesse Barnes if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE)) 1710776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n"); 1711776ad806SJesse Barnes 1712776ad806SJesse Barnes if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR)) 1713776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n"); 1714776ad806SJesse Barnes 1715776ad806SJesse Barnes if (pch_iir & SDE_TRANSA_FIFO_UNDER) 17168664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, 17178664281bSPaulo Zanoni false)) 1718fc2c807bSVille Syrjälä DRM_ERROR("PCH transcoder A FIFO underrun\n"); 17198664281bSPaulo Zanoni 17208664281bSPaulo Zanoni if (pch_iir & SDE_TRANSB_FIFO_UNDER) 17218664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B, 17228664281bSPaulo Zanoni false)) 1723fc2c807bSVille Syrjälä DRM_ERROR("PCH transcoder B FIFO underrun\n"); 17248664281bSPaulo Zanoni } 17258664281bSPaulo Zanoni 17268664281bSPaulo Zanoni static void ivb_err_int_handler(struct drm_device *dev) 17278664281bSPaulo Zanoni { 17288664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 17298664281bSPaulo Zanoni u32 err_int = I915_READ(GEN7_ERR_INT); 17305a69b89fSDaniel Vetter enum pipe pipe; 17318664281bSPaulo Zanoni 1732de032bf4SPaulo Zanoni if (err_int & ERR_INT_POISON) 1733de032bf4SPaulo Zanoni DRM_ERROR("Poison interrupt\n"); 1734de032bf4SPaulo Zanoni 17355a69b89fSDaniel Vetter for_each_pipe(pipe) { 17365a69b89fSDaniel Vetter if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) { 17375a69b89fSDaniel Vetter if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, 17385a69b89fSDaniel Vetter false)) 1739fc2c807bSVille Syrjälä DRM_ERROR("Pipe %c FIFO underrun\n", 17405a69b89fSDaniel Vetter pipe_name(pipe)); 17415a69b89fSDaniel Vetter } 17428664281bSPaulo Zanoni 17435a69b89fSDaniel Vetter if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) { 17445a69b89fSDaniel Vetter if (IS_IVYBRIDGE(dev)) 1745277de95eSDaniel Vetter ivb_pipe_crc_irq_handler(dev, pipe); 17465a69b89fSDaniel Vetter else 1747277de95eSDaniel Vetter hsw_pipe_crc_irq_handler(dev, pipe); 17485a69b89fSDaniel Vetter } 17495a69b89fSDaniel Vetter } 17508bf1e9f1SShuang He 17518664281bSPaulo Zanoni I915_WRITE(GEN7_ERR_INT, err_int); 17528664281bSPaulo Zanoni } 17538664281bSPaulo Zanoni 17548664281bSPaulo Zanoni static void cpt_serr_int_handler(struct drm_device *dev) 17558664281bSPaulo Zanoni { 17568664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 17578664281bSPaulo Zanoni u32 serr_int = I915_READ(SERR_INT); 17588664281bSPaulo Zanoni 1759de032bf4SPaulo Zanoni if (serr_int & SERR_INT_POISON) 1760de032bf4SPaulo Zanoni DRM_ERROR("PCH poison interrupt\n"); 1761de032bf4SPaulo Zanoni 17628664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN) 17638664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, 17648664281bSPaulo Zanoni false)) 1765fc2c807bSVille Syrjälä DRM_ERROR("PCH transcoder A FIFO underrun\n"); 17668664281bSPaulo Zanoni 17678664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN) 17688664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B, 17698664281bSPaulo Zanoni false)) 1770fc2c807bSVille Syrjälä DRM_ERROR("PCH transcoder B FIFO underrun\n"); 17718664281bSPaulo Zanoni 17728664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN) 17738664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C, 17748664281bSPaulo Zanoni false)) 1775fc2c807bSVille Syrjälä DRM_ERROR("PCH transcoder C FIFO underrun\n"); 17768664281bSPaulo Zanoni 17778664281bSPaulo Zanoni I915_WRITE(SERR_INT, serr_int); 1778776ad806SJesse Barnes } 1779776ad806SJesse Barnes 178023e81d69SAdam Jackson static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir) 178123e81d69SAdam Jackson { 178223e81d69SAdam Jackson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 178323e81d69SAdam Jackson int pipe; 1784b543fb04SEgbert Eich u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT; 178523e81d69SAdam Jackson 178610a504deSDaniel Vetter intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt); 178791d131d2SDaniel Vetter 1788cfc33bf7SVille Syrjälä if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) { 1789cfc33bf7SVille Syrjälä int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >> 179023e81d69SAdam Jackson SDE_AUDIO_POWER_SHIFT_CPT); 1791cfc33bf7SVille Syrjälä DRM_DEBUG_DRIVER("PCH audio power change on port %c\n", 1792cfc33bf7SVille Syrjälä port_name(port)); 1793cfc33bf7SVille Syrjälä } 179423e81d69SAdam Jackson 179523e81d69SAdam Jackson if (pch_iir & SDE_AUX_MASK_CPT) 1796ce99c256SDaniel Vetter dp_aux_irq_handler(dev); 179723e81d69SAdam Jackson 179823e81d69SAdam Jackson if (pch_iir & SDE_GMBUS_CPT) 1799515ac2bbSDaniel Vetter gmbus_irq_handler(dev); 180023e81d69SAdam Jackson 180123e81d69SAdam Jackson if (pch_iir & SDE_AUDIO_CP_REQ_CPT) 180223e81d69SAdam Jackson DRM_DEBUG_DRIVER("Audio CP request interrupt\n"); 180323e81d69SAdam Jackson 180423e81d69SAdam Jackson if (pch_iir & SDE_AUDIO_CP_CHG_CPT) 180523e81d69SAdam Jackson DRM_DEBUG_DRIVER("Audio CP change interrupt\n"); 180623e81d69SAdam Jackson 180723e81d69SAdam Jackson if (pch_iir & SDE_FDI_MASK_CPT) 180823e81d69SAdam Jackson for_each_pipe(pipe) 180923e81d69SAdam Jackson DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", 181023e81d69SAdam Jackson pipe_name(pipe), 181123e81d69SAdam Jackson I915_READ(FDI_RX_IIR(pipe))); 18128664281bSPaulo Zanoni 18138664281bSPaulo Zanoni if (pch_iir & SDE_ERROR_CPT) 18148664281bSPaulo Zanoni cpt_serr_int_handler(dev); 181523e81d69SAdam Jackson } 181623e81d69SAdam Jackson 1817c008bc6eSPaulo Zanoni static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir) 1818c008bc6eSPaulo Zanoni { 1819c008bc6eSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 182040da17c2SDaniel Vetter enum pipe pipe; 1821c008bc6eSPaulo Zanoni 1822c008bc6eSPaulo Zanoni if (de_iir & DE_AUX_CHANNEL_A) 1823c008bc6eSPaulo Zanoni dp_aux_irq_handler(dev); 1824c008bc6eSPaulo Zanoni 1825c008bc6eSPaulo Zanoni if (de_iir & DE_GSE) 1826c008bc6eSPaulo Zanoni intel_opregion_asle_intr(dev); 1827c008bc6eSPaulo Zanoni 1828c008bc6eSPaulo Zanoni if (de_iir & DE_POISON) 1829c008bc6eSPaulo Zanoni DRM_ERROR("Poison interrupt\n"); 1830c008bc6eSPaulo Zanoni 183140da17c2SDaniel Vetter for_each_pipe(pipe) { 183240da17c2SDaniel Vetter if (de_iir & DE_PIPE_VBLANK(pipe)) 183340da17c2SDaniel Vetter drm_handle_vblank(dev, pipe); 1834c008bc6eSPaulo Zanoni 183540da17c2SDaniel Vetter if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe)) 183640da17c2SDaniel Vetter if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, false)) 1837fc2c807bSVille Syrjälä DRM_ERROR("Pipe %c FIFO underrun\n", 183840da17c2SDaniel Vetter pipe_name(pipe)); 1839c008bc6eSPaulo Zanoni 184040da17c2SDaniel Vetter if (de_iir & DE_PIPE_CRC_DONE(pipe)) 184140da17c2SDaniel Vetter i9xx_pipe_crc_irq_handler(dev, pipe); 18425b3a856bSDaniel Vetter 184340da17c2SDaniel Vetter /* plane/pipes map 1:1 on ilk+ */ 184440da17c2SDaniel Vetter if (de_iir & DE_PLANE_FLIP_DONE(pipe)) { 184540da17c2SDaniel Vetter intel_prepare_page_flip(dev, pipe); 184640da17c2SDaniel Vetter intel_finish_page_flip_plane(dev, pipe); 1847c008bc6eSPaulo Zanoni } 1848c008bc6eSPaulo Zanoni } 1849c008bc6eSPaulo Zanoni 1850c008bc6eSPaulo Zanoni /* check event from PCH */ 1851c008bc6eSPaulo Zanoni if (de_iir & DE_PCH_EVENT) { 1852c008bc6eSPaulo Zanoni u32 pch_iir = I915_READ(SDEIIR); 1853c008bc6eSPaulo Zanoni 1854c008bc6eSPaulo Zanoni if (HAS_PCH_CPT(dev)) 1855c008bc6eSPaulo Zanoni cpt_irq_handler(dev, pch_iir); 1856c008bc6eSPaulo Zanoni else 1857c008bc6eSPaulo Zanoni ibx_irq_handler(dev, pch_iir); 1858c008bc6eSPaulo Zanoni 1859c008bc6eSPaulo Zanoni /* should clear PCH hotplug event before clear CPU irq */ 1860c008bc6eSPaulo Zanoni I915_WRITE(SDEIIR, pch_iir); 1861c008bc6eSPaulo Zanoni } 1862c008bc6eSPaulo Zanoni 1863c008bc6eSPaulo Zanoni if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT) 1864c008bc6eSPaulo Zanoni ironlake_rps_change_irq_handler(dev); 1865c008bc6eSPaulo Zanoni } 1866c008bc6eSPaulo Zanoni 18679719fb98SPaulo Zanoni static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir) 18689719fb98SPaulo Zanoni { 18699719fb98SPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 18703b6c42e8SDaniel Vetter enum pipe i; 18719719fb98SPaulo Zanoni 18729719fb98SPaulo Zanoni if (de_iir & DE_ERR_INT_IVB) 18739719fb98SPaulo Zanoni ivb_err_int_handler(dev); 18749719fb98SPaulo Zanoni 18759719fb98SPaulo Zanoni if (de_iir & DE_AUX_CHANNEL_A_IVB) 18769719fb98SPaulo Zanoni dp_aux_irq_handler(dev); 18779719fb98SPaulo Zanoni 18789719fb98SPaulo Zanoni if (de_iir & DE_GSE_IVB) 18799719fb98SPaulo Zanoni intel_opregion_asle_intr(dev); 18809719fb98SPaulo Zanoni 18813b6c42e8SDaniel Vetter for_each_pipe(i) { 188240da17c2SDaniel Vetter if (de_iir & (DE_PIPE_VBLANK_IVB(i))) 18839719fb98SPaulo Zanoni drm_handle_vblank(dev, i); 188440da17c2SDaniel Vetter 188540da17c2SDaniel Vetter /* plane/pipes map 1:1 on ilk+ */ 188640da17c2SDaniel Vetter if (de_iir & DE_PLANE_FLIP_DONE_IVB(i)) { 18879719fb98SPaulo Zanoni intel_prepare_page_flip(dev, i); 18889719fb98SPaulo Zanoni intel_finish_page_flip_plane(dev, i); 18899719fb98SPaulo Zanoni } 18909719fb98SPaulo Zanoni } 18919719fb98SPaulo Zanoni 18929719fb98SPaulo Zanoni /* check event from PCH */ 18939719fb98SPaulo Zanoni if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) { 18949719fb98SPaulo Zanoni u32 pch_iir = I915_READ(SDEIIR); 18959719fb98SPaulo Zanoni 18969719fb98SPaulo Zanoni cpt_irq_handler(dev, pch_iir); 18979719fb98SPaulo Zanoni 18989719fb98SPaulo Zanoni /* clear PCH hotplug event before clear CPU irq */ 18999719fb98SPaulo Zanoni I915_WRITE(SDEIIR, pch_iir); 19009719fb98SPaulo Zanoni } 19019719fb98SPaulo Zanoni } 19029719fb98SPaulo Zanoni 1903f1af8fc1SPaulo Zanoni static irqreturn_t ironlake_irq_handler(int irq, void *arg) 1904b1f14ad0SJesse Barnes { 1905b1f14ad0SJesse Barnes struct drm_device *dev = (struct drm_device *) arg; 1906b1f14ad0SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1907f1af8fc1SPaulo Zanoni u32 de_iir, gt_iir, de_ier, sde_ier = 0; 19080e43406bSChris Wilson irqreturn_t ret = IRQ_NONE; 1909b1f14ad0SJesse Barnes 19108664281bSPaulo Zanoni /* We get interrupts on unclaimed registers, so check for this before we 19118664281bSPaulo Zanoni * do any I915_{READ,WRITE}. */ 1912907b28c5SChris Wilson intel_uncore_check_errors(dev); 19138664281bSPaulo Zanoni 1914b1f14ad0SJesse Barnes /* disable master interrupt before clearing iir */ 1915b1f14ad0SJesse Barnes de_ier = I915_READ(DEIER); 1916b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL); 191723a78516SPaulo Zanoni POSTING_READ(DEIER); 19180e43406bSChris Wilson 191944498aeaSPaulo Zanoni /* Disable south interrupts. We'll only write to SDEIIR once, so further 192044498aeaSPaulo Zanoni * interrupts will will be stored on its back queue, and then we'll be 192144498aeaSPaulo Zanoni * able to process them after we restore SDEIER (as soon as we restore 192244498aeaSPaulo Zanoni * it, we'll get an interrupt if SDEIIR still has something to process 192344498aeaSPaulo Zanoni * due to its back queue). */ 1924ab5c608bSBen Widawsky if (!HAS_PCH_NOP(dev)) { 192544498aeaSPaulo Zanoni sde_ier = I915_READ(SDEIER); 192644498aeaSPaulo Zanoni I915_WRITE(SDEIER, 0); 192744498aeaSPaulo Zanoni POSTING_READ(SDEIER); 1928ab5c608bSBen Widawsky } 192944498aeaSPaulo Zanoni 19300e43406bSChris Wilson gt_iir = I915_READ(GTIIR); 19310e43406bSChris Wilson if (gt_iir) { 1932d8fc8a47SPaulo Zanoni if (INTEL_INFO(dev)->gen >= 6) 19330e43406bSChris Wilson snb_gt_irq_handler(dev, dev_priv, gt_iir); 1934d8fc8a47SPaulo Zanoni else 1935d8fc8a47SPaulo Zanoni ilk_gt_irq_handler(dev, dev_priv, gt_iir); 19360e43406bSChris Wilson I915_WRITE(GTIIR, gt_iir); 19370e43406bSChris Wilson ret = IRQ_HANDLED; 19380e43406bSChris Wilson } 1939b1f14ad0SJesse Barnes 1940b1f14ad0SJesse Barnes de_iir = I915_READ(DEIIR); 19410e43406bSChris Wilson if (de_iir) { 1942f1af8fc1SPaulo Zanoni if (INTEL_INFO(dev)->gen >= 7) 19439719fb98SPaulo Zanoni ivb_display_irq_handler(dev, de_iir); 1944f1af8fc1SPaulo Zanoni else 1945f1af8fc1SPaulo Zanoni ilk_display_irq_handler(dev, de_iir); 19460e43406bSChris Wilson I915_WRITE(DEIIR, de_iir); 19470e43406bSChris Wilson ret = IRQ_HANDLED; 19480e43406bSChris Wilson } 19490e43406bSChris Wilson 1950f1af8fc1SPaulo Zanoni if (INTEL_INFO(dev)->gen >= 6) { 1951f1af8fc1SPaulo Zanoni u32 pm_iir = I915_READ(GEN6_PMIIR); 19520e43406bSChris Wilson if (pm_iir) { 1953d0ecd7e2SDaniel Vetter gen6_rps_irq_handler(dev_priv, pm_iir); 1954b1f14ad0SJesse Barnes I915_WRITE(GEN6_PMIIR, pm_iir); 19550e43406bSChris Wilson ret = IRQ_HANDLED; 19560e43406bSChris Wilson } 1957f1af8fc1SPaulo Zanoni } 1958b1f14ad0SJesse Barnes 1959b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier); 1960b1f14ad0SJesse Barnes POSTING_READ(DEIER); 1961ab5c608bSBen Widawsky if (!HAS_PCH_NOP(dev)) { 196244498aeaSPaulo Zanoni I915_WRITE(SDEIER, sde_ier); 196344498aeaSPaulo Zanoni POSTING_READ(SDEIER); 1964ab5c608bSBen Widawsky } 1965b1f14ad0SJesse Barnes 1966b1f14ad0SJesse Barnes return ret; 1967b1f14ad0SJesse Barnes } 1968b1f14ad0SJesse Barnes 1969abd58f01SBen Widawsky static irqreturn_t gen8_irq_handler(int irq, void *arg) 1970abd58f01SBen Widawsky { 1971abd58f01SBen Widawsky struct drm_device *dev = arg; 1972abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 1973abd58f01SBen Widawsky u32 master_ctl; 1974abd58f01SBen Widawsky irqreturn_t ret = IRQ_NONE; 1975abd58f01SBen Widawsky uint32_t tmp = 0; 1976c42664ccSDaniel Vetter enum pipe pipe; 1977abd58f01SBen Widawsky 1978abd58f01SBen Widawsky master_ctl = I915_READ(GEN8_MASTER_IRQ); 1979abd58f01SBen Widawsky master_ctl &= ~GEN8_MASTER_IRQ_CONTROL; 1980abd58f01SBen Widawsky if (!master_ctl) 1981abd58f01SBen Widawsky return IRQ_NONE; 1982abd58f01SBen Widawsky 1983abd58f01SBen Widawsky I915_WRITE(GEN8_MASTER_IRQ, 0); 1984abd58f01SBen Widawsky POSTING_READ(GEN8_MASTER_IRQ); 1985abd58f01SBen Widawsky 1986abd58f01SBen Widawsky ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl); 1987abd58f01SBen Widawsky 1988abd58f01SBen Widawsky if (master_ctl & GEN8_DE_MISC_IRQ) { 1989abd58f01SBen Widawsky tmp = I915_READ(GEN8_DE_MISC_IIR); 1990abd58f01SBen Widawsky if (tmp & GEN8_DE_MISC_GSE) 1991abd58f01SBen Widawsky intel_opregion_asle_intr(dev); 1992abd58f01SBen Widawsky else if (tmp) 1993abd58f01SBen Widawsky DRM_ERROR("Unexpected DE Misc interrupt\n"); 1994abd58f01SBen Widawsky else 1995abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (DE MISC)!\n"); 1996abd58f01SBen Widawsky 1997abd58f01SBen Widawsky if (tmp) { 1998abd58f01SBen Widawsky I915_WRITE(GEN8_DE_MISC_IIR, tmp); 1999abd58f01SBen Widawsky ret = IRQ_HANDLED; 2000abd58f01SBen Widawsky } 2001abd58f01SBen Widawsky } 2002abd58f01SBen Widawsky 20036d766f02SDaniel Vetter if (master_ctl & GEN8_DE_PORT_IRQ) { 20046d766f02SDaniel Vetter tmp = I915_READ(GEN8_DE_PORT_IIR); 20056d766f02SDaniel Vetter if (tmp & GEN8_AUX_CHANNEL_A) 20066d766f02SDaniel Vetter dp_aux_irq_handler(dev); 20076d766f02SDaniel Vetter else if (tmp) 20086d766f02SDaniel Vetter DRM_ERROR("Unexpected DE Port interrupt\n"); 20096d766f02SDaniel Vetter else 20106d766f02SDaniel Vetter DRM_ERROR("The master control interrupt lied (DE PORT)!\n"); 20116d766f02SDaniel Vetter 20126d766f02SDaniel Vetter if (tmp) { 20136d766f02SDaniel Vetter I915_WRITE(GEN8_DE_PORT_IIR, tmp); 20146d766f02SDaniel Vetter ret = IRQ_HANDLED; 20156d766f02SDaniel Vetter } 20166d766f02SDaniel Vetter } 20176d766f02SDaniel Vetter 2018abd58f01SBen Widawsky for_each_pipe(pipe) { 2019abd58f01SBen Widawsky uint32_t pipe_iir; 2020abd58f01SBen Widawsky 2021c42664ccSDaniel Vetter if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe))) 2022c42664ccSDaniel Vetter continue; 2023c42664ccSDaniel Vetter 2024abd58f01SBen Widawsky pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe)); 2025abd58f01SBen Widawsky if (pipe_iir & GEN8_PIPE_VBLANK) 2026abd58f01SBen Widawsky drm_handle_vblank(dev, pipe); 2027abd58f01SBen Widawsky 2028abd58f01SBen Widawsky if (pipe_iir & GEN8_PIPE_FLIP_DONE) { 2029abd58f01SBen Widawsky intel_prepare_page_flip(dev, pipe); 2030abd58f01SBen Widawsky intel_finish_page_flip_plane(dev, pipe); 2031abd58f01SBen Widawsky } 2032abd58f01SBen Widawsky 20330fbe7870SDaniel Vetter if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE) 20340fbe7870SDaniel Vetter hsw_pipe_crc_irq_handler(dev, pipe); 20350fbe7870SDaniel Vetter 203638d83c96SDaniel Vetter if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN) { 203738d83c96SDaniel Vetter if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, 203838d83c96SDaniel Vetter false)) 2039fc2c807bSVille Syrjälä DRM_ERROR("Pipe %c FIFO underrun\n", 204038d83c96SDaniel Vetter pipe_name(pipe)); 204138d83c96SDaniel Vetter } 204238d83c96SDaniel Vetter 204330100f2bSDaniel Vetter if (pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS) { 204430100f2bSDaniel Vetter DRM_ERROR("Fault errors on pipe %c\n: 0x%08x", 204530100f2bSDaniel Vetter pipe_name(pipe), 204630100f2bSDaniel Vetter pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS); 204730100f2bSDaniel Vetter } 2048abd58f01SBen Widawsky 2049abd58f01SBen Widawsky if (pipe_iir) { 2050abd58f01SBen Widawsky ret = IRQ_HANDLED; 2051abd58f01SBen Widawsky I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir); 2052c42664ccSDaniel Vetter } else 2053abd58f01SBen Widawsky DRM_ERROR("The master control interrupt lied (DE PIPE)!\n"); 2054abd58f01SBen Widawsky } 2055abd58f01SBen Widawsky 205692d03a80SDaniel Vetter if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) { 205792d03a80SDaniel Vetter /* 205892d03a80SDaniel Vetter * FIXME(BDW): Assume for now that the new interrupt handling 205992d03a80SDaniel Vetter * scheme also closed the SDE interrupt handling race we've seen 206092d03a80SDaniel Vetter * on older pch-split platforms. But this needs testing. 206192d03a80SDaniel Vetter */ 206292d03a80SDaniel Vetter u32 pch_iir = I915_READ(SDEIIR); 206392d03a80SDaniel Vetter 206492d03a80SDaniel Vetter cpt_irq_handler(dev, pch_iir); 206592d03a80SDaniel Vetter 206692d03a80SDaniel Vetter if (pch_iir) { 206792d03a80SDaniel Vetter I915_WRITE(SDEIIR, pch_iir); 206892d03a80SDaniel Vetter ret = IRQ_HANDLED; 206992d03a80SDaniel Vetter } 207092d03a80SDaniel Vetter } 207192d03a80SDaniel Vetter 2072abd58f01SBen Widawsky I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); 2073abd58f01SBen Widawsky POSTING_READ(GEN8_MASTER_IRQ); 2074abd58f01SBen Widawsky 2075abd58f01SBen Widawsky return ret; 2076abd58f01SBen Widawsky } 2077abd58f01SBen Widawsky 207817e1df07SDaniel Vetter static void i915_error_wake_up(struct drm_i915_private *dev_priv, 207917e1df07SDaniel Vetter bool reset_completed) 208017e1df07SDaniel Vetter { 208117e1df07SDaniel Vetter struct intel_ring_buffer *ring; 208217e1df07SDaniel Vetter int i; 208317e1df07SDaniel Vetter 208417e1df07SDaniel Vetter /* 208517e1df07SDaniel Vetter * Notify all waiters for GPU completion events that reset state has 208617e1df07SDaniel Vetter * been changed, and that they need to restart their wait after 208717e1df07SDaniel Vetter * checking for potential errors (and bail out to drop locks if there is 208817e1df07SDaniel Vetter * a gpu reset pending so that i915_error_work_func can acquire them). 208917e1df07SDaniel Vetter */ 209017e1df07SDaniel Vetter 209117e1df07SDaniel Vetter /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */ 209217e1df07SDaniel Vetter for_each_ring(ring, dev_priv, i) 209317e1df07SDaniel Vetter wake_up_all(&ring->irq_queue); 209417e1df07SDaniel Vetter 209517e1df07SDaniel Vetter /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */ 209617e1df07SDaniel Vetter wake_up_all(&dev_priv->pending_flip_queue); 209717e1df07SDaniel Vetter 209817e1df07SDaniel Vetter /* 209917e1df07SDaniel Vetter * Signal tasks blocked in i915_gem_wait_for_error that the pending 210017e1df07SDaniel Vetter * reset state is cleared. 210117e1df07SDaniel Vetter */ 210217e1df07SDaniel Vetter if (reset_completed) 210317e1df07SDaniel Vetter wake_up_all(&dev_priv->gpu_error.reset_queue); 210417e1df07SDaniel Vetter } 210517e1df07SDaniel Vetter 21068a905236SJesse Barnes /** 21078a905236SJesse Barnes * i915_error_work_func - do process context error handling work 21088a905236SJesse Barnes * @work: work struct 21098a905236SJesse Barnes * 21108a905236SJesse Barnes * Fire an error uevent so userspace can see that a hang or error 21118a905236SJesse Barnes * was detected. 21128a905236SJesse Barnes */ 21138a905236SJesse Barnes static void i915_error_work_func(struct work_struct *work) 21148a905236SJesse Barnes { 21151f83fee0SDaniel Vetter struct i915_gpu_error *error = container_of(work, struct i915_gpu_error, 21161f83fee0SDaniel Vetter work); 21171f83fee0SDaniel Vetter drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t, 21181f83fee0SDaniel Vetter gpu_error); 21198a905236SJesse Barnes struct drm_device *dev = dev_priv->dev; 2120cce723edSBen Widawsky char *error_event[] = { I915_ERROR_UEVENT "=1", NULL }; 2121cce723edSBen Widawsky char *reset_event[] = { I915_RESET_UEVENT "=1", NULL }; 2122cce723edSBen Widawsky char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL }; 212317e1df07SDaniel Vetter int ret; 21248a905236SJesse Barnes 21255bdebb18SDave Airlie kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event); 21268a905236SJesse Barnes 21277db0ba24SDaniel Vetter /* 21287db0ba24SDaniel Vetter * Note that there's only one work item which does gpu resets, so we 21297db0ba24SDaniel Vetter * need not worry about concurrent gpu resets potentially incrementing 21307db0ba24SDaniel Vetter * error->reset_counter twice. We only need to take care of another 21317db0ba24SDaniel Vetter * racing irq/hangcheck declaring the gpu dead for a second time. A 21327db0ba24SDaniel Vetter * quick check for that is good enough: schedule_work ensures the 21337db0ba24SDaniel Vetter * correct ordering between hang detection and this work item, and since 21347db0ba24SDaniel Vetter * the reset in-progress bit is only ever set by code outside of this 21357db0ba24SDaniel Vetter * work we don't need to worry about any other races. 21367db0ba24SDaniel Vetter */ 21377db0ba24SDaniel Vetter if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) { 213844d98a61SZhao Yakui DRM_DEBUG_DRIVER("resetting chip\n"); 21395bdebb18SDave Airlie kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, 21407db0ba24SDaniel Vetter reset_event); 21411f83fee0SDaniel Vetter 214217e1df07SDaniel Vetter /* 214317e1df07SDaniel Vetter * All state reset _must_ be completed before we update the 214417e1df07SDaniel Vetter * reset counter, for otherwise waiters might miss the reset 214517e1df07SDaniel Vetter * pending state and not properly drop locks, resulting in 214617e1df07SDaniel Vetter * deadlocks with the reset work. 214717e1df07SDaniel Vetter */ 2148f69061beSDaniel Vetter ret = i915_reset(dev); 2149f69061beSDaniel Vetter 215017e1df07SDaniel Vetter intel_display_handle_reset(dev); 215117e1df07SDaniel Vetter 2152f69061beSDaniel Vetter if (ret == 0) { 2153f69061beSDaniel Vetter /* 2154f69061beSDaniel Vetter * After all the gem state is reset, increment the reset 2155f69061beSDaniel Vetter * counter and wake up everyone waiting for the reset to 2156f69061beSDaniel Vetter * complete. 2157f69061beSDaniel Vetter * 2158f69061beSDaniel Vetter * Since unlock operations are a one-sided barrier only, 2159f69061beSDaniel Vetter * we need to insert a barrier here to order any seqno 2160f69061beSDaniel Vetter * updates before 2161f69061beSDaniel Vetter * the counter increment. 2162f69061beSDaniel Vetter */ 2163f69061beSDaniel Vetter smp_mb__before_atomic_inc(); 2164f69061beSDaniel Vetter atomic_inc(&dev_priv->gpu_error.reset_counter); 2165f69061beSDaniel Vetter 21665bdebb18SDave Airlie kobject_uevent_env(&dev->primary->kdev->kobj, 2167f69061beSDaniel Vetter KOBJ_CHANGE, reset_done_event); 21681f83fee0SDaniel Vetter } else { 21692ac0f450SMika Kuoppala atomic_set_mask(I915_WEDGED, &error->reset_counter); 2170f316a42cSBen Gamari } 21711f83fee0SDaniel Vetter 217217e1df07SDaniel Vetter /* 217317e1df07SDaniel Vetter * Note: The wake_up also serves as a memory barrier so that 217417e1df07SDaniel Vetter * waiters see the update value of the reset counter atomic_t. 217517e1df07SDaniel Vetter */ 217617e1df07SDaniel Vetter i915_error_wake_up(dev_priv, true); 2177f316a42cSBen Gamari } 21788a905236SJesse Barnes } 21798a905236SJesse Barnes 218035aed2e6SChris Wilson static void i915_report_and_clear_eir(struct drm_device *dev) 2181c0e09200SDave Airlie { 21828a905236SJesse Barnes struct drm_i915_private *dev_priv = dev->dev_private; 2183bd9854f9SBen Widawsky uint32_t instdone[I915_NUM_INSTDONE_REG]; 218463eeaf38SJesse Barnes u32 eir = I915_READ(EIR); 2185050ee91fSBen Widawsky int pipe, i; 218663eeaf38SJesse Barnes 218735aed2e6SChris Wilson if (!eir) 218835aed2e6SChris Wilson return; 218963eeaf38SJesse Barnes 2190a70491ccSJoe Perches pr_err("render error detected, EIR: 0x%08x\n", eir); 21918a905236SJesse Barnes 2192bd9854f9SBen Widawsky i915_get_extra_instdone(dev, instdone); 2193bd9854f9SBen Widawsky 21948a905236SJesse Barnes if (IS_G4X(dev)) { 21958a905236SJesse Barnes if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) { 21968a905236SJesse Barnes u32 ipeir = I915_READ(IPEIR_I965); 21978a905236SJesse Barnes 2198a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); 2199a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); 2200050ee91fSBen Widawsky for (i = 0; i < ARRAY_SIZE(instdone); i++) 2201050ee91fSBen Widawsky pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]); 2202a70491ccSJoe Perches pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); 2203a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); 22048a905236SJesse Barnes I915_WRITE(IPEIR_I965, ipeir); 22053143a2bfSChris Wilson POSTING_READ(IPEIR_I965); 22068a905236SJesse Barnes } 22078a905236SJesse Barnes if (eir & GM45_ERROR_PAGE_TABLE) { 22088a905236SJesse Barnes u32 pgtbl_err = I915_READ(PGTBL_ER); 2209a70491ccSJoe Perches pr_err("page table error\n"); 2210a70491ccSJoe Perches pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); 22118a905236SJesse Barnes I915_WRITE(PGTBL_ER, pgtbl_err); 22123143a2bfSChris Wilson POSTING_READ(PGTBL_ER); 22138a905236SJesse Barnes } 22148a905236SJesse Barnes } 22158a905236SJesse Barnes 2216a6c45cf0SChris Wilson if (!IS_GEN2(dev)) { 221763eeaf38SJesse Barnes if (eir & I915_ERROR_PAGE_TABLE) { 221863eeaf38SJesse Barnes u32 pgtbl_err = I915_READ(PGTBL_ER); 2219a70491ccSJoe Perches pr_err("page table error\n"); 2220a70491ccSJoe Perches pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); 222163eeaf38SJesse Barnes I915_WRITE(PGTBL_ER, pgtbl_err); 22223143a2bfSChris Wilson POSTING_READ(PGTBL_ER); 222363eeaf38SJesse Barnes } 22248a905236SJesse Barnes } 22258a905236SJesse Barnes 222663eeaf38SJesse Barnes if (eir & I915_ERROR_MEMORY_REFRESH) { 2227a70491ccSJoe Perches pr_err("memory refresh error:\n"); 22289db4a9c7SJesse Barnes for_each_pipe(pipe) 2229a70491ccSJoe Perches pr_err("pipe %c stat: 0x%08x\n", 22309db4a9c7SJesse Barnes pipe_name(pipe), I915_READ(PIPESTAT(pipe))); 223163eeaf38SJesse Barnes /* pipestat has already been acked */ 223263eeaf38SJesse Barnes } 223363eeaf38SJesse Barnes if (eir & I915_ERROR_INSTRUCTION) { 2234a70491ccSJoe Perches pr_err("instruction error\n"); 2235a70491ccSJoe Perches pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM)); 2236050ee91fSBen Widawsky for (i = 0; i < ARRAY_SIZE(instdone); i++) 2237050ee91fSBen Widawsky pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]); 2238a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen < 4) { 223963eeaf38SJesse Barnes u32 ipeir = I915_READ(IPEIR); 224063eeaf38SJesse Barnes 2241a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR)); 2242a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR)); 2243a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD)); 224463eeaf38SJesse Barnes I915_WRITE(IPEIR, ipeir); 22453143a2bfSChris Wilson POSTING_READ(IPEIR); 224663eeaf38SJesse Barnes } else { 224763eeaf38SJesse Barnes u32 ipeir = I915_READ(IPEIR_I965); 224863eeaf38SJesse Barnes 2249a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); 2250a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); 2251a70491ccSJoe Perches pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); 2252a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); 225363eeaf38SJesse Barnes I915_WRITE(IPEIR_I965, ipeir); 22543143a2bfSChris Wilson POSTING_READ(IPEIR_I965); 225563eeaf38SJesse Barnes } 225663eeaf38SJesse Barnes } 225763eeaf38SJesse Barnes 225863eeaf38SJesse Barnes I915_WRITE(EIR, eir); 22593143a2bfSChris Wilson POSTING_READ(EIR); 226063eeaf38SJesse Barnes eir = I915_READ(EIR); 226163eeaf38SJesse Barnes if (eir) { 226263eeaf38SJesse Barnes /* 226363eeaf38SJesse Barnes * some errors might have become stuck, 226463eeaf38SJesse Barnes * mask them. 226563eeaf38SJesse Barnes */ 226663eeaf38SJesse Barnes DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir); 226763eeaf38SJesse Barnes I915_WRITE(EMR, I915_READ(EMR) | eir); 226863eeaf38SJesse Barnes I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 226963eeaf38SJesse Barnes } 227035aed2e6SChris Wilson } 227135aed2e6SChris Wilson 227235aed2e6SChris Wilson /** 227335aed2e6SChris Wilson * i915_handle_error - handle an error interrupt 227435aed2e6SChris Wilson * @dev: drm device 227535aed2e6SChris Wilson * 227635aed2e6SChris Wilson * Do some basic checking of regsiter state at error interrupt time and 227735aed2e6SChris Wilson * dump it to the syslog. Also call i915_capture_error_state() to make 227835aed2e6SChris Wilson * sure we get a record and make it available in debugfs. Fire a uevent 227935aed2e6SChris Wilson * so userspace knows something bad happened (should trigger collection 228035aed2e6SChris Wilson * of a ring dump etc.). 228135aed2e6SChris Wilson */ 2282*58174462SMika Kuoppala void i915_handle_error(struct drm_device *dev, bool wedged, 2283*58174462SMika Kuoppala const char *fmt, ...) 228435aed2e6SChris Wilson { 228535aed2e6SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 2286*58174462SMika Kuoppala va_list args; 2287*58174462SMika Kuoppala char error_msg[80]; 228835aed2e6SChris Wilson 2289*58174462SMika Kuoppala va_start(args, fmt); 2290*58174462SMika Kuoppala vscnprintf(error_msg, sizeof(error_msg), fmt, args); 2291*58174462SMika Kuoppala va_end(args); 2292*58174462SMika Kuoppala 2293*58174462SMika Kuoppala i915_capture_error_state(dev, wedged, error_msg); 229435aed2e6SChris Wilson i915_report_and_clear_eir(dev); 22958a905236SJesse Barnes 2296ba1234d1SBen Gamari if (wedged) { 2297f69061beSDaniel Vetter atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG, 2298f69061beSDaniel Vetter &dev_priv->gpu_error.reset_counter); 2299ba1234d1SBen Gamari 230011ed50ecSBen Gamari /* 230117e1df07SDaniel Vetter * Wakeup waiting processes so that the reset work function 230217e1df07SDaniel Vetter * i915_error_work_func doesn't deadlock trying to grab various 230317e1df07SDaniel Vetter * locks. By bumping the reset counter first, the woken 230417e1df07SDaniel Vetter * processes will see a reset in progress and back off, 230517e1df07SDaniel Vetter * releasing their locks and then wait for the reset completion. 230617e1df07SDaniel Vetter * We must do this for _all_ gpu waiters that might hold locks 230717e1df07SDaniel Vetter * that the reset work needs to acquire. 230817e1df07SDaniel Vetter * 230917e1df07SDaniel Vetter * Note: The wake_up serves as the required memory barrier to 231017e1df07SDaniel Vetter * ensure that the waiters see the updated value of the reset 231117e1df07SDaniel Vetter * counter atomic_t. 231211ed50ecSBen Gamari */ 231317e1df07SDaniel Vetter i915_error_wake_up(dev_priv, false); 231411ed50ecSBen Gamari } 231511ed50ecSBen Gamari 2316122f46baSDaniel Vetter /* 2317122f46baSDaniel Vetter * Our reset work can grab modeset locks (since it needs to reset the 2318122f46baSDaniel Vetter * state of outstanding pagelips). Hence it must not be run on our own 2319122f46baSDaniel Vetter * dev-priv->wq work queue for otherwise the flush_work in the pageflip 2320122f46baSDaniel Vetter * code will deadlock. 2321122f46baSDaniel Vetter */ 2322122f46baSDaniel Vetter schedule_work(&dev_priv->gpu_error.work); 23238a905236SJesse Barnes } 23248a905236SJesse Barnes 232521ad8330SVille Syrjälä static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe) 23264e5359cdSSimon Farnsworth { 23274e5359cdSSimon Farnsworth drm_i915_private_t *dev_priv = dev->dev_private; 23284e5359cdSSimon Farnsworth struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 23294e5359cdSSimon Farnsworth struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 233005394f39SChris Wilson struct drm_i915_gem_object *obj; 23314e5359cdSSimon Farnsworth struct intel_unpin_work *work; 23324e5359cdSSimon Farnsworth unsigned long flags; 23334e5359cdSSimon Farnsworth bool stall_detected; 23344e5359cdSSimon Farnsworth 23354e5359cdSSimon Farnsworth /* Ignore early vblank irqs */ 23364e5359cdSSimon Farnsworth if (intel_crtc == NULL) 23374e5359cdSSimon Farnsworth return; 23384e5359cdSSimon Farnsworth 23394e5359cdSSimon Farnsworth spin_lock_irqsave(&dev->event_lock, flags); 23404e5359cdSSimon Farnsworth work = intel_crtc->unpin_work; 23414e5359cdSSimon Farnsworth 2342e7d841caSChris Wilson if (work == NULL || 2343e7d841caSChris Wilson atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE || 2344e7d841caSChris Wilson !work->enable_stall_check) { 23454e5359cdSSimon Farnsworth /* Either the pending flip IRQ arrived, or we're too early. Don't check */ 23464e5359cdSSimon Farnsworth spin_unlock_irqrestore(&dev->event_lock, flags); 23474e5359cdSSimon Farnsworth return; 23484e5359cdSSimon Farnsworth } 23494e5359cdSSimon Farnsworth 23504e5359cdSSimon Farnsworth /* Potential stall - if we see that the flip has happened, assume a missed interrupt */ 235105394f39SChris Wilson obj = work->pending_flip_obj; 2352a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen >= 4) { 23539db4a9c7SJesse Barnes int dspsurf = DSPSURF(intel_crtc->plane); 2354446f2545SArmin Reese stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) == 2355f343c5f6SBen Widawsky i915_gem_obj_ggtt_offset(obj); 23564e5359cdSSimon Farnsworth } else { 23579db4a9c7SJesse Barnes int dspaddr = DSPADDR(intel_crtc->plane); 2358f343c5f6SBen Widawsky stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) + 235901f2c773SVille Syrjälä crtc->y * crtc->fb->pitches[0] + 23604e5359cdSSimon Farnsworth crtc->x * crtc->fb->bits_per_pixel/8); 23614e5359cdSSimon Farnsworth } 23624e5359cdSSimon Farnsworth 23634e5359cdSSimon Farnsworth spin_unlock_irqrestore(&dev->event_lock, flags); 23644e5359cdSSimon Farnsworth 23654e5359cdSSimon Farnsworth if (stall_detected) { 23664e5359cdSSimon Farnsworth DRM_DEBUG_DRIVER("Pageflip stall detected\n"); 23674e5359cdSSimon Farnsworth intel_prepare_page_flip(dev, intel_crtc->plane); 23684e5359cdSSimon Farnsworth } 23694e5359cdSSimon Farnsworth } 23704e5359cdSSimon Farnsworth 237142f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 237242f52ef8SKeith Packard * we use as a pipe index 237342f52ef8SKeith Packard */ 2374f71d4af4SJesse Barnes static int i915_enable_vblank(struct drm_device *dev, int pipe) 23750a3e67a4SJesse Barnes { 23760a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2377e9d21d7fSKeith Packard unsigned long irqflags; 237871e0ffa5SJesse Barnes 23795eddb70bSChris Wilson if (!i915_pipe_enabled(dev, pipe)) 238071e0ffa5SJesse Barnes return -EINVAL; 23810a3e67a4SJesse Barnes 23821ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2383f796cf8fSJesse Barnes if (INTEL_INFO(dev)->gen >= 4) 23847c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 2385755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 23860a3e67a4SJesse Barnes else 23877c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 2388755e9019SImre Deak PIPE_VBLANK_INTERRUPT_STATUS); 23898692d00eSChris Wilson 23908692d00eSChris Wilson /* maintain vblank delivery even in deep C-states */ 23913d13ef2eSDamien Lespiau if (INTEL_INFO(dev)->gen == 3) 23926b26c86dSDaniel Vetter I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS)); 23931ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 23948692d00eSChris Wilson 23950a3e67a4SJesse Barnes return 0; 23960a3e67a4SJesse Barnes } 23970a3e67a4SJesse Barnes 2398f71d4af4SJesse Barnes static int ironlake_enable_vblank(struct drm_device *dev, int pipe) 2399f796cf8fSJesse Barnes { 2400f796cf8fSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2401f796cf8fSJesse Barnes unsigned long irqflags; 2402b518421fSPaulo Zanoni uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) : 240340da17c2SDaniel Vetter DE_PIPE_VBLANK(pipe); 2404f796cf8fSJesse Barnes 2405f796cf8fSJesse Barnes if (!i915_pipe_enabled(dev, pipe)) 2406f796cf8fSJesse Barnes return -EINVAL; 2407f796cf8fSJesse Barnes 2408f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2409b518421fSPaulo Zanoni ironlake_enable_display_irq(dev_priv, bit); 2410b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2411b1f14ad0SJesse Barnes 2412b1f14ad0SJesse Barnes return 0; 2413b1f14ad0SJesse Barnes } 2414b1f14ad0SJesse Barnes 24157e231dbeSJesse Barnes static int valleyview_enable_vblank(struct drm_device *dev, int pipe) 24167e231dbeSJesse Barnes { 24177e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 24187e231dbeSJesse Barnes unsigned long irqflags; 24197e231dbeSJesse Barnes 24207e231dbeSJesse Barnes if (!i915_pipe_enabled(dev, pipe)) 24217e231dbeSJesse Barnes return -EINVAL; 24227e231dbeSJesse Barnes 24237e231dbeSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 242431acc7f5SJesse Barnes i915_enable_pipestat(dev_priv, pipe, 2425755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 24267e231dbeSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 24277e231dbeSJesse Barnes 24287e231dbeSJesse Barnes return 0; 24297e231dbeSJesse Barnes } 24307e231dbeSJesse Barnes 2431abd58f01SBen Widawsky static int gen8_enable_vblank(struct drm_device *dev, int pipe) 2432abd58f01SBen Widawsky { 2433abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 2434abd58f01SBen Widawsky unsigned long irqflags; 2435abd58f01SBen Widawsky 2436abd58f01SBen Widawsky if (!i915_pipe_enabled(dev, pipe)) 2437abd58f01SBen Widawsky return -EINVAL; 2438abd58f01SBen Widawsky 2439abd58f01SBen Widawsky spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 24407167d7c6SDaniel Vetter dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK; 24417167d7c6SDaniel Vetter I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]); 2442abd58f01SBen Widawsky POSTING_READ(GEN8_DE_PIPE_IMR(pipe)); 2443abd58f01SBen Widawsky spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2444abd58f01SBen Widawsky return 0; 2445abd58f01SBen Widawsky } 2446abd58f01SBen Widawsky 244742f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 244842f52ef8SKeith Packard * we use as a pipe index 244942f52ef8SKeith Packard */ 2450f71d4af4SJesse Barnes static void i915_disable_vblank(struct drm_device *dev, int pipe) 24510a3e67a4SJesse Barnes { 24520a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2453e9d21d7fSKeith Packard unsigned long irqflags; 24540a3e67a4SJesse Barnes 24551ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 24563d13ef2eSDamien Lespiau if (INTEL_INFO(dev)->gen == 3) 24576b26c86dSDaniel Vetter I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS)); 24588692d00eSChris Wilson 24597c463586SKeith Packard i915_disable_pipestat(dev_priv, pipe, 2460755e9019SImre Deak PIPE_VBLANK_INTERRUPT_STATUS | 2461755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 24621ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 24630a3e67a4SJesse Barnes } 24640a3e67a4SJesse Barnes 2465f71d4af4SJesse Barnes static void ironlake_disable_vblank(struct drm_device *dev, int pipe) 2466f796cf8fSJesse Barnes { 2467f796cf8fSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2468f796cf8fSJesse Barnes unsigned long irqflags; 2469b518421fSPaulo Zanoni uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) : 247040da17c2SDaniel Vetter DE_PIPE_VBLANK(pipe); 2471f796cf8fSJesse Barnes 2472f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2473b518421fSPaulo Zanoni ironlake_disable_display_irq(dev_priv, bit); 2474b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2475b1f14ad0SJesse Barnes } 2476b1f14ad0SJesse Barnes 24777e231dbeSJesse Barnes static void valleyview_disable_vblank(struct drm_device *dev, int pipe) 24787e231dbeSJesse Barnes { 24797e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 24807e231dbeSJesse Barnes unsigned long irqflags; 24817e231dbeSJesse Barnes 24827e231dbeSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 248331acc7f5SJesse Barnes i915_disable_pipestat(dev_priv, pipe, 2484755e9019SImre Deak PIPE_START_VBLANK_INTERRUPT_STATUS); 24857e231dbeSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 24867e231dbeSJesse Barnes } 24877e231dbeSJesse Barnes 2488abd58f01SBen Widawsky static void gen8_disable_vblank(struct drm_device *dev, int pipe) 2489abd58f01SBen Widawsky { 2490abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 2491abd58f01SBen Widawsky unsigned long irqflags; 2492abd58f01SBen Widawsky 2493abd58f01SBen Widawsky if (!i915_pipe_enabled(dev, pipe)) 2494abd58f01SBen Widawsky return; 2495abd58f01SBen Widawsky 2496abd58f01SBen Widawsky spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 24977167d7c6SDaniel Vetter dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK; 24987167d7c6SDaniel Vetter I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]); 2499abd58f01SBen Widawsky POSTING_READ(GEN8_DE_PIPE_IMR(pipe)); 2500abd58f01SBen Widawsky spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2501abd58f01SBen Widawsky } 2502abd58f01SBen Widawsky 2503893eead0SChris Wilson static u32 2504893eead0SChris Wilson ring_last_seqno(struct intel_ring_buffer *ring) 2505852835f3SZou Nan hai { 2506893eead0SChris Wilson return list_entry(ring->request_list.prev, 2507893eead0SChris Wilson struct drm_i915_gem_request, list)->seqno; 2508893eead0SChris Wilson } 2509893eead0SChris Wilson 25109107e9d2SChris Wilson static bool 25119107e9d2SChris Wilson ring_idle(struct intel_ring_buffer *ring, u32 seqno) 2512893eead0SChris Wilson { 25139107e9d2SChris Wilson return (list_empty(&ring->request_list) || 25149107e9d2SChris Wilson i915_seqno_passed(seqno, ring_last_seqno(ring))); 2515f65d9421SBen Gamari } 2516f65d9421SBen Gamari 25176274f212SChris Wilson static struct intel_ring_buffer * 25186274f212SChris Wilson semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno) 2519a24a11e6SChris Wilson { 2520a24a11e6SChris Wilson struct drm_i915_private *dev_priv = ring->dev->dev_private; 25216274f212SChris Wilson u32 cmd, ipehr, acthd, acthd_min; 2522a24a11e6SChris Wilson 2523a24a11e6SChris Wilson ipehr = I915_READ(RING_IPEHR(ring->mmio_base)); 2524a24a11e6SChris Wilson if ((ipehr & ~(0x3 << 16)) != 2525a24a11e6SChris Wilson (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER)) 25266274f212SChris Wilson return NULL; 2527a24a11e6SChris Wilson 2528a24a11e6SChris Wilson /* ACTHD is likely pointing to the dword after the actual command, 2529a24a11e6SChris Wilson * so scan backwards until we find the MBOX. 2530a24a11e6SChris Wilson */ 25316274f212SChris Wilson acthd = intel_ring_get_active_head(ring) & HEAD_ADDR; 2532a24a11e6SChris Wilson acthd_min = max((int)acthd - 3 * 4, 0); 2533a24a11e6SChris Wilson do { 2534a24a11e6SChris Wilson cmd = ioread32(ring->virtual_start + acthd); 2535a24a11e6SChris Wilson if (cmd == ipehr) 2536a24a11e6SChris Wilson break; 2537a24a11e6SChris Wilson 2538a24a11e6SChris Wilson acthd -= 4; 2539a24a11e6SChris Wilson if (acthd < acthd_min) 25406274f212SChris Wilson return NULL; 2541a24a11e6SChris Wilson } while (1); 2542a24a11e6SChris Wilson 25436274f212SChris Wilson *seqno = ioread32(ring->virtual_start+acthd+4)+1; 25446274f212SChris Wilson return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3]; 2545a24a11e6SChris Wilson } 2546a24a11e6SChris Wilson 25476274f212SChris Wilson static int semaphore_passed(struct intel_ring_buffer *ring) 25486274f212SChris Wilson { 25496274f212SChris Wilson struct drm_i915_private *dev_priv = ring->dev->dev_private; 25506274f212SChris Wilson struct intel_ring_buffer *signaller; 25516274f212SChris Wilson u32 seqno, ctl; 25526274f212SChris Wilson 25536274f212SChris Wilson ring->hangcheck.deadlock = true; 25546274f212SChris Wilson 25556274f212SChris Wilson signaller = semaphore_waits_for(ring, &seqno); 25566274f212SChris Wilson if (signaller == NULL || signaller->hangcheck.deadlock) 25576274f212SChris Wilson return -1; 25586274f212SChris Wilson 25596274f212SChris Wilson /* cursory check for an unkickable deadlock */ 25606274f212SChris Wilson ctl = I915_READ_CTL(signaller); 25616274f212SChris Wilson if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0) 25626274f212SChris Wilson return -1; 25636274f212SChris Wilson 25646274f212SChris Wilson return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno); 25656274f212SChris Wilson } 25666274f212SChris Wilson 25676274f212SChris Wilson static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv) 25686274f212SChris Wilson { 25696274f212SChris Wilson struct intel_ring_buffer *ring; 25706274f212SChris Wilson int i; 25716274f212SChris Wilson 25726274f212SChris Wilson for_each_ring(ring, dev_priv, i) 25736274f212SChris Wilson ring->hangcheck.deadlock = false; 25746274f212SChris Wilson } 25756274f212SChris Wilson 2576ad8beaeaSMika Kuoppala static enum intel_ring_hangcheck_action 2577ad8beaeaSMika Kuoppala ring_stuck(struct intel_ring_buffer *ring, u32 acthd) 25781ec14ad3SChris Wilson { 25791ec14ad3SChris Wilson struct drm_device *dev = ring->dev; 25801ec14ad3SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 25819107e9d2SChris Wilson u32 tmp; 25829107e9d2SChris Wilson 25836274f212SChris Wilson if (ring->hangcheck.acthd != acthd) 2584f2f4d82fSJani Nikula return HANGCHECK_ACTIVE; 25856274f212SChris Wilson 25869107e9d2SChris Wilson if (IS_GEN2(dev)) 2587f2f4d82fSJani Nikula return HANGCHECK_HUNG; 25889107e9d2SChris Wilson 25899107e9d2SChris Wilson /* Is the chip hanging on a WAIT_FOR_EVENT? 25909107e9d2SChris Wilson * If so we can simply poke the RB_WAIT bit 25919107e9d2SChris Wilson * and break the hang. This should work on 25929107e9d2SChris Wilson * all but the second generation chipsets. 25939107e9d2SChris Wilson */ 25949107e9d2SChris Wilson tmp = I915_READ_CTL(ring); 25951ec14ad3SChris Wilson if (tmp & RING_WAIT) { 2596*58174462SMika Kuoppala i915_handle_error(dev, false, 2597*58174462SMika Kuoppala "Kicking stuck wait on %s", 25981ec14ad3SChris Wilson ring->name); 25991ec14ad3SChris Wilson I915_WRITE_CTL(ring, tmp); 2600f2f4d82fSJani Nikula return HANGCHECK_KICK; 26011ec14ad3SChris Wilson } 2602a24a11e6SChris Wilson 26036274f212SChris Wilson if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) { 26046274f212SChris Wilson switch (semaphore_passed(ring)) { 26056274f212SChris Wilson default: 2606f2f4d82fSJani Nikula return HANGCHECK_HUNG; 26076274f212SChris Wilson case 1: 2608*58174462SMika Kuoppala i915_handle_error(dev, false, 2609*58174462SMika Kuoppala "Kicking stuck semaphore on %s", 2610a24a11e6SChris Wilson ring->name); 2611a24a11e6SChris Wilson I915_WRITE_CTL(ring, tmp); 2612f2f4d82fSJani Nikula return HANGCHECK_KICK; 26136274f212SChris Wilson case 0: 2614f2f4d82fSJani Nikula return HANGCHECK_WAIT; 26156274f212SChris Wilson } 26169107e9d2SChris Wilson } 26179107e9d2SChris Wilson 2618f2f4d82fSJani Nikula return HANGCHECK_HUNG; 2619a24a11e6SChris Wilson } 2620d1e61e7fSChris Wilson 2621f65d9421SBen Gamari /** 2622f65d9421SBen Gamari * This is called when the chip hasn't reported back with completed 262305407ff8SMika Kuoppala * batchbuffers in a long time. We keep track per ring seqno progress and 262405407ff8SMika Kuoppala * if there are no progress, hangcheck score for that ring is increased. 262505407ff8SMika Kuoppala * Further, acthd is inspected to see if the ring is stuck. On stuck case 262605407ff8SMika Kuoppala * we kick the ring. If we see no progress on three subsequent calls 262705407ff8SMika Kuoppala * we assume chip is wedged and try to fix it by resetting the chip. 2628f65d9421SBen Gamari */ 2629a658b5d2SDamien Lespiau static void i915_hangcheck_elapsed(unsigned long data) 2630f65d9421SBen Gamari { 2631f65d9421SBen Gamari struct drm_device *dev = (struct drm_device *)data; 2632f65d9421SBen Gamari drm_i915_private_t *dev_priv = dev->dev_private; 2633b4519513SChris Wilson struct intel_ring_buffer *ring; 2634b4519513SChris Wilson int i; 263505407ff8SMika Kuoppala int busy_count = 0, rings_hung = 0; 26369107e9d2SChris Wilson bool stuck[I915_NUM_RINGS] = { 0 }; 26379107e9d2SChris Wilson #define BUSY 1 26389107e9d2SChris Wilson #define KICK 5 26399107e9d2SChris Wilson #define HUNG 20 2640893eead0SChris Wilson 2641d330a953SJani Nikula if (!i915.enable_hangcheck) 26423e0dc6b0SBen Widawsky return; 26433e0dc6b0SBen Widawsky 2644b4519513SChris Wilson for_each_ring(ring, dev_priv, i) { 264505407ff8SMika Kuoppala u32 seqno, acthd; 26469107e9d2SChris Wilson bool busy = true; 2647b4519513SChris Wilson 26486274f212SChris Wilson semaphore_clear_deadlocks(dev_priv); 26496274f212SChris Wilson 265005407ff8SMika Kuoppala seqno = ring->get_seqno(ring, false); 265105407ff8SMika Kuoppala acthd = intel_ring_get_active_head(ring); 265205407ff8SMika Kuoppala 265305407ff8SMika Kuoppala if (ring->hangcheck.seqno == seqno) { 26549107e9d2SChris Wilson if (ring_idle(ring, seqno)) { 2655da661464SMika Kuoppala ring->hangcheck.action = HANGCHECK_IDLE; 2656da661464SMika Kuoppala 26579107e9d2SChris Wilson if (waitqueue_active(&ring->irq_queue)) { 26589107e9d2SChris Wilson /* Issue a wake-up to catch stuck h/w. */ 2659094f9a54SChris Wilson if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) { 2660f4adcd24SDaniel Vetter if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring))) 26619107e9d2SChris Wilson DRM_ERROR("Hangcheck timer elapsed... %s idle\n", 26629107e9d2SChris Wilson ring->name); 2663f4adcd24SDaniel Vetter else 2664f4adcd24SDaniel Vetter DRM_INFO("Fake missed irq on %s\n", 2665f4adcd24SDaniel Vetter ring->name); 26669107e9d2SChris Wilson wake_up_all(&ring->irq_queue); 2667094f9a54SChris Wilson } 2668094f9a54SChris Wilson /* Safeguard against driver failure */ 2669094f9a54SChris Wilson ring->hangcheck.score += BUSY; 26709107e9d2SChris Wilson } else 26719107e9d2SChris Wilson busy = false; 267205407ff8SMika Kuoppala } else { 26736274f212SChris Wilson /* We always increment the hangcheck score 26746274f212SChris Wilson * if the ring is busy and still processing 26756274f212SChris Wilson * the same request, so that no single request 26766274f212SChris Wilson * can run indefinitely (such as a chain of 26776274f212SChris Wilson * batches). The only time we do not increment 26786274f212SChris Wilson * the hangcheck score on this ring, if this 26796274f212SChris Wilson * ring is in a legitimate wait for another 26806274f212SChris Wilson * ring. In that case the waiting ring is a 26816274f212SChris Wilson * victim and we want to be sure we catch the 26826274f212SChris Wilson * right culprit. Then every time we do kick 26836274f212SChris Wilson * the ring, add a small increment to the 26846274f212SChris Wilson * score so that we can catch a batch that is 26856274f212SChris Wilson * being repeatedly kicked and so responsible 26866274f212SChris Wilson * for stalling the machine. 26879107e9d2SChris Wilson */ 2688ad8beaeaSMika Kuoppala ring->hangcheck.action = ring_stuck(ring, 2689ad8beaeaSMika Kuoppala acthd); 2690ad8beaeaSMika Kuoppala 2691ad8beaeaSMika Kuoppala switch (ring->hangcheck.action) { 2692da661464SMika Kuoppala case HANGCHECK_IDLE: 2693f2f4d82fSJani Nikula case HANGCHECK_WAIT: 26946274f212SChris Wilson break; 2695f2f4d82fSJani Nikula case HANGCHECK_ACTIVE: 2696ea04cb31SJani Nikula ring->hangcheck.score += BUSY; 26976274f212SChris Wilson break; 2698f2f4d82fSJani Nikula case HANGCHECK_KICK: 2699ea04cb31SJani Nikula ring->hangcheck.score += KICK; 27006274f212SChris Wilson break; 2701f2f4d82fSJani Nikula case HANGCHECK_HUNG: 2702ea04cb31SJani Nikula ring->hangcheck.score += HUNG; 27036274f212SChris Wilson stuck[i] = true; 27046274f212SChris Wilson break; 27056274f212SChris Wilson } 270605407ff8SMika Kuoppala } 27079107e9d2SChris Wilson } else { 2708da661464SMika Kuoppala ring->hangcheck.action = HANGCHECK_ACTIVE; 2709da661464SMika Kuoppala 27109107e9d2SChris Wilson /* Gradually reduce the count so that we catch DoS 27119107e9d2SChris Wilson * attempts across multiple batches. 27129107e9d2SChris Wilson */ 27139107e9d2SChris Wilson if (ring->hangcheck.score > 0) 27149107e9d2SChris Wilson ring->hangcheck.score--; 2715cbb465e7SChris Wilson } 2716f65d9421SBen Gamari 271705407ff8SMika Kuoppala ring->hangcheck.seqno = seqno; 271805407ff8SMika Kuoppala ring->hangcheck.acthd = acthd; 27199107e9d2SChris Wilson busy_count += busy; 272005407ff8SMika Kuoppala } 272105407ff8SMika Kuoppala 272205407ff8SMika Kuoppala for_each_ring(ring, dev_priv, i) { 2723b6b0fac0SMika Kuoppala if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) { 2724b8d88d1dSDaniel Vetter DRM_INFO("%s on %s\n", 272505407ff8SMika Kuoppala stuck[i] ? "stuck" : "no progress", 2726a43adf07SChris Wilson ring->name); 2727a43adf07SChris Wilson rings_hung++; 272805407ff8SMika Kuoppala } 272905407ff8SMika Kuoppala } 273005407ff8SMika Kuoppala 273105407ff8SMika Kuoppala if (rings_hung) 2732*58174462SMika Kuoppala return i915_handle_error(dev, true, "Ring hung"); 273305407ff8SMika Kuoppala 273405407ff8SMika Kuoppala if (busy_count) 273505407ff8SMika Kuoppala /* Reset timer case chip hangs without another request 273605407ff8SMika Kuoppala * being added */ 273710cd45b6SMika Kuoppala i915_queue_hangcheck(dev); 273810cd45b6SMika Kuoppala } 273910cd45b6SMika Kuoppala 274010cd45b6SMika Kuoppala void i915_queue_hangcheck(struct drm_device *dev) 274110cd45b6SMika Kuoppala { 274210cd45b6SMika Kuoppala struct drm_i915_private *dev_priv = dev->dev_private; 2743d330a953SJani Nikula if (!i915.enable_hangcheck) 274410cd45b6SMika Kuoppala return; 274510cd45b6SMika Kuoppala 274699584db3SDaniel Vetter mod_timer(&dev_priv->gpu_error.hangcheck_timer, 274710cd45b6SMika Kuoppala round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES)); 2748f65d9421SBen Gamari } 2749f65d9421SBen Gamari 275091738a95SPaulo Zanoni static void ibx_irq_preinstall(struct drm_device *dev) 275191738a95SPaulo Zanoni { 275291738a95SPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 275391738a95SPaulo Zanoni 275491738a95SPaulo Zanoni if (HAS_PCH_NOP(dev)) 275591738a95SPaulo Zanoni return; 275691738a95SPaulo Zanoni 275791738a95SPaulo Zanoni /* south display irq */ 275891738a95SPaulo Zanoni I915_WRITE(SDEIMR, 0xffffffff); 275991738a95SPaulo Zanoni /* 276091738a95SPaulo Zanoni * SDEIER is also touched by the interrupt handler to work around missed 276191738a95SPaulo Zanoni * PCH interrupts. Hence we can't update it after the interrupt handler 276291738a95SPaulo Zanoni * is enabled - instead we unconditionally enable all PCH interrupt 276391738a95SPaulo Zanoni * sources here, but then only unmask them as needed with SDEIMR. 276491738a95SPaulo Zanoni */ 276591738a95SPaulo Zanoni I915_WRITE(SDEIER, 0xffffffff); 276691738a95SPaulo Zanoni POSTING_READ(SDEIER); 276791738a95SPaulo Zanoni } 276891738a95SPaulo Zanoni 2769d18ea1b5SDaniel Vetter static void gen5_gt_irq_preinstall(struct drm_device *dev) 2770d18ea1b5SDaniel Vetter { 2771d18ea1b5SDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 2772d18ea1b5SDaniel Vetter 2773d18ea1b5SDaniel Vetter /* and GT */ 2774d18ea1b5SDaniel Vetter I915_WRITE(GTIMR, 0xffffffff); 2775d18ea1b5SDaniel Vetter I915_WRITE(GTIER, 0x0); 2776d18ea1b5SDaniel Vetter POSTING_READ(GTIER); 2777d18ea1b5SDaniel Vetter 2778d18ea1b5SDaniel Vetter if (INTEL_INFO(dev)->gen >= 6) { 2779d18ea1b5SDaniel Vetter /* and PM */ 2780d18ea1b5SDaniel Vetter I915_WRITE(GEN6_PMIMR, 0xffffffff); 2781d18ea1b5SDaniel Vetter I915_WRITE(GEN6_PMIER, 0x0); 2782d18ea1b5SDaniel Vetter POSTING_READ(GEN6_PMIER); 2783d18ea1b5SDaniel Vetter } 2784d18ea1b5SDaniel Vetter } 2785d18ea1b5SDaniel Vetter 2786c0e09200SDave Airlie /* drm_dma.h hooks 2787c0e09200SDave Airlie */ 2788f71d4af4SJesse Barnes static void ironlake_irq_preinstall(struct drm_device *dev) 2789036a4a7dSZhenyu Wang { 2790036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2791036a4a7dSZhenyu Wang 2792036a4a7dSZhenyu Wang I915_WRITE(HWSTAM, 0xeffe); 2793bdfcdb63SDaniel Vetter 2794036a4a7dSZhenyu Wang I915_WRITE(DEIMR, 0xffffffff); 2795036a4a7dSZhenyu Wang I915_WRITE(DEIER, 0x0); 27963143a2bfSChris Wilson POSTING_READ(DEIER); 2797036a4a7dSZhenyu Wang 2798d18ea1b5SDaniel Vetter gen5_gt_irq_preinstall(dev); 2799c650156aSZhenyu Wang 280091738a95SPaulo Zanoni ibx_irq_preinstall(dev); 28017d99163dSBen Widawsky } 28027d99163dSBen Widawsky 28037e231dbeSJesse Barnes static void valleyview_irq_preinstall(struct drm_device *dev) 28047e231dbeSJesse Barnes { 28057e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 28067e231dbeSJesse Barnes int pipe; 28077e231dbeSJesse Barnes 28087e231dbeSJesse Barnes /* VLV magic */ 28097e231dbeSJesse Barnes I915_WRITE(VLV_IMR, 0); 28107e231dbeSJesse Barnes I915_WRITE(RING_IMR(RENDER_RING_BASE), 0); 28117e231dbeSJesse Barnes I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0); 28127e231dbeSJesse Barnes I915_WRITE(RING_IMR(BLT_RING_BASE), 0); 28137e231dbeSJesse Barnes 28147e231dbeSJesse Barnes /* and GT */ 28157e231dbeSJesse Barnes I915_WRITE(GTIIR, I915_READ(GTIIR)); 28167e231dbeSJesse Barnes I915_WRITE(GTIIR, I915_READ(GTIIR)); 2817d18ea1b5SDaniel Vetter 2818d18ea1b5SDaniel Vetter gen5_gt_irq_preinstall(dev); 28197e231dbeSJesse Barnes 28207e231dbeSJesse Barnes I915_WRITE(DPINVGTT, 0xff); 28217e231dbeSJesse Barnes 28227e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_EN, 0); 28237e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 28247e231dbeSJesse Barnes for_each_pipe(pipe) 28257e231dbeSJesse Barnes I915_WRITE(PIPESTAT(pipe), 0xffff); 28267e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 28277e231dbeSJesse Barnes I915_WRITE(VLV_IMR, 0xffffffff); 28287e231dbeSJesse Barnes I915_WRITE(VLV_IER, 0x0); 28297e231dbeSJesse Barnes POSTING_READ(VLV_IER); 28307e231dbeSJesse Barnes } 28317e231dbeSJesse Barnes 2832abd58f01SBen Widawsky static void gen8_irq_preinstall(struct drm_device *dev) 2833abd58f01SBen Widawsky { 2834abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 2835abd58f01SBen Widawsky int pipe; 2836abd58f01SBen Widawsky 2837abd58f01SBen Widawsky I915_WRITE(GEN8_MASTER_IRQ, 0); 2838abd58f01SBen Widawsky POSTING_READ(GEN8_MASTER_IRQ); 2839abd58f01SBen Widawsky 2840abd58f01SBen Widawsky /* IIR can theoretically queue up two events. Be paranoid */ 2841abd58f01SBen Widawsky #define GEN8_IRQ_INIT_NDX(type, which) do { \ 2842abd58f01SBen Widawsky I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \ 2843abd58f01SBen Widawsky POSTING_READ(GEN8_##type##_IMR(which)); \ 2844abd58f01SBen Widawsky I915_WRITE(GEN8_##type##_IER(which), 0); \ 2845abd58f01SBen Widawsky I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \ 2846abd58f01SBen Widawsky POSTING_READ(GEN8_##type##_IIR(which)); \ 2847abd58f01SBen Widawsky I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \ 2848abd58f01SBen Widawsky } while (0) 2849abd58f01SBen Widawsky 2850abd58f01SBen Widawsky #define GEN8_IRQ_INIT(type) do { \ 2851abd58f01SBen Widawsky I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \ 2852abd58f01SBen Widawsky POSTING_READ(GEN8_##type##_IMR); \ 2853abd58f01SBen Widawsky I915_WRITE(GEN8_##type##_IER, 0); \ 2854abd58f01SBen Widawsky I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \ 2855abd58f01SBen Widawsky POSTING_READ(GEN8_##type##_IIR); \ 2856abd58f01SBen Widawsky I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \ 2857abd58f01SBen Widawsky } while (0) 2858abd58f01SBen Widawsky 2859abd58f01SBen Widawsky GEN8_IRQ_INIT_NDX(GT, 0); 2860abd58f01SBen Widawsky GEN8_IRQ_INIT_NDX(GT, 1); 2861abd58f01SBen Widawsky GEN8_IRQ_INIT_NDX(GT, 2); 2862abd58f01SBen Widawsky GEN8_IRQ_INIT_NDX(GT, 3); 2863abd58f01SBen Widawsky 2864abd58f01SBen Widawsky for_each_pipe(pipe) { 2865abd58f01SBen Widawsky GEN8_IRQ_INIT_NDX(DE_PIPE, pipe); 2866abd58f01SBen Widawsky } 2867abd58f01SBen Widawsky 2868abd58f01SBen Widawsky GEN8_IRQ_INIT(DE_PORT); 2869abd58f01SBen Widawsky GEN8_IRQ_INIT(DE_MISC); 2870abd58f01SBen Widawsky GEN8_IRQ_INIT(PCU); 2871abd58f01SBen Widawsky #undef GEN8_IRQ_INIT 2872abd58f01SBen Widawsky #undef GEN8_IRQ_INIT_NDX 2873abd58f01SBen Widawsky 2874abd58f01SBen Widawsky POSTING_READ(GEN8_PCU_IIR); 287509f2344dSJesse Barnes 287609f2344dSJesse Barnes ibx_irq_preinstall(dev); 2877abd58f01SBen Widawsky } 2878abd58f01SBen Widawsky 287982a28bcfSDaniel Vetter static void ibx_hpd_irq_setup(struct drm_device *dev) 288082a28bcfSDaniel Vetter { 288182a28bcfSDaniel Vetter drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 288282a28bcfSDaniel Vetter struct drm_mode_config *mode_config = &dev->mode_config; 288382a28bcfSDaniel Vetter struct intel_encoder *intel_encoder; 2884fee884edSDaniel Vetter u32 hotplug_irqs, hotplug, enabled_irqs = 0; 288582a28bcfSDaniel Vetter 288682a28bcfSDaniel Vetter if (HAS_PCH_IBX(dev)) { 2887fee884edSDaniel Vetter hotplug_irqs = SDE_HOTPLUG_MASK; 288882a28bcfSDaniel Vetter list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head) 2889cd569aedSEgbert Eich if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) 2890fee884edSDaniel Vetter enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin]; 289182a28bcfSDaniel Vetter } else { 2892fee884edSDaniel Vetter hotplug_irqs = SDE_HOTPLUG_MASK_CPT; 289382a28bcfSDaniel Vetter list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head) 2894cd569aedSEgbert Eich if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) 2895fee884edSDaniel Vetter enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin]; 289682a28bcfSDaniel Vetter } 289782a28bcfSDaniel Vetter 2898fee884edSDaniel Vetter ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); 289982a28bcfSDaniel Vetter 29007fe0b973SKeith Packard /* 29017fe0b973SKeith Packard * Enable digital hotplug on the PCH, and configure the DP short pulse 29027fe0b973SKeith Packard * duration to 2ms (which is the minimum in the Display Port spec) 29037fe0b973SKeith Packard * 29047fe0b973SKeith Packard * This register is the same on all known PCH chips. 29057fe0b973SKeith Packard */ 29067fe0b973SKeith Packard hotplug = I915_READ(PCH_PORT_HOTPLUG); 29077fe0b973SKeith Packard hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK); 29087fe0b973SKeith Packard hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms; 29097fe0b973SKeith Packard hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms; 29107fe0b973SKeith Packard hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms; 29117fe0b973SKeith Packard I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 29127fe0b973SKeith Packard } 29137fe0b973SKeith Packard 2914d46da437SPaulo Zanoni static void ibx_irq_postinstall(struct drm_device *dev) 2915d46da437SPaulo Zanoni { 2916d46da437SPaulo Zanoni drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 291782a28bcfSDaniel Vetter u32 mask; 2918d46da437SPaulo Zanoni 2919692a04cfSDaniel Vetter if (HAS_PCH_NOP(dev)) 2920692a04cfSDaniel Vetter return; 2921692a04cfSDaniel Vetter 29228664281bSPaulo Zanoni if (HAS_PCH_IBX(dev)) { 29238664281bSPaulo Zanoni mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER | 2924de032bf4SPaulo Zanoni SDE_TRANSA_FIFO_UNDER | SDE_POISON; 29258664281bSPaulo Zanoni } else { 29268664281bSPaulo Zanoni mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT; 29278664281bSPaulo Zanoni 29288664281bSPaulo Zanoni I915_WRITE(SERR_INT, I915_READ(SERR_INT)); 29298664281bSPaulo Zanoni } 2930ab5c608bSBen Widawsky 2931d46da437SPaulo Zanoni I915_WRITE(SDEIIR, I915_READ(SDEIIR)); 2932d46da437SPaulo Zanoni I915_WRITE(SDEIMR, ~mask); 2933d46da437SPaulo Zanoni } 2934d46da437SPaulo Zanoni 29350a9a8c91SDaniel Vetter static void gen5_gt_irq_postinstall(struct drm_device *dev) 29360a9a8c91SDaniel Vetter { 29370a9a8c91SDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 29380a9a8c91SDaniel Vetter u32 pm_irqs, gt_irqs; 29390a9a8c91SDaniel Vetter 29400a9a8c91SDaniel Vetter pm_irqs = gt_irqs = 0; 29410a9a8c91SDaniel Vetter 29420a9a8c91SDaniel Vetter dev_priv->gt_irq_mask = ~0; 2943040d2baaSBen Widawsky if (HAS_L3_DPF(dev)) { 29440a9a8c91SDaniel Vetter /* L3 parity interrupt is always unmasked. */ 294535a85ac6SBen Widawsky dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev); 294635a85ac6SBen Widawsky gt_irqs |= GT_PARITY_ERROR(dev); 29470a9a8c91SDaniel Vetter } 29480a9a8c91SDaniel Vetter 29490a9a8c91SDaniel Vetter gt_irqs |= GT_RENDER_USER_INTERRUPT; 29500a9a8c91SDaniel Vetter if (IS_GEN5(dev)) { 29510a9a8c91SDaniel Vetter gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT | 29520a9a8c91SDaniel Vetter ILK_BSD_USER_INTERRUPT; 29530a9a8c91SDaniel Vetter } else { 29540a9a8c91SDaniel Vetter gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT; 29550a9a8c91SDaniel Vetter } 29560a9a8c91SDaniel Vetter 29570a9a8c91SDaniel Vetter I915_WRITE(GTIIR, I915_READ(GTIIR)); 29580a9a8c91SDaniel Vetter I915_WRITE(GTIMR, dev_priv->gt_irq_mask); 29590a9a8c91SDaniel Vetter I915_WRITE(GTIER, gt_irqs); 29600a9a8c91SDaniel Vetter POSTING_READ(GTIER); 29610a9a8c91SDaniel Vetter 29620a9a8c91SDaniel Vetter if (INTEL_INFO(dev)->gen >= 6) { 29630a9a8c91SDaniel Vetter pm_irqs |= GEN6_PM_RPS_EVENTS; 29640a9a8c91SDaniel Vetter 29650a9a8c91SDaniel Vetter if (HAS_VEBOX(dev)) 29660a9a8c91SDaniel Vetter pm_irqs |= PM_VEBOX_USER_INTERRUPT; 29670a9a8c91SDaniel Vetter 2968605cd25bSPaulo Zanoni dev_priv->pm_irq_mask = 0xffffffff; 29690a9a8c91SDaniel Vetter I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR)); 2970605cd25bSPaulo Zanoni I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask); 29710a9a8c91SDaniel Vetter I915_WRITE(GEN6_PMIER, pm_irqs); 29720a9a8c91SDaniel Vetter POSTING_READ(GEN6_PMIER); 29730a9a8c91SDaniel Vetter } 29740a9a8c91SDaniel Vetter } 29750a9a8c91SDaniel Vetter 2976f71d4af4SJesse Barnes static int ironlake_irq_postinstall(struct drm_device *dev) 2977036a4a7dSZhenyu Wang { 29784bc9d430SDaniel Vetter unsigned long irqflags; 2979036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 29808e76f8dcSPaulo Zanoni u32 display_mask, extra_mask; 29818e76f8dcSPaulo Zanoni 29828e76f8dcSPaulo Zanoni if (INTEL_INFO(dev)->gen >= 7) { 29838e76f8dcSPaulo Zanoni display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | 29848e76f8dcSPaulo Zanoni DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB | 29858e76f8dcSPaulo Zanoni DE_PLANEB_FLIP_DONE_IVB | 29868e76f8dcSPaulo Zanoni DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB | 29878e76f8dcSPaulo Zanoni DE_ERR_INT_IVB); 29888e76f8dcSPaulo Zanoni extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB | 29898e76f8dcSPaulo Zanoni DE_PIPEA_VBLANK_IVB); 29908e76f8dcSPaulo Zanoni 29918e76f8dcSPaulo Zanoni I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT)); 29928e76f8dcSPaulo Zanoni } else { 29938e76f8dcSPaulo Zanoni display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | 2994ce99c256SDaniel Vetter DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE | 29955b3a856bSDaniel Vetter DE_AUX_CHANNEL_A | 29965b3a856bSDaniel Vetter DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN | 29975b3a856bSDaniel Vetter DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE | 29985b3a856bSDaniel Vetter DE_POISON); 29998e76f8dcSPaulo Zanoni extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT; 30008e76f8dcSPaulo Zanoni } 3001036a4a7dSZhenyu Wang 30021ec14ad3SChris Wilson dev_priv->irq_mask = ~display_mask; 3003036a4a7dSZhenyu Wang 3004036a4a7dSZhenyu Wang /* should always can generate irq */ 3005036a4a7dSZhenyu Wang I915_WRITE(DEIIR, I915_READ(DEIIR)); 30061ec14ad3SChris Wilson I915_WRITE(DEIMR, dev_priv->irq_mask); 30078e76f8dcSPaulo Zanoni I915_WRITE(DEIER, display_mask | extra_mask); 30083143a2bfSChris Wilson POSTING_READ(DEIER); 3009036a4a7dSZhenyu Wang 30100a9a8c91SDaniel Vetter gen5_gt_irq_postinstall(dev); 3011036a4a7dSZhenyu Wang 3012d46da437SPaulo Zanoni ibx_irq_postinstall(dev); 30137fe0b973SKeith Packard 3014f97108d1SJesse Barnes if (IS_IRONLAKE_M(dev)) { 30156005ce42SDaniel Vetter /* Enable PCU event interrupts 30166005ce42SDaniel Vetter * 30176005ce42SDaniel Vetter * spinlocking not required here for correctness since interrupt 30184bc9d430SDaniel Vetter * setup is guaranteed to run in single-threaded context. But we 30194bc9d430SDaniel Vetter * need it to make the assert_spin_locked happy. */ 30204bc9d430SDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3021f97108d1SJesse Barnes ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT); 30224bc9d430SDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3023f97108d1SJesse Barnes } 3024f97108d1SJesse Barnes 3025036a4a7dSZhenyu Wang return 0; 3026036a4a7dSZhenyu Wang } 3027036a4a7dSZhenyu Wang 30287e231dbeSJesse Barnes static int valleyview_irq_postinstall(struct drm_device *dev) 30297e231dbeSJesse Barnes { 30307e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 30317e231dbeSJesse Barnes u32 enable_mask; 3032755e9019SImre Deak u32 pipestat_enable = PLANE_FLIP_DONE_INT_STATUS_VLV | 3033755e9019SImre Deak PIPE_CRC_DONE_INTERRUPT_STATUS; 3034b79480baSDaniel Vetter unsigned long irqflags; 30357e231dbeSJesse Barnes 30367e231dbeSJesse Barnes enable_mask = I915_DISPLAY_PORT_INTERRUPT; 303731acc7f5SJesse Barnes enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 303831acc7f5SJesse Barnes I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT | 303931acc7f5SJesse Barnes I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 30407e231dbeSJesse Barnes I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; 30417e231dbeSJesse Barnes 304231acc7f5SJesse Barnes /* 304331acc7f5SJesse Barnes *Leave vblank interrupts masked initially. enable/disable will 304431acc7f5SJesse Barnes * toggle them based on usage. 304531acc7f5SJesse Barnes */ 304631acc7f5SJesse Barnes dev_priv->irq_mask = (~enable_mask) | 304731acc7f5SJesse Barnes I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT | 304831acc7f5SJesse Barnes I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; 30497e231dbeSJesse Barnes 305020afbda2SDaniel Vetter I915_WRITE(PORT_HOTPLUG_EN, 0); 305120afbda2SDaniel Vetter POSTING_READ(PORT_HOTPLUG_EN); 305220afbda2SDaniel Vetter 30537e231dbeSJesse Barnes I915_WRITE(VLV_IMR, dev_priv->irq_mask); 30547e231dbeSJesse Barnes I915_WRITE(VLV_IER, enable_mask); 30557e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 30567e231dbeSJesse Barnes I915_WRITE(PIPESTAT(0), 0xffff); 30577e231dbeSJesse Barnes I915_WRITE(PIPESTAT(1), 0xffff); 30587e231dbeSJesse Barnes POSTING_READ(VLV_IER); 30597e231dbeSJesse Barnes 3060b79480baSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3061b79480baSDaniel Vetter * just to make the assert_spin_locked check happy. */ 3062b79480baSDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 30633b6c42e8SDaniel Vetter i915_enable_pipestat(dev_priv, PIPE_A, pipestat_enable); 3064755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS); 30653b6c42e8SDaniel Vetter i915_enable_pipestat(dev_priv, PIPE_B, pipestat_enable); 3066b79480baSDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 306731acc7f5SJesse Barnes 30687e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 30697e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 30707e231dbeSJesse Barnes 30710a9a8c91SDaniel Vetter gen5_gt_irq_postinstall(dev); 30727e231dbeSJesse Barnes 30737e231dbeSJesse Barnes /* ack & enable invalid PTE error interrupts */ 30747e231dbeSJesse Barnes #if 0 /* FIXME: add support to irq handler for checking these bits */ 30757e231dbeSJesse Barnes I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK); 30767e231dbeSJesse Barnes I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK); 30777e231dbeSJesse Barnes #endif 30787e231dbeSJesse Barnes 30797e231dbeSJesse Barnes I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE); 308020afbda2SDaniel Vetter 308120afbda2SDaniel Vetter return 0; 308220afbda2SDaniel Vetter } 308320afbda2SDaniel Vetter 3084abd58f01SBen Widawsky static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv) 3085abd58f01SBen Widawsky { 3086abd58f01SBen Widawsky int i; 3087abd58f01SBen Widawsky 3088abd58f01SBen Widawsky /* These are interrupts we'll toggle with the ring mask register */ 3089abd58f01SBen Widawsky uint32_t gt_interrupts[] = { 3090abd58f01SBen Widawsky GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT | 3091abd58f01SBen Widawsky GT_RENDER_L3_PARITY_ERROR_INTERRUPT | 3092abd58f01SBen Widawsky GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT, 3093abd58f01SBen Widawsky GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT | 3094abd58f01SBen Widawsky GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT, 3095abd58f01SBen Widawsky 0, 3096abd58f01SBen Widawsky GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT 3097abd58f01SBen Widawsky }; 3098abd58f01SBen Widawsky 3099abd58f01SBen Widawsky for (i = 0; i < ARRAY_SIZE(gt_interrupts); i++) { 3100abd58f01SBen Widawsky u32 tmp = I915_READ(GEN8_GT_IIR(i)); 3101abd58f01SBen Widawsky if (tmp) 3102abd58f01SBen Widawsky DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n", 3103abd58f01SBen Widawsky i, tmp); 3104abd58f01SBen Widawsky I915_WRITE(GEN8_GT_IMR(i), ~gt_interrupts[i]); 3105abd58f01SBen Widawsky I915_WRITE(GEN8_GT_IER(i), gt_interrupts[i]); 3106abd58f01SBen Widawsky } 3107abd58f01SBen Widawsky POSTING_READ(GEN8_GT_IER(0)); 3108abd58f01SBen Widawsky } 3109abd58f01SBen Widawsky 3110abd58f01SBen Widawsky static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv) 3111abd58f01SBen Widawsky { 3112abd58f01SBen Widawsky struct drm_device *dev = dev_priv->dev; 311313b3a0a7SDaniel Vetter uint32_t de_pipe_masked = GEN8_PIPE_FLIP_DONE | 31140fbe7870SDaniel Vetter GEN8_PIPE_CDCLK_CRC_DONE | 311538d83c96SDaniel Vetter GEN8_PIPE_FIFO_UNDERRUN | 311630100f2bSDaniel Vetter GEN8_DE_PIPE_IRQ_FAULT_ERRORS; 311713b3a0a7SDaniel Vetter uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK; 3118abd58f01SBen Widawsky int pipe; 311913b3a0a7SDaniel Vetter dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked; 312013b3a0a7SDaniel Vetter dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked; 312113b3a0a7SDaniel Vetter dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked; 3122abd58f01SBen Widawsky 3123abd58f01SBen Widawsky for_each_pipe(pipe) { 3124abd58f01SBen Widawsky u32 tmp = I915_READ(GEN8_DE_PIPE_IIR(pipe)); 3125abd58f01SBen Widawsky if (tmp) 3126abd58f01SBen Widawsky DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n", 3127abd58f01SBen Widawsky pipe, tmp); 3128abd58f01SBen Widawsky I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]); 3129abd58f01SBen Widawsky I915_WRITE(GEN8_DE_PIPE_IER(pipe), de_pipe_enables); 3130abd58f01SBen Widawsky } 3131abd58f01SBen Widawsky POSTING_READ(GEN8_DE_PIPE_ISR(0)); 3132abd58f01SBen Widawsky 31336d766f02SDaniel Vetter I915_WRITE(GEN8_DE_PORT_IMR, ~GEN8_AUX_CHANNEL_A); 31346d766f02SDaniel Vetter I915_WRITE(GEN8_DE_PORT_IER, GEN8_AUX_CHANNEL_A); 3135abd58f01SBen Widawsky POSTING_READ(GEN8_DE_PORT_IER); 3136abd58f01SBen Widawsky } 3137abd58f01SBen Widawsky 3138abd58f01SBen Widawsky static int gen8_irq_postinstall(struct drm_device *dev) 3139abd58f01SBen Widawsky { 3140abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 3141abd58f01SBen Widawsky 3142abd58f01SBen Widawsky gen8_gt_irq_postinstall(dev_priv); 3143abd58f01SBen Widawsky gen8_de_irq_postinstall(dev_priv); 3144abd58f01SBen Widawsky 3145abd58f01SBen Widawsky ibx_irq_postinstall(dev); 3146abd58f01SBen Widawsky 3147abd58f01SBen Widawsky I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL); 3148abd58f01SBen Widawsky POSTING_READ(GEN8_MASTER_IRQ); 3149abd58f01SBen Widawsky 3150abd58f01SBen Widawsky return 0; 3151abd58f01SBen Widawsky } 3152abd58f01SBen Widawsky 3153abd58f01SBen Widawsky static void gen8_irq_uninstall(struct drm_device *dev) 3154abd58f01SBen Widawsky { 3155abd58f01SBen Widawsky struct drm_i915_private *dev_priv = dev->dev_private; 3156abd58f01SBen Widawsky int pipe; 3157abd58f01SBen Widawsky 3158abd58f01SBen Widawsky if (!dev_priv) 3159abd58f01SBen Widawsky return; 3160abd58f01SBen Widawsky 3161abd58f01SBen Widawsky I915_WRITE(GEN8_MASTER_IRQ, 0); 3162abd58f01SBen Widawsky 3163abd58f01SBen Widawsky #define GEN8_IRQ_FINI_NDX(type, which) do { \ 3164abd58f01SBen Widawsky I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \ 3165abd58f01SBen Widawsky I915_WRITE(GEN8_##type##_IER(which), 0); \ 3166abd58f01SBen Widawsky I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \ 3167abd58f01SBen Widawsky } while (0) 3168abd58f01SBen Widawsky 3169abd58f01SBen Widawsky #define GEN8_IRQ_FINI(type) do { \ 3170abd58f01SBen Widawsky I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \ 3171abd58f01SBen Widawsky I915_WRITE(GEN8_##type##_IER, 0); \ 3172abd58f01SBen Widawsky I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \ 3173abd58f01SBen Widawsky } while (0) 3174abd58f01SBen Widawsky 3175abd58f01SBen Widawsky GEN8_IRQ_FINI_NDX(GT, 0); 3176abd58f01SBen Widawsky GEN8_IRQ_FINI_NDX(GT, 1); 3177abd58f01SBen Widawsky GEN8_IRQ_FINI_NDX(GT, 2); 3178abd58f01SBen Widawsky GEN8_IRQ_FINI_NDX(GT, 3); 3179abd58f01SBen Widawsky 3180abd58f01SBen Widawsky for_each_pipe(pipe) { 3181abd58f01SBen Widawsky GEN8_IRQ_FINI_NDX(DE_PIPE, pipe); 3182abd58f01SBen Widawsky } 3183abd58f01SBen Widawsky 3184abd58f01SBen Widawsky GEN8_IRQ_FINI(DE_PORT); 3185abd58f01SBen Widawsky GEN8_IRQ_FINI(DE_MISC); 3186abd58f01SBen Widawsky GEN8_IRQ_FINI(PCU); 3187abd58f01SBen Widawsky #undef GEN8_IRQ_FINI 3188abd58f01SBen Widawsky #undef GEN8_IRQ_FINI_NDX 3189abd58f01SBen Widawsky 3190abd58f01SBen Widawsky POSTING_READ(GEN8_PCU_IIR); 3191abd58f01SBen Widawsky } 3192abd58f01SBen Widawsky 31937e231dbeSJesse Barnes static void valleyview_irq_uninstall(struct drm_device *dev) 31947e231dbeSJesse Barnes { 31957e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 31967e231dbeSJesse Barnes int pipe; 31977e231dbeSJesse Barnes 31987e231dbeSJesse Barnes if (!dev_priv) 31997e231dbeSJesse Barnes return; 32007e231dbeSJesse Barnes 32013ca1ccedSVille Syrjälä intel_hpd_irq_uninstall(dev_priv); 3202ac4c16c5SEgbert Eich 32037e231dbeSJesse Barnes for_each_pipe(pipe) 32047e231dbeSJesse Barnes I915_WRITE(PIPESTAT(pipe), 0xffff); 32057e231dbeSJesse Barnes 32067e231dbeSJesse Barnes I915_WRITE(HWSTAM, 0xffffffff); 32077e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_EN, 0); 32087e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 32097e231dbeSJesse Barnes for_each_pipe(pipe) 32107e231dbeSJesse Barnes I915_WRITE(PIPESTAT(pipe), 0xffff); 32117e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 32127e231dbeSJesse Barnes I915_WRITE(VLV_IMR, 0xffffffff); 32137e231dbeSJesse Barnes I915_WRITE(VLV_IER, 0x0); 32147e231dbeSJesse Barnes POSTING_READ(VLV_IER); 32157e231dbeSJesse Barnes } 32167e231dbeSJesse Barnes 3217f71d4af4SJesse Barnes static void ironlake_irq_uninstall(struct drm_device *dev) 3218036a4a7dSZhenyu Wang { 3219036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 32204697995bSJesse Barnes 32214697995bSJesse Barnes if (!dev_priv) 32224697995bSJesse Barnes return; 32234697995bSJesse Barnes 32243ca1ccedSVille Syrjälä intel_hpd_irq_uninstall(dev_priv); 3225ac4c16c5SEgbert Eich 3226036a4a7dSZhenyu Wang I915_WRITE(HWSTAM, 0xffffffff); 3227036a4a7dSZhenyu Wang 3228036a4a7dSZhenyu Wang I915_WRITE(DEIMR, 0xffffffff); 3229036a4a7dSZhenyu Wang I915_WRITE(DEIER, 0x0); 3230036a4a7dSZhenyu Wang I915_WRITE(DEIIR, I915_READ(DEIIR)); 32318664281bSPaulo Zanoni if (IS_GEN7(dev)) 32328664281bSPaulo Zanoni I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT)); 3233036a4a7dSZhenyu Wang 3234036a4a7dSZhenyu Wang I915_WRITE(GTIMR, 0xffffffff); 3235036a4a7dSZhenyu Wang I915_WRITE(GTIER, 0x0); 3236036a4a7dSZhenyu Wang I915_WRITE(GTIIR, I915_READ(GTIIR)); 3237192aac1fSKeith Packard 3238ab5c608bSBen Widawsky if (HAS_PCH_NOP(dev)) 3239ab5c608bSBen Widawsky return; 3240ab5c608bSBen Widawsky 3241192aac1fSKeith Packard I915_WRITE(SDEIMR, 0xffffffff); 3242192aac1fSKeith Packard I915_WRITE(SDEIER, 0x0); 3243192aac1fSKeith Packard I915_WRITE(SDEIIR, I915_READ(SDEIIR)); 32448664281bSPaulo Zanoni if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev)) 32458664281bSPaulo Zanoni I915_WRITE(SERR_INT, I915_READ(SERR_INT)); 3246036a4a7dSZhenyu Wang } 3247036a4a7dSZhenyu Wang 3248c2798b19SChris Wilson static void i8xx_irq_preinstall(struct drm_device * dev) 3249c2798b19SChris Wilson { 3250c2798b19SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 3251c2798b19SChris Wilson int pipe; 3252c2798b19SChris Wilson 3253c2798b19SChris Wilson for_each_pipe(pipe) 3254c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3255c2798b19SChris Wilson I915_WRITE16(IMR, 0xffff); 3256c2798b19SChris Wilson I915_WRITE16(IER, 0x0); 3257c2798b19SChris Wilson POSTING_READ16(IER); 3258c2798b19SChris Wilson } 3259c2798b19SChris Wilson 3260c2798b19SChris Wilson static int i8xx_irq_postinstall(struct drm_device *dev) 3261c2798b19SChris Wilson { 3262c2798b19SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 3263379ef82dSDaniel Vetter unsigned long irqflags; 3264c2798b19SChris Wilson 3265c2798b19SChris Wilson I915_WRITE16(EMR, 3266c2798b19SChris Wilson ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH)); 3267c2798b19SChris Wilson 3268c2798b19SChris Wilson /* Unmask the interrupts that we always want on. */ 3269c2798b19SChris Wilson dev_priv->irq_mask = 3270c2798b19SChris Wilson ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3271c2798b19SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3272c2798b19SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 3273c2798b19SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | 3274c2798b19SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 3275c2798b19SChris Wilson I915_WRITE16(IMR, dev_priv->irq_mask); 3276c2798b19SChris Wilson 3277c2798b19SChris Wilson I915_WRITE16(IER, 3278c2798b19SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3279c2798b19SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3280c2798b19SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT | 3281c2798b19SChris Wilson I915_USER_INTERRUPT); 3282c2798b19SChris Wilson POSTING_READ16(IER); 3283c2798b19SChris Wilson 3284379ef82dSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3285379ef82dSDaniel Vetter * just to make the assert_spin_locked check happy. */ 3286379ef82dSDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3287755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 3288755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 3289379ef82dSDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3290379ef82dSDaniel Vetter 3291c2798b19SChris Wilson return 0; 3292c2798b19SChris Wilson } 3293c2798b19SChris Wilson 329490a72f87SVille Syrjälä /* 329590a72f87SVille Syrjälä * Returns true when a page flip has completed. 329690a72f87SVille Syrjälä */ 329790a72f87SVille Syrjälä static bool i8xx_handle_vblank(struct drm_device *dev, 32981f1c2e24SVille Syrjälä int plane, int pipe, u32 iir) 329990a72f87SVille Syrjälä { 330090a72f87SVille Syrjälä drm_i915_private_t *dev_priv = dev->dev_private; 33011f1c2e24SVille Syrjälä u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane); 330290a72f87SVille Syrjälä 330390a72f87SVille Syrjälä if (!drm_handle_vblank(dev, pipe)) 330490a72f87SVille Syrjälä return false; 330590a72f87SVille Syrjälä 330690a72f87SVille Syrjälä if ((iir & flip_pending) == 0) 330790a72f87SVille Syrjälä return false; 330890a72f87SVille Syrjälä 33091f1c2e24SVille Syrjälä intel_prepare_page_flip(dev, plane); 331090a72f87SVille Syrjälä 331190a72f87SVille Syrjälä /* We detect FlipDone by looking for the change in PendingFlip from '1' 331290a72f87SVille Syrjälä * to '0' on the following vblank, i.e. IIR has the Pendingflip 331390a72f87SVille Syrjälä * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence 331490a72f87SVille Syrjälä * the flip is completed (no longer pending). Since this doesn't raise 331590a72f87SVille Syrjälä * an interrupt per se, we watch for the change at vblank. 331690a72f87SVille Syrjälä */ 331790a72f87SVille Syrjälä if (I915_READ16(ISR) & flip_pending) 331890a72f87SVille Syrjälä return false; 331990a72f87SVille Syrjälä 332090a72f87SVille Syrjälä intel_finish_page_flip(dev, pipe); 332190a72f87SVille Syrjälä 332290a72f87SVille Syrjälä return true; 332390a72f87SVille Syrjälä } 332490a72f87SVille Syrjälä 3325ff1f525eSDaniel Vetter static irqreturn_t i8xx_irq_handler(int irq, void *arg) 3326c2798b19SChris Wilson { 3327c2798b19SChris Wilson struct drm_device *dev = (struct drm_device *) arg; 3328c2798b19SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 3329c2798b19SChris Wilson u16 iir, new_iir; 3330c2798b19SChris Wilson u32 pipe_stats[2]; 3331c2798b19SChris Wilson unsigned long irqflags; 3332c2798b19SChris Wilson int pipe; 3333c2798b19SChris Wilson u16 flip_mask = 3334c2798b19SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 3335c2798b19SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 3336c2798b19SChris Wilson 3337c2798b19SChris Wilson iir = I915_READ16(IIR); 3338c2798b19SChris Wilson if (iir == 0) 3339c2798b19SChris Wilson return IRQ_NONE; 3340c2798b19SChris Wilson 3341c2798b19SChris Wilson while (iir & ~flip_mask) { 3342c2798b19SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 3343c2798b19SChris Wilson * have been cleared after the pipestat interrupt was received. 3344c2798b19SChris Wilson * It doesn't set the bit in iir again, but it still produces 3345c2798b19SChris Wilson * interrupts (for non-MSI). 3346c2798b19SChris Wilson */ 3347c2798b19SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3348c2798b19SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 3349*58174462SMika Kuoppala i915_handle_error(dev, false, 3350*58174462SMika Kuoppala "Command parser error, iir 0x%08x", 3351*58174462SMika Kuoppala iir); 3352c2798b19SChris Wilson 3353c2798b19SChris Wilson for_each_pipe(pipe) { 3354c2798b19SChris Wilson int reg = PIPESTAT(pipe); 3355c2798b19SChris Wilson pipe_stats[pipe] = I915_READ(reg); 3356c2798b19SChris Wilson 3357c2798b19SChris Wilson /* 3358c2798b19SChris Wilson * Clear the PIPE*STAT regs before the IIR 3359c2798b19SChris Wilson */ 33602d9d2b0bSVille Syrjälä if (pipe_stats[pipe] & 0x8000ffff) 3361c2798b19SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 3362c2798b19SChris Wilson } 3363c2798b19SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3364c2798b19SChris Wilson 3365c2798b19SChris Wilson I915_WRITE16(IIR, iir & ~flip_mask); 3366c2798b19SChris Wilson new_iir = I915_READ16(IIR); /* Flush posted writes */ 3367c2798b19SChris Wilson 3368d05c617eSDaniel Vetter i915_update_dri1_breadcrumb(dev); 3369c2798b19SChris Wilson 3370c2798b19SChris Wilson if (iir & I915_USER_INTERRUPT) 3371c2798b19SChris Wilson notify_ring(dev, &dev_priv->ring[RCS]); 3372c2798b19SChris Wilson 33734356d586SDaniel Vetter for_each_pipe(pipe) { 33741f1c2e24SVille Syrjälä int plane = pipe; 33753a77c4c4SDaniel Vetter if (HAS_FBC(dev)) 33761f1c2e24SVille Syrjälä plane = !plane; 33771f1c2e24SVille Syrjälä 33784356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS && 33791f1c2e24SVille Syrjälä i8xx_handle_vblank(dev, plane, pipe, iir)) 33801f1c2e24SVille Syrjälä flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane); 3381c2798b19SChris Wilson 33824356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 3383277de95eSDaniel Vetter i9xx_pipe_crc_irq_handler(dev, pipe); 33842d9d2b0bSVille Syrjälä 33852d9d2b0bSVille Syrjälä if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS && 33862d9d2b0bSVille Syrjälä intel_set_cpu_fifo_underrun_reporting(dev, pipe, false)) 3387fc2c807bSVille Syrjälä DRM_ERROR("pipe %c underrun\n", pipe_name(pipe)); 33884356d586SDaniel Vetter } 3389c2798b19SChris Wilson 3390c2798b19SChris Wilson iir = new_iir; 3391c2798b19SChris Wilson } 3392c2798b19SChris Wilson 3393c2798b19SChris Wilson return IRQ_HANDLED; 3394c2798b19SChris Wilson } 3395c2798b19SChris Wilson 3396c2798b19SChris Wilson static void i8xx_irq_uninstall(struct drm_device * dev) 3397c2798b19SChris Wilson { 3398c2798b19SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 3399c2798b19SChris Wilson int pipe; 3400c2798b19SChris Wilson 3401c2798b19SChris Wilson for_each_pipe(pipe) { 3402c2798b19SChris Wilson /* Clear enable bits; then clear status bits */ 3403c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3404c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe))); 3405c2798b19SChris Wilson } 3406c2798b19SChris Wilson I915_WRITE16(IMR, 0xffff); 3407c2798b19SChris Wilson I915_WRITE16(IER, 0x0); 3408c2798b19SChris Wilson I915_WRITE16(IIR, I915_READ16(IIR)); 3409c2798b19SChris Wilson } 3410c2798b19SChris Wilson 3411a266c7d5SChris Wilson static void i915_irq_preinstall(struct drm_device * dev) 3412a266c7d5SChris Wilson { 3413a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 3414a266c7d5SChris Wilson int pipe; 3415a266c7d5SChris Wilson 3416a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 3417a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 3418a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3419a266c7d5SChris Wilson } 3420a266c7d5SChris Wilson 342100d98ebdSChris Wilson I915_WRITE16(HWSTAM, 0xeffe); 3422a266c7d5SChris Wilson for_each_pipe(pipe) 3423a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3424a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 3425a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 3426a266c7d5SChris Wilson POSTING_READ(IER); 3427a266c7d5SChris Wilson } 3428a266c7d5SChris Wilson 3429a266c7d5SChris Wilson static int i915_irq_postinstall(struct drm_device *dev) 3430a266c7d5SChris Wilson { 3431a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 343238bde180SChris Wilson u32 enable_mask; 3433379ef82dSDaniel Vetter unsigned long irqflags; 3434a266c7d5SChris Wilson 343538bde180SChris Wilson I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH)); 343638bde180SChris Wilson 343738bde180SChris Wilson /* Unmask the interrupts that we always want on. */ 343838bde180SChris Wilson dev_priv->irq_mask = 343938bde180SChris Wilson ~(I915_ASLE_INTERRUPT | 344038bde180SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 344138bde180SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 344238bde180SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 344338bde180SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | 344438bde180SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 344538bde180SChris Wilson 344638bde180SChris Wilson enable_mask = 344738bde180SChris Wilson I915_ASLE_INTERRUPT | 344838bde180SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 344938bde180SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 345038bde180SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT | 345138bde180SChris Wilson I915_USER_INTERRUPT; 345238bde180SChris Wilson 3453a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 345420afbda2SDaniel Vetter I915_WRITE(PORT_HOTPLUG_EN, 0); 345520afbda2SDaniel Vetter POSTING_READ(PORT_HOTPLUG_EN); 345620afbda2SDaniel Vetter 3457a266c7d5SChris Wilson /* Enable in IER... */ 3458a266c7d5SChris Wilson enable_mask |= I915_DISPLAY_PORT_INTERRUPT; 3459a266c7d5SChris Wilson /* and unmask in IMR */ 3460a266c7d5SChris Wilson dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT; 3461a266c7d5SChris Wilson } 3462a266c7d5SChris Wilson 3463a266c7d5SChris Wilson I915_WRITE(IMR, dev_priv->irq_mask); 3464a266c7d5SChris Wilson I915_WRITE(IER, enable_mask); 3465a266c7d5SChris Wilson POSTING_READ(IER); 3466a266c7d5SChris Wilson 3467f49e38ddSJani Nikula i915_enable_asle_pipestat(dev); 346820afbda2SDaniel Vetter 3469379ef82dSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3470379ef82dSDaniel Vetter * just to make the assert_spin_locked check happy. */ 3471379ef82dSDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3472755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 3473755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 3474379ef82dSDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3475379ef82dSDaniel Vetter 347620afbda2SDaniel Vetter return 0; 347720afbda2SDaniel Vetter } 347820afbda2SDaniel Vetter 347990a72f87SVille Syrjälä /* 348090a72f87SVille Syrjälä * Returns true when a page flip has completed. 348190a72f87SVille Syrjälä */ 348290a72f87SVille Syrjälä static bool i915_handle_vblank(struct drm_device *dev, 348390a72f87SVille Syrjälä int plane, int pipe, u32 iir) 348490a72f87SVille Syrjälä { 348590a72f87SVille Syrjälä drm_i915_private_t *dev_priv = dev->dev_private; 348690a72f87SVille Syrjälä u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane); 348790a72f87SVille Syrjälä 348890a72f87SVille Syrjälä if (!drm_handle_vblank(dev, pipe)) 348990a72f87SVille Syrjälä return false; 349090a72f87SVille Syrjälä 349190a72f87SVille Syrjälä if ((iir & flip_pending) == 0) 349290a72f87SVille Syrjälä return false; 349390a72f87SVille Syrjälä 349490a72f87SVille Syrjälä intel_prepare_page_flip(dev, plane); 349590a72f87SVille Syrjälä 349690a72f87SVille Syrjälä /* We detect FlipDone by looking for the change in PendingFlip from '1' 349790a72f87SVille Syrjälä * to '0' on the following vblank, i.e. IIR has the Pendingflip 349890a72f87SVille Syrjälä * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence 349990a72f87SVille Syrjälä * the flip is completed (no longer pending). Since this doesn't raise 350090a72f87SVille Syrjälä * an interrupt per se, we watch for the change at vblank. 350190a72f87SVille Syrjälä */ 350290a72f87SVille Syrjälä if (I915_READ(ISR) & flip_pending) 350390a72f87SVille Syrjälä return false; 350490a72f87SVille Syrjälä 350590a72f87SVille Syrjälä intel_finish_page_flip(dev, pipe); 350690a72f87SVille Syrjälä 350790a72f87SVille Syrjälä return true; 350890a72f87SVille Syrjälä } 350990a72f87SVille Syrjälä 3510ff1f525eSDaniel Vetter static irqreturn_t i915_irq_handler(int irq, void *arg) 3511a266c7d5SChris Wilson { 3512a266c7d5SChris Wilson struct drm_device *dev = (struct drm_device *) arg; 3513a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 35148291ee90SChris Wilson u32 iir, new_iir, pipe_stats[I915_MAX_PIPES]; 3515a266c7d5SChris Wilson unsigned long irqflags; 351638bde180SChris Wilson u32 flip_mask = 351738bde180SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 351838bde180SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 351938bde180SChris Wilson int pipe, ret = IRQ_NONE; 3520a266c7d5SChris Wilson 3521a266c7d5SChris Wilson iir = I915_READ(IIR); 352238bde180SChris Wilson do { 352338bde180SChris Wilson bool irq_received = (iir & ~flip_mask) != 0; 35248291ee90SChris Wilson bool blc_event = false; 3525a266c7d5SChris Wilson 3526a266c7d5SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 3527a266c7d5SChris Wilson * have been cleared after the pipestat interrupt was received. 3528a266c7d5SChris Wilson * It doesn't set the bit in iir again, but it still produces 3529a266c7d5SChris Wilson * interrupts (for non-MSI). 3530a266c7d5SChris Wilson */ 3531a266c7d5SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3532a266c7d5SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 3533*58174462SMika Kuoppala i915_handle_error(dev, false, 3534*58174462SMika Kuoppala "Command parser error, iir 0x%08x", 3535*58174462SMika Kuoppala iir); 3536a266c7d5SChris Wilson 3537a266c7d5SChris Wilson for_each_pipe(pipe) { 3538a266c7d5SChris Wilson int reg = PIPESTAT(pipe); 3539a266c7d5SChris Wilson pipe_stats[pipe] = I915_READ(reg); 3540a266c7d5SChris Wilson 354138bde180SChris Wilson /* Clear the PIPE*STAT regs before the IIR */ 3542a266c7d5SChris Wilson if (pipe_stats[pipe] & 0x8000ffff) { 3543a266c7d5SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 354438bde180SChris Wilson irq_received = true; 3545a266c7d5SChris Wilson } 3546a266c7d5SChris Wilson } 3547a266c7d5SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3548a266c7d5SChris Wilson 3549a266c7d5SChris Wilson if (!irq_received) 3550a266c7d5SChris Wilson break; 3551a266c7d5SChris Wilson 3552a266c7d5SChris Wilson /* Consume port. Then clear IIR or we'll miss events */ 3553a266c7d5SChris Wilson if ((I915_HAS_HOTPLUG(dev)) && 3554a266c7d5SChris Wilson (iir & I915_DISPLAY_PORT_INTERRUPT)) { 3555a266c7d5SChris Wilson u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); 3556b543fb04SEgbert Eich u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915; 3557a266c7d5SChris Wilson 355810a504deSDaniel Vetter intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915); 355991d131d2SDaniel Vetter 3560a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); 356138bde180SChris Wilson POSTING_READ(PORT_HOTPLUG_STAT); 3562a266c7d5SChris Wilson } 3563a266c7d5SChris Wilson 356438bde180SChris Wilson I915_WRITE(IIR, iir & ~flip_mask); 3565a266c7d5SChris Wilson new_iir = I915_READ(IIR); /* Flush posted writes */ 3566a266c7d5SChris Wilson 3567a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 3568a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[RCS]); 3569a266c7d5SChris Wilson 3570a266c7d5SChris Wilson for_each_pipe(pipe) { 357138bde180SChris Wilson int plane = pipe; 35723a77c4c4SDaniel Vetter if (HAS_FBC(dev)) 357338bde180SChris Wilson plane = !plane; 35745e2032d4SVille Syrjälä 357590a72f87SVille Syrjälä if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS && 357690a72f87SVille Syrjälä i915_handle_vblank(dev, plane, pipe, iir)) 357790a72f87SVille Syrjälä flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane); 3578a266c7d5SChris Wilson 3579a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 3580a266c7d5SChris Wilson blc_event = true; 35814356d586SDaniel Vetter 35824356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 3583277de95eSDaniel Vetter i9xx_pipe_crc_irq_handler(dev, pipe); 35842d9d2b0bSVille Syrjälä 35852d9d2b0bSVille Syrjälä if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS && 35862d9d2b0bSVille Syrjälä intel_set_cpu_fifo_underrun_reporting(dev, pipe, false)) 3587fc2c807bSVille Syrjälä DRM_ERROR("pipe %c underrun\n", pipe_name(pipe)); 3588a266c7d5SChris Wilson } 3589a266c7d5SChris Wilson 3590a266c7d5SChris Wilson if (blc_event || (iir & I915_ASLE_INTERRUPT)) 3591a266c7d5SChris Wilson intel_opregion_asle_intr(dev); 3592a266c7d5SChris Wilson 3593a266c7d5SChris Wilson /* With MSI, interrupts are only generated when iir 3594a266c7d5SChris Wilson * transitions from zero to nonzero. If another bit got 3595a266c7d5SChris Wilson * set while we were handling the existing iir bits, then 3596a266c7d5SChris Wilson * we would never get another interrupt. 3597a266c7d5SChris Wilson * 3598a266c7d5SChris Wilson * This is fine on non-MSI as well, as if we hit this path 3599a266c7d5SChris Wilson * we avoid exiting the interrupt handler only to generate 3600a266c7d5SChris Wilson * another one. 3601a266c7d5SChris Wilson * 3602a266c7d5SChris Wilson * Note that for MSI this could cause a stray interrupt report 3603a266c7d5SChris Wilson * if an interrupt landed in the time between writing IIR and 3604a266c7d5SChris Wilson * the posting read. This should be rare enough to never 3605a266c7d5SChris Wilson * trigger the 99% of 100,000 interrupts test for disabling 3606a266c7d5SChris Wilson * stray interrupts. 3607a266c7d5SChris Wilson */ 360838bde180SChris Wilson ret = IRQ_HANDLED; 3609a266c7d5SChris Wilson iir = new_iir; 361038bde180SChris Wilson } while (iir & ~flip_mask); 3611a266c7d5SChris Wilson 3612d05c617eSDaniel Vetter i915_update_dri1_breadcrumb(dev); 36138291ee90SChris Wilson 3614a266c7d5SChris Wilson return ret; 3615a266c7d5SChris Wilson } 3616a266c7d5SChris Wilson 3617a266c7d5SChris Wilson static void i915_irq_uninstall(struct drm_device * dev) 3618a266c7d5SChris Wilson { 3619a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 3620a266c7d5SChris Wilson int pipe; 3621a266c7d5SChris Wilson 36223ca1ccedSVille Syrjälä intel_hpd_irq_uninstall(dev_priv); 3623ac4c16c5SEgbert Eich 3624a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 3625a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 3626a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3627a266c7d5SChris Wilson } 3628a266c7d5SChris Wilson 362900d98ebdSChris Wilson I915_WRITE16(HWSTAM, 0xffff); 363055b39755SChris Wilson for_each_pipe(pipe) { 363155b39755SChris Wilson /* Clear enable bits; then clear status bits */ 3632a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 363355b39755SChris Wilson I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe))); 363455b39755SChris Wilson } 3635a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 3636a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 3637a266c7d5SChris Wilson 3638a266c7d5SChris Wilson I915_WRITE(IIR, I915_READ(IIR)); 3639a266c7d5SChris Wilson } 3640a266c7d5SChris Wilson 3641a266c7d5SChris Wilson static void i965_irq_preinstall(struct drm_device * dev) 3642a266c7d5SChris Wilson { 3643a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 3644a266c7d5SChris Wilson int pipe; 3645a266c7d5SChris Wilson 3646a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 3647a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3648a266c7d5SChris Wilson 3649a266c7d5SChris Wilson I915_WRITE(HWSTAM, 0xeffe); 3650a266c7d5SChris Wilson for_each_pipe(pipe) 3651a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3652a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 3653a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 3654a266c7d5SChris Wilson POSTING_READ(IER); 3655a266c7d5SChris Wilson } 3656a266c7d5SChris Wilson 3657a266c7d5SChris Wilson static int i965_irq_postinstall(struct drm_device *dev) 3658a266c7d5SChris Wilson { 3659a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 3660bbba0a97SChris Wilson u32 enable_mask; 3661a266c7d5SChris Wilson u32 error_mask; 3662b79480baSDaniel Vetter unsigned long irqflags; 3663a266c7d5SChris Wilson 3664a266c7d5SChris Wilson /* Unmask the interrupts that we always want on. */ 3665bbba0a97SChris Wilson dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT | 3666adca4730SChris Wilson I915_DISPLAY_PORT_INTERRUPT | 3667bbba0a97SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3668bbba0a97SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3669bbba0a97SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 3670bbba0a97SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | 3671bbba0a97SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 3672bbba0a97SChris Wilson 3673bbba0a97SChris Wilson enable_mask = ~dev_priv->irq_mask; 367421ad8330SVille Syrjälä enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 367521ad8330SVille Syrjälä I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT); 3676bbba0a97SChris Wilson enable_mask |= I915_USER_INTERRUPT; 3677bbba0a97SChris Wilson 3678bbba0a97SChris Wilson if (IS_G4X(dev)) 3679bbba0a97SChris Wilson enable_mask |= I915_BSD_USER_INTERRUPT; 3680a266c7d5SChris Wilson 3681b79480baSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3682b79480baSDaniel Vetter * just to make the assert_spin_locked check happy. */ 3683b79480baSDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3684755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS); 3685755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 3686755e9019SImre Deak i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 3687b79480baSDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3688a266c7d5SChris Wilson 3689a266c7d5SChris Wilson /* 3690a266c7d5SChris Wilson * Enable some error detection, note the instruction error mask 3691a266c7d5SChris Wilson * bit is reserved, so we leave it masked. 3692a266c7d5SChris Wilson */ 3693a266c7d5SChris Wilson if (IS_G4X(dev)) { 3694a266c7d5SChris Wilson error_mask = ~(GM45_ERROR_PAGE_TABLE | 3695a266c7d5SChris Wilson GM45_ERROR_MEM_PRIV | 3696a266c7d5SChris Wilson GM45_ERROR_CP_PRIV | 3697a266c7d5SChris Wilson I915_ERROR_MEMORY_REFRESH); 3698a266c7d5SChris Wilson } else { 3699a266c7d5SChris Wilson error_mask = ~(I915_ERROR_PAGE_TABLE | 3700a266c7d5SChris Wilson I915_ERROR_MEMORY_REFRESH); 3701a266c7d5SChris Wilson } 3702a266c7d5SChris Wilson I915_WRITE(EMR, error_mask); 3703a266c7d5SChris Wilson 3704a266c7d5SChris Wilson I915_WRITE(IMR, dev_priv->irq_mask); 3705a266c7d5SChris Wilson I915_WRITE(IER, enable_mask); 3706a266c7d5SChris Wilson POSTING_READ(IER); 3707a266c7d5SChris Wilson 370820afbda2SDaniel Vetter I915_WRITE(PORT_HOTPLUG_EN, 0); 370920afbda2SDaniel Vetter POSTING_READ(PORT_HOTPLUG_EN); 371020afbda2SDaniel Vetter 3711f49e38ddSJani Nikula i915_enable_asle_pipestat(dev); 371220afbda2SDaniel Vetter 371320afbda2SDaniel Vetter return 0; 371420afbda2SDaniel Vetter } 371520afbda2SDaniel Vetter 3716bac56d5bSEgbert Eich static void i915_hpd_irq_setup(struct drm_device *dev) 371720afbda2SDaniel Vetter { 371820afbda2SDaniel Vetter drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 3719e5868a31SEgbert Eich struct drm_mode_config *mode_config = &dev->mode_config; 3720cd569aedSEgbert Eich struct intel_encoder *intel_encoder; 372120afbda2SDaniel Vetter u32 hotplug_en; 372220afbda2SDaniel Vetter 3723b5ea2d56SDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 3724b5ea2d56SDaniel Vetter 3725bac56d5bSEgbert Eich if (I915_HAS_HOTPLUG(dev)) { 3726bac56d5bSEgbert Eich hotplug_en = I915_READ(PORT_HOTPLUG_EN); 3727bac56d5bSEgbert Eich hotplug_en &= ~HOTPLUG_INT_EN_MASK; 3728adca4730SChris Wilson /* Note HDMI and DP share hotplug bits */ 3729e5868a31SEgbert Eich /* enable bits are the same for all generations */ 3730cd569aedSEgbert Eich list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head) 3731cd569aedSEgbert Eich if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) 3732cd569aedSEgbert Eich hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin]; 3733a266c7d5SChris Wilson /* Programming the CRT detection parameters tends 3734a266c7d5SChris Wilson to generate a spurious hotplug event about three 3735a266c7d5SChris Wilson seconds later. So just do it once. 3736a266c7d5SChris Wilson */ 3737a266c7d5SChris Wilson if (IS_G4X(dev)) 3738a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64; 373985fc95baSDaniel Vetter hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK; 3740a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; 3741a266c7d5SChris Wilson 3742a266c7d5SChris Wilson /* Ignore TV since it's buggy */ 3743a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, hotplug_en); 3744a266c7d5SChris Wilson } 3745bac56d5bSEgbert Eich } 3746a266c7d5SChris Wilson 3747ff1f525eSDaniel Vetter static irqreturn_t i965_irq_handler(int irq, void *arg) 3748a266c7d5SChris Wilson { 3749a266c7d5SChris Wilson struct drm_device *dev = (struct drm_device *) arg; 3750a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 3751a266c7d5SChris Wilson u32 iir, new_iir; 3752a266c7d5SChris Wilson u32 pipe_stats[I915_MAX_PIPES]; 3753a266c7d5SChris Wilson unsigned long irqflags; 3754a266c7d5SChris Wilson int ret = IRQ_NONE, pipe; 375521ad8330SVille Syrjälä u32 flip_mask = 375621ad8330SVille Syrjälä I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 375721ad8330SVille Syrjälä I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 3758a266c7d5SChris Wilson 3759a266c7d5SChris Wilson iir = I915_READ(IIR); 3760a266c7d5SChris Wilson 3761a266c7d5SChris Wilson for (;;) { 3762501e01d7SVille Syrjälä bool irq_received = (iir & ~flip_mask) != 0; 37632c8ba29fSChris Wilson bool blc_event = false; 37642c8ba29fSChris Wilson 3765a266c7d5SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 3766a266c7d5SChris Wilson * have been cleared after the pipestat interrupt was received. 3767a266c7d5SChris Wilson * It doesn't set the bit in iir again, but it still produces 3768a266c7d5SChris Wilson * interrupts (for non-MSI). 3769a266c7d5SChris Wilson */ 3770a266c7d5SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3771a266c7d5SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 3772*58174462SMika Kuoppala i915_handle_error(dev, false, 3773*58174462SMika Kuoppala "Command parser error, iir 0x%08x", 3774*58174462SMika Kuoppala iir); 3775a266c7d5SChris Wilson 3776a266c7d5SChris Wilson for_each_pipe(pipe) { 3777a266c7d5SChris Wilson int reg = PIPESTAT(pipe); 3778a266c7d5SChris Wilson pipe_stats[pipe] = I915_READ(reg); 3779a266c7d5SChris Wilson 3780a266c7d5SChris Wilson /* 3781a266c7d5SChris Wilson * Clear the PIPE*STAT regs before the IIR 3782a266c7d5SChris Wilson */ 3783a266c7d5SChris Wilson if (pipe_stats[pipe] & 0x8000ffff) { 3784a266c7d5SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 3785501e01d7SVille Syrjälä irq_received = true; 3786a266c7d5SChris Wilson } 3787a266c7d5SChris Wilson } 3788a266c7d5SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3789a266c7d5SChris Wilson 3790a266c7d5SChris Wilson if (!irq_received) 3791a266c7d5SChris Wilson break; 3792a266c7d5SChris Wilson 3793a266c7d5SChris Wilson ret = IRQ_HANDLED; 3794a266c7d5SChris Wilson 3795a266c7d5SChris Wilson /* Consume port. Then clear IIR or we'll miss events */ 3796adca4730SChris Wilson if (iir & I915_DISPLAY_PORT_INTERRUPT) { 3797a266c7d5SChris Wilson u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); 3798b543fb04SEgbert Eich u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ? 3799b543fb04SEgbert Eich HOTPLUG_INT_STATUS_G4X : 38004f7fd709SDaniel Vetter HOTPLUG_INT_STATUS_I915); 3801a266c7d5SChris Wilson 380210a504deSDaniel Vetter intel_hpd_irq_handler(dev, hotplug_trigger, 3803704cfb87SDaniel Vetter IS_G4X(dev) ? hpd_status_g4x : hpd_status_i915); 380491d131d2SDaniel Vetter 38054aeebd74SDaniel Vetter if (IS_G4X(dev) && 38064aeebd74SDaniel Vetter (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)) 38074aeebd74SDaniel Vetter dp_aux_irq_handler(dev); 38084aeebd74SDaniel Vetter 3809a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); 3810a266c7d5SChris Wilson I915_READ(PORT_HOTPLUG_STAT); 3811a266c7d5SChris Wilson } 3812a266c7d5SChris Wilson 381321ad8330SVille Syrjälä I915_WRITE(IIR, iir & ~flip_mask); 3814a266c7d5SChris Wilson new_iir = I915_READ(IIR); /* Flush posted writes */ 3815a266c7d5SChris Wilson 3816a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 3817a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[RCS]); 3818a266c7d5SChris Wilson if (iir & I915_BSD_USER_INTERRUPT) 3819a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[VCS]); 3820a266c7d5SChris Wilson 3821a266c7d5SChris Wilson for_each_pipe(pipe) { 38222c8ba29fSChris Wilson if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS && 382390a72f87SVille Syrjälä i915_handle_vblank(dev, pipe, pipe, iir)) 382490a72f87SVille Syrjälä flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe); 3825a266c7d5SChris Wilson 3826a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 3827a266c7d5SChris Wilson blc_event = true; 38284356d586SDaniel Vetter 38294356d586SDaniel Vetter if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 3830277de95eSDaniel Vetter i9xx_pipe_crc_irq_handler(dev, pipe); 3831a266c7d5SChris Wilson 38322d9d2b0bSVille Syrjälä if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS && 38332d9d2b0bSVille Syrjälä intel_set_cpu_fifo_underrun_reporting(dev, pipe, false)) 3834fc2c807bSVille Syrjälä DRM_ERROR("pipe %c underrun\n", pipe_name(pipe)); 38352d9d2b0bSVille Syrjälä } 3836a266c7d5SChris Wilson 3837a266c7d5SChris Wilson if (blc_event || (iir & I915_ASLE_INTERRUPT)) 3838a266c7d5SChris Wilson intel_opregion_asle_intr(dev); 3839a266c7d5SChris Wilson 3840515ac2bbSDaniel Vetter if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 3841515ac2bbSDaniel Vetter gmbus_irq_handler(dev); 3842515ac2bbSDaniel Vetter 3843a266c7d5SChris Wilson /* With MSI, interrupts are only generated when iir 3844a266c7d5SChris Wilson * transitions from zero to nonzero. If another bit got 3845a266c7d5SChris Wilson * set while we were handling the existing iir bits, then 3846a266c7d5SChris Wilson * we would never get another interrupt. 3847a266c7d5SChris Wilson * 3848a266c7d5SChris Wilson * This is fine on non-MSI as well, as if we hit this path 3849a266c7d5SChris Wilson * we avoid exiting the interrupt handler only to generate 3850a266c7d5SChris Wilson * another one. 3851a266c7d5SChris Wilson * 3852a266c7d5SChris Wilson * Note that for MSI this could cause a stray interrupt report 3853a266c7d5SChris Wilson * if an interrupt landed in the time between writing IIR and 3854a266c7d5SChris Wilson * the posting read. This should be rare enough to never 3855a266c7d5SChris Wilson * trigger the 99% of 100,000 interrupts test for disabling 3856a266c7d5SChris Wilson * stray interrupts. 3857a266c7d5SChris Wilson */ 3858a266c7d5SChris Wilson iir = new_iir; 3859a266c7d5SChris Wilson } 3860a266c7d5SChris Wilson 3861d05c617eSDaniel Vetter i915_update_dri1_breadcrumb(dev); 38622c8ba29fSChris Wilson 3863a266c7d5SChris Wilson return ret; 3864a266c7d5SChris Wilson } 3865a266c7d5SChris Wilson 3866a266c7d5SChris Wilson static void i965_irq_uninstall(struct drm_device * dev) 3867a266c7d5SChris Wilson { 3868a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 3869a266c7d5SChris Wilson int pipe; 3870a266c7d5SChris Wilson 3871a266c7d5SChris Wilson if (!dev_priv) 3872a266c7d5SChris Wilson return; 3873a266c7d5SChris Wilson 38743ca1ccedSVille Syrjälä intel_hpd_irq_uninstall(dev_priv); 3875ac4c16c5SEgbert Eich 3876a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 3877a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3878a266c7d5SChris Wilson 3879a266c7d5SChris Wilson I915_WRITE(HWSTAM, 0xffffffff); 3880a266c7d5SChris Wilson for_each_pipe(pipe) 3881a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3882a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 3883a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 3884a266c7d5SChris Wilson 3885a266c7d5SChris Wilson for_each_pipe(pipe) 3886a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 3887a266c7d5SChris Wilson I915_READ(PIPESTAT(pipe)) & 0x8000ffff); 3888a266c7d5SChris Wilson I915_WRITE(IIR, I915_READ(IIR)); 3889a266c7d5SChris Wilson } 3890a266c7d5SChris Wilson 38913ca1ccedSVille Syrjälä static void intel_hpd_irq_reenable(unsigned long data) 3892ac4c16c5SEgbert Eich { 3893ac4c16c5SEgbert Eich drm_i915_private_t *dev_priv = (drm_i915_private_t *)data; 3894ac4c16c5SEgbert Eich struct drm_device *dev = dev_priv->dev; 3895ac4c16c5SEgbert Eich struct drm_mode_config *mode_config = &dev->mode_config; 3896ac4c16c5SEgbert Eich unsigned long irqflags; 3897ac4c16c5SEgbert Eich int i; 3898ac4c16c5SEgbert Eich 3899ac4c16c5SEgbert Eich spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3900ac4c16c5SEgbert Eich for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) { 3901ac4c16c5SEgbert Eich struct drm_connector *connector; 3902ac4c16c5SEgbert Eich 3903ac4c16c5SEgbert Eich if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED) 3904ac4c16c5SEgbert Eich continue; 3905ac4c16c5SEgbert Eich 3906ac4c16c5SEgbert Eich dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED; 3907ac4c16c5SEgbert Eich 3908ac4c16c5SEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 3909ac4c16c5SEgbert Eich struct intel_connector *intel_connector = to_intel_connector(connector); 3910ac4c16c5SEgbert Eich 3911ac4c16c5SEgbert Eich if (intel_connector->encoder->hpd_pin == i) { 3912ac4c16c5SEgbert Eich if (connector->polled != intel_connector->polled) 3913ac4c16c5SEgbert Eich DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n", 3914ac4c16c5SEgbert Eich drm_get_connector_name(connector)); 3915ac4c16c5SEgbert Eich connector->polled = intel_connector->polled; 3916ac4c16c5SEgbert Eich if (!connector->polled) 3917ac4c16c5SEgbert Eich connector->polled = DRM_CONNECTOR_POLL_HPD; 3918ac4c16c5SEgbert Eich } 3919ac4c16c5SEgbert Eich } 3920ac4c16c5SEgbert Eich } 3921ac4c16c5SEgbert Eich if (dev_priv->display.hpd_irq_setup) 3922ac4c16c5SEgbert Eich dev_priv->display.hpd_irq_setup(dev); 3923ac4c16c5SEgbert Eich spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3924ac4c16c5SEgbert Eich } 3925ac4c16c5SEgbert Eich 3926f71d4af4SJesse Barnes void intel_irq_init(struct drm_device *dev) 3927f71d4af4SJesse Barnes { 39288b2e326dSChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 39298b2e326dSChris Wilson 39308b2e326dSChris Wilson INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func); 393199584db3SDaniel Vetter INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func); 3932c6a828d3SDaniel Vetter INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work); 3933a4da4fa4SDaniel Vetter INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work); 39348b2e326dSChris Wilson 393599584db3SDaniel Vetter setup_timer(&dev_priv->gpu_error.hangcheck_timer, 393699584db3SDaniel Vetter i915_hangcheck_elapsed, 393761bac78eSDaniel Vetter (unsigned long) dev); 39383ca1ccedSVille Syrjälä setup_timer(&dev_priv->hotplug_reenable_timer, intel_hpd_irq_reenable, 3939ac4c16c5SEgbert Eich (unsigned long) dev_priv); 394061bac78eSDaniel Vetter 394197a19a24STomas Janousek pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE); 39429ee32feaSDaniel Vetter 39434cdb83ecSVille Syrjälä if (IS_GEN2(dev)) { 39444cdb83ecSVille Syrjälä dev->max_vblank_count = 0; 39454cdb83ecSVille Syrjälä dev->driver->get_vblank_counter = i8xx_get_vblank_counter; 39464cdb83ecSVille Syrjälä } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { 3947f71d4af4SJesse Barnes dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */ 3948f71d4af4SJesse Barnes dev->driver->get_vblank_counter = gm45_get_vblank_counter; 3949391f75e2SVille Syrjälä } else { 3950391f75e2SVille Syrjälä dev->driver->get_vblank_counter = i915_get_vblank_counter; 3951391f75e2SVille Syrjälä dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ 3952f71d4af4SJesse Barnes } 3953f71d4af4SJesse Barnes 3954c2baf4b7SVille Syrjälä if (drm_core_check_feature(dev, DRIVER_MODESET)) { 3955f71d4af4SJesse Barnes dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp; 3956f71d4af4SJesse Barnes dev->driver->get_scanout_position = i915_get_crtc_scanoutpos; 3957c2baf4b7SVille Syrjälä } 3958f71d4af4SJesse Barnes 39597e231dbeSJesse Barnes if (IS_VALLEYVIEW(dev)) { 39607e231dbeSJesse Barnes dev->driver->irq_handler = valleyview_irq_handler; 39617e231dbeSJesse Barnes dev->driver->irq_preinstall = valleyview_irq_preinstall; 39627e231dbeSJesse Barnes dev->driver->irq_postinstall = valleyview_irq_postinstall; 39637e231dbeSJesse Barnes dev->driver->irq_uninstall = valleyview_irq_uninstall; 39647e231dbeSJesse Barnes dev->driver->enable_vblank = valleyview_enable_vblank; 39657e231dbeSJesse Barnes dev->driver->disable_vblank = valleyview_disable_vblank; 3966fa00abe0SEgbert Eich dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 3967abd58f01SBen Widawsky } else if (IS_GEN8(dev)) { 3968abd58f01SBen Widawsky dev->driver->irq_handler = gen8_irq_handler; 3969abd58f01SBen Widawsky dev->driver->irq_preinstall = gen8_irq_preinstall; 3970abd58f01SBen Widawsky dev->driver->irq_postinstall = gen8_irq_postinstall; 3971abd58f01SBen Widawsky dev->driver->irq_uninstall = gen8_irq_uninstall; 3972abd58f01SBen Widawsky dev->driver->enable_vblank = gen8_enable_vblank; 3973abd58f01SBen Widawsky dev->driver->disable_vblank = gen8_disable_vblank; 3974abd58f01SBen Widawsky dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup; 3975f71d4af4SJesse Barnes } else if (HAS_PCH_SPLIT(dev)) { 3976f71d4af4SJesse Barnes dev->driver->irq_handler = ironlake_irq_handler; 3977f71d4af4SJesse Barnes dev->driver->irq_preinstall = ironlake_irq_preinstall; 3978f71d4af4SJesse Barnes dev->driver->irq_postinstall = ironlake_irq_postinstall; 3979f71d4af4SJesse Barnes dev->driver->irq_uninstall = ironlake_irq_uninstall; 3980f71d4af4SJesse Barnes dev->driver->enable_vblank = ironlake_enable_vblank; 3981f71d4af4SJesse Barnes dev->driver->disable_vblank = ironlake_disable_vblank; 398282a28bcfSDaniel Vetter dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup; 3983f71d4af4SJesse Barnes } else { 3984c2798b19SChris Wilson if (INTEL_INFO(dev)->gen == 2) { 3985c2798b19SChris Wilson dev->driver->irq_preinstall = i8xx_irq_preinstall; 3986c2798b19SChris Wilson dev->driver->irq_postinstall = i8xx_irq_postinstall; 3987c2798b19SChris Wilson dev->driver->irq_handler = i8xx_irq_handler; 3988c2798b19SChris Wilson dev->driver->irq_uninstall = i8xx_irq_uninstall; 3989a266c7d5SChris Wilson } else if (INTEL_INFO(dev)->gen == 3) { 3990a266c7d5SChris Wilson dev->driver->irq_preinstall = i915_irq_preinstall; 3991a266c7d5SChris Wilson dev->driver->irq_postinstall = i915_irq_postinstall; 3992a266c7d5SChris Wilson dev->driver->irq_uninstall = i915_irq_uninstall; 3993a266c7d5SChris Wilson dev->driver->irq_handler = i915_irq_handler; 399420afbda2SDaniel Vetter dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 3995c2798b19SChris Wilson } else { 3996a266c7d5SChris Wilson dev->driver->irq_preinstall = i965_irq_preinstall; 3997a266c7d5SChris Wilson dev->driver->irq_postinstall = i965_irq_postinstall; 3998a266c7d5SChris Wilson dev->driver->irq_uninstall = i965_irq_uninstall; 3999a266c7d5SChris Wilson dev->driver->irq_handler = i965_irq_handler; 4000bac56d5bSEgbert Eich dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 4001c2798b19SChris Wilson } 4002f71d4af4SJesse Barnes dev->driver->enable_vblank = i915_enable_vblank; 4003f71d4af4SJesse Barnes dev->driver->disable_vblank = i915_disable_vblank; 4004f71d4af4SJesse Barnes } 4005f71d4af4SJesse Barnes } 400620afbda2SDaniel Vetter 400720afbda2SDaniel Vetter void intel_hpd_init(struct drm_device *dev) 400820afbda2SDaniel Vetter { 400920afbda2SDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 4010821450c6SEgbert Eich struct drm_mode_config *mode_config = &dev->mode_config; 4011821450c6SEgbert Eich struct drm_connector *connector; 4012b5ea2d56SDaniel Vetter unsigned long irqflags; 4013821450c6SEgbert Eich int i; 401420afbda2SDaniel Vetter 4015821450c6SEgbert Eich for (i = 1; i < HPD_NUM_PINS; i++) { 4016821450c6SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt = 0; 4017821450c6SEgbert Eich dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED; 4018821450c6SEgbert Eich } 4019821450c6SEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 4020821450c6SEgbert Eich struct intel_connector *intel_connector = to_intel_connector(connector); 4021821450c6SEgbert Eich connector->polled = intel_connector->polled; 4022821450c6SEgbert Eich if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE) 4023821450c6SEgbert Eich connector->polled = DRM_CONNECTOR_POLL_HPD; 4024821450c6SEgbert Eich } 4025b5ea2d56SDaniel Vetter 4026b5ea2d56SDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 4027b5ea2d56SDaniel Vetter * just to make the assert_spin_locked checks happy. */ 4028b5ea2d56SDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 402920afbda2SDaniel Vetter if (dev_priv->display.hpd_irq_setup) 403020afbda2SDaniel Vetter dev_priv->display.hpd_irq_setup(dev); 4031b5ea2d56SDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 403220afbda2SDaniel Vetter } 4033c67a470bSPaulo Zanoni 4034c67a470bSPaulo Zanoni /* Disable interrupts so we can allow Package C8+. */ 4035c67a470bSPaulo Zanoni void hsw_pc8_disable_interrupts(struct drm_device *dev) 4036c67a470bSPaulo Zanoni { 4037c67a470bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 4038c67a470bSPaulo Zanoni unsigned long irqflags; 4039c67a470bSPaulo Zanoni 4040c67a470bSPaulo Zanoni spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 4041c67a470bSPaulo Zanoni 4042c67a470bSPaulo Zanoni dev_priv->pc8.regsave.deimr = I915_READ(DEIMR); 4043c67a470bSPaulo Zanoni dev_priv->pc8.regsave.sdeimr = I915_READ(SDEIMR); 4044c67a470bSPaulo Zanoni dev_priv->pc8.regsave.gtimr = I915_READ(GTIMR); 4045c67a470bSPaulo Zanoni dev_priv->pc8.regsave.gtier = I915_READ(GTIER); 4046c67a470bSPaulo Zanoni dev_priv->pc8.regsave.gen6_pmimr = I915_READ(GEN6_PMIMR); 4047c67a470bSPaulo Zanoni 40481f2d4531SPaulo Zanoni ironlake_disable_display_irq(dev_priv, 0xffffffff); 40491f2d4531SPaulo Zanoni ibx_disable_display_interrupt(dev_priv, 0xffffffff); 4050c67a470bSPaulo Zanoni ilk_disable_gt_irq(dev_priv, 0xffffffff); 4051c67a470bSPaulo Zanoni snb_disable_pm_irq(dev_priv, 0xffffffff); 4052c67a470bSPaulo Zanoni 4053c67a470bSPaulo Zanoni dev_priv->pc8.irqs_disabled = true; 4054c67a470bSPaulo Zanoni 4055c67a470bSPaulo Zanoni spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 4056c67a470bSPaulo Zanoni } 4057c67a470bSPaulo Zanoni 4058c67a470bSPaulo Zanoni /* Restore interrupts so we can recover from Package C8+. */ 4059c67a470bSPaulo Zanoni void hsw_pc8_restore_interrupts(struct drm_device *dev) 4060c67a470bSPaulo Zanoni { 4061c67a470bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 4062c67a470bSPaulo Zanoni unsigned long irqflags; 40631f2d4531SPaulo Zanoni uint32_t val; 4064c67a470bSPaulo Zanoni 4065c67a470bSPaulo Zanoni spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 4066c67a470bSPaulo Zanoni 4067c67a470bSPaulo Zanoni val = I915_READ(DEIMR); 40681f2d4531SPaulo Zanoni WARN(val != 0xffffffff, "DEIMR is 0x%08x\n", val); 4069c67a470bSPaulo Zanoni 40701f2d4531SPaulo Zanoni val = I915_READ(SDEIMR); 40711f2d4531SPaulo Zanoni WARN(val != 0xffffffff, "SDEIMR is 0x%08x\n", val); 4072c67a470bSPaulo Zanoni 4073c67a470bSPaulo Zanoni val = I915_READ(GTIMR); 40741f2d4531SPaulo Zanoni WARN(val != 0xffffffff, "GTIMR is 0x%08x\n", val); 4075c67a470bSPaulo Zanoni 4076c67a470bSPaulo Zanoni val = I915_READ(GEN6_PMIMR); 40771f2d4531SPaulo Zanoni WARN(val != 0xffffffff, "GEN6_PMIMR is 0x%08x\n", val); 4078c67a470bSPaulo Zanoni 4079c67a470bSPaulo Zanoni dev_priv->pc8.irqs_disabled = false; 4080c67a470bSPaulo Zanoni 4081c67a470bSPaulo Zanoni ironlake_enable_display_irq(dev_priv, ~dev_priv->pc8.regsave.deimr); 40821f2d4531SPaulo Zanoni ibx_enable_display_interrupt(dev_priv, ~dev_priv->pc8.regsave.sdeimr); 4083c67a470bSPaulo Zanoni ilk_enable_gt_irq(dev_priv, ~dev_priv->pc8.regsave.gtimr); 4084c67a470bSPaulo Zanoni snb_enable_pm_irq(dev_priv, ~dev_priv->pc8.regsave.gen6_pmimr); 4085c67a470bSPaulo Zanoni I915_WRITE(GTIER, dev_priv->pc8.regsave.gtier); 4086c67a470bSPaulo Zanoni 4087c67a470bSPaulo Zanoni spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 4088c67a470bSPaulo Zanoni } 4089