Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 1 | /* i915_irq.c -- IRQ support for the I915 -*- linux-c -*- |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | */ |
Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 3 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. |
| 5 | * All Rights Reserved. |
Dave Airlie | bc54fd1 | 2005-06-23 22:46:46 +1000 | [diff] [blame] | 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the |
| 9 | * "Software"), to deal in the Software without restriction, including |
| 10 | * without limitation the rights to use, copy, modify, merge, publish, |
| 11 | * distribute, sub license, and/or sell copies of the Software, and to |
| 12 | * permit persons to whom the Software is furnished to do so, subject to |
| 13 | * the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice (including the |
| 16 | * next paragraph) shall be included in all copies or substantial portions |
| 17 | * of the Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
| 22 | * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR |
| 23 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 24 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 25 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 26 | * |
Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 27 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 29 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 30 | |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 31 | #include <linux/sysrq.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Damien Lespiau | b2c88f5 | 2013-10-15 18:55:29 +0100 | [diff] [blame] | 33 | #include <linux/circ_buf.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 34 | #include <drm/drmP.h> |
| 35 | #include <drm/i915_drm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include "i915_drv.h" |
Chris Wilson | 1c5d22f | 2009-08-25 11:15:50 +0100 | [diff] [blame] | 37 | #include "i915_trace.h" |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 38 | #include "intel_drv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Egbert Eich | e5868a3 | 2013-02-28 04:17:12 -0500 | [diff] [blame] | 40 | static const u32 hpd_ibx[] = { |
| 41 | [HPD_CRT] = SDE_CRT_HOTPLUG, |
| 42 | [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG, |
| 43 | [HPD_PORT_B] = SDE_PORTB_HOTPLUG, |
| 44 | [HPD_PORT_C] = SDE_PORTC_HOTPLUG, |
| 45 | [HPD_PORT_D] = SDE_PORTD_HOTPLUG |
| 46 | }; |
| 47 | |
| 48 | static const u32 hpd_cpt[] = { |
| 49 | [HPD_CRT] = SDE_CRT_HOTPLUG_CPT, |
Daniel Vetter | 73c352a | 2013-03-26 22:38:43 +0100 | [diff] [blame] | 50 | [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT, |
Egbert Eich | e5868a3 | 2013-02-28 04:17:12 -0500 | [diff] [blame] | 51 | [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT, |
| 52 | [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT, |
| 53 | [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT |
| 54 | }; |
| 55 | |
| 56 | static const u32 hpd_mask_i915[] = { |
| 57 | [HPD_CRT] = CRT_HOTPLUG_INT_EN, |
| 58 | [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN, |
| 59 | [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN, |
| 60 | [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN, |
| 61 | [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN, |
| 62 | [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN |
| 63 | }; |
| 64 | |
Daniel Vetter | 704cfb8 | 2013-12-18 09:08:43 +0100 | [diff] [blame] | 65 | static const u32 hpd_status_g4x[] = { |
Egbert Eich | e5868a3 | 2013-02-28 04:17:12 -0500 | [diff] [blame] | 66 | [HPD_CRT] = CRT_HOTPLUG_INT_STATUS, |
| 67 | [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X, |
| 68 | [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X, |
| 69 | [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS, |
| 70 | [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS, |
| 71 | [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS |
| 72 | }; |
| 73 | |
Egbert Eich | e5868a3 | 2013-02-28 04:17:12 -0500 | [diff] [blame] | 74 | static const u32 hpd_status_i915[] = { /* i915 and valleyview are the same */ |
| 75 | [HPD_CRT] = CRT_HOTPLUG_INT_STATUS, |
| 76 | [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915, |
| 77 | [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915, |
| 78 | [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS, |
| 79 | [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS, |
| 80 | [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS |
| 81 | }; |
| 82 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 83 | /* For display hotplug interrupt */ |
Chris Wilson | 995b676 | 2010-08-20 13:23:26 +0100 | [diff] [blame] | 84 | static void |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 85 | ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 86 | { |
Daniel Vetter | 4bc9d43 | 2013-06-27 13:44:58 +0200 | [diff] [blame] | 87 | assert_spin_locked(&dev_priv->irq_lock); |
| 88 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 89 | if (dev_priv->pc8.irqs_disabled) { |
| 90 | WARN(1, "IRQs disabled\n"); |
| 91 | dev_priv->pc8.regsave.deimr &= ~mask; |
| 92 | return; |
| 93 | } |
| 94 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 95 | if ((dev_priv->irq_mask & mask) != 0) { |
| 96 | dev_priv->irq_mask &= ~mask; |
| 97 | I915_WRITE(DEIMR, dev_priv->irq_mask); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 98 | POSTING_READ(DEIMR); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | |
Paulo Zanoni | 0ff9800 | 2013-02-22 17:05:31 -0300 | [diff] [blame] | 102 | static void |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 103 | ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 104 | { |
Daniel Vetter | 4bc9d43 | 2013-06-27 13:44:58 +0200 | [diff] [blame] | 105 | assert_spin_locked(&dev_priv->irq_lock); |
| 106 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 107 | if (dev_priv->pc8.irqs_disabled) { |
| 108 | WARN(1, "IRQs disabled\n"); |
| 109 | dev_priv->pc8.regsave.deimr |= mask; |
| 110 | return; |
| 111 | } |
| 112 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 113 | if ((dev_priv->irq_mask & mask) != mask) { |
| 114 | dev_priv->irq_mask |= mask; |
| 115 | I915_WRITE(DEIMR, dev_priv->irq_mask); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 116 | POSTING_READ(DEIMR); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
Paulo Zanoni | 43eaea1 | 2013-08-06 18:57:12 -0300 | [diff] [blame] | 120 | /** |
| 121 | * ilk_update_gt_irq - update GTIMR |
| 122 | * @dev_priv: driver private |
| 123 | * @interrupt_mask: mask of interrupt bits to update |
| 124 | * @enabled_irq_mask: mask of interrupt bits to enable |
| 125 | */ |
| 126 | static void ilk_update_gt_irq(struct drm_i915_private *dev_priv, |
| 127 | uint32_t interrupt_mask, |
| 128 | uint32_t enabled_irq_mask) |
| 129 | { |
| 130 | assert_spin_locked(&dev_priv->irq_lock); |
| 131 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 132 | if (dev_priv->pc8.irqs_disabled) { |
| 133 | WARN(1, "IRQs disabled\n"); |
| 134 | dev_priv->pc8.regsave.gtimr &= ~interrupt_mask; |
| 135 | dev_priv->pc8.regsave.gtimr |= (~enabled_irq_mask & |
| 136 | interrupt_mask); |
| 137 | return; |
| 138 | } |
| 139 | |
Paulo Zanoni | 43eaea1 | 2013-08-06 18:57:12 -0300 | [diff] [blame] | 140 | dev_priv->gt_irq_mask &= ~interrupt_mask; |
| 141 | dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask); |
| 142 | I915_WRITE(GTIMR, dev_priv->gt_irq_mask); |
| 143 | POSTING_READ(GTIMR); |
| 144 | } |
| 145 | |
| 146 | void ilk_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask) |
| 147 | { |
| 148 | ilk_update_gt_irq(dev_priv, mask, mask); |
| 149 | } |
| 150 | |
| 151 | void ilk_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask) |
| 152 | { |
| 153 | ilk_update_gt_irq(dev_priv, mask, 0); |
| 154 | } |
| 155 | |
Paulo Zanoni | edbfdb4 | 2013-08-06 18:57:13 -0300 | [diff] [blame] | 156 | /** |
| 157 | * snb_update_pm_irq - update GEN6_PMIMR |
| 158 | * @dev_priv: driver private |
| 159 | * @interrupt_mask: mask of interrupt bits to update |
| 160 | * @enabled_irq_mask: mask of interrupt bits to enable |
| 161 | */ |
| 162 | static void snb_update_pm_irq(struct drm_i915_private *dev_priv, |
| 163 | uint32_t interrupt_mask, |
| 164 | uint32_t enabled_irq_mask) |
| 165 | { |
Paulo Zanoni | 605cd25 | 2013-08-06 18:57:15 -0300 | [diff] [blame] | 166 | uint32_t new_val; |
Paulo Zanoni | edbfdb4 | 2013-08-06 18:57:13 -0300 | [diff] [blame] | 167 | |
| 168 | assert_spin_locked(&dev_priv->irq_lock); |
| 169 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 170 | if (dev_priv->pc8.irqs_disabled) { |
| 171 | WARN(1, "IRQs disabled\n"); |
| 172 | dev_priv->pc8.regsave.gen6_pmimr &= ~interrupt_mask; |
| 173 | dev_priv->pc8.regsave.gen6_pmimr |= (~enabled_irq_mask & |
| 174 | interrupt_mask); |
| 175 | return; |
| 176 | } |
| 177 | |
Paulo Zanoni | 605cd25 | 2013-08-06 18:57:15 -0300 | [diff] [blame] | 178 | new_val = dev_priv->pm_irq_mask; |
Paulo Zanoni | f52ecbc | 2013-08-06 18:57:14 -0300 | [diff] [blame] | 179 | new_val &= ~interrupt_mask; |
| 180 | new_val |= (~enabled_irq_mask & interrupt_mask); |
| 181 | |
Paulo Zanoni | 605cd25 | 2013-08-06 18:57:15 -0300 | [diff] [blame] | 182 | if (new_val != dev_priv->pm_irq_mask) { |
| 183 | dev_priv->pm_irq_mask = new_val; |
| 184 | I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask); |
Paulo Zanoni | f52ecbc | 2013-08-06 18:57:14 -0300 | [diff] [blame] | 185 | POSTING_READ(GEN6_PMIMR); |
| 186 | } |
Paulo Zanoni | edbfdb4 | 2013-08-06 18:57:13 -0300 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | void snb_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask) |
| 190 | { |
| 191 | snb_update_pm_irq(dev_priv, mask, mask); |
| 192 | } |
| 193 | |
| 194 | void snb_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask) |
| 195 | { |
| 196 | snb_update_pm_irq(dev_priv, mask, 0); |
| 197 | } |
| 198 | |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 199 | static bool ivb_can_enable_err_int(struct drm_device *dev) |
| 200 | { |
| 201 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 202 | struct intel_crtc *crtc; |
| 203 | enum pipe pipe; |
| 204 | |
Daniel Vetter | 4bc9d43 | 2013-06-27 13:44:58 +0200 | [diff] [blame] | 205 | assert_spin_locked(&dev_priv->irq_lock); |
| 206 | |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 207 | for_each_pipe(pipe) { |
| 208 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 209 | |
| 210 | if (crtc->cpu_fifo_underrun_disabled) |
| 211 | return false; |
| 212 | } |
| 213 | |
| 214 | return true; |
| 215 | } |
| 216 | |
| 217 | static bool cpt_can_enable_serr_int(struct drm_device *dev) |
| 218 | { |
| 219 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 220 | enum pipe pipe; |
| 221 | struct intel_crtc *crtc; |
| 222 | |
Daniel Vetter | fee884e | 2013-07-04 23:35:21 +0200 | [diff] [blame] | 223 | assert_spin_locked(&dev_priv->irq_lock); |
| 224 | |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 225 | for_each_pipe(pipe) { |
| 226 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 227 | |
| 228 | if (crtc->pch_fifo_underrun_disabled) |
| 229 | return false; |
| 230 | } |
| 231 | |
| 232 | return true; |
| 233 | } |
| 234 | |
Ville Syrjälä | 2d9d2b0 | 2014-01-17 11:44:31 +0200 | [diff] [blame] | 235 | static void i9xx_clear_fifo_underrun(struct drm_device *dev, enum pipe pipe) |
| 236 | { |
| 237 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 238 | u32 reg = PIPESTAT(pipe); |
| 239 | u32 pipestat = I915_READ(reg) & 0x7fff0000; |
| 240 | |
| 241 | assert_spin_locked(&dev_priv->irq_lock); |
| 242 | |
| 243 | I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS); |
| 244 | POSTING_READ(reg); |
| 245 | } |
| 246 | |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 247 | static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev, |
| 248 | enum pipe pipe, bool enable) |
| 249 | { |
| 250 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 251 | uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN : |
| 252 | DE_PIPEB_FIFO_UNDERRUN; |
| 253 | |
| 254 | if (enable) |
| 255 | ironlake_enable_display_irq(dev_priv, bit); |
| 256 | else |
| 257 | ironlake_disable_display_irq(dev_priv, bit); |
| 258 | } |
| 259 | |
| 260 | static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev, |
Daniel Vetter | 7336df6 | 2013-07-09 22:59:16 +0200 | [diff] [blame] | 261 | enum pipe pipe, bool enable) |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 262 | { |
| 263 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 264 | if (enable) { |
Daniel Vetter | 7336df6 | 2013-07-09 22:59:16 +0200 | [diff] [blame] | 265 | I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe)); |
| 266 | |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 267 | if (!ivb_can_enable_err_int(dev)) |
| 268 | return; |
| 269 | |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 270 | ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB); |
| 271 | } else { |
Daniel Vetter | 7336df6 | 2013-07-09 22:59:16 +0200 | [diff] [blame] | 272 | bool was_enabled = !(I915_READ(DEIMR) & DE_ERR_INT_IVB); |
| 273 | |
| 274 | /* Change the state _after_ we've read out the current one. */ |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 275 | ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB); |
Daniel Vetter | 7336df6 | 2013-07-09 22:59:16 +0200 | [diff] [blame] | 276 | |
| 277 | if (!was_enabled && |
| 278 | (I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe))) { |
| 279 | DRM_DEBUG_KMS("uncleared fifo underrun on pipe %c\n", |
| 280 | pipe_name(pipe)); |
| 281 | } |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
Daniel Vetter | 38d83c96 | 2013-11-07 11:05:46 +0100 | [diff] [blame] | 285 | static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev, |
| 286 | enum pipe pipe, bool enable) |
| 287 | { |
| 288 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 289 | |
| 290 | assert_spin_locked(&dev_priv->irq_lock); |
| 291 | |
| 292 | if (enable) |
| 293 | dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_FIFO_UNDERRUN; |
| 294 | else |
| 295 | dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_FIFO_UNDERRUN; |
| 296 | I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]); |
| 297 | POSTING_READ(GEN8_DE_PIPE_IMR(pipe)); |
| 298 | } |
| 299 | |
Daniel Vetter | fee884e | 2013-07-04 23:35:21 +0200 | [diff] [blame] | 300 | /** |
| 301 | * ibx_display_interrupt_update - update SDEIMR |
| 302 | * @dev_priv: driver private |
| 303 | * @interrupt_mask: mask of interrupt bits to update |
| 304 | * @enabled_irq_mask: mask of interrupt bits to enable |
| 305 | */ |
| 306 | static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv, |
| 307 | uint32_t interrupt_mask, |
| 308 | uint32_t enabled_irq_mask) |
| 309 | { |
| 310 | uint32_t sdeimr = I915_READ(SDEIMR); |
| 311 | sdeimr &= ~interrupt_mask; |
| 312 | sdeimr |= (~enabled_irq_mask & interrupt_mask); |
| 313 | |
| 314 | assert_spin_locked(&dev_priv->irq_lock); |
| 315 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 316 | if (dev_priv->pc8.irqs_disabled && |
| 317 | (interrupt_mask & SDE_HOTPLUG_MASK_CPT)) { |
| 318 | WARN(1, "IRQs disabled\n"); |
| 319 | dev_priv->pc8.regsave.sdeimr &= ~interrupt_mask; |
| 320 | dev_priv->pc8.regsave.sdeimr |= (~enabled_irq_mask & |
| 321 | interrupt_mask); |
| 322 | return; |
| 323 | } |
| 324 | |
Daniel Vetter | fee884e | 2013-07-04 23:35:21 +0200 | [diff] [blame] | 325 | I915_WRITE(SDEIMR, sdeimr); |
| 326 | POSTING_READ(SDEIMR); |
| 327 | } |
| 328 | #define ibx_enable_display_interrupt(dev_priv, bits) \ |
| 329 | ibx_display_interrupt_update((dev_priv), (bits), (bits)) |
| 330 | #define ibx_disable_display_interrupt(dev_priv, bits) \ |
| 331 | ibx_display_interrupt_update((dev_priv), (bits), 0) |
| 332 | |
Daniel Vetter | de28075 | 2013-07-04 23:35:24 +0200 | [diff] [blame] | 333 | static void ibx_set_fifo_underrun_reporting(struct drm_device *dev, |
| 334 | enum transcoder pch_transcoder, |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 335 | bool enable) |
| 336 | { |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 337 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | de28075 | 2013-07-04 23:35:24 +0200 | [diff] [blame] | 338 | uint32_t bit = (pch_transcoder == TRANSCODER_A) ? |
| 339 | SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 340 | |
| 341 | if (enable) |
Daniel Vetter | fee884e | 2013-07-04 23:35:21 +0200 | [diff] [blame] | 342 | ibx_enable_display_interrupt(dev_priv, bit); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 343 | else |
Daniel Vetter | fee884e | 2013-07-04 23:35:21 +0200 | [diff] [blame] | 344 | ibx_disable_display_interrupt(dev_priv, bit); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | static void cpt_set_fifo_underrun_reporting(struct drm_device *dev, |
| 348 | enum transcoder pch_transcoder, |
| 349 | bool enable) |
| 350 | { |
| 351 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 352 | |
| 353 | if (enable) { |
Daniel Vetter | 1dd246f | 2013-07-10 08:30:23 +0200 | [diff] [blame] | 354 | I915_WRITE(SERR_INT, |
| 355 | SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)); |
| 356 | |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 357 | if (!cpt_can_enable_serr_int(dev)) |
| 358 | return; |
| 359 | |
Daniel Vetter | fee884e | 2013-07-04 23:35:21 +0200 | [diff] [blame] | 360 | ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 361 | } else { |
Daniel Vetter | 1dd246f | 2013-07-10 08:30:23 +0200 | [diff] [blame] | 362 | uint32_t tmp = I915_READ(SERR_INT); |
| 363 | bool was_enabled = !(I915_READ(SDEIMR) & SDE_ERROR_CPT); |
| 364 | |
| 365 | /* Change the state _after_ we've read out the current one. */ |
Daniel Vetter | fee884e | 2013-07-04 23:35:21 +0200 | [diff] [blame] | 366 | ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT); |
Daniel Vetter | 1dd246f | 2013-07-10 08:30:23 +0200 | [diff] [blame] | 367 | |
| 368 | if (!was_enabled && |
| 369 | (tmp & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder))) { |
| 370 | DRM_DEBUG_KMS("uncleared pch fifo underrun on pch transcoder %c\n", |
| 371 | transcoder_name(pch_transcoder)); |
| 372 | } |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 373 | } |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | /** |
| 377 | * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages |
| 378 | * @dev: drm device |
| 379 | * @pipe: pipe |
| 380 | * @enable: true if we want to report FIFO underrun errors, false otherwise |
| 381 | * |
| 382 | * This function makes us disable or enable CPU fifo underruns for a specific |
| 383 | * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun |
| 384 | * reporting for one pipe may also disable all the other CPU error interruts for |
| 385 | * the other pipes, due to the fact that there's just one interrupt mask/enable |
| 386 | * bit for all the pipes. |
| 387 | * |
| 388 | * Returns the previous state of underrun reporting. |
| 389 | */ |
| 390 | bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev, |
| 391 | enum pipe pipe, bool enable) |
| 392 | { |
| 393 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 394 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 395 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 396 | unsigned long flags; |
| 397 | bool ret; |
| 398 | |
| 399 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
| 400 | |
| 401 | ret = !intel_crtc->cpu_fifo_underrun_disabled; |
| 402 | |
| 403 | if (enable == ret) |
| 404 | goto done; |
| 405 | |
| 406 | intel_crtc->cpu_fifo_underrun_disabled = !enable; |
| 407 | |
Ville Syrjälä | 2d9d2b0 | 2014-01-17 11:44:31 +0200 | [diff] [blame] | 408 | if (enable && (INTEL_INFO(dev)->gen < 5 || IS_VALLEYVIEW(dev))) |
| 409 | i9xx_clear_fifo_underrun(dev, pipe); |
| 410 | else if (IS_GEN5(dev) || IS_GEN6(dev)) |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 411 | ironlake_set_fifo_underrun_reporting(dev, pipe, enable); |
| 412 | else if (IS_GEN7(dev)) |
Daniel Vetter | 7336df6 | 2013-07-09 22:59:16 +0200 | [diff] [blame] | 413 | ivybridge_set_fifo_underrun_reporting(dev, pipe, enable); |
Daniel Vetter | 38d83c96 | 2013-11-07 11:05:46 +0100 | [diff] [blame] | 414 | else if (IS_GEN8(dev)) |
| 415 | broadwell_set_fifo_underrun_reporting(dev, pipe, enable); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 416 | |
| 417 | done: |
| 418 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
| 419 | return ret; |
| 420 | } |
| 421 | |
| 422 | /** |
| 423 | * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages |
| 424 | * @dev: drm device |
| 425 | * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older) |
| 426 | * @enable: true if we want to report FIFO underrun errors, false otherwise |
| 427 | * |
| 428 | * This function makes us disable or enable PCH fifo underruns for a specific |
| 429 | * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO |
| 430 | * underrun reporting for one transcoder may also disable all the other PCH |
| 431 | * error interruts for the other transcoders, due to the fact that there's just |
| 432 | * one interrupt mask/enable bit for all the transcoders. |
| 433 | * |
| 434 | * Returns the previous state of underrun reporting. |
| 435 | */ |
| 436 | bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev, |
| 437 | enum transcoder pch_transcoder, |
| 438 | bool enable) |
| 439 | { |
| 440 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | de28075 | 2013-07-04 23:35:24 +0200 | [diff] [blame] | 441 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder]; |
| 442 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 443 | unsigned long flags; |
| 444 | bool ret; |
| 445 | |
Daniel Vetter | de28075 | 2013-07-04 23:35:24 +0200 | [diff] [blame] | 446 | /* |
| 447 | * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT |
| 448 | * has only one pch transcoder A that all pipes can use. To avoid racy |
| 449 | * pch transcoder -> pipe lookups from interrupt code simply store the |
| 450 | * underrun statistics in crtc A. Since we never expose this anywhere |
| 451 | * nor use it outside of the fifo underrun code here using the "wrong" |
| 452 | * crtc on LPT won't cause issues. |
| 453 | */ |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 454 | |
| 455 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
| 456 | |
| 457 | ret = !intel_crtc->pch_fifo_underrun_disabled; |
| 458 | |
| 459 | if (enable == ret) |
| 460 | goto done; |
| 461 | |
| 462 | intel_crtc->pch_fifo_underrun_disabled = !enable; |
| 463 | |
| 464 | if (HAS_PCH_IBX(dev)) |
Daniel Vetter | de28075 | 2013-07-04 23:35:24 +0200 | [diff] [blame] | 465 | ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 466 | else |
| 467 | cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable); |
| 468 | |
| 469 | done: |
| 470 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
| 471 | return ret; |
| 472 | } |
| 473 | |
| 474 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 475 | void |
Daniel Vetter | 3b6c42e | 2013-10-21 18:04:35 +0200 | [diff] [blame] | 476 | i915_enable_pipestat(drm_i915_private_t *dev_priv, enum pipe pipe, u32 mask) |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 477 | { |
Ville Syrjälä | 46c06a3 | 2013-02-20 21:16:18 +0200 | [diff] [blame] | 478 | u32 reg = PIPESTAT(pipe); |
| 479 | u32 pipestat = I915_READ(reg) & 0x7fff0000; |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 480 | |
Daniel Vetter | b79480b | 2013-06-27 17:52:10 +0200 | [diff] [blame] | 481 | assert_spin_locked(&dev_priv->irq_lock); |
| 482 | |
Ville Syrjälä | 46c06a3 | 2013-02-20 21:16:18 +0200 | [diff] [blame] | 483 | if ((pipestat & mask) == mask) |
| 484 | return; |
| 485 | |
| 486 | /* Enable the interrupt, clear any pending status */ |
| 487 | pipestat |= mask | (mask >> 16); |
| 488 | I915_WRITE(reg, pipestat); |
| 489 | POSTING_READ(reg); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | void |
Daniel Vetter | 3b6c42e | 2013-10-21 18:04:35 +0200 | [diff] [blame] | 493 | i915_disable_pipestat(drm_i915_private_t *dev_priv, enum pipe pipe, u32 mask) |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 494 | { |
Ville Syrjälä | 46c06a3 | 2013-02-20 21:16:18 +0200 | [diff] [blame] | 495 | u32 reg = PIPESTAT(pipe); |
| 496 | u32 pipestat = I915_READ(reg) & 0x7fff0000; |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 497 | |
Daniel Vetter | b79480b | 2013-06-27 17:52:10 +0200 | [diff] [blame] | 498 | assert_spin_locked(&dev_priv->irq_lock); |
| 499 | |
Ville Syrjälä | 46c06a3 | 2013-02-20 21:16:18 +0200 | [diff] [blame] | 500 | if ((pipestat & mask) == 0) |
| 501 | return; |
| 502 | |
| 503 | pipestat &= ~mask; |
| 504 | I915_WRITE(reg, pipestat); |
| 505 | POSTING_READ(reg); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 506 | } |
| 507 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 508 | /** |
Jani Nikula | f49e38d | 2013-04-29 13:02:54 +0300 | [diff] [blame] | 509 | * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion |
Zhao Yakui | 01c6688 | 2009-10-28 05:10:00 +0000 | [diff] [blame] | 510 | */ |
Jani Nikula | f49e38d | 2013-04-29 13:02:54 +0300 | [diff] [blame] | 511 | static void i915_enable_asle_pipestat(struct drm_device *dev) |
Zhao Yakui | 01c6688 | 2009-10-28 05:10:00 +0000 | [diff] [blame] | 512 | { |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 513 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 514 | unsigned long irqflags; |
| 515 | |
Jani Nikula | f49e38d | 2013-04-29 13:02:54 +0300 | [diff] [blame] | 516 | if (!dev_priv->opregion.asle || !IS_MOBILE(dev)) |
| 517 | return; |
| 518 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 519 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Zhao Yakui | 01c6688 | 2009-10-28 05:10:00 +0000 | [diff] [blame] | 520 | |
Daniel Vetter | 3b6c42e | 2013-10-21 18:04:35 +0200 | [diff] [blame] | 521 | i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_ENABLE); |
Jani Nikula | f898780 | 2013-04-29 13:02:53 +0300 | [diff] [blame] | 522 | if (INTEL_INFO(dev)->gen >= 4) |
Daniel Vetter | 3b6c42e | 2013-10-21 18:04:35 +0200 | [diff] [blame] | 523 | i915_enable_pipestat(dev_priv, PIPE_A, |
| 524 | PIPE_LEGACY_BLC_EVENT_ENABLE); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 525 | |
| 526 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
Zhao Yakui | 01c6688 | 2009-10-28 05:10:00 +0000 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | /** |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 530 | * i915_pipe_enabled - check if a pipe is enabled |
| 531 | * @dev: DRM device |
| 532 | * @pipe: pipe to check |
| 533 | * |
| 534 | * Reading certain registers when the pipe is disabled can hang the chip. |
| 535 | * Use this routine to make sure the PLL is running and the pipe is active |
| 536 | * before reading such registers if unsure. |
| 537 | */ |
| 538 | static int |
| 539 | i915_pipe_enabled(struct drm_device *dev, int pipe) |
| 540 | { |
| 541 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 542 | |
Daniel Vetter | a01025a | 2013-05-22 00:50:23 +0200 | [diff] [blame] | 543 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
| 544 | /* Locking is horribly broken here, but whatever. */ |
| 545 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 546 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 71f8ba6 | 2013-05-03 12:15:39 -0300 | [diff] [blame] | 547 | |
Daniel Vetter | a01025a | 2013-05-22 00:50:23 +0200 | [diff] [blame] | 548 | return intel_crtc->active; |
| 549 | } else { |
| 550 | return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE; |
| 551 | } |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Ville Syrjälä | 4cdb83e | 2013-10-11 21:52:44 +0300 | [diff] [blame] | 554 | static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe) |
| 555 | { |
| 556 | /* Gen2 doesn't have a hardware frame counter */ |
| 557 | return 0; |
| 558 | } |
| 559 | |
Keith Packard | 42f52ef | 2008-10-18 19:39:29 -0700 | [diff] [blame] | 560 | /* Called from drm generic code, passed a 'crtc', which |
| 561 | * we use as a pipe index |
| 562 | */ |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 563 | static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 564 | { |
| 565 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 566 | unsigned long high_frame; |
| 567 | unsigned long low_frame; |
Ville Syrjälä | 391f75e | 2013-09-25 19:55:26 +0300 | [diff] [blame] | 568 | u32 high1, high2, low, pixel, vbl_start; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 569 | |
| 570 | if (!i915_pipe_enabled(dev, pipe)) { |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 571 | DRM_DEBUG_DRIVER("trying to get vblank count for disabled " |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 572 | "pipe %c\n", pipe_name(pipe)); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 573 | return 0; |
| 574 | } |
| 575 | |
Ville Syrjälä | 391f75e | 2013-09-25 19:55:26 +0300 | [diff] [blame] | 576 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
| 577 | struct intel_crtc *intel_crtc = |
| 578 | to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 579 | const struct drm_display_mode *mode = |
| 580 | &intel_crtc->config.adjusted_mode; |
| 581 | |
| 582 | vbl_start = mode->crtc_vblank_start * mode->crtc_htotal; |
| 583 | } else { |
| 584 | enum transcoder cpu_transcoder = |
| 585 | intel_pipe_to_cpu_transcoder(dev_priv, pipe); |
| 586 | u32 htotal; |
| 587 | |
| 588 | htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1; |
| 589 | vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1; |
| 590 | |
| 591 | vbl_start *= htotal; |
| 592 | } |
| 593 | |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 594 | high_frame = PIPEFRAME(pipe); |
| 595 | low_frame = PIPEFRAMEPIXEL(pipe); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 596 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 597 | /* |
| 598 | * High & low register fields aren't synchronized, so make sure |
| 599 | * we get a low value that's stable across two reads of the high |
| 600 | * register. |
| 601 | */ |
| 602 | do { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 603 | high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; |
Ville Syrjälä | 391f75e | 2013-09-25 19:55:26 +0300 | [diff] [blame] | 604 | low = I915_READ(low_frame); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 605 | high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 606 | } while (high1 != high2); |
| 607 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 608 | high1 >>= PIPE_FRAME_HIGH_SHIFT; |
Ville Syrjälä | 391f75e | 2013-09-25 19:55:26 +0300 | [diff] [blame] | 609 | pixel = low & PIPE_PIXEL_MASK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 610 | low >>= PIPE_FRAME_LOW_SHIFT; |
Ville Syrjälä | 391f75e | 2013-09-25 19:55:26 +0300 | [diff] [blame] | 611 | |
| 612 | /* |
| 613 | * The frame counter increments at beginning of active. |
| 614 | * Cook up a vblank counter by also checking the pixel |
| 615 | * counter against vblank start. |
| 616 | */ |
Ville Syrjälä | edc08d0 | 2013-11-06 13:56:27 -0200 | [diff] [blame] | 617 | return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 618 | } |
| 619 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 620 | static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe) |
Jesse Barnes | 9880b7a | 2009-02-06 10:22:41 -0800 | [diff] [blame] | 621 | { |
| 622 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 623 | int reg = PIPE_FRMCOUNT_GM45(pipe); |
Jesse Barnes | 9880b7a | 2009-02-06 10:22:41 -0800 | [diff] [blame] | 624 | |
| 625 | if (!i915_pipe_enabled(dev, pipe)) { |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 626 | DRM_DEBUG_DRIVER("trying to get vblank count for disabled " |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 627 | "pipe %c\n", pipe_name(pipe)); |
Jesse Barnes | 9880b7a | 2009-02-06 10:22:41 -0800 | [diff] [blame] | 628 | return 0; |
| 629 | } |
| 630 | |
| 631 | return I915_READ(reg); |
| 632 | } |
| 633 | |
Mario Kleiner | ad3543e | 2013-10-30 05:13:08 +0100 | [diff] [blame] | 634 | /* raw reads, only for fast reads of display block, no need for forcewake etc. */ |
| 635 | #define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__)) |
| 636 | #define __raw_i915_read16(dev_priv__, reg__) readw((dev_priv__)->regs + (reg__)) |
| 637 | |
Ville Syrjälä | 095163b | 2013-10-29 00:04:43 +0200 | [diff] [blame] | 638 | static bool ilk_pipe_in_vblank_locked(struct drm_device *dev, enum pipe pipe) |
Ville Syrjälä | 54ddcbd | 2013-09-23 13:02:07 +0300 | [diff] [blame] | 639 | { |
| 640 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 641 | uint32_t status; |
| 642 | |
Ville Syrjälä | 095163b | 2013-10-29 00:04:43 +0200 | [diff] [blame] | 643 | if (INTEL_INFO(dev)->gen < 7) { |
Ville Syrjälä | 54ddcbd | 2013-09-23 13:02:07 +0300 | [diff] [blame] | 644 | status = pipe == PIPE_A ? |
| 645 | DE_PIPEA_VBLANK : |
| 646 | DE_PIPEB_VBLANK; |
Ville Syrjälä | 54ddcbd | 2013-09-23 13:02:07 +0300 | [diff] [blame] | 647 | } else { |
| 648 | switch (pipe) { |
| 649 | default: |
| 650 | case PIPE_A: |
| 651 | status = DE_PIPEA_VBLANK_IVB; |
| 652 | break; |
| 653 | case PIPE_B: |
| 654 | status = DE_PIPEB_VBLANK_IVB; |
| 655 | break; |
| 656 | case PIPE_C: |
| 657 | status = DE_PIPEC_VBLANK_IVB; |
| 658 | break; |
| 659 | } |
Ville Syrjälä | 54ddcbd | 2013-09-23 13:02:07 +0300 | [diff] [blame] | 660 | } |
Mario Kleiner | ad3543e | 2013-10-30 05:13:08 +0100 | [diff] [blame] | 661 | |
Ville Syrjälä | 095163b | 2013-10-29 00:04:43 +0200 | [diff] [blame] | 662 | return __raw_i915_read32(dev_priv, DEISR) & status; |
Ville Syrjälä | 54ddcbd | 2013-09-23 13:02:07 +0300 | [diff] [blame] | 663 | } |
| 664 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 665 | static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe, |
Ville Syrjälä | abca9e45 | 2013-10-28 20:50:48 +0200 | [diff] [blame] | 666 | unsigned int flags, int *vpos, int *hpos, |
| 667 | ktime_t *stime, ktime_t *etime) |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 668 | { |
Ville Syrjälä | c2baf4b | 2013-09-23 14:48:50 +0300 | [diff] [blame] | 669 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 670 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 671 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 672 | const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode; |
Ville Syrjälä | 3aa18df | 2013-10-11 19:10:32 +0300 | [diff] [blame] | 673 | int position; |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 674 | int vbl_start, vbl_end, htotal, vtotal; |
| 675 | bool in_vbl = true; |
| 676 | int ret = 0; |
Mario Kleiner | ad3543e | 2013-10-30 05:13:08 +0100 | [diff] [blame] | 677 | unsigned long irqflags; |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 678 | |
Ville Syrjälä | c2baf4b | 2013-09-23 14:48:50 +0300 | [diff] [blame] | 679 | if (!intel_crtc->active) { |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 680 | DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled " |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 681 | "pipe %c\n", pipe_name(pipe)); |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 682 | return 0; |
| 683 | } |
| 684 | |
Ville Syrjälä | c2baf4b | 2013-09-23 14:48:50 +0300 | [diff] [blame] | 685 | htotal = mode->crtc_htotal; |
| 686 | vtotal = mode->crtc_vtotal; |
| 687 | vbl_start = mode->crtc_vblank_start; |
| 688 | vbl_end = mode->crtc_vblank_end; |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 689 | |
Ville Syrjälä | d31faf6 | 2013-10-28 16:31:41 +0200 | [diff] [blame] | 690 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) { |
| 691 | vbl_start = DIV_ROUND_UP(vbl_start, 2); |
| 692 | vbl_end /= 2; |
| 693 | vtotal /= 2; |
| 694 | } |
| 695 | |
Ville Syrjälä | c2baf4b | 2013-09-23 14:48:50 +0300 | [diff] [blame] | 696 | ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE; |
| 697 | |
Mario Kleiner | ad3543e | 2013-10-30 05:13:08 +0100 | [diff] [blame] | 698 | /* |
| 699 | * Lock uncore.lock, as we will do multiple timing critical raw |
| 700 | * register reads, potentially with preemption disabled, so the |
| 701 | * following code must not block on uncore.lock. |
| 702 | */ |
| 703 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 704 | |
| 705 | /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */ |
| 706 | |
| 707 | /* Get optional system timestamp before query. */ |
| 708 | if (stime) |
| 709 | *stime = ktime_get(); |
| 710 | |
Ville Syrjälä | 7c06b08 | 2013-10-11 21:52:43 +0300 | [diff] [blame] | 711 | if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 712 | /* No obvious pixelcount register. Only query vertical |
| 713 | * scanout position from Display scan line register. |
| 714 | */ |
Ville Syrjälä | 7c06b08 | 2013-10-11 21:52:43 +0300 | [diff] [blame] | 715 | if (IS_GEN2(dev)) |
Mario Kleiner | ad3543e | 2013-10-30 05:13:08 +0100 | [diff] [blame] | 716 | position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2; |
Ville Syrjälä | 7c06b08 | 2013-10-11 21:52:43 +0300 | [diff] [blame] | 717 | else |
Mario Kleiner | ad3543e | 2013-10-30 05:13:08 +0100 | [diff] [blame] | 718 | position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3; |
Ville Syrjälä | 54ddcbd | 2013-09-23 13:02:07 +0300 | [diff] [blame] | 719 | |
Ville Syrjälä | 095163b | 2013-10-29 00:04:43 +0200 | [diff] [blame] | 720 | if (HAS_PCH_SPLIT(dev)) { |
| 721 | /* |
| 722 | * The scanline counter increments at the leading edge |
| 723 | * of hsync, ie. it completely misses the active portion |
| 724 | * of the line. Fix up the counter at both edges of vblank |
| 725 | * to get a more accurate picture whether we're in vblank |
| 726 | * or not. |
| 727 | */ |
| 728 | in_vbl = ilk_pipe_in_vblank_locked(dev, pipe); |
| 729 | if ((in_vbl && position == vbl_start - 1) || |
| 730 | (!in_vbl && position == vbl_end - 1)) |
| 731 | position = (position + 1) % vtotal; |
| 732 | } else { |
| 733 | /* |
| 734 | * ISR vblank status bits don't work the way we'd want |
| 735 | * them to work on non-PCH platforms (for |
| 736 | * ilk_pipe_in_vblank_locked()), and there doesn't |
| 737 | * appear any other way to determine if we're currently |
| 738 | * in vblank. |
| 739 | * |
| 740 | * Instead let's assume that we're already in vblank if |
| 741 | * we got called from the vblank interrupt and the |
| 742 | * scanline counter value indicates that we're on the |
| 743 | * line just prior to vblank start. This should result |
| 744 | * in the correct answer, unless the vblank interrupt |
| 745 | * delivery really got delayed for almost exactly one |
| 746 | * full frame/field. |
| 747 | */ |
| 748 | if (flags & DRM_CALLED_FROM_VBLIRQ && |
| 749 | position == vbl_start - 1) { |
| 750 | position = (position + 1) % vtotal; |
| 751 | |
| 752 | /* Signal this correction as "applied". */ |
| 753 | ret |= 0x8; |
| 754 | } |
| 755 | } |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 756 | } else { |
| 757 | /* Have access to pixelcount since start of frame. |
| 758 | * We can split this into vertical and horizontal |
| 759 | * scanout position. |
| 760 | */ |
Mario Kleiner | ad3543e | 2013-10-30 05:13:08 +0100 | [diff] [blame] | 761 | position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT; |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 762 | |
Ville Syrjälä | 3aa18df | 2013-10-11 19:10:32 +0300 | [diff] [blame] | 763 | /* convert to pixel counts */ |
| 764 | vbl_start *= htotal; |
| 765 | vbl_end *= htotal; |
| 766 | vtotal *= htotal; |
| 767 | } |
| 768 | |
Mario Kleiner | ad3543e | 2013-10-30 05:13:08 +0100 | [diff] [blame] | 769 | /* Get optional system timestamp after query. */ |
| 770 | if (etime) |
| 771 | *etime = ktime_get(); |
| 772 | |
| 773 | /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */ |
| 774 | |
| 775 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
| 776 | |
Ville Syrjälä | 3aa18df | 2013-10-11 19:10:32 +0300 | [diff] [blame] | 777 | in_vbl = position >= vbl_start && position < vbl_end; |
| 778 | |
| 779 | /* |
| 780 | * While in vblank, position will be negative |
| 781 | * counting up towards 0 at vbl_end. And outside |
| 782 | * vblank, position will be positive counting |
| 783 | * up since vbl_end. |
| 784 | */ |
| 785 | if (position >= vbl_start) |
| 786 | position -= vbl_end; |
| 787 | else |
| 788 | position += vtotal - vbl_end; |
| 789 | |
Ville Syrjälä | 7c06b08 | 2013-10-11 21:52:43 +0300 | [diff] [blame] | 790 | if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { |
Ville Syrjälä | 3aa18df | 2013-10-11 19:10:32 +0300 | [diff] [blame] | 791 | *vpos = position; |
| 792 | *hpos = 0; |
| 793 | } else { |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 794 | *vpos = position / htotal; |
| 795 | *hpos = position - (*vpos * htotal); |
| 796 | } |
| 797 | |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 798 | /* In vblank? */ |
| 799 | if (in_vbl) |
| 800 | ret |= DRM_SCANOUTPOS_INVBL; |
| 801 | |
| 802 | return ret; |
| 803 | } |
| 804 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 805 | static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe, |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 806 | int *max_error, |
| 807 | struct timeval *vblank_time, |
| 808 | unsigned flags) |
| 809 | { |
Chris Wilson | 4041b85 | 2011-01-22 10:07:56 +0000 | [diff] [blame] | 810 | struct drm_crtc *crtc; |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 811 | |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 812 | if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) { |
Chris Wilson | 4041b85 | 2011-01-22 10:07:56 +0000 | [diff] [blame] | 813 | DRM_ERROR("Invalid crtc %d\n", pipe); |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 814 | return -EINVAL; |
| 815 | } |
| 816 | |
| 817 | /* Get drm_crtc to timestamp: */ |
Chris Wilson | 4041b85 | 2011-01-22 10:07:56 +0000 | [diff] [blame] | 818 | crtc = intel_get_crtc_for_pipe(dev, pipe); |
| 819 | if (crtc == NULL) { |
| 820 | DRM_ERROR("Invalid crtc %d\n", pipe); |
| 821 | return -EINVAL; |
| 822 | } |
| 823 | |
| 824 | if (!crtc->enabled) { |
| 825 | DRM_DEBUG_KMS("crtc %d is disabled\n", pipe); |
| 826 | return -EBUSY; |
| 827 | } |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 828 | |
| 829 | /* Helper routine in DRM core does all the work: */ |
Chris Wilson | 4041b85 | 2011-01-22 10:07:56 +0000 | [diff] [blame] | 830 | return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error, |
| 831 | vblank_time, flags, |
Ville Syrjälä | 7da903e | 2013-10-26 17:57:31 +0300 | [diff] [blame] | 832 | crtc, |
| 833 | &to_intel_crtc(crtc)->config.adjusted_mode); |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 834 | } |
| 835 | |
Jani Nikula | 67c347f | 2013-09-17 14:26:34 +0300 | [diff] [blame] | 836 | static bool intel_hpd_irq_event(struct drm_device *dev, |
| 837 | struct drm_connector *connector) |
Egbert Eich | 321a1b3 | 2013-04-11 16:00:26 +0200 | [diff] [blame] | 838 | { |
| 839 | enum drm_connector_status old_status; |
| 840 | |
| 841 | WARN_ON(!mutex_is_locked(&dev->mode_config.mutex)); |
| 842 | old_status = connector->status; |
| 843 | |
| 844 | connector->status = connector->funcs->detect(connector, false); |
Jani Nikula | 67c347f | 2013-09-17 14:26:34 +0300 | [diff] [blame] | 845 | if (old_status == connector->status) |
| 846 | return false; |
| 847 | |
| 848 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n", |
Egbert Eich | 321a1b3 | 2013-04-11 16:00:26 +0200 | [diff] [blame] | 849 | connector->base.id, |
| 850 | drm_get_connector_name(connector), |
Jani Nikula | 67c347f | 2013-09-17 14:26:34 +0300 | [diff] [blame] | 851 | drm_get_connector_status_name(old_status), |
| 852 | drm_get_connector_status_name(connector->status)); |
| 853 | |
| 854 | return true; |
Egbert Eich | 321a1b3 | 2013-04-11 16:00:26 +0200 | [diff] [blame] | 855 | } |
| 856 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 857 | /* |
| 858 | * Handle hotplug events outside the interrupt handler proper. |
| 859 | */ |
Egbert Eich | ac4c16c | 2013-04-16 13:36:58 +0200 | [diff] [blame] | 860 | #define I915_REENABLE_HOTPLUG_DELAY (2*60*1000) |
| 861 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 862 | static void i915_hotplug_work_func(struct work_struct *work) |
| 863 | { |
| 864 | drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, |
| 865 | hotplug_work); |
| 866 | struct drm_device *dev = dev_priv->dev; |
Keith Packard | c31c4ba | 2009-05-06 11:48:58 -0700 | [diff] [blame] | 867 | struct drm_mode_config *mode_config = &dev->mode_config; |
Egbert Eich | cd569ae | 2013-04-16 13:36:57 +0200 | [diff] [blame] | 868 | struct intel_connector *intel_connector; |
| 869 | struct intel_encoder *intel_encoder; |
| 870 | struct drm_connector *connector; |
| 871 | unsigned long irqflags; |
| 872 | bool hpd_disabled = false; |
Egbert Eich | 321a1b3 | 2013-04-11 16:00:26 +0200 | [diff] [blame] | 873 | bool changed = false; |
Egbert Eich | 142e239 | 2013-04-11 15:57:57 +0200 | [diff] [blame] | 874 | u32 hpd_event_bits; |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 875 | |
Daniel Vetter | 52d7ece | 2012-12-01 21:03:22 +0100 | [diff] [blame] | 876 | /* HPD irq before everything is fully set up. */ |
| 877 | if (!dev_priv->enable_hotplug_processing) |
| 878 | return; |
| 879 | |
Keith Packard | a65e34c | 2011-07-25 10:04:56 -0700 | [diff] [blame] | 880 | mutex_lock(&mode_config->mutex); |
Jesse Barnes | e67189ab | 2011-02-11 14:44:51 -0800 | [diff] [blame] | 881 | DRM_DEBUG_KMS("running encoder hotplug functions\n"); |
| 882 | |
Egbert Eich | cd569ae | 2013-04-16 13:36:57 +0200 | [diff] [blame] | 883 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Egbert Eich | 142e239 | 2013-04-11 15:57:57 +0200 | [diff] [blame] | 884 | |
| 885 | hpd_event_bits = dev_priv->hpd_event_bits; |
| 886 | dev_priv->hpd_event_bits = 0; |
Egbert Eich | cd569ae | 2013-04-16 13:36:57 +0200 | [diff] [blame] | 887 | list_for_each_entry(connector, &mode_config->connector_list, head) { |
| 888 | intel_connector = to_intel_connector(connector); |
| 889 | intel_encoder = intel_connector->encoder; |
| 890 | if (intel_encoder->hpd_pin > HPD_NONE && |
| 891 | dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED && |
| 892 | connector->polled == DRM_CONNECTOR_POLL_HPD) { |
| 893 | DRM_INFO("HPD interrupt storm detected on connector %s: " |
| 894 | "switching from hotplug detection to polling\n", |
| 895 | drm_get_connector_name(connector)); |
| 896 | dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED; |
| 897 | connector->polled = DRM_CONNECTOR_POLL_CONNECT |
| 898 | | DRM_CONNECTOR_POLL_DISCONNECT; |
| 899 | hpd_disabled = true; |
| 900 | } |
Egbert Eich | 142e239 | 2013-04-11 15:57:57 +0200 | [diff] [blame] | 901 | if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) { |
| 902 | DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n", |
| 903 | drm_get_connector_name(connector), intel_encoder->hpd_pin); |
| 904 | } |
Egbert Eich | cd569ae | 2013-04-16 13:36:57 +0200 | [diff] [blame] | 905 | } |
| 906 | /* if there were no outputs to poll, poll was disabled, |
| 907 | * therefore make sure it's enabled when disabling HPD on |
| 908 | * some connectors */ |
Egbert Eich | ac4c16c | 2013-04-16 13:36:58 +0200 | [diff] [blame] | 909 | if (hpd_disabled) { |
Egbert Eich | cd569ae | 2013-04-16 13:36:57 +0200 | [diff] [blame] | 910 | drm_kms_helper_poll_enable(dev); |
Egbert Eich | ac4c16c | 2013-04-16 13:36:58 +0200 | [diff] [blame] | 911 | mod_timer(&dev_priv->hotplug_reenable_timer, |
| 912 | jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY)); |
| 913 | } |
Egbert Eich | cd569ae | 2013-04-16 13:36:57 +0200 | [diff] [blame] | 914 | |
| 915 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 916 | |
Egbert Eich | 321a1b3 | 2013-04-11 16:00:26 +0200 | [diff] [blame] | 917 | list_for_each_entry(connector, &mode_config->connector_list, head) { |
| 918 | intel_connector = to_intel_connector(connector); |
| 919 | intel_encoder = intel_connector->encoder; |
| 920 | if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) { |
| 921 | if (intel_encoder->hot_plug) |
| 922 | intel_encoder->hot_plug(intel_encoder); |
| 923 | if (intel_hpd_irq_event(dev, connector)) |
| 924 | changed = true; |
| 925 | } |
| 926 | } |
Keith Packard | 40ee338 | 2011-07-28 15:31:19 -0700 | [diff] [blame] | 927 | mutex_unlock(&mode_config->mutex); |
| 928 | |
Egbert Eich | 321a1b3 | 2013-04-11 16:00:26 +0200 | [diff] [blame] | 929 | if (changed) |
| 930 | drm_kms_helper_hotplug_event(dev); |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 931 | } |
| 932 | |
Ville Syrjälä | 3ca1cce | 2014-01-17 13:43:51 +0200 | [diff] [blame] | 933 | static void intel_hpd_irq_uninstall(struct drm_i915_private *dev_priv) |
| 934 | { |
| 935 | del_timer_sync(&dev_priv->hotplug_reenable_timer); |
| 936 | } |
| 937 | |
Daniel Vetter | d0ecd7e | 2013-07-04 23:35:25 +0200 | [diff] [blame] | 938 | static void ironlake_rps_change_irq_handler(struct drm_device *dev) |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 939 | { |
| 940 | drm_i915_private_t *dev_priv = dev->dev_private; |
Matthew Garrett | b5b72e8 | 2010-02-02 18:30:47 +0000 | [diff] [blame] | 941 | u32 busy_up, busy_down, max_avg, min_avg; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 942 | u8 new_delay; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 943 | |
Daniel Vetter | d0ecd7e | 2013-07-04 23:35:25 +0200 | [diff] [blame] | 944 | spin_lock(&mchdev_lock); |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 945 | |
Daniel Vetter | 73edd18f | 2012-08-08 23:35:37 +0200 | [diff] [blame] | 946 | I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS)); |
| 947 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 948 | new_delay = dev_priv->ips.cur_delay; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 949 | |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 950 | I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG); |
Matthew Garrett | b5b72e8 | 2010-02-02 18:30:47 +0000 | [diff] [blame] | 951 | busy_up = I915_READ(RCPREVBSYTUPAVG); |
| 952 | busy_down = I915_READ(RCPREVBSYTDNAVG); |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 953 | max_avg = I915_READ(RCBMAXAVG); |
| 954 | min_avg = I915_READ(RCBMINAVG); |
| 955 | |
| 956 | /* Handle RCS change request from hw */ |
Matthew Garrett | b5b72e8 | 2010-02-02 18:30:47 +0000 | [diff] [blame] | 957 | if (busy_up > max_avg) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 958 | if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay) |
| 959 | new_delay = dev_priv->ips.cur_delay - 1; |
| 960 | if (new_delay < dev_priv->ips.max_delay) |
| 961 | new_delay = dev_priv->ips.max_delay; |
Matthew Garrett | b5b72e8 | 2010-02-02 18:30:47 +0000 | [diff] [blame] | 962 | } else if (busy_down < min_avg) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 963 | if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay) |
| 964 | new_delay = dev_priv->ips.cur_delay + 1; |
| 965 | if (new_delay > dev_priv->ips.min_delay) |
| 966 | new_delay = dev_priv->ips.min_delay; |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 967 | } |
| 968 | |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 969 | if (ironlake_set_drps(dev, new_delay)) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 970 | dev_priv->ips.cur_delay = new_delay; |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 971 | |
Daniel Vetter | d0ecd7e | 2013-07-04 23:35:25 +0200 | [diff] [blame] | 972 | spin_unlock(&mchdev_lock); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 973 | |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 974 | return; |
| 975 | } |
| 976 | |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 977 | static void notify_ring(struct drm_device *dev, |
| 978 | struct intel_ring_buffer *ring) |
| 979 | { |
Chris Wilson | 475553d | 2011-01-20 09:52:56 +0000 | [diff] [blame] | 980 | if (ring->obj == NULL) |
| 981 | return; |
| 982 | |
Chris Wilson | 814e9b5 | 2013-09-23 17:33:19 -0300 | [diff] [blame] | 983 | trace_i915_gem_request_complete(ring); |
Chris Wilson | 9862e60 | 2011-01-04 22:22:17 +0000 | [diff] [blame] | 984 | |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 985 | wake_up_all(&ring->irq_queue); |
Mika Kuoppala | 10cd45b | 2013-07-03 17:22:08 +0300 | [diff] [blame] | 986 | i915_queue_hangcheck(dev); |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 987 | } |
| 988 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 989 | void gen6_set_pm_mask(struct drm_i915_private *dev_priv, |
Deepak S | 2754436 | 2014-01-27 21:35:05 +0530 | [diff] [blame] | 990 | u32 pm_iir, int new_delay) |
| 991 | { |
| 992 | if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) { |
| 993 | if (new_delay >= dev_priv->rps.max_delay) { |
| 994 | /* Mask UP THRESHOLD Interrupts */ |
| 995 | I915_WRITE(GEN6_PMINTRMSK, |
| 996 | I915_READ(GEN6_PMINTRMSK) | |
| 997 | GEN6_PM_RP_UP_THRESHOLD); |
| 998 | dev_priv->rps.rp_up_masked = true; |
| 999 | } |
| 1000 | if (dev_priv->rps.rp_down_masked) { |
| 1001 | /* UnMask DOWN THRESHOLD Interrupts */ |
| 1002 | I915_WRITE(GEN6_PMINTRMSK, |
| 1003 | I915_READ(GEN6_PMINTRMSK) & |
| 1004 | ~GEN6_PM_RP_DOWN_THRESHOLD); |
| 1005 | dev_priv->rps.rp_down_masked = false; |
| 1006 | } |
| 1007 | } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) { |
| 1008 | if (new_delay <= dev_priv->rps.min_delay) { |
| 1009 | /* Mask DOWN THRESHOLD Interrupts */ |
| 1010 | I915_WRITE(GEN6_PMINTRMSK, |
| 1011 | I915_READ(GEN6_PMINTRMSK) | |
| 1012 | GEN6_PM_RP_DOWN_THRESHOLD); |
| 1013 | dev_priv->rps.rp_down_masked = true; |
| 1014 | } |
| 1015 | |
| 1016 | if (dev_priv->rps.rp_up_masked) { |
| 1017 | /* UnMask UP THRESHOLD Interrupts */ |
| 1018 | I915_WRITE(GEN6_PMINTRMSK, |
| 1019 | I915_READ(GEN6_PMINTRMSK) & |
| 1020 | ~GEN6_PM_RP_UP_THRESHOLD); |
| 1021 | dev_priv->rps.rp_up_masked = false; |
| 1022 | } |
| 1023 | } |
| 1024 | } |
| 1025 | |
Ben Widawsky | 4912d04 | 2011-04-25 11:25:20 -0700 | [diff] [blame] | 1026 | static void gen6_pm_rps_work(struct work_struct *work) |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 1027 | { |
Ben Widawsky | 4912d04 | 2011-04-25 11:25:20 -0700 | [diff] [blame] | 1028 | drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, |
Daniel Vetter | c6a828d | 2012-08-08 23:35:35 +0200 | [diff] [blame] | 1029 | rps.work); |
Paulo Zanoni | edbfdb4 | 2013-08-06 18:57:13 -0300 | [diff] [blame] | 1030 | u32 pm_iir; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 1031 | int new_delay, adj; |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 1032 | |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 1033 | spin_lock_irq(&dev_priv->irq_lock); |
Daniel Vetter | c6a828d | 2012-08-08 23:35:35 +0200 | [diff] [blame] | 1034 | pm_iir = dev_priv->rps.pm_iir; |
| 1035 | dev_priv->rps.pm_iir = 0; |
Ben Widawsky | 4848405 | 2013-05-28 19:22:27 -0700 | [diff] [blame] | 1036 | /* Make sure not to corrupt PMIMR state used by ringbuffer code */ |
Paulo Zanoni | edbfdb4 | 2013-08-06 18:57:13 -0300 | [diff] [blame] | 1037 | snb_enable_pm_irq(dev_priv, GEN6_PM_RPS_EVENTS); |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 1038 | spin_unlock_irq(&dev_priv->irq_lock); |
Ben Widawsky | 4912d04 | 2011-04-25 11:25:20 -0700 | [diff] [blame] | 1039 | |
Paulo Zanoni | 60611c1 | 2013-08-15 11:50:01 -0300 | [diff] [blame] | 1040 | /* Make sure we didn't queue anything we're not going to process. */ |
| 1041 | WARN_ON(pm_iir & ~GEN6_PM_RPS_EVENTS); |
| 1042 | |
Ben Widawsky | 4848405 | 2013-05-28 19:22:27 -0700 | [diff] [blame] | 1043 | if ((pm_iir & GEN6_PM_RPS_EVENTS) == 0) |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 1044 | return; |
| 1045 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 1046 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 1047 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 1048 | adj = dev_priv->rps.last_adj; |
Ville Syrjälä | 7425034 | 2013-06-25 21:38:11 +0300 | [diff] [blame] | 1049 | if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) { |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 1050 | if (adj > 0) |
| 1051 | adj *= 2; |
| 1052 | else |
| 1053 | adj = 1; |
| 1054 | new_delay = dev_priv->rps.cur_delay + adj; |
Ville Syrjälä | 7425034 | 2013-06-25 21:38:11 +0300 | [diff] [blame] | 1055 | |
| 1056 | /* |
| 1057 | * For better performance, jump directly |
| 1058 | * to RPe if we're below it. |
| 1059 | */ |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 1060 | if (new_delay < dev_priv->rps.rpe_delay) |
Ville Syrjälä | 7425034 | 2013-06-25 21:38:11 +0300 | [diff] [blame] | 1061 | new_delay = dev_priv->rps.rpe_delay; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 1062 | } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) { |
| 1063 | if (dev_priv->rps.cur_delay > dev_priv->rps.rpe_delay) |
| 1064 | new_delay = dev_priv->rps.rpe_delay; |
| 1065 | else |
| 1066 | new_delay = dev_priv->rps.min_delay; |
| 1067 | adj = 0; |
| 1068 | } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) { |
| 1069 | if (adj < 0) |
| 1070 | adj *= 2; |
| 1071 | else |
| 1072 | adj = -1; |
| 1073 | new_delay = dev_priv->rps.cur_delay + adj; |
| 1074 | } else { /* unknown event */ |
| 1075 | new_delay = dev_priv->rps.cur_delay; |
| 1076 | } |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 1077 | |
Ben Widawsky | 7924963 | 2012-09-07 19:43:42 -0700 | [diff] [blame] | 1078 | /* sysfs frequency interfaces may have snuck in while servicing the |
| 1079 | * interrupt |
| 1080 | */ |
Ville Syrjälä | 1272e7b | 2013-11-07 19:57:49 +0200 | [diff] [blame] | 1081 | new_delay = clamp_t(int, new_delay, |
| 1082 | dev_priv->rps.min_delay, dev_priv->rps.max_delay); |
Deepak S | 2754436 | 2014-01-27 21:35:05 +0530 | [diff] [blame] | 1083 | |
| 1084 | gen6_set_pm_mask(dev_priv, pm_iir, new_delay); |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 1085 | dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_delay; |
| 1086 | |
| 1087 | if (IS_VALLEYVIEW(dev_priv->dev)) |
| 1088 | valleyview_set_rps(dev_priv->dev, new_delay); |
| 1089 | else |
| 1090 | gen6_set_rps(dev_priv->dev, new_delay); |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 1091 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 1092 | mutex_unlock(&dev_priv->rps.hw_lock); |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 1093 | } |
| 1094 | |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1095 | |
| 1096 | /** |
| 1097 | * ivybridge_parity_work - Workqueue called when a parity error interrupt |
| 1098 | * occurred. |
| 1099 | * @work: workqueue struct |
| 1100 | * |
| 1101 | * Doesn't actually do anything except notify userspace. As a consequence of |
| 1102 | * this event, userspace should try to remap the bad rows since statistically |
| 1103 | * it is likely the same row is more likely to go bad again. |
| 1104 | */ |
| 1105 | static void ivybridge_parity_work(struct work_struct *work) |
| 1106 | { |
| 1107 | drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, |
Daniel Vetter | a4da4fa | 2012-11-02 19:55:07 +0100 | [diff] [blame] | 1108 | l3_parity.error_work); |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1109 | u32 error_status, row, bank, subbank; |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1110 | char *parity_event[6]; |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1111 | uint32_t misccpctl; |
| 1112 | unsigned long flags; |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1113 | uint8_t slice = 0; |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1114 | |
| 1115 | /* We must turn off DOP level clock gating to access the L3 registers. |
| 1116 | * In order to prevent a get/put style interface, acquire struct mutex |
| 1117 | * any time we access those registers. |
| 1118 | */ |
| 1119 | mutex_lock(&dev_priv->dev->struct_mutex); |
| 1120 | |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1121 | /* If we've screwed up tracking, just let the interrupt fire again */ |
| 1122 | if (WARN_ON(!dev_priv->l3_parity.which_slice)) |
| 1123 | goto out; |
| 1124 | |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1125 | misccpctl = I915_READ(GEN7_MISCCPCTL); |
| 1126 | I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); |
| 1127 | POSTING_READ(GEN7_MISCCPCTL); |
| 1128 | |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1129 | while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) { |
| 1130 | u32 reg; |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1131 | |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1132 | slice--; |
| 1133 | if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev))) |
| 1134 | break; |
| 1135 | |
| 1136 | dev_priv->l3_parity.which_slice &= ~(1<<slice); |
| 1137 | |
| 1138 | reg = GEN7_L3CDERRST1 + (slice * 0x200); |
| 1139 | |
| 1140 | error_status = I915_READ(reg); |
| 1141 | row = GEN7_PARITY_ERROR_ROW(error_status); |
| 1142 | bank = GEN7_PARITY_ERROR_BANK(error_status); |
| 1143 | subbank = GEN7_PARITY_ERROR_SUBBANK(error_status); |
| 1144 | |
| 1145 | I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE); |
| 1146 | POSTING_READ(reg); |
| 1147 | |
| 1148 | parity_event[0] = I915_L3_PARITY_UEVENT "=1"; |
| 1149 | parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row); |
| 1150 | parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank); |
| 1151 | parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank); |
| 1152 | parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice); |
| 1153 | parity_event[5] = NULL; |
| 1154 | |
Dave Airlie | 5bdebb1 | 2013-10-11 14:07:25 +1000 | [diff] [blame] | 1155 | kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj, |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1156 | KOBJ_CHANGE, parity_event); |
| 1157 | |
| 1158 | DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n", |
| 1159 | slice, row, bank, subbank); |
| 1160 | |
| 1161 | kfree(parity_event[4]); |
| 1162 | kfree(parity_event[3]); |
| 1163 | kfree(parity_event[2]); |
| 1164 | kfree(parity_event[1]); |
| 1165 | } |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1166 | |
| 1167 | I915_WRITE(GEN7_MISCCPCTL, misccpctl); |
| 1168 | |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1169 | out: |
| 1170 | WARN_ON(dev_priv->l3_parity.which_slice); |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1171 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1172 | ilk_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev)); |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1173 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
| 1174 | |
| 1175 | mutex_unlock(&dev_priv->dev->struct_mutex); |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1176 | } |
| 1177 | |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1178 | static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir) |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1179 | { |
| 1180 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1181 | |
Ben Widawsky | 040d2ba | 2013-09-19 11:01:40 -0700 | [diff] [blame] | 1182 | if (!HAS_L3_DPF(dev)) |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1183 | return; |
| 1184 | |
Daniel Vetter | d0ecd7e | 2013-07-04 23:35:25 +0200 | [diff] [blame] | 1185 | spin_lock(&dev_priv->irq_lock); |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1186 | ilk_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev)); |
Daniel Vetter | d0ecd7e | 2013-07-04 23:35:25 +0200 | [diff] [blame] | 1187 | spin_unlock(&dev_priv->irq_lock); |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1188 | |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1189 | iir &= GT_PARITY_ERROR(dev); |
| 1190 | if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1) |
| 1191 | dev_priv->l3_parity.which_slice |= 1 << 1; |
| 1192 | |
| 1193 | if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT) |
| 1194 | dev_priv->l3_parity.which_slice |= 1 << 0; |
| 1195 | |
Daniel Vetter | a4da4fa | 2012-11-02 19:55:07 +0100 | [diff] [blame] | 1196 | queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work); |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1197 | } |
| 1198 | |
Paulo Zanoni | f1af8fc | 2013-07-12 19:56:30 -0300 | [diff] [blame] | 1199 | static void ilk_gt_irq_handler(struct drm_device *dev, |
| 1200 | struct drm_i915_private *dev_priv, |
| 1201 | u32 gt_iir) |
| 1202 | { |
| 1203 | if (gt_iir & |
| 1204 | (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT)) |
| 1205 | notify_ring(dev, &dev_priv->ring[RCS]); |
| 1206 | if (gt_iir & ILK_BSD_USER_INTERRUPT) |
| 1207 | notify_ring(dev, &dev_priv->ring[VCS]); |
| 1208 | } |
| 1209 | |
Daniel Vetter | e7b4c6b | 2012-03-30 20:24:35 +0200 | [diff] [blame] | 1210 | static void snb_gt_irq_handler(struct drm_device *dev, |
| 1211 | struct drm_i915_private *dev_priv, |
| 1212 | u32 gt_iir) |
| 1213 | { |
| 1214 | |
Ben Widawsky | cc609d5 | 2013-05-28 19:22:29 -0700 | [diff] [blame] | 1215 | if (gt_iir & |
| 1216 | (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT)) |
Daniel Vetter | e7b4c6b | 2012-03-30 20:24:35 +0200 | [diff] [blame] | 1217 | notify_ring(dev, &dev_priv->ring[RCS]); |
Ben Widawsky | cc609d5 | 2013-05-28 19:22:29 -0700 | [diff] [blame] | 1218 | if (gt_iir & GT_BSD_USER_INTERRUPT) |
Daniel Vetter | e7b4c6b | 2012-03-30 20:24:35 +0200 | [diff] [blame] | 1219 | notify_ring(dev, &dev_priv->ring[VCS]); |
Ben Widawsky | cc609d5 | 2013-05-28 19:22:29 -0700 | [diff] [blame] | 1220 | if (gt_iir & GT_BLT_USER_INTERRUPT) |
Daniel Vetter | e7b4c6b | 2012-03-30 20:24:35 +0200 | [diff] [blame] | 1221 | notify_ring(dev, &dev_priv->ring[BCS]); |
| 1222 | |
Ben Widawsky | cc609d5 | 2013-05-28 19:22:29 -0700 | [diff] [blame] | 1223 | if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT | |
| 1224 | GT_BSD_CS_ERROR_INTERRUPT | |
| 1225 | GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) { |
Daniel Vetter | e7b4c6b | 2012-03-30 20:24:35 +0200 | [diff] [blame] | 1226 | DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir); |
| 1227 | i915_handle_error(dev, false); |
| 1228 | } |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1229 | |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1230 | if (gt_iir & GT_PARITY_ERROR(dev)) |
| 1231 | ivybridge_parity_error_irq_handler(dev, gt_iir); |
Daniel Vetter | e7b4c6b | 2012-03-30 20:24:35 +0200 | [diff] [blame] | 1232 | } |
| 1233 | |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 1234 | static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev, |
| 1235 | struct drm_i915_private *dev_priv, |
| 1236 | u32 master_ctl) |
| 1237 | { |
| 1238 | u32 rcs, bcs, vcs; |
| 1239 | uint32_t tmp = 0; |
| 1240 | irqreturn_t ret = IRQ_NONE; |
| 1241 | |
| 1242 | if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) { |
| 1243 | tmp = I915_READ(GEN8_GT_IIR(0)); |
| 1244 | if (tmp) { |
| 1245 | ret = IRQ_HANDLED; |
| 1246 | rcs = tmp >> GEN8_RCS_IRQ_SHIFT; |
| 1247 | bcs = tmp >> GEN8_BCS_IRQ_SHIFT; |
| 1248 | if (rcs & GT_RENDER_USER_INTERRUPT) |
| 1249 | notify_ring(dev, &dev_priv->ring[RCS]); |
| 1250 | if (bcs & GT_RENDER_USER_INTERRUPT) |
| 1251 | notify_ring(dev, &dev_priv->ring[BCS]); |
| 1252 | I915_WRITE(GEN8_GT_IIR(0), tmp); |
| 1253 | } else |
| 1254 | DRM_ERROR("The master control interrupt lied (GT0)!\n"); |
| 1255 | } |
| 1256 | |
| 1257 | if (master_ctl & GEN8_GT_VCS1_IRQ) { |
| 1258 | tmp = I915_READ(GEN8_GT_IIR(1)); |
| 1259 | if (tmp) { |
| 1260 | ret = IRQ_HANDLED; |
| 1261 | vcs = tmp >> GEN8_VCS1_IRQ_SHIFT; |
| 1262 | if (vcs & GT_RENDER_USER_INTERRUPT) |
| 1263 | notify_ring(dev, &dev_priv->ring[VCS]); |
| 1264 | I915_WRITE(GEN8_GT_IIR(1), tmp); |
| 1265 | } else |
| 1266 | DRM_ERROR("The master control interrupt lied (GT1)!\n"); |
| 1267 | } |
| 1268 | |
| 1269 | if (master_ctl & GEN8_GT_VECS_IRQ) { |
| 1270 | tmp = I915_READ(GEN8_GT_IIR(3)); |
| 1271 | if (tmp) { |
| 1272 | ret = IRQ_HANDLED; |
| 1273 | vcs = tmp >> GEN8_VECS_IRQ_SHIFT; |
| 1274 | if (vcs & GT_RENDER_USER_INTERRUPT) |
| 1275 | notify_ring(dev, &dev_priv->ring[VECS]); |
| 1276 | I915_WRITE(GEN8_GT_IIR(3), tmp); |
| 1277 | } else |
| 1278 | DRM_ERROR("The master control interrupt lied (GT3)!\n"); |
| 1279 | } |
| 1280 | |
| 1281 | return ret; |
| 1282 | } |
| 1283 | |
Egbert Eich | b543fb0 | 2013-04-16 13:36:54 +0200 | [diff] [blame] | 1284 | #define HPD_STORM_DETECT_PERIOD 1000 |
| 1285 | #define HPD_STORM_THRESHOLD 5 |
| 1286 | |
Daniel Vetter | 10a504d | 2013-06-27 17:52:12 +0200 | [diff] [blame] | 1287 | static inline void intel_hpd_irq_handler(struct drm_device *dev, |
Daniel Vetter | 22062db | 2013-06-27 17:52:11 +0200 | [diff] [blame] | 1288 | u32 hotplug_trigger, |
| 1289 | const u32 *hpd) |
Egbert Eich | b543fb0 | 2013-04-16 13:36:54 +0200 | [diff] [blame] | 1290 | { |
| 1291 | drm_i915_private_t *dev_priv = dev->dev_private; |
Egbert Eich | b543fb0 | 2013-04-16 13:36:54 +0200 | [diff] [blame] | 1292 | int i; |
Daniel Vetter | 10a504d | 2013-06-27 17:52:12 +0200 | [diff] [blame] | 1293 | bool storm_detected = false; |
Egbert Eich | b543fb0 | 2013-04-16 13:36:54 +0200 | [diff] [blame] | 1294 | |
Daniel Vetter | 91d131d | 2013-06-27 17:52:14 +0200 | [diff] [blame] | 1295 | if (!hotplug_trigger) |
| 1296 | return; |
| 1297 | |
Imre Deak | cc9bd49 | 2014-01-16 19:56:54 +0200 | [diff] [blame] | 1298 | DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n", |
| 1299 | hotplug_trigger); |
| 1300 | |
Daniel Vetter | b5ea2d5 | 2013-06-27 17:52:15 +0200 | [diff] [blame] | 1301 | spin_lock(&dev_priv->irq_lock); |
Egbert Eich | b543fb0 | 2013-04-16 13:36:54 +0200 | [diff] [blame] | 1302 | for (i = 1; i < HPD_NUM_PINS; i++) { |
Egbert Eich | 821450c | 2013-04-16 13:36:55 +0200 | [diff] [blame] | 1303 | |
Chris Wilson | 3432087 | 2014-01-10 18:49:20 +0000 | [diff] [blame] | 1304 | WARN_ONCE(hpd[i] & hotplug_trigger && |
Chris Wilson | 8b5565b | 2014-01-10 18:49:21 +0000 | [diff] [blame] | 1305 | dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED, |
Chris Wilson | cba1c07 | 2014-01-10 20:17:07 +0000 | [diff] [blame] | 1306 | "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n", |
| 1307 | hotplug_trigger, i, hpd[i]); |
Egbert Eich | b8f102e | 2013-07-26 14:14:24 +0200 | [diff] [blame] | 1308 | |
Egbert Eich | b543fb0 | 2013-04-16 13:36:54 +0200 | [diff] [blame] | 1309 | if (!(hpd[i] & hotplug_trigger) || |
| 1310 | dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED) |
| 1311 | continue; |
| 1312 | |
Jani Nikula | bc5ead8c | 2013-05-07 15:10:29 +0300 | [diff] [blame] | 1313 | dev_priv->hpd_event_bits |= (1 << i); |
Egbert Eich | b543fb0 | 2013-04-16 13:36:54 +0200 | [diff] [blame] | 1314 | if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies, |
| 1315 | dev_priv->hpd_stats[i].hpd_last_jiffies |
| 1316 | + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) { |
| 1317 | dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies; |
| 1318 | dev_priv->hpd_stats[i].hpd_cnt = 0; |
Egbert Eich | b8f102e | 2013-07-26 14:14:24 +0200 | [diff] [blame] | 1319 | DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i); |
Egbert Eich | b543fb0 | 2013-04-16 13:36:54 +0200 | [diff] [blame] | 1320 | } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) { |
| 1321 | dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED; |
Egbert Eich | 142e239 | 2013-04-11 15:57:57 +0200 | [diff] [blame] | 1322 | dev_priv->hpd_event_bits &= ~(1 << i); |
Egbert Eich | b543fb0 | 2013-04-16 13:36:54 +0200 | [diff] [blame] | 1323 | DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i); |
Daniel Vetter | 10a504d | 2013-06-27 17:52:12 +0200 | [diff] [blame] | 1324 | storm_detected = true; |
Egbert Eich | b543fb0 | 2013-04-16 13:36:54 +0200 | [diff] [blame] | 1325 | } else { |
| 1326 | dev_priv->hpd_stats[i].hpd_cnt++; |
Egbert Eich | b8f102e | 2013-07-26 14:14:24 +0200 | [diff] [blame] | 1327 | DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i, |
| 1328 | dev_priv->hpd_stats[i].hpd_cnt); |
Egbert Eich | b543fb0 | 2013-04-16 13:36:54 +0200 | [diff] [blame] | 1329 | } |
| 1330 | } |
| 1331 | |
Daniel Vetter | 10a504d | 2013-06-27 17:52:12 +0200 | [diff] [blame] | 1332 | if (storm_detected) |
| 1333 | dev_priv->display.hpd_irq_setup(dev); |
Daniel Vetter | b5ea2d5 | 2013-06-27 17:52:15 +0200 | [diff] [blame] | 1334 | spin_unlock(&dev_priv->irq_lock); |
Daniel Vetter | 5876fa0 | 2013-06-27 17:52:13 +0200 | [diff] [blame] | 1335 | |
Daniel Vetter | 645416f | 2013-09-02 16:22:25 +0200 | [diff] [blame] | 1336 | /* |
| 1337 | * Our hotplug handler can grab modeset locks (by calling down into the |
| 1338 | * fb helpers). Hence it must not be run on our own dev-priv->wq work |
| 1339 | * queue for otherwise the flush_work in the pageflip code will |
| 1340 | * deadlock. |
| 1341 | */ |
| 1342 | schedule_work(&dev_priv->hotplug_work); |
Egbert Eich | b543fb0 | 2013-04-16 13:36:54 +0200 | [diff] [blame] | 1343 | } |
| 1344 | |
Daniel Vetter | 515ac2b | 2012-12-01 13:53:44 +0100 | [diff] [blame] | 1345 | static void gmbus_irq_handler(struct drm_device *dev) |
| 1346 | { |
Daniel Vetter | 28c70f1 | 2012-12-01 13:53:45 +0100 | [diff] [blame] | 1347 | struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 1348 | |
Daniel Vetter | 28c70f1 | 2012-12-01 13:53:45 +0100 | [diff] [blame] | 1349 | wake_up_all(&dev_priv->gmbus_wait_queue); |
Daniel Vetter | 515ac2b | 2012-12-01 13:53:44 +0100 | [diff] [blame] | 1350 | } |
| 1351 | |
Daniel Vetter | ce99c25 | 2012-12-01 13:53:47 +0100 | [diff] [blame] | 1352 | static void dp_aux_irq_handler(struct drm_device *dev) |
| 1353 | { |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1354 | struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 1355 | |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1356 | wake_up_all(&dev_priv->gmbus_wait_queue); |
Daniel Vetter | ce99c25 | 2012-12-01 13:53:47 +0100 | [diff] [blame] | 1357 | } |
| 1358 | |
Shuang He | 8bf1e9f | 2013-10-15 18:55:27 +0100 | [diff] [blame] | 1359 | #if defined(CONFIG_DEBUG_FS) |
Daniel Vetter | 277de95 | 2013-10-18 16:37:07 +0200 | [diff] [blame] | 1360 | static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe, |
| 1361 | uint32_t crc0, uint32_t crc1, |
| 1362 | uint32_t crc2, uint32_t crc3, |
| 1363 | uint32_t crc4) |
Shuang He | 8bf1e9f | 2013-10-15 18:55:27 +0100 | [diff] [blame] | 1364 | { |
| 1365 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1366 | struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe]; |
| 1367 | struct intel_pipe_crc_entry *entry; |
Damien Lespiau | ac2300d | 2013-10-15 18:55:30 +0100 | [diff] [blame] | 1368 | int head, tail; |
Damien Lespiau | b2c88f5 | 2013-10-15 18:55:29 +0100 | [diff] [blame] | 1369 | |
Damien Lespiau | d538bbd | 2013-10-21 14:29:30 +0100 | [diff] [blame] | 1370 | spin_lock(&pipe_crc->lock); |
| 1371 | |
Damien Lespiau | 0c912c7 | 2013-10-15 18:55:37 +0100 | [diff] [blame] | 1372 | if (!pipe_crc->entries) { |
Damien Lespiau | d538bbd | 2013-10-21 14:29:30 +0100 | [diff] [blame] | 1373 | spin_unlock(&pipe_crc->lock); |
Damien Lespiau | 0c912c7 | 2013-10-15 18:55:37 +0100 | [diff] [blame] | 1374 | DRM_ERROR("spurious interrupt\n"); |
| 1375 | return; |
| 1376 | } |
| 1377 | |
Damien Lespiau | d538bbd | 2013-10-21 14:29:30 +0100 | [diff] [blame] | 1378 | head = pipe_crc->head; |
| 1379 | tail = pipe_crc->tail; |
Damien Lespiau | b2c88f5 | 2013-10-15 18:55:29 +0100 | [diff] [blame] | 1380 | |
| 1381 | if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) { |
Damien Lespiau | d538bbd | 2013-10-21 14:29:30 +0100 | [diff] [blame] | 1382 | spin_unlock(&pipe_crc->lock); |
Damien Lespiau | b2c88f5 | 2013-10-15 18:55:29 +0100 | [diff] [blame] | 1383 | DRM_ERROR("CRC buffer overflowing\n"); |
| 1384 | return; |
| 1385 | } |
| 1386 | |
| 1387 | entry = &pipe_crc->entries[head]; |
Shuang He | 8bf1e9f | 2013-10-15 18:55:27 +0100 | [diff] [blame] | 1388 | |
Daniel Vetter | 8bc5e95 | 2013-10-16 22:55:49 +0200 | [diff] [blame] | 1389 | entry->frame = dev->driver->get_vblank_counter(dev, pipe); |
Daniel Vetter | eba94eb | 2013-10-16 22:55:46 +0200 | [diff] [blame] | 1390 | entry->crc[0] = crc0; |
| 1391 | entry->crc[1] = crc1; |
| 1392 | entry->crc[2] = crc2; |
| 1393 | entry->crc[3] = crc3; |
| 1394 | entry->crc[4] = crc4; |
Damien Lespiau | b2c88f5 | 2013-10-15 18:55:29 +0100 | [diff] [blame] | 1395 | |
| 1396 | head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1); |
Damien Lespiau | d538bbd | 2013-10-21 14:29:30 +0100 | [diff] [blame] | 1397 | pipe_crc->head = head; |
| 1398 | |
| 1399 | spin_unlock(&pipe_crc->lock); |
Damien Lespiau | 0714442 | 2013-10-15 18:55:40 +0100 | [diff] [blame] | 1400 | |
| 1401 | wake_up_interruptible(&pipe_crc->wq); |
Shuang He | 8bf1e9f | 2013-10-15 18:55:27 +0100 | [diff] [blame] | 1402 | } |
Daniel Vetter | 277de95 | 2013-10-18 16:37:07 +0200 | [diff] [blame] | 1403 | #else |
| 1404 | static inline void |
| 1405 | display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe, |
| 1406 | uint32_t crc0, uint32_t crc1, |
| 1407 | uint32_t crc2, uint32_t crc3, |
| 1408 | uint32_t crc4) {} |
| 1409 | #endif |
Daniel Vetter | eba94eb | 2013-10-16 22:55:46 +0200 | [diff] [blame] | 1410 | |
Daniel Vetter | 277de95 | 2013-10-18 16:37:07 +0200 | [diff] [blame] | 1411 | |
| 1412 | static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe) |
Daniel Vetter | 5a69b89 | 2013-10-16 22:55:52 +0200 | [diff] [blame] | 1413 | { |
| 1414 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1415 | |
Daniel Vetter | 277de95 | 2013-10-18 16:37:07 +0200 | [diff] [blame] | 1416 | display_pipe_crc_irq_handler(dev, pipe, |
| 1417 | I915_READ(PIPE_CRC_RES_1_IVB(pipe)), |
| 1418 | 0, 0, 0, 0); |
Daniel Vetter | 5a69b89 | 2013-10-16 22:55:52 +0200 | [diff] [blame] | 1419 | } |
| 1420 | |
Daniel Vetter | 277de95 | 2013-10-18 16:37:07 +0200 | [diff] [blame] | 1421 | static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe) |
Daniel Vetter | eba94eb | 2013-10-16 22:55:46 +0200 | [diff] [blame] | 1422 | { |
| 1423 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1424 | |
Daniel Vetter | 277de95 | 2013-10-18 16:37:07 +0200 | [diff] [blame] | 1425 | display_pipe_crc_irq_handler(dev, pipe, |
| 1426 | I915_READ(PIPE_CRC_RES_1_IVB(pipe)), |
| 1427 | I915_READ(PIPE_CRC_RES_2_IVB(pipe)), |
| 1428 | I915_READ(PIPE_CRC_RES_3_IVB(pipe)), |
| 1429 | I915_READ(PIPE_CRC_RES_4_IVB(pipe)), |
| 1430 | I915_READ(PIPE_CRC_RES_5_IVB(pipe))); |
Daniel Vetter | eba94eb | 2013-10-16 22:55:46 +0200 | [diff] [blame] | 1431 | } |
Daniel Vetter | 5b3a856 | 2013-10-16 22:55:48 +0200 | [diff] [blame] | 1432 | |
Daniel Vetter | 277de95 | 2013-10-18 16:37:07 +0200 | [diff] [blame] | 1433 | static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe) |
Daniel Vetter | 5b3a856 | 2013-10-16 22:55:48 +0200 | [diff] [blame] | 1434 | { |
| 1435 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 0b5c5ed | 2013-10-16 22:55:53 +0200 | [diff] [blame] | 1436 | uint32_t res1, res2; |
| 1437 | |
| 1438 | if (INTEL_INFO(dev)->gen >= 3) |
| 1439 | res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe)); |
| 1440 | else |
| 1441 | res1 = 0; |
| 1442 | |
| 1443 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
| 1444 | res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe)); |
| 1445 | else |
| 1446 | res2 = 0; |
Daniel Vetter | 5b3a856 | 2013-10-16 22:55:48 +0200 | [diff] [blame] | 1447 | |
Daniel Vetter | 277de95 | 2013-10-18 16:37:07 +0200 | [diff] [blame] | 1448 | display_pipe_crc_irq_handler(dev, pipe, |
| 1449 | I915_READ(PIPE_CRC_RES_RED(pipe)), |
| 1450 | I915_READ(PIPE_CRC_RES_GREEN(pipe)), |
| 1451 | I915_READ(PIPE_CRC_RES_BLUE(pipe)), |
| 1452 | res1, res2); |
Daniel Vetter | 5b3a856 | 2013-10-16 22:55:48 +0200 | [diff] [blame] | 1453 | } |
Shuang He | 8bf1e9f | 2013-10-15 18:55:27 +0100 | [diff] [blame] | 1454 | |
Paulo Zanoni | 1403c0d | 2013-08-15 11:51:32 -0300 | [diff] [blame] | 1455 | /* The RPS events need forcewake, so we add them to a work queue and mask their |
| 1456 | * IMR bits until the work is done. Other interrupts can be processed without |
| 1457 | * the work queue. */ |
| 1458 | static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir) |
Ben Widawsky | baf02a1 | 2013-05-28 19:22:24 -0700 | [diff] [blame] | 1459 | { |
Daniel Vetter | 41a05a3 | 2013-07-04 23:35:26 +0200 | [diff] [blame] | 1460 | if (pm_iir & GEN6_PM_RPS_EVENTS) { |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 1461 | spin_lock(&dev_priv->irq_lock); |
Daniel Vetter | 41a05a3 | 2013-07-04 23:35:26 +0200 | [diff] [blame] | 1462 | dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS; |
Paulo Zanoni | 4d3b3d5 | 2013-08-09 17:04:36 -0300 | [diff] [blame] | 1463 | snb_disable_pm_irq(dev_priv, pm_iir & GEN6_PM_RPS_EVENTS); |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 1464 | spin_unlock(&dev_priv->irq_lock); |
Daniel Vetter | 2adbee6 | 2013-07-04 23:35:27 +0200 | [diff] [blame] | 1465 | |
| 1466 | queue_work(dev_priv->wq, &dev_priv->rps.work); |
Ben Widawsky | baf02a1 | 2013-05-28 19:22:24 -0700 | [diff] [blame] | 1467 | } |
Ben Widawsky | baf02a1 | 2013-05-28 19:22:24 -0700 | [diff] [blame] | 1468 | |
Paulo Zanoni | 1403c0d | 2013-08-15 11:51:32 -0300 | [diff] [blame] | 1469 | if (HAS_VEBOX(dev_priv->dev)) { |
| 1470 | if (pm_iir & PM_VEBOX_USER_INTERRUPT) |
| 1471 | notify_ring(dev_priv->dev, &dev_priv->ring[VECS]); |
Ben Widawsky | 12638c5 | 2013-05-28 19:22:31 -0700 | [diff] [blame] | 1472 | |
Paulo Zanoni | 1403c0d | 2013-08-15 11:51:32 -0300 | [diff] [blame] | 1473 | if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) { |
| 1474 | DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir); |
| 1475 | i915_handle_error(dev_priv->dev, false); |
| 1476 | } |
Ben Widawsky | 12638c5 | 2013-05-28 19:22:31 -0700 | [diff] [blame] | 1477 | } |
Ben Widawsky | baf02a1 | 2013-05-28 19:22:24 -0700 | [diff] [blame] | 1478 | } |
| 1479 | |
Imre Deak | c1874ed | 2014-02-04 21:35:46 +0200 | [diff] [blame] | 1480 | static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir) |
| 1481 | { |
| 1482 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1483 | u32 pipe_stats[I915_MAX_PIPES]; |
Imre Deak | c1874ed | 2014-02-04 21:35:46 +0200 | [diff] [blame] | 1484 | int pipe; |
| 1485 | |
Imre Deak | 58ead0d | 2014-02-04 21:35:47 +0200 | [diff] [blame] | 1486 | spin_lock(&dev_priv->irq_lock); |
Imre Deak | c1874ed | 2014-02-04 21:35:46 +0200 | [diff] [blame] | 1487 | for_each_pipe(pipe) { |
| 1488 | int reg = PIPESTAT(pipe); |
| 1489 | pipe_stats[pipe] = I915_READ(reg); |
| 1490 | |
| 1491 | /* |
| 1492 | * Clear the PIPE*STAT regs before the IIR |
| 1493 | */ |
| 1494 | if (pipe_stats[pipe] & 0x8000ffff) |
| 1495 | I915_WRITE(reg, pipe_stats[pipe]); |
| 1496 | } |
Imre Deak | 58ead0d | 2014-02-04 21:35:47 +0200 | [diff] [blame] | 1497 | spin_unlock(&dev_priv->irq_lock); |
Imre Deak | c1874ed | 2014-02-04 21:35:46 +0200 | [diff] [blame] | 1498 | |
| 1499 | for_each_pipe(pipe) { |
| 1500 | if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS) |
| 1501 | drm_handle_vblank(dev, pipe); |
| 1502 | |
Imre Deak | 579a9b0 | 2014-02-04 21:35:48 +0200 | [diff] [blame] | 1503 | if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) { |
Imre Deak | c1874ed | 2014-02-04 21:35:46 +0200 | [diff] [blame] | 1504 | intel_prepare_page_flip(dev, pipe); |
| 1505 | intel_finish_page_flip(dev, pipe); |
| 1506 | } |
| 1507 | |
| 1508 | if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) |
| 1509 | i9xx_pipe_crc_irq_handler(dev, pipe); |
| 1510 | |
| 1511 | if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS && |
| 1512 | intel_set_cpu_fifo_underrun_reporting(dev, pipe, false)) |
| 1513 | DRM_ERROR("pipe %c underrun\n", pipe_name(pipe)); |
| 1514 | } |
| 1515 | |
| 1516 | if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) |
| 1517 | gmbus_irq_handler(dev); |
| 1518 | } |
| 1519 | |
Daniel Vetter | ff1f525 | 2012-10-02 15:10:55 +0200 | [diff] [blame] | 1520 | static irqreturn_t valleyview_irq_handler(int irq, void *arg) |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 1521 | { |
| 1522 | struct drm_device *dev = (struct drm_device *) arg; |
| 1523 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 1524 | u32 iir, gt_iir, pm_iir; |
| 1525 | irqreturn_t ret = IRQ_NONE; |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 1526 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 1527 | while (true) { |
| 1528 | iir = I915_READ(VLV_IIR); |
| 1529 | gt_iir = I915_READ(GTIIR); |
| 1530 | pm_iir = I915_READ(GEN6_PMIIR); |
| 1531 | |
| 1532 | if (gt_iir == 0 && pm_iir == 0 && iir == 0) |
| 1533 | goto out; |
| 1534 | |
| 1535 | ret = IRQ_HANDLED; |
| 1536 | |
Daniel Vetter | e7b4c6b | 2012-03-30 20:24:35 +0200 | [diff] [blame] | 1537 | snb_gt_irq_handler(dev, dev_priv, gt_iir); |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 1538 | |
Imre Deak | c1874ed | 2014-02-04 21:35:46 +0200 | [diff] [blame] | 1539 | valleyview_pipestat_irq_handler(dev, iir); |
Jesse Barnes | 31acc7f | 2012-06-20 10:53:11 -0700 | [diff] [blame] | 1540 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 1541 | /* Consume port. Then clear IIR or we'll miss events */ |
| 1542 | if (iir & I915_DISPLAY_PORT_INTERRUPT) { |
| 1543 | u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); |
Egbert Eich | b543fb0 | 2013-04-16 13:36:54 +0200 | [diff] [blame] | 1544 | u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915; |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 1545 | |
Daniel Vetter | 91d131d | 2013-06-27 17:52:14 +0200 | [diff] [blame] | 1546 | intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915); |
| 1547 | |
Daniel Vetter | 4aeebd7 | 2013-10-31 09:53:36 +0100 | [diff] [blame] | 1548 | if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X) |
| 1549 | dp_aux_irq_handler(dev); |
| 1550 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 1551 | I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); |
| 1552 | I915_READ(PORT_HOTPLUG_STAT); |
| 1553 | } |
| 1554 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 1555 | |
Paulo Zanoni | 60611c1 | 2013-08-15 11:50:01 -0300 | [diff] [blame] | 1556 | if (pm_iir) |
Daniel Vetter | d0ecd7e | 2013-07-04 23:35:25 +0200 | [diff] [blame] | 1557 | gen6_rps_irq_handler(dev_priv, pm_iir); |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 1558 | |
| 1559 | I915_WRITE(GTIIR, gt_iir); |
| 1560 | I915_WRITE(GEN6_PMIIR, pm_iir); |
| 1561 | I915_WRITE(VLV_IIR, iir); |
| 1562 | } |
| 1563 | |
| 1564 | out: |
| 1565 | return ret; |
| 1566 | } |
| 1567 | |
Adam Jackson | 23e81d6 | 2012-06-06 15:45:44 -0400 | [diff] [blame] | 1568 | static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir) |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 1569 | { |
| 1570 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1571 | int pipe; |
Egbert Eich | b543fb0 | 2013-04-16 13:36:54 +0200 | [diff] [blame] | 1572 | u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK; |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 1573 | |
Daniel Vetter | 91d131d | 2013-06-27 17:52:14 +0200 | [diff] [blame] | 1574 | intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx); |
| 1575 | |
Ville Syrjälä | cfc33bf | 2013-04-17 17:48:48 +0300 | [diff] [blame] | 1576 | if (pch_iir & SDE_AUDIO_POWER_MASK) { |
| 1577 | int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >> |
| 1578 | SDE_AUDIO_POWER_SHIFT); |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 1579 | DRM_DEBUG_DRIVER("PCH audio power change on port %d\n", |
Ville Syrjälä | cfc33bf | 2013-04-17 17:48:48 +0300 | [diff] [blame] | 1580 | port_name(port)); |
| 1581 | } |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 1582 | |
Daniel Vetter | ce99c25 | 2012-12-01 13:53:47 +0100 | [diff] [blame] | 1583 | if (pch_iir & SDE_AUX_MASK) |
| 1584 | dp_aux_irq_handler(dev); |
| 1585 | |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 1586 | if (pch_iir & SDE_GMBUS) |
Daniel Vetter | 515ac2b | 2012-12-01 13:53:44 +0100 | [diff] [blame] | 1587 | gmbus_irq_handler(dev); |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 1588 | |
| 1589 | if (pch_iir & SDE_AUDIO_HDCP_MASK) |
| 1590 | DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n"); |
| 1591 | |
| 1592 | if (pch_iir & SDE_AUDIO_TRANS_MASK) |
| 1593 | DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n"); |
| 1594 | |
| 1595 | if (pch_iir & SDE_POISON) |
| 1596 | DRM_ERROR("PCH poison interrupt\n"); |
| 1597 | |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1598 | if (pch_iir & SDE_FDI_MASK) |
| 1599 | for_each_pipe(pipe) |
| 1600 | DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", |
| 1601 | pipe_name(pipe), |
| 1602 | I915_READ(FDI_RX_IIR(pipe))); |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 1603 | |
| 1604 | if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE)) |
| 1605 | DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n"); |
| 1606 | |
| 1607 | if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR)) |
| 1608 | DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n"); |
| 1609 | |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 1610 | if (pch_iir & SDE_TRANSA_FIFO_UNDER) |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 1611 | if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, |
| 1612 | false)) |
Ville Syrjälä | fc2c807 | 2014-01-17 11:44:32 +0200 | [diff] [blame] | 1613 | DRM_ERROR("PCH transcoder A FIFO underrun\n"); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 1614 | |
| 1615 | if (pch_iir & SDE_TRANSB_FIFO_UNDER) |
| 1616 | if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B, |
| 1617 | false)) |
Ville Syrjälä | fc2c807 | 2014-01-17 11:44:32 +0200 | [diff] [blame] | 1618 | DRM_ERROR("PCH transcoder B FIFO underrun\n"); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | static void ivb_err_int_handler(struct drm_device *dev) |
| 1622 | { |
| 1623 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1624 | u32 err_int = I915_READ(GEN7_ERR_INT); |
Daniel Vetter | 5a69b89 | 2013-10-16 22:55:52 +0200 | [diff] [blame] | 1625 | enum pipe pipe; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 1626 | |
Paulo Zanoni | de032bf | 2013-04-12 17:57:58 -0300 | [diff] [blame] | 1627 | if (err_int & ERR_INT_POISON) |
| 1628 | DRM_ERROR("Poison interrupt\n"); |
| 1629 | |
Daniel Vetter | 5a69b89 | 2013-10-16 22:55:52 +0200 | [diff] [blame] | 1630 | for_each_pipe(pipe) { |
| 1631 | if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) { |
| 1632 | if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, |
| 1633 | false)) |
Ville Syrjälä | fc2c807 | 2014-01-17 11:44:32 +0200 | [diff] [blame] | 1634 | DRM_ERROR("Pipe %c FIFO underrun\n", |
| 1635 | pipe_name(pipe)); |
Daniel Vetter | 5a69b89 | 2013-10-16 22:55:52 +0200 | [diff] [blame] | 1636 | } |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 1637 | |
Daniel Vetter | 5a69b89 | 2013-10-16 22:55:52 +0200 | [diff] [blame] | 1638 | if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) { |
| 1639 | if (IS_IVYBRIDGE(dev)) |
Daniel Vetter | 277de95 | 2013-10-18 16:37:07 +0200 | [diff] [blame] | 1640 | ivb_pipe_crc_irq_handler(dev, pipe); |
Daniel Vetter | 5a69b89 | 2013-10-16 22:55:52 +0200 | [diff] [blame] | 1641 | else |
Daniel Vetter | 277de95 | 2013-10-18 16:37:07 +0200 | [diff] [blame] | 1642 | hsw_pipe_crc_irq_handler(dev, pipe); |
Daniel Vetter | 5a69b89 | 2013-10-16 22:55:52 +0200 | [diff] [blame] | 1643 | } |
| 1644 | } |
Shuang He | 8bf1e9f | 2013-10-15 18:55:27 +0100 | [diff] [blame] | 1645 | |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 1646 | I915_WRITE(GEN7_ERR_INT, err_int); |
| 1647 | } |
| 1648 | |
| 1649 | static void cpt_serr_int_handler(struct drm_device *dev) |
| 1650 | { |
| 1651 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1652 | u32 serr_int = I915_READ(SERR_INT); |
| 1653 | |
Paulo Zanoni | de032bf | 2013-04-12 17:57:58 -0300 | [diff] [blame] | 1654 | if (serr_int & SERR_INT_POISON) |
| 1655 | DRM_ERROR("PCH poison interrupt\n"); |
| 1656 | |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 1657 | if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN) |
| 1658 | if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, |
| 1659 | false)) |
Ville Syrjälä | fc2c807 | 2014-01-17 11:44:32 +0200 | [diff] [blame] | 1660 | DRM_ERROR("PCH transcoder A FIFO underrun\n"); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 1661 | |
| 1662 | if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN) |
| 1663 | if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B, |
| 1664 | false)) |
Ville Syrjälä | fc2c807 | 2014-01-17 11:44:32 +0200 | [diff] [blame] | 1665 | DRM_ERROR("PCH transcoder B FIFO underrun\n"); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 1666 | |
| 1667 | if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN) |
| 1668 | if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C, |
| 1669 | false)) |
Ville Syrjälä | fc2c807 | 2014-01-17 11:44:32 +0200 | [diff] [blame] | 1670 | DRM_ERROR("PCH transcoder C FIFO underrun\n"); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 1671 | |
| 1672 | I915_WRITE(SERR_INT, serr_int); |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 1673 | } |
| 1674 | |
Adam Jackson | 23e81d6 | 2012-06-06 15:45:44 -0400 | [diff] [blame] | 1675 | static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir) |
| 1676 | { |
| 1677 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 1678 | int pipe; |
Egbert Eich | b543fb0 | 2013-04-16 13:36:54 +0200 | [diff] [blame] | 1679 | u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT; |
Adam Jackson | 23e81d6 | 2012-06-06 15:45:44 -0400 | [diff] [blame] | 1680 | |
Daniel Vetter | 91d131d | 2013-06-27 17:52:14 +0200 | [diff] [blame] | 1681 | intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt); |
| 1682 | |
Ville Syrjälä | cfc33bf | 2013-04-17 17:48:48 +0300 | [diff] [blame] | 1683 | if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) { |
| 1684 | int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >> |
| 1685 | SDE_AUDIO_POWER_SHIFT_CPT); |
| 1686 | DRM_DEBUG_DRIVER("PCH audio power change on port %c\n", |
| 1687 | port_name(port)); |
| 1688 | } |
Adam Jackson | 23e81d6 | 2012-06-06 15:45:44 -0400 | [diff] [blame] | 1689 | |
| 1690 | if (pch_iir & SDE_AUX_MASK_CPT) |
Daniel Vetter | ce99c25 | 2012-12-01 13:53:47 +0100 | [diff] [blame] | 1691 | dp_aux_irq_handler(dev); |
Adam Jackson | 23e81d6 | 2012-06-06 15:45:44 -0400 | [diff] [blame] | 1692 | |
| 1693 | if (pch_iir & SDE_GMBUS_CPT) |
Daniel Vetter | 515ac2b | 2012-12-01 13:53:44 +0100 | [diff] [blame] | 1694 | gmbus_irq_handler(dev); |
Adam Jackson | 23e81d6 | 2012-06-06 15:45:44 -0400 | [diff] [blame] | 1695 | |
| 1696 | if (pch_iir & SDE_AUDIO_CP_REQ_CPT) |
| 1697 | DRM_DEBUG_DRIVER("Audio CP request interrupt\n"); |
| 1698 | |
| 1699 | if (pch_iir & SDE_AUDIO_CP_CHG_CPT) |
| 1700 | DRM_DEBUG_DRIVER("Audio CP change interrupt\n"); |
| 1701 | |
| 1702 | if (pch_iir & SDE_FDI_MASK_CPT) |
| 1703 | for_each_pipe(pipe) |
| 1704 | DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", |
| 1705 | pipe_name(pipe), |
| 1706 | I915_READ(FDI_RX_IIR(pipe))); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 1707 | |
| 1708 | if (pch_iir & SDE_ERROR_CPT) |
| 1709 | cpt_serr_int_handler(dev); |
Adam Jackson | 23e81d6 | 2012-06-06 15:45:44 -0400 | [diff] [blame] | 1710 | } |
| 1711 | |
Paulo Zanoni | c008bc6 | 2013-07-12 16:35:10 -0300 | [diff] [blame] | 1712 | static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir) |
| 1713 | { |
| 1714 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 40da17c2 | 2013-10-21 18:04:36 +0200 | [diff] [blame] | 1715 | enum pipe pipe; |
Paulo Zanoni | c008bc6 | 2013-07-12 16:35:10 -0300 | [diff] [blame] | 1716 | |
| 1717 | if (de_iir & DE_AUX_CHANNEL_A) |
| 1718 | dp_aux_irq_handler(dev); |
| 1719 | |
| 1720 | if (de_iir & DE_GSE) |
| 1721 | intel_opregion_asle_intr(dev); |
| 1722 | |
Paulo Zanoni | c008bc6 | 2013-07-12 16:35:10 -0300 | [diff] [blame] | 1723 | if (de_iir & DE_POISON) |
| 1724 | DRM_ERROR("Poison interrupt\n"); |
| 1725 | |
Daniel Vetter | 40da17c2 | 2013-10-21 18:04:36 +0200 | [diff] [blame] | 1726 | for_each_pipe(pipe) { |
| 1727 | if (de_iir & DE_PIPE_VBLANK(pipe)) |
| 1728 | drm_handle_vblank(dev, pipe); |
Paulo Zanoni | c008bc6 | 2013-07-12 16:35:10 -0300 | [diff] [blame] | 1729 | |
Daniel Vetter | 40da17c2 | 2013-10-21 18:04:36 +0200 | [diff] [blame] | 1730 | if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe)) |
| 1731 | if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, false)) |
Ville Syrjälä | fc2c807 | 2014-01-17 11:44:32 +0200 | [diff] [blame] | 1732 | DRM_ERROR("Pipe %c FIFO underrun\n", |
| 1733 | pipe_name(pipe)); |
Paulo Zanoni | c008bc6 | 2013-07-12 16:35:10 -0300 | [diff] [blame] | 1734 | |
Daniel Vetter | 40da17c2 | 2013-10-21 18:04:36 +0200 | [diff] [blame] | 1735 | if (de_iir & DE_PIPE_CRC_DONE(pipe)) |
| 1736 | i9xx_pipe_crc_irq_handler(dev, pipe); |
Daniel Vetter | 5b3a856 | 2013-10-16 22:55:48 +0200 | [diff] [blame] | 1737 | |
Daniel Vetter | 40da17c2 | 2013-10-21 18:04:36 +0200 | [diff] [blame] | 1738 | /* plane/pipes map 1:1 on ilk+ */ |
| 1739 | if (de_iir & DE_PLANE_FLIP_DONE(pipe)) { |
| 1740 | intel_prepare_page_flip(dev, pipe); |
| 1741 | intel_finish_page_flip_plane(dev, pipe); |
| 1742 | } |
Paulo Zanoni | c008bc6 | 2013-07-12 16:35:10 -0300 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | /* check event from PCH */ |
| 1746 | if (de_iir & DE_PCH_EVENT) { |
| 1747 | u32 pch_iir = I915_READ(SDEIIR); |
| 1748 | |
| 1749 | if (HAS_PCH_CPT(dev)) |
| 1750 | cpt_irq_handler(dev, pch_iir); |
| 1751 | else |
| 1752 | ibx_irq_handler(dev, pch_iir); |
| 1753 | |
| 1754 | /* should clear PCH hotplug event before clear CPU irq */ |
| 1755 | I915_WRITE(SDEIIR, pch_iir); |
| 1756 | } |
| 1757 | |
| 1758 | if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT) |
| 1759 | ironlake_rps_change_irq_handler(dev); |
| 1760 | } |
| 1761 | |
Paulo Zanoni | 9719fb9 | 2013-07-12 16:35:11 -0300 | [diff] [blame] | 1762 | static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir) |
| 1763 | { |
| 1764 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 3b6c42e | 2013-10-21 18:04:35 +0200 | [diff] [blame] | 1765 | enum pipe i; |
Paulo Zanoni | 9719fb9 | 2013-07-12 16:35:11 -0300 | [diff] [blame] | 1766 | |
| 1767 | if (de_iir & DE_ERR_INT_IVB) |
| 1768 | ivb_err_int_handler(dev); |
| 1769 | |
| 1770 | if (de_iir & DE_AUX_CHANNEL_A_IVB) |
| 1771 | dp_aux_irq_handler(dev); |
| 1772 | |
| 1773 | if (de_iir & DE_GSE_IVB) |
| 1774 | intel_opregion_asle_intr(dev); |
| 1775 | |
Daniel Vetter | 3b6c42e | 2013-10-21 18:04:35 +0200 | [diff] [blame] | 1776 | for_each_pipe(i) { |
Daniel Vetter | 40da17c2 | 2013-10-21 18:04:36 +0200 | [diff] [blame] | 1777 | if (de_iir & (DE_PIPE_VBLANK_IVB(i))) |
Paulo Zanoni | 9719fb9 | 2013-07-12 16:35:11 -0300 | [diff] [blame] | 1778 | drm_handle_vblank(dev, i); |
Daniel Vetter | 40da17c2 | 2013-10-21 18:04:36 +0200 | [diff] [blame] | 1779 | |
| 1780 | /* plane/pipes map 1:1 on ilk+ */ |
| 1781 | if (de_iir & DE_PLANE_FLIP_DONE_IVB(i)) { |
Paulo Zanoni | 9719fb9 | 2013-07-12 16:35:11 -0300 | [diff] [blame] | 1782 | intel_prepare_page_flip(dev, i); |
| 1783 | intel_finish_page_flip_plane(dev, i); |
| 1784 | } |
| 1785 | } |
| 1786 | |
| 1787 | /* check event from PCH */ |
| 1788 | if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) { |
| 1789 | u32 pch_iir = I915_READ(SDEIIR); |
| 1790 | |
| 1791 | cpt_irq_handler(dev, pch_iir); |
| 1792 | |
| 1793 | /* clear PCH hotplug event before clear CPU irq */ |
| 1794 | I915_WRITE(SDEIIR, pch_iir); |
| 1795 | } |
| 1796 | } |
| 1797 | |
Paulo Zanoni | f1af8fc | 2013-07-12 19:56:30 -0300 | [diff] [blame] | 1798 | static irqreturn_t ironlake_irq_handler(int irq, void *arg) |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 1799 | { |
| 1800 | struct drm_device *dev = (struct drm_device *) arg; |
| 1801 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Paulo Zanoni | f1af8fc | 2013-07-12 19:56:30 -0300 | [diff] [blame] | 1802 | u32 de_iir, gt_iir, de_ier, sde_ier = 0; |
Chris Wilson | 0e43406 | 2012-05-09 21:45:44 +0100 | [diff] [blame] | 1803 | irqreturn_t ret = IRQ_NONE; |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 1804 | |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 1805 | /* We get interrupts on unclaimed registers, so check for this before we |
| 1806 | * do any I915_{READ,WRITE}. */ |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 1807 | intel_uncore_check_errors(dev); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 1808 | |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 1809 | /* disable master interrupt before clearing iir */ |
| 1810 | de_ier = I915_READ(DEIER); |
| 1811 | I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL); |
Paulo Zanoni | 23a7851 | 2013-07-12 16:35:14 -0300 | [diff] [blame] | 1812 | POSTING_READ(DEIER); |
Chris Wilson | 0e43406 | 2012-05-09 21:45:44 +0100 | [diff] [blame] | 1813 | |
Paulo Zanoni | 44498ae | 2013-02-22 17:05:28 -0300 | [diff] [blame] | 1814 | /* Disable south interrupts. We'll only write to SDEIIR once, so further |
| 1815 | * interrupts will will be stored on its back queue, and then we'll be |
| 1816 | * able to process them after we restore SDEIER (as soon as we restore |
| 1817 | * it, we'll get an interrupt if SDEIIR still has something to process |
| 1818 | * due to its back queue). */ |
Ben Widawsky | ab5c608 | 2013-04-05 13:12:41 -0700 | [diff] [blame] | 1819 | if (!HAS_PCH_NOP(dev)) { |
| 1820 | sde_ier = I915_READ(SDEIER); |
| 1821 | I915_WRITE(SDEIER, 0); |
| 1822 | POSTING_READ(SDEIER); |
| 1823 | } |
Paulo Zanoni | 44498ae | 2013-02-22 17:05:28 -0300 | [diff] [blame] | 1824 | |
Chris Wilson | 0e43406 | 2012-05-09 21:45:44 +0100 | [diff] [blame] | 1825 | gt_iir = I915_READ(GTIIR); |
| 1826 | if (gt_iir) { |
Paulo Zanoni | d8fc8a4 | 2013-07-19 18:57:55 -0300 | [diff] [blame] | 1827 | if (INTEL_INFO(dev)->gen >= 6) |
Paulo Zanoni | f1af8fc | 2013-07-12 19:56:30 -0300 | [diff] [blame] | 1828 | snb_gt_irq_handler(dev, dev_priv, gt_iir); |
Paulo Zanoni | d8fc8a4 | 2013-07-19 18:57:55 -0300 | [diff] [blame] | 1829 | else |
| 1830 | ilk_gt_irq_handler(dev, dev_priv, gt_iir); |
Chris Wilson | 0e43406 | 2012-05-09 21:45:44 +0100 | [diff] [blame] | 1831 | I915_WRITE(GTIIR, gt_iir); |
| 1832 | ret = IRQ_HANDLED; |
| 1833 | } |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 1834 | |
| 1835 | de_iir = I915_READ(DEIIR); |
Chris Wilson | 0e43406 | 2012-05-09 21:45:44 +0100 | [diff] [blame] | 1836 | if (de_iir) { |
Paulo Zanoni | f1af8fc | 2013-07-12 19:56:30 -0300 | [diff] [blame] | 1837 | if (INTEL_INFO(dev)->gen >= 7) |
| 1838 | ivb_display_irq_handler(dev, de_iir); |
| 1839 | else |
| 1840 | ilk_display_irq_handler(dev, de_iir); |
Chris Wilson | 0e43406 | 2012-05-09 21:45:44 +0100 | [diff] [blame] | 1841 | I915_WRITE(DEIIR, de_iir); |
| 1842 | ret = IRQ_HANDLED; |
| 1843 | } |
| 1844 | |
Paulo Zanoni | f1af8fc | 2013-07-12 19:56:30 -0300 | [diff] [blame] | 1845 | if (INTEL_INFO(dev)->gen >= 6) { |
| 1846 | u32 pm_iir = I915_READ(GEN6_PMIIR); |
| 1847 | if (pm_iir) { |
Paulo Zanoni | 1403c0d | 2013-08-15 11:51:32 -0300 | [diff] [blame] | 1848 | gen6_rps_irq_handler(dev_priv, pm_iir); |
Paulo Zanoni | f1af8fc | 2013-07-12 19:56:30 -0300 | [diff] [blame] | 1849 | I915_WRITE(GEN6_PMIIR, pm_iir); |
| 1850 | ret = IRQ_HANDLED; |
| 1851 | } |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 1852 | } |
| 1853 | |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 1854 | I915_WRITE(DEIER, de_ier); |
| 1855 | POSTING_READ(DEIER); |
Ben Widawsky | ab5c608 | 2013-04-05 13:12:41 -0700 | [diff] [blame] | 1856 | if (!HAS_PCH_NOP(dev)) { |
| 1857 | I915_WRITE(SDEIER, sde_ier); |
| 1858 | POSTING_READ(SDEIER); |
| 1859 | } |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 1860 | |
| 1861 | return ret; |
| 1862 | } |
| 1863 | |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 1864 | static irqreturn_t gen8_irq_handler(int irq, void *arg) |
| 1865 | { |
| 1866 | struct drm_device *dev = arg; |
| 1867 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1868 | u32 master_ctl; |
| 1869 | irqreturn_t ret = IRQ_NONE; |
| 1870 | uint32_t tmp = 0; |
Daniel Vetter | c42664c | 2013-11-07 11:05:40 +0100 | [diff] [blame] | 1871 | enum pipe pipe; |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 1872 | |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 1873 | master_ctl = I915_READ(GEN8_MASTER_IRQ); |
| 1874 | master_ctl &= ~GEN8_MASTER_IRQ_CONTROL; |
| 1875 | if (!master_ctl) |
| 1876 | return IRQ_NONE; |
| 1877 | |
| 1878 | I915_WRITE(GEN8_MASTER_IRQ, 0); |
| 1879 | POSTING_READ(GEN8_MASTER_IRQ); |
| 1880 | |
| 1881 | ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl); |
| 1882 | |
| 1883 | if (master_ctl & GEN8_DE_MISC_IRQ) { |
| 1884 | tmp = I915_READ(GEN8_DE_MISC_IIR); |
| 1885 | if (tmp & GEN8_DE_MISC_GSE) |
| 1886 | intel_opregion_asle_intr(dev); |
| 1887 | else if (tmp) |
| 1888 | DRM_ERROR("Unexpected DE Misc interrupt\n"); |
| 1889 | else |
| 1890 | DRM_ERROR("The master control interrupt lied (DE MISC)!\n"); |
| 1891 | |
| 1892 | if (tmp) { |
| 1893 | I915_WRITE(GEN8_DE_MISC_IIR, tmp); |
| 1894 | ret = IRQ_HANDLED; |
| 1895 | } |
| 1896 | } |
| 1897 | |
Daniel Vetter | 6d766f0 | 2013-11-07 14:49:55 +0100 | [diff] [blame] | 1898 | if (master_ctl & GEN8_DE_PORT_IRQ) { |
| 1899 | tmp = I915_READ(GEN8_DE_PORT_IIR); |
| 1900 | if (tmp & GEN8_AUX_CHANNEL_A) |
| 1901 | dp_aux_irq_handler(dev); |
| 1902 | else if (tmp) |
| 1903 | DRM_ERROR("Unexpected DE Port interrupt\n"); |
| 1904 | else |
| 1905 | DRM_ERROR("The master control interrupt lied (DE PORT)!\n"); |
| 1906 | |
| 1907 | if (tmp) { |
| 1908 | I915_WRITE(GEN8_DE_PORT_IIR, tmp); |
| 1909 | ret = IRQ_HANDLED; |
| 1910 | } |
| 1911 | } |
| 1912 | |
Daniel Vetter | c42664c | 2013-11-07 11:05:40 +0100 | [diff] [blame] | 1913 | for_each_pipe(pipe) { |
| 1914 | uint32_t pipe_iir; |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 1915 | |
Daniel Vetter | c42664c | 2013-11-07 11:05:40 +0100 | [diff] [blame] | 1916 | if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe))) |
| 1917 | continue; |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 1918 | |
Daniel Vetter | c42664c | 2013-11-07 11:05:40 +0100 | [diff] [blame] | 1919 | pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe)); |
| 1920 | if (pipe_iir & GEN8_PIPE_VBLANK) |
| 1921 | drm_handle_vblank(dev, pipe); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 1922 | |
Daniel Vetter | c42664c | 2013-11-07 11:05:40 +0100 | [diff] [blame] | 1923 | if (pipe_iir & GEN8_PIPE_FLIP_DONE) { |
| 1924 | intel_prepare_page_flip(dev, pipe); |
| 1925 | intel_finish_page_flip_plane(dev, pipe); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 1926 | } |
Daniel Vetter | c42664c | 2013-11-07 11:05:40 +0100 | [diff] [blame] | 1927 | |
Daniel Vetter | 0fbe787 | 2013-11-07 11:05:44 +0100 | [diff] [blame] | 1928 | if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE) |
| 1929 | hsw_pipe_crc_irq_handler(dev, pipe); |
| 1930 | |
Daniel Vetter | 38d83c96 | 2013-11-07 11:05:46 +0100 | [diff] [blame] | 1931 | if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN) { |
| 1932 | if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, |
| 1933 | false)) |
Ville Syrjälä | fc2c807 | 2014-01-17 11:44:32 +0200 | [diff] [blame] | 1934 | DRM_ERROR("Pipe %c FIFO underrun\n", |
| 1935 | pipe_name(pipe)); |
Daniel Vetter | 38d83c96 | 2013-11-07 11:05:46 +0100 | [diff] [blame] | 1936 | } |
| 1937 | |
Daniel Vetter | 30100f2 | 2013-11-07 14:49:24 +0100 | [diff] [blame] | 1938 | if (pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS) { |
| 1939 | DRM_ERROR("Fault errors on pipe %c\n: 0x%08x", |
| 1940 | pipe_name(pipe), |
| 1941 | pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS); |
| 1942 | } |
Daniel Vetter | c42664c | 2013-11-07 11:05:40 +0100 | [diff] [blame] | 1943 | |
| 1944 | if (pipe_iir) { |
| 1945 | ret = IRQ_HANDLED; |
| 1946 | I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir); |
| 1947 | } else |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 1948 | DRM_ERROR("The master control interrupt lied (DE PIPE)!\n"); |
| 1949 | } |
| 1950 | |
Daniel Vetter | 92d03a8 | 2013-11-07 11:05:43 +0100 | [diff] [blame] | 1951 | if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) { |
| 1952 | /* |
| 1953 | * FIXME(BDW): Assume for now that the new interrupt handling |
| 1954 | * scheme also closed the SDE interrupt handling race we've seen |
| 1955 | * on older pch-split platforms. But this needs testing. |
| 1956 | */ |
| 1957 | u32 pch_iir = I915_READ(SDEIIR); |
| 1958 | |
| 1959 | cpt_irq_handler(dev, pch_iir); |
| 1960 | |
| 1961 | if (pch_iir) { |
| 1962 | I915_WRITE(SDEIIR, pch_iir); |
| 1963 | ret = IRQ_HANDLED; |
| 1964 | } |
| 1965 | } |
| 1966 | |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 1967 | I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); |
| 1968 | POSTING_READ(GEN8_MASTER_IRQ); |
| 1969 | |
| 1970 | return ret; |
| 1971 | } |
| 1972 | |
Daniel Vetter | 17e1df0 | 2013-09-08 21:57:13 +0200 | [diff] [blame] | 1973 | static void i915_error_wake_up(struct drm_i915_private *dev_priv, |
| 1974 | bool reset_completed) |
| 1975 | { |
| 1976 | struct intel_ring_buffer *ring; |
| 1977 | int i; |
| 1978 | |
| 1979 | /* |
| 1980 | * Notify all waiters for GPU completion events that reset state has |
| 1981 | * been changed, and that they need to restart their wait after |
| 1982 | * checking for potential errors (and bail out to drop locks if there is |
| 1983 | * a gpu reset pending so that i915_error_work_func can acquire them). |
| 1984 | */ |
| 1985 | |
| 1986 | /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */ |
| 1987 | for_each_ring(ring, dev_priv, i) |
| 1988 | wake_up_all(&ring->irq_queue); |
| 1989 | |
| 1990 | /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */ |
| 1991 | wake_up_all(&dev_priv->pending_flip_queue); |
| 1992 | |
| 1993 | /* |
| 1994 | * Signal tasks blocked in i915_gem_wait_for_error that the pending |
| 1995 | * reset state is cleared. |
| 1996 | */ |
| 1997 | if (reset_completed) |
| 1998 | wake_up_all(&dev_priv->gpu_error.reset_queue); |
| 1999 | } |
| 2000 | |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2001 | /** |
| 2002 | * i915_error_work_func - do process context error handling work |
| 2003 | * @work: work struct |
| 2004 | * |
| 2005 | * Fire an error uevent so userspace can see that a hang or error |
| 2006 | * was detected. |
| 2007 | */ |
| 2008 | static void i915_error_work_func(struct work_struct *work) |
| 2009 | { |
Daniel Vetter | 1f83fee | 2012-11-15 17:17:22 +0100 | [diff] [blame] | 2010 | struct i915_gpu_error *error = container_of(work, struct i915_gpu_error, |
| 2011 | work); |
| 2012 | drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t, |
| 2013 | gpu_error); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2014 | struct drm_device *dev = dev_priv->dev; |
Ben Widawsky | cce723e | 2013-07-19 09:16:42 -0700 | [diff] [blame] | 2015 | char *error_event[] = { I915_ERROR_UEVENT "=1", NULL }; |
| 2016 | char *reset_event[] = { I915_RESET_UEVENT "=1", NULL }; |
| 2017 | char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL }; |
Daniel Vetter | 17e1df0 | 2013-09-08 21:57:13 +0200 | [diff] [blame] | 2018 | int ret; |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2019 | |
Dave Airlie | 5bdebb1 | 2013-10-11 14:07:25 +1000 | [diff] [blame] | 2020 | kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2021 | |
Daniel Vetter | 7db0ba2 | 2012-12-06 16:23:37 +0100 | [diff] [blame] | 2022 | /* |
| 2023 | * Note that there's only one work item which does gpu resets, so we |
| 2024 | * need not worry about concurrent gpu resets potentially incrementing |
| 2025 | * error->reset_counter twice. We only need to take care of another |
| 2026 | * racing irq/hangcheck declaring the gpu dead for a second time. A |
| 2027 | * quick check for that is good enough: schedule_work ensures the |
| 2028 | * correct ordering between hang detection and this work item, and since |
| 2029 | * the reset in-progress bit is only ever set by code outside of this |
| 2030 | * work we don't need to worry about any other races. |
| 2031 | */ |
| 2032 | if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) { |
Chris Wilson | f803aa5 | 2010-09-19 12:38:26 +0100 | [diff] [blame] | 2033 | DRM_DEBUG_DRIVER("resetting chip\n"); |
Dave Airlie | 5bdebb1 | 2013-10-11 14:07:25 +1000 | [diff] [blame] | 2034 | kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, |
Daniel Vetter | 7db0ba2 | 2012-12-06 16:23:37 +0100 | [diff] [blame] | 2035 | reset_event); |
Daniel Vetter | 1f83fee | 2012-11-15 17:17:22 +0100 | [diff] [blame] | 2036 | |
Daniel Vetter | 17e1df0 | 2013-09-08 21:57:13 +0200 | [diff] [blame] | 2037 | /* |
| 2038 | * All state reset _must_ be completed before we update the |
| 2039 | * reset counter, for otherwise waiters might miss the reset |
| 2040 | * pending state and not properly drop locks, resulting in |
| 2041 | * deadlocks with the reset work. |
| 2042 | */ |
Daniel Vetter | f69061b | 2012-12-06 09:01:42 +0100 | [diff] [blame] | 2043 | ret = i915_reset(dev); |
| 2044 | |
Daniel Vetter | 17e1df0 | 2013-09-08 21:57:13 +0200 | [diff] [blame] | 2045 | intel_display_handle_reset(dev); |
| 2046 | |
Daniel Vetter | f69061b | 2012-12-06 09:01:42 +0100 | [diff] [blame] | 2047 | if (ret == 0) { |
| 2048 | /* |
| 2049 | * After all the gem state is reset, increment the reset |
| 2050 | * counter and wake up everyone waiting for the reset to |
| 2051 | * complete. |
| 2052 | * |
| 2053 | * Since unlock operations are a one-sided barrier only, |
| 2054 | * we need to insert a barrier here to order any seqno |
| 2055 | * updates before |
| 2056 | * the counter increment. |
| 2057 | */ |
| 2058 | smp_mb__before_atomic_inc(); |
| 2059 | atomic_inc(&dev_priv->gpu_error.reset_counter); |
| 2060 | |
Dave Airlie | 5bdebb1 | 2013-10-11 14:07:25 +1000 | [diff] [blame] | 2061 | kobject_uevent_env(&dev->primary->kdev->kobj, |
Daniel Vetter | f69061b | 2012-12-06 09:01:42 +0100 | [diff] [blame] | 2062 | KOBJ_CHANGE, reset_done_event); |
Daniel Vetter | 1f83fee | 2012-11-15 17:17:22 +0100 | [diff] [blame] | 2063 | } else { |
Mika Kuoppala | 2ac0f45 | 2013-11-12 14:44:19 +0200 | [diff] [blame] | 2064 | atomic_set_mask(I915_WEDGED, &error->reset_counter); |
Ben Gamari | f316a42 | 2009-09-14 17:48:46 -0400 | [diff] [blame] | 2065 | } |
Daniel Vetter | 1f83fee | 2012-11-15 17:17:22 +0100 | [diff] [blame] | 2066 | |
Daniel Vetter | 17e1df0 | 2013-09-08 21:57:13 +0200 | [diff] [blame] | 2067 | /* |
| 2068 | * Note: The wake_up also serves as a memory barrier so that |
| 2069 | * waiters see the update value of the reset counter atomic_t. |
| 2070 | */ |
| 2071 | i915_error_wake_up(dev_priv, true); |
Ben Gamari | f316a42 | 2009-09-14 17:48:46 -0400 | [diff] [blame] | 2072 | } |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2073 | } |
| 2074 | |
Chris Wilson | 35aed2e | 2010-05-27 13:18:12 +0100 | [diff] [blame] | 2075 | static void i915_report_and_clear_eir(struct drm_device *dev) |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2076 | { |
| 2077 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ben Widawsky | bd9854f | 2012-08-23 15:18:09 -0700 | [diff] [blame] | 2078 | uint32_t instdone[I915_NUM_INSTDONE_REG]; |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2079 | u32 eir = I915_READ(EIR); |
Ben Widawsky | 050ee91 | 2012-08-22 11:32:15 -0700 | [diff] [blame] | 2080 | int pipe, i; |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2081 | |
Chris Wilson | 35aed2e | 2010-05-27 13:18:12 +0100 | [diff] [blame] | 2082 | if (!eir) |
| 2083 | return; |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2084 | |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 2085 | pr_err("render error detected, EIR: 0x%08x\n", eir); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2086 | |
Ben Widawsky | bd9854f | 2012-08-23 15:18:09 -0700 | [diff] [blame] | 2087 | i915_get_extra_instdone(dev, instdone); |
| 2088 | |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2089 | if (IS_G4X(dev)) { |
| 2090 | if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) { |
| 2091 | u32 ipeir = I915_READ(IPEIR_I965); |
| 2092 | |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 2093 | pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); |
| 2094 | pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); |
Ben Widawsky | 050ee91 | 2012-08-22 11:32:15 -0700 | [diff] [blame] | 2095 | for (i = 0; i < ARRAY_SIZE(instdone); i++) |
| 2096 | pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]); |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 2097 | pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 2098 | pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2099 | I915_WRITE(IPEIR_I965, ipeir); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 2100 | POSTING_READ(IPEIR_I965); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2101 | } |
| 2102 | if (eir & GM45_ERROR_PAGE_TABLE) { |
| 2103 | u32 pgtbl_err = I915_READ(PGTBL_ER); |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 2104 | pr_err("page table error\n"); |
| 2105 | pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2106 | I915_WRITE(PGTBL_ER, pgtbl_err); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 2107 | POSTING_READ(PGTBL_ER); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2108 | } |
| 2109 | } |
| 2110 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2111 | if (!IS_GEN2(dev)) { |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2112 | if (eir & I915_ERROR_PAGE_TABLE) { |
| 2113 | u32 pgtbl_err = I915_READ(PGTBL_ER); |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 2114 | pr_err("page table error\n"); |
| 2115 | pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2116 | I915_WRITE(PGTBL_ER, pgtbl_err); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 2117 | POSTING_READ(PGTBL_ER); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2118 | } |
| 2119 | } |
| 2120 | |
| 2121 | if (eir & I915_ERROR_MEMORY_REFRESH) { |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 2122 | pr_err("memory refresh error:\n"); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 2123 | for_each_pipe(pipe) |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 2124 | pr_err("pipe %c stat: 0x%08x\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 2125 | pipe_name(pipe), I915_READ(PIPESTAT(pipe))); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2126 | /* pipestat has already been acked */ |
| 2127 | } |
| 2128 | if (eir & I915_ERROR_INSTRUCTION) { |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 2129 | pr_err("instruction error\n"); |
| 2130 | pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM)); |
Ben Widawsky | 050ee91 | 2012-08-22 11:32:15 -0700 | [diff] [blame] | 2131 | for (i = 0; i < ARRAY_SIZE(instdone); i++) |
| 2132 | pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2133 | if (INTEL_INFO(dev)->gen < 4) { |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2134 | u32 ipeir = I915_READ(IPEIR); |
| 2135 | |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 2136 | pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR)); |
| 2137 | pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR)); |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 2138 | pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD)); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2139 | I915_WRITE(IPEIR, ipeir); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 2140 | POSTING_READ(IPEIR); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2141 | } else { |
| 2142 | u32 ipeir = I915_READ(IPEIR_I965); |
| 2143 | |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 2144 | pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); |
| 2145 | pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 2146 | pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 2147 | pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2148 | I915_WRITE(IPEIR_I965, ipeir); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 2149 | POSTING_READ(IPEIR_I965); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2150 | } |
| 2151 | } |
| 2152 | |
| 2153 | I915_WRITE(EIR, eir); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 2154 | POSTING_READ(EIR); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2155 | eir = I915_READ(EIR); |
| 2156 | if (eir) { |
| 2157 | /* |
| 2158 | * some errors might have become stuck, |
| 2159 | * mask them. |
| 2160 | */ |
| 2161 | DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir); |
| 2162 | I915_WRITE(EMR, I915_READ(EMR) | eir); |
| 2163 | I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); |
| 2164 | } |
Chris Wilson | 35aed2e | 2010-05-27 13:18:12 +0100 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | /** |
| 2168 | * i915_handle_error - handle an error interrupt |
| 2169 | * @dev: drm device |
| 2170 | * |
| 2171 | * Do some basic checking of regsiter state at error interrupt time and |
| 2172 | * dump it to the syslog. Also call i915_capture_error_state() to make |
| 2173 | * sure we get a record and make it available in debugfs. Fire a uevent |
| 2174 | * so userspace knows something bad happened (should trigger collection |
| 2175 | * of a ring dump etc.). |
| 2176 | */ |
Chris Wilson | 527f9e9 | 2010-11-11 01:16:58 +0000 | [diff] [blame] | 2177 | void i915_handle_error(struct drm_device *dev, bool wedged) |
Chris Wilson | 35aed2e | 2010-05-27 13:18:12 +0100 | [diff] [blame] | 2178 | { |
| 2179 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2180 | |
| 2181 | i915_capture_error_state(dev); |
| 2182 | i915_report_and_clear_eir(dev); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2183 | |
Ben Gamari | ba1234d | 2009-09-14 17:48:47 -0400 | [diff] [blame] | 2184 | if (wedged) { |
Daniel Vetter | f69061b | 2012-12-06 09:01:42 +0100 | [diff] [blame] | 2185 | atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG, |
| 2186 | &dev_priv->gpu_error.reset_counter); |
Ben Gamari | ba1234d | 2009-09-14 17:48:47 -0400 | [diff] [blame] | 2187 | |
Ben Gamari | 11ed50e | 2009-09-14 17:48:45 -0400 | [diff] [blame] | 2188 | /* |
Daniel Vetter | 17e1df0 | 2013-09-08 21:57:13 +0200 | [diff] [blame] | 2189 | * Wakeup waiting processes so that the reset work function |
| 2190 | * i915_error_work_func doesn't deadlock trying to grab various |
| 2191 | * locks. By bumping the reset counter first, the woken |
| 2192 | * processes will see a reset in progress and back off, |
| 2193 | * releasing their locks and then wait for the reset completion. |
| 2194 | * We must do this for _all_ gpu waiters that might hold locks |
| 2195 | * that the reset work needs to acquire. |
| 2196 | * |
| 2197 | * Note: The wake_up serves as the required memory barrier to |
| 2198 | * ensure that the waiters see the updated value of the reset |
| 2199 | * counter atomic_t. |
Ben Gamari | 11ed50e | 2009-09-14 17:48:45 -0400 | [diff] [blame] | 2200 | */ |
Daniel Vetter | 17e1df0 | 2013-09-08 21:57:13 +0200 | [diff] [blame] | 2201 | i915_error_wake_up(dev_priv, false); |
Ben Gamari | 11ed50e | 2009-09-14 17:48:45 -0400 | [diff] [blame] | 2202 | } |
| 2203 | |
Daniel Vetter | 122f46b | 2013-09-04 17:36:14 +0200 | [diff] [blame] | 2204 | /* |
| 2205 | * Our reset work can grab modeset locks (since it needs to reset the |
| 2206 | * state of outstanding pagelips). Hence it must not be run on our own |
| 2207 | * dev-priv->wq work queue for otherwise the flush_work in the pageflip |
| 2208 | * code will deadlock. |
| 2209 | */ |
| 2210 | schedule_work(&dev_priv->gpu_error.work); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2211 | } |
| 2212 | |
Ville Syrjälä | 21ad833 | 2013-02-19 15:16:39 +0200 | [diff] [blame] | 2213 | static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe) |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 2214 | { |
| 2215 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 2216 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 2217 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 2218 | struct drm_i915_gem_object *obj; |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 2219 | struct intel_unpin_work *work; |
| 2220 | unsigned long flags; |
| 2221 | bool stall_detected; |
| 2222 | |
| 2223 | /* Ignore early vblank irqs */ |
| 2224 | if (intel_crtc == NULL) |
| 2225 | return; |
| 2226 | |
| 2227 | spin_lock_irqsave(&dev->event_lock, flags); |
| 2228 | work = intel_crtc->unpin_work; |
| 2229 | |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 2230 | if (work == NULL || |
| 2231 | atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE || |
| 2232 | !work->enable_stall_check) { |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 2233 | /* Either the pending flip IRQ arrived, or we're too early. Don't check */ |
| 2234 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 2235 | return; |
| 2236 | } |
| 2237 | |
| 2238 | /* Potential stall - if we see that the flip has happened, assume a missed interrupt */ |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 2239 | obj = work->pending_flip_obj; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2240 | if (INTEL_INFO(dev)->gen >= 4) { |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 2241 | int dspsurf = DSPSURF(intel_crtc->plane); |
Armin Reese | 446f254 | 2012-03-30 16:20:16 -0700 | [diff] [blame] | 2242 | stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) == |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 2243 | i915_gem_obj_ggtt_offset(obj); |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 2244 | } else { |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 2245 | int dspaddr = DSPADDR(intel_crtc->plane); |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 2246 | stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) + |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2247 | crtc->y * crtc->fb->pitches[0] + |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 2248 | crtc->x * crtc->fb->bits_per_pixel/8); |
| 2249 | } |
| 2250 | |
| 2251 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 2252 | |
| 2253 | if (stall_detected) { |
| 2254 | DRM_DEBUG_DRIVER("Pageflip stall detected\n"); |
| 2255 | intel_prepare_page_flip(dev, intel_crtc->plane); |
| 2256 | } |
| 2257 | } |
| 2258 | |
Keith Packard | 42f52ef | 2008-10-18 19:39:29 -0700 | [diff] [blame] | 2259 | /* Called from drm generic code, passed 'crtc' which |
| 2260 | * we use as a pipe index |
| 2261 | */ |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 2262 | static int i915_enable_vblank(struct drm_device *dev, int pipe) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 2263 | { |
| 2264 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 2265 | unsigned long irqflags; |
Jesse Barnes | 71e0ffa | 2009-01-08 10:42:15 -0800 | [diff] [blame] | 2266 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2267 | if (!i915_pipe_enabled(dev, pipe)) |
Jesse Barnes | 71e0ffa | 2009-01-08 10:42:15 -0800 | [diff] [blame] | 2268 | return -EINVAL; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 2269 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2270 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Jesse Barnes | f796cf8 | 2011-04-07 13:58:17 -0700 | [diff] [blame] | 2271 | if (INTEL_INFO(dev)->gen >= 4) |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 2272 | i915_enable_pipestat(dev_priv, pipe, |
| 2273 | PIPE_START_VBLANK_INTERRUPT_ENABLE); |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 2274 | else |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 2275 | i915_enable_pipestat(dev_priv, pipe, |
| 2276 | PIPE_VBLANK_INTERRUPT_ENABLE); |
Chris Wilson | 8692d00e | 2011-02-05 10:08:21 +0000 | [diff] [blame] | 2277 | |
| 2278 | /* maintain vblank delivery even in deep C-states */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame^] | 2279 | if (INTEL_INFO(dev)->gen == 3) |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 2280 | I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS)); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2281 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
Chris Wilson | 8692d00e | 2011-02-05 10:08:21 +0000 | [diff] [blame] | 2282 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 2283 | return 0; |
| 2284 | } |
| 2285 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 2286 | static int ironlake_enable_vblank(struct drm_device *dev, int pipe) |
Jesse Barnes | f796cf8 | 2011-04-07 13:58:17 -0700 | [diff] [blame] | 2287 | { |
| 2288 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 2289 | unsigned long irqflags; |
Paulo Zanoni | b518421 | 2013-07-12 20:00:08 -0300 | [diff] [blame] | 2290 | uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) : |
Daniel Vetter | 40da17c2 | 2013-10-21 18:04:36 +0200 | [diff] [blame] | 2291 | DE_PIPE_VBLANK(pipe); |
Jesse Barnes | f796cf8 | 2011-04-07 13:58:17 -0700 | [diff] [blame] | 2292 | |
| 2293 | if (!i915_pipe_enabled(dev, pipe)) |
| 2294 | return -EINVAL; |
| 2295 | |
| 2296 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Paulo Zanoni | b518421 | 2013-07-12 20:00:08 -0300 | [diff] [blame] | 2297 | ironlake_enable_display_irq(dev_priv, bit); |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 2298 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 2299 | |
| 2300 | return 0; |
| 2301 | } |
| 2302 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2303 | static int valleyview_enable_vblank(struct drm_device *dev, int pipe) |
| 2304 | { |
| 2305 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 2306 | unsigned long irqflags; |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2307 | |
| 2308 | if (!i915_pipe_enabled(dev, pipe)) |
| 2309 | return -EINVAL; |
| 2310 | |
| 2311 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Jesse Barnes | 31acc7f | 2012-06-20 10:53:11 -0700 | [diff] [blame] | 2312 | i915_enable_pipestat(dev_priv, pipe, |
| 2313 | PIPE_START_VBLANK_INTERRUPT_ENABLE); |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2314 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 2315 | |
| 2316 | return 0; |
| 2317 | } |
| 2318 | |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2319 | static int gen8_enable_vblank(struct drm_device *dev, int pipe) |
| 2320 | { |
| 2321 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2322 | unsigned long irqflags; |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2323 | |
| 2324 | if (!i915_pipe_enabled(dev, pipe)) |
| 2325 | return -EINVAL; |
| 2326 | |
| 2327 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Daniel Vetter | 7167d7c | 2013-11-07 11:05:45 +0100 | [diff] [blame] | 2328 | dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK; |
| 2329 | I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]); |
| 2330 | POSTING_READ(GEN8_DE_PIPE_IMR(pipe)); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2331 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 2332 | return 0; |
| 2333 | } |
| 2334 | |
Keith Packard | 42f52ef | 2008-10-18 19:39:29 -0700 | [diff] [blame] | 2335 | /* Called from drm generic code, passed 'crtc' which |
| 2336 | * we use as a pipe index |
| 2337 | */ |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 2338 | static void i915_disable_vblank(struct drm_device *dev, int pipe) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 2339 | { |
| 2340 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 2341 | unsigned long irqflags; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 2342 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2343 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame^] | 2344 | if (INTEL_INFO(dev)->gen == 3) |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 2345 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS)); |
Chris Wilson | 8692d00e | 2011-02-05 10:08:21 +0000 | [diff] [blame] | 2346 | |
Jesse Barnes | f796cf8 | 2011-04-07 13:58:17 -0700 | [diff] [blame] | 2347 | i915_disable_pipestat(dev_priv, pipe, |
| 2348 | PIPE_VBLANK_INTERRUPT_ENABLE | |
| 2349 | PIPE_START_VBLANK_INTERRUPT_ENABLE); |
| 2350 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 2351 | } |
| 2352 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 2353 | static void ironlake_disable_vblank(struct drm_device *dev, int pipe) |
Jesse Barnes | f796cf8 | 2011-04-07 13:58:17 -0700 | [diff] [blame] | 2354 | { |
| 2355 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 2356 | unsigned long irqflags; |
Paulo Zanoni | b518421 | 2013-07-12 20:00:08 -0300 | [diff] [blame] | 2357 | uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) : |
Daniel Vetter | 40da17c2 | 2013-10-21 18:04:36 +0200 | [diff] [blame] | 2358 | DE_PIPE_VBLANK(pipe); |
Jesse Barnes | f796cf8 | 2011-04-07 13:58:17 -0700 | [diff] [blame] | 2359 | |
| 2360 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Paulo Zanoni | b518421 | 2013-07-12 20:00:08 -0300 | [diff] [blame] | 2361 | ironlake_disable_display_irq(dev_priv, bit); |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 2362 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 2363 | } |
| 2364 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2365 | static void valleyview_disable_vblank(struct drm_device *dev, int pipe) |
| 2366 | { |
| 2367 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 2368 | unsigned long irqflags; |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2369 | |
| 2370 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Jesse Barnes | 31acc7f | 2012-06-20 10:53:11 -0700 | [diff] [blame] | 2371 | i915_disable_pipestat(dev_priv, pipe, |
| 2372 | PIPE_START_VBLANK_INTERRUPT_ENABLE); |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2373 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 2374 | } |
| 2375 | |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2376 | static void gen8_disable_vblank(struct drm_device *dev, int pipe) |
| 2377 | { |
| 2378 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2379 | unsigned long irqflags; |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2380 | |
| 2381 | if (!i915_pipe_enabled(dev, pipe)) |
| 2382 | return; |
| 2383 | |
| 2384 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Daniel Vetter | 7167d7c | 2013-11-07 11:05:45 +0100 | [diff] [blame] | 2385 | dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK; |
| 2386 | I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]); |
| 2387 | POSTING_READ(GEN8_DE_PIPE_IMR(pipe)); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2388 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 2389 | } |
| 2390 | |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 2391 | static u32 |
| 2392 | ring_last_seqno(struct intel_ring_buffer *ring) |
Zou Nan hai | 852835f | 2010-05-21 09:08:56 +0800 | [diff] [blame] | 2393 | { |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 2394 | return list_entry(ring->request_list.prev, |
| 2395 | struct drm_i915_gem_request, list)->seqno; |
| 2396 | } |
| 2397 | |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 2398 | static bool |
| 2399 | ring_idle(struct intel_ring_buffer *ring, u32 seqno) |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 2400 | { |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 2401 | return (list_empty(&ring->request_list) || |
| 2402 | i915_seqno_passed(seqno, ring_last_seqno(ring))); |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 2403 | } |
| 2404 | |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2405 | static struct intel_ring_buffer * |
| 2406 | semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno) |
Chris Wilson | a24a11e | 2013-03-14 17:52:05 +0200 | [diff] [blame] | 2407 | { |
| 2408 | struct drm_i915_private *dev_priv = ring->dev->dev_private; |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2409 | u32 cmd, ipehr, acthd, acthd_min; |
Chris Wilson | a24a11e | 2013-03-14 17:52:05 +0200 | [diff] [blame] | 2410 | |
| 2411 | ipehr = I915_READ(RING_IPEHR(ring->mmio_base)); |
| 2412 | if ((ipehr & ~(0x3 << 16)) != |
| 2413 | (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER)) |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2414 | return NULL; |
Chris Wilson | a24a11e | 2013-03-14 17:52:05 +0200 | [diff] [blame] | 2415 | |
| 2416 | /* ACTHD is likely pointing to the dword after the actual command, |
| 2417 | * so scan backwards until we find the MBOX. |
| 2418 | */ |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2419 | acthd = intel_ring_get_active_head(ring) & HEAD_ADDR; |
Chris Wilson | a24a11e | 2013-03-14 17:52:05 +0200 | [diff] [blame] | 2420 | acthd_min = max((int)acthd - 3 * 4, 0); |
| 2421 | do { |
| 2422 | cmd = ioread32(ring->virtual_start + acthd); |
| 2423 | if (cmd == ipehr) |
| 2424 | break; |
| 2425 | |
| 2426 | acthd -= 4; |
| 2427 | if (acthd < acthd_min) |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2428 | return NULL; |
Chris Wilson | a24a11e | 2013-03-14 17:52:05 +0200 | [diff] [blame] | 2429 | } while (1); |
| 2430 | |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2431 | *seqno = ioread32(ring->virtual_start+acthd+4)+1; |
| 2432 | return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3]; |
Chris Wilson | a24a11e | 2013-03-14 17:52:05 +0200 | [diff] [blame] | 2433 | } |
| 2434 | |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2435 | static int semaphore_passed(struct intel_ring_buffer *ring) |
| 2436 | { |
| 2437 | struct drm_i915_private *dev_priv = ring->dev->dev_private; |
| 2438 | struct intel_ring_buffer *signaller; |
| 2439 | u32 seqno, ctl; |
| 2440 | |
| 2441 | ring->hangcheck.deadlock = true; |
| 2442 | |
| 2443 | signaller = semaphore_waits_for(ring, &seqno); |
| 2444 | if (signaller == NULL || signaller->hangcheck.deadlock) |
| 2445 | return -1; |
| 2446 | |
| 2447 | /* cursory check for an unkickable deadlock */ |
| 2448 | ctl = I915_READ_CTL(signaller); |
| 2449 | if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0) |
| 2450 | return -1; |
| 2451 | |
| 2452 | return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno); |
| 2453 | } |
| 2454 | |
| 2455 | static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv) |
| 2456 | { |
| 2457 | struct intel_ring_buffer *ring; |
| 2458 | int i; |
| 2459 | |
| 2460 | for_each_ring(ring, dev_priv, i) |
| 2461 | ring->hangcheck.deadlock = false; |
| 2462 | } |
| 2463 | |
Mika Kuoppala | ad8beae | 2013-06-12 12:35:32 +0300 | [diff] [blame] | 2464 | static enum intel_ring_hangcheck_action |
| 2465 | ring_stuck(struct intel_ring_buffer *ring, u32 acthd) |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2466 | { |
| 2467 | struct drm_device *dev = ring->dev; |
| 2468 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 2469 | u32 tmp; |
| 2470 | |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2471 | if (ring->hangcheck.acthd != acthd) |
Jani Nikula | f2f4d82 | 2013-08-11 12:44:01 +0300 | [diff] [blame] | 2472 | return HANGCHECK_ACTIVE; |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2473 | |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 2474 | if (IS_GEN2(dev)) |
Jani Nikula | f2f4d82 | 2013-08-11 12:44:01 +0300 | [diff] [blame] | 2475 | return HANGCHECK_HUNG; |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 2476 | |
| 2477 | /* Is the chip hanging on a WAIT_FOR_EVENT? |
| 2478 | * If so we can simply poke the RB_WAIT bit |
| 2479 | * and break the hang. This should work on |
| 2480 | * all but the second generation chipsets. |
| 2481 | */ |
| 2482 | tmp = I915_READ_CTL(ring); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2483 | if (tmp & RING_WAIT) { |
| 2484 | DRM_ERROR("Kicking stuck wait on %s\n", |
| 2485 | ring->name); |
Chris Wilson | 09e14bf | 2013-10-10 09:37:19 +0100 | [diff] [blame] | 2486 | i915_handle_error(dev, false); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2487 | I915_WRITE_CTL(ring, tmp); |
Jani Nikula | f2f4d82 | 2013-08-11 12:44:01 +0300 | [diff] [blame] | 2488 | return HANGCHECK_KICK; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2489 | } |
Chris Wilson | a24a11e | 2013-03-14 17:52:05 +0200 | [diff] [blame] | 2490 | |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2491 | if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) { |
| 2492 | switch (semaphore_passed(ring)) { |
| 2493 | default: |
Jani Nikula | f2f4d82 | 2013-08-11 12:44:01 +0300 | [diff] [blame] | 2494 | return HANGCHECK_HUNG; |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2495 | case 1: |
| 2496 | DRM_ERROR("Kicking stuck semaphore on %s\n", |
| 2497 | ring->name); |
Chris Wilson | 09e14bf | 2013-10-10 09:37:19 +0100 | [diff] [blame] | 2498 | i915_handle_error(dev, false); |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2499 | I915_WRITE_CTL(ring, tmp); |
Jani Nikula | f2f4d82 | 2013-08-11 12:44:01 +0300 | [diff] [blame] | 2500 | return HANGCHECK_KICK; |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2501 | case 0: |
Jani Nikula | f2f4d82 | 2013-08-11 12:44:01 +0300 | [diff] [blame] | 2502 | return HANGCHECK_WAIT; |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2503 | } |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 2504 | } |
Mika Kuoppala | ed5cbb0 | 2013-05-13 16:32:11 +0300 | [diff] [blame] | 2505 | |
Jani Nikula | f2f4d82 | 2013-08-11 12:44:01 +0300 | [diff] [blame] | 2506 | return HANGCHECK_HUNG; |
Mika Kuoppala | ed5cbb0 | 2013-05-13 16:32:11 +0300 | [diff] [blame] | 2507 | } |
| 2508 | |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 2509 | /** |
| 2510 | * This is called when the chip hasn't reported back with completed |
Mika Kuoppala | 05407ff | 2013-05-30 09:04:29 +0300 | [diff] [blame] | 2511 | * batchbuffers in a long time. We keep track per ring seqno progress and |
| 2512 | * if there are no progress, hangcheck score for that ring is increased. |
| 2513 | * Further, acthd is inspected to see if the ring is stuck. On stuck case |
| 2514 | * we kick the ring. If we see no progress on three subsequent calls |
| 2515 | * we assume chip is wedged and try to fix it by resetting the chip. |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 2516 | */ |
Damien Lespiau | a658b5d | 2013-08-08 22:28:56 +0100 | [diff] [blame] | 2517 | static void i915_hangcheck_elapsed(unsigned long data) |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 2518 | { |
| 2519 | struct drm_device *dev = (struct drm_device *)data; |
| 2520 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | b451951 | 2012-05-11 14:29:30 +0100 | [diff] [blame] | 2521 | struct intel_ring_buffer *ring; |
Chris Wilson | b451951 | 2012-05-11 14:29:30 +0100 | [diff] [blame] | 2522 | int i; |
Mika Kuoppala | 05407ff | 2013-05-30 09:04:29 +0300 | [diff] [blame] | 2523 | int busy_count = 0, rings_hung = 0; |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 2524 | bool stuck[I915_NUM_RINGS] = { 0 }; |
| 2525 | #define BUSY 1 |
| 2526 | #define KICK 5 |
| 2527 | #define HUNG 20 |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 2528 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 2529 | if (!i915.enable_hangcheck) |
Ben Widawsky | 3e0dc6b | 2011-06-29 10:26:42 -0700 | [diff] [blame] | 2530 | return; |
| 2531 | |
Chris Wilson | b451951 | 2012-05-11 14:29:30 +0100 | [diff] [blame] | 2532 | for_each_ring(ring, dev_priv, i) { |
Mika Kuoppala | 05407ff | 2013-05-30 09:04:29 +0300 | [diff] [blame] | 2533 | u32 seqno, acthd; |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 2534 | bool busy = true; |
Chris Wilson | b451951 | 2012-05-11 14:29:30 +0100 | [diff] [blame] | 2535 | |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2536 | semaphore_clear_deadlocks(dev_priv); |
| 2537 | |
Mika Kuoppala | 05407ff | 2013-05-30 09:04:29 +0300 | [diff] [blame] | 2538 | seqno = ring->get_seqno(ring, false); |
| 2539 | acthd = intel_ring_get_active_head(ring); |
Chris Wilson | d1e61e7 | 2012-04-10 17:00:41 +0100 | [diff] [blame] | 2540 | |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 2541 | if (ring->hangcheck.seqno == seqno) { |
| 2542 | if (ring_idle(ring, seqno)) { |
Mika Kuoppala | da66146 | 2013-09-06 16:03:28 +0300 | [diff] [blame] | 2543 | ring->hangcheck.action = HANGCHECK_IDLE; |
| 2544 | |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 2545 | if (waitqueue_active(&ring->irq_queue)) { |
| 2546 | /* Issue a wake-up to catch stuck h/w. */ |
Chris Wilson | 094f9a5 | 2013-09-25 17:34:55 +0100 | [diff] [blame] | 2547 | if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) { |
Daniel Vetter | f4adcd2 | 2013-10-28 09:24:13 +0100 | [diff] [blame] | 2548 | if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring))) |
| 2549 | DRM_ERROR("Hangcheck timer elapsed... %s idle\n", |
| 2550 | ring->name); |
| 2551 | else |
| 2552 | DRM_INFO("Fake missed irq on %s\n", |
| 2553 | ring->name); |
Chris Wilson | 094f9a5 | 2013-09-25 17:34:55 +0100 | [diff] [blame] | 2554 | wake_up_all(&ring->irq_queue); |
| 2555 | } |
| 2556 | /* Safeguard against driver failure */ |
| 2557 | ring->hangcheck.score += BUSY; |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 2558 | } else |
| 2559 | busy = false; |
Mika Kuoppala | 05407ff | 2013-05-30 09:04:29 +0300 | [diff] [blame] | 2560 | } else { |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2561 | /* We always increment the hangcheck score |
| 2562 | * if the ring is busy and still processing |
| 2563 | * the same request, so that no single request |
| 2564 | * can run indefinitely (such as a chain of |
| 2565 | * batches). The only time we do not increment |
| 2566 | * the hangcheck score on this ring, if this |
| 2567 | * ring is in a legitimate wait for another |
| 2568 | * ring. In that case the waiting ring is a |
| 2569 | * victim and we want to be sure we catch the |
| 2570 | * right culprit. Then every time we do kick |
| 2571 | * the ring, add a small increment to the |
| 2572 | * score so that we can catch a batch that is |
| 2573 | * being repeatedly kicked and so responsible |
| 2574 | * for stalling the machine. |
| 2575 | */ |
Mika Kuoppala | ad8beae | 2013-06-12 12:35:32 +0300 | [diff] [blame] | 2576 | ring->hangcheck.action = ring_stuck(ring, |
| 2577 | acthd); |
| 2578 | |
| 2579 | switch (ring->hangcheck.action) { |
Mika Kuoppala | da66146 | 2013-09-06 16:03:28 +0300 | [diff] [blame] | 2580 | case HANGCHECK_IDLE: |
Jani Nikula | f2f4d82 | 2013-08-11 12:44:01 +0300 | [diff] [blame] | 2581 | case HANGCHECK_WAIT: |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2582 | break; |
Jani Nikula | f2f4d82 | 2013-08-11 12:44:01 +0300 | [diff] [blame] | 2583 | case HANGCHECK_ACTIVE: |
Jani Nikula | ea04cb3 | 2013-08-11 12:44:02 +0300 | [diff] [blame] | 2584 | ring->hangcheck.score += BUSY; |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2585 | break; |
Jani Nikula | f2f4d82 | 2013-08-11 12:44:01 +0300 | [diff] [blame] | 2586 | case HANGCHECK_KICK: |
Jani Nikula | ea04cb3 | 2013-08-11 12:44:02 +0300 | [diff] [blame] | 2587 | ring->hangcheck.score += KICK; |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2588 | break; |
Jani Nikula | f2f4d82 | 2013-08-11 12:44:01 +0300 | [diff] [blame] | 2589 | case HANGCHECK_HUNG: |
Jani Nikula | ea04cb3 | 2013-08-11 12:44:02 +0300 | [diff] [blame] | 2590 | ring->hangcheck.score += HUNG; |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2591 | stuck[i] = true; |
| 2592 | break; |
| 2593 | } |
Mika Kuoppala | 05407ff | 2013-05-30 09:04:29 +0300 | [diff] [blame] | 2594 | } |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 2595 | } else { |
Mika Kuoppala | da66146 | 2013-09-06 16:03:28 +0300 | [diff] [blame] | 2596 | ring->hangcheck.action = HANGCHECK_ACTIVE; |
| 2597 | |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 2598 | /* Gradually reduce the count so that we catch DoS |
| 2599 | * attempts across multiple batches. |
| 2600 | */ |
| 2601 | if (ring->hangcheck.score > 0) |
| 2602 | ring->hangcheck.score--; |
Chris Wilson | d1e61e7 | 2012-04-10 17:00:41 +0100 | [diff] [blame] | 2603 | } |
| 2604 | |
Mika Kuoppala | 05407ff | 2013-05-30 09:04:29 +0300 | [diff] [blame] | 2605 | ring->hangcheck.seqno = seqno; |
| 2606 | ring->hangcheck.acthd = acthd; |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 2607 | busy_count += busy; |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 2608 | } |
Eric Anholt | b9201c1 | 2010-01-08 14:25:16 -0800 | [diff] [blame] | 2609 | |
Mika Kuoppala | 92cab73 | 2013-05-24 17:16:07 +0300 | [diff] [blame] | 2610 | for_each_ring(ring, dev_priv, i) { |
Mika Kuoppala | b6b0fac | 2014-01-30 19:04:43 +0200 | [diff] [blame] | 2611 | if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) { |
Daniel Vetter | b8d88d1 | 2013-08-28 10:57:59 +0200 | [diff] [blame] | 2612 | DRM_INFO("%s on %s\n", |
| 2613 | stuck[i] ? "stuck" : "no progress", |
| 2614 | ring->name); |
Chris Wilson | a43adf0 | 2013-06-10 11:20:22 +0100 | [diff] [blame] | 2615 | rings_hung++; |
Mika Kuoppala | 92cab73 | 2013-05-24 17:16:07 +0300 | [diff] [blame] | 2616 | } |
| 2617 | } |
| 2618 | |
Mika Kuoppala | 05407ff | 2013-05-30 09:04:29 +0300 | [diff] [blame] | 2619 | if (rings_hung) |
| 2620 | return i915_handle_error(dev, true); |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 2621 | |
Mika Kuoppala | 05407ff | 2013-05-30 09:04:29 +0300 | [diff] [blame] | 2622 | if (busy_count) |
| 2623 | /* Reset timer case chip hangs without another request |
| 2624 | * being added */ |
Mika Kuoppala | 10cd45b | 2013-07-03 17:22:08 +0300 | [diff] [blame] | 2625 | i915_queue_hangcheck(dev); |
| 2626 | } |
| 2627 | |
| 2628 | void i915_queue_hangcheck(struct drm_device *dev) |
| 2629 | { |
| 2630 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 2631 | if (!i915.enable_hangcheck) |
Mika Kuoppala | 10cd45b | 2013-07-03 17:22:08 +0300 | [diff] [blame] | 2632 | return; |
| 2633 | |
| 2634 | mod_timer(&dev_priv->gpu_error.hangcheck_timer, |
| 2635 | round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES)); |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 2636 | } |
| 2637 | |
Paulo Zanoni | 91738a9 | 2013-06-05 14:21:51 -0300 | [diff] [blame] | 2638 | static void ibx_irq_preinstall(struct drm_device *dev) |
| 2639 | { |
| 2640 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2641 | |
| 2642 | if (HAS_PCH_NOP(dev)) |
| 2643 | return; |
| 2644 | |
| 2645 | /* south display irq */ |
| 2646 | I915_WRITE(SDEIMR, 0xffffffff); |
| 2647 | /* |
| 2648 | * SDEIER is also touched by the interrupt handler to work around missed |
| 2649 | * PCH interrupts. Hence we can't update it after the interrupt handler |
| 2650 | * is enabled - instead we unconditionally enable all PCH interrupt |
| 2651 | * sources here, but then only unmask them as needed with SDEIMR. |
| 2652 | */ |
| 2653 | I915_WRITE(SDEIER, 0xffffffff); |
| 2654 | POSTING_READ(SDEIER); |
| 2655 | } |
| 2656 | |
Daniel Vetter | d18ea1b | 2013-07-12 22:43:25 +0200 | [diff] [blame] | 2657 | static void gen5_gt_irq_preinstall(struct drm_device *dev) |
| 2658 | { |
| 2659 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2660 | |
| 2661 | /* and GT */ |
| 2662 | I915_WRITE(GTIMR, 0xffffffff); |
| 2663 | I915_WRITE(GTIER, 0x0); |
| 2664 | POSTING_READ(GTIER); |
| 2665 | |
| 2666 | if (INTEL_INFO(dev)->gen >= 6) { |
| 2667 | /* and PM */ |
| 2668 | I915_WRITE(GEN6_PMIMR, 0xffffffff); |
| 2669 | I915_WRITE(GEN6_PMIER, 0x0); |
| 2670 | POSTING_READ(GEN6_PMIER); |
| 2671 | } |
| 2672 | } |
| 2673 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2674 | /* drm_dma.h hooks |
| 2675 | */ |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 2676 | static void ironlake_irq_preinstall(struct drm_device *dev) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2677 | { |
| 2678 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 2679 | |
| 2680 | I915_WRITE(HWSTAM, 0xeffe); |
Daniel Vetter | bdfcdb6 | 2012-01-05 01:05:26 +0100 | [diff] [blame] | 2681 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2682 | I915_WRITE(DEIMR, 0xffffffff); |
| 2683 | I915_WRITE(DEIER, 0x0); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 2684 | POSTING_READ(DEIER); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2685 | |
Daniel Vetter | d18ea1b | 2013-07-12 22:43:25 +0200 | [diff] [blame] | 2686 | gen5_gt_irq_preinstall(dev); |
Zhenyu Wang | c650156 | 2009-11-03 18:57:21 +0000 | [diff] [blame] | 2687 | |
Paulo Zanoni | 91738a9 | 2013-06-05 14:21:51 -0300 | [diff] [blame] | 2688 | ibx_irq_preinstall(dev); |
Ben Widawsky | 7d99163 | 2013-05-28 19:22:25 -0700 | [diff] [blame] | 2689 | } |
| 2690 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2691 | static void valleyview_irq_preinstall(struct drm_device *dev) |
| 2692 | { |
| 2693 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 2694 | int pipe; |
| 2695 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2696 | /* VLV magic */ |
| 2697 | I915_WRITE(VLV_IMR, 0); |
| 2698 | I915_WRITE(RING_IMR(RENDER_RING_BASE), 0); |
| 2699 | I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0); |
| 2700 | I915_WRITE(RING_IMR(BLT_RING_BASE), 0); |
| 2701 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2702 | /* and GT */ |
| 2703 | I915_WRITE(GTIIR, I915_READ(GTIIR)); |
| 2704 | I915_WRITE(GTIIR, I915_READ(GTIIR)); |
Daniel Vetter | d18ea1b | 2013-07-12 22:43:25 +0200 | [diff] [blame] | 2705 | |
| 2706 | gen5_gt_irq_preinstall(dev); |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2707 | |
| 2708 | I915_WRITE(DPINVGTT, 0xff); |
| 2709 | |
| 2710 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
| 2711 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); |
| 2712 | for_each_pipe(pipe) |
| 2713 | I915_WRITE(PIPESTAT(pipe), 0xffff); |
| 2714 | I915_WRITE(VLV_IIR, 0xffffffff); |
| 2715 | I915_WRITE(VLV_IMR, 0xffffffff); |
| 2716 | I915_WRITE(VLV_IER, 0x0); |
| 2717 | POSTING_READ(VLV_IER); |
| 2718 | } |
| 2719 | |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2720 | static void gen8_irq_preinstall(struct drm_device *dev) |
| 2721 | { |
| 2722 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2723 | int pipe; |
| 2724 | |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2725 | I915_WRITE(GEN8_MASTER_IRQ, 0); |
| 2726 | POSTING_READ(GEN8_MASTER_IRQ); |
| 2727 | |
| 2728 | /* IIR can theoretically queue up two events. Be paranoid */ |
| 2729 | #define GEN8_IRQ_INIT_NDX(type, which) do { \ |
| 2730 | I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \ |
| 2731 | POSTING_READ(GEN8_##type##_IMR(which)); \ |
| 2732 | I915_WRITE(GEN8_##type##_IER(which), 0); \ |
| 2733 | I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \ |
| 2734 | POSTING_READ(GEN8_##type##_IIR(which)); \ |
| 2735 | I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \ |
| 2736 | } while (0) |
| 2737 | |
| 2738 | #define GEN8_IRQ_INIT(type) do { \ |
| 2739 | I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \ |
| 2740 | POSTING_READ(GEN8_##type##_IMR); \ |
| 2741 | I915_WRITE(GEN8_##type##_IER, 0); \ |
| 2742 | I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \ |
| 2743 | POSTING_READ(GEN8_##type##_IIR); \ |
| 2744 | I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \ |
| 2745 | } while (0) |
| 2746 | |
| 2747 | GEN8_IRQ_INIT_NDX(GT, 0); |
| 2748 | GEN8_IRQ_INIT_NDX(GT, 1); |
| 2749 | GEN8_IRQ_INIT_NDX(GT, 2); |
| 2750 | GEN8_IRQ_INIT_NDX(GT, 3); |
| 2751 | |
| 2752 | for_each_pipe(pipe) { |
| 2753 | GEN8_IRQ_INIT_NDX(DE_PIPE, pipe); |
| 2754 | } |
| 2755 | |
| 2756 | GEN8_IRQ_INIT(DE_PORT); |
| 2757 | GEN8_IRQ_INIT(DE_MISC); |
| 2758 | GEN8_IRQ_INIT(PCU); |
| 2759 | #undef GEN8_IRQ_INIT |
| 2760 | #undef GEN8_IRQ_INIT_NDX |
| 2761 | |
| 2762 | POSTING_READ(GEN8_PCU_IIR); |
Jesse Barnes | 09f2344 | 2014-01-10 13:13:09 -0800 | [diff] [blame] | 2763 | |
| 2764 | ibx_irq_preinstall(dev); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2765 | } |
| 2766 | |
Daniel Vetter | 82a28bc | 2013-03-27 15:55:01 +0100 | [diff] [blame] | 2767 | static void ibx_hpd_irq_setup(struct drm_device *dev) |
Keith Packard | 7fe0b97 | 2011-09-19 13:31:02 -0700 | [diff] [blame] | 2768 | { |
| 2769 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Daniel Vetter | 82a28bc | 2013-03-27 15:55:01 +0100 | [diff] [blame] | 2770 | struct drm_mode_config *mode_config = &dev->mode_config; |
| 2771 | struct intel_encoder *intel_encoder; |
Daniel Vetter | fee884e | 2013-07-04 23:35:21 +0200 | [diff] [blame] | 2772 | u32 hotplug_irqs, hotplug, enabled_irqs = 0; |
Keith Packard | 7fe0b97 | 2011-09-19 13:31:02 -0700 | [diff] [blame] | 2773 | |
Daniel Vetter | 82a28bc | 2013-03-27 15:55:01 +0100 | [diff] [blame] | 2774 | if (HAS_PCH_IBX(dev)) { |
Daniel Vetter | fee884e | 2013-07-04 23:35:21 +0200 | [diff] [blame] | 2775 | hotplug_irqs = SDE_HOTPLUG_MASK; |
Daniel Vetter | 82a28bc | 2013-03-27 15:55:01 +0100 | [diff] [blame] | 2776 | list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head) |
Egbert Eich | cd569ae | 2013-04-16 13:36:57 +0200 | [diff] [blame] | 2777 | if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) |
Daniel Vetter | fee884e | 2013-07-04 23:35:21 +0200 | [diff] [blame] | 2778 | enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin]; |
Daniel Vetter | 82a28bc | 2013-03-27 15:55:01 +0100 | [diff] [blame] | 2779 | } else { |
Daniel Vetter | fee884e | 2013-07-04 23:35:21 +0200 | [diff] [blame] | 2780 | hotplug_irqs = SDE_HOTPLUG_MASK_CPT; |
Daniel Vetter | 82a28bc | 2013-03-27 15:55:01 +0100 | [diff] [blame] | 2781 | list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head) |
Egbert Eich | cd569ae | 2013-04-16 13:36:57 +0200 | [diff] [blame] | 2782 | if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) |
Daniel Vetter | fee884e | 2013-07-04 23:35:21 +0200 | [diff] [blame] | 2783 | enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin]; |
Daniel Vetter | 82a28bc | 2013-03-27 15:55:01 +0100 | [diff] [blame] | 2784 | } |
| 2785 | |
Daniel Vetter | fee884e | 2013-07-04 23:35:21 +0200 | [diff] [blame] | 2786 | ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); |
Daniel Vetter | 82a28bc | 2013-03-27 15:55:01 +0100 | [diff] [blame] | 2787 | |
| 2788 | /* |
| 2789 | * Enable digital hotplug on the PCH, and configure the DP short pulse |
| 2790 | * duration to 2ms (which is the minimum in the Display Port spec) |
| 2791 | * |
| 2792 | * This register is the same on all known PCH chips. |
| 2793 | */ |
Keith Packard | 7fe0b97 | 2011-09-19 13:31:02 -0700 | [diff] [blame] | 2794 | hotplug = I915_READ(PCH_PORT_HOTPLUG); |
| 2795 | hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK); |
| 2796 | hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms; |
| 2797 | hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms; |
| 2798 | hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms; |
| 2799 | I915_WRITE(PCH_PORT_HOTPLUG, hotplug); |
| 2800 | } |
| 2801 | |
Paulo Zanoni | d46da43 | 2013-02-08 17:35:15 -0200 | [diff] [blame] | 2802 | static void ibx_irq_postinstall(struct drm_device *dev) |
| 2803 | { |
| 2804 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Daniel Vetter | 82a28bc | 2013-03-27 15:55:01 +0100 | [diff] [blame] | 2805 | u32 mask; |
Paulo Zanoni | d46da43 | 2013-02-08 17:35:15 -0200 | [diff] [blame] | 2806 | |
Daniel Vetter | 692a04c | 2013-05-29 21:43:05 +0200 | [diff] [blame] | 2807 | if (HAS_PCH_NOP(dev)) |
| 2808 | return; |
| 2809 | |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 2810 | if (HAS_PCH_IBX(dev)) { |
| 2811 | mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER | |
Paulo Zanoni | de032bf | 2013-04-12 17:57:58 -0300 | [diff] [blame] | 2812 | SDE_TRANSA_FIFO_UNDER | SDE_POISON; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 2813 | } else { |
| 2814 | mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT; |
| 2815 | |
| 2816 | I915_WRITE(SERR_INT, I915_READ(SERR_INT)); |
| 2817 | } |
Ben Widawsky | ab5c608 | 2013-04-05 13:12:41 -0700 | [diff] [blame] | 2818 | |
Paulo Zanoni | d46da43 | 2013-02-08 17:35:15 -0200 | [diff] [blame] | 2819 | I915_WRITE(SDEIIR, I915_READ(SDEIIR)); |
| 2820 | I915_WRITE(SDEIMR, ~mask); |
Paulo Zanoni | d46da43 | 2013-02-08 17:35:15 -0200 | [diff] [blame] | 2821 | } |
| 2822 | |
Daniel Vetter | 0a9a8c9 | 2013-07-12 22:43:26 +0200 | [diff] [blame] | 2823 | static void gen5_gt_irq_postinstall(struct drm_device *dev) |
| 2824 | { |
| 2825 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2826 | u32 pm_irqs, gt_irqs; |
| 2827 | |
| 2828 | pm_irqs = gt_irqs = 0; |
| 2829 | |
| 2830 | dev_priv->gt_irq_mask = ~0; |
Ben Widawsky | 040d2ba | 2013-09-19 11:01:40 -0700 | [diff] [blame] | 2831 | if (HAS_L3_DPF(dev)) { |
Daniel Vetter | 0a9a8c9 | 2013-07-12 22:43:26 +0200 | [diff] [blame] | 2832 | /* L3 parity interrupt is always unmasked. */ |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 2833 | dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev); |
| 2834 | gt_irqs |= GT_PARITY_ERROR(dev); |
Daniel Vetter | 0a9a8c9 | 2013-07-12 22:43:26 +0200 | [diff] [blame] | 2835 | } |
| 2836 | |
| 2837 | gt_irqs |= GT_RENDER_USER_INTERRUPT; |
| 2838 | if (IS_GEN5(dev)) { |
| 2839 | gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT | |
| 2840 | ILK_BSD_USER_INTERRUPT; |
| 2841 | } else { |
| 2842 | gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT; |
| 2843 | } |
| 2844 | |
| 2845 | I915_WRITE(GTIIR, I915_READ(GTIIR)); |
| 2846 | I915_WRITE(GTIMR, dev_priv->gt_irq_mask); |
| 2847 | I915_WRITE(GTIER, gt_irqs); |
| 2848 | POSTING_READ(GTIER); |
| 2849 | |
| 2850 | if (INTEL_INFO(dev)->gen >= 6) { |
| 2851 | pm_irqs |= GEN6_PM_RPS_EVENTS; |
| 2852 | |
| 2853 | if (HAS_VEBOX(dev)) |
| 2854 | pm_irqs |= PM_VEBOX_USER_INTERRUPT; |
| 2855 | |
Paulo Zanoni | 605cd25 | 2013-08-06 18:57:15 -0300 | [diff] [blame] | 2856 | dev_priv->pm_irq_mask = 0xffffffff; |
Daniel Vetter | 0a9a8c9 | 2013-07-12 22:43:26 +0200 | [diff] [blame] | 2857 | I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR)); |
Paulo Zanoni | 605cd25 | 2013-08-06 18:57:15 -0300 | [diff] [blame] | 2858 | I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask); |
Daniel Vetter | 0a9a8c9 | 2013-07-12 22:43:26 +0200 | [diff] [blame] | 2859 | I915_WRITE(GEN6_PMIER, pm_irqs); |
| 2860 | POSTING_READ(GEN6_PMIER); |
| 2861 | } |
| 2862 | } |
| 2863 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 2864 | static int ironlake_irq_postinstall(struct drm_device *dev) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2865 | { |
Daniel Vetter | 4bc9d43 | 2013-06-27 13:44:58 +0200 | [diff] [blame] | 2866 | unsigned long irqflags; |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2867 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Paulo Zanoni | 8e76f8d | 2013-07-12 20:01:56 -0300 | [diff] [blame] | 2868 | u32 display_mask, extra_mask; |
| 2869 | |
| 2870 | if (INTEL_INFO(dev)->gen >= 7) { |
| 2871 | display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | |
| 2872 | DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB | |
| 2873 | DE_PLANEB_FLIP_DONE_IVB | |
| 2874 | DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB | |
| 2875 | DE_ERR_INT_IVB); |
| 2876 | extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB | |
| 2877 | DE_PIPEA_VBLANK_IVB); |
| 2878 | |
| 2879 | I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT)); |
| 2880 | } else { |
| 2881 | display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | |
| 2882 | DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE | |
Daniel Vetter | 5b3a856 | 2013-10-16 22:55:48 +0200 | [diff] [blame] | 2883 | DE_AUX_CHANNEL_A | |
| 2884 | DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN | |
| 2885 | DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE | |
| 2886 | DE_POISON); |
Paulo Zanoni | 8e76f8d | 2013-07-12 20:01:56 -0300 | [diff] [blame] | 2887 | extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT; |
| 2888 | } |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2889 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2890 | dev_priv->irq_mask = ~display_mask; |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2891 | |
| 2892 | /* should always can generate irq */ |
| 2893 | I915_WRITE(DEIIR, I915_READ(DEIIR)); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2894 | I915_WRITE(DEIMR, dev_priv->irq_mask); |
Paulo Zanoni | 8e76f8d | 2013-07-12 20:01:56 -0300 | [diff] [blame] | 2895 | I915_WRITE(DEIER, display_mask | extra_mask); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 2896 | POSTING_READ(DEIER); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2897 | |
Daniel Vetter | 0a9a8c9 | 2013-07-12 22:43:26 +0200 | [diff] [blame] | 2898 | gen5_gt_irq_postinstall(dev); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2899 | |
Paulo Zanoni | d46da43 | 2013-02-08 17:35:15 -0200 | [diff] [blame] | 2900 | ibx_irq_postinstall(dev); |
Keith Packard | 7fe0b97 | 2011-09-19 13:31:02 -0700 | [diff] [blame] | 2901 | |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 2902 | if (IS_IRONLAKE_M(dev)) { |
Daniel Vetter | 6005ce4 | 2013-06-27 13:44:59 +0200 | [diff] [blame] | 2903 | /* Enable PCU event interrupts |
| 2904 | * |
| 2905 | * spinlocking not required here for correctness since interrupt |
Daniel Vetter | 4bc9d43 | 2013-06-27 13:44:58 +0200 | [diff] [blame] | 2906 | * setup is guaranteed to run in single-threaded context. But we |
| 2907 | * need it to make the assert_spin_locked happy. */ |
| 2908 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 2909 | ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT); |
Daniel Vetter | 4bc9d43 | 2013-06-27 13:44:58 +0200 | [diff] [blame] | 2910 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 2911 | } |
| 2912 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2913 | return 0; |
| 2914 | } |
| 2915 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2916 | static int valleyview_irq_postinstall(struct drm_device *dev) |
| 2917 | { |
| 2918 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2919 | u32 enable_mask; |
Daniel Vetter | 379ef82 | 2013-10-16 22:55:56 +0200 | [diff] [blame] | 2920 | u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV | |
| 2921 | PIPE_CRC_DONE_ENABLE; |
Daniel Vetter | b79480b | 2013-06-27 17:52:10 +0200 | [diff] [blame] | 2922 | unsigned long irqflags; |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2923 | |
| 2924 | enable_mask = I915_DISPLAY_PORT_INTERRUPT; |
Jesse Barnes | 31acc7f | 2012-06-20 10:53:11 -0700 | [diff] [blame] | 2925 | enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | |
| 2926 | I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT | |
| 2927 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2928 | I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; |
| 2929 | |
Jesse Barnes | 31acc7f | 2012-06-20 10:53:11 -0700 | [diff] [blame] | 2930 | /* |
| 2931 | *Leave vblank interrupts masked initially. enable/disable will |
| 2932 | * toggle them based on usage. |
| 2933 | */ |
| 2934 | dev_priv->irq_mask = (~enable_mask) | |
| 2935 | I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT | |
| 2936 | I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2937 | |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 2938 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
| 2939 | POSTING_READ(PORT_HOTPLUG_EN); |
| 2940 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2941 | I915_WRITE(VLV_IMR, dev_priv->irq_mask); |
| 2942 | I915_WRITE(VLV_IER, enable_mask); |
| 2943 | I915_WRITE(VLV_IIR, 0xffffffff); |
| 2944 | I915_WRITE(PIPESTAT(0), 0xffff); |
| 2945 | I915_WRITE(PIPESTAT(1), 0xffff); |
| 2946 | POSTING_READ(VLV_IER); |
| 2947 | |
Daniel Vetter | b79480b | 2013-06-27 17:52:10 +0200 | [diff] [blame] | 2948 | /* Interrupt setup is already guaranteed to be single-threaded, this is |
| 2949 | * just to make the assert_spin_locked check happy. */ |
| 2950 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Daniel Vetter | 3b6c42e | 2013-10-21 18:04:35 +0200 | [diff] [blame] | 2951 | i915_enable_pipestat(dev_priv, PIPE_A, pipestat_enable); |
| 2952 | i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_EVENT_ENABLE); |
| 2953 | i915_enable_pipestat(dev_priv, PIPE_B, pipestat_enable); |
Daniel Vetter | b79480b | 2013-06-27 17:52:10 +0200 | [diff] [blame] | 2954 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
Jesse Barnes | 31acc7f | 2012-06-20 10:53:11 -0700 | [diff] [blame] | 2955 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2956 | I915_WRITE(VLV_IIR, 0xffffffff); |
| 2957 | I915_WRITE(VLV_IIR, 0xffffffff); |
| 2958 | |
Daniel Vetter | 0a9a8c9 | 2013-07-12 22:43:26 +0200 | [diff] [blame] | 2959 | gen5_gt_irq_postinstall(dev); |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2960 | |
| 2961 | /* ack & enable invalid PTE error interrupts */ |
| 2962 | #if 0 /* FIXME: add support to irq handler for checking these bits */ |
| 2963 | I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK); |
| 2964 | I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK); |
| 2965 | #endif |
| 2966 | |
| 2967 | I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE); |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 2968 | |
| 2969 | return 0; |
| 2970 | } |
| 2971 | |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2972 | static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv) |
| 2973 | { |
| 2974 | int i; |
| 2975 | |
| 2976 | /* These are interrupts we'll toggle with the ring mask register */ |
| 2977 | uint32_t gt_interrupts[] = { |
| 2978 | GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT | |
| 2979 | GT_RENDER_L3_PARITY_ERROR_INTERRUPT | |
| 2980 | GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT, |
| 2981 | GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT | |
| 2982 | GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT, |
| 2983 | 0, |
| 2984 | GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
| 2985 | }; |
| 2986 | |
| 2987 | for (i = 0; i < ARRAY_SIZE(gt_interrupts); i++) { |
| 2988 | u32 tmp = I915_READ(GEN8_GT_IIR(i)); |
| 2989 | if (tmp) |
| 2990 | DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n", |
| 2991 | i, tmp); |
| 2992 | I915_WRITE(GEN8_GT_IMR(i), ~gt_interrupts[i]); |
| 2993 | I915_WRITE(GEN8_GT_IER(i), gt_interrupts[i]); |
| 2994 | } |
| 2995 | POSTING_READ(GEN8_GT_IER(0)); |
| 2996 | } |
| 2997 | |
| 2998 | static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv) |
| 2999 | { |
| 3000 | struct drm_device *dev = dev_priv->dev; |
Daniel Vetter | 13b3a0a | 2013-11-07 15:31:52 +0100 | [diff] [blame] | 3001 | uint32_t de_pipe_masked = GEN8_PIPE_FLIP_DONE | |
| 3002 | GEN8_PIPE_CDCLK_CRC_DONE | |
| 3003 | GEN8_PIPE_FIFO_UNDERRUN | |
| 3004 | GEN8_DE_PIPE_IRQ_FAULT_ERRORS; |
| 3005 | uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK; |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3006 | int pipe; |
Daniel Vetter | 13b3a0a | 2013-11-07 15:31:52 +0100 | [diff] [blame] | 3007 | dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked; |
| 3008 | dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked; |
| 3009 | dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked; |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3010 | |
| 3011 | for_each_pipe(pipe) { |
| 3012 | u32 tmp = I915_READ(GEN8_DE_PIPE_IIR(pipe)); |
| 3013 | if (tmp) |
| 3014 | DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n", |
| 3015 | pipe, tmp); |
| 3016 | I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]); |
| 3017 | I915_WRITE(GEN8_DE_PIPE_IER(pipe), de_pipe_enables); |
| 3018 | } |
| 3019 | POSTING_READ(GEN8_DE_PIPE_ISR(0)); |
| 3020 | |
Daniel Vetter | 6d766f0 | 2013-11-07 14:49:55 +0100 | [diff] [blame] | 3021 | I915_WRITE(GEN8_DE_PORT_IMR, ~GEN8_AUX_CHANNEL_A); |
| 3022 | I915_WRITE(GEN8_DE_PORT_IER, GEN8_AUX_CHANNEL_A); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3023 | POSTING_READ(GEN8_DE_PORT_IER); |
| 3024 | } |
| 3025 | |
| 3026 | static int gen8_irq_postinstall(struct drm_device *dev) |
| 3027 | { |
| 3028 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3029 | |
| 3030 | gen8_gt_irq_postinstall(dev_priv); |
| 3031 | gen8_de_irq_postinstall(dev_priv); |
| 3032 | |
| 3033 | ibx_irq_postinstall(dev); |
| 3034 | |
| 3035 | I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL); |
| 3036 | POSTING_READ(GEN8_MASTER_IRQ); |
| 3037 | |
| 3038 | return 0; |
| 3039 | } |
| 3040 | |
| 3041 | static void gen8_irq_uninstall(struct drm_device *dev) |
| 3042 | { |
| 3043 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3044 | int pipe; |
| 3045 | |
| 3046 | if (!dev_priv) |
| 3047 | return; |
| 3048 | |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3049 | I915_WRITE(GEN8_MASTER_IRQ, 0); |
| 3050 | |
| 3051 | #define GEN8_IRQ_FINI_NDX(type, which) do { \ |
| 3052 | I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \ |
| 3053 | I915_WRITE(GEN8_##type##_IER(which), 0); \ |
| 3054 | I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \ |
| 3055 | } while (0) |
| 3056 | |
| 3057 | #define GEN8_IRQ_FINI(type) do { \ |
| 3058 | I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \ |
| 3059 | I915_WRITE(GEN8_##type##_IER, 0); \ |
| 3060 | I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \ |
| 3061 | } while (0) |
| 3062 | |
| 3063 | GEN8_IRQ_FINI_NDX(GT, 0); |
| 3064 | GEN8_IRQ_FINI_NDX(GT, 1); |
| 3065 | GEN8_IRQ_FINI_NDX(GT, 2); |
| 3066 | GEN8_IRQ_FINI_NDX(GT, 3); |
| 3067 | |
| 3068 | for_each_pipe(pipe) { |
| 3069 | GEN8_IRQ_FINI_NDX(DE_PIPE, pipe); |
| 3070 | } |
| 3071 | |
| 3072 | GEN8_IRQ_FINI(DE_PORT); |
| 3073 | GEN8_IRQ_FINI(DE_MISC); |
| 3074 | GEN8_IRQ_FINI(PCU); |
| 3075 | #undef GEN8_IRQ_FINI |
| 3076 | #undef GEN8_IRQ_FINI_NDX |
| 3077 | |
| 3078 | POSTING_READ(GEN8_PCU_IIR); |
| 3079 | } |
| 3080 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 3081 | static void valleyview_irq_uninstall(struct drm_device *dev) |
| 3082 | { |
| 3083 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 3084 | int pipe; |
| 3085 | |
| 3086 | if (!dev_priv) |
| 3087 | return; |
| 3088 | |
Ville Syrjälä | 3ca1cce | 2014-01-17 13:43:51 +0200 | [diff] [blame] | 3089 | intel_hpd_irq_uninstall(dev_priv); |
Egbert Eich | ac4c16c | 2013-04-16 13:36:58 +0200 | [diff] [blame] | 3090 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 3091 | for_each_pipe(pipe) |
| 3092 | I915_WRITE(PIPESTAT(pipe), 0xffff); |
| 3093 | |
| 3094 | I915_WRITE(HWSTAM, 0xffffffff); |
| 3095 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
| 3096 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); |
| 3097 | for_each_pipe(pipe) |
| 3098 | I915_WRITE(PIPESTAT(pipe), 0xffff); |
| 3099 | I915_WRITE(VLV_IIR, 0xffffffff); |
| 3100 | I915_WRITE(VLV_IMR, 0xffffffff); |
| 3101 | I915_WRITE(VLV_IER, 0x0); |
| 3102 | POSTING_READ(VLV_IER); |
| 3103 | } |
| 3104 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 3105 | static void ironlake_irq_uninstall(struct drm_device *dev) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 3106 | { |
| 3107 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Jesse Barnes | 4697995 | 2011-04-07 13:53:55 -0700 | [diff] [blame] | 3108 | |
| 3109 | if (!dev_priv) |
| 3110 | return; |
| 3111 | |
Ville Syrjälä | 3ca1cce | 2014-01-17 13:43:51 +0200 | [diff] [blame] | 3112 | intel_hpd_irq_uninstall(dev_priv); |
Egbert Eich | ac4c16c | 2013-04-16 13:36:58 +0200 | [diff] [blame] | 3113 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 3114 | I915_WRITE(HWSTAM, 0xffffffff); |
| 3115 | |
| 3116 | I915_WRITE(DEIMR, 0xffffffff); |
| 3117 | I915_WRITE(DEIER, 0x0); |
| 3118 | I915_WRITE(DEIIR, I915_READ(DEIIR)); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 3119 | if (IS_GEN7(dev)) |
| 3120 | I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT)); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 3121 | |
| 3122 | I915_WRITE(GTIMR, 0xffffffff); |
| 3123 | I915_WRITE(GTIER, 0x0); |
| 3124 | I915_WRITE(GTIIR, I915_READ(GTIIR)); |
Keith Packard | 192aac1f | 2011-09-20 10:12:44 -0700 | [diff] [blame] | 3125 | |
Ben Widawsky | ab5c608 | 2013-04-05 13:12:41 -0700 | [diff] [blame] | 3126 | if (HAS_PCH_NOP(dev)) |
| 3127 | return; |
| 3128 | |
Keith Packard | 192aac1f | 2011-09-20 10:12:44 -0700 | [diff] [blame] | 3129 | I915_WRITE(SDEIMR, 0xffffffff); |
| 3130 | I915_WRITE(SDEIER, 0x0); |
| 3131 | I915_WRITE(SDEIIR, I915_READ(SDEIIR)); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 3132 | if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev)) |
| 3133 | I915_WRITE(SERR_INT, I915_READ(SERR_INT)); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 3134 | } |
| 3135 | |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3136 | static void i8xx_irq_preinstall(struct drm_device * dev) |
| 3137 | { |
| 3138 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 3139 | int pipe; |
| 3140 | |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3141 | for_each_pipe(pipe) |
| 3142 | I915_WRITE(PIPESTAT(pipe), 0); |
| 3143 | I915_WRITE16(IMR, 0xffff); |
| 3144 | I915_WRITE16(IER, 0x0); |
| 3145 | POSTING_READ16(IER); |
| 3146 | } |
| 3147 | |
| 3148 | static int i8xx_irq_postinstall(struct drm_device *dev) |
| 3149 | { |
| 3150 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Daniel Vetter | 379ef82 | 2013-10-16 22:55:56 +0200 | [diff] [blame] | 3151 | unsigned long irqflags; |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3152 | |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3153 | I915_WRITE16(EMR, |
| 3154 | ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH)); |
| 3155 | |
| 3156 | /* Unmask the interrupts that we always want on. */ |
| 3157 | dev_priv->irq_mask = |
| 3158 | ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | |
| 3159 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | |
| 3160 | I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | |
| 3161 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | |
| 3162 | I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); |
| 3163 | I915_WRITE16(IMR, dev_priv->irq_mask); |
| 3164 | |
| 3165 | I915_WRITE16(IER, |
| 3166 | I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | |
| 3167 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | |
| 3168 | I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT | |
| 3169 | I915_USER_INTERRUPT); |
| 3170 | POSTING_READ16(IER); |
| 3171 | |
Daniel Vetter | 379ef82 | 2013-10-16 22:55:56 +0200 | [diff] [blame] | 3172 | /* Interrupt setup is already guaranteed to be single-threaded, this is |
| 3173 | * just to make the assert_spin_locked check happy. */ |
| 3174 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Daniel Vetter | 3b6c42e | 2013-10-21 18:04:35 +0200 | [diff] [blame] | 3175 | i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE); |
| 3176 | i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE); |
Daniel Vetter | 379ef82 | 2013-10-16 22:55:56 +0200 | [diff] [blame] | 3177 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 3178 | |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3179 | return 0; |
| 3180 | } |
| 3181 | |
Ville Syrjälä | 90a72f8 | 2013-02-19 23:16:44 +0200 | [diff] [blame] | 3182 | /* |
| 3183 | * Returns true when a page flip has completed. |
| 3184 | */ |
| 3185 | static bool i8xx_handle_vblank(struct drm_device *dev, |
Ville Syrjälä | 1f1c2e2 | 2013-11-28 17:30:01 +0200 | [diff] [blame] | 3186 | int plane, int pipe, u32 iir) |
Ville Syrjälä | 90a72f8 | 2013-02-19 23:16:44 +0200 | [diff] [blame] | 3187 | { |
| 3188 | drm_i915_private_t *dev_priv = dev->dev_private; |
Ville Syrjälä | 1f1c2e2 | 2013-11-28 17:30:01 +0200 | [diff] [blame] | 3189 | u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane); |
Ville Syrjälä | 90a72f8 | 2013-02-19 23:16:44 +0200 | [diff] [blame] | 3190 | |
| 3191 | if (!drm_handle_vblank(dev, pipe)) |
| 3192 | return false; |
| 3193 | |
| 3194 | if ((iir & flip_pending) == 0) |
| 3195 | return false; |
| 3196 | |
Ville Syrjälä | 1f1c2e2 | 2013-11-28 17:30:01 +0200 | [diff] [blame] | 3197 | intel_prepare_page_flip(dev, plane); |
Ville Syrjälä | 90a72f8 | 2013-02-19 23:16:44 +0200 | [diff] [blame] | 3198 | |
| 3199 | /* We detect FlipDone by looking for the change in PendingFlip from '1' |
| 3200 | * to '0' on the following vblank, i.e. IIR has the Pendingflip |
| 3201 | * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence |
| 3202 | * the flip is completed (no longer pending). Since this doesn't raise |
| 3203 | * an interrupt per se, we watch for the change at vblank. |
| 3204 | */ |
| 3205 | if (I915_READ16(ISR) & flip_pending) |
| 3206 | return false; |
| 3207 | |
| 3208 | intel_finish_page_flip(dev, pipe); |
| 3209 | |
| 3210 | return true; |
| 3211 | } |
| 3212 | |
Daniel Vetter | ff1f525 | 2012-10-02 15:10:55 +0200 | [diff] [blame] | 3213 | static irqreturn_t i8xx_irq_handler(int irq, void *arg) |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3214 | { |
| 3215 | struct drm_device *dev = (struct drm_device *) arg; |
| 3216 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3217 | u16 iir, new_iir; |
| 3218 | u32 pipe_stats[2]; |
| 3219 | unsigned long irqflags; |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3220 | int pipe; |
| 3221 | u16 flip_mask = |
| 3222 | I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | |
| 3223 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; |
| 3224 | |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3225 | iir = I915_READ16(IIR); |
| 3226 | if (iir == 0) |
| 3227 | return IRQ_NONE; |
| 3228 | |
| 3229 | while (iir & ~flip_mask) { |
| 3230 | /* Can't rely on pipestat interrupt bit in iir as it might |
| 3231 | * have been cleared after the pipestat interrupt was received. |
| 3232 | * It doesn't set the bit in iir again, but it still produces |
| 3233 | * interrupts (for non-MSI). |
| 3234 | */ |
| 3235 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
| 3236 | if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) |
| 3237 | i915_handle_error(dev, false); |
| 3238 | |
| 3239 | for_each_pipe(pipe) { |
| 3240 | int reg = PIPESTAT(pipe); |
| 3241 | pipe_stats[pipe] = I915_READ(reg); |
| 3242 | |
| 3243 | /* |
| 3244 | * Clear the PIPE*STAT regs before the IIR |
| 3245 | */ |
Ville Syrjälä | 2d9d2b0 | 2014-01-17 11:44:31 +0200 | [diff] [blame] | 3246 | if (pipe_stats[pipe] & 0x8000ffff) |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3247 | I915_WRITE(reg, pipe_stats[pipe]); |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3248 | } |
| 3249 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 3250 | |
| 3251 | I915_WRITE16(IIR, iir & ~flip_mask); |
| 3252 | new_iir = I915_READ16(IIR); /* Flush posted writes */ |
| 3253 | |
Daniel Vetter | d05c617 | 2012-04-26 23:28:09 +0200 | [diff] [blame] | 3254 | i915_update_dri1_breadcrumb(dev); |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3255 | |
| 3256 | if (iir & I915_USER_INTERRUPT) |
| 3257 | notify_ring(dev, &dev_priv->ring[RCS]); |
| 3258 | |
Daniel Vetter | 4356d58 | 2013-10-16 22:55:55 +0200 | [diff] [blame] | 3259 | for_each_pipe(pipe) { |
Ville Syrjälä | 1f1c2e2 | 2013-11-28 17:30:01 +0200 | [diff] [blame] | 3260 | int plane = pipe; |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 3261 | if (HAS_FBC(dev)) |
Ville Syrjälä | 1f1c2e2 | 2013-11-28 17:30:01 +0200 | [diff] [blame] | 3262 | plane = !plane; |
| 3263 | |
Daniel Vetter | 4356d58 | 2013-10-16 22:55:55 +0200 | [diff] [blame] | 3264 | if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS && |
Ville Syrjälä | 1f1c2e2 | 2013-11-28 17:30:01 +0200 | [diff] [blame] | 3265 | i8xx_handle_vblank(dev, plane, pipe, iir)) |
| 3266 | flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane); |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3267 | |
Daniel Vetter | 4356d58 | 2013-10-16 22:55:55 +0200 | [diff] [blame] | 3268 | if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) |
Daniel Vetter | 277de95 | 2013-10-18 16:37:07 +0200 | [diff] [blame] | 3269 | i9xx_pipe_crc_irq_handler(dev, pipe); |
Ville Syrjälä | 2d9d2b0 | 2014-01-17 11:44:31 +0200 | [diff] [blame] | 3270 | |
| 3271 | if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS && |
| 3272 | intel_set_cpu_fifo_underrun_reporting(dev, pipe, false)) |
Ville Syrjälä | fc2c807 | 2014-01-17 11:44:32 +0200 | [diff] [blame] | 3273 | DRM_ERROR("pipe %c underrun\n", pipe_name(pipe)); |
Daniel Vetter | 4356d58 | 2013-10-16 22:55:55 +0200 | [diff] [blame] | 3274 | } |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3275 | |
| 3276 | iir = new_iir; |
| 3277 | } |
| 3278 | |
| 3279 | return IRQ_HANDLED; |
| 3280 | } |
| 3281 | |
| 3282 | static void i8xx_irq_uninstall(struct drm_device * dev) |
| 3283 | { |
| 3284 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 3285 | int pipe; |
| 3286 | |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3287 | for_each_pipe(pipe) { |
| 3288 | /* Clear enable bits; then clear status bits */ |
| 3289 | I915_WRITE(PIPESTAT(pipe), 0); |
| 3290 | I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe))); |
| 3291 | } |
| 3292 | I915_WRITE16(IMR, 0xffff); |
| 3293 | I915_WRITE16(IER, 0x0); |
| 3294 | I915_WRITE16(IIR, I915_READ16(IIR)); |
| 3295 | } |
| 3296 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3297 | static void i915_irq_preinstall(struct drm_device * dev) |
| 3298 | { |
| 3299 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 3300 | int pipe; |
| 3301 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3302 | if (I915_HAS_HOTPLUG(dev)) { |
| 3303 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
| 3304 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); |
| 3305 | } |
| 3306 | |
Chris Wilson | 00d98eb | 2012-04-24 22:59:48 +0100 | [diff] [blame] | 3307 | I915_WRITE16(HWSTAM, 0xeffe); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3308 | for_each_pipe(pipe) |
| 3309 | I915_WRITE(PIPESTAT(pipe), 0); |
| 3310 | I915_WRITE(IMR, 0xffffffff); |
| 3311 | I915_WRITE(IER, 0x0); |
| 3312 | POSTING_READ(IER); |
| 3313 | } |
| 3314 | |
| 3315 | static int i915_irq_postinstall(struct drm_device *dev) |
| 3316 | { |
| 3317 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 3318 | u32 enable_mask; |
Daniel Vetter | 379ef82 | 2013-10-16 22:55:56 +0200 | [diff] [blame] | 3319 | unsigned long irqflags; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3320 | |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 3321 | I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH)); |
| 3322 | |
| 3323 | /* Unmask the interrupts that we always want on. */ |
| 3324 | dev_priv->irq_mask = |
| 3325 | ~(I915_ASLE_INTERRUPT | |
| 3326 | I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | |
| 3327 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | |
| 3328 | I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | |
| 3329 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | |
| 3330 | I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); |
| 3331 | |
| 3332 | enable_mask = |
| 3333 | I915_ASLE_INTERRUPT | |
| 3334 | I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | |
| 3335 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | |
| 3336 | I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT | |
| 3337 | I915_USER_INTERRUPT; |
| 3338 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3339 | if (I915_HAS_HOTPLUG(dev)) { |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 3340 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
| 3341 | POSTING_READ(PORT_HOTPLUG_EN); |
| 3342 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3343 | /* Enable in IER... */ |
| 3344 | enable_mask |= I915_DISPLAY_PORT_INTERRUPT; |
| 3345 | /* and unmask in IMR */ |
| 3346 | dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT; |
| 3347 | } |
| 3348 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3349 | I915_WRITE(IMR, dev_priv->irq_mask); |
| 3350 | I915_WRITE(IER, enable_mask); |
| 3351 | POSTING_READ(IER); |
| 3352 | |
Jani Nikula | f49e38d | 2013-04-29 13:02:54 +0300 | [diff] [blame] | 3353 | i915_enable_asle_pipestat(dev); |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 3354 | |
Daniel Vetter | 379ef82 | 2013-10-16 22:55:56 +0200 | [diff] [blame] | 3355 | /* Interrupt setup is already guaranteed to be single-threaded, this is |
| 3356 | * just to make the assert_spin_locked check happy. */ |
| 3357 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Daniel Vetter | 3b6c42e | 2013-10-21 18:04:35 +0200 | [diff] [blame] | 3358 | i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE); |
| 3359 | i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE); |
Daniel Vetter | 379ef82 | 2013-10-16 22:55:56 +0200 | [diff] [blame] | 3360 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 3361 | |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 3362 | return 0; |
| 3363 | } |
| 3364 | |
Ville Syrjälä | 90a72f8 | 2013-02-19 23:16:44 +0200 | [diff] [blame] | 3365 | /* |
| 3366 | * Returns true when a page flip has completed. |
| 3367 | */ |
| 3368 | static bool i915_handle_vblank(struct drm_device *dev, |
| 3369 | int plane, int pipe, u32 iir) |
| 3370 | { |
| 3371 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 3372 | u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane); |
| 3373 | |
| 3374 | if (!drm_handle_vblank(dev, pipe)) |
| 3375 | return false; |
| 3376 | |
| 3377 | if ((iir & flip_pending) == 0) |
| 3378 | return false; |
| 3379 | |
| 3380 | intel_prepare_page_flip(dev, plane); |
| 3381 | |
| 3382 | /* We detect FlipDone by looking for the change in PendingFlip from '1' |
| 3383 | * to '0' on the following vblank, i.e. IIR has the Pendingflip |
| 3384 | * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence |
| 3385 | * the flip is completed (no longer pending). Since this doesn't raise |
| 3386 | * an interrupt per se, we watch for the change at vblank. |
| 3387 | */ |
| 3388 | if (I915_READ(ISR) & flip_pending) |
| 3389 | return false; |
| 3390 | |
| 3391 | intel_finish_page_flip(dev, pipe); |
| 3392 | |
| 3393 | return true; |
| 3394 | } |
| 3395 | |
Daniel Vetter | ff1f525 | 2012-10-02 15:10:55 +0200 | [diff] [blame] | 3396 | static irqreturn_t i915_irq_handler(int irq, void *arg) |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3397 | { |
| 3398 | struct drm_device *dev = (struct drm_device *) arg; |
| 3399 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Chris Wilson | 8291ee9 | 2012-04-24 22:59:47 +0100 | [diff] [blame] | 3400 | u32 iir, new_iir, pipe_stats[I915_MAX_PIPES]; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3401 | unsigned long irqflags; |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 3402 | u32 flip_mask = |
| 3403 | I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | |
| 3404 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 3405 | int pipe, ret = IRQ_NONE; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3406 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3407 | iir = I915_READ(IIR); |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 3408 | do { |
| 3409 | bool irq_received = (iir & ~flip_mask) != 0; |
Chris Wilson | 8291ee9 | 2012-04-24 22:59:47 +0100 | [diff] [blame] | 3410 | bool blc_event = false; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3411 | |
| 3412 | /* Can't rely on pipestat interrupt bit in iir as it might |
| 3413 | * have been cleared after the pipestat interrupt was received. |
| 3414 | * It doesn't set the bit in iir again, but it still produces |
| 3415 | * interrupts (for non-MSI). |
| 3416 | */ |
| 3417 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
| 3418 | if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) |
| 3419 | i915_handle_error(dev, false); |
| 3420 | |
| 3421 | for_each_pipe(pipe) { |
| 3422 | int reg = PIPESTAT(pipe); |
| 3423 | pipe_stats[pipe] = I915_READ(reg); |
| 3424 | |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 3425 | /* Clear the PIPE*STAT regs before the IIR */ |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3426 | if (pipe_stats[pipe] & 0x8000ffff) { |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3427 | I915_WRITE(reg, pipe_stats[pipe]); |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 3428 | irq_received = true; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3429 | } |
| 3430 | } |
| 3431 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 3432 | |
| 3433 | if (!irq_received) |
| 3434 | break; |
| 3435 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3436 | /* Consume port. Then clear IIR or we'll miss events */ |
| 3437 | if ((I915_HAS_HOTPLUG(dev)) && |
| 3438 | (iir & I915_DISPLAY_PORT_INTERRUPT)) { |
| 3439 | u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); |
Egbert Eich | b543fb0 | 2013-04-16 13:36:54 +0200 | [diff] [blame] | 3440 | u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3441 | |
Daniel Vetter | 91d131d | 2013-06-27 17:52:14 +0200 | [diff] [blame] | 3442 | intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915); |
| 3443 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3444 | I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 3445 | POSTING_READ(PORT_HOTPLUG_STAT); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3446 | } |
| 3447 | |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 3448 | I915_WRITE(IIR, iir & ~flip_mask); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3449 | new_iir = I915_READ(IIR); /* Flush posted writes */ |
| 3450 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3451 | if (iir & I915_USER_INTERRUPT) |
| 3452 | notify_ring(dev, &dev_priv->ring[RCS]); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3453 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3454 | for_each_pipe(pipe) { |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 3455 | int plane = pipe; |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 3456 | if (HAS_FBC(dev)) |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 3457 | plane = !plane; |
Ville Syrjälä | 5e2032d | 2013-02-19 15:16:38 +0200 | [diff] [blame] | 3458 | |
Ville Syrjälä | 90a72f8 | 2013-02-19 23:16:44 +0200 | [diff] [blame] | 3459 | if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS && |
| 3460 | i915_handle_vblank(dev, plane, pipe, iir)) |
| 3461 | flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3462 | |
| 3463 | if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) |
| 3464 | blc_event = true; |
Daniel Vetter | 4356d58 | 2013-10-16 22:55:55 +0200 | [diff] [blame] | 3465 | |
| 3466 | if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) |
Daniel Vetter | 277de95 | 2013-10-18 16:37:07 +0200 | [diff] [blame] | 3467 | i9xx_pipe_crc_irq_handler(dev, pipe); |
Ville Syrjälä | 2d9d2b0 | 2014-01-17 11:44:31 +0200 | [diff] [blame] | 3468 | |
| 3469 | if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS && |
| 3470 | intel_set_cpu_fifo_underrun_reporting(dev, pipe, false)) |
Ville Syrjälä | fc2c807 | 2014-01-17 11:44:32 +0200 | [diff] [blame] | 3471 | DRM_ERROR("pipe %c underrun\n", pipe_name(pipe)); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3472 | } |
| 3473 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3474 | if (blc_event || (iir & I915_ASLE_INTERRUPT)) |
| 3475 | intel_opregion_asle_intr(dev); |
| 3476 | |
| 3477 | /* With MSI, interrupts are only generated when iir |
| 3478 | * transitions from zero to nonzero. If another bit got |
| 3479 | * set while we were handling the existing iir bits, then |
| 3480 | * we would never get another interrupt. |
| 3481 | * |
| 3482 | * This is fine on non-MSI as well, as if we hit this path |
| 3483 | * we avoid exiting the interrupt handler only to generate |
| 3484 | * another one. |
| 3485 | * |
| 3486 | * Note that for MSI this could cause a stray interrupt report |
| 3487 | * if an interrupt landed in the time between writing IIR and |
| 3488 | * the posting read. This should be rare enough to never |
| 3489 | * trigger the 99% of 100,000 interrupts test for disabling |
| 3490 | * stray interrupts. |
| 3491 | */ |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 3492 | ret = IRQ_HANDLED; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3493 | iir = new_iir; |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 3494 | } while (iir & ~flip_mask); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3495 | |
Daniel Vetter | d05c617 | 2012-04-26 23:28:09 +0200 | [diff] [blame] | 3496 | i915_update_dri1_breadcrumb(dev); |
Chris Wilson | 8291ee9 | 2012-04-24 22:59:47 +0100 | [diff] [blame] | 3497 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3498 | return ret; |
| 3499 | } |
| 3500 | |
| 3501 | static void i915_irq_uninstall(struct drm_device * dev) |
| 3502 | { |
| 3503 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 3504 | int pipe; |
| 3505 | |
Ville Syrjälä | 3ca1cce | 2014-01-17 13:43:51 +0200 | [diff] [blame] | 3506 | intel_hpd_irq_uninstall(dev_priv); |
Egbert Eich | ac4c16c | 2013-04-16 13:36:58 +0200 | [diff] [blame] | 3507 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3508 | if (I915_HAS_HOTPLUG(dev)) { |
| 3509 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
| 3510 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); |
| 3511 | } |
| 3512 | |
Chris Wilson | 00d98eb | 2012-04-24 22:59:48 +0100 | [diff] [blame] | 3513 | I915_WRITE16(HWSTAM, 0xffff); |
Chris Wilson | 55b3975 | 2012-04-24 22:59:49 +0100 | [diff] [blame] | 3514 | for_each_pipe(pipe) { |
| 3515 | /* Clear enable bits; then clear status bits */ |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3516 | I915_WRITE(PIPESTAT(pipe), 0); |
Chris Wilson | 55b3975 | 2012-04-24 22:59:49 +0100 | [diff] [blame] | 3517 | I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe))); |
| 3518 | } |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3519 | I915_WRITE(IMR, 0xffffffff); |
| 3520 | I915_WRITE(IER, 0x0); |
| 3521 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3522 | I915_WRITE(IIR, I915_READ(IIR)); |
| 3523 | } |
| 3524 | |
| 3525 | static void i965_irq_preinstall(struct drm_device * dev) |
| 3526 | { |
| 3527 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 3528 | int pipe; |
| 3529 | |
Chris Wilson | adca473 | 2012-05-11 18:01:31 +0100 | [diff] [blame] | 3530 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
| 3531 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3532 | |
| 3533 | I915_WRITE(HWSTAM, 0xeffe); |
| 3534 | for_each_pipe(pipe) |
| 3535 | I915_WRITE(PIPESTAT(pipe), 0); |
| 3536 | I915_WRITE(IMR, 0xffffffff); |
| 3537 | I915_WRITE(IER, 0x0); |
| 3538 | POSTING_READ(IER); |
| 3539 | } |
| 3540 | |
| 3541 | static int i965_irq_postinstall(struct drm_device *dev) |
| 3542 | { |
| 3543 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Chris Wilson | bbba0a9 | 2012-04-24 22:59:51 +0100 | [diff] [blame] | 3544 | u32 enable_mask; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3545 | u32 error_mask; |
Daniel Vetter | b79480b | 2013-06-27 17:52:10 +0200 | [diff] [blame] | 3546 | unsigned long irqflags; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3547 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3548 | /* Unmask the interrupts that we always want on. */ |
Chris Wilson | bbba0a9 | 2012-04-24 22:59:51 +0100 | [diff] [blame] | 3549 | dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT | |
Chris Wilson | adca473 | 2012-05-11 18:01:31 +0100 | [diff] [blame] | 3550 | I915_DISPLAY_PORT_INTERRUPT | |
Chris Wilson | bbba0a9 | 2012-04-24 22:59:51 +0100 | [diff] [blame] | 3551 | I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | |
| 3552 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | |
| 3553 | I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | |
| 3554 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | |
| 3555 | I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); |
| 3556 | |
| 3557 | enable_mask = ~dev_priv->irq_mask; |
Ville Syrjälä | 21ad833 | 2013-02-19 15:16:39 +0200 | [diff] [blame] | 3558 | enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | |
| 3559 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT); |
Chris Wilson | bbba0a9 | 2012-04-24 22:59:51 +0100 | [diff] [blame] | 3560 | enable_mask |= I915_USER_INTERRUPT; |
| 3561 | |
| 3562 | if (IS_G4X(dev)) |
| 3563 | enable_mask |= I915_BSD_USER_INTERRUPT; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3564 | |
Daniel Vetter | b79480b | 2013-06-27 17:52:10 +0200 | [diff] [blame] | 3565 | /* Interrupt setup is already guaranteed to be single-threaded, this is |
| 3566 | * just to make the assert_spin_locked check happy. */ |
| 3567 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Daniel Vetter | 3b6c42e | 2013-10-21 18:04:35 +0200 | [diff] [blame] | 3568 | i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_EVENT_ENABLE); |
| 3569 | i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE); |
| 3570 | i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE); |
Daniel Vetter | b79480b | 2013-06-27 17:52:10 +0200 | [diff] [blame] | 3571 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3572 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3573 | /* |
| 3574 | * Enable some error detection, note the instruction error mask |
| 3575 | * bit is reserved, so we leave it masked. |
| 3576 | */ |
| 3577 | if (IS_G4X(dev)) { |
| 3578 | error_mask = ~(GM45_ERROR_PAGE_TABLE | |
| 3579 | GM45_ERROR_MEM_PRIV | |
| 3580 | GM45_ERROR_CP_PRIV | |
| 3581 | I915_ERROR_MEMORY_REFRESH); |
| 3582 | } else { |
| 3583 | error_mask = ~(I915_ERROR_PAGE_TABLE | |
| 3584 | I915_ERROR_MEMORY_REFRESH); |
| 3585 | } |
| 3586 | I915_WRITE(EMR, error_mask); |
| 3587 | |
| 3588 | I915_WRITE(IMR, dev_priv->irq_mask); |
| 3589 | I915_WRITE(IER, enable_mask); |
| 3590 | POSTING_READ(IER); |
| 3591 | |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 3592 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
| 3593 | POSTING_READ(PORT_HOTPLUG_EN); |
| 3594 | |
Jani Nikula | f49e38d | 2013-04-29 13:02:54 +0300 | [diff] [blame] | 3595 | i915_enable_asle_pipestat(dev); |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 3596 | |
| 3597 | return 0; |
| 3598 | } |
| 3599 | |
Egbert Eich | bac56d5 | 2013-02-25 12:06:51 -0500 | [diff] [blame] | 3600 | static void i915_hpd_irq_setup(struct drm_device *dev) |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 3601 | { |
| 3602 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Egbert Eich | e5868a3 | 2013-02-28 04:17:12 -0500 | [diff] [blame] | 3603 | struct drm_mode_config *mode_config = &dev->mode_config; |
Egbert Eich | cd569ae | 2013-04-16 13:36:57 +0200 | [diff] [blame] | 3604 | struct intel_encoder *intel_encoder; |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 3605 | u32 hotplug_en; |
| 3606 | |
Daniel Vetter | b5ea2d5 | 2013-06-27 17:52:15 +0200 | [diff] [blame] | 3607 | assert_spin_locked(&dev_priv->irq_lock); |
| 3608 | |
Egbert Eich | bac56d5 | 2013-02-25 12:06:51 -0500 | [diff] [blame] | 3609 | if (I915_HAS_HOTPLUG(dev)) { |
| 3610 | hotplug_en = I915_READ(PORT_HOTPLUG_EN); |
| 3611 | hotplug_en &= ~HOTPLUG_INT_EN_MASK; |
| 3612 | /* Note HDMI and DP share hotplug bits */ |
Egbert Eich | e5868a3 | 2013-02-28 04:17:12 -0500 | [diff] [blame] | 3613 | /* enable bits are the same for all generations */ |
Egbert Eich | cd569ae | 2013-04-16 13:36:57 +0200 | [diff] [blame] | 3614 | list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head) |
| 3615 | if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) |
| 3616 | hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin]; |
Egbert Eich | bac56d5 | 2013-02-25 12:06:51 -0500 | [diff] [blame] | 3617 | /* Programming the CRT detection parameters tends |
| 3618 | to generate a spurious hotplug event about three |
| 3619 | seconds later. So just do it once. |
| 3620 | */ |
| 3621 | if (IS_G4X(dev)) |
| 3622 | hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64; |
Daniel Vetter | 85fc95b | 2013-03-27 15:47:11 +0100 | [diff] [blame] | 3623 | hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK; |
Egbert Eich | bac56d5 | 2013-02-25 12:06:51 -0500 | [diff] [blame] | 3624 | hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3625 | |
Egbert Eich | bac56d5 | 2013-02-25 12:06:51 -0500 | [diff] [blame] | 3626 | /* Ignore TV since it's buggy */ |
| 3627 | I915_WRITE(PORT_HOTPLUG_EN, hotplug_en); |
| 3628 | } |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3629 | } |
| 3630 | |
Daniel Vetter | ff1f525 | 2012-10-02 15:10:55 +0200 | [diff] [blame] | 3631 | static irqreturn_t i965_irq_handler(int irq, void *arg) |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3632 | { |
| 3633 | struct drm_device *dev = (struct drm_device *) arg; |
| 3634 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3635 | u32 iir, new_iir; |
| 3636 | u32 pipe_stats[I915_MAX_PIPES]; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3637 | unsigned long irqflags; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3638 | int ret = IRQ_NONE, pipe; |
Ville Syrjälä | 21ad833 | 2013-02-19 15:16:39 +0200 | [diff] [blame] | 3639 | u32 flip_mask = |
| 3640 | I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | |
| 3641 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3642 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3643 | iir = I915_READ(IIR); |
| 3644 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3645 | for (;;) { |
Ville Syrjälä | 501e01d | 2014-01-17 11:35:15 +0200 | [diff] [blame] | 3646 | bool irq_received = (iir & ~flip_mask) != 0; |
Chris Wilson | 2c8ba29 | 2012-04-24 22:59:46 +0100 | [diff] [blame] | 3647 | bool blc_event = false; |
| 3648 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3649 | /* Can't rely on pipestat interrupt bit in iir as it might |
| 3650 | * have been cleared after the pipestat interrupt was received. |
| 3651 | * It doesn't set the bit in iir again, but it still produces |
| 3652 | * interrupts (for non-MSI). |
| 3653 | */ |
| 3654 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
| 3655 | if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) |
| 3656 | i915_handle_error(dev, false); |
| 3657 | |
| 3658 | for_each_pipe(pipe) { |
| 3659 | int reg = PIPESTAT(pipe); |
| 3660 | pipe_stats[pipe] = I915_READ(reg); |
| 3661 | |
| 3662 | /* |
| 3663 | * Clear the PIPE*STAT regs before the IIR |
| 3664 | */ |
| 3665 | if (pipe_stats[pipe] & 0x8000ffff) { |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3666 | I915_WRITE(reg, pipe_stats[pipe]); |
Ville Syrjälä | 501e01d | 2014-01-17 11:35:15 +0200 | [diff] [blame] | 3667 | irq_received = true; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3668 | } |
| 3669 | } |
| 3670 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 3671 | |
| 3672 | if (!irq_received) |
| 3673 | break; |
| 3674 | |
| 3675 | ret = IRQ_HANDLED; |
| 3676 | |
| 3677 | /* Consume port. Then clear IIR or we'll miss events */ |
Chris Wilson | adca473 | 2012-05-11 18:01:31 +0100 | [diff] [blame] | 3678 | if (iir & I915_DISPLAY_PORT_INTERRUPT) { |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3679 | u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); |
Egbert Eich | b543fb0 | 2013-04-16 13:36:54 +0200 | [diff] [blame] | 3680 | u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ? |
| 3681 | HOTPLUG_INT_STATUS_G4X : |
Daniel Vetter | 4f7fd70 | 2013-06-24 21:33:28 +0200 | [diff] [blame] | 3682 | HOTPLUG_INT_STATUS_I915); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3683 | |
Daniel Vetter | 91d131d | 2013-06-27 17:52:14 +0200 | [diff] [blame] | 3684 | intel_hpd_irq_handler(dev, hotplug_trigger, |
Daniel Vetter | 704cfb8 | 2013-12-18 09:08:43 +0100 | [diff] [blame] | 3685 | IS_G4X(dev) ? hpd_status_g4x : hpd_status_i915); |
Daniel Vetter | 91d131d | 2013-06-27 17:52:14 +0200 | [diff] [blame] | 3686 | |
Daniel Vetter | 4aeebd7 | 2013-10-31 09:53:36 +0100 | [diff] [blame] | 3687 | if (IS_G4X(dev) && |
| 3688 | (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)) |
| 3689 | dp_aux_irq_handler(dev); |
| 3690 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3691 | I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); |
| 3692 | I915_READ(PORT_HOTPLUG_STAT); |
| 3693 | } |
| 3694 | |
Ville Syrjälä | 21ad833 | 2013-02-19 15:16:39 +0200 | [diff] [blame] | 3695 | I915_WRITE(IIR, iir & ~flip_mask); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3696 | new_iir = I915_READ(IIR); /* Flush posted writes */ |
| 3697 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3698 | if (iir & I915_USER_INTERRUPT) |
| 3699 | notify_ring(dev, &dev_priv->ring[RCS]); |
| 3700 | if (iir & I915_BSD_USER_INTERRUPT) |
| 3701 | notify_ring(dev, &dev_priv->ring[VCS]); |
| 3702 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3703 | for_each_pipe(pipe) { |
Chris Wilson | 2c8ba29 | 2012-04-24 22:59:46 +0100 | [diff] [blame] | 3704 | if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS && |
Ville Syrjälä | 90a72f8 | 2013-02-19 23:16:44 +0200 | [diff] [blame] | 3705 | i915_handle_vblank(dev, pipe, pipe, iir)) |
| 3706 | flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3707 | |
| 3708 | if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) |
| 3709 | blc_event = true; |
Daniel Vetter | 4356d58 | 2013-10-16 22:55:55 +0200 | [diff] [blame] | 3710 | |
| 3711 | if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) |
Daniel Vetter | 277de95 | 2013-10-18 16:37:07 +0200 | [diff] [blame] | 3712 | i9xx_pipe_crc_irq_handler(dev, pipe); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3713 | |
Ville Syrjälä | 2d9d2b0 | 2014-01-17 11:44:31 +0200 | [diff] [blame] | 3714 | if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS && |
| 3715 | intel_set_cpu_fifo_underrun_reporting(dev, pipe, false)) |
Ville Syrjälä | fc2c807 | 2014-01-17 11:44:32 +0200 | [diff] [blame] | 3716 | DRM_ERROR("pipe %c underrun\n", pipe_name(pipe)); |
Ville Syrjälä | 2d9d2b0 | 2014-01-17 11:44:31 +0200 | [diff] [blame] | 3717 | } |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3718 | |
| 3719 | if (blc_event || (iir & I915_ASLE_INTERRUPT)) |
| 3720 | intel_opregion_asle_intr(dev); |
| 3721 | |
Daniel Vetter | 515ac2b | 2012-12-01 13:53:44 +0100 | [diff] [blame] | 3722 | if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) |
| 3723 | gmbus_irq_handler(dev); |
| 3724 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3725 | /* With MSI, interrupts are only generated when iir |
| 3726 | * transitions from zero to nonzero. If another bit got |
| 3727 | * set while we were handling the existing iir bits, then |
| 3728 | * we would never get another interrupt. |
| 3729 | * |
| 3730 | * This is fine on non-MSI as well, as if we hit this path |
| 3731 | * we avoid exiting the interrupt handler only to generate |
| 3732 | * another one. |
| 3733 | * |
| 3734 | * Note that for MSI this could cause a stray interrupt report |
| 3735 | * if an interrupt landed in the time between writing IIR and |
| 3736 | * the posting read. This should be rare enough to never |
| 3737 | * trigger the 99% of 100,000 interrupts test for disabling |
| 3738 | * stray interrupts. |
| 3739 | */ |
| 3740 | iir = new_iir; |
| 3741 | } |
| 3742 | |
Daniel Vetter | d05c617 | 2012-04-26 23:28:09 +0200 | [diff] [blame] | 3743 | i915_update_dri1_breadcrumb(dev); |
Chris Wilson | 2c8ba29 | 2012-04-24 22:59:46 +0100 | [diff] [blame] | 3744 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3745 | return ret; |
| 3746 | } |
| 3747 | |
| 3748 | static void i965_irq_uninstall(struct drm_device * dev) |
| 3749 | { |
| 3750 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 3751 | int pipe; |
| 3752 | |
| 3753 | if (!dev_priv) |
| 3754 | return; |
| 3755 | |
Ville Syrjälä | 3ca1cce | 2014-01-17 13:43:51 +0200 | [diff] [blame] | 3756 | intel_hpd_irq_uninstall(dev_priv); |
Egbert Eich | ac4c16c | 2013-04-16 13:36:58 +0200 | [diff] [blame] | 3757 | |
Chris Wilson | adca473 | 2012-05-11 18:01:31 +0100 | [diff] [blame] | 3758 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
| 3759 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3760 | |
| 3761 | I915_WRITE(HWSTAM, 0xffffffff); |
| 3762 | for_each_pipe(pipe) |
| 3763 | I915_WRITE(PIPESTAT(pipe), 0); |
| 3764 | I915_WRITE(IMR, 0xffffffff); |
| 3765 | I915_WRITE(IER, 0x0); |
| 3766 | |
| 3767 | for_each_pipe(pipe) |
| 3768 | I915_WRITE(PIPESTAT(pipe), |
| 3769 | I915_READ(PIPESTAT(pipe)) & 0x8000ffff); |
| 3770 | I915_WRITE(IIR, I915_READ(IIR)); |
| 3771 | } |
| 3772 | |
Ville Syrjälä | 3ca1cce | 2014-01-17 13:43:51 +0200 | [diff] [blame] | 3773 | static void intel_hpd_irq_reenable(unsigned long data) |
Egbert Eich | ac4c16c | 2013-04-16 13:36:58 +0200 | [diff] [blame] | 3774 | { |
| 3775 | drm_i915_private_t *dev_priv = (drm_i915_private_t *)data; |
| 3776 | struct drm_device *dev = dev_priv->dev; |
| 3777 | struct drm_mode_config *mode_config = &dev->mode_config; |
| 3778 | unsigned long irqflags; |
| 3779 | int i; |
| 3780 | |
| 3781 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
| 3782 | for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) { |
| 3783 | struct drm_connector *connector; |
| 3784 | |
| 3785 | if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED) |
| 3786 | continue; |
| 3787 | |
| 3788 | dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED; |
| 3789 | |
| 3790 | list_for_each_entry(connector, &mode_config->connector_list, head) { |
| 3791 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 3792 | |
| 3793 | if (intel_connector->encoder->hpd_pin == i) { |
| 3794 | if (connector->polled != intel_connector->polled) |
| 3795 | DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n", |
| 3796 | drm_get_connector_name(connector)); |
| 3797 | connector->polled = intel_connector->polled; |
| 3798 | if (!connector->polled) |
| 3799 | connector->polled = DRM_CONNECTOR_POLL_HPD; |
| 3800 | } |
| 3801 | } |
| 3802 | } |
| 3803 | if (dev_priv->display.hpd_irq_setup) |
| 3804 | dev_priv->display.hpd_irq_setup(dev); |
| 3805 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 3806 | } |
| 3807 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 3808 | void intel_irq_init(struct drm_device *dev) |
| 3809 | { |
Chris Wilson | 8b2e326 | 2012-04-24 22:59:41 +0100 | [diff] [blame] | 3810 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3811 | |
| 3812 | INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func); |
Daniel Vetter | 99584db | 2012-11-14 17:14:04 +0100 | [diff] [blame] | 3813 | INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func); |
Daniel Vetter | c6a828d | 2012-08-08 23:35:35 +0200 | [diff] [blame] | 3814 | INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work); |
Daniel Vetter | a4da4fa | 2012-11-02 19:55:07 +0100 | [diff] [blame] | 3815 | INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work); |
Chris Wilson | 8b2e326 | 2012-04-24 22:59:41 +0100 | [diff] [blame] | 3816 | |
Daniel Vetter | 99584db | 2012-11-14 17:14:04 +0100 | [diff] [blame] | 3817 | setup_timer(&dev_priv->gpu_error.hangcheck_timer, |
| 3818 | i915_hangcheck_elapsed, |
Daniel Vetter | 61bac78 | 2012-12-01 21:03:21 +0100 | [diff] [blame] | 3819 | (unsigned long) dev); |
Ville Syrjälä | 3ca1cce | 2014-01-17 13:43:51 +0200 | [diff] [blame] | 3820 | setup_timer(&dev_priv->hotplug_reenable_timer, intel_hpd_irq_reenable, |
Egbert Eich | ac4c16c | 2013-04-16 13:36:58 +0200 | [diff] [blame] | 3821 | (unsigned long) dev_priv); |
Daniel Vetter | 61bac78 | 2012-12-01 21:03:21 +0100 | [diff] [blame] | 3822 | |
Tomas Janousek | 97a19a2 | 2012-12-08 13:48:13 +0100 | [diff] [blame] | 3823 | pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE); |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 3824 | |
Ville Syrjälä | 4cdb83e | 2013-10-11 21:52:44 +0300 | [diff] [blame] | 3825 | if (IS_GEN2(dev)) { |
| 3826 | dev->max_vblank_count = 0; |
| 3827 | dev->driver->get_vblank_counter = i8xx_get_vblank_counter; |
| 3828 | } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 3829 | dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */ |
| 3830 | dev->driver->get_vblank_counter = gm45_get_vblank_counter; |
Ville Syrjälä | 391f75e | 2013-09-25 19:55:26 +0300 | [diff] [blame] | 3831 | } else { |
| 3832 | dev->driver->get_vblank_counter = i915_get_vblank_counter; |
| 3833 | dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 3834 | } |
| 3835 | |
Ville Syrjälä | c2baf4b | 2013-09-23 14:48:50 +0300 | [diff] [blame] | 3836 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
Keith Packard | c3613de | 2011-08-12 17:05:54 -0700 | [diff] [blame] | 3837 | dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp; |
Ville Syrjälä | c2baf4b | 2013-09-23 14:48:50 +0300 | [diff] [blame] | 3838 | dev->driver->get_scanout_position = i915_get_crtc_scanoutpos; |
| 3839 | } |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 3840 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 3841 | if (IS_VALLEYVIEW(dev)) { |
| 3842 | dev->driver->irq_handler = valleyview_irq_handler; |
| 3843 | dev->driver->irq_preinstall = valleyview_irq_preinstall; |
| 3844 | dev->driver->irq_postinstall = valleyview_irq_postinstall; |
| 3845 | dev->driver->irq_uninstall = valleyview_irq_uninstall; |
| 3846 | dev->driver->enable_vblank = valleyview_enable_vblank; |
| 3847 | dev->driver->disable_vblank = valleyview_disable_vblank; |
Egbert Eich | fa00abe | 2013-02-25 12:06:48 -0500 | [diff] [blame] | 3848 | dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3849 | } else if (IS_GEN8(dev)) { |
| 3850 | dev->driver->irq_handler = gen8_irq_handler; |
| 3851 | dev->driver->irq_preinstall = gen8_irq_preinstall; |
| 3852 | dev->driver->irq_postinstall = gen8_irq_postinstall; |
| 3853 | dev->driver->irq_uninstall = gen8_irq_uninstall; |
| 3854 | dev->driver->enable_vblank = gen8_enable_vblank; |
| 3855 | dev->driver->disable_vblank = gen8_disable_vblank; |
| 3856 | dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup; |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 3857 | } else if (HAS_PCH_SPLIT(dev)) { |
| 3858 | dev->driver->irq_handler = ironlake_irq_handler; |
| 3859 | dev->driver->irq_preinstall = ironlake_irq_preinstall; |
| 3860 | dev->driver->irq_postinstall = ironlake_irq_postinstall; |
| 3861 | dev->driver->irq_uninstall = ironlake_irq_uninstall; |
| 3862 | dev->driver->enable_vblank = ironlake_enable_vblank; |
| 3863 | dev->driver->disable_vblank = ironlake_disable_vblank; |
Daniel Vetter | 82a28bc | 2013-03-27 15:55:01 +0100 | [diff] [blame] | 3864 | dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup; |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 3865 | } else { |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3866 | if (INTEL_INFO(dev)->gen == 2) { |
| 3867 | dev->driver->irq_preinstall = i8xx_irq_preinstall; |
| 3868 | dev->driver->irq_postinstall = i8xx_irq_postinstall; |
| 3869 | dev->driver->irq_handler = i8xx_irq_handler; |
| 3870 | dev->driver->irq_uninstall = i8xx_irq_uninstall; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3871 | } else if (INTEL_INFO(dev)->gen == 3) { |
| 3872 | dev->driver->irq_preinstall = i915_irq_preinstall; |
| 3873 | dev->driver->irq_postinstall = i915_irq_postinstall; |
| 3874 | dev->driver->irq_uninstall = i915_irq_uninstall; |
| 3875 | dev->driver->irq_handler = i915_irq_handler; |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 3876 | dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3877 | } else { |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 3878 | dev->driver->irq_preinstall = i965_irq_preinstall; |
| 3879 | dev->driver->irq_postinstall = i965_irq_postinstall; |
| 3880 | dev->driver->irq_uninstall = i965_irq_uninstall; |
| 3881 | dev->driver->irq_handler = i965_irq_handler; |
Egbert Eich | bac56d5 | 2013-02-25 12:06:51 -0500 | [diff] [blame] | 3882 | dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3883 | } |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 3884 | dev->driver->enable_vblank = i915_enable_vblank; |
| 3885 | dev->driver->disable_vblank = i915_disable_vblank; |
| 3886 | } |
| 3887 | } |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 3888 | |
| 3889 | void intel_hpd_init(struct drm_device *dev) |
| 3890 | { |
| 3891 | struct drm_i915_private *dev_priv = dev->dev_private; |
Egbert Eich | 821450c | 2013-04-16 13:36:55 +0200 | [diff] [blame] | 3892 | struct drm_mode_config *mode_config = &dev->mode_config; |
| 3893 | struct drm_connector *connector; |
Daniel Vetter | b5ea2d5 | 2013-06-27 17:52:15 +0200 | [diff] [blame] | 3894 | unsigned long irqflags; |
Egbert Eich | 821450c | 2013-04-16 13:36:55 +0200 | [diff] [blame] | 3895 | int i; |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 3896 | |
Egbert Eich | 821450c | 2013-04-16 13:36:55 +0200 | [diff] [blame] | 3897 | for (i = 1; i < HPD_NUM_PINS; i++) { |
| 3898 | dev_priv->hpd_stats[i].hpd_cnt = 0; |
| 3899 | dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED; |
| 3900 | } |
| 3901 | list_for_each_entry(connector, &mode_config->connector_list, head) { |
| 3902 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 3903 | connector->polled = intel_connector->polled; |
| 3904 | if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE) |
| 3905 | connector->polled = DRM_CONNECTOR_POLL_HPD; |
| 3906 | } |
Daniel Vetter | b5ea2d5 | 2013-06-27 17:52:15 +0200 | [diff] [blame] | 3907 | |
| 3908 | /* Interrupt setup is already guaranteed to be single-threaded, this is |
| 3909 | * just to make the assert_spin_locked checks happy. */ |
| 3910 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 3911 | if (dev_priv->display.hpd_irq_setup) |
| 3912 | dev_priv->display.hpd_irq_setup(dev); |
Daniel Vetter | b5ea2d5 | 2013-06-27 17:52:15 +0200 | [diff] [blame] | 3913 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 3914 | } |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 3915 | |
| 3916 | /* Disable interrupts so we can allow Package C8+. */ |
| 3917 | void hsw_pc8_disable_interrupts(struct drm_device *dev) |
| 3918 | { |
| 3919 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3920 | unsigned long irqflags; |
| 3921 | |
| 3922 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
| 3923 | |
| 3924 | dev_priv->pc8.regsave.deimr = I915_READ(DEIMR); |
| 3925 | dev_priv->pc8.regsave.sdeimr = I915_READ(SDEIMR); |
| 3926 | dev_priv->pc8.regsave.gtimr = I915_READ(GTIMR); |
| 3927 | dev_priv->pc8.regsave.gtier = I915_READ(GTIER); |
| 3928 | dev_priv->pc8.regsave.gen6_pmimr = I915_READ(GEN6_PMIMR); |
| 3929 | |
Paulo Zanoni | 1f2d453 | 2013-11-21 13:47:25 -0200 | [diff] [blame] | 3930 | ironlake_disable_display_irq(dev_priv, 0xffffffff); |
| 3931 | ibx_disable_display_interrupt(dev_priv, 0xffffffff); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 3932 | ilk_disable_gt_irq(dev_priv, 0xffffffff); |
| 3933 | snb_disable_pm_irq(dev_priv, 0xffffffff); |
| 3934 | |
| 3935 | dev_priv->pc8.irqs_disabled = true; |
| 3936 | |
| 3937 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 3938 | } |
| 3939 | |
| 3940 | /* Restore interrupts so we can recover from Package C8+. */ |
| 3941 | void hsw_pc8_restore_interrupts(struct drm_device *dev) |
| 3942 | { |
| 3943 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3944 | unsigned long irqflags; |
Paulo Zanoni | 1f2d453 | 2013-11-21 13:47:25 -0200 | [diff] [blame] | 3945 | uint32_t val; |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 3946 | |
| 3947 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
| 3948 | |
| 3949 | val = I915_READ(DEIMR); |
Paulo Zanoni | 1f2d453 | 2013-11-21 13:47:25 -0200 | [diff] [blame] | 3950 | WARN(val != 0xffffffff, "DEIMR is 0x%08x\n", val); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 3951 | |
Paulo Zanoni | 1f2d453 | 2013-11-21 13:47:25 -0200 | [diff] [blame] | 3952 | val = I915_READ(SDEIMR); |
| 3953 | WARN(val != 0xffffffff, "SDEIMR is 0x%08x\n", val); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 3954 | |
| 3955 | val = I915_READ(GTIMR); |
Paulo Zanoni | 1f2d453 | 2013-11-21 13:47:25 -0200 | [diff] [blame] | 3956 | WARN(val != 0xffffffff, "GTIMR is 0x%08x\n", val); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 3957 | |
| 3958 | val = I915_READ(GEN6_PMIMR); |
Paulo Zanoni | 1f2d453 | 2013-11-21 13:47:25 -0200 | [diff] [blame] | 3959 | WARN(val != 0xffffffff, "GEN6_PMIMR is 0x%08x\n", val); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 3960 | |
| 3961 | dev_priv->pc8.irqs_disabled = false; |
| 3962 | |
| 3963 | ironlake_enable_display_irq(dev_priv, ~dev_priv->pc8.regsave.deimr); |
Paulo Zanoni | 1f2d453 | 2013-11-21 13:47:25 -0200 | [diff] [blame] | 3964 | ibx_enable_display_interrupt(dev_priv, ~dev_priv->pc8.regsave.sdeimr); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 3965 | ilk_enable_gt_irq(dev_priv, ~dev_priv->pc8.regsave.gtimr); |
| 3966 | snb_enable_pm_irq(dev_priv, ~dev_priv->pc8.regsave.gen6_pmimr); |
| 3967 | I915_WRITE(GTIER, dev_priv->pc8.regsave.gtier); |
| 3968 | |
| 3969 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 3970 | } |