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