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 | |
| 29 | #include "drmP.h" |
| 30 | #include "drm.h" |
| 31 | #include "i915_drm.h" |
| 32 | #include "i915_drv.h" |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 33 | #include "intel_drv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #define MAX_NOPID ((u32)~0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 37 | /** |
| 38 | * Interrupts that are always left unmasked. |
| 39 | * |
| 40 | * Since pipe events are edge-triggered from the PIPESTAT register to IIR, |
| 41 | * we leave them always unmasked in IMR and then control enabling them through |
| 42 | * PIPESTAT alone. |
| 43 | */ |
| 44 | #define I915_INTERRUPT_ENABLE_FIX (I915_ASLE_INTERRUPT | \ |
| 45 | I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | \ |
| 46 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT) |
| 47 | |
| 48 | /** Interrupts that we mask and unmask at runtime. */ |
| 49 | #define I915_INTERRUPT_ENABLE_VAR (I915_USER_INTERRUPT) |
| 50 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 51 | #define I915_PIPE_VBLANK_STATUS (PIPE_START_VBLANK_INTERRUPT_STATUS |\ |
| 52 | PIPE_VBLANK_INTERRUPT_STATUS) |
| 53 | |
| 54 | #define I915_PIPE_VBLANK_ENABLE (PIPE_START_VBLANK_INTERRUPT_ENABLE |\ |
| 55 | PIPE_VBLANK_INTERRUPT_ENABLE) |
| 56 | |
| 57 | #define DRM_I915_VBLANK_PIPE_ALL (DRM_I915_VBLANK_PIPE_A | \ |
| 58 | DRM_I915_VBLANK_PIPE_B) |
| 59 | |
Matthew Garrett | 8ee1c3d | 2008-08-05 19:37:25 +0100 | [diff] [blame] | 60 | void |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 61 | igdng_enable_graphics_irq(drm_i915_private_t *dev_priv, u32 mask) |
| 62 | { |
| 63 | if ((dev_priv->gt_irq_mask_reg & mask) != 0) { |
| 64 | dev_priv->gt_irq_mask_reg &= ~mask; |
| 65 | I915_WRITE(GTIMR, dev_priv->gt_irq_mask_reg); |
| 66 | (void) I915_READ(GTIMR); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | static inline void |
| 71 | igdng_disable_graphics_irq(drm_i915_private_t *dev_priv, u32 mask) |
| 72 | { |
| 73 | if ((dev_priv->gt_irq_mask_reg & mask) != mask) { |
| 74 | dev_priv->gt_irq_mask_reg |= mask; |
| 75 | I915_WRITE(GTIMR, dev_priv->gt_irq_mask_reg); |
| 76 | (void) I915_READ(GTIMR); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | /* For display hotplug interrupt */ |
| 81 | void |
| 82 | igdng_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask) |
| 83 | { |
| 84 | if ((dev_priv->irq_mask_reg & mask) != 0) { |
| 85 | dev_priv->irq_mask_reg &= ~mask; |
| 86 | I915_WRITE(DEIMR, dev_priv->irq_mask_reg); |
| 87 | (void) I915_READ(DEIMR); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | static inline void |
| 92 | igdng_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask) |
| 93 | { |
| 94 | if ((dev_priv->irq_mask_reg & mask) != mask) { |
| 95 | dev_priv->irq_mask_reg |= mask; |
| 96 | I915_WRITE(DEIMR, dev_priv->irq_mask_reg); |
| 97 | (void) I915_READ(DEIMR); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | void |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 102 | i915_enable_irq(drm_i915_private_t *dev_priv, u32 mask) |
| 103 | { |
| 104 | if ((dev_priv->irq_mask_reg & mask) != 0) { |
| 105 | dev_priv->irq_mask_reg &= ~mask; |
| 106 | I915_WRITE(IMR, dev_priv->irq_mask_reg); |
| 107 | (void) I915_READ(IMR); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | static inline void |
| 112 | i915_disable_irq(drm_i915_private_t *dev_priv, u32 mask) |
| 113 | { |
| 114 | if ((dev_priv->irq_mask_reg & mask) != mask) { |
| 115 | dev_priv->irq_mask_reg |= mask; |
| 116 | I915_WRITE(IMR, dev_priv->irq_mask_reg); |
| 117 | (void) I915_READ(IMR); |
| 118 | } |
| 119 | } |
| 120 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 121 | static inline u32 |
| 122 | i915_pipestat(int pipe) |
| 123 | { |
| 124 | if (pipe == 0) |
| 125 | return PIPEASTAT; |
| 126 | if (pipe == 1) |
| 127 | return PIPEBSTAT; |
Andrew Morton | 9c84ba4 | 2008-12-01 13:14:08 -0800 | [diff] [blame] | 128 | BUG(); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | void |
| 132 | i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask) |
| 133 | { |
| 134 | if ((dev_priv->pipestat[pipe] & mask) != mask) { |
| 135 | u32 reg = i915_pipestat(pipe); |
| 136 | |
| 137 | dev_priv->pipestat[pipe] |= mask; |
| 138 | /* Enable the interrupt, clear any pending status */ |
| 139 | I915_WRITE(reg, dev_priv->pipestat[pipe] | (mask >> 16)); |
| 140 | (void) I915_READ(reg); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | void |
| 145 | i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask) |
| 146 | { |
| 147 | if ((dev_priv->pipestat[pipe] & mask) != 0) { |
| 148 | u32 reg = i915_pipestat(pipe); |
| 149 | |
| 150 | dev_priv->pipestat[pipe] &= ~mask; |
| 151 | I915_WRITE(reg, dev_priv->pipestat[pipe]); |
| 152 | (void) I915_READ(reg); |
| 153 | } |
| 154 | } |
| 155 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 156 | /** |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 157 | * i915_pipe_enabled - check if a pipe is enabled |
| 158 | * @dev: DRM device |
| 159 | * @pipe: pipe to check |
| 160 | * |
| 161 | * Reading certain registers when the pipe is disabled can hang the chip. |
| 162 | * Use this routine to make sure the PLL is running and the pipe is active |
| 163 | * before reading such registers if unsure. |
| 164 | */ |
| 165 | static int |
| 166 | i915_pipe_enabled(struct drm_device *dev, int pipe) |
| 167 | { |
| 168 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 169 | unsigned long pipeconf = pipe ? PIPEBCONF : PIPEACONF; |
| 170 | |
| 171 | if (I915_READ(pipeconf) & PIPEACONF_ENABLE) |
| 172 | return 1; |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
Keith Packard | 42f52ef | 2008-10-18 19:39:29 -0700 | [diff] [blame] | 177 | /* Called from drm generic code, passed a 'crtc', which |
| 178 | * we use as a pipe index |
| 179 | */ |
| 180 | u32 i915_get_vblank_counter(struct drm_device *dev, int pipe) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 181 | { |
| 182 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 183 | unsigned long high_frame; |
| 184 | unsigned long low_frame; |
| 185 | u32 high1, high2, low, count; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 186 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 187 | high_frame = pipe ? PIPEBFRAMEHIGH : PIPEAFRAMEHIGH; |
| 188 | low_frame = pipe ? PIPEBFRAMEPIXEL : PIPEAFRAMEPIXEL; |
| 189 | |
| 190 | if (!i915_pipe_enabled(dev, pipe)) { |
| 191 | DRM_ERROR("trying to get vblank count for disabled pipe %d\n", pipe); |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | /* |
| 196 | * High & low register fields aren't synchronized, so make sure |
| 197 | * we get a low value that's stable across two reads of the high |
| 198 | * register. |
| 199 | */ |
| 200 | do { |
| 201 | high1 = ((I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >> |
| 202 | PIPE_FRAME_HIGH_SHIFT); |
| 203 | low = ((I915_READ(low_frame) & PIPE_FRAME_LOW_MASK) >> |
| 204 | PIPE_FRAME_LOW_SHIFT); |
| 205 | high2 = ((I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >> |
| 206 | PIPE_FRAME_HIGH_SHIFT); |
| 207 | } while (high1 != high2); |
| 208 | |
| 209 | count = (high1 << 8) | low; |
| 210 | |
| 211 | return count; |
| 212 | } |
| 213 | |
Jesse Barnes | 9880b7a | 2009-02-06 10:22:41 -0800 | [diff] [blame] | 214 | u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe) |
| 215 | { |
| 216 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 217 | int reg = pipe ? PIPEB_FRMCOUNT_GM45 : PIPEA_FRMCOUNT_GM45; |
| 218 | |
| 219 | if (!i915_pipe_enabled(dev, pipe)) { |
| 220 | DRM_ERROR("trying to get vblank count for disabled pipe %d\n", pipe); |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | return I915_READ(reg); |
| 225 | } |
| 226 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 227 | /* |
| 228 | * Handle hotplug events outside the interrupt handler proper. |
| 229 | */ |
| 230 | static void i915_hotplug_work_func(struct work_struct *work) |
| 231 | { |
| 232 | drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, |
| 233 | hotplug_work); |
| 234 | struct drm_device *dev = dev_priv->dev; |
| 235 | |
| 236 | /* Just fire off a uevent and let userspace tell us what to do */ |
| 237 | drm_sysfs_hotplug_event(dev); |
| 238 | } |
| 239 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 240 | irqreturn_t igdng_irq_handler(struct drm_device *dev) |
| 241 | { |
| 242 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 243 | int ret = IRQ_NONE; |
| 244 | u32 de_iir, gt_iir; |
| 245 | u32 new_de_iir, new_gt_iir; |
| 246 | struct drm_i915_master_private *master_priv; |
| 247 | |
| 248 | de_iir = I915_READ(DEIIR); |
| 249 | gt_iir = I915_READ(GTIIR); |
| 250 | |
| 251 | for (;;) { |
| 252 | if (de_iir == 0 && gt_iir == 0) |
| 253 | break; |
| 254 | |
| 255 | ret = IRQ_HANDLED; |
| 256 | |
| 257 | I915_WRITE(DEIIR, de_iir); |
| 258 | new_de_iir = I915_READ(DEIIR); |
| 259 | I915_WRITE(GTIIR, gt_iir); |
| 260 | new_gt_iir = I915_READ(GTIIR); |
| 261 | |
| 262 | if (dev->primary->master) { |
| 263 | master_priv = dev->primary->master->driver_priv; |
| 264 | if (master_priv->sarea_priv) |
| 265 | master_priv->sarea_priv->last_dispatch = |
| 266 | READ_BREADCRUMB(dev_priv); |
| 267 | } |
| 268 | |
| 269 | if (gt_iir & GT_USER_INTERRUPT) { |
| 270 | dev_priv->mm.irq_gem_seqno = i915_get_gem_seqno(dev); |
| 271 | DRM_WAKEUP(&dev_priv->irq_queue); |
| 272 | } |
| 273 | |
| 274 | de_iir = new_de_iir; |
| 275 | gt_iir = new_gt_iir; |
| 276 | } |
| 277 | |
| 278 | return ret; |
| 279 | } |
| 280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS) |
| 282 | { |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 283 | struct drm_device *dev = (struct drm_device *) arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | 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] | 285 | struct drm_i915_master_private *master_priv; |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 286 | u32 iir, new_iir; |
| 287 | u32 pipea_stats, pipeb_stats; |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 288 | u32 vblank_status; |
| 289 | u32 vblank_enable; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 290 | int vblank = 0; |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 291 | unsigned long irqflags; |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 292 | int irq_received; |
| 293 | int ret = IRQ_NONE; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 294 | |
Eric Anholt | 630681d | 2008-10-06 15:14:12 -0700 | [diff] [blame] | 295 | atomic_inc(&dev_priv->irq_received); |
| 296 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 297 | if (IS_IGDNG(dev)) |
| 298 | return igdng_irq_handler(dev); |
| 299 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 300 | iir = I915_READ(IIR); |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 301 | |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 302 | if (IS_I965G(dev)) { |
| 303 | vblank_status = I915_START_VBLANK_INTERRUPT_STATUS; |
| 304 | vblank_enable = PIPE_START_VBLANK_INTERRUPT_ENABLE; |
| 305 | } else { |
| 306 | vblank_status = I915_VBLANK_INTERRUPT_STATUS; |
| 307 | vblank_enable = I915_VBLANK_INTERRUPT_ENABLE; |
| 308 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 310 | for (;;) { |
| 311 | irq_received = iir != 0; |
| 312 | |
| 313 | /* Can't rely on pipestat interrupt bit in iir as it might |
| 314 | * have been cleared after the pipestat interrupt was received. |
| 315 | * It doesn't set the bit in iir again, but it still produces |
| 316 | * interrupts (for non-MSI). |
| 317 | */ |
| 318 | spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); |
| 319 | pipea_stats = I915_READ(PIPEASTAT); |
| 320 | pipeb_stats = I915_READ(PIPEBSTAT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 321 | |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 322 | /* |
| 323 | * Clear the PIPE(A|B)STAT regs before the IIR |
| 324 | */ |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 325 | if (pipea_stats & 0x8000ffff) { |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 326 | I915_WRITE(PIPEASTAT, pipea_stats); |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 327 | irq_received = 1; |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 328 | } |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 329 | |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 330 | if (pipeb_stats & 0x8000ffff) { |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 331 | I915_WRITE(PIPEBSTAT, pipeb_stats); |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 332 | irq_received = 1; |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 333 | } |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 334 | spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags); |
| 335 | |
| 336 | if (!irq_received) |
| 337 | break; |
| 338 | |
| 339 | ret = IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 341 | /* Consume port. Then clear IIR or we'll miss events */ |
| 342 | if ((I915_HAS_HOTPLUG(dev)) && |
| 343 | (iir & I915_DISPLAY_PORT_INTERRUPT)) { |
| 344 | u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); |
| 345 | |
| 346 | DRM_DEBUG("hotplug event received, stat 0x%08x\n", |
| 347 | hotplug_status); |
| 348 | if (hotplug_status & dev_priv->hotplug_supported_mask) |
| 349 | schedule_work(&dev_priv->hotplug_work); |
| 350 | |
| 351 | I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); |
| 352 | I915_READ(PORT_HOTPLUG_STAT); |
| 353 | } |
| 354 | |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 355 | I915_WRITE(IIR, iir); |
| 356 | new_iir = I915_READ(IIR); /* Flush posted writes */ |
Matthew Garrett | 8ee1c3d | 2008-08-05 19:37:25 +0100 | [diff] [blame] | 357 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 358 | if (dev->primary->master) { |
| 359 | master_priv = dev->primary->master->driver_priv; |
| 360 | if (master_priv->sarea_priv) |
| 361 | master_priv->sarea_priv->last_dispatch = |
| 362 | READ_BREADCRUMB(dev_priv); |
| 363 | } |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 364 | |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 365 | if (iir & I915_USER_INTERRUPT) { |
| 366 | dev_priv->mm.irq_gem_seqno = i915_get_gem_seqno(dev); |
| 367 | DRM_WAKEUP(&dev_priv->irq_queue); |
| 368 | } |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 369 | |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 370 | if (pipea_stats & vblank_status) { |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 371 | vblank++; |
| 372 | drm_handle_vblank(dev, 0); |
| 373 | } |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 374 | |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 375 | if (pipeb_stats & vblank_status) { |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 376 | vblank++; |
| 377 | drm_handle_vblank(dev, 1); |
| 378 | } |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 379 | |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 380 | if ((pipeb_stats & I915_LEGACY_BLC_EVENT_STATUS) || |
| 381 | (iir & I915_ASLE_INTERRUPT)) |
| 382 | opregion_asle_intr(dev); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 383 | |
Eric Anholt | cdfbc41 | 2008-11-04 15:50:30 -0800 | [diff] [blame] | 384 | /* With MSI, interrupts are only generated when iir |
| 385 | * transitions from zero to nonzero. If another bit got |
| 386 | * set while we were handling the existing iir bits, then |
| 387 | * we would never get another interrupt. |
| 388 | * |
| 389 | * This is fine on non-MSI as well, as if we hit this path |
| 390 | * we avoid exiting the interrupt handler only to generate |
| 391 | * another one. |
| 392 | * |
| 393 | * Note that for MSI this could cause a stray interrupt report |
| 394 | * if an interrupt landed in the time between writing IIR and |
| 395 | * the posting read. This should be rare enough to never |
| 396 | * trigger the 99% of 100,000 interrupts test for disabling |
| 397 | * stray interrupts. |
| 398 | */ |
| 399 | iir = new_iir; |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 400 | } |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 401 | |
Keith Packard | 05eff84 | 2008-11-19 14:03:05 -0800 | [diff] [blame] | 402 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 405 | static int i915_emit_irq(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | { |
| 407 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 408 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | RING_LOCALS; |
| 410 | |
| 411 | i915_kernel_lost_context(dev); |
| 412 | |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 413 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 415 | dev_priv->counter++; |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 416 | if (dev_priv->counter > 0x7FFFFFFFUL) |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 417 | dev_priv->counter = 1; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 418 | if (master_priv->sarea_priv) |
| 419 | master_priv->sarea_priv->last_enqueue = dev_priv->counter; |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 420 | |
Keith Packard | 0baf823 | 2008-11-08 11:44:14 +1000 | [diff] [blame] | 421 | BEGIN_LP_RING(4); |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 422 | OUT_RING(MI_STORE_DWORD_INDEX); |
Keith Packard | 0baf823 | 2008-11-08 11:44:14 +1000 | [diff] [blame] | 423 | OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT); |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 424 | OUT_RING(dev_priv->counter); |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 425 | OUT_RING(MI_USER_INTERRUPT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | ADVANCE_LP_RING(); |
Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 427 | |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 428 | return dev_priv->counter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 431 | void i915_user_irq_get(struct drm_device *dev) |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 432 | { |
| 433 | 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] | 434 | unsigned long irqflags; |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 435 | |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 436 | spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 437 | if (dev->irq_enabled && (++dev_priv->user_irq_refcount == 1)) { |
| 438 | if (IS_IGDNG(dev)) |
| 439 | igdng_enable_graphics_irq(dev_priv, GT_USER_INTERRUPT); |
| 440 | else |
| 441 | i915_enable_irq(dev_priv, I915_USER_INTERRUPT); |
| 442 | } |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 443 | spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 444 | } |
| 445 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 446 | void i915_user_irq_put(struct drm_device *dev) |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 447 | { |
| 448 | 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] | 449 | unsigned long irqflags; |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 450 | |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 451 | spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 452 | BUG_ON(dev->irq_enabled && dev_priv->user_irq_refcount <= 0); |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 453 | if (dev->irq_enabled && (--dev_priv->user_irq_refcount == 0)) { |
| 454 | if (IS_IGDNG(dev)) |
| 455 | igdng_disable_graphics_irq(dev_priv, GT_USER_INTERRUPT); |
| 456 | else |
| 457 | i915_disable_irq(dev_priv, I915_USER_INTERRUPT); |
| 458 | } |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 459 | spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 462 | static int i915_wait_irq(struct drm_device * dev, int irq_nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | { |
| 464 | 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] | 465 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | int ret = 0; |
| 467 | |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 468 | DRM_DEBUG("irq_nr=%d breadcrumb=%d\n", irq_nr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | READ_BREADCRUMB(dev_priv)); |
| 470 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 471 | if (READ_BREADCRUMB(dev_priv) >= irq_nr) { |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 472 | if (master_priv->sarea_priv) |
| 473 | master_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | return 0; |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 475 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 477 | if (master_priv->sarea_priv) |
| 478 | master_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 480 | i915_user_irq_get(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ, |
| 482 | READ_BREADCRUMB(dev_priv) >= irq_nr); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 483 | i915_user_irq_put(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 485 | if (ret == -EBUSY) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 486 | DRM_ERROR("EBUSY -- rec: %d emitted: %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | READ_BREADCRUMB(dev_priv), (int)dev_priv->counter); |
| 488 | } |
| 489 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 490 | return ret; |
| 491 | } |
| 492 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | /* Needs the lock as it touches the ring. |
| 494 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 495 | int i915_irq_emit(struct drm_device *dev, void *data, |
| 496 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 499 | drm_i915_irq_emit_t *emit = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | int result; |
| 501 | |
Eric Anholt | 07f4f8b | 2009-04-16 13:46:12 -0700 | [diff] [blame] | 502 | if (!dev_priv || !dev_priv->ring.virtual_start) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 503 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 504 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | } |
Eric Anholt | 299eb93 | 2009-02-24 22:14:12 -0800 | [diff] [blame] | 506 | |
| 507 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
| 508 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 509 | mutex_lock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | result = i915_emit_irq(dev); |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 511 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 513 | if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | DRM_ERROR("copy_to_user\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 515 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | return 0; |
| 519 | } |
| 520 | |
| 521 | /* Doesn't need the hardware lock. |
| 522 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 523 | int i915_irq_wait(struct drm_device *dev, void *data, |
| 524 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 527 | drm_i915_irq_wait_t *irqwait = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
| 529 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 530 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 531 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 534 | return i915_wait_irq(dev, irqwait->irq_seq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Keith Packard | 42f52ef | 2008-10-18 19:39:29 -0700 | [diff] [blame] | 537 | /* Called from drm generic code, passed 'crtc' which |
| 538 | * we use as a pipe index |
| 539 | */ |
| 540 | int i915_enable_vblank(struct drm_device *dev, int pipe) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 541 | { |
| 542 | 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] | 543 | unsigned long irqflags; |
Jesse Barnes | 71e0ffa | 2009-01-08 10:42:15 -0800 | [diff] [blame] | 544 | int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF; |
| 545 | u32 pipeconf; |
| 546 | |
| 547 | pipeconf = I915_READ(pipeconf_reg); |
| 548 | if (!(pipeconf & PIPEACONF_ENABLE)) |
| 549 | return -EINVAL; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 550 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 551 | if (IS_IGDNG(dev)) |
| 552 | return 0; |
| 553 | |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 554 | spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 555 | if (IS_I965G(dev)) |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 556 | i915_enable_pipestat(dev_priv, pipe, |
| 557 | PIPE_START_VBLANK_INTERRUPT_ENABLE); |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 558 | else |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 559 | i915_enable_pipestat(dev_priv, pipe, |
| 560 | PIPE_VBLANK_INTERRUPT_ENABLE); |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 561 | spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 562 | return 0; |
| 563 | } |
| 564 | |
Keith Packard | 42f52ef | 2008-10-18 19:39:29 -0700 | [diff] [blame] | 565 | /* Called from drm generic code, passed 'crtc' which |
| 566 | * we use as a pipe index |
| 567 | */ |
| 568 | void i915_disable_vblank(struct drm_device *dev, int pipe) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 569 | { |
| 570 | 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] | 571 | unsigned long irqflags; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 572 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 573 | if (IS_IGDNG(dev)) |
| 574 | return; |
| 575 | |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 576 | spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 577 | i915_disable_pipestat(dev_priv, pipe, |
| 578 | PIPE_VBLANK_INTERRUPT_ENABLE | |
| 579 | PIPE_START_VBLANK_INTERRUPT_ENABLE); |
Keith Packard | e9d21d7 | 2008-10-16 11:31:38 -0700 | [diff] [blame] | 580 | spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 581 | } |
| 582 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 583 | void i915_enable_interrupt (struct drm_device *dev) |
| 584 | { |
| 585 | struct drm_i915_private *dev_priv = dev->dev_private; |
Zhenyu Wang | e170b03 | 2009-06-05 15:38:40 +0800 | [diff] [blame] | 586 | |
| 587 | if (!IS_IGDNG(dev)) |
| 588 | opregion_enable_asle(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 589 | dev_priv->irq_enabled = 1; |
| 590 | } |
| 591 | |
| 592 | |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 593 | /* Set the vblank monitor pipe |
| 594 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 595 | int i915_vblank_pipe_set(struct drm_device *dev, void *data, |
| 596 | struct drm_file *file_priv) |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 597 | { |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 598 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 599 | |
| 600 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 601 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 602 | return -EINVAL; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 603 | } |
| 604 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 5b51694 | 2006-10-25 00:08:23 +1000 | [diff] [blame] | 605 | return 0; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 606 | } |
| 607 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 608 | int i915_vblank_pipe_get(struct drm_device *dev, void *data, |
| 609 | struct drm_file *file_priv) |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 610 | { |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 611 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 612 | drm_i915_vblank_pipe_t *pipe = data; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 613 | |
| 614 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 615 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 616 | return -EINVAL; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 617 | } |
| 618 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 619 | pipe->pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 620 | |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 621 | return 0; |
| 622 | } |
| 623 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 624 | /** |
| 625 | * Schedule buffer swap at given vertical blank. |
| 626 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 627 | int i915_vblank_swap(struct drm_device *dev, void *data, |
| 628 | struct drm_file *file_priv) |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 629 | { |
Eric Anholt | bd95e0a | 2008-11-04 12:01:24 -0800 | [diff] [blame] | 630 | /* The delayed swap mechanism was fundamentally racy, and has been |
| 631 | * removed. The model was that the client requested a delayed flip/swap |
| 632 | * from the kernel, then waited for vblank before continuing to perform |
| 633 | * rendering. The problem was that the kernel might wake the client |
| 634 | * up before it dispatched the vblank swap (since the lock has to be |
| 635 | * held while touching the ringbuffer), in which case the client would |
| 636 | * clear and start the next frame before the swap occurred, and |
| 637 | * flicker would occur in addition to likely missing the vblank. |
| 638 | * |
| 639 | * In the absence of this ioctl, userland falls back to a correct path |
| 640 | * of waiting for a vblank, then dispatching the swap on its own. |
| 641 | * Context switching to userland and back is plenty fast enough for |
| 642 | * meeting the requirements of vblank swapping. |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 643 | */ |
Eric Anholt | bd95e0a | 2008-11-04 12:01:24 -0800 | [diff] [blame] | 644 | return -EINVAL; |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 645 | } |
| 646 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | /* drm_dma.h hooks |
| 648 | */ |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 649 | static void igdng_irq_preinstall(struct drm_device *dev) |
| 650 | { |
| 651 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 652 | |
| 653 | I915_WRITE(HWSTAM, 0xeffe); |
| 654 | |
| 655 | /* XXX hotplug from PCH */ |
| 656 | |
| 657 | I915_WRITE(DEIMR, 0xffffffff); |
| 658 | I915_WRITE(DEIER, 0x0); |
| 659 | (void) I915_READ(DEIER); |
| 660 | |
| 661 | /* and GT */ |
| 662 | I915_WRITE(GTIMR, 0xffffffff); |
| 663 | I915_WRITE(GTIER, 0x0); |
| 664 | (void) I915_READ(GTIER); |
| 665 | } |
| 666 | |
| 667 | static int igdng_irq_postinstall(struct drm_device *dev) |
| 668 | { |
| 669 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 670 | /* enable kind of interrupts always enabled */ |
| 671 | u32 display_mask = DE_MASTER_IRQ_CONTROL /*| DE_PCH_EVENT */; |
| 672 | u32 render_mask = GT_USER_INTERRUPT; |
| 673 | |
| 674 | dev_priv->irq_mask_reg = ~display_mask; |
| 675 | dev_priv->de_irq_enable_reg = display_mask; |
| 676 | |
| 677 | /* should always can generate irq */ |
| 678 | I915_WRITE(DEIIR, I915_READ(DEIIR)); |
| 679 | I915_WRITE(DEIMR, dev_priv->irq_mask_reg); |
| 680 | I915_WRITE(DEIER, dev_priv->de_irq_enable_reg); |
| 681 | (void) I915_READ(DEIER); |
| 682 | |
| 683 | /* user interrupt should be enabled, but masked initial */ |
| 684 | dev_priv->gt_irq_mask_reg = 0xffffffff; |
| 685 | dev_priv->gt_irq_enable_reg = render_mask; |
| 686 | |
| 687 | I915_WRITE(GTIIR, I915_READ(GTIIR)); |
| 688 | I915_WRITE(GTIMR, dev_priv->gt_irq_mask_reg); |
| 689 | I915_WRITE(GTIER, dev_priv->gt_irq_enable_reg); |
| 690 | (void) I915_READ(GTIER); |
| 691 | |
| 692 | return 0; |
| 693 | } |
| 694 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 695 | void i915_driver_irq_preinstall(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | { |
| 697 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 698 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 699 | atomic_set(&dev_priv->irq_received, 0); |
| 700 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 701 | INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func); |
| 702 | |
| 703 | if (IS_IGDNG(dev)) { |
| 704 | igdng_irq_preinstall(dev); |
| 705 | return; |
| 706 | } |
| 707 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 708 | if (I915_HAS_HOTPLUG(dev)) { |
| 709 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
| 710 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); |
| 711 | } |
| 712 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 713 | I915_WRITE(HWSTAM, 0xeffe); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 714 | I915_WRITE(PIPEASTAT, 0); |
| 715 | I915_WRITE(PIPEBSTAT, 0); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 716 | I915_WRITE(IMR, 0xffffffff); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 717 | I915_WRITE(IER, 0x0); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 718 | (void) I915_READ(IER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 721 | int i915_driver_irq_postinstall(struct drm_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | { |
| 723 | 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] | 724 | u32 enable_mask = I915_INTERRUPT_ENABLE_FIX | I915_INTERRUPT_ENABLE_VAR; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 725 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 726 | DRM_INIT_WAITQUEUE(&dev_priv->irq_queue); |
| 727 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 728 | 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] | 729 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 730 | if (IS_IGDNG(dev)) |
| 731 | return igdng_irq_postinstall(dev); |
| 732 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 733 | /* Unmask the interrupts that we always want on. */ |
| 734 | dev_priv->irq_mask_reg = ~I915_INTERRUPT_ENABLE_FIX; |
Matthew Garrett | 8ee1c3d | 2008-08-05 19:37:25 +0100 | [diff] [blame] | 735 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 736 | dev_priv->pipestat[0] = 0; |
| 737 | dev_priv->pipestat[1] = 0; |
| 738 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 739 | if (I915_HAS_HOTPLUG(dev)) { |
| 740 | u32 hotplug_en = I915_READ(PORT_HOTPLUG_EN); |
| 741 | |
| 742 | /* Leave other bits alone */ |
| 743 | hotplug_en |= HOTPLUG_EN_MASK; |
| 744 | I915_WRITE(PORT_HOTPLUG_EN, hotplug_en); |
| 745 | |
| 746 | dev_priv->hotplug_supported_mask = CRT_HOTPLUG_INT_STATUS | |
| 747 | TV_HOTPLUG_INT_STATUS | SDVOC_HOTPLUG_INT_STATUS | |
| 748 | SDVOB_HOTPLUG_INT_STATUS; |
| 749 | if (IS_G4X(dev)) { |
| 750 | dev_priv->hotplug_supported_mask |= |
| 751 | HDMIB_HOTPLUG_INT_STATUS | |
| 752 | HDMIC_HOTPLUG_INT_STATUS | |
| 753 | HDMID_HOTPLUG_INT_STATUS; |
| 754 | } |
| 755 | /* Enable in IER... */ |
| 756 | enable_mask |= I915_DISPLAY_PORT_INTERRUPT; |
| 757 | /* and unmask in IMR */ |
| 758 | i915_enable_irq(dev_priv, I915_DISPLAY_PORT_INTERRUPT); |
| 759 | } |
| 760 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 761 | /* Disable pipe interrupt enables, clear pending pipe status */ |
| 762 | I915_WRITE(PIPEASTAT, I915_READ(PIPEASTAT) & 0x8000ffff); |
| 763 | I915_WRITE(PIPEBSTAT, I915_READ(PIPEBSTAT) & 0x8000ffff); |
| 764 | /* Clear pending interrupt status */ |
| 765 | I915_WRITE(IIR, I915_READ(IIR)); |
| 766 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 767 | I915_WRITE(IER, enable_mask); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 768 | I915_WRITE(IMR, dev_priv->irq_mask_reg); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 769 | (void) I915_READ(IER); |
| 770 | |
Matthew Garrett | 8ee1c3d | 2008-08-05 19:37:25 +0100 | [diff] [blame] | 771 | opregion_enable_asle(dev); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 772 | |
| 773 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | } |
| 775 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 776 | static void igdng_irq_uninstall(struct drm_device *dev) |
| 777 | { |
| 778 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 779 | I915_WRITE(HWSTAM, 0xffffffff); |
| 780 | |
| 781 | I915_WRITE(DEIMR, 0xffffffff); |
| 782 | I915_WRITE(DEIER, 0x0); |
| 783 | I915_WRITE(DEIIR, I915_READ(DEIIR)); |
| 784 | |
| 785 | I915_WRITE(GTIMR, 0xffffffff); |
| 786 | I915_WRITE(GTIER, 0x0); |
| 787 | I915_WRITE(GTIIR, I915_READ(GTIIR)); |
| 788 | } |
| 789 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 790 | void i915_driver_irq_uninstall(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | { |
| 792 | 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] | 793 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | if (!dev_priv) |
| 795 | return; |
| 796 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 797 | dev_priv->vblank_pipe = 0; |
| 798 | |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 799 | if (IS_IGDNG(dev)) { |
| 800 | igdng_irq_uninstall(dev); |
| 801 | return; |
| 802 | } |
| 803 | |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 804 | if (I915_HAS_HOTPLUG(dev)) { |
| 805 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
| 806 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); |
| 807 | } |
| 808 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 809 | I915_WRITE(HWSTAM, 0xffffffff); |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 810 | I915_WRITE(PIPEASTAT, 0); |
| 811 | I915_WRITE(PIPEBSTAT, 0); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 812 | I915_WRITE(IMR, 0xffffffff); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 813 | I915_WRITE(IER, 0x0); |
Dave Airlie | 91e3738 | 2006-02-18 15:17:04 +1100 | [diff] [blame] | 814 | |
Keith Packard | 7c46358 | 2008-11-04 02:03:27 -0800 | [diff] [blame] | 815 | I915_WRITE(PIPEASTAT, I915_READ(PIPEASTAT) & 0x8000ffff); |
| 816 | I915_WRITE(PIPEBSTAT, I915_READ(PIPEBSTAT) & 0x8000ffff); |
| 817 | I915_WRITE(IIR, I915_READ(IIR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | } |