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