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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include "drmP.h" |
| 31 | #include "drm.h" |
| 32 | #include "i915_drm.h" |
| 33 | #include "i915_drv.h" |
Chris Wilson | 1c5d22f | 2009-08-25 11:15:50 +0100 | [diff] [blame] | 34 | #include "i915_trace.h" |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 35 | #include "intel_drv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #define MAX_NOPID ((u32)~0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 39 | /** |
| 40 | * Interrupts that are always left unmasked. |
| 41 | * |
| 42 | * Since pipe events are edge-triggered from the PIPESTAT register to IIR, |
| 43 | * we leave them always unmasked in IMR and then control enabling them through |
| 44 | * PIPESTAT alone. |
| 45 | */ |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 46 | #define I915_INTERRUPT_ENABLE_FIX (I915_ASLE_INTERRUPT | \ |
| 47 | I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | \ |
| 48 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | \ |
| 49 | I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 50 | |
| 51 | /** Interrupts that we mask and unmask at runtime. */ |
| 52 | #define I915_INTERRUPT_ENABLE_VAR (I915_USER_INTERRUPT) |
| 53 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 54 | #define I915_PIPE_VBLANK_STATUS (PIPE_START_VBLANK_INTERRUPT_STATUS |\ |
| 55 | PIPE_VBLANK_INTERRUPT_STATUS) |
| 56 | |
| 57 | #define I915_PIPE_VBLANK_ENABLE (PIPE_START_VBLANK_INTERRUPT_ENABLE |\ |
| 58 | PIPE_VBLANK_INTERRUPT_ENABLE) |
| 59 | |
| 60 | #define DRM_I915_VBLANK_PIPE_ALL (DRM_I915_VBLANK_PIPE_A | \ |
| 61 | DRM_I915_VBLANK_PIPE_B) |
| 62 | |
Matthew Garrett | 8ee1c3d | 2008-08-05 19:37:25 +0100 | [diff] [blame] | 63 | void |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 64 | igdng_enable_graphics_irq(drm_i915_private_t *dev_priv, u32 mask) |
| 65 | { |
| 66 | if ((dev_priv->gt_irq_mask_reg & mask) != 0) { |
| 67 | dev_priv->gt_irq_mask_reg &= ~mask; |
| 68 | I915_WRITE(GTIMR, dev_priv->gt_irq_mask_reg); |
| 69 | (void) I915_READ(GTIMR); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | static inline void |
| 74 | igdng_disable_graphics_irq(drm_i915_private_t *dev_priv, u32 mask) |
| 75 | { |
| 76 | if ((dev_priv->gt_irq_mask_reg & mask) != mask) { |
| 77 | dev_priv->gt_irq_mask_reg |= mask; |
| 78 | I915_WRITE(GTIMR, dev_priv->gt_irq_mask_reg); |
| 79 | (void) I915_READ(GTIMR); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /* For display hotplug interrupt */ |
| 84 | void |
| 85 | igdng_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask) |
| 86 | { |
| 87 | if ((dev_priv->irq_mask_reg & mask) != 0) { |
| 88 | dev_priv->irq_mask_reg &= ~mask; |
| 89 | I915_WRITE(DEIMR, dev_priv->irq_mask_reg); |
| 90 | (void) I915_READ(DEIMR); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | static inline void |
| 95 | igdng_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask) |
| 96 | { |
| 97 | if ((dev_priv->irq_mask_reg & mask) != mask) { |
| 98 | dev_priv->irq_mask_reg |= mask; |
| 99 | I915_WRITE(DEIMR, dev_priv->irq_mask_reg); |
| 100 | (void) I915_READ(DEIMR); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | void |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 105 | i915_enable_irq(drm_i915_private_t *dev_priv, u32 mask) |
| 106 | { |
| 107 | if ((dev_priv->irq_mask_reg & mask) != 0) { |
| 108 | dev_priv->irq_mask_reg &= ~mask; |
| 109 | I915_WRITE(IMR, dev_priv->irq_mask_reg); |
| 110 | (void) I915_READ(IMR); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | static inline void |
| 115 | i915_disable_irq(drm_i915_private_t *dev_priv, u32 mask) |
| 116 | { |
| 117 | if ((dev_priv->irq_mask_reg & mask) != mask) { |
| 118 | dev_priv->irq_mask_reg |= mask; |
| 119 | I915_WRITE(IMR, dev_priv->irq_mask_reg); |
| 120 | (void) I915_READ(IMR); |
| 121 | } |
| 122 | } |
| 123 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 124 | static inline u32 |
| 125 | i915_pipestat(int pipe) |
| 126 | { |
| 127 | if (pipe == 0) |
| 128 | return PIPEASTAT; |
| 129 | if (pipe == 1) |
| 130 | return PIPEBSTAT; |
Andrew Morton | 9c84ba4 | 2008-12-01 13:14:08 -0800 | [diff] [blame] | 131 | BUG(); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | void |
| 135 | i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask) |
| 136 | { |
| 137 | if ((dev_priv->pipestat[pipe] & mask) != mask) { |
| 138 | u32 reg = i915_pipestat(pipe); |
| 139 | |
| 140 | dev_priv->pipestat[pipe] |= mask; |
| 141 | /* Enable the interrupt, clear any pending status */ |
| 142 | I915_WRITE(reg, dev_priv->pipestat[pipe] | (mask >> 16)); |
| 143 | (void) I915_READ(reg); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | void |
| 148 | i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask) |
| 149 | { |
| 150 | if ((dev_priv->pipestat[pipe] & mask) != 0) { |
| 151 | u32 reg = i915_pipestat(pipe); |
| 152 | |
| 153 | dev_priv->pipestat[pipe] &= ~mask; |
| 154 | I915_WRITE(reg, dev_priv->pipestat[pipe]); |
| 155 | (void) I915_READ(reg); |
| 156 | } |
| 157 | } |
| 158 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 159 | /** |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 160 | * i915_pipe_enabled - check if a pipe is enabled |
| 161 | * @dev: DRM device |
| 162 | * @pipe: pipe to check |
| 163 | * |
| 164 | * Reading certain registers when the pipe is disabled can hang the chip. |
| 165 | * Use this routine to make sure the PLL is running and the pipe is active |
| 166 | * before reading such registers if unsure. |
| 167 | */ |
| 168 | static int |
| 169 | i915_pipe_enabled(struct drm_device *dev, int pipe) |
| 170 | { |
| 171 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 172 | unsigned long pipeconf = pipe ? PIPEBCONF : PIPEACONF; |
| 173 | |
| 174 | if (I915_READ(pipeconf) & PIPEACONF_ENABLE) |
| 175 | return 1; |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
Keith Packard | 42f52ef | 2008-10-18 19:39:29 -0700 | [diff] [blame] | 180 | /* Called from drm generic code, passed a 'crtc', which |
| 181 | * we use as a pipe index |
| 182 | */ |
| 183 | u32 i915_get_vblank_counter(struct drm_device *dev, int pipe) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 184 | { |
| 185 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 186 | unsigned long high_frame; |
| 187 | unsigned long low_frame; |
| 188 | u32 high1, high2, low, count; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 189 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 190 | high_frame = pipe ? PIPEBFRAMEHIGH : PIPEAFRAMEHIGH; |
| 191 | low_frame = pipe ? PIPEBFRAMEPIXEL : PIPEAFRAMEPIXEL; |
| 192 | |
| 193 | if (!i915_pipe_enabled(dev, pipe)) { |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame^] | 194 | DRM_DEBUG_DRIVER("trying to get vblank count for disabled " |
| 195 | "pipe %d\n", pipe); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | /* |
| 200 | * High & low register fields aren't synchronized, so make sure |
| 201 | * we get a low value that's stable across two reads of the high |
| 202 | * register. |
| 203 | */ |
| 204 | do { |
| 205 | high1 = ((I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >> |
| 206 | PIPE_FRAME_HIGH_SHIFT); |
| 207 | low = ((I915_READ(low_frame) & PIPE_FRAME_LOW_MASK) >> |
| 208 | PIPE_FRAME_LOW_SHIFT); |
| 209 | high2 = ((I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >> |
| 210 | PIPE_FRAME_HIGH_SHIFT); |
| 211 | } while (high1 != high2); |
| 212 | |
| 213 | count = (high1 << 8) | low; |
| 214 | |
| 215 | return count; |
| 216 | } |
| 217 | |
Jesse Barnes | 9880b7a | 2009-02-06 10:22:41 -0800 | [diff] [blame] | 218 | u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe) |
| 219 | { |
| 220 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 221 | int reg = pipe ? PIPEB_FRMCOUNT_GM45 : PIPEA_FRMCOUNT_GM45; |
| 222 | |
| 223 | if (!i915_pipe_enabled(dev, pipe)) { |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame^] | 224 | DRM_DEBUG_DRIVER("trying to get vblank count for disabled " |
| 225 | "pipe %d\n", pipe); |
Jesse Barnes | 9880b7a | 2009-02-06 10:22:41 -0800 | [diff] [blame] | 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | return I915_READ(reg); |
| 230 | } |
| 231 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 232 | /* |
| 233 | * Handle hotplug events outside the interrupt handler proper. |
| 234 | */ |
| 235 | static void i915_hotplug_work_func(struct work_struct *work) |
| 236 | { |
| 237 | drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, |
| 238 | hotplug_work); |
| 239 | struct drm_device *dev = dev_priv->dev; |
Keith Packard | c31c4ba | 2009-05-06 11:48:58 -0700 | [diff] [blame] | 240 | struct drm_mode_config *mode_config = &dev->mode_config; |
| 241 | struct drm_connector *connector; |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 242 | |
Keith Packard | c31c4ba | 2009-05-06 11:48:58 -0700 | [diff] [blame] | 243 | if (mode_config->num_connector) { |
| 244 | list_for_each_entry(connector, &mode_config->connector_list, head) { |
| 245 | struct intel_output *intel_output = to_intel_output(connector); |
| 246 | |
| 247 | if (intel_output->hot_plug) |
| 248 | (*intel_output->hot_plug) (intel_output); |
| 249 | } |
| 250 | } |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 251 | /* Just fire off a uevent and let userspace tell us what to do */ |
| 252 | drm_sysfs_hotplug_event(dev); |
| 253 | } |
| 254 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 255 | irqreturn_t igdng_irq_handler(struct drm_device *dev) |
| 256 | { |
| 257 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 258 | int ret = IRQ_NONE; |
| 259 | u32 de_iir, gt_iir; |
| 260 | u32 new_de_iir, new_gt_iir; |
| 261 | struct drm_i915_master_private *master_priv; |
| 262 | |
| 263 | de_iir = I915_READ(DEIIR); |
| 264 | gt_iir = I915_READ(GTIIR); |
| 265 | |
| 266 | for (;;) { |
| 267 | if (de_iir == 0 && gt_iir == 0) |
| 268 | break; |
| 269 | |
| 270 | ret = IRQ_HANDLED; |
| 271 | |
| 272 | I915_WRITE(DEIIR, de_iir); |
| 273 | new_de_iir = I915_READ(DEIIR); |
| 274 | I915_WRITE(GTIIR, gt_iir); |
| 275 | new_gt_iir = I915_READ(GTIIR); |
| 276 | |
| 277 | if (dev->primary->master) { |
| 278 | master_priv = dev->primary->master->driver_priv; |
| 279 | if (master_priv->sarea_priv) |
| 280 | master_priv->sarea_priv->last_dispatch = |
| 281 | READ_BREADCRUMB(dev_priv); |
| 282 | } |
| 283 | |
| 284 | if (gt_iir & GT_USER_INTERRUPT) { |
Chris Wilson | 1c5d22f | 2009-08-25 11:15:50 +0100 | [diff] [blame] | 285 | u32 seqno = i915_get_gem_seqno(dev); |
| 286 | dev_priv->mm.irq_gem_seqno = seqno; |
| 287 | trace_i915_gem_request_complete(dev, seqno); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 288 | DRM_WAKEUP(&dev_priv->irq_queue); |
| 289 | } |
| 290 | |
| 291 | de_iir = new_de_iir; |
| 292 | gt_iir = new_gt_iir; |
| 293 | } |
| 294 | |
| 295 | return ret; |
| 296 | } |
| 297 | |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 298 | /** |
| 299 | * i915_error_work_func - do process context error handling work |
| 300 | * @work: work struct |
| 301 | * |
| 302 | * Fire an error uevent so userspace can see that a hang or error |
| 303 | * was detected. |
| 304 | */ |
| 305 | static void i915_error_work_func(struct work_struct *work) |
| 306 | { |
| 307 | drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, |
| 308 | error_work); |
| 309 | struct drm_device *dev = dev_priv->dev; |
Ben Gamari | f316a42 | 2009-09-14 17:48:46 -0400 | [diff] [blame] | 310 | char *error_event[] = { "ERROR=1", NULL }; |
| 311 | char *reset_event[] = { "RESET=1", NULL }; |
| 312 | char *reset_done_event[] = { "ERROR=0", NULL }; |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 313 | |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame^] | 314 | DRM_DEBUG_DRIVER("generating error event\n"); |
Ben Gamari | f316a42 | 2009-09-14 17:48:46 -0400 | [diff] [blame] | 315 | kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 316 | |
Ben Gamari | ba1234d | 2009-09-14 17:48:47 -0400 | [diff] [blame] | 317 | if (atomic_read(&dev_priv->mm.wedged)) { |
Ben Gamari | f316a42 | 2009-09-14 17:48:46 -0400 | [diff] [blame] | 318 | if (IS_I965G(dev)) { |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame^] | 319 | DRM_DEBUG_DRIVER("resetting chip\n"); |
Ben Gamari | f316a42 | 2009-09-14 17:48:46 -0400 | [diff] [blame] | 320 | kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_event); |
| 321 | if (!i965_reset(dev, GDRST_RENDER)) { |
Ben Gamari | ba1234d | 2009-09-14 17:48:47 -0400 | [diff] [blame] | 322 | atomic_set(&dev_priv->mm.wedged, 0); |
Ben Gamari | f316a42 | 2009-09-14 17:48:46 -0400 | [diff] [blame] | 323 | kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_done_event); |
| 324 | } |
| 325 | } else { |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame^] | 326 | DRM_DEBUG_DRIVER("reboot required\n"); |
Ben Gamari | f316a42 | 2009-09-14 17:48:46 -0400 | [diff] [blame] | 327 | } |
| 328 | } |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | /** |
| 332 | * i915_capture_error_state - capture an error record for later analysis |
| 333 | * @dev: drm device |
| 334 | * |
| 335 | * Should be called when an error is detected (either a hang or an error |
| 336 | * interrupt) to capture error state from the time of the error. Fills |
| 337 | * out a structure which becomes available in debugfs for user level tools |
| 338 | * to pick up. |
| 339 | */ |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 340 | static void i915_capture_error_state(struct drm_device *dev) |
| 341 | { |
| 342 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 343 | struct drm_i915_error_state *error; |
| 344 | unsigned long flags; |
| 345 | |
| 346 | spin_lock_irqsave(&dev_priv->error_lock, flags); |
| 347 | if (dev_priv->first_error) |
| 348 | goto out; |
| 349 | |
| 350 | error = kmalloc(sizeof(*error), GFP_ATOMIC); |
| 351 | if (!error) { |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame^] | 352 | DRM_DEBUG_DRIVER("out ot memory, not capturing error state\n"); |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 353 | goto out; |
| 354 | } |
| 355 | |
| 356 | error->eir = I915_READ(EIR); |
| 357 | error->pgtbl_er = I915_READ(PGTBL_ER); |
| 358 | error->pipeastat = I915_READ(PIPEASTAT); |
| 359 | error->pipebstat = I915_READ(PIPEBSTAT); |
| 360 | error->instpm = I915_READ(INSTPM); |
| 361 | if (!IS_I965G(dev)) { |
| 362 | error->ipeir = I915_READ(IPEIR); |
| 363 | error->ipehr = I915_READ(IPEHR); |
| 364 | error->instdone = I915_READ(INSTDONE); |
| 365 | error->acthd = I915_READ(ACTHD); |
| 366 | } else { |
| 367 | error->ipeir = I915_READ(IPEIR_I965); |
| 368 | error->ipehr = I915_READ(IPEHR_I965); |
| 369 | error->instdone = I915_READ(INSTDONE_I965); |
| 370 | error->instps = I915_READ(INSTPS); |
| 371 | error->instdone1 = I915_READ(INSTDONE1); |
| 372 | error->acthd = I915_READ(ACTHD_I965); |
| 373 | } |
| 374 | |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 375 | do_gettimeofday(&error->time); |
| 376 | |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 377 | dev_priv->first_error = error; |
| 378 | |
| 379 | out: |
| 380 | spin_unlock_irqrestore(&dev_priv->error_lock, flags); |
| 381 | } |
| 382 | |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 383 | /** |
| 384 | * i915_handle_error - handle an error interrupt |
| 385 | * @dev: drm device |
| 386 | * |
| 387 | * Do some basic checking of regsiter state at error interrupt time and |
| 388 | * dump it to the syslog. Also call i915_capture_error_state() to make |
| 389 | * sure we get a record and make it available in debugfs. Fire a uevent |
| 390 | * so userspace knows something bad happened (should trigger collection |
| 391 | * of a ring dump etc.). |
| 392 | */ |
Ben Gamari | ba1234d | 2009-09-14 17:48:47 -0400 | [diff] [blame] | 393 | static void i915_handle_error(struct drm_device *dev, bool wedged) |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 394 | { |
| 395 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 396 | u32 eir = I915_READ(EIR); |
| 397 | u32 pipea_stats = I915_READ(PIPEASTAT); |
| 398 | u32 pipeb_stats = I915_READ(PIPEBSTAT); |
| 399 | |
| 400 | i915_capture_error_state(dev); |
| 401 | |
| 402 | printk(KERN_ERR "render error detected, EIR: 0x%08x\n", |
| 403 | eir); |
| 404 | |
| 405 | if (IS_G4X(dev)) { |
| 406 | if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) { |
| 407 | u32 ipeir = I915_READ(IPEIR_I965); |
| 408 | |
| 409 | printk(KERN_ERR " IPEIR: 0x%08x\n", |
| 410 | I915_READ(IPEIR_I965)); |
| 411 | printk(KERN_ERR " IPEHR: 0x%08x\n", |
| 412 | I915_READ(IPEHR_I965)); |
| 413 | printk(KERN_ERR " INSTDONE: 0x%08x\n", |
| 414 | I915_READ(INSTDONE_I965)); |
| 415 | printk(KERN_ERR " INSTPS: 0x%08x\n", |
| 416 | I915_READ(INSTPS)); |
| 417 | printk(KERN_ERR " INSTDONE1: 0x%08x\n", |
| 418 | I915_READ(INSTDONE1)); |
| 419 | printk(KERN_ERR " ACTHD: 0x%08x\n", |
| 420 | I915_READ(ACTHD_I965)); |
| 421 | I915_WRITE(IPEIR_I965, ipeir); |
| 422 | (void)I915_READ(IPEIR_I965); |
| 423 | } |
| 424 | if (eir & GM45_ERROR_PAGE_TABLE) { |
| 425 | u32 pgtbl_err = I915_READ(PGTBL_ER); |
| 426 | printk(KERN_ERR "page table error\n"); |
| 427 | printk(KERN_ERR " PGTBL_ER: 0x%08x\n", |
| 428 | pgtbl_err); |
| 429 | I915_WRITE(PGTBL_ER, pgtbl_err); |
| 430 | (void)I915_READ(PGTBL_ER); |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | if (IS_I9XX(dev)) { |
| 435 | if (eir & I915_ERROR_PAGE_TABLE) { |
| 436 | u32 pgtbl_err = I915_READ(PGTBL_ER); |
| 437 | printk(KERN_ERR "page table error\n"); |
| 438 | printk(KERN_ERR " PGTBL_ER: 0x%08x\n", |
| 439 | pgtbl_err); |
| 440 | I915_WRITE(PGTBL_ER, pgtbl_err); |
| 441 | (void)I915_READ(PGTBL_ER); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | if (eir & I915_ERROR_MEMORY_REFRESH) { |
| 446 | printk(KERN_ERR "memory refresh error\n"); |
| 447 | printk(KERN_ERR "PIPEASTAT: 0x%08x\n", |
| 448 | pipea_stats); |
| 449 | printk(KERN_ERR "PIPEBSTAT: 0x%08x\n", |
| 450 | pipeb_stats); |
| 451 | /* pipestat has already been acked */ |
| 452 | } |
| 453 | if (eir & I915_ERROR_INSTRUCTION) { |
| 454 | printk(KERN_ERR "instruction error\n"); |
| 455 | printk(KERN_ERR " INSTPM: 0x%08x\n", |
| 456 | I915_READ(INSTPM)); |
| 457 | if (!IS_I965G(dev)) { |
| 458 | u32 ipeir = I915_READ(IPEIR); |
| 459 | |
| 460 | printk(KERN_ERR " IPEIR: 0x%08x\n", |
| 461 | I915_READ(IPEIR)); |
| 462 | printk(KERN_ERR " IPEHR: 0x%08x\n", |
| 463 | I915_READ(IPEHR)); |
| 464 | printk(KERN_ERR " INSTDONE: 0x%08x\n", |
| 465 | I915_READ(INSTDONE)); |
| 466 | printk(KERN_ERR " ACTHD: 0x%08x\n", |
| 467 | I915_READ(ACTHD)); |
| 468 | I915_WRITE(IPEIR, ipeir); |
| 469 | (void)I915_READ(IPEIR); |
| 470 | } else { |
| 471 | u32 ipeir = I915_READ(IPEIR_I965); |
| 472 | |
| 473 | printk(KERN_ERR " IPEIR: 0x%08x\n", |
| 474 | I915_READ(IPEIR_I965)); |
| 475 | printk(KERN_ERR " IPEHR: 0x%08x\n", |
| 476 | I915_READ(IPEHR_I965)); |
| 477 | printk(KERN_ERR " INSTDONE: 0x%08x\n", |
| 478 | I915_READ(INSTDONE_I965)); |
| 479 | printk(KERN_ERR " INSTPS: 0x%08x\n", |
| 480 | I915_READ(INSTPS)); |
| 481 | printk(KERN_ERR " INSTDONE1: 0x%08x\n", |
| 482 | I915_READ(INSTDONE1)); |
| 483 | printk(KERN_ERR " ACTHD: 0x%08x\n", |
| 484 | I915_READ(ACTHD_I965)); |
| 485 | I915_WRITE(IPEIR_I965, ipeir); |
| 486 | (void)I915_READ(IPEIR_I965); |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | I915_WRITE(EIR, eir); |
| 491 | (void)I915_READ(EIR); |
| 492 | eir = I915_READ(EIR); |
| 493 | if (eir) { |
| 494 | /* |
| 495 | * some errors might have become stuck, |
| 496 | * mask them. |
| 497 | */ |
| 498 | DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir); |
| 499 | I915_WRITE(EMR, I915_READ(EMR) | eir); |
| 500 | I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); |
| 501 | } |
| 502 | |
Ben Gamari | ba1234d | 2009-09-14 17:48:47 -0400 | [diff] [blame] | 503 | if (wedged) { |
| 504 | atomic_set(&dev_priv->mm.wedged, 1); |
| 505 | |
Ben Gamari | 11ed50e | 2009-09-14 17:48:45 -0400 | [diff] [blame] | 506 | /* |
| 507 | * Wakeup waiting processes so they don't hang |
| 508 | */ |
| 509 | printk("i915: Waking up sleeping processes\n"); |
| 510 | DRM_WAKEUP(&dev_priv->irq_queue); |
| 511 | } |
| 512 | |
Eric Anholt | 9c9fe1f | 2009-08-03 16:09:16 -0700 | [diff] [blame] | 513 | queue_work(dev_priv->wq, &dev_priv->error_work); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 514 | } |
| 515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS) |
| 517 | { |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 518 | struct drm_device *dev = (struct drm_device *) arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | 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] | 520 | struct drm_i915_master_private *master_priv; |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 521 | u32 iir, new_iir; |
| 522 | u32 pipea_stats, pipeb_stats; |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 523 | u32 vblank_status; |
| 524 | u32 vblank_enable; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 525 | int vblank = 0; |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 526 | unsigned long irqflags; |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 527 | int irq_received; |
| 528 | int ret = IRQ_NONE; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 529 | |
Eric Anholt | 630681d | 2008-10-06 15:14:12 -0700 | [diff] [blame] | 530 | atomic_inc(&dev_priv->irq_received); |
| 531 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 532 | if (IS_IGDNG(dev)) |
| 533 | return igdng_irq_handler(dev); |
| 534 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 535 | iir = I915_READ(IIR); |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 536 | |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 537 | if (IS_I965G(dev)) { |
| 538 | vblank_status = I915_START_VBLANK_INTERRUPT_STATUS; |
| 539 | vblank_enable = PIPE_START_VBLANK_INTERRUPT_ENABLE; |
| 540 | } else { |
| 541 | vblank_status = I915_VBLANK_INTERRUPT_STATUS; |
| 542 | vblank_enable = I915_VBLANK_INTERRUPT_ENABLE; |
| 543 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 545 | for (;;) { |
| 546 | irq_received = iir != 0; |
| 547 | |
| 548 | /* Can't rely on pipestat interrupt bit in iir as it might |
| 549 | * have been cleared after the pipestat interrupt was received. |
| 550 | * It doesn't set the bit in iir again, but it still produces |
| 551 | * interrupts (for non-MSI). |
| 552 | */ |
| 553 | spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); |
| 554 | pipea_stats = I915_READ(PIPEASTAT); |
| 555 | pipeb_stats = I915_READ(PIPEBSTAT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 556 | |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 557 | if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) |
Ben Gamari | ba1234d | 2009-09-14 17:48:47 -0400 | [diff] [blame] | 558 | i915_handle_error(dev, false); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 559 | |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 560 | /* |
| 561 | * Clear the PIPE(A|B)STAT regs before the IIR |
| 562 | */ |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 563 | if (pipea_stats & 0x8000ffff) { |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 564 | if (pipea_stats & PIPE_FIFO_UNDERRUN_STATUS) |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame^] | 565 | DRM_DEBUG_DRIVER("pipe a underrun\n"); |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 566 | I915_WRITE(PIPEASTAT, pipea_stats); |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 567 | irq_received = 1; |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 568 | } |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 569 | |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 570 | if (pipeb_stats & 0x8000ffff) { |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 571 | if (pipeb_stats & PIPE_FIFO_UNDERRUN_STATUS) |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame^] | 572 | DRM_DEBUG_DRIVER("pipe b underrun\n"); |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 573 | I915_WRITE(PIPEBSTAT, pipeb_stats); |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 574 | irq_received = 1; |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 575 | } |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 576 | spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags); |
| 577 | |
| 578 | if (!irq_received) |
| 579 | break; |
| 580 | |
| 581 | ret = IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 583 | /* Consume port. Then clear IIR or we'll miss events */ |
| 584 | if ((I915_HAS_HOTPLUG(dev)) && |
| 585 | (iir & I915_DISPLAY_PORT_INTERRUPT)) { |
| 586 | u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); |
| 587 | |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame^] | 588 | DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n", |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 589 | hotplug_status); |
| 590 | if (hotplug_status & dev_priv->hotplug_supported_mask) |
Eric Anholt | 9c9fe1f | 2009-08-03 16:09:16 -0700 | [diff] [blame] | 591 | queue_work(dev_priv->wq, |
| 592 | &dev_priv->hotplug_work); |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 593 | |
| 594 | I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); |
| 595 | I915_READ(PORT_HOTPLUG_STAT); |
Shaohua Li | 0430296 | 2009-08-24 10:25:23 +0800 | [diff] [blame] | 596 | |
| 597 | /* EOS interrupts occurs */ |
| 598 | if (IS_IGD(dev) && |
| 599 | (hotplug_status & CRT_EOS_INT_STATUS)) { |
| 600 | u32 temp; |
| 601 | |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame^] | 602 | DRM_DEBUG_DRIVER("EOS interrupt occurs\n"); |
Shaohua Li | 0430296 | 2009-08-24 10:25:23 +0800 | [diff] [blame] | 603 | /* status is already cleared */ |
| 604 | temp = I915_READ(ADPA); |
| 605 | temp &= ~ADPA_DAC_ENABLE; |
| 606 | I915_WRITE(ADPA, temp); |
| 607 | |
| 608 | temp = I915_READ(PORT_HOTPLUG_EN); |
| 609 | temp &= ~CRT_EOS_INT_EN; |
| 610 | I915_WRITE(PORT_HOTPLUG_EN, temp); |
| 611 | |
| 612 | temp = I915_READ(PORT_HOTPLUG_STAT); |
| 613 | if (temp & CRT_EOS_INT_STATUS) |
| 614 | I915_WRITE(PORT_HOTPLUG_STAT, |
| 615 | CRT_EOS_INT_STATUS); |
| 616 | } |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 617 | } |
| 618 | |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 619 | I915_WRITE(IIR, iir); |
| 620 | new_iir = I915_READ(IIR); /* Flush posted writes */ |
Matthew Garrett | 8ee1c3d | 2008-08-05 19:37:25 +0100 | [diff] [blame] | 621 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 622 | if (dev->primary->master) { |
| 623 | master_priv = dev->primary->master->driver_priv; |
| 624 | if (master_priv->sarea_priv) |
| 625 | master_priv->sarea_priv->last_dispatch = |
| 626 | READ_BREADCRUMB(dev_priv); |
| 627 | } |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 628 | |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 629 | if (iir & I915_USER_INTERRUPT) { |
Chris Wilson | 1c5d22f | 2009-08-25 11:15:50 +0100 | [diff] [blame] | 630 | u32 seqno = i915_get_gem_seqno(dev); |
| 631 | dev_priv->mm.irq_gem_seqno = seqno; |
| 632 | trace_i915_gem_request_complete(dev, seqno); |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 633 | DRM_WAKEUP(&dev_priv->irq_queue); |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 634 | dev_priv->hangcheck_count = 0; |
| 635 | mod_timer(&dev_priv->hangcheck_timer, jiffies + DRM_I915_HANGCHECK_PERIOD); |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 636 | } |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 637 | |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 638 | if (pipea_stats & vblank_status) { |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 639 | vblank++; |
| 640 | drm_handle_vblank(dev, 0); |
| 641 | } |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 642 | |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 643 | if (pipeb_stats & vblank_status) { |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 644 | vblank++; |
| 645 | drm_handle_vblank(dev, 1); |
| 646 | } |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 647 | |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 648 | if ((pipeb_stats & I915_LEGACY_BLC_EVENT_STATUS) || |
| 649 | (iir & I915_ASLE_INTERRUPT)) |
| 650 | opregion_asle_intr(dev); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 651 | |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 652 | /* With MSI, interrupts are only generated when iir |
| 653 | * transitions from zero to nonzero. If another bit got |
| 654 | * set while we were handling the existing iir bits, then |
| 655 | * we would never get another interrupt. |
| 656 | * |
| 657 | * This is fine on non-MSI as well, as if we hit this path |
| 658 | * we avoid exiting the interrupt handler only to generate |
| 659 | * another one. |
| 660 | * |
| 661 | * Note that for MSI this could cause a stray interrupt report |
| 662 | * if an interrupt landed in the time between writing IIR and |
| 663 | * the posting read. This should be rare enough to never |
| 664 | * trigger the 99% of 100,000 interrupts test for disabling |
| 665 | * stray interrupts. |
| 666 | */ |
| 667 | iir = new_iir; |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 668 | } |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 669 | |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 670 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 673 | static int i915_emit_irq(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | { |
| 675 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 676 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | RING_LOCALS; |
| 678 | |
| 679 | i915_kernel_lost_context(dev); |
| 680 | |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame^] | 681 | DRM_DEBUG_DRIVER("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 683 | dev_priv->counter++; |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 684 | if (dev_priv->counter > 0x7FFFFFFFUL) |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 685 | dev_priv->counter = 1; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 686 | if (master_priv->sarea_priv) |
| 687 | master_priv->sarea_priv->last_enqueue = dev_priv->counter; |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 688 | |
Keith Packard | 0baf823 | 2008-11-08 11:44:14 +1000 | [diff] [blame] | 689 | BEGIN_LP_RING(4); |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 690 | OUT_RING(MI_STORE_DWORD_INDEX); |
Keith Packard | 0baf823 | 2008-11-08 11:44:14 +1000 | [diff] [blame] | 691 | OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT); |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 692 | OUT_RING(dev_priv->counter); |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 693 | OUT_RING(MI_USER_INTERRUPT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | ADVANCE_LP_RING(); |
Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 695 | |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 696 | return dev_priv->counter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | } |
| 698 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 699 | void i915_user_irq_get(struct drm_device *dev) |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 700 | { |
| 701 | 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] | 702 | unsigned long irqflags; |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 703 | |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 704 | spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 705 | if (dev->irq_enabled && (++dev_priv->user_irq_refcount == 1)) { |
| 706 | if (IS_IGDNG(dev)) |
| 707 | igdng_enable_graphics_irq(dev_priv, GT_USER_INTERRUPT); |
| 708 | else |
| 709 | i915_enable_irq(dev_priv, I915_USER_INTERRUPT); |
| 710 | } |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 711 | spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 712 | } |
| 713 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 714 | void i915_user_irq_put(struct drm_device *dev) |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 715 | { |
| 716 | 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] | 717 | unsigned long irqflags; |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 718 | |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 719 | spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 720 | BUG_ON(dev->irq_enabled && dev_priv->user_irq_refcount <= 0); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 721 | if (dev->irq_enabled && (--dev_priv->user_irq_refcount == 0)) { |
| 722 | if (IS_IGDNG(dev)) |
| 723 | igdng_disable_graphics_irq(dev_priv, GT_USER_INTERRUPT); |
| 724 | else |
| 725 | i915_disable_irq(dev_priv, I915_USER_INTERRUPT); |
| 726 | } |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 727 | spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Chris Wilson | 9d34e5d | 2009-09-24 05:26:06 +0100 | [diff] [blame] | 730 | void i915_trace_irq_get(struct drm_device *dev, u32 seqno) |
| 731 | { |
| 732 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 733 | |
| 734 | if (dev_priv->trace_irq_seqno == 0) |
| 735 | i915_user_irq_get(dev); |
| 736 | |
| 737 | dev_priv->trace_irq_seqno = seqno; |
| 738 | } |
| 739 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 740 | static int i915_wait_irq(struct drm_device * dev, int irq_nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | { |
| 742 | 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] | 743 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | int ret = 0; |
| 745 | |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame^] | 746 | DRM_DEBUG_DRIVER("irq_nr=%d breadcrumb=%d\n", irq_nr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | READ_BREADCRUMB(dev_priv)); |
| 748 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 749 | if (READ_BREADCRUMB(dev_priv) >= irq_nr) { |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 750 | if (master_priv->sarea_priv) |
| 751 | master_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | return 0; |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 753 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 755 | if (master_priv->sarea_priv) |
| 756 | master_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 758 | i915_user_irq_get(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ, |
| 760 | READ_BREADCRUMB(dev_priv) >= irq_nr); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 761 | i915_user_irq_put(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 763 | if (ret == -EBUSY) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 764 | DRM_ERROR("EBUSY -- rec: %d emitted: %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | READ_BREADCRUMB(dev_priv), (int)dev_priv->counter); |
| 766 | } |
| 767 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 768 | return ret; |
| 769 | } |
| 770 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | /* Needs the lock as it touches the ring. |
| 772 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 773 | int i915_irq_emit(struct drm_device *dev, void *data, |
| 774 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 777 | drm_i915_irq_emit_t *emit = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | int result; |
| 779 | |
Eric Anholt | 07f4f8b | 2009-04-16 13:46:12 -0700 | [diff] [blame] | 780 | if (!dev_priv || !dev_priv->ring.virtual_start) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 781 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 782 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | } |
Eric Anholt | 299eb93 | 2009-02-24 22:14:12 -0800 | [diff] [blame] | 784 | |
| 785 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
| 786 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 787 | mutex_lock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | result = i915_emit_irq(dev); |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 789 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 791 | if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | DRM_ERROR("copy_to_user\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 793 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | return 0; |
| 797 | } |
| 798 | |
| 799 | /* Doesn't need the hardware lock. |
| 800 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 801 | int i915_irq_wait(struct drm_device *dev, void *data, |
| 802 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 805 | drm_i915_irq_wait_t *irqwait = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | |
| 807 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 808 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 809 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 812 | return i915_wait_irq(dev, irqwait->irq_seq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | } |
| 814 | |
Keith Packard | 42f52ef | 2008-10-18 19:39:29 -0700 | [diff] [blame] | 815 | /* Called from drm generic code, passed 'crtc' which |
| 816 | * we use as a pipe index |
| 817 | */ |
| 818 | int i915_enable_vblank(struct drm_device *dev, int pipe) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 819 | { |
| 820 | 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] | 821 | unsigned long irqflags; |
Jesse Barnes | 71e0ffa | 2009-01-08 10:42:15 -0800 | [diff] [blame] | 822 | int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF; |
| 823 | u32 pipeconf; |
| 824 | |
| 825 | pipeconf = I915_READ(pipeconf_reg); |
| 826 | if (!(pipeconf & PIPEACONF_ENABLE)) |
| 827 | return -EINVAL; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 828 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 829 | if (IS_IGDNG(dev)) |
| 830 | return 0; |
| 831 | |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 832 | spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 833 | if (IS_I965G(dev)) |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 834 | i915_enable_pipestat(dev_priv, pipe, |
| 835 | PIPE_START_VBLANK_INTERRUPT_ENABLE); |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 836 | else |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 837 | i915_enable_pipestat(dev_priv, pipe, |
| 838 | PIPE_VBLANK_INTERRUPT_ENABLE); |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 839 | spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 840 | return 0; |
| 841 | } |
| 842 | |
Keith Packard | 42f52ef | 2008-10-18 19:39:29 -0700 | [diff] [blame] | 843 | /* Called from drm generic code, passed 'crtc' which |
| 844 | * we use as a pipe index |
| 845 | */ |
| 846 | void i915_disable_vblank(struct drm_device *dev, int pipe) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 847 | { |
| 848 | 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] | 849 | unsigned long irqflags; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 850 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 851 | if (IS_IGDNG(dev)) |
| 852 | return; |
| 853 | |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 854 | spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 855 | i915_disable_pipestat(dev_priv, pipe, |
| 856 | PIPE_VBLANK_INTERRUPT_ENABLE | |
| 857 | PIPE_START_VBLANK_INTERRUPT_ENABLE); |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 858 | spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 859 | } |
| 860 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 861 | void i915_enable_interrupt (struct drm_device *dev) |
| 862 | { |
| 863 | struct drm_i915_private *dev_priv = dev->dev_private; |
Zhenyu Wang | e170b03 | 2009-06-05 15:38:40 +0800 | [diff] [blame] | 864 | |
| 865 | if (!IS_IGDNG(dev)) |
| 866 | opregion_enable_asle(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 867 | dev_priv->irq_enabled = 1; |
| 868 | } |
| 869 | |
| 870 | |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 871 | /* Set the vblank monitor pipe |
| 872 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 873 | int i915_vblank_pipe_set(struct drm_device *dev, void *data, |
| 874 | struct drm_file *file_priv) |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 875 | { |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 876 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 877 | |
| 878 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 879 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 880 | return -EINVAL; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 881 | } |
| 882 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 5b51694 | 2006-10-25 00:08:23 +1000 | [diff] [blame] | 883 | return 0; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 884 | } |
| 885 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 886 | int i915_vblank_pipe_get(struct drm_device *dev, void *data, |
| 887 | struct drm_file *file_priv) |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 888 | { |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 889 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 890 | drm_i915_vblank_pipe_t *pipe = data; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 891 | |
| 892 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 893 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 894 | return -EINVAL; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 895 | } |
| 896 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 897 | pipe->pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 898 | |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 899 | return 0; |
| 900 | } |
| 901 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 902 | /** |
| 903 | * Schedule buffer swap at given vertical blank. |
| 904 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 905 | int i915_vblank_swap(struct drm_device *dev, void *data, |
| 906 | struct drm_file *file_priv) |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 907 | { |
Eric Anholt | bd95e0a | 2008-11-04 12:01:24 -0800 | [diff] [blame] | 908 | /* The delayed swap mechanism was fundamentally racy, and has been |
| 909 | * removed. The model was that the client requested a delayed flip/swap |
| 910 | * from the kernel, then waited for vblank before continuing to perform |
| 911 | * rendering. The problem was that the kernel might wake the client |
| 912 | * up before it dispatched the vblank swap (since the lock has to be |
| 913 | * held while touching the ringbuffer), in which case the client would |
| 914 | * clear and start the next frame before the swap occurred, and |
| 915 | * flicker would occur in addition to likely missing the vblank. |
| 916 | * |
| 917 | * In the absence of this ioctl, userland falls back to a correct path |
| 918 | * of waiting for a vblank, then dispatching the swap on its own. |
| 919 | * Context switching to userland and back is plenty fast enough for |
| 920 | * meeting the requirements of vblank swapping. |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 921 | */ |
Eric Anholt | bd95e0a | 2008-11-04 12:01:24 -0800 | [diff] [blame] | 922 | return -EINVAL; |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 923 | } |
| 924 | |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 925 | struct drm_i915_gem_request *i915_get_tail_request(struct drm_device *dev) { |
| 926 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 927 | return list_entry(dev_priv->mm.request_list.prev, struct drm_i915_gem_request, list); |
| 928 | } |
| 929 | |
| 930 | /** |
| 931 | * This is called when the chip hasn't reported back with completed |
| 932 | * batchbuffers in a long time. The first time this is called we simply record |
| 933 | * ACTHD. If ACTHD hasn't changed by the time the hangcheck timer elapses |
| 934 | * again, we assume the chip is wedged and try to fix it. |
| 935 | */ |
| 936 | void i915_hangcheck_elapsed(unsigned long data) |
| 937 | { |
| 938 | struct drm_device *dev = (struct drm_device *)data; |
| 939 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 940 | uint32_t acthd; |
| 941 | |
| 942 | if (!IS_I965G(dev)) |
| 943 | acthd = I915_READ(ACTHD); |
| 944 | else |
| 945 | acthd = I915_READ(ACTHD_I965); |
| 946 | |
| 947 | /* If all work is done then ACTHD clearly hasn't advanced. */ |
| 948 | if (list_empty(&dev_priv->mm.request_list) || |
| 949 | i915_seqno_passed(i915_get_gem_seqno(dev), i915_get_tail_request(dev)->seqno)) { |
| 950 | dev_priv->hangcheck_count = 0; |
| 951 | return; |
| 952 | } |
| 953 | |
| 954 | if (dev_priv->last_acthd == acthd && dev_priv->hangcheck_count > 0) { |
| 955 | DRM_ERROR("Hangcheck timer elapsed... GPU hung\n"); |
Ben Gamari | ba1234d | 2009-09-14 17:48:47 -0400 | [diff] [blame] | 956 | i915_handle_error(dev, true); |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 957 | return; |
| 958 | } |
| 959 | |
| 960 | /* Reset timer case chip hangs without another request being added */ |
| 961 | mod_timer(&dev_priv->hangcheck_timer, jiffies + DRM_I915_HANGCHECK_PERIOD); |
| 962 | |
| 963 | if (acthd != dev_priv->last_acthd) |
| 964 | dev_priv->hangcheck_count = 0; |
| 965 | else |
| 966 | dev_priv->hangcheck_count++; |
| 967 | |
| 968 | dev_priv->last_acthd = acthd; |
| 969 | } |
| 970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | /* drm_dma.h hooks |
| 972 | */ |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 973 | static void igdng_irq_preinstall(struct drm_device *dev) |
| 974 | { |
| 975 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 976 | |
| 977 | I915_WRITE(HWSTAM, 0xeffe); |
| 978 | |
| 979 | /* XXX hotplug from PCH */ |
| 980 | |
| 981 | I915_WRITE(DEIMR, 0xffffffff); |
| 982 | I915_WRITE(DEIER, 0x0); |
| 983 | (void) I915_READ(DEIER); |
| 984 | |
| 985 | /* and GT */ |
| 986 | I915_WRITE(GTIMR, 0xffffffff); |
| 987 | I915_WRITE(GTIER, 0x0); |
| 988 | (void) I915_READ(GTIER); |
| 989 | } |
| 990 | |
| 991 | static int igdng_irq_postinstall(struct drm_device *dev) |
| 992 | { |
| 993 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 994 | /* enable kind of interrupts always enabled */ |
| 995 | u32 display_mask = DE_MASTER_IRQ_CONTROL /*| DE_PCH_EVENT */; |
| 996 | u32 render_mask = GT_USER_INTERRUPT; |
| 997 | |
| 998 | dev_priv->irq_mask_reg = ~display_mask; |
| 999 | dev_priv->de_irq_enable_reg = display_mask; |
| 1000 | |
| 1001 | /* should always can generate irq */ |
| 1002 | I915_WRITE(DEIIR, I915_READ(DEIIR)); |
| 1003 | I915_WRITE(DEIMR, dev_priv->irq_mask_reg); |
| 1004 | I915_WRITE(DEIER, dev_priv->de_irq_enable_reg); |
| 1005 | (void) I915_READ(DEIER); |
| 1006 | |
| 1007 | /* user interrupt should be enabled, but masked initial */ |
| 1008 | dev_priv->gt_irq_mask_reg = 0xffffffff; |
| 1009 | dev_priv->gt_irq_enable_reg = render_mask; |
| 1010 | |
| 1011 | I915_WRITE(GTIIR, I915_READ(GTIIR)); |
| 1012 | I915_WRITE(GTIMR, dev_priv->gt_irq_mask_reg); |
| 1013 | I915_WRITE(GTIER, dev_priv->gt_irq_enable_reg); |
| 1014 | (void) I915_READ(GTIER); |
| 1015 | |
| 1016 | return 0; |
| 1017 | } |
| 1018 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1019 | void i915_driver_irq_preinstall(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | { |
| 1021 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 1022 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1023 | atomic_set(&dev_priv->irq_received, 0); |
| 1024 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1025 | INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func); |
Jesse Barnes | 8a90523 | 2009-07-11 16:48:03 -0400 | [diff] [blame] | 1026 | INIT_WORK(&dev_priv->error_work, i915_error_work_func); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1027 | |
| 1028 | if (IS_IGDNG(dev)) { |
| 1029 | igdng_irq_preinstall(dev); |
| 1030 | return; |
| 1031 | } |
| 1032 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 1033 | if (I915_HAS_HOTPLUG(dev)) { |
| 1034 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
| 1035 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); |
| 1036 | } |
| 1037 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1038 | I915_WRITE(HWSTAM, 0xeffe); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1039 | I915_WRITE(PIPEASTAT, 0); |
| 1040 | I915_WRITE(PIPEBSTAT, 0); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1041 | I915_WRITE(IMR, 0xffffffff); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1042 | I915_WRITE(IER, 0x0); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1043 | (void) I915_READ(IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | } |
| 1045 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1046 | int i915_driver_irq_postinstall(struct drm_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | { |
| 1048 | 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] | 1049 | u32 enable_mask = I915_INTERRUPT_ENABLE_FIX | I915_INTERRUPT_ENABLE_VAR; |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 1050 | u32 error_mask; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1051 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1052 | DRM_INIT_WAITQUEUE(&dev_priv->irq_queue); |
| 1053 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1054 | 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] | 1055 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1056 | if (IS_IGDNG(dev)) |
| 1057 | return igdng_irq_postinstall(dev); |
| 1058 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1059 | /* Unmask the interrupts that we always want on. */ |
| 1060 | dev_priv->irq_mask_reg = ~I915_INTERRUPT_ENABLE_FIX; |
Matthew Garrett | 8ee1c3d | 2008-08-05 19:37:25 +0100 | [diff] [blame] | 1061 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1062 | dev_priv->pipestat[0] = 0; |
| 1063 | dev_priv->pipestat[1] = 0; |
| 1064 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 1065 | if (I915_HAS_HOTPLUG(dev)) { |
| 1066 | u32 hotplug_en = I915_READ(PORT_HOTPLUG_EN); |
| 1067 | |
| 1068 | /* Leave other bits alone */ |
| 1069 | hotplug_en |= HOTPLUG_EN_MASK; |
| 1070 | I915_WRITE(PORT_HOTPLUG_EN, hotplug_en); |
| 1071 | |
| 1072 | dev_priv->hotplug_supported_mask = CRT_HOTPLUG_INT_STATUS | |
| 1073 | TV_HOTPLUG_INT_STATUS | SDVOC_HOTPLUG_INT_STATUS | |
| 1074 | SDVOB_HOTPLUG_INT_STATUS; |
| 1075 | if (IS_G4X(dev)) { |
| 1076 | dev_priv->hotplug_supported_mask |= |
| 1077 | HDMIB_HOTPLUG_INT_STATUS | |
| 1078 | HDMIC_HOTPLUG_INT_STATUS | |
| 1079 | HDMID_HOTPLUG_INT_STATUS; |
| 1080 | } |
| 1081 | /* Enable in IER... */ |
| 1082 | enable_mask |= I915_DISPLAY_PORT_INTERRUPT; |
| 1083 | /* and unmask in IMR */ |
| 1084 | i915_enable_irq(dev_priv, I915_DISPLAY_PORT_INTERRUPT); |
| 1085 | } |
| 1086 | |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 1087 | /* |
| 1088 | * Enable some error detection, note the instruction error mask |
| 1089 | * bit is reserved, so we leave it masked. |
| 1090 | */ |
| 1091 | if (IS_G4X(dev)) { |
| 1092 | error_mask = ~(GM45_ERROR_PAGE_TABLE | |
| 1093 | GM45_ERROR_MEM_PRIV | |
| 1094 | GM45_ERROR_CP_PRIV | |
| 1095 | I915_ERROR_MEMORY_REFRESH); |
| 1096 | } else { |
| 1097 | error_mask = ~(I915_ERROR_PAGE_TABLE | |
| 1098 | I915_ERROR_MEMORY_REFRESH); |
| 1099 | } |
| 1100 | I915_WRITE(EMR, error_mask); |
| 1101 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1102 | /* Disable pipe interrupt enables, clear pending pipe status */ |
| 1103 | I915_WRITE(PIPEASTAT, I915_READ(PIPEASTAT) & 0x8000ffff); |
| 1104 | I915_WRITE(PIPEBSTAT, I915_READ(PIPEBSTAT) & 0x8000ffff); |
| 1105 | /* Clear pending interrupt status */ |
| 1106 | I915_WRITE(IIR, I915_READ(IIR)); |
| 1107 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 1108 | I915_WRITE(IER, enable_mask); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1109 | I915_WRITE(IMR, dev_priv->irq_mask_reg); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1110 | (void) I915_READ(IER); |
| 1111 | |
Matthew Garrett | 8ee1c3d | 2008-08-05 19:37:25 +0100 | [diff] [blame] | 1112 | opregion_enable_asle(dev); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1113 | |
| 1114 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | } |
| 1116 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1117 | static void igdng_irq_uninstall(struct drm_device *dev) |
| 1118 | { |
| 1119 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 1120 | I915_WRITE(HWSTAM, 0xffffffff); |
| 1121 | |
| 1122 | I915_WRITE(DEIMR, 0xffffffff); |
| 1123 | I915_WRITE(DEIER, 0x0); |
| 1124 | I915_WRITE(DEIIR, I915_READ(DEIIR)); |
| 1125 | |
| 1126 | I915_WRITE(GTIMR, 0xffffffff); |
| 1127 | I915_WRITE(GTIER, 0x0); |
| 1128 | I915_WRITE(GTIIR, I915_READ(GTIIR)); |
| 1129 | } |
| 1130 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1131 | void i915_driver_irq_uninstall(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | { |
| 1133 | 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] | 1134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | if (!dev_priv) |
| 1136 | return; |
| 1137 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1138 | dev_priv->vblank_pipe = 0; |
| 1139 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1140 | if (IS_IGDNG(dev)) { |
| 1141 | igdng_irq_uninstall(dev); |
| 1142 | return; |
| 1143 | } |
| 1144 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 1145 | if (I915_HAS_HOTPLUG(dev)) { |
| 1146 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
| 1147 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); |
| 1148 | } |
| 1149 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1150 | I915_WRITE(HWSTAM, 0xffffffff); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1151 | I915_WRITE(PIPEASTAT, 0); |
| 1152 | I915_WRITE(PIPEBSTAT, 0); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 1153 | I915_WRITE(IMR, 0xffffffff); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1154 | I915_WRITE(IER, 0x0); |
Dave Airlie | 91e3738 | 2006-02-18 15:17:04 +1100 | [diff] [blame] | 1155 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 1156 | I915_WRITE(PIPEASTAT, I915_READ(PIPEASTAT) & 0x8000ffff); |
| 1157 | I915_WRITE(PIPEBSTAT, I915_READ(PIPEBSTAT) & 0x8000ffff); |
| 1158 | I915_WRITE(IIR, I915_READ(IIR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | } |