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 | |
Ville Syrjälä | e4ce95a | 2015-08-27 23:56:03 +0300 | [diff] [blame] | 48 | static const u32 hpd_ilk[HPD_NUM_PINS] = { |
| 49 | [HPD_PORT_A] = DE_DP_A_HOTPLUG, |
| 50 | }; |
| 51 | |
Ville Syrjälä | 23bb4cb | 2015-08-27 23:56:04 +0300 | [diff] [blame] | 52 | static const u32 hpd_ivb[HPD_NUM_PINS] = { |
| 53 | [HPD_PORT_A] = DE_DP_A_HOTPLUG_IVB, |
| 54 | }; |
| 55 | |
Ville Syrjälä | 3a3b3c7 | 2015-08-27 23:56:06 +0300 | [diff] [blame] | 56 | static const u32 hpd_bdw[HPD_NUM_PINS] = { |
| 57 | [HPD_PORT_A] = GEN8_PORT_DP_A_HOTPLUG, |
| 58 | }; |
| 59 | |
Ville Syrjälä | 7c7e10d | 2015-01-09 14:21:12 +0200 | [diff] [blame] | 60 | static const u32 hpd_ibx[HPD_NUM_PINS] = { |
Egbert Eich | e5868a3 | 2013-02-28 04:17:12 -0500 | [diff] [blame] | 61 | [HPD_CRT] = SDE_CRT_HOTPLUG, |
| 62 | [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG, |
| 63 | [HPD_PORT_B] = SDE_PORTB_HOTPLUG, |
| 64 | [HPD_PORT_C] = SDE_PORTC_HOTPLUG, |
| 65 | [HPD_PORT_D] = SDE_PORTD_HOTPLUG |
| 66 | }; |
| 67 | |
Ville Syrjälä | 7c7e10d | 2015-01-09 14:21:12 +0200 | [diff] [blame] | 68 | static const u32 hpd_cpt[HPD_NUM_PINS] = { |
Egbert Eich | e5868a3 | 2013-02-28 04:17:12 -0500 | [diff] [blame] | 69 | [HPD_CRT] = SDE_CRT_HOTPLUG_CPT, |
Daniel Vetter | 73c352a | 2013-03-26 22:38:43 +0100 | [diff] [blame] | 70 | [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT, |
Egbert Eich | e5868a3 | 2013-02-28 04:17:12 -0500 | [diff] [blame] | 71 | [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT, |
| 72 | [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT, |
| 73 | [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT |
| 74 | }; |
| 75 | |
Xiong Zhang | 26951ca | 2015-08-17 15:55:50 +0800 | [diff] [blame] | 76 | static const u32 hpd_spt[HPD_NUM_PINS] = { |
Ville Syrjälä | 74c0b39 | 2015-08-27 23:56:07 +0300 | [diff] [blame] | 77 | [HPD_PORT_A] = SDE_PORTA_HOTPLUG_SPT, |
Xiong Zhang | 26951ca | 2015-08-17 15:55:50 +0800 | [diff] [blame] | 78 | [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT, |
| 79 | [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT, |
| 80 | [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT, |
| 81 | [HPD_PORT_E] = SDE_PORTE_HOTPLUG_SPT |
| 82 | }; |
| 83 | |
Ville Syrjälä | 7c7e10d | 2015-01-09 14:21:12 +0200 | [diff] [blame] | 84 | static const u32 hpd_mask_i915[HPD_NUM_PINS] = { |
Egbert Eich | e5868a3 | 2013-02-28 04:17:12 -0500 | [diff] [blame] | 85 | [HPD_CRT] = CRT_HOTPLUG_INT_EN, |
| 86 | [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN, |
| 87 | [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN, |
| 88 | [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN, |
| 89 | [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN, |
| 90 | [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN |
| 91 | }; |
| 92 | |
Ville Syrjälä | 7c7e10d | 2015-01-09 14:21:12 +0200 | [diff] [blame] | 93 | static const u32 hpd_status_g4x[HPD_NUM_PINS] = { |
Egbert Eich | e5868a3 | 2013-02-28 04:17:12 -0500 | [diff] [blame] | 94 | [HPD_CRT] = CRT_HOTPLUG_INT_STATUS, |
| 95 | [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X, |
| 96 | [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X, |
| 97 | [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS, |
| 98 | [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS, |
| 99 | [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS |
| 100 | }; |
| 101 | |
Ville Syrjälä | 4bca26d | 2015-05-11 20:49:10 +0300 | [diff] [blame] | 102 | static const u32 hpd_status_i915[HPD_NUM_PINS] = { |
Egbert Eich | e5868a3 | 2013-02-28 04:17:12 -0500 | [diff] [blame] | 103 | [HPD_CRT] = CRT_HOTPLUG_INT_STATUS, |
| 104 | [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915, |
| 105 | [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915, |
| 106 | [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS, |
| 107 | [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS, |
| 108 | [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS |
| 109 | }; |
| 110 | |
Shashank Sharma | e0a20ad | 2015-03-27 14:54:14 +0200 | [diff] [blame] | 111 | /* BXT hpd list */ |
| 112 | static const u32 hpd_bxt[HPD_NUM_PINS] = { |
Sonika Jindal | 7f3561b | 2015-08-10 10:35:35 +0530 | [diff] [blame] | 113 | [HPD_PORT_A] = BXT_DE_PORT_HP_DDIA, |
Shashank Sharma | e0a20ad | 2015-03-27 14:54:14 +0200 | [diff] [blame] | 114 | [HPD_PORT_B] = BXT_DE_PORT_HP_DDIB, |
| 115 | [HPD_PORT_C] = BXT_DE_PORT_HP_DDIC |
| 116 | }; |
| 117 | |
Paulo Zanoni | 5c50244 | 2014-04-01 15:37:11 -0300 | [diff] [blame] | 118 | /* IIR can theoretically queue up two events. Be paranoid. */ |
Paulo Zanoni | f86f3fb | 2014-04-01 15:37:14 -0300 | [diff] [blame] | 119 | #define GEN8_IRQ_RESET_NDX(type, which) do { \ |
Paulo Zanoni | 5c50244 | 2014-04-01 15:37:11 -0300 | [diff] [blame] | 120 | I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \ |
| 121 | POSTING_READ(GEN8_##type##_IMR(which)); \ |
| 122 | I915_WRITE(GEN8_##type##_IER(which), 0); \ |
| 123 | I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \ |
| 124 | POSTING_READ(GEN8_##type##_IIR(which)); \ |
| 125 | I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \ |
| 126 | POSTING_READ(GEN8_##type##_IIR(which)); \ |
| 127 | } while (0) |
| 128 | |
Paulo Zanoni | f86f3fb | 2014-04-01 15:37:14 -0300 | [diff] [blame] | 129 | #define GEN5_IRQ_RESET(type) do { \ |
Paulo Zanoni | a9d356a | 2014-04-01 15:37:09 -0300 | [diff] [blame] | 130 | I915_WRITE(type##IMR, 0xffffffff); \ |
Paulo Zanoni | 5c50244 | 2014-04-01 15:37:11 -0300 | [diff] [blame] | 131 | POSTING_READ(type##IMR); \ |
Paulo Zanoni | a9d356a | 2014-04-01 15:37:09 -0300 | [diff] [blame] | 132 | I915_WRITE(type##IER, 0); \ |
Paulo Zanoni | 5c50244 | 2014-04-01 15:37:11 -0300 | [diff] [blame] | 133 | I915_WRITE(type##IIR, 0xffffffff); \ |
| 134 | POSTING_READ(type##IIR); \ |
| 135 | I915_WRITE(type##IIR, 0xffffffff); \ |
| 136 | POSTING_READ(type##IIR); \ |
Paulo Zanoni | a9d356a | 2014-04-01 15:37:09 -0300 | [diff] [blame] | 137 | } while (0) |
| 138 | |
Paulo Zanoni | 337ba01 | 2014-04-01 15:37:16 -0300 | [diff] [blame] | 139 | /* |
| 140 | * We should clear IMR at preinstall/uninstall, and just check at postinstall. |
| 141 | */ |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 142 | static void gen5_assert_iir_is_zero(struct drm_i915_private *dev_priv, |
| 143 | i915_reg_t reg) |
Ville Syrjälä | b51a284 | 2015-09-18 20:03:41 +0300 | [diff] [blame] | 144 | { |
| 145 | u32 val = I915_READ(reg); |
| 146 | |
| 147 | if (val == 0) |
| 148 | return; |
| 149 | |
| 150 | WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n", |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 151 | i915_mmio_reg_offset(reg), val); |
Ville Syrjälä | b51a284 | 2015-09-18 20:03:41 +0300 | [diff] [blame] | 152 | I915_WRITE(reg, 0xffffffff); |
| 153 | POSTING_READ(reg); |
| 154 | I915_WRITE(reg, 0xffffffff); |
| 155 | POSTING_READ(reg); |
| 156 | } |
Paulo Zanoni | 337ba01 | 2014-04-01 15:37:16 -0300 | [diff] [blame] | 157 | |
Paulo Zanoni | 3507989 | 2014-04-01 15:37:15 -0300 | [diff] [blame] | 158 | #define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \ |
Ville Syrjälä | b51a284 | 2015-09-18 20:03:41 +0300 | [diff] [blame] | 159 | gen5_assert_iir_is_zero(dev_priv, GEN8_##type##_IIR(which)); \ |
Paulo Zanoni | 3507989 | 2014-04-01 15:37:15 -0300 | [diff] [blame] | 160 | I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \ |
Ville Syrjälä | 7d1bd539 | 2014-10-30 19:42:50 +0200 | [diff] [blame] | 161 | I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \ |
| 162 | POSTING_READ(GEN8_##type##_IMR(which)); \ |
Paulo Zanoni | 3507989 | 2014-04-01 15:37:15 -0300 | [diff] [blame] | 163 | } while (0) |
| 164 | |
| 165 | #define GEN5_IRQ_INIT(type, imr_val, ier_val) do { \ |
Ville Syrjälä | b51a284 | 2015-09-18 20:03:41 +0300 | [diff] [blame] | 166 | gen5_assert_iir_is_zero(dev_priv, type##IIR); \ |
Paulo Zanoni | 3507989 | 2014-04-01 15:37:15 -0300 | [diff] [blame] | 167 | I915_WRITE(type##IER, (ier_val)); \ |
Ville Syrjälä | 7d1bd539 | 2014-10-30 19:42:50 +0200 | [diff] [blame] | 168 | I915_WRITE(type##IMR, (imr_val)); \ |
| 169 | POSTING_READ(type##IMR); \ |
Paulo Zanoni | 3507989 | 2014-04-01 15:37:15 -0300 | [diff] [blame] | 170 | } while (0) |
| 171 | |
Imre Deak | c9a9a26 | 2014-11-05 20:48:37 +0200 | [diff] [blame] | 172 | static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir); |
Sagar Arun Kamble | 26705e2 | 2016-10-12 21:54:31 +0530 | [diff] [blame^] | 173 | static void gen9_guc_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir); |
Imre Deak | c9a9a26 | 2014-11-05 20:48:37 +0200 | [diff] [blame] | 174 | |
Egbert Eich | 0706f17 | 2015-09-23 16:15:27 +0200 | [diff] [blame] | 175 | /* For display hotplug interrupt */ |
| 176 | static inline void |
| 177 | i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv, |
| 178 | uint32_t mask, |
| 179 | uint32_t bits) |
| 180 | { |
| 181 | uint32_t val; |
| 182 | |
| 183 | assert_spin_locked(&dev_priv->irq_lock); |
| 184 | WARN_ON(bits & ~mask); |
| 185 | |
| 186 | val = I915_READ(PORT_HOTPLUG_EN); |
| 187 | val &= ~mask; |
| 188 | val |= bits; |
| 189 | I915_WRITE(PORT_HOTPLUG_EN, val); |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * i915_hotplug_interrupt_update - update hotplug interrupt enable |
| 194 | * @dev_priv: driver private |
| 195 | * @mask: bits to update |
| 196 | * @bits: bits to enable |
| 197 | * NOTE: the HPD enable bits are modified both inside and outside |
| 198 | * of an interrupt context. To avoid that read-modify-write cycles |
| 199 | * interfer, these bits are protected by a spinlock. Since this |
| 200 | * function is usually not called from a context where the lock is |
| 201 | * held already, this function acquires the lock itself. A non-locking |
| 202 | * version is also available. |
| 203 | */ |
| 204 | void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv, |
| 205 | uint32_t mask, |
| 206 | uint32_t bits) |
| 207 | { |
| 208 | spin_lock_irq(&dev_priv->irq_lock); |
| 209 | i915_hotplug_interrupt_update_locked(dev_priv, mask, bits); |
| 210 | spin_unlock_irq(&dev_priv->irq_lock); |
| 211 | } |
| 212 | |
Ville Syrjälä | d9dc34f1 | 2015-08-27 23:55:58 +0300 | [diff] [blame] | 213 | /** |
| 214 | * ilk_update_display_irq - update DEIMR |
| 215 | * @dev_priv: driver private |
| 216 | * @interrupt_mask: mask of interrupt bits to update |
| 217 | * @enabled_irq_mask: mask of interrupt bits to enable |
| 218 | */ |
Ville Syrjälä | fbdedaea | 2015-11-23 18:06:16 +0200 | [diff] [blame] | 219 | void ilk_update_display_irq(struct drm_i915_private *dev_priv, |
| 220 | uint32_t interrupt_mask, |
| 221 | uint32_t enabled_irq_mask) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 222 | { |
Ville Syrjälä | d9dc34f1 | 2015-08-27 23:55:58 +0300 | [diff] [blame] | 223 | uint32_t new_val; |
| 224 | |
Daniel Vetter | 4bc9d43 | 2013-06-27 13:44:58 +0200 | [diff] [blame] | 225 | assert_spin_locked(&dev_priv->irq_lock); |
| 226 | |
Ville Syrjälä | d9dc34f1 | 2015-08-27 23:55:58 +0300 | [diff] [blame] | 227 | WARN_ON(enabled_irq_mask & ~interrupt_mask); |
| 228 | |
Jesse Barnes | 9df7575f | 2014-06-20 09:29:20 -0700 | [diff] [blame] | 229 | if (WARN_ON(!intel_irqs_enabled(dev_priv))) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 230 | return; |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 231 | |
Ville Syrjälä | d9dc34f1 | 2015-08-27 23:55:58 +0300 | [diff] [blame] | 232 | new_val = dev_priv->irq_mask; |
| 233 | new_val &= ~interrupt_mask; |
| 234 | new_val |= (~enabled_irq_mask & interrupt_mask); |
| 235 | |
| 236 | if (new_val != dev_priv->irq_mask) { |
| 237 | dev_priv->irq_mask = new_val; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 238 | I915_WRITE(DEIMR, dev_priv->irq_mask); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 239 | POSTING_READ(DEIMR); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
Paulo Zanoni | 43eaea1 | 2013-08-06 18:57:12 -0300 | [diff] [blame] | 243 | /** |
| 244 | * ilk_update_gt_irq - update GTIMR |
| 245 | * @dev_priv: driver private |
| 246 | * @interrupt_mask: mask of interrupt bits to update |
| 247 | * @enabled_irq_mask: mask of interrupt bits to enable |
| 248 | */ |
| 249 | static void ilk_update_gt_irq(struct drm_i915_private *dev_priv, |
| 250 | uint32_t interrupt_mask, |
| 251 | uint32_t enabled_irq_mask) |
| 252 | { |
| 253 | assert_spin_locked(&dev_priv->irq_lock); |
| 254 | |
Daniel Vetter | 15a17aa | 2014-12-08 16:30:00 +0100 | [diff] [blame] | 255 | WARN_ON(enabled_irq_mask & ~interrupt_mask); |
| 256 | |
Jesse Barnes | 9df7575f | 2014-06-20 09:29:20 -0700 | [diff] [blame] | 257 | if (WARN_ON(!intel_irqs_enabled(dev_priv))) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 258 | return; |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 259 | |
Paulo Zanoni | 43eaea1 | 2013-08-06 18:57:12 -0300 | [diff] [blame] | 260 | dev_priv->gt_irq_mask &= ~interrupt_mask; |
| 261 | dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask); |
| 262 | I915_WRITE(GTIMR, dev_priv->gt_irq_mask); |
Paulo Zanoni | 43eaea1 | 2013-08-06 18:57:12 -0300 | [diff] [blame] | 263 | } |
| 264 | |
Daniel Vetter | 480c803 | 2014-07-16 09:49:40 +0200 | [diff] [blame] | 265 | 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] | 266 | { |
| 267 | ilk_update_gt_irq(dev_priv, mask, mask); |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 268 | POSTING_READ_FW(GTIMR); |
Paulo Zanoni | 43eaea1 | 2013-08-06 18:57:12 -0300 | [diff] [blame] | 269 | } |
| 270 | |
Daniel Vetter | 480c803 | 2014-07-16 09:49:40 +0200 | [diff] [blame] | 271 | 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] | 272 | { |
| 273 | ilk_update_gt_irq(dev_priv, mask, 0); |
| 274 | } |
| 275 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 276 | static i915_reg_t gen6_pm_iir(struct drm_i915_private *dev_priv) |
Imre Deak | b900b94 | 2014-11-05 20:48:48 +0200 | [diff] [blame] | 277 | { |
| 278 | return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR; |
| 279 | } |
| 280 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 281 | static i915_reg_t gen6_pm_imr(struct drm_i915_private *dev_priv) |
Imre Deak | a72fbc3 | 2014-11-05 20:48:31 +0200 | [diff] [blame] | 282 | { |
| 283 | return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IMR(2) : GEN6_PMIMR; |
| 284 | } |
| 285 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 286 | static i915_reg_t gen6_pm_ier(struct drm_i915_private *dev_priv) |
Imre Deak | b900b94 | 2014-11-05 20:48:48 +0200 | [diff] [blame] | 287 | { |
| 288 | return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IER(2) : GEN6_PMIER; |
| 289 | } |
| 290 | |
Paulo Zanoni | edbfdb4 | 2013-08-06 18:57:13 -0300 | [diff] [blame] | 291 | /** |
Ville Syrjälä | 81fd874 | 2015-11-25 16:21:30 +0200 | [diff] [blame] | 292 | * snb_update_pm_irq - update GEN6_PMIMR |
| 293 | * @dev_priv: driver private |
| 294 | * @interrupt_mask: mask of interrupt bits to update |
| 295 | * @enabled_irq_mask: mask of interrupt bits to enable |
| 296 | */ |
Paulo Zanoni | edbfdb4 | 2013-08-06 18:57:13 -0300 | [diff] [blame] | 297 | static void snb_update_pm_irq(struct drm_i915_private *dev_priv, |
| 298 | uint32_t interrupt_mask, |
| 299 | uint32_t enabled_irq_mask) |
| 300 | { |
Paulo Zanoni | 605cd25 | 2013-08-06 18:57:15 -0300 | [diff] [blame] | 301 | uint32_t new_val; |
Paulo Zanoni | edbfdb4 | 2013-08-06 18:57:13 -0300 | [diff] [blame] | 302 | |
Daniel Vetter | 15a17aa | 2014-12-08 16:30:00 +0100 | [diff] [blame] | 303 | WARN_ON(enabled_irq_mask & ~interrupt_mask); |
| 304 | |
Paulo Zanoni | edbfdb4 | 2013-08-06 18:57:13 -0300 | [diff] [blame] | 305 | assert_spin_locked(&dev_priv->irq_lock); |
| 306 | |
Akash Goel | f4e9af4 | 2016-10-12 21:54:30 +0530 | [diff] [blame] | 307 | new_val = dev_priv->pm_imr; |
Paulo Zanoni | f52ecbc | 2013-08-06 18:57:14 -0300 | [diff] [blame] | 308 | new_val &= ~interrupt_mask; |
| 309 | new_val |= (~enabled_irq_mask & interrupt_mask); |
| 310 | |
Akash Goel | f4e9af4 | 2016-10-12 21:54:30 +0530 | [diff] [blame] | 311 | if (new_val != dev_priv->pm_imr) { |
| 312 | dev_priv->pm_imr = new_val; |
| 313 | I915_WRITE(gen6_pm_imr(dev_priv), dev_priv->pm_imr); |
Imre Deak | a72fbc3 | 2014-11-05 20:48:31 +0200 | [diff] [blame] | 314 | POSTING_READ(gen6_pm_imr(dev_priv)); |
Paulo Zanoni | f52ecbc | 2013-08-06 18:57:14 -0300 | [diff] [blame] | 315 | } |
Paulo Zanoni | edbfdb4 | 2013-08-06 18:57:13 -0300 | [diff] [blame] | 316 | } |
| 317 | |
Akash Goel | f4e9af4 | 2016-10-12 21:54:30 +0530 | [diff] [blame] | 318 | void gen6_unmask_pm_irq(struct drm_i915_private *dev_priv, u32 mask) |
Paulo Zanoni | edbfdb4 | 2013-08-06 18:57:13 -0300 | [diff] [blame] | 319 | { |
Imre Deak | 9939fba | 2014-11-20 23:01:47 +0200 | [diff] [blame] | 320 | if (WARN_ON(!intel_irqs_enabled(dev_priv))) |
| 321 | return; |
| 322 | |
Paulo Zanoni | edbfdb4 | 2013-08-06 18:57:13 -0300 | [diff] [blame] | 323 | snb_update_pm_irq(dev_priv, mask, mask); |
| 324 | } |
| 325 | |
Akash Goel | f4e9af4 | 2016-10-12 21:54:30 +0530 | [diff] [blame] | 326 | static void __gen6_mask_pm_irq(struct drm_i915_private *dev_priv, u32 mask) |
Imre Deak | 9939fba | 2014-11-20 23:01:47 +0200 | [diff] [blame] | 327 | { |
| 328 | snb_update_pm_irq(dev_priv, mask, 0); |
| 329 | } |
| 330 | |
Akash Goel | f4e9af4 | 2016-10-12 21:54:30 +0530 | [diff] [blame] | 331 | void gen6_mask_pm_irq(struct drm_i915_private *dev_priv, u32 mask) |
Paulo Zanoni | edbfdb4 | 2013-08-06 18:57:13 -0300 | [diff] [blame] | 332 | { |
Imre Deak | 9939fba | 2014-11-20 23:01:47 +0200 | [diff] [blame] | 333 | if (WARN_ON(!intel_irqs_enabled(dev_priv))) |
| 334 | return; |
| 335 | |
Akash Goel | f4e9af4 | 2016-10-12 21:54:30 +0530 | [diff] [blame] | 336 | __gen6_mask_pm_irq(dev_priv, mask); |
| 337 | } |
| 338 | |
| 339 | void gen6_reset_pm_iir(struct drm_i915_private *dev_priv, u32 reset_mask) |
| 340 | { |
| 341 | i915_reg_t reg = gen6_pm_iir(dev_priv); |
| 342 | |
| 343 | assert_spin_locked(&dev_priv->irq_lock); |
| 344 | |
| 345 | I915_WRITE(reg, reset_mask); |
| 346 | I915_WRITE(reg, reset_mask); |
| 347 | POSTING_READ(reg); |
| 348 | } |
| 349 | |
| 350 | void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, u32 enable_mask) |
| 351 | { |
| 352 | assert_spin_locked(&dev_priv->irq_lock); |
| 353 | |
| 354 | dev_priv->pm_ier |= enable_mask; |
| 355 | I915_WRITE(gen6_pm_ier(dev_priv), dev_priv->pm_ier); |
| 356 | gen6_unmask_pm_irq(dev_priv, enable_mask); |
| 357 | /* unmask_pm_irq provides an implicit barrier (POSTING_READ) */ |
| 358 | } |
| 359 | |
| 360 | void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, u32 disable_mask) |
| 361 | { |
| 362 | assert_spin_locked(&dev_priv->irq_lock); |
| 363 | |
| 364 | dev_priv->pm_ier &= ~disable_mask; |
| 365 | __gen6_mask_pm_irq(dev_priv, disable_mask); |
| 366 | I915_WRITE(gen6_pm_ier(dev_priv), dev_priv->pm_ier); |
| 367 | /* though a barrier is missing here, but don't really need a one */ |
Paulo Zanoni | edbfdb4 | 2013-08-06 18:57:13 -0300 | [diff] [blame] | 368 | } |
| 369 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 370 | void gen6_reset_rps_interrupts(struct drm_i915_private *dev_priv) |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 371 | { |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 372 | spin_lock_irq(&dev_priv->irq_lock); |
Akash Goel | f4e9af4 | 2016-10-12 21:54:30 +0530 | [diff] [blame] | 373 | gen6_reset_pm_iir(dev_priv, dev_priv->pm_rps_events); |
Imre Deak | 096fad9 | 2015-03-23 19:11:35 +0200 | [diff] [blame] | 374 | dev_priv->rps.pm_iir = 0; |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 375 | spin_unlock_irq(&dev_priv->irq_lock); |
| 376 | } |
| 377 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 378 | void gen6_enable_rps_interrupts(struct drm_i915_private *dev_priv) |
Imre Deak | b900b94 | 2014-11-05 20:48:48 +0200 | [diff] [blame] | 379 | { |
Chris Wilson | f2a91d1 | 2016-09-21 14:51:06 +0100 | [diff] [blame] | 380 | if (READ_ONCE(dev_priv->rps.interrupts_enabled)) |
| 381 | return; |
| 382 | |
Imre Deak | b900b94 | 2014-11-05 20:48:48 +0200 | [diff] [blame] | 383 | spin_lock_irq(&dev_priv->irq_lock); |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 384 | WARN_ON_ONCE(dev_priv->rps.pm_iir); |
| 385 | WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events); |
Imre Deak | d4d70aa | 2014-11-19 15:30:04 +0200 | [diff] [blame] | 386 | dev_priv->rps.interrupts_enabled = true; |
Imre Deak | b900b94 | 2014-11-05 20:48:48 +0200 | [diff] [blame] | 387 | gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events); |
Imre Deak | 78e68d3 | 2014-12-15 18:59:27 +0200 | [diff] [blame] | 388 | |
Imre Deak | b900b94 | 2014-11-05 20:48:48 +0200 | [diff] [blame] | 389 | spin_unlock_irq(&dev_priv->irq_lock); |
| 390 | } |
| 391 | |
Imre Deak | 59d02a1 | 2014-12-19 19:33:26 +0200 | [diff] [blame] | 392 | u32 gen6_sanitize_rps_pm_mask(struct drm_i915_private *dev_priv, u32 mask) |
| 393 | { |
Sagar Arun Kamble | 1800ad2 | 2016-05-31 13:58:27 +0530 | [diff] [blame] | 394 | return (mask & ~dev_priv->rps.pm_intr_keep); |
Imre Deak | 59d02a1 | 2014-12-19 19:33:26 +0200 | [diff] [blame] | 395 | } |
| 396 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 397 | void gen6_disable_rps_interrupts(struct drm_i915_private *dev_priv) |
Imre Deak | b900b94 | 2014-11-05 20:48:48 +0200 | [diff] [blame] | 398 | { |
Chris Wilson | f2a91d1 | 2016-09-21 14:51:06 +0100 | [diff] [blame] | 399 | if (!READ_ONCE(dev_priv->rps.interrupts_enabled)) |
| 400 | return; |
| 401 | |
Imre Deak | d4d70aa | 2014-11-19 15:30:04 +0200 | [diff] [blame] | 402 | spin_lock_irq(&dev_priv->irq_lock); |
| 403 | dev_priv->rps.interrupts_enabled = false; |
Imre Deak | 9939fba | 2014-11-20 23:01:47 +0200 | [diff] [blame] | 404 | |
Dave Gordon | b20e3cf | 2016-09-12 21:19:35 +0100 | [diff] [blame] | 405 | I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0u)); |
Imre Deak | 9939fba | 2014-11-20 23:01:47 +0200 | [diff] [blame] | 406 | |
Akash Goel | f4e9af4 | 2016-10-12 21:54:30 +0530 | [diff] [blame] | 407 | gen6_disable_pm_irq(dev_priv, dev_priv->pm_rps_events); |
Imre Deak | 58072cc | 2015-03-23 19:11:34 +0200 | [diff] [blame] | 408 | |
| 409 | spin_unlock_irq(&dev_priv->irq_lock); |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 410 | synchronize_irq(dev_priv->drm.irq); |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 411 | |
| 412 | /* Now that we will not be generating any more work, flush any |
| 413 | * outsanding tasks. As we are called on the RPS idle path, |
| 414 | * we will reset the GPU to minimum frequencies, so the current |
| 415 | * state of the worker can be discarded. |
| 416 | */ |
| 417 | cancel_work_sync(&dev_priv->rps.work); |
| 418 | gen6_reset_rps_interrupts(dev_priv); |
Imre Deak | b900b94 | 2014-11-05 20:48:48 +0200 | [diff] [blame] | 419 | } |
| 420 | |
Sagar Arun Kamble | 26705e2 | 2016-10-12 21:54:31 +0530 | [diff] [blame^] | 421 | void gen9_reset_guc_interrupts(struct drm_i915_private *dev_priv) |
| 422 | { |
| 423 | spin_lock_irq(&dev_priv->irq_lock); |
| 424 | gen6_reset_pm_iir(dev_priv, dev_priv->pm_guc_events); |
| 425 | spin_unlock_irq(&dev_priv->irq_lock); |
| 426 | } |
| 427 | |
| 428 | void gen9_enable_guc_interrupts(struct drm_i915_private *dev_priv) |
| 429 | { |
| 430 | spin_lock_irq(&dev_priv->irq_lock); |
| 431 | if (!dev_priv->guc.interrupts_enabled) { |
| 432 | WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) & |
| 433 | dev_priv->pm_guc_events); |
| 434 | dev_priv->guc.interrupts_enabled = true; |
| 435 | gen6_enable_pm_irq(dev_priv, dev_priv->pm_guc_events); |
| 436 | } |
| 437 | spin_unlock_irq(&dev_priv->irq_lock); |
| 438 | } |
| 439 | |
| 440 | void gen9_disable_guc_interrupts(struct drm_i915_private *dev_priv) |
| 441 | { |
| 442 | spin_lock_irq(&dev_priv->irq_lock); |
| 443 | dev_priv->guc.interrupts_enabled = false; |
| 444 | |
| 445 | gen6_disable_pm_irq(dev_priv, dev_priv->pm_guc_events); |
| 446 | |
| 447 | spin_unlock_irq(&dev_priv->irq_lock); |
| 448 | synchronize_irq(dev_priv->drm.irq); |
| 449 | |
| 450 | gen9_reset_guc_interrupts(dev_priv); |
| 451 | } |
| 452 | |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 453 | /** |
Ville Syrjälä | 81fd874 | 2015-11-25 16:21:30 +0200 | [diff] [blame] | 454 | * bdw_update_port_irq - update DE port interrupt |
| 455 | * @dev_priv: driver private |
| 456 | * @interrupt_mask: mask of interrupt bits to update |
| 457 | * @enabled_irq_mask: mask of interrupt bits to enable |
| 458 | */ |
Ville Syrjälä | 3a3b3c7 | 2015-08-27 23:56:06 +0300 | [diff] [blame] | 459 | static void bdw_update_port_irq(struct drm_i915_private *dev_priv, |
| 460 | uint32_t interrupt_mask, |
| 461 | uint32_t enabled_irq_mask) |
| 462 | { |
| 463 | uint32_t new_val; |
| 464 | uint32_t old_val; |
| 465 | |
| 466 | assert_spin_locked(&dev_priv->irq_lock); |
| 467 | |
| 468 | WARN_ON(enabled_irq_mask & ~interrupt_mask); |
| 469 | |
| 470 | if (WARN_ON(!intel_irqs_enabled(dev_priv))) |
| 471 | return; |
| 472 | |
| 473 | old_val = I915_READ(GEN8_DE_PORT_IMR); |
| 474 | |
| 475 | new_val = old_val; |
| 476 | new_val &= ~interrupt_mask; |
| 477 | new_val |= (~enabled_irq_mask & interrupt_mask); |
| 478 | |
| 479 | if (new_val != old_val) { |
| 480 | I915_WRITE(GEN8_DE_PORT_IMR, new_val); |
| 481 | POSTING_READ(GEN8_DE_PORT_IMR); |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | /** |
Ville Syrjälä | 013d375 | 2015-11-23 18:06:17 +0200 | [diff] [blame] | 486 | * bdw_update_pipe_irq - update DE pipe interrupt |
| 487 | * @dev_priv: driver private |
| 488 | * @pipe: pipe whose interrupt to update |
| 489 | * @interrupt_mask: mask of interrupt bits to update |
| 490 | * @enabled_irq_mask: mask of interrupt bits to enable |
| 491 | */ |
| 492 | void bdw_update_pipe_irq(struct drm_i915_private *dev_priv, |
| 493 | enum pipe pipe, |
| 494 | uint32_t interrupt_mask, |
| 495 | uint32_t enabled_irq_mask) |
| 496 | { |
| 497 | uint32_t new_val; |
| 498 | |
| 499 | assert_spin_locked(&dev_priv->irq_lock); |
| 500 | |
| 501 | WARN_ON(enabled_irq_mask & ~interrupt_mask); |
| 502 | |
| 503 | if (WARN_ON(!intel_irqs_enabled(dev_priv))) |
| 504 | return; |
| 505 | |
| 506 | new_val = dev_priv->de_irq_mask[pipe]; |
| 507 | new_val &= ~interrupt_mask; |
| 508 | new_val |= (~enabled_irq_mask & interrupt_mask); |
| 509 | |
| 510 | if (new_val != dev_priv->de_irq_mask[pipe]) { |
| 511 | dev_priv->de_irq_mask[pipe] = new_val; |
| 512 | I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]); |
| 513 | POSTING_READ(GEN8_DE_PIPE_IMR(pipe)); |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | /** |
Daniel Vetter | fee884e | 2013-07-04 23:35:21 +0200 | [diff] [blame] | 518 | * ibx_display_interrupt_update - update SDEIMR |
| 519 | * @dev_priv: driver private |
| 520 | * @interrupt_mask: mask of interrupt bits to update |
| 521 | * @enabled_irq_mask: mask of interrupt bits to enable |
| 522 | */ |
Daniel Vetter | 47339cd | 2014-09-30 10:56:46 +0200 | [diff] [blame] | 523 | void ibx_display_interrupt_update(struct drm_i915_private *dev_priv, |
| 524 | uint32_t interrupt_mask, |
| 525 | uint32_t enabled_irq_mask) |
Daniel Vetter | fee884e | 2013-07-04 23:35:21 +0200 | [diff] [blame] | 526 | { |
| 527 | uint32_t sdeimr = I915_READ(SDEIMR); |
| 528 | sdeimr &= ~interrupt_mask; |
| 529 | sdeimr |= (~enabled_irq_mask & interrupt_mask); |
| 530 | |
Daniel Vetter | 15a17aa | 2014-12-08 16:30:00 +0100 | [diff] [blame] | 531 | WARN_ON(enabled_irq_mask & ~interrupt_mask); |
| 532 | |
Daniel Vetter | fee884e | 2013-07-04 23:35:21 +0200 | [diff] [blame] | 533 | assert_spin_locked(&dev_priv->irq_lock); |
| 534 | |
Jesse Barnes | 9df7575f | 2014-06-20 09:29:20 -0700 | [diff] [blame] | 535 | if (WARN_ON(!intel_irqs_enabled(dev_priv))) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 536 | return; |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 537 | |
Daniel Vetter | fee884e | 2013-07-04 23:35:21 +0200 | [diff] [blame] | 538 | I915_WRITE(SDEIMR, sdeimr); |
| 539 | POSTING_READ(SDEIMR); |
| 540 | } |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 541 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 542 | static void |
Imre Deak | 755e901 | 2014-02-10 18:42:47 +0200 | [diff] [blame] | 543 | __i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, |
| 544 | u32 enable_mask, u32 status_mask) |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 545 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 546 | i915_reg_t reg = PIPESTAT(pipe); |
Imre Deak | 755e901 | 2014-02-10 18:42:47 +0200 | [diff] [blame] | 547 | u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK; |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 548 | |
Daniel Vetter | b79480b | 2013-06-27 17:52:10 +0200 | [diff] [blame] | 549 | assert_spin_locked(&dev_priv->irq_lock); |
Daniel Vetter | d518ce5 | 2014-08-27 10:43:37 +0200 | [diff] [blame] | 550 | WARN_ON(!intel_irqs_enabled(dev_priv)); |
Daniel Vetter | b79480b | 2013-06-27 17:52:10 +0200 | [diff] [blame] | 551 | |
Ville Syrjälä | 04feced | 2014-04-03 13:28:33 +0300 | [diff] [blame] | 552 | if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK || |
| 553 | status_mask & ~PIPESTAT_INT_STATUS_MASK, |
| 554 | "pipe %c: enable_mask=0x%x, status_mask=0x%x\n", |
| 555 | pipe_name(pipe), enable_mask, status_mask)) |
Imre Deak | 755e901 | 2014-02-10 18:42:47 +0200 | [diff] [blame] | 556 | return; |
| 557 | |
| 558 | if ((pipestat & enable_mask) == enable_mask) |
Ville Syrjälä | 46c06a3 | 2013-02-20 21:16:18 +0200 | [diff] [blame] | 559 | return; |
| 560 | |
Imre Deak | 91d181d | 2014-02-10 18:42:49 +0200 | [diff] [blame] | 561 | dev_priv->pipestat_irq_mask[pipe] |= status_mask; |
| 562 | |
Ville Syrjälä | 46c06a3 | 2013-02-20 21:16:18 +0200 | [diff] [blame] | 563 | /* Enable the interrupt, clear any pending status */ |
Imre Deak | 755e901 | 2014-02-10 18:42:47 +0200 | [diff] [blame] | 564 | pipestat |= enable_mask | status_mask; |
Ville Syrjälä | 46c06a3 | 2013-02-20 21:16:18 +0200 | [diff] [blame] | 565 | I915_WRITE(reg, pipestat); |
| 566 | POSTING_READ(reg); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 567 | } |
| 568 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 569 | static void |
Imre Deak | 755e901 | 2014-02-10 18:42:47 +0200 | [diff] [blame] | 570 | __i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, |
| 571 | u32 enable_mask, u32 status_mask) |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 572 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 573 | i915_reg_t reg = PIPESTAT(pipe); |
Imre Deak | 755e901 | 2014-02-10 18:42:47 +0200 | [diff] [blame] | 574 | u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK; |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 575 | |
Daniel Vetter | b79480b | 2013-06-27 17:52:10 +0200 | [diff] [blame] | 576 | assert_spin_locked(&dev_priv->irq_lock); |
Daniel Vetter | d518ce5 | 2014-08-27 10:43:37 +0200 | [diff] [blame] | 577 | WARN_ON(!intel_irqs_enabled(dev_priv)); |
Daniel Vetter | b79480b | 2013-06-27 17:52:10 +0200 | [diff] [blame] | 578 | |
Ville Syrjälä | 04feced | 2014-04-03 13:28:33 +0300 | [diff] [blame] | 579 | if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK || |
| 580 | status_mask & ~PIPESTAT_INT_STATUS_MASK, |
| 581 | "pipe %c: enable_mask=0x%x, status_mask=0x%x\n", |
| 582 | pipe_name(pipe), enable_mask, status_mask)) |
Ville Syrjälä | 46c06a3 | 2013-02-20 21:16:18 +0200 | [diff] [blame] | 583 | return; |
| 584 | |
Imre Deak | 755e901 | 2014-02-10 18:42:47 +0200 | [diff] [blame] | 585 | if ((pipestat & enable_mask) == 0) |
| 586 | return; |
| 587 | |
Imre Deak | 91d181d | 2014-02-10 18:42:49 +0200 | [diff] [blame] | 588 | dev_priv->pipestat_irq_mask[pipe] &= ~status_mask; |
| 589 | |
Imre Deak | 755e901 | 2014-02-10 18:42:47 +0200 | [diff] [blame] | 590 | pipestat &= ~enable_mask; |
Ville Syrjälä | 46c06a3 | 2013-02-20 21:16:18 +0200 | [diff] [blame] | 591 | I915_WRITE(reg, pipestat); |
| 592 | POSTING_READ(reg); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 593 | } |
| 594 | |
Imre Deak | 10c59c5 | 2014-02-10 18:42:48 +0200 | [diff] [blame] | 595 | static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask) |
| 596 | { |
| 597 | u32 enable_mask = status_mask << 16; |
| 598 | |
| 599 | /* |
Ville Syrjälä | 724a690 | 2014-04-09 13:28:48 +0300 | [diff] [blame] | 600 | * On pipe A we don't support the PSR interrupt yet, |
| 601 | * on pipe B and C the same bit MBZ. |
Imre Deak | 10c59c5 | 2014-02-10 18:42:48 +0200 | [diff] [blame] | 602 | */ |
| 603 | if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV)) |
| 604 | return 0; |
Ville Syrjälä | 724a690 | 2014-04-09 13:28:48 +0300 | [diff] [blame] | 605 | /* |
| 606 | * On pipe B and C we don't support the PSR interrupt yet, on pipe |
| 607 | * A the same bit is for perf counters which we don't use either. |
| 608 | */ |
| 609 | if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV)) |
| 610 | return 0; |
Imre Deak | 10c59c5 | 2014-02-10 18:42:48 +0200 | [diff] [blame] | 611 | |
| 612 | enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS | |
| 613 | SPRITE0_FLIP_DONE_INT_EN_VLV | |
| 614 | SPRITE1_FLIP_DONE_INT_EN_VLV); |
| 615 | if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV) |
| 616 | enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV; |
| 617 | if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV) |
| 618 | enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV; |
| 619 | |
| 620 | return enable_mask; |
| 621 | } |
| 622 | |
Imre Deak | 755e901 | 2014-02-10 18:42:47 +0200 | [diff] [blame] | 623 | void |
| 624 | i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, |
| 625 | u32 status_mask) |
| 626 | { |
| 627 | u32 enable_mask; |
| 628 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 629 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 630 | enable_mask = vlv_get_pipestat_enable_mask(&dev_priv->drm, |
Imre Deak | 10c59c5 | 2014-02-10 18:42:48 +0200 | [diff] [blame] | 631 | status_mask); |
| 632 | else |
| 633 | enable_mask = status_mask << 16; |
Imre Deak | 755e901 | 2014-02-10 18:42:47 +0200 | [diff] [blame] | 634 | __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask); |
| 635 | } |
| 636 | |
| 637 | void |
| 638 | i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, |
| 639 | u32 status_mask) |
| 640 | { |
| 641 | u32 enable_mask; |
| 642 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 643 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 644 | enable_mask = vlv_get_pipestat_enable_mask(&dev_priv->drm, |
Imre Deak | 10c59c5 | 2014-02-10 18:42:48 +0200 | [diff] [blame] | 645 | status_mask); |
| 646 | else |
| 647 | enable_mask = status_mask << 16; |
Imre Deak | 755e901 | 2014-02-10 18:42:47 +0200 | [diff] [blame] | 648 | __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask); |
| 649 | } |
| 650 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 651 | /** |
Jani Nikula | f49e38d | 2013-04-29 13:02:54 +0300 | [diff] [blame] | 652 | * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion |
Tvrtko Ursulin | 14bb2c1 | 2016-06-03 14:02:17 +0100 | [diff] [blame] | 653 | * @dev_priv: i915 device private |
Zhao Yakui | 01c6688 | 2009-10-28 05:10:00 +0000 | [diff] [blame] | 654 | */ |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 655 | static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv) |
Zhao Yakui | 01c6688 | 2009-10-28 05:10:00 +0000 | [diff] [blame] | 656 | { |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 657 | if (!dev_priv->opregion.asle || !IS_MOBILE(dev_priv)) |
Jani Nikula | f49e38d | 2013-04-29 13:02:54 +0300 | [diff] [blame] | 658 | return; |
| 659 | |
Daniel Vetter | 1332178 | 2014-09-15 14:55:29 +0200 | [diff] [blame] | 660 | spin_lock_irq(&dev_priv->irq_lock); |
Zhao Yakui | 01c6688 | 2009-10-28 05:10:00 +0000 | [diff] [blame] | 661 | |
Imre Deak | 755e901 | 2014-02-10 18:42:47 +0200 | [diff] [blame] | 662 | i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS); |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 663 | if (INTEL_GEN(dev_priv) >= 4) |
Daniel Vetter | 3b6c42e | 2013-10-21 18:04:35 +0200 | [diff] [blame] | 664 | i915_enable_pipestat(dev_priv, PIPE_A, |
Imre Deak | 755e901 | 2014-02-10 18:42:47 +0200 | [diff] [blame] | 665 | PIPE_LEGACY_BLC_EVENT_STATUS); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 666 | |
Daniel Vetter | 1332178 | 2014-09-15 14:55:29 +0200 | [diff] [blame] | 667 | spin_unlock_irq(&dev_priv->irq_lock); |
Zhao Yakui | 01c6688 | 2009-10-28 05:10:00 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Ville Syrjälä | f75f374 | 2014-05-15 20:20:36 +0300 | [diff] [blame] | 670 | /* |
| 671 | * This timing diagram depicts the video signal in and |
| 672 | * around the vertical blanking period. |
| 673 | * |
| 674 | * Assumptions about the fictitious mode used in this example: |
| 675 | * vblank_start >= 3 |
| 676 | * vsync_start = vblank_start + 1 |
| 677 | * vsync_end = vblank_start + 2 |
| 678 | * vtotal = vblank_start + 3 |
| 679 | * |
| 680 | * start of vblank: |
| 681 | * latch double buffered registers |
| 682 | * increment frame counter (ctg+) |
| 683 | * generate start of vblank interrupt (gen4+) |
| 684 | * | |
| 685 | * | frame start: |
| 686 | * | generate frame start interrupt (aka. vblank interrupt) (gmch) |
| 687 | * | may be shifted forward 1-3 extra lines via PIPECONF |
| 688 | * | | |
| 689 | * | | start of vsync: |
| 690 | * | | generate vsync interrupt |
| 691 | * | | | |
| 692 | * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx |
| 693 | * . \hs/ . \hs/ \hs/ \hs/ . \hs/ |
| 694 | * ----va---> <-----------------vb--------------------> <--------va------------- |
| 695 | * | | <----vs-----> | |
| 696 | * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2) |
| 697 | * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+) |
| 698 | * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi) |
| 699 | * | | | |
| 700 | * last visible pixel first visible pixel |
| 701 | * | increment frame counter (gen3/4) |
| 702 | * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4) |
| 703 | * |
| 704 | * x = horizontal active |
| 705 | * _ = horizontal blanking |
| 706 | * hs = horizontal sync |
| 707 | * va = vertical active |
| 708 | * vb = vertical blanking |
| 709 | * vs = vertical sync |
| 710 | * vbs = vblank_start (number) |
| 711 | * |
| 712 | * Summary: |
| 713 | * - most events happen at the start of horizontal sync |
| 714 | * - frame start happens at the start of horizontal blank, 1-4 lines |
| 715 | * (depending on PIPECONF settings) after the start of vblank |
| 716 | * - gen3/4 pixel and frame counter are synchronized with the start |
| 717 | * of horizontal active on the first line of vertical active |
| 718 | */ |
| 719 | |
Keith Packard | 42f52ef | 2008-10-18 19:39:29 -0700 | [diff] [blame] | 720 | /* Called from drm generic code, passed a 'crtc', which |
| 721 | * we use as a pipe index |
| 722 | */ |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 723 | static u32 i915_get_vblank_counter(struct drm_device *dev, unsigned int pipe) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 724 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 725 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 726 | i915_reg_t high_frame, low_frame; |
Ville Syrjälä | 0b2a8e0 | 2014-04-29 13:35:50 +0300 | [diff] [blame] | 727 | u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal; |
Daniel Vetter | f3a5c3f | 2015-02-13 21:03:44 +0100 | [diff] [blame] | 728 | struct intel_crtc *intel_crtc = |
| 729 | to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
Maarten Lankhorst | fc467a22 | 2015-06-01 12:50:07 +0200 | [diff] [blame] | 730 | const struct drm_display_mode *mode = &intel_crtc->base.hwmode; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 731 | |
Daniel Vetter | f3a5c3f | 2015-02-13 21:03:44 +0100 | [diff] [blame] | 732 | htotal = mode->crtc_htotal; |
| 733 | hsync_start = mode->crtc_hsync_start; |
| 734 | vbl_start = mode->crtc_vblank_start; |
| 735 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 736 | vbl_start = DIV_ROUND_UP(vbl_start, 2); |
Ville Syrjälä | 391f75e | 2013-09-25 19:55:26 +0300 | [diff] [blame] | 737 | |
Ville Syrjälä | 0b2a8e0 | 2014-04-29 13:35:50 +0300 | [diff] [blame] | 738 | /* Convert to pixel count */ |
| 739 | vbl_start *= htotal; |
| 740 | |
| 741 | /* Start of vblank event occurs at start of hsync */ |
| 742 | vbl_start -= htotal - hsync_start; |
| 743 | |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 744 | high_frame = PIPEFRAME(pipe); |
| 745 | low_frame = PIPEFRAMEPIXEL(pipe); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 746 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 747 | /* |
| 748 | * High & low register fields aren't synchronized, so make sure |
| 749 | * we get a low value that's stable across two reads of the high |
| 750 | * register. |
| 751 | */ |
| 752 | do { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 753 | high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; |
Ville Syrjälä | 391f75e | 2013-09-25 19:55:26 +0300 | [diff] [blame] | 754 | low = I915_READ(low_frame); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 755 | high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 756 | } while (high1 != high2); |
| 757 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 758 | high1 >>= PIPE_FRAME_HIGH_SHIFT; |
Ville Syrjälä | 391f75e | 2013-09-25 19:55:26 +0300 | [diff] [blame] | 759 | pixel = low & PIPE_PIXEL_MASK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 760 | low >>= PIPE_FRAME_LOW_SHIFT; |
Ville Syrjälä | 391f75e | 2013-09-25 19:55:26 +0300 | [diff] [blame] | 761 | |
| 762 | /* |
| 763 | * The frame counter increments at beginning of active. |
| 764 | * Cook up a vblank counter by also checking the pixel |
| 765 | * counter against vblank start. |
| 766 | */ |
Ville Syrjälä | edc08d0 | 2013-11-06 13:56:27 -0200 | [diff] [blame] | 767 | return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 768 | } |
| 769 | |
Dave Airlie | 974e59b | 2015-10-30 09:45:33 +1000 | [diff] [blame] | 770 | static u32 g4x_get_vblank_counter(struct drm_device *dev, unsigned int pipe) |
Jesse Barnes | 9880b7a | 2009-02-06 10:22:41 -0800 | [diff] [blame] | 771 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 772 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 9880b7a | 2009-02-06 10:22:41 -0800 | [diff] [blame] | 773 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 774 | return I915_READ(PIPE_FRMCOUNT_G4X(pipe)); |
Jesse Barnes | 9880b7a | 2009-02-06 10:22:41 -0800 | [diff] [blame] | 775 | } |
| 776 | |
Ville Syrjälä | 75aa3f6 | 2015-10-22 15:34:56 +0300 | [diff] [blame] | 777 | /* I915_READ_FW, only for fast reads of display block, no need for forcewake etc. */ |
Ville Syrjälä | a225f07 | 2014-04-29 13:35:45 +0300 | [diff] [blame] | 778 | static int __intel_get_crtc_scanline(struct intel_crtc *crtc) |
| 779 | { |
| 780 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 781 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | fc467a22 | 2015-06-01 12:50:07 +0200 | [diff] [blame] | 782 | const struct drm_display_mode *mode = &crtc->base.hwmode; |
Ville Syrjälä | a225f07 | 2014-04-29 13:35:45 +0300 | [diff] [blame] | 783 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 784 | int position, vtotal; |
Ville Syrjälä | a225f07 | 2014-04-29 13:35:45 +0300 | [diff] [blame] | 785 | |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 786 | vtotal = mode->crtc_vtotal; |
Ville Syrjälä | a225f07 | 2014-04-29 13:35:45 +0300 | [diff] [blame] | 787 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 788 | vtotal /= 2; |
| 789 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 790 | if (IS_GEN2(dev_priv)) |
Ville Syrjälä | 75aa3f6 | 2015-10-22 15:34:56 +0300 | [diff] [blame] | 791 | position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2; |
Ville Syrjälä | a225f07 | 2014-04-29 13:35:45 +0300 | [diff] [blame] | 792 | else |
Ville Syrjälä | 75aa3f6 | 2015-10-22 15:34:56 +0300 | [diff] [blame] | 793 | position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3; |
Ville Syrjälä | a225f07 | 2014-04-29 13:35:45 +0300 | [diff] [blame] | 794 | |
| 795 | /* |
Jesse Barnes | 41b578f | 2015-09-22 12:15:54 -0700 | [diff] [blame] | 796 | * On HSW, the DSL reg (0x70000) appears to return 0 if we |
| 797 | * read it just before the start of vblank. So try it again |
| 798 | * so we don't accidentally end up spanning a vblank frame |
| 799 | * increment, causing the pipe_update_end() code to squak at us. |
| 800 | * |
| 801 | * The nature of this problem means we can't simply check the ISR |
| 802 | * bit and return the vblank start value; nor can we use the scanline |
| 803 | * debug register in the transcoder as it appears to have the same |
| 804 | * problem. We may need to extend this to include other platforms, |
| 805 | * but so far testing only shows the problem on HSW. |
| 806 | */ |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 807 | if (HAS_DDI(dev_priv) && !position) { |
Jesse Barnes | 41b578f | 2015-09-22 12:15:54 -0700 | [diff] [blame] | 808 | int i, temp; |
| 809 | |
| 810 | for (i = 0; i < 100; i++) { |
| 811 | udelay(1); |
| 812 | temp = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & |
| 813 | DSL_LINEMASK_GEN3; |
| 814 | if (temp != position) { |
| 815 | position = temp; |
| 816 | break; |
| 817 | } |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | /* |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 822 | * See update_scanline_offset() for the details on the |
| 823 | * scanline_offset adjustment. |
Ville Syrjälä | a225f07 | 2014-04-29 13:35:45 +0300 | [diff] [blame] | 824 | */ |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 825 | return (position + crtc->scanline_offset) % vtotal; |
Ville Syrjälä | a225f07 | 2014-04-29 13:35:45 +0300 | [diff] [blame] | 826 | } |
| 827 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 828 | static int i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe, |
Ville Syrjälä | abca9e45 | 2013-10-28 20:50:48 +0200 | [diff] [blame] | 829 | unsigned int flags, int *vpos, int *hpos, |
Ville Syrjälä | 3bb403b | 2015-09-14 22:43:44 +0300 | [diff] [blame] | 830 | ktime_t *stime, ktime_t *etime, |
| 831 | const struct drm_display_mode *mode) |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 832 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 833 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | c2baf4b | 2013-09-23 14:48:50 +0300 | [diff] [blame] | 834 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 835 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 3aa18df | 2013-10-11 19:10:32 +0300 | [diff] [blame] | 836 | int position; |
Ville Syrjälä | 78e8fc6 | 2014-04-29 13:35:44 +0300 | [diff] [blame] | 837 | int vbl_start, vbl_end, hsync_start, htotal, vtotal; |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 838 | bool in_vbl = true; |
| 839 | int ret = 0; |
Mario Kleiner | ad3543e | 2013-10-30 05:13:08 +0100 | [diff] [blame] | 840 | unsigned long irqflags; |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 841 | |
Maarten Lankhorst | fc467a22 | 2015-06-01 12:50:07 +0200 | [diff] [blame] | 842 | if (WARN_ON(!mode->crtc_clock)) { |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 843 | DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled " |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 844 | "pipe %c\n", pipe_name(pipe)); |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 845 | return 0; |
| 846 | } |
| 847 | |
Ville Syrjälä | c2baf4b | 2013-09-23 14:48:50 +0300 | [diff] [blame] | 848 | htotal = mode->crtc_htotal; |
Ville Syrjälä | 78e8fc6 | 2014-04-29 13:35:44 +0300 | [diff] [blame] | 849 | hsync_start = mode->crtc_hsync_start; |
Ville Syrjälä | c2baf4b | 2013-09-23 14:48:50 +0300 | [diff] [blame] | 850 | vtotal = mode->crtc_vtotal; |
| 851 | vbl_start = mode->crtc_vblank_start; |
| 852 | vbl_end = mode->crtc_vblank_end; |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 853 | |
Ville Syrjälä | d31faf6 | 2013-10-28 16:31:41 +0200 | [diff] [blame] | 854 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) { |
| 855 | vbl_start = DIV_ROUND_UP(vbl_start, 2); |
| 856 | vbl_end /= 2; |
| 857 | vtotal /= 2; |
| 858 | } |
| 859 | |
Ville Syrjälä | c2baf4b | 2013-09-23 14:48:50 +0300 | [diff] [blame] | 860 | ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE; |
| 861 | |
Mario Kleiner | ad3543e | 2013-10-30 05:13:08 +0100 | [diff] [blame] | 862 | /* |
| 863 | * Lock uncore.lock, as we will do multiple timing critical raw |
| 864 | * register reads, potentially with preemption disabled, so the |
| 865 | * following code must not block on uncore.lock. |
| 866 | */ |
| 867 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
Ville Syrjälä | 78e8fc6 | 2014-04-29 13:35:44 +0300 | [diff] [blame] | 868 | |
Mario Kleiner | ad3543e | 2013-10-30 05:13:08 +0100 | [diff] [blame] | 869 | /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */ |
| 870 | |
| 871 | /* Get optional system timestamp before query. */ |
| 872 | if (stime) |
| 873 | *stime = ktime_get(); |
| 874 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 875 | if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) { |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 876 | /* No obvious pixelcount register. Only query vertical |
| 877 | * scanout position from Display scan line register. |
| 878 | */ |
Ville Syrjälä | a225f07 | 2014-04-29 13:35:45 +0300 | [diff] [blame] | 879 | position = __intel_get_crtc_scanline(intel_crtc); |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 880 | } else { |
| 881 | /* Have access to pixelcount since start of frame. |
| 882 | * We can split this into vertical and horizontal |
| 883 | * scanout position. |
| 884 | */ |
Ville Syrjälä | 75aa3f6 | 2015-10-22 15:34:56 +0300 | [diff] [blame] | 885 | position = (I915_READ_FW(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT; |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 886 | |
Ville Syrjälä | 3aa18df | 2013-10-11 19:10:32 +0300 | [diff] [blame] | 887 | /* convert to pixel counts */ |
| 888 | vbl_start *= htotal; |
| 889 | vbl_end *= htotal; |
| 890 | vtotal *= htotal; |
Ville Syrjälä | 78e8fc6 | 2014-04-29 13:35:44 +0300 | [diff] [blame] | 891 | |
| 892 | /* |
Ville Syrjälä | 7e78f1cb | 2014-04-29 13:35:49 +0300 | [diff] [blame] | 893 | * In interlaced modes, the pixel counter counts all pixels, |
| 894 | * so one field will have htotal more pixels. In order to avoid |
| 895 | * the reported position from jumping backwards when the pixel |
| 896 | * counter is beyond the length of the shorter field, just |
| 897 | * clamp the position the length of the shorter field. This |
| 898 | * matches how the scanline counter based position works since |
| 899 | * the scanline counter doesn't count the two half lines. |
| 900 | */ |
| 901 | if (position >= vtotal) |
| 902 | position = vtotal - 1; |
| 903 | |
| 904 | /* |
Ville Syrjälä | 78e8fc6 | 2014-04-29 13:35:44 +0300 | [diff] [blame] | 905 | * Start of vblank interrupt is triggered at start of hsync, |
| 906 | * just prior to the first active line of vblank. However we |
| 907 | * consider lines to start at the leading edge of horizontal |
| 908 | * active. So, should we get here before we've crossed into |
| 909 | * the horizontal active of the first line in vblank, we would |
| 910 | * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that, |
| 911 | * always add htotal-hsync_start to the current pixel position. |
| 912 | */ |
| 913 | position = (position + htotal - hsync_start) % vtotal; |
Ville Syrjälä | 3aa18df | 2013-10-11 19:10:32 +0300 | [diff] [blame] | 914 | } |
| 915 | |
Mario Kleiner | ad3543e | 2013-10-30 05:13:08 +0100 | [diff] [blame] | 916 | /* Get optional system timestamp after query. */ |
| 917 | if (etime) |
| 918 | *etime = ktime_get(); |
| 919 | |
| 920 | /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */ |
| 921 | |
| 922 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
| 923 | |
Ville Syrjälä | 3aa18df | 2013-10-11 19:10:32 +0300 | [diff] [blame] | 924 | in_vbl = position >= vbl_start && position < vbl_end; |
| 925 | |
| 926 | /* |
| 927 | * While in vblank, position will be negative |
| 928 | * counting up towards 0 at vbl_end. And outside |
| 929 | * vblank, position will be positive counting |
| 930 | * up since vbl_end. |
| 931 | */ |
| 932 | if (position >= vbl_start) |
| 933 | position -= vbl_end; |
| 934 | else |
| 935 | position += vtotal - vbl_end; |
| 936 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 937 | if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) { |
Ville Syrjälä | 3aa18df | 2013-10-11 19:10:32 +0300 | [diff] [blame] | 938 | *vpos = position; |
| 939 | *hpos = 0; |
| 940 | } else { |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 941 | *vpos = position / htotal; |
| 942 | *hpos = position - (*vpos * htotal); |
| 943 | } |
| 944 | |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 945 | /* In vblank? */ |
| 946 | if (in_vbl) |
Daniel Vetter | 3d3cbd8 | 2014-09-10 17:36:11 +0200 | [diff] [blame] | 947 | ret |= DRM_SCANOUTPOS_IN_VBLANK; |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 948 | |
| 949 | return ret; |
| 950 | } |
| 951 | |
Ville Syrjälä | a225f07 | 2014-04-29 13:35:45 +0300 | [diff] [blame] | 952 | int intel_get_crtc_scanline(struct intel_crtc *crtc) |
| 953 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 954 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | a225f07 | 2014-04-29 13:35:45 +0300 | [diff] [blame] | 955 | unsigned long irqflags; |
| 956 | int position; |
| 957 | |
| 958 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 959 | position = __intel_get_crtc_scanline(crtc); |
| 960 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
| 961 | |
| 962 | return position; |
| 963 | } |
| 964 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 965 | static int i915_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe, |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 966 | int *max_error, |
| 967 | struct timeval *vblank_time, |
| 968 | unsigned flags) |
| 969 | { |
Chris Wilson | 4041b85 | 2011-01-22 10:07:56 +0000 | [diff] [blame] | 970 | struct drm_crtc *crtc; |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 971 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 972 | if (pipe >= INTEL_INFO(dev)->num_pipes) { |
| 973 | DRM_ERROR("Invalid crtc %u\n", pipe); |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 974 | return -EINVAL; |
| 975 | } |
| 976 | |
| 977 | /* Get drm_crtc to timestamp: */ |
Chris Wilson | 4041b85 | 2011-01-22 10:07:56 +0000 | [diff] [blame] | 978 | crtc = intel_get_crtc_for_pipe(dev, pipe); |
| 979 | if (crtc == NULL) { |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 980 | DRM_ERROR("Invalid crtc %u\n", pipe); |
Chris Wilson | 4041b85 | 2011-01-22 10:07:56 +0000 | [diff] [blame] | 981 | return -EINVAL; |
| 982 | } |
| 983 | |
Maarten Lankhorst | fc467a22 | 2015-06-01 12:50:07 +0200 | [diff] [blame] | 984 | if (!crtc->hwmode.crtc_clock) { |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 985 | DRM_DEBUG_KMS("crtc %u is disabled\n", pipe); |
Chris Wilson | 4041b85 | 2011-01-22 10:07:56 +0000 | [diff] [blame] | 986 | return -EBUSY; |
| 987 | } |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 988 | |
| 989 | /* Helper routine in DRM core does all the work: */ |
Chris Wilson | 4041b85 | 2011-01-22 10:07:56 +0000 | [diff] [blame] | 990 | return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error, |
| 991 | vblank_time, flags, |
Maarten Lankhorst | fc467a22 | 2015-06-01 12:50:07 +0200 | [diff] [blame] | 992 | &crtc->hwmode); |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 993 | } |
| 994 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 995 | static void ironlake_rps_change_irq_handler(struct drm_i915_private *dev_priv) |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 996 | { |
Matthew Garrett | b5b72e8 | 2010-02-02 18:30:47 +0000 | [diff] [blame] | 997 | u32 busy_up, busy_down, max_avg, min_avg; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 998 | u8 new_delay; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 999 | |
Daniel Vetter | d0ecd7e | 2013-07-04 23:35:25 +0200 | [diff] [blame] | 1000 | spin_lock(&mchdev_lock); |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 1001 | |
Daniel Vetter | 73edd18f | 2012-08-08 23:35:37 +0200 | [diff] [blame] | 1002 | I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS)); |
| 1003 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 1004 | new_delay = dev_priv->ips.cur_delay; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 1005 | |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1006 | I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG); |
Matthew Garrett | b5b72e8 | 2010-02-02 18:30:47 +0000 | [diff] [blame] | 1007 | busy_up = I915_READ(RCPREVBSYTUPAVG); |
| 1008 | busy_down = I915_READ(RCPREVBSYTDNAVG); |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 1009 | max_avg = I915_READ(RCBMAXAVG); |
| 1010 | min_avg = I915_READ(RCBMINAVG); |
| 1011 | |
| 1012 | /* Handle RCS change request from hw */ |
Matthew Garrett | b5b72e8 | 2010-02-02 18:30:47 +0000 | [diff] [blame] | 1013 | if (busy_up > max_avg) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 1014 | if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay) |
| 1015 | new_delay = dev_priv->ips.cur_delay - 1; |
| 1016 | if (new_delay < dev_priv->ips.max_delay) |
| 1017 | new_delay = dev_priv->ips.max_delay; |
Matthew Garrett | b5b72e8 | 2010-02-02 18:30:47 +0000 | [diff] [blame] | 1018 | } else if (busy_down < min_avg) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 1019 | if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay) |
| 1020 | new_delay = dev_priv->ips.cur_delay + 1; |
| 1021 | if (new_delay > dev_priv->ips.min_delay) |
| 1022 | new_delay = dev_priv->ips.min_delay; |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 1023 | } |
| 1024 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1025 | if (ironlake_set_drps(dev_priv, new_delay)) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 1026 | dev_priv->ips.cur_delay = new_delay; |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 1027 | |
Daniel Vetter | d0ecd7e | 2013-07-04 23:35:25 +0200 | [diff] [blame] | 1028 | spin_unlock(&mchdev_lock); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 1029 | |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 1030 | return; |
| 1031 | } |
| 1032 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1033 | static void notify_ring(struct intel_engine_cs *engine) |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1034 | { |
Chris Wilson | aca34b6 | 2016-07-06 12:39:02 +0100 | [diff] [blame] | 1035 | smp_store_mb(engine->breadcrumbs.irq_posted, true); |
Chris Wilson | 83348ba | 2016-08-09 17:47:51 +0100 | [diff] [blame] | 1036 | if (intel_engine_wakeup(engine)) |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 1037 | trace_i915_gem_request_notify(engine); |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1038 | } |
| 1039 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 1040 | static void vlv_c0_read(struct drm_i915_private *dev_priv, |
| 1041 | struct intel_rps_ei *ei) |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 1042 | { |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 1043 | ei->cz_clock = vlv_punit_read(dev_priv, PUNIT_REG_CZ_TIMESTAMP); |
| 1044 | ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT); |
| 1045 | ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT); |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 1046 | } |
| 1047 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 1048 | static bool vlv_c0_above(struct drm_i915_private *dev_priv, |
| 1049 | const struct intel_rps_ei *old, |
| 1050 | const struct intel_rps_ei *now, |
| 1051 | int threshold) |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 1052 | { |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 1053 | u64 time, c0; |
Ville Syrjälä | 7bad74d | 2015-09-24 23:29:20 +0300 | [diff] [blame] | 1054 | unsigned int mul = 100; |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 1055 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 1056 | if (old->cz_clock == 0) |
| 1057 | return false; |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 1058 | |
Ville Syrjälä | 7bad74d | 2015-09-24 23:29:20 +0300 | [diff] [blame] | 1059 | if (I915_READ(VLV_COUNTER_CONTROL) & VLV_COUNT_RANGE_HIGH) |
| 1060 | mul <<= 8; |
| 1061 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 1062 | time = now->cz_clock - old->cz_clock; |
Ville Syrjälä | 7bad74d | 2015-09-24 23:29:20 +0300 | [diff] [blame] | 1063 | time *= threshold * dev_priv->czclk_freq; |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 1064 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 1065 | /* Workload can be split between render + media, e.g. SwapBuffers |
| 1066 | * being blitted in X after being rendered in mesa. To account for |
| 1067 | * this we need to combine both engines into our activity counter. |
| 1068 | */ |
| 1069 | c0 = now->render_c0 - old->render_c0; |
| 1070 | c0 += now->media_c0 - old->media_c0; |
Ville Syrjälä | 7bad74d | 2015-09-24 23:29:20 +0300 | [diff] [blame] | 1071 | c0 *= mul * VLV_CZ_CLOCK_TO_MILLI_SEC; |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 1072 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 1073 | return c0 >= time; |
| 1074 | } |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 1075 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 1076 | void gen6_rps_reset_ei(struct drm_i915_private *dev_priv) |
| 1077 | { |
| 1078 | vlv_c0_read(dev_priv, &dev_priv->rps.down_ei); |
| 1079 | dev_priv->rps.up_ei = dev_priv->rps.down_ei; |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir) |
| 1083 | { |
| 1084 | struct intel_rps_ei now; |
| 1085 | u32 events = 0; |
| 1086 | |
Chris Wilson | 6f4b12f8 | 2015-03-18 09:48:23 +0000 | [diff] [blame] | 1087 | if ((pm_iir & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED)) == 0) |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 1088 | return 0; |
| 1089 | |
| 1090 | vlv_c0_read(dev_priv, &now); |
| 1091 | if (now.cz_clock == 0) |
| 1092 | return 0; |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 1093 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 1094 | if (pm_iir & GEN6_PM_RP_DOWN_EI_EXPIRED) { |
| 1095 | if (!vlv_c0_above(dev_priv, |
| 1096 | &dev_priv->rps.down_ei, &now, |
Chris Wilson | 8fb5519 | 2015-04-07 16:20:28 +0100 | [diff] [blame] | 1097 | dev_priv->rps.down_threshold)) |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 1098 | events |= GEN6_PM_RP_DOWN_THRESHOLD; |
| 1099 | dev_priv->rps.down_ei = now; |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 1100 | } |
| 1101 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 1102 | if (pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) { |
| 1103 | if (vlv_c0_above(dev_priv, |
| 1104 | &dev_priv->rps.up_ei, &now, |
Chris Wilson | 8fb5519 | 2015-04-07 16:20:28 +0100 | [diff] [blame] | 1105 | dev_priv->rps.up_threshold)) |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 1106 | events |= GEN6_PM_RP_UP_THRESHOLD; |
| 1107 | dev_priv->rps.up_ei = now; |
| 1108 | } |
| 1109 | |
| 1110 | return events; |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 1111 | } |
| 1112 | |
Chris Wilson | f5a4c67 | 2015-04-27 13:41:23 +0100 | [diff] [blame] | 1113 | static bool any_waiters(struct drm_i915_private *dev_priv) |
| 1114 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 1115 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1116 | enum intel_engine_id id; |
Chris Wilson | f5a4c67 | 2015-04-27 13:41:23 +0100 | [diff] [blame] | 1117 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1118 | for_each_engine(engine, dev_priv, id) |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 1119 | if (intel_engine_has_waiter(engine)) |
Chris Wilson | f5a4c67 | 2015-04-27 13:41:23 +0100 | [diff] [blame] | 1120 | return true; |
| 1121 | |
| 1122 | return false; |
| 1123 | } |
| 1124 | |
Ben Widawsky | 4912d04 | 2011-04-25 11:25:20 -0700 | [diff] [blame] | 1125 | static void gen6_pm_rps_work(struct work_struct *work) |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 1126 | { |
Jani Nikula | 2d1013d | 2014-03-31 14:27:17 +0300 | [diff] [blame] | 1127 | struct drm_i915_private *dev_priv = |
| 1128 | container_of(work, struct drm_i915_private, rps.work); |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 1129 | bool client_boost; |
| 1130 | int new_delay, adj, min, max; |
Paulo Zanoni | edbfdb4 | 2013-08-06 18:57:13 -0300 | [diff] [blame] | 1131 | u32 pm_iir; |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 1132 | |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 1133 | spin_lock_irq(&dev_priv->irq_lock); |
Imre Deak | d4d70aa | 2014-11-19 15:30:04 +0200 | [diff] [blame] | 1134 | /* Speed up work cancelation during disabling rps interrupts. */ |
| 1135 | if (!dev_priv->rps.interrupts_enabled) { |
| 1136 | spin_unlock_irq(&dev_priv->irq_lock); |
| 1137 | return; |
| 1138 | } |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1139 | |
Daniel Vetter | c6a828d | 2012-08-08 23:35:35 +0200 | [diff] [blame] | 1140 | pm_iir = dev_priv->rps.pm_iir; |
| 1141 | dev_priv->rps.pm_iir = 0; |
Imre Deak | a72fbc3 | 2014-11-05 20:48:31 +0200 | [diff] [blame] | 1142 | /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */ |
Akash Goel | f4e9af4 | 2016-10-12 21:54:30 +0530 | [diff] [blame] | 1143 | gen6_unmask_pm_irq(dev_priv, dev_priv->pm_rps_events); |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 1144 | client_boost = dev_priv->rps.client_boost; |
| 1145 | dev_priv->rps.client_boost = false; |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 1146 | spin_unlock_irq(&dev_priv->irq_lock); |
Ben Widawsky | 4912d04 | 2011-04-25 11:25:20 -0700 | [diff] [blame] | 1147 | |
Paulo Zanoni | 60611c1 | 2013-08-15 11:50:01 -0300 | [diff] [blame] | 1148 | /* 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] | 1149 | WARN_ON(pm_iir & ~dev_priv->pm_rps_events); |
Paulo Zanoni | 60611c1 | 2013-08-15 11:50:01 -0300 | [diff] [blame] | 1150 | |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 1151 | if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost) |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 1152 | return; |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 1153 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 1154 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 1155 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 1156 | pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir); |
| 1157 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 1158 | adj = dev_priv->rps.last_adj; |
Chris Wilson | edcf284 | 2015-04-07 16:20:29 +0100 | [diff] [blame] | 1159 | new_delay = dev_priv->rps.cur_freq; |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 1160 | min = dev_priv->rps.min_freq_softlimit; |
| 1161 | max = dev_priv->rps.max_freq_softlimit; |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 1162 | if (client_boost || any_waiters(dev_priv)) |
| 1163 | max = dev_priv->rps.max_freq; |
| 1164 | if (client_boost && new_delay < dev_priv->rps.boost_freq) { |
| 1165 | new_delay = dev_priv->rps.boost_freq; |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 1166 | adj = 0; |
| 1167 | } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) { |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 1168 | if (adj > 0) |
| 1169 | adj *= 2; |
Chris Wilson | edcf284 | 2015-04-07 16:20:29 +0100 | [diff] [blame] | 1170 | else /* CHV needs even encode values */ |
| 1171 | adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1; |
Ville Syrjälä | 7425034 | 2013-06-25 21:38:11 +0300 | [diff] [blame] | 1172 | /* |
| 1173 | * For better performance, jump directly |
| 1174 | * to RPe if we're below it. |
| 1175 | */ |
Chris Wilson | edcf284 | 2015-04-07 16:20:29 +0100 | [diff] [blame] | 1176 | if (new_delay < dev_priv->rps.efficient_freq - adj) { |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 1177 | new_delay = dev_priv->rps.efficient_freq; |
Chris Wilson | edcf284 | 2015-04-07 16:20:29 +0100 | [diff] [blame] | 1178 | adj = 0; |
| 1179 | } |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 1180 | } else if (client_boost || any_waiters(dev_priv)) { |
Chris Wilson | f5a4c67 | 2015-04-27 13:41:23 +0100 | [diff] [blame] | 1181 | adj = 0; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 1182 | } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) { |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 1183 | if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq) |
| 1184 | new_delay = dev_priv->rps.efficient_freq; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 1185 | else |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 1186 | new_delay = dev_priv->rps.min_freq_softlimit; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 1187 | adj = 0; |
| 1188 | } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) { |
| 1189 | if (adj < 0) |
| 1190 | adj *= 2; |
Chris Wilson | edcf284 | 2015-04-07 16:20:29 +0100 | [diff] [blame] | 1191 | else /* CHV needs even encode values */ |
| 1192 | adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 1193 | } else { /* unknown event */ |
Chris Wilson | edcf284 | 2015-04-07 16:20:29 +0100 | [diff] [blame] | 1194 | adj = 0; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 1195 | } |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 1196 | |
Chris Wilson | edcf284 | 2015-04-07 16:20:29 +0100 | [diff] [blame] | 1197 | dev_priv->rps.last_adj = adj; |
| 1198 | |
Ben Widawsky | 7924963 | 2012-09-07 19:43:42 -0700 | [diff] [blame] | 1199 | /* sysfs frequency interfaces may have snuck in while servicing the |
| 1200 | * interrupt |
| 1201 | */ |
Chris Wilson | edcf284 | 2015-04-07 16:20:29 +0100 | [diff] [blame] | 1202 | new_delay += adj; |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 1203 | new_delay = clamp_t(int, new_delay, min, max); |
Deepak S | 2754436 | 2014-01-27 21:35:05 +0530 | [diff] [blame] | 1204 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 1205 | intel_set_rps(dev_priv, new_delay); |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 1206 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 1207 | mutex_unlock(&dev_priv->rps.hw_lock); |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 1208 | } |
| 1209 | |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1210 | |
| 1211 | /** |
| 1212 | * ivybridge_parity_work - Workqueue called when a parity error interrupt |
| 1213 | * occurred. |
| 1214 | * @work: workqueue struct |
| 1215 | * |
| 1216 | * Doesn't actually do anything except notify userspace. As a consequence of |
| 1217 | * this event, userspace should try to remap the bad rows since statistically |
| 1218 | * it is likely the same row is more likely to go bad again. |
| 1219 | */ |
| 1220 | static void ivybridge_parity_work(struct work_struct *work) |
| 1221 | { |
Jani Nikula | 2d1013d | 2014-03-31 14:27:17 +0300 | [diff] [blame] | 1222 | struct drm_i915_private *dev_priv = |
| 1223 | container_of(work, struct drm_i915_private, l3_parity.error_work); |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1224 | u32 error_status, row, bank, subbank; |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1225 | char *parity_event[6]; |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1226 | uint32_t misccpctl; |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1227 | uint8_t slice = 0; |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1228 | |
| 1229 | /* We must turn off DOP level clock gating to access the L3 registers. |
| 1230 | * In order to prevent a get/put style interface, acquire struct mutex |
| 1231 | * any time we access those registers. |
| 1232 | */ |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 1233 | mutex_lock(&dev_priv->drm.struct_mutex); |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1234 | |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1235 | /* If we've screwed up tracking, just let the interrupt fire again */ |
| 1236 | if (WARN_ON(!dev_priv->l3_parity.which_slice)) |
| 1237 | goto out; |
| 1238 | |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1239 | misccpctl = I915_READ(GEN7_MISCCPCTL); |
| 1240 | I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); |
| 1241 | POSTING_READ(GEN7_MISCCPCTL); |
| 1242 | |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1243 | while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1244 | i915_reg_t reg; |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1245 | |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1246 | slice--; |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1247 | if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv))) |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1248 | break; |
| 1249 | |
| 1250 | dev_priv->l3_parity.which_slice &= ~(1<<slice); |
| 1251 | |
Ville Syrjälä | 6fa1c5f | 2015-11-04 23:20:02 +0200 | [diff] [blame] | 1252 | reg = GEN7_L3CDERRST1(slice); |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1253 | |
| 1254 | error_status = I915_READ(reg); |
| 1255 | row = GEN7_PARITY_ERROR_ROW(error_status); |
| 1256 | bank = GEN7_PARITY_ERROR_BANK(error_status); |
| 1257 | subbank = GEN7_PARITY_ERROR_SUBBANK(error_status); |
| 1258 | |
| 1259 | I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE); |
| 1260 | POSTING_READ(reg); |
| 1261 | |
| 1262 | parity_event[0] = I915_L3_PARITY_UEVENT "=1"; |
| 1263 | parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row); |
| 1264 | parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank); |
| 1265 | parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank); |
| 1266 | parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice); |
| 1267 | parity_event[5] = NULL; |
| 1268 | |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 1269 | kobject_uevent_env(&dev_priv->drm.primary->kdev->kobj, |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1270 | KOBJ_CHANGE, parity_event); |
| 1271 | |
| 1272 | DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n", |
| 1273 | slice, row, bank, subbank); |
| 1274 | |
| 1275 | kfree(parity_event[4]); |
| 1276 | kfree(parity_event[3]); |
| 1277 | kfree(parity_event[2]); |
| 1278 | kfree(parity_event[1]); |
| 1279 | } |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1280 | |
| 1281 | I915_WRITE(GEN7_MISCCPCTL, misccpctl); |
| 1282 | |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1283 | out: |
| 1284 | WARN_ON(dev_priv->l3_parity.which_slice); |
Daniel Vetter | 4cb2183 | 2014-09-15 14:55:26 +0200 | [diff] [blame] | 1285 | spin_lock_irq(&dev_priv->irq_lock); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1286 | gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv)); |
Daniel Vetter | 4cb2183 | 2014-09-15 14:55:26 +0200 | [diff] [blame] | 1287 | spin_unlock_irq(&dev_priv->irq_lock); |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1288 | |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 1289 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1290 | } |
| 1291 | |
Ville Syrjälä | 261e40b | 2016-04-13 21:19:57 +0300 | [diff] [blame] | 1292 | static void ivybridge_parity_error_irq_handler(struct drm_i915_private *dev_priv, |
| 1293 | u32 iir) |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1294 | { |
Ville Syrjälä | 261e40b | 2016-04-13 21:19:57 +0300 | [diff] [blame] | 1295 | if (!HAS_L3_DPF(dev_priv)) |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1296 | return; |
| 1297 | |
Daniel Vetter | d0ecd7e | 2013-07-04 23:35:25 +0200 | [diff] [blame] | 1298 | spin_lock(&dev_priv->irq_lock); |
Ville Syrjälä | 261e40b | 2016-04-13 21:19:57 +0300 | [diff] [blame] | 1299 | gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv)); |
Daniel Vetter | d0ecd7e | 2013-07-04 23:35:25 +0200 | [diff] [blame] | 1300 | spin_unlock(&dev_priv->irq_lock); |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1301 | |
Ville Syrjälä | 261e40b | 2016-04-13 21:19:57 +0300 | [diff] [blame] | 1302 | iir &= GT_PARITY_ERROR(dev_priv); |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 1303 | if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1) |
| 1304 | dev_priv->l3_parity.which_slice |= 1 << 1; |
| 1305 | |
| 1306 | if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT) |
| 1307 | dev_priv->l3_parity.which_slice |= 1 << 0; |
| 1308 | |
Daniel Vetter | a4da4fa | 2012-11-02 19:55:07 +0100 | [diff] [blame] | 1309 | queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work); |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1310 | } |
| 1311 | |
Ville Syrjälä | 261e40b | 2016-04-13 21:19:57 +0300 | [diff] [blame] | 1312 | static void ilk_gt_irq_handler(struct drm_i915_private *dev_priv, |
Paulo Zanoni | f1af8fc | 2013-07-12 19:56:30 -0300 | [diff] [blame] | 1313 | u32 gt_iir) |
| 1314 | { |
Chris Wilson | f8973c2 | 2016-07-01 17:23:21 +0100 | [diff] [blame] | 1315 | if (gt_iir & GT_RENDER_USER_INTERRUPT) |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1316 | notify_ring(dev_priv->engine[RCS]); |
Paulo Zanoni | f1af8fc | 2013-07-12 19:56:30 -0300 | [diff] [blame] | 1317 | if (gt_iir & ILK_BSD_USER_INTERRUPT) |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1318 | notify_ring(dev_priv->engine[VCS]); |
Paulo Zanoni | f1af8fc | 2013-07-12 19:56:30 -0300 | [diff] [blame] | 1319 | } |
| 1320 | |
Ville Syrjälä | 261e40b | 2016-04-13 21:19:57 +0300 | [diff] [blame] | 1321 | static void snb_gt_irq_handler(struct drm_i915_private *dev_priv, |
Daniel Vetter | e7b4c6b | 2012-03-30 20:24:35 +0200 | [diff] [blame] | 1322 | u32 gt_iir) |
| 1323 | { |
Chris Wilson | f8973c2 | 2016-07-01 17:23:21 +0100 | [diff] [blame] | 1324 | if (gt_iir & GT_RENDER_USER_INTERRUPT) |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1325 | notify_ring(dev_priv->engine[RCS]); |
Ben Widawsky | cc609d5 | 2013-05-28 19:22:29 -0700 | [diff] [blame] | 1326 | if (gt_iir & GT_BSD_USER_INTERRUPT) |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1327 | notify_ring(dev_priv->engine[VCS]); |
Ben Widawsky | cc609d5 | 2013-05-28 19:22:29 -0700 | [diff] [blame] | 1328 | if (gt_iir & GT_BLT_USER_INTERRUPT) |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1329 | notify_ring(dev_priv->engine[BCS]); |
Daniel Vetter | e7b4c6b | 2012-03-30 20:24:35 +0200 | [diff] [blame] | 1330 | |
Ben Widawsky | cc609d5 | 2013-05-28 19:22:29 -0700 | [diff] [blame] | 1331 | if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT | |
| 1332 | GT_BSD_CS_ERROR_INTERRUPT | |
Daniel Vetter | aaecdf6 | 2014-11-04 15:52:22 +0100 | [diff] [blame] | 1333 | GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) |
| 1334 | DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir); |
Ben Widawsky | e368919 | 2012-05-25 16:56:22 -0700 | [diff] [blame] | 1335 | |
Ville Syrjälä | 261e40b | 2016-04-13 21:19:57 +0300 | [diff] [blame] | 1336 | if (gt_iir & GT_PARITY_ERROR(dev_priv)) |
| 1337 | ivybridge_parity_error_irq_handler(dev_priv, gt_iir); |
Daniel Vetter | e7b4c6b | 2012-03-30 20:24:35 +0200 | [diff] [blame] | 1338 | } |
| 1339 | |
Nick Hoath | fbcc1a0 | 2015-10-20 10:23:52 +0100 | [diff] [blame] | 1340 | static __always_inline void |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1341 | gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir, int test_shift) |
Nick Hoath | fbcc1a0 | 2015-10-20 10:23:52 +0100 | [diff] [blame] | 1342 | { |
| 1343 | if (iir & (GT_RENDER_USER_INTERRUPT << test_shift)) |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1344 | notify_ring(engine); |
Nick Hoath | fbcc1a0 | 2015-10-20 10:23:52 +0100 | [diff] [blame] | 1345 | if (iir & (GT_CONTEXT_SWITCH_INTERRUPT << test_shift)) |
Tvrtko Ursulin | 27af5ee | 2016-04-04 12:11:56 +0100 | [diff] [blame] | 1346 | tasklet_schedule(&engine->irq_tasklet); |
Nick Hoath | fbcc1a0 | 2015-10-20 10:23:52 +0100 | [diff] [blame] | 1347 | } |
| 1348 | |
Ville Syrjälä | e30e251 | 2016-04-13 21:19:58 +0300 | [diff] [blame] | 1349 | static irqreturn_t gen8_gt_irq_ack(struct drm_i915_private *dev_priv, |
| 1350 | u32 master_ctl, |
| 1351 | u32 gt_iir[4]) |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 1352 | { |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 1353 | irqreturn_t ret = IRQ_NONE; |
| 1354 | |
| 1355 | if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) { |
Ville Syrjälä | e30e251 | 2016-04-13 21:19:58 +0300 | [diff] [blame] | 1356 | gt_iir[0] = I915_READ_FW(GEN8_GT_IIR(0)); |
| 1357 | if (gt_iir[0]) { |
| 1358 | I915_WRITE_FW(GEN8_GT_IIR(0), gt_iir[0]); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 1359 | ret = IRQ_HANDLED; |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 1360 | } else |
| 1361 | DRM_ERROR("The master control interrupt lied (GT0)!\n"); |
| 1362 | } |
| 1363 | |
Zhao Yakui | 85f9b5f | 2014-04-17 10:37:38 +0800 | [diff] [blame] | 1364 | if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) { |
Ville Syrjälä | e30e251 | 2016-04-13 21:19:58 +0300 | [diff] [blame] | 1365 | gt_iir[1] = I915_READ_FW(GEN8_GT_IIR(1)); |
| 1366 | if (gt_iir[1]) { |
| 1367 | I915_WRITE_FW(GEN8_GT_IIR(1), gt_iir[1]); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 1368 | ret = IRQ_HANDLED; |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 1369 | } else |
| 1370 | DRM_ERROR("The master control interrupt lied (GT1)!\n"); |
| 1371 | } |
| 1372 | |
Chris Wilson | 74cdb33 | 2015-04-07 16:21:05 +0100 | [diff] [blame] | 1373 | if (master_ctl & GEN8_GT_VECS_IRQ) { |
Ville Syrjälä | e30e251 | 2016-04-13 21:19:58 +0300 | [diff] [blame] | 1374 | gt_iir[3] = I915_READ_FW(GEN8_GT_IIR(3)); |
| 1375 | if (gt_iir[3]) { |
| 1376 | I915_WRITE_FW(GEN8_GT_IIR(3), gt_iir[3]); |
Chris Wilson | 74cdb33 | 2015-04-07 16:21:05 +0100 | [diff] [blame] | 1377 | ret = IRQ_HANDLED; |
Chris Wilson | 74cdb33 | 2015-04-07 16:21:05 +0100 | [diff] [blame] | 1378 | } else |
| 1379 | DRM_ERROR("The master control interrupt lied (GT3)!\n"); |
| 1380 | } |
| 1381 | |
Sagar Arun Kamble | 26705e2 | 2016-10-12 21:54:31 +0530 | [diff] [blame^] | 1382 | if (master_ctl & (GEN8_GT_PM_IRQ | GEN8_GT_GUC_IRQ)) { |
Ville Syrjälä | e30e251 | 2016-04-13 21:19:58 +0300 | [diff] [blame] | 1383 | gt_iir[2] = I915_READ_FW(GEN8_GT_IIR(2)); |
Sagar Arun Kamble | 26705e2 | 2016-10-12 21:54:31 +0530 | [diff] [blame^] | 1384 | if (gt_iir[2] & (dev_priv->pm_rps_events | |
| 1385 | dev_priv->pm_guc_events)) { |
Chris Wilson | cb0d205 | 2015-04-07 16:21:04 +0100 | [diff] [blame] | 1386 | I915_WRITE_FW(GEN8_GT_IIR(2), |
Sagar Arun Kamble | 26705e2 | 2016-10-12 21:54:31 +0530 | [diff] [blame^] | 1387 | gt_iir[2] & (dev_priv->pm_rps_events | |
| 1388 | dev_priv->pm_guc_events)); |
Oscar Mateo | 38cc46d | 2014-06-16 16:10:59 +0100 | [diff] [blame] | 1389 | ret = IRQ_HANDLED; |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 1390 | } else |
| 1391 | DRM_ERROR("The master control interrupt lied (PM)!\n"); |
| 1392 | } |
| 1393 | |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 1394 | return ret; |
| 1395 | } |
| 1396 | |
Ville Syrjälä | e30e251 | 2016-04-13 21:19:58 +0300 | [diff] [blame] | 1397 | static void gen8_gt_irq_handler(struct drm_i915_private *dev_priv, |
| 1398 | u32 gt_iir[4]) |
| 1399 | { |
| 1400 | if (gt_iir[0]) { |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1401 | gen8_cs_irq_handler(dev_priv->engine[RCS], |
Ville Syrjälä | e30e251 | 2016-04-13 21:19:58 +0300 | [diff] [blame] | 1402 | gt_iir[0], GEN8_RCS_IRQ_SHIFT); |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1403 | gen8_cs_irq_handler(dev_priv->engine[BCS], |
Ville Syrjälä | e30e251 | 2016-04-13 21:19:58 +0300 | [diff] [blame] | 1404 | gt_iir[0], GEN8_BCS_IRQ_SHIFT); |
| 1405 | } |
| 1406 | |
| 1407 | if (gt_iir[1]) { |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1408 | gen8_cs_irq_handler(dev_priv->engine[VCS], |
Ville Syrjälä | e30e251 | 2016-04-13 21:19:58 +0300 | [diff] [blame] | 1409 | gt_iir[1], GEN8_VCS1_IRQ_SHIFT); |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1410 | gen8_cs_irq_handler(dev_priv->engine[VCS2], |
Ville Syrjälä | e30e251 | 2016-04-13 21:19:58 +0300 | [diff] [blame] | 1411 | gt_iir[1], GEN8_VCS2_IRQ_SHIFT); |
| 1412 | } |
| 1413 | |
| 1414 | if (gt_iir[3]) |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1415 | gen8_cs_irq_handler(dev_priv->engine[VECS], |
Ville Syrjälä | e30e251 | 2016-04-13 21:19:58 +0300 | [diff] [blame] | 1416 | gt_iir[3], GEN8_VECS_IRQ_SHIFT); |
| 1417 | |
| 1418 | if (gt_iir[2] & dev_priv->pm_rps_events) |
| 1419 | gen6_rps_irq_handler(dev_priv, gt_iir[2]); |
Sagar Arun Kamble | 26705e2 | 2016-10-12 21:54:31 +0530 | [diff] [blame^] | 1420 | |
| 1421 | if (gt_iir[2] & dev_priv->pm_guc_events) |
| 1422 | gen9_guc_irq_handler(dev_priv, gt_iir[2]); |
Ville Syrjälä | e30e251 | 2016-04-13 21:19:58 +0300 | [diff] [blame] | 1423 | } |
| 1424 | |
Imre Deak | 63c88d2 | 2015-07-20 14:43:39 -0700 | [diff] [blame] | 1425 | static bool bxt_port_hotplug_long_detect(enum port port, u32 val) |
| 1426 | { |
| 1427 | switch (port) { |
| 1428 | case PORT_A: |
Ville Syrjälä | 195baa0 | 2015-08-27 23:56:00 +0300 | [diff] [blame] | 1429 | return val & PORTA_HOTPLUG_LONG_DETECT; |
Imre Deak | 63c88d2 | 2015-07-20 14:43:39 -0700 | [diff] [blame] | 1430 | case PORT_B: |
| 1431 | return val & PORTB_HOTPLUG_LONG_DETECT; |
| 1432 | case PORT_C: |
| 1433 | return val & PORTC_HOTPLUG_LONG_DETECT; |
Imre Deak | 63c88d2 | 2015-07-20 14:43:39 -0700 | [diff] [blame] | 1434 | default: |
| 1435 | return false; |
| 1436 | } |
| 1437 | } |
| 1438 | |
Ville Syrjälä | 6dbf30c | 2015-08-27 23:56:02 +0300 | [diff] [blame] | 1439 | static bool spt_port_hotplug2_long_detect(enum port port, u32 val) |
| 1440 | { |
| 1441 | switch (port) { |
| 1442 | case PORT_E: |
| 1443 | return val & PORTE_HOTPLUG_LONG_DETECT; |
| 1444 | default: |
| 1445 | return false; |
| 1446 | } |
| 1447 | } |
| 1448 | |
Ville Syrjälä | 74c0b39 | 2015-08-27 23:56:07 +0300 | [diff] [blame] | 1449 | static bool spt_port_hotplug_long_detect(enum port port, u32 val) |
| 1450 | { |
| 1451 | switch (port) { |
| 1452 | case PORT_A: |
| 1453 | return val & PORTA_HOTPLUG_LONG_DETECT; |
| 1454 | case PORT_B: |
| 1455 | return val & PORTB_HOTPLUG_LONG_DETECT; |
| 1456 | case PORT_C: |
| 1457 | return val & PORTC_HOTPLUG_LONG_DETECT; |
| 1458 | case PORT_D: |
| 1459 | return val & PORTD_HOTPLUG_LONG_DETECT; |
| 1460 | default: |
| 1461 | return false; |
| 1462 | } |
| 1463 | } |
| 1464 | |
Ville Syrjälä | e4ce95a | 2015-08-27 23:56:03 +0300 | [diff] [blame] | 1465 | static bool ilk_port_hotplug_long_detect(enum port port, u32 val) |
| 1466 | { |
| 1467 | switch (port) { |
| 1468 | case PORT_A: |
| 1469 | return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT; |
| 1470 | default: |
| 1471 | return false; |
| 1472 | } |
| 1473 | } |
| 1474 | |
Jani Nikula | 676574d | 2015-05-28 15:43:53 +0300 | [diff] [blame] | 1475 | static bool pch_port_hotplug_long_detect(enum port port, u32 val) |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 1476 | { |
| 1477 | switch (port) { |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 1478 | case PORT_B: |
Jani Nikula | 676574d | 2015-05-28 15:43:53 +0300 | [diff] [blame] | 1479 | return val & PORTB_HOTPLUG_LONG_DETECT; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 1480 | case PORT_C: |
Jani Nikula | 676574d | 2015-05-28 15:43:53 +0300 | [diff] [blame] | 1481 | return val & PORTC_HOTPLUG_LONG_DETECT; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 1482 | case PORT_D: |
Jani Nikula | 676574d | 2015-05-28 15:43:53 +0300 | [diff] [blame] | 1483 | return val & PORTD_HOTPLUG_LONG_DETECT; |
| 1484 | default: |
| 1485 | return false; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 1486 | } |
| 1487 | } |
| 1488 | |
Jani Nikula | 676574d | 2015-05-28 15:43:53 +0300 | [diff] [blame] | 1489 | static bool i9xx_port_hotplug_long_detect(enum port port, u32 val) |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 1490 | { |
| 1491 | switch (port) { |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 1492 | case PORT_B: |
Jani Nikula | 676574d | 2015-05-28 15:43:53 +0300 | [diff] [blame] | 1493 | return val & PORTB_HOTPLUG_INT_LONG_PULSE; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 1494 | case PORT_C: |
Jani Nikula | 676574d | 2015-05-28 15:43:53 +0300 | [diff] [blame] | 1495 | return val & PORTC_HOTPLUG_INT_LONG_PULSE; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 1496 | case PORT_D: |
Jani Nikula | 676574d | 2015-05-28 15:43:53 +0300 | [diff] [blame] | 1497 | return val & PORTD_HOTPLUG_INT_LONG_PULSE; |
| 1498 | default: |
| 1499 | return false; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 1500 | } |
| 1501 | } |
| 1502 | |
Ville Syrjälä | 42db67d | 2015-08-28 21:26:27 +0300 | [diff] [blame] | 1503 | /* |
| 1504 | * Get a bit mask of pins that have triggered, and which ones may be long. |
| 1505 | * This can be called multiple times with the same masks to accumulate |
| 1506 | * hotplug detection results from several registers. |
| 1507 | * |
| 1508 | * Note that the caller is expected to zero out the masks initially. |
| 1509 | */ |
Imre Deak | fd63e2a | 2015-07-21 15:32:44 -0700 | [diff] [blame] | 1510 | static void intel_get_hpd_pins(u32 *pin_mask, u32 *long_mask, |
Jani Nikula | 8c841e5 | 2015-06-18 13:06:17 +0300 | [diff] [blame] | 1511 | u32 hotplug_trigger, u32 dig_hotplug_reg, |
Imre Deak | fd63e2a | 2015-07-21 15:32:44 -0700 | [diff] [blame] | 1512 | const u32 hpd[HPD_NUM_PINS], |
| 1513 | bool long_pulse_detect(enum port port, u32 val)) |
Jani Nikula | 676574d | 2015-05-28 15:43:53 +0300 | [diff] [blame] | 1514 | { |
Jani Nikula | 8c841e5 | 2015-06-18 13:06:17 +0300 | [diff] [blame] | 1515 | enum port port; |
Jani Nikula | 676574d | 2015-05-28 15:43:53 +0300 | [diff] [blame] | 1516 | int i; |
| 1517 | |
Jani Nikula | 676574d | 2015-05-28 15:43:53 +0300 | [diff] [blame] | 1518 | for_each_hpd_pin(i) { |
Jani Nikula | 8c841e5 | 2015-06-18 13:06:17 +0300 | [diff] [blame] | 1519 | if ((hpd[i] & hotplug_trigger) == 0) |
| 1520 | continue; |
Jani Nikula | 676574d | 2015-05-28 15:43:53 +0300 | [diff] [blame] | 1521 | |
Jani Nikula | 8c841e5 | 2015-06-18 13:06:17 +0300 | [diff] [blame] | 1522 | *pin_mask |= BIT(i); |
| 1523 | |
Imre Deak | cc24fcd | 2015-07-21 15:32:45 -0700 | [diff] [blame] | 1524 | if (!intel_hpd_pin_to_port(i, &port)) |
| 1525 | continue; |
| 1526 | |
Imre Deak | fd63e2a | 2015-07-21 15:32:44 -0700 | [diff] [blame] | 1527 | if (long_pulse_detect(port, dig_hotplug_reg)) |
Jani Nikula | 8c841e5 | 2015-06-18 13:06:17 +0300 | [diff] [blame] | 1528 | *long_mask |= BIT(i); |
Jani Nikula | 676574d | 2015-05-28 15:43:53 +0300 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x\n", |
| 1532 | hotplug_trigger, dig_hotplug_reg, *pin_mask); |
| 1533 | |
| 1534 | } |
| 1535 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1536 | static void gmbus_irq_handler(struct drm_i915_private *dev_priv) |
Daniel Vetter | 515ac2b | 2012-12-01 13:53:44 +0100 | [diff] [blame] | 1537 | { |
Daniel Vetter | 28c70f1 | 2012-12-01 13:53:45 +0100 | [diff] [blame] | 1538 | wake_up_all(&dev_priv->gmbus_wait_queue); |
Daniel Vetter | 515ac2b | 2012-12-01 13:53:44 +0100 | [diff] [blame] | 1539 | } |
| 1540 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1541 | static void dp_aux_irq_handler(struct drm_i915_private *dev_priv) |
Daniel Vetter | ce99c25 | 2012-12-01 13:53:47 +0100 | [diff] [blame] | 1542 | { |
Daniel Vetter | 9ee32fea | 2012-12-01 13:53:48 +0100 | [diff] [blame] | 1543 | wake_up_all(&dev_priv->gmbus_wait_queue); |
Daniel Vetter | ce99c25 | 2012-12-01 13:53:47 +0100 | [diff] [blame] | 1544 | } |
| 1545 | |
Shuang He | 8bf1e9f | 2013-10-15 18:55:27 +0100 | [diff] [blame] | 1546 | #if defined(CONFIG_DEBUG_FS) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1547 | static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, |
| 1548 | enum pipe pipe, |
Daniel Vetter | 277de95 | 2013-10-18 16:37:07 +0200 | [diff] [blame] | 1549 | uint32_t crc0, uint32_t crc1, |
| 1550 | uint32_t crc2, uint32_t crc3, |
| 1551 | uint32_t crc4) |
Shuang He | 8bf1e9f | 2013-10-15 18:55:27 +0100 | [diff] [blame] | 1552 | { |
Shuang He | 8bf1e9f | 2013-10-15 18:55:27 +0100 | [diff] [blame] | 1553 | struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe]; |
| 1554 | struct intel_pipe_crc_entry *entry; |
Damien Lespiau | ac2300d | 2013-10-15 18:55:30 +0100 | [diff] [blame] | 1555 | int head, tail; |
Damien Lespiau | b2c88f5 | 2013-10-15 18:55:29 +0100 | [diff] [blame] | 1556 | |
Damien Lespiau | d538bbd | 2013-10-21 14:29:30 +0100 | [diff] [blame] | 1557 | spin_lock(&pipe_crc->lock); |
| 1558 | |
Damien Lespiau | 0c912c7 | 2013-10-15 18:55:37 +0100 | [diff] [blame] | 1559 | if (!pipe_crc->entries) { |
Damien Lespiau | d538bbd | 2013-10-21 14:29:30 +0100 | [diff] [blame] | 1560 | spin_unlock(&pipe_crc->lock); |
Daniel Vetter | 3427362 | 2014-11-26 16:29:04 +0100 | [diff] [blame] | 1561 | DRM_DEBUG_KMS("spurious interrupt\n"); |
Damien Lespiau | 0c912c7 | 2013-10-15 18:55:37 +0100 | [diff] [blame] | 1562 | return; |
| 1563 | } |
| 1564 | |
Damien Lespiau | d538bbd | 2013-10-21 14:29:30 +0100 | [diff] [blame] | 1565 | head = pipe_crc->head; |
| 1566 | tail = pipe_crc->tail; |
Damien Lespiau | b2c88f5 | 2013-10-15 18:55:29 +0100 | [diff] [blame] | 1567 | |
| 1568 | if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) { |
Damien Lespiau | d538bbd | 2013-10-21 14:29:30 +0100 | [diff] [blame] | 1569 | spin_unlock(&pipe_crc->lock); |
Damien Lespiau | b2c88f5 | 2013-10-15 18:55:29 +0100 | [diff] [blame] | 1570 | DRM_ERROR("CRC buffer overflowing\n"); |
| 1571 | return; |
| 1572 | } |
| 1573 | |
| 1574 | entry = &pipe_crc->entries[head]; |
Shuang He | 8bf1e9f | 2013-10-15 18:55:27 +0100 | [diff] [blame] | 1575 | |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 1576 | entry->frame = dev_priv->drm.driver->get_vblank_counter(&dev_priv->drm, |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1577 | pipe); |
Daniel Vetter | eba94eb | 2013-10-16 22:55:46 +0200 | [diff] [blame] | 1578 | entry->crc[0] = crc0; |
| 1579 | entry->crc[1] = crc1; |
| 1580 | entry->crc[2] = crc2; |
| 1581 | entry->crc[3] = crc3; |
| 1582 | entry->crc[4] = crc4; |
Damien Lespiau | b2c88f5 | 2013-10-15 18:55:29 +0100 | [diff] [blame] | 1583 | |
| 1584 | head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1); |
Damien Lespiau | d538bbd | 2013-10-21 14:29:30 +0100 | [diff] [blame] | 1585 | pipe_crc->head = head; |
| 1586 | |
| 1587 | spin_unlock(&pipe_crc->lock); |
Damien Lespiau | 0714442 | 2013-10-15 18:55:40 +0100 | [diff] [blame] | 1588 | |
| 1589 | wake_up_interruptible(&pipe_crc->wq); |
Shuang He | 8bf1e9f | 2013-10-15 18:55:27 +0100 | [diff] [blame] | 1590 | } |
Daniel Vetter | 277de95 | 2013-10-18 16:37:07 +0200 | [diff] [blame] | 1591 | #else |
| 1592 | static inline void |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1593 | display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, |
| 1594 | enum pipe pipe, |
Daniel Vetter | 277de95 | 2013-10-18 16:37:07 +0200 | [diff] [blame] | 1595 | uint32_t crc0, uint32_t crc1, |
| 1596 | uint32_t crc2, uint32_t crc3, |
| 1597 | uint32_t crc4) {} |
| 1598 | #endif |
Daniel Vetter | eba94eb | 2013-10-16 22:55:46 +0200 | [diff] [blame] | 1599 | |
Daniel Vetter | 277de95 | 2013-10-18 16:37:07 +0200 | [diff] [blame] | 1600 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1601 | static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, |
| 1602 | enum pipe pipe) |
Daniel Vetter | 5a69b89 | 2013-10-16 22:55:52 +0200 | [diff] [blame] | 1603 | { |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1604 | display_pipe_crc_irq_handler(dev_priv, pipe, |
Daniel Vetter | 277de95 | 2013-10-18 16:37:07 +0200 | [diff] [blame] | 1605 | I915_READ(PIPE_CRC_RES_1_IVB(pipe)), |
| 1606 | 0, 0, 0, 0); |
Daniel Vetter | 5a69b89 | 2013-10-16 22:55:52 +0200 | [diff] [blame] | 1607 | } |
| 1608 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1609 | static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, |
| 1610 | enum pipe pipe) |
Daniel Vetter | eba94eb | 2013-10-16 22:55:46 +0200 | [diff] [blame] | 1611 | { |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1612 | display_pipe_crc_irq_handler(dev_priv, pipe, |
Daniel Vetter | 277de95 | 2013-10-18 16:37:07 +0200 | [diff] [blame] | 1613 | I915_READ(PIPE_CRC_RES_1_IVB(pipe)), |
| 1614 | I915_READ(PIPE_CRC_RES_2_IVB(pipe)), |
| 1615 | I915_READ(PIPE_CRC_RES_3_IVB(pipe)), |
| 1616 | I915_READ(PIPE_CRC_RES_4_IVB(pipe)), |
| 1617 | I915_READ(PIPE_CRC_RES_5_IVB(pipe))); |
Daniel Vetter | eba94eb | 2013-10-16 22:55:46 +0200 | [diff] [blame] | 1618 | } |
Daniel Vetter | 5b3a856 | 2013-10-16 22:55:48 +0200 | [diff] [blame] | 1619 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1620 | static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, |
| 1621 | enum pipe pipe) |
Daniel Vetter | 5b3a856 | 2013-10-16 22:55:48 +0200 | [diff] [blame] | 1622 | { |
Daniel Vetter | 0b5c5ed | 2013-10-16 22:55:53 +0200 | [diff] [blame] | 1623 | uint32_t res1, res2; |
| 1624 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1625 | if (INTEL_GEN(dev_priv) >= 3) |
Daniel Vetter | 0b5c5ed | 2013-10-16 22:55:53 +0200 | [diff] [blame] | 1626 | res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe)); |
| 1627 | else |
| 1628 | res1 = 0; |
| 1629 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1630 | if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) |
Daniel Vetter | 0b5c5ed | 2013-10-16 22:55:53 +0200 | [diff] [blame] | 1631 | res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe)); |
| 1632 | else |
| 1633 | res2 = 0; |
Daniel Vetter | 5b3a856 | 2013-10-16 22:55:48 +0200 | [diff] [blame] | 1634 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1635 | display_pipe_crc_irq_handler(dev_priv, pipe, |
Daniel Vetter | 277de95 | 2013-10-18 16:37:07 +0200 | [diff] [blame] | 1636 | I915_READ(PIPE_CRC_RES_RED(pipe)), |
| 1637 | I915_READ(PIPE_CRC_RES_GREEN(pipe)), |
| 1638 | I915_READ(PIPE_CRC_RES_BLUE(pipe)), |
| 1639 | res1, res2); |
Daniel Vetter | 5b3a856 | 2013-10-16 22:55:48 +0200 | [diff] [blame] | 1640 | } |
Shuang He | 8bf1e9f | 2013-10-15 18:55:27 +0100 | [diff] [blame] | 1641 | |
Paulo Zanoni | 1403c0d | 2013-08-15 11:51:32 -0300 | [diff] [blame] | 1642 | /* The RPS events need forcewake, so we add them to a work queue and mask their |
| 1643 | * IMR bits until the work is done. Other interrupts can be processed without |
| 1644 | * the work queue. */ |
| 1645 | 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] | 1646 | { |
Deepak S | a6706b4 | 2014-03-15 20:23:22 +0530 | [diff] [blame] | 1647 | if (pm_iir & dev_priv->pm_rps_events) { |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 1648 | spin_lock(&dev_priv->irq_lock); |
Akash Goel | f4e9af4 | 2016-10-12 21:54:30 +0530 | [diff] [blame] | 1649 | gen6_mask_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events); |
Imre Deak | d4d70aa | 2014-11-19 15:30:04 +0200 | [diff] [blame] | 1650 | if (dev_priv->rps.interrupts_enabled) { |
| 1651 | dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events; |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 1652 | schedule_work(&dev_priv->rps.work); |
Imre Deak | d4d70aa | 2014-11-19 15:30:04 +0200 | [diff] [blame] | 1653 | } |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 1654 | spin_unlock(&dev_priv->irq_lock); |
Ben Widawsky | baf02a1 | 2013-05-28 19:22:24 -0700 | [diff] [blame] | 1655 | } |
Ben Widawsky | baf02a1 | 2013-05-28 19:22:24 -0700 | [diff] [blame] | 1656 | |
Imre Deak | c9a9a26 | 2014-11-05 20:48:37 +0200 | [diff] [blame] | 1657 | if (INTEL_INFO(dev_priv)->gen >= 8) |
| 1658 | return; |
| 1659 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1660 | if (HAS_VEBOX(dev_priv)) { |
Paulo Zanoni | 1403c0d | 2013-08-15 11:51:32 -0300 | [diff] [blame] | 1661 | if (pm_iir & PM_VEBOX_USER_INTERRUPT) |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1662 | notify_ring(dev_priv->engine[VECS]); |
Ben Widawsky | 12638c5 | 2013-05-28 19:22:31 -0700 | [diff] [blame] | 1663 | |
Daniel Vetter | aaecdf6 | 2014-11-04 15:52:22 +0100 | [diff] [blame] | 1664 | if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) |
| 1665 | DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir); |
Ben Widawsky | 12638c5 | 2013-05-28 19:22:31 -0700 | [diff] [blame] | 1666 | } |
Ben Widawsky | baf02a1 | 2013-05-28 19:22:24 -0700 | [diff] [blame] | 1667 | } |
| 1668 | |
Sagar Arun Kamble | 26705e2 | 2016-10-12 21:54:31 +0530 | [diff] [blame^] | 1669 | static void gen9_guc_irq_handler(struct drm_i915_private *dev_priv, u32 gt_iir) |
| 1670 | { |
| 1671 | if (gt_iir & GEN9_GUC_TO_HOST_INT_EVENT) { |
| 1672 | /* TODO: Handle events for which GuC interrupted host */ |
| 1673 | } |
| 1674 | } |
| 1675 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 1676 | static bool intel_pipe_handle_vblank(struct drm_i915_private *dev_priv, |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1677 | enum pipe pipe) |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 1678 | { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 1679 | bool ret; |
| 1680 | |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 1681 | ret = drm_handle_vblank(&dev_priv->drm, pipe); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 1682 | if (ret) |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 1683 | intel_finish_page_flip_mmio(dev_priv, pipe); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 1684 | |
| 1685 | return ret; |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 1686 | } |
| 1687 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1688 | static void valleyview_pipestat_irq_ack(struct drm_i915_private *dev_priv, |
| 1689 | u32 iir, u32 pipe_stats[I915_MAX_PIPES]) |
Imre Deak | c1874ed | 2014-02-04 21:35:46 +0200 | [diff] [blame] | 1690 | { |
Imre Deak | c1874ed | 2014-02-04 21:35:46 +0200 | [diff] [blame] | 1691 | int pipe; |
| 1692 | |
Imre Deak | 58ead0d | 2014-02-04 21:35:47 +0200 | [diff] [blame] | 1693 | spin_lock(&dev_priv->irq_lock); |
Ville Syrjälä | 1ca993d | 2016-02-18 21:54:26 +0200 | [diff] [blame] | 1694 | |
| 1695 | if (!dev_priv->display_irqs_enabled) { |
| 1696 | spin_unlock(&dev_priv->irq_lock); |
| 1697 | return; |
| 1698 | } |
| 1699 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 1700 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1701 | i915_reg_t reg; |
Daniel Vetter | bbb5eeb | 2014-02-12 17:55:36 +0100 | [diff] [blame] | 1702 | u32 mask, iir_bit = 0; |
Imre Deak | 91d181d | 2014-02-10 18:42:49 +0200 | [diff] [blame] | 1703 | |
Daniel Vetter | bbb5eeb | 2014-02-12 17:55:36 +0100 | [diff] [blame] | 1704 | /* |
| 1705 | * PIPESTAT bits get signalled even when the interrupt is |
| 1706 | * disabled with the mask bits, and some of the status bits do |
| 1707 | * not generate interrupts at all (like the underrun bit). Hence |
| 1708 | * we need to be careful that we only handle what we want to |
| 1709 | * handle. |
| 1710 | */ |
Daniel Vetter | 0f239f4 | 2014-09-30 10:56:49 +0200 | [diff] [blame] | 1711 | |
| 1712 | /* fifo underruns are filterered in the underrun handler. */ |
| 1713 | mask = PIPE_FIFO_UNDERRUN_STATUS; |
Daniel Vetter | bbb5eeb | 2014-02-12 17:55:36 +0100 | [diff] [blame] | 1714 | |
| 1715 | switch (pipe) { |
| 1716 | case PIPE_A: |
| 1717 | iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT; |
| 1718 | break; |
| 1719 | case PIPE_B: |
| 1720 | iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT; |
| 1721 | break; |
Ville Syrjälä | 3278f67 | 2014-04-09 13:28:49 +0300 | [diff] [blame] | 1722 | case PIPE_C: |
| 1723 | iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT; |
| 1724 | break; |
Daniel Vetter | bbb5eeb | 2014-02-12 17:55:36 +0100 | [diff] [blame] | 1725 | } |
| 1726 | if (iir & iir_bit) |
| 1727 | mask |= dev_priv->pipestat_irq_mask[pipe]; |
| 1728 | |
| 1729 | if (!mask) |
Imre Deak | 91d181d | 2014-02-10 18:42:49 +0200 | [diff] [blame] | 1730 | continue; |
| 1731 | |
| 1732 | reg = PIPESTAT(pipe); |
Daniel Vetter | bbb5eeb | 2014-02-12 17:55:36 +0100 | [diff] [blame] | 1733 | mask |= PIPESTAT_INT_ENABLE_MASK; |
| 1734 | pipe_stats[pipe] = I915_READ(reg) & mask; |
Imre Deak | c1874ed | 2014-02-04 21:35:46 +0200 | [diff] [blame] | 1735 | |
| 1736 | /* |
| 1737 | * Clear the PIPE*STAT regs before the IIR |
| 1738 | */ |
Imre Deak | 91d181d | 2014-02-10 18:42:49 +0200 | [diff] [blame] | 1739 | if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS | |
| 1740 | PIPESTAT_INT_STATUS_MASK)) |
Imre Deak | c1874ed | 2014-02-04 21:35:46 +0200 | [diff] [blame] | 1741 | I915_WRITE(reg, pipe_stats[pipe]); |
| 1742 | } |
Imre Deak | 58ead0d | 2014-02-04 21:35:47 +0200 | [diff] [blame] | 1743 | spin_unlock(&dev_priv->irq_lock); |
Ville Syrjälä | 2ecb8ca | 2016-04-13 21:19:55 +0300 | [diff] [blame] | 1744 | } |
| 1745 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1746 | static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 2ecb8ca | 2016-04-13 21:19:55 +0300 | [diff] [blame] | 1747 | u32 pipe_stats[I915_MAX_PIPES]) |
| 1748 | { |
Ville Syrjälä | 2ecb8ca | 2016-04-13 21:19:55 +0300 | [diff] [blame] | 1749 | enum pipe pipe; |
Imre Deak | c1874ed | 2014-02-04 21:35:46 +0200 | [diff] [blame] | 1750 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 1751 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 1752 | if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS && |
| 1753 | intel_pipe_handle_vblank(dev_priv, pipe)) |
| 1754 | intel_check_page_flip(dev_priv, pipe); |
Imre Deak | c1874ed | 2014-02-04 21:35:46 +0200 | [diff] [blame] | 1755 | |
Maarten Lankhorst | 5251f04 | 2016-05-17 15:07:47 +0200 | [diff] [blame] | 1756 | if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 1757 | intel_finish_page_flip_cs(dev_priv, pipe); |
Imre Deak | c1874ed | 2014-02-04 21:35:46 +0200 | [diff] [blame] | 1758 | |
| 1759 | if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1760 | i9xx_pipe_crc_irq_handler(dev_priv, pipe); |
Imre Deak | c1874ed | 2014-02-04 21:35:46 +0200 | [diff] [blame] | 1761 | |
Daniel Vetter | 1f7247c | 2014-09-30 10:56:48 +0200 | [diff] [blame] | 1762 | if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) |
| 1763 | intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); |
Imre Deak | c1874ed | 2014-02-04 21:35:46 +0200 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1767 | gmbus_irq_handler(dev_priv); |
Imre Deak | c1874ed | 2014-02-04 21:35:46 +0200 | [diff] [blame] | 1768 | } |
| 1769 | |
Ville Syrjälä | 1ae3c34 | 2016-04-13 21:19:54 +0300 | [diff] [blame] | 1770 | static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 16c6c56 | 2014-04-01 10:54:36 +0300 | [diff] [blame] | 1771 | { |
Ville Syrjälä | 16c6c56 | 2014-04-01 10:54:36 +0300 | [diff] [blame] | 1772 | u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); |
Ville Syrjälä | 1ae3c34 | 2016-04-13 21:19:54 +0300 | [diff] [blame] | 1773 | |
| 1774 | if (hotplug_status) |
| 1775 | I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); |
| 1776 | |
| 1777 | return hotplug_status; |
| 1778 | } |
| 1779 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1780 | static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 1ae3c34 | 2016-04-13 21:19:54 +0300 | [diff] [blame] | 1781 | u32 hotplug_status) |
| 1782 | { |
Ville Syrjälä | 42db67d | 2015-08-28 21:26:27 +0300 | [diff] [blame] | 1783 | u32 pin_mask = 0, long_mask = 0; |
Ville Syrjälä | 16c6c56 | 2014-04-01 10:54:36 +0300 | [diff] [blame] | 1784 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1785 | if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 1786 | IS_CHERRYVIEW(dev_priv)) { |
Jani Nikula | 0d2e429 | 2015-05-27 15:03:39 +0300 | [diff] [blame] | 1787 | u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X; |
Oscar Mateo | 3ff60f8 | 2014-06-16 16:10:58 +0100 | [diff] [blame] | 1788 | |
Ville Syrjälä | 58f2cf2 | 2015-08-28 22:59:08 +0300 | [diff] [blame] | 1789 | if (hotplug_trigger) { |
| 1790 | intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger, |
| 1791 | hotplug_trigger, hpd_status_g4x, |
| 1792 | i9xx_port_hotplug_long_detect); |
| 1793 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1794 | intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); |
Ville Syrjälä | 58f2cf2 | 2015-08-28 22:59:08 +0300 | [diff] [blame] | 1795 | } |
Jani Nikula | 369712e | 2015-05-27 15:03:40 +0300 | [diff] [blame] | 1796 | |
| 1797 | if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1798 | dp_aux_irq_handler(dev_priv); |
Jani Nikula | 0d2e429 | 2015-05-27 15:03:39 +0300 | [diff] [blame] | 1799 | } else { |
| 1800 | u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915; |
Oscar Mateo | 3ff60f8 | 2014-06-16 16:10:58 +0100 | [diff] [blame] | 1801 | |
Ville Syrjälä | 58f2cf2 | 2015-08-28 22:59:08 +0300 | [diff] [blame] | 1802 | if (hotplug_trigger) { |
| 1803 | intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger, |
Daniel Vetter | 44cc6c0 | 2015-09-30 08:47:41 +0200 | [diff] [blame] | 1804 | hotplug_trigger, hpd_status_i915, |
Ville Syrjälä | 58f2cf2 | 2015-08-28 22:59:08 +0300 | [diff] [blame] | 1805 | i9xx_port_hotplug_long_detect); |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1806 | intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); |
Ville Syrjälä | 58f2cf2 | 2015-08-28 22:59:08 +0300 | [diff] [blame] | 1807 | } |
Ville Syrjälä | 16c6c56 | 2014-04-01 10:54:36 +0300 | [diff] [blame] | 1808 | } |
Ville Syrjälä | 16c6c56 | 2014-04-01 10:54:36 +0300 | [diff] [blame] | 1809 | } |
| 1810 | |
Daniel Vetter | ff1f525 | 2012-10-02 15:10:55 +0200 | [diff] [blame] | 1811 | static irqreturn_t valleyview_irq_handler(int irq, void *arg) |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 1812 | { |
Daniel Vetter | 45a83f8 | 2014-05-12 19:17:55 +0200 | [diff] [blame] | 1813 | struct drm_device *dev = arg; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1814 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 1815 | irqreturn_t ret = IRQ_NONE; |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 1816 | |
Imre Deak | 2dd2a88 | 2015-02-24 11:14:30 +0200 | [diff] [blame] | 1817 | if (!intel_irqs_enabled(dev_priv)) |
| 1818 | return IRQ_NONE; |
| 1819 | |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1820 | /* IRQs are synced during runtime_suspend, we don't require a wakeref */ |
| 1821 | disable_rpm_wakeref_asserts(dev_priv); |
| 1822 | |
Ville Syrjälä | 1e1cace | 2016-04-13 21:19:52 +0300 | [diff] [blame] | 1823 | do { |
Ville Syrjälä | 6e81480 | 2016-04-13 21:19:53 +0300 | [diff] [blame] | 1824 | u32 iir, gt_iir, pm_iir; |
Ville Syrjälä | 2ecb8ca | 2016-04-13 21:19:55 +0300 | [diff] [blame] | 1825 | u32 pipe_stats[I915_MAX_PIPES] = {}; |
Ville Syrjälä | 1ae3c34 | 2016-04-13 21:19:54 +0300 | [diff] [blame] | 1826 | u32 hotplug_status = 0; |
Ville Syrjälä | a5e485a | 2016-04-13 21:19:51 +0300 | [diff] [blame] | 1827 | u32 ier = 0; |
Oscar Mateo | 3ff60f8 | 2014-06-16 16:10:58 +0100 | [diff] [blame] | 1828 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 1829 | gt_iir = I915_READ(GTIIR); |
| 1830 | pm_iir = I915_READ(GEN6_PMIIR); |
Oscar Mateo | 3ff60f8 | 2014-06-16 16:10:58 +0100 | [diff] [blame] | 1831 | iir = I915_READ(VLV_IIR); |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 1832 | |
| 1833 | if (gt_iir == 0 && pm_iir == 0 && iir == 0) |
Ville Syrjälä | 1e1cace | 2016-04-13 21:19:52 +0300 | [diff] [blame] | 1834 | break; |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 1835 | |
| 1836 | ret = IRQ_HANDLED; |
| 1837 | |
Ville Syrjälä | a5e485a | 2016-04-13 21:19:51 +0300 | [diff] [blame] | 1838 | /* |
| 1839 | * Theory on interrupt generation, based on empirical evidence: |
| 1840 | * |
| 1841 | * x = ((VLV_IIR & VLV_IER) || |
| 1842 | * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) && |
| 1843 | * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE))); |
| 1844 | * |
| 1845 | * A CPU interrupt will only be raised when 'x' has a 0->1 edge. |
| 1846 | * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to |
| 1847 | * guarantee the CPU interrupt will be raised again even if we |
| 1848 | * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR |
| 1849 | * bits this time around. |
| 1850 | */ |
Ville Syrjälä | 4a0a020 | 2016-04-13 21:19:50 +0300 | [diff] [blame] | 1851 | I915_WRITE(VLV_MASTER_IER, 0); |
Ville Syrjälä | a5e485a | 2016-04-13 21:19:51 +0300 | [diff] [blame] | 1852 | ier = I915_READ(VLV_IER); |
| 1853 | I915_WRITE(VLV_IER, 0); |
Ville Syrjälä | 4a0a020 | 2016-04-13 21:19:50 +0300 | [diff] [blame] | 1854 | |
| 1855 | if (gt_iir) |
| 1856 | I915_WRITE(GTIIR, gt_iir); |
| 1857 | if (pm_iir) |
| 1858 | I915_WRITE(GEN6_PMIIR, pm_iir); |
| 1859 | |
Ville Syrjälä | 7ce4d1f | 2016-04-13 21:19:49 +0300 | [diff] [blame] | 1860 | if (iir & I915_DISPLAY_PORT_INTERRUPT) |
Ville Syrjälä | 1ae3c34 | 2016-04-13 21:19:54 +0300 | [diff] [blame] | 1861 | hotplug_status = i9xx_hpd_irq_ack(dev_priv); |
Ville Syrjälä | 7ce4d1f | 2016-04-13 21:19:49 +0300 | [diff] [blame] | 1862 | |
Oscar Mateo | 3ff60f8 | 2014-06-16 16:10:58 +0100 | [diff] [blame] | 1863 | /* Call regardless, as some status bits might not be |
| 1864 | * signalled in iir */ |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1865 | valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats); |
Ville Syrjälä | 7ce4d1f | 2016-04-13 21:19:49 +0300 | [diff] [blame] | 1866 | |
| 1867 | /* |
| 1868 | * VLV_IIR is single buffered, and reflects the level |
| 1869 | * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last. |
| 1870 | */ |
| 1871 | if (iir) |
| 1872 | I915_WRITE(VLV_IIR, iir); |
Ville Syrjälä | 4a0a020 | 2016-04-13 21:19:50 +0300 | [diff] [blame] | 1873 | |
Ville Syrjälä | a5e485a | 2016-04-13 21:19:51 +0300 | [diff] [blame] | 1874 | I915_WRITE(VLV_IER, ier); |
Ville Syrjälä | 4a0a020 | 2016-04-13 21:19:50 +0300 | [diff] [blame] | 1875 | I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE); |
| 1876 | POSTING_READ(VLV_MASTER_IER); |
Ville Syrjälä | 1ae3c34 | 2016-04-13 21:19:54 +0300 | [diff] [blame] | 1877 | |
Ville Syrjälä | 5289487 | 2016-04-13 21:19:56 +0300 | [diff] [blame] | 1878 | if (gt_iir) |
Ville Syrjälä | 261e40b | 2016-04-13 21:19:57 +0300 | [diff] [blame] | 1879 | snb_gt_irq_handler(dev_priv, gt_iir); |
Ville Syrjälä | 5289487 | 2016-04-13 21:19:56 +0300 | [diff] [blame] | 1880 | if (pm_iir) |
| 1881 | gen6_rps_irq_handler(dev_priv, pm_iir); |
| 1882 | |
Ville Syrjälä | 1ae3c34 | 2016-04-13 21:19:54 +0300 | [diff] [blame] | 1883 | if (hotplug_status) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1884 | i9xx_hpd_irq_handler(dev_priv, hotplug_status); |
Ville Syrjälä | 2ecb8ca | 2016-04-13 21:19:55 +0300 | [diff] [blame] | 1885 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1886 | valleyview_pipestat_irq_handler(dev_priv, pipe_stats); |
Ville Syrjälä | 1e1cace | 2016-04-13 21:19:52 +0300 | [diff] [blame] | 1887 | } while (0); |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 1888 | |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1889 | enable_rpm_wakeref_asserts(dev_priv); |
| 1890 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 1891 | return ret; |
| 1892 | } |
| 1893 | |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 1894 | static irqreturn_t cherryview_irq_handler(int irq, void *arg) |
| 1895 | { |
Daniel Vetter | 45a83f8 | 2014-05-12 19:17:55 +0200 | [diff] [blame] | 1896 | struct drm_device *dev = arg; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1897 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 1898 | irqreturn_t ret = IRQ_NONE; |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 1899 | |
Imre Deak | 2dd2a88 | 2015-02-24 11:14:30 +0200 | [diff] [blame] | 1900 | if (!intel_irqs_enabled(dev_priv)) |
| 1901 | return IRQ_NONE; |
| 1902 | |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1903 | /* IRQs are synced during runtime_suspend, we don't require a wakeref */ |
| 1904 | disable_rpm_wakeref_asserts(dev_priv); |
| 1905 | |
Chris Wilson | 579de73 | 2016-03-14 09:01:57 +0000 | [diff] [blame] | 1906 | do { |
Ville Syrjälä | 6e81480 | 2016-04-13 21:19:53 +0300 | [diff] [blame] | 1907 | u32 master_ctl, iir; |
Ville Syrjälä | e30e251 | 2016-04-13 21:19:58 +0300 | [diff] [blame] | 1908 | u32 gt_iir[4] = {}; |
Ville Syrjälä | 2ecb8ca | 2016-04-13 21:19:55 +0300 | [diff] [blame] | 1909 | u32 pipe_stats[I915_MAX_PIPES] = {}; |
Ville Syrjälä | 1ae3c34 | 2016-04-13 21:19:54 +0300 | [diff] [blame] | 1910 | u32 hotplug_status = 0; |
Ville Syrjälä | a5e485a | 2016-04-13 21:19:51 +0300 | [diff] [blame] | 1911 | u32 ier = 0; |
| 1912 | |
Ville Syrjälä | 8e5fd59 | 2014-04-09 13:28:50 +0300 | [diff] [blame] | 1913 | master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL; |
| 1914 | iir = I915_READ(VLV_IIR); |
Ville Syrjälä | 3278f67 | 2014-04-09 13:28:49 +0300 | [diff] [blame] | 1915 | |
Ville Syrjälä | 8e5fd59 | 2014-04-09 13:28:50 +0300 | [diff] [blame] | 1916 | if (master_ctl == 0 && iir == 0) |
| 1917 | break; |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 1918 | |
Oscar Mateo | 27b6c12 | 2014-06-16 16:11:00 +0100 | [diff] [blame] | 1919 | ret = IRQ_HANDLED; |
| 1920 | |
Ville Syrjälä | a5e485a | 2016-04-13 21:19:51 +0300 | [diff] [blame] | 1921 | /* |
| 1922 | * Theory on interrupt generation, based on empirical evidence: |
| 1923 | * |
| 1924 | * x = ((VLV_IIR & VLV_IER) || |
| 1925 | * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) && |
| 1926 | * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL))); |
| 1927 | * |
| 1928 | * A CPU interrupt will only be raised when 'x' has a 0->1 edge. |
| 1929 | * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to |
| 1930 | * guarantee the CPU interrupt will be raised again even if we |
| 1931 | * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL |
| 1932 | * bits this time around. |
| 1933 | */ |
Ville Syrjälä | 8e5fd59 | 2014-04-09 13:28:50 +0300 | [diff] [blame] | 1934 | I915_WRITE(GEN8_MASTER_IRQ, 0); |
Ville Syrjälä | a5e485a | 2016-04-13 21:19:51 +0300 | [diff] [blame] | 1935 | ier = I915_READ(VLV_IER); |
| 1936 | I915_WRITE(VLV_IER, 0); |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 1937 | |
Ville Syrjälä | e30e251 | 2016-04-13 21:19:58 +0300 | [diff] [blame] | 1938 | gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir); |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 1939 | |
Ville Syrjälä | 7ce4d1f | 2016-04-13 21:19:49 +0300 | [diff] [blame] | 1940 | if (iir & I915_DISPLAY_PORT_INTERRUPT) |
Ville Syrjälä | 1ae3c34 | 2016-04-13 21:19:54 +0300 | [diff] [blame] | 1941 | hotplug_status = i9xx_hpd_irq_ack(dev_priv); |
Ville Syrjälä | 7ce4d1f | 2016-04-13 21:19:49 +0300 | [diff] [blame] | 1942 | |
Oscar Mateo | 27b6c12 | 2014-06-16 16:11:00 +0100 | [diff] [blame] | 1943 | /* Call regardless, as some status bits might not be |
| 1944 | * signalled in iir */ |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1945 | valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats); |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 1946 | |
Ville Syrjälä | 7ce4d1f | 2016-04-13 21:19:49 +0300 | [diff] [blame] | 1947 | /* |
| 1948 | * VLV_IIR is single buffered, and reflects the level |
| 1949 | * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last. |
| 1950 | */ |
| 1951 | if (iir) |
| 1952 | I915_WRITE(VLV_IIR, iir); |
| 1953 | |
Ville Syrjälä | a5e485a | 2016-04-13 21:19:51 +0300 | [diff] [blame] | 1954 | I915_WRITE(VLV_IER, ier); |
Ville Syrjälä | e5328c4 | 2016-04-13 21:19:47 +0300 | [diff] [blame] | 1955 | I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); |
Ville Syrjälä | 8e5fd59 | 2014-04-09 13:28:50 +0300 | [diff] [blame] | 1956 | POSTING_READ(GEN8_MASTER_IRQ); |
Ville Syrjälä | 1ae3c34 | 2016-04-13 21:19:54 +0300 | [diff] [blame] | 1957 | |
Ville Syrjälä | e30e251 | 2016-04-13 21:19:58 +0300 | [diff] [blame] | 1958 | gen8_gt_irq_handler(dev_priv, gt_iir); |
| 1959 | |
Ville Syrjälä | 1ae3c34 | 2016-04-13 21:19:54 +0300 | [diff] [blame] | 1960 | if (hotplug_status) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1961 | i9xx_hpd_irq_handler(dev_priv, hotplug_status); |
Ville Syrjälä | 2ecb8ca | 2016-04-13 21:19:55 +0300 | [diff] [blame] | 1962 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1963 | valleyview_pipestat_irq_handler(dev_priv, pipe_stats); |
Chris Wilson | 579de73 | 2016-03-14 09:01:57 +0000 | [diff] [blame] | 1964 | } while (0); |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 1965 | |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1966 | enable_rpm_wakeref_asserts(dev_priv); |
| 1967 | |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 1968 | return ret; |
| 1969 | } |
| 1970 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1971 | static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv, |
| 1972 | u32 hotplug_trigger, |
Ville Syrjälä | 40e5641 | 2015-08-27 23:56:10 +0300 | [diff] [blame] | 1973 | const u32 hpd[HPD_NUM_PINS]) |
| 1974 | { |
Ville Syrjälä | 40e5641 | 2015-08-27 23:56:10 +0300 | [diff] [blame] | 1975 | u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0; |
| 1976 | |
Jani Nikula | 6a39d7c | 2015-11-25 16:47:22 +0200 | [diff] [blame] | 1977 | /* |
| 1978 | * Somehow the PCH doesn't seem to really ack the interrupt to the CPU |
| 1979 | * unless we touch the hotplug register, even if hotplug_trigger is |
| 1980 | * zero. Not acking leads to "The master control interrupt lied (SDE)!" |
| 1981 | * errors. |
| 1982 | */ |
Ville Syrjälä | 40e5641 | 2015-08-27 23:56:10 +0300 | [diff] [blame] | 1983 | dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG); |
Jani Nikula | 6a39d7c | 2015-11-25 16:47:22 +0200 | [diff] [blame] | 1984 | if (!hotplug_trigger) { |
| 1985 | u32 mask = PORTA_HOTPLUG_STATUS_MASK | |
| 1986 | PORTD_HOTPLUG_STATUS_MASK | |
| 1987 | PORTC_HOTPLUG_STATUS_MASK | |
| 1988 | PORTB_HOTPLUG_STATUS_MASK; |
| 1989 | dig_hotplug_reg &= ~mask; |
| 1990 | } |
| 1991 | |
Ville Syrjälä | 40e5641 | 2015-08-27 23:56:10 +0300 | [diff] [blame] | 1992 | I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg); |
Jani Nikula | 6a39d7c | 2015-11-25 16:47:22 +0200 | [diff] [blame] | 1993 | if (!hotplug_trigger) |
| 1994 | return; |
Ville Syrjälä | 40e5641 | 2015-08-27 23:56:10 +0300 | [diff] [blame] | 1995 | |
| 1996 | intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger, |
| 1997 | dig_hotplug_reg, hpd, |
| 1998 | pch_port_hotplug_long_detect); |
| 1999 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2000 | intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); |
Ville Syrjälä | 40e5641 | 2015-08-27 23:56:10 +0300 | [diff] [blame] | 2001 | } |
| 2002 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2003 | static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir) |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 2004 | { |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 2005 | int pipe; |
Egbert Eich | b543fb0 | 2013-04-16 13:36:54 +0200 | [diff] [blame] | 2006 | u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK; |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 2007 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2008 | ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ibx); |
Daniel Vetter | 91d131d | 2013-06-27 17:52:14 +0200 | [diff] [blame] | 2009 | |
Ville Syrjälä | cfc33bf | 2013-04-17 17:48:48 +0300 | [diff] [blame] | 2010 | if (pch_iir & SDE_AUDIO_POWER_MASK) { |
| 2011 | int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >> |
| 2012 | SDE_AUDIO_POWER_SHIFT); |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 2013 | DRM_DEBUG_DRIVER("PCH audio power change on port %d\n", |
Ville Syrjälä | cfc33bf | 2013-04-17 17:48:48 +0300 | [diff] [blame] | 2014 | port_name(port)); |
| 2015 | } |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 2016 | |
Daniel Vetter | ce99c25 | 2012-12-01 13:53:47 +0100 | [diff] [blame] | 2017 | if (pch_iir & SDE_AUX_MASK) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2018 | dp_aux_irq_handler(dev_priv); |
Daniel Vetter | ce99c25 | 2012-12-01 13:53:47 +0100 | [diff] [blame] | 2019 | |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 2020 | if (pch_iir & SDE_GMBUS) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2021 | gmbus_irq_handler(dev_priv); |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 2022 | |
| 2023 | if (pch_iir & SDE_AUDIO_HDCP_MASK) |
| 2024 | DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n"); |
| 2025 | |
| 2026 | if (pch_iir & SDE_AUDIO_TRANS_MASK) |
| 2027 | DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n"); |
| 2028 | |
| 2029 | if (pch_iir & SDE_POISON) |
| 2030 | DRM_ERROR("PCH poison interrupt\n"); |
| 2031 | |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 2032 | if (pch_iir & SDE_FDI_MASK) |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2033 | for_each_pipe(dev_priv, pipe) |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 2034 | DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", |
| 2035 | pipe_name(pipe), |
| 2036 | I915_READ(FDI_RX_IIR(pipe))); |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 2037 | |
| 2038 | if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE)) |
| 2039 | DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n"); |
| 2040 | |
| 2041 | if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR)) |
| 2042 | DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n"); |
| 2043 | |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 2044 | if (pch_iir & SDE_TRANSA_FIFO_UNDER) |
Daniel Vetter | 1f7247c | 2014-09-30 10:56:48 +0200 | [diff] [blame] | 2045 | intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 2046 | |
| 2047 | if (pch_iir & SDE_TRANSB_FIFO_UNDER) |
Daniel Vetter | 1f7247c | 2014-09-30 10:56:48 +0200 | [diff] [blame] | 2048 | intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 2049 | } |
| 2050 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2051 | static void ivb_err_int_handler(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 2052 | { |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 2053 | u32 err_int = I915_READ(GEN7_ERR_INT); |
Daniel Vetter | 5a69b89 | 2013-10-16 22:55:52 +0200 | [diff] [blame] | 2054 | enum pipe pipe; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 2055 | |
Paulo Zanoni | de032bf | 2013-04-12 17:57:58 -0300 | [diff] [blame] | 2056 | if (err_int & ERR_INT_POISON) |
| 2057 | DRM_ERROR("Poison interrupt\n"); |
| 2058 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2059 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 1f7247c | 2014-09-30 10:56:48 +0200 | [diff] [blame] | 2060 | if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) |
| 2061 | intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 2062 | |
Daniel Vetter | 5a69b89 | 2013-10-16 22:55:52 +0200 | [diff] [blame] | 2063 | if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) { |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2064 | if (IS_IVYBRIDGE(dev_priv)) |
| 2065 | ivb_pipe_crc_irq_handler(dev_priv, pipe); |
Daniel Vetter | 5a69b89 | 2013-10-16 22:55:52 +0200 | [diff] [blame] | 2066 | else |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2067 | hsw_pipe_crc_irq_handler(dev_priv, pipe); |
Daniel Vetter | 5a69b89 | 2013-10-16 22:55:52 +0200 | [diff] [blame] | 2068 | } |
| 2069 | } |
Shuang He | 8bf1e9f | 2013-10-15 18:55:27 +0100 | [diff] [blame] | 2070 | |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 2071 | I915_WRITE(GEN7_ERR_INT, err_int); |
| 2072 | } |
| 2073 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2074 | static void cpt_serr_int_handler(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 2075 | { |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 2076 | u32 serr_int = I915_READ(SERR_INT); |
| 2077 | |
Paulo Zanoni | de032bf | 2013-04-12 17:57:58 -0300 | [diff] [blame] | 2078 | if (serr_int & SERR_INT_POISON) |
| 2079 | DRM_ERROR("PCH poison interrupt\n"); |
| 2080 | |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 2081 | if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN) |
Daniel Vetter | 1f7247c | 2014-09-30 10:56:48 +0200 | [diff] [blame] | 2082 | intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 2083 | |
| 2084 | if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN) |
Daniel Vetter | 1f7247c | 2014-09-30 10:56:48 +0200 | [diff] [blame] | 2085 | intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 2086 | |
| 2087 | if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN) |
Daniel Vetter | 1f7247c | 2014-09-30 10:56:48 +0200 | [diff] [blame] | 2088 | intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_C); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 2089 | |
| 2090 | I915_WRITE(SERR_INT, serr_int); |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 2091 | } |
| 2092 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2093 | static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir) |
Adam Jackson | 23e81d6 | 2012-06-06 15:45:44 -0400 | [diff] [blame] | 2094 | { |
Adam Jackson | 23e81d6 | 2012-06-06 15:45:44 -0400 | [diff] [blame] | 2095 | int pipe; |
Ville Syrjälä | 6dbf30c | 2015-08-27 23:56:02 +0300 | [diff] [blame] | 2096 | u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT; |
Adam Jackson | 23e81d6 | 2012-06-06 15:45:44 -0400 | [diff] [blame] | 2097 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2098 | ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_cpt); |
Daniel Vetter | 91d131d | 2013-06-27 17:52:14 +0200 | [diff] [blame] | 2099 | |
Ville Syrjälä | cfc33bf | 2013-04-17 17:48:48 +0300 | [diff] [blame] | 2100 | if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) { |
| 2101 | int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >> |
| 2102 | SDE_AUDIO_POWER_SHIFT_CPT); |
| 2103 | DRM_DEBUG_DRIVER("PCH audio power change on port %c\n", |
| 2104 | port_name(port)); |
| 2105 | } |
Adam Jackson | 23e81d6 | 2012-06-06 15:45:44 -0400 | [diff] [blame] | 2106 | |
| 2107 | if (pch_iir & SDE_AUX_MASK_CPT) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2108 | dp_aux_irq_handler(dev_priv); |
Adam Jackson | 23e81d6 | 2012-06-06 15:45:44 -0400 | [diff] [blame] | 2109 | |
| 2110 | if (pch_iir & SDE_GMBUS_CPT) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2111 | gmbus_irq_handler(dev_priv); |
Adam Jackson | 23e81d6 | 2012-06-06 15:45:44 -0400 | [diff] [blame] | 2112 | |
| 2113 | if (pch_iir & SDE_AUDIO_CP_REQ_CPT) |
| 2114 | DRM_DEBUG_DRIVER("Audio CP request interrupt\n"); |
| 2115 | |
| 2116 | if (pch_iir & SDE_AUDIO_CP_CHG_CPT) |
| 2117 | DRM_DEBUG_DRIVER("Audio CP change interrupt\n"); |
| 2118 | |
| 2119 | if (pch_iir & SDE_FDI_MASK_CPT) |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2120 | for_each_pipe(dev_priv, pipe) |
Adam Jackson | 23e81d6 | 2012-06-06 15:45:44 -0400 | [diff] [blame] | 2121 | DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", |
| 2122 | pipe_name(pipe), |
| 2123 | I915_READ(FDI_RX_IIR(pipe))); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 2124 | |
| 2125 | if (pch_iir & SDE_ERROR_CPT) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2126 | cpt_serr_int_handler(dev_priv); |
Adam Jackson | 23e81d6 | 2012-06-06 15:45:44 -0400 | [diff] [blame] | 2127 | } |
| 2128 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2129 | static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir) |
Ville Syrjälä | 6dbf30c | 2015-08-27 23:56:02 +0300 | [diff] [blame] | 2130 | { |
Ville Syrjälä | 6dbf30c | 2015-08-27 23:56:02 +0300 | [diff] [blame] | 2131 | u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT & |
| 2132 | ~SDE_PORTE_HOTPLUG_SPT; |
| 2133 | u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT; |
| 2134 | u32 pin_mask = 0, long_mask = 0; |
| 2135 | |
| 2136 | if (hotplug_trigger) { |
| 2137 | u32 dig_hotplug_reg; |
| 2138 | |
| 2139 | dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG); |
| 2140 | I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg); |
| 2141 | |
| 2142 | intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger, |
| 2143 | dig_hotplug_reg, hpd_spt, |
Ville Syrjälä | 74c0b39 | 2015-08-27 23:56:07 +0300 | [diff] [blame] | 2144 | spt_port_hotplug_long_detect); |
Ville Syrjälä | 6dbf30c | 2015-08-27 23:56:02 +0300 | [diff] [blame] | 2145 | } |
| 2146 | |
| 2147 | if (hotplug2_trigger) { |
| 2148 | u32 dig_hotplug_reg; |
| 2149 | |
| 2150 | dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2); |
| 2151 | I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg); |
| 2152 | |
| 2153 | intel_get_hpd_pins(&pin_mask, &long_mask, hotplug2_trigger, |
| 2154 | dig_hotplug_reg, hpd_spt, |
| 2155 | spt_port_hotplug2_long_detect); |
| 2156 | } |
| 2157 | |
| 2158 | if (pin_mask) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2159 | intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); |
Ville Syrjälä | 6dbf30c | 2015-08-27 23:56:02 +0300 | [diff] [blame] | 2160 | |
| 2161 | if (pch_iir & SDE_GMBUS_CPT) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2162 | gmbus_irq_handler(dev_priv); |
Ville Syrjälä | 6dbf30c | 2015-08-27 23:56:02 +0300 | [diff] [blame] | 2163 | } |
| 2164 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2165 | static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv, |
| 2166 | u32 hotplug_trigger, |
Ville Syrjälä | 40e5641 | 2015-08-27 23:56:10 +0300 | [diff] [blame] | 2167 | const u32 hpd[HPD_NUM_PINS]) |
| 2168 | { |
Ville Syrjälä | 40e5641 | 2015-08-27 23:56:10 +0300 | [diff] [blame] | 2169 | u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0; |
| 2170 | |
| 2171 | dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL); |
| 2172 | I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg); |
| 2173 | |
| 2174 | intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger, |
| 2175 | dig_hotplug_reg, hpd, |
| 2176 | ilk_port_hotplug_long_detect); |
| 2177 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2178 | intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); |
Ville Syrjälä | 40e5641 | 2015-08-27 23:56:10 +0300 | [diff] [blame] | 2179 | } |
| 2180 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2181 | static void ilk_display_irq_handler(struct drm_i915_private *dev_priv, |
| 2182 | u32 de_iir) |
Paulo Zanoni | c008bc6 | 2013-07-12 16:35:10 -0300 | [diff] [blame] | 2183 | { |
Daniel Vetter | 40da17c2 | 2013-10-21 18:04:36 +0200 | [diff] [blame] | 2184 | enum pipe pipe; |
Ville Syrjälä | e4ce95a | 2015-08-27 23:56:03 +0300 | [diff] [blame] | 2185 | u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG; |
| 2186 | |
Ville Syrjälä | 40e5641 | 2015-08-27 23:56:10 +0300 | [diff] [blame] | 2187 | if (hotplug_trigger) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2188 | ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk); |
Paulo Zanoni | c008bc6 | 2013-07-12 16:35:10 -0300 | [diff] [blame] | 2189 | |
| 2190 | if (de_iir & DE_AUX_CHANNEL_A) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2191 | dp_aux_irq_handler(dev_priv); |
Paulo Zanoni | c008bc6 | 2013-07-12 16:35:10 -0300 | [diff] [blame] | 2192 | |
| 2193 | if (de_iir & DE_GSE) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2194 | intel_opregion_asle_intr(dev_priv); |
Paulo Zanoni | c008bc6 | 2013-07-12 16:35:10 -0300 | [diff] [blame] | 2195 | |
Paulo Zanoni | c008bc6 | 2013-07-12 16:35:10 -0300 | [diff] [blame] | 2196 | if (de_iir & DE_POISON) |
| 2197 | DRM_ERROR("Poison interrupt\n"); |
| 2198 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2199 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 2200 | if (de_iir & DE_PIPE_VBLANK(pipe) && |
| 2201 | intel_pipe_handle_vblank(dev_priv, pipe)) |
| 2202 | intel_check_page_flip(dev_priv, pipe); |
Paulo Zanoni | c008bc6 | 2013-07-12 16:35:10 -0300 | [diff] [blame] | 2203 | |
Daniel Vetter | 40da17c2 | 2013-10-21 18:04:36 +0200 | [diff] [blame] | 2204 | if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe)) |
Daniel Vetter | 1f7247c | 2014-09-30 10:56:48 +0200 | [diff] [blame] | 2205 | intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); |
Paulo Zanoni | c008bc6 | 2013-07-12 16:35:10 -0300 | [diff] [blame] | 2206 | |
Daniel Vetter | 40da17c2 | 2013-10-21 18:04:36 +0200 | [diff] [blame] | 2207 | if (de_iir & DE_PIPE_CRC_DONE(pipe)) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2208 | i9xx_pipe_crc_irq_handler(dev_priv, pipe); |
Daniel Vetter | 5b3a856 | 2013-10-16 22:55:48 +0200 | [diff] [blame] | 2209 | |
Daniel Vetter | 40da17c2 | 2013-10-21 18:04:36 +0200 | [diff] [blame] | 2210 | /* plane/pipes map 1:1 on ilk+ */ |
Maarten Lankhorst | 5251f04 | 2016-05-17 15:07:47 +0200 | [diff] [blame] | 2211 | if (de_iir & DE_PLANE_FLIP_DONE(pipe)) |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 2212 | intel_finish_page_flip_cs(dev_priv, pipe); |
Paulo Zanoni | c008bc6 | 2013-07-12 16:35:10 -0300 | [diff] [blame] | 2213 | } |
| 2214 | |
| 2215 | /* check event from PCH */ |
| 2216 | if (de_iir & DE_PCH_EVENT) { |
| 2217 | u32 pch_iir = I915_READ(SDEIIR); |
| 2218 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2219 | if (HAS_PCH_CPT(dev_priv)) |
| 2220 | cpt_irq_handler(dev_priv, pch_iir); |
Paulo Zanoni | c008bc6 | 2013-07-12 16:35:10 -0300 | [diff] [blame] | 2221 | else |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2222 | ibx_irq_handler(dev_priv, pch_iir); |
Paulo Zanoni | c008bc6 | 2013-07-12 16:35:10 -0300 | [diff] [blame] | 2223 | |
| 2224 | /* should clear PCH hotplug event before clear CPU irq */ |
| 2225 | I915_WRITE(SDEIIR, pch_iir); |
| 2226 | } |
| 2227 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2228 | if (IS_GEN5(dev_priv) && de_iir & DE_PCU_EVENT) |
| 2229 | ironlake_rps_change_irq_handler(dev_priv); |
Paulo Zanoni | c008bc6 | 2013-07-12 16:35:10 -0300 | [diff] [blame] | 2230 | } |
| 2231 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2232 | static void ivb_display_irq_handler(struct drm_i915_private *dev_priv, |
| 2233 | u32 de_iir) |
Paulo Zanoni | 9719fb9 | 2013-07-12 16:35:11 -0300 | [diff] [blame] | 2234 | { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 2235 | enum pipe pipe; |
Ville Syrjälä | 23bb4cb | 2015-08-27 23:56:04 +0300 | [diff] [blame] | 2236 | u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB; |
| 2237 | |
Ville Syrjälä | 40e5641 | 2015-08-27 23:56:10 +0300 | [diff] [blame] | 2238 | if (hotplug_trigger) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2239 | ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb); |
Paulo Zanoni | 9719fb9 | 2013-07-12 16:35:11 -0300 | [diff] [blame] | 2240 | |
| 2241 | if (de_iir & DE_ERR_INT_IVB) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2242 | ivb_err_int_handler(dev_priv); |
Paulo Zanoni | 9719fb9 | 2013-07-12 16:35:11 -0300 | [diff] [blame] | 2243 | |
| 2244 | if (de_iir & DE_AUX_CHANNEL_A_IVB) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2245 | dp_aux_irq_handler(dev_priv); |
Paulo Zanoni | 9719fb9 | 2013-07-12 16:35:11 -0300 | [diff] [blame] | 2246 | |
| 2247 | if (de_iir & DE_GSE_IVB) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2248 | intel_opregion_asle_intr(dev_priv); |
Paulo Zanoni | 9719fb9 | 2013-07-12 16:35:11 -0300 | [diff] [blame] | 2249 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2250 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 2251 | if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)) && |
| 2252 | intel_pipe_handle_vblank(dev_priv, pipe)) |
| 2253 | intel_check_page_flip(dev_priv, pipe); |
Daniel Vetter | 40da17c2 | 2013-10-21 18:04:36 +0200 | [diff] [blame] | 2254 | |
| 2255 | /* plane/pipes map 1:1 on ilk+ */ |
Maarten Lankhorst | 5251f04 | 2016-05-17 15:07:47 +0200 | [diff] [blame] | 2256 | if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 2257 | intel_finish_page_flip_cs(dev_priv, pipe); |
Paulo Zanoni | 9719fb9 | 2013-07-12 16:35:11 -0300 | [diff] [blame] | 2258 | } |
| 2259 | |
| 2260 | /* check event from PCH */ |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2261 | if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) { |
Paulo Zanoni | 9719fb9 | 2013-07-12 16:35:11 -0300 | [diff] [blame] | 2262 | u32 pch_iir = I915_READ(SDEIIR); |
| 2263 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2264 | cpt_irq_handler(dev_priv, pch_iir); |
Paulo Zanoni | 9719fb9 | 2013-07-12 16:35:11 -0300 | [diff] [blame] | 2265 | |
| 2266 | /* clear PCH hotplug event before clear CPU irq */ |
| 2267 | I915_WRITE(SDEIIR, pch_iir); |
| 2268 | } |
| 2269 | } |
| 2270 | |
Oscar Mateo | 72c90f6 | 2014-06-16 16:10:57 +0100 | [diff] [blame] | 2271 | /* |
| 2272 | * To handle irqs with the minimum potential races with fresh interrupts, we: |
| 2273 | * 1 - Disable Master Interrupt Control. |
| 2274 | * 2 - Find the source(s) of the interrupt. |
| 2275 | * 3 - Clear the Interrupt Identity bits (IIR). |
| 2276 | * 4 - Process the interrupt(s) that had bits set in the IIRs. |
| 2277 | * 5 - Re-enable Master Interrupt Control. |
| 2278 | */ |
Paulo Zanoni | f1af8fc | 2013-07-12 19:56:30 -0300 | [diff] [blame] | 2279 | static irqreturn_t ironlake_irq_handler(int irq, void *arg) |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 2280 | { |
Daniel Vetter | 45a83f8 | 2014-05-12 19:17:55 +0200 | [diff] [blame] | 2281 | struct drm_device *dev = arg; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2282 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | f1af8fc | 2013-07-12 19:56:30 -0300 | [diff] [blame] | 2283 | u32 de_iir, gt_iir, de_ier, sde_ier = 0; |
Chris Wilson | 0e43406 | 2012-05-09 21:45:44 +0100 | [diff] [blame] | 2284 | irqreturn_t ret = IRQ_NONE; |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 2285 | |
Imre Deak | 2dd2a88 | 2015-02-24 11:14:30 +0200 | [diff] [blame] | 2286 | if (!intel_irqs_enabled(dev_priv)) |
| 2287 | return IRQ_NONE; |
| 2288 | |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 2289 | /* IRQs are synced during runtime_suspend, we don't require a wakeref */ |
| 2290 | disable_rpm_wakeref_asserts(dev_priv); |
| 2291 | |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 2292 | /* disable master interrupt before clearing iir */ |
| 2293 | de_ier = I915_READ(DEIER); |
| 2294 | I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL); |
Paulo Zanoni | 23a7851 | 2013-07-12 16:35:14 -0300 | [diff] [blame] | 2295 | POSTING_READ(DEIER); |
Chris Wilson | 0e43406 | 2012-05-09 21:45:44 +0100 | [diff] [blame] | 2296 | |
Paulo Zanoni | 44498ae | 2013-02-22 17:05:28 -0300 | [diff] [blame] | 2297 | /* Disable south interrupts. We'll only write to SDEIIR once, so further |
| 2298 | * interrupts will will be stored on its back queue, and then we'll be |
| 2299 | * able to process them after we restore SDEIER (as soon as we restore |
| 2300 | * it, we'll get an interrupt if SDEIIR still has something to process |
| 2301 | * due to its back queue). */ |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2302 | if (!HAS_PCH_NOP(dev_priv)) { |
Ben Widawsky | ab5c608 | 2013-04-05 13:12:41 -0700 | [diff] [blame] | 2303 | sde_ier = I915_READ(SDEIER); |
| 2304 | I915_WRITE(SDEIER, 0); |
| 2305 | POSTING_READ(SDEIER); |
| 2306 | } |
Paulo Zanoni | 44498ae | 2013-02-22 17:05:28 -0300 | [diff] [blame] | 2307 | |
Oscar Mateo | 72c90f6 | 2014-06-16 16:10:57 +0100 | [diff] [blame] | 2308 | /* Find, clear, then process each source of interrupt */ |
| 2309 | |
Chris Wilson | 0e43406 | 2012-05-09 21:45:44 +0100 | [diff] [blame] | 2310 | gt_iir = I915_READ(GTIIR); |
| 2311 | if (gt_iir) { |
Oscar Mateo | 72c90f6 | 2014-06-16 16:10:57 +0100 | [diff] [blame] | 2312 | I915_WRITE(GTIIR, gt_iir); |
| 2313 | ret = IRQ_HANDLED; |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2314 | if (INTEL_GEN(dev_priv) >= 6) |
Ville Syrjälä | 261e40b | 2016-04-13 21:19:57 +0300 | [diff] [blame] | 2315 | snb_gt_irq_handler(dev_priv, gt_iir); |
Paulo Zanoni | d8fc8a4 | 2013-07-19 18:57:55 -0300 | [diff] [blame] | 2316 | else |
Ville Syrjälä | 261e40b | 2016-04-13 21:19:57 +0300 | [diff] [blame] | 2317 | ilk_gt_irq_handler(dev_priv, gt_iir); |
Chris Wilson | 0e43406 | 2012-05-09 21:45:44 +0100 | [diff] [blame] | 2318 | } |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 2319 | |
| 2320 | de_iir = I915_READ(DEIIR); |
Chris Wilson | 0e43406 | 2012-05-09 21:45:44 +0100 | [diff] [blame] | 2321 | if (de_iir) { |
Oscar Mateo | 72c90f6 | 2014-06-16 16:10:57 +0100 | [diff] [blame] | 2322 | I915_WRITE(DEIIR, de_iir); |
| 2323 | ret = IRQ_HANDLED; |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2324 | if (INTEL_GEN(dev_priv) >= 7) |
| 2325 | ivb_display_irq_handler(dev_priv, de_iir); |
Paulo Zanoni | f1af8fc | 2013-07-12 19:56:30 -0300 | [diff] [blame] | 2326 | else |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2327 | ilk_display_irq_handler(dev_priv, de_iir); |
Chris Wilson | 0e43406 | 2012-05-09 21:45:44 +0100 | [diff] [blame] | 2328 | } |
| 2329 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2330 | if (INTEL_GEN(dev_priv) >= 6) { |
Paulo Zanoni | f1af8fc | 2013-07-12 19:56:30 -0300 | [diff] [blame] | 2331 | u32 pm_iir = I915_READ(GEN6_PMIIR); |
| 2332 | if (pm_iir) { |
Paulo Zanoni | f1af8fc | 2013-07-12 19:56:30 -0300 | [diff] [blame] | 2333 | I915_WRITE(GEN6_PMIIR, pm_iir); |
| 2334 | ret = IRQ_HANDLED; |
Oscar Mateo | 72c90f6 | 2014-06-16 16:10:57 +0100 | [diff] [blame] | 2335 | gen6_rps_irq_handler(dev_priv, pm_iir); |
Paulo Zanoni | f1af8fc | 2013-07-12 19:56:30 -0300 | [diff] [blame] | 2336 | } |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 2337 | } |
| 2338 | |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 2339 | I915_WRITE(DEIER, de_ier); |
| 2340 | POSTING_READ(DEIER); |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2341 | if (!HAS_PCH_NOP(dev_priv)) { |
Ben Widawsky | ab5c608 | 2013-04-05 13:12:41 -0700 | [diff] [blame] | 2342 | I915_WRITE(SDEIER, sde_ier); |
| 2343 | POSTING_READ(SDEIER); |
| 2344 | } |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 2345 | |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 2346 | /* IRQs are synced during runtime_suspend, we don't require a wakeref */ |
| 2347 | enable_rpm_wakeref_asserts(dev_priv); |
| 2348 | |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 2349 | return ret; |
| 2350 | } |
| 2351 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2352 | static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv, |
| 2353 | u32 hotplug_trigger, |
Ville Syrjälä | 40e5641 | 2015-08-27 23:56:10 +0300 | [diff] [blame] | 2354 | const u32 hpd[HPD_NUM_PINS]) |
Shashank Sharma | d04a492 | 2014-08-22 17:40:41 +0530 | [diff] [blame] | 2355 | { |
Ville Syrjälä | cebd87a | 2015-08-27 23:56:09 +0300 | [diff] [blame] | 2356 | u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0; |
Shashank Sharma | d04a492 | 2014-08-22 17:40:41 +0530 | [diff] [blame] | 2357 | |
Ville Syrjälä | a52bb15 | 2015-08-27 23:56:11 +0300 | [diff] [blame] | 2358 | dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG); |
| 2359 | I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg); |
Shashank Sharma | d04a492 | 2014-08-22 17:40:41 +0530 | [diff] [blame] | 2360 | |
Ville Syrjälä | cebd87a | 2015-08-27 23:56:09 +0300 | [diff] [blame] | 2361 | intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger, |
Ville Syrjälä | 40e5641 | 2015-08-27 23:56:10 +0300 | [diff] [blame] | 2362 | dig_hotplug_reg, hpd, |
Ville Syrjälä | cebd87a | 2015-08-27 23:56:09 +0300 | [diff] [blame] | 2363 | bxt_port_hotplug_long_detect); |
Ville Syrjälä | 40e5641 | 2015-08-27 23:56:10 +0300 | [diff] [blame] | 2364 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2365 | intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); |
Shashank Sharma | d04a492 | 2014-08-22 17:40:41 +0530 | [diff] [blame] | 2366 | } |
| 2367 | |
Tvrtko Ursulin | f11a0f4 | 2016-01-12 16:04:07 +0000 | [diff] [blame] | 2368 | static irqreturn_t |
| 2369 | gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl) |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2370 | { |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2371 | irqreturn_t ret = IRQ_NONE; |
Tvrtko Ursulin | f11a0f4 | 2016-01-12 16:04:07 +0000 | [diff] [blame] | 2372 | u32 iir; |
Daniel Vetter | c42664c | 2013-11-07 11:05:40 +0100 | [diff] [blame] | 2373 | enum pipe pipe; |
Jesse Barnes | 88e0470 | 2014-11-13 17:51:48 +0000 | [diff] [blame] | 2374 | |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2375 | if (master_ctl & GEN8_DE_MISC_IRQ) { |
Tvrtko Ursulin | e32192e | 2016-01-12 16:04:06 +0000 | [diff] [blame] | 2376 | iir = I915_READ(GEN8_DE_MISC_IIR); |
| 2377 | if (iir) { |
| 2378 | I915_WRITE(GEN8_DE_MISC_IIR, iir); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2379 | ret = IRQ_HANDLED; |
Tvrtko Ursulin | e32192e | 2016-01-12 16:04:06 +0000 | [diff] [blame] | 2380 | if (iir & GEN8_DE_MISC_GSE) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2381 | intel_opregion_asle_intr(dev_priv); |
Oscar Mateo | 38cc46d | 2014-06-16 16:10:59 +0100 | [diff] [blame] | 2382 | else |
| 2383 | DRM_ERROR("Unexpected DE Misc interrupt\n"); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2384 | } |
Oscar Mateo | 38cc46d | 2014-06-16 16:10:59 +0100 | [diff] [blame] | 2385 | else |
| 2386 | DRM_ERROR("The master control interrupt lied (DE MISC)!\n"); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2387 | } |
| 2388 | |
Daniel Vetter | 6d766f0 | 2013-11-07 14:49:55 +0100 | [diff] [blame] | 2389 | if (master_ctl & GEN8_DE_PORT_IRQ) { |
Tvrtko Ursulin | e32192e | 2016-01-12 16:04:06 +0000 | [diff] [blame] | 2390 | iir = I915_READ(GEN8_DE_PORT_IIR); |
| 2391 | if (iir) { |
| 2392 | u32 tmp_mask; |
Shashank Sharma | d04a492 | 2014-08-22 17:40:41 +0530 | [diff] [blame] | 2393 | bool found = false; |
Ville Syrjälä | cebd87a | 2015-08-27 23:56:09 +0300 | [diff] [blame] | 2394 | |
Tvrtko Ursulin | e32192e | 2016-01-12 16:04:06 +0000 | [diff] [blame] | 2395 | I915_WRITE(GEN8_DE_PORT_IIR, iir); |
Daniel Vetter | 6d766f0 | 2013-11-07 14:49:55 +0100 | [diff] [blame] | 2396 | ret = IRQ_HANDLED; |
Jesse Barnes | 88e0470 | 2014-11-13 17:51:48 +0000 | [diff] [blame] | 2397 | |
Tvrtko Ursulin | e32192e | 2016-01-12 16:04:06 +0000 | [diff] [blame] | 2398 | tmp_mask = GEN8_AUX_CHANNEL_A; |
| 2399 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 2400 | tmp_mask |= GEN9_AUX_CHANNEL_B | |
| 2401 | GEN9_AUX_CHANNEL_C | |
| 2402 | GEN9_AUX_CHANNEL_D; |
| 2403 | |
| 2404 | if (iir & tmp_mask) { |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2405 | dp_aux_irq_handler(dev_priv); |
Shashank Sharma | d04a492 | 2014-08-22 17:40:41 +0530 | [diff] [blame] | 2406 | found = true; |
| 2407 | } |
| 2408 | |
Tvrtko Ursulin | e32192e | 2016-01-12 16:04:06 +0000 | [diff] [blame] | 2409 | if (IS_BROXTON(dev_priv)) { |
| 2410 | tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK; |
| 2411 | if (tmp_mask) { |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2412 | bxt_hpd_irq_handler(dev_priv, tmp_mask, |
| 2413 | hpd_bxt); |
Tvrtko Ursulin | e32192e | 2016-01-12 16:04:06 +0000 | [diff] [blame] | 2414 | found = true; |
| 2415 | } |
| 2416 | } else if (IS_BROADWELL(dev_priv)) { |
| 2417 | tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG; |
| 2418 | if (tmp_mask) { |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2419 | ilk_hpd_irq_handler(dev_priv, |
| 2420 | tmp_mask, hpd_bdw); |
Tvrtko Ursulin | e32192e | 2016-01-12 16:04:06 +0000 | [diff] [blame] | 2421 | found = true; |
| 2422 | } |
Shashank Sharma | d04a492 | 2014-08-22 17:40:41 +0530 | [diff] [blame] | 2423 | } |
| 2424 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2425 | if (IS_BROXTON(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) { |
| 2426 | gmbus_irq_handler(dev_priv); |
Shashank Sharma | 9e63743 | 2014-08-22 17:40:43 +0530 | [diff] [blame] | 2427 | found = true; |
| 2428 | } |
| 2429 | |
Shashank Sharma | d04a492 | 2014-08-22 17:40:41 +0530 | [diff] [blame] | 2430 | if (!found) |
Oscar Mateo | 38cc46d | 2014-06-16 16:10:59 +0100 | [diff] [blame] | 2431 | DRM_ERROR("Unexpected DE Port interrupt\n"); |
Daniel Vetter | 6d766f0 | 2013-11-07 14:49:55 +0100 | [diff] [blame] | 2432 | } |
Oscar Mateo | 38cc46d | 2014-06-16 16:10:59 +0100 | [diff] [blame] | 2433 | else |
| 2434 | DRM_ERROR("The master control interrupt lied (DE PORT)!\n"); |
Daniel Vetter | 6d766f0 | 2013-11-07 14:49:55 +0100 | [diff] [blame] | 2435 | } |
| 2436 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2437 | for_each_pipe(dev_priv, pipe) { |
Tvrtko Ursulin | e32192e | 2016-01-12 16:04:06 +0000 | [diff] [blame] | 2438 | u32 flip_done, fault_errors; |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2439 | |
Daniel Vetter | c42664c | 2013-11-07 11:05:40 +0100 | [diff] [blame] | 2440 | if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe))) |
| 2441 | continue; |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2442 | |
Tvrtko Ursulin | e32192e | 2016-01-12 16:04:06 +0000 | [diff] [blame] | 2443 | iir = I915_READ(GEN8_DE_PIPE_IIR(pipe)); |
| 2444 | if (!iir) { |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2445 | DRM_ERROR("The master control interrupt lied (DE PIPE)!\n"); |
Tvrtko Ursulin | e32192e | 2016-01-12 16:04:06 +0000 | [diff] [blame] | 2446 | continue; |
| 2447 | } |
| 2448 | |
| 2449 | ret = IRQ_HANDLED; |
| 2450 | I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir); |
| 2451 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 2452 | if (iir & GEN8_PIPE_VBLANK && |
| 2453 | intel_pipe_handle_vblank(dev_priv, pipe)) |
| 2454 | intel_check_page_flip(dev_priv, pipe); |
Tvrtko Ursulin | e32192e | 2016-01-12 16:04:06 +0000 | [diff] [blame] | 2455 | |
| 2456 | flip_done = iir; |
| 2457 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 2458 | flip_done &= GEN9_PIPE_PLANE1_FLIP_DONE; |
| 2459 | else |
| 2460 | flip_done &= GEN8_PIPE_PRIMARY_FLIP_DONE; |
| 2461 | |
Maarten Lankhorst | 5251f04 | 2016-05-17 15:07:47 +0200 | [diff] [blame] | 2462 | if (flip_done) |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 2463 | intel_finish_page_flip_cs(dev_priv, pipe); |
Tvrtko Ursulin | e32192e | 2016-01-12 16:04:06 +0000 | [diff] [blame] | 2464 | |
| 2465 | if (iir & GEN8_PIPE_CDCLK_CRC_DONE) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2466 | hsw_pipe_crc_irq_handler(dev_priv, pipe); |
Tvrtko Ursulin | e32192e | 2016-01-12 16:04:06 +0000 | [diff] [blame] | 2467 | |
| 2468 | if (iir & GEN8_PIPE_FIFO_UNDERRUN) |
| 2469 | intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); |
| 2470 | |
| 2471 | fault_errors = iir; |
| 2472 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 2473 | fault_errors &= GEN9_DE_PIPE_IRQ_FAULT_ERRORS; |
| 2474 | else |
| 2475 | fault_errors &= GEN8_DE_PIPE_IRQ_FAULT_ERRORS; |
| 2476 | |
| 2477 | if (fault_errors) |
| 2478 | DRM_ERROR("Fault errors on pipe %c\n: 0x%08x", |
| 2479 | pipe_name(pipe), |
| 2480 | fault_errors); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2481 | } |
| 2482 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2483 | if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) && |
Shashank Sharma | 266ea3d | 2014-08-22 17:40:42 +0530 | [diff] [blame] | 2484 | master_ctl & GEN8_DE_PCH_IRQ) { |
Daniel Vetter | 92d03a8 | 2013-11-07 11:05:43 +0100 | [diff] [blame] | 2485 | /* |
| 2486 | * FIXME(BDW): Assume for now that the new interrupt handling |
| 2487 | * scheme also closed the SDE interrupt handling race we've seen |
| 2488 | * on older pch-split platforms. But this needs testing. |
| 2489 | */ |
Tvrtko Ursulin | e32192e | 2016-01-12 16:04:06 +0000 | [diff] [blame] | 2490 | iir = I915_READ(SDEIIR); |
| 2491 | if (iir) { |
| 2492 | I915_WRITE(SDEIIR, iir); |
Daniel Vetter | 92d03a8 | 2013-11-07 11:05:43 +0100 | [diff] [blame] | 2493 | ret = IRQ_HANDLED; |
Ville Syrjälä | 6dbf30c | 2015-08-27 23:56:02 +0300 | [diff] [blame] | 2494 | |
Rodrigo Vivi | 22dea0b | 2016-07-01 17:07:12 -0700 | [diff] [blame] | 2495 | if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv)) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2496 | spt_irq_handler(dev_priv, iir); |
Ville Syrjälä | 6dbf30c | 2015-08-27 23:56:02 +0300 | [diff] [blame] | 2497 | else |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 2498 | cpt_irq_handler(dev_priv, iir); |
Jani Nikula | 2dfb0b8 | 2016-01-07 10:29:10 +0200 | [diff] [blame] | 2499 | } else { |
| 2500 | /* |
| 2501 | * Like on previous PCH there seems to be something |
| 2502 | * fishy going on with forwarding PCH interrupts. |
| 2503 | */ |
| 2504 | DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n"); |
| 2505 | } |
Daniel Vetter | 92d03a8 | 2013-11-07 11:05:43 +0100 | [diff] [blame] | 2506 | } |
| 2507 | |
Tvrtko Ursulin | f11a0f4 | 2016-01-12 16:04:07 +0000 | [diff] [blame] | 2508 | return ret; |
| 2509 | } |
| 2510 | |
| 2511 | static irqreturn_t gen8_irq_handler(int irq, void *arg) |
| 2512 | { |
| 2513 | struct drm_device *dev = arg; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2514 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | f11a0f4 | 2016-01-12 16:04:07 +0000 | [diff] [blame] | 2515 | u32 master_ctl; |
Ville Syrjälä | e30e251 | 2016-04-13 21:19:58 +0300 | [diff] [blame] | 2516 | u32 gt_iir[4] = {}; |
Tvrtko Ursulin | f11a0f4 | 2016-01-12 16:04:07 +0000 | [diff] [blame] | 2517 | irqreturn_t ret; |
| 2518 | |
| 2519 | if (!intel_irqs_enabled(dev_priv)) |
| 2520 | return IRQ_NONE; |
| 2521 | |
| 2522 | master_ctl = I915_READ_FW(GEN8_MASTER_IRQ); |
| 2523 | master_ctl &= ~GEN8_MASTER_IRQ_CONTROL; |
| 2524 | if (!master_ctl) |
| 2525 | return IRQ_NONE; |
| 2526 | |
| 2527 | I915_WRITE_FW(GEN8_MASTER_IRQ, 0); |
| 2528 | |
| 2529 | /* IRQs are synced during runtime_suspend, we don't require a wakeref */ |
| 2530 | disable_rpm_wakeref_asserts(dev_priv); |
| 2531 | |
| 2532 | /* Find, clear, then process each source of interrupt */ |
Ville Syrjälä | e30e251 | 2016-04-13 21:19:58 +0300 | [diff] [blame] | 2533 | ret = gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir); |
| 2534 | gen8_gt_irq_handler(dev_priv, gt_iir); |
Tvrtko Ursulin | f11a0f4 | 2016-01-12 16:04:07 +0000 | [diff] [blame] | 2535 | ret |= gen8_de_irq_handler(dev_priv, master_ctl); |
| 2536 | |
Chris Wilson | cb0d205 | 2015-04-07 16:21:04 +0100 | [diff] [blame] | 2537 | I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); |
| 2538 | POSTING_READ_FW(GEN8_MASTER_IRQ); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2539 | |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 2540 | enable_rpm_wakeref_asserts(dev_priv); |
| 2541 | |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2542 | return ret; |
| 2543 | } |
| 2544 | |
Chris Wilson | 1f15b76 | 2016-07-01 17:23:14 +0100 | [diff] [blame] | 2545 | static void i915_error_wake_up(struct drm_i915_private *dev_priv) |
Daniel Vetter | 17e1df0 | 2013-09-08 21:57:13 +0200 | [diff] [blame] | 2546 | { |
Daniel Vetter | 17e1df0 | 2013-09-08 21:57:13 +0200 | [diff] [blame] | 2547 | /* |
| 2548 | * Notify all waiters for GPU completion events that reset state has |
| 2549 | * been changed, and that they need to restart their wait after |
| 2550 | * checking for potential errors (and bail out to drop locks if there is |
| 2551 | * a gpu reset pending so that i915_error_work_func can acquire them). |
| 2552 | */ |
| 2553 | |
| 2554 | /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */ |
Chris Wilson | 1f15b76 | 2016-07-01 17:23:14 +0100 | [diff] [blame] | 2555 | wake_up_all(&dev_priv->gpu_error.wait_queue); |
Daniel Vetter | 17e1df0 | 2013-09-08 21:57:13 +0200 | [diff] [blame] | 2556 | |
| 2557 | /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */ |
| 2558 | wake_up_all(&dev_priv->pending_flip_queue); |
Daniel Vetter | 17e1df0 | 2013-09-08 21:57:13 +0200 | [diff] [blame] | 2559 | } |
| 2560 | |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2561 | /** |
Mika Kuoppala | b8d24a0 | 2015-01-28 17:03:14 +0200 | [diff] [blame] | 2562 | * i915_reset_and_wakeup - do process context error handling work |
Tvrtko Ursulin | 14bb2c1 | 2016-06-03 14:02:17 +0100 | [diff] [blame] | 2563 | * @dev_priv: i915 device private |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2564 | * |
| 2565 | * Fire an error uevent so userspace can see that a hang or error |
| 2566 | * was detected. |
| 2567 | */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2568 | static void i915_reset_and_wakeup(struct drm_i915_private *dev_priv) |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2569 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 2570 | struct kobject *kobj = &dev_priv->drm.primary->kdev->kobj; |
Ben Widawsky | cce723e | 2013-07-19 09:16:42 -0700 | [diff] [blame] | 2571 | char *error_event[] = { I915_ERROR_UEVENT "=1", NULL }; |
| 2572 | char *reset_event[] = { I915_RESET_UEVENT "=1", NULL }; |
| 2573 | char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL }; |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2574 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2575 | kobject_uevent_env(kobj, KOBJ_CHANGE, error_event); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2576 | |
Chris Wilson | 8af29b0 | 2016-09-09 14:11:47 +0100 | [diff] [blame] | 2577 | DRM_DEBUG_DRIVER("resetting chip\n"); |
| 2578 | kobject_uevent_env(kobj, KOBJ_CHANGE, reset_event); |
| 2579 | |
Daniel Vetter | 7db0ba2 | 2012-12-06 16:23:37 +0100 | [diff] [blame] | 2580 | /* |
Chris Wilson | 8af29b0 | 2016-09-09 14:11:47 +0100 | [diff] [blame] | 2581 | * In most cases it's guaranteed that we get here with an RPM |
| 2582 | * reference held, for example because there is a pending GPU |
| 2583 | * request that won't finish until the reset is done. This |
| 2584 | * isn't the case at least when we get here by doing a |
| 2585 | * simulated reset via debugs, so get an RPM reference. |
Daniel Vetter | 7db0ba2 | 2012-12-06 16:23:37 +0100 | [diff] [blame] | 2586 | */ |
Chris Wilson | 8af29b0 | 2016-09-09 14:11:47 +0100 | [diff] [blame] | 2587 | intel_runtime_pm_get(dev_priv); |
Chris Wilson | 8af29b0 | 2016-09-09 14:11:47 +0100 | [diff] [blame] | 2588 | intel_prepare_reset(dev_priv); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 2589 | |
Chris Wilson | 780f262 | 2016-09-09 14:11:52 +0100 | [diff] [blame] | 2590 | do { |
| 2591 | /* |
| 2592 | * All state reset _must_ be completed before we update the |
| 2593 | * reset counter, for otherwise waiters might miss the reset |
| 2594 | * pending state and not properly drop locks, resulting in |
| 2595 | * deadlocks with the reset work. |
| 2596 | */ |
| 2597 | if (mutex_trylock(&dev_priv->drm.struct_mutex)) { |
| 2598 | i915_reset(dev_priv); |
| 2599 | mutex_unlock(&dev_priv->drm.struct_mutex); |
| 2600 | } |
| 2601 | |
| 2602 | /* We need to wait for anyone holding the lock to wakeup */ |
| 2603 | } while (wait_on_bit_timeout(&dev_priv->gpu_error.flags, |
| 2604 | I915_RESET_IN_PROGRESS, |
| 2605 | TASK_UNINTERRUPTIBLE, |
| 2606 | HZ)); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 2607 | |
Chris Wilson | 8af29b0 | 2016-09-09 14:11:47 +0100 | [diff] [blame] | 2608 | intel_finish_reset(dev_priv); |
Chris Wilson | 8af29b0 | 2016-09-09 14:11:47 +0100 | [diff] [blame] | 2609 | intel_runtime_pm_put(dev_priv); |
Daniel Vetter | 17e1df0 | 2013-09-08 21:57:13 +0200 | [diff] [blame] | 2610 | |
Chris Wilson | 780f262 | 2016-09-09 14:11:52 +0100 | [diff] [blame] | 2611 | if (!test_bit(I915_WEDGED, &dev_priv->gpu_error.flags)) |
Chris Wilson | 8af29b0 | 2016-09-09 14:11:47 +0100 | [diff] [blame] | 2612 | kobject_uevent_env(kobj, |
| 2613 | KOBJ_CHANGE, reset_done_event); |
Imre Deak | f454c69 | 2014-04-23 01:09:04 +0300 | [diff] [blame] | 2614 | |
Chris Wilson | 8af29b0 | 2016-09-09 14:11:47 +0100 | [diff] [blame] | 2615 | /* |
| 2616 | * Note: The wake_up also serves as a memory barrier so that |
| 2617 | * waiters see the updated value of the dev_priv->gpu_error. |
| 2618 | */ |
| 2619 | wake_up_all(&dev_priv->gpu_error.reset_queue); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2620 | } |
| 2621 | |
Ben Widawsky | d636951 | 2016-09-20 16:54:32 +0300 | [diff] [blame] | 2622 | static inline void |
| 2623 | i915_err_print_instdone(struct drm_i915_private *dev_priv, |
| 2624 | struct intel_instdone *instdone) |
| 2625 | { |
Ben Widawsky | f9e6137 | 2016-09-20 16:54:33 +0300 | [diff] [blame] | 2626 | int slice; |
| 2627 | int subslice; |
| 2628 | |
Ben Widawsky | d636951 | 2016-09-20 16:54:32 +0300 | [diff] [blame] | 2629 | pr_err(" INSTDONE: 0x%08x\n", instdone->instdone); |
| 2630 | |
| 2631 | if (INTEL_GEN(dev_priv) <= 3) |
| 2632 | return; |
| 2633 | |
| 2634 | pr_err(" SC_INSTDONE: 0x%08x\n", instdone->slice_common); |
| 2635 | |
| 2636 | if (INTEL_GEN(dev_priv) <= 6) |
| 2637 | return; |
| 2638 | |
Ben Widawsky | f9e6137 | 2016-09-20 16:54:33 +0300 | [diff] [blame] | 2639 | for_each_instdone_slice_subslice(dev_priv, slice, subslice) |
| 2640 | pr_err(" SAMPLER_INSTDONE[%d][%d]: 0x%08x\n", |
| 2641 | slice, subslice, instdone->sampler[slice][subslice]); |
| 2642 | |
| 2643 | for_each_instdone_slice_subslice(dev_priv, slice, subslice) |
| 2644 | pr_err(" ROW_INSTDONE[%d][%d]: 0x%08x\n", |
| 2645 | slice, subslice, instdone->row[slice][subslice]); |
Ben Widawsky | d636951 | 2016-09-20 16:54:32 +0300 | [diff] [blame] | 2646 | } |
| 2647 | |
Chris Wilson | eaa14c2 | 2016-10-19 13:52:03 +0100 | [diff] [blame] | 2648 | static void i915_clear_error_registers(struct drm_i915_private *dev_priv) |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2649 | { |
Chris Wilson | eaa14c2 | 2016-10-19 13:52:03 +0100 | [diff] [blame] | 2650 | u32 eir; |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2651 | |
Chris Wilson | eaa14c2 | 2016-10-19 13:52:03 +0100 | [diff] [blame] | 2652 | if (!IS_GEN2(dev_priv)) |
| 2653 | I915_WRITE(PGTBL_ER, I915_READ(PGTBL_ER)); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2654 | |
Chris Wilson | eaa14c2 | 2016-10-19 13:52:03 +0100 | [diff] [blame] | 2655 | if (INTEL_GEN(dev_priv) < 4) |
| 2656 | I915_WRITE(IPEIR, I915_READ(IPEIR)); |
| 2657 | else |
| 2658 | I915_WRITE(IPEIR_I965, I915_READ(IPEIR_I965)); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2659 | |
Chris Wilson | eaa14c2 | 2016-10-19 13:52:03 +0100 | [diff] [blame] | 2660 | I915_WRITE(EIR, I915_READ(EIR)); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2661 | eir = I915_READ(EIR); |
| 2662 | if (eir) { |
| 2663 | /* |
| 2664 | * some errors might have become stuck, |
| 2665 | * mask them. |
| 2666 | */ |
Chris Wilson | eaa14c2 | 2016-10-19 13:52:03 +0100 | [diff] [blame] | 2667 | DRM_DEBUG_DRIVER("EIR stuck: 0x%08x, masking\n", eir); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2668 | I915_WRITE(EMR, I915_READ(EMR) | eir); |
| 2669 | I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); |
| 2670 | } |
Chris Wilson | 35aed2e | 2010-05-27 13:18:12 +0100 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | /** |
Mika Kuoppala | b8d24a0 | 2015-01-28 17:03:14 +0200 | [diff] [blame] | 2674 | * i915_handle_error - handle a gpu error |
Tvrtko Ursulin | 14bb2c1 | 2016-06-03 14:02:17 +0100 | [diff] [blame] | 2675 | * @dev_priv: i915 device private |
arun.siluvery@linux.intel.com | 14b730f | 2016-03-18 20:07:55 +0000 | [diff] [blame] | 2676 | * @engine_mask: mask representing engines that are hung |
Javier Martinez Canillas | aafd858 | 2015-10-08 09:57:49 +0200 | [diff] [blame] | 2677 | * Do some basic checking of register state at error time and |
Chris Wilson | 35aed2e | 2010-05-27 13:18:12 +0100 | [diff] [blame] | 2678 | * dump it to the syslog. Also call i915_capture_error_state() to make |
| 2679 | * sure we get a record and make it available in debugfs. Fire a uevent |
| 2680 | * so userspace knows something bad happened (should trigger collection |
| 2681 | * of a ring dump etc.). |
Tvrtko Ursulin | 14bb2c1 | 2016-06-03 14:02:17 +0100 | [diff] [blame] | 2682 | * @fmt: Error message format string |
Chris Wilson | 35aed2e | 2010-05-27 13:18:12 +0100 | [diff] [blame] | 2683 | */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2684 | void i915_handle_error(struct drm_i915_private *dev_priv, |
| 2685 | u32 engine_mask, |
Mika Kuoppala | 5817446 | 2014-02-25 17:11:26 +0200 | [diff] [blame] | 2686 | const char *fmt, ...) |
Chris Wilson | 35aed2e | 2010-05-27 13:18:12 +0100 | [diff] [blame] | 2687 | { |
Mika Kuoppala | 5817446 | 2014-02-25 17:11:26 +0200 | [diff] [blame] | 2688 | va_list args; |
| 2689 | char error_msg[80]; |
Chris Wilson | 35aed2e | 2010-05-27 13:18:12 +0100 | [diff] [blame] | 2690 | |
Mika Kuoppala | 5817446 | 2014-02-25 17:11:26 +0200 | [diff] [blame] | 2691 | va_start(args, fmt); |
| 2692 | vscnprintf(error_msg, sizeof(error_msg), fmt, args); |
| 2693 | va_end(args); |
| 2694 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2695 | i915_capture_error_state(dev_priv, engine_mask, error_msg); |
Chris Wilson | eaa14c2 | 2016-10-19 13:52:03 +0100 | [diff] [blame] | 2696 | i915_clear_error_registers(dev_priv); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2697 | |
Chris Wilson | 8af29b0 | 2016-09-09 14:11:47 +0100 | [diff] [blame] | 2698 | if (!engine_mask) |
| 2699 | return; |
Ben Gamari | ba1234d | 2009-09-14 17:48:47 -0400 | [diff] [blame] | 2700 | |
Chris Wilson | 8af29b0 | 2016-09-09 14:11:47 +0100 | [diff] [blame] | 2701 | if (test_and_set_bit(I915_RESET_IN_PROGRESS, |
| 2702 | &dev_priv->gpu_error.flags)) |
| 2703 | return; |
| 2704 | |
| 2705 | /* |
| 2706 | * Wakeup waiting processes so that the reset function |
| 2707 | * i915_reset_and_wakeup doesn't deadlock trying to grab |
| 2708 | * various locks. By bumping the reset counter first, the woken |
| 2709 | * processes will see a reset in progress and back off, |
| 2710 | * releasing their locks and then wait for the reset completion. |
| 2711 | * We must do this for _all_ gpu waiters that might hold locks |
| 2712 | * that the reset work needs to acquire. |
| 2713 | * |
| 2714 | * Note: The wake_up also provides a memory barrier to ensure that the |
| 2715 | * waiters see the updated value of the reset flags. |
| 2716 | */ |
| 2717 | i915_error_wake_up(dev_priv); |
Ben Gamari | 11ed50e | 2009-09-14 17:48:45 -0400 | [diff] [blame] | 2718 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2719 | i915_reset_and_wakeup(dev_priv); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2720 | } |
| 2721 | |
Keith Packard | 42f52ef | 2008-10-18 19:39:29 -0700 | [diff] [blame] | 2722 | /* Called from drm generic code, passed 'crtc' which |
| 2723 | * we use as a pipe index |
| 2724 | */ |
Chris Wilson | 86e83e3 | 2016-10-07 20:49:52 +0100 | [diff] [blame] | 2725 | static int i8xx_enable_vblank(struct drm_device *dev, unsigned int pipe) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 2726 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2727 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 2728 | unsigned long irqflags; |
Jesse Barnes | 71e0ffa | 2009-01-08 10:42:15 -0800 | [diff] [blame] | 2729 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2730 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Chris Wilson | 86e83e3 | 2016-10-07 20:49:52 +0100 | [diff] [blame] | 2731 | i915_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS); |
| 2732 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 2733 | |
| 2734 | return 0; |
| 2735 | } |
| 2736 | |
| 2737 | static int i965_enable_vblank(struct drm_device *dev, unsigned int pipe) |
| 2738 | { |
| 2739 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 2740 | unsigned long irqflags; |
| 2741 | |
| 2742 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
| 2743 | i915_enable_pipestat(dev_priv, pipe, |
| 2744 | PIPE_START_VBLANK_INTERRUPT_STATUS); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2745 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
Chris Wilson | 8692d00e | 2011-02-05 10:08:21 +0000 | [diff] [blame] | 2746 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 2747 | return 0; |
| 2748 | } |
| 2749 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 2750 | static int ironlake_enable_vblank(struct drm_device *dev, unsigned int pipe) |
Jesse Barnes | f796cf8 | 2011-04-07 13:58:17 -0700 | [diff] [blame] | 2751 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2752 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | f796cf8 | 2011-04-07 13:58:17 -0700 | [diff] [blame] | 2753 | unsigned long irqflags; |
Tvrtko Ursulin | 55b8f2a | 2016-10-14 09:17:22 +0100 | [diff] [blame] | 2754 | uint32_t bit = INTEL_GEN(dev_priv) >= 7 ? |
Chris Wilson | 86e83e3 | 2016-10-07 20:49:52 +0100 | [diff] [blame] | 2755 | DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe); |
Jesse Barnes | f796cf8 | 2011-04-07 13:58:17 -0700 | [diff] [blame] | 2756 | |
Jesse Barnes | f796cf8 | 2011-04-07 13:58:17 -0700 | [diff] [blame] | 2757 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Ville Syrjälä | fbdedaea | 2015-11-23 18:06:16 +0200 | [diff] [blame] | 2758 | ilk_enable_display_irq(dev_priv, bit); |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 2759 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 2760 | |
| 2761 | return 0; |
| 2762 | } |
| 2763 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 2764 | static int gen8_enable_vblank(struct drm_device *dev, unsigned int pipe) |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2765 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2766 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2767 | unsigned long irqflags; |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2768 | |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2769 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Ville Syrjälä | 013d375 | 2015-11-23 18:06:17 +0200 | [diff] [blame] | 2770 | bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2771 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
Ville Syrjälä | 013d375 | 2015-11-23 18:06:17 +0200 | [diff] [blame] | 2772 | |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2773 | return 0; |
| 2774 | } |
| 2775 | |
Keith Packard | 42f52ef | 2008-10-18 19:39:29 -0700 | [diff] [blame] | 2776 | /* Called from drm generic code, passed 'crtc' which |
| 2777 | * we use as a pipe index |
| 2778 | */ |
Chris Wilson | 86e83e3 | 2016-10-07 20:49:52 +0100 | [diff] [blame] | 2779 | static void i8xx_disable_vblank(struct drm_device *dev, unsigned int pipe) |
| 2780 | { |
| 2781 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 2782 | unsigned long irqflags; |
| 2783 | |
| 2784 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
| 2785 | i915_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS); |
| 2786 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 2787 | } |
| 2788 | |
| 2789 | static void i965_disable_vblank(struct drm_device *dev, unsigned int pipe) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 2790 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2791 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 2792 | unsigned long irqflags; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 2793 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2794 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Jesse Barnes | f796cf8 | 2011-04-07 13:58:17 -0700 | [diff] [blame] | 2795 | i915_disable_pipestat(dev_priv, pipe, |
Imre Deak | 755e901 | 2014-02-10 18:42:47 +0200 | [diff] [blame] | 2796 | PIPE_START_VBLANK_INTERRUPT_STATUS); |
Jesse Barnes | f796cf8 | 2011-04-07 13:58:17 -0700 | [diff] [blame] | 2797 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 2798 | } |
| 2799 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 2800 | static void ironlake_disable_vblank(struct drm_device *dev, unsigned int pipe) |
Jesse Barnes | f796cf8 | 2011-04-07 13:58:17 -0700 | [diff] [blame] | 2801 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2802 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | f796cf8 | 2011-04-07 13:58:17 -0700 | [diff] [blame] | 2803 | unsigned long irqflags; |
Tvrtko Ursulin | 55b8f2a | 2016-10-14 09:17:22 +0100 | [diff] [blame] | 2804 | uint32_t bit = INTEL_GEN(dev_priv) >= 7 ? |
Chris Wilson | 86e83e3 | 2016-10-07 20:49:52 +0100 | [diff] [blame] | 2805 | DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe); |
Jesse Barnes | f796cf8 | 2011-04-07 13:58:17 -0700 | [diff] [blame] | 2806 | |
| 2807 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Ville Syrjälä | fbdedaea | 2015-11-23 18:06:16 +0200 | [diff] [blame] | 2808 | ilk_disable_display_irq(dev_priv, bit); |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 2809 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 2810 | } |
| 2811 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 2812 | static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe) |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2813 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2814 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2815 | unsigned long irqflags; |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2816 | |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2817 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Ville Syrjälä | 013d375 | 2015-11-23 18:06:17 +0200 | [diff] [blame] | 2818 | bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2819 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 2820 | } |
| 2821 | |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 2822 | static bool |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 2823 | ipehr_is_semaphore_wait(struct intel_engine_cs *engine, u32 ipehr) |
Daniel Vetter | a028c4b | 2014-03-15 00:08:56 +0100 | [diff] [blame] | 2824 | { |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 2825 | if (INTEL_GEN(engine->i915) >= 8) { |
Rodrigo Vivi | a6cdb93 | 2014-06-30 09:53:39 -0700 | [diff] [blame] | 2826 | return (ipehr >> 23) == 0x1c; |
Daniel Vetter | a028c4b | 2014-03-15 00:08:56 +0100 | [diff] [blame] | 2827 | } else { |
| 2828 | ipehr &= ~MI_SEMAPHORE_SYNC_MASK; |
| 2829 | return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | |
| 2830 | MI_SEMAPHORE_REGISTER); |
| 2831 | } |
| 2832 | } |
| 2833 | |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 2834 | static struct intel_engine_cs * |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2835 | semaphore_wait_to_signaller_ring(struct intel_engine_cs *engine, u32 ipehr, |
| 2836 | u64 offset) |
Daniel Vetter | 921d42e | 2014-03-18 10:26:04 +0100 | [diff] [blame] | 2837 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2838 | struct drm_i915_private *dev_priv = engine->i915; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 2839 | struct intel_engine_cs *signaller; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 2840 | enum intel_engine_id id; |
Daniel Vetter | 921d42e | 2014-03-18 10:26:04 +0100 | [diff] [blame] | 2841 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2842 | if (INTEL_GEN(dev_priv) >= 8) { |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 2843 | for_each_engine(signaller, dev_priv, id) { |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2844 | if (engine == signaller) |
Rodrigo Vivi | a6cdb93 | 2014-06-30 09:53:39 -0700 | [diff] [blame] | 2845 | continue; |
| 2846 | |
Chris Wilson | 348b9b1 | 2016-10-03 13:45:16 +0100 | [diff] [blame] | 2847 | if (offset == signaller->semaphore.signal_ggtt[engine->hw_id]) |
Rodrigo Vivi | a6cdb93 | 2014-06-30 09:53:39 -0700 | [diff] [blame] | 2848 | return signaller; |
| 2849 | } |
Daniel Vetter | 921d42e | 2014-03-18 10:26:04 +0100 | [diff] [blame] | 2850 | } else { |
| 2851 | u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK; |
| 2852 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 2853 | for_each_engine(signaller, dev_priv, id) { |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2854 | if(engine == signaller) |
Daniel Vetter | 921d42e | 2014-03-18 10:26:04 +0100 | [diff] [blame] | 2855 | continue; |
| 2856 | |
Chris Wilson | 348b9b1 | 2016-10-03 13:45:16 +0100 | [diff] [blame] | 2857 | if (sync_bits == signaller->semaphore.mbox.wait[engine->hw_id]) |
Daniel Vetter | 921d42e | 2014-03-18 10:26:04 +0100 | [diff] [blame] | 2858 | return signaller; |
| 2859 | } |
| 2860 | } |
| 2861 | |
Chris Wilson | 348b9b1 | 2016-10-03 13:45:16 +0100 | [diff] [blame] | 2862 | DRM_DEBUG_DRIVER("No signaller ring found for %s, ipehr 0x%08x, offset 0x%016llx\n", |
| 2863 | engine->name, ipehr, offset); |
Daniel Vetter | 921d42e | 2014-03-18 10:26:04 +0100 | [diff] [blame] | 2864 | |
Chris Wilson | 80b5bdb | 2016-09-09 14:11:58 +0100 | [diff] [blame] | 2865 | return ERR_PTR(-ENODEV); |
Daniel Vetter | 921d42e | 2014-03-18 10:26:04 +0100 | [diff] [blame] | 2866 | } |
| 2867 | |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 2868 | static struct intel_engine_cs * |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2869 | semaphore_waits_for(struct intel_engine_cs *engine, u32 *seqno) |
Chris Wilson | a24a11e | 2013-03-14 17:52:05 +0200 | [diff] [blame] | 2870 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2871 | struct drm_i915_private *dev_priv = engine->i915; |
Chris Wilson | 406ea8d | 2016-07-20 13:31:55 +0100 | [diff] [blame] | 2872 | void __iomem *vaddr; |
Daniel Vetter | 88fe429 | 2014-03-15 00:08:55 +0100 | [diff] [blame] | 2873 | u32 cmd, ipehr, head; |
Rodrigo Vivi | a6cdb93 | 2014-06-30 09:53:39 -0700 | [diff] [blame] | 2874 | u64 offset = 0; |
| 2875 | int i, backwards; |
Chris Wilson | a24a11e | 2013-03-14 17:52:05 +0200 | [diff] [blame] | 2876 | |
Tomas Elf | 381e8ae | 2015-10-08 19:31:33 +0100 | [diff] [blame] | 2877 | /* |
| 2878 | * This function does not support execlist mode - any attempt to |
| 2879 | * proceed further into this function will result in a kernel panic |
| 2880 | * when dereferencing ring->buffer, which is not set up in execlist |
| 2881 | * mode. |
| 2882 | * |
| 2883 | * The correct way of doing it would be to derive the currently |
| 2884 | * executing ring buffer from the current context, which is derived |
| 2885 | * from the currently running request. Unfortunately, to get the |
| 2886 | * current request we would have to grab the struct_mutex before doing |
| 2887 | * anything else, which would be ill-advised since some other thread |
| 2888 | * might have grabbed it already and managed to hang itself, causing |
| 2889 | * the hang checker to deadlock. |
| 2890 | * |
| 2891 | * Therefore, this function does not support execlist mode in its |
| 2892 | * current form. Just return NULL and move on. |
| 2893 | */ |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2894 | if (engine->buffer == NULL) |
Tomas Elf | 381e8ae | 2015-10-08 19:31:33 +0100 | [diff] [blame] | 2895 | return NULL; |
| 2896 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2897 | ipehr = I915_READ(RING_IPEHR(engine->mmio_base)); |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 2898 | if (!ipehr_is_semaphore_wait(engine, ipehr)) |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2899 | return NULL; |
Chris Wilson | a24a11e | 2013-03-14 17:52:05 +0200 | [diff] [blame] | 2900 | |
Daniel Vetter | 88fe429 | 2014-03-15 00:08:55 +0100 | [diff] [blame] | 2901 | /* |
| 2902 | * HEAD is likely pointing to the dword after the actual command, |
| 2903 | * 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] | 2904 | * or 4 dwords depending on the semaphore wait command size. |
| 2905 | * Note that we don't care about ACTHD here since that might |
Daniel Vetter | 88fe429 | 2014-03-15 00:08:55 +0100 | [diff] [blame] | 2906 | * point at at batch, and semaphores are always emitted into the |
| 2907 | * ringbuffer itself. |
Chris Wilson | a24a11e | 2013-03-14 17:52:05 +0200 | [diff] [blame] | 2908 | */ |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2909 | head = I915_READ_HEAD(engine) & HEAD_ADDR; |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2910 | backwards = (INTEL_GEN(dev_priv) >= 8) ? 5 : 4; |
Chris Wilson | f2f0ed7 | 2016-07-20 13:31:56 +0100 | [diff] [blame] | 2911 | vaddr = (void __iomem *)engine->buffer->vaddr; |
Daniel Vetter | 88fe429 | 2014-03-15 00:08:55 +0100 | [diff] [blame] | 2912 | |
Rodrigo Vivi | a6cdb93 | 2014-06-30 09:53:39 -0700 | [diff] [blame] | 2913 | for (i = backwards; i; --i) { |
Daniel Vetter | 88fe429 | 2014-03-15 00:08:55 +0100 | [diff] [blame] | 2914 | /* |
| 2915 | * Be paranoid and presume the hw has gone off into the wild - |
| 2916 | * our ring is smaller than what the hardware (and hence |
| 2917 | * HEAD_ADDR) allows. Also handles wrap-around. |
| 2918 | */ |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2919 | head &= engine->buffer->size - 1; |
Daniel Vetter | 88fe429 | 2014-03-15 00:08:55 +0100 | [diff] [blame] | 2920 | |
| 2921 | /* This here seems to blow up */ |
Chris Wilson | 406ea8d | 2016-07-20 13:31:55 +0100 | [diff] [blame] | 2922 | cmd = ioread32(vaddr + head); |
Chris Wilson | a24a11e | 2013-03-14 17:52:05 +0200 | [diff] [blame] | 2923 | if (cmd == ipehr) |
| 2924 | break; |
| 2925 | |
Daniel Vetter | 88fe429 | 2014-03-15 00:08:55 +0100 | [diff] [blame] | 2926 | head -= 4; |
| 2927 | } |
Chris Wilson | a24a11e | 2013-03-14 17:52:05 +0200 | [diff] [blame] | 2928 | |
Daniel Vetter | 88fe429 | 2014-03-15 00:08:55 +0100 | [diff] [blame] | 2929 | if (!i) |
| 2930 | return NULL; |
| 2931 | |
Chris Wilson | 406ea8d | 2016-07-20 13:31:55 +0100 | [diff] [blame] | 2932 | *seqno = ioread32(vaddr + head + 4) + 1; |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2933 | if (INTEL_GEN(dev_priv) >= 8) { |
Chris Wilson | 406ea8d | 2016-07-20 13:31:55 +0100 | [diff] [blame] | 2934 | offset = ioread32(vaddr + head + 12); |
Rodrigo Vivi | a6cdb93 | 2014-06-30 09:53:39 -0700 | [diff] [blame] | 2935 | offset <<= 32; |
Chris Wilson | 406ea8d | 2016-07-20 13:31:55 +0100 | [diff] [blame] | 2936 | offset |= ioread32(vaddr + head + 8); |
Rodrigo Vivi | a6cdb93 | 2014-06-30 09:53:39 -0700 | [diff] [blame] | 2937 | } |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2938 | return semaphore_wait_to_signaller_ring(engine, ipehr, offset); |
Chris Wilson | a24a11e | 2013-03-14 17:52:05 +0200 | [diff] [blame] | 2939 | } |
| 2940 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2941 | static int semaphore_passed(struct intel_engine_cs *engine) |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2942 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2943 | struct drm_i915_private *dev_priv = engine->i915; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 2944 | struct intel_engine_cs *signaller; |
Chris Wilson | a0d036b | 2014-07-19 12:40:42 +0100 | [diff] [blame] | 2945 | u32 seqno; |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2946 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2947 | engine->hangcheck.deadlock++; |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2948 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2949 | signaller = semaphore_waits_for(engine, &seqno); |
Chris Wilson | 4be1738 | 2014-06-06 10:22:29 +0100 | [diff] [blame] | 2950 | if (signaller == NULL) |
| 2951 | return -1; |
| 2952 | |
Chris Wilson | 80b5bdb | 2016-09-09 14:11:58 +0100 | [diff] [blame] | 2953 | if (IS_ERR(signaller)) |
| 2954 | return 0; |
| 2955 | |
Chris Wilson | 4be1738 | 2014-06-06 10:22:29 +0100 | [diff] [blame] | 2956 | /* Prevent pathological recursion due to driver bugs */ |
Tvrtko Ursulin | 666796d | 2016-03-16 11:00:39 +0000 | [diff] [blame] | 2957 | if (signaller->hangcheck.deadlock >= I915_NUM_ENGINES) |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2958 | return -1; |
| 2959 | |
Chris Wilson | 1b7744e | 2016-07-01 17:23:17 +0100 | [diff] [blame] | 2960 | if (i915_seqno_passed(intel_engine_get_seqno(signaller), seqno)) |
Chris Wilson | 4be1738 | 2014-06-06 10:22:29 +0100 | [diff] [blame] | 2961 | return 1; |
| 2962 | |
Chris Wilson | a0d036b | 2014-07-19 12:40:42 +0100 | [diff] [blame] | 2963 | /* cursory check for an unkickable deadlock */ |
| 2964 | if (I915_READ_CTL(signaller) & RING_WAIT_SEMAPHORE && |
| 2965 | semaphore_passed(signaller) < 0) |
Chris Wilson | 4be1738 | 2014-06-06 10:22:29 +0100 | [diff] [blame] | 2966 | return -1; |
| 2967 | |
| 2968 | return 0; |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2969 | } |
| 2970 | |
| 2971 | static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv) |
| 2972 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 2973 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 2974 | enum intel_engine_id id; |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2975 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 2976 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 2977 | engine->hangcheck.deadlock = 0; |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 2978 | } |
| 2979 | |
Ben Widawsky | d636951 | 2016-09-20 16:54:32 +0300 | [diff] [blame] | 2980 | static bool instdone_unchanged(u32 current_instdone, u32 *old_instdone) |
| 2981 | { |
| 2982 | u32 tmp = current_instdone | *old_instdone; |
| 2983 | bool unchanged; |
| 2984 | |
| 2985 | unchanged = tmp == *old_instdone; |
| 2986 | *old_instdone |= tmp; |
| 2987 | |
| 2988 | return unchanged; |
| 2989 | } |
| 2990 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2991 | static bool subunits_stuck(struct intel_engine_cs *engine) |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2992 | { |
Ben Widawsky | d636951 | 2016-09-20 16:54:32 +0300 | [diff] [blame] | 2993 | struct drm_i915_private *dev_priv = engine->i915; |
| 2994 | struct intel_instdone instdone; |
| 2995 | struct intel_instdone *accu_instdone = &engine->hangcheck.instdone; |
Mika Kuoppala | 61642ff | 2015-12-01 17:56:12 +0200 | [diff] [blame] | 2996 | bool stuck; |
Ben Widawsky | f9e6137 | 2016-09-20 16:54:33 +0300 | [diff] [blame] | 2997 | int slice; |
| 2998 | int subslice; |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 2999 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 3000 | if (engine->id != RCS) |
Mika Kuoppala | 61642ff | 2015-12-01 17:56:12 +0200 | [diff] [blame] | 3001 | return true; |
| 3002 | |
Chris Wilson | 0e70447 | 2016-10-12 10:05:17 +0100 | [diff] [blame] | 3003 | intel_engine_get_instdone(engine, &instdone); |
Mika Kuoppala | 61642ff | 2015-12-01 17:56:12 +0200 | [diff] [blame] | 3004 | |
| 3005 | /* There might be unstable subunit states even when |
| 3006 | * actual head is not moving. Filter out the unstable ones by |
| 3007 | * accumulating the undone -> done transitions and only |
| 3008 | * consider those as progress. |
| 3009 | */ |
Ben Widawsky | d636951 | 2016-09-20 16:54:32 +0300 | [diff] [blame] | 3010 | stuck = instdone_unchanged(instdone.instdone, |
| 3011 | &accu_instdone->instdone); |
| 3012 | stuck &= instdone_unchanged(instdone.slice_common, |
| 3013 | &accu_instdone->slice_common); |
Ben Widawsky | f9e6137 | 2016-09-20 16:54:33 +0300 | [diff] [blame] | 3014 | |
| 3015 | for_each_instdone_slice_subslice(dev_priv, slice, subslice) { |
| 3016 | stuck &= instdone_unchanged(instdone.sampler[slice][subslice], |
| 3017 | &accu_instdone->sampler[slice][subslice]); |
| 3018 | stuck &= instdone_unchanged(instdone.row[slice][subslice], |
| 3019 | &accu_instdone->row[slice][subslice]); |
| 3020 | } |
Mika Kuoppala | 61642ff | 2015-12-01 17:56:12 +0200 | [diff] [blame] | 3021 | |
| 3022 | return stuck; |
| 3023 | } |
| 3024 | |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 3025 | static enum intel_engine_hangcheck_action |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 3026 | head_stuck(struct intel_engine_cs *engine, u64 acthd) |
Mika Kuoppala | 61642ff | 2015-12-01 17:56:12 +0200 | [diff] [blame] | 3027 | { |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 3028 | if (acthd != engine->hangcheck.acthd) { |
Mika Kuoppala | 61642ff | 2015-12-01 17:56:12 +0200 | [diff] [blame] | 3029 | |
| 3030 | /* Clear subunit states on head movement */ |
Ben Widawsky | d636951 | 2016-09-20 16:54:32 +0300 | [diff] [blame] | 3031 | memset(&engine->hangcheck.instdone, 0, |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 3032 | sizeof(engine->hangcheck.instdone)); |
Mika Kuoppala | 61642ff | 2015-12-01 17:56:12 +0200 | [diff] [blame] | 3033 | |
Mika Kuoppala | 24a65e6 | 2016-03-02 16:48:29 +0200 | [diff] [blame] | 3034 | return HANGCHECK_ACTIVE; |
Mika Kuoppala | f260fe7 | 2014-08-05 17:16:26 +0300 | [diff] [blame] | 3035 | } |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 3036 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 3037 | if (!subunits_stuck(engine)) |
Mika Kuoppala | 61642ff | 2015-12-01 17:56:12 +0200 | [diff] [blame] | 3038 | return HANGCHECK_ACTIVE; |
| 3039 | |
| 3040 | return HANGCHECK_HUNG; |
| 3041 | } |
| 3042 | |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 3043 | static enum intel_engine_hangcheck_action |
| 3044 | engine_stuck(struct intel_engine_cs *engine, u64 acthd) |
Mika Kuoppala | 61642ff | 2015-12-01 17:56:12 +0200 | [diff] [blame] | 3045 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3046 | struct drm_i915_private *dev_priv = engine->i915; |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 3047 | enum intel_engine_hangcheck_action ha; |
Mika Kuoppala | 61642ff | 2015-12-01 17:56:12 +0200 | [diff] [blame] | 3048 | u32 tmp; |
| 3049 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 3050 | ha = head_stuck(engine, acthd); |
Mika Kuoppala | 61642ff | 2015-12-01 17:56:12 +0200 | [diff] [blame] | 3051 | if (ha != HANGCHECK_HUNG) |
| 3052 | return ha; |
| 3053 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3054 | if (IS_GEN2(dev_priv)) |
Jani Nikula | f2f4d82 | 2013-08-11 12:44:01 +0300 | [diff] [blame] | 3055 | return HANGCHECK_HUNG; |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 3056 | |
| 3057 | /* Is the chip hanging on a WAIT_FOR_EVENT? |
| 3058 | * If so we can simply poke the RB_WAIT bit |
| 3059 | * and break the hang. This should work on |
| 3060 | * all but the second generation chipsets. |
| 3061 | */ |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 3062 | tmp = I915_READ_CTL(engine); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 3063 | if (tmp & RING_WAIT) { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3064 | i915_handle_error(dev_priv, 0, |
Mika Kuoppala | 5817446 | 2014-02-25 17:11:26 +0200 | [diff] [blame] | 3065 | "Kicking stuck wait on %s", |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 3066 | engine->name); |
| 3067 | I915_WRITE_CTL(engine, tmp); |
Jani Nikula | f2f4d82 | 2013-08-11 12:44:01 +0300 | [diff] [blame] | 3068 | return HANGCHECK_KICK; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 3069 | } |
Chris Wilson | a24a11e | 2013-03-14 17:52:05 +0200 | [diff] [blame] | 3070 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3071 | if (INTEL_GEN(dev_priv) >= 6 && tmp & RING_WAIT_SEMAPHORE) { |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 3072 | switch (semaphore_passed(engine)) { |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 3073 | default: |
Jani Nikula | f2f4d82 | 2013-08-11 12:44:01 +0300 | [diff] [blame] | 3074 | return HANGCHECK_HUNG; |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 3075 | case 1: |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3076 | i915_handle_error(dev_priv, 0, |
Mika Kuoppala | 5817446 | 2014-02-25 17:11:26 +0200 | [diff] [blame] | 3077 | "Kicking stuck semaphore on %s", |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 3078 | engine->name); |
| 3079 | I915_WRITE_CTL(engine, tmp); |
Jani Nikula | f2f4d82 | 2013-08-11 12:44:01 +0300 | [diff] [blame] | 3080 | return HANGCHECK_KICK; |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 3081 | case 0: |
Jani Nikula | f2f4d82 | 2013-08-11 12:44:01 +0300 | [diff] [blame] | 3082 | return HANGCHECK_WAIT; |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 3083 | } |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 3084 | } |
Mika Kuoppala | ed5cbb0 | 2013-05-13 16:32:11 +0300 | [diff] [blame] | 3085 | |
Jani Nikula | f2f4d82 | 2013-08-11 12:44:01 +0300 | [diff] [blame] | 3086 | return HANGCHECK_HUNG; |
Mika Kuoppala | ed5cbb0 | 2013-05-13 16:32:11 +0300 | [diff] [blame] | 3087 | } |
| 3088 | |
Chris Wilson | 737b150 | 2015-01-26 18:03:03 +0200 | [diff] [blame] | 3089 | /* |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 3090 | * This is called when the chip hasn't reported back with completed |
Mika Kuoppala | 05407ff | 2013-05-30 09:04:29 +0300 | [diff] [blame] | 3091 | * batchbuffers in a long time. We keep track per ring seqno progress and |
| 3092 | * if there are no progress, hangcheck score for that ring is increased. |
| 3093 | * Further, acthd is inspected to see if the ring is stuck. On stuck case |
| 3094 | * we kick the ring. If we see no progress on three subsequent calls |
| 3095 | * 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] | 3096 | */ |
Chris Wilson | 737b150 | 2015-01-26 18:03:03 +0200 | [diff] [blame] | 3097 | static void i915_hangcheck_elapsed(struct work_struct *work) |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 3098 | { |
Chris Wilson | 737b150 | 2015-01-26 18:03:03 +0200 | [diff] [blame] | 3099 | struct drm_i915_private *dev_priv = |
| 3100 | container_of(work, typeof(*dev_priv), |
| 3101 | gpu_error.hangcheck_work.work); |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 3102 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 3103 | enum intel_engine_id id; |
Chris Wilson | 2b28428 | 2016-07-04 08:48:32 +0100 | [diff] [blame] | 3104 | unsigned int hung = 0, stuck = 0; |
| 3105 | int busy_count = 0; |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 3106 | #define BUSY 1 |
| 3107 | #define KICK 5 |
| 3108 | #define HUNG 20 |
Mika Kuoppala | 24a65e6 | 2016-03-02 16:48:29 +0200 | [diff] [blame] | 3109 | #define ACTIVE_DECAY 15 |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 3110 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 3111 | if (!i915.enable_hangcheck) |
Ben Widawsky | 3e0dc6b | 2011-06-29 10:26:42 -0700 | [diff] [blame] | 3112 | return; |
| 3113 | |
Chris Wilson | b1379d4 | 2016-07-05 08:54:36 +0100 | [diff] [blame] | 3114 | if (!READ_ONCE(dev_priv->gt.awake)) |
Chris Wilson | 67d97da | 2016-07-04 08:08:31 +0100 | [diff] [blame] | 3115 | return; |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 3116 | |
Mika Kuoppala | 7571494 | 2015-12-16 09:26:48 +0200 | [diff] [blame] | 3117 | /* As enabling the GPU requires fairly extensive mmio access, |
| 3118 | * periodically arm the mmio checker to see if we are triggering |
| 3119 | * any invalid access. |
| 3120 | */ |
| 3121 | intel_uncore_arm_unclaimed_mmio_detection(dev_priv); |
| 3122 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 3123 | for_each_engine(engine, dev_priv, id) { |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 3124 | bool busy = intel_engine_has_waiter(engine); |
Chris Wilson | 5087744 | 2014-03-21 12:41:53 +0000 | [diff] [blame] | 3125 | u64 acthd; |
| 3126 | u32 seqno; |
Chris Wilson | 34730fe | 2016-08-20 15:54:08 +0100 | [diff] [blame] | 3127 | u32 submit; |
Chris Wilson | b451951 | 2012-05-11 14:29:30 +0100 | [diff] [blame] | 3128 | |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 3129 | semaphore_clear_deadlocks(dev_priv); |
| 3130 | |
Chris Wilson | c04e0f3 | 2016-04-09 10:57:54 +0100 | [diff] [blame] | 3131 | /* We don't strictly need an irq-barrier here, as we are not |
| 3132 | * serving an interrupt request, be paranoid in case the |
| 3133 | * barrier has side-effects (such as preventing a broken |
| 3134 | * cacheline snoop) and so be sure that we can see the seqno |
| 3135 | * advance. If the seqno should stick, due to a stale |
| 3136 | * cacheline, we would erroneously declare the GPU hung. |
| 3137 | */ |
| 3138 | if (engine->irq_seqno_barrier) |
| 3139 | engine->irq_seqno_barrier(engine); |
| 3140 | |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 3141 | acthd = intel_engine_get_active_head(engine); |
Chris Wilson | 1b7744e | 2016-07-01 17:23:17 +0100 | [diff] [blame] | 3142 | seqno = intel_engine_get_seqno(engine); |
Chris Wilson | 34730fe | 2016-08-20 15:54:08 +0100 | [diff] [blame] | 3143 | submit = READ_ONCE(engine->last_submitted_seqno); |
Chris Wilson | d1e61e7 | 2012-04-10 17:00:41 +0100 | [diff] [blame] | 3144 | |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 3145 | if (engine->hangcheck.seqno == seqno) { |
Chris Wilson | 34730fe | 2016-08-20 15:54:08 +0100 | [diff] [blame] | 3146 | if (i915_seqno_passed(seqno, submit)) { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 3147 | engine->hangcheck.action = HANGCHECK_IDLE; |
Mika Kuoppala | 05407ff | 2013-05-30 09:04:29 +0300 | [diff] [blame] | 3148 | } else { |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 3149 | /* We always increment the hangcheck score |
Chris Wilson | 9930ca1 | 2016-07-27 09:07:30 +0100 | [diff] [blame] | 3150 | * if the engine is busy and still processing |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 3151 | * the same request, so that no single request |
| 3152 | * can run indefinitely (such as a chain of |
| 3153 | * batches). The only time we do not increment |
| 3154 | * the hangcheck score on this ring, if this |
Chris Wilson | 9930ca1 | 2016-07-27 09:07:30 +0100 | [diff] [blame] | 3155 | * engine is in a legitimate wait for another |
| 3156 | * engine. In that case the waiting engine is a |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 3157 | * victim and we want to be sure we catch the |
| 3158 | * right culprit. Then every time we do kick |
| 3159 | * the ring, add a small increment to the |
| 3160 | * score so that we can catch a batch that is |
| 3161 | * being repeatedly kicked and so responsible |
| 3162 | * for stalling the machine. |
| 3163 | */ |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 3164 | engine->hangcheck.action = |
| 3165 | engine_stuck(engine, acthd); |
Mika Kuoppala | ad8beae | 2013-06-12 12:35:32 +0300 | [diff] [blame] | 3166 | |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 3167 | switch (engine->hangcheck.action) { |
Mika Kuoppala | da66146 | 2013-09-06 16:03:28 +0300 | [diff] [blame] | 3168 | case HANGCHECK_IDLE: |
Jani Nikula | f2f4d82 | 2013-08-11 12:44:01 +0300 | [diff] [blame] | 3169 | case HANGCHECK_WAIT: |
Mika Kuoppala | f260fe7 | 2014-08-05 17:16:26 +0300 | [diff] [blame] | 3170 | break; |
Mika Kuoppala | 24a65e6 | 2016-03-02 16:48:29 +0200 | [diff] [blame] | 3171 | case HANGCHECK_ACTIVE: |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 3172 | engine->hangcheck.score += BUSY; |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 3173 | break; |
Jani Nikula | f2f4d82 | 2013-08-11 12:44:01 +0300 | [diff] [blame] | 3174 | case HANGCHECK_KICK: |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 3175 | engine->hangcheck.score += KICK; |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 3176 | break; |
Jani Nikula | f2f4d82 | 2013-08-11 12:44:01 +0300 | [diff] [blame] | 3177 | case HANGCHECK_HUNG: |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 3178 | engine->hangcheck.score += HUNG; |
Chris Wilson | 6274f21 | 2013-06-10 11:20:21 +0100 | [diff] [blame] | 3179 | break; |
| 3180 | } |
Mika Kuoppala | 05407ff | 2013-05-30 09:04:29 +0300 | [diff] [blame] | 3181 | } |
Chris Wilson | 2b28428 | 2016-07-04 08:48:32 +0100 | [diff] [blame] | 3182 | |
| 3183 | if (engine->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) { |
| 3184 | hung |= intel_engine_flag(engine); |
| 3185 | if (engine->hangcheck.action != HANGCHECK_HUNG) |
| 3186 | stuck |= intel_engine_flag(engine); |
| 3187 | } |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 3188 | } else { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 3189 | engine->hangcheck.action = HANGCHECK_ACTIVE; |
Mika Kuoppala | da66146 | 2013-09-06 16:03:28 +0300 | [diff] [blame] | 3190 | |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 3191 | /* Gradually reduce the count so that we catch DoS |
| 3192 | * attempts across multiple batches. |
| 3193 | */ |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 3194 | if (engine->hangcheck.score > 0) |
| 3195 | engine->hangcheck.score -= ACTIVE_DECAY; |
| 3196 | if (engine->hangcheck.score < 0) |
| 3197 | engine->hangcheck.score = 0; |
Mika Kuoppala | f260fe7 | 2014-08-05 17:16:26 +0300 | [diff] [blame] | 3198 | |
Mika Kuoppala | 61642ff | 2015-12-01 17:56:12 +0200 | [diff] [blame] | 3199 | /* Clear head and subunit states on seqno movement */ |
Chris Wilson | 12471ba | 2016-04-09 10:57:55 +0100 | [diff] [blame] | 3200 | acthd = 0; |
Mika Kuoppala | 61642ff | 2015-12-01 17:56:12 +0200 | [diff] [blame] | 3201 | |
Ben Widawsky | d636951 | 2016-09-20 16:54:32 +0300 | [diff] [blame] | 3202 | memset(&engine->hangcheck.instdone, 0, |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 3203 | sizeof(engine->hangcheck.instdone)); |
Chris Wilson | d1e61e7 | 2012-04-10 17:00:41 +0100 | [diff] [blame] | 3204 | } |
| 3205 | |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 3206 | engine->hangcheck.seqno = seqno; |
| 3207 | engine->hangcheck.acthd = acthd; |
Chris Wilson | 9107e9d | 2013-06-10 11:20:20 +0100 | [diff] [blame] | 3208 | busy_count += busy; |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 3209 | } |
Eric Anholt | b9201c1 | 2010-01-08 14:25:16 -0800 | [diff] [blame] | 3210 | |
Chris Wilson | 2b28428 | 2016-07-04 08:48:32 +0100 | [diff] [blame] | 3211 | if (hung) { |
| 3212 | char msg[80]; |
Chris Wilson | bafb0fc | 2016-08-27 08:54:01 +0100 | [diff] [blame] | 3213 | unsigned int tmp; |
Chris Wilson | 2b28428 | 2016-07-04 08:48:32 +0100 | [diff] [blame] | 3214 | int len; |
Mika Kuoppala | 92cab73 | 2013-05-24 17:16:07 +0300 | [diff] [blame] | 3215 | |
Chris Wilson | 2b28428 | 2016-07-04 08:48:32 +0100 | [diff] [blame] | 3216 | /* If some rings hung but others were still busy, only |
| 3217 | * blame the hanging rings in the synopsis. |
| 3218 | */ |
| 3219 | if (stuck != hung) |
| 3220 | hung &= ~stuck; |
| 3221 | len = scnprintf(msg, sizeof(msg), |
| 3222 | "%s on ", stuck == hung ? "No progress" : "Hang"); |
Chris Wilson | bafb0fc | 2016-08-27 08:54:01 +0100 | [diff] [blame] | 3223 | for_each_engine_masked(engine, dev_priv, hung, tmp) |
Chris Wilson | 2b28428 | 2016-07-04 08:48:32 +0100 | [diff] [blame] | 3224 | len += scnprintf(msg + len, sizeof(msg) - len, |
| 3225 | "%s, ", engine->name); |
| 3226 | msg[len-2] = '\0'; |
| 3227 | |
| 3228 | return i915_handle_error(dev_priv, hung, msg); |
| 3229 | } |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 3230 | |
Chris Wilson | 0553572 | 2016-07-01 17:23:11 +0100 | [diff] [blame] | 3231 | /* Reset timer in case GPU hangs without another request being added */ |
Mika Kuoppala | 05407ff | 2013-05-30 09:04:29 +0300 | [diff] [blame] | 3232 | if (busy_count) |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3233 | i915_queue_hangcheck(dev_priv); |
Mika Kuoppala | 10cd45b | 2013-07-03 17:22:08 +0300 | [diff] [blame] | 3234 | } |
| 3235 | |
Paulo Zanoni | 1c69eb4 | 2014-04-01 15:37:23 -0300 | [diff] [blame] | 3236 | static void ibx_irq_reset(struct drm_device *dev) |
Paulo Zanoni | 91738a9 | 2013-06-05 14:21:51 -0300 | [diff] [blame] | 3237 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3238 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | 91738a9 | 2013-06-05 14:21:51 -0300 | [diff] [blame] | 3239 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3240 | if (HAS_PCH_NOP(dev_priv)) |
Paulo Zanoni | 91738a9 | 2013-06-05 14:21:51 -0300 | [diff] [blame] | 3241 | return; |
| 3242 | |
Paulo Zanoni | f86f3fb | 2014-04-01 15:37:14 -0300 | [diff] [blame] | 3243 | GEN5_IRQ_RESET(SDE); |
Paulo Zanoni | 105b122 | 2014-04-01 15:37:17 -0300 | [diff] [blame] | 3244 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3245 | if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv)) |
Paulo Zanoni | 105b122 | 2014-04-01 15:37:17 -0300 | [diff] [blame] | 3246 | I915_WRITE(SERR_INT, 0xffffffff); |
Paulo Zanoni | 622364b | 2014-04-01 15:37:22 -0300 | [diff] [blame] | 3247 | } |
Paulo Zanoni | 105b122 | 2014-04-01 15:37:17 -0300 | [diff] [blame] | 3248 | |
Paulo Zanoni | 622364b | 2014-04-01 15:37:22 -0300 | [diff] [blame] | 3249 | /* |
| 3250 | * SDEIER is also touched by the interrupt handler to work around missed PCH |
| 3251 | * interrupts. Hence we can't update it after the interrupt handler is enabled - |
| 3252 | * instead we unconditionally enable all PCH interrupt sources here, but then |
| 3253 | * only unmask them as needed with SDEIMR. |
| 3254 | * |
| 3255 | * This function needs to be called before interrupts are enabled. |
| 3256 | */ |
| 3257 | static void ibx_irq_pre_postinstall(struct drm_device *dev) |
| 3258 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3259 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | 622364b | 2014-04-01 15:37:22 -0300 | [diff] [blame] | 3260 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3261 | if (HAS_PCH_NOP(dev_priv)) |
Paulo Zanoni | 622364b | 2014-04-01 15:37:22 -0300 | [diff] [blame] | 3262 | return; |
| 3263 | |
| 3264 | WARN_ON(I915_READ(SDEIER) != 0); |
Paulo Zanoni | 91738a9 | 2013-06-05 14:21:51 -0300 | [diff] [blame] | 3265 | I915_WRITE(SDEIER, 0xffffffff); |
| 3266 | POSTING_READ(SDEIER); |
| 3267 | } |
| 3268 | |
Paulo Zanoni | 7c4d664 | 2014-04-01 15:37:19 -0300 | [diff] [blame] | 3269 | static void gen5_gt_irq_reset(struct drm_device *dev) |
Daniel Vetter | d18ea1b | 2013-07-12 22:43:25 +0200 | [diff] [blame] | 3270 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3271 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | d18ea1b | 2013-07-12 22:43:25 +0200 | [diff] [blame] | 3272 | |
Paulo Zanoni | f86f3fb | 2014-04-01 15:37:14 -0300 | [diff] [blame] | 3273 | GEN5_IRQ_RESET(GT); |
Paulo Zanoni | a9d356a | 2014-04-01 15:37:09 -0300 | [diff] [blame] | 3274 | if (INTEL_INFO(dev)->gen >= 6) |
Paulo Zanoni | f86f3fb | 2014-04-01 15:37:14 -0300 | [diff] [blame] | 3275 | GEN5_IRQ_RESET(GEN6_PM); |
Daniel Vetter | d18ea1b | 2013-07-12 22:43:25 +0200 | [diff] [blame] | 3276 | } |
| 3277 | |
Ville Syrjälä | 70591a4 | 2014-10-30 19:42:58 +0200 | [diff] [blame] | 3278 | static void vlv_display_irq_reset(struct drm_i915_private *dev_priv) |
| 3279 | { |
| 3280 | enum pipe pipe; |
| 3281 | |
Ville Syrjälä | 71b8b41 | 2016-04-11 16:56:31 +0300 | [diff] [blame] | 3282 | if (IS_CHERRYVIEW(dev_priv)) |
| 3283 | I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV); |
| 3284 | else |
| 3285 | I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK); |
| 3286 | |
Ville Syrjälä | ad22d10 | 2016-04-12 18:56:14 +0300 | [diff] [blame] | 3287 | i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0); |
Ville Syrjälä | 70591a4 | 2014-10-30 19:42:58 +0200 | [diff] [blame] | 3288 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); |
| 3289 | |
Ville Syrjälä | ad22d10 | 2016-04-12 18:56:14 +0300 | [diff] [blame] | 3290 | for_each_pipe(dev_priv, pipe) { |
| 3291 | I915_WRITE(PIPESTAT(pipe), |
| 3292 | PIPE_FIFO_UNDERRUN_STATUS | |
| 3293 | PIPESTAT_INT_STATUS_MASK); |
| 3294 | dev_priv->pipestat_irq_mask[pipe] = 0; |
| 3295 | } |
Ville Syrjälä | 70591a4 | 2014-10-30 19:42:58 +0200 | [diff] [blame] | 3296 | |
| 3297 | GEN5_IRQ_RESET(VLV_); |
Ville Syrjälä | ad22d10 | 2016-04-12 18:56:14 +0300 | [diff] [blame] | 3298 | dev_priv->irq_mask = ~0; |
Ville Syrjälä | 70591a4 | 2014-10-30 19:42:58 +0200 | [diff] [blame] | 3299 | } |
| 3300 | |
Ville Syrjälä | 8bb6130 | 2016-04-12 18:56:44 +0300 | [diff] [blame] | 3301 | static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv) |
| 3302 | { |
| 3303 | u32 pipestat_mask; |
Ville Syrjälä | 9ab981f | 2016-04-11 16:56:28 +0300 | [diff] [blame] | 3304 | u32 enable_mask; |
Ville Syrjälä | 8bb6130 | 2016-04-12 18:56:44 +0300 | [diff] [blame] | 3305 | enum pipe pipe; |
| 3306 | |
Ville Syrjälä | 8bb6130 | 2016-04-12 18:56:44 +0300 | [diff] [blame] | 3307 | pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV | |
| 3308 | PIPE_CRC_DONE_INTERRUPT_STATUS; |
| 3309 | |
| 3310 | i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS); |
| 3311 | for_each_pipe(dev_priv, pipe) |
| 3312 | i915_enable_pipestat(dev_priv, pipe, pipestat_mask); |
| 3313 | |
Ville Syrjälä | 9ab981f | 2016-04-11 16:56:28 +0300 | [diff] [blame] | 3314 | enable_mask = I915_DISPLAY_PORT_INTERRUPT | |
| 3315 | I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | |
| 3316 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT; |
Ville Syrjälä | 8bb6130 | 2016-04-12 18:56:44 +0300 | [diff] [blame] | 3317 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 9ab981f | 2016-04-11 16:56:28 +0300 | [diff] [blame] | 3318 | enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT; |
Ville Syrjälä | 6b7eafc | 2016-04-11 16:56:29 +0300 | [diff] [blame] | 3319 | |
| 3320 | WARN_ON(dev_priv->irq_mask != ~0); |
| 3321 | |
Ville Syrjälä | 9ab981f | 2016-04-11 16:56:28 +0300 | [diff] [blame] | 3322 | dev_priv->irq_mask = ~enable_mask; |
Ville Syrjälä | 8bb6130 | 2016-04-12 18:56:44 +0300 | [diff] [blame] | 3323 | |
Ville Syrjälä | 9ab981f | 2016-04-11 16:56:28 +0300 | [diff] [blame] | 3324 | GEN5_IRQ_INIT(VLV_, dev_priv->irq_mask, enable_mask); |
Ville Syrjälä | 8bb6130 | 2016-04-12 18:56:44 +0300 | [diff] [blame] | 3325 | } |
| 3326 | |
| 3327 | /* drm_dma.h hooks |
| 3328 | */ |
| 3329 | static void ironlake_irq_reset(struct drm_device *dev) |
| 3330 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3331 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 8bb6130 | 2016-04-12 18:56:44 +0300 | [diff] [blame] | 3332 | |
| 3333 | I915_WRITE(HWSTAM, 0xffffffff); |
| 3334 | |
| 3335 | GEN5_IRQ_RESET(DE); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3336 | if (IS_GEN7(dev_priv)) |
Ville Syrjälä | 8bb6130 | 2016-04-12 18:56:44 +0300 | [diff] [blame] | 3337 | I915_WRITE(GEN7_ERR_INT, 0xffffffff); |
| 3338 | |
| 3339 | gen5_gt_irq_reset(dev); |
| 3340 | |
| 3341 | ibx_irq_reset(dev); |
| 3342 | } |
| 3343 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 3344 | static void valleyview_irq_preinstall(struct drm_device *dev) |
| 3345 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3346 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 3347 | |
Ville Syrjälä | 34c7b8a | 2016-04-13 21:19:48 +0300 | [diff] [blame] | 3348 | I915_WRITE(VLV_MASTER_IER, 0); |
| 3349 | POSTING_READ(VLV_MASTER_IER); |
| 3350 | |
Paulo Zanoni | 7c4d664 | 2014-04-01 15:37:19 -0300 | [diff] [blame] | 3351 | gen5_gt_irq_reset(dev); |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 3352 | |
Ville Syrjälä | ad22d10 | 2016-04-12 18:56:14 +0300 | [diff] [blame] | 3353 | spin_lock_irq(&dev_priv->irq_lock); |
Ville Syrjälä | 9918271 | 2016-04-11 16:56:25 +0300 | [diff] [blame] | 3354 | if (dev_priv->display_irqs_enabled) |
| 3355 | vlv_display_irq_reset(dev_priv); |
Ville Syrjälä | ad22d10 | 2016-04-12 18:56:14 +0300 | [diff] [blame] | 3356 | spin_unlock_irq(&dev_priv->irq_lock); |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 3357 | } |
| 3358 | |
Daniel Vetter | d6e3cca | 2014-05-22 22:18:22 +0200 | [diff] [blame] | 3359 | static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv) |
| 3360 | { |
| 3361 | GEN8_IRQ_RESET_NDX(GT, 0); |
| 3362 | GEN8_IRQ_RESET_NDX(GT, 1); |
| 3363 | GEN8_IRQ_RESET_NDX(GT, 2); |
| 3364 | GEN8_IRQ_RESET_NDX(GT, 3); |
| 3365 | } |
| 3366 | |
Paulo Zanoni | 823f6b3 | 2014-04-01 15:37:26 -0300 | [diff] [blame] | 3367 | static void gen8_irq_reset(struct drm_device *dev) |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3368 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3369 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3370 | int pipe; |
| 3371 | |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3372 | I915_WRITE(GEN8_MASTER_IRQ, 0); |
| 3373 | POSTING_READ(GEN8_MASTER_IRQ); |
| 3374 | |
Daniel Vetter | d6e3cca | 2014-05-22 22:18:22 +0200 | [diff] [blame] | 3375 | gen8_gt_irq_reset(dev_priv); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3376 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3377 | for_each_pipe(dev_priv, pipe) |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 3378 | if (intel_display_power_is_enabled(dev_priv, |
| 3379 | POWER_DOMAIN_PIPE(pipe))) |
Paulo Zanoni | 813bde4 | 2014-07-04 11:50:29 -0300 | [diff] [blame] | 3380 | GEN8_IRQ_RESET_NDX(DE_PIPE, pipe); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3381 | |
Paulo Zanoni | f86f3fb | 2014-04-01 15:37:14 -0300 | [diff] [blame] | 3382 | GEN5_IRQ_RESET(GEN8_DE_PORT_); |
| 3383 | GEN5_IRQ_RESET(GEN8_DE_MISC_); |
| 3384 | GEN5_IRQ_RESET(GEN8_PCU_); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3385 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3386 | if (HAS_PCH_SPLIT(dev_priv)) |
Shashank Sharma | 266ea3d | 2014-08-22 17:40:42 +0530 | [diff] [blame] | 3387 | ibx_irq_reset(dev); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3388 | } |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3389 | |
Damien Lespiau | 4c6c03b | 2015-03-06 18:50:48 +0000 | [diff] [blame] | 3390 | void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv, |
| 3391 | unsigned int pipe_mask) |
Paulo Zanoni | d49bdb0 | 2014-07-04 11:50:31 -0300 | [diff] [blame] | 3392 | { |
Paulo Zanoni | 1180e20 | 2014-10-07 18:02:52 -0300 | [diff] [blame] | 3393 | uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN; |
Ville Syrjälä | 6831f3e | 2016-02-19 20:47:31 +0200 | [diff] [blame] | 3394 | enum pipe pipe; |
Paulo Zanoni | d49bdb0 | 2014-07-04 11:50:31 -0300 | [diff] [blame] | 3395 | |
Daniel Vetter | 1332178 | 2014-09-15 14:55:29 +0200 | [diff] [blame] | 3396 | spin_lock_irq(&dev_priv->irq_lock); |
Ville Syrjälä | 6831f3e | 2016-02-19 20:47:31 +0200 | [diff] [blame] | 3397 | for_each_pipe_masked(dev_priv, pipe, pipe_mask) |
| 3398 | GEN8_IRQ_INIT_NDX(DE_PIPE, pipe, |
| 3399 | dev_priv->de_irq_mask[pipe], |
| 3400 | ~dev_priv->de_irq_mask[pipe] | extra_ier); |
Daniel Vetter | 1332178 | 2014-09-15 14:55:29 +0200 | [diff] [blame] | 3401 | spin_unlock_irq(&dev_priv->irq_lock); |
Paulo Zanoni | d49bdb0 | 2014-07-04 11:50:31 -0300 | [diff] [blame] | 3402 | } |
| 3403 | |
Ville Syrjälä | aae8ba8 | 2016-02-19 20:47:30 +0200 | [diff] [blame] | 3404 | void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv, |
| 3405 | unsigned int pipe_mask) |
| 3406 | { |
Ville Syrjälä | 6831f3e | 2016-02-19 20:47:31 +0200 | [diff] [blame] | 3407 | enum pipe pipe; |
| 3408 | |
Ville Syrjälä | aae8ba8 | 2016-02-19 20:47:30 +0200 | [diff] [blame] | 3409 | spin_lock_irq(&dev_priv->irq_lock); |
Ville Syrjälä | 6831f3e | 2016-02-19 20:47:31 +0200 | [diff] [blame] | 3410 | for_each_pipe_masked(dev_priv, pipe, pipe_mask) |
| 3411 | GEN8_IRQ_RESET_NDX(DE_PIPE, pipe); |
Ville Syrjälä | aae8ba8 | 2016-02-19 20:47:30 +0200 | [diff] [blame] | 3412 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3413 | |
| 3414 | /* make sure we're done processing display irqs */ |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 3415 | synchronize_irq(dev_priv->drm.irq); |
Ville Syrjälä | aae8ba8 | 2016-02-19 20:47:30 +0200 | [diff] [blame] | 3416 | } |
| 3417 | |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 3418 | static void cherryview_irq_preinstall(struct drm_device *dev) |
| 3419 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3420 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 3421 | |
| 3422 | I915_WRITE(GEN8_MASTER_IRQ, 0); |
| 3423 | POSTING_READ(GEN8_MASTER_IRQ); |
| 3424 | |
Daniel Vetter | d6e3cca | 2014-05-22 22:18:22 +0200 | [diff] [blame] | 3425 | gen8_gt_irq_reset(dev_priv); |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 3426 | |
| 3427 | GEN5_IRQ_RESET(GEN8_PCU_); |
| 3428 | |
Ville Syrjälä | ad22d10 | 2016-04-12 18:56:14 +0300 | [diff] [blame] | 3429 | spin_lock_irq(&dev_priv->irq_lock); |
Ville Syrjälä | 9918271 | 2016-04-11 16:56:25 +0300 | [diff] [blame] | 3430 | if (dev_priv->display_irqs_enabled) |
| 3431 | vlv_display_irq_reset(dev_priv); |
Ville Syrjälä | ad22d10 | 2016-04-12 18:56:14 +0300 | [diff] [blame] | 3432 | spin_unlock_irq(&dev_priv->irq_lock); |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 3433 | } |
| 3434 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 3435 | static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 87a0210 | 2015-08-27 23:55:57 +0300 | [diff] [blame] | 3436 | const u32 hpd[HPD_NUM_PINS]) |
| 3437 | { |
Ville Syrjälä | 87a0210 | 2015-08-27 23:55:57 +0300 | [diff] [blame] | 3438 | struct intel_encoder *encoder; |
| 3439 | u32 enabled_irqs = 0; |
| 3440 | |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 3441 | for_each_intel_encoder(&dev_priv->drm, encoder) |
Ville Syrjälä | 87a0210 | 2015-08-27 23:55:57 +0300 | [diff] [blame] | 3442 | if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED) |
| 3443 | enabled_irqs |= hpd[encoder->hpd_pin]; |
| 3444 | |
| 3445 | return enabled_irqs; |
| 3446 | } |
| 3447 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 3448 | static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv) |
Keith Packard | 7fe0b97 | 2011-09-19 13:31:02 -0700 | [diff] [blame] | 3449 | { |
Ville Syrjälä | 87a0210 | 2015-08-27 23:55:57 +0300 | [diff] [blame] | 3450 | u32 hotplug_irqs, hotplug, enabled_irqs; |
Keith Packard | 7fe0b97 | 2011-09-19 13:31:02 -0700 | [diff] [blame] | 3451 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 3452 | if (HAS_PCH_IBX(dev_priv)) { |
Daniel Vetter | fee884e | 2013-07-04 23:35:21 +0200 | [diff] [blame] | 3453 | hotplug_irqs = SDE_HOTPLUG_MASK; |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 3454 | enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx); |
Daniel Vetter | 82a28bc | 2013-03-27 15:55:01 +0100 | [diff] [blame] | 3455 | } else { |
Daniel Vetter | fee884e | 2013-07-04 23:35:21 +0200 | [diff] [blame] | 3456 | hotplug_irqs = SDE_HOTPLUG_MASK_CPT; |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 3457 | enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt); |
Daniel Vetter | 82a28bc | 2013-03-27 15:55:01 +0100 | [diff] [blame] | 3458 | } |
| 3459 | |
Daniel Vetter | fee884e | 2013-07-04 23:35:21 +0200 | [diff] [blame] | 3460 | ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); |
Daniel Vetter | 82a28bc | 2013-03-27 15:55:01 +0100 | [diff] [blame] | 3461 | |
| 3462 | /* |
| 3463 | * Enable digital hotplug on the PCH, and configure the DP short pulse |
Ville Syrjälä | 6dbf30c | 2015-08-27 23:56:02 +0300 | [diff] [blame] | 3464 | * duration to 2ms (which is the minimum in the Display Port spec). |
| 3465 | * The pulse duration bits are reserved on LPT+. |
Daniel Vetter | 82a28bc | 2013-03-27 15:55:01 +0100 | [diff] [blame] | 3466 | */ |
Keith Packard | 7fe0b97 | 2011-09-19 13:31:02 -0700 | [diff] [blame] | 3467 | hotplug = I915_READ(PCH_PORT_HOTPLUG); |
| 3468 | hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK); |
| 3469 | hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms; |
| 3470 | hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms; |
| 3471 | hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms; |
Ville Syrjälä | 0b2eb33 | 2015-08-27 23:56:05 +0300 | [diff] [blame] | 3472 | /* |
| 3473 | * When CPU and PCH are on the same package, port A |
| 3474 | * HPD must be enabled in both north and south. |
| 3475 | */ |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 3476 | if (HAS_PCH_LPT_LP(dev_priv)) |
Ville Syrjälä | 0b2eb33 | 2015-08-27 23:56:05 +0300 | [diff] [blame] | 3477 | hotplug |= PORTA_HOTPLUG_ENABLE; |
Keith Packard | 7fe0b97 | 2011-09-19 13:31:02 -0700 | [diff] [blame] | 3478 | I915_WRITE(PCH_PORT_HOTPLUG, hotplug); |
Ville Syrjälä | 6dbf30c | 2015-08-27 23:56:02 +0300 | [diff] [blame] | 3479 | } |
Xiong Zhang | 26951ca | 2015-08-17 15:55:50 +0800 | [diff] [blame] | 3480 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 3481 | static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 6dbf30c | 2015-08-27 23:56:02 +0300 | [diff] [blame] | 3482 | { |
Ville Syrjälä | 6dbf30c | 2015-08-27 23:56:02 +0300 | [diff] [blame] | 3483 | u32 hotplug_irqs, hotplug, enabled_irqs; |
| 3484 | |
| 3485 | hotplug_irqs = SDE_HOTPLUG_MASK_SPT; |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 3486 | enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt); |
Ville Syrjälä | 6dbf30c | 2015-08-27 23:56:02 +0300 | [diff] [blame] | 3487 | |
| 3488 | ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); |
| 3489 | |
| 3490 | /* Enable digital hotplug on the PCH */ |
| 3491 | hotplug = I915_READ(PCH_PORT_HOTPLUG); |
| 3492 | hotplug |= PORTD_HOTPLUG_ENABLE | PORTC_HOTPLUG_ENABLE | |
Ville Syrjälä | 74c0b39 | 2015-08-27 23:56:07 +0300 | [diff] [blame] | 3493 | PORTB_HOTPLUG_ENABLE | PORTA_HOTPLUG_ENABLE; |
Ville Syrjälä | 6dbf30c | 2015-08-27 23:56:02 +0300 | [diff] [blame] | 3494 | I915_WRITE(PCH_PORT_HOTPLUG, hotplug); |
| 3495 | |
| 3496 | hotplug = I915_READ(PCH_PORT_HOTPLUG2); |
| 3497 | hotplug |= PORTE_HOTPLUG_ENABLE; |
| 3498 | I915_WRITE(PCH_PORT_HOTPLUG2, hotplug); |
Keith Packard | 7fe0b97 | 2011-09-19 13:31:02 -0700 | [diff] [blame] | 3499 | } |
| 3500 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 3501 | static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv) |
Ville Syrjälä | e4ce95a | 2015-08-27 23:56:03 +0300 | [diff] [blame] | 3502 | { |
Ville Syrjälä | e4ce95a | 2015-08-27 23:56:03 +0300 | [diff] [blame] | 3503 | u32 hotplug_irqs, hotplug, enabled_irqs; |
| 3504 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 3505 | if (INTEL_GEN(dev_priv) >= 8) { |
Ville Syrjälä | 3a3b3c7 | 2015-08-27 23:56:06 +0300 | [diff] [blame] | 3506 | hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG; |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 3507 | enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw); |
Ville Syrjälä | 3a3b3c7 | 2015-08-27 23:56:06 +0300 | [diff] [blame] | 3508 | |
| 3509 | bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs); |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 3510 | } else if (INTEL_GEN(dev_priv) >= 7) { |
Ville Syrjälä | 23bb4cb | 2015-08-27 23:56:04 +0300 | [diff] [blame] | 3511 | hotplug_irqs = DE_DP_A_HOTPLUG_IVB; |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 3512 | enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb); |
Ville Syrjälä | 3a3b3c7 | 2015-08-27 23:56:06 +0300 | [diff] [blame] | 3513 | |
| 3514 | ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs); |
Ville Syrjälä | 23bb4cb | 2015-08-27 23:56:04 +0300 | [diff] [blame] | 3515 | } else { |
| 3516 | hotplug_irqs = DE_DP_A_HOTPLUG; |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 3517 | enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk); |
Ville Syrjälä | e4ce95a | 2015-08-27 23:56:03 +0300 | [diff] [blame] | 3518 | |
Ville Syrjälä | 3a3b3c7 | 2015-08-27 23:56:06 +0300 | [diff] [blame] | 3519 | ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs); |
| 3520 | } |
Ville Syrjälä | e4ce95a | 2015-08-27 23:56:03 +0300 | [diff] [blame] | 3521 | |
| 3522 | /* |
| 3523 | * Enable digital hotplug on the CPU, and configure the DP short pulse |
| 3524 | * duration to 2ms (which is the minimum in the Display Port spec) |
Ville Syrjälä | 23bb4cb | 2015-08-27 23:56:04 +0300 | [diff] [blame] | 3525 | * The pulse duration bits are reserved on HSW+. |
Ville Syrjälä | e4ce95a | 2015-08-27 23:56:03 +0300 | [diff] [blame] | 3526 | */ |
| 3527 | hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL); |
| 3528 | hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK; |
| 3529 | hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE | DIGITAL_PORTA_PULSE_DURATION_2ms; |
| 3530 | I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug); |
| 3531 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 3532 | ibx_hpd_irq_setup(dev_priv); |
Ville Syrjälä | e4ce95a | 2015-08-27 23:56:03 +0300 | [diff] [blame] | 3533 | } |
| 3534 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 3535 | static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv) |
Shashank Sharma | e0a20ad | 2015-03-27 14:54:14 +0200 | [diff] [blame] | 3536 | { |
Ville Syrjälä | a52bb15 | 2015-08-27 23:56:11 +0300 | [diff] [blame] | 3537 | u32 hotplug_irqs, hotplug, enabled_irqs; |
Shashank Sharma | e0a20ad | 2015-03-27 14:54:14 +0200 | [diff] [blame] | 3538 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 3539 | enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt); |
Ville Syrjälä | a52bb15 | 2015-08-27 23:56:11 +0300 | [diff] [blame] | 3540 | hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK; |
Shashank Sharma | e0a20ad | 2015-03-27 14:54:14 +0200 | [diff] [blame] | 3541 | |
Ville Syrjälä | a52bb15 | 2015-08-27 23:56:11 +0300 | [diff] [blame] | 3542 | bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs); |
Shashank Sharma | e0a20ad | 2015-03-27 14:54:14 +0200 | [diff] [blame] | 3543 | |
Ville Syrjälä | a52bb15 | 2015-08-27 23:56:11 +0300 | [diff] [blame] | 3544 | hotplug = I915_READ(PCH_PORT_HOTPLUG); |
| 3545 | hotplug |= PORTC_HOTPLUG_ENABLE | PORTB_HOTPLUG_ENABLE | |
| 3546 | PORTA_HOTPLUG_ENABLE; |
Shubhangi Shrivastava | d252bf6 | 2016-03-31 16:11:47 +0530 | [diff] [blame] | 3547 | |
| 3548 | DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n", |
| 3549 | hotplug, enabled_irqs); |
| 3550 | hotplug &= ~BXT_DDI_HPD_INVERT_MASK; |
| 3551 | |
| 3552 | /* |
| 3553 | * For BXT invert bit has to be set based on AOB design |
| 3554 | * for HPD detection logic, update it based on VBT fields. |
| 3555 | */ |
| 3556 | |
| 3557 | if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) && |
| 3558 | intel_bios_is_port_hpd_inverted(dev_priv, PORT_A)) |
| 3559 | hotplug |= BXT_DDIA_HPD_INVERT; |
| 3560 | if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) && |
| 3561 | intel_bios_is_port_hpd_inverted(dev_priv, PORT_B)) |
| 3562 | hotplug |= BXT_DDIB_HPD_INVERT; |
| 3563 | if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) && |
| 3564 | intel_bios_is_port_hpd_inverted(dev_priv, PORT_C)) |
| 3565 | hotplug |= BXT_DDIC_HPD_INVERT; |
| 3566 | |
Ville Syrjälä | a52bb15 | 2015-08-27 23:56:11 +0300 | [diff] [blame] | 3567 | I915_WRITE(PCH_PORT_HOTPLUG, hotplug); |
Shashank Sharma | e0a20ad | 2015-03-27 14:54:14 +0200 | [diff] [blame] | 3568 | } |
| 3569 | |
Paulo Zanoni | d46da43 | 2013-02-08 17:35:15 -0200 | [diff] [blame] | 3570 | static void ibx_irq_postinstall(struct drm_device *dev) |
| 3571 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3572 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 82a28bc | 2013-03-27 15:55:01 +0100 | [diff] [blame] | 3573 | u32 mask; |
Paulo Zanoni | d46da43 | 2013-02-08 17:35:15 -0200 | [diff] [blame] | 3574 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3575 | if (HAS_PCH_NOP(dev_priv)) |
Daniel Vetter | 692a04c | 2013-05-29 21:43:05 +0200 | [diff] [blame] | 3576 | return; |
| 3577 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3578 | if (HAS_PCH_IBX(dev_priv)) |
Daniel Vetter | 5c673b6 | 2014-03-07 20:34:46 +0100 | [diff] [blame] | 3579 | mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON; |
Paulo Zanoni | 105b122 | 2014-04-01 15:37:17 -0300 | [diff] [blame] | 3580 | else |
Daniel Vetter | 5c673b6 | 2014-03-07 20:34:46 +0100 | [diff] [blame] | 3581 | mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 3582 | |
Ville Syrjälä | b51a284 | 2015-09-18 20:03:41 +0300 | [diff] [blame] | 3583 | gen5_assert_iir_is_zero(dev_priv, SDEIIR); |
Paulo Zanoni | d46da43 | 2013-02-08 17:35:15 -0200 | [diff] [blame] | 3584 | I915_WRITE(SDEIMR, ~mask); |
Paulo Zanoni | d46da43 | 2013-02-08 17:35:15 -0200 | [diff] [blame] | 3585 | } |
| 3586 | |
Daniel Vetter | 0a9a8c9 | 2013-07-12 22:43:26 +0200 | [diff] [blame] | 3587 | static void gen5_gt_irq_postinstall(struct drm_device *dev) |
| 3588 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3589 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 0a9a8c9 | 2013-07-12 22:43:26 +0200 | [diff] [blame] | 3590 | u32 pm_irqs, gt_irqs; |
| 3591 | |
| 3592 | pm_irqs = gt_irqs = 0; |
| 3593 | |
| 3594 | dev_priv->gt_irq_mask = ~0; |
Tvrtko Ursulin | 3c9192b | 2016-10-13 11:03:05 +0100 | [diff] [blame] | 3595 | if (HAS_L3_DPF(dev_priv)) { |
Daniel Vetter | 0a9a8c9 | 2013-07-12 22:43:26 +0200 | [diff] [blame] | 3596 | /* L3 parity interrupt is always unmasked. */ |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 3597 | dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev_priv); |
| 3598 | gt_irqs |= GT_PARITY_ERROR(dev_priv); |
Daniel Vetter | 0a9a8c9 | 2013-07-12 22:43:26 +0200 | [diff] [blame] | 3599 | } |
| 3600 | |
| 3601 | gt_irqs |= GT_RENDER_USER_INTERRUPT; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3602 | if (IS_GEN5(dev_priv)) { |
Chris Wilson | f8973c2 | 2016-07-01 17:23:21 +0100 | [diff] [blame] | 3603 | gt_irqs |= ILK_BSD_USER_INTERRUPT; |
Daniel Vetter | 0a9a8c9 | 2013-07-12 22:43:26 +0200 | [diff] [blame] | 3604 | } else { |
| 3605 | gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT; |
| 3606 | } |
| 3607 | |
Paulo Zanoni | 3507989 | 2014-04-01 15:37:15 -0300 | [diff] [blame] | 3608 | GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs); |
Daniel Vetter | 0a9a8c9 | 2013-07-12 22:43:26 +0200 | [diff] [blame] | 3609 | |
| 3610 | if (INTEL_INFO(dev)->gen >= 6) { |
Imre Deak | 78e68d3 | 2014-12-15 18:59:27 +0200 | [diff] [blame] | 3611 | /* |
| 3612 | * RPS interrupts will get enabled/disabled on demand when RPS |
| 3613 | * itself is enabled/disabled. |
| 3614 | */ |
Akash Goel | f4e9af4 | 2016-10-12 21:54:30 +0530 | [diff] [blame] | 3615 | if (HAS_VEBOX(dev_priv)) { |
Daniel Vetter | 0a9a8c9 | 2013-07-12 22:43:26 +0200 | [diff] [blame] | 3616 | pm_irqs |= PM_VEBOX_USER_INTERRUPT; |
Akash Goel | f4e9af4 | 2016-10-12 21:54:30 +0530 | [diff] [blame] | 3617 | dev_priv->pm_ier |= PM_VEBOX_USER_INTERRUPT; |
| 3618 | } |
Daniel Vetter | 0a9a8c9 | 2013-07-12 22:43:26 +0200 | [diff] [blame] | 3619 | |
Akash Goel | f4e9af4 | 2016-10-12 21:54:30 +0530 | [diff] [blame] | 3620 | dev_priv->pm_imr = 0xffffffff; |
| 3621 | GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_imr, pm_irqs); |
Daniel Vetter | 0a9a8c9 | 2013-07-12 22:43:26 +0200 | [diff] [blame] | 3622 | } |
| 3623 | } |
| 3624 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 3625 | static int ironlake_irq_postinstall(struct drm_device *dev) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 3626 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3627 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | 8e76f8d | 2013-07-12 20:01:56 -0300 | [diff] [blame] | 3628 | u32 display_mask, extra_mask; |
| 3629 | |
| 3630 | if (INTEL_INFO(dev)->gen >= 7) { |
| 3631 | display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | |
| 3632 | DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB | |
| 3633 | DE_PLANEB_FLIP_DONE_IVB | |
Daniel Vetter | 5c673b6 | 2014-03-07 20:34:46 +0100 | [diff] [blame] | 3634 | DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB); |
Paulo Zanoni | 8e76f8d | 2013-07-12 20:01:56 -0300 | [diff] [blame] | 3635 | extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB | |
Ville Syrjälä | 23bb4cb | 2015-08-27 23:56:04 +0300 | [diff] [blame] | 3636 | DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB | |
| 3637 | DE_DP_A_HOTPLUG_IVB); |
Paulo Zanoni | 8e76f8d | 2013-07-12 20:01:56 -0300 | [diff] [blame] | 3638 | } else { |
| 3639 | display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | |
| 3640 | DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE | |
Daniel Vetter | 5b3a856 | 2013-10-16 22:55:48 +0200 | [diff] [blame] | 3641 | DE_AUX_CHANNEL_A | |
Daniel Vetter | 5b3a856 | 2013-10-16 22:55:48 +0200 | [diff] [blame] | 3642 | DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE | |
| 3643 | DE_POISON); |
Ville Syrjälä | e4ce95a | 2015-08-27 23:56:03 +0300 | [diff] [blame] | 3644 | extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT | |
| 3645 | DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN | |
| 3646 | DE_DP_A_HOTPLUG); |
Paulo Zanoni | 8e76f8d | 2013-07-12 20:01:56 -0300 | [diff] [blame] | 3647 | } |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 3648 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 3649 | dev_priv->irq_mask = ~display_mask; |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 3650 | |
Paulo Zanoni | 0c84121 | 2014-04-01 15:37:27 -0300 | [diff] [blame] | 3651 | I915_WRITE(HWSTAM, 0xeffe); |
| 3652 | |
Paulo Zanoni | 622364b | 2014-04-01 15:37:22 -0300 | [diff] [blame] | 3653 | ibx_irq_pre_postinstall(dev); |
| 3654 | |
Paulo Zanoni | 3507989 | 2014-04-01 15:37:15 -0300 | [diff] [blame] | 3655 | GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 3656 | |
Daniel Vetter | 0a9a8c9 | 2013-07-12 22:43:26 +0200 | [diff] [blame] | 3657 | gen5_gt_irq_postinstall(dev); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 3658 | |
Paulo Zanoni | d46da43 | 2013-02-08 17:35:15 -0200 | [diff] [blame] | 3659 | ibx_irq_postinstall(dev); |
Keith Packard | 7fe0b97 | 2011-09-19 13:31:02 -0700 | [diff] [blame] | 3660 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 3661 | if (IS_IRONLAKE_M(dev_priv)) { |
Daniel Vetter | 6005ce4 | 2013-06-27 13:44:59 +0200 | [diff] [blame] | 3662 | /* Enable PCU event interrupts |
| 3663 | * |
| 3664 | * spinlocking not required here for correctness since interrupt |
Daniel Vetter | 4bc9d43 | 2013-06-27 13:44:58 +0200 | [diff] [blame] | 3665 | * setup is guaranteed to run in single-threaded context. But we |
| 3666 | * need it to make the assert_spin_locked happy. */ |
Daniel Vetter | d620743 | 2014-09-15 14:55:27 +0200 | [diff] [blame] | 3667 | spin_lock_irq(&dev_priv->irq_lock); |
Ville Syrjälä | fbdedaea | 2015-11-23 18:06:16 +0200 | [diff] [blame] | 3668 | ilk_enable_display_irq(dev_priv, DE_PCU_EVENT); |
Daniel Vetter | d620743 | 2014-09-15 14:55:27 +0200 | [diff] [blame] | 3669 | spin_unlock_irq(&dev_priv->irq_lock); |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 3670 | } |
| 3671 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 3672 | return 0; |
| 3673 | } |
| 3674 | |
Imre Deak | f8b79e5 | 2014-03-04 19:23:07 +0200 | [diff] [blame] | 3675 | void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv) |
| 3676 | { |
| 3677 | assert_spin_locked(&dev_priv->irq_lock); |
| 3678 | |
| 3679 | if (dev_priv->display_irqs_enabled) |
| 3680 | return; |
| 3681 | |
| 3682 | dev_priv->display_irqs_enabled = true; |
| 3683 | |
Ville Syrjälä | d6c6980 | 2016-04-11 16:56:27 +0300 | [diff] [blame] | 3684 | if (intel_irqs_enabled(dev_priv)) { |
| 3685 | vlv_display_irq_reset(dev_priv); |
Ville Syrjälä | ad22d10 | 2016-04-12 18:56:14 +0300 | [diff] [blame] | 3686 | vlv_display_irq_postinstall(dev_priv); |
Ville Syrjälä | d6c6980 | 2016-04-11 16:56:27 +0300 | [diff] [blame] | 3687 | } |
Imre Deak | f8b79e5 | 2014-03-04 19:23:07 +0200 | [diff] [blame] | 3688 | } |
| 3689 | |
| 3690 | void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv) |
| 3691 | { |
| 3692 | assert_spin_locked(&dev_priv->irq_lock); |
| 3693 | |
| 3694 | if (!dev_priv->display_irqs_enabled) |
| 3695 | return; |
| 3696 | |
| 3697 | dev_priv->display_irqs_enabled = false; |
| 3698 | |
Imre Deak | 950eaba | 2014-09-08 15:21:09 +0300 | [diff] [blame] | 3699 | if (intel_irqs_enabled(dev_priv)) |
Ville Syrjälä | ad22d10 | 2016-04-12 18:56:14 +0300 | [diff] [blame] | 3700 | vlv_display_irq_reset(dev_priv); |
Imre Deak | f8b79e5 | 2014-03-04 19:23:07 +0200 | [diff] [blame] | 3701 | } |
| 3702 | |
Ville Syrjälä | 0e6c9a9 | 2014-10-30 19:43:00 +0200 | [diff] [blame] | 3703 | |
| 3704 | static int valleyview_irq_postinstall(struct drm_device *dev) |
| 3705 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3706 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 0e6c9a9 | 2014-10-30 19:43:00 +0200 | [diff] [blame] | 3707 | |
Daniel Vetter | 0a9a8c9 | 2013-07-12 22:43:26 +0200 | [diff] [blame] | 3708 | gen5_gt_irq_postinstall(dev); |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 3709 | |
Ville Syrjälä | ad22d10 | 2016-04-12 18:56:14 +0300 | [diff] [blame] | 3710 | spin_lock_irq(&dev_priv->irq_lock); |
Ville Syrjälä | 9918271 | 2016-04-11 16:56:25 +0300 | [diff] [blame] | 3711 | if (dev_priv->display_irqs_enabled) |
| 3712 | vlv_display_irq_postinstall(dev_priv); |
Ville Syrjälä | ad22d10 | 2016-04-12 18:56:14 +0300 | [diff] [blame] | 3713 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3714 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 3715 | I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE); |
Ville Syrjälä | 34c7b8a | 2016-04-13 21:19:48 +0300 | [diff] [blame] | 3716 | POSTING_READ(VLV_MASTER_IER); |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 3717 | |
| 3718 | return 0; |
| 3719 | } |
| 3720 | |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3721 | static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv) |
| 3722 | { |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3723 | /* These are interrupts we'll toggle with the ring mask register */ |
| 3724 | uint32_t gt_interrupts[] = { |
| 3725 | GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT | |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 3726 | GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT | |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 3727 | GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT | |
| 3728 | GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT, |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3729 | GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT | |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 3730 | GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT | |
| 3731 | GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT | |
| 3732 | GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT, |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3733 | 0, |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 3734 | GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT | |
| 3735 | GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3736 | }; |
| 3737 | |
Tvrtko Ursulin | 9873573 | 2016-04-19 16:46:08 +0100 | [diff] [blame] | 3738 | if (HAS_L3_DPF(dev_priv)) |
| 3739 | gt_interrupts[0] |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT; |
| 3740 | |
Akash Goel | f4e9af4 | 2016-10-12 21:54:30 +0530 | [diff] [blame] | 3741 | dev_priv->pm_ier = 0x0; |
| 3742 | dev_priv->pm_imr = ~dev_priv->pm_ier; |
Deepak S | 9a2d2d8 | 2014-08-22 08:32:40 +0530 | [diff] [blame] | 3743 | GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]); |
| 3744 | GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]); |
Imre Deak | 78e68d3 | 2014-12-15 18:59:27 +0200 | [diff] [blame] | 3745 | /* |
| 3746 | * RPS interrupts will get enabled/disabled on demand when RPS itself |
Sagar Arun Kamble | 26705e2 | 2016-10-12 21:54:31 +0530 | [diff] [blame^] | 3747 | * is enabled/disabled. Same wil be the case for GuC interrupts. |
Imre Deak | 78e68d3 | 2014-12-15 18:59:27 +0200 | [diff] [blame] | 3748 | */ |
Akash Goel | f4e9af4 | 2016-10-12 21:54:30 +0530 | [diff] [blame] | 3749 | GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_imr, dev_priv->pm_ier); |
Deepak S | 9a2d2d8 | 2014-08-22 08:32:40 +0530 | [diff] [blame] | 3750 | GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3751 | } |
| 3752 | |
| 3753 | static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv) |
| 3754 | { |
Damien Lespiau | 770de83d | 2014-03-20 20:45:01 +0000 | [diff] [blame] | 3755 | uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE; |
| 3756 | uint32_t de_pipe_enables; |
Ville Syrjälä | 3a3b3c7 | 2015-08-27 23:56:06 +0300 | [diff] [blame] | 3757 | u32 de_port_masked = GEN8_AUX_CHANNEL_A; |
| 3758 | u32 de_port_enables; |
Ville Syrjälä | 11825b0 | 2016-05-19 12:14:43 +0300 | [diff] [blame] | 3759 | u32 de_misc_masked = GEN8_DE_MISC_GSE; |
Ville Syrjälä | 3a3b3c7 | 2015-08-27 23:56:06 +0300 | [diff] [blame] | 3760 | enum pipe pipe; |
Damien Lespiau | 770de83d | 2014-03-20 20:45:01 +0000 | [diff] [blame] | 3761 | |
Rodrigo Vivi | b4834a5 | 2015-09-02 15:19:24 -0700 | [diff] [blame] | 3762 | if (INTEL_INFO(dev_priv)->gen >= 9) { |
Damien Lespiau | 770de83d | 2014-03-20 20:45:01 +0000 | [diff] [blame] | 3763 | de_pipe_masked |= GEN9_PIPE_PLANE1_FLIP_DONE | |
| 3764 | GEN9_DE_PIPE_IRQ_FAULT_ERRORS; |
Ville Syrjälä | 3a3b3c7 | 2015-08-27 23:56:06 +0300 | [diff] [blame] | 3765 | de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C | |
| 3766 | GEN9_AUX_CHANNEL_D; |
Shashank Sharma | 9e63743 | 2014-08-22 17:40:43 +0530 | [diff] [blame] | 3767 | if (IS_BROXTON(dev_priv)) |
Ville Syrjälä | 3a3b3c7 | 2015-08-27 23:56:06 +0300 | [diff] [blame] | 3768 | de_port_masked |= BXT_DE_PORT_GMBUS; |
| 3769 | } else { |
Damien Lespiau | 770de83d | 2014-03-20 20:45:01 +0000 | [diff] [blame] | 3770 | de_pipe_masked |= GEN8_PIPE_PRIMARY_FLIP_DONE | |
| 3771 | GEN8_DE_PIPE_IRQ_FAULT_ERRORS; |
Ville Syrjälä | 3a3b3c7 | 2015-08-27 23:56:06 +0300 | [diff] [blame] | 3772 | } |
Damien Lespiau | 770de83d | 2014-03-20 20:45:01 +0000 | [diff] [blame] | 3773 | |
| 3774 | de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK | |
| 3775 | GEN8_PIPE_FIFO_UNDERRUN; |
| 3776 | |
Ville Syrjälä | 3a3b3c7 | 2015-08-27 23:56:06 +0300 | [diff] [blame] | 3777 | de_port_enables = de_port_masked; |
Ville Syrjälä | a52bb15 | 2015-08-27 23:56:11 +0300 | [diff] [blame] | 3778 | if (IS_BROXTON(dev_priv)) |
| 3779 | de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK; |
| 3780 | else if (IS_BROADWELL(dev_priv)) |
Ville Syrjälä | 3a3b3c7 | 2015-08-27 23:56:06 +0300 | [diff] [blame] | 3781 | de_port_enables |= GEN8_PORT_DP_A_HOTPLUG; |
| 3782 | |
Daniel Vetter | 13b3a0a | 2013-11-07 15:31:52 +0100 | [diff] [blame] | 3783 | dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked; |
| 3784 | dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked; |
| 3785 | dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked; |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3786 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3787 | for_each_pipe(dev_priv, pipe) |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 3788 | if (intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | 813bde4 | 2014-07-04 11:50:29 -0300 | [diff] [blame] | 3789 | POWER_DOMAIN_PIPE(pipe))) |
| 3790 | GEN8_IRQ_INIT_NDX(DE_PIPE, pipe, |
| 3791 | dev_priv->de_irq_mask[pipe], |
| 3792 | de_pipe_enables); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3793 | |
Ville Syrjälä | 3a3b3c7 | 2015-08-27 23:56:06 +0300 | [diff] [blame] | 3794 | GEN5_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables); |
Ville Syrjälä | 11825b0 | 2016-05-19 12:14:43 +0300 | [diff] [blame] | 3795 | GEN5_IRQ_INIT(GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3796 | } |
| 3797 | |
| 3798 | static int gen8_irq_postinstall(struct drm_device *dev) |
| 3799 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3800 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3801 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3802 | if (HAS_PCH_SPLIT(dev_priv)) |
Shashank Sharma | 266ea3d | 2014-08-22 17:40:42 +0530 | [diff] [blame] | 3803 | ibx_irq_pre_postinstall(dev); |
Paulo Zanoni | 622364b | 2014-04-01 15:37:22 -0300 | [diff] [blame] | 3804 | |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3805 | gen8_gt_irq_postinstall(dev_priv); |
| 3806 | gen8_de_irq_postinstall(dev_priv); |
| 3807 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3808 | if (HAS_PCH_SPLIT(dev_priv)) |
Shashank Sharma | 266ea3d | 2014-08-22 17:40:42 +0530 | [diff] [blame] | 3809 | ibx_irq_postinstall(dev); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3810 | |
Ville Syrjälä | e5328c4 | 2016-04-13 21:19:47 +0300 | [diff] [blame] | 3811 | I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3812 | POSTING_READ(GEN8_MASTER_IRQ); |
| 3813 | |
| 3814 | return 0; |
| 3815 | } |
| 3816 | |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 3817 | static int cherryview_irq_postinstall(struct drm_device *dev) |
| 3818 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3819 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 3820 | |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 3821 | gen8_gt_irq_postinstall(dev_priv); |
| 3822 | |
Ville Syrjälä | ad22d10 | 2016-04-12 18:56:14 +0300 | [diff] [blame] | 3823 | spin_lock_irq(&dev_priv->irq_lock); |
Ville Syrjälä | 9918271 | 2016-04-11 16:56:25 +0300 | [diff] [blame] | 3824 | if (dev_priv->display_irqs_enabled) |
| 3825 | vlv_display_irq_postinstall(dev_priv); |
Ville Syrjälä | ad22d10 | 2016-04-12 18:56:14 +0300 | [diff] [blame] | 3826 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3827 | |
Ville Syrjälä | e5328c4 | 2016-04-13 21:19:47 +0300 | [diff] [blame] | 3828 | I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 3829 | POSTING_READ(GEN8_MASTER_IRQ); |
| 3830 | |
| 3831 | return 0; |
| 3832 | } |
| 3833 | |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3834 | static void gen8_irq_uninstall(struct drm_device *dev) |
| 3835 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3836 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3837 | |
| 3838 | if (!dev_priv) |
| 3839 | return; |
| 3840 | |
Paulo Zanoni | 823f6b3 | 2014-04-01 15:37:26 -0300 | [diff] [blame] | 3841 | gen8_irq_reset(dev); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 3842 | } |
| 3843 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 3844 | static void valleyview_irq_uninstall(struct drm_device *dev) |
| 3845 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3846 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 3847 | |
| 3848 | if (!dev_priv) |
| 3849 | return; |
| 3850 | |
Imre Deak | 843d0e7 | 2014-04-14 20:24:23 +0300 | [diff] [blame] | 3851 | I915_WRITE(VLV_MASTER_IER, 0); |
Ville Syrjälä | 34c7b8a | 2016-04-13 21:19:48 +0300 | [diff] [blame] | 3852 | POSTING_READ(VLV_MASTER_IER); |
Imre Deak | 843d0e7 | 2014-04-14 20:24:23 +0300 | [diff] [blame] | 3853 | |
Ville Syrjälä | 893fce8 | 2014-10-30 19:42:56 +0200 | [diff] [blame] | 3854 | gen5_gt_irq_reset(dev); |
| 3855 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 3856 | I915_WRITE(HWSTAM, 0xffffffff); |
Imre Deak | f8b79e5 | 2014-03-04 19:23:07 +0200 | [diff] [blame] | 3857 | |
Ville Syrjälä | ad22d10 | 2016-04-12 18:56:14 +0300 | [diff] [blame] | 3858 | spin_lock_irq(&dev_priv->irq_lock); |
Ville Syrjälä | 9918271 | 2016-04-11 16:56:25 +0300 | [diff] [blame] | 3859 | if (dev_priv->display_irqs_enabled) |
| 3860 | vlv_display_irq_reset(dev_priv); |
Ville Syrjälä | ad22d10 | 2016-04-12 18:56:14 +0300 | [diff] [blame] | 3861 | spin_unlock_irq(&dev_priv->irq_lock); |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 3862 | } |
| 3863 | |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 3864 | static void cherryview_irq_uninstall(struct drm_device *dev) |
| 3865 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3866 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 3867 | |
| 3868 | if (!dev_priv) |
| 3869 | return; |
| 3870 | |
| 3871 | I915_WRITE(GEN8_MASTER_IRQ, 0); |
| 3872 | POSTING_READ(GEN8_MASTER_IRQ); |
| 3873 | |
Ville Syrjälä | a2c30fb | 2014-10-30 19:42:52 +0200 | [diff] [blame] | 3874 | gen8_gt_irq_reset(dev_priv); |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 3875 | |
Ville Syrjälä | a2c30fb | 2014-10-30 19:42:52 +0200 | [diff] [blame] | 3876 | GEN5_IRQ_RESET(GEN8_PCU_); |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 3877 | |
Ville Syrjälä | ad22d10 | 2016-04-12 18:56:14 +0300 | [diff] [blame] | 3878 | spin_lock_irq(&dev_priv->irq_lock); |
Ville Syrjälä | 9918271 | 2016-04-11 16:56:25 +0300 | [diff] [blame] | 3879 | if (dev_priv->display_irqs_enabled) |
| 3880 | vlv_display_irq_reset(dev_priv); |
Ville Syrjälä | ad22d10 | 2016-04-12 18:56:14 +0300 | [diff] [blame] | 3881 | spin_unlock_irq(&dev_priv->irq_lock); |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 3882 | } |
| 3883 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 3884 | static void ironlake_irq_uninstall(struct drm_device *dev) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 3885 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3886 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 4697995 | 2011-04-07 13:53:55 -0700 | [diff] [blame] | 3887 | |
| 3888 | if (!dev_priv) |
| 3889 | return; |
| 3890 | |
Paulo Zanoni | be30b29 | 2014-04-01 15:37:25 -0300 | [diff] [blame] | 3891 | ironlake_irq_reset(dev); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 3892 | } |
| 3893 | |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3894 | static void i8xx_irq_preinstall(struct drm_device * dev) |
| 3895 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3896 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3897 | int pipe; |
| 3898 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3899 | for_each_pipe(dev_priv, pipe) |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3900 | I915_WRITE(PIPESTAT(pipe), 0); |
| 3901 | I915_WRITE16(IMR, 0xffff); |
| 3902 | I915_WRITE16(IER, 0x0); |
| 3903 | POSTING_READ16(IER); |
| 3904 | } |
| 3905 | |
| 3906 | static int i8xx_irq_postinstall(struct drm_device *dev) |
| 3907 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3908 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3909 | |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3910 | I915_WRITE16(EMR, |
| 3911 | ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH)); |
| 3912 | |
| 3913 | /* Unmask the interrupts that we always want on. */ |
| 3914 | dev_priv->irq_mask = |
| 3915 | ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | |
| 3916 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | |
| 3917 | I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | |
Daniel Vetter | 37ef01a | 2015-04-01 13:43:46 +0200 | [diff] [blame] | 3918 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT); |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3919 | I915_WRITE16(IMR, dev_priv->irq_mask); |
| 3920 | |
| 3921 | I915_WRITE16(IER, |
| 3922 | I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | |
| 3923 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3924 | I915_USER_INTERRUPT); |
| 3925 | POSTING_READ16(IER); |
| 3926 | |
Daniel Vetter | 379ef82 | 2013-10-16 22:55:56 +0200 | [diff] [blame] | 3927 | /* Interrupt setup is already guaranteed to be single-threaded, this is |
| 3928 | * just to make the assert_spin_locked check happy. */ |
Daniel Vetter | d620743 | 2014-09-15 14:55:27 +0200 | [diff] [blame] | 3929 | spin_lock_irq(&dev_priv->irq_lock); |
Imre Deak | 755e901 | 2014-02-10 18:42:47 +0200 | [diff] [blame] | 3930 | i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); |
| 3931 | i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); |
Daniel Vetter | d620743 | 2014-09-15 14:55:27 +0200 | [diff] [blame] | 3932 | spin_unlock_irq(&dev_priv->irq_lock); |
Daniel Vetter | 379ef82 | 2013-10-16 22:55:56 +0200 | [diff] [blame] | 3933 | |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3934 | return 0; |
| 3935 | } |
| 3936 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 3937 | /* |
| 3938 | * Returns true when a page flip has completed. |
| 3939 | */ |
| 3940 | static bool i8xx_handle_vblank(struct drm_i915_private *dev_priv, |
| 3941 | int plane, int pipe, u32 iir) |
| 3942 | { |
| 3943 | u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane); |
| 3944 | |
| 3945 | if (!intel_pipe_handle_vblank(dev_priv, pipe)) |
| 3946 | return false; |
| 3947 | |
| 3948 | if ((iir & flip_pending) == 0) |
| 3949 | goto check_page_flip; |
| 3950 | |
| 3951 | /* We detect FlipDone by looking for the change in PendingFlip from '1' |
| 3952 | * to '0' on the following vblank, i.e. IIR has the Pendingflip |
| 3953 | * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence |
| 3954 | * the flip is completed (no longer pending). Since this doesn't raise |
| 3955 | * an interrupt per se, we watch for the change at vblank. |
| 3956 | */ |
| 3957 | if (I915_READ16(ISR) & flip_pending) |
| 3958 | goto check_page_flip; |
| 3959 | |
| 3960 | intel_finish_page_flip_cs(dev_priv, pipe); |
| 3961 | return true; |
| 3962 | |
| 3963 | check_page_flip: |
| 3964 | intel_check_page_flip(dev_priv, pipe); |
| 3965 | return false; |
| 3966 | } |
| 3967 | |
Daniel Vetter | ff1f525 | 2012-10-02 15:10:55 +0200 | [diff] [blame] | 3968 | static irqreturn_t i8xx_irq_handler(int irq, void *arg) |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3969 | { |
Daniel Vetter | 45a83f8 | 2014-05-12 19:17:55 +0200 | [diff] [blame] | 3970 | struct drm_device *dev = arg; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3971 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3972 | u16 iir, new_iir; |
| 3973 | u32 pipe_stats[2]; |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3974 | int pipe; |
| 3975 | u16 flip_mask = |
| 3976 | I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | |
| 3977 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 3978 | irqreturn_t ret; |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3979 | |
Imre Deak | 2dd2a88 | 2015-02-24 11:14:30 +0200 | [diff] [blame] | 3980 | if (!intel_irqs_enabled(dev_priv)) |
| 3981 | return IRQ_NONE; |
| 3982 | |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 3983 | /* IRQs are synced during runtime_suspend, we don't require a wakeref */ |
| 3984 | disable_rpm_wakeref_asserts(dev_priv); |
| 3985 | |
| 3986 | ret = IRQ_NONE; |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3987 | iir = I915_READ16(IIR); |
| 3988 | if (iir == 0) |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 3989 | goto out; |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3990 | |
| 3991 | while (iir & ~flip_mask) { |
| 3992 | /* Can't rely on pipestat interrupt bit in iir as it might |
| 3993 | * have been cleared after the pipestat interrupt was received. |
| 3994 | * It doesn't set the bit in iir again, but it still produces |
| 3995 | * interrupts (for non-MSI). |
| 3996 | */ |
Daniel Vetter | 222c7f5 | 2014-09-15 14:55:28 +0200 | [diff] [blame] | 3997 | spin_lock(&dev_priv->irq_lock); |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 3998 | if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) |
Daniel Vetter | aaecdf6 | 2014-11-04 15:52:22 +0100 | [diff] [blame] | 3999 | DRM_DEBUG("Command parser error, iir 0x%08x\n", iir); |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 4000 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 4001 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4002 | i915_reg_t reg = PIPESTAT(pipe); |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 4003 | pipe_stats[pipe] = I915_READ(reg); |
| 4004 | |
| 4005 | /* |
| 4006 | * Clear the PIPE*STAT regs before the IIR |
| 4007 | */ |
Ville Syrjälä | 2d9d2b0 | 2014-01-17 11:44:31 +0200 | [diff] [blame] | 4008 | if (pipe_stats[pipe] & 0x8000ffff) |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 4009 | I915_WRITE(reg, pipe_stats[pipe]); |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 4010 | } |
Daniel Vetter | 222c7f5 | 2014-09-15 14:55:28 +0200 | [diff] [blame] | 4011 | spin_unlock(&dev_priv->irq_lock); |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 4012 | |
| 4013 | I915_WRITE16(IIR, iir & ~flip_mask); |
| 4014 | new_iir = I915_READ16(IIR); /* Flush posted writes */ |
| 4015 | |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 4016 | if (iir & I915_USER_INTERRUPT) |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 4017 | notify_ring(dev_priv->engine[RCS]); |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 4018 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 4019 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 4020 | int plane = pipe; |
| 4021 | if (HAS_FBC(dev_priv)) |
| 4022 | plane = !plane; |
| 4023 | |
| 4024 | if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS && |
| 4025 | i8xx_handle_vblank(dev_priv, plane, pipe, iir)) |
| 4026 | flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane); |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 4027 | |
Daniel Vetter | 4356d58 | 2013-10-16 22:55:55 +0200 | [diff] [blame] | 4028 | if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 4029 | i9xx_pipe_crc_irq_handler(dev_priv, pipe); |
Ville Syrjälä | 2d9d2b0 | 2014-01-17 11:44:31 +0200 | [diff] [blame] | 4030 | |
Daniel Vetter | 1f7247c | 2014-09-30 10:56:48 +0200 | [diff] [blame] | 4031 | if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) |
| 4032 | intel_cpu_fifo_underrun_irq_handler(dev_priv, |
| 4033 | pipe); |
Daniel Vetter | 4356d58 | 2013-10-16 22:55:55 +0200 | [diff] [blame] | 4034 | } |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 4035 | |
| 4036 | iir = new_iir; |
| 4037 | } |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 4038 | ret = IRQ_HANDLED; |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 4039 | |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 4040 | out: |
| 4041 | enable_rpm_wakeref_asserts(dev_priv); |
| 4042 | |
| 4043 | return ret; |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 4044 | } |
| 4045 | |
| 4046 | static void i8xx_irq_uninstall(struct drm_device * dev) |
| 4047 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4048 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 4049 | int pipe; |
| 4050 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 4051 | for_each_pipe(dev_priv, pipe) { |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 4052 | /* Clear enable bits; then clear status bits */ |
| 4053 | I915_WRITE(PIPESTAT(pipe), 0); |
| 4054 | I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe))); |
| 4055 | } |
| 4056 | I915_WRITE16(IMR, 0xffff); |
| 4057 | I915_WRITE16(IER, 0x0); |
| 4058 | I915_WRITE16(IIR, I915_READ16(IIR)); |
| 4059 | } |
| 4060 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4061 | static void i915_irq_preinstall(struct drm_device * dev) |
| 4062 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4063 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4064 | int pipe; |
| 4065 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4066 | if (I915_HAS_HOTPLUG(dev)) { |
Egbert Eich | 0706f17 | 2015-09-23 16:15:27 +0200 | [diff] [blame] | 4067 | i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4068 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); |
| 4069 | } |
| 4070 | |
Chris Wilson | 00d98eb | 2012-04-24 22:59:48 +0100 | [diff] [blame] | 4071 | I915_WRITE16(HWSTAM, 0xeffe); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 4072 | for_each_pipe(dev_priv, pipe) |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4073 | I915_WRITE(PIPESTAT(pipe), 0); |
| 4074 | I915_WRITE(IMR, 0xffffffff); |
| 4075 | I915_WRITE(IER, 0x0); |
| 4076 | POSTING_READ(IER); |
| 4077 | } |
| 4078 | |
| 4079 | static int i915_irq_postinstall(struct drm_device *dev) |
| 4080 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4081 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 4082 | u32 enable_mask; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4083 | |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 4084 | I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH)); |
| 4085 | |
| 4086 | /* Unmask the interrupts that we always want on. */ |
| 4087 | dev_priv->irq_mask = |
| 4088 | ~(I915_ASLE_INTERRUPT | |
| 4089 | I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | |
| 4090 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | |
| 4091 | I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | |
Daniel Vetter | 37ef01a | 2015-04-01 13:43:46 +0200 | [diff] [blame] | 4092 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT); |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 4093 | |
| 4094 | enable_mask = |
| 4095 | I915_ASLE_INTERRUPT | |
| 4096 | I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | |
| 4097 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 4098 | I915_USER_INTERRUPT; |
| 4099 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4100 | if (I915_HAS_HOTPLUG(dev)) { |
Egbert Eich | 0706f17 | 2015-09-23 16:15:27 +0200 | [diff] [blame] | 4101 | i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0); |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 4102 | POSTING_READ(PORT_HOTPLUG_EN); |
| 4103 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4104 | /* Enable in IER... */ |
| 4105 | enable_mask |= I915_DISPLAY_PORT_INTERRUPT; |
| 4106 | /* and unmask in IMR */ |
| 4107 | dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT; |
| 4108 | } |
| 4109 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4110 | I915_WRITE(IMR, dev_priv->irq_mask); |
| 4111 | I915_WRITE(IER, enable_mask); |
| 4112 | POSTING_READ(IER); |
| 4113 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 4114 | i915_enable_asle_pipestat(dev_priv); |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 4115 | |
Daniel Vetter | 379ef82 | 2013-10-16 22:55:56 +0200 | [diff] [blame] | 4116 | /* Interrupt setup is already guaranteed to be single-threaded, this is |
| 4117 | * just to make the assert_spin_locked check happy. */ |
Daniel Vetter | d620743 | 2014-09-15 14:55:27 +0200 | [diff] [blame] | 4118 | spin_lock_irq(&dev_priv->irq_lock); |
Imre Deak | 755e901 | 2014-02-10 18:42:47 +0200 | [diff] [blame] | 4119 | i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); |
| 4120 | i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); |
Daniel Vetter | d620743 | 2014-09-15 14:55:27 +0200 | [diff] [blame] | 4121 | spin_unlock_irq(&dev_priv->irq_lock); |
Daniel Vetter | 379ef82 | 2013-10-16 22:55:56 +0200 | [diff] [blame] | 4122 | |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 4123 | return 0; |
| 4124 | } |
| 4125 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 4126 | /* |
| 4127 | * Returns true when a page flip has completed. |
| 4128 | */ |
| 4129 | static bool i915_handle_vblank(struct drm_i915_private *dev_priv, |
| 4130 | int plane, int pipe, u32 iir) |
| 4131 | { |
| 4132 | u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane); |
| 4133 | |
| 4134 | if (!intel_pipe_handle_vblank(dev_priv, pipe)) |
| 4135 | return false; |
| 4136 | |
| 4137 | if ((iir & flip_pending) == 0) |
| 4138 | goto check_page_flip; |
| 4139 | |
| 4140 | /* We detect FlipDone by looking for the change in PendingFlip from '1' |
| 4141 | * to '0' on the following vblank, i.e. IIR has the Pendingflip |
| 4142 | * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence |
| 4143 | * the flip is completed (no longer pending). Since this doesn't raise |
| 4144 | * an interrupt per se, we watch for the change at vblank. |
| 4145 | */ |
| 4146 | if (I915_READ(ISR) & flip_pending) |
| 4147 | goto check_page_flip; |
| 4148 | |
| 4149 | intel_finish_page_flip_cs(dev_priv, pipe); |
| 4150 | return true; |
| 4151 | |
| 4152 | check_page_flip: |
| 4153 | intel_check_page_flip(dev_priv, pipe); |
| 4154 | return false; |
| 4155 | } |
| 4156 | |
Daniel Vetter | ff1f525 | 2012-10-02 15:10:55 +0200 | [diff] [blame] | 4157 | static irqreturn_t i915_irq_handler(int irq, void *arg) |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4158 | { |
Daniel Vetter | 45a83f8 | 2014-05-12 19:17:55 +0200 | [diff] [blame] | 4159 | struct drm_device *dev = arg; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4160 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | 8291ee9 | 2012-04-24 22:59:47 +0100 | [diff] [blame] | 4161 | u32 iir, new_iir, pipe_stats[I915_MAX_PIPES]; |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 4162 | u32 flip_mask = |
| 4163 | I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | |
| 4164 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 4165 | int pipe, ret = IRQ_NONE; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4166 | |
Imre Deak | 2dd2a88 | 2015-02-24 11:14:30 +0200 | [diff] [blame] | 4167 | if (!intel_irqs_enabled(dev_priv)) |
| 4168 | return IRQ_NONE; |
| 4169 | |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 4170 | /* IRQs are synced during runtime_suspend, we don't require a wakeref */ |
| 4171 | disable_rpm_wakeref_asserts(dev_priv); |
| 4172 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4173 | iir = I915_READ(IIR); |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 4174 | do { |
| 4175 | bool irq_received = (iir & ~flip_mask) != 0; |
Chris Wilson | 8291ee9 | 2012-04-24 22:59:47 +0100 | [diff] [blame] | 4176 | bool blc_event = false; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4177 | |
| 4178 | /* Can't rely on pipestat interrupt bit in iir as it might |
| 4179 | * have been cleared after the pipestat interrupt was received. |
| 4180 | * It doesn't set the bit in iir again, but it still produces |
| 4181 | * interrupts (for non-MSI). |
| 4182 | */ |
Daniel Vetter | 222c7f5 | 2014-09-15 14:55:28 +0200 | [diff] [blame] | 4183 | spin_lock(&dev_priv->irq_lock); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4184 | if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) |
Daniel Vetter | aaecdf6 | 2014-11-04 15:52:22 +0100 | [diff] [blame] | 4185 | DRM_DEBUG("Command parser error, iir 0x%08x\n", iir); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4186 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 4187 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4188 | i915_reg_t reg = PIPESTAT(pipe); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4189 | pipe_stats[pipe] = I915_READ(reg); |
| 4190 | |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 4191 | /* Clear the PIPE*STAT regs before the IIR */ |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4192 | if (pipe_stats[pipe] & 0x8000ffff) { |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4193 | I915_WRITE(reg, pipe_stats[pipe]); |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 4194 | irq_received = true; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4195 | } |
| 4196 | } |
Daniel Vetter | 222c7f5 | 2014-09-15 14:55:28 +0200 | [diff] [blame] | 4197 | spin_unlock(&dev_priv->irq_lock); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4198 | |
| 4199 | if (!irq_received) |
| 4200 | break; |
| 4201 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4202 | /* Consume port. Then clear IIR or we'll miss events */ |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 4203 | if (I915_HAS_HOTPLUG(dev_priv) && |
Ville Syrjälä | 1ae3c34 | 2016-04-13 21:19:54 +0300 | [diff] [blame] | 4204 | iir & I915_DISPLAY_PORT_INTERRUPT) { |
| 4205 | u32 hotplug_status = i9xx_hpd_irq_ack(dev_priv); |
| 4206 | if (hotplug_status) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 4207 | i9xx_hpd_irq_handler(dev_priv, hotplug_status); |
Ville Syrjälä | 1ae3c34 | 2016-04-13 21:19:54 +0300 | [diff] [blame] | 4208 | } |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4209 | |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 4210 | I915_WRITE(IIR, iir & ~flip_mask); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4211 | new_iir = I915_READ(IIR); /* Flush posted writes */ |
| 4212 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4213 | if (iir & I915_USER_INTERRUPT) |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 4214 | notify_ring(dev_priv->engine[RCS]); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4215 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 4216 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 4217 | int plane = pipe; |
| 4218 | if (HAS_FBC(dev_priv)) |
| 4219 | plane = !plane; |
| 4220 | |
| 4221 | if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS && |
| 4222 | i915_handle_vblank(dev_priv, plane, pipe, iir)) |
| 4223 | flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4224 | |
| 4225 | if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) |
| 4226 | blc_event = true; |
Daniel Vetter | 4356d58 | 2013-10-16 22:55:55 +0200 | [diff] [blame] | 4227 | |
| 4228 | if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 4229 | i9xx_pipe_crc_irq_handler(dev_priv, pipe); |
Ville Syrjälä | 2d9d2b0 | 2014-01-17 11:44:31 +0200 | [diff] [blame] | 4230 | |
Daniel Vetter | 1f7247c | 2014-09-30 10:56:48 +0200 | [diff] [blame] | 4231 | if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) |
| 4232 | intel_cpu_fifo_underrun_irq_handler(dev_priv, |
| 4233 | pipe); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4234 | } |
| 4235 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4236 | if (blc_event || (iir & I915_ASLE_INTERRUPT)) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 4237 | intel_opregion_asle_intr(dev_priv); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4238 | |
| 4239 | /* With MSI, interrupts are only generated when iir |
| 4240 | * transitions from zero to nonzero. If another bit got |
| 4241 | * set while we were handling the existing iir bits, then |
| 4242 | * we would never get another interrupt. |
| 4243 | * |
| 4244 | * This is fine on non-MSI as well, as if we hit this path |
| 4245 | * we avoid exiting the interrupt handler only to generate |
| 4246 | * another one. |
| 4247 | * |
| 4248 | * Note that for MSI this could cause a stray interrupt report |
| 4249 | * if an interrupt landed in the time between writing IIR and |
| 4250 | * the posting read. This should be rare enough to never |
| 4251 | * trigger the 99% of 100,000 interrupts test for disabling |
| 4252 | * stray interrupts. |
| 4253 | */ |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 4254 | ret = IRQ_HANDLED; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4255 | iir = new_iir; |
Chris Wilson | 38bde18 | 2012-04-24 22:59:50 +0100 | [diff] [blame] | 4256 | } while (iir & ~flip_mask); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4257 | |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 4258 | enable_rpm_wakeref_asserts(dev_priv); |
| 4259 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4260 | return ret; |
| 4261 | } |
| 4262 | |
| 4263 | static void i915_irq_uninstall(struct drm_device * dev) |
| 4264 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4265 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4266 | int pipe; |
| 4267 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4268 | if (I915_HAS_HOTPLUG(dev)) { |
Egbert Eich | 0706f17 | 2015-09-23 16:15:27 +0200 | [diff] [blame] | 4269 | i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4270 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); |
| 4271 | } |
| 4272 | |
Chris Wilson | 00d98eb | 2012-04-24 22:59:48 +0100 | [diff] [blame] | 4273 | I915_WRITE16(HWSTAM, 0xffff); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 4274 | for_each_pipe(dev_priv, pipe) { |
Chris Wilson | 55b3975 | 2012-04-24 22:59:49 +0100 | [diff] [blame] | 4275 | /* Clear enable bits; then clear status bits */ |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4276 | I915_WRITE(PIPESTAT(pipe), 0); |
Chris Wilson | 55b3975 | 2012-04-24 22:59:49 +0100 | [diff] [blame] | 4277 | I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe))); |
| 4278 | } |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4279 | I915_WRITE(IMR, 0xffffffff); |
| 4280 | I915_WRITE(IER, 0x0); |
| 4281 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4282 | I915_WRITE(IIR, I915_READ(IIR)); |
| 4283 | } |
| 4284 | |
| 4285 | static void i965_irq_preinstall(struct drm_device * dev) |
| 4286 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4287 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4288 | int pipe; |
| 4289 | |
Egbert Eich | 0706f17 | 2015-09-23 16:15:27 +0200 | [diff] [blame] | 4290 | i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0); |
Chris Wilson | adca473 | 2012-05-11 18:01:31 +0100 | [diff] [blame] | 4291 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4292 | |
| 4293 | I915_WRITE(HWSTAM, 0xeffe); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 4294 | for_each_pipe(dev_priv, pipe) |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4295 | I915_WRITE(PIPESTAT(pipe), 0); |
| 4296 | I915_WRITE(IMR, 0xffffffff); |
| 4297 | I915_WRITE(IER, 0x0); |
| 4298 | POSTING_READ(IER); |
| 4299 | } |
| 4300 | |
| 4301 | static int i965_irq_postinstall(struct drm_device *dev) |
| 4302 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4303 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | bbba0a9 | 2012-04-24 22:59:51 +0100 | [diff] [blame] | 4304 | u32 enable_mask; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4305 | u32 error_mask; |
| 4306 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4307 | /* Unmask the interrupts that we always want on. */ |
Chris Wilson | bbba0a9 | 2012-04-24 22:59:51 +0100 | [diff] [blame] | 4308 | dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT | |
Chris Wilson | adca473 | 2012-05-11 18:01:31 +0100 | [diff] [blame] | 4309 | I915_DISPLAY_PORT_INTERRUPT | |
Chris Wilson | bbba0a9 | 2012-04-24 22:59:51 +0100 | [diff] [blame] | 4310 | I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | |
| 4311 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | |
| 4312 | I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | |
| 4313 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | |
| 4314 | I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); |
| 4315 | |
| 4316 | enable_mask = ~dev_priv->irq_mask; |
Ville Syrjälä | 21ad833 | 2013-02-19 15:16:39 +0200 | [diff] [blame] | 4317 | enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | |
| 4318 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT); |
Chris Wilson | bbba0a9 | 2012-04-24 22:59:51 +0100 | [diff] [blame] | 4319 | enable_mask |= I915_USER_INTERRUPT; |
| 4320 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 4321 | if (IS_G4X(dev_priv)) |
Chris Wilson | bbba0a9 | 2012-04-24 22:59:51 +0100 | [diff] [blame] | 4322 | enable_mask |= I915_BSD_USER_INTERRUPT; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4323 | |
Daniel Vetter | b79480b | 2013-06-27 17:52:10 +0200 | [diff] [blame] | 4324 | /* Interrupt setup is already guaranteed to be single-threaded, this is |
| 4325 | * just to make the assert_spin_locked check happy. */ |
Daniel Vetter | d620743 | 2014-09-15 14:55:27 +0200 | [diff] [blame] | 4326 | spin_lock_irq(&dev_priv->irq_lock); |
Imre Deak | 755e901 | 2014-02-10 18:42:47 +0200 | [diff] [blame] | 4327 | i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS); |
| 4328 | i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); |
| 4329 | i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); |
Daniel Vetter | d620743 | 2014-09-15 14:55:27 +0200 | [diff] [blame] | 4330 | spin_unlock_irq(&dev_priv->irq_lock); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4331 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4332 | /* |
| 4333 | * Enable some error detection, note the instruction error mask |
| 4334 | * bit is reserved, so we leave it masked. |
| 4335 | */ |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 4336 | if (IS_G4X(dev_priv)) { |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4337 | error_mask = ~(GM45_ERROR_PAGE_TABLE | |
| 4338 | GM45_ERROR_MEM_PRIV | |
| 4339 | GM45_ERROR_CP_PRIV | |
| 4340 | I915_ERROR_MEMORY_REFRESH); |
| 4341 | } else { |
| 4342 | error_mask = ~(I915_ERROR_PAGE_TABLE | |
| 4343 | I915_ERROR_MEMORY_REFRESH); |
| 4344 | } |
| 4345 | I915_WRITE(EMR, error_mask); |
| 4346 | |
| 4347 | I915_WRITE(IMR, dev_priv->irq_mask); |
| 4348 | I915_WRITE(IER, enable_mask); |
| 4349 | POSTING_READ(IER); |
| 4350 | |
Egbert Eich | 0706f17 | 2015-09-23 16:15:27 +0200 | [diff] [blame] | 4351 | i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0); |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 4352 | POSTING_READ(PORT_HOTPLUG_EN); |
| 4353 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 4354 | i915_enable_asle_pipestat(dev_priv); |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 4355 | |
| 4356 | return 0; |
| 4357 | } |
| 4358 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 4359 | static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv) |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 4360 | { |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 4361 | u32 hotplug_en; |
| 4362 | |
Daniel Vetter | b5ea2d5 | 2013-06-27 17:52:15 +0200 | [diff] [blame] | 4363 | assert_spin_locked(&dev_priv->irq_lock); |
| 4364 | |
Ville Syrjälä | 778eb33 | 2015-01-09 14:21:13 +0200 | [diff] [blame] | 4365 | /* Note HDMI and DP share hotplug bits */ |
| 4366 | /* enable bits are the same for all generations */ |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 4367 | hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915); |
Ville Syrjälä | 778eb33 | 2015-01-09 14:21:13 +0200 | [diff] [blame] | 4368 | /* Programming the CRT detection parameters tends |
| 4369 | to generate a spurious hotplug event about three |
| 4370 | seconds later. So just do it once. |
| 4371 | */ |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 4372 | if (IS_G4X(dev_priv)) |
Ville Syrjälä | 778eb33 | 2015-01-09 14:21:13 +0200 | [diff] [blame] | 4373 | hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64; |
Ville Syrjälä | 778eb33 | 2015-01-09 14:21:13 +0200 | [diff] [blame] | 4374 | hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4375 | |
Ville Syrjälä | 778eb33 | 2015-01-09 14:21:13 +0200 | [diff] [blame] | 4376 | /* Ignore TV since it's buggy */ |
Egbert Eich | 0706f17 | 2015-09-23 16:15:27 +0200 | [diff] [blame] | 4377 | i915_hotplug_interrupt_update_locked(dev_priv, |
Jani Nikula | f9e3dc7 | 2015-10-21 17:22:43 +0300 | [diff] [blame] | 4378 | HOTPLUG_INT_EN_MASK | |
| 4379 | CRT_HOTPLUG_VOLTAGE_COMPARE_MASK | |
| 4380 | CRT_HOTPLUG_ACTIVATION_PERIOD_64, |
| 4381 | hotplug_en); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4382 | } |
| 4383 | |
Daniel Vetter | ff1f525 | 2012-10-02 15:10:55 +0200 | [diff] [blame] | 4384 | static irqreturn_t i965_irq_handler(int irq, void *arg) |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4385 | { |
Daniel Vetter | 45a83f8 | 2014-05-12 19:17:55 +0200 | [diff] [blame] | 4386 | struct drm_device *dev = arg; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4387 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4388 | u32 iir, new_iir; |
| 4389 | u32 pipe_stats[I915_MAX_PIPES]; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4390 | int ret = IRQ_NONE, pipe; |
Ville Syrjälä | 21ad833 | 2013-02-19 15:16:39 +0200 | [diff] [blame] | 4391 | u32 flip_mask = |
| 4392 | I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | |
| 4393 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4394 | |
Imre Deak | 2dd2a88 | 2015-02-24 11:14:30 +0200 | [diff] [blame] | 4395 | if (!intel_irqs_enabled(dev_priv)) |
| 4396 | return IRQ_NONE; |
| 4397 | |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 4398 | /* IRQs are synced during runtime_suspend, we don't require a wakeref */ |
| 4399 | disable_rpm_wakeref_asserts(dev_priv); |
| 4400 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4401 | iir = I915_READ(IIR); |
| 4402 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4403 | for (;;) { |
Ville Syrjälä | 501e01d | 2014-01-17 11:35:15 +0200 | [diff] [blame] | 4404 | bool irq_received = (iir & ~flip_mask) != 0; |
Chris Wilson | 2c8ba29 | 2012-04-24 22:59:46 +0100 | [diff] [blame] | 4405 | bool blc_event = false; |
| 4406 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4407 | /* Can't rely on pipestat interrupt bit in iir as it might |
| 4408 | * have been cleared after the pipestat interrupt was received. |
| 4409 | * It doesn't set the bit in iir again, but it still produces |
| 4410 | * interrupts (for non-MSI). |
| 4411 | */ |
Daniel Vetter | 222c7f5 | 2014-09-15 14:55:28 +0200 | [diff] [blame] | 4412 | spin_lock(&dev_priv->irq_lock); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4413 | if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) |
Daniel Vetter | aaecdf6 | 2014-11-04 15:52:22 +0100 | [diff] [blame] | 4414 | DRM_DEBUG("Command parser error, iir 0x%08x\n", iir); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4415 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 4416 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4417 | i915_reg_t reg = PIPESTAT(pipe); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4418 | pipe_stats[pipe] = I915_READ(reg); |
| 4419 | |
| 4420 | /* |
| 4421 | * Clear the PIPE*STAT regs before the IIR |
| 4422 | */ |
| 4423 | if (pipe_stats[pipe] & 0x8000ffff) { |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4424 | I915_WRITE(reg, pipe_stats[pipe]); |
Ville Syrjälä | 501e01d | 2014-01-17 11:35:15 +0200 | [diff] [blame] | 4425 | irq_received = true; |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4426 | } |
| 4427 | } |
Daniel Vetter | 222c7f5 | 2014-09-15 14:55:28 +0200 | [diff] [blame] | 4428 | spin_unlock(&dev_priv->irq_lock); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4429 | |
| 4430 | if (!irq_received) |
| 4431 | break; |
| 4432 | |
| 4433 | ret = IRQ_HANDLED; |
| 4434 | |
| 4435 | /* Consume port. Then clear IIR or we'll miss events */ |
Ville Syrjälä | 1ae3c34 | 2016-04-13 21:19:54 +0300 | [diff] [blame] | 4436 | if (iir & I915_DISPLAY_PORT_INTERRUPT) { |
| 4437 | u32 hotplug_status = i9xx_hpd_irq_ack(dev_priv); |
| 4438 | if (hotplug_status) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 4439 | i9xx_hpd_irq_handler(dev_priv, hotplug_status); |
Ville Syrjälä | 1ae3c34 | 2016-04-13 21:19:54 +0300 | [diff] [blame] | 4440 | } |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4441 | |
Ville Syrjälä | 21ad833 | 2013-02-19 15:16:39 +0200 | [diff] [blame] | 4442 | I915_WRITE(IIR, iir & ~flip_mask); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4443 | new_iir = I915_READ(IIR); /* Flush posted writes */ |
| 4444 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4445 | if (iir & I915_USER_INTERRUPT) |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 4446 | notify_ring(dev_priv->engine[RCS]); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4447 | if (iir & I915_BSD_USER_INTERRUPT) |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 4448 | notify_ring(dev_priv->engine[VCS]); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4449 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 4450 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 4451 | if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS && |
| 4452 | i915_handle_vblank(dev_priv, pipe, pipe, iir)) |
| 4453 | flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4454 | |
| 4455 | if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) |
| 4456 | blc_event = true; |
Daniel Vetter | 4356d58 | 2013-10-16 22:55:55 +0200 | [diff] [blame] | 4457 | |
| 4458 | if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 4459 | i9xx_pipe_crc_irq_handler(dev_priv, pipe); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4460 | |
Daniel Vetter | 1f7247c | 2014-09-30 10:56:48 +0200 | [diff] [blame] | 4461 | if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) |
| 4462 | intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); |
Ville Syrjälä | 2d9d2b0 | 2014-01-17 11:44:31 +0200 | [diff] [blame] | 4463 | } |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4464 | |
| 4465 | if (blc_event || (iir & I915_ASLE_INTERRUPT)) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 4466 | intel_opregion_asle_intr(dev_priv); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4467 | |
Daniel Vetter | 515ac2b | 2012-12-01 13:53:44 +0100 | [diff] [blame] | 4468 | if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 4469 | gmbus_irq_handler(dev_priv); |
Daniel Vetter | 515ac2b | 2012-12-01 13:53:44 +0100 | [diff] [blame] | 4470 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4471 | /* With MSI, interrupts are only generated when iir |
| 4472 | * transitions from zero to nonzero. If another bit got |
| 4473 | * set while we were handling the existing iir bits, then |
| 4474 | * we would never get another interrupt. |
| 4475 | * |
| 4476 | * This is fine on non-MSI as well, as if we hit this path |
| 4477 | * we avoid exiting the interrupt handler only to generate |
| 4478 | * another one. |
| 4479 | * |
| 4480 | * Note that for MSI this could cause a stray interrupt report |
| 4481 | * if an interrupt landed in the time between writing IIR and |
| 4482 | * the posting read. This should be rare enough to never |
| 4483 | * trigger the 99% of 100,000 interrupts test for disabling |
| 4484 | * stray interrupts. |
| 4485 | */ |
| 4486 | iir = new_iir; |
| 4487 | } |
| 4488 | |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 4489 | enable_rpm_wakeref_asserts(dev_priv); |
| 4490 | |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4491 | return ret; |
| 4492 | } |
| 4493 | |
| 4494 | static void i965_irq_uninstall(struct drm_device * dev) |
| 4495 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4496 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4497 | int pipe; |
| 4498 | |
| 4499 | if (!dev_priv) |
| 4500 | return; |
| 4501 | |
Egbert Eich | 0706f17 | 2015-09-23 16:15:27 +0200 | [diff] [blame] | 4502 | i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0); |
Chris Wilson | adca473 | 2012-05-11 18:01:31 +0100 | [diff] [blame] | 4503 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4504 | |
| 4505 | I915_WRITE(HWSTAM, 0xffffffff); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 4506 | for_each_pipe(dev_priv, pipe) |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4507 | I915_WRITE(PIPESTAT(pipe), 0); |
| 4508 | I915_WRITE(IMR, 0xffffffff); |
| 4509 | I915_WRITE(IER, 0x0); |
| 4510 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 4511 | for_each_pipe(dev_priv, pipe) |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4512 | I915_WRITE(PIPESTAT(pipe), |
| 4513 | I915_READ(PIPESTAT(pipe)) & 0x8000ffff); |
| 4514 | I915_WRITE(IIR, I915_READ(IIR)); |
| 4515 | } |
| 4516 | |
Daniel Vetter | fca52a5 | 2014-09-30 10:56:45 +0200 | [diff] [blame] | 4517 | /** |
| 4518 | * intel_irq_init - initializes irq support |
| 4519 | * @dev_priv: i915 device instance |
| 4520 | * |
| 4521 | * This function initializes all the irq support including work items, timers |
| 4522 | * and all the vtables. It does not setup the interrupt itself though. |
| 4523 | */ |
Daniel Vetter | b963291 | 2014-09-30 10:56:44 +0200 | [diff] [blame] | 4524 | void intel_irq_init(struct drm_i915_private *dev_priv) |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 4525 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 4526 | struct drm_device *dev = &dev_priv->drm; |
Chris Wilson | 8b2e326 | 2012-04-24 22:59:41 +0100 | [diff] [blame] | 4527 | |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 4528 | intel_hpd_init_work(dev_priv); |
| 4529 | |
Daniel Vetter | c6a828d | 2012-08-08 23:35:35 +0200 | [diff] [blame] | 4530 | INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work); |
Daniel Vetter | a4da4fa | 2012-11-02 19:55:07 +0100 | [diff] [blame] | 4531 | INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work); |
Chris Wilson | 8b2e326 | 2012-04-24 22:59:41 +0100 | [diff] [blame] | 4532 | |
Sagar Arun Kamble | 26705e2 | 2016-10-12 21:54:31 +0530 | [diff] [blame^] | 4533 | if (HAS_GUC_SCHED(dev)) |
| 4534 | dev_priv->pm_guc_events = GEN9_GUC_TO_HOST_INT_EVENT; |
| 4535 | |
Deepak S | a6706b4 | 2014-03-15 20:23:22 +0530 | [diff] [blame] | 4536 | /* Let's track the enabled rps events */ |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 4537 | if (IS_VALLEYVIEW(dev_priv)) |
Ville Syrjälä | 6c65a587 | 2014-08-29 14:14:07 +0300 | [diff] [blame] | 4538 | /* WaGsvRC0ResidencyMethod:vlv */ |
Chris Wilson | 6f4b12f8 | 2015-03-18 09:48:23 +0000 | [diff] [blame] | 4539 | dev_priv->pm_rps_events = GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED; |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 4540 | else |
| 4541 | dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS; |
Deepak S | a6706b4 | 2014-03-15 20:23:22 +0530 | [diff] [blame] | 4542 | |
Sagar Arun Kamble | 1800ad2 | 2016-05-31 13:58:27 +0530 | [diff] [blame] | 4543 | dev_priv->rps.pm_intr_keep = 0; |
| 4544 | |
| 4545 | /* |
| 4546 | * SNB,IVB can while VLV,CHV may hard hang on looping batchbuffer |
| 4547 | * if GEN6_PM_UP_EI_EXPIRED is masked. |
| 4548 | * |
| 4549 | * TODO: verify if this can be reproduced on VLV,CHV. |
| 4550 | */ |
| 4551 | if (INTEL_INFO(dev_priv)->gen <= 7 && !IS_HASWELL(dev_priv)) |
| 4552 | dev_priv->rps.pm_intr_keep |= GEN6_PM_RP_UP_EI_EXPIRED; |
| 4553 | |
| 4554 | if (INTEL_INFO(dev_priv)->gen >= 8) |
Dave Gordon | b20e3cf | 2016-09-12 21:19:35 +0100 | [diff] [blame] | 4555 | dev_priv->rps.pm_intr_keep |= GEN8_PMINTR_REDIRECT_TO_GUC; |
Sagar Arun Kamble | 1800ad2 | 2016-05-31 13:58:27 +0530 | [diff] [blame] | 4556 | |
Chris Wilson | 737b150 | 2015-01-26 18:03:03 +0200 | [diff] [blame] | 4557 | INIT_DELAYED_WORK(&dev_priv->gpu_error.hangcheck_work, |
| 4558 | i915_hangcheck_elapsed); |
Daniel Vetter | 61bac78 | 2012-12-01 21:03:21 +0100 | [diff] [blame] | 4559 | |
Daniel Vetter | b963291 | 2014-09-30 10:56:44 +0200 | [diff] [blame] | 4560 | if (IS_GEN2(dev_priv)) { |
Rodrigo Vivi | 4194c08 | 2016-08-03 10:00:56 -0700 | [diff] [blame] | 4561 | /* Gen2 doesn't have a hardware frame counter */ |
Ville Syrjälä | 4cdb83e | 2013-10-11 21:52:44 +0300 | [diff] [blame] | 4562 | dev->max_vblank_count = 0; |
Rodrigo Vivi | 4194c08 | 2016-08-03 10:00:56 -0700 | [diff] [blame] | 4563 | dev->driver->get_vblank_counter = drm_vblank_no_hw_counter; |
Daniel Vetter | b963291 | 2014-09-30 10:56:44 +0200 | [diff] [blame] | 4564 | } else if (IS_G4X(dev_priv) || INTEL_INFO(dev_priv)->gen >= 5) { |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 4565 | dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */ |
Ville Syrjälä | fd8f507c | 2015-09-18 20:03:42 +0300 | [diff] [blame] | 4566 | dev->driver->get_vblank_counter = g4x_get_vblank_counter; |
Ville Syrjälä | 391f75e | 2013-09-25 19:55:26 +0300 | [diff] [blame] | 4567 | } else { |
| 4568 | dev->driver->get_vblank_counter = i915_get_vblank_counter; |
| 4569 | dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 4570 | } |
| 4571 | |
Ville Syrjälä | 21da270 | 2014-08-06 14:49:55 +0300 | [diff] [blame] | 4572 | /* |
| 4573 | * Opt out of the vblank disable timer on everything except gen2. |
| 4574 | * Gen2 doesn't have a hardware frame counter and so depends on |
| 4575 | * vblank interrupts to produce sane vblank seuquence numbers. |
| 4576 | */ |
Daniel Vetter | b963291 | 2014-09-30 10:56:44 +0200 | [diff] [blame] | 4577 | if (!IS_GEN2(dev_priv)) |
Ville Syrjälä | 21da270 | 2014-08-06 14:49:55 +0300 | [diff] [blame] | 4578 | dev->vblank_disable_immediate = true; |
| 4579 | |
Daniel Vetter | f3a5c3f | 2015-02-13 21:03:44 +0100 | [diff] [blame] | 4580 | dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp; |
| 4581 | dev->driver->get_scanout_position = i915_get_crtc_scanoutpos; |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 4582 | |
Daniel Vetter | b963291 | 2014-09-30 10:56:44 +0200 | [diff] [blame] | 4583 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 4584 | dev->driver->irq_handler = cherryview_irq_handler; |
| 4585 | dev->driver->irq_preinstall = cherryview_irq_preinstall; |
| 4586 | dev->driver->irq_postinstall = cherryview_irq_postinstall; |
| 4587 | dev->driver->irq_uninstall = cherryview_irq_uninstall; |
Chris Wilson | 86e83e3 | 2016-10-07 20:49:52 +0100 | [diff] [blame] | 4588 | dev->driver->enable_vblank = i965_enable_vblank; |
| 4589 | dev->driver->disable_vblank = i965_disable_vblank; |
Ville Syrjälä | 43f328d | 2014-04-09 20:40:52 +0300 | [diff] [blame] | 4590 | dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; |
Daniel Vetter | b963291 | 2014-09-30 10:56:44 +0200 | [diff] [blame] | 4591 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 4592 | dev->driver->irq_handler = valleyview_irq_handler; |
| 4593 | dev->driver->irq_preinstall = valleyview_irq_preinstall; |
| 4594 | dev->driver->irq_postinstall = valleyview_irq_postinstall; |
| 4595 | dev->driver->irq_uninstall = valleyview_irq_uninstall; |
Chris Wilson | 86e83e3 | 2016-10-07 20:49:52 +0100 | [diff] [blame] | 4596 | dev->driver->enable_vblank = i965_enable_vblank; |
| 4597 | dev->driver->disable_vblank = i965_disable_vblank; |
Egbert Eich | fa00abe | 2013-02-25 12:06:48 -0500 | [diff] [blame] | 4598 | dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; |
Daniel Vetter | b963291 | 2014-09-30 10:56:44 +0200 | [diff] [blame] | 4599 | } else if (INTEL_INFO(dev_priv)->gen >= 8) { |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 4600 | dev->driver->irq_handler = gen8_irq_handler; |
Daniel Vetter | 723761b | 2014-05-22 17:56:34 +0200 | [diff] [blame] | 4601 | dev->driver->irq_preinstall = gen8_irq_reset; |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 4602 | dev->driver->irq_postinstall = gen8_irq_postinstall; |
| 4603 | dev->driver->irq_uninstall = gen8_irq_uninstall; |
| 4604 | dev->driver->enable_vblank = gen8_enable_vblank; |
| 4605 | dev->driver->disable_vblank = gen8_disable_vblank; |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 4606 | if (IS_BROXTON(dev_priv)) |
Shashank Sharma | e0a20ad | 2015-03-27 14:54:14 +0200 | [diff] [blame] | 4607 | dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4608 | else if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv)) |
Ville Syrjälä | 6dbf30c | 2015-08-27 23:56:02 +0300 | [diff] [blame] | 4609 | dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup; |
| 4610 | else |
Ville Syrjälä | 3a3b3c7 | 2015-08-27 23:56:06 +0300 | [diff] [blame] | 4611 | dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4612 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 4613 | dev->driver->irq_handler = ironlake_irq_handler; |
Daniel Vetter | 723761b | 2014-05-22 17:56:34 +0200 | [diff] [blame] | 4614 | dev->driver->irq_preinstall = ironlake_irq_reset; |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 4615 | dev->driver->irq_postinstall = ironlake_irq_postinstall; |
| 4616 | dev->driver->irq_uninstall = ironlake_irq_uninstall; |
| 4617 | dev->driver->enable_vblank = ironlake_enable_vblank; |
| 4618 | dev->driver->disable_vblank = ironlake_disable_vblank; |
Ville Syrjälä | 23bb4cb | 2015-08-27 23:56:04 +0300 | [diff] [blame] | 4619 | dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup; |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 4620 | } else { |
Tvrtko Ursulin | 7e22dbb | 2016-05-10 10:57:06 +0100 | [diff] [blame] | 4621 | if (IS_GEN2(dev_priv)) { |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 4622 | dev->driver->irq_preinstall = i8xx_irq_preinstall; |
| 4623 | dev->driver->irq_postinstall = i8xx_irq_postinstall; |
| 4624 | dev->driver->irq_handler = i8xx_irq_handler; |
| 4625 | dev->driver->irq_uninstall = i8xx_irq_uninstall; |
Chris Wilson | 86e83e3 | 2016-10-07 20:49:52 +0100 | [diff] [blame] | 4626 | dev->driver->enable_vblank = i8xx_enable_vblank; |
| 4627 | dev->driver->disable_vblank = i8xx_disable_vblank; |
Tvrtko Ursulin | 7e22dbb | 2016-05-10 10:57:06 +0100 | [diff] [blame] | 4628 | } else if (IS_GEN3(dev_priv)) { |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4629 | dev->driver->irq_preinstall = i915_irq_preinstall; |
| 4630 | dev->driver->irq_postinstall = i915_irq_postinstall; |
| 4631 | dev->driver->irq_uninstall = i915_irq_uninstall; |
| 4632 | dev->driver->irq_handler = i915_irq_handler; |
Chris Wilson | 86e83e3 | 2016-10-07 20:49:52 +0100 | [diff] [blame] | 4633 | dev->driver->enable_vblank = i8xx_enable_vblank; |
| 4634 | dev->driver->disable_vblank = i8xx_disable_vblank; |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 4635 | } else { |
Chris Wilson | a266c7d | 2012-04-24 22:59:44 +0100 | [diff] [blame] | 4636 | dev->driver->irq_preinstall = i965_irq_preinstall; |
| 4637 | dev->driver->irq_postinstall = i965_irq_postinstall; |
| 4638 | dev->driver->irq_uninstall = i965_irq_uninstall; |
| 4639 | dev->driver->irq_handler = i965_irq_handler; |
Chris Wilson | 86e83e3 | 2016-10-07 20:49:52 +0100 | [diff] [blame] | 4640 | dev->driver->enable_vblank = i965_enable_vblank; |
| 4641 | dev->driver->disable_vblank = i965_disable_vblank; |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 4642 | } |
Ville Syrjälä | 778eb33 | 2015-01-09 14:21:13 +0200 | [diff] [blame] | 4643 | if (I915_HAS_HOTPLUG(dev_priv)) |
| 4644 | dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 4645 | } |
| 4646 | } |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 4647 | |
Daniel Vetter | fca52a5 | 2014-09-30 10:56:45 +0200 | [diff] [blame] | 4648 | /** |
Daniel Vetter | fca52a5 | 2014-09-30 10:56:45 +0200 | [diff] [blame] | 4649 | * intel_irq_install - enables the hardware interrupt |
| 4650 | * @dev_priv: i915 device instance |
| 4651 | * |
| 4652 | * This function enables the hardware interrupt handling, but leaves the hotplug |
| 4653 | * handling still disabled. It is called after intel_irq_init(). |
| 4654 | * |
| 4655 | * In the driver load and resume code we need working interrupts in a few places |
| 4656 | * but don't want to deal with the hassle of concurrent probe and hotplug |
| 4657 | * workers. Hence the split into this two-stage approach. |
| 4658 | */ |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 4659 | int intel_irq_install(struct drm_i915_private *dev_priv) |
| 4660 | { |
| 4661 | /* |
| 4662 | * We enable some interrupt sources in our postinstall hooks, so mark |
| 4663 | * interrupts as enabled _before_ actually enabling them to avoid |
| 4664 | * special cases in our ordering checks. |
| 4665 | */ |
| 4666 | dev_priv->pm.irqs_enabled = true; |
| 4667 | |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 4668 | return drm_irq_install(&dev_priv->drm, dev_priv->drm.pdev->irq); |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 4669 | } |
| 4670 | |
Daniel Vetter | fca52a5 | 2014-09-30 10:56:45 +0200 | [diff] [blame] | 4671 | /** |
| 4672 | * intel_irq_uninstall - finilizes all irq handling |
| 4673 | * @dev_priv: i915 device instance |
| 4674 | * |
| 4675 | * This stops interrupt and hotplug handling and unregisters and frees all |
| 4676 | * resources acquired in the init functions. |
| 4677 | */ |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 4678 | void intel_irq_uninstall(struct drm_i915_private *dev_priv) |
| 4679 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 4680 | drm_irq_uninstall(&dev_priv->drm); |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 4681 | intel_hpd_cancel_work(dev_priv); |
| 4682 | dev_priv->pm.irqs_enabled = false; |
| 4683 | } |
| 4684 | |
Daniel Vetter | fca52a5 | 2014-09-30 10:56:45 +0200 | [diff] [blame] | 4685 | /** |
| 4686 | * intel_runtime_pm_disable_interrupts - runtime interrupt disabling |
| 4687 | * @dev_priv: i915 device instance |
| 4688 | * |
| 4689 | * This function is used to disable interrupts at runtime, both in the runtime |
| 4690 | * pm and the system suspend/resume code. |
| 4691 | */ |
Daniel Vetter | b963291 | 2014-09-30 10:56:44 +0200 | [diff] [blame] | 4692 | void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 4693 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 4694 | dev_priv->drm.driver->irq_uninstall(&dev_priv->drm); |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 4695 | dev_priv->pm.irqs_enabled = false; |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 4696 | synchronize_irq(dev_priv->drm.irq); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 4697 | } |
| 4698 | |
Daniel Vetter | fca52a5 | 2014-09-30 10:56:45 +0200 | [diff] [blame] | 4699 | /** |
| 4700 | * intel_runtime_pm_enable_interrupts - runtime interrupt enabling |
| 4701 | * @dev_priv: i915 device instance |
| 4702 | * |
| 4703 | * This function is used to enable interrupts at runtime, both in the runtime |
| 4704 | * pm and the system suspend/resume code. |
| 4705 | */ |
Daniel Vetter | b963291 | 2014-09-30 10:56:44 +0200 | [diff] [blame] | 4706 | void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 4707 | { |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 4708 | dev_priv->pm.irqs_enabled = true; |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 4709 | dev_priv->drm.driver->irq_preinstall(&dev_priv->drm); |
| 4710 | dev_priv->drm.driver->irq_postinstall(&dev_priv->drm); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 4711 | } |