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> 33760285e7SDavid Howells #include <drm/drmP.h> 34760285e7SDavid Howells #include <drm/i915_drm.h> 35c0e09200SDave Airlie #include "i915_drv.h" 361c5d22f7SChris Wilson #include "i915_trace.h" 3779e53945SJesse Barnes #include "intel_drv.h" 38c0e09200SDave Airlie 39e5868a31SEgbert Eich static const u32 hpd_ibx[] = { 40e5868a31SEgbert Eich [HPD_CRT] = SDE_CRT_HOTPLUG, 41e5868a31SEgbert Eich [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG, 42e5868a31SEgbert Eich [HPD_PORT_B] = SDE_PORTB_HOTPLUG, 43e5868a31SEgbert Eich [HPD_PORT_C] = SDE_PORTC_HOTPLUG, 44e5868a31SEgbert Eich [HPD_PORT_D] = SDE_PORTD_HOTPLUG 45e5868a31SEgbert Eich }; 46e5868a31SEgbert Eich 47e5868a31SEgbert Eich static const u32 hpd_cpt[] = { 48e5868a31SEgbert Eich [HPD_CRT] = SDE_CRT_HOTPLUG_CPT, 4973c352a2SDaniel Vetter [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT, 50e5868a31SEgbert Eich [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT, 51e5868a31SEgbert Eich [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT, 52e5868a31SEgbert Eich [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT 53e5868a31SEgbert Eich }; 54e5868a31SEgbert Eich 55e5868a31SEgbert Eich static const u32 hpd_mask_i915[] = { 56e5868a31SEgbert Eich [HPD_CRT] = CRT_HOTPLUG_INT_EN, 57e5868a31SEgbert Eich [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN, 58e5868a31SEgbert Eich [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN, 59e5868a31SEgbert Eich [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN, 60e5868a31SEgbert Eich [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN, 61e5868a31SEgbert Eich [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN 62e5868a31SEgbert Eich }; 63e5868a31SEgbert Eich 64e5868a31SEgbert Eich static const u32 hpd_status_gen4[] = { 65e5868a31SEgbert Eich [HPD_CRT] = CRT_HOTPLUG_INT_STATUS, 66e5868a31SEgbert Eich [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X, 67e5868a31SEgbert Eich [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X, 68e5868a31SEgbert Eich [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS, 69e5868a31SEgbert Eich [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS, 70e5868a31SEgbert Eich [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS 71e5868a31SEgbert Eich }; 72e5868a31SEgbert Eich 73e5868a31SEgbert Eich static const u32 hpd_status_i915[] = { /* i915 and valleyview are the same */ 74e5868a31SEgbert Eich [HPD_CRT] = CRT_HOTPLUG_INT_STATUS, 75e5868a31SEgbert Eich [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915, 76e5868a31SEgbert Eich [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915, 77e5868a31SEgbert Eich [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS, 78e5868a31SEgbert Eich [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS, 79e5868a31SEgbert Eich [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS 80e5868a31SEgbert Eich }; 81e5868a31SEgbert Eich 82036a4a7dSZhenyu Wang /* For display hotplug interrupt */ 83995b6762SChris Wilson static void 84f2b115e6SAdam Jackson ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask) 85036a4a7dSZhenyu Wang { 864bc9d430SDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 874bc9d430SDaniel Vetter 881ec14ad3SChris Wilson if ((dev_priv->irq_mask & mask) != 0) { 891ec14ad3SChris Wilson dev_priv->irq_mask &= ~mask; 901ec14ad3SChris Wilson I915_WRITE(DEIMR, dev_priv->irq_mask); 913143a2bfSChris Wilson POSTING_READ(DEIMR); 92036a4a7dSZhenyu Wang } 93036a4a7dSZhenyu Wang } 94036a4a7dSZhenyu Wang 950ff9800aSPaulo Zanoni static void 96f2b115e6SAdam Jackson ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask) 97036a4a7dSZhenyu Wang { 984bc9d430SDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 994bc9d430SDaniel Vetter 1001ec14ad3SChris Wilson if ((dev_priv->irq_mask & mask) != mask) { 1011ec14ad3SChris Wilson dev_priv->irq_mask |= mask; 1021ec14ad3SChris Wilson I915_WRITE(DEIMR, dev_priv->irq_mask); 1033143a2bfSChris Wilson POSTING_READ(DEIMR); 104036a4a7dSZhenyu Wang } 105036a4a7dSZhenyu Wang } 106036a4a7dSZhenyu Wang 10743eaea13SPaulo Zanoni /** 10843eaea13SPaulo Zanoni * ilk_update_gt_irq - update GTIMR 10943eaea13SPaulo Zanoni * @dev_priv: driver private 11043eaea13SPaulo Zanoni * @interrupt_mask: mask of interrupt bits to update 11143eaea13SPaulo Zanoni * @enabled_irq_mask: mask of interrupt bits to enable 11243eaea13SPaulo Zanoni */ 11343eaea13SPaulo Zanoni static void ilk_update_gt_irq(struct drm_i915_private *dev_priv, 11443eaea13SPaulo Zanoni uint32_t interrupt_mask, 11543eaea13SPaulo Zanoni uint32_t enabled_irq_mask) 11643eaea13SPaulo Zanoni { 11743eaea13SPaulo Zanoni assert_spin_locked(&dev_priv->irq_lock); 11843eaea13SPaulo Zanoni 11943eaea13SPaulo Zanoni dev_priv->gt_irq_mask &= ~interrupt_mask; 12043eaea13SPaulo Zanoni dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask); 12143eaea13SPaulo Zanoni I915_WRITE(GTIMR, dev_priv->gt_irq_mask); 12243eaea13SPaulo Zanoni POSTING_READ(GTIMR); 12343eaea13SPaulo Zanoni } 12443eaea13SPaulo Zanoni 12543eaea13SPaulo Zanoni void ilk_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask) 12643eaea13SPaulo Zanoni { 12743eaea13SPaulo Zanoni ilk_update_gt_irq(dev_priv, mask, mask); 12843eaea13SPaulo Zanoni } 12943eaea13SPaulo Zanoni 13043eaea13SPaulo Zanoni void ilk_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask) 13143eaea13SPaulo Zanoni { 13243eaea13SPaulo Zanoni ilk_update_gt_irq(dev_priv, mask, 0); 13343eaea13SPaulo Zanoni } 13443eaea13SPaulo Zanoni 135edbfdb45SPaulo Zanoni /** 136edbfdb45SPaulo Zanoni * snb_update_pm_irq - update GEN6_PMIMR 137edbfdb45SPaulo Zanoni * @dev_priv: driver private 138edbfdb45SPaulo Zanoni * @interrupt_mask: mask of interrupt bits to update 139edbfdb45SPaulo Zanoni * @enabled_irq_mask: mask of interrupt bits to enable 140edbfdb45SPaulo Zanoni */ 141edbfdb45SPaulo Zanoni static void snb_update_pm_irq(struct drm_i915_private *dev_priv, 142edbfdb45SPaulo Zanoni uint32_t interrupt_mask, 143edbfdb45SPaulo Zanoni uint32_t enabled_irq_mask) 144edbfdb45SPaulo Zanoni { 145*f52ecbcfSPaulo Zanoni uint32_t pmimr, new_val; 146edbfdb45SPaulo Zanoni 147edbfdb45SPaulo Zanoni assert_spin_locked(&dev_priv->irq_lock); 148edbfdb45SPaulo Zanoni 149*f52ecbcfSPaulo Zanoni pmimr = new_val = I915_READ(GEN6_PMIMR); 150*f52ecbcfSPaulo Zanoni new_val &= ~interrupt_mask; 151*f52ecbcfSPaulo Zanoni new_val |= (~enabled_irq_mask & interrupt_mask); 152*f52ecbcfSPaulo Zanoni 153*f52ecbcfSPaulo Zanoni if (new_val != pmimr) { 154*f52ecbcfSPaulo Zanoni I915_WRITE(GEN6_PMIMR, new_val); 155edbfdb45SPaulo Zanoni POSTING_READ(GEN6_PMIMR); 156edbfdb45SPaulo Zanoni } 157*f52ecbcfSPaulo Zanoni } 158edbfdb45SPaulo Zanoni 159edbfdb45SPaulo Zanoni void snb_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask) 160edbfdb45SPaulo Zanoni { 161edbfdb45SPaulo Zanoni snb_update_pm_irq(dev_priv, mask, mask); 162edbfdb45SPaulo Zanoni } 163edbfdb45SPaulo Zanoni 164edbfdb45SPaulo Zanoni void snb_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask) 165edbfdb45SPaulo Zanoni { 166edbfdb45SPaulo Zanoni snb_update_pm_irq(dev_priv, mask, 0); 167edbfdb45SPaulo Zanoni } 168edbfdb45SPaulo Zanoni 169edbfdb45SPaulo Zanoni static void snb_set_pm_irq(struct drm_i915_private *dev_priv, uint32_t val) 170edbfdb45SPaulo Zanoni { 171edbfdb45SPaulo Zanoni snb_update_pm_irq(dev_priv, 0xffffffff, ~val); 172edbfdb45SPaulo Zanoni } 173edbfdb45SPaulo Zanoni 1748664281bSPaulo Zanoni static bool ivb_can_enable_err_int(struct drm_device *dev) 1758664281bSPaulo Zanoni { 1768664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 1778664281bSPaulo Zanoni struct intel_crtc *crtc; 1788664281bSPaulo Zanoni enum pipe pipe; 1798664281bSPaulo Zanoni 1804bc9d430SDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 1814bc9d430SDaniel Vetter 1828664281bSPaulo Zanoni for_each_pipe(pipe) { 1838664281bSPaulo Zanoni crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); 1848664281bSPaulo Zanoni 1858664281bSPaulo Zanoni if (crtc->cpu_fifo_underrun_disabled) 1868664281bSPaulo Zanoni return false; 1878664281bSPaulo Zanoni } 1888664281bSPaulo Zanoni 1898664281bSPaulo Zanoni return true; 1908664281bSPaulo Zanoni } 1918664281bSPaulo Zanoni 1928664281bSPaulo Zanoni static bool cpt_can_enable_serr_int(struct drm_device *dev) 1938664281bSPaulo Zanoni { 1948664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 1958664281bSPaulo Zanoni enum pipe pipe; 1968664281bSPaulo Zanoni struct intel_crtc *crtc; 1978664281bSPaulo Zanoni 198fee884edSDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 199fee884edSDaniel Vetter 2008664281bSPaulo Zanoni for_each_pipe(pipe) { 2018664281bSPaulo Zanoni crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); 2028664281bSPaulo Zanoni 2038664281bSPaulo Zanoni if (crtc->pch_fifo_underrun_disabled) 2048664281bSPaulo Zanoni return false; 2058664281bSPaulo Zanoni } 2068664281bSPaulo Zanoni 2078664281bSPaulo Zanoni return true; 2088664281bSPaulo Zanoni } 2098664281bSPaulo Zanoni 2108664281bSPaulo Zanoni static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev, 2118664281bSPaulo Zanoni enum pipe pipe, bool enable) 2128664281bSPaulo Zanoni { 2138664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 2148664281bSPaulo Zanoni uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN : 2158664281bSPaulo Zanoni DE_PIPEB_FIFO_UNDERRUN; 2168664281bSPaulo Zanoni 2178664281bSPaulo Zanoni if (enable) 2188664281bSPaulo Zanoni ironlake_enable_display_irq(dev_priv, bit); 2198664281bSPaulo Zanoni else 2208664281bSPaulo Zanoni ironlake_disable_display_irq(dev_priv, bit); 2218664281bSPaulo Zanoni } 2228664281bSPaulo Zanoni 2238664281bSPaulo Zanoni static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev, 2247336df65SDaniel Vetter enum pipe pipe, bool enable) 2258664281bSPaulo Zanoni { 2268664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 2278664281bSPaulo Zanoni if (enable) { 2287336df65SDaniel Vetter I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe)); 2297336df65SDaniel Vetter 2308664281bSPaulo Zanoni if (!ivb_can_enable_err_int(dev)) 2318664281bSPaulo Zanoni return; 2328664281bSPaulo Zanoni 2338664281bSPaulo Zanoni ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB); 2348664281bSPaulo Zanoni } else { 2357336df65SDaniel Vetter bool was_enabled = !(I915_READ(DEIMR) & DE_ERR_INT_IVB); 2367336df65SDaniel Vetter 2377336df65SDaniel Vetter /* Change the state _after_ we've read out the current one. */ 2388664281bSPaulo Zanoni ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB); 2397336df65SDaniel Vetter 2407336df65SDaniel Vetter if (!was_enabled && 2417336df65SDaniel Vetter (I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe))) { 2427336df65SDaniel Vetter DRM_DEBUG_KMS("uncleared fifo underrun on pipe %c\n", 2437336df65SDaniel Vetter pipe_name(pipe)); 2447336df65SDaniel Vetter } 2458664281bSPaulo Zanoni } 2468664281bSPaulo Zanoni } 2478664281bSPaulo Zanoni 248fee884edSDaniel Vetter /** 249fee884edSDaniel Vetter * ibx_display_interrupt_update - update SDEIMR 250fee884edSDaniel Vetter * @dev_priv: driver private 251fee884edSDaniel Vetter * @interrupt_mask: mask of interrupt bits to update 252fee884edSDaniel Vetter * @enabled_irq_mask: mask of interrupt bits to enable 253fee884edSDaniel Vetter */ 254fee884edSDaniel Vetter static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv, 255fee884edSDaniel Vetter uint32_t interrupt_mask, 256fee884edSDaniel Vetter uint32_t enabled_irq_mask) 257fee884edSDaniel Vetter { 258fee884edSDaniel Vetter uint32_t sdeimr = I915_READ(SDEIMR); 259fee884edSDaniel Vetter sdeimr &= ~interrupt_mask; 260fee884edSDaniel Vetter sdeimr |= (~enabled_irq_mask & interrupt_mask); 261fee884edSDaniel Vetter 262fee884edSDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 263fee884edSDaniel Vetter 264fee884edSDaniel Vetter I915_WRITE(SDEIMR, sdeimr); 265fee884edSDaniel Vetter POSTING_READ(SDEIMR); 266fee884edSDaniel Vetter } 267fee884edSDaniel Vetter #define ibx_enable_display_interrupt(dev_priv, bits) \ 268fee884edSDaniel Vetter ibx_display_interrupt_update((dev_priv), (bits), (bits)) 269fee884edSDaniel Vetter #define ibx_disable_display_interrupt(dev_priv, bits) \ 270fee884edSDaniel Vetter ibx_display_interrupt_update((dev_priv), (bits), 0) 271fee884edSDaniel Vetter 272de28075dSDaniel Vetter static void ibx_set_fifo_underrun_reporting(struct drm_device *dev, 273de28075dSDaniel Vetter enum transcoder pch_transcoder, 2748664281bSPaulo Zanoni bool enable) 2758664281bSPaulo Zanoni { 2768664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 277de28075dSDaniel Vetter uint32_t bit = (pch_transcoder == TRANSCODER_A) ? 278de28075dSDaniel Vetter SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER; 2798664281bSPaulo Zanoni 2808664281bSPaulo Zanoni if (enable) 281fee884edSDaniel Vetter ibx_enable_display_interrupt(dev_priv, bit); 2828664281bSPaulo Zanoni else 283fee884edSDaniel Vetter ibx_disable_display_interrupt(dev_priv, bit); 2848664281bSPaulo Zanoni } 2858664281bSPaulo Zanoni 2868664281bSPaulo Zanoni static void cpt_set_fifo_underrun_reporting(struct drm_device *dev, 2878664281bSPaulo Zanoni enum transcoder pch_transcoder, 2888664281bSPaulo Zanoni bool enable) 2898664281bSPaulo Zanoni { 2908664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 2918664281bSPaulo Zanoni 2928664281bSPaulo Zanoni if (enable) { 2931dd246fbSDaniel Vetter I915_WRITE(SERR_INT, 2941dd246fbSDaniel Vetter SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)); 2951dd246fbSDaniel Vetter 2968664281bSPaulo Zanoni if (!cpt_can_enable_serr_int(dev)) 2978664281bSPaulo Zanoni return; 2988664281bSPaulo Zanoni 299fee884edSDaniel Vetter ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT); 3008664281bSPaulo Zanoni } else { 3011dd246fbSDaniel Vetter uint32_t tmp = I915_READ(SERR_INT); 3021dd246fbSDaniel Vetter bool was_enabled = !(I915_READ(SDEIMR) & SDE_ERROR_CPT); 3031dd246fbSDaniel Vetter 3041dd246fbSDaniel Vetter /* Change the state _after_ we've read out the current one. */ 305fee884edSDaniel Vetter ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT); 3061dd246fbSDaniel Vetter 3071dd246fbSDaniel Vetter if (!was_enabled && 3081dd246fbSDaniel Vetter (tmp & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder))) { 3091dd246fbSDaniel Vetter DRM_DEBUG_KMS("uncleared pch fifo underrun on pch transcoder %c\n", 3101dd246fbSDaniel Vetter transcoder_name(pch_transcoder)); 3111dd246fbSDaniel Vetter } 3128664281bSPaulo Zanoni } 3138664281bSPaulo Zanoni } 3148664281bSPaulo Zanoni 3158664281bSPaulo Zanoni /** 3168664281bSPaulo Zanoni * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages 3178664281bSPaulo Zanoni * @dev: drm device 3188664281bSPaulo Zanoni * @pipe: pipe 3198664281bSPaulo Zanoni * @enable: true if we want to report FIFO underrun errors, false otherwise 3208664281bSPaulo Zanoni * 3218664281bSPaulo Zanoni * This function makes us disable or enable CPU fifo underruns for a specific 3228664281bSPaulo Zanoni * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun 3238664281bSPaulo Zanoni * reporting for one pipe may also disable all the other CPU error interruts for 3248664281bSPaulo Zanoni * the other pipes, due to the fact that there's just one interrupt mask/enable 3258664281bSPaulo Zanoni * bit for all the pipes. 3268664281bSPaulo Zanoni * 3278664281bSPaulo Zanoni * Returns the previous state of underrun reporting. 3288664281bSPaulo Zanoni */ 3298664281bSPaulo Zanoni bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev, 3308664281bSPaulo Zanoni enum pipe pipe, bool enable) 3318664281bSPaulo Zanoni { 3328664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 3338664281bSPaulo Zanoni struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 3348664281bSPaulo Zanoni struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 3358664281bSPaulo Zanoni unsigned long flags; 3368664281bSPaulo Zanoni bool ret; 3378664281bSPaulo Zanoni 3388664281bSPaulo Zanoni spin_lock_irqsave(&dev_priv->irq_lock, flags); 3398664281bSPaulo Zanoni 3408664281bSPaulo Zanoni ret = !intel_crtc->cpu_fifo_underrun_disabled; 3418664281bSPaulo Zanoni 3428664281bSPaulo Zanoni if (enable == ret) 3438664281bSPaulo Zanoni goto done; 3448664281bSPaulo Zanoni 3458664281bSPaulo Zanoni intel_crtc->cpu_fifo_underrun_disabled = !enable; 3468664281bSPaulo Zanoni 3478664281bSPaulo Zanoni if (IS_GEN5(dev) || IS_GEN6(dev)) 3488664281bSPaulo Zanoni ironlake_set_fifo_underrun_reporting(dev, pipe, enable); 3498664281bSPaulo Zanoni else if (IS_GEN7(dev)) 3507336df65SDaniel Vetter ivybridge_set_fifo_underrun_reporting(dev, pipe, enable); 3518664281bSPaulo Zanoni 3528664281bSPaulo Zanoni done: 3538664281bSPaulo Zanoni spin_unlock_irqrestore(&dev_priv->irq_lock, flags); 3548664281bSPaulo Zanoni return ret; 3558664281bSPaulo Zanoni } 3568664281bSPaulo Zanoni 3578664281bSPaulo Zanoni /** 3588664281bSPaulo Zanoni * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages 3598664281bSPaulo Zanoni * @dev: drm device 3608664281bSPaulo Zanoni * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older) 3618664281bSPaulo Zanoni * @enable: true if we want to report FIFO underrun errors, false otherwise 3628664281bSPaulo Zanoni * 3638664281bSPaulo Zanoni * This function makes us disable or enable PCH fifo underruns for a specific 3648664281bSPaulo Zanoni * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO 3658664281bSPaulo Zanoni * underrun reporting for one transcoder may also disable all the other PCH 3668664281bSPaulo Zanoni * error interruts for the other transcoders, due to the fact that there's just 3678664281bSPaulo Zanoni * one interrupt mask/enable bit for all the transcoders. 3688664281bSPaulo Zanoni * 3698664281bSPaulo Zanoni * Returns the previous state of underrun reporting. 3708664281bSPaulo Zanoni */ 3718664281bSPaulo Zanoni bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev, 3728664281bSPaulo Zanoni enum transcoder pch_transcoder, 3738664281bSPaulo Zanoni bool enable) 3748664281bSPaulo Zanoni { 3758664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 376de28075dSDaniel Vetter struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder]; 377de28075dSDaniel Vetter struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 3788664281bSPaulo Zanoni unsigned long flags; 3798664281bSPaulo Zanoni bool ret; 3808664281bSPaulo Zanoni 381de28075dSDaniel Vetter /* 382de28075dSDaniel Vetter * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT 383de28075dSDaniel Vetter * has only one pch transcoder A that all pipes can use. To avoid racy 384de28075dSDaniel Vetter * pch transcoder -> pipe lookups from interrupt code simply store the 385de28075dSDaniel Vetter * underrun statistics in crtc A. Since we never expose this anywhere 386de28075dSDaniel Vetter * nor use it outside of the fifo underrun code here using the "wrong" 387de28075dSDaniel Vetter * crtc on LPT won't cause issues. 388de28075dSDaniel Vetter */ 3898664281bSPaulo Zanoni 3908664281bSPaulo Zanoni spin_lock_irqsave(&dev_priv->irq_lock, flags); 3918664281bSPaulo Zanoni 3928664281bSPaulo Zanoni ret = !intel_crtc->pch_fifo_underrun_disabled; 3938664281bSPaulo Zanoni 3948664281bSPaulo Zanoni if (enable == ret) 3958664281bSPaulo Zanoni goto done; 3968664281bSPaulo Zanoni 3978664281bSPaulo Zanoni intel_crtc->pch_fifo_underrun_disabled = !enable; 3988664281bSPaulo Zanoni 3998664281bSPaulo Zanoni if (HAS_PCH_IBX(dev)) 400de28075dSDaniel Vetter ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable); 4018664281bSPaulo Zanoni else 4028664281bSPaulo Zanoni cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable); 4038664281bSPaulo Zanoni 4048664281bSPaulo Zanoni done: 4058664281bSPaulo Zanoni spin_unlock_irqrestore(&dev_priv->irq_lock, flags); 4068664281bSPaulo Zanoni return ret; 4078664281bSPaulo Zanoni } 4088664281bSPaulo Zanoni 4098664281bSPaulo Zanoni 4107c463586SKeith Packard void 4117c463586SKeith Packard i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask) 4127c463586SKeith Packard { 4139db4a9c7SJesse Barnes u32 reg = PIPESTAT(pipe); 41446c06a30SVille Syrjälä u32 pipestat = I915_READ(reg) & 0x7fff0000; 4157c463586SKeith Packard 416b79480baSDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 417b79480baSDaniel Vetter 41846c06a30SVille Syrjälä if ((pipestat & mask) == mask) 41946c06a30SVille Syrjälä return; 42046c06a30SVille Syrjälä 4217c463586SKeith Packard /* Enable the interrupt, clear any pending status */ 42246c06a30SVille Syrjälä pipestat |= mask | (mask >> 16); 42346c06a30SVille Syrjälä I915_WRITE(reg, pipestat); 4243143a2bfSChris Wilson POSTING_READ(reg); 4257c463586SKeith Packard } 4267c463586SKeith Packard 4277c463586SKeith Packard void 4287c463586SKeith Packard i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask) 4297c463586SKeith Packard { 4309db4a9c7SJesse Barnes u32 reg = PIPESTAT(pipe); 43146c06a30SVille Syrjälä u32 pipestat = I915_READ(reg) & 0x7fff0000; 4327c463586SKeith Packard 433b79480baSDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 434b79480baSDaniel Vetter 43546c06a30SVille Syrjälä if ((pipestat & mask) == 0) 43646c06a30SVille Syrjälä return; 43746c06a30SVille Syrjälä 43846c06a30SVille Syrjälä pipestat &= ~mask; 43946c06a30SVille Syrjälä I915_WRITE(reg, pipestat); 4403143a2bfSChris Wilson POSTING_READ(reg); 4417c463586SKeith Packard } 4427c463586SKeith Packard 443c0e09200SDave Airlie /** 444f49e38ddSJani Nikula * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion 44501c66889SZhao Yakui */ 446f49e38ddSJani Nikula static void i915_enable_asle_pipestat(struct drm_device *dev) 44701c66889SZhao Yakui { 4481ec14ad3SChris Wilson drm_i915_private_t *dev_priv = dev->dev_private; 4491ec14ad3SChris Wilson unsigned long irqflags; 4501ec14ad3SChris Wilson 451f49e38ddSJani Nikula if (!dev_priv->opregion.asle || !IS_MOBILE(dev)) 452f49e38ddSJani Nikula return; 453f49e38ddSJani Nikula 4541ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 45501c66889SZhao Yakui 456f898780bSJani Nikula i915_enable_pipestat(dev_priv, 1, PIPE_LEGACY_BLC_EVENT_ENABLE); 457a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen >= 4) 458f898780bSJani Nikula i915_enable_pipestat(dev_priv, 0, PIPE_LEGACY_BLC_EVENT_ENABLE); 4591ec14ad3SChris Wilson 4601ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 46101c66889SZhao Yakui } 46201c66889SZhao Yakui 46301c66889SZhao Yakui /** 4640a3e67a4SJesse Barnes * i915_pipe_enabled - check if a pipe is enabled 4650a3e67a4SJesse Barnes * @dev: DRM device 4660a3e67a4SJesse Barnes * @pipe: pipe to check 4670a3e67a4SJesse Barnes * 4680a3e67a4SJesse Barnes * Reading certain registers when the pipe is disabled can hang the chip. 4690a3e67a4SJesse Barnes * Use this routine to make sure the PLL is running and the pipe is active 4700a3e67a4SJesse Barnes * before reading such registers if unsure. 4710a3e67a4SJesse Barnes */ 4720a3e67a4SJesse Barnes static int 4730a3e67a4SJesse Barnes i915_pipe_enabled(struct drm_device *dev, int pipe) 4740a3e67a4SJesse Barnes { 4750a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 476702e7a56SPaulo Zanoni 477a01025afSDaniel Vetter if (drm_core_check_feature(dev, DRIVER_MODESET)) { 478a01025afSDaniel Vetter /* Locking is horribly broken here, but whatever. */ 479a01025afSDaniel Vetter struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 480a01025afSDaniel Vetter struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 48171f8ba6bSPaulo Zanoni 482a01025afSDaniel Vetter return intel_crtc->active; 483a01025afSDaniel Vetter } else { 484a01025afSDaniel Vetter return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE; 485a01025afSDaniel Vetter } 4860a3e67a4SJesse Barnes } 4870a3e67a4SJesse Barnes 48842f52ef8SKeith Packard /* Called from drm generic code, passed a 'crtc', which 48942f52ef8SKeith Packard * we use as a pipe index 49042f52ef8SKeith Packard */ 491f71d4af4SJesse Barnes static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe) 4920a3e67a4SJesse Barnes { 4930a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 4940a3e67a4SJesse Barnes unsigned long high_frame; 4950a3e67a4SJesse Barnes unsigned long low_frame; 4965eddb70bSChris Wilson u32 high1, high2, low; 4970a3e67a4SJesse Barnes 4980a3e67a4SJesse Barnes if (!i915_pipe_enabled(dev, pipe)) { 49944d98a61SZhao Yakui DRM_DEBUG_DRIVER("trying to get vblank count for disabled " 5009db4a9c7SJesse Barnes "pipe %c\n", pipe_name(pipe)); 5010a3e67a4SJesse Barnes return 0; 5020a3e67a4SJesse Barnes } 5030a3e67a4SJesse Barnes 5049db4a9c7SJesse Barnes high_frame = PIPEFRAME(pipe); 5059db4a9c7SJesse Barnes low_frame = PIPEFRAMEPIXEL(pipe); 5065eddb70bSChris Wilson 5070a3e67a4SJesse Barnes /* 5080a3e67a4SJesse Barnes * High & low register fields aren't synchronized, so make sure 5090a3e67a4SJesse Barnes * we get a low value that's stable across two reads of the high 5100a3e67a4SJesse Barnes * register. 5110a3e67a4SJesse Barnes */ 5120a3e67a4SJesse Barnes do { 5135eddb70bSChris Wilson high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; 5145eddb70bSChris Wilson low = I915_READ(low_frame) & PIPE_FRAME_LOW_MASK; 5155eddb70bSChris Wilson high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; 5160a3e67a4SJesse Barnes } while (high1 != high2); 5170a3e67a4SJesse Barnes 5185eddb70bSChris Wilson high1 >>= PIPE_FRAME_HIGH_SHIFT; 5195eddb70bSChris Wilson low >>= PIPE_FRAME_LOW_SHIFT; 5205eddb70bSChris Wilson return (high1 << 8) | low; 5210a3e67a4SJesse Barnes } 5220a3e67a4SJesse Barnes 523f71d4af4SJesse Barnes static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe) 5249880b7a5SJesse Barnes { 5259880b7a5SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 5269db4a9c7SJesse Barnes int reg = PIPE_FRMCOUNT_GM45(pipe); 5279880b7a5SJesse Barnes 5289880b7a5SJesse Barnes if (!i915_pipe_enabled(dev, pipe)) { 52944d98a61SZhao Yakui DRM_DEBUG_DRIVER("trying to get vblank count for disabled " 5309db4a9c7SJesse Barnes "pipe %c\n", pipe_name(pipe)); 5319880b7a5SJesse Barnes return 0; 5329880b7a5SJesse Barnes } 5339880b7a5SJesse Barnes 5349880b7a5SJesse Barnes return I915_READ(reg); 5359880b7a5SJesse Barnes } 5369880b7a5SJesse Barnes 537f71d4af4SJesse Barnes static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe, 5380af7e4dfSMario Kleiner int *vpos, int *hpos) 5390af7e4dfSMario Kleiner { 5400af7e4dfSMario Kleiner drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 5410af7e4dfSMario Kleiner u32 vbl = 0, position = 0; 5420af7e4dfSMario Kleiner int vbl_start, vbl_end, htotal, vtotal; 5430af7e4dfSMario Kleiner bool in_vbl = true; 5440af7e4dfSMario Kleiner int ret = 0; 545fe2b8f9dSPaulo Zanoni enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, 546fe2b8f9dSPaulo Zanoni pipe); 5470af7e4dfSMario Kleiner 5480af7e4dfSMario Kleiner if (!i915_pipe_enabled(dev, pipe)) { 5490af7e4dfSMario Kleiner DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled " 5509db4a9c7SJesse Barnes "pipe %c\n", pipe_name(pipe)); 5510af7e4dfSMario Kleiner return 0; 5520af7e4dfSMario Kleiner } 5530af7e4dfSMario Kleiner 5540af7e4dfSMario Kleiner /* Get vtotal. */ 555fe2b8f9dSPaulo Zanoni vtotal = 1 + ((I915_READ(VTOTAL(cpu_transcoder)) >> 16) & 0x1fff); 5560af7e4dfSMario Kleiner 5570af7e4dfSMario Kleiner if (INTEL_INFO(dev)->gen >= 4) { 5580af7e4dfSMario Kleiner /* No obvious pixelcount register. Only query vertical 5590af7e4dfSMario Kleiner * scanout position from Display scan line register. 5600af7e4dfSMario Kleiner */ 5610af7e4dfSMario Kleiner position = I915_READ(PIPEDSL(pipe)); 5620af7e4dfSMario Kleiner 5630af7e4dfSMario Kleiner /* Decode into vertical scanout position. Don't have 5640af7e4dfSMario Kleiner * horizontal scanout position. 5650af7e4dfSMario Kleiner */ 5660af7e4dfSMario Kleiner *vpos = position & 0x1fff; 5670af7e4dfSMario Kleiner *hpos = 0; 5680af7e4dfSMario Kleiner } else { 5690af7e4dfSMario Kleiner /* Have access to pixelcount since start of frame. 5700af7e4dfSMario Kleiner * We can split this into vertical and horizontal 5710af7e4dfSMario Kleiner * scanout position. 5720af7e4dfSMario Kleiner */ 5730af7e4dfSMario Kleiner position = (I915_READ(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT; 5740af7e4dfSMario Kleiner 575fe2b8f9dSPaulo Zanoni htotal = 1 + ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff); 5760af7e4dfSMario Kleiner *vpos = position / htotal; 5770af7e4dfSMario Kleiner *hpos = position - (*vpos * htotal); 5780af7e4dfSMario Kleiner } 5790af7e4dfSMario Kleiner 5800af7e4dfSMario Kleiner /* Query vblank area. */ 581fe2b8f9dSPaulo Zanoni vbl = I915_READ(VBLANK(cpu_transcoder)); 5820af7e4dfSMario Kleiner 5830af7e4dfSMario Kleiner /* Test position against vblank region. */ 5840af7e4dfSMario Kleiner vbl_start = vbl & 0x1fff; 5850af7e4dfSMario Kleiner vbl_end = (vbl >> 16) & 0x1fff; 5860af7e4dfSMario Kleiner 5870af7e4dfSMario Kleiner if ((*vpos < vbl_start) || (*vpos > vbl_end)) 5880af7e4dfSMario Kleiner in_vbl = false; 5890af7e4dfSMario Kleiner 5900af7e4dfSMario Kleiner /* Inside "upper part" of vblank area? Apply corrective offset: */ 5910af7e4dfSMario Kleiner if (in_vbl && (*vpos >= vbl_start)) 5920af7e4dfSMario Kleiner *vpos = *vpos - vtotal; 5930af7e4dfSMario Kleiner 5940af7e4dfSMario Kleiner /* Readouts valid? */ 5950af7e4dfSMario Kleiner if (vbl > 0) 5960af7e4dfSMario Kleiner ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE; 5970af7e4dfSMario Kleiner 5980af7e4dfSMario Kleiner /* In vblank? */ 5990af7e4dfSMario Kleiner if (in_vbl) 6000af7e4dfSMario Kleiner ret |= DRM_SCANOUTPOS_INVBL; 6010af7e4dfSMario Kleiner 6020af7e4dfSMario Kleiner return ret; 6030af7e4dfSMario Kleiner } 6040af7e4dfSMario Kleiner 605f71d4af4SJesse Barnes static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe, 6060af7e4dfSMario Kleiner int *max_error, 6070af7e4dfSMario Kleiner struct timeval *vblank_time, 6080af7e4dfSMario Kleiner unsigned flags) 6090af7e4dfSMario Kleiner { 6104041b853SChris Wilson struct drm_crtc *crtc; 6110af7e4dfSMario Kleiner 6127eb552aeSBen Widawsky if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) { 6134041b853SChris Wilson DRM_ERROR("Invalid crtc %d\n", pipe); 6140af7e4dfSMario Kleiner return -EINVAL; 6150af7e4dfSMario Kleiner } 6160af7e4dfSMario Kleiner 6170af7e4dfSMario Kleiner /* Get drm_crtc to timestamp: */ 6184041b853SChris Wilson crtc = intel_get_crtc_for_pipe(dev, pipe); 6194041b853SChris Wilson if (crtc == NULL) { 6204041b853SChris Wilson DRM_ERROR("Invalid crtc %d\n", pipe); 6214041b853SChris Wilson return -EINVAL; 6224041b853SChris Wilson } 6234041b853SChris Wilson 6244041b853SChris Wilson if (!crtc->enabled) { 6254041b853SChris Wilson DRM_DEBUG_KMS("crtc %d is disabled\n", pipe); 6264041b853SChris Wilson return -EBUSY; 6274041b853SChris Wilson } 6280af7e4dfSMario Kleiner 6290af7e4dfSMario Kleiner /* Helper routine in DRM core does all the work: */ 6304041b853SChris Wilson return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error, 6314041b853SChris Wilson vblank_time, flags, 6324041b853SChris Wilson crtc); 6330af7e4dfSMario Kleiner } 6340af7e4dfSMario Kleiner 635321a1b30SEgbert Eich static int intel_hpd_irq_event(struct drm_device *dev, struct drm_connector *connector) 636321a1b30SEgbert Eich { 637321a1b30SEgbert Eich enum drm_connector_status old_status; 638321a1b30SEgbert Eich 639321a1b30SEgbert Eich WARN_ON(!mutex_is_locked(&dev->mode_config.mutex)); 640321a1b30SEgbert Eich old_status = connector->status; 641321a1b30SEgbert Eich 642321a1b30SEgbert Eich connector->status = connector->funcs->detect(connector, false); 643321a1b30SEgbert Eich DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %d to %d\n", 644321a1b30SEgbert Eich connector->base.id, 645321a1b30SEgbert Eich drm_get_connector_name(connector), 646321a1b30SEgbert Eich old_status, connector->status); 647321a1b30SEgbert Eich return (old_status != connector->status); 648321a1b30SEgbert Eich } 649321a1b30SEgbert Eich 6505ca58282SJesse Barnes /* 6515ca58282SJesse Barnes * Handle hotplug events outside the interrupt handler proper. 6525ca58282SJesse Barnes */ 653ac4c16c5SEgbert Eich #define I915_REENABLE_HOTPLUG_DELAY (2*60*1000) 654ac4c16c5SEgbert Eich 6555ca58282SJesse Barnes static void i915_hotplug_work_func(struct work_struct *work) 6565ca58282SJesse Barnes { 6575ca58282SJesse Barnes drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, 6585ca58282SJesse Barnes hotplug_work); 6595ca58282SJesse Barnes struct drm_device *dev = dev_priv->dev; 660c31c4ba3SKeith Packard struct drm_mode_config *mode_config = &dev->mode_config; 661cd569aedSEgbert Eich struct intel_connector *intel_connector; 662cd569aedSEgbert Eich struct intel_encoder *intel_encoder; 663cd569aedSEgbert Eich struct drm_connector *connector; 664cd569aedSEgbert Eich unsigned long irqflags; 665cd569aedSEgbert Eich bool hpd_disabled = false; 666321a1b30SEgbert Eich bool changed = false; 667142e2398SEgbert Eich u32 hpd_event_bits; 6685ca58282SJesse Barnes 66952d7ecedSDaniel Vetter /* HPD irq before everything is fully set up. */ 67052d7ecedSDaniel Vetter if (!dev_priv->enable_hotplug_processing) 67152d7ecedSDaniel Vetter return; 67252d7ecedSDaniel Vetter 673a65e34c7SKeith Packard mutex_lock(&mode_config->mutex); 674e67189abSJesse Barnes DRM_DEBUG_KMS("running encoder hotplug functions\n"); 675e67189abSJesse Barnes 676cd569aedSEgbert Eich spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 677142e2398SEgbert Eich 678142e2398SEgbert Eich hpd_event_bits = dev_priv->hpd_event_bits; 679142e2398SEgbert Eich dev_priv->hpd_event_bits = 0; 680cd569aedSEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 681cd569aedSEgbert Eich intel_connector = to_intel_connector(connector); 682cd569aedSEgbert Eich intel_encoder = intel_connector->encoder; 683cd569aedSEgbert Eich if (intel_encoder->hpd_pin > HPD_NONE && 684cd569aedSEgbert Eich dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED && 685cd569aedSEgbert Eich connector->polled == DRM_CONNECTOR_POLL_HPD) { 686cd569aedSEgbert Eich DRM_INFO("HPD interrupt storm detected on connector %s: " 687cd569aedSEgbert Eich "switching from hotplug detection to polling\n", 688cd569aedSEgbert Eich drm_get_connector_name(connector)); 689cd569aedSEgbert Eich dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED; 690cd569aedSEgbert Eich connector->polled = DRM_CONNECTOR_POLL_CONNECT 691cd569aedSEgbert Eich | DRM_CONNECTOR_POLL_DISCONNECT; 692cd569aedSEgbert Eich hpd_disabled = true; 693cd569aedSEgbert Eich } 694142e2398SEgbert Eich if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) { 695142e2398SEgbert Eich DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n", 696142e2398SEgbert Eich drm_get_connector_name(connector), intel_encoder->hpd_pin); 697142e2398SEgbert Eich } 698cd569aedSEgbert Eich } 699cd569aedSEgbert Eich /* if there were no outputs to poll, poll was disabled, 700cd569aedSEgbert Eich * therefore make sure it's enabled when disabling HPD on 701cd569aedSEgbert Eich * some connectors */ 702ac4c16c5SEgbert Eich if (hpd_disabled) { 703cd569aedSEgbert Eich drm_kms_helper_poll_enable(dev); 704ac4c16c5SEgbert Eich mod_timer(&dev_priv->hotplug_reenable_timer, 705ac4c16c5SEgbert Eich jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY)); 706ac4c16c5SEgbert Eich } 707cd569aedSEgbert Eich 708cd569aedSEgbert Eich spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 709cd569aedSEgbert Eich 710321a1b30SEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 711321a1b30SEgbert Eich intel_connector = to_intel_connector(connector); 712321a1b30SEgbert Eich intel_encoder = intel_connector->encoder; 713321a1b30SEgbert Eich if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) { 714cd569aedSEgbert Eich if (intel_encoder->hot_plug) 715cd569aedSEgbert Eich intel_encoder->hot_plug(intel_encoder); 716321a1b30SEgbert Eich if (intel_hpd_irq_event(dev, connector)) 717321a1b30SEgbert Eich changed = true; 718321a1b30SEgbert Eich } 719321a1b30SEgbert Eich } 72040ee3381SKeith Packard mutex_unlock(&mode_config->mutex); 72140ee3381SKeith Packard 722321a1b30SEgbert Eich if (changed) 723321a1b30SEgbert Eich drm_kms_helper_hotplug_event(dev); 7245ca58282SJesse Barnes } 7255ca58282SJesse Barnes 726d0ecd7e2SDaniel Vetter static void ironlake_rps_change_irq_handler(struct drm_device *dev) 727f97108d1SJesse Barnes { 728f97108d1SJesse Barnes drm_i915_private_t *dev_priv = dev->dev_private; 729b5b72e89SMatthew Garrett u32 busy_up, busy_down, max_avg, min_avg; 7309270388eSDaniel Vetter u8 new_delay; 7319270388eSDaniel Vetter 732d0ecd7e2SDaniel Vetter spin_lock(&mchdev_lock); 733f97108d1SJesse Barnes 73473edd18fSDaniel Vetter I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS)); 73573edd18fSDaniel Vetter 73620e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay; 7379270388eSDaniel Vetter 7387648fa99SJesse Barnes I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG); 739b5b72e89SMatthew Garrett busy_up = I915_READ(RCPREVBSYTUPAVG); 740b5b72e89SMatthew Garrett busy_down = I915_READ(RCPREVBSYTDNAVG); 741f97108d1SJesse Barnes max_avg = I915_READ(RCBMAXAVG); 742f97108d1SJesse Barnes min_avg = I915_READ(RCBMINAVG); 743f97108d1SJesse Barnes 744f97108d1SJesse Barnes /* Handle RCS change request from hw */ 745b5b72e89SMatthew Garrett if (busy_up > max_avg) { 74620e4d407SDaniel Vetter if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay) 74720e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay - 1; 74820e4d407SDaniel Vetter if (new_delay < dev_priv->ips.max_delay) 74920e4d407SDaniel Vetter new_delay = dev_priv->ips.max_delay; 750b5b72e89SMatthew Garrett } else if (busy_down < min_avg) { 75120e4d407SDaniel Vetter if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay) 75220e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay + 1; 75320e4d407SDaniel Vetter if (new_delay > dev_priv->ips.min_delay) 75420e4d407SDaniel Vetter new_delay = dev_priv->ips.min_delay; 755f97108d1SJesse Barnes } 756f97108d1SJesse Barnes 7577648fa99SJesse Barnes if (ironlake_set_drps(dev, new_delay)) 75820e4d407SDaniel Vetter dev_priv->ips.cur_delay = new_delay; 759f97108d1SJesse Barnes 760d0ecd7e2SDaniel Vetter spin_unlock(&mchdev_lock); 7619270388eSDaniel Vetter 762f97108d1SJesse Barnes return; 763f97108d1SJesse Barnes } 764f97108d1SJesse Barnes 765549f7365SChris Wilson static void notify_ring(struct drm_device *dev, 766549f7365SChris Wilson struct intel_ring_buffer *ring) 767549f7365SChris Wilson { 768475553deSChris Wilson if (ring->obj == NULL) 769475553deSChris Wilson return; 770475553deSChris Wilson 771b2eadbc8SChris Wilson trace_i915_gem_request_complete(ring, ring->get_seqno(ring, false)); 7729862e600SChris Wilson 773549f7365SChris Wilson wake_up_all(&ring->irq_queue); 77410cd45b6SMika Kuoppala i915_queue_hangcheck(dev); 775549f7365SChris Wilson } 776549f7365SChris Wilson 7774912d041SBen Widawsky static void gen6_pm_rps_work(struct work_struct *work) 7783b8d8d91SJesse Barnes { 7794912d041SBen Widawsky drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, 780c6a828d3SDaniel Vetter rps.work); 781edbfdb45SPaulo Zanoni u32 pm_iir; 7827b9e0ae6SChris Wilson u8 new_delay; 7833b8d8d91SJesse Barnes 78459cdb63dSDaniel Vetter spin_lock_irq(&dev_priv->irq_lock); 785c6a828d3SDaniel Vetter pm_iir = dev_priv->rps.pm_iir; 786c6a828d3SDaniel Vetter dev_priv->rps.pm_iir = 0; 7874848405cSBen Widawsky /* Make sure not to corrupt PMIMR state used by ringbuffer code */ 788edbfdb45SPaulo Zanoni snb_enable_pm_irq(dev_priv, GEN6_PM_RPS_EVENTS); 78959cdb63dSDaniel Vetter spin_unlock_irq(&dev_priv->irq_lock); 7904912d041SBen Widawsky 7914848405cSBen Widawsky if ((pm_iir & GEN6_PM_RPS_EVENTS) == 0) 7923b8d8d91SJesse Barnes return; 7933b8d8d91SJesse Barnes 7944fc688ceSJesse Barnes mutex_lock(&dev_priv->rps.hw_lock); 7957b9e0ae6SChris Wilson 7967425034aSVille Syrjälä if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) { 797c6a828d3SDaniel Vetter new_delay = dev_priv->rps.cur_delay + 1; 7987425034aSVille Syrjälä 7997425034aSVille Syrjälä /* 8007425034aSVille Syrjälä * For better performance, jump directly 8017425034aSVille Syrjälä * to RPe if we're below it. 8027425034aSVille Syrjälä */ 8037425034aSVille Syrjälä if (IS_VALLEYVIEW(dev_priv->dev) && 8047425034aSVille Syrjälä dev_priv->rps.cur_delay < dev_priv->rps.rpe_delay) 8057425034aSVille Syrjälä new_delay = dev_priv->rps.rpe_delay; 8067425034aSVille Syrjälä } else 807c6a828d3SDaniel Vetter new_delay = dev_priv->rps.cur_delay - 1; 8083b8d8d91SJesse Barnes 80979249636SBen Widawsky /* sysfs frequency interfaces may have snuck in while servicing the 81079249636SBen Widawsky * interrupt 81179249636SBen Widawsky */ 812d8289c9eSVille Syrjälä if (new_delay >= dev_priv->rps.min_delay && 813d8289c9eSVille Syrjälä new_delay <= dev_priv->rps.max_delay) { 8140a073b84SJesse Barnes if (IS_VALLEYVIEW(dev_priv->dev)) 8150a073b84SJesse Barnes valleyview_set_rps(dev_priv->dev, new_delay); 8160a073b84SJesse Barnes else 8174912d041SBen Widawsky gen6_set_rps(dev_priv->dev, new_delay); 81879249636SBen Widawsky } 8193b8d8d91SJesse Barnes 82052ceb908SJesse Barnes if (IS_VALLEYVIEW(dev_priv->dev)) { 82152ceb908SJesse Barnes /* 82252ceb908SJesse Barnes * On VLV, when we enter RC6 we may not be at the minimum 82352ceb908SJesse Barnes * voltage level, so arm a timer to check. It should only 82452ceb908SJesse Barnes * fire when there's activity or once after we've entered 82552ceb908SJesse Barnes * RC6, and then won't be re-armed until the next RPS interrupt. 82652ceb908SJesse Barnes */ 82752ceb908SJesse Barnes mod_delayed_work(dev_priv->wq, &dev_priv->rps.vlv_work, 82852ceb908SJesse Barnes msecs_to_jiffies(100)); 82952ceb908SJesse Barnes } 83052ceb908SJesse Barnes 8314fc688ceSJesse Barnes mutex_unlock(&dev_priv->rps.hw_lock); 8323b8d8d91SJesse Barnes } 8333b8d8d91SJesse Barnes 834e3689190SBen Widawsky 835e3689190SBen Widawsky /** 836e3689190SBen Widawsky * ivybridge_parity_work - Workqueue called when a parity error interrupt 837e3689190SBen Widawsky * occurred. 838e3689190SBen Widawsky * @work: workqueue struct 839e3689190SBen Widawsky * 840e3689190SBen Widawsky * Doesn't actually do anything except notify userspace. As a consequence of 841e3689190SBen Widawsky * this event, userspace should try to remap the bad rows since statistically 842e3689190SBen Widawsky * it is likely the same row is more likely to go bad again. 843e3689190SBen Widawsky */ 844e3689190SBen Widawsky static void ivybridge_parity_work(struct work_struct *work) 845e3689190SBen Widawsky { 846e3689190SBen Widawsky drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, 847a4da4fa4SDaniel Vetter l3_parity.error_work); 848e3689190SBen Widawsky u32 error_status, row, bank, subbank; 849e3689190SBen Widawsky char *parity_event[5]; 850e3689190SBen Widawsky uint32_t misccpctl; 851e3689190SBen Widawsky unsigned long flags; 852e3689190SBen Widawsky 853e3689190SBen Widawsky /* We must turn off DOP level clock gating to access the L3 registers. 854e3689190SBen Widawsky * In order to prevent a get/put style interface, acquire struct mutex 855e3689190SBen Widawsky * any time we access those registers. 856e3689190SBen Widawsky */ 857e3689190SBen Widawsky mutex_lock(&dev_priv->dev->struct_mutex); 858e3689190SBen Widawsky 859e3689190SBen Widawsky misccpctl = I915_READ(GEN7_MISCCPCTL); 860e3689190SBen Widawsky I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); 861e3689190SBen Widawsky POSTING_READ(GEN7_MISCCPCTL); 862e3689190SBen Widawsky 863e3689190SBen Widawsky error_status = I915_READ(GEN7_L3CDERRST1); 864e3689190SBen Widawsky row = GEN7_PARITY_ERROR_ROW(error_status); 865e3689190SBen Widawsky bank = GEN7_PARITY_ERROR_BANK(error_status); 866e3689190SBen Widawsky subbank = GEN7_PARITY_ERROR_SUBBANK(error_status); 867e3689190SBen Widawsky 868e3689190SBen Widawsky I915_WRITE(GEN7_L3CDERRST1, GEN7_PARITY_ERROR_VALID | 869e3689190SBen Widawsky GEN7_L3CDERRST1_ENABLE); 870e3689190SBen Widawsky POSTING_READ(GEN7_L3CDERRST1); 871e3689190SBen Widawsky 872e3689190SBen Widawsky I915_WRITE(GEN7_MISCCPCTL, misccpctl); 873e3689190SBen Widawsky 874e3689190SBen Widawsky spin_lock_irqsave(&dev_priv->irq_lock, flags); 87543eaea13SPaulo Zanoni ilk_enable_gt_irq(dev_priv, GT_RENDER_L3_PARITY_ERROR_INTERRUPT); 876e3689190SBen Widawsky spin_unlock_irqrestore(&dev_priv->irq_lock, flags); 877e3689190SBen Widawsky 878e3689190SBen Widawsky mutex_unlock(&dev_priv->dev->struct_mutex); 879e3689190SBen Widawsky 880cce723edSBen Widawsky parity_event[0] = I915_L3_PARITY_UEVENT "=1"; 881e3689190SBen Widawsky parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row); 882e3689190SBen Widawsky parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank); 883e3689190SBen Widawsky parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank); 884e3689190SBen Widawsky parity_event[4] = NULL; 885e3689190SBen Widawsky 886e3689190SBen Widawsky kobject_uevent_env(&dev_priv->dev->primary->kdev.kobj, 887e3689190SBen Widawsky KOBJ_CHANGE, parity_event); 888e3689190SBen Widawsky 889e3689190SBen Widawsky DRM_DEBUG("Parity error: Row = %d, Bank = %d, Sub bank = %d.\n", 890e3689190SBen Widawsky row, bank, subbank); 891e3689190SBen Widawsky 892e3689190SBen Widawsky kfree(parity_event[3]); 893e3689190SBen Widawsky kfree(parity_event[2]); 894e3689190SBen Widawsky kfree(parity_event[1]); 895e3689190SBen Widawsky } 896e3689190SBen Widawsky 897d0ecd7e2SDaniel Vetter static void ivybridge_parity_error_irq_handler(struct drm_device *dev) 898e3689190SBen Widawsky { 899e3689190SBen Widawsky drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 900e3689190SBen Widawsky 901e1ef7cc2SBen Widawsky if (!HAS_L3_GPU_CACHE(dev)) 902e3689190SBen Widawsky return; 903e3689190SBen Widawsky 904d0ecd7e2SDaniel Vetter spin_lock(&dev_priv->irq_lock); 90543eaea13SPaulo Zanoni ilk_disable_gt_irq(dev_priv, GT_RENDER_L3_PARITY_ERROR_INTERRUPT); 906d0ecd7e2SDaniel Vetter spin_unlock(&dev_priv->irq_lock); 907e3689190SBen Widawsky 908a4da4fa4SDaniel Vetter queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work); 909e3689190SBen Widawsky } 910e3689190SBen Widawsky 911f1af8fc1SPaulo Zanoni static void ilk_gt_irq_handler(struct drm_device *dev, 912f1af8fc1SPaulo Zanoni struct drm_i915_private *dev_priv, 913f1af8fc1SPaulo Zanoni u32 gt_iir) 914f1af8fc1SPaulo Zanoni { 915f1af8fc1SPaulo Zanoni if (gt_iir & 916f1af8fc1SPaulo Zanoni (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT)) 917f1af8fc1SPaulo Zanoni notify_ring(dev, &dev_priv->ring[RCS]); 918f1af8fc1SPaulo Zanoni if (gt_iir & ILK_BSD_USER_INTERRUPT) 919f1af8fc1SPaulo Zanoni notify_ring(dev, &dev_priv->ring[VCS]); 920f1af8fc1SPaulo Zanoni } 921f1af8fc1SPaulo Zanoni 922e7b4c6b1SDaniel Vetter static void snb_gt_irq_handler(struct drm_device *dev, 923e7b4c6b1SDaniel Vetter struct drm_i915_private *dev_priv, 924e7b4c6b1SDaniel Vetter u32 gt_iir) 925e7b4c6b1SDaniel Vetter { 926e7b4c6b1SDaniel Vetter 927cc609d5dSBen Widawsky if (gt_iir & 928cc609d5dSBen Widawsky (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT)) 929e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[RCS]); 930cc609d5dSBen Widawsky if (gt_iir & GT_BSD_USER_INTERRUPT) 931e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[VCS]); 932cc609d5dSBen Widawsky if (gt_iir & GT_BLT_USER_INTERRUPT) 933e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[BCS]); 934e7b4c6b1SDaniel Vetter 935cc609d5dSBen Widawsky if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT | 936cc609d5dSBen Widawsky GT_BSD_CS_ERROR_INTERRUPT | 937cc609d5dSBen Widawsky GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) { 938e7b4c6b1SDaniel Vetter DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir); 939e7b4c6b1SDaniel Vetter i915_handle_error(dev, false); 940e7b4c6b1SDaniel Vetter } 941e3689190SBen Widawsky 942cc609d5dSBen Widawsky if (gt_iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT) 943d0ecd7e2SDaniel Vetter ivybridge_parity_error_irq_handler(dev); 944e7b4c6b1SDaniel Vetter } 945e7b4c6b1SDaniel Vetter 946baf02a1fSBen Widawsky /* Legacy way of handling PM interrupts */ 947d0ecd7e2SDaniel Vetter static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, 948fc6826d1SChris Wilson u32 pm_iir) 949fc6826d1SChris Wilson { 950fc6826d1SChris Wilson /* 951fc6826d1SChris Wilson * IIR bits should never already be set because IMR should 952fc6826d1SChris Wilson * prevent an interrupt from being shown in IIR. The warning 953fc6826d1SChris Wilson * displays a case where we've unsafely cleared 954c6a828d3SDaniel Vetter * dev_priv->rps.pm_iir. Although missing an interrupt of the same 955fc6826d1SChris Wilson * type is not a problem, it displays a problem in the logic. 956fc6826d1SChris Wilson * 957c6a828d3SDaniel Vetter * The mask bit in IMR is cleared by dev_priv->rps.work. 958fc6826d1SChris Wilson */ 959fc6826d1SChris Wilson 96059cdb63dSDaniel Vetter spin_lock(&dev_priv->irq_lock); 961c6a828d3SDaniel Vetter dev_priv->rps.pm_iir |= pm_iir; 962edbfdb45SPaulo Zanoni snb_set_pm_irq(dev_priv, dev_priv->rps.pm_iir); 96359cdb63dSDaniel Vetter spin_unlock(&dev_priv->irq_lock); 964fc6826d1SChris Wilson 965c6a828d3SDaniel Vetter queue_work(dev_priv->wq, &dev_priv->rps.work); 966fc6826d1SChris Wilson } 967fc6826d1SChris Wilson 968b543fb04SEgbert Eich #define HPD_STORM_DETECT_PERIOD 1000 969b543fb04SEgbert Eich #define HPD_STORM_THRESHOLD 5 970b543fb04SEgbert Eich 97110a504deSDaniel Vetter static inline void intel_hpd_irq_handler(struct drm_device *dev, 972b543fb04SEgbert Eich u32 hotplug_trigger, 973b543fb04SEgbert Eich const u32 *hpd) 974b543fb04SEgbert Eich { 975b543fb04SEgbert Eich drm_i915_private_t *dev_priv = dev->dev_private; 976b543fb04SEgbert Eich int i; 97710a504deSDaniel Vetter bool storm_detected = false; 978b543fb04SEgbert Eich 97991d131d2SDaniel Vetter if (!hotplug_trigger) 98091d131d2SDaniel Vetter return; 98191d131d2SDaniel Vetter 982b5ea2d56SDaniel Vetter spin_lock(&dev_priv->irq_lock); 983b543fb04SEgbert Eich for (i = 1; i < HPD_NUM_PINS; i++) { 984821450c6SEgbert Eich 985b8f102e8SEgbert Eich WARN(((hpd[i] & hotplug_trigger) && 986b8f102e8SEgbert Eich dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED), 987b8f102e8SEgbert Eich "Received HPD interrupt although disabled\n"); 988b8f102e8SEgbert Eich 989b543fb04SEgbert Eich if (!(hpd[i] & hotplug_trigger) || 990b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED) 991b543fb04SEgbert Eich continue; 992b543fb04SEgbert Eich 993bc5ead8cSJani Nikula dev_priv->hpd_event_bits |= (1 << i); 994b543fb04SEgbert Eich if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies, 995b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_last_jiffies 996b543fb04SEgbert Eich + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) { 997b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies; 998b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt = 0; 999b8f102e8SEgbert Eich DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i); 1000b543fb04SEgbert Eich } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) { 1001b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED; 1002142e2398SEgbert Eich dev_priv->hpd_event_bits &= ~(1 << i); 1003b543fb04SEgbert Eich DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i); 100410a504deSDaniel Vetter storm_detected = true; 1005b543fb04SEgbert Eich } else { 1006b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt++; 1007b8f102e8SEgbert Eich DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i, 1008b8f102e8SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt); 1009b543fb04SEgbert Eich } 1010b543fb04SEgbert Eich } 1011b543fb04SEgbert Eich 101210a504deSDaniel Vetter if (storm_detected) 101310a504deSDaniel Vetter dev_priv->display.hpd_irq_setup(dev); 1014b5ea2d56SDaniel Vetter spin_unlock(&dev_priv->irq_lock); 10155876fa0dSDaniel Vetter 10165876fa0dSDaniel Vetter queue_work(dev_priv->wq, 10175876fa0dSDaniel Vetter &dev_priv->hotplug_work); 1018b543fb04SEgbert Eich } 1019b543fb04SEgbert Eich 1020515ac2bbSDaniel Vetter static void gmbus_irq_handler(struct drm_device *dev) 1021515ac2bbSDaniel Vetter { 102228c70f16SDaniel Vetter struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private; 102328c70f16SDaniel Vetter 102428c70f16SDaniel Vetter wake_up_all(&dev_priv->gmbus_wait_queue); 1025515ac2bbSDaniel Vetter } 1026515ac2bbSDaniel Vetter 1027ce99c256SDaniel Vetter static void dp_aux_irq_handler(struct drm_device *dev) 1028ce99c256SDaniel Vetter { 10299ee32feaSDaniel Vetter struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private; 10309ee32feaSDaniel Vetter 10319ee32feaSDaniel Vetter wake_up_all(&dev_priv->gmbus_wait_queue); 1032ce99c256SDaniel Vetter } 1033ce99c256SDaniel Vetter 1034d0ecd7e2SDaniel Vetter /* Unlike gen6_rps_irq_handler() from which this function is originally derived, 1035baf02a1fSBen Widawsky * we must be able to deal with other PM interrupts. This is complicated because 1036baf02a1fSBen Widawsky * of the way in which we use the masks to defer the RPS work (which for 1037baf02a1fSBen Widawsky * posterity is necessary because of forcewake). 1038baf02a1fSBen Widawsky */ 1039baf02a1fSBen Widawsky static void hsw_pm_irq_handler(struct drm_i915_private *dev_priv, 1040baf02a1fSBen Widawsky u32 pm_iir) 1041baf02a1fSBen Widawsky { 104241a05a3aSDaniel Vetter if (pm_iir & GEN6_PM_RPS_EVENTS) { 104359cdb63dSDaniel Vetter spin_lock(&dev_priv->irq_lock); 10444848405cSBen Widawsky dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS; 1045edbfdb45SPaulo Zanoni snb_set_pm_irq(dev_priv, dev_priv->rps.pm_iir); 1046edbfdb45SPaulo Zanoni /* never want to mask useful interrupts. */ 10474848405cSBen Widawsky WARN_ON(I915_READ_NOTRACE(GEN6_PMIMR) & ~GEN6_PM_RPS_EVENTS); 104859cdb63dSDaniel Vetter spin_unlock(&dev_priv->irq_lock); 10492adbee62SDaniel Vetter 10502adbee62SDaniel Vetter queue_work(dev_priv->wq, &dev_priv->rps.work); 105141a05a3aSDaniel Vetter } 1052baf02a1fSBen Widawsky 105312638c57SBen Widawsky if (pm_iir & PM_VEBOX_USER_INTERRUPT) 105412638c57SBen Widawsky notify_ring(dev_priv->dev, &dev_priv->ring[VECS]); 105512638c57SBen Widawsky 105612638c57SBen Widawsky if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) { 105712638c57SBen Widawsky DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir); 105812638c57SBen Widawsky i915_handle_error(dev_priv->dev, false); 105912638c57SBen Widawsky } 106012638c57SBen Widawsky } 1061baf02a1fSBen Widawsky 1062ff1f525eSDaniel Vetter static irqreturn_t valleyview_irq_handler(int irq, void *arg) 10637e231dbeSJesse Barnes { 10647e231dbeSJesse Barnes struct drm_device *dev = (struct drm_device *) arg; 10657e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 10667e231dbeSJesse Barnes u32 iir, gt_iir, pm_iir; 10677e231dbeSJesse Barnes irqreturn_t ret = IRQ_NONE; 10687e231dbeSJesse Barnes unsigned long irqflags; 10697e231dbeSJesse Barnes int pipe; 10707e231dbeSJesse Barnes u32 pipe_stats[I915_MAX_PIPES]; 10717e231dbeSJesse Barnes 10727e231dbeSJesse Barnes atomic_inc(&dev_priv->irq_received); 10737e231dbeSJesse Barnes 10747e231dbeSJesse Barnes while (true) { 10757e231dbeSJesse Barnes iir = I915_READ(VLV_IIR); 10767e231dbeSJesse Barnes gt_iir = I915_READ(GTIIR); 10777e231dbeSJesse Barnes pm_iir = I915_READ(GEN6_PMIIR); 10787e231dbeSJesse Barnes 10797e231dbeSJesse Barnes if (gt_iir == 0 && pm_iir == 0 && iir == 0) 10807e231dbeSJesse Barnes goto out; 10817e231dbeSJesse Barnes 10827e231dbeSJesse Barnes ret = IRQ_HANDLED; 10837e231dbeSJesse Barnes 1084e7b4c6b1SDaniel Vetter snb_gt_irq_handler(dev, dev_priv, gt_iir); 10857e231dbeSJesse Barnes 10867e231dbeSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 10877e231dbeSJesse Barnes for_each_pipe(pipe) { 10887e231dbeSJesse Barnes int reg = PIPESTAT(pipe); 10897e231dbeSJesse Barnes pipe_stats[pipe] = I915_READ(reg); 10907e231dbeSJesse Barnes 10917e231dbeSJesse Barnes /* 10927e231dbeSJesse Barnes * Clear the PIPE*STAT regs before the IIR 10937e231dbeSJesse Barnes */ 10947e231dbeSJesse Barnes if (pipe_stats[pipe] & 0x8000ffff) { 10957e231dbeSJesse Barnes if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 10967e231dbeSJesse Barnes DRM_DEBUG_DRIVER("pipe %c underrun\n", 10977e231dbeSJesse Barnes pipe_name(pipe)); 10987e231dbeSJesse Barnes I915_WRITE(reg, pipe_stats[pipe]); 10997e231dbeSJesse Barnes } 11007e231dbeSJesse Barnes } 11017e231dbeSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 11027e231dbeSJesse Barnes 110331acc7f5SJesse Barnes for_each_pipe(pipe) { 110431acc7f5SJesse Barnes if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS) 110531acc7f5SJesse Barnes drm_handle_vblank(dev, pipe); 110631acc7f5SJesse Barnes 110731acc7f5SJesse Barnes if (pipe_stats[pipe] & PLANE_FLIPDONE_INT_STATUS_VLV) { 110831acc7f5SJesse Barnes intel_prepare_page_flip(dev, pipe); 110931acc7f5SJesse Barnes intel_finish_page_flip(dev, pipe); 111031acc7f5SJesse Barnes } 111131acc7f5SJesse Barnes } 111231acc7f5SJesse Barnes 11137e231dbeSJesse Barnes /* Consume port. Then clear IIR or we'll miss events */ 11147e231dbeSJesse Barnes if (iir & I915_DISPLAY_PORT_INTERRUPT) { 11157e231dbeSJesse Barnes u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); 1116b543fb04SEgbert Eich u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915; 11177e231dbeSJesse Barnes 11187e231dbeSJesse Barnes DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n", 11197e231dbeSJesse Barnes hotplug_status); 112091d131d2SDaniel Vetter 112110a504deSDaniel Vetter intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915); 112291d131d2SDaniel Vetter 11237e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); 11247e231dbeSJesse Barnes I915_READ(PORT_HOTPLUG_STAT); 11257e231dbeSJesse Barnes } 11267e231dbeSJesse Barnes 1127515ac2bbSDaniel Vetter if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 1128515ac2bbSDaniel Vetter gmbus_irq_handler(dev); 11297e231dbeSJesse Barnes 11304848405cSBen Widawsky if (pm_iir & GEN6_PM_RPS_EVENTS) 1131d0ecd7e2SDaniel Vetter gen6_rps_irq_handler(dev_priv, pm_iir); 11327e231dbeSJesse Barnes 11337e231dbeSJesse Barnes I915_WRITE(GTIIR, gt_iir); 11347e231dbeSJesse Barnes I915_WRITE(GEN6_PMIIR, pm_iir); 11357e231dbeSJesse Barnes I915_WRITE(VLV_IIR, iir); 11367e231dbeSJesse Barnes } 11377e231dbeSJesse Barnes 11387e231dbeSJesse Barnes out: 11397e231dbeSJesse Barnes return ret; 11407e231dbeSJesse Barnes } 11417e231dbeSJesse Barnes 114223e81d69SAdam Jackson static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir) 1143776ad806SJesse Barnes { 1144776ad806SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 11459db4a9c7SJesse Barnes int pipe; 1146b543fb04SEgbert Eich u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK; 1147776ad806SJesse Barnes 114810a504deSDaniel Vetter intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx); 114991d131d2SDaniel Vetter 1150cfc33bf7SVille Syrjälä if (pch_iir & SDE_AUDIO_POWER_MASK) { 1151cfc33bf7SVille Syrjälä int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >> 1152776ad806SJesse Barnes SDE_AUDIO_POWER_SHIFT); 1153cfc33bf7SVille Syrjälä DRM_DEBUG_DRIVER("PCH audio power change on port %d\n", 1154cfc33bf7SVille Syrjälä port_name(port)); 1155cfc33bf7SVille Syrjälä } 1156776ad806SJesse Barnes 1157ce99c256SDaniel Vetter if (pch_iir & SDE_AUX_MASK) 1158ce99c256SDaniel Vetter dp_aux_irq_handler(dev); 1159ce99c256SDaniel Vetter 1160776ad806SJesse Barnes if (pch_iir & SDE_GMBUS) 1161515ac2bbSDaniel Vetter gmbus_irq_handler(dev); 1162776ad806SJesse Barnes 1163776ad806SJesse Barnes if (pch_iir & SDE_AUDIO_HDCP_MASK) 1164776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n"); 1165776ad806SJesse Barnes 1166776ad806SJesse Barnes if (pch_iir & SDE_AUDIO_TRANS_MASK) 1167776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n"); 1168776ad806SJesse Barnes 1169776ad806SJesse Barnes if (pch_iir & SDE_POISON) 1170776ad806SJesse Barnes DRM_ERROR("PCH poison interrupt\n"); 1171776ad806SJesse Barnes 11729db4a9c7SJesse Barnes if (pch_iir & SDE_FDI_MASK) 11739db4a9c7SJesse Barnes for_each_pipe(pipe) 11749db4a9c7SJesse Barnes DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", 11759db4a9c7SJesse Barnes pipe_name(pipe), 11769db4a9c7SJesse Barnes I915_READ(FDI_RX_IIR(pipe))); 1177776ad806SJesse Barnes 1178776ad806SJesse Barnes if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE)) 1179776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n"); 1180776ad806SJesse Barnes 1181776ad806SJesse Barnes if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR)) 1182776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n"); 1183776ad806SJesse Barnes 1184776ad806SJesse Barnes if (pch_iir & SDE_TRANSA_FIFO_UNDER) 11858664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, 11868664281bSPaulo Zanoni false)) 11878664281bSPaulo Zanoni DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n"); 11888664281bSPaulo Zanoni 11898664281bSPaulo Zanoni if (pch_iir & SDE_TRANSB_FIFO_UNDER) 11908664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B, 11918664281bSPaulo Zanoni false)) 11928664281bSPaulo Zanoni DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n"); 11938664281bSPaulo Zanoni } 11948664281bSPaulo Zanoni 11958664281bSPaulo Zanoni static void ivb_err_int_handler(struct drm_device *dev) 11968664281bSPaulo Zanoni { 11978664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 11988664281bSPaulo Zanoni u32 err_int = I915_READ(GEN7_ERR_INT); 11998664281bSPaulo Zanoni 1200de032bf4SPaulo Zanoni if (err_int & ERR_INT_POISON) 1201de032bf4SPaulo Zanoni DRM_ERROR("Poison interrupt\n"); 1202de032bf4SPaulo Zanoni 12038664281bSPaulo Zanoni if (err_int & ERR_INT_FIFO_UNDERRUN_A) 12048664281bSPaulo Zanoni if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false)) 12058664281bSPaulo Zanoni DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n"); 12068664281bSPaulo Zanoni 12078664281bSPaulo Zanoni if (err_int & ERR_INT_FIFO_UNDERRUN_B) 12088664281bSPaulo Zanoni if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false)) 12098664281bSPaulo Zanoni DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n"); 12108664281bSPaulo Zanoni 12118664281bSPaulo Zanoni if (err_int & ERR_INT_FIFO_UNDERRUN_C) 12128664281bSPaulo Zanoni if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_C, false)) 12138664281bSPaulo Zanoni DRM_DEBUG_DRIVER("Pipe C FIFO underrun\n"); 12148664281bSPaulo Zanoni 12158664281bSPaulo Zanoni I915_WRITE(GEN7_ERR_INT, err_int); 12168664281bSPaulo Zanoni } 12178664281bSPaulo Zanoni 12188664281bSPaulo Zanoni static void cpt_serr_int_handler(struct drm_device *dev) 12198664281bSPaulo Zanoni { 12208664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 12218664281bSPaulo Zanoni u32 serr_int = I915_READ(SERR_INT); 12228664281bSPaulo Zanoni 1223de032bf4SPaulo Zanoni if (serr_int & SERR_INT_POISON) 1224de032bf4SPaulo Zanoni DRM_ERROR("PCH poison interrupt\n"); 1225de032bf4SPaulo Zanoni 12268664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN) 12278664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, 12288664281bSPaulo Zanoni false)) 12298664281bSPaulo Zanoni DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n"); 12308664281bSPaulo Zanoni 12318664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN) 12328664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B, 12338664281bSPaulo Zanoni false)) 12348664281bSPaulo Zanoni DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n"); 12358664281bSPaulo Zanoni 12368664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN) 12378664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C, 12388664281bSPaulo Zanoni false)) 12398664281bSPaulo Zanoni DRM_DEBUG_DRIVER("PCH transcoder C FIFO underrun\n"); 12408664281bSPaulo Zanoni 12418664281bSPaulo Zanoni I915_WRITE(SERR_INT, serr_int); 1242776ad806SJesse Barnes } 1243776ad806SJesse Barnes 124423e81d69SAdam Jackson static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir) 124523e81d69SAdam Jackson { 124623e81d69SAdam Jackson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 124723e81d69SAdam Jackson int pipe; 1248b543fb04SEgbert Eich u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT; 124923e81d69SAdam Jackson 125010a504deSDaniel Vetter intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt); 125191d131d2SDaniel Vetter 1252cfc33bf7SVille Syrjälä if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) { 1253cfc33bf7SVille Syrjälä int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >> 125423e81d69SAdam Jackson SDE_AUDIO_POWER_SHIFT_CPT); 1255cfc33bf7SVille Syrjälä DRM_DEBUG_DRIVER("PCH audio power change on port %c\n", 1256cfc33bf7SVille Syrjälä port_name(port)); 1257cfc33bf7SVille Syrjälä } 125823e81d69SAdam Jackson 125923e81d69SAdam Jackson if (pch_iir & SDE_AUX_MASK_CPT) 1260ce99c256SDaniel Vetter dp_aux_irq_handler(dev); 126123e81d69SAdam Jackson 126223e81d69SAdam Jackson if (pch_iir & SDE_GMBUS_CPT) 1263515ac2bbSDaniel Vetter gmbus_irq_handler(dev); 126423e81d69SAdam Jackson 126523e81d69SAdam Jackson if (pch_iir & SDE_AUDIO_CP_REQ_CPT) 126623e81d69SAdam Jackson DRM_DEBUG_DRIVER("Audio CP request interrupt\n"); 126723e81d69SAdam Jackson 126823e81d69SAdam Jackson if (pch_iir & SDE_AUDIO_CP_CHG_CPT) 126923e81d69SAdam Jackson DRM_DEBUG_DRIVER("Audio CP change interrupt\n"); 127023e81d69SAdam Jackson 127123e81d69SAdam Jackson if (pch_iir & SDE_FDI_MASK_CPT) 127223e81d69SAdam Jackson for_each_pipe(pipe) 127323e81d69SAdam Jackson DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", 127423e81d69SAdam Jackson pipe_name(pipe), 127523e81d69SAdam Jackson I915_READ(FDI_RX_IIR(pipe))); 12768664281bSPaulo Zanoni 12778664281bSPaulo Zanoni if (pch_iir & SDE_ERROR_CPT) 12788664281bSPaulo Zanoni cpt_serr_int_handler(dev); 127923e81d69SAdam Jackson } 128023e81d69SAdam Jackson 1281c008bc6eSPaulo Zanoni static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir) 1282c008bc6eSPaulo Zanoni { 1283c008bc6eSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 1284c008bc6eSPaulo Zanoni 1285c008bc6eSPaulo Zanoni if (de_iir & DE_AUX_CHANNEL_A) 1286c008bc6eSPaulo Zanoni dp_aux_irq_handler(dev); 1287c008bc6eSPaulo Zanoni 1288c008bc6eSPaulo Zanoni if (de_iir & DE_GSE) 1289c008bc6eSPaulo Zanoni intel_opregion_asle_intr(dev); 1290c008bc6eSPaulo Zanoni 1291c008bc6eSPaulo Zanoni if (de_iir & DE_PIPEA_VBLANK) 1292c008bc6eSPaulo Zanoni drm_handle_vblank(dev, 0); 1293c008bc6eSPaulo Zanoni 1294c008bc6eSPaulo Zanoni if (de_iir & DE_PIPEB_VBLANK) 1295c008bc6eSPaulo Zanoni drm_handle_vblank(dev, 1); 1296c008bc6eSPaulo Zanoni 1297c008bc6eSPaulo Zanoni if (de_iir & DE_POISON) 1298c008bc6eSPaulo Zanoni DRM_ERROR("Poison interrupt\n"); 1299c008bc6eSPaulo Zanoni 1300c008bc6eSPaulo Zanoni if (de_iir & DE_PIPEA_FIFO_UNDERRUN) 1301c008bc6eSPaulo Zanoni if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false)) 1302c008bc6eSPaulo Zanoni DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n"); 1303c008bc6eSPaulo Zanoni 1304c008bc6eSPaulo Zanoni if (de_iir & DE_PIPEB_FIFO_UNDERRUN) 1305c008bc6eSPaulo Zanoni if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false)) 1306c008bc6eSPaulo Zanoni DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n"); 1307c008bc6eSPaulo Zanoni 1308c008bc6eSPaulo Zanoni if (de_iir & DE_PLANEA_FLIP_DONE) { 1309c008bc6eSPaulo Zanoni intel_prepare_page_flip(dev, 0); 1310c008bc6eSPaulo Zanoni intel_finish_page_flip_plane(dev, 0); 1311c008bc6eSPaulo Zanoni } 1312c008bc6eSPaulo Zanoni 1313c008bc6eSPaulo Zanoni if (de_iir & DE_PLANEB_FLIP_DONE) { 1314c008bc6eSPaulo Zanoni intel_prepare_page_flip(dev, 1); 1315c008bc6eSPaulo Zanoni intel_finish_page_flip_plane(dev, 1); 1316c008bc6eSPaulo Zanoni } 1317c008bc6eSPaulo Zanoni 1318c008bc6eSPaulo Zanoni /* check event from PCH */ 1319c008bc6eSPaulo Zanoni if (de_iir & DE_PCH_EVENT) { 1320c008bc6eSPaulo Zanoni u32 pch_iir = I915_READ(SDEIIR); 1321c008bc6eSPaulo Zanoni 1322c008bc6eSPaulo Zanoni if (HAS_PCH_CPT(dev)) 1323c008bc6eSPaulo Zanoni cpt_irq_handler(dev, pch_iir); 1324c008bc6eSPaulo Zanoni else 1325c008bc6eSPaulo Zanoni ibx_irq_handler(dev, pch_iir); 1326c008bc6eSPaulo Zanoni 1327c008bc6eSPaulo Zanoni /* should clear PCH hotplug event before clear CPU irq */ 1328c008bc6eSPaulo Zanoni I915_WRITE(SDEIIR, pch_iir); 1329c008bc6eSPaulo Zanoni } 1330c008bc6eSPaulo Zanoni 1331c008bc6eSPaulo Zanoni if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT) 1332c008bc6eSPaulo Zanoni ironlake_rps_change_irq_handler(dev); 1333c008bc6eSPaulo Zanoni } 1334c008bc6eSPaulo Zanoni 13359719fb98SPaulo Zanoni static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir) 13369719fb98SPaulo Zanoni { 13379719fb98SPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 13389719fb98SPaulo Zanoni int i; 13399719fb98SPaulo Zanoni 13409719fb98SPaulo Zanoni if (de_iir & DE_ERR_INT_IVB) 13419719fb98SPaulo Zanoni ivb_err_int_handler(dev); 13429719fb98SPaulo Zanoni 13439719fb98SPaulo Zanoni if (de_iir & DE_AUX_CHANNEL_A_IVB) 13449719fb98SPaulo Zanoni dp_aux_irq_handler(dev); 13459719fb98SPaulo Zanoni 13469719fb98SPaulo Zanoni if (de_iir & DE_GSE_IVB) 13479719fb98SPaulo Zanoni intel_opregion_asle_intr(dev); 13489719fb98SPaulo Zanoni 13499719fb98SPaulo Zanoni for (i = 0; i < 3; i++) { 13509719fb98SPaulo Zanoni if (de_iir & (DE_PIPEA_VBLANK_IVB << (5 * i))) 13519719fb98SPaulo Zanoni drm_handle_vblank(dev, i); 13529719fb98SPaulo Zanoni if (de_iir & (DE_PLANEA_FLIP_DONE_IVB << (5 * i))) { 13539719fb98SPaulo Zanoni intel_prepare_page_flip(dev, i); 13549719fb98SPaulo Zanoni intel_finish_page_flip_plane(dev, i); 13559719fb98SPaulo Zanoni } 13569719fb98SPaulo Zanoni } 13579719fb98SPaulo Zanoni 13589719fb98SPaulo Zanoni /* check event from PCH */ 13599719fb98SPaulo Zanoni if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) { 13609719fb98SPaulo Zanoni u32 pch_iir = I915_READ(SDEIIR); 13619719fb98SPaulo Zanoni 13629719fb98SPaulo Zanoni cpt_irq_handler(dev, pch_iir); 13639719fb98SPaulo Zanoni 13649719fb98SPaulo Zanoni /* clear PCH hotplug event before clear CPU irq */ 13659719fb98SPaulo Zanoni I915_WRITE(SDEIIR, pch_iir); 13669719fb98SPaulo Zanoni } 13679719fb98SPaulo Zanoni } 13689719fb98SPaulo Zanoni 1369f1af8fc1SPaulo Zanoni static irqreturn_t ironlake_irq_handler(int irq, void *arg) 1370b1f14ad0SJesse Barnes { 1371b1f14ad0SJesse Barnes struct drm_device *dev = (struct drm_device *) arg; 1372b1f14ad0SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1373f1af8fc1SPaulo Zanoni u32 de_iir, gt_iir, de_ier, sde_ier = 0; 13740e43406bSChris Wilson irqreturn_t ret = IRQ_NONE; 1375b1f14ad0SJesse Barnes 1376b1f14ad0SJesse Barnes atomic_inc(&dev_priv->irq_received); 1377b1f14ad0SJesse Barnes 13788664281bSPaulo Zanoni /* We get interrupts on unclaimed registers, so check for this before we 13798664281bSPaulo Zanoni * do any I915_{READ,WRITE}. */ 1380907b28c5SChris Wilson intel_uncore_check_errors(dev); 13818664281bSPaulo Zanoni 1382b1f14ad0SJesse Barnes /* disable master interrupt before clearing iir */ 1383b1f14ad0SJesse Barnes de_ier = I915_READ(DEIER); 1384b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL); 138523a78516SPaulo Zanoni POSTING_READ(DEIER); 13860e43406bSChris Wilson 138744498aeaSPaulo Zanoni /* Disable south interrupts. We'll only write to SDEIIR once, so further 138844498aeaSPaulo Zanoni * interrupts will will be stored on its back queue, and then we'll be 138944498aeaSPaulo Zanoni * able to process them after we restore SDEIER (as soon as we restore 139044498aeaSPaulo Zanoni * it, we'll get an interrupt if SDEIIR still has something to process 139144498aeaSPaulo Zanoni * due to its back queue). */ 1392ab5c608bSBen Widawsky if (!HAS_PCH_NOP(dev)) { 139344498aeaSPaulo Zanoni sde_ier = I915_READ(SDEIER); 139444498aeaSPaulo Zanoni I915_WRITE(SDEIER, 0); 139544498aeaSPaulo Zanoni POSTING_READ(SDEIER); 1396ab5c608bSBen Widawsky } 139744498aeaSPaulo Zanoni 13988664281bSPaulo Zanoni /* On Haswell, also mask ERR_INT because we don't want to risk 13998664281bSPaulo Zanoni * generating "unclaimed register" interrupts from inside the interrupt 14008664281bSPaulo Zanoni * handler. */ 14014bc9d430SDaniel Vetter if (IS_HASWELL(dev)) { 14024bc9d430SDaniel Vetter spin_lock(&dev_priv->irq_lock); 14038664281bSPaulo Zanoni ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB); 14044bc9d430SDaniel Vetter spin_unlock(&dev_priv->irq_lock); 14054bc9d430SDaniel Vetter } 14068664281bSPaulo Zanoni 14070e43406bSChris Wilson gt_iir = I915_READ(GTIIR); 14080e43406bSChris Wilson if (gt_iir) { 1409d8fc8a47SPaulo Zanoni if (INTEL_INFO(dev)->gen >= 6) 14100e43406bSChris Wilson snb_gt_irq_handler(dev, dev_priv, gt_iir); 1411d8fc8a47SPaulo Zanoni else 1412d8fc8a47SPaulo Zanoni ilk_gt_irq_handler(dev, dev_priv, gt_iir); 14130e43406bSChris Wilson I915_WRITE(GTIIR, gt_iir); 14140e43406bSChris Wilson ret = IRQ_HANDLED; 14150e43406bSChris Wilson } 1416b1f14ad0SJesse Barnes 1417b1f14ad0SJesse Barnes de_iir = I915_READ(DEIIR); 14180e43406bSChris Wilson if (de_iir) { 1419f1af8fc1SPaulo Zanoni if (INTEL_INFO(dev)->gen >= 7) 14209719fb98SPaulo Zanoni ivb_display_irq_handler(dev, de_iir); 1421f1af8fc1SPaulo Zanoni else 1422f1af8fc1SPaulo Zanoni ilk_display_irq_handler(dev, de_iir); 14230e43406bSChris Wilson I915_WRITE(DEIIR, de_iir); 14240e43406bSChris Wilson ret = IRQ_HANDLED; 14250e43406bSChris Wilson } 14260e43406bSChris Wilson 1427f1af8fc1SPaulo Zanoni if (INTEL_INFO(dev)->gen >= 6) { 1428f1af8fc1SPaulo Zanoni u32 pm_iir = I915_READ(GEN6_PMIIR); 14290e43406bSChris Wilson if (pm_iir) { 1430baf02a1fSBen Widawsky if (IS_HASWELL(dev)) 1431baf02a1fSBen Widawsky hsw_pm_irq_handler(dev_priv, pm_iir); 14324848405cSBen Widawsky else if (pm_iir & GEN6_PM_RPS_EVENTS) 1433d0ecd7e2SDaniel Vetter gen6_rps_irq_handler(dev_priv, pm_iir); 1434b1f14ad0SJesse Barnes I915_WRITE(GEN6_PMIIR, pm_iir); 14350e43406bSChris Wilson ret = IRQ_HANDLED; 14360e43406bSChris Wilson } 1437f1af8fc1SPaulo Zanoni } 1438b1f14ad0SJesse Barnes 14394bc9d430SDaniel Vetter if (IS_HASWELL(dev)) { 14404bc9d430SDaniel Vetter spin_lock(&dev_priv->irq_lock); 14414bc9d430SDaniel Vetter if (ivb_can_enable_err_int(dev)) 14428664281bSPaulo Zanoni ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB); 14434bc9d430SDaniel Vetter spin_unlock(&dev_priv->irq_lock); 14444bc9d430SDaniel Vetter } 14458664281bSPaulo Zanoni 1446b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier); 1447b1f14ad0SJesse Barnes POSTING_READ(DEIER); 1448ab5c608bSBen Widawsky if (!HAS_PCH_NOP(dev)) { 144944498aeaSPaulo Zanoni I915_WRITE(SDEIER, sde_ier); 145044498aeaSPaulo Zanoni POSTING_READ(SDEIER); 1451ab5c608bSBen Widawsky } 1452b1f14ad0SJesse Barnes 1453b1f14ad0SJesse Barnes return ret; 1454b1f14ad0SJesse Barnes } 1455b1f14ad0SJesse Barnes 14568a905236SJesse Barnes /** 14578a905236SJesse Barnes * i915_error_work_func - do process context error handling work 14588a905236SJesse Barnes * @work: work struct 14598a905236SJesse Barnes * 14608a905236SJesse Barnes * Fire an error uevent so userspace can see that a hang or error 14618a905236SJesse Barnes * was detected. 14628a905236SJesse Barnes */ 14638a905236SJesse Barnes static void i915_error_work_func(struct work_struct *work) 14648a905236SJesse Barnes { 14651f83fee0SDaniel Vetter struct i915_gpu_error *error = container_of(work, struct i915_gpu_error, 14661f83fee0SDaniel Vetter work); 14671f83fee0SDaniel Vetter drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t, 14681f83fee0SDaniel Vetter gpu_error); 14698a905236SJesse Barnes struct drm_device *dev = dev_priv->dev; 1470f69061beSDaniel Vetter struct intel_ring_buffer *ring; 1471cce723edSBen Widawsky char *error_event[] = { I915_ERROR_UEVENT "=1", NULL }; 1472cce723edSBen Widawsky char *reset_event[] = { I915_RESET_UEVENT "=1", NULL }; 1473cce723edSBen Widawsky char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL }; 1474f69061beSDaniel Vetter int i, ret; 14758a905236SJesse Barnes 1476f316a42cSBen Gamari kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event); 14778a905236SJesse Barnes 14787db0ba24SDaniel Vetter /* 14797db0ba24SDaniel Vetter * Note that there's only one work item which does gpu resets, so we 14807db0ba24SDaniel Vetter * need not worry about concurrent gpu resets potentially incrementing 14817db0ba24SDaniel Vetter * error->reset_counter twice. We only need to take care of another 14827db0ba24SDaniel Vetter * racing irq/hangcheck declaring the gpu dead for a second time. A 14837db0ba24SDaniel Vetter * quick check for that is good enough: schedule_work ensures the 14847db0ba24SDaniel Vetter * correct ordering between hang detection and this work item, and since 14857db0ba24SDaniel Vetter * the reset in-progress bit is only ever set by code outside of this 14867db0ba24SDaniel Vetter * work we don't need to worry about any other races. 14877db0ba24SDaniel Vetter */ 14887db0ba24SDaniel Vetter if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) { 148944d98a61SZhao Yakui DRM_DEBUG_DRIVER("resetting chip\n"); 14907db0ba24SDaniel Vetter kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, 14917db0ba24SDaniel Vetter reset_event); 14921f83fee0SDaniel Vetter 1493f69061beSDaniel Vetter ret = i915_reset(dev); 1494f69061beSDaniel Vetter 1495f69061beSDaniel Vetter if (ret == 0) { 1496f69061beSDaniel Vetter /* 1497f69061beSDaniel Vetter * After all the gem state is reset, increment the reset 1498f69061beSDaniel Vetter * counter and wake up everyone waiting for the reset to 1499f69061beSDaniel Vetter * complete. 1500f69061beSDaniel Vetter * 1501f69061beSDaniel Vetter * Since unlock operations are a one-sided barrier only, 1502f69061beSDaniel Vetter * we need to insert a barrier here to order any seqno 1503f69061beSDaniel Vetter * updates before 1504f69061beSDaniel Vetter * the counter increment. 1505f69061beSDaniel Vetter */ 1506f69061beSDaniel Vetter smp_mb__before_atomic_inc(); 1507f69061beSDaniel Vetter atomic_inc(&dev_priv->gpu_error.reset_counter); 1508f69061beSDaniel Vetter 1509f69061beSDaniel Vetter kobject_uevent_env(&dev->primary->kdev.kobj, 1510f69061beSDaniel Vetter KOBJ_CHANGE, reset_done_event); 15111f83fee0SDaniel Vetter } else { 15121f83fee0SDaniel Vetter atomic_set(&error->reset_counter, I915_WEDGED); 1513f316a42cSBen Gamari } 15141f83fee0SDaniel Vetter 1515f69061beSDaniel Vetter for_each_ring(ring, dev_priv, i) 1516f69061beSDaniel Vetter wake_up_all(&ring->irq_queue); 1517f69061beSDaniel Vetter 151896a02917SVille Syrjälä intel_display_handle_reset(dev); 151996a02917SVille Syrjälä 15201f83fee0SDaniel Vetter wake_up_all(&dev_priv->gpu_error.reset_queue); 1521f316a42cSBen Gamari } 15228a905236SJesse Barnes } 15238a905236SJesse Barnes 152435aed2e6SChris Wilson static void i915_report_and_clear_eir(struct drm_device *dev) 1525c0e09200SDave Airlie { 15268a905236SJesse Barnes struct drm_i915_private *dev_priv = dev->dev_private; 1527bd9854f9SBen Widawsky uint32_t instdone[I915_NUM_INSTDONE_REG]; 152863eeaf38SJesse Barnes u32 eir = I915_READ(EIR); 1529050ee91fSBen Widawsky int pipe, i; 153063eeaf38SJesse Barnes 153135aed2e6SChris Wilson if (!eir) 153235aed2e6SChris Wilson return; 153363eeaf38SJesse Barnes 1534a70491ccSJoe Perches pr_err("render error detected, EIR: 0x%08x\n", eir); 15358a905236SJesse Barnes 1536bd9854f9SBen Widawsky i915_get_extra_instdone(dev, instdone); 1537bd9854f9SBen Widawsky 15388a905236SJesse Barnes if (IS_G4X(dev)) { 15398a905236SJesse Barnes if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) { 15408a905236SJesse Barnes u32 ipeir = I915_READ(IPEIR_I965); 15418a905236SJesse Barnes 1542a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); 1543a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); 1544050ee91fSBen Widawsky for (i = 0; i < ARRAY_SIZE(instdone); i++) 1545050ee91fSBen Widawsky pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]); 1546a70491ccSJoe Perches pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); 1547a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); 15488a905236SJesse Barnes I915_WRITE(IPEIR_I965, ipeir); 15493143a2bfSChris Wilson POSTING_READ(IPEIR_I965); 15508a905236SJesse Barnes } 15518a905236SJesse Barnes if (eir & GM45_ERROR_PAGE_TABLE) { 15528a905236SJesse Barnes u32 pgtbl_err = I915_READ(PGTBL_ER); 1553a70491ccSJoe Perches pr_err("page table error\n"); 1554a70491ccSJoe Perches pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); 15558a905236SJesse Barnes I915_WRITE(PGTBL_ER, pgtbl_err); 15563143a2bfSChris Wilson POSTING_READ(PGTBL_ER); 15578a905236SJesse Barnes } 15588a905236SJesse Barnes } 15598a905236SJesse Barnes 1560a6c45cf0SChris Wilson if (!IS_GEN2(dev)) { 156163eeaf38SJesse Barnes if (eir & I915_ERROR_PAGE_TABLE) { 156263eeaf38SJesse Barnes u32 pgtbl_err = I915_READ(PGTBL_ER); 1563a70491ccSJoe Perches pr_err("page table error\n"); 1564a70491ccSJoe Perches pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); 156563eeaf38SJesse Barnes I915_WRITE(PGTBL_ER, pgtbl_err); 15663143a2bfSChris Wilson POSTING_READ(PGTBL_ER); 156763eeaf38SJesse Barnes } 15688a905236SJesse Barnes } 15698a905236SJesse Barnes 157063eeaf38SJesse Barnes if (eir & I915_ERROR_MEMORY_REFRESH) { 1571a70491ccSJoe Perches pr_err("memory refresh error:\n"); 15729db4a9c7SJesse Barnes for_each_pipe(pipe) 1573a70491ccSJoe Perches pr_err("pipe %c stat: 0x%08x\n", 15749db4a9c7SJesse Barnes pipe_name(pipe), I915_READ(PIPESTAT(pipe))); 157563eeaf38SJesse Barnes /* pipestat has already been acked */ 157663eeaf38SJesse Barnes } 157763eeaf38SJesse Barnes if (eir & I915_ERROR_INSTRUCTION) { 1578a70491ccSJoe Perches pr_err("instruction error\n"); 1579a70491ccSJoe Perches pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM)); 1580050ee91fSBen Widawsky for (i = 0; i < ARRAY_SIZE(instdone); i++) 1581050ee91fSBen Widawsky pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]); 1582a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen < 4) { 158363eeaf38SJesse Barnes u32 ipeir = I915_READ(IPEIR); 158463eeaf38SJesse Barnes 1585a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR)); 1586a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR)); 1587a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD)); 158863eeaf38SJesse Barnes I915_WRITE(IPEIR, ipeir); 15893143a2bfSChris Wilson POSTING_READ(IPEIR); 159063eeaf38SJesse Barnes } else { 159163eeaf38SJesse Barnes u32 ipeir = I915_READ(IPEIR_I965); 159263eeaf38SJesse Barnes 1593a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); 1594a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); 1595a70491ccSJoe Perches pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); 1596a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); 159763eeaf38SJesse Barnes I915_WRITE(IPEIR_I965, ipeir); 15983143a2bfSChris Wilson POSTING_READ(IPEIR_I965); 159963eeaf38SJesse Barnes } 160063eeaf38SJesse Barnes } 160163eeaf38SJesse Barnes 160263eeaf38SJesse Barnes I915_WRITE(EIR, eir); 16033143a2bfSChris Wilson POSTING_READ(EIR); 160463eeaf38SJesse Barnes eir = I915_READ(EIR); 160563eeaf38SJesse Barnes if (eir) { 160663eeaf38SJesse Barnes /* 160763eeaf38SJesse Barnes * some errors might have become stuck, 160863eeaf38SJesse Barnes * mask them. 160963eeaf38SJesse Barnes */ 161063eeaf38SJesse Barnes DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir); 161163eeaf38SJesse Barnes I915_WRITE(EMR, I915_READ(EMR) | eir); 161263eeaf38SJesse Barnes I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 161363eeaf38SJesse Barnes } 161435aed2e6SChris Wilson } 161535aed2e6SChris Wilson 161635aed2e6SChris Wilson /** 161735aed2e6SChris Wilson * i915_handle_error - handle an error interrupt 161835aed2e6SChris Wilson * @dev: drm device 161935aed2e6SChris Wilson * 162035aed2e6SChris Wilson * Do some basic checking of regsiter state at error interrupt time and 162135aed2e6SChris Wilson * dump it to the syslog. Also call i915_capture_error_state() to make 162235aed2e6SChris Wilson * sure we get a record and make it available in debugfs. Fire a uevent 162335aed2e6SChris Wilson * so userspace knows something bad happened (should trigger collection 162435aed2e6SChris Wilson * of a ring dump etc.). 162535aed2e6SChris Wilson */ 1626527f9e90SChris Wilson void i915_handle_error(struct drm_device *dev, bool wedged) 162735aed2e6SChris Wilson { 162835aed2e6SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 1629b4519513SChris Wilson struct intel_ring_buffer *ring; 1630b4519513SChris Wilson int i; 163135aed2e6SChris Wilson 163235aed2e6SChris Wilson i915_capture_error_state(dev); 163335aed2e6SChris Wilson i915_report_and_clear_eir(dev); 16348a905236SJesse Barnes 1635ba1234d1SBen Gamari if (wedged) { 1636f69061beSDaniel Vetter atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG, 1637f69061beSDaniel Vetter &dev_priv->gpu_error.reset_counter); 1638ba1234d1SBen Gamari 163911ed50ecSBen Gamari /* 16401f83fee0SDaniel Vetter * Wakeup waiting processes so that the reset work item 16411f83fee0SDaniel Vetter * doesn't deadlock trying to grab various locks. 164211ed50ecSBen Gamari */ 1643b4519513SChris Wilson for_each_ring(ring, dev_priv, i) 1644b4519513SChris Wilson wake_up_all(&ring->irq_queue); 164511ed50ecSBen Gamari } 164611ed50ecSBen Gamari 164799584db3SDaniel Vetter queue_work(dev_priv->wq, &dev_priv->gpu_error.work); 16488a905236SJesse Barnes } 16498a905236SJesse Barnes 165021ad8330SVille Syrjälä static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe) 16514e5359cdSSimon Farnsworth { 16524e5359cdSSimon Farnsworth drm_i915_private_t *dev_priv = dev->dev_private; 16534e5359cdSSimon Farnsworth struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 16544e5359cdSSimon Farnsworth struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 165505394f39SChris Wilson struct drm_i915_gem_object *obj; 16564e5359cdSSimon Farnsworth struct intel_unpin_work *work; 16574e5359cdSSimon Farnsworth unsigned long flags; 16584e5359cdSSimon Farnsworth bool stall_detected; 16594e5359cdSSimon Farnsworth 16604e5359cdSSimon Farnsworth /* Ignore early vblank irqs */ 16614e5359cdSSimon Farnsworth if (intel_crtc == NULL) 16624e5359cdSSimon Farnsworth return; 16634e5359cdSSimon Farnsworth 16644e5359cdSSimon Farnsworth spin_lock_irqsave(&dev->event_lock, flags); 16654e5359cdSSimon Farnsworth work = intel_crtc->unpin_work; 16664e5359cdSSimon Farnsworth 1667e7d841caSChris Wilson if (work == NULL || 1668e7d841caSChris Wilson atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE || 1669e7d841caSChris Wilson !work->enable_stall_check) { 16704e5359cdSSimon Farnsworth /* Either the pending flip IRQ arrived, or we're too early. Don't check */ 16714e5359cdSSimon Farnsworth spin_unlock_irqrestore(&dev->event_lock, flags); 16724e5359cdSSimon Farnsworth return; 16734e5359cdSSimon Farnsworth } 16744e5359cdSSimon Farnsworth 16754e5359cdSSimon Farnsworth /* Potential stall - if we see that the flip has happened, assume a missed interrupt */ 167605394f39SChris Wilson obj = work->pending_flip_obj; 1677a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen >= 4) { 16789db4a9c7SJesse Barnes int dspsurf = DSPSURF(intel_crtc->plane); 1679446f2545SArmin Reese stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) == 1680f343c5f6SBen Widawsky i915_gem_obj_ggtt_offset(obj); 16814e5359cdSSimon Farnsworth } else { 16829db4a9c7SJesse Barnes int dspaddr = DSPADDR(intel_crtc->plane); 1683f343c5f6SBen Widawsky stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) + 168401f2c773SVille Syrjälä crtc->y * crtc->fb->pitches[0] + 16854e5359cdSSimon Farnsworth crtc->x * crtc->fb->bits_per_pixel/8); 16864e5359cdSSimon Farnsworth } 16874e5359cdSSimon Farnsworth 16884e5359cdSSimon Farnsworth spin_unlock_irqrestore(&dev->event_lock, flags); 16894e5359cdSSimon Farnsworth 16904e5359cdSSimon Farnsworth if (stall_detected) { 16914e5359cdSSimon Farnsworth DRM_DEBUG_DRIVER("Pageflip stall detected\n"); 16924e5359cdSSimon Farnsworth intel_prepare_page_flip(dev, intel_crtc->plane); 16934e5359cdSSimon Farnsworth } 16944e5359cdSSimon Farnsworth } 16954e5359cdSSimon Farnsworth 169642f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 169742f52ef8SKeith Packard * we use as a pipe index 169842f52ef8SKeith Packard */ 1699f71d4af4SJesse Barnes static int i915_enable_vblank(struct drm_device *dev, int pipe) 17000a3e67a4SJesse Barnes { 17010a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1702e9d21d7fSKeith Packard unsigned long irqflags; 170371e0ffa5SJesse Barnes 17045eddb70bSChris Wilson if (!i915_pipe_enabled(dev, pipe)) 170571e0ffa5SJesse Barnes return -EINVAL; 17060a3e67a4SJesse Barnes 17071ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 1708f796cf8fSJesse Barnes if (INTEL_INFO(dev)->gen >= 4) 17097c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 17107c463586SKeith Packard PIPE_START_VBLANK_INTERRUPT_ENABLE); 17110a3e67a4SJesse Barnes else 17127c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 17137c463586SKeith Packard PIPE_VBLANK_INTERRUPT_ENABLE); 17148692d00eSChris Wilson 17158692d00eSChris Wilson /* maintain vblank delivery even in deep C-states */ 17168692d00eSChris Wilson if (dev_priv->info->gen == 3) 17176b26c86dSDaniel Vetter I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS)); 17181ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 17198692d00eSChris Wilson 17200a3e67a4SJesse Barnes return 0; 17210a3e67a4SJesse Barnes } 17220a3e67a4SJesse Barnes 1723f71d4af4SJesse Barnes static int ironlake_enable_vblank(struct drm_device *dev, int pipe) 1724f796cf8fSJesse Barnes { 1725f796cf8fSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1726f796cf8fSJesse Barnes unsigned long irqflags; 1727b518421fSPaulo Zanoni uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) : 1728b518421fSPaulo Zanoni DE_PIPE_VBLANK_ILK(pipe); 1729f796cf8fSJesse Barnes 1730f796cf8fSJesse Barnes if (!i915_pipe_enabled(dev, pipe)) 1731f796cf8fSJesse Barnes return -EINVAL; 1732f796cf8fSJesse Barnes 1733f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 1734b518421fSPaulo Zanoni ironlake_enable_display_irq(dev_priv, bit); 1735b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 1736b1f14ad0SJesse Barnes 1737b1f14ad0SJesse Barnes return 0; 1738b1f14ad0SJesse Barnes } 1739b1f14ad0SJesse Barnes 17407e231dbeSJesse Barnes static int valleyview_enable_vblank(struct drm_device *dev, int pipe) 17417e231dbeSJesse Barnes { 17427e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 17437e231dbeSJesse Barnes unsigned long irqflags; 174431acc7f5SJesse Barnes u32 imr; 17457e231dbeSJesse Barnes 17467e231dbeSJesse Barnes if (!i915_pipe_enabled(dev, pipe)) 17477e231dbeSJesse Barnes return -EINVAL; 17487e231dbeSJesse Barnes 17497e231dbeSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 17507e231dbeSJesse Barnes imr = I915_READ(VLV_IMR); 175131acc7f5SJesse Barnes if (pipe == 0) 17527e231dbeSJesse Barnes imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT; 175331acc7f5SJesse Barnes else 17547e231dbeSJesse Barnes imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; 17557e231dbeSJesse Barnes I915_WRITE(VLV_IMR, imr); 175631acc7f5SJesse Barnes i915_enable_pipestat(dev_priv, pipe, 175731acc7f5SJesse Barnes PIPE_START_VBLANK_INTERRUPT_ENABLE); 17587e231dbeSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 17597e231dbeSJesse Barnes 17607e231dbeSJesse Barnes return 0; 17617e231dbeSJesse Barnes } 17627e231dbeSJesse Barnes 176342f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 176442f52ef8SKeith Packard * we use as a pipe index 176542f52ef8SKeith Packard */ 1766f71d4af4SJesse Barnes static void i915_disable_vblank(struct drm_device *dev, int pipe) 17670a3e67a4SJesse Barnes { 17680a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1769e9d21d7fSKeith Packard unsigned long irqflags; 17700a3e67a4SJesse Barnes 17711ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 17728692d00eSChris Wilson if (dev_priv->info->gen == 3) 17736b26c86dSDaniel Vetter I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS)); 17748692d00eSChris Wilson 17757c463586SKeith Packard i915_disable_pipestat(dev_priv, pipe, 17767c463586SKeith Packard PIPE_VBLANK_INTERRUPT_ENABLE | 17777c463586SKeith Packard PIPE_START_VBLANK_INTERRUPT_ENABLE); 17781ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 17790a3e67a4SJesse Barnes } 17800a3e67a4SJesse Barnes 1781f71d4af4SJesse Barnes static void ironlake_disable_vblank(struct drm_device *dev, int pipe) 1782f796cf8fSJesse Barnes { 1783f796cf8fSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1784f796cf8fSJesse Barnes unsigned long irqflags; 1785b518421fSPaulo Zanoni uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) : 1786b518421fSPaulo Zanoni DE_PIPE_VBLANK_ILK(pipe); 1787f796cf8fSJesse Barnes 1788f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 1789b518421fSPaulo Zanoni ironlake_disable_display_irq(dev_priv, bit); 1790b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 1791b1f14ad0SJesse Barnes } 1792b1f14ad0SJesse Barnes 17937e231dbeSJesse Barnes static void valleyview_disable_vblank(struct drm_device *dev, int pipe) 17947e231dbeSJesse Barnes { 17957e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 17967e231dbeSJesse Barnes unsigned long irqflags; 179731acc7f5SJesse Barnes u32 imr; 17987e231dbeSJesse Barnes 17997e231dbeSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 180031acc7f5SJesse Barnes i915_disable_pipestat(dev_priv, pipe, 180131acc7f5SJesse Barnes PIPE_START_VBLANK_INTERRUPT_ENABLE); 18027e231dbeSJesse Barnes imr = I915_READ(VLV_IMR); 180331acc7f5SJesse Barnes if (pipe == 0) 18047e231dbeSJesse Barnes imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT; 180531acc7f5SJesse Barnes else 18067e231dbeSJesse Barnes imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; 18077e231dbeSJesse Barnes I915_WRITE(VLV_IMR, imr); 18087e231dbeSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 18097e231dbeSJesse Barnes } 18107e231dbeSJesse Barnes 1811893eead0SChris Wilson static u32 1812893eead0SChris Wilson ring_last_seqno(struct intel_ring_buffer *ring) 1813852835f3SZou Nan hai { 1814893eead0SChris Wilson return list_entry(ring->request_list.prev, 1815893eead0SChris Wilson struct drm_i915_gem_request, list)->seqno; 1816893eead0SChris Wilson } 1817893eead0SChris Wilson 18189107e9d2SChris Wilson static bool 18199107e9d2SChris Wilson ring_idle(struct intel_ring_buffer *ring, u32 seqno) 1820893eead0SChris Wilson { 18219107e9d2SChris Wilson return (list_empty(&ring->request_list) || 18229107e9d2SChris Wilson i915_seqno_passed(seqno, ring_last_seqno(ring))); 1823f65d9421SBen Gamari } 1824f65d9421SBen Gamari 18256274f212SChris Wilson static struct intel_ring_buffer * 18266274f212SChris Wilson semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno) 1827a24a11e6SChris Wilson { 1828a24a11e6SChris Wilson struct drm_i915_private *dev_priv = ring->dev->dev_private; 18296274f212SChris Wilson u32 cmd, ipehr, acthd, acthd_min; 1830a24a11e6SChris Wilson 1831a24a11e6SChris Wilson ipehr = I915_READ(RING_IPEHR(ring->mmio_base)); 1832a24a11e6SChris Wilson if ((ipehr & ~(0x3 << 16)) != 1833a24a11e6SChris Wilson (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER)) 18346274f212SChris Wilson return NULL; 1835a24a11e6SChris Wilson 1836a24a11e6SChris Wilson /* ACTHD is likely pointing to the dword after the actual command, 1837a24a11e6SChris Wilson * so scan backwards until we find the MBOX. 1838a24a11e6SChris Wilson */ 18396274f212SChris Wilson acthd = intel_ring_get_active_head(ring) & HEAD_ADDR; 1840a24a11e6SChris Wilson acthd_min = max((int)acthd - 3 * 4, 0); 1841a24a11e6SChris Wilson do { 1842a24a11e6SChris Wilson cmd = ioread32(ring->virtual_start + acthd); 1843a24a11e6SChris Wilson if (cmd == ipehr) 1844a24a11e6SChris Wilson break; 1845a24a11e6SChris Wilson 1846a24a11e6SChris Wilson acthd -= 4; 1847a24a11e6SChris Wilson if (acthd < acthd_min) 18486274f212SChris Wilson return NULL; 1849a24a11e6SChris Wilson } while (1); 1850a24a11e6SChris Wilson 18516274f212SChris Wilson *seqno = ioread32(ring->virtual_start+acthd+4)+1; 18526274f212SChris Wilson return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3]; 1853a24a11e6SChris Wilson } 1854a24a11e6SChris Wilson 18556274f212SChris Wilson static int semaphore_passed(struct intel_ring_buffer *ring) 18566274f212SChris Wilson { 18576274f212SChris Wilson struct drm_i915_private *dev_priv = ring->dev->dev_private; 18586274f212SChris Wilson struct intel_ring_buffer *signaller; 18596274f212SChris Wilson u32 seqno, ctl; 18606274f212SChris Wilson 18616274f212SChris Wilson ring->hangcheck.deadlock = true; 18626274f212SChris Wilson 18636274f212SChris Wilson signaller = semaphore_waits_for(ring, &seqno); 18646274f212SChris Wilson if (signaller == NULL || signaller->hangcheck.deadlock) 18656274f212SChris Wilson return -1; 18666274f212SChris Wilson 18676274f212SChris Wilson /* cursory check for an unkickable deadlock */ 18686274f212SChris Wilson ctl = I915_READ_CTL(signaller); 18696274f212SChris Wilson if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0) 18706274f212SChris Wilson return -1; 18716274f212SChris Wilson 18726274f212SChris Wilson return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno); 18736274f212SChris Wilson } 18746274f212SChris Wilson 18756274f212SChris Wilson static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv) 18766274f212SChris Wilson { 18776274f212SChris Wilson struct intel_ring_buffer *ring; 18786274f212SChris Wilson int i; 18796274f212SChris Wilson 18806274f212SChris Wilson for_each_ring(ring, dev_priv, i) 18816274f212SChris Wilson ring->hangcheck.deadlock = false; 18826274f212SChris Wilson } 18836274f212SChris Wilson 1884ad8beaeaSMika Kuoppala static enum intel_ring_hangcheck_action 1885ad8beaeaSMika Kuoppala ring_stuck(struct intel_ring_buffer *ring, u32 acthd) 18861ec14ad3SChris Wilson { 18871ec14ad3SChris Wilson struct drm_device *dev = ring->dev; 18881ec14ad3SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 18899107e9d2SChris Wilson u32 tmp; 18909107e9d2SChris Wilson 18916274f212SChris Wilson if (ring->hangcheck.acthd != acthd) 1892f2f4d82fSJani Nikula return HANGCHECK_ACTIVE; 18936274f212SChris Wilson 18949107e9d2SChris Wilson if (IS_GEN2(dev)) 1895f2f4d82fSJani Nikula return HANGCHECK_HUNG; 18969107e9d2SChris Wilson 18979107e9d2SChris Wilson /* Is the chip hanging on a WAIT_FOR_EVENT? 18989107e9d2SChris Wilson * If so we can simply poke the RB_WAIT bit 18999107e9d2SChris Wilson * and break the hang. This should work on 19009107e9d2SChris Wilson * all but the second generation chipsets. 19019107e9d2SChris Wilson */ 19029107e9d2SChris Wilson tmp = I915_READ_CTL(ring); 19031ec14ad3SChris Wilson if (tmp & RING_WAIT) { 19041ec14ad3SChris Wilson DRM_ERROR("Kicking stuck wait on %s\n", 19051ec14ad3SChris Wilson ring->name); 19061ec14ad3SChris Wilson I915_WRITE_CTL(ring, tmp); 1907f2f4d82fSJani Nikula return HANGCHECK_KICK; 19081ec14ad3SChris Wilson } 1909a24a11e6SChris Wilson 19106274f212SChris Wilson if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) { 19116274f212SChris Wilson switch (semaphore_passed(ring)) { 19126274f212SChris Wilson default: 1913f2f4d82fSJani Nikula return HANGCHECK_HUNG; 19146274f212SChris Wilson case 1: 1915a24a11e6SChris Wilson DRM_ERROR("Kicking stuck semaphore on %s\n", 1916a24a11e6SChris Wilson ring->name); 1917a24a11e6SChris Wilson I915_WRITE_CTL(ring, tmp); 1918f2f4d82fSJani Nikula return HANGCHECK_KICK; 19196274f212SChris Wilson case 0: 1920f2f4d82fSJani Nikula return HANGCHECK_WAIT; 19216274f212SChris Wilson } 19229107e9d2SChris Wilson } 19239107e9d2SChris Wilson 1924f2f4d82fSJani Nikula return HANGCHECK_HUNG; 1925a24a11e6SChris Wilson } 1926d1e61e7fSChris Wilson 1927f65d9421SBen Gamari /** 1928f65d9421SBen Gamari * This is called when the chip hasn't reported back with completed 192905407ff8SMika Kuoppala * batchbuffers in a long time. We keep track per ring seqno progress and 193005407ff8SMika Kuoppala * if there are no progress, hangcheck score for that ring is increased. 193105407ff8SMika Kuoppala * Further, acthd is inspected to see if the ring is stuck. On stuck case 193205407ff8SMika Kuoppala * we kick the ring. If we see no progress on three subsequent calls 193305407ff8SMika Kuoppala * we assume chip is wedged and try to fix it by resetting the chip. 1934f65d9421SBen Gamari */ 1935a658b5d2SDamien Lespiau static void i915_hangcheck_elapsed(unsigned long data) 1936f65d9421SBen Gamari { 1937f65d9421SBen Gamari struct drm_device *dev = (struct drm_device *)data; 1938f65d9421SBen Gamari drm_i915_private_t *dev_priv = dev->dev_private; 1939b4519513SChris Wilson struct intel_ring_buffer *ring; 1940b4519513SChris Wilson int i; 194105407ff8SMika Kuoppala int busy_count = 0, rings_hung = 0; 19429107e9d2SChris Wilson bool stuck[I915_NUM_RINGS] = { 0 }; 19439107e9d2SChris Wilson #define BUSY 1 19449107e9d2SChris Wilson #define KICK 5 19459107e9d2SChris Wilson #define HUNG 20 19469107e9d2SChris Wilson #define FIRE 30 1947893eead0SChris Wilson 19483e0dc6b0SBen Widawsky if (!i915_enable_hangcheck) 19493e0dc6b0SBen Widawsky return; 19503e0dc6b0SBen Widawsky 1951b4519513SChris Wilson for_each_ring(ring, dev_priv, i) { 195205407ff8SMika Kuoppala u32 seqno, acthd; 19539107e9d2SChris Wilson bool busy = true; 1954b4519513SChris Wilson 19556274f212SChris Wilson semaphore_clear_deadlocks(dev_priv); 19566274f212SChris Wilson 195705407ff8SMika Kuoppala seqno = ring->get_seqno(ring, false); 195805407ff8SMika Kuoppala acthd = intel_ring_get_active_head(ring); 195905407ff8SMika Kuoppala 196005407ff8SMika Kuoppala if (ring->hangcheck.seqno == seqno) { 19619107e9d2SChris Wilson if (ring_idle(ring, seqno)) { 19629107e9d2SChris Wilson if (waitqueue_active(&ring->irq_queue)) { 19639107e9d2SChris Wilson /* Issue a wake-up to catch stuck h/w. */ 19649107e9d2SChris Wilson DRM_ERROR("Hangcheck timer elapsed... %s idle\n", 19659107e9d2SChris Wilson ring->name); 19669107e9d2SChris Wilson wake_up_all(&ring->irq_queue); 19679107e9d2SChris Wilson ring->hangcheck.score += HUNG; 19689107e9d2SChris Wilson } else 19699107e9d2SChris Wilson busy = false; 197005407ff8SMika Kuoppala } else { 19716274f212SChris Wilson /* We always increment the hangcheck score 19726274f212SChris Wilson * if the ring is busy and still processing 19736274f212SChris Wilson * the same request, so that no single request 19746274f212SChris Wilson * can run indefinitely (such as a chain of 19756274f212SChris Wilson * batches). The only time we do not increment 19766274f212SChris Wilson * the hangcheck score on this ring, if this 19776274f212SChris Wilson * ring is in a legitimate wait for another 19786274f212SChris Wilson * ring. In that case the waiting ring is a 19796274f212SChris Wilson * victim and we want to be sure we catch the 19806274f212SChris Wilson * right culprit. Then every time we do kick 19816274f212SChris Wilson * the ring, add a small increment to the 19826274f212SChris Wilson * score so that we can catch a batch that is 19836274f212SChris Wilson * being repeatedly kicked and so responsible 19846274f212SChris Wilson * for stalling the machine. 19859107e9d2SChris Wilson */ 1986ad8beaeaSMika Kuoppala ring->hangcheck.action = ring_stuck(ring, 1987ad8beaeaSMika Kuoppala acthd); 1988ad8beaeaSMika Kuoppala 1989ad8beaeaSMika Kuoppala switch (ring->hangcheck.action) { 1990f2f4d82fSJani Nikula case HANGCHECK_WAIT: 19916274f212SChris Wilson break; 1992f2f4d82fSJani Nikula case HANGCHECK_ACTIVE: 1993ea04cb31SJani Nikula ring->hangcheck.score += BUSY; 19946274f212SChris Wilson break; 1995f2f4d82fSJani Nikula case HANGCHECK_KICK: 1996ea04cb31SJani Nikula ring->hangcheck.score += KICK; 19976274f212SChris Wilson break; 1998f2f4d82fSJani Nikula case HANGCHECK_HUNG: 1999ea04cb31SJani Nikula ring->hangcheck.score += HUNG; 20006274f212SChris Wilson stuck[i] = true; 20016274f212SChris Wilson break; 20026274f212SChris Wilson } 200305407ff8SMika Kuoppala } 20049107e9d2SChris Wilson } else { 20059107e9d2SChris Wilson /* Gradually reduce the count so that we catch DoS 20069107e9d2SChris Wilson * attempts across multiple batches. 20079107e9d2SChris Wilson */ 20089107e9d2SChris Wilson if (ring->hangcheck.score > 0) 20099107e9d2SChris Wilson ring->hangcheck.score--; 2010cbb465e7SChris Wilson } 2011f65d9421SBen Gamari 201205407ff8SMika Kuoppala ring->hangcheck.seqno = seqno; 201305407ff8SMika Kuoppala ring->hangcheck.acthd = acthd; 20149107e9d2SChris Wilson busy_count += busy; 201505407ff8SMika Kuoppala } 201605407ff8SMika Kuoppala 201705407ff8SMika Kuoppala for_each_ring(ring, dev_priv, i) { 20189107e9d2SChris Wilson if (ring->hangcheck.score > FIRE) { 2019acd78c11SBen Widawsky DRM_ERROR("%s on %s\n", 202005407ff8SMika Kuoppala stuck[i] ? "stuck" : "no progress", 2021a43adf07SChris Wilson ring->name); 2022a43adf07SChris Wilson rings_hung++; 202305407ff8SMika Kuoppala } 202405407ff8SMika Kuoppala } 202505407ff8SMika Kuoppala 202605407ff8SMika Kuoppala if (rings_hung) 202705407ff8SMika Kuoppala return i915_handle_error(dev, true); 202805407ff8SMika Kuoppala 202905407ff8SMika Kuoppala if (busy_count) 203005407ff8SMika Kuoppala /* Reset timer case chip hangs without another request 203105407ff8SMika Kuoppala * being added */ 203210cd45b6SMika Kuoppala i915_queue_hangcheck(dev); 203310cd45b6SMika Kuoppala } 203410cd45b6SMika Kuoppala 203510cd45b6SMika Kuoppala void i915_queue_hangcheck(struct drm_device *dev) 203610cd45b6SMika Kuoppala { 203710cd45b6SMika Kuoppala struct drm_i915_private *dev_priv = dev->dev_private; 203810cd45b6SMika Kuoppala if (!i915_enable_hangcheck) 203910cd45b6SMika Kuoppala return; 204010cd45b6SMika Kuoppala 204199584db3SDaniel Vetter mod_timer(&dev_priv->gpu_error.hangcheck_timer, 204210cd45b6SMika Kuoppala round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES)); 2043f65d9421SBen Gamari } 2044f65d9421SBen Gamari 204591738a95SPaulo Zanoni static void ibx_irq_preinstall(struct drm_device *dev) 204691738a95SPaulo Zanoni { 204791738a95SPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 204891738a95SPaulo Zanoni 204991738a95SPaulo Zanoni if (HAS_PCH_NOP(dev)) 205091738a95SPaulo Zanoni return; 205191738a95SPaulo Zanoni 205291738a95SPaulo Zanoni /* south display irq */ 205391738a95SPaulo Zanoni I915_WRITE(SDEIMR, 0xffffffff); 205491738a95SPaulo Zanoni /* 205591738a95SPaulo Zanoni * SDEIER is also touched by the interrupt handler to work around missed 205691738a95SPaulo Zanoni * PCH interrupts. Hence we can't update it after the interrupt handler 205791738a95SPaulo Zanoni * is enabled - instead we unconditionally enable all PCH interrupt 205891738a95SPaulo Zanoni * sources here, but then only unmask them as needed with SDEIMR. 205991738a95SPaulo Zanoni */ 206091738a95SPaulo Zanoni I915_WRITE(SDEIER, 0xffffffff); 206191738a95SPaulo Zanoni POSTING_READ(SDEIER); 206291738a95SPaulo Zanoni } 206391738a95SPaulo Zanoni 2064d18ea1b5SDaniel Vetter static void gen5_gt_irq_preinstall(struct drm_device *dev) 2065d18ea1b5SDaniel Vetter { 2066d18ea1b5SDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 2067d18ea1b5SDaniel Vetter 2068d18ea1b5SDaniel Vetter /* and GT */ 2069d18ea1b5SDaniel Vetter I915_WRITE(GTIMR, 0xffffffff); 2070d18ea1b5SDaniel Vetter I915_WRITE(GTIER, 0x0); 2071d18ea1b5SDaniel Vetter POSTING_READ(GTIER); 2072d18ea1b5SDaniel Vetter 2073d18ea1b5SDaniel Vetter if (INTEL_INFO(dev)->gen >= 6) { 2074d18ea1b5SDaniel Vetter /* and PM */ 2075d18ea1b5SDaniel Vetter I915_WRITE(GEN6_PMIMR, 0xffffffff); 2076d18ea1b5SDaniel Vetter I915_WRITE(GEN6_PMIER, 0x0); 2077d18ea1b5SDaniel Vetter POSTING_READ(GEN6_PMIER); 2078d18ea1b5SDaniel Vetter } 2079d18ea1b5SDaniel Vetter } 2080d18ea1b5SDaniel Vetter 2081c0e09200SDave Airlie /* drm_dma.h hooks 2082c0e09200SDave Airlie */ 2083f71d4af4SJesse Barnes static void ironlake_irq_preinstall(struct drm_device *dev) 2084036a4a7dSZhenyu Wang { 2085036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2086036a4a7dSZhenyu Wang 20874697995bSJesse Barnes atomic_set(&dev_priv->irq_received, 0); 20884697995bSJesse Barnes 2089036a4a7dSZhenyu Wang I915_WRITE(HWSTAM, 0xeffe); 2090bdfcdb63SDaniel Vetter 2091036a4a7dSZhenyu Wang I915_WRITE(DEIMR, 0xffffffff); 2092036a4a7dSZhenyu Wang I915_WRITE(DEIER, 0x0); 20933143a2bfSChris Wilson POSTING_READ(DEIER); 2094036a4a7dSZhenyu Wang 2095d18ea1b5SDaniel Vetter gen5_gt_irq_preinstall(dev); 2096c650156aSZhenyu Wang 209791738a95SPaulo Zanoni ibx_irq_preinstall(dev); 20987d99163dSBen Widawsky } 20997d99163dSBen Widawsky 21007e231dbeSJesse Barnes static void valleyview_irq_preinstall(struct drm_device *dev) 21017e231dbeSJesse Barnes { 21027e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 21037e231dbeSJesse Barnes int pipe; 21047e231dbeSJesse Barnes 21057e231dbeSJesse Barnes atomic_set(&dev_priv->irq_received, 0); 21067e231dbeSJesse Barnes 21077e231dbeSJesse Barnes /* VLV magic */ 21087e231dbeSJesse Barnes I915_WRITE(VLV_IMR, 0); 21097e231dbeSJesse Barnes I915_WRITE(RING_IMR(RENDER_RING_BASE), 0); 21107e231dbeSJesse Barnes I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0); 21117e231dbeSJesse Barnes I915_WRITE(RING_IMR(BLT_RING_BASE), 0); 21127e231dbeSJesse Barnes 21137e231dbeSJesse Barnes /* and GT */ 21147e231dbeSJesse Barnes I915_WRITE(GTIIR, I915_READ(GTIIR)); 21157e231dbeSJesse Barnes I915_WRITE(GTIIR, I915_READ(GTIIR)); 2116d18ea1b5SDaniel Vetter 2117d18ea1b5SDaniel Vetter gen5_gt_irq_preinstall(dev); 21187e231dbeSJesse Barnes 21197e231dbeSJesse Barnes I915_WRITE(DPINVGTT, 0xff); 21207e231dbeSJesse Barnes 21217e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_EN, 0); 21227e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 21237e231dbeSJesse Barnes for_each_pipe(pipe) 21247e231dbeSJesse Barnes I915_WRITE(PIPESTAT(pipe), 0xffff); 21257e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 21267e231dbeSJesse Barnes I915_WRITE(VLV_IMR, 0xffffffff); 21277e231dbeSJesse Barnes I915_WRITE(VLV_IER, 0x0); 21287e231dbeSJesse Barnes POSTING_READ(VLV_IER); 21297e231dbeSJesse Barnes } 21307e231dbeSJesse Barnes 213182a28bcfSDaniel Vetter static void ibx_hpd_irq_setup(struct drm_device *dev) 213282a28bcfSDaniel Vetter { 213382a28bcfSDaniel Vetter drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 213482a28bcfSDaniel Vetter struct drm_mode_config *mode_config = &dev->mode_config; 213582a28bcfSDaniel Vetter struct intel_encoder *intel_encoder; 2136fee884edSDaniel Vetter u32 hotplug_irqs, hotplug, enabled_irqs = 0; 213782a28bcfSDaniel Vetter 213882a28bcfSDaniel Vetter if (HAS_PCH_IBX(dev)) { 2139fee884edSDaniel Vetter hotplug_irqs = SDE_HOTPLUG_MASK; 214082a28bcfSDaniel Vetter list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head) 2141cd569aedSEgbert Eich if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) 2142fee884edSDaniel Vetter enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin]; 214382a28bcfSDaniel Vetter } else { 2144fee884edSDaniel Vetter hotplug_irqs = SDE_HOTPLUG_MASK_CPT; 214582a28bcfSDaniel Vetter list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head) 2146cd569aedSEgbert Eich if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) 2147fee884edSDaniel Vetter enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin]; 214882a28bcfSDaniel Vetter } 214982a28bcfSDaniel Vetter 2150fee884edSDaniel Vetter ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); 215182a28bcfSDaniel Vetter 21527fe0b973SKeith Packard /* 21537fe0b973SKeith Packard * Enable digital hotplug on the PCH, and configure the DP short pulse 21547fe0b973SKeith Packard * duration to 2ms (which is the minimum in the Display Port spec) 21557fe0b973SKeith Packard * 21567fe0b973SKeith Packard * This register is the same on all known PCH chips. 21577fe0b973SKeith Packard */ 21587fe0b973SKeith Packard hotplug = I915_READ(PCH_PORT_HOTPLUG); 21597fe0b973SKeith Packard hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK); 21607fe0b973SKeith Packard hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms; 21617fe0b973SKeith Packard hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms; 21627fe0b973SKeith Packard hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms; 21637fe0b973SKeith Packard I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 21647fe0b973SKeith Packard } 21657fe0b973SKeith Packard 2166d46da437SPaulo Zanoni static void ibx_irq_postinstall(struct drm_device *dev) 2167d46da437SPaulo Zanoni { 2168d46da437SPaulo Zanoni drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 216982a28bcfSDaniel Vetter u32 mask; 2170d46da437SPaulo Zanoni 2171692a04cfSDaniel Vetter if (HAS_PCH_NOP(dev)) 2172692a04cfSDaniel Vetter return; 2173692a04cfSDaniel Vetter 21748664281bSPaulo Zanoni if (HAS_PCH_IBX(dev)) { 21758664281bSPaulo Zanoni mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER | 2176de032bf4SPaulo Zanoni SDE_TRANSA_FIFO_UNDER | SDE_POISON; 21778664281bSPaulo Zanoni } else { 21788664281bSPaulo Zanoni mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT; 21798664281bSPaulo Zanoni 21808664281bSPaulo Zanoni I915_WRITE(SERR_INT, I915_READ(SERR_INT)); 21818664281bSPaulo Zanoni } 2182ab5c608bSBen Widawsky 2183d46da437SPaulo Zanoni I915_WRITE(SDEIIR, I915_READ(SDEIIR)); 2184d46da437SPaulo Zanoni I915_WRITE(SDEIMR, ~mask); 2185d46da437SPaulo Zanoni } 2186d46da437SPaulo Zanoni 21870a9a8c91SDaniel Vetter static void gen5_gt_irq_postinstall(struct drm_device *dev) 21880a9a8c91SDaniel Vetter { 21890a9a8c91SDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 21900a9a8c91SDaniel Vetter u32 pm_irqs, gt_irqs; 21910a9a8c91SDaniel Vetter 21920a9a8c91SDaniel Vetter pm_irqs = gt_irqs = 0; 21930a9a8c91SDaniel Vetter 21940a9a8c91SDaniel Vetter dev_priv->gt_irq_mask = ~0; 21950a9a8c91SDaniel Vetter if (HAS_L3_GPU_CACHE(dev)) { 21960a9a8c91SDaniel Vetter /* L3 parity interrupt is always unmasked. */ 21970a9a8c91SDaniel Vetter dev_priv->gt_irq_mask = ~GT_RENDER_L3_PARITY_ERROR_INTERRUPT; 21980a9a8c91SDaniel Vetter gt_irqs |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT; 21990a9a8c91SDaniel Vetter } 22000a9a8c91SDaniel Vetter 22010a9a8c91SDaniel Vetter gt_irqs |= GT_RENDER_USER_INTERRUPT; 22020a9a8c91SDaniel Vetter if (IS_GEN5(dev)) { 22030a9a8c91SDaniel Vetter gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT | 22040a9a8c91SDaniel Vetter ILK_BSD_USER_INTERRUPT; 22050a9a8c91SDaniel Vetter } else { 22060a9a8c91SDaniel Vetter gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT; 22070a9a8c91SDaniel Vetter } 22080a9a8c91SDaniel Vetter 22090a9a8c91SDaniel Vetter I915_WRITE(GTIIR, I915_READ(GTIIR)); 22100a9a8c91SDaniel Vetter I915_WRITE(GTIMR, dev_priv->gt_irq_mask); 22110a9a8c91SDaniel Vetter I915_WRITE(GTIER, gt_irqs); 22120a9a8c91SDaniel Vetter POSTING_READ(GTIER); 22130a9a8c91SDaniel Vetter 22140a9a8c91SDaniel Vetter if (INTEL_INFO(dev)->gen >= 6) { 22150a9a8c91SDaniel Vetter pm_irqs |= GEN6_PM_RPS_EVENTS; 22160a9a8c91SDaniel Vetter 22170a9a8c91SDaniel Vetter if (HAS_VEBOX(dev)) 22180a9a8c91SDaniel Vetter pm_irqs |= PM_VEBOX_USER_INTERRUPT; 22190a9a8c91SDaniel Vetter 22200a9a8c91SDaniel Vetter I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR)); 22210a9a8c91SDaniel Vetter I915_WRITE(GEN6_PMIMR, 0xffffffff); 22220a9a8c91SDaniel Vetter I915_WRITE(GEN6_PMIER, pm_irqs); 22230a9a8c91SDaniel Vetter POSTING_READ(GEN6_PMIER); 22240a9a8c91SDaniel Vetter } 22250a9a8c91SDaniel Vetter } 22260a9a8c91SDaniel Vetter 2227f71d4af4SJesse Barnes static int ironlake_irq_postinstall(struct drm_device *dev) 2228036a4a7dSZhenyu Wang { 22294bc9d430SDaniel Vetter unsigned long irqflags; 2230036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 22318e76f8dcSPaulo Zanoni u32 display_mask, extra_mask; 22328e76f8dcSPaulo Zanoni 22338e76f8dcSPaulo Zanoni if (INTEL_INFO(dev)->gen >= 7) { 22348e76f8dcSPaulo Zanoni display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | 22358e76f8dcSPaulo Zanoni DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB | 22368e76f8dcSPaulo Zanoni DE_PLANEB_FLIP_DONE_IVB | 22378e76f8dcSPaulo Zanoni DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB | 22388e76f8dcSPaulo Zanoni DE_ERR_INT_IVB); 22398e76f8dcSPaulo Zanoni extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB | 22408e76f8dcSPaulo Zanoni DE_PIPEA_VBLANK_IVB); 22418e76f8dcSPaulo Zanoni 22428e76f8dcSPaulo Zanoni I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT)); 22438e76f8dcSPaulo Zanoni } else { 22448e76f8dcSPaulo Zanoni display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | 2245ce99c256SDaniel Vetter DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE | 22468664281bSPaulo Zanoni DE_AUX_CHANNEL_A | DE_PIPEB_FIFO_UNDERRUN | 22478e76f8dcSPaulo Zanoni DE_PIPEA_FIFO_UNDERRUN | DE_POISON); 22488e76f8dcSPaulo Zanoni extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT; 22498e76f8dcSPaulo Zanoni } 2250036a4a7dSZhenyu Wang 22511ec14ad3SChris Wilson dev_priv->irq_mask = ~display_mask; 2252036a4a7dSZhenyu Wang 2253036a4a7dSZhenyu Wang /* should always can generate irq */ 2254036a4a7dSZhenyu Wang I915_WRITE(DEIIR, I915_READ(DEIIR)); 22551ec14ad3SChris Wilson I915_WRITE(DEIMR, dev_priv->irq_mask); 22568e76f8dcSPaulo Zanoni I915_WRITE(DEIER, display_mask | extra_mask); 22573143a2bfSChris Wilson POSTING_READ(DEIER); 2258036a4a7dSZhenyu Wang 22590a9a8c91SDaniel Vetter gen5_gt_irq_postinstall(dev); 2260036a4a7dSZhenyu Wang 2261d46da437SPaulo Zanoni ibx_irq_postinstall(dev); 22627fe0b973SKeith Packard 2263f97108d1SJesse Barnes if (IS_IRONLAKE_M(dev)) { 22646005ce42SDaniel Vetter /* Enable PCU event interrupts 22656005ce42SDaniel Vetter * 22666005ce42SDaniel Vetter * spinlocking not required here for correctness since interrupt 22674bc9d430SDaniel Vetter * setup is guaranteed to run in single-threaded context. But we 22684bc9d430SDaniel Vetter * need it to make the assert_spin_locked happy. */ 22694bc9d430SDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2270f97108d1SJesse Barnes ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT); 22714bc9d430SDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2272f97108d1SJesse Barnes } 2273f97108d1SJesse Barnes 2274036a4a7dSZhenyu Wang return 0; 2275036a4a7dSZhenyu Wang } 2276036a4a7dSZhenyu Wang 22777e231dbeSJesse Barnes static int valleyview_irq_postinstall(struct drm_device *dev) 22787e231dbeSJesse Barnes { 22797e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 22807e231dbeSJesse Barnes u32 enable_mask; 228131acc7f5SJesse Barnes u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV; 2282b79480baSDaniel Vetter unsigned long irqflags; 22837e231dbeSJesse Barnes 22847e231dbeSJesse Barnes enable_mask = I915_DISPLAY_PORT_INTERRUPT; 228531acc7f5SJesse Barnes enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 228631acc7f5SJesse Barnes I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT | 228731acc7f5SJesse Barnes I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 22887e231dbeSJesse Barnes I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; 22897e231dbeSJesse Barnes 229031acc7f5SJesse Barnes /* 229131acc7f5SJesse Barnes *Leave vblank interrupts masked initially. enable/disable will 229231acc7f5SJesse Barnes * toggle them based on usage. 229331acc7f5SJesse Barnes */ 229431acc7f5SJesse Barnes dev_priv->irq_mask = (~enable_mask) | 229531acc7f5SJesse Barnes I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT | 229631acc7f5SJesse Barnes I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; 22977e231dbeSJesse Barnes 229820afbda2SDaniel Vetter I915_WRITE(PORT_HOTPLUG_EN, 0); 229920afbda2SDaniel Vetter POSTING_READ(PORT_HOTPLUG_EN); 230020afbda2SDaniel Vetter 23017e231dbeSJesse Barnes I915_WRITE(VLV_IMR, dev_priv->irq_mask); 23027e231dbeSJesse Barnes I915_WRITE(VLV_IER, enable_mask); 23037e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 23047e231dbeSJesse Barnes I915_WRITE(PIPESTAT(0), 0xffff); 23057e231dbeSJesse Barnes I915_WRITE(PIPESTAT(1), 0xffff); 23067e231dbeSJesse Barnes POSTING_READ(VLV_IER); 23077e231dbeSJesse Barnes 2308b79480baSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 2309b79480baSDaniel Vetter * just to make the assert_spin_locked check happy. */ 2310b79480baSDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 231131acc7f5SJesse Barnes i915_enable_pipestat(dev_priv, 0, pipestat_enable); 2312515ac2bbSDaniel Vetter i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE); 231331acc7f5SJesse Barnes i915_enable_pipestat(dev_priv, 1, pipestat_enable); 2314b79480baSDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 231531acc7f5SJesse Barnes 23167e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 23177e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 23187e231dbeSJesse Barnes 23190a9a8c91SDaniel Vetter gen5_gt_irq_postinstall(dev); 23207e231dbeSJesse Barnes 23217e231dbeSJesse Barnes /* ack & enable invalid PTE error interrupts */ 23227e231dbeSJesse Barnes #if 0 /* FIXME: add support to irq handler for checking these bits */ 23237e231dbeSJesse Barnes I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK); 23247e231dbeSJesse Barnes I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK); 23257e231dbeSJesse Barnes #endif 23267e231dbeSJesse Barnes 23277e231dbeSJesse Barnes I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE); 232820afbda2SDaniel Vetter 232920afbda2SDaniel Vetter return 0; 233020afbda2SDaniel Vetter } 233120afbda2SDaniel Vetter 23327e231dbeSJesse Barnes static void valleyview_irq_uninstall(struct drm_device *dev) 23337e231dbeSJesse Barnes { 23347e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 23357e231dbeSJesse Barnes int pipe; 23367e231dbeSJesse Barnes 23377e231dbeSJesse Barnes if (!dev_priv) 23387e231dbeSJesse Barnes return; 23397e231dbeSJesse Barnes 2340ac4c16c5SEgbert Eich del_timer_sync(&dev_priv->hotplug_reenable_timer); 2341ac4c16c5SEgbert Eich 23427e231dbeSJesse Barnes for_each_pipe(pipe) 23437e231dbeSJesse Barnes I915_WRITE(PIPESTAT(pipe), 0xffff); 23447e231dbeSJesse Barnes 23457e231dbeSJesse Barnes I915_WRITE(HWSTAM, 0xffffffff); 23467e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_EN, 0); 23477e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 23487e231dbeSJesse Barnes for_each_pipe(pipe) 23497e231dbeSJesse Barnes I915_WRITE(PIPESTAT(pipe), 0xffff); 23507e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 23517e231dbeSJesse Barnes I915_WRITE(VLV_IMR, 0xffffffff); 23527e231dbeSJesse Barnes I915_WRITE(VLV_IER, 0x0); 23537e231dbeSJesse Barnes POSTING_READ(VLV_IER); 23547e231dbeSJesse Barnes } 23557e231dbeSJesse Barnes 2356f71d4af4SJesse Barnes static void ironlake_irq_uninstall(struct drm_device *dev) 2357036a4a7dSZhenyu Wang { 2358036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 23594697995bSJesse Barnes 23604697995bSJesse Barnes if (!dev_priv) 23614697995bSJesse Barnes return; 23624697995bSJesse Barnes 2363ac4c16c5SEgbert Eich del_timer_sync(&dev_priv->hotplug_reenable_timer); 2364ac4c16c5SEgbert Eich 2365036a4a7dSZhenyu Wang I915_WRITE(HWSTAM, 0xffffffff); 2366036a4a7dSZhenyu Wang 2367036a4a7dSZhenyu Wang I915_WRITE(DEIMR, 0xffffffff); 2368036a4a7dSZhenyu Wang I915_WRITE(DEIER, 0x0); 2369036a4a7dSZhenyu Wang I915_WRITE(DEIIR, I915_READ(DEIIR)); 23708664281bSPaulo Zanoni if (IS_GEN7(dev)) 23718664281bSPaulo Zanoni I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT)); 2372036a4a7dSZhenyu Wang 2373036a4a7dSZhenyu Wang I915_WRITE(GTIMR, 0xffffffff); 2374036a4a7dSZhenyu Wang I915_WRITE(GTIER, 0x0); 2375036a4a7dSZhenyu Wang I915_WRITE(GTIIR, I915_READ(GTIIR)); 2376192aac1fSKeith Packard 2377ab5c608bSBen Widawsky if (HAS_PCH_NOP(dev)) 2378ab5c608bSBen Widawsky return; 2379ab5c608bSBen Widawsky 2380192aac1fSKeith Packard I915_WRITE(SDEIMR, 0xffffffff); 2381192aac1fSKeith Packard I915_WRITE(SDEIER, 0x0); 2382192aac1fSKeith Packard I915_WRITE(SDEIIR, I915_READ(SDEIIR)); 23838664281bSPaulo Zanoni if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev)) 23848664281bSPaulo Zanoni I915_WRITE(SERR_INT, I915_READ(SERR_INT)); 2385036a4a7dSZhenyu Wang } 2386036a4a7dSZhenyu Wang 2387c2798b19SChris Wilson static void i8xx_irq_preinstall(struct drm_device * dev) 2388c2798b19SChris Wilson { 2389c2798b19SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2390c2798b19SChris Wilson int pipe; 2391c2798b19SChris Wilson 2392c2798b19SChris Wilson atomic_set(&dev_priv->irq_received, 0); 2393c2798b19SChris Wilson 2394c2798b19SChris Wilson for_each_pipe(pipe) 2395c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 2396c2798b19SChris Wilson I915_WRITE16(IMR, 0xffff); 2397c2798b19SChris Wilson I915_WRITE16(IER, 0x0); 2398c2798b19SChris Wilson POSTING_READ16(IER); 2399c2798b19SChris Wilson } 2400c2798b19SChris Wilson 2401c2798b19SChris Wilson static int i8xx_irq_postinstall(struct drm_device *dev) 2402c2798b19SChris Wilson { 2403c2798b19SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2404c2798b19SChris Wilson 2405c2798b19SChris Wilson I915_WRITE16(EMR, 2406c2798b19SChris Wilson ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH)); 2407c2798b19SChris Wilson 2408c2798b19SChris Wilson /* Unmask the interrupts that we always want on. */ 2409c2798b19SChris Wilson dev_priv->irq_mask = 2410c2798b19SChris Wilson ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 2411c2798b19SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 2412c2798b19SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 2413c2798b19SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | 2414c2798b19SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 2415c2798b19SChris Wilson I915_WRITE16(IMR, dev_priv->irq_mask); 2416c2798b19SChris Wilson 2417c2798b19SChris Wilson I915_WRITE16(IER, 2418c2798b19SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 2419c2798b19SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 2420c2798b19SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT | 2421c2798b19SChris Wilson I915_USER_INTERRUPT); 2422c2798b19SChris Wilson POSTING_READ16(IER); 2423c2798b19SChris Wilson 2424c2798b19SChris Wilson return 0; 2425c2798b19SChris Wilson } 2426c2798b19SChris Wilson 242790a72f87SVille Syrjälä /* 242890a72f87SVille Syrjälä * Returns true when a page flip has completed. 242990a72f87SVille Syrjälä */ 243090a72f87SVille Syrjälä static bool i8xx_handle_vblank(struct drm_device *dev, 243190a72f87SVille Syrjälä int pipe, u16 iir) 243290a72f87SVille Syrjälä { 243390a72f87SVille Syrjälä drm_i915_private_t *dev_priv = dev->dev_private; 243490a72f87SVille Syrjälä u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(pipe); 243590a72f87SVille Syrjälä 243690a72f87SVille Syrjälä if (!drm_handle_vblank(dev, pipe)) 243790a72f87SVille Syrjälä return false; 243890a72f87SVille Syrjälä 243990a72f87SVille Syrjälä if ((iir & flip_pending) == 0) 244090a72f87SVille Syrjälä return false; 244190a72f87SVille Syrjälä 244290a72f87SVille Syrjälä intel_prepare_page_flip(dev, pipe); 244390a72f87SVille Syrjälä 244490a72f87SVille Syrjälä /* We detect FlipDone by looking for the change in PendingFlip from '1' 244590a72f87SVille Syrjälä * to '0' on the following vblank, i.e. IIR has the Pendingflip 244690a72f87SVille Syrjälä * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence 244790a72f87SVille Syrjälä * the flip is completed (no longer pending). Since this doesn't raise 244890a72f87SVille Syrjälä * an interrupt per se, we watch for the change at vblank. 244990a72f87SVille Syrjälä */ 245090a72f87SVille Syrjälä if (I915_READ16(ISR) & flip_pending) 245190a72f87SVille Syrjälä return false; 245290a72f87SVille Syrjälä 245390a72f87SVille Syrjälä intel_finish_page_flip(dev, pipe); 245490a72f87SVille Syrjälä 245590a72f87SVille Syrjälä return true; 245690a72f87SVille Syrjälä } 245790a72f87SVille Syrjälä 2458ff1f525eSDaniel Vetter static irqreturn_t i8xx_irq_handler(int irq, void *arg) 2459c2798b19SChris Wilson { 2460c2798b19SChris Wilson struct drm_device *dev = (struct drm_device *) arg; 2461c2798b19SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2462c2798b19SChris Wilson u16 iir, new_iir; 2463c2798b19SChris Wilson u32 pipe_stats[2]; 2464c2798b19SChris Wilson unsigned long irqflags; 2465c2798b19SChris Wilson int pipe; 2466c2798b19SChris Wilson u16 flip_mask = 2467c2798b19SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 2468c2798b19SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 2469c2798b19SChris Wilson 2470c2798b19SChris Wilson atomic_inc(&dev_priv->irq_received); 2471c2798b19SChris Wilson 2472c2798b19SChris Wilson iir = I915_READ16(IIR); 2473c2798b19SChris Wilson if (iir == 0) 2474c2798b19SChris Wilson return IRQ_NONE; 2475c2798b19SChris Wilson 2476c2798b19SChris Wilson while (iir & ~flip_mask) { 2477c2798b19SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 2478c2798b19SChris Wilson * have been cleared after the pipestat interrupt was received. 2479c2798b19SChris Wilson * It doesn't set the bit in iir again, but it still produces 2480c2798b19SChris Wilson * interrupts (for non-MSI). 2481c2798b19SChris Wilson */ 2482c2798b19SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2483c2798b19SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 2484c2798b19SChris Wilson i915_handle_error(dev, false); 2485c2798b19SChris Wilson 2486c2798b19SChris Wilson for_each_pipe(pipe) { 2487c2798b19SChris Wilson int reg = PIPESTAT(pipe); 2488c2798b19SChris Wilson pipe_stats[pipe] = I915_READ(reg); 2489c2798b19SChris Wilson 2490c2798b19SChris Wilson /* 2491c2798b19SChris Wilson * Clear the PIPE*STAT regs before the IIR 2492c2798b19SChris Wilson */ 2493c2798b19SChris Wilson if (pipe_stats[pipe] & 0x8000ffff) { 2494c2798b19SChris Wilson if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 2495c2798b19SChris Wilson DRM_DEBUG_DRIVER("pipe %c underrun\n", 2496c2798b19SChris Wilson pipe_name(pipe)); 2497c2798b19SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 2498c2798b19SChris Wilson } 2499c2798b19SChris Wilson } 2500c2798b19SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2501c2798b19SChris Wilson 2502c2798b19SChris Wilson I915_WRITE16(IIR, iir & ~flip_mask); 2503c2798b19SChris Wilson new_iir = I915_READ16(IIR); /* Flush posted writes */ 2504c2798b19SChris Wilson 2505d05c617eSDaniel Vetter i915_update_dri1_breadcrumb(dev); 2506c2798b19SChris Wilson 2507c2798b19SChris Wilson if (iir & I915_USER_INTERRUPT) 2508c2798b19SChris Wilson notify_ring(dev, &dev_priv->ring[RCS]); 2509c2798b19SChris Wilson 2510c2798b19SChris Wilson if (pipe_stats[0] & PIPE_VBLANK_INTERRUPT_STATUS && 251190a72f87SVille Syrjälä i8xx_handle_vblank(dev, 0, iir)) 251290a72f87SVille Syrjälä flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(0); 2513c2798b19SChris Wilson 2514c2798b19SChris Wilson if (pipe_stats[1] & PIPE_VBLANK_INTERRUPT_STATUS && 251590a72f87SVille Syrjälä i8xx_handle_vblank(dev, 1, iir)) 251690a72f87SVille Syrjälä flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(1); 2517c2798b19SChris Wilson 2518c2798b19SChris Wilson iir = new_iir; 2519c2798b19SChris Wilson } 2520c2798b19SChris Wilson 2521c2798b19SChris Wilson return IRQ_HANDLED; 2522c2798b19SChris Wilson } 2523c2798b19SChris Wilson 2524c2798b19SChris Wilson static void i8xx_irq_uninstall(struct drm_device * dev) 2525c2798b19SChris Wilson { 2526c2798b19SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2527c2798b19SChris Wilson int pipe; 2528c2798b19SChris Wilson 2529c2798b19SChris Wilson for_each_pipe(pipe) { 2530c2798b19SChris Wilson /* Clear enable bits; then clear status bits */ 2531c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 2532c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe))); 2533c2798b19SChris Wilson } 2534c2798b19SChris Wilson I915_WRITE16(IMR, 0xffff); 2535c2798b19SChris Wilson I915_WRITE16(IER, 0x0); 2536c2798b19SChris Wilson I915_WRITE16(IIR, I915_READ16(IIR)); 2537c2798b19SChris Wilson } 2538c2798b19SChris Wilson 2539a266c7d5SChris Wilson static void i915_irq_preinstall(struct drm_device * dev) 2540a266c7d5SChris Wilson { 2541a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2542a266c7d5SChris Wilson int pipe; 2543a266c7d5SChris Wilson 2544a266c7d5SChris Wilson atomic_set(&dev_priv->irq_received, 0); 2545a266c7d5SChris Wilson 2546a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 2547a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 2548a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 2549a266c7d5SChris Wilson } 2550a266c7d5SChris Wilson 255100d98ebdSChris Wilson I915_WRITE16(HWSTAM, 0xeffe); 2552a266c7d5SChris Wilson for_each_pipe(pipe) 2553a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 2554a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 2555a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 2556a266c7d5SChris Wilson POSTING_READ(IER); 2557a266c7d5SChris Wilson } 2558a266c7d5SChris Wilson 2559a266c7d5SChris Wilson static int i915_irq_postinstall(struct drm_device *dev) 2560a266c7d5SChris Wilson { 2561a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 256238bde180SChris Wilson u32 enable_mask; 2563a266c7d5SChris Wilson 256438bde180SChris Wilson I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH)); 256538bde180SChris Wilson 256638bde180SChris Wilson /* Unmask the interrupts that we always want on. */ 256738bde180SChris Wilson dev_priv->irq_mask = 256838bde180SChris Wilson ~(I915_ASLE_INTERRUPT | 256938bde180SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 257038bde180SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 257138bde180SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 257238bde180SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | 257338bde180SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 257438bde180SChris Wilson 257538bde180SChris Wilson enable_mask = 257638bde180SChris Wilson I915_ASLE_INTERRUPT | 257738bde180SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 257838bde180SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 257938bde180SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT | 258038bde180SChris Wilson I915_USER_INTERRUPT; 258138bde180SChris Wilson 2582a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 258320afbda2SDaniel Vetter I915_WRITE(PORT_HOTPLUG_EN, 0); 258420afbda2SDaniel Vetter POSTING_READ(PORT_HOTPLUG_EN); 258520afbda2SDaniel Vetter 2586a266c7d5SChris Wilson /* Enable in IER... */ 2587a266c7d5SChris Wilson enable_mask |= I915_DISPLAY_PORT_INTERRUPT; 2588a266c7d5SChris Wilson /* and unmask in IMR */ 2589a266c7d5SChris Wilson dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT; 2590a266c7d5SChris Wilson } 2591a266c7d5SChris Wilson 2592a266c7d5SChris Wilson I915_WRITE(IMR, dev_priv->irq_mask); 2593a266c7d5SChris Wilson I915_WRITE(IER, enable_mask); 2594a266c7d5SChris Wilson POSTING_READ(IER); 2595a266c7d5SChris Wilson 2596f49e38ddSJani Nikula i915_enable_asle_pipestat(dev); 259720afbda2SDaniel Vetter 259820afbda2SDaniel Vetter return 0; 259920afbda2SDaniel Vetter } 260020afbda2SDaniel Vetter 260190a72f87SVille Syrjälä /* 260290a72f87SVille Syrjälä * Returns true when a page flip has completed. 260390a72f87SVille Syrjälä */ 260490a72f87SVille Syrjälä static bool i915_handle_vblank(struct drm_device *dev, 260590a72f87SVille Syrjälä int plane, int pipe, u32 iir) 260690a72f87SVille Syrjälä { 260790a72f87SVille Syrjälä drm_i915_private_t *dev_priv = dev->dev_private; 260890a72f87SVille Syrjälä u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane); 260990a72f87SVille Syrjälä 261090a72f87SVille Syrjälä if (!drm_handle_vblank(dev, pipe)) 261190a72f87SVille Syrjälä return false; 261290a72f87SVille Syrjälä 261390a72f87SVille Syrjälä if ((iir & flip_pending) == 0) 261490a72f87SVille Syrjälä return false; 261590a72f87SVille Syrjälä 261690a72f87SVille Syrjälä intel_prepare_page_flip(dev, plane); 261790a72f87SVille Syrjälä 261890a72f87SVille Syrjälä /* We detect FlipDone by looking for the change in PendingFlip from '1' 261990a72f87SVille Syrjälä * to '0' on the following vblank, i.e. IIR has the Pendingflip 262090a72f87SVille Syrjälä * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence 262190a72f87SVille Syrjälä * the flip is completed (no longer pending). Since this doesn't raise 262290a72f87SVille Syrjälä * an interrupt per se, we watch for the change at vblank. 262390a72f87SVille Syrjälä */ 262490a72f87SVille Syrjälä if (I915_READ(ISR) & flip_pending) 262590a72f87SVille Syrjälä return false; 262690a72f87SVille Syrjälä 262790a72f87SVille Syrjälä intel_finish_page_flip(dev, pipe); 262890a72f87SVille Syrjälä 262990a72f87SVille Syrjälä return true; 263090a72f87SVille Syrjälä } 263190a72f87SVille Syrjälä 2632ff1f525eSDaniel Vetter static irqreturn_t i915_irq_handler(int irq, void *arg) 2633a266c7d5SChris Wilson { 2634a266c7d5SChris Wilson struct drm_device *dev = (struct drm_device *) arg; 2635a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 26368291ee90SChris Wilson u32 iir, new_iir, pipe_stats[I915_MAX_PIPES]; 2637a266c7d5SChris Wilson unsigned long irqflags; 263838bde180SChris Wilson u32 flip_mask = 263938bde180SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 264038bde180SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 264138bde180SChris Wilson int pipe, ret = IRQ_NONE; 2642a266c7d5SChris Wilson 2643a266c7d5SChris Wilson atomic_inc(&dev_priv->irq_received); 2644a266c7d5SChris Wilson 2645a266c7d5SChris Wilson iir = I915_READ(IIR); 264638bde180SChris Wilson do { 264738bde180SChris Wilson bool irq_received = (iir & ~flip_mask) != 0; 26488291ee90SChris Wilson bool blc_event = false; 2649a266c7d5SChris Wilson 2650a266c7d5SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 2651a266c7d5SChris Wilson * have been cleared after the pipestat interrupt was received. 2652a266c7d5SChris Wilson * It doesn't set the bit in iir again, but it still produces 2653a266c7d5SChris Wilson * interrupts (for non-MSI). 2654a266c7d5SChris Wilson */ 2655a266c7d5SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2656a266c7d5SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 2657a266c7d5SChris Wilson i915_handle_error(dev, false); 2658a266c7d5SChris Wilson 2659a266c7d5SChris Wilson for_each_pipe(pipe) { 2660a266c7d5SChris Wilson int reg = PIPESTAT(pipe); 2661a266c7d5SChris Wilson pipe_stats[pipe] = I915_READ(reg); 2662a266c7d5SChris Wilson 266338bde180SChris Wilson /* Clear the PIPE*STAT regs before the IIR */ 2664a266c7d5SChris Wilson if (pipe_stats[pipe] & 0x8000ffff) { 2665a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 2666a266c7d5SChris Wilson DRM_DEBUG_DRIVER("pipe %c underrun\n", 2667a266c7d5SChris Wilson pipe_name(pipe)); 2668a266c7d5SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 266938bde180SChris Wilson irq_received = true; 2670a266c7d5SChris Wilson } 2671a266c7d5SChris Wilson } 2672a266c7d5SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2673a266c7d5SChris Wilson 2674a266c7d5SChris Wilson if (!irq_received) 2675a266c7d5SChris Wilson break; 2676a266c7d5SChris Wilson 2677a266c7d5SChris Wilson /* Consume port. Then clear IIR or we'll miss events */ 2678a266c7d5SChris Wilson if ((I915_HAS_HOTPLUG(dev)) && 2679a266c7d5SChris Wilson (iir & I915_DISPLAY_PORT_INTERRUPT)) { 2680a266c7d5SChris Wilson u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); 2681b543fb04SEgbert Eich u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915; 2682a266c7d5SChris Wilson 2683a266c7d5SChris Wilson DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n", 2684a266c7d5SChris Wilson hotplug_status); 268591d131d2SDaniel Vetter 268610a504deSDaniel Vetter intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915); 268791d131d2SDaniel Vetter 2688a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); 268938bde180SChris Wilson POSTING_READ(PORT_HOTPLUG_STAT); 2690a266c7d5SChris Wilson } 2691a266c7d5SChris Wilson 269238bde180SChris Wilson I915_WRITE(IIR, iir & ~flip_mask); 2693a266c7d5SChris Wilson new_iir = I915_READ(IIR); /* Flush posted writes */ 2694a266c7d5SChris Wilson 2695a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 2696a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[RCS]); 2697a266c7d5SChris Wilson 2698a266c7d5SChris Wilson for_each_pipe(pipe) { 269938bde180SChris Wilson int plane = pipe; 270038bde180SChris Wilson if (IS_MOBILE(dev)) 270138bde180SChris Wilson plane = !plane; 27025e2032d4SVille Syrjälä 270390a72f87SVille Syrjälä if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS && 270490a72f87SVille Syrjälä i915_handle_vblank(dev, plane, pipe, iir)) 270590a72f87SVille Syrjälä flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane); 2706a266c7d5SChris Wilson 2707a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 2708a266c7d5SChris Wilson blc_event = true; 2709a266c7d5SChris Wilson } 2710a266c7d5SChris Wilson 2711a266c7d5SChris Wilson if (blc_event || (iir & I915_ASLE_INTERRUPT)) 2712a266c7d5SChris Wilson intel_opregion_asle_intr(dev); 2713a266c7d5SChris Wilson 2714a266c7d5SChris Wilson /* With MSI, interrupts are only generated when iir 2715a266c7d5SChris Wilson * transitions from zero to nonzero. If another bit got 2716a266c7d5SChris Wilson * set while we were handling the existing iir bits, then 2717a266c7d5SChris Wilson * we would never get another interrupt. 2718a266c7d5SChris Wilson * 2719a266c7d5SChris Wilson * This is fine on non-MSI as well, as if we hit this path 2720a266c7d5SChris Wilson * we avoid exiting the interrupt handler only to generate 2721a266c7d5SChris Wilson * another one. 2722a266c7d5SChris Wilson * 2723a266c7d5SChris Wilson * Note that for MSI this could cause a stray interrupt report 2724a266c7d5SChris Wilson * if an interrupt landed in the time between writing IIR and 2725a266c7d5SChris Wilson * the posting read. This should be rare enough to never 2726a266c7d5SChris Wilson * trigger the 99% of 100,000 interrupts test for disabling 2727a266c7d5SChris Wilson * stray interrupts. 2728a266c7d5SChris Wilson */ 272938bde180SChris Wilson ret = IRQ_HANDLED; 2730a266c7d5SChris Wilson iir = new_iir; 273138bde180SChris Wilson } while (iir & ~flip_mask); 2732a266c7d5SChris Wilson 2733d05c617eSDaniel Vetter i915_update_dri1_breadcrumb(dev); 27348291ee90SChris Wilson 2735a266c7d5SChris Wilson return ret; 2736a266c7d5SChris Wilson } 2737a266c7d5SChris Wilson 2738a266c7d5SChris Wilson static void i915_irq_uninstall(struct drm_device * dev) 2739a266c7d5SChris Wilson { 2740a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2741a266c7d5SChris Wilson int pipe; 2742a266c7d5SChris Wilson 2743ac4c16c5SEgbert Eich del_timer_sync(&dev_priv->hotplug_reenable_timer); 2744ac4c16c5SEgbert Eich 2745a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 2746a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 2747a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 2748a266c7d5SChris Wilson } 2749a266c7d5SChris Wilson 275000d98ebdSChris Wilson I915_WRITE16(HWSTAM, 0xffff); 275155b39755SChris Wilson for_each_pipe(pipe) { 275255b39755SChris Wilson /* Clear enable bits; then clear status bits */ 2753a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 275455b39755SChris Wilson I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe))); 275555b39755SChris Wilson } 2756a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 2757a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 2758a266c7d5SChris Wilson 2759a266c7d5SChris Wilson I915_WRITE(IIR, I915_READ(IIR)); 2760a266c7d5SChris Wilson } 2761a266c7d5SChris Wilson 2762a266c7d5SChris Wilson static void i965_irq_preinstall(struct drm_device * dev) 2763a266c7d5SChris Wilson { 2764a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2765a266c7d5SChris Wilson int pipe; 2766a266c7d5SChris Wilson 2767a266c7d5SChris Wilson atomic_set(&dev_priv->irq_received, 0); 2768a266c7d5SChris Wilson 2769a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 2770a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 2771a266c7d5SChris Wilson 2772a266c7d5SChris Wilson I915_WRITE(HWSTAM, 0xeffe); 2773a266c7d5SChris Wilson for_each_pipe(pipe) 2774a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 2775a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 2776a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 2777a266c7d5SChris Wilson POSTING_READ(IER); 2778a266c7d5SChris Wilson } 2779a266c7d5SChris Wilson 2780a266c7d5SChris Wilson static int i965_irq_postinstall(struct drm_device *dev) 2781a266c7d5SChris Wilson { 2782a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2783bbba0a97SChris Wilson u32 enable_mask; 2784a266c7d5SChris Wilson u32 error_mask; 2785b79480baSDaniel Vetter unsigned long irqflags; 2786a266c7d5SChris Wilson 2787a266c7d5SChris Wilson /* Unmask the interrupts that we always want on. */ 2788bbba0a97SChris Wilson dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT | 2789adca4730SChris Wilson I915_DISPLAY_PORT_INTERRUPT | 2790bbba0a97SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 2791bbba0a97SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 2792bbba0a97SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 2793bbba0a97SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | 2794bbba0a97SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 2795bbba0a97SChris Wilson 2796bbba0a97SChris Wilson enable_mask = ~dev_priv->irq_mask; 279721ad8330SVille Syrjälä enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 279821ad8330SVille Syrjälä I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT); 2799bbba0a97SChris Wilson enable_mask |= I915_USER_INTERRUPT; 2800bbba0a97SChris Wilson 2801bbba0a97SChris Wilson if (IS_G4X(dev)) 2802bbba0a97SChris Wilson enable_mask |= I915_BSD_USER_INTERRUPT; 2803a266c7d5SChris Wilson 2804b79480baSDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 2805b79480baSDaniel Vetter * just to make the assert_spin_locked check happy. */ 2806b79480baSDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2807515ac2bbSDaniel Vetter i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE); 2808b79480baSDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2809a266c7d5SChris Wilson 2810a266c7d5SChris Wilson /* 2811a266c7d5SChris Wilson * Enable some error detection, note the instruction error mask 2812a266c7d5SChris Wilson * bit is reserved, so we leave it masked. 2813a266c7d5SChris Wilson */ 2814a266c7d5SChris Wilson if (IS_G4X(dev)) { 2815a266c7d5SChris Wilson error_mask = ~(GM45_ERROR_PAGE_TABLE | 2816a266c7d5SChris Wilson GM45_ERROR_MEM_PRIV | 2817a266c7d5SChris Wilson GM45_ERROR_CP_PRIV | 2818a266c7d5SChris Wilson I915_ERROR_MEMORY_REFRESH); 2819a266c7d5SChris Wilson } else { 2820a266c7d5SChris Wilson error_mask = ~(I915_ERROR_PAGE_TABLE | 2821a266c7d5SChris Wilson I915_ERROR_MEMORY_REFRESH); 2822a266c7d5SChris Wilson } 2823a266c7d5SChris Wilson I915_WRITE(EMR, error_mask); 2824a266c7d5SChris Wilson 2825a266c7d5SChris Wilson I915_WRITE(IMR, dev_priv->irq_mask); 2826a266c7d5SChris Wilson I915_WRITE(IER, enable_mask); 2827a266c7d5SChris Wilson POSTING_READ(IER); 2828a266c7d5SChris Wilson 282920afbda2SDaniel Vetter I915_WRITE(PORT_HOTPLUG_EN, 0); 283020afbda2SDaniel Vetter POSTING_READ(PORT_HOTPLUG_EN); 283120afbda2SDaniel Vetter 2832f49e38ddSJani Nikula i915_enable_asle_pipestat(dev); 283320afbda2SDaniel Vetter 283420afbda2SDaniel Vetter return 0; 283520afbda2SDaniel Vetter } 283620afbda2SDaniel Vetter 2837bac56d5bSEgbert Eich static void i915_hpd_irq_setup(struct drm_device *dev) 283820afbda2SDaniel Vetter { 283920afbda2SDaniel Vetter drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2840e5868a31SEgbert Eich struct drm_mode_config *mode_config = &dev->mode_config; 2841cd569aedSEgbert Eich struct intel_encoder *intel_encoder; 284220afbda2SDaniel Vetter u32 hotplug_en; 284320afbda2SDaniel Vetter 2844b5ea2d56SDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 2845b5ea2d56SDaniel Vetter 2846bac56d5bSEgbert Eich if (I915_HAS_HOTPLUG(dev)) { 2847bac56d5bSEgbert Eich hotplug_en = I915_READ(PORT_HOTPLUG_EN); 2848bac56d5bSEgbert Eich hotplug_en &= ~HOTPLUG_INT_EN_MASK; 2849adca4730SChris Wilson /* Note HDMI and DP share hotplug bits */ 2850e5868a31SEgbert Eich /* enable bits are the same for all generations */ 2851cd569aedSEgbert Eich list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head) 2852cd569aedSEgbert Eich if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) 2853cd569aedSEgbert Eich hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin]; 2854a266c7d5SChris Wilson /* Programming the CRT detection parameters tends 2855a266c7d5SChris Wilson to generate a spurious hotplug event about three 2856a266c7d5SChris Wilson seconds later. So just do it once. 2857a266c7d5SChris Wilson */ 2858a266c7d5SChris Wilson if (IS_G4X(dev)) 2859a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64; 286085fc95baSDaniel Vetter hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK; 2861a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; 2862a266c7d5SChris Wilson 2863a266c7d5SChris Wilson /* Ignore TV since it's buggy */ 2864a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, hotplug_en); 2865a266c7d5SChris Wilson } 2866bac56d5bSEgbert Eich } 2867a266c7d5SChris Wilson 2868ff1f525eSDaniel Vetter static irqreturn_t i965_irq_handler(int irq, void *arg) 2869a266c7d5SChris Wilson { 2870a266c7d5SChris Wilson struct drm_device *dev = (struct drm_device *) arg; 2871a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2872a266c7d5SChris Wilson u32 iir, new_iir; 2873a266c7d5SChris Wilson u32 pipe_stats[I915_MAX_PIPES]; 2874a266c7d5SChris Wilson unsigned long irqflags; 2875a266c7d5SChris Wilson int irq_received; 2876a266c7d5SChris Wilson int ret = IRQ_NONE, pipe; 287721ad8330SVille Syrjälä u32 flip_mask = 287821ad8330SVille Syrjälä I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 287921ad8330SVille Syrjälä I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 2880a266c7d5SChris Wilson 2881a266c7d5SChris Wilson atomic_inc(&dev_priv->irq_received); 2882a266c7d5SChris Wilson 2883a266c7d5SChris Wilson iir = I915_READ(IIR); 2884a266c7d5SChris Wilson 2885a266c7d5SChris Wilson for (;;) { 28862c8ba29fSChris Wilson bool blc_event = false; 28872c8ba29fSChris Wilson 288821ad8330SVille Syrjälä irq_received = (iir & ~flip_mask) != 0; 2889a266c7d5SChris Wilson 2890a266c7d5SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 2891a266c7d5SChris Wilson * have been cleared after the pipestat interrupt was received. 2892a266c7d5SChris Wilson * It doesn't set the bit in iir again, but it still produces 2893a266c7d5SChris Wilson * interrupts (for non-MSI). 2894a266c7d5SChris Wilson */ 2895a266c7d5SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2896a266c7d5SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 2897a266c7d5SChris Wilson i915_handle_error(dev, false); 2898a266c7d5SChris Wilson 2899a266c7d5SChris Wilson for_each_pipe(pipe) { 2900a266c7d5SChris Wilson int reg = PIPESTAT(pipe); 2901a266c7d5SChris Wilson pipe_stats[pipe] = I915_READ(reg); 2902a266c7d5SChris Wilson 2903a266c7d5SChris Wilson /* 2904a266c7d5SChris Wilson * Clear the PIPE*STAT regs before the IIR 2905a266c7d5SChris Wilson */ 2906a266c7d5SChris Wilson if (pipe_stats[pipe] & 0x8000ffff) { 2907a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 2908a266c7d5SChris Wilson DRM_DEBUG_DRIVER("pipe %c underrun\n", 2909a266c7d5SChris Wilson pipe_name(pipe)); 2910a266c7d5SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 2911a266c7d5SChris Wilson irq_received = 1; 2912a266c7d5SChris Wilson } 2913a266c7d5SChris Wilson } 2914a266c7d5SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2915a266c7d5SChris Wilson 2916a266c7d5SChris Wilson if (!irq_received) 2917a266c7d5SChris Wilson break; 2918a266c7d5SChris Wilson 2919a266c7d5SChris Wilson ret = IRQ_HANDLED; 2920a266c7d5SChris Wilson 2921a266c7d5SChris Wilson /* Consume port. Then clear IIR or we'll miss events */ 2922adca4730SChris Wilson if (iir & I915_DISPLAY_PORT_INTERRUPT) { 2923a266c7d5SChris Wilson u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); 2924b543fb04SEgbert Eich u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ? 2925b543fb04SEgbert Eich HOTPLUG_INT_STATUS_G4X : 29264f7fd709SDaniel Vetter HOTPLUG_INT_STATUS_I915); 2927a266c7d5SChris Wilson 2928a266c7d5SChris Wilson DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n", 2929a266c7d5SChris Wilson hotplug_status); 293091d131d2SDaniel Vetter 293110a504deSDaniel Vetter intel_hpd_irq_handler(dev, hotplug_trigger, 293210a504deSDaniel Vetter IS_G4X(dev) ? hpd_status_gen4 : hpd_status_i915); 293391d131d2SDaniel Vetter 2934a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); 2935a266c7d5SChris Wilson I915_READ(PORT_HOTPLUG_STAT); 2936a266c7d5SChris Wilson } 2937a266c7d5SChris Wilson 293821ad8330SVille Syrjälä I915_WRITE(IIR, iir & ~flip_mask); 2939a266c7d5SChris Wilson new_iir = I915_READ(IIR); /* Flush posted writes */ 2940a266c7d5SChris Wilson 2941a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 2942a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[RCS]); 2943a266c7d5SChris Wilson if (iir & I915_BSD_USER_INTERRUPT) 2944a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[VCS]); 2945a266c7d5SChris Wilson 2946a266c7d5SChris Wilson for_each_pipe(pipe) { 29472c8ba29fSChris Wilson if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS && 294890a72f87SVille Syrjälä i915_handle_vblank(dev, pipe, pipe, iir)) 294990a72f87SVille Syrjälä flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe); 2950a266c7d5SChris Wilson 2951a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 2952a266c7d5SChris Wilson blc_event = true; 2953a266c7d5SChris Wilson } 2954a266c7d5SChris Wilson 2955a266c7d5SChris Wilson 2956a266c7d5SChris Wilson if (blc_event || (iir & I915_ASLE_INTERRUPT)) 2957a266c7d5SChris Wilson intel_opregion_asle_intr(dev); 2958a266c7d5SChris Wilson 2959515ac2bbSDaniel Vetter if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 2960515ac2bbSDaniel Vetter gmbus_irq_handler(dev); 2961515ac2bbSDaniel Vetter 2962a266c7d5SChris Wilson /* With MSI, interrupts are only generated when iir 2963a266c7d5SChris Wilson * transitions from zero to nonzero. If another bit got 2964a266c7d5SChris Wilson * set while we were handling the existing iir bits, then 2965a266c7d5SChris Wilson * we would never get another interrupt. 2966a266c7d5SChris Wilson * 2967a266c7d5SChris Wilson * This is fine on non-MSI as well, as if we hit this path 2968a266c7d5SChris Wilson * we avoid exiting the interrupt handler only to generate 2969a266c7d5SChris Wilson * another one. 2970a266c7d5SChris Wilson * 2971a266c7d5SChris Wilson * Note that for MSI this could cause a stray interrupt report 2972a266c7d5SChris Wilson * if an interrupt landed in the time between writing IIR and 2973a266c7d5SChris Wilson * the posting read. This should be rare enough to never 2974a266c7d5SChris Wilson * trigger the 99% of 100,000 interrupts test for disabling 2975a266c7d5SChris Wilson * stray interrupts. 2976a266c7d5SChris Wilson */ 2977a266c7d5SChris Wilson iir = new_iir; 2978a266c7d5SChris Wilson } 2979a266c7d5SChris Wilson 2980d05c617eSDaniel Vetter i915_update_dri1_breadcrumb(dev); 29812c8ba29fSChris Wilson 2982a266c7d5SChris Wilson return ret; 2983a266c7d5SChris Wilson } 2984a266c7d5SChris Wilson 2985a266c7d5SChris Wilson static void i965_irq_uninstall(struct drm_device * dev) 2986a266c7d5SChris Wilson { 2987a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2988a266c7d5SChris Wilson int pipe; 2989a266c7d5SChris Wilson 2990a266c7d5SChris Wilson if (!dev_priv) 2991a266c7d5SChris Wilson return; 2992a266c7d5SChris Wilson 2993ac4c16c5SEgbert Eich del_timer_sync(&dev_priv->hotplug_reenable_timer); 2994ac4c16c5SEgbert Eich 2995a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 2996a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 2997a266c7d5SChris Wilson 2998a266c7d5SChris Wilson I915_WRITE(HWSTAM, 0xffffffff); 2999a266c7d5SChris Wilson for_each_pipe(pipe) 3000a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3001a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 3002a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 3003a266c7d5SChris Wilson 3004a266c7d5SChris Wilson for_each_pipe(pipe) 3005a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 3006a266c7d5SChris Wilson I915_READ(PIPESTAT(pipe)) & 0x8000ffff); 3007a266c7d5SChris Wilson I915_WRITE(IIR, I915_READ(IIR)); 3008a266c7d5SChris Wilson } 3009a266c7d5SChris Wilson 3010ac4c16c5SEgbert Eich static void i915_reenable_hotplug_timer_func(unsigned long data) 3011ac4c16c5SEgbert Eich { 3012ac4c16c5SEgbert Eich drm_i915_private_t *dev_priv = (drm_i915_private_t *)data; 3013ac4c16c5SEgbert Eich struct drm_device *dev = dev_priv->dev; 3014ac4c16c5SEgbert Eich struct drm_mode_config *mode_config = &dev->mode_config; 3015ac4c16c5SEgbert Eich unsigned long irqflags; 3016ac4c16c5SEgbert Eich int i; 3017ac4c16c5SEgbert Eich 3018ac4c16c5SEgbert Eich spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3019ac4c16c5SEgbert Eich for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) { 3020ac4c16c5SEgbert Eich struct drm_connector *connector; 3021ac4c16c5SEgbert Eich 3022ac4c16c5SEgbert Eich if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED) 3023ac4c16c5SEgbert Eich continue; 3024ac4c16c5SEgbert Eich 3025ac4c16c5SEgbert Eich dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED; 3026ac4c16c5SEgbert Eich 3027ac4c16c5SEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 3028ac4c16c5SEgbert Eich struct intel_connector *intel_connector = to_intel_connector(connector); 3029ac4c16c5SEgbert Eich 3030ac4c16c5SEgbert Eich if (intel_connector->encoder->hpd_pin == i) { 3031ac4c16c5SEgbert Eich if (connector->polled != intel_connector->polled) 3032ac4c16c5SEgbert Eich DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n", 3033ac4c16c5SEgbert Eich drm_get_connector_name(connector)); 3034ac4c16c5SEgbert Eich connector->polled = intel_connector->polled; 3035ac4c16c5SEgbert Eich if (!connector->polled) 3036ac4c16c5SEgbert Eich connector->polled = DRM_CONNECTOR_POLL_HPD; 3037ac4c16c5SEgbert Eich } 3038ac4c16c5SEgbert Eich } 3039ac4c16c5SEgbert Eich } 3040ac4c16c5SEgbert Eich if (dev_priv->display.hpd_irq_setup) 3041ac4c16c5SEgbert Eich dev_priv->display.hpd_irq_setup(dev); 3042ac4c16c5SEgbert Eich spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3043ac4c16c5SEgbert Eich } 3044ac4c16c5SEgbert Eich 3045f71d4af4SJesse Barnes void intel_irq_init(struct drm_device *dev) 3046f71d4af4SJesse Barnes { 30478b2e326dSChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 30488b2e326dSChris Wilson 30498b2e326dSChris Wilson INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func); 305099584db3SDaniel Vetter INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func); 3051c6a828d3SDaniel Vetter INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work); 3052a4da4fa4SDaniel Vetter INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work); 30538b2e326dSChris Wilson 305499584db3SDaniel Vetter setup_timer(&dev_priv->gpu_error.hangcheck_timer, 305599584db3SDaniel Vetter i915_hangcheck_elapsed, 305661bac78eSDaniel Vetter (unsigned long) dev); 3057ac4c16c5SEgbert Eich setup_timer(&dev_priv->hotplug_reenable_timer, i915_reenable_hotplug_timer_func, 3058ac4c16c5SEgbert Eich (unsigned long) dev_priv); 305961bac78eSDaniel Vetter 306097a19a24STomas Janousek pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE); 30619ee32feaSDaniel Vetter 3062f71d4af4SJesse Barnes dev->driver->get_vblank_counter = i915_get_vblank_counter; 3063f71d4af4SJesse Barnes dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ 30647d4e146fSEugeni Dodonov if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { 3065f71d4af4SJesse Barnes dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */ 3066f71d4af4SJesse Barnes dev->driver->get_vblank_counter = gm45_get_vblank_counter; 3067f71d4af4SJesse Barnes } 3068f71d4af4SJesse Barnes 3069c3613de9SKeith Packard if (drm_core_check_feature(dev, DRIVER_MODESET)) 3070f71d4af4SJesse Barnes dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp; 3071c3613de9SKeith Packard else 3072c3613de9SKeith Packard dev->driver->get_vblank_timestamp = NULL; 3073f71d4af4SJesse Barnes dev->driver->get_scanout_position = i915_get_crtc_scanoutpos; 3074f71d4af4SJesse Barnes 30757e231dbeSJesse Barnes if (IS_VALLEYVIEW(dev)) { 30767e231dbeSJesse Barnes dev->driver->irq_handler = valleyview_irq_handler; 30777e231dbeSJesse Barnes dev->driver->irq_preinstall = valleyview_irq_preinstall; 30787e231dbeSJesse Barnes dev->driver->irq_postinstall = valleyview_irq_postinstall; 30797e231dbeSJesse Barnes dev->driver->irq_uninstall = valleyview_irq_uninstall; 30807e231dbeSJesse Barnes dev->driver->enable_vblank = valleyview_enable_vblank; 30817e231dbeSJesse Barnes dev->driver->disable_vblank = valleyview_disable_vblank; 3082fa00abe0SEgbert Eich dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 3083f71d4af4SJesse Barnes } else if (HAS_PCH_SPLIT(dev)) { 3084f71d4af4SJesse Barnes dev->driver->irq_handler = ironlake_irq_handler; 3085f71d4af4SJesse Barnes dev->driver->irq_preinstall = ironlake_irq_preinstall; 3086f71d4af4SJesse Barnes dev->driver->irq_postinstall = ironlake_irq_postinstall; 3087f71d4af4SJesse Barnes dev->driver->irq_uninstall = ironlake_irq_uninstall; 3088f71d4af4SJesse Barnes dev->driver->enable_vblank = ironlake_enable_vblank; 3089f71d4af4SJesse Barnes dev->driver->disable_vblank = ironlake_disable_vblank; 309082a28bcfSDaniel Vetter dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup; 3091f71d4af4SJesse Barnes } else { 3092c2798b19SChris Wilson if (INTEL_INFO(dev)->gen == 2) { 3093c2798b19SChris Wilson dev->driver->irq_preinstall = i8xx_irq_preinstall; 3094c2798b19SChris Wilson dev->driver->irq_postinstall = i8xx_irq_postinstall; 3095c2798b19SChris Wilson dev->driver->irq_handler = i8xx_irq_handler; 3096c2798b19SChris Wilson dev->driver->irq_uninstall = i8xx_irq_uninstall; 3097a266c7d5SChris Wilson } else if (INTEL_INFO(dev)->gen == 3) { 3098a266c7d5SChris Wilson dev->driver->irq_preinstall = i915_irq_preinstall; 3099a266c7d5SChris Wilson dev->driver->irq_postinstall = i915_irq_postinstall; 3100a266c7d5SChris Wilson dev->driver->irq_uninstall = i915_irq_uninstall; 3101a266c7d5SChris Wilson dev->driver->irq_handler = i915_irq_handler; 310220afbda2SDaniel Vetter dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 3103c2798b19SChris Wilson } else { 3104a266c7d5SChris Wilson dev->driver->irq_preinstall = i965_irq_preinstall; 3105a266c7d5SChris Wilson dev->driver->irq_postinstall = i965_irq_postinstall; 3106a266c7d5SChris Wilson dev->driver->irq_uninstall = i965_irq_uninstall; 3107a266c7d5SChris Wilson dev->driver->irq_handler = i965_irq_handler; 3108bac56d5bSEgbert Eich dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 3109c2798b19SChris Wilson } 3110f71d4af4SJesse Barnes dev->driver->enable_vblank = i915_enable_vblank; 3111f71d4af4SJesse Barnes dev->driver->disable_vblank = i915_disable_vblank; 3112f71d4af4SJesse Barnes } 3113f71d4af4SJesse Barnes } 311420afbda2SDaniel Vetter 311520afbda2SDaniel Vetter void intel_hpd_init(struct drm_device *dev) 311620afbda2SDaniel Vetter { 311720afbda2SDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 3118821450c6SEgbert Eich struct drm_mode_config *mode_config = &dev->mode_config; 3119821450c6SEgbert Eich struct drm_connector *connector; 3120b5ea2d56SDaniel Vetter unsigned long irqflags; 3121821450c6SEgbert Eich int i; 312220afbda2SDaniel Vetter 3123821450c6SEgbert Eich for (i = 1; i < HPD_NUM_PINS; i++) { 3124821450c6SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt = 0; 3125821450c6SEgbert Eich dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED; 3126821450c6SEgbert Eich } 3127821450c6SEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 3128821450c6SEgbert Eich struct intel_connector *intel_connector = to_intel_connector(connector); 3129821450c6SEgbert Eich connector->polled = intel_connector->polled; 3130821450c6SEgbert Eich if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE) 3131821450c6SEgbert Eich connector->polled = DRM_CONNECTOR_POLL_HPD; 3132821450c6SEgbert Eich } 3133b5ea2d56SDaniel Vetter 3134b5ea2d56SDaniel Vetter /* Interrupt setup is already guaranteed to be single-threaded, this is 3135b5ea2d56SDaniel Vetter * just to make the assert_spin_locked checks happy. */ 3136b5ea2d56SDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 313720afbda2SDaniel Vetter if (dev_priv->display.hpd_irq_setup) 313820afbda2SDaniel Vetter dev_priv->display.hpd_irq_setup(dev); 3139b5ea2d56SDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 314020afbda2SDaniel Vetter } 3141