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