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