1 /* i915_dma.c -- DMA support for the I915 -*- linux-c -*-
3 /**************************************************************************
5 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
8 **************************************************************************/
15 #define USER_INT_FLAG 0x2
16 #define MAX_NOPID ((u32)~0)
17 #define READ_BREADCRUMB(dev_priv) (((u32*)(dev_priv->hw_status_page))[5])
19 irqreturn_t
i915_driver_irq_handler(DRM_IRQ_ARGS
)
21 drm_device_t
*dev
= (drm_device_t
*) arg
;
22 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
25 temp
= I915_READ16(I915REG_INT_IDENTITY_R
);
26 temp
&= USER_INT_FLAG
;
28 DRM_DEBUG("%s flag=%08x\n", __FUNCTION__
, temp
);
33 I915_WRITE16(I915REG_INT_IDENTITY_R
, temp
);
34 DRM_WAKEUP(&dev_priv
->irq_queue
);
39 int i915_emit_irq(drm_device_t
* dev
)
41 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
45 i915_kernel_lost_context(dev
);
47 DRM_DEBUG("%s\n", __FUNCTION__
);
49 ret
= dev_priv
->counter
;
53 OUT_RING(GFX_OP_USER_INTERRUPT
);
59 int i915_wait_irq(drm_device_t
* dev
, int irq_nr
)
61 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
64 DRM_DEBUG("%s irq_nr=%d breadcrumb=%d\n", __FUNCTION__
, irq_nr
,
65 READ_BREADCRUMB(dev_priv
));
67 if (READ_BREADCRUMB(dev_priv
) >= irq_nr
)
70 dev_priv
->sarea_priv
->perf_boxes
|= I915_BOX_WAIT
;
72 DRM_WAIT_ON(ret
, dev_priv
->irq_queue
, 3 * DRM_HZ
,
73 READ_BREADCRUMB(dev_priv
) >= irq_nr
);
75 if (ret
== DRM_ERR(EBUSY
)) {
76 DRM_ERROR("%s: EBUSY -- rec: %d emitted: %d\n",
78 READ_BREADCRUMB(dev_priv
), (int)dev_priv
->counter
);
81 dev_priv
->sarea_priv
->last_dispatch
= READ_BREADCRUMB(dev_priv
);
85 /* Needs the lock as it touches the ring.
87 int i915_irq_emit(DRM_IOCTL_ARGS
)
90 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
91 drm_i915_irq_emit_t emit
;
94 LOCK_TEST_WITH_RETURN(dev
, filp
);
97 DRM_ERROR("%s called with no initialization\n", __FUNCTION__
);
98 return DRM_ERR(EINVAL
);
101 DRM_COPY_FROM_USER_IOCTL(emit
, (drm_i915_irq_emit_t __user
*) data
,
104 result
= i915_emit_irq(dev
);
106 if (DRM_COPY_TO_USER(emit
.irq_seq
, &result
, sizeof(int))) {
107 DRM_ERROR("copy_to_user\n");
108 return DRM_ERR(EFAULT
);
114 /* Doesn't need the hardware lock.
116 int i915_irq_wait(DRM_IOCTL_ARGS
)
119 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
120 drm_i915_irq_wait_t irqwait
;
123 DRM_ERROR("%s called with no initialization\n", __FUNCTION__
);
124 return DRM_ERR(EINVAL
);
127 DRM_COPY_FROM_USER_IOCTL(irqwait
, (drm_i915_irq_wait_t __user
*) data
,
130 return i915_wait_irq(dev
, irqwait
.irq_seq
);
135 void i915_driver_irq_preinstall(drm_device_t
* dev
)
137 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
139 I915_WRITE16(I915REG_HWSTAM
, 0xfffe);
140 I915_WRITE16(I915REG_INT_MASK_R
, 0x0);
141 I915_WRITE16(I915REG_INT_ENABLE_R
, 0x0);
144 void i915_driver_irq_postinstall(drm_device_t
* dev
)
146 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
148 I915_WRITE16(I915REG_INT_ENABLE_R
, USER_INT_FLAG
);
149 DRM_INIT_WAITQUEUE(&dev_priv
->irq_queue
);
152 void i915_driver_irq_uninstall(drm_device_t
* dev
)
154 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
158 I915_WRITE16(I915REG_HWSTAM
, 0xffff);
159 I915_WRITE16(I915REG_INT_MASK_R
, 0xffff);
160 I915_WRITE16(I915REG_INT_ENABLE_R
, 0x0);