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