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)
40 irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
42 drm_device_t *dev = (drm_device_t *) arg;
43 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
46 temp = I915_READ16(I915REG_INT_IDENTITY_R);
48 temp &= (USER_INT_FLAG | VSYNC_PIPEA_FLAG | VSYNC_PIPEB_FLAG);
50 DRM_DEBUG("%s flag=%08x\n", __FUNCTION__, temp);
55 I915_WRITE16(I915REG_INT_IDENTITY_R, temp);
57 dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
59 if (temp & USER_INT_FLAG)
60 DRM_WAKEUP(&dev_priv->irq_queue);
62 if (temp & (VSYNC_PIPEA_FLAG | VSYNC_PIPEB_FLAG)) {
63 atomic_inc(&dev->vbl_received);
64 DRM_WAKEUP(&dev->vbl_queue);
65 drm_vbl_send_signals(dev);
71 static int i915_emit_irq(drm_device_t * dev)
73 drm_i915_private_t *dev_priv = dev->dev_private;
77 i915_kernel_lost_context(dev);
79 DRM_DEBUG("%s\n", __FUNCTION__);
81 ret = dev_priv->counter;
85 OUT_RING(GFX_OP_USER_INTERRUPT);
91 static int i915_wait_irq(drm_device_t * dev, int irq_nr)
93 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
96 DRM_DEBUG("%s irq_nr=%d breadcrumb=%d\n", __FUNCTION__, irq_nr,
97 READ_BREADCRUMB(dev_priv));
99 if (READ_BREADCRUMB(dev_priv) >= irq_nr)
102 dev_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
104 DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ,
105 READ_BREADCRUMB(dev_priv) >= irq_nr);
107 if (ret == DRM_ERR(EBUSY)) {
108 DRM_ERROR("%s: EBUSY -- rec: %d emitted: %d\n",
110 READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
113 dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
117 int i915_driver_vblank_wait(drm_device_t *dev, unsigned int *sequence)
119 drm_i915_private_t *dev_priv = dev->dev_private;
120 unsigned int cur_vblank;
124 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
125 return DRM_ERR(EINVAL);
128 DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
129 (((cur_vblank = atomic_read(&dev->vbl_received))
130 - *sequence) <= (1<<23)));
132 *sequence = cur_vblank;
138 /* Needs the lock as it touches the ring.
140 int i915_irq_emit(DRM_IOCTL_ARGS)
143 drm_i915_private_t *dev_priv = dev->dev_private;
144 drm_i915_irq_emit_t emit;
147 LOCK_TEST_WITH_RETURN(dev, filp);
150 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
151 return DRM_ERR(EINVAL);
154 DRM_COPY_FROM_USER_IOCTL(emit, (drm_i915_irq_emit_t __user *) data,
157 result = i915_emit_irq(dev);
159 if (DRM_COPY_TO_USER(emit.irq_seq, &result, sizeof(int))) {
160 DRM_ERROR("copy_to_user\n");
161 return DRM_ERR(EFAULT);
167 /* Doesn't need the hardware lock.
169 int i915_irq_wait(DRM_IOCTL_ARGS)
172 drm_i915_private_t *dev_priv = dev->dev_private;
173 drm_i915_irq_wait_t irqwait;
176 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
177 return DRM_ERR(EINVAL);
180 DRM_COPY_FROM_USER_IOCTL(irqwait, (drm_i915_irq_wait_t __user *) data,
183 return i915_wait_irq(dev, irqwait.irq_seq);
186 static int i915_enable_interrupt (drm_device_t *dev)
188 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
192 if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_A)
193 flag |= VSYNC_PIPEA_FLAG;
194 if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_B)
195 flag |= VSYNC_PIPEB_FLAG;
196 if (dev_priv->vblank_pipe & ~(DRM_I915_VBLANK_PIPE_A|DRM_I915_VBLANK_PIPE_B)) {
197 DRM_ERROR("%s called with invalid pipe 0x%x\n",
198 __FUNCTION__, dev_priv->vblank_pipe);
199 return DRM_ERR(EINVAL);
201 I915_WRITE16(I915REG_INT_ENABLE_R, USER_INT_FLAG | flag);
205 /* Set the vblank monitor pipe
207 int i915_vblank_pipe_set(DRM_IOCTL_ARGS)
210 drm_i915_private_t *dev_priv = dev->dev_private;
211 drm_i915_vblank_pipe_t pipe;
214 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
215 return DRM_ERR(EINVAL);
218 DRM_COPY_FROM_USER_IOCTL(pipe, (drm_i915_vblank_pipe_t __user *) data,
221 dev_priv->vblank_pipe = pipe.pipe;
222 return i915_enable_interrupt (dev);
225 int i915_vblank_pipe_get(DRM_IOCTL_ARGS)
228 drm_i915_private_t *dev_priv = dev->dev_private;
229 drm_i915_vblank_pipe_t pipe;
233 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
234 return DRM_ERR(EINVAL);
237 flag = I915_READ(I915REG_INT_ENABLE_R);
239 if (flag & VSYNC_PIPEA_FLAG)
240 pipe.pipe |= DRM_I915_VBLANK_PIPE_A;
241 if (flag & VSYNC_PIPEB_FLAG)
242 pipe.pipe |= DRM_I915_VBLANK_PIPE_B;
243 DRM_COPY_TO_USER_IOCTL((drm_i915_vblank_pipe_t __user *) data, pipe,
250 void i915_driver_irq_preinstall(drm_device_t * dev)
252 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
254 I915_WRITE16(I915REG_HWSTAM, 0xfffe);
255 I915_WRITE16(I915REG_INT_MASK_R, 0x0);
256 I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
259 void i915_driver_irq_postinstall(drm_device_t * dev)
261 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
263 i915_enable_interrupt(dev);
264 DRM_INIT_WAITQUEUE(&dev_priv->irq_queue);
267 void i915_driver_irq_uninstall(drm_device_t * dev)
269 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
275 I915_WRITE16(I915REG_HWSTAM, 0xffff);
276 I915_WRITE16(I915REG_INT_MASK_R, 0xffff);
277 I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
279 temp = I915_READ16(I915REG_INT_IDENTITY_R);
280 I915_WRITE16(I915REG_INT_IDENTITY_R, temp);