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