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