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))
409 /* count may be reset by other driver(e.g. 2D driver),
410 we have no way to know if it is wrapped or resetted
411 when count is zero. do a rough guess.
413 if (count == 0 && dev->last_vblank[pipe] < dev->max_vblank_count/2)
414 dev->last_vblank[pipe] = 0;
419 irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
421 struct drm_device *dev = (struct drm_device *) arg;
422 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
424 u32 pipea_stats, pipeb_stats;
426 pipea_stats = I915_READ(I915REG_PIPEASTAT);
427 pipeb_stats = I915_READ(I915REG_PIPEBSTAT);
429 temp = I915_READ16(I915REG_INT_IDENTITY_R);
432 DRM_DEBUG("flag=%08x\n", temp);
438 * Clear the PIPE(A|B)STAT regs before the IIR otherwise
439 * we may get extra interrupts.
441 if (temp & VSYNC_PIPEA_FLAG) {
442 drm_handle_vblank(dev, i915_get_plane(dev, 0));
443 I915_WRITE(I915REG_PIPEASTAT,
444 pipea_stats | I915_VBLANK_INTERRUPT_ENABLE |
447 if (temp & VSYNC_PIPEB_FLAG) {
448 drm_handle_vblank(dev, i915_get_plane(dev, 1));
449 I915_WRITE(I915REG_PIPEBSTAT,
450 pipeb_stats | I915_VBLANK_INTERRUPT_ENABLE |
454 I915_WRITE16(I915REG_INT_IDENTITY_R, temp);
455 (void) I915_READ16(I915REG_INT_IDENTITY_R); /* Flush posted write */
457 temp &= (dev_priv->irq_enable_reg | USER_INT_FLAG | VSYNC_PIPEA_FLAG |
460 if (dev_priv->sarea_priv)
461 dev_priv->sarea_priv->last_dispatch =
462 READ_BREADCRUMB(dev_priv);
464 if (temp & USER_INT_FLAG) {
465 DRM_WAKEUP(&dev_priv->irq_queue);
466 #ifdef I915_HAVE_FENCE
467 i915_fence_handler(dev);
471 if (temp & (VSYNC_PIPEA_FLAG | VSYNC_PIPEB_FLAG)) {
472 if (dev_priv->swaps_pending > 0)
473 drm_locked_tasklet(dev, i915_vblank_tasklet);
479 int i915_emit_irq(struct drm_device *dev)
481 drm_i915_private_t *dev_priv = dev->dev_private;
484 i915_kernel_lost_context(dev);
488 i915_emit_breadcrumb(dev);
492 OUT_RING(GFX_OP_USER_INTERRUPT);
495 return dev_priv->counter;
498 void i915_user_irq_on(drm_i915_private_t *dev_priv)
500 DRM_SPINLOCK(&dev_priv->user_irq_lock);
501 if (dev_priv->irq_enabled && (++dev_priv->user_irq_refcount == 1)){
502 dev_priv->irq_enable_reg |= USER_INT_FLAG;
503 I915_WRITE16(I915REG_INT_ENABLE_R, dev_priv->irq_enable_reg);
505 DRM_SPINUNLOCK(&dev_priv->user_irq_lock);
509 void i915_user_irq_off(drm_i915_private_t *dev_priv)
511 DRM_SPINLOCK(&dev_priv->user_irq_lock);
512 if (dev_priv->irq_enabled && (--dev_priv->user_irq_refcount == 0)) {
513 // dev_priv->irq_enable_reg &= ~USER_INT_FLAG;
514 // I915_WRITE16(I915REG_INT_ENABLE_R, dev_priv->irq_enable_reg);
516 DRM_SPINUNLOCK(&dev_priv->user_irq_lock);
520 static int i915_wait_irq(struct drm_device * dev, int irq_nr)
522 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
525 DRM_DEBUG("irq_nr=%d breadcrumb=%d\n", irq_nr,
526 READ_BREADCRUMB(dev_priv));
528 if (READ_BREADCRUMB(dev_priv) >= irq_nr)
531 i915_user_irq_on(dev_priv);
532 DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ,
533 READ_BREADCRUMB(dev_priv) >= irq_nr);
534 i915_user_irq_off(dev_priv);
537 DRM_ERROR("EBUSY -- rec: %d emitted: %d\n",
538 READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
541 if (dev_priv->sarea_priv)
542 dev_priv->sarea_priv->last_dispatch =
543 READ_BREADCRUMB(dev_priv);
547 /* Needs the lock as it touches the ring.
549 int i915_irq_emit(struct drm_device *dev, void *data,
550 struct drm_file *file_priv)
552 drm_i915_private_t *dev_priv = dev->dev_private;
553 drm_i915_irq_emit_t *emit = data;
556 LOCK_TEST_WITH_RETURN(dev, file_priv);
559 DRM_ERROR("called with no initialization\n");
563 result = i915_emit_irq(dev);
565 if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) {
566 DRM_ERROR("copy_to_user\n");
573 /* Doesn't need the hardware lock.
575 int i915_irq_wait(struct drm_device *dev, void *data,
576 struct drm_file *file_priv)
578 drm_i915_private_t *dev_priv = dev->dev_private;
579 drm_i915_irq_wait_t *irqwait = data;
582 DRM_ERROR("called with no initialization\n");
586 return i915_wait_irq(dev, irqwait->irq_seq);
589 int i915_enable_vblank(struct drm_device *dev, int plane)
591 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
592 int pipe = i915_get_pipe(dev, plane);
596 dev_priv->irq_enable_reg |= VSYNC_PIPEA_FLAG;
599 dev_priv->irq_enable_reg |= VSYNC_PIPEB_FLAG;
602 DRM_ERROR("tried to enable vblank on non-existent pipe %d\n",
607 I915_WRITE16(I915REG_INT_ENABLE_R, dev_priv->irq_enable_reg);
612 void i915_disable_vblank(struct drm_device *dev, int plane)
614 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
615 int pipe = i915_get_pipe(dev, plane);
619 dev_priv->irq_enable_reg &= ~VSYNC_PIPEA_FLAG;
622 dev_priv->irq_enable_reg &= ~VSYNC_PIPEB_FLAG;
625 DRM_ERROR("tried to disable vblank on non-existent pipe %d\n",
630 I915_WRITE16(I915REG_INT_ENABLE_R, dev_priv->irq_enable_reg);
633 static void i915_enable_interrupt (struct drm_device *dev)
635 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
637 dev_priv->irq_enable_reg |= USER_INT_FLAG;
639 I915_WRITE16(I915REG_INT_ENABLE_R, dev_priv->irq_enable_reg);
640 dev_priv->irq_enabled = 1;
643 /* Set the vblank monitor pipe
645 int i915_vblank_pipe_set(struct drm_device *dev, void *data,
646 struct drm_file *file_priv)
648 drm_i915_private_t *dev_priv = dev->dev_private;
649 drm_i915_vblank_pipe_t *pipe = data;
652 DRM_ERROR("called with no initialization\n");
656 if (pipe->pipe & ~(DRM_I915_VBLANK_PIPE_A|DRM_I915_VBLANK_PIPE_B)) {
657 DRM_ERROR("called with invalid pipe 0x%x\n", pipe->pipe);
661 dev_priv->vblank_pipe = pipe->pipe;
666 int i915_vblank_pipe_get(struct drm_device *dev, void *data,
667 struct drm_file *file_priv)
669 drm_i915_private_t *dev_priv = dev->dev_private;
670 drm_i915_vblank_pipe_t *pipe = data;
674 DRM_ERROR("called with no initialization\n");
678 flag = I915_READ(I915REG_INT_ENABLE_R);
680 if (flag & VSYNC_PIPEA_FLAG)
681 pipe->pipe |= DRM_I915_VBLANK_PIPE_A;
682 if (flag & VSYNC_PIPEB_FLAG)
683 pipe->pipe |= DRM_I915_VBLANK_PIPE_B;
689 * Schedule buffer swap at given vertical blank.
691 int i915_vblank_swap(struct drm_device *dev, void *data,
692 struct drm_file *file_priv)
694 drm_i915_private_t *dev_priv = dev->dev_private;
695 drm_i915_vblank_swap_t *swap = data;
696 drm_i915_vbl_swap_t *vbl_swap;
697 unsigned int pipe, seqtype, curseq, plane;
698 unsigned long irqflags;
699 struct list_head *list;
703 DRM_ERROR("%s called with no initialization\n", __func__);
707 if (!dev_priv->sarea_priv || dev_priv->sarea_priv->rotation) {
708 DRM_DEBUG("Rotation not supported\n");
712 if (swap->seqtype & ~(_DRM_VBLANK_RELATIVE | _DRM_VBLANK_ABSOLUTE |
713 _DRM_VBLANK_SECONDARY | _DRM_VBLANK_NEXTONMISS |
715 DRM_ERROR("Invalid sequence type 0x%x\n", swap->seqtype);
719 plane = (swap->seqtype & _DRM_VBLANK_SECONDARY) ? 1 : 0;
720 pipe = i915_get_pipe(dev, plane);
722 seqtype = swap->seqtype & (_DRM_VBLANK_RELATIVE | _DRM_VBLANK_ABSOLUTE);
724 if (!(dev_priv->vblank_pipe & (1 << pipe))) {
725 DRM_ERROR("Invalid pipe %d\n", pipe);
729 DRM_SPINLOCK_IRQSAVE(&dev->drw_lock, irqflags);
731 /* It makes no sense to schedule a swap for a drawable that doesn't have
732 * valid information at this point. E.g. this could mean that the X
733 * server is too old to push drawable information to the DRM, in which
734 * case all such swaps would become ineffective.
736 if (!drm_get_drawable_info(dev, swap->drawable)) {
737 DRM_SPINUNLOCK_IRQRESTORE(&dev->drw_lock, irqflags);
738 DRM_DEBUG("Invalid drawable ID %d\n", swap->drawable);
742 DRM_SPINUNLOCK_IRQRESTORE(&dev->drw_lock, irqflags);
744 drm_update_vblank_count(dev, pipe);
745 curseq = drm_vblank_count(dev, pipe);
747 if (seqtype == _DRM_VBLANK_RELATIVE)
748 swap->sequence += curseq;
750 if ((curseq - swap->sequence) <= (1<<23)) {
751 if (swap->seqtype & _DRM_VBLANK_NEXTONMISS) {
752 swap->sequence = curseq + 1;
754 DRM_DEBUG("Missed target sequence\n");
759 if (swap->seqtype & _DRM_VBLANK_FLIP) {
762 if ((curseq - swap->sequence) <= (1<<23)) {
763 struct drm_drawable_info *drw;
765 LOCK_TEST_WITH_RETURN(dev, file_priv);
767 DRM_SPINLOCK_IRQSAVE(&dev->drw_lock, irqflags);
769 drw = drm_get_drawable_info(dev, swap->drawable);
772 DRM_SPINUNLOCK_IRQRESTORE(&dev->drw_lock,
774 DRM_DEBUG("Invalid drawable ID %d\n",
779 i915_dispatch_vsync_flip(dev, drw, plane);
781 DRM_SPINUNLOCK_IRQRESTORE(&dev->drw_lock, irqflags);
787 DRM_SPINLOCK_IRQSAVE(&dev_priv->swaps_lock, irqflags);
789 list_for_each(list, &dev_priv->vbl_swaps.head) {
790 vbl_swap = list_entry(list, drm_i915_vbl_swap_t, head);
792 if (vbl_swap->drw_id == swap->drawable &&
793 vbl_swap->plane == plane &&
794 vbl_swap->sequence == swap->sequence) {
795 vbl_swap->flip = (swap->seqtype & _DRM_VBLANK_FLIP);
796 DRM_SPINUNLOCK_IRQRESTORE(&dev_priv->swaps_lock, irqflags);
797 DRM_DEBUG("Already scheduled\n");
802 DRM_SPINUNLOCK_IRQRESTORE(&dev_priv->swaps_lock, irqflags);
804 if (dev_priv->swaps_pending >= 100) {
805 DRM_DEBUG("Too many swaps queued\n");
809 vbl_swap = drm_calloc(1, sizeof(*vbl_swap), DRM_MEM_DRIVER);
812 DRM_ERROR("Failed to allocate memory to queue swap\n");
818 ret = drm_vblank_get(dev, pipe);
820 drm_free(vbl_swap, sizeof(*vbl_swap), DRM_MEM_DRIVER);
824 vbl_swap->drw_id = swap->drawable;
825 vbl_swap->plane = plane;
826 vbl_swap->sequence = swap->sequence;
827 vbl_swap->flip = (swap->seqtype & _DRM_VBLANK_FLIP);
832 DRM_SPINLOCK_IRQSAVE(&dev_priv->swaps_lock, irqflags);
834 list_add_tail(&vbl_swap->head, &dev_priv->vbl_swaps.head);
835 dev_priv->swaps_pending++;
837 DRM_SPINUNLOCK_IRQRESTORE(&dev_priv->swaps_lock, irqflags);
844 void i915_driver_irq_preinstall(struct drm_device * dev)
846 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
848 I915_WRITE16(I915REG_HWSTAM, 0xeffe);
849 I915_WRITE16(I915REG_INT_MASK_R, 0x0);
850 I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
853 int i915_driver_irq_postinstall(struct drm_device * dev)
855 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
856 int ret, num_pipes = 2;
858 DRM_SPININIT(&dev_priv->swaps_lock, "swap");
859 INIT_LIST_HEAD(&dev_priv->vbl_swaps.head);
860 dev_priv->swaps_pending = 0;
862 DRM_SPININIT(&dev_priv->user_irq_lock, "userirq");
863 dev_priv->user_irq_refcount = 0;
864 dev_priv->irq_enable_reg = 0;
866 ret = drm_vblank_init(dev, num_pipes);
870 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
872 i915_enable_interrupt(dev);
873 DRM_INIT_WAITQUEUE(&dev_priv->irq_queue);
876 * Initialize the hardware status page IRQ location.
879 I915_WRITE(I915REG_INSTPM, (1 << 5) | (1 << 21));
883 void i915_driver_irq_uninstall(struct drm_device * dev)
885 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
891 dev_priv->irq_enabled = 0;
892 I915_WRITE16(I915REG_HWSTAM, 0xffff);
893 I915_WRITE16(I915REG_INT_MASK_R, 0xffff);
894 I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
896 temp = I915_READ16(I915REG_INT_IDENTITY_R);
897 I915_WRITE16(I915REG_INT_IDENTITY_R, temp);