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" |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #define MAX_NOPID ((u32)~0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 36 | /** These are the interrupts used by the driver */ |
| 37 | #define I915_INTERRUPT_ENABLE_MASK (I915_USER_INTERRUPT | \ |
| 38 | I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT | \ |
| 39 | I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT) |
| 40 | |
| 41 | static inline void |
| 42 | i915_enable_irq(drm_i915_private_t *dev_priv, u32 mask) |
| 43 | { |
| 44 | if ((dev_priv->irq_mask_reg & mask) != 0) { |
| 45 | dev_priv->irq_mask_reg &= ~mask; |
| 46 | I915_WRITE(IMR, dev_priv->irq_mask_reg); |
| 47 | (void) I915_READ(IMR); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | static inline void |
| 52 | i915_disable_irq(drm_i915_private_t *dev_priv, u32 mask) |
| 53 | { |
| 54 | if ((dev_priv->irq_mask_reg & mask) != mask) { |
| 55 | dev_priv->irq_mask_reg |= mask; |
| 56 | I915_WRITE(IMR, dev_priv->irq_mask_reg); |
| 57 | (void) I915_READ(IMR); |
| 58 | } |
| 59 | } |
| 60 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 61 | /** |
| 62 | * Emit blits for scheduled buffer swaps. |
| 63 | * |
| 64 | * This function will be called with the HW lock held. |
| 65 | */ |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 66 | static void i915_vblank_tasklet(struct drm_device *dev) |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 67 | { |
| 68 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 69 | unsigned long irqflags; |
=?utf-8?q?Michel_D=C3=A4nzer?= | 3188a24 | 2006-12-11 18:32:27 +1100 | [diff] [blame] | 70 | struct list_head *list, *tmp, hits, *hit; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 71 | int nhits, nrects, slice[2], upper[2], lower[2], i; |
| 72 | unsigned counter[2] = { atomic_read(&dev->vbl_received), |
| 73 | atomic_read(&dev->vbl_received2) }; |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 74 | struct drm_drawable_info *drw; |
=?utf-8?q?Michel_D=C3=A4nzer?= | 3188a24 | 2006-12-11 18:32:27 +1100 | [diff] [blame] | 75 | drm_i915_sarea_t *sarea_priv = dev_priv->sarea_priv; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 76 | u32 cpp = dev_priv->cpp; |
=?utf-8?q?Michel_D=C3=A4nzer?= | 3188a24 | 2006-12-11 18:32:27 +1100 | [diff] [blame] | 77 | u32 cmd = (cpp == 4) ? (XY_SRC_COPY_BLT_CMD | |
| 78 | XY_SRC_COPY_BLT_WRITE_ALPHA | |
| 79 | XY_SRC_COPY_BLT_WRITE_RGB) |
| 80 | : XY_SRC_COPY_BLT_CMD; |
Keith Packard | 7b832b5 | 2008-04-21 16:31:10 +1000 | [diff] [blame] | 81 | u32 src_pitch = sarea_priv->pitch * cpp; |
| 82 | u32 dst_pitch = sarea_priv->pitch * cpp; |
| 83 | u32 ropcpp = (0xcc << 16) | ((cpp - 1) << 24); |
=?utf-8?q?Michel_D=C3=A4nzer?= | 3188a24 | 2006-12-11 18:32:27 +1100 | [diff] [blame] | 84 | RING_LOCALS; |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 85 | |
Jesse Barnes | 3d25802 | 2008-07-01 12:32:52 -0700 | [diff] [blame] | 86 | if (IS_I965G(dev) && sarea_priv->front_tiled) { |
Keith Packard | 7b832b5 | 2008-04-21 16:31:10 +1000 | [diff] [blame] | 87 | cmd |= XY_SRC_COPY_BLT_DST_TILED; |
| 88 | dst_pitch >>= 2; |
| 89 | } |
Jesse Barnes | 3d25802 | 2008-07-01 12:32:52 -0700 | [diff] [blame] | 90 | if (IS_I965G(dev) && sarea_priv->back_tiled) { |
Keith Packard | 7b832b5 | 2008-04-21 16:31:10 +1000 | [diff] [blame] | 91 | cmd |= XY_SRC_COPY_BLT_SRC_TILED; |
| 92 | src_pitch >>= 2; |
| 93 | } |
| 94 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 95 | DRM_DEBUG("\n"); |
| 96 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 3188a24 | 2006-12-11 18:32:27 +1100 | [diff] [blame] | 97 | INIT_LIST_HEAD(&hits); |
| 98 | |
| 99 | nhits = nrects = 0; |
| 100 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 101 | spin_lock_irqsave(&dev_priv->swaps_lock, irqflags); |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 102 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 3188a24 | 2006-12-11 18:32:27 +1100 | [diff] [blame] | 103 | /* Find buffer swaps scheduled for this vertical blank */ |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 104 | list_for_each_safe(list, tmp, &dev_priv->vbl_swaps.head) { |
| 105 | drm_i915_vbl_swap_t *vbl_swap = |
| 106 | list_entry(list, drm_i915_vbl_swap_t, head); |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 107 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 108 | if ((counter[vbl_swap->pipe] - vbl_swap->sequence) > (1<<23)) |
=?utf-8?q?Michel_D=C3=A4nzer?= | 3188a24 | 2006-12-11 18:32:27 +1100 | [diff] [blame] | 109 | continue; |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 110 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 3188a24 | 2006-12-11 18:32:27 +1100 | [diff] [blame] | 111 | list_del(list); |
| 112 | dev_priv->swaps_pending--; |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 113 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 3188a24 | 2006-12-11 18:32:27 +1100 | [diff] [blame] | 114 | spin_unlock(&dev_priv->swaps_lock); |
| 115 | spin_lock(&dev->drw_lock); |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 116 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 3188a24 | 2006-12-11 18:32:27 +1100 | [diff] [blame] | 117 | drw = drm_get_drawable_info(dev, vbl_swap->drw_id); |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 118 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 3188a24 | 2006-12-11 18:32:27 +1100 | [diff] [blame] | 119 | if (!drw) { |
| 120 | spin_unlock(&dev->drw_lock); |
| 121 | drm_free(vbl_swap, sizeof(*vbl_swap), DRM_MEM_DRIVER); |
| 122 | spin_lock(&dev_priv->swaps_lock); |
| 123 | continue; |
| 124 | } |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 125 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 3188a24 | 2006-12-11 18:32:27 +1100 | [diff] [blame] | 126 | list_for_each(hit, &hits) { |
| 127 | drm_i915_vbl_swap_t *swap_cmp = |
| 128 | list_entry(hit, drm_i915_vbl_swap_t, head); |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 129 | struct drm_drawable_info *drw_cmp = |
=?utf-8?q?Michel_D=C3=A4nzer?= | 3188a24 | 2006-12-11 18:32:27 +1100 | [diff] [blame] | 130 | drm_get_drawable_info(dev, swap_cmp->drw_id); |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 131 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 3188a24 | 2006-12-11 18:32:27 +1100 | [diff] [blame] | 132 | if (drw_cmp && |
| 133 | drw_cmp->rects[0].y1 > drw->rects[0].y1) { |
| 134 | list_add_tail(list, hit); |
| 135 | break; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | spin_unlock(&dev->drw_lock); |
| 140 | |
| 141 | /* List of hits was empty, or we reached the end of it */ |
| 142 | if (hit == &hits) |
| 143 | list_add_tail(list, hits.prev); |
| 144 | |
| 145 | nhits++; |
| 146 | |
| 147 | spin_lock(&dev_priv->swaps_lock); |
| 148 | } |
| 149 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 150 | if (nhits == 0) { |
| 151 | spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags); |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 152 | return; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | spin_unlock(&dev_priv->swaps_lock); |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 156 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 3188a24 | 2006-12-11 18:32:27 +1100 | [diff] [blame] | 157 | i915_kernel_lost_context(dev); |
| 158 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 159 | if (IS_I965G(dev)) { |
| 160 | BEGIN_LP_RING(4); |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 161 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 162 | OUT_RING(GFX_OP_DRAWRECT_INFO_I965); |
| 163 | OUT_RING(0); |
| 164 | OUT_RING(((sarea_priv->width - 1) & 0xffff) | ((sarea_priv->height - 1) << 16)); |
| 165 | OUT_RING(0); |
| 166 | ADVANCE_LP_RING(); |
| 167 | } else { |
| 168 | BEGIN_LP_RING(6); |
| 169 | |
| 170 | OUT_RING(GFX_OP_DRAWRECT_INFO); |
| 171 | OUT_RING(0); |
| 172 | OUT_RING(0); |
| 173 | OUT_RING(sarea_priv->width | sarea_priv->height << 16); |
| 174 | OUT_RING(sarea_priv->width | sarea_priv->height << 16); |
| 175 | OUT_RING(0); |
| 176 | |
| 177 | ADVANCE_LP_RING(); |
| 178 | } |
| 179 | |
| 180 | sarea_priv->ctxOwner = DRM_KERNEL_CONTEXT; |
| 181 | |
| 182 | upper[0] = upper[1] = 0; |
| 183 | slice[0] = max(sarea_priv->pipeA_h / nhits, 1); |
| 184 | slice[1] = max(sarea_priv->pipeB_h / nhits, 1); |
| 185 | lower[0] = sarea_priv->pipeA_y + slice[0]; |
| 186 | lower[1] = sarea_priv->pipeB_y + slice[0]; |
=?utf-8?q?Michel_D=C3=A4nzer?= | 3188a24 | 2006-12-11 18:32:27 +1100 | [diff] [blame] | 187 | |
| 188 | spin_lock(&dev->drw_lock); |
| 189 | |
| 190 | /* Emit blits for buffer swaps, partitioning both outputs into as many |
| 191 | * slices as there are buffer swaps scheduled in order to avoid tearing |
| 192 | * (based on the assumption that a single buffer swap would always |
| 193 | * complete before scanout starts). |
| 194 | */ |
| 195 | for (i = 0; i++ < nhits; |
| 196 | upper[0] = lower[0], lower[0] += slice[0], |
| 197 | upper[1] = lower[1], lower[1] += slice[1]) { |
| 198 | if (i == nhits) |
| 199 | lower[0] = lower[1] = sarea_priv->height; |
| 200 | |
| 201 | list_for_each(hit, &hits) { |
| 202 | drm_i915_vbl_swap_t *swap_hit = |
| 203 | list_entry(hit, drm_i915_vbl_swap_t, head); |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 204 | struct drm_clip_rect *rect; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 205 | int num_rects, pipe; |
=?utf-8?q?Michel_D=C3=A4nzer?= | 3188a24 | 2006-12-11 18:32:27 +1100 | [diff] [blame] | 206 | unsigned short top, bottom; |
| 207 | |
| 208 | drw = drm_get_drawable_info(dev, swap_hit->drw_id); |
| 209 | |
| 210 | if (!drw) |
| 211 | continue; |
| 212 | |
| 213 | rect = drw->rects; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 214 | pipe = swap_hit->pipe; |
| 215 | top = upper[pipe]; |
| 216 | bottom = lower[pipe]; |
=?utf-8?q?Michel_D=C3=A4nzer?= | 3188a24 | 2006-12-11 18:32:27 +1100 | [diff] [blame] | 217 | |
| 218 | for (num_rects = drw->num_rects; num_rects--; rect++) { |
| 219 | int y1 = max(rect->y1, top); |
| 220 | int y2 = min(rect->y2, bottom); |
| 221 | |
| 222 | if (y1 >= y2) |
| 223 | continue; |
| 224 | |
| 225 | BEGIN_LP_RING(8); |
| 226 | |
| 227 | OUT_RING(cmd); |
Keith Packard | 7b832b5 | 2008-04-21 16:31:10 +1000 | [diff] [blame] | 228 | OUT_RING(ropcpp | dst_pitch); |
=?utf-8?q?Michel_D=C3=A4nzer?= | 3188a24 | 2006-12-11 18:32:27 +1100 | [diff] [blame] | 229 | OUT_RING((y1 << 16) | rect->x1); |
| 230 | OUT_RING((y2 << 16) | rect->x2); |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 231 | OUT_RING(sarea_priv->front_offset); |
=?utf-8?q?Michel_D=C3=A4nzer?= | 3188a24 | 2006-12-11 18:32:27 +1100 | [diff] [blame] | 232 | OUT_RING((y1 << 16) | rect->x1); |
Keith Packard | 7b832b5 | 2008-04-21 16:31:10 +1000 | [diff] [blame] | 233 | OUT_RING(src_pitch); |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 234 | OUT_RING(sarea_priv->back_offset); |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 235 | |
| 236 | ADVANCE_LP_RING(); |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 237 | } |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 241 | spin_unlock_irqrestore(&dev->drw_lock, irqflags); |
=?utf-8?q?Michel_D=C3=A4nzer?= | 3188a24 | 2006-12-11 18:32:27 +1100 | [diff] [blame] | 242 | |
| 243 | list_for_each_safe(hit, tmp, &hits) { |
| 244 | drm_i915_vbl_swap_t *swap_hit = |
| 245 | list_entry(hit, drm_i915_vbl_swap_t, head); |
| 246 | |
| 247 | list_del(hit); |
| 248 | |
| 249 | drm_free(swap_hit, sizeof(*swap_hit), DRM_MEM_DRIVER); |
| 250 | } |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 251 | } |
| 252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS) |
| 254 | { |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 255 | struct drm_device *dev = (struct drm_device *) arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Dave Airlie | e4a7b1d | 2007-09-28 11:46:28 +1000 | [diff] [blame] | 257 | u32 pipea_stats, pipeb_stats; |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 258 | u32 iir; |
Dave Airlie | e4a7b1d | 2007-09-28 11:46:28 +1000 | [diff] [blame] | 259 | |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 260 | pipea_stats = I915_READ(PIPEASTAT); |
| 261 | pipeb_stats = I915_READ(PIPEBSTAT); |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 262 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 263 | if (dev->pdev->msi_enabled) |
| 264 | I915_WRITE(IMR, ~0); |
| 265 | iir = I915_READ(IIR); |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 266 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 267 | DRM_DEBUG("iir=%08x\n", iir); |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 268 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 269 | if (iir == 0) { |
| 270 | if (dev->pdev->msi_enabled) { |
| 271 | I915_WRITE(IMR, dev_priv->irq_mask_reg); |
| 272 | (void) I915_READ(IMR); |
| 273 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | return IRQ_NONE; |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 275 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 277 | I915_WRITE(IIR, iir); |
| 278 | if (dev->pdev->msi_enabled) |
| 279 | I915_WRITE(IMR, dev_priv->irq_mask_reg); |
| 280 | (void) I915_READ(IIR); /* Flush posted writes */ |
Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 281 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 282 | dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv); |
Dave Airlie | 6e5fca5 | 2006-03-20 18:34:29 +1100 | [diff] [blame] | 283 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 284 | if (iir & I915_USER_INTERRUPT) |
Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 285 | DRM_WAKEUP(&dev_priv->irq_queue); |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 286 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 287 | if (iir & (I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT | |
| 288 | I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT)) { |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 289 | int vblank_pipe = dev_priv->vblank_pipe; |
| 290 | |
| 291 | if ((vblank_pipe & |
| 292 | (DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B)) |
| 293 | == (DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B)) { |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 294 | if (iir & I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT) |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 295 | atomic_inc(&dev->vbl_received); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 296 | if (iir & I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT) |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 297 | atomic_inc(&dev->vbl_received2); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 298 | } else if (((iir & I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT) && |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 299 | (vblank_pipe & DRM_I915_VBLANK_PIPE_A)) || |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 300 | ((iir & I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT) && |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 301 | (vblank_pipe & DRM_I915_VBLANK_PIPE_B))) |
| 302 | atomic_inc(&dev->vbl_received); |
| 303 | |
| 304 | DRM_WAKEUP(&dev->vbl_queue); |
| 305 | drm_vbl_send_signals(dev); |
| 306 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 2228ed6 | 2006-10-25 01:05:09 +1000 | [diff] [blame] | 307 | if (dev_priv->swaps_pending > 0) |
| 308 | drm_locked_tasklet(dev, i915_vblank_tasklet); |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 309 | I915_WRITE(PIPEASTAT, |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 310 | pipea_stats|I915_VBLANK_INTERRUPT_ENABLE| |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 311 | PIPE_VBLANK_INTERRUPT_STATUS); |
| 312 | I915_WRITE(PIPEBSTAT, |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 313 | pipeb_stats|I915_VBLANK_INTERRUPT_ENABLE| |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 314 | PIPE_VBLANK_INTERRUPT_STATUS); |
Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 315 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
| 317 | return IRQ_HANDLED; |
| 318 | } |
| 319 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 320 | static int i915_emit_irq(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | { |
| 322 | drm_i915_private_t *dev_priv = dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | RING_LOCALS; |
| 324 | |
| 325 | i915_kernel_lost_context(dev); |
| 326 | |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 327 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 329 | dev_priv->sarea_priv->last_enqueue = ++dev_priv->counter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 331 | if (dev_priv->counter > 0x7FFFFFFFUL) |
| 332 | dev_priv->sarea_priv->last_enqueue = dev_priv->counter = 1; |
| 333 | |
| 334 | BEGIN_LP_RING(6); |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 335 | OUT_RING(MI_STORE_DWORD_INDEX); |
| 336 | OUT_RING(5 << MI_STORE_DWORD_INDEX_SHIFT); |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 337 | OUT_RING(dev_priv->counter); |
| 338 | OUT_RING(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | OUT_RING(0); |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 340 | OUT_RING(MI_USER_INTERRUPT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | ADVANCE_LP_RING(); |
Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 342 | |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 343 | return dev_priv->counter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 346 | static void i915_user_irq_get(struct drm_device *dev) |
| 347 | { |
| 348 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 349 | |
| 350 | spin_lock(&dev_priv->user_irq_lock); |
| 351 | if (dev->irq_enabled && (++dev_priv->user_irq_refcount == 1)) |
| 352 | i915_enable_irq(dev_priv, I915_USER_INTERRUPT); |
| 353 | spin_unlock(&dev_priv->user_irq_lock); |
| 354 | } |
| 355 | |
| 356 | static void i915_user_irq_put(struct drm_device *dev) |
| 357 | { |
| 358 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 359 | |
| 360 | spin_lock(&dev_priv->user_irq_lock); |
| 361 | BUG_ON(dev->irq_enabled && dev_priv->user_irq_refcount <= 0); |
| 362 | if (dev->irq_enabled && (--dev_priv->user_irq_refcount == 0)) |
| 363 | i915_disable_irq(dev_priv, I915_USER_INTERRUPT); |
| 364 | spin_unlock(&dev_priv->user_irq_lock); |
| 365 | } |
| 366 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 367 | static int i915_wait_irq(struct drm_device * dev, int irq_nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | { |
| 369 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 370 | int ret = 0; |
| 371 | |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 372 | DRM_DEBUG("irq_nr=%d breadcrumb=%d\n", irq_nr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | READ_BREADCRUMB(dev_priv)); |
| 374 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 375 | if (READ_BREADCRUMB(dev_priv) >= irq_nr) { |
| 376 | dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | return 0; |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 378 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
| 380 | dev_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT; |
| 381 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 382 | i915_user_irq_get(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ, |
| 384 | READ_BREADCRUMB(dev_priv) >= irq_nr); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 385 | i915_user_irq_put(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 387 | if (ret == -EBUSY) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 388 | DRM_ERROR("EBUSY -- rec: %d emitted: %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | READ_BREADCRUMB(dev_priv), (int)dev_priv->counter); |
| 390 | } |
| 391 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 392 | dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | return ret; |
| 394 | } |
| 395 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 396 | static int i915_driver_vblank_do_wait(struct drm_device *dev, unsigned int *sequence, |
| 397 | atomic_t *counter) |
| 398 | { |
| 399 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 400 | unsigned int cur_vblank; |
| 401 | int ret = 0; |
| 402 | |
| 403 | if (!dev_priv) { |
| 404 | DRM_ERROR("called with no initialization\n"); |
| 405 | return -EINVAL; |
| 406 | } |
| 407 | |
| 408 | DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ, |
| 409 | (((cur_vblank = atomic_read(counter)) |
| 410 | - *sequence) <= (1<<23))); |
| 411 | |
| 412 | *sequence = cur_vblank; |
| 413 | |
| 414 | return ret; |
| 415 | } |
| 416 | |
| 417 | |
| 418 | int i915_driver_vblank_wait(struct drm_device *dev, unsigned int *sequence) |
| 419 | { |
| 420 | return i915_driver_vblank_do_wait(dev, sequence, &dev->vbl_received); |
| 421 | } |
| 422 | |
| 423 | int i915_driver_vblank_wait2(struct drm_device *dev, unsigned int *sequence) |
| 424 | { |
| 425 | return i915_driver_vblank_do_wait(dev, sequence, &dev->vbl_received2); |
| 426 | } |
| 427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | /* Needs the lock as it touches the ring. |
| 429 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 430 | int i915_irq_emit(struct drm_device *dev, void *data, |
| 431 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 434 | drm_i915_irq_emit_t *emit = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | int result; |
| 436 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 437 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
| 439 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 440 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 441 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | result = i915_emit_irq(dev); |
| 445 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 446 | if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | DRM_ERROR("copy_to_user\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 448 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | /* Doesn't need the hardware lock. |
| 455 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 456 | int i915_irq_wait(struct drm_device *dev, void *data, |
| 457 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 460 | drm_i915_irq_wait_t *irqwait = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | |
| 462 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 463 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 464 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 467 | return i915_wait_irq(dev, irqwait->irq_seq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 470 | /* Set the vblank monitor pipe |
| 471 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 472 | int i915_vblank_pipe_set(struct drm_device *dev, void *data, |
| 473 | struct drm_file *file_priv) |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 474 | { |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 475 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 476 | drm_i915_vblank_pipe_t *pipe = data; |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 477 | u32 enable_mask = 0, disable_mask = 0; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 478 | |
| 479 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 480 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 481 | return -EINVAL; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 482 | } |
| 483 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 484 | if (pipe->pipe & ~(DRM_I915_VBLANK_PIPE_A|DRM_I915_VBLANK_PIPE_B)) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 485 | DRM_ERROR("called with invalid pipe 0x%x\n", pipe->pipe); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 486 | return -EINVAL; |
=?utf-8?q?Michel_D=C3=A4nzer?= | 5b51694 | 2006-10-25 00:08:23 +1000 | [diff] [blame] | 487 | } |
| 488 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 489 | if (pipe->pipe & DRM_I915_VBLANK_PIPE_A) |
| 490 | enable_mask |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT; |
| 491 | else |
| 492 | disable_mask |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT; |
=?utf-8?q?Michel_D=C3=A4nzer?= | 5b51694 | 2006-10-25 00:08:23 +1000 | [diff] [blame] | 493 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 494 | if (pipe->pipe & DRM_I915_VBLANK_PIPE_B) |
| 495 | enable_mask |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; |
| 496 | else |
| 497 | disable_mask |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; |
| 498 | |
| 499 | i915_enable_irq(dev_priv, enable_mask); |
| 500 | i915_disable_irq(dev_priv, disable_mask); |
| 501 | |
| 502 | dev_priv->vblank_pipe = pipe->pipe; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 503 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 5b51694 | 2006-10-25 00:08:23 +1000 | [diff] [blame] | 504 | return 0; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 505 | } |
| 506 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 507 | int i915_vblank_pipe_get(struct drm_device *dev, void *data, |
| 508 | struct drm_file *file_priv) |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 509 | { |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 510 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 511 | drm_i915_vblank_pipe_t *pipe = data; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 512 | u16 flag; |
| 513 | |
| 514 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 515 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 516 | return -EINVAL; |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 517 | } |
| 518 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 519 | flag = I915_READ(IMR); |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 520 | pipe->pipe = 0; |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 521 | if (flag & I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT) |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 522 | pipe->pipe |= DRM_I915_VBLANK_PIPE_A; |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 523 | if (flag & I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT) |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 524 | pipe->pipe |= DRM_I915_VBLANK_PIPE_B; |
| 525 | |
Dave Airlie | 702880f | 2006-06-24 17:07:34 +1000 | [diff] [blame] | 526 | return 0; |
| 527 | } |
| 528 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 529 | /** |
| 530 | * Schedule buffer swap at given vertical blank. |
| 531 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 532 | int i915_vblank_swap(struct drm_device *dev, void *data, |
| 533 | struct drm_file *file_priv) |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 534 | { |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 535 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 536 | drm_i915_vblank_swap_t *swap = data; |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 537 | drm_i915_vbl_swap_t *vbl_swap; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 538 | unsigned int pipe, seqtype, curseq; |
=?utf-8?q?Michel_D=C3=A4nzer?= | a0b136b | 2006-10-25 00:12:52 +1000 | [diff] [blame] | 539 | unsigned long irqflags; |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 540 | struct list_head *list; |
| 541 | |
| 542 | if (!dev_priv) { |
| 543 | DRM_ERROR("%s called with no initialization\n", __func__); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 544 | return -EINVAL; |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 545 | } |
| 546 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 547 | if (dev_priv->sarea_priv->rotation) { |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 548 | DRM_DEBUG("Rotation not supported\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 549 | return -EINVAL; |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 550 | } |
| 551 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 552 | if (swap->seqtype & ~(_DRM_VBLANK_RELATIVE | _DRM_VBLANK_ABSOLUTE | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 553 | _DRM_VBLANK_SECONDARY | _DRM_VBLANK_NEXTONMISS)) { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 554 | DRM_ERROR("Invalid sequence type 0x%x\n", swap->seqtype); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 555 | return -EINVAL; |
=?utf-8?q?Michel_D=C3=A4nzer?= | 541f29a | 2006-10-24 23:38:54 +1000 | [diff] [blame] | 556 | } |
| 557 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 558 | pipe = (swap->seqtype & _DRM_VBLANK_SECONDARY) ? 1 : 0; |
=?utf-8?q?Michel_D=C3=A4nzer?= | 541f29a | 2006-10-24 23:38:54 +1000 | [diff] [blame] | 559 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 560 | seqtype = swap->seqtype & (_DRM_VBLANK_RELATIVE | _DRM_VBLANK_ABSOLUTE); |
=?utf-8?q?Michel_D=C3=A4nzer?= | 541f29a | 2006-10-24 23:38:54 +1000 | [diff] [blame] | 561 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 541f29a | 2006-10-24 23:38:54 +1000 | [diff] [blame] | 562 | if (!(dev_priv->vblank_pipe & (1 << pipe))) { |
| 563 | DRM_ERROR("Invalid pipe %d\n", pipe); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 564 | return -EINVAL; |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | spin_lock_irqsave(&dev->drw_lock, irqflags); |
| 568 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 569 | if (!drm_get_drawable_info(dev, swap->drawable)) { |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 570 | spin_unlock_irqrestore(&dev->drw_lock, irqflags); |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 571 | DRM_DEBUG("Invalid drawable ID %d\n", swap->drawable); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 572 | return -EINVAL; |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | spin_unlock_irqrestore(&dev->drw_lock, irqflags); |
| 576 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 577 | curseq = atomic_read(pipe ? &dev->vbl_received2 : &dev->vbl_received); |
=?utf-8?q?Michel_D=C3=A4nzer?= | 541f29a | 2006-10-24 23:38:54 +1000 | [diff] [blame] | 578 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 2228ed6 | 2006-10-25 01:05:09 +1000 | [diff] [blame] | 579 | if (seqtype == _DRM_VBLANK_RELATIVE) |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 580 | swap->sequence += curseq; |
=?utf-8?q?Michel_D=C3=A4nzer?= | 2228ed6 | 2006-10-25 01:05:09 +1000 | [diff] [blame] | 581 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 582 | if ((curseq - swap->sequence) <= (1<<23)) { |
| 583 | if (swap->seqtype & _DRM_VBLANK_NEXTONMISS) { |
| 584 | swap->sequence = curseq + 1; |
=?utf-8?q?Michel_D=C3=A4nzer?= | 2228ed6 | 2006-10-25 01:05:09 +1000 | [diff] [blame] | 585 | } else { |
=?utf-8?q?Michel_D=C3=A4nzer?= | 541f29a | 2006-10-24 23:38:54 +1000 | [diff] [blame] | 586 | DRM_DEBUG("Missed target sequence\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 587 | return -EINVAL; |
=?utf-8?q?Michel_D=C3=A4nzer?= | 541f29a | 2006-10-24 23:38:54 +1000 | [diff] [blame] | 588 | } |
=?utf-8?q?Michel_D=C3=A4nzer?= | 541f29a | 2006-10-24 23:38:54 +1000 | [diff] [blame] | 589 | } |
| 590 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 2228ed6 | 2006-10-25 01:05:09 +1000 | [diff] [blame] | 591 | spin_lock_irqsave(&dev_priv->swaps_lock, irqflags); |
| 592 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 593 | list_for_each(list, &dev_priv->vbl_swaps.head) { |
| 594 | vbl_swap = list_entry(list, drm_i915_vbl_swap_t, head); |
| 595 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 596 | if (vbl_swap->drw_id == swap->drawable && |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 597 | vbl_swap->pipe == pipe && |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 598 | vbl_swap->sequence == swap->sequence) { |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 599 | spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags); |
| 600 | DRM_DEBUG("Already scheduled\n"); |
| 601 | return 0; |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags); |
| 606 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 21fa60e | 2006-10-25 00:10:59 +1000 | [diff] [blame] | 607 | if (dev_priv->swaps_pending >= 100) { |
| 608 | DRM_DEBUG("Too many swaps queued\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 609 | return -EBUSY; |
=?utf-8?q?Michel_D=C3=A4nzer?= | 21fa60e | 2006-10-25 00:10:59 +1000 | [diff] [blame] | 610 | } |
| 611 | |
Dave Airlie | 54583bf | 2007-10-14 21:21:30 +1000 | [diff] [blame] | 612 | vbl_swap = drm_calloc(1, sizeof(*vbl_swap), DRM_MEM_DRIVER); |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 613 | |
| 614 | if (!vbl_swap) { |
| 615 | DRM_ERROR("Failed to allocate memory to queue swap\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 616 | return -ENOMEM; |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | DRM_DEBUG("\n"); |
| 620 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 621 | vbl_swap->drw_id = swap->drawable; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 622 | vbl_swap->pipe = pipe; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 623 | vbl_swap->sequence = swap->sequence; |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 624 | |
| 625 | spin_lock_irqsave(&dev_priv->swaps_lock, irqflags); |
| 626 | |
Li Zefan | d5b0d1b | 2007-12-17 09:47:19 +1000 | [diff] [blame] | 627 | list_add_tail(&vbl_swap->head, &dev_priv->vbl_swaps.head); |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 628 | dev_priv->swaps_pending++; |
| 629 | |
| 630 | spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags); |
| 631 | |
| 632 | return 0; |
| 633 | } |
| 634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | /* drm_dma.h hooks |
| 636 | */ |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 637 | void i915_driver_irq_preinstall(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | { |
| 639 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 640 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 641 | I915_WRITE(HWSTAM, 0xfffe); |
| 642 | I915_WRITE(IMR, 0x0); |
| 643 | I915_WRITE(IER, 0x0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | } |
| 645 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 646 | void i915_driver_irq_postinstall(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | { |
| 648 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 649 | |
Thomas Gleixner | a6399bd | 2007-05-26 05:56:14 +1000 | [diff] [blame] | 650 | spin_lock_init(&dev_priv->swaps_lock); |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 651 | INIT_LIST_HEAD(&dev_priv->vbl_swaps.head); |
| 652 | dev_priv->swaps_pending = 0; |
| 653 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 654 | if (!dev_priv->vblank_pipe) |
| 655 | dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A; |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 656 | |
| 657 | /* Set initial unmasked IRQs to just the selected vblank pipes. */ |
| 658 | dev_priv->irq_mask_reg = ~0; |
| 659 | if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_A) |
| 660 | dev_priv->irq_mask_reg &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT; |
| 661 | if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_B) |
| 662 | dev_priv->irq_mask_reg &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; |
| 663 | |
| 664 | I915_WRITE(IMR, dev_priv->irq_mask_reg); |
| 665 | I915_WRITE(IER, I915_INTERRUPT_ENABLE_MASK); |
| 666 | (void) I915_READ(IER); |
| 667 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | DRM_INIT_WAITQUEUE(&dev_priv->irq_queue); |
| 669 | } |
| 670 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 671 | void i915_driver_irq_uninstall(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | { |
| 673 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 674 | u16 temp; |
Dave Airlie | 91e3738 | 2006-02-18 15:17:04 +1100 | [diff] [blame] | 675 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | if (!dev_priv) |
| 677 | return; |
| 678 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 679 | I915_WRITE(HWSTAM, 0xffff); |
| 680 | I915_WRITE(IMR, 0xffff); |
| 681 | I915_WRITE(IER, 0x0); |
Dave Airlie | 91e3738 | 2006-02-18 15:17:04 +1100 | [diff] [blame] | 682 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame^] | 683 | temp = I915_READ(IIR); |
| 684 | I915_WRITE(IIR, temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | } |