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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include "drmP.h" |
| 34 | #include "drm.h" |
| 35 | #include "i915_drm.h" |
| 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #define MAX_NOPID ((u32)~0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 42 | /** |
| 43 | * Interrupts that are always left unmasked. |
| 44 | * |
| 45 | * Since pipe events are edge-triggered from the PIPESTAT register to IIR, |
| 46 | * we leave them always unmasked in IMR and then control enabling them through |
| 47 | * PIPESTAT alone. |
| 48 | */ |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 49 | #define I915_INTERRUPT_ENABLE_FIX \ |
| 50 | (I915_ASLE_INTERRUPT | \ |
| 51 | I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | \ |
| 52 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | \ |
| 53 | I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | \ |
| 54 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | \ |
| 55 | I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 56 | |
| 57 | /** Interrupts that we mask and unmask at runtime. */ |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 58 | #define I915_INTERRUPT_ENABLE_VAR (I915_USER_INTERRUPT | I915_BSD_USER_INTERRUPT) |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 59 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 60 | #define I915_PIPE_VBLANK_STATUS (PIPE_START_VBLANK_INTERRUPT_STATUS |\ |
| 61 | PIPE_VBLANK_INTERRUPT_STATUS) |
| 62 | |
| 63 | #define I915_PIPE_VBLANK_ENABLE (PIPE_START_VBLANK_INTERRUPT_ENABLE |\ |
| 64 | PIPE_VBLANK_INTERRUPT_ENABLE) |
| 65 | |
| 66 | #define DRM_I915_VBLANK_PIPE_ALL (DRM_I915_VBLANK_PIPE_A | \ |
| 67 | DRM_I915_VBLANK_PIPE_B) |
| 68 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 69 | /* For display hotplug interrupt */ |
Chris Wilson | 995b6762 | 2010-08-20 13:23:26 +0100 | [diff] [blame] | 70 | static void |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 71 | ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 72 | { |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 73 | if ((dev_priv->irq_mask & mask) != 0) { |
| 74 | dev_priv->irq_mask &= ~mask; |
| 75 | I915_WRITE(DEIMR, dev_priv->irq_mask); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 76 | POSTING_READ(DEIMR); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | |
| 80 | static inline void |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 81 | ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 82 | { |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 83 | if ((dev_priv->irq_mask & mask) != mask) { |
| 84 | dev_priv->irq_mask |= mask; |
| 85 | I915_WRITE(DEIMR, dev_priv->irq_mask); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 86 | POSTING_READ(DEIMR); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 90 | void |
| 91 | i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask) |
| 92 | { |
| 93 | if ((dev_priv->pipestat[pipe] & mask) != mask) { |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 94 | u32 reg = PIPESTAT(pipe); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 95 | |
| 96 | dev_priv->pipestat[pipe] |= mask; |
| 97 | /* Enable the interrupt, clear any pending status */ |
| 98 | I915_WRITE(reg, dev_priv->pipestat[pipe] | (mask >> 16)); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 99 | POSTING_READ(reg); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
| 103 | void |
| 104 | i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask) |
| 105 | { |
| 106 | if ((dev_priv->pipestat[pipe] & mask) != 0) { |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 107 | u32 reg = PIPESTAT(pipe); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 108 | |
| 109 | dev_priv->pipestat[pipe] &= ~mask; |
| 110 | I915_WRITE(reg, dev_priv->pipestat[pipe]); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 111 | POSTING_READ(reg); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 115 | /** |
Zhao Yakui | 01c6688 | 2009-10-28 05:10:00 +0000 | [diff] [blame] | 116 | * intel_enable_asle - enable ASLE interrupt for OpRegion |
| 117 | */ |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 118 | void intel_enable_asle(struct drm_device *dev) |
Zhao Yakui | 01c6688 | 2009-10-28 05:10:00 +0000 | [diff] [blame] | 119 | { |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 120 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 121 | unsigned long irqflags; |
| 122 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 123 | /* FIXME: opregion/asle for VLV */ |
| 124 | if (IS_VALLEYVIEW(dev)) |
| 125 | return; |
| 126 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 127 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Zhao Yakui | 01c6688 | 2009-10-28 05:10:00 +0000 | [diff] [blame] | 128 | |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 129 | if (HAS_PCH_SPLIT(dev)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 130 | ironlake_enable_display_irq(dev_priv, DE_GSE); |
Zhao Yakui | edcb49c | 2010-04-07 17:11:21 +0800 | [diff] [blame] | 131 | else { |
Zhao Yakui | 01c6688 | 2009-10-28 05:10:00 +0000 | [diff] [blame] | 132 | i915_enable_pipestat(dev_priv, 1, |
Jesse Barnes | d874bcf | 2010-06-30 13:16:00 -0700 | [diff] [blame] | 133 | PIPE_LEGACY_BLC_EVENT_ENABLE); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 134 | if (INTEL_INFO(dev)->gen >= 4) |
Zhao Yakui | edcb49c | 2010-04-07 17:11:21 +0800 | [diff] [blame] | 135 | i915_enable_pipestat(dev_priv, 0, |
Jesse Barnes | d874bcf | 2010-06-30 13:16:00 -0700 | [diff] [blame] | 136 | PIPE_LEGACY_BLC_EVENT_ENABLE); |
Zhao Yakui | edcb49c | 2010-04-07 17:11:21 +0800 | [diff] [blame] | 137 | } |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 138 | |
| 139 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
Zhao Yakui | 01c6688 | 2009-10-28 05:10:00 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | /** |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 143 | * i915_pipe_enabled - check if a pipe is enabled |
| 144 | * @dev: DRM device |
| 145 | * @pipe: pipe to check |
| 146 | * |
| 147 | * Reading certain registers when the pipe is disabled can hang the chip. |
| 148 | * Use this routine to make sure the PLL is running and the pipe is active |
| 149 | * before reading such registers if unsure. |
| 150 | */ |
| 151 | static int |
| 152 | i915_pipe_enabled(struct drm_device *dev, int pipe) |
| 153 | { |
| 154 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 155 | return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Keith Packard | 42f52ef | 2008-10-18 19:39:29 -0700 | [diff] [blame] | 158 | /* Called from drm generic code, passed a 'crtc', which |
| 159 | * we use as a pipe index |
| 160 | */ |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 161 | static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 162 | { |
| 163 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 164 | unsigned long high_frame; |
| 165 | unsigned long low_frame; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 166 | u32 high1, high2, low; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 167 | |
| 168 | if (!i915_pipe_enabled(dev, pipe)) { |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 169 | DRM_DEBUG_DRIVER("trying to get vblank count for disabled " |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 170 | "pipe %c\n", pipe_name(pipe)); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 171 | return 0; |
| 172 | } |
| 173 | |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 174 | high_frame = PIPEFRAME(pipe); |
| 175 | low_frame = PIPEFRAMEPIXEL(pipe); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 176 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 177 | /* |
| 178 | * High & low register fields aren't synchronized, so make sure |
| 179 | * we get a low value that's stable across two reads of the high |
| 180 | * register. |
| 181 | */ |
| 182 | do { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 183 | high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; |
| 184 | low = I915_READ(low_frame) & PIPE_FRAME_LOW_MASK; |
| 185 | high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 186 | } while (high1 != high2); |
| 187 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 188 | high1 >>= PIPE_FRAME_HIGH_SHIFT; |
| 189 | low >>= PIPE_FRAME_LOW_SHIFT; |
| 190 | return (high1 << 8) | low; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 193 | static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe) |
Jesse Barnes | 9880b7a | 2009-02-06 10:22:41 -0800 | [diff] [blame] | 194 | { |
| 195 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 196 | int reg = PIPE_FRMCOUNT_GM45(pipe); |
Jesse Barnes | 9880b7a | 2009-02-06 10:22:41 -0800 | [diff] [blame] | 197 | |
| 198 | if (!i915_pipe_enabled(dev, pipe)) { |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 199 | DRM_DEBUG_DRIVER("trying to get vblank count for disabled " |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 200 | "pipe %c\n", pipe_name(pipe)); |
Jesse Barnes | 9880b7a | 2009-02-06 10:22:41 -0800 | [diff] [blame] | 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | return I915_READ(reg); |
| 205 | } |
| 206 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 207 | static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe, |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 208 | int *vpos, int *hpos) |
| 209 | { |
| 210 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 211 | u32 vbl = 0, position = 0; |
| 212 | int vbl_start, vbl_end, htotal, vtotal; |
| 213 | bool in_vbl = true; |
| 214 | int ret = 0; |
| 215 | |
| 216 | if (!i915_pipe_enabled(dev, pipe)) { |
| 217 | DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled " |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 218 | "pipe %c\n", pipe_name(pipe)); |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | /* Get vtotal. */ |
| 223 | vtotal = 1 + ((I915_READ(VTOTAL(pipe)) >> 16) & 0x1fff); |
| 224 | |
| 225 | if (INTEL_INFO(dev)->gen >= 4) { |
| 226 | /* No obvious pixelcount register. Only query vertical |
| 227 | * scanout position from Display scan line register. |
| 228 | */ |
| 229 | position = I915_READ(PIPEDSL(pipe)); |
| 230 | |
| 231 | /* Decode into vertical scanout position. Don't have |
| 232 | * horizontal scanout position. |
| 233 | */ |
| 234 | *vpos = position & 0x1fff; |
| 235 | *hpos = 0; |
| 236 | } else { |
| 237 | /* Have access to pixelcount since start of frame. |
| 238 | * We can split this into vertical and horizontal |
| 239 | * scanout position. |
| 240 | */ |
| 241 | position = (I915_READ(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT; |
| 242 | |
| 243 | htotal = 1 + ((I915_READ(HTOTAL(pipe)) >> 16) & 0x1fff); |
| 244 | *vpos = position / htotal; |
| 245 | *hpos = position - (*vpos * htotal); |
| 246 | } |
| 247 | |
| 248 | /* Query vblank area. */ |
| 249 | vbl = I915_READ(VBLANK(pipe)); |
| 250 | |
| 251 | /* Test position against vblank region. */ |
| 252 | vbl_start = vbl & 0x1fff; |
| 253 | vbl_end = (vbl >> 16) & 0x1fff; |
| 254 | |
| 255 | if ((*vpos < vbl_start) || (*vpos > vbl_end)) |
| 256 | in_vbl = false; |
| 257 | |
| 258 | /* Inside "upper part" of vblank area? Apply corrective offset: */ |
| 259 | if (in_vbl && (*vpos >= vbl_start)) |
| 260 | *vpos = *vpos - vtotal; |
| 261 | |
| 262 | /* Readouts valid? */ |
| 263 | if (vbl > 0) |
| 264 | ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE; |
| 265 | |
| 266 | /* In vblank? */ |
| 267 | if (in_vbl) |
| 268 | ret |= DRM_SCANOUTPOS_INVBL; |
| 269 | |
| 270 | return ret; |
| 271 | } |
| 272 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 273 | static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe, |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 274 | int *max_error, |
| 275 | struct timeval *vblank_time, |
| 276 | unsigned flags) |
| 277 | { |
Chris Wilson | 4041b85 | 2011-01-22 10:07:56 +0000 | [diff] [blame] | 278 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 279 | struct drm_crtc *crtc; |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 280 | |
Chris Wilson | 4041b85 | 2011-01-22 10:07:56 +0000 | [diff] [blame] | 281 | if (pipe < 0 || pipe >= dev_priv->num_pipe) { |
| 282 | DRM_ERROR("Invalid crtc %d\n", pipe); |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 283 | return -EINVAL; |
| 284 | } |
| 285 | |
| 286 | /* Get drm_crtc to timestamp: */ |
Chris Wilson | 4041b85 | 2011-01-22 10:07:56 +0000 | [diff] [blame] | 287 | crtc = intel_get_crtc_for_pipe(dev, pipe); |
| 288 | if (crtc == NULL) { |
| 289 | DRM_ERROR("Invalid crtc %d\n", pipe); |
| 290 | return -EINVAL; |
| 291 | } |
| 292 | |
| 293 | if (!crtc->enabled) { |
| 294 | DRM_DEBUG_KMS("crtc %d is disabled\n", pipe); |
| 295 | return -EBUSY; |
| 296 | } |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 297 | |
| 298 | /* Helper routine in DRM core does all the work: */ |
Chris Wilson | 4041b85 | 2011-01-22 10:07:56 +0000 | [diff] [blame] | 299 | return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error, |
| 300 | vblank_time, flags, |
| 301 | crtc); |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 302 | } |
| 303 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 304 | /* |
| 305 | * Handle hotplug events outside the interrupt handler proper. |
| 306 | */ |
| 307 | static void i915_hotplug_work_func(struct work_struct *work) |
| 308 | { |
| 309 | drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, |
| 310 | hotplug_work); |
| 311 | struct drm_device *dev = dev_priv->dev; |
Keith Packard | c31c4ba | 2009-05-06 11:48:58 -0700 | [diff] [blame] | 312 | struct drm_mode_config *mode_config = &dev->mode_config; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 313 | struct intel_encoder *encoder; |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 314 | |
Keith Packard | a65e34c | 2011-07-25 10:04:56 -0700 | [diff] [blame] | 315 | mutex_lock(&mode_config->mutex); |
Jesse Barnes | e67189ab | 2011-02-11 14:44:51 -0800 | [diff] [blame] | 316 | DRM_DEBUG_KMS("running encoder hotplug functions\n"); |
| 317 | |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 318 | list_for_each_entry(encoder, &mode_config->encoder_list, base.head) |
| 319 | if (encoder->hot_plug) |
| 320 | encoder->hot_plug(encoder); |
| 321 | |
Keith Packard | 40ee338 | 2011-07-28 15:31:19 -0700 | [diff] [blame] | 322 | mutex_unlock(&mode_config->mutex); |
| 323 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 324 | /* Just fire off a uevent and let userspace tell us what to do */ |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 325 | drm_helper_hpd_irq_event(dev); |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 328 | static void i915_handle_rps_change(struct drm_device *dev) |
| 329 | { |
| 330 | drm_i915_private_t *dev_priv = dev->dev_private; |
Matthew Garrett | b5b72e8 | 2010-02-02 18:30:47 +0000 | [diff] [blame] | 331 | u32 busy_up, busy_down, max_avg, min_avg; |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 332 | u8 new_delay = dev_priv->cur_delay; |
| 333 | |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 334 | I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG); |
Matthew Garrett | b5b72e8 | 2010-02-02 18:30:47 +0000 | [diff] [blame] | 335 | busy_up = I915_READ(RCPREVBSYTUPAVG); |
| 336 | busy_down = I915_READ(RCPREVBSYTDNAVG); |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 337 | max_avg = I915_READ(RCBMAXAVG); |
| 338 | min_avg = I915_READ(RCBMINAVG); |
| 339 | |
| 340 | /* Handle RCS change request from hw */ |
Matthew Garrett | b5b72e8 | 2010-02-02 18:30:47 +0000 | [diff] [blame] | 341 | if (busy_up > max_avg) { |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 342 | if (dev_priv->cur_delay != dev_priv->max_delay) |
| 343 | new_delay = dev_priv->cur_delay - 1; |
| 344 | if (new_delay < dev_priv->max_delay) |
| 345 | new_delay = dev_priv->max_delay; |
Matthew Garrett | b5b72e8 | 2010-02-02 18:30:47 +0000 | [diff] [blame] | 346 | } else if (busy_down < min_avg) { |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 347 | if (dev_priv->cur_delay != dev_priv->min_delay) |
| 348 | new_delay = dev_priv->cur_delay + 1; |
| 349 | if (new_delay > dev_priv->min_delay) |
| 350 | new_delay = dev_priv->min_delay; |
| 351 | } |
| 352 | |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 353 | if (ironlake_set_drps(dev, new_delay)) |
| 354 | dev_priv->cur_delay = new_delay; |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 355 | |
| 356 | return; |
| 357 | } |
| 358 | |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 359 | static void notify_ring(struct drm_device *dev, |
| 360 | struct intel_ring_buffer *ring) |
| 361 | { |
| 362 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 475553d | 2011-01-20 09:52:56 +0000 | [diff] [blame] | 363 | u32 seqno; |
Chris Wilson | 9862e60 | 2011-01-04 22:22:17 +0000 | [diff] [blame] | 364 | |
Chris Wilson | 475553d | 2011-01-20 09:52:56 +0000 | [diff] [blame] | 365 | if (ring->obj == NULL) |
| 366 | return; |
| 367 | |
| 368 | seqno = ring->get_seqno(ring); |
Chris Wilson | db53a30 | 2011-02-03 11:57:46 +0000 | [diff] [blame] | 369 | trace_i915_gem_request_complete(ring, seqno); |
Chris Wilson | 9862e60 | 2011-01-04 22:22:17 +0000 | [diff] [blame] | 370 | |
| 371 | ring->irq_seqno = seqno; |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 372 | wake_up_all(&ring->irq_queue); |
Ben Widawsky | 3e0dc6b | 2011-06-29 10:26:42 -0700 | [diff] [blame] | 373 | if (i915_enable_hangcheck) { |
| 374 | dev_priv->hangcheck_count = 0; |
| 375 | mod_timer(&dev_priv->hangcheck_timer, |
| 376 | jiffies + |
| 377 | msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD)); |
| 378 | } |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 379 | } |
| 380 | |
Ben Widawsky | 4912d04 | 2011-04-25 11:25:20 -0700 | [diff] [blame] | 381 | static void gen6_pm_rps_work(struct work_struct *work) |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 382 | { |
Ben Widawsky | 4912d04 | 2011-04-25 11:25:20 -0700 | [diff] [blame] | 383 | drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, |
| 384 | rps_work); |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 385 | u8 new_delay = dev_priv->cur_delay; |
Ben Widawsky | 4912d04 | 2011-04-25 11:25:20 -0700 | [diff] [blame] | 386 | u32 pm_iir, pm_imr; |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 387 | |
Ben Widawsky | 4912d04 | 2011-04-25 11:25:20 -0700 | [diff] [blame] | 388 | spin_lock_irq(&dev_priv->rps_lock); |
| 389 | pm_iir = dev_priv->pm_iir; |
| 390 | dev_priv->pm_iir = 0; |
| 391 | pm_imr = I915_READ(GEN6_PMIMR); |
Daniel Vetter | a9e2641 | 2011-09-08 14:00:21 +0200 | [diff] [blame] | 392 | I915_WRITE(GEN6_PMIMR, 0); |
Ben Widawsky | 4912d04 | 2011-04-25 11:25:20 -0700 | [diff] [blame] | 393 | spin_unlock_irq(&dev_priv->rps_lock); |
| 394 | |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 395 | if (!pm_iir) |
| 396 | return; |
| 397 | |
Ben Widawsky | 4912d04 | 2011-04-25 11:25:20 -0700 | [diff] [blame] | 398 | mutex_lock(&dev_priv->dev->struct_mutex); |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 399 | if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) { |
| 400 | if (dev_priv->cur_delay != dev_priv->max_delay) |
| 401 | new_delay = dev_priv->cur_delay + 1; |
| 402 | if (new_delay > dev_priv->max_delay) |
| 403 | new_delay = dev_priv->max_delay; |
| 404 | } else if (pm_iir & (GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_DOWN_TIMEOUT)) { |
Ben Widawsky | 4912d04 | 2011-04-25 11:25:20 -0700 | [diff] [blame] | 405 | gen6_gt_force_wake_get(dev_priv); |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 406 | if (dev_priv->cur_delay != dev_priv->min_delay) |
| 407 | new_delay = dev_priv->cur_delay - 1; |
| 408 | if (new_delay < dev_priv->min_delay) { |
| 409 | new_delay = dev_priv->min_delay; |
| 410 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
| 411 | I915_READ(GEN6_RP_INTERRUPT_LIMITS) | |
| 412 | ((new_delay << 16) & 0x3f0000)); |
| 413 | } else { |
| 414 | /* Make sure we continue to get down interrupts |
| 415 | * until we hit the minimum frequency */ |
| 416 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
| 417 | I915_READ(GEN6_RP_INTERRUPT_LIMITS) & ~0x3f0000); |
| 418 | } |
Ben Widawsky | 4912d04 | 2011-04-25 11:25:20 -0700 | [diff] [blame] | 419 | gen6_gt_force_wake_put(dev_priv); |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 420 | } |
| 421 | |
Ben Widawsky | 4912d04 | 2011-04-25 11:25:20 -0700 | [diff] [blame] | 422 | gen6_set_rps(dev_priv->dev, new_delay); |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 423 | dev_priv->cur_delay = new_delay; |
| 424 | |
Ben Widawsky | 4912d04 | 2011-04-25 11:25:20 -0700 | [diff] [blame] | 425 | /* |
| 426 | * rps_lock not held here because clearing is non-destructive. There is |
| 427 | * an *extremely* unlikely race with gen6_rps_enable() that is prevented |
| 428 | * by holding struct_mutex for the duration of the write. |
| 429 | */ |
Ben Widawsky | 4912d04 | 2011-04-25 11:25:20 -0700 | [diff] [blame] | 430 | mutex_unlock(&dev_priv->dev->struct_mutex); |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 431 | } |
| 432 | |
Daniel Vetter | e7b4c6b | 2012-03-30 20:24:35 +0200 | [diff] [blame] | 433 | static void snb_gt_irq_handler(struct drm_device *dev, |
| 434 | struct drm_i915_private *dev_priv, |
| 435 | u32 gt_iir) |
| 436 | { |
| 437 | |
| 438 | if (gt_iir & (GEN6_RENDER_USER_INTERRUPT | |
| 439 | GEN6_RENDER_PIPE_CONTROL_NOTIFY_INTERRUPT)) |
| 440 | notify_ring(dev, &dev_priv->ring[RCS]); |
| 441 | if (gt_iir & GEN6_BSD_USER_INTERRUPT) |
| 442 | notify_ring(dev, &dev_priv->ring[VCS]); |
| 443 | if (gt_iir & GEN6_BLITTER_USER_INTERRUPT) |
| 444 | notify_ring(dev, &dev_priv->ring[BCS]); |
| 445 | |
| 446 | if (gt_iir & (GT_GEN6_BLT_CS_ERROR_INTERRUPT | |
| 447 | GT_GEN6_BSD_CS_ERROR_INTERRUPT | |
| 448 | GT_RENDER_CS_ERROR_INTERRUPT)) { |
| 449 | DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir); |
| 450 | i915_handle_error(dev, false); |
| 451 | } |
| 452 | } |
| 453 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 454 | static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS) |
| 455 | { |
| 456 | struct drm_device *dev = (struct drm_device *) arg; |
| 457 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 458 | u32 iir, gt_iir, pm_iir; |
| 459 | irqreturn_t ret = IRQ_NONE; |
| 460 | unsigned long irqflags; |
| 461 | int pipe; |
| 462 | u32 pipe_stats[I915_MAX_PIPES]; |
| 463 | u32 vblank_status; |
| 464 | int vblank = 0; |
| 465 | bool blc_event; |
| 466 | |
| 467 | atomic_inc(&dev_priv->irq_received); |
| 468 | |
| 469 | vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS | |
| 470 | PIPE_VBLANK_INTERRUPT_STATUS; |
| 471 | |
| 472 | while (true) { |
| 473 | iir = I915_READ(VLV_IIR); |
| 474 | gt_iir = I915_READ(GTIIR); |
| 475 | pm_iir = I915_READ(GEN6_PMIIR); |
| 476 | |
| 477 | if (gt_iir == 0 && pm_iir == 0 && iir == 0) |
| 478 | goto out; |
| 479 | |
| 480 | ret = IRQ_HANDLED; |
| 481 | |
Daniel Vetter | e7b4c6b | 2012-03-30 20:24:35 +0200 | [diff] [blame] | 482 | snb_gt_irq_handler(dev, dev_priv, gt_iir); |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 483 | |
| 484 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
| 485 | for_each_pipe(pipe) { |
| 486 | int reg = PIPESTAT(pipe); |
| 487 | pipe_stats[pipe] = I915_READ(reg); |
| 488 | |
| 489 | /* |
| 490 | * Clear the PIPE*STAT regs before the IIR |
| 491 | */ |
| 492 | if (pipe_stats[pipe] & 0x8000ffff) { |
| 493 | if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) |
| 494 | DRM_DEBUG_DRIVER("pipe %c underrun\n", |
| 495 | pipe_name(pipe)); |
| 496 | I915_WRITE(reg, pipe_stats[pipe]); |
| 497 | } |
| 498 | } |
| 499 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 500 | |
| 501 | /* Consume port. Then clear IIR or we'll miss events */ |
| 502 | if (iir & I915_DISPLAY_PORT_INTERRUPT) { |
| 503 | u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); |
| 504 | |
| 505 | DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n", |
| 506 | hotplug_status); |
| 507 | if (hotplug_status & dev_priv->hotplug_supported_mask) |
| 508 | queue_work(dev_priv->wq, |
| 509 | &dev_priv->hotplug_work); |
| 510 | |
| 511 | I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); |
| 512 | I915_READ(PORT_HOTPLUG_STAT); |
| 513 | } |
| 514 | |
| 515 | |
| 516 | if (iir & I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT) { |
| 517 | drm_handle_vblank(dev, 0); |
| 518 | vblank++; |
| 519 | if (!dev_priv->flip_pending_is_done) { |
| 520 | intel_finish_page_flip(dev, 0); |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | if (iir & I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT) { |
| 525 | drm_handle_vblank(dev, 1); |
| 526 | vblank++; |
| 527 | if (!dev_priv->flip_pending_is_done) { |
| 528 | intel_finish_page_flip(dev, 0); |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) |
| 533 | blc_event = true; |
| 534 | |
| 535 | if (pm_iir & GEN6_PM_DEFERRED_EVENTS) { |
| 536 | unsigned long flags; |
| 537 | spin_lock_irqsave(&dev_priv->rps_lock, flags); |
| 538 | WARN(dev_priv->pm_iir & pm_iir, "Missed a PM interrupt\n"); |
| 539 | dev_priv->pm_iir |= pm_iir; |
| 540 | I915_WRITE(GEN6_PMIMR, dev_priv->pm_iir); |
| 541 | POSTING_READ(GEN6_PMIMR); |
| 542 | spin_unlock_irqrestore(&dev_priv->rps_lock, flags); |
| 543 | queue_work(dev_priv->wq, &dev_priv->rps_work); |
| 544 | } |
| 545 | |
| 546 | I915_WRITE(GTIIR, gt_iir); |
| 547 | I915_WRITE(GEN6_PMIIR, pm_iir); |
| 548 | I915_WRITE(VLV_IIR, iir); |
| 549 | } |
| 550 | |
| 551 | out: |
| 552 | return ret; |
| 553 | } |
| 554 | |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 555 | static void pch_irq_handler(struct drm_device *dev) |
| 556 | { |
| 557 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 558 | u32 pch_iir; |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 559 | int pipe; |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 560 | |
| 561 | pch_iir = I915_READ(SDEIIR); |
| 562 | |
| 563 | if (pch_iir & SDE_AUDIO_POWER_MASK) |
| 564 | DRM_DEBUG_DRIVER("PCH audio power change on port %d\n", |
| 565 | (pch_iir & SDE_AUDIO_POWER_MASK) >> |
| 566 | SDE_AUDIO_POWER_SHIFT); |
| 567 | |
| 568 | if (pch_iir & SDE_GMBUS) |
| 569 | DRM_DEBUG_DRIVER("PCH GMBUS interrupt\n"); |
| 570 | |
| 571 | if (pch_iir & SDE_AUDIO_HDCP_MASK) |
| 572 | DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n"); |
| 573 | |
| 574 | if (pch_iir & SDE_AUDIO_TRANS_MASK) |
| 575 | DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n"); |
| 576 | |
| 577 | if (pch_iir & SDE_POISON) |
| 578 | DRM_ERROR("PCH poison interrupt\n"); |
| 579 | |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 580 | if (pch_iir & SDE_FDI_MASK) |
| 581 | for_each_pipe(pipe) |
| 582 | DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", |
| 583 | pipe_name(pipe), |
| 584 | I915_READ(FDI_RX_IIR(pipe))); |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 585 | |
| 586 | if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE)) |
| 587 | DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n"); |
| 588 | |
| 589 | if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR)) |
| 590 | DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n"); |
| 591 | |
| 592 | if (pch_iir & SDE_TRANSB_FIFO_UNDER) |
| 593 | DRM_DEBUG_DRIVER("PCH transcoder B underrun interrupt\n"); |
| 594 | if (pch_iir & SDE_TRANSA_FIFO_UNDER) |
| 595 | DRM_DEBUG_DRIVER("PCH transcoder A underrun interrupt\n"); |
| 596 | } |
| 597 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 598 | static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS) |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 599 | { |
| 600 | struct drm_device *dev = (struct drm_device *) arg; |
| 601 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 602 | int ret = IRQ_NONE; |
| 603 | u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir; |
| 604 | struct drm_i915_master_private *master_priv; |
| 605 | |
| 606 | atomic_inc(&dev_priv->irq_received); |
| 607 | |
| 608 | /* disable master interrupt before clearing iir */ |
| 609 | de_ier = I915_READ(DEIER); |
| 610 | I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL); |
| 611 | POSTING_READ(DEIER); |
| 612 | |
| 613 | de_iir = I915_READ(DEIIR); |
| 614 | gt_iir = I915_READ(GTIIR); |
| 615 | pch_iir = I915_READ(SDEIIR); |
| 616 | pm_iir = I915_READ(GEN6_PMIIR); |
| 617 | |
| 618 | if (de_iir == 0 && gt_iir == 0 && pch_iir == 0 && pm_iir == 0) |
| 619 | goto done; |
| 620 | |
| 621 | ret = IRQ_HANDLED; |
| 622 | |
| 623 | if (dev->primary->master) { |
| 624 | master_priv = dev->primary->master->driver_priv; |
| 625 | if (master_priv->sarea_priv) |
| 626 | master_priv->sarea_priv->last_dispatch = |
| 627 | READ_BREADCRUMB(dev_priv); |
| 628 | } |
| 629 | |
Daniel Vetter | e7b4c6b | 2012-03-30 20:24:35 +0200 | [diff] [blame] | 630 | snb_gt_irq_handler(dev, dev_priv, gt_iir); |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 631 | |
| 632 | if (de_iir & DE_GSE_IVB) |
| 633 | intel_opregion_gse_intr(dev); |
| 634 | |
| 635 | if (de_iir & DE_PLANEA_FLIP_DONE_IVB) { |
| 636 | intel_prepare_page_flip(dev, 0); |
| 637 | intel_finish_page_flip_plane(dev, 0); |
| 638 | } |
| 639 | |
| 640 | if (de_iir & DE_PLANEB_FLIP_DONE_IVB) { |
| 641 | intel_prepare_page_flip(dev, 1); |
| 642 | intel_finish_page_flip_plane(dev, 1); |
| 643 | } |
| 644 | |
| 645 | if (de_iir & DE_PIPEA_VBLANK_IVB) |
| 646 | drm_handle_vblank(dev, 0); |
| 647 | |
Dan Carpenter | f6b07f4 | 2011-05-25 12:56:56 +0300 | [diff] [blame] | 648 | if (de_iir & DE_PIPEB_VBLANK_IVB) |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 649 | drm_handle_vblank(dev, 1); |
| 650 | |
| 651 | /* check event from PCH */ |
| 652 | if (de_iir & DE_PCH_EVENT_IVB) { |
| 653 | if (pch_iir & SDE_HOTPLUG_MASK_CPT) |
| 654 | queue_work(dev_priv->wq, &dev_priv->hotplug_work); |
| 655 | pch_irq_handler(dev); |
| 656 | } |
| 657 | |
| 658 | if (pm_iir & GEN6_PM_DEFERRED_EVENTS) { |
| 659 | unsigned long flags; |
| 660 | spin_lock_irqsave(&dev_priv->rps_lock, flags); |
| 661 | WARN(dev_priv->pm_iir & pm_iir, "Missed a PM interrupt\n"); |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 662 | dev_priv->pm_iir |= pm_iir; |
Daniel Vetter | 4fb066a | 2011-09-08 14:00:20 +0200 | [diff] [blame] | 663 | I915_WRITE(GEN6_PMIMR, dev_priv->pm_iir); |
| 664 | POSTING_READ(GEN6_PMIMR); |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 665 | spin_unlock_irqrestore(&dev_priv->rps_lock, flags); |
| 666 | queue_work(dev_priv->wq, &dev_priv->rps_work); |
| 667 | } |
| 668 | |
| 669 | /* should clear PCH hotplug event before clear CPU irq */ |
| 670 | I915_WRITE(SDEIIR, pch_iir); |
| 671 | I915_WRITE(GTIIR, gt_iir); |
| 672 | I915_WRITE(DEIIR, de_iir); |
| 673 | I915_WRITE(GEN6_PMIIR, pm_iir); |
| 674 | |
| 675 | done: |
| 676 | I915_WRITE(DEIER, de_ier); |
| 677 | POSTING_READ(DEIER); |
| 678 | |
| 679 | return ret; |
| 680 | } |
| 681 | |
Daniel Vetter | e7b4c6b | 2012-03-30 20:24:35 +0200 | [diff] [blame] | 682 | static void ilk_gt_irq_handler(struct drm_device *dev, |
| 683 | struct drm_i915_private *dev_priv, |
| 684 | u32 gt_iir) |
| 685 | { |
| 686 | if (gt_iir & (GT_USER_INTERRUPT | GT_PIPE_NOTIFY)) |
| 687 | notify_ring(dev, &dev_priv->ring[RCS]); |
| 688 | if (gt_iir & GT_BSD_USER_INTERRUPT) |
| 689 | notify_ring(dev, &dev_priv->ring[VCS]); |
| 690 | } |
| 691 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 692 | static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 693 | { |
Jesse Barnes | 4697995 | 2011-04-07 13:53:55 -0700 | [diff] [blame] | 694 | struct drm_device *dev = (struct drm_device *) arg; |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 695 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 696 | int ret = IRQ_NONE; |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 697 | u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir; |
Yuanhan Liu | 2d7b836 | 2010-10-08 10:21:06 +0100 | [diff] [blame] | 698 | u32 hotplug_mask; |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 699 | struct drm_i915_master_private *master_priv; |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 700 | |
Jesse Barnes | 4697995 | 2011-04-07 13:53:55 -0700 | [diff] [blame] | 701 | atomic_inc(&dev_priv->irq_received); |
| 702 | |
Zou, Nanhai | 2d109a8 | 2009-11-06 02:13:01 +0000 | [diff] [blame] | 703 | /* disable master interrupt before clearing iir */ |
| 704 | de_ier = I915_READ(DEIER); |
| 705 | I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 706 | POSTING_READ(DEIER); |
Zou, Nanhai | 2d109a8 | 2009-11-06 02:13:01 +0000 | [diff] [blame] | 707 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 708 | de_iir = I915_READ(DEIIR); |
| 709 | gt_iir = I915_READ(GTIIR); |
Zhenyu Wang | c650156 | 2009-11-03 18:57:21 +0000 | [diff] [blame] | 710 | pch_iir = I915_READ(SDEIIR); |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 711 | pm_iir = I915_READ(GEN6_PMIIR); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 712 | |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 713 | if (de_iir == 0 && gt_iir == 0 && pch_iir == 0 && |
| 714 | (!IS_GEN6(dev) || pm_iir == 0)) |
Zou Nan hai | c7c8510 | 2010-01-15 10:29:06 +0800 | [diff] [blame] | 715 | goto done; |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 716 | |
Yuanhan Liu | 2d7b836 | 2010-10-08 10:21:06 +0100 | [diff] [blame] | 717 | if (HAS_PCH_CPT(dev)) |
| 718 | hotplug_mask = SDE_HOTPLUG_MASK_CPT; |
| 719 | else |
| 720 | hotplug_mask = SDE_HOTPLUG_MASK; |
| 721 | |
Zou Nan hai | c7c8510 | 2010-01-15 10:29:06 +0800 | [diff] [blame] | 722 | ret = IRQ_HANDLED; |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 723 | |
Zou Nan hai | c7c8510 | 2010-01-15 10:29:06 +0800 | [diff] [blame] | 724 | if (dev->primary->master) { |
| 725 | master_priv = dev->primary->master->driver_priv; |
| 726 | if (master_priv->sarea_priv) |
| 727 | master_priv->sarea_priv->last_dispatch = |
| 728 | READ_BREADCRUMB(dev_priv); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 729 | } |
| 730 | |
Daniel Vetter | e7b4c6b | 2012-03-30 20:24:35 +0200 | [diff] [blame] | 731 | if (IS_GEN5(dev)) |
| 732 | ilk_gt_irq_handler(dev, dev_priv, gt_iir); |
| 733 | else |
| 734 | snb_gt_irq_handler(dev, dev_priv, gt_iir); |
Zou Nan hai | c7c8510 | 2010-01-15 10:29:06 +0800 | [diff] [blame] | 735 | |
| 736 | if (de_iir & DE_GSE) |
Chris Wilson | 3b61796 | 2010-08-24 09:02:58 +0100 | [diff] [blame] | 737 | intel_opregion_gse_intr(dev); |
Zou Nan hai | c7c8510 | 2010-01-15 10:29:06 +0800 | [diff] [blame] | 738 | |
Zhenyu Wang | f072d2e | 2010-02-09 09:46:19 +0800 | [diff] [blame] | 739 | if (de_iir & DE_PLANEA_FLIP_DONE) { |
Jesse Barnes | 013d5aa | 2010-01-29 11:18:31 -0800 | [diff] [blame] | 740 | intel_prepare_page_flip(dev, 0); |
Chris Wilson | 2bbda38 | 2010-09-02 17:59:39 +0100 | [diff] [blame] | 741 | intel_finish_page_flip_plane(dev, 0); |
Jesse Barnes | 013d5aa | 2010-01-29 11:18:31 -0800 | [diff] [blame] | 742 | } |
| 743 | |
Zhenyu Wang | f072d2e | 2010-02-09 09:46:19 +0800 | [diff] [blame] | 744 | if (de_iir & DE_PLANEB_FLIP_DONE) { |
| 745 | intel_prepare_page_flip(dev, 1); |
Chris Wilson | 2bbda38 | 2010-09-02 17:59:39 +0100 | [diff] [blame] | 746 | intel_finish_page_flip_plane(dev, 1); |
Jesse Barnes | 013d5aa | 2010-01-29 11:18:31 -0800 | [diff] [blame] | 747 | } |
Li Peng | c062df6 | 2010-01-23 00:12:58 +0800 | [diff] [blame] | 748 | |
Zhenyu Wang | f072d2e | 2010-02-09 09:46:19 +0800 | [diff] [blame] | 749 | if (de_iir & DE_PIPEA_VBLANK) |
| 750 | drm_handle_vblank(dev, 0); |
| 751 | |
| 752 | if (de_iir & DE_PIPEB_VBLANK) |
| 753 | drm_handle_vblank(dev, 1); |
| 754 | |
Zou Nan hai | c7c8510 | 2010-01-15 10:29:06 +0800 | [diff] [blame] | 755 | /* check event from PCH */ |
Jesse Barnes | 776ad80 | 2011-01-04 15:09:39 -0800 | [diff] [blame] | 756 | if (de_iir & DE_PCH_EVENT) { |
| 757 | if (pch_iir & hotplug_mask) |
| 758 | queue_work(dev_priv->wq, &dev_priv->hotplug_work); |
| 759 | pch_irq_handler(dev); |
| 760 | } |
Zou Nan hai | c7c8510 | 2010-01-15 10:29:06 +0800 | [diff] [blame] | 761 | |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 762 | if (de_iir & DE_PCU_EVENT) { |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 763 | I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS)); |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 764 | i915_handle_rps_change(dev); |
| 765 | } |
| 766 | |
Ben Widawsky | 4912d04 | 2011-04-25 11:25:20 -0700 | [diff] [blame] | 767 | if (IS_GEN6(dev) && pm_iir & GEN6_PM_DEFERRED_EVENTS) { |
| 768 | /* |
| 769 | * IIR bits should never already be set because IMR should |
| 770 | * prevent an interrupt from being shown in IIR. The warning |
| 771 | * displays a case where we've unsafely cleared |
| 772 | * dev_priv->pm_iir. Although missing an interrupt of the same |
| 773 | * type is not a problem, it displays a problem in the logic. |
| 774 | * |
| 775 | * The mask bit in IMR is cleared by rps_work. |
| 776 | */ |
| 777 | unsigned long flags; |
| 778 | spin_lock_irqsave(&dev_priv->rps_lock, flags); |
| 779 | WARN(dev_priv->pm_iir & pm_iir, "Missed a PM interrupt\n"); |
Ben Widawsky | 4912d04 | 2011-04-25 11:25:20 -0700 | [diff] [blame] | 780 | dev_priv->pm_iir |= pm_iir; |
Daniel Vetter | 4fb066a | 2011-09-08 14:00:20 +0200 | [diff] [blame] | 781 | I915_WRITE(GEN6_PMIMR, dev_priv->pm_iir); |
| 782 | POSTING_READ(GEN6_PMIMR); |
Ben Widawsky | 4912d04 | 2011-04-25 11:25:20 -0700 | [diff] [blame] | 783 | spin_unlock_irqrestore(&dev_priv->rps_lock, flags); |
| 784 | queue_work(dev_priv->wq, &dev_priv->rps_work); |
| 785 | } |
Jesse Barnes | 3b8d8d9 | 2010-12-17 14:19:02 -0800 | [diff] [blame] | 786 | |
Zou Nan hai | c7c8510 | 2010-01-15 10:29:06 +0800 | [diff] [blame] | 787 | /* should clear PCH hotplug event before clear CPU irq */ |
| 788 | I915_WRITE(SDEIIR, pch_iir); |
| 789 | I915_WRITE(GTIIR, gt_iir); |
| 790 | I915_WRITE(DEIIR, de_iir); |
Ben Widawsky | 4912d04 | 2011-04-25 11:25:20 -0700 | [diff] [blame] | 791 | I915_WRITE(GEN6_PMIIR, pm_iir); |
Zou Nan hai | c7c8510 | 2010-01-15 10:29:06 +0800 | [diff] [blame] | 792 | |
| 793 | done: |
Zou, Nanhai | 2d109a8 | 2009-11-06 02:13:01 +0000 | [diff] [blame] | 794 | I915_WRITE(DEIER, de_ier); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 795 | POSTING_READ(DEIER); |
Zou, Nanhai | 2d109a8 | 2009-11-06 02:13:01 +0000 | [diff] [blame] | 796 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 797 | return ret; |
| 798 | } |
| 799 | |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 800 | /** |
| 801 | * i915_error_work_func - do process context error handling work |
| 802 | * @work: work struct |
| 803 | * |
| 804 | * Fire an error uevent so userspace can see that a hang or error |
| 805 | * was detected. |
| 806 | */ |
| 807 | static void i915_error_work_func(struct work_struct *work) |
| 808 | { |
| 809 | drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, |
| 810 | error_work); |
| 811 | struct drm_device *dev = dev_priv->dev; |
Ben Gamari | f316a42 | 2009-09-14 17:48:46 -0400 | [diff] [blame] | 812 | char *error_event[] = { "ERROR=1", NULL }; |
| 813 | char *reset_event[] = { "RESET=1", NULL }; |
| 814 | char *reset_done_event[] = { "ERROR=0", NULL }; |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 815 | |
Ben Gamari | f316a42 | 2009-09-14 17:48:46 -0400 | [diff] [blame] | 816 | kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 817 | |
Ben Gamari | ba1234d | 2009-09-14 17:48:47 -0400 | [diff] [blame] | 818 | if (atomic_read(&dev_priv->mm.wedged)) { |
Chris Wilson | f803aa5 | 2010-09-19 12:38:26 +0100 | [diff] [blame] | 819 | DRM_DEBUG_DRIVER("resetting chip\n"); |
| 820 | kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_event); |
| 821 | if (!i915_reset(dev, GRDOM_RENDER)) { |
| 822 | atomic_set(&dev_priv->mm.wedged, 0); |
| 823 | kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_done_event); |
Ben Gamari | f316a42 | 2009-09-14 17:48:46 -0400 | [diff] [blame] | 824 | } |
Chris Wilson | 30dbf0c | 2010-09-25 10:19:17 +0100 | [diff] [blame] | 825 | complete_all(&dev_priv->error_completion); |
Ben Gamari | f316a42 | 2009-09-14 17:48:46 -0400 | [diff] [blame] | 826 | } |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 827 | } |
| 828 | |
Chris Wilson | 3bd3c93 | 2010-08-19 08:19:30 +0100 | [diff] [blame] | 829 | #ifdef CONFIG_DEBUG_FS |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 830 | static struct drm_i915_error_object * |
Chris Wilson | bcfb2e2 | 2011-01-07 21:06:07 +0000 | [diff] [blame] | 831 | i915_error_object_create(struct drm_i915_private *dev_priv, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 832 | struct drm_i915_gem_object *src) |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 833 | { |
| 834 | struct drm_i915_error_object *dst; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 835 | int page, page_count; |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 836 | u32 reloc_offset; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 837 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 838 | if (src == NULL || src->pages == NULL) |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 839 | return NULL; |
| 840 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 841 | page_count = src->base.size / PAGE_SIZE; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 842 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 843 | dst = kmalloc(sizeof(*dst) + page_count * sizeof(u32 *), GFP_ATOMIC); |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 844 | if (dst == NULL) |
| 845 | return NULL; |
| 846 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 847 | reloc_offset = src->gtt_offset; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 848 | for (page = 0; page < page_count; page++) { |
Andrew Morton | 788885a | 2010-05-11 14:07:05 -0700 | [diff] [blame] | 849 | unsigned long flags; |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 850 | void *d; |
Andrew Morton | 788885a | 2010-05-11 14:07:05 -0700 | [diff] [blame] | 851 | |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 852 | d = kmalloc(PAGE_SIZE, GFP_ATOMIC); |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 853 | if (d == NULL) |
| 854 | goto unwind; |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 855 | |
Andrew Morton | 788885a | 2010-05-11 14:07:05 -0700 | [diff] [blame] | 856 | local_irq_save(flags); |
Daniel Vetter | 74898d7 | 2012-02-15 23:50:22 +0100 | [diff] [blame] | 857 | if (reloc_offset < dev_priv->mm.gtt_mappable_end && |
| 858 | src->has_global_gtt_mapping) { |
Chris Wilson | 172975aa | 2011-12-14 13:57:25 +0100 | [diff] [blame] | 859 | void __iomem *s; |
| 860 | |
| 861 | /* Simply ignore tiling or any overlapping fence. |
| 862 | * It's part of the error state, and this hopefully |
| 863 | * captures what the GPU read. |
| 864 | */ |
| 865 | |
| 866 | s = io_mapping_map_atomic_wc(dev_priv->mm.gtt_mapping, |
| 867 | reloc_offset); |
| 868 | memcpy_fromio(d, s, PAGE_SIZE); |
| 869 | io_mapping_unmap_atomic(s); |
| 870 | } else { |
| 871 | void *s; |
| 872 | |
| 873 | drm_clflush_pages(&src->pages[page], 1); |
| 874 | |
| 875 | s = kmap_atomic(src->pages[page]); |
| 876 | memcpy(d, s, PAGE_SIZE); |
| 877 | kunmap_atomic(s); |
| 878 | |
| 879 | drm_clflush_pages(&src->pages[page], 1); |
| 880 | } |
Andrew Morton | 788885a | 2010-05-11 14:07:05 -0700 | [diff] [blame] | 881 | local_irq_restore(flags); |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 882 | |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 883 | dst->pages[page] = d; |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 884 | |
| 885 | reloc_offset += PAGE_SIZE; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 886 | } |
| 887 | dst->page_count = page_count; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 888 | dst->gtt_offset = src->gtt_offset; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 889 | |
| 890 | return dst; |
| 891 | |
| 892 | unwind: |
| 893 | while (page--) |
| 894 | kfree(dst->pages[page]); |
| 895 | kfree(dst); |
| 896 | return NULL; |
| 897 | } |
| 898 | |
| 899 | static void |
| 900 | i915_error_object_free(struct drm_i915_error_object *obj) |
| 901 | { |
| 902 | int page; |
| 903 | |
| 904 | if (obj == NULL) |
| 905 | return; |
| 906 | |
| 907 | for (page = 0; page < obj->page_count; page++) |
| 908 | kfree(obj->pages[page]); |
| 909 | |
| 910 | kfree(obj); |
| 911 | } |
| 912 | |
| 913 | static void |
| 914 | i915_error_state_free(struct drm_device *dev, |
| 915 | struct drm_i915_error_state *error) |
| 916 | { |
Chris Wilson | e2f973d | 2011-01-27 19:15:11 +0000 | [diff] [blame] | 917 | int i; |
| 918 | |
Chris Wilson | 52d39a2 | 2012-02-15 11:25:37 +0000 | [diff] [blame] | 919 | for (i = 0; i < ARRAY_SIZE(error->ring); i++) { |
| 920 | i915_error_object_free(error->ring[i].batchbuffer); |
| 921 | i915_error_object_free(error->ring[i].ringbuffer); |
| 922 | kfree(error->ring[i].requests); |
| 923 | } |
Chris Wilson | e2f973d | 2011-01-27 19:15:11 +0000 | [diff] [blame] | 924 | |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 925 | kfree(error->active_bo); |
Chris Wilson | 6ef3d42 | 2010-08-04 20:26:07 +0100 | [diff] [blame] | 926 | kfree(error->overlay); |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 927 | kfree(error); |
| 928 | } |
| 929 | |
Chris Wilson | c724e8a | 2010-11-22 08:07:02 +0000 | [diff] [blame] | 930 | static u32 capture_bo_list(struct drm_i915_error_buffer *err, |
| 931 | int count, |
| 932 | struct list_head *head) |
| 933 | { |
| 934 | struct drm_i915_gem_object *obj; |
| 935 | int i = 0; |
| 936 | |
| 937 | list_for_each_entry(obj, head, mm_list) { |
| 938 | err->size = obj->base.size; |
| 939 | err->name = obj->base.name; |
| 940 | err->seqno = obj->last_rendering_seqno; |
| 941 | err->gtt_offset = obj->gtt_offset; |
| 942 | err->read_domains = obj->base.read_domains; |
| 943 | err->write_domain = obj->base.write_domain; |
| 944 | err->fence_reg = obj->fence_reg; |
| 945 | err->pinned = 0; |
| 946 | if (obj->pin_count > 0) |
| 947 | err->pinned = 1; |
| 948 | if (obj->user_pin_count > 0) |
| 949 | err->pinned = -1; |
| 950 | err->tiling = obj->tiling_mode; |
| 951 | err->dirty = obj->dirty; |
| 952 | err->purgeable = obj->madv != I915_MADV_WILLNEED; |
Daniel Vetter | 96154f2 | 2011-12-14 13:57:00 +0100 | [diff] [blame] | 953 | err->ring = obj->ring ? obj->ring->id : -1; |
Chris Wilson | 93dfb40 | 2011-03-29 16:59:50 -0700 | [diff] [blame] | 954 | err->cache_level = obj->cache_level; |
Chris Wilson | c724e8a | 2010-11-22 08:07:02 +0000 | [diff] [blame] | 955 | |
| 956 | if (++i == count) |
| 957 | break; |
| 958 | |
| 959 | err++; |
| 960 | } |
| 961 | |
| 962 | return i; |
| 963 | } |
| 964 | |
Chris Wilson | 748ebc6 | 2010-10-24 10:28:47 +0100 | [diff] [blame] | 965 | static void i915_gem_record_fences(struct drm_device *dev, |
| 966 | struct drm_i915_error_state *error) |
| 967 | { |
| 968 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 969 | int i; |
| 970 | |
| 971 | /* Fences */ |
| 972 | switch (INTEL_INFO(dev)->gen) { |
Daniel Vetter | 775d17b | 2011-10-09 21:52:01 +0200 | [diff] [blame] | 973 | case 7: |
Chris Wilson | 748ebc6 | 2010-10-24 10:28:47 +0100 | [diff] [blame] | 974 | case 6: |
| 975 | for (i = 0; i < 16; i++) |
| 976 | error->fence[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 + (i * 8)); |
| 977 | break; |
| 978 | case 5: |
| 979 | case 4: |
| 980 | for (i = 0; i < 16; i++) |
| 981 | error->fence[i] = I915_READ64(FENCE_REG_965_0 + (i * 8)); |
| 982 | break; |
| 983 | case 3: |
| 984 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) |
| 985 | for (i = 0; i < 8; i++) |
| 986 | error->fence[i+8] = I915_READ(FENCE_REG_945_8 + (i * 4)); |
| 987 | case 2: |
| 988 | for (i = 0; i < 8; i++) |
| 989 | error->fence[i] = I915_READ(FENCE_REG_830_0 + (i * 4)); |
| 990 | break; |
| 991 | |
| 992 | } |
| 993 | } |
| 994 | |
Chris Wilson | bcfb2e2 | 2011-01-07 21:06:07 +0000 | [diff] [blame] | 995 | static struct drm_i915_error_object * |
| 996 | i915_error_first_batchbuffer(struct drm_i915_private *dev_priv, |
| 997 | struct intel_ring_buffer *ring) |
| 998 | { |
| 999 | struct drm_i915_gem_object *obj; |
| 1000 | u32 seqno; |
| 1001 | |
| 1002 | if (!ring->get_seqno) |
| 1003 | return NULL; |
| 1004 | |
| 1005 | seqno = ring->get_seqno(ring); |
| 1006 | list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list) { |
| 1007 | if (obj->ring != ring) |
| 1008 | continue; |
| 1009 | |
Chris Wilson | c37d9a5 | 2011-01-12 20:33:01 +0000 | [diff] [blame] | 1010 | if (i915_seqno_passed(seqno, obj->last_rendering_seqno)) |
Chris Wilson | bcfb2e2 | 2011-01-07 21:06:07 +0000 | [diff] [blame] | 1011 | continue; |
| 1012 | |
| 1013 | if ((obj->base.read_domains & I915_GEM_DOMAIN_COMMAND) == 0) |
| 1014 | continue; |
| 1015 | |
| 1016 | /* We need to copy these to an anonymous buffer as the simplest |
| 1017 | * method to avoid being overwritten by userspace. |
| 1018 | */ |
| 1019 | return i915_error_object_create(dev_priv, obj); |
| 1020 | } |
| 1021 | |
| 1022 | return NULL; |
| 1023 | } |
| 1024 | |
Daniel Vetter | d27b1e0 | 2011-12-14 13:57:01 +0100 | [diff] [blame] | 1025 | static void i915_record_ring_state(struct drm_device *dev, |
| 1026 | struct drm_i915_error_state *error, |
| 1027 | struct intel_ring_buffer *ring) |
| 1028 | { |
| 1029 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1030 | |
Daniel Vetter | 33f3f51 | 2011-12-14 13:57:39 +0100 | [diff] [blame] | 1031 | if (INTEL_INFO(dev)->gen >= 6) { |
Daniel Vetter | 33f3f51 | 2011-12-14 13:57:39 +0100 | [diff] [blame] | 1032 | error->fault_reg[ring->id] = I915_READ(RING_FAULT_REG(ring)); |
Daniel Vetter | 7e3b873 | 2012-02-01 22:26:45 +0100 | [diff] [blame] | 1033 | error->semaphore_mboxes[ring->id][0] |
| 1034 | = I915_READ(RING_SYNC_0(ring->mmio_base)); |
| 1035 | error->semaphore_mboxes[ring->id][1] |
| 1036 | = I915_READ(RING_SYNC_1(ring->mmio_base)); |
Daniel Vetter | 33f3f51 | 2011-12-14 13:57:39 +0100 | [diff] [blame] | 1037 | } |
Daniel Vetter | c1cd90e | 2011-12-14 13:57:02 +0100 | [diff] [blame] | 1038 | |
Daniel Vetter | d27b1e0 | 2011-12-14 13:57:01 +0100 | [diff] [blame] | 1039 | if (INTEL_INFO(dev)->gen >= 4) { |
Daniel Vetter | 9d2f41f | 2012-04-02 21:41:45 +0200 | [diff] [blame^] | 1040 | error->faddr[ring->id] = I915_READ(RING_DMA_FADD(ring->mmio_base)); |
Daniel Vetter | d27b1e0 | 2011-12-14 13:57:01 +0100 | [diff] [blame] | 1041 | error->ipeir[ring->id] = I915_READ(RING_IPEIR(ring->mmio_base)); |
| 1042 | error->ipehr[ring->id] = I915_READ(RING_IPEHR(ring->mmio_base)); |
| 1043 | error->instdone[ring->id] = I915_READ(RING_INSTDONE(ring->mmio_base)); |
Daniel Vetter | c1cd90e | 2011-12-14 13:57:02 +0100 | [diff] [blame] | 1044 | error->instps[ring->id] = I915_READ(RING_INSTPS(ring->mmio_base)); |
Daniel Vetter | d27b1e0 | 2011-12-14 13:57:01 +0100 | [diff] [blame] | 1045 | if (ring->id == RCS) { |
Daniel Vetter | d27b1e0 | 2011-12-14 13:57:01 +0100 | [diff] [blame] | 1046 | error->instdone1 = I915_READ(INSTDONE1); |
| 1047 | error->bbaddr = I915_READ64(BB_ADDR); |
| 1048 | } |
| 1049 | } else { |
Daniel Vetter | 9d2f41f | 2012-04-02 21:41:45 +0200 | [diff] [blame^] | 1050 | error->faddr[ring->id] = I915_READ(DMA_FADD_I8XX); |
Daniel Vetter | d27b1e0 | 2011-12-14 13:57:01 +0100 | [diff] [blame] | 1051 | error->ipeir[ring->id] = I915_READ(IPEIR); |
| 1052 | error->ipehr[ring->id] = I915_READ(IPEHR); |
| 1053 | error->instdone[ring->id] = I915_READ(INSTDONE); |
Daniel Vetter | d27b1e0 | 2011-12-14 13:57:01 +0100 | [diff] [blame] | 1054 | } |
| 1055 | |
Daniel Vetter | c1cd90e | 2011-12-14 13:57:02 +0100 | [diff] [blame] | 1056 | error->instpm[ring->id] = I915_READ(RING_INSTPM(ring->mmio_base)); |
Daniel Vetter | d27b1e0 | 2011-12-14 13:57:01 +0100 | [diff] [blame] | 1057 | error->seqno[ring->id] = ring->get_seqno(ring); |
| 1058 | error->acthd[ring->id] = intel_ring_get_active_head(ring); |
Daniel Vetter | c1cd90e | 2011-12-14 13:57:02 +0100 | [diff] [blame] | 1059 | error->head[ring->id] = I915_READ_HEAD(ring); |
| 1060 | error->tail[ring->id] = I915_READ_TAIL(ring); |
Daniel Vetter | 7e3b873 | 2012-02-01 22:26:45 +0100 | [diff] [blame] | 1061 | |
| 1062 | error->cpu_ring_head[ring->id] = ring->head; |
| 1063 | error->cpu_ring_tail[ring->id] = ring->tail; |
Daniel Vetter | d27b1e0 | 2011-12-14 13:57:01 +0100 | [diff] [blame] | 1064 | } |
| 1065 | |
Chris Wilson | 52d39a2 | 2012-02-15 11:25:37 +0000 | [diff] [blame] | 1066 | static void i915_gem_record_rings(struct drm_device *dev, |
| 1067 | struct drm_i915_error_state *error) |
| 1068 | { |
| 1069 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1070 | struct drm_i915_gem_request *request; |
| 1071 | int i, count; |
| 1072 | |
| 1073 | for (i = 0; i < I915_NUM_RINGS; i++) { |
| 1074 | struct intel_ring_buffer *ring = &dev_priv->ring[i]; |
| 1075 | |
| 1076 | if (ring->obj == NULL) |
| 1077 | continue; |
| 1078 | |
| 1079 | i915_record_ring_state(dev, error, ring); |
| 1080 | |
| 1081 | error->ring[i].batchbuffer = |
| 1082 | i915_error_first_batchbuffer(dev_priv, ring); |
| 1083 | |
| 1084 | error->ring[i].ringbuffer = |
| 1085 | i915_error_object_create(dev_priv, ring->obj); |
| 1086 | |
| 1087 | count = 0; |
| 1088 | list_for_each_entry(request, &ring->request_list, list) |
| 1089 | count++; |
| 1090 | |
| 1091 | error->ring[i].num_requests = count; |
| 1092 | error->ring[i].requests = |
| 1093 | kmalloc(count*sizeof(struct drm_i915_error_request), |
| 1094 | GFP_ATOMIC); |
| 1095 | if (error->ring[i].requests == NULL) { |
| 1096 | error->ring[i].num_requests = 0; |
| 1097 | continue; |
| 1098 | } |
| 1099 | |
| 1100 | count = 0; |
| 1101 | list_for_each_entry(request, &ring->request_list, list) { |
| 1102 | struct drm_i915_error_request *erq; |
| 1103 | |
| 1104 | erq = &error->ring[i].requests[count++]; |
| 1105 | erq->seqno = request->seqno; |
| 1106 | erq->jiffies = request->emitted_jiffies; |
Chris Wilson | ee4f42b | 2012-02-15 11:25:38 +0000 | [diff] [blame] | 1107 | erq->tail = request->tail; |
Chris Wilson | 52d39a2 | 2012-02-15 11:25:37 +0000 | [diff] [blame] | 1108 | } |
| 1109 | } |
| 1110 | } |
| 1111 | |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1112 | /** |
| 1113 | * i915_capture_error_state - capture an error record for later analysis |
| 1114 | * @dev: drm device |
| 1115 | * |
| 1116 | * Should be called when an error is detected (either a hang or an error |
| 1117 | * interrupt) to capture error state from the time of the error. Fills |
| 1118 | * out a structure which becomes available in debugfs for user level tools |
| 1119 | * to pick up. |
| 1120 | */ |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 1121 | static void i915_capture_error_state(struct drm_device *dev) |
| 1122 | { |
| 1123 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1124 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 1125 | struct drm_i915_error_state *error; |
| 1126 | unsigned long flags; |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1127 | int i, pipe; |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 1128 | |
| 1129 | spin_lock_irqsave(&dev_priv->error_lock, flags); |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 1130 | error = dev_priv->first_error; |
| 1131 | spin_unlock_irqrestore(&dev_priv->error_lock, flags); |
| 1132 | if (error) |
| 1133 | return; |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 1134 | |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1135 | /* Account for pipe specific data like PIPE*STAT */ |
Daniel Vetter | 33f3f51 | 2011-12-14 13:57:39 +0100 | [diff] [blame] | 1136 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 1137 | if (!error) { |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 1138 | DRM_DEBUG_DRIVER("out of memory, not capturing error state\n"); |
| 1139 | return; |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 1140 | } |
| 1141 | |
Chris Wilson | b6f7833 | 2011-02-01 14:15:55 +0000 | [diff] [blame] | 1142 | DRM_INFO("capturing error event; look for more information in /debug/dri/%d/i915_error_state\n", |
| 1143 | dev->primary->index); |
Chris Wilson | 2fa772f3 | 2010-10-01 13:23:27 +0100 | [diff] [blame] | 1144 | |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 1145 | error->eir = I915_READ(EIR); |
| 1146 | error->pgtbl_er = I915_READ(PGTBL_ER); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1147 | for_each_pipe(pipe) |
| 1148 | error->pipestat[pipe] = I915_READ(PIPESTAT(pipe)); |
Daniel Vetter | d27b1e0 | 2011-12-14 13:57:01 +0100 | [diff] [blame] | 1149 | |
Daniel Vetter | 33f3f51 | 2011-12-14 13:57:39 +0100 | [diff] [blame] | 1150 | if (INTEL_INFO(dev)->gen >= 6) { |
Chris Wilson | f406839 | 2010-10-27 20:36:41 +0100 | [diff] [blame] | 1151 | error->error = I915_READ(ERROR_GEN6); |
Daniel Vetter | 33f3f51 | 2011-12-14 13:57:39 +0100 | [diff] [blame] | 1152 | error->done_reg = I915_READ(DONE_REG); |
| 1153 | } |
Chris Wilson | add354d | 2010-10-29 19:00:51 +0100 | [diff] [blame] | 1154 | |
Chris Wilson | 748ebc6 | 2010-10-24 10:28:47 +0100 | [diff] [blame] | 1155 | i915_gem_record_fences(dev, error); |
Chris Wilson | 52d39a2 | 2012-02-15 11:25:37 +0000 | [diff] [blame] | 1156 | i915_gem_record_rings(dev, error); |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 1157 | |
Chris Wilson | c724e8a | 2010-11-22 08:07:02 +0000 | [diff] [blame] | 1158 | /* Record buffers on the active and pinned lists. */ |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 1159 | error->active_bo = NULL; |
Chris Wilson | c724e8a | 2010-11-22 08:07:02 +0000 | [diff] [blame] | 1160 | error->pinned_bo = NULL; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 1161 | |
Chris Wilson | bcfb2e2 | 2011-01-07 21:06:07 +0000 | [diff] [blame] | 1162 | i = 0; |
| 1163 | list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list) |
| 1164 | i++; |
| 1165 | error->active_bo_count = i; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1166 | list_for_each_entry(obj, &dev_priv->mm.pinned_list, mm_list) |
Chris Wilson | bcfb2e2 | 2011-01-07 21:06:07 +0000 | [diff] [blame] | 1167 | i++; |
| 1168 | error->pinned_bo_count = i - error->active_bo_count; |
Chris Wilson | c724e8a | 2010-11-22 08:07:02 +0000 | [diff] [blame] | 1169 | |
Chris Wilson | 8e934db | 2011-01-24 12:34:00 +0000 | [diff] [blame] | 1170 | error->active_bo = NULL; |
| 1171 | error->pinned_bo = NULL; |
Chris Wilson | bcfb2e2 | 2011-01-07 21:06:07 +0000 | [diff] [blame] | 1172 | if (i) { |
| 1173 | error->active_bo = kmalloc(sizeof(*error->active_bo)*i, |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 1174 | GFP_ATOMIC); |
Chris Wilson | c724e8a | 2010-11-22 08:07:02 +0000 | [diff] [blame] | 1175 | if (error->active_bo) |
| 1176 | error->pinned_bo = |
| 1177 | error->active_bo + error->active_bo_count; |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 1178 | } |
| 1179 | |
Chris Wilson | c724e8a | 2010-11-22 08:07:02 +0000 | [diff] [blame] | 1180 | if (error->active_bo) |
| 1181 | error->active_bo_count = |
| 1182 | capture_bo_list(error->active_bo, |
| 1183 | error->active_bo_count, |
| 1184 | &dev_priv->mm.active_list); |
| 1185 | |
| 1186 | if (error->pinned_bo) |
| 1187 | error->pinned_bo_count = |
| 1188 | capture_bo_list(error->pinned_bo, |
| 1189 | error->pinned_bo_count, |
| 1190 | &dev_priv->mm.pinned_list); |
| 1191 | |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1192 | do_gettimeofday(&error->time); |
| 1193 | |
Chris Wilson | 6ef3d42 | 2010-08-04 20:26:07 +0100 | [diff] [blame] | 1194 | error->overlay = intel_overlay_capture_error_state(dev); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 1195 | error->display = intel_display_capture_error_state(dev); |
Chris Wilson | 6ef3d42 | 2010-08-04 20:26:07 +0100 | [diff] [blame] | 1196 | |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 1197 | spin_lock_irqsave(&dev_priv->error_lock, flags); |
| 1198 | if (dev_priv->first_error == NULL) { |
| 1199 | dev_priv->first_error = error; |
| 1200 | error = NULL; |
| 1201 | } |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 1202 | spin_unlock_irqrestore(&dev_priv->error_lock, flags); |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 1203 | |
| 1204 | if (error) |
| 1205 | i915_error_state_free(dev, error); |
| 1206 | } |
| 1207 | |
| 1208 | void i915_destroy_error_state(struct drm_device *dev) |
| 1209 | { |
| 1210 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1211 | struct drm_i915_error_state *error; |
Ben Widawsky | 6dc0e81 | 2012-01-23 15:30:02 -0800 | [diff] [blame] | 1212 | unsigned long flags; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 1213 | |
Ben Widawsky | 6dc0e81 | 2012-01-23 15:30:02 -0800 | [diff] [blame] | 1214 | spin_lock_irqsave(&dev_priv->error_lock, flags); |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 1215 | error = dev_priv->first_error; |
| 1216 | dev_priv->first_error = NULL; |
Ben Widawsky | 6dc0e81 | 2012-01-23 15:30:02 -0800 | [diff] [blame] | 1217 | spin_unlock_irqrestore(&dev_priv->error_lock, flags); |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 1218 | |
| 1219 | if (error) |
| 1220 | i915_error_state_free(dev, error); |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 1221 | } |
Chris Wilson | 3bd3c93 | 2010-08-19 08:19:30 +0100 | [diff] [blame] | 1222 | #else |
| 1223 | #define i915_capture_error_state(x) |
| 1224 | #endif |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 1225 | |
Chris Wilson | 35aed2e | 2010-05-27 13:18:12 +0100 | [diff] [blame] | 1226 | static void i915_report_and_clear_eir(struct drm_device *dev) |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1227 | { |
| 1228 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1229 | u32 eir = I915_READ(EIR); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1230 | int pipe; |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1231 | |
Chris Wilson | 35aed2e | 2010-05-27 13:18:12 +0100 | [diff] [blame] | 1232 | if (!eir) |
| 1233 | return; |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1234 | |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 1235 | pr_err("render error detected, EIR: 0x%08x\n", eir); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1236 | |
| 1237 | if (IS_G4X(dev)) { |
| 1238 | if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) { |
| 1239 | u32 ipeir = I915_READ(IPEIR_I965); |
| 1240 | |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 1241 | pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); |
| 1242 | pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); |
| 1243 | pr_err(" INSTDONE: 0x%08x\n", |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1244 | I915_READ(INSTDONE_I965)); |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 1245 | pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); |
| 1246 | pr_err(" INSTDONE1: 0x%08x\n", I915_READ(INSTDONE1)); |
| 1247 | pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1248 | I915_WRITE(IPEIR_I965, ipeir); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 1249 | POSTING_READ(IPEIR_I965); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1250 | } |
| 1251 | if (eir & GM45_ERROR_PAGE_TABLE) { |
| 1252 | u32 pgtbl_err = I915_READ(PGTBL_ER); |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 1253 | pr_err("page table error\n"); |
| 1254 | pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1255 | I915_WRITE(PGTBL_ER, pgtbl_err); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 1256 | POSTING_READ(PGTBL_ER); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1257 | } |
| 1258 | } |
| 1259 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1260 | if (!IS_GEN2(dev)) { |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1261 | if (eir & I915_ERROR_PAGE_TABLE) { |
| 1262 | u32 pgtbl_err = I915_READ(PGTBL_ER); |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 1263 | pr_err("page table error\n"); |
| 1264 | pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1265 | I915_WRITE(PGTBL_ER, pgtbl_err); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 1266 | POSTING_READ(PGTBL_ER); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | if (eir & I915_ERROR_MEMORY_REFRESH) { |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 1271 | pr_err("memory refresh error:\n"); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1272 | for_each_pipe(pipe) |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 1273 | pr_err("pipe %c stat: 0x%08x\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1274 | pipe_name(pipe), I915_READ(PIPESTAT(pipe))); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1275 | /* pipestat has already been acked */ |
| 1276 | } |
| 1277 | if (eir & I915_ERROR_INSTRUCTION) { |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 1278 | pr_err("instruction error\n"); |
| 1279 | pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM)); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1280 | if (INTEL_INFO(dev)->gen < 4) { |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1281 | u32 ipeir = I915_READ(IPEIR); |
| 1282 | |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 1283 | pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR)); |
| 1284 | pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR)); |
| 1285 | pr_err(" INSTDONE: 0x%08x\n", I915_READ(INSTDONE)); |
| 1286 | pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD)); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1287 | I915_WRITE(IPEIR, ipeir); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 1288 | POSTING_READ(IPEIR); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1289 | } else { |
| 1290 | u32 ipeir = I915_READ(IPEIR_I965); |
| 1291 | |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 1292 | pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); |
| 1293 | pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); |
| 1294 | pr_err(" INSTDONE: 0x%08x\n", |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1295 | I915_READ(INSTDONE_I965)); |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 1296 | pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); |
| 1297 | pr_err(" INSTDONE1: 0x%08x\n", I915_READ(INSTDONE1)); |
| 1298 | pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1299 | I915_WRITE(IPEIR_I965, ipeir); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 1300 | POSTING_READ(IPEIR_I965); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | I915_WRITE(EIR, eir); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 1305 | POSTING_READ(EIR); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1306 | eir = I915_READ(EIR); |
| 1307 | if (eir) { |
| 1308 | /* |
| 1309 | * some errors might have become stuck, |
| 1310 | * mask them. |
| 1311 | */ |
| 1312 | DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir); |
| 1313 | I915_WRITE(EMR, I915_READ(EMR) | eir); |
| 1314 | I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); |
| 1315 | } |
Chris Wilson | 35aed2e | 2010-05-27 13:18:12 +0100 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | /** |
| 1319 | * i915_handle_error - handle an error interrupt |
| 1320 | * @dev: drm device |
| 1321 | * |
| 1322 | * Do some basic checking of regsiter state at error interrupt time and |
| 1323 | * dump it to the syslog. Also call i915_capture_error_state() to make |
| 1324 | * sure we get a record and make it available in debugfs. Fire a uevent |
| 1325 | * so userspace knows something bad happened (should trigger collection |
| 1326 | * of a ring dump etc.). |
| 1327 | */ |
Chris Wilson | 527f9e9 | 2010-11-11 01:16:58 +0000 | [diff] [blame] | 1328 | void i915_handle_error(struct drm_device *dev, bool wedged) |
Chris Wilson | 35aed2e | 2010-05-27 13:18:12 +0100 | [diff] [blame] | 1329 | { |
| 1330 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1331 | |
| 1332 | i915_capture_error_state(dev); |
| 1333 | i915_report_and_clear_eir(dev); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1334 | |
Ben Gamari | ba1234d | 2009-09-14 17:48:47 -0400 | [diff] [blame] | 1335 | if (wedged) { |
Chris Wilson | 30dbf0c | 2010-09-25 10:19:17 +0100 | [diff] [blame] | 1336 | INIT_COMPLETION(dev_priv->error_completion); |
Ben Gamari | ba1234d | 2009-09-14 17:48:47 -0400 | [diff] [blame] | 1337 | atomic_set(&dev_priv->mm.wedged, 1); |
| 1338 | |
Ben Gamari | 11ed50e | 2009-09-14 17:48:45 -0400 | [diff] [blame] | 1339 | /* |
| 1340 | * Wakeup waiting processes so they don't hang |
| 1341 | */ |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1342 | wake_up_all(&dev_priv->ring[RCS].irq_queue); |
Chris Wilson | f787a5f | 2010-09-24 16:02:42 +0100 | [diff] [blame] | 1343 | if (HAS_BSD(dev)) |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1344 | wake_up_all(&dev_priv->ring[VCS].irq_queue); |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1345 | if (HAS_BLT(dev)) |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1346 | wake_up_all(&dev_priv->ring[BCS].irq_queue); |
Ben Gamari | 11ed50e | 2009-09-14 17:48:45 -0400 | [diff] [blame] | 1347 | } |
| 1348 | |
Eric Anholt | 9c9fe1f | 2009-08-03 16:09:16 -0700 | [diff] [blame] | 1349 | queue_work(dev_priv->wq, &dev_priv->error_work); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1350 | } |
| 1351 | |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 1352 | static void i915_pageflip_stall_check(struct drm_device *dev, int pipe) |
| 1353 | { |
| 1354 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 1355 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 1356 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1357 | struct drm_i915_gem_object *obj; |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 1358 | struct intel_unpin_work *work; |
| 1359 | unsigned long flags; |
| 1360 | bool stall_detected; |
| 1361 | |
| 1362 | /* Ignore early vblank irqs */ |
| 1363 | if (intel_crtc == NULL) |
| 1364 | return; |
| 1365 | |
| 1366 | spin_lock_irqsave(&dev->event_lock, flags); |
| 1367 | work = intel_crtc->unpin_work; |
| 1368 | |
| 1369 | if (work == NULL || work->pending || !work->enable_stall_check) { |
| 1370 | /* Either the pending flip IRQ arrived, or we're too early. Don't check */ |
| 1371 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 1372 | return; |
| 1373 | } |
| 1374 | |
| 1375 | /* Potential stall - if we see that the flip has happened, assume a missed interrupt */ |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1376 | obj = work->pending_flip_obj; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1377 | if (INTEL_INFO(dev)->gen >= 4) { |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1378 | int dspsurf = DSPSURF(intel_crtc->plane); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1379 | stall_detected = I915_READ(dspsurf) == obj->gtt_offset; |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 1380 | } else { |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1381 | int dspaddr = DSPADDR(intel_crtc->plane); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1382 | stall_detected = I915_READ(dspaddr) == (obj->gtt_offset + |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 1383 | crtc->y * crtc->fb->pitches[0] + |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 1384 | crtc->x * crtc->fb->bits_per_pixel/8); |
| 1385 | } |
| 1386 | |
| 1387 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 1388 | |
| 1389 | if (stall_detected) { |
| 1390 | DRM_DEBUG_DRIVER("Pageflip stall detected\n"); |
| 1391 | intel_prepare_page_flip(dev, intel_crtc->plane); |
| 1392 | } |
| 1393 | } |
| 1394 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 1395 | static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | { |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1397 | struct drm_device *dev = (struct drm_device *) arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1399 | struct drm_i915_master_private *master_priv; |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 1400 | u32 iir, new_iir; |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1401 | u32 pipe_stats[I915_MAX_PIPES]; |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 1402 | u32 vblank_status; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1403 | int vblank = 0; |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1404 | unsigned long irqflags; |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 1405 | int irq_received; |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1406 | int ret = IRQ_NONE, pipe; |
| 1407 | bool blc_event = false; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 1408 | |
Eric Anholt | 630681d | 2008-10-06 15:14:12 -0700 | [diff] [blame] | 1409 | atomic_inc(&dev_priv->irq_received); |
| 1410 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1411 | iir = I915_READ(IIR); |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 1412 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1413 | if (INTEL_INFO(dev)->gen >= 4) |
Jesse Barnes | d874bcf | 2010-06-30 13:16:00 -0700 | [diff] [blame] | 1414 | vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS; |
Jesse Barnes | e25e660 | 2010-06-30 13:15:19 -0700 | [diff] [blame] | 1415 | else |
Jesse Barnes | d874bcf | 2010-06-30 13:16:00 -0700 | [diff] [blame] | 1416 | vblank_status = PIPE_VBLANK_INTERRUPT_STATUS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 1418 | for (;;) { |
| 1419 | irq_received = iir != 0; |
| 1420 | |
| 1421 | /* Can't rely on pipestat interrupt bit in iir as it might |
| 1422 | * have been cleared after the pipestat interrupt was received. |
| 1423 | * It doesn't set the bit in iir again, but it still produces |
| 1424 | * interrupts (for non-MSI). |
| 1425 | */ |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1426 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1427 | if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) |
Ben Gamari | ba1234d | 2009-09-14 17:48:47 -0400 | [diff] [blame] | 1428 | i915_handle_error(dev, false); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1429 | |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1430 | for_each_pipe(pipe) { |
| 1431 | int reg = PIPESTAT(pipe); |
| 1432 | pipe_stats[pipe] = I915_READ(reg); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1433 | |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1434 | /* |
| 1435 | * Clear the PIPE*STAT regs before the IIR |
| 1436 | */ |
| 1437 | if (pipe_stats[pipe] & 0x8000ffff) { |
| 1438 | if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) |
| 1439 | DRM_DEBUG_DRIVER("pipe %c underrun\n", |
| 1440 | pipe_name(pipe)); |
| 1441 | I915_WRITE(reg, pipe_stats[pipe]); |
| 1442 | irq_received = 1; |
| 1443 | } |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 1444 | } |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1445 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 1446 | |
| 1447 | if (!irq_received) |
| 1448 | break; |
| 1449 | |
| 1450 | ret = IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 1452 | /* Consume port. Then clear IIR or we'll miss events */ |
| 1453 | if ((I915_HAS_HOTPLUG(dev)) && |
| 1454 | (iir & I915_DISPLAY_PORT_INTERRUPT)) { |
| 1455 | u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); |
| 1456 | |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 1457 | DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n", |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 1458 | hotplug_status); |
| 1459 | if (hotplug_status & dev_priv->hotplug_supported_mask) |
Eric Anholt | 9c9fe1f | 2009-08-03 16:09:16 -0700 | [diff] [blame] | 1460 | queue_work(dev_priv->wq, |
| 1461 | &dev_priv->hotplug_work); |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 1462 | |
| 1463 | I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); |
| 1464 | I915_READ(PORT_HOTPLUG_STAT); |
| 1465 | } |
| 1466 | |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 1467 | I915_WRITE(IIR, iir); |
| 1468 | new_iir = I915_READ(IIR); /* Flush posted writes */ |
Matthew Garrett | 8ee1c3d | 2008-08-05 19:37:25 +0100 | [diff] [blame] | 1469 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1470 | if (dev->primary->master) { |
| 1471 | master_priv = dev->primary->master->driver_priv; |
| 1472 | if (master_priv->sarea_priv) |
| 1473 | master_priv->sarea_priv->last_dispatch = |
| 1474 | READ_BREADCRUMB(dev_priv); |
| 1475 | } |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1476 | |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1477 | if (iir & I915_USER_INTERRUPT) |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1478 | notify_ring(dev, &dev_priv->ring[RCS]); |
| 1479 | if (iir & I915_BSD_USER_INTERRUPT) |
| 1480 | notify_ring(dev, &dev_priv->ring[VCS]); |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 1481 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 1482 | if (iir & I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT) { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1483 | intel_prepare_page_flip(dev, 0); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 1484 | if (dev_priv->flip_pending_is_done) |
| 1485 | intel_finish_page_flip_plane(dev, 0); |
| 1486 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1487 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 1488 | if (iir & I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT) { |
Jesse Barnes | 70565d0 | 2010-07-01 04:45:43 -0700 | [diff] [blame] | 1489 | intel_prepare_page_flip(dev, 1); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 1490 | if (dev_priv->flip_pending_is_done) |
| 1491 | intel_finish_page_flip_plane(dev, 1); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 1492 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1493 | |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1494 | for_each_pipe(pipe) { |
| 1495 | if (pipe_stats[pipe] & vblank_status && |
| 1496 | drm_handle_vblank(dev, pipe)) { |
| 1497 | vblank++; |
| 1498 | if (!dev_priv->flip_pending_is_done) { |
| 1499 | i915_pageflip_stall_check(dev, pipe); |
| 1500 | intel_finish_page_flip(dev, pipe); |
| 1501 | } |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 1502 | } |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1503 | |
| 1504 | if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) |
| 1505 | blc_event = true; |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 1506 | } |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1507 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1508 | |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1509 | if (blc_event || (iir & I915_ASLE_INTERRUPT)) |
Chris Wilson | 3b61796 | 2010-08-24 09:02:58 +0100 | [diff] [blame] | 1510 | intel_opregion_asle_intr(dev); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1511 | |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 1512 | /* With MSI, interrupts are only generated when iir |
| 1513 | * transitions from zero to nonzero. If another bit got |
| 1514 | * set while we were handling the existing iir bits, then |
| 1515 | * we would never get another interrupt. |
| 1516 | * |
| 1517 | * This is fine on non-MSI as well, as if we hit this path |
| 1518 | * we avoid exiting the interrupt handler only to generate |
| 1519 | * another one. |
| 1520 | * |
| 1521 | * Note that for MSI this could cause a stray interrupt report |
| 1522 | * if an interrupt landed in the time between writing IIR and |
| 1523 | * the posting read. This should be rare enough to never |
| 1524 | * trigger the 99% of 100,000 interrupts test for disabling |
| 1525 | * stray interrupts. |
| 1526 | */ |
| 1527 | iir = new_iir; |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 1528 | } |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1529 | |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 1530 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | } |
| 1532 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 1533 | static int i915_emit_irq(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | { |
| 1535 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1536 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | |
| 1538 | i915_kernel_lost_context(dev); |
| 1539 | |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 1540 | DRM_DEBUG_DRIVER("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 1542 | dev_priv->counter++; |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 1543 | if (dev_priv->counter > 0x7FFFFFFFUL) |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 1544 | dev_priv->counter = 1; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1545 | if (master_priv->sarea_priv) |
| 1546 | master_priv->sarea_priv->last_enqueue = dev_priv->counter; |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 1547 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 1548 | if (BEGIN_LP_RING(4) == 0) { |
| 1549 | OUT_RING(MI_STORE_DWORD_INDEX); |
| 1550 | OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT); |
| 1551 | OUT_RING(dev_priv->counter); |
| 1552 | OUT_RING(MI_USER_INTERRUPT); |
| 1553 | ADVANCE_LP_RING(); |
| 1554 | } |
Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 1555 | |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 1556 | return dev_priv->counter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | } |
| 1558 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1559 | static int i915_wait_irq(struct drm_device * dev, int irq_nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | { |
| 1561 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1562 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | int ret = 0; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1564 | struct intel_ring_buffer *ring = LP_RING(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 1566 | DRM_DEBUG_DRIVER("irq_nr=%d breadcrumb=%d\n", irq_nr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | READ_BREADCRUMB(dev_priv)); |
| 1568 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1569 | if (READ_BREADCRUMB(dev_priv) >= irq_nr) { |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1570 | if (master_priv->sarea_priv) |
| 1571 | master_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | return 0; |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1573 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1575 | if (master_priv->sarea_priv) |
| 1576 | master_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | |
Chris Wilson | b13c2b9 | 2010-12-13 16:54:50 +0000 | [diff] [blame] | 1578 | if (ring->irq_get(ring)) { |
| 1579 | DRM_WAIT_ON(ret, ring->irq_queue, 3 * DRM_HZ, |
| 1580 | READ_BREADCRUMB(dev_priv) >= irq_nr); |
| 1581 | ring->irq_put(ring); |
Chris Wilson | 5a9a8d1 | 2011-01-23 13:03:24 +0000 | [diff] [blame] | 1582 | } else if (wait_for(READ_BREADCRUMB(dev_priv) >= irq_nr, 3000)) |
| 1583 | ret = -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1585 | if (ret == -EBUSY) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 1586 | DRM_ERROR("EBUSY -- rec: %d emitted: %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | READ_BREADCRUMB(dev_priv), (int)dev_priv->counter); |
| 1588 | } |
| 1589 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 1590 | return ret; |
| 1591 | } |
| 1592 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | /* Needs the lock as it touches the ring. |
| 1594 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1595 | int i915_irq_emit(struct drm_device *dev, void *data, |
| 1596 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1599 | drm_i915_irq_emit_t *emit = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | int result; |
| 1601 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1602 | if (!dev_priv || !LP_RING(dev_priv)->virtual_start) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 1603 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1604 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | } |
Eric Anholt | 299eb93 | 2009-02-24 22:14:12 -0800 | [diff] [blame] | 1606 | |
| 1607 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
| 1608 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 1609 | mutex_lock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | result = i915_emit_irq(dev); |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 1611 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1613 | if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | DRM_ERROR("copy_to_user\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1615 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | return 0; |
| 1619 | } |
| 1620 | |
| 1621 | /* Doesn't need the hardware lock. |
| 1622 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1623 | int i915_irq_wait(struct drm_device *dev, void *data, |
| 1624 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1627 | drm_i915_irq_wait_t *irqwait = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | |
| 1629 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 1630 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1631 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | } |
| 1633 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1634 | return i915_wait_irq(dev, irqwait->irq_seq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | } |
| 1636 | |
Keith Packard | 42f52ef | 2008-10-18 19:39:29 -0700 | [diff] [blame] | 1637 | /* Called from drm generic code, passed 'crtc' which |
| 1638 | * we use as a pipe index |
| 1639 | */ |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 1640 | static int i915_enable_vblank(struct drm_device *dev, int pipe) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1641 | { |
| 1642 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 1643 | unsigned long irqflags; |
Jesse Barnes | 71e0ffa | 2009-01-08 10:42:15 -0800 | [diff] [blame] | 1644 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1645 | if (!i915_pipe_enabled(dev, pipe)) |
Jesse Barnes | 71e0ffa | 2009-01-08 10:42:15 -0800 | [diff] [blame] | 1646 | return -EINVAL; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1647 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1648 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Jesse Barnes | f796cf8 | 2011-04-07 13:58:17 -0700 | [diff] [blame] | 1649 | if (INTEL_INFO(dev)->gen >= 4) |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1650 | i915_enable_pipestat(dev_priv, pipe, |
| 1651 | PIPE_START_VBLANK_INTERRUPT_ENABLE); |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 1652 | else |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1653 | i915_enable_pipestat(dev_priv, pipe, |
| 1654 | PIPE_VBLANK_INTERRUPT_ENABLE); |
Chris Wilson | 8692d00e | 2011-02-05 10:08:21 +0000 | [diff] [blame] | 1655 | |
| 1656 | /* maintain vblank delivery even in deep C-states */ |
| 1657 | if (dev_priv->info->gen == 3) |
| 1658 | I915_WRITE(INSTPM, INSTPM_AGPBUSY_DIS << 16); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1659 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
Chris Wilson | 8692d00e | 2011-02-05 10:08:21 +0000 | [diff] [blame] | 1660 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1661 | return 0; |
| 1662 | } |
| 1663 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 1664 | static int ironlake_enable_vblank(struct drm_device *dev, int pipe) |
Jesse Barnes | f796cf8 | 2011-04-07 13:58:17 -0700 | [diff] [blame] | 1665 | { |
| 1666 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 1667 | unsigned long irqflags; |
| 1668 | |
| 1669 | if (!i915_pipe_enabled(dev, pipe)) |
| 1670 | return -EINVAL; |
| 1671 | |
| 1672 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
| 1673 | ironlake_enable_display_irq(dev_priv, (pipe == 0) ? |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1674 | DE_PIPEA_VBLANK : DE_PIPEB_VBLANK); |
Jesse Barnes | f796cf8 | 2011-04-07 13:58:17 -0700 | [diff] [blame] | 1675 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 1676 | |
| 1677 | return 0; |
| 1678 | } |
| 1679 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 1680 | static int ivybridge_enable_vblank(struct drm_device *dev, int pipe) |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 1681 | { |
| 1682 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 1683 | unsigned long irqflags; |
| 1684 | |
| 1685 | if (!i915_pipe_enabled(dev, pipe)) |
| 1686 | return -EINVAL; |
| 1687 | |
| 1688 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
| 1689 | ironlake_enable_display_irq(dev_priv, (pipe == 0) ? |
| 1690 | DE_PIPEA_VBLANK_IVB : DE_PIPEB_VBLANK_IVB); |
| 1691 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 1692 | |
| 1693 | return 0; |
| 1694 | } |
| 1695 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 1696 | static int valleyview_enable_vblank(struct drm_device *dev, int pipe) |
| 1697 | { |
| 1698 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 1699 | unsigned long irqflags; |
| 1700 | u32 dpfl, imr; |
| 1701 | |
| 1702 | if (!i915_pipe_enabled(dev, pipe)) |
| 1703 | return -EINVAL; |
| 1704 | |
| 1705 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
| 1706 | dpfl = I915_READ(VLV_DPFLIPSTAT); |
| 1707 | imr = I915_READ(VLV_IMR); |
| 1708 | if (pipe == 0) { |
| 1709 | dpfl |= PIPEA_VBLANK_INT_EN; |
| 1710 | imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT; |
| 1711 | } else { |
| 1712 | dpfl |= PIPEA_VBLANK_INT_EN; |
| 1713 | imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; |
| 1714 | } |
| 1715 | I915_WRITE(VLV_DPFLIPSTAT, dpfl); |
| 1716 | I915_WRITE(VLV_IMR, imr); |
| 1717 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 1718 | |
| 1719 | return 0; |
| 1720 | } |
| 1721 | |
Keith Packard | 42f52ef | 2008-10-18 19:39:29 -0700 | [diff] [blame] | 1722 | /* Called from drm generic code, passed 'crtc' which |
| 1723 | * we use as a pipe index |
| 1724 | */ |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 1725 | static void i915_disable_vblank(struct drm_device *dev, int pipe) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1726 | { |
| 1727 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 1728 | unsigned long irqflags; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1729 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1730 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Chris Wilson | 8692d00e | 2011-02-05 10:08:21 +0000 | [diff] [blame] | 1731 | if (dev_priv->info->gen == 3) |
| 1732 | I915_WRITE(INSTPM, |
| 1733 | INSTPM_AGPBUSY_DIS << 16 | INSTPM_AGPBUSY_DIS); |
| 1734 | |
Jesse Barnes | f796cf8 | 2011-04-07 13:58:17 -0700 | [diff] [blame] | 1735 | i915_disable_pipestat(dev_priv, pipe, |
| 1736 | PIPE_VBLANK_INTERRUPT_ENABLE | |
| 1737 | PIPE_START_VBLANK_INTERRUPT_ENABLE); |
| 1738 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 1739 | } |
| 1740 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 1741 | static void ironlake_disable_vblank(struct drm_device *dev, int pipe) |
Jesse Barnes | f796cf8 | 2011-04-07 13:58:17 -0700 | [diff] [blame] | 1742 | { |
| 1743 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 1744 | unsigned long irqflags; |
| 1745 | |
| 1746 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
| 1747 | ironlake_disable_display_irq(dev_priv, (pipe == 0) ? |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1748 | DE_PIPEA_VBLANK : DE_PIPEB_VBLANK); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1749 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1750 | } |
| 1751 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 1752 | static void ivybridge_disable_vblank(struct drm_device *dev, int pipe) |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 1753 | { |
| 1754 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 1755 | unsigned long irqflags; |
| 1756 | |
| 1757 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
| 1758 | ironlake_disable_display_irq(dev_priv, (pipe == 0) ? |
| 1759 | DE_PIPEA_VBLANK_IVB : DE_PIPEB_VBLANK_IVB); |
| 1760 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 1761 | } |
| 1762 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 1763 | static void valleyview_disable_vblank(struct drm_device *dev, int pipe) |
| 1764 | { |
| 1765 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 1766 | unsigned long irqflags; |
| 1767 | u32 dpfl, imr; |
| 1768 | |
| 1769 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
| 1770 | dpfl = I915_READ(VLV_DPFLIPSTAT); |
| 1771 | imr = I915_READ(VLV_IMR); |
| 1772 | if (pipe == 0) { |
| 1773 | dpfl &= ~PIPEA_VBLANK_INT_EN; |
| 1774 | imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT; |
| 1775 | } else { |
| 1776 | dpfl &= ~PIPEB_VBLANK_INT_EN; |
| 1777 | imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; |
| 1778 | } |
| 1779 | I915_WRITE(VLV_IMR, imr); |
| 1780 | I915_WRITE(VLV_DPFLIPSTAT, dpfl); |
| 1781 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 1782 | } |
| 1783 | |
| 1784 | |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1785 | /* Set the vblank monitor pipe |
| 1786 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1787 | int i915_vblank_pipe_set(struct drm_device *dev, void *data, |
| 1788 | struct drm_file *file_priv) |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1789 | { |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1790 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1791 | |
| 1792 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 1793 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1794 | return -EINVAL; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1795 | } |
| 1796 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 5b51694 | 2006-10-25 00:08:23 +1000 | [diff] [blame] | 1797 | return 0; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1798 | } |
| 1799 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1800 | int i915_vblank_pipe_get(struct drm_device *dev, void *data, |
| 1801 | struct drm_file *file_priv) |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1802 | { |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1803 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1804 | drm_i915_vblank_pipe_t *pipe = data; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1805 | |
| 1806 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 1807 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1808 | return -EINVAL; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1809 | } |
| 1810 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1811 | pipe->pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1812 | |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1813 | return 0; |
| 1814 | } |
| 1815 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 1816 | /** |
| 1817 | * Schedule buffer swap at given vertical blank. |
| 1818 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1819 | int i915_vblank_swap(struct drm_device *dev, void *data, |
| 1820 | struct drm_file *file_priv) |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 1821 | { |
Eric Anholt | bd95e0a | 2008-11-04 12:01:24 -0800 | [diff] [blame] | 1822 | /* The delayed swap mechanism was fundamentally racy, and has been |
| 1823 | * removed. The model was that the client requested a delayed flip/swap |
| 1824 | * from the kernel, then waited for vblank before continuing to perform |
| 1825 | * rendering. The problem was that the kernel might wake the client |
| 1826 | * up before it dispatched the vblank swap (since the lock has to be |
| 1827 | * held while touching the ringbuffer), in which case the client would |
| 1828 | * clear and start the next frame before the swap occurred, and |
| 1829 | * flicker would occur in addition to likely missing the vblank. |
| 1830 | * |
| 1831 | * In the absence of this ioctl, userland falls back to a correct path |
| 1832 | * of waiting for a vblank, then dispatching the swap on its own. |
| 1833 | * Context switching to userland and back is plenty fast enough for |
| 1834 | * meeting the requirements of vblank swapping. |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1835 | */ |
Eric Anholt | bd95e0a | 2008-11-04 12:01:24 -0800 | [diff] [blame] | 1836 | return -EINVAL; |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 1837 | } |
| 1838 | |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 1839 | static u32 |
| 1840 | ring_last_seqno(struct intel_ring_buffer *ring) |
Zou Nan hai | 852835f | 2010-05-21 09:08:56 +0800 | [diff] [blame] | 1841 | { |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 1842 | return list_entry(ring->request_list.prev, |
| 1843 | struct drm_i915_gem_request, list)->seqno; |
| 1844 | } |
| 1845 | |
| 1846 | static bool i915_hangcheck_ring_idle(struct intel_ring_buffer *ring, bool *err) |
| 1847 | { |
| 1848 | if (list_empty(&ring->request_list) || |
| 1849 | i915_seqno_passed(ring->get_seqno(ring), ring_last_seqno(ring))) { |
| 1850 | /* Issue a wake-up to catch stuck h/w. */ |
Chris Wilson | b222349 | 2010-10-27 15:27:33 +0100 | [diff] [blame] | 1851 | if (ring->waiting_seqno && waitqueue_active(&ring->irq_queue)) { |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 1852 | DRM_ERROR("Hangcheck timer elapsed... %s idle [waiting on %d, at %d], missed IRQ?\n", |
| 1853 | ring->name, |
Chris Wilson | b222349 | 2010-10-27 15:27:33 +0100 | [diff] [blame] | 1854 | ring->waiting_seqno, |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 1855 | ring->get_seqno(ring)); |
| 1856 | wake_up_all(&ring->irq_queue); |
| 1857 | *err = true; |
| 1858 | } |
| 1859 | return true; |
| 1860 | } |
| 1861 | return false; |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 1862 | } |
| 1863 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1864 | static bool kick_ring(struct intel_ring_buffer *ring) |
| 1865 | { |
| 1866 | struct drm_device *dev = ring->dev; |
| 1867 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1868 | u32 tmp = I915_READ_CTL(ring); |
| 1869 | if (tmp & RING_WAIT) { |
| 1870 | DRM_ERROR("Kicking stuck wait on %s\n", |
| 1871 | ring->name); |
| 1872 | I915_WRITE_CTL(ring, tmp); |
| 1873 | return true; |
| 1874 | } |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1875 | return false; |
| 1876 | } |
| 1877 | |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 1878 | /** |
| 1879 | * This is called when the chip hasn't reported back with completed |
| 1880 | * batchbuffers in a long time. The first time this is called we simply record |
| 1881 | * ACTHD. If ACTHD hasn't changed by the time the hangcheck timer elapses |
| 1882 | * again, we assume the chip is wedged and try to fix it. |
| 1883 | */ |
| 1884 | void i915_hangcheck_elapsed(unsigned long data) |
| 1885 | { |
| 1886 | struct drm_device *dev = (struct drm_device *)data; |
| 1887 | drm_i915_private_t *dev_priv = dev->dev_private; |
Daniel Vetter | 097354e | 2011-11-27 18:58:17 +0100 | [diff] [blame] | 1888 | uint32_t acthd, instdone, instdone1, acthd_bsd, acthd_blt; |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 1889 | bool err = false; |
| 1890 | |
Ben Widawsky | 3e0dc6b | 2011-06-29 10:26:42 -0700 | [diff] [blame] | 1891 | if (!i915_enable_hangcheck) |
| 1892 | return; |
| 1893 | |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 1894 | /* If all work is done then ACTHD clearly hasn't advanced. */ |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1895 | if (i915_hangcheck_ring_idle(&dev_priv->ring[RCS], &err) && |
| 1896 | i915_hangcheck_ring_idle(&dev_priv->ring[VCS], &err) && |
| 1897 | i915_hangcheck_ring_idle(&dev_priv->ring[BCS], &err)) { |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 1898 | dev_priv->hangcheck_count = 0; |
| 1899 | if (err) |
| 1900 | goto repeat; |
| 1901 | return; |
| 1902 | } |
Eric Anholt | b9201c1 | 2010-01-08 14:25:16 -0800 | [diff] [blame] | 1903 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1904 | if (INTEL_INFO(dev)->gen < 4) { |
Chris Wilson | cbb465e | 2010-06-06 12:16:24 +0100 | [diff] [blame] | 1905 | instdone = I915_READ(INSTDONE); |
| 1906 | instdone1 = 0; |
| 1907 | } else { |
Chris Wilson | cbb465e | 2010-06-06 12:16:24 +0100 | [diff] [blame] | 1908 | instdone = I915_READ(INSTDONE_I965); |
| 1909 | instdone1 = I915_READ(INSTDONE1); |
| 1910 | } |
Daniel Vetter | 097354e | 2011-11-27 18:58:17 +0100 | [diff] [blame] | 1911 | acthd = intel_ring_get_active_head(&dev_priv->ring[RCS]); |
| 1912 | acthd_bsd = HAS_BSD(dev) ? |
| 1913 | intel_ring_get_active_head(&dev_priv->ring[VCS]) : 0; |
| 1914 | acthd_blt = HAS_BLT(dev) ? |
| 1915 | intel_ring_get_active_head(&dev_priv->ring[BCS]) : 0; |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 1916 | |
Chris Wilson | cbb465e | 2010-06-06 12:16:24 +0100 | [diff] [blame] | 1917 | if (dev_priv->last_acthd == acthd && |
Daniel Vetter | 097354e | 2011-11-27 18:58:17 +0100 | [diff] [blame] | 1918 | dev_priv->last_acthd_bsd == acthd_bsd && |
| 1919 | dev_priv->last_acthd_blt == acthd_blt && |
Chris Wilson | cbb465e | 2010-06-06 12:16:24 +0100 | [diff] [blame] | 1920 | dev_priv->last_instdone == instdone && |
| 1921 | dev_priv->last_instdone1 == instdone1) { |
| 1922 | if (dev_priv->hangcheck_count++ > 1) { |
| 1923 | DRM_ERROR("Hangcheck timer elapsed... GPU hung\n"); |
Daniel Vetter | 653d7be | 2011-12-14 13:57:21 +0100 | [diff] [blame] | 1924 | i915_handle_error(dev, true); |
Chris Wilson | 8c80b59 | 2010-08-08 20:38:12 +0100 | [diff] [blame] | 1925 | |
| 1926 | if (!IS_GEN2(dev)) { |
| 1927 | /* Is the chip hanging on a WAIT_FOR_EVENT? |
| 1928 | * If so we can simply poke the RB_WAIT bit |
| 1929 | * and break the hang. This should work on |
| 1930 | * all but the second generation chipsets. |
| 1931 | */ |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1932 | if (kick_ring(&dev_priv->ring[RCS])) |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 1933 | goto repeat; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1934 | |
| 1935 | if (HAS_BSD(dev) && |
| 1936 | kick_ring(&dev_priv->ring[VCS])) |
| 1937 | goto repeat; |
| 1938 | |
| 1939 | if (HAS_BLT(dev) && |
| 1940 | kick_ring(&dev_priv->ring[BCS])) |
| 1941 | goto repeat; |
Chris Wilson | 8c80b59 | 2010-08-08 20:38:12 +0100 | [diff] [blame] | 1942 | } |
| 1943 | |
Chris Wilson | cbb465e | 2010-06-06 12:16:24 +0100 | [diff] [blame] | 1944 | return; |
| 1945 | } |
| 1946 | } else { |
| 1947 | dev_priv->hangcheck_count = 0; |
| 1948 | |
| 1949 | dev_priv->last_acthd = acthd; |
Daniel Vetter | 097354e | 2011-11-27 18:58:17 +0100 | [diff] [blame] | 1950 | dev_priv->last_acthd_bsd = acthd_bsd; |
| 1951 | dev_priv->last_acthd_blt = acthd_blt; |
Chris Wilson | cbb465e | 2010-06-06 12:16:24 +0100 | [diff] [blame] | 1952 | dev_priv->last_instdone = instdone; |
| 1953 | dev_priv->last_instdone1 = instdone1; |
| 1954 | } |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 1955 | |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 1956 | repeat: |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 1957 | /* Reset timer case chip hangs without another request being added */ |
Chris Wilson | b3b079d | 2010-09-13 23:44:34 +0100 | [diff] [blame] | 1958 | mod_timer(&dev_priv->hangcheck_timer, |
| 1959 | jiffies + msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD)); |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 1960 | } |
| 1961 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | /* drm_dma.h hooks |
| 1963 | */ |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 1964 | static void ironlake_irq_preinstall(struct drm_device *dev) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1965 | { |
| 1966 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 1967 | |
Jesse Barnes | 4697995 | 2011-04-07 13:53:55 -0700 | [diff] [blame] | 1968 | atomic_set(&dev_priv->irq_received, 0); |
| 1969 | |
| 1970 | INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func); |
| 1971 | INIT_WORK(&dev_priv->error_work, i915_error_work_func); |
Jesse Barnes | 9e3c256 | 2011-05-18 13:51:43 -0700 | [diff] [blame] | 1972 | if (IS_GEN6(dev) || IS_IVYBRIDGE(dev)) |
| 1973 | INIT_WORK(&dev_priv->rps_work, gen6_pm_rps_work); |
Jesse Barnes | 4697995 | 2011-04-07 13:53:55 -0700 | [diff] [blame] | 1974 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1975 | I915_WRITE(HWSTAM, 0xeffe); |
Daniel Vetter | bdfcdb6 | 2012-01-05 01:05:26 +0100 | [diff] [blame] | 1976 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1977 | /* XXX hotplug from PCH */ |
| 1978 | |
| 1979 | I915_WRITE(DEIMR, 0xffffffff); |
| 1980 | I915_WRITE(DEIER, 0x0); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 1981 | POSTING_READ(DEIER); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1982 | |
| 1983 | /* and GT */ |
| 1984 | I915_WRITE(GTIMR, 0xffffffff); |
| 1985 | I915_WRITE(GTIER, 0x0); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 1986 | POSTING_READ(GTIER); |
Zhenyu Wang | c650156 | 2009-11-03 18:57:21 +0000 | [diff] [blame] | 1987 | |
| 1988 | /* south display irq */ |
| 1989 | I915_WRITE(SDEIMR, 0xffffffff); |
| 1990 | I915_WRITE(SDEIER, 0x0); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 1991 | POSTING_READ(SDEIER); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1992 | } |
| 1993 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 1994 | static void valleyview_irq_preinstall(struct drm_device *dev) |
| 1995 | { |
| 1996 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 1997 | int pipe; |
| 1998 | |
| 1999 | atomic_set(&dev_priv->irq_received, 0); |
| 2000 | |
| 2001 | INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func); |
| 2002 | INIT_WORK(&dev_priv->error_work, i915_error_work_func); |
| 2003 | |
| 2004 | /* VLV magic */ |
| 2005 | I915_WRITE(VLV_IMR, 0); |
| 2006 | I915_WRITE(RING_IMR(RENDER_RING_BASE), 0); |
| 2007 | I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0); |
| 2008 | I915_WRITE(RING_IMR(BLT_RING_BASE), 0); |
| 2009 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2010 | /* and GT */ |
| 2011 | I915_WRITE(GTIIR, I915_READ(GTIIR)); |
| 2012 | I915_WRITE(GTIIR, I915_READ(GTIIR)); |
| 2013 | I915_WRITE(GTIMR, 0xffffffff); |
| 2014 | I915_WRITE(GTIER, 0x0); |
| 2015 | POSTING_READ(GTIER); |
| 2016 | |
| 2017 | I915_WRITE(DPINVGTT, 0xff); |
| 2018 | |
| 2019 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
| 2020 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); |
| 2021 | for_each_pipe(pipe) |
| 2022 | I915_WRITE(PIPESTAT(pipe), 0xffff); |
| 2023 | I915_WRITE(VLV_IIR, 0xffffffff); |
| 2024 | I915_WRITE(VLV_IMR, 0xffffffff); |
| 2025 | I915_WRITE(VLV_IER, 0x0); |
| 2026 | POSTING_READ(VLV_IER); |
| 2027 | } |
| 2028 | |
Keith Packard | 7fe0b97 | 2011-09-19 13:31:02 -0700 | [diff] [blame] | 2029 | /* |
| 2030 | * Enable digital hotplug on the PCH, and configure the DP short pulse |
| 2031 | * duration to 2ms (which is the minimum in the Display Port spec) |
| 2032 | * |
| 2033 | * This register is the same on all known PCH chips. |
| 2034 | */ |
| 2035 | |
| 2036 | static void ironlake_enable_pch_hotplug(struct drm_device *dev) |
| 2037 | { |
| 2038 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 2039 | u32 hotplug; |
| 2040 | |
| 2041 | hotplug = I915_READ(PCH_PORT_HOTPLUG); |
| 2042 | hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK); |
| 2043 | hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms; |
| 2044 | hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms; |
| 2045 | hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms; |
| 2046 | I915_WRITE(PCH_PORT_HOTPLUG, hotplug); |
| 2047 | } |
| 2048 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 2049 | static int ironlake_irq_postinstall(struct drm_device *dev) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2050 | { |
| 2051 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 2052 | /* enable kind of interrupts always enabled */ |
Jesse Barnes | 013d5aa | 2010-01-29 11:18:31 -0800 | [diff] [blame] | 2053 | u32 display_mask = DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | |
| 2054 | DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2055 | u32 render_irqs; |
Yuanhan Liu | 2d7b836 | 2010-10-08 10:21:06 +0100 | [diff] [blame] | 2056 | u32 hotplug_mask; |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2057 | |
Jesse Barnes | 4697995 | 2011-04-07 13:53:55 -0700 | [diff] [blame] | 2058 | DRM_INIT_WAITQUEUE(&dev_priv->ring[RCS].irq_queue); |
| 2059 | if (HAS_BSD(dev)) |
| 2060 | DRM_INIT_WAITQUEUE(&dev_priv->ring[VCS].irq_queue); |
| 2061 | if (HAS_BLT(dev)) |
| 2062 | DRM_INIT_WAITQUEUE(&dev_priv->ring[BCS].irq_queue); |
| 2063 | |
| 2064 | dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2065 | dev_priv->irq_mask = ~display_mask; |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2066 | |
| 2067 | /* should always can generate irq */ |
| 2068 | I915_WRITE(DEIIR, I915_READ(DEIIR)); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2069 | I915_WRITE(DEIMR, dev_priv->irq_mask); |
| 2070 | I915_WRITE(DEIER, display_mask | DE_PIPEA_VBLANK | DE_PIPEB_VBLANK); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 2071 | POSTING_READ(DEIER); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2072 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2073 | dev_priv->gt_irq_mask = ~0; |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2074 | |
| 2075 | I915_WRITE(GTIIR, I915_READ(GTIIR)); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2076 | I915_WRITE(GTIMR, dev_priv->gt_irq_mask); |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 2077 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2078 | if (IS_GEN6(dev)) |
| 2079 | render_irqs = |
| 2080 | GT_USER_INTERRUPT | |
Ben Widawsky | e2a1e2f | 2012-03-29 19:11:26 -0700 | [diff] [blame] | 2081 | GEN6_BSD_USER_INTERRUPT | |
| 2082 | GEN6_BLITTER_USER_INTERRUPT; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2083 | else |
| 2084 | render_irqs = |
Chris Wilson | 88f23b8 | 2010-12-05 15:08:31 +0000 | [diff] [blame] | 2085 | GT_USER_INTERRUPT | |
Chris Wilson | c6df541 | 2010-12-15 09:56:50 +0000 | [diff] [blame] | 2086 | GT_PIPE_NOTIFY | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2087 | GT_BSD_USER_INTERRUPT; |
| 2088 | I915_WRITE(GTIER, render_irqs); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 2089 | POSTING_READ(GTIER); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2090 | |
Yuanhan Liu | 2d7b836 | 2010-10-08 10:21:06 +0100 | [diff] [blame] | 2091 | if (HAS_PCH_CPT(dev)) { |
Chris Wilson | 9035a97 | 2011-02-16 09:36:05 +0000 | [diff] [blame] | 2092 | hotplug_mask = (SDE_CRT_HOTPLUG_CPT | |
| 2093 | SDE_PORTB_HOTPLUG_CPT | |
| 2094 | SDE_PORTC_HOTPLUG_CPT | |
| 2095 | SDE_PORTD_HOTPLUG_CPT); |
Yuanhan Liu | 2d7b836 | 2010-10-08 10:21:06 +0100 | [diff] [blame] | 2096 | } else { |
Chris Wilson | 9035a97 | 2011-02-16 09:36:05 +0000 | [diff] [blame] | 2097 | hotplug_mask = (SDE_CRT_HOTPLUG | |
| 2098 | SDE_PORTB_HOTPLUG | |
| 2099 | SDE_PORTC_HOTPLUG | |
| 2100 | SDE_PORTD_HOTPLUG | |
| 2101 | SDE_AUX_MASK); |
Yuanhan Liu | 2d7b836 | 2010-10-08 10:21:06 +0100 | [diff] [blame] | 2102 | } |
| 2103 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2104 | dev_priv->pch_irq_mask = ~hotplug_mask; |
Zhenyu Wang | c650156 | 2009-11-03 18:57:21 +0000 | [diff] [blame] | 2105 | |
| 2106 | I915_WRITE(SDEIIR, I915_READ(SDEIIR)); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2107 | I915_WRITE(SDEIMR, dev_priv->pch_irq_mask); |
| 2108 | I915_WRITE(SDEIER, hotplug_mask); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 2109 | POSTING_READ(SDEIER); |
Zhenyu Wang | c650156 | 2009-11-03 18:57:21 +0000 | [diff] [blame] | 2110 | |
Keith Packard | 7fe0b97 | 2011-09-19 13:31:02 -0700 | [diff] [blame] | 2111 | ironlake_enable_pch_hotplug(dev); |
| 2112 | |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 2113 | if (IS_IRONLAKE_M(dev)) { |
| 2114 | /* Clear & enable PCU event interrupts */ |
| 2115 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 2116 | I915_WRITE(DEIER, I915_READ(DEIER) | DE_PCU_EVENT); |
| 2117 | ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT); |
| 2118 | } |
| 2119 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2120 | return 0; |
| 2121 | } |
| 2122 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 2123 | static int ivybridge_irq_postinstall(struct drm_device *dev) |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 2124 | { |
| 2125 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 2126 | /* enable kind of interrupts always enabled */ |
| 2127 | u32 display_mask = DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | |
| 2128 | DE_PCH_EVENT_IVB | DE_PLANEA_FLIP_DONE_IVB | |
| 2129 | DE_PLANEB_FLIP_DONE_IVB; |
| 2130 | u32 render_irqs; |
| 2131 | u32 hotplug_mask; |
| 2132 | |
| 2133 | DRM_INIT_WAITQUEUE(&dev_priv->ring[RCS].irq_queue); |
| 2134 | if (HAS_BSD(dev)) |
| 2135 | DRM_INIT_WAITQUEUE(&dev_priv->ring[VCS].irq_queue); |
| 2136 | if (HAS_BLT(dev)) |
| 2137 | DRM_INIT_WAITQUEUE(&dev_priv->ring[BCS].irq_queue); |
| 2138 | |
| 2139 | dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; |
| 2140 | dev_priv->irq_mask = ~display_mask; |
| 2141 | |
| 2142 | /* should always can generate irq */ |
| 2143 | I915_WRITE(DEIIR, I915_READ(DEIIR)); |
| 2144 | I915_WRITE(DEIMR, dev_priv->irq_mask); |
| 2145 | I915_WRITE(DEIER, display_mask | DE_PIPEA_VBLANK_IVB | |
| 2146 | DE_PIPEB_VBLANK_IVB); |
| 2147 | POSTING_READ(DEIER); |
| 2148 | |
| 2149 | dev_priv->gt_irq_mask = ~0; |
| 2150 | |
| 2151 | I915_WRITE(GTIIR, I915_READ(GTIIR)); |
| 2152 | I915_WRITE(GTIMR, dev_priv->gt_irq_mask); |
| 2153 | |
Ben Widawsky | e2a1e2f | 2012-03-29 19:11:26 -0700 | [diff] [blame] | 2154 | render_irqs = GT_USER_INTERRUPT | GEN6_BSD_USER_INTERRUPT | |
| 2155 | GEN6_BLITTER_USER_INTERRUPT; |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 2156 | I915_WRITE(GTIER, render_irqs); |
| 2157 | POSTING_READ(GTIER); |
| 2158 | |
| 2159 | hotplug_mask = (SDE_CRT_HOTPLUG_CPT | |
| 2160 | SDE_PORTB_HOTPLUG_CPT | |
| 2161 | SDE_PORTC_HOTPLUG_CPT | |
| 2162 | SDE_PORTD_HOTPLUG_CPT); |
| 2163 | dev_priv->pch_irq_mask = ~hotplug_mask; |
| 2164 | |
| 2165 | I915_WRITE(SDEIIR, I915_READ(SDEIIR)); |
| 2166 | I915_WRITE(SDEIMR, dev_priv->pch_irq_mask); |
| 2167 | I915_WRITE(SDEIER, hotplug_mask); |
| 2168 | POSTING_READ(SDEIER); |
| 2169 | |
Keith Packard | 7fe0b97 | 2011-09-19 13:31:02 -0700 | [diff] [blame] | 2170 | ironlake_enable_pch_hotplug(dev); |
| 2171 | |
Jesse Barnes | b1f14ad | 2011-04-06 12:13:38 -0700 | [diff] [blame] | 2172 | return 0; |
| 2173 | } |
| 2174 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2175 | static int valleyview_irq_postinstall(struct drm_device *dev) |
| 2176 | { |
| 2177 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 2178 | u32 render_irqs; |
| 2179 | u32 enable_mask; |
| 2180 | u32 hotplug_en = I915_READ(PORT_HOTPLUG_EN); |
| 2181 | u16 msid; |
| 2182 | |
| 2183 | enable_mask = I915_DISPLAY_PORT_INTERRUPT; |
| 2184 | enable_mask |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT | |
| 2185 | I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; |
| 2186 | |
| 2187 | dev_priv->irq_mask = ~enable_mask; |
| 2188 | |
| 2189 | |
| 2190 | DRM_INIT_WAITQUEUE(&dev_priv->ring[RCS].irq_queue); |
| 2191 | DRM_INIT_WAITQUEUE(&dev_priv->ring[VCS].irq_queue); |
| 2192 | DRM_INIT_WAITQUEUE(&dev_priv->ring[BCS].irq_queue); |
| 2193 | |
| 2194 | dev_priv->pipestat[0] = 0; |
| 2195 | dev_priv->pipestat[1] = 0; |
| 2196 | |
| 2197 | dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; |
| 2198 | |
| 2199 | /* Hack for broken MSIs on VLV */ |
| 2200 | pci_write_config_dword(dev_priv->dev->pdev, 0x94, 0xfee00000); |
| 2201 | pci_read_config_word(dev->pdev, 0x98, &msid); |
| 2202 | msid &= 0xff; /* mask out delivery bits */ |
| 2203 | msid |= (1<<14); |
| 2204 | pci_write_config_word(dev_priv->dev->pdev, 0x98, msid); |
| 2205 | |
| 2206 | I915_WRITE(VLV_IMR, dev_priv->irq_mask); |
| 2207 | I915_WRITE(VLV_IER, enable_mask); |
| 2208 | I915_WRITE(VLV_IIR, 0xffffffff); |
| 2209 | I915_WRITE(PIPESTAT(0), 0xffff); |
| 2210 | I915_WRITE(PIPESTAT(1), 0xffff); |
| 2211 | POSTING_READ(VLV_IER); |
| 2212 | |
| 2213 | I915_WRITE(VLV_IIR, 0xffffffff); |
| 2214 | I915_WRITE(VLV_IIR, 0xffffffff); |
| 2215 | |
| 2216 | render_irqs = GT_GEN6_BLT_FLUSHDW_NOTIFY_INTERRUPT | |
| 2217 | GT_GEN6_BLT_CS_ERROR_INTERRUPT | |
Ben Widawsky | e2a1e2f | 2012-03-29 19:11:26 -0700 | [diff] [blame] | 2218 | GT_GEN6_BLT_USER_INTERRUPT | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2219 | GT_GEN6_BSD_USER_INTERRUPT | |
| 2220 | GT_GEN6_BSD_CS_ERROR_INTERRUPT | |
| 2221 | GT_GEN7_L3_PARITY_ERROR_INTERRUPT | |
| 2222 | GT_PIPE_NOTIFY | |
| 2223 | GT_RENDER_CS_ERROR_INTERRUPT | |
| 2224 | GT_SYNC_STATUS | |
| 2225 | GT_USER_INTERRUPT; |
| 2226 | |
| 2227 | dev_priv->gt_irq_mask = ~render_irqs; |
| 2228 | |
| 2229 | I915_WRITE(GTIIR, I915_READ(GTIIR)); |
| 2230 | I915_WRITE(GTIIR, I915_READ(GTIIR)); |
| 2231 | I915_WRITE(GTIMR, 0); |
| 2232 | I915_WRITE(GTIER, render_irqs); |
| 2233 | POSTING_READ(GTIER); |
| 2234 | |
| 2235 | /* ack & enable invalid PTE error interrupts */ |
| 2236 | #if 0 /* FIXME: add support to irq handler for checking these bits */ |
| 2237 | I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK); |
| 2238 | I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK); |
| 2239 | #endif |
| 2240 | |
| 2241 | I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE); |
| 2242 | #if 0 /* FIXME: check register definitions; some have moved */ |
| 2243 | /* Note HDMI and DP share bits */ |
| 2244 | if (dev_priv->hotplug_supported_mask & HDMIB_HOTPLUG_INT_STATUS) |
| 2245 | hotplug_en |= HDMIB_HOTPLUG_INT_EN; |
| 2246 | if (dev_priv->hotplug_supported_mask & HDMIC_HOTPLUG_INT_STATUS) |
| 2247 | hotplug_en |= HDMIC_HOTPLUG_INT_EN; |
| 2248 | if (dev_priv->hotplug_supported_mask & HDMID_HOTPLUG_INT_STATUS) |
| 2249 | hotplug_en |= HDMID_HOTPLUG_INT_EN; |
| 2250 | if (dev_priv->hotplug_supported_mask & SDVOC_HOTPLUG_INT_STATUS) |
| 2251 | hotplug_en |= SDVOC_HOTPLUG_INT_EN; |
| 2252 | if (dev_priv->hotplug_supported_mask & SDVOB_HOTPLUG_INT_STATUS) |
| 2253 | hotplug_en |= SDVOB_HOTPLUG_INT_EN; |
| 2254 | if (dev_priv->hotplug_supported_mask & CRT_HOTPLUG_INT_STATUS) { |
| 2255 | hotplug_en |= CRT_HOTPLUG_INT_EN; |
| 2256 | hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; |
| 2257 | } |
| 2258 | #endif |
| 2259 | |
| 2260 | I915_WRITE(PORT_HOTPLUG_EN, hotplug_en); |
| 2261 | |
| 2262 | return 0; |
| 2263 | } |
| 2264 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 2265 | static void i915_driver_irq_preinstall(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | { |
| 2267 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 2268 | int pipe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2270 | atomic_set(&dev_priv->irq_received, 0); |
| 2271 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2272 | INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 2273 | INIT_WORK(&dev_priv->error_work, i915_error_work_func); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2274 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 2275 | if (I915_HAS_HOTPLUG(dev)) { |
| 2276 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
| 2277 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); |
| 2278 | } |
| 2279 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 2280 | I915_WRITE(HWSTAM, 0xeffe); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 2281 | for_each_pipe(pipe) |
| 2282 | I915_WRITE(PIPESTAT(pipe), 0); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 2283 | I915_WRITE(IMR, 0xffffffff); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 2284 | I915_WRITE(IER, 0x0); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 2285 | POSTING_READ(IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | } |
| 2287 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 2288 | /* |
| 2289 | * Must be called after intel_modeset_init or hotplug interrupts won't be |
| 2290 | * enabled correctly. |
| 2291 | */ |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 2292 | static int i915_driver_irq_postinstall(struct drm_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | { |
| 2294 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 2295 | u32 enable_mask = I915_INTERRUPT_ENABLE_FIX | I915_INTERRUPT_ENABLE_VAR; |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 2296 | u32 error_mask; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 2297 | |
| 2298 | dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 2299 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 2300 | /* Unmask the interrupts that we always want on. */ |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2301 | dev_priv->irq_mask = ~I915_INTERRUPT_ENABLE_FIX; |
Matthew Garrett | 8ee1c3d | 2008-08-05 19:37:25 +0100 | [diff] [blame] | 2302 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 2303 | dev_priv->pipestat[0] = 0; |
| 2304 | dev_priv->pipestat[1] = 0; |
| 2305 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 2306 | if (I915_HAS_HOTPLUG(dev)) { |
Adam Jackson | c496fa1 | 2010-05-27 17:26:45 -0400 | [diff] [blame] | 2307 | /* Enable in IER... */ |
| 2308 | enable_mask |= I915_DISPLAY_PORT_INTERRUPT; |
| 2309 | /* and unmask in IMR */ |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2310 | dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT; |
Adam Jackson | c496fa1 | 2010-05-27 17:26:45 -0400 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | /* |
| 2314 | * Enable some error detection, note the instruction error mask |
| 2315 | * bit is reserved, so we leave it masked. |
| 2316 | */ |
| 2317 | if (IS_G4X(dev)) { |
| 2318 | error_mask = ~(GM45_ERROR_PAGE_TABLE | |
| 2319 | GM45_ERROR_MEM_PRIV | |
| 2320 | GM45_ERROR_CP_PRIV | |
| 2321 | I915_ERROR_MEMORY_REFRESH); |
| 2322 | } else { |
| 2323 | error_mask = ~(I915_ERROR_PAGE_TABLE | |
| 2324 | I915_ERROR_MEMORY_REFRESH); |
| 2325 | } |
| 2326 | I915_WRITE(EMR, error_mask); |
| 2327 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2328 | I915_WRITE(IMR, dev_priv->irq_mask); |
Adam Jackson | c496fa1 | 2010-05-27 17:26:45 -0400 | [diff] [blame] | 2329 | I915_WRITE(IER, enable_mask); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 2330 | POSTING_READ(IER); |
Adam Jackson | c496fa1 | 2010-05-27 17:26:45 -0400 | [diff] [blame] | 2331 | |
| 2332 | if (I915_HAS_HOTPLUG(dev)) { |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 2333 | u32 hotplug_en = I915_READ(PORT_HOTPLUG_EN); |
| 2334 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 2335 | /* Note HDMI and DP share bits */ |
| 2336 | if (dev_priv->hotplug_supported_mask & HDMIB_HOTPLUG_INT_STATUS) |
| 2337 | hotplug_en |= HDMIB_HOTPLUG_INT_EN; |
| 2338 | if (dev_priv->hotplug_supported_mask & HDMIC_HOTPLUG_INT_STATUS) |
| 2339 | hotplug_en |= HDMIC_HOTPLUG_INT_EN; |
| 2340 | if (dev_priv->hotplug_supported_mask & HDMID_HOTPLUG_INT_STATUS) |
| 2341 | hotplug_en |= HDMID_HOTPLUG_INT_EN; |
| 2342 | if (dev_priv->hotplug_supported_mask & SDVOC_HOTPLUG_INT_STATUS) |
| 2343 | hotplug_en |= SDVOC_HOTPLUG_INT_EN; |
| 2344 | if (dev_priv->hotplug_supported_mask & SDVOB_HOTPLUG_INT_STATUS) |
| 2345 | hotplug_en |= SDVOB_HOTPLUG_INT_EN; |
Andy Lutomirski | 2d1c975 | 2010-06-12 05:21:18 -0400 | [diff] [blame] | 2346 | if (dev_priv->hotplug_supported_mask & CRT_HOTPLUG_INT_STATUS) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 2347 | hotplug_en |= CRT_HOTPLUG_INT_EN; |
Andy Lutomirski | 2d1c975 | 2010-06-12 05:21:18 -0400 | [diff] [blame] | 2348 | |
| 2349 | /* Programming the CRT detection parameters tends |
| 2350 | to generate a spurious hotplug event about three |
| 2351 | seconds later. So just do it once. |
| 2352 | */ |
| 2353 | if (IS_G4X(dev)) |
| 2354 | hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64; |
| 2355 | hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; |
| 2356 | } |
| 2357 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 2358 | /* Ignore TV since it's buggy */ |
| 2359 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 2360 | I915_WRITE(PORT_HOTPLUG_EN, hotplug_en); |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 2361 | } |
| 2362 | |
Chris Wilson | 3b61796 | 2010-08-24 09:02:58 +0100 | [diff] [blame] | 2363 | intel_opregion_enable_asle(dev); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 2364 | |
| 2365 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | } |
| 2367 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2368 | static void valleyview_irq_uninstall(struct drm_device *dev) |
| 2369 | { |
| 2370 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 2371 | int pipe; |
| 2372 | |
| 2373 | if (!dev_priv) |
| 2374 | return; |
| 2375 | |
| 2376 | dev_priv->vblank_pipe = 0; |
| 2377 | |
| 2378 | for_each_pipe(pipe) |
| 2379 | I915_WRITE(PIPESTAT(pipe), 0xffff); |
| 2380 | |
| 2381 | I915_WRITE(HWSTAM, 0xffffffff); |
| 2382 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
| 2383 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); |
| 2384 | for_each_pipe(pipe) |
| 2385 | I915_WRITE(PIPESTAT(pipe), 0xffff); |
| 2386 | I915_WRITE(VLV_IIR, 0xffffffff); |
| 2387 | I915_WRITE(VLV_IMR, 0xffffffff); |
| 2388 | I915_WRITE(VLV_IER, 0x0); |
| 2389 | POSTING_READ(VLV_IER); |
| 2390 | } |
| 2391 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 2392 | static void ironlake_irq_uninstall(struct drm_device *dev) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2393 | { |
| 2394 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Jesse Barnes | 4697995 | 2011-04-07 13:53:55 -0700 | [diff] [blame] | 2395 | |
| 2396 | if (!dev_priv) |
| 2397 | return; |
| 2398 | |
| 2399 | dev_priv->vblank_pipe = 0; |
| 2400 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2401 | I915_WRITE(HWSTAM, 0xffffffff); |
| 2402 | |
| 2403 | I915_WRITE(DEIMR, 0xffffffff); |
| 2404 | I915_WRITE(DEIER, 0x0); |
| 2405 | I915_WRITE(DEIIR, I915_READ(DEIIR)); |
| 2406 | |
| 2407 | I915_WRITE(GTIMR, 0xffffffff); |
| 2408 | I915_WRITE(GTIER, 0x0); |
| 2409 | I915_WRITE(GTIIR, I915_READ(GTIIR)); |
Keith Packard | 192aac1f | 2011-09-20 10:12:44 -0700 | [diff] [blame] | 2410 | |
| 2411 | I915_WRITE(SDEIMR, 0xffffffff); |
| 2412 | I915_WRITE(SDEIER, 0x0); |
| 2413 | I915_WRITE(SDEIIR, I915_READ(SDEIIR)); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 2414 | } |
| 2415 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 2416 | static void i915_driver_irq_uninstall(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | { |
| 2418 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 2419 | int pipe; |
Dave Airlie | 91e3738 | 2006-02-18 15:17:04 +1100 | [diff] [blame] | 2420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2421 | if (!dev_priv) |
| 2422 | return; |
| 2423 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 2424 | dev_priv->vblank_pipe = 0; |
| 2425 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 2426 | if (I915_HAS_HOTPLUG(dev)) { |
| 2427 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
| 2428 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); |
| 2429 | } |
| 2430 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 2431 | I915_WRITE(HWSTAM, 0xffffffff); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 2432 | for_each_pipe(pipe) |
| 2433 | I915_WRITE(PIPESTAT(pipe), 0); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 2434 | I915_WRITE(IMR, 0xffffffff); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 2435 | I915_WRITE(IER, 0x0); |
Dave Airlie | 91e3738 | 2006-02-18 15:17:04 +1100 | [diff] [blame] | 2436 | |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 2437 | for_each_pipe(pipe) |
| 2438 | I915_WRITE(PIPESTAT(pipe), |
| 2439 | I915_READ(PIPESTAT(pipe)) & 0x8000ffff); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 2440 | I915_WRITE(IIR, I915_READ(IIR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2441 | } |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 2442 | |
| 2443 | void intel_irq_init(struct drm_device *dev) |
| 2444 | { |
| 2445 | dev->driver->get_vblank_counter = i915_get_vblank_counter; |
| 2446 | dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2447 | if (IS_G4X(dev) || IS_GEN5(dev) || IS_GEN6(dev) || IS_IVYBRIDGE(dev) || |
| 2448 | IS_VALLEYVIEW(dev)) { |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 2449 | dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */ |
| 2450 | dev->driver->get_vblank_counter = gm45_get_vblank_counter; |
| 2451 | } |
| 2452 | |
Keith Packard | c3613de | 2011-08-12 17:05:54 -0700 | [diff] [blame] | 2453 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2454 | dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp; |
| 2455 | else |
| 2456 | dev->driver->get_vblank_timestamp = NULL; |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 2457 | dev->driver->get_scanout_position = i915_get_crtc_scanoutpos; |
| 2458 | |
Jesse Barnes | 7e231dbe | 2012-03-28 13:39:38 -0700 | [diff] [blame] | 2459 | if (IS_VALLEYVIEW(dev)) { |
| 2460 | dev->driver->irq_handler = valleyview_irq_handler; |
| 2461 | dev->driver->irq_preinstall = valleyview_irq_preinstall; |
| 2462 | dev->driver->irq_postinstall = valleyview_irq_postinstall; |
| 2463 | dev->driver->irq_uninstall = valleyview_irq_uninstall; |
| 2464 | dev->driver->enable_vblank = valleyview_enable_vblank; |
| 2465 | dev->driver->disable_vblank = valleyview_disable_vblank; |
| 2466 | } else if (IS_IVYBRIDGE(dev)) { |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 2467 | /* Share pre & uninstall handlers with ILK/SNB */ |
| 2468 | dev->driver->irq_handler = ivybridge_irq_handler; |
| 2469 | dev->driver->irq_preinstall = ironlake_irq_preinstall; |
| 2470 | dev->driver->irq_postinstall = ivybridge_irq_postinstall; |
| 2471 | dev->driver->irq_uninstall = ironlake_irq_uninstall; |
| 2472 | dev->driver->enable_vblank = ivybridge_enable_vblank; |
| 2473 | dev->driver->disable_vblank = ivybridge_disable_vblank; |
| 2474 | } else if (HAS_PCH_SPLIT(dev)) { |
| 2475 | dev->driver->irq_handler = ironlake_irq_handler; |
| 2476 | dev->driver->irq_preinstall = ironlake_irq_preinstall; |
| 2477 | dev->driver->irq_postinstall = ironlake_irq_postinstall; |
| 2478 | dev->driver->irq_uninstall = ironlake_irq_uninstall; |
| 2479 | dev->driver->enable_vblank = ironlake_enable_vblank; |
| 2480 | dev->driver->disable_vblank = ironlake_disable_vblank; |
| 2481 | } else { |
| 2482 | dev->driver->irq_preinstall = i915_driver_irq_preinstall; |
| 2483 | dev->driver->irq_postinstall = i915_driver_irq_postinstall; |
| 2484 | dev->driver->irq_uninstall = i915_driver_irq_uninstall; |
| 2485 | dev->driver->irq_handler = i915_driver_irq_handler; |
| 2486 | dev->driver->enable_vblank = i915_enable_vblank; |
| 2487 | dev->driver->disable_vblank = i915_disable_vblank; |
| 2488 | } |
| 2489 | } |