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.
33 #include "intel_drv.h"
34 #include "drm_crtc_helper.h"
36 #define MAX_NOPID ((u32)~0)
39 * i915_get_pipe - return the the pipe associated with a given plane
41 * @plane: plane to look for
43 * The Intel Mesa & 2D drivers call the vblank routines with a plane number
44 * rather than a pipe number, since they may not always be equal. This routine
45 * maps the given @plane back to a pipe number.
48 i915_get_pipe(struct drm_device *dev, int plane)
50 struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
53 dspcntr = plane ? I915_READ(DSPBCNTR) : I915_READ(DSPACNTR);
55 return dspcntr & DISPPLANE_SEL_PIPE_MASK ? 1 : 0;
59 * i915_get_plane - return the the plane associated with a given pipe
61 * @pipe: pipe to look for
63 * The Intel Mesa & 2D drivers call the vblank routines with a plane number
64 * rather than a plane number, since they may not always be equal. This routine
65 * maps the given @pipe back to a plane number.
68 i915_get_plane(struct drm_device *dev, int pipe)
70 if (i915_get_pipe(dev, 0) == pipe)
76 * i915_pipe_enabled - check if a pipe is enabled
78 * @pipe: pipe to check
80 * Reading certain registers when the pipe is disabled can hang the chip.
81 * Use this routine to make sure the PLL is running and the pipe is active
82 * before reading such registers if unsure.
85 i915_pipe_enabled(struct drm_device *dev, int pipe)
87 struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
88 unsigned long pipeconf = pipe ? PIPEBCONF : PIPEACONF;
90 if (I915_READ(pipeconf) & PIPEACONF_ENABLE)
97 * Emit a synchronous flip.
99 * This function must be called with the drawable spinlock held.
102 i915_dispatch_vsync_flip(struct drm_device *dev, struct drm_drawable_info *drw,
105 struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
106 struct drm_i915_sarea *sarea_priv = master_priv->sarea_priv;
108 int pf_planes = 1 << plane;
110 DRM_SPINLOCK_ASSERT(&dev->drw_lock);
112 /* If the window is visible on the other plane, we have to flip on that
116 x1 = sarea_priv->planeA_x;
117 y1 = sarea_priv->planeA_y;
118 x2 = x1 + sarea_priv->planeA_w;
119 y2 = y1 + sarea_priv->planeA_h;
121 x1 = sarea_priv->planeB_x;
122 y1 = sarea_priv->planeB_y;
123 x2 = x1 + sarea_priv->planeB_w;
124 y2 = y1 + sarea_priv->planeB_h;
127 if (x2 > 0 && y2 > 0) {
128 int i, num_rects = drw->num_rects;
129 struct drm_clip_rect *rect = drw->rects;
131 for (i = 0; i < num_rects; i++)
132 if (!(rect[i].x1 >= x2 || rect[i].y1 >= y2 ||
133 rect[i].x2 <= x1 || rect[i].y2 <= y1)) {
140 i915_dispatch_flip(dev, pf_planes, 1);
144 * Emit blits for scheduled buffer swaps.
146 * This function will be called with the HW lock held.
148 static void i915_vblank_tasklet(struct drm_device *dev)
150 struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
151 struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
152 struct list_head *list, *tmp, hits, *hit;
153 int nhits, nrects, slice[2], upper[2], lower[2], i, num_pages;
155 struct drm_drawable_info *drw;
156 struct drm_i915_sarea *sarea_priv = master_priv->sarea_priv;
157 u32 cpp = dev_priv->cpp, offsets[3];
158 u32 cmd = (cpp == 4) ? (XY_SRC_COPY_BLT_CMD |
159 XY_SRC_COPY_BLT_WRITE_ALPHA |
160 XY_SRC_COPY_BLT_WRITE_RGB)
161 : XY_SRC_COPY_BLT_CMD;
162 u32 src_pitch = sarea_priv->pitch * cpp;
163 u32 dst_pitch = sarea_priv->pitch * cpp;
164 /* COPY rop (0xcc), map cpp to magic color depth constants */
165 u32 ropcpp = (0xcc << 16) | ((cpp - 1) << 24);
168 if (sarea_priv->front_tiled) {
169 cmd |= XY_SRC_COPY_BLT_DST_TILED;
172 if (sarea_priv->back_tiled) {
173 cmd |= XY_SRC_COPY_BLT_SRC_TILED;
177 counter[0] = drm_vblank_count(dev, 0);
178 counter[1] = drm_vblank_count(dev, 1);
182 INIT_LIST_HEAD(&hits);
186 /* No irqsave/restore necessary. This tasklet may be run in an
187 * interrupt context or normal context, but we don't have to worry
188 * about getting interrupted by something acquiring the lock, because
189 * we are the interrupt context thing that acquires the lock.
191 DRM_SPINLOCK(&dev_priv->swaps_lock);
193 /* Find buffer swaps scheduled for this vertical blank */
194 list_for_each_safe(list, tmp, &dev_priv->vbl_swaps.head) {
195 struct drm_i915_vbl_swap *vbl_swap =
196 list_entry(list, struct drm_i915_vbl_swap, head);
197 int pipe = i915_get_pipe(dev, vbl_swap->plane);
199 if ((counter[pipe] - vbl_swap->sequence) > (1<<23))
202 master_priv = vbl_swap->minor->master->driver_priv;
203 sarea_priv = master_priv->sarea_priv;
206 dev_priv->swaps_pending--;
207 drm_vblank_put(dev, pipe);
209 DRM_SPINUNLOCK(&dev_priv->swaps_lock);
210 DRM_SPINLOCK(&dev->drw_lock);
212 drw = drm_get_drawable_info(dev, vbl_swap->drw_id);
215 DRM_SPINUNLOCK(&dev->drw_lock);
216 drm_free(vbl_swap, sizeof(*vbl_swap), DRM_MEM_DRIVER);
217 DRM_SPINLOCK(&dev_priv->swaps_lock);
221 list_for_each(hit, &hits) {
222 struct drm_i915_vbl_swap *swap_cmp =
223 list_entry(hit, struct drm_i915_vbl_swap, head);
224 struct drm_drawable_info *drw_cmp =
225 drm_get_drawable_info(dev, swap_cmp->drw_id);
228 drw_cmp->rects[0].y1 > drw->rects[0].y1) {
229 list_add_tail(list, hit);
234 DRM_SPINUNLOCK(&dev->drw_lock);
236 /* List of hits was empty, or we reached the end of it */
238 list_add_tail(list, hits.prev);
242 DRM_SPINLOCK(&dev_priv->swaps_lock);
245 DRM_SPINUNLOCK(&dev_priv->swaps_lock);
251 i915_kernel_lost_context(dev);
253 upper[0] = upper[1] = 0;
254 slice[0] = max(sarea_priv->planeA_h / nhits, 1);
255 slice[1] = max(sarea_priv->planeB_h / nhits, 1);
256 lower[0] = sarea_priv->planeA_y + slice[0];
257 lower[1] = sarea_priv->planeB_y + slice[0];
259 offsets[0] = sarea_priv->front_offset;
260 offsets[1] = sarea_priv->back_offset;
261 offsets[2] = sarea_priv->third_offset;
262 num_pages = sarea_priv->third_handle ? 3 : 2;
264 DRM_SPINLOCK(&dev->drw_lock);
266 /* Emit blits for buffer swaps, partitioning both outputs into as many
267 * slices as there are buffer swaps scheduled in order to avoid tearing
268 * (based on the assumption that a single buffer swap would always
269 * complete before scanout starts).
271 for (i = 0; i++ < nhits;
272 upper[0] = lower[0], lower[0] += slice[0],
273 upper[1] = lower[1], lower[1] += slice[1]) {
274 int init_drawrect = 1;
277 lower[0] = lower[1] = sarea_priv->height;
279 list_for_each(hit, &hits) {
280 struct drm_i915_vbl_swap *swap_hit =
281 list_entry(hit, struct drm_i915_vbl_swap, head);
282 struct drm_clip_rect *rect;
283 int num_rects, plane, front, back;
284 unsigned short top, bottom;
286 drw = drm_get_drawable_info(dev, swap_hit->drw_id);
291 plane = swap_hit->plane;
293 if (swap_hit->flip) {
294 i915_dispatch_vsync_flip(dev, drw, plane);
299 int width = sarea_priv->width;
300 int height = sarea_priv->height;
304 OUT_RING(GFX_OP_DRAWRECT_INFO_I965);
306 OUT_RING(((width - 1) & 0xffff) | ((height - 1) << 16));
313 OUT_RING(GFX_OP_DRAWRECT_INFO);
316 OUT_RING(((width - 1) & 0xffff) | ((height - 1) << 16));
323 sarea_priv->ctxOwner = DRM_KERNEL_CONTEXT;
330 bottom = lower[plane];
332 front = (master_priv->sarea_priv->pf_current_page >>
334 back = (front + 1) % num_pages;
336 for (num_rects = drw->num_rects; num_rects--; rect++) {
337 int y1 = max(rect->y1, top);
338 int y2 = min(rect->y2, bottom);
346 OUT_RING(ropcpp | dst_pitch);
347 OUT_RING((y1 << 16) | rect->x1);
348 OUT_RING((y2 << 16) | rect->x2);
349 OUT_RING(offsets[front]);
350 OUT_RING((y1 << 16) | rect->x1);
352 OUT_RING(offsets[back]);
359 DRM_SPINUNLOCK(&dev->drw_lock);
361 list_for_each_safe(hit, tmp, &hits) {
362 struct drm_i915_vbl_swap *swap_hit =
363 list_entry(hit, struct drm_i915_vbl_swap, head);
367 drm_free(swap_hit, sizeof(*swap_hit), DRM_MEM_DRIVER);
371 static int i915_in_vblank(struct drm_device *dev, int pipe)
373 struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
374 unsigned long pipedsl, vblank, vtotal;
375 unsigned long vbl_start, vbl_end, cur_line;
377 pipedsl = pipe ? PIPEBDSL : PIPEADSL;
378 vblank = pipe ? VBLANK_B : VBLANK_A;
379 vtotal = pipe ? VTOTAL_B : VTOTAL_A;
381 vbl_start = I915_READ(vblank) & VBLANK_START_MASK;
382 vbl_end = (I915_READ(vblank) >> VBLANK_END_SHIFT) & VBLANK_END_MASK;
384 cur_line = I915_READ(pipedsl);
386 if (cur_line >= vbl_start)
392 u32 i915_get_vblank_counter(struct drm_device *dev, int plane)
394 struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
395 unsigned long high_frame;
396 unsigned long low_frame;
397 u32 high1, high2, low, count;
400 pipe = i915_get_pipe(dev, plane);
401 high_frame = pipe ? PIPEBFRAMEHIGH : PIPEAFRAMEHIGH;
402 low_frame = pipe ? PIPEBFRAMEPIXEL : PIPEAFRAMEPIXEL;
404 if (!i915_pipe_enabled(dev, pipe)) {
405 DRM_ERROR("trying to get vblank count for disabled pipe %d\n", pipe);
410 * High & low register fields aren't synchronized, so make sure
411 * we get a low value that's stable across two reads of the high
415 high1 = ((I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >>
416 PIPE_FRAME_HIGH_SHIFT);
417 low = ((I915_READ(low_frame) & PIPE_FRAME_LOW_MASK) >>
418 PIPE_FRAME_LOW_SHIFT);
419 high2 = ((I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >>
420 PIPE_FRAME_HIGH_SHIFT);
421 } while (high1 != high2);
423 count = (high1 << 8) | low;
426 * If we're in the middle of the vblank period, the
427 * above regs won't have been updated yet, so return
428 * an incremented count to stay accurate
431 if (i915_in_vblank(dev, pipe))
434 /* count may be reset by other driver(e.g. 2D driver),
435 we have no way to know if it is wrapped or resetted
436 when count is zero. do a rough guess.
438 if (count == 0 && dev->last_vblank[pipe] < dev->max_vblank_count/2)
439 dev->last_vblank[pipe] = 0;
444 static struct drm_device *hotplug_dev;
447 * Handler for user interrupts in process context (able to sleep, do VFS
450 * If another IRQ comes in while we're in this handler, it will still get put
451 * on the queue again to be rerun when we finish.
453 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
454 static void i915_hotplug_work_func(void *work)
456 static void i915_hotplug_work_func(struct work_struct *work)
459 struct drm_device *dev = hotplug_dev;
461 drm_helper_hotplug_stage_two(dev);
462 drm_handle_hotplug(dev);
465 static int i915_run_hotplug_tasklet(struct drm_device *dev, uint32_t stat)
467 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
468 static DECLARE_WORK(hotplug, i915_hotplug_work_func, NULL);
470 static DECLARE_WORK(hotplug, i915_hotplug_work_func);
472 struct drm_i915_private *dev_priv = dev->dev_private;
476 if (stat & TV_HOTPLUG_INT_STATUS) {
477 DRM_DEBUG("TV event\n");
480 if (stat & CRT_HOTPLUG_INT_STATUS) {
481 DRM_DEBUG("CRT event\n");
484 if (stat & SDVOB_HOTPLUG_INT_STATUS) {
485 DRM_DEBUG("sDVOB event\n");
488 if (stat & SDVOC_HOTPLUG_INT_STATUS) {
489 DRM_DEBUG("sDVOC event\n");
491 queue_work(dev_priv->wq, &hotplug);
497 i915_user_interrupt_handler(struct work_struct *work)
499 struct drm_i915_private *dev_priv;
500 struct drm_device *dev;
502 dev_priv = container_of(work, struct drm_i915_private,
503 user_interrupt_task);
506 mutex_lock(&dev->struct_mutex);
507 i915_gem_retire_requests(dev);
508 mutex_unlock(&dev->struct_mutex);
511 irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
513 struct drm_device *dev = (struct drm_device *) arg;
514 struct drm_i915_master_private *master_priv;
515 struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
517 u32 pipea_stats = 0, pipeb_stats, tvdac;
521 /* On i8xx/i915 hw the IIR and IER are 16bit on i9xx its 32bit */
522 if (IS_I9XX(dev) && !IS_I915G(dev) && !IS_I915GM(dev))
523 iir = I915_READ(IIR);
525 iir = I915_READ16(IIR);
527 iir &= (dev_priv->irq_mask_reg | I915_USER_INTERRUPT);
530 DRM_DEBUG("flag=%08x\n", iir);
534 DRM_DEBUG ("iir 0x%08x im 0x%08x ie 0x%08x pipea 0x%08x pipeb 0x%08x\n",
538 I915_READ(PIPEASTAT),
539 I915_READ(PIPEBSTAT));
545 * Clear the PIPE(A|B)STAT regs before the IIR otherwise
546 * we may get extra interrupts.
548 if (iir & I915_DISPLAY_PIPE_A_EVENT_INTERRUPT) {
549 pipea_stats = I915_READ(PIPEASTAT);
550 if (pipea_stats & (PIPE_START_VBLANK_INTERRUPT_STATUS|
551 PIPE_VBLANK_INTERRUPT_STATUS))
554 drm_handle_vblank(dev, i915_get_plane(dev, 0));
557 /* This is a global event, and not a pipe A event */
558 if (pipea_stats & PIPE_HOTPLUG_INTERRUPT_STATUS)
561 if (pipea_stats & PIPE_HOTPLUG_TV_INTERRUPT_STATUS) {
563 /* Toggle hotplug detection to clear hotplug status */
564 tvdac = I915_READ(TV_DAC);
565 I915_WRITE(TV_DAC, tvdac & ~TVDAC_STATE_CHG_EN);
566 I915_WRITE(TV_DAC, tvdac | TVDAC_STATE_CHG_EN);
569 I915_WRITE(PIPEASTAT, pipea_stats);
572 if (iir & I915_DISPLAY_PIPE_B_EVENT_INTERRUPT) {
573 pipeb_stats = I915_READ(PIPEBSTAT);
574 if (pipeb_stats & (PIPE_START_VBLANK_INTERRUPT_STATUS|
575 PIPE_VBLANK_INTERRUPT_STATUS))
578 drm_handle_vblank(dev, i915_get_plane(dev, 1));
580 I915_WRITE(PIPEBSTAT, pipeb_stats);
583 /* Clear the generated interrupt */
584 if (IS_I9XX(dev) && !IS_I915G(dev) && !IS_I915GM(dev)) {
585 I915_WRITE(IIR, iir);
586 (void) I915_READ(IIR);
588 I915_WRITE16(IIR, iir);
589 (void) I915_READ16(IIR);
592 if (dev->primary->master) {
593 master_priv = dev->primary->master->driver_priv;
594 master_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
597 if (iir & I915_USER_INTERRUPT) {
598 DRM_WAKEUP(&dev_priv->irq_queue);
599 #ifdef I915_HAVE_FENCE
600 i915_fence_handler(dev);
601 schedule_work(&dev_priv->user_interrupt_task);
606 if (dev_priv->swaps_pending > 0)
607 drm_locked_tasklet(dev, i915_vblank_tasklet);
610 if ((iir & I915_DISPLAY_PORT_INTERRUPT) || hotplug) {
613 DRM_INFO("Hotplug event received\n");
615 if (!IS_I9XX(dev) || IS_I915G(dev) || IS_I915GM(dev)) {
616 if (pipea_stats & PIPE_HOTPLUG_INTERRUPT_STATUS)
617 temp2 |= SDVOB_HOTPLUG_INT_STATUS |
618 SDVOC_HOTPLUG_INT_STATUS;
619 if (pipea_stats & PIPE_HOTPLUG_TV_INTERRUPT_STATUS)
620 temp2 |= TV_HOTPLUG_INT_STATUS;
622 temp2 = I915_READ(PORT_HOTPLUG_STAT);
624 I915_WRITE(PORT_HOTPLUG_STAT, temp2);
626 i915_run_hotplug_tasklet(dev, temp2);
632 int i915_emit_irq(struct drm_device *dev)
634 struct drm_i915_private *dev_priv = dev->dev_private;
637 i915_kernel_lost_context(dev);
641 i915_emit_breadcrumb(dev);
645 OUT_RING(MI_USER_INTERRUPT);
648 return dev_priv->counter;
651 void i915_user_irq_on(struct drm_device *dev)
653 struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
655 DRM_SPINLOCK(&dev_priv->user_irq_lock);
656 if (dev_priv->irq_enabled && (++dev_priv->user_irq_refcount == 1)){
657 dev_priv->irq_mask_reg &= ~I915_USER_INTERRUPT;
658 if (IS_I9XX(dev) && !IS_I915G(dev) && !IS_I915GM(dev))
659 I915_WRITE(IMR, dev_priv->irq_mask_reg);
661 I915_WRITE16(IMR, dev_priv->irq_mask_reg);
664 DRM_SPINUNLOCK(&dev_priv->user_irq_lock);
668 void i915_user_irq_off(struct drm_device *dev)
670 struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
672 DRM_SPINLOCK(&dev_priv->user_irq_lock);
673 BUG_ON(dev_priv->irq_enabled && dev_priv->user_irq_refcount <= 0);
674 if (dev_priv->irq_enabled && (--dev_priv->user_irq_refcount == 0)) {
675 dev_priv->irq_mask_reg |= I915_USER_INTERRUPT;
676 if (IS_I9XX(dev) && !IS_I915G(dev) && !IS_I915GM(dev))
677 I915_WRITE(IMR, dev_priv->irq_mask_reg);
679 I915_WRITE16(IMR, dev_priv->irq_mask_reg);
682 DRM_SPINUNLOCK(&dev_priv->user_irq_lock);
686 int i915_wait_irq(struct drm_device * dev, int irq_nr)
688 struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
689 struct drm_i915_master_private *master_priv;
693 DRM_ERROR("called with no initialization\n");
697 DRM_DEBUG("irq_nr=%d breadcrumb=%d\n", irq_nr,
698 READ_BREADCRUMB(dev_priv));
700 if (READ_BREADCRUMB(dev_priv) >= irq_nr)
703 i915_user_irq_on(dev);
704 DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ,
705 READ_BREADCRUMB(dev_priv) >= irq_nr);
706 i915_user_irq_off(dev);
709 DRM_ERROR("EBUSY -- rec: %d emitted: %d\n",
710 READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
713 if (dev->primary->master) {
714 master_priv = dev->primary->master->driver_priv;
715 master_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
721 /* Needs the lock as it touches the ring.
723 int i915_irq_emit(struct drm_device *dev, void *data,
724 struct drm_file *file_priv)
726 struct drm_i915_private *dev_priv = dev->dev_private;
727 struct drm_i915_irq_emit *emit = data;
730 LOCK_TEST_WITH_RETURN(dev, file_priv);
733 DRM_ERROR("called with no initialization\n");
737 result = i915_emit_irq(dev);
739 if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) {
740 DRM_ERROR("copy_to_user\n");
747 /* Doesn't need the hardware lock.
749 int i915_irq_wait(struct drm_device *dev, void *data,
750 struct drm_file *file_priv)
752 struct drm_i915_private *dev_priv = dev->dev_private;
753 struct drm_i915_irq_wait *irqwait = data;
756 DRM_ERROR("called with no initialization\n");
760 return i915_wait_irq(dev, irqwait->irq_seq);
763 int i915_enable_vblank(struct drm_device *dev, int plane)
765 struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
766 int pipe = i915_get_pipe(dev, plane);
767 u32 pipestat_reg = 0;
773 pipestat_reg = PIPEASTAT;
774 mask_reg |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
777 pipestat_reg = PIPEBSTAT;
778 mask_reg |= I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
781 DRM_ERROR("tried to enable vblank on non-existent pipe %d\n",
788 pipestat = I915_READ (pipestat_reg);
790 * Older chips didn't have the start vblank interrupt,
794 pipestat |= PIPE_START_VBLANK_INTERRUPT_ENABLE;
796 pipestat |= PIPE_VBLANK_INTERRUPT_ENABLE;
798 * Clear any pending status
800 pipestat |= (PIPE_START_VBLANK_INTERRUPT_STATUS |
801 PIPE_VBLANK_INTERRUPT_STATUS);
802 I915_WRITE(pipestat_reg, pipestat);
805 DRM_SPINLOCK(&dev_priv->user_irq_lock);
806 dev_priv->irq_mask_reg &= ~mask_reg;
807 if (IS_I9XX(dev) && !IS_I915G(dev) && !IS_I915GM(dev))
808 I915_WRITE(IMR, dev_priv->irq_mask_reg);
810 I915_WRITE16(IMR, dev_priv->irq_mask_reg);
811 DRM_SPINUNLOCK(&dev_priv->user_irq_lock);
816 void i915_disable_vblank(struct drm_device *dev, int plane)
818 struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
819 int pipe = i915_get_pipe(dev, plane);
820 u32 pipestat_reg = 0;
826 pipestat_reg = PIPEASTAT;
827 mask_reg |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
830 pipestat_reg = PIPEBSTAT;
831 mask_reg |= I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
834 DRM_ERROR("tried to disable vblank on non-existent pipe %d\n",
839 DRM_SPINLOCK(&dev_priv->user_irq_lock);
840 dev_priv->irq_mask_reg |= mask_reg;
841 if (IS_I9XX(dev) && !IS_I915G(dev) && !IS_I915GM(dev))
842 I915_WRITE(IMR, dev_priv->irq_mask_reg);
844 I915_WRITE16(IMR, dev_priv->irq_mask_reg);
845 DRM_SPINUNLOCK(&dev_priv->user_irq_lock);
848 pipestat = I915_READ (pipestat_reg);
849 pipestat &= ~(PIPE_START_VBLANK_INTERRUPT_ENABLE |
850 PIPE_VBLANK_INTERRUPT_ENABLE);
852 * Clear any pending status
854 pipestat |= (PIPE_START_VBLANK_INTERRUPT_STATUS |
855 PIPE_VBLANK_INTERRUPT_STATUS);
856 I915_WRITE(pipestat_reg, pipestat);
857 (void) I915_READ(pipestat_reg);
861 void i915_enable_interrupt (struct drm_device *dev)
863 struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
864 struct drm_connector *o;
866 dev_priv->irq_mask_reg &= ~I915_USER_INTERRUPT;
868 if (IS_I9XX(dev) && !IS_I915G(dev) && !IS_I915GM(dev)) {
869 if (dev->mode_config.num_connector)
870 dev_priv->irq_mask_reg &= ~I915_DISPLAY_PORT_INTERRUPT;
872 if (dev->mode_config.num_connector)
873 dev_priv->irq_mask_reg &= ~I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
875 /* Enable global interrupts for hotplug - not a pipeA event */
876 I915_WRITE(PIPEASTAT, I915_READ(PIPEASTAT) |
877 PIPE_HOTPLUG_INTERRUPT_ENABLE |
878 PIPE_HOTPLUG_TV_INTERRUPT_ENABLE |
879 PIPE_HOTPLUG_TV_INTERRUPT_STATUS |
880 PIPE_HOTPLUG_INTERRUPT_STATUS);
883 if (!(dev_priv->irq_mask_reg & I915_DISPLAY_PORT_INTERRUPT) ||
884 !(dev_priv->irq_mask_reg & I915_DISPLAY_PIPE_A_EVENT_INTERRUPT)) {
887 if (IS_I9XX(dev) && !IS_I915G(dev) && !IS_I915GM(dev)) {
888 temp = I915_READ(PORT_HOTPLUG_EN);
890 /* Activate the CRT */
891 temp |= CRT_HOTPLUG_INT_EN;
896 o = intel_sdvo_find(dev, 1);
897 if (o && intel_sdvo_supports_hotplug(o)) {
898 intel_sdvo_set_hotplug(o, 1);
899 temp |= SDVOB_HOTPLUG_INT_EN;
903 o = intel_sdvo_find(dev, 0);
904 if (o && intel_sdvo_supports_hotplug(o)) {
905 intel_sdvo_set_hotplug(o, 1);
906 temp |= SDVOC_HOTPLUG_INT_EN;
909 I915_WRITE(SDVOB, I915_READ(SDVOB) | SDVO_INTERRUPT_ENABLE);
910 I915_WRITE(SDVOC, I915_READ(SDVOC) | SDVO_INTERRUPT_ENABLE);
913 I915_WRITE(TV_DAC, I915_READ(TV_DAC) | TVDAC_STATE_CHG_EN);
918 if (IS_I9XX(dev) && !IS_I915G(dev) && !IS_I915GM(dev)) {
919 I915_WRITE(PORT_HOTPLUG_EN, temp);
921 DRM_DEBUG("HEN %08x\n",I915_READ(PORT_HOTPLUG_EN));
922 DRM_DEBUG("HST %08x\n",I915_READ(PORT_HOTPLUG_STAT));
924 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
928 if (IS_I9XX(dev) && !IS_I915G(dev) && !IS_I915GM(dev)) {
929 I915_WRITE(IMR, dev_priv->irq_mask_reg);
930 I915_WRITE(IER, ~dev_priv->irq_mask_reg);
932 I915_WRITE16(IMR, dev_priv->irq_mask_reg);
933 I915_WRITE16(IER, ~(u16)dev_priv->irq_mask_reg);
936 dev_priv->irq_enabled = 1;
939 /* Set the vblank monitor pipe
941 int i915_vblank_pipe_set(struct drm_device *dev, void *data,
942 struct drm_file *file_priv)
944 struct drm_i915_private *dev_priv = dev->dev_private;
945 struct drm_i915_vblank_pipe *pipe = data;
948 DRM_ERROR("called with no initialization\n");
952 if (pipe->pipe & ~(DRM_I915_VBLANK_PIPE_A|DRM_I915_VBLANK_PIPE_B)) {
953 DRM_ERROR("called with invalid pipe 0x%x\n", pipe->pipe);
957 dev_priv->vblank_pipe = pipe->pipe;
962 int i915_vblank_pipe_get(struct drm_device *dev, void *data,
963 struct drm_file *file_priv)
965 struct drm_i915_private *dev_priv = dev->dev_private;
966 struct drm_i915_vblank_pipe *pipe = data;
970 DRM_ERROR("called with no initialization\n");
974 if (IS_I9XX(dev) && !IS_I915G(dev) && !IS_I915GM(dev))
975 flag = I915_READ(IER);
977 flag = I915_READ16(IER);
980 if (flag & I915_DISPLAY_PIPE_A_EVENT_INTERRUPT)
981 pipe->pipe |= DRM_I915_VBLANK_PIPE_A;
982 if (flag & I915_DISPLAY_PIPE_B_EVENT_INTERRUPT)
983 pipe->pipe |= DRM_I915_VBLANK_PIPE_B;
989 * Schedule buffer swap at given vertical blank.
991 int i915_vblank_swap(struct drm_device *dev, void *data,
992 struct drm_file *file_priv)
994 struct drm_i915_private *dev_priv = dev->dev_private;
995 struct drm_i915_master_private *master_priv;
996 struct drm_i915_vblank_swap *swap = data;
997 struct drm_i915_vbl_swap *vbl_swap;
998 unsigned int pipe, seqtype, curseq, plane;
999 unsigned long irqflags;
1000 struct list_head *list;
1004 DRM_ERROR("%s called with no initialization\n", __func__);
1008 if (!dev->primary->master)
1011 master_priv = dev->primary->master->driver_priv;
1013 if (master_priv->sarea_priv->rotation) {
1014 DRM_DEBUG("Rotation not supported\n");
1018 if (swap->seqtype & ~(_DRM_VBLANK_RELATIVE | _DRM_VBLANK_ABSOLUTE |
1019 _DRM_VBLANK_SECONDARY | _DRM_VBLANK_NEXTONMISS |
1020 _DRM_VBLANK_FLIP)) {
1021 DRM_ERROR("Invalid sequence type 0x%x\n", swap->seqtype);
1025 plane = (swap->seqtype & _DRM_VBLANK_SECONDARY) ? 1 : 0;
1026 pipe = i915_get_pipe(dev, plane);
1028 seqtype = swap->seqtype & (_DRM_VBLANK_RELATIVE | _DRM_VBLANK_ABSOLUTE);
1030 if (!(dev_priv->vblank_pipe & (1 << pipe))) {
1031 DRM_ERROR("Invalid pipe %d\n", pipe);
1035 DRM_SPINLOCK_IRQSAVE(&dev->drw_lock, irqflags);
1037 /* It makes no sense to schedule a swap for a drawable that doesn't have
1038 * valid information at this point. E.g. this could mean that the X
1039 * server is too old to push drawable information to the DRM, in which
1040 * case all such swaps would become ineffective.
1042 if (!drm_get_drawable_info(dev, swap->drawable)) {
1043 DRM_SPINUNLOCK_IRQRESTORE(&dev->drw_lock, irqflags);
1044 DRM_DEBUG("Invalid drawable ID %d\n", swap->drawable);
1048 DRM_SPINUNLOCK_IRQRESTORE(&dev->drw_lock, irqflags);
1050 drm_update_vblank_count(dev, pipe);
1051 curseq = drm_vblank_count(dev, pipe);
1053 if (seqtype == _DRM_VBLANK_RELATIVE)
1054 swap->sequence += curseq;
1056 if ((curseq - swap->sequence) <= (1<<23)) {
1057 if (swap->seqtype & _DRM_VBLANK_NEXTONMISS) {
1058 swap->sequence = curseq + 1;
1060 DRM_DEBUG("Missed target sequence\n");
1065 if (swap->seqtype & _DRM_VBLANK_FLIP) {
1068 if ((curseq - swap->sequence) <= (1<<23)) {
1069 struct drm_drawable_info *drw;
1071 LOCK_TEST_WITH_RETURN(dev, file_priv);
1073 DRM_SPINLOCK_IRQSAVE(&dev->drw_lock, irqflags);
1075 drw = drm_get_drawable_info(dev, swap->drawable);
1078 DRM_SPINUNLOCK_IRQRESTORE(&dev->drw_lock,
1080 DRM_DEBUG("Invalid drawable ID %d\n",
1085 i915_dispatch_vsync_flip(dev, drw, plane);
1087 DRM_SPINUNLOCK_IRQRESTORE(&dev->drw_lock, irqflags);
1093 DRM_SPINLOCK_IRQSAVE(&dev_priv->swaps_lock, irqflags);
1095 list_for_each(list, &dev_priv->vbl_swaps.head) {
1096 vbl_swap = list_entry(list, struct drm_i915_vbl_swap, head);
1098 if (vbl_swap->drw_id == swap->drawable &&
1099 vbl_swap->plane == plane &&
1100 vbl_swap->sequence == swap->sequence) {
1101 vbl_swap->flip = (swap->seqtype & _DRM_VBLANK_FLIP);
1102 DRM_SPINUNLOCK_IRQRESTORE(&dev_priv->swaps_lock, irqflags);
1103 DRM_DEBUG("Already scheduled\n");
1108 DRM_SPINUNLOCK_IRQRESTORE(&dev_priv->swaps_lock, irqflags);
1110 if (dev_priv->swaps_pending >= 100) {
1111 DRM_DEBUG("Too many swaps queued\n");
1115 vbl_swap = drm_calloc(1, sizeof(*vbl_swap), DRM_MEM_DRIVER);
1118 DRM_ERROR("Failed to allocate memory to queue swap\n");
1124 ret = drm_vblank_get(dev, pipe);
1126 drm_free(vbl_swap, sizeof(*vbl_swap), DRM_MEM_DRIVER);
1130 vbl_swap->drw_id = swap->drawable;
1131 vbl_swap->plane = plane;
1132 vbl_swap->sequence = swap->sequence;
1133 vbl_swap->flip = (swap->seqtype & _DRM_VBLANK_FLIP);
1134 vbl_swap->minor = file_priv->minor;
1139 DRM_SPINLOCK_IRQSAVE(&dev_priv->swaps_lock, irqflags);
1141 list_add_tail(&vbl_swap->head, &dev_priv->vbl_swaps.head);
1142 dev_priv->swaps_pending++;
1144 DRM_SPINUNLOCK_IRQRESTORE(&dev_priv->swaps_lock, irqflags);
1151 void i915_driver_irq_preinstall(struct drm_device * dev)
1153 struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
1156 tmp = I915_READ(PIPEASTAT);
1157 I915_WRITE(PIPEASTAT, tmp);
1158 tmp = I915_READ(PIPEBSTAT);
1159 I915_WRITE(PIPEBSTAT, tmp);
1162 I915_WRITE16(HWSTAM, 0xeffe);
1163 if (IS_I9XX(dev) && !IS_I915G(dev) && !IS_I915GM(dev)) {
1164 I915_WRITE(IMR, 0x0);
1165 I915_WRITE(IER, 0x0);
1166 tmp = I915_READ(IIR);
1167 I915_WRITE(IIR, tmp);
1169 I915_WRITE16(IMR, 0x0);
1170 I915_WRITE16(IER, 0x0);
1171 tmp = I915_READ16(IIR);
1172 I915_WRITE16(IIR, tmp);
1176 int i915_driver_irq_postinstall(struct drm_device * dev)
1178 struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
1179 int ret, num_pipes = 2;
1181 DRM_SPININIT(&dev_priv->swaps_lock, "swap");
1182 INIT_LIST_HEAD(&dev_priv->vbl_swaps.head);
1183 dev_priv->swaps_pending = 0;
1185 DRM_SPININIT(&dev_priv->user_irq_lock, "userirq");
1186 dev_priv->user_irq_refcount = 0;
1187 dev_priv->irq_mask_reg = ~0;
1189 ret = drm_vblank_init(dev, num_pipes);
1193 ret = drm_hotplug_init(dev);
1197 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
1199 i915_enable_interrupt(dev);
1200 DRM_INIT_WAITQUEUE(&dev_priv->irq_queue);
1203 * Initialize the hardware status page IRQ location.
1206 I915_WRITE(INSTPM, (1 << 5) | (1 << 21));
1210 void i915_driver_irq_uninstall(struct drm_device * dev)
1212 struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
1218 dev_priv->irq_enabled = 1;
1220 temp = I915_READ(PIPEASTAT);
1221 I915_WRITE(PIPEASTAT, temp);
1222 temp = I915_READ(PIPEBSTAT);
1223 I915_WRITE(PIPEBSTAT, temp);
1224 if (IS_I9XX(dev) && !IS_I915G(dev) && !IS_I915GM(dev)) {
1225 I915_WRITE(HWSTAM, 0xffffffff);
1226 I915_WRITE(IMR, 0xffffffff);
1227 I915_WRITE(IER, 0x0);
1229 temp = I915_READ(IIR);
1230 I915_WRITE(IIR, temp);
1232 I915_WRITE16(HWSTAM, 0xffff);
1233 I915_WRITE16(IMR, 0xffff);
1234 I915_WRITE16(IER, 0x0);
1236 temp = I915_READ16(IIR);
1237 I915_WRITE16(IIR, temp);