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 1078664281bSPaulo Zanoni static bool ivb_can_enable_err_int(struct drm_device *dev) 1088664281bSPaulo Zanoni { 1098664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 1108664281bSPaulo Zanoni struct intel_crtc *crtc; 1118664281bSPaulo Zanoni enum pipe pipe; 1128664281bSPaulo Zanoni 1134bc9d430SDaniel Vetter assert_spin_locked(&dev_priv->irq_lock); 1144bc9d430SDaniel Vetter 1158664281bSPaulo Zanoni for_each_pipe(pipe) { 1168664281bSPaulo Zanoni crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); 1178664281bSPaulo Zanoni 1188664281bSPaulo Zanoni if (crtc->cpu_fifo_underrun_disabled) 1198664281bSPaulo Zanoni return false; 1208664281bSPaulo Zanoni } 1218664281bSPaulo Zanoni 1228664281bSPaulo Zanoni return true; 1238664281bSPaulo Zanoni } 1248664281bSPaulo Zanoni 1258664281bSPaulo Zanoni static bool cpt_can_enable_serr_int(struct drm_device *dev) 1268664281bSPaulo Zanoni { 1278664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 1288664281bSPaulo Zanoni enum pipe pipe; 1298664281bSPaulo Zanoni struct intel_crtc *crtc; 1308664281bSPaulo Zanoni 1318664281bSPaulo Zanoni for_each_pipe(pipe) { 1328664281bSPaulo Zanoni crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); 1338664281bSPaulo Zanoni 1348664281bSPaulo Zanoni if (crtc->pch_fifo_underrun_disabled) 1358664281bSPaulo Zanoni return false; 1368664281bSPaulo Zanoni } 1378664281bSPaulo Zanoni 1388664281bSPaulo Zanoni return true; 1398664281bSPaulo Zanoni } 1408664281bSPaulo Zanoni 1418664281bSPaulo Zanoni static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev, 1428664281bSPaulo Zanoni enum pipe pipe, bool enable) 1438664281bSPaulo Zanoni { 1448664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 1458664281bSPaulo Zanoni uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN : 1468664281bSPaulo Zanoni DE_PIPEB_FIFO_UNDERRUN; 1478664281bSPaulo Zanoni 1488664281bSPaulo Zanoni if (enable) 1498664281bSPaulo Zanoni ironlake_enable_display_irq(dev_priv, bit); 1508664281bSPaulo Zanoni else 1518664281bSPaulo Zanoni ironlake_disable_display_irq(dev_priv, bit); 1528664281bSPaulo Zanoni } 1538664281bSPaulo Zanoni 1548664281bSPaulo Zanoni static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev, 1558664281bSPaulo Zanoni bool enable) 1568664281bSPaulo Zanoni { 1578664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 1588664281bSPaulo Zanoni 1598664281bSPaulo Zanoni if (enable) { 1608664281bSPaulo Zanoni if (!ivb_can_enable_err_int(dev)) 1618664281bSPaulo Zanoni return; 1628664281bSPaulo Zanoni 1638664281bSPaulo Zanoni I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN_A | 1648664281bSPaulo Zanoni ERR_INT_FIFO_UNDERRUN_B | 1658664281bSPaulo Zanoni ERR_INT_FIFO_UNDERRUN_C); 1668664281bSPaulo Zanoni 1678664281bSPaulo Zanoni ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB); 1688664281bSPaulo Zanoni } else { 1698664281bSPaulo Zanoni ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB); 1708664281bSPaulo Zanoni } 1718664281bSPaulo Zanoni } 1728664281bSPaulo Zanoni 1738664281bSPaulo Zanoni static void ibx_set_fifo_underrun_reporting(struct intel_crtc *crtc, 1748664281bSPaulo Zanoni bool enable) 1758664281bSPaulo Zanoni { 1768664281bSPaulo Zanoni struct drm_device *dev = crtc->base.dev; 1778664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 1788664281bSPaulo Zanoni uint32_t bit = (crtc->pipe == PIPE_A) ? SDE_TRANSA_FIFO_UNDER : 1798664281bSPaulo Zanoni SDE_TRANSB_FIFO_UNDER; 1808664281bSPaulo Zanoni 1818664281bSPaulo Zanoni if (enable) 1828664281bSPaulo Zanoni I915_WRITE(SDEIMR, I915_READ(SDEIMR) & ~bit); 1838664281bSPaulo Zanoni else 1848664281bSPaulo Zanoni I915_WRITE(SDEIMR, I915_READ(SDEIMR) | bit); 1858664281bSPaulo Zanoni 1868664281bSPaulo Zanoni POSTING_READ(SDEIMR); 1878664281bSPaulo Zanoni } 1888664281bSPaulo Zanoni 1898664281bSPaulo Zanoni static void cpt_set_fifo_underrun_reporting(struct drm_device *dev, 1908664281bSPaulo Zanoni enum transcoder pch_transcoder, 1918664281bSPaulo Zanoni bool enable) 1928664281bSPaulo Zanoni { 1938664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 1948664281bSPaulo Zanoni 1958664281bSPaulo Zanoni if (enable) { 1968664281bSPaulo Zanoni if (!cpt_can_enable_serr_int(dev)) 1978664281bSPaulo Zanoni return; 1988664281bSPaulo Zanoni 1998664281bSPaulo Zanoni I915_WRITE(SERR_INT, SERR_INT_TRANS_A_FIFO_UNDERRUN | 2008664281bSPaulo Zanoni SERR_INT_TRANS_B_FIFO_UNDERRUN | 2018664281bSPaulo Zanoni SERR_INT_TRANS_C_FIFO_UNDERRUN); 2028664281bSPaulo Zanoni 2038664281bSPaulo Zanoni I915_WRITE(SDEIMR, I915_READ(SDEIMR) & ~SDE_ERROR_CPT); 2048664281bSPaulo Zanoni } else { 2058664281bSPaulo Zanoni I915_WRITE(SDEIMR, I915_READ(SDEIMR) | SDE_ERROR_CPT); 2068664281bSPaulo Zanoni } 2078664281bSPaulo Zanoni 2088664281bSPaulo Zanoni POSTING_READ(SDEIMR); 2098664281bSPaulo Zanoni } 2108664281bSPaulo Zanoni 2118664281bSPaulo Zanoni /** 2128664281bSPaulo Zanoni * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages 2138664281bSPaulo Zanoni * @dev: drm device 2148664281bSPaulo Zanoni * @pipe: pipe 2158664281bSPaulo Zanoni * @enable: true if we want to report FIFO underrun errors, false otherwise 2168664281bSPaulo Zanoni * 2178664281bSPaulo Zanoni * This function makes us disable or enable CPU fifo underruns for a specific 2188664281bSPaulo Zanoni * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun 2198664281bSPaulo Zanoni * reporting for one pipe may also disable all the other CPU error interruts for 2208664281bSPaulo Zanoni * the other pipes, due to the fact that there's just one interrupt mask/enable 2218664281bSPaulo Zanoni * bit for all the pipes. 2228664281bSPaulo Zanoni * 2238664281bSPaulo Zanoni * Returns the previous state of underrun reporting. 2248664281bSPaulo Zanoni */ 2258664281bSPaulo Zanoni bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev, 2268664281bSPaulo Zanoni enum pipe pipe, bool enable) 2278664281bSPaulo Zanoni { 2288664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 2298664281bSPaulo Zanoni struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 2308664281bSPaulo Zanoni struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 2318664281bSPaulo Zanoni unsigned long flags; 2328664281bSPaulo Zanoni bool ret; 2338664281bSPaulo Zanoni 2348664281bSPaulo Zanoni spin_lock_irqsave(&dev_priv->irq_lock, flags); 2358664281bSPaulo Zanoni 2368664281bSPaulo Zanoni ret = !intel_crtc->cpu_fifo_underrun_disabled; 2378664281bSPaulo Zanoni 2388664281bSPaulo Zanoni if (enable == ret) 2398664281bSPaulo Zanoni goto done; 2408664281bSPaulo Zanoni 2418664281bSPaulo Zanoni intel_crtc->cpu_fifo_underrun_disabled = !enable; 2428664281bSPaulo Zanoni 2438664281bSPaulo Zanoni if (IS_GEN5(dev) || IS_GEN6(dev)) 2448664281bSPaulo Zanoni ironlake_set_fifo_underrun_reporting(dev, pipe, enable); 2458664281bSPaulo Zanoni else if (IS_GEN7(dev)) 2468664281bSPaulo Zanoni ivybridge_set_fifo_underrun_reporting(dev, enable); 2478664281bSPaulo Zanoni 2488664281bSPaulo Zanoni done: 2498664281bSPaulo Zanoni spin_unlock_irqrestore(&dev_priv->irq_lock, flags); 2508664281bSPaulo Zanoni return ret; 2518664281bSPaulo Zanoni } 2528664281bSPaulo Zanoni 2538664281bSPaulo Zanoni /** 2548664281bSPaulo Zanoni * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages 2558664281bSPaulo Zanoni * @dev: drm device 2568664281bSPaulo Zanoni * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older) 2578664281bSPaulo Zanoni * @enable: true if we want to report FIFO underrun errors, false otherwise 2588664281bSPaulo Zanoni * 2598664281bSPaulo Zanoni * This function makes us disable or enable PCH fifo underruns for a specific 2608664281bSPaulo Zanoni * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO 2618664281bSPaulo Zanoni * underrun reporting for one transcoder may also disable all the other PCH 2628664281bSPaulo Zanoni * error interruts for the other transcoders, due to the fact that there's just 2638664281bSPaulo Zanoni * one interrupt mask/enable bit for all the transcoders. 2648664281bSPaulo Zanoni * 2658664281bSPaulo Zanoni * Returns the previous state of underrun reporting. 2668664281bSPaulo Zanoni */ 2678664281bSPaulo Zanoni bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev, 2688664281bSPaulo Zanoni enum transcoder pch_transcoder, 2698664281bSPaulo Zanoni bool enable) 2708664281bSPaulo Zanoni { 2718664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 2728664281bSPaulo Zanoni enum pipe p; 2738664281bSPaulo Zanoni struct drm_crtc *crtc; 2748664281bSPaulo Zanoni struct intel_crtc *intel_crtc; 2758664281bSPaulo Zanoni unsigned long flags; 2768664281bSPaulo Zanoni bool ret; 2778664281bSPaulo Zanoni 2788664281bSPaulo Zanoni if (HAS_PCH_LPT(dev)) { 2798664281bSPaulo Zanoni crtc = NULL; 2808664281bSPaulo Zanoni for_each_pipe(p) { 2818664281bSPaulo Zanoni struct drm_crtc *c = dev_priv->pipe_to_crtc_mapping[p]; 2828664281bSPaulo Zanoni if (intel_pipe_has_type(c, INTEL_OUTPUT_ANALOG)) { 2838664281bSPaulo Zanoni crtc = c; 2848664281bSPaulo Zanoni break; 2858664281bSPaulo Zanoni } 2868664281bSPaulo Zanoni } 2878664281bSPaulo Zanoni if (!crtc) { 2888664281bSPaulo Zanoni DRM_ERROR("PCH FIFO underrun, but no CRTC using the PCH found\n"); 2898664281bSPaulo Zanoni return false; 2908664281bSPaulo Zanoni } 2918664281bSPaulo Zanoni } else { 2928664281bSPaulo Zanoni crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder]; 2938664281bSPaulo Zanoni } 2948664281bSPaulo Zanoni intel_crtc = to_intel_crtc(crtc); 2958664281bSPaulo Zanoni 2968664281bSPaulo Zanoni spin_lock_irqsave(&dev_priv->irq_lock, flags); 2978664281bSPaulo Zanoni 2988664281bSPaulo Zanoni ret = !intel_crtc->pch_fifo_underrun_disabled; 2998664281bSPaulo Zanoni 3008664281bSPaulo Zanoni if (enable == ret) 3018664281bSPaulo Zanoni goto done; 3028664281bSPaulo Zanoni 3038664281bSPaulo Zanoni intel_crtc->pch_fifo_underrun_disabled = !enable; 3048664281bSPaulo Zanoni 3058664281bSPaulo Zanoni if (HAS_PCH_IBX(dev)) 3068664281bSPaulo Zanoni ibx_set_fifo_underrun_reporting(intel_crtc, enable); 3078664281bSPaulo Zanoni else 3088664281bSPaulo Zanoni cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable); 3098664281bSPaulo Zanoni 3108664281bSPaulo Zanoni done: 3118664281bSPaulo Zanoni spin_unlock_irqrestore(&dev_priv->irq_lock, flags); 3128664281bSPaulo Zanoni return ret; 3138664281bSPaulo Zanoni } 3148664281bSPaulo Zanoni 3158664281bSPaulo Zanoni 3167c463586SKeith Packard void 3177c463586SKeith Packard i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask) 3187c463586SKeith Packard { 3199db4a9c7SJesse Barnes u32 reg = PIPESTAT(pipe); 32046c06a30SVille Syrjälä u32 pipestat = I915_READ(reg) & 0x7fff0000; 3217c463586SKeith Packard 32246c06a30SVille Syrjälä if ((pipestat & mask) == mask) 32346c06a30SVille Syrjälä return; 32446c06a30SVille Syrjälä 3257c463586SKeith Packard /* Enable the interrupt, clear any pending status */ 32646c06a30SVille Syrjälä pipestat |= mask | (mask >> 16); 32746c06a30SVille Syrjälä I915_WRITE(reg, pipestat); 3283143a2bfSChris Wilson POSTING_READ(reg); 3297c463586SKeith Packard } 3307c463586SKeith Packard 3317c463586SKeith Packard void 3327c463586SKeith Packard i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask) 3337c463586SKeith Packard { 3349db4a9c7SJesse Barnes u32 reg = PIPESTAT(pipe); 33546c06a30SVille Syrjälä u32 pipestat = I915_READ(reg) & 0x7fff0000; 3367c463586SKeith Packard 33746c06a30SVille Syrjälä if ((pipestat & mask) == 0) 33846c06a30SVille Syrjälä return; 33946c06a30SVille Syrjälä 34046c06a30SVille Syrjälä pipestat &= ~mask; 34146c06a30SVille Syrjälä I915_WRITE(reg, pipestat); 3423143a2bfSChris Wilson POSTING_READ(reg); 3437c463586SKeith Packard } 3447c463586SKeith Packard 345c0e09200SDave Airlie /** 346f49e38ddSJani Nikula * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion 34701c66889SZhao Yakui */ 348f49e38ddSJani Nikula static void i915_enable_asle_pipestat(struct drm_device *dev) 34901c66889SZhao Yakui { 3501ec14ad3SChris Wilson drm_i915_private_t *dev_priv = dev->dev_private; 3511ec14ad3SChris Wilson unsigned long irqflags; 3521ec14ad3SChris Wilson 353f49e38ddSJani Nikula if (!dev_priv->opregion.asle || !IS_MOBILE(dev)) 354f49e38ddSJani Nikula return; 355f49e38ddSJani Nikula 3561ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 35701c66889SZhao Yakui 358f898780bSJani Nikula i915_enable_pipestat(dev_priv, 1, PIPE_LEGACY_BLC_EVENT_ENABLE); 359a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen >= 4) 360f898780bSJani Nikula i915_enable_pipestat(dev_priv, 0, PIPE_LEGACY_BLC_EVENT_ENABLE); 3611ec14ad3SChris Wilson 3621ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 36301c66889SZhao Yakui } 36401c66889SZhao Yakui 36501c66889SZhao Yakui /** 3660a3e67a4SJesse Barnes * i915_pipe_enabled - check if a pipe is enabled 3670a3e67a4SJesse Barnes * @dev: DRM device 3680a3e67a4SJesse Barnes * @pipe: pipe to check 3690a3e67a4SJesse Barnes * 3700a3e67a4SJesse Barnes * Reading certain registers when the pipe is disabled can hang the chip. 3710a3e67a4SJesse Barnes * Use this routine to make sure the PLL is running and the pipe is active 3720a3e67a4SJesse Barnes * before reading such registers if unsure. 3730a3e67a4SJesse Barnes */ 3740a3e67a4SJesse Barnes static int 3750a3e67a4SJesse Barnes i915_pipe_enabled(struct drm_device *dev, int pipe) 3760a3e67a4SJesse Barnes { 3770a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 378702e7a56SPaulo Zanoni 379a01025afSDaniel Vetter if (drm_core_check_feature(dev, DRIVER_MODESET)) { 380a01025afSDaniel Vetter /* Locking is horribly broken here, but whatever. */ 381a01025afSDaniel Vetter struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 382a01025afSDaniel Vetter struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 38371f8ba6bSPaulo Zanoni 384a01025afSDaniel Vetter return intel_crtc->active; 385a01025afSDaniel Vetter } else { 386a01025afSDaniel Vetter return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE; 387a01025afSDaniel Vetter } 3880a3e67a4SJesse Barnes } 3890a3e67a4SJesse Barnes 39042f52ef8SKeith Packard /* Called from drm generic code, passed a 'crtc', which 39142f52ef8SKeith Packard * we use as a pipe index 39242f52ef8SKeith Packard */ 393f71d4af4SJesse Barnes static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe) 3940a3e67a4SJesse Barnes { 3950a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 3960a3e67a4SJesse Barnes unsigned long high_frame; 3970a3e67a4SJesse Barnes unsigned long low_frame; 3985eddb70bSChris Wilson u32 high1, high2, low; 3990a3e67a4SJesse Barnes 4000a3e67a4SJesse Barnes if (!i915_pipe_enabled(dev, pipe)) { 40144d98a61SZhao Yakui DRM_DEBUG_DRIVER("trying to get vblank count for disabled " 4029db4a9c7SJesse Barnes "pipe %c\n", pipe_name(pipe)); 4030a3e67a4SJesse Barnes return 0; 4040a3e67a4SJesse Barnes } 4050a3e67a4SJesse Barnes 4069db4a9c7SJesse Barnes high_frame = PIPEFRAME(pipe); 4079db4a9c7SJesse Barnes low_frame = PIPEFRAMEPIXEL(pipe); 4085eddb70bSChris Wilson 4090a3e67a4SJesse Barnes /* 4100a3e67a4SJesse Barnes * High & low register fields aren't synchronized, so make sure 4110a3e67a4SJesse Barnes * we get a low value that's stable across two reads of the high 4120a3e67a4SJesse Barnes * register. 4130a3e67a4SJesse Barnes */ 4140a3e67a4SJesse Barnes do { 4155eddb70bSChris Wilson high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; 4165eddb70bSChris Wilson low = I915_READ(low_frame) & PIPE_FRAME_LOW_MASK; 4175eddb70bSChris Wilson high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; 4180a3e67a4SJesse Barnes } while (high1 != high2); 4190a3e67a4SJesse Barnes 4205eddb70bSChris Wilson high1 >>= PIPE_FRAME_HIGH_SHIFT; 4215eddb70bSChris Wilson low >>= PIPE_FRAME_LOW_SHIFT; 4225eddb70bSChris Wilson return (high1 << 8) | low; 4230a3e67a4SJesse Barnes } 4240a3e67a4SJesse Barnes 425f71d4af4SJesse Barnes static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe) 4269880b7a5SJesse Barnes { 4279880b7a5SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 4289db4a9c7SJesse Barnes int reg = PIPE_FRMCOUNT_GM45(pipe); 4299880b7a5SJesse Barnes 4309880b7a5SJesse Barnes if (!i915_pipe_enabled(dev, pipe)) { 43144d98a61SZhao Yakui DRM_DEBUG_DRIVER("trying to get vblank count for disabled " 4329db4a9c7SJesse Barnes "pipe %c\n", pipe_name(pipe)); 4339880b7a5SJesse Barnes return 0; 4349880b7a5SJesse Barnes } 4359880b7a5SJesse Barnes 4369880b7a5SJesse Barnes return I915_READ(reg); 4379880b7a5SJesse Barnes } 4389880b7a5SJesse Barnes 439f71d4af4SJesse Barnes static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe, 4400af7e4dfSMario Kleiner int *vpos, int *hpos) 4410af7e4dfSMario Kleiner { 4420af7e4dfSMario Kleiner drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 4430af7e4dfSMario Kleiner u32 vbl = 0, position = 0; 4440af7e4dfSMario Kleiner int vbl_start, vbl_end, htotal, vtotal; 4450af7e4dfSMario Kleiner bool in_vbl = true; 4460af7e4dfSMario Kleiner int ret = 0; 447fe2b8f9dSPaulo Zanoni enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, 448fe2b8f9dSPaulo Zanoni pipe); 4490af7e4dfSMario Kleiner 4500af7e4dfSMario Kleiner if (!i915_pipe_enabled(dev, pipe)) { 4510af7e4dfSMario Kleiner DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled " 4529db4a9c7SJesse Barnes "pipe %c\n", pipe_name(pipe)); 4530af7e4dfSMario Kleiner return 0; 4540af7e4dfSMario Kleiner } 4550af7e4dfSMario Kleiner 4560af7e4dfSMario Kleiner /* Get vtotal. */ 457fe2b8f9dSPaulo Zanoni vtotal = 1 + ((I915_READ(VTOTAL(cpu_transcoder)) >> 16) & 0x1fff); 4580af7e4dfSMario Kleiner 4590af7e4dfSMario Kleiner if (INTEL_INFO(dev)->gen >= 4) { 4600af7e4dfSMario Kleiner /* No obvious pixelcount register. Only query vertical 4610af7e4dfSMario Kleiner * scanout position from Display scan line register. 4620af7e4dfSMario Kleiner */ 4630af7e4dfSMario Kleiner position = I915_READ(PIPEDSL(pipe)); 4640af7e4dfSMario Kleiner 4650af7e4dfSMario Kleiner /* Decode into vertical scanout position. Don't have 4660af7e4dfSMario Kleiner * horizontal scanout position. 4670af7e4dfSMario Kleiner */ 4680af7e4dfSMario Kleiner *vpos = position & 0x1fff; 4690af7e4dfSMario Kleiner *hpos = 0; 4700af7e4dfSMario Kleiner } else { 4710af7e4dfSMario Kleiner /* Have access to pixelcount since start of frame. 4720af7e4dfSMario Kleiner * We can split this into vertical and horizontal 4730af7e4dfSMario Kleiner * scanout position. 4740af7e4dfSMario Kleiner */ 4750af7e4dfSMario Kleiner position = (I915_READ(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT; 4760af7e4dfSMario Kleiner 477fe2b8f9dSPaulo Zanoni htotal = 1 + ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff); 4780af7e4dfSMario Kleiner *vpos = position / htotal; 4790af7e4dfSMario Kleiner *hpos = position - (*vpos * htotal); 4800af7e4dfSMario Kleiner } 4810af7e4dfSMario Kleiner 4820af7e4dfSMario Kleiner /* Query vblank area. */ 483fe2b8f9dSPaulo Zanoni vbl = I915_READ(VBLANK(cpu_transcoder)); 4840af7e4dfSMario Kleiner 4850af7e4dfSMario Kleiner /* Test position against vblank region. */ 4860af7e4dfSMario Kleiner vbl_start = vbl & 0x1fff; 4870af7e4dfSMario Kleiner vbl_end = (vbl >> 16) & 0x1fff; 4880af7e4dfSMario Kleiner 4890af7e4dfSMario Kleiner if ((*vpos < vbl_start) || (*vpos > vbl_end)) 4900af7e4dfSMario Kleiner in_vbl = false; 4910af7e4dfSMario Kleiner 4920af7e4dfSMario Kleiner /* Inside "upper part" of vblank area? Apply corrective offset: */ 4930af7e4dfSMario Kleiner if (in_vbl && (*vpos >= vbl_start)) 4940af7e4dfSMario Kleiner *vpos = *vpos - vtotal; 4950af7e4dfSMario Kleiner 4960af7e4dfSMario Kleiner /* Readouts valid? */ 4970af7e4dfSMario Kleiner if (vbl > 0) 4980af7e4dfSMario Kleiner ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE; 4990af7e4dfSMario Kleiner 5000af7e4dfSMario Kleiner /* In vblank? */ 5010af7e4dfSMario Kleiner if (in_vbl) 5020af7e4dfSMario Kleiner ret |= DRM_SCANOUTPOS_INVBL; 5030af7e4dfSMario Kleiner 5040af7e4dfSMario Kleiner return ret; 5050af7e4dfSMario Kleiner } 5060af7e4dfSMario Kleiner 507f71d4af4SJesse Barnes static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe, 5080af7e4dfSMario Kleiner int *max_error, 5090af7e4dfSMario Kleiner struct timeval *vblank_time, 5100af7e4dfSMario Kleiner unsigned flags) 5110af7e4dfSMario Kleiner { 5124041b853SChris Wilson struct drm_crtc *crtc; 5130af7e4dfSMario Kleiner 5147eb552aeSBen Widawsky if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) { 5154041b853SChris Wilson DRM_ERROR("Invalid crtc %d\n", pipe); 5160af7e4dfSMario Kleiner return -EINVAL; 5170af7e4dfSMario Kleiner } 5180af7e4dfSMario Kleiner 5190af7e4dfSMario Kleiner /* Get drm_crtc to timestamp: */ 5204041b853SChris Wilson crtc = intel_get_crtc_for_pipe(dev, pipe); 5214041b853SChris Wilson if (crtc == NULL) { 5224041b853SChris Wilson DRM_ERROR("Invalid crtc %d\n", pipe); 5234041b853SChris Wilson return -EINVAL; 5244041b853SChris Wilson } 5254041b853SChris Wilson 5264041b853SChris Wilson if (!crtc->enabled) { 5274041b853SChris Wilson DRM_DEBUG_KMS("crtc %d is disabled\n", pipe); 5284041b853SChris Wilson return -EBUSY; 5294041b853SChris Wilson } 5300af7e4dfSMario Kleiner 5310af7e4dfSMario Kleiner /* Helper routine in DRM core does all the work: */ 5324041b853SChris Wilson return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error, 5334041b853SChris Wilson vblank_time, flags, 5344041b853SChris Wilson crtc); 5350af7e4dfSMario Kleiner } 5360af7e4dfSMario Kleiner 537321a1b30SEgbert Eich static int intel_hpd_irq_event(struct drm_device *dev, struct drm_connector *connector) 538321a1b30SEgbert Eich { 539321a1b30SEgbert Eich enum drm_connector_status old_status; 540321a1b30SEgbert Eich 541321a1b30SEgbert Eich WARN_ON(!mutex_is_locked(&dev->mode_config.mutex)); 542321a1b30SEgbert Eich old_status = connector->status; 543321a1b30SEgbert Eich 544321a1b30SEgbert Eich connector->status = connector->funcs->detect(connector, false); 545321a1b30SEgbert Eich DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %d to %d\n", 546321a1b30SEgbert Eich connector->base.id, 547321a1b30SEgbert Eich drm_get_connector_name(connector), 548321a1b30SEgbert Eich old_status, connector->status); 549321a1b30SEgbert Eich return (old_status != connector->status); 550321a1b30SEgbert Eich } 551321a1b30SEgbert Eich 5525ca58282SJesse Barnes /* 5535ca58282SJesse Barnes * Handle hotplug events outside the interrupt handler proper. 5545ca58282SJesse Barnes */ 555ac4c16c5SEgbert Eich #define I915_REENABLE_HOTPLUG_DELAY (2*60*1000) 556ac4c16c5SEgbert Eich 5575ca58282SJesse Barnes static void i915_hotplug_work_func(struct work_struct *work) 5585ca58282SJesse Barnes { 5595ca58282SJesse Barnes drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, 5605ca58282SJesse Barnes hotplug_work); 5615ca58282SJesse Barnes struct drm_device *dev = dev_priv->dev; 562c31c4ba3SKeith Packard struct drm_mode_config *mode_config = &dev->mode_config; 563cd569aedSEgbert Eich struct intel_connector *intel_connector; 564cd569aedSEgbert Eich struct intel_encoder *intel_encoder; 565cd569aedSEgbert Eich struct drm_connector *connector; 566cd569aedSEgbert Eich unsigned long irqflags; 567cd569aedSEgbert Eich bool hpd_disabled = false; 568321a1b30SEgbert Eich bool changed = false; 569142e2398SEgbert Eich u32 hpd_event_bits; 5705ca58282SJesse Barnes 57152d7ecedSDaniel Vetter /* HPD irq before everything is fully set up. */ 57252d7ecedSDaniel Vetter if (!dev_priv->enable_hotplug_processing) 57352d7ecedSDaniel Vetter return; 57452d7ecedSDaniel Vetter 575a65e34c7SKeith Packard mutex_lock(&mode_config->mutex); 576e67189abSJesse Barnes DRM_DEBUG_KMS("running encoder hotplug functions\n"); 577e67189abSJesse Barnes 578cd569aedSEgbert Eich spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 579142e2398SEgbert Eich 580142e2398SEgbert Eich hpd_event_bits = dev_priv->hpd_event_bits; 581142e2398SEgbert Eich dev_priv->hpd_event_bits = 0; 582cd569aedSEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 583cd569aedSEgbert Eich intel_connector = to_intel_connector(connector); 584cd569aedSEgbert Eich intel_encoder = intel_connector->encoder; 585cd569aedSEgbert Eich if (intel_encoder->hpd_pin > HPD_NONE && 586cd569aedSEgbert Eich dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED && 587cd569aedSEgbert Eich connector->polled == DRM_CONNECTOR_POLL_HPD) { 588cd569aedSEgbert Eich DRM_INFO("HPD interrupt storm detected on connector %s: " 589cd569aedSEgbert Eich "switching from hotplug detection to polling\n", 590cd569aedSEgbert Eich drm_get_connector_name(connector)); 591cd569aedSEgbert Eich dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED; 592cd569aedSEgbert Eich connector->polled = DRM_CONNECTOR_POLL_CONNECT 593cd569aedSEgbert Eich | DRM_CONNECTOR_POLL_DISCONNECT; 594cd569aedSEgbert Eich hpd_disabled = true; 595cd569aedSEgbert Eich } 596142e2398SEgbert Eich if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) { 597142e2398SEgbert Eich DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n", 598142e2398SEgbert Eich drm_get_connector_name(connector), intel_encoder->hpd_pin); 599142e2398SEgbert Eich } 600cd569aedSEgbert Eich } 601cd569aedSEgbert Eich /* if there were no outputs to poll, poll was disabled, 602cd569aedSEgbert Eich * therefore make sure it's enabled when disabling HPD on 603cd569aedSEgbert Eich * some connectors */ 604ac4c16c5SEgbert Eich if (hpd_disabled) { 605cd569aedSEgbert Eich drm_kms_helper_poll_enable(dev); 606ac4c16c5SEgbert Eich mod_timer(&dev_priv->hotplug_reenable_timer, 607ac4c16c5SEgbert Eich jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY)); 608ac4c16c5SEgbert Eich } 609cd569aedSEgbert Eich 610cd569aedSEgbert Eich spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 611cd569aedSEgbert Eich 612321a1b30SEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 613321a1b30SEgbert Eich intel_connector = to_intel_connector(connector); 614321a1b30SEgbert Eich intel_encoder = intel_connector->encoder; 615321a1b30SEgbert Eich if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) { 616cd569aedSEgbert Eich if (intel_encoder->hot_plug) 617cd569aedSEgbert Eich intel_encoder->hot_plug(intel_encoder); 618321a1b30SEgbert Eich if (intel_hpd_irq_event(dev, connector)) 619321a1b30SEgbert Eich changed = true; 620321a1b30SEgbert Eich } 621321a1b30SEgbert Eich } 62240ee3381SKeith Packard mutex_unlock(&mode_config->mutex); 62340ee3381SKeith Packard 624321a1b30SEgbert Eich if (changed) 625321a1b30SEgbert Eich drm_kms_helper_hotplug_event(dev); 6265ca58282SJesse Barnes } 6275ca58282SJesse Barnes 62873edd18fSDaniel Vetter static void ironlake_handle_rps_change(struct drm_device *dev) 629f97108d1SJesse Barnes { 630f97108d1SJesse Barnes drm_i915_private_t *dev_priv = dev->dev_private; 631b5b72e89SMatthew Garrett u32 busy_up, busy_down, max_avg, min_avg; 6329270388eSDaniel Vetter u8 new_delay; 6339270388eSDaniel Vetter unsigned long flags; 6349270388eSDaniel Vetter 6359270388eSDaniel Vetter spin_lock_irqsave(&mchdev_lock, flags); 636f97108d1SJesse Barnes 63773edd18fSDaniel Vetter I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS)); 63873edd18fSDaniel Vetter 63920e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay; 6409270388eSDaniel Vetter 6417648fa99SJesse Barnes I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG); 642b5b72e89SMatthew Garrett busy_up = I915_READ(RCPREVBSYTUPAVG); 643b5b72e89SMatthew Garrett busy_down = I915_READ(RCPREVBSYTDNAVG); 644f97108d1SJesse Barnes max_avg = I915_READ(RCBMAXAVG); 645f97108d1SJesse Barnes min_avg = I915_READ(RCBMINAVG); 646f97108d1SJesse Barnes 647f97108d1SJesse Barnes /* Handle RCS change request from hw */ 648b5b72e89SMatthew Garrett if (busy_up > max_avg) { 64920e4d407SDaniel Vetter if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay) 65020e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay - 1; 65120e4d407SDaniel Vetter if (new_delay < dev_priv->ips.max_delay) 65220e4d407SDaniel Vetter new_delay = dev_priv->ips.max_delay; 653b5b72e89SMatthew Garrett } else if (busy_down < min_avg) { 65420e4d407SDaniel Vetter if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay) 65520e4d407SDaniel Vetter new_delay = dev_priv->ips.cur_delay + 1; 65620e4d407SDaniel Vetter if (new_delay > dev_priv->ips.min_delay) 65720e4d407SDaniel Vetter new_delay = dev_priv->ips.min_delay; 658f97108d1SJesse Barnes } 659f97108d1SJesse Barnes 6607648fa99SJesse Barnes if (ironlake_set_drps(dev, new_delay)) 66120e4d407SDaniel Vetter dev_priv->ips.cur_delay = new_delay; 662f97108d1SJesse Barnes 6639270388eSDaniel Vetter spin_unlock_irqrestore(&mchdev_lock, flags); 6649270388eSDaniel Vetter 665f97108d1SJesse Barnes return; 666f97108d1SJesse Barnes } 667f97108d1SJesse Barnes 668549f7365SChris Wilson static void notify_ring(struct drm_device *dev, 669549f7365SChris Wilson struct intel_ring_buffer *ring) 670549f7365SChris Wilson { 671549f7365SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 6729862e600SChris Wilson 673475553deSChris Wilson if (ring->obj == NULL) 674475553deSChris Wilson return; 675475553deSChris Wilson 676b2eadbc8SChris Wilson trace_i915_gem_request_complete(ring, ring->get_seqno(ring, false)); 6779862e600SChris Wilson 678549f7365SChris Wilson wake_up_all(&ring->irq_queue); 6793e0dc6b0SBen Widawsky if (i915_enable_hangcheck) { 68099584db3SDaniel Vetter mod_timer(&dev_priv->gpu_error.hangcheck_timer, 681cecc21feSChris Wilson round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES)); 6823e0dc6b0SBen Widawsky } 683549f7365SChris Wilson } 684549f7365SChris Wilson 6854912d041SBen Widawsky static void gen6_pm_rps_work(struct work_struct *work) 6863b8d8d91SJesse Barnes { 6874912d041SBen Widawsky drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, 688c6a828d3SDaniel Vetter rps.work); 6894912d041SBen Widawsky u32 pm_iir, pm_imr; 6907b9e0ae6SChris Wilson u8 new_delay; 6913b8d8d91SJesse Barnes 692c6a828d3SDaniel Vetter spin_lock_irq(&dev_priv->rps.lock); 693c6a828d3SDaniel Vetter pm_iir = dev_priv->rps.pm_iir; 694c6a828d3SDaniel Vetter dev_priv->rps.pm_iir = 0; 6954912d041SBen Widawsky pm_imr = I915_READ(GEN6_PMIMR); 6964848405cSBen Widawsky /* Make sure not to corrupt PMIMR state used by ringbuffer code */ 6974848405cSBen Widawsky I915_WRITE(GEN6_PMIMR, pm_imr & ~GEN6_PM_RPS_EVENTS); 698c6a828d3SDaniel Vetter spin_unlock_irq(&dev_priv->rps.lock); 6994912d041SBen Widawsky 7004848405cSBen Widawsky if ((pm_iir & GEN6_PM_RPS_EVENTS) == 0) 7013b8d8d91SJesse Barnes return; 7023b8d8d91SJesse Barnes 7034fc688ceSJesse Barnes mutex_lock(&dev_priv->rps.hw_lock); 7047b9e0ae6SChris Wilson 7057425034aSVille Syrjälä if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) { 706c6a828d3SDaniel Vetter new_delay = dev_priv->rps.cur_delay + 1; 7077425034aSVille Syrjälä 7087425034aSVille Syrjälä /* 7097425034aSVille Syrjälä * For better performance, jump directly 7107425034aSVille Syrjälä * to RPe if we're below it. 7117425034aSVille Syrjälä */ 7127425034aSVille Syrjälä if (IS_VALLEYVIEW(dev_priv->dev) && 7137425034aSVille Syrjälä dev_priv->rps.cur_delay < dev_priv->rps.rpe_delay) 7147425034aSVille Syrjälä new_delay = dev_priv->rps.rpe_delay; 7157425034aSVille Syrjälä } else 716c6a828d3SDaniel Vetter new_delay = dev_priv->rps.cur_delay - 1; 7173b8d8d91SJesse Barnes 71879249636SBen Widawsky /* sysfs frequency interfaces may have snuck in while servicing the 71979249636SBen Widawsky * interrupt 72079249636SBen Widawsky */ 721d8289c9eSVille Syrjälä if (new_delay >= dev_priv->rps.min_delay && 722d8289c9eSVille Syrjälä new_delay <= dev_priv->rps.max_delay) { 7230a073b84SJesse Barnes if (IS_VALLEYVIEW(dev_priv->dev)) 7240a073b84SJesse Barnes valleyview_set_rps(dev_priv->dev, new_delay); 7250a073b84SJesse Barnes else 7264912d041SBen Widawsky gen6_set_rps(dev_priv->dev, new_delay); 72779249636SBen Widawsky } 7283b8d8d91SJesse Barnes 72952ceb908SJesse Barnes if (IS_VALLEYVIEW(dev_priv->dev)) { 73052ceb908SJesse Barnes /* 73152ceb908SJesse Barnes * On VLV, when we enter RC6 we may not be at the minimum 73252ceb908SJesse Barnes * voltage level, so arm a timer to check. It should only 73352ceb908SJesse Barnes * fire when there's activity or once after we've entered 73452ceb908SJesse Barnes * RC6, and then won't be re-armed until the next RPS interrupt. 73552ceb908SJesse Barnes */ 73652ceb908SJesse Barnes mod_delayed_work(dev_priv->wq, &dev_priv->rps.vlv_work, 73752ceb908SJesse Barnes msecs_to_jiffies(100)); 73852ceb908SJesse Barnes } 73952ceb908SJesse Barnes 7404fc688ceSJesse Barnes mutex_unlock(&dev_priv->rps.hw_lock); 7413b8d8d91SJesse Barnes } 7423b8d8d91SJesse Barnes 743e3689190SBen Widawsky 744e3689190SBen Widawsky /** 745e3689190SBen Widawsky * ivybridge_parity_work - Workqueue called when a parity error interrupt 746e3689190SBen Widawsky * occurred. 747e3689190SBen Widawsky * @work: workqueue struct 748e3689190SBen Widawsky * 749e3689190SBen Widawsky * Doesn't actually do anything except notify userspace. As a consequence of 750e3689190SBen Widawsky * this event, userspace should try to remap the bad rows since statistically 751e3689190SBen Widawsky * it is likely the same row is more likely to go bad again. 752e3689190SBen Widawsky */ 753e3689190SBen Widawsky static void ivybridge_parity_work(struct work_struct *work) 754e3689190SBen Widawsky { 755e3689190SBen Widawsky drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, 756a4da4fa4SDaniel Vetter l3_parity.error_work); 757e3689190SBen Widawsky u32 error_status, row, bank, subbank; 758e3689190SBen Widawsky char *parity_event[5]; 759e3689190SBen Widawsky uint32_t misccpctl; 760e3689190SBen Widawsky unsigned long flags; 761e3689190SBen Widawsky 762e3689190SBen Widawsky /* We must turn off DOP level clock gating to access the L3 registers. 763e3689190SBen Widawsky * In order to prevent a get/put style interface, acquire struct mutex 764e3689190SBen Widawsky * any time we access those registers. 765e3689190SBen Widawsky */ 766e3689190SBen Widawsky mutex_lock(&dev_priv->dev->struct_mutex); 767e3689190SBen Widawsky 768e3689190SBen Widawsky misccpctl = I915_READ(GEN7_MISCCPCTL); 769e3689190SBen Widawsky I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); 770e3689190SBen Widawsky POSTING_READ(GEN7_MISCCPCTL); 771e3689190SBen Widawsky 772e3689190SBen Widawsky error_status = I915_READ(GEN7_L3CDERRST1); 773e3689190SBen Widawsky row = GEN7_PARITY_ERROR_ROW(error_status); 774e3689190SBen Widawsky bank = GEN7_PARITY_ERROR_BANK(error_status); 775e3689190SBen Widawsky subbank = GEN7_PARITY_ERROR_SUBBANK(error_status); 776e3689190SBen Widawsky 777e3689190SBen Widawsky I915_WRITE(GEN7_L3CDERRST1, GEN7_PARITY_ERROR_VALID | 778e3689190SBen Widawsky GEN7_L3CDERRST1_ENABLE); 779e3689190SBen Widawsky POSTING_READ(GEN7_L3CDERRST1); 780e3689190SBen Widawsky 781e3689190SBen Widawsky I915_WRITE(GEN7_MISCCPCTL, misccpctl); 782e3689190SBen Widawsky 783e3689190SBen Widawsky spin_lock_irqsave(&dev_priv->irq_lock, flags); 784cc609d5dSBen Widawsky dev_priv->gt_irq_mask &= ~GT_RENDER_L3_PARITY_ERROR_INTERRUPT; 785e3689190SBen Widawsky I915_WRITE(GTIMR, dev_priv->gt_irq_mask); 786e3689190SBen Widawsky spin_unlock_irqrestore(&dev_priv->irq_lock, flags); 787e3689190SBen Widawsky 788e3689190SBen Widawsky mutex_unlock(&dev_priv->dev->struct_mutex); 789e3689190SBen Widawsky 790e3689190SBen Widawsky parity_event[0] = "L3_PARITY_ERROR=1"; 791e3689190SBen Widawsky parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row); 792e3689190SBen Widawsky parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank); 793e3689190SBen Widawsky parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank); 794e3689190SBen Widawsky parity_event[4] = NULL; 795e3689190SBen Widawsky 796e3689190SBen Widawsky kobject_uevent_env(&dev_priv->dev->primary->kdev.kobj, 797e3689190SBen Widawsky KOBJ_CHANGE, parity_event); 798e3689190SBen Widawsky 799e3689190SBen Widawsky DRM_DEBUG("Parity error: Row = %d, Bank = %d, Sub bank = %d.\n", 800e3689190SBen Widawsky row, bank, subbank); 801e3689190SBen Widawsky 802e3689190SBen Widawsky kfree(parity_event[3]); 803e3689190SBen Widawsky kfree(parity_event[2]); 804e3689190SBen Widawsky kfree(parity_event[1]); 805e3689190SBen Widawsky } 806e3689190SBen Widawsky 807d2ba8470SDaniel Vetter static void ivybridge_handle_parity_error(struct drm_device *dev) 808e3689190SBen Widawsky { 809e3689190SBen Widawsky drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 810e3689190SBen Widawsky unsigned long flags; 811e3689190SBen Widawsky 812e1ef7cc2SBen Widawsky if (!HAS_L3_GPU_CACHE(dev)) 813e3689190SBen Widawsky return; 814e3689190SBen Widawsky 815e3689190SBen Widawsky spin_lock_irqsave(&dev_priv->irq_lock, flags); 816cc609d5dSBen Widawsky dev_priv->gt_irq_mask |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT; 817e3689190SBen Widawsky I915_WRITE(GTIMR, dev_priv->gt_irq_mask); 818e3689190SBen Widawsky spin_unlock_irqrestore(&dev_priv->irq_lock, flags); 819e3689190SBen Widawsky 820a4da4fa4SDaniel Vetter queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work); 821e3689190SBen Widawsky } 822e3689190SBen Widawsky 823e7b4c6b1SDaniel Vetter static void snb_gt_irq_handler(struct drm_device *dev, 824e7b4c6b1SDaniel Vetter struct drm_i915_private *dev_priv, 825e7b4c6b1SDaniel Vetter u32 gt_iir) 826e7b4c6b1SDaniel Vetter { 827e7b4c6b1SDaniel Vetter 828cc609d5dSBen Widawsky if (gt_iir & 829cc609d5dSBen Widawsky (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT)) 830e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[RCS]); 831cc609d5dSBen Widawsky if (gt_iir & GT_BSD_USER_INTERRUPT) 832e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[VCS]); 833cc609d5dSBen Widawsky if (gt_iir & GT_BLT_USER_INTERRUPT) 834e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[BCS]); 835e7b4c6b1SDaniel Vetter 836cc609d5dSBen Widawsky if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT | 837cc609d5dSBen Widawsky GT_BSD_CS_ERROR_INTERRUPT | 838cc609d5dSBen Widawsky GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) { 839e7b4c6b1SDaniel Vetter DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir); 840e7b4c6b1SDaniel Vetter i915_handle_error(dev, false); 841e7b4c6b1SDaniel Vetter } 842e3689190SBen Widawsky 843cc609d5dSBen Widawsky if (gt_iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT) 844e3689190SBen Widawsky ivybridge_handle_parity_error(dev); 845e7b4c6b1SDaniel Vetter } 846e7b4c6b1SDaniel Vetter 847baf02a1fSBen Widawsky /* Legacy way of handling PM interrupts */ 848fc6826d1SChris Wilson static void gen6_queue_rps_work(struct drm_i915_private *dev_priv, 849fc6826d1SChris Wilson u32 pm_iir) 850fc6826d1SChris Wilson { 851fc6826d1SChris Wilson unsigned long flags; 852fc6826d1SChris Wilson 853fc6826d1SChris Wilson /* 854fc6826d1SChris Wilson * IIR bits should never already be set because IMR should 855fc6826d1SChris Wilson * prevent an interrupt from being shown in IIR. The warning 856fc6826d1SChris Wilson * displays a case where we've unsafely cleared 857c6a828d3SDaniel Vetter * dev_priv->rps.pm_iir. Although missing an interrupt of the same 858fc6826d1SChris Wilson * type is not a problem, it displays a problem in the logic. 859fc6826d1SChris Wilson * 860c6a828d3SDaniel Vetter * The mask bit in IMR is cleared by dev_priv->rps.work. 861fc6826d1SChris Wilson */ 862fc6826d1SChris Wilson 863c6a828d3SDaniel Vetter spin_lock_irqsave(&dev_priv->rps.lock, flags); 864c6a828d3SDaniel Vetter dev_priv->rps.pm_iir |= pm_iir; 865c6a828d3SDaniel Vetter I915_WRITE(GEN6_PMIMR, dev_priv->rps.pm_iir); 866fc6826d1SChris Wilson POSTING_READ(GEN6_PMIMR); 867c6a828d3SDaniel Vetter spin_unlock_irqrestore(&dev_priv->rps.lock, flags); 868fc6826d1SChris Wilson 869c6a828d3SDaniel Vetter queue_work(dev_priv->wq, &dev_priv->rps.work); 870fc6826d1SChris Wilson } 871fc6826d1SChris Wilson 872b543fb04SEgbert Eich #define HPD_STORM_DETECT_PERIOD 1000 873b543fb04SEgbert Eich #define HPD_STORM_THRESHOLD 5 874b543fb04SEgbert Eich 87510a504deSDaniel Vetter static inline void intel_hpd_irq_handler(struct drm_device *dev, 876b543fb04SEgbert Eich u32 hotplug_trigger, 877b543fb04SEgbert Eich const u32 *hpd) 878b543fb04SEgbert Eich { 879b543fb04SEgbert Eich drm_i915_private_t *dev_priv = dev->dev_private; 880b543fb04SEgbert Eich unsigned long irqflags; 881b543fb04SEgbert Eich int i; 88210a504deSDaniel Vetter bool storm_detected = false; 883b543fb04SEgbert Eich 884b543fb04SEgbert Eich spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 885b543fb04SEgbert Eich 886b543fb04SEgbert Eich for (i = 1; i < HPD_NUM_PINS; i++) { 887821450c6SEgbert Eich 888b543fb04SEgbert Eich if (!(hpd[i] & hotplug_trigger) || 889b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED) 890b543fb04SEgbert Eich continue; 891b543fb04SEgbert Eich 892bc5ead8cSJani Nikula dev_priv->hpd_event_bits |= (1 << i); 893b543fb04SEgbert Eich if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies, 894b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_last_jiffies 895b543fb04SEgbert Eich + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) { 896b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies; 897b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt = 0; 898b543fb04SEgbert Eich } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) { 899b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED; 900142e2398SEgbert Eich dev_priv->hpd_event_bits &= ~(1 << i); 901b543fb04SEgbert Eich DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i); 90210a504deSDaniel Vetter storm_detected = true; 903b543fb04SEgbert Eich } else { 904b543fb04SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt++; 905b543fb04SEgbert Eich } 906b543fb04SEgbert Eich } 907b543fb04SEgbert Eich 908b543fb04SEgbert Eich spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 909cd569aedSEgbert Eich 91010a504deSDaniel Vetter if (storm_detected) 91110a504deSDaniel Vetter dev_priv->display.hpd_irq_setup(dev); 912*5876fa0dSDaniel Vetter 913*5876fa0dSDaniel Vetter queue_work(dev_priv->wq, 914*5876fa0dSDaniel Vetter &dev_priv->hotplug_work); 915b543fb04SEgbert Eich } 916b543fb04SEgbert Eich 917515ac2bbSDaniel Vetter static void gmbus_irq_handler(struct drm_device *dev) 918515ac2bbSDaniel Vetter { 91928c70f16SDaniel Vetter struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private; 92028c70f16SDaniel Vetter 92128c70f16SDaniel Vetter wake_up_all(&dev_priv->gmbus_wait_queue); 922515ac2bbSDaniel Vetter } 923515ac2bbSDaniel Vetter 924ce99c256SDaniel Vetter static void dp_aux_irq_handler(struct drm_device *dev) 925ce99c256SDaniel Vetter { 9269ee32feaSDaniel Vetter struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private; 9279ee32feaSDaniel Vetter 9289ee32feaSDaniel Vetter wake_up_all(&dev_priv->gmbus_wait_queue); 929ce99c256SDaniel Vetter } 930ce99c256SDaniel Vetter 931baf02a1fSBen Widawsky /* Unlike gen6_queue_rps_work() from which this function is originally derived, 932baf02a1fSBen Widawsky * we must be able to deal with other PM interrupts. This is complicated because 933baf02a1fSBen Widawsky * of the way in which we use the masks to defer the RPS work (which for 934baf02a1fSBen Widawsky * posterity is necessary because of forcewake). 935baf02a1fSBen Widawsky */ 936baf02a1fSBen Widawsky static void hsw_pm_irq_handler(struct drm_i915_private *dev_priv, 937baf02a1fSBen Widawsky u32 pm_iir) 938baf02a1fSBen Widawsky { 939baf02a1fSBen Widawsky unsigned long flags; 940baf02a1fSBen Widawsky 941baf02a1fSBen Widawsky spin_lock_irqsave(&dev_priv->rps.lock, flags); 9424848405cSBen Widawsky dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS; 943baf02a1fSBen Widawsky if (dev_priv->rps.pm_iir) { 944baf02a1fSBen Widawsky I915_WRITE(GEN6_PMIMR, dev_priv->rps.pm_iir); 945baf02a1fSBen Widawsky /* never want to mask useful interrupts. (also posting read) */ 9464848405cSBen Widawsky WARN_ON(I915_READ_NOTRACE(GEN6_PMIMR) & ~GEN6_PM_RPS_EVENTS); 947baf02a1fSBen Widawsky /* TODO: if queue_work is slow, move it out of the spinlock */ 948baf02a1fSBen Widawsky queue_work(dev_priv->wq, &dev_priv->rps.work); 949baf02a1fSBen Widawsky } 950baf02a1fSBen Widawsky spin_unlock_irqrestore(&dev_priv->rps.lock, flags); 951baf02a1fSBen Widawsky 95212638c57SBen Widawsky if (pm_iir & ~GEN6_PM_RPS_EVENTS) { 95312638c57SBen Widawsky if (pm_iir & PM_VEBOX_USER_INTERRUPT) 95412638c57SBen Widawsky notify_ring(dev_priv->dev, &dev_priv->ring[VECS]); 95512638c57SBen Widawsky 95612638c57SBen Widawsky if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) { 95712638c57SBen Widawsky DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir); 95812638c57SBen Widawsky i915_handle_error(dev_priv->dev, false); 95912638c57SBen Widawsky } 96012638c57SBen Widawsky } 961baf02a1fSBen Widawsky } 962baf02a1fSBen Widawsky 963ff1f525eSDaniel Vetter static irqreturn_t valleyview_irq_handler(int irq, void *arg) 9647e231dbeSJesse Barnes { 9657e231dbeSJesse Barnes struct drm_device *dev = (struct drm_device *) arg; 9667e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 9677e231dbeSJesse Barnes u32 iir, gt_iir, pm_iir; 9687e231dbeSJesse Barnes irqreturn_t ret = IRQ_NONE; 9697e231dbeSJesse Barnes unsigned long irqflags; 9707e231dbeSJesse Barnes int pipe; 9717e231dbeSJesse Barnes u32 pipe_stats[I915_MAX_PIPES]; 9727e231dbeSJesse Barnes 9737e231dbeSJesse Barnes atomic_inc(&dev_priv->irq_received); 9747e231dbeSJesse Barnes 9757e231dbeSJesse Barnes while (true) { 9767e231dbeSJesse Barnes iir = I915_READ(VLV_IIR); 9777e231dbeSJesse Barnes gt_iir = I915_READ(GTIIR); 9787e231dbeSJesse Barnes pm_iir = I915_READ(GEN6_PMIIR); 9797e231dbeSJesse Barnes 9807e231dbeSJesse Barnes if (gt_iir == 0 && pm_iir == 0 && iir == 0) 9817e231dbeSJesse Barnes goto out; 9827e231dbeSJesse Barnes 9837e231dbeSJesse Barnes ret = IRQ_HANDLED; 9847e231dbeSJesse Barnes 985e7b4c6b1SDaniel Vetter snb_gt_irq_handler(dev, dev_priv, gt_iir); 9867e231dbeSJesse Barnes 9877e231dbeSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 9887e231dbeSJesse Barnes for_each_pipe(pipe) { 9897e231dbeSJesse Barnes int reg = PIPESTAT(pipe); 9907e231dbeSJesse Barnes pipe_stats[pipe] = I915_READ(reg); 9917e231dbeSJesse Barnes 9927e231dbeSJesse Barnes /* 9937e231dbeSJesse Barnes * Clear the PIPE*STAT regs before the IIR 9947e231dbeSJesse Barnes */ 9957e231dbeSJesse Barnes if (pipe_stats[pipe] & 0x8000ffff) { 9967e231dbeSJesse Barnes if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 9977e231dbeSJesse Barnes DRM_DEBUG_DRIVER("pipe %c underrun\n", 9987e231dbeSJesse Barnes pipe_name(pipe)); 9997e231dbeSJesse Barnes I915_WRITE(reg, pipe_stats[pipe]); 10007e231dbeSJesse Barnes } 10017e231dbeSJesse Barnes } 10027e231dbeSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 10037e231dbeSJesse Barnes 100431acc7f5SJesse Barnes for_each_pipe(pipe) { 100531acc7f5SJesse Barnes if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS) 100631acc7f5SJesse Barnes drm_handle_vblank(dev, pipe); 100731acc7f5SJesse Barnes 100831acc7f5SJesse Barnes if (pipe_stats[pipe] & PLANE_FLIPDONE_INT_STATUS_VLV) { 100931acc7f5SJesse Barnes intel_prepare_page_flip(dev, pipe); 101031acc7f5SJesse Barnes intel_finish_page_flip(dev, pipe); 101131acc7f5SJesse Barnes } 101231acc7f5SJesse Barnes } 101331acc7f5SJesse Barnes 10147e231dbeSJesse Barnes /* Consume port. Then clear IIR or we'll miss events */ 10157e231dbeSJesse Barnes if (iir & I915_DISPLAY_PORT_INTERRUPT) { 10167e231dbeSJesse Barnes u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); 1017b543fb04SEgbert Eich u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915; 10187e231dbeSJesse Barnes 10197e231dbeSJesse Barnes DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n", 10207e231dbeSJesse Barnes hotplug_status); 1021b543fb04SEgbert Eich if (hotplug_trigger) { 102210a504deSDaniel Vetter intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915); 1023b543fb04SEgbert Eich } 10247e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); 10257e231dbeSJesse Barnes I915_READ(PORT_HOTPLUG_STAT); 10267e231dbeSJesse Barnes } 10277e231dbeSJesse Barnes 1028515ac2bbSDaniel Vetter if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 1029515ac2bbSDaniel Vetter gmbus_irq_handler(dev); 10307e231dbeSJesse Barnes 10314848405cSBen Widawsky if (pm_iir & GEN6_PM_RPS_EVENTS) 1032fc6826d1SChris Wilson gen6_queue_rps_work(dev_priv, pm_iir); 10337e231dbeSJesse Barnes 10347e231dbeSJesse Barnes I915_WRITE(GTIIR, gt_iir); 10357e231dbeSJesse Barnes I915_WRITE(GEN6_PMIIR, pm_iir); 10367e231dbeSJesse Barnes I915_WRITE(VLV_IIR, iir); 10377e231dbeSJesse Barnes } 10387e231dbeSJesse Barnes 10397e231dbeSJesse Barnes out: 10407e231dbeSJesse Barnes return ret; 10417e231dbeSJesse Barnes } 10427e231dbeSJesse Barnes 104323e81d69SAdam Jackson static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir) 1044776ad806SJesse Barnes { 1045776ad806SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 10469db4a9c7SJesse Barnes int pipe; 1047b543fb04SEgbert Eich u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK; 1048776ad806SJesse Barnes 1049b543fb04SEgbert Eich if (hotplug_trigger) { 105010a504deSDaniel Vetter intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx); 1051b543fb04SEgbert Eich } 1052cfc33bf7SVille Syrjälä if (pch_iir & SDE_AUDIO_POWER_MASK) { 1053cfc33bf7SVille Syrjälä int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >> 1054776ad806SJesse Barnes SDE_AUDIO_POWER_SHIFT); 1055cfc33bf7SVille Syrjälä DRM_DEBUG_DRIVER("PCH audio power change on port %d\n", 1056cfc33bf7SVille Syrjälä port_name(port)); 1057cfc33bf7SVille Syrjälä } 1058776ad806SJesse Barnes 1059ce99c256SDaniel Vetter if (pch_iir & SDE_AUX_MASK) 1060ce99c256SDaniel Vetter dp_aux_irq_handler(dev); 1061ce99c256SDaniel Vetter 1062776ad806SJesse Barnes if (pch_iir & SDE_GMBUS) 1063515ac2bbSDaniel Vetter gmbus_irq_handler(dev); 1064776ad806SJesse Barnes 1065776ad806SJesse Barnes if (pch_iir & SDE_AUDIO_HDCP_MASK) 1066776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n"); 1067776ad806SJesse Barnes 1068776ad806SJesse Barnes if (pch_iir & SDE_AUDIO_TRANS_MASK) 1069776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n"); 1070776ad806SJesse Barnes 1071776ad806SJesse Barnes if (pch_iir & SDE_POISON) 1072776ad806SJesse Barnes DRM_ERROR("PCH poison interrupt\n"); 1073776ad806SJesse Barnes 10749db4a9c7SJesse Barnes if (pch_iir & SDE_FDI_MASK) 10759db4a9c7SJesse Barnes for_each_pipe(pipe) 10769db4a9c7SJesse Barnes DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", 10779db4a9c7SJesse Barnes pipe_name(pipe), 10789db4a9c7SJesse Barnes I915_READ(FDI_RX_IIR(pipe))); 1079776ad806SJesse Barnes 1080776ad806SJesse Barnes if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE)) 1081776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n"); 1082776ad806SJesse Barnes 1083776ad806SJesse Barnes if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR)) 1084776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n"); 1085776ad806SJesse Barnes 1086776ad806SJesse Barnes if (pch_iir & SDE_TRANSA_FIFO_UNDER) 10878664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, 10888664281bSPaulo Zanoni false)) 10898664281bSPaulo Zanoni DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n"); 10908664281bSPaulo Zanoni 10918664281bSPaulo Zanoni if (pch_iir & SDE_TRANSB_FIFO_UNDER) 10928664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B, 10938664281bSPaulo Zanoni false)) 10948664281bSPaulo Zanoni DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n"); 10958664281bSPaulo Zanoni } 10968664281bSPaulo Zanoni 10978664281bSPaulo Zanoni static void ivb_err_int_handler(struct drm_device *dev) 10988664281bSPaulo Zanoni { 10998664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 11008664281bSPaulo Zanoni u32 err_int = I915_READ(GEN7_ERR_INT); 11018664281bSPaulo Zanoni 1102de032bf4SPaulo Zanoni if (err_int & ERR_INT_POISON) 1103de032bf4SPaulo Zanoni DRM_ERROR("Poison interrupt\n"); 1104de032bf4SPaulo Zanoni 11058664281bSPaulo Zanoni if (err_int & ERR_INT_FIFO_UNDERRUN_A) 11068664281bSPaulo Zanoni if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false)) 11078664281bSPaulo Zanoni DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n"); 11088664281bSPaulo Zanoni 11098664281bSPaulo Zanoni if (err_int & ERR_INT_FIFO_UNDERRUN_B) 11108664281bSPaulo Zanoni if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false)) 11118664281bSPaulo Zanoni DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n"); 11128664281bSPaulo Zanoni 11138664281bSPaulo Zanoni if (err_int & ERR_INT_FIFO_UNDERRUN_C) 11148664281bSPaulo Zanoni if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_C, false)) 11158664281bSPaulo Zanoni DRM_DEBUG_DRIVER("Pipe C FIFO underrun\n"); 11168664281bSPaulo Zanoni 11178664281bSPaulo Zanoni I915_WRITE(GEN7_ERR_INT, err_int); 11188664281bSPaulo Zanoni } 11198664281bSPaulo Zanoni 11208664281bSPaulo Zanoni static void cpt_serr_int_handler(struct drm_device *dev) 11218664281bSPaulo Zanoni { 11228664281bSPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 11238664281bSPaulo Zanoni u32 serr_int = I915_READ(SERR_INT); 11248664281bSPaulo Zanoni 1125de032bf4SPaulo Zanoni if (serr_int & SERR_INT_POISON) 1126de032bf4SPaulo Zanoni DRM_ERROR("PCH poison interrupt\n"); 1127de032bf4SPaulo Zanoni 11288664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN) 11298664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, 11308664281bSPaulo Zanoni false)) 11318664281bSPaulo Zanoni DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n"); 11328664281bSPaulo Zanoni 11338664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN) 11348664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B, 11358664281bSPaulo Zanoni false)) 11368664281bSPaulo Zanoni DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n"); 11378664281bSPaulo Zanoni 11388664281bSPaulo Zanoni if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN) 11398664281bSPaulo Zanoni if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C, 11408664281bSPaulo Zanoni false)) 11418664281bSPaulo Zanoni DRM_DEBUG_DRIVER("PCH transcoder C FIFO underrun\n"); 11428664281bSPaulo Zanoni 11438664281bSPaulo Zanoni I915_WRITE(SERR_INT, serr_int); 1144776ad806SJesse Barnes } 1145776ad806SJesse Barnes 114623e81d69SAdam Jackson static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir) 114723e81d69SAdam Jackson { 114823e81d69SAdam Jackson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 114923e81d69SAdam Jackson int pipe; 1150b543fb04SEgbert Eich u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT; 115123e81d69SAdam Jackson 1152b543fb04SEgbert Eich if (hotplug_trigger) { 115310a504deSDaniel Vetter intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt); 1154b543fb04SEgbert Eich } 1155cfc33bf7SVille Syrjälä if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) { 1156cfc33bf7SVille Syrjälä int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >> 115723e81d69SAdam Jackson SDE_AUDIO_POWER_SHIFT_CPT); 1158cfc33bf7SVille Syrjälä DRM_DEBUG_DRIVER("PCH audio power change on port %c\n", 1159cfc33bf7SVille Syrjälä port_name(port)); 1160cfc33bf7SVille Syrjälä } 116123e81d69SAdam Jackson 116223e81d69SAdam Jackson if (pch_iir & SDE_AUX_MASK_CPT) 1163ce99c256SDaniel Vetter dp_aux_irq_handler(dev); 116423e81d69SAdam Jackson 116523e81d69SAdam Jackson if (pch_iir & SDE_GMBUS_CPT) 1166515ac2bbSDaniel Vetter gmbus_irq_handler(dev); 116723e81d69SAdam Jackson 116823e81d69SAdam Jackson if (pch_iir & SDE_AUDIO_CP_REQ_CPT) 116923e81d69SAdam Jackson DRM_DEBUG_DRIVER("Audio CP request interrupt\n"); 117023e81d69SAdam Jackson 117123e81d69SAdam Jackson if (pch_iir & SDE_AUDIO_CP_CHG_CPT) 117223e81d69SAdam Jackson DRM_DEBUG_DRIVER("Audio CP change interrupt\n"); 117323e81d69SAdam Jackson 117423e81d69SAdam Jackson if (pch_iir & SDE_FDI_MASK_CPT) 117523e81d69SAdam Jackson for_each_pipe(pipe) 117623e81d69SAdam Jackson DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", 117723e81d69SAdam Jackson pipe_name(pipe), 117823e81d69SAdam Jackson I915_READ(FDI_RX_IIR(pipe))); 11798664281bSPaulo Zanoni 11808664281bSPaulo Zanoni if (pch_iir & SDE_ERROR_CPT) 11818664281bSPaulo Zanoni cpt_serr_int_handler(dev); 118223e81d69SAdam Jackson } 118323e81d69SAdam Jackson 1184ff1f525eSDaniel Vetter static irqreturn_t ivybridge_irq_handler(int irq, void *arg) 1185b1f14ad0SJesse Barnes { 1186b1f14ad0SJesse Barnes struct drm_device *dev = (struct drm_device *) arg; 1187b1f14ad0SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1188ab5c608bSBen Widawsky u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier = 0; 11890e43406bSChris Wilson irqreturn_t ret = IRQ_NONE; 11900e43406bSChris Wilson int i; 1191b1f14ad0SJesse Barnes 1192b1f14ad0SJesse Barnes atomic_inc(&dev_priv->irq_received); 1193b1f14ad0SJesse Barnes 11948664281bSPaulo Zanoni /* We get interrupts on unclaimed registers, so check for this before we 11958664281bSPaulo Zanoni * do any I915_{READ,WRITE}. */ 11968664281bSPaulo Zanoni if (IS_HASWELL(dev) && 11978664281bSPaulo Zanoni (I915_READ_NOTRACE(FPGA_DBG) & FPGA_DBG_RM_NOCLAIM)) { 11988664281bSPaulo Zanoni DRM_ERROR("Unclaimed register before interrupt\n"); 11998664281bSPaulo Zanoni I915_WRITE_NOTRACE(FPGA_DBG, FPGA_DBG_RM_NOCLAIM); 12008664281bSPaulo Zanoni } 12018664281bSPaulo Zanoni 1202b1f14ad0SJesse Barnes /* disable master interrupt before clearing iir */ 1203b1f14ad0SJesse Barnes de_ier = I915_READ(DEIER); 1204b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL); 12050e43406bSChris Wilson 120644498aeaSPaulo Zanoni /* Disable south interrupts. We'll only write to SDEIIR once, so further 120744498aeaSPaulo Zanoni * interrupts will will be stored on its back queue, and then we'll be 120844498aeaSPaulo Zanoni * able to process them after we restore SDEIER (as soon as we restore 120944498aeaSPaulo Zanoni * it, we'll get an interrupt if SDEIIR still has something to process 121044498aeaSPaulo Zanoni * due to its back queue). */ 1211ab5c608bSBen Widawsky if (!HAS_PCH_NOP(dev)) { 121244498aeaSPaulo Zanoni sde_ier = I915_READ(SDEIER); 121344498aeaSPaulo Zanoni I915_WRITE(SDEIER, 0); 121444498aeaSPaulo Zanoni POSTING_READ(SDEIER); 1215ab5c608bSBen Widawsky } 121644498aeaSPaulo Zanoni 12178664281bSPaulo Zanoni /* On Haswell, also mask ERR_INT because we don't want to risk 12188664281bSPaulo Zanoni * generating "unclaimed register" interrupts from inside the interrupt 12198664281bSPaulo Zanoni * handler. */ 12204bc9d430SDaniel Vetter if (IS_HASWELL(dev)) { 12214bc9d430SDaniel Vetter spin_lock(&dev_priv->irq_lock); 12228664281bSPaulo Zanoni ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB); 12234bc9d430SDaniel Vetter spin_unlock(&dev_priv->irq_lock); 12244bc9d430SDaniel Vetter } 12258664281bSPaulo Zanoni 12260e43406bSChris Wilson gt_iir = I915_READ(GTIIR); 12270e43406bSChris Wilson if (gt_iir) { 12280e43406bSChris Wilson snb_gt_irq_handler(dev, dev_priv, gt_iir); 12290e43406bSChris Wilson I915_WRITE(GTIIR, gt_iir); 12300e43406bSChris Wilson ret = IRQ_HANDLED; 12310e43406bSChris Wilson } 1232b1f14ad0SJesse Barnes 1233b1f14ad0SJesse Barnes de_iir = I915_READ(DEIIR); 12340e43406bSChris Wilson if (de_iir) { 12358664281bSPaulo Zanoni if (de_iir & DE_ERR_INT_IVB) 12368664281bSPaulo Zanoni ivb_err_int_handler(dev); 12378664281bSPaulo Zanoni 1238ce99c256SDaniel Vetter if (de_iir & DE_AUX_CHANNEL_A_IVB) 1239ce99c256SDaniel Vetter dp_aux_irq_handler(dev); 1240ce99c256SDaniel Vetter 1241b1f14ad0SJesse Barnes if (de_iir & DE_GSE_IVB) 124281a07809SJani Nikula intel_opregion_asle_intr(dev); 1243b1f14ad0SJesse Barnes 12440e43406bSChris Wilson for (i = 0; i < 3; i++) { 124574d44445SDaniel Vetter if (de_iir & (DE_PIPEA_VBLANK_IVB << (5 * i))) 124674d44445SDaniel Vetter drm_handle_vblank(dev, i); 12470e43406bSChris Wilson if (de_iir & (DE_PLANEA_FLIP_DONE_IVB << (5 * i))) { 12480e43406bSChris Wilson intel_prepare_page_flip(dev, i); 12490e43406bSChris Wilson intel_finish_page_flip_plane(dev, i); 1250b1f14ad0SJesse Barnes } 1251b1f14ad0SJesse Barnes } 1252b1f14ad0SJesse Barnes 1253b1f14ad0SJesse Barnes /* check event from PCH */ 1254ab5c608bSBen Widawsky if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) { 12550e43406bSChris Wilson u32 pch_iir = I915_READ(SDEIIR); 12560e43406bSChris Wilson 125723e81d69SAdam Jackson cpt_irq_handler(dev, pch_iir); 12580e43406bSChris Wilson 12590e43406bSChris Wilson /* clear PCH hotplug event before clear CPU irq */ 12600e43406bSChris Wilson I915_WRITE(SDEIIR, pch_iir); 1261b1f14ad0SJesse Barnes } 1262b1f14ad0SJesse Barnes 12630e43406bSChris Wilson I915_WRITE(DEIIR, de_iir); 12640e43406bSChris Wilson ret = IRQ_HANDLED; 12650e43406bSChris Wilson } 12660e43406bSChris Wilson 12670e43406bSChris Wilson pm_iir = I915_READ(GEN6_PMIIR); 12680e43406bSChris Wilson if (pm_iir) { 1269baf02a1fSBen Widawsky if (IS_HASWELL(dev)) 1270baf02a1fSBen Widawsky hsw_pm_irq_handler(dev_priv, pm_iir); 12714848405cSBen Widawsky else if (pm_iir & GEN6_PM_RPS_EVENTS) 1272fc6826d1SChris Wilson gen6_queue_rps_work(dev_priv, pm_iir); 1273b1f14ad0SJesse Barnes I915_WRITE(GEN6_PMIIR, pm_iir); 12740e43406bSChris Wilson ret = IRQ_HANDLED; 12750e43406bSChris Wilson } 1276b1f14ad0SJesse Barnes 12774bc9d430SDaniel Vetter if (IS_HASWELL(dev)) { 12784bc9d430SDaniel Vetter spin_lock(&dev_priv->irq_lock); 12794bc9d430SDaniel Vetter if (ivb_can_enable_err_int(dev)) 12808664281bSPaulo Zanoni ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB); 12814bc9d430SDaniel Vetter spin_unlock(&dev_priv->irq_lock); 12824bc9d430SDaniel Vetter } 12838664281bSPaulo Zanoni 1284b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier); 1285b1f14ad0SJesse Barnes POSTING_READ(DEIER); 1286ab5c608bSBen Widawsky if (!HAS_PCH_NOP(dev)) { 128744498aeaSPaulo Zanoni I915_WRITE(SDEIER, sde_ier); 128844498aeaSPaulo Zanoni POSTING_READ(SDEIER); 1289ab5c608bSBen Widawsky } 1290b1f14ad0SJesse Barnes 1291b1f14ad0SJesse Barnes return ret; 1292b1f14ad0SJesse Barnes } 1293b1f14ad0SJesse Barnes 1294e7b4c6b1SDaniel Vetter static void ilk_gt_irq_handler(struct drm_device *dev, 1295e7b4c6b1SDaniel Vetter struct drm_i915_private *dev_priv, 1296e7b4c6b1SDaniel Vetter u32 gt_iir) 1297e7b4c6b1SDaniel Vetter { 1298cc609d5dSBen Widawsky if (gt_iir & 1299cc609d5dSBen Widawsky (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT)) 1300e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[RCS]); 1301cc609d5dSBen Widawsky if (gt_iir & ILK_BSD_USER_INTERRUPT) 1302e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[VCS]); 1303e7b4c6b1SDaniel Vetter } 1304e7b4c6b1SDaniel Vetter 1305ff1f525eSDaniel Vetter static irqreturn_t ironlake_irq_handler(int irq, void *arg) 1306036a4a7dSZhenyu Wang { 13074697995bSJesse Barnes struct drm_device *dev = (struct drm_device *) arg; 1308036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1309036a4a7dSZhenyu Wang int ret = IRQ_NONE; 131044498aeaSPaulo Zanoni u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier; 1311881f47b6SXiang, Haihao 13124697995bSJesse Barnes atomic_inc(&dev_priv->irq_received); 13134697995bSJesse Barnes 13142d109a84SZou, Nanhai /* disable master interrupt before clearing iir */ 13152d109a84SZou, Nanhai de_ier = I915_READ(DEIER); 13162d109a84SZou, Nanhai I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL); 13173143a2bfSChris Wilson POSTING_READ(DEIER); 13182d109a84SZou, Nanhai 131944498aeaSPaulo Zanoni /* Disable south interrupts. We'll only write to SDEIIR once, so further 132044498aeaSPaulo Zanoni * interrupts will will be stored on its back queue, and then we'll be 132144498aeaSPaulo Zanoni * able to process them after we restore SDEIER (as soon as we restore 132244498aeaSPaulo Zanoni * it, we'll get an interrupt if SDEIIR still has something to process 132344498aeaSPaulo Zanoni * due to its back queue). */ 132444498aeaSPaulo Zanoni sde_ier = I915_READ(SDEIER); 132544498aeaSPaulo Zanoni I915_WRITE(SDEIER, 0); 132644498aeaSPaulo Zanoni POSTING_READ(SDEIER); 132744498aeaSPaulo Zanoni 1328036a4a7dSZhenyu Wang de_iir = I915_READ(DEIIR); 1329036a4a7dSZhenyu Wang gt_iir = I915_READ(GTIIR); 13303b8d8d91SJesse Barnes pm_iir = I915_READ(GEN6_PMIIR); 1331036a4a7dSZhenyu Wang 1332acd15b6cSDaniel Vetter if (de_iir == 0 && gt_iir == 0 && (!IS_GEN6(dev) || pm_iir == 0)) 1333c7c85101SZou Nan hai goto done; 1334036a4a7dSZhenyu Wang 1335036a4a7dSZhenyu Wang ret = IRQ_HANDLED; 1336036a4a7dSZhenyu Wang 1337e7b4c6b1SDaniel Vetter if (IS_GEN5(dev)) 1338e7b4c6b1SDaniel Vetter ilk_gt_irq_handler(dev, dev_priv, gt_iir); 1339e7b4c6b1SDaniel Vetter else 1340e7b4c6b1SDaniel Vetter snb_gt_irq_handler(dev, dev_priv, gt_iir); 1341036a4a7dSZhenyu Wang 1342ce99c256SDaniel Vetter if (de_iir & DE_AUX_CHANNEL_A) 1343ce99c256SDaniel Vetter dp_aux_irq_handler(dev); 1344ce99c256SDaniel Vetter 134501c66889SZhao Yakui if (de_iir & DE_GSE) 134681a07809SJani Nikula intel_opregion_asle_intr(dev); 134701c66889SZhao Yakui 134874d44445SDaniel Vetter if (de_iir & DE_PIPEA_VBLANK) 134974d44445SDaniel Vetter drm_handle_vblank(dev, 0); 135074d44445SDaniel Vetter 135174d44445SDaniel Vetter if (de_iir & DE_PIPEB_VBLANK) 135274d44445SDaniel Vetter drm_handle_vblank(dev, 1); 135374d44445SDaniel Vetter 1354de032bf4SPaulo Zanoni if (de_iir & DE_POISON) 1355de032bf4SPaulo Zanoni DRM_ERROR("Poison interrupt\n"); 1356de032bf4SPaulo Zanoni 13578664281bSPaulo Zanoni if (de_iir & DE_PIPEA_FIFO_UNDERRUN) 13588664281bSPaulo Zanoni if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false)) 13598664281bSPaulo Zanoni DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n"); 13608664281bSPaulo Zanoni 13618664281bSPaulo Zanoni if (de_iir & DE_PIPEB_FIFO_UNDERRUN) 13628664281bSPaulo Zanoni if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false)) 13638664281bSPaulo Zanoni DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n"); 13648664281bSPaulo Zanoni 1365f072d2e7SZhenyu Wang if (de_iir & DE_PLANEA_FLIP_DONE) { 1366013d5aa2SJesse Barnes intel_prepare_page_flip(dev, 0); 13672bbda389SChris Wilson intel_finish_page_flip_plane(dev, 0); 1368013d5aa2SJesse Barnes } 1369013d5aa2SJesse Barnes 1370f072d2e7SZhenyu Wang if (de_iir & DE_PLANEB_FLIP_DONE) { 1371f072d2e7SZhenyu Wang intel_prepare_page_flip(dev, 1); 13722bbda389SChris Wilson intel_finish_page_flip_plane(dev, 1); 1373013d5aa2SJesse Barnes } 1374c062df61SLi Peng 1375c650156aSZhenyu Wang /* check event from PCH */ 1376776ad806SJesse Barnes if (de_iir & DE_PCH_EVENT) { 1377acd15b6cSDaniel Vetter u32 pch_iir = I915_READ(SDEIIR); 1378acd15b6cSDaniel Vetter 137923e81d69SAdam Jackson if (HAS_PCH_CPT(dev)) 138023e81d69SAdam Jackson cpt_irq_handler(dev, pch_iir); 138123e81d69SAdam Jackson else 138223e81d69SAdam Jackson ibx_irq_handler(dev, pch_iir); 1383acd15b6cSDaniel Vetter 1384acd15b6cSDaniel Vetter /* should clear PCH hotplug event before clear CPU irq */ 1385acd15b6cSDaniel Vetter I915_WRITE(SDEIIR, pch_iir); 1386776ad806SJesse Barnes } 1387c650156aSZhenyu Wang 138873edd18fSDaniel Vetter if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT) 138973edd18fSDaniel Vetter ironlake_handle_rps_change(dev); 1390f97108d1SJesse Barnes 13914848405cSBen Widawsky if (IS_GEN6(dev) && pm_iir & GEN6_PM_RPS_EVENTS) 1392fc6826d1SChris Wilson gen6_queue_rps_work(dev_priv, pm_iir); 13933b8d8d91SJesse Barnes 1394c7c85101SZou Nan hai I915_WRITE(GTIIR, gt_iir); 1395c7c85101SZou Nan hai I915_WRITE(DEIIR, de_iir); 13964912d041SBen Widawsky I915_WRITE(GEN6_PMIIR, pm_iir); 1397036a4a7dSZhenyu Wang 1398c7c85101SZou Nan hai done: 13992d109a84SZou, Nanhai I915_WRITE(DEIER, de_ier); 14003143a2bfSChris Wilson POSTING_READ(DEIER); 140144498aeaSPaulo Zanoni I915_WRITE(SDEIER, sde_ier); 140244498aeaSPaulo Zanoni POSTING_READ(SDEIER); 14032d109a84SZou, Nanhai 1404036a4a7dSZhenyu Wang return ret; 1405036a4a7dSZhenyu Wang } 1406036a4a7dSZhenyu Wang 14078a905236SJesse Barnes /** 14088a905236SJesse Barnes * i915_error_work_func - do process context error handling work 14098a905236SJesse Barnes * @work: work struct 14108a905236SJesse Barnes * 14118a905236SJesse Barnes * Fire an error uevent so userspace can see that a hang or error 14128a905236SJesse Barnes * was detected. 14138a905236SJesse Barnes */ 14148a905236SJesse Barnes static void i915_error_work_func(struct work_struct *work) 14158a905236SJesse Barnes { 14161f83fee0SDaniel Vetter struct i915_gpu_error *error = container_of(work, struct i915_gpu_error, 14171f83fee0SDaniel Vetter work); 14181f83fee0SDaniel Vetter drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t, 14191f83fee0SDaniel Vetter gpu_error); 14208a905236SJesse Barnes struct drm_device *dev = dev_priv->dev; 1421f69061beSDaniel Vetter struct intel_ring_buffer *ring; 1422f316a42cSBen Gamari char *error_event[] = { "ERROR=1", NULL }; 1423f316a42cSBen Gamari char *reset_event[] = { "RESET=1", NULL }; 1424f316a42cSBen Gamari char *reset_done_event[] = { "ERROR=0", NULL }; 1425f69061beSDaniel Vetter int i, ret; 14268a905236SJesse Barnes 1427f316a42cSBen Gamari kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event); 14288a905236SJesse Barnes 14297db0ba24SDaniel Vetter /* 14307db0ba24SDaniel Vetter * Note that there's only one work item which does gpu resets, so we 14317db0ba24SDaniel Vetter * need not worry about concurrent gpu resets potentially incrementing 14327db0ba24SDaniel Vetter * error->reset_counter twice. We only need to take care of another 14337db0ba24SDaniel Vetter * racing irq/hangcheck declaring the gpu dead for a second time. A 14347db0ba24SDaniel Vetter * quick check for that is good enough: schedule_work ensures the 14357db0ba24SDaniel Vetter * correct ordering between hang detection and this work item, and since 14367db0ba24SDaniel Vetter * the reset in-progress bit is only ever set by code outside of this 14377db0ba24SDaniel Vetter * work we don't need to worry about any other races. 14387db0ba24SDaniel Vetter */ 14397db0ba24SDaniel Vetter if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) { 144044d98a61SZhao Yakui DRM_DEBUG_DRIVER("resetting chip\n"); 14417db0ba24SDaniel Vetter kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, 14427db0ba24SDaniel Vetter reset_event); 14431f83fee0SDaniel Vetter 1444f69061beSDaniel Vetter ret = i915_reset(dev); 1445f69061beSDaniel Vetter 1446f69061beSDaniel Vetter if (ret == 0) { 1447f69061beSDaniel Vetter /* 1448f69061beSDaniel Vetter * After all the gem state is reset, increment the reset 1449f69061beSDaniel Vetter * counter and wake up everyone waiting for the reset to 1450f69061beSDaniel Vetter * complete. 1451f69061beSDaniel Vetter * 1452f69061beSDaniel Vetter * Since unlock operations are a one-sided barrier only, 1453f69061beSDaniel Vetter * we need to insert a barrier here to order any seqno 1454f69061beSDaniel Vetter * updates before 1455f69061beSDaniel Vetter * the counter increment. 1456f69061beSDaniel Vetter */ 1457f69061beSDaniel Vetter smp_mb__before_atomic_inc(); 1458f69061beSDaniel Vetter atomic_inc(&dev_priv->gpu_error.reset_counter); 1459f69061beSDaniel Vetter 1460f69061beSDaniel Vetter kobject_uevent_env(&dev->primary->kdev.kobj, 1461f69061beSDaniel Vetter KOBJ_CHANGE, reset_done_event); 14621f83fee0SDaniel Vetter } else { 14631f83fee0SDaniel Vetter atomic_set(&error->reset_counter, I915_WEDGED); 1464f316a42cSBen Gamari } 14651f83fee0SDaniel Vetter 1466f69061beSDaniel Vetter for_each_ring(ring, dev_priv, i) 1467f69061beSDaniel Vetter wake_up_all(&ring->irq_queue); 1468f69061beSDaniel Vetter 146996a02917SVille Syrjälä intel_display_handle_reset(dev); 147096a02917SVille Syrjälä 14711f83fee0SDaniel Vetter wake_up_all(&dev_priv->gpu_error.reset_queue); 1472f316a42cSBen Gamari } 14738a905236SJesse Barnes } 14748a905236SJesse Barnes 147585f9e50dSDaniel Vetter /* NB: please notice the memset */ 147685f9e50dSDaniel Vetter static void i915_get_extra_instdone(struct drm_device *dev, 147785f9e50dSDaniel Vetter uint32_t *instdone) 147885f9e50dSDaniel Vetter { 147985f9e50dSDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 148085f9e50dSDaniel Vetter memset(instdone, 0, sizeof(*instdone) * I915_NUM_INSTDONE_REG); 148185f9e50dSDaniel Vetter 148285f9e50dSDaniel Vetter switch(INTEL_INFO(dev)->gen) { 148385f9e50dSDaniel Vetter case 2: 148485f9e50dSDaniel Vetter case 3: 148585f9e50dSDaniel Vetter instdone[0] = I915_READ(INSTDONE); 148685f9e50dSDaniel Vetter break; 148785f9e50dSDaniel Vetter case 4: 148885f9e50dSDaniel Vetter case 5: 148985f9e50dSDaniel Vetter case 6: 149085f9e50dSDaniel Vetter instdone[0] = I915_READ(INSTDONE_I965); 149185f9e50dSDaniel Vetter instdone[1] = I915_READ(INSTDONE1); 149285f9e50dSDaniel Vetter break; 149385f9e50dSDaniel Vetter default: 149485f9e50dSDaniel Vetter WARN_ONCE(1, "Unsupported platform\n"); 149585f9e50dSDaniel Vetter case 7: 149685f9e50dSDaniel Vetter instdone[0] = I915_READ(GEN7_INSTDONE_1); 149785f9e50dSDaniel Vetter instdone[1] = I915_READ(GEN7_SC_INSTDONE); 149885f9e50dSDaniel Vetter instdone[2] = I915_READ(GEN7_SAMPLER_INSTDONE); 149985f9e50dSDaniel Vetter instdone[3] = I915_READ(GEN7_ROW_INSTDONE); 150085f9e50dSDaniel Vetter break; 150185f9e50dSDaniel Vetter } 150285f9e50dSDaniel Vetter } 150385f9e50dSDaniel Vetter 15043bd3c932SChris Wilson #ifdef CONFIG_DEBUG_FS 15059df30794SChris Wilson static struct drm_i915_error_object * 1506d0d045e8SBen Widawsky i915_error_object_create_sized(struct drm_i915_private *dev_priv, 1507d0d045e8SBen Widawsky struct drm_i915_gem_object *src, 1508d0d045e8SBen Widawsky const int num_pages) 15099df30794SChris Wilson { 15109df30794SChris Wilson struct drm_i915_error_object *dst; 1511d0d045e8SBen Widawsky int i; 1512e56660ddSChris Wilson u32 reloc_offset; 15139df30794SChris Wilson 151405394f39SChris Wilson if (src == NULL || src->pages == NULL) 15159df30794SChris Wilson return NULL; 15169df30794SChris Wilson 1517d0d045e8SBen Widawsky dst = kmalloc(sizeof(*dst) + num_pages * sizeof(u32 *), GFP_ATOMIC); 15189df30794SChris Wilson if (dst == NULL) 15199df30794SChris Wilson return NULL; 15209df30794SChris Wilson 152105394f39SChris Wilson reloc_offset = src->gtt_offset; 1522d0d045e8SBen Widawsky for (i = 0; i < num_pages; i++) { 1523788885aeSAndrew Morton unsigned long flags; 1524e56660ddSChris Wilson void *d; 1525788885aeSAndrew Morton 1526e56660ddSChris Wilson d = kmalloc(PAGE_SIZE, GFP_ATOMIC); 15279df30794SChris Wilson if (d == NULL) 15289df30794SChris Wilson goto unwind; 1529e56660ddSChris Wilson 1530788885aeSAndrew Morton local_irq_save(flags); 15315d4545aeSBen Widawsky if (reloc_offset < dev_priv->gtt.mappable_end && 153274898d7eSDaniel Vetter src->has_global_gtt_mapping) { 1533172975aaSChris Wilson void __iomem *s; 1534172975aaSChris Wilson 1535172975aaSChris Wilson /* Simply ignore tiling or any overlapping fence. 1536172975aaSChris Wilson * It's part of the error state, and this hopefully 1537172975aaSChris Wilson * captures what the GPU read. 1538172975aaSChris Wilson */ 1539172975aaSChris Wilson 15405d4545aeSBen Widawsky s = io_mapping_map_atomic_wc(dev_priv->gtt.mappable, 15413e4d3af5SPeter Zijlstra reloc_offset); 1542e56660ddSChris Wilson memcpy_fromio(d, s, PAGE_SIZE); 15433e4d3af5SPeter Zijlstra io_mapping_unmap_atomic(s); 1544960e3564SChris Wilson } else if (src->stolen) { 1545960e3564SChris Wilson unsigned long offset; 1546960e3564SChris Wilson 1547960e3564SChris Wilson offset = dev_priv->mm.stolen_base; 1548960e3564SChris Wilson offset += src->stolen->start; 1549960e3564SChris Wilson offset += i << PAGE_SHIFT; 1550960e3564SChris Wilson 15511a240d4dSDaniel Vetter memcpy_fromio(d, (void __iomem *) offset, PAGE_SIZE); 1552172975aaSChris Wilson } else { 15539da3da66SChris Wilson struct page *page; 1554172975aaSChris Wilson void *s; 1555172975aaSChris Wilson 15569da3da66SChris Wilson page = i915_gem_object_get_page(src, i); 1557172975aaSChris Wilson 15589da3da66SChris Wilson drm_clflush_pages(&page, 1); 15599da3da66SChris Wilson 15609da3da66SChris Wilson s = kmap_atomic(page); 1561172975aaSChris Wilson memcpy(d, s, PAGE_SIZE); 1562172975aaSChris Wilson kunmap_atomic(s); 1563172975aaSChris Wilson 15649da3da66SChris Wilson drm_clflush_pages(&page, 1); 1565172975aaSChris Wilson } 1566788885aeSAndrew Morton local_irq_restore(flags); 1567e56660ddSChris Wilson 15689da3da66SChris Wilson dst->pages[i] = d; 1569e56660ddSChris Wilson 1570e56660ddSChris Wilson reloc_offset += PAGE_SIZE; 15719df30794SChris Wilson } 1572d0d045e8SBen Widawsky dst->page_count = num_pages; 157305394f39SChris Wilson dst->gtt_offset = src->gtt_offset; 15749df30794SChris Wilson 15759df30794SChris Wilson return dst; 15769df30794SChris Wilson 15779df30794SChris Wilson unwind: 15789da3da66SChris Wilson while (i--) 15799da3da66SChris Wilson kfree(dst->pages[i]); 15809df30794SChris Wilson kfree(dst); 15819df30794SChris Wilson return NULL; 15829df30794SChris Wilson } 1583d0d045e8SBen Widawsky #define i915_error_object_create(dev_priv, src) \ 1584d0d045e8SBen Widawsky i915_error_object_create_sized((dev_priv), (src), \ 1585d0d045e8SBen Widawsky (src)->base.size>>PAGE_SHIFT) 15869df30794SChris Wilson 15879df30794SChris Wilson static void 15889df30794SChris Wilson i915_error_object_free(struct drm_i915_error_object *obj) 15899df30794SChris Wilson { 15909df30794SChris Wilson int page; 15919df30794SChris Wilson 15929df30794SChris Wilson if (obj == NULL) 15939df30794SChris Wilson return; 15949df30794SChris Wilson 15959df30794SChris Wilson for (page = 0; page < obj->page_count; page++) 15969df30794SChris Wilson kfree(obj->pages[page]); 15979df30794SChris Wilson 15989df30794SChris Wilson kfree(obj); 15999df30794SChris Wilson } 16009df30794SChris Wilson 1601742cbee8SDaniel Vetter void 1602742cbee8SDaniel Vetter i915_error_state_free(struct kref *error_ref) 16039df30794SChris Wilson { 1604742cbee8SDaniel Vetter struct drm_i915_error_state *error = container_of(error_ref, 1605742cbee8SDaniel Vetter typeof(*error), ref); 1606e2f973d5SChris Wilson int i; 1607e2f973d5SChris Wilson 160852d39a21SChris Wilson for (i = 0; i < ARRAY_SIZE(error->ring); i++) { 160952d39a21SChris Wilson i915_error_object_free(error->ring[i].batchbuffer); 161052d39a21SChris Wilson i915_error_object_free(error->ring[i].ringbuffer); 16117ed73da0SBen Widawsky i915_error_object_free(error->ring[i].ctx); 161252d39a21SChris Wilson kfree(error->ring[i].requests); 161352d39a21SChris Wilson } 1614e2f973d5SChris Wilson 16159df30794SChris Wilson kfree(error->active_bo); 16166ef3d427SChris Wilson kfree(error->overlay); 16177ed73da0SBen Widawsky kfree(error->display); 16189df30794SChris Wilson kfree(error); 16199df30794SChris Wilson } 16201b50247aSChris Wilson static void capture_bo(struct drm_i915_error_buffer *err, 16211b50247aSChris Wilson struct drm_i915_gem_object *obj) 1622c724e8a9SChris Wilson { 1623c724e8a9SChris Wilson err->size = obj->base.size; 1624c724e8a9SChris Wilson err->name = obj->base.name; 16250201f1ecSChris Wilson err->rseqno = obj->last_read_seqno; 16260201f1ecSChris Wilson err->wseqno = obj->last_write_seqno; 1627c724e8a9SChris Wilson err->gtt_offset = obj->gtt_offset; 1628c724e8a9SChris Wilson err->read_domains = obj->base.read_domains; 1629c724e8a9SChris Wilson err->write_domain = obj->base.write_domain; 1630c724e8a9SChris Wilson err->fence_reg = obj->fence_reg; 1631c724e8a9SChris Wilson err->pinned = 0; 1632c724e8a9SChris Wilson if (obj->pin_count > 0) 1633c724e8a9SChris Wilson err->pinned = 1; 1634c724e8a9SChris Wilson if (obj->user_pin_count > 0) 1635c724e8a9SChris Wilson err->pinned = -1; 1636c724e8a9SChris Wilson err->tiling = obj->tiling_mode; 1637c724e8a9SChris Wilson err->dirty = obj->dirty; 1638c724e8a9SChris Wilson err->purgeable = obj->madv != I915_MADV_WILLNEED; 163996154f2fSDaniel Vetter err->ring = obj->ring ? obj->ring->id : -1; 164093dfb40cSChris Wilson err->cache_level = obj->cache_level; 16411b50247aSChris Wilson } 1642c724e8a9SChris Wilson 16431b50247aSChris Wilson static u32 capture_active_bo(struct drm_i915_error_buffer *err, 16441b50247aSChris Wilson int count, struct list_head *head) 16451b50247aSChris Wilson { 16461b50247aSChris Wilson struct drm_i915_gem_object *obj; 16471b50247aSChris Wilson int i = 0; 16481b50247aSChris Wilson 16491b50247aSChris Wilson list_for_each_entry(obj, head, mm_list) { 16501b50247aSChris Wilson capture_bo(err++, obj); 1651c724e8a9SChris Wilson if (++i == count) 1652c724e8a9SChris Wilson break; 16531b50247aSChris Wilson } 1654c724e8a9SChris Wilson 16551b50247aSChris Wilson return i; 16561b50247aSChris Wilson } 16571b50247aSChris Wilson 16581b50247aSChris Wilson static u32 capture_pinned_bo(struct drm_i915_error_buffer *err, 16591b50247aSChris Wilson int count, struct list_head *head) 16601b50247aSChris Wilson { 16611b50247aSChris Wilson struct drm_i915_gem_object *obj; 16621b50247aSChris Wilson int i = 0; 16631b50247aSChris Wilson 166435c20a60SBen Widawsky list_for_each_entry(obj, head, global_list) { 16651b50247aSChris Wilson if (obj->pin_count == 0) 16661b50247aSChris Wilson continue; 16671b50247aSChris Wilson 16681b50247aSChris Wilson capture_bo(err++, obj); 16691b50247aSChris Wilson if (++i == count) 16701b50247aSChris Wilson break; 1671c724e8a9SChris Wilson } 1672c724e8a9SChris Wilson 1673c724e8a9SChris Wilson return i; 1674c724e8a9SChris Wilson } 1675c724e8a9SChris Wilson 1676748ebc60SChris Wilson static void i915_gem_record_fences(struct drm_device *dev, 1677748ebc60SChris Wilson struct drm_i915_error_state *error) 1678748ebc60SChris Wilson { 1679748ebc60SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 1680748ebc60SChris Wilson int i; 1681748ebc60SChris Wilson 1682748ebc60SChris Wilson /* Fences */ 1683748ebc60SChris Wilson switch (INTEL_INFO(dev)->gen) { 1684775d17b6SDaniel Vetter case 7: 1685748ebc60SChris Wilson case 6: 168642b5aeabSVille Syrjälä for (i = 0; i < dev_priv->num_fence_regs; i++) 1687748ebc60SChris Wilson error->fence[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 + (i * 8)); 1688748ebc60SChris Wilson break; 1689748ebc60SChris Wilson case 5: 1690748ebc60SChris Wilson case 4: 1691748ebc60SChris Wilson for (i = 0; i < 16; i++) 1692748ebc60SChris Wilson error->fence[i] = I915_READ64(FENCE_REG_965_0 + (i * 8)); 1693748ebc60SChris Wilson break; 1694748ebc60SChris Wilson case 3: 1695748ebc60SChris Wilson if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) 1696748ebc60SChris Wilson for (i = 0; i < 8; i++) 1697748ebc60SChris Wilson error->fence[i+8] = I915_READ(FENCE_REG_945_8 + (i * 4)); 1698748ebc60SChris Wilson case 2: 1699748ebc60SChris Wilson for (i = 0; i < 8; i++) 1700748ebc60SChris Wilson error->fence[i] = I915_READ(FENCE_REG_830_0 + (i * 4)); 1701748ebc60SChris Wilson break; 1702748ebc60SChris Wilson 17037dbf9d6eSBen Widawsky default: 17047dbf9d6eSBen Widawsky BUG(); 1705748ebc60SChris Wilson } 1706748ebc60SChris Wilson } 1707748ebc60SChris Wilson 1708bcfb2e28SChris Wilson static struct drm_i915_error_object * 1709bcfb2e28SChris Wilson i915_error_first_batchbuffer(struct drm_i915_private *dev_priv, 1710bcfb2e28SChris Wilson struct intel_ring_buffer *ring) 1711bcfb2e28SChris Wilson { 1712bcfb2e28SChris Wilson struct drm_i915_gem_object *obj; 1713bcfb2e28SChris Wilson u32 seqno; 1714bcfb2e28SChris Wilson 1715bcfb2e28SChris Wilson if (!ring->get_seqno) 1716bcfb2e28SChris Wilson return NULL; 1717bcfb2e28SChris Wilson 1718b45305fcSDaniel Vetter if (HAS_BROKEN_CS_TLB(dev_priv->dev)) { 1719b45305fcSDaniel Vetter u32 acthd = I915_READ(ACTHD); 1720b45305fcSDaniel Vetter 1721b45305fcSDaniel Vetter if (WARN_ON(ring->id != RCS)) 1722b45305fcSDaniel Vetter return NULL; 1723b45305fcSDaniel Vetter 1724b45305fcSDaniel Vetter obj = ring->private; 1725b45305fcSDaniel Vetter if (acthd >= obj->gtt_offset && 1726b45305fcSDaniel Vetter acthd < obj->gtt_offset + obj->base.size) 1727b45305fcSDaniel Vetter return i915_error_object_create(dev_priv, obj); 1728b45305fcSDaniel Vetter } 1729b45305fcSDaniel Vetter 1730b2eadbc8SChris Wilson seqno = ring->get_seqno(ring, false); 1731bcfb2e28SChris Wilson list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list) { 1732bcfb2e28SChris Wilson if (obj->ring != ring) 1733bcfb2e28SChris Wilson continue; 1734bcfb2e28SChris Wilson 17350201f1ecSChris Wilson if (i915_seqno_passed(seqno, obj->last_read_seqno)) 1736bcfb2e28SChris Wilson continue; 1737bcfb2e28SChris Wilson 1738bcfb2e28SChris Wilson if ((obj->base.read_domains & I915_GEM_DOMAIN_COMMAND) == 0) 1739bcfb2e28SChris Wilson continue; 1740bcfb2e28SChris Wilson 1741bcfb2e28SChris Wilson /* We need to copy these to an anonymous buffer as the simplest 1742bcfb2e28SChris Wilson * method to avoid being overwritten by userspace. 1743bcfb2e28SChris Wilson */ 1744bcfb2e28SChris Wilson return i915_error_object_create(dev_priv, obj); 1745bcfb2e28SChris Wilson } 1746bcfb2e28SChris Wilson 1747bcfb2e28SChris Wilson return NULL; 1748bcfb2e28SChris Wilson } 1749bcfb2e28SChris Wilson 1750d27b1e0eSDaniel Vetter static void i915_record_ring_state(struct drm_device *dev, 1751d27b1e0eSDaniel Vetter struct drm_i915_error_state *error, 1752d27b1e0eSDaniel Vetter struct intel_ring_buffer *ring) 1753d27b1e0eSDaniel Vetter { 1754d27b1e0eSDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 1755d27b1e0eSDaniel Vetter 175633f3f518SDaniel Vetter if (INTEL_INFO(dev)->gen >= 6) { 175712f55818SChris Wilson error->rc_psmi[ring->id] = I915_READ(ring->mmio_base + 0x50); 175833f3f518SDaniel Vetter error->fault_reg[ring->id] = I915_READ(RING_FAULT_REG(ring)); 17597e3b8737SDaniel Vetter error->semaphore_mboxes[ring->id][0] 17607e3b8737SDaniel Vetter = I915_READ(RING_SYNC_0(ring->mmio_base)); 17617e3b8737SDaniel Vetter error->semaphore_mboxes[ring->id][1] 17627e3b8737SDaniel Vetter = I915_READ(RING_SYNC_1(ring->mmio_base)); 1763df2b23d9SChris Wilson error->semaphore_seqno[ring->id][0] = ring->sync_seqno[0]; 1764df2b23d9SChris Wilson error->semaphore_seqno[ring->id][1] = ring->sync_seqno[1]; 176533f3f518SDaniel Vetter } 1766c1cd90edSDaniel Vetter 1767d27b1e0eSDaniel Vetter if (INTEL_INFO(dev)->gen >= 4) { 17689d2f41faSDaniel Vetter error->faddr[ring->id] = I915_READ(RING_DMA_FADD(ring->mmio_base)); 1769d27b1e0eSDaniel Vetter error->ipeir[ring->id] = I915_READ(RING_IPEIR(ring->mmio_base)); 1770d27b1e0eSDaniel Vetter error->ipehr[ring->id] = I915_READ(RING_IPEHR(ring->mmio_base)); 1771d27b1e0eSDaniel Vetter error->instdone[ring->id] = I915_READ(RING_INSTDONE(ring->mmio_base)); 1772c1cd90edSDaniel Vetter error->instps[ring->id] = I915_READ(RING_INSTPS(ring->mmio_base)); 1773050ee91fSBen Widawsky if (ring->id == RCS) 1774d27b1e0eSDaniel Vetter error->bbaddr = I915_READ64(BB_ADDR); 1775d27b1e0eSDaniel Vetter } else { 17769d2f41faSDaniel Vetter error->faddr[ring->id] = I915_READ(DMA_FADD_I8XX); 1777d27b1e0eSDaniel Vetter error->ipeir[ring->id] = I915_READ(IPEIR); 1778d27b1e0eSDaniel Vetter error->ipehr[ring->id] = I915_READ(IPEHR); 1779d27b1e0eSDaniel Vetter error->instdone[ring->id] = I915_READ(INSTDONE); 1780d27b1e0eSDaniel Vetter } 1781d27b1e0eSDaniel Vetter 17829574b3feSBen Widawsky error->waiting[ring->id] = waitqueue_active(&ring->irq_queue); 1783c1cd90edSDaniel Vetter error->instpm[ring->id] = I915_READ(RING_INSTPM(ring->mmio_base)); 1784b2eadbc8SChris Wilson error->seqno[ring->id] = ring->get_seqno(ring, false); 1785d27b1e0eSDaniel Vetter error->acthd[ring->id] = intel_ring_get_active_head(ring); 1786c1cd90edSDaniel Vetter error->head[ring->id] = I915_READ_HEAD(ring); 1787c1cd90edSDaniel Vetter error->tail[ring->id] = I915_READ_TAIL(ring); 17880f3b6849SChris Wilson error->ctl[ring->id] = I915_READ_CTL(ring); 17897e3b8737SDaniel Vetter 17907e3b8737SDaniel Vetter error->cpu_ring_head[ring->id] = ring->head; 17917e3b8737SDaniel Vetter error->cpu_ring_tail[ring->id] = ring->tail; 1792d27b1e0eSDaniel Vetter } 1793d27b1e0eSDaniel Vetter 17948c123e54SBen Widawsky 17958c123e54SBen Widawsky static void i915_gem_record_active_context(struct intel_ring_buffer *ring, 17968c123e54SBen Widawsky struct drm_i915_error_state *error, 17978c123e54SBen Widawsky struct drm_i915_error_ring *ering) 17988c123e54SBen Widawsky { 17998c123e54SBen Widawsky struct drm_i915_private *dev_priv = ring->dev->dev_private; 18008c123e54SBen Widawsky struct drm_i915_gem_object *obj; 18018c123e54SBen Widawsky 18028c123e54SBen Widawsky /* Currently render ring is the only HW context user */ 18038c123e54SBen Widawsky if (ring->id != RCS || !error->ccid) 18048c123e54SBen Widawsky return; 18058c123e54SBen Widawsky 180635c20a60SBen Widawsky list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) { 18078c123e54SBen Widawsky if ((error->ccid & PAGE_MASK) == obj->gtt_offset) { 18088c123e54SBen Widawsky ering->ctx = i915_error_object_create_sized(dev_priv, 18098c123e54SBen Widawsky obj, 1); 18108c123e54SBen Widawsky } 18118c123e54SBen Widawsky } 18128c123e54SBen Widawsky } 18138c123e54SBen Widawsky 181452d39a21SChris Wilson static void i915_gem_record_rings(struct drm_device *dev, 181552d39a21SChris Wilson struct drm_i915_error_state *error) 181652d39a21SChris Wilson { 181752d39a21SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 1818b4519513SChris Wilson struct intel_ring_buffer *ring; 181952d39a21SChris Wilson struct drm_i915_gem_request *request; 182052d39a21SChris Wilson int i, count; 182152d39a21SChris Wilson 1822b4519513SChris Wilson for_each_ring(ring, dev_priv, i) { 182352d39a21SChris Wilson i915_record_ring_state(dev, error, ring); 182452d39a21SChris Wilson 182552d39a21SChris Wilson error->ring[i].batchbuffer = 182652d39a21SChris Wilson i915_error_first_batchbuffer(dev_priv, ring); 182752d39a21SChris Wilson 182852d39a21SChris Wilson error->ring[i].ringbuffer = 182952d39a21SChris Wilson i915_error_object_create(dev_priv, ring->obj); 183052d39a21SChris Wilson 18318c123e54SBen Widawsky 18328c123e54SBen Widawsky i915_gem_record_active_context(ring, error, &error->ring[i]); 18338c123e54SBen Widawsky 183452d39a21SChris Wilson count = 0; 183552d39a21SChris Wilson list_for_each_entry(request, &ring->request_list, list) 183652d39a21SChris Wilson count++; 183752d39a21SChris Wilson 183852d39a21SChris Wilson error->ring[i].num_requests = count; 183952d39a21SChris Wilson error->ring[i].requests = 184052d39a21SChris Wilson kmalloc(count*sizeof(struct drm_i915_error_request), 184152d39a21SChris Wilson GFP_ATOMIC); 184252d39a21SChris Wilson if (error->ring[i].requests == NULL) { 184352d39a21SChris Wilson error->ring[i].num_requests = 0; 184452d39a21SChris Wilson continue; 184552d39a21SChris Wilson } 184652d39a21SChris Wilson 184752d39a21SChris Wilson count = 0; 184852d39a21SChris Wilson list_for_each_entry(request, &ring->request_list, list) { 184952d39a21SChris Wilson struct drm_i915_error_request *erq; 185052d39a21SChris Wilson 185152d39a21SChris Wilson erq = &error->ring[i].requests[count++]; 185252d39a21SChris Wilson erq->seqno = request->seqno; 185352d39a21SChris Wilson erq->jiffies = request->emitted_jiffies; 1854ee4f42b1SChris Wilson erq->tail = request->tail; 185552d39a21SChris Wilson } 185652d39a21SChris Wilson } 185752d39a21SChris Wilson } 185852d39a21SChris Wilson 18598a905236SJesse Barnes /** 18608a905236SJesse Barnes * i915_capture_error_state - capture an error record for later analysis 18618a905236SJesse Barnes * @dev: drm device 18628a905236SJesse Barnes * 18638a905236SJesse Barnes * Should be called when an error is detected (either a hang or an error 18648a905236SJesse Barnes * interrupt) to capture error state from the time of the error. Fills 18658a905236SJesse Barnes * out a structure which becomes available in debugfs for user level tools 18668a905236SJesse Barnes * to pick up. 18678a905236SJesse Barnes */ 186863eeaf38SJesse Barnes static void i915_capture_error_state(struct drm_device *dev) 186963eeaf38SJesse Barnes { 187063eeaf38SJesse Barnes struct drm_i915_private *dev_priv = dev->dev_private; 187105394f39SChris Wilson struct drm_i915_gem_object *obj; 187263eeaf38SJesse Barnes struct drm_i915_error_state *error; 187363eeaf38SJesse Barnes unsigned long flags; 18749db4a9c7SJesse Barnes int i, pipe; 187563eeaf38SJesse Barnes 187699584db3SDaniel Vetter spin_lock_irqsave(&dev_priv->gpu_error.lock, flags); 187799584db3SDaniel Vetter error = dev_priv->gpu_error.first_error; 187899584db3SDaniel Vetter spin_unlock_irqrestore(&dev_priv->gpu_error.lock, flags); 18799df30794SChris Wilson if (error) 18809df30794SChris Wilson return; 188163eeaf38SJesse Barnes 18829db4a9c7SJesse Barnes /* Account for pipe specific data like PIPE*STAT */ 188333f3f518SDaniel Vetter error = kzalloc(sizeof(*error), GFP_ATOMIC); 188463eeaf38SJesse Barnes if (!error) { 18859df30794SChris Wilson DRM_DEBUG_DRIVER("out of memory, not capturing error state\n"); 18869df30794SChris Wilson return; 188763eeaf38SJesse Barnes } 188863eeaf38SJesse Barnes 18892f86f191SBen Widawsky DRM_INFO("capturing error event; look for more information in " 18902f86f191SBen Widawsky "/sys/kernel/debug/dri/%d/i915_error_state\n", 1891b6f7833bSChris Wilson dev->primary->index); 18922fa772f3SChris Wilson 1893742cbee8SDaniel Vetter kref_init(&error->ref); 189463eeaf38SJesse Barnes error->eir = I915_READ(EIR); 189563eeaf38SJesse Barnes error->pgtbl_er = I915_READ(PGTBL_ER); 1896211816ecSBen Widawsky if (HAS_HW_CONTEXTS(dev)) 1897b9a3906bSBen Widawsky error->ccid = I915_READ(CCID); 1898be998e2eSBen Widawsky 1899be998e2eSBen Widawsky if (HAS_PCH_SPLIT(dev)) 1900be998e2eSBen Widawsky error->ier = I915_READ(DEIER) | I915_READ(GTIER); 1901be998e2eSBen Widawsky else if (IS_VALLEYVIEW(dev)) 1902be998e2eSBen Widawsky error->ier = I915_READ(GTIER) | I915_READ(VLV_IER); 1903be998e2eSBen Widawsky else if (IS_GEN2(dev)) 1904be998e2eSBen Widawsky error->ier = I915_READ16(IER); 1905be998e2eSBen Widawsky else 1906be998e2eSBen Widawsky error->ier = I915_READ(IER); 1907be998e2eSBen Widawsky 19080f3b6849SChris Wilson if (INTEL_INFO(dev)->gen >= 6) 19090f3b6849SChris Wilson error->derrmr = I915_READ(DERRMR); 19100f3b6849SChris Wilson 19110f3b6849SChris Wilson if (IS_VALLEYVIEW(dev)) 19120f3b6849SChris Wilson error->forcewake = I915_READ(FORCEWAKE_VLV); 19130f3b6849SChris Wilson else if (INTEL_INFO(dev)->gen >= 7) 19140f3b6849SChris Wilson error->forcewake = I915_READ(FORCEWAKE_MT); 19150f3b6849SChris Wilson else if (INTEL_INFO(dev)->gen == 6) 19160f3b6849SChris Wilson error->forcewake = I915_READ(FORCEWAKE); 19170f3b6849SChris Wilson 19184f3308b9SPaulo Zanoni if (!HAS_PCH_SPLIT(dev)) 19199db4a9c7SJesse Barnes for_each_pipe(pipe) 19209db4a9c7SJesse Barnes error->pipestat[pipe] = I915_READ(PIPESTAT(pipe)); 1921d27b1e0eSDaniel Vetter 192233f3f518SDaniel Vetter if (INTEL_INFO(dev)->gen >= 6) { 1923f406839fSChris Wilson error->error = I915_READ(ERROR_GEN6); 192433f3f518SDaniel Vetter error->done_reg = I915_READ(DONE_REG); 192533f3f518SDaniel Vetter } 1926add354ddSChris Wilson 192771e172e8SBen Widawsky if (INTEL_INFO(dev)->gen == 7) 192871e172e8SBen Widawsky error->err_int = I915_READ(GEN7_ERR_INT); 192971e172e8SBen Widawsky 1930050ee91fSBen Widawsky i915_get_extra_instdone(dev, error->extra_instdone); 1931050ee91fSBen Widawsky 1932748ebc60SChris Wilson i915_gem_record_fences(dev, error); 193352d39a21SChris Wilson i915_gem_record_rings(dev, error); 19349df30794SChris Wilson 1935c724e8a9SChris Wilson /* Record buffers on the active and pinned lists. */ 19369df30794SChris Wilson error->active_bo = NULL; 1937c724e8a9SChris Wilson error->pinned_bo = NULL; 19389df30794SChris Wilson 1939bcfb2e28SChris Wilson i = 0; 1940bcfb2e28SChris Wilson list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list) 1941bcfb2e28SChris Wilson i++; 1942bcfb2e28SChris Wilson error->active_bo_count = i; 194335c20a60SBen Widawsky list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) 19441b50247aSChris Wilson if (obj->pin_count) 1945bcfb2e28SChris Wilson i++; 1946bcfb2e28SChris Wilson error->pinned_bo_count = i - error->active_bo_count; 1947c724e8a9SChris Wilson 19488e934dbfSChris Wilson error->active_bo = NULL; 19498e934dbfSChris Wilson error->pinned_bo = NULL; 1950bcfb2e28SChris Wilson if (i) { 1951bcfb2e28SChris Wilson error->active_bo = kmalloc(sizeof(*error->active_bo)*i, 19529df30794SChris Wilson GFP_ATOMIC); 1953c724e8a9SChris Wilson if (error->active_bo) 1954c724e8a9SChris Wilson error->pinned_bo = 1955c724e8a9SChris Wilson error->active_bo + error->active_bo_count; 19569df30794SChris Wilson } 1957c724e8a9SChris Wilson 1958c724e8a9SChris Wilson if (error->active_bo) 1959c724e8a9SChris Wilson error->active_bo_count = 19601b50247aSChris Wilson capture_active_bo(error->active_bo, 1961c724e8a9SChris Wilson error->active_bo_count, 1962c724e8a9SChris Wilson &dev_priv->mm.active_list); 1963c724e8a9SChris Wilson 1964c724e8a9SChris Wilson if (error->pinned_bo) 1965c724e8a9SChris Wilson error->pinned_bo_count = 19661b50247aSChris Wilson capture_pinned_bo(error->pinned_bo, 1967c724e8a9SChris Wilson error->pinned_bo_count, 19686c085a72SChris Wilson &dev_priv->mm.bound_list); 196963eeaf38SJesse Barnes 19708a905236SJesse Barnes do_gettimeofday(&error->time); 19718a905236SJesse Barnes 19726ef3d427SChris Wilson error->overlay = intel_overlay_capture_error_state(dev); 1973c4a1d9e4SChris Wilson error->display = intel_display_capture_error_state(dev); 19746ef3d427SChris Wilson 197599584db3SDaniel Vetter spin_lock_irqsave(&dev_priv->gpu_error.lock, flags); 197699584db3SDaniel Vetter if (dev_priv->gpu_error.first_error == NULL) { 197799584db3SDaniel Vetter dev_priv->gpu_error.first_error = error; 19789df30794SChris Wilson error = NULL; 19799df30794SChris Wilson } 198099584db3SDaniel Vetter spin_unlock_irqrestore(&dev_priv->gpu_error.lock, flags); 19819df30794SChris Wilson 19829df30794SChris Wilson if (error) 1983742cbee8SDaniel Vetter i915_error_state_free(&error->ref); 19849df30794SChris Wilson } 19859df30794SChris Wilson 19869df30794SChris Wilson void i915_destroy_error_state(struct drm_device *dev) 19879df30794SChris Wilson { 19889df30794SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 19899df30794SChris Wilson struct drm_i915_error_state *error; 19906dc0e816SBen Widawsky unsigned long flags; 19919df30794SChris Wilson 199299584db3SDaniel Vetter spin_lock_irqsave(&dev_priv->gpu_error.lock, flags); 199399584db3SDaniel Vetter error = dev_priv->gpu_error.first_error; 199499584db3SDaniel Vetter dev_priv->gpu_error.first_error = NULL; 199599584db3SDaniel Vetter spin_unlock_irqrestore(&dev_priv->gpu_error.lock, flags); 19969df30794SChris Wilson 19979df30794SChris Wilson if (error) 1998742cbee8SDaniel Vetter kref_put(&error->ref, i915_error_state_free); 199963eeaf38SJesse Barnes } 20003bd3c932SChris Wilson #else 20013bd3c932SChris Wilson #define i915_capture_error_state(x) 20023bd3c932SChris Wilson #endif 200363eeaf38SJesse Barnes 200435aed2e6SChris Wilson static void i915_report_and_clear_eir(struct drm_device *dev) 2005c0e09200SDave Airlie { 20068a905236SJesse Barnes struct drm_i915_private *dev_priv = dev->dev_private; 2007bd9854f9SBen Widawsky uint32_t instdone[I915_NUM_INSTDONE_REG]; 200863eeaf38SJesse Barnes u32 eir = I915_READ(EIR); 2009050ee91fSBen Widawsky int pipe, i; 201063eeaf38SJesse Barnes 201135aed2e6SChris Wilson if (!eir) 201235aed2e6SChris Wilson return; 201363eeaf38SJesse Barnes 2014a70491ccSJoe Perches pr_err("render error detected, EIR: 0x%08x\n", eir); 20158a905236SJesse Barnes 2016bd9854f9SBen Widawsky i915_get_extra_instdone(dev, instdone); 2017bd9854f9SBen Widawsky 20188a905236SJesse Barnes if (IS_G4X(dev)) { 20198a905236SJesse Barnes if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) { 20208a905236SJesse Barnes u32 ipeir = I915_READ(IPEIR_I965); 20218a905236SJesse Barnes 2022a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); 2023a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); 2024050ee91fSBen Widawsky for (i = 0; i < ARRAY_SIZE(instdone); i++) 2025050ee91fSBen Widawsky pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]); 2026a70491ccSJoe Perches pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); 2027a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); 20288a905236SJesse Barnes I915_WRITE(IPEIR_I965, ipeir); 20293143a2bfSChris Wilson POSTING_READ(IPEIR_I965); 20308a905236SJesse Barnes } 20318a905236SJesse Barnes if (eir & GM45_ERROR_PAGE_TABLE) { 20328a905236SJesse Barnes u32 pgtbl_err = I915_READ(PGTBL_ER); 2033a70491ccSJoe Perches pr_err("page table error\n"); 2034a70491ccSJoe Perches pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); 20358a905236SJesse Barnes I915_WRITE(PGTBL_ER, pgtbl_err); 20363143a2bfSChris Wilson POSTING_READ(PGTBL_ER); 20378a905236SJesse Barnes } 20388a905236SJesse Barnes } 20398a905236SJesse Barnes 2040a6c45cf0SChris Wilson if (!IS_GEN2(dev)) { 204163eeaf38SJesse Barnes if (eir & I915_ERROR_PAGE_TABLE) { 204263eeaf38SJesse Barnes u32 pgtbl_err = I915_READ(PGTBL_ER); 2043a70491ccSJoe Perches pr_err("page table error\n"); 2044a70491ccSJoe Perches pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); 204563eeaf38SJesse Barnes I915_WRITE(PGTBL_ER, pgtbl_err); 20463143a2bfSChris Wilson POSTING_READ(PGTBL_ER); 204763eeaf38SJesse Barnes } 20488a905236SJesse Barnes } 20498a905236SJesse Barnes 205063eeaf38SJesse Barnes if (eir & I915_ERROR_MEMORY_REFRESH) { 2051a70491ccSJoe Perches pr_err("memory refresh error:\n"); 20529db4a9c7SJesse Barnes for_each_pipe(pipe) 2053a70491ccSJoe Perches pr_err("pipe %c stat: 0x%08x\n", 20549db4a9c7SJesse Barnes pipe_name(pipe), I915_READ(PIPESTAT(pipe))); 205563eeaf38SJesse Barnes /* pipestat has already been acked */ 205663eeaf38SJesse Barnes } 205763eeaf38SJesse Barnes if (eir & I915_ERROR_INSTRUCTION) { 2058a70491ccSJoe Perches pr_err("instruction error\n"); 2059a70491ccSJoe Perches pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM)); 2060050ee91fSBen Widawsky for (i = 0; i < ARRAY_SIZE(instdone); i++) 2061050ee91fSBen Widawsky pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]); 2062a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen < 4) { 206363eeaf38SJesse Barnes u32 ipeir = I915_READ(IPEIR); 206463eeaf38SJesse Barnes 2065a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR)); 2066a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR)); 2067a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD)); 206863eeaf38SJesse Barnes I915_WRITE(IPEIR, ipeir); 20693143a2bfSChris Wilson POSTING_READ(IPEIR); 207063eeaf38SJesse Barnes } else { 207163eeaf38SJesse Barnes u32 ipeir = I915_READ(IPEIR_I965); 207263eeaf38SJesse Barnes 2073a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); 2074a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); 2075a70491ccSJoe Perches pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); 2076a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); 207763eeaf38SJesse Barnes I915_WRITE(IPEIR_I965, ipeir); 20783143a2bfSChris Wilson POSTING_READ(IPEIR_I965); 207963eeaf38SJesse Barnes } 208063eeaf38SJesse Barnes } 208163eeaf38SJesse Barnes 208263eeaf38SJesse Barnes I915_WRITE(EIR, eir); 20833143a2bfSChris Wilson POSTING_READ(EIR); 208463eeaf38SJesse Barnes eir = I915_READ(EIR); 208563eeaf38SJesse Barnes if (eir) { 208663eeaf38SJesse Barnes /* 208763eeaf38SJesse Barnes * some errors might have become stuck, 208863eeaf38SJesse Barnes * mask them. 208963eeaf38SJesse Barnes */ 209063eeaf38SJesse Barnes DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir); 209163eeaf38SJesse Barnes I915_WRITE(EMR, I915_READ(EMR) | eir); 209263eeaf38SJesse Barnes I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 209363eeaf38SJesse Barnes } 209435aed2e6SChris Wilson } 209535aed2e6SChris Wilson 209635aed2e6SChris Wilson /** 209735aed2e6SChris Wilson * i915_handle_error - handle an error interrupt 209835aed2e6SChris Wilson * @dev: drm device 209935aed2e6SChris Wilson * 210035aed2e6SChris Wilson * Do some basic checking of regsiter state at error interrupt time and 210135aed2e6SChris Wilson * dump it to the syslog. Also call i915_capture_error_state() to make 210235aed2e6SChris Wilson * sure we get a record and make it available in debugfs. Fire a uevent 210335aed2e6SChris Wilson * so userspace knows something bad happened (should trigger collection 210435aed2e6SChris Wilson * of a ring dump etc.). 210535aed2e6SChris Wilson */ 2106527f9e90SChris Wilson void i915_handle_error(struct drm_device *dev, bool wedged) 210735aed2e6SChris Wilson { 210835aed2e6SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 2109b4519513SChris Wilson struct intel_ring_buffer *ring; 2110b4519513SChris Wilson int i; 211135aed2e6SChris Wilson 211235aed2e6SChris Wilson i915_capture_error_state(dev); 211335aed2e6SChris Wilson i915_report_and_clear_eir(dev); 21148a905236SJesse Barnes 2115ba1234d1SBen Gamari if (wedged) { 2116f69061beSDaniel Vetter atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG, 2117f69061beSDaniel Vetter &dev_priv->gpu_error.reset_counter); 2118ba1234d1SBen Gamari 211911ed50ecSBen Gamari /* 21201f83fee0SDaniel Vetter * Wakeup waiting processes so that the reset work item 21211f83fee0SDaniel Vetter * doesn't deadlock trying to grab various locks. 212211ed50ecSBen Gamari */ 2123b4519513SChris Wilson for_each_ring(ring, dev_priv, i) 2124b4519513SChris Wilson wake_up_all(&ring->irq_queue); 212511ed50ecSBen Gamari } 212611ed50ecSBen Gamari 212799584db3SDaniel Vetter queue_work(dev_priv->wq, &dev_priv->gpu_error.work); 21288a905236SJesse Barnes } 21298a905236SJesse Barnes 213021ad8330SVille Syrjälä static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe) 21314e5359cdSSimon Farnsworth { 21324e5359cdSSimon Farnsworth drm_i915_private_t *dev_priv = dev->dev_private; 21334e5359cdSSimon Farnsworth struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 21344e5359cdSSimon Farnsworth struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 213505394f39SChris Wilson struct drm_i915_gem_object *obj; 21364e5359cdSSimon Farnsworth struct intel_unpin_work *work; 21374e5359cdSSimon Farnsworth unsigned long flags; 21384e5359cdSSimon Farnsworth bool stall_detected; 21394e5359cdSSimon Farnsworth 21404e5359cdSSimon Farnsworth /* Ignore early vblank irqs */ 21414e5359cdSSimon Farnsworth if (intel_crtc == NULL) 21424e5359cdSSimon Farnsworth return; 21434e5359cdSSimon Farnsworth 21444e5359cdSSimon Farnsworth spin_lock_irqsave(&dev->event_lock, flags); 21454e5359cdSSimon Farnsworth work = intel_crtc->unpin_work; 21464e5359cdSSimon Farnsworth 2147e7d841caSChris Wilson if (work == NULL || 2148e7d841caSChris Wilson atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE || 2149e7d841caSChris Wilson !work->enable_stall_check) { 21504e5359cdSSimon Farnsworth /* Either the pending flip IRQ arrived, or we're too early. Don't check */ 21514e5359cdSSimon Farnsworth spin_unlock_irqrestore(&dev->event_lock, flags); 21524e5359cdSSimon Farnsworth return; 21534e5359cdSSimon Farnsworth } 21544e5359cdSSimon Farnsworth 21554e5359cdSSimon Farnsworth /* Potential stall - if we see that the flip has happened, assume a missed interrupt */ 215605394f39SChris Wilson obj = work->pending_flip_obj; 2157a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen >= 4) { 21589db4a9c7SJesse Barnes int dspsurf = DSPSURF(intel_crtc->plane); 2159446f2545SArmin Reese stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) == 2160446f2545SArmin Reese obj->gtt_offset; 21614e5359cdSSimon Farnsworth } else { 21629db4a9c7SJesse Barnes int dspaddr = DSPADDR(intel_crtc->plane); 216305394f39SChris Wilson stall_detected = I915_READ(dspaddr) == (obj->gtt_offset + 216401f2c773SVille Syrjälä crtc->y * crtc->fb->pitches[0] + 21654e5359cdSSimon Farnsworth crtc->x * crtc->fb->bits_per_pixel/8); 21664e5359cdSSimon Farnsworth } 21674e5359cdSSimon Farnsworth 21684e5359cdSSimon Farnsworth spin_unlock_irqrestore(&dev->event_lock, flags); 21694e5359cdSSimon Farnsworth 21704e5359cdSSimon Farnsworth if (stall_detected) { 21714e5359cdSSimon Farnsworth DRM_DEBUG_DRIVER("Pageflip stall detected\n"); 21724e5359cdSSimon Farnsworth intel_prepare_page_flip(dev, intel_crtc->plane); 21734e5359cdSSimon Farnsworth } 21744e5359cdSSimon Farnsworth } 21754e5359cdSSimon Farnsworth 217642f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 217742f52ef8SKeith Packard * we use as a pipe index 217842f52ef8SKeith Packard */ 2179f71d4af4SJesse Barnes static int i915_enable_vblank(struct drm_device *dev, int pipe) 21800a3e67a4SJesse Barnes { 21810a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2182e9d21d7fSKeith Packard unsigned long irqflags; 218371e0ffa5SJesse Barnes 21845eddb70bSChris Wilson if (!i915_pipe_enabled(dev, pipe)) 218571e0ffa5SJesse Barnes return -EINVAL; 21860a3e67a4SJesse Barnes 21871ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2188f796cf8fSJesse Barnes if (INTEL_INFO(dev)->gen >= 4) 21897c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 21907c463586SKeith Packard PIPE_START_VBLANK_INTERRUPT_ENABLE); 21910a3e67a4SJesse Barnes else 21927c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 21937c463586SKeith Packard PIPE_VBLANK_INTERRUPT_ENABLE); 21948692d00eSChris Wilson 21958692d00eSChris Wilson /* maintain vblank delivery even in deep C-states */ 21968692d00eSChris Wilson if (dev_priv->info->gen == 3) 21976b26c86dSDaniel Vetter I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS)); 21981ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 21998692d00eSChris Wilson 22000a3e67a4SJesse Barnes return 0; 22010a3e67a4SJesse Barnes } 22020a3e67a4SJesse Barnes 2203f71d4af4SJesse Barnes static int ironlake_enable_vblank(struct drm_device *dev, int pipe) 2204f796cf8fSJesse Barnes { 2205f796cf8fSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2206f796cf8fSJesse Barnes unsigned long irqflags; 2207f796cf8fSJesse Barnes 2208f796cf8fSJesse Barnes if (!i915_pipe_enabled(dev, pipe)) 2209f796cf8fSJesse Barnes return -EINVAL; 2210f796cf8fSJesse Barnes 2211f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2212f796cf8fSJesse Barnes ironlake_enable_display_irq(dev_priv, (pipe == 0) ? 2213f796cf8fSJesse Barnes DE_PIPEA_VBLANK : DE_PIPEB_VBLANK); 2214f796cf8fSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2215f796cf8fSJesse Barnes 2216f796cf8fSJesse Barnes return 0; 2217f796cf8fSJesse Barnes } 2218f796cf8fSJesse Barnes 2219f71d4af4SJesse Barnes static int ivybridge_enable_vblank(struct drm_device *dev, int pipe) 2220b1f14ad0SJesse Barnes { 2221b1f14ad0SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2222b1f14ad0SJesse Barnes unsigned long irqflags; 2223b1f14ad0SJesse Barnes 2224b1f14ad0SJesse Barnes if (!i915_pipe_enabled(dev, pipe)) 2225b1f14ad0SJesse Barnes return -EINVAL; 2226b1f14ad0SJesse Barnes 2227b1f14ad0SJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2228b615b57aSChris Wilson ironlake_enable_display_irq(dev_priv, 2229b615b57aSChris Wilson DE_PIPEA_VBLANK_IVB << (5 * pipe)); 2230b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2231b1f14ad0SJesse Barnes 2232b1f14ad0SJesse Barnes return 0; 2233b1f14ad0SJesse Barnes } 2234b1f14ad0SJesse Barnes 22357e231dbeSJesse Barnes static int valleyview_enable_vblank(struct drm_device *dev, int pipe) 22367e231dbeSJesse Barnes { 22377e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 22387e231dbeSJesse Barnes unsigned long irqflags; 223931acc7f5SJesse Barnes u32 imr; 22407e231dbeSJesse Barnes 22417e231dbeSJesse Barnes if (!i915_pipe_enabled(dev, pipe)) 22427e231dbeSJesse Barnes return -EINVAL; 22437e231dbeSJesse Barnes 22447e231dbeSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 22457e231dbeSJesse Barnes imr = I915_READ(VLV_IMR); 224631acc7f5SJesse Barnes if (pipe == 0) 22477e231dbeSJesse Barnes imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT; 224831acc7f5SJesse Barnes else 22497e231dbeSJesse Barnes imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; 22507e231dbeSJesse Barnes I915_WRITE(VLV_IMR, imr); 225131acc7f5SJesse Barnes i915_enable_pipestat(dev_priv, pipe, 225231acc7f5SJesse Barnes PIPE_START_VBLANK_INTERRUPT_ENABLE); 22537e231dbeSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 22547e231dbeSJesse Barnes 22557e231dbeSJesse Barnes return 0; 22567e231dbeSJesse Barnes } 22577e231dbeSJesse Barnes 225842f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 225942f52ef8SKeith Packard * we use as a pipe index 226042f52ef8SKeith Packard */ 2261f71d4af4SJesse Barnes static void i915_disable_vblank(struct drm_device *dev, int pipe) 22620a3e67a4SJesse Barnes { 22630a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2264e9d21d7fSKeith Packard unsigned long irqflags; 22650a3e67a4SJesse Barnes 22661ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 22678692d00eSChris Wilson if (dev_priv->info->gen == 3) 22686b26c86dSDaniel Vetter I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS)); 22698692d00eSChris Wilson 22707c463586SKeith Packard i915_disable_pipestat(dev_priv, pipe, 22717c463586SKeith Packard PIPE_VBLANK_INTERRUPT_ENABLE | 22727c463586SKeith Packard PIPE_START_VBLANK_INTERRUPT_ENABLE); 22731ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 22740a3e67a4SJesse Barnes } 22750a3e67a4SJesse Barnes 2276f71d4af4SJesse Barnes static void ironlake_disable_vblank(struct drm_device *dev, int pipe) 2277f796cf8fSJesse Barnes { 2278f796cf8fSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2279f796cf8fSJesse Barnes unsigned long irqflags; 2280f796cf8fSJesse Barnes 2281f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2282f796cf8fSJesse Barnes ironlake_disable_display_irq(dev_priv, (pipe == 0) ? 2283f796cf8fSJesse Barnes DE_PIPEA_VBLANK : DE_PIPEB_VBLANK); 2284f796cf8fSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2285f796cf8fSJesse Barnes } 2286f796cf8fSJesse Barnes 2287f71d4af4SJesse Barnes static void ivybridge_disable_vblank(struct drm_device *dev, int pipe) 2288b1f14ad0SJesse Barnes { 2289b1f14ad0SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2290b1f14ad0SJesse Barnes unsigned long irqflags; 2291b1f14ad0SJesse Barnes 2292b1f14ad0SJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2293b615b57aSChris Wilson ironlake_disable_display_irq(dev_priv, 2294b615b57aSChris Wilson DE_PIPEA_VBLANK_IVB << (pipe * 5)); 2295b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2296b1f14ad0SJesse Barnes } 2297b1f14ad0SJesse Barnes 22987e231dbeSJesse Barnes static void valleyview_disable_vblank(struct drm_device *dev, int pipe) 22997e231dbeSJesse Barnes { 23007e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 23017e231dbeSJesse Barnes unsigned long irqflags; 230231acc7f5SJesse Barnes u32 imr; 23037e231dbeSJesse Barnes 23047e231dbeSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 230531acc7f5SJesse Barnes i915_disable_pipestat(dev_priv, pipe, 230631acc7f5SJesse Barnes PIPE_START_VBLANK_INTERRUPT_ENABLE); 23077e231dbeSJesse Barnes imr = I915_READ(VLV_IMR); 230831acc7f5SJesse Barnes if (pipe == 0) 23097e231dbeSJesse Barnes imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT; 231031acc7f5SJesse Barnes else 23117e231dbeSJesse Barnes imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; 23127e231dbeSJesse Barnes I915_WRITE(VLV_IMR, imr); 23137e231dbeSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 23147e231dbeSJesse Barnes } 23157e231dbeSJesse Barnes 2316893eead0SChris Wilson static u32 2317893eead0SChris Wilson ring_last_seqno(struct intel_ring_buffer *ring) 2318852835f3SZou Nan hai { 2319893eead0SChris Wilson return list_entry(ring->request_list.prev, 2320893eead0SChris Wilson struct drm_i915_gem_request, list)->seqno; 2321893eead0SChris Wilson } 2322893eead0SChris Wilson 23239107e9d2SChris Wilson static bool 23249107e9d2SChris Wilson ring_idle(struct intel_ring_buffer *ring, u32 seqno) 2325893eead0SChris Wilson { 23269107e9d2SChris Wilson return (list_empty(&ring->request_list) || 23279107e9d2SChris Wilson i915_seqno_passed(seqno, ring_last_seqno(ring))); 2328f65d9421SBen Gamari } 2329f65d9421SBen Gamari 23306274f212SChris Wilson static struct intel_ring_buffer * 23316274f212SChris Wilson semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno) 2332a24a11e6SChris Wilson { 2333a24a11e6SChris Wilson struct drm_i915_private *dev_priv = ring->dev->dev_private; 23346274f212SChris Wilson u32 cmd, ipehr, acthd, acthd_min; 2335a24a11e6SChris Wilson 2336a24a11e6SChris Wilson ipehr = I915_READ(RING_IPEHR(ring->mmio_base)); 2337a24a11e6SChris Wilson if ((ipehr & ~(0x3 << 16)) != 2338a24a11e6SChris Wilson (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER)) 23396274f212SChris Wilson return NULL; 2340a24a11e6SChris Wilson 2341a24a11e6SChris Wilson /* ACTHD is likely pointing to the dword after the actual command, 2342a24a11e6SChris Wilson * so scan backwards until we find the MBOX. 2343a24a11e6SChris Wilson */ 23446274f212SChris Wilson acthd = intel_ring_get_active_head(ring) & HEAD_ADDR; 2345a24a11e6SChris Wilson acthd_min = max((int)acthd - 3 * 4, 0); 2346a24a11e6SChris Wilson do { 2347a24a11e6SChris Wilson cmd = ioread32(ring->virtual_start + acthd); 2348a24a11e6SChris Wilson if (cmd == ipehr) 2349a24a11e6SChris Wilson break; 2350a24a11e6SChris Wilson 2351a24a11e6SChris Wilson acthd -= 4; 2352a24a11e6SChris Wilson if (acthd < acthd_min) 23536274f212SChris Wilson return NULL; 2354a24a11e6SChris Wilson } while (1); 2355a24a11e6SChris Wilson 23566274f212SChris Wilson *seqno = ioread32(ring->virtual_start+acthd+4)+1; 23576274f212SChris Wilson return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3]; 2358a24a11e6SChris Wilson } 2359a24a11e6SChris Wilson 23606274f212SChris Wilson static int semaphore_passed(struct intel_ring_buffer *ring) 23616274f212SChris Wilson { 23626274f212SChris Wilson struct drm_i915_private *dev_priv = ring->dev->dev_private; 23636274f212SChris Wilson struct intel_ring_buffer *signaller; 23646274f212SChris Wilson u32 seqno, ctl; 23656274f212SChris Wilson 23666274f212SChris Wilson ring->hangcheck.deadlock = true; 23676274f212SChris Wilson 23686274f212SChris Wilson signaller = semaphore_waits_for(ring, &seqno); 23696274f212SChris Wilson if (signaller == NULL || signaller->hangcheck.deadlock) 23706274f212SChris Wilson return -1; 23716274f212SChris Wilson 23726274f212SChris Wilson /* cursory check for an unkickable deadlock */ 23736274f212SChris Wilson ctl = I915_READ_CTL(signaller); 23746274f212SChris Wilson if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0) 23756274f212SChris Wilson return -1; 23766274f212SChris Wilson 23776274f212SChris Wilson return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno); 23786274f212SChris Wilson } 23796274f212SChris Wilson 23806274f212SChris Wilson static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv) 23816274f212SChris Wilson { 23826274f212SChris Wilson struct intel_ring_buffer *ring; 23836274f212SChris Wilson int i; 23846274f212SChris Wilson 23856274f212SChris Wilson for_each_ring(ring, dev_priv, i) 23866274f212SChris Wilson ring->hangcheck.deadlock = false; 23876274f212SChris Wilson } 23886274f212SChris Wilson 2389ad8beaeaSMika Kuoppala static enum intel_ring_hangcheck_action 2390ad8beaeaSMika Kuoppala ring_stuck(struct intel_ring_buffer *ring, u32 acthd) 23911ec14ad3SChris Wilson { 23921ec14ad3SChris Wilson struct drm_device *dev = ring->dev; 23931ec14ad3SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 23949107e9d2SChris Wilson u32 tmp; 23959107e9d2SChris Wilson 23966274f212SChris Wilson if (ring->hangcheck.acthd != acthd) 23976274f212SChris Wilson return active; 23986274f212SChris Wilson 23999107e9d2SChris Wilson if (IS_GEN2(dev)) 24006274f212SChris Wilson return hung; 24019107e9d2SChris Wilson 24029107e9d2SChris Wilson /* Is the chip hanging on a WAIT_FOR_EVENT? 24039107e9d2SChris Wilson * If so we can simply poke the RB_WAIT bit 24049107e9d2SChris Wilson * and break the hang. This should work on 24059107e9d2SChris Wilson * all but the second generation chipsets. 24069107e9d2SChris Wilson */ 24079107e9d2SChris Wilson tmp = I915_READ_CTL(ring); 24081ec14ad3SChris Wilson if (tmp & RING_WAIT) { 24091ec14ad3SChris Wilson DRM_ERROR("Kicking stuck wait on %s\n", 24101ec14ad3SChris Wilson ring->name); 24111ec14ad3SChris Wilson I915_WRITE_CTL(ring, tmp); 24126274f212SChris Wilson return kick; 24131ec14ad3SChris Wilson } 2414a24a11e6SChris Wilson 24156274f212SChris Wilson if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) { 24166274f212SChris Wilson switch (semaphore_passed(ring)) { 24176274f212SChris Wilson default: 24186274f212SChris Wilson return hung; 24196274f212SChris Wilson case 1: 2420a24a11e6SChris Wilson DRM_ERROR("Kicking stuck semaphore on %s\n", 2421a24a11e6SChris Wilson ring->name); 2422a24a11e6SChris Wilson I915_WRITE_CTL(ring, tmp); 24236274f212SChris Wilson return kick; 24246274f212SChris Wilson case 0: 24256274f212SChris Wilson return wait; 24266274f212SChris Wilson } 24279107e9d2SChris Wilson } 24289107e9d2SChris Wilson 24296274f212SChris Wilson return hung; 2430a24a11e6SChris Wilson } 2431d1e61e7fSChris Wilson 2432f65d9421SBen Gamari /** 2433f65d9421SBen Gamari * This is called when the chip hasn't reported back with completed 243405407ff8SMika Kuoppala * batchbuffers in a long time. We keep track per ring seqno progress and 243505407ff8SMika Kuoppala * if there are no progress, hangcheck score for that ring is increased. 243605407ff8SMika Kuoppala * Further, acthd is inspected to see if the ring is stuck. On stuck case 243705407ff8SMika Kuoppala * we kick the ring. If we see no progress on three subsequent calls 243805407ff8SMika Kuoppala * we assume chip is wedged and try to fix it by resetting the chip. 2439f65d9421SBen Gamari */ 2440f65d9421SBen Gamari void i915_hangcheck_elapsed(unsigned long data) 2441f65d9421SBen Gamari { 2442f65d9421SBen Gamari struct drm_device *dev = (struct drm_device *)data; 2443f65d9421SBen Gamari drm_i915_private_t *dev_priv = dev->dev_private; 2444b4519513SChris Wilson struct intel_ring_buffer *ring; 2445b4519513SChris Wilson int i; 244605407ff8SMika Kuoppala int busy_count = 0, rings_hung = 0; 24479107e9d2SChris Wilson bool stuck[I915_NUM_RINGS] = { 0 }; 24489107e9d2SChris Wilson #define BUSY 1 24499107e9d2SChris Wilson #define KICK 5 24509107e9d2SChris Wilson #define HUNG 20 24519107e9d2SChris Wilson #define FIRE 30 2452893eead0SChris Wilson 24533e0dc6b0SBen Widawsky if (!i915_enable_hangcheck) 24543e0dc6b0SBen Widawsky return; 24553e0dc6b0SBen Widawsky 2456b4519513SChris Wilson for_each_ring(ring, dev_priv, i) { 245705407ff8SMika Kuoppala u32 seqno, acthd; 24589107e9d2SChris Wilson bool busy = true; 2459b4519513SChris Wilson 24606274f212SChris Wilson semaphore_clear_deadlocks(dev_priv); 24616274f212SChris Wilson 246205407ff8SMika Kuoppala seqno = ring->get_seqno(ring, false); 246305407ff8SMika Kuoppala acthd = intel_ring_get_active_head(ring); 246405407ff8SMika Kuoppala 246505407ff8SMika Kuoppala if (ring->hangcheck.seqno == seqno) { 24669107e9d2SChris Wilson if (ring_idle(ring, seqno)) { 24679107e9d2SChris Wilson if (waitqueue_active(&ring->irq_queue)) { 24689107e9d2SChris Wilson /* Issue a wake-up to catch stuck h/w. */ 24699107e9d2SChris Wilson DRM_ERROR("Hangcheck timer elapsed... %s idle\n", 24709107e9d2SChris Wilson ring->name); 24719107e9d2SChris Wilson wake_up_all(&ring->irq_queue); 24729107e9d2SChris Wilson ring->hangcheck.score += HUNG; 24739107e9d2SChris Wilson } else 24749107e9d2SChris Wilson busy = false; 247505407ff8SMika Kuoppala } else { 24769107e9d2SChris Wilson int score; 24779107e9d2SChris Wilson 24786274f212SChris Wilson /* We always increment the hangcheck score 24796274f212SChris Wilson * if the ring is busy and still processing 24806274f212SChris Wilson * the same request, so that no single request 24816274f212SChris Wilson * can run indefinitely (such as a chain of 24826274f212SChris Wilson * batches). The only time we do not increment 24836274f212SChris Wilson * the hangcheck score on this ring, if this 24846274f212SChris Wilson * ring is in a legitimate wait for another 24856274f212SChris Wilson * ring. In that case the waiting ring is a 24866274f212SChris Wilson * victim and we want to be sure we catch the 24876274f212SChris Wilson * right culprit. Then every time we do kick 24886274f212SChris Wilson * the ring, add a small increment to the 24896274f212SChris Wilson * score so that we can catch a batch that is 24906274f212SChris Wilson * being repeatedly kicked and so responsible 24916274f212SChris Wilson * for stalling the machine. 24929107e9d2SChris Wilson */ 2493ad8beaeaSMika Kuoppala ring->hangcheck.action = ring_stuck(ring, 2494ad8beaeaSMika Kuoppala acthd); 2495ad8beaeaSMika Kuoppala 2496ad8beaeaSMika Kuoppala switch (ring->hangcheck.action) { 24976274f212SChris Wilson case wait: 24986274f212SChris Wilson score = 0; 24996274f212SChris Wilson break; 25006274f212SChris Wilson case active: 25019107e9d2SChris Wilson score = BUSY; 25026274f212SChris Wilson break; 25036274f212SChris Wilson case kick: 25046274f212SChris Wilson score = KICK; 25056274f212SChris Wilson break; 25066274f212SChris Wilson case hung: 25076274f212SChris Wilson score = HUNG; 25086274f212SChris Wilson stuck[i] = true; 25096274f212SChris Wilson break; 25106274f212SChris Wilson } 25119107e9d2SChris Wilson ring->hangcheck.score += score; 251205407ff8SMika Kuoppala } 25139107e9d2SChris Wilson } else { 25149107e9d2SChris Wilson /* Gradually reduce the count so that we catch DoS 25159107e9d2SChris Wilson * attempts across multiple batches. 25169107e9d2SChris Wilson */ 25179107e9d2SChris Wilson if (ring->hangcheck.score > 0) 25189107e9d2SChris Wilson ring->hangcheck.score--; 2519cbb465e7SChris Wilson } 2520f65d9421SBen Gamari 252105407ff8SMika Kuoppala ring->hangcheck.seqno = seqno; 252205407ff8SMika Kuoppala ring->hangcheck.acthd = acthd; 25239107e9d2SChris Wilson busy_count += busy; 252405407ff8SMika Kuoppala } 252505407ff8SMika Kuoppala 252605407ff8SMika Kuoppala for_each_ring(ring, dev_priv, i) { 25279107e9d2SChris Wilson if (ring->hangcheck.score > FIRE) { 2528acd78c11SBen Widawsky DRM_ERROR("%s on %s\n", 252905407ff8SMika Kuoppala stuck[i] ? "stuck" : "no progress", 2530a43adf07SChris Wilson ring->name); 2531a43adf07SChris Wilson rings_hung++; 253205407ff8SMika Kuoppala } 253305407ff8SMika Kuoppala } 253405407ff8SMika Kuoppala 253505407ff8SMika Kuoppala if (rings_hung) 253605407ff8SMika Kuoppala return i915_handle_error(dev, true); 253705407ff8SMika Kuoppala 253805407ff8SMika Kuoppala if (busy_count) 253905407ff8SMika Kuoppala /* Reset timer case chip hangs without another request 254005407ff8SMika Kuoppala * being added */ 254199584db3SDaniel Vetter mod_timer(&dev_priv->gpu_error.hangcheck_timer, 254205407ff8SMika Kuoppala round_jiffies_up(jiffies + 254305407ff8SMika Kuoppala DRM_I915_HANGCHECK_JIFFIES)); 2544f65d9421SBen Gamari } 2545f65d9421SBen Gamari 254691738a95SPaulo Zanoni static void ibx_irq_preinstall(struct drm_device *dev) 254791738a95SPaulo Zanoni { 254891738a95SPaulo Zanoni struct drm_i915_private *dev_priv = dev->dev_private; 254991738a95SPaulo Zanoni 255091738a95SPaulo Zanoni if (HAS_PCH_NOP(dev)) 255191738a95SPaulo Zanoni return; 255291738a95SPaulo Zanoni 255391738a95SPaulo Zanoni /* south display irq */ 255491738a95SPaulo Zanoni I915_WRITE(SDEIMR, 0xffffffff); 255591738a95SPaulo Zanoni /* 255691738a95SPaulo Zanoni * SDEIER is also touched by the interrupt handler to work around missed 255791738a95SPaulo Zanoni * PCH interrupts. Hence we can't update it after the interrupt handler 255891738a95SPaulo Zanoni * is enabled - instead we unconditionally enable all PCH interrupt 255991738a95SPaulo Zanoni * sources here, but then only unmask them as needed with SDEIMR. 256091738a95SPaulo Zanoni */ 256191738a95SPaulo Zanoni I915_WRITE(SDEIER, 0xffffffff); 256291738a95SPaulo Zanoni POSTING_READ(SDEIER); 256391738a95SPaulo Zanoni } 256491738a95SPaulo Zanoni 2565c0e09200SDave Airlie /* drm_dma.h hooks 2566c0e09200SDave Airlie */ 2567f71d4af4SJesse Barnes static void ironlake_irq_preinstall(struct drm_device *dev) 2568036a4a7dSZhenyu Wang { 2569036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2570036a4a7dSZhenyu Wang 25714697995bSJesse Barnes atomic_set(&dev_priv->irq_received, 0); 25724697995bSJesse Barnes 2573036a4a7dSZhenyu Wang I915_WRITE(HWSTAM, 0xeffe); 2574bdfcdb63SDaniel Vetter 2575036a4a7dSZhenyu Wang /* XXX hotplug from PCH */ 2576036a4a7dSZhenyu Wang 2577036a4a7dSZhenyu Wang I915_WRITE(DEIMR, 0xffffffff); 2578036a4a7dSZhenyu Wang I915_WRITE(DEIER, 0x0); 25793143a2bfSChris Wilson POSTING_READ(DEIER); 2580036a4a7dSZhenyu Wang 2581036a4a7dSZhenyu Wang /* and GT */ 2582036a4a7dSZhenyu Wang I915_WRITE(GTIMR, 0xffffffff); 2583036a4a7dSZhenyu Wang I915_WRITE(GTIER, 0x0); 25843143a2bfSChris Wilson POSTING_READ(GTIER); 2585c650156aSZhenyu Wang 258691738a95SPaulo Zanoni ibx_irq_preinstall(dev); 25877d99163dSBen Widawsky } 25887d99163dSBen Widawsky 25897d99163dSBen Widawsky static void ivybridge_irq_preinstall(struct drm_device *dev) 25907d99163dSBen Widawsky { 25917d99163dSBen Widawsky drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 25927d99163dSBen Widawsky 25937d99163dSBen Widawsky atomic_set(&dev_priv->irq_received, 0); 25947d99163dSBen Widawsky 25957d99163dSBen Widawsky I915_WRITE(HWSTAM, 0xeffe); 25967d99163dSBen Widawsky 25977d99163dSBen Widawsky /* XXX hotplug from PCH */ 25987d99163dSBen Widawsky 25997d99163dSBen Widawsky I915_WRITE(DEIMR, 0xffffffff); 26007d99163dSBen Widawsky I915_WRITE(DEIER, 0x0); 26017d99163dSBen Widawsky POSTING_READ(DEIER); 26027d99163dSBen Widawsky 26037d99163dSBen Widawsky /* and GT */ 26047d99163dSBen Widawsky I915_WRITE(GTIMR, 0xffffffff); 26057d99163dSBen Widawsky I915_WRITE(GTIER, 0x0); 26067d99163dSBen Widawsky POSTING_READ(GTIER); 26077d99163dSBen Widawsky 2608eda63ffbSBen Widawsky /* Power management */ 2609eda63ffbSBen Widawsky I915_WRITE(GEN6_PMIMR, 0xffffffff); 2610eda63ffbSBen Widawsky I915_WRITE(GEN6_PMIER, 0x0); 2611eda63ffbSBen Widawsky POSTING_READ(GEN6_PMIER); 2612eda63ffbSBen Widawsky 261391738a95SPaulo Zanoni ibx_irq_preinstall(dev); 2614036a4a7dSZhenyu Wang } 2615036a4a7dSZhenyu Wang 26167e231dbeSJesse Barnes static void valleyview_irq_preinstall(struct drm_device *dev) 26177e231dbeSJesse Barnes { 26187e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 26197e231dbeSJesse Barnes int pipe; 26207e231dbeSJesse Barnes 26217e231dbeSJesse Barnes atomic_set(&dev_priv->irq_received, 0); 26227e231dbeSJesse Barnes 26237e231dbeSJesse Barnes /* VLV magic */ 26247e231dbeSJesse Barnes I915_WRITE(VLV_IMR, 0); 26257e231dbeSJesse Barnes I915_WRITE(RING_IMR(RENDER_RING_BASE), 0); 26267e231dbeSJesse Barnes I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0); 26277e231dbeSJesse Barnes I915_WRITE(RING_IMR(BLT_RING_BASE), 0); 26287e231dbeSJesse Barnes 26297e231dbeSJesse Barnes /* and GT */ 26307e231dbeSJesse Barnes I915_WRITE(GTIIR, I915_READ(GTIIR)); 26317e231dbeSJesse Barnes I915_WRITE(GTIIR, I915_READ(GTIIR)); 26327e231dbeSJesse Barnes I915_WRITE(GTIMR, 0xffffffff); 26337e231dbeSJesse Barnes I915_WRITE(GTIER, 0x0); 26347e231dbeSJesse Barnes POSTING_READ(GTIER); 26357e231dbeSJesse Barnes 26367e231dbeSJesse Barnes I915_WRITE(DPINVGTT, 0xff); 26377e231dbeSJesse Barnes 26387e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_EN, 0); 26397e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 26407e231dbeSJesse Barnes for_each_pipe(pipe) 26417e231dbeSJesse Barnes I915_WRITE(PIPESTAT(pipe), 0xffff); 26427e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 26437e231dbeSJesse Barnes I915_WRITE(VLV_IMR, 0xffffffff); 26447e231dbeSJesse Barnes I915_WRITE(VLV_IER, 0x0); 26457e231dbeSJesse Barnes POSTING_READ(VLV_IER); 26467e231dbeSJesse Barnes } 26477e231dbeSJesse Barnes 264882a28bcfSDaniel Vetter static void ibx_hpd_irq_setup(struct drm_device *dev) 264982a28bcfSDaniel Vetter { 265082a28bcfSDaniel Vetter drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 265182a28bcfSDaniel Vetter struct drm_mode_config *mode_config = &dev->mode_config; 265282a28bcfSDaniel Vetter struct intel_encoder *intel_encoder; 265382a28bcfSDaniel Vetter u32 mask = ~I915_READ(SDEIMR); 265482a28bcfSDaniel Vetter u32 hotplug; 265582a28bcfSDaniel Vetter 265682a28bcfSDaniel Vetter if (HAS_PCH_IBX(dev)) { 2657995e6b3dSEgbert Eich mask &= ~SDE_HOTPLUG_MASK; 265882a28bcfSDaniel Vetter list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head) 2659cd569aedSEgbert Eich if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) 266082a28bcfSDaniel Vetter mask |= hpd_ibx[intel_encoder->hpd_pin]; 266182a28bcfSDaniel Vetter } else { 2662995e6b3dSEgbert Eich mask &= ~SDE_HOTPLUG_MASK_CPT; 266382a28bcfSDaniel Vetter list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head) 2664cd569aedSEgbert Eich if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) 266582a28bcfSDaniel Vetter mask |= hpd_cpt[intel_encoder->hpd_pin]; 266682a28bcfSDaniel Vetter } 266782a28bcfSDaniel Vetter 266882a28bcfSDaniel Vetter I915_WRITE(SDEIMR, ~mask); 266982a28bcfSDaniel Vetter 26707fe0b973SKeith Packard /* 26717fe0b973SKeith Packard * Enable digital hotplug on the PCH, and configure the DP short pulse 26727fe0b973SKeith Packard * duration to 2ms (which is the minimum in the Display Port spec) 26737fe0b973SKeith Packard * 26747fe0b973SKeith Packard * This register is the same on all known PCH chips. 26757fe0b973SKeith Packard */ 26767fe0b973SKeith Packard hotplug = I915_READ(PCH_PORT_HOTPLUG); 26777fe0b973SKeith Packard hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK); 26787fe0b973SKeith Packard hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms; 26797fe0b973SKeith Packard hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms; 26807fe0b973SKeith Packard hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms; 26817fe0b973SKeith Packard I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 26827fe0b973SKeith Packard } 26837fe0b973SKeith Packard 2684d46da437SPaulo Zanoni static void ibx_irq_postinstall(struct drm_device *dev) 2685d46da437SPaulo Zanoni { 2686d46da437SPaulo Zanoni drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 268782a28bcfSDaniel Vetter u32 mask; 2688d46da437SPaulo Zanoni 2689692a04cfSDaniel Vetter if (HAS_PCH_NOP(dev)) 2690692a04cfSDaniel Vetter return; 2691692a04cfSDaniel Vetter 26928664281bSPaulo Zanoni if (HAS_PCH_IBX(dev)) { 26938664281bSPaulo Zanoni mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER | 2694de032bf4SPaulo Zanoni SDE_TRANSA_FIFO_UNDER | SDE_POISON; 26958664281bSPaulo Zanoni } else { 26968664281bSPaulo Zanoni mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT; 26978664281bSPaulo Zanoni 26988664281bSPaulo Zanoni I915_WRITE(SERR_INT, I915_READ(SERR_INT)); 26998664281bSPaulo Zanoni } 2700ab5c608bSBen Widawsky 2701d46da437SPaulo Zanoni I915_WRITE(SDEIIR, I915_READ(SDEIIR)); 2702d46da437SPaulo Zanoni I915_WRITE(SDEIMR, ~mask); 2703d46da437SPaulo Zanoni } 2704d46da437SPaulo Zanoni 2705f71d4af4SJesse Barnes static int ironlake_irq_postinstall(struct drm_device *dev) 2706036a4a7dSZhenyu Wang { 27074bc9d430SDaniel Vetter unsigned long irqflags; 27084bc9d430SDaniel Vetter 2709036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2710036a4a7dSZhenyu Wang /* enable kind of interrupts always enabled */ 2711013d5aa2SJesse Barnes u32 display_mask = DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | 2712ce99c256SDaniel Vetter DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE | 27138664281bSPaulo Zanoni DE_AUX_CHANNEL_A | DE_PIPEB_FIFO_UNDERRUN | 2714de032bf4SPaulo Zanoni DE_PIPEA_FIFO_UNDERRUN | DE_POISON; 2715cc609d5dSBen Widawsky u32 gt_irqs; 2716036a4a7dSZhenyu Wang 27171ec14ad3SChris Wilson dev_priv->irq_mask = ~display_mask; 2718036a4a7dSZhenyu Wang 2719036a4a7dSZhenyu Wang /* should always can generate irq */ 2720036a4a7dSZhenyu Wang I915_WRITE(DEIIR, I915_READ(DEIIR)); 27211ec14ad3SChris Wilson I915_WRITE(DEIMR, dev_priv->irq_mask); 27226005ce42SDaniel Vetter I915_WRITE(DEIER, display_mask | 27236005ce42SDaniel Vetter DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT); 27243143a2bfSChris Wilson POSTING_READ(DEIER); 2725036a4a7dSZhenyu Wang 27261ec14ad3SChris Wilson dev_priv->gt_irq_mask = ~0; 2727036a4a7dSZhenyu Wang 2728036a4a7dSZhenyu Wang I915_WRITE(GTIIR, I915_READ(GTIIR)); 27291ec14ad3SChris Wilson I915_WRITE(GTIMR, dev_priv->gt_irq_mask); 2730881f47b6SXiang, Haihao 2731cc609d5dSBen Widawsky gt_irqs = GT_RENDER_USER_INTERRUPT; 2732cc609d5dSBen Widawsky 27331ec14ad3SChris Wilson if (IS_GEN6(dev)) 2734cc609d5dSBen Widawsky gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT; 27351ec14ad3SChris Wilson else 2736cc609d5dSBen Widawsky gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT | 2737cc609d5dSBen Widawsky ILK_BSD_USER_INTERRUPT; 2738cc609d5dSBen Widawsky 2739cc609d5dSBen Widawsky I915_WRITE(GTIER, gt_irqs); 27403143a2bfSChris Wilson POSTING_READ(GTIER); 2741036a4a7dSZhenyu Wang 2742d46da437SPaulo Zanoni ibx_irq_postinstall(dev); 27437fe0b973SKeith Packard 2744f97108d1SJesse Barnes if (IS_IRONLAKE_M(dev)) { 27456005ce42SDaniel Vetter /* Enable PCU event interrupts 27466005ce42SDaniel Vetter * 27476005ce42SDaniel Vetter * spinlocking not required here for correctness since interrupt 27484bc9d430SDaniel Vetter * setup is guaranteed to run in single-threaded context. But we 27494bc9d430SDaniel Vetter * need it to make the assert_spin_locked happy. */ 27504bc9d430SDaniel Vetter spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2751f97108d1SJesse Barnes ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT); 27524bc9d430SDaniel Vetter spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2753f97108d1SJesse Barnes } 2754f97108d1SJesse Barnes 2755036a4a7dSZhenyu Wang return 0; 2756036a4a7dSZhenyu Wang } 2757036a4a7dSZhenyu Wang 2758f71d4af4SJesse Barnes static int ivybridge_irq_postinstall(struct drm_device *dev) 2759b1f14ad0SJesse Barnes { 2760b1f14ad0SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2761b1f14ad0SJesse Barnes /* enable kind of interrupts always enabled */ 2762b615b57aSChris Wilson u32 display_mask = 2763b615b57aSChris Wilson DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | DE_PCH_EVENT_IVB | 2764b615b57aSChris Wilson DE_PLANEC_FLIP_DONE_IVB | 2765b615b57aSChris Wilson DE_PLANEB_FLIP_DONE_IVB | 2766ce99c256SDaniel Vetter DE_PLANEA_FLIP_DONE_IVB | 27678664281bSPaulo Zanoni DE_AUX_CHANNEL_A_IVB | 27688664281bSPaulo Zanoni DE_ERR_INT_IVB; 276912638c57SBen Widawsky u32 pm_irqs = GEN6_PM_RPS_EVENTS; 2770cc609d5dSBen Widawsky u32 gt_irqs; 2771b1f14ad0SJesse Barnes 2772b1f14ad0SJesse Barnes dev_priv->irq_mask = ~display_mask; 2773b1f14ad0SJesse Barnes 2774b1f14ad0SJesse Barnes /* should always can generate irq */ 27758664281bSPaulo Zanoni I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT)); 2776b1f14ad0SJesse Barnes I915_WRITE(DEIIR, I915_READ(DEIIR)); 2777b1f14ad0SJesse Barnes I915_WRITE(DEIMR, dev_priv->irq_mask); 2778b615b57aSChris Wilson I915_WRITE(DEIER, 2779b615b57aSChris Wilson display_mask | 2780b615b57aSChris Wilson DE_PIPEC_VBLANK_IVB | 2781b615b57aSChris Wilson DE_PIPEB_VBLANK_IVB | 2782b615b57aSChris Wilson DE_PIPEA_VBLANK_IVB); 2783b1f14ad0SJesse Barnes POSTING_READ(DEIER); 2784b1f14ad0SJesse Barnes 2785cc609d5dSBen Widawsky dev_priv->gt_irq_mask = ~GT_RENDER_L3_PARITY_ERROR_INTERRUPT; 2786b1f14ad0SJesse Barnes 2787b1f14ad0SJesse Barnes I915_WRITE(GTIIR, I915_READ(GTIIR)); 2788b1f14ad0SJesse Barnes I915_WRITE(GTIMR, dev_priv->gt_irq_mask); 2789b1f14ad0SJesse Barnes 2790cc609d5dSBen Widawsky gt_irqs = GT_RENDER_USER_INTERRUPT | GT_BSD_USER_INTERRUPT | 2791cc609d5dSBen Widawsky GT_BLT_USER_INTERRUPT | GT_RENDER_L3_PARITY_ERROR_INTERRUPT; 2792cc609d5dSBen Widawsky I915_WRITE(GTIER, gt_irqs); 2793b1f14ad0SJesse Barnes POSTING_READ(GTIER); 2794b1f14ad0SJesse Barnes 279512638c57SBen Widawsky I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR)); 279612638c57SBen Widawsky if (HAS_VEBOX(dev)) 279712638c57SBen Widawsky pm_irqs |= PM_VEBOX_USER_INTERRUPT | 279812638c57SBen Widawsky PM_VEBOX_CS_ERROR_INTERRUPT; 279912638c57SBen Widawsky 280012638c57SBen Widawsky /* Our enable/disable rps functions may touch these registers so 280112638c57SBen Widawsky * make sure to set a known state for only the non-RPS bits. 280212638c57SBen Widawsky * The RMW is extra paranoia since this should be called after being set 280312638c57SBen Widawsky * to a known state in preinstall. 280412638c57SBen Widawsky * */ 280512638c57SBen Widawsky I915_WRITE(GEN6_PMIMR, 280612638c57SBen Widawsky (I915_READ(GEN6_PMIMR) | ~GEN6_PM_RPS_EVENTS) & ~pm_irqs); 280712638c57SBen Widawsky I915_WRITE(GEN6_PMIER, 280812638c57SBen Widawsky (I915_READ(GEN6_PMIER) & GEN6_PM_RPS_EVENTS) | pm_irqs); 280912638c57SBen Widawsky POSTING_READ(GEN6_PMIER); 2810eda63ffbSBen Widawsky 2811d46da437SPaulo Zanoni ibx_irq_postinstall(dev); 28127fe0b973SKeith Packard 2813b1f14ad0SJesse Barnes return 0; 2814b1f14ad0SJesse Barnes } 2815b1f14ad0SJesse Barnes 28167e231dbeSJesse Barnes static int valleyview_irq_postinstall(struct drm_device *dev) 28177e231dbeSJesse Barnes { 28187e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2819cc609d5dSBen Widawsky u32 gt_irqs; 28207e231dbeSJesse Barnes u32 enable_mask; 282131acc7f5SJesse Barnes u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV; 28227e231dbeSJesse Barnes 28237e231dbeSJesse Barnes enable_mask = I915_DISPLAY_PORT_INTERRUPT; 282431acc7f5SJesse Barnes enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 282531acc7f5SJesse Barnes I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT | 282631acc7f5SJesse Barnes I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 28277e231dbeSJesse Barnes I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; 28287e231dbeSJesse Barnes 282931acc7f5SJesse Barnes /* 283031acc7f5SJesse Barnes *Leave vblank interrupts masked initially. enable/disable will 283131acc7f5SJesse Barnes * toggle them based on usage. 283231acc7f5SJesse Barnes */ 283331acc7f5SJesse Barnes dev_priv->irq_mask = (~enable_mask) | 283431acc7f5SJesse Barnes I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT | 283531acc7f5SJesse Barnes I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; 28367e231dbeSJesse Barnes 283720afbda2SDaniel Vetter I915_WRITE(PORT_HOTPLUG_EN, 0); 283820afbda2SDaniel Vetter POSTING_READ(PORT_HOTPLUG_EN); 283920afbda2SDaniel Vetter 28407e231dbeSJesse Barnes I915_WRITE(VLV_IMR, dev_priv->irq_mask); 28417e231dbeSJesse Barnes I915_WRITE(VLV_IER, enable_mask); 28427e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 28437e231dbeSJesse Barnes I915_WRITE(PIPESTAT(0), 0xffff); 28447e231dbeSJesse Barnes I915_WRITE(PIPESTAT(1), 0xffff); 28457e231dbeSJesse Barnes POSTING_READ(VLV_IER); 28467e231dbeSJesse Barnes 284731acc7f5SJesse Barnes i915_enable_pipestat(dev_priv, 0, pipestat_enable); 2848515ac2bbSDaniel Vetter i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE); 284931acc7f5SJesse Barnes i915_enable_pipestat(dev_priv, 1, pipestat_enable); 285031acc7f5SJesse Barnes 28517e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 28527e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 28537e231dbeSJesse Barnes 285431acc7f5SJesse Barnes I915_WRITE(GTIIR, I915_READ(GTIIR)); 285531acc7f5SJesse Barnes I915_WRITE(GTIMR, dev_priv->gt_irq_mask); 28563bcedbe5SJesse Barnes 2857cc609d5dSBen Widawsky gt_irqs = GT_RENDER_USER_INTERRUPT | GT_BSD_USER_INTERRUPT | 2858cc609d5dSBen Widawsky GT_BLT_USER_INTERRUPT; 2859cc609d5dSBen Widawsky I915_WRITE(GTIER, gt_irqs); 28607e231dbeSJesse Barnes POSTING_READ(GTIER); 28617e231dbeSJesse Barnes 28627e231dbeSJesse Barnes /* ack & enable invalid PTE error interrupts */ 28637e231dbeSJesse Barnes #if 0 /* FIXME: add support to irq handler for checking these bits */ 28647e231dbeSJesse Barnes I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK); 28657e231dbeSJesse Barnes I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK); 28667e231dbeSJesse Barnes #endif 28677e231dbeSJesse Barnes 28687e231dbeSJesse Barnes I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE); 286920afbda2SDaniel Vetter 287020afbda2SDaniel Vetter return 0; 287120afbda2SDaniel Vetter } 287220afbda2SDaniel Vetter 28737e231dbeSJesse Barnes static void valleyview_irq_uninstall(struct drm_device *dev) 28747e231dbeSJesse Barnes { 28757e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 28767e231dbeSJesse Barnes int pipe; 28777e231dbeSJesse Barnes 28787e231dbeSJesse Barnes if (!dev_priv) 28797e231dbeSJesse Barnes return; 28807e231dbeSJesse Barnes 2881ac4c16c5SEgbert Eich del_timer_sync(&dev_priv->hotplug_reenable_timer); 2882ac4c16c5SEgbert Eich 28837e231dbeSJesse Barnes for_each_pipe(pipe) 28847e231dbeSJesse Barnes I915_WRITE(PIPESTAT(pipe), 0xffff); 28857e231dbeSJesse Barnes 28867e231dbeSJesse Barnes I915_WRITE(HWSTAM, 0xffffffff); 28877e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_EN, 0); 28887e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 28897e231dbeSJesse Barnes for_each_pipe(pipe) 28907e231dbeSJesse Barnes I915_WRITE(PIPESTAT(pipe), 0xffff); 28917e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 28927e231dbeSJesse Barnes I915_WRITE(VLV_IMR, 0xffffffff); 28937e231dbeSJesse Barnes I915_WRITE(VLV_IER, 0x0); 28947e231dbeSJesse Barnes POSTING_READ(VLV_IER); 28957e231dbeSJesse Barnes } 28967e231dbeSJesse Barnes 2897f71d4af4SJesse Barnes static void ironlake_irq_uninstall(struct drm_device *dev) 2898036a4a7dSZhenyu Wang { 2899036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 29004697995bSJesse Barnes 29014697995bSJesse Barnes if (!dev_priv) 29024697995bSJesse Barnes return; 29034697995bSJesse Barnes 2904ac4c16c5SEgbert Eich del_timer_sync(&dev_priv->hotplug_reenable_timer); 2905ac4c16c5SEgbert Eich 2906036a4a7dSZhenyu Wang I915_WRITE(HWSTAM, 0xffffffff); 2907036a4a7dSZhenyu Wang 2908036a4a7dSZhenyu Wang I915_WRITE(DEIMR, 0xffffffff); 2909036a4a7dSZhenyu Wang I915_WRITE(DEIER, 0x0); 2910036a4a7dSZhenyu Wang I915_WRITE(DEIIR, I915_READ(DEIIR)); 29118664281bSPaulo Zanoni if (IS_GEN7(dev)) 29128664281bSPaulo Zanoni I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT)); 2913036a4a7dSZhenyu Wang 2914036a4a7dSZhenyu Wang I915_WRITE(GTIMR, 0xffffffff); 2915036a4a7dSZhenyu Wang I915_WRITE(GTIER, 0x0); 2916036a4a7dSZhenyu Wang I915_WRITE(GTIIR, I915_READ(GTIIR)); 2917192aac1fSKeith Packard 2918ab5c608bSBen Widawsky if (HAS_PCH_NOP(dev)) 2919ab5c608bSBen Widawsky return; 2920ab5c608bSBen Widawsky 2921192aac1fSKeith Packard I915_WRITE(SDEIMR, 0xffffffff); 2922192aac1fSKeith Packard I915_WRITE(SDEIER, 0x0); 2923192aac1fSKeith Packard I915_WRITE(SDEIIR, I915_READ(SDEIIR)); 29248664281bSPaulo Zanoni if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev)) 29258664281bSPaulo Zanoni I915_WRITE(SERR_INT, I915_READ(SERR_INT)); 2926036a4a7dSZhenyu Wang } 2927036a4a7dSZhenyu Wang 2928c2798b19SChris Wilson static void i8xx_irq_preinstall(struct drm_device * dev) 2929c2798b19SChris Wilson { 2930c2798b19SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2931c2798b19SChris Wilson int pipe; 2932c2798b19SChris Wilson 2933c2798b19SChris Wilson atomic_set(&dev_priv->irq_received, 0); 2934c2798b19SChris Wilson 2935c2798b19SChris Wilson for_each_pipe(pipe) 2936c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 2937c2798b19SChris Wilson I915_WRITE16(IMR, 0xffff); 2938c2798b19SChris Wilson I915_WRITE16(IER, 0x0); 2939c2798b19SChris Wilson POSTING_READ16(IER); 2940c2798b19SChris Wilson } 2941c2798b19SChris Wilson 2942c2798b19SChris Wilson static int i8xx_irq_postinstall(struct drm_device *dev) 2943c2798b19SChris Wilson { 2944c2798b19SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2945c2798b19SChris Wilson 2946c2798b19SChris Wilson I915_WRITE16(EMR, 2947c2798b19SChris Wilson ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH)); 2948c2798b19SChris Wilson 2949c2798b19SChris Wilson /* Unmask the interrupts that we always want on. */ 2950c2798b19SChris Wilson dev_priv->irq_mask = 2951c2798b19SChris Wilson ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 2952c2798b19SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 2953c2798b19SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 2954c2798b19SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | 2955c2798b19SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 2956c2798b19SChris Wilson I915_WRITE16(IMR, dev_priv->irq_mask); 2957c2798b19SChris Wilson 2958c2798b19SChris Wilson I915_WRITE16(IER, 2959c2798b19SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 2960c2798b19SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 2961c2798b19SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT | 2962c2798b19SChris Wilson I915_USER_INTERRUPT); 2963c2798b19SChris Wilson POSTING_READ16(IER); 2964c2798b19SChris Wilson 2965c2798b19SChris Wilson return 0; 2966c2798b19SChris Wilson } 2967c2798b19SChris Wilson 296890a72f87SVille Syrjälä /* 296990a72f87SVille Syrjälä * Returns true when a page flip has completed. 297090a72f87SVille Syrjälä */ 297190a72f87SVille Syrjälä static bool i8xx_handle_vblank(struct drm_device *dev, 297290a72f87SVille Syrjälä int pipe, u16 iir) 297390a72f87SVille Syrjälä { 297490a72f87SVille Syrjälä drm_i915_private_t *dev_priv = dev->dev_private; 297590a72f87SVille Syrjälä u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(pipe); 297690a72f87SVille Syrjälä 297790a72f87SVille Syrjälä if (!drm_handle_vblank(dev, pipe)) 297890a72f87SVille Syrjälä return false; 297990a72f87SVille Syrjälä 298090a72f87SVille Syrjälä if ((iir & flip_pending) == 0) 298190a72f87SVille Syrjälä return false; 298290a72f87SVille Syrjälä 298390a72f87SVille Syrjälä intel_prepare_page_flip(dev, pipe); 298490a72f87SVille Syrjälä 298590a72f87SVille Syrjälä /* We detect FlipDone by looking for the change in PendingFlip from '1' 298690a72f87SVille Syrjälä * to '0' on the following vblank, i.e. IIR has the Pendingflip 298790a72f87SVille Syrjälä * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence 298890a72f87SVille Syrjälä * the flip is completed (no longer pending). Since this doesn't raise 298990a72f87SVille Syrjälä * an interrupt per se, we watch for the change at vblank. 299090a72f87SVille Syrjälä */ 299190a72f87SVille Syrjälä if (I915_READ16(ISR) & flip_pending) 299290a72f87SVille Syrjälä return false; 299390a72f87SVille Syrjälä 299490a72f87SVille Syrjälä intel_finish_page_flip(dev, pipe); 299590a72f87SVille Syrjälä 299690a72f87SVille Syrjälä return true; 299790a72f87SVille Syrjälä } 299890a72f87SVille Syrjälä 2999ff1f525eSDaniel Vetter static irqreturn_t i8xx_irq_handler(int irq, void *arg) 3000c2798b19SChris Wilson { 3001c2798b19SChris Wilson struct drm_device *dev = (struct drm_device *) arg; 3002c2798b19SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 3003c2798b19SChris Wilson u16 iir, new_iir; 3004c2798b19SChris Wilson u32 pipe_stats[2]; 3005c2798b19SChris Wilson unsigned long irqflags; 3006c2798b19SChris Wilson int irq_received; 3007c2798b19SChris Wilson int pipe; 3008c2798b19SChris Wilson u16 flip_mask = 3009c2798b19SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 3010c2798b19SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 3011c2798b19SChris Wilson 3012c2798b19SChris Wilson atomic_inc(&dev_priv->irq_received); 3013c2798b19SChris Wilson 3014c2798b19SChris Wilson iir = I915_READ16(IIR); 3015c2798b19SChris Wilson if (iir == 0) 3016c2798b19SChris Wilson return IRQ_NONE; 3017c2798b19SChris Wilson 3018c2798b19SChris Wilson while (iir & ~flip_mask) { 3019c2798b19SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 3020c2798b19SChris Wilson * have been cleared after the pipestat interrupt was received. 3021c2798b19SChris Wilson * It doesn't set the bit in iir again, but it still produces 3022c2798b19SChris Wilson * interrupts (for non-MSI). 3023c2798b19SChris Wilson */ 3024c2798b19SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3025c2798b19SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 3026c2798b19SChris Wilson i915_handle_error(dev, false); 3027c2798b19SChris Wilson 3028c2798b19SChris Wilson for_each_pipe(pipe) { 3029c2798b19SChris Wilson int reg = PIPESTAT(pipe); 3030c2798b19SChris Wilson pipe_stats[pipe] = I915_READ(reg); 3031c2798b19SChris Wilson 3032c2798b19SChris Wilson /* 3033c2798b19SChris Wilson * Clear the PIPE*STAT regs before the IIR 3034c2798b19SChris Wilson */ 3035c2798b19SChris Wilson if (pipe_stats[pipe] & 0x8000ffff) { 3036c2798b19SChris Wilson if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 3037c2798b19SChris Wilson DRM_DEBUG_DRIVER("pipe %c underrun\n", 3038c2798b19SChris Wilson pipe_name(pipe)); 3039c2798b19SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 3040c2798b19SChris Wilson irq_received = 1; 3041c2798b19SChris Wilson } 3042c2798b19SChris Wilson } 3043c2798b19SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3044c2798b19SChris Wilson 3045c2798b19SChris Wilson I915_WRITE16(IIR, iir & ~flip_mask); 3046c2798b19SChris Wilson new_iir = I915_READ16(IIR); /* Flush posted writes */ 3047c2798b19SChris Wilson 3048d05c617eSDaniel Vetter i915_update_dri1_breadcrumb(dev); 3049c2798b19SChris Wilson 3050c2798b19SChris Wilson if (iir & I915_USER_INTERRUPT) 3051c2798b19SChris Wilson notify_ring(dev, &dev_priv->ring[RCS]); 3052c2798b19SChris Wilson 3053c2798b19SChris Wilson if (pipe_stats[0] & PIPE_VBLANK_INTERRUPT_STATUS && 305490a72f87SVille Syrjälä i8xx_handle_vblank(dev, 0, iir)) 305590a72f87SVille Syrjälä flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(0); 3056c2798b19SChris Wilson 3057c2798b19SChris Wilson if (pipe_stats[1] & PIPE_VBLANK_INTERRUPT_STATUS && 305890a72f87SVille Syrjälä i8xx_handle_vblank(dev, 1, iir)) 305990a72f87SVille Syrjälä flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(1); 3060c2798b19SChris Wilson 3061c2798b19SChris Wilson iir = new_iir; 3062c2798b19SChris Wilson } 3063c2798b19SChris Wilson 3064c2798b19SChris Wilson return IRQ_HANDLED; 3065c2798b19SChris Wilson } 3066c2798b19SChris Wilson 3067c2798b19SChris Wilson static void i8xx_irq_uninstall(struct drm_device * dev) 3068c2798b19SChris Wilson { 3069c2798b19SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 3070c2798b19SChris Wilson int pipe; 3071c2798b19SChris Wilson 3072c2798b19SChris Wilson for_each_pipe(pipe) { 3073c2798b19SChris Wilson /* Clear enable bits; then clear status bits */ 3074c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3075c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe))); 3076c2798b19SChris Wilson } 3077c2798b19SChris Wilson I915_WRITE16(IMR, 0xffff); 3078c2798b19SChris Wilson I915_WRITE16(IER, 0x0); 3079c2798b19SChris Wilson I915_WRITE16(IIR, I915_READ16(IIR)); 3080c2798b19SChris Wilson } 3081c2798b19SChris Wilson 3082a266c7d5SChris Wilson static void i915_irq_preinstall(struct drm_device * dev) 3083a266c7d5SChris Wilson { 3084a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 3085a266c7d5SChris Wilson int pipe; 3086a266c7d5SChris Wilson 3087a266c7d5SChris Wilson atomic_set(&dev_priv->irq_received, 0); 3088a266c7d5SChris Wilson 3089a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 3090a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 3091a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3092a266c7d5SChris Wilson } 3093a266c7d5SChris Wilson 309400d98ebdSChris Wilson I915_WRITE16(HWSTAM, 0xeffe); 3095a266c7d5SChris Wilson for_each_pipe(pipe) 3096a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3097a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 3098a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 3099a266c7d5SChris Wilson POSTING_READ(IER); 3100a266c7d5SChris Wilson } 3101a266c7d5SChris Wilson 3102a266c7d5SChris Wilson static int i915_irq_postinstall(struct drm_device *dev) 3103a266c7d5SChris Wilson { 3104a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 310538bde180SChris Wilson u32 enable_mask; 3106a266c7d5SChris Wilson 310738bde180SChris Wilson I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH)); 310838bde180SChris Wilson 310938bde180SChris Wilson /* Unmask the interrupts that we always want on. */ 311038bde180SChris Wilson dev_priv->irq_mask = 311138bde180SChris Wilson ~(I915_ASLE_INTERRUPT | 311238bde180SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 311338bde180SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 311438bde180SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 311538bde180SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | 311638bde180SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 311738bde180SChris Wilson 311838bde180SChris Wilson enable_mask = 311938bde180SChris Wilson I915_ASLE_INTERRUPT | 312038bde180SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 312138bde180SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 312238bde180SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT | 312338bde180SChris Wilson I915_USER_INTERRUPT; 312438bde180SChris Wilson 3125a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 312620afbda2SDaniel Vetter I915_WRITE(PORT_HOTPLUG_EN, 0); 312720afbda2SDaniel Vetter POSTING_READ(PORT_HOTPLUG_EN); 312820afbda2SDaniel Vetter 3129a266c7d5SChris Wilson /* Enable in IER... */ 3130a266c7d5SChris Wilson enable_mask |= I915_DISPLAY_PORT_INTERRUPT; 3131a266c7d5SChris Wilson /* and unmask in IMR */ 3132a266c7d5SChris Wilson dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT; 3133a266c7d5SChris Wilson } 3134a266c7d5SChris Wilson 3135a266c7d5SChris Wilson I915_WRITE(IMR, dev_priv->irq_mask); 3136a266c7d5SChris Wilson I915_WRITE(IER, enable_mask); 3137a266c7d5SChris Wilson POSTING_READ(IER); 3138a266c7d5SChris Wilson 3139f49e38ddSJani Nikula i915_enable_asle_pipestat(dev); 314020afbda2SDaniel Vetter 314120afbda2SDaniel Vetter return 0; 314220afbda2SDaniel Vetter } 314320afbda2SDaniel Vetter 314490a72f87SVille Syrjälä /* 314590a72f87SVille Syrjälä * Returns true when a page flip has completed. 314690a72f87SVille Syrjälä */ 314790a72f87SVille Syrjälä static bool i915_handle_vblank(struct drm_device *dev, 314890a72f87SVille Syrjälä int plane, int pipe, u32 iir) 314990a72f87SVille Syrjälä { 315090a72f87SVille Syrjälä drm_i915_private_t *dev_priv = dev->dev_private; 315190a72f87SVille Syrjälä u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane); 315290a72f87SVille Syrjälä 315390a72f87SVille Syrjälä if (!drm_handle_vblank(dev, pipe)) 315490a72f87SVille Syrjälä return false; 315590a72f87SVille Syrjälä 315690a72f87SVille Syrjälä if ((iir & flip_pending) == 0) 315790a72f87SVille Syrjälä return false; 315890a72f87SVille Syrjälä 315990a72f87SVille Syrjälä intel_prepare_page_flip(dev, plane); 316090a72f87SVille Syrjälä 316190a72f87SVille Syrjälä /* We detect FlipDone by looking for the change in PendingFlip from '1' 316290a72f87SVille Syrjälä * to '0' on the following vblank, i.e. IIR has the Pendingflip 316390a72f87SVille Syrjälä * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence 316490a72f87SVille Syrjälä * the flip is completed (no longer pending). Since this doesn't raise 316590a72f87SVille Syrjälä * an interrupt per se, we watch for the change at vblank. 316690a72f87SVille Syrjälä */ 316790a72f87SVille Syrjälä if (I915_READ(ISR) & flip_pending) 316890a72f87SVille Syrjälä return false; 316990a72f87SVille Syrjälä 317090a72f87SVille Syrjälä intel_finish_page_flip(dev, pipe); 317190a72f87SVille Syrjälä 317290a72f87SVille Syrjälä return true; 317390a72f87SVille Syrjälä } 317490a72f87SVille Syrjälä 3175ff1f525eSDaniel Vetter static irqreturn_t i915_irq_handler(int irq, void *arg) 3176a266c7d5SChris Wilson { 3177a266c7d5SChris Wilson struct drm_device *dev = (struct drm_device *) arg; 3178a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 31798291ee90SChris Wilson u32 iir, new_iir, pipe_stats[I915_MAX_PIPES]; 3180a266c7d5SChris Wilson unsigned long irqflags; 318138bde180SChris Wilson u32 flip_mask = 318238bde180SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 318338bde180SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 318438bde180SChris Wilson int pipe, ret = IRQ_NONE; 3185a266c7d5SChris Wilson 3186a266c7d5SChris Wilson atomic_inc(&dev_priv->irq_received); 3187a266c7d5SChris Wilson 3188a266c7d5SChris Wilson iir = I915_READ(IIR); 318938bde180SChris Wilson do { 319038bde180SChris Wilson bool irq_received = (iir & ~flip_mask) != 0; 31918291ee90SChris Wilson bool blc_event = false; 3192a266c7d5SChris Wilson 3193a266c7d5SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 3194a266c7d5SChris Wilson * have been cleared after the pipestat interrupt was received. 3195a266c7d5SChris Wilson * It doesn't set the bit in iir again, but it still produces 3196a266c7d5SChris Wilson * interrupts (for non-MSI). 3197a266c7d5SChris Wilson */ 3198a266c7d5SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3199a266c7d5SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 3200a266c7d5SChris Wilson i915_handle_error(dev, false); 3201a266c7d5SChris Wilson 3202a266c7d5SChris Wilson for_each_pipe(pipe) { 3203a266c7d5SChris Wilson int reg = PIPESTAT(pipe); 3204a266c7d5SChris Wilson pipe_stats[pipe] = I915_READ(reg); 3205a266c7d5SChris Wilson 320638bde180SChris Wilson /* Clear the PIPE*STAT regs before the IIR */ 3207a266c7d5SChris Wilson if (pipe_stats[pipe] & 0x8000ffff) { 3208a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 3209a266c7d5SChris Wilson DRM_DEBUG_DRIVER("pipe %c underrun\n", 3210a266c7d5SChris Wilson pipe_name(pipe)); 3211a266c7d5SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 321238bde180SChris Wilson irq_received = true; 3213a266c7d5SChris Wilson } 3214a266c7d5SChris Wilson } 3215a266c7d5SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3216a266c7d5SChris Wilson 3217a266c7d5SChris Wilson if (!irq_received) 3218a266c7d5SChris Wilson break; 3219a266c7d5SChris Wilson 3220a266c7d5SChris Wilson /* Consume port. Then clear IIR or we'll miss events */ 3221a266c7d5SChris Wilson if ((I915_HAS_HOTPLUG(dev)) && 3222a266c7d5SChris Wilson (iir & I915_DISPLAY_PORT_INTERRUPT)) { 3223a266c7d5SChris Wilson u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); 3224b543fb04SEgbert Eich u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915; 3225a266c7d5SChris Wilson 3226a266c7d5SChris Wilson DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n", 3227a266c7d5SChris Wilson hotplug_status); 3228b543fb04SEgbert Eich if (hotplug_trigger) { 322910a504deSDaniel Vetter intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915); 3230b543fb04SEgbert Eich } 3231a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); 323238bde180SChris Wilson POSTING_READ(PORT_HOTPLUG_STAT); 3233a266c7d5SChris Wilson } 3234a266c7d5SChris Wilson 323538bde180SChris Wilson I915_WRITE(IIR, iir & ~flip_mask); 3236a266c7d5SChris Wilson new_iir = I915_READ(IIR); /* Flush posted writes */ 3237a266c7d5SChris Wilson 3238a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 3239a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[RCS]); 3240a266c7d5SChris Wilson 3241a266c7d5SChris Wilson for_each_pipe(pipe) { 324238bde180SChris Wilson int plane = pipe; 324338bde180SChris Wilson if (IS_MOBILE(dev)) 324438bde180SChris Wilson plane = !plane; 32455e2032d4SVille Syrjälä 324690a72f87SVille Syrjälä if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS && 324790a72f87SVille Syrjälä i915_handle_vblank(dev, plane, pipe, iir)) 324890a72f87SVille Syrjälä flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane); 3249a266c7d5SChris Wilson 3250a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 3251a266c7d5SChris Wilson blc_event = true; 3252a266c7d5SChris Wilson } 3253a266c7d5SChris Wilson 3254a266c7d5SChris Wilson if (blc_event || (iir & I915_ASLE_INTERRUPT)) 3255a266c7d5SChris Wilson intel_opregion_asle_intr(dev); 3256a266c7d5SChris Wilson 3257a266c7d5SChris Wilson /* With MSI, interrupts are only generated when iir 3258a266c7d5SChris Wilson * transitions from zero to nonzero. If another bit got 3259a266c7d5SChris Wilson * set while we were handling the existing iir bits, then 3260a266c7d5SChris Wilson * we would never get another interrupt. 3261a266c7d5SChris Wilson * 3262a266c7d5SChris Wilson * This is fine on non-MSI as well, as if we hit this path 3263a266c7d5SChris Wilson * we avoid exiting the interrupt handler only to generate 3264a266c7d5SChris Wilson * another one. 3265a266c7d5SChris Wilson * 3266a266c7d5SChris Wilson * Note that for MSI this could cause a stray interrupt report 3267a266c7d5SChris Wilson * if an interrupt landed in the time between writing IIR and 3268a266c7d5SChris Wilson * the posting read. This should be rare enough to never 3269a266c7d5SChris Wilson * trigger the 99% of 100,000 interrupts test for disabling 3270a266c7d5SChris Wilson * stray interrupts. 3271a266c7d5SChris Wilson */ 327238bde180SChris Wilson ret = IRQ_HANDLED; 3273a266c7d5SChris Wilson iir = new_iir; 327438bde180SChris Wilson } while (iir & ~flip_mask); 3275a266c7d5SChris Wilson 3276d05c617eSDaniel Vetter i915_update_dri1_breadcrumb(dev); 32778291ee90SChris Wilson 3278a266c7d5SChris Wilson return ret; 3279a266c7d5SChris Wilson } 3280a266c7d5SChris Wilson 3281a266c7d5SChris Wilson static void i915_irq_uninstall(struct drm_device * dev) 3282a266c7d5SChris Wilson { 3283a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 3284a266c7d5SChris Wilson int pipe; 3285a266c7d5SChris Wilson 3286ac4c16c5SEgbert Eich del_timer_sync(&dev_priv->hotplug_reenable_timer); 3287ac4c16c5SEgbert Eich 3288a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 3289a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 3290a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3291a266c7d5SChris Wilson } 3292a266c7d5SChris Wilson 329300d98ebdSChris Wilson I915_WRITE16(HWSTAM, 0xffff); 329455b39755SChris Wilson for_each_pipe(pipe) { 329555b39755SChris Wilson /* Clear enable bits; then clear status bits */ 3296a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 329755b39755SChris Wilson I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe))); 329855b39755SChris Wilson } 3299a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 3300a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 3301a266c7d5SChris Wilson 3302a266c7d5SChris Wilson I915_WRITE(IIR, I915_READ(IIR)); 3303a266c7d5SChris Wilson } 3304a266c7d5SChris Wilson 3305a266c7d5SChris Wilson static void i965_irq_preinstall(struct drm_device * dev) 3306a266c7d5SChris Wilson { 3307a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 3308a266c7d5SChris Wilson int pipe; 3309a266c7d5SChris Wilson 3310a266c7d5SChris Wilson atomic_set(&dev_priv->irq_received, 0); 3311a266c7d5SChris Wilson 3312a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 3313a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3314a266c7d5SChris Wilson 3315a266c7d5SChris Wilson I915_WRITE(HWSTAM, 0xeffe); 3316a266c7d5SChris Wilson for_each_pipe(pipe) 3317a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3318a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 3319a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 3320a266c7d5SChris Wilson POSTING_READ(IER); 3321a266c7d5SChris Wilson } 3322a266c7d5SChris Wilson 3323a266c7d5SChris Wilson static int i965_irq_postinstall(struct drm_device *dev) 3324a266c7d5SChris Wilson { 3325a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 3326bbba0a97SChris Wilson u32 enable_mask; 3327a266c7d5SChris Wilson u32 error_mask; 3328a266c7d5SChris Wilson 3329a266c7d5SChris Wilson /* Unmask the interrupts that we always want on. */ 3330bbba0a97SChris Wilson dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT | 3331adca4730SChris Wilson I915_DISPLAY_PORT_INTERRUPT | 3332bbba0a97SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3333bbba0a97SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3334bbba0a97SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 3335bbba0a97SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | 3336bbba0a97SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 3337bbba0a97SChris Wilson 3338bbba0a97SChris Wilson enable_mask = ~dev_priv->irq_mask; 333921ad8330SVille Syrjälä enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 334021ad8330SVille Syrjälä I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT); 3341bbba0a97SChris Wilson enable_mask |= I915_USER_INTERRUPT; 3342bbba0a97SChris Wilson 3343bbba0a97SChris Wilson if (IS_G4X(dev)) 3344bbba0a97SChris Wilson enable_mask |= I915_BSD_USER_INTERRUPT; 3345a266c7d5SChris Wilson 3346515ac2bbSDaniel Vetter i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE); 3347a266c7d5SChris Wilson 3348a266c7d5SChris Wilson /* 3349a266c7d5SChris Wilson * Enable some error detection, note the instruction error mask 3350a266c7d5SChris Wilson * bit is reserved, so we leave it masked. 3351a266c7d5SChris Wilson */ 3352a266c7d5SChris Wilson if (IS_G4X(dev)) { 3353a266c7d5SChris Wilson error_mask = ~(GM45_ERROR_PAGE_TABLE | 3354a266c7d5SChris Wilson GM45_ERROR_MEM_PRIV | 3355a266c7d5SChris Wilson GM45_ERROR_CP_PRIV | 3356a266c7d5SChris Wilson I915_ERROR_MEMORY_REFRESH); 3357a266c7d5SChris Wilson } else { 3358a266c7d5SChris Wilson error_mask = ~(I915_ERROR_PAGE_TABLE | 3359a266c7d5SChris Wilson I915_ERROR_MEMORY_REFRESH); 3360a266c7d5SChris Wilson } 3361a266c7d5SChris Wilson I915_WRITE(EMR, error_mask); 3362a266c7d5SChris Wilson 3363a266c7d5SChris Wilson I915_WRITE(IMR, dev_priv->irq_mask); 3364a266c7d5SChris Wilson I915_WRITE(IER, enable_mask); 3365a266c7d5SChris Wilson POSTING_READ(IER); 3366a266c7d5SChris Wilson 336720afbda2SDaniel Vetter I915_WRITE(PORT_HOTPLUG_EN, 0); 336820afbda2SDaniel Vetter POSTING_READ(PORT_HOTPLUG_EN); 336920afbda2SDaniel Vetter 3370f49e38ddSJani Nikula i915_enable_asle_pipestat(dev); 337120afbda2SDaniel Vetter 337220afbda2SDaniel Vetter return 0; 337320afbda2SDaniel Vetter } 337420afbda2SDaniel Vetter 3375bac56d5bSEgbert Eich static void i915_hpd_irq_setup(struct drm_device *dev) 337620afbda2SDaniel Vetter { 337720afbda2SDaniel Vetter drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 3378e5868a31SEgbert Eich struct drm_mode_config *mode_config = &dev->mode_config; 3379cd569aedSEgbert Eich struct intel_encoder *intel_encoder; 338020afbda2SDaniel Vetter u32 hotplug_en; 338120afbda2SDaniel Vetter 3382bac56d5bSEgbert Eich if (I915_HAS_HOTPLUG(dev)) { 3383bac56d5bSEgbert Eich hotplug_en = I915_READ(PORT_HOTPLUG_EN); 3384bac56d5bSEgbert Eich hotplug_en &= ~HOTPLUG_INT_EN_MASK; 3385adca4730SChris Wilson /* Note HDMI and DP share hotplug bits */ 3386e5868a31SEgbert Eich /* enable bits are the same for all generations */ 3387cd569aedSEgbert Eich list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head) 3388cd569aedSEgbert Eich if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) 3389cd569aedSEgbert Eich hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin]; 3390a266c7d5SChris Wilson /* Programming the CRT detection parameters tends 3391a266c7d5SChris Wilson to generate a spurious hotplug event about three 3392a266c7d5SChris Wilson seconds later. So just do it once. 3393a266c7d5SChris Wilson */ 3394a266c7d5SChris Wilson if (IS_G4X(dev)) 3395a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64; 339685fc95baSDaniel Vetter hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK; 3397a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; 3398a266c7d5SChris Wilson 3399a266c7d5SChris Wilson /* Ignore TV since it's buggy */ 3400a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, hotplug_en); 3401a266c7d5SChris Wilson } 3402bac56d5bSEgbert Eich } 3403a266c7d5SChris Wilson 3404ff1f525eSDaniel Vetter static irqreturn_t i965_irq_handler(int irq, void *arg) 3405a266c7d5SChris Wilson { 3406a266c7d5SChris Wilson struct drm_device *dev = (struct drm_device *) arg; 3407a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 3408a266c7d5SChris Wilson u32 iir, new_iir; 3409a266c7d5SChris Wilson u32 pipe_stats[I915_MAX_PIPES]; 3410a266c7d5SChris Wilson unsigned long irqflags; 3411a266c7d5SChris Wilson int irq_received; 3412a266c7d5SChris Wilson int ret = IRQ_NONE, pipe; 341321ad8330SVille Syrjälä u32 flip_mask = 341421ad8330SVille Syrjälä I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 341521ad8330SVille Syrjälä I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 3416a266c7d5SChris Wilson 3417a266c7d5SChris Wilson atomic_inc(&dev_priv->irq_received); 3418a266c7d5SChris Wilson 3419a266c7d5SChris Wilson iir = I915_READ(IIR); 3420a266c7d5SChris Wilson 3421a266c7d5SChris Wilson for (;;) { 34222c8ba29fSChris Wilson bool blc_event = false; 34232c8ba29fSChris Wilson 342421ad8330SVille Syrjälä irq_received = (iir & ~flip_mask) != 0; 3425a266c7d5SChris Wilson 3426a266c7d5SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 3427a266c7d5SChris Wilson * have been cleared after the pipestat interrupt was received. 3428a266c7d5SChris Wilson * It doesn't set the bit in iir again, but it still produces 3429a266c7d5SChris Wilson * interrupts (for non-MSI). 3430a266c7d5SChris Wilson */ 3431a266c7d5SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3432a266c7d5SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 3433a266c7d5SChris Wilson i915_handle_error(dev, false); 3434a266c7d5SChris Wilson 3435a266c7d5SChris Wilson for_each_pipe(pipe) { 3436a266c7d5SChris Wilson int reg = PIPESTAT(pipe); 3437a266c7d5SChris Wilson pipe_stats[pipe] = I915_READ(reg); 3438a266c7d5SChris Wilson 3439a266c7d5SChris Wilson /* 3440a266c7d5SChris Wilson * Clear the PIPE*STAT regs before the IIR 3441a266c7d5SChris Wilson */ 3442a266c7d5SChris Wilson if (pipe_stats[pipe] & 0x8000ffff) { 3443a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 3444a266c7d5SChris Wilson DRM_DEBUG_DRIVER("pipe %c underrun\n", 3445a266c7d5SChris Wilson pipe_name(pipe)); 3446a266c7d5SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 3447a266c7d5SChris Wilson irq_received = 1; 3448a266c7d5SChris Wilson } 3449a266c7d5SChris Wilson } 3450a266c7d5SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3451a266c7d5SChris Wilson 3452a266c7d5SChris Wilson if (!irq_received) 3453a266c7d5SChris Wilson break; 3454a266c7d5SChris Wilson 3455a266c7d5SChris Wilson ret = IRQ_HANDLED; 3456a266c7d5SChris Wilson 3457a266c7d5SChris Wilson /* Consume port. Then clear IIR or we'll miss events */ 3458adca4730SChris Wilson if (iir & I915_DISPLAY_PORT_INTERRUPT) { 3459a266c7d5SChris Wilson u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); 3460b543fb04SEgbert Eich u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ? 3461b543fb04SEgbert Eich HOTPLUG_INT_STATUS_G4X : 34624f7fd709SDaniel Vetter HOTPLUG_INT_STATUS_I915); 3463a266c7d5SChris Wilson 3464a266c7d5SChris Wilson DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n", 3465a266c7d5SChris Wilson hotplug_status); 3466b543fb04SEgbert Eich if (hotplug_trigger) { 346710a504deSDaniel Vetter intel_hpd_irq_handler(dev, hotplug_trigger, 346810a504deSDaniel Vetter IS_G4X(dev) ? hpd_status_gen4 : hpd_status_i915); 3469b543fb04SEgbert Eich } 3470a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); 3471a266c7d5SChris Wilson I915_READ(PORT_HOTPLUG_STAT); 3472a266c7d5SChris Wilson } 3473a266c7d5SChris Wilson 347421ad8330SVille Syrjälä I915_WRITE(IIR, iir & ~flip_mask); 3475a266c7d5SChris Wilson new_iir = I915_READ(IIR); /* Flush posted writes */ 3476a266c7d5SChris Wilson 3477a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 3478a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[RCS]); 3479a266c7d5SChris Wilson if (iir & I915_BSD_USER_INTERRUPT) 3480a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[VCS]); 3481a266c7d5SChris Wilson 3482a266c7d5SChris Wilson for_each_pipe(pipe) { 34832c8ba29fSChris Wilson if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS && 348490a72f87SVille Syrjälä i915_handle_vblank(dev, pipe, pipe, iir)) 348590a72f87SVille Syrjälä flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe); 3486a266c7d5SChris Wilson 3487a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 3488a266c7d5SChris Wilson blc_event = true; 3489a266c7d5SChris Wilson } 3490a266c7d5SChris Wilson 3491a266c7d5SChris Wilson 3492a266c7d5SChris Wilson if (blc_event || (iir & I915_ASLE_INTERRUPT)) 3493a266c7d5SChris Wilson intel_opregion_asle_intr(dev); 3494a266c7d5SChris Wilson 3495515ac2bbSDaniel Vetter if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 3496515ac2bbSDaniel Vetter gmbus_irq_handler(dev); 3497515ac2bbSDaniel Vetter 3498a266c7d5SChris Wilson /* With MSI, interrupts are only generated when iir 3499a266c7d5SChris Wilson * transitions from zero to nonzero. If another bit got 3500a266c7d5SChris Wilson * set while we were handling the existing iir bits, then 3501a266c7d5SChris Wilson * we would never get another interrupt. 3502a266c7d5SChris Wilson * 3503a266c7d5SChris Wilson * This is fine on non-MSI as well, as if we hit this path 3504a266c7d5SChris Wilson * we avoid exiting the interrupt handler only to generate 3505a266c7d5SChris Wilson * another one. 3506a266c7d5SChris Wilson * 3507a266c7d5SChris Wilson * Note that for MSI this could cause a stray interrupt report 3508a266c7d5SChris Wilson * if an interrupt landed in the time between writing IIR and 3509a266c7d5SChris Wilson * the posting read. This should be rare enough to never 3510a266c7d5SChris Wilson * trigger the 99% of 100,000 interrupts test for disabling 3511a266c7d5SChris Wilson * stray interrupts. 3512a266c7d5SChris Wilson */ 3513a266c7d5SChris Wilson iir = new_iir; 3514a266c7d5SChris Wilson } 3515a266c7d5SChris Wilson 3516d05c617eSDaniel Vetter i915_update_dri1_breadcrumb(dev); 35172c8ba29fSChris Wilson 3518a266c7d5SChris Wilson return ret; 3519a266c7d5SChris Wilson } 3520a266c7d5SChris Wilson 3521a266c7d5SChris Wilson static void i965_irq_uninstall(struct drm_device * dev) 3522a266c7d5SChris Wilson { 3523a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 3524a266c7d5SChris Wilson int pipe; 3525a266c7d5SChris Wilson 3526a266c7d5SChris Wilson if (!dev_priv) 3527a266c7d5SChris Wilson return; 3528a266c7d5SChris Wilson 3529ac4c16c5SEgbert Eich del_timer_sync(&dev_priv->hotplug_reenable_timer); 3530ac4c16c5SEgbert Eich 3531a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 3532a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3533a266c7d5SChris Wilson 3534a266c7d5SChris Wilson I915_WRITE(HWSTAM, 0xffffffff); 3535a266c7d5SChris Wilson for_each_pipe(pipe) 3536a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 3537a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 3538a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 3539a266c7d5SChris Wilson 3540a266c7d5SChris Wilson for_each_pipe(pipe) 3541a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 3542a266c7d5SChris Wilson I915_READ(PIPESTAT(pipe)) & 0x8000ffff); 3543a266c7d5SChris Wilson I915_WRITE(IIR, I915_READ(IIR)); 3544a266c7d5SChris Wilson } 3545a266c7d5SChris Wilson 3546ac4c16c5SEgbert Eich static void i915_reenable_hotplug_timer_func(unsigned long data) 3547ac4c16c5SEgbert Eich { 3548ac4c16c5SEgbert Eich drm_i915_private_t *dev_priv = (drm_i915_private_t *)data; 3549ac4c16c5SEgbert Eich struct drm_device *dev = dev_priv->dev; 3550ac4c16c5SEgbert Eich struct drm_mode_config *mode_config = &dev->mode_config; 3551ac4c16c5SEgbert Eich unsigned long irqflags; 3552ac4c16c5SEgbert Eich int i; 3553ac4c16c5SEgbert Eich 3554ac4c16c5SEgbert Eich spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 3555ac4c16c5SEgbert Eich for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) { 3556ac4c16c5SEgbert Eich struct drm_connector *connector; 3557ac4c16c5SEgbert Eich 3558ac4c16c5SEgbert Eich if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED) 3559ac4c16c5SEgbert Eich continue; 3560ac4c16c5SEgbert Eich 3561ac4c16c5SEgbert Eich dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED; 3562ac4c16c5SEgbert Eich 3563ac4c16c5SEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 3564ac4c16c5SEgbert Eich struct intel_connector *intel_connector = to_intel_connector(connector); 3565ac4c16c5SEgbert Eich 3566ac4c16c5SEgbert Eich if (intel_connector->encoder->hpd_pin == i) { 3567ac4c16c5SEgbert Eich if (connector->polled != intel_connector->polled) 3568ac4c16c5SEgbert Eich DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n", 3569ac4c16c5SEgbert Eich drm_get_connector_name(connector)); 3570ac4c16c5SEgbert Eich connector->polled = intel_connector->polled; 3571ac4c16c5SEgbert Eich if (!connector->polled) 3572ac4c16c5SEgbert Eich connector->polled = DRM_CONNECTOR_POLL_HPD; 3573ac4c16c5SEgbert Eich } 3574ac4c16c5SEgbert Eich } 3575ac4c16c5SEgbert Eich } 3576ac4c16c5SEgbert Eich if (dev_priv->display.hpd_irq_setup) 3577ac4c16c5SEgbert Eich dev_priv->display.hpd_irq_setup(dev); 3578ac4c16c5SEgbert Eich spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 3579ac4c16c5SEgbert Eich } 3580ac4c16c5SEgbert Eich 3581f71d4af4SJesse Barnes void intel_irq_init(struct drm_device *dev) 3582f71d4af4SJesse Barnes { 35838b2e326dSChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 35848b2e326dSChris Wilson 35858b2e326dSChris Wilson INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func); 358699584db3SDaniel Vetter INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func); 3587c6a828d3SDaniel Vetter INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work); 3588a4da4fa4SDaniel Vetter INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work); 35898b2e326dSChris Wilson 359099584db3SDaniel Vetter setup_timer(&dev_priv->gpu_error.hangcheck_timer, 359199584db3SDaniel Vetter i915_hangcheck_elapsed, 359261bac78eSDaniel Vetter (unsigned long) dev); 3593ac4c16c5SEgbert Eich setup_timer(&dev_priv->hotplug_reenable_timer, i915_reenable_hotplug_timer_func, 3594ac4c16c5SEgbert Eich (unsigned long) dev_priv); 359561bac78eSDaniel Vetter 359697a19a24STomas Janousek pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE); 35979ee32feaSDaniel Vetter 3598f71d4af4SJesse Barnes dev->driver->get_vblank_counter = i915_get_vblank_counter; 3599f71d4af4SJesse Barnes dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ 36007d4e146fSEugeni Dodonov if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { 3601f71d4af4SJesse Barnes dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */ 3602f71d4af4SJesse Barnes dev->driver->get_vblank_counter = gm45_get_vblank_counter; 3603f71d4af4SJesse Barnes } 3604f71d4af4SJesse Barnes 3605c3613de9SKeith Packard if (drm_core_check_feature(dev, DRIVER_MODESET)) 3606f71d4af4SJesse Barnes dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp; 3607c3613de9SKeith Packard else 3608c3613de9SKeith Packard dev->driver->get_vblank_timestamp = NULL; 3609f71d4af4SJesse Barnes dev->driver->get_scanout_position = i915_get_crtc_scanoutpos; 3610f71d4af4SJesse Barnes 36117e231dbeSJesse Barnes if (IS_VALLEYVIEW(dev)) { 36127e231dbeSJesse Barnes dev->driver->irq_handler = valleyview_irq_handler; 36137e231dbeSJesse Barnes dev->driver->irq_preinstall = valleyview_irq_preinstall; 36147e231dbeSJesse Barnes dev->driver->irq_postinstall = valleyview_irq_postinstall; 36157e231dbeSJesse Barnes dev->driver->irq_uninstall = valleyview_irq_uninstall; 36167e231dbeSJesse Barnes dev->driver->enable_vblank = valleyview_enable_vblank; 36177e231dbeSJesse Barnes dev->driver->disable_vblank = valleyview_disable_vblank; 3618fa00abe0SEgbert Eich dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 36194a06e201SDaniel Vetter } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { 36207d99163dSBen Widawsky /* Share uninstall handlers with ILK/SNB */ 3621f71d4af4SJesse Barnes dev->driver->irq_handler = ivybridge_irq_handler; 36227d99163dSBen Widawsky dev->driver->irq_preinstall = ivybridge_irq_preinstall; 3623f71d4af4SJesse Barnes dev->driver->irq_postinstall = ivybridge_irq_postinstall; 3624f71d4af4SJesse Barnes dev->driver->irq_uninstall = ironlake_irq_uninstall; 3625f71d4af4SJesse Barnes dev->driver->enable_vblank = ivybridge_enable_vblank; 3626f71d4af4SJesse Barnes dev->driver->disable_vblank = ivybridge_disable_vblank; 362782a28bcfSDaniel Vetter dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup; 3628f71d4af4SJesse Barnes } else if (HAS_PCH_SPLIT(dev)) { 3629f71d4af4SJesse Barnes dev->driver->irq_handler = ironlake_irq_handler; 3630f71d4af4SJesse Barnes dev->driver->irq_preinstall = ironlake_irq_preinstall; 3631f71d4af4SJesse Barnes dev->driver->irq_postinstall = ironlake_irq_postinstall; 3632f71d4af4SJesse Barnes dev->driver->irq_uninstall = ironlake_irq_uninstall; 3633f71d4af4SJesse Barnes dev->driver->enable_vblank = ironlake_enable_vblank; 3634f71d4af4SJesse Barnes dev->driver->disable_vblank = ironlake_disable_vblank; 363582a28bcfSDaniel Vetter dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup; 3636f71d4af4SJesse Barnes } else { 3637c2798b19SChris Wilson if (INTEL_INFO(dev)->gen == 2) { 3638c2798b19SChris Wilson dev->driver->irq_preinstall = i8xx_irq_preinstall; 3639c2798b19SChris Wilson dev->driver->irq_postinstall = i8xx_irq_postinstall; 3640c2798b19SChris Wilson dev->driver->irq_handler = i8xx_irq_handler; 3641c2798b19SChris Wilson dev->driver->irq_uninstall = i8xx_irq_uninstall; 3642a266c7d5SChris Wilson } else if (INTEL_INFO(dev)->gen == 3) { 3643a266c7d5SChris Wilson dev->driver->irq_preinstall = i915_irq_preinstall; 3644a266c7d5SChris Wilson dev->driver->irq_postinstall = i915_irq_postinstall; 3645a266c7d5SChris Wilson dev->driver->irq_uninstall = i915_irq_uninstall; 3646a266c7d5SChris Wilson dev->driver->irq_handler = i915_irq_handler; 364720afbda2SDaniel Vetter dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 3648c2798b19SChris Wilson } else { 3649a266c7d5SChris Wilson dev->driver->irq_preinstall = i965_irq_preinstall; 3650a266c7d5SChris Wilson dev->driver->irq_postinstall = i965_irq_postinstall; 3651a266c7d5SChris Wilson dev->driver->irq_uninstall = i965_irq_uninstall; 3652a266c7d5SChris Wilson dev->driver->irq_handler = i965_irq_handler; 3653bac56d5bSEgbert Eich dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 3654c2798b19SChris Wilson } 3655f71d4af4SJesse Barnes dev->driver->enable_vblank = i915_enable_vblank; 3656f71d4af4SJesse Barnes dev->driver->disable_vblank = i915_disable_vblank; 3657f71d4af4SJesse Barnes } 3658f71d4af4SJesse Barnes } 365920afbda2SDaniel Vetter 366020afbda2SDaniel Vetter void intel_hpd_init(struct drm_device *dev) 366120afbda2SDaniel Vetter { 366220afbda2SDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 3663821450c6SEgbert Eich struct drm_mode_config *mode_config = &dev->mode_config; 3664821450c6SEgbert Eich struct drm_connector *connector; 3665821450c6SEgbert Eich int i; 366620afbda2SDaniel Vetter 3667821450c6SEgbert Eich for (i = 1; i < HPD_NUM_PINS; i++) { 3668821450c6SEgbert Eich dev_priv->hpd_stats[i].hpd_cnt = 0; 3669821450c6SEgbert Eich dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED; 3670821450c6SEgbert Eich } 3671821450c6SEgbert Eich list_for_each_entry(connector, &mode_config->connector_list, head) { 3672821450c6SEgbert Eich struct intel_connector *intel_connector = to_intel_connector(connector); 3673821450c6SEgbert Eich connector->polled = intel_connector->polled; 3674821450c6SEgbert Eich if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE) 3675821450c6SEgbert Eich connector->polled = DRM_CONNECTOR_POLL_HPD; 3676821450c6SEgbert Eich } 367720afbda2SDaniel Vetter if (dev_priv->display.hpd_irq_setup) 367820afbda2SDaniel Vetter dev_priv->display.hpd_irq_setup(dev); 367920afbda2SDaniel Vetter } 3680