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