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 | |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 29 | #include <linux/sysrq.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include "drmP.h" |
| 32 | #include "drm.h" |
| 33 | #include "i915_drm.h" |
| 34 | #include "i915_drv.h" |
Chris Wilson | 1c5d22f | 2009-08-25 11:15:50 +0100 | [diff] [blame] | 35 | #include "i915_trace.h" |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 36 | #include "intel_drv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #define MAX_NOPID ((u32)~0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 40 | /** |
| 41 | * Interrupts that are always left unmasked. |
| 42 | * |
| 43 | * Since pipe events are edge-triggered from the PIPESTAT register to IIR, |
| 44 | * we leave them always unmasked in IMR and then control enabling them through |
| 45 | * PIPESTAT alone. |
| 46 | */ |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 47 | #define I915_INTERRUPT_ENABLE_FIX \ |
| 48 | (I915_ASLE_INTERRUPT | \ |
| 49 | I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | \ |
| 50 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | \ |
| 51 | I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | \ |
| 52 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | \ |
| 53 | I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 54 | |
| 55 | /** Interrupts that we mask and unmask at runtime. */ |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 56 | #define I915_INTERRUPT_ENABLE_VAR (I915_USER_INTERRUPT | I915_BSD_USER_INTERRUPT) |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 57 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 58 | #define I915_PIPE_VBLANK_STATUS (PIPE_START_VBLANK_INTERRUPT_STATUS |\ |
| 59 | PIPE_VBLANK_INTERRUPT_STATUS) |
| 60 | |
| 61 | #define I915_PIPE_VBLANK_ENABLE (PIPE_START_VBLANK_INTERRUPT_ENABLE |\ |
| 62 | PIPE_VBLANK_INTERRUPT_ENABLE) |
| 63 | |
| 64 | #define DRM_I915_VBLANK_PIPE_ALL (DRM_I915_VBLANK_PIPE_A | \ |
| 65 | DRM_I915_VBLANK_PIPE_B) |
| 66 | |
Matthew Garrett | 8ee1c3d | 2008-08-05 19:37:25 +0100 | [diff] [blame] | 67 | void |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 68 | ironlake_enable_graphics_irq(drm_i915_private_t *dev_priv, u32 mask) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 69 | { |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 70 | if ((dev_priv->gt_irq_mask & mask) != 0) { |
| 71 | dev_priv->gt_irq_mask &= ~mask; |
| 72 | I915_WRITE(GTIMR, dev_priv->gt_irq_mask); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 73 | POSTING_READ(GTIMR); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 77 | void |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 78 | ironlake_disable_graphics_irq(drm_i915_private_t *dev_priv, u32 mask) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 79 | { |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 80 | if ((dev_priv->gt_irq_mask & mask) != mask) { |
| 81 | dev_priv->gt_irq_mask |= mask; |
| 82 | I915_WRITE(GTIMR, dev_priv->gt_irq_mask); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 83 | POSTING_READ(GTIMR); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | |
| 87 | /* For display hotplug interrupt */ |
Chris Wilson | 995b6762 | 2010-08-20 13:23:26 +0100 | [diff] [blame] | 88 | static void |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 89 | ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 90 | { |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 91 | if ((dev_priv->irq_mask & mask) != 0) { |
| 92 | dev_priv->irq_mask &= ~mask; |
| 93 | I915_WRITE(DEIMR, dev_priv->irq_mask); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 94 | POSTING_READ(DEIMR); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
| 98 | static inline void |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 99 | ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 100 | { |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 101 | if ((dev_priv->irq_mask & mask) != mask) { |
| 102 | dev_priv->irq_mask |= mask; |
| 103 | I915_WRITE(DEIMR, dev_priv->irq_mask); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 104 | POSTING_READ(DEIMR); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | |
| 108 | void |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 109 | i915_enable_irq(drm_i915_private_t *dev_priv, u32 mask) |
| 110 | { |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 111 | if ((dev_priv->irq_mask & mask) != 0) { |
| 112 | dev_priv->irq_mask &= ~mask; |
| 113 | I915_WRITE(IMR, dev_priv->irq_mask); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 114 | POSTING_READ(IMR); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 115 | } |
| 116 | } |
| 117 | |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 118 | void |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 119 | i915_disable_irq(drm_i915_private_t *dev_priv, u32 mask) |
| 120 | { |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 121 | if ((dev_priv->irq_mask & mask) != mask) { |
| 122 | dev_priv->irq_mask |= mask; |
| 123 | I915_WRITE(IMR, dev_priv->irq_mask); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 124 | POSTING_READ(IMR); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 128 | static inline u32 |
| 129 | i915_pipestat(int pipe) |
| 130 | { |
| 131 | if (pipe == 0) |
| 132 | return PIPEASTAT; |
| 133 | if (pipe == 1) |
| 134 | return PIPEBSTAT; |
Andrew Morton | 9c84ba4 | 2008-12-01 13:14:08 -0800 | [diff] [blame] | 135 | BUG(); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | void |
| 139 | i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask) |
| 140 | { |
| 141 | if ((dev_priv->pipestat[pipe] & mask) != mask) { |
| 142 | u32 reg = i915_pipestat(pipe); |
| 143 | |
| 144 | dev_priv->pipestat[pipe] |= mask; |
| 145 | /* Enable the interrupt, clear any pending status */ |
| 146 | I915_WRITE(reg, dev_priv->pipestat[pipe] | (mask >> 16)); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 147 | POSTING_READ(reg); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | |
| 151 | void |
| 152 | i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask) |
| 153 | { |
| 154 | if ((dev_priv->pipestat[pipe] & mask) != 0) { |
| 155 | u32 reg = i915_pipestat(pipe); |
| 156 | |
| 157 | dev_priv->pipestat[pipe] &= ~mask; |
| 158 | I915_WRITE(reg, dev_priv->pipestat[pipe]); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 159 | POSTING_READ(reg); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 163 | /** |
Zhao Yakui | 01c6688 | 2009-10-28 05:10:00 +0000 | [diff] [blame] | 164 | * intel_enable_asle - enable ASLE interrupt for OpRegion |
| 165 | */ |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 166 | void intel_enable_asle(struct drm_device *dev) |
Zhao Yakui | 01c6688 | 2009-10-28 05:10:00 +0000 | [diff] [blame] | 167 | { |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 168 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 169 | unsigned long irqflags; |
| 170 | |
| 171 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Zhao Yakui | 01c6688 | 2009-10-28 05:10:00 +0000 | [diff] [blame] | 172 | |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 173 | if (HAS_PCH_SPLIT(dev)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 174 | ironlake_enable_display_irq(dev_priv, DE_GSE); |
Zhao Yakui | edcb49c | 2010-04-07 17:11:21 +0800 | [diff] [blame] | 175 | else { |
Zhao Yakui | 01c6688 | 2009-10-28 05:10:00 +0000 | [diff] [blame] | 176 | i915_enable_pipestat(dev_priv, 1, |
Jesse Barnes | d874bcf | 2010-06-30 13:16:00 -0700 | [diff] [blame] | 177 | PIPE_LEGACY_BLC_EVENT_ENABLE); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 178 | if (INTEL_INFO(dev)->gen >= 4) |
Zhao Yakui | edcb49c | 2010-04-07 17:11:21 +0800 | [diff] [blame] | 179 | i915_enable_pipestat(dev_priv, 0, |
Jesse Barnes | d874bcf | 2010-06-30 13:16:00 -0700 | [diff] [blame] | 180 | PIPE_LEGACY_BLC_EVENT_ENABLE); |
Zhao Yakui | edcb49c | 2010-04-07 17:11:21 +0800 | [diff] [blame] | 181 | } |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 182 | |
| 183 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
Zhao Yakui | 01c6688 | 2009-10-28 05:10:00 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /** |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 187 | * i915_pipe_enabled - check if a pipe is enabled |
| 188 | * @dev: DRM device |
| 189 | * @pipe: pipe to check |
| 190 | * |
| 191 | * Reading certain registers when the pipe is disabled can hang the chip. |
| 192 | * Use this routine to make sure the PLL is running and the pipe is active |
| 193 | * before reading such registers if unsure. |
| 194 | */ |
| 195 | static int |
| 196 | i915_pipe_enabled(struct drm_device *dev, int pipe) |
| 197 | { |
| 198 | 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] | 199 | return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Keith Packard | 42f52ef | 2008-10-18 19:39:29 -0700 | [diff] [blame] | 202 | /* Called from drm generic code, passed a 'crtc', which |
| 203 | * we use as a pipe index |
| 204 | */ |
| 205 | u32 i915_get_vblank_counter(struct drm_device *dev, int pipe) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 206 | { |
| 207 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 208 | unsigned long high_frame; |
| 209 | unsigned long low_frame; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 210 | u32 high1, high2, low; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 211 | |
| 212 | if (!i915_pipe_enabled(dev, pipe)) { |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 213 | DRM_DEBUG_DRIVER("trying to get vblank count for disabled " |
| 214 | "pipe %d\n", pipe); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 215 | return 0; |
| 216 | } |
| 217 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 218 | high_frame = pipe ? PIPEBFRAMEHIGH : PIPEAFRAMEHIGH; |
| 219 | low_frame = pipe ? PIPEBFRAMEPIXEL : PIPEAFRAMEPIXEL; |
| 220 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 221 | /* |
| 222 | * High & low register fields aren't synchronized, so make sure |
| 223 | * we get a low value that's stable across two reads of the high |
| 224 | * register. |
| 225 | */ |
| 226 | do { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 227 | high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; |
| 228 | low = I915_READ(low_frame) & PIPE_FRAME_LOW_MASK; |
| 229 | high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 230 | } while (high1 != high2); |
| 231 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 232 | high1 >>= PIPE_FRAME_HIGH_SHIFT; |
| 233 | low >>= PIPE_FRAME_LOW_SHIFT; |
| 234 | return (high1 << 8) | low; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Jesse Barnes | 9880b7a | 2009-02-06 10:22:41 -0800 | [diff] [blame] | 237 | u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe) |
| 238 | { |
| 239 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 240 | int reg = pipe ? PIPEB_FRMCOUNT_GM45 : PIPEA_FRMCOUNT_GM45; |
| 241 | |
| 242 | if (!i915_pipe_enabled(dev, pipe)) { |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 243 | DRM_DEBUG_DRIVER("trying to get vblank count for disabled " |
| 244 | "pipe %d\n", pipe); |
Jesse Barnes | 9880b7a | 2009-02-06 10:22:41 -0800 | [diff] [blame] | 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | return I915_READ(reg); |
| 249 | } |
| 250 | |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame^] | 251 | int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe, |
| 252 | int *vpos, int *hpos) |
| 253 | { |
| 254 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 255 | u32 vbl = 0, position = 0; |
| 256 | int vbl_start, vbl_end, htotal, vtotal; |
| 257 | bool in_vbl = true; |
| 258 | int ret = 0; |
| 259 | |
| 260 | if (!i915_pipe_enabled(dev, pipe)) { |
| 261 | DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled " |
| 262 | "pipe %d\n", pipe); |
| 263 | return 0; |
| 264 | } |
| 265 | |
| 266 | /* Get vtotal. */ |
| 267 | vtotal = 1 + ((I915_READ(VTOTAL(pipe)) >> 16) & 0x1fff); |
| 268 | |
| 269 | if (INTEL_INFO(dev)->gen >= 4) { |
| 270 | /* No obvious pixelcount register. Only query vertical |
| 271 | * scanout position from Display scan line register. |
| 272 | */ |
| 273 | position = I915_READ(PIPEDSL(pipe)); |
| 274 | |
| 275 | /* Decode into vertical scanout position. Don't have |
| 276 | * horizontal scanout position. |
| 277 | */ |
| 278 | *vpos = position & 0x1fff; |
| 279 | *hpos = 0; |
| 280 | } else { |
| 281 | /* Have access to pixelcount since start of frame. |
| 282 | * We can split this into vertical and horizontal |
| 283 | * scanout position. |
| 284 | */ |
| 285 | position = (I915_READ(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT; |
| 286 | |
| 287 | htotal = 1 + ((I915_READ(HTOTAL(pipe)) >> 16) & 0x1fff); |
| 288 | *vpos = position / htotal; |
| 289 | *hpos = position - (*vpos * htotal); |
| 290 | } |
| 291 | |
| 292 | /* Query vblank area. */ |
| 293 | vbl = I915_READ(VBLANK(pipe)); |
| 294 | |
| 295 | /* Test position against vblank region. */ |
| 296 | vbl_start = vbl & 0x1fff; |
| 297 | vbl_end = (vbl >> 16) & 0x1fff; |
| 298 | |
| 299 | if ((*vpos < vbl_start) || (*vpos > vbl_end)) |
| 300 | in_vbl = false; |
| 301 | |
| 302 | /* Inside "upper part" of vblank area? Apply corrective offset: */ |
| 303 | if (in_vbl && (*vpos >= vbl_start)) |
| 304 | *vpos = *vpos - vtotal; |
| 305 | |
| 306 | /* Readouts valid? */ |
| 307 | if (vbl > 0) |
| 308 | ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE; |
| 309 | |
| 310 | /* In vblank? */ |
| 311 | if (in_vbl) |
| 312 | ret |= DRM_SCANOUTPOS_INVBL; |
| 313 | |
| 314 | return ret; |
| 315 | } |
| 316 | |
| 317 | int i915_get_vblank_timestamp(struct drm_device *dev, int crtc, |
| 318 | int *max_error, |
| 319 | struct timeval *vblank_time, |
| 320 | unsigned flags) |
| 321 | { |
| 322 | struct drm_crtc *drmcrtc; |
| 323 | |
| 324 | if (crtc < 0 || crtc >= dev->num_crtcs) { |
| 325 | DRM_ERROR("Invalid crtc %d\n", crtc); |
| 326 | return -EINVAL; |
| 327 | } |
| 328 | |
| 329 | /* Get drm_crtc to timestamp: */ |
| 330 | drmcrtc = intel_get_crtc_for_pipe(dev, crtc); |
| 331 | |
| 332 | /* Helper routine in DRM core does all the work: */ |
| 333 | return drm_calc_vbltimestamp_from_scanoutpos(dev, crtc, max_error, |
| 334 | vblank_time, flags, drmcrtc); |
| 335 | } |
| 336 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 337 | /* |
| 338 | * Handle hotplug events outside the interrupt handler proper. |
| 339 | */ |
| 340 | static void i915_hotplug_work_func(struct work_struct *work) |
| 341 | { |
| 342 | drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, |
| 343 | hotplug_work); |
| 344 | struct drm_device *dev = dev_priv->dev; |
Keith Packard | c31c4ba | 2009-05-06 11:48:58 -0700 | [diff] [blame] | 345 | struct drm_mode_config *mode_config = &dev->mode_config; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 346 | struct intel_encoder *encoder; |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 347 | |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 348 | list_for_each_entry(encoder, &mode_config->encoder_list, base.head) |
| 349 | if (encoder->hot_plug) |
| 350 | encoder->hot_plug(encoder); |
| 351 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 352 | /* 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] | 353 | drm_helper_hpd_irq_event(dev); |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 356 | static void i915_handle_rps_change(struct drm_device *dev) |
| 357 | { |
| 358 | drm_i915_private_t *dev_priv = dev->dev_private; |
Matthew Garrett | b5b72e8 | 2010-02-02 18:30:47 +0000 | [diff] [blame] | 359 | u32 busy_up, busy_down, max_avg, min_avg; |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 360 | u8 new_delay = dev_priv->cur_delay; |
| 361 | |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 362 | I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG); |
Matthew Garrett | b5b72e8 | 2010-02-02 18:30:47 +0000 | [diff] [blame] | 363 | busy_up = I915_READ(RCPREVBSYTUPAVG); |
| 364 | busy_down = I915_READ(RCPREVBSYTDNAVG); |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 365 | max_avg = I915_READ(RCBMAXAVG); |
| 366 | min_avg = I915_READ(RCBMINAVG); |
| 367 | |
| 368 | /* Handle RCS change request from hw */ |
Matthew Garrett | b5b72e8 | 2010-02-02 18:30:47 +0000 | [diff] [blame] | 369 | if (busy_up > max_avg) { |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 370 | if (dev_priv->cur_delay != dev_priv->max_delay) |
| 371 | new_delay = dev_priv->cur_delay - 1; |
| 372 | if (new_delay < dev_priv->max_delay) |
| 373 | new_delay = dev_priv->max_delay; |
Matthew Garrett | b5b72e8 | 2010-02-02 18:30:47 +0000 | [diff] [blame] | 374 | } else if (busy_down < min_avg) { |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 375 | if (dev_priv->cur_delay != dev_priv->min_delay) |
| 376 | new_delay = dev_priv->cur_delay + 1; |
| 377 | if (new_delay > dev_priv->min_delay) |
| 378 | new_delay = dev_priv->min_delay; |
| 379 | } |
| 380 | |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 381 | if (ironlake_set_drps(dev, new_delay)) |
| 382 | dev_priv->cur_delay = new_delay; |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 383 | |
| 384 | return; |
| 385 | } |
| 386 | |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 387 | static void notify_ring(struct drm_device *dev, |
| 388 | struct intel_ring_buffer *ring) |
| 389 | { |
| 390 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 391 | u32 seqno = ring->get_seqno(ring); |
Chris Wilson | b222349 | 2010-10-27 15:27:33 +0100 | [diff] [blame] | 392 | ring->irq_seqno = seqno; |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 393 | trace_i915_gem_request_complete(dev, seqno); |
| 394 | wake_up_all(&ring->irq_queue); |
| 395 | dev_priv->hangcheck_count = 0; |
| 396 | mod_timer(&dev_priv->hangcheck_timer, |
| 397 | jiffies + msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD)); |
| 398 | } |
| 399 | |
Chris Wilson | 995b6762 | 2010-08-20 13:23:26 +0100 | [diff] [blame] | 400 | static irqreturn_t ironlake_irq_handler(struct drm_device *dev) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 401 | { |
| 402 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 403 | int ret = IRQ_NONE; |
Dave Airlie | 3ff9916 | 2009-12-08 14:03:47 +1000 | [diff] [blame] | 404 | u32 de_iir, gt_iir, de_ier, pch_iir; |
Yuanhan Liu | 2d7b836 | 2010-10-08 10:21:06 +0100 | [diff] [blame] | 405 | u32 hotplug_mask; |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 406 | struct drm_i915_master_private *master_priv; |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 407 | u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT; |
| 408 | |
| 409 | if (IS_GEN6(dev)) |
| 410 | bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT; |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 411 | |
Zou, Nanhai | 2d109a8 | 2009-11-06 02:13:01 +0000 | [diff] [blame] | 412 | /* disable master interrupt before clearing iir */ |
| 413 | de_ier = I915_READ(DEIER); |
| 414 | I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 415 | POSTING_READ(DEIER); |
Zou, Nanhai | 2d109a8 | 2009-11-06 02:13:01 +0000 | [diff] [blame] | 416 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 417 | de_iir = I915_READ(DEIIR); |
| 418 | gt_iir = I915_READ(GTIIR); |
Zhenyu Wang | c650156 | 2009-11-03 18:57:21 +0000 | [diff] [blame] | 419 | pch_iir = I915_READ(SDEIIR); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 420 | |
Zou Nan hai | c7c8510 | 2010-01-15 10:29:06 +0800 | [diff] [blame] | 421 | if (de_iir == 0 && gt_iir == 0 && pch_iir == 0) |
| 422 | goto done; |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 423 | |
Yuanhan Liu | 2d7b836 | 2010-10-08 10:21:06 +0100 | [diff] [blame] | 424 | if (HAS_PCH_CPT(dev)) |
| 425 | hotplug_mask = SDE_HOTPLUG_MASK_CPT; |
| 426 | else |
| 427 | hotplug_mask = SDE_HOTPLUG_MASK; |
| 428 | |
Zou Nan hai | c7c8510 | 2010-01-15 10:29:06 +0800 | [diff] [blame] | 429 | ret = IRQ_HANDLED; |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 430 | |
Zou Nan hai | c7c8510 | 2010-01-15 10:29:06 +0800 | [diff] [blame] | 431 | if (dev->primary->master) { |
| 432 | master_priv = dev->primary->master->driver_priv; |
| 433 | if (master_priv->sarea_priv) |
| 434 | master_priv->sarea_priv->last_dispatch = |
| 435 | READ_BREADCRUMB(dev_priv); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 436 | } |
| 437 | |
Chris Wilson | c6df541 | 2010-12-15 09:56:50 +0000 | [diff] [blame] | 438 | if (gt_iir & (GT_USER_INTERRUPT | GT_PIPE_NOTIFY)) |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 439 | notify_ring(dev, &dev_priv->ring[RCS]); |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 440 | if (gt_iir & bsd_usr_interrupt) |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 441 | notify_ring(dev, &dev_priv->ring[VCS]); |
| 442 | if (gt_iir & GT_BLT_USER_INTERRUPT) |
| 443 | notify_ring(dev, &dev_priv->ring[BCS]); |
Zou Nan hai | c7c8510 | 2010-01-15 10:29:06 +0800 | [diff] [blame] | 444 | |
| 445 | if (de_iir & DE_GSE) |
Chris Wilson | 3b61796 | 2010-08-24 09:02:58 +0100 | [diff] [blame] | 446 | intel_opregion_gse_intr(dev); |
Zou Nan hai | c7c8510 | 2010-01-15 10:29:06 +0800 | [diff] [blame] | 447 | |
Zhenyu Wang | f072d2e | 2010-02-09 09:46:19 +0800 | [diff] [blame] | 448 | if (de_iir & DE_PLANEA_FLIP_DONE) { |
Jesse Barnes | 013d5aa | 2010-01-29 11:18:31 -0800 | [diff] [blame] | 449 | intel_prepare_page_flip(dev, 0); |
Chris Wilson | 2bbda38 | 2010-09-02 17:59:39 +0100 | [diff] [blame] | 450 | intel_finish_page_flip_plane(dev, 0); |
Jesse Barnes | 013d5aa | 2010-01-29 11:18:31 -0800 | [diff] [blame] | 451 | } |
| 452 | |
Zhenyu Wang | f072d2e | 2010-02-09 09:46:19 +0800 | [diff] [blame] | 453 | if (de_iir & DE_PLANEB_FLIP_DONE) { |
| 454 | intel_prepare_page_flip(dev, 1); |
Chris Wilson | 2bbda38 | 2010-09-02 17:59:39 +0100 | [diff] [blame] | 455 | intel_finish_page_flip_plane(dev, 1); |
Jesse Barnes | 013d5aa | 2010-01-29 11:18:31 -0800 | [diff] [blame] | 456 | } |
Li Peng | c062df6 | 2010-01-23 00:12:58 +0800 | [diff] [blame] | 457 | |
Zhenyu Wang | f072d2e | 2010-02-09 09:46:19 +0800 | [diff] [blame] | 458 | if (de_iir & DE_PIPEA_VBLANK) |
| 459 | drm_handle_vblank(dev, 0); |
| 460 | |
| 461 | if (de_iir & DE_PIPEB_VBLANK) |
| 462 | drm_handle_vblank(dev, 1); |
| 463 | |
Zou Nan hai | c7c8510 | 2010-01-15 10:29:06 +0800 | [diff] [blame] | 464 | /* check event from PCH */ |
Yuanhan Liu | 2d7b836 | 2010-10-08 10:21:06 +0100 | [diff] [blame] | 465 | if ((de_iir & DE_PCH_EVENT) && (pch_iir & hotplug_mask)) |
Zou Nan hai | c7c8510 | 2010-01-15 10:29:06 +0800 | [diff] [blame] | 466 | queue_work(dev_priv->wq, &dev_priv->hotplug_work); |
Zou Nan hai | c7c8510 | 2010-01-15 10:29:06 +0800 | [diff] [blame] | 467 | |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 468 | if (de_iir & DE_PCU_EVENT) { |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 469 | I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS)); |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 470 | i915_handle_rps_change(dev); |
| 471 | } |
| 472 | |
Zou Nan hai | c7c8510 | 2010-01-15 10:29:06 +0800 | [diff] [blame] | 473 | /* should clear PCH hotplug event before clear CPU irq */ |
| 474 | I915_WRITE(SDEIIR, pch_iir); |
| 475 | I915_WRITE(GTIIR, gt_iir); |
| 476 | I915_WRITE(DEIIR, de_iir); |
| 477 | |
| 478 | done: |
Zou, Nanhai | 2d109a8 | 2009-11-06 02:13:01 +0000 | [diff] [blame] | 479 | I915_WRITE(DEIER, de_ier); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 480 | POSTING_READ(DEIER); |
Zou, Nanhai | 2d109a8 | 2009-11-06 02:13:01 +0000 | [diff] [blame] | 481 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 482 | return ret; |
| 483 | } |
| 484 | |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 485 | /** |
| 486 | * i915_error_work_func - do process context error handling work |
| 487 | * @work: work struct |
| 488 | * |
| 489 | * Fire an error uevent so userspace can see that a hang or error |
| 490 | * was detected. |
| 491 | */ |
| 492 | static void i915_error_work_func(struct work_struct *work) |
| 493 | { |
| 494 | drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, |
| 495 | error_work); |
| 496 | struct drm_device *dev = dev_priv->dev; |
Ben Gamari | f316a42 | 2009-09-14 17:48:46 -0400 | [diff] [blame] | 497 | char *error_event[] = { "ERROR=1", NULL }; |
| 498 | char *reset_event[] = { "RESET=1", NULL }; |
| 499 | char *reset_done_event[] = { "ERROR=0", NULL }; |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 500 | |
Ben Gamari | f316a42 | 2009-09-14 17:48:46 -0400 | [diff] [blame] | 501 | kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 502 | |
Ben Gamari | ba1234d | 2009-09-14 17:48:47 -0400 | [diff] [blame] | 503 | if (atomic_read(&dev_priv->mm.wedged)) { |
Chris Wilson | f803aa5 | 2010-09-19 12:38:26 +0100 | [diff] [blame] | 504 | DRM_DEBUG_DRIVER("resetting chip\n"); |
| 505 | kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_event); |
| 506 | if (!i915_reset(dev, GRDOM_RENDER)) { |
| 507 | atomic_set(&dev_priv->mm.wedged, 0); |
| 508 | kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_done_event); |
Ben Gamari | f316a42 | 2009-09-14 17:48:46 -0400 | [diff] [blame] | 509 | } |
Chris Wilson | 30dbf0c | 2010-09-25 10:19:17 +0100 | [diff] [blame] | 510 | complete_all(&dev_priv->error_completion); |
Ben Gamari | f316a42 | 2009-09-14 17:48:46 -0400 | [diff] [blame] | 511 | } |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 512 | } |
| 513 | |
Chris Wilson | 3bd3c93 | 2010-08-19 08:19:30 +0100 | [diff] [blame] | 514 | #ifdef CONFIG_DEBUG_FS |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 515 | static struct drm_i915_error_object * |
| 516 | i915_error_object_create(struct drm_device *dev, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 517 | struct drm_i915_gem_object *src) |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 518 | { |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 519 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 520 | struct drm_i915_error_object *dst; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 521 | int page, page_count; |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 522 | u32 reloc_offset; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 523 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 524 | if (src == NULL || src->pages == NULL) |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 525 | return NULL; |
| 526 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 527 | page_count = src->base.size / PAGE_SIZE; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 528 | |
| 529 | dst = kmalloc(sizeof(*dst) + page_count * sizeof (u32 *), GFP_ATOMIC); |
| 530 | if (dst == NULL) |
| 531 | return NULL; |
| 532 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 533 | reloc_offset = src->gtt_offset; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 534 | for (page = 0; page < page_count; page++) { |
Andrew Morton | 788885a | 2010-05-11 14:07:05 -0700 | [diff] [blame] | 535 | unsigned long flags; |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 536 | void __iomem *s; |
| 537 | void *d; |
Andrew Morton | 788885a | 2010-05-11 14:07:05 -0700 | [diff] [blame] | 538 | |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 539 | d = kmalloc(PAGE_SIZE, GFP_ATOMIC); |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 540 | if (d == NULL) |
| 541 | goto unwind; |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 542 | |
Andrew Morton | 788885a | 2010-05-11 14:07:05 -0700 | [diff] [blame] | 543 | local_irq_save(flags); |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 544 | s = io_mapping_map_atomic_wc(dev_priv->mm.gtt_mapping, |
Peter Zijlstra | 3e4d3af | 2010-10-26 14:21:51 -0700 | [diff] [blame] | 545 | reloc_offset); |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 546 | memcpy_fromio(d, s, PAGE_SIZE); |
Peter Zijlstra | 3e4d3af | 2010-10-26 14:21:51 -0700 | [diff] [blame] | 547 | io_mapping_unmap_atomic(s); |
Andrew Morton | 788885a | 2010-05-11 14:07:05 -0700 | [diff] [blame] | 548 | local_irq_restore(flags); |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 549 | |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 550 | dst->pages[page] = d; |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 551 | |
| 552 | reloc_offset += PAGE_SIZE; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 553 | } |
| 554 | dst->page_count = page_count; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 555 | dst->gtt_offset = src->gtt_offset; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 556 | |
| 557 | return dst; |
| 558 | |
| 559 | unwind: |
| 560 | while (page--) |
| 561 | kfree(dst->pages[page]); |
| 562 | kfree(dst); |
| 563 | return NULL; |
| 564 | } |
| 565 | |
| 566 | static void |
| 567 | i915_error_object_free(struct drm_i915_error_object *obj) |
| 568 | { |
| 569 | int page; |
| 570 | |
| 571 | if (obj == NULL) |
| 572 | return; |
| 573 | |
| 574 | for (page = 0; page < obj->page_count; page++) |
| 575 | kfree(obj->pages[page]); |
| 576 | |
| 577 | kfree(obj); |
| 578 | } |
| 579 | |
| 580 | static void |
| 581 | i915_error_state_free(struct drm_device *dev, |
| 582 | struct drm_i915_error_state *error) |
| 583 | { |
| 584 | i915_error_object_free(error->batchbuffer[0]); |
| 585 | i915_error_object_free(error->batchbuffer[1]); |
| 586 | i915_error_object_free(error->ringbuffer); |
| 587 | kfree(error->active_bo); |
Chris Wilson | 6ef3d42 | 2010-08-04 20:26:07 +0100 | [diff] [blame] | 588 | kfree(error->overlay); |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 589 | kfree(error); |
| 590 | } |
| 591 | |
| 592 | static u32 |
| 593 | i915_get_bbaddr(struct drm_device *dev, u32 *ring) |
| 594 | { |
| 595 | u32 cmd; |
| 596 | |
| 597 | if (IS_I830(dev) || IS_845G(dev)) |
| 598 | cmd = MI_BATCH_BUFFER; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 599 | else if (INTEL_INFO(dev)->gen >= 4) |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 600 | cmd = (MI_BATCH_BUFFER_START | (2 << 6) | |
| 601 | MI_BATCH_NON_SECURE_I965); |
| 602 | else |
| 603 | cmd = (MI_BATCH_BUFFER_START | (2 << 6)); |
| 604 | |
| 605 | return ring[0] == cmd ? ring[1] : 0; |
| 606 | } |
| 607 | |
| 608 | static u32 |
Chris Wilson | 8168bd4 | 2010-11-11 17:54:52 +0000 | [diff] [blame] | 609 | i915_ringbuffer_last_batch(struct drm_device *dev, |
| 610 | struct intel_ring_buffer *ring) |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 611 | { |
| 612 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 613 | u32 head, bbaddr; |
Chris Wilson | 8168bd4 | 2010-11-11 17:54:52 +0000 | [diff] [blame] | 614 | u32 *val; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 615 | |
| 616 | /* Locate the current position in the ringbuffer and walk back |
| 617 | * to find the most recently dispatched batch buffer. |
| 618 | */ |
Chris Wilson | 8168bd4 | 2010-11-11 17:54:52 +0000 | [diff] [blame] | 619 | head = I915_READ_HEAD(ring) & HEAD_ADDR; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 620 | |
Chris Wilson | ab5793a | 2010-11-22 13:24:13 +0000 | [diff] [blame] | 621 | val = (u32 *)(ring->virtual_start + head); |
Chris Wilson | 8168bd4 | 2010-11-11 17:54:52 +0000 | [diff] [blame] | 622 | while (--val >= (u32 *)ring->virtual_start) { |
| 623 | bbaddr = i915_get_bbaddr(dev, val); |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 624 | if (bbaddr) |
Chris Wilson | ab5793a | 2010-11-22 13:24:13 +0000 | [diff] [blame] | 625 | return bbaddr; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 626 | } |
| 627 | |
Chris Wilson | ab5793a | 2010-11-22 13:24:13 +0000 | [diff] [blame] | 628 | val = (u32 *)(ring->virtual_start + ring->size); |
| 629 | while (--val >= (u32 *)ring->virtual_start) { |
| 630 | bbaddr = i915_get_bbaddr(dev, val); |
| 631 | if (bbaddr) |
| 632 | return bbaddr; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 633 | } |
| 634 | |
Chris Wilson | ab5793a | 2010-11-22 13:24:13 +0000 | [diff] [blame] | 635 | return 0; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 636 | } |
| 637 | |
Chris Wilson | c724e8a | 2010-11-22 08:07:02 +0000 | [diff] [blame] | 638 | static u32 capture_bo_list(struct drm_i915_error_buffer *err, |
| 639 | int count, |
| 640 | struct list_head *head) |
| 641 | { |
| 642 | struct drm_i915_gem_object *obj; |
| 643 | int i = 0; |
| 644 | |
| 645 | list_for_each_entry(obj, head, mm_list) { |
| 646 | err->size = obj->base.size; |
| 647 | err->name = obj->base.name; |
| 648 | err->seqno = obj->last_rendering_seqno; |
| 649 | err->gtt_offset = obj->gtt_offset; |
| 650 | err->read_domains = obj->base.read_domains; |
| 651 | err->write_domain = obj->base.write_domain; |
| 652 | err->fence_reg = obj->fence_reg; |
| 653 | err->pinned = 0; |
| 654 | if (obj->pin_count > 0) |
| 655 | err->pinned = 1; |
| 656 | if (obj->user_pin_count > 0) |
| 657 | err->pinned = -1; |
| 658 | err->tiling = obj->tiling_mode; |
| 659 | err->dirty = obj->dirty; |
| 660 | err->purgeable = obj->madv != I915_MADV_WILLNEED; |
Chris Wilson | 3685092 | 2010-11-23 08:49:38 +0000 | [diff] [blame] | 661 | err->ring = obj->ring ? obj->ring->id : 0; |
Chris Wilson | c724e8a | 2010-11-22 08:07:02 +0000 | [diff] [blame] | 662 | |
| 663 | if (++i == count) |
| 664 | break; |
| 665 | |
| 666 | err++; |
| 667 | } |
| 668 | |
| 669 | return i; |
| 670 | } |
| 671 | |
Chris Wilson | 748ebc6 | 2010-10-24 10:28:47 +0100 | [diff] [blame] | 672 | static void i915_gem_record_fences(struct drm_device *dev, |
| 673 | struct drm_i915_error_state *error) |
| 674 | { |
| 675 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 676 | int i; |
| 677 | |
| 678 | /* Fences */ |
| 679 | switch (INTEL_INFO(dev)->gen) { |
| 680 | case 6: |
| 681 | for (i = 0; i < 16; i++) |
| 682 | error->fence[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 + (i * 8)); |
| 683 | break; |
| 684 | case 5: |
| 685 | case 4: |
| 686 | for (i = 0; i < 16; i++) |
| 687 | error->fence[i] = I915_READ64(FENCE_REG_965_0 + (i * 8)); |
| 688 | break; |
| 689 | case 3: |
| 690 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) |
| 691 | for (i = 0; i < 8; i++) |
| 692 | error->fence[i+8] = I915_READ(FENCE_REG_945_8 + (i * 4)); |
| 693 | case 2: |
| 694 | for (i = 0; i < 8; i++) |
| 695 | error->fence[i] = I915_READ(FENCE_REG_830_0 + (i * 4)); |
| 696 | break; |
| 697 | |
| 698 | } |
| 699 | } |
| 700 | |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 701 | /** |
| 702 | * i915_capture_error_state - capture an error record for later analysis |
| 703 | * @dev: drm device |
| 704 | * |
| 705 | * Should be called when an error is detected (either a hang or an error |
| 706 | * interrupt) to capture error state from the time of the error. Fills |
| 707 | * out a structure which becomes available in debugfs for user level tools |
| 708 | * to pick up. |
| 709 | */ |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 710 | static void i915_capture_error_state(struct drm_device *dev) |
| 711 | { |
| 712 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 713 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 714 | struct drm_i915_error_state *error; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 715 | struct drm_i915_gem_object *batchbuffer[2]; |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 716 | unsigned long flags; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 717 | u32 bbaddr; |
| 718 | int count; |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 719 | |
| 720 | spin_lock_irqsave(&dev_priv->error_lock, flags); |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 721 | error = dev_priv->first_error; |
| 722 | spin_unlock_irqrestore(&dev_priv->error_lock, flags); |
| 723 | if (error) |
| 724 | return; |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 725 | |
| 726 | error = kmalloc(sizeof(*error), GFP_ATOMIC); |
| 727 | if (!error) { |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 728 | DRM_DEBUG_DRIVER("out of memory, not capturing error state\n"); |
| 729 | return; |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Chris Wilson | 2fa772f3 | 2010-10-01 13:23:27 +0100 | [diff] [blame] | 732 | DRM_DEBUG_DRIVER("generating error event\n"); |
| 733 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 734 | error->seqno = dev_priv->ring[RCS].get_seqno(&dev_priv->ring[RCS]); |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 735 | error->eir = I915_READ(EIR); |
| 736 | error->pgtbl_er = I915_READ(PGTBL_ER); |
| 737 | error->pipeastat = I915_READ(PIPEASTAT); |
| 738 | error->pipebstat = I915_READ(PIPEBSTAT); |
| 739 | error->instpm = I915_READ(INSTPM); |
Chris Wilson | f406839 | 2010-10-27 20:36:41 +0100 | [diff] [blame] | 740 | error->error = 0; |
| 741 | if (INTEL_INFO(dev)->gen >= 6) { |
| 742 | error->error = I915_READ(ERROR_GEN6); |
Chris Wilson | add354d | 2010-10-29 19:00:51 +0100 | [diff] [blame] | 743 | |
Chris Wilson | 1d8f38f | 2010-10-29 19:00:51 +0100 | [diff] [blame] | 744 | error->bcs_acthd = I915_READ(BCS_ACTHD); |
| 745 | error->bcs_ipehr = I915_READ(BCS_IPEHR); |
| 746 | error->bcs_ipeir = I915_READ(BCS_IPEIR); |
| 747 | error->bcs_instdone = I915_READ(BCS_INSTDONE); |
| 748 | error->bcs_seqno = 0; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 749 | if (dev_priv->ring[BCS].get_seqno) |
| 750 | error->bcs_seqno = dev_priv->ring[BCS].get_seqno(&dev_priv->ring[BCS]); |
Chris Wilson | add354d | 2010-10-29 19:00:51 +0100 | [diff] [blame] | 751 | |
| 752 | error->vcs_acthd = I915_READ(VCS_ACTHD); |
| 753 | error->vcs_ipehr = I915_READ(VCS_IPEHR); |
| 754 | error->vcs_ipeir = I915_READ(VCS_IPEIR); |
| 755 | error->vcs_instdone = I915_READ(VCS_INSTDONE); |
| 756 | error->vcs_seqno = 0; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 757 | if (dev_priv->ring[VCS].get_seqno) |
| 758 | error->vcs_seqno = dev_priv->ring[VCS].get_seqno(&dev_priv->ring[VCS]); |
Chris Wilson | f406839 | 2010-10-27 20:36:41 +0100 | [diff] [blame] | 759 | } |
| 760 | if (INTEL_INFO(dev)->gen >= 4) { |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 761 | error->ipeir = I915_READ(IPEIR_I965); |
| 762 | error->ipehr = I915_READ(IPEHR_I965); |
| 763 | error->instdone = I915_READ(INSTDONE_I965); |
| 764 | error->instps = I915_READ(INSTPS); |
| 765 | error->instdone1 = I915_READ(INSTDONE1); |
| 766 | error->acthd = I915_READ(ACTHD_I965); |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 767 | error->bbaddr = I915_READ64(BB_ADDR); |
Chris Wilson | f406839 | 2010-10-27 20:36:41 +0100 | [diff] [blame] | 768 | } else { |
| 769 | error->ipeir = I915_READ(IPEIR); |
| 770 | error->ipehr = I915_READ(IPEHR); |
| 771 | error->instdone = I915_READ(INSTDONE); |
| 772 | error->acthd = I915_READ(ACTHD); |
| 773 | error->bbaddr = 0; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 774 | } |
Chris Wilson | 748ebc6 | 2010-10-24 10:28:47 +0100 | [diff] [blame] | 775 | i915_gem_record_fences(dev, error); |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 776 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 777 | bbaddr = i915_ringbuffer_last_batch(dev, &dev_priv->ring[RCS]); |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 778 | |
| 779 | /* Grab the current batchbuffer, most likely to have crashed. */ |
| 780 | batchbuffer[0] = NULL; |
| 781 | batchbuffer[1] = NULL; |
| 782 | count = 0; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 783 | list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list) { |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 784 | if (batchbuffer[0] == NULL && |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 785 | bbaddr >= obj->gtt_offset && |
| 786 | bbaddr < obj->gtt_offset + obj->base.size) |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 787 | batchbuffer[0] = obj; |
| 788 | |
| 789 | if (batchbuffer[1] == NULL && |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 790 | error->acthd >= obj->gtt_offset && |
| 791 | error->acthd < obj->gtt_offset + obj->base.size) |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 792 | batchbuffer[1] = obj; |
| 793 | |
| 794 | count++; |
| 795 | } |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 796 | /* Scan the other lists for completeness for those bizarre errors. */ |
| 797 | if (batchbuffer[0] == NULL || batchbuffer[1] == NULL) { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 798 | list_for_each_entry(obj, &dev_priv->mm.flushing_list, mm_list) { |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 799 | if (batchbuffer[0] == NULL && |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 800 | bbaddr >= obj->gtt_offset && |
| 801 | bbaddr < obj->gtt_offset + obj->base.size) |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 802 | batchbuffer[0] = obj; |
| 803 | |
| 804 | if (batchbuffer[1] == NULL && |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 805 | error->acthd >= obj->gtt_offset && |
| 806 | error->acthd < obj->gtt_offset + obj->base.size) |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 807 | batchbuffer[1] = obj; |
| 808 | |
| 809 | if (batchbuffer[0] && batchbuffer[1]) |
| 810 | break; |
| 811 | } |
| 812 | } |
| 813 | if (batchbuffer[0] == NULL || batchbuffer[1] == NULL) { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 814 | list_for_each_entry(obj, &dev_priv->mm.inactive_list, mm_list) { |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 815 | if (batchbuffer[0] == NULL && |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 816 | bbaddr >= obj->gtt_offset && |
| 817 | bbaddr < obj->gtt_offset + obj->base.size) |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 818 | batchbuffer[0] = obj; |
| 819 | |
| 820 | if (batchbuffer[1] == NULL && |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 821 | error->acthd >= obj->gtt_offset && |
| 822 | error->acthd < obj->gtt_offset + obj->base.size) |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 823 | batchbuffer[1] = obj; |
| 824 | |
| 825 | if (batchbuffer[0] && batchbuffer[1]) |
| 826 | break; |
| 827 | } |
| 828 | } |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 829 | |
| 830 | /* We need to copy these to an anonymous buffer as the simplest |
Andrea Gelmini | 139d363 | 2010-10-15 17:14:33 +0200 | [diff] [blame] | 831 | * method to avoid being overwritten by userspace. |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 832 | */ |
| 833 | error->batchbuffer[0] = i915_error_object_create(dev, batchbuffer[0]); |
Chris Wilson | e56660d | 2010-08-07 11:01:26 +0100 | [diff] [blame] | 834 | if (batchbuffer[1] != batchbuffer[0]) |
| 835 | error->batchbuffer[1] = i915_error_object_create(dev, batchbuffer[1]); |
| 836 | else |
| 837 | error->batchbuffer[1] = NULL; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 838 | |
| 839 | /* Record the ringbuffer */ |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 840 | error->ringbuffer = i915_error_object_create(dev, |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 841 | dev_priv->ring[RCS].obj); |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 842 | |
Chris Wilson | c724e8a | 2010-11-22 08:07:02 +0000 | [diff] [blame] | 843 | /* Record buffers on the active and pinned lists. */ |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 844 | error->active_bo = NULL; |
Chris Wilson | c724e8a | 2010-11-22 08:07:02 +0000 | [diff] [blame] | 845 | error->pinned_bo = NULL; |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 846 | |
Chris Wilson | c724e8a | 2010-11-22 08:07:02 +0000 | [diff] [blame] | 847 | error->active_bo_count = count; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 848 | list_for_each_entry(obj, &dev_priv->mm.pinned_list, mm_list) |
Chris Wilson | c724e8a | 2010-11-22 08:07:02 +0000 | [diff] [blame] | 849 | count++; |
| 850 | error->pinned_bo_count = count - error->active_bo_count; |
| 851 | |
| 852 | if (count) { |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 853 | error->active_bo = kmalloc(sizeof(*error->active_bo)*count, |
| 854 | GFP_ATOMIC); |
Chris Wilson | c724e8a | 2010-11-22 08:07:02 +0000 | [diff] [blame] | 855 | if (error->active_bo) |
| 856 | error->pinned_bo = |
| 857 | error->active_bo + error->active_bo_count; |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 858 | } |
| 859 | |
Chris Wilson | c724e8a | 2010-11-22 08:07:02 +0000 | [diff] [blame] | 860 | if (error->active_bo) |
| 861 | error->active_bo_count = |
| 862 | capture_bo_list(error->active_bo, |
| 863 | error->active_bo_count, |
| 864 | &dev_priv->mm.active_list); |
| 865 | |
| 866 | if (error->pinned_bo) |
| 867 | error->pinned_bo_count = |
| 868 | capture_bo_list(error->pinned_bo, |
| 869 | error->pinned_bo_count, |
| 870 | &dev_priv->mm.pinned_list); |
| 871 | |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 872 | do_gettimeofday(&error->time); |
| 873 | |
Chris Wilson | 6ef3d42 | 2010-08-04 20:26:07 +0100 | [diff] [blame] | 874 | error->overlay = intel_overlay_capture_error_state(dev); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 875 | error->display = intel_display_capture_error_state(dev); |
Chris Wilson | 6ef3d42 | 2010-08-04 20:26:07 +0100 | [diff] [blame] | 876 | |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 877 | spin_lock_irqsave(&dev_priv->error_lock, flags); |
| 878 | if (dev_priv->first_error == NULL) { |
| 879 | dev_priv->first_error = error; |
| 880 | error = NULL; |
| 881 | } |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 882 | spin_unlock_irqrestore(&dev_priv->error_lock, flags); |
Chris Wilson | 9df3079 | 2010-02-18 10:24:56 +0000 | [diff] [blame] | 883 | |
| 884 | if (error) |
| 885 | i915_error_state_free(dev, error); |
| 886 | } |
| 887 | |
| 888 | void i915_destroy_error_state(struct drm_device *dev) |
| 889 | { |
| 890 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 891 | struct drm_i915_error_state *error; |
| 892 | |
| 893 | spin_lock(&dev_priv->error_lock); |
| 894 | error = dev_priv->first_error; |
| 895 | dev_priv->first_error = NULL; |
| 896 | spin_unlock(&dev_priv->error_lock); |
| 897 | |
| 898 | if (error) |
| 899 | i915_error_state_free(dev, error); |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 900 | } |
Chris Wilson | 3bd3c93 | 2010-08-19 08:19:30 +0100 | [diff] [blame] | 901 | #else |
| 902 | #define i915_capture_error_state(x) |
| 903 | #endif |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 904 | |
Chris Wilson | 35aed2e | 2010-05-27 13:18:12 +0100 | [diff] [blame] | 905 | static void i915_report_and_clear_eir(struct drm_device *dev) |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 906 | { |
| 907 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 908 | u32 eir = I915_READ(EIR); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 909 | |
Chris Wilson | 35aed2e | 2010-05-27 13:18:12 +0100 | [diff] [blame] | 910 | if (!eir) |
| 911 | return; |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 912 | |
| 913 | printk(KERN_ERR "render error detected, EIR: 0x%08x\n", |
| 914 | eir); |
| 915 | |
| 916 | if (IS_G4X(dev)) { |
| 917 | if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) { |
| 918 | u32 ipeir = I915_READ(IPEIR_I965); |
| 919 | |
| 920 | printk(KERN_ERR " IPEIR: 0x%08x\n", |
| 921 | I915_READ(IPEIR_I965)); |
| 922 | printk(KERN_ERR " IPEHR: 0x%08x\n", |
| 923 | I915_READ(IPEHR_I965)); |
| 924 | printk(KERN_ERR " INSTDONE: 0x%08x\n", |
| 925 | I915_READ(INSTDONE_I965)); |
| 926 | printk(KERN_ERR " INSTPS: 0x%08x\n", |
| 927 | I915_READ(INSTPS)); |
| 928 | printk(KERN_ERR " INSTDONE1: 0x%08x\n", |
| 929 | I915_READ(INSTDONE1)); |
| 930 | printk(KERN_ERR " ACTHD: 0x%08x\n", |
| 931 | I915_READ(ACTHD_I965)); |
| 932 | I915_WRITE(IPEIR_I965, ipeir); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 933 | POSTING_READ(IPEIR_I965); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 934 | } |
| 935 | if (eir & GM45_ERROR_PAGE_TABLE) { |
| 936 | u32 pgtbl_err = I915_READ(PGTBL_ER); |
| 937 | printk(KERN_ERR "page table error\n"); |
| 938 | printk(KERN_ERR " PGTBL_ER: 0x%08x\n", |
| 939 | pgtbl_err); |
| 940 | I915_WRITE(PGTBL_ER, pgtbl_err); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 941 | POSTING_READ(PGTBL_ER); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 942 | } |
| 943 | } |
| 944 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 945 | if (!IS_GEN2(dev)) { |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 946 | if (eir & I915_ERROR_PAGE_TABLE) { |
| 947 | u32 pgtbl_err = I915_READ(PGTBL_ER); |
| 948 | printk(KERN_ERR "page table error\n"); |
| 949 | printk(KERN_ERR " PGTBL_ER: 0x%08x\n", |
| 950 | pgtbl_err); |
| 951 | I915_WRITE(PGTBL_ER, pgtbl_err); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 952 | POSTING_READ(PGTBL_ER); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | |
| 956 | if (eir & I915_ERROR_MEMORY_REFRESH) { |
Chris Wilson | 35aed2e | 2010-05-27 13:18:12 +0100 | [diff] [blame] | 957 | u32 pipea_stats = I915_READ(PIPEASTAT); |
| 958 | u32 pipeb_stats = I915_READ(PIPEBSTAT); |
| 959 | |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 960 | printk(KERN_ERR "memory refresh error\n"); |
| 961 | printk(KERN_ERR "PIPEASTAT: 0x%08x\n", |
| 962 | pipea_stats); |
| 963 | printk(KERN_ERR "PIPEBSTAT: 0x%08x\n", |
| 964 | pipeb_stats); |
| 965 | /* pipestat has already been acked */ |
| 966 | } |
| 967 | if (eir & I915_ERROR_INSTRUCTION) { |
| 968 | printk(KERN_ERR "instruction error\n"); |
| 969 | printk(KERN_ERR " INSTPM: 0x%08x\n", |
| 970 | I915_READ(INSTPM)); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 971 | if (INTEL_INFO(dev)->gen < 4) { |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 972 | u32 ipeir = I915_READ(IPEIR); |
| 973 | |
| 974 | printk(KERN_ERR " IPEIR: 0x%08x\n", |
| 975 | I915_READ(IPEIR)); |
| 976 | printk(KERN_ERR " IPEHR: 0x%08x\n", |
| 977 | I915_READ(IPEHR)); |
| 978 | printk(KERN_ERR " INSTDONE: 0x%08x\n", |
| 979 | I915_READ(INSTDONE)); |
| 980 | printk(KERN_ERR " ACTHD: 0x%08x\n", |
| 981 | I915_READ(ACTHD)); |
| 982 | I915_WRITE(IPEIR, ipeir); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 983 | POSTING_READ(IPEIR); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 984 | } else { |
| 985 | u32 ipeir = I915_READ(IPEIR_I965); |
| 986 | |
| 987 | printk(KERN_ERR " IPEIR: 0x%08x\n", |
| 988 | I915_READ(IPEIR_I965)); |
| 989 | printk(KERN_ERR " IPEHR: 0x%08x\n", |
| 990 | I915_READ(IPEHR_I965)); |
| 991 | printk(KERN_ERR " INSTDONE: 0x%08x\n", |
| 992 | I915_READ(INSTDONE_I965)); |
| 993 | printk(KERN_ERR " INSTPS: 0x%08x\n", |
| 994 | I915_READ(INSTPS)); |
| 995 | printk(KERN_ERR " INSTDONE1: 0x%08x\n", |
| 996 | I915_READ(INSTDONE1)); |
| 997 | printk(KERN_ERR " ACTHD: 0x%08x\n", |
| 998 | I915_READ(ACTHD_I965)); |
| 999 | I915_WRITE(IPEIR_I965, ipeir); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 1000 | POSTING_READ(IPEIR_I965); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | I915_WRITE(EIR, eir); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 1005 | POSTING_READ(EIR); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1006 | eir = I915_READ(EIR); |
| 1007 | if (eir) { |
| 1008 | /* |
| 1009 | * some errors might have become stuck, |
| 1010 | * mask them. |
| 1011 | */ |
| 1012 | DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir); |
| 1013 | I915_WRITE(EMR, I915_READ(EMR) | eir); |
| 1014 | I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); |
| 1015 | } |
Chris Wilson | 35aed2e | 2010-05-27 13:18:12 +0100 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | /** |
| 1019 | * i915_handle_error - handle an error interrupt |
| 1020 | * @dev: drm device |
| 1021 | * |
| 1022 | * Do some basic checking of regsiter state at error interrupt time and |
| 1023 | * dump it to the syslog. Also call i915_capture_error_state() to make |
| 1024 | * sure we get a record and make it available in debugfs. Fire a uevent |
| 1025 | * so userspace knows something bad happened (should trigger collection |
| 1026 | * of a ring dump etc.). |
| 1027 | */ |
Chris Wilson | 527f9e9 | 2010-11-11 01:16:58 +0000 | [diff] [blame] | 1028 | void i915_handle_error(struct drm_device *dev, bool wedged) |
Chris Wilson | 35aed2e | 2010-05-27 13:18:12 +0100 | [diff] [blame] | 1029 | { |
| 1030 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1031 | |
| 1032 | i915_capture_error_state(dev); |
| 1033 | i915_report_and_clear_eir(dev); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1034 | |
Ben Gamari | ba1234d | 2009-09-14 17:48:47 -0400 | [diff] [blame] | 1035 | if (wedged) { |
Chris Wilson | 30dbf0c | 2010-09-25 10:19:17 +0100 | [diff] [blame] | 1036 | INIT_COMPLETION(dev_priv->error_completion); |
Ben Gamari | ba1234d | 2009-09-14 17:48:47 -0400 | [diff] [blame] | 1037 | atomic_set(&dev_priv->mm.wedged, 1); |
| 1038 | |
Ben Gamari | 11ed50e | 2009-09-14 17:48:45 -0400 | [diff] [blame] | 1039 | /* |
| 1040 | * Wakeup waiting processes so they don't hang |
| 1041 | */ |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1042 | wake_up_all(&dev_priv->ring[RCS].irq_queue); |
Chris Wilson | f787a5f | 2010-09-24 16:02:42 +0100 | [diff] [blame] | 1043 | if (HAS_BSD(dev)) |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1044 | wake_up_all(&dev_priv->ring[VCS].irq_queue); |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1045 | if (HAS_BLT(dev)) |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1046 | wake_up_all(&dev_priv->ring[BCS].irq_queue); |
Ben Gamari | 11ed50e | 2009-09-14 17:48:45 -0400 | [diff] [blame] | 1047 | } |
| 1048 | |
Eric Anholt | 9c9fe1f | 2009-08-03 16:09:16 -0700 | [diff] [blame] | 1049 | queue_work(dev_priv->wq, &dev_priv->error_work); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1050 | } |
| 1051 | |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 1052 | static void i915_pageflip_stall_check(struct drm_device *dev, int pipe) |
| 1053 | { |
| 1054 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 1055 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 1056 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1057 | struct drm_i915_gem_object *obj; |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 1058 | struct intel_unpin_work *work; |
| 1059 | unsigned long flags; |
| 1060 | bool stall_detected; |
| 1061 | |
| 1062 | /* Ignore early vblank irqs */ |
| 1063 | if (intel_crtc == NULL) |
| 1064 | return; |
| 1065 | |
| 1066 | spin_lock_irqsave(&dev->event_lock, flags); |
| 1067 | work = intel_crtc->unpin_work; |
| 1068 | |
| 1069 | if (work == NULL || work->pending || !work->enable_stall_check) { |
| 1070 | /* Either the pending flip IRQ arrived, or we're too early. Don't check */ |
| 1071 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 1072 | return; |
| 1073 | } |
| 1074 | |
| 1075 | /* 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] | 1076 | obj = work->pending_flip_obj; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1077 | if (INTEL_INFO(dev)->gen >= 4) { |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 1078 | int dspsurf = intel_crtc->plane == 0 ? DSPASURF : DSPBSURF; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1079 | stall_detected = I915_READ(dspsurf) == obj->gtt_offset; |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 1080 | } else { |
| 1081 | int dspaddr = intel_crtc->plane == 0 ? DSPAADDR : DSPBADDR; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1082 | stall_detected = I915_READ(dspaddr) == (obj->gtt_offset + |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 1083 | crtc->y * crtc->fb->pitch + |
| 1084 | crtc->x * crtc->fb->bits_per_pixel/8); |
| 1085 | } |
| 1086 | |
| 1087 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 1088 | |
| 1089 | if (stall_detected) { |
| 1090 | DRM_DEBUG_DRIVER("Pageflip stall detected\n"); |
| 1091 | intel_prepare_page_flip(dev, intel_crtc->plane); |
| 1092 | } |
| 1093 | } |
| 1094 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS) |
| 1096 | { |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1097 | struct drm_device *dev = (struct drm_device *) arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | 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] | 1099 | struct drm_i915_master_private *master_priv; |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 1100 | u32 iir, new_iir; |
| 1101 | u32 pipea_stats, pipeb_stats; |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 1102 | u32 vblank_status; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1103 | int vblank = 0; |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1104 | unsigned long irqflags; |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 1105 | int irq_received; |
| 1106 | int ret = IRQ_NONE; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 1107 | |
Eric Anholt | 630681d | 2008-10-06 15:14:12 -0700 | [diff] [blame] | 1108 | atomic_inc(&dev_priv->irq_received); |
| 1109 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 1110 | if (HAS_PCH_SPLIT(dev)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 1111 | return ironlake_irq_handler(dev); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1112 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1113 | iir = I915_READ(IIR); |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 1114 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1115 | if (INTEL_INFO(dev)->gen >= 4) |
Jesse Barnes | d874bcf | 2010-06-30 13:16:00 -0700 | [diff] [blame] | 1116 | vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS; |
Jesse Barnes | e25e660 | 2010-06-30 13:15:19 -0700 | [diff] [blame] | 1117 | else |
Jesse Barnes | d874bcf | 2010-06-30 13:16:00 -0700 | [diff] [blame] | 1118 | vblank_status = PIPE_VBLANK_INTERRUPT_STATUS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 1120 | for (;;) { |
| 1121 | irq_received = iir != 0; |
| 1122 | |
| 1123 | /* Can't rely on pipestat interrupt bit in iir as it might |
| 1124 | * have been cleared after the pipestat interrupt was received. |
| 1125 | * It doesn't set the bit in iir again, but it still produces |
| 1126 | * interrupts (for non-MSI). |
| 1127 | */ |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1128 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 1129 | pipea_stats = I915_READ(PIPEASTAT); |
| 1130 | pipeb_stats = I915_READ(PIPEBSTAT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1131 | |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1132 | if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) |
Ben Gamari | ba1234d | 2009-09-14 17:48:47 -0400 | [diff] [blame] | 1133 | i915_handle_error(dev, false); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1134 | |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 1135 | /* |
| 1136 | * Clear the PIPE(A|B)STAT regs before the IIR |
| 1137 | */ |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 1138 | if (pipea_stats & 0x8000ffff) { |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 1139 | if (pipea_stats & PIPE_FIFO_UNDERRUN_STATUS) |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 1140 | DRM_DEBUG_DRIVER("pipe a underrun\n"); |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 1141 | I915_WRITE(PIPEASTAT, pipea_stats); |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 1142 | irq_received = 1; |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 1143 | } |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1144 | |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 1145 | if (pipeb_stats & 0x8000ffff) { |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 1146 | if (pipeb_stats & PIPE_FIFO_UNDERRUN_STATUS) |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 1147 | DRM_DEBUG_DRIVER("pipe b underrun\n"); |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 1148 | I915_WRITE(PIPEBSTAT, pipeb_stats); |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 1149 | irq_received = 1; |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 1150 | } |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1151 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 1152 | |
| 1153 | if (!irq_received) |
| 1154 | break; |
| 1155 | |
| 1156 | ret = IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 1158 | /* Consume port. Then clear IIR or we'll miss events */ |
| 1159 | if ((I915_HAS_HOTPLUG(dev)) && |
| 1160 | (iir & I915_DISPLAY_PORT_INTERRUPT)) { |
| 1161 | u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); |
| 1162 | |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 1163 | DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n", |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 1164 | hotplug_status); |
| 1165 | if (hotplug_status & dev_priv->hotplug_supported_mask) |
Eric Anholt | 9c9fe1f | 2009-08-03 16:09:16 -0700 | [diff] [blame] | 1166 | queue_work(dev_priv->wq, |
| 1167 | &dev_priv->hotplug_work); |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 1168 | |
| 1169 | I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); |
| 1170 | I915_READ(PORT_HOTPLUG_STAT); |
| 1171 | } |
| 1172 | |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 1173 | I915_WRITE(IIR, iir); |
| 1174 | new_iir = I915_READ(IIR); /* Flush posted writes */ |
Matthew Garrett | 8ee1c3d | 2008-08-05 19:37:25 +0100 | [diff] [blame] | 1175 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1176 | if (dev->primary->master) { |
| 1177 | master_priv = dev->primary->master->driver_priv; |
| 1178 | if (master_priv->sarea_priv) |
| 1179 | master_priv->sarea_priv->last_dispatch = |
| 1180 | READ_BREADCRUMB(dev_priv); |
| 1181 | } |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1182 | |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1183 | if (iir & I915_USER_INTERRUPT) |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1184 | notify_ring(dev, &dev_priv->ring[RCS]); |
| 1185 | if (iir & I915_BSD_USER_INTERRUPT) |
| 1186 | notify_ring(dev, &dev_priv->ring[VCS]); |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 1187 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 1188 | if (iir & I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT) { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1189 | intel_prepare_page_flip(dev, 0); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 1190 | if (dev_priv->flip_pending_is_done) |
| 1191 | intel_finish_page_flip_plane(dev, 0); |
| 1192 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1193 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 1194 | if (iir & I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT) { |
Jesse Barnes | 70565d0 | 2010-07-01 04:45:43 -0700 | [diff] [blame] | 1195 | intel_prepare_page_flip(dev, 1); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 1196 | if (dev_priv->flip_pending_is_done) |
| 1197 | intel_finish_page_flip_plane(dev, 1); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 1198 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1199 | |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 1200 | if (pipea_stats & vblank_status) { |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 1201 | vblank++; |
| 1202 | drm_handle_vblank(dev, 0); |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 1203 | if (!dev_priv->flip_pending_is_done) { |
| 1204 | i915_pageflip_stall_check(dev, 0); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 1205 | intel_finish_page_flip(dev, 0); |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 1206 | } |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 1207 | } |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1208 | |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 1209 | if (pipeb_stats & vblank_status) { |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 1210 | vblank++; |
| 1211 | drm_handle_vblank(dev, 1); |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 1212 | if (!dev_priv->flip_pending_is_done) { |
| 1213 | i915_pageflip_stall_check(dev, 1); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 1214 | intel_finish_page_flip(dev, 1); |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 1215 | } |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 1216 | } |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1217 | |
Jesse Barnes | d874bcf | 2010-06-30 13:16:00 -0700 | [diff] [blame] | 1218 | if ((pipea_stats & PIPE_LEGACY_BLC_EVENT_STATUS) || |
| 1219 | (pipeb_stats & PIPE_LEGACY_BLC_EVENT_STATUS) || |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 1220 | (iir & I915_ASLE_INTERRUPT)) |
Chris Wilson | 3b61796 | 2010-08-24 09:02:58 +0100 | [diff] [blame] | 1221 | intel_opregion_asle_intr(dev); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1222 | |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 1223 | /* With MSI, interrupts are only generated when iir |
| 1224 | * transitions from zero to nonzero. If another bit got |
| 1225 | * set while we were handling the existing iir bits, then |
| 1226 | * we would never get another interrupt. |
| 1227 | * |
| 1228 | * This is fine on non-MSI as well, as if we hit this path |
| 1229 | * we avoid exiting the interrupt handler only to generate |
| 1230 | * another one. |
| 1231 | * |
| 1232 | * Note that for MSI this could cause a stray interrupt report |
| 1233 | * if an interrupt landed in the time between writing IIR and |
| 1234 | * the posting read. This should be rare enough to never |
| 1235 | * trigger the 99% of 100,000 interrupts test for disabling |
| 1236 | * stray interrupts. |
| 1237 | */ |
| 1238 | iir = new_iir; |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 1239 | } |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1240 | |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 1241 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 1244 | static int i915_emit_irq(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | { |
| 1246 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1247 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | |
| 1249 | i915_kernel_lost_context(dev); |
| 1250 | |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 1251 | DRM_DEBUG_DRIVER("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 1253 | dev_priv->counter++; |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 1254 | if (dev_priv->counter > 0x7FFFFFFFUL) |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 1255 | dev_priv->counter = 1; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1256 | if (master_priv->sarea_priv) |
| 1257 | master_priv->sarea_priv->last_enqueue = dev_priv->counter; |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 1258 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 1259 | if (BEGIN_LP_RING(4) == 0) { |
| 1260 | OUT_RING(MI_STORE_DWORD_INDEX); |
| 1261 | OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT); |
| 1262 | OUT_RING(dev_priv->counter); |
| 1263 | OUT_RING(MI_USER_INTERRUPT); |
| 1264 | ADVANCE_LP_RING(); |
| 1265 | } |
Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 1266 | |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 1267 | return dev_priv->counter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
Chris Wilson | 9d34e5d | 2009-09-24 05:26:06 +0100 | [diff] [blame] | 1270 | void i915_trace_irq_get(struct drm_device *dev, u32 seqno) |
| 1271 | { |
| 1272 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1273 | struct intel_ring_buffer *ring = LP_RING(dev_priv); |
Chris Wilson | 9d34e5d | 2009-09-24 05:26:06 +0100 | [diff] [blame] | 1274 | |
Chris Wilson | b13c2b9 | 2010-12-13 16:54:50 +0000 | [diff] [blame] | 1275 | if (dev_priv->trace_irq_seqno == 0 && |
| 1276 | ring->irq_get(ring)) |
| 1277 | dev_priv->trace_irq_seqno = seqno; |
Chris Wilson | 9d34e5d | 2009-09-24 05:26:06 +0100 | [diff] [blame] | 1278 | } |
| 1279 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1280 | static int i915_wait_irq(struct drm_device * dev, int irq_nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | { |
| 1282 | 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] | 1283 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | int ret = 0; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1285 | struct intel_ring_buffer *ring = LP_RING(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 1287 | DRM_DEBUG_DRIVER("irq_nr=%d breadcrumb=%d\n", irq_nr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | READ_BREADCRUMB(dev_priv)); |
| 1289 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1290 | if (READ_BREADCRUMB(dev_priv) >= irq_nr) { |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1291 | if (master_priv->sarea_priv) |
| 1292 | master_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | return 0; |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1294 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1296 | if (master_priv->sarea_priv) |
| 1297 | master_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | |
Chris Wilson | b13c2b9 | 2010-12-13 16:54:50 +0000 | [diff] [blame] | 1299 | ret = -ENODEV; |
| 1300 | if (ring->irq_get(ring)) { |
| 1301 | DRM_WAIT_ON(ret, ring->irq_queue, 3 * DRM_HZ, |
| 1302 | READ_BREADCRUMB(dev_priv) >= irq_nr); |
| 1303 | ring->irq_put(ring); |
| 1304 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1306 | if (ret == -EBUSY) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 1307 | DRM_ERROR("EBUSY -- rec: %d emitted: %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | READ_BREADCRUMB(dev_priv), (int)dev_priv->counter); |
| 1309 | } |
| 1310 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 1311 | return ret; |
| 1312 | } |
| 1313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | /* Needs the lock as it touches the ring. |
| 1315 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1316 | int i915_irq_emit(struct drm_device *dev, void *data, |
| 1317 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1320 | drm_i915_irq_emit_t *emit = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | int result; |
| 1322 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1323 | if (!dev_priv || !LP_RING(dev_priv)->virtual_start) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 1324 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1325 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | } |
Eric Anholt | 299eb93 | 2009-02-24 22:14:12 -0800 | [diff] [blame] | 1327 | |
| 1328 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
| 1329 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 1330 | mutex_lock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | result = i915_emit_irq(dev); |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 1332 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1334 | if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | DRM_ERROR("copy_to_user\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1336 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | return 0; |
| 1340 | } |
| 1341 | |
| 1342 | /* Doesn't need the hardware lock. |
| 1343 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1344 | int i915_irq_wait(struct drm_device *dev, void *data, |
| 1345 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1348 | drm_i915_irq_wait_t *irqwait = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | |
| 1350 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 1351 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1352 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | } |
| 1354 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1355 | return i915_wait_irq(dev, irqwait->irq_seq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | } |
| 1357 | |
Keith Packard | 42f52ef | 2008-10-18 19:39:29 -0700 | [diff] [blame] | 1358 | /* Called from drm generic code, passed 'crtc' which |
| 1359 | * we use as a pipe index |
| 1360 | */ |
| 1361 | int i915_enable_vblank(struct drm_device *dev, int pipe) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1362 | { |
| 1363 | 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] | 1364 | unsigned long irqflags; |
Jesse Barnes | 71e0ffa | 2009-01-08 10:42:15 -0800 | [diff] [blame] | 1365 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1366 | if (!i915_pipe_enabled(dev, pipe)) |
Jesse Barnes | 71e0ffa | 2009-01-08 10:42:15 -0800 | [diff] [blame] | 1367 | return -EINVAL; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1368 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1369 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 1370 | if (HAS_PCH_SPLIT(dev)) |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1371 | ironlake_enable_display_irq(dev_priv, (pipe == 0) ? |
Li Peng | c062df6 | 2010-01-23 00:12:58 +0800 | [diff] [blame] | 1372 | DE_PIPEA_VBLANK: DE_PIPEB_VBLANK); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1373 | else if (INTEL_INFO(dev)->gen >= 4) |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1374 | i915_enable_pipestat(dev_priv, pipe, |
| 1375 | PIPE_START_VBLANK_INTERRUPT_ENABLE); |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 1376 | else |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1377 | i915_enable_pipestat(dev_priv, pipe, |
| 1378 | PIPE_VBLANK_INTERRUPT_ENABLE); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1379 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1380 | return 0; |
| 1381 | } |
| 1382 | |
Keith Packard | 42f52ef | 2008-10-18 19:39:29 -0700 | [diff] [blame] | 1383 | /* Called from drm generic code, passed 'crtc' which |
| 1384 | * we use as a pipe index |
| 1385 | */ |
| 1386 | void i915_disable_vblank(struct drm_device *dev, int pipe) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1387 | { |
| 1388 | 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] | 1389 | unsigned long irqflags; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1390 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1391 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 1392 | if (HAS_PCH_SPLIT(dev)) |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1393 | ironlake_disable_display_irq(dev_priv, (pipe == 0) ? |
Li Peng | c062df6 | 2010-01-23 00:12:58 +0800 | [diff] [blame] | 1394 | DE_PIPEA_VBLANK: DE_PIPEB_VBLANK); |
| 1395 | else |
| 1396 | i915_disable_pipestat(dev_priv, pipe, |
| 1397 | PIPE_VBLANK_INTERRUPT_ENABLE | |
| 1398 | PIPE_START_VBLANK_INTERRUPT_ENABLE); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1399 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1402 | void i915_enable_interrupt (struct drm_device *dev) |
| 1403 | { |
| 1404 | struct drm_i915_private *dev_priv = dev->dev_private; |
Zhenyu Wang | e170b03 | 2009-06-05 15:38:40 +0800 | [diff] [blame] | 1405 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 1406 | if (!HAS_PCH_SPLIT(dev)) |
Chris Wilson | 3b61796 | 2010-08-24 09:02:58 +0100 | [diff] [blame] | 1407 | intel_opregion_enable_asle(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1408 | dev_priv->irq_enabled = 1; |
| 1409 | } |
| 1410 | |
| 1411 | |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1412 | /* Set the vblank monitor pipe |
| 1413 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1414 | int i915_vblank_pipe_set(struct drm_device *dev, void *data, |
| 1415 | struct drm_file *file_priv) |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1416 | { |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1417 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1418 | |
| 1419 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 1420 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1421 | return -EINVAL; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1422 | } |
| 1423 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 5b51694 | 2006-10-25 00:08:23 +1000 | [diff] [blame] | 1424 | return 0; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1425 | } |
| 1426 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1427 | int i915_vblank_pipe_get(struct drm_device *dev, void *data, |
| 1428 | struct drm_file *file_priv) |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1429 | { |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1430 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1431 | drm_i915_vblank_pipe_t *pipe = data; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1432 | |
| 1433 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 1434 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1435 | return -EINVAL; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1436 | } |
| 1437 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1438 | pipe->pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1439 | |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 1440 | return 0; |
| 1441 | } |
| 1442 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 1443 | /** |
| 1444 | * Schedule buffer swap at given vertical blank. |
| 1445 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1446 | int i915_vblank_swap(struct drm_device *dev, void *data, |
| 1447 | struct drm_file *file_priv) |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 1448 | { |
Eric Anholt | bd95e0a | 2008-11-04 12:01:24 -0800 | [diff] [blame] | 1449 | /* The delayed swap mechanism was fundamentally racy, and has been |
| 1450 | * removed. The model was that the client requested a delayed flip/swap |
| 1451 | * from the kernel, then waited for vblank before continuing to perform |
| 1452 | * rendering. The problem was that the kernel might wake the client |
| 1453 | * up before it dispatched the vblank swap (since the lock has to be |
| 1454 | * held while touching the ringbuffer), in which case the client would |
| 1455 | * clear and start the next frame before the swap occurred, and |
| 1456 | * flicker would occur in addition to likely missing the vblank. |
| 1457 | * |
| 1458 | * In the absence of this ioctl, userland falls back to a correct path |
| 1459 | * of waiting for a vblank, then dispatching the swap on its own. |
| 1460 | * Context switching to userland and back is plenty fast enough for |
| 1461 | * meeting the requirements of vblank swapping. |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1462 | */ |
Eric Anholt | bd95e0a | 2008-11-04 12:01:24 -0800 | [diff] [blame] | 1463 | return -EINVAL; |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 1464 | } |
| 1465 | |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 1466 | static u32 |
| 1467 | ring_last_seqno(struct intel_ring_buffer *ring) |
Zou Nan hai | 852835f | 2010-05-21 09:08:56 +0800 | [diff] [blame] | 1468 | { |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 1469 | return list_entry(ring->request_list.prev, |
| 1470 | struct drm_i915_gem_request, list)->seqno; |
| 1471 | } |
| 1472 | |
| 1473 | static bool i915_hangcheck_ring_idle(struct intel_ring_buffer *ring, bool *err) |
| 1474 | { |
| 1475 | if (list_empty(&ring->request_list) || |
| 1476 | i915_seqno_passed(ring->get_seqno(ring), ring_last_seqno(ring))) { |
| 1477 | /* Issue a wake-up to catch stuck h/w. */ |
Chris Wilson | b222349 | 2010-10-27 15:27:33 +0100 | [diff] [blame] | 1478 | if (ring->waiting_seqno && waitqueue_active(&ring->irq_queue)) { |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 1479 | DRM_ERROR("Hangcheck timer elapsed... %s idle [waiting on %d, at %d], missed IRQ?\n", |
| 1480 | ring->name, |
Chris Wilson | b222349 | 2010-10-27 15:27:33 +0100 | [diff] [blame] | 1481 | ring->waiting_seqno, |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 1482 | ring->get_seqno(ring)); |
| 1483 | wake_up_all(&ring->irq_queue); |
| 1484 | *err = true; |
| 1485 | } |
| 1486 | return true; |
| 1487 | } |
| 1488 | return false; |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 1489 | } |
| 1490 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1491 | static bool kick_ring(struct intel_ring_buffer *ring) |
| 1492 | { |
| 1493 | struct drm_device *dev = ring->dev; |
| 1494 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1495 | u32 tmp = I915_READ_CTL(ring); |
| 1496 | if (tmp & RING_WAIT) { |
| 1497 | DRM_ERROR("Kicking stuck wait on %s\n", |
| 1498 | ring->name); |
| 1499 | I915_WRITE_CTL(ring, tmp); |
| 1500 | return true; |
| 1501 | } |
| 1502 | if (IS_GEN6(dev) && |
| 1503 | (tmp & RING_WAIT_SEMAPHORE)) { |
| 1504 | DRM_ERROR("Kicking stuck semaphore on %s\n", |
| 1505 | ring->name); |
| 1506 | I915_WRITE_CTL(ring, tmp); |
| 1507 | return true; |
| 1508 | } |
| 1509 | return false; |
| 1510 | } |
| 1511 | |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 1512 | /** |
| 1513 | * This is called when the chip hasn't reported back with completed |
| 1514 | * batchbuffers in a long time. The first time this is called we simply record |
| 1515 | * ACTHD. If ACTHD hasn't changed by the time the hangcheck timer elapses |
| 1516 | * again, we assume the chip is wedged and try to fix it. |
| 1517 | */ |
| 1518 | void i915_hangcheck_elapsed(unsigned long data) |
| 1519 | { |
| 1520 | struct drm_device *dev = (struct drm_device *)data; |
| 1521 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | cbb465e | 2010-06-06 12:16:24 +0100 | [diff] [blame] | 1522 | uint32_t acthd, instdone, instdone1; |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 1523 | bool err = false; |
| 1524 | |
| 1525 | /* If all work is done then ACTHD clearly hasn't advanced. */ |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1526 | if (i915_hangcheck_ring_idle(&dev_priv->ring[RCS], &err) && |
| 1527 | i915_hangcheck_ring_idle(&dev_priv->ring[VCS], &err) && |
| 1528 | i915_hangcheck_ring_idle(&dev_priv->ring[BCS], &err)) { |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 1529 | dev_priv->hangcheck_count = 0; |
| 1530 | if (err) |
| 1531 | goto repeat; |
| 1532 | return; |
| 1533 | } |
Eric Anholt | b9201c1 | 2010-01-08 14:25:16 -0800 | [diff] [blame] | 1534 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1535 | if (INTEL_INFO(dev)->gen < 4) { |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 1536 | acthd = I915_READ(ACTHD); |
Chris Wilson | cbb465e | 2010-06-06 12:16:24 +0100 | [diff] [blame] | 1537 | instdone = I915_READ(INSTDONE); |
| 1538 | instdone1 = 0; |
| 1539 | } else { |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 1540 | acthd = I915_READ(ACTHD_I965); |
Chris Wilson | cbb465e | 2010-06-06 12:16:24 +0100 | [diff] [blame] | 1541 | instdone = I915_READ(INSTDONE_I965); |
| 1542 | instdone1 = I915_READ(INSTDONE1); |
| 1543 | } |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 1544 | |
Chris Wilson | cbb465e | 2010-06-06 12:16:24 +0100 | [diff] [blame] | 1545 | if (dev_priv->last_acthd == acthd && |
| 1546 | dev_priv->last_instdone == instdone && |
| 1547 | dev_priv->last_instdone1 == instdone1) { |
| 1548 | if (dev_priv->hangcheck_count++ > 1) { |
| 1549 | DRM_ERROR("Hangcheck timer elapsed... GPU hung\n"); |
Chris Wilson | 8c80b59 | 2010-08-08 20:38:12 +0100 | [diff] [blame] | 1550 | |
| 1551 | if (!IS_GEN2(dev)) { |
| 1552 | /* Is the chip hanging on a WAIT_FOR_EVENT? |
| 1553 | * If so we can simply poke the RB_WAIT bit |
| 1554 | * and break the hang. This should work on |
| 1555 | * all but the second generation chipsets. |
| 1556 | */ |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1557 | |
| 1558 | if (kick_ring(&dev_priv->ring[RCS])) |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 1559 | goto repeat; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1560 | |
| 1561 | if (HAS_BSD(dev) && |
| 1562 | kick_ring(&dev_priv->ring[VCS])) |
| 1563 | goto repeat; |
| 1564 | |
| 1565 | if (HAS_BLT(dev) && |
| 1566 | kick_ring(&dev_priv->ring[BCS])) |
| 1567 | goto repeat; |
Chris Wilson | 8c80b59 | 2010-08-08 20:38:12 +0100 | [diff] [blame] | 1568 | } |
| 1569 | |
Chris Wilson | cbb465e | 2010-06-06 12:16:24 +0100 | [diff] [blame] | 1570 | i915_handle_error(dev, true); |
| 1571 | return; |
| 1572 | } |
| 1573 | } else { |
| 1574 | dev_priv->hangcheck_count = 0; |
| 1575 | |
| 1576 | dev_priv->last_acthd = acthd; |
| 1577 | dev_priv->last_instdone = instdone; |
| 1578 | dev_priv->last_instdone1 = instdone1; |
| 1579 | } |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 1580 | |
Chris Wilson | 893eead | 2010-10-27 14:44:35 +0100 | [diff] [blame] | 1581 | repeat: |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 1582 | /* Reset timer case chip hangs without another request being added */ |
Chris Wilson | b3b079d | 2010-09-13 23:44:34 +0100 | [diff] [blame] | 1583 | mod_timer(&dev_priv->hangcheck_timer, |
| 1584 | jiffies + msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD)); |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 1585 | } |
| 1586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | /* drm_dma.h hooks |
| 1588 | */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 1589 | static void ironlake_irq_preinstall(struct drm_device *dev) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1590 | { |
| 1591 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 1592 | |
| 1593 | I915_WRITE(HWSTAM, 0xeffe); |
| 1594 | |
| 1595 | /* XXX hotplug from PCH */ |
| 1596 | |
| 1597 | I915_WRITE(DEIMR, 0xffffffff); |
| 1598 | I915_WRITE(DEIER, 0x0); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 1599 | POSTING_READ(DEIER); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1600 | |
| 1601 | /* and GT */ |
| 1602 | I915_WRITE(GTIMR, 0xffffffff); |
| 1603 | I915_WRITE(GTIER, 0x0); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 1604 | POSTING_READ(GTIER); |
Zhenyu Wang | c650156 | 2009-11-03 18:57:21 +0000 | [diff] [blame] | 1605 | |
| 1606 | /* south display irq */ |
| 1607 | I915_WRITE(SDEIMR, 0xffffffff); |
| 1608 | I915_WRITE(SDEIER, 0x0); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 1609 | POSTING_READ(SDEIER); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1610 | } |
| 1611 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 1612 | static int ironlake_irq_postinstall(struct drm_device *dev) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1613 | { |
| 1614 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 1615 | /* enable kind of interrupts always enabled */ |
Jesse Barnes | 013d5aa | 2010-01-29 11:18:31 -0800 | [diff] [blame] | 1616 | u32 display_mask = DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | |
| 1617 | DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1618 | u32 render_irqs; |
Yuanhan Liu | 2d7b836 | 2010-10-08 10:21:06 +0100 | [diff] [blame] | 1619 | u32 hotplug_mask; |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1620 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1621 | dev_priv->irq_mask = ~display_mask; |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1622 | |
| 1623 | /* should always can generate irq */ |
| 1624 | I915_WRITE(DEIIR, I915_READ(DEIIR)); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1625 | I915_WRITE(DEIMR, dev_priv->irq_mask); |
| 1626 | I915_WRITE(DEIER, display_mask | DE_PIPEA_VBLANK | DE_PIPEB_VBLANK); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 1627 | POSTING_READ(DEIER); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1628 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1629 | dev_priv->gt_irq_mask = ~0; |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1630 | |
| 1631 | I915_WRITE(GTIIR, I915_READ(GTIIR)); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1632 | I915_WRITE(GTIMR, dev_priv->gt_irq_mask); |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1633 | if (IS_GEN6(dev)) { |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1634 | I915_WRITE(GEN6_RENDER_IMR, ~GEN6_RENDER_USER_INTERRUPT); |
| 1635 | I915_WRITE(GEN6_BSD_IMR, ~GEN6_BSD_USER_INTERRUPT); |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1636 | I915_WRITE(GEN6_BLITTER_IMR, ~GEN6_BLITTER_USER_INTERRUPT); |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1637 | } |
| 1638 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1639 | if (IS_GEN6(dev)) |
| 1640 | render_irqs = |
| 1641 | GT_USER_INTERRUPT | |
| 1642 | GT_GEN6_BSD_USER_INTERRUPT | |
| 1643 | GT_BLT_USER_INTERRUPT; |
| 1644 | else |
| 1645 | render_irqs = |
Chris Wilson | 88f23b8 | 2010-12-05 15:08:31 +0000 | [diff] [blame] | 1646 | GT_USER_INTERRUPT | |
Chris Wilson | c6df541 | 2010-12-15 09:56:50 +0000 | [diff] [blame] | 1647 | GT_PIPE_NOTIFY | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1648 | GT_BSD_USER_INTERRUPT; |
| 1649 | I915_WRITE(GTIER, render_irqs); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 1650 | POSTING_READ(GTIER); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1651 | |
Yuanhan Liu | 2d7b836 | 2010-10-08 10:21:06 +0100 | [diff] [blame] | 1652 | if (HAS_PCH_CPT(dev)) { |
| 1653 | hotplug_mask = SDE_CRT_HOTPLUG_CPT | SDE_PORTB_HOTPLUG_CPT | |
| 1654 | SDE_PORTC_HOTPLUG_CPT | SDE_PORTD_HOTPLUG_CPT ; |
| 1655 | } else { |
| 1656 | hotplug_mask = SDE_CRT_HOTPLUG | SDE_PORTB_HOTPLUG | |
| 1657 | SDE_PORTC_HOTPLUG | SDE_PORTD_HOTPLUG; |
| 1658 | } |
| 1659 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1660 | dev_priv->pch_irq_mask = ~hotplug_mask; |
Zhenyu Wang | c650156 | 2009-11-03 18:57:21 +0000 | [diff] [blame] | 1661 | |
| 1662 | I915_WRITE(SDEIIR, I915_READ(SDEIIR)); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1663 | I915_WRITE(SDEIMR, dev_priv->pch_irq_mask); |
| 1664 | I915_WRITE(SDEIER, hotplug_mask); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 1665 | POSTING_READ(SDEIER); |
Zhenyu Wang | c650156 | 2009-11-03 18:57:21 +0000 | [diff] [blame] | 1666 | |
Jesse Barnes | f97108d | 2010-01-29 11:27:07 -0800 | [diff] [blame] | 1667 | if (IS_IRONLAKE_M(dev)) { |
| 1668 | /* Clear & enable PCU event interrupts */ |
| 1669 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 1670 | I915_WRITE(DEIER, I915_READ(DEIER) | DE_PCU_EVENT); |
| 1671 | ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT); |
| 1672 | } |
| 1673 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1674 | return 0; |
| 1675 | } |
| 1676 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1677 | void i915_driver_irq_preinstall(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | { |
| 1679 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 1680 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1681 | atomic_set(&dev_priv->irq_received, 0); |
| 1682 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1683 | INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1684 | INIT_WORK(&dev_priv->error_work, i915_error_work_func); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1685 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 1686 | if (HAS_PCH_SPLIT(dev)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 1687 | ironlake_irq_preinstall(dev); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1688 | return; |
| 1689 | } |
| 1690 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 1691 | if (I915_HAS_HOTPLUG(dev)) { |
| 1692 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
| 1693 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); |
| 1694 | } |
| 1695 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1696 | I915_WRITE(HWSTAM, 0xeffe); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1697 | I915_WRITE(PIPEASTAT, 0); |
| 1698 | I915_WRITE(PIPEBSTAT, 0); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1699 | I915_WRITE(IMR, 0xffffffff); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1700 | I915_WRITE(IER, 0x0); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 1701 | POSTING_READ(IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | } |
| 1703 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 1704 | /* |
| 1705 | * Must be called after intel_modeset_init or hotplug interrupts won't be |
| 1706 | * enabled correctly. |
| 1707 | */ |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1708 | int i915_driver_irq_postinstall(struct drm_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | { |
| 1710 | 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] | 1711 | u32 enable_mask = I915_INTERRUPT_ENABLE_FIX | I915_INTERRUPT_ENABLE_VAR; |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 1712 | u32 error_mask; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1713 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1714 | DRM_INIT_WAITQUEUE(&dev_priv->ring[RCS].irq_queue); |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 1715 | if (HAS_BSD(dev)) |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1716 | DRM_INIT_WAITQUEUE(&dev_priv->ring[VCS].irq_queue); |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1717 | if (HAS_BLT(dev)) |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1718 | DRM_INIT_WAITQUEUE(&dev_priv->ring[BCS].irq_queue); |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 1719 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1720 | 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] | 1721 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 1722 | if (HAS_PCH_SPLIT(dev)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 1723 | return ironlake_irq_postinstall(dev); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1724 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1725 | /* Unmask the interrupts that we always want on. */ |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1726 | dev_priv->irq_mask = ~I915_INTERRUPT_ENABLE_FIX; |
Matthew Garrett | 8ee1c3d | 2008-08-05 19:37:25 +0100 | [diff] [blame] | 1727 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1728 | dev_priv->pipestat[0] = 0; |
| 1729 | dev_priv->pipestat[1] = 0; |
| 1730 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 1731 | if (I915_HAS_HOTPLUG(dev)) { |
Adam Jackson | c496fa1 | 2010-05-27 17:26:45 -0400 | [diff] [blame] | 1732 | /* Enable in IER... */ |
| 1733 | enable_mask |= I915_DISPLAY_PORT_INTERRUPT; |
| 1734 | /* and unmask in IMR */ |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1735 | dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT; |
Adam Jackson | c496fa1 | 2010-05-27 17:26:45 -0400 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | /* |
| 1739 | * Enable some error detection, note the instruction error mask |
| 1740 | * bit is reserved, so we leave it masked. |
| 1741 | */ |
| 1742 | if (IS_G4X(dev)) { |
| 1743 | error_mask = ~(GM45_ERROR_PAGE_TABLE | |
| 1744 | GM45_ERROR_MEM_PRIV | |
| 1745 | GM45_ERROR_CP_PRIV | |
| 1746 | I915_ERROR_MEMORY_REFRESH); |
| 1747 | } else { |
| 1748 | error_mask = ~(I915_ERROR_PAGE_TABLE | |
| 1749 | I915_ERROR_MEMORY_REFRESH); |
| 1750 | } |
| 1751 | I915_WRITE(EMR, error_mask); |
| 1752 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1753 | I915_WRITE(IMR, dev_priv->irq_mask); |
Adam Jackson | c496fa1 | 2010-05-27 17:26:45 -0400 | [diff] [blame] | 1754 | I915_WRITE(IER, enable_mask); |
Chris Wilson | 3143a2b | 2010-11-16 15:55:10 +0000 | [diff] [blame] | 1755 | POSTING_READ(IER); |
Adam Jackson | c496fa1 | 2010-05-27 17:26:45 -0400 | [diff] [blame] | 1756 | |
| 1757 | if (I915_HAS_HOTPLUG(dev)) { |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 1758 | u32 hotplug_en = I915_READ(PORT_HOTPLUG_EN); |
| 1759 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 1760 | /* Note HDMI and DP share bits */ |
| 1761 | if (dev_priv->hotplug_supported_mask & HDMIB_HOTPLUG_INT_STATUS) |
| 1762 | hotplug_en |= HDMIB_HOTPLUG_INT_EN; |
| 1763 | if (dev_priv->hotplug_supported_mask & HDMIC_HOTPLUG_INT_STATUS) |
| 1764 | hotplug_en |= HDMIC_HOTPLUG_INT_EN; |
| 1765 | if (dev_priv->hotplug_supported_mask & HDMID_HOTPLUG_INT_STATUS) |
| 1766 | hotplug_en |= HDMID_HOTPLUG_INT_EN; |
| 1767 | if (dev_priv->hotplug_supported_mask & SDVOC_HOTPLUG_INT_STATUS) |
| 1768 | hotplug_en |= SDVOC_HOTPLUG_INT_EN; |
| 1769 | if (dev_priv->hotplug_supported_mask & SDVOB_HOTPLUG_INT_STATUS) |
| 1770 | hotplug_en |= SDVOB_HOTPLUG_INT_EN; |
Andy Lutomirski | 2d1c975 | 2010-06-12 05:21:18 -0400 | [diff] [blame] | 1771 | if (dev_priv->hotplug_supported_mask & CRT_HOTPLUG_INT_STATUS) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 1772 | hotplug_en |= CRT_HOTPLUG_INT_EN; |
Andy Lutomirski | 2d1c975 | 2010-06-12 05:21:18 -0400 | [diff] [blame] | 1773 | |
| 1774 | /* Programming the CRT detection parameters tends |
| 1775 | to generate a spurious hotplug event about three |
| 1776 | seconds later. So just do it once. |
| 1777 | */ |
| 1778 | if (IS_G4X(dev)) |
| 1779 | hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64; |
| 1780 | hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; |
| 1781 | } |
| 1782 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 1783 | /* Ignore TV since it's buggy */ |
| 1784 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 1785 | I915_WRITE(PORT_HOTPLUG_EN, hotplug_en); |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
Chris Wilson | 3b61796 | 2010-08-24 09:02:58 +0100 | [diff] [blame] | 1788 | intel_opregion_enable_asle(dev); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1789 | |
| 1790 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 1793 | static void ironlake_irq_uninstall(struct drm_device *dev) |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1794 | { |
| 1795 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 1796 | I915_WRITE(HWSTAM, 0xffffffff); |
| 1797 | |
| 1798 | I915_WRITE(DEIMR, 0xffffffff); |
| 1799 | I915_WRITE(DEIER, 0x0); |
| 1800 | I915_WRITE(DEIIR, I915_READ(DEIIR)); |
| 1801 | |
| 1802 | I915_WRITE(GTIMR, 0xffffffff); |
| 1803 | I915_WRITE(GTIER, 0x0); |
| 1804 | I915_WRITE(GTIIR, I915_READ(GTIIR)); |
| 1805 | } |
| 1806 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1807 | void i915_driver_irq_uninstall(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | { |
| 1809 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Dave Airlie | 91e3738 | 2006-02-18 15:17:04 +1100 | [diff] [blame] | 1810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | if (!dev_priv) |
| 1812 | return; |
| 1813 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1814 | dev_priv->vblank_pipe = 0; |
| 1815 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 1816 | if (HAS_PCH_SPLIT(dev)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 1817 | ironlake_irq_uninstall(dev); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1818 | return; |
| 1819 | } |
| 1820 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 1821 | if (I915_HAS_HOTPLUG(dev)) { |
| 1822 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
| 1823 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); |
| 1824 | } |
| 1825 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1826 | I915_WRITE(HWSTAM, 0xffffffff); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1827 | I915_WRITE(PIPEASTAT, 0); |
| 1828 | I915_WRITE(PIPEBSTAT, 0); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1829 | I915_WRITE(IMR, 0xffffffff); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1830 | I915_WRITE(IER, 0x0); |
Dave Airlie | 91e3738 | 2006-02-18 15:17:04 +1100 | [diff] [blame] | 1831 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1832 | I915_WRITE(PIPEASTAT, I915_READ(PIPEASTAT) & 0x8000ffff); |
| 1833 | I915_WRITE(PIPEBSTAT, I915_READ(PIPEBSTAT) & 0x8000ffff); |
| 1834 | I915_WRITE(IIR, I915_READ(IIR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | } |