1 /* i915_dma.c -- DMA support for the I915 -*- linux-c -*-
3 /**************************************************************************
5 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
24 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 **************************************************************************/
35 #define USER_INT_FLAG 0x2
36 #define MAX_NOPID ((u32)~0)
37 #define READ_BREADCRUMB(dev_priv) (((u32*)(dev_priv->hw_status_page))[5])
39 irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
41 drm_device_t *dev = (drm_device_t *) arg;
42 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
45 temp = I915_READ16(I915REG_INT_IDENTITY_R);
46 temp &= USER_INT_FLAG;
48 DRM_DEBUG("%s flag=%08x\n", __FUNCTION__, temp);
53 I915_WRITE16(I915REG_INT_IDENTITY_R, temp);
54 DRM_WAKEUP(&dev_priv->irq_queue);
59 int i915_emit_irq(drm_device_t * dev)
61 drm_i915_private_t *dev_priv = dev->dev_private;
65 i915_kernel_lost_context(dev);
67 DRM_DEBUG("%s\n", __FUNCTION__);
69 ret = dev_priv->counter;
73 OUT_RING(GFX_OP_USER_INTERRUPT);
79 int i915_wait_irq(drm_device_t * dev, int irq_nr)
81 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
84 DRM_DEBUG("%s irq_nr=%d breadcrumb=%d\n", __FUNCTION__, irq_nr,
85 READ_BREADCRUMB(dev_priv));
87 if (READ_BREADCRUMB(dev_priv) >= irq_nr)
90 dev_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
92 DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ,
93 READ_BREADCRUMB(dev_priv) >= irq_nr);
95 if (ret == DRM_ERR(EBUSY)) {
96 DRM_ERROR("%s: EBUSY -- rec: %d emitted: %d\n",
98 READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
101 dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
105 /* Needs the lock as it touches the ring.
107 int i915_irq_emit(DRM_IOCTL_ARGS)
110 drm_i915_private_t *dev_priv = dev->dev_private;
111 drm_i915_irq_emit_t emit;
114 LOCK_TEST_WITH_RETURN(dev, filp);
117 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
118 return DRM_ERR(EINVAL);
121 DRM_COPY_FROM_USER_IOCTL(emit, (drm_i915_irq_emit_t __user *) data,
124 result = i915_emit_irq(dev);
126 if (DRM_COPY_TO_USER(emit.irq_seq, &result, sizeof(int))) {
127 DRM_ERROR("copy_to_user\n");
128 return DRM_ERR(EFAULT);
134 /* Doesn't need the hardware lock.
136 int i915_irq_wait(DRM_IOCTL_ARGS)
139 drm_i915_private_t *dev_priv = dev->dev_private;
140 drm_i915_irq_wait_t irqwait;
143 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
144 return DRM_ERR(EINVAL);
147 DRM_COPY_FROM_USER_IOCTL(irqwait, (drm_i915_irq_wait_t __user *) data,
150 return i915_wait_irq(dev, irqwait.irq_seq);
155 void i915_driver_irq_preinstall(drm_device_t * dev)
157 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
159 I915_WRITE16(I915REG_HWSTAM, 0xfffe);
160 I915_WRITE16(I915REG_INT_MASK_R, 0x0);
161 I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
164 void i915_driver_irq_postinstall(drm_device_t * dev)
166 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
168 I915_WRITE16(I915REG_INT_ENABLE_R, USER_INT_FLAG);
169 DRM_INIT_WAITQUEUE(&dev_priv->irq_queue);
172 void i915_driver_irq_uninstall(drm_device_t * dev)
174 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
178 I915_WRITE16(I915REG_HWSTAM, 0xffff);
179 I915_WRITE16(I915REG_INT_MASK_R, 0xffff);
180 I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);