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