1 /* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
4 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
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.
34 #define USER_INT_FLAG (1<<1)
35 #define VSYNC_PIPEB_FLAG (1<<5)
36 #define VSYNC_PIPEA_FLAG (1<<7)
38 #define MAX_NOPID ((u32)~0)
41 * i915_get_pipe - return the the pipe associated with a given plane
43 * @plane: plane to look for
45 * The Intel Mesa & 2D drivers call the vblank routines with a plane number
46 * rather than a pipe number, since they may not always be equal. This routine
47 * maps the given @plane back to a pipe number.
50 i915_get_pipe(struct drm_device *dev, int plane)
52 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
55 dspcntr = plane ? I915_READ(DSPBCNTR) : I915_READ(DSPACNTR);
57 return dspcntr & DISPPLANE_SEL_PIPE_MASK ? 1 : 0;
61 * i915_get_plane - return the the plane associated with a given pipe
63 * @pipe: pipe to look for
65 * The Intel Mesa & 2D drivers call the vblank routines with a plane number
66 * rather than a plane number, since they may not always be equal. This routine
67 * maps the given @pipe back to a plane number.
70 i915_get_plane(struct drm_device *dev, int pipe)
72 if (i915_get_pipe(dev, 0) == pipe)
78 * i915_pipe_enabled - check if a pipe is enabled
80 * @pipe: pipe to check
82 * Reading certain registers when the pipe is disabled can hang the chip.
83 * Use this routine to make sure the PLL is running and the pipe is active
84 * before reading such registers if unsure.
87 i915_pipe_enabled(struct drm_device *dev, int pipe)
89 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
90 unsigned long pipeconf = pipe ? PIPEBCONF : PIPEACONF;
92 if (I915_READ(pipeconf) & PIPEACONF_ENABLE)
99 * Emit a synchronous flip.
101 * This function must be called with the drawable spinlock held.
104 i915_dispatch_vsync_flip(struct drm_device *dev, struct drm_drawable_info *drw,
107 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
108 drm_i915_sarea_t *sarea_priv = dev_priv->sarea_priv;
110 int pf_planes = 1 << plane;
112 DRM_SPINLOCK_ASSERT(&dev->drw_lock);
114 /* If the window is visible on the other plane, we have to flip on that
118 x1 = sarea_priv->planeA_x;
119 y1 = sarea_priv->planeA_y;
120 x2 = x1 + sarea_priv->planeA_w;
121 y2 = y1 + sarea_priv->planeA_h;
123 x1 = sarea_priv->planeB_x;
124 y1 = sarea_priv->planeB_y;
125 x2 = x1 + sarea_priv->planeB_w;
126 y2 = y1 + sarea_priv->planeB_h;
129 if (x2 > 0 && y2 > 0) {
130 int i, num_rects = drw->num_rects;
131 struct drm_clip_rect *rect = drw->rects;
133 for (i = 0; i < num_rects; i++)
134 if (!(rect[i].x1 >= x2 || rect[i].y1 >= y2 ||
135 rect[i].x2 <= x1 || rect[i].y2 <= y1)) {
142 i915_dispatch_flip(dev, pf_planes, 1);
146 * Emit blits for scheduled buffer swaps.
148 * This function will be called with the HW lock held.
150 static void i915_vblank_tasklet(struct drm_device *dev)
152 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
153 struct list_head *list, *tmp, hits, *hit;
154 int nhits, nrects, slice[2], upper[2], lower[2], i, num_pages;
156 struct drm_drawable_info *drw;
157 drm_i915_sarea_t *sarea_priv = dev_priv->sarea_priv;
158 u32 cpp = dev_priv->cpp, offsets[3];
159 u32 cmd = (cpp == 4) ? (XY_SRC_COPY_BLT_CMD |
160 XY_SRC_COPY_BLT_WRITE_ALPHA |
161 XY_SRC_COPY_BLT_WRITE_RGB)
162 : XY_SRC_COPY_BLT_CMD;
163 u32 pitchropcpp = (sarea_priv->pitch * cpp) | (0xcc << 16) |
164 (cpp << 23) | (1 << 24);
167 counter[0] = drm_vblank_count(dev, 0);
168 counter[1] = drm_vblank_count(dev, 1);
172 INIT_LIST_HEAD(&hits);
176 /* No irqsave/restore necessary. This tasklet may be run in an
177 * interrupt context or normal context, but we don't have to worry
178 * about getting interrupted by something acquiring the lock, because
179 * we are the interrupt context thing that acquires the lock.
181 DRM_SPINLOCK(&dev_priv->swaps_lock);
183 /* Find buffer swaps scheduled for this vertical blank */
184 list_for_each_safe(list, tmp, &dev_priv->vbl_swaps.head) {
185 drm_i915_vbl_swap_t *vbl_swap =
186 list_entry(list, drm_i915_vbl_swap_t, head);
187 int pipe = i915_get_pipe(dev, vbl_swap->plane);
189 if ((counter[pipe] - vbl_swap->sequence) > (1<<23))
193 dev_priv->swaps_pending--;
194 drm_vblank_put(dev, pipe);
196 DRM_SPINUNLOCK(&dev_priv->swaps_lock);
197 DRM_SPINLOCK(&dev->drw_lock);
199 drw = drm_get_drawable_info(dev, vbl_swap->drw_id);
202 DRM_SPINUNLOCK(&dev->drw_lock);
203 drm_free(vbl_swap, sizeof(*vbl_swap), DRM_MEM_DRIVER);
204 DRM_SPINLOCK(&dev_priv->swaps_lock);
208 list_for_each(hit, &hits) {
209 drm_i915_vbl_swap_t *swap_cmp =
210 list_entry(hit, drm_i915_vbl_swap_t, head);
211 struct drm_drawable_info *drw_cmp =
212 drm_get_drawable_info(dev, swap_cmp->drw_id);
215 drw_cmp->rects[0].y1 > drw->rects[0].y1) {
216 list_add_tail(list, hit);
221 DRM_SPINUNLOCK(&dev->drw_lock);
223 /* List of hits was empty, or we reached the end of it */
225 list_add_tail(list, hits.prev);
229 DRM_SPINLOCK(&dev_priv->swaps_lock);
232 DRM_SPINUNLOCK(&dev_priv->swaps_lock);
238 i915_kernel_lost_context(dev);
240 upper[0] = upper[1] = 0;
241 slice[0] = max(sarea_priv->planeA_h / nhits, 1);
242 slice[1] = max(sarea_priv->planeB_h / nhits, 1);
243 lower[0] = sarea_priv->planeA_y + slice[0];
244 lower[1] = sarea_priv->planeB_y + slice[0];
246 offsets[0] = sarea_priv->front_offset;
247 offsets[1] = sarea_priv->back_offset;
248 offsets[2] = sarea_priv->third_offset;
249 num_pages = sarea_priv->third_handle ? 3 : 2;
251 DRM_SPINLOCK(&dev->drw_lock);
253 /* Emit blits for buffer swaps, partitioning both outputs into as many
254 * slices as there are buffer swaps scheduled in order to avoid tearing
255 * (based on the assumption that a single buffer swap would always
256 * complete before scanout starts).
258 for (i = 0; i++ < nhits;
259 upper[0] = lower[0], lower[0] += slice[0],
260 upper[1] = lower[1], lower[1] += slice[1]) {
261 int init_drawrect = 1;
264 lower[0] = lower[1] = sarea_priv->height;
266 list_for_each(hit, &hits) {
267 drm_i915_vbl_swap_t *swap_hit =
268 list_entry(hit, drm_i915_vbl_swap_t, head);
269 struct drm_clip_rect *rect;
270 int num_rects, plane, front, back;
271 unsigned short top, bottom;
273 drw = drm_get_drawable_info(dev, swap_hit->drw_id);
278 plane = swap_hit->plane;
280 if (swap_hit->flip) {
281 i915_dispatch_vsync_flip(dev, drw, plane);
288 OUT_RING(GFX_OP_DRAWRECT_INFO);
291 OUT_RING(sarea_priv->width | sarea_priv->height << 16);
292 OUT_RING(sarea_priv->width | sarea_priv->height << 16);
297 sarea_priv->ctxOwner = DRM_KERNEL_CONTEXT;
304 bottom = lower[plane];
306 front = (dev_priv->sarea_priv->pf_current_page >>
308 back = (front + 1) % num_pages;
310 for (num_rects = drw->num_rects; num_rects--; rect++) {
311 int y1 = max(rect->y1, top);
312 int y2 = min(rect->y2, bottom);
320 OUT_RING(pitchropcpp);
321 OUT_RING((y1 << 16) | rect->x1);
322 OUT_RING((y2 << 16) | rect->x2);
323 OUT_RING(offsets[front]);
324 OUT_RING((y1 << 16) | rect->x1);
325 OUT_RING(pitchropcpp & 0xffff);
326 OUT_RING(offsets[back]);
333 DRM_SPINUNLOCK(&dev->drw_lock);
335 list_for_each_safe(hit, tmp, &hits) {
336 drm_i915_vbl_swap_t *swap_hit =
337 list_entry(hit, drm_i915_vbl_swap_t, head);
341 drm_free(swap_hit, sizeof(*swap_hit), DRM_MEM_DRIVER);
345 static int i915_in_vblank(struct drm_device *dev, int pipe)
347 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
348 unsigned long pipedsl, vblank, vtotal;
349 unsigned long vbl_start, vbl_end, cur_line;
351 pipedsl = pipe ? PIPEBDSL : PIPEADSL;
352 vblank = pipe ? VBLANK_B : VBLANK_A;
353 vtotal = pipe ? VTOTAL_B : VTOTAL_A;
355 vbl_start = I915_READ(vblank) & VBLANK_START_MASK;
356 vbl_end = (I915_READ(vblank) >> VBLANK_END_SHIFT) & VBLANK_END_MASK;
358 cur_line = I915_READ(pipedsl);
360 if (cur_line >= vbl_start)
366 u32 i915_get_vblank_counter(struct drm_device *dev, int plane)
368 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
369 unsigned long high_frame;
370 unsigned long low_frame;
371 u32 high1, high2, low, count;
374 pipe = i915_get_pipe(dev, plane);
375 high_frame = pipe ? PIPEBFRAMEHIGH : PIPEAFRAMEHIGH;
376 low_frame = pipe ? PIPEBFRAMEPIXEL : PIPEAFRAMEPIXEL;
378 if (!i915_pipe_enabled(dev, pipe)) {
379 printk(KERN_ERR "trying to get vblank count for disabled "
385 * High & low register fields aren't synchronized, so make sure
386 * we get a low value that's stable across two reads of the high
390 high1 = ((I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >>
391 PIPE_FRAME_HIGH_SHIFT);
392 low = ((I915_READ(low_frame) & PIPE_FRAME_LOW_MASK) >>
393 PIPE_FRAME_LOW_SHIFT);
394 high2 = ((I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >>
395 PIPE_FRAME_HIGH_SHIFT);
396 } while (high1 != high2);
398 count = (high1 << 8) | low;
401 * If we're in the middle of the vblank period, the
402 * above regs won't have been updated yet, so return
403 * an incremented count to stay accurate
406 if (i915_in_vblank(dev, pipe))
412 irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
414 struct drm_device *dev = (struct drm_device *) arg;
415 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
417 u32 pipea_stats, pipeb_stats;
419 pipea_stats = I915_READ(I915REG_PIPEASTAT);
420 pipeb_stats = I915_READ(I915REG_PIPEBSTAT);
422 temp = I915_READ16(I915REG_INT_IDENTITY_R);
425 DRM_DEBUG("flag=%08x\n", temp);
431 * Clear the PIPE(A|B)STAT regs before the IIR otherwise
432 * we may get extra interrupts.
434 if (temp & VSYNC_PIPEA_FLAG) {
435 drm_handle_vblank(dev, i915_get_plane(dev, 0));
436 I915_WRITE(I915REG_PIPEASTAT,
437 pipea_stats | I915_VBLANK_INTERRUPT_ENABLE |
440 if (temp & VSYNC_PIPEB_FLAG) {
441 drm_handle_vblank(dev, i915_get_plane(dev, 1));
442 I915_WRITE(I915REG_PIPEBSTAT,
443 pipeb_stats | I915_VBLANK_INTERRUPT_ENABLE |
447 I915_WRITE16(I915REG_INT_IDENTITY_R, temp);
448 (void) I915_READ16(I915REG_INT_IDENTITY_R); /* Flush posted write */
450 temp &= (dev_priv->irq_enable_reg | USER_INT_FLAG | VSYNC_PIPEA_FLAG |
453 if (dev_priv->sarea_priv)
454 dev_priv->sarea_priv->last_dispatch =
455 READ_BREADCRUMB(dev_priv);
457 if (temp & USER_INT_FLAG) {
458 DRM_WAKEUP(&dev_priv->irq_queue);
459 #ifdef I915_HAVE_FENCE
460 i915_fence_handler(dev);
464 if (temp & (VSYNC_PIPEA_FLAG | VSYNC_PIPEB_FLAG)) {
465 if (dev_priv->swaps_pending > 0)
466 drm_locked_tasklet(dev, i915_vblank_tasklet);
472 int i915_emit_irq(struct drm_device *dev)
474 drm_i915_private_t *dev_priv = dev->dev_private;
477 i915_kernel_lost_context(dev);
481 i915_emit_breadcrumb(dev);
485 OUT_RING(GFX_OP_USER_INTERRUPT);
488 return dev_priv->counter;
491 void i915_user_irq_on(drm_i915_private_t *dev_priv)
493 DRM_SPINLOCK(&dev_priv->user_irq_lock);
494 if (dev_priv->irq_enabled && (++dev_priv->user_irq_refcount == 1)){
495 dev_priv->irq_enable_reg |= USER_INT_FLAG;
496 I915_WRITE16(I915REG_INT_ENABLE_R, dev_priv->irq_enable_reg);
498 DRM_SPINUNLOCK(&dev_priv->user_irq_lock);
502 void i915_user_irq_off(drm_i915_private_t *dev_priv)
504 DRM_SPINLOCK(&dev_priv->user_irq_lock);
505 if (dev_priv->irq_enabled && (--dev_priv->user_irq_refcount == 0)) {
506 // dev_priv->irq_enable_reg &= ~USER_INT_FLAG;
507 // I915_WRITE16(I915REG_INT_ENABLE_R, dev_priv->irq_enable_reg);
509 DRM_SPINUNLOCK(&dev_priv->user_irq_lock);
513 static int i915_wait_irq(struct drm_device * dev, int irq_nr)
515 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
518 DRM_DEBUG("irq_nr=%d breadcrumb=%d\n", irq_nr,
519 READ_BREADCRUMB(dev_priv));
521 if (READ_BREADCRUMB(dev_priv) >= irq_nr)
524 i915_user_irq_on(dev_priv);
525 DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ,
526 READ_BREADCRUMB(dev_priv) >= irq_nr);
527 i915_user_irq_off(dev_priv);
530 DRM_ERROR("EBUSY -- rec: %d emitted: %d\n",
531 READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
534 if (dev_priv->sarea_priv)
535 dev_priv->sarea_priv->last_dispatch =
536 READ_BREADCRUMB(dev_priv);
540 /* Needs the lock as it touches the ring.
542 int i915_irq_emit(struct drm_device *dev, void *data,
543 struct drm_file *file_priv)
545 drm_i915_private_t *dev_priv = dev->dev_private;
546 drm_i915_irq_emit_t *emit = data;
549 LOCK_TEST_WITH_RETURN(dev, file_priv);
552 DRM_ERROR("called with no initialization\n");
556 result = i915_emit_irq(dev);
558 if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) {
559 DRM_ERROR("copy_to_user\n");
566 /* Doesn't need the hardware lock.
568 int i915_irq_wait(struct drm_device *dev, void *data,
569 struct drm_file *file_priv)
571 drm_i915_private_t *dev_priv = dev->dev_private;
572 drm_i915_irq_wait_t *irqwait = data;
575 DRM_ERROR("called with no initialization\n");
579 return i915_wait_irq(dev, irqwait->irq_seq);
582 int i915_enable_vblank(struct drm_device *dev, int plane)
584 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
585 int pipe = i915_get_pipe(dev, plane);
589 dev_priv->irq_enable_reg |= VSYNC_PIPEA_FLAG;
592 dev_priv->irq_enable_reg |= VSYNC_PIPEB_FLAG;
595 DRM_ERROR("tried to enable vblank on non-existent pipe %d\n",
600 I915_WRITE16(I915REG_INT_ENABLE_R, dev_priv->irq_enable_reg);
605 void i915_disable_vblank(struct drm_device *dev, int plane)
607 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
608 int pipe = i915_get_pipe(dev, plane);
612 dev_priv->irq_enable_reg &= ~VSYNC_PIPEA_FLAG;
615 dev_priv->irq_enable_reg &= ~VSYNC_PIPEB_FLAG;
618 DRM_ERROR("tried to disable vblank on non-existent pipe %d\n",
623 I915_WRITE16(I915REG_INT_ENABLE_R, dev_priv->irq_enable_reg);
626 static void i915_enable_interrupt (struct drm_device *dev)
628 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
630 dev_priv->irq_enable_reg |= USER_INT_FLAG;
632 I915_WRITE16(I915REG_INT_ENABLE_R, dev_priv->irq_enable_reg);
633 dev_priv->irq_enabled = 1;
636 /* Set the vblank monitor pipe
638 int i915_vblank_pipe_set(struct drm_device *dev, void *data,
639 struct drm_file *file_priv)
641 drm_i915_private_t *dev_priv = dev->dev_private;
642 drm_i915_vblank_pipe_t *pipe = data;
645 DRM_ERROR("called with no initialization\n");
649 if (pipe->pipe & ~(DRM_I915_VBLANK_PIPE_A|DRM_I915_VBLANK_PIPE_B)) {
650 DRM_ERROR("called with invalid pipe 0x%x\n", pipe->pipe);
654 dev_priv->vblank_pipe = pipe->pipe;
659 int i915_vblank_pipe_get(struct drm_device *dev, void *data,
660 struct drm_file *file_priv)
662 drm_i915_private_t *dev_priv = dev->dev_private;
663 drm_i915_vblank_pipe_t *pipe = data;
667 DRM_ERROR("called with no initialization\n");
671 flag = I915_READ(I915REG_INT_ENABLE_R);
673 if (flag & VSYNC_PIPEA_FLAG)
674 pipe->pipe |= DRM_I915_VBLANK_PIPE_A;
675 if (flag & VSYNC_PIPEB_FLAG)
676 pipe->pipe |= DRM_I915_VBLANK_PIPE_B;
682 * Schedule buffer swap at given vertical blank.
684 int i915_vblank_swap(struct drm_device *dev, void *data,
685 struct drm_file *file_priv)
687 drm_i915_private_t *dev_priv = dev->dev_private;
688 drm_i915_vblank_swap_t *swap = data;
689 drm_i915_vbl_swap_t *vbl_swap;
690 unsigned int pipe, seqtype, curseq, plane;
691 unsigned long irqflags;
692 struct list_head *list;
696 DRM_ERROR("%s called with no initialization\n", __func__);
700 if (!dev_priv->sarea_priv || dev_priv->sarea_priv->rotation) {
701 DRM_DEBUG("Rotation not supported\n");
705 if (swap->seqtype & ~(_DRM_VBLANK_RELATIVE | _DRM_VBLANK_ABSOLUTE |
706 _DRM_VBLANK_SECONDARY | _DRM_VBLANK_NEXTONMISS |
708 DRM_ERROR("Invalid sequence type 0x%x\n", swap->seqtype);
712 plane = (swap->seqtype & _DRM_VBLANK_SECONDARY) ? 1 : 0;
713 pipe = i915_get_pipe(dev, plane);
715 seqtype = swap->seqtype & (_DRM_VBLANK_RELATIVE | _DRM_VBLANK_ABSOLUTE);
717 if (!(dev_priv->vblank_pipe & (1 << pipe))) {
718 DRM_ERROR("Invalid pipe %d\n", pipe);
722 DRM_SPINLOCK_IRQSAVE(&dev->drw_lock, irqflags);
724 /* It makes no sense to schedule a swap for a drawable that doesn't have
725 * valid information at this point. E.g. this could mean that the X
726 * server is too old to push drawable information to the DRM, in which
727 * case all such swaps would become ineffective.
729 if (!drm_get_drawable_info(dev, swap->drawable)) {
730 DRM_SPINUNLOCK_IRQRESTORE(&dev->drw_lock, irqflags);
731 DRM_DEBUG("Invalid drawable ID %d\n", swap->drawable);
735 DRM_SPINUNLOCK_IRQRESTORE(&dev->drw_lock, irqflags);
737 drm_update_vblank_count(dev, pipe);
738 curseq = drm_vblank_count(dev, pipe);
740 if (seqtype == _DRM_VBLANK_RELATIVE)
741 swap->sequence += curseq;
743 if ((curseq - swap->sequence) <= (1<<23)) {
744 if (swap->seqtype & _DRM_VBLANK_NEXTONMISS) {
745 swap->sequence = curseq + 1;
747 DRM_DEBUG("Missed target sequence\n");
752 if (swap->seqtype & _DRM_VBLANK_FLIP) {
755 if ((curseq - swap->sequence) <= (1<<23)) {
756 struct drm_drawable_info *drw;
758 LOCK_TEST_WITH_RETURN(dev, file_priv);
760 DRM_SPINLOCK_IRQSAVE(&dev->drw_lock, irqflags);
762 drw = drm_get_drawable_info(dev, swap->drawable);
765 DRM_SPINUNLOCK_IRQRESTORE(&dev->drw_lock,
767 DRM_DEBUG("Invalid drawable ID %d\n",
772 i915_dispatch_vsync_flip(dev, drw, plane);
774 DRM_SPINUNLOCK_IRQRESTORE(&dev->drw_lock, irqflags);
780 DRM_SPINLOCK_IRQSAVE(&dev_priv->swaps_lock, irqflags);
782 list_for_each(list, &dev_priv->vbl_swaps.head) {
783 vbl_swap = list_entry(list, drm_i915_vbl_swap_t, head);
785 if (vbl_swap->drw_id == swap->drawable &&
786 vbl_swap->plane == plane &&
787 vbl_swap->sequence == swap->sequence) {
788 vbl_swap->flip = (swap->seqtype & _DRM_VBLANK_FLIP);
789 DRM_SPINUNLOCK_IRQRESTORE(&dev_priv->swaps_lock, irqflags);
790 DRM_DEBUG("Already scheduled\n");
795 DRM_SPINUNLOCK_IRQRESTORE(&dev_priv->swaps_lock, irqflags);
797 if (dev_priv->swaps_pending >= 100) {
798 DRM_DEBUG("Too many swaps queued\n");
802 vbl_swap = drm_calloc(1, sizeof(*vbl_swap), DRM_MEM_DRIVER);
805 DRM_ERROR("Failed to allocate memory to queue swap\n");
811 ret = drm_vblank_get(dev, pipe);
813 drm_free(vbl_swap, sizeof(*vbl_swap), DRM_MEM_DRIVER);
817 vbl_swap->drw_id = swap->drawable;
818 vbl_swap->plane = plane;
819 vbl_swap->sequence = swap->sequence;
820 vbl_swap->flip = (swap->seqtype & _DRM_VBLANK_FLIP);
825 DRM_SPINLOCK_IRQSAVE(&dev_priv->swaps_lock, irqflags);
827 list_add_tail(&vbl_swap->head, &dev_priv->vbl_swaps.head);
828 dev_priv->swaps_pending++;
830 DRM_SPINUNLOCK_IRQRESTORE(&dev_priv->swaps_lock, irqflags);
837 void i915_driver_irq_preinstall(struct drm_device * dev)
839 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
841 I915_WRITE16(I915REG_HWSTAM, 0xeffe);
842 I915_WRITE16(I915REG_INT_MASK_R, 0x0);
843 I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
846 int i915_driver_irq_postinstall(struct drm_device * dev)
848 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
849 int ret, num_pipes = 2;
851 DRM_SPININIT(&dev_priv->swaps_lock, "swap");
852 INIT_LIST_HEAD(&dev_priv->vbl_swaps.head);
853 dev_priv->swaps_pending = 0;
855 DRM_SPININIT(&dev_priv->user_irq_lock, "userirq");
856 dev_priv->user_irq_refcount = 0;
857 dev_priv->irq_enable_reg = 0;
859 ret = drm_vblank_init(dev, num_pipes);
863 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
865 i915_enable_interrupt(dev);
866 DRM_INIT_WAITQUEUE(&dev_priv->irq_queue);
869 * Initialize the hardware status page IRQ location.
872 I915_WRITE(I915REG_INSTPM, (1 << 5) | (1 << 21));
876 void i915_driver_irq_uninstall(struct drm_device * dev)
878 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
884 dev_priv->irq_enabled = 0;
885 I915_WRITE16(I915REG_HWSTAM, 0xffff);
886 I915_WRITE16(I915REG_INT_MASK_R, 0xffff);
887 I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
889 temp = I915_READ16(I915REG_INT_IDENTITY_R);
890 I915_WRITE16(I915REG_INT_IDENTITY_R, temp);