[PATCH] aic7xxx_osm build fix
[cris-mirror.git] / drivers / char / drm / i915_irq.c
blobb0239262a84ae9515124afd41517e0c10de05bdf
1 /* i915_dma.c -- DMA support for the I915 -*- linux-c -*-
2 */
3 /**************************************************************************
4 *
5 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * All Rights Reserved.
7 *
8 **************************************************************************/
10 #include "drmP.h"
11 #include "drm.h"
12 #include "i915_drm.h"
13 #include "i915_drv.h"
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;
23 u16 temp;
25 temp = I915_READ16(I915REG_INT_IDENTITY_R);
26 temp &= USER_INT_FLAG;
28 DRM_DEBUG("%s flag=%08x\n", __FUNCTION__, temp);
30 if (temp == 0)
31 return IRQ_NONE;
33 I915_WRITE16(I915REG_INT_IDENTITY_R, temp);
34 DRM_WAKEUP(&dev_priv->irq_queue);
36 return IRQ_HANDLED;
39 int i915_emit_irq(drm_device_t * dev)
41 drm_i915_private_t *dev_priv = dev->dev_private;
42 u32 ret;
43 RING_LOCALS;
45 i915_kernel_lost_context(dev);
47 DRM_DEBUG("%s\n", __FUNCTION__);
49 ret = dev_priv->counter;
51 BEGIN_LP_RING(2);
52 OUT_RING(0);
53 OUT_RING(GFX_OP_USER_INTERRUPT);
54 ADVANCE_LP_RING();
56 return ret;
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;
62 int ret = 0;
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)
68 return 0;
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",
77 __FUNCTION__,
78 READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
81 dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
82 return ret;
85 /* Needs the lock as it touches the ring.
87 int i915_irq_emit(DRM_IOCTL_ARGS)
89 DRM_DEVICE;
90 drm_i915_private_t *dev_priv = dev->dev_private;
91 drm_i915_irq_emit_t emit;
92 int result;
94 LOCK_TEST_WITH_RETURN(dev, filp);
96 if (!dev_priv) {
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,
102 sizeof(emit));
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);
111 return 0;
114 /* Doesn't need the hardware lock.
116 int i915_irq_wait(DRM_IOCTL_ARGS)
118 DRM_DEVICE;
119 drm_i915_private_t *dev_priv = dev->dev_private;
120 drm_i915_irq_wait_t irqwait;
122 if (!dev_priv) {
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,
128 sizeof(irqwait));
130 return i915_wait_irq(dev, irqwait.irq_seq);
133 /* drm_dma.h hooks
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;
155 if (!dev_priv)
156 return;
158 I915_WRITE16(I915REG_HWSTAM, 0xffff);
159 I915_WRITE16(I915REG_INT_MASK_R, 0xffff);
160 I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);